@protobase/server 0.129.1 → 0.130.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 (253) hide show
  1. package/dist/assistant/query-runner/grants-sql.js +32 -0
  2. package/dist/assistant/query-runner/query-input.js +33 -0
  3. package/dist/assistant/query-runner/query-module.js +44 -0
  4. package/dist/assistant/query-runner/query-runner.d.ts +8 -11
  5. package/dist/assistant/query-runner/query-runner.js +15 -57
  6. package/dist/assistant/query-runner/read-query.js +54 -0
  7. package/dist/assistant/query-runner/runner-sql.js +4 -20
  8. package/dist/assistant/query-runner/steps/001-role.js +19 -0
  9. package/dist/auth-store.d.ts +2 -2
  10. package/dist/auth-store.js +3 -3
  11. package/dist/better-auth/auth-schema.d.ts +13 -4
  12. package/dist/better-auth/auth-schema.js +40 -32
  13. package/dist/better-auth/auth-settings.d.ts +59 -11
  14. package/dist/better-auth/auth-settings.js +57 -13
  15. package/dist/better-auth/auth-tables.d.ts +6 -3
  16. package/dist/better-auth/auth-tables.js +12 -7
  17. package/dist/better-auth/authenticator.js +10 -2
  18. package/dist/better-auth/create-auth.d.ts +62 -7
  19. package/dist/better-auth/create-auth.js +55 -14
  20. package/dist/better-auth/device-sign-in-check.js +13 -0
  21. package/dist/better-auth/names/declaration.d.ts +18 -5
  22. package/dist/better-auth/names/declaration.js +3 -1
  23. package/dist/better-auth/names/modules/auth.js +9 -0
  24. package/dist/better-auth/names/modules/index.d.ts +34 -4
  25. package/dist/better-auth/names/modules/organizations.js +10 -3
  26. package/dist/better-auth/names/modules/personal-access-tokens.js +6 -3
  27. package/dist/better-auth/names/modules-on.js +25 -2
  28. package/dist/better-auth/names/resolve-names.d.ts +9 -1
  29. package/dist/better-auth/names/resolve-names.js +15 -9
  30. package/dist/better-auth/organizations/accept-invitation.js +5 -4
  31. package/dist/better-auth/organizations/add-every-user.js +3 -2
  32. package/dist/better-auth/organizations/host-scope.d.ts +10 -0
  33. package/dist/better-auth/organizations/host-scope.js +15 -0
  34. package/dist/better-auth/organizations/host.d.ts +12 -6
  35. package/dist/better-auth/organizations/host.js +99 -61
  36. package/dist/better-auth/organizations/kept-organizations.d.ts +21 -0
  37. package/dist/better-auth/organizations/kept-organizations.js +62 -0
  38. package/dist/better-auth/organizations/member-endpoints.js +4 -3
  39. package/dist/better-auth/organizations/options.d.ts +15 -0
  40. package/dist/better-auth/organizations/options.js +19 -1
  41. package/dist/better-auth/organizations/people-endpoint.js +3 -2
  42. package/dist/better-auth/organizations/pinned-membership.js +81 -0
  43. package/dist/better-auth/organizations/pinned-sessions.js +46 -0
  44. package/dist/better-auth/organizations/session-organization.js +3 -2
  45. package/dist/better-auth/organizations/store.d.ts +1 -1
  46. package/dist/better-auth/organizations/store.js +14 -9
  47. package/dist/better-auth/personal-access-tokens/pinned-tokens.js +23 -0
  48. package/dist/better-auth/personal-access-tokens/token-plugin.js +75 -54
  49. package/dist/better-auth/personal-access-tokens/token-sessions.js +6 -3
  50. package/dist/better-auth/personal-access-tokens/token-store.js +15 -11
  51. package/dist/better-auth/store/adoption.js +25 -10
  52. package/dist/better-auth/store/drift.js +5 -4
  53. package/dist/better-auth/store/legacy-record.d.ts +10 -0
  54. package/dist/better-auth/store/legacy-record.js +56 -0
  55. package/dist/better-auth/store/migration-sql.js +31 -26
  56. package/dist/better-auth/store/offline/archive-revival.d.ts +11 -0
  57. package/dist/better-auth/store/offline/archive-revival.js +25 -0
  58. package/dist/better-auth/store/offline/baseline-store.d.ts +11 -7
  59. package/dist/better-auth/store/offline/baseline-store.js +15 -12
  60. package/dist/better-auth/store/offline/contract-gate.d.ts +18 -0
  61. package/dist/better-auth/store/offline/contract-gate.js +35 -0
  62. package/dist/better-auth/store/offline/module-archive.d.ts +41 -0
  63. package/dist/better-auth/store/offline/module-archive.js +95 -0
  64. package/dist/better-auth/store/offline/module-delete.d.ts +22 -0
  65. package/dist/better-auth/store/offline/module-delete.js +99 -0
  66. package/dist/better-auth/store/offline/module-switches.d.ts +32 -0
  67. package/dist/better-auth/store/offline/module-switches.js +113 -0
  68. package/dist/better-auth/store/offline/name-changes.d.ts +4 -1
  69. package/dist/better-auth/store/offline/name-changes.js +5 -2
  70. package/dist/better-auth/store/offline/offline-steps.d.ts +21 -7
  71. package/dist/better-auth/store/offline/offline-steps.js +29 -20
  72. package/dist/better-auth/store/offline/retired-watch.d.ts +5 -0
  73. package/dist/better-auth/store/offline/retired-watch.js +43 -0
  74. package/dist/better-auth/store/offline/settings-names.d.ts +3 -2
  75. package/dist/better-auth/store/offline/settings-names.js +10 -3
  76. package/dist/better-auth/store/offline/store-model.d.ts +27 -1
  77. package/dist/better-auth/store/offline/store-model.js +22 -5
  78. package/dist/better-auth/store/resources-outside.js +1 -1
  79. package/dist/better-auth/store/step-record.d.ts +13 -0
  80. package/dist/better-auth/store/step-record.js +59 -0
  81. package/dist/better-auth/store/steps/index.js +6 -1
  82. package/dist/better-auth/store/steps/legacy-versions.d.ts +7 -0
  83. package/dist/better-auth/store/steps/legacy-versions.js +4 -0
  84. package/dist/better-auth/store/steps/organizations/003-default-organization.js +113 -0
  85. package/dist/better-auth/store/steps/render.d.ts +3 -0
  86. package/dist/better-auth/store/steps/render.js +48 -25
  87. package/dist/better-auth/store/steps/step-lint.d.ts +14 -0
  88. package/dist/better-auth/store/steps/step-lint.js +31 -10
  89. package/dist/better-auth/store/steps/step.d.ts +18 -0
  90. package/dist/better-auth/store/steps/step.js +7 -1
  91. package/dist/better-auth/store/store-db.d.ts +6 -0
  92. package/dist/better-auth/store/store-db.js +11 -5
  93. package/dist/better-auth/store/store-names.d.ts +4 -0
  94. package/dist/better-auth/store/store-sql.d.ts +1 -1
  95. package/dist/better-auth/token-standing.js +12 -7
  96. package/dist/better-auth/users.d.ts +7 -2
  97. package/dist/better-auth/users.js +25 -3
  98. package/dist/built-in-resources.js +1 -1
  99. package/dist/calls/calls-module.js +42 -0
  100. package/dist/calls/calls-sql.js +4 -30
  101. package/dist/changes/capture-names.d.ts +3 -1
  102. package/dist/changes/capture-names.js +5 -2
  103. package/dist/changes/capture-schema-sql.d.ts +10 -0
  104. package/dist/changes/capture-schema-sql.js +21 -0
  105. package/dist/changes/capture-schema.d.ts +0 -18
  106. package/dist/changes/capture-schema.js +1 -74
  107. package/dist/changes/capture-sql.js +30 -24
  108. package/dist/changes/changes-input.js +36 -0
  109. package/dist/changes/changes-module.js +44 -0
  110. package/dist/changes/read-capture.js +67 -0
  111. package/dist/changes/steps/001-outbox.js +23 -0
  112. package/dist/channels/sends-module.js +37 -0
  113. package/dist/channels/sends-schema-sql.js +5 -5
  114. package/dist/comments/comments-module.js +30 -0
  115. package/dist/comments/comments-sql.js +1 -22
  116. package/dist/computed/buckets-sql.d.ts +5 -1
  117. package/dist/computed/buckets-sql.js +39 -46
  118. package/dist/computed/{buckets-schema.d.ts → buckets-targets.d.ts} +2 -3
  119. package/dist/computed/buckets-targets.js +50 -0
  120. package/dist/computed/computed-input.js +65 -0
  121. package/dist/computed/computed-module.js +102 -0
  122. package/dist/computed/formula-sql.js +14 -1
  123. package/dist/computed/read-computed.js +100 -0
  124. package/dist/computed/rollup-sql.js +13 -10
  125. package/dist/config-exports.d.ts +2 -2
  126. package/dist/create-admin.js +21 -5
  127. package/dist/derived/derived-module.js +89 -0
  128. package/dist/derived/derived-sql.js +1 -47
  129. package/dist/functions/define-function.d.ts +10 -4
  130. package/dist/functions/routes.js +5 -3
  131. package/dist/functions/supabase-routes.js +7 -5
  132. package/dist/history/history-module.js +34 -0
  133. package/dist/index.d.ts +19 -28
  134. package/dist/index.js +11 -21
  135. package/dist/internal.d.ts +30 -10
  136. package/dist/internal.js +26 -8
  137. package/dist/jobs/functions-sql.js +7 -11
  138. package/dist/jobs/job-data.js +36 -0
  139. package/dist/jobs/job-types.d.ts +6 -3
  140. package/dist/jobs/jobs-module.d.ts +5 -0
  141. package/dist/jobs/jobs-module.js +84 -0
  142. package/dist/jobs/run-job.d.ts +1 -1
  143. package/dist/jobs/run-job.js +7 -5
  144. package/dist/jobs/runtime.d.ts +9 -4
  145. package/dist/jobs/runtime.js +11 -6
  146. package/dist/jobs/schema.d.ts +0 -11
  147. package/dist/jobs/schema.js +1 -59
  148. package/dist/jobs/steps/001-pg-boss-45.js +483 -0
  149. package/dist/live/notices-module.js +30 -0
  150. package/dist/live/notices-sql.js +2 -1
  151. package/dist/mail/feedback/feedback-schema.js +3 -30
  152. package/dist/mail/feedback/mail-feedback-module.js +37 -0
  153. package/dist/mail/unsubscribe/unsubscribe-schema.js +3 -21
  154. package/dist/mail/unsubscribe/unsubscribes-module.js +31 -0
  155. package/dist/migration-record/check-record.d.ts +9 -7
  156. package/dist/migration-record/check-record.js +12 -11
  157. package/dist/migration-record/module-needs.js +30 -0
  158. package/dist/migration-record/read-record.js +27 -15
  159. package/dist/migration-record/record-model.d.ts +7 -2
  160. package/dist/migration-record/record-model.js +14 -6
  161. package/dist/migration-record/startup-decision.js +18 -7
  162. package/dist/migration-sql/additive-statements.d.ts +4 -0
  163. package/dist/migration-sql/additive-statements.js +105 -0
  164. package/dist/notifications/devices-module.js +61 -0
  165. package/dist/notifications/history-module.js +50 -0
  166. package/dist/notifications/notifications-targets.js +23 -0
  167. package/dist/notifications/read-table.js +16 -0
  168. package/dist/notifications/schema-sql.js +1 -22
  169. package/dist/notifications/schema.js +1 -101
  170. package/dist/notifications/table-names.js +40 -0
  171. package/dist/organization-scope/app-scope.js +38 -0
  172. package/dist/organization-scope/auth-request-organization.js +71 -0
  173. package/dist/organization-scope/organization-tables.js +20 -0
  174. package/dist/organization-scope/sign-in-organization.js +21 -0
  175. package/dist/package.js +1 -1
  176. package/dist/personal-mail/shared-sender-store.js +4 -2
  177. package/dist/realtime/relay/realtime-relay-module.js +37 -0
  178. package/dist/relation-found.js +6 -0
  179. package/dist/relay/read-relay.js +85 -0
  180. package/dist/relay/realtime-members-sql.js +51 -28
  181. package/dist/relay/relay-module.js +53 -0
  182. package/dist/relay/relay-targets.js +28 -0
  183. package/dist/relay/session-end.js +1 -3
  184. package/dist/relay/sessions-sql.js +4 -27
  185. package/dist/rest/table-routes.js +9 -2
  186. package/dist/schema-modules/feature-schemas-sql.d.ts +40 -0
  187. package/dist/schema-modules/feature-schemas-sql.js +51 -0
  188. package/dist/schema-modules/module-difference.d.ts +31 -0
  189. package/dist/schema-modules/module-difference.js +98 -0
  190. package/dist/schema-modules/modules-sql.js +13 -0
  191. package/dist/schema-modules/modules.d.ts +37 -0
  192. package/dist/schema-modules/modules.js +56 -0
  193. package/dist/schema-modules/needed-modules.d.ts +41 -0
  194. package/dist/schema-modules/needed-modules.js +61 -0
  195. package/dist/schema-modules/resource-difference.js +83 -0
  196. package/dist/schema-modules/schema-module.d.ts +112 -0
  197. package/dist/schema-modules/schema-module.js +8 -0
  198. package/dist/status/status-module.js +63 -0
  199. package/dist/status/status-targets.js +21 -0
  200. package/dist/types.d.ts +6 -1
  201. package/dist/user-tables/reloading-admin.d.ts +1 -0
  202. package/dist/user-tables/reloading-admin.js +1 -0
  203. package/dist/user-tables/schema-sql.js +1 -14
  204. package/dist/user-tables/schema.js +4 -27
  205. package/dist/user-tables/user-tables-module.js +38 -0
  206. package/dist/webhooks/table/delivery-log-module.js +36 -0
  207. package/dist/webhooks/table/owner-roles.js +3 -2
  208. package/dist/webhooks/table/schema-sql.js +27 -26
  209. package/dist/webhooks/table/webhooks-schema-module.js +63 -0
  210. package/dist/webhooks/table/webhooks-targets.js +26 -0
  211. package/dist/webhooks/webhooks.js +1 -1
  212. package/dist/workflows/custom-steps/custom-steps-module.js +51 -0
  213. package/dist/workflows/custom-steps/custom-steps-sql.js +10 -7
  214. package/dist/workflows/custom-steps/runners-sql.js +10 -7
  215. package/dist/workflows/read-catalogue.js +23 -0
  216. package/dist/workflows/schema-sql.js +12 -9
  217. package/dist/workflows/status-sql.js +12 -6
  218. package/dist/workflows/storage/storage-module.js +39 -0
  219. package/dist/workflows/storage/storage-sql.js +8 -5
  220. package/dist/workflows/workflows-schema-module.js +49 -0
  221. package/dist/workflows/workflows-tables-sql.js +32 -0
  222. package/dist/workflows/workflows-targets.js +16 -0
  223. package/package.json +6 -6
  224. package/dist/assistant/query-runner/runner-plan.js +0 -30
  225. package/dist/better-auth/store/migrations-table.js +0 -27
  226. package/dist/better-auth/store/modules-off.js +0 -17
  227. package/dist/calls/calls-sql.d.ts +0 -11
  228. package/dist/changes/capture-plan.js +0 -79
  229. package/dist/channels/sends-schema.d.ts +0 -7
  230. package/dist/channels/sends-schema.js +0 -18
  231. package/dist/comments/comments-sql.d.ts +0 -14
  232. package/dist/computed/buckets-plan.d.ts +0 -2
  233. package/dist/computed/buckets-plan.js +0 -88
  234. package/dist/computed/buckets-schema.js +0 -39
  235. package/dist/computed/computed-plan.js +0 -81
  236. package/dist/computed/computed-schema.d.ts +0 -16
  237. package/dist/computed/computed-schema.js +0 -63
  238. package/dist/derived/derived-sql.d.ts +0 -12
  239. package/dist/mail/feedback/feedback-schema.d.ts +0 -7
  240. package/dist/mail/unsubscribe/unsubscribe-schema.d.ts +0 -10
  241. package/dist/notifications/schema.d.ts +0 -14
  242. package/dist/realtime/relay/relay-schema.d.ts +0 -7
  243. package/dist/realtime/relay/relay-schema.js +0 -20
  244. package/dist/relay/realtime-members-schema.js +0 -67
  245. package/dist/relay/relay-schema.d.ts +0 -14
  246. package/dist/relay/relay-schema.js +0 -28
  247. package/dist/status/schema.d.ts +0 -12
  248. package/dist/status/schema.js +0 -33
  249. package/dist/user-tables/schema.d.ts +0 -11
  250. package/dist/webhooks/table/schema.d.ts +0 -16
  251. package/dist/webhooks/table/schema.js +0 -56
  252. package/dist/workflows/schema.d.ts +0 -13
  253. package/dist/workflows/schema.js +0 -88
