@fjell/express-router 4.4.3 → 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 +139 -48
- package/dist/ItemRouter.cjs.map +1 -1
- package/dist/ItemRouter.d.ts +8 -6
- package/dist/ItemRouter.js +139 -48
- 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 +159 -76
- 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 +111 -46
- 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
|
@@ -62,22 +62,100 @@ class ItemRouter {
|
|
|
62
62
|
_define_property(this, "getPkParam", ()=>{
|
|
63
63
|
return `${this.getPkType()}Pk`;
|
|
64
64
|
});
|
|
65
|
+
_define_property(this, "postAllAction", async (req, res)=>{
|
|
66
|
+
const libOptions = this.lib.definition.options;
|
|
67
|
+
const libOperations = this.lib.operations;
|
|
68
|
+
this.logger.debug('Posting All Action', {
|
|
69
|
+
query: req === null || req === void 0 ? void 0 : req.query,
|
|
70
|
+
params: req === null || req === void 0 ? void 0 : req.params,
|
|
71
|
+
locals: res === null || res === void 0 ? void 0 : res.locals
|
|
72
|
+
});
|
|
73
|
+
const allActionKey = req.path.substring(req.path.lastIndexOf('/') + 1);
|
|
74
|
+
if (!libOptions.allActions) {
|
|
75
|
+
this.logger.error('Item Actions are not configured');
|
|
76
|
+
res.status(500).json({
|
|
77
|
+
error: 'Item Actions are not configured'
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const allAction = libOptions.allActions[allActionKey];
|
|
82
|
+
if (!allAction) {
|
|
83
|
+
this.logger.error('All Action is not configured', {
|
|
84
|
+
allActionKey
|
|
85
|
+
});
|
|
86
|
+
res.status(500).json({
|
|
87
|
+
error: 'Item Action is not configured'
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
res.json(await libOperations.allAction(allActionKey, req.body));
|
|
93
|
+
} catch (err) {
|
|
94
|
+
this.logger.error('Error in All Action', {
|
|
95
|
+
message: err === null || err === void 0 ? void 0 : err.message,
|
|
96
|
+
stack: err === null || err === void 0 ? void 0 : err.stack
|
|
97
|
+
});
|
|
98
|
+
res.status(500).json(err);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
_define_property(this, "getAllFacet", async (req, res)=>{
|
|
102
|
+
const libOptions = this.lib.definition.options;
|
|
103
|
+
const libOperations = this.lib.operations;
|
|
104
|
+
this.logger.debug('Getting All Facet', {
|
|
105
|
+
query: req === null || req === void 0 ? void 0 : req.query,
|
|
106
|
+
params: req === null || req === void 0 ? void 0 : req.params,
|
|
107
|
+
locals: res === null || res === void 0 ? void 0 : res.locals
|
|
108
|
+
});
|
|
109
|
+
const facetKey = req.path.substring(req.path.lastIndexOf('/') + 1);
|
|
110
|
+
if (!libOptions.allFacets) {
|
|
111
|
+
this.logger.error('Item Facets are not configured');
|
|
112
|
+
res.status(500).json({
|
|
113
|
+
error: 'Item Facets are not configured'
|
|
114
|
+
});
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const facet = libOptions.allFacets[facetKey];
|
|
118
|
+
if (!facet) {
|
|
119
|
+
this.logger.error('Item Facet is not configured', {
|
|
120
|
+
facetKey
|
|
121
|
+
});
|
|
122
|
+
res.status(500).json({
|
|
123
|
+
error: 'Item Facet is not configured'
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const combinedQueryParams = {
|
|
129
|
+
...req.query,
|
|
130
|
+
...req.params
|
|
131
|
+
};
|
|
132
|
+
res.json(await libOperations.allFacet(facetKey, combinedQueryParams));
|
|
133
|
+
} catch (err) {
|
|
134
|
+
this.logger.error('Error in All Facet', {
|
|
135
|
+
message: err === null || err === void 0 ? void 0 : err.message,
|
|
136
|
+
stack: err === null || err === void 0 ? void 0 : err.stack
|
|
137
|
+
});
|
|
138
|
+
res.status(500).json(err);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
65
141
|
_define_property(this, "postItemAction", async (req, res)=>{
|
|
66
|
-
this.
|
|
142
|
+
const libOptions = this.lib.definition.options;
|
|
143
|
+
const libOperations = this.lib.operations;
|
|
144
|
+
this.logger.debug('Getting Item', {
|
|
67
145
|
query: req === null || req === void 0 ? void 0 : req.query,
|
|
68
146
|
params: req === null || req === void 0 ? void 0 : req.params,
|
|
69
147
|
locals: res === null || res === void 0 ? void 0 : res.locals
|
|
70
148
|
});
|
|
71
149
|
const ik = this.getIk(res);
|
|
72
150
|
const actionKey = req.path.substring(req.path.lastIndexOf('/') + 1);
|
|
73
|
-
if (!
|
|
151
|
+
if (!libOptions.actions) {
|
|
74
152
|
this.logger.error('Item Actions are not configured');
|
|
75
153
|
res.status(500).json({
|
|
76
154
|
error: 'Item Actions are not configured'
|
|
77
155
|
});
|
|
78
156
|
return;
|
|
79
157
|
}
|
|
80
|
-
const action =
|
|
158
|
+
const action = libOptions.actions[actionKey];
|
|
81
159
|
if (!action) {
|
|
82
160
|
this.logger.error('Item Action is not configured', {
|
|
83
161
|
actionKey
|
|
@@ -88,7 +166,7 @@ class ItemRouter {
|
|
|
88
166
|
return;
|
|
89
167
|
}
|
|
90
168
|
try {
|
|
91
|
-
res.json(await
|
|
169
|
+
res.json(await libOperations.action(ik, actionKey, req.body));
|
|
92
170
|
} catch (err) {
|
|
93
171
|
this.logger.error('Error in Item Action', {
|
|
94
172
|
message: err === null || err === void 0 ? void 0 : err.message,
|
|
@@ -98,21 +176,23 @@ class ItemRouter {
|
|
|
98
176
|
}
|
|
99
177
|
});
|
|
100
178
|
_define_property(this, "getItemFacet", async (req, res)=>{
|
|
101
|
-
this.
|
|
179
|
+
const libOptions = this.lib.definition.options;
|
|
180
|
+
const libOperations = this.lib.operations;
|
|
181
|
+
this.logger.debug('Getting Item', {
|
|
102
182
|
query: req === null || req === void 0 ? void 0 : req.query,
|
|
103
183
|
params: req === null || req === void 0 ? void 0 : req.params,
|
|
104
184
|
locals: res === null || res === void 0 ? void 0 : res.locals
|
|
105
185
|
});
|
|
106
186
|
const ik = this.getIk(res);
|
|
107
187
|
const facetKey = req.path.substring(req.path.lastIndexOf('/') + 1);
|
|
108
|
-
if (!
|
|
188
|
+
if (!libOptions.facets) {
|
|
109
189
|
this.logger.error('Item Facets are not configured');
|
|
110
190
|
res.status(500).json({
|
|
111
191
|
error: 'Item Facets are not configured'
|
|
112
192
|
});
|
|
113
193
|
return;
|
|
114
194
|
}
|
|
115
|
-
const facet =
|
|
195
|
+
const facet = libOptions.facets[facetKey];
|
|
116
196
|
if (!facet) {
|
|
117
197
|
this.logger.error('Item Facet is not configured', {
|
|
118
198
|
facetKey
|
|
@@ -123,7 +203,11 @@ class ItemRouter {
|
|
|
123
203
|
return;
|
|
124
204
|
}
|
|
125
205
|
try {
|
|
126
|
-
|
|
206
|
+
const combinedQueryParams = {
|
|
207
|
+
...req.query,
|
|
208
|
+
...req.params
|
|
209
|
+
};
|
|
210
|
+
res.json(await libOperations.facet(ik, facetKey, combinedQueryParams));
|
|
127
211
|
} catch (err) {
|
|
128
212
|
this.logger.error('Error in Item Facet', {
|
|
129
213
|
message: err === null || err === void 0 ? void 0 : err.message,
|
|
@@ -133,51 +217,57 @@ class ItemRouter {
|
|
|
133
217
|
}
|
|
134
218
|
});
|
|
135
219
|
_define_property(this, "configure", (router)=>{
|
|
136
|
-
this.
|
|
220
|
+
const libOptions = this.lib.definition.options;
|
|
221
|
+
this.logger.debug('Configuring Router', {
|
|
137
222
|
pkType: this.getPkType()
|
|
138
223
|
});
|
|
139
224
|
router.get('/', this.findItems);
|
|
140
225
|
router.post('/', this.createItem);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
226
|
+
this.logger.default('All Actions supplied to Router', {
|
|
227
|
+
allActions: libOptions.allActions
|
|
228
|
+
});
|
|
229
|
+
if (libOptions.allActions) {
|
|
230
|
+
Object.keys(libOptions.allActions).forEach((actionKey)=>{
|
|
231
|
+
this.logger.debug('Configuring All Action %s', actionKey);
|
|
232
|
+
// TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers
|
|
233
|
+
router.post(`/${actionKey}`, this.postAllAction);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
this.logger.default('All Facets supplied to Router', {
|
|
237
|
+
allFacets: libOptions.allFacets
|
|
238
|
+
});
|
|
239
|
+
if (libOptions.allFacets) {
|
|
240
|
+
Object.keys(libOptions.allFacets).forEach((facetKey)=>{
|
|
241
|
+
this.logger.debug('Configuring All Facet %s', facetKey);
|
|
242
|
+
// TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers
|
|
243
|
+
router.get(`/${facetKey}`, this.getAllFacet);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
150
246
|
const itemRouter = express.Router();
|
|
151
247
|
itemRouter.get('/', this.getItem);
|
|
152
248
|
itemRouter.put('/', this.updateItem);
|
|
153
249
|
itemRouter.delete('/', this.deleteItem);
|
|
154
|
-
this.logger.
|
|
155
|
-
itemActions:
|
|
250
|
+
this.logger.default('Item Actions supplied to Router', {
|
|
251
|
+
itemActions: libOptions.actions
|
|
156
252
|
});
|
|
157
|
-
if (
|
|
158
|
-
Object.keys(
|
|
159
|
-
this.logger.
|
|
160
|
-
actionKey
|
|
161
|
-
});
|
|
253
|
+
if (libOptions.actions) {
|
|
254
|
+
Object.keys(libOptions.actions).forEach((actionKey)=>{
|
|
255
|
+
this.logger.debug('Configuring Item Action %s', actionKey);
|
|
162
256
|
// TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers
|
|
163
257
|
itemRouter.post(`/${actionKey}`, this.postItemAction);
|
|
164
258
|
});
|
|
165
259
|
}
|
|
166
|
-
this.logger.
|
|
167
|
-
itemFacets:
|
|
260
|
+
this.logger.default('Item Facets supplied to Router', {
|
|
261
|
+
itemFacets: libOptions.facets
|
|
168
262
|
});
|
|
169
|
-
if (
|
|
170
|
-
Object.keys(
|
|
171
|
-
this.logger.
|
|
172
|
-
facetKey
|
|
173
|
-
});
|
|
263
|
+
if (libOptions.facets) {
|
|
264
|
+
Object.keys(libOptions.facets).forEach((facetKey)=>{
|
|
265
|
+
this.logger.debug('Configuring Item Facet %s', facetKey);
|
|
174
266
|
// TODO: Ok, this is a bit of a hack, but we need to customize the types of the request handlers
|
|
175
267
|
itemRouter.get(`/${facetKey}`, this.getItemFacet);
|
|
176
268
|
});
|
|
177
269
|
}
|
|
178
|
-
this.logger.
|
|
179
|
-
pkParam: this.getPkParam()
|
|
180
|
-
});
|
|
270
|
+
this.logger.debug('Configuring Item Operations under PK Param %s', this.getPkParam());
|
|
181
271
|
router.use(`/:${this.getPkParam()}`, this.validatePrimaryKeyValue, itemRouter);
|
|
182
272
|
if (this.childRouters) {
|
|
183
273
|
this.configureChildRouters(itemRouter, this.childRouters);
|
|
@@ -192,19 +282,17 @@ class ItemRouter {
|
|
|
192
282
|
} else {
|
|
193
283
|
this.logger.error('Invalid Primary Key', {
|
|
194
284
|
pkParamValue,
|
|
195
|
-
path: req === null || req === void 0 ? void 0 : req.
|
|
285
|
+
path: req === null || req === void 0 ? void 0 : req.originalUrl
|
|
196
286
|
});
|
|
197
287
|
res.status(500).json({
|
|
198
288
|
error: 'Invalid Primary Key',
|
|
199
|
-
path: req === null || req === void 0 ? void 0 : req.
|
|
289
|
+
path: req === null || req === void 0 ? void 0 : req.originalUrl
|
|
200
290
|
});
|
|
201
291
|
}
|
|
202
292
|
});
|
|
203
293
|
_define_property(this, "configureChildRouters", (router, childRouters)=>{
|
|
204
294
|
for(const path in childRouters){
|
|
205
|
-
this.logger.
|
|
206
|
-
path
|
|
207
|
-
});
|
|
295
|
+
this.logger.debug('Configuring Child Router at Path %s', path);
|
|
208
296
|
router.use(`/${path}`, childRouters[path]);
|
|
209
297
|
}
|
|
210
298
|
return router;
|
|
@@ -218,19 +306,20 @@ class ItemRouter {
|
|
|
218
306
|
});
|
|
219
307
|
// TODO: Probably a better way to do this, but this postCreate hook only needs the item.
|
|
220
308
|
/* istanbul ignore next */ _define_property(this, "postCreateItem", async (item)=>{
|
|
221
|
-
this.logger.
|
|
309
|
+
this.logger.debug('Post Create Item', {
|
|
222
310
|
item
|
|
223
311
|
});
|
|
224
312
|
return item;
|
|
225
313
|
});
|
|
226
314
|
_define_property(this, "deleteItem", async (req, res)=>{
|
|
227
|
-
this.
|
|
315
|
+
const libOperations = this.lib.operations;
|
|
316
|
+
this.logger.debug('Deleting Item', {
|
|
228
317
|
query: req.query,
|
|
229
318
|
params: req.params,
|
|
230
319
|
locals: res.locals
|
|
231
320
|
});
|
|
232
321
|
const ik = this.getIk(res);
|
|
233
|
-
const removedItem = await
|
|
322
|
+
const removedItem = await libOperations.remove(ik);
|
|
234
323
|
const item = core.validatePK(removedItem, this.getPkType());
|
|
235
324
|
res.json(item);
|
|
236
325
|
});
|
|
@@ -238,7 +327,8 @@ class ItemRouter {
|
|
|
238
327
|
throw new Error('Method not implemented in an abstract router');
|
|
239
328
|
});
|
|
240
329
|
/* eslint-enable */ _define_property(this, "getItem", async (req, res)=>{
|
|
241
|
-
this.
|
|
330
|
+
const libOperations = this.lib.operations;
|
|
331
|
+
this.logger.debug('Getting Item', {
|
|
242
332
|
query: req.query,
|
|
243
333
|
params: req.params,
|
|
244
334
|
locals: res.locals
|
|
@@ -246,7 +336,7 @@ class ItemRouter {
|
|
|
246
336
|
const ik = this.getIk(res);
|
|
247
337
|
try {
|
|
248
338
|
// TODO: What error does validate PK throw, when can that fail?
|
|
249
|
-
const item = core.validatePK(await
|
|
339
|
+
const item = core.validatePK(await libOperations.get(ik), this.getPkType());
|
|
250
340
|
res.json(item);
|
|
251
341
|
} catch (err) {
|
|
252
342
|
if (err instanceof lib.NotFoundError) {
|
|
@@ -273,7 +363,8 @@ class ItemRouter {
|
|
|
273
363
|
}
|
|
274
364
|
});
|
|
275
365
|
_define_property(this, "updateItem", async (req, res)=>{
|
|
276
|
-
this.
|
|
366
|
+
const libOperations = this.lib.operations;
|
|
367
|
+
this.logger.debug('Updating Item', {
|
|
277
368
|
body: req === null || req === void 0 ? void 0 : req.body,
|
|
278
369
|
query: req === null || req === void 0 ? void 0 : req.query,
|
|
279
370
|
params: req === null || req === void 0 ? void 0 : req.params,
|
|
@@ -281,12 +372,12 @@ class ItemRouter {
|
|
|
281
372
|
});
|
|
282
373
|
const ik = this.getIk(res);
|
|
283
374
|
const itemToUpdate = this.convertDates(req.body);
|
|
284
|
-
const retItem = core.validatePK(await
|
|
375
|
+
const retItem = core.validatePK(await libOperations.update(ik, itemToUpdate), this.getPkType());
|
|
285
376
|
res.json(retItem);
|
|
286
377
|
});
|
|
287
378
|
_define_property(this, "convertDates", (item)=>{
|
|
288
379
|
const events = item.events;
|
|
289
|
-
this.logger.
|
|
380
|
+
this.logger.debug('Converting Dates', {
|
|
290
381
|
item
|
|
291
382
|
});
|
|
292
383
|
if (events) {
|