@websolutespa/bom-mixer-store 1.8.3 → 1.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/index.d.ts +22 -9
- package/dist/index.js +170 -55
- package/dist/index.mjs +169 -55
- package/package.json +1 -1
- package/src/api/api.ts +42 -6
- package/src/cached/cached.service.ts +18 -0
- package/src/decorators/category.ts +53 -35
- package/src/decorators/consts.ts +2 -0
- package/src/decorators/index.ts +1 -1
- package/src/decorators/relation.ts +2 -3
- package/src/mock/mock-page.service.ts +10 -2
- package/src/mock/mock.service.ts +3 -3
- package/src/remote/remote.service.ts +59 -11
- package/src/session/session.service.ts +25 -0
- package/src/static/static.service.ts +2 -2
- package/src/store/store.handler.ts +57 -8
- package/src/vars/vars.handler.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @websolutespa/bom-mixer-store
|
|
2
2
|
|
|
3
|
+
## 1.8.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Modified: IQuerable
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @websolutespa/bom-core@1.8.12
|
|
10
|
+
|
|
11
|
+
## 1.8.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Modified: decorateCategory\_
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @websolutespa/bom-core@1.8.11
|
|
18
|
+
|
|
3
19
|
## 1.8.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { FetchRequestOptions,
|
|
1
|
+
import { FetchRequestOptions, IEquatable, ICategory, IStore, QueryParams, ICategorized, IRoute, ISchema, IUndecoratedMenu, IMenu, IEntity, JsonService, IMemoryStore, IQuerable, IPagedResult } from '@websolutespa/bom-core';
|
|
2
2
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
3
3
|
import { NextRequest } from 'next/server';
|
|
4
|
-
import * as _websolutespa_bom_mixer_store from '@websolutespa/bom-mixer-store';
|
|
5
4
|
|
|
6
5
|
type ApiRequestOptions = FetchRequestOptions;
|
|
7
6
|
declare function getLocalApiRequestOptions(): ApiRequestOptions;
|
|
@@ -18,12 +17,23 @@ declare function errorHandler(error: any, response: NextApiResponse): NextApiRes
|
|
|
18
17
|
|
|
19
18
|
declare function fromCache<T = unknown>(callback: () => Promise<T>, key?: string): Promise<T>;
|
|
20
19
|
|
|
21
|
-
declare function decorateCategory_<T extends
|
|
20
|
+
declare function decorateCategory_<T extends {
|
|
21
|
+
category?: IEquatable | ICategory;
|
|
22
|
+
} = {
|
|
23
|
+
category?: IEquatable | ICategory;
|
|
24
|
+
}>(store: IStore, item: T, params?: QueryParams): Promise<T | (T & {
|
|
22
25
|
category: ICategory;
|
|
23
26
|
})>;
|
|
24
27
|
declare function decorateCategories_<T extends ICategorized = ICategorized>(store: IStore, items: T[], params?: QueryParams): Promise<(T | (T & {
|
|
25
28
|
category: ICategory;
|
|
26
29
|
}))[]>;
|
|
30
|
+
declare function collectCategory_<T extends {
|
|
31
|
+
category?: IEquatable | ICategory;
|
|
32
|
+
} = {
|
|
33
|
+
category?: IEquatable | ICategory;
|
|
34
|
+
}>(categories: ICategory[], routes: IRoute[], item: T, params: QueryParams | undefined, depth: number): Promise<T>;
|
|
35
|
+
|
|
36
|
+
declare const DEFAULT_DEPTH = 3;
|
|
27
37
|
|
|
28
38
|
declare function decorateHref_<T extends ISchema = ISchema>(store: IStore, item: T, params?: QueryParams): Promise<T | T & {
|
|
29
39
|
href: string | null;
|
|
@@ -51,7 +61,6 @@ declare function decorateNavs_<T extends ISchema = ISchema>(store: IStore, items
|
|
|
51
61
|
declare function optimizeOne_<T extends ICategorized = ICategorized>(item: T): Promise<T>;
|
|
52
62
|
declare function optimizeMany_<T extends ICategorized = ICategorized>(items: T[]): Promise<T[]>;
|
|
53
63
|
|
|
54
|
-
declare const SERVICE_DEFAULT_DEPTH = 3;
|
|
55
64
|
declare function decorateRelation_<T extends ISchema = ISchema>(store: IStore, item: T, params?: QueryParams): Promise<T>;
|
|
56
65
|
declare function decorateRelations_<T extends ISchema = ISchema>(store: IStore, items: T[], params?: QueryParams): Promise<T[]>;
|
|
57
66
|
type IPageResolvedRelation = {
|
|
@@ -136,11 +145,15 @@ declare class RemoteService<T extends IEntity = IEntity> implements IQuerable<T>
|
|
|
136
145
|
key: string;
|
|
137
146
|
store: IStore;
|
|
138
147
|
constructor(key: string, store: IStore);
|
|
139
|
-
findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
|
|
148
|
+
findOne<B extends T = T>(id: IEquatable, params?: Omit<QueryParams, 'where'>): Promise<B | undefined>;
|
|
140
149
|
findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
|
|
141
150
|
findPaged<B extends T = T>(params?: QueryParams): Promise<IPagedResult<B>>;
|
|
142
|
-
create<B extends T = T>(payload: Omit<B, 'id'
|
|
143
|
-
|
|
151
|
+
create<B extends T = T>(payload: Omit<B, 'id'>, params?: QueryParams): Promise<B>;
|
|
152
|
+
updateOne<B extends T = T>(id: IEquatable, payload: Partial<B>, params?: Omit<QueryParams, 'where'>): Promise<B>;
|
|
153
|
+
updateMany<B extends T = T>(payload: Partial<B>, params?: QueryParams): Promise<B[]>;
|
|
154
|
+
deleteOne<B extends T = T>(id: IEquatable, params?: Omit<QueryParams, 'where'>): Promise<B | undefined>;
|
|
155
|
+
deleteMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
|
|
156
|
+
update<B extends T = T>(payload: Partial<B>, params?: QueryParams): Promise<B>;
|
|
144
157
|
delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
|
|
145
158
|
protected decorateOne_<B extends T = T>(item: B, params?: QueryParams): Promise<B>;
|
|
146
159
|
protected decorateMany_<B extends T = T>(items: B[], params?: QueryParams): Promise<B[]>;
|
|
@@ -240,6 +253,6 @@ declare function findRoute(store: IStore, pathname: string, href: string, hrefBe
|
|
|
240
253
|
|
|
241
254
|
declare function getStore<T extends IStore>(): Promise<T>;
|
|
242
255
|
|
|
243
|
-
declare function varsHandler():
|
|
256
|
+
declare function varsHandler(): IHandler<any>;
|
|
244
257
|
|
|
245
|
-
export { ApiRequestOptions, BuildStrategy, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, REMOTE_API_SESSION, RemoteMenuService, RemotePageService, RemoteService, RemoteServiceStrategy,
|
|
258
|
+
export { ApiRequestOptions, BuildStrategy, COLLECTIONS, DEFAULT_DEPTH, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, REMOTE_API_SESSION, RemoteMenuService, RemotePageService, RemoteService, RemoteServiceStrategy, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectCategory_, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, decorateStaticRelation_, decorateStaticRelations_, errorHandler, findRoute, fromCache, getLocalApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, getRemoteApiRequestOptions, getRemoteApiUrl, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, nextPhase, optimizeMany_, optimizeOne_, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeCacheDuration, storeHandler, storeIndexHandler, storeStrategy, varsHandler };
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
BuildStrategy: () => BuildStrategy,
|
|
34
34
|
COLLECTIONS: () => COLLECTIONS,
|
|
35
|
+
DEFAULT_DEPTH: () => DEFAULT_DEPTH,
|
|
35
36
|
KNOWN_COLLECTIONS: () => KNOWN_COLLECTIONS,
|
|
36
37
|
MAX_INT: () => MAX_INT,
|
|
37
38
|
MOCK_COLLECTIONS: () => MOCK_COLLECTIONS,
|
|
@@ -44,12 +45,12 @@ __export(src_exports, {
|
|
|
44
45
|
RemotePageService: () => RemotePageService,
|
|
45
46
|
RemoteService: () => RemoteService,
|
|
46
47
|
RemoteServiceStrategy: () => RemoteServiceStrategy,
|
|
47
|
-
SERVICE_DEFAULT_DEPTH: () => SERVICE_DEFAULT_DEPTH,
|
|
48
48
|
STATIC_COLLECTIONS: () => STATIC_COLLECTIONS,
|
|
49
49
|
StaticService: () => StaticService,
|
|
50
50
|
StoreStrategy: () => StoreStrategy,
|
|
51
51
|
apiHandler: () => apiHandler,
|
|
52
52
|
buildStrategy: () => buildStrategy,
|
|
53
|
+
collectCategory_: () => collectCategory_,
|
|
53
54
|
collectionDelete: () => collectionDelete,
|
|
54
55
|
collectionGet: () => collectionGet,
|
|
55
56
|
collectionPatch: () => collectionPatch,
|
|
@@ -192,47 +193,60 @@ async function fromCache(callback, key) {
|
|
|
192
193
|
|
|
193
194
|
// src/decorators/category.ts
|
|
194
195
|
var import_bom_core = require("@websolutespa/bom-core");
|
|
196
|
+
|
|
197
|
+
// src/decorators/consts.ts
|
|
198
|
+
var DEFAULT_DEPTH = 3;
|
|
199
|
+
|
|
200
|
+
// src/decorators/category.ts
|
|
195
201
|
async function decorateCategory_(store, item, params = {}) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
203
|
+
if (depth === 0) {
|
|
204
|
+
return item;
|
|
205
|
+
}
|
|
206
|
+
const categories = await store.category.findMany({
|
|
207
|
+
market: params.market,
|
|
208
|
+
locale: params.locale,
|
|
209
|
+
depth: 0
|
|
210
|
+
});
|
|
211
|
+
const routes = await store.route.findMany();
|
|
212
|
+
const decoratedItem = await collectCategory_(categories, routes, item, params, depth);
|
|
213
|
+
return decoratedItem;
|
|
214
|
+
}
|
|
215
|
+
async function decorateCategories_(store, items, params = {}) {
|
|
216
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
217
|
+
if (depth === 0) {
|
|
218
|
+
return items;
|
|
219
|
+
}
|
|
220
|
+
const categories = await store.category.findMany({
|
|
221
|
+
market: params.market,
|
|
222
|
+
locale: params.locale,
|
|
223
|
+
depth: 0
|
|
224
|
+
});
|
|
225
|
+
const routes = await store.route.findMany();
|
|
226
|
+
const decoratedItems = [];
|
|
227
|
+
for (const item of items) {
|
|
228
|
+
const decoratedItem = await collectCategory_(categories, routes, item, params, depth);
|
|
229
|
+
decoratedItems.push(decoratedItem);
|
|
230
|
+
}
|
|
231
|
+
return decoratedItems;
|
|
232
|
+
}
|
|
233
|
+
async function collectCategory_(categories, routes, item, params = {}, depth) {
|
|
234
|
+
if (depth === 0) {
|
|
235
|
+
return item;
|
|
236
|
+
}
|
|
237
|
+
if ((0, import_bom_core.isUnresolvedCategory)(item.category)) {
|
|
238
|
+
const category = categories.find((x) => x.id === item.category);
|
|
239
|
+
if (category) {
|
|
207
240
|
const route = (0, import_bom_core.findRouteOfCategory)(routes, category.id, params.market, params.locale);
|
|
208
241
|
if (route) {
|
|
209
242
|
category.href = route.id;
|
|
210
243
|
}
|
|
211
|
-
|
|
244
|
+
const decoratedCategory = await collectCategory_(categories, routes, category, params, depth - 1);
|
|
245
|
+
return { ...item, category: decoratedCategory };
|
|
212
246
|
}
|
|
213
247
|
}
|
|
214
248
|
return item;
|
|
215
249
|
}
|
|
216
|
-
async function decorateCategories_(store, items, params = {}) {
|
|
217
|
-
const hasUndecoratedCategories = items.find((x) => typeof x.category === "string") !== void 0;
|
|
218
|
-
if (hasUndecoratedCategories) {
|
|
219
|
-
const categories = await store.category.findMany();
|
|
220
|
-
let routes = await store.route.findMany();
|
|
221
|
-
routes = routes.filter((x) => x.market === params.market && x.locale === params.locale);
|
|
222
|
-
return items.map((item) => {
|
|
223
|
-
const category = categories.find((x) => x.id === item.category);
|
|
224
|
-
if (category) {
|
|
225
|
-
const route = (0, import_bom_core.findRouteOfCategory)(routes, category.id);
|
|
226
|
-
if (route) {
|
|
227
|
-
category.href = route.id;
|
|
228
|
-
}
|
|
229
|
-
return { ...item, category };
|
|
230
|
-
}
|
|
231
|
-
return item;
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
return items;
|
|
235
|
-
}
|
|
236
250
|
|
|
237
251
|
// src/decorators/href.ts
|
|
238
252
|
async function decorateHref_(store, item, params = {}) {
|
|
@@ -591,9 +605,8 @@ async function optimizeMany_(items) {
|
|
|
591
605
|
|
|
592
606
|
// src/decorators/relation.ts
|
|
593
607
|
var import_bom_core5 = require("@websolutespa/bom-core");
|
|
594
|
-
var SERVICE_DEFAULT_DEPTH = 3;
|
|
595
608
|
async function decorateRelation_(store, item, params = {}) {
|
|
596
|
-
const depth = params.depth != null ? params.depth :
|
|
609
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
597
610
|
if (depth === 0) {
|
|
598
611
|
return item;
|
|
599
612
|
}
|
|
@@ -729,7 +742,7 @@ var MockService = class extends import_bom_core7.JsonService {
|
|
|
729
742
|
decoratedItem = await decorateRelation_(store, decoratedItem, {
|
|
730
743
|
market: params.market,
|
|
731
744
|
locale: params.locale,
|
|
732
|
-
depth: params.depth != null ? params.depth :
|
|
745
|
+
depth: params.depth != null ? params.depth : DEFAULT_DEPTH
|
|
733
746
|
});
|
|
734
747
|
return decoratedItem;
|
|
735
748
|
}
|
|
@@ -740,7 +753,7 @@ var MockService = class extends import_bom_core7.JsonService {
|
|
|
740
753
|
decoratedItems = await decorateRelations_(store, decoratedItems, {
|
|
741
754
|
market: params.market,
|
|
742
755
|
locale: params.locale,
|
|
743
|
-
depth: params.depth != null ? params.depth :
|
|
756
|
+
depth: params.depth != null ? params.depth : DEFAULT_DEPTH
|
|
744
757
|
});
|
|
745
758
|
return decoratedItems;
|
|
746
759
|
}
|
|
@@ -779,7 +792,11 @@ var MockPageService = class extends MockService {
|
|
|
779
792
|
async decorateOne_(item, params = {}) {
|
|
780
793
|
const store = this.store;
|
|
781
794
|
let decoratedItem = item;
|
|
782
|
-
decoratedItem = await decorateCategory_(store, decoratedItem,
|
|
795
|
+
decoratedItem = await decorateCategory_(store, decoratedItem, {
|
|
796
|
+
market: params.market,
|
|
797
|
+
locale: params.locale,
|
|
798
|
+
depth: params.depth
|
|
799
|
+
});
|
|
783
800
|
decoratedItem = await decorateLocalizable_(decoratedItem, params);
|
|
784
801
|
decoratedItem = await decorateHref_(store, decoratedItem, params);
|
|
785
802
|
decoratedItem = await decorateNav_(store, decoratedItem, params);
|
|
@@ -793,7 +810,11 @@ var MockPageService = class extends MockService {
|
|
|
793
810
|
async decorateMany_(items, params = {}) {
|
|
794
811
|
const store = this.store;
|
|
795
812
|
let decoratedItems = items;
|
|
796
|
-
decoratedItems = await decorateCategories_(store, decoratedItems,
|
|
813
|
+
decoratedItems = await decorateCategories_(store, decoratedItems, {
|
|
814
|
+
market: params.market,
|
|
815
|
+
locale: params.locale,
|
|
816
|
+
depth: params.depth
|
|
817
|
+
});
|
|
797
818
|
decoratedItems = await decorateLocalizables_(decoratedItems, params);
|
|
798
819
|
decoratedItems = await decorateHrefs_(store, decoratedItems, params);
|
|
799
820
|
decoratedItems = await decorateRelations_(store, decoratedItems, {
|
|
@@ -1233,7 +1254,7 @@ var StaticService = class extends import_bom_core9.JsonService {
|
|
|
1233
1254
|
}
|
|
1234
1255
|
};
|
|
1235
1256
|
async function decorateStaticRelation_(store, fields, item, params = {}) {
|
|
1236
|
-
const depth = params.depth != null ? params.depth :
|
|
1257
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
1237
1258
|
if (depth === 0) {
|
|
1238
1259
|
return item;
|
|
1239
1260
|
}
|
|
@@ -1412,6 +1433,19 @@ var CachedService = class extends import_bom_core11.JsonService {
|
|
|
1412
1433
|
async create(payload) {
|
|
1413
1434
|
return await this.service_.create(payload);
|
|
1414
1435
|
}
|
|
1436
|
+
async updateOne(id, payload, params = {}) {
|
|
1437
|
+
return await this.service_.updateOne(id, payload, params);
|
|
1438
|
+
}
|
|
1439
|
+
async updateMany(payload, params = {}) {
|
|
1440
|
+
return await this.service_.updateMany(payload, params);
|
|
1441
|
+
}
|
|
1442
|
+
async deleteOne(id, params = {}) {
|
|
1443
|
+
return await this.service_.deleteOne(id, params);
|
|
1444
|
+
}
|
|
1445
|
+
async deleteMany(params = {}) {
|
|
1446
|
+
return await this.service_.deleteMany(params);
|
|
1447
|
+
}
|
|
1448
|
+
// !!! old
|
|
1415
1449
|
async update(payload) {
|
|
1416
1450
|
return await this.service_.update(payload);
|
|
1417
1451
|
}
|
|
@@ -1497,7 +1531,7 @@ var RemoteService = class {
|
|
|
1497
1531
|
const search = query ? `?${query}` : "";
|
|
1498
1532
|
const url = `/${this.key}${search}`;
|
|
1499
1533
|
const response = await remoteApiGet(url);
|
|
1500
|
-
const items = Array.isArray(response
|
|
1534
|
+
const items = Array.isArray(response) ? response : response.docs;
|
|
1501
1535
|
return await this.decorateMany_(items, params);
|
|
1502
1536
|
}
|
|
1503
1537
|
async findPaged(params = {}) {
|
|
@@ -1512,21 +1546,60 @@ var RemoteService = class {
|
|
|
1512
1546
|
items = await this.decorateMany_(items, params);
|
|
1513
1547
|
return { ...response, docs: items };
|
|
1514
1548
|
}
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1549
|
+
async create(payload, params = {}) {
|
|
1550
|
+
params.richText = String(params.richText) === "true" ? true : false;
|
|
1551
|
+
params.draft = RemoteServiceStrategy.draft;
|
|
1552
|
+
const query = (0, import_bom_core13.qsSerialize)(params);
|
|
1553
|
+
const search = query ? `?${query}` : "";
|
|
1554
|
+
const url = `/${this.key}${search}`;
|
|
1518
1555
|
const result = await remoteApiPost(url, payload);
|
|
1519
1556
|
const item = result.doc ? result.doc : result;
|
|
1520
1557
|
return await this.decorateOne_(item, {});
|
|
1521
1558
|
}
|
|
1522
|
-
|
|
1523
|
-
|
|
1559
|
+
async updateOne(id, payload, params = {}) {
|
|
1560
|
+
const query = (0, import_bom_core13.qsSerialize)(params);
|
|
1561
|
+
const search = query ? `?${query}` : "";
|
|
1562
|
+
const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
|
|
1563
|
+
const result = await remoteApiPatch(url, payload);
|
|
1564
|
+
const item = result.doc ? result.doc : result;
|
|
1565
|
+
return await this.decorateOne_(item, {});
|
|
1566
|
+
}
|
|
1567
|
+
async updateMany(payload, params = {}) {
|
|
1568
|
+
params.richText = String(params.richText) === "true" ? true : false;
|
|
1569
|
+
params.draft = RemoteServiceStrategy.draft;
|
|
1570
|
+
params.pagination = false;
|
|
1571
|
+
const query = (0, import_bom_core13.qsSerialize)(params);
|
|
1572
|
+
const search = query ? `?${query}` : "";
|
|
1573
|
+
const url = `/${this.key}${search}`;
|
|
1574
|
+
const response = await remoteApiPatch(url, payload);
|
|
1575
|
+
const items = Array.isArray(response) ? response : response.docs;
|
|
1576
|
+
return await this.decorateMany_(items, params);
|
|
1577
|
+
}
|
|
1578
|
+
async deleteOne(id, params = {}) {
|
|
1579
|
+
const query = (0, import_bom_core13.qsSerialize)(params);
|
|
1580
|
+
const search = query ? `?${query}` : "";
|
|
1581
|
+
const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
|
|
1582
|
+
const item = await remoteApiDelete(url);
|
|
1583
|
+
return await this.decorateOne_(item, {});
|
|
1584
|
+
}
|
|
1585
|
+
async deleteMany(params = {}) {
|
|
1586
|
+
params.richText = String(params.richText) === "true" ? true : false;
|
|
1587
|
+
params.draft = RemoteServiceStrategy.draft;
|
|
1588
|
+
params.pagination = false;
|
|
1589
|
+
const query = (0, import_bom_core13.qsSerialize)(params);
|
|
1590
|
+
const search = query ? `?${query}` : "";
|
|
1591
|
+
const url = `/${this.key}${search}`;
|
|
1592
|
+
const response = await remoteApiDelete(url);
|
|
1593
|
+
const items = Array.isArray(response) ? response : response.docs;
|
|
1594
|
+
return await this.decorateMany_(items, params);
|
|
1595
|
+
}
|
|
1596
|
+
// !!! old
|
|
1597
|
+
async update(payload, params = {}) {
|
|
1524
1598
|
const url = `/${this.key}`;
|
|
1525
|
-
const result = await
|
|
1599
|
+
const result = await remoteApiPatch(url, payload);
|
|
1526
1600
|
const item = result.doc ? result.doc : result;
|
|
1527
1601
|
return await this.decorateOne_(item, {});
|
|
1528
1602
|
}
|
|
1529
|
-
// !!! todo params
|
|
1530
1603
|
async delete(id) {
|
|
1531
1604
|
const params = {
|
|
1532
1605
|
where: {
|
|
@@ -1769,19 +1842,40 @@ function collectionPost(storePromise) {
|
|
|
1769
1842
|
function collectionPatch(storePromise) {
|
|
1770
1843
|
return async (request, response) => {
|
|
1771
1844
|
try {
|
|
1772
|
-
const
|
|
1773
|
-
|
|
1845
|
+
const { collections, ...query } = request.query;
|
|
1846
|
+
if (!Array.isArray(collections) || collections?.length === 0) {
|
|
1847
|
+
console.error("storeHandler.collectionUpdate", "method not allowed", collections);
|
|
1848
|
+
return response.status(405).send("method not allowed");
|
|
1849
|
+
}
|
|
1774
1850
|
if (!Array.isArray(collections) || collections.length !== 2) {
|
|
1775
1851
|
console.error("method not allowed", collections);
|
|
1776
1852
|
return response.status(405).send("method not allowed");
|
|
1777
1853
|
}
|
|
1778
1854
|
const collection = collections[0];
|
|
1855
|
+
const id = collections[1];
|
|
1856
|
+
const qs = Object.entries(query).map((kv) => kv.join("=")).join("&");
|
|
1857
|
+
const params = (0, import_bom_core14.qsDeserialize)(qs);
|
|
1858
|
+
if (!COLLECTIONS.includes(collection)) {
|
|
1859
|
+
console.error("storeHandler.collectionUpdate", "method not allowed", collection);
|
|
1860
|
+
return response.status(405).send("method not allowed");
|
|
1861
|
+
}
|
|
1779
1862
|
const store = await storePromise();
|
|
1780
1863
|
const service = store[collection];
|
|
1781
1864
|
if (!service) {
|
|
1782
|
-
console.error("method not allowed", collection);
|
|
1865
|
+
console.error("storeHandler.collectionUpdate", "method not allowed", collection);
|
|
1783
1866
|
return response.status(405).send("method not allowed");
|
|
1784
1867
|
}
|
|
1868
|
+
if (id) {
|
|
1869
|
+
const item = await service.updateOne((0, import_bom_core14.asEquatable)(id), params);
|
|
1870
|
+
if (item) {
|
|
1871
|
+
return response.status(200).json(item);
|
|
1872
|
+
} else {
|
|
1873
|
+
return response.status(404).send("not found");
|
|
1874
|
+
}
|
|
1875
|
+
} else {
|
|
1876
|
+
const items = await service.updateMany(params);
|
|
1877
|
+
return response.status(200).json(items);
|
|
1878
|
+
}
|
|
1785
1879
|
} catch (error) {
|
|
1786
1880
|
console.error("storeHandler.error.500", error);
|
|
1787
1881
|
throw error;
|
|
@@ -1791,20 +1885,40 @@ function collectionPatch(storePromise) {
|
|
|
1791
1885
|
function collectionDelete(storePromise) {
|
|
1792
1886
|
return async (request, response) => {
|
|
1793
1887
|
try {
|
|
1794
|
-
const
|
|
1795
|
-
|
|
1888
|
+
const { collections, ...query } = request.query;
|
|
1889
|
+
if (!Array.isArray(collections) || collections?.length === 0) {
|
|
1890
|
+
console.error("storeHandler.collectionDelete", "method not allowed", collections);
|
|
1891
|
+
return response.status(405).send("method not allowed");
|
|
1892
|
+
}
|
|
1796
1893
|
if (!Array.isArray(collections) || collections.length !== 2) {
|
|
1797
1894
|
console.error("method not allowed", collections);
|
|
1798
1895
|
return response.status(405).send("method not allowed");
|
|
1799
1896
|
}
|
|
1800
1897
|
const collection = collections[0];
|
|
1801
1898
|
const id = collections[1];
|
|
1899
|
+
const qs = Object.entries(query).map((kv) => kv.join("=")).join("&");
|
|
1900
|
+
const params = (0, import_bom_core14.qsDeserialize)(qs);
|
|
1901
|
+
if (!COLLECTIONS.includes(collection)) {
|
|
1902
|
+
console.error("storeHandler.collectionDelete", "method not allowed", collection);
|
|
1903
|
+
return response.status(405).send("method not allowed");
|
|
1904
|
+
}
|
|
1802
1905
|
const store = await storePromise();
|
|
1803
1906
|
const service = store[collection];
|
|
1804
1907
|
if (!service) {
|
|
1805
|
-
console.error("method not allowed", collection);
|
|
1908
|
+
console.error("storeHandler.collectionDelete", "method not allowed", collection);
|
|
1806
1909
|
return response.status(405).send("method not allowed");
|
|
1807
1910
|
}
|
|
1911
|
+
if (id) {
|
|
1912
|
+
const item = await service.deleteOne((0, import_bom_core14.asEquatable)(id), params);
|
|
1913
|
+
if (item) {
|
|
1914
|
+
return response.status(200).json(item);
|
|
1915
|
+
} else {
|
|
1916
|
+
return response.status(404).send("not found");
|
|
1917
|
+
}
|
|
1918
|
+
} else {
|
|
1919
|
+
const items = await service.deleteMany(params);
|
|
1920
|
+
return response.status(200).json(items);
|
|
1921
|
+
}
|
|
1808
1922
|
} catch (error) {
|
|
1809
1923
|
console.error("storeHandler.error.500", error);
|
|
1810
1924
|
throw error;
|
|
@@ -2378,6 +2492,7 @@ function varsHandler() {
|
|
|
2378
2492
|
0 && (module.exports = {
|
|
2379
2493
|
BuildStrategy,
|
|
2380
2494
|
COLLECTIONS,
|
|
2495
|
+
DEFAULT_DEPTH,
|
|
2381
2496
|
KNOWN_COLLECTIONS,
|
|
2382
2497
|
MAX_INT,
|
|
2383
2498
|
MOCK_COLLECTIONS,
|
|
@@ -2390,12 +2505,12 @@ function varsHandler() {
|
|
|
2390
2505
|
RemotePageService,
|
|
2391
2506
|
RemoteService,
|
|
2392
2507
|
RemoteServiceStrategy,
|
|
2393
|
-
SERVICE_DEFAULT_DEPTH,
|
|
2394
2508
|
STATIC_COLLECTIONS,
|
|
2395
2509
|
StaticService,
|
|
2396
2510
|
StoreStrategy,
|
|
2397
2511
|
apiHandler,
|
|
2398
2512
|
buildStrategy,
|
|
2513
|
+
collectCategory_,
|
|
2399
2514
|
collectionDelete,
|
|
2400
2515
|
collectionGet,
|
|
2401
2516
|
collectionPatch,
|