@dnax/core 0.41.0 → 0.42.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/driver/mongo/rest.ts +43 -122
- package/package.json +1 -1
package/driver/mongo/rest.ts
CHANGED
|
@@ -188,7 +188,7 @@ class useRest {
|
|
|
188
188
|
async aggregate(
|
|
189
189
|
collection: string,
|
|
190
190
|
pipeline: Array<object>,
|
|
191
|
-
options?: optionCb
|
|
191
|
+
options?: Omit<optionCb, "withMeta" | "elementAt">
|
|
192
192
|
) {
|
|
193
193
|
return new Promise(async (resolve, reject) => {
|
|
194
194
|
try {
|
|
@@ -264,7 +264,11 @@ class useRest {
|
|
|
264
264
|
}
|
|
265
265
|
});
|
|
266
266
|
}
|
|
267
|
-
async insertOne(
|
|
267
|
+
async insertOne(
|
|
268
|
+
collection: string,
|
|
269
|
+
data: object,
|
|
270
|
+
options?: Omit<optionCb, "withMeta" | "elementAt">
|
|
271
|
+
) {
|
|
268
272
|
return new Promise(async (resolve, reject) => {
|
|
269
273
|
try {
|
|
270
274
|
let sharedData = {};
|
|
@@ -388,7 +392,7 @@ class useRest {
|
|
|
388
392
|
async insertMany(
|
|
389
393
|
collection: string,
|
|
390
394
|
data: Array<object>,
|
|
391
|
-
options?: optionCb
|
|
395
|
+
options?: Omit<optionCb, "withMeta" | "elementAt">
|
|
392
396
|
) {
|
|
393
397
|
return new Promise(async (resolve, reject) => {
|
|
394
398
|
try {
|
|
@@ -689,7 +693,10 @@ class useRest {
|
|
|
689
693
|
async count(
|
|
690
694
|
collection: string,
|
|
691
695
|
params: findParam,
|
|
692
|
-
options?:
|
|
696
|
+
options?: Omit<
|
|
697
|
+
optionCb,
|
|
698
|
+
"useCustomApi" | "withMeta" | "elementAt" | "useHook"
|
|
699
|
+
>
|
|
693
700
|
): Promise<number> {
|
|
694
701
|
return new Promise(async (resolve, reject) => {
|
|
695
702
|
try {
|
|
@@ -806,7 +813,7 @@ class useRest {
|
|
|
806
813
|
collection: string,
|
|
807
814
|
id: string,
|
|
808
815
|
params?: findOneParam,
|
|
809
|
-
options?: optionCb
|
|
816
|
+
options?: Omit<optionCb, "elementAt" | "withMeta">
|
|
810
817
|
): Promise<object | null> {
|
|
811
818
|
return new Promise(async (resolve, reject) => {
|
|
812
819
|
try {
|
|
@@ -918,7 +925,7 @@ class useRest {
|
|
|
918
925
|
collection: string,
|
|
919
926
|
id: string,
|
|
920
927
|
update: updateParams,
|
|
921
|
-
options?: optionCb
|
|
928
|
+
options?: Omit<optionCb, "withMeta" | "elementAt" | "withMeta">
|
|
922
929
|
): Promise<object> {
|
|
923
930
|
return new Promise(async (resolve, reject) => {
|
|
924
931
|
try {
|
|
@@ -1081,53 +1088,20 @@ class useRest {
|
|
|
1081
1088
|
collection: string,
|
|
1082
1089
|
filter: object,
|
|
1083
1090
|
update: updateParams,
|
|
1084
|
-
options?:
|
|
1085
|
-
|
|
1091
|
+
options?: Omit<
|
|
1092
|
+
optionCb,
|
|
1093
|
+
"useHook" | "useCustomApi" | "elementAt" | "withMeta"
|
|
1094
|
+
>
|
|
1095
|
+
): Promise<{ docs: object[]; matchedCount: number; modifiedCount: number }> {
|
|
1086
1096
|
return new Promise(async (resolve, reject) => {
|
|
1087
1097
|
try {
|
|
1088
1098
|
let result = {
|
|
1089
|
-
|
|
1099
|
+
docs: [] as Array<object>,
|
|
1090
1100
|
};
|
|
1091
1101
|
let col = getCollection(collection, this.#tenant_id);
|
|
1092
1102
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
1093
1103
|
update = toJson(update);
|
|
1094
1104
|
let sharedData = {};
|
|
1095
|
-
let useHook = options?.useHook ?? this.#useHook;
|
|
1096
|
-
if (col?.hooks?.beforeOperation && useHook) {
|
|
1097
|
-
await col.hooks.beforeOperation({
|
|
1098
|
-
sharedData: sharedData,
|
|
1099
|
-
filter: filter || {},
|
|
1100
|
-
c: this.#c,
|
|
1101
|
-
error: fn.error,
|
|
1102
|
-
io: Cfg.io,
|
|
1103
|
-
driver: "mongodb",
|
|
1104
|
-
action: "findAndUpdate",
|
|
1105
|
-
update: update,
|
|
1106
|
-
session: sessionStorage(),
|
|
1107
|
-
rest: new useRest({
|
|
1108
|
-
useHook: false,
|
|
1109
|
-
tenant_id: this.#tenant_id,
|
|
1110
|
-
}),
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
if (col?.hooks?.beforeUpdate && useHook) {
|
|
1115
|
-
await col.hooks.beforeUpdate({
|
|
1116
|
-
sharedData: sharedData,
|
|
1117
|
-
c: this.#c,
|
|
1118
|
-
filter: filter || {},
|
|
1119
|
-
driver: "mongodb",
|
|
1120
|
-
io: Cfg.io,
|
|
1121
|
-
action: "findAndUpdate",
|
|
1122
|
-
update: update,
|
|
1123
|
-
session: sessionStorage(),
|
|
1124
|
-
rest: new useRest({
|
|
1125
|
-
useHook: false,
|
|
1126
|
-
tenant_id: this.#tenant_id,
|
|
1127
|
-
}),
|
|
1128
|
-
});
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
1105
|
//@ts-expect-error
|
|
1132
1106
|
update = omit(update, omitUpdate);
|
|
1133
1107
|
if (update.$set) {
|
|
@@ -1146,7 +1120,7 @@ class useRest {
|
|
|
1146
1120
|
if (!valid) fn.error(error, 400);
|
|
1147
1121
|
}
|
|
1148
1122
|
|
|
1149
|
-
|
|
1123
|
+
let up_ = await this.#tenant.database.db
|
|
1150
1124
|
?.collection(collection)
|
|
1151
1125
|
.updateMany(
|
|
1152
1126
|
{
|
|
@@ -1166,25 +1140,18 @@ class useRest {
|
|
|
1166
1140
|
}
|
|
1167
1141
|
);
|
|
1168
1142
|
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
useHook: false,
|
|
1182
|
-
tenant_id: this.#tenant_id,
|
|
1183
|
-
}),
|
|
1184
|
-
});
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
return resolve(result.doc);
|
|
1143
|
+
result.docs = await this.#tenant.database.db
|
|
1144
|
+
.collection(collection)
|
|
1145
|
+
.find(filter, {
|
|
1146
|
+
session: this.#session ? this.#session : undefined,
|
|
1147
|
+
allowDiskUse: true,
|
|
1148
|
+
})
|
|
1149
|
+
.toArray();
|
|
1150
|
+
return resolve({
|
|
1151
|
+
docs: result.docs,
|
|
1152
|
+
matchedCount: up_?.matchedCount || 0,
|
|
1153
|
+
modifiedCount: up_?.modifiedCount || 0,
|
|
1154
|
+
});
|
|
1188
1155
|
} catch (err) {
|
|
1189
1156
|
return reject(err);
|
|
1190
1157
|
}
|
|
@@ -1195,8 +1162,11 @@ class useRest {
|
|
|
1195
1162
|
collection: string,
|
|
1196
1163
|
filter: object,
|
|
1197
1164
|
update: updateParams,
|
|
1198
|
-
options?:
|
|
1199
|
-
|
|
1165
|
+
options?: Omit<
|
|
1166
|
+
optionCb,
|
|
1167
|
+
"useHook" | "useCustomApi" | "elementAt" | "withMeta"
|
|
1168
|
+
>
|
|
1169
|
+
): Promise<object | null> {
|
|
1200
1170
|
return new Promise(async (resolve, reject) => {
|
|
1201
1171
|
try {
|
|
1202
1172
|
let result = {
|
|
@@ -1206,41 +1176,6 @@ class useRest {
|
|
|
1206
1176
|
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
1207
1177
|
update = toJson(update);
|
|
1208
1178
|
let sharedData = {};
|
|
1209
|
-
let useHook = options?.useHook ?? this.#useHook;
|
|
1210
|
-
if (col?.hooks?.beforeOperation && useHook) {
|
|
1211
|
-
await col.hooks.beforeOperation({
|
|
1212
|
-
sharedData: sharedData,
|
|
1213
|
-
filter: filter || {},
|
|
1214
|
-
c: this.#c,
|
|
1215
|
-
error: fn.error,
|
|
1216
|
-
io: Cfg.io,
|
|
1217
|
-
driver: "mongodb",
|
|
1218
|
-
action: "findOneAndUpdate",
|
|
1219
|
-
update: update,
|
|
1220
|
-
session: sessionStorage(),
|
|
1221
|
-
rest: new useRest({
|
|
1222
|
-
useHook: false,
|
|
1223
|
-
tenant_id: this.#tenant_id,
|
|
1224
|
-
}),
|
|
1225
|
-
});
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
if (col?.hooks?.beforeUpdate && useHook) {
|
|
1229
|
-
await col.hooks.beforeUpdate({
|
|
1230
|
-
sharedData: sharedData,
|
|
1231
|
-
c: this.#c,
|
|
1232
|
-
filter: filter || {},
|
|
1233
|
-
driver: "mongodb",
|
|
1234
|
-
io: Cfg.io,
|
|
1235
|
-
action: "findOneAndUpdate",
|
|
1236
|
-
update: update,
|
|
1237
|
-
session: sessionStorage(),
|
|
1238
|
-
rest: new useRest({
|
|
1239
|
-
useHook: false,
|
|
1240
|
-
tenant_id: this.#tenant_id,
|
|
1241
|
-
}),
|
|
1242
|
-
});
|
|
1243
|
-
}
|
|
1244
1179
|
|
|
1245
1180
|
//@ts-expect-error
|
|
1246
1181
|
update = omit(update, omitUpdate);
|
|
@@ -1284,24 +1219,6 @@ class useRest {
|
|
|
1284
1219
|
}
|
|
1285
1220
|
);
|
|
1286
1221
|
|
|
1287
|
-
if (col?.hooks?.afterUpdate && useHook) {
|
|
1288
|
-
await col.hooks.afterUpdate({
|
|
1289
|
-
sharedData: sharedData,
|
|
1290
|
-
c: this.#c,
|
|
1291
|
-
driver: "mongodb",
|
|
1292
|
-
filter: filter,
|
|
1293
|
-
action: "findOneAndUpdate",
|
|
1294
|
-
update: update,
|
|
1295
|
-
session: sessionStorage(),
|
|
1296
|
-
result: result.doc,
|
|
1297
|
-
io: Cfg.io,
|
|
1298
|
-
rest: new useRest({
|
|
1299
|
-
useHook: false,
|
|
1300
|
-
tenant_id: this.#tenant_id,
|
|
1301
|
-
}),
|
|
1302
|
-
});
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
1222
|
return resolve(result.doc);
|
|
1306
1223
|
} catch (err) {
|
|
1307
1224
|
return reject(err);
|
|
@@ -1482,7 +1399,7 @@ class useRest {
|
|
|
1482
1399
|
async deleteOne(
|
|
1483
1400
|
collection: string,
|
|
1484
1401
|
id: string,
|
|
1485
|
-
options?: optionCb
|
|
1402
|
+
options?: Omit<optionCb, "useCustomApi" | "withMeta" | "elementAt">
|
|
1486
1403
|
): Promise<object> {
|
|
1487
1404
|
return new Promise(async (resolve, reject) => {
|
|
1488
1405
|
try {
|
|
@@ -1587,7 +1504,11 @@ class useRest {
|
|
|
1587
1504
|
}
|
|
1588
1505
|
});
|
|
1589
1506
|
}
|
|
1590
|
-
async deleteMany(
|
|
1507
|
+
async deleteMany(
|
|
1508
|
+
collection: string,
|
|
1509
|
+
ids: Array<string>,
|
|
1510
|
+
options?: Omit<optionCb, "useCustomApi" | "withMeta" | "elementAt">
|
|
1511
|
+
) {
|
|
1591
1512
|
return new Promise(async (resolve, reject) => {
|
|
1592
1513
|
try {
|
|
1593
1514
|
let useHook = options?.useHook ?? this.#useHook;
|