@hot-updater/plugin-core 1.1.4 → 1.2.0-rc.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.
@@ -6,256 +6,385 @@ const CHANNEL_ID = {
6
6
  maxLength: 1408,
7
7
  ascii: true
8
8
  };
9
- /** Core's schema version: the `schema.core` settings row. */
10
- const HOT_UPDATER_SCHEMA_VERSION = "1.0.0";
11
- const coreSchema = {
12
- bundles: defineTable({
13
- id: {
14
- type: "string",
15
- maxLength: 36
16
- },
17
- platform: {
18
- type: "string",
19
- maxLength: 16
20
- },
21
- git_commit_hash: {
22
- type: "string",
23
- maxLength: 255,
24
- required: false
9
+ /**
10
+ * Core's schema version: the `schema.core` settings row. Bump it when core
11
+ * adds a table, then regenerate the managed migrations with
12
+ * HOT_UPDATER_UPDATE_SQL=1 (the D1 and Supabase schema specs), so the next
13
+ * release's numbered migration carries the change and `hot-updater init`
14
+ * applies it to managed databases an earlier release created. The official
15
+ * plugins' `schemaVersion`s follow the same rule. A bump only adds tables:
16
+ * every database's migrator creates missing tables and then records the
17
+ * version, and none of them changes an existing table, so changing one
18
+ * needs a migration step of its own first. The schema fence answers 503 on
19
+ * a database whose row differs, until it runs.
20
+ */
21
+ const HOT_UPDATER_SCHEMA_VERSION = "1.2.0";
22
+ const bundles = defineTable({
23
+ id: {
24
+ type: "string",
25
+ maxLength: 36
26
+ },
27
+ platform: {
28
+ type: "string",
29
+ maxLength: 16
30
+ },
31
+ git_commit_hash: {
32
+ type: "string",
33
+ maxLength: 255,
34
+ required: false
35
+ },
36
+ metadata: { type: "json" },
37
+ manifest_storage_uri: { type: "string" },
38
+ manifest_file_hash: { type: "string" },
39
+ asset_base_storage_uri: { type: "string" }
40
+ }, {
41
+ key: ["id"],
42
+ indexes: {
43
+ byPlatform: {
44
+ eq: ["platform"],
45
+ sort: ["id"]
25
46
  },
26
- metadata: { type: "json" },
27
- manifest_storage_uri: { type: "string" },
28
- manifest_file_hash: { type: "string" },
29
- asset_base_storage_uri: { type: "string" }
30
- }, {
31
- key: ["id"],
32
- indexes: {
33
- byPlatform: {
34
- eq: ["platform"],
35
- sort: ["id"]
36
- },
37
- all: {
38
- eq: [],
39
- sort: ["id"]
40
- }
47
+ all: {
48
+ eq: [],
49
+ sort: ["id"]
41
50
  }
42
- }),
43
- bundle_patches: defineTable({
44
- id: {
45
- type: "string",
46
- maxLength: 255
47
- },
48
- bundle_id: {
49
- type: "string",
50
- maxLength: 36,
51
- references: {
52
- model: "bundles",
53
- onDelete: "cascade"
54
- }
55
- },
56
- base_bundle_id: {
57
- type: "string",
58
- maxLength: 36,
59
- references: {
60
- model: "bundles",
61
- onDelete: "cascade"
62
- }
63
- },
64
- base_file_hash: { type: "string" },
65
- patch_file_hash: { type: "string" },
66
- patch_storage_uri: { type: "string" },
67
- byte_size: { type: "integer" },
68
- order_index: { type: "integer" }
69
- }, {
70
- key: ["id"],
71
- indexes: {
72
- pair: {
73
- eq: ["bundle_id", "base_bundle_id"],
74
- sort: [],
75
- unique: true
76
- },
77
- byBundle: {
78
- eq: ["bundle_id"],
79
- sort: ["order_index"],
80
- root: { model: "bundles" }
81
- },
82
- byBase: {
83
- eq: ["base_bundle_id"],
84
- sort: ["bundle_id"]
85
- }
51
+ }
52
+ });
53
+ const bundlePatches = defineTable({
54
+ id: {
55
+ type: "string",
56
+ maxLength: 255
57
+ },
58
+ bundle_id: {
59
+ type: "string",
60
+ maxLength: 36,
61
+ references: {
62
+ model: "bundles",
63
+ onDelete: "cascade"
86
64
  }
87
- }),
88
- releases: defineTable({
89
- id: {
90
- type: "string",
91
- maxLength: 36
92
- },
93
- revision: { type: "integer" },
94
- scope_key: {
95
- type: "string",
96
- maxLength: 2048,
97
- ascii: true
98
- },
99
- channel_id: {
100
- ...CHANNEL_ID,
101
- references: {
102
- model: "channels",
103
- onDelete: "restrict"
104
- }
105
- },
106
- platform: {
107
- type: "string",
108
- maxLength: 16
109
- },
110
- kind: {
111
- type: "string",
112
- maxLength: 16
113
- },
114
- bundle_id: {
115
- type: "string",
116
- maxLength: 36,
117
- required: false,
118
- references: {
119
- model: "bundles",
120
- onDelete: "restrict"
121
- }
122
- },
123
- strategy: {
124
- type: "string",
125
- maxLength: 16
126
- },
127
- target_app_version: {
128
- type: "string",
129
- required: false
130
- },
131
- fingerprint_hash: {
132
- type: "string",
133
- maxLength: 255,
134
- required: false
135
- },
136
- enabled: { type: "boolean" },
137
- should_force_update: { type: "boolean" },
138
- message: {
139
- type: "string",
140
- required: false
141
- },
142
- rollout_cohort_count: { type: "integer" },
143
- target_cohorts: { type: "json" },
144
- operation: {
145
- type: "string",
146
- maxLength: 16
65
+ },
66
+ base_bundle_id: {
67
+ type: "string",
68
+ maxLength: 36,
69
+ references: {
70
+ model: "bundles",
71
+ onDelete: "cascade"
72
+ }
73
+ },
74
+ base_file_hash: { type: "string" },
75
+ patch_file_hash: { type: "string" },
76
+ patch_storage_uri: { type: "string" },
77
+ byte_size: { type: "integer" },
78
+ order_index: { type: "integer" }
79
+ }, {
80
+ key: ["id"],
81
+ indexes: {
82
+ pair: {
83
+ eq: ["bundle_id", "base_bundle_id"],
84
+ sort: [],
85
+ unique: true
147
86
  },
148
- source_release_id: {
149
- type: "string",
150
- maxLength: 36,
151
- required: false,
152
- references: {
153
- model: "releases",
154
- onDelete: "none"
155
- }
87
+ byBundle: {
88
+ eq: ["bundle_id"],
89
+ sort: ["order_index"],
90
+ root: { model: "bundles" }
156
91
  },
157
- created_at_ms: { type: "integer" },
158
- updated_at_ms: { type: "integer" }
159
- }, {
160
- key: ["id"],
161
- indexes: {
162
- byScope: {
163
- eq: ["scope_key"],
164
- sort: ["id"],
165
- root: { model: "release_catalogs" }
166
- },
167
- byScopeEnabled: {
168
- eq: ["scope_key", "enabled"],
169
- sort: ["id"],
170
- root: { model: "release_catalogs" }
171
- },
172
- byChannelPlatform: {
173
- eq: ["channel_id", "platform"],
174
- sort: ["id"]
175
- },
176
- byChannelPlatformEnabled: {
177
- eq: [
178
- "channel_id",
179
- "platform",
180
- "enabled"
181
- ],
182
- sort: ["id"]
183
- },
184
- byBundle: {
185
- eq: ["bundle_id"],
186
- sort: ["id"]
187
- },
188
- all: {
189
- eq: [],
190
- sort: ["id"]
191
- }
92
+ byBase: {
93
+ eq: ["base_bundle_id"],
94
+ sort: ["bundle_id"]
192
95
  }
193
- }),
194
- release_catalogs: defineTable({
195
- scope_key: {
196
- type: "string",
197
- maxLength: 2048,
198
- ascii: true
96
+ }
97
+ });
98
+ const releases = defineTable({
99
+ id: {
100
+ type: "string",
101
+ maxLength: 36
102
+ },
103
+ revision: { type: "integer" },
104
+ scope_key: {
105
+ type: "string",
106
+ maxLength: 2048,
107
+ ascii: true
108
+ },
109
+ channel_id: {
110
+ ...CHANNEL_ID,
111
+ references: {
112
+ model: "channels",
113
+ onDelete: "restrict"
114
+ }
115
+ },
116
+ platform: {
117
+ type: "string",
118
+ maxLength: 16
119
+ },
120
+ kind: {
121
+ type: "string",
122
+ maxLength: 16
123
+ },
124
+ bundle_id: {
125
+ type: "string",
126
+ maxLength: 36,
127
+ required: false,
128
+ references: {
129
+ model: "bundles",
130
+ onDelete: "restrict"
131
+ }
132
+ },
133
+ strategy: {
134
+ type: "string",
135
+ maxLength: 16
136
+ },
137
+ target_app_version: {
138
+ type: "string",
139
+ required: false
140
+ },
141
+ fingerprint_hash: {
142
+ type: "string",
143
+ maxLength: 255,
144
+ required: false
145
+ },
146
+ enabled: { type: "boolean" },
147
+ should_force_update: { type: "boolean" },
148
+ message: {
149
+ type: "string",
150
+ required: false
151
+ },
152
+ rollout_cohort_count: { type: "integer" },
153
+ target_cohorts: { type: "json" },
154
+ operation: {
155
+ type: "string",
156
+ maxLength: 16
157
+ },
158
+ source_release_id: {
159
+ type: "string",
160
+ maxLength: 36,
161
+ required: false,
162
+ references: {
163
+ model: "releases",
164
+ onDelete: "none"
165
+ }
166
+ },
167
+ created_at_ms: { type: "integer" },
168
+ updated_at_ms: { type: "integer" }
169
+ }, {
170
+ key: ["id"],
171
+ indexes: {
172
+ byScope: {
173
+ eq: ["scope_key"],
174
+ sort: ["id"],
175
+ root: { model: "release_catalogs" }
199
176
  },
200
- catalog_id: {
201
- type: "string",
202
- maxLength: 255
177
+ byScopeEnabled: {
178
+ eq: ["scope_key", "enabled"],
179
+ sort: ["id"],
180
+ root: { model: "release_catalogs" }
203
181
  },
204
- strategy: {
205
- type: "string",
206
- maxLength: 16
182
+ byChannelPlatform: {
183
+ eq: ["channel_id", "platform"],
184
+ sort: ["id"]
207
185
  },
208
- channel_id: {
209
- ...CHANNEL_ID,
210
- references: {
211
- model: "channels",
212
- onDelete: "none"
213
- }
186
+ byChannelPlatformEnabled: {
187
+ eq: [
188
+ "channel_id",
189
+ "platform",
190
+ "enabled"
191
+ ],
192
+ sort: ["id"]
214
193
  },
215
- channel_key: {
216
- type: "string",
217
- maxLength: 1400,
218
- ascii: true
194
+ byBundle: {
195
+ eq: ["bundle_id"],
196
+ sort: ["id"]
219
197
  },
220
- platform: {
221
- type: "string",
222
- maxLength: 16
198
+ all: {
199
+ eq: [],
200
+ sort: ["id"]
201
+ }
202
+ }
203
+ });
204
+ /** One compiled catalog per scope; the update check reads exactly this row. */
205
+ const releaseCatalogs = defineTable({
206
+ scope_key: {
207
+ type: "string",
208
+ maxLength: 2048,
209
+ ascii: true
210
+ },
211
+ catalog_id: {
212
+ type: "string",
213
+ maxLength: 255
214
+ },
215
+ strategy: {
216
+ type: "string",
217
+ maxLength: 16
218
+ },
219
+ channel_id: {
220
+ ...CHANNEL_ID,
221
+ references: {
222
+ model: "channels",
223
+ onDelete: "none"
224
+ }
225
+ },
226
+ channel_key: {
227
+ type: "string",
228
+ maxLength: 1400,
229
+ ascii: true
230
+ },
231
+ platform: {
232
+ type: "string",
233
+ maxLength: 16
234
+ },
235
+ fingerprint_hash: {
236
+ type: "string",
237
+ maxLength: 255,
238
+ required: false
239
+ },
240
+ generation: { type: "integer" },
241
+ payload: { type: "string" },
242
+ catalog_hash: {
243
+ type: "string",
244
+ maxLength: 71
245
+ },
246
+ byte_size: { type: "integer" },
247
+ is_tombstone: { type: "boolean" },
248
+ updated_at_ms: { type: "integer" }
249
+ }, {
250
+ key: ["scope_key"],
251
+ indexes: { all: {
252
+ eq: [],
253
+ sort: ["scope_key"]
254
+ } }
255
+ });
256
+ const channels = defineTable({
257
+ id: CHANNEL_ID,
258
+ name: {
259
+ type: "string",
260
+ maxLength: 255,
261
+ unique: true
262
+ }
263
+ }, {
264
+ key: ["id"],
265
+ indexes: { all: {
266
+ eq: [],
267
+ sort: ["name"]
268
+ } }
269
+ });
270
+ /**
271
+ * The native builds `native-build android` and `native-build ios` track, newest first
272
+ * in each scope: a platform, a channel, and the fingerprint or app version
273
+ * the build compiled in. `min_bundle_id` names the build's built-in bundle,
274
+ * a `bundles` row no release publishes. Its references keep no counters, so
275
+ * adding this table changes no existing one; a channel with builds is
276
+ * refused deletion through `byChannel`. `build_key` is the native build key
277
+ * of every input the artifact was built from (`nbk1:` and a SHA-256), which
278
+ * a build with the same inputs reuses it by; a build registered without
279
+ * one is never reused. `build_number` is the artifact's `CFBundleVersion`
280
+ * or `versionCode`. `submitted_to`, `submitted_at_ms` and
281
+ * `submitted_version` record the store track a build went to, when, and
282
+ * the store's label of the build; they stay null for a build no store took.
283
+ */
284
+ const nativeBuilds = defineTable({
285
+ id: {
286
+ type: "string",
287
+ maxLength: 36
288
+ },
289
+ scope_key: {
290
+ type: "string",
291
+ maxLength: 2048,
292
+ ascii: true
293
+ },
294
+ platform: {
295
+ type: "string",
296
+ maxLength: 16
297
+ },
298
+ channel_id: {
299
+ ...CHANNEL_ID,
300
+ references: {
301
+ model: "channels",
302
+ onDelete: "none"
303
+ }
304
+ },
305
+ fingerprint_hash: {
306
+ type: "string",
307
+ maxLength: 255,
308
+ required: false
309
+ },
310
+ app_version: {
311
+ type: "string",
312
+ required: false
313
+ },
314
+ min_bundle_id: {
315
+ type: "string",
316
+ maxLength: 36,
317
+ unique: true,
318
+ references: {
319
+ model: "bundles",
320
+ onDelete: "none"
321
+ }
322
+ },
323
+ artifact_kind: {
324
+ type: "string",
325
+ maxLength: 16
326
+ },
327
+ artifact_storage_uri: { type: "string" },
328
+ byte_size: { type: "integer" },
329
+ git_commit_hash: {
330
+ type: "string",
331
+ maxLength: 255,
332
+ required: false
333
+ },
334
+ created_at_ms: { type: "integer" },
335
+ build_key: {
336
+ type: "string",
337
+ maxLength: 69,
338
+ ascii: true,
339
+ required: false
340
+ },
341
+ build_number: {
342
+ type: "string",
343
+ maxLength: 64,
344
+ required: false
345
+ },
346
+ submitted_to: {
347
+ type: "string",
348
+ maxLength: 16,
349
+ required: false
350
+ },
351
+ submitted_at_ms: {
352
+ type: "integer",
353
+ required: false
354
+ },
355
+ submitted_version: {
356
+ type: "string",
357
+ maxLength: 255,
358
+ required: false
359
+ }
360
+ }, {
361
+ key: ["id"],
362
+ indexes: {
363
+ byScope: {
364
+ eq: ["scope_key"],
365
+ sort: ["id"]
223
366
  },
224
- fingerprint_hash: {
225
- type: "string",
226
- maxLength: 255,
227
- required: false
367
+ byBuildKey: {
368
+ eq: ["scope_key", "build_key"],
369
+ sort: ["id"]
228
370
  },
229
- generation: { type: "integer" },
230
- payload: { type: "string" },
231
- catalog_hash: {
232
- type: "string",
233
- maxLength: 71
371
+ byChannel: {
372
+ eq: ["channel_id"],
373
+ sort: ["id"],
374
+ root: { model: "channels" }
234
375
  },
235
- byte_size: { type: "integer" },
236
- is_tombstone: { type: "boolean" },
237
- updated_at_ms: { type: "integer" }
238
- }, {
239
- key: ["scope_key"],
240
- indexes: { all: {
376
+ all: {
241
377
  eq: [],
242
- sort: ["scope_key"]
243
- } }
244
- }),
245
- channels: defineTable({
246
- id: CHANNEL_ID,
247
- name: {
248
- type: "string",
249
- maxLength: 255,
250
- unique: true
378
+ sort: ["id"]
251
379
  }
252
- }, {
253
- key: ["id"],
254
- indexes: { all: {
255
- eq: [],
256
- sort: ["name"]
257
- } }
258
- }),
380
+ }
381
+ });
382
+ const coreSchema = {
383
+ bundles,
384
+ bundle_patches: bundlePatches,
385
+ releases,
386
+ release_catalogs: releaseCatalogs,
387
+ channels,
259
388
  bundle_totals: defineAggregate({ platform_key: {
260
389
  type: "string",
261
390
  maxLength: 16
@@ -266,7 +395,8 @@ const coreSchema = {
266
395
  eq: ["platform_key"],
267
396
  sort: []
268
397
  } }
269
- })
398
+ }),
399
+ native_builds: nativeBuilds
270
400
  };
271
401
  /** Core's module: always installed, never a plugin. */
272
402
  const coreModule = {
@@ -14,9 +14,9 @@ const require_coreDatabase = require("./db/coreDatabase.cjs");
14
14
  */
15
15
  const pluginTablesFix = (database) => {
16
16
  const { createMigrator, generateSchema } = database;
17
- const managed = "A managed server runs only its provider's plugins, and rerunning `hot-updater init --provider <provider>` applies the provider's migrations.";
17
+ const doctor = "Run `npx hot-updater doctor` in the project whose hot-updater.config.ts names this database: it names the command that migrates it.";
18
18
  const serverProject = "Run `hot-updater db` commands in the server's project: they load the server file named on the command line, or src/hotUpdater.* or src/db.*, and don't read hot-updater.config.ts.";
19
- return createMigrator !== void 0 ? `Run \`hot-updater db migrate\`. ${managed} ${serverProject}` : generateSchema !== void 0 ? `Run \`hot-updater db generate\` and apply the file it writes. ${managed} ${serverProject}` : managed;
19
+ return createMigrator !== void 0 ? `${doctor} In a server project, run \`hot-updater db migrate\`. ${serverProject}` : generateSchema !== void 0 ? `${doctor} On a database \`hot-updater init\` created, that is init again with its saved inputs; for your own server, run \`hot-updater db generate\` and apply the file it writes. ${serverProject}` : `${doctor} On a database \`hot-updater init\` created, that is init again with its saved inputs.`;
20
20
  };
21
21
  /**
22
22
  * The storage engine over a database, as a server runs it: core's tables
@@ -14,9 +14,9 @@ import { pluginModule, pluginSettings } from "./db/coreDatabase.mjs";
14
14
  */
15
15
  const pluginTablesFix = (database) => {
16
16
  const { createMigrator, generateSchema } = database;
17
- const managed = "A managed server runs only its provider's plugins, and rerunning `hot-updater init --provider <provider>` applies the provider's migrations.";
17
+ const doctor = "Run `npx hot-updater doctor` in the project whose hot-updater.config.ts names this database: it names the command that migrates it.";
18
18
  const serverProject = "Run `hot-updater db` commands in the server's project: they load the server file named on the command line, or src/hotUpdater.* or src/db.*, and don't read hot-updater.config.ts.";
19
- return createMigrator !== void 0 ? `Run \`hot-updater db migrate\`. ${managed} ${serverProject}` : generateSchema !== void 0 ? `Run \`hot-updater db generate\` and apply the file it writes. ${managed} ${serverProject}` : managed;
19
+ return createMigrator !== void 0 ? `${doctor} In a server project, run \`hot-updater db migrate\`. ${serverProject}` : generateSchema !== void 0 ? `${doctor} On a database \`hot-updater init\` created, that is init again with its saved inputs; for your own server, run \`hot-updater db generate\` and apply the file it writes. ${serverProject}` : `${doctor} On a database \`hot-updater init\` created, that is init again with its saved inputs.`;
20
20
  };
21
21
  /**
22
22
  * The storage engine over a database, as a server runs it: core's tables