better-supabase 0.3.0 → 0.4.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/README.md +7 -6
- package/bin/better-supabase.js +4 -0
- package/dist/{base64-CQeB1eSf.js → base64-D2gsioCY.js} +2 -2
- package/dist/claims-BAf6c7is.js +48 -0
- package/dist/cli/_format-Cax5EsM9.js +101 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +48 -0
- package/dist/cli/command-CK14fP91.js +502 -0
- package/dist/cli/compare-BmIWVEui.js +9 -0
- package/dist/cli/config-D9R0o1LH.js +1895 -0
- package/dist/cli/config-SSKSTUl2.js +2 -0
- package/dist/cli/db-DOBPt660.js +52 -0
- package/dist/cli/dist-B1MvLv-M.js +129 -0
- package/dist/cli/dist-CFgGknmZ.js +1112 -0
- package/dist/cli/dist-Du7VnEUG.js +621 -0
- package/dist/cli/doctor-BOym3mbL.js +2382 -0
- package/dist/cli/env-BZ0uy8XK.js +108 -0
- package/dist/cli/env-jIFUADLY.js +511 -0
- package/dist/cli/errors-4v4DTtda.js +56 -0
- package/dist/cli/fastest-levenshtein-CFN-lNDv.js +120 -0
- package/dist/cli/gen-Ccn_p90L.js +2008 -0
- package/dist/cli/gen-D5cLCULx.js +2 -0
- package/dist/cli/index.d.ts +493 -0
- package/dist/cli/index.js +184 -0
- package/dist/cli/init-ClnxRYBF.js +550 -0
- package/dist/cli/introspect-DxqfkVIv.js +81 -0
- package/dist/cli/io-k41_z-jT.js +24 -0
- package/dist/cli/json5-ChRycquj.js +787 -0
- package/dist/cli/jsonc-BUniUpOk.js +2 -0
- package/dist/cli/jsonc-D5Fu67jw.js +45 -0
- package/dist/cli/keys-ByKHnvP9.js +83 -0
- package/dist/cli/ohash-D7bG_EOb.js +277 -0
- package/dist/cli/openapi-8WHjxiTJ.js +66 -0
- package/dist/cli/project-B_GeXyHh.js +70 -0
- package/dist/cli/prompts-BNcNfAve.js +1142 -0
- package/dist/cli/prompts-BTYQGunc.js +2 -0
- package/dist/cli/read-sets-CMa29t9a.js +971 -0
- package/dist/cli/rolldown-runtime-BPOCksWG.js +24 -0
- package/dist/cli/run-CP20LKk_.js +347 -0
- package/dist/cli/seed-5J6eu_Xg.js +98 -0
- package/dist/cli/skills-LJJIhLFR.js +137 -0
- package/dist/cli/sql-D4VbqmXi.js +199 -0
- package/dist/cli/style-C0NFdJRL.js +29 -0
- package/dist/cli/toml-DB-MNnFs.js +424 -0
- package/dist/cli/version-5mW_8sY1.js +4 -0
- package/dist/cli/yaml-CYCbJ6et.js +2252 -0
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +13 -13
- package/dist/{compiler-2zqGzxVZ.d.ts → compiler-DB3aSFOA.d.ts} +2 -2
- package/dist/config/index.js +4 -4
- package/dist/{config-Be4GwsqI.js → config-BpxDfnbg.js} +1 -1
- package/dist/{config-DOsGYSiT.js → config-CbvFmGD8.js} +1 -1
- package/dist/{define-DF341GDj.js → define-Bh0AqTik.js} +160 -79
- package/dist/{define-DUbydmJa.d.ts → define-CRS2MRV3.d.ts} +32 -28
- package/dist/edge/index.d.ts +8 -12
- package/dist/edge/index.js +50 -24
- package/dist/{entitlements-DvJXoI02.d.ts → entitlements-Dm-FHpNH.d.ts} +2 -2
- package/dist/{errors-Bl3rkOzo.js → errors-L0xK41y_.js} +1 -1
- package/dist/events/index.d.ts +1 -1
- package/dist/events/index.js +4 -4
- package/dist/{events-Do8jXh4D.d.ts → events-B21UOhvP.d.ts} +4 -4
- package/dist/{executor-DynmIWhq.d.ts → executor-B5IoUxLE.d.ts} +1 -1
- package/dist/{executor-C57jx2pn.js → executor-CVt6dD0B.js} +3 -3
- package/dist/{executor-B26lgbHD.d.ts → executor-CZ7ImRiD.d.ts} +2 -2
- package/dist/hono/index.d.ts +16 -23
- package/dist/hono/index.js +10 -10
- package/dist/{index-CTTMS6_1.d.ts → index-528Ugmyp.d.ts} +12 -3
- package/dist/{index-CADlNHK-.d.ts → index-BAy4tsAP.d.ts} +5 -5
- package/dist/{index-BNsABq7P.d.ts → index-BBdvo-5d.d.ts} +23 -25
- package/dist/{index-qriRM9cZ.d.ts → index-BhHEC04r.d.ts} +3 -3
- package/dist/{index-GV77NpRP.d.ts → index-D5IfUIDh.d.ts} +3 -3
- package/dist/{index-CriFFJ_p.d.ts → index-DFmOpBGC.d.ts} +11 -11
- package/dist/{index-UJ-LUxtI.d.ts → index-RlLXd8dL.d.ts} +12 -12
- package/dist/index.d.ts +15 -15
- package/dist/index.js +13 -13
- package/dist/{invalidate-DbxuL2jL.js → invalidate-CgxmRamI.js} +7 -1
- package/dist/jobs/index.d.ts +10 -4
- package/dist/jobs/index.js +32 -16
- package/dist/{json-schema--aOXAGfU.js → json-schema-DP6V7cbr.js} +1 -1
- package/dist/list/index.d.ts +1 -1
- package/dist/list/index.js +3 -3
- package/dist/{live-QE3UPbGm.d.ts → live-BHakSWWo.d.ts} +12 -12
- package/dist/{live-D8rV1Ldw.js → live-CdJBOc4f.js} +13 -9
- package/dist/lookup-BaP5bI27.js +18 -0
- package/dist/mcp/index.d.ts +18 -18
- package/dist/mcp/index.js +23 -18
- package/dist/{mfa-x3V3vGh-.d.ts → mfa-C7MNQ1Ob.d.ts} +1 -1
- package/dist/{mfa-BxoR1RkN.js → mfa-byfjruR9.js} +118 -29
- package/dist/next/image/index.js +6 -3
- package/dist/next/index.d.ts +38 -35
- package/dist/next/index.js +41 -33
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +6 -6
- package/dist/orpc/index.d.ts +17 -20
- package/dist/orpc/index.js +11 -11
- package/dist/otel/index.d.ts +5 -5
- package/dist/otel/index.js +81 -62
- package/dist/{permdock-sql-Bta_G0v-.js → permdock-sql-C4KFzLc9.js} +1 -1
- package/dist/{plugin-DVRB8qNE.d.ts → plugin-bNhvJwRh.d.ts} +2 -2
- package/dist/plugins/actor/index.d.ts +1 -1
- package/dist/plugins/actor/index.js +1 -1
- package/dist/plugins/rules/index.d.ts +2 -2
- package/dist/plugins/rules/index.js +42 -12
- package/dist/plugins/soft-delete/index.d.ts +2 -2
- package/dist/plugins/soft-delete/index.js +2 -2
- package/dist/plugins/tenant/index.d.ts +2 -2
- package/dist/plugins/tenant/index.js +10 -4
- package/dist/plugins/timestamps/index.d.ts +1 -1
- package/dist/plugins/timestamps/index.js +1 -1
- package/dist/plugins/validation/index.d.ts +2 -2
- package/dist/plugins/validation/index.js +3 -3
- package/dist/{pool-B9qsLyFR.d.ts → pool-DFwEQwmN.d.ts} +11 -4
- package/dist/postgres/index.d.ts +5 -5
- package/dist/postgres/index.js +3 -2
- package/dist/{postgrest-DmBlevh-.d.ts → postgrest-Bc-0Xw62.d.ts} +1 -1
- package/dist/{problem-CGt1ADix.js → problem-BihjPR0t.js} +1 -1
- package/dist/{problem-Z2RTQjZD.d.ts → problem-U8UEKccv.d.ts} +1 -1
- package/dist/query/index.d.ts +2 -2
- package/dist/query/index.js +2 -2
- package/dist/{query-BdKLTPlj.js → query-BMMSWbI7.js} +18 -18
- package/dist/react/index.d.ts +6 -6
- package/dist/react/index.js +1 -1
- package/dist/react/server.d.ts +5 -5
- package/dist/react/server.js +3 -3
- package/dist/react/session.d.ts +4 -4
- package/dist/react/session.js +2 -2
- package/dist/{react-DNBYNazu.js → react-CQHMaESR.js} +39 -39
- package/dist/{read-set-D0qBcboM.js → read-set-FWK8qQ58.js} +50 -15
- package/dist/realtime/index.d.ts +1 -1
- package/dist/realtime/index.js +13 -12
- package/dist/{index-kpgopLNv.d.ts → refresh-BwYkyNOQ.d.ts} +6 -3
- package/dist/{resolve-BRciX2jK.d.ts → resolve-BAqQcwMW.d.ts} +15 -10
- package/dist/{resource-CwVgiI5q.d.ts → resource-BJcaIfxi.d.ts} +5 -5
- package/dist/{resource-D30rp0GN.js → resource-My_y-Syh.js} +6 -6
- package/dist/{respond-DAkPIdTH.d.ts → respond-DgIbdrt8.d.ts} +31 -12
- package/dist/{result-DWXatkd6.js → result-Bj6yt33D.js} +2 -2
- package/dist/{result-c2OYgCV2.d.ts → result-CqEsbgYs.d.ts} +3 -3
- package/dist/server/index.d.ts +14 -14
- package/dist/server/index.js +12 -12
- package/dist/{respond-C44EZAJo.js → server-BA75B0mT.js} +139 -100
- package/dist/{shared-_6-uPL7E.js → shared-DnoCdMDr.js} +4 -3
- package/dist/{simplify-LakqK1vH.js → simplify-Cqvfr9dj.js} +67 -24
- package/dist/sql/index.d.ts +1 -1
- package/dist/sql/index.js +7 -7
- package/dist/{sql-BIgk12ew.js → sql-B34HU2DI.js} +3 -2
- package/dist/ssr/index.d.ts +4 -4
- package/dist/ssr/index.js +2 -2
- package/dist/{standard-FUi3Z3-7.js → standard-BRyBGTtp.js} +2 -2
- package/dist/{standard-eudBiRk1.d.ts → standard-BsaCYQJc.d.ts} +1 -1
- package/dist/{stats-D78UQ8Yu.js → stats-C_YxA2r1.js} +33 -8
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.js +26 -8
- package/dist/{tables-Dhha3BXM.js → tables-Cb-3_VWc.js} +14 -0
- package/dist/{temporal-required-CMxeSVPo.js → temporal-required-CBNHT6ni.js} +1 -1
- package/dist/testing/index.d.ts +20 -21
- package/dist/testing/index.js +45 -45
- package/dist/{version-BfpG2gks.js → version-Bmf7_FzM.js} +1 -1
- package/dist/{view-3Po_PVlr.d.ts → view-B64o81wp.d.ts} +5 -5
- package/dist/{view-wZ-9qIUz.js → view-BrJI2LKp.js} +1 -1
- package/dist/webhooks/index.d.ts +3 -3
- package/dist/webhooks/index.js +1 -1
- package/dist/{webhooks-CAIFQSTM.js → webhooks-Bh_Jf_-l.js} +37 -18
- package/package.json +36 -4
- package/skills/better-supabase/SKILL.md +57 -10
- package/skills/better-supabase/references/plugins.md +7 -11
- package/skills/better-supabase/references/troubleshooting.md +24 -4
- package/skills/better-supabase-api/SKILL.md +66 -18
- package/skills/better-supabase-api/references/adapters.md +44 -26
- package/skills/better-supabase-auth/SKILL.md +146 -0
- package/skills/better-supabase-auth/references/permdock.md +55 -0
- package/skills/better-supabase-testing/SKILL.md +58 -4
- package/dist/claims-CoTobNC-.js +0 -25
|
@@ -1,61 +1,59 @@
|
|
|
1
|
-
import { p as DbError } from "./result-
|
|
2
|
-
import { Z as QuerySpec } from "./define-
|
|
3
|
-
import { i as
|
|
1
|
+
import { p as DbError } from "./result-CqEsbgYs.js";
|
|
2
|
+
import { Z as QuerySpec } from "./define-CRS2MRV3.js";
|
|
3
|
+
import { i as ClientAuth, t as AuthSnapshot } from "./index-RlLXd8dL.js";
|
|
4
4
|
import { n as TemplateValues } from "./template-mbvlysOo.js";
|
|
5
|
-
import { t as AuthSession } from "./view-
|
|
6
|
-
import { a as LiveSource, g as Topic, h as SubscriptionStatus, p as SubscribeOptions, r as LiveCountSeed, u as EventSchemas, v as TopicHandlers, y as TopicMessage } from "./live-
|
|
7
|
-
import "./entitlements-DvJXoI02.js";
|
|
8
|
-
import "./react/session.js";
|
|
5
|
+
import { t as AuthSession } from "./view-B64o81wp.js";
|
|
6
|
+
import { a as LiveSource, g as Topic, h as SubscriptionStatus, p as SubscribeOptions, r as LiveCountSeed, u as EventSchemas, v as TopicHandlers, y as TopicMessage } from "./live-BHakSWWo.js";
|
|
9
7
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
10
8
|
import { ReactNode } from "react";
|
|
11
9
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
12
10
|
import { QueryClient } from "@tanstack/query-core";
|
|
13
11
|
//#region src/react/hooks.d.ts
|
|
14
|
-
/** The parts of `
|
|
15
|
-
interface
|
|
16
|
-
readonly
|
|
12
|
+
/** The parts of `createClient()` the provider needs. */
|
|
13
|
+
interface ClientLike {
|
|
14
|
+
readonly betterSupabase: LiveSource;
|
|
17
15
|
readonly supabase: SupabaseClient;
|
|
18
|
-
readonly auth:
|
|
16
|
+
readonly auth: ClientAuth;
|
|
19
17
|
readonly db: object;
|
|
20
18
|
readonly queries: object;
|
|
21
19
|
}
|
|
22
20
|
interface BetterSupabaseProviderProps {
|
|
23
|
-
readonly
|
|
21
|
+
readonly client: ClientLike;
|
|
24
22
|
/** better-supabase queries are removed when the user signs out or changes. */
|
|
25
23
|
readonly queryClient?: QueryClient;
|
|
26
24
|
readonly children?: ReactNode;
|
|
27
25
|
}
|
|
28
|
-
/** Provides the
|
|
26
|
+
/** Provides the better-supabase client to the hooks. */
|
|
29
27
|
declare function BetterSupabaseProvider(props: BetterSupabaseProviderProps): ReactNode;
|
|
30
28
|
/** The session state for UI: `loading`, `signed-out` or `signed-in` with the user and claims. */
|
|
31
29
|
declare function useAuth(): AuthSnapshot;
|
|
32
30
|
declare function useSupabase(): SupabaseClient;
|
|
33
|
-
interface BetterHooks<B extends
|
|
31
|
+
interface BetterHooks<B extends ClientLike> {
|
|
34
32
|
/** Repositories bound to the current session. Re-renders when the user changes. */
|
|
35
33
|
readonly useDb: () => B["db"];
|
|
36
34
|
/** TanStack Query option factories: `useQuery(useQueries().customers.findMany())`. */
|
|
37
35
|
readonly useQueries: () => B["queries"];
|
|
38
36
|
readonly useSupabase: () => SupabaseClient;
|
|
39
37
|
readonly useAuth: () => AuthSnapshot;
|
|
40
|
-
/** `useSession()` typed by the
|
|
38
|
+
/** `useSession()` typed by the client's `betterSupabase.claims(schema)` and `betterSupabase.userMetadata(schema)`. */
|
|
41
39
|
readonly useSession: () => AuthSession<ClaimsOf<B>, ProfileOf<B>>;
|
|
42
40
|
}
|
|
43
|
-
/** The claims type of a
|
|
44
|
-
type ClaimsOf<B extends
|
|
41
|
+
/** The claims type of a client's `betterSupabase.claims(schema)`, `unknown` without one. */
|
|
42
|
+
type ClaimsOf<B extends ClientLike> = B["betterSupabase"] extends {
|
|
45
43
|
readonly claimsSchema: StandardSchemaV1<unknown, infer C> | undefined;
|
|
46
44
|
} ? C : unknown;
|
|
47
|
-
/** The profile type of a
|
|
48
|
-
type ProfileOf<B extends
|
|
45
|
+
/** The profile type of a client's `betterSupabase.userMetadata(schema)`, `unknown` without one. */
|
|
46
|
+
type ProfileOf<B extends ClientLike> = B["betterSupabase"] extends {
|
|
49
47
|
readonly userMetadataSchema: StandardSchemaV1<unknown, infer P> | undefined;
|
|
50
48
|
} ? P : unknown;
|
|
51
49
|
/**
|
|
52
50
|
* Hooks typed for your schema.
|
|
53
51
|
*
|
|
54
52
|
* ```ts
|
|
55
|
-
* export const { useDb, useQueries, useAuth } = createHooks<typeof
|
|
53
|
+
* export const { useDb, useQueries, useAuth } = createHooks<typeof bs>();
|
|
56
54
|
* ```
|
|
57
55
|
*/
|
|
58
|
-
declare function createHooks<B extends
|
|
56
|
+
declare function createHooks<B extends ClientLike>(): BetterHooks<B>;
|
|
59
57
|
interface BroadcastOptions extends Omit<SubscribeOptions, "onStatus"> {
|
|
60
58
|
/**
|
|
61
59
|
* Refetch after each message: table keys (every query that read one of
|
|
@@ -88,7 +86,7 @@ interface LiveQueryHookOptions {
|
|
|
88
86
|
* resubscribes when the spec, tenant or user changes.
|
|
89
87
|
*
|
|
90
88
|
* ```ts
|
|
91
|
-
* const spec =
|
|
89
|
+
* const spec = betterSupabase.spec.customers.findMany({ include: { notes: true } });
|
|
92
90
|
* const { data } = useQuery(q.$spec(spec));
|
|
93
91
|
* useLiveQuery(spec);
|
|
94
92
|
* ```
|
|
@@ -108,13 +106,13 @@ interface LiveCount {
|
|
|
108
106
|
/**
|
|
109
107
|
* A count that stays current: refetches only the `count` spec (a HEAD
|
|
110
108
|
* request) after each debounced change to a table it reads, and after the
|
|
111
|
-
* channel rejoins. Takes a spec or a `
|
|
109
|
+
* channel rejoins. Takes a spec or a `bs.liveCount()` seed; pass `null` to
|
|
112
110
|
* pause. Doesn't need a `QueryClient`.
|
|
113
111
|
*
|
|
114
112
|
* ```tsx
|
|
115
|
-
* const { count } = useLiveCount(seed); // seed = await
|
|
113
|
+
* const { count } = useLiveCount(seed); // seed = await bs.liveCount(spec)
|
|
116
114
|
* ```
|
|
117
115
|
*/
|
|
118
116
|
declare function useLiveCount(source: QuerySpec<string, "count", number> | LiveCountSeed | null | undefined, options?: LiveCountHookOptions): LiveCount;
|
|
119
117
|
//#endregion
|
|
120
|
-
export {
|
|
118
|
+
export { ClaimsOf as a, LiveCountHookOptions as c, createHooks as d, useAuth as f, useSupabase as g, useLiveQuery as h, BroadcastOptions as i, LiveQueryHookOptions as l, useLiveCount as m, BetterSupabaseProvider as n, ClientLike as o, useBroadcast as p, BetterSupabaseProviderProps as r, LiveCount as s, BetterHooks as t, ProfileOf as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A as SchemaMeta } from "./types-DONv9SHN.js";
|
|
2
|
-
import { p as OpenApiParameter } from "./index-
|
|
2
|
+
import { p as OpenApiParameter } from "./index-BAy4tsAP.js";
|
|
3
3
|
//#region src/openapi/index.d.ts
|
|
4
4
|
type Json = Record<string, unknown>;
|
|
5
5
|
type ResourceOperation = "list" | "get" | "create" | "update" | "delete";
|
|
@@ -68,13 +68,13 @@ declare const PROBLEM_SCHEMA: Json;
|
|
|
68
68
|
* schemes and Problem Details errors.
|
|
69
69
|
*
|
|
70
70
|
* ```ts
|
|
71
|
-
* const doc = createOpenApi(
|
|
71
|
+
* const doc = createOpenApi(betterSupabase, {
|
|
72
72
|
* info: { title: 'CRM API', version: '1.0.0' },
|
|
73
73
|
* resources: { customers: { list: customerList }, notes: { operations: ['list', 'get'] } },
|
|
74
74
|
* });
|
|
75
75
|
* ```
|
|
76
76
|
*/
|
|
77
|
-
declare function createOpenApi(
|
|
77
|
+
declare function createOpenApi(betterSupabase: {
|
|
78
78
|
readonly meta: SchemaMeta;
|
|
79
79
|
}, options: OpenApiOptions): OpenApiDocument;
|
|
80
80
|
//#endregion
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
2
|
import { A as SchemaMeta } from "./types-DONv9SHN.js";
|
|
3
|
-
import { a as EventHub, s as MutationNotice } from "./events-
|
|
4
|
-
import { l as MutationKind } from "./plugin-
|
|
3
|
+
import { a as EventHub, s as MutationNotice } from "./events-B21UOhvP.js";
|
|
4
|
+
import { l as MutationKind } from "./plugin-bNhvJwRh.js";
|
|
5
5
|
//#region src/events/index.d.ts
|
|
6
6
|
/** A CloudEvents 1.0 event. Extension attributes are lowercase alphanumerics. */
|
|
7
7
|
interface CloudEvent<T = unknown> {
|
|
@@ -51,7 +51,7 @@ interface ForwardOptions extends CloudEventOptions {
|
|
|
51
51
|
* Sends a CloudEvent for every mutation to `sink`. Returns a function that
|
|
52
52
|
* stops forwarding. Use an outbox (SQL kit) when events must not be lost.
|
|
53
53
|
*/
|
|
54
|
-
declare function forwardMutations(
|
|
54
|
+
declare function forwardMutations(betterSupabase: {
|
|
55
55
|
readonly events: EventHub;
|
|
56
56
|
readonly meta: SchemaMeta;
|
|
57
57
|
}, sink: EventSink, options: ForwardOptions): () => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as PrimaryKeyValue, L as UniqueWhere, N as TableKey, R as Update, g as Insert, n as AnyModels, t as AnyFunctions } from "./types-DONv9SHN.js";
|
|
2
|
-
import { _ as DbException } from "./result-
|
|
3
|
-
import { C as FindExt, Ct as WhereInput, M as UpsertArgs, N as WriteArgs, S as DeleteExt, T as OffsetPageArgs, X as InferResult, Z as QuerySpec, _ as CursorPage, it as AggregateResult, j as UpdateArgs, k as Returned, l as CacheAdapter, lt as FindFirstArgs, rt as AggregateArgs, st as CountArgs, t as BetterSupabase, ut as FindManyArgs, v as CursorPageArgs, vt as Payload, w as OffsetPage, x as DeleteArgs, y as Db, yt as ReadArgs } from "./define-
|
|
2
|
+
import { _ as DbException } from "./result-CqEsbgYs.js";
|
|
3
|
+
import { C as FindExt, Ct as WhereInput, M as UpsertArgs, N as WriteArgs, S as DeleteExt, T as OffsetPageArgs, X as InferResult, Z as QuerySpec, _ as CursorPage, it as AggregateResult, j as UpdateArgs, k as Returned, l as CacheAdapter, lt as FindFirstArgs, rt as AggregateArgs, st as CountArgs, t as BetterSupabase, ut as FindManyArgs, v as CursorPageArgs, vt as Payload, w as OffsetPage, x as DeleteArgs, y as Db, yt as ReadArgs } from "./define-CRS2MRV3.js";
|
|
4
4
|
import { DataTag, InfiniteData, QueryClient, SkipToken } from "@tanstack/query-core";
|
|
5
5
|
//#region src/query/invalidate.d.ts
|
|
6
6
|
/** Carried by every better-supabase query: the tables whose changes make it stale. */
|
|
@@ -76,7 +76,7 @@ interface TableQueries<M extends AnyModels, T extends TableKey<M>, E> {
|
|
|
76
76
|
type RpcArgsOf<F extends AnyFunctions, N extends keyof F> = F[N]["Args"];
|
|
77
77
|
interface QueryHelpers<M extends AnyModels, F extends AnyFunctions> {
|
|
78
78
|
/** Prefix of every better-supabase key. */
|
|
79
|
-
readonly key: readonly ["bs"];
|
|
79
|
+
readonly $key: readonly ["bs"];
|
|
80
80
|
/** Query options for a `QuerySpec`, for example one sent from a Server Component. */
|
|
81
81
|
$spec<S extends QuerySpec<TableKey<M>>>(spec: S | SkipToken): QueryOptionsOf<InferResult<S>>;
|
|
82
82
|
/** Fetches a spec into `queryClient` for server rendering and hydration. */
|
|
@@ -85,11 +85,11 @@ interface QueryHelpers<M extends AnyModels, F extends AnyFunctions> {
|
|
|
85
85
|
$rpc<N extends Extract<keyof F, string>>(name: N, args?: RpcArgsOf<F, N> | SkipToken, options?: {
|
|
86
86
|
readonly tables?: readonly TableKey<M>[];
|
|
87
87
|
}): QueryOptionsOf<F[N]["Returns"]>;
|
|
88
|
-
/** Mutation options for a database function; invalidates what `
|
|
88
|
+
/** Mutation options for a database function; invalidates what `betterSupabase.defineRpc` declared. */
|
|
89
89
|
$rpcMutation<N extends Extract<keyof F, string>>(name: N): MutationOptionsOf<RpcArgsOf<F, N>, F[N]["Returns"]>;
|
|
90
90
|
}
|
|
91
|
-
type
|
|
92
|
-
interface
|
|
91
|
+
type BetterQueries<M extends AnyModels, E, F extends AnyFunctions = AnyFunctions> = { readonly [T in TableKey<M>]: TableQueries<M, T, E>; } & QueryHelpers<M, F>;
|
|
92
|
+
interface QueriesOptions {
|
|
93
93
|
/**
|
|
94
94
|
* `staleTime` for every query option. Set it above zero when rendering on
|
|
95
95
|
* the server so hydrated data isn't refetched on mount.
|
|
@@ -104,14 +104,14 @@ interface CreateQueriesOptions {
|
|
|
104
104
|
* changed table.
|
|
105
105
|
*
|
|
106
106
|
* ```ts
|
|
107
|
-
* const q = createQueries(
|
|
107
|
+
* const q = createQueries(betterSupabase, () => bs.db);
|
|
108
108
|
* const { data } = useQuery(q.customers.findMany({ select: ['id', 'name'] }));
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
|
-
declare function createQueries<M extends AnyModels, D, F extends AnyFunctions, E>(
|
|
111
|
+
declare function createQueries<M extends AnyModels, D, F extends AnyFunctions, E>(betterSupabase: BetterSupabase<M, D, F, E>, db: Db<M, F, E, unknown> | (() => Db<M, F, E, unknown>), options?: QueriesOptions): BetterQueries<M, E, F>;
|
|
112
112
|
/** Invalidates every query that read a table in the target. */
|
|
113
113
|
declare function queryCache(client: QueryClient): CacheAdapter;
|
|
114
|
-
/** Invalidates affected queries for every mutation and declared RPC `
|
|
115
|
-
declare function invalidateOnMutation<M extends AnyModels, D, F extends AnyFunctions, E>(
|
|
114
|
+
/** Invalidates affected queries for every mutation and declared RPC `betterSupabase` performs in this runtime. */
|
|
115
|
+
declare function invalidateOnMutation<M extends AnyModels, D, F extends AnyFunctions, E>(betterSupabase: BetterSupabase<M, D, F, E>, client: QueryClient): () => void;
|
|
116
116
|
//#endregion
|
|
117
|
-
export { QueryHelpers as a, TableQueries as c, queryCache as d, BetterQueryMeta as f,
|
|
117
|
+
export { QueryHelpers as a, TableQueries as c, queryCache as d, BetterQueryMeta as f, QueriesOptions as i, createQueries as l, InfiniteOptionsOf as n, QueryKeyOf as o, invalidateTables as p, MutationOptionsOf as r, QueryOptionsOf as s, BetterQueries as t, invalidateOnMutation as u };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { n as AnyModels, t as AnyFunctions } from "./types-DONv9SHN.js";
|
|
2
|
-
import { t as BetterSupabase, y as Db } from "./define-
|
|
2
|
+
import { t as BetterSupabase, y as Db } from "./define-CRS2MRV3.js";
|
|
3
3
|
import { c as PublicEnv } from "./index-Dy6kuF0P.js";
|
|
4
|
-
import {
|
|
4
|
+
import { t as BetterQueries } from "./index-DFmOpBGC.js";
|
|
5
5
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
6
6
|
//#region src/client/index.d.ts
|
|
7
|
-
interface
|
|
7
|
+
interface ClientOptions {
|
|
8
8
|
/** URL and publishable key. Not needed when `client` is given. */
|
|
9
9
|
readonly env?: PublicEnv;
|
|
10
10
|
/** Bring your own supabase-js client (React Native, custom storage). */
|
|
@@ -34,29 +34,29 @@ type AuthSnapshot = {
|
|
|
34
34
|
readonly user: AuthUser;
|
|
35
35
|
readonly claims: Readonly<Record<string, unknown>>;
|
|
36
36
|
};
|
|
37
|
-
interface
|
|
37
|
+
interface ClientAuth {
|
|
38
38
|
readonly current: () => AuthSnapshot;
|
|
39
39
|
/** `useSyncExternalStore`-compatible. */
|
|
40
40
|
readonly subscribe: (listener: () => void) => () => void;
|
|
41
41
|
}
|
|
42
|
-
interface
|
|
43
|
-
/** The definition the
|
|
44
|
-
readonly
|
|
42
|
+
interface BetterClient<M extends AnyModels, F extends AnyFunctions, E, C = unknown, P = unknown> {
|
|
43
|
+
/** The definition the client was created from (schema metadata, specs, live queries). */
|
|
44
|
+
readonly betterSupabase: BetterSupabase<M, unknown, F, E, C, P>;
|
|
45
45
|
readonly supabase: SupabaseClient;
|
|
46
46
|
/** Repositories with the current session's actor and claims. */
|
|
47
47
|
readonly db: Db<M, F, E, SupabaseClient>;
|
|
48
48
|
/** TanStack Query option factories over `db`. */
|
|
49
|
-
readonly queries:
|
|
50
|
-
readonly auth:
|
|
49
|
+
readonly queries: BetterQueries<M, E, F>;
|
|
50
|
+
readonly auth: ClientAuth;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* The browser side: a supabase-js client, repositories that follow the
|
|
54
54
|
* session, TanStack Query options and an auth store for UI state.
|
|
55
55
|
*
|
|
56
56
|
* ```ts
|
|
57
|
-
* export const
|
|
57
|
+
* export const bs = createClient(betterSupabase, { env: { url, publishableKey } });
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
|
-
declare function
|
|
60
|
+
declare function createClient$1<M extends AnyModels, D, F extends AnyFunctions, E, C = unknown, P = unknown>(betterSupabase: BetterSupabase<M, D, F, E, C, P>, options?: ClientOptions): BetterClient<M, F, E, C, P>;
|
|
61
61
|
//#endregion
|
|
62
|
-
export {
|
|
62
|
+
export { ClientOptions as a, ClientAuth as i, AuthUser as n, createClient$1 as o, BetterClient as r, AuthSnapshot as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { A as SchemaMeta, C as PrimaryKeyValue, D as Relations, E as RelationTypes, F as UniqueConstraint, I as UniqueKeyName, L as UniqueWhere, M as TableFlags, N as TableKey, O as Row, P as TableMeta, R as Update, S as PrimaryKeyColumn, T as RelationMeta, _ as ModelFlags, a as Casing, b as PermdockBucketPolicy, c as Codec, d as Flags, f as ForeignKeyConstraint, g as Insert, h as FunctionsOf, i as BucketPolicyName, j as Simplify, k as Schema, l as ColumnMeta, m as FunctionTypes, n as AnyModels, o as CheckConstraint, p as FunctionMeta, r as BucketMeta, s as ClaimsMeta, t as AnyFunctions, u as DatabaseOf, v as ModelTypes, w as RealtimeTableMeta, x as PermdockTopicPolicy, y as ModelsOf } from "./types-DONv9SHN.js";
|
|
2
|
-
import { C as and, E as or, S as UpdateOp, T as not, _ as OrderTerm, a as AggregateFn, b as SelectOp, c as Condition, d as FunctionSource, f as Include, g as Operation, h as MutationOp, i as RpcContext, l as CountMode, m as Measure, n as ExecuteResult, o as Aggregation, p as InsertOp, r as Executor, s as ColumnOp, t as ExecuteContext, u as DeleteOp, v as Quantifier, w as column, x as Selection, y as SelectColumn } from "./executor-
|
|
3
|
-
import { C as isConflict, D as statusOf, E as mapDbError, S as isCheck, T as isForeignKey, _ as DbException, a as Ok, b as ValidationIssue, c as err, d as toBetterResult, f as toDbError, g as DbErrorOf, h as DbErrorKinds, i as Err, l as fromBetterResult, m as DbErrorKind, n as BetterResultApi, o as Result, p as DbError, r as BetterResultValue, t as AsyncResult, u as ok, v as ErrorMapper, w as isDbError, x as dbError, y as RawDbError } from "./result-
|
|
4
|
-
import { a as EventHub, c as QueryEvent, d as LogFields, f as Logger, i as EventHandler, l as RefreshEvent, m as silentLogger, n as BetterSupabaseEvents, o as EventName, p as consoleLogger, r as ErrorEvent, s as MutationNotice, t as AuthEvent, u as RpcNotice } from "./events-
|
|
5
|
-
import { $ as Specs, A as RpcOptions, B as ReadSet, C as FindExt, Ct as WhereInput, D as Repository, E as PageOf, F as EMPTY_STATS, G as ReadSetParams, H as ReadSetParamType, I as StatsRecorder, J as isReadSet, K as ReadSetResult, L as recordStats, M as UpsertArgs, N as WriteArgs, O as RepositoryOf, P as DbStats, Q as ReadMethod, R as SearchArgs, S as DeleteExt, St as SortDirection, T as OffsetPageArgs, U as ReadSetParamTypes, V as ReadSetOptions, W as ReadSetParamValue, X as InferResult, Y as readSetTables, Z as QuerySpec, _ as CursorPage, _t as OrderByInput, a as defineSupabase, at as AggregateRow, b as DbHelpers, bt as RelationMeasureArg, c as postgrestExecutor, ct as FieldFilter, d as MemoryCache, dt as IncludeArg, et as TableSpecs, f as cacheTargetOf, ft as IncludeArgs, g as ConflictTarget, gt as OrderByArg, h as rpcCacheTargets, ht as NumericMeasureArg, i as
|
|
6
|
-
import { _ as definePlugin, a as ExtensionOf, c as MutationEvent, d as PLUGIN_API_VERSION, f as Plugin, g as WithExtension, h as RequestContext, i as CallOptions, l as MutationKind, m as RepositoryExtension, n as AnyPlugin, o as HasFlag, p as RepositoryApi, r as ApplyExtension, s as HookArgs, t as Actor, u as NoExtension } from "./plugin-
|
|
7
|
-
import { n as validate, t as StandardSchemaV1 } from "./standard-
|
|
8
|
-
import { a as compilePostgrest, i as PostgrestPlan, n as PlanLimit, r as PlanOrder, t as PlanFilter } from "./postgrest-
|
|
2
|
+
import { C as and, E as or, S as UpdateOp, T as not, _ as OrderTerm, a as AggregateFn, b as SelectOp, c as Condition, d as FunctionSource, f as Include, g as Operation, h as MutationOp, i as RpcContext, l as CountMode, m as Measure, n as ExecuteResult, o as Aggregation, p as InsertOp, r as Executor, s as ColumnOp, t as ExecuteContext, u as DeleteOp, v as Quantifier, w as column, x as Selection, y as SelectColumn } from "./executor-B5IoUxLE.js";
|
|
3
|
+
import { C as isConflict, D as statusOf, E as mapDbError, S as isCheck, T as isForeignKey, _ as DbException, a as Ok, b as ValidationIssue, c as err, d as toBetterResult, f as toDbError, g as DbErrorOf, h as DbErrorKinds, i as Err, l as fromBetterResult, m as DbErrorKind, n as BetterResultApi, o as Result, p as DbError, r as BetterResultValue, t as AsyncResult, u as ok, v as ErrorMapper, w as isDbError, x as dbError, y as RawDbError } from "./result-CqEsbgYs.js";
|
|
4
|
+
import { a as EventHub, c as QueryEvent, d as LogFields, f as Logger, i as EventHandler, l as RefreshEvent, m as silentLogger, n as BetterSupabaseEvents, o as EventName, p as consoleLogger, r as ErrorEvent, s as MutationNotice, t as AuthEvent, u as RpcNotice } from "./events-B21UOhvP.js";
|
|
5
|
+
import { $ as Specs, A as RpcOptions, B as ReadSet, C as FindExt, Ct as WhereInput, D as Repository, E as PageOf, F as EMPTY_STATS, G as ReadSetParams, H as ReadSetParamType, I as StatsRecorder, J as isReadSet, K as ReadSetResult, L as recordStats, M as UpsertArgs, N as WriteArgs, O as RepositoryOf, P as DbStats, Q as ReadMethod, R as SearchArgs, S as DeleteExt, St as SortDirection, T as OffsetPageArgs, U as ReadSetParamTypes, V as ReadSetOptions, W as ReadSetParamValue, X as InferResult, Y as readSetTables, Z as QuerySpec, _ as CursorPage, _t as OrderByInput, a as defineSupabase, at as AggregateRow, b as DbHelpers, bt as RelationMeasureArg, c as postgrestExecutor, ct as FieldFilter, d as MemoryCache, dt as IncludeArg, et as TableSpecs, f as cacheTargetOf, ft as IncludeArgs, g as ConflictTarget, gt as OrderByArg, h as rpcCacheTargets, ht as NumericMeasureArg, i as SupabaseOptions, it as AggregateResult, j as UpdateArgs, k as Returned, l as CacheAdapter, lt as FindFirstArgs, m as rowKey, mt as MeasureKey, n as ConnectOptions, nt as specTables, o as PostgrestClientLike, ot as CountArg, p as memoryCache, pt as MeasureArg, q as defineReadSet, r as RpcDefinition, rt as AggregateArgs, s as explainPostgrest, st as CountArgs, t as BetterSupabase, tt as isQuerySpec, u as CacheTarget, ut as FindManyArgs, v as CursorPageArgs, vt as Payload, w as OffsetPage, x as DeleteArgs, xt as SelectArg, y as Db, yt as ReadArgs, z as InferReadSetParams } from "./define-CRS2MRV3.js";
|
|
6
|
+
import { _ as definePlugin, a as ExtensionOf, c as MutationEvent, d as PLUGIN_API_VERSION, f as Plugin, g as WithExtension, h as RequestContext, i as CallOptions, l as MutationKind, m as RepositoryExtension, n as AnyPlugin, o as HasFlag, p as RepositoryApi, r as ApplyExtension, s as HookArgs, t as Actor, u as NoExtension } from "./plugin-bNhvJwRh.js";
|
|
7
|
+
import { n as validate, t as StandardSchemaV1 } from "./standard-BsaCYQJc.js";
|
|
8
|
+
import { a as compilePostgrest, i as PostgrestPlan, n as PlanLimit, r as PlanOrder, t as PlanFilter } from "./postgrest-Bc-0Xw62.js";
|
|
9
9
|
import { n as StoragePath } from "./path-Cv__-OTj.js";
|
|
10
|
-
import { n as postgrestCompiler, t as Compiler } from "./compiler-
|
|
11
|
-
import { a as ProblemResponseOptions, c as problemResponse, i as ProblemOptions, l as toProblem, n as PROBLEM_TYPE_BASE, o as fromProblem, r as ProblemDetails, s as isProblem, t as PROBLEM_CONTENT_TYPE } from "./problem-
|
|
10
|
+
import { n as postgrestCompiler, t as Compiler } from "./compiler-DB3aSFOA.js";
|
|
11
|
+
import { a as ProblemResponseOptions, c as problemResponse, i as ProblemOptions, l as toProblem, n as PROBLEM_TYPE_BASE, o as fromProblem, r as ProblemDetails, s as isProblem, t as PROBLEM_CONTENT_TYPE } from "./problem-U8UEKccv.js";
|
|
12
12
|
import { t as SPEC_PINS } from "./spec-pins-CqorWDnO.js";
|
|
13
13
|
//#region src/core/define-repository.d.ts
|
|
14
14
|
/** Adds `Methods` to the repository of `Table` only. */
|
|
@@ -20,14 +20,14 @@ interface TableRepositoryExtension<Table extends string, Methods> extends Reposi
|
|
|
20
20
|
* repository at call time, with every other plugin's methods.
|
|
21
21
|
*
|
|
22
22
|
* ```ts
|
|
23
|
-
* const customers = defineRepository(
|
|
23
|
+
* const customers = defineRepository(betterSupabase, 'customers', (base) => ({
|
|
24
24
|
* active: () => base.findMany({ where: { status: 'active' } }),
|
|
25
25
|
* }));
|
|
26
|
-
* export const app =
|
|
26
|
+
* export const app = betterSupabase.use(customers);
|
|
27
27
|
* await app.connect(client).customers.active();
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
export declare function defineRepository<M extends AnyModels, D, F extends AnyFunctions, E, const Table extends TableKey<M>, Methods extends object>(
|
|
30
|
+
export declare function defineRepository<M extends AnyModels, D, F extends AnyFunctions, E, const Table extends TableKey<M>, Methods extends object>(betterSupabase: BetterSupabase<M, D, F, E>, table: Table, build: (base: RepositoryOf<M, Table, E>) => Methods): Plugin<`repository:${Table}`, TableRepositoryExtension<Table, Methods>>;
|
|
31
31
|
//#endregion
|
|
32
32
|
//#region src/ir/tables.d.ts
|
|
33
33
|
/**
|
|
@@ -41,7 +41,7 @@ export declare function touchedTables(op: Operation): string[];
|
|
|
41
41
|
* plus every table whose foreign key cascades or sets a value on delete,
|
|
42
42
|
* followed through chains of cascades.
|
|
43
43
|
*/
|
|
44
|
-
export declare function invalidationTargets(meta: SchemaMeta, table: string): string[];
|
|
44
|
+
export declare function invalidationTargets(meta: SchemaMeta, table: string): readonly string[];
|
|
45
45
|
//#endregion
|
|
46
46
|
//#region src/core/cursor.d.ts
|
|
47
47
|
/** Opaque, URL-safe keyset cursor. */
|
|
@@ -74,7 +74,7 @@ export declare function escapeLike(value: string): string;
|
|
|
74
74
|
/** Wire form of an app value: Temporal values to ISO text, `bigint` to decimal text. */
|
|
75
75
|
export declare function encodeValue(value: unknown): unknown;
|
|
76
76
|
/** Applies column codecs to returned rows, including embedded relations. */
|
|
77
|
-
export declare function decodeRows(selection: Selection | undefined, rows: readonly Record<string, unknown>[]): Record<string, unknown>[];
|
|
77
|
+
export declare function decodeRows(selection: Selection | undefined, rows: readonly Record<string, unknown>[], checked?: boolean): Record<string, unknown>[];
|
|
78
78
|
//#endregion
|
|
79
79
|
//#region src/ir/scope.d.ts
|
|
80
80
|
/** Returns the filter that always applies to rows of `table`, if any. */
|
|
@@ -107,4 +107,4 @@ export declare function toCamel(name: string): string;
|
|
|
107
107
|
/** `firstName` to `first_name`. */
|
|
108
108
|
export declare function toSnake(name: string): string;
|
|
109
109
|
//#endregion
|
|
110
|
-
export { type Actor, type AggregateArgs, type AggregateFn, type AggregateResult, type AggregateRow, type Aggregation, type AnyFunctions, type AnyModels, type AnyPlugin, type ApplyExtension, AsyncResult, type AuthEvent, type BetterResultApi, type BetterResultValue, BetterSupabase, type BetterSupabaseEvents, type BucketMeta, type BucketPolicyName, type CacheAdapter, type CacheTarget, type CallOptions, type Casing, type CheckConstraint, type ClaimsMeta, type Codec, type ColumnMeta, type ColumnOp, type Compiler, type Condition, type ConflictTarget, type ConnectOptions, type CountArg, type CountArgs, type CountMode, type CursorPage, type CursorPageArgs, type DatabaseOf, type Db, type DbError, type DbErrorKind, type DbErrorKinds, type DbErrorOf, DbException, type DbHelpers, type DbStats, type
|
|
110
|
+
export { type Actor, type AggregateArgs, type AggregateFn, type AggregateResult, type AggregateRow, type Aggregation, type AnyFunctions, type AnyModels, type AnyPlugin, type ApplyExtension, AsyncResult, type AuthEvent, type BetterResultApi, type BetterResultValue, BetterSupabase, type BetterSupabaseEvents, type BucketMeta, type BucketPolicyName, type CacheAdapter, type CacheTarget, type CallOptions, type Casing, type CheckConstraint, type ClaimsMeta, type Codec, type ColumnMeta, type ColumnOp, type Compiler, type Condition, type ConflictTarget, type ConnectOptions, type CountArg, type CountArgs, type CountMode, type CursorPage, type CursorPageArgs, type DatabaseOf, type Db, type DbError, type DbErrorKind, type DbErrorKinds, type DbErrorOf, DbException, type DbHelpers, type DbStats, type DeleteArgs, type DeleteExt, type DeleteOp, EMPTY_STATS, type EnrichDatabase, type Err, type ErrorEvent, type ErrorMapper, type EventHandler, EventHub, type EventName, type ExecuteContext, type ExecuteResult, type Executor, type ExtensionOf, type FieldFilter, type FindExt, type FindFirstArgs, type FindManyArgs, type Flags, type ForeignKeyConstraint, type FunctionMeta, type FunctionSource, type FunctionTypes, type FunctionsOf, type HasFlag, type HookArgs, type Include, type IncludeArg, type IncludeArgs, type InferReadSetParams, type InferResult, type Insert, type InsertOp, type LogFields, type Logger, type Measure, type MeasureArg, type MeasureKey, type MemoryCache, type ModelFlags, type ModelTypes, type ModelsOf, type MutationEvent, type MutationKind, type MutationNotice, type MutationOp, type NoExtension, type NumericMeasureArg, type OffsetPage, type OffsetPageArgs, type Ok, type Operation, type OrderByArg, type OrderByInput, type OrderTerm, PLUGIN_API_VERSION, PROBLEM_CONTENT_TYPE, PROBLEM_TYPE_BASE, type PageOf, type Payload, type PermdockBucketPolicy, type PermdockTopicPolicy, type PlanFilter, type PlanLimit, type PlanOrder, type Plugin, type PostgrestClientLike, type PostgrestPlan, type PrimaryKeyColumn, type PrimaryKeyValue, type ProblemDetails, type ProblemOptions, type ProblemResponseOptions, type Quantifier, type QueryEvent, type QuerySpec, type RawDbError, type ReadArgs, type ReadMethod, type ReadSet, type ReadSetOptions, type ReadSetParamType, type ReadSetParamTypes, type ReadSetParamValue, type ReadSetParams, type ReadSetResult, type RealtimeTableMeta, type RefreshEvent, type RelationMeasureArg, type RelationMeta, type RelationTypes, type Relations, type Repository, type RepositoryApi, type RepositoryExtension, type RepositoryOf, type RequestContext, type Result, type Returned, type Row, type RpcContext, type RpcDefinition, type RpcNotice, type RpcOptions, SPEC_PINS, type Schema, type SchemaMeta, type ScopeFor, type SearchArgs, type SelectArg, type SelectColumn, type SelectOp, type Selection, type Simplify, type SortDirection, type Specs, type StandardSchemaV1, StatsRecorder, type StoragePath, type SupabaseOptions, type TableFlags, type TableKey, type TableMeta, type TableRepositoryExtension, type TableSpecs, type UniqueConstraint, type UniqueKeyName, type UniqueWhere, type Update, type UpdateArgs, type UpdateOp, type UpsertArgs, type ValidationIssue, type WhereInput, type WithExtension, type WriteArgs, and, cacheTargetOf, column, compilePostgrest, consoleLogger, dbError, definePlugin, defineReadSet, defineSupabase, err, explainPostgrest, fromBetterResult, fromProblem, isCheck, isConflict, isDbError, isForeignKey, isProblem, isQuerySpec, isReadSet, mapDbError, memoryCache, not, ok, or, postgrestCompiler, postgrestExecutor, problemResponse, readSetTables, recordStats, rowKey, rpcCacheTargets, silentLogger, specTables, statusOf, toBetterResult, toDbError, toProblem, validate };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { a as isConflict, c as mapDbError, i as isCheck, l as statusOf, n as dbError, o as isDbError, s as isForeignKey, t as DbException } from "./errors-
|
|
2
|
-
import { i as escapeLike, l as defineSchema, o as decodeRows, s as encodeValue, t as simplify, u as tableMeta } from "./simplify-
|
|
1
|
+
import { a as isConflict, c as mapDbError, i as isCheck, l as statusOf, n as dbError, o as isDbError, s as isForeignKey, t as DbException } from "./errors-L0xK41y_.js";
|
|
2
|
+
import { i as escapeLike, l as defineSchema, o as decodeRows, s as encodeValue, t as simplify, u as tableMeta } from "./simplify-Cqvfr9dj.js";
|
|
3
3
|
import { i as or, n as column, r as not, t as and } from "./types-6cYK9pbJ.js";
|
|
4
|
-
import { a as toBetterResult, i as ok, n as err, o as toDbError, r as fromBetterResult, t as AsyncResult } from "./result-
|
|
5
|
-
import { a as EventHub, c as rowKey, i as encodeCursor, l as rpcCacheTargets, n as defineSupabase, o as cacheTargetOf, r as decodeCursor, s as memoryCache, t as BetterSupabase } from "./define-
|
|
6
|
-
import { n as touchedTables, t as invalidationTargets } from "./tables-
|
|
4
|
+
import { a as toBetterResult, i as ok, n as err, o as toDbError, r as fromBetterResult, t as AsyncResult } from "./result-Bj6yt33D.js";
|
|
5
|
+
import { a as EventHub, c as rowKey, i as encodeCursor, l as rpcCacheTargets, n as defineSupabase, o as cacheTargetOf, r as decodeCursor, s as memoryCache, t as BetterSupabase } from "./define-Bh0AqTik.js";
|
|
6
|
+
import { n as touchedTables, t as invalidationTargets } from "./tables-Cb-3_VWc.js";
|
|
7
7
|
import { n as silentLogger, t as consoleLogger } from "./logger-glM28NVN.js";
|
|
8
8
|
import { n as definePlugin, t as PLUGIN_API_VERSION } from "./plugin-BqR6wKMB.js";
|
|
9
|
-
import { a as postgrestExecutor, i as explainPostgrest, n as StatsRecorder, o as compilePostgrest, r as recordStats, t as EMPTY_STATS } from "./stats-
|
|
10
|
-
import { c as readSetTables, d as isQuerySpec, f as specTables, i as defineReadSet, o as isReadSet } from "./read-set-
|
|
11
|
-
import { t as validate } from "./standard-
|
|
12
|
-
import { a as problemResponse, i as isProblem, n as PROBLEM_TYPE_BASE, o as toProblem, r as fromProblem, t as PROBLEM_CONTENT_TYPE } from "./problem-
|
|
9
|
+
import { a as postgrestExecutor, i as explainPostgrest, n as StatsRecorder, o as compilePostgrest, r as recordStats, t as EMPTY_STATS } from "./stats-C_YxA2r1.js";
|
|
10
|
+
import { c as readSetTables, d as isQuerySpec, f as specTables, i as defineReadSet, o as isReadSet } from "./read-set-FWK8qQ58.js";
|
|
11
|
+
import { t as validate } from "./standard-BRyBGTtp.js";
|
|
12
|
+
import { a as problemResponse, i as isProblem, n as PROBLEM_TYPE_BASE, o as toProblem, r as fromProblem, t as PROBLEM_CONTENT_TYPE } from "./problem-BihjPR0t.js";
|
|
13
13
|
import { t as SPEC_PINS } from "./spec-pins-C3oc-Tdp.js";
|
|
14
14
|
import { n as scopeOperation, r as scopeSelection, t as scopeCondition } from "./scope-CDHcS7dE.js";
|
|
15
15
|
//#region src/core/define-repository.ts
|
|
@@ -18,15 +18,15 @@ import { n as scopeOperation, r as scopeSelection, t as scopeCondition } from ".
|
|
|
18
18
|
* repository at call time, with every other plugin's methods.
|
|
19
19
|
*
|
|
20
20
|
* ```ts
|
|
21
|
-
* const customers = defineRepository(
|
|
21
|
+
* const customers = defineRepository(betterSupabase, 'customers', (base) => ({
|
|
22
22
|
* active: () => base.findMany({ where: { status: 'active' } }),
|
|
23
23
|
* }));
|
|
24
|
-
* export const app =
|
|
24
|
+
* export const app = betterSupabase.use(customers);
|
|
25
25
|
* await app.connect(client).customers.active();
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
function defineRepository(
|
|
29
|
-
if (!(table in
|
|
28
|
+
function defineRepository(betterSupabase, table, build) {
|
|
29
|
+
if (!(table in betterSupabase.meta.tables)) throw new TypeError(`better-supabase: defineRepository: unknown table "${table}"`);
|
|
30
30
|
return definePlugin({
|
|
31
31
|
name: `repository:${table}`,
|
|
32
32
|
repository: ({ table: meta, base }) => meta.key === table ? build(base) : void 0
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
//#region src/query/invalidate.ts
|
|
2
|
+
function isString(value) {
|
|
3
|
+
return typeof value === "string";
|
|
4
|
+
}
|
|
2
5
|
function queryTables(query) {
|
|
3
6
|
const tables = query.meta?.["bsTables"];
|
|
4
|
-
if (Array.isArray(tables))
|
|
7
|
+
if (Array.isArray(tables)) {
|
|
8
|
+
const list = tables;
|
|
9
|
+
return list.every(isString) ? list : list.filter(isString);
|
|
10
|
+
}
|
|
5
11
|
const [prefix, table] = query.queryKey;
|
|
6
12
|
return prefix === "bs" && typeof table === "string" ? [table] : void 0;
|
|
7
13
|
}
|
package/dist/jobs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { o as Result, p as DbError, t as AsyncResult } from "../result-
|
|
3
|
-
import { t as SqlClient } from "../executor-
|
|
2
|
+
import { o as Result, p as DbError, t as AsyncResult } from "../result-CqEsbgYs.js";
|
|
3
|
+
import { t as SqlClient } from "../executor-CZ7ImRiD.js";
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
5
|
//#region src/jobs/jobs.d.ts
|
|
6
6
|
type QueueSchemas = Readonly<Record<string, StandardSchemaV1>>;
|
|
@@ -46,8 +46,14 @@ type JobHandler<P> = (payload: P, job: Job<P>, signal: AbortSignal) => unknown;
|
|
|
46
46
|
interface WorkOptions extends ClaimOptions {
|
|
47
47
|
/** Jobs handled at once. Defaults to 1. */
|
|
48
48
|
readonly concurrency?: number;
|
|
49
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* First wait between polls when the queue is empty, in ms. Defaults to
|
|
51
|
+
* 1000. Each empty poll doubles the wait up to `maxPollInterval`; a claimed
|
|
52
|
+
* job resets it.
|
|
53
|
+
*/
|
|
50
54
|
readonly pollInterval?: number;
|
|
55
|
+
/** Longest wait between empty polls, in ms. Defaults to 30000. */
|
|
56
|
+
readonly maxPollInterval?: number;
|
|
51
57
|
/** Stops the loop; running jobs finish first. */
|
|
52
58
|
readonly signal?: AbortSignal;
|
|
53
59
|
readonly onError?: (error: DbError, job: Job) => void;
|
|
@@ -73,7 +79,7 @@ interface Jobs<Q extends QueueSchemas> {
|
|
|
73
79
|
schedule<N extends Extract<keyof Q, string>>(name: string, cron: string, queue: N, payload: PayloadIn<Q, N>): AsyncResult<void>;
|
|
74
80
|
unschedule(name: string): AsyncResult<boolean>;
|
|
75
81
|
/** Processes ready jobs until the queue is empty. For cron and edge invocations. */
|
|
76
|
-
drain<N extends Extract<keyof Q, string>>(queue: N, handler: JobHandler<PayloadOut<Q, N>>, options?: Omit<WorkOptions, "pollInterval" | "signal">): Promise<DrainResult>;
|
|
82
|
+
drain<N extends Extract<keyof Q, string>>(queue: N, handler: JobHandler<PayloadOut<Q, N>>, options?: Omit<WorkOptions, "pollInterval" | "maxPollInterval" | "signal">): Promise<DrainResult>;
|
|
77
83
|
/** Polls and processes jobs until `signal` aborts. */
|
|
78
84
|
work<N extends Extract<keyof Q, string>>(queue: N, handler: JobHandler<PayloadOut<Q, N>>, options?: WorkOptions): Promise<DrainResult>;
|
|
79
85
|
}
|
package/dist/jobs/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { c as mapDbError, n as dbError, t as DbException } from "../errors-
|
|
1
|
+
import { c as mapDbError, n as dbError, t as DbException } from "../errors-L0xK41y_.js";
|
|
2
2
|
import { n as nowInstant } from "../temporal-BwshQk0W.js";
|
|
3
|
-
import { t as temporal } from "../temporal-required-
|
|
4
|
-
import { i as ok, n as err, o as toDbError, t as AsyncResult } from "../result-
|
|
5
|
-
import { t as validate } from "../standard-
|
|
6
|
-
import { a as problemResponse } from "../problem-
|
|
7
|
-
import { t as fromPgError } from "../executor-
|
|
8
|
-
import { c as verifyWebhook } from "../webhooks-
|
|
3
|
+
import { t as temporal } from "../temporal-required-CBNHT6ni.js";
|
|
4
|
+
import { i as ok, n as err, o as toDbError, t as AsyncResult } from "../result-Bj6yt33D.js";
|
|
5
|
+
import { t as validate } from "../standard-BRyBGTtp.js";
|
|
6
|
+
import { a as problemResponse } from "../problem-BihjPR0t.js";
|
|
7
|
+
import { t as fromPgError } from "../executor-CVt6dD0B.js";
|
|
8
|
+
import { c as verifyWebhook } from "../webhooks-Bh_Jf_-l.js";
|
|
9
9
|
//#region src/jobs/jobs.ts
|
|
10
10
|
function run(fn) {
|
|
11
11
|
return AsyncResult.from(async () => {
|
|
@@ -200,12 +200,15 @@ function createJobs(source, queues) {
|
|
|
200
200
|
schemaOf(queue);
|
|
201
201
|
return (await transport.read(queue, claimOptions.lease ?? 300, claimOptions.batch ?? 1)).map((row) => toJob(queue, row));
|
|
202
202
|
});
|
|
203
|
+
/**
|
|
204
|
+
* Extends the lease of every job in `held` at half the lease, so jobs
|
|
205
|
+
* waiting their turn in a claimed batch don't expire before they run.
|
|
206
|
+
*/
|
|
207
|
+
const heartbeat = (held, lease) => transport.name === "sql" ? setInterval(() => {
|
|
208
|
+
for (const job of held) run(() => transport.extend(job, lease));
|
|
209
|
+
}, Math.max(1e3, lease * 1e3 / 2)) : void 0;
|
|
203
210
|
const handle = async (job, handler, workOptions) => {
|
|
204
211
|
const controller = new AbortController();
|
|
205
|
-
const lease = workOptions.lease ?? 300;
|
|
206
|
-
const heartbeat = transport.name === "sql" ? setInterval(() => {
|
|
207
|
-
run(() => transport.extend(job, lease));
|
|
208
|
-
}, Math.max(1e3, lease * 1e3 / 2)) : void 0;
|
|
209
212
|
try {
|
|
210
213
|
const payload = await validate(schemaOf(job.queue), job.payload, "payload");
|
|
211
214
|
if (!payload.ok) {
|
|
@@ -225,15 +228,17 @@ function createJobs(source, queues) {
|
|
|
225
228
|
await fail(job, cause);
|
|
226
229
|
workOptions.onError?.(typeof cause === "object" && cause !== null && "kind" in cause ? cause : toDbError(cause), job);
|
|
227
230
|
return false;
|
|
228
|
-
} finally {
|
|
229
|
-
clearInterval(heartbeat);
|
|
230
231
|
}
|
|
231
232
|
};
|
|
232
233
|
const loop = async (queue, handler, workOptions, forever) => {
|
|
233
234
|
const concurrency = Math.max(1, workOptions.concurrency ?? 1);
|
|
235
|
+
const lease = workOptions.lease ?? 300;
|
|
236
|
+
const firstWait = workOptions.pollInterval ?? 1e3;
|
|
237
|
+
const maxWait = Math.max(firstWait, workOptions.maxPollInterval ?? 3e4);
|
|
234
238
|
let succeeded = 0;
|
|
235
239
|
let failed = 0;
|
|
236
240
|
const lanes = Array.from({ length: concurrency }, async () => {
|
|
241
|
+
let wait = firstWait;
|
|
237
242
|
while (!workOptions.signal?.aborted) {
|
|
238
243
|
const claimed = await claim(queue, {
|
|
239
244
|
...workOptions,
|
|
@@ -242,11 +247,22 @@ function createJobs(source, queues) {
|
|
|
242
247
|
if (!claimed.ok) throw new TypeError(claimed.error.message, { cause: claimed.error });
|
|
243
248
|
if (claimed.data.length === 0) {
|
|
244
249
|
if (!forever) return;
|
|
245
|
-
await sleep(
|
|
250
|
+
await sleep(wait, workOptions.signal);
|
|
251
|
+
wait = Math.min(maxWait, wait * 2);
|
|
246
252
|
continue;
|
|
247
253
|
}
|
|
248
|
-
|
|
249
|
-
|
|
254
|
+
wait = firstWait;
|
|
255
|
+
const held = new Set(claimed.data);
|
|
256
|
+
const timer = heartbeat(held, lease);
|
|
257
|
+
try {
|
|
258
|
+
for (const job of claimed.data) {
|
|
259
|
+
if (await handle(job, handler, workOptions)) succeeded += 1;
|
|
260
|
+
else failed += 1;
|
|
261
|
+
held.delete(job);
|
|
262
|
+
}
|
|
263
|
+
} finally {
|
|
264
|
+
clearInterval(timer);
|
|
265
|
+
}
|
|
250
266
|
}
|
|
251
267
|
});
|
|
252
268
|
await Promise.all(lanes);
|
|
@@ -65,7 +65,7 @@ function variantsFor(table) {
|
|
|
65
65
|
];
|
|
66
66
|
}
|
|
67
67
|
function tableEntries(input) {
|
|
68
|
-
return Object.entries(input.meta.tables).sort(([a], [b]) => a
|
|
68
|
+
return Object.entries(input.meta.tables).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
69
69
|
}
|
|
70
70
|
function propertyKey(name) {
|
|
71
71
|
return /^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name);
|
package/dist/list/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ListPage, c as ListParsers, d as ListQueryInput, f as ListSearchParams, g as defineListQuery, h as UNSET, i as ListExtra, l as ListQuery, m as ParserSpec, n as FacetInfo, o as ListPagination, p as OpenApiParameter, r as ListDefinition, s as ListParseResult, t as FacetCounts, u as ListQueryConfig } from "../index-
|
|
1
|
+
import { a as ListPage, c as ListParsers, d as ListQueryInput, f as ListSearchParams, g as defineListQuery, h as UNSET, i as ListExtra, l as ListQuery, m as ParserSpec, n as FacetInfo, o as ListPagination, p as OpenApiParameter, r as ListDefinition, s as ListParseResult, t as FacetCounts, u as ListQueryConfig } from "../index-BAy4tsAP.js";
|
|
2
2
|
export { type FacetCounts, type FacetInfo, type ListDefinition, type ListExtra, type ListPage, type ListPagination, type ListParseResult, type ListParsers, type ListQuery, type ListQueryConfig, type ListQueryInput, type ListSearchParams, type OpenApiParameter, type ParserSpec, UNSET, defineListQuery };
|
package/dist/list/index.js
CHANGED
|
@@ -35,7 +35,7 @@ function toInt(raw) {
|
|
|
35
35
|
* OpenAPI parameters and a JSON Schema derived from the same definition.
|
|
36
36
|
*
|
|
37
37
|
* ```ts
|
|
38
|
-
* export const customerList = defineListQuery(
|
|
38
|
+
* export const customerList = defineListQuery(betterSupabase, 'customers', {
|
|
39
39
|
* search: ['name', 'kvk'],
|
|
40
40
|
* facets: { status: 'status' },
|
|
41
41
|
* sorts: { name: { name: 'asc' }, newest: [{ createdAt: 'desc' }, { id: 'asc' }] },
|
|
@@ -43,8 +43,8 @@ function toInt(raw) {
|
|
|
43
43
|
* });
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
-
function defineListQuery(
|
|
47
|
-
const meta =
|
|
46
|
+
function defineListQuery(betterSupabase, table, config) {
|
|
47
|
+
const meta = betterSupabase.meta.tables[table];
|
|
48
48
|
if (!meta) throw new TypeError(`defineListQuery: unknown table "${table}"`);
|
|
49
49
|
const pageSize = config.pageSize ?? 50;
|
|
50
50
|
const maxPageSize = config.maxPageSize ?? 200;
|