@fjell/express-router 4.4.25 → 4.4.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CItemRouter.js +1 -1
- package/dist/CItemRouter.js.map +2 -2
- package/dist/ItemRouter.d.ts.map +1 -1
- package/dist/ItemRouter.js +68 -12
- package/dist/ItemRouter.js.map +2 -2
- package/dist/PItemRouter.js +1 -1
- package/dist/PItemRouter.js.map +2 -2
- package/examples/basic-router-example.ts +8 -4
- package/examples/full-application-example.ts +35 -2
- package/examples/router-handlers-example.ts +1 -0
- package/examples/router-options-example.ts +214 -0
- package/package.json +2 -2
package/dist/CItemRouter.js
CHANGED
|
@@ -37,7 +37,7 @@ class CItemRouter extends ItemRouter {
|
|
|
37
37
|
), this.getPkType());
|
|
38
38
|
item = await this.postCreateItem(item);
|
|
39
39
|
this.logger.default("Created Item %j", item);
|
|
40
|
-
res.json(item);
|
|
40
|
+
res.status(201).json(item);
|
|
41
41
|
} catch (err) {
|
|
42
42
|
if (err instanceof NotFoundError) {
|
|
43
43
|
this.logger.error("Item Not Found for Create", { message: err?.message, stack: err?.stack });
|
package/dist/CItemRouter.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/CItemRouter.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ComKey, Item, ItemQuery, LocKey, LocKeyArray, paramsToQuery, PriKey, QueryParams, validatePK\n} from \"@fjell/core\";\nimport { NotFoundError } from \"@fjell/lib\";\nimport { Request, Response } from \"express\";\nimport { ItemRouter, ItemRouterOptions } from \"./ItemRouter.js\";\nimport { Instance } from \"./Instance.js\";\n\ninterface ParsedQuery {\n [key: string]: undefined | string | string[] | ParsedQuery | ParsedQuery[];\n}\n\nexport class CItemRouter<\n T extends Item<S, L1, L2, L3, L4, L5>,\n S extends string,\n L1 extends string,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n> extends ItemRouter<S, L1, L2, L3, L4, L5> {\n\n private parentRoute: ItemRouter<L1, L2, L3, L4, L5, never>;\n\n constructor(\n lib: Instance<T, S, L1, L2, L3, L4, L5>,\n type: S,\n parentRoute: ItemRouter<L1, L2, L3, L4, L5, never>,\n options: ItemRouterOptions<S, L1, L2, L3, L4, L5> = {},\n ) {\n super(lib as any, type, options);\n this.parentRoute = parentRoute;\n }\n\n public hasParent(): boolean {\n return !!this.parentRoute;\n }\n\n public getIk(res: Response): ComKey<S, L1, L2, L3, L4, L5> {\n const pri = this.getPk(res) as PriKey<S>;\n const loc = this.getLocations(res) as LocKeyArray<L1, L2, L3, L4, L5>;\n return { kt: pri.kt, pk: pri.pk, loc }\n }\n\n public getLKA(res: Response): LocKeyArray<S, L1, L2, L3, L4> {\n /**\n * A location key array is passed to a child router to provide contextfor the items it will\n * be working with. It is always a concatenation of \"My LKA\" + \"Parent LKA\" which will\n * bubble all the way up to the root Primary.\n */\n let lka: LocKey<S | L1 | L2 | L3 | L4>[] = [this.getLk(res)];\n lka = lka.concat(this.parentRoute.getLKA(res) as LocKey<S | L1 | L2 | L3 | L4>[]);\n return lka as LocKeyArray<S, L1, L2, L3, L4>;\n }\n\n public getLocations(res: Response): LocKeyArray<L1, L2, L3, L4, L5> {\n return this.parentRoute.getLKA(res) as LocKeyArray<L1, L2, L3, L4, L5>;\n }\n\n protected createItem = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n this.logger.default('Creating Item', { body: req?.body, query: req?.query, params: req?.params, locals: res?.locals });\n try {\n const itemToCreate = this.convertDates(req.body as Item<S, L1, L2, L3, L4, L5>);\n let item = validatePK(await libOperations.create(\n itemToCreate, { locations: this.getLocations(res) }), this.getPkType()) as Item<S, L1, L2, L3, L4, L5>;\n item = await this.postCreateItem(item);\n this.logger.default('Created Item %j', item);\n res.json(item);\n } catch (err: any) {\n if (err instanceof NotFoundError) {\n this.logger.error('Item Not Found for Create', { message: err?.message, stack: err?.stack });\n res.status(404).json({\n message: \"Item Not Found\",\n });\n } else {\n this.logger.error('General Error in Create', { message: err?.message, stack: err?.stack });\n res.status(500).json({\n message: \"General Error\",\n });\n }\n }\n };\n\n protected findItems = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n const query: ParsedQuery = req.query as unknown as ParsedQuery;\n const finder = query['finder'] as string;\n const finderParams = query['finderParams'] as string;\n const one = query['one'] as string;\n\n let items: Item<S, L1, L2, L3, L4, L5>[] = [];\n\n if (finder) {\n // If finder is defined? Call a finder.\n this.logger.default('Finding Items with Finder', { finder, finderParams, one });\n\n if (one === 'true') {\n const item = await (this.lib as any).findOne(finder, JSON.parse(finderParams), this.getLocations(res));\n items = item ? [item] : [];\n } else {\n items = await libOperations.find(finder, JSON.parse(finderParams), this.getLocations(res));\n }\n } else {\n // TODO: This is once of the more important places to perform some validaation and feedback\n const itemQuery: ItemQuery = paramsToQuery(req.query as QueryParams);\n this.logger.default('Finding Items with Query: %j', itemQuery);\n items = await libOperations.all(itemQuery, this.getLocations(res));\n this.logger.default('Found %d Items with Query', items.length);\n }\n\n res.json(items.map((item: Item<S, L1, L2, L3, L4, L5>) => validatePK(item, this.getPkType())));\n };\n\n}\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EACgD;AAAA,EAAoC;AAAA,OAC7E;AACP,SAAS,qBAAqB;AAE9B,SAAS,kBAAqC;AAOvC,MAAM,oBAQH,WAAkC;AAAA,EAElC;AAAA,EAER,YACE,KACA,MACA,aACA,UAAoD,CAAC,GACrD;AACA,UAAM,KAAY,MAAM,OAAO;AAC/B,SAAK,cAAc;AAAA,EACrB;AAAA,EAEO,YAAqB;AAC1B,WAAO,CAAC,CAAC,KAAK;AAAA,EAChB;AAAA,EAEO,MAAM,KAA8C;AACzD,UAAM,MAAM,KAAK,MAAM,GAAG;AAC1B,UAAM,MAAM,KAAK,aAAa,GAAG;AACjC,WAAO,EAAE,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI;AAAA,EACvC;AAAA,EAEO,OAAO,KAA+C;AAM3D,QAAI,MAAuC,CAAC,KAAK,MAAM,GAAG,CAAC;AAC3D,UAAM,IAAI,OAAO,KAAK,YAAY,OAAO,GAAG,CAAoC;AAChF,WAAO;AAAA,EACT;AAAA,EAEO,aAAa,KAAgD;AAClE,WAAO,KAAK,YAAY,OAAO,GAAG;AAAA,EACpC;AAAA,EAEU,aAAa,OAAO,KAAc,QAAkB;AAC5D,UAAM,gBAAgB,KAAK,IAAI;AAC/B,SAAK,OAAO,QAAQ,iBAAiB,EAAE,MAAM,KAAK,MAAM,OAAO,KAAK,OAAO,QAAQ,KAAK,QAAQ,QAAQ,KAAK,OAAO,CAAC;AACrH,QAAI;AACF,YAAM,eAAe,KAAK,aAAa,IAAI,IAAmC;AAC9E,UAAI,OAAO,WAAW,MAAM,cAAc;AAAA,QACxC;AAAA,QAAc,EAAE,WAAW,KAAK,aAAa,GAAG,EAAE;AAAA,MAAC,GAAG,KAAK,UAAU,CAAC;AACxE,aAAO,MAAM,KAAK,eAAe,IAAI;AACrC,WAAK,OAAO,QAAQ,mBAAmB,IAAI;AAC3C,UAAI,KAAK,IAAI;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n ComKey, Item, ItemQuery, LocKey, LocKeyArray, paramsToQuery, PriKey, QueryParams, validatePK\n} from \"@fjell/core\";\nimport { NotFoundError } from \"@fjell/lib\";\nimport { Request, Response } from \"express\";\nimport { ItemRouter, ItemRouterOptions } from \"./ItemRouter.js\";\nimport { Instance } from \"./Instance.js\";\n\ninterface ParsedQuery {\n [key: string]: undefined | string | string[] | ParsedQuery | ParsedQuery[];\n}\n\nexport class CItemRouter<\n T extends Item<S, L1, L2, L3, L4, L5>,\n S extends string,\n L1 extends string,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n> extends ItemRouter<S, L1, L2, L3, L4, L5> {\n\n private parentRoute: ItemRouter<L1, L2, L3, L4, L5, never>;\n\n constructor(\n lib: Instance<T, S, L1, L2, L3, L4, L5>,\n type: S,\n parentRoute: ItemRouter<L1, L2, L3, L4, L5, never>,\n options: ItemRouterOptions<S, L1, L2, L3, L4, L5> = {},\n ) {\n super(lib as any, type, options);\n this.parentRoute = parentRoute;\n }\n\n public hasParent(): boolean {\n return !!this.parentRoute;\n }\n\n public getIk(res: Response): ComKey<S, L1, L2, L3, L4, L5> {\n const pri = this.getPk(res) as PriKey<S>;\n const loc = this.getLocations(res) as LocKeyArray<L1, L2, L3, L4, L5>;\n return { kt: pri.kt, pk: pri.pk, loc }\n }\n\n public getLKA(res: Response): LocKeyArray<S, L1, L2, L3, L4> {\n /**\n * A location key array is passed to a child router to provide contextfor the items it will\n * be working with. It is always a concatenation of \"My LKA\" + \"Parent LKA\" which will\n * bubble all the way up to the root Primary.\n */\n let lka: LocKey<S | L1 | L2 | L3 | L4>[] = [this.getLk(res)];\n lka = lka.concat(this.parentRoute.getLKA(res) as LocKey<S | L1 | L2 | L3 | L4>[]);\n return lka as LocKeyArray<S, L1, L2, L3, L4>;\n }\n\n public getLocations(res: Response): LocKeyArray<L1, L2, L3, L4, L5> {\n return this.parentRoute.getLKA(res) as LocKeyArray<L1, L2, L3, L4, L5>;\n }\n\n protected createItem = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n this.logger.default('Creating Item', { body: req?.body, query: req?.query, params: req?.params, locals: res?.locals });\n try {\n const itemToCreate = this.convertDates(req.body as Item<S, L1, L2, L3, L4, L5>);\n let item = validatePK(await libOperations.create(\n itemToCreate, { locations: this.getLocations(res) }), this.getPkType()) as Item<S, L1, L2, L3, L4, L5>;\n item = await this.postCreateItem(item);\n this.logger.default('Created Item %j', item);\n res.status(201).json(item);\n } catch (err: any) {\n if (err instanceof NotFoundError) {\n this.logger.error('Item Not Found for Create', { message: err?.message, stack: err?.stack });\n res.status(404).json({\n message: \"Item Not Found\",\n });\n } else {\n this.logger.error('General Error in Create', { message: err?.message, stack: err?.stack });\n res.status(500).json({\n message: \"General Error\",\n });\n }\n }\n };\n\n protected findItems = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n const query: ParsedQuery = req.query as unknown as ParsedQuery;\n const finder = query['finder'] as string;\n const finderParams = query['finderParams'] as string;\n const one = query['one'] as string;\n\n let items: Item<S, L1, L2, L3, L4, L5>[] = [];\n\n if (finder) {\n // If finder is defined? Call a finder.\n this.logger.default('Finding Items with Finder', { finder, finderParams, one });\n\n if (one === 'true') {\n const item = await (this.lib as any).findOne(finder, JSON.parse(finderParams), this.getLocations(res));\n items = item ? [item] : [];\n } else {\n items = await libOperations.find(finder, JSON.parse(finderParams), this.getLocations(res));\n }\n } else {\n // TODO: This is once of the more important places to perform some validaation and feedback\n const itemQuery: ItemQuery = paramsToQuery(req.query as QueryParams);\n this.logger.default('Finding Items with Query: %j', itemQuery);\n items = await libOperations.all(itemQuery, this.getLocations(res));\n this.logger.default('Found %d Items with Query', items.length);\n }\n\n res.json(items.map((item: Item<S, L1, L2, L3, L4, L5>) => validatePK(item, this.getPkType())));\n };\n\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACgD;AAAA,EAAoC;AAAA,OAC7E;AACP,SAAS,qBAAqB;AAE9B,SAAS,kBAAqC;AAOvC,MAAM,oBAQH,WAAkC;AAAA,EAElC;AAAA,EAER,YACE,KACA,MACA,aACA,UAAoD,CAAC,GACrD;AACA,UAAM,KAAY,MAAM,OAAO;AAC/B,SAAK,cAAc;AAAA,EACrB;AAAA,EAEO,YAAqB;AAC1B,WAAO,CAAC,CAAC,KAAK;AAAA,EAChB;AAAA,EAEO,MAAM,KAA8C;AACzD,UAAM,MAAM,KAAK,MAAM,GAAG;AAC1B,UAAM,MAAM,KAAK,aAAa,GAAG;AACjC,WAAO,EAAE,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI;AAAA,EACvC;AAAA,EAEO,OAAO,KAA+C;AAM3D,QAAI,MAAuC,CAAC,KAAK,MAAM,GAAG,CAAC;AAC3D,UAAM,IAAI,OAA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AAC,UAAU,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CAAC,CAEvE;IAIK,cAAc,GAAU,MAAM,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,KAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAGrG;IAEF,SAAS,CAAC,UAAU,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CAAC,CAwBvE;IAIF,SAAS,CAAC,SAAS,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CAAC,CAEtE;IAGF,SAAS,CAAC,OAAO,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,mBAuBrD;IAED,SAAS,CAAC,UAAU,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,mBAwBvD;IAEK,YAAY,GAAI,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,KAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAYtG;IAGF;;;;;;OAMG;IACH,SAAS,CAAC,eAAe,GAAI,cAAc,MAAM,KAAG,OAAO,CAU1D;CAEF"}
|
package/dist/ItemRouter.js
CHANGED
|
@@ -209,36 +209,92 @@ class ItemRouter {
|
|
|
209
209
|
this.logger.debug("Configuring Router", { pkType: this.getPkType() });
|
|
210
210
|
router.get("/", this.findItems);
|
|
211
211
|
router.post("/", this.createItem);
|
|
212
|
-
|
|
212
|
+
const registeredAllActions = /* @__PURE__ */ new Set();
|
|
213
|
+
const registeredAllFacets = /* @__PURE__ */ new Set();
|
|
214
|
+
const registeredItemActions = /* @__PURE__ */ new Set();
|
|
215
|
+
const registeredItemFacets = /* @__PURE__ */ new Set();
|
|
216
|
+
this.logger.default("Router All Actions", { allActions: this.options.allActions });
|
|
217
|
+
if (this.options.allActions) {
|
|
218
|
+
Object.keys(this.options.allActions).forEach((actionKey) => {
|
|
219
|
+
this.logger.debug("Configuring Router All Action %s", actionKey);
|
|
220
|
+
router.post(`/${actionKey}`, this.postAllAction);
|
|
221
|
+
registeredAllActions.add(actionKey);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
this.logger.default("Library All Actions", { allActions: libOptions.allActions });
|
|
213
225
|
if (libOptions.allActions) {
|
|
214
226
|
Object.keys(libOptions.allActions).forEach((actionKey) => {
|
|
215
|
-
|
|
216
|
-
|
|
227
|
+
if (registeredAllActions.has(actionKey)) {
|
|
228
|
+
this.logger.warning("All Action name collision - router-level handler takes precedence", { actionKey });
|
|
229
|
+
} else {
|
|
230
|
+
this.logger.debug("Configuring Library All Action %s", actionKey);
|
|
231
|
+
router.post(`/${actionKey}`, this.postAllAction);
|
|
232
|
+
registeredAllActions.add(actionKey);
|
|
233
|
+
}
|
|
217
234
|
});
|
|
218
235
|
}
|
|
219
|
-
this.logger.default("All Facets
|
|
236
|
+
this.logger.default("Router All Facets", { allFacets: this.options.allFacets });
|
|
237
|
+
if (this.options.allFacets) {
|
|
238
|
+
Object.keys(this.options.allFacets).forEach((facetKey) => {
|
|
239
|
+
this.logger.debug("Configuring Router All Facet %s", facetKey);
|
|
240
|
+
router.get(`/${facetKey}`, this.getAllFacet);
|
|
241
|
+
registeredAllFacets.add(facetKey);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
this.logger.default("Library All Facets", { allFacets: libOptions.allFacets });
|
|
220
245
|
if (libOptions.allFacets) {
|
|
221
246
|
Object.keys(libOptions.allFacets).forEach((facetKey) => {
|
|
222
|
-
|
|
223
|
-
|
|
247
|
+
if (registeredAllFacets.has(facetKey)) {
|
|
248
|
+
this.logger.warning("All Facet name collision - router-level handler takes precedence", { facetKey });
|
|
249
|
+
} else {
|
|
250
|
+
this.logger.debug("Configuring Library All Facet %s", facetKey);
|
|
251
|
+
router.get(`/${facetKey}`, this.getAllFacet);
|
|
252
|
+
registeredAllFacets.add(facetKey);
|
|
253
|
+
}
|
|
224
254
|
});
|
|
225
255
|
}
|
|
226
256
|
const itemRouter = Router();
|
|
227
257
|
itemRouter.get("/", this.getItem);
|
|
228
258
|
itemRouter.put("/", this.updateItem);
|
|
229
259
|
itemRouter.delete("/", this.deleteItem);
|
|
230
|
-
this.logger.default("Item Actions
|
|
260
|
+
this.logger.default("Router Item Actions", { itemActions: this.options.actions });
|
|
261
|
+
if (this.options.actions) {
|
|
262
|
+
Object.keys(this.options.actions).forEach((actionKey) => {
|
|
263
|
+
this.logger.debug("Configuring Router Item Action %s", actionKey);
|
|
264
|
+
itemRouter.post(`/${actionKey}`, this.postItemAction);
|
|
265
|
+
registeredItemActions.add(actionKey);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
this.logger.default("Library Item Actions", { itemActions: libOptions.actions });
|
|
231
269
|
if (libOptions.actions) {
|
|
232
270
|
Object.keys(libOptions.actions).forEach((actionKey) => {
|
|
233
|
-
|
|
234
|
-
|
|
271
|
+
if (registeredItemActions.has(actionKey)) {
|
|
272
|
+
this.logger.warning("Item Action name collision - router-level handler takes precedence", { actionKey });
|
|
273
|
+
} else {
|
|
274
|
+
this.logger.debug("Configuring Library Item Action %s", actionKey);
|
|
275
|
+
itemRouter.post(`/${actionKey}`, this.postItemAction);
|
|
276
|
+
registeredItemActions.add(actionKey);
|
|
277
|
+
}
|
|
235
278
|
});
|
|
236
279
|
}
|
|
237
|
-
this.logger.default("Item Facets
|
|
280
|
+
this.logger.default("Router Item Facets", { itemFacets: this.options.facets });
|
|
281
|
+
if (this.options.facets) {
|
|
282
|
+
Object.keys(this.options.facets).forEach((facetKey) => {
|
|
283
|
+
this.logger.debug("Configuring Router Item Facet %s", facetKey);
|
|
284
|
+
itemRouter.get(`/${facetKey}`, this.getItemFacet);
|
|
285
|
+
registeredItemFacets.add(facetKey);
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
this.logger.default("Library Item Facets", { itemFacets: libOptions.facets });
|
|
238
289
|
if (libOptions.facets) {
|
|
239
290
|
Object.keys(libOptions.facets).forEach((facetKey) => {
|
|
240
|
-
|
|
241
|
-
|
|
291
|
+
if (registeredItemFacets.has(facetKey)) {
|
|
292
|
+
this.logger.warning("Item Facet name collision - router-level handler takes precedence", { facetKey });
|
|
293
|
+
} else {
|
|
294
|
+
this.logger.debug("Configuring Library Item Facet %s", facetKey);
|
|
295
|
+
itemRouter.get(`/${facetKey}`, this.getItemFacet);
|
|
296
|
+
registeredItemFacets.add(facetKey);
|
|
297
|
+
}
|
|
242
298
|
});
|
|
243
299
|
}
|
|
244
300
|
this.logger.debug("Configuring Item Operations under PK Param %s", this.getPkParam());
|
package/dist/ItemRouter.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/ItemRouter.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ComKey,\n cPK,\n Item,\n ItemEvent,\n LocKey,\n LocKeyArray,\n PriKey,\n validatePK\n} from \"@fjell/core\";\nimport { NotFoundError } from \"@fjell/lib\";\nimport { Instance } from \"./Instance.js\";\nimport deepmerge from \"deepmerge\";\nimport { Request, Response, Router } from \"express\";\nimport LibLogger from \"./logger.js\";\n\n/**\n * Router-level action method signature - aligned with library ActionMethod pattern\n * Takes the resolved item key, action parameters, and HTTP context\n */\nexport interface RouterActionMethod<\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never,\n> {\n (\n ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>,\n actionParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n context: { req: Request, res: Response }\n ): Promise<any>;\n}\n\n/**\n * Router-level facet method signature - aligned with library FacetMethod pattern\n * Takes the resolved item key, facet parameters, and HTTP context\n */\nexport interface RouterFacetMethod<\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never,\n> {\n (\n ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>,\n facetParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n context: { req: Request, res: Response }\n ): Promise<any>;\n}\n\n/**\n * Router-level all action method signature - aligned with library AllActionMethod pattern\n * Takes action parameters, optional locations, and HTTP context\n */\nexport interface RouterAllActionMethod<\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never,\n> {\n (\n allActionParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n locations: LocKeyArray<L1, L2, L3, L4, L5> | [],\n context: { req: Request, res: Response }\n ): Promise<any>;\n}\n\n/**\n * Router-level all facet method signature - aligned with library AllFacetMethod pattern\n * Takes facet parameters, optional locations, and HTTP context\n */\nexport interface RouterAllFacetMethod<\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never,\n> {\n (\n allFacetParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n locations: LocKeyArray<L1, L2, L3, L4, L5> | [],\n context: { req: Request, res: Response }\n ): Promise<any>;\n}\n\nexport type ItemRouterOptions<\n S extends string = string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n> = {\n /**\n * Handlers for item actions - aligned with library operation signatures\n * The key in the Record is the action name, method receives resolved item key and parameters\n */\n actions?: Record<string, RouterActionMethod<S, L1, L2, L3, L4, L5>>;\n\n /**\n * Handlers for item facets - aligned with library operation signatures\n * The key in the Record is the facet name, method receives resolved item key and parameters\n */\n facets?: Record<string, RouterFacetMethod<S, L1, L2, L3, L4, L5>>;\n\n /**\n * Handlers for all actions - aligned with library operation signatures\n * The key in the Record is the action name, method receives parameters and optional locations\n */\n allActions?: Record<string, RouterAllActionMethod<L1, L2, L3, L4, L5>>;\n\n /**\n * Handlers for all facets - aligned with library operation signatures\n * The key in the Record is the facet name, method receives parameters and optional locations\n */\n allFacets?: Record<string, RouterAllFacetMethod<L1, L2, L3, L4, L5>>;\n};\n\nexport class ItemRouter<\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n> {\n\n protected lib: Instance<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>;\n private keyType: S;\n protected options: ItemRouterOptions<S, L1, L2, L3, L4, L5>;\n private childRouters: Record<string, Router> = {};\n protected logger;\n\n constructor(\n lib: Instance<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>,\n keyType: S,\n options: ItemRouterOptions<S, L1, L2, L3, L4, L5> = {}\n ) {\n this.lib = lib;\n this.keyType = keyType;\n this.options = options;\n this.logger = LibLogger.get(\"ItemRouter\", keyType);\n }\n\n public getPkType = (): S => {\n return this.keyType;\n }\n\n protected getPkParam = (): string => {\n return `${this.getPkType()}Pk`;\n }\n\n protected getLk(res: Response): LocKey<S> {\n return { kt: this.keyType, lk: res.locals[this.getPkParam()] };\n }\n\n // this is meant to be consumed by children routers\n public getLKA(res: Response): LocKeyArray<S, L1, L2, L3, L4> {\n return [this.getLk(res)] as LocKeyArray<S, L1, L2, L3, L4>;\n }\n\n public getPk(res: Response): PriKey<S> {\n return cPK<S>(res.locals[this.getPkParam()], this.getPkType());\n }\n\n // Unless this is a contained router, the locations will always be an empty array.\n /* eslint-disable */\n protected getLocations(res: Response): LocKeyArray<L1, L2, L3, L4, L5> | [] {\n throw new Error('Method not implemented in an abstract router');\n }\n /* eslint-enable */\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected getIk(res: Response): PriKey<S> | ComKey<S, L1, L2, L3, L4, L5> {\n throw new Error('Method not implemented in an abstract router');\n }\n\n protected postAllAction = async (req: Request, res: Response) => {\n const libOptions = this.lib.options;\n const libOperations = this.lib.operations;\n this.logger.debug('Posting All Action', { query: req?.query, params: req?.params, locals: res?.locals });\n const allActionKey = req.path.substring(req.path.lastIndexOf('/') + 1);\n\n // Check for router-level handler first\n if (this.options.allActions && this.options.allActions[allActionKey]) {\n this.logger.debug('Using router-level all action handler', { allActionKey });\n try {\n const result = await this.options.allActions[allActionKey](\n req.body as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n this.getLKA(res) as LocKeyArray<L1, L2, L3, L4, L5> | [],\n { req, res }\n );\n if (result != null) res.json(result);\n return;\n } catch (err: any) {\n this.logger.error('Error in router-level all action', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n return;\n }\n }\n\n // Fallback to library handler\n if (!libOptions.allActions) {\n this.logger.error('All Actions are not configured');\n res.status(500).json({ error: 'All Actions are not configured' });\n return;\n }\n const allAction = libOptions.allActions[allActionKey];\n if (!allAction) {\n this.logger.error('All Action is not configured', { allActionKey });\n res.status(500).json({ error: 'All Action is not configured' });\n return;\n }\n try {\n res.json(await libOperations.allAction(allActionKey, req.body));\n } catch (err: any) {\n this.logger.error('Error in All Action', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n }\n }\n\n protected getAllFacet = async (req: Request, res: Response) => {\n const libOptions = this.lib.options;\n const libOperations = this.lib.operations;\n this.logger.debug('Getting All Facet', { query: req?.query, params: req?.params, locals: res?.locals });\n const facetKey = req.path.substring(req.path.lastIndexOf('/') + 1);\n\n // Check for router-level handler first\n if (this.options.allFacets && this.options.allFacets[facetKey]) {\n this.logger.debug('Using router-level all facet handler', { facetKey });\n try {\n const result = await this.options.allFacets[facetKey](\n req.query as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n this.getLKA(res) as LocKeyArray<L1, L2, L3, L4, L5> | [],\n { req, res }\n );\n if (result != null) res.json(result);\n return;\n } catch (err: any) {\n this.logger.error('Error in router-level all facet', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n return;\n }\n }\n\n // Fallback to library handler\n if (!libOptions.allFacets) {\n this.logger.error('All Facets are not configured');\n res.status(500).json({ error: 'All Facets are not configured' });\n return;\n }\n const facet = libOptions.allFacets[facetKey];\n if (!facet) {\n this.logger.error('All Facet is not configured', { facetKey });\n res.status(500).json({ error: 'All Facet is not configured' });\n return;\n }\n try {\n const combinedQueryParams = { ...req.query, ...req.params } as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>;\n res.json(await libOperations.allFacet(facetKey, combinedQueryParams));\n } catch (err: any) {\n this.logger.error('Error in All Facet', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n }\n }\n\n protected postItemAction = async (req: Request, res: Response) => {\n const libOptions = this.lib.options;\n const libOperations = this.lib.operations;\n this.logger.debug('Posting Item Action', { query: req?.query, params: req?.params, locals: res?.locals });\n const ik = this.getIk(res);\n const actionKey = req.path.substring(req.path.lastIndexOf('/') + 1);\n\n // Check for router-level handler first\n if (this.options.actions && this.options.actions[actionKey]) {\n this.logger.debug('Using router-level action handler', { actionKey });\n try {\n const result = await this.options.actions[actionKey](\n ik,\n req.body as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n { req, res }\n );\n if (result != null) res.json(result);\n return;\n } catch (err: any) {\n this.logger.error('Error in router-level action', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n return;\n }\n }\n\n // Fallback to library handler\n if (!libOptions.actions) {\n this.logger.error('Item Actions are not configured');\n res.status(500).json({ error: 'Item Actions are not configured' });\n return;\n }\n const action = libOptions.actions[actionKey];\n if (!action) {\n this.logger.error('Item Action is not configured', { actionKey });\n res.status(500).json({ error: 'Item Action is not configured' });\n return;\n }\n try {\n res.json(await libOperations.action(ik, actionKey, req.body));\n } catch (err: any) {\n this.logger.error('Error in Item Action', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n }\n }\n\n protected getItemFacet = async (req: Request, res: Response) => {\n const libOptions = this.lib.options;\n const libOperations = this.lib.operations;\n this.logger.debug('Getting Item Facet', { query: req?.query, params: req?.params, locals: res?.locals });\n const ik = this.getIk(res);\n const facetKey = req.path.substring(req.path.lastIndexOf('/') + 1);\n\n // Check for router-level handler first\n if (this.options.facets && this.options.facets[facetKey]) {\n this.logger.debug('Using router-level facet handler', { facetKey });\n try {\n const result = await this.options.facets[facetKey](\n ik,\n req.query as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n { req, res }\n );\n if (result != null) res.json(result);\n return;\n } catch (err: any) {\n this.logger.error('Error in router-level facet', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n return;\n }\n }\n\n // Fallback to library handler\n if (!libOptions.facets) {\n this.logger.error('Item Facets are not configured');\n res.status(500).json({ error: 'Item Facets are not configured' });\n return;\n }\n const facet = libOptions.facets[facetKey];\n if (!facet) {\n this.logger.error('Item Facet is not configured', { facetKey });\n res.status(500).json({ error: 'Item Facet is not configured' });\n return;\n }\n try {\n const combinedQueryParams = { ...req.query, ...req.params } as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>;\n res.json(await libOperations.facet(ik, facetKey, combinedQueryParams));\n } catch (err: any) {\n this.logger.error('Error in Item Facet', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n }\n }\n\n private configure = (router: Router) => {\n const libOptions = this.lib.options;\n this.logger.debug('Configuring Router', { pkType: this.getPkType() });\n router.get('/', this.findItems);\n router.post('/', this.createItem);\n\n this.logger.default('All Actions supplied to Router', { allActions: libOptions.allActions });\n if (libOptions.allActions) {\n Object.keys(libOptions.allActions).forEach((actionKey) => {\n this.logger.debug('Configuring All Action %s', actionKey);\n // TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers\n router.post(`/${actionKey}`, this.postAllAction);\n });\n }\n\n this.logger.default('All Facets supplied to Router', { allFacets: libOptions.allFacets });\n if (libOptions.allFacets) {\n Object.keys(libOptions.allFacets).forEach((facetKey) => {\n this.logger.debug('Configuring All Facet %s', facetKey);\n // TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers\n router.get(`/${facetKey}`, this.getAllFacet);\n });\n }\n\n const itemRouter = Router();\n itemRouter.get('/', this.getItem);\n itemRouter.put('/', this.updateItem);\n itemRouter.delete('/', this.deleteItem);\n\n this.logger.default('Item Actions supplied to Router', { itemActions: libOptions.actions });\n if (libOptions.actions) {\n Object.keys(libOptions.actions).forEach((actionKey) => {\n this.logger.debug('Configuring Item Action %s', actionKey);\n // TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers\n itemRouter.post(`/${actionKey}`, this.postItemAction)\n });\n }\n\n this.logger.default('Item Facets supplied to Router', { itemFacets: libOptions.facets });\n if (libOptions.facets) {\n Object.keys(libOptions.facets).forEach((facetKey) => {\n this.logger.debug('Configuring Item Facet %s', facetKey);\n // TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers\n itemRouter.get(`/${facetKey}`, this.getItemFacet)\n });\n }\n\n this.logger.debug('Configuring Item Operations under PK Param %s', this.getPkParam());\n router.use(`/:${this.getPkParam()}`, this.validatePrimaryKeyValue, itemRouter);\n\n if (this.childRouters) {\n this.configureChildRouters(itemRouter, this.childRouters);\n }\n return router;\n }\n\n private validatePrimaryKeyValue = (req: Request, res: Response, next: any) => {\n const pkParamValue = req.params[this.getPkParam()];\n if (this.validatePKParam(pkParamValue)) {\n res.locals[this.getPkParam()] = pkParamValue;\n next();\n } else {\n this.logger.error('Invalid Primary Key', { pkParamValue, path: req?.originalUrl });\n res.status(500).json({ error: 'Invalid Primary Key', path: req?.originalUrl });\n }\n }\n\n private configureChildRouters = (router: Router, childRouters: Record<string, Router>) => {\n for (const path in childRouters) {\n this.logger.debug('Configuring Child Router at Path %s', path);\n\n router.use(`/${path}`, childRouters[path]);\n }\n return router;\n }\n\n public addChildRouter = (path: string, router: Router) => {\n this.childRouters[path] = router;\n }\n\n /* istanbul ignore next */\n public getRouter(): Router {\n const router = Router();\n this.configure(router);\n return router;\n }\n\n /* istanbul ignore next */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected createItem = async (req: Request, res: Response): Promise<void> => {\n throw new Error('Method not implemented in an abstract router');\n };\n\n // TODO: Probably a better way to do this, but this postCreate hook only needs the item.\n /* istanbul ignore next */\n public postCreateItem = async (item: Item<S, L1, L2, L3, L4, L5>): Promise<Item<S, L1, L2, L3, L4, L5>> => {\n this.logger.debug('Post Create Item', { item });\n return item;\n };\n\n protected deleteItem = async (req: Request, res: Response): Promise<void> => {\n const libOperations = this.lib.operations;\n\n this.logger.debug('Deleting Item', { query: req.query, params: req.params, locals: res.locals });\n const ik = this.getIk(res);\n try {\n const removedItem = await libOperations.remove(ik);\n const item = validatePK(removedItem, this.getPkType());\n res.json(item);\n } catch (err: any) {\n if (err instanceof NotFoundError) {\n this.logger.error('Item Not Found for Delete', { ik, message: err?.message, stack: err?.stack });\n res.status(404).json({\n ik,\n message: \"Item Not Found\",\n });\n } else {\n this.logger.error('General Error in Delete', { ik, message: err?.message, stack: err?.stack });\n res.status(500).json({\n ik,\n message: \"General Error\",\n });\n }\n }\n };\n\n /* eslint-disable */\n /* istanbul ignore next */\n protected findItems = async (req: Request, res: Response): Promise<void> => {\n throw new Error('Method not implemented in an abstract router');\n };\n /* eslint-enable */\n\n protected getItem = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n this.logger.debug('Getting Item', { query: req.query, params: req.params, locals: res.locals });\n const ik = this.getIk(res);\n try {\n // TODO: What error does validate PK throw, when can that fail?\n const item = validatePK(await libOperations.get(ik), this.getPkType());\n res.json(item);\n } catch (err: any) {\n if (err instanceof NotFoundError) {\n this.logger.error('Item Not Found', { ik, message: err?.message, stack: err?.stack });\n res.status(404).json({\n ik,\n message: \"Item Not Found\",\n });\n } else {\n this.logger.error('General Error', { ik, message: err?.message, stack: err?.stack });\n res.status(500).json({\n ik,\n message: \"General Error\",\n });\n }\n }\n }\n\n protected updateItem = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n this.logger.debug('Updating Item',\n { body: req?.body, query: req?.query, params: req?.params, locals: res?.locals });\n const ik = this.getIk(res);\n try {\n const itemToUpdate = this.convertDates(req.body as Partial<Item<S, L1, L2, L3, L4, L5>>);\n const retItem = validatePK(await libOperations.update(ik, itemToUpdate), this.getPkType());\n res.json(retItem);\n } catch (err: any) {\n if (err instanceof NotFoundError) {\n this.logger.error('Item Not Found for Update', { ik, message: err?.message, stack: err?.stack });\n res.status(404).json({\n ik,\n message: \"Item Not Found\",\n });\n } else {\n this.logger.error('General Error in Update', { ik, message: err?.message, stack: err?.stack });\n res.status(500).json({\n ik,\n message: \"General Error\",\n });\n }\n }\n };\n\n public convertDates = (item: Partial<Item<S, L1, L2, L3, L4, L5>>): Partial<Item<S, L1, L2, L3, L4, L5>> => {\n const events = item.events as Record<string, ItemEvent>;\n this.logger.debug('Converting Dates', { item });\n if (events) {\n Object.keys(events).forEach((key: string) => {\n Object.assign(events, {\n [key]: deepmerge(events[key], { at: events[key].at ? new Date(events[key].at) : null })\n });\n });\n }\n Object.assign(item, { events });\n return item;\n };\n\n // TODO: Maybe just simplify this and require that everything is a UUID?\n /**\n * This method might be an annoyance, but we need to capture a few cases where someone passes\n * a PK parameter that has an odd string in it.\n *\n * @param pkParamValue The value of the primary key parameter\n * @returns if the value is valid.\n */\n protected validatePKParam = (pkParamValue: string): boolean => {\n let validPkParam = true;\n if (pkParamValue.length <= 0) {\n this.logger.error('Primary Key is an Empty String', { pkParamValue });\n validPkParam = false;\n } else if (pkParamValue === 'undefined') {\n this.logger.error('Primary Key is the string \\'undefined\\'', { pkParamValue });\n validPkParam = false;\n }\n return validPkParam;\n }\n\n}\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EAEE;AAAA,EAMA;AAAA,OACK;AACP,SAAS,qBAAqB;AAE9B,OAAO,eAAe;AACtB,SAA4B,cAAc;AAC1C,OAAO,eAAe;AA6Gf,MAAM,WAOX;AAAA,EAEU;AAAA,EACF;AAAA,EACE;AAAA,E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AAK;AAAA,UACnB;AAAA,UACA,SAAS;AAAA,QACX,CAAC;AAAA,MACH,OAAO;AACL,aAAK,OAAO,MAAM,2BAA2B,EAAE,IAAI,SAAS,KAAK,SAAS,OAAO,KAAK,MAAM,CAAC;AAC7F,YAAI,OAAO,GAAG,EAAE,KAAK;AAAA,UACnB;AAAA,UACA,SAAS;AAAA,QACX,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EAEO,eAAe,CAAC,SAAqF;AAC1G,UAAM,SAAS,KAAK;AACpB,SAAK,OAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC;AAC9C,QAAI,QAAQ;AACV,aAAO,KAAK,MAAM,EAAE,QAAQ,CAAC,QAAgB;AAC3C,eAAO,OAAO,QAAQ;AAAA,UACpB,CAAC,GAAG,GAAG,UAAU,OAAO,GAAG,GAAG,EAAE,IAAI,OAAO,GAAG,EAAE,KAAK,IAAI,KAAK,OAAO,GAAG,EAAE,EAAE,IAAI,KAAK,CAAC;AAAA,QACxF,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AACA,WAAO,OAAO,MAAM,EAAE,OAAO,CAAC;AAC9B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUU,kBAAkB,CAAC,iBAAkC;AAC7D,QAAI,eAAe;AACnB,QAAI,aAAa,UAAU,GAAG;AAC5B,WAAK,OAAO,MAAM,kCAAkC,EAAE,aAAa,CAAC;AACpE,qBAAe;AAAA,IACjB,WAAW,iBAAiB,aAAa;AACvC,WAAK,OAAO,MAAM,yCAA2C,EAAE,aAAa,CAAC;AAC7E,qBAAe;AAAA,IACjB;AACA,WAAO;AAAA,EACT;AAEF;",
|
|
4
|
+
"sourcesContent": ["import {\n ComKey,\n cPK,\n Item,\n ItemEvent,\n LocKey,\n LocKeyArray,\n PriKey,\n validatePK\n} from \"@fjell/core\";\nimport { NotFoundError } from \"@fjell/lib\";\nimport { Instance } from \"./Instance.js\";\nimport deepmerge from \"deepmerge\";\nimport { Request, Response, Router } from \"express\";\nimport LibLogger from \"./logger.js\";\n\n/**\n * Router-level action method signature - aligned with library ActionMethod pattern\n * Takes the resolved item key, action parameters, and HTTP context\n */\nexport interface RouterActionMethod<\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never,\n> {\n (\n ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>,\n actionParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n context: { req: Request, res: Response }\n ): Promise<any>;\n}\n\n/**\n * Router-level facet method signature - aligned with library FacetMethod pattern\n * Takes the resolved item key, facet parameters, and HTTP context\n */\nexport interface RouterFacetMethod<\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never,\n> {\n (\n ik: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>,\n facetParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n context: { req: Request, res: Response }\n ): Promise<any>;\n}\n\n/**\n * Router-level all action method signature - aligned with library AllActionMethod pattern\n * Takes action parameters, optional locations, and HTTP context\n */\nexport interface RouterAllActionMethod<\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never,\n> {\n (\n allActionParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n locations: LocKeyArray<L1, L2, L3, L4, L5> | [],\n context: { req: Request, res: Response }\n ): Promise<any>;\n}\n\n/**\n * Router-level all facet method signature - aligned with library AllFacetMethod pattern\n * Takes facet parameters, optional locations, and HTTP context\n */\nexport interface RouterAllFacetMethod<\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never,\n> {\n (\n allFacetParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n locations: LocKeyArray<L1, L2, L3, L4, L5> | [],\n context: { req: Request, res: Response }\n ): Promise<any>;\n}\n\nexport type ItemRouterOptions<\n S extends string = string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n> = {\n /**\n * Handlers for item actions - aligned with library operation signatures\n * The key in the Record is the action name, method receives resolved item key and parameters\n */\n actions?: Record<string, RouterActionMethod<S, L1, L2, L3, L4, L5>>;\n\n /**\n * Handlers for item facets - aligned with library operation signatures\n * The key in the Record is the facet name, method receives resolved item key and parameters\n */\n facets?: Record<string, RouterFacetMethod<S, L1, L2, L3, L4, L5>>;\n\n /**\n * Handlers for all actions - aligned with library operation signatures\n * The key in the Record is the action name, method receives parameters and optional locations\n */\n allActions?: Record<string, RouterAllActionMethod<L1, L2, L3, L4, L5>>;\n\n /**\n * Handlers for all facets - aligned with library operation signatures\n * The key in the Record is the facet name, method receives parameters and optional locations\n */\n allFacets?: Record<string, RouterAllFacetMethod<L1, L2, L3, L4, L5>>;\n};\n\nexport class ItemRouter<\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n> {\n\n protected lib: Instance<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>;\n private keyType: S;\n protected options: ItemRouterOptions<S, L1, L2, L3, L4, L5>;\n private childRouters: Record<string, Router> = {};\n protected logger;\n\n constructor(\n lib: Instance<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>,\n keyType: S,\n options: ItemRouterOptions<S, L1, L2, L3, L4, L5> = {}\n ) {\n this.lib = lib;\n this.keyType = keyType;\n this.options = options;\n this.logger = LibLogger.get(\"ItemRouter\", keyType);\n }\n\n public getPkType = (): S => {\n return this.keyType;\n }\n\n protected getPkParam = (): string => {\n return `${this.getPkType()}Pk`;\n }\n\n protected getLk(res: Response): LocKey<S> {\n return { kt: this.keyType, lk: res.locals[this.getPkParam()] };\n }\n\n // this is meant to be consumed by children routers\n public getLKA(res: Response): LocKeyArray<S, L1, L2, L3, L4> {\n return [this.getLk(res)] as LocKeyArray<S, L1, L2, L3, L4>;\n }\n\n public getPk(res: Response): PriKey<S> {\n return cPK<S>(res.locals[this.getPkParam()], this.getPkType());\n }\n\n // Unless this is a contained router, the locations will always be an empty array.\n /* eslint-disable */\n protected getLocations(res: Response): LocKeyArray<L1, L2, L3, L4, L5> | [] {\n throw new Error('Method not implemented in an abstract router');\n }\n /* eslint-enable */\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected getIk(res: Response): PriKey<S> | ComKey<S, L1, L2, L3, L4, L5> {\n throw new Error('Method not implemented in an abstract router');\n }\n\n protected postAllAction = async (req: Request, res: Response) => {\n const libOptions = this.lib.options;\n const libOperations = this.lib.operations;\n this.logger.debug('Posting All Action', { query: req?.query, params: req?.params, locals: res?.locals });\n const allActionKey = req.path.substring(req.path.lastIndexOf('/') + 1);\n\n // Check for router-level handler first\n if (this.options.allActions && this.options.allActions[allActionKey]) {\n this.logger.debug('Using router-level all action handler', { allActionKey });\n try {\n const result = await this.options.allActions[allActionKey](\n req.body as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n this.getLKA(res) as LocKeyArray<L1, L2, L3, L4, L5> | [],\n { req, res }\n );\n if (result != null) res.json(result);\n return;\n } catch (err: any) {\n this.logger.error('Error in router-level all action', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n return;\n }\n }\n\n // Fallback to library handler\n if (!libOptions.allActions) {\n this.logger.error('All Actions are not configured');\n res.status(500).json({ error: 'All Actions are not configured' });\n return;\n }\n const allAction = libOptions.allActions[allActionKey];\n if (!allAction) {\n this.logger.error('All Action is not configured', { allActionKey });\n res.status(500).json({ error: 'All Action is not configured' });\n return;\n }\n try {\n res.json(await libOperations.allAction(allActionKey, req.body));\n } catch (err: any) {\n this.logger.error('Error in All Action', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n }\n }\n\n protected getAllFacet = async (req: Request, res: Response) => {\n const libOptions = this.lib.options;\n const libOperations = this.lib.operations;\n this.logger.debug('Getting All Facet', { query: req?.query, params: req?.params, locals: res?.locals });\n const facetKey = req.path.substring(req.path.lastIndexOf('/') + 1);\n\n // Check for router-level handler first\n if (this.options.allFacets && this.options.allFacets[facetKey]) {\n this.logger.debug('Using router-level all facet handler', { facetKey });\n try {\n const result = await this.options.allFacets[facetKey](\n req.query as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n this.getLKA(res) as LocKeyArray<L1, L2, L3, L4, L5> | [],\n { req, res }\n );\n if (result != null) res.json(result);\n return;\n } catch (err: any) {\n this.logger.error('Error in router-level all facet', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n return;\n }\n }\n\n // Fallback to library handler\n if (!libOptions.allFacets) {\n this.logger.error('All Facets are not configured');\n res.status(500).json({ error: 'All Facets are not configured' });\n return;\n }\n const facet = libOptions.allFacets[facetKey];\n if (!facet) {\n this.logger.error('All Facet is not configured', { facetKey });\n res.status(500).json({ error: 'All Facet is not configured' });\n return;\n }\n try {\n const combinedQueryParams = { ...req.query, ...req.params } as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>;\n res.json(await libOperations.allFacet(facetKey, combinedQueryParams));\n } catch (err: any) {\n this.logger.error('Error in All Facet', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n }\n }\n\n protected postItemAction = async (req: Request, res: Response) => {\n const libOptions = this.lib.options;\n const libOperations = this.lib.operations;\n this.logger.debug('Posting Item Action', { query: req?.query, params: req?.params, locals: res?.locals });\n const ik = this.getIk(res);\n const actionKey = req.path.substring(req.path.lastIndexOf('/') + 1);\n\n // Check for router-level handler first\n if (this.options.actions && this.options.actions[actionKey]) {\n this.logger.debug('Using router-level action handler', { actionKey });\n try {\n const result = await this.options.actions[actionKey](\n ik,\n req.body as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n { req, res }\n );\n if (result != null) res.json(result);\n return;\n } catch (err: any) {\n this.logger.error('Error in router-level action', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n return;\n }\n }\n\n // Fallback to library handler\n if (!libOptions.actions) {\n this.logger.error('Item Actions are not configured');\n res.status(500).json({ error: 'Item Actions are not configured' });\n return;\n }\n const action = libOptions.actions[actionKey];\n if (!action) {\n this.logger.error('Item Action is not configured', { actionKey });\n res.status(500).json({ error: 'Item Action is not configured' });\n return;\n }\n try {\n res.json(await libOperations.action(ik, actionKey, req.body));\n } catch (err: any) {\n this.logger.error('Error in Item Action', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n }\n }\n\n protected getItemFacet = async (req: Request, res: Response) => {\n const libOptions = this.lib.options;\n const libOperations = this.lib.operations;\n this.logger.debug('Getting Item Facet', { query: req?.query, params: req?.params, locals: res?.locals });\n const ik = this.getIk(res);\n const facetKey = req.path.substring(req.path.lastIndexOf('/') + 1);\n\n // Check for router-level handler first\n if (this.options.facets && this.options.facets[facetKey]) {\n this.logger.debug('Using router-level facet handler', { facetKey });\n try {\n const result = await this.options.facets[facetKey](\n ik,\n req.query as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,\n { req, res }\n );\n if (result != null) res.json(result);\n return;\n } catch (err: any) {\n this.logger.error('Error in router-level facet', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n return;\n }\n }\n\n // Fallback to library handler\n if (!libOptions.facets) {\n this.logger.error('Item Facets are not configured');\n res.status(500).json({ error: 'Item Facets are not configured' });\n return;\n }\n const facet = libOptions.facets[facetKey];\n if (!facet) {\n this.logger.error('Item Facet is not configured', { facetKey });\n res.status(500).json({ error: 'Item Facet is not configured' });\n return;\n }\n try {\n const combinedQueryParams = { ...req.query, ...req.params } as Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>;\n res.json(await libOperations.facet(ik, facetKey, combinedQueryParams));\n } catch (err: any) {\n this.logger.error('Error in Item Facet', { message: err?.message, stack: err?.stack });\n res.status(500).json(err);\n }\n }\n\n private configure = (router: Router) => {\n const libOptions = this.lib.options;\n this.logger.debug('Configuring Router', { pkType: this.getPkType() });\n router.get('/', this.findItems);\n router.post('/', this.createItem);\n\n // Track registered routes to detect collisions\n const registeredAllActions = new Set<string>();\n const registeredAllFacets = new Set<string>();\n const registeredItemActions = new Set<string>();\n const registeredItemFacets = new Set<string>();\n\n // Configure router-level allActions first (highest precedence)\n this.logger.default('Router All Actions', { allActions: this.options.allActions });\n if (this.options.allActions) {\n Object.keys(this.options.allActions).forEach((actionKey) => {\n this.logger.debug('Configuring Router All Action %s', actionKey);\n router.post(`/${actionKey}`, this.postAllAction);\n registeredAllActions.add(actionKey);\n });\n }\n\n // Configure library allActions, warn on conflicts\n this.logger.default('Library All Actions', { allActions: libOptions.allActions });\n if (libOptions.allActions) {\n Object.keys(libOptions.allActions).forEach((actionKey) => {\n if (registeredAllActions.has(actionKey)) {\n this.logger.warning('All Action name collision - router-level handler takes precedence', { actionKey });\n } else {\n this.logger.debug('Configuring Library All Action %s', actionKey);\n router.post(`/${actionKey}`, this.postAllAction);\n registeredAllActions.add(actionKey);\n }\n });\n }\n\n // Configure router-level allFacets first (highest precedence)\n this.logger.default('Router All Facets', { allFacets: this.options.allFacets });\n if (this.options.allFacets) {\n Object.keys(this.options.allFacets).forEach((facetKey) => {\n this.logger.debug('Configuring Router All Facet %s', facetKey);\n router.get(`/${facetKey}`, this.getAllFacet);\n registeredAllFacets.add(facetKey);\n });\n }\n\n // Configure library allFacets, warn on conflicts\n this.logger.default('Library All Facets', { allFacets: libOptions.allFacets });\n if (libOptions.allFacets) {\n Object.keys(libOptions.allFacets).forEach((facetKey) => {\n if (registeredAllFacets.has(facetKey)) {\n this.logger.warning('All Facet name collision - router-level handler takes precedence', { facetKey });\n } else {\n this.logger.debug('Configuring Library All Facet %s', facetKey);\n router.get(`/${facetKey}`, this.getAllFacet);\n registeredAllFacets.add(facetKey);\n }\n });\n }\n\n const itemRouter = Router();\n itemRouter.get('/', this.getItem);\n itemRouter.put('/', this.updateItem);\n itemRouter.delete('/', this.deleteItem);\n\n // Configure router-level item actions first (highest precedence)\n this.logger.default('Router Item Actions', { itemActions: this.options.actions });\n if (this.options.actions) {\n Object.keys(this.options.actions).forEach((actionKey) => {\n this.logger.debug('Configuring Router Item Action %s', actionKey);\n itemRouter.post(`/${actionKey}`, this.postItemAction);\n registeredItemActions.add(actionKey);\n });\n }\n\n // Configure library item actions, warn on conflicts\n this.logger.default('Library Item Actions', { itemActions: libOptions.actions });\n if (libOptions.actions) {\n Object.keys(libOptions.actions).forEach((actionKey) => {\n if (registeredItemActions.has(actionKey)) {\n this.logger.warning('Item Action name collision - router-level handler takes precedence', { actionKey });\n } else {\n this.logger.debug('Configuring Library Item Action %s', actionKey);\n itemRouter.post(`/${actionKey}`, this.postItemAction);\n registeredItemActions.add(actionKey);\n }\n });\n }\n\n // Configure router-level item facets first (highest precedence)\n this.logger.default('Router Item Facets', { itemFacets: this.options.facets });\n if (this.options.facets) {\n Object.keys(this.options.facets).forEach((facetKey) => {\n this.logger.debug('Configuring Router Item Facet %s', facetKey);\n itemRouter.get(`/${facetKey}`, this.getItemFacet);\n registeredItemFacets.add(facetKey);\n });\n }\n\n // Configure library item facets, warn on conflicts\n this.logger.default('Library Item Facets', { itemFacets: libOptions.facets });\n if (libOptions.facets) {\n Object.keys(libOptions.facets).forEach((facetKey) => {\n if (registeredItemFacets.has(facetKey)) {\n this.logger.warning('Item Facet name collision - router-level handler takes precedence', { facetKey });\n } else {\n this.logger.debug('Configuring Library Item Facet %s', facetKey);\n itemRouter.get(`/${facetKey}`, this.getItemFacet);\n registeredItemFacets.add(facetKey);\n }\n });\n }\n\n this.logger.debug('Configuring Item Operations under PK Param %s', this.getPkParam());\n router.use(`/:${this.getPkParam()}`, this.validatePrimaryKeyValue, itemRouter);\n\n if (this.childRouters) {\n this.configureChildRouters(itemRouter, this.childRouters);\n }\n return router;\n }\n\n private validatePrimaryKeyValue = (req: Request, res: Response, next: any) => {\n const pkParamValue = req.params[this.getPkParam()];\n if (this.validatePKParam(pkParamValue)) {\n res.locals[this.getPkParam()] = pkParamValue;\n next();\n } else {\n this.logger.error('Invalid Primary Key', { pkParamValue, path: req?.originalUrl });\n res.status(500).json({ error: 'Invalid Primary Key', path: req?.originalUrl });\n }\n }\n\n private configureChildRouters = (router: Router, childRouters: Record<string, Router>) => {\n for (const path in childRouters) {\n this.logger.debug('Configuring Child Router at Path %s', path);\n\n router.use(`/${path}`, childRouters[path]);\n }\n return router;\n }\n\n public addChildRouter = (path: string, router: Router) => {\n this.childRouters[path] = router;\n }\n\n /* istanbul ignore next */\n public getRouter(): Router {\n const router = Router();\n this.configure(router);\n return router;\n }\n\n /* istanbul ignore next */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected createItem = async (req: Request, res: Response): Promise<void> => {\n throw new Error('Method not implemented in an abstract router');\n };\n\n // TODO: Probably a better way to do this, but this postCreate hook only needs the item.\n /* istanbul ignore next */\n public postCreateItem = async (item: Item<S, L1, L2, L3, L4, L5>): Promise<Item<S, L1, L2, L3, L4, L5>> => {\n this.logger.debug('Post Create Item', { item });\n return item;\n };\n\n protected deleteItem = async (req: Request, res: Response): Promise<void> => {\n const libOperations = this.lib.operations;\n\n this.logger.debug('Deleting Item', { query: req.query, params: req.params, locals: res.locals });\n const ik = this.getIk(res);\n try {\n const removedItem = await libOperations.remove(ik);\n const item = validatePK(removedItem, this.getPkType());\n res.json(item);\n } catch (err: any) {\n if (err instanceof NotFoundError) {\n this.logger.error('Item Not Found for Delete', { ik, message: err?.message, stack: err?.stack });\n res.status(404).json({\n ik,\n message: \"Item Not Found\",\n });\n } else {\n this.logger.error('General Error in Delete', { ik, message: err?.message, stack: err?.stack });\n res.status(500).json({\n ik,\n message: \"General Error\",\n });\n }\n }\n };\n\n /* eslint-disable */\n /* istanbul ignore next */\n protected findItems = async (req: Request, res: Response): Promise<void> => {\n throw new Error('Method not implemented in an abstract router');\n };\n /* eslint-enable */\n\n protected getItem = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n this.logger.debug('Getting Item', { query: req.query, params: req.params, locals: res.locals });\n const ik = this.getIk(res);\n try {\n // TODO: What error does validate PK throw, when can that fail?\n const item = validatePK(await libOperations.get(ik), this.getPkType());\n res.json(item);\n } catch (err: any) {\n if (err instanceof NotFoundError) {\n this.logger.error('Item Not Found', { ik, message: err?.message, stack: err?.stack });\n res.status(404).json({\n ik,\n message: \"Item Not Found\",\n });\n } else {\n this.logger.error('General Error', { ik, message: err?.message, stack: err?.stack });\n res.status(500).json({\n ik,\n message: \"General Error\",\n });\n }\n }\n }\n\n protected updateItem = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n this.logger.debug('Updating Item',\n { body: req?.body, query: req?.query, params: req?.params, locals: res?.locals });\n const ik = this.getIk(res);\n try {\n const itemToUpdate = this.convertDates(req.body as Partial<Item<S, L1, L2, L3, L4, L5>>);\n const retItem = validatePK(await libOperations.update(ik, itemToUpdate), this.getPkType());\n res.json(retItem);\n } catch (err: any) {\n if (err instanceof NotFoundError) {\n this.logger.error('Item Not Found for Update', { ik, message: err?.message, stack: err?.stack });\n res.status(404).json({\n ik,\n message: \"Item Not Found\",\n });\n } else {\n this.logger.error('General Error in Update', { ik, message: err?.message, stack: err?.stack });\n res.status(500).json({\n ik,\n message: \"General Error\",\n });\n }\n }\n };\n\n public convertDates = (item: Partial<Item<S, L1, L2, L3, L4, L5>>): Partial<Item<S, L1, L2, L3, L4, L5>> => {\n const events = item.events as Record<string, ItemEvent>;\n this.logger.debug('Converting Dates', { item });\n if (events) {\n Object.keys(events).forEach((key: string) => {\n Object.assign(events, {\n [key]: deepmerge(events[key], { at: events[key].at ? new Date(events[key].at) : null })\n });\n });\n }\n Object.assign(item, { events });\n return item;\n };\n\n // TODO: Maybe just simplify this and require that everything is a UUID?\n /**\n * This method might be an annoyance, but we need to capture a few cases where someone passes\n * a PK parameter that has an odd string in it.\n *\n * @param pkParamValue The value of the primary key parameter\n * @returns if the value is valid.\n */\n protected validatePKParam = (pkParamValue: string): boolean => {\n let validPkParam = true;\n if (pkParamValue.length <= 0) {\n this.logger.error('Primary Key is an Empty String', { pkParamValue });\n validPkParam = false;\n } else if (pkParamValue === 'undefined') {\n this.logger.error('Primary Key is the string \\'undefined\\'', { pkParamValue });\n validPkParam = false;\n }\n return validPkParam;\n }\n\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAEE;AAAA,EAMA;AAAA,OACK;AACP,SAAS,qBAAqB;AAE9B,OAAO,eAAe;AACtB,SAA4B,cAAc;AAC1C,OAAO,eAAe;AA6Gf,MAAM,WAOX;AAAA,EAEU;AAAA,EACF;AAAA,EACE;AAAA,EACF,eAAuC,CAAC;AAAA,EACtC;AAAA,EAEV,YACE,KACA,SACA,UAAoD,CAAC,GACrD;AACA,SAAK,MAAM;AACX,SAAK,UAAU;AACf,SAAK,UAAU;AACf,SAAK,SAAS,UAAU,IAAI,cAAc,OAAO;AAAA,EACnD;AAAA,EAEO,YAAY,MAAS;AAC1B,WAAO,KAAK;AAAA,EACd;AAAA,EAEU,aAAa,MAAc;AACnC,WAAO,GAAG,KAAK,UAAU,CAAC;AAAA,EAC5B;AAAA,EAEU,MAAM,KAA0B;AACxC,WAAO,EAAE,IAAI,KAAK,SAAS,IAAI,IAAI,OAAO,KAAK,WAAW,CAAC,EAAE;AAAA,EAC/D;AAAA;AAAA,EAGO,OAAO,KAA+C;AAC3D,WAAO,CAAC,KAAK,MAAM,GAAG,CAAC;AAAA,EACzB;AAAA,EAEO,MAAM,KAA0B;AACrC,WAAO,IAAO,IAAI,OAAO,KAAK,WAAW,CAAC,GAAG,KAAK,UAAU,CAAC;AAAA,EAC/D;AAAA;AAAA;AAAA,EAIU,aAAa,KAAqD;AAC1E,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AAAA;AAAA;AAAA,EAIU,MAAM,KAA0D;AACxE,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AAAA,EAEU,gBAAgB,OAAO,KAAc,QAAkB;AAC/D,UAAM,aAAa,KAAK,IAAI;AAC5B,UAAM,gBAAgB,KAAK,IAAI;AAC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AAC;AAC7F,YAAI,OAAO,GAAG,EAAE,KAAK;AAAA,UACnB;AAAA,UACA,SAAS;AAAA,QACX,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EAEO,eAAe,CAAC,SAAqF;AAC1G,UAAM,SAAS,KAAK;AACpB,SAAK,OAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC;AAC9C,QAAI,QAAQ;AACV,aAAO,KAAK,MAAM,EAAE,QAAQ,CAAC,QAAgB;AAC3C,eAAO,OAAO,QAAQ;AAAA,UACpB,CAAC,GAAG,GAAG,UAAU,OAAO,GAAG,GAAG,EAAE,IAAI,OAAO,GAAG,EAAE,KAAK,IAAI,KAAK,OAAO,GAAG,EAAE,EAAE,IAAI,KAAK,CAAC;AAAA,QACxF,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AACA,WAAO,OAAO,MAAM,EAAE,OAAO,CAAC;AAC9B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUU,kBAAkB,CAAC,iBAAkC;AAC7D,QAAI,eAAe;AACnB,QAAI,aAAa,UAAU,GAAG;AAC5B,WAAK,OAAO,MAAM,kCAAkC,EAAE,aAAa,CAAC;AACpE,qBAAe;AAAA,IACjB,WAAW,iBAAiB,aAAa;AACvC,WAAK,OAAO,MAAM,yCAA2C,EAAE,aAAa,CAAC;AAC7E,qBAAe;AAAA,IACjB;AACA,WAAO;AAAA,EACT;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/PItemRouter.js
CHANGED
|
@@ -15,7 +15,7 @@ class PItemRouter extends ItemRouter {
|
|
|
15
15
|
let item = validatePK(await libOperations.create(itemToCreate), this.getPkType());
|
|
16
16
|
item = await this.postCreateItem(item);
|
|
17
17
|
this.logger.default("Created Item %j", item);
|
|
18
|
-
res.json(item);
|
|
18
|
+
res.status(201).json(item);
|
|
19
19
|
};
|
|
20
20
|
findItems = async (req, res) => {
|
|
21
21
|
const libOperations = this.lib.operations;
|
package/dist/PItemRouter.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/PItemRouter.ts"],
|
|
4
|
-
"sourcesContent": ["import { Item, ItemQuery, paramsToQuery, PriKey, QueryParams, validatePK } from \"@fjell/core\";\nimport { ItemRouter, ItemRouterOptions } from \"./ItemRouter.js\";\nimport { Instance } from \"./Instance.js\";\nimport { Request, Response } from \"express\";\n\ninterface ParsedQuery {\n [key: string]: undefined | string | string[] | ParsedQuery | ParsedQuery[];\n}\n\nexport class PItemRouter<T extends Item<S>, S extends string> extends ItemRouter<S> {\n\n constructor(lib: Instance<T, S>, keyType: S, options: ItemRouterOptions<S, never, never, never, never, never> = {}) {\n super(lib as any, keyType, options);\n }\n\n public getIk(res: Response): PriKey<S> {\n const pri = this.getPk(res) as PriKey<S>;\n return pri\n }\n\n public createItem = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n this.logger.default('Creating Item', { body: req.body, query: req.query, params: req.params, locals: res.locals });\n const itemToCreate = this.convertDates(req.body as Item<S>);\n let item = validatePK(await libOperations.create(itemToCreate), this.getPkType()) as Item<S>;\n item = await this.postCreateItem(item);\n this.logger.default('Created Item %j', item);\n res.json(item);\n };\n\n protected findItems = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n this.logger.default('Finding Items', { query: req.query, params: req.params, locals: res.locals });\n\n let items: Item<S>[] = [];\n\n const query: ParsedQuery = req.query as unknown as ParsedQuery;\n const finder = query['finder'] as string;\n const finderParams = query['finderParams'] as string;\n const one = query['one'] as string;\n\n if (finder) {\n // If finder is defined? Call a finder.\n this.logger.default('Finding Items with Finder %s %j one:%s', finder, finderParams, one);\n\n if (one === 'true') {\n const item = await (this.lib as any).findOne(finder, JSON.parse(finderParams));\n items = item ? [item] : [];\n } else {\n items = await libOperations.find(finder, JSON.parse(finderParams));\n }\n } else {\n // TODO: This is once of the more important places to perform some validaation and feedback\n const itemQuery: ItemQuery = paramsToQuery(req.query as QueryParams);\n this.logger.default('Finding Items with a query %j', itemQuery);\n items = await libOperations.all(itemQuery);\n }\n\n res.json(items.map((item: Item<S>) => validatePK(item, this.getPkType())));\n };\n\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAA0B,eAAoC,kBAAkB;AAChF,SAAS,kBAAqC;AAQvC,MAAM,oBAAyD,WAAc;AAAA,EAElF,YAAY,KAAqB,SAAY,UAAmE,CAAC,GAAG;AAClH,UAAM,KAAY,SAAS,OAAO;AAAA,EACpC;AAAA,EAEO,MAAM,KAA0B;AACrC,UAAM,MAAM,KAAK,MAAM,GAAG;AAC1B,WAAO;AAAA,EACT;AAAA,EAEO,aAAa,OAAO,KAAc,QAAkB;AACzD,UAAM,gBAAgB,KAAK,IAAI;AAC/B,SAAK,OAAO,QAAQ,iBAAiB,EAAE,MAAM,IAAI,MAAM,OAAO,IAAI,OAAO,QAAQ,IAAI,QAAQ,QAAQ,IAAI,OAAO,CAAC;AACjH,UAAM,eAAe,KAAK,aAAa,IAAI,IAAe;AAC1D,QAAI,OAAO,WAAW,MAAM,cAAc,OAAO,YAAY,GAAG,KAAK,UAAU,CAAC;AAChF,WAAO,MAAM,KAAK,eAAe,IAAI;AACrC,SAAK,OAAO,QAAQ,mBAAmB,IAAI;AAC3C,QAAI,KAAK,IAAI;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Item, ItemQuery, paramsToQuery, PriKey, QueryParams, validatePK } from \"@fjell/core\";\nimport { ItemRouter, ItemRouterOptions } from \"./ItemRouter.js\";\nimport { Instance } from \"./Instance.js\";\nimport { Request, Response } from \"express\";\n\ninterface ParsedQuery {\n [key: string]: undefined | string | string[] | ParsedQuery | ParsedQuery[];\n}\n\nexport class PItemRouter<T extends Item<S>, S extends string> extends ItemRouter<S> {\n\n constructor(lib: Instance<T, S>, keyType: S, options: ItemRouterOptions<S, never, never, never, never, never> = {}) {\n super(lib as any, keyType, options);\n }\n\n public getIk(res: Response): PriKey<S> {\n const pri = this.getPk(res) as PriKey<S>;\n return pri\n }\n\n public createItem = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n this.logger.default('Creating Item', { body: req.body, query: req.query, params: req.params, locals: res.locals });\n const itemToCreate = this.convertDates(req.body as Item<S>);\n let item = validatePK(await libOperations.create(itemToCreate), this.getPkType()) as Item<S>;\n item = await this.postCreateItem(item);\n this.logger.default('Created Item %j', item);\n res.status(201).json(item);\n };\n\n protected findItems = async (req: Request, res: Response) => {\n const libOperations = this.lib.operations;\n this.logger.default('Finding Items', { query: req.query, params: req.params, locals: res.locals });\n\n let items: Item<S>[] = [];\n\n const query: ParsedQuery = req.query as unknown as ParsedQuery;\n const finder = query['finder'] as string;\n const finderParams = query['finderParams'] as string;\n const one = query['one'] as string;\n\n if (finder) {\n // If finder is defined? Call a finder.\n this.logger.default('Finding Items with Finder %s %j one:%s', finder, finderParams, one);\n\n if (one === 'true') {\n const item = await (this.lib as any).findOne(finder, JSON.parse(finderParams));\n items = item ? [item] : [];\n } else {\n items = await libOperations.find(finder, JSON.parse(finderParams));\n }\n } else {\n // TODO: This is once of the more important places to perform some validaation and feedback\n const itemQuery: ItemQuery = paramsToQuery(req.query as QueryParams);\n this.logger.default('Finding Items with a query %j', itemQuery);\n items = await libOperations.all(itemQuery);\n }\n\n res.json(items.map((item: Item<S>) => validatePK(item, this.getPkType())));\n };\n\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAA0B,eAAoC,kBAAkB;AAChF,SAAS,kBAAqC;AAQvC,MAAM,oBAAyD,WAAc;AAAA,EAElF,YAAY,KAAqB,SAAY,UAAmE,CAAC,GAAG;AAClH,UAAM,KAAY,SAAS,OAAO;AAAA,EACpC;AAAA,EAEO,MAAM,KAA0B;AACrC,UAAM,MAAM,KAAK,MAAM,GAAG;AAC1B,WAAO;AAAA,EACT;AAAA,EAEO,aAAa,OAAO,KAAc,QAAkB;AACzD,UAAM,gBAAgB,KAAK,IAAI;AAC/B,SA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AA,EAC3E;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -39,6 +39,10 @@ export interface Task extends Item<'task'> {
|
|
|
39
39
|
const mockUserStorage = new Map<string, User>();
|
|
40
40
|
const mockTaskStorage = new Map<string, Task>();
|
|
41
41
|
|
|
42
|
+
// Counters for unique ID generation
|
|
43
|
+
let userIdCounter = 1000;
|
|
44
|
+
let taskIdCounter = 1000;
|
|
45
|
+
|
|
42
46
|
// Initialize with some sample data
|
|
43
47
|
const initializeSampleData = () => {
|
|
44
48
|
const users: User[] = [
|
|
@@ -130,7 +134,7 @@ const createUserOperations = () => {
|
|
|
130
134
|
|
|
131
135
|
async create(item: User) {
|
|
132
136
|
console.log(`✨ UserOperations.create() - Creating user: ${item.name}`);
|
|
133
|
-
const id = `user-${
|
|
137
|
+
const id = `user-${++userIdCounter}`;
|
|
134
138
|
const newUser: User = {
|
|
135
139
|
...item,
|
|
136
140
|
id,
|
|
@@ -170,7 +174,7 @@ const createUserOperations = () => {
|
|
|
170
174
|
return false;
|
|
171
175
|
}
|
|
172
176
|
mockUserStorage.delete(String(key.pk));
|
|
173
|
-
return
|
|
177
|
+
return existing;
|
|
174
178
|
},
|
|
175
179
|
|
|
176
180
|
async find(finder: string, params: any) {
|
|
@@ -207,7 +211,7 @@ const createTaskOperations = () => {
|
|
|
207
211
|
|
|
208
212
|
async create(item: Task) {
|
|
209
213
|
console.log(`✨ TaskOperations.create() - Creating task: ${item.title}`);
|
|
210
|
-
const id = `task-${
|
|
214
|
+
const id = `task-${++taskIdCounter}`;
|
|
211
215
|
const newTask: Task = {
|
|
212
216
|
...item,
|
|
213
217
|
id,
|
|
@@ -247,7 +251,7 @@ const createTaskOperations = () => {
|
|
|
247
251
|
return false;
|
|
248
252
|
}
|
|
249
253
|
mockTaskStorage.delete(String(key.pk));
|
|
250
|
-
return
|
|
254
|
+
return existing;
|
|
251
255
|
},
|
|
252
256
|
|
|
253
257
|
async find(finder: string, params: any) {
|
|
@@ -86,6 +86,13 @@ const mockReviewStorage = new Map<string, Review>();
|
|
|
86
86
|
|
|
87
87
|
// ===== Sample Data Initialization =====
|
|
88
88
|
const initializeSampleData = () => {
|
|
89
|
+
// Clear existing data
|
|
90
|
+
mockCustomerStorage.clear();
|
|
91
|
+
mockProductStorage.clear();
|
|
92
|
+
mockOrderStorage.clear();
|
|
93
|
+
mockOrderItemStorage.clear();
|
|
94
|
+
mockReviewStorage.clear();
|
|
95
|
+
|
|
89
96
|
// Sample customers
|
|
90
97
|
const customers: Customer[] = [
|
|
91
98
|
{
|
|
@@ -489,10 +496,19 @@ export const runFullApplicationExample = async (): Promise<{ app: Application }>
|
|
|
489
496
|
app.use('/api/customers', (req, res, next) => {
|
|
490
497
|
// Only validate for direct customer creation, not nested routes like orders
|
|
491
498
|
if (req.method === 'POST' && req.path === '/') {
|
|
492
|
-
const { name, email } = req.body;
|
|
499
|
+
const { name, email, phone, address, tier } = req.body;
|
|
493
500
|
if (!name || !email) {
|
|
494
501
|
return res.status(500).json({ error: 'Missing required fields: name and email' });
|
|
495
502
|
}
|
|
503
|
+
if (!phone || !address || !tier) {
|
|
504
|
+
return res.status(500).json({ error: 'Missing required fields: phone, address, and tier' });
|
|
505
|
+
}
|
|
506
|
+
if (!address.street || !address.city || !address.state || !address.zipCode) {
|
|
507
|
+
return res.status(500).json({ error: 'Missing required address fields: street, city, state, and zipCode' });
|
|
508
|
+
}
|
|
509
|
+
if (!['bronze', 'silver', 'gold', 'platinum'].includes(tier)) {
|
|
510
|
+
return res.status(500).json({ error: 'Invalid tier. Must be bronze, silver, gold, or platinum' });
|
|
511
|
+
}
|
|
496
512
|
}
|
|
497
513
|
next();
|
|
498
514
|
});
|
|
@@ -553,7 +569,24 @@ export const runFullApplicationExample = async (): Promise<{ app: Application }>
|
|
|
553
569
|
});
|
|
554
570
|
app.use('/api/customers/:customerPk/orders', orderRouter.getRouter());
|
|
555
571
|
|
|
556
|
-
//
|
|
572
|
+
// Security validation middleware for customer routes - must be BEFORE router
|
|
573
|
+
app.use('/api/customers/:customerPk', (req, res, next) => {
|
|
574
|
+
const { customerPk } = req.params;
|
|
575
|
+
|
|
576
|
+
// Check for path traversal attempts
|
|
577
|
+
if (customerPk.includes('../') || customerPk.includes('..\\') || customerPk.includes('%2e%2e')) {
|
|
578
|
+
return res.status(500).json({ error: 'Path traversal attempt detected' });
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// Check for null byte injection
|
|
582
|
+
if (customerPk.includes('\x00') || customerPk.includes('%00') || customerPk.includes('\u0000')) {
|
|
583
|
+
return res.status(500).json({ error: 'Null byte injection attempt detected' });
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
next();
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
// Customer router after security validation
|
|
557
590
|
app.use('/api/customers', customerRouter.getRouter());
|
|
558
591
|
|
|
559
592
|
// Custom find routes for better test compatibility
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/**
|
|
3
|
+
* Example: Router-Level Options with Name Collision Handling
|
|
4
|
+
*
|
|
5
|
+
* This example demonstrates how router-level actions, facets, allActions, and allFacets
|
|
6
|
+
* take precedence over library-level options with the same names, and how collision
|
|
7
|
+
* warnings are logged when there are conflicts.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { ItemRouter, ItemRouterOptions } from "../src/ItemRouter.js";
|
|
11
|
+
import { ComKey, Item, LocKeyArray, PriKey } from "@fjell/core";
|
|
12
|
+
import { Request, Response } from "express";
|
|
13
|
+
|
|
14
|
+
// Sample Item Types
|
|
15
|
+
type User = Item<"user", "tenant">;
|
|
16
|
+
type Tenant = Item<"tenant">;
|
|
17
|
+
|
|
18
|
+
// Mock library instance with actions/facets that will collide with router options
|
|
19
|
+
const mockLibWithConflicts = {
|
|
20
|
+
operations: {
|
|
21
|
+
get: async () => ({ key: { kt: "user", pk: "user-1" }, name: "John Doe" } as User),
|
|
22
|
+
create: async () => ({ key: { kt: "user", pk: "user-2" }, name: "Jane Doe" } as User),
|
|
23
|
+
update: async () => ({ key: { kt: "user", pk: "user-1" }, name: "John Updated" } as User),
|
|
24
|
+
remove: async () => ({ key: { kt: "user", pk: "user-1" }, name: "John Doe" } as User),
|
|
25
|
+
all: async () => [] as User[],
|
|
26
|
+
find: async () => [] as User[],
|
|
27
|
+
findOne: async () => null,
|
|
28
|
+
action: async (ik: any, actionKey: string) => ({ source: "library", action: actionKey }),
|
|
29
|
+
facet: async (ik: any, facetKey: string) => ({ source: "library", facet: facetKey }),
|
|
30
|
+
allAction: async (actionKey: string) => ({ source: "library", allAction: actionKey }),
|
|
31
|
+
allFacet: async (facetKey: string) => ({ source: "library", allFacet: facetKey })
|
|
32
|
+
},
|
|
33
|
+
options: {
|
|
34
|
+
// These will collide with router-level options
|
|
35
|
+
actions: {
|
|
36
|
+
activate: async () => ({ source: "library", action: "activate" }),
|
|
37
|
+
archive: async () => ({ source: "library", action: "archive" })
|
|
38
|
+
},
|
|
39
|
+
facets: {
|
|
40
|
+
profile: async () => ({ source: "library", facet: "profile" }),
|
|
41
|
+
settings: async () => ({ source: "library", facet: "settings" })
|
|
42
|
+
},
|
|
43
|
+
allActions: {
|
|
44
|
+
bulkUpdate: async () => ({ source: "library", allAction: "bulkUpdate" }),
|
|
45
|
+
export: async () => ({ source: "library", allAction: "export" })
|
|
46
|
+
},
|
|
47
|
+
allFacets: {
|
|
48
|
+
analytics: async () => ({ source: "library", allFacet: "analytics" }),
|
|
49
|
+
dashboard: async () => ({ source: "library", allFacet: "dashboard" })
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
class UserRouter extends ItemRouter<"user", "tenant"> {
|
|
55
|
+
protected getIk(res: Response): ComKey<"user", "tenant"> {
|
|
56
|
+
return {
|
|
57
|
+
kt: "user",
|
|
58
|
+
pk: res.locals.userPk,
|
|
59
|
+
loc: [{ kt: "tenant", lk: res.locals.tenantId || "tenant-1" }]
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected getLocations(res: Response): LocKeyArray<"tenant"> {
|
|
64
|
+
return [{ kt: "tenant", lk: res.locals.tenantId || "tenant-1" }];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public createItem = async (req: Request, res: Response): Promise<void> => {
|
|
68
|
+
const newUser: User = {
|
|
69
|
+
key: { kt: "user", pk: "user-new", loc: this.getLocations(res) },
|
|
70
|
+
name: req.body.name || "New User",
|
|
71
|
+
email: req.body.email || "new@example.com",
|
|
72
|
+
events: {
|
|
73
|
+
created: { at: new Date() },
|
|
74
|
+
updated: { at: new Date() },
|
|
75
|
+
deleted: { at: null }
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
res.json(newUser);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
public findItems = async (req: Request, res: Response): Promise<void> => {
|
|
82
|
+
const users: User[] = [
|
|
83
|
+
{
|
|
84
|
+
key: { kt: "user", pk: "user-1", loc: this.getLocations(res) },
|
|
85
|
+
name: "John Doe",
|
|
86
|
+
email: "john@example.com",
|
|
87
|
+
events: {
|
|
88
|
+
created: { at: new Date() },
|
|
89
|
+
updated: { at: new Date() },
|
|
90
|
+
deleted: { at: null }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
];
|
|
94
|
+
res.json(users);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Router-level options that will take precedence over library options
|
|
100
|
+
* Notice some of these have the same names as the library options
|
|
101
|
+
*/
|
|
102
|
+
const routerOptions: ItemRouterOptions<"user", "tenant"> = {
|
|
103
|
+
// These will override library actions with same names
|
|
104
|
+
actions: {
|
|
105
|
+
activate: async (ik, params, { req, res }) => {
|
|
106
|
+
console.log("🚀 Router-level activate action called!");
|
|
107
|
+
return { source: "router", action: "activate", ik, params };
|
|
108
|
+
},
|
|
109
|
+
archive: async (ik, params, { req, res }) => {
|
|
110
|
+
console.log("📦 Router-level archive action called!");
|
|
111
|
+
return { source: "router", action: "archive", ik, params };
|
|
112
|
+
},
|
|
113
|
+
// This one is unique to router
|
|
114
|
+
resetPassword: async (ik, params, { req, res }) => {
|
|
115
|
+
console.log("🔑 Router-level resetPassword action called!");
|
|
116
|
+
return { source: "router", action: "resetPassword", ik, params };
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
// These will override library facets with same names
|
|
121
|
+
facets: {
|
|
122
|
+
profile: async (ik, params, { req, res }) => {
|
|
123
|
+
console.log("👤 Router-level profile facet called!");
|
|
124
|
+
return { source: "router", facet: "profile", ik, params };
|
|
125
|
+
},
|
|
126
|
+
settings: async (ik, params, { req, res }) => {
|
|
127
|
+
console.log("⚙️ Router-level settings facet called!");
|
|
128
|
+
return { source: "router", facet: "settings", ik, params };
|
|
129
|
+
},
|
|
130
|
+
// This one is unique to router
|
|
131
|
+
permissions: async (ik, params, { req, res }) => {
|
|
132
|
+
console.log("🔒 Router-level permissions facet called!");
|
|
133
|
+
return { source: "router", facet: "permissions", ik, params };
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
// These will override library allActions with same names
|
|
138
|
+
allActions: {
|
|
139
|
+
bulkUpdate: async (params, locations, { req, res }) => {
|
|
140
|
+
console.log("📝 Router-level bulkUpdate allAction called!");
|
|
141
|
+
return { source: "router", allAction: "bulkUpdate", params, locations };
|
|
142
|
+
},
|
|
143
|
+
export: async (params, locations, { req, res }) => {
|
|
144
|
+
console.log("📤 Router-level export allAction called!");
|
|
145
|
+
return { source: "router", allAction: "export", params, locations };
|
|
146
|
+
},
|
|
147
|
+
// This one is unique to router
|
|
148
|
+
backup: async (params, locations, { req, res }) => {
|
|
149
|
+
console.log("💾 Router-level backup allAction called!");
|
|
150
|
+
return { source: "router", allAction: "backup", params, locations };
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
// These will override library allFacets with same names
|
|
155
|
+
allFacets: {
|
|
156
|
+
analytics: async (params, locations, { req, res }) => {
|
|
157
|
+
console.log("📊 Router-level analytics allFacet called!");
|
|
158
|
+
return { source: "router", allFacet: "analytics", params, locations };
|
|
159
|
+
},
|
|
160
|
+
dashboard: async (params, locations, { req, res }) => {
|
|
161
|
+
console.log("📈 Router-level dashboard allFacet called!");
|
|
162
|
+
return { source: "router", allFacet: "dashboard", params, locations };
|
|
163
|
+
},
|
|
164
|
+
// This one is unique to router
|
|
165
|
+
reports: async (params, locations, { req, res }) => {
|
|
166
|
+
console.log("📋 Router-level reports allFacet called!");
|
|
167
|
+
return { source: "router", allFacet: "reports", params, locations };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export function createRouterWithCollisions() {
|
|
173
|
+
console.log("🎭 Creating UserRouter with router-level options that collide with library options...");
|
|
174
|
+
console.log("⚠️ Watch for collision warnings in the logs!");
|
|
175
|
+
|
|
176
|
+
// Create router with options that will collide with library options
|
|
177
|
+
const userRouter = new UserRouter(mockLibWithConflicts as any, "user", routerOptions);
|
|
178
|
+
|
|
179
|
+
console.log("✅ Router created successfully!");
|
|
180
|
+
console.log("📋 Available endpoints with precedence:");
|
|
181
|
+
console.log(" Actions (router overrides library):");
|
|
182
|
+
console.log(" ✅ POST /users/:userPk/activate (Router-level handler)");
|
|
183
|
+
console.log(" ✅ POST /users/:userPk/archive (Router-level handler)");
|
|
184
|
+
console.log(" 🆕 POST /users/:userPk/resetPassword (Router-only)");
|
|
185
|
+
console.log(" Facets (router overrides library):");
|
|
186
|
+
console.log(" ✅ GET /users/:userPk/profile (Router-level handler)");
|
|
187
|
+
console.log(" ✅ GET /users/:userPk/settings (Router-level handler)");
|
|
188
|
+
console.log(" 🆕 GET /users/:userPk/permissions (Router-only)");
|
|
189
|
+
console.log(" All Actions (router overrides library):");
|
|
190
|
+
console.log(" ✅ POST /users/bulkUpdate (Router-level handler)");
|
|
191
|
+
console.log(" ✅ POST /users/export (Router-level handler)");
|
|
192
|
+
console.log(" 🆕 POST /users/backup (Router-only)");
|
|
193
|
+
console.log(" All Facets (router overrides library):");
|
|
194
|
+
console.log(" ✅ GET /users/analytics (Router-level handler)");
|
|
195
|
+
console.log(" ✅ GET /users/dashboard (Router-level handler)");
|
|
196
|
+
console.log(" 🆕 GET /users/reports (Router-only)");
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
userRouter,
|
|
200
|
+
expressRouter: userRouter.getRouter()
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Example usage
|
|
205
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
206
|
+
console.log("🚀 Starting Router Options Collision Example...");
|
|
207
|
+
console.log("=".repeat(60));
|
|
208
|
+
|
|
209
|
+
const { userRouter, expressRouter } = createRouterWithCollisions();
|
|
210
|
+
|
|
211
|
+
console.log("=".repeat(60));
|
|
212
|
+
console.log("✅ Example complete! Check the logs above for collision warnings.");
|
|
213
|
+
console.log("💡 Router-level handlers take precedence over library handlers with the same names.");
|
|
214
|
+
}
|
package/package.json
CHANGED