@dnax/core 0.40.2 → 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 +98 -63
- package/package.json +1 -1
- package/types/index.ts +1 -0
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 {
|
|
@@ -1077,56 +1084,98 @@ class useRest {
|
|
|
1077
1084
|
});
|
|
1078
1085
|
}
|
|
1079
1086
|
|
|
1080
|
-
async
|
|
1087
|
+
async findAndUpdate(
|
|
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
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
});
|
|
1105
|
+
//@ts-expect-error
|
|
1106
|
+
update = omit(update, omitUpdate);
|
|
1107
|
+
if (update.$set) {
|
|
1108
|
+
// update.$set = deepSetId(col, update.$set);
|
|
1109
|
+
update.$set = deepSetId(col, update.$set);
|
|
1110
|
+
update.$set = transformAllDate(update.$set);
|
|
1111
|
+
update.$set = await hashPasswordAuto(update.$set, col);
|
|
1112
|
+
var { valid, output, error } = this.validator(
|
|
1113
|
+
collection,
|
|
1114
|
+
update.$set,
|
|
1115
|
+
{
|
|
1116
|
+
partial: true,
|
|
1117
|
+
}
|
|
1118
|
+
);
|
|
1119
|
+
// update.$set = output;
|
|
1120
|
+
if (!valid) fn.error(error, 400);
|
|
1112
1121
|
}
|
|
1113
1122
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1123
|
+
let up_ = await this.#tenant.database.db
|
|
1124
|
+
?.collection(collection)
|
|
1125
|
+
.updateMany(
|
|
1126
|
+
{
|
|
1127
|
+
...(formatData(filter) || {}),
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
...formatData(omit(update, omitUpdate), {
|
|
1131
|
+
collection: collection,
|
|
1132
|
+
tenant_id: this.#tenant_id,
|
|
1133
|
+
}),
|
|
1134
|
+
$currentDate: {
|
|
1135
|
+
updatedAt: true,
|
|
1136
|
+
},
|
|
1137
|
+
},
|
|
1138
|
+
{
|
|
1139
|
+
session: this.#session ? this.#session : undefined,
|
|
1140
|
+
}
|
|
1141
|
+
);
|
|
1142
|
+
|
|
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
|
+
});
|
|
1155
|
+
} catch (err) {
|
|
1156
|
+
return reject(err);
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
async findOneAndUpdate(
|
|
1162
|
+
collection: string,
|
|
1163
|
+
filter: object,
|
|
1164
|
+
update: updateParams,
|
|
1165
|
+
options?: Omit<
|
|
1166
|
+
optionCb,
|
|
1167
|
+
"useHook" | "useCustomApi" | "elementAt" | "withMeta"
|
|
1168
|
+
>
|
|
1169
|
+
): Promise<object | null> {
|
|
1170
|
+
return new Promise(async (resolve, reject) => {
|
|
1171
|
+
try {
|
|
1172
|
+
let result = {
|
|
1173
|
+
doc: null,
|
|
1174
|
+
};
|
|
1175
|
+
let col = getCollection(collection, this.#tenant_id);
|
|
1176
|
+
if (!col) return fn.error(`Collection ${collection} not found`, 404);
|
|
1177
|
+
update = toJson(update);
|
|
1178
|
+
let sharedData = {};
|
|
1130
1179
|
|
|
1131
1180
|
//@ts-expect-error
|
|
1132
1181
|
update = omit(update, omitUpdate);
|
|
@@ -1170,24 +1219,6 @@ class useRest {
|
|
|
1170
1219
|
}
|
|
1171
1220
|
);
|
|
1172
1221
|
|
|
1173
|
-
if (col?.hooks?.afterUpdate && useHook) {
|
|
1174
|
-
await col.hooks.afterUpdate({
|
|
1175
|
-
sharedData: sharedData,
|
|
1176
|
-
c: this.#c,
|
|
1177
|
-
driver: "mongodb",
|
|
1178
|
-
filter: filter,
|
|
1179
|
-
action: "updateOne",
|
|
1180
|
-
update: update,
|
|
1181
|
-
session: sessionStorage(),
|
|
1182
|
-
result: result.doc,
|
|
1183
|
-
io: Cfg.io,
|
|
1184
|
-
rest: new useRest({
|
|
1185
|
-
useHook: false,
|
|
1186
|
-
tenant_id: this.#tenant_id,
|
|
1187
|
-
}),
|
|
1188
|
-
});
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
1222
|
return resolve(result.doc);
|
|
1192
1223
|
} catch (err) {
|
|
1193
1224
|
return reject(err);
|
|
@@ -1368,7 +1399,7 @@ class useRest {
|
|
|
1368
1399
|
async deleteOne(
|
|
1369
1400
|
collection: string,
|
|
1370
1401
|
id: string,
|
|
1371
|
-
options?: optionCb
|
|
1402
|
+
options?: Omit<optionCb, "useCustomApi" | "withMeta" | "elementAt">
|
|
1372
1403
|
): Promise<object> {
|
|
1373
1404
|
return new Promise(async (resolve, reject) => {
|
|
1374
1405
|
try {
|
|
@@ -1473,7 +1504,11 @@ class useRest {
|
|
|
1473
1504
|
}
|
|
1474
1505
|
});
|
|
1475
1506
|
}
|
|
1476
|
-
async deleteMany(
|
|
1507
|
+
async deleteMany(
|
|
1508
|
+
collection: string,
|
|
1509
|
+
ids: Array<string>,
|
|
1510
|
+
options?: Omit<optionCb, "useCustomApi" | "withMeta" | "elementAt">
|
|
1511
|
+
) {
|
|
1477
1512
|
return new Promise(async (resolve, reject) => {
|
|
1478
1513
|
try {
|
|
1479
1514
|
let useHook = options?.useHook ?? this.#useHook;
|
package/package.json
CHANGED