@websolutespa/bom-mixer-store 3.0.2 → 3.0.3

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.
@@ -1,7 +1,6 @@
1
- import { COLLECTIONS, DEFAULT_DEPTH, KNOWN_COLLECTIONS, MOCK_COLLECTIONS, NextPhase, StoreStrategy, buildStrategy, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, fromCache, getLocalApiRequestOptions, getRemoteApiRequestOptions, nextPhase, remoteApiDelete, remoteApiGet, remoteApiPatch, remoteApiPost, staticCollections, storeCacheDuration, storeStrategy } from "../src-bMn1KJCJ.js";
1
+ import { COLLECTIONS, DEFAULT_DEPTH, KNOWN_COLLECTIONS, MOCK_COLLECTIONS, NextPhase, StoreStrategy, buildStrategy, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, fromCache, getRemoteApiRequestOptions, nextPhase, remoteApiDelete, remoteApiGet, remoteApiPatch, remoteApiPost, staticCollections, storeCacheDuration, storeStrategy } from "../src-D-0XSCD9.js";
2
2
  import { createRequire } from "node:module";
3
- import { JsonService, asCategoryId, asEquatable, defaultLocale, defaultMarket, findRouteOfCategory, getHost, getOrigin, getRootCategory, httpFetch, httpGet, isBrowser, isDevelopment, isProduction, localize, merge, qsDeserialize, qsSerialize } from "@websolutespa/bom-core";
4
- import { createPayloadRequest, getPayload } from "payload";
3
+ import { JsonService, asCategoryId, asEquatable, defaultLocale, defaultMarket, findRouteOfCategory, getHost, getOrigin, getRootCategory, httpGet, isDevelopment, isProduction, localize, qsDeserialize, qsSerialize } from "@websolutespa/bom-core";
5
4
  import { getIronSession } from "iron-session";
6
5
  import * as fs from "fs";
7
6
 
@@ -39,336 +38,6 @@ function errorHandler(error, response) {
39
38
  response.status(500).json({ message: error.message });
40
39
  }
41
40
 
