better-supabase 0.1.0 → 0.3.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.
Files changed (149) hide show
  1. package/README.md +34 -31
  2. package/dist/base64-CQeB1eSf.js +42 -0
  3. package/dist/claims-CoTobNC-.js +25 -0
  4. package/dist/client/index.d.ts +1 -1
  5. package/dist/client/index.js +4 -14
  6. package/dist/{compiler-DL18ukPe.d.ts → compiler-2zqGzxVZ.d.ts} +2 -2
  7. package/dist/config/index.d.ts +4 -3
  8. package/dist/config/index.js +5 -3
  9. package/dist/config-Be4GwsqI.js +129 -0
  10. package/dist/{index-BD6wKthp.d.ts → config-C1CYcm6o.d.ts} +75 -54
  11. package/dist/{config-D-aR2ZoN.js → config-DOsGYSiT.js} +14 -136
  12. package/dist/{define-QGkq04oe.js → define-DF341GDj.js} +133 -110
  13. package/dist/{define-CTfWw-SS.d.ts → define-DUbydmJa.d.ts} +32 -14
  14. package/dist/edge/index.d.ts +4 -4
  15. package/dist/edge/index.js +4 -4
  16. package/dist/entitlements-CTEBm7IB.js +20 -0
  17. package/dist/entitlements-DvJXoI02.d.ts +42 -0
  18. package/dist/env/index.js +203 -1
  19. package/dist/events/index.d.ts +1 -1
  20. package/dist/events/index.js +139 -1
  21. package/dist/{events-2OJsVG_d.d.ts → events-Do8jXh4D.d.ts} +3 -3
  22. package/dist/{executor-Bje4suQF.d.ts → executor-B26lgbHD.d.ts} +2 -2
  23. package/dist/{executor-Ceq60hPM.js → executor-C57jx2pn.js} +7 -2
  24. package/dist/{executor-Bazhgsgq.d.ts → executor-DynmIWhq.d.ts} +2 -2
  25. package/dist/guards-BnzDvFrz.js +10 -0
  26. package/dist/hono/index.d.ts +5 -5
  27. package/dist/hono/index.js +4 -4
  28. package/dist/{index-Hf8PP9sP.d.ts → index-BNsABq7P.d.ts} +17 -13
  29. package/dist/{index-JXHBuS53.d.ts → index-CADlNHK-.d.ts} +27 -14
  30. package/dist/{index-Nxo3TJcm.d.ts → index-CTTMS6_1.d.ts} +27 -8
  31. package/dist/index-Cf-D2jk1.d.ts +50 -0
  32. package/dist/{index-Dup-nSe9.d.ts → index-CriFFJ_p.d.ts} +4 -4
  33. package/dist/{index-DQVvHzjW.d.ts → index-GV77NpRP.d.ts} +5 -4
  34. package/dist/{index-Sw43J8HG.d.ts → index-UJ-LUxtI.d.ts} +6 -6
  35. package/dist/{index-cEeweTeM.d.ts → index-kpgopLNv.d.ts} +4 -3
  36. package/dist/{index-DRid0qIv.d.ts → index-qriRM9cZ.d.ts} +7 -2
  37. package/dist/index.d.ts +13 -13
  38. package/dist/index.js +18 -8
  39. package/dist/jobs/index.d.ts +25 -24
  40. package/dist/jobs/index.js +19 -12
  41. package/dist/{json-schema-BbwO2mZg.js → json-schema--aOXAGfU.js} +9 -3
  42. package/dist/lint/index.js +1 -1
  43. package/dist/list/index.d.ts +2 -2
  44. package/dist/list/index.js +128 -93
  45. package/dist/{live-6b9i72Ux.d.ts → live-QE3UPbGm.d.ts} +27 -6
  46. package/dist/logger-glM28NVN.js +21 -0
  47. package/dist/mcp/index.d.ts +59 -15
  48. package/dist/mcp/index.js +229 -67
  49. package/dist/{mfa-CpogP66z.js → mfa-BxoR1RkN.js} +97 -22
  50. package/dist/{mfa-TVia554c.d.ts → mfa-x3V3vGh-.d.ts} +1 -1
  51. package/dist/next/index.d.ts +51 -38
  52. package/dist/next/index.js +31 -25
  53. package/dist/openapi/index.d.ts +1 -1
  54. package/dist/openapi/index.js +58 -35
  55. package/dist/orpc/index.d.ts +6 -6
  56. package/dist/orpc/index.js +3 -3
  57. package/dist/otel/index.d.ts +3 -3
  58. package/dist/otel/index.js +5 -3
  59. package/dist/{template-BeOGnynM.js → permdock-sql-Bta_G0v-.js} +32 -3
  60. package/dist/permdock-sql-DImJULY-.d.ts +17 -0
  61. package/dist/{plugin-HvGqCurB.d.ts → plugin-DVRB8qNE.d.ts} +5 -4
  62. package/dist/plugins/actor/index.d.ts +1 -1
  63. package/dist/plugins/rules/index.d.ts +4 -3
  64. package/dist/plugins/rules/index.js +8 -15
  65. package/dist/plugins/soft-delete/index.d.ts +3 -3
  66. package/dist/plugins/soft-delete/index.js +2 -2
  67. package/dist/plugins/tenant/index.d.ts +10 -4
  68. package/dist/plugins/tenant/index.js +15 -13
  69. package/dist/plugins/timestamps/index.d.ts +1 -1
  70. package/dist/plugins/timestamps/index.js +1 -1
  71. package/dist/plugins/validation/index.d.ts +2 -2
  72. package/dist/pool-B9qsLyFR.d.ts +71 -0
  73. package/dist/postgres/index.d.ts +10 -5
  74. package/dist/postgres/index.js +36 -16
  75. package/dist/{postgrest-Dm-vhY6R.d.ts → postgrest-DmBlevh-.d.ts} +1 -1
  76. package/dist/{problem-DPu6Fh-t.js → problem-CGt1ADix.js} +14 -8
  77. package/dist/{problem-DlgB0lYl.d.ts → problem-Z2RTQjZD.d.ts} +6 -4
  78. package/dist/query/index.d.ts +2 -2
  79. package/dist/query/index.js +1 -1
  80. package/dist/{query-ChvDbsDE.js → query-BdKLTPlj.js} +2 -2
  81. package/dist/react/index.d.ts +7 -7
  82. package/dist/react/index.js +3 -3
  83. package/dist/react/server.d.ts +5 -5
  84. package/dist/react/server.js +1 -1
  85. package/dist/react/session.d.ts +21 -2
  86. package/dist/react/session.js +19 -1
  87. package/dist/{react-CrOvrnIP.js → react-DNBYNazu.js} +28 -23
  88. package/dist/{read-set-DhX2d04c.js → read-set-D0qBcboM.js} +3 -3
  89. package/dist/realtime/index.d.ts +4 -2
  90. package/dist/realtime/index.js +30 -14
  91. package/dist/{resolve-DW8h9NPm.d.ts → resolve-BRciX2jK.d.ts} +25 -9
  92. package/dist/{resource-SkPTRJDD.d.ts → resource-CwVgiI5q.d.ts} +16 -7
  93. package/dist/{resource-CYiu6Ygi.js → resource-D30rp0GN.js} +38 -16
  94. package/dist/{respond-4-dhoV7x.js → respond-C44EZAJo.js} +38 -19
  95. package/dist/{respond-PoTpy5DT.d.ts → respond-DAkPIdTH.d.ts} +23 -17
  96. package/dist/{result-CTkCZ6JA.d.ts → result-c2OYgCV2.d.ts} +13 -8
  97. package/dist/server/index.d.ts +35 -10
  98. package/dist/server/index.js +38 -9
  99. package/dist/{simplify-oHiDKRVQ.js → simplify-LakqK1vH.js} +22 -28
  100. package/dist/{spec-pins-t6sPaHvl.js → spec-pins-C3oc-Tdp.js} +1 -1
  101. package/dist/{spec-pins-CJPVghHy.d.ts → spec-pins-CqorWDnO.d.ts} +1 -1
  102. package/dist/sql/index.d.ts +139 -0
  103. package/dist/sql/index.js +1983 -0
  104. package/dist/{sql-M8l3fnS0.js → sql-BIgk12ew.js} +72 -16
  105. package/dist/ssr/index.d.ts +5 -5
  106. package/dist/ssr/index.js +3 -3
  107. package/dist/{standard-CyhRzctb.d.ts → standard-eudBiRk1.d.ts} +1 -1
  108. package/dist/{stats-3iy8u3_P.js → stats-D78UQ8Yu.js} +8 -7
  109. package/dist/storage/index.d.ts +4 -2
  110. package/dist/storage/index.js +530 -1
  111. package/dist/{tables-rZxRxNPW.js → tables-Dhha3BXM.js} +5 -5
  112. package/dist/temporal-BwshQk0W.js +27 -0
  113. package/dist/temporal-required-CMxeSVPo.js +19 -0
  114. package/dist/testing/index.d.ts +49 -16
  115. package/dist/testing/index.js +233 -66
  116. package/dist/{types-C2fslP1z.d.ts → types-DONv9SHN.d.ts} +68 -12
  117. package/dist/{version-Cqq1m3UY.js → version-BfpG2gks.js} +1 -1
  118. package/dist/view-3Po_PVlr.d.ts +79 -0
  119. package/dist/{view-B6F9QbG-.js → view-wZ-9qIUz.js} +12 -2
  120. package/dist/webhooks/index.d.ts +19 -17
  121. package/dist/webhooks/index.js +1 -1
  122. package/dist/{webhooks-DbMTJJX2.js → webhooks-CAIFQSTM.js} +12 -10
  123. package/package.json +30 -30
  124. package/schemas/config-v1.json +80 -5
  125. package/schemas/doctor-report-v1.json +18 -1
  126. package/schemas/snapshot-v2.json +39 -0
  127. package/skills/better-supabase/SKILL.md +23 -11
  128. package/skills/better-supabase/references/plugins.md +28 -16
  129. package/skills/better-supabase/references/troubleshooting.md +15 -15
  130. package/skills/better-supabase-api/SKILL.md +9 -9
  131. package/skills/better-supabase-api/references/adapters.md +30 -25
  132. package/skills/better-supabase-testing/SKILL.md +15 -11
  133. package/bin/better-supabase.js +0 -3
  134. package/dist/casing-da0uRTqt.js +0 -14
  135. package/dist/cli/bin.d.ts +0 -1
  136. package/dist/cli/bin.js +0 -15
  137. package/dist/cli/index.d.ts +0 -226
  138. package/dist/cli/index.js +0 -3
  139. package/dist/cli-CoByWYja.js +0 -6472
  140. package/dist/entitlements-BBg61DQZ.d.ts +0 -20
  141. package/dist/entitlements-BC_khwRy.js +0 -17
  142. package/dist/env-BEToab0I.js +0 -204
  143. package/dist/events-BuzTgn2D.js +0 -135
  144. package/dist/pool-BFeqzwQS.d.ts +0 -37
  145. package/dist/seed-CzecODcJ.js +0 -101
  146. package/dist/session-C3osL21k.d.ts +0 -21
  147. package/dist/session-CD-3orO_.js +0 -19
  148. package/dist/storage-BWXVUXGk.js +0 -461
  149. package/dist/view-B0ltUmTi.d.ts +0 -43
