@websolutespa/bom-mixer-store 1.2.2 → 1.4.0
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/CHANGELOG.md +13 -0
- package/dist/index.d.ts +23 -10
- package/dist/index.js +606 -285
- package/dist/index.mjs +579 -269
- package/package.json +1 -1
- package/src/mock/mock-menu.service.ts +63 -28
- package/src/mock/mock-page.service.ts +133 -54
- package/src/mock/mock.service.ts +120 -45
- package/src/mock/mock.store.ts +1 -1
- package/src/remote/remote.service.ts +14 -9
- package/src/remote/remote.store.ts +21 -5
- package/src/static/static.service.ts +67 -50
- package/src/store/store.handler.ts +140 -8
- package/src/store/store.ts +18 -2
package/dist/index.js
CHANGED
|
@@ -30,31 +30,37 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
+
BuildStrategy: () => BuildStrategy,
|
|
33
34
|
COLLECTIONS: () => COLLECTIONS,
|
|
34
35
|
KNOWN_COLLECTIONS: () => KNOWN_COLLECTIONS,
|
|
35
36
|
MOCK_COLLECTIONS: () => MOCK_COLLECTIONS,
|
|
37
|
+
MOCK_SERVICE_DEFAULT_DEPTH: () => MOCK_SERVICE_DEFAULT_DEPTH,
|
|
36
38
|
MockService: () => MockService,
|
|
37
39
|
RemoteService: () => RemoteService,
|
|
38
40
|
STATIC_COLLECTIONS: () => STATIC_COLLECTIONS,
|
|
39
41
|
StaticService: () => StaticService,
|
|
40
42
|
StoreStrategy: () => StoreStrategy,
|
|
41
43
|
apiHandler: () => apiHandler,
|
|
44
|
+
buildStrategy: () => buildStrategy,
|
|
42
45
|
collectionDelete: () => collectionDelete,
|
|
43
46
|
collectionGet: () => collectionGet,
|
|
44
47
|
collectionPatch: () => collectionPatch,
|
|
45
48
|
collectionPost: () => collectionPost,
|
|
49
|
+
decorateRelation_: () => decorateRelation_,
|
|
50
|
+
decorateRelations_: () => decorateRelations_,
|
|
51
|
+
decorateStaticRelation_: () => decorateStaticRelation_,
|
|
52
|
+
decorateStaticRelations_: () => decorateStaticRelations_,
|
|
46
53
|
defaultApiRequestOptions: () => defaultApiRequestOptions,
|
|
47
54
|
errorHandler: () => errorHandler,
|
|
48
55
|
fromCache: () => fromCache,
|
|
49
56
|
getDefaultApiRequestOptions: () => getDefaultApiRequestOptions,
|
|
50
57
|
getLocalApiUrl: () => getLocalApiUrl,
|
|
51
58
|
getMockStore: () => getMockStore,
|
|
59
|
+
getMockStoreFromData_: () => getMockStoreFromData_,
|
|
52
60
|
getRemoteStore: () => getRemoteStore,
|
|
53
61
|
getStore: () => getStore,
|
|
54
62
|
isApiRequest: () => isApiRequest,
|
|
55
63
|
isNextRequest: () => isNextRequest,
|
|
56
|
-
isObject: () => isObject,
|
|
57
|
-
isRelation: () => isRelation,
|
|
58
64
|
isStaticRequest: () => isStaticRequest,
|
|
59
65
|
localApiDelete: () => localApiDelete,
|
|
60
66
|
localApiFetch: () => localApiFetch,
|
|
@@ -62,6 +68,8 @@ __export(src_exports, {
|
|
|
62
68
|
localApiPatch: () => localApiPatch,
|
|
63
69
|
localApiPost: () => localApiPost,
|
|
64
70
|
localApiPut: () => localApiPut,
|
|
71
|
+
localizeItem_: () => localizeItem_,
|
|
72
|
+
localizeItems_: () => localizeItems_,
|
|
65
73
|
mockApiDelete: () => mockApiDelete,
|
|
66
74
|
mockApiFetch: () => mockApiFetch,
|
|
67
75
|
mockApiGet: () => mockApiGet,
|
|
@@ -83,6 +91,7 @@ __export(src_exports, {
|
|
|
83
91
|
storeApiPost: () => storeApiPost,
|
|
84
92
|
storeApiPut: () => storeApiPut,
|
|
85
93
|
storeHandler: () => storeHandler,
|
|
94
|
+
storeIndexHandler: () => storeIndexHandler,
|
|
86
95
|
storeStrategy: () => storeStrategy
|
|
87
96
|
});
|
|
88
97
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -233,67 +242,7 @@ async function mockApiDelete(url, options = {}) {
|
|
|
233
242
|
}
|
|
234
243
|
|
|
235
244
|
// src/store/store.handler.ts
|
|
236
|
-
var
|
|
237
|
-
|
|
238
|
-
// src/store/store.ts
|
|
239
|
-
var StoreStrategy = /* @__PURE__ */ ((StoreStrategy2) => {
|
|
240
|
-
StoreStrategy2["Api"] = "api";
|
|
241
|
-
StoreStrategy2["Data"] = "data";
|
|
242
|
-
StoreStrategy2["Mock"] = "mock";
|
|
243
|
-
return StoreStrategy2;
|
|
244
|
-
})(StoreStrategy || {});
|
|
245
|
-
function getStoreStrategy() {
|
|
246
|
-
let storeStrategy2 = "mock" /* Mock */;
|
|
247
|
-
if (process && process.env.STORE_STRATEGY) {
|
|
248
|
-
storeStrategy2 = process.env.STORE_STRATEGY;
|
|
249
|
-
}
|
|
250
|
-
return storeStrategy2;
|
|
251
|
-
}
|
|
252
|
-
var storeStrategy = getStoreStrategy();
|
|
253
|
-
var ENV_COLLECTIONS = process.env.COLLECTIONS ? process.env.COLLECTIONS.split(",") : [];
|
|
254
|
-
var MOCK_COLLECTIONS = process.env.MOCKS ? process.env.MOCKS.split(",") : [];
|
|
255
|
-
var STATIC_COLLECTIONS = [];
|
|
256
|
-
var KNOWN_COLLECTIONS = [
|
|
257
|
-
"category",
|
|
258
|
-
"label",
|
|
259
|
-
"locale",
|
|
260
|
-
"market",
|
|
261
|
-
"menu",
|
|
262
|
-
"template",
|
|
263
|
-
"page",
|
|
264
|
-
"redirect",
|
|
265
|
-
"route",
|
|
266
|
-
...STATIC_COLLECTIONS
|
|
267
|
-
];
|
|
268
|
-
var COLLECTIONS = [...ENV_COLLECTIONS, ...KNOWN_COLLECTIONS];
|
|
269
|
-
|
|
270
|
-
// src/mock/mock.store.ts
|
|
271
|
-
var import_bom_core7 = require("@websolutespa/bom-core");
|
|
272
|
-
|
|
273
|
-
// src/fs/fs.service.ts
|
|
274
|
-
var fs = __toESM(require("fs"));
|
|
275
|
-
async function fsRead(pathname, option) {
|
|
276
|
-
try {
|
|
277
|
-
const data = await fs.promises.readFile(pathname, option?.encoding || "utf8");
|
|
278
|
-
return data || void 0;
|
|
279
|
-
} catch (error) {
|
|
280
|
-
console.log("fsRead.error", error, pathname);
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
async function fsReadJson(pathname) {
|
|
285
|
-
try {
|
|
286
|
-
const data = await fsRead(pathname);
|
|
287
|
-
if (data) {
|
|
288
|
-
return JSON.parse(data);
|
|
289
|
-
} else {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
} catch (error) {
|
|
293
|
-
console.log("fsReadJson.error", error, pathname);
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
245
|
+
var import_bom_core10 = require("@websolutespa/bom-core");
|
|
297
246
|
|
|
298
247
|
// src/static/static.ts
|
|
299
248
|
var staticCollections = [{
|
|
@@ -498,15 +447,190 @@ var staticCollections = [{
|
|
|
498
447
|
]
|
|
499
448
|
}];
|
|
500
449
|
|
|
450
|
+
// src/store/store.ts
|
|
451
|
+
var BuildStrategy = /* @__PURE__ */ ((BuildStrategy2) => {
|
|
452
|
+
BuildStrategy2["Static"] = "static";
|
|
453
|
+
BuildStrategy2["Runtime"] = "runtime";
|
|
454
|
+
return BuildStrategy2;
|
|
455
|
+
})(BuildStrategy || {});
|
|
456
|
+
function getBuildStrategy() {
|
|
457
|
+
let buildStrategy2 = "static" /* Static */;
|
|
458
|
+
if (process && process.env.BUILD_STRATEGY) {
|
|
459
|
+
buildStrategy2 = process.env.BUILD_STRATEGY;
|
|
460
|
+
}
|
|
461
|
+
return buildStrategy2;
|
|
462
|
+
}
|
|
463
|
+
var buildStrategy = getBuildStrategy();
|
|
464
|
+
var StoreStrategy = /* @__PURE__ */ ((StoreStrategy2) => {
|
|
465
|
+
StoreStrategy2["Api"] = "api";
|
|
466
|
+
StoreStrategy2["Data"] = "data";
|
|
467
|
+
StoreStrategy2["Mock"] = "mock";
|
|
468
|
+
return StoreStrategy2;
|
|
469
|
+
})(StoreStrategy || {});
|
|
470
|
+
function getStoreStrategy() {
|
|
471
|
+
let storeStrategy2 = "mock" /* Mock */;
|
|
472
|
+
if (process && process.env.STORE_STRATEGY) {
|
|
473
|
+
storeStrategy2 = process.env.STORE_STRATEGY;
|
|
474
|
+
}
|
|
475
|
+
return storeStrategy2;
|
|
476
|
+
}
|
|
477
|
+
var storeStrategy = getStoreStrategy();
|
|
478
|
+
var ENV_COLLECTIONS = process.env.COLLECTIONS ? process.env.COLLECTIONS.split(",") : [];
|
|
479
|
+
var MOCK_COLLECTIONS = process.env.MOCKS ? process.env.MOCKS.split(",") : [];
|
|
480
|
+
var STATIC_COLLECTIONS = staticCollections.map((x) => x.slug);
|
|
481
|
+
var KNOWN_COLLECTIONS = [
|
|
482
|
+
"category",
|
|
483
|
+
"label",
|
|
484
|
+
"locale",
|
|
485
|
+
"market",
|
|
486
|
+
"menu",
|
|
487
|
+
"template",
|
|
488
|
+
"redirect",
|
|
489
|
+
"route",
|
|
490
|
+
...STATIC_COLLECTIONS
|
|
491
|
+
];
|
|
492
|
+
var COLLECTIONS = [...ENV_COLLECTIONS, ...KNOWN_COLLECTIONS];
|
|
493
|
+
|
|
494
|
+
// src/mock/mock.store.ts
|
|
495
|
+
var import_bom_core6 = require("@websolutespa/bom-core");
|
|
496
|
+
|
|
497
|
+
// src/fs/fs.service.ts
|
|
498
|
+
var fs = __toESM(require("fs"));
|
|
499
|
+
async function fsRead(pathname, option) {
|
|
500
|
+
try {
|
|
501
|
+
const data = await fs.promises.readFile(pathname, option?.encoding || "utf8");
|
|
502
|
+
return data || void 0;
|
|
503
|
+
} catch (error) {
|
|
504
|
+
console.log("fsRead.error", error, pathname);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
async function fsReadJson(pathname) {
|
|
509
|
+
try {
|
|
510
|
+
const data = await fsRead(pathname);
|
|
511
|
+
if (data) {
|
|
512
|
+
return JSON.parse(data);
|
|
513
|
+
} else {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
} catch (error) {
|
|
517
|
+
console.log("fsReadJson.error", error, pathname);
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
501
522
|
// src/static/static.service.ts
|
|
523
|
+
var import_bom_core4 = require("@websolutespa/bom-core");
|
|
524
|
+
|
|
525
|
+
// src/mock/mock.service.ts
|
|
502
526
|
var import_bom_core3 = require("@websolutespa/bom-core");
|
|
503
|
-
var
|
|
527
|
+
var MOCK_SERVICE_DEFAULT_DEPTH = 2;
|
|
528
|
+
var MockService = class extends import_bom_core3.JsonService {
|
|
529
|
+
constructor(items, store) {
|
|
530
|
+
super(items);
|
|
531
|
+
this.store = store;
|
|
532
|
+
}
|
|
533
|
+
async decorateOne_(item, params = {}) {
|
|
534
|
+
let decoratedItem = await localizeItem_(item, params);
|
|
535
|
+
decoratedItem = await decorateRelation_(this.store, decoratedItem, {
|
|
536
|
+
market: params.market,
|
|
537
|
+
locale: params.locale,
|
|
538
|
+
depth: params.depth != null ? params.depth : MOCK_SERVICE_DEFAULT_DEPTH
|
|
539
|
+
});
|
|
540
|
+
return decoratedItem;
|
|
541
|
+
}
|
|
542
|
+
async decorateMany_(items, params = {}) {
|
|
543
|
+
let decoratedItems = await localizeItems_(items, params);
|
|
544
|
+
decoratedItems = await decorateRelations_(this.store, decoratedItems, {
|
|
545
|
+
market: params.market,
|
|
546
|
+
locale: params.locale,
|
|
547
|
+
depth: params.depth != null ? params.depth : MOCK_SERVICE_DEFAULT_DEPTH
|
|
548
|
+
});
|
|
549
|
+
return decoratedItems;
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
async function localizeItem_(item, params = {}) {
|
|
553
|
+
if (params.locale) {
|
|
554
|
+
return (0, import_bom_core3.localizeItem)(item, params.locale);
|
|
555
|
+
} else {
|
|
556
|
+
return (0, import_bom_core3.cloneItem)(item);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
async function localizeItems_(items, params = {}) {
|
|
560
|
+
const decoratedItems = [];
|
|
561
|
+
for (const item of items) {
|
|
562
|
+
const decoratedItem = params.locale ? (0, import_bom_core3.localizeItem)(item, params.locale) : (0, import_bom_core3.cloneItem)(item);
|
|
563
|
+
decoratedItems.push(decoratedItem);
|
|
564
|
+
}
|
|
565
|
+
return decoratedItems;
|
|
566
|
+
}
|
|
567
|
+
function collectRelations_(item, relations = []) {
|
|
568
|
+
if ((0, import_bom_core3.isObject)(item)) {
|
|
569
|
+
Object.entries(item).forEach(([key, value]) => {
|
|
570
|
+
if (key === "relation" && (0, import_bom_core3.isUnresolvedRelation)(value)) {
|
|
571
|
+
if (value.relationTo !== item.schema || value.value !== item.id) {
|
|
572
|
+
relations.push(value);
|
|
573
|
+
}
|
|
574
|
+
} else if ((0, import_bom_core3.isArray)(value)) {
|
|
575
|
+
value.forEach((x) => collectRelations_(x, relations));
|
|
576
|
+
} else if ((0, import_bom_core3.isObject)(value)) {
|
|
577
|
+
collectRelations_(value, relations);
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
return relations;
|
|
582
|
+
}
|
|
583
|
+
async function decorateRelation_(store, item, params = {}) {
|
|
584
|
+
const depth = params.depth != null ? params.depth : MOCK_SERVICE_DEFAULT_DEPTH;
|
|
585
|
+
if (depth === 0) {
|
|
586
|
+
return item;
|
|
587
|
+
}
|
|
588
|
+
const relations = collectRelations_(item);
|
|
589
|
+
for (const relation of relations) {
|
|
590
|
+
const isMany = Array.isArray(relation.value);
|
|
591
|
+
const items = await store[relation.relationTo].findMany({
|
|
592
|
+
...params,
|
|
593
|
+
where: {
|
|
594
|
+
id: { in: isMany ? relation.value : [relation.value] }
|
|
595
|
+
},
|
|
596
|
+
depth: depth - 1
|
|
597
|
+
});
|
|
598
|
+
if (isMany) {
|
|
599
|
+
relation.value = items;
|
|
600
|
+
} else {
|
|
601
|
+
relation.value = items.length ? items[0] : void 0;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return item;
|
|
605
|
+
}
|
|
606
|
+
async function decorateRelations_(store, items, params = {}) {
|
|
607
|
+
for (const item of items) {
|
|
608
|
+
await decorateRelation_(store, item, params);
|
|
609
|
+
}
|
|
610
|
+
return items;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// src/static/static.service.ts
|
|
614
|
+
var StaticService = class extends import_bom_core4.JsonService {
|
|
504
615
|
constructor(config, store) {
|
|
505
616
|
super([]);
|
|
506
617
|
this.loaded = false;
|
|
507
618
|
this.config = config;
|
|
508
619
|
this.store = store;
|
|
509
620
|
}
|
|
621
|
+
mapItems_(items, map) {
|
|
622
|
+
if (typeof map === "object") {
|
|
623
|
+
items = items.map((x) => {
|
|
624
|
+
const item = {};
|
|
625
|
+
Object.entries(x).forEach(([k, v]) => {
|
|
626
|
+
const key = map[k] || k;
|
|
627
|
+
item[key] = v;
|
|
628
|
+
});
|
|
629
|
+
return item;
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
return items;
|
|
633
|
+
}
|
|
510
634
|
async getItems() {
|
|
511
635
|
let items = this.items;
|
|
512
636
|
if (this.loaded && items) {
|
|
@@ -515,7 +639,7 @@ var StaticService = class extends import_bom_core3.JsonService {
|
|
|
515
639
|
const config = this.config;
|
|
516
640
|
const src = config.src;
|
|
517
641
|
if (typeof src === "string") {
|
|
518
|
-
const response = await (0,
|
|
642
|
+
const response = await (0, import_bom_core4.httpGet)(src, {});
|
|
519
643
|
items = response.items;
|
|
520
644
|
} else if (typeof src === "function") {
|
|
521
645
|
if (src instanceof Promise) {
|
|
@@ -532,161 +656,121 @@ var StaticService = class extends import_bom_core3.JsonService {
|
|
|
532
656
|
return items;
|
|
533
657
|
}
|
|
534
658
|
}
|
|
535
|
-
async
|
|
536
|
-
let
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
item = await this.relatedItems_(item, this.config.fields);
|
|
544
|
-
}
|
|
545
|
-
return this.decorator_(item, params);
|
|
546
|
-
} else {
|
|
547
|
-
console.log("StaticService.findOne.notfound", id, params);
|
|
548
|
-
return void 0;
|
|
549
|
-
}
|
|
659
|
+
async decorateOne_(item, params = {}) {
|
|
660
|
+
let decoratedItem = await localizeItem_(item, params);
|
|
661
|
+
decoratedItem = await decorateStaticRelation_(this.store, this.config.fields, decoratedItem, {
|
|
662
|
+
market: params.market,
|
|
663
|
+
locale: params.locale,
|
|
664
|
+
depth: params.depth
|
|
665
|
+
});
|
|
666
|
+
return decoratedItem;
|
|
550
667
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
return item;
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
return items;
|
|
668
|
+
async decorateMany_(items, params = {}) {
|
|
669
|
+
let decoratedItems = await localizeItems_(items, params);
|
|
670
|
+
decoratedItems = await decorateStaticRelations_(this.store, this.config.fields, decoratedItems, {
|
|
671
|
+
market: params.market,
|
|
672
|
+
locale: params.locale,
|
|
673
|
+
depth: params.depth
|
|
674
|
+
});
|
|
675
|
+
return decoratedItems;
|
|
563
676
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
677
|
+
};
|
|
678
|
+
async function decorateStaticRelation_(store, fields, item, params = {}) {
|
|
679
|
+
const depth = params.depth != null ? params.depth : MOCK_SERVICE_DEFAULT_DEPTH;
|
|
680
|
+
if (depth === 0) {
|
|
681
|
+
return item;
|
|
682
|
+
}
|
|
683
|
+
const decoratedItem = { ...item };
|
|
684
|
+
for (const field of fields) {
|
|
685
|
+
if (field.type === "relationship" && typeof field.relationTo === "string") {
|
|
686
|
+
const name = field.name;
|
|
687
|
+
const value = item[name];
|
|
688
|
+
const ids = field.hasMany ? value : [value];
|
|
689
|
+
const items = await store[field.relationTo].findMany({
|
|
690
|
+
where: {
|
|
691
|
+
id: { in: ids }
|
|
692
|
+
},
|
|
693
|
+
depth: depth - 1,
|
|
694
|
+
locale: params.locale
|
|
695
|
+
});
|
|
696
|
+
if (field.hasMany) {
|
|
697
|
+
decoratedItem[name] = items;
|
|
698
|
+
} else {
|
|
699
|
+
decoratedItem[name] = items.length ? items[0] : void 0;
|
|
578
700
|
}
|
|
579
701
|
}
|
|
580
|
-
return x;
|
|
581
702
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
703
|
+
return decoratedItem;
|
|
704
|
+
}
|
|
705
|
+
async function decorateStaticRelations_(store, fields, items, params = {}) {
|
|
706
|
+
const decoratedItems = [];
|
|
707
|
+
for (const item of items) {
|
|
708
|
+
const decoratedItem = await decorateStaticRelation_(store, fields, item, params);
|
|
709
|
+
decoratedItems.push(decoratedItem);
|
|
587
710
|
}
|
|
588
|
-
|
|
711
|
+
return decoratedItems;
|
|
712
|
+
}
|
|
589
713
|
|
|
590
714
|
// src/mock/mock-menu.service.ts
|
|
591
|
-
var
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
var import_bom_core4 = require("@websolutespa/bom-core");
|
|
595
|
-
var MockService = class extends import_bom_core4.JsonService {
|
|
596
|
-
constructor(items, store) {
|
|
597
|
-
super(items);
|
|
598
|
-
this.store = store;
|
|
599
|
-
}
|
|
600
|
-
// !!! todo handle relations
|
|
715
|
+
var MAX_INT = 1e12;
|
|
716
|
+
var UID = 0;
|
|
717
|
+
var MockMenuService = class extends MockService {
|
|
601
718
|
/*
|
|
602
|
-
|
|
603
|
-
console.log('
|
|
719
|
+
async findOne<B extends T = T>(id: IEquatable, params: QueryParams = {}): Promise<B | undefined> {
|
|
720
|
+
// console.log('MockMenuService.findOne', id, params);
|
|
604
721
|
let item = await super.findOne<B>(id, params);
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
}
|
|
722
|
+
if (item && params.market && params.locale) {
|
|
723
|
+
item = await decorateMenu_(this.store, (item as any), {
|
|
724
|
+
market: params.market,
|
|
725
|
+
locale: params.locale,
|
|
726
|
+
}) as any;
|
|
610
727
|
}
|
|
611
728
|
return item;
|
|
612
729
|
}
|
|
613
730
|
|
|
614
|
-
|
|
615
|
-
// console.log('
|
|
731
|
+
async findMany<B extends T = T>(params: QueryParams = {}): Promise<B[]> {
|
|
732
|
+
// console.log('MockMenuService.findMany', params);
|
|
616
733
|
let items = await super.findMany<B>(params);
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
734
|
+
if (params.market && params.locale) {
|
|
735
|
+
items = await decorateMenus_(this.store, (items as any[]), {
|
|
736
|
+
market: params.market,
|
|
737
|
+
locale: params.locale,
|
|
738
|
+
}) as any[];
|
|
620
739
|
}
|
|
621
740
|
return items;
|
|
622
741
|
}
|
|
623
742
|
|
|
624
|
-
|
|
625
|
-
// console.log('
|
|
743
|
+
async findPaged<B extends T = T>(params: QueryParams = {}): Promise<{ docs: B[]; } & Pagination> {
|
|
744
|
+
// console.log('MockMenuService.findPaged', params);
|
|
626
745
|
const pagination = await super.findPaged<B>(params);
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
746
|
+
if (params.market && params.locale) {
|
|
747
|
+
pagination.docs = await decorateMenus_(this.store, (pagination.docs as any[]), {
|
|
748
|
+
market: params.market,
|
|
749
|
+
locale: params.locale,
|
|
750
|
+
}) as any[];
|
|
630
751
|
}
|
|
631
752
|
return pagination;
|
|
632
753
|
}
|
|
633
|
-
|
|
634
|
-
protected async relatedItems_<B extends T = T>(item: B): Promise<B> {
|
|
635
|
-
const x = { ...item };
|
|
636
|
-
Object.entries(item).forEach(([k, v]) => {
|
|
637
|
-
if (isRelation(v)) {
|
|
638
|
-
console.log(k, v);
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
return x;
|
|
642
|
-
}
|
|
643
754
|
*/
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
return (0, import_bom_core4.localizeItem)(item, params.locale);
|
|
647
|
-
} else {
|
|
648
|
-
return item;
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
};
|
|
652
|
-
function isObject(item) {
|
|
653
|
-
return item !== null && typeof item === "object";
|
|
654
|
-
}
|
|
655
|
-
function isRelation(item) {
|
|
656
|
-
return isObject(item) && typeof item.relationTo === "string" && item.value !== void 0;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
// src/mock/mock-menu.service.ts
|
|
660
|
-
var MAX_INT = 1e12;
|
|
661
|
-
var UID = 0;
|
|
662
|
-
var MockMenuService = class extends MockService {
|
|
663
|
-
async findOne(id, params = {}) {
|
|
664
|
-
let item = await super.findOne(id, params);
|
|
665
|
-
if (item && params.market && params.locale) {
|
|
666
|
-
item = await decorateMenu(this.store, item, params.market, params.locale);
|
|
667
|
-
}
|
|
668
|
-
return item;
|
|
669
|
-
}
|
|
670
|
-
async findMany(params = {}) {
|
|
671
|
-
let items = await super.findMany(params);
|
|
755
|
+
async decorateOne_(item, params = {}) {
|
|
756
|
+
let decoratedItem = await localizeItem_(item, params);
|
|
672
757
|
if (params.market && params.locale) {
|
|
673
|
-
|
|
758
|
+
decoratedItem = await decorateMenu_(this.store, decoratedItem, {
|
|
759
|
+
market: params.market,
|
|
760
|
+
locale: params.locale
|
|
761
|
+
});
|
|
674
762
|
}
|
|
675
|
-
return
|
|
763
|
+
return decoratedItem;
|
|
676
764
|
}
|
|
677
|
-
async
|
|
678
|
-
|
|
765
|
+
async decorateMany_(items, params = {}) {
|
|
766
|
+
let decoratedItems = await localizeItems_(items, params);
|
|
679
767
|
if (params.market && params.locale) {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
decorator_(item, params = {}) {
|
|
685
|
-
if (params.locale) {
|
|
686
|
-
return (0, import_bom_core5.localizeItem)(item, params.locale);
|
|
687
|
-
} else {
|
|
688
|
-
return item;
|
|
768
|
+
decoratedItems = await decorateMenus_(this.store, decoratedItems, {
|
|
769
|
+
market: params.market,
|
|
770
|
+
locale: params.locale
|
|
771
|
+
});
|
|
689
772
|
}
|
|
773
|
+
return decoratedItems;
|
|
690
774
|
}
|
|
691
775
|
};
|
|
692
776
|
async function collectPages(store, items, params = {}) {
|
|
@@ -699,15 +783,15 @@ async function collectPages(store, items, params = {}) {
|
|
|
699
783
|
if (value) {
|
|
700
784
|
const routes = await store.route.findMany({
|
|
701
785
|
where: {
|
|
786
|
+
...params.market ? { market: { equals: params.market } } : {},
|
|
787
|
+
...params.locale ? { locale: { equals: params.locale } } : {},
|
|
702
788
|
page: {
|
|
703
789
|
equals: item.page.value
|
|
704
790
|
},
|
|
705
791
|
schema: {
|
|
706
792
|
equals: item.page.relationTo
|
|
707
793
|
}
|
|
708
|
-
}
|
|
709
|
-
market: params.market,
|
|
710
|
-
locale: params.locale
|
|
794
|
+
}
|
|
711
795
|
});
|
|
712
796
|
const page = {
|
|
713
797
|
...value,
|
|
@@ -725,31 +809,31 @@ async function collectPages(store, items, params = {}) {
|
|
|
725
809
|
}
|
|
726
810
|
}
|
|
727
811
|
}
|
|
728
|
-
async function
|
|
812
|
+
async function decorateMenu_(store, item, params) {
|
|
729
813
|
const items = item.items || [];
|
|
730
814
|
const decoratedItem = {
|
|
731
815
|
id: item.id,
|
|
732
816
|
items: []
|
|
733
817
|
};
|
|
734
|
-
const categories = await store.category.findMany(
|
|
818
|
+
const categories = await store.category.findMany(params);
|
|
735
819
|
const routes = await store.route.findMany({
|
|
820
|
+
...params,
|
|
736
821
|
where: {
|
|
737
|
-
market: {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
locale: {
|
|
741
|
-
equals: locale
|
|
742
|
-
}
|
|
743
|
-
},
|
|
744
|
-
market,
|
|
745
|
-
locale
|
|
822
|
+
...params.market ? { market: { equals: params.market } } : {},
|
|
823
|
+
...params.locale ? { locale: { equals: params.locale } } : {}
|
|
824
|
+
}
|
|
746
825
|
});
|
|
747
|
-
await collectPages(store, items,
|
|
748
|
-
decoratedItem.items = items.filter((x) => hasMarket(x, market)).map((x) => decorateMenuItem(x, categories, routes, market));
|
|
826
|
+
await collectPages(store, items, params);
|
|
827
|
+
decoratedItem.items = items.filter((x) => hasMarket(x, params.market)).map((x) => decorateMenuItem(x, categories, routes, params.market));
|
|
749
828
|
return decoratedItem;
|
|
750
829
|
}
|
|
751
|
-
async function
|
|
752
|
-
|
|
830
|
+
async function decorateMenus_(store, items, params) {
|
|
831
|
+
const decoratedItems = [];
|
|
832
|
+
for (const item of items) {
|
|
833
|
+
const decoratedItem = await decorateMenu_(store, item, params);
|
|
834
|
+
decoratedItems.push(decoratedItem);
|
|
835
|
+
}
|
|
836
|
+
return decoratedItems;
|
|
753
837
|
}
|
|
754
838
|
function decorateMenuCategory(item, categories, routes, market, depth = 0) {
|
|
755
839
|
const decoratedItem = {
|
|
@@ -841,7 +925,9 @@ function decorateMenuLink(item, categories, routes, market) {
|
|
|
841
925
|
}
|
|
842
926
|
function decorateMenuPage(item, categories, routes, market) {
|
|
843
927
|
const items = item.items || [];
|
|
844
|
-
const route = routes.find(
|
|
928
|
+
const route = routes.find(
|
|
929
|
+
(x) => x.schema === item.page.relationTo && x.page === item.page.value.id
|
|
930
|
+
);
|
|
845
931
|
const decoratedItem = {
|
|
846
932
|
id: item.id || "",
|
|
847
933
|
type: item.type,
|
|
@@ -886,66 +972,144 @@ function hasMarket(item, market) {
|
|
|
886
972
|
}
|
|
887
973
|
|
|
888
974
|
// src/mock/mock-page.service.ts
|
|
889
|
-
var
|
|
975
|
+
var import_bom_core5 = require("@websolutespa/bom-core");
|
|
890
976
|
var MockPageService = class extends MockService {
|
|
891
|
-
async
|
|
892
|
-
let
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
977
|
+
async decorateOne_(item, params = {}) {
|
|
978
|
+
let decoratedItem = await localizeItem_(item, params);
|
|
979
|
+
decoratedItem = await decorateHref_(this.store, decoratedItem, params);
|
|
980
|
+
decoratedItem = await decorateNav_(this.store, decoratedItem, params);
|
|
981
|
+
decoratedItem = await decorateRelation_(this.store, decoratedItem, {
|
|
982
|
+
market: params.market,
|
|
983
|
+
locale: params.locale,
|
|
984
|
+
depth: params.depth
|
|
985
|
+
});
|
|
986
|
+
return decoratedItem;
|
|
987
|
+
}
|
|
988
|
+
async decorateMany_(items, params = {}) {
|
|
989
|
+
let decoratedItems = await localizeItems_(items, params);
|
|
990
|
+
decoratedItems = await decorateHrefs_(this.store, decoratedItems, params);
|
|
991
|
+
decoratedItems = await decorateNavs_(this.store, decoratedItems, params);
|
|
992
|
+
decoratedItems = await decorateRelations_(this.store, decoratedItems, {
|
|
993
|
+
market: params.market,
|
|
994
|
+
locale: params.locale,
|
|
995
|
+
depth: params.depth
|
|
996
|
+
});
|
|
997
|
+
return decoratedItems;
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
async function decorateHref_(store, item, params = {}) {
|
|
1001
|
+
if (params.market && params.locale) {
|
|
1002
|
+
const routes = await store.route.findMany({
|
|
1003
|
+
where: {
|
|
1004
|
+
market: {
|
|
1005
|
+
equals: params.market
|
|
1006
|
+
},
|
|
1007
|
+
locale: {
|
|
1008
|
+
equals: params.locale
|
|
1009
|
+
},
|
|
1010
|
+
schema: {
|
|
1011
|
+
equals: item.schema
|
|
1012
|
+
},
|
|
1013
|
+
page: {
|
|
1014
|
+
equals: item.id
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
const href = routes.length ? routes[0].id : null;
|
|
1019
|
+
return { ...item, href };
|
|
1020
|
+
} else {
|
|
896
1021
|
return item;
|
|
897
1022
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
1023
|
+
}
|
|
1024
|
+
async function decorateHrefs_(store, items, params = {}) {
|
|
1025
|
+
if (params.market && params.locale) {
|
|
1026
|
+
const routes = await store.route.findMany({
|
|
1027
|
+
where: {
|
|
1028
|
+
market: {
|
|
1029
|
+
equals: params.market
|
|
1030
|
+
},
|
|
1031
|
+
locale: {
|
|
1032
|
+
equals: params.locale
|
|
1033
|
+
}
|
|
1034
|
+
/*
|
|
1035
|
+
...(params.market ? { market: { equals: params.market } } : {}),
|
|
1036
|
+
...(params.locale ? { locale: { equals: params.locale } } : {}),
|
|
1037
|
+
*/
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
return items.map((item) => {
|
|
1041
|
+
const route = routes.find(
|
|
1042
|
+
(x) => x.schema === item.schema && x.page === item.id
|
|
1043
|
+
);
|
|
1044
|
+
const href = route ? route.id : null;
|
|
1045
|
+
return { ...item, href };
|
|
1046
|
+
});
|
|
1047
|
+
} else {
|
|
903
1048
|
return items;
|
|
904
1049
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
1050
|
+
}
|
|
1051
|
+
async function decorateNav_(store, item, params = {}, routes) {
|
|
1052
|
+
if (!routes) {
|
|
1053
|
+
routes = await store.route.findMany({
|
|
1054
|
+
where: {
|
|
1055
|
+
...params.market ? { market: { equals: params.market } } : {},
|
|
1056
|
+
...params.locale ? { locale: { equals: params.locale } } : {}
|
|
1057
|
+
}
|
|
1058
|
+
});
|
|
911
1059
|
}
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
return item;
|
|
917
|
-
}
|
|
1060
|
+
const navs = collectNavs_(item);
|
|
1061
|
+
for (const nav of navs) {
|
|
1062
|
+
const decoratedNav = decorateNav__(nav, routes);
|
|
1063
|
+
nav.nav = decoratedNav.nav;
|
|
918
1064
|
}
|
|
919
|
-
|
|
920
|
-
|
|
1065
|
+
return item;
|
|
1066
|
+
}
|
|
1067
|
+
async function decorateNavs_(store, items, params = {}) {
|
|
921
1068
|
const routes = await store.route.findMany({
|
|
1069
|
+
...params,
|
|
922
1070
|
where: {
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
},
|
|
926
|
-
page: {
|
|
927
|
-
equals: item.id
|
|
928
|
-
},
|
|
929
|
-
market: {
|
|
930
|
-
equals: market
|
|
931
|
-
},
|
|
932
|
-
locale: {
|
|
933
|
-
equals: locale
|
|
934
|
-
}
|
|
1071
|
+
...params.market ? { market: { equals: params.market } } : {},
|
|
1072
|
+
...params.locale ? { locale: { equals: params.locale } } : {}
|
|
935
1073
|
}
|
|
936
1074
|
});
|
|
937
|
-
const
|
|
938
|
-
|
|
1075
|
+
for (const item of items) {
|
|
1076
|
+
await decorateNav_(store, item, params, routes);
|
|
1077
|
+
}
|
|
1078
|
+
return items;
|
|
1079
|
+
}
|
|
1080
|
+
function collectNavs_(item, navs = []) {
|
|
1081
|
+
if ((0, import_bom_core5.isUndecoratedNav)(item)) {
|
|
1082
|
+
navs.push(item);
|
|
1083
|
+
}
|
|
1084
|
+
if ((0, import_bom_core5.isArray)(item)) {
|
|
1085
|
+
item.forEach((x) => collectNavs_(x, navs));
|
|
1086
|
+
} else if ((0, import_bom_core5.isObject)(item)) {
|
|
1087
|
+
Object.values(item).forEach((value) => {
|
|
1088
|
+
collectNavs_(value, navs);
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
return navs;
|
|
939
1092
|
}
|
|
940
|
-
|
|
941
|
-
const
|
|
942
|
-
|
|
1093
|
+
function decorateNav__(item, routes) {
|
|
1094
|
+
const { nav, ...undecorated } = item;
|
|
1095
|
+
if (nav !== void 0) {
|
|
1096
|
+
const decorated = { ...undecorated };
|
|
943
1097
|
const route = routes.find(
|
|
944
|
-
(x) => x.
|
|
1098
|
+
(x) => x.page === nav.page.value && x.schema === nav.page.relationTo
|
|
945
1099
|
);
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1100
|
+
if (route) {
|
|
1101
|
+
decorated.nav = {
|
|
1102
|
+
type: "page",
|
|
1103
|
+
id: route.id,
|
|
1104
|
+
href: route.id,
|
|
1105
|
+
title: route.title,
|
|
1106
|
+
page: nav.page.value,
|
|
1107
|
+
schema: nav.page.relationTo
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
return decorated;
|
|
1111
|
+
}
|
|
1112
|
+
return undecorated;
|
|
949
1113
|
}
|
|
950
1114
|
|
|
951
1115
|
// src/mock/mock.store.ts
|
|
@@ -985,7 +1149,7 @@ function getMockStoreFromData_(data) {
|
|
|
985
1149
|
return store;
|
|
986
1150
|
}
|
|
987
1151
|
async function getStoreData_() {
|
|
988
|
-
if (
|
|
1152
|
+
if (import_bom_core6.isDevelopment) {
|
|
989
1153
|
const path = require("path");
|
|
990
1154
|
const pathname = path.join(process.cwd(), ".mixer", "store.json");
|
|
991
1155
|
return await fsReadJson(pathname) || {};
|
|
@@ -1004,26 +1168,26 @@ async function getMockStore() {
|
|
|
1004
1168
|
console.log("getMockStore");
|
|
1005
1169
|
const store = await getMockStore_();
|
|
1006
1170
|
return store;
|
|
1007
|
-
},
|
|
1171
|
+
}, import_bom_core6.isDevelopment ? void 0 : "STORE_MOCK_");
|
|
1008
1172
|
}
|
|
1009
1173
|
|
|
1010
1174
|
// src/remote/remote.store.ts
|
|
1011
|
-
var
|
|
1175
|
+
var import_bom_core9 = require("@websolutespa/bom-core");
|
|
1012
1176
|
|
|
1013
1177
|
// src/remote/remote.api.ts
|
|
1014
|
-
var
|
|
1178
|
+
var import_bom_core7 = require("@websolutespa/bom-core");
|
|
1015
1179
|
var API_URL3 = process.env.STORE_URL;
|
|
1016
1180
|
var API_BASE4 = process.env.STORE_API || "/api";
|
|
1017
1181
|
function getRemoteApiUrl(pathname) {
|
|
1018
1182
|
let url = `${API_URL3}${API_BASE4}${pathname}`;
|
|
1019
|
-
url =
|
|
1183
|
+
url = import_bom_core7.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
|
|
1020
1184
|
console.log("getRemoteApiUrl", url);
|
|
1021
1185
|
return url;
|
|
1022
1186
|
}
|
|
1023
1187
|
async function remoteApiFetch(pathname, options = {}) {
|
|
1024
1188
|
const url = getRemoteApiUrl(pathname);
|
|
1025
|
-
const apiOptions = (0,
|
|
1026
|
-
const apiResponse = await (0,
|
|
1189
|
+
const apiOptions = (0, import_bom_core7.merge)({ ...getDefaultApiRequestOptions() }, options);
|
|
1190
|
+
const apiResponse = await (0, import_bom_core7.httpFetch)(url, apiOptions);
|
|
1027
1191
|
return apiResponse;
|
|
1028
1192
|
}
|
|
1029
1193
|
async function remoteApiGet(url, options = {}) {
|
|
@@ -1043,7 +1207,7 @@ async function remoteApiDelete(url, options = {}) {
|
|
|
1043
1207
|
}
|
|
1044
1208
|
|
|
1045
1209
|
// src/remote/remote.service.ts
|
|
1046
|
-
var
|
|
1210
|
+
var import_bom_core8 = require("@websolutespa/bom-core");
|
|
1047
1211
|
var RemoteService = class {
|
|
1048
1212
|
constructor(key) {
|
|
1049
1213
|
if (!key) {
|
|
@@ -1053,46 +1217,49 @@ var RemoteService = class {
|
|
|
1053
1217
|
}
|
|
1054
1218
|
async findOne(id, params = {}) {
|
|
1055
1219
|
params.richText = String(params.richText) === "true" ? true : false;
|
|
1056
|
-
const query = (0,
|
|
1220
|
+
const query = (0, import_bom_core8.qsSerialize)(params);
|
|
1057
1221
|
const search = query ? `?${query}` : "";
|
|
1058
1222
|
const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
|
|
1059
1223
|
const item = await remoteApiGet(url);
|
|
1060
1224
|
if (item) {
|
|
1061
|
-
return this.
|
|
1225
|
+
return await this.decorateOne_(item, params);
|
|
1062
1226
|
}
|
|
1063
1227
|
return;
|
|
1064
1228
|
}
|
|
1065
1229
|
async findMany(params = {}) {
|
|
1066
1230
|
params.richText = String(params.richText) === "true" ? true : false;
|
|
1067
1231
|
params.pagination = false;
|
|
1068
|
-
const query = (0,
|
|
1232
|
+
const query = (0, import_bom_core8.qsSerialize)(params);
|
|
1069
1233
|
const search = query ? `?${query}` : "";
|
|
1070
1234
|
const url = `/${this.key}${search}`;
|
|
1071
1235
|
const response = await remoteApiGet(url);
|
|
1072
1236
|
const items = Array.isArray(response.docs) ? response.docs : response;
|
|
1073
|
-
return
|
|
1237
|
+
return await this.decorateMany_(items, params);
|
|
1074
1238
|
}
|
|
1075
1239
|
async findPaged(params = {}) {
|
|
1076
1240
|
params.richText = String(params.richText) === "true" ? true : false;
|
|
1077
1241
|
params.pagination = true;
|
|
1078
|
-
const query = (0,
|
|
1242
|
+
const query = (0, import_bom_core8.qsSerialize)(params);
|
|
1079
1243
|
const search = query ? `?${query}` : "";
|
|
1080
1244
|
const url = `/${this.key}${search}`;
|
|
1081
1245
|
const response = await remoteApiGet(url);
|
|
1082
1246
|
let items = response.docs;
|
|
1083
|
-
items =
|
|
1247
|
+
items = await this.decorateMany_(items, params);
|
|
1084
1248
|
return { ...response, docs: items };
|
|
1085
1249
|
}
|
|
1250
|
+
// !!! todo params
|
|
1086
1251
|
async create(payload) {
|
|
1087
1252
|
const url = `/${this.key}`;
|
|
1088
1253
|
const item = await remoteApiPost(url, payload);
|
|
1089
|
-
return this.
|
|
1254
|
+
return await this.decorateOne_(item, {});
|
|
1090
1255
|
}
|
|
1256
|
+
// !!! todo params
|
|
1091
1257
|
async update(payload) {
|
|
1092
1258
|
const url = `/${this.key}`;
|
|
1093
1259
|
const item = await remoteApiPut(url, payload);
|
|
1094
|
-
return this.
|
|
1260
|
+
return await this.decorateOne_(item, {});
|
|
1095
1261
|
}
|
|
1262
|
+
// !!! todo params
|
|
1096
1263
|
async delete(id) {
|
|
1097
1264
|
const params = {
|
|
1098
1265
|
where: {
|
|
@@ -1101,16 +1268,18 @@ var RemoteService = class {
|
|
|
1101
1268
|
}
|
|
1102
1269
|
}
|
|
1103
1270
|
};
|
|
1104
|
-
const query = (0,
|
|
1271
|
+
const query = (0, import_bom_core8.qsSerialize)(params);
|
|
1105
1272
|
const search = query ? `?${query}` : "";
|
|
1106
1273
|
const url = `/${this.key}${search}`;
|
|
1107
1274
|
const item = await remoteApiDelete(url);
|
|
1108
|
-
return this.
|
|
1275
|
+
return await this.decorateOne_(item, {});
|
|
1109
1276
|
}
|
|
1110
|
-
|
|
1111
|
-
decorator_(item, params = {}) {
|
|
1277
|
+
async decorateOne_(item, params = {}) {
|
|
1112
1278
|
return item;
|
|
1113
1279
|
}
|
|
1280
|
+
async decorateMany_(items, params = {}) {
|
|
1281
|
+
return items;
|
|
1282
|
+
}
|
|
1114
1283
|
};
|
|
1115
1284
|
|
|
1116
1285
|
// src/remote/remote.store.ts
|
|
@@ -1135,11 +1304,11 @@ async function getRemoteStore_() {
|
|
|
1135
1304
|
}
|
|
1136
1305
|
});
|
|
1137
1306
|
return store;
|
|
1138
|
-
},
|
|
1307
|
+
}, import_bom_core9.isDevelopment ? void 0 : "STORE_RUNTIME_");
|
|
1139
1308
|
}
|
|
1140
|
-
async function
|
|
1309
|
+
async function getRemoteStoreStaticBuild_() {
|
|
1141
1310
|
return fromCache(async () => {
|
|
1142
|
-
console.log("
|
|
1311
|
+
console.log("getRemoteStoreStaticBuild_");
|
|
1143
1312
|
const store = {};
|
|
1144
1313
|
const url = "/store?pagination=true&richText=false";
|
|
1145
1314
|
const json = await remoteApiGet(url);
|
|
@@ -1155,9 +1324,24 @@ async function getRemoteStoreProductionBuild_() {
|
|
|
1155
1324
|
return store;
|
|
1156
1325
|
}, "STORE_BUILD_");
|
|
1157
1326
|
}
|
|
1327
|
+
async function getRemoteStoreRuntimeBuild_() {
|
|
1328
|
+
return fromCache(async () => {
|
|
1329
|
+
console.log("getRemoteStoreRuntimeBuild_");
|
|
1330
|
+
const data = {};
|
|
1331
|
+
COLLECTIONS.forEach((key) => {
|
|
1332
|
+
data[key] = [];
|
|
1333
|
+
});
|
|
1334
|
+
const store = getMockStoreFromData_(data);
|
|
1335
|
+
return store;
|
|
1336
|
+
}, "STORE_RUNTIME_BUILD_");
|
|
1337
|
+
}
|
|
1158
1338
|
async function getRemoteStore() {
|
|
1159
1339
|
if (process.env.NEXT_PHASE === "phase-production-build") {
|
|
1160
|
-
|
|
1340
|
+
if (buildStrategy === "runtime" /* Runtime */) {
|
|
1341
|
+
return await getRemoteStoreRuntimeBuild_();
|
|
1342
|
+
} else {
|
|
1343
|
+
return await getRemoteStoreStaticBuild_();
|
|
1344
|
+
}
|
|
1161
1345
|
} else {
|
|
1162
1346
|
return await getRemoteStore_();
|
|
1163
1347
|
}
|
|
@@ -1193,7 +1377,7 @@ function collectionGet(storePromise) {
|
|
|
1193
1377
|
const collection = collections[0];
|
|
1194
1378
|
const id = collections[1];
|
|
1195
1379
|
const qs = Object.entries(query).map((kv) => kv.join("=")).join("&");
|
|
1196
|
-
const params = (0,
|
|
1380
|
+
const params = (0, import_bom_core10.qsDeserialize)(qs);
|
|
1197
1381
|
if (!COLLECTIONS.includes(collection)) {
|
|
1198
1382
|
console.error("storeHandler.collectionGet", "method not allowed", collection);
|
|
1199
1383
|
return response.status(405).send("method not allowed");
|
|
@@ -1205,7 +1389,7 @@ function collectionGet(storePromise) {
|
|
|
1205
1389
|
return response.status(405).send("method not allowed");
|
|
1206
1390
|
}
|
|
1207
1391
|
if (id) {
|
|
1208
|
-
const item = await service.findOne((0,
|
|
1392
|
+
const item = await service.findOne((0, import_bom_core10.asEquatable)(id), params);
|
|
1209
1393
|
if (item) {
|
|
1210
1394
|
return response.status(200).json(item);
|
|
1211
1395
|
} else {
|
|
@@ -1258,7 +1442,6 @@ function collectionPatch(storePromise) {
|
|
|
1258
1442
|
return response.status(405).send("method not allowed");
|
|
1259
1443
|
}
|
|
1260
1444
|
const collection = collections[0];
|
|
1261
|
-
const id = collections[1];
|
|
1262
1445
|
const store = await storePromise();
|
|
1263
1446
|
const service = store[collection];
|
|
1264
1447
|
if (!service) {
|
|
@@ -1388,6 +1571,135 @@ async function routePost(store, request, response) {
|
|
|
1388
1571
|
return response.status(400).send("bad request");
|
|
1389
1572
|
}
|
|
1390
1573
|
}
|
|
1574
|
+
function storeIndexHandler() {
|
|
1575
|
+
return apiHandler({
|
|
1576
|
+
get: async (request, response) => {
|
|
1577
|
+
try {
|
|
1578
|
+
if (!Array.isArray(COLLECTIONS) || COLLECTIONS?.length === 0) {
|
|
1579
|
+
console.error("apiHome.collectionGet", "collections not found", COLLECTIONS);
|
|
1580
|
+
return response.status(405).send("method not allowed");
|
|
1581
|
+
}
|
|
1582
|
+
response.setHeader("Content-Type", "text/html; charset=UTF-8");
|
|
1583
|
+
response.setHeader("X-Frame-Options", "SAMEORIGIN");
|
|
1584
|
+
response.setHeader("X-Robots-Tag", "noindex, follow");
|
|
1585
|
+
return response.status(200).send(`
|
|
1586
|
+
<html>
|
|
1587
|
+
<head>
|
|
1588
|
+
<title>REST Api</title>
|
|
1589
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
1590
|
+
<style type="text/css">
|
|
1591
|
+
html {
|
|
1592
|
+
padding: 0;
|
|
1593
|
+
background: #09090A;
|
|
1594
|
+
color: #fefefe;
|
|
1595
|
+
}
|
|
1596
|
+
body {
|
|
1597
|
+
padding: 15px;
|
|
1598
|
+
font-family: Inter,-apple-system,'Helvetica Neue','Segoe UI',Roboto,Arial,'Noto Sans',sans-serif;
|
|
1599
|
+
font-size: 13px;
|
|
1600
|
+
background: #09090A;
|
|
1601
|
+
color: #fefefe;
|
|
1602
|
+
}
|
|
1603
|
+
.container {
|
|
1604
|
+
margin: 0 auto;
|
|
1605
|
+
max-width: 1280px;
|
|
1606
|
+
}
|
|
1607
|
+
a {
|
|
1608
|
+
color: #fefefe;
|
|
1609
|
+
text-decoration: none;
|
|
1610
|
+
}
|
|
1611
|
+
a:visited {
|
|
1612
|
+
color: #9e9e9e;
|
|
1613
|
+
}
|
|
1614
|
+
a:hover {
|
|
1615
|
+
text-decoration: underline;
|
|
1616
|
+
}
|
|
1617
|
+
table {
|
|
1618
|
+
width: 100%;
|
|
1619
|
+
margin: 10px 0;
|
|
1620
|
+
border: none;
|
|
1621
|
+
border-collapse: collapse;
|
|
1622
|
+
}
|
|
1623
|
+
td,
|
|
1624
|
+
th {
|
|
1625
|
+
text-align: left;
|
|
1626
|
+
font-size: 12px;
|
|
1627
|
+
padding: 3px;
|
|
1628
|
+
}
|
|
1629
|
+
th:not(:last-child),
|
|
1630
|
+
td:not(:last-child) {
|
|
1631
|
+
padding-right: 30px;
|
|
1632
|
+
}
|
|
1633
|
+
thead th {
|
|
1634
|
+
border-bottom: 1px solid #0e0e0f;
|
|
1635
|
+
}
|
|
1636
|
+
#table tr:nth-child(odd) td {
|
|
1637
|
+
background-color: #0e0e0f;
|
|
1638
|
+
}
|
|
1639
|
+
#table tbody tr:hover td {
|
|
1640
|
+
background-color: #1A1A1B;
|
|
1641
|
+
}
|
|
1642
|
+
#table tbody tr:hover td,
|
|
1643
|
+
#table tbody tr:hover td a {
|
|
1644
|
+
color: #fefefe;
|
|
1645
|
+
}
|
|
1646
|
+
.wysiwyg {
|
|
1647
|
+
margin: 0;
|
|
1648
|
+
padding: 0 0 10px 0;
|
|
1649
|
+
line-height: 1.2em;
|
|
1650
|
+
}
|
|
1651
|
+
.wysiwyg a {
|
|
1652
|
+
color: #00ea4e;
|
|
1653
|
+
font-weight: 600;
|
|
1654
|
+
}
|
|
1655
|
+
.wysiwyg a:visited {
|
|
1656
|
+
color: #00ea4e;
|
|
1657
|
+
}
|
|
1658
|
+
</style>
|
|
1659
|
+
</head>
|
|
1660
|
+
<body>
|
|
1661
|
+
<div class="container">
|
|
1662
|
+
<h1>REST API</h1>
|
|
1663
|
+
<p class="wysiwyg">
|
|
1664
|
+
This is the REST Api generated by <a href="https://github.com/websolutespa/bom" target="_blank" rel="noopener">Mixer</a>.
|
|
1665
|
+
</p>
|
|
1666
|
+
<p class="wysiwyg">
|
|
1667
|
+
It contains a list of all the generic local api CRUD handlers of Mixer app. <br />
|
|
1668
|
+
All methods should be called with market and locale parameters.
|
|
1669
|
+
</p>
|
|
1670
|
+
<table id="table" cellpadding="3">
|
|
1671
|
+
<thead>
|
|
1672
|
+
<tr>
|
|
1673
|
+
<th width="150px">Method</th>
|
|
1674
|
+
<th width="150px">Collection</th>
|
|
1675
|
+
<th>Endpoint</th>
|
|
1676
|
+
</tr>
|
|
1677
|
+
</thead>
|
|
1678
|
+
<tbody>
|
|
1679
|
+
${COLLECTIONS.map((c) => `
|
|
1680
|
+
<tr>
|
|
1681
|
+
<td>GET, POST, PATCH</td>
|
|
1682
|
+
<td>${c}</td>
|
|
1683
|
+
<td><a href="/api/${c}?market={market}&locale={locale}">/api/${c}</a></td>
|
|
1684
|
+
</tr>
|
|
1685
|
+
<tr>
|
|
1686
|
+
<td>GET, DELETE</td>
|
|
1687
|
+
<td>${c}</td>
|
|
1688
|
+
<td><a href="/api/${c}/{id}?market={market}&locale={locale}">/api/${c}/{id}</a></td>
|
|
1689
|
+
</tr>
|
|
1690
|
+
`).join("\n")}
|
|
1691
|
+
</tbody>
|
|
1692
|
+
</table>
|
|
1693
|
+
</div>
|
|
1694
|
+
</body>
|
|
1695
|
+
`);
|
|
1696
|
+
} catch (error) {
|
|
1697
|
+
console.error("storeHandler.collectionGet.error", "500", error);
|
|
1698
|
+
throw error;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1391
1703
|
|
|
1392
1704
|
// src/mock/mock.handler.ts
|
|
1393
1705
|
function mockHandler() {
|
|
@@ -1413,31 +1725,37 @@ async function storeApiDelete(url, options = {}) {
|
|
|
1413
1725
|
}
|
|
1414
1726
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1415
1727
|
0 && (module.exports = {
|
|
1728
|
+
BuildStrategy,
|
|
1416
1729
|
COLLECTIONS,
|
|
1417
1730
|
KNOWN_COLLECTIONS,
|
|
1418
1731
|
MOCK_COLLECTIONS,
|
|
1732
|
+
MOCK_SERVICE_DEFAULT_DEPTH,
|
|
1419
1733
|
MockService,
|
|
1420
1734
|
RemoteService,
|
|
1421
1735
|
STATIC_COLLECTIONS,
|
|
1422
1736
|
StaticService,
|
|
1423
1737
|
StoreStrategy,
|
|
1424
1738
|
apiHandler,
|
|
1739
|
+
buildStrategy,
|
|
1425
1740
|
collectionDelete,
|
|
1426
1741
|
collectionGet,
|
|
1427
1742
|
collectionPatch,
|
|
1428
1743
|
collectionPost,
|
|
1744
|
+
decorateRelation_,
|
|
1745
|
+
decorateRelations_,
|
|
1746
|
+
decorateStaticRelation_,
|
|
1747
|
+
decorateStaticRelations_,
|
|
1429
1748
|
defaultApiRequestOptions,
|
|
1430
1749
|
errorHandler,
|
|
1431
1750
|
fromCache,
|
|
1432
1751
|
getDefaultApiRequestOptions,
|
|
1433
1752
|
getLocalApiUrl,
|
|
1434
1753
|
getMockStore,
|
|
1754
|
+
getMockStoreFromData_,
|
|
1435
1755
|
getRemoteStore,
|
|
1436
1756
|
getStore,
|
|
1437
1757
|
isApiRequest,
|
|
1438
1758
|
isNextRequest,
|
|
1439
|
-
isObject,
|
|
1440
|
-
isRelation,
|
|
1441
1759
|
isStaticRequest,
|
|
1442
1760
|
localApiDelete,
|
|
1443
1761
|
localApiFetch,
|
|
@@ -1445,6 +1763,8 @@ async function storeApiDelete(url, options = {}) {
|
|
|
1445
1763
|
localApiPatch,
|
|
1446
1764
|
localApiPost,
|
|
1447
1765
|
localApiPut,
|
|
1766
|
+
localizeItem_,
|
|
1767
|
+
localizeItems_,
|
|
1448
1768
|
mockApiDelete,
|
|
1449
1769
|
mockApiFetch,
|
|
1450
1770
|
mockApiGet,
|
|
@@ -1466,5 +1786,6 @@ async function storeApiDelete(url, options = {}) {
|
|
|
1466
1786
|
storeApiPost,
|
|
1467
1787
|
storeApiPut,
|
|
1468
1788
|
storeHandler,
|
|
1789
|
+
storeIndexHandler,
|
|
1469
1790
|
storeStrategy
|
|
1470
1791
|
});
|