supabase-typed-query 0.9.4 → 0.9.7
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/README.md +9 -0
- package/dist/index.js +75 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -7
- package/dist/index.mjs.map +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/query/index.d.ts +2 -0
- package/dist/src/query/index.d.ts.map +1 -1
- package/dist/src/query/rpc.d.ts +81 -0
- package/dist/src/query/rpc.d.ts.map +1 -0
- package/dist/src/types.d.ts +45 -1
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +34 -24
package/dist/index.mjs
CHANGED
|
@@ -46,7 +46,7 @@ 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$
|
|
49
|
+
const wrapAsync$2 = (fn) => {
|
|
50
50
|
return fn();
|
|
51
51
|
};
|
|
52
52
|
const QueryBuilder = (client, config) => {
|
|
@@ -414,7 +414,7 @@ const QueryBuilder = (client, config) => {
|
|
|
414
414
|
* Execute query expecting exactly one result
|
|
415
415
|
*/
|
|
416
416
|
one: () => {
|
|
417
|
-
return wrapAsync$
|
|
417
|
+
return wrapAsync$2(async () => {
|
|
418
418
|
try {
|
|
419
419
|
const query2 = buildSupabaseQuery();
|
|
420
420
|
const { data, error } = await query2.single();
|
|
@@ -438,7 +438,7 @@ const QueryBuilder = (client, config) => {
|
|
|
438
438
|
* Execute query expecting zero or more results
|
|
439
439
|
*/
|
|
440
440
|
many: () => {
|
|
441
|
-
return wrapAsync$
|
|
441
|
+
return wrapAsync$2(async () => {
|
|
442
442
|
try {
|
|
443
443
|
const query2 = buildSupabaseQuery();
|
|
444
444
|
const { data, error } = await query2;
|
|
@@ -459,7 +459,7 @@ const QueryBuilder = (client, config) => {
|
|
|
459
459
|
* Execute query expecting first result from potentially multiple
|
|
460
460
|
*/
|
|
461
461
|
first: () => {
|
|
462
|
-
return wrapAsync$
|
|
462
|
+
return wrapAsync$2(async () => {
|
|
463
463
|
const manyResult = await QueryBuilder(client, config).many();
|
|
464
464
|
const list = manyResult.orThrow();
|
|
465
465
|
if (list.isEmpty) {
|
|
@@ -503,7 +503,7 @@ const createMappedQuery = (sourceQuery, mapFn) => {
|
|
|
503
503
|
return createMappedQuery(filteredQuery, mapFn);
|
|
504
504
|
},
|
|
505
505
|
one: () => {
|
|
506
|
-
return wrapAsync$
|
|
506
|
+
return wrapAsync$2(async () => {
|
|
507
507
|
const maybeItemResult = await sourceQuery.one();
|
|
508
508
|
const maybeItem = maybeItemResult.orThrow();
|
|
509
509
|
return maybeItem.fold(
|
|
@@ -513,14 +513,14 @@ const createMappedQuery = (sourceQuery, mapFn) => {
|
|
|
513
513
|
});
|
|
514
514
|
},
|
|
515
515
|
many: () => {
|
|
516
|
-
return wrapAsync$
|
|
516
|
+
return wrapAsync$2(async () => {
|
|
517
517
|
const itemsResult = await sourceQuery.many();
|
|
518
518
|
const items = itemsResult.orThrow();
|
|
519
519
|
return Ok(items.map(mapFn));
|
|
520
520
|
});
|
|
521
521
|
},
|
|
522
522
|
first: () => {
|
|
523
|
-
return wrapAsync$
|
|
523
|
+
return wrapAsync$2(async () => {
|
|
524
524
|
const maybeItemResult = await sourceQuery.first();
|
|
525
525
|
const maybeItem = maybeItemResult.orThrow();
|
|
526
526
|
return maybeItem.fold(
|
|
@@ -571,6 +571,73 @@ const isQuery = (obj) => {
|
|
|
571
571
|
const isMappedQuery = (obj) => {
|
|
572
572
|
return typeof obj === "object" && obj !== null && "one" in obj && "many" in obj && "first" in obj && "map" in obj && "filter" in obj;
|
|
573
573
|
};
|
|
574
|
+
const wrapAsync$1 = (fn) => {
|
|
575
|
+
return fn();
|
|
576
|
+
};
|
|
577
|
+
const rpc = (client, functionName, args, options) => {
|
|
578
|
+
const executeRpc = () => {
|
|
579
|
+
return client.rpc(functionName, args ?? {}, {
|
|
580
|
+
count: options?.count
|
|
581
|
+
});
|
|
582
|
+
};
|
|
583
|
+
const one = () => wrapAsync$1(async () => {
|
|
584
|
+
try {
|
|
585
|
+
const { data, error } = await executeRpc();
|
|
586
|
+
if (error) {
|
|
587
|
+
return Err(toError(error));
|
|
588
|
+
}
|
|
589
|
+
if (data === null || data === void 0) {
|
|
590
|
+
return Ok(Option.none());
|
|
591
|
+
}
|
|
592
|
+
if (Array.isArray(data)) {
|
|
593
|
+
if (data.length === 0) {
|
|
594
|
+
return Ok(Option.none());
|
|
595
|
+
}
|
|
596
|
+
return Ok(Option(data[0]));
|
|
597
|
+
}
|
|
598
|
+
return Ok(Option(data));
|
|
599
|
+
} catch (error) {
|
|
600
|
+
return Err(toError(error));
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
const oneOrThrow = async () => {
|
|
604
|
+
const result = await one();
|
|
605
|
+
const option = result.orThrow();
|
|
606
|
+
return option.fold(
|
|
607
|
+
() => {
|
|
608
|
+
throw new Error("RPC call returned no result");
|
|
609
|
+
},
|
|
610
|
+
(value) => value
|
|
611
|
+
);
|
|
612
|
+
};
|
|
613
|
+
const many = () => wrapAsync$1(async () => {
|
|
614
|
+
try {
|
|
615
|
+
const { data, error } = await executeRpc();
|
|
616
|
+
if (error) {
|
|
617
|
+
return Err(toError(error));
|
|
618
|
+
}
|
|
619
|
+
if (data === null || data === void 0) {
|
|
620
|
+
return Ok(List([]));
|
|
621
|
+
}
|
|
622
|
+
if (Array.isArray(data)) {
|
|
623
|
+
return Ok(List(data));
|
|
624
|
+
}
|
|
625
|
+
return Ok(List([data]));
|
|
626
|
+
} catch (error) {
|
|
627
|
+
return Err(toError(error));
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
const manyOrThrow = async () => {
|
|
631
|
+
const result = await many();
|
|
632
|
+
return result.orThrow();
|
|
633
|
+
};
|
|
634
|
+
return {
|
|
635
|
+
one,
|
|
636
|
+
oneOrThrow,
|
|
637
|
+
many,
|
|
638
|
+
manyOrThrow
|
|
639
|
+
};
|
|
640
|
+
};
|
|
574
641
|
const wrapAsync = (fn) => {
|
|
575
642
|
return fn();
|
|
576
643
|
};
|
|
@@ -1156,6 +1223,7 @@ export {
|
|
|
1156
1223
|
isMappedQuery,
|
|
1157
1224
|
isQuery,
|
|
1158
1225
|
query,
|
|
1226
|
+
rpc,
|
|
1159
1227
|
softDeleteEntities,
|
|
1160
1228
|
softDeleteEntity,
|
|
1161
1229
|
toError,
|