@sanoma-ai/workflows 0.11.12 → 0.11.14

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 (142) hide show
  1. package/CLOUD-IDENTITY.md +12 -4
  2. package/KMS-SECRETS.md +3 -1
  3. package/README.md +4 -2
  4. package/dist/bundled.d.ts +2 -2
  5. package/dist/chats.d.ts +3 -3
  6. package/dist/chats.js +34 -20
  7. package/dist/chats.js.map +1 -1
  8. package/dist/client.d.ts +17 -4
  9. package/dist/client.js +74 -63
  10. package/dist/client.js.map +1 -1
  11. package/dist/cloud-identity.js +14 -12
  12. package/dist/cloud-identity.js.map +1 -1
  13. package/dist/collection.d.ts +2 -2
  14. package/dist/collection.js +53 -42
  15. package/dist/collection.js.map +1 -1
  16. package/dist/config.d.ts +11 -6
  17. package/dist/config.js +15 -13
  18. package/dist/config.js.map +1 -1
  19. package/dist/connection.d.ts +2 -0
  20. package/dist/connection.js +112 -40
  21. package/dist/connection.js.map +1 -1
  22. package/dist/credentials.d.ts +1 -1
  23. package/dist/credentials.js +33 -29
  24. package/dist/credentials.js.map +1 -1
  25. package/dist/db/company.d.ts +1152 -0
  26. package/dist/db/company.js +118 -0
  27. package/dist/db/company.js.map +1 -0
  28. package/dist/db/dbos.d.ts +111 -0
  29. package/dist/db/dbos.js +15 -0
  30. package/dist/db/dbos.js.map +1 -0
  31. package/dist/db/identity.d.ts +367 -0
  32. package/dist/db/identity.js +48 -0
  33. package/dist/db/identity.js.map +1 -0
  34. package/dist/db/index.d.ts +7 -0
  35. package/dist/db/index.js +12 -0
  36. package/dist/db/index.js.map +1 -0
  37. package/dist/db/kms.d.ts +224 -0
  38. package/dist/db/kms.js +29 -0
  39. package/dist/db/kms.js.map +1 -0
  40. package/dist/db/migrate.d.ts +66 -0
  41. package/dist/db/migrate.js +39 -0
  42. package/dist/db/migrate.js.map +1 -0
  43. package/dist/db/wakeup.d.ts +271 -0
  44. package/dist/db/wakeup.js +34 -0
  45. package/dist/db/wakeup.js.map +1 -0
  46. package/dist/db.d.ts +42 -39
  47. package/dist/db.js +129 -169
  48. package/dist/db.js.map +1 -1
  49. package/dist/deadlines.js +8 -4
  50. package/dist/deadlines.js.map +1 -1
  51. package/dist/deployment-key.d.ts +4 -1
  52. package/dist/deployment-key.js +10 -3
  53. package/dist/deployment-key.js.map +1 -1
  54. package/dist/host-derive.d.ts +12 -3
  55. package/dist/host-derive.js +21 -8
  56. package/dist/host-derive.js.map +1 -1
  57. package/dist/identity-provisioning.d.ts +2 -2
  58. package/dist/identity-provisioning.js +75 -42
  59. package/dist/identity-provisioning.js.map +1 -1
  60. package/dist/identity-service.js +18 -15
  61. package/dist/identity-service.js.map +1 -1
  62. package/dist/index.d.ts +2 -2
  63. package/dist/index.js +1 -1
  64. package/dist/index.js.map +1 -1
  65. package/dist/kms-secrets.d.ts +9 -0
  66. package/dist/kms-secrets.js +59 -27
  67. package/dist/kms-secrets.js.map +1 -1
  68. package/dist/ledger.d.ts +1 -1
  69. package/dist/ledger.js +22 -14
  70. package/dist/ledger.js.map +1 -1
  71. package/dist/op.d.ts +27 -6
  72. package/dist/op.js.map +1 -1
  73. package/dist/run-status.js +7 -3
  74. package/dist/run-status.js.map +1 -1
  75. package/dist/schedules.d.ts +1 -1
  76. package/dist/schedules.js +5 -7
  77. package/dist/schedules.js.map +1 -1
  78. package/dist/schema.d.ts +6 -5
  79. package/dist/schema.js +11 -7
  80. package/dist/schema.js.map +1 -1
  81. package/dist/shared.d.ts +6 -23
  82. package/dist/shared.js +6 -5
  83. package/dist/shared.js.map +1 -1
  84. package/dist/storage-provisioning.d.ts +2 -0
  85. package/dist/storage-provisioning.js +51 -50
  86. package/dist/storage-provisioning.js.map +1 -1
  87. package/dist/tokens.d.ts +2 -2
  88. package/dist/tokens.js +31 -20
  89. package/dist/tokens.js.map +1 -1
  90. package/dist/version.d.ts +4 -4
  91. package/dist/version.js +5 -5
  92. package/dist/version.js.map +1 -1
  93. package/dist/wakeup-service.d.ts +0 -4
  94. package/dist/wakeup-service.js +102 -93
  95. package/dist/wakeup-service.js.map +1 -1
  96. package/dist/worker.d.ts +7 -0
  97. package/dist/worker.js +26 -21
  98. package/dist/worker.js.map +1 -1
  99. package/drizzle/company/0000_tables.sql +104 -0
  100. package/drizzle/company/0001_wakeup_row.sql +2 -0
  101. package/drizzle/company/meta/0000_snapshot.json +652 -0
  102. package/drizzle/company/meta/0001_snapshot.json +652 -0
  103. package/drizzle/company/meta/_journal.json +20 -0
  104. package/drizzle/wakeup/0000_tables.sql +26 -0
  105. package/drizzle/wakeup/meta/0000_snapshot.json +200 -0
  106. package/drizzle/wakeup/meta/_journal.json +13 -0
  107. package/oxlint.json +2 -1
  108. package/package.json +11 -2
  109. package/src/bundled.ts +2 -2
  110. package/src/chats.ts +41 -42
  111. package/src/client.ts +81 -64
  112. package/src/cloud-identity.ts +23 -24
  113. package/src/collection.ts +58 -50
  114. package/src/config.ts +29 -19
  115. package/src/connection.ts +132 -102
  116. package/src/credentials.ts +37 -33
  117. package/src/db/company.ts +173 -0
  118. package/src/db/dbos.ts +17 -0
  119. package/src/db/identity.ts +61 -0
  120. package/src/db/index.ts +12 -0
  121. package/src/db/kms.ts +41 -0
  122. package/src/db/migrate.ts +71 -0
  123. package/src/db/wakeup.ts +41 -0
  124. package/src/db.ts +151 -182
  125. package/src/deadlines.ts +10 -4
  126. package/src/deployment-key.ts +11 -3
  127. package/src/host-derive.ts +26 -9
  128. package/src/identity-provisioning.ts +85 -57
  129. package/src/identity-service.ts +19 -19
  130. package/src/index.ts +3 -0
  131. package/src/kms-secrets.ts +64 -56
  132. package/src/ledger.ts +23 -18
  133. package/src/op.ts +28 -6
  134. package/src/run-status.ts +7 -6
  135. package/src/schedules.ts +6 -8
  136. package/src/schema.ts +11 -8
  137. package/src/shared.ts +6 -17
  138. package/src/storage-provisioning.ts +47 -52
  139. package/src/tokens.ts +43 -33
  140. package/src/version.ts +5 -5
  141. package/src/wakeup-service.ts +117 -131
  142. package/src/worker.ts +38 -21
