supabase-typed-query 0.8.0 → 0.9.1
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 +72 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -17
- package/dist/index.mjs.map +1 -1
- package/dist/src/entity/Entity.d.ts.map +1 -1
- package/dist/src/entity/PartitionedEntity.d.ts.map +1 -1
- package/dist/src/entity/core.d.ts +12 -8
- package/dist/src/entity/core.d.ts.map +1 -1
- package/dist/src/entity/index.d.ts +1 -1
- package/dist/src/entity/index.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/query/index.d.ts +26 -0
- package/dist/src/query/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -703,6 +703,44 @@ const deleteEntities = (client, table, where, is, wherein, schema) => wrapAsync(
|
|
|
703
703
|
return functype.Err(toError(error));
|
|
704
704
|
}
|
|
705
705
|
});
|
|
706
|
+
const softDeleteEntity = (client, table, where, is, wherein, schema) => wrapAsync(async () => {
|
|
707
|
+
try {
|
|
708
|
+
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
709
|
+
const baseQuery = tableQuery.update({ deleted: (/* @__PURE__ */ new Date()).toISOString() }).match(where);
|
|
710
|
+
const queryWithIn = wherein ? functype.List(Object.entries(wherein)).foldLeft(baseQuery)(
|
|
711
|
+
(query2, [column, values]) => query2.in(column, values)
|
|
712
|
+
) : baseQuery;
|
|
713
|
+
const queryWithIs = is ? functype.List(Object.entries(is)).foldLeft(queryWithIn)(
|
|
714
|
+
(query2, [column, value]) => query2.is(column, value)
|
|
715
|
+
) : queryWithIn;
|
|
716
|
+
const { data, error } = await queryWithIs.select().single();
|
|
717
|
+
if (error) {
|
|
718
|
+
return functype.Err(toError(error));
|
|
719
|
+
}
|
|
720
|
+
return functype.Ok(data);
|
|
721
|
+
} catch (error) {
|
|
722
|
+
return functype.Err(toError(error));
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
const softDeleteEntities = (client, table, where, is, wherein, schema) => wrapAsync(async () => {
|
|
726
|
+
try {
|
|
727
|
+
const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
|
|
728
|
+
const baseQuery = tableQuery.update({ deleted: (/* @__PURE__ */ new Date()).toISOString() }).match(where);
|
|
729
|
+
const queryWithIn = wherein ? functype.List(Object.entries(wherein)).foldLeft(baseQuery)(
|
|
730
|
+
(query2, [column, values]) => query2.in(column, values)
|
|
731
|
+
) : baseQuery;
|
|
732
|
+
const queryWithIs = is ? functype.List(Object.entries(is)).foldLeft(queryWithIn)(
|
|
733
|
+
(query2, [column, value]) => query2.is(column, value)
|
|
734
|
+
) : queryWithIn;
|
|
735
|
+
const { data, error } = await queryWithIs.select();
|
|
736
|
+
if (error) {
|
|
737
|
+
return functype.Err(toError(error));
|
|
738
|
+
}
|
|
739
|
+
return functype.Ok(functype.List(data));
|
|
740
|
+
} catch (error) {
|
|
741
|
+
return functype.Err(toError(error));
|
|
742
|
+
}
|
|
743
|
+
});
|
|
706
744
|
const query = (client, table, where = {}, is, wherein, order, schema) => {
|
|
707
745
|
return createQuery(client, table, where, is, wherein, order, void 0, schema);
|
|
708
746
|
};
|
|
@@ -918,22 +956,28 @@ function makePartitionedUpsertItems(client, name, _partitionField, schema) {
|
|
|
918
956
|
return createUpsertItemsMutation(client, name, items, identity, schema);
|
|
919
957
|
};
|
|
920
958
|
}
|
|
921
|
-
function createDeleteItemMutation(client, name, whereConditions, is, wherein, schema) {
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
);
|
|
959
|
+
function createDeleteItemMutation(client, name, whereConditions, is, wherein, softDelete, schema) {
|
|
960
|
+
const operation = softDelete ? softDeleteEntity(client, name, whereConditions, is, wherein, schema) : deleteEntity(client, name, whereConditions, is, wherein, schema);
|
|
961
|
+
return SingleMutationQuery(operation);
|
|
925
962
|
}
|
|
926
|
-
function createDeleteItemsMutation(client, name, whereConditions, is, wherein, schema) {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
);
|
|
963
|
+
function createDeleteItemsMutation(client, name, whereConditions, is, wherein, softDelete, schema) {
|
|
964
|
+
const operation = softDelete ? softDeleteEntities(client, name, whereConditions, is, wherein, schema) : deleteEntities(client, name, whereConditions, is, wherein, schema);
|
|
965
|
+
return MultiMutationQuery(operation);
|
|
930
966
|
}
|
|
931
|
-
function makeDeleteItem(client, name, schema) {
|
|
967
|
+
function makeDeleteItem(client, name, softDelete, schema) {
|
|
932
968
|
return function deleteItem({ where, is, wherein }) {
|
|
933
|
-
return createDeleteItemMutation(
|
|
969
|
+
return createDeleteItemMutation(
|
|
970
|
+
client,
|
|
971
|
+
name,
|
|
972
|
+
where,
|
|
973
|
+
is,
|
|
974
|
+
wherein,
|
|
975
|
+
softDelete,
|
|
976
|
+
schema
|
|
977
|
+
);
|
|
934
978
|
};
|
|
935
979
|
}
|
|
936
|
-
function makeDeleteItems(client, name, schema) {
|
|
980
|
+
function makeDeleteItems(client, name, softDelete, schema) {
|
|
937
981
|
return function deleteItems({ where, is, wherein }) {
|
|
938
982
|
return createDeleteItemsMutation(
|
|
939
983
|
client,
|
|
@@ -941,11 +985,12 @@ function makeDeleteItems(client, name, schema) {
|
|
|
941
985
|
where,
|
|
942
986
|
is,
|
|
943
987
|
wherein,
|
|
988
|
+
softDelete,
|
|
944
989
|
schema
|
|
945
990
|
);
|
|
946
991
|
};
|
|
947
992
|
}
|
|
948
|
-
function makePartitionedDeleteItem(client, name, partitionField, schema) {
|
|
993
|
+
function makePartitionedDeleteItem(client, name, partitionField, softDelete, schema) {
|
|
949
994
|
return function deleteItem(partitionKey, { where, is, wherein }) {
|
|
950
995
|
const whereConditions = buildWhereWithPartition(partitionField, partitionKey, where);
|
|
951
996
|
return createDeleteItemMutation(
|
|
@@ -954,11 +999,12 @@ function makePartitionedDeleteItem(client, name, partitionField, schema) {
|
|
|
954
999
|
whereConditions,
|
|
955
1000
|
is,
|
|
956
1001
|
wherein,
|
|
1002
|
+
softDelete,
|
|
957
1003
|
schema
|
|
958
1004
|
);
|
|
959
1005
|
};
|
|
960
1006
|
}
|
|
961
|
-
function makePartitionedDeleteItems(client, name, partitionField, schema) {
|
|
1007
|
+
function makePartitionedDeleteItems(client, name, partitionField, softDelete, schema) {
|
|
962
1008
|
return function deleteItems(partitionKey, { where, is, wherein }) {
|
|
963
1009
|
const whereConditions = buildWhereWithPartition(partitionField, partitionKey, where);
|
|
964
1010
|
return createDeleteItemsMutation(
|
|
@@ -967,6 +1013,7 @@ function makePartitionedDeleteItems(client, name, partitionField, schema) {
|
|
|
967
1013
|
whereConditions,
|
|
968
1014
|
is,
|
|
969
1015
|
wherein,
|
|
1016
|
+
softDelete,
|
|
970
1017
|
schema
|
|
971
1018
|
);
|
|
972
1019
|
};
|
|
@@ -1013,16 +1060,18 @@ const Entity = (client, name, config) => {
|
|
|
1013
1060
|
upsertItems: makeUpsertItems(client, name, schema),
|
|
1014
1061
|
/**
|
|
1015
1062
|
* Delete a single item from the table.
|
|
1063
|
+
* When softDelete is true, sets the deleted timestamp instead of hard deleting.
|
|
1016
1064
|
* @param params Delete parameters including where conditions
|
|
1017
1065
|
* @returns A mutation query with OrThrow methods, returns deleted row
|
|
1018
1066
|
*/
|
|
1019
|
-
deleteItem: makeDeleteItem(client, name, schema),
|
|
1067
|
+
deleteItem: makeDeleteItem(client, name, config.softDelete, schema),
|
|
1020
1068
|
/**
|
|
1021
1069
|
* Delete multiple items from the table.
|
|
1070
|
+
* When softDelete is true, sets the deleted timestamp instead of hard deleting.
|
|
1022
1071
|
* @param params Delete parameters including where conditions
|
|
1023
1072
|
* @returns A mutation query with OrThrow methods, returns deleted rows
|
|
1024
1073
|
*/
|
|
1025
|
-
deleteItems: makeDeleteItems(client, name, schema)
|
|
1074
|
+
deleteItems: makeDeleteItems(client, name, config.softDelete, schema)
|
|
1026
1075
|
};
|
|
1027
1076
|
};
|
|
1028
1077
|
const PartitionedEntity = (client, name, config) => {
|
|
@@ -1074,18 +1123,20 @@ const PartitionedEntity = (client, name, config) => {
|
|
|
1074
1123
|
upsertItems: makePartitionedUpsertItems(client, name, partitionField, schema),
|
|
1075
1124
|
/**
|
|
1076
1125
|
* Delete a single item from the table within a partition.
|
|
1126
|
+
* When softDelete is true, sets the deleted timestamp instead of hard deleting.
|
|
1077
1127
|
* @param partitionKey The partition key value (e.g., tenantId)
|
|
1078
1128
|
* @param params Delete parameters including where conditions
|
|
1079
1129
|
* @returns A mutation query with OrThrow methods, returns deleted row
|
|
1080
1130
|
*/
|
|
1081
|
-
deleteItem: makePartitionedDeleteItem(client, name, partitionField, schema),
|
|
1131
|
+
deleteItem: makePartitionedDeleteItem(client, name, partitionField, config.softDelete, schema),
|
|
1082
1132
|
/**
|
|
1083
1133
|
* Delete multiple items from the table within a partition.
|
|
1134
|
+
* When softDelete is true, sets the deleted timestamp instead of hard deleting.
|
|
1084
1135
|
* @param partitionKey The partition key value (e.g., tenantId)
|
|
1085
1136
|
* @param params Delete parameters including where conditions
|
|
1086
1137
|
* @returns A mutation query with OrThrow methods, returns deleted rows
|
|
1087
1138
|
*/
|
|
1088
|
-
deleteItems: makePartitionedDeleteItems(client, name, partitionField, schema)
|
|
1139
|
+
deleteItems: makePartitionedDeleteItems(client, name, partitionField, config.softDelete, schema)
|
|
1089
1140
|
};
|
|
1090
1141
|
};
|
|
1091
1142
|
Object.defineProperty(exports, "Err", {
|
|
@@ -1110,11 +1161,15 @@ exports.PartitionedEntity = PartitionedEntity;
|
|
|
1110
1161
|
exports.SingleMutationQuery = SingleMutationQuery;
|
|
1111
1162
|
exports.SupabaseError = SupabaseError;
|
|
1112
1163
|
exports.addEntities = addEntities;
|
|
1164
|
+
exports.deleteEntities = deleteEntities;
|
|
1165
|
+
exports.deleteEntity = deleteEntity;
|
|
1113
1166
|
exports.getEntities = getEntities;
|
|
1114
1167
|
exports.getEntity = getEntity;
|
|
1115
1168
|
exports.isMappedQuery = isMappedQuery;
|
|
1116
1169
|
exports.isQuery = isQuery;
|
|
1117
1170
|
exports.query = query;
|
|
1171
|
+
exports.softDeleteEntities = softDeleteEntities;
|
|
1172
|
+
exports.softDeleteEntity = softDeleteEntity;
|
|
1118
1173
|
exports.toError = toError;
|
|
1119
1174
|
exports.updateEntity = updateEntity;
|
|
1120
1175
|
exports.upsertEntities = upsertEntities;
|