av6-core 1.4.3 → 1.4.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/dist/index.js +13 -16
- package/dist/index.mjs +13 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -927,7 +927,7 @@ var buildRelationWrite = (rel, op, env) => {
|
|
|
927
927
|
if (writeCfg.strategy === "replace") return { deleteMany: {}, create: itemsCreate };
|
|
928
928
|
if (writeCfg.strategy === "upsert") {
|
|
929
929
|
const incomingIds = [];
|
|
930
|
-
const
|
|
930
|
+
const updateItems = [];
|
|
931
931
|
const createOnly = [];
|
|
932
932
|
for (const item of arr) {
|
|
933
933
|
const itemRec = isRecord(item) ? item : {};
|
|
@@ -940,14 +940,13 @@ var buildRelationWrite = (rel, op, env) => {
|
|
|
940
940
|
}
|
|
941
941
|
const pkNum = typeof pk === "string" ? Number(pk) : pk;
|
|
942
942
|
if (Number.isFinite(pkNum)) incomingIds.push(pkNum);
|
|
943
|
-
|
|
943
|
+
updateItems.push({
|
|
944
944
|
where: { [itemPrimaryKey]: pkNum },
|
|
945
|
-
create: dataCreate,
|
|
946
945
|
update: omitUndefined(dataUpdate)
|
|
947
946
|
});
|
|
948
947
|
}
|
|
949
948
|
const payload = {};
|
|
950
|
-
if (
|
|
949
|
+
if (updateItems.length) payload.update = updateItems;
|
|
951
950
|
if (createOnly.length) payload.create = createOnly;
|
|
952
951
|
const cfgAny = writeCfg;
|
|
953
952
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -958,18 +957,16 @@ var buildRelationWrite = (rel, op, env) => {
|
|
|
958
957
|
};
|
|
959
958
|
if (data.deletedAt === "now") data.deletedAt = now;
|
|
960
959
|
if (data.deletedBy === "ctx.userId") data.deletedBy = env.ctx.userId ?? void 0;
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
{
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
];
|
|
972
|
-
}
|
|
960
|
+
payload.updateMany = [
|
|
961
|
+
{
|
|
962
|
+
where: {
|
|
963
|
+
...whereExtra,
|
|
964
|
+
createdAt: { lt: now },
|
|
965
|
+
...incomingIds.length > 0 ? { [itemPrimaryKey]: { notIn: incomingIds } } : {}
|
|
966
|
+
},
|
|
967
|
+
data
|
|
968
|
+
}
|
|
969
|
+
];
|
|
973
970
|
}
|
|
974
971
|
return payload;
|
|
975
972
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -877,7 +877,7 @@ var buildRelationWrite = (rel, op, env) => {
|
|
|
877
877
|
if (writeCfg.strategy === "replace") return { deleteMany: {}, create: itemsCreate };
|
|
878
878
|
if (writeCfg.strategy === "upsert") {
|
|
879
879
|
const incomingIds = [];
|
|
880
|
-
const
|
|
880
|
+
const updateItems = [];
|
|
881
881
|
const createOnly = [];
|
|
882
882
|
for (const item of arr) {
|
|
883
883
|
const itemRec = isRecord(item) ? item : {};
|
|
@@ -890,14 +890,13 @@ var buildRelationWrite = (rel, op, env) => {
|
|
|
890
890
|
}
|
|
891
891
|
const pkNum = typeof pk === "string" ? Number(pk) : pk;
|
|
892
892
|
if (Number.isFinite(pkNum)) incomingIds.push(pkNum);
|
|
893
|
-
|
|
893
|
+
updateItems.push({
|
|
894
894
|
where: { [itemPrimaryKey]: pkNum },
|
|
895
|
-
create: dataCreate,
|
|
896
895
|
update: omitUndefined(dataUpdate)
|
|
897
896
|
});
|
|
898
897
|
}
|
|
899
898
|
const payload = {};
|
|
900
|
-
if (
|
|
899
|
+
if (updateItems.length) payload.update = updateItems;
|
|
901
900
|
if (createOnly.length) payload.create = createOnly;
|
|
902
901
|
const cfgAny = writeCfg;
|
|
903
902
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -908,18 +907,16 @@ var buildRelationWrite = (rel, op, env) => {
|
|
|
908
907
|
};
|
|
909
908
|
if (data.deletedAt === "now") data.deletedAt = now;
|
|
910
909
|
if (data.deletedBy === "ctx.userId") data.deletedBy = env.ctx.userId ?? void 0;
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
{
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
];
|
|
922
|
-
}
|
|
910
|
+
payload.updateMany = [
|
|
911
|
+
{
|
|
912
|
+
where: {
|
|
913
|
+
...whereExtra,
|
|
914
|
+
createdAt: { lt: now },
|
|
915
|
+
...incomingIds.length > 0 ? { [itemPrimaryKey]: { notIn: incomingIds } } : {}
|
|
916
|
+
},
|
|
917
|
+
data
|
|
918
|
+
}
|
|
919
|
+
];
|
|
923
920
|
}
|
|
924
921
|
return payload;
|
|
925
922
|
}
|