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