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,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as Executor } from "./executor-B5IoUxLE.js";
|
|
2
|
+
import { t as SqlClient } from "./executor-CZ7ImRiD.js";
|
|
2
3
|
//#region src/postgres/pool.d.ts
|
|
3
4
|
/** The part of a `pg` pool client `createPostgres` uses. */
|
|
4
5
|
interface PgPoolClient {
|
|
@@ -47,13 +48,19 @@ interface SqlClaims {
|
|
|
47
48
|
readonly role?: string;
|
|
48
49
|
readonly [claim: string]: unknown;
|
|
49
50
|
}
|
|
50
|
-
interface
|
|
51
|
+
interface BetterPostgres {
|
|
51
52
|
/** Connects as the connection-string role. On Supabase that bypasses RLS. */
|
|
52
53
|
readonly admin: SqlClient;
|
|
53
54
|
/** Runs every query as the given user, with RLS, like PostgREST does. */
|
|
54
55
|
asUser(claims: SqlClaims): SqlClient;
|
|
55
56
|
/** Runs every query as `anon`. */
|
|
56
57
|
readonly anon: SqlClient;
|
|
58
|
+
/**
|
|
59
|
+
* Repositories' executor as the given user (`postgresExecutor(asUser(claims))`).
|
|
60
|
+
* `createServer` calls it for `ctx.sql`, so only apps that pass `postgres`
|
|
61
|
+
* bundle the SQL compiler.
|
|
62
|
+
*/
|
|
63
|
+
executorFor(claims: SqlClaims): Executor;
|
|
57
64
|
/** Runs `fn` in one transaction. Pass claims to run it as a user. */
|
|
58
65
|
transaction<T>(fn: (client: SqlClient) => Promise<T>, options?: {
|
|
59
66
|
readonly claims?: SqlClaims;
|
|
@@ -66,6 +73,6 @@ interface Postgres {
|
|
|
66
73
|
* transaction) runs in its own transaction; claims and role are
|
|
67
74
|
* transaction-local, so nothing leaks back into the pool.
|
|
68
75
|
*/
|
|
69
|
-
declare function createPostgres(options?: PostgresOptions):
|
|
76
|
+
declare function createPostgres(options?: PostgresOptions): BetterPostgres;
|
|
70
77
|
//#endregion
|
|
71
|
-
export { PostgresTimeouts as a, PostgresOptions as i,
|
|
78
|
+
export { PostgresTimeouts as a, PostgresOptions as i, PgPool as n, SqlClaims as o, PgPoolClient as r, createPostgres as s, BetterPostgres as t };
|
package/dist/postgres/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { g as Operation } from "../executor-
|
|
2
|
-
import { n as fromPgError, r as postgresExecutor, t as SqlClient } from "../executor-
|
|
3
|
-
import { a as PostgresTimeouts, i as PostgresOptions, n as
|
|
4
|
-
import { t as Compiler } from "../compiler-
|
|
1
|
+
import { g as Operation } from "../executor-B5IoUxLE.js";
|
|
2
|
+
import { n as fromPgError, r as postgresExecutor, t as SqlClient } from "../executor-CZ7ImRiD.js";
|
|
3
|
+
import { a as PostgresTimeouts, i as PostgresOptions, n as PgPool, o as SqlClaims, r as PgPoolClient, s as createPostgres, t as BetterPostgres } from "../pool-DFwEQwmN.js";
|
|
4
|
+
import { t as Compiler } from "../compiler-DB3aSFOA.js";
|
|
5
5
|
//#region src/compile/sql.d.ts
|
|
6
6
|
interface SqlQuery {
|
|
7
7
|
readonly text: string;
|
|
@@ -30,4 +30,4 @@ export declare function compileSql(op: Operation): SqlPlan;
|
|
|
30
30
|
//#region src/postgres/compiler.d.ts
|
|
31
31
|
export declare const sqlCompiler: Compiler<SqlPlan>;
|
|
32
32
|
//#endregion
|
|
33
|
-
export { type
|
|
33
|
+
export { type BetterPostgres, type PgPool, type PgPoolClient, type PostgresOptions, type PostgresTimeouts, type SqlClaims, type SqlClient, type SqlPlan, type SqlQuery, createPostgres, fromPgError, postgresExecutor };
|
package/dist/postgres/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as quoteIdent, t as compileSql } from "../sql-
|
|
2
|
-
import { n as postgresExecutor, t as fromPgError } from "../executor-
|
|
1
|
+
import { n as quoteIdent, t as compileSql } from "../sql-B34HU2DI.js";
|
|
2
|
+
import { n as postgresExecutor, t as fromPgError } from "../executor-CVt6dD0B.js";
|
|
3
3
|
import { Pool } from "pg";
|
|
4
4
|
//#region src/postgres/pool.ts
|
|
5
5
|
const DEFAULT_TIMEOUTS = {
|
|
@@ -84,6 +84,7 @@ function createPostgres(options = {}) {
|
|
|
84
84
|
role: "anon"
|
|
85
85
|
}),
|
|
86
86
|
asUser: (claims) => clientFor(sessionFor(claims)),
|
|
87
|
+
executorFor: (claims) => postgresExecutor(clientFor(sessionFor(claims))),
|
|
87
88
|
transaction: (fn, txOptions) => transaction(txOptions?.claims ? sessionFor(txOptions.claims) : void 0, fn),
|
|
88
89
|
end: () => pool.end(),
|
|
89
90
|
[Symbol.asyncDispose]: () => pool.end()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as ValidationIssue, m as DbErrorKind, p as DbError } from "./result-
|
|
1
|
+
import { b as ValidationIssue, m as DbErrorKind, p as DbError } from "./result-CqEsbgYs.js";
|
|
2
2
|
//#region src/core/problem.d.ts
|
|
3
3
|
/** RFC 9457 Problem Details, with the `DbError` fields as extension members. */
|
|
4
4
|
interface ProblemDetails {
|
package/dist/query/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as QueryHelpers, c as TableQueries, d as queryCache, f as BetterQueryMeta, i as
|
|
2
|
-
export { type
|
|
1
|
+
import { a as QueryHelpers, c as TableQueries, d as queryCache, f as BetterQueryMeta, i as QueriesOptions, l as createQueries, n as InfiniteOptionsOf, o as QueryKeyOf, p as invalidateTables, r as MutationOptionsOf, s as QueryOptionsOf, t as BetterQueries, u as invalidateOnMutation } from "../index-DFmOpBGC.js";
|
|
2
|
+
export { type BetterQueries, type BetterQueryMeta, type InfiniteOptionsOf, type MutationOptionsOf, type QueriesOptions, type QueryHelpers, type QueryKeyOf, type QueryOptionsOf, type TableQueries, createQueries, invalidateOnMutation, invalidateTables, queryCache };
|
package/dist/query/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as invalidateTables } from "../invalidate-
|
|
2
|
-
import { n as invalidateOnMutation, r as queryCache, t as createQueries } from "../query-
|
|
1
|
+
import { t as invalidateTables } from "../invalidate-CgxmRamI.js";
|
|
2
|
+
import { n as invalidateOnMutation, r as queryCache, t as createQueries } from "../query-BMMSWbI7.js";
|
|
3
3
|
export { createQueries, invalidateOnMutation, invalidateTables, queryCache };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as DbException } from "./errors-
|
|
2
|
-
import { t as invalidationTargets } from "./tables-
|
|
3
|
-
import { t as invalidateTables } from "./invalidate-
|
|
1
|
+
import { t as DbException } from "./errors-L0xK41y_.js";
|
|
2
|
+
import { t as invalidationTargets } from "./tables-Cb-3_VWc.js";
|
|
3
|
+
import { t as invalidateTables } from "./invalidate-CgxmRamI.js";
|
|
4
4
|
//#region src/query/queries.ts
|
|
5
|
-
/** Query errors stay `DbException`s, even for an `
|
|
5
|
+
/** Query errors stay `DbException`s, even for an `betterSupabase` with `mapError()`. */
|
|
6
6
|
const asException = (error) => new DbException(error);
|
|
7
7
|
function isSkip(value) {
|
|
8
8
|
return typeof value === "symbol";
|
|
@@ -28,13 +28,13 @@ function specQuery(runtime, spec, key) {
|
|
|
28
28
|
...spec.args
|
|
29
29
|
],
|
|
30
30
|
queryFn: ({ signal }) => runtime.db().$run(spec, { signal }).orThrow(asException),
|
|
31
|
-
meta: { bsTables: runtime.
|
|
31
|
+
meta: { bsTables: runtime.betterSupabase.tablesOf(spec) },
|
|
32
32
|
...stale
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function tableQueries(runtime, table) {
|
|
36
36
|
const key = ["bs", table];
|
|
37
|
-
const specs = runtime.
|
|
37
|
+
const specs = runtime.betterSupabase.spec[table];
|
|
38
38
|
const stale = runtime.staleTime === void 0 ? {} : { staleTime: runtime.staleTime };
|
|
39
39
|
const read = (method) => (args) => isSkip(args) ? specQuery(runtime, args, [
|
|
40
40
|
...key,
|
|
@@ -84,7 +84,7 @@ function tableQueries(runtime, table) {
|
|
|
84
84
|
}), { signal }).orThrow(asException),
|
|
85
85
|
initialPageParam: null,
|
|
86
86
|
getNextPageParam: (last) => last.nextCursor ?? void 0,
|
|
87
|
-
meta: { bsTables: runtime.
|
|
87
|
+
meta: { bsTables: runtime.betterSupabase.tablesOf(specs["paginate"]({
|
|
88
88
|
...base,
|
|
89
89
|
after: null
|
|
90
90
|
})) },
|
|
@@ -105,14 +105,14 @@ function tableQueries(runtime, table) {
|
|
|
105
105
|
}), { signal }).orThrow(asException),
|
|
106
106
|
initialPageParam: base.page ?? 1,
|
|
107
107
|
getNextPageParam: (last) => last.page.hasMore ? last.page.number + 1 : void 0,
|
|
108
|
-
meta: { bsTables: runtime.
|
|
108
|
+
meta: { bsTables: runtime.betterSupabase.tablesOf(specs["paginate"](base)) },
|
|
109
109
|
...stale
|
|
110
110
|
};
|
|
111
111
|
},
|
|
112
112
|
create: (args) => mutation("create", (data) => call("create", data, args), [table]),
|
|
113
113
|
update: (args) => mutation("update", (variables) => call("update", variables.id, variables.patch, args), [table]),
|
|
114
114
|
upsert: (args) => mutation("upsert", (data) => call("upsert", data, args), [table]),
|
|
115
|
-
delete: (args) => mutation("delete", (id) => call("delete", id, args), invalidationTargets(runtime.
|
|
115
|
+
delete: (args) => mutation("delete", (id) => call("delete", id, args), invalidationTargets(runtime.betterSupabase.meta, table))
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
@@ -123,19 +123,19 @@ function tableQueries(runtime, table) {
|
|
|
123
123
|
* changed table.
|
|
124
124
|
*
|
|
125
125
|
* ```ts
|
|
126
|
-
* const q = createQueries(
|
|
126
|
+
* const q = createQueries(betterSupabase, () => bs.db);
|
|
127
127
|
* const { data } = useQuery(q.customers.findMany({ select: ['id', 'name'] }));
|
|
128
128
|
* ```
|
|
129
129
|
*/
|
|
130
|
-
function createQueries(
|
|
130
|
+
function createQueries(betterSupabase, db, options = {}) {
|
|
131
131
|
const runtime = {
|
|
132
|
-
|
|
132
|
+
betterSupabase,
|
|
133
133
|
db: typeof db === "function" ? db : () => db,
|
|
134
134
|
staleTime: options.staleTime
|
|
135
135
|
};
|
|
136
136
|
const stale = options.staleTime === void 0 ? {} : { staleTime: options.staleTime };
|
|
137
137
|
const queries = {
|
|
138
|
-
key: ["bs"],
|
|
138
|
+
$key: ["bs"],
|
|
139
139
|
$spec: (spec) => specQuery(runtime, spec),
|
|
140
140
|
$prefetch: (client, spec) => client.prefetchQuery(specQuery(runtime, spec)),
|
|
141
141
|
$rpc: (name, args, rpcOptions = {}) => ({
|
|
@@ -156,10 +156,10 @@ function createQueries(sb, db, options = {}) {
|
|
|
156
156
|
name
|
|
157
157
|
],
|
|
158
158
|
mutationFn: (args) => runtime.db().$rpc(name, args ?? {}).orThrow(asException),
|
|
159
|
-
onSuccess: (_data, _variables, _result, context) => invalidateTables(context.client, (
|
|
159
|
+
onSuccess: (_data, _variables, _result, context) => invalidateTables(context.client, (betterSupabase.options.rpc?.[name]?.invalidates ?? []).flatMap((table) => invalidationTargets(betterSupabase.meta, table)))
|
|
160
160
|
})
|
|
161
161
|
};
|
|
162
|
-
for (const table of Object.keys(
|
|
162
|
+
for (const table of Object.keys(betterSupabase.meta.tables)) {
|
|
163
163
|
let built;
|
|
164
164
|
Object.defineProperty(queries, table, {
|
|
165
165
|
enumerable: true,
|
|
@@ -178,9 +178,9 @@ function queryCache(client) {
|
|
|
178
178
|
invalidate: (target) => invalidateTables(client, target.tables)
|
|
179
179
|
};
|
|
180
180
|
}
|
|
181
|
-
/** Invalidates affected queries for every mutation and declared RPC `
|
|
182
|
-
function invalidateOnMutation(
|
|
183
|
-
return
|
|
181
|
+
/** Invalidates affected queries for every mutation and declared RPC `betterSupabase` performs in this runtime. */
|
|
182
|
+
function invalidateOnMutation(betterSupabase, client) {
|
|
183
|
+
return betterSupabase.cache(queryCache(client));
|
|
184
184
|
}
|
|
185
185
|
//#endregion
|
|
186
186
|
export { invalidateOnMutation as n, queryCache as r, createQueries as t };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { s as Impersonator } from "../mfa-
|
|
2
|
-
import { t as AuthSession } from "../view-
|
|
3
|
-
import { r as LiveCountSeed } from "../live-
|
|
4
|
-
import { n as MembershipClaim, r as hasEntitlement, t as EntitlementKey } from "../entitlements-
|
|
5
|
-
import { a as
|
|
1
|
+
import { s as Impersonator } from "../mfa-C7MNQ1Ob.js";
|
|
2
|
+
import { t as AuthSession } from "../view-B64o81wp.js";
|
|
3
|
+
import { r as LiveCountSeed } from "../live-BHakSWWo.js";
|
|
4
|
+
import { n as MembershipClaim, r as hasEntitlement, t as EntitlementKey } from "../entitlements-Dm-FHpNH.js";
|
|
5
|
+
import { a as ClaimsOf, c as LiveCountHookOptions, d as createHooks, f as useAuth, g as useSupabase, h as useLiveQuery, i as BroadcastOptions, l as LiveQueryHookOptions, m as useLiveCount, n as BetterSupabaseProvider, o as ClientLike, p as useBroadcast, r as BetterSupabaseProviderProps, s as LiveCount, t as BetterHooks, u as ProfileOf } from "../index-BBdvo-5d.js";
|
|
6
6
|
import { SessionProvider, SessionProviderProps, useSession } from "./session.js";
|
|
7
|
-
export { type AuthSession, type BetterHooks, BetterSupabaseProvider, type BetterSupabaseProviderProps, type BroadcastOptions, type
|
|
7
|
+
export { type AuthSession, type BetterHooks, BetterSupabaseProvider, type BetterSupabaseProviderProps, type BroadcastOptions, type ClaimsOf, type ClientLike, type EntitlementKey, type Impersonator, type LiveCount, type LiveCountHookOptions, type LiveCountSeed, type LiveQueryHookOptions, type MembershipClaim, type ProfileOf, SessionProvider, type SessionProviderProps, createHooks, hasEntitlement, useAuth, useBroadcast, useLiveCount, useLiveQuery, useSession, useSupabase };
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { SessionProvider, useSession } from "./session.js";
|
|
3
|
-
import { a as useLiveCount, i as useBroadcast, n as createHooks, o as useLiveQuery, r as useAuth, s as useSupabase, t as BetterSupabaseProvider } from "../react-
|
|
3
|
+
import { a as useLiveCount, i as useBroadcast, n as createHooks, o as useLiveQuery, r as useAuth, s as useSupabase, t as BetterSupabaseProvider } from "../react-CQHMaESR.js";
|
|
4
4
|
import { t as hasEntitlement } from "../entitlements-CTEBm7IB.js";
|
|
5
5
|
export { BetterSupabaseProvider, SessionProvider, createHooks, hasEntitlement, useAuth, useBroadcast, useLiveCount, useLiveQuery, useSession, useSupabase };
|
package/dist/react/server.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { t as AuthSession } from "../view-
|
|
2
|
-
import { a as
|
|
1
|
+
import { t as AuthSession } from "../view-B64o81wp.js";
|
|
2
|
+
import { a as ClaimsOf, f as useAuth, g as useSupabase, h as useLiveQuery, i as BroadcastOptions, l as LiveQueryHookOptions, n as BetterSupabaseProvider, o as ClientLike, p as useBroadcast, r as BetterSupabaseProviderProps, t as BetterHooks, u as ProfileOf } from "../index-BBdvo-5d.js";
|
|
3
3
|
import { SessionProvider, SessionProviderProps } from "./session.js";
|
|
4
4
|
//#region src/react/server.d.ts
|
|
5
|
-
/** The `react-server` build of `useSession`: await `
|
|
5
|
+
/** The `react-server` build of `useSession`: await `bs.session()` instead. */
|
|
6
6
|
export declare const useSession: <C = unknown, P = unknown>() => AuthSession<C, P>;
|
|
7
7
|
/**
|
|
8
8
|
* The `react-server` build of `createHooks`: importing a module that creates
|
|
9
9
|
* hooks is safe on the server, calling a hook there throws.
|
|
10
10
|
*/
|
|
11
|
-
export declare function createHooks<B extends
|
|
11
|
+
export declare function createHooks<B extends ClientLike>(): BetterHooks<B>;
|
|
12
12
|
//#endregion
|
|
13
|
-
export { type AuthSession, type BetterHooks, BetterSupabaseProvider, type BetterSupabaseProviderProps, type BroadcastOptions, type
|
|
13
|
+
export { type AuthSession, type BetterHooks, BetterSupabaseProvider, type BetterSupabaseProviderProps, type BroadcastOptions, type ClaimsOf, type ClientLike, type LiveQueryHookOptions, type ProfileOf, SessionProvider, type SessionProviderProps, useAuth, useBroadcast, useLiveQuery, useSupabase };
|
package/dist/react/server.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { i as useBroadcast, o as useLiveQuery, r as useAuth, s as useSupabase, t as BetterSupabaseProvider } from "../react-
|
|
1
|
+
import { i as useBroadcast, o as useLiveQuery, r as useAuth, s as useSupabase, t as BetterSupabaseProvider } from "../react-CQHMaESR.js";
|
|
2
2
|
import { SessionProvider } from "./session.js";
|
|
3
3
|
//#region src/react/server.ts
|
|
4
4
|
function clientOnly(name) {
|
|
5
5
|
return () => {
|
|
6
|
-
throw new Error(`better-supabase: ${name}() runs in Client Components only. In Server Components use \`
|
|
6
|
+
throw new Error(`better-supabase: ${name}() runs in Client Components only. In Server Components use \`bs.context()\` or \`db.$run(spec)\`.`);
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
/** The `react-server` build of `useSession`: await `
|
|
9
|
+
/** The `react-server` build of `useSession`: await `bs.session()` instead. */
|
|
10
10
|
const useSession = clientOnly("useSession");
|
|
11
11
|
/**
|
|
12
12
|
* The `react-server` build of `createHooks`: importing a module that creates
|
package/dist/react/session.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as AuthSession } from "../view-
|
|
1
|
+
import { t as AuthSession } from "../view-B64o81wp.js";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
//#region src/react/session.d.ts
|
|
4
4
|
export interface SessionProviderProps {
|
|
5
5
|
/**
|
|
6
|
-
* An unresolved `
|
|
6
|
+
* An unresolved `bs.session()` promise, created inside a `<Suspense>`
|
|
7
7
|
* boundary so the layout itself never waits for auth.
|
|
8
8
|
*/
|
|
9
9
|
readonly sessionPromise: Promise<AuthSession>;
|
|
@@ -14,8 +14,8 @@ export declare function SessionProvider(props: SessionProviderProps): ReactNode;
|
|
|
14
14
|
/**
|
|
15
15
|
* The session from the nearest `<SessionProvider>`. Suspends until the
|
|
16
16
|
* promise resolves, so render it inside `<Suspense>`. `C` types the claims
|
|
17
|
-
* (the output of `
|
|
18
|
-
* `
|
|
17
|
+
* (the output of `betterSupabase.claims(schema)`) and `P` the profile (the output of
|
|
18
|
+
* `betterSupabase.userMetadata(schema)`); `createHooks().useSession` infers both.
|
|
19
19
|
*/
|
|
20
20
|
export declare function useSession<C = unknown, P = unknown>(): AuthSession<C, P>;
|
|
21
21
|
//#endregion
|
package/dist/react/session.js
CHANGED
|
@@ -9,8 +9,8 @@ function SessionProvider(props) {
|
|
|
9
9
|
/**
|
|
10
10
|
* The session from the nearest `<SessionProvider>`. Suspends until the
|
|
11
11
|
* promise resolves, so render it inside `<Suspense>`. `C` types the claims
|
|
12
|
-
* (the output of `
|
|
13
|
-
* `
|
|
12
|
+
* (the output of `betterSupabase.claims(schema)`) and `P` the profile (the output of
|
|
13
|
+
* `betterSupabase.userMetadata(schema)`); `createHooks().useSession` infers both.
|
|
14
14
|
*/
|
|
15
15
|
function useSession() {
|
|
16
16
|
const promise = useContext(SessionContext);
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { i as tenantClaimPaths, n as claimAt, r as claimsOf } from "./claims-
|
|
2
|
-
import { t as invalidateTables } from "./invalidate-
|
|
3
|
-
import { n as liveQuery, t as liveCount } from "./live-
|
|
1
|
+
import { i as tenantClaimPaths, n as claimAt, r as claimsOf } from "./claims-BAf6c7is.js";
|
|
2
|
+
import { t as invalidateTables } from "./invalidate-CgxmRamI.js";
|
|
3
|
+
import { n as liveQuery, t as liveCount } from "./live-CdJBOc4f.js";
|
|
4
4
|
import { useSession } from "./react/session.js";
|
|
5
5
|
import { createContext, createElement, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
6
6
|
//#region src/react/hooks.ts
|
|
7
|
-
const
|
|
7
|
+
const ClientContext = createContext(null);
|
|
8
8
|
const LOADING = {
|
|
9
9
|
status: "loading",
|
|
10
10
|
user: null,
|
|
11
11
|
claims: null
|
|
12
12
|
};
|
|
13
|
-
/** Provides the
|
|
13
|
+
/** Provides the better-supabase client to the hooks. */
|
|
14
14
|
function BetterSupabaseProvider(props) {
|
|
15
|
-
const {
|
|
15
|
+
const { client, queryClient } = props;
|
|
16
16
|
const user = useRef(void 0);
|
|
17
|
-
useEffect(() =>
|
|
18
|
-
const snapshot =
|
|
17
|
+
useEffect(() => client.auth.subscribe(() => {
|
|
18
|
+
const snapshot = client.auth.current();
|
|
19
19
|
if (snapshot.status === "loading") return;
|
|
20
20
|
const id = snapshot.user?.id ?? null;
|
|
21
21
|
if (user.current !== void 0 && user.current !== id) queryClient?.removeQueries({ queryKey: ["bs"] });
|
|
22
22
|
user.current = id;
|
|
23
|
-
}), [
|
|
23
|
+
}), [client, queryClient]);
|
|
24
24
|
const value = useMemo(() => ({
|
|
25
|
-
|
|
25
|
+
client,
|
|
26
26
|
queryClient
|
|
27
|
-
}), [
|
|
28
|
-
return createElement(
|
|
27
|
+
}), [client, queryClient]);
|
|
28
|
+
return createElement(ClientContext.Provider, { value }, props.children);
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
const value = useContext(
|
|
32
|
-
if (!value) throw new Error("better-supabase: wrap your app in <BetterSupabaseProvider
|
|
30
|
+
function useClientContext() {
|
|
31
|
+
const value = useContext(ClientContext);
|
|
32
|
+
if (!value) throw new Error("better-supabase: wrap your app in <BetterSupabaseProvider client={bs}>");
|
|
33
33
|
return value;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
return
|
|
35
|
+
function useClient() {
|
|
36
|
+
return useClientContext().client;
|
|
37
37
|
}
|
|
38
38
|
/** The session state for UI: `loading`, `signed-out` or `signed-in` with the user and claims. */
|
|
39
39
|
function useAuth() {
|
|
40
|
-
const
|
|
41
|
-
return useSyncExternalStore(
|
|
40
|
+
const client = useClient();
|
|
41
|
+
return useSyncExternalStore(client.auth.subscribe, client.auth.current, () => LOADING);
|
|
42
42
|
}
|
|
43
43
|
function useSupabase() {
|
|
44
|
-
return
|
|
44
|
+
return useClient().supabase;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Hooks typed for your schema.
|
|
48
48
|
*
|
|
49
49
|
* ```ts
|
|
50
|
-
* export const { useDb, useQueries, useAuth } = createHooks<typeof
|
|
50
|
+
* export const { useDb, useQueries, useAuth } = createHooks<typeof bs>();
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
function createHooks() {
|
|
54
54
|
return {
|
|
55
55
|
useDb() {
|
|
56
|
-
const
|
|
56
|
+
const client = useClient();
|
|
57
57
|
useAuth();
|
|
58
|
-
return
|
|
58
|
+
return client.db;
|
|
59
59
|
},
|
|
60
60
|
useQueries() {
|
|
61
|
-
const
|
|
61
|
+
const client = useClient();
|
|
62
62
|
useAuth();
|
|
63
|
-
return
|
|
63
|
+
return client.queries;
|
|
64
64
|
},
|
|
65
65
|
useSupabase,
|
|
66
66
|
useAuth,
|
|
@@ -76,7 +76,7 @@ function createHooks() {
|
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
78
78
|
function useBroadcast(topic, values, handlers, options) {
|
|
79
|
-
const {
|
|
79
|
+
const { client, queryClient } = useClientContext();
|
|
80
80
|
const auth = useAuth();
|
|
81
81
|
const [status, setStatus] = useState("closed");
|
|
82
82
|
const latest = useRef({
|
|
@@ -106,7 +106,7 @@ function useBroadcast(topic, values, handlers, options) {
|
|
|
106
106
|
}
|
|
107
107
|
for (const queryKey of invalidate(message)) queryClient.invalidateQueries({ queryKey });
|
|
108
108
|
};
|
|
109
|
-
const subscription = topic.subscribe(
|
|
109
|
+
const subscription = topic.subscribe(client.supabase, matched, { "*": forward }, {
|
|
110
110
|
...latest.current.options?.self === void 0 ? {} : { self: latest.current.options.self },
|
|
111
111
|
onStatus: setStatus,
|
|
112
112
|
onInvalid: (message, issues) => latest.current.options?.onInvalid?.(message, issues)
|
|
@@ -116,7 +116,7 @@ function useBroadcast(topic, values, handlers, options) {
|
|
|
116
116
|
setStatus("closed");
|
|
117
117
|
};
|
|
118
118
|
}, [
|
|
119
|
-
|
|
119
|
+
client,
|
|
120
120
|
topic,
|
|
121
121
|
name,
|
|
122
122
|
userId,
|
|
@@ -138,23 +138,23 @@ function claimedTenant(auth, meta) {
|
|
|
138
138
|
* resubscribes when the spec, tenant or user changes.
|
|
139
139
|
*
|
|
140
140
|
* ```ts
|
|
141
|
-
* const spec =
|
|
141
|
+
* const spec = betterSupabase.spec.customers.findMany({ include: { notes: true } });
|
|
142
142
|
* const { data } = useQuery(q.$spec(spec));
|
|
143
143
|
* useLiveQuery(spec);
|
|
144
144
|
* ```
|
|
145
145
|
*/
|
|
146
146
|
function useLiveQuery(spec, options = {}) {
|
|
147
|
-
const {
|
|
147
|
+
const { client, queryClient } = useClientContext();
|
|
148
148
|
const auth = useAuth();
|
|
149
149
|
const [status, setStatus] = useState("closed");
|
|
150
150
|
if (spec && !queryClient) throw new Error("better-supabase: useLiveQuery needs <BetterSupabaseProvider queryClient={...}>");
|
|
151
151
|
const key = spec ? JSON.stringify(spec) : null;
|
|
152
|
-
const tenant = options.tenant ?? claimedTenant(auth,
|
|
152
|
+
const tenant = options.tenant ?? claimedTenant(auth, client.betterSupabase.meta);
|
|
153
153
|
const userId = auth.user?.id ?? null;
|
|
154
154
|
const debounceMs = options.debounceMs;
|
|
155
155
|
useEffect(() => {
|
|
156
156
|
if (!key || !queryClient || auth.status === "loading") return;
|
|
157
|
-
const live = liveQuery(
|
|
157
|
+
const live = liveQuery(client.betterSupabase, client.supabase, JSON.parse(key), {
|
|
158
158
|
onChange: (tables) => void invalidateTables(queryClient, tables),
|
|
159
159
|
onStatus: setStatus,
|
|
160
160
|
...tenant === void 0 ? {} : { tenant },
|
|
@@ -164,7 +164,7 @@ function useLiveQuery(spec, options = {}) {
|
|
|
164
164
|
live.unsubscribe();
|
|
165
165
|
};
|
|
166
166
|
}, [
|
|
167
|
-
|
|
167
|
+
client,
|
|
168
168
|
queryClient,
|
|
169
169
|
key,
|
|
170
170
|
tenant,
|
|
@@ -177,15 +177,15 @@ function useLiveQuery(spec, options = {}) {
|
|
|
177
177
|
/**
|
|
178
178
|
* A count that stays current: refetches only the `count` spec (a HEAD
|
|
179
179
|
* request) after each debounced change to a table it reads, and after the
|
|
180
|
-
* channel rejoins. Takes a spec or a `
|
|
180
|
+
* channel rejoins. Takes a spec or a `bs.liveCount()` seed; pass `null` to
|
|
181
181
|
* pause. Doesn't need a `QueryClient`.
|
|
182
182
|
*
|
|
183
183
|
* ```tsx
|
|
184
|
-
* const { count } = useLiveCount(seed); // seed = await
|
|
184
|
+
* const { count } = useLiveCount(seed); // seed = await bs.liveCount(spec)
|
|
185
185
|
* ```
|
|
186
186
|
*/
|
|
187
187
|
function useLiveCount(source, options = {}) {
|
|
188
|
-
const {
|
|
188
|
+
const { client } = useClientContext();
|
|
189
189
|
const auth = useAuth();
|
|
190
190
|
const seed = source && "spec" in source ? source : void 0;
|
|
191
191
|
const spec = seed ? seed.spec : source;
|
|
@@ -197,13 +197,13 @@ function useLiveCount(source, options = {}) {
|
|
|
197
197
|
});
|
|
198
198
|
const [status, setStatus] = useState("closed");
|
|
199
199
|
const key = spec ? JSON.stringify(spec) : null;
|
|
200
|
-
const tenant = options.tenant ?? claimedTenant(auth,
|
|
200
|
+
const tenant = options.tenant ?? claimedTenant(auth, client.betterSupabase.meta);
|
|
201
201
|
const userId = auth.user?.id ?? null;
|
|
202
202
|
const debounceMs = options.debounceMs;
|
|
203
203
|
const hasInitial = initial !== void 0;
|
|
204
204
|
useEffect(() => {
|
|
205
205
|
if (!key || auth.status === "loading") return;
|
|
206
|
-
const live = liveCount(
|
|
206
|
+
const live = liveCount(client.betterSupabase, client.supabase, client.db, JSON.parse(key), {
|
|
207
207
|
immediate: !hasInitial,
|
|
208
208
|
onCount: (count) => {
|
|
209
209
|
setState({
|
|
@@ -227,7 +227,7 @@ function useLiveCount(source, options = {}) {
|
|
|
227
227
|
live.unsubscribe();
|
|
228
228
|
};
|
|
229
229
|
}, [
|
|
230
|
-
|
|
230
|
+
client,
|
|
231
231
|
key,
|
|
232
232
|
tenant,
|
|
233
233
|
userId,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as
|
|
2
|
-
import { n as touchedTables } from "./tables-
|
|
1
|
+
import { r as builderFor, u as tableMeta } from "./simplify-Cqvfr9dj.js";
|
|
2
|
+
import { n as touchedTables } from "./tables-Cb-3_VWc.js";
|
|
3
3
|
//#region src/core/spec.ts
|
|
4
4
|
const READ_METHODS = [
|
|
5
5
|
"findMany",
|
|
@@ -40,7 +40,6 @@ function specOptions(spec) {
|
|
|
40
40
|
const value = spec.method === "findById" ? spec.args[1] : spec.args[0];
|
|
41
41
|
return typeof value === "object" && value !== null ? value : void 0;
|
|
42
42
|
}
|
|
43
|
-
const builders = /* @__PURE__ */ new WeakMap();
|
|
44
43
|
/**
|
|
45
44
|
* App keys of every table a spec reads: its table, included relations and
|
|
46
45
|
* relations used in `where`. Queries keyed by a spec go stale when any of
|
|
@@ -48,18 +47,54 @@ const builders = /* @__PURE__ */ new WeakMap();
|
|
|
48
47
|
* spec reports the error.
|
|
49
48
|
*/
|
|
50
49
|
function specTables(meta, spec) {
|
|
50
|
+
const table = meta.tables[spec.table];
|
|
51
|
+
const args = specOptions(spec);
|
|
52
|
+
if (table && args?.["include"] === void 0 && !touchesRelations(table, args?.["where"])) return [spec.table];
|
|
53
|
+
const key = specKey(spec);
|
|
54
|
+
let byKey = tablesByMeta.get(meta);
|
|
55
|
+
if (!byKey) {
|
|
56
|
+
byKey = /* @__PURE__ */ new Map();
|
|
57
|
+
tablesByMeta.set(meta, byKey);
|
|
58
|
+
}
|
|
59
|
+
const known = key === void 0 ? void 0 : byKey.get(key);
|
|
60
|
+
if (known) return [...known];
|
|
61
|
+
let tables;
|
|
51
62
|
try {
|
|
52
|
-
|
|
63
|
+
tables = readTables(meta, spec);
|
|
53
64
|
} catch {
|
|
54
|
-
|
|
65
|
+
tables = [spec.table];
|
|
66
|
+
}
|
|
67
|
+
if (key !== void 0) {
|
|
68
|
+
if (byKey.size >= SPEC_CACHE_SIZE) byKey.clear();
|
|
69
|
+
byKey.set(key, tables);
|
|
55
70
|
}
|
|
71
|
+
return [...tables];
|
|
56
72
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
const SPEC_CACHE_SIZE = 500;
|
|
74
|
+
const tablesByMeta = /* @__PURE__ */ new WeakMap();
|
|
75
|
+
/** A text key for the spec, or `undefined` when its arguments do not serialize. */
|
|
76
|
+
function specKey(spec) {
|
|
77
|
+
try {
|
|
78
|
+
return JSON.stringify([
|
|
79
|
+
spec.table,
|
|
80
|
+
spec.method,
|
|
81
|
+
spec.args
|
|
82
|
+
], (_key, value) => typeof value === "bigint" ? `${value}n` : value);
|
|
83
|
+
} catch {
|
|
84
|
+
return;
|
|
62
85
|
}
|
|
86
|
+
}
|
|
87
|
+
function touchesRelations(table, where) {
|
|
88
|
+
if (typeof where !== "object" || where === null) return false;
|
|
89
|
+
if (Array.isArray(where)) return where.some((item) => touchesRelations(table, item));
|
|
90
|
+
for (const [key, value] of Object.entries(where)) {
|
|
91
|
+
if (key in table.relations) return true;
|
|
92
|
+
if ((key === "AND" || key === "OR" || key === "NOT") && touchesRelations(table, value)) return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
function readTables(meta, spec) {
|
|
97
|
+
const builder = builderFor(meta);
|
|
63
98
|
const table = tableMeta(meta, spec.table);
|
|
64
99
|
const args = specOptions(spec);
|
|
65
100
|
const counts = spec.method === "count" || spec.method === "exists" || spec.method === "aggregate";
|
|
@@ -98,7 +133,7 @@ function sentinel(name) {
|
|
|
98
133
|
*
|
|
99
134
|
* ```ts
|
|
100
135
|
* export const appChrome = defineReadSet(
|
|
101
|
-
*
|
|
136
|
+
* betterSupabase,
|
|
102
137
|
* 'app_chrome',
|
|
103
138
|
* { params: { userId: 'uuid' } },
|
|
104
139
|
* (s, p) => ({
|
|
@@ -111,7 +146,7 @@ function sentinel(name) {
|
|
|
111
146
|
* `p` holds placeholders, not values: pass them straight into `where` (or
|
|
112
147
|
* `in`), where the function reads them from its `p jsonb` argument.
|
|
113
148
|
*/
|
|
114
|
-
function defineReadSet(
|
|
149
|
+
function defineReadSet(betterSupabase, name, options, build) {
|
|
115
150
|
if (!NAME.test(name)) throw new TypeError(`better-supabase: read set name "${name}" must be snake_case and at most 60 characters`);
|
|
116
151
|
const params = options.params ?? {};
|
|
117
152
|
const placeholders = {};
|
|
@@ -120,10 +155,10 @@ function defineReadSet(sb, name, options, build) {
|
|
|
120
155
|
if (!TYPE.test(type)) throw new TypeError(`better-supabase: read set "${name}" parameter "${key}" has an invalid type "${type}"`);
|
|
121
156
|
placeholders[key] = type.endsWith("[]") ? [sentinel(key)] : sentinel(key);
|
|
122
157
|
}
|
|
123
|
-
const specs = build(
|
|
158
|
+
const specs = build(betterSupabase.spec, placeholders);
|
|
124
159
|
const entries = Object.entries(specs);
|
|
125
160
|
if (entries.length === 0 || entries.length > MAX_ENTRIES) throw new TypeError(`better-supabase: read set "${name}" needs between 1 and ${MAX_ENTRIES} reads`);
|
|
126
|
-
for (const [key, spec] of entries) if (!isQuerySpec(spec)) throw new TypeError(`better-supabase: read set "${name}" entry "${key}" is not a spec from
|
|
161
|
+
for (const [key, spec] of entries) if (!isQuerySpec(spec)) throw new TypeError(`better-supabase: read set "${name}" entry "${key}" is not a spec from betterSupabase.spec`);
|
|
127
162
|
return {
|
|
128
163
|
kind: "read-set",
|
|
129
164
|
name,
|
|
@@ -131,7 +166,7 @@ function defineReadSet(sb, name, options, build) {
|
|
|
131
166
|
params,
|
|
132
167
|
roles: options.roles ?? ["authenticated"],
|
|
133
168
|
specs,
|
|
134
|
-
definition:
|
|
169
|
+
definition: betterSupabase
|
|
135
170
|
};
|
|
136
171
|
}
|
|
137
172
|
function isReadSet(value) {
|
package/dist/realtime/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { x as PermdockTopicPolicy } from "../types-DONv9SHN.js";
|
|
2
2
|
import { t as PermdockCatalog } from "../permdock-sql-DImJULY-.js";
|
|
3
3
|
import { n as TemplateValues, t as TemplateParams } from "../template-mbvlysOo.js";
|
|
4
|
-
import { C as defineTopic, S as TriggerOptions, _ as TopicEvent, a as LiveSource, b as TopicOptions, c as liveQuery, d as RealtimeClient, f as RowChange, g as Topic, h as SubscriptionStatus, i as LiveQueryOptions, l as liveTopic, m as Subscription, n as LiveCountOptions, o as LiveSubscription, p as SubscribeOptions, r as LiveCountSeed, s as liveCount, t as CountRunner, u as EventSchemas, v as TopicHandlers, w as rowChange, x as TopicPayload, y as TopicMessage } from "../live-
|
|
4
|
+
import { C as defineTopic, S as TriggerOptions, _ as TopicEvent, a as LiveSource, b as TopicOptions, c as liveQuery, d as RealtimeClient, f as RowChange, g as Topic, h as SubscriptionStatus, i as LiveQueryOptions, l as liveTopic, m as Subscription, n as LiveCountOptions, o as LiveSubscription, p as SubscribeOptions, r as LiveCountSeed, s as liveCount, t as CountRunner, u as EventSchemas, v as TopicHandlers, w as rowChange, x as TopicPayload, y as TopicMessage } from "../live-BHakSWWo.js";
|
|
5
5
|
export { type CountRunner, type EventSchemas, type LiveCountOptions, type LiveCountSeed, type LiveQueryOptions, type LiveSource, type LiveSubscription, type PermdockCatalog, type PermdockTopicPolicy, type RealtimeClient, type RowChange, type SubscribeOptions, type Subscription, type SubscriptionStatus, type TemplateParams, type TemplateValues, type Topic, type TopicEvent, type TopicHandlers, type TopicMessage, type TopicOptions, type TopicPayload, type TriggerOptions, defineTopic, liveCount, liveQuery, liveTopic, rowChange };
|