@websolutespa/bom-mixer-store 1.3.0 → 1.4.1

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @websolutespa/bom-mixer-store
2
2
 
3
+ ## 1.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: MockPageService
8
+ - Updated dependencies
9
+ - @websolutespa/bom-core@0.6.3
10
+
11
+ ## 1.4.0
12
+
13
+ ### Minor Changes
14
+
15
+ - Added: BuildStrategy.
16
+
3
17
  ## 1.3.0
4
18
 
5
19
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FetchRequestOptions, IEntity, JsonService, IStore, QueryParams, ISchema, IQuerable, IEquatable, Pagination } from '@websolutespa/bom-core';
1
+ import { FetchRequestOptions, IEntity, JsonService, IStore, QueryParams, ISchema, IMemoryStore, IQuerable, IEquatable, Pagination } from '@websolutespa/bom-core';
2
2
  import { NextApiRequest, NextApiResponse } from 'next';
3
3
  import { NextRequest } from 'next/server';
4
4
 
@@ -65,6 +65,7 @@ declare function localizeItems_<B>(items: B[], params?: QueryParams): Promise<B[
65
65
  declare function decorateRelation_<T extends ISchema = ISchema>(store: IStore, item: T, params?: QueryParams): Promise<T>;
66
66
  declare function decorateRelations_<T extends ISchema = ISchema>(store: IStore, items: T[], params?: QueryParams): Promise<T[]>;
67
67
 
68
+ declare function getMockStoreFromData_<T extends IStore>(data?: IMemoryStore): T;
68
69
  declare function getMockStore<T extends IStore = IStore>(): Promise<T>;
69
70
 
70
71
  declare function remoteApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): Promise<T>;
@@ -125,6 +126,11 @@ declare class StaticService<T extends IEntity = IEntity> extends JsonService<T>
125
126
  declare function decorateStaticRelation_<T>(store: IStore, fields: IField[], item: T, params?: QueryParams): Promise<T>;
126
127
  declare function decorateStaticRelations_<T>(store: IStore, fields: IField[], items: T[], params?: QueryParams): Promise<T[]>;
127
128
 