@@ -1,4 +1,4 @@
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-BbwO2mZg.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--aOXAGfU.js";
2
2
  //#region src/generators/valibot.ts
3
3
  function scalar$1(kind) {
4
4
  switch (kind.kind) {
@@ -9,7 +9,8 @@ function scalar$1(kind) {
9
9
  case "boolean": return "v.boolean()";
10
10
  case "datetime": return "v.pipe(v.string(), v.isoTimestamp())";
11
11
  case "date": return "v.pipe(v.string(), v.isoDate())";
12
- case "dateObject": return "v.date()";
12
+ case "instant": return "v.instance(Temporal.Instant)";
13
+ case "plainDateTime": return "v.instance(Temporal.PlainDateTime)";
13
14
  case "bigint": return "v.bigint()";
14
15
  case "json": return "json";
15
16
  case "enum": return `v.picklist([${kind.values.map((value) => JSON.stringify(value)).join(", ")}])`;
@@ -18,8 +19,7 @@ function scalar$1(kind) {
18
19
  }
19
20
  }
20
21
  function field$1(table, plan, jsonImports) {
21
- const imported = jsonImports.get(`${table}.${plan.column.db}`);
22
- let expr = imported ? imported : plan.customJson ? `v.custom<NonNullable<RowOf<'${table}'>['${plan.name}']>>((value) => value !== undefined)` : plan.column.storage !== void 0 ? `(v.string() as unknown as v.GenericSchema<${rowType(table, plan)}>)` : scalar$1(plan.scalar);
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 "dateObject": return "z.date()";
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,8 +96,7 @@ function scalar(kind) {
96
96
  }
97
97
  }
98
98
  function field(table, plan, jsonImports) {
99
- const imported = jsonImports.get(`${table}.${plan.column.db}`);
100
- let expr = imported ? imported : plan.customJson ? `z.custom<NonNullable<RowOf<'${table}'>['${plan.name}']>>((value) => value !== undefined)` : plan.column.storage !== void 0 ? `(z.string() as unknown as z.ZodType<${rowType(table, plan)}>)` : scalar(plan.scalar);
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)}>)`);
101
100
  if (plan.column.array) expr = `z.array(${expr})`;
102
101
  if (plan.nullable) expr = `${expr}.nullable()`;
103
102
  if (plan.optional) expr = `${expr}.exactOptional()`;
@@ -122,9 +121,9 @@ function zod(options = {}) {
122
121
  const lines = [
123
122
  HEADER,
124
123
  "import { z } from \"zod\";",
125
- ""
124
+ "",
125
+ `import type { InsertOf, RowOf, UpdateOf } from ${JSON.stringify(input.importPath(path, input.config.output))};`
126
126
  ];
127
- lines.push(`import type { InsertOf, RowOf, UpdateOf } from ${JSON.stringify(input.importPath(path, input.config.output))};`);
128
127
  for (const [from, names] of imports) lines.push(`import { ${[...new Set(names)].sort().join(", ")} } from ${JSON.stringify(from)};`);
129
128
  const validators = [];
130
129
  for (const [key, table] of tableEntries(input)) {
@@ -138,8 +137,7 @@ function zod(options = {}) {
138
137
  }
139
138
  if (variants.includes("Insert")) validators.push(` ${propertyKey(key)}: { insert: ${schemaName(key, "Insert")}, update: ${schemaName(key, "Update")} },`);
140
139
  }
141
- lines.push("", "/** Write validators for the validation plugin. */");
142
- lines.push("export const validators: {");
140
+ lines.push("", "/** Write validators for the validation plugin. */", "export const validators: {");
143
141
  for (const [key, table] of tableEntries(input)) {
144
142
  if (!variantsFor(table).includes("Insert")) continue;
145
143
  lines.push(` readonly ${propertyKey(key)}: { readonly insert: typeof ${schemaName(key, "Insert")}; readonly update: typeof ${schemaName(key, "Update")} };`);
@@ -153,124 +151,4 @@ function zod(options = {}) {
153
151
  };
154
152
  }
155
153
  //#endregion
156
- //#region src/config/index.ts
157
- /** The JSON Schema document for a `json[...].schema` entry. */
158
- function resolveJsonSchema(source) {
159
- const standard = source["~standard"];
160
- if (standard === void 0) return source;
161
- const jsonSchema = standard.jsonSchema;
162
- 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");
163
- return jsonSchema.input({ target: "draft-2020-12" });
164
- }
165
- function entitlementsOf(config = {}) {
166
- const customer = config.customer ?? "organizations.stripe_customer_id";
167
- const dot = customer.lastIndexOf(".");
168
- if (dot <= 0) throw new TypeError(`entitlements.customer must be "table.column", got "${customer}"`);
169
- return {
170
- table: customer.slice(0, dot),
171
- column: customer.slice(dot + 1),
172
- key: config.key ?? "id"
173
- };
174
- }
175
- function vectorSearchOf(config = {}) {
176
- return Object.entries(config).map(([table, entry]) => typeof entry === "string" ? {
177
- table,
178
- column: entry,
179
- distance: "cosine"
180
- } : {
181
- table,
182
- column: entry.column,
183
- distance: entry.distance ?? "cosine"
184
- });
185
- }
186
- const CONFIG_SCHEMA_URL = "https://unpkg.com/better-supabase/schemas/config-v1.json";
187
- /** Identity helper that types `better-supabase.config.ts`. */
188
- function defineConfig(config) {
189
- return config;
190
- }
191
- function pick(value, defaults) {
192
- if (value === void 0 || value === false) return void 0;
193
- if (value === true) return defaults;
194
- return {
195
- ...defaults,
196
- ...value
197
- };
198
- }
199
- function resolveExpose(entry) {
200
- if (Array.isArray(entry)) return {
201
- anon: [],
202
- authenticated: entry
203
- };
204
- const roles = entry;
205
- return {
206
- anon: roles.anon ?? [],
207
- authenticated: roles.authenticated ?? []
208
- };
209
- }
210
- /** Applies defaults. Paths stay relative to `root`. */
211
- function resolveConfig(config, root) {
212
- const output = config.output ?? "src/lib/supabase/generated.ts";
213
- return {
214
- root,
215
- source: config.source ?? {},
216
- schemas: config.schemas ?? ["public"],
217
- casing: config.casing ?? "snake",
218
- tables: config.tables ?? {},
219
- output,
220
- databaseTypesOutput: output.replace(/[^/]+$/, "database.types.ts"),
221
- postgrestVersion: config.postgrestVersion ?? "13",
222
- json: config.json ?? {},
223
- codecs: {
224
- timestamptz: config.codecs?.timestamptz ?? "string",
225
- int8: config.codecs?.int8 ?? "number",
226
- numeric: config.codecs?.numeric ?? "number"
227
- },
228
- sensitive: config.sensitive ?? [],
229
- storagePaths: config.storagePaths ?? {},
230
- expose: Object.fromEntries(Object.entries(config.expose ?? {}).map(([table, entry]) => [table, resolveExpose(entry)])),
231
- readSets: config.readSets ?? [],
232
- generators: config.generators ?? [],
233
- plugins: {
234
- timestamps: pick(config.plugins?.timestamps, {
235
- createdAt: "created_at",
236
- updatedAt: "updated_at"
237
- }),
238
- softDelete: pick(config.plugins?.softDelete, { column: "deleted_at" }),
239
- tenant: pick(config.plugins?.tenant, {
240
- column: "organization_id",
241
- claim: "org_id"
242
- }),
243
- actor: pick(config.plugins?.actor, {
244
- createdBy: "created_by",
245
- updatedBy: "updated_by"
246
- })
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
- }
273
- };
274
- }
275
- //#endregion
276
- 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 };