@@ -0,0 +1,112 @@
1
+ import { Db } from "@protobase/query";
2
+ //#region src/schema-modules/schema-module.d.ts
3
+ /** The names a module's statements take from the app's config, such as the schema it lives in, by role. */
4
+ export type ModuleNames = Record<string, string>;
5
+ /**
6
+ * One step of the chain, numbered from 1. Once released its statements never change: a later change to the module's
7
+ * tables is a step of its own, with the next number.
8
+ */
9
+ export type SchemaStep = {
10
+ step: number;
11
+ name: string;
12
+ /** What it makes, the comment above its statements. */
13
+ title: string;
14
+ /** Whether the code of the version before still runs once it is applied: a step that only adds is. */
15
+ additive: boolean;
16
+ sql: (names: ModuleNames) => string;
17
+ };
18
+ /**
19
+ * Derived objects written whole with `create or replace`, or dropped and made again, at a version: a change to them
20
+ * bumps `version`. `compatibleFrom` is the oldest version whose code still runs on this one: replacing an older one
21
+ * breaks older code, so the migration that does is not additive.
22
+ */
23
+ export type Replaceable = {
24
+ name: string;
25
+ title: string;
26
+ version: number;
27
+ compatibleFrom: number;
28
+ sql: (names: ModuleNames) => string;
29
+ };
30
+ /** A table as SQL names it, unqualified without `schema`. */
31
+ export type TableName = {
32
+ schema?: string;
33
+ name: string;
34
+ };
35
+ /**
36
+ * Derived objects of each of the app's resources that need them, such as the triggers that capture a resource's
37
+ * changes, written whole for one resource from its input (`ResourceInput`) at a version, as a `Replaceable` is: once
38
+ * more when its statements change. `drop` removes what it made on `table`, and `column` when its objects are a
39
+ * column's; without `drop` they stay once no resource needs them, for a migration of the project's own to drop a
40
+ * deploy later, and the model keeps them, so a resource that needs them again finds them. A resource that no longer needs them keeps them while another resource
41
+ * still does when `keptWhileOthers`, and loses them once none does. `replace` removes what an earlier input made at the
42
+ * same place before its statements are written again, where they cannot replace it themselves, such as a generated
43
+ * column; the removals of every resource replaceable go before any writes, the last replaceable's first. `after`
44
+ * rebuilds what the objects derive from the data, such as a rollup's values, once the migration's transaction commits,
45
+ * in its `.after.sql`: each statement recomputes from the source, so running it again is safe.
46
+ */
47
+ export type ResourceReplaceable = {
48
+ name: string;
49
+ /** What it makes for one resource, the comment above its statements, followed by the resource's name. */
50
+ title: string;
51
+ version: number;
52
+ compatibleFrom: number;
53
+ sql: (names: ModuleNames, input: unknown) => string;
54
+ /** `key`: the resource's key in the input, such as a derived value's name. */
55
+ drop?: (names: ModuleNames, table: TableName, column: string | undefined, key: string) => string;
56
+ replace?: (names: ModuleNames, table: TableName, column?: string) => string;
57
+ after?: (names: ModuleNames, input: unknown) => string;
58
+ keptWhileOthers: boolean;
59
+ };
60
+ /**
61
+ * One resource's input to a `ResourceReplaceable`: the table its objects are on, the column when they are a column's,
62
+ * and what its statements are made from. `kept`: the resource no longer needs them, so they are written only to follow
63
+ * it while they are kept.
64
+ */
65
+ export type ResourceInput = {
66
+ table: TableName;
67
+ column?: string;
68
+ input: unknown;
69
+ kept?: boolean;
70
+ };
71
+ /** What the app gives a module: its names, and each resource replaceable's input by resource. */
72
+ export type ModuleInput = {
73
+ names: ModuleNames;
74
+ resources: Record<string, Record<string, ResourceInput>>;
75
+ };
76
+ /** The input of a module that takes nothing from the app. */
77
+ export declare const noInput: ModuleInput;
78
+ /** One resource's objects as the model holds them: their version, a digest of their statements, their table and column. */
79
+ export type ResourceEntry = {
80
+ version: number;
81
+ digest: string;
82
+ table: TableName;
83
+ column?: string;
84
+ };
85
+ /**
86
+ * What a module has in the database, as the snapshot, the record and the runtime hold it: `names` and `resources`, by
87
+ * resource replaceable then resource, only when it has any.
88
+ */
89
+ export type ModuleModel = {
90
+ lastStep: number;
91
+ replaceables: Record<string, number>;
92
+ names?: ModuleNames;
93
+ resources?: Record<string, Record<string, ResourceEntry>>;
94
+ };
95
+ export type SchemaModule = {
96
+ /** What it is in messages, such as "the jobs schema". */
97
+ label: string;
98
+ /** What a migration writes of it, the comment above its statements, such as "The jobs schema this version of Protobase needs". */
99
+ title: string;
100
+ steps: SchemaStep[];
101
+ /** In the order they are written, after the steps. */
102
+ replaceables: Replaceable[];
103
+ /** Written after the replaceables, each resource's in the order of the input. */
104
+ resourceReplaceables: ResourceReplaceable[];
105
+ /**
106
+ * What the database has of it for `input`, read once from its catalogue by `protobase migration baseline` and by a
107
+ * release's migrate, which compare with the database; `undefined` when it has none of it. Throws on a state no step
108
+ * records.
109
+ */
110
+ read: (db: Db, input: ModuleInput) => Promise<ModuleModel | undefined>;
111
+ };
112
+ //#endregion
@@ -0,0 +1,8 @@
1
+ //#region src/schema-modules/schema-module.ts
2
+ /** The input of a module that takes nothing from the app. */
3
+ const noInput = {
4
+ names: {},
5
+ resources: {}
6
+ };
7
+ //#endregion
8
+ export { noInput };
@@ -0,0 +1,63 @@
1
+ import { qualified } from "../notifications/schema-sql.js";
2
+ import { cascadesFrom, columnNumbers } from "../notifications/read-table.js";
3
+ import { regclass } from "../notifications/schema.js";
4
+ import { statusesTableSql } from "./schema-sql.js";
5
+ //#region src/status/status-module.ts
6
+ const columns = [
7
+ "user_id",
8
+ "availability",
9
+ "text",
10
+ "clears_at",
11
+ "updated_at"
12
+ ];
13
+ /**
14
+ * The statuses table as the database has it: step 1 once it has each column and the foreign key that deletes a user's
15
+ * status with the user. Refuses one without them, naming what it lacks.
16
+ */
17
+ const readStatus = async (db, { names }) => {
18
+ const statuses = qualified({
19
+ schema: names.schema,
20
+ table: names.table
21
+ });
22
+ const oid = await regclass(db, statuses);
23
+ if (oid === null) return;
24
+ const numbers = await columnNumbers(db, oid, {
25
+ schema: names.schema,
26
+ table: names.table,
27
+ columns: Object.fromEntries(columns.map((column) => [column, column]))
28
+ });
29
+ const missing = columns.find((column) => numbers[column] === void 0);
30
+ if (missing !== void 0) throw new Error(`The statuses table ${statuses} has no column "${missing}", which no step of this version of Protobase records`);
31
+ if (!await cascadesFrom(db, oid, numbers.user_id, names.users)) throw new Error(`The statuses table ${statuses} needs a foreign key from "user_id" to ${names.users} with on delete cascade, so a deleted user's status goes with them`);
32
+ return {
33
+ lastStep: 1,
34
+ replaceables: {},
35
+ names
36
+ };
37
+ };
38
+ /**
39
+ * The statuses table of people's own status, in the schema `status` names (`names.schema`), its user column pointing
40
+ * at the auth store's users (`names.users`). Never dropped.
41
+ */
42
+ const statusModule = {
43
+ label: "the statuses table of status",
44
+ title: "The statuses table of people's own status",
45
+ steps: [{
46
+ step: 1,
47
+ name: "statuses",
48
+ title: "The statuses table",
49
+ additive: true,
50
+ sql: (names) => `${statusesTableSql({
51
+ schema: names.schema,
52
+ table: names.table
53
+ }, {
54
+ type: names.user_id_type,
55
+ references: `${names.users} (id)`
56
+ }).join(";\n")};`
57
+ }],
58
+ replaceables: [],
59
+ resourceReplaceables: [],
60
+ read: readStatus
61
+ };
62
+ //#endregion
63
+ export { statusModule };
@@ -0,0 +1,21 @@
1
+ import { checkStatusAuth, statusNames } from "./options.js";
2
+ import { usersTarget } from "../notifications/table-names.js";
3
+ //#region src/status/status-targets.ts
4
+ /**
5
+ * The schema module `status` needs, under the names its options give it, pointing at the users of the auth store
6
+ * `store` names. Refuses an app without sign-in, as it has no organizations (`checkStatusAuth`).
7
+ */
8
+ const statusTargets = (options, store) => {
9
+ if (!store) checkStatusAuth(void 0);
10
+ const { users, idType } = usersTarget(store);
11
+ return { status: {
12
+ names: {
13
+ ...statusNames(options),
14
+ users,
15
+ user_id_type: idType
16
+ },
17
+ resources: {}
18
+ } };
19
+ };
20
+ //#endregion
21
+ export { statusTargets };
package/dist/types.d.ts CHANGED
@@ -5,7 +5,7 @@ import { RealtimePrune } from "./realtime/realtime-prune.js";
5
5
  import { Hono } from "hono";
