@web-ts-toolkit/access-router-client 0.4.0 → 0.5.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/README.md +39 -12
- package/index.d.mts +218 -193
- package/index.d.ts +218 -193
- package/index.js +785 -905
- package/index.mjs +781 -902
- package/package.json +13 -11
package/index.js
CHANGED
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/index.ts
|
|
30
30
|
var index_exports = {};
|
|
31
31
|
__export(index_exports, {
|
|
32
|
+
CustomHeaders: () => CustomHeaders,
|
|
32
33
|
DataService: () => DataService,
|
|
33
34
|
Model: () => Model,
|
|
34
35
|
ModelService: () => ModelService,
|
|
@@ -43,47 +44,13 @@ __export(index_exports, {
|
|
|
43
44
|
module.exports = __toCommonJS(index_exports);
|
|
44
45
|
|
|
45
46
|
// src/adapter.ts
|
|
46
|
-
var
|
|
47
|
-
var
|
|
47
|
+
var import_axios8 = __toESM(require("axios"));
|
|
48
|
+
var import_utils6 = require("@web-ts-toolkit/utils");
|
|
48
49
|
|
|
49
50
|
// src/services/model-service.ts
|
|
50
|
-
var
|
|
51
|
+
var import_axios4 = require("axios");
|
|
51
52
|
var import_utils5 = require("@web-ts-toolkit/utils");
|
|
52
53
|
|
|
53
|
-
// src/types.ts
|
|
54
|
-
var wrapLazyPromise = (promiseFn, meta) => {
|
|
55
|
-
let promise;
|
|
56
|
-
const exec = () => {
|
|
57
|
-
if (!promise) {
|
|
58
|
-
promise = promiseFn();
|
|
59
|
-
}
|
|
60
|
-
return promise;
|
|
61
|
-
};
|
|
62
|
-
const prom = {
|
|
63
|
-
exec,
|
|
64
|
-
then(onFulfilled, onRejected) {
|
|
65
|
-
return exec().then(onFulfilled, onRejected);
|
|
66
|
-
},
|
|
67
|
-
catch(onRejected) {
|
|
68
|
-
return exec().catch(onRejected);
|
|
69
|
-
},
|
|
70
|
-
finally(onFinally) {
|
|
71
|
-
return exec().finally(onFinally);
|
|
72
|
-
},
|
|
73
|
-
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
74
|
-
return "LazyPromise";
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
Object.defineProperty(prom, Symbol.toStringTag, {
|
|
78
|
-
value: "Promise",
|
|
79
|
-
writable: false,
|
|
80
|
-
enumerable: false,
|
|
81
|
-
configurable: true
|
|
82
|
-
});
|
|
83
|
-
Object.assign(prom, meta);
|
|
84
|
-
return prom;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
54
|
// src/model.ts
|
|
88
55
|
var import_utils = require("@web-ts-toolkit/utils");
|
|
89
56
|
var Model = class _Model {
|
|
@@ -158,7 +125,6 @@ var Model = class _Model {
|
|
|
158
125
|
toJSON() {
|
|
159
126
|
return this.toObject();
|
|
160
127
|
}
|
|
161
|
-
// async validate() {}
|
|
162
128
|
updateModel(data) {
|
|
163
129
|
(0, import_utils.assign)(this._data, data);
|
|
164
130
|
this.definePublicDataProps();
|
|
@@ -238,12 +204,15 @@ var Model = class _Model {
|
|
|
238
204
|
};
|
|
239
205
|
|
|
240
206
|
// src/services/service.ts
|
|
241
|
-
var
|
|
242
|
-
var import_utils3 = require("@web-ts-toolkit/utils");
|
|
207
|
+
var import_axios2 = require("axios");
|
|
243
208
|
|
|
244
209
|
// src/constants.ts
|
|
245
210
|
var CACHE_HEADER = "x-axios-cache";
|
|
246
211
|
|
|
212
|
+
// src/services/wrap.ts
|
|
213
|
+
var import_axios = require("axios");
|
|
214
|
+
var import_utils3 = require("@web-ts-toolkit/utils");
|
|
215
|
+
|
|
247
216
|
// src/helpers.ts
|
|
248
217
|
var import_utils2 = require("@web-ts-toolkit/utils");
|
|
249
218
|
function replaceSubQuery(filter) {
|
|
@@ -276,9 +245,77 @@ function getWrapContext(url, options, config) {
|
|
|
276
245
|
return { finalUrl, finalConfig: config };
|
|
277
246
|
}
|
|
278
247
|
|
|
248
|
+
// src/services/wrap.ts
|
|
249
|
+
var removeTrailingSlash = (s) => s.replace(/\/$/, "");
|
|
250
|
+
var removeLeadingSlash = (s) => s.replace(/^\/+/g, "");
|
|
251
|
+
function resolveUrl(basePath, url) {
|
|
252
|
+
return basePath ? `${removeTrailingSlash(basePath)}/${removeLeadingSlash(url)}` : url;
|
|
253
|
+
}
|
|
254
|
+
function prepareConfig(defaultConfig, cacheValue, requestConfig) {
|
|
255
|
+
(0, import_utils3.set)(defaultConfig, `headers.${CACHE_HEADER}`, cacheValue);
|
|
256
|
+
return (0, import_axios.mergeConfig)(defaultConfig, requestConfig);
|
|
257
|
+
}
|
|
258
|
+
function createWrapHelper(axios2, basePath) {
|
|
259
|
+
return {
|
|
260
|
+
wrapGet: (url, defaultConfig = {}) => {
|
|
261
|
+
const _url = resolveUrl(basePath, url);
|
|
262
|
+
return (options, requestConfig) => {
|
|
263
|
+
const { finalUrl, finalConfig } = getWrapContext(
|
|
264
|
+
_url,
|
|
265
|
+
options,
|
|
266
|
+
prepareConfig(defaultConfig, "true", requestConfig)
|
|
267
|
+
);
|
|
268
|
+
return axios2.get(finalUrl, finalConfig);
|
|
269
|
+
};
|
|
270
|
+
},
|
|
271
|
+
wrapPost: (url, defaultConfig = {}) => {
|
|
272
|
+
const _url = resolveUrl(basePath, url);
|
|
273
|
+
return (data, options, requestConfig) => {
|
|
274
|
+
const { finalUrl, finalConfig } = getWrapContext(
|
|
275
|
+
_url,
|
|
276
|
+
options,
|
|
277
|
+
prepareConfig(defaultConfig, "false", requestConfig)
|
|
278
|
+
);
|
|
279
|
+
return axios2.post(finalUrl, data, finalConfig);
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
wrapPut: (url, defaultConfig = {}) => {
|
|
283
|
+
const _url = resolveUrl(basePath, url);
|
|
284
|
+
return (data, options, requestConfig) => {
|
|
285
|
+
const { finalUrl, finalConfig } = getWrapContext(
|
|
286
|
+
_url,
|
|
287
|
+
options,
|
|
288
|
+
prepareConfig(defaultConfig, "false", requestConfig)
|
|
289
|
+
);
|
|
290
|
+
return axios2.put(finalUrl, data, finalConfig);
|
|
291
|
+
};
|
|
292
|
+
},
|
|
293
|
+
wrapPatch: (url, defaultConfig = {}) => {
|
|
294
|
+
const _url = resolveUrl(basePath, url);
|
|
295
|
+
return (data, options, requestConfig) => {
|
|
296
|
+
const { finalUrl, finalConfig } = getWrapContext(
|
|
297
|
+
_url,
|
|
298
|
+
options,
|
|
299
|
+
prepareConfig(defaultConfig, "false", requestConfig)
|
|
300
|
+
);
|
|
301
|
+
return axios2.patch(finalUrl, data, finalConfig);
|
|
302
|
+
};
|
|
303
|
+
},
|
|
304
|
+
wrapDelete: (url, defaultConfig = {}) => {
|
|
305
|
+
const _url = resolveUrl(basePath, url);
|
|
306
|
+
return (options, requestConfig) => {
|
|
307
|
+
const { finalUrl, finalConfig } = getWrapContext(
|
|
308
|
+
_url,
|
|
309
|
+
options,
|
|
310
|
+
prepareConfig(defaultConfig, "false", requestConfig)
|
|
311
|
+
);
|
|
312
|
+
return axios2.delete(finalUrl, finalConfig);
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
279
318
|
// src/services/service.ts
|
|
280
|
-
var removeTrailingSlash = (inputString) => inputString.replace(/\/$/, "");
|
|
281
|
-
var removeLeadingSlash = (inputString) => inputString.replace(/^\/+/g, "");
|
|
282
319
|
var readProblemDetail = (value) => {
|
|
283
320
|
if (!value || typeof value !== "object") {
|
|
284
321
|
return void 0;
|
|
@@ -326,11 +363,12 @@ var Service = class {
|
|
|
326
363
|
constructor(axios2, basePath) {
|
|
327
364
|
this._axios = axios2;
|
|
328
365
|
this._basePath = basePath;
|
|
366
|
+
this._wrap = createWrapHelper(axios2, basePath);
|
|
329
367
|
}
|
|
330
368
|
handleSuccess(res, extra = {}) {
|
|
331
369
|
return { success: true, raw: res.data, status: res.status, headers: res.headers, ...extra };
|
|
332
370
|
}
|
|
333
|
-
// See https://axios-http.com/docs/
|
|
371
|
+
// See https://axios-http.com/docs/handling-errors
|
|
334
372
|
handleError(error) {
|
|
335
373
|
const result = {
|
|
336
374
|
success: false,
|
|
@@ -355,71 +393,26 @@ var Service = class {
|
|
|
355
393
|
return result;
|
|
356
394
|
}
|
|
357
395
|
wrapGet(url, defaultAxiosRequestConfig = {}) {
|
|
358
|
-
|
|
359
|
-
(0, import_utils3.set)(defaultAxiosRequestConfig, `headers.${CACHE_HEADER}`, "true");
|
|
360
|
-
return (options, axiosRequestConfig) => {
|
|
361
|
-
const { finalUrl, finalConfig } = getWrapContext(
|
|
362
|
-
_url,
|
|
363
|
-
options,
|
|
364
|
-
(0, import_axios.mergeConfig)(defaultAxiosRequestConfig, axiosRequestConfig)
|
|
365
|
-
);
|
|
366
|
-
return this._axios.get(finalUrl, finalConfig);
|
|
367
|
-
};
|
|
396
|
+
return this._wrap.wrapGet(url, defaultAxiosRequestConfig);
|
|
368
397
|
}
|
|
369
398
|
wrapPost(url, defaultAxiosRequestConfig = {}) {
|
|
370
|
-
|
|
371
|
-
(0, import_utils3.set)(defaultAxiosRequestConfig, `headers.${CACHE_HEADER}`, "false");
|
|
372
|
-
return (data, options, axiosRequestConfig) => {
|
|
373
|
-
const { finalUrl, finalConfig } = getWrapContext(
|
|
374
|
-
_url,
|
|
375
|
-
options,
|
|
376
|
-
(0, import_axios.mergeConfig)(defaultAxiosRequestConfig, axiosRequestConfig)
|
|
377
|
-
);
|
|
378
|
-
return this._axios.post(finalUrl, data, finalConfig);
|
|
379
|
-
};
|
|
399
|
+
return this._wrap.wrapPost(url, defaultAxiosRequestConfig);
|
|
380
400
|
}
|
|
381
401
|
wrapPut(url, defaultAxiosRequestConfig = {}) {
|
|
382
|
-
|
|
383
|
-
(0, import_utils3.set)(defaultAxiosRequestConfig, `headers.${CACHE_HEADER}`, "false");
|
|
384
|
-
return (data, options, axiosRequestConfig) => {
|
|
385
|
-
const { finalUrl, finalConfig } = getWrapContext(
|
|
386
|
-
_url,
|
|
387
|
-
options,
|
|
388
|
-
(0, import_axios.mergeConfig)(defaultAxiosRequestConfig, axiosRequestConfig)
|
|
389
|
-
);
|
|
390
|
-
return this._axios.put(finalUrl, data, finalConfig);
|
|
391
|
-
};
|
|
402
|
+
return this._wrap.wrapPut(url, defaultAxiosRequestConfig);
|
|
392
403
|
}
|
|
393
404
|
wrapPatch(url, defaultAxiosRequestConfig = {}) {
|
|
394
|
-
|
|
395
|
-
(0, import_utils3.set)(defaultAxiosRequestConfig, `headers.${CACHE_HEADER}`, "false");
|
|
396
|
-
return (data, options, axiosRequestConfig) => {
|
|
397
|
-
const { finalUrl, finalConfig } = getWrapContext(
|
|
398
|
-
_url,
|
|
399
|
-
options,
|
|
400
|
-
(0, import_axios.mergeConfig)(defaultAxiosRequestConfig, axiosRequestConfig)
|
|
401
|
-
);
|
|
402
|
-
return this._axios.patch(finalUrl, data, finalConfig);
|
|
403
|
-
};
|
|
405
|
+
return this._wrap.wrapPatch(url, defaultAxiosRequestConfig);
|
|
404
406
|
}
|
|
405
407
|
wrapDelete(url, defaultAxiosRequestConfig = {}) {
|
|
406
|
-
|
|
407
|
-
(0, import_utils3.set)(defaultAxiosRequestConfig, `headers.${CACHE_HEADER}`, "false");
|
|
408
|
-
return (options, axiosRequestConfig) => {
|
|
409
|
-
const { finalUrl, finalConfig } = getWrapContext(
|
|
410
|
-
_url,
|
|
411
|
-
options,
|
|
412
|
-
(0, import_axios.mergeConfig)(defaultAxiosRequestConfig, axiosRequestConfig)
|
|
413
|
-
);
|
|
414
|
-
return this._axios.delete(finalUrl, finalConfig);
|
|
415
|
-
};
|
|
408
|
+
return this._wrap.wrapDelete(url, defaultAxiosRequestConfig);
|
|
416
409
|
}
|
|
417
410
|
updateHeaders(headers, { ignoreCache }) {
|
|
418
411
|
const cacheValue = ignoreCache ? "false" : "true";
|
|
419
412
|
if (!headers) {
|
|
420
413
|
return { [CACHE_HEADER]: cacheValue };
|
|
421
414
|
}
|
|
422
|
-
if (headers instanceof
|
|
415
|
+
if (headers instanceof import_axios2.AxiosHeaders) {
|
|
423
416
|
if (headers.has(CACHE_HEADER)) return headers;
|
|
424
417
|
headers.set(CACHE_HEADER, cacheValue);
|
|
425
418
|
return headers;
|
|
@@ -445,6 +438,20 @@ var ServiceError = class extends Error {
|
|
|
445
438
|
|
|
446
439
|
// src/services/shared.ts
|
|
447
440
|
var import_utils4 = require("@web-ts-toolkit/utils");
|
|
441
|
+
|
|
442
|
+
// src/enums.ts
|
|
443
|
+
var CustomHeaders = /* @__PURE__ */ ((CustomHeaders2) => {
|
|
444
|
+
CustomHeaders2["TotalCount"] = "wtt-total-count";
|
|
445
|
+
CustomHeaders2["ReturnedCount"] = "wtt-returned-count";
|
|
446
|
+
CustomHeaders2["Page"] = "wtt-page";
|
|
447
|
+
CustomHeaders2["PageSize"] = "wtt-page-size";
|
|
448
|
+
CustomHeaders2["TotalPages"] = "wtt-total-pages";
|
|
449
|
+
CustomHeaders2["HasNextPage"] = "wtt-has-next-page";
|
|
450
|
+
CustomHeaders2["HasPreviousPage"] = "wtt-has-previous-page";
|
|
451
|
+
return CustomHeaders2;
|
|
452
|
+
})(CustomHeaders || {});
|
|
453
|
+
|
|
454
|
+
// src/services/shared.ts
|
|
448
455
|
var setDefaultObjectProp = (obj, key, value) => {
|
|
449
456
|
if (!(0, import_utils4.get)(obj, key)) {
|
|
450
457
|
(0, import_utils4.set)(obj, key, value);
|
|
@@ -465,6 +472,268 @@ var createResponseHandler = (onSuccess, onFailure, throwOnError) => {
|
|
|
465
472
|
return res;
|
|
466
473
|
};
|
|
467
474
|
};
|
|
475
|
+
function processListResult(result, { includeCount, includeExtraHeaders }, wrapItem) {
|
|
476
|
+
const wrappedRows = (0, import_utils4.get)(result, "raw.data");
|
|
477
|
+
const wrappedTotalCount = (0, import_utils4.get)(result, "raw.meta.totalCount");
|
|
478
|
+
if (Array.isArray(wrappedRows)) {
|
|
479
|
+
const rows = wrappedRows;
|
|
480
|
+
result.raw = wrappedRows;
|
|
481
|
+
if (includeCount) {
|
|
482
|
+
if (includeExtraHeaders) {
|
|
483
|
+
const totalCount = (0, import_utils4.get)(result, `headers.${"wtt-total-count" /* TotalCount */}`, 0);
|
|
484
|
+
result.totalCount = Number(totalCount);
|
|
485
|
+
} else {
|
|
486
|
+
result.totalCount = Number(wrappedTotalCount ?? rows.length);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
} else if (includeCount) {
|
|
490
|
+
if (includeExtraHeaders) {
|
|
491
|
+
const totalCount = (0, import_utils4.get)(result, `headers.${"wtt-total-count" /* TotalCount */}`, 0);
|
|
492
|
+
result.totalCount = Number(totalCount);
|
|
493
|
+
} else {
|
|
494
|
+
const listData = result.raw;
|
|
495
|
+
result.totalCount = listData.count;
|
|
496
|
+
result.raw = listData.rows;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
result.data = wrapItem ? result.raw.map(wrapItem) : result.raw;
|
|
500
|
+
return result;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// src/lazy-promise.ts
|
|
504
|
+
var wrapLazyPromise = (promiseFn, meta) => {
|
|
505
|
+
let promise;
|
|
506
|
+
const exec = () => {
|
|
507
|
+
if (!promise) {
|
|
508
|
+
promise = promiseFn();
|
|
509
|
+
}
|
|
510
|
+
return promise;
|
|
511
|
+
};
|
|
512
|
+
const prom = {
|
|
513
|
+
exec,
|
|
514
|
+
then(onFulfilled, onRejected) {
|
|
515
|
+
return exec().then(onFulfilled, onRejected);
|
|
516
|
+
},
|
|
517
|
+
catch(onRejected) {
|
|
518
|
+
return exec().catch(onRejected);
|
|
519
|
+
},
|
|
520
|
+
finally(onFinally) {
|
|
521
|
+
return exec().finally(onFinally);
|
|
522
|
+
},
|
|
523
|
+
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
524
|
+
return "LazyPromise";
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
Object.defineProperty(prom, Symbol.toStringTag, {
|
|
528
|
+
value: "Promise",
|
|
529
|
+
writable: false,
|
|
530
|
+
enumerable: false,
|
|
531
|
+
configurable: true
|
|
532
|
+
});
|
|
533
|
+
Object.assign(prom, meta);
|
|
534
|
+
return prom;
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
// src/services/request.ts
|
|
538
|
+
function makeRequest(execute, meta) {
|
|
539
|
+
return wrapLazyPromise(execute, meta);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/services/sub-ops.ts
|
|
543
|
+
var import_axios3 = require("axios");
|
|
544
|
+
function buildSubDocumentOps(ctx, id, sub) {
|
|
545
|
+
const { axios: axios2, basePath, modelName, queryPath, handleSuccess, handleError, _handleCallbacks, parentService } = ctx;
|
|
546
|
+
const asS = parentService;
|
|
547
|
+
return {
|
|
548
|
+
list: (axiosRequestConfig) => {
|
|
549
|
+
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
550
|
+
return makeRequest(
|
|
551
|
+
() => axios2.get(`${basePath}/${id}/${sub}`, (0, import_axios3.mergeConfig)(reqConfig, { params: {} })).then(handleSuccess).then((result) => {
|
|
552
|
+
result.totalCount = Array.isArray(result.raw) ? result.raw.length : 0;
|
|
553
|
+
result.data = Array.isArray(result.raw) ? result.raw.map((item) => Model.create(item, asS)) : [];
|
|
554
|
+
return result;
|
|
555
|
+
}).catch(handleError).then((res) => _handleCallbacks(res, throwOnError)),
|
|
556
|
+
{
|
|
557
|
+
__op: "listSub",
|
|
558
|
+
__query: {
|
|
559
|
+
target: "model",
|
|
560
|
+
name: modelName,
|
|
561
|
+
model: modelName,
|
|
562
|
+
op: "subList",
|
|
563
|
+
id,
|
|
564
|
+
sub,
|
|
565
|
+
filter: {},
|
|
566
|
+
args: {},
|
|
567
|
+
options: {}
|
|
568
|
+
},
|
|
569
|
+
__requestConfig: reqConfig,
|
|
570
|
+
__service: parentService
|
|
571
|
+
}
|
|
572
|
+
);
|
|
573
|
+
},
|
|
574
|
+
listAdvanced: (filter, args, axiosRequestConfig) => {
|
|
575
|
+
const select = args?.select;
|
|
576
|
+
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
577
|
+
return makeRequest(
|
|
578
|
+
() => axios2.post(`${basePath}/${id}/${sub}/${queryPath}`, { filter, select }, reqConfig).then(handleSuccess).then((result) => {
|
|
579
|
+
result.totalCount = Array.isArray(result.raw) ? result.raw.length : 0;
|
|
580
|
+
result.data = Array.isArray(result.raw) ? result.raw.map((item) => Model.create(item, asS)) : [];
|
|
581
|
+
return result;
|
|
582
|
+
}).catch(handleError).then(
|
|
583
|
+
(res) => _handleCallbacks(res, throwOnError)
|
|
584
|
+
),
|
|
585
|
+
{
|
|
586
|
+
__op: "listAdvancedSub",
|
|
587
|
+
__query: {
|
|
588
|
+
target: "model",
|
|
589
|
+
name: modelName,
|
|
590
|
+
model: modelName,
|
|
591
|
+
op: "subList",
|
|
592
|
+
id,
|
|
593
|
+
sub,
|
|
594
|
+
filter,
|
|
595
|
+
args: { select },
|
|
596
|
+
options: {}
|
|
597
|
+
},
|
|
598
|
+
__requestConfig: reqConfig,
|
|
599
|
+
__service: parentService
|
|
600
|
+
}
|
|
601
|
+
);
|
|
602
|
+
},
|
|
603
|
+
read: (subId, axiosRequestConfig) => {
|
|
604
|
+
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
605
|
+
return makeRequest(
|
|
606
|
+
() => axios2.get(`${basePath}/${id}/${sub}/${subId}`, (0, import_axios3.mergeConfig)(reqConfig, { params: {} })).then(handleSuccess).then((result) => {
|
|
607
|
+
result.data = result.success ? Model.create(result.raw, asS) : null;
|
|
608
|
+
return result;
|
|
609
|
+
}).catch(handleError).then((res) => _handleCallbacks(res, throwOnError)),
|
|
610
|
+
{
|
|
611
|
+
__op: "readSub",
|
|
612
|
+
__query: {
|
|
613
|
+
target: "model",
|
|
614
|
+
name: modelName,
|
|
615
|
+
model: modelName,
|
|
616
|
+
op: "subRead",
|
|
617
|
+
id,
|
|
618
|
+
sub,
|
|
619
|
+
subId,
|
|
620
|
+
args: {},
|
|
621
|
+
options: {}
|
|
622
|
+
},
|
|
623
|
+
__requestConfig: reqConfig,
|
|
624
|
+
__service: parentService
|
|
625
|
+
}
|
|
626
|
+
);
|
|
627
|
+
},
|
|
628
|
+
readAdvanced: (subId, args, axiosRequestConfig) => {
|
|
629
|
+
const { select, populate } = args ?? {};
|
|
630
|
+
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
631
|
+
return makeRequest(
|
|
632
|
+
() => axios2.post(`${basePath}/${id}/${sub}/${subId}/${queryPath}`, { select, populate }, reqConfig).then(handleSuccess).then((result) => {
|
|
633
|
+
result.data = result.success ? Model.create(result.raw, asS) : null;
|
|
634
|
+
return result;
|
|
635
|
+
}).catch(handleError).then(
|
|
636
|
+
(res) => _handleCallbacks(res, throwOnError)
|
|
637
|
+
),
|
|
638
|
+
{
|
|
639
|
+
__op: "readAdvancedSub",
|
|
640
|
+
__query: {
|
|
641
|
+
target: "model",
|
|
642
|
+
name: modelName,
|
|
643
|
+
model: modelName,
|
|
644
|
+
op: "subRead",
|
|
645
|
+
id,
|
|
646
|
+
sub,
|
|
647
|
+
subId,
|
|
648
|
+
args: { select, populate },
|
|
649
|
+
options: {}
|
|
650
|
+
},
|
|
651
|
+
__requestConfig: reqConfig,
|
|
652
|
+
__service: parentService
|
|
653
|
+
}
|
|
654
|
+
);
|
|
655
|
+
},
|
|
656
|
+
update: (subId, data, axiosRequestConfig) => {
|
|
657
|
+
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
658
|
+
return makeRequest(
|
|
659
|
+
() => axios2.patch(`${basePath}/${id}/${sub}/${subId}`, data, (0, import_axios3.mergeConfig)(reqConfig, { params: {} })).then(handleSuccess).then((result) => {
|
|
660
|
+
result.data = result.success ? Model.create(result.raw, asS) : null;
|
|
661
|
+
return result;
|
|
662
|
+
}).catch(handleError).then((res) => _handleCallbacks(res, throwOnError)),
|
|
663
|
+
{
|
|
664
|
+
__op: "updateSub",
|
|
665
|
+
__query: {
|
|
666
|
+
target: "model",
|
|
667
|
+
name: modelName,
|
|
668
|
+
model: modelName,
|
|
669
|
+
op: "subUpdate",
|
|
670
|
+
id,
|
|
671
|
+
sub,
|
|
672
|
+
subId,
|
|
673
|
+
data,
|
|
674
|
+
options: {}
|
|
675
|
+
},
|
|
676
|
+
__requestConfig: reqConfig,
|
|
677
|
+
__service: parentService
|
|
678
|
+
}
|
|
679
|
+
);
|
|
680
|
+
},
|
|
681
|
+
bulkUpdate: (data, axiosRequestConfig) => {
|
|
682
|
+
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
683
|
+
return makeRequest(
|
|
684
|
+
() => axios2.patch(`${basePath}/${id}/${sub}`, data, (0, import_axios3.mergeConfig)(reqConfig, { params: {} })).then(handleSuccess).then((result) => {
|
|
685
|
+
result.data = Array.isArray(result.raw) ? result.raw.map((item) => Model.create(item, asS)) : [];
|
|
686
|
+
return result;
|
|
687
|
+
}).catch(handleError).then((res) => _handleCallbacks(res, throwOnError)),
|
|
688
|
+
{
|
|
689
|
+
__op: "bulkUpdateSub",
|
|
690
|
+
__query: {
|
|
691
|
+
target: "model",
|
|
692
|
+
name: modelName,
|
|
693
|
+
model: modelName,
|
|
694
|
+
op: "subBulkUpdate",
|
|
695
|
+
id,
|
|
696
|
+
sub,
|
|
697
|
+
data,
|
|
698
|
+
options: {}
|
|
699
|
+
},
|
|
700
|
+
__requestConfig: reqConfig,
|
|
701
|
+
__service: parentService
|
|
702
|
+
}
|
|
703
|
+
);
|
|
704
|
+
},
|
|
705
|
+
create: (data, axiosRequestConfig) => {
|
|
706
|
+
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
707
|
+
return makeRequest(
|
|
708
|
+
() => axios2.post(`${basePath}/${id}/${sub}`, data, (0, import_axios3.mergeConfig)(reqConfig, { params: {} })).then(handleSuccess).then((result) => {
|
|
709
|
+
result.data = result.success ? Model.create(result.raw, asS) : null;
|
|
710
|
+
return result;
|
|
711
|
+
}).catch(handleError).then((res) => _handleCallbacks(res, throwOnError)),
|
|
712
|
+
{
|
|
713
|
+
__op: "createSub",
|
|
714
|
+
__query: { target: "model", name: modelName, model: modelName, op: "subCreate", id, sub, data, options: {} },
|
|
715
|
+
__requestConfig: reqConfig,
|
|
716
|
+
__service: parentService
|
|
717
|
+
}
|
|
718
|
+
);
|
|
719
|
+
},
|
|
720
|
+
delete: (subId, axiosRequestConfig) => {
|
|
721
|
+
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
722
|
+
return makeRequest(
|
|
723
|
+
() => axios2.delete(`${basePath}/${id}/${sub}/${subId}`, reqConfig).then(handleSuccess).then((result) => {
|
|
724
|
+
result.data = result.raw;
|
|
725
|
+
return result;
|
|
726
|
+
}).catch(handleError).then((res) => _handleCallbacks(res, throwOnError)),
|
|
727
|
+
{
|
|
728
|
+
__op: "deleteSub",
|
|
729
|
+
__query: { target: "model", name: modelName, model: modelName, op: "subDelete", id, sub, subId },
|
|
730
|
+
__requestConfig: reqConfig,
|
|
731
|
+
__service: parentService
|
|
732
|
+
}
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
}
|
|
468
737
|
|
|
469
738
|
// src/services/model-service.ts
|
|
470
739
|
var ModelService = class extends Service {
|
|
@@ -494,6 +763,9 @@ var ModelService = class extends Service {
|
|
|
494
763
|
"upsertAdvancedOptions"
|
|
495
764
|
].forEach((key) => setDefaultObjectProp(this._defaults, key, {}));
|
|
496
765
|
}
|
|
766
|
+
// ---------------------------------------------------------------------------
|
|
767
|
+
// Collection operations
|
|
768
|
+
// ---------------------------------------------------------------------------
|
|
497
769
|
list(args, options, axiosRequestConfig) {
|
|
498
770
|
const {
|
|
499
771
|
skip = this._defaults.listArgs.skip,
|
|
@@ -511,10 +783,10 @@ var ModelService = class extends Service {
|
|
|
511
783
|
} = options ?? {};
|
|
512
784
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
513
785
|
reqConfig.headers = this.updateHeaders(reqConfig.headers, { ignoreCache });
|
|
514
|
-
|
|
786
|
+
return makeRequest(
|
|
515
787
|
() => this._axios.get(
|
|
516
788
|
this._basePath,
|
|
517
|
-
(0,
|
|
789
|
+
(0, import_axios4.mergeConfig)(reqConfig, {
|
|
518
790
|
params: {
|
|
519
791
|
skip,
|
|
520
792
|
limit,
|
|
@@ -526,8 +798,12 @@ var ModelService = class extends Service {
|
|
|
526
798
|
include_extra_headers: includeExtraHeaders
|
|
527
799
|
}
|
|
528
800
|
})
|
|
529
|
-
).then(this.handleSuccess).then((
|
|
530
|
-
return
|
|
801
|
+
).then(this.handleSuccess).then((result) => {
|
|
802
|
+
return processListResult(
|
|
803
|
+
result,
|
|
804
|
+
{ includeCount, includeExtraHeaders },
|
|
805
|
+
(item) => Model.create(item, this)
|
|
806
|
+
);
|
|
531
807
|
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
532
808
|
{
|
|
533
809
|
__op: "list",
|
|
@@ -538,19 +814,13 @@ var ModelService = class extends Service {
|
|
|
538
814
|
op: "list",
|
|
539
815
|
filter: {},
|
|
540
816
|
args: { skip, limit, page, pageSize },
|
|
541
|
-
options: {
|
|
542
|
-
skim,
|
|
543
|
-
includePermissions,
|
|
544
|
-
includeCount,
|
|
545
|
-
includeExtraHeaders
|
|
546
|
-
},
|
|
817
|
+
options: { skim, includePermissions, includeCount, includeExtraHeaders },
|
|
547
818
|
sqOptions: sq
|
|
548
819
|
},
|
|
549
820
|
__requestConfig: reqConfig,
|
|
550
821
|
__service: this
|
|
551
822
|
}
|
|
552
823
|
);
|
|
553
|
-
return result;
|
|
554
824
|
}
|
|
555
825
|
listAdvanced(filter, args, options, axiosRequestConfig) {
|
|
556
826
|
const {
|
|
@@ -576,7 +846,7 @@ var ModelService = class extends Service {
|
|
|
576
846
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
577
847
|
reqConfig.headers = this.updateHeaders(reqConfig.headers, { ignoreCache });
|
|
578
848
|
const _filter = replaceSubQuery(filter);
|
|
579
|
-
|
|
849
|
+
return makeRequest(
|
|
580
850
|
() => this._axios.post(
|
|
581
851
|
`${this._basePath}/${this._queryPath}`,
|
|
582
852
|
{
|
|
@@ -590,17 +860,15 @@ var ModelService = class extends Service {
|
|
|
590
860
|
page,
|
|
591
861
|
pageSize,
|
|
592
862
|
tasks,
|
|
593
|
-
options: {
|
|
594
|
-
skim,
|
|
595
|
-
includePermissions,
|
|
596
|
-
includeCount,
|
|
597
|
-
includeExtraHeaders,
|
|
598
|
-
populateAccess
|
|
599
|
-
}
|
|
863
|
+
options: { skim, includePermissions, includeCount, includeExtraHeaders, populateAccess }
|
|
600
864
|
},
|
|
601
865
|
reqConfig
|
|
602
|
-
).then(this.handleSuccess).then((
|
|
603
|
-
return
|
|
866
|
+
).then(this.handleSuccess).then((result) => {
|
|
867
|
+
return processListResult(
|
|
868
|
+
result,
|
|
869
|
+
{ includeCount, includeExtraHeaders },
|
|
870
|
+
(item) => Model.create(item, this)
|
|
871
|
+
);
|
|
604
872
|
}).catch(this.handleError).then(
|
|
605
873
|
(res) => this._handleCallbacks(res, throwOnError)
|
|
606
874
|
),
|
|
@@ -613,829 +881,520 @@ var ModelService = class extends Service {
|
|
|
613
881
|
op: "list",
|
|
614
882
|
filter: _filter,
|
|
615
883
|
args: { select, sort, populate, include, skip, limit, page, pageSize, tasks },
|
|
616
|
-
options: {
|
|
617
|
-
skim,
|
|
618
|
-
includePermissions,
|
|
619
|
-
includeCount,
|
|
620
|
-
includeExtraHeaders,
|
|
621
|
-
populateAccess
|
|
622
|
-
},
|
|
884
|
+
options: { skim, includePermissions, includeCount, includeExtraHeaders, populateAccess },
|
|
623
885
|
sqOptions: sq
|
|
624
886
|
},
|
|
625
887
|
__requestConfig: reqConfig,
|
|
626
888
|
__service: this
|
|
627
889
|
}
|
|
628
890
|
);
|
|
629
|
-
return result;
|
|
630
891
|
}
|
|
631
|
-
|
|
632
|
-
const {
|
|
633
|
-
includePermissions = this._defaults.readOptions.includePermissions ?? true,
|
|
634
|
-
tryList = this._defaults.readOptions.tryList ?? true,
|
|
635
|
-
ignoreCache = this._defaults.readOptions.ignoreCache ?? false,
|
|
636
|
-
sq
|
|
637
|
-
} = options ?? {};
|
|
892
|
+
create(data, options, axiosRequestConfig) {
|
|
893
|
+
const { includePermissions = this._defaults.createOptions.includePermissions ?? true } = options ?? {};
|
|
638
894
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
() => this._axios.
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
params: {
|
|
645
|
-
include_permissions: includePermissions,
|
|
646
|
-
try_list: tryList
|
|
647
|
-
}
|
|
648
|
-
})
|
|
649
|
-
).then(this.handleSuccess).then((result2) => {
|
|
650
|
-
result2.data = result2.success ? Model.create(result2.raw, this) : null;
|
|
651
|
-
return result2;
|
|
895
|
+
(0, import_utils5.set)(reqConfig, `headers.${CACHE_HEADER}`, "false");
|
|
896
|
+
return makeRequest(
|
|
897
|
+
() => this._axios.post(this._basePath, data, (0, import_axios4.mergeConfig)(reqConfig, { params: { include_permissions: includePermissions } })).then(this.handleSuccess).then((result) => {
|
|
898
|
+
result.data = result.success ? Model.create(result.raw, this) : null;
|
|
899
|
+
return result;
|
|
652
900
|
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
653
901
|
{
|
|
654
|
-
__op: "
|
|
902
|
+
__op: "create",
|
|
655
903
|
__query: {
|
|
656
904
|
target: "model",
|
|
657
905
|
name: this._modelName,
|
|
658
906
|
model: this._modelName,
|
|
659
|
-
op: "
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
options: {
|
|
663
|
-
includePermissions,
|
|
664
|
-
tryList
|
|
665
|
-
},
|
|
666
|
-
sqOptions: sq
|
|
907
|
+
op: "create",
|
|
908
|
+
data,
|
|
909
|
+
options: { includePermissions }
|
|
667
910
|
},
|
|
668
911
|
__requestConfig: reqConfig,
|
|
669
912
|
__service: this
|
|
670
913
|
}
|
|
671
914
|
);
|
|
672
|
-
return result;
|
|
673
915
|
}
|
|
674
|
-
|
|
675
|
-
const {
|
|
676
|
-
|
|
677
|
-
include = this._defaults.readAdvancedArgs.include,
|
|
678
|
-
tasks = this._defaults.readAdvancedArgs.tasks
|
|
679
|
-
} = args ?? {};
|
|
680
|
-
const select = args?.select ?? this._defaults.readAdvancedArgs.select;
|
|
916
|
+
createAdvanced(data, args, options, axiosRequestConfig) {
|
|
917
|
+
const { populate = this._defaults.createAdvancedArgs.populate, tasks = this._defaults.createAdvancedArgs.tasks } = args ?? {};
|
|
918
|
+
const select = args?.select ?? this._defaults.createAdvancedArgs.select;
|
|
681
919
|
const {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
tryList = this._defaults.readAdvancedOptions.tryList ?? true,
|
|
685
|
-
populateAccess = this._defaults.readAdvancedOptions.populateAccess,
|
|
686
|
-
ignoreCache = this._defaults.readAdvancedOptions.ignoreCache ?? false,
|
|
687
|
-
sq
|
|
920
|
+
includePermissions = this._defaults.createAdvancedOptions.includePermissions ?? true,
|
|
921
|
+
populateAccess = this._defaults.createAdvancedOptions.populateAccess
|
|
688
922
|
} = options ?? {};
|
|
689
923
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
690
|
-
|
|
691
|
-
|
|
924
|
+
(0, import_utils5.set)(reqConfig, `headers.${CACHE_HEADER}`, "false");
|
|
925
|
+
return makeRequest(
|
|
692
926
|
() => this._axios.post(
|
|
693
|
-
`${this._basePath}/${this.
|
|
694
|
-
{
|
|
695
|
-
select,
|
|
696
|
-
populate,
|
|
697
|
-
include,
|
|
698
|
-
tasks,
|
|
699
|
-
options: {
|
|
700
|
-
skim,
|
|
701
|
-
includePermissions,
|
|
702
|
-
tryList,
|
|
703
|
-
populateAccess
|
|
704
|
-
}
|
|
705
|
-
},
|
|
927
|
+
`${this._basePath}/${this._mutationPath}`,
|
|
928
|
+
{ data, select, populate, tasks, options: { includePermissions, populateAccess } },
|
|
706
929
|
reqConfig
|
|
707
|
-
).then(this.handleSuccess).then((
|
|
708
|
-
|
|
709
|
-
return
|
|
930
|
+
).then(this.handleSuccess).then((result) => {
|
|
931
|
+
result.data = result.success ? Model.create(result.raw, this) : null;
|
|
932
|
+
return result;
|
|
710
933
|
}).catch(this.handleError).then(
|
|
711
934
|
(res) => this._handleCallbacks(res, throwOnError)
|
|
712
935
|
),
|
|
713
936
|
{
|
|
714
|
-
__op: "
|
|
937
|
+
__op: "createAdvanced",
|
|
715
938
|
__query: {
|
|
716
939
|
target: "model",
|
|
717
940
|
name: this._modelName,
|
|
718
941
|
model: this._modelName,
|
|
719
|
-
op: "
|
|
720
|
-
|
|
721
|
-
args: { select, populate,
|
|
722
|
-
options: {
|
|
723
|
-
skim,
|
|
724
|
-
includePermissions,
|
|
725
|
-
tryList,
|
|
726
|
-
populateAccess
|
|
727
|
-
},
|
|
728
|
-
sqOptions: sq
|
|
942
|
+
op: "create",
|
|
943
|
+
data,
|
|
944
|
+
args: { select, populate, tasks },
|
|
945
|
+
options: { includePermissions, populateAccess }
|
|
729
946
|
},
|
|
730
947
|
__requestConfig: reqConfig,
|
|
731
948
|
__service: this
|
|
732
949
|
}
|
|
733
950
|
);
|
|
734
|
-
return result;
|
|
735
951
|
}
|
|
736
|
-
|
|
737
|
-
const {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
952
|
+
upsert(data, options, axiosRequestConfig) {
|
|
953
|
+
const { returningAll = this._defaults.upsertOptions.returningAll ?? true } = options ?? {};
|
|
954
|
+
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
955
|
+
(0, import_utils5.set)(reqConfig, `headers.${CACHE_HEADER}`, "false");
|
|
956
|
+
return makeRequest(
|
|
957
|
+
() => this._axios.put(this._basePath, data, (0, import_axios4.mergeConfig)(reqConfig, { params: { returning_all: returningAll } })).then(this.handleSuccess).then((result) => {
|
|
958
|
+
result.data = result.success ? Model.create(result.raw, this) : null;
|
|
959
|
+
return result;
|
|
960
|
+
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
961
|
+
{
|
|
962
|
+
__op: "upsert",
|
|
963
|
+
__query: {
|
|
964
|
+
target: "model",
|
|
965
|
+
name: this._modelName,
|
|
966
|
+
model: this._modelName,
|
|
967
|
+
op: "upsert",
|
|
968
|
+
data,
|
|
969
|
+
options: { returningAll }
|
|
970
|
+
},
|
|
971
|
+
__requestConfig: reqConfig,
|
|
972
|
+
__service: this
|
|
973
|
+
}
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
upsertAdvanced(data, args, options, axiosRequestConfig) {
|
|
977
|
+
const { populate = this._defaults.upsertAdvancedArgs.populate, tasks = this._defaults.upsertAdvancedArgs.tasks } = args ?? {};
|
|
978
|
+
const select = args?.select ?? this._defaults.upsertAdvancedArgs.select;
|
|
744
979
|
const {
|
|
745
|
-
|
|
746
|
-
includePermissions = this._defaults.
|
|
747
|
-
|
|
748
|
-
populateAccess = this._defaults.readAdvancedOptions.populateAccess,
|
|
749
|
-
ignoreCache = this._defaults.readAdvancedOptions.ignoreCache ?? false,
|
|
750
|
-
sq
|
|
980
|
+
returningAll = this._defaults.upsertAdvancedOptions.returningAll ?? true,
|
|
981
|
+
includePermissions = this._defaults.upsertAdvancedOptions.includePermissions ?? true,
|
|
982
|
+
populateAccess = this._defaults.upsertAdvancedOptions.populateAccess
|
|
751
983
|
} = options ?? {};
|
|
752
984
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
`${this._basePath}/${this._queryPath}/__filter`,
|
|
985
|
+
(0, import_utils5.set)(reqConfig, `headers.${CACHE_HEADER}`, "false");
|
|
986
|
+
return makeRequest(
|
|
987
|
+
() => this._axios.put(
|
|
988
|
+
`${this._basePath}/${this._mutationPath}`,
|
|
758
989
|
{
|
|
759
|
-
|
|
990
|
+
data,
|
|
760
991
|
select,
|
|
761
|
-
sort,
|
|
762
992
|
populate,
|
|
763
|
-
include,
|
|
764
993
|
tasks,
|
|
765
|
-
options: {
|
|
766
|
-
skim,
|
|
767
|
-
includePermissions,
|
|
768
|
-
tryList,
|
|
769
|
-
populateAccess
|
|
770
|
-
}
|
|
994
|
+
options: { returningAll, includePermissions, populateAccess }
|
|
771
995
|
},
|
|
772
996
|
reqConfig
|
|
773
|
-
).then(this.handleSuccess).then((
|
|
774
|
-
|
|
775
|
-
return
|
|
997
|
+
).then(this.handleSuccess).then((result) => {
|
|
998
|
+
result.data = result.success ? Model.create(result.raw, this) : null;
|
|
999
|
+
return result;
|
|
776
1000
|
}).catch(this.handleError).then(
|
|
777
1001
|
(res) => this._handleCallbacks(res, throwOnError)
|
|
778
1002
|
),
|
|
779
1003
|
{
|
|
780
|
-
__op: "
|
|
1004
|
+
__op: "upsertAdvanced",
|
|
781
1005
|
__query: {
|
|
782
1006
|
target: "model",
|
|
783
1007
|
name: this._modelName,
|
|
784
1008
|
model: this._modelName,
|
|
785
|
-
op: "
|
|
786
|
-
|
|
787
|
-
args: { select,
|
|
788
|
-
options: {
|
|
789
|
-
skim,
|
|
790
|
-
includePermissions,
|
|
791
|
-
tryList,
|
|
792
|
-
populateAccess
|
|
793
|
-
},
|
|
794
|
-
sqOptions: sq
|
|
1009
|
+
op: "upsert",
|
|
1010
|
+
data,
|
|
1011
|
+
args: { select, populate, tasks },
|
|
1012
|
+
options: { returningAll, includePermissions, populateAccess }
|
|
795
1013
|
},
|
|
796
1014
|
__requestConfig: reqConfig,
|
|
797
1015
|
__service: this
|
|
798
1016
|
}
|
|
799
1017
|
);
|
|
800
|
-
return result;
|
|
801
1018
|
}
|
|
802
|
-
|
|
1019
|
+
delete(identifier, axiosRequestConfig) {
|
|
803
1020
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
804
1021
|
(0, import_utils5.set)(reqConfig, `headers.${CACHE_HEADER}`, "false");
|
|
805
|
-
|
|
806
|
-
() => this._axios.
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
return result2;
|
|
1022
|
+
return makeRequest(
|
|
1023
|
+
() => this._axios.delete(`${this._basePath}/${identifier}`, reqConfig).then(this.handleSuccess).then((result) => {
|
|
1024
|
+
result.data = result.raw;
|
|
1025
|
+
return result;
|
|
810
1026
|
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
811
1027
|
{
|
|
812
|
-
__op: "
|
|
1028
|
+
__op: "delete",
|
|
813
1029
|
__query: {
|
|
814
1030
|
target: "model",
|
|
815
1031
|
name: this._modelName,
|
|
816
1032
|
model: this._modelName,
|
|
817
|
-
op: "
|
|
1033
|
+
op: "delete",
|
|
1034
|
+
id: identifier
|
|
818
1035
|
},
|
|
819
1036
|
__requestConfig: reqConfig,
|
|
820
1037
|
__service: this
|
|
821
1038
|
}
|
|
822
1039
|
);
|
|
823
|
-
return result;
|
|
824
1040
|
}
|
|
825
|
-
|
|
826
|
-
const { includePermissions = this._defaults.createOptions.includePermissions ?? true } = options ?? {};
|
|
1041
|
+
new(axiosRequestConfig) {
|
|
827
1042
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
828
1043
|
(0, import_utils5.set)(reqConfig, `headers.${CACHE_HEADER}`, "false");
|
|
829
|
-
|
|
830
|
-
() => this._axios.
|
|
831
|
-
|
|
832
|
-
|
|
1044
|
+
return makeRequest(
|
|
1045
|
+
() => this._axios.get(`${this._basePath}/new`, reqConfig).then(this.handleSuccess).then((result) => {
|
|
1046
|
+
delete result.raw._id;
|
|
1047
|
+
result.data = result.success ? Model.create(result.raw, this) : null;
|
|
1048
|
+
return result;
|
|
833
1049
|
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
834
1050
|
{
|
|
835
|
-
__op: "
|
|
1051
|
+
__op: "new",
|
|
836
1052
|
__query: {
|
|
837
1053
|
target: "model",
|
|
838
1054
|
name: this._modelName,
|
|
839
1055
|
model: this._modelName,
|
|
840
|
-
op: "
|
|
841
|
-
data,
|
|
842
|
-
options: {
|
|
843
|
-
includePermissions
|
|
844
|
-
}
|
|
1056
|
+
op: "new"
|
|
845
1057
|
},
|
|
846
1058
|
__requestConfig: reqConfig,
|
|
847
1059
|
__service: this
|
|
848
1060
|
}
|
|
849
1061
|
);
|
|
850
|
-
return result;
|
|
851
1062
|
}
|
|
852
|
-
|
|
853
|
-
const { populate = this._defaults.createAdvancedArgs.populate, tasks = this._defaults.createAdvancedArgs.tasks } = args ?? {};
|
|
854
|
-
const select = args?.select ?? this._defaults.createAdvancedArgs.select;
|
|
855
|
-
const {
|
|
856
|
-
includePermissions = this._defaults.createAdvancedOptions.includePermissions ?? true,
|
|
857
|
-
populateAccess = this._defaults.createAdvancedOptions.populateAccess
|
|
858
|
-
} = options ?? {};
|
|
1063
|
+
distinct(field, axiosRequestConfig) {
|
|
859
1064
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
reqConfig
|
|
866
|
-
).then(this.handleSuccess).then((result2) => {
|
|
867
|
-
result2.data = result2.success ? Model.create(result2.raw, this) : null;
|
|
868
|
-
return result2;
|
|
869
|
-
}).catch(this.handleError).then(
|
|
870
|
-
(res) => this._handleCallbacks(res, throwOnError)
|
|
871
|
-
),
|
|
1065
|
+
return makeRequest(
|
|
1066
|
+
() => this._axios.get(`${this._basePath}/distinct/${field}`, reqConfig).then(this.handleSuccess).then((result) => {
|
|
1067
|
+
result.data = result.raw;
|
|
1068
|
+
return result;
|
|
1069
|
+
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
872
1070
|
{
|
|
873
|
-
__op: "
|
|
1071
|
+
__op: "distinct",
|
|
874
1072
|
__query: {
|
|
875
1073
|
target: "model",
|
|
876
1074
|
name: this._modelName,
|
|
877
1075
|
model: this._modelName,
|
|
878
|
-
op: "
|
|
879
|
-
|
|
880
|
-
args: { select, populate, tasks },
|
|
881
|
-
options: {
|
|
882
|
-
includePermissions,
|
|
883
|
-
populateAccess
|
|
884
|
-
}
|
|
1076
|
+
op: "distinct",
|
|
1077
|
+
field
|
|
885
1078
|
},
|
|
886
1079
|
__requestConfig: reqConfig,
|
|
887
1080
|
__service: this
|
|
888
1081
|
}
|
|
889
1082
|
);
|
|
890
|
-
return result;
|
|
891
1083
|
}
|
|
892
|
-
|
|
893
|
-
const { returningAll = this._defaults.updateOptions.returningAll ?? true } = options ?? {};
|
|
1084
|
+
distinctAdvanced(field, conditions, axiosRequestConfig) {
|
|
894
1085
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
data,
|
|
900
|
-
(0, import_axios2.mergeConfig)(reqConfig, { params: { returning_all: returningAll } })
|
|
901
|
-
).then(this.handleSuccess).then((result2) => {
|
|
902
|
-
result2.data = result2.success ? Model.create(result2.raw, this) : null;
|
|
903
|
-
return result2;
|
|
1086
|
+
return makeRequest(
|
|
1087
|
+
() => this._axios.post(`${this._basePath}/distinct/${field}`, conditions, reqConfig).then(this.handleSuccess).then((result) => {
|
|
1088
|
+
result.data = result.raw;
|
|
1089
|
+
return result;
|
|
904
1090
|
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
905
1091
|
{
|
|
906
|
-
__op: "
|
|
1092
|
+
__op: "distinctAdvanced",
|
|
907
1093
|
__query: {
|
|
908
1094
|
target: "model",
|
|
909
1095
|
name: this._modelName,
|
|
910
1096
|
model: this._modelName,
|
|
911
|
-
op: "
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
options: {
|
|
915
|
-
returningAll
|
|
916
|
-
}
|
|
1097
|
+
op: "distinct",
|
|
1098
|
+
field,
|
|
1099
|
+
filter: conditions
|
|
917
1100
|
},
|
|
918
1101
|
__requestConfig: reqConfig,
|
|
919
1102
|
__service: this
|
|
920
1103
|
}
|
|
921
1104
|
);
|
|
922
|
-
return result;
|
|
923
1105
|
}
|
|
924
|
-
|
|
925
|
-
const { populate = this._defaults.updateAdvancedArgs.populate, tasks = this._defaults.updateAdvancedArgs.tasks } = args ?? {};
|
|
926
|
-
const select = args?.select ?? this._defaults.updateAdvancedArgs.select;
|
|
927
|
-
const {
|
|
928
|
-
returningAll = this._defaults.updateAdvancedOptions.returningAll ?? true,
|
|
929
|
-
includePermissions = this._defaults.updateAdvancedOptions.includePermissions ?? true,
|
|
930
|
-
populateAccess = this._defaults.updateAdvancedOptions.populateAccess
|
|
931
|
-
} = options ?? {};
|
|
1106
|
+
count(axiosRequestConfig) {
|
|
932
1107
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
data,
|
|
939
|
-
select,
|
|
940
|
-
populate,
|
|
941
|
-
tasks,
|
|
942
|
-
options: { returningAll, includePermissions, populateAccess }
|
|
943
|
-
},
|
|
944
|
-
reqConfig
|
|
945
|
-
).then(this.handleSuccess).then((result2) => {
|
|
946
|
-
result2.data = result2.success ? Model.create(result2.raw, this) : null;
|
|
947
|
-
return result2;
|
|
948
|
-
}).catch(this.handleError).then(
|
|
949
|
-
(res) => this._handleCallbacks(res, throwOnError)
|
|
950
|
-
),
|
|
1108
|
+
return makeRequest(
|
|
1109
|
+
() => this._axios.get(`${this._basePath}/count`, reqConfig).then(this.handleSuccess).then((result) => {
|
|
1110
|
+
result.data = result.raw;
|
|
1111
|
+
return result;
|
|
1112
|
+
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
951
1113
|
{
|
|
952
|
-
__op: "
|
|
1114
|
+
__op: "count",
|
|
953
1115
|
__query: {
|
|
954
1116
|
target: "model",
|
|
955
1117
|
name: this._modelName,
|
|
956
1118
|
model: this._modelName,
|
|
957
|
-
op: "
|
|
958
|
-
id: identifier,
|
|
959
|
-
data,
|
|
960
|
-
args: { select, populate, tasks },
|
|
961
|
-
options: {
|
|
962
|
-
returningAll,
|
|
963
|
-
includePermissions,
|
|
964
|
-
populateAccess
|
|
965
|
-
}
|
|
1119
|
+
op: "count"
|
|
966
1120
|
},
|
|
967
1121
|
__requestConfig: reqConfig,
|
|
968
1122
|
__service: this
|
|
969
1123
|
}
|
|
970
1124
|
);
|
|
971
|
-
return result;
|
|
972
1125
|
}
|
|
973
|
-
|
|
974
|
-
const {
|
|
1126
|
+
countAdvanced(filter, args, axiosRequestConfig) {
|
|
1127
|
+
const { access } = args ?? {};
|
|
975
1128
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
return result2;
|
|
1129
|
+
return makeRequest(
|
|
1130
|
+
() => this._axios.post(`${this._basePath}/count`, { filter, options: { access } }, reqConfig).then(this.handleSuccess).then((result) => {
|
|
1131
|
+
result.data = result.raw;
|
|
1132
|
+
return result;
|
|
981
1133
|
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
982
1134
|
{
|
|
983
|
-
__op: "
|
|
1135
|
+
__op: "countAdvanced",
|
|
984
1136
|
__query: {
|
|
985
1137
|
target: "model",
|
|
986
1138
|
name: this._modelName,
|
|
987
1139
|
model: this._modelName,
|
|
988
|
-
op: "
|
|
989
|
-
|
|
990
|
-
options: {
|
|
991
|
-
returningAll
|
|
992
|
-
}
|
|
1140
|
+
op: "count",
|
|
1141
|
+
filter,
|
|
1142
|
+
options: { access }
|
|
993
1143
|
},
|
|
994
1144
|
__requestConfig: reqConfig,
|
|
995
1145
|
__service: this
|
|
996
1146
|
}
|
|
997
1147
|
);
|
|
998
|
-
return result;
|
|
999
1148
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1149
|
+
// ---------------------------------------------------------------------------
|
|
1150
|
+
// Document operations
|
|
1151
|
+
// ---------------------------------------------------------------------------
|
|
1152
|
+
read(identifier, options, axiosRequestConfig) {
|
|
1003
1153
|
const {
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1154
|
+
includePermissions = this._defaults.readOptions.includePermissions ?? true,
|
|
1155
|
+
tryList = this._defaults.readOptions.tryList ?? true,
|
|
1156
|
+
ignoreCache = this._defaults.readOptions.ignoreCache ?? false,
|
|
1157
|
+
sq
|
|
1007
1158
|
} = options ?? {};
|
|
1008
1159
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
() => this._axios.
|
|
1012
|
-
`${this._basePath}/${
|
|
1013
|
-
{
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
},
|
|
1020
|
-
reqConfig
|
|
1021
|
-
).then(this.handleSuccess).then((result2) => {
|
|
1022
|
-
result2.data = result2.success ? Model.create(result2.raw, this) : null;
|
|
1023
|
-
return result2;
|
|
1024
|
-
}).catch(this.handleError).then(
|
|
1025
|
-
(res) => this._handleCallbacks(res, throwOnError)
|
|
1026
|
-
),
|
|
1027
|
-
{
|
|
1028
|
-
__op: "upsertAdvanced",
|
|
1029
|
-
__query: {
|
|
1030
|
-
target: "model",
|
|
1031
|
-
name: this._modelName,
|
|
1032
|
-
model: this._modelName,
|
|
1033
|
-
op: "upsert",
|
|
1034
|
-
data,
|
|
1035
|
-
args: { select, populate, tasks },
|
|
1036
|
-
options: {
|
|
1037
|
-
returningAll,
|
|
1038
|
-
includePermissions,
|
|
1039
|
-
populateAccess
|
|
1040
|
-
}
|
|
1041
|
-
},
|
|
1042
|
-
__requestConfig: reqConfig,
|
|
1043
|
-
__service: this
|
|
1044
|
-
}
|
|
1045
|
-
);
|
|
1046
|
-
return result;
|
|
1047
|
-
}
|
|
1048
|
-
delete(identifier, axiosRequestConfig) {
|
|
1049
|
-
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1050
|
-
(0, import_utils5.set)(reqConfig, `headers.${CACHE_HEADER}`, "false");
|
|
1051
|
-
const result = wrapLazyPromise(
|
|
1052
|
-
() => this._axios.delete(`${this._basePath}/${identifier}`, reqConfig).then(this.handleSuccess).then((result2) => {
|
|
1053
|
-
result2.data = result2.raw;
|
|
1054
|
-
return result2;
|
|
1160
|
+
reqConfig.headers = this.updateHeaders(reqConfig.headers, { ignoreCache });
|
|
1161
|
+
return makeRequest(
|
|
1162
|
+
() => this._axios.get(
|
|
1163
|
+
`${this._basePath}/${identifier}`,
|
|
1164
|
+
(0, import_axios4.mergeConfig)(reqConfig, {
|
|
1165
|
+
params: { include_permissions: includePermissions, try_list: tryList }
|
|
1166
|
+
})
|
|
1167
|
+
).then(this.handleSuccess).then((result) => {
|
|
1168
|
+
result.data = result.success ? Model.create(result.raw, this) : null;
|
|
1169
|
+
return result;
|
|
1055
1170
|
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
1056
1171
|
{
|
|
1057
|
-
__op: "
|
|
1172
|
+
__op: "read",
|
|
1058
1173
|
__query: {
|
|
1059
1174
|
target: "model",
|
|
1060
1175
|
name: this._modelName,
|
|
1061
1176
|
model: this._modelName,
|
|
1062
|
-
op: "
|
|
1063
|
-
id: identifier
|
|
1177
|
+
op: "read",
|
|
1178
|
+
id: identifier,
|
|
1179
|
+
args: {},
|
|
1180
|
+
options: { includePermissions, tryList },
|
|
1181
|
+
sqOptions: sq
|
|
1064
1182
|
},
|
|
1065
1183
|
__requestConfig: reqConfig,
|
|
1066
1184
|
__service: this
|
|
1067
1185
|
}
|
|
1068
1186
|
);
|
|
1069
|
-
return result;
|
|
1070
1187
|
}
|
|
1071
|
-
|
|
1188
|
+
readAdvanced(identifier, args, options, axiosRequestConfig) {
|
|
1189
|
+
const {
|
|
1190
|
+
populate = this._defaults.readAdvancedArgs.populate,
|
|
1191
|
+
include = this._defaults.readAdvancedArgs.include,
|
|
1192
|
+
tasks = this._defaults.readAdvancedArgs.tasks
|
|
1193
|
+
} = args ?? {};
|
|
1194
|
+
const select = args?.select ?? this._defaults.readAdvancedArgs.select;
|
|
1195
|
+
const {
|
|
1196
|
+
skim = this._defaults.readAdvancedOptions.skim ?? true,
|
|
1197
|
+
includePermissions = this._defaults.readAdvancedOptions.includePermissions ?? true,
|
|
1198
|
+
tryList = this._defaults.readAdvancedOptions.tryList ?? true,
|
|
1199
|
+
populateAccess = this._defaults.readAdvancedOptions.populateAccess,
|
|
1200
|
+
ignoreCache = this._defaults.readAdvancedOptions.ignoreCache ?? false,
|
|
1201
|
+
sq
|
|
1202
|
+
} = options ?? {};
|
|
1072
1203
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1204
|
+
reqConfig.headers = this.updateHeaders(reqConfig.headers, { ignoreCache });
|
|
1205
|
+
return makeRequest(
|
|
1206
|
+
() => this._axios.post(
|
|
1207
|
+
`${this._basePath}/${this._queryPath}/${identifier}`,
|
|
1208
|
+
{
|
|
1209
|
+
select,
|
|
1210
|
+
populate,
|
|
1211
|
+
include,
|
|
1212
|
+
tasks,
|
|
1213
|
+
options: { skim, includePermissions, tryList, populateAccess }
|
|
1214
|
+
},
|
|
1215
|
+
reqConfig
|
|
1216
|
+
).then(this.handleSuccess).then((result) => {
|
|
1217
|
+
result.data = result.success ? Model.create(result.raw, this) : null;
|
|
1218
|
+
return result;
|
|
1219
|
+
}).catch(this.handleError).then(
|
|
1220
|
+
(res) => this._handleCallbacks(res, throwOnError)
|
|
1221
|
+
),
|
|
1078
1222
|
{
|
|
1079
|
-
__op: "
|
|
1223
|
+
__op: "readAdvanced",
|
|
1080
1224
|
__query: {
|
|
1081
1225
|
target: "model",
|
|
1082
1226
|
name: this._modelName,
|
|
1083
1227
|
model: this._modelName,
|
|
1084
|
-
op: "
|
|
1085
|
-
|
|
1228
|
+
op: "read",
|
|
1229
|
+
id: identifier,
|
|
1230
|
+
args: { select, populate, include, tasks },
|
|
1231
|
+
options: { skim, includePermissions, tryList, populateAccess },
|
|
1232
|
+
sqOptions: sq
|
|
1086
1233
|
},
|
|
1087
1234
|
__requestConfig: reqConfig,
|
|
1088
1235
|
__service: this
|
|
1089
1236
|
}
|
|
1090
1237
|
);
|
|
1091
|
-
return result;
|
|
1092
1238
|
}
|
|
1093
|
-
|
|
1239
|
+
readAdvancedFilter(filter, args, options, axiosRequestConfig) {
|
|
1240
|
+
const {
|
|
1241
|
+
sort = this._defaults.readAdvancedArgs.sort,
|
|
1242
|
+
populate = this._defaults.readAdvancedArgs.populate,
|
|
1243
|
+
include = this._defaults.readAdvancedArgs.include,
|
|
1244
|
+
tasks = this._defaults.readAdvancedArgs.tasks
|
|
1245
|
+
} = args ?? {};
|
|
1246
|
+
const select = args?.select ?? this._defaults.readAdvancedArgs.select;
|
|
1247
|
+
const {
|
|
1248
|
+
skim = this._defaults.readAdvancedOptions.skim ?? true,
|
|
1249
|
+
includePermissions = this._defaults.readAdvancedOptions.includePermissions ?? true,
|
|
1250
|
+
tryList = this._defaults.readAdvancedOptions.tryList ?? true,
|
|
1251
|
+
populateAccess = this._defaults.readAdvancedOptions.populateAccess,
|
|
1252
|
+
ignoreCache = this._defaults.readAdvancedOptions.ignoreCache ?? false,
|
|
1253
|
+
sq
|
|
1254
|
+
} = options ?? {};
|
|
1094
1255
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1256
|
+
reqConfig.headers = this.updateHeaders(reqConfig.headers, { ignoreCache });
|
|
1257
|
+
const _filter = replaceSubQuery(filter);
|
|
1258
|
+
return makeRequest(
|
|
1259
|
+
() => this._axios.post(
|
|
1260
|
+
`${this._basePath}/${this._queryPath}/__filter`,
|
|
1261
|
+
{
|
|
1262
|
+
filter: _filter,
|
|
1263
|
+
select,
|
|
1264
|
+
sort,
|
|
1265
|
+
populate,
|
|
1266
|
+
include,
|
|
1267
|
+
tasks,
|
|
1268
|
+
options: { skim, includePermissions, tryList, populateAccess }
|
|
1269
|
+
},
|
|
1270
|
+
reqConfig
|
|
1271
|
+
).then(this.handleSuccess).then((result) => {
|
|
1272
|
+
result.data = result.success ? Model.create(result.raw, this) : null;
|
|
1273
|
+
return result;
|
|
1274
|
+
}).catch(this.handleError).then(
|
|
1275
|
+
(res) => this._handleCallbacks(res, throwOnError)
|
|
1276
|
+
),
|
|
1100
1277
|
{
|
|
1101
|
-
__op: "
|
|
1278
|
+
__op: "readAdvancedFilter",
|
|
1102
1279
|
__query: {
|
|
1103
1280
|
target: "model",
|
|
1104
1281
|
name: this._modelName,
|
|
1105
1282
|
model: this._modelName,
|
|
1106
|
-
op: "
|
|
1107
|
-
|
|
1108
|
-
|
|
1283
|
+
op: "read",
|
|
1284
|
+
filter: _filter,
|
|
1285
|
+
args: { select, sort, populate, include, tasks },
|
|
1286
|
+
options: { skim, includePermissions, tryList, populateAccess },
|
|
1287
|
+
sqOptions: sq
|
|
1109
1288
|
},
|
|
1110
1289
|
__requestConfig: reqConfig,
|
|
1111
1290
|
__service: this
|
|
1112
1291
|
}
|
|
1113
1292
|
);
|
|
1114
|
-
return result;
|
|
1115
1293
|
}
|
|
1116
|
-
|
|
1294
|
+
update(identifier, data, options, axiosRequestConfig) {
|
|
1295
|
+
const { returningAll = this._defaults.updateOptions.returningAll ?? true } = options ?? {};
|
|
1117
1296
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1297
|
+
(0, import_utils5.set)(reqConfig, `headers.${CACHE_HEADER}`, "false");
|
|
1298
|
+
return makeRequest(
|
|
1299
|
+
() => this._axios.patch(
|
|
1300
|
+
`${this._basePath}/${identifier}`,
|
|
1301
|
+
data,
|
|
1302
|
+
(0, import_axios4.mergeConfig)(reqConfig, { params: { returning_all: returningAll } })
|
|
1303
|
+
).then(this.handleSuccess).then((result) => {
|
|
1304
|
+
result.data = result.success ? Model.create(result.raw, this) : null;
|
|
1305
|
+
return result;
|
|
1122
1306
|
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
1123
1307
|
{
|
|
1124
|
-
__op: "
|
|
1308
|
+
__op: "update",
|
|
1125
1309
|
__query: {
|
|
1126
1310
|
target: "model",
|
|
1127
1311
|
name: this._modelName,
|
|
1128
1312
|
model: this._modelName,
|
|
1129
|
-
op: "
|
|
1313
|
+
op: "update",
|
|
1314
|
+
id: identifier,
|
|
1315
|
+
data,
|
|
1316
|
+
options: { returningAll }
|
|
1130
1317
|
},
|
|
1131
1318
|
__requestConfig: reqConfig,
|
|
1132
1319
|
__service: this
|
|
1133
1320
|
}
|
|
1134
1321
|
);
|
|
1135
|
-
return result;
|
|
1136
1322
|
}
|
|
1137
|
-
|
|
1138
|
-
const {
|
|
1323
|
+
updateAdvanced(identifier, data, args, options, axiosRequestConfig) {
|
|
1324
|
+
const { populate = this._defaults.updateAdvancedArgs.populate, tasks = this._defaults.updateAdvancedArgs.tasks } = args ?? {};
|
|
1325
|
+
const select = args?.select ?? this._defaults.updateAdvancedArgs.select;
|
|
1326
|
+
const {
|
|
1327
|
+
returningAll = this._defaults.updateAdvancedOptions.returningAll ?? true,
|
|
1328
|
+
includePermissions = this._defaults.updateAdvancedOptions.includePermissions ?? true,
|
|
1329
|
+
populateAccess = this._defaults.updateAdvancedOptions.populateAccess
|
|
1330
|
+
} = options ?? {};
|
|
1139
1331
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1332
|
+
(0, import_utils5.set)(reqConfig, `headers.${CACHE_HEADER}`, "false");
|
|
1333
|
+
return makeRequest(
|
|
1334
|
+
() => this._axios.patch(
|
|
1335
|
+
`${this._basePath}/${this._mutationPath}/${identifier}`,
|
|
1336
|
+
{
|
|
1337
|
+
data,
|
|
1338
|
+
select,
|
|
1339
|
+
populate,
|
|
1340
|
+
tasks,
|
|
1341
|
+
options: { returningAll, includePermissions, populateAccess }
|
|
1342
|
+
},
|
|
1343
|
+
reqConfig
|
|
1344
|
+
).then(this.handleSuccess).then((result) => {
|
|
1345
|
+
result.data = result.success ? Model.create(result.raw, this) : null;
|
|
1346
|
+
return result;
|
|
1347
|
+
}).catch(this.handleError).then(
|
|
1348
|
+
(res) => this._handleCallbacks(res, throwOnError)
|
|
1349
|
+
),
|
|
1145
1350
|
{
|
|
1146
|
-
__op: "
|
|
1351
|
+
__op: "updateAdvanced",
|
|
1147
1352
|
__query: {
|
|
1148
1353
|
target: "model",
|
|
1149
1354
|
name: this._modelName,
|
|
1150
1355
|
model: this._modelName,
|
|
1151
|
-
op: "
|
|
1152
|
-
|
|
1153
|
-
|
|
1356
|
+
op: "update",
|
|
1357
|
+
id: identifier,
|
|
1358
|
+
data,
|
|
1359
|
+
args: { select, populate, tasks },
|
|
1360
|
+
options: { returningAll, includePermissions, populateAccess }
|
|
1154
1361
|
},
|
|
1155
1362
|
__requestConfig: reqConfig,
|
|
1156
1363
|
__service: this
|
|
1157
1364
|
}
|
|
1158
1365
|
);
|
|
1159
|
-
return result;
|
|
1160
1366
|
}
|
|
1367
|
+
// ---------------------------------------------------------------------------
|
|
1368
|
+
// Sub-document operations
|
|
1369
|
+
// ---------------------------------------------------------------------------
|
|
1161
1370
|
id(id) {
|
|
1162
1371
|
return {
|
|
1163
1372
|
subs: (field) => {
|
|
1164
1373
|
const sub = String(field);
|
|
1165
|
-
return
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
result2.totalCount = Array.isArray(result2.raw) ? result2.raw.length : 0;
|
|
1176
|
-
result2.data = [];
|
|
1177
|
-
return result2;
|
|
1178
|
-
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
1179
|
-
{
|
|
1180
|
-
__op: "listSub",
|
|
1181
|
-
__query: {
|
|
1182
|
-
target: "model",
|
|
1183
|
-
name: this._modelName,
|
|
1184
|
-
model: this._modelName,
|
|
1185
|
-
op: "subList",
|
|
1186
|
-
id,
|
|
1187
|
-
sub,
|
|
1188
|
-
filter: {},
|
|
1189
|
-
args: {},
|
|
1190
|
-
options: {}
|
|
1191
|
-
},
|
|
1192
|
-
__requestConfig: reqConfig,
|
|
1193
|
-
__service: this
|
|
1194
|
-
}
|
|
1195
|
-
);
|
|
1196
|
-
return result;
|
|
1197
|
-
},
|
|
1198
|
-
listAdvanced: (filter, args, axiosRequestConfig) => {
|
|
1199
|
-
const select = args?.select;
|
|
1200
|
-
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1201
|
-
const result = wrapLazyPromise(
|
|
1202
|
-
() => this._axios.post(`${this._basePath}/${id}/${sub}/${this._queryPath}`, { filter, select }, reqConfig).then(this.handleSuccess).then((result2) => {
|
|
1203
|
-
result2.totalCount = result2.raw.length;
|
|
1204
|
-
result2.data = [];
|
|
1205
|
-
return result2;
|
|
1206
|
-
}).catch(this.handleError).then(
|
|
1207
|
-
(res) => this._handleCallbacks(
|
|
1208
|
-
res,
|
|
1209
|
-
throwOnError
|
|
1210
|
-
)
|
|
1211
|
-
),
|
|
1212
|
-
{
|
|
1213
|
-
__op: "listAdvancedSub",
|
|
1214
|
-
__query: {
|
|
1215
|
-
target: "model",
|
|
1216
|
-
name: this._modelName,
|
|
1217
|
-
model: this._modelName,
|
|
1218
|
-
op: "subList",
|
|
1219
|
-
id,
|
|
1220
|
-
sub,
|
|
1221
|
-
filter,
|
|
1222
|
-
args: { select },
|
|
1223
|
-
options: {}
|
|
1224
|
-
},
|
|
1225
|
-
__requestConfig: reqConfig,
|
|
1226
|
-
__service: this
|
|
1227
|
-
}
|
|
1228
|
-
);
|
|
1229
|
-
return result;
|
|
1230
|
-
},
|
|
1231
|
-
read: (subId, axiosRequestConfig) => {
|
|
1232
|
-
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1233
|
-
const result = wrapLazyPromise(
|
|
1234
|
-
() => this._axios.get(
|
|
1235
|
-
`${this._basePath}/${id}/${sub}/${subId}`,
|
|
1236
|
-
(0, import_axios2.mergeConfig)(reqConfig, {
|
|
1237
|
-
params: {}
|
|
1238
|
-
})
|
|
1239
|
-
).then(this.handleSuccess).then((result2) => {
|
|
1240
|
-
result2.data = null;
|
|
1241
|
-
return result2;
|
|
1242
|
-
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
1243
|
-
{
|
|
1244
|
-
__op: "readSub",
|
|
1245
|
-
__query: {
|
|
1246
|
-
target: "model",
|
|
1247
|
-
name: this._modelName,
|
|
1248
|
-
model: this._modelName,
|
|
1249
|
-
op: "subRead",
|
|
1250
|
-
id,
|
|
1251
|
-
sub,
|
|
1252
|
-
subId,
|
|
1253
|
-
args: {},
|
|
1254
|
-
options: {}
|
|
1255
|
-
},
|
|
1256
|
-
__requestConfig: reqConfig,
|
|
1257
|
-
__service: this
|
|
1258
|
-
}
|
|
1259
|
-
);
|
|
1260
|
-
return result;
|
|
1374
|
+
return buildSubDocumentOps(
|
|
1375
|
+
{
|
|
1376
|
+
axios: this._axios,
|
|
1377
|
+
basePath: this._basePath,
|
|
1378
|
+
modelName: this._modelName,
|
|
1379
|
+
queryPath: this._queryPath,
|
|
1380
|
+
handleSuccess: this.handleSuccess,
|
|
1381
|
+
handleError: this.handleError,
|
|
1382
|
+
_handleCallbacks: this._handleCallbacks,
|
|
1383
|
+
parentService: this
|
|
1261
1384
|
},
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
const result = wrapLazyPromise(
|
|
1266
|
-
() => this._axios.post(
|
|
1267
|
-
`${this._basePath}/${id}/${sub}/${subId}/${this._queryPath}`,
|
|
1268
|
-
{
|
|
1269
|
-
select,
|
|
1270
|
-
populate
|
|
1271
|
-
},
|
|
1272
|
-
reqConfig
|
|
1273
|
-
).then(this.handleSuccess).then((result2) => {
|
|
1274
|
-
result2.data = null;
|
|
1275
|
-
return result2;
|
|
1276
|
-
}).catch(this.handleError).then(
|
|
1277
|
-
(res) => this._handleCallbacks(
|
|
1278
|
-
res,
|
|
1279
|
-
throwOnError
|
|
1280
|
-
)
|
|
1281
|
-
),
|
|
1282
|
-
{
|
|
1283
|
-
__op: "readAdvancedSub",
|
|
1284
|
-
__query: {
|
|
1285
|
-
target: "model",
|
|
1286
|
-
name: this._modelName,
|
|
1287
|
-
model: this._modelName,
|
|
1288
|
-
op: "subRead",
|
|
1289
|
-
id,
|
|
1290
|
-
sub,
|
|
1291
|
-
subId,
|
|
1292
|
-
args: { select, populate },
|
|
1293
|
-
options: {}
|
|
1294
|
-
},
|
|
1295
|
-
__requestConfig: reqConfig,
|
|
1296
|
-
__service: this
|
|
1297
|
-
}
|
|
1298
|
-
);
|
|
1299
|
-
return result;
|
|
1300
|
-
},
|
|
1301
|
-
update: (subId, data, axiosRequestConfig) => {
|
|
1302
|
-
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1303
|
-
const result = wrapLazyPromise(
|
|
1304
|
-
() => this._axios.patch(`${this._basePath}/${id}/${sub}/${subId}`, data, (0, import_axios2.mergeConfig)(reqConfig, { params: {} })).then(this.handleSuccess).then((result2) => {
|
|
1305
|
-
result2.data = null;
|
|
1306
|
-
return result2;
|
|
1307
|
-
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
1308
|
-
{
|
|
1309
|
-
__op: "updateSub",
|
|
1310
|
-
__query: {
|
|
1311
|
-
target: "model",
|
|
1312
|
-
name: this._modelName,
|
|
1313
|
-
model: this._modelName,
|
|
1314
|
-
op: "subUpdate",
|
|
1315
|
-
id,
|
|
1316
|
-
sub,
|
|
1317
|
-
subId,
|
|
1318
|
-
data,
|
|
1319
|
-
options: {}
|
|
1320
|
-
},
|
|
1321
|
-
__requestConfig: reqConfig,
|
|
1322
|
-
__service: this
|
|
1323
|
-
}
|
|
1324
|
-
);
|
|
1325
|
-
return result;
|
|
1326
|
-
},
|
|
1327
|
-
bulkUpdate: (data, _options, axiosRequestConfig) => {
|
|
1328
|
-
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1329
|
-
const result = wrapLazyPromise(
|
|
1330
|
-
() => this._axios.patch(`${this._basePath}/${id}/${sub}`, data, (0, import_axios2.mergeConfig)(reqConfig, { params: {} })).then(this.handleSuccess).then((result2) => {
|
|
1331
|
-
result2.data = [];
|
|
1332
|
-
return result2;
|
|
1333
|
-
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
1334
|
-
{
|
|
1335
|
-
__op: "bulkUpdateSub",
|
|
1336
|
-
__query: {
|
|
1337
|
-
target: "model",
|
|
1338
|
-
name: this._modelName,
|
|
1339
|
-
model: this._modelName,
|
|
1340
|
-
op: "subBulkUpdate",
|
|
1341
|
-
id,
|
|
1342
|
-
sub,
|
|
1343
|
-
data,
|
|
1344
|
-
options: {}
|
|
1345
|
-
},
|
|
1346
|
-
__requestConfig: reqConfig,
|
|
1347
|
-
__service: this
|
|
1348
|
-
}
|
|
1349
|
-
);
|
|
1350
|
-
return result;
|
|
1351
|
-
},
|
|
1352
|
-
create: (data, axiosRequestConfig) => {
|
|
1353
|
-
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1354
|
-
const result = wrapLazyPromise(
|
|
1355
|
-
() => this._axios.post(`${this._basePath}/${id}/${sub}`, data, (0, import_axios2.mergeConfig)(reqConfig, { params: {} })).then(this.handleSuccess).then((result2) => {
|
|
1356
|
-
result2.data = null;
|
|
1357
|
-
return result2;
|
|
1358
|
-
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
1359
|
-
{
|
|
1360
|
-
__op: "createSub",
|
|
1361
|
-
__query: {
|
|
1362
|
-
target: "model",
|
|
1363
|
-
name: this._modelName,
|
|
1364
|
-
model: this._modelName,
|
|
1365
|
-
op: "subCreate",
|
|
1366
|
-
id,
|
|
1367
|
-
sub,
|
|
1368
|
-
data,
|
|
1369
|
-
options: {}
|
|
1370
|
-
},
|
|
1371
|
-
__requestConfig: reqConfig,
|
|
1372
|
-
__service: this
|
|
1373
|
-
}
|
|
1374
|
-
);
|
|
1375
|
-
return result;
|
|
1376
|
-
},
|
|
1377
|
-
delete: (subId, axiosRequestConfig) => {
|
|
1378
|
-
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1379
|
-
const result = wrapLazyPromise(
|
|
1380
|
-
() => this._axios.delete(`${this._basePath}/${id}/${sub}/${subId}`, reqConfig).then(this.handleSuccess).then((result2) => {
|
|
1381
|
-
result2.data = null;
|
|
1382
|
-
return result2;
|
|
1383
|
-
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
1384
|
-
{
|
|
1385
|
-
__op: "deleteSub",
|
|
1386
|
-
__query: {
|
|
1387
|
-
target: "model",
|
|
1388
|
-
name: this._modelName,
|
|
1389
|
-
model: this._modelName,
|
|
1390
|
-
op: "subDelete",
|
|
1391
|
-
id,
|
|
1392
|
-
sub,
|
|
1393
|
-
subId
|
|
1394
|
-
},
|
|
1395
|
-
__requestConfig: reqConfig,
|
|
1396
|
-
__service: this
|
|
1397
|
-
}
|
|
1398
|
-
);
|
|
1399
|
-
return result;
|
|
1400
|
-
}
|
|
1401
|
-
};
|
|
1385
|
+
id,
|
|
1386
|
+
sub
|
|
1387
|
+
);
|
|
1402
1388
|
},
|
|
1403
1389
|
fetch: (args, options, axiosRequestConfig) => {
|
|
1404
1390
|
return this.readAdvanced(id, args, options, axiosRequestConfig);
|
|
1405
1391
|
}
|
|
1406
1392
|
};
|
|
1407
1393
|
}
|
|
1408
|
-
processListResult(_this, result, { includeCount, includeExtraHeaders }) {
|
|
1409
|
-
const wrappedRows = (0, import_utils5.get)(result, "raw.data");
|
|
1410
|
-
const wrappedTotalCount = (0, import_utils5.get)(result, "raw.meta.totalCount");
|
|
1411
|
-
if (Array.isArray(wrappedRows)) {
|
|
1412
|
-
const rows = wrappedRows;
|
|
1413
|
-
result.raw = wrappedRows;
|
|
1414
|
-
if (includeCount) {
|
|
1415
|
-
if (includeExtraHeaders) {
|
|
1416
|
-
const totalCount = (0, import_utils5.get)(result, `headers.${"wtt-total-count" /* TotalCount */}`, 0);
|
|
1417
|
-
result.totalCount = Number(totalCount);
|
|
1418
|
-
} else {
|
|
1419
|
-
result.totalCount = Number(wrappedTotalCount ?? rows.length);
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
} else if (includeCount) {
|
|
1423
|
-
if (includeExtraHeaders) {
|
|
1424
|
-
const totalCount = (0, import_utils5.get)(result, `headers.${"wtt-total-count" /* TotalCount */}`, 0);
|
|
1425
|
-
result.totalCount = Number(totalCount);
|
|
1426
|
-
} else {
|
|
1427
|
-
result.totalCount = result.raw.count;
|
|
1428
|
-
result.raw = result.raw.rows;
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
result.data = result.success ? result.raw.map((item) => Model.create(item, _this)) : [];
|
|
1432
|
-
return result;
|
|
1433
|
-
}
|
|
1434
1394
|
};
|
|
1435
1395
|
|
|
1436
1396
|
// src/services/data-service.ts
|
|
1437
|
-
var
|
|
1438
|
-
var import_utils6 = require("@web-ts-toolkit/utils");
|
|
1397
|
+
var import_axios5 = require("axios");
|
|
1439
1398
|
var DataService = class extends Service {
|
|
1440
1399
|
constructor({ axios: axios2, dataName, basePath, queryPath, onSuccess, onFailure, throwOnError }, defaults) {
|
|
1441
1400
|
super(axios2, basePath);
|
|
@@ -1453,6 +1412,9 @@ var DataService = class extends Service {
|
|
|
1453
1412
|
"readAdvancedOptions"
|
|
1454
1413
|
].forEach((key) => setDefaultObjectProp(this._defaults, key, {}));
|
|
1455
1414
|
}
|
|
1415
|
+
// ---------------------------------------------------------------------------
|
|
1416
|
+
// Collection operations
|
|
1417
|
+
// ---------------------------------------------------------------------------
|
|
1456
1418
|
list(args, options, axiosRequestConfig) {
|
|
1457
1419
|
const {
|
|
1458
1420
|
skip = this._defaults.listArgs.skip,
|
|
@@ -1468,10 +1430,10 @@ var DataService = class extends Service {
|
|
|
1468
1430
|
} = options ?? {};
|
|
1469
1431
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1470
1432
|
reqConfig.headers = this.updateHeaders(reqConfig.headers, { ignoreCache });
|
|
1471
|
-
|
|
1433
|
+
return makeRequest(
|
|
1472
1434
|
() => this._axios.get(
|
|
1473
1435
|
this._basePath,
|
|
1474
|
-
(0,
|
|
1436
|
+
(0, import_axios5.mergeConfig)(reqConfig, {
|
|
1475
1437
|
params: {
|
|
1476
1438
|
skip,
|
|
1477
1439
|
limit,
|
|
@@ -1482,8 +1444,8 @@ var DataService = class extends Service {
|
|
|
1482
1444
|
include_extra_headers: includeExtraHeaders
|
|
1483
1445
|
}
|
|
1484
1446
|
})
|
|
1485
|
-
).then(this.handleSuccess).then((
|
|
1486
|
-
return
|
|
1447
|
+
).then(this.handleSuccess).then((result) => {
|
|
1448
|
+
return processListResult(result, { includeCount, includeExtraHeaders });
|
|
1487
1449
|
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
1488
1450
|
{
|
|
1489
1451
|
__op: "list",
|
|
@@ -1493,17 +1455,12 @@ var DataService = class extends Service {
|
|
|
1493
1455
|
op: "list",
|
|
1494
1456
|
filter: {},
|
|
1495
1457
|
args: { skip, limit, page, pageSize },
|
|
1496
|
-
options: {
|
|
1497
|
-
includePermissions,
|
|
1498
|
-
includeCount,
|
|
1499
|
-
includeExtraHeaders
|
|
1500
|
-
}
|
|
1458
|
+
options: { includePermissions, includeCount, includeExtraHeaders }
|
|
1501
1459
|
},
|
|
1502
1460
|
__requestConfig: reqConfig,
|
|
1503
1461
|
__service: this
|
|
1504
1462
|
}
|
|
1505
1463
|
);
|
|
1506
|
-
return result;
|
|
1507
1464
|
}
|
|
1508
1465
|
listAdvanced(filter, args, options, axiosRequestConfig) {
|
|
1509
1466
|
const {
|
|
@@ -1523,7 +1480,7 @@ var DataService = class extends Service {
|
|
|
1523
1480
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1524
1481
|
reqConfig.headers = this.updateHeaders(reqConfig.headers, { ignoreCache });
|
|
1525
1482
|
const _filter = replaceSubQuery(filter);
|
|
1526
|
-
|
|
1483
|
+
return makeRequest(
|
|
1527
1484
|
() => this._axios.post(
|
|
1528
1485
|
`${this._basePath}/${this._queryPath}`,
|
|
1529
1486
|
{
|
|
@@ -1534,15 +1491,14 @@ var DataService = class extends Service {
|
|
|
1534
1491
|
limit,
|
|
1535
1492
|
page,
|
|
1536
1493
|
pageSize,
|
|
1537
|
-
options: {
|
|
1538
|
-
includePermissions,
|
|
1539
|
-
includeCount,
|
|
1540
|
-
includeExtraHeaders
|
|
1541
|
-
}
|
|
1494
|
+
options: { includePermissions, includeCount, includeExtraHeaders }
|
|
1542
1495
|
},
|
|
1543
1496
|
reqConfig
|
|
1544
|
-
).then(this.handleSuccess).then((
|
|
1545
|
-
return
|
|
1497
|
+
).then(this.handleSuccess).then((result) => {
|
|
1498
|
+
return processListResult(result, {
|
|
1499
|
+
includeCount,
|
|
1500
|
+
includeExtraHeaders
|
|
1501
|
+
});
|
|
1546
1502
|
}).catch(this.handleError).then(
|
|
1547
1503
|
(res) => this._handleCallbacks(res, throwOnError)
|
|
1548
1504
|
),
|
|
@@ -1554,18 +1510,16 @@ var DataService = class extends Service {
|
|
|
1554
1510
|
op: "list",
|
|
1555
1511
|
filter: _filter,
|
|
1556
1512
|
args: { select, sort, skip, limit, page, pageSize },
|
|
1557
|
-
options: {
|
|
1558
|
-
includePermissions,
|
|
1559
|
-
includeCount,
|
|
1560
|
-
includeExtraHeaders
|
|
1561
|
-
}
|
|
1513
|
+
options: { includePermissions, includeCount, includeExtraHeaders }
|
|
1562
1514
|
},
|
|
1563
1515
|
__requestConfig: reqConfig,
|
|
1564
1516
|
__service: this
|
|
1565
1517
|
}
|
|
1566
1518
|
);
|
|
1567
|
-
return result;
|
|
1568
1519
|
}
|
|
1520
|
+
// ---------------------------------------------------------------------------
|
|
1521
|
+
// Document operations
|
|
1522
|
+
// ---------------------------------------------------------------------------
|
|
1569
1523
|
read(identifier, options, axiosRequestConfig) {
|
|
1570
1524
|
const {
|
|
1571
1525
|
includePermissions = this._defaults.readOptions.includePermissions ?? true,
|
|
@@ -1573,17 +1527,15 @@ var DataService = class extends Service {
|
|
|
1573
1527
|
} = options ?? {};
|
|
1574
1528
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1575
1529
|
reqConfig.headers = this.updateHeaders(reqConfig.headers, { ignoreCache });
|
|
1576
|
-
|
|
1530
|
+
return makeRequest(
|
|
1577
1531
|
() => this._axios.get(
|
|
1578
1532
|
`${this._basePath}/${identifier}`,
|
|
1579
|
-
(0,
|
|
1580
|
-
params: {
|
|
1581
|
-
include_permissions: includePermissions
|
|
1582
|
-
}
|
|
1533
|
+
(0, import_axios5.mergeConfig)(reqConfig, {
|
|
1534
|
+
params: { include_permissions: includePermissions }
|
|
1583
1535
|
})
|
|
1584
|
-
).then(this.handleSuccess).then((
|
|
1585
|
-
|
|
1586
|
-
return
|
|
1536
|
+
).then(this.handleSuccess).then((result) => {
|
|
1537
|
+
result.data = result.raw;
|
|
1538
|
+
return result;
|
|
1587
1539
|
}).catch(this.handleError).then((res) => this._handleCallbacks(res, throwOnError)),
|
|
1588
1540
|
{
|
|
1589
1541
|
__op: "read",
|
|
@@ -1593,15 +1545,12 @@ var DataService = class extends Service {
|
|
|
1593
1545
|
op: "read",
|
|
1594
1546
|
id: identifier,
|
|
1595
1547
|
args: {},
|
|
1596
|
-
options: {
|
|
1597
|
-
includePermissions
|
|
1598
|
-
}
|
|
1548
|
+
options: { includePermissions }
|
|
1599
1549
|
},
|
|
1600
1550
|
__requestConfig: reqConfig,
|
|
1601
1551
|
__service: this
|
|
1602
1552
|
}
|
|
1603
1553
|
);
|
|
1604
|
-
return result;
|
|
1605
1554
|
}
|
|
1606
1555
|
readAdvanced(identifier, args, options, axiosRequestConfig) {
|
|
1607
1556
|
const { ignoreCache = this._defaults.readAdvancedArgs.ignoreCache ?? false } = args ?? {};
|
|
@@ -1609,10 +1558,10 @@ var DataService = class extends Service {
|
|
|
1609
1558
|
const { includePermissions = this._defaults.readAdvancedOptions.includePermissions ?? true } = options ?? {};
|
|
1610
1559
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1611
1560
|
reqConfig.headers = this.updateHeaders(reqConfig.headers, { ignoreCache });
|
|
1612
|
-
|
|
1613
|
-
() => this._axios.post(`${this._basePath}/${this._queryPath}/${identifier}`, { select }, reqConfig).then(this.handleSuccess).then((
|
|
1614
|
-
|
|
1615
|
-
return
|
|
1561
|
+
return makeRequest(
|
|
1562
|
+
() => this._axios.post(`${this._basePath}/${this._queryPath}/${identifier}`, { select }, reqConfig).then(this.handleSuccess).then((result) => {
|
|
1563
|
+
result.data = result.raw;
|
|
1564
|
+
return result;
|
|
1616
1565
|
}).catch(this.handleError).then(
|
|
1617
1566
|
(res) => this._handleCallbacks(res, throwOnError)
|
|
1618
1567
|
),
|
|
@@ -1624,29 +1573,24 @@ var DataService = class extends Service {
|
|
|
1624
1573
|
op: "read",
|
|
1625
1574
|
id: identifier,
|
|
1626
1575
|
args: { select },
|
|
1627
|
-
options: {
|
|
1628
|
-
includePermissions
|
|
1629
|
-
}
|
|
1576
|
+
options: { includePermissions }
|
|
1630
1577
|
},
|
|
1631
1578
|
__requestConfig: reqConfig,
|
|
1632
1579
|
__service: this
|
|
1633
1580
|
}
|
|
1634
1581
|
);
|
|
1635
|
-
return result;
|
|
1636
1582
|
}
|
|
1637
1583
|
readAdvancedFilter(filter, args, options, axiosRequestConfig) {
|
|
1638
1584
|
const select = args?.select ?? this._defaults.readAdvancedArgs.select;
|
|
1639
|
-
const {
|
|
1640
|
-
|
|
1641
|
-
ignoreCache = this._defaults.readAdvancedOptions.ignoreCache ?? false
|
|
1642
|
-
} = options ?? {};
|
|
1585
|
+
const { ignoreCache = this._defaults.readAdvancedArgs.ignoreCache ?? false } = args ?? {};
|
|
1586
|
+
const { includePermissions = this._defaults.readAdvancedOptions.includePermissions ?? true } = options ?? {};
|
|
1643
1587
|
const { throwOnError, ...reqConfig } = axiosRequestConfig ?? {};
|
|
1644
1588
|
reqConfig.headers = this.updateHeaders(reqConfig.headers, { ignoreCache });
|
|
1645
1589
|
const _filter = replaceSubQuery(filter);
|
|
1646
|
-
|
|
1647
|
-
() => this._axios.post(`${this._basePath}/${this._queryPath}/__filter`, { filter: _filter, select }, reqConfig).then(this.handleSuccess).then((
|
|
1648
|
-
|
|
1649
|
-
return
|
|
1590
|
+
return makeRequest(
|
|
1591
|
+
() => this._axios.post(`${this._basePath}/${this._queryPath}/__filter`, { filter: _filter, select }, reqConfig).then(this.handleSuccess).then((result) => {
|
|
1592
|
+
result.data = result.raw;
|
|
1593
|
+
return result;
|
|
1650
1594
|
}).catch(this.handleError).then(
|
|
1651
1595
|
(res) => this._handleCallbacks(res, throwOnError)
|
|
1652
1596
|
),
|
|
@@ -1658,52 +1602,56 @@ var DataService = class extends Service {
|
|
|
1658
1602
|
op: "read",
|
|
1659
1603
|
filter: _filter,
|
|
1660
1604
|
args: { select },
|
|
1661
|
-
options: {
|
|
1662
|
-
includePermissions
|
|
1663
|
-
}
|
|
1605
|
+
options: { includePermissions }
|
|
1664
1606
|
},
|
|
1665
1607
|
__requestConfig: reqConfig,
|
|
1666
1608
|
__service: this
|
|
1667
1609
|
}
|
|
1668
1610
|
);
|
|
1669
|
-
return result;
|
|
1670
1611
|
}
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
result.raw = result.raw.rows;
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
result.data = result.raw;
|
|
1695
|
-
return result;
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
// src/services/interceptors.ts
|
|
1615
|
+
var import_axios7 = require("axios");
|
|
1616
|
+
|
|
1617
|
+
// src/services/cache-utils.ts
|
|
1618
|
+
var import_axios6 = require("axios");
|
|
1619
|
+
var normalizeConfigValue = (value) => {
|
|
1620
|
+
if (value == null) return value;
|
|
1621
|
+
if (value instanceof import_axios6.AxiosHeaders) {
|
|
1622
|
+
return normalizeConfigValue(value.toJSON());
|
|
1623
|
+
}
|
|
1624
|
+
if (Array.isArray(value)) {
|
|
1625
|
+
return value.map((item) => normalizeConfigValue(item));
|
|
1626
|
+
}
|
|
1627
|
+
if (typeof value === "object") {
|
|
1628
|
+
return Object.entries(value).filter(([, item]) => item !== void 0).sort(([left], [right]) => left.localeCompare(right)).reduce((acc, [key, item]) => {
|
|
1629
|
+
acc[key] = normalizeConfigValue(item);
|
|
1630
|
+
return acc;
|
|
1631
|
+
}, {});
|
|
1696
1632
|
}
|
|
1633
|
+
return value;
|
|
1697
1634
|
};
|
|
1698
1635
|
|
|
1699
1636
|
// src/services/interceptors.ts
|
|
1700
|
-
var import_axios4 = require("axios");
|
|
1701
1637
|
var SimpleCache = class {
|
|
1702
1638
|
constructor() {
|
|
1703
1639
|
this.cache = /* @__PURE__ */ new Map();
|
|
1640
|
+
this.timers = /* @__PURE__ */ new Map();
|
|
1704
1641
|
}
|
|
1705
|
-
set(key, value) {
|
|
1642
|
+
set(key, value, ttl) {
|
|
1706
1643
|
this.cache.set(key, value);
|
|
1644
|
+
if (ttl && ttl > 0) {
|
|
1645
|
+
const existing = this.timers.get(key);
|
|
1646
|
+
if (existing) clearTimeout(existing);
|
|
1647
|
+
this.timers.set(
|
|
1648
|
+
key,
|
|
1649
|
+
setTimeout(() => {
|
|
1650
|
+
this.cache.delete(key);
|
|
1651
|
+
this.timers.delete(key);
|
|
1652
|
+
}, ttl)
|
|
1653
|
+
);
|
|
1654
|
+
}
|
|
1707
1655
|
}
|
|
1708
1656
|
get(key) {
|
|
1709
1657
|
return this.cache.get(key);
|
|
@@ -1712,22 +1660,14 @@ var SimpleCache = class {
|
|
|
1712
1660
|
return this.cache.has(key);
|
|
1713
1661
|
}
|
|
1714
1662
|
delete(key) {
|
|
1663
|
+
const timer = this.timers.get(key);
|
|
1664
|
+
if (timer) {
|
|
1665
|
+
clearTimeout(timer);
|
|
1666
|
+
this.timers.delete(key);
|
|
1667
|
+
}
|
|
1715
1668
|
return this.cache.delete(key);
|
|
1716
1669
|
}
|
|
1717
1670
|
};
|
|
1718
|
-
var normalizeCacheValue = (value) => {
|
|
1719
|
-
if (value == null) return value;
|
|
1720
|
-
if (Array.isArray(value)) {
|
|
1721
|
-
return value.map((item) => normalizeCacheValue(item));
|
|
1722
|
-
}
|
|
1723
|
-
if (typeof value === "object") {
|
|
1724
|
-
return Object.entries(value).filter(([, item]) => item !== void 0).sort(([left], [right]) => left.localeCompare(right)).reduce((acc, [key, item]) => {
|
|
1725
|
-
acc[key] = normalizeCacheValue(item);
|
|
1726
|
-
return acc;
|
|
1727
|
-
}, {});
|
|
1728
|
-
}
|
|
1729
|
-
return value;
|
|
1730
|
-
};
|
|
1731
1671
|
var IGNORED_CACHE_HEADERS = /* @__PURE__ */ new Set([
|
|
1732
1672
|
"accept",
|
|
1733
1673
|
"accept-encoding",
|
|
@@ -1741,7 +1681,7 @@ var IGNORED_CACHE_HEADERS = /* @__PURE__ */ new Set([
|
|
|
1741
1681
|
"user-agent"
|
|
1742
1682
|
]);
|
|
1743
1683
|
var serializeHeaders = (headers) => {
|
|
1744
|
-
const resolvedHeaders = headers instanceof
|
|
1684
|
+
const resolvedHeaders = headers instanceof import_axios7.AxiosHeaders ? headers.toJSON() : headers;
|
|
1745
1685
|
const normalizedHeaders = Object.entries(resolvedHeaders ?? {}).filter(([key, value]) => {
|
|
1746
1686
|
const normalizedKey = key.toLowerCase();
|
|
1747
1687
|
return normalizedKey !== CACHE_HEADER.toLowerCase() && !IGNORED_CACHE_HEADERS.has(normalizedKey) && value !== void 0;
|
|
@@ -1749,7 +1689,7 @@ var serializeHeaders = (headers) => {
|
|
|
1749
1689
|
acc[key.toLowerCase()] = value;
|
|
1750
1690
|
return acc;
|
|
1751
1691
|
}, {});
|
|
1752
|
-
return JSON.stringify(
|
|
1692
|
+
return JSON.stringify(normalizeConfigValue(normalizedHeaders));
|
|
1753
1693
|
};
|
|
1754
1694
|
function generateCacheKey(config) {
|
|
1755
1695
|
const key = `${config.baseURL}/${config.url}_${config.method}_${generateParamKey(config.params)}_${generateDataKey(
|
|
@@ -1759,11 +1699,11 @@ function generateCacheKey(config) {
|
|
|
1759
1699
|
}
|
|
1760
1700
|
function generateParamKey(params) {
|
|
1761
1701
|
if (!params) return "";
|
|
1762
|
-
return JSON.stringify(
|
|
1702
|
+
return JSON.stringify(normalizeConfigValue(params));
|
|
1763
1703
|
}
|
|
1764
1704
|
function generateDataKey(data) {
|
|
1765
1705
|
if (!data) return "";
|
|
1766
|
-
return typeof data === "string" ? data : JSON.stringify(
|
|
1706
|
+
return typeof data === "string" ? data : JSON.stringify(normalizeConfigValue(data));
|
|
1767
1707
|
}
|
|
1768
1708
|
function useCacheInterceptors(instance, cacheTTL) {
|
|
1769
1709
|
const store = new SimpleCache();
|
|
@@ -1790,8 +1730,7 @@ function useCacheInterceptors(instance, cacheTTL) {
|
|
|
1790
1730
|
(response) => {
|
|
1791
1731
|
if (response.config.headers[CACHE_HEADER] === "false") return response;
|
|
1792
1732
|
const key = generateCacheKey(response.config);
|
|
1793
|
-
store.set(key, response);
|
|
1794
|
-
setTimeout(() => store.delete(key), cacheTTL);
|
|
1733
|
+
store.set(key, response, cacheTTL);
|
|
1795
1734
|
return response;
|
|
1796
1735
|
},
|
|
1797
1736
|
(error) => Promise.reject(error)
|
|
@@ -1810,26 +1749,10 @@ var defaultAxiosConfig = Object.freeze({
|
|
|
1810
1749
|
}
|
|
1811
1750
|
});
|
|
1812
1751
|
var isModelQuery = (query) => query.target === "model";
|
|
1813
|
-
var normalizeConfigValue = (value) => {
|
|
1814
|
-
if (value == null) return value;
|
|
1815
|
-
if (value instanceof import_axios5.AxiosHeaders) {
|
|
1816
|
-
return normalizeConfigValue(value.toJSON());
|
|
1817
|
-
}
|
|
1818
|
-
if (Array.isArray(value)) {
|
|
1819
|
-
return value.map((item) => normalizeConfigValue(item));
|
|
1820
|
-
}
|
|
1821
|
-
if (typeof value === "object") {
|
|
1822
|
-
return Object.entries(value).filter(([, item]) => item !== void 0).sort(([left], [right]) => left.localeCompare(right)).reduce((acc, [key, item]) => {
|
|
1823
|
-
acc[key] = normalizeConfigValue(item);
|
|
1824
|
-
return acc;
|
|
1825
|
-
}, {});
|
|
1826
|
-
}
|
|
1827
|
-
return value;
|
|
1828
|
-
};
|
|
1829
1752
|
var serializeRequestConfig = (config) => JSON.stringify(normalizeConfigValue(config ?? {}));
|
|
1830
1753
|
function createAdapter(axiosConfig, adapterOptions) {
|
|
1831
|
-
const merged = (0,
|
|
1832
|
-
const instance =
|
|
1754
|
+
const merged = (0, import_axios8.mergeConfig)(defaultAxiosConfig, axiosConfig ?? {});
|
|
1755
|
+
const instance = import_axios8.default.create(merged);
|
|
1833
1756
|
const {
|
|
1834
1757
|
rootRouterPath = "root",
|
|
1835
1758
|
onSuccess: onSuccessRoot,
|
|
@@ -1838,6 +1761,7 @@ function createAdapter(axiosConfig, adapterOptions) {
|
|
|
1838
1761
|
cacheTTL = 0
|
|
1839
1762
|
} = adapterOptions ?? {};
|
|
1840
1763
|
if (cacheTTL > 0) useCacheInterceptors(instance, cacheTTL);
|
|
1764
|
+
const wraps = createWrapHelper(instance);
|
|
1841
1765
|
return Object.freeze({
|
|
1842
1766
|
axios: instance,
|
|
1843
1767
|
createModelService: ({
|
|
@@ -1877,66 +1801,16 @@ function createAdapter(axiosConfig, adapterOptions) {
|
|
|
1877
1801
|
defaults
|
|
1878
1802
|
);
|
|
1879
1803
|
},
|
|
1880
|
-
wrapGet:
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
options,
|
|
1886
|
-
(0, import_axios5.mergeConfig)(defaultAxiosRequestConfig, axiosRequestConfig)
|
|
1887
|
-
);
|
|
1888
|
-
return instance.get(finalUrl, finalConfig);
|
|
1889
|
-
};
|
|
1890
|
-
},
|
|
1891
|
-
wrapPost: (url, defaultAxiosRequestConfig = {}) => {
|
|
1892
|
-
(0, import_utils7.set)(defaultAxiosRequestConfig, `headers.${CACHE_HEADER}`, "false");
|
|
1893
|
-
return (data, options, axiosRequestConfig) => {
|
|
1894
|
-
const { finalUrl, finalConfig } = getWrapContext(
|
|
1895
|
-
url,
|
|
1896
|
-
options,
|
|
1897
|
-
(0, import_axios5.mergeConfig)(defaultAxiosRequestConfig, axiosRequestConfig)
|
|
1898
|
-
);
|
|
1899
|
-
return instance.post(finalUrl, data, finalConfig);
|
|
1900
|
-
};
|
|
1901
|
-
},
|
|
1902
|
-
wrapPut: (url, defaultAxiosRequestConfig = {}) => {
|
|
1903
|
-
(0, import_utils7.set)(defaultAxiosRequestConfig, `headers.${CACHE_HEADER}`, "false");
|
|
1904
|
-
return (data, options, axiosRequestConfig) => {
|
|
1905
|
-
const { finalUrl, finalConfig } = getWrapContext(
|
|
1906
|
-
url,
|
|
1907
|
-
options,
|
|
1908
|
-
(0, import_axios5.mergeConfig)(defaultAxiosRequestConfig, axiosRequestConfig)
|
|
1909
|
-
);
|
|
1910
|
-
return instance.put(finalUrl, data, finalConfig);
|
|
1911
|
-
};
|
|
1912
|
-
},
|
|
1913
|
-
wrapPatch: (url, defaultAxiosRequestConfig = {}) => {
|
|
1914
|
-
(0, import_utils7.set)(defaultAxiosRequestConfig, `headers.${CACHE_HEADER}`, "false");
|
|
1915
|
-
return (data, options, axiosRequestConfig) => {
|
|
1916
|
-
const { finalUrl, finalConfig } = getWrapContext(
|
|
1917
|
-
url,
|
|
1918
|
-
options,
|
|
1919
|
-
(0, import_axios5.mergeConfig)(defaultAxiosRequestConfig, axiosRequestConfig)
|
|
1920
|
-
);
|
|
1921
|
-
return instance.patch(finalUrl, data, finalConfig);
|
|
1922
|
-
};
|
|
1923
|
-
},
|
|
1924
|
-
wrapDelete: (url, defaultAxiosRequestConfig = {}) => {
|
|
1925
|
-
(0, import_utils7.set)(defaultAxiosRequestConfig, `headers.${CACHE_HEADER}`, "false");
|
|
1926
|
-
return (options, axiosRequestConfig) => {
|
|
1927
|
-
const { finalUrl, finalConfig } = getWrapContext(
|
|
1928
|
-
url,
|
|
1929
|
-
options,
|
|
1930
|
-
(0, import_axios5.mergeConfig)(defaultAxiosRequestConfig, axiosRequestConfig)
|
|
1931
|
-
);
|
|
1932
|
-
return instance.delete(finalUrl, finalConfig);
|
|
1933
|
-
};
|
|
1934
|
-
},
|
|
1804
|
+
wrapGet: wraps.wrapGet,
|
|
1805
|
+
wrapPost: wraps.wrapPost,
|
|
1806
|
+
wrapPut: wraps.wrapPut,
|
|
1807
|
+
wrapPatch: wraps.wrapPatch,
|
|
1808
|
+
wrapDelete: wraps.wrapDelete,
|
|
1935
1809
|
group: async (...proms) => {
|
|
1936
1810
|
let sharedConfig;
|
|
1937
1811
|
let sharedConfigKey;
|
|
1938
|
-
const defs = proms.map((prom) => {
|
|
1939
|
-
if (!(0,
|
|
1812
|
+
const defs = proms.map((prom, index) => {
|
|
1813
|
+
if (!(0, import_utils6.isEmpty)(prom.__requestConfig)) {
|
|
1940
1814
|
const configKey = serializeRequestConfig(prom.__requestConfig);
|
|
1941
1815
|
if (sharedConfigKey && sharedConfigKey !== configKey) {
|
|
1942
1816
|
throw new Error("Grouped requests must share the same axios request config");
|
|
@@ -1944,9 +1818,14 @@ function createAdapter(axiosConfig, adapterOptions) {
|
|
|
1944
1818
|
sharedConfig = prom.__requestConfig;
|
|
1945
1819
|
sharedConfigKey = configKey;
|
|
1946
1820
|
}
|
|
1947
|
-
|
|
1821
|
+
const query = { ...prom.__query };
|
|
1822
|
+
if (prom.__query.order == null) {
|
|
1823
|
+
query.order = index;
|
|
1824
|
+
}
|
|
1825
|
+
return query;
|
|
1948
1826
|
});
|
|
1949
1827
|
const result = await instance.post(rootRouterPath, defs, sharedConfig ?? {}).then((res) => {
|
|
1828
|
+
const responseHeaders = res.headers ?? {};
|
|
1950
1829
|
return res.data.map(({ result: result2, message, statusCode, op }, index) => {
|
|
1951
1830
|
const service = proms[index].__service;
|
|
1952
1831
|
const query = proms[index].__query;
|
|
@@ -1962,7 +1841,7 @@ function createAdapter(axiosConfig, adapterOptions) {
|
|
|
1962
1841
|
_raw = result2.data[0];
|
|
1963
1842
|
_data = Model.create(result2.data[0], modelService);
|
|
1964
1843
|
} else if (!["distinct", "subList"].includes(op)) {
|
|
1965
|
-
_data = (0,
|
|
1844
|
+
_data = (0, import_utils6.castArray)(result2.data).map((item) => Model.create(item, modelService));
|
|
1966
1845
|
}
|
|
1967
1846
|
} else if (result2.kind === "single" && ["new", "read", "update", "upsert"].includes(op)) {
|
|
1968
1847
|
_data = Model.create(result2.data, modelService);
|
|
@@ -1975,7 +1854,7 @@ function createAdapter(axiosConfig, adapterOptions) {
|
|
|
1975
1854
|
message,
|
|
1976
1855
|
status: statusCode,
|
|
1977
1856
|
totalCount: result2.success && result2.kind === "list" ? result2.totalCount ?? result2.count ?? 0 : 0,
|
|
1978
|
-
headers:
|
|
1857
|
+
headers: responseHeaders
|
|
1979
1858
|
};
|
|
1980
1859
|
});
|
|
1981
1860
|
});
|
|
@@ -1985,18 +1864,18 @@ function createAdapter(axiosConfig, adapterOptions) {
|
|
|
1985
1864
|
}
|
|
1986
1865
|
|
|
1987
1866
|
// src/utils.ts
|
|
1988
|
-
function replaceItemById(items,
|
|
1867
|
+
function replaceItemById(items, targetItem, options) {
|
|
1989
1868
|
const { merge = true } = options ?? {};
|
|
1990
1869
|
return items.map((item) => {
|
|
1991
|
-
if (item._id ===
|
|
1992
|
-
return merge ? { ...item, ...
|
|
1870
|
+
if (item._id === targetItem._id) {
|
|
1871
|
+
return merge ? { ...item, ...targetItem } : targetItem;
|
|
1993
1872
|
}
|
|
1994
1873
|
return item;
|
|
1995
1874
|
});
|
|
1996
1875
|
}
|
|
1997
|
-
function removeItemById(items,
|
|
1876
|
+
function removeItemById(items, targetItem) {
|
|
1998
1877
|
return items.filter((item) => {
|
|
1999
|
-
return item._id !==
|
|
1878
|
+
return item._id !== targetItem._id;
|
|
2000
1879
|
});
|
|
2001
1880
|
}
|
|
2002
1881
|
|
|
@@ -2004,6 +1883,7 @@ function removeItemById(items, newItem) {
|
|
|
2004
1883
|
var index_default = { createAdapter };
|
|
2005
1884
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2006
1885
|
0 && (module.exports = {
|
|
1886
|
+
CustomHeaders,
|
|
2007
1887
|
DataService,
|
|
2008
1888
|
Model,
|
|
2009
1889
|
ModelService,
|