supabase-typed-query 0.7.0 → 0.8.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/dist/index.js CHANGED
@@ -665,6 +665,44 @@ const upsertEntities = (client, table, entities, identity = "id", where, is, whe
665
665
  return functype.Err(toError(error));
666
666
  }
667
667
  });
668
+ const deleteEntity = (client, table, where, is, wherein, schema) => wrapAsync(async () => {
669
+ try {
670
+ const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
671
+ const baseQuery = tableQuery.delete().match(where);
672
+ const queryWithIn = wherein ? functype.List(Object.entries(wherein)).foldLeft(baseQuery)(
673
+ (query2, [column, values]) => query2.in(column, values)
674
+ ) : baseQuery;
675
+ const queryWithIs = is ? functype.List(Object.entries(is)).foldLeft(queryWithIn)(
676
+ (query2, [column, value]) => query2.is(column, value)
677
+ ) : queryWithIn;
678
+ const { data, error } = await queryWithIs.select().single();
679
+ if (error) {
680
+ return functype.Err(toError(error));
681
+ }
682
+ return functype.Ok(data);
683
+ } catch (error) {
684
+ return functype.Err(toError(error));
685
+ }
686
+ });
687
+ const deleteEntities = (client, table, where, is, wherein, schema) => wrapAsync(async () => {
688
+ try {
689
+ const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
690
+ const baseQuery = tableQuery.delete().match(where);
691
+ const queryWithIn = wherein ? functype.List(Object.entries(wherein)).foldLeft(baseQuery)(
692
+ (query2, [column, values]) => query2.in(column, values)
693
+ ) : baseQuery;
694
+ const queryWithIs = is ? functype.List(Object.entries(is)).foldLeft(queryWithIn)(
695
+ (query2, [column, value]) => query2.is(column, value)
696
+ ) : queryWithIn;
697
+ const { data, error } = await queryWithIs.select();
698
+ if (error) {
699
+ return functype.Err(toError(error));
700
+ }
701
+ return functype.Ok(functype.List(data));
702
+ } catch (error) {
703
+ return functype.Err(toError(error));
704
+ }
705
+ });
668
706
  const query = (client, table, where = {}, is, wherein, order, schema) => {
669
707
  return createQuery(client, table, where, is, wherein, order, void 0, schema);
670
708
  };
@@ -880,6 +918,59 @@ function makePartitionedUpsertItems(client, name, _partitionField, schema) {
880
918
  return createUpsertItemsMutation(client, name, items, identity, schema);
881
919
  };
882
920
  }
921
+ function createDeleteItemMutation(client, name, whereConditions, is, wherein, schema) {
922
+ return SingleMutationQuery(
923
+ deleteEntity(client, name, whereConditions, is, wherein, schema)
924
+ );
925
+ }
926
+ function createDeleteItemsMutation(client, name, whereConditions, is, wherein, schema) {
927
+ return MultiMutationQuery(
928
+ deleteEntities(client, name, whereConditions, is, wherein, schema)
929
+ );
930
+ }
931
+ function makeDeleteItem(client, name, schema) {
932
+ return function deleteItem({ where, is, wherein }) {
933
+ return createDeleteItemMutation(client, name, where, is, wherein, schema);
934
+ };
935
+ }
936
+ function makeDeleteItems(client, name, schema) {
937
+ return function deleteItems({ where, is, wherein }) {
938
+ return createDeleteItemsMutation(
939
+ client,
940
+ name,
941
+ where,
942
+ is,
943
+ wherein,
944
+ schema
945
+ );
946
+ };
947
+ }
948
+ function makePartitionedDeleteItem(client, name, partitionField, schema) {
949
+ return function deleteItem(partitionKey, { where, is, wherein }) {
950
+ const whereConditions = buildWhereWithPartition(partitionField, partitionKey, where);
951
+ return createDeleteItemMutation(
952
+ client,
953
+ name,
954
+ whereConditions,
955
+ is,
956
+ wherein,
957
+ schema
958
+ );
959
+ };
960
+ }
961
+ function makePartitionedDeleteItems(client, name, partitionField, schema) {
962
+ return function deleteItems(partitionKey, { where, is, wherein }) {
963
+ const whereConditions = buildWhereWithPartition(partitionField, partitionKey, where);
964
+ return createDeleteItemsMutation(
965
+ client,
966
+ name,
967
+ whereConditions,
968
+ is,
969
+ wherein,
970
+ schema
971
+ );
972
+ };
973
+ }
883
974
  const Entity = (client, name, config) => {
884
975
  const softDeleteMode = getSoftDeleteMode(config.softDelete);
885
976
  const { schema } = config;
@@ -919,7 +1010,19 @@ const Entity = (client, name, config) => {
919
1010
  * @param params Upsert parameters including items array and identity columns
920
1011
  * @returns A mutation query with OrThrow methods
921
1012
  */
922
- upsertItems: makeUpsertItems(client, name, schema)
1013
+ upsertItems: makeUpsertItems(client, name, schema),
1014
+ /**
1015
+ * Delete a single item from the table.
1016
+ * @param params Delete parameters including where conditions
1017
+ * @returns A mutation query with OrThrow methods, returns deleted row
1018
+ */
1019
+ deleteItem: makeDeleteItem(client, name, schema),
1020
+ /**
1021
+ * Delete multiple items from the table.
1022
+ * @param params Delete parameters including where conditions
1023
+ * @returns A mutation query with OrThrow methods, returns deleted rows
1024
+ */
1025
+ deleteItems: makeDeleteItems(client, name, schema)
923
1026
  };
924
1027
  };
925
1028
  const PartitionedEntity = (client, name, config) => {
@@ -968,7 +1071,21 @@ const PartitionedEntity = (client, name, config) => {
968
1071
  * @param params Upsert parameters including items array and identity columns
969
1072
  * @returns A mutation query with OrThrow methods
970
1073
  */
971
- upsertItems: makePartitionedUpsertItems(client, name, partitionField, schema)
1074
+ upsertItems: makePartitionedUpsertItems(client, name, partitionField, schema),
1075
+ /**
1076
+ * Delete a single item from the table within a partition.
1077
+ * @param partitionKey The partition key value (e.g., tenantId)
1078
+ * @param params Delete parameters including where conditions
1079
+ * @returns A mutation query with OrThrow methods, returns deleted row
1080
+ */
1081
+ deleteItem: makePartitionedDeleteItem(client, name, partitionField, schema),
1082
+ /**
1083
+ * Delete multiple items from the table within a partition.
1084
+ * @param partitionKey The partition key value (e.g., tenantId)
1085
+ * @param params Delete parameters including where conditions
1086
+ * @returns A mutation query with OrThrow methods, returns deleted rows
1087
+ */
1088
+ deleteItems: makePartitionedDeleteItems(client, name, partitionField, schema)
972
1089
  };
973
1090
  };
974
1091
  Object.defineProperty(exports, "Err", {