better-supabase 0.2.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 +37 -33
- package/dist/base64-D2gsioCY.js +42 -0
- package/dist/claims-BAf6c7is.js +48 -0
- package/dist/cli/_format-Cax5EsM9.js +101 -0
- package/dist/cli/bin.js +39 -6
- 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 +295 -28
- package/dist/cli/index.js +184 -3
- 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/{version-Cqq1m3UY.js → cli/version-5mW_8sY1.js} +1 -1
- package/dist/cli/yaml-CYCbJ6et.js +2252 -0
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +15 -25
- package/dist/{compiler-CZ9nIuqy.d.ts → compiler-DB3aSFOA.d.ts} +2 -2
- package/dist/config/index.d.ts +4 -3
- package/dist/config/index.js +5 -3
- package/dist/config-BpxDfnbg.js +129 -0
- package/dist/{index-DOsjFvMf.d.ts → config-C1CYcm6o.d.ts} +49 -49
- package/dist/{config-ClDXmVtY.js → config-CbvFmGD8.js} +14 -137
- package/dist/{define-BXMYD9AY.js → define-Bh0AqTik.js} +221 -120
- package/dist/{define-e3zI4_4g.d.ts → define-CRS2MRV3.d.ts} +36 -31
- package/dist/edge/index.d.ts +9 -13
- package/dist/edge/index.js +51 -25
- package/dist/{entitlements-Dng-ctuT.d.ts → entitlements-Dm-FHpNH.d.ts} +2 -2
- package/dist/env/index.js +203 -1
- package/dist/{errors-Bl3rkOzo.js → errors-L0xK41y_.js} +1 -1
- package/dist/events/index.d.ts +1 -1
- package/dist/events/index.js +139 -1
- package/dist/{events-DOt3nSO-.d.ts → events-B21UOhvP.d.ts} +4 -4
- package/dist/{executor-CGdNQ27g.d.ts → executor-B5IoUxLE.d.ts} +2 -2
- package/dist/{executor-DeppvirK.js → executor-CVt6dD0B.js} +9 -4
- package/dist/{executor-BYXQ9AGn.d.ts → executor-CZ7ImRiD.d.ts} +2 -2
- package/dist/hono/index.d.ts +17 -24
- package/dist/hono/index.js +11 -11
- package/dist/{index-DuP14VHo.d.ts → index-528Ugmyp.d.ts} +30 -10
- package/dist/{index-Bw1bwtC0.d.ts → index-BAy4tsAP.d.ts} +28 -15
- package/dist/{index-CBDufH1M.d.ts → index-BBdvo-5d.d.ts} +24 -26
- package/dist/{index-DbxFr7XG.d.ts → index-BhHEC04r.d.ts} +9 -4
- package/dist/index-Cf-D2jk1.d.ts +50 -0
- package/dist/{index-Ciu5Xlml.d.ts → index-D5IfUIDh.d.ts} +6 -5
- package/dist/{index-K-3WM2Hp.d.ts → index-DFmOpBGC.d.ts} +13 -13
- package/dist/{index-D4v7sncu.d.ts → index-RlLXd8dL.d.ts} +13 -13
- package/dist/index.d.ts +17 -17
- package/dist/index.js +23 -14
- package/dist/{invalidate-DbxuL2jL.js → invalidate-CgxmRamI.js} +7 -1
- package/dist/jobs/index.d.ts +33 -26
- package/dist/jobs/index.js +44 -22
- package/dist/{json-schema-BpYqkCKf.js → json-schema-DP6V7cbr.js} +8 -3
- package/dist/lint/index.js +1 -1
- package/dist/list/index.d.ts +2 -2
- package/dist/list/index.js +131 -96
- package/dist/{live-DJyZMD6w.d.ts → live-BHakSWWo.d.ts} +26 -16
- package/dist/{live-D8rV1Ldw.js → live-CdJBOc4f.js} +13 -9
- package/dist/lookup-BaP5bI27.js +18 -0
- package/dist/mcp/index.d.ts +34 -27
- package/dist/mcp/index.js +59 -25
- package/dist/{mfa-TVia554c.d.ts → mfa-C7MNQ1Ob.d.ts} +1 -1
- package/dist/{mfa-CpLfJSde.js → mfa-byfjruR9.js} +190 -46
- package/dist/next/image/index.js +6 -3
- package/dist/next/index.d.ts +64 -48
- package/dist/next/index.js +63 -50
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +61 -38
- package/dist/orpc/index.d.ts +18 -21
- package/dist/orpc/index.js +12 -12
- package/dist/otel/index.d.ts +5 -5
- package/dist/otel/index.js +84 -63
- package/dist/{permdock-sql-CghlHPuH.js → permdock-sql-C4KFzLc9.js} +12 -7
- package/dist/permdock-sql-DImJULY-.d.ts +17 -0
- package/dist/{plugin-C4TR9J0Z.d.ts → plugin-bNhvJwRh.d.ts} +5 -4
- 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 +46 -16
- package/dist/plugins/soft-delete/index.d.ts +3 -3
- package/dist/plugins/soft-delete/index.js +4 -4
- package/dist/plugins/tenant/index.d.ts +3 -3
- package/dist/plugins/tenant/index.js +10 -4
- package/dist/plugins/timestamps/index.d.ts +1 -1
- package/dist/plugins/timestamps/index.js +2 -2
- package/dist/plugins/validation/index.d.ts +2 -2
- package/dist/plugins/validation/index.js +3 -3
- package/dist/pool-DFwEQwmN.d.ts +78 -0
- package/dist/postgres/index.d.ts +10 -5
- package/dist/postgres/index.js +37 -16
- package/dist/{postgrest-cAEQ_IQN.d.ts → postgrest-Bc-0Xw62.d.ts} +1 -1
- package/dist/{problem-BTkTtRV9.js → problem-BihjPR0t.js} +11 -5
- package/dist/{problem-DlgB0lYl.d.ts → problem-U8UEKccv.d.ts} +6 -4
- package/dist/query/index.d.ts +2 -2
- package/dist/query/index.js +2 -2
- package/dist/{query-ChvDbsDE.js → query-BMMSWbI7.js} +19 -19
- package/dist/react/index.d.ts +7 -7
- package/dist/react/index.js +2 -2
- package/dist/react/server.d.ts +6 -6
- package/dist/react/server.js +3 -3
- package/dist/react/session.d.ts +21 -2
- package/dist/react/session.js +19 -1
- package/dist/{react-C83BdBGt.js → react-CQHMaESR.js} +59 -55
- package/dist/{read-set-4lI3W_gZ.js → read-set-FWK8qQ58.js} +51 -16
- package/dist/realtime/index.d.ts +4 -3
- package/dist/realtime/index.js +19 -17
- package/dist/{index-CG69s15v.d.ts → refresh-BwYkyNOQ.d.ts} +7 -3
- package/dist/{resolve-CjHILk2w.d.ts → resolve-BAqQcwMW.d.ts} +17 -11
- package/dist/{resource-CgZa3YG_.d.ts → resource-BJcaIfxi.d.ts} +17 -8
- package/dist/{resource-BHEWmQJK.js → resource-My_y-Syh.js} +43 -21
- package/dist/{respond-Dne1ARSa.d.ts → respond-DgIbdrt8.d.ts} +39 -14
- package/dist/{result-DWXatkd6.js → result-Bj6yt33D.js} +2 -2
- package/dist/{result-CTkCZ6JA.d.ts → result-CqEsbgYs.d.ts} +16 -11
- package/dist/server/index.d.ts +38 -13
- package/dist/server/index.js +43 -14
- package/dist/{respond-DMcbQwfN.js → server-BA75B0mT.js} +151 -96
- package/dist/{shared-_6-uPL7E.js → shared-DnoCdMDr.js} +4 -3
- package/dist/{simplify-bwJpLnaS.js → simplify-Cqvfr9dj.js} +76 -39
- package/dist/sql/index.d.ts +139 -0
- package/dist/sql/index.js +1983 -0
- package/dist/{sql-DTjA1LPj.js → sql-B34HU2DI.js} +74 -17
- 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-CyhRzctb.d.ts → standard-BsaCYQJc.d.ts} +1 -1
- package/dist/{stats-C5W-rBfR.js → stats-C_YxA2r1.js} +40 -14
- package/dist/storage/index.d.ts +4 -3
- package/dist/storage/index.js +548 -1
- package/dist/{tables-rZxRxNPW.js → tables-Cb-3_VWc.js} +19 -5
- package/dist/temporal-BwshQk0W.js +27 -0
- package/dist/temporal-required-CBNHT6ni.js +19 -0
- package/dist/testing/index.d.ts +25 -24
- package/dist/testing/index.js +165 -66
- package/dist/{types-C83v5SQz.d.ts → types-DONv9SHN.d.ts} +14 -11
- package/dist/version-Bmf7_FzM.js +4 -0
- package/dist/{view-D1s0wa0T.d.ts → view-B64o81wp.d.ts} +36 -6
- package/dist/{view-aOYizTeE.js → view-BrJI2LKp.js} +11 -2
- package/dist/webhooks/index.d.ts +19 -17
- package/dist/webhooks/index.js +1 -1
- package/dist/{webhooks-DMipjhSP.js → webhooks-Bh_Jf_-l.js} +45 -24
- package/package.json +50 -22
- package/schemas/config-v1.json +31 -1
- package/schemas/doctor-report-v1.json +17 -1
- package/schemas/snapshot-v2.json +35 -0
- package/skills/better-supabase/SKILL.md +77 -18
- package/skills/better-supabase/references/plugins.md +21 -22
- package/skills/better-supabase/references/troubleshooting.md +38 -18
- package/skills/better-supabase-api/SKILL.md +66 -18
- package/skills/better-supabase-api/references/adapters.md +64 -41
- 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 +68 -11
- package/dist/casing-da0uRTqt.js +0 -14
- package/dist/claims-CoTobNC-.js +0 -25
- package/dist/cli-DrSgDOQC.js +0 -6646
- package/dist/env-BEToab0I.js +0 -204
- package/dist/events-BuzTgn2D.js +0 -135
- package/dist/pool-R2m_DkXi.d.ts +0 -37
- package/dist/seed-CzecODcJ.js +0 -101
- package/dist/session-C3LxnQ0e.d.ts +0 -22
- package/dist/session-CqEwzVup.js +0 -20
- package/dist/storage-DuGn38fr.js +0 -527
package/dist/client/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { AuthSnapshot, AuthUser,
|
|
1
|
+
import { a as ClientOptions, i as ClientAuth, n as AuthUser, o as createClient, r as BetterClient, t as AuthSnapshot } from "../index-RlLXd8dL.js";
|
|
2
|
+
export { AuthSnapshot, AuthUser, BetterClient, ClientAuth, ClientOptions, createClient };
|
package/dist/client/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { n as decodeJwtPayload } from "../base64-D2gsioCY.js";
|
|
2
|
+
import { EnvValidationError, parseEnv } from "../env/index.js";
|
|
3
|
+
import { t as createQueries } from "../query-BMMSWbI7.js";
|
|
3
4
|
import { createBrowserClient } from "@supabase/ssr";
|
|
4
|
-
import { createClient } from "@supabase/supabase-js";
|
|
5
|
+
import { createClient as createClient$1 } from "@supabase/supabase-js";
|
|
5
6
|
//#region src/client/index.ts
|
|
6
7
|
const LOADING = {
|
|
7
8
|
status: "loading",
|
|
@@ -13,20 +14,9 @@ const SIGNED_OUT = {
|
|
|
13
14
|
user: null,
|
|
14
15
|
claims: null
|
|
15
16
|
};
|
|
16
|
-
function decodeClaims(token) {
|
|
17
|
-
const part = token.split(".")[1];
|
|
18
|
-
if (!part) return {};
|
|
19
|
-
try {
|
|
20
|
-
const bytes = Uint8Array.from(atob(part.replace(/-/g, "+").replace(/_/g, "/")), (char) => char.charCodeAt(0));
|
|
21
|
-
const parsed = JSON.parse(new TextDecoder().decode(bytes));
|
|
22
|
-
return typeof parsed === "object" && parsed !== null ? parsed : {};
|
|
23
|
-
} catch {
|
|
24
|
-
return {};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
17
|
function snapshotOf(session) {
|
|
28
18
|
if (!session) return SIGNED_OUT;
|
|
29
|
-
const claims =
|
|
19
|
+
const claims = decodeJwtPayload(session.access_token) ?? {};
|
|
30
20
|
const role = typeof claims["role"] === "string" ? claims["role"] : session.user.role;
|
|
31
21
|
return {
|
|
32
22
|
status: "signed-in",
|
|
@@ -59,13 +49,13 @@ function contextOf(snapshot) {
|
|
|
59
49
|
}
|
|
60
50
|
function clientFor(options) {
|
|
61
51
|
if (options.client) return options.client;
|
|
62
|
-
if (!options.env) throw new TypeError("
|
|
52
|
+
if (!options.env) throw new TypeError("createClient needs `env` ({ url, publishableKey }) or `client`");
|
|
63
53
|
const checked = parseEnv({
|
|
64
54
|
SUPABASE_URL: options.env.url,
|
|
65
55
|
SUPABASE_PUBLISHABLE_KEY: options.env.publishableKey
|
|
66
56
|
});
|
|
67
57
|
if (!checked.ok) throw new EnvValidationError(checked.issues);
|
|
68
|
-
if (options.storage === "local") return createClient(checked.env.url, checked.env.publishableKey);
|
|
58
|
+
if (options.storage === "local") return createClient$1(checked.env.url, checked.env.publishableKey);
|
|
69
59
|
return createBrowserClient(checked.env.url, checked.env.publishableKey);
|
|
70
60
|
}
|
|
71
61
|
/**
|
|
@@ -73,10 +63,10 @@ function clientFor(options) {
|
|
|
73
63
|
* session, TanStack Query options and an auth store for UI state.
|
|
74
64
|
*
|
|
75
65
|
* ```ts
|
|
76
|
-
* export const
|
|
66
|
+
* export const bs = createClient(betterSupabase, { env: { url, publishableKey } });
|
|
77
67
|
* ```
|
|
78
68
|
*/
|
|
79
|
-
function
|
|
69
|
+
function createClient(betterSupabase, options = {}) {
|
|
80
70
|
const supabase = clientFor(options);
|
|
81
71
|
let snapshot = LOADING;
|
|
82
72
|
let db;
|
|
@@ -88,14 +78,14 @@ function createBrowser(sb, options = {}) {
|
|
|
88
78
|
db = void 0;
|
|
89
79
|
for (const listener of listeners) listener();
|
|
90
80
|
});
|
|
91
|
-
const
|
|
92
|
-
|
|
81
|
+
const client = {
|
|
82
|
+
betterSupabase,
|
|
93
83
|
supabase,
|
|
94
84
|
get db() {
|
|
95
|
-
db ??=
|
|
85
|
+
db ??= betterSupabase.connect(supabase, contextOf(snapshot));
|
|
96
86
|
return db;
|
|
97
87
|
},
|
|
98
|
-
queries: createQueries(
|
|
88
|
+
queries: createQueries(betterSupabase, () => client.db),
|
|
99
89
|
auth: {
|
|
100
90
|
current: () => snapshot,
|
|
101
91
|
subscribe: (listener) => {
|
|
@@ -106,7 +96,7 @@ function createBrowser(sb, options = {}) {
|
|
|
106
96
|
}
|
|
107
97
|
}
|
|
108
98
|
};
|
|
109
|
-
return
|
|
99
|
+
return client;
|
|
110
100
|
}
|
|
111
101
|
//#endregion
|
|
112
|
-
export {
|
|
102
|
+
export { createClient };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as Operation } from "./executor-
|
|
2
|
-
import { i as PostgrestPlan } from "./postgrest-
|
|
1
|
+
import { g as Operation } from "./executor-B5IoUxLE.js";
|
|
2
|
+
import { i as PostgrestPlan } from "./postgrest-Bc-0Xw62.js";
|
|
3
3
|
//#region src/core/compiler.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Turns an IR operation into something a backend runs. An `Executor` for a
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
|
|
1
|
+
import { a as Casing } from "../types-DONv9SHN.js";
|
|
2
|
+
import { $ as GeneratorMetadata, A as VectorSearchConfig, B as CatalogFunction, C as SoftDeleteConfig, D as TenantConfig, E as TableConfig, F as CatalogCheck, G as CatalogTable, H as CatalogGrant, I as CatalogColumn, J as ExtrasFunction, K as CatalogTrigger, L as CatalogColumnGrant, M as resolveConfig, N as resolveJsonSchema, O as TimestampsConfig, P as Catalog, Q as ForeignKeyAction, R as CatalogEnum, S as SeedConfig, T as SqlConfig, U as CatalogIndex, V as CatalogFunctionArg, W as CatalogPolicy, X as ExtrasHookFunction, Y as ExtrasHook, Z as ExtrasTable, _ as PluginFlagsConfig, a as ClaimsConfig, b as ResolvedConfig, c as EntitlementsConfig, d as Generator, et as Snapshot, f as GeneratorInput, g as PermdockPathsConfig, h as OpenApiConfig, i as CONFIG_SCHEMA_URL, j as defineConfig, k as VectorDistance, l as ExposeConfig, m as JsonTypeConfig, n as BetterSupabaseConfig, nt as SnapshotExtras, o as CodecsConfig, p as JsonSchemaSource, q as CatalogUnique, r as BucketConfig, s as DoctorConfig, t as ActorConfig, tt as SnapshotBucket, u as GeneratedFile, v as Privilege, w as SourceConfig, x as ResolvedExpose, y as RealtimeConfig, z as CatalogForeignKey } from "../config-C1CYcm6o.js";
|
|
3
|
+
import { a as JsonSchemaGeneratorOptions, c as DEFAULT_CLAIMS, i as valibot, l as tenantClaimPaths, n as zod, o as buildJsonSchema, r as ValibotGeneratorOptions, s as jsonSchema, t as ZodGeneratorOptions } from "../index-Cf-D2jk1.js";
|
|
4
|
+
export { type ActorConfig, type BetterSupabaseConfig, type BucketConfig, CONFIG_SCHEMA_URL, type Casing, type Catalog, type CatalogCheck, type CatalogColumn, type CatalogColumnGrant, type CatalogEnum, type CatalogForeignKey, type CatalogFunction, type CatalogFunctionArg, type CatalogGrant, type CatalogIndex, type CatalogPolicy, type CatalogTable, type CatalogTrigger, type CatalogUnique, type ClaimsConfig, type CodecsConfig, DEFAULT_CLAIMS, type DoctorConfig, type EntitlementsConfig, type ExposeConfig, type ExtrasFunction, type ExtrasHook, type ExtrasHookFunction, type ExtrasTable, type ForeignKeyAction, type GeneratedFile, type Generator, type GeneratorInput, type GeneratorMetadata, type JsonSchemaGeneratorOptions, type JsonSchemaSource, type JsonTypeConfig, type OpenApiConfig, type PermdockPathsConfig, type PluginFlagsConfig, type Privilege, type RealtimeConfig, type ResolvedConfig, type ResolvedExpose, type SeedConfig, type Snapshot, type SnapshotBucket, type SnapshotExtras, type SoftDeleteConfig, type SourceConfig, type SqlConfig, type TableConfig, type TenantConfig, type TimestampsConfig, type ValibotGeneratorOptions, type VectorDistance, type VectorSearchConfig, type ZodGeneratorOptions, buildJsonSchema, defineConfig, jsonSchema, resolveConfig, resolveJsonSchema, tenantClaimPaths, valibot, zod };
|
package/dist/config/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { i as tenantClaimPaths, t as DEFAULT_CLAIMS } from "../claims-BAf6c7is.js";
|
|
2
|
+
import { i as resolveJsonSchema, n as defineConfig, r as resolveConfig, t as CONFIG_SCHEMA_URL } from "../config-BpxDfnbg.js";
|
|
3
|
+
import { n as jsonSchema, t as buildJsonSchema } from "../json-schema-DP6V7cbr.js";
|
|
4
|
+
import { n as valibot, t as zod } from "../config-CbvFmGD8.js";
|
|
5
|
+
export { CONFIG_SCHEMA_URL, DEFAULT_CLAIMS, buildJsonSchema, defineConfig, jsonSchema, resolveConfig, resolveJsonSchema, tenantClaimPaths, valibot, zod };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { t as DEFAULT_CLAIMS } from "./claims-BAf6c7is.js";
|
|
2
|
+
//#region src/config/config.ts
|
|
3
|
+
/** The JSON Schema document for a `json[...].schema` entry. */
|
|
4
|
+
function resolveJsonSchema(source) {
|
|
5
|
+
const standard = source["~standard"];
|
|
6
|
+
if (standard === void 0) return source;
|
|
7
|
+
const jsonSchema = standard.jsonSchema;
|
|
8
|
+
if (typeof jsonSchema?.input !== "function") throw new TypeError("json[...].schema: this Standard Schema library does not implement Standard JSON Schema; pass a JSON Schema object instead");
|
|
9
|
+
return jsonSchema.input({ target: "draft-2020-12" });
|
|
10
|
+
}
|
|
11
|
+
function entitlementsOf(config = {}) {
|
|
12
|
+
const customer = config.customer ?? "organizations.stripe_customer_id";
|
|
13
|
+
const dot = customer.lastIndexOf(".");
|
|
14
|
+
if (dot <= 0) throw new TypeError(`entitlements.customer must be "table.column", got "${customer}"`);
|
|
15
|
+
return {
|
|
16
|
+
table: customer.slice(0, dot),
|
|
17
|
+
column: customer.slice(dot + 1),
|
|
18
|
+
key: config.key ?? "id",
|
|
19
|
+
permdock: config.permdock === false ? false : { scope: config.permdock?.scope ?? "organization" }
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function vectorSearchOf(config = {}) {
|
|
23
|
+
return Object.entries(config).map(([table, entry]) => typeof entry === "string" ? {
|
|
24
|
+
table,
|
|
25
|
+
column: entry,
|
|
26
|
+
distance: "cosine"
|
|
27
|
+
} : {
|
|
28
|
+
table,
|
|
29
|
+
column: entry.column,
|
|
30
|
+
distance: entry.distance ?? "cosine"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const CONFIG_SCHEMA_URL = "https://unpkg.com/better-supabase/schemas/config-v1.json";
|
|
34
|
+
/** Identity helper that types `better-supabase.config.ts`. */
|
|
35
|
+
function defineConfig(config) {
|
|
36
|
+
return config;
|
|
37
|
+
}
|
|
38
|
+
function pick(value, defaults) {
|
|
39
|
+
if (value === void 0 || value === false) return void 0;
|
|
40
|
+
if (value === true) return defaults;
|
|
41
|
+
return {
|
|
42
|
+
...defaults,
|
|
43
|
+
...value
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function resolveExpose(entry) {
|
|
47
|
+
if (Array.isArray(entry)) return {
|
|
48
|
+
anon: [],
|
|
49
|
+
authenticated: entry
|
|
50
|
+
};
|
|
51
|
+
const roles = entry;
|
|
52
|
+
return {
|
|
53
|
+
anon: roles.anon ?? [],
|
|
54
|
+
authenticated: roles.authenticated ?? []
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Applies defaults. Paths stay relative to `root`. */
|
|
58
|
+
function resolveConfig(config, root) {
|
|
59
|
+
const output = config.output ?? "src/lib/supabase/generated.ts";
|
|
60
|
+
return {
|
|
61
|
+
root,
|
|
62
|
+
source: config.source ?? {},
|
|
63
|
+
schemas: config.schemas ?? ["public"],
|
|
64
|
+
casing: config.casing ?? "snake",
|
|
65
|
+
tables: config.tables ?? {},
|
|
66
|
+
output,
|
|
67
|
+
databaseTypesOutput: output.replace(/[^/]+$/, "database.types.ts"),
|
|
68
|
+
postgrestVersion: config.postgrestVersion ?? "13",
|
|
69
|
+
json: config.json ?? {},
|
|
70
|
+
codecs: {
|
|
71
|
+
timestamptz: config.codecs?.timestamptz ?? "string",
|
|
72
|
+
int8: config.codecs?.int8 ?? "number",
|
|
73
|
+
numeric: config.codecs?.numeric ?? "number"
|
|
74
|
+
},
|
|
75
|
+
sensitive: config.sensitive ?? [],
|
|
76
|
+
storagePaths: config.storagePaths ?? {},
|
|
77
|
+
expose: Object.fromEntries(Object.entries(config.expose ?? {}).map(([table, entry]) => [table, resolveExpose(entry)])),
|
|
78
|
+
readSets: config.readSets ?? [],
|
|
79
|
+
generators: config.generators ?? [],
|
|
80
|
+
plugins: {
|
|
81
|
+
timestamps: pick(config.plugins?.timestamps, {
|
|
82
|
+
createdAt: "created_at",
|
|
83
|
+
updatedAt: "updated_at"
|
|
84
|
+
}),
|
|
85
|
+
softDelete: pick(config.plugins?.softDelete, { column: "deleted_at" }),
|
|
86
|
+
tenant: pick(config.plugins?.tenant, { column: "organization_id" }),
|
|
87
|
+
actor: pick(config.plugins?.actor, {
|
|
88
|
+
createdBy: "created_by",
|
|
89
|
+
updatedBy: "updated_by"
|
|
90
|
+
})
|
|
91
|
+
},
|
|
92
|
+
claims: {
|
|
93
|
+
...DEFAULT_CLAIMS,
|
|
94
|
+
...config.claims
|
|
95
|
+
},
|
|
96
|
+
buckets: config.buckets ?? {},
|
|
97
|
+
topics: config.topics ?? {},
|
|
98
|
+
realtime: { tables: config.realtime?.tables ?? [] },
|
|
99
|
+
entitlements: entitlementsOf(config.entitlements),
|
|
100
|
+
permdock: {
|
|
101
|
+
manifest: config.permdock?.manifest ?? "permdock.manifest.json",
|
|
102
|
+
catalog: config.permdock?.catalog ?? "permissions.catalog.json"
|
|
103
|
+
},
|
|
104
|
+
vectorSearch: vectorSearchOf(config.vectorSearch),
|
|
105
|
+
sql: {
|
|
106
|
+
dir: config.sql?.dir ?? "supabase/schemas",
|
|
107
|
+
prefix: config.sql?.prefix ?? "900_better_supabase",
|
|
108
|
+
testsDir: config.sql?.testsDir ?? "supabase/tests",
|
|
109
|
+
kit: config.sql?.kit ?? []
|
|
110
|
+
},
|
|
111
|
+
seed: {
|
|
112
|
+
entry: config.seed?.entry ?? "supabase/seed.ts",
|
|
113
|
+
output: config.seed?.output ?? "supabase/seeds/000_better_supabase.sql"
|
|
114
|
+
},
|
|
115
|
+
openapi: {
|
|
116
|
+
entry: config.openapi?.entry ?? "src/lib/openapi.ts",
|
|
117
|
+
output: config.openapi?.output ?? "openapi.json"
|
|
118
|
+
},
|
|
119
|
+
doctor: {
|
|
120
|
+
ignore: config.doctor?.ignore ?? [],
|
|
121
|
+
strict: config.doctor?.strict ?? false,
|
|
122
|
+
sources: config.doctor?.sources ?? ["src/**/*.{ts,tsx}"],
|
|
123
|
+
policyHelperLimit: config.doctor?.policyHelperLimit ?? 5,
|
|
124
|
+
...config.doctor?.claimsLimit === void 0 ? {} : { claimsLimit: config.doctor.claimsLimit }
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
export { resolveJsonSchema as i, defineConfig as n, resolveConfig as r, CONFIG_SCHEMA_URL as t };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
/// <reference lib="esnext.temporal" />
|
|
2
|
+
import { A as SchemaMeta, a as Casing, b as PermdockBucketPolicy, i as BucketPolicyName } from "./types-DONv9SHN.js";
|
|
3
|
+
import { GeneratorMetadata } from "@supabase/postgrest-typegen";
|
|
4
|
+
//#region src/config/snapshot.d.ts
|
|
4
5
|
/**
|
|
5
6
|
* What `better-supabase introspect` reads from Postgres. `generator` is the
|
|
6
7
|
* `@supabase/postgrest-typegen` contract (the same metadata behind
|
|
@@ -72,6 +73,8 @@ interface ExtrasFunction {
|
|
|
72
73
|
readonly securityDefiner: boolean;
|
|
73
74
|
/** `set` options, e.g. `{ statement_timeout: '5s' }`. */
|
|
74
75
|
readonly settings: Readonly<Record<string, string>>;
|
|
76
|
+
/** Which of `anon` and `authenticated` may execute it. Absent in older snapshots. */
|
|
77
|
+
readonly execute?: readonly string[];
|
|
75
78
|
}
|
|
76
79
|
interface ExtrasTable {
|
|
77
80
|
/** Table oid, matching `GeneratorMetadata.tables[].id`. */
|
|
@@ -91,6 +94,8 @@ interface ExtrasTable {
|
|
|
91
94
|
readonly policies: readonly CatalogPolicy[];
|
|
92
95
|
readonly triggers: readonly CatalogTrigger[];
|
|
93
96
|
readonly grants: readonly CatalogGrant[];
|
|
97
|
+
/** Absent in snapshots taken before column grants were introspected. */
|
|
98
|
+
readonly columnGrants?: readonly CatalogColumnGrant[];
|
|
94
99
|
/** Postgres estimates at least `LARGE_TABLE_ROWS` rows; the `unbounded-read` lint reads it. */
|
|
95
100
|
readonly large?: true;
|
|
96
101
|
}
|
|
@@ -109,6 +114,10 @@ interface CatalogIndex {
|
|
|
109
114
|
readonly unique: boolean;
|
|
110
115
|
readonly primary: boolean;
|
|
111
116
|
readonly partial: boolean;
|
|
117
|
+
/** Access method (`btree`, `gin`, `gist`, ...). Absent in older snapshots. */
|
|
118
|
+
readonly method?: string;
|
|
119
|
+
/** The `where` of a partial index, as Postgres prints it. Absent in older snapshots. */
|
|
120
|
+
readonly predicate?: string | null;
|
|
112
121
|
}
|
|
113
122
|
interface CatalogPolicy {
|
|
114
123
|
readonly name: string;
|
|
@@ -134,6 +143,12 @@ interface CatalogGrant {
|
|
|
134
143
|
readonly role: string;
|
|
135
144
|
readonly privileges: readonly string[];
|
|
136
145
|
}
|
|
146
|
+
/** A column-level `insert` or `update` grant to `anon` or `authenticated`. */
|
|
147
|
+
interface CatalogColumnGrant {
|
|
148
|
+
readonly column: string;
|
|
149
|
+
readonly role: string;
|
|
150
|
+
readonly privileges: readonly string[];
|
|
151
|
+
}
|
|
137
152
|
interface SnapshotBucket {
|
|
138
153
|
readonly id: string;
|
|
139
154
|
readonly public: boolean;
|
|
@@ -175,6 +190,8 @@ interface CatalogTable {
|
|
|
175
190
|
readonly policies: readonly CatalogPolicy[];
|
|
176
191
|
readonly triggers: readonly CatalogTrigger[];
|
|
177
192
|
readonly grants: readonly CatalogGrant[];
|
|
193
|
+
/** Absent in snapshots taken before column grants were introspected. */
|
|
194
|
+
readonly columnGrants?: readonly CatalogColumnGrant[];
|
|
178
195
|
}
|
|
179
196
|
interface CatalogColumn {
|
|
180
197
|
readonly name: string;
|
|
@@ -237,49 +254,7 @@ interface CatalogFunctionArg {
|
|
|
237
254
|
readonly hasDefault: boolean;
|
|
238
255
|
}
|
|
239
256
|
//#endregion
|
|
240
|
-
//#region src/
|
|
241
|
-
/** What field planning reads: the metadata and the typed-jsonb config. */
|
|
242
|
-
interface SchemaSource {
|
|
243
|
-
readonly meta: SchemaMeta;
|
|
244
|
-
readonly config: {
|
|
245
|
-
readonly json: Readonly<Record<string, unknown>>;
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
//#endregion
|
|
249
|
-
//#region src/generators/json-schema.d.ts
|
|
250
|
-
interface JsonSchemaGeneratorOptions {
|
|
251
|
-
/** Output path relative to the project root. Defaults to `<output>.schema.json`. */
|
|
252
|
-
readonly output?: string;
|
|
253
|
-
/** `$id` of the document. */
|
|
254
|
-
readonly id?: string;
|
|
255
|
-
}
|
|
256
|
-
type JsonSchema = Record<string, unknown>;
|
|
257
|
-
/** JSON Schema (2020-12) `$defs` for every table: `customersRow`, `customersInsert`, ... */
|
|
258
|
-
declare function buildJsonSchema(input: SchemaSource, id?: string): JsonSchema;
|
|
259
|
-
/** Writes the JSON Schema document; `createOpenApi` reuses the same `$defs`. */
|
|
260
|
-
declare function jsonSchema(options?: JsonSchemaGeneratorOptions): Generator;
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/generators/valibot.d.ts
|
|
263
|
-
interface ValibotGeneratorOptions {
|
|
264
|
-
/** Output path relative to the project root. Defaults to `<output>.valibot.ts`. */
|
|
265
|
-
readonly output?: string;
|
|
266
|
-
/** Schemas for typed jsonb columns: `{ 'customers.metadata': './schemas.ts#metadata' }`. */
|
|
267
|
-
readonly json?: Readonly<Record<string, string>>;
|
|
268
|
-
}
|
|
269
|
-
/** Valibot schemas for every table's Row, Insert and Update shape. */
|
|
270
|
-
declare function valibot(options?: ValibotGeneratorOptions): Generator;
|
|
271
|
-
//#endregion
|
|
272
|
-
//#region src/generators/zod.d.ts
|
|
273
|
-
interface ZodGeneratorOptions {
|
|
274
|
-
/** Output path relative to the project root. Defaults to `<output>.zod.ts`. */
|
|
275
|
-
readonly output?: string;
|
|
276
|
-
/** Schemas for typed jsonb columns: `{ 'customers.metadata': './schemas.ts#metadata' }`. */
|
|
277
|
-
readonly json?: Readonly<Record<string, string>>;
|
|
278
|
-
}
|
|
279
|
-
/** Zod 4 schemas for every table's Row, Insert and Update shape. */
|
|
280
|
-
declare function zod(options?: ZodGeneratorOptions): Generator;
|
|
281
|
-
//#endregion
|
|
282
|
-
//#region src/config/index.d.ts
|
|
257
|
+
//#region src/config/config.d.ts
|
|
283
258
|
/**
|
|
284
259
|
* Where codegen reads the database from. Without any of these, `$DATABASE_URL`
|
|
285
260
|
* and then the local stack (`supabase start`) are used.
|
|
@@ -423,8 +398,11 @@ interface DoctorConfig {
|
|
|
423
398
|
* `numeric` as numbers.
|
|
424
399
|
*/
|
|
425
400
|
interface CodecsConfig {
|
|
426
|
-
/**
|
|
427
|
-
|
|
401
|
+
/**
|
|
402
|
+
* `'instant'` decodes `timestamptz` columns to `Temporal.Instant` and
|
|
403
|
+
* `timestamp` columns to `Temporal.PlainDateTime`.
|
|
404
|
+
*/
|
|
405
|
+
readonly timestamptz?: "string" | "instant";
|
|
428
406
|
/** `'bigint'` or `'string'` read `int8` exactly (above 2^53). */
|
|
429
407
|
readonly int8?: "number" | "string" | "bigint";
|
|
430
408
|
/** `'string'` reads `numeric` exactly. */
|
|
@@ -475,6 +453,22 @@ interface EntitlementsConfig {
|
|
|
475
453
|
readonly customer?: string;
|
|
476
454
|
/** The tenant id column of that table. Defaults to `id`. */
|
|
477
455
|
readonly key?: string;
|
|
456
|
+
/**
|
|
457
|
+
* With a PermDock manifest, `has_entitlement` and `feature_claims` read
|
|
458
|
+
* PermDock's memberships (`member_<scope>_ids()` and
|
|
459
|
+
* `member_<scope>_ids_for(user)`) instead of `better_supabase.memberships`.
|
|
460
|
+
* `scope` is the PermDock scope tenants are (default `organization`);
|
|
461
|
+
* `false` keeps the kit's memberships table.
|
|
462
|
+
*/
|
|
463
|
+
readonly permdock?: false | {
|
|
464
|
+
readonly scope?: string;
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
interface PermdockPathsConfig {
|
|
468
|
+
/** What `permdock supabase inspect --out` writes. Defaults to `permdock.manifest.json`. */
|
|
469
|
+
readonly manifest?: string;
|
|
470
|
+
/** What `permdock catalog` writes. Defaults to `permissions.catalog.json`. */
|
|
471
|
+
readonly catalog?: string;
|
|
478
472
|
}
|
|
479
473
|
/** pgvector distance: `<=>` (cosine), `<->` (l2) or `<#>` (negative inner product). */
|
|
480
474
|
type VectorDistance = "cosine" | "l2" | "inner_product";
|
|
@@ -555,6 +549,8 @@ interface BetterSupabaseConfig {
|
|
|
555
549
|
readonly topics?: Readonly<Record<string, string>>;
|
|
556
550
|
readonly realtime?: RealtimeConfig;
|
|
557
551
|
readonly entitlements?: EntitlementsConfig;
|
|
552
|
+
/** Where PermDock's JSON outputs are, for doctor, `gen` and the SQL kit. */
|
|
553
|
+
readonly permdock?: PermdockPathsConfig;
|
|
558
554
|
/**
|
|
559
555
|
* Embedding columns, keyed by `table` or `schema.table`. The
|
|
560
556
|
* `vector-search` SQL kit module writes `search_<table>(query, k)` for each,
|
|
@@ -596,7 +592,11 @@ interface ResolvedConfig {
|
|
|
596
592
|
readonly table: string;
|
|
597
593
|
readonly column: string;
|
|
598
594
|
readonly key: string;
|
|
595
|
+
readonly permdock: false | {
|
|
596
|
+
readonly scope: string;
|
|
597
|
+
};
|
|
599
598
|
};
|
|
599
|
+
readonly permdock: Required<PermdockPathsConfig>;
|
|
600
600
|
readonly vectorSearch: readonly {
|
|
601
601
|
readonly table: string;
|
|
602
602
|
readonly column: string;
|
|
@@ -615,4 +615,4 @@ declare function defineConfig(config: BetterSupabaseConfig): BetterSupabaseConfi
|
|
|
615
615
|
/** Applies defaults. Paths stay relative to `root`. */
|
|
616
616
|
declare function resolveConfig(config: BetterSupabaseConfig, root: string): ResolvedConfig;
|
|
617
617
|
//#endregion
|
|
618
|
-
export {
|
|
618
|
+
export { GeneratorMetadata as $, VectorSearchConfig as A, CatalogFunction as B, SoftDeleteConfig as C, TenantConfig as D, TableConfig as E, CatalogCheck as F, CatalogTable as G, CatalogGrant as H, CatalogColumn as I, ExtrasFunction as J, CatalogTrigger as K, CatalogColumnGrant as L, resolveConfig as M, resolveJsonSchema as N, TimestampsConfig as O, Catalog as P, ForeignKeyAction as Q, CatalogEnum as R, SeedConfig as S, SqlConfig as T, CatalogIndex as U, CatalogFunctionArg as V, CatalogPolicy as W, ExtrasHookFunction as X, ExtrasHook as Y, ExtrasTable as Z, PluginFlagsConfig as _, ClaimsConfig as a, ResolvedConfig as b, EntitlementsConfig as c, Generator as d, Snapshot as et, GeneratorInput as f, PermdockPathsConfig as g, OpenApiConfig as h, CONFIG_SCHEMA_URL as i, defineConfig as j, VectorDistance as k, ExposeConfig as l, JsonTypeConfig as m, BetterSupabaseConfig as n, SnapshotExtras as nt, CodecsConfig as o, JsonSchemaSource as p, CatalogUnique as q, BucketConfig as r, DoctorConfig as s, ActorConfig as t, SnapshotBucket as tt, GeneratedFile as u, Privilege as v, SourceConfig as w, ResolvedExpose as x, RealtimeConfig as y, CatalogForeignKey as z };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as parseImport, c as schemaName, d as variantsFor, i as fieldsFor, l as siblingPath, o as propertyKey, r as HEADER, s as rowType, u as tableEntries } from "./json-schema-BpYqkCKf.js";
|
|
1
|
+
import { a as parseImport, c as schemaName, d as variantsFor, i as fieldsFor, l as siblingPath, o as propertyKey, r as HEADER, s as rowType, u as tableEntries } from "./json-schema-DP6V7cbr.js";
|
|
3
2
|
//#region src/generators/valibot.ts
|
|
4
3
|
function scalar$1(kind) {
|
|
5
4
|
switch (kind.kind) {
|
|
@@ -10,7 +9,8 @@ function scalar$1(kind) {
|
|
|
10
9
|
case "boolean": return "v.boolean()";
|
|
11
10
|
case "datetime": return "v.pipe(v.string(), v.isoTimestamp())";
|
|
12
11
|
case "date": return "v.pipe(v.string(), v.isoDate())";
|
|
13
|
-
case "
|
|
12
|
+
case "instant": return "v.instance(Temporal.Instant)";
|
|
13
|
+
case "plainDateTime": return "v.instance(Temporal.PlainDateTime)";
|
|
14
14
|
case "bigint": return "v.bigint()";
|
|
15
15
|
case "json": return "json";
|
|
16
16
|
case "enum": return `v.picklist([${kind.values.map((value) => JSON.stringify(value)).join(", ")}])`;
|
|
@@ -19,7 +19,7 @@ function scalar$1(kind) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
function field$1(table, plan, jsonImports) {
|
|
22
|
-
let expr = jsonImports.get(`${table}.${plan.column.db}`) ?? (plan.customJson ? `v.custom<NonNullable<RowOf<'${table}'>['${plan.name}']>>((value) => value !== undefined)` : plan.column.storage
|
|
22
|
+
let expr = jsonImports.get(`${table}.${plan.column.db}`) ?? (plan.customJson ? `v.custom<NonNullable<RowOf<'${table}'>['${plan.name}']>>((value) => value !== undefined)` : plan.column.storage === void 0 ? scalar$1(plan.scalar) : `(v.string() as unknown as v.GenericSchema<${rowType(table, plan)}>)`);
|
|
23
23
|
if (plan.column.array) expr = `v.array(${expr})`;
|
|
24
24
|
if (plan.nullable) expr = `v.nullable(${expr})`;
|
|
25
25
|
if (plan.optional) expr = `v.exactOptional(${expr})`;
|
|
@@ -44,9 +44,9 @@ function valibot(options = {}) {
|
|
|
44
44
|
const lines = [
|
|
45
45
|
HEADER,
|
|
46
46
|
"import * as v from \"valibot\";",
|
|
47
|
-
""
|
|
47
|
+
"",
|
|
48
|
+
`import type { InsertOf, Json, RowOf, UpdateOf } from ${JSON.stringify(input.importPath(path, input.config.output))};`
|
|
48
49
|
];
|
|
49
|
-
lines.push(`import type { InsertOf, Json, RowOf, UpdateOf } from ${JSON.stringify(input.importPath(path, input.config.output))};`);
|
|
50
50
|
for (const [from, names] of imports) lines.push(`import { ${[...new Set(names)].sort().join(", ")} } from ${JSON.stringify(from)};`);
|
|
51
51
|
lines.push("", "const json: v.GenericSchema<Json> = v.lazy(() =>", " v.union([v.string(), v.number(), v.boolean(), v.null(), v.array(json), v.record(v.string(), v.optional(json))]),", ");");
|
|
52
52
|
const validators = [];
|
|
@@ -67,8 +67,7 @@ function valibot(options = {}) {
|
|
|
67
67
|
validatorTypes.push(` readonly ${propertyKey(key)}: { readonly insert: typeof ${insert}; readonly update: typeof ${update} };`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
lines.push("", "/** Write validators for the validation plugin. */");
|
|
71
|
-
lines.push("export const validators: {", ...validatorTypes, "} = {", ...validators, "};", "");
|
|
70
|
+
lines.push("", "/** Write validators for the validation plugin. */", "export const validators: {", ...validatorTypes, "} = {", ...validators, "};", "");
|
|
72
71
|
return [{
|
|
73
72
|
path,
|
|
74
73
|
contents: lines.join("\n")
|
|
@@ -87,7 +86,8 @@ function scalar(kind) {
|
|
|
87
86
|
case "boolean": return "z.boolean()";
|
|
88
87
|
case "datetime": return "z.iso.datetime({ offset: true })";
|
|
89
88
|
case "date": return "z.iso.date()";
|
|
90
|
-
case "
|
|
89
|
+
case "instant": return "z.instanceof(Temporal.Instant)";
|
|
90
|
+
case "plainDateTime": return "z.instanceof(Temporal.PlainDateTime)";
|
|
91
91
|
case "bigint": return "z.bigint()";
|
|
92
92
|
case "json": return "z.json()";
|
|
93
93
|
case "enum": return `z.enum([${kind.values.map((value) => JSON.stringify(value)).join(", ")}])`;
|
|
@@ -96,7 +96,7 @@ function scalar(kind) {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
function field(table, plan, jsonImports) {
|
|
99
|
-
let expr = jsonImports.get(`${table}.${plan.column.db}`) ?? (plan.customJson ? `z.custom<NonNullable<RowOf<'${table}'>['${plan.name}']>>((value) => value !== undefined)` : plan.column.storage
|
|
99
|
+
let expr = jsonImports.get(`${table}.${plan.column.db}`) ?? (plan.customJson ? `z.custom<NonNullable<RowOf<'${table}'>['${plan.name}']>>((value) => value !== undefined)` : plan.column.storage === void 0 ? scalar(plan.scalar) : `(z.string() as unknown as z.ZodType<${rowType(table, plan)}>)`);
|
|
100
100
|
if (plan.column.array) expr = `z.array(${expr})`;
|
|
101
101
|
if (plan.nullable) expr = `${expr}.nullable()`;
|
|
102
102
|
if (plan.optional) expr = `${expr}.exactOptional()`;
|
|
@@ -121,9 +121,9 @@ function zod(options = {}) {
|
|
|
121
121
|
const lines = [
|
|
122
122
|
HEADER,
|
|
123
123
|
"import { z } from \"zod\";",
|
|
124
|
-
""
|
|
124
|
+
"",
|
|
125
|
+
`import type { InsertOf, RowOf, UpdateOf } from ${JSON.stringify(input.importPath(path, input.config.output))};`
|
|
125
126
|
];
|
|
126
|
-
lines.push(`import type { InsertOf, RowOf, UpdateOf } from ${JSON.stringify(input.importPath(path, input.config.output))};`);
|
|
127
127
|
for (const [from, names] of imports) lines.push(`import { ${[...new Set(names)].sort().join(", ")} } from ${JSON.stringify(from)};`);
|
|
128
128
|
const validators = [];
|
|
129
129
|
for (const [key, table] of tableEntries(input)) {
|
|
@@ -137,8 +137,7 @@ function zod(options = {}) {
|
|
|
137
137
|
}
|
|
138
138
|
if (variants.includes("Insert")) validators.push(` ${propertyKey(key)}: { insert: ${schemaName(key, "Insert")}, update: ${schemaName(key, "Update")} },`);
|
|
139
139
|
}
|
|
140
|
-
lines.push("", "/** Write validators for the validation plugin. */");
|
|
141
|
-
lines.push("export const validators: {");
|
|
140
|
+
lines.push("", "/** Write validators for the validation plugin. */", "export const validators: {");
|
|
142
141
|
for (const [key, table] of tableEntries(input)) {
|
|
143
142
|
if (!variantsFor(table).includes("Insert")) continue;
|
|
144
143
|
lines.push(` readonly ${propertyKey(key)}: { readonly insert: typeof ${schemaName(key, "Insert")}; readonly update: typeof ${schemaName(key, "Update")} };`);
|
|
@@ -152,126 +151,4 @@ function zod(options = {}) {
|
|
|
152
151
|
};
|
|
153
152
|
}
|
|
154
153
|
//#endregion
|
|
155
|
-
|
|
156
|
-
/** The JSON Schema document for a `json[...].schema` entry. */
|
|
157
|
-
function resolveJsonSchema(source) {
|
|
158
|
-
const standard = source["~standard"];
|
|
159
|
-
if (standard === void 0) return source;
|
|
160
|
-
const jsonSchema = standard.jsonSchema;
|
|
161
|
-
if (typeof jsonSchema?.input !== "function") throw new TypeError("json[...].schema: this Standard Schema library does not implement Standard JSON Schema; pass a JSON Schema object instead");
|
|
162
|
-
return jsonSchema.input({ target: "draft-2020-12" });
|
|
163
|
-
}
|
|
164
|
-
function entitlementsOf(config = {}) {
|
|
165
|
-
const customer = config.customer ?? "organizations.stripe_customer_id";
|
|
166
|
-
const dot = customer.lastIndexOf(".");
|
|
167
|
-
if (dot <= 0) throw new TypeError(`entitlements.customer must be "table.column", got "${customer}"`);
|
|
168
|
-
return {
|
|
169
|
-
table: customer.slice(0, dot),
|
|
170
|
-
column: customer.slice(dot + 1),
|
|
171
|
-
key: config.key ?? "id"
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function vectorSearchOf(config = {}) {
|
|
175
|
-
return Object.entries(config).map(([table, entry]) => typeof entry === "string" ? {
|
|
176
|
-
table,
|
|
177
|
-
column: entry,
|
|
178
|
-
distance: "cosine"
|
|
179
|
-
} : {
|
|
180
|
-
table,
|
|
181
|
-
column: entry.column,
|
|
182
|
-
distance: entry.distance ?? "cosine"
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
const CONFIG_SCHEMA_URL = "https://unpkg.com/better-supabase/schemas/config-v1.json";
|
|
186
|
-
/** Identity helper that types `better-supabase.config.ts`. */
|
|
187
|
-
function defineConfig(config) {
|
|
188
|
-
return config;
|
|
189
|
-
}
|
|
190
|
-
function pick(value, defaults) {
|
|
191
|
-
if (value === void 0 || value === false) return void 0;
|
|
192
|
-
if (value === true) return defaults;
|
|
193
|
-
return {
|
|
194
|
-
...defaults,
|
|
195
|
-
...value
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function resolveExpose(entry) {
|
|
199
|
-
if (Array.isArray(entry)) return {
|
|
200
|
-
anon: [],
|
|
201
|
-
authenticated: entry
|
|
202
|
-
};
|
|
203
|
-
const roles = entry;
|
|
204
|
-
return {
|
|
205
|
-
anon: roles.anon ?? [],
|
|
206
|
-
authenticated: roles.authenticated ?? []
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
/** Applies defaults. Paths stay relative to `root`. */
|
|
210
|
-
function resolveConfig(config, root) {
|
|
211
|
-
const output = config.output ?? "src/lib/supabase/generated.ts";
|
|
212
|
-
return {
|
|
213
|
-
root,
|
|
214
|
-
source: config.source ?? {},
|
|
215
|
-
schemas: config.schemas ?? ["public"],
|
|
216
|
-
casing: config.casing ?? "snake",
|
|
217
|
-
tables: config.tables ?? {},
|
|
218
|
-
output,
|
|
219
|
-
databaseTypesOutput: output.replace(/[^/]+$/, "database.types.ts"),
|
|
220
|
-
postgrestVersion: config.postgrestVersion ?? "13",
|
|
221
|
-
json: config.json ?? {},
|
|
222
|
-
codecs: {
|
|
223
|
-
timestamptz: config.codecs?.timestamptz ?? "string",
|
|
224
|
-
int8: config.codecs?.int8 ?? "number",
|
|
225
|
-
numeric: config.codecs?.numeric ?? "number"
|
|
226
|
-
},
|
|
227
|
-
sensitive: config.sensitive ?? [],
|
|
228
|
-
storagePaths: config.storagePaths ?? {},
|
|
229
|
-
expose: Object.fromEntries(Object.entries(config.expose ?? {}).map(([table, entry]) => [table, resolveExpose(entry)])),
|
|
230
|
-
readSets: config.readSets ?? [],
|
|
231
|
-
generators: config.generators ?? [],
|
|
232
|
-
plugins: {
|
|
233
|
-
timestamps: pick(config.plugins?.timestamps, {
|
|
234
|
-
createdAt: "created_at",
|
|
235
|
-
updatedAt: "updated_at"
|
|
236
|
-
}),
|
|
237
|
-
softDelete: pick(config.plugins?.softDelete, { column: "deleted_at" }),
|
|
238
|
-
tenant: pick(config.plugins?.tenant, { column: "organization_id" }),
|
|
239
|
-
actor: pick(config.plugins?.actor, {
|
|
240
|
-
createdBy: "created_by",
|
|
241
|
-
updatedBy: "updated_by"
|
|
242
|
-
})
|
|
243
|
-
},
|
|
244
|
-
claims: {
|
|
245
|
-
...DEFAULT_CLAIMS,
|
|
246
|
-
...config.claims
|
|
247
|
-
},
|
|
248
|
-
buckets: config.buckets ?? {},
|
|
249
|
-
topics: config.topics ?? {},
|
|
250
|
-
realtime: { tables: config.realtime?.tables ?? [] },
|
|
251
|
-
entitlements: entitlementsOf(config.entitlements),
|
|
252
|
-
vectorSearch: vectorSearchOf(config.vectorSearch),
|
|
253
|
-
sql: {
|
|
254
|
-
dir: config.sql?.dir ?? "supabase/schemas",
|
|
255
|
-
prefix: config.sql?.prefix ?? "900_better_supabase",
|
|
256
|
-
testsDir: config.sql?.testsDir ?? "supabase/tests",
|
|
257
|
-
kit: config.sql?.kit ?? []
|
|
258
|
-
},
|
|
259
|
-
seed: {
|
|
260
|
-
entry: config.seed?.entry ?? "supabase/seed.ts",
|
|
261
|
-
output: config.seed?.output ?? "supabase/seeds/000_better_supabase.sql"
|
|
262
|
-
},
|
|
263
|
-
openapi: {
|
|
264
|
-
entry: config.openapi?.entry ?? "src/lib/openapi.ts",
|
|
265
|
-
output: config.openapi?.output ?? "openapi.json"
|
|
266
|
-
},
|
|
267
|
-
doctor: {
|
|
268
|
-
ignore: config.doctor?.ignore ?? [],
|
|
269
|
-
strict: config.doctor?.strict ?? false,
|
|
270
|
-
sources: config.doctor?.sources ?? ["src/**/*.{ts,tsx}"],
|
|
271
|
-
policyHelperLimit: config.doctor?.policyHelperLimit ?? 5,
|
|
272
|
-
...config.doctor?.claimsLimit === void 0 ? {} : { claimsLimit: config.doctor.claimsLimit }
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
//#endregion
|
|
277
|
-
export { zod as a, resolveJsonSchema as i, defineConfig as n, valibot as o, resolveConfig as r, CONFIG_SCHEMA_URL as t };
|
|
154
|
+
export { valibot as n, zod as t };
|