better-supabase 0.4.0 → 0.5.1

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 (180) hide show
  1. package/README.md +135 -16
  2. package/dist/actor-DaJjqD5R.d.ts +43 -0
  3. package/dist/channel-FQW-CnGR.d.ts +70 -0
  4. package/dist/cli/bin.js +1 -1
  5. package/dist/cli/codemod-DqV7612m.js +388 -0
  6. package/dist/cli/{config-D9R0o1LH.js → config-CPVpXP5I.js} +78 -8
  7. package/dist/cli/{config-SSKSTUl2.js → config-dtoekM0v.js} +1 -1
  8. package/dist/cli/{read-sets-CMa29t9a.js → diff-SjkO5rNr.js} +1 -220
  9. package/dist/cli/{dist-CFgGknmZ.js → dist-DBPdlPYK.js} +4 -4
  10. package/dist/cli/{dist-B1MvLv-M.js → dist-DreZ24Sz.js} +1 -1
  11. package/dist/cli/{dist-Du7VnEUG.js → dist-xn4wlboc.js} +112 -1
  12. package/dist/cli/{doctor-BOym3mbL.js → doctor-C_A-KEAz.js} +533 -50
  13. package/dist/cli/{env-BZ0uy8XK.js → env-DmKv_G4A.js} +1 -1
  14. package/dist/cli/gen-CIdSQZad.js +2 -0
  15. package/dist/cli/{gen-Ccn_p90L.js → gen-CjElD1Vw.js} +321 -88
  16. package/dist/cli/index.d.ts +1 -1
  17. package/dist/cli/index.js +4 -4
  18. package/dist/cli/{init-ClnxRYBF.js → init-DMa6M7hV.js} +2 -2
  19. package/dist/cli/{introspect-DxqfkVIv.js → introspect-BKlaIu_M.js} +2 -2
  20. package/dist/cli/{openapi-8WHjxiTJ.js → openapi-Cp5Fyta-.js} +1 -1
  21. package/dist/cli/read-sets-VQcPgxU9.js +436 -0
  22. package/dist/cli/{run-CP20LKk_.js → run-Bo_NLT5n.js} +16 -12
  23. package/dist/cli/{seed-5J6eu_Xg.js → seed-CUlqWh-8.js} +1 -1
  24. package/dist/cli/sql-CVx-1O8G.js +373 -0
  25. package/dist/cli/{version-5mW_8sY1.js → version-BCtlgDQx.js} +1 -1
  26. package/dist/client/index.d.ts +1 -1
  27. package/dist/client/index.js +3 -10
  28. package/dist/clone-BfgmLU90.js +21 -0
  29. package/dist/{compiler-DB3aSFOA.d.ts → compiler-BXH_aZ7N.d.ts} +2 -2
  30. package/dist/config/index.d.ts +4 -4
  31. package/dist/config/index.js +4 -4
  32. package/dist/{config-C1CYcm6o.d.ts → config-Bv7gvfzC.d.ts} +185 -11
  33. package/dist/{config-CbvFmGD8.js → config-DreERlKo.js} +1 -1
  34. package/dist/{define-CRS2MRV3.d.ts → define-Bp_BZa5h.d.ts} +11 -7
  35. package/dist/{define-Bh0AqTik.js → define-cNKzqwL_.js} +202 -16
  36. package/dist/edge/index.d.ts +16 -5
  37. package/dist/edge/index.js +10 -7
  38. package/dist/{entitlements-Dm-FHpNH.d.ts → entitlements-BiJZ4t49.d.ts} +1 -1
  39. package/dist/env/index.d.ts +2 -2
  40. package/dist/env/index.js +34 -1
  41. package/dist/{errors-L0xK41y_.js → errors-DtwXa6b8.js} +1 -0
  42. package/dist/events/index.d.ts +3 -2
  43. package/dist/events/index.js +65 -12
  44. package/dist/events-aIO7vsIk.d.ts +230 -0
  45. package/dist/{result-CqEsbgYs.d.ts → executor-BunPOO-k.d.ts} +200 -1
  46. package/dist/{executor-CZ7ImRiD.d.ts → executor-Cghdstwu.d.ts} +1 -2
  47. package/dist/{executor-CVt6dD0B.js → executor-XycESQPH.js} +3 -3
  48. package/dist/hono/index.d.ts +17 -6
  49. package/dist/hono/index.js +40 -5
  50. package/dist/impersonation-BgSHAYLf.js +133 -0
  51. package/dist/{resolve-BAqQcwMW.d.ts → impersonation-BmePsuxz.d.ts} +36 -6
  52. package/dist/{index-BhHEC04r.d.ts → index-C7f8cOBM.d.ts} +2 -2
  53. package/dist/{index-Dy6kuF0P.d.ts → index-CLg87OBW.d.ts} +6 -1
  54. package/dist/{index-Cf-D2jk1.d.ts → index-CWMDdEr4.d.ts} +2 -2
  55. package/dist/{index-D5IfUIDh.d.ts → index-DOESKG27.d.ts} +33 -8
  56. package/dist/{index-DFmOpBGC.d.ts → index-DgILJRXj.d.ts} +35 -9
  57. package/dist/{index-RlLXd8dL.d.ts → index-DmXSxbLi.d.ts} +4 -4
  58. package/dist/{index-BBdvo-5d.d.ts → index-Dp2VDwog.d.ts} +49 -6
  59. package/dist/{index-528Ugmyp.d.ts → index-SaTsEfGP.d.ts} +76 -8
  60. package/dist/{index-BAy4tsAP.d.ts → index-fag8VJZ2.d.ts} +3 -4
  61. package/dist/index.d.ts +30 -13
  62. package/dist/index.js +10 -9
  63. package/dist/jobs/index.d.ts +147 -101
  64. package/dist/jobs/index.js +744 -237
  65. package/dist/{json-schema-DP6V7cbr.js → json-schema-m1fiwKgN.js} +22 -1
  66. package/dist/kit-events-CTFDfSwb.js +60 -0
  67. package/dist/kit-transport-B82k1djG.d.ts +33 -0
  68. package/dist/kit-transport-DJlHQUBU.js +55 -0
  69. package/dist/{config-BpxDfnbg.js → kits-CGLLrNPd.js} +37 -9
  70. package/dist/list/index.d.ts +1 -1
  71. package/dist/{live-BHakSWWo.d.ts → live-D9W2M5aO.d.ts} +6 -5
  72. package/dist/mcp/index.d.ts +25 -8
  73. package/dist/mcp/index.js +23 -14
  74. package/dist/{mfa-C7MNQ1Ob.d.ts → mfa-Cu96oJdw.d.ts} +2 -16
  75. package/dist/next/index.d.ts +31 -10
  76. package/dist/next/index.js +136 -27
  77. package/dist/notifications/index.d.ts +162 -0
  78. package/dist/notifications/index.js +264 -0
  79. package/dist/openapi/index.d.ts +1 -1
  80. package/dist/openapi/index.js +2 -2
  81. package/dist/orgs/index.d.ts +132 -0
  82. package/dist/orgs/index.js +245 -0
  83. package/dist/orpc/index.d.ts +28 -8
  84. package/dist/orpc/index.js +16 -3
  85. package/dist/otel/index.d.ts +21 -2
  86. package/dist/otel/index.js +50 -9
  87. package/dist/permdock-sql-C2Inc6Xc.d.ts +29 -0
  88. package/dist/permdock-sql-DgOfeixi.js +51 -0
  89. package/dist/plugin-DwARMuQp.js +59 -0
  90. package/dist/{plugin-bNhvJwRh.d.ts → plugin-o144f322.d.ts} +17 -5
  91. package/dist/plugins/actor/index.d.ts +5 -2
  92. package/dist/plugins/actor/index.js +22 -8
  93. package/dist/plugins/rules/index.d.ts +2 -2
  94. package/dist/plugins/rules/index.js +15 -10
  95. package/dist/plugins/soft-delete/index.d.ts +3 -3
  96. package/dist/plugins/soft-delete/index.js +14 -5
  97. package/dist/plugins/tenant/index.d.ts +2 -2
  98. package/dist/plugins/tenant/index.js +38 -20
  99. package/dist/plugins/timestamps/index.d.ts +1 -1
  100. package/dist/plugins/timestamps/index.js +4 -3
  101. package/dist/plugins/validation/index.d.ts +2 -2
  102. package/dist/plugins/validation/index.js +26 -6
  103. package/dist/{pool-DFwEQwmN.d.ts → pool-C9voM4Kw.d.ts} +17 -6
  104. package/dist/postgres/index.d.ts +5 -5
  105. package/dist/postgres/index.js +20 -11
  106. package/dist/{postgrest-Bc-0Xw62.d.ts → postgrest-CruYKAvV.d.ts} +1 -1
  107. package/dist/{problem-BihjPR0t.js → problem-BW1KhzSG.js} +2 -1
  108. package/dist/{problem-U8UEKccv.d.ts → problem-Blxe8S31.d.ts} +1 -1
  109. package/dist/query/index.d.ts +2 -2
  110. package/dist/query/index.js +3 -3
  111. package/dist/{query-BMMSWbI7.js → query-CCbo44lG.js} +2 -2
  112. package/dist/queue-BYUCjr59.d.ts +252 -0
  113. package/dist/react/index.d.ts +8 -7
  114. package/dist/react/index.js +4 -3
  115. package/dist/react/server.d.ts +14 -3
  116. package/dist/react/server.js +10 -2
  117. package/dist/react/session.d.ts +7 -1
  118. package/dist/react/session.js +9 -1
  119. package/dist/{react-CQHMaESR.js → react-C_s7kiNz.js} +103 -11
  120. package/dist/{read-set-FWK8qQ58.js → read-set-DQFt1N_Y.js} +22 -1
  121. package/dist/realtime/index.d.ts +3 -3
  122. package/dist/realtime/index.js +5 -4
  123. package/dist/{refresh-BwYkyNOQ.d.ts → refresh-CFPX0Qft.d.ts} +1 -1
  124. package/dist/{resource-BJcaIfxi.d.ts → resource-DNRFP7KR.d.ts} +5 -5
  125. package/dist/{resource-My_y-Syh.js → resource-mqfJW4YF.js} +22 -7
  126. package/dist/respond-BR1fJWOB.d.ts +377 -0
  127. package/dist/{result-Bj6yt33D.js → result-BKiliPY7.js} +1 -1
  128. package/dist/server/index.d.ts +15 -12
  129. package/dist/server/index.js +11 -17
  130. package/dist/{server-BA75B0mT.js → server-B1mZ7CgQ.js} +259 -37
  131. package/dist/{shared-DnoCdMDr.js → shared-D1dRUrAg.js} +16 -2
  132. package/dist/signers-Cc6r98SW.d.ts +162 -0
  133. package/dist/{simplify-Cqvfr9dj.js → simplify-_0oUKqCd.js} +4 -115
  134. package/dist/sql/index.d.ts +283 -11
  135. package/dist/sql/index.js +8705 -775
  136. package/dist/{sql-B34HU2DI.js → sql-Coh6n4cC.js} +9 -2
  137. package/dist/ssr/index.d.ts +4 -4
  138. package/dist/ssr/index.js +1 -2
  139. package/dist/{standard-BRyBGTtp.js → standard-D7r6dMUu.js} +6 -3
  140. package/dist/{standard-BsaCYQJc.d.ts → standard-J4YgMOLm.d.ts} +1 -1
  141. package/dist/{stats-C_YxA2r1.js → stats-Bqob3WqT.js} +4 -4
  142. package/dist/storage/index.d.ts +4 -4
  143. package/dist/storage/index.js +155 -26
  144. package/dist/support-CEPwlw2G.d.ts +89 -0
  145. package/dist/support-view-B8SlToQX.d.ts +17 -0
  146. package/dist/support-view-g4YLBeqX.js +18 -0
  147. package/dist/support-wHnK6zp-.js +293 -0
  148. package/dist/{permdock-sql-C4KFzLc9.js → template-TxrGI5jR.js} +2 -31
  149. package/dist/{temporal-BwshQk0W.js → temporal-CVlIV2DZ.js} +17 -4
  150. package/dist/{temporal-required-CBNHT6ni.js → temporal-required-CAt4Dc9Z.js} +2 -2
  151. package/dist/testing/index.d.ts +132 -10
  152. package/dist/testing/index.js +476 -8
  153. package/dist/{types-DONv9SHN.d.ts → types-Dnf_wRDz.d.ts} +26 -3
  154. package/dist/user-change-CHFEUro1.js +49 -0
  155. package/dist/{webhooks-Bh_Jf_-l.js → verify-Ce49ETPz.js} +5 -5
  156. package/dist/{version-Bmf7_FzM.js → version-DOYTYwHP.js} +1 -1
  157. package/dist/{mfa-byfjruR9.js → view-Bn6HNKUe.js} +97 -98
  158. package/dist/{view-B64o81wp.d.ts → view-CbgObAeb.d.ts} +22 -31
  159. package/dist/webhooks/index.d.ts +135 -4
  160. package/dist/webhooks/index.js +588 -2
  161. package/dist/wire-D2dT86vi.js +35 -0
  162. package/package.json +27 -19
  163. package/schemas/config-v1.json +131 -1
  164. package/schemas/doctor-report-v1.json +11 -0
  165. package/skills/better-supabase/SKILL.md +9 -6
  166. package/skills/better-supabase/references/plugins.md +6 -3
  167. package/skills/better-supabase/references/troubleshooting.md +1 -0
  168. package/skills/better-supabase-api/SKILL.md +9 -2
  169. package/skills/better-supabase-api/references/adapters.md +11 -8
  170. package/skills/better-supabase-auth/SKILL.md +18 -7
  171. package/skills/better-supabase-auth/references/permdock.md +78 -11
  172. package/dist/cli/gen-D5cLCULx.js +0 -2
  173. package/dist/cli/sql-D4VbqmXi.js +0 -199
  174. package/dist/events-B21UOhvP.d.ts +0 -84
  175. package/dist/executor-B5IoUxLE.d.ts +0 -195
  176. package/dist/invalidate-CgxmRamI.js +0 -24
  177. package/dist/permdock-sql-DImJULY-.d.ts +0 -17
  178. package/dist/plugin-BqR6wKMB.js +0 -23
  179. package/dist/respond-DgIbdrt8.d.ts +0 -194
  180. package/dist/view-BrJI2LKp.js +0 -45
