@@ -43,7 +43,7 @@ await server.register([
4343}
4444```
4545
46- - Create a lens using ramda for the above object
46+ - Create a lens using ramda for the above object. Ramda [ lenses ] ( !https://ramdajs.com/docs/#lensProp )
4747
4848``` js
4949const lens = R .lensProp < string, any> (' file' ) // here file is the key from object
@@ -119,24 +119,71 @@ server.route({
119119});
120120```
121121
122- ### Note
122+ ## Route Options
123123
124- - It will work with single objects and arrays. ` pathToSource ` is optional field,
125- use when nested objects are to be updated.
124+ | Key | Type | Description |
125+ | ------------ | -------------------------------- | --------------------------------------------------------------------------- |
126+ | lenses | Lens<object, string>[ ] | Array of lenses, this should be ` R.lensProp<string, string>(key) ` |
127+ | pathToSource | Lens<object, object \| object[ ] > | Path to the nested object, this should be ` R.lensPath(['somepath', '...']) ` |
126128
127- - Improvements todo
128- - Change the options structure to following, which will allow using multiple paths
129+ The options for the Route config can also be array, the type is represented as
129130
130- ``` js
131- const options = {
132- sources: [
131+ ``` ts
132+ interface RouteOptions {
133+ lenses: Lens <object , string >[];
134+ pathToSource? : Lens <object , Response >;
135+ }
136+
137+ // allows single option object or multiple
138+ const routeOptions: RouteOptions | RouteOptions [];
139+ ```
140+
141+ Example with multiple options
142+
143+ ``` ts
144+ const responseObject = {
145+ name: ' atul' ,
146+ profile: ' 1212121' , // to sign
147+ projects: [
133148 {
134- lenses: [nameLens],
149+ id: ' 1' ,
150+ files: ' 1234' , // to sign
135151 },
136152 {
137- lenses : [fileLens] ,
138- path : docLens,
153+ id: ' 2 ' ,
154+ files: ' 123232 ' , // to sign
139155 },
140156 ],
141157};
158+
159+ // lenses for the entire object
160+ const profileLens = R .lensProp <string , string >(' profile' );
161+ const filesLens = R .lensProp <string , string >(' files' );
162+
163+ // path for nested object
164+ const projectPath = R .lensPath ([' projects' ]);
165+
166+ // server route config
167+ server .route ({
168+ method: ' GET' ,
169+ path: ' /sample' ,
170+ options: {
171+ handler: handler .performAction ,
172+ plugins: {
173+ signedUrl: [
174+ // for profile sign
175+ {
176+ lenses: [profileLens ],
177+ },
178+
179+ // for files signing
180+ {
181+ lenses: [fileLens ],
182+ pathToSource: projectPath ,
183+ }
184+ ]
185+ },
186+ ...
187+ },
188+ });
142189```
0 commit comments