@hot-updater/plugin-core 1.2.0-rc.5 → 1.2.0-rc.51

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 (89) hide show
  1. package/dist/coreApi.d.cts +277 -10
  2. package/dist/coreApi.d.mts +277 -10
  3. package/dist/database/adapter.d.cts +24 -0
  4. package/dist/database/adapter.d.mts +24 -0
  5. package/dist/databaseRows.cjs +4 -2
  6. package/dist/databaseRows.mjs +4 -2
  7. package/dist/engine/core/schema.cjs +253 -6
  8. package/dist/engine/core/schema.d.cts +154 -1
  9. package/dist/engine/core/schema.d.mts +154 -1
  10. package/dist/engine/core/schema.mjs +252 -7
  11. package/dist/engine/createEngine.cjs +1 -2
  12. package/dist/engine/createEngine.d.cts +1 -6
  13. package/dist/engine/createEngine.d.mts +1 -6
  14. package/dist/engine/createEngine.mjs +1 -2
  15. package/dist/engine/database/aggregateBatching.cjs +87 -129
  16. package/dist/engine/database/aggregateBatching.mjs +87 -129
  17. package/dist/engine/database/database.cjs +1 -4
  18. package/dist/engine/database/database.mjs +1 -4
  19. package/dist/engine/database/engineTransaction.cjs +21 -1
  20. package/dist/engine/database/engineTransaction.d.cts +5 -1
  21. package/dist/engine/database/engineTransaction.d.mts +5 -1
  22. package/dist/engine/database/engineTransaction.mjs +21 -1
  23. package/dist/engine/database/kv/kvAdapter.cjs +80 -4
  24. package/dist/engine/database/kv/kvAdapter.mjs +80 -4
  25. package/dist/engine/database/resolveSchema.cjs +6 -3
  26. package/dist/engine/database/resolveSchema.mjs +6 -3
  27. package/dist/engine/database/sql/sqlAdapter.cjs +36 -12
  28. package/dist/engine/database/sql/sqlAdapter.mjs +37 -13
  29. package/dist/engine/database/sql/sqlSchema.cjs +24 -6
  30. package/dist/engine/database/sql/sqlSchema.d.cts +1 -1
  31. package/dist/engine/database/sql/sqlSchema.d.mts +1 -1
  32. package/dist/engine/database/sql/sqlSchema.mjs +24 -6
  33. package/dist/engine/db/coreDatabase.cjs +10 -5
  34. package/dist/engine/db/coreDatabase.d.cts +2 -1
  35. package/dist/engine/db/coreDatabase.d.mts +2 -1
  36. package/dist/engine/db/coreDatabase.mjs +10 -5
  37. package/dist/engine/db/engineMigrator.cjs +45 -17
  38. package/dist/engine/db/engineMigrator.mjs +46 -18
  39. package/dist/engine/db/engineSql.cjs +25 -0
  40. package/dist/engine/db/engineSql.d.cts +13 -1
  41. package/dist/engine/db/engineSql.d.mts +13 -1
  42. package/dist/engine/db/engineSql.mjs +26 -2
  43. package/dist/engine/db/engineSqlMigrator.cjs +60 -21
  44. package/dist/engine/db/engineSqlMigrator.d.cts +2 -0
  45. package/dist/engine/db/engineSqlMigrator.d.mts +2 -0
  46. package/dist/engine/db/engineSqlMigrator.mjs +62 -23
  47. package/dist/engine/db/schemaSettings.cjs +56 -5
  48. package/dist/engine/db/schemaSettings.d.cts +5 -2
  49. package/dist/engine/db/schemaSettings.d.mts +5 -2
  50. package/dist/engine/db/schemaSettings.mjs +55 -6
  51. package/dist/engine/db/settingsMigrator.cjs +124 -15
  52. package/dist/engine/db/settingsMigrator.d.cts +18 -8
  53. package/dist/engine/db/settingsMigrator.d.mts +18 -8
  54. package/dist/engine/db/settingsMigrator.mjs +121 -16
  55. package/dist/engine/db/sqlSchemaState.cjs +136 -0
  56. package/dist/engine/db/sqlSchemaState.mjs +131 -0
  57. package/dist/engine/db/types.d.cts +6 -0
  58. package/dist/engine/db/types.d.mts +6 -0
  59. package/dist/index.cjs +3 -8
  60. package/dist/index.d.cts +6 -7
  61. package/dist/index.d.mts +6 -7
  62. package/dist/index.mjs +4 -5
  63. package/dist/releaseCatalogCompiler.cjs +18 -7
  64. package/dist/releaseCatalogCompiler.mjs +18 -7
  65. package/dist/releaseCatalogMutation.d.cts +6 -0
  66. package/dist/releaseCatalogMutation.d.mts +6 -0
  67. package/dist/serverPlugin/coreReads.d.cts +10 -1
  68. package/dist/serverPlugin/coreReads.d.mts +10 -1
  69. package/dist/serverPlugin/definitions.d.cts +4 -0
  70. package/dist/serverPlugin/definitions.d.mts +4 -0
  71. package/dist/serverPlugin/schema.d.cts +4 -0
  72. package/dist/serverPlugin/schema.d.mts +4 -0
  73. package/dist/types/databaseConfig.d.cts +10 -20
  74. package/dist/types/databaseConfig.d.mts +10 -20
  75. package/dist/types/databaseRows.d.cts +77 -2
  76. package/dist/types/databaseRows.d.mts +77 -2
  77. package/dist/types/index.cjs +3 -0
  78. package/dist/types/index.d.cts +114 -56
  79. package/dist/types/index.d.mts +114 -56
  80. package/dist/types/index.mjs +3 -1
  81. package/dist/types/models.d.cts +9 -1
  82. package/dist/types/models.d.mts +9 -1
  83. package/dist/types/public.d.cts +3 -3
  84. package/dist/types/public.d.mts +3 -3
  85. package/package.json +3 -9
  86. package/dist/remoteBundleSigning.cjs +0 -357
  87. package/dist/remoteBundleSigning.d.cts +0 -38
  88. package/dist/remoteBundleSigning.d.mts +0 -38
  89. package/dist/remoteBundleSigning.mjs +0 -352
