@websolutespa/bom-mixer-store 1.3.0 → 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 +6 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +37 -3
- package/dist/index.mjs +34 -3
- package/package.json +1 -1
- package/src/mock/mock.store.ts +1 -1
- package/src/remote/remote.store.ts +21 -5
- package/src/store/store.ts +15 -0
package/CHANGELOG.md
CHANGED
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";
|
|
@@ -1290,9 +1306,9 @@ async function getRemoteStore_() {
|
|
|
1290
1306
|
return store;
|
|
1291
1307
|
}, import_bom_core9.isDevelopment ? void 0 : "STORE_RUNTIME_");
|
|
1292
1308
|
}
|
|
1293
|
-
async function
|
|
1309
|
+
async function getRemoteStoreStaticBuild_() {
|
|
1294
1310
|
return fromCache(async () => {
|
|
1295
|
-
console.log("
|
|
1311
|
+
console.log("getRemoteStoreStaticBuild_");
|
|
1296
1312
|
const store = {};
|
|
1297
1313
|
const url = "/store?pagination=true&richText=false";
|
|
1298
1314
|
const json = await remoteApiGet(url);
|
|
@@ -1308,9 +1324,24 @@ async function getRemoteStoreProductionBuild_() {
|
|
|
1308
1324
|
return store;
|
|
1309
1325
|
}, "STORE_BUILD_");
|
|
1310
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
|
+
}
|
|
1311
1338
|
async function getRemoteStore() {
|
|
1312
1339
|
if (process.env.NEXT_PHASE === "phase-production-build") {
|
|
1313
|
-
|
|
1340
|
+
if (buildStrategy === "runtime" /* Runtime */) {
|
|
1341
|
+
return await getRemoteStoreRuntimeBuild_();
|
|
1342
|
+
} else {
|
|
1343
|
+
return await getRemoteStoreStaticBuild_();
|
|
1344
|
+
}
|
|
1314
1345
|
} else {
|
|
1315
1346
|
return await getRemoteStore_();
|
|
1316
1347
|
}
|
|
@@ -1694,6 +1725,7 @@ async function storeApiDelete(url, options = {}) {
|
|
|
1694
1725
|
}
|
|
1695
1726
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1696
1727
|
0 && (module.exports = {
|
|
1728
|
+
BuildStrategy,
|
|
1697
1729
|
COLLECTIONS,
|
|
1698
1730
|
KNOWN_COLLECTIONS,
|
|
1699
1731
|
MOCK_COLLECTIONS,
|
|
@@ -1704,6 +1736,7 @@ async function storeApiDelete(url, options = {}) {
|
|
|
1704
1736
|
StaticService,
|
|
1705
1737
|
StoreStrategy,
|
|
1706
1738
|
apiHandler,
|
|
1739
|
+
buildStrategy,
|
|
1707
1740
|
collectionDelete,
|
|
1708
1741
|
collectionGet,
|
|
1709
1742
|
collectionPatch,
|
|
@@ -1718,6 +1751,7 @@ async function storeApiDelete(url, options = {}) {
|
|
|
1718
1751
|
getDefaultApiRequestOptions,
|
|
1719
1752
|
getLocalApiUrl,
|
|
1720
1753
|
getMockStore,
|
|
1754
|
+
getMockStoreFromData_,
|
|
1721
1755
|
getRemoteStore,
|
|
1722
1756
|
getStore,
|
|
1723
1757
|
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";
|
|
@@ -1203,9 +1216,9 @@ async function getRemoteStore_() {
|
|
|
1203
1216
|
return store;
|
|
1204
1217
|
}, isDevelopment2 ? void 0 : "STORE_RUNTIME_");
|
|
1205
1218
|
}
|
|
1206
|
-
async function
|
|
1219
|
+
async function getRemoteStoreStaticBuild_() {
|
|
1207
1220
|
return fromCache(async () => {
|
|
1208
|
-
console.log("
|
|
1221
|
+
console.log("getRemoteStoreStaticBuild_");
|
|
1209
1222
|
const store = {};
|
|
1210
1223
|
const url = "/store?pagination=true&richText=false";
|
|
1211
1224
|
const json = await remoteApiGet(url);
|
|
@@ -1221,9 +1234,24 @@ async function getRemoteStoreProductionBuild_() {
|
|
|
1221
1234
|
return store;
|
|
1222
1235
|
}, "STORE_BUILD_");
|
|
1223
1236
|
}
|
|
1237
|
+
async function getRemoteStoreRuntimeBuild_() {
|
|
1238
|
+
return fromCache(async () => {
|
|
1239
|
+
console.log("getRemoteStoreRuntimeBuild_");
|
|
1240
|
+
const data = {};
|
|
1241
|
+
COLLECTIONS.forEach((key) => {
|
|
1242
|
+
data[key] = [];
|
|
1243
|
+
});
|
|
1244
|
+
const store = getMockStoreFromData_(data);
|
|
1245
|
+
return store;
|
|
1246
|
+
}, "STORE_RUNTIME_BUILD_");
|
|
1247
|
+
}
|
|
1224
1248
|
async function getRemoteStore() {
|
|
1225
1249
|
if (process.env.NEXT_PHASE === "phase-production-build") {
|
|
1226
|
-
|
|
1250
|
+
if (buildStrategy === "runtime" /* Runtime */) {
|
|
1251
|
+
return await getRemoteStoreRuntimeBuild_();
|
|
1252
|
+
} else {
|
|
1253
|
+
return await getRemoteStoreStaticBuild_();
|
|
1254
|
+
}
|
|
1227
1255
|
} else {
|
|
1228
1256
|
return await getRemoteStore_();
|
|
1229
1257
|
}
|
|
@@ -1606,6 +1634,7 @@ async function storeApiDelete(url, options = {}) {
|
|
|
1606
1634
|
return await storeApiFetch(url, { ...options, method: "DELETE" });
|
|
1607
1635
|
}
|
|
1608
1636
|
export {
|
|
1637
|
+
BuildStrategy,
|
|
1609
1638
|
COLLECTIONS,
|
|
1610
1639
|
KNOWN_COLLECTIONS,
|
|
1611
1640
|
MOCK_COLLECTIONS,
|
|
@@ -1616,6 +1645,7 @@ export {
|
|
|
1616
1645
|
StaticService,
|
|
1617
1646
|
StoreStrategy,
|
|
1618
1647
|
apiHandler,
|
|
1648
|
+
buildStrategy,
|
|
1619
1649
|
collectionDelete,
|
|
1620
1650
|
collectionGet,
|
|
1621
1651
|
collectionPatch,
|
|
@@ -1630,6 +1660,7 @@ export {
|
|
|
1630
1660
|
getDefaultApiRequestOptions,
|
|
1631
1661
|
getLocalApiUrl,
|
|
1632
1662
|
getMockStore,
|
|
1663
|
+
getMockStoreFromData_,
|
|
1633
1664
|
getRemoteStore,
|
|
1634
1665
|
getStore,
|
|
1635
1666
|
isApiRequest,
|
package/package.json
CHANGED
package/src/mock/mock.store.ts
CHANGED
|
@@ -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) {
|
|
@@ -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
|
|
33
|
+
async function getRemoteStoreStaticBuild_<T extends IStore>(): Promise<T> {
|
|
34
34
|
return fromCache<T>(async () => {
|
|
35
|
-
console.log('
|
|
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
|
-
|
|
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
|
}
|
package/src/store/store.ts
CHANGED
|
@@ -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',
|