42
- //#endregion
43
- //#region src/local_/local.api.ts
44
- /**
45
-
46
- * This methods handle api requests / responses to local api (bowl or over)
47
-
48
- */
49
- const API_URL = process.env.STORE_URL;
50
- const API_BASE = process.env.STORE_API || "/api";
51
- function getLocalApiUrl(pathname) {
52
- const url = `${API_URL}${API_BASE}${pathname}`;
53
- return url;
54
- }
55
- async function localApiFetch(pathname, options = {}) {
56
- if (isBrowser) throw "Unauthorized: local api cannot be fetched client side";
57
- const url = getLocalApiUrl(pathname);
58
- const apiOptions = merge({ ...getLocalApiRequestOptions() }, options);
59
- const apiResponse = await httpFetch(url, apiOptions);
60
- return apiResponse;
61
- }
62
- async function localApiGet(url, options = {}) {
63
- return await localApiFetch(url, {
64
- ...options,
65
- method: "GET"
66
- });
67
- }
68
- async function localApiPost(url, payload, options = {}) {
69
- return await localApiFetch(url, {
70
- ...options,
71
- method: "POST",
72
- body: JSON.stringify(payload)
73
- });
74
- }
75
- async function localApiPatch(url, payload, options = {}) {
76
- return await localApiFetch(url, {
77
- ...options,
78
- method: "PATCH",
79
- body: JSON.stringify(payload)
80
- });
81
- }
82
- async function localApiDelete(url, options = {}) {
83
- return await localApiFetch(url, {
84
- ...options,
85
- method: "DELETE"
86
- });
87
- }
88
-
89
- //#endregion
90
- //#region src/local_/local.service.ts
91
- const getSingletonProvider = () => {
92
- let provider = globalThis.LocalProvider;
93
- if (!provider) {
94
- provider = {
95
- config: void 0,
96
- sanitizedConfig: void 0,
97
- payload: void 0
98
- };
99
- globalThis.LocalProvider = provider;
100
- }
101
- return provider;
102
- };
103
- async function setPayloadConfig(config) {
104
- const provider = getSingletonProvider();
105
- provider.config = config;
106
- const sanitizedConfig = await config;
107
- provider.sanitizedConfig = sanitizedConfig;
108
- return sanitizedConfig;
109
- }
110
- async function getPayloadSingleton() {
111
- const provider = getSingletonProvider();
112
- let payload = provider.payload;
113
- if (!payload) {
114
- const sanitizedConfig = provider.sanitizedConfig;
115
- if (!sanitizedConfig) console.warn("LocalService.setPayloadConfig must be initialized", provider);
116
- payload = await getPayload({ config: sanitizedConfig });
117
- provider.payload = payload;
118
- }
119
- return payload;
120
- }
121
- function getAuthHeaders(token) {
122
- if (token) return new Headers({ Authorization: `JWT ${token}` });
123
- else return new Headers({ Authorization: `users API-Key ${process.env.STORE_API_KEY}` });
124
- }
125
- async function getPayloadUser(payload, token) {
126
- const { user } = await payload.auth({ headers: getAuthHeaders(token) });
127
- return user;
128
- }
129
- /**
130
-
131
- * This service handle call to local api
132
-
133
- */
134
- var LocalService = class {
135
- key;
136
- store;
137
- constructor(key, store) {
138
- if (!key) throw new Error("LocalService: key is required");
139
- if (!store) throw new Error("LocalService: store is required");
140
- this.key = key;
141
- this.store = store;
142
- }
143
- async findGlobal(params = {}, token) {
144
- if (["locale", "route"].includes(this.key)) {
145
- params.richText = String(params.richText) === "true" ? true : false;
146
- const query$1 = qsSerialize(params);
147
- const search$1 = query$1 ? `?${query$1}` : "";
148
- const url$1 = `/globals/${this.key}${search$1}`;
149
- try {
150
- const item = await remoteApiGet(url$1, getRemoteApiRequestOptions(token));
151
- if (item) return await this.decorateOne_(item, params);
152
- } catch (error) {
153
- console.log("LocalService", this.key, "findGlobal.error", error);
154
- }
155
- return;
156
- }
157
- const payload = await getPayloadSingleton();
158
- const user = await getPayloadUser(payload, token);
159
- const query = qsSerialize(params);
160
- const search = query ? `?${query}` : "";
161
- const url = `http://mixer/globals/${this.key}${search}`;
162
- const req = await createPayloadRequest({
163
- config: payload.config,
164
- request: new Request(url)
165
- });
166
- String(params.richText) === "true" ? true : false;
167
- try {
168
- const item = await payload.findGlobal({
169
- slug: this.key,
170
- depth: params.depth,
171
- locale: params.locale,
172
- fallbackLocale: false,
173
- req,
174
- overrideAccess: false,
175
- user
176
- });
177
- if (item) return await this.decorateOne_(item, params);
178
- } catch (error) {
179
- console.log("LocalService", this.key, "findOne.error", error);
180
- }
181
- }
182
- async findOne(id, params = {}, token) {
183
- if (["locale", "route"].includes(this.key)) {
184
- params.richText = String(params.richText) === "true" ? true : false;
185
- const query$1 = qsSerialize(params);
186
- const search$1 = query$1 ? `?${query$1}` : "";
187
- const url$1 = `/${this.key}/${encodeURIComponent(id)}${search$1}`;
188
- try {
189
- console.log("remoteApiGet", url$1);
190
- const item = await remoteApiGet(url$1, getRemoteApiRequestOptions(token));
191
- if (item) return await this.decorateOne_(item, params);
192
- } catch (error) {
193
- console.log("LocalService", this.key, "findOne.error", error);
194
- }
195
- return;
196
- }
197
- const payload = await getPayloadSingleton();
198
- const user = await getPayloadUser(payload, token);
199
- const query = qsSerialize(params);
200
- const search = query ? `?${query}` : "";
201
- const url = `http://mixer/${this.key}/${encodeURIComponent(id)}${search}`;
202
- const req = await createPayloadRequest({
203
- config: payload.config,
204
- request: new Request(url)
205
- });
206
- String(params.richText) === "true" ? true : false;
207
- try {
208
- const item = await payload.findByID({
209
- collection: this.key,
210
- id,
211
- depth: params.depth,
212
- locale: params.locale,
213
- fallbackLocale: false,
214
- req,
215
- overrideAccess: false,
216
- user,
217
- disableErrors: true
218
- });
219
- if (item) return await this.decorateOne_(item, params);
220
- } catch (error) {
221
- console.log("LocalService", this.key, "findOne.error", error);
222
- }
223
- }
224
- async findMany(params = {}, token) {
225
- if (["locale", "route"].includes(this.key)) {
226
- params.richText = String(params.richText) === "true" ? true : false;
227
- params.pagination = false;
228
- const query$1 = qsSerialize(params);
229
- const search$1 = query$1 ? `?${query$1}` : "";
230
- const url$1 = `/${this.key}${search$1}`;
231
- const response$1 = await remoteApiGet(url$1, getRemoteApiRequestOptions(token));
232
- const items$1 = Array.isArray(response$1) ? response$1 : response$1.docs;
233
- return await this.decorateMany_(items$1, params);
234
- }
235
- params.richText = String(params.richText) === "true" ? true : false;
236
- params.pagination = false;
237
- const payload = await getPayloadSingleton();
238
- const user = await getPayloadUser(payload, token);
239
- const query = qsSerialize(params);
240
- const search = query ? `?${query}` : "";
241
- const url = `http://mixer/${this.key}${search}`;
242
- const req = await createPayloadRequest({
243
- config: payload.config,
244
- request: new Request(url)
245
- });
246
- const response = await payload.find({
247
- collection: this.key,
248
- depth: params.depth,
249
- locale: params.locale,
250
- fallbackLocale: false,
251
- req,
252
- overrideAccess: false,
253
- user,
254
- disableErrors: true
255
- });
256
- const items = Array.isArray(response) ? response : response.docs;
257
- return await this.decorateMany_(items, params);
258
- }
259
- async findPaged(params = {}, token) {
260
- if (["locale", "route"].includes(this.key)) {
261
- params.richText = String(params.richText) === "true" ? true : false;
262
- params.pagination = true;
263
- const query$1 = qsSerialize(params);
264
- const search$1 = query$1 ? `?${query$1}` : "";
265
- const url$1 = `/${this.key}${search$1}`;
266
- const response$1 = await remoteApiGet(url$1, getRemoteApiRequestOptions(token));
267
- let items$1 = response$1.docs;
268
- items$1 = await this.decorateMany_(items$1, params);
269
- return {
270
- ...response$1,
271
- docs: items$1
272
- };
273
- }
274
- params.richText = String(params.richText) === "true" ? true : false;
275
- params.pagination = true;
276
- const payload = await getPayloadSingleton();
277
- const user = await getPayloadUser(payload, token);
278
- const query = qsSerialize(params);
279
- const search = query ? `?${query}` : "";
280
- const url = `http://mixer/${this.key}${search}`;
281
- const req = await createPayloadRequest({
282
- config: payload.config,
283
- request: new Request(url)
284
- });
285
- const response = await payload.find({
286
- collection: this.key,
287
- depth: params.depth,
288
- locale: params.locale,
289
- fallbackLocale: false,
290
- req,
291
- overrideAccess: false,
292
- user,
293
- disableErrors: true
294
- });
295
- let items = response.docs;
296
- items = await this.decorateMany_(items, params);
297
- return {
298
- ...response,
299
- docs: items
300
- };
301
- }
302
- async create(payload, params = {}, token) {
303
- params.richText = String(params.richText) === "true" ? true : false;
304
- const query = qsSerialize(params);
305
- const search = query ? `?${query}` : "";
306
- const url = `/${this.key}${search}`;
307
- const result = await localApiPost(url, payload, getRemoteApiRequestOptions(token));
308
- const item = result.doc ? result.doc : result;
309
- return await this.decorateOne_(item, {});
310
- }
311
- async updateOne(id, payload, params = {}, token) {
312
- const query = qsSerialize(params);
313
- const search = query ? `?${query}` : "";
314
- const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
315
- const result = await localApiPatch(url, payload, getRemoteApiRequestOptions(token));
316
- const item = result.doc ? result.doc : result;
317
- return await this.decorateOne_(item, {});
318
- }
319
- async updateMany(payload, params = {}, token) {
320
- params.richText = String(params.richText) === "true" ? true : false;
321
- params.pagination = false;
322
- const query = qsSerialize(params);
323
- const search = query ? `?${query}` : "";
324
- const url = `/${this.key}${search}`;
325
- const response = await localApiPatch(url, payload, getRemoteApiRequestOptions(token));
326
- const items = Array.isArray(response) ? response : response.docs;
327
- return await this.decorateMany_(items, params);
328
- }
329
- async deleteOne(id, params = {}, token) {
330
- const query = qsSerialize(params);
331
- const search = query ? `?${query}` : "";
332
- const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
333
- const item = await localApiDelete(url, getRemoteApiRequestOptions(token));
334
- return await this.decorateOne_(item, {});
335
- }
336
- async deleteMany(params = {}, token) {
337
- params.richText = String(params.richText) === "true" ? true : false;
338
- params.pagination = false;
339
- const query = qsSerialize(params);
340
- const search = query ? `?${query}` : "";
341
- const url = `/${this.key}${search}`;
342
- const response = await localApiDelete(url, getRemoteApiRequestOptions(token));
343
- const items = Array.isArray(response) ? response : response.docs;
344
- return await this.decorateMany_(items, params);
345
- }
346
- async update(payload, params = {}, token) {
347
- const url = `/${this.key}`;
348
- const result = await localApiPatch(url, payload, getRemoteApiRequestOptions(token));
349
- const item = result.doc ? result.doc : result;
350
- return await this.decorateOne_(item, {});
351
- }
352
- async delete(id, token) {
353
- const params = { where: { id: { equals: id } } };
354
- const query = qsSerialize(params);
355
- const search = query ? `?${query}` : "";
356
- const url = `/${this.key}${search}`;
357
- const item = await localApiDelete(url, getRemoteApiRequestOptions(token));
358
- return await this.decorateOne_(item, {});
359
- }
360
- async decorateOne_(item, params = {}) {
361
- let decoratedItem = item;
362
- decoratedItem = await decorateSchema_(this.store, decoratedItem, this.key);
363
- return decoratedItem;
364
- }
365
- async decorateMany_(items, params = {}) {
366
- let decoratedItems = items;
367
- decoratedItems = await decorateSchemas_(this.store, decoratedItems, this.key);
368
- return decoratedItems;
369
- }
370
- };
371
-
372
41
  //#endregion
