supabase-typed-query 0.13.0 → 1.0.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.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { Ok, Option, Err, List } from "functype";
2
- import { Err as Err2, List as List2, Ok as Ok2, Option as Option2 } from "functype";
1
+ import { Option, IO, List } from "functype";
2
+ import { IO as IO2, List as List2, Option as Option2 } from "functype";
3
3
  class SupabaseError extends Error {
4
4
  code;
5
5
  details;
@@ -46,9 +46,6 @@ const log = {
46
46
  info: (msg) => process.env.NODE_ENV !== "test" && console.info(`[supabase-typed-query] ${msg}`)
47
47
  };
48
48
  const TABLES_WITHOUT_DELETED = /* @__PURE__ */ new Set([]);
49
- const wrapAsync$2 = (fn) => {
50
- return fn();
51
- };
52
49
  const QueryBuilder = (client, config) => {
53
50
  const buildSupabaseQuery = () => {
54
51
  const { table, conditions, order, limit, offset, schema } = config;
@@ -443,81 +440,52 @@ const QueryBuilder = (client, config) => {
443
440
  * Execute query expecting exactly one result
444
441
  */
445
442
  one: () => {
446
- return wrapAsync$2(async () => {
447
- try {
448
- const query2 = buildSupabaseQuery();
449
- const { data, error } = await query2.single();
450
- if (error) {
451
- log.error(`Error getting ${config.table} item: ${toError(error).toString()}`);
452
- return Err(toError(error));
453
- }
454
- const result = data;
455
- const filteredResult = config.filterFn ? config.filterFn(result) : true;
456
- if (!filteredResult) {
457
- return Ok(Option.none());
458
- }
459
- return Ok(Option(result));
460
- } catch (error) {
461
- log.error(`Error executing single query on ${config.table}: ${toError(error).toString()}`);
462
- return Err(toError(error));
463
- }
464
- });
443
+ return IO.tryAsync(async () => {
444
+ const query2 = buildSupabaseQuery();
445
+ const { data, error } = await query2.single();
446
+ if (error) throw toError(error);
447
+ const result = data;
448
+ const passes = config.filterFn ? config.filterFn(result) : true;
449
+ return passes ? Option(result) : Option.none();
450
+ }, toError).tapError((err) => log.error(`Error getting ${config.table} item: ${err}`));
465
451
  },
466
452
  /**
467
453
  * Execute query expecting zero or more results
468
454
  */
469
455
  many: () => {
470
- return wrapAsync$2(async () => {
471
- try {
472
- const query2 = buildSupabaseQuery();
473
- const { data, error } = await query2;
474
- if (error) {
475
- log.error(`Error getting ${config.table} items: ${toError(error).toString()}`);
476
- return Err(toError(error));
477
- }
478
- const rawResults = data;
479
- const results = config.filterFn ? rawResults.filter(config.filterFn) : rawResults;
480
- return Ok(List(results));
481
- } catch (error) {
482
- log.error(`Error executing multi query on ${config.table}: ${toError(error).toString()}`);
483
- return Err(toError(error));
484
- }
485
- });
456
+ return IO.tryAsync(async () => {
457
+ const query2 = buildSupabaseQuery();
458
+ const { data, error } = await query2;
459
+ if (error) throw toError(error);
460
+ const rawResults = data;
461
+ const results = config.filterFn ? rawResults.filter(config.filterFn) : rawResults;
462
+ return List(results);
463
+ }, toError).tapError((err) => log.error(`Error getting ${config.table} items: ${err}`));
486
464
  },
487
465
  /**
488
466
  * Execute query expecting first result from potentially multiple
489
467
  */
490
468
  first: () => {
491
- return wrapAsync$2(async () => {
492
- const manyResult = await QueryBuilder(client, config).many();
493
- const list = manyResult.orThrow();
494
- if (list.isEmpty) {
495
- return Ok(Option.none());
496
- }
497
- return Ok(Option(list.head));
498
- });
469
+ return QueryBuilder(client, config).many().map((list) => list.isEmpty ? Option.none() : Option(list.head));
499
470
  },
500
471
  /**
501
472
  * Execute query expecting exactly one result, throw if error or not found
502
473
  */
503
474
  oneOrThrow: async () => {
504
- const result = await QueryBuilder(client, config).one();
505
- const option = result.orThrow();
475
+ const option = await QueryBuilder(client, config).one().runOrThrow();
506
476
  return option.orThrow(new Error(`No record found in ${config.table}`));
507
477
  },
508
478
  /**
509
479
  * Execute query expecting zero or more results, throw if error
510
480
  */
511
481
  manyOrThrow: async () => {
512
- const result = await QueryBuilder(client, config).many();
513
- return result.orThrow();
482
+ return QueryBuilder(client, config).many().runOrThrow();
514
483
  },
515
484
  /**
516
485
  * Execute query expecting first result, throw if error or empty
517
486
  */
518
487
  firstOrThrow: async () => {
519
- const result = await QueryBuilder(client, config).first();
520
- const option = result.orThrow();
488
+ const option = await QueryBuilder(client, config).first().runOrThrow();
521
489
  return option.orThrow(new Error(`No records found in ${config.table}`));
522
490
  }
523
491
  };
@@ -532,53 +500,42 @@ const createMappedQuery = (sourceQuery, mapFn) => {
532
500
  return createMappedQuery(filteredQuery, mapFn);
533
501
  },
534
502
  one: () => {
535
- return wrapAsync$2(async () => {
536
- const maybeItemResult = await sourceQuery.one();
537
- const maybeItem = maybeItemResult.orThrow();
538
- return maybeItem.fold(
539
- () => Ok(Option.none()),
540
- (item) => Ok(Option(mapFn(item)))
541
- );
542
- });
503
+ return sourceQuery.one().map(
504
+ (maybeItem) => maybeItem.fold(
505
+ () => Option.none(),
506
+ (item) => Option(mapFn(item))
507
+ )
508
+ );
543
509
  },
544
510
  many: () => {
545
- return wrapAsync$2(async () => {
546
- const itemsResult = await sourceQuery.many();
547
- const items = itemsResult.orThrow();
548
- return Ok(items.map(mapFn));
549
- });
511
+ return sourceQuery.many().map((items) => items.map(mapFn));
550
512
  },
551
513
  first: () => {
552
- return wrapAsync$2(async () => {
553
- const maybeItemResult = await sourceQuery.first();
554
- const maybeItem = maybeItemResult.orThrow();
555
- return maybeItem.fold(
556
- () => Ok(Option.none()),
557
- (item) => Ok(Option(mapFn(item)))
558
- );
559
- });
514
+ return sourceQuery.first().map(
515
+ (maybeItem) => maybeItem.fold(
516
+ () => Option.none(),
517
+ (item) => Option(mapFn(item))
518
+ )
519
+ );
560
520
  },
561
521
  /**
562
522
  * Execute mapped query expecting exactly one result, throw if error or not found
563
523
  */
564
524
  oneOrThrow: async () => {
565
- const result = await createMappedQuery(sourceQuery, mapFn).one();
566
- const option = result.orThrow();
525
+ const option = await createMappedQuery(sourceQuery, mapFn).one().runOrThrow();
567
526
  return option.orThrow(new Error(`No record found`));
568
527
  },
569
528
  /**
570
529
  * Execute mapped query expecting zero or more results, throw if error
571
530
  */
572
531
  manyOrThrow: async () => {
573
- const result = await createMappedQuery(sourceQuery, mapFn).many();
574
- return result.orThrow();
532
+ return createMappedQuery(sourceQuery, mapFn).many().runOrThrow();
575
533
  },
576
534
  /**
577
535
  * Execute mapped query expecting first result, throw if error or empty
578
536
  */
579
537
  firstOrThrow: async () => {
580
- const result = await createMappedQuery(sourceQuery, mapFn).first();
581
- const option = result.orThrow();
538
+ const option = await createMappedQuery(sourceQuery, mapFn).first().runOrThrow();
582
539
  return option.orThrow(new Error(`No records found`));
583
540
  }
584
541
  };
@@ -600,38 +557,28 @@ const isQuery = (obj) => {
600
557
  const isMappedQuery = (obj) => {
601
558
  return typeof obj === "object" && obj !== null && "one" in obj && "many" in obj && "first" in obj && "map" in obj && "filter" in obj;
602
559
  };
603
- const wrapAsync$1 = (fn) => {
604
- return fn();
605
- };
606
560
  const rpc = (client, functionName, args, options) => {
607
561
  const executeRpc = () => {
608
562
  return client.rpc(functionName, args ?? {}, {
609
563
  count: options?.count
610
564
  });
611
565
  };
612
- const one = () => wrapAsync$1(async () => {
613
- try {
614
- const { data, error } = await executeRpc();
615
- if (error) {
616
- return Err(toError(error));
617
- }
618
- if (data === null || data === void 0) {
619
- return Ok(Option.none());
620
- }
621
- if (Array.isArray(data)) {
622
- if (data.length === 0) {
623
- return Ok(Option.none());
624
- }
625
- return Ok(Option(data[0]));
566
+ const one = () => IO.tryAsync(async () => {
567
+ const { data, error } = await executeRpc();
568
+ if (error) throw toError(error);
569
+ if (data === null || data === void 0) {
570
+ return Option.none();
571
+ }
572
+ if (Array.isArray(data)) {
573
+ if (data.length === 0) {
574
+ return Option.none();
626
575
  }
627
- return Ok(Option(data));
628
- } catch (error) {
629
- return Err(toError(error));
576
+ return Option(data[0]);
630
577
  }
631
- });
578
+ return Option(data);
579
+ }, toError);
632
580
  const oneOrThrow = async () => {
633
- const result = await one();
634
- const option = result.orThrow();
581
+ const option = await one().runOrThrow();
635
582
  return option.fold(
636
583
  () => {
637
584
  throw new Error("RPC call returned no result");
@@ -639,26 +586,19 @@ const rpc = (client, functionName, args, options) => {
639
586
  (value) => value
640
587
  );
641
588
  };
642
- const many = () => wrapAsync$1(async () => {
643
- try {
644
- const { data, error } = await executeRpc();
645
- if (error) {
646
- return Err(toError(error));
647
- }
648
- if (data === null || data === void 0) {
649
- return Ok(List([]));
650
- }
651
- if (Array.isArray(data)) {
652
- return Ok(List(data));
653
- }
654
- return Ok(List([data]));
655
- } catch (error) {
656
- return Err(toError(error));
589
+ const many = () => IO.tryAsync(async () => {
590
+ const { data, error } = await executeRpc();
591
+ if (error) throw toError(error);
592
+ if (data === null || data === void 0) {
593
+ return List([]);
657
594
  }
658
- });
595
+ if (Array.isArray(data)) {
596
+ return List(data);
597
+ }
598
+ return List([data]);
599
+ }, toError);
659
600
  const manyOrThrow = async () => {
660
- const result = await many();
661
- return result.orThrow();
601
+ return many().runOrThrow();
662
602
  };
663
603
  return {
664
604
  one,
@@ -667,208 +607,145 @@ const rpc = (client, functionName, args, options) => {
667
607
  manyOrThrow
668
608
  };
669
609
  };
670
- const wrapAsync = (fn) => {
671
- return fn();
672
- };
673
- const getEntity = (client, table, where, is, schema) => wrapAsync(async () => {
674
- try {
675
- const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
676
- const baseQuery = tableQuery.select("*").match(where);
677
- const queryWithIs = is ? List(Object.entries(is)).foldLeft(baseQuery)(
678
- (query2, [column, value]) => query2.is(column, value)
679
- ) : baseQuery;
680
- const { data, error } = await queryWithIs.single();
681
- if (error) {
682
- return Err(toError(error));
683
- }
684
- return Ok(data);
685
- } catch (error) {
686
- return Err(toError(error));
687
- }
688
- });
610
+ const getEntity = (client, table, where, is, schema) => IO.tryAsync(async () => {
611
+ const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
612
+ const baseQuery = tableQuery.select("*").match(where);
613
+ const queryWithIs = is ? List(Object.entries(is)).foldLeft(baseQuery)(
614
+ (query2, [column, value]) => query2.is(column, value)
615
+ ) : baseQuery;
616
+ const { data, error } = await queryWithIs.single();
617
+ if (error) throw toError(error);
618
+ return data;
619
+ }, toError);
689
620
  const getEntities = (client, table, where = {}, is, wherein, order = [
690
621
  "id",
691
622
  { ascending: true }
692
- ], schema) => wrapAsync(async () => {
693
- try {
694
- const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
695
- const baseQuery = tableQuery.select("*").match(where);
696
- const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
697
- (query2, [column, values]) => query2.in(column, values)
698
- ) : baseQuery;
699
- const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
700
- (query2, [column, value]) => query2.is(column, value)
701
- ) : queryWithIn;
702
- const queryOrderBy = queryWithIs.order(order[0], order[1]);
703
- const { data, error } = await queryOrderBy;
704
- if (error) {
705
- return Err(toError(error));
706
- }
707
- return Ok(List(data));
708
- } catch (error) {
709
- return Err(toError(error));
710
- }
711
- });
712
- const addEntities = (client, table, entities, schema) => wrapAsync(async () => {
713
- try {
714
- const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
715
- const { data, error } = await tableQuery.insert(entities).select();
716
- if (error) {
717
- return Err(toError(error));
718
- }
719
- return Ok(List(data));
720
- } catch (error) {
721
- return Err(toError(error));
722
- }
723
- });
724
- const updateEntity = (client, table, entities, where, is, wherein, schema) => wrapAsync(async () => {
725
- try {
726
- const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
727
- const baseQuery = tableQuery.update(entities).match(where);
728
- const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
729
- (query2, [column, values]) => query2.in(column, values)
730
- ) : baseQuery;
731
- const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
732
- (query2, [column, value]) => query2.is(column, value)
733
- ) : queryWithIn;
734
- const { data, error } = await queryWithIs.select().single();
735
- if (error) {
736
- return Err(toError(error));
737
- }
738
- return Ok(data);
739
- } catch (error) {
740
- return Err(toError(error));
741
- }
742
- });
743
- const upsertEntities = (client, table, entities, identity = "id", where, is, wherein, schema) => wrapAsync(async () => {
744
- try {
745
- const onConflict = Array.isArray(identity) ? identity.join(",") : identity;
746
- const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
747
- const baseQuery = tableQuery.upsert(entities, { onConflict }).match(where ?? {});
748
- const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
749
- (query2, [column, values]) => query2.in(column, values)
750
- ) : baseQuery;
751
- const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
752
- (query2, [column, value]) => query2.is(column, value)
753
- ) : queryWithIn;
754
- const { data, error } = await queryWithIs.select();
755
- if (error) {
756
- return Err(toError(error));
757
- }
758
- return Ok(List(data));
759
- } catch (error) {
760
- return Err(toError(error));
761
- }
762
- });
763
- const deleteEntity = (client, table, where, is, wherein, schema) => wrapAsync(async () => {
764
- try {
765
- const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
766
- const baseQuery = tableQuery.delete().match(where);
767
- const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
768
- (query2, [column, values]) => query2.in(column, values)
769
- ) : baseQuery;
770
- const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
771
- (query2, [column, value]) => query2.is(column, value)
772
- ) : queryWithIn;
773
- const { data, error } = await queryWithIs.select().single();
774
- if (error) {
775
- return Err(toError(error));
776
- }
777
- return Ok(data);
778
- } catch (error) {
779
- return Err(toError(error));
780
- }
781
- });
782
- const deleteEntities = (client, table, where, is, wherein, schema) => wrapAsync(async () => {
783
- try {
784
- const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
785
- const baseQuery = tableQuery.delete().match(where);
786
- const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
787
- (query2, [column, values]) => query2.in(column, values)
788
- ) : baseQuery;
789
- const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
790
- (query2, [column, value]) => query2.is(column, value)
791
- ) : queryWithIn;
792
- const { data, error } = await queryWithIs.select();
793
- if (error) {
794
- return Err(toError(error));
795
- }
796
- return Ok(List(data));
797
- } catch (error) {
798
- return Err(toError(error));
799
- }
800
- });
801
- const softDeleteEntity = (client, table, where, is, wherein, schema) => wrapAsync(async () => {
802
- try {
803
- const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
804
- const baseQuery = tableQuery.update({ deleted: (/* @__PURE__ */ new Date()).toISOString() }).match(where);
805
- const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
806
- (query2, [column, values]) => query2.in(column, values)
807
- ) : baseQuery;
808
- const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
809
- (query2, [column, value]) => query2.is(column, value)
810
- ) : queryWithIn;
811
- const { data, error } = await queryWithIs.select().single();
812
- if (error) {
813
- return Err(toError(error));
814
- }
815
- return Ok(data);
816
- } catch (error) {
817
- return Err(toError(error));
818
- }
819
- });
820
- const softDeleteEntities = (client, table, where, is, wherein, schema) => wrapAsync(async () => {
821
- try {
822
- const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
823
- const baseQuery = tableQuery.update({ deleted: (/* @__PURE__ */ new Date()).toISOString() }).match(where);
824
- const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
825
- (query2, [column, values]) => query2.in(column, values)
826
- ) : baseQuery;
827
- const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
828
- (query2, [column, value]) => query2.is(column, value)
829
- ) : queryWithIn;
830
- const { data, error } = await queryWithIs.select();
831
- if (error) {
832
- return Err(toError(error));
833
- }
834
- return Ok(List(data));
835
- } catch (error) {
836
- return Err(toError(error));
837
- }
838
- });
623
+ ], schema) => IO.tryAsync(async () => {
624
+ const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
625
+ const baseQuery = tableQuery.select("*").match(where);
626
+ const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
627
+ (query2, [column, values]) => query2.in(column, values)
628
+ ) : baseQuery;
629
+ const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
630
+ (query2, [column, value]) => query2.is(column, value)
631
+ ) : queryWithIn;
632
+ const queryOrderBy = queryWithIs.order(order[0], order[1]);
633
+ const { data, error } = await queryOrderBy;
634
+ if (error) throw toError(error);
635
+ return List(data);
636
+ }, toError);
637
+ const addEntities = (client, table, entities, schema) => IO.tryAsync(async () => {
638
+ const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
639
+ const { data, error } = await tableQuery.insert(entities).select();
640
+ if (error) throw toError(error);
641
+ return List(data);
642
+ }, toError);
643
+ const updateEntity = (client, table, entities, where, is, wherein, schema) => IO.tryAsync(async () => {
644
+ const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
645
+ const baseQuery = tableQuery.update(entities).match(where);
646
+ const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
647
+ (query2, [column, values]) => query2.in(column, values)
648
+ ) : baseQuery;
649
+ const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
650
+ (query2, [column, value]) => query2.is(column, value)
651
+ ) : queryWithIn;
652
+ const { data, error } = await queryWithIs.select().single();
653
+ if (error) throw toError(error);
654
+ return data;
655
+ }, toError);
656
+ const upsertEntities = (client, table, entities, identity = "id", where, is, wherein, schema) => IO.tryAsync(async () => {
657
+ const onConflict = Array.isArray(identity) ? identity.join(",") : identity;
658
+ const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
659
+ const baseQuery = tableQuery.upsert(entities, { onConflict }).match(where ?? {});
660
+ const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
661
+ (query2, [column, values]) => query2.in(column, values)
662
+ ) : baseQuery;
663
+ const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
664
+ (query2, [column, value]) => query2.is(column, value)
665
+ ) : queryWithIn;
666
+ const { data, error } = await queryWithIs.select();
667
+ if (error) throw toError(error);
668
+ return List(data);
669
+ }, toError);
670
+ const deleteEntity = (client, table, where, is, wherein, schema) => IO.tryAsync(async () => {
671
+ const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
672
+ const baseQuery = tableQuery.delete().match(where);
673
+ const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
674
+ (query2, [column, values]) => query2.in(column, values)
675
+ ) : baseQuery;
676
+ const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
677
+ (query2, [column, value]) => query2.is(column, value)
678
+ ) : queryWithIn;
679
+ const { data, error } = await queryWithIs.select().single();
680
+ if (error) throw toError(error);
681
+ return data;
682
+ }, toError);
683
+ const deleteEntities = (client, table, where, is, wherein, schema) => IO.tryAsync(async () => {
684
+ const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
685
+ const baseQuery = tableQuery.delete().match(where);
686
+ const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
687
+ (query2, [column, values]) => query2.in(column, values)
688
+ ) : baseQuery;
689
+ const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
690
+ (query2, [column, value]) => query2.is(column, value)
691
+ ) : queryWithIn;
692
+ const { data, error } = await queryWithIs.select();
693
+ if (error) throw toError(error);
694
+ return List(data);
695
+ }, toError);
696
+ const softDeleteEntity = (client, table, where, is, wherein, schema) => IO.tryAsync(async () => {
697
+ const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
698
+ const baseQuery = tableQuery.update({ deleted: (/* @__PURE__ */ new Date()).toISOString() }).match(where);
699
+ const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
700
+ (query2, [column, values]) => query2.in(column, values)
701
+ ) : baseQuery;
702
+ const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
703
+ (query2, [column, value]) => query2.is(column, value)
704
+ ) : queryWithIn;
705
+ const { data, error } = await queryWithIs.select().single();
706
+ if (error) throw toError(error);
707
+ return data;
708
+ }, toError);
709
+ const softDeleteEntities = (client, table, where, is, wherein, schema) => IO.tryAsync(async () => {
710
+ const tableQuery = schema ? client.schema(schema).from(table) : client.from(table);
711
+ const baseQuery = tableQuery.update({ deleted: (/* @__PURE__ */ new Date()).toISOString() }).match(where);
712
+ const queryWithIn = wherein ? List(Object.entries(wherein)).foldLeft(baseQuery)(
713
+ (query2, [column, values]) => query2.in(column, values)
714
+ ) : baseQuery;
715
+ const queryWithIs = is ? List(Object.entries(is)).foldLeft(queryWithIn)(
716
+ (query2, [column, value]) => query2.is(column, value)
717
+ ) : queryWithIn;
718
+ const { data, error } = await queryWithIs.select();
719
+ if (error) throw toError(error);
720
+ return List(data);
721
+ }, toError);
839
722
  const query = (client, table, where = {}, is, wherein, order, schema) => {
840
723
  return createQuery(client, table, where, is, wherein, order, void 0, schema);
841
724
  };
842
- function MultiMutationQuery(promise) {
843
- const result = Object.assign(promise, {
844
- many: () => promise,
725
+ function MultiMutationQuery(task) {
726
+ return {
727
+ many: () => task,
845
728
  manyOrThrow: async () => {
846
- const taskResult = await promise;
847
- return taskResult.orThrow();
729
+ return task.runOrThrow();
848
730
  },
849
- execute: () => promise,
731
+ execute: () => task,
850
732
  executeOrThrow: async () => {
851
- const taskResult = await promise;
852
- return taskResult.orThrow();
733
+ return task.runOrThrow();
853
734
  }
854
- });
855
- return result;
735
+ };
856
736
  }
857
- function SingleMutationQuery(promise) {
858
- const result = Object.assign(promise, {
859
- one: () => promise.then((outcome) => outcome.map((value) => Option(value))),
737
+ function SingleMutationQuery(task) {
738
+ return {
739
+ one: () => task.map((value) => Option(value)),
860
740
  oneOrThrow: async () => {
861
- const taskResult = await promise;
862
- return taskResult.orThrow();
741
+ return task.runOrThrow();
863
742
  },
864
- execute: () => promise.then((outcome) => outcome.map((value) => Option(value))),
743
+ execute: () => task.map((value) => Option(value)),
865
744
  executeOrThrow: async () => {
866
- const taskResult = await promise;
867
- const value = taskResult.orThrow();
745
+ const value = await task.runOrThrow();
868
746
  return Option(value);
869
747
  }
870
- });
871
- return result;
748
+ };
872
749
  }
873
750
  function getSoftDeleteMode(softDelete) {
874
751
  return softDelete ? "exclude" : "include";
@@ -1309,10 +1186,9 @@ const PartitionedEntity = (client, name, config) => {
1309
1186
  };
1310
1187
  export {
1311
1188
  Entity,
1312
- Err2 as Err,
1189
+ IO2 as IO,
1313
1190
  List2 as List,
1314
1191
  MultiMutationQuery,
1315
- Ok2 as Ok,
1316
1192
  Option2 as Option,
1317
1193
  PartitionedEntity,
1318
1194
  SingleMutationQuery,