@dnax/core 0.73.2 → 0.73.4
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 +10 -2
- package/driver/mongo/utils.ts +5 -2
- package/package.json +1 -1
package/driver/mongo/rest.ts
CHANGED
|
@@ -1653,6 +1653,12 @@ class useRest {
|
|
|
1653
1653
|
},
|
|
1654
1654
|
$setOnInsert: {
|
|
1655
1655
|
createdAt: new Date(),
|
|
1656
|
+
...formatData(update?.$setOnInsert || {}, {
|
|
1657
|
+
collection: collection,
|
|
1658
|
+
tenant_id: this.#tenant_id,
|
|
1659
|
+
action: "updateMany",
|
|
1660
|
+
upsert: true,
|
|
1661
|
+
}),
|
|
1656
1662
|
},
|
|
1657
1663
|
},
|
|
1658
1664
|
{
|
|
@@ -1808,14 +1814,16 @@ class useRest {
|
|
|
1808
1814
|
collection: collection,
|
|
1809
1815
|
tenant_id: this.#tenant_id,
|
|
1810
1816
|
}),
|
|
1817
|
+
|
|
1811
1818
|
$setOnInsert: {
|
|
1812
1819
|
...formatData(update?.$setOnInsert || {}, {
|
|
1813
1820
|
collection: collection,
|
|
1814
1821
|
tenant_id: this.#tenant_id,
|
|
1822
|
+
action: "insertOne",
|
|
1823
|
+
upsert: true,
|
|
1815
1824
|
}),
|
|
1816
|
-
//updatedAt: new Date(),
|
|
1817
|
-
createdAt: new Date(),
|
|
1818
1825
|
},
|
|
1826
|
+
|
|
1819
1827
|
$currentDate: {
|
|
1820
1828
|
updatedAt: true,
|
|
1821
1829
|
},
|
package/driver/mongo/utils.ts
CHANGED
|
@@ -188,6 +188,7 @@ function transformAllDate(data: object) {
|
|
|
188
188
|
function toBson<T>(
|
|
189
189
|
data: object | T,
|
|
190
190
|
options?: {
|
|
191
|
+
upsert?: boolean;
|
|
191
192
|
action?:
|
|
192
193
|
| "insertOne"
|
|
193
194
|
| "insertMany"
|
|
@@ -204,14 +205,14 @@ function toBson<T>(
|
|
|
204
205
|
// InsertOne
|
|
205
206
|
if (options?.action == "insertOne") {
|
|
206
207
|
data.createdAt = new Date();
|
|
207
|
-
data.updatedAt = new Date();
|
|
208
|
+
if (!options?.upsert) data.updatedAt = new Date();
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
// insertMany
|
|
211
212
|
if (options?.action == "insertMany" && Array.isArray(data)) {
|
|
212
213
|
data?.map((d) => {
|
|
213
214
|
d.createdAt = new Date();
|
|
214
|
-
d.updatedAt = new Date();
|
|
215
|
+
if (!options?.upsert) d.updatedAt = new Date();
|
|
215
216
|
});
|
|
216
217
|
}
|
|
217
218
|
|
|
@@ -414,6 +415,7 @@ function formatData(
|
|
|
414
415
|
collection?: string;
|
|
415
416
|
action?: Actions;
|
|
416
417
|
tenant_id: string;
|
|
418
|
+
upsert?: boolean;
|
|
417
419
|
} = {
|
|
418
420
|
tenant_id: "_",
|
|
419
421
|
collection: "",
|
|
@@ -424,6 +426,7 @@ function formatData(
|
|
|
424
426
|
data = deepSetId(col, data);
|
|
425
427
|
}
|
|
426
428
|
data = toBson(data, {
|
|
429
|
+
upsert: options?.upsert,
|
|
427
430
|
action: options?.action,
|
|
428
431
|
});
|
|
429
432
|
|