@@ -1,108 +1,34 @@
1
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";
4
- import { StandardSchemaV1 } from "@standard-schema/spec";
5
- //#region src/jobs/jobs.d.ts
6
- type QueueSchemas = Readonly<Record<string, StandardSchemaV1>>;
7
- type PayloadIn<Q extends QueueSchemas, N extends keyof Q> = StandardSchemaV1.InferInput<Q[N]>;
8
- type PayloadOut<Q extends QueueSchemas, N extends keyof Q> = StandardSchemaV1.InferOutput<Q[N]>;
9
- interface Job<P = unknown> {
10
- /** The pgmq message id. */
11
- readonly id: number;
12
- readonly queue: string;
13
- readonly payload: P;
14
- /** 1 on the first run (pgmq's `read_ct`). */
15
- readonly attempts: number;
16
- readonly maxAttempts: number;
17
- readonly enqueuedAt: Temporal.Instant;
18
- /** End of the lease: the job becomes claimable again after this. */
19
- readonly visibleUntil: Temporal.Instant;
20
- readonly lastError: string | null;
21
- }
22
- interface EnqueueOptions {
23
- /** Run no earlier than this. */
24
- readonly runAt?: Temporal.Instant;
25
- /** Seconds to wait before running. */
26
- readonly delay?: number;
27
- /** Defaults to 5. After this many failed attempts the job is archived as dead. */
28
- readonly maxAttempts?: number;
29
- /**
30
- * While a job with this key is waiting or running, enqueueing again returns
31
- * its id. SQL connections only.
32
- */
33
- readonly dedupeKey?: string;
34
- }
35
- interface ClaimOptions {
36
- /** Defaults to 1. */
37
- readonly batch?: number;
38
- /** Seconds a claimed job stays invisible to other workers. Defaults to 300. */
39
- readonly lease?: number;
40
- }
41
- interface FailOptions {
42
- /** Retry after this many seconds instead of the exponential backoff. SQL connections only. */
43
- readonly retryIn?: number;
44
- }
45
- type JobHandler<P> = (payload: P, job: Job<P>, signal: AbortSignal) => unknown;
46
- interface WorkOptions extends ClaimOptions {
47
- /** Jobs handled at once. Defaults to 1. */
48
- readonly concurrency?: number;
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
- */
54
- readonly pollInterval?: number;
55
- /** Longest wait between empty polls, in ms. Defaults to 30000. */
56
- readonly maxPollInterval?: number;
57
- /** Stops the loop; running jobs finish first. */
58
- readonly signal?: AbortSignal;
59
- readonly onError?: (error: DbError, job: Job) => void;
60
- }
61
- interface DrainResult {
62
- readonly succeeded: number;
63
- readonly failed: number;
64
- }
65
- interface Jobs<Q extends QueueSchemas> {
66
- /** Validates the payload with the queue's schema, then enqueues it. Returns the job id. */
67
- enqueue<N extends Extract<keyof Q, string>>(queue: N, payload: PayloadIn<Q, N>, options?: EnqueueOptions): AsyncResult<number>;
68
- claim<N extends Extract<keyof Q, string>>(queue: N, options?: ClaimOptions): AsyncResult<Job<PayloadOut<Q, N>>[]>;
69
- /** Archives the job. `false` when the lease was lost (another worker claimed it since). */
70
- complete(job: Job): AsyncResult<boolean>;
71
- /** Returns the new state: `queued` (will retry), `dead` (archived), or `null` when the lease was lost. */
72
- fail(job: Job, error: unknown, options?: FailOptions): AsyncResult<"queued" | "dead" | null>;
73
- /** Pushes the lease out by `lease` seconds. `false` when it was lost or the transport can't. */
74
- extend(job: Job, lease: number): AsyncResult<boolean>;
75
- /**
76
- * Enqueues `payload` on a cron schedule with pg_cron (`'0 3 * * *'`,
77
- * `'30 seconds'`). Re-scheduling a name replaces it. SQL connections only.
78
- */
79
- schedule<N extends Extract<keyof Q, string>>(name: string, cron: string, queue: N, payload: PayloadIn<Q, N>): AsyncResult<void>;
80
- unschedule(name: string): AsyncResult<boolean>;
81
- /** Processes ready jobs until the queue is empty. For cron and edge invocations. */
82
- drain<N extends Extract<keyof Q, string>>(queue: N, handler: JobHandler<PayloadOut<Q, N>>, options?: Omit<WorkOptions, "pollInterval" | "maxPollInterval" | "signal">): Promise<DrainResult>;
83
- /** Polls and processes jobs until `signal` aborts. */
84
- work<N extends Extract<keyof Q, string>>(queue: N, handler: JobHandler<PayloadOut<Q, N>>, options?: WorkOptions): Promise<DrainResult>;
85
- }
86
- /** A Supabase client, or anything with `.schema(name).rpc(fn, args)`. */
87
- interface QueueRpcClient {
88
- schema(name: string): {
89
- rpc(fn: string, args: Readonly<Record<string, unknown>>): PromiseLike<{
90
- data: unknown;
91
- error: unknown;
92
- }>;
93
- };
94
- }
2
+ import { _ as DbError, a as AsyncResult, u as Result } from "../executor-BunPOO-k.js";
3
+ import { t as SqlClient } from "../executor-Cghdstwu.js";
4
+ import { r as EventSink, t as CloudEvent } from "../index-DOESKG27.js";
5
+ import { C as sqlQueueBackend, S as pgmqPublicBackend, _ as QueueSchemas, a as DrainRouteResult, b as WorkOptions, c as FailOptions, d as JobHandler, f as Jobs, g as QueueRpcClient, h as QueueMessageRow, i as DrainRouteOptions, l as Job, m as QueueMessageBody, n as DrainOptions, o as DueSchedule, p as QueueBackend, r as DrainResult, s as EnqueueOptions, t as ClaimOptions, u as JobContext, v as RunSchedulesOptions, x as createJobs, y as ScheduleOptions } from "../queue-BYUCjr59.js";
6
+ //#region src/jobs/cron.d.ts
7
+ /**
8
+ * Throws a `TypeError` unless `expression` is a schedule `nextCronRun`
9
+ * understands: five cron fields, a macro such as `@daily`, or an interval
10
+ * such as `30 seconds`.
11
+ */
12
+ export declare function assertCron(expression: string): void;
95
13
  /**
96
- * Typed jobs on Supabase Queues (pgmq), over the `jobs` SQL kit module.
14
+ * The first run of `expression` after `after`, in `timeZone`.
97
15
  *
98
- * Pass a service SQL connection (`postgres.admin`, `ctx.sql`) for the full
99
- * feature set, or a service-role Supabase client to go through the
100
- * `pgmq_public` RPCs where no direct connection exists (edge functions).
101
- * Queue names are lowercase letters, digits and underscores.
16
+ * Accepts five cron fields (lists, ranges and steps; a restricted day of
17
+ * month and day of week match either, as in cron), the macros `@hourly`,
18
+ * `@daily`, `@weekly`, `@monthly` and `@yearly`, and intervals such as
19
+ * `30 seconds`, `5 minutes` or `2 hours`, counted from `after`. A local time
20
+ * that a DST change skips runs at the same offset after the gap.
102
21
  */