373
42
  //#region src/mock/mock.service.ts
374
43
  var MockService = class extends JsonService {
@@ -493,111 +162,6 @@ async function getSessionToken(request, response) {
493
162
  }
494
163
  }
495
164
 
496
- //#endregion
497
- //#region src/cached/cached.service.ts
498
- var CachedService = class extends JsonService {
499
- service_;
500
- cache_ = /* @__PURE__ */ new Map();
501
- duration_ = storeCacheDuration;
502
- constructor(service, options = {}) {
503
- super([]);
504
- if (!service) throw new Error("CachedService: service is required");
505
- this.service_ = service;
506
- this.duration_ = typeof options.duration !== "undefined" ? options.duration : this.duration_;
507
- }
508
- async fromCache_(callback, key) {
509
- if (key && this.hasKey_(key)) return this.getKey_(key);
510
- else {
511
- const t = await callback();
512
- if (key && t) this.setKey_(key, t);
513
- return t;
514
- }
515
- }
516
- isExpired_(item) {
517
- return this.duration_ === false ? true : item.timestamp < (/* @__PURE__ */ new Date()).getTime() - this.duration_;
518
- }
519
- hasKey_(key) {
520
- const item = this.cache_.get(key);
521
- return item ? !this.isExpired_(item) : false;
522
- }
523
- getKey_(key) {
524
- return this.cache_.get(key).data;
525
- }
526
- setKey_(key, data) {
527
- this.cache_.set(key, {
528
- timestamp: (/* @__PURE__ */ new Date()).getTime(),
529
- data
530
- });
531
- }
532
- async findGlobal(params = {}) {
533
- const serializedParams = qsSerialize(params);
534
- const key = `findGlobal?${serializedParams}`;
535
- return await this.fromCache_(async () => {
536
- return await this.service_.findGlobal(params);
537
- }, key);
538
- }
539
- async findOne(id, params = {}) {
540
- const serializedParams = qsSerialize(params);
541
- const key = `findOne[${id}]?${serializedParams}`;
542
- return await this.fromCache_(async () => {
543
- return await this.service_.findOne(id, params);
544
- }, key);
545
- }
546
- async findMany(params = {}) {
547
- if (storeStrategy === StoreStrategy.DecoratedApi) {
548
- const { market, locale,...otherParams } = params;
549
- const serializedParams = qsSerialize({
550
- market,
551
- locale
552
- });
553
- const key = `findMany?${serializedParams}`;
554
- let items = await this.fromCache_(async () => {
555
- return await this.service_.findMany({
556
- market,
557
- locale
558
- });
559
- }, key);
560
- if (otherParams.where) items = this.whereItems_(items, otherParams.where);
561
- if (otherParams.sort) items = this.sortCollection_(items, otherParams.sort);
562
- return items;
563
- } else {
564
- const serializedParams = qsSerialize(params);
565
- const key = `findMany?${serializedParams}`;
566
- return await this.fromCache_(async () => {
567
- return await this.service_.findMany(params);
568
- }, key);
569
- }
570
- }
571
- async findPaged(params = {}) {
572
- const serializedParams = qsSerialize(params);
573
- const key = `findPaged?${serializedParams}`;
574
- return await this.fromCache_(async () => {
575
- return await this.service_.findPaged(params);
576
- }, key);
577
- }
578
- async create(payload) {
579
- return await this.service_.create(payload);
580
- }
581
- async updateOne(id, payload, params = {}) {
582
- return await this.service_.updateOne(id, payload, params);
583
- }
584
- async updateMany(payload, params = {}) {
585
- return await this.service_.updateMany(payload, params);
586
- }
587
- async deleteOne(id, params = {}) {
588
- return await this.service_.deleteOne(id, params);
589
- }
590
- async deleteMany(params = {}) {
591
- return await this.service_.deleteMany(params);
592
- }
593
- async update(payload) {
594
- return await this.service_.update(payload);
595
- }
596
- async delete(id) {
597
- return await this.service_.delete(id);
598
- }
599
- };
600
-
601
165
  //#endregion
