@dnax/core 0.65.4 → 0.65.6
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 +46 -10
- package/package.json +1 -1
package/driver/mongo/rest.ts
CHANGED
|
@@ -330,7 +330,9 @@ class useRest {
|
|
|
330
330
|
async insertOne(
|
|
331
331
|
collection: string,
|
|
332
332
|
data: object,
|
|
333
|
-
options?: Omit<optionCb, "withMeta" | "elementAt">
|
|
333
|
+
options?: Omit<optionCb, "withMeta" | "elementAt"> & {
|
|
334
|
+
disableReadOnlyFields?: string[];
|
|
335
|
+
}
|
|
334
336
|
) {
|
|
335
337
|
return new Promise(async (resolve, reject) => {
|
|
336
338
|
try {
|
|
@@ -340,6 +342,10 @@ class useRest {
|
|
|
340
342
|
|
|
341
343
|
let col = getCollection(collection, this.#tenant_id);
|
|
342
344
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
345
|
+
let disableReadOnlyFields = omit(
|
|
346
|
+
col?.api?.fields?.readOnly || [],
|
|
347
|
+
options?.disableReadOnlyFields || []
|
|
348
|
+
) as string[];
|
|
343
349
|
|
|
344
350
|
// before operation
|
|
345
351
|
if (col?.hooks?.beforeOperation && useHook) {
|
|
@@ -397,7 +403,10 @@ class useRest {
|
|
|
397
403
|
data = await hashPasswordAuto(data, col);
|
|
398
404
|
data = transformAllDate(data);
|
|
399
405
|
data = deepSetId(col, data);
|
|
400
|
-
data = omit(
|
|
406
|
+
data = omit(
|
|
407
|
+
data,
|
|
408
|
+
["_id", "createdAt", "updatedAt"].concat(disableReadOnlyFields)
|
|
409
|
+
);
|
|
401
410
|
|
|
402
411
|
var { valid, output, error } = this.validator(collection, data);
|
|
403
412
|
if (!valid) fn.error(error, 400);
|
|
@@ -484,7 +493,9 @@ class useRest {
|
|
|
484
493
|
async insertMany(
|
|
485
494
|
collection: string,
|
|
486
495
|
data: Array<object>,
|
|
487
|
-
options?: Omit<optionCb, "withMeta" | "elementAt">
|
|
496
|
+
options?: Omit<optionCb, "withMeta" | "elementAt"> & {
|
|
497
|
+
disableReadOnlyFields?: string[];
|
|
498
|
+
}
|
|
488
499
|
) {
|
|
489
500
|
return new Promise(async (resolve, reject) => {
|
|
490
501
|
try {
|
|
@@ -493,7 +504,10 @@ class useRest {
|
|
|
493
504
|
let useHook = options?.useHook ?? this.#useHook;
|
|
494
505
|
let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
|
|
495
506
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
496
|
-
|
|
507
|
+
let disableReadOnlyFields = omit(
|
|
508
|
+
col?.api?.fields?.readOnly || [],
|
|
509
|
+
options?.disableReadOnlyFields || []
|
|
510
|
+
) as string[];
|
|
497
511
|
if (col?.hooks?.beforeOperation && useHook) {
|
|
498
512
|
await col.hooks.beforeOperation({
|
|
499
513
|
sharedData: sharedData,
|
|
@@ -548,6 +562,10 @@ class useRest {
|
|
|
548
562
|
d = await setUUID(d, col);
|
|
549
563
|
d = await randomCode(d, col);
|
|
550
564
|
d = await hashPasswordAuto(d, col);
|
|
565
|
+
d = omit(
|
|
566
|
+
d,
|
|
567
|
+
["_id", "createdAt", "updatedAt"].concat(disableReadOnlyFields)
|
|
568
|
+
);
|
|
551
569
|
d = deepSetId(col, d);
|
|
552
570
|
var { valid, output, error } = this.validator(collection, d);
|
|
553
571
|
if (!valid) fn.error(error, 400);
|
|
@@ -1085,7 +1103,10 @@ class useRest {
|
|
|
1085
1103
|
let allFieldKeys = getKeyFields(col);
|
|
1086
1104
|
|
|
1087
1105
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
1088
|
-
|
|
1106
|
+
let disableReadOnlyFields = omit(
|
|
1107
|
+
col?.api?.fields?.readOnly || [],
|
|
1108
|
+
options?.disableReadOnlyFields || []
|
|
1109
|
+
) as string[];
|
|
1089
1110
|
if (col?.hooks?.beforeOperation && useHook) {
|
|
1090
1111
|
await col.hooks.beforeOperation({
|
|
1091
1112
|
sharedData: sharedData,
|
|
@@ -1159,7 +1180,7 @@ class useRest {
|
|
|
1159
1180
|
omit(
|
|
1160
1181
|
update.$set,
|
|
1161
1182
|
["createdAt", "updatedAt", "_id"].concat(
|
|
1162
|
-
|
|
1183
|
+
disableReadOnlyFields || []
|
|
1163
1184
|
)
|
|
1164
1185
|
)
|
|
1165
1186
|
);
|
|
@@ -1288,6 +1309,10 @@ class useRest {
|
|
|
1288
1309
|
};
|
|
1289
1310
|
let col = getCollection(collection, this.#tenant_id);
|
|
1290
1311
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
1312
|
+
let disableReadOnlyFields = omit(
|
|
1313
|
+
col?.api?.fields?.readOnly || [],
|
|
1314
|
+
options?.disableReadOnlyFields || []
|
|
1315
|
+
) as string[];
|
|
1291
1316
|
update = toJson(update);
|
|
1292
1317
|
let sharedData = {};
|
|
1293
1318
|
//@ts-expect-error
|
|
@@ -1299,7 +1324,7 @@ class useRest {
|
|
|
1299
1324
|
omit(
|
|
1300
1325
|
update.$set,
|
|
1301
1326
|
["createdAt", "updatedAt", "_id"].concat(
|
|
1302
|
-
|
|
1327
|
+
disableReadOnlyFields || []
|
|
1303
1328
|
)
|
|
1304
1329
|
)
|
|
1305
1330
|
);
|
|
@@ -1406,6 +1431,10 @@ class useRest {
|
|
|
1406
1431
|
};
|
|
1407
1432
|
let col = getCollection(collection, this.#tenant_id);
|
|
1408
1433
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
1434
|
+
let disableReadOnlyFields = omit(
|
|
1435
|
+
col?.api?.fields?.readOnly || [],
|
|
1436
|
+
options?.disableReadOnlyFields || []
|
|
1437
|
+
) as string[];
|
|
1409
1438
|
update = toJson(update);
|
|
1410
1439
|
let sharedData = {};
|
|
1411
1440
|
|
|
@@ -1419,7 +1448,7 @@ class useRest {
|
|
|
1419
1448
|
omit(
|
|
1420
1449
|
update.$set,
|
|
1421
1450
|
["createdAt", "updatedAt", "_id"].concat(
|
|
1422
|
-
|
|
1451
|
+
disableReadOnlyFields || []
|
|
1423
1452
|
)
|
|
1424
1453
|
)
|
|
1425
1454
|
);
|
|
@@ -1553,6 +1582,10 @@ class useRest {
|
|
|
1553
1582
|
let useHook = options?.useHook ?? this.#useHook;
|
|
1554
1583
|
let useCustomApi = options?.useCustomApi ?? this.#useCustomApi;
|
|
1555
1584
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
1585
|
+
let disableReadOnlyFields = omit(
|
|
1586
|
+
col?.api?.fields?.readOnly || [],
|
|
1587
|
+
options?.disableReadOnlyFields || []
|
|
1588
|
+
) as string[];
|
|
1556
1589
|
let allFieldKeys = getKeyFields(col);
|
|
1557
1590
|
update = toJson(update);
|
|
1558
1591
|
|
|
@@ -1621,7 +1654,7 @@ class useRest {
|
|
|
1621
1654
|
omit(
|
|
1622
1655
|
update.$set,
|
|
1623
1656
|
["createdAt", "updatedAt", "_id"].concat(
|
|
1624
|
-
|
|
1657
|
+
disableReadOnlyFields || []
|
|
1625
1658
|
)
|
|
1626
1659
|
)
|
|
1627
1660
|
);
|
|
@@ -2057,7 +2090,10 @@ class useRest {
|
|
|
2057
2090
|
.dropIndex(indexName);
|
|
2058
2091
|
}
|
|
2059
2092
|
|
|
2060
|
-
startTransaction() {
|
|
2093
|
+
startTransaction(options?: { forceNew?: boolean }) {
|
|
2094
|
+
if (options?.forceNew) {
|
|
2095
|
+
this.#session = null;
|
|
2096
|
+
}
|
|
2061
2097
|
if (!this.#session) {
|
|
2062
2098
|
this.#session = this.#tenant.database.client?.startSession();
|
|
2063
2099
|
this.#session?.startTransaction();
|