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