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 +185 -312
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +186 -310
- package/dist/index.mjs.map +1 -1
- package/dist/src/entity/core.d.ts.map +1 -1
- package/dist/src/entity/types.d.ts +5 -5
- package/dist/src/entity/types.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/Query.d.ts +13 -13
- package/dist/src/query/Query.d.ts.map +1 -1
- package/dist/src/query/QueryBuilder.d.ts +3 -0
- package/dist/src/query/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query/index.d.ts +19 -19
- package/dist/src/query/index.d.ts.map +1 -1
- package/dist/src/query/rpc.d.ts +7 -5
- package/dist/src/query/rpc.d.ts.map +1 -1
- package/package.json +31 -33
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
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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
|
|
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
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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 = () =>
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
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.
|
|
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
|
|
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 = () =>
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
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
|
-
|
|
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
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
const
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
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) =>
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
});
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
)
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
)
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
)
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
)
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
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(
|
|
844
|
-
|
|
845
|
-
many: () =>
|
|
726
|
+
function MultiMutationQuery(task) {
|
|
727
|
+
return {
|
|
728
|
+
many: () => task,
|
|
846
729
|
manyOrThrow: async () => {
|
|
847
|
-
|
|
848
|
-
return taskResult.orThrow();
|
|
730
|
+
return task.runOrThrow();
|
|
849
731
|
},
|
|
850
|
-
execute: () =>
|
|
732
|
+
execute: () => task,
|
|
851
733
|
executeOrThrow: async () => {
|
|
852
|
-
|
|
853
|
-
return taskResult.orThrow();
|
|
734
|
+
return task.runOrThrow();
|
|
854
735
|
}
|
|
855
|
-
}
|
|
856
|
-
return result;
|
|
736
|
+
};
|
|
857
737
|
}
|
|
858
|
-
function SingleMutationQuery(
|
|
859
|
-
|
|
860
|
-
one: () =>
|
|
738
|
+
function SingleMutationQuery(task) {
|
|
739
|
+
return {
|
|
740
|
+
one: () => task.map((value) => functype.Option(value)),
|
|
861
741
|
oneOrThrow: async () => {
|
|
862
|
-
|
|
863
|
-
return taskResult.orThrow();
|
|
742
|
+
return task.runOrThrow();
|
|
864
743
|
},
|
|
865
|
-
execute: () =>
|
|
744
|
+
execute: () => task.map((value) => functype.Option(value)),
|
|
866
745
|
executeOrThrow: async () => {
|
|
867
|
-
const
|
|
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, "
|
|
1188
|
+
Object.defineProperty(exports, "IO", {
|
|
1312
1189
|
enumerable: true,
|
|
1313
|
-
get: () => functype.
|
|
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
|