6
6
  import { PageModel } from "@protobase/layout";
7
7
  import { KeyType, ResourceModel, ViewModel } from "@protobase/schema";
8
- import { Db } from "@protobase/query";
8
+ import { Db, ScopedTables } from "@protobase/query";
9
9
  //#region src/types.d.ts
10
10
  export type TenantValue = string | number;
11
11
  export type User = {
@@ -169,5 +169,10 @@ export type Admin = Hono<AdminEnv> & {
169
169
  decryptField: FieldDecrypter;
170
170
  metaPath: string;
171
171
  unsubscribe?: UnsubscribeLinks;
172
+ /**
173
+ * The tables whose rows belong to one organization, which the app's functions, jobs and hooks see one organization
174
+ * of (`startJobs`' `scope`), read once the store says whether organizations were on.
175
+ */
176
+ organizationScope: () => Promise<ScopedTables>;
172
177
  };
173
178
  //#endregion
@@ -41,5 +41,6 @@ export declare const reloadingAdmin: ({ first, version, readVersion, readTables,
41
41
  stopHolding: () => Promise<undefined>;
42
42
  decryptField: FieldDecrypter;
43
43
  metaPath: string;
44
+ organizationScope: () => Promise<import("@protobase/query").ScopedTables>;
44
45
  };
45
46
  //#endregion
@@ -78,6 +78,7 @@ const reloadingAdmin = ({ first, version, readVersion, readTables, build, report
78
78
  stopHolding,
79
79
  decryptField: first.decryptField,
80
80
  metaPath: first.metaPath,
81
+ organizationScope: first.organizationScope,
81
82
  ...first.unsubscribe && { unsubscribe: first.unsubscribe },
82
83
  reload
83
84
  });
@@ -23,8 +23,6 @@ const tableNameColumn = `table_name text not null unique generated always as (ca
23
23
  const tenantKeyColumn = "tenant_key text not null generated always as (coalesce(organization_id, '-')) stored";
24
24
  /** A name is unique among the definitions of one organization, or of the app without organizations. */
25
25
  const nameIndexesSql = () => [`create unique index tables_name_key on ${definitionsSchema}.tables (name) where organization_id is null`, `create unique index tables_organization_name_key on ${definitionsSchema}.tables (organization_id, name) where organization_id is not null`];
26
- /** Gives a definitions table made before new definitions started at version 1 that default. */
27
- const versionDefaultSql = () => `alter table ${definitionsSchema}.tables alter column version set default 1`;
28
26
  /**
29
27
  * The fields of each definition, in order, each with its label and type; a decimal names its precision and scale. A
30
28
  * field belongs to its table's organization: the foreign key compares both, so no field reaches another organization's
@@ -50,17 +48,6 @@ const fieldsSql = () => `create table ${definitionsSchema}.fields (
50
48
  * `position` only from an index that reaches it with `table_id` pinned. It also reaches a fields table made before it.
51
49
  */
52
50
  const fieldsPositionIndexSql = () => `create index if not exists fields_position_idx on ${definitionsSchema}.fields (table_id, position)`;
53
- /**
54
- * Brings a definitions table made before organizations to the shape of `tablesSql`: a name unique per organization and
55
- * the served name.
56
- */
57
- const organizationsSql = () => [
58
- `alter table ${definitionsSchema}.tables add column organization_id text, add column ${tableNameColumn}, add column ${tenantKeyColumn}, add unique (id, tenant_key)`,
59
- `alter table ${definitionsSchema}.tables drop constraint tables_name_key`,
60
- ...nameIndexesSql()
61
- ];
62
- /** Ties the fields made before organizations to their table's organization, as `fieldsSql` does. */
63
- const fieldsOrganizationSql = () => `alter table ${definitionsSchema}.fields add column organization_id text, add column ${tenantKeyColumn}, add foreign key (table_id, tenant_key) references ${definitionsSchema}.tables (id, tenant_key) on delete cascade`;
64
51
  const schemasSql = () => [
65
52
  "create extension if not exists pg_trgm",
66
53
  `create schema if not exists ${definitionsSchema}`,
@@ -70,4 +57,4 @@ const schemasSql = () => [
70
57
  `grant usage, create on schema ${userTablesSchema} to current_user`
71
58
  ];
72
59
  //#endregion
73
- export { fieldsOrganizationSql, fieldsPositionIndexSql, fieldsSql, nameIndexesSql, organizationsSql, schemasSql, tablesSql, versionDefaultSql };
60
+ export { fieldsPositionIndexSql, fieldsSql, nameIndexesSql, schemasSql, tablesSql };
@@ -1,9 +1,7 @@
1
- import { migrationCommand } from "../changes/capture-schema.js";
2
1
  import { definitionsSchema, userTablesSchema } from "./names.js";
3
- import { fieldsOrganizationSql, fieldsPositionIndexSql, fieldsSql, nameIndexesSql, organizationsSql, schemasSql, tablesSql, versionDefaultSql } from "./schema-sql.js";
4
2
  import { sql } from "kysely";
5
3
  //#region src/user-tables/schema.ts
6
- const current = (found) => found.tables && found.versionDefault && found.organizations && found.fields && found.positionIndex && found.data && found.trgm;
4
+ /** What the database has of the schemas user tables need, read from the catalogue. `to_regclass` resolves an index too. */
7
5
  const readUserTablesSchema = async (db) => {
8
6
  const { rows } = await sql`select
9
7
  to_regclass(${`${definitionsSchema}.tables`}) is not null as tables,
@@ -15,28 +13,7 @@ const readUserTablesSchema = async (db) => {
15
13
  exists (select from pg_extension where extname = 'pg_trgm') as trgm`.execute(db);
16
14
  return rows[0];
17
15
  };
18
- /**
19
- * The SQL that adds what user tables need: pg_trgm, the definitions schema with its `tables` and `fields`, and the
20
- * schema the tables themselves live in. `undefined` when current. Nothing is dropped but the unique constraint on a
21
- * definition's name, which a name unique per organization replaces.
22
- */
23
- const userTablesMigration = async (db) => {
24
- const found = await readUserTablesSchema(db);
25
- if (current(found)) return void 0;
26
- const tables = found.tables ? [...found.versionDefault ? [] : [versionDefaultSql()], ...found.organizations ? [] : organizationsSql()] : [tablesSql(), ...nameIndexesSql()];
27
- const fields = found.fields ? found.tables && !found.organizations ? [fieldsOrganizationSql()] : [] : [fieldsSql()];
28
- return `${[
29
- ...schemasSql(),
30
- ...tables,
31
- ...fields,
32
- fieldsPositionIndexSql()
33
- ].join(";\n\n")};`;
34
- };
35
- /** Refuses to go on while the schemas of user tables are missing; the project's migrations add them. */
36
- const checkUserTablesSchema = async (db) => {
37
- const found = await readUserTablesSchema(db);
38
- if (current(found)) return;
39
- throw new Error(`The ${definitionsSchema} or ${userTablesSchema} schema, the default of a definition's version, a definition's organization, the position index of its fields, or pg_trgm, is missing, and userTables keeps the tables users add there. Write it as a migration with \`${migrationCommand}\`, apply it with the project's migrations, then start again.`);
40
- };
16
+ /** Whether every part this version's step makes is there. */
17
+ const userTablesCurrent = (found) => found.tables && found.versionDefault && found.organizations && found.fields && found.positionIndex && found.data && found.trgm;
41
18
  //#endregion
42
- export { checkUserTablesSchema, userTablesMigration };
19
+ export { readUserTablesSchema, userTablesCurrent };
@@ -0,0 +1,38 @@
1
+ import { definitionsSchema, userTablesSchema } from "./names.js";
2
+ import { readUserTablesSchema, userTablesCurrent } from "./schema.js";
3
+ import { fieldsPositionIndexSql, fieldsSql, nameIndexesSql, schemasSql, tablesSql } from "./schema-sql.js";
4
+ //#region src/user-tables/user-tables-module.ts
5
+ /**
6
+ * pg_trgm, the definitions schema with its `tables` and `fields`, and the schema the tables users add live in. Those
7
+ * tables are data, not schema: admins create them while the app serves, and no migration writes them. Never dropped.
8
+ */
9
+ const userTablesModule = {
10
+ label: `the ${definitionsSchema} and ${userTablesSchema} schemas of user tables`,
11
+ title: "The schemas of the tables users add and of their definitions, and pg_trgm",
12
+ steps: [{
13
+ step: 1,
14
+ name: "user_tables",
15
+ title: "The definitions of user tables and the schema of the tables themselves",
16
+ additive: true,
17
+ sql: () => `${[
18
+ ...schemasSql(),
19
+ tablesSql(),
20
+ ...nameIndexesSql(),
21
+ fieldsSql(),
22
+ fieldsPositionIndexSql()
23
+ ].join(";\n\n")};`
24
+ }],
25
+ replaceables: [],
26
+ resourceReplaceables: [],
27
+ read: async (db) => {
28
+ const found = await readUserTablesSchema(db);
29
+ if (!found.tables) return;
30
+ if (!userTablesCurrent(found)) throw new Error(`The ${definitionsSchema} schema lacks the default of a definition's version, a definition's organization, the position index of its fields, the ${userTablesSchema} schema or pg_trgm, which no step of this version of Protobase records: bring it there with \`protobase migration\` and \`protobase migrate\` of the Protobase release before this one first, then run this command again`);
31
+ return {
32
+ lastStep: 1,
33
+ replaceables: {}
34
+ };
35
+ }
36
+ };
37
+ //#endregion
38
+ export { userTablesModule };
@@ -0,0 +1,36 @@
1
+ import { quoteIdent } from "../../changes/capture-sql.js";
2
+ import { deliveryLogIndexes, deliveryLogIndexesSql, deliveryLogSql } from "./schema-sql.js";
3
+ import { hasIndexes } from "../../has-indexes.js";
4
+ import { relationFound } from "../../relation-found.js";
5
+ //#region src/webhooks/table/delivery-log-module.ts
6
+ /** The delivery log as the database has it: step 1 once it is there with every index. Refuses one without them, which no step records. */
7
+ const readDeliveryLog = async (db, { names }) => {
8
+ const schema = names.schema;
9
+ if (!await relationFound(db, `${quoteIdent(schema)}."delivery_log"`)) return;
10
+ if (!await hasIndexes(db, schema, "delivery_log", deliveryLogIndexes)) throw new Error(`The delivery log in schema "${schema}" lacks indexes no step of this version of Protobase records: add them with \`protobase migration\` and \`protobase migrate\` of Protobase 0.14.2 first, then run this command again`);
11
+ return {
12
+ lastStep: 1,
13
+ replaceables: {},
14
+ names
15
+ };
16
+ };
17
+ /**
18
+ * The log of every try of the subscriptions' deliveries, with `deliveryLog`, in the webhooks schema (`names.schema`):
19
+ * a module of its own, after the webhooks schema whose subscriptions it points at, so turning it on later writes it alone.
20
+ */
21
+ const webhookDeliveryLogModule = {
22
+ label: "the webhook delivery log",
23
+ title: "The log of every try of the webhook subscriptions' deliveries",
24
+ steps: [{
25
+ step: 1,
26
+ name: "delivery_log",
27
+ title: "The delivery log and its indexes",
28
+ additive: true,
29
+ sql: (names) => `${deliveryLogSql(names.schema)};\n${deliveryLogIndexesSql(names.schema)};`
30
+ }],
31
+ replaceables: [],
32
+ resourceReplaceables: [],
33
+ read: readDeliveryLog
34
+ };
35
+ //#endregion
36
+ export { webhookDeliveryLogModule };
@@ -1,5 +1,6 @@
1
1
  import { parseRoles } from "../../better-auth/parse-roles.js";
2
2
  import { effectiveRoles, globalRoles, parseAppRoles } from "../../better-auth/organizations/app-roles.js";
3
+ import { acrossOrganizations } from "../../organization-scope/sign-in-organization.js";
3
4
  import { resolveActiveRole } from "../../better-auth/roles/active-role.js";
4
5
  import { storeSqlOf } from "../../better-auth/store/store-sql.js";
5
6
  import { mayBeId, storedId } from "../../better-auth/store/store-reads.js";
@@ -21,8 +22,8 @@ const ownersRoles = async (auth, owners) => {
21
22
  const tenants = auth.organizations ? [...new Set(owners.flatMap((owner) => owner.tenant !== void 0 && standing.has(idOf(owner.id)) ? [idOf(String(owner.tenant))] : []))].filter((id) => mayBeId(context.options, id)) : [];
22
23
  const member = store.table("member");
23
24
  const m = member.columns;
24
- const { rows: members } = tenants.length === 0 ? { rows: [] } : await sql`select ${m.user_id} as user_id, ${m.organization_id} as organization_id, ${m.app_roles} as app_roles from ${member}
25
- where ${m.user_id} = any(${[...standing.keys()]}) and ${m.organization_id} = any(${tenants})`.execute(store.db);
25
+ const { rows: members } = tenants.length === 0 ? { rows: [] } : await acrossOrganizations("the owners of webhooks, workflows and comments act in their own organizations, one batch read for them all", () => sql`select ${m.user_id} as user_id, ${m.organization_id} as organization_id, ${m.app_roles} as app_roles from ${member}
26
+ where ${m.user_id} = any(${[...standing.keys()]}) and ${m.organization_id} = any(${tenants})`.execute(store.db));
26
27
  const memberships = new Map(members.map((member) => [memberKey(member.user_id, member.organization_id), parseAppRoles(member.app_roles)]));
27
28
  return owners.map(({ id, tenant }) => {
28
29
  const user = standing.get(idOf(id));
@@ -1,6 +1,6 @@
1
1
  import { jobsSchema } from "../../jobs/schema.js";
2
2
  import { quoteIdent } from "../../changes/capture-sql.js";
3
- /** The comment the schema's functions carry, which the startup check reads. */
3
+ /** The comment the schema's functions carry, which `protobase migration baseline` reads. */
4
4
  const webhooksComment = `Protobase webhooks 2`;
5
5
  /** The version a function's comment names, `undefined` when it is not one Protobase wrote. */
6
6
  const commentVersion = (comment) => {
@@ -41,21 +41,21 @@ const subscriptionsSql = (schema, changesSchema) => `create table if not exists
41
41
  "resend_failed" boolean not null default false
42
42
  )`;
43
43
  /**
44
- * An index for each read of the subscriptions the API takes: the tenant and owner every caller's rows keep to, the
45
- * sorts and filter the list offers, and pg_trgm ones for its search over the name and URL.
44
+ * An index for each read of the subscriptions the API takes, by name: the tenant and owner every caller's rows keep to,
45
+ * the sorts and filter the list offers, and pg_trgm ones for its search over the name and URL.
46
46
  */
47
- const subscriptionsIndexesSql = (schema) => {
48
- const table = `${quoteIdent(schema)}."subscriptions"`;
49
- return `create extension if not exists pg_trgm;
50
- create index if not exists "subscriptions_tenant" on ${table} ("tenant_id");
51
- create index if not exists "subscriptions_owner" on ${table} ("owner_id");
52
- create index if not exists "subscriptions_created_at" on ${table} ("created_at");
53
- create index if not exists "subscriptions_name" on ${table} ("name");
54
- create index if not exists "subscriptions_enabled" on ${table} ("enabled");
55
- create index if not exists "subscriptions_last_success_at" on ${table} ("last_success_at");
56
- create index if not exists "subscriptions_name_search" on ${table} using gin ("name" gin_trgm_ops);
57
- create index if not exists "subscriptions_url_search" on ${table} using gin ("url" gin_trgm_ops)`;
58
- };
47
+ const subscriptionsIndexList = [
48
+ ["subscriptions_tenant", "(\"tenant_id\")"],
49
+ ["subscriptions_owner", "(\"owner_id\")"],
50
+ ["subscriptions_created_at", "(\"created_at\")"],
51
+ ["subscriptions_name", "(\"name\")"],
52
+ ["subscriptions_enabled", "(\"enabled\")"],
53
+ ["subscriptions_last_success_at", "(\"last_success_at\")"],
54
+ ["subscriptions_name_search", "using gin (\"name\" gin_trgm_ops)"],
55
+ ["subscriptions_url_search", "using gin (\"url\" gin_trgm_ops)"]
56
+ ];
57
+ const subscriptionsIndexes = subscriptionsIndexList.map(([name]) => name);
58
+ const subscriptionsIndexesSql = (schema) => `create extension if not exists pg_trgm;\n${subscriptionsIndexList.map(([name, columns]) => `create index if not exists "${name}" on ${quoteIdent(schema)}."subscriptions" ${columns}`).join(";\n")}`;
59
59
  const retryJobs = (where) => `update ${jobsSchema}.job
60
60
  set state = 'retry', retry_limit = retry_limit + 1, completed_on = null,
61
61
  start_after = greatest(start_after, ${jobsSchema}.job_now()), keep_until = greatest(keep_until, ${jobsSchema}.job_now() + interval '14 days')
@@ -131,15 +131,16 @@ const deliveryLogSql = (schema) => `create table if not exists ${quoteIdent(sche
131
131
  "duration_ms" integer not null,
132
132
  "at" timestamptz not null default now()
133
133
  )`;
134
- /** An index for each filter and sort of the delivery log the API takes. */
135
- const deliveryLogIndexesSql = (schema) => {
136
- const table = `${quoteIdent(schema)}."delivery_log"`;
137
- return `create index if not exists "delivery_log_subscription" on ${table} ("subscription_id", "at");
138
- create index if not exists "delivery_log_at" on ${table} ("at");
139
- create index if not exists "delivery_log_event_id" on ${table} ("event_id");
140
- create index if not exists "delivery_log_event_type" on ${table} ("event_type");
141
- create index if not exists "delivery_log_status" on ${table} ("status");
142
- create index if not exists "delivery_log_status_code" on ${table} ("status_code")`;
143
- };
134
+ /** An index for each filter and sort of the delivery log the API takes, by name. */
135
+ const deliveryLogIndexList = [
136
+ ["delivery_log_subscription", "\"subscription_id\", \"at\""],
137
+ ["delivery_log_at", "\"at\""],
138
+ ["delivery_log_event_id", "\"event_id\""],
139
+ ["delivery_log_event_type", "\"event_type\""],
140
+ ["delivery_log_status", "\"status\""],
141
+ ["delivery_log_status_code", "\"status_code\""]
142
+ ];
143
+ const deliveryLogIndexes = deliveryLogIndexList.map(([name]) => name);
144
+ const deliveryLogIndexesSql = (schema) => deliveryLogIndexList.map(([name, columns]) => `create index if not exists "${name}" on ${quoteIdent(schema)}."delivery_log" (${columns})`).join(";\n");
144
145
  //#endregion
145
- export { commandsSql, commentVersion, deliveriesSql, deliveryJobs, deliveryLogIndexesSql, deliveryLogSql, sendTestJob, subscriptionsIndexesSql, subscriptionsSql, webhooksComment };
146
+ export { commandsSql, commentVersion, deliveriesSql, deliveryJobs, deliveryLogIndexes, deliveryLogIndexesSql, deliveryLogSql, sendTestJob, subscriptionsIndexes, subscriptionsIndexesSql, subscriptionsSql, webhooksComment };
@@ -0,0 +1,63 @@
1
+ import { quoteIdent } from "../../changes/capture-sql.js";
2
+ import { commandsSql, commentVersion, deliveriesSql, subscriptionsIndexes, subscriptionsIndexesSql, subscriptionsSql } from "./schema-sql.js";
3
+ import { hasIndexes } from "../../has-indexes.js";
4
+ import { relationFound } from "../../relation-found.js";
5
+ import { sql } from "kysely";
6
+ //#region src/webhooks/table/webhooks-schema-module.ts
7
+ const functionNames = ["subscription_commands", "deliveries_resend"];
8
+ const upgradeFirst = "with `protobase migration` and `protobase migrate` of Protobase 0.14.2 first, then run this command again";
9
+ /**
10
+ * The functions' version, from the oldest version their comments name, `undefined` when one of them or the deliveries
11
+ * view is missing, so they are written again as new. Refuses a version newer than this version of Protobase writes.
12
+ */
13
+ const readFunctions = async (db, schema) => {
14
+ const { rows } = await sql`select p.proname as name, obj_description(p.oid, 'pg_proc') as comment
15
+ from pg_proc p join pg_namespace n on n.oid = p.pronamespace where n.nspname = ${schema} and p.proname = any(${functionNames}::text[])`.execute(db);
16
+ const versions = functionNames.map((name) => commentVersion(rows.find((row) => row.name === name)?.comment ?? null));
17
+ const newest = Math.max(...versions.filter((version) => version !== void 0));
18
+ if (newest > 2) throw new Error(`The functions of the ${schema} schema are at version ${newest}, newer than the 2 this version of Protobase writes: upgrade Protobase`);
19
+ if (!await relationFound(db, `${quoteIdent(schema)}."deliveries"`) || versions.some((version) => version === void 0)) return {};
20
+ return { functions: Math.min(...versions) };
21
+ };
22
+ /**
23
+ * The webhooks schema as the database has it: step 1 once the subscriptions table is there with every index, and its
24
+ * functions at the version their comments name. Refuses a table without those indexes, as version 1 wrote it, which no
25
+ * step records.
26
+ */
27
+ const readWebhooks = async (db, { names }) => {
28
+ const schema = names.schema;
29
+ if (!await relationFound(db, `${quoteIdent(schema)}."subscriptions"`)) return;
30
+ if (!await hasIndexes(db, schema, "subscriptions", subscriptionsIndexes)) throw new Error(`The subscriptions table in schema "${schema}" lacks indexes no step of this version of Protobase records: add them ${upgradeFirst}`);
31
+ return {
32
+ lastStep: 1,
33
+ replaceables: await readFunctions(db, schema),
34
+ names
35
+ };
36
+ };
37
+ /**
38
+ * The webhook subscriptions made in the admin app, in the schema `webhooks` names (`names.schema`): the subscriptions
39
+ * table, whose owner the change capture's actor setting in schema `names.changes` gives, and its commands and the
40
+ * deliveries view over the jobs schema. Its tables are never dropped.
41
+ */
42
+ const webhooksSchemaModule = {
43
+ label: "the webhooks schema",
44
+ title: "The webhook subscriptions of webhooks",
45
+ steps: [{
46
+ step: 1,
47
+ name: "subscriptions",
48
+ title: "The subscriptions table and its indexes",
49
+ additive: true,
50
+ sql: (names) => `create schema if not exists ${quoteIdent(names.schema)};\n${subscriptionsSql(names.schema, names.changes)};\n${subscriptionsIndexesSql(names.schema)};`
51
+ }],
52
+ replaceables: [{
53
+ name: "functions",
54
+ title: "The subscriptions' commands and the deliveries view",
55
+ version: 2,
56
+ compatibleFrom: 1,
57
+ sql: (names) => `${commandsSql(names.schema)};\n\n${deliveriesSql(names.schema)};`
58
+ }],
59
+ resourceReplaceables: [],
60
+ read: readWebhooks
61
+ };
62
+ //#endregion
63
+ export { webhooksSchemaModule };
@@ -0,0 +1,26 @@
1
+ import { changesSchema } from "../../changes/events-options.js";
2
+ import { webhooksSchema } from "./options.js";
3
+ //#region src/webhooks/table/webhooks-targets.ts
4
+ /**
5
+ * The schema modules `webhooks` needs, each with its names: the webhooks schema in the schema `options` names, whose
6
+ * subscriptions take their owner from the change capture's actor setting in the schema `events` names, and with
7
+ * `deliveryLog` the delivery log in that schema too.
8
+ */
9
+ const webhooksTargets = (options, events) => {
10
+ const schema = webhooksSchema(options);
11
+ return {
12
+ webhooks: {
13
+ names: {
14
+ schema,
15
+ changes: changesSchema(events)
16
+ },
17
+ resources: {}
18
+ },
19
+ ...options.deliveryLog && { webhook_delivery_log: {
20
+ names: { schema },
21
+ resources: {}
22
+ } }
23
+ };
24
+ };
25
+ //#endregion
26
+ export { webhooksTargets };
@@ -1,7 +1,6 @@
1
1
  import { capturedBy, dispatchJobName } from "../changes/capture-sql.js";
2
2
  import { defineJob } from "../jobs/define-job.js";
3
3
  import { FatalJobError } from "../jobs/run-job.js";
4
- import { writeNotices } from "../live/notices-sql.js";
5
4
  import { coalesce } from "../changes/coalesce.js";
6
5
  import { EventCodeError } from "../changes/event-code-error.js";
7
6
  import { eventMatcher } from "../changes/match-events.js";
@@ -10,6 +9,7 @@ import { currentChange, resourceChange } from "../changes/resource-change.js";
10
9
  import { callerRecords } from "../functions/records.js";
11
10
  import { writeHistory } from "../history/write-history.js";
12
11
  import { liveNotices } from "../live/live-notices.js";
12
+ import { writeNotices } from "../live/notices-sql.js";
13
13
  import { maxTries, nextRetryDelay } from "./retry-schedule.js";
14
14
  import { eventChange, subscriberEvents } from "./subscriber-view.js";
15
15
  import { attemptDelivery } from "./attempt.js";