@fjell/express-router 4.4.4 → 4.4.5
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/commit.sh +8 -0
- package/dist/CItemRouter.cjs +10 -15
- package/dist/CItemRouter.cjs.map +1 -1
- package/dist/CItemRouter.d.ts +1 -1
- package/dist/CItemRouter.js +10 -15
- package/dist/CItemRouter.js.map +1 -1
- package/dist/ItemRouter.cjs +61 -61
- package/dist/ItemRouter.cjs.map +1 -1
- package/dist/ItemRouter.d.ts +6 -6
- package/dist/ItemRouter.js +61 -61
- package/dist/ItemRouter.js.map +1 -1
- package/dist/PItemRouter.cjs +10 -15
- package/dist/PItemRouter.cjs.map +1 -1
- package/dist/PItemRouter.d.ts +1 -1
- package/dist/PItemRouter.js +10 -15
- package/dist/PItemRouter.js.map +1 -1
- package/dist/index.cjs +81 -89
- package/dist/index.cjs.map +1 -1
- package/dist/util/general.d.ts +4 -0
- package/package.json +11 -11
- package/pnpm-workspace.yaml.bak +4 -0
- package/release.sh +89 -0
- package/src/CItemRouter.ts +12 -14
- package/src/ItemRouter.ts +64 -53
- package/src/PItemRouter.ts +11 -12
- package/src/util/general.ts +65 -0
package/commit.sh
ADDED
package/dist/CItemRouter.cjs
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
|
|
5
5
|
const core = require('@fjell/core');
|
|
6
6
|
const ItemRouter = require('./ItemRouter.cjs');
|
|
7
|
-
const logger$1 = require('./logger.cjs');
|
|
8
7
|
|
|
9
8
|
function _define_property(obj, key, value) {
|
|
10
9
|
if (key in obj) {
|
|
@@ -19,7 +18,6 @@ function _define_property(obj, key, value) {
|
|
|
19
18
|
}
|
|
20
19
|
return obj;
|
|
21
20
|
}
|
|
22
|
-
const logger = logger$1.default.get('CItemRouter');
|
|
23
21
|
class CItemRouter extends ItemRouter.ItemRouter {
|
|
24
22
|
hasParent() {
|
|
25
23
|
return !!this.parentRoute;
|
|
@@ -49,24 +47,22 @@ class CItemRouter extends ItemRouter.ItemRouter {
|
|
|
49
47
|
}
|
|
50
48
|
constructor(lib, type, parentRoute, options = {}){
|
|
51
49
|
super(lib, type, options), _define_property(this, "parentRoute", void 0), _define_property(this, "createItem", async (req, res)=>{
|
|
52
|
-
|
|
50
|
+
const libOperations = this.lib.operations;
|
|
51
|
+
this.logger.default('Creating Item', {
|
|
53
52
|
body: req === null || req === void 0 ? void 0 : req.body,
|
|
54
53
|
query: req === null || req === void 0 ? void 0 : req.query,
|
|
55
54
|
params: req === null || req === void 0 ? void 0 : req.params,
|
|
56
55
|
locals: res === null || res === void 0 ? void 0 : res.locals
|
|
57
56
|
});
|
|
58
57
|
const itemToCreate = this.convertDates(req.body);
|
|
59
|
-
let item = core.validatePK(await
|
|
58
|
+
let item = core.validatePK(await libOperations.create(itemToCreate, {
|
|
60
59
|
locations: this.getLocations(res)
|
|
61
60
|
}), this.getPkType());
|
|
62
61
|
item = await this.postCreateItem(item);
|
|
62
|
+
this.logger.default('Created Item %j', item);
|
|
63
63
|
res.json(item);
|
|
64
64
|
}), _define_property(this, "findItems", async (req, res)=>{
|
|
65
|
-
|
|
66
|
-
query: req.query,
|
|
67
|
-
params: req.params,
|
|
68
|
-
locals: res.locals
|
|
69
|
-
});
|
|
65
|
+
const libOperations = this.lib.operations;
|
|
70
66
|
const query = req.query;
|
|
71
67
|
const finder = query['finder'];
|
|
72
68
|
const finderParams = query['finderParams'];
|
|
@@ -74,7 +70,7 @@ class CItemRouter extends ItemRouter.ItemRouter {
|
|
|
74
70
|
let items = [];
|
|
75
71
|
if (finder) {
|
|
76
72
|
// If finder is defined? Call a finder.
|
|
77
|
-
logger.
|
|
73
|
+
this.logger.default('Finding Items with Finder', {
|
|
78
74
|
finder,
|
|
79
75
|
finderParams,
|
|
80
76
|
one
|
|
@@ -85,15 +81,14 @@ class CItemRouter extends ItemRouter.ItemRouter {
|
|
|
85
81
|
item
|
|
86
82
|
] : [];
|
|
87
83
|
} else {
|
|
88
|
-
items = await
|
|
84
|
+
items = await libOperations.find(finder, JSON.parse(finderParams), this.getLocations(res));
|
|
89
85
|
}
|
|
90
86
|
} else {
|
|
91
|
-
logger.trace('Finding Items with a query', {
|
|
92
|
-
query: req.query
|
|
93
|
-
});
|
|
94
87
|
// TODO: This is once of the more important places to perform some validaation and feedback
|
|
95
88
|
const itemQuery = core.paramsToQuery(req.query);
|
|
96
|
-
|
|
89
|
+
this.logger.default('Finding Items with Query: %j', itemQuery);
|
|
90
|
+
items = await libOperations.all(itemQuery, this.getLocations(res));
|
|
91
|
+
this.logger.default('Found %d Items with Query', items.length);
|
|
97
92
|
}
|
|
98
93
|
res.json(items.map((item)=>core.validatePK(item, this.getPkType())));
|
|
99
94
|
});
|
package/dist/CItemRouter.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CItemRouter.cjs","sources":["../src/CItemRouter.ts"],"sourcesContent":["import {\n ComKey, Item, ItemQuery, LocKey, LocKeyArray, paramsToQuery, PriKey, QueryParams, validatePK\n} from \"@fjell/core\";\nimport { Request, Response } from \"express\";\nimport { ItemRouter, ItemRouterOptions } from \"@/ItemRouter\";\nimport
|
|
1
|
+
{"version":3,"file":"CItemRouter.cjs","sources":["../src/CItemRouter.ts"],"sourcesContent":["import {\n ComKey, Item, ItemQuery, LocKey, LocKeyArray, paramsToQuery, PriKey, QueryParams, validatePK\n} from \"@fjell/core\";\nimport { Request, Response } from \"express\";\nimport { ItemRouter, ItemRouterOptions } from \"@/ItemRouter\";\nimport { Contained } from \"@fjell/lib\";\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: Contained.Instance<T, S, L1, L2, L3, L4, L5>,\n type: S,\n parentRoute: ItemRouter<L1, L2, L3, L4, L5, never>,\n options: ItemRouterOptions = {},\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 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 };\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"],"names":["CItemRouter","ItemRouter","hasParent","parentRoute","getIk","res","pri","getPk","loc","getLocations","kt","pk","getLKA","lka","getLk","concat","lib","type","options","createItem","req","libOperations","operations","logger","default","body","query","params","locals","itemToCreate","convertDates","item","validatePK","create","locations","getPkType","postCreateItem","json","findItems","finder","finderParams","one","items","findOne","JSON","parse","find","itemQuery","paramsToQuery","all","length","map"],"mappings":";;;;;;;;;;;;;;;;;;;;AAWO,MAAMA,WAAAA,SAQHC,qBAAAA,CAAAA;IAcDC,SAAAA,GAAqB;AAC1B,QAAA,OAAO,CAAC,CAAC,IAAI,CAACC,WAAW;AAC3B;AAEOC,IAAAA,KAAAA,CAAMC,GAAa,EAAiC;AACzD,QAAA,MAAMC,GAAAA,GAAM,IAAI,CAACC,KAAK,CAACF,GAAAA,CAAAA;AACvB,QAAA,MAAMG,GAAAA,GAAM,IAAI,CAACC,YAAY,CAACJ,GAAAA,CAAAA;QAC9B,OAAO;AAAEK,YAAAA,EAAAA,EAAIJ,IAAII,EAAE;AAAEC,YAAAA,EAAAA,EAAIL,IAAIK,EAAE;AAAEH,YAAAA;AAAI,SAAA;AACvC;AAEOI,IAAAA,MAAAA,CAAOP,GAAa,EAAkC;AAC3D;;;;AA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AC/B,YAAY,CAACJ,GAAAA,CAAAA,CAAAA;AACjGqC,oBAAAA,KAAAA,GAAQX,IAAAA,GAAO;AAACA,wBAAAA;AAAK,qBAAA,GAAG,EAAE;iBAC5B,MAAO;AACLW,oBAAAA,KAAAA,GAAQ,MAAMrB,aAAAA,CAAcyB,IAAI,CAACP,MAAAA,EAAQK,IAAAA,CAAKC,KAAK,CAACL,YAAAA,CAAAA,EAAe,IAAI,CAAC/B,YAAY,CAACJ,GAAAA,CAAAA,CAAAA;AACvF;aACF,MAAO;;gBAEL,MAAM0C,SAAAA,GAAuBC,kBAAAA,CAAc5B,GAAAA,CAAIM,KAAK,CAAA;AACpD,gBAAA,IAAI,CAACH,MAAM,CAACC,OAAO,CAAC,8BAAA,EAAgCuB,SAAAA,CAAAA;gBACpDL,KAAAA,GAAQ,MAAMrB,cAAc4B,GAAG,CAACF,WAAW,IAAI,CAACtC,YAAY,CAACJ,GAAAA,CAAAA,CAAAA;AAC7D,gBAAA,IAAI,CAACkB,MAAM,CAACC,OAAO,CAAC,2BAAA,EAA6BkB,MAAMQ,MAAM,CAAA;AAC/D;YAEA7C,GAAAA,CAAIgC,IAAI,CAACK,KAAAA,CAAMS,GAAG,CAAC,CAACpB,IAAAA,GAAsCC,eAAAA,CAAWD,IAAAA,EAAM,IAAI,CAACI,SAAS,EAAA,CAAA,CAAA,CAAA;AAC3F,SAAA,CAAA;QAnEE,IAAI,CAAChC,WAAW,GAAGA,WAAAA;AACrB;AAoEF;;;;"}
|
package/dist/CItemRouter.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ItemRouter, ItemRouterOptions } from './ItemRouter';
|
|
|
4
4
|
import { Contained } from '@fjell/lib';
|
|
5
5
|
export declare class CItemRouter<T extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> extends ItemRouter<S, L1, L2, L3, L4, L5> {
|
|
6
6
|
private parentRoute;
|
|
7
|
-
constructor(lib: Contained.
|
|
7
|
+
constructor(lib: Contained.Instance<T, S, L1, L2, L3, L4, L5>, type: S, parentRoute: ItemRouter<L1, L2, L3, L4, L5, never>, options?: ItemRouterOptions);
|
|
8
8
|
hasParent(): boolean;
|
|
9
9
|
getIk(res: Response): ComKey<S, L1, L2, L3, L4, L5>;
|
|
10
10
|
getLKA(res: Response): LocKeyArray<S, L1, L2, L3, L4>;
|
package/dist/CItemRouter.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { validatePK, paramsToQuery } from '@fjell/core';
|
|
2
2
|
import { ItemRouter } from './ItemRouter.js';
|
|
3
|
-
import LibLogger from './logger.js';
|
|
4
3
|
|
|
5
4
|
function _define_property(obj, key, value) {
|
|
6
5
|
if (key in obj) {
|
|
@@ -15,7 +14,6 @@ function _define_property(obj, key, value) {
|
|
|
15
14
|
}
|
|
16
15
|
return obj;
|
|
17
16
|
}
|
|
18
|
-
const logger = LibLogger.get('CItemRouter');
|
|
19
17
|
class CItemRouter extends ItemRouter {
|
|
20
18
|
hasParent() {
|
|
21
19
|
return !!this.parentRoute;
|
|
@@ -45,24 +43,22 @@ class CItemRouter extends ItemRouter {
|
|
|
45
43
|
}
|
|
46
44
|
constructor(lib, type, parentRoute, options = {}){
|
|
47
45
|
super(lib, type, options), _define_property(this, "parentRoute", void 0), _define_property(this, "createItem", async (req, res)=>{
|
|
48
|
-
|
|
46
|
+
const libOperations = this.lib.operations;
|
|
47
|
+
this.logger.default('Creating Item', {
|
|
49
48
|
body: req === null || req === void 0 ? void 0 : req.body,
|
|
50
49
|
query: req === null || req === void 0 ? void 0 : req.query,
|
|
51
50
|
params: req === null || req === void 0 ? void 0 : req.params,
|
|
52
51
|
locals: res === null || res === void 0 ? void 0 : res.locals
|
|
53
52
|
});
|
|
54
53
|
const itemToCreate = this.convertDates(req.body);
|
|
55
|
-
let item = validatePK(await
|
|
54
|
+
let item = validatePK(await libOperations.create(itemToCreate, {
|
|
56
55
|
locations: this.getLocations(res)
|
|
57
56
|
}), this.getPkType());
|
|
58
57
|
item = await this.postCreateItem(item);
|
|
58
|
+
this.logger.default('Created Item %j', item);
|
|
59
59
|
res.json(item);
|
|
60
60
|
}), _define_property(this, "findItems", async (req, res)=>{
|
|
61
|
-
|
|
62
|
-
query: req.query,
|
|
63
|
-
params: req.params,
|
|
64
|
-
locals: res.locals
|
|
65
|
-
});
|
|
61
|
+
const libOperations = this.lib.operations;
|
|
66
62
|
const query = req.query;
|
|
67
63
|
const finder = query['finder'];
|
|
68
64
|
const finderParams = query['finderParams'];
|
|
@@ -70,7 +66,7 @@ class CItemRouter extends ItemRouter {
|
|
|
70
66
|
let items = [];
|
|
71
67
|
if (finder) {
|
|
72
68
|
// If finder is defined? Call a finder.
|
|
73
|
-
logger.
|
|
69
|
+
this.logger.default('Finding Items with Finder', {
|
|
74
70
|
finder,
|
|
75
71
|
finderParams,
|
|
76
72
|
one
|
|
@@ -81,15 +77,14 @@ class CItemRouter extends ItemRouter {
|
|
|
81
77
|
item
|
|
82
78
|
] : [];
|
|
83
79
|
} else {
|
|
84
|
-
items = await
|
|
80
|
+
items = await libOperations.find(finder, JSON.parse(finderParams), this.getLocations(res));
|
|
85
81
|
}
|
|
86
82
|
} else {
|
|
87
|
-
logger.trace('Finding Items with a query', {
|
|
88
|
-
query: req.query
|
|
89
|
-
});
|
|
90
83
|
// TODO: This is once of the more important places to perform some validaation and feedback
|
|
91
84
|
const itemQuery = paramsToQuery(req.query);
|
|
92
|
-
|
|
85
|
+
this.logger.default('Finding Items with Query: %j', itemQuery);
|
|
86
|
+
items = await libOperations.all(itemQuery, this.getLocations(res));
|
|
87
|
+
this.logger.default('Found %d Items with Query', items.length);
|
|
93
88
|
}
|
|
94
89
|
res.json(items.map((item)=>validatePK(item, this.getPkType())));
|
|
95
90
|
});
|
package/dist/CItemRouter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CItemRouter.js","sources":["../src/CItemRouter.ts"],"sourcesContent":["import {\n ComKey, Item, ItemQuery, LocKey, LocKeyArray, paramsToQuery, PriKey, QueryParams, validatePK\n} from \"@fjell/core\";\nimport { Request, Response } from \"express\";\nimport { ItemRouter, ItemRouterOptions } from \"@/ItemRouter\";\nimport
|
|
1
|
+
{"version":3,"file":"CItemRouter.js","sources":["../src/CItemRouter.ts"],"sourcesContent":["import {\n ComKey, Item, ItemQuery, LocKey, LocKeyArray, paramsToQuery, PriKey, QueryParams, validatePK\n} from \"@fjell/core\";\nimport { Request, Response } from \"express\";\nimport { ItemRouter, ItemRouterOptions } from \"@/ItemRouter\";\nimport { Contained } from \"@fjell/lib\";\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: Contained.Instance<T, S, L1, L2, L3, L4, L5>,\n type: S,\n parentRoute: ItemRouter<L1, L2, L3, L4, L5, never>,\n options: ItemRouterOptions = {},\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 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 };\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"],"names":["CItemRouter","ItemRouter","hasParent","parentRoute","getIk","res","pri","getPk","loc","getLocations","kt","pk","getLKA","lka","getLk","concat","lib","type","options","createItem","req","libOperations","operations","logger","default","body","query","params","locals","itemToCreate","convertDates","item","validatePK","create","locations","getPkType","postCreateItem","json","findItems","finder","finderParams","one","items","findOne","JSON","parse","find","itemQuery","paramsToQuery","all","length","map"],"mappings":";;;;;;;;;;;;;;;;AAWO,MAAMA,WAAAA,SAQHC,UAAAA,CAAAA;IAcDC,SAAAA,GAAqB;AAC1B,QAAA,OAAO,CAAC,CAAC,IAAI,CAACC,WAAW;AAC3B;AAEOC,IAAAA,KAAAA,CAAMC,GAAa,EAAiC;AACzD,QAAA,MAAMC,GAAAA,GAAM,IAAI,CAACC,KAAK,CAACF,GAAAA,CAAAA;AACvB,QAAA,MAAMG,GAAAA,GAAM,IAAI,CAACC,YAAY,CAACJ,GAAAA,CAAAA;QAC9B,OAAO;AAAEK,YAAAA,EAAAA,EAAIJ,IAAII,EAAE;AAAEC,YAAAA,EAAAA,EAAIL,IAAIK,EAAE;AAAEH,YAAAA;AAAI,SAAA;AACvC;AAEOI,IAAAA,MAAAA,CAAOP,GAAa,EAAkC;AAC3D;;;;AAIC,QACD,IAAIQ,GAAAA,GAAuC;YAAC,IAAI,CAACC,KAAK,CAACT,GAAAA;AAAK,SAAA;QAC5DQ,GAAAA,GAAMA,GAAAA,CAAIE,MAAM,CAAC,IAAI,CAACZ,WAAW,CAACS,MAAM,CAACP,GAAAA,CAAAA,CAAAA;QACzC,OAAOQ,GAAAA;AACT;AAEOJ,IAAAA,YAAAA,CAAaJ,GAAa,EAAmC;AAClE,QAAA,OAAO,IAAI,CAACF,WAAW,CAACS,MAAM,CAACP,GAAAA,CAAAA;AACjC;IAjCA,WAAA,CACEW,GAAiD,EACjDC,IAAO,EACPd,WAAkD,EAClDe,OAAAA,GAA6B,EAAE,CAC/B;QACA,KAAK,CAACF,GAAAA,EAAYC,IAAAA,EAAMC,OAAAA,CAAAA,EAR1B,gBAAA,CAAA,IAAA,EAAQf,aAAAA,EAAR,MAAA,CAAA,EAqCA,gBAAA,CAAA,IAAA,EAAUgB,YAAAA,EAAa,OAAOC,GAAAA,EAAcf,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,CAACkB,MAAM,CAACC,OAAO,CAAC,2BAAA,EAA6BkB,MAAMQ,MAAM,CAAA;AAC/D;YAEA7C,GAAAA,CAAIgC,IAAI,CAACK,KAAAA,CAAMS,GAAG,CAAC,CAACpB,IAAAA,GAAsCC,UAAAA,CAAWD,IAAAA,EAAM,IAAI,CAACI,SAAS,EAAA,CAAA,CAAA,CAAA;AAC3F,SAAA,CAAA;QAnEE,IAAI,CAAChC,WAAW,GAAGA,WAAAA;AACrB;AAoEF;;;;"}
|
package/dist/ItemRouter.cjs
CHANGED
|
@@ -63,20 +63,22 @@ class ItemRouter {
|
|
|
63
63
|
return `${this.getPkType()}Pk`;
|
|
64
64
|
});
|
|
65
65
|
_define_property(this, "postAllAction", async (req, res)=>{
|
|
66
|
-
this.
|
|
66
|
+
const libOptions = this.lib.definition.options;
|
|
67
|
+
const libOperations = this.lib.operations;
|
|
68
|
+
this.logger.debug('Posting All Action', {
|
|
67
69
|
query: req === null || req === void 0 ? void 0 : req.query,
|
|
68
70
|
params: req === null || req === void 0 ? void 0 : req.params,
|
|
69
71
|
locals: res === null || res === void 0 ? void 0 : res.locals
|
|
70
72
|
});
|
|
71
73
|
const allActionKey = req.path.substring(req.path.lastIndexOf('/') + 1);
|
|
72
|
-
if (!
|
|
74
|
+
if (!libOptions.allActions) {
|
|
73
75
|
this.logger.error('Item Actions are not configured');
|
|
74
76
|
res.status(500).json({
|
|
75
77
|
error: 'Item Actions are not configured'
|
|
76
78
|
});
|
|
77
79
|
return;
|
|
78
80
|
}
|
|
79
|
-
const allAction =
|
|
81
|
+
const allAction = libOptions.allActions[allActionKey];
|
|
80
82
|
if (!allAction) {
|
|
81
83
|
this.logger.error('All Action is not configured', {
|
|
82
84
|
allActionKey
|
|
@@ -87,7 +89,7 @@ class ItemRouter {
|
|
|
87
89
|
return;
|
|
88
90
|
}
|
|
89
91
|
try {
|
|
90
|
-
res.json(await
|
|
92
|
+
res.json(await libOperations.allAction(allActionKey, req.body));
|
|
91
93
|
} catch (err) {
|
|
92
94
|
this.logger.error('Error in All Action', {
|
|
93
95
|
message: err === null || err === void 0 ? void 0 : err.message,
|
|
@@ -97,20 +99,22 @@ class ItemRouter {
|
|
|
97
99
|
}
|
|
98
100
|
});
|
|
99
101
|
_define_property(this, "getAllFacet", async (req, res)=>{
|
|
100
|
-
this.
|
|
102
|
+
const libOptions = this.lib.definition.options;
|
|
103
|
+
const libOperations = this.lib.operations;
|
|
104
|
+
this.logger.debug('Getting All Facet', {
|
|
101
105
|
query: req === null || req === void 0 ? void 0 : req.query,
|
|
102
106
|
params: req === null || req === void 0 ? void 0 : req.params,
|
|
103
107
|
locals: res === null || res === void 0 ? void 0 : res.locals
|
|
104
108
|
});
|
|
105
109
|
const facetKey = req.path.substring(req.path.lastIndexOf('/') + 1);
|
|
106
|
-
if (!
|
|
110
|
+
if (!libOptions.allFacets) {
|
|
107
111
|
this.logger.error('Item Facets are not configured');
|
|
108
112
|
res.status(500).json({
|
|
109
113
|
error: 'Item Facets are not configured'
|
|
110
114
|
});
|
|
111
115
|
return;
|
|
112
116
|
}
|
|
113
|
-
const facet =
|
|
117
|
+
const facet = libOptions.allFacets[facetKey];
|
|
114
118
|
if (!facet) {
|
|
115
119
|
this.logger.error('Item Facet is not configured', {
|
|
116
120
|
facetKey
|
|
@@ -125,7 +129,7 @@ class ItemRouter {
|
|
|
125
129
|
...req.query,
|
|
126
130
|
...req.params
|
|
127
131
|
};
|
|
128
|
-
res.json(await
|
|
132
|
+
res.json(await libOperations.allFacet(facetKey, combinedQueryParams));
|
|
129
133
|
} catch (err) {
|
|
130
134
|
this.logger.error('Error in All Facet', {
|
|
131
135
|
message: err === null || err === void 0 ? void 0 : err.message,
|
|
@@ -135,21 +139,23 @@ class ItemRouter {
|
|
|
135
139
|
}
|
|
136
140
|
});
|
|
137
141
|
_define_property(this, "postItemAction", async (req, res)=>{
|
|
138
|
-
this.
|
|
142
|
+
const libOptions = this.lib.definition.options;
|
|
143
|
+
const libOperations = this.lib.operations;
|
|
144
|
+
this.logger.debug('Getting Item', {
|
|
139
145
|
query: req === null || req === void 0 ? void 0 : req.query,
|
|
140
146
|
params: req === null || req === void 0 ? void 0 : req.params,
|
|
141
147
|
locals: res === null || res === void 0 ? void 0 : res.locals
|
|
142
148
|
});
|
|
143
149
|
const ik = this.getIk(res);
|
|
144
150
|
const actionKey = req.path.substring(req.path.lastIndexOf('/') + 1);
|
|
145
|
-
if (!
|
|
151
|
+
if (!libOptions.actions) {
|
|
146
152
|
this.logger.error('Item Actions are not configured');
|
|
147
153
|
res.status(500).json({
|
|
148
154
|
error: 'Item Actions are not configured'
|
|
149
155
|
});
|
|
150
156
|
return;
|
|
151
157
|
}
|
|
152
|
-
const action =
|
|
158
|
+
const action = libOptions.actions[actionKey];
|
|
153
159
|
if (!action) {
|
|
154
160
|
this.logger.error('Item Action is not configured', {
|
|
155
161
|
actionKey
|
|
@@ -160,7 +166,7 @@ class ItemRouter {
|
|
|
160
166
|
return;
|
|
161
167
|
}
|
|
162
168
|
try {
|
|
163
|
-
res.json(await
|
|
169
|
+
res.json(await libOperations.action(ik, actionKey, req.body));
|
|
164
170
|
} catch (err) {
|
|
165
171
|
this.logger.error('Error in Item Action', {
|
|
166
172
|
message: err === null || err === void 0 ? void 0 : err.message,
|
|
@@ -170,21 +176,23 @@ class ItemRouter {
|
|
|
170
176
|
}
|
|
171
177
|
});
|
|
172
178
|
_define_property(this, "getItemFacet", async (req, res)=>{
|
|
173
|
-
this.
|
|
179
|
+
const libOptions = this.lib.definition.options;
|
|
180
|
+
const libOperations = this.lib.operations;
|
|
181
|
+
this.logger.debug('Getting Item', {
|
|
174
182
|
query: req === null || req === void 0 ? void 0 : req.query,
|
|
175
183
|
params: req === null || req === void 0 ? void 0 : req.params,
|
|
176
184
|
locals: res === null || res === void 0 ? void 0 : res.locals
|
|
177
185
|
});
|
|
178
186
|
const ik = this.getIk(res);
|
|
179
187
|
const facetKey = req.path.substring(req.path.lastIndexOf('/') + 1);
|
|
180
|
-
if (!
|
|
188
|
+
if (!libOptions.facets) {
|
|
181
189
|
this.logger.error('Item Facets are not configured');
|
|
182
190
|
res.status(500).json({
|
|
183
191
|
error: 'Item Facets are not configured'
|
|
184
192
|
});
|
|
185
193
|
return;
|
|
186
194
|
}
|
|
187
|
-
const facet =
|
|
195
|
+
const facet = libOptions.facets[facetKey];
|
|
188
196
|
if (!facet) {
|
|
189
197
|
this.logger.error('Item Facet is not configured', {
|
|
190
198
|
facetKey
|
|
@@ -199,7 +207,7 @@ class ItemRouter {
|
|
|
199
207
|
...req.query,
|
|
200
208
|
...req.params
|
|
201
209
|
};
|
|
202
|
-
res.json(await
|
|
210
|
+
res.json(await libOperations.facet(ik, facetKey, combinedQueryParams));
|
|
203
211
|
} catch (err) {
|
|
204
212
|
this.logger.error('Error in Item Facet', {
|
|
205
213
|
message: err === null || err === void 0 ? void 0 : err.message,
|
|
@@ -209,31 +217,28 @@ class ItemRouter {
|
|
|
209
217
|
}
|
|
210
218
|
});
|
|
211
219
|
_define_property(this, "configure", (router)=>{
|
|
212
|
-
this.
|
|
220
|
+
const libOptions = this.lib.definition.options;
|
|
221
|
+
this.logger.debug('Configuring Router', {
|
|
213
222
|
pkType: this.getPkType()
|
|
214
223
|
});
|
|
215
224
|
router.get('/', this.findItems);
|
|
216
225
|
router.post('/', this.createItem);
|
|
217
|
-
this.logger.
|
|
218
|
-
allActions:
|
|
226
|
+
this.logger.default('All Actions supplied to Router', {
|
|
227
|
+
allActions: libOptions.allActions
|
|
219
228
|
});
|
|
220
|
-
if (
|
|
221
|
-
Object.keys(
|
|
222
|
-
this.logger.
|
|
223
|
-
actionKey
|
|
224
|
-
});
|
|
229
|
+
if (libOptions.allActions) {
|
|
230
|
+
Object.keys(libOptions.allActions).forEach((actionKey)=>{
|
|
231
|
+
this.logger.debug('Configuring All Action %s', actionKey);
|
|
225
232
|
// TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers
|
|
226
233
|
router.post(`/${actionKey}`, this.postAllAction);
|
|
227
234
|
});
|
|
228
235
|
}
|
|
229
|
-
this.logger.
|
|
230
|
-
allFacets:
|
|
236
|
+
this.logger.default('All Facets supplied to Router', {
|
|
237
|
+
allFacets: libOptions.allFacets
|
|
231
238
|
});
|
|
232
|
-
if (
|
|
233
|
-
Object.keys(
|
|
234
|
-
this.logger.
|
|
235
|
-
facetKey
|
|
236
|
-
});
|
|
239
|
+
if (libOptions.allFacets) {
|
|
240
|
+
Object.keys(libOptions.allFacets).forEach((facetKey)=>{
|
|
241
|
+
this.logger.debug('Configuring All Facet %s', facetKey);
|
|
237
242
|
// TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers
|
|
238
243
|
router.get(`/${facetKey}`, this.getAllFacet);
|
|
239
244
|
});
|
|
@@ -242,33 +247,27 @@ class ItemRouter {
|
|
|
242
247
|
itemRouter.get('/', this.getItem);
|
|
243
248
|
itemRouter.put('/', this.updateItem);
|
|
244
249
|
itemRouter.delete('/', this.deleteItem);
|
|
245
|
-
this.logger.
|
|
246
|
-
itemActions:
|
|
250
|
+
this.logger.default('Item Actions supplied to Router', {
|
|
251
|
+
itemActions: libOptions.actions
|
|
247
252
|
});
|
|
248
|
-
if (
|
|
249
|
-
Object.keys(
|
|
250
|
-
this.logger.
|
|
251
|
-
actionKey
|
|
252
|
-
});
|
|
253
|
+
if (libOptions.actions) {
|
|
254
|
+
Object.keys(libOptions.actions).forEach((actionKey)=>{
|
|
255
|
+
this.logger.debug('Configuring Item Action %s', actionKey);
|
|
253
256
|
// TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers
|
|
254
257
|
itemRouter.post(`/${actionKey}`, this.postItemAction);
|
|
255
258
|
});
|
|
256
259
|
}
|
|
257
|
-
this.logger.
|
|
258
|
-
itemFacets:
|
|
260
|
+
this.logger.default('Item Facets supplied to Router', {
|
|
261
|
+
itemFacets: libOptions.facets
|
|
259
262
|
});
|
|
260
|
-
if (
|
|
261
|
-
Object.keys(
|
|
262
|
-
this.logger.
|
|
263
|
-
facetKey
|
|
264
|
-
});
|
|
263
|
+
if (libOptions.facets) {
|
|
264
|
+
Object.keys(libOptions.facets).forEach((facetKey)=>{
|
|
265
|
+
this.logger.debug('Configuring Item Facet %s', facetKey);
|
|
265
266
|
// TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers
|
|
266
267
|
itemRouter.get(`/${facetKey}`, this.getItemFacet);
|
|
267
268
|
});
|
|
268
269
|
}
|
|
269
|
-
this.logger.
|
|
270
|
-
pkParam: this.getPkParam()
|
|
271
|
-
});
|
|
270
|
+
this.logger.debug('Configuring Item Operations under PK Param %s', this.getPkParam());
|
|
272
271
|
router.use(`/:${this.getPkParam()}`, this.validatePrimaryKeyValue, itemRouter);
|
|
273
272
|
if (this.childRouters) {
|
|
274
273
|
this.configureChildRouters(itemRouter, this.childRouters);
|
|
@@ -283,19 +282,17 @@ class ItemRouter {
|
|
|
283
282
|
} else {
|
|
284
283
|
this.logger.error('Invalid Primary Key', {
|
|
285
284
|
pkParamValue,
|
|
286
|
-
path: req === null || req === void 0 ? void 0 : req.
|
|
285
|
+
path: req === null || req === void 0 ? void 0 : req.originalUrl
|
|
287
286
|
});
|
|
288
287
|
res.status(500).json({
|
|
289
288
|
error: 'Invalid Primary Key',
|
|
290
|
-
path: req === null || req === void 0 ? void 0 : req.
|
|
289
|
+
path: req === null || req === void 0 ? void 0 : req.originalUrl
|
|
291
290
|
});
|
|
292
291
|
}
|
|
293
292
|
});
|
|
294
293
|
_define_property(this, "configureChildRouters", (router, childRouters)=>{
|
|
295
294
|
for(const path in childRouters){
|
|
296
|
-
this.logger.
|
|
297
|
-
path
|
|
298
|
-
});
|
|
295
|
+
this.logger.debug('Configuring Child Router at Path %s', path);
|
|
299
296
|
router.use(`/${path}`, childRouters[path]);
|
|
300
297
|
}
|
|
301
298
|
return router;
|
|
@@ -309,19 +306,20 @@ class ItemRouter {
|
|
|
309
306
|
});
|
|
310
307
|
// TODO: Probably a better way to do this, but this postCreate hook only needs the item.
|
|
311
308
|
/* istanbul ignore next */ _define_property(this, "postCreateItem", async (item)=>{
|
|
312
|
-
this.logger.
|
|
309
|
+
this.logger.debug('Post Create Item', {
|
|
313
310
|
item
|
|
314
311
|
});
|
|
315
312
|
return item;
|
|
316
313
|
});
|
|
317
314
|
_define_property(this, "deleteItem", async (req, res)=>{
|
|
318
|
-
this.
|
|
315
|
+
const libOperations = this.lib.operations;
|
|
316
|
+
this.logger.debug('Deleting Item', {
|
|
319
317
|
query: req.query,
|
|
320
318
|
params: req.params,
|
|
321
319
|
locals: res.locals
|
|
322
320
|
});
|
|
323
321
|
const ik = this.getIk(res);
|
|
324
|
-
const removedItem = await
|
|
322
|
+
const removedItem = await libOperations.remove(ik);
|
|
325
323
|
const item = core.validatePK(removedItem, this.getPkType());
|
|
326
324
|
res.json(item);
|
|
327
325
|
});
|
|
@@ -329,7 +327,8 @@ class ItemRouter {
|
|
|
329
327
|
throw new Error('Method not implemented in an abstract router');
|
|
330
328
|
});
|
|
331
329
|
/* eslint-enable */ _define_property(this, "getItem", async (req, res)=>{
|
|
332
|
-
this.
|
|
330
|
+
const libOperations = this.lib.operations;
|
|
331
|
+
this.logger.debug('Getting Item', {
|
|
333
332
|
query: req.query,
|
|
334
333
|
params: req.params,
|
|
335
334
|
locals: res.locals
|
|
@@ -337,7 +336,7 @@ class ItemRouter {
|
|
|
337
336
|
const ik = this.getIk(res);
|
|
338
337
|
try {
|
|
339
338
|
// TODO: What error does validate PK throw, when can that fail?
|
|
340
|
-
const item = core.validatePK(await
|
|
339
|
+
const item = core.validatePK(await libOperations.get(ik), this.getPkType());
|
|
341
340
|
res.json(item);
|
|
342
341
|
} catch (err) {
|
|
343
342
|
if (err instanceof lib.NotFoundError) {
|
|
@@ -364,7 +363,8 @@ class ItemRouter {
|
|
|
364
363
|
}
|
|
365
364
|
});
|
|
366
365
|
_define_property(this, "updateItem", async (req, res)=>{
|
|
367
|
-
this.
|
|
366
|
+
const libOperations = this.lib.operations;
|
|
367
|
+
this.logger.debug('Updating Item', {
|
|
368
368
|
body: req === null || req === void 0 ? void 0 : req.body,
|
|
369
369
|
query: req === null || req === void 0 ? void 0 : req.query,
|
|
370
370
|
params: req === null || req === void 0 ? void 0 : req.params,
|
|
@@ -372,12 +372,12 @@ class ItemRouter {
|
|
|
372
372
|
});
|
|
373
373
|
const ik = this.getIk(res);
|
|
374
374
|
const itemToUpdate = this.convertDates(req.body);
|
|
375
|
-
const retItem = core.validatePK(await
|
|
375
|
+
const retItem = core.validatePK(await libOperations.update(ik, itemToUpdate), this.getPkType());
|
|
376
376
|
res.json(retItem);
|
|
377
377
|
});
|
|
378
378
|
_define_property(this, "convertDates", (item)=>{
|
|
379
379
|
const events = item.events;
|
|
380
|
-
this.logger.
|
|
380
|
+
this.logger.debug('Converting Dates', {
|
|
381
381
|
item
|
|
382
382
|
});
|
|
383
383
|
if (events) {
|