@@ -0,0 +1,7 @@
1
+ export { type Db, databaseOn, pgCode, underPreparationLock } from "../db.ts";
2
+ export * from "./company.ts";
3
+ export * from "./dbos.ts";
4
+ export * from "./identity.ts";
5
+ export * from "./kms.ts";
6
+ export * from "./migrate.ts";
7
+ export * from "./wakeup.ts";
@@ -0,0 +1,12 @@
1
+ // `@sanoma-ai/workflows/db`, server-only: the runtime's tables and the database they are read
2
+ // with, for the packages that share them (the connectors' stores, the app's tests), and the
3
+ // migrator a connector applies its own generated folder with, under the preparation's lock. Never
4
+ // a workflow's import: the shipped `oxlint.json` refuses it, as it does `/wakeup-service`.
5
+ export { databaseOn, pgCode, underPreparationLock } from "../db.js";
6
+ export * from "./company.js";
7
+ export * from "./dbos.js";
8
+ export * from "./identity.js";
9
+ export * from "./kms.js";
10
+ export * from "./migrate.js";
11
+ export * from "./wakeup.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,4FAA4F;AAC5F,kGAAkG;AAClG,2FAA2F;AAE3F,OAAO,EAAW,UAAU,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAC7E,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,224 @@
1
+ import type { Envelope } from "../kms-secrets.ts";
2
+ export declare const kms: import("drizzle-orm/pg-core").PgSchema<"sanoma_kms">;
3
+ /** Each secret's envelope, by company, namespace and path. */
4
+ export declare const kmsSecrets: import("drizzle-orm/pg-core").PgTableWithColumns<{
5
+ name: "secrets";
6
+ schema: "sanoma_kms";
7
+ columns: {
8
+ company: import("drizzle-orm/pg-core").PgColumn<{
9
+ name: "company";
10
+ tableName: "secrets";
11
+ dataType: "string";
12
+ columnType: "PgText";
13
+ data: string;
14
+ driverParam: string;
15
+ notNull: true;
16
+ hasDefault: false;
17
+ isPrimaryKey: false;
18
+ isAutoincrement: false;
19
+ hasRuntimeDefault: false;
20
+ enumValues: [string, ...string[]];
21
+ baseColumn: never;
22
+ identity: undefined;
23
+ generated: undefined;
24
+ }, {}, {}>;
25
+ namespace: import("drizzle-orm/pg-core").PgColumn<{
26
+ name: "namespace";
27
+ tableName: "secrets";
28
+ dataType: "string";
29
+ columnType: "PgText";
30
+ data: string;
31
+ driverParam: string;
32
+ notNull: true;
33
+ hasDefault: false;
34
+ isPrimaryKey: false;
35
+ isAutoincrement: false;
36
+ hasRuntimeDefault: false;
37
+ enumValues: [string, ...string[]];
38
+ baseColumn: never;
39
+ identity: undefined;
40
+ generated: undefined;
41
+ }, {}, {}>;
42
+ path: import("drizzle-orm/pg-core").PgColumn<{
43
+ name: "path";
44
+ tableName: "secrets";
45
+ dataType: "string";
46
+ columnType: "PgText";
47
+ data: string;
48
+ driverParam: string;
49
+ notNull: true;
50
+ hasDefault: false;
51
+ isPrimaryKey: false;
52
+ isAutoincrement: false;
53
+ hasRuntimeDefault: false;
54
+ enumValues: [string, ...string[]];
55
+ baseColumn: never;
56
+ identity: undefined;
57
+ generated: undefined;
58
+ }, {}, {}>;
59
+ version: import("drizzle-orm/pg-core").PgColumn<{
60
+ name: "version";
61
+ tableName: "secrets";
62
+ dataType: "string";
63
+ columnType: "PgUUID";
64
+ data: string;
65
+ driverParam: string;
66
+ notNull: true;
67
+ hasDefault: false;
68
+ isPrimaryKey: false;
69
+ isAutoincrement: false;
70
+ hasRuntimeDefault: false;
71
+ enumValues: undefined;
72
+ baseColumn: never;
73
+ identity: undefined;
74
+ generated: undefined;
75
+ }, {}, {}>;
76
+ envelope: import("drizzle-orm/pg-core").PgColumn<{
77
+ name: "envelope";
78
+ tableName: "secrets";
79
+ dataType: "json";
80
+ columnType: "PgJsonb";
81
+ data: Envelope;
82
+ driverParam: unknown;
83
+ notNull: true;
84
+ hasDefault: false;
85
+ isPrimaryKey: false;
86
+ isAutoincrement: false;
87
+ hasRuntimeDefault: false;
88
+ enumValues: undefined;
89
+ baseColumn: never;
90
+ identity: undefined;
91
+ generated: undefined;
92
+ }, {}, {
93
+ $type: Envelope;
94
+ }>;
95
+ updatedBy: import("drizzle-orm/pg-core").PgColumn<{
96
+ name: "updatedBy";
97
+ tableName: "secrets";
98
+ dataType: "string";
99
+ columnType: "PgText";
100
+ data: string;
101
+ driverParam: string;
102
+ notNull: true;
103
+ hasDefault: false;
104
+ isPrimaryKey: false;
105
+ isAutoincrement: false;
106
+ hasRuntimeDefault: false;
107
+ enumValues: [string, ...string[]];
108
+ baseColumn: never;
109
+ identity: undefined;
110
+ generated: undefined;
111
+ }, {}, {}>;
112
+ updatedAt: import("drizzle-orm/pg-core").PgColumn<{
113
+ name: "updatedAt";
114
+ tableName: "secrets";
115
+ dataType: "date";
116
+ columnType: "PgTimestamp";
117
+ data: Date;
118
+ driverParam: string;
119
+ notNull: true;
120
+ hasDefault: true;
121
+ isPrimaryKey: false;
122
+ isAutoincrement: false;
123
+ hasRuntimeDefault: false;
124
+ enumValues: undefined;
125
+ baseColumn: never;
126
+ identity: undefined;
127
+ generated: undefined;
128
+ }, {}, {}>;
129
+ };
130
+ dialect: 'pg';
131
+ }>;
132
+ /** The one row binding the database to its company and environment, and the runtime role's credential hash. */
133
+ export declare const kmsDeployment: import("drizzle-orm/pg-core").PgTableWithColumns<{
134
+ name: "deployment";
135
+ schema: "sanoma_kms";
136
+ columns: {
137
+ singleton: import("drizzle-orm/pg-core").PgColumn<{
138
+ name: "singleton";
139
+ tableName: "deployment";
140
+ dataType: "boolean";
141
+ columnType: "PgBoolean";
142
+ data: boolean;
143
+ driverParam: boolean;
144
+ notNull: true;
145
+ hasDefault: true;
146
+ isPrimaryKey: true;
147
+ isAutoincrement: false;
148
+ hasRuntimeDefault: false;
149
+ enumValues: undefined;
150
+ baseColumn: never;
151
+ identity: undefined;
152
+ generated: undefined;
153
+ }, {}, {}>;
154
+ company: import("drizzle-orm/pg-core").PgColumn<{
155
+ name: "company";
156
+ tableName: "deployment";
157
+ dataType: "string";
158
+ columnType: "PgText";
159
+ data: string;
160
+ driverParam: string;
161
+ notNull: true;
162
+ hasDefault: false;
163
+ isPrimaryKey: false;
164
+ isAutoincrement: false;
165
+ hasRuntimeDefault: false;
166
+ enumValues: [string, ...string[]];
167
+ baseColumn: never;
168
+ identity: undefined;
169
+ generated: undefined;
170
+ }, {}, {}>;
171
+ environment: import("drizzle-orm/pg-core").PgColumn<{
172
+ name: "environment";
173
+ tableName: "deployment";
174
+ dataType: "string";
175
+ columnType: "PgText";
176
+ data: string;
177
+ driverParam: string;
178
+ notNull: true;
179
+ hasDefault: false;
180
+ isPrimaryKey: false;
181
+ isAutoincrement: false;
182
+ hasRuntimeDefault: false;
183
+ enumValues: [string, ...string[]];
184
+ baseColumn: never;
185
+ identity: undefined;
186
+ generated: undefined;
187
+ }, {}, {}>;
188
+ runtimeRole: import("drizzle-orm/pg-core").PgColumn<{
189
+ name: "runtimeRole";
190
+ tableName: "deployment";
191
+ dataType: "string";
192
+ columnType: "PgText";
193
+ data: string;
194
+ driverParam: string;
195
+ notNull: true;
196
+ hasDefault: false;
197
+ isPrimaryKey: false;
198
+ isAutoincrement: false;
199
+ hasRuntimeDefault: false;
200
+ enumValues: [string, ...string[]];
201
+ baseColumn: never;
202
+ identity: undefined;
203
+ generated: undefined;
204
+ }, {}, {}>;
205
+ credentialHash: import("drizzle-orm/pg-core").PgColumn<{
206
+ name: "credentialHash";
207
+ tableName: "deployment";
208
+ dataType: "string";
209
+ columnType: "PgText";
210
+ data: string;
211
+ driverParam: string;
212
+ notNull: true;
213
+ hasDefault: false;
214
+ isPrimaryKey: false;
215
+ isAutoincrement: false;
216
+ hasRuntimeDefault: false;
217
+ enumValues: [string, ...string[]];
218
+ baseColumn: never;
219
+ identity: undefined;
220
+ generated: undefined;
221
+ }, {}, {}>;
222
+ };
223
+ dialect: 'pg';
224
+ }>;
package/dist/db/kms.js ADDED
@@ -0,0 +1,29 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { boolean, check, jsonb, pgSchema, primaryKey, text, timestamp, uuid } from "drizzle-orm/pg-core";
3
+ // The KMS secret store's tables, in the schema `sanoma_kms` an administrator installs with
4
+ // `KMS_SECRETS_SQL` (`kms-secrets.ts`) and `sanoma.secretStore.prepare` (`storage-provisioning.ts`),
5
+ // with their grants: the runtime never makes them, so no migration is generated from this model.
6
+ // `installed-schemas.test.ts` holds the install SQL to it.
7
+ export const kms = pgSchema("sanoma_kms");
8
+ /** Each secret's envelope, by company, namespace and path. */
9
+ export const kmsSecrets = kms.table("secrets", {
10
+ company: text().notNull(),
11
+ namespace: text().notNull(),
12
+ path: text().notNull(),
13
+ version: uuid().notNull(),
14
+ envelope: jsonb().$type().notNull(),
15
+ updatedBy: text().notNull(),
16
+ updatedAt: timestamp({ withTimezone: true })
17
+ .notNull()
18
+ .defaultNow()
19
+ .$onUpdate(() => sql `now()`),
20
+ }, (t) => [primaryKey({ columns: [t.company, t.namespace, t.path] })]);
21
+ /** The one row binding the database to its company and environment, and the runtime role's credential hash. */
22
+ export const kmsDeployment = kms.table("deployment", {
23
+ singleton: boolean().primaryKey().default(true),
24
+ company: text().notNull(),
25
+ environment: text().notNull(),
26
+ runtimeRole: text().notNull(),
27
+ credentialHash: text().notNull(),
28
+ }, (t) => [check("deployment_singleton", sql `${t.singleton}`)]);
29
+ //# sourceMappingURL=kms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kms.js","sourceRoot":"","sources":["../../src/db/kms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAGzG,2FAA2F;AAC3F,qGAAqG;AACrG,iGAAiG;AACjG,2DAA2D;AAE3D,MAAM,CAAC,MAAM,GAAG,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AAE1C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CACjC,SAAS,EACT;IACE,OAAO,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE;IACzB,SAAS,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE;IAC3B,IAAI,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE;IACtB,OAAO,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE;IACzB,QAAQ,EAAE,KAAK,EAAE,CAAC,KAAK,EAAY,CAAC,OAAO,EAAE;IAC7C,SAAS,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE;IAC3B,SAAS,EAAE,SAAS,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;SACzC,OAAO,EAAE;SACT,UAAU,EAAE;SACZ,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,CAAA,OAAO,CAAC;CAC/B,EACD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CACnE,CAAC;AAEF,+GAA+G;AAC/G,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC,KAAK,CACpC,YAAY,EACZ;IACE,SAAS,EAAE,OAAO,EAAE,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/C,OAAO,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE;IACzB,WAAW,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE;IAC7B,WAAW,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE;IAC7B,cAAc,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE;CACjC,EACD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,CAAA,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAC5D,CAAC"}
@@ -0,0 +1,66 @@
1
+ import type { Db } from "../db.ts";
2
+ /** Drizzle's journal, `meta/_journal.json` of a migrations folder. */
3
+ export interface MigrationsJournal {
4
+ entries: {
5
+ idx: number;
6
+ when: number;
7
+ tag: string;
8
+ }[];
9
+ }
10
+ /** A migrations folder with the journal table recording what of it a database has. */
11
+ export interface Migrations {
12
+ /**
13
+ * The folder, beside the module declaring it (`new URL("../drizzle/<name>/", import.meta.url)`,
14
+ * from `src/` and from `dist/` alike), asked for only when migrating, never in the Worker.
15
+ */
16
+ folder(): URL;
17
+ /** Its journal table in the schema `drizzle`. */
18
+ table: string;
19
+ journal: MigrationsJournal;
20
+ }
21
+ /** The tables every company database gets (`db/company.ts`). */
22
+ export declare const COMPANY_MIGRATIONS: {
23
+ folder: () => import("node:url").URL;
24
+ table: string;
25
+ journal: {
26
+ version: string;
27
+ dialect: string;
28
+ entries: {
29
+ idx: number;
30
+ version: string;
31
+ when: number;
32
+ tag: string;
33
+ breakpoints: boolean;
34
+ }[];
35
+ };
36
+ };
37
+ /** The wakeup service's tables (`db/wakeup.ts`). */
38
+ export declare const WAKEUP_MIGRATIONS: {
39
+ folder: () => import("node:url").URL;
40
+ table: string;
41
+ journal: {
42
+ version: string;
43
+ dialect: string;
44
+ entries: {
45
+ idx: number;
46
+ version: string;
47
+ when: number;
48
+ tag: string;
49
+ breakpoints: boolean;
50
+ }[];
51
+ };
52
+ };
53
+ /**
54
+ * Applies to `db` the migrations of `of` its database has not had, in one transaction, recording
55
+ * each in the journal table. Drizzle's migrator compares only the newest timestamp, so a migration
56
+ * older than the newest applied is skipped: the repository's `scripts/check-journal.ts` keeps a
57
+ * branch from adding one. Two processes migrating one database at once race (the migrator takes no lock): callers
58
+ * hold `underPreparationLock`.
59
+ */
60
+ export declare const applyMigrations: (db: Db, of: Migrations) => Promise<void>;
61
+ /**
62
+ * Whether the database `db` is on has had every migration of `of`: each journal entry's `when`
63
+ * is a `created_at` of its journal table, whatever else the table holds (a database a newer
64
+ * release migrated serves this one, as after a rollback). False with no journal table.
65
+ */
66
+ export declare function migrationsApplied(db: Db, of: Migrations): Promise<boolean>;
@@ -0,0 +1,39 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { sql } from "drizzle-orm";
3
+ import { migrate } from "drizzle-orm/node-postgres/migrator";
4
+ import companyJournal from "../../drizzle/company/meta/_journal.json" with { type: "json" };
5
+ import wakeupJournal from "../../drizzle/wakeup/meta/_journal.json" with { type: "json" };
6
+ /** The tables every company database gets (`db/company.ts`). */
7
+ export const COMPANY_MIGRATIONS = {
8
+ folder: () => new URL("../../drizzle/company/", import.meta.url),
9
+ table: "__drizzle_migrations",
10
+ journal: companyJournal,
11
+ };
12
+ /** The wakeup service's tables (`db/wakeup.ts`). */
13
+ export const WAKEUP_MIGRATIONS = {
14
+ folder: () => new URL("../../drizzle/wakeup/", import.meta.url),
15
+ table: "__drizzle_migrations_wakeup",
16
+ journal: wakeupJournal,
17
+ };
18
+ /**
19
+ * Applies to `db` the migrations of `of` its database has not had, in one transaction, recording
20
+ * each in the journal table. Drizzle's migrator compares only the newest timestamp, so a migration
21
+ * older than the newest applied is skipped: the repository's `scripts/check-journal.ts` keeps a
22
+ * branch from adding one. Two processes migrating one database at once race (the migrator takes no lock): callers
23
+ * hold `underPreparationLock`.
24
+ */
25
+ export const applyMigrations = (db, of) => migrate(db, { migrationsFolder: fileURLToPath(of.folder()), migrationsTable: of.table });
26
+ /**
27
+ * Whether the database `db` is on has had every migration of `of`: each journal entry's `when`
28
+ * is a `created_at` of its journal table, whatever else the table holds (a database a newer
29
+ * release migrated serves this one, as after a rollback). False with no journal table.
30
+ */
31
+ export async function migrationsApplied(db, of) {
32
+ const present = await db.execute(sql `SELECT to_regclass(${`drizzle.${of.table}`}) IS NOT NULL AS present`);
33
+ if (present.rows[0]?.present !== true)
34
+ return false;
35
+ const { rows } = await db.execute(sql `SELECT created_at::text AS at FROM drizzle.${sql.identifier(of.table)}`);
36
+ const applied = new Set(rows.map((row) => Number(row.at)));
37
+ return of.journal.entries.every((entry) => applied.has(entry.when));
38
+ }
39
+ //# sourceMappingURL=migrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/db/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAE7D,OAAO,cAAc,MAAM,0CAA0C,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC5F,OAAO,aAAa,MAAM,yCAAyC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AA0B1F,gEAAgE;AAChE,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,GAAG,CAAC,wBAAwB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC;IAChE,KAAK,EAAE,sBAAsB;IAC7B,OAAO,EAAE,cAAc;CACH,CAAC;AAEvB,oDAAoD;AACpD,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,GAAG,CAAC,uBAAuB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC;IAC/D,KAAK,EAAE,6BAA6B;IACpC,OAAO,EAAE,aAAa;CACF,CAAC;AAEvB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAM,EAAE,EAAc,EAAiB,EAAE,CACvE,OAAO,CAAC,EAAE,EAAE,EAAE,gBAAgB,EAAE,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,eAAe,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;AAE3F;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,EAAM,EAAE,EAAc;IAC5D,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAC9B,GAAG,CAAA,sBAAsB,WAAW,EAAE,CAAC,KAAK,EAAE,0BAA0B,CACzE,CAAC;IACF,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACpD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,OAAO,CAC/B,GAAG,CAAA,8CAA8C,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAC5E,CAAC;IACF,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3D,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AACtE,CAAC"}
@@ -0,0 +1,271 @@
1
+ /** One account per party that registers instances, its token's hash alone. */
2
+ export declare const wakeupAccounts: import("drizzle-orm/pg-core").PgTableWithColumns<{
3
+ name: "sanoma_wakeup_accounts";
4
+ schema: undefined;
5
+ columns: {
6
+ id: import("drizzle-orm/pg-core").PgColumn<{
7
+ name: "id";
8
+ tableName: "sanoma_wakeup_accounts";
9
+ dataType: "string";
10
+ columnType: "PgUUID";
11
+ data: string;
12
+ driverParam: string;
13
+ notNull: true;
14
+ hasDefault: false;
15
+ isPrimaryKey: true;
16
+ isAutoincrement: false;
17
+ hasRuntimeDefault: false;
18
+ enumValues: undefined;
19
+ baseColumn: never;
20
+ identity: undefined;
21
+ generated: undefined;
22
+ }, {}, {}>;
23
+ tokenHash: import("drizzle-orm/pg-core").PgColumn<{
24
+ name: "tokenHash";
25
+ tableName: "sanoma_wakeup_accounts";
26
+ dataType: "string";
27
+ columnType: "PgText";
28
+ data: string;
29
+ driverParam: string;
30
+ notNull: true;
31
+ hasDefault: false;
32
+ isPrimaryKey: false;
33
+ isAutoincrement: false;
34
+ hasRuntimeDefault: false;
35
+ enumValues: [string, ...string[]];
36
+ baseColumn: never;
37
+ identity: undefined;
38
+ generated: undefined;
39
+ }, {}, {}>;
40
+ label: import("drizzle-orm/pg-core").PgColumn<{
41
+ name: "label";
42
+ tableName: "sanoma_wakeup_accounts";
43
+ dataType: "string";
44
+ columnType: "PgText";
45
+ data: string;
46
+ driverParam: string;
47
+ notNull: true;
48
+ hasDefault: false;
49
+ isPrimaryKey: false;
50
+ isAutoincrement: false;
51
+ hasRuntimeDefault: false;
52
+ enumValues: [string, ...string[]];
53
+ baseColumn: never;
54
+ identity: undefined;
55
+ generated: undefined;
56
+ }, {}, {}>;
57
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
58
+ name: "createdAt";
59
+ tableName: "sanoma_wakeup_accounts";
60
+ dataType: "date";
61
+ columnType: "PgTimestamp";
62
+ data: Date;
63
+ driverParam: string;
64
+ notNull: true;
65
+ hasDefault: true;
66
+ isPrimaryKey: false;
67
+ isAutoincrement: false;
68
+ hasRuntimeDefault: false;
69
+ enumValues: undefined;
70
+ baseColumn: never;
71
+ identity: undefined;
72
+ generated: undefined;
73
+ }, {}, {}>;
74
+ revokedAt: import("drizzle-orm/pg-core").PgColumn<{
75
+ name: "revokedAt";
76
+ tableName: "sanoma_wakeup_accounts";
77
+ dataType: "date";
78
+ columnType: "PgTimestamp";
79
+ data: Date;
80
+ driverParam: string;
81
+ notNull: false;
82
+ hasDefault: false;
83
+ isPrimaryKey: false;
84
+ isAutoincrement: false;
85
+ hasRuntimeDefault: false;
86
+ enumValues: undefined;
87
+ baseColumn: never;
88
+ identity: undefined;
89
+ generated: undefined;
90
+ }, {}, {}>;
91
+ };
92
+ dialect: 'pg';
93
+ }>;
94
+ /** Each registered instance: its URL, its token's hash and its registered wake. */
95
+ export declare const wakeupInstances: import("drizzle-orm/pg-core").PgTableWithColumns<{
96
+ name: "sanoma_wakeup_instances";
97
+ schema: undefined;
98
+ columns: {
99
+ id: import("drizzle-orm/pg-core").PgColumn<{
100
+ name: "id";
101
+ tableName: "sanoma_wakeup_instances";
102
+ dataType: "string";
103
+ columnType: "PgUUID";
104
+ data: string;
105
+ driverParam: string;
106
+ notNull: true;
107
+ hasDefault: false;
108
+ isPrimaryKey: true;
109
+ isAutoincrement: false;
110
+ hasRuntimeDefault: false;
111
+ enumValues: undefined;
112
+ baseColumn: never;
113
+ identity: undefined;
114
+ generated: undefined;
115
+ }, {}, {}>;
116
+ accountId: import("drizzle-orm/pg-core").PgColumn<{
117
+ name: "accountId";
118
+ tableName: "sanoma_wakeup_instances";
119
+ dataType: "string";
120
+ columnType: "PgUUID";
121
+ data: string;
122
+ driverParam: string;
123
+ notNull: true;
124
+ hasDefault: false;
125
+ isPrimaryKey: false;
126
+ isAutoincrement: false;
127
+ hasRuntimeDefault: false;
128
+ enumValues: undefined;
129
+ baseColumn: never;
130
+ identity: undefined;
131
+ generated: undefined;
132
+ }, {}, {}>;
133
+ url: import("drizzle-orm/pg-core").PgColumn<{
134
+ name: "url";
135
+ tableName: "sanoma_wakeup_instances";
136
+ dataType: "string";
137
+ columnType: "PgText";
138
+ data: string;
139
+ driverParam: string;
140
+ notNull: true;
141
+ hasDefault: false;
142
+ isPrimaryKey: false;
143
+ isAutoincrement: false;
144
+ hasRuntimeDefault: false;
145
+ enumValues: [string, ...string[]];
146
+ baseColumn: never;
147
+ identity: undefined;
148
+ generated: undefined;
149
+ }, {}, {}>;
150
+ tokenHash: import("drizzle-orm/pg-core").PgColumn<{
151
+ name: "tokenHash";
152
+ tableName: "sanoma_wakeup_instances";
153
+ dataType: "string";
154
+ columnType: "PgText";
155
+ data: string;
156
+ driverParam: string;
157
+ notNull: true;
158
+ hasDefault: false;
159
+ isPrimaryKey: false;
160
+ isAutoincrement: false;
161
+ hasRuntimeDefault: false;
162
+ enumValues: [string, ...string[]];
163
+ baseColumn: never;
164
+ identity: undefined;
165
+ generated: undefined;
166
+ }, {}, {}>;
167
+ at: import("drizzle-orm/pg-core").PgColumn<{
168
+ name: "at";
169
+ tableName: "sanoma_wakeup_instances";
170
+ dataType: "date";
171
+ columnType: "PgTimestamp";
172
+ data: Date;
173
+ driverParam: string;
174
+ notNull: false;
175
+ hasDefault: false;
176
+ isPrimaryKey: false;
177
+ isAutoincrement: false;
178
+ hasRuntimeDefault: false;
179
+ enumValues: undefined;
180
+ baseColumn: never;
181
+ identity: undefined;
182
+ generated: undefined;
183
+ }, {}, {}>;
184
+ calledAt: import("drizzle-orm/pg-core").PgColumn<{
185
+ name: "calledAt";
186
+ tableName: "sanoma_wakeup_instances";
187
+ dataType: "date";
188
+ columnType: "PgTimestamp";
189
+ data: Date;
190
+ driverParam: string;
191
+ notNull: false;
192
+ hasDefault: false;
193
+ isPrimaryKey: false;
194
+ isAutoincrement: false;
195
+ hasRuntimeDefault: false;
196
+ enumValues: undefined;
197
+ baseColumn: never;
198
+ identity: undefined;
199
+ generated: undefined;
200
+ }, {}, {}>;
201
+ attempts: import("drizzle-orm/pg-core").PgColumn<{
202
+ name: "attempts";
203
+ tableName: "sanoma_wakeup_instances";
204
+ dataType: "number";
205
+ columnType: "PgInteger";
206
+ data: number;
207
+ driverParam: string | number;
208
+ notNull: true;
209
+ hasDefault: true;
210
+ isPrimaryKey: false;
211
+ isAutoincrement: false;
212
+ hasRuntimeDefault: false;
213
+ enumValues: undefined;
214
+ baseColumn: never;
215
+ identity: undefined;
216
+ generated: undefined;
217
+ }, {}, {}>;
218
+ nextAttemptAt: import("drizzle-orm/pg-core").PgColumn<{
219
+ name: "nextAttemptAt";
220
+ tableName: "sanoma_wakeup_instances";
221
+ dataType: "date";
222
+ columnType: "PgTimestamp";
223
+ data: Date;
224
+ driverParam: string;
225
+ notNull: false;
226
+ hasDefault: false;
227
+ isPrimaryKey: false;
228
+ isAutoincrement: false;
229
+ hasRuntimeDefault: false;
230
+ enumValues: undefined;
231
+ baseColumn: never;
232
+ identity: undefined;
233
+ generated: undefined;
234
+ }, {}, {}>;
235
+ lastError: import("drizzle-orm/pg-core").PgColumn<{
236
+ name: "lastError";
237
+ tableName: "sanoma_wakeup_instances";
238
+ dataType: "string";
239
+ columnType: "PgText";
240
+ data: string;
241
+ driverParam: string;
242
+ notNull: false;
243
+ hasDefault: false;
244
+ isPrimaryKey: false;
245
+ isAutoincrement: false;
246
+ hasRuntimeDefault: false;
247
+ enumValues: [string, ...string[]];
248
+ baseColumn: never;
249
+ identity: undefined;
250
+ generated: undefined;
251
+ }, {}, {}>;
252
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
253
+ name: "createdAt";
254
+ tableName: "sanoma_wakeup_instances";
255
+ dataType: "date";
256
+ columnType: "PgTimestamp";
257
+ data: Date;
258
+ driverParam: string;
259
+ notNull: true;
260
+ hasDefault: true;
261
+ isPrimaryKey: false;
262
+ isAutoincrement: false;
263
+ hasRuntimeDefault: false;
264
+ enumValues: undefined;
265
+ baseColumn: never;
266
+ identity: undefined;
267
+ generated: undefined;
268
+ }, {}, {}>;
269
+ };
270
+ dialect: 'pg';
271
+ }>;