129
+ declare enum BuildStrategy {
130
+ Static = "static",
131
+ Runtime = "runtime"
132
+ }
133
+ declare const buildStrategy: BuildStrategy;
128
134
  declare enum StoreStrategy {
129
135
  Api = "api",
130
136
  Data = "data",
@@ -152,4 +158,4 @@ declare function storeIndexHandler(): any;
152
158
 
153
159
  declare function getStore<T extends IStore>(): Promise<T>;
154
160
 
155
- export { ApiRequestOptions, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, KNOWN_COLLECTIONS, MOCK_COLLECTIONS, MOCK_SERVICE_DEFAULT_DEPTH, MapTo, MockService, RemoteService, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateRelation_, decorateRelations_, decorateStaticRelation_, decorateStaticRelations_, defaultApiRequestOptions, errorHandler, fromCache, getDefaultApiRequestOptions, getLocalApiUrl, getMockStore, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, localizeItem_, localizeItems_, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeHandler, storeIndexHandler, storeStrategy };
161
+ export { ApiRequestOptions, BuildStrategy, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, KNOWN_COLLECTIONS, MOCK_COLLECTIONS, MOCK_SERVICE_DEFAULT_DEPTH, MapTo, MockService, RemoteService, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateRelation_, decorateRelations_, decorateStaticRelation_, decorateStaticRelations_, defaultApiRequestOptions, errorHandler, fromCache, getDefaultApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, localizeItem_, localizeItems_, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeHandler, storeIndexHandler, storeStrategy };
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ 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,
@@ -40,6 +41,7 @@ __export(src_exports, {
40
41
  StaticService: () => StaticService,
41
42
  StoreStrategy: () => StoreStrategy,
42
43
  apiHandler: () => apiHandler,
44
+ buildStrategy: () => buildStrategy,
43
45
  collectionDelete: () => collectionDelete,
44
46
  collectionGet: () => collectionGet,
45
47
  collectionPatch: () => collectionPatch,
@@ -54,6 +56,7 @@ __export(src_exports, {
54
56
  getDefaultApiRequestOptions: () => getDefaultApiRequestOptions,
55
57
  getLocalApiUrl: () => getLocalApiUrl,
56
58
  getMockStore: () => getMockStore,
59
+ getMockStoreFromData_: () => getMockStoreFromData_,
57
60
  getRemoteStore: () => getRemoteStore,
58
61
  getStore: () => getStore,
59
62
  isApiRequest: () => isApiRequest,
@@ -445,6 +448,19 @@ var staticCollections = [{
445
448
  }];
446
449
 
447
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();
448
464
  var StoreStrategy = /* @__PURE__ */ ((StoreStrategy2) => {
449
465
  StoreStrategy2["Api"] = "api";
450
466
  StoreStrategy2["Data"] = "data";
@@ -468,9 +484,9 @@ var KNOWN_COLLECTIONS = [
468
484
  "locale",
469
485
  "market",
470
486
  "menu",
471
- "template",
472
487
  "redirect",
473
488
  "route",
489
+ "template",
474
490
  ...STATIC_COLLECTIONS
475
491
  ];
476
492
  var COLLECTIONS = [...ENV_COLLECTIONS, ...KNOWN_COLLECTIONS];
@@ -1084,11 +1100,11 @@ function decorateNav__(item, routes) {
1084
1100
  if (route) {
1085
1101
  decorated.nav = {
1086
1102
  type: "page",
1087
- id: route.id,
1103
+ id: route.page,
1088
1104
  href: route.id,
1089
1105
  title: route.title,
1090
- page: nav.page.value,
1091
- schema: nav.page.relationTo
1106
+ page: route.page,
1107
+ schema: route.schema
1092
1108
  };
1093
1109
  }
1094
1110
  return decorated;
@@ -1149,7 +1165,9 @@ async function getMockStore_() {
1149
1165
  }
1150
1166
  async function getMockStore() {
1151
1167
  return fromCache(async () => {
1152
- console.log("getMockStore");
1168
+ if (!import_bom_core6.isDevelopment) {
1169
+ console.warn("getMockStore");
1170
+ }
1153
1171
  const store = await getMockStore_();
1154
1172
  return store;
1155
1173
  }, import_bom_core6.isDevelopment ? void 0 : "STORE_MOCK_");
@@ -1290,9 +1308,9 @@ async function getRemoteStore_() {
1290
1308
  return store;
1291
1309
  }, import_bom_core9.isDevelopment ? void 0 : "STORE_RUNTIME_");
1292
1310
  }
1293
- async function getRemoteStoreProductionBuild_() {
1311
+ async function getRemoteStoreStaticBuild_() {
1294
1312
  return fromCache(async () => {
1295
- console.log("getRemoteStoreProductionBuild_");
1313
+ console.log("getRemoteStoreStaticBuild_");
1296
1314
  const store = {};
1297
1315
  const url = "/store?pagination=true&richText=false";
1298
1316
  const json = await remoteApiGet(url);
@@ -1308,9 +1326,24 @@ async function getRemoteStoreProductionBuild_() {
1308
1326
  return store;
1309
1327
  }, "STORE_BUILD_");
1310
1328
  }
1329
+ async function getRemoteStoreRuntimeBuild_() {
1330
+ return fromCache(async () => {
1331
+ console.log("getRemoteStoreRuntimeBuild_");
1332
+ const data = {};
1333
+ COLLECTIONS.forEach((key) => {
1334
+ data[key] = [];
1335
+ });
1336
+ const store = getMockStoreFromData_(data);
1337
+ return store;
1338
+ }, "STORE_RUNTIME_BUILD_");
1339
+ }
1311
1340
  async function getRemoteStore() {
1312
1341
  if (process.env.NEXT_PHASE === "phase-production-build") {
1313
- return await getRemoteStoreProductionBuild_();
1342
+ if (buildStrategy === "runtime" /* Runtime */) {
1343
+ return await getRemoteStoreRuntimeBuild_();
1344
+ } else {
1345
+ return await getRemoteStoreStaticBuild_();
1346
+ }
1314
1347
  } else {
1315
1348
  return await getRemoteStore_();
1316
1349
  }
@@ -1694,6 +1727,7 @@ async function storeApiDelete(url, options = {}) {
1694
1727
  }
1695
1728
  // Annotate the CommonJS export names for ESM import in node:
1696
1729
  0 && (module.exports = {
1730
+ BuildStrategy,
1697
1731
  COLLECTIONS,
1698
1732
  KNOWN_COLLECTIONS,
1699
1733
  MOCK_COLLECTIONS,
@@ -1704,6 +1738,7 @@ async function storeApiDelete(url, options = {}) {
1704
1738
  StaticService,
1705
1739
  StoreStrategy,
1706
1740
  apiHandler,
1741
+ buildStrategy,
1707
1742
  collectionDelete,
1708
1743
  collectionGet,
1709
1744
  collectionPatch,
@@ -1718,6 +1753,7 @@ async function storeApiDelete(url, options = {}) {
1718
1753
  getDefaultApiRequestOptions,
1719
1754
  getLocalApiUrl,
1720
1755
  getMockStore,
1756
+ getMockStoreFromData_,
1721
1757
  getRemoteStore,
1722
1758
  getStore,
1723
1759
  isApiRequest,
package/dist/index.mjs CHANGED
@@ -358,6 +358,19 @@ var staticCollections = [{
358
358
  }];
359
359
 
360
360
  // src/store/store.ts
361
+ var BuildStrategy = /* @__PURE__ */ ((BuildStrategy2) => {
362
+ BuildStrategy2["Static"] = "static";
363
+ BuildStrategy2["Runtime"] = "runtime";
364
+ return BuildStrategy2;
365
+ })(BuildStrategy || {});
366
+ function getBuildStrategy() {
367
+ let buildStrategy2 = "static" /* Static */;
368
+ if (process && process.env.BUILD_STRATEGY) {
369
+ buildStrategy2 = process.env.BUILD_STRATEGY;
370
+ }
371
+ return buildStrategy2;
372
+ }
373
+ var buildStrategy = getBuildStrategy();
361
374
  var StoreStrategy = /* @__PURE__ */ ((StoreStrategy2) => {
362
375
  StoreStrategy2["Api"] = "api";
363
376
  StoreStrategy2["Data"] = "data";
@@ -381,9 +394,9 @@ var KNOWN_COLLECTIONS = [
381
394
  "locale",
382
395
  "market",
383
396
  "menu",
384
- "template",
385
397
  "redirect",
386
398
  "route",
399
+ "template",
387
400
  ...STATIC_COLLECTIONS
388
401
  ];
389
402
  var COLLECTIONS = [...ENV_COLLECTIONS, ...KNOWN_COLLECTIONS];
@@ -997,11 +1010,11 @@ function decorateNav__(item, routes) {
997
1010
  if (route) {
998
1011
  decorated.nav = {
999
1012
  type: "page",
1000
- id: route.id,
1013
+ id: route.page,
1001
1014
  href: route.id,
1002
1015
  title: route.title,
1003
- page: nav.page.value,
1004
- schema: nav.page.relationTo
1016
+ page: route.page,
1017
+ schema: route.schema
1005
1018
  };
1006
1019
  }
1007
1020
  return decorated;
@@ -1062,7 +1075,9 @@ async function getMockStore_() {
1062
1075
  }
1063
1076
  async function getMockStore() {
1064
1077
  return fromCache(async () => {
1065
- console.log("getMockStore");
1078
+ if (!isDevelopment) {
1079
+ console.warn("getMockStore");
1080
+ }
1066
1081
  const store = await getMockStore_();
1067
1082
  return store;
1068
1083
  }, isDevelopment ? void 0 : "STORE_MOCK_");
@@ -1203,9 +1218,9 @@ async function getRemoteStore_() {
1203
1218
  return store;
1204
1219
  }, isDevelopment2 ? void 0 : "STORE_RUNTIME_");
1205
1220
  }
1206
- async function getRemoteStoreProductionBuild_() {
1221
+ async function getRemoteStoreStaticBuild_() {
1207
1222
  return fromCache(async () => {
1208
- console.log("getRemoteStoreProductionBuild_");
1223
+ console.log("getRemoteStoreStaticBuild_");
1209
1224
  const store = {};
1210
1225
  const url = "/store?pagination=true&richText=false";
1211
1226
  const json = await remoteApiGet(url);
@@ -1221,9 +1236,24 @@ async function getRemoteStoreProductionBuild_() {
1221
1236
  return store;
1222
1237
  }, "STORE_BUILD_");
1223
1238
  }
1239
+ async function getRemoteStoreRuntimeBuild_() {
1240
+ return fromCache(async () => {
1241
+ console.log("getRemoteStoreRuntimeBuild_");
1242
+ const data = {};
1243
+ COLLECTIONS.forEach((key) => {
1244
+ data[key] = [];
1245
+ });
1246
+ const store = getMockStoreFromData_(data);
1247
+ return store;
1248
+ }, "STORE_RUNTIME_BUILD_");
1249
+ }
1224
1250
  async function getRemoteStore() {
1225
1251
  if (process.env.NEXT_PHASE === "phase-production-build") {
1226
- return await getRemoteStoreProductionBuild_();
1252
+ if (buildStrategy === "runtime" /* Runtime */) {
1253
+ return await getRemoteStoreRuntimeBuild_();
1254
+ } else {
1255
+ return await getRemoteStoreStaticBuild_();
1256
+ }
1227
1257
  } else {
1228
1258
  return await getRemoteStore_();
1229
1259
  }
@@ -1606,6 +1636,7 @@ async function storeApiDelete(url, options = {}) {
1606
1636
  return await storeApiFetch(url, { ...options, method: "DELETE" });
1607
1637
  }
1608
1638
  export {
1639
+ BuildStrategy,
1609
1640
  COLLECTIONS,
1610
1641
  KNOWN_COLLECTIONS,
1611
1642
  MOCK_COLLECTIONS,
@@ -1616,6 +1647,7 @@ export {
1616
1647
  StaticService,
1617
1648
  StoreStrategy,
1618
1649
  apiHandler,
1650
+ buildStrategy,
1619
1651
  collectionDelete,
1620
1652
  collectionGet,
1621
1653
  collectionPatch,
@@ -1630,6 +1662,7 @@ export {
1630
1662
  getDefaultApiRequestOptions,
1631
1663
  getLocalApiUrl,
1632
1664
  getMockStore,
1665
+ getMockStoreFromData_,
1633
1666
  getRemoteStore,
1634
1667
  getStore,
1635
1668
  isApiRequest,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-store",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Mixer Store module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -141,11 +141,11 @@ function decorateNav__<T>(item: IUndecoratedNav<T>, routes: IRoute[]): IDecorate
141
141
  if (route) {
142
142
  decorated.nav = {
143
143
  type: 'page',
144
- id: route.id,
144
+ id: route.page,
145
145
  href: route.id,
146
146
  title: route.title,
147
- page: (nav.page.value as unknown as IEquatable),
148
- schema: nav.page.relationTo,
147
+ page: route.page,
148
+ schema: route.schema,
149
149
  };
150
150
  }
151
151
  return decorated as IDecoratedNav<T>;
@@ -9,7 +9,7 @@ import { MockService } from './mock.service';
9
9
 
10
10
  const PAGES: string[] = process.env.PAGES ? process.env.PAGES.split(',') : [];
11
11
 
12
- function getMockStoreFromData_<T extends IStore>(data?: IMemoryStore): T {
12
+ export function getMockStoreFromData_<T extends IStore>(data?: IMemoryStore): T {
13
13
  const store: IStore = {};
14
14
  if (data) {
15
15
  for (const key in data) {
@@ -67,7 +67,9 @@ async function getMockStore_<T extends IStore = IStore>(): Promise<T> {
67
67
 
68
68
  export async function getMockStore<T extends IStore = IStore>(): Promise<T> {
69
69
  return fromCache<T>(async () => {
70
- console.log('getMockStore');
70
+ if (!isDevelopment) {
71
+ console.warn('getMockStore');
72
+ }
71
73
  const store = await getMockStore_<T>();
72
74
  return store;
73
75
  }, isDevelopment ? undefined : 'STORE_MOCK_');
@@ -1,8 +1,8 @@
1
1
  import { IEntity, IMemoryStore, IQuerable, IStore, isDevelopment } from '@websolutespa/bom-core';
2
2
  import { fromCache } from '../cache/cache.service';
3
3
  import { MockService } from '../mock/mock.service';
4
- import { getMockStore } from '../mock/mock.store';
5
- import { COLLECTIONS, MOCK_COLLECTIONS } from '../store/store';
4
+ import { getMockStore, getMockStoreFromData_ } from '../mock/mock.store';
5
+ import { BuildStrategy, COLLECTIONS, MOCK_COLLECTIONS, buildStrategy } from '../store/store';
6
6
  import { remoteApiGet } from './remote.api';
7
7
  import { RemoteService } from './remote.service';
8
8
 
@@ -30,9 +30,9 @@ async function getRemoteStore_<T extends IStore>(): Promise<T> {
30
30
  }, isDevelopment ? undefined : 'STORE_RUNTIME_');
31
31
  }
32
32
 
33
- async function getRemoteStoreProductionBuild_<T extends IStore>(): Promise<T> {
33
+ async function getRemoteStoreStaticBuild_<T extends IStore>(): Promise<T> {
34
34
  return fromCache<T>(async () => {
35
- console.log('getRemoteStoreProductionBuild_');
35
+ console.log('getRemoteStoreStaticBuild_');
36
36
  const store: IStore = {};
37
37
  const url = '/store?pagination=true&richText=false';
38
38
  const json = await remoteApiGet<IMemoryStore>(url);
@@ -49,9 +49,25 @@ async function getRemoteStoreProductionBuild_<T extends IStore>(): Promise<T> {
49
49
  }, 'STORE_BUILD_');
50
50
  }
51
51
 
52
+ async function getRemoteStoreRuntimeBuild_<T extends IStore>(): Promise<T> {
53
+ return fromCache<T>(async () => {
54
+ console.log('getRemoteStoreRuntimeBuild_');
55
+ const data: IMemoryStore = {};
56
+ COLLECTIONS.forEach(key => {
57
+ data[key] = [];
58
+ });
59
+ const store = getMockStoreFromData_(data);
60
+ return store as T;
61
+ }, 'STORE_RUNTIME_BUILD_');
62
+ }
63
+
52
64
  export async function getRemoteStore<T extends IStore>(): Promise<T> {
53
65
  if (process.env.NEXT_PHASE === 'phase-production-build') {
54
- return await getRemoteStoreProductionBuild_();
66
+ if (buildStrategy === BuildStrategy.Runtime) {
67
+ return await getRemoteStoreRuntimeBuild_();
68
+ } else {
69
+ return await getRemoteStoreStaticBuild_();
70
+ }
55
71
  } else {
56
72
  return await getRemoteStore_();
57
73
  }
@@ -1,5 +1,20 @@
1
1
  import { staticCollections } from '../static/static';
2
2
 
3
+ export enum BuildStrategy {
4
+ Static = 'static',
5
+ Runtime = 'runtime',
6
+ }
7
+
8
+ function getBuildStrategy(): BuildStrategy {
9
+ let buildStrategy = BuildStrategy.Static;
10
+ if (process && process.env.BUILD_STRATEGY) {
11
+ buildStrategy = process.env.BUILD_STRATEGY as BuildStrategy;
12
+ }
13
+ return buildStrategy;
14
+ }
15
+
16
+ export const buildStrategy: BuildStrategy = getBuildStrategy();
17
+
3
18
  export enum StoreStrategy {
4
19
  Api = 'api',
5
20
  Data = 'data',
@@ -25,9 +40,9 @@ export const KNOWN_COLLECTIONS: string[] = [
25
40
  'locale',
26
41
  'market',
27
42
  'menu',
28
- 'template',
29
43
  'redirect',
30
44
  'route',
45
+ 'template',
31
46
  ...STATIC_COLLECTIONS,
32
47
  ];
33
48
  export const COLLECTIONS = [...ENV_COLLECTIONS, ...KNOWN_COLLECTIONS];