supabase-typed-query 0.4.0 → 0.6.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
@@ -640,7 +640,7 @@ const updateEntity = (client, table, entities, where, is, wherein) => wrapAsync(
640
640
  return functype.Err(toError(error));
641
641
  }
642
642
  });
643
- const updateEntities = (client, table, entities, identity = "id", where, is, wherein) => wrapAsync(async () => {
643
+ const upsertEntities = (client, table, entities, identity = "id", where, is, wherein) => wrapAsync(async () => {
644
644
  try {
645
645
  const onConflict = Array.isArray(identity) ? identity.join(",") : identity;
646
646
  const baseQuery = client.from(table).upsert(entities, { onConflict }).match(where ?? {});
@@ -726,7 +726,12 @@ function createUpdateItemMutation(client, name, item, whereConditions, is, where
726
726
  }
727
727
  function createUpdateItemsMutation(client, name, data, where, is, wherein) {
728
728
  return MultiMutationQuery(
729
- updateEntities(client, name, [data], void 0, where, is, wherein)
729
+ upsertEntities(client, name, [data], void 0, where, is, wherein)
730
+ );
731
+ }
732
+ function createUpsertItemsMutation(client, name, items, identity) {
733
+ return MultiMutationQuery(
734
+ upsertEntities(client, name, items, identity, void 0, void 0, void 0)
730
735
  );
731
736
  }
732
737
  function makeGetItem(client, name, softDeleteMode) {
@@ -737,13 +742,27 @@ function makeGetItem(client, name, softDeleteMode) {
737
742
  }
738
743
  function makeGetItems(client, name, softDeleteMode) {
739
744
  return function getItems({ where, is, wherein, order } = {}) {
740
- return createGetItemsQuery(client, name, where, is, wherein, order, softDeleteMode);
745
+ return createGetItemsQuery(
746
+ client,
747
+ name,
748
+ where,
749
+ is,
750
+ wherein,
751
+ order,
752
+ softDeleteMode
753
+ );
741
754
  };
742
755
  }
743
756
  function makePartitionedGetItem(client, name, partitionField, softDeleteMode) {
744
757
  return function getItem(partitionKey, { id, where, is }) {
745
758
  const whereConditions = buildWhereWithPartitionAndId(partitionField, partitionKey, id, where);
746
- return createGetItemQuery(client, name, whereConditions, is, softDeleteMode);
759
+ return createGetItemQuery(
760
+ client,
761
+ name,
762
+ whereConditions,
763
+ is,
764
+ softDeleteMode
765
+ );
747
766
  };
748
767
  }
749
768
  function makePartitionedGetItems(client, name, partitionField, softDeleteMode) {
@@ -768,7 +787,14 @@ function makeUpdateItem(client, name) {
768
787
  function makePartitionedUpdateItem(client, name, partitionField) {
769
788
  return function updateItem(partitionKey, { where, data, is, wherein }) {
770
789
  const whereConditions = buildWhereWithPartition(partitionField, partitionKey, where);
771
- return createUpdateItemMutation(client, name, data, whereConditions, is, wherein);
790
+ return createUpdateItemMutation(
791
+ client,
792
+ name,
793
+ data,
794
+ whereConditions,
795
+ is,
796
+ wherein
797
+ );
772
798
  };
773
799
  }
774
800
  function makeUpdateItems(client, name) {
@@ -779,7 +805,14 @@ function makeUpdateItems(client, name) {
779
805
  function makePartitionedUpdateItems(client, name, partitionField) {
780
806
  return function updateItems(partitionKey, { where, data, is, wherein }) {
781
807
  const whereConditions = buildWhereWithPartition(partitionField, partitionKey, where);
782
- return createUpdateItemsMutation(client, name, data, whereConditions, is, wherein);
808
+ return createUpdateItemsMutation(
809
+ client,
810
+ name,
811
+ data,
812
+ whereConditions,
813
+ is,
814
+ wherein
815
+ );
783
816
  };
784
817
  }
785
818
  function makeAddItems(client, name) {
@@ -787,6 +820,19 @@ function makeAddItems(client, name) {
787
820
  return createAddItemsMutation(client, name, items);
788
821
  };
789
822
  }
823
+ function makeUpsertItems(client, name) {
824
+ return function upsertItems({
825
+ items,
826
+ identity = "id"
827
+ }) {
828
+ return createUpsertItemsMutation(client, name, items, identity);
829
+ };
830
+ }
831
+ function makePartitionedUpsertItems(client, name, _partitionField) {
832
+ return function upsertItems(_partitionKey, { items, identity = "id" }) {
833
+ return createUpsertItemsMutation(client, name, items, identity);
834
+ };
835
+ }
790
836
  const Entity = (client, name, config) => {
791
837
  const softDeleteMode = getSoftDeleteMode(config.softDelete);
792
838
  return {
@@ -819,7 +865,13 @@ const Entity = (client, name, config) => {
819
865
  * @param params Update parameters including items array, identity, and optional filters
820
866
  * @returns A mutation query with OrThrow methods
821
867
  */
822
- updateItems: makeUpdateItems(client, name)
868
+ updateItems: makeUpdateItems(client, name),
869
+ /**
870
+ * Upsert multiple items with different data per row.
871
+ * @param params Upsert parameters including items array and identity columns
872
+ * @returns A mutation query with OrThrow methods
873
+ */
874
+ upsertItems: makeUpsertItems(client, name)
823
875
  };
824
876
  };
825
877
  const PartitionedEntity = (client, name, config) => {
@@ -860,7 +912,15 @@ const PartitionedEntity = (client, name, config) => {
860
912
  * @param params Update parameters including items array, identity, and optional filters
861
913
  * @returns A mutation query with OrThrow methods
862
914
  */
863
- updateItems: makePartitionedUpdateItems(client, name, partitionField)
915
+ updateItems: makePartitionedUpdateItems(client, name, partitionField),
916
+ /**
917
+ * Upsert multiple items with different data per row within a partition.
918
+ * Note: Items should include the partition key value in their data.
919
+ * @param partitionKey The partition key value (e.g., tenantId)
920
+ * @param params Upsert parameters including items array and identity columns
921
+ * @returns A mutation query with OrThrow methods
922
+ */
923
+ upsertItems: makePartitionedUpsertItems(client, name)
864
924
  };
865
925
  };
866
926
  Object.defineProperty(exports, "Err", {
@@ -891,6 +951,6 @@ exports.isMappedQuery = isMappedQuery;
891
951
  exports.isQuery = isQuery;
892
952
  exports.query = query;
893
953
  exports.toError = toError;
894
- exports.updateEntities = updateEntities;
895
954
  exports.updateEntity = updateEntity;
955
+ exports.upsertEntities = upsertEntities;
896
956
  //# sourceMappingURL=index.js.map