@@ -14,9 +14,13 @@ const CHANNEL_ID = {
14
14
  * applies it to managed databases an earlier release created. The official
15
15
  * plugins' `schemaVersion`s follow the same rule. A bump only adds tables:
16
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.
17
+ * version, and none of them changes an existing table's columns, so changing
18
+ * one needs a migration step of its own first. An index added to an existing
19
+ * table is listed in `LATE_INDEXES`, and a column in `LATE_COLUMNS`. The schema fence answers 503 on
20
+ * a database whose row differs, until it runs. Before a version is released,
21
+ * its tables change in place in its own migration, and a database one of its
22
+ * prereleases migrated takes the same change by hand: the fence compares this
23
+ * row, not columns, so nothing reports it.
20
24
  */
21
25
  const HOT_UPDATER_SCHEMA_VERSION = "1.2.0";
22
26
  const bundles = defineTable({
@@ -165,7 +169,11 @@ const releases = defineTable({
165
169
  }
166
170
  },
167
171
  created_at_ms: { type: "integer" },
168
- updated_at_ms: { type: "integer" }
172
+ updated_at_ms: { type: "integer" },
173
+ label: {
174
+ type: "integer",
175
+ required: false
176
+ }
169
177
  }, {
170
178
  key: ["id"],
171
179
  indexes: {
@@ -198,9 +206,72 @@ const releases = defineTable({
198
206
  all: {
199
207
  eq: [],
200
208
  sort: ["id"]
209
+ },
210
+ scopes: {
211
+ eq: [],
212
+ sort: ["scope_key"]
213
+ },
214
+ byLabel: {
215
+ eq: [
216
+ "channel_id",
217
+ "platform",
218
+ "label"
219
+ ],
220
+ sort: [],
221
+ unique: true
201
222
  }
202
223
  }
203
224
  });
225
+ /**
226
+ * Indexes declared on a table that a released schema's servers write: a
227
+ * store that keeps index items of its own (`migrations.fillIndex`) lacks
228
+ * them for rows written before, and for rows such a server still writes
229
+ * after the migration, since its schema fence keeps a check that passed.
230
+ * Each migration writes the missing items, and `db migrate` on a database
231
+ * whose settings match looks for them. `releases.scopes` arrived in 1.2.0;
232
+ * 1.1.x servers write releases without it.
233
+ */
234
+ const LATE_INDEXES = [{
235
+ table: "releases",
236
+ index: "scopes"
237
+ }];
238
+ /**
239
+ * Columns added to a table that a released schema created: a migrator whose
240
+ * store has columns adds each one missing from an existing table, with
241
+ * `ALTER TABLE … ADD COLUMN`, before it creates the table's indexes, and
242
+ * `db migrate` on a database whose settings match still looks for them,
243
+ * since a database a prerelease migrated records the same settings. Each
244
+ * is optional, so rows written before it, and rows a server of the earlier
245
+ * release still writes, read as null. `releases.label` arrived in 1.2.0.
246
+ */
247
+ const LATE_COLUMNS = [{
248
+ table: "releases",
249
+ column: "label"
250
+ }];
251
+ /**
252
+ * One counter per sequence: `releases/<platform>/<channel ID>` holds the
253
+ * last label that channel and platform's releases took. A deploy or a
254
+ * promote reads it and writes the next value in the transaction that writes
255
+ * the release, so two writers never take one label. `is_filled` is true once
256
+ * every release of the sequence written before labels has one, in ID order;
257
+ * until then a writer fills them first. Deleting a channel deletes its
258
+ * counters, so a channel created again with the name starts at 1.
259
+ */
260
+ const labelSequences = defineTable({
261
+ id: {
262
+ type: "string",
263
+ maxLength: 1440,
264
+ ascii: true
265
+ },
266
+ last_label: { type: "integer" },
267
+ is_filled: { type: "boolean" }
268
+ }, {
269
+ key: ["id"],
270
+ indexes: { all: {
271
+ eq: [],
272
+ sort: ["id"]
273
+ } }
274
+ });
204
275
  /** One compiled catalog per scope; the update check reads exactly this row. */
205
276
  const releaseCatalogs = defineTable({
206
277
  scope_key: {
@@ -270,7 +341,10 @@ const channels = defineTable({
270
341
  /**
271
342
  * The native builds `native-build android` and `native-build ios` track, newest first
272
343
  * 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,
344
+ * the build compiled in. A sandbox build's scope has no channel: its app ID,
345
+ * URL scheme, artifact kind and distribution in its place, so pull requests
346
+ * reuse it across channels, while `channel_id` still names the channel it
347
+ * embeds. `min_bundle_id` names the build's built-in bundle,
274
348
  * a `bundles` row no release publishes. Its references keep no counters, so
275
349
  * adding this table changes no existing one; a channel with builds is
276
350
  * refused deletion through `byChannel`. `build_key` is the native build key
@@ -280,6 +354,27 @@ const channels = defineTable({
280
354
  * or `versionCode`. `submitted_to`, `submitted_at_ms` and
281
355
  * `submitted_version` record the store track a build went to, when, and
282
356
  * the store's label of the build; they stay null for a build no store took.
357
+ * `is_store_build` is true on the build a person or a job says the store
358
+ * sells, and false on every other: deploys patch from it over the scope's
359
+ * newest build. The engine copies the scope key into `store_build_scope_key`
360
+ * for that build alone, so `byStoreBuild` holds one entry per scope at most,
361
+ * on every store, while any number of a scope's builds hold none.
362
+ * `is_sandbox` is true on a sandbox build, set from its artifact when it
363
+ * registers and never changed, and `sandbox_url_scheme` is the URL scheme its artifact registers,
364
+ * which its preview links open; null on any other build, and on a sandbox
365
+ * build registered before the column, which registered the derived one.
366
+ * `export_method` is how an `.ipa` was exported, read from its profile when
367
+ * it registers and never changed; null on any other artifact, on an `.ipa`
368
+ * whose profile couldn't be read, and on one registered before the column.
369
+ * `native_app_version` is the app version the artifact itself reports, its
370
+ * `CFBundleShortVersionString` or `versionName`, read from the artifact when
371
+ * it registers and never changed, whatever the update strategy; `app_version`
372
+ * stays the version OTAs target, null on a fingerprint build. It is null
373
+ * when the artifact's can't be read, and on a build registered before the
374
+ * column.
375
+ * Boolean columns follow one rule: `is_*` for a fact about the row or
376
+ * `should_*` for an instruction to the client, never null; a unique index over
377
+ * the rows where one is true keys a derived slot, not the boolean.
283
378
  */
284
379
  const nativeBuilds = defineTable({
285
380
  id: {
@@ -356,9 +451,34 @@ const nativeBuilds = defineTable({
356
451
  type: "string",
357
452
  maxLength: 255,
358
453
  required: false
454
+ },
455
+ is_store_build: { type: "boolean" },
456
+ is_sandbox: { type: "boolean" },
457
+ sandbox_url_scheme: {
458
+ type: "string",
459
+ maxLength: 255,
460
+ ascii: true,
461
+ required: false
462
+ },
463
+ export_method: {
464
+ type: "string",
465
+ maxLength: 16,
466
+ required: false
467
+ },
468
+ native_app_version: {
469
+ type: "string",
470
+ required: false
359
471
  }
360
472
  }, {
361
473
  key: ["id"],
474
+ derived: {
475
+ /** The scope this build is the store build of; null on every other. */
476
+ store_build_scope_key: {
477
+ type: "string",
478
+ maxLength: 2048,
479
+ ascii: true,
480
+ compute: (row) => row.is_store_build ? row.scope_key : null
481
+ } },
362
482
  indexes: {
363
483
  byScope: {
364
484
  eq: ["scope_key"],
@@ -368,6 +488,15 @@ const nativeBuilds = defineTable({
368
488
  eq: ["scope_key", "build_key"],
369
489
  sort: ["id"]
370
490
  },
491
+ byScopeKind: {
492
+ eq: ["scope_key", "artifact_kind"],
493
+ sort: ["id"]
494
+ },
495
+ byStoreBuild: {
496
+ eq: ["store_build_scope_key"],
497
+ sort: [],
498
+ unique: true
499
+ },
371
500
  byChannel: {
372
501
  eq: ["channel_id"],
373
502
  sort: ["id"],
@@ -379,6 +508,119 @@ const nativeBuilds = defineTable({
379
508
  }
380
509
  }
381
510
  });
511
+ /**
512
+ * The iPhones a team asks to install ad hoc builds on. A row decides what the
513
+ * CLI registers with Apple, not what an export includes: Xcode's automatic ad
514
+ * hoc profile lists every device the Apple account has enabled. `status` is
515
+ * `pending` until someone approves it, `approved` until a build or
516
+ * `native-build devices add` registers it with Apple, then `registered`;
517
+ * declining or removing one deletes its row. `udid` is the UDID in lower case.
518
+ * `apple_issuer_id` is the App Store Connect issuer whose key registered it,
519
+ * set once: a build signed by another account never registers these rows.
520
+ * `apple_error` is Apple's refusal of the device, or why it stopped counting
521
+ * it, cleared by the next success. `build_id` is the newest native build whose
522
+ * .ipa the CLI checked lists it; deleting that build never touches the row.
523
+ * It holds personal data: a UDID, a name, and the emails of who asked and who
524
+ * approved, null for the CLI.
525
+ */
526
+ const iosDevices = defineTable({
527
+ id: {
528
+ type: "string",
529
+ maxLength: 36
530
+ },
531
+ udid: {
532
+ type: "string",
533
+ maxLength: 40,
534
+ ascii: true,
535
+ unique: true
536
+ },
537
+ name: {
538
+ type: "string",
539
+ maxLength: 100
540
+ },
541
+ status: {
542
+ type: "string",
543
+ maxLength: 16
544
+ },
545
+ requested_by: {
546
+ type: "string",
547
+ maxLength: 320,
548
+ required: false
549
+ },
550
+ created_at_ms: { type: "integer" },
551
+ approved_by: {
552
+ type: "string",
553
+ maxLength: 320,
554
+ required: false
555
+ },
556
+ approved_at_ms: {
557
+ type: "integer",
558
+ required: false
559
+ },
560
+ registered_at_ms: {
561
+ type: "integer",
562
+ required: false
563
+ },
564
+ apple_issuer_id: {
565
+ type: "string",
566
+ maxLength: 64,
567
+ ascii: true,
568
+ required: false
569
+ },
570
+ apple_error: {
571
+ type: "string",
572
+ maxLength: 512,
573
+ required: false
574
+ },
575
+ build_id: {
576
+ type: "string",
577
+ maxLength: 36,
578
+ required: false
579
+ }
580
+ }, {
581
+ key: ["id"],
582
+ indexes: {
583
+ byStatus: {
584
+ eq: ["status"],
585
+ sort: ["id"]
586
+ },
587
+ byRegistration: {
588
+ eq: [],
589
+ sort: ["registered_at_ms"]
590
+ },
591
+ all: {
592
+ eq: [],
593
+ sort: ["id"]
594
+ }
595
+ }
596
+ });
597
+ /**
598
+ * The Apple account the iOS device registry belongs to: one row, keyed
599
+ * `registry`, holding the App Store Connect issuer that first registered a
600
+ * device. A build claims it before it sends Apple anything, and its key makes
601
+ * the claim atomic on every store, so two builds of two accounts can't both
602
+ * spend a slot; another account's build then registers nothing. Removing
603
+ * devices never releases it.
604
+ */
605
+ const iosDeviceAccount = defineTable({
606
+ id: {
607
+ type: "string",
608
+ maxLength: 16,
609
+ ascii: true
610
+ },
611
+ apple_issuer_id: {
612
+ type: "string",
613
+ maxLength: 64,
614
+ ascii: true
615
+ },
616
+ claimed_at_ms: { type: "integer" }
617
+ }, {
618
+ key: ["id"],
619
+ indexes: { all: {
620
+ eq: [],
621
+ sort: ["id"]
622
+ } }
623
+ });
382
624
  const coreSchema = {
383
625
  bundles,
384
626
  bundle_patches: bundlePatches,
@@ -396,7 +638,10 @@ const coreSchema = {
396
638
  sort: []
397
639
  } }
398
640
  }),
399
- native_builds: nativeBuilds
641
+ native_builds: nativeBuilds,
642
+ ios_devices: iosDevices,
643
+ ios_device_account: iosDeviceAccount,
644
+ label_sequences: labelSequences
400
645
  };
401
646
  /** Core's module: always installed, never a plugin. */
402
647
  const coreModule = {
@@ -404,4 +649,4 @@ const coreModule = {
404
649
  schema: coreSchema
405
650
  };
406
651
  //#endregion
407
- export { HOT_UPDATER_SCHEMA_VERSION, coreModule, coreSchema };
652
+ export { HOT_UPDATER_SCHEMA_VERSION, LATE_COLUMNS, LATE_INDEXES, coreModule, coreSchema };
@@ -64,8 +64,7 @@ const createEngine = (database, { plugins = [], now = Date.now } = {}) => {
64
64
  if (module === void 0) throw new require_configError.HotUpdaterConfigError(`Plugin "${plugin.id}" is not one of this engine's plugins.`);
65
65
  return engine.database(module);
66
66
  },
67
- flush: () => engine.flush(),
68
- dispose: () => engine.dispose()
67
+ flush: () => engine.flush()
69
68
  };
70
69
  };
71
70
  //#endregion
@@ -23,13 +23,8 @@ interface Engine {
23
23
  readonly id: string;
24
24
  readonly schema: TSchema;
25
25
  }): HotUpdaterDatabase<TSchema>;
26
- /**
27
- * Applies aggregate changes the database batches that are still pending:
28
- * this process's buffer, and the log rows no compaction has merged yet.
29
- */
26
+ /** Applies the log rows of batched aggregates that no compaction has merged yet. */
30
27
  flush(): Promise<void>;
31
- /** Stops batching's timer after a last flush. */
32
- dispose(): Promise<void>;
33
28
  }
34
29
  /**
35
30
  * The storage engine over a database, as a server runs it: core's tables
@@ -23,13 +23,8 @@ interface Engine {
23
23
  readonly id: string;
24
24
  readonly schema: TSchema;
25
25
  }): HotUpdaterDatabase<TSchema>;
26
- /**
27
- * Applies aggregate changes the database batches that are still pending:
28
- * this process's buffer, and the log rows no compaction has merged yet.
29
- */
26
+ /** Applies the log rows of batched aggregates that no compaction has merged yet. */
30
27
  flush(): Promise<void>;
31
- /** Stops batching's timer after a last flush. */
32
- dispose(): Promise<void>;
33
28
  }
34
29
  /**
35
30
  * The storage engine over a database, as a server runs it: core's tables
@@ -64,8 +64,7 @@ const createEngine = (database, { plugins = [], now = Date.now } = {}) => {
64
64
  if (module === void 0) throw new HotUpdaterConfigError(`Plugin "${plugin.id}" is not one of this engine's plugins.`);
65
65
  return engine.database(module);
66
66
  },
67
- flush: () => engine.flush(),
68
- dispose: () => engine.dispose()
67
+ flush: () => engine.flush()
69
68
  };
70
69
  };
71
70
  //#endregion