@dnax/core 0.1.6 → 0.1.8
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/driver/mongo/rest.ts +33 -24
- package/package.json +1 -1
package/driver/mongo/rest.ts
CHANGED
|
@@ -32,12 +32,13 @@ type options = {
|
|
|
32
32
|
tenant_id: string;
|
|
33
33
|
c?: Context;
|
|
34
34
|
useHook?: boolean;
|
|
35
|
-
|
|
35
|
+
useCustomApi?: boolean;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
type optionCb = {
|
|
39
39
|
useHook?: boolean;
|
|
40
40
|
cleanDeep?: boolean;
|
|
41
|
+
useCustomApi: boolean;
|
|
41
42
|
};
|
|
42
43
|
|
|
43
44
|
const omitUpdate = [
|
|
@@ -55,10 +56,10 @@ class useRest {
|
|
|
55
56
|
#tenant: Tenant;
|
|
56
57
|
#tenant_id: string;
|
|
57
58
|
#session: ClientSession | null | undefined;
|
|
58
|
-
#
|
|
59
|
+
#useCustomApi = true;
|
|
59
60
|
constructor(options: options) {
|
|
60
61
|
this.#c = options.c;
|
|
61
|
-
this.#
|
|
62
|
+
this.#useCustomApi = options.useCustomApi ?? true;
|
|
62
63
|
this.#tenant_id = options.tenant_id;
|
|
63
64
|
this.#session = null;
|
|
64
65
|
this.#tenant = getTenant(this.#tenant_id);
|
|
@@ -203,10 +204,12 @@ class useRest {
|
|
|
203
204
|
try {
|
|
204
205
|
let sharedData = {};
|
|
205
206
|
let useHook = options?.useHook ?? this.#useHook;
|
|
207
|
+
let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
|
|
208
|
+
|
|
206
209
|
let col = getCollection(collection, this.#tenant_id);
|
|
207
210
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
208
211
|
|
|
209
|
-
if (col?.customApi?.insertOne &&
|
|
212
|
+
if (col?.customApi?.insertOne && useCustomApi) {
|
|
210
213
|
let result = await col?.customApi?.insertOne({
|
|
211
214
|
io: Cfg.io,
|
|
212
215
|
session: sessionStorage(),
|
|
@@ -214,7 +217,7 @@ class useRest {
|
|
|
214
217
|
rest: new useRest({
|
|
215
218
|
useHook: false,
|
|
216
219
|
tenant_id: this.#tenant_id,
|
|
217
|
-
|
|
220
|
+
useCustomApi: false,
|
|
218
221
|
}),
|
|
219
222
|
});
|
|
220
223
|
return resolve(result);
|
|
@@ -305,9 +308,10 @@ class useRest {
|
|
|
305
308
|
let sharedData = {};
|
|
306
309
|
let col = getCollection(collection, this.#tenant_id);
|
|
307
310
|
let useHook = options?.useHook ?? this.#useHook;
|
|
311
|
+
let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
|
|
308
312
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
309
313
|
|
|
310
|
-
if (col?.customApi?.insertMany &&
|
|
314
|
+
if (col?.customApi?.insertMany && useCustomApi) {
|
|
311
315
|
let result = await col?.customApi?.insertMany({
|
|
312
316
|
io: Cfg.io,
|
|
313
317
|
session: sessionStorage(),
|
|
@@ -315,7 +319,7 @@ class useRest {
|
|
|
315
319
|
rest: new useRest({
|
|
316
320
|
useHook: false,
|
|
317
321
|
tenant_id: this.#tenant_id,
|
|
318
|
-
|
|
322
|
+
useCustomApi: false,
|
|
319
323
|
}),
|
|
320
324
|
});
|
|
321
325
|
return resolve(result);
|
|
@@ -412,6 +416,7 @@ class useRest {
|
|
|
412
416
|
return new Promise(async (resolve, reject) => {
|
|
413
417
|
try {
|
|
414
418
|
let useHook = options?.useHook ?? this.#useHook;
|
|
419
|
+
let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
|
|
415
420
|
let sharedData = {};
|
|
416
421
|
let result = {
|
|
417
422
|
docs: [],
|
|
@@ -419,7 +424,7 @@ class useRest {
|
|
|
419
424
|
|
|
420
425
|
let col = getCollection(collection, this.#tenant_id);
|
|
421
426
|
|
|
422
|
-
if (col?.customApi?.find &&
|
|
427
|
+
if (col?.customApi?.find && useCustomApi) {
|
|
423
428
|
let result = await col?.customApi?.find({
|
|
424
429
|
io: Cfg.io,
|
|
425
430
|
session: sessionStorage(),
|
|
@@ -427,7 +432,7 @@ class useRest {
|
|
|
427
432
|
rest: new useRest({
|
|
428
433
|
useHook: false,
|
|
429
434
|
tenant_id: this.#tenant_id,
|
|
430
|
-
|
|
435
|
+
useCustomApi: false,
|
|
431
436
|
}),
|
|
432
437
|
});
|
|
433
438
|
return resolve(result);
|
|
@@ -506,10 +511,11 @@ class useRest {
|
|
|
506
511
|
let sharedData = {};
|
|
507
512
|
let docs: Array<any> | any = [];
|
|
508
513
|
let useHook = options?.useHook ?? this.#useHook;
|
|
514
|
+
let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
|
|
509
515
|
|
|
510
516
|
let col = getCollection(collection, this.#tenant_id);
|
|
511
517
|
|
|
512
|
-
if (col?.customApi?.findOne &&
|
|
518
|
+
if (col?.customApi?.findOne && useCustomApi) {
|
|
513
519
|
let result = await col?.customApi?.findOne({
|
|
514
520
|
io: Cfg.io,
|
|
515
521
|
session: sessionStorage(),
|
|
@@ -518,7 +524,7 @@ class useRest {
|
|
|
518
524
|
rest: new useRest({
|
|
519
525
|
useHook: false,
|
|
520
526
|
tenant_id: this.#tenant_id,
|
|
521
|
-
|
|
527
|
+
useCustomApi: false,
|
|
522
528
|
}),
|
|
523
529
|
});
|
|
524
530
|
return resolve(result);
|
|
@@ -615,10 +621,13 @@ class useRest {
|
|
|
615
621
|
let result = {
|
|
616
622
|
doc: null,
|
|
617
623
|
};
|
|
624
|
+
let sharedData = {};
|
|
625
|
+
let useHook = options?.useHook ?? this.#useHook;
|
|
626
|
+
let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
|
|
618
627
|
let col = getCollection(collection, this.#tenant_id);
|
|
619
628
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
620
629
|
|
|
621
|
-
if (col?.customApi?.updateOne &&
|
|
630
|
+
if (col?.customApi?.updateOne && useCustomApi) {
|
|
622
631
|
let result = await col?.customApi?.updateOne({
|
|
623
632
|
io: Cfg.io,
|
|
624
633
|
session: sessionStorage(),
|
|
@@ -627,15 +636,12 @@ class useRest {
|
|
|
627
636
|
rest: new useRest({
|
|
628
637
|
useHook: false,
|
|
629
638
|
tenant_id: this.#tenant_id,
|
|
630
|
-
|
|
639
|
+
useCustomApi: false,
|
|
631
640
|
}),
|
|
632
641
|
});
|
|
633
642
|
return resolve(result);
|
|
634
643
|
}
|
|
635
644
|
|
|
636
|
-
let sharedData = {};
|
|
637
|
-
let useHook = options?.useHook ?? this.#useHook;
|
|
638
|
-
|
|
639
645
|
//@ts-expect-error
|
|
640
646
|
update = omit(update, omitUpdate);
|
|
641
647
|
|
|
@@ -865,9 +871,11 @@ class useRest {
|
|
|
865
871
|
docs: [],
|
|
866
872
|
};
|
|
867
873
|
let col = getCollection(collection, this.#tenant_id);
|
|
874
|
+
let useHook = options?.useHook ?? this.#useHook;
|
|
875
|
+
let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
|
|
868
876
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
869
877
|
|
|
870
|
-
if (col?.customApi?.updateMany &&
|
|
878
|
+
if (col?.customApi?.updateMany && useCustomApi) {
|
|
871
879
|
let result = await col?.customApi?.updateMany({
|
|
872
880
|
io: Cfg.io,
|
|
873
881
|
session: sessionStorage(),
|
|
@@ -876,14 +884,12 @@ class useRest {
|
|
|
876
884
|
rest: new useRest({
|
|
877
885
|
useHook: false,
|
|
878
886
|
tenant_id: this.#tenant_id,
|
|
879
|
-
|
|
887
|
+
useCustomApi: false,
|
|
880
888
|
}),
|
|
881
889
|
});
|
|
882
890
|
return resolve(result);
|
|
883
891
|
}
|
|
884
892
|
|
|
885
|
-
let useHook = options?.useHook ?? this.#useHook;
|
|
886
|
-
|
|
887
893
|
//@ts-expect-error
|
|
888
894
|
update = omit(update, omitUpdate);
|
|
889
895
|
|
|
@@ -1007,11 +1013,12 @@ class useRest {
|
|
|
1007
1013
|
try {
|
|
1008
1014
|
if (!id) fn.error("Id is required", 400);
|
|
1009
1015
|
let useHook = options?.useHook ?? this.#useHook;
|
|
1016
|
+
let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
|
|
1010
1017
|
|
|
1011
1018
|
let col = getCollection(collection, this.#tenant_id);
|
|
1012
1019
|
let sharedData = {};
|
|
1013
1020
|
|
|
1014
|
-
if (col?.customApi?.deleteOne &&
|
|
1021
|
+
if (col?.customApi?.deleteOne && useCustomApi) {
|
|
1015
1022
|
let result = await col?.customApi?.deleteOne({
|
|
1016
1023
|
io: Cfg.io,
|
|
1017
1024
|
session: sessionStorage(),
|
|
@@ -1019,7 +1026,7 @@ class useRest {
|
|
|
1019
1026
|
rest: new useRest({
|
|
1020
1027
|
useHook: false,
|
|
1021
1028
|
tenant_id: this.#tenant_id,
|
|
1022
|
-
|
|
1029
|
+
useCustomApi: false,
|
|
1023
1030
|
}),
|
|
1024
1031
|
});
|
|
1025
1032
|
return resolve(result!);
|
|
@@ -1095,10 +1102,12 @@ class useRest {
|
|
|
1095
1102
|
try {
|
|
1096
1103
|
let useHook = options?.useHook ?? this.#useHook;
|
|
1097
1104
|
|
|
1105
|
+
let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
|
|
1106
|
+
|
|
1098
1107
|
let sharedData = {};
|
|
1099
1108
|
let col = getCollection(collection, this.#tenant_id);
|
|
1100
1109
|
|
|
1101
|
-
if (col?.customApi?.deleteMany &&
|
|
1110
|
+
if (col?.customApi?.deleteMany && useCustomApi) {
|
|
1102
1111
|
let result = await col?.customApi?.deleteMany({
|
|
1103
1112
|
io: Cfg.io,
|
|
1104
1113
|
session: sessionStorage(),
|
|
@@ -1106,7 +1115,7 @@ class useRest {
|
|
|
1106
1115
|
rest: new useRest({
|
|
1107
1116
|
useHook: false,
|
|
1108
1117
|
tenant_id: this.#tenant_id,
|
|
1109
|
-
|
|
1118
|
+
useCustomApi: false,
|
|
1110
1119
|
}),
|
|
1111
1120
|
});
|
|
1112
1121
|
return resolve(result!);
|