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.
Files changed (190) hide show
  1. package/README.md +37 -33
  2. package/dist/base64-D2gsioCY.js +42 -0
  3. package/dist/claims-BAf6c7is.js +48 -0
  4. package/dist/cli/_format-Cax5EsM9.js +101 -0
  5. package/dist/cli/bin.js +39 -6
  6. package/dist/cli/command-CK14fP91.js +502 -0
  7. package/dist/cli/compare-BmIWVEui.js +9 -0
  8. package/dist/cli/config-D9R0o1LH.js +1895 -0
  9. package/dist/cli/config-SSKSTUl2.js +2 -0
  10. package/dist/cli/db-DOBPt660.js +52 -0
  11. package/dist/cli/dist-B1MvLv-M.js +129 -0
  12. package/dist/cli/dist-CFgGknmZ.js +1112 -0
  13. package/dist/cli/dist-Du7VnEUG.js +621 -0
  14. package/dist/cli/doctor-BOym3mbL.js +2382 -0
  15. package/dist/cli/env-BZ0uy8XK.js +108 -0
  16. package/dist/cli/env-jIFUADLY.js +511 -0
  17. package/dist/cli/errors-4v4DTtda.js +56 -0
  18. package/dist/cli/fastest-levenshtein-CFN-lNDv.js +120 -0
  19. package/dist/cli/gen-Ccn_p90L.js +2008 -0
  20. package/dist/cli/gen-D5cLCULx.js +2 -0
  21. package/dist/cli/index.d.ts +295 -28
  22. package/dist/cli/index.js +184 -3
  23. package/dist/cli/init-ClnxRYBF.js +550 -0
  24. package/dist/cli/introspect-DxqfkVIv.js +81 -0
  25. package/dist/cli/io-k41_z-jT.js +24 -0
  26. package/dist/cli/json5-ChRycquj.js +787 -0
  27. package/dist/cli/jsonc-BUniUpOk.js +2 -0
  28. package/dist/cli/jsonc-D5Fu67jw.js +45 -0
  29. package/dist/cli/keys-ByKHnvP9.js +83 -0
  30. package/dist/cli/ohash-D7bG_EOb.js +277 -0
  31. package/dist/cli/openapi-8WHjxiTJ.js +66 -0
  32. package/dist/cli/project-B_GeXyHh.js +70 -0
  33. package/dist/cli/prompts-BNcNfAve.js +1142 -0
  34. package/dist/cli/prompts-BTYQGunc.js +2 -0
  35. package/dist/cli/read-sets-CMa29t9a.js +971 -0
  36. package/dist/cli/rolldown-runtime-BPOCksWG.js +24 -0
  37. package/dist/cli/run-CP20LKk_.js +347 -0
  38. package/dist/cli/seed-5J6eu_Xg.js +98 -0
  39. package/dist/cli/skills-LJJIhLFR.js +137 -0
  40. package/dist/cli/sql-D4VbqmXi.js +199 -0
  41. package/dist/cli/style-C0NFdJRL.js +29 -0
  42. package/dist/cli/toml-DB-MNnFs.js +424 -0
  43. package/dist/{version-Cqq1m3UY.js → cli/version-5mW_8sY1.js} +1 -1
  44. package/dist/cli/yaml-CYCbJ6et.js +2252 -0
  45. package/dist/client/index.d.ts +2 -2
  46. package/dist/client/index.js +15 -25
  47. package/dist/{compiler-CZ9nIuqy.d.ts → compiler-DB3aSFOA.d.ts} +2 -2
  48. package/dist/config/index.d.ts +4 -3
  49. package/dist/config/index.js +5 -3
  50. package/dist/config-BpxDfnbg.js +129 -0
  51. package/dist/{index-DOsjFvMf.d.ts → config-C1CYcm6o.d.ts} +49 -49
  52. package/dist/{config-ClDXmVtY.js → config-CbvFmGD8.js} +14 -137
  53. package/dist/{define-BXMYD9AY.js → define-Bh0AqTik.js} +221 -120
  54. package/dist/{define-e3zI4_4g.d.ts → define-CRS2MRV3.d.ts} +36 -31
  55. package/dist/edge/index.d.ts +9 -13
  56. package/dist/edge/index.js +51 -25
  57. package/dist/{entitlements-Dng-ctuT.d.ts → entitlements-Dm-FHpNH.d.ts} +2 -2
  58. package/dist/env/index.js +203 -1
  59. package/dist/{errors-Bl3rkOzo.js → errors-L0xK41y_.js} +1 -1
  60. package/dist/events/index.d.ts +1 -1
  61. package/dist/events/index.js +139 -1
  62. package/dist/{events-DOt3nSO-.d.ts → events-B21UOhvP.d.ts} +4 -4
  63. package/dist/{executor-CGdNQ27g.d.ts → executor-B5IoUxLE.d.ts} +2 -2
  64. package/dist/{executor-DeppvirK.js → executor-CVt6dD0B.js} +9 -4
  65. package/dist/{executor-BYXQ9AGn.d.ts → executor-CZ7ImRiD.d.ts} +2 -2
  66. package/dist/hono/index.d.ts +17 -24
  67. package/dist/hono/index.js +11 -11
  68. package/dist/{index-DuP14VHo.d.ts → index-528Ugmyp.d.ts} +30 -10
  69. package/dist/{index-Bw1bwtC0.d.ts → index-BAy4tsAP.d.ts} +28 -15
  70. package/dist/{index-CBDufH1M.d.ts → index-BBdvo-5d.d.ts} +24 -26
  71. package/dist/{index-DbxFr7XG.d.ts → index-BhHEC04r.d.ts} +9 -4
  72. package/dist/index-Cf-D2jk1.d.ts +50 -0
  73. package/dist/{index-Ciu5Xlml.d.ts → index-D5IfUIDh.d.ts} +6 -5
  74. package/dist/{index-K-3WM2Hp.d.ts → index-DFmOpBGC.d.ts} +13 -13
  75. package/dist/{index-D4v7sncu.d.ts → index-RlLXd8dL.d.ts} +13 -13
  76. package/dist/index.d.ts +17 -17
  77. package/dist/index.js +23 -14
  78. package/dist/{invalidate-DbxuL2jL.js → invalidate-CgxmRamI.js} +7 -1
  79. package/dist/jobs/index.d.ts +33 -26
  80. package/dist/jobs/index.js +44 -22
  81. package/dist/{json-schema-BpYqkCKf.js → json-schema-DP6V7cbr.js} +8 -3
  82. package/dist/lint/index.js +1 -1
  83. package/dist/list/index.d.ts +2 -2
  84. package/dist/list/index.js +131 -96
  85. package/dist/{live-DJyZMD6w.d.ts → live-BHakSWWo.d.ts} +26 -16
  86. package/dist/{live-D8rV1Ldw.js → live-CdJBOc4f.js} +13 -9
  87. package/dist/lookup-BaP5bI27.js +18 -0
  88. package/dist/mcp/index.d.ts +34 -27
  89. package/dist/mcp/index.js +59 -25
  90. package/dist/{mfa-TVia554c.d.ts → mfa-C7MNQ1Ob.d.ts} +1 -1
  91. package/dist/{mfa-CpLfJSde.js → mfa-byfjruR9.js} +190 -46
  92. package/dist/next/image/index.js +6 -3
  93. package/dist/next/index.d.ts +64 -48
  94. package/dist/next/index.js +63 -50
  95. package/dist/openapi/index.d.ts +1 -1
  96. package/dist/openapi/index.js +61 -38
  97. package/dist/orpc/index.d.ts +18 -21
  98. package/dist/orpc/index.js +12 -12
  99. package/dist/otel/index.d.ts +5 -5
  100. package/dist/otel/index.js +84 -63
  101. package/dist/{permdock-sql-CghlHPuH.js → permdock-sql-C4KFzLc9.js} +12 -7
  102. package/dist/permdock-sql-DImJULY-.d.ts +17 -0
  103. package/dist/{plugin-C4TR9J0Z.d.ts → plugin-bNhvJwRh.d.ts} +5 -4
  104. package/dist/plugins/actor/index.d.ts +1 -1
  105. package/dist/plugins/actor/index.js +1 -1
  106. package/dist/plugins/rules/index.d.ts +2 -2
  107. package/dist/plugins/rules/index.js +46 -16
  108. package/dist/plugins/soft-delete/index.d.ts +3 -3
  109. package/dist/plugins/soft-delete/index.js +4 -4
  110. package/dist/plugins/tenant/index.d.ts +3 -3
  111. package/dist/plugins/tenant/index.js +10 -4
  112. package/dist/plugins/timestamps/index.d.ts +1 -1
  113. package/dist/plugins/timestamps/index.js +2 -2
  114. package/dist/plugins/validation/index.d.ts +2 -2
  115. package/dist/plugins/validation/index.js +3 -3
  116. package/dist/pool-DFwEQwmN.d.ts +78 -0
  117. package/dist/postgres/index.d.ts +10 -5
  118. package/dist/postgres/index.js +37 -16
  119. package/dist/{postgrest-cAEQ_IQN.d.ts → postgrest-Bc-0Xw62.d.ts} +1 -1
  120. package/dist/{problem-BTkTtRV9.js → problem-BihjPR0t.js} +11 -5
  121. package/dist/{problem-DlgB0lYl.d.ts → problem-U8UEKccv.d.ts} +6 -4
  122. package/dist/query/index.d.ts +2 -2
  123. package/dist/query/index.js +2 -2
  124. package/dist/{query-ChvDbsDE.js → query-BMMSWbI7.js} +19 -19
  125. package/dist/react/index.d.ts +7 -7
  126. package/dist/react/index.js +2 -2
  127. package/dist/react/server.d.ts +6 -6
  128. package/dist/react/server.js +3 -3
  129. package/dist/react/session.d.ts +21 -2
  130. package/dist/react/session.js +19 -1
  131. package/dist/{react-C83BdBGt.js → react-CQHMaESR.js} +59 -55
  132. package/dist/{read-set-4lI3W_gZ.js → read-set-FWK8qQ58.js} +51 -16
  133. package/dist/realtime/index.d.ts +4 -3
  134. package/dist/realtime/index.js +19 -17
  135. package/dist/{index-CG69s15v.d.ts → refresh-BwYkyNOQ.d.ts} +7 -3
  136. package/dist/{resolve-CjHILk2w.d.ts → resolve-BAqQcwMW.d.ts} +17 -11
  137. package/dist/{resource-CgZa3YG_.d.ts → resource-BJcaIfxi.d.ts} +17 -8
  138. package/dist/{resource-BHEWmQJK.js → resource-My_y-Syh.js} +43 -21
  139. package/dist/{respond-Dne1ARSa.d.ts → respond-DgIbdrt8.d.ts} +39 -14
  140. package/dist/{result-DWXatkd6.js → result-Bj6yt33D.js} +2 -2
  141. package/dist/{result-CTkCZ6JA.d.ts → result-CqEsbgYs.d.ts} +16 -11
  142. package/dist/server/index.d.ts +38 -13
  143. package/dist/server/index.js +43 -14
  144. package/dist/{respond-DMcbQwfN.js → server-BA75B0mT.js} +151 -96
  145. package/dist/{shared-_6-uPL7E.js → shared-DnoCdMDr.js} +4 -3
  146. package/dist/{simplify-bwJpLnaS.js → simplify-Cqvfr9dj.js} +76 -39
  147. package/dist/sql/index.d.ts +139 -0
  148. package/dist/sql/index.js +1983 -0
  149. package/dist/{sql-DTjA1LPj.js → sql-B34HU2DI.js} +74 -17
  150. package/dist/ssr/index.d.ts +4 -4
  151. package/dist/ssr/index.js +2 -2
  152. package/dist/{standard-FUi3Z3-7.js → standard-BRyBGTtp.js} +2 -2
  153. package/dist/{standard-CyhRzctb.d.ts → standard-BsaCYQJc.d.ts} +1 -1
  154. package/dist/{stats-C5W-rBfR.js → stats-C_YxA2r1.js} +40 -14
  155. package/dist/storage/index.d.ts +4 -3
  156. package/dist/storage/index.js +548 -1
  157. package/dist/{tables-rZxRxNPW.js → tables-Cb-3_VWc.js} +19 -5
  158. package/dist/temporal-BwshQk0W.js +27 -0
  159. package/dist/temporal-required-CBNHT6ni.js +19 -0
  160. package/dist/testing/index.d.ts +25 -24
  161. package/dist/testing/index.js +165 -66
  162. package/dist/{types-C83v5SQz.d.ts → types-DONv9SHN.d.ts} +14 -11
  163. package/dist/version-Bmf7_FzM.js +4 -0
  164. package/dist/{view-D1s0wa0T.d.ts → view-B64o81wp.d.ts} +36 -6
  165. package/dist/{view-aOYizTeE.js → view-BrJI2LKp.js} +11 -2
  166. package/dist/webhooks/index.d.ts +19 -17
  167. package/dist/webhooks/index.js +1 -1
  168. package/dist/{webhooks-DMipjhSP.js → webhooks-Bh_Jf_-l.js} +45 -24
  169. package/package.json +50 -22
  170. package/schemas/config-v1.json +31 -1
  171. package/schemas/doctor-report-v1.json +17 -1
  172. package/schemas/snapshot-v2.json +35 -0
  173. package/skills/better-supabase/SKILL.md +77 -18
  174. package/skills/better-supabase/references/plugins.md +21 -22
  175. package/skills/better-supabase/references/troubleshooting.md +38 -18
  176. package/skills/better-supabase-api/SKILL.md +66 -18
  177. package/skills/better-supabase-api/references/adapters.md +64 -41
  178. package/skills/better-supabase-auth/SKILL.md +146 -0
  179. package/skills/better-supabase-auth/references/permdock.md +55 -0
  180. package/skills/better-supabase-testing/SKILL.md +68 -11
  181. package/dist/casing-da0uRTqt.js +0 -14
  182. package/dist/claims-CoTobNC-.js +0 -25
  183. package/dist/cli-DrSgDOQC.js +0 -6646
  184. package/dist/env-BEToab0I.js +0 -204
  185. package/dist/events-BuzTgn2D.js +0 -135
  186. package/dist/pool-R2m_DkXi.d.ts +0 -37
  187. package/dist/seed-CzecODcJ.js +0 -101
  188. package/dist/session-C3LxnQ0e.d.ts +0 -22
  189. package/dist/session-CqEwzVup.js +0 -20
  190. package/dist/storage-DuGn38fr.js +0 -527
@@ -1,5 +1,7 @@
1
- import { a as invalidRequest, n as simplifyOrFalse } from "./simplify-bwJpLnaS.js";
1
+ import { a as invalidRequest, n as simplifyOrFalse } from "./simplify-Cqvfr9dj.js";
2
+ import { t as lookupOf } from "./lookup-BaP5bI27.js";
2
3
  //#region src/compile/sql.ts
4
+ const MAX_PARAMS = 65535;
3
5
  const MAX_PAIRS = 50;
4
6
  function quoteIdent(name) {
5
7
  return `"${name.replaceAll("\"", "\"\"")}"`;
@@ -13,7 +15,34 @@ function dbColumn(table, app) {
13
15
  return meta.db;
14
16
  }
15
17
  function columnType(table, db) {
16
- return Object.values(table.columns).find((meta) => meta.db === db)?.type;
18
+ return lookupOf(table).byDb.get(db)?.[1].type;
19
+ }
20
+ /**
21
+ * `a > x or (a = x and b > y) or ...` as `(a, b) > (x, y)`, which an index
22
+ * on `(a, b)` serves. Both forms give the same result under SQL's
23
+ * three-valued logic, nulls included.
24
+ */
25
+ function rowComparison(condition) {
26
+ const steps = [];
27
+ for (const [index, item] of condition.items.entries()) {
28
+ const terms = index === 0 ? [item] : item.kind === "and" ? item.items : [];
29
+ if (terms.length !== index + 1) return null;
30
+ const step = terms[index];
31
+ if (step.kind !== "column" || step.op !== "gt" && step.op !== "lt") return null;
32
+ for (const [at, term] of terms.slice(0, index).entries()) {
33
+ const prev = steps[at];
34
+ if (term.kind !== "column" || term.op !== "eq" || term.column !== prev.column || !Object.is(term.value, prev.value)) return null;
35
+ }
36
+ steps.push(step);
37
+ }
38
+ const op = steps[0]?.op;
39
+ if (op !== "gt" && op !== "lt") return null;
40
+ if (steps.length < 2 || steps.some((step) => step.op !== op)) return null;
41
+ return {
42
+ columns: steps.map((step) => step.column),
43
+ op,
44
+ values: steps.map((step) => step.value)
45
+ };
17
46
  }
18
47
  var SqlCompiler = class {
19
48
  params = [];
@@ -35,6 +64,12 @@ var SqlCompiler = class {
35
64
  case "and":
36
65
  case "or": {
37
66
  if (condition.items.length === 0) return condition.kind === "and" ? "true" : "false";
67
+ const row = condition.kind === "or" ? rowComparison(condition) : null;
68
+ if (row) {
69
+ const columns = row.columns.map((name) => this.column(alias, name));
70
+ const values = row.values.map((value) => this.param(value));
71
+ return `(${columns.join(", ")}) ${row.op === "gt" ? ">" : "<"} (${values.join(", ")})`;
72
+ }
38
73
  const joiner = condition.kind === "and" ? " and " : " or ";
39
74
  return `(${condition.items.map((item) => this.condition(item, table, alias)).join(joiner)})`;
40
75
  }
@@ -85,6 +120,7 @@ var SqlCompiler = class {
85
120
  }
86
121
  }
87
122
  join(relation, source, sourceAlias, target, targetAlias) {
123
+ if (relation.columns.length !== relation.references.length) invalidRequest(`Relation to "${target.key}" has mismatched columns`);
88
124
  return relation.columns.map((column, index) => {
89
125
  const reference = relation.references[index];
90
126
  if (reference === void 0) invalidRequest(`Relation to "${target.key}" has mismatched columns`);
@@ -199,21 +235,20 @@ function compileSql(op) {
199
235
  never: true
200
236
  };
201
237
  const columns = insertColumns(op);
202
- let body;
203
- if (columns.length === 0) {
204
- if (op.rows.length > 1) invalidRequest("Cannot insert several rows without columns");
205
- body = "default values";
206
- } else {
207
- const values = op.rows.map((row) => `(${columns.map((column) => column in row ? compiler.param(row[column]) : op.defaultToNull ? "null" : "default").join(", ")})`);
208
- body = `(${columns.map(quoteIdent).join(", ")}) values ${values.join(", ")}`;
209
- }
210
- let conflict = "";
211
- if (op.onConflict) {
212
- const target = `(${op.onConflict.columns.map(quoteIdent).join(", ")})`;
213
- const updates = columns.map((column) => `${quoteIdent(column)} = excluded.${quoteIdent(column)}`);
214
- conflict = op.onConflict.action === "ignore" || updates.length === 0 ? ` on conflict ${target} do nothing` : ` on conflict ${target} do update set ${updates.join(", ")}`;
215
- }
216
- return mutation(`insert into ${from} ${body}${conflict}${returningRows(compiler, op, alias)}`, op.returning !== void 0, compiler.params);
238
+ const perChunk = Math.floor(MAX_PARAMS / Math.max(columns.length, 1));
239
+ if (op.rows.length <= perChunk) return insertPlan(compiler, from, alias, op, columns);
240
+ const [first, ...rest] = chunk(op.rows, perChunk).map((rows) => {
241
+ const own = new SqlCompiler();
242
+ const ownAlias = own.alias();
243
+ return insertPlan(own, `${tableRef(op.table)} as ${ownAlias}`, ownAlias, {
244
+ ...op,
245
+ rows
246
+ }, columns);
247
+ });
248
+ return {
249
+ ...first,
250
+ chunks: rest
251
+ };
217
252
  }
218
253
  case "update": {
219
254
  const simple = simplifyOrFalse(op.where);
@@ -238,6 +273,28 @@ function compileSql(op) {
238
273
  default: return op;
239
274
  }
240
275
  }
276
+ function chunk(items, size) {
277
+ const out = [];
278
+ for (let start = 0; start < items.length; start += size) out.push(items.slice(start, start + size));
279
+ return out;
280
+ }
281
+ function insertPlan(compiler, from, alias, op, columns) {
282
+ let body;
283
+ if (columns.length === 0) {
284
+ if (op.rows.length > 1) invalidRequest("Cannot insert several rows without columns");
285
+ body = "default values";
286
+ } else {
287
+ const values = op.rows.map((row) => `(${columns.map((column) => column in row ? compiler.param(row[column]) : op.defaultToNull ? "null" : "default").join(", ")})`);
288
+ body = `(${columns.map(quoteIdent).join(", ")}) values ${values.join(", ")}`;
289
+ }
290
+ let conflict = "";
291
+ if (op.onConflict) {
292
+ const target = `(${op.onConflict.columns.map(quoteIdent).join(", ")})`;
293
+ const updates = columns.map((column) => `${quoteIdent(column)} = excluded.${quoteIdent(column)}`);
294
+ conflict = op.onConflict.action === "ignore" || updates.length === 0 ? ` on conflict ${target} do nothing` : ` on conflict ${target} do update set ${updates.join(", ")}`;
295
+ }
296
+ return mutation(`insert into ${from} ${body}${conflict}${returningRows(compiler, op, alias)}`, op.returning !== void 0, compiler.params);
297
+ }
241
298
  function mutation(statement, returning, params) {
242
299
  if (returning) return {
243
300
  rows: {
@@ -1,5 +1,5 @@
1
- import { _ as readSession, a as ResolveAuthOptions, b as writeSession, d as CookieOptions, f as CookieRecord, g as parseCookies, h as applyCookieWrites, l as resolveAuth, m as StoredSession, n as AuthResolver, p as CookieWrite, r as AuthState, s as authContext, t as AuthResolution, u as AUTH_CACHE_HEADERS, v as serializeCookie, y as sessionCookieName } from "../resolve-CjHILk2w.js";
2
- import { n as toSession, t as AuthSession } from "../view-D1s0wa0T.js";
3
- import { n as MembershipClaim, r as hasEntitlement, t as EntitlementKey } from "../entitlements-Dng-ctuT.js";
4
- import { n as RefreshOutcome, r as refreshSession, t as RefreshOptions } from "../index-CG69s15v.js";
1
+ import { _ as readSession, a as ResolveAuthOptions, b as writeSession, d as CookieOptions, f as CookieRecord, g as parseCookies, h as applyCookieWrites, l as resolveAuth, m as StoredSession, n as AuthResolver, p as CookieWrite, r as AuthState, s as authContext, t as AuthResolution, u as AUTH_CACHE_HEADERS, v as serializeCookie, y as sessionCookieName } from "../resolve-BAqQcwMW.js";
2
+ import { n as toSession, t as AuthSession } from "../view-B64o81wp.js";
3
+ import { n as MembershipClaim, r as hasEntitlement, t as EntitlementKey } from "../entitlements-Dm-FHpNH.js";
4
+ import { n as RefreshOutcome, r as refreshSession, t as RefreshOptions } from "../refresh-BwYkyNOQ.js";
5
5
  export { AUTH_CACHE_HEADERS, type AuthResolution, type AuthResolver, type AuthSession, type AuthState, type CookieOptions, type CookieRecord, type CookieWrite, type EntitlementKey, type MembershipClaim, type RefreshOptions, type RefreshOutcome, type ResolveAuthOptions, type StoredSession, applyCookieWrites, authContext, hasEntitlement, parseCookies, readSession, refreshSession, resolveAuth, serializeCookie, sessionCookieName, toSession, writeSession };
package/dist/ssr/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { t as hasEntitlement } from "../entitlements-CTEBm7IB.js";
2
- import { c as applyCookieWrites, d as serializeCookie, f as sessionCookieName, i as authContext, l as parseCookies, m as refreshSession, o as resolveAuth, p as writeSession, s as AUTH_CACHE_HEADERS, u as readSession } from "../mfa-CpLfJSde.js";
3
- import { t as toSession } from "../view-aOYizTeE.js";
2
+ import { c as AUTH_CACHE_HEADERS, d as readSession, f as serializeCookie, h as refreshSession, i as authContext, l as applyCookieWrites, m as writeSession, p as sessionCookieName, s as resolveAuth, u as parseCookies } from "../mfa-byfjruR9.js";
3
+ import { t as toSession } from "../view-BrJI2LKp.js";
4
4
  export { AUTH_CACHE_HEADERS, applyCookieWrites, authContext, hasEntitlement, parseCookies, readSession, refreshSession, resolveAuth, serializeCookie, sessionCookieName, toSession, writeSession };
@@ -1,5 +1,5 @@
1
- import { n as dbError } from "./errors-Bl3rkOzo.js";
2
- import { i as ok, n as err } from "./result-DWXatkd6.js";
1
+ import { n as dbError } from "./errors-L0xK41y_.js";
2
+ import { i as ok, n as err } from "./result-Bj6yt33D.js";
3
3
  //#region src/core/standard.ts
4
4
  /** Validates with any Standard Schema (zod, valibot, arktype, ...). */
5
5
  async function validate(schema, value, label = "value") {
@@ -1,4 +1,4 @@
1
- import { o as Result } from "./result-CTkCZ6JA.js";
1
+ import { o as Result } from "./result-CqEsbgYs.js";
2
2
  import { StandardSchemaV1 as StandardSchemaV1$1 } from "@standard-schema/spec";
3
3
  //#region src/core/standard.d.ts
4
4
  /** Validates with any Standard Schema (zod, valibot, arktype, ...). */
@@ -1,17 +1,20 @@
1
- import { c as mapDbError, n as dbError } from "./errors-Bl3rkOzo.js";
2
- import { a as invalidRequest, n as simplifyOrFalse } from "./simplify-bwJpLnaS.js";
3
- import { i as ok, n as err, o as toDbError } from "./result-DWXatkd6.js";
1
+ import { c as mapDbError, n as dbError } from "./errors-L0xK41y_.js";
2
+ import { a as invalidRequest, n as simplifyOrFalse } from "./simplify-Cqvfr9dj.js";
3
+ import { i as temporalText } from "./temporal-BwshQk0W.js";
4
+ import { i as ok, n as err, o as toDbError } from "./result-Bj6yt33D.js";
4
5
  //#region src/compile/postgrest.ts
5
6
  function scalar(value) {
6
- if (value instanceof Date) return value.toISOString();
7
7
  if (typeof value === "string") return value;
8
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
9
+ const temporalValue = temporalText(value);
10
+ if (temporalValue !== void 0) return temporalValue;
8
11
  if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return String(value);
9
12
  if (value === null) return "null";
10
13
  return JSON.stringify(value);
11
14
  }
12
15
  /** Double-quotes a value for PostgREST lists and logic trees. */
13
16
  function quote(value) {
14
- return `"${scalar(value).replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
17
+ return `"${scalar(value).replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"`;
15
18
  }
16
19
  function list(values, open, close) {
17
20
  return `${open}${values.map(quote).join(",")}${close}`;
@@ -220,8 +223,7 @@ var PostgrestCompiler = class {
220
223
  path: `${aliasPath}.${column}`,
221
224
  operator: "is",
222
225
  value: "null"
223
- });
224
- this.filters.push({
226
+ }, {
225
227
  kind: "filter",
226
228
  path: `${aliasPath}.${column}`,
227
229
  operator: "not.is",
@@ -274,11 +276,21 @@ function filterEmbed(alias, condition, inner) {
274
276
  children: []
275
277
  };
276
278
  }
279
+ const columnTexts = /* @__PURE__ */ new WeakMap();
280
+ /** The rendered column list, cached per (shared, immutable) column array. */
281
+ function columnText(columns) {
282
+ let text = columnTexts.get(columns);
283
+ if (text === void 0) {
284
+ text = columns.map(({ alias, column, cast }) => {
285
+ const source = cast ? `${column}::${cast}` : column;
286
+ return alias === column ? source : `${alias}:${source}`;
287
+ }).join(",");
288
+ columnTexts.set(columns, text);
289
+ }
290
+ return text;
291
+ }
277
292
  function columnList(columns) {
278
- return columns.map(({ alias, column, cast }) => {
279
- const source = cast ? `${column}::${cast}` : column;
280
- return alias === column ? source : `${alias}:${source}`;
281
- });
293
+ return columns.length > 0 ? [columnText(columns)] : [];
282
294
  }
283
295
  /** `key:column.sum()::text`, PostgREST's aggregate syntax (PostgREST 12+). */
284
296
  function measureList(measures) {
@@ -297,6 +309,7 @@ function renderEmbeds(embeds) {
297
309
  });
298
310
  }
299
311
  function renderSelect(selection, embeds) {
312
+ if (!selection.aggregate && embeds.length === 0) return selection.columns.length > 0 ? columnText(selection.columns) : "*";
300
313
  const parts = [
301
314
  ...columnList(selection.columns),
302
315
  ...selection.aggregate ? aggregateList(selection.aggregate) : [],
@@ -349,8 +362,21 @@ function compilePostgrest(op) {
349
362
  //#region src/core/postgrest-executor.ts
350
363
  function scope(client, schema) {
351
364
  const loose = client;
352
- return schema !== "public" && loose.schema ? loose.schema(schema) : loose;
365
+ if (schema === "public" || !loose.schema) return loose;
366
+ let schemas = scopedClients.get(client);
367
+ if (!schemas) {
368
+ schemas = /* @__PURE__ */ new Map();
369
+ scopedClients.set(client, schemas);
370
+ }
371
+ let scoped = schemas.get(schema);
372
+ if (!scoped) {
373
+ scoped = loose.schema(schema);
374
+ schemas.set(schema, scoped);
375
+ }
376
+ return scoped;
353
377
  }
378
+ /** `schema()` builds a new client on every call; one per client and schema is enough. */
379
+ const scopedClients = /* @__PURE__ */ new WeakMap();
354
380
  function fromTable(client, schema, table) {
355
381
  return scope(client, schema).from(table);
356
382
  }
@@ -365,7 +391,7 @@ function applyFilters(builder, plan) {
365
391
  for (const filter of plan.filters) query = filter.kind === "filter" ? query.filter(filter.path, filter.operator, filter.value) : query.or(filter.expression, filter.referencedTable ? { referencedTable: filter.referencedTable } : {});
366
392
  return query;
367
393
  }
368
- function applyShape(builder, plan) {
394
+ function applyOrderAndLimits(builder, plan) {
369
395
  let query = builder;
370
396
  for (const order of plan.orders) {
371
397
  const options = { ascending: order.ascending };
@@ -384,7 +410,7 @@ function build(client, op, plan) {
384
410
  const options = {};
385
411
  if (op.count) options.count = op.count;
386
412
  if (op.head) options.head = true;
387
- let query = applyShape(applyFilters(op.source ? fromFunction(client, op.source, options).select(plan.select) : base.select(plan.select, options), plan), plan);
413
+ let query = applyOrderAndLimits(applyFilters(op.source ? fromFunction(client, op.source, options).select(plan.select) : base.select(plan.select, options), plan), plan);
388
414
  if (op.single === "one") query = query.single();
389
415
  if (op.single === "maybe") query = query.maybeSingle();
390
416
  return query;
@@ -1,5 +1,6 @@
1
- import { b as PermdockBucketPolicy } from "../types-C83v5SQz.js";
1
+ import { b as PermdockBucketPolicy } from "../types-DONv9SHN.js";
2
2
  import { n as StoragePath, t as PathIn } from "../path-Cv__-OTj.js";
3
+ import { t as PermdockCatalog } from "../permdock-sql-DImJULY-.js";
3
4
  import { n as TemplateValues, t as TemplateParams } from "../template-mbvlysOo.js";
4
- import { C as parseSize, S as fromStorageError, _ as TtlPreset, a as BucketDrift, b as UrlOptions, c as ReplaceOptions, d as StorageClient, f as StoredObject, g as TransformOptions, h as TTL, i as BucketConfig, l as ReplaceResult, m as SweepResult, n as Bucket, o as BucketPolicy, p as SweepOptions, r as BucketClient, s as ObjectTarget, t as ActualBucket, u as Reservation, v as UploadBody, x as defineBucket, y as UploadOptions } from "../index-DuP14VHo.js";
5
- export { ActualBucket, Bucket, BucketClient, BucketConfig, BucketDrift, BucketPolicy, ObjectTarget, type PathIn, type PermdockBucketPolicy, ReplaceOptions, ReplaceResult, Reservation, StorageClient, type StoragePath, StoredObject, SweepOptions, SweepResult, TTL, type TemplateParams, type TemplateValues, TransformOptions, TtlPreset, UploadBody, UploadOptions, UrlOptions, defineBucket, fromStorageError, parseSize };
5
+ import { C as fromStorageError, S as defineBucket, _ as TransformOptions, a as BucketConnectOptions, b as UploadOptions, c as ObjectTarget, d as Reservation, f as StorageClient, g as TTL, h as SweepResult, i as BucketConfig, l as ReplaceOptions, m as SweepOptions, n as Bucket, o as BucketDrift, p as StoredObject, r as BucketClient, s as BucketPolicy, t as ActualBucket, u as ReplaceResult, v as TtlPreset, w as parseSize, x as UrlOptions, y as UploadBody } from "../index-528Ugmyp.js";
6
+ export { type ActualBucket, type Bucket, type BucketClient, type BucketConfig, type BucketConnectOptions, type BucketDrift, type BucketPolicy, type ObjectTarget, type PathIn, type PermdockBucketPolicy, type PermdockCatalog, type ReplaceOptions, type ReplaceResult, type Reservation, type StorageClient, type StoragePath, type StoredObject, type SweepOptions, type SweepResult, TTL, type TemplateParams, type TemplateValues, type TransformOptions, type TtlPreset, type UploadBody, type UploadOptions, type UrlOptions, defineBucket, fromStorageError, parseSize };