103
- export declare function createJobs<const Q extends QueueSchemas>(source: SqlClient | QueueRpcClient, queues: Q): Jobs<Q>;
22
+ export declare function nextCronRun(expression: string, timeZone: string, after: Temporal.Instant): Temporal.Instant;
23
+ //#endregion
24
+ //#region src/jobs/jobs.d.ts
104
25
  interface IdempotencyOptions {
105
- /** Separates keys of different endpoints or tenants. Defaults to `''`. */
26
+ /**
27
+ * Separates keys of different callers, endpoints or tenants. Defaults to a
28
+ * hash of the caller's credentials (the `Authorization` header or the
29
+ * Supabase auth cookies), so one caller never replays another's response.
30
+ * Pass the verified user id to keep keys across token refreshes.
31
+ */
106
32
  readonly scope?: string | ((request: Request) => string);
107
33
  /** How long a completed response is replayed. Defaults to `24 hours`. */
108
34
  readonly ttl?: number | string;
@@ -176,5 +102,125 @@ export declare const ENTITLEMENTS_UPDATED = "entitlements.active_entitlement_sum
176
102
  * a job can invalidate their sessions. Empty for other payloads.
177
103
  */
178
104
  export declare function entitlementMembers(sql: SqlClient, payload: unknown): AsyncResult<readonly string[]>;
105
+ interface PurgeAuditLogOptions {
106
+ /** How long entries are kept when `retention` has no answer. Defaults to `1 year`. */
107
+ readonly olderThan?: number | string;
108
+ /** The most entries deleted per tenant in one call. Defaults to 10000. */
109
+ readonly batch?: number;
110
+ /**
111
+ * Days a tenant keeps its entries (a plan's retention, say); `undefined`
112
+ * uses `olderThan`. Called with `null` for entries without a tenant.
113
+ * Retention shorter than a day is not supported.
114
+ */
115
+ readonly retention?: (tenant: string | null) => number | undefined | Promise<number | undefined>;
116
+ }
117
+ /**
118
+ * Deletes audit entries past their retention and returns how many. Without
119
+ * `retention` it is one `purge_audit_log` call (which honours an
120
+ * `audit_retention` SQL hook); with it, each tenant is purged with its own
121
+ * interval. Run it from a schedule until it returns 0.
122
+ */
123
+ export declare function purgeAuditLog(sql: SqlClient, options?: PurgeAuditLogOptions): AsyncResult<number>;
124
+ //#endregion
125
+ //#region src/jobs/outbox.d.ts
126
+ /** One row of the outbox, as `outbox_claim` and `outbox_history` return it. */
127
+ interface OutboxEvent {
128
+ /** The cursor value: increases with every event. */
129
+ readonly position: number;
130
+ readonly id: string;
131
+ readonly type: string;
132
+ readonly payload: unknown;
133
+ /** The module or function that wrote it, e.g. `better-supabase/organizations`. */
134
+ readonly source: string | null;
135
+ readonly subject: string | null;
136
+ readonly tenant: string | null;
137
+ readonly key: string | null;
138
+ readonly actorId: string | null;
139
+ readonly createdAt: Temporal.Instant;
140
+ }
141
+ interface EmitOptions {
142
+ readonly subject?: string;
143
+ readonly tenant?: string;
144
+ /** With a key, emitting again (per tenant) returns the first event. */
145
+ readonly key?: string;
146
+ readonly source?: string;
147
+ }
148
+ interface OutboxOptions {
149
+ /** The schema of the `outbox` module. Defaults to `better_supabase`. */
150
+ readonly schema?: string;
151
+ /** CloudEvents `source` of the relayed events, e.g. `https://crm.example.com`. */
152
+ readonly source: string;
153
+ /** Prepended to each type with a dot when relaying, e.g. `com.example`. Defaults to `dev.better-supabase`. */
154
+ readonly typePrefix?: string;
155
+ }
156
+ interface RegisterOptions {
157
+ /** Type patterns such as `org.*` or `invoice.paid`. Defaults to every event. */
158
+ readonly types?: readonly string[];
159
+ /** Start at the first kept event instead of after the latest one. */
160
+ readonly fromStart?: boolean;
161
+ }
162
+ interface RelayOptions {
163
+ /** Events per claim and per `sink.send`. Defaults to 100. */
164
+ readonly batch?: number;
165
+ /** How long a claim holds the consumer. Defaults to `1 minute`. */
166
+ readonly lease?: string;
167
+ /** Stops claiming after this many milliseconds. */
168
+ readonly budgetMs?: number;
169
+ /** Identifies this worker in the lease. Defaults to a random id. */
170
+ readonly owner?: string;
171
+ }
172
+ interface RelayResult {
173
+ readonly delivered: number;
174
+ /** Set when the sink threw: the batch stays unacknowledged for the next run. */
175
+ readonly error?: DbError;
176
+ }
177
+ interface OutboxRouteOptions extends Omit<RelayOptions, "owner"> {
178
+ /** The bearer secret, such as `process.env.CRON_SECRET`. */
179
+ readonly secret: string | undefined;
180
+ /** Consumer name to the sink its events go to. */
181
+ readonly consumers: Readonly<Record<string, EventSink>>;
182
+ readonly onError?: (error: DbError, consumer: string) => void;
183
+ }
184
+ interface OutboxRouteResult {
185
+ readonly consumers: Readonly<Record<string, RelayResult>>;
186
+ readonly budgetExhausted: boolean;
187
+ }
188
+ interface HistoryFilter {
189
+ readonly subject?: string;
190
+ readonly type?: string;
191
+ /** Only events after this position. */
192
+ readonly after?: number;
193
+ readonly limit?: number;
194
+ }
195
+ interface Outbox {
196
+ /** Writes an event in the current transaction and returns its id. */
197
+ emit(type: string, payload?: unknown, options?: EmitOptions): AsyncResult<string>;
198
+ /** Creates the consumer, or changes its types. Returns its cursor position. */
199
+ register(consumer: string, options?: RegisterOptions): AsyncResult<number>;
200
+ /** Removes the consumer, so purges stop waiting for it. */
201
+ unregister(consumer: string): AsyncResult<boolean>;
202
+ /**
203
+ * Claims the consumer's next events, sends them to `sink` as CloudEvents and
204
+ * moves the cursor, until none are left or the budget runs out. A sink that
205
+ * throws leaves the batch for the next run, so delivery is at least once.
206
+ */
207
+ relay(consumer: string, sink: EventSink, options?: RelayOptions): Promise<RelayResult>;
208
+ /** A `GET`/`POST` handler for a cron that relays every consumer in turn. */
209
+ relayRoute(options: OutboxRouteOptions): (request: Request) => Promise<Response>;
210
+ history(filter?: HistoryFilter): AsyncResult<readonly OutboxEvent[]>;
211
+ /**
212
+ * Deletes up to `batch` events (default 10,000) older than `olderThan` that
213
+ * every consumer has passed. Call it again while it returns `batch`.
214
+ */
215
+ purge(olderThan?: string, batch?: number): AsyncResult<number>;
216
+ }
217
+ /**
218
+ * The CloudEvent for an outbox row: the row id as `id` (stable, so receivers
219
+ * can deduplicate), the payload as `data`, the tenant as `partitionkey` and
220
+ * the writing module as `producer`. The actor stays out of the context
221
+ * attributes, which must not carry personal data.
222
+ */
223
+ export declare function outboxCloudEvent(event: OutboxEvent, options: Pick<OutboxOptions, "source" | "typePrefix">): CloudEvent;
224
+ export declare function createOutbox(sql: SqlClient, options: OutboxOptions): Outbox;
179
225
  //#endregion
180
- export type { ClaimOptions, DrainResult, EnqueueOptions, FailOptions, Idempotency, IdempotencyOptions, IdempotencyState, Inbox, InboxMessage, InboxOptions, Job, JobHandler, Jobs, QueueRpcClient, QueueSchemas, SqlClient, WorkOptions };
226
+ export { type ClaimOptions, type DrainOptions, type DrainResult, type DrainRouteOptions, type DrainRouteResult, type DueSchedule, type EmitOptions, type EnqueueOptions, type FailOptions, type HistoryFilter, type Idempotency, type IdempotencyOptions, type IdempotencyState, type Inbox, type InboxMessage, type InboxOptions, type Job, type JobContext, type JobHandler, type Jobs, type Outbox, type OutboxEvent, type OutboxOptions, type OutboxRouteOptions, type OutboxRouteResult, type PurgeAuditLogOptions, type QueueBackend, type QueueMessageBody, type QueueMessageRow, type QueueRpcClient, type QueueSchemas, type RegisterOptions, type RelayOptions, type RelayResult, type RunSchedulesOptions, type ScheduleOptions, type SqlClient, type WorkOptions, createJobs, pgmqPublicBackend, sqlQueueBackend };