602
166
  //#region src/fs/fs.service.ts
603
167
  async function fsRead(pathname, option) {
@@ -712,11 +276,11 @@ async function decorateStaticRelations_(store, fields, items, params = {}) {
712
276
 
713
277
  //#endregion
714
278
  //#region src/mock/mock.store.ts
715
- const PAGES$2 = process.env.PAGES ? process.env.PAGES.split(",") : [];
279
+ const PAGES$1 = process.env.PAGES ? process.env.PAGES.split(",") : [];
716
280
  function getMockStoreFromData_(data) {
717
281
  const store = {};
718
282
  if (data) {
719
- for (const key in data) if (!PAGES$2.includes(key)) {
283
+ for (const key in data) if (!PAGES$1.includes(key)) {
720
284
  const service = new MockService(data[key], store);
721
285
  store[key] = service;
722
286
  }
@@ -727,7 +291,7 @@ function getMockStoreFromData_(data) {
727
291
  if (category && route) {
728
292
  const menu = data.menu;
729
293
  if (menu) store.menu = new MockMenuService(menu, store);
730
- for (const key in data) if (PAGES$2.includes(key)) {
294
+ for (const key in data) if (PAGES$1.includes(key)) {
731
295
  const service = new MockPageService(data[key], store);
732
296
  store[key] = service;
733
297
  }
@@ -763,99 +327,109 @@ async function getMockStore() {
763
327
  }
764
328
 
765
329
  //#endregion
766
- //#region src/local_/local-menu.service.ts
767
- var LocalMenuService = class extends LocalService {
768
- async decorateOne_(item, params = {}) {
769
- const store = this.store;
770
- let decoratedItem = item;
771
- decoratedItem = await decorateSchema_(store, decoratedItem, this.key);
772
- decoratedItem = await decorateLocalizable_(item, params);
773
- if (params.market && params.locale) decoratedItem = await decorateMenu_(store, decoratedItem, {
774
- market: params.market,
775
- locale: params.locale
776
- });
777
- return decoratedItem;
330
+ //#region src/cached/cached.service.ts
331
+ var CachedService = class extends JsonService {
332
+ service_;
333
+ cache_ = /* @__PURE__ */ new Map();
334
+ duration_ = storeCacheDuration;
335
+ constructor(service, options = {}) {
336
+ super([]);
337
+ if (!service) throw new Error("CachedService: service is required");
338
+ this.service_ = service;
339
+ this.duration_ = typeof options.duration !== "undefined" ? options.duration : this.duration_;
778
340
  }
779
- async decorateMany_(items, params = {}) {
780
- const store = this.store;
781
- let decoratedItems = items;
782
- decoratedItems = await decorateSchemas_(store, decoratedItems, this.key);
783
- decoratedItems = await decorateLocalizables_(items, params);
784
- if (params.market && params.locale) decoratedItems = await decorateMenus_(store, decoratedItems, {
785
- market: params.market,
786
- locale: params.locale
787
- });
788
- return decoratedItems;
341
+ async fromCache_(callback, key) {
342
+ if (key && this.hasKey_(key)) return this.getKey_(key);
343
+ else {
344
+ const t = await callback();
345
+ if (key && t) this.setKey_(key, t);
346
+ return t;
347
+ }
789
348
  }
790
- };
791
-
792
- //#endregion
793
- //#region src/local_/local-page.service.ts
794
- var LocalPageService = class extends LocalService {
795
- async decorateOne_(item, params = {}) {
796
- const store = this.store;
797
- let decoratedItem = item;
798
- decoratedItem = await decorateSchema_(store, decoratedItem, this.key);
799
- decoratedItem = await decorateCategory_(store, decoratedItem, params);
800
- decoratedItem = await decorateHref_(store, decoratedItem, params);
801
- decoratedItem = await decorateNav_(store, decoratedItem, params);
802
- decoratedItem = await decorateRelation_(store, decoratedItem, {
803
- market: params.market,
804
- locale: params.locale,
805
- depth: params.depth
806
- });
807
- return decoratedItem;
349
+ isExpired_(item) {
350
+ return this.duration_ === false ? true : item.timestamp < (/* @__PURE__ */ new Date()).getTime() - this.duration_;
808
351
  }
809
- async decorateMany_(items, params = {}) {
810
- const store = this.store;
811
- let decoratedItems = items;
812
- decoratedItems = await decorateSchemas_(store, decoratedItems, this.key);
813
- decoratedItems = await decorateCategories_(store, decoratedItems, params);
814
- decoratedItems = await decorateHrefs_(store, decoratedItems, params);
815
- return decoratedItems;
352
+ hasKey_(key) {
353
+ const item = this.cache_.get(key);
354
+ return item ? !this.isExpired_(item) : false;
816
355
  }
817
- };
818
-
819
- //#endregion
820
- //#region src/local_/local.store.ts
821
- const PAGES$1 = process.env.PAGES ? process.env.PAGES.split(",") : [];
822
- async function getLocalStore_() {
823
- return fromCache(async () => {
824
- if (COLLECTIONS.length === 0) {
825
- console.error("LocalStore.getLocalStore_ no collections");
826
- throw "LocalStore.getLocalStore_ no collections";
827
- }
828
- let mockStore = {};
829
- if (MOCK_COLLECTIONS.length > 0) mockStore = await getMockStore();
830
- const store = {};
831
- COLLECTIONS.sort();
832
- COLLECTIONS.forEach((key) => {
833
- if (MOCK_COLLECTIONS.includes(key)) store[key] = mockStore[key];
834
- else if (PAGES$1.includes(key) && storeStrategy === StoreStrategy.DecoratedApi) store[key] = new LocalPageService(key, store);
835
- else if (key === "menu" && storeStrategy === StoreStrategy.DecoratedApi) store[key] = new CachedService(new LocalMenuService(key, store));
836
- else if (KNOWN_COLLECTIONS.includes(key)) store[key] = new CachedService(new LocalService(key, store));
837
- else store[key] = new LocalService(key, store);
356
+ getKey_(key) {
357
+ return this.cache_.get(key).data;
358
+ }
359
+ setKey_(key, data) {
360
+ this.cache_.set(key, {
361
+ timestamp: (/* @__PURE__ */ new Date()).getTime(),
362
+ data
838
363
  });
839
- return store;
840
- }, "STORE_RUNTIME_");
841
- }
842
- async function getLocalStoreStaticBuild_() {
843
- return fromCache(async () => {
844
- console.log("getLocalStoreStaticBuild_");
845
- let store = {};
846
- const url = `/store?strategy=${buildStrategy}`;
847
- const json = await localApiGet(url);
848
- if (json != null) {
849
- const data = Object.fromEntries(COLLECTIONS.map((key) => [key, json[key] || []]));
850
- store = getMockStoreFromData_(data);
364
+ }
365
+ async findGlobal(params = {}) {
366
+ const serializedParams = qsSerialize(params);
367
+ const key = `findGlobal?${serializedParams}`;
368
+ return await this.fromCache_(async () => {
369
+ return await this.service_.findGlobal(params);
370
+ }, key);
371
+ }
372
+ async findOne(id, params = {}) {
373
+ const serializedParams = qsSerialize(params);
374
+ const key = `findOne[${id}]?${serializedParams}`;
375
+ return await this.fromCache_(async () => {
376
+ return await this.service_.findOne(id, params);
377
+ }, key);
378
+ }
379
+ async findMany(params = {}) {
380
+ if (storeStrategy === StoreStrategy.DecoratedApi) {
381
+ const { market, locale,...otherParams } = params;
382
+ const serializedParams = qsSerialize({
383
+ market,
384
+ locale
385
+ });
386
+ const key = `findMany?${serializedParams}`;
387
+ let items = await this.fromCache_(async () => {
388
+ return await this.service_.findMany({
389
+ market,
390
+ locale
391
+ });
392
+ }, key);
393
+ if (otherParams.where) items = this.whereItems_(items, otherParams.where);
394
+ if (otherParams.sort) items = this.sortCollection_(items, otherParams.sort);
395
+ return items;
396
+ } else {
397
+ const serializedParams = qsSerialize(params);
398
+ const key = `findMany?${serializedParams}`;
399
+ return await this.fromCache_(async () => {
400
+ return await this.service_.findMany(params);
401
+ }, key);
851
402
  }
852
- return store;
853
- }, "STORE_BUILD_");
854
- }
855
- async function getLocalStore() {
856
- if (nextPhase === NextPhase.ProductionBuild) return await getLocalStoreStaticBuild_();
857
- else return await getLocalStore_();
858
- }
403
+ }
404
+ async findPaged(params = {}) {
405
+ const serializedParams = qsSerialize(params);
406
+ const key = `findPaged?${serializedParams}`;
407
+ return await this.fromCache_(async () => {
408
+ return await this.service_.findPaged(params);
409
+ }, key);
410
+ }
411
+ async create(payload) {
412
+ return await this.service_.create(payload);
413
+ }
414
+ async updateOne(id, payload, params = {}) {
415
+ return await this.service_.updateOne(id, payload, params);
416
+ }
417
+ async updateMany(payload, params = {}) {
418
+ return await this.service_.updateMany(payload, params);
419
+ }
420
+ async deleteOne(id, params = {}) {
421
+ return await this.service_.deleteOne(id, params);
422
+ }
423
+ async deleteMany(params = {}) {
424
+ return await this.service_.deleteMany(params);
425
+ }
426
+ async update(payload) {
427
+ return await this.service_.update(payload);
428
+ }
429
+ async delete(id) {
430
+ return await this.service_.delete(id);
431
+ }
432
+ };
859
433
 
860
434
  //#endregion
861
435
  //#region src/remote/remote.service.ts
@@ -1092,7 +666,6 @@ async function getRemoteStore() {
1092
666
  async function getStore() {
1093
667
  switch (storeStrategy) {
1094
668
  case StoreStrategy.Mock: return await getMockStore();
1095
- case StoreStrategy.Local: return await getLocalStore();
1096
669
  default: return await getRemoteStore();
1097
670
  }
1098
671
  }
@@ -1798,5 +1371,5 @@ function varsHandler() {
1798
1371
  }
1799
1372
 
1800
1373
  //#endregion
1801
- export { LocalService, MockMenuService, MockPageService, MockService, RemoteMenuService, RemotePageService, RemoteService, StaticService, apiHandler, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateStaticRelation_, decorateStaticRelations_, errorHandler, findRoute, getAuthHeaders, getMockStore, getMockStoreFromData_, getPayloadSingleton, getPayloadUser, getRemoteStore, getStore, mockHandler, previewHandler, routePost, setPayloadConfig, storeHandler, storeIndexHandler, varsHandler };
1374
+ export { MockMenuService, MockPageService, MockService, RemoteMenuService, RemotePageService, RemoteService, StaticService, apiHandler, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateStaticRelation_, decorateStaticRelations_, errorHandler, findRoute, getMockStore, getMockStoreFromData_, getRemoteStore, getStore, mockHandler, previewHandler, routePost, storeHandler, storeIndexHandler, varsHandler };
1802
1375
  //# sourceMappingURL=server.js.map