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