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,5 @@
1
- import { A as SchemaMeta } from "./types-C83v5SQz.js";
2
- import { f as OpenApiParameter } from "./index-Bw1bwtC0.js";
1
+ import { A as SchemaMeta } from "./types-DONv9SHN.js";
2
+ import { p as OpenApiParameter } from "./index-BAy4tsAP.js";
3
3
  //#region src/openapi/index.d.ts
4
4
  type Json = Record<string, unknown>;
5
5
  type ResourceOperation = "list" | "get" | "create" | "update" | "delete";
@@ -9,7 +9,12 @@ interface ResourceOptions {
9
9
  /** Parameters for `list`, from `defineListQuery`. */
10
10
  readonly list?: {
11
11
  readonly openapi: readonly OpenApiParameter[];
12
+ readonly pagination?: "offset" | "cursor";
12
13
  };
14
+ /** Paging of the default list, as in `defineResource`. Defaults to `offset`. */
15
+ readonly pagination?: "offset" | "cursor";
16
+ /** Largest page of the default list. Defaults to 200. */
17
+ readonly maxPageSize?: number;
13
18
  /** Path of the collection. Defaults to `/<table>`. */
14
19
  readonly path?: string;
15
20
  readonly tag?: string;
@@ -63,13 +68,13 @@ declare const PROBLEM_SCHEMA: Json;
63
68
  * schemes and Problem Details errors.
64
69
  *
65
70
  * ```ts
66
- * const doc = createOpenApi(sb, {
71
+ * const doc = createOpenApi(betterSupabase, {
67
72
  * info: { title: 'CRM API', version: '1.0.0' },
68
73
  * resources: { customers: { list: customerList }, notes: { operations: ['list', 'get'] } },
69
74
  * });
70
75
  * ```
71
76
  */
72
- declare function createOpenApi(sb: {
77
+ declare function createOpenApi(betterSupabase: {
73
78
  readonly meta: SchemaMeta;
74
79
  }, options: OpenApiOptions): OpenApiDocument;
75
80
  //#endregion
@@ -0,0 +1,50 @@
1
+ import { A as SchemaMeta, s as ClaimsMeta } from "./types-DONv9SHN.js";
2
+ import { d as Generator } from "./config-C1CYcm6o.js";
3
+ //#region src/core/claims.d.ts
4
+ declare const DEFAULT_CLAIMS: ClaimsMeta;
5
+ /** Where the active tenant is read from: the top-level claim, then `app_metadata`. */
6
+ declare function tenantClaimPaths(tenant?: string): readonly [string, string];
7
+ //#endregion
8
+ //#region src/generators/shared.d.ts
9
+ /** What field planning reads: the metadata and the typed-jsonb config. */
10
+ interface SchemaSource {
11
+ readonly meta: SchemaMeta;
12
+ readonly config: {
13
+ readonly json: Readonly<Record<string, unknown>>;
14
+ };
15
+ }
16
+ //#endregion
17
+ //#region src/generators/json-schema.d.ts
18
+ interface JsonSchemaGeneratorOptions {
19
+ /** Output path relative to the project root. Defaults to `<output>.schema.json`. */
20
+ readonly output?: string;
21
+ /** `$id` of the document. */
22
+ readonly id?: string;
23
+ }
24
+ type JsonSchema = Record<string, unknown>;
25
+ /** JSON Schema (2020-12) `$defs` for every table: `customersRow`, `customersInsert`, ... */
26
+ declare function buildJsonSchema(input: SchemaSource, id?: string): JsonSchema;
27
+ /** Writes the JSON Schema document; `createOpenApi` reuses the same `$defs`. */
28
+ declare function jsonSchema(options?: JsonSchemaGeneratorOptions): Generator;
29
+ //#endregion
30
+ //#region src/generators/valibot.d.ts
31
+ interface ValibotGeneratorOptions {
32
+ /** Output path relative to the project root. Defaults to `<output>.valibot.ts`. */
33
+ readonly output?: string;
34
+ /** Schemas for typed jsonb columns: `{ 'customers.metadata': './schemas.ts#metadata' }`. */
35
+ readonly json?: Readonly<Record<string, string>>;
36
+ }
37
+ /** Valibot schemas for every table's Row, Insert and Update shape. */
38
+ declare function valibot(options?: ValibotGeneratorOptions): Generator;
39
+ //#endregion
40
+ //#region src/generators/zod.d.ts
41
+ interface ZodGeneratorOptions {
42
+ /** Output path relative to the project root. Defaults to `<output>.zod.ts`. */
43
+ readonly output?: string;
44
+ /** Schemas for typed jsonb columns: `{ 'customers.metadata': './schemas.ts#metadata' }`. */
45
+ readonly json?: Readonly<Record<string, string>>;
46
+ }
47
+ /** Zod 4 schemas for every table's Row, Insert and Update shape. */
48
+ declare function zod(options?: ZodGeneratorOptions): Generator;
49
+ //#endregion
50
+ export { JsonSchemaGeneratorOptions as a, DEFAULT_CLAIMS as c, valibot as i, tenantClaimPaths as l, zod as n, buildJsonSchema as o, ValibotGeneratorOptions as r, jsonSchema as s, ZodGeneratorOptions as t };
@@ -1,6 +1,7 @@
1
- import { A as SchemaMeta } from "./types-C83v5SQz.js";
2
- import { a as EventHub, s as MutationNotice } from "./events-DOt3nSO-.js";
3
- import { l as MutationKind } from "./plugin-C4TR9J0Z.js";
1
+ /// <reference lib="esnext.temporal" />
2
+ import { A as SchemaMeta } from "./types-DONv9SHN.js";
3
+ import { a as EventHub, s as MutationNotice } from "./events-B21UOhvP.js";
4
+ import { l as MutationKind } from "./plugin-bNhvJwRh.js";
4
5
  //#region src/events/index.d.ts
5
6
  /** A CloudEvents 1.0 event. Extension attributes are lowercase alphanumerics. */
6
7
  interface CloudEvent<T = unknown> {
@@ -26,7 +27,7 @@ interface CloudEventOptions {
26
27
  /** Replaces the `dev.better-supabase` type prefix. */
27
28
  readonly typePrefix?: string;
28
29
  readonly id?: () => string;
29
- readonly now?: () => Date;
30
+ readonly now?: () => Temporal.Instant;
30
31
  }
31
32
  /** Sends events somewhere: a queue, a bus, an outbox table, an HTTP endpoint. */
32
33
  interface EventSink {
@@ -50,7 +51,7 @@ interface ForwardOptions extends CloudEventOptions {
50
51
  * Sends a CloudEvent for every mutation to `sink`. Returns a function that
51
52
  * stops forwarding. Use an outbox (SQL kit) when events must not be lost.
52
53
  */
53
- declare function forwardMutations(sb: {
54
+ declare function forwardMutations(betterSupabase: {
54
55
  readonly events: EventHub;
55
56
  readonly meta: SchemaMeta;
56
57
  }, sink: EventSink, options: ForwardOptions): () => void;
@@ -1,6 +1,6 @@
1
- import { C as PrimaryKeyValue, L as UniqueWhere, N as TableKey, R as Update, _ as Insert, n as AnyModels, t as AnyFunctions } from "./types-C83v5SQz.js";
2
- import { _ as DbException } from "./result-CTkCZ6JA.js";
3
- import { C as FindExt, Ct as WhereInput, M as UpsertArgs, N as WriteArgs, S as DeleteExt, T as OffsetPageArgs, X as InferResult, Z as QuerySpec, _ as CursorPage, it as AggregateResult, j as UpdateArgs, k as Returned, l as CacheAdapter, lt as FindFirstArgs, rt as AggregateArgs, st as CountArgs, t as BetterSupabase, ut as FindManyArgs, v as CursorPageArgs, vt as Payload, w as OffsetPage, x as DeleteArgs, y as Db, yt as ReadArgs } from "./define-e3zI4_4g.js";
1
+ import { C as PrimaryKeyValue, L as UniqueWhere, N as TableKey, R as Update, g as Insert, n as AnyModels, t as AnyFunctions } from "./types-DONv9SHN.js";
2
+ import { _ as DbException } from "./result-CqEsbgYs.js";
3
+ import { C as FindExt, Ct as WhereInput, M as UpsertArgs, N as WriteArgs, S as DeleteExt, T as OffsetPageArgs, X as InferResult, Z as QuerySpec, _ as CursorPage, it as AggregateResult, j as UpdateArgs, k as Returned, l as CacheAdapter, lt as FindFirstArgs, rt as AggregateArgs, st as CountArgs, t as BetterSupabase, ut as FindManyArgs, v as CursorPageArgs, vt as Payload, w as OffsetPage, x as DeleteArgs, y as Db, yt as ReadArgs } from "./define-CRS2MRV3.js";
4
4
  import { DataTag, InfiniteData, QueryClient, SkipToken } from "@tanstack/query-core";
5
5
  //#region src/query/invalidate.d.ts
6
6
  /** Carried by every better-supabase query: the tables whose changes make it stale. */
@@ -14,7 +14,7 @@ interface BetterQueryMeta {
14
14
  */
15
15
  declare function invalidateTables(client: QueryClient, tables: readonly string[]): Promise<void>;
16
16
  //#endregion
17
- //#region src/query/index.d.ts
17
+ //#region src/query/queries.d.ts
18
18
  type QueryKeyOf<T> = DataTag<readonly unknown[], T, DbException>;
19
19
  type QueryFnOf<T> = ((context: {
20
20
  readonly signal: AbortSignal;
@@ -76,7 +76,7 @@ interface TableQueries<M extends AnyModels, T extends TableKey<M>, E> {
76
76
  type RpcArgsOf<F extends AnyFunctions, N extends keyof F> = F[N]["Args"];
77
77
  interface QueryHelpers<M extends AnyModels, F extends AnyFunctions> {
78
78
  /** Prefix of every better-supabase key. */
79
- readonly key: readonly ["bs"];
79
+ readonly $key: readonly ["bs"];
80
80
  /** Query options for a `QuerySpec`, for example one sent from a Server Component. */
81
81
  $spec<S extends QuerySpec<TableKey<M>>>(spec: S | SkipToken): QueryOptionsOf<InferResult<S>>;
82
82
  /** Fetches a spec into `queryClient` for server rendering and hydration. */
@@ -85,11 +85,11 @@ interface QueryHelpers<M extends AnyModels, F extends AnyFunctions> {
85
85
  $rpc<N extends Extract<keyof F, string>>(name: N, args?: RpcArgsOf<F, N> | SkipToken, options?: {
86
86
  readonly tables?: readonly TableKey<M>[];
87
87
  }): QueryOptionsOf<F[N]["Returns"]>;
88
- /** Mutation options for a database function; invalidates what `sb.defineRpc` declared. */
88
+ /** Mutation options for a database function; invalidates what `betterSupabase.defineRpc` declared. */
89
89
  $rpcMutation<N extends Extract<keyof F, string>>(name: N): MutationOptionsOf<RpcArgsOf<F, N>, F[N]["Returns"]>;
90
90
  }
91
- type Queries<M extends AnyModels, E, F extends AnyFunctions = AnyFunctions> = { readonly [T in TableKey<M>]: TableQueries<M, T, E>; } & QueryHelpers<M, F>;
92
- interface CreateQueriesOptions {
91
+ type BetterQueries<M extends AnyModels, E, F extends AnyFunctions = AnyFunctions> = { readonly [T in TableKey<M>]: TableQueries<M, T, E>; } & QueryHelpers<M, F>;
92
+ interface QueriesOptions {
93
93
  /**
94
94
  * `staleTime` for every query option. Set it above zero when rendering on
95
95
  * the server so hydrated data isn't refetched on mount.
@@ -104,14 +104,14 @@ interface CreateQueriesOptions {
104
104
  * changed table.
105
105
  *
106
106
  * ```ts
107
- * const q = createQueries(sb, () => browser.db);
107
+ * const q = createQueries(betterSupabase, () => bs.db);
108
108
  * const { data } = useQuery(q.customers.findMany({ select: ['id', 'name'] }));
109
109
  * ```
110
110
  */
111
- declare function createQueries<M extends AnyModels, D, F extends AnyFunctions, E>(sb: BetterSupabase<M, D, F, E>, db: Db<M, F, E, unknown> | (() => Db<M, F, E, unknown>), options?: CreateQueriesOptions): Queries<M, E, F>;
111
+ declare function createQueries<M extends AnyModels, D, F extends AnyFunctions, E>(betterSupabase: BetterSupabase<M, D, F, E>, db: Db<M, F, E, unknown> | (() => Db<M, F, E, unknown>), options?: QueriesOptions): BetterQueries<M, E, F>;
112
112
  /** Invalidates every query that read a table in the target. */
113
113
  declare function queryCache(client: QueryClient): CacheAdapter;
114
- /** Invalidates affected queries for every mutation and declared RPC `sb` performs in this runtime. */
115
- declare function invalidateOnMutation<M extends AnyModels, D, F extends AnyFunctions, E>(sb: BetterSupabase<M, D, F, E>, client: QueryClient): () => void;
114
+ /** Invalidates affected queries for every mutation and declared RPC `betterSupabase` performs in this runtime. */
115
+ declare function invalidateOnMutation<M extends AnyModels, D, F extends AnyFunctions, E>(betterSupabase: BetterSupabase<M, D, F, E>, client: QueryClient): () => void;
116
116
  //#endregion
117
- export { QueryHelpers as a, TableQueries as c, queryCache as d, BetterQueryMeta as f, Queries as i, createQueries as l, InfiniteOptionsOf as n, QueryKeyOf as o, invalidateTables as p, MutationOptionsOf as r, QueryOptionsOf as s, CreateQueriesOptions as t, invalidateOnMutation as u };
117
+ export { QueryHelpers as a, TableQueries as c, queryCache as d, BetterQueryMeta as f, QueriesOptions as i, createQueries as l, InfiniteOptionsOf as n, QueryKeyOf as o, invalidateTables as p, MutationOptionsOf as r, QueryOptionsOf as s, BetterQueries as t, invalidateOnMutation as u };
@@ -1,10 +1,10 @@
1
- import { n as AnyModels, t as AnyFunctions } from "./types-C83v5SQz.js";
2
- import { t as BetterSupabase, y as Db } from "./define-e3zI4_4g.js";
1
+ import { n as AnyModels, t as AnyFunctions } from "./types-DONv9SHN.js";
2
+ import { t as BetterSupabase, y as Db } from "./define-CRS2MRV3.js";
3
3
  import { c as PublicEnv } from "./index-Dy6kuF0P.js";
4
- import { i as Queries } from "./index-K-3WM2Hp.js";
4
+ import { t as BetterQueries } from "./index-DFmOpBGC.js";
5
5
  import { SupabaseClient } from "@supabase/supabase-js";
6
6
  //#region src/client/index.d.ts
7
- interface BrowserOptions {
7
+ interface ClientOptions {
8
8
  /** URL and publishable key. Not needed when `client` is given. */
9
9
  readonly env?: PublicEnv;
10
10
  /** Bring your own supabase-js client (React Native, custom storage). */
@@ -34,29 +34,29 @@ type AuthSnapshot = {
34
34
  readonly user: AuthUser;
35
35
  readonly claims: Readonly<Record<string, unknown>>;
36
36
  };
37
- interface BrowserAuth {
37
+ interface ClientAuth {
38
38
  readonly current: () => AuthSnapshot;
39
39
  /** `useSyncExternalStore`-compatible. */
40
40
  readonly subscribe: (listener: () => void) => () => void;
41
41
  }
42
- interface BetterBrowser<M extends AnyModels, F extends AnyFunctions, E, C = unknown, P = unknown> {
43
- /** The definition the browser was created from (schema metadata, specs, live queries). */
44
- readonly sb: BetterSupabase<M, unknown, F, E, C, P>;
42
+ interface BetterClient<M extends AnyModels, F extends AnyFunctions, E, C = unknown, P = unknown> {
43
+ /** The definition the client was created from (schema metadata, specs, live queries). */
44
+ readonly betterSupabase: BetterSupabase<M, unknown, F, E, C, P>;
45
45
  readonly supabase: SupabaseClient;
46
46
  /** Repositories with the current session's actor and claims. */
47
47
  readonly db: Db<M, F, E, SupabaseClient>;
48
48
  /** TanStack Query option factories over `db`. */
49
- readonly queries: Queries<M, E, F>;
50
- readonly auth: BrowserAuth;
49
+ readonly queries: BetterQueries<M, E, F>;
50
+ readonly auth: ClientAuth;
51
51
  }
52
52
  /**
53
53
  * The browser side: a supabase-js client, repositories that follow the
54
54
  * session, TanStack Query options and an auth store for UI state.
55
55
  *
56
56
  * ```ts
57
- * export const browser = createBrowser(sb, { env: { url, publishableKey } });
57
+ * export const bs = createClient(betterSupabase, { env: { url, publishableKey } });
58
58
  * ```
59
59
  */
60
- declare function createBrowser<M extends AnyModels, D, F extends AnyFunctions, E, C = unknown, P = unknown>(sb: BetterSupabase<M, D, F, E, C, P>, options?: BrowserOptions): BetterBrowser<M, F, E, C, P>;
60
+ declare function createClient$1<M extends AnyModels, D, F extends AnyFunctions, E, C = unknown, P = unknown>(betterSupabase: BetterSupabase<M, D, F, E, C, P>, options?: ClientOptions): BetterClient<M, F, E, C, P>;
61
61
  //#endregion
62
- export { BrowserOptions as a, BrowserAuth as i, AuthUser as n, createBrowser as o, BetterBrowser as r, AuthSnapshot as t };
62
+ export { ClientOptions as a, ClientAuth as i, AuthUser as n, createClient$1 as o, BetterClient as r, AuthSnapshot as t };
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { A as SchemaMeta, C as PrimaryKeyValue, D as Relations, E as RelationShape, F as UniqueConstraint, I as UniqueKeyName, L as UniqueWhere, M as TableFlags, N as TableKey, O as Row, P as TableMeta, R as Update, S as PrimaryKeyColumn, T as RelationMeta, _ as Insert, a as Casing, b as PermdockBucketPolicy, c as Codec, d as Flags, f as FlagsShape, g as FunctionsOf, h as FunctionShape, i as BucketPolicyName, j as Simplify, k as Schema, l as ColumnMeta, m as FunctionMeta, n as AnyModels, o as CheckConstraint, p as ForeignKeyConstraint, r as BucketMeta, s as ClaimsMeta, t as AnyFunctions, u as DatabaseOf, v as ModelShape, w as RealtimeTableMeta, x as PermdockTopicPolicy, y as ModelsOf } from "./types-C83v5SQz.js";
2
- import { C as and, E as or, S as UpdateOp, T as not, _ as OrderTerm, a as AggregateFn, b as SelectOp, c as Condition, d as FunctionSource, f as Include, g as Operation, h as MutationOp, i as RpcContext, l as CountMode, m as Measure, n as ExecuteResult, o as Aggregation, p as InsertOp, r as Executor, s as ColumnOp, t as ExecuteContext, u as DeleteOp, v as Quantifier, w as column, x as Selection, y as SelectColumn } from "./executor-CGdNQ27g.js";
3
- import { C as isConflict, D as statusOf, E as mapDbError, S as isCheck, T as isForeignKey, _ as DbException, a as Ok, b as ValidationIssue, c as err, d as toBetterResult, f as toDbError, g as DbErrorOf, h as DbErrorKinds, i as Err, l as fromBetterResult, m as DbErrorKind, n as BetterResultApi, o as Result, p as DbError, r as BetterResultShape, t as AsyncResult, u as ok, v as ErrorMapper, w as isDbError, x as dbError, y as RawDbError } from "./result-CTkCZ6JA.js";
4
- import { a as EventHub, c as QueryEvent, d as LogFields, f as Logger, i as EventHandler, l as RefreshEvent, m as silentLogger, n as BetterSupabaseEvents, o as EventName, p as consoleLogger, r as ErrorEvent, s as MutationNotice, t as AuthEvent, u as RpcNotice } from "./events-DOt3nSO-.js";
5
- import { $ as Specs, A as RpcOptions, B as ReadSet, C as FindExt, Ct as WhereInput, D as Repository, E as PageOf, F as EMPTY_STATS, G as ReadSetParams, H as ReadSetParamType, I as StatsRecorder, J as isReadSet, K as ReadSetResult, L as recordStats, M as UpsertArgs, N as WriteArgs, O as RepositoryOf, P as DbStats, Q as ReadMethod, R as SearchArgs, S as DeleteExt, St as SortDirection, T as OffsetPageArgs, U as ReadSetParamTypes, V as ReadSetOptions, W as ReadSetParamValue, X as InferResult, Y as readSetTables, Z as QuerySpec, _ as CursorPage, _t as OrderByInput, a as defineSupabase, at as AggregateRow, b as DbHelpers, bt as RelationMeasureArg, c as postgrestExecutor, ct as FieldFilter, d as MemoryCache, dt as IncludeArg, et as TableSpecs, f as cacheTargetOf, ft as IncludeArgs, g as ConflictTarget, gt as OrderByArg, h as rpcCacheTargets, ht as NumericMeasureArg, i as RpcDefinition, it as AggregateResult, j as UpdateArgs, k as Returned, l as CacheAdapter, lt as FindFirstArgs, m as rowKey, mt as MeasureKey, n as ConnectOptions, nt as specTables, o as PostgrestClientLike, ot as CountArg, p as memoryCache, pt as MeasureArg, q as defineReadSet, r as DefineSupabaseOptions, rt as AggregateArgs, s as explainPostgrest, st as CountArgs, t as BetterSupabase, tt as isQuerySpec, u as CacheTarget, ut as FindManyArgs, v as CursorPageArgs, vt as Payload, w as OffsetPage, x as DeleteArgs, xt as SelectArg, y as Db, yt as ReadArgs, z as InferReadSetParams } from "./define-e3zI4_4g.js";
6
- import { _ as definePlugin, a as ExtensionOf, c as MutationEvent, d as PLUGIN_API_VERSION, f as Plugin, g as WithExtension, h as RequestContext, i as CallOptions, l as MutationKind, m as RepositoryExtension, n as AnyPlugin, o as HasFlag, p as RepositoryApi, r as ApplyExtension, s as HookArgs, t as Actor, u as NoExtension } from "./plugin-C4TR9J0Z.js";
7
- import { n as validate, t as StandardSchemaV1 } from "./standard-CyhRzctb.js";
8
- import { a as compilePostgrest, i as PostgrestPlan, n as PlanLimit, r as PlanOrder, t as PlanFilter } from "./postgrest-cAEQ_IQN.js";
1
+ import { A as SchemaMeta, C as PrimaryKeyValue, D as Relations, E as RelationTypes, F as UniqueConstraint, I as UniqueKeyName, L as UniqueWhere, M as TableFlags, N as TableKey, O as Row, P as TableMeta, R as Update, S as PrimaryKeyColumn, T as RelationMeta, _ as ModelFlags, a as Casing, b as PermdockBucketPolicy, c as Codec, d as Flags, f as ForeignKeyConstraint, g as Insert, h as FunctionsOf, i as BucketPolicyName, j as Simplify, k as Schema, l as ColumnMeta, m as FunctionTypes, n as AnyModels, o as CheckConstraint, p as FunctionMeta, r as BucketMeta, s as ClaimsMeta, t as AnyFunctions, u as DatabaseOf, v as ModelTypes, w as RealtimeTableMeta, x as PermdockTopicPolicy, y as ModelsOf } from "./types-DONv9SHN.js";
2
+ import { C as and, E as or, S as UpdateOp, T as not, _ as OrderTerm, a as AggregateFn, b as SelectOp, c as Condition, d as FunctionSource, f as Include, g as Operation, h as MutationOp, i as RpcContext, l as CountMode, m as Measure, n as ExecuteResult, o as Aggregation, p as InsertOp, r as Executor, s as ColumnOp, t as ExecuteContext, u as DeleteOp, v as Quantifier, w as column, x as Selection, y as SelectColumn } from "./executor-B5IoUxLE.js";
3
+ import { C as isConflict, D as statusOf, E as mapDbError, S as isCheck, T as isForeignKey, _ as DbException, a as Ok, b as ValidationIssue, c as err, d as toBetterResult, f as toDbError, g as DbErrorOf, h as DbErrorKinds, i as Err, l as fromBetterResult, m as DbErrorKind, n as BetterResultApi, o as Result, p as DbError, r as BetterResultValue, t as AsyncResult, u as ok, v as ErrorMapper, w as isDbError, x as dbError, y as RawDbError } from "./result-CqEsbgYs.js";
4
+ import { a as EventHub, c as QueryEvent, d as LogFields, f as Logger, i as EventHandler, l as RefreshEvent, m as silentLogger, n as BetterSupabaseEvents, o as EventName, p as consoleLogger, r as ErrorEvent, s as MutationNotice, t as AuthEvent, u as RpcNotice } from "./events-B21UOhvP.js";
5
+ import { $ as Specs, A as RpcOptions, B as ReadSet, C as FindExt, Ct as WhereInput, D as Repository, E as PageOf, F as EMPTY_STATS, G as ReadSetParams, H as ReadSetParamType, I as StatsRecorder, J as isReadSet, K as ReadSetResult, L as recordStats, M as UpsertArgs, N as WriteArgs, O as RepositoryOf, P as DbStats, Q as ReadMethod, R as SearchArgs, S as DeleteExt, St as SortDirection, T as OffsetPageArgs, U as ReadSetParamTypes, V as ReadSetOptions, W as ReadSetParamValue, X as InferResult, Y as readSetTables, Z as QuerySpec, _ as CursorPage, _t as OrderByInput, a as defineSupabase, at as AggregateRow, b as DbHelpers, bt as RelationMeasureArg, c as postgrestExecutor, ct as FieldFilter, d as MemoryCache, dt as IncludeArg, et as TableSpecs, f as cacheTargetOf, ft as IncludeArgs, g as ConflictTarget, gt as OrderByArg, h as rpcCacheTargets, ht as NumericMeasureArg, i as SupabaseOptions, it as AggregateResult, j as UpdateArgs, k as Returned, l as CacheAdapter, lt as FindFirstArgs, m as rowKey, mt as MeasureKey, n as ConnectOptions, nt as specTables, o as PostgrestClientLike, ot as CountArg, p as memoryCache, pt as MeasureArg, q as defineReadSet, r as RpcDefinition, rt as AggregateArgs, s as explainPostgrest, st as CountArgs, t as BetterSupabase, tt as isQuerySpec, u as CacheTarget, ut as FindManyArgs, v as CursorPageArgs, vt as Payload, w as OffsetPage, x as DeleteArgs, xt as SelectArg, y as Db, yt as ReadArgs, z as InferReadSetParams } from "./define-CRS2MRV3.js";
6
+ import { _ as definePlugin, a as ExtensionOf, c as MutationEvent, d as PLUGIN_API_VERSION, f as Plugin, g as WithExtension, h as RequestContext, i as CallOptions, l as MutationKind, m as RepositoryExtension, n as AnyPlugin, o as HasFlag, p as RepositoryApi, r as ApplyExtension, s as HookArgs, t as Actor, u as NoExtension } from "./plugin-bNhvJwRh.js";
7
+ import { n as validate, t as StandardSchemaV1 } from "./standard-BsaCYQJc.js";
8
+ import { a as compilePostgrest, i as PostgrestPlan, n as PlanLimit, r as PlanOrder, t as PlanFilter } from "./postgrest-Bc-0Xw62.js";
9
9
  import { n as StoragePath } from "./path-Cv__-OTj.js";
10
- import { n as postgrestCompiler, t as Compiler } from "./compiler-CZ9nIuqy.js";
11
- import { a as ProblemResponseOptions, c as problemResponse, i as ProblemOptions, l as toProblem, n as PROBLEM_TYPE_BASE, o as fromProblem, r as ProblemDetails, s as isProblem, t as PROBLEM_CONTENT_TYPE } from "./problem-DlgB0lYl.js";
10
+ import { n as postgrestCompiler, t as Compiler } from "./compiler-DB3aSFOA.js";
11
+ import { a as ProblemResponseOptions, c as problemResponse, i as ProblemOptions, l as toProblem, n as PROBLEM_TYPE_BASE, o as fromProblem, r as ProblemDetails, s as isProblem, t as PROBLEM_CONTENT_TYPE } from "./problem-U8UEKccv.js";
12
12
  import { t as SPEC_PINS } from "./spec-pins-CqorWDnO.js";
13
13
  //#region src/core/define-repository.d.ts
14
14
  /** Adds `Methods` to the repository of `Table` only. */
@@ -20,14 +20,14 @@ interface TableRepositoryExtension<Table extends string, Methods> extends Reposi
20
20
  * repository at call time, with every other plugin's methods.
21
21
  *
22
22
  * ```ts
23
- * const customers = defineRepository(sb, 'customers', (base) => ({
23
+ * const customers = defineRepository(betterSupabase, 'customers', (base) => ({
24
24
  * active: () => base.findMany({ where: { status: 'active' } }),
25
25
  * }));
26
- * export const app = sb.use(customers);
26
+ * export const app = betterSupabase.use(customers);
27
27
  * await app.connect(client).customers.active();
28
28
  * ```
29
29
  */
30
- export declare function defineRepository<M extends AnyModels, D, F extends AnyFunctions, E, const Table extends TableKey<M>, Methods extends object>(sb: BetterSupabase<M, D, F, E>, table: Table, build: (base: RepositoryOf<M, Table, E>) => Methods): Plugin<`repository:${Table}`, TableRepositoryExtension<Table, Methods>>;
30
+ export declare function defineRepository<M extends AnyModels, D, F extends AnyFunctions, E, const Table extends TableKey<M>, Methods extends object>(betterSupabase: BetterSupabase<M, D, F, E>, table: Table, build: (base: RepositoryOf<M, Table, E>) => Methods): Plugin<`repository:${Table}`, TableRepositoryExtension<Table, Methods>>;
31
31
  //#endregion
32
32
  //#region src/ir/tables.d.ts
33
33
  /**
@@ -41,7 +41,7 @@ export declare function touchedTables(op: Operation): string[];
41
41
  * plus every table whose foreign key cascades or sets a value on delete,
42
42
  * followed through chains of cascades.
43
43
  */
44
- export declare function invalidationTargets(meta: SchemaMeta, table: string): string[];
44
+ export declare function invalidationTargets(meta: SchemaMeta, table: string): readonly string[];
45
45
  //#endregion
46
46
  //#region src/core/cursor.d.ts
47
47
  /** Opaque, URL-safe keyset cursor. */
@@ -71,10 +71,10 @@ type EnrichDatabase<D, O> = { [S in keyof D]: S extends keyof O ? EnrichSchema<D
71
71
  export declare function escapeLike(value: string): string;
72
72
  //#endregion
73
73
  //#region src/ir/codec.d.ts
74
- /** Wire form of an app value: `Date` to ISO text, `bigint` to decimal text. */
74
+ /** Wire form of an app value: Temporal values to ISO text, `bigint` to decimal text. */
75
75
  export declare function encodeValue(value: unknown): unknown;
76
76
  /** Applies column codecs to returned rows, including embedded relations. */
77
- export declare function decodeRows(selection: Selection | undefined, rows: readonly Record<string, unknown>[]): Record<string, unknown>[];
77
+ export declare function decodeRows(selection: Selection | undefined, rows: readonly Record<string, unknown>[], checked?: boolean): Record<string, unknown>[];
78
78
  //#endregion
79
79
  //#region src/ir/scope.d.ts
80
80
  /** Returns the filter that always applies to rows of `table`, if any. */
@@ -107,4 +107,4 @@ export declare function toCamel(name: string): string;
107
107
  /** `firstName` to `first_name`. */
108
108
  export declare function toSnake(name: string): string;
109
109
  //#endregion
110
- export { type Actor, type AggregateArgs, type AggregateFn, type AggregateResult, type AggregateRow, type Aggregation, type AnyFunctions, type AnyModels, type AnyPlugin, type ApplyExtension, AsyncResult, type AuthEvent, type BetterResultApi, type BetterResultShape, BetterSupabase, type BetterSupabaseEvents, type BucketMeta, type BucketPolicyName, type CacheAdapter, type CacheTarget, type CallOptions, type Casing, type CheckConstraint, type ClaimsMeta, type Codec, type ColumnMeta, type ColumnOp, type Compiler, type Condition, type ConflictTarget, type ConnectOptions, type CountArg, type CountArgs, type CountMode, type CursorPage, type CursorPageArgs, type DatabaseOf, type Db, type DbError, type DbErrorKind, type DbErrorKinds, type DbErrorOf, DbException, type DbHelpers, type DbStats, type DefineSupabaseOptions, type DeleteArgs, type DeleteExt, type DeleteOp, EMPTY_STATS, type EnrichDatabase, type Err, type ErrorEvent, type ErrorMapper, type EventHandler, EventHub, type EventName, type ExecuteContext, type ExecuteResult, type Executor, type ExtensionOf, type FieldFilter, type FindExt, type FindFirstArgs, type FindManyArgs, type Flags, type FlagsShape, type ForeignKeyConstraint, type FunctionMeta, type FunctionShape, type FunctionSource, type FunctionsOf, type HasFlag, type HookArgs, type Include, type IncludeArg, type IncludeArgs, type InferReadSetParams, type InferResult, type Insert, type InsertOp, type LogFields, type Logger, type Measure, type MeasureArg, type MeasureKey, type MemoryCache, type ModelShape, type ModelsOf, type MutationEvent, type MutationKind, type MutationNotice, type MutationOp, type NoExtension, type NumericMeasureArg, type OffsetPage, type OffsetPageArgs, type Ok, type Operation, type OrderByArg, type OrderByInput, type OrderTerm, PLUGIN_API_VERSION, PROBLEM_CONTENT_TYPE, PROBLEM_TYPE_BASE, type PageOf, type Payload, type PermdockBucketPolicy, type PermdockTopicPolicy, type PlanFilter, type PlanLimit, type PlanOrder, type Plugin, type PostgrestClientLike, type PostgrestPlan, type PrimaryKeyColumn, type PrimaryKeyValue, type ProblemDetails, type ProblemOptions, type ProblemResponseOptions, type Quantifier, type QueryEvent, type QuerySpec, type RawDbError, type ReadArgs, type ReadMethod, type ReadSet, type ReadSetOptions, type ReadSetParamType, type ReadSetParamTypes, type ReadSetParamValue, type ReadSetParams, type ReadSetResult, type RealtimeTableMeta, type RefreshEvent, type RelationMeasureArg, type RelationMeta, type RelationShape, type Relations, type Repository, type RepositoryApi, type RepositoryExtension, type RepositoryOf, type RequestContext, type Result, type Returned, type Row, type RpcContext, type RpcDefinition, type RpcNotice, type RpcOptions, SPEC_PINS, type Schema, type SchemaMeta, type ScopeFor, type SearchArgs, type SelectArg, type SelectColumn, type SelectOp, type Selection, type Simplify, type SortDirection, type Specs, type StandardSchemaV1, StatsRecorder, type StoragePath, type TableFlags, type TableKey, type TableMeta, type TableRepositoryExtension, type TableSpecs, type UniqueConstraint, type UniqueKeyName, type UniqueWhere, type Update, type UpdateArgs, type UpdateOp, type UpsertArgs, type ValidationIssue, type WhereInput, type WithExtension, type WriteArgs, and, cacheTargetOf, column, compilePostgrest, consoleLogger, dbError, definePlugin, defineReadSet, defineSupabase, err, explainPostgrest, fromBetterResult, fromProblem, isCheck, isConflict, isDbError, isForeignKey, isProblem, isQuerySpec, isReadSet, mapDbError, memoryCache, not, ok, or, postgrestCompiler, postgrestExecutor, problemResponse, readSetTables, recordStats, rowKey, rpcCacheTargets, silentLogger, specTables, statusOf, toBetterResult, toDbError, toProblem, validate };
110
+ export { type Actor, type AggregateArgs, type AggregateFn, type AggregateResult, type AggregateRow, type Aggregation, type AnyFunctions, type AnyModels, type AnyPlugin, type ApplyExtension, AsyncResult, type AuthEvent, type BetterResultApi, type BetterResultValue, BetterSupabase, type BetterSupabaseEvents, type BucketMeta, type BucketPolicyName, type CacheAdapter, type CacheTarget, type CallOptions, type Casing, type CheckConstraint, type ClaimsMeta, type Codec, type ColumnMeta, type ColumnOp, type Compiler, type Condition, type ConflictTarget, type ConnectOptions, type CountArg, type CountArgs, type CountMode, type CursorPage, type CursorPageArgs, type DatabaseOf, type Db, type DbError, type DbErrorKind, type DbErrorKinds, type DbErrorOf, DbException, type DbHelpers, type DbStats, type DeleteArgs, type DeleteExt, type DeleteOp, EMPTY_STATS, type EnrichDatabase, type Err, type ErrorEvent, type ErrorMapper, type EventHandler, EventHub, type EventName, type ExecuteContext, type ExecuteResult, type Executor, type ExtensionOf, type FieldFilter, type FindExt, type FindFirstArgs, type FindManyArgs, type Flags, type ForeignKeyConstraint, type FunctionMeta, type FunctionSource, type FunctionTypes, type FunctionsOf, type HasFlag, type HookArgs, type Include, type IncludeArg, type IncludeArgs, type InferReadSetParams, type InferResult, type Insert, type InsertOp, type LogFields, type Logger, type Measure, type MeasureArg, type MeasureKey, type MemoryCache, type ModelFlags, type ModelTypes, type ModelsOf, type MutationEvent, type MutationKind, type MutationNotice, type MutationOp, type NoExtension, type NumericMeasureArg, type OffsetPage, type OffsetPageArgs, type Ok, type Operation, type OrderByArg, type OrderByInput, type OrderTerm, PLUGIN_API_VERSION, PROBLEM_CONTENT_TYPE, PROBLEM_TYPE_BASE, type PageOf, type Payload, type PermdockBucketPolicy, type PermdockTopicPolicy, type PlanFilter, type PlanLimit, type PlanOrder, type Plugin, type PostgrestClientLike, type PostgrestPlan, type PrimaryKeyColumn, type PrimaryKeyValue, type ProblemDetails, type ProblemOptions, type ProblemResponseOptions, type Quantifier, type QueryEvent, type QuerySpec, type RawDbError, type ReadArgs, type ReadMethod, type ReadSet, type ReadSetOptions, type ReadSetParamType, type ReadSetParamTypes, type ReadSetParamValue, type ReadSetParams, type ReadSetResult, type RealtimeTableMeta, type RefreshEvent, type RelationMeasureArg, type RelationMeta, type RelationTypes, type Relations, type Repository, type RepositoryApi, type RepositoryExtension, type RepositoryOf, type RequestContext, type Result, type Returned, type Row, type RpcContext, type RpcDefinition, type RpcNotice, type RpcOptions, SPEC_PINS, type Schema, type SchemaMeta, type ScopeFor, type SearchArgs, type SelectArg, type SelectColumn, type SelectOp, type Selection, type Simplify, type SortDirection, type Specs, type StandardSchemaV1, StatsRecorder, type StoragePath, type SupabaseOptions, type TableFlags, type TableKey, type TableMeta, type TableRepositoryExtension, type TableSpecs, type UniqueConstraint, type UniqueKeyName, type UniqueWhere, type Update, type UpdateArgs, type UpdateOp, type UpsertArgs, type ValidationIssue, type WhereInput, type WithExtension, type WriteArgs, and, cacheTargetOf, column, compilePostgrest, consoleLogger, dbError, definePlugin, defineReadSet, defineSupabase, err, explainPostgrest, fromBetterResult, fromProblem, isCheck, isConflict, isDbError, isForeignKey, isProblem, isQuerySpec, isReadSet, mapDbError, memoryCache, not, ok, or, postgrestCompiler, postgrestExecutor, problemResponse, readSetTables, recordStats, rowKey, rpcCacheTargets, silentLogger, specTables, statusOf, toBetterResult, toDbError, toProblem, validate };
package/dist/index.js CHANGED
@@ -1,33 +1,32 @@
1
- import { a as isConflict, c as mapDbError, i as isCheck, l as statusOf, n as dbError, o as isDbError, s as isForeignKey, t as DbException } from "./errors-Bl3rkOzo.js";
2
- import { i as escapeLike, l as defineSchema, o as decodeRows, s as encodeValue, t as simplify, u as tableMeta } from "./simplify-bwJpLnaS.js";
1
+ import { a as isConflict, c as mapDbError, i as isCheck, l as statusOf, n as dbError, o as isDbError, s as isForeignKey, t as DbException } from "./errors-L0xK41y_.js";
2
+ import { i as escapeLike, l as defineSchema, o as decodeRows, s as encodeValue, t as simplify, u as tableMeta } from "./simplify-Cqvfr9dj.js";
3
3
  import { i as or, n as column, r as not, t as and } from "./types-6cYK9pbJ.js";
4
- import { a as toBetterResult, i as ok, n as err, o as toDbError, r as fromBetterResult, t as AsyncResult } from "./result-DWXatkd6.js";
5
- import { a as EventHub, c as rowKey, i as encodeCursor, l as rpcCacheTargets, n as defineSupabase, o as cacheTargetOf, r as decodeCursor, s as memoryCache, t as BetterSupabase } from "./define-BXMYD9AY.js";
6
- import { n as touchedTables, t as invalidationTargets } from "./tables-rZxRxNPW.js";
4
+ import { a as toBetterResult, i as ok, n as err, o as toDbError, r as fromBetterResult, t as AsyncResult } from "./result-Bj6yt33D.js";
5
+ import { a as EventHub, c as rowKey, i as encodeCursor, l as rpcCacheTargets, n as defineSupabase, o as cacheTargetOf, r as decodeCursor, s as memoryCache, t as BetterSupabase } from "./define-Bh0AqTik.js";
6
+ import { n as touchedTables, t as invalidationTargets } from "./tables-Cb-3_VWc.js";
7
7
  import { n as silentLogger, t as consoleLogger } from "./logger-glM28NVN.js";
8
8
  import { n as definePlugin, t as PLUGIN_API_VERSION } from "./plugin-BqR6wKMB.js";
9
- import { a as postgrestExecutor, i as explainPostgrest, n as StatsRecorder, o as compilePostgrest, r as recordStats, t as EMPTY_STATS } from "./stats-C5W-rBfR.js";
10
- import { c as readSetTables, d as isQuerySpec, f as specTables, i as defineReadSet, o as isReadSet } from "./read-set-4lI3W_gZ.js";
11
- import { t as validate } from "./standard-FUi3Z3-7.js";
12
- import { a as problemResponse, i as isProblem, n as PROBLEM_TYPE_BASE, o as toProblem, r as fromProblem, t as PROBLEM_CONTENT_TYPE } from "./problem-BTkTtRV9.js";
9
+ import { a as postgrestExecutor, i as explainPostgrest, n as StatsRecorder, o as compilePostgrest, r as recordStats, t as EMPTY_STATS } from "./stats-C_YxA2r1.js";
10
+ import { c as readSetTables, d as isQuerySpec, f as specTables, i as defineReadSet, o as isReadSet } from "./read-set-FWK8qQ58.js";
11
+ import { t as validate } from "./standard-BRyBGTtp.js";
12
+ import { a as problemResponse, i as isProblem, n as PROBLEM_TYPE_BASE, o as toProblem, r as fromProblem, t as PROBLEM_CONTENT_TYPE } from "./problem-BihjPR0t.js";
13
13
  import { t as SPEC_PINS } from "./spec-pins-C3oc-Tdp.js";
14
14
  import { n as scopeOperation, r as scopeSelection, t as scopeCondition } from "./scope-CDHcS7dE.js";
15
- import { n as toCamel, r as toSnake } from "./casing-da0uRTqt.js";
16
15
  //#region src/core/define-repository.ts
17
16
  /**
18
17
  * Domain methods for one table, installed with `use()`. `base` is the
19
18
  * repository at call time, with every other plugin's methods.
20
19
  *
21
20
  * ```ts
22
- * const customers = defineRepository(sb, 'customers', (base) => ({
21
+ * const customers = defineRepository(betterSupabase, 'customers', (base) => ({
23
22
  * active: () => base.findMany({ where: { status: 'active' } }),
24
23
  * }));
25
- * export const app = sb.use(customers);
24
+ * export const app = betterSupabase.use(customers);
26
25
  * await app.connect(client).customers.active();
27
26
  * ```
28
27
  */
29
- function defineRepository(sb, table, build) {
30
- if (!(table in sb.meta.tables)) throw new TypeError(`better-supabase: defineRepository: unknown table "${table}"`);
28
+ function defineRepository(betterSupabase, table, build) {
29
+ if (!(table in betterSupabase.meta.tables)) throw new TypeError(`better-supabase: defineRepository: unknown table "${table}"`);
31
30
  return definePlugin({
32
31
  name: `repository:${table}`,
33
32
  repository: ({ table: meta, base }) => meta.key === table ? build(base) : void 0
@@ -40,4 +39,14 @@ const postgrestCompiler = {
40
39
  compile: compilePostgrest
41
40
  };
42
41
  //#endregion
42
+ //#region src/casing/index.ts
43
+ /** `first_name` to `firstName`. Leaves already camel-cased names untouched. */
44
+ function toCamel(name) {
45
+ return name.replaceAll(/_+([a-z0-9])/g, (_, char) => char.toUpperCase());
46
+ }
47
+ /** `firstName` to `first_name`. */
48
+ function toSnake(name) {
49
+ return name.replaceAll(/([a-z0-9])([A-Z])/g, "$1_$2").replaceAll(/([A-Z])([A-Z][a-z])/g, "$1_$2").toLowerCase();
50
+ }
51
+ //#endregion
43
52
  export { AsyncResult, BetterSupabase, DbException, EMPTY_STATS, EventHub, PLUGIN_API_VERSION, PROBLEM_CONTENT_TYPE, PROBLEM_TYPE_BASE, SPEC_PINS, StatsRecorder, and, cacheTargetOf, column, compilePostgrest, consoleLogger, dbError, decodeCursor, decodeRows, definePlugin, defineReadSet, defineRepository, defineSchema, defineSupabase, encodeCursor, encodeValue, err, escapeLike, explainPostgrest, fromBetterResult, fromProblem, invalidationTargets, isCheck, isConflict, isDbError, isForeignKey, isProblem, isQuerySpec, isReadSet, mapDbError, memoryCache, not, ok, or, postgrestCompiler, postgrestExecutor, problemResponse, readSetTables, recordStats, rowKey, rpcCacheTargets, scopeCondition, scopeOperation, scopeSelection, silentLogger, simplify, specTables, statusOf, tableMeta, toBetterResult, toCamel, toDbError, toProblem, toSnake, touchedTables, validate };
@@ -1,7 +1,13 @@
1
1
  //#region src/query/invalidate.ts
2
+ function isString(value) {
3
+ return typeof value === "string";
4
+ }
2
5
  function queryTables(query) {
3
6
  const tables = query.meta?.["bsTables"];
4
- if (Array.isArray(tables)) return tables.filter((t) => typeof t === "string");
7
+ if (Array.isArray(tables)) {
8
+ const list = tables;
9
+ return list.every(isString) ? list : list.filter(isString);
10
+ }
5
11
  const [prefix, table] = query.queryKey;
6
12
  return prefix === "bs" && typeof table === "string" ? [table] : void 0;
7
13
  }
@@ -1,11 +1,12 @@
1
- import { o as Result, p as DbError, t as AsyncResult } from "../result-CTkCZ6JA.js";
2
- import { t as SqlClient } from "../executor-BYXQ9AGn.js";
1
+ /// <reference lib="esnext.temporal" />
2
+ import { o as Result, p as DbError, t as AsyncResult } from "../result-CqEsbgYs.js";
3
+ import { t as SqlClient } from "../executor-CZ7ImRiD.js";
3
4
  import { StandardSchemaV1 } from "@standard-schema/spec";
4
- //#region src/jobs/index.d.ts
5
- export type QueueSchemas = Readonly<Record<string, StandardSchemaV1>>;
5
+ //#region src/jobs/jobs.d.ts
6
+ type QueueSchemas = Readonly<Record<string, StandardSchemaV1>>;
6
7
  type PayloadIn<Q extends QueueSchemas, N extends keyof Q> = StandardSchemaV1.InferInput<Q[N]>;
7
8
  type PayloadOut<Q extends QueueSchemas, N extends keyof Q> = StandardSchemaV1.InferOutput<Q[N]>;
8
- export interface Job<P = unknown> {
9
+ interface Job<P = unknown> {
9
10
  /** The pgmq message id. */
10
11
  readonly id: number;
11
12
  readonly queue: string;
@@ -13,14 +14,14 @@ export interface Job<P = unknown> {
13
14
  /** 1 on the first run (pgmq's `read_ct`). */
14
15
  readonly attempts: number;
15
16
  readonly maxAttempts: number;
16
- readonly enqueuedAt: Date;
17
+ readonly enqueuedAt: Temporal.Instant;
17
18
  /** End of the lease: the job becomes claimable again after this. */
18
- readonly visibleUntil: Date;
19
+ readonly visibleUntil: Temporal.Instant;
19
20
  readonly lastError: string | null;
20
21
  }
21
- export interface EnqueueOptions {
22
+ interface EnqueueOptions {
22
23
  /** Run no earlier than this. */
23
- readonly runAt?: Date;
24
+ readonly runAt?: Temporal.Instant;
24
25
  /** Seconds to wait before running. */
25
26
  readonly delay?: number;
26
27
  /** Defaults to 5. After this many failed attempts the job is archived as dead. */
@@ -31,31 +32,37 @@ export interface EnqueueOptions {
31
32
  */
32
33
  readonly dedupeKey?: string;
33
34
  }
34
- export interface ClaimOptions {
35
+ interface ClaimOptions {
35
36
  /** Defaults to 1. */
36
37
  readonly batch?: number;
37
38
  /** Seconds a claimed job stays invisible to other workers. Defaults to 300. */
38
39
  readonly lease?: number;
39
40
  }
40
- export interface FailOptions {
41
+ interface FailOptions {
41
42
  /** Retry after this many seconds instead of the exponential backoff. SQL connections only. */
42
43
  readonly retryIn?: number;
43
44
  }
44
- export type JobHandler<P> = (payload: P, job: Job<P>, signal: AbortSignal) => unknown;
45
- export interface WorkOptions extends ClaimOptions {
45
+ type JobHandler<P> = (payload: P, job: Job<P>, signal: AbortSignal) => unknown;
46
+ interface WorkOptions extends ClaimOptions {
46
47
  /** Jobs handled at once. Defaults to 1. */
47
48
  readonly concurrency?: number;
48
- /** Wait between polls when the queue is empty, in ms. Defaults to 1000. */
49
+ /**
50
+ * First wait between polls when the queue is empty, in ms. Defaults to
51
+ * 1000. Each empty poll doubles the wait up to `maxPollInterval`; a claimed
52
+ * job resets it.
53
+ */
49
54
  readonly pollInterval?: number;
55
+ /** Longest wait between empty polls, in ms. Defaults to 30000. */
56
+ readonly maxPollInterval?: number;
50
57
  /** Stops the loop; running jobs finish first. */
51
58
  readonly signal?: AbortSignal;
52
59
  readonly onError?: (error: DbError, job: Job) => void;
53
60
  }
54
- export interface DrainResult {
61
+ interface DrainResult {
55
62
  readonly succeeded: number;
56
63
  readonly failed: number;
57
64
  }
58
- export interface Jobs<Q extends QueueSchemas> {
65
+ interface Jobs<Q extends QueueSchemas> {
59
66
  /** Validates the payload with the queue's schema, then enqueues it. Returns the job id. */
60
67
  enqueue<N extends Extract<keyof Q, string>>(queue: N, payload: PayloadIn<Q, N>, options?: EnqueueOptions): AsyncResult<number>;
61
68
  claim<N extends Extract<keyof Q, string>>(queue: N, options?: ClaimOptions): AsyncResult<Job<PayloadOut<Q, N>>[]>;
@@ -72,12 +79,12 @@ export interface Jobs<Q extends QueueSchemas> {
72
79
  schedule<N extends Extract<keyof Q, string>>(name: string, cron: string, queue: N, payload: PayloadIn<Q, N>): AsyncResult<void>;
73
80
  unschedule(name: string): AsyncResult<boolean>;
74
81
  /** Processes ready jobs until the queue is empty. For cron and edge invocations. */
75
- drain<N extends Extract<keyof Q, string>>(queue: N, handler: JobHandler<PayloadOut<Q, N>>, options?: Omit<WorkOptions, "pollInterval" | "signal">): Promise<DrainResult>;
82
+ drain<N extends Extract<keyof Q, string>>(queue: N, handler: JobHandler<PayloadOut<Q, N>>, options?: Omit<WorkOptions, "pollInterval" | "maxPollInterval" | "signal">): Promise<DrainResult>;
76
83
  /** Polls and processes jobs until `signal` aborts. */
77
84
  work<N extends Extract<keyof Q, string>>(queue: N, handler: JobHandler<PayloadOut<Q, N>>, options?: WorkOptions): Promise<DrainResult>;
78
85
  }
79
86
  /** A Supabase client, or anything with `.schema(name).rpc(fn, args)`. */
80
- export interface QueueRpcClient {
87
+ interface QueueRpcClient {
81
88
  schema(name: string): {
82
89
  rpc(fn: string, args: Readonly<Record<string, unknown>>): PromiseLike<{
83
90
  data: unknown;
@@ -94,7 +101,7 @@ export interface QueueRpcClient {
94
101
  * Queue names are lowercase letters, digits and underscores.
95
102
  */
96
103
  export declare function createJobs<const Q extends QueueSchemas>(source: SqlClient | QueueRpcClient, queues: Q): Jobs<Q>;
97
- export interface IdempotencyOptions {
104
+ interface IdempotencyOptions {
98
105
  /** Separates keys of different endpoints or tenants. Defaults to `''`. */
99
106
  readonly scope?: string | ((request: Request) => string);
100
107
  /** How long a completed response is replayed. Defaults to `24 hours`. */
@@ -106,8 +113,8 @@ export interface IdempotencyOptions {
106
113
  /** Defaults to `Idempotency-Key`. */
107
114
  readonly header?: string;
108
115
  }
109
- export type IdempotencyState = "started" | "replay" | "running" | "mismatch";
110
- export interface Idempotency {
116
+ type IdempotencyState = "started" | "replay" | "running" | "mismatch";
117
+ interface Idempotency {
111
118
  /**
112
119
  * Runs `handler` at most once per key: retries with the same key and body
113
120
  * get the stored response (with `Idempotency-Replayed: true`).
@@ -124,7 +131,7 @@ export interface Idempotency {
124
131
  }
125
132
  /** HTTP idempotency keys (IETF `Idempotency-Key` header) over the `idempotency` SQL kit module. */
126
133
  export declare function createIdempotency(sql: SqlClient, options?: IdempotencyOptions): Idempotency;
127
- export interface InboxMessage<T = unknown> {
134
+ interface InboxMessage<T = unknown> {
128
135
  readonly id: number;
129
136
  readonly source: string;
130
137
  readonly messageId: string;
@@ -132,9 +139,9 @@ export interface InboxMessage<T = unknown> {
132
139
  readonly payload: T;
133
140
  readonly headers: Readonly<Record<string, string>>;
134
141
  readonly attempts: number;
135
- readonly receivedAt: Date;
142
+ readonly receivedAt: Temporal.Instant;
136
143
  }
137
- export interface InboxOptions {
144
+ interface InboxOptions {
138
145
  /** Name of the sender, e.g. `stripe` or `supabase-auth`. */
139
146
  readonly source: string;
140
147
  /** Standard Webhooks secrets; the signature is verified before storing. */
@@ -150,7 +157,7 @@ export interface InboxOptions {
150
157
  readonly keepHeaders?: readonly string[];
151
158
  readonly worker?: string;
152
159
  }
153
- export interface Inbox {
160
+ interface Inbox {
154
161
  /** Verifies and stores a webhook; answers 202, or 200 for a duplicate delivery. */
155
162
  receive(request: Request): Promise<Response>;
156
163
  /** Processes stored messages until none are ready. */
@@ -170,4 +177,4 @@ export declare const ENTITLEMENTS_UPDATED = "entitlements.active_entitlement_sum
170
177
  */
171
178
  export declare function entitlementMembers(sql: SqlClient, payload: unknown): AsyncResult<readonly string[]>;
172
179
  //#endregion
173
- export type { SqlClient };
180
+ export type { ClaimOptions, DrainResult, EnqueueOptions, FailOptions, Idempotency, IdempotencyOptions, IdempotencyState, Inbox, InboxMessage, InboxOptions, Job, JobHandler, Jobs, QueueRpcClient, QueueSchemas, SqlClient, WorkOptions };