@hot-updater/plugin-core 1.2.0-rc.12 → 1.2.0-rc.13

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.
@@ -1,5 +1,5 @@
1
1
  import { BundlePatchRow, BundleRow, ChannelRow, DatabaseBundleMetadata, NativeBuildArtifactKind, NativeBuildRow, NativeBuildSubmissionDestination, ReleaseCatalogRow, ReleaseRow } from "./types/databaseRows.cjs";
2
- import { ChannelDeleteResult, NativeBuildDeleteResult } from "./types/models.cjs";
2
+ import { ChannelDeleteResult, NativeBuildDeleteResult, NativeBuildMarkResult } from "./types/models.cjs";
3
3
  import { Bundle, Platform } from "./types/index.cjs";
4
4
  import { ReleaseCatalogMutationPreflight, ReleaseCatalogMutationResult, ReleaseCatalogRebuildPreflight, ReleaseCatalogRebuildResult } from "./releaseCatalogMutation.cjs";
5
5
  import { PromoteReleaseResult, ReleasePolicyPatch } from "./releaseManagement.cjs";
@@ -146,12 +146,19 @@ interface HotUpdaterCoreApi {
146
146
  /** A native build by ID: one read of its key. */
147
147
  getNativeBuild(id: string): Promise<NativeBuildRow | null>;
148
148
  /**
149
- * The newest native build of a scope: one read of its index. With
150
- * `buildKey`, the newest of the scope registered with that native build
151
- * key, also one read.
149
+ * The newest native build of a scope: the one registered last, in one read
150
+ * of its index. With `buildKey`, the newest of the scope registered with that
151
+ * native build key, also one read. With `storeBuild`, the scope's marked
152
+ * build or null, also one read. With `builtInOlderThan`, the newest of the
153
+ * scope whose built-in bundle is older than that bundle: one read when the
154
+ * newest is, and then a page of older builds per read until one is, when
155
+ * builds made after the bundle are in the way. With `buildKey` too, only
156
+ * builds of that key.
152
157
  */
153
158
  findNativeBuild(scope: NativeBuildScope, options?: {
154
159
  readonly buildKey?: string;
160
+ readonly storeBuild?: true;
161
+ readonly builtInOlderThan?: string;
155
162
  }): Promise<NativeBuildRow | null>;
156
163
  /**
157
164
  * One page of native builds, by ID: oldest or newest first. With
@@ -217,6 +224,14 @@ interface HotUpdaterCoreApi {
217
224
  * full bundles. Its artifact stays in storage for the caller to delete.
218
225
  */
219
226
  deleteNativeBuild(id: string): Promise<NativeBuildDeleteResult>;
227
+ /**
228
+ * Marks a build as what the store sells, replacing its scope's mark in one
229
+ * write, or clears the mark it holds. Running it again changes nothing. Null
230
+ * for an unknown ID. A sandbox channel's build can't be marked.
231
+ */
232
+ markNativeBuild(id: string, mark: {
233
+ readonly storeBuild: boolean;
234
+ }): Promise<NativeBuildMarkResult | null>;
220
235
  }
221
236
  //#endregion
222
237
  export { BundleDeployment, BundleDetail, DeployReleasePolicy, Deployment, HotUpdaterCoreApi, KeysetInput, NativeBuildRegistration, NativeBuildScope, ReleaseFilter, ReleaseTarget, StoredBundleDeployment };
@@ -1,5 +1,5 @@
1
1
  import { BundlePatchRow, BundleRow, ChannelRow, DatabaseBundleMetadata, NativeBuildArtifactKind, NativeBuildRow, NativeBuildSubmissionDestination, ReleaseCatalogRow, ReleaseRow } from "./types/databaseRows.mjs";
2
- import { ChannelDeleteResult, NativeBuildDeleteResult } from "./types/models.mjs";
2
+ import { ChannelDeleteResult, NativeBuildDeleteResult, NativeBuildMarkResult } from "./types/models.mjs";
3
3
  import { Bundle, Platform } from "./types/index.mjs";
4
4
  import { ReleaseCatalogMutationPreflight, ReleaseCatalogMutationResult, ReleaseCatalogRebuildPreflight, ReleaseCatalogRebuildResult } from "./releaseCatalogMutation.mjs";
5
5
  import { PromoteReleaseResult, ReleasePolicyPatch } from "./releaseManagement.mjs";
@@ -146,12 +146,19 @@ interface HotUpdaterCoreApi {
146
146
  /** A native build by ID: one read of its key. */
147
147
  getNativeBuild(id: string): Promise<NativeBuildRow | null>;
148
148
  /**
149
- * The newest native build of a scope: one read of its index. With
150
- * `buildKey`, the newest of the scope registered with that native build
151
- * key, also one read.
149
+ * The newest native build of a scope: the one registered last, in one read
150
+ * of its index. With `buildKey`, the newest of the scope registered with that
151
+ * native build key, also one read. With `storeBuild`, the scope's marked
152
+ * build or null, also one read. With `builtInOlderThan`, the newest of the
153
+ * scope whose built-in bundle is older than that bundle: one read when the
154
+ * newest is, and then a page of older builds per read until one is, when
155
+ * builds made after the bundle are in the way. With `buildKey` too, only
156
+ * builds of that key.
152
157
  */
153
158
  findNativeBuild(scope: NativeBuildScope, options?: {
154
159
  readonly buildKey?: string;
160
+ readonly storeBuild?: true;
161
+ readonly builtInOlderThan?: string;
155
162
  }): Promise<NativeBuildRow | null>;
156
163
  /**
157
164
  * One page of native builds, by ID: oldest or newest first. With
@@ -217,6 +224,14 @@ interface HotUpdaterCoreApi {
217
224
  * full bundles. Its artifact stays in storage for the caller to delete.
218
225
  */
219
226
  deleteNativeBuild(id: string): Promise<NativeBuildDeleteResult>;
227
+ /**
228
+ * Marks a build as what the store sells, replacing its scope's mark in one
229
+ * write, or clears the mark it holds. Running it again changes nothing. Null
230
+ * for an unknown ID. A sandbox channel's build can't be marked.
231
+ */
232
+ markNativeBuild(id: string, mark: {
233
+ readonly storeBuild: boolean;
234
+ }): Promise<NativeBuildMarkResult | null>;
220
235
  }
221
236
  //#endregion
222
237
  export { BundleDeployment, BundleDetail, DeployReleasePolicy, Deployment, HotUpdaterCoreApi, KeysetInput, NativeBuildRegistration, NativeBuildScope, ReleaseFilter, ReleaseTarget, StoredBundleDeployment };
@@ -16,7 +16,10 @@ const CHANNEL_ID = {
16
16
  * every database's migrator creates missing tables and then records the
17
17
  * version, and none of them changes an existing table, so changing one
18
18
  * needs a migration step of its own first. The schema fence answers 503 on
19
- * a database whose row differs, until it runs.
19
+ * a database whose row differs, until it runs. Before a version is released,
20
+ * its tables change in place in its own migration, and a database one of its
21
+ * prereleases migrated takes the same change by hand: the fence compares this
22
+ * row, not columns, so nothing reports it.
20
23
  */
21
24
  const HOT_UPDATER_SCHEMA_VERSION = "1.2.0";
22
25
  const bundles = require_schema.defineTable({
@@ -280,6 +283,10 @@ const channels = require_schema.defineTable({
280
283
  * or `versionCode`. `submitted_to`, `submitted_at_ms` and
281
284
  * `submitted_version` record the store track a build went to, when, and
282
285
  * the store's label of the build; they stay null for a build no store took.
286
+ * `store_build` is true on the build a person or a job says the store sells,
287
+ * and null on every other: deploys patch from it over the scope's newest build.
288
+ * It is never false, so `byStoreBuild` holds one entry per scope at most, on
289
+ * every store, and an unmarked row, older than the column or not, holds none.
283
290
  */
284
291
  const nativeBuilds = require_schema.defineTable({
285
292
  id: {
@@ -356,6 +363,10 @@ const nativeBuilds = require_schema.defineTable({
356
363
  type: "string",
357
364
  maxLength: 255,
358
365
  required: false
366
+ },
367
+ store_build: {
368
+ type: "boolean",
369
+ required: false
359
370
  }
360
371
  }, {
361
372
  key: ["id"],
@@ -368,6 +379,11 @@ const nativeBuilds = require_schema.defineTable({
368
379
  eq: ["scope_key", "build_key"],
369
380
  sort: ["id"]
370
381
  },
382
+ byStoreBuild: {
383
+ eq: ["scope_key", "store_build"],
384
+ sort: [],
385
+ unique: true
386
+ },
371
387
  byChannel: {
372
388
  eq: ["channel_id"],
373
389
  sort: ["id"],
@@ -385,6 +385,10 @@ declare const coreSchema: {
385
385
  readonly maxLength: 255;
386
386
  readonly required: false;
387
387
  };
388
+ readonly store_build: {
389
+ readonly type: "boolean";
390
+ readonly required: false;
391
+ };
388
392
  }, {}, {
389
393
  readonly byScope: {
390
394
  readonly eq: readonly ["scope_key"];
@@ -394,6 +398,11 @@ declare const coreSchema: {
394
398
  readonly eq: readonly ["scope_key", "build_key"];
395
399
  readonly sort: readonly ["id"];
396
400
  };
401
+ readonly byStoreBuild: {
402
+ readonly eq: readonly ["scope_key", "store_build"];
403
+ readonly sort: readonly [];
404
+ readonly unique: true;
405
+ };
397
406
  readonly byChannel: {
398
407
  readonly eq: readonly ["channel_id"];
399
408
  readonly sort: readonly ["id"];
@@ -385,6 +385,10 @@ declare const coreSchema: {
385
385
  readonly maxLength: 255;
386
386
  readonly required: false;
387
387
  };
388
+ readonly store_build: {
389
+ readonly type: "boolean";
390
+ readonly required: false;
391
+ };
388
392
  }, {}, {
389
393
  readonly byScope: {
390
394
  readonly eq: readonly ["scope_key"];
@@ -394,6 +398,11 @@ declare const coreSchema: {
394
398
  readonly eq: readonly ["scope_key", "build_key"];
395
399
  readonly sort: readonly ["id"];
396
400
  };
401
+ readonly byStoreBuild: {
402
+ readonly eq: readonly ["scope_key", "store_build"];
403
+ readonly sort: readonly [];
404
+ readonly unique: true;
405
+ };
397
406
  readonly byChannel: {
398
407
  readonly eq: readonly ["channel_id"];
399
408
  readonly sort: readonly ["id"];
@@ -16,7 +16,10 @@ const CHANNEL_ID = {
16
16
  * every database's migrator creates missing tables and then records the
17
17
  * version, and none of them changes an existing table, so changing one
18
18
  * needs a migration step of its own first. The schema fence answers 503 on
19
- * a database whose row differs, until it runs.
19
+ * a database whose row differs, until it runs. Before a version is released,
20
+ * its tables change in place in its own migration, and a database one of its
21
+ * prereleases migrated takes the same change by hand: the fence compares this
22
+ * row, not columns, so nothing reports it.
20
23
  */
21
24
  const HOT_UPDATER_SCHEMA_VERSION = "1.2.0";
22
25
  const bundles = defineTable({
@@ -280,6 +283,10 @@ const channels = defineTable({
280
283
  * or `versionCode`. `submitted_to`, `submitted_at_ms` and
281
284
  * `submitted_version` record the store track a build went to, when, and
282
285
  * the store's label of the build; they stay null for a build no store took.
286
+ * `store_build` is true on the build a person or a job says the store sells,
287
+ * and null on every other: deploys patch from it over the scope's newest build.
288
+ * It is never false, so `byStoreBuild` holds one entry per scope at most, on
289
+ * every store, and an unmarked row, older than the column or not, holds none.
283
290
  */
284
291
  const nativeBuilds = defineTable({
285
292
  id: {
@@ -356,6 +363,10 @@ const nativeBuilds = defineTable({
356
363
  type: "string",
357
364
  maxLength: 255,
358
365
  required: false
366
+ },
367
+ store_build: {
368
+ type: "boolean",
369
+ required: false
359
370
  }
360
371
  }, {
361
372
  key: ["id"],
@@ -368,6 +379,11 @@ const nativeBuilds = defineTable({
368
379
  eq: ["scope_key", "build_key"],
369
380
  sort: ["id"]
370
381
  },
382
+ byStoreBuild: {
383
+ eq: ["scope_key", "store_build"],
384
+ sort: [],
385
+ unique: true
386
+ },
371
387
  byChannel: {
372
388
  eq: ["channel_id"],
373
389
  sort: ["id"],
@@ -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
@@ -19,15 +19,8 @@ const LEASE_TABLE = "aggregate_lease";
19
19
  const LEASE = { id: "compaction" };
20
20
  /** How long a compaction holds the lease before another process may take it. */
21
21
  const LEASE_MS = 3e4;
22
- /**
23
- * Default windows: log mode compacts every 60 seconds, since reads compact
24
- * first; memory mode flushes every 15, since its window is what a crash
25
- * loses.
26
- */
27
- const WINDOW_MS = {
28
- log: 6e4,
29
- memory: 15e3
30
- };
22
+ /** A commit compacts once this has passed since the last compaction. */
23
+ const WINDOW_MS = 6e4;
31
24
  /** Log rows a compaction reads from each log table for one group. */
32
25
  const LOG_PAGE = 200;
33
26
  /**
@@ -41,8 +34,6 @@ const GROUPS = {
41
34
  };
42
35
  /** Tries per write after a conflict or a transient error. */
43
36
  const ATTEMPTS = 5;
44
- /** Aggregate rows a memory buffer holds before a commit waits for a flush. */
45
- const MAX_BUFFERED = 1e4;
46
37
  const log = require_schema.defineTable({
47
38
  id: {
48
39
  type: "string",
@@ -92,7 +83,7 @@ const valuesOf = ({ deltas, sketches }) => ({
92
83
  /**
93
84
  * Merges `values` into the change for `key`'s identity as `tx.aggregate`
94
85
  * does: deltas add up and sketches merge. One constant `shardBy` keys each
95
- * identity to one entry; the write picks the shard.
86
+ * identity to one entry; `compile` writes it to shard 0.
96
87
  */
97
88
  const merge = (into, model, key, values) => require_engineAggregates.recordAggregate(into, model, Object.fromEntries(shapeOf(model).key.map((field, at) => [field, key[at]])), values, "");
98
89
  const mergeAll = (into, changes) => {
@@ -126,7 +117,7 @@ const increment = ({ model, deltas }, key) => Object.values(deltas).some((delta)
126
117
  /**
127
118
  * The guarded write that merges `change` into `current`: insert, patch, or
128
119
  * delete at zero. Unlike a transaction's, a gauge may go below zero here: a
129
- * shard row holds one writer's net changes, and reads sum every shard.
120
+ * group can hold a loss without the gain before it, and reads sum every shard.
130
121
  */
131
122
  const rewrite = (change, key, current) => {
132
123
  const { model } = change;
@@ -164,12 +155,12 @@ const rewrite = (change, key, current) => {
164
155
  };
165
156
  };
166
157
  /**
167
- * The write for each change on its shard: a blind increment that creates
168
- * the row for counters, and a guarded rewrite for gauges and sketches, whose
169
- * rows are read in one batch per table.
158
+ * The write for each change on shard 0, since one compaction runs at a time:
159
+ * a blind increment that creates the row for counters, and a guarded rewrite
160
+ * for gauges and sketches, whose rows are read in one batch per table.
170
161
  */
171
- const compile = async (adapter, changes, shard) => {
172
- const keys = changes.map(({ model, key }) => [...key.slice(0, -1), shard(model)]);
162
+ const compile = async (adapter, changes) => {
163
+ const keys = changes.map(({ key }) => [...key.slice(0, -1), 0]);
173
164
  const reads = /* @__PURE__ */ new Map();
174
165
  changes.forEach((change, at) => {
175
166
  if (rewrites(change)) reads.set(change.model, [...reads.get(change.model) ?? [], at]);
@@ -223,14 +214,13 @@ const encode = async (changes) => {
223
214
  return zipped !== void 0 && zipped.length < json.length ? `z${zipped}` : json;
224
215
  };
225
216
  /**
226
- * Batches changes to aggregates declared `batched`. A transaction records
227
- * them without writing their rows; once it commits, "memory" mode keeps
228
- * them in this process until its timer flushes them, and "log" mode has
229
- * written them as one log row in the same atomic write, which a compaction
230
- * later merges into the aggregates and deletes, atomically again, so each
231
- * applies exactly once. One lease row keeps compactions one at a time.
217
+ * Batches changes to aggregates declared `batched`. A transaction writes
218
+ * them as one log row in its own atomic write, in place of their rows; a
219
+ * compaction later merges log rows into the aggregates and deletes them,
220
+ * atomically again, so each applies exactly once. One lease row keeps
221
+ * compactions one at a time.
232
222
  */
233
- const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "log", windowMs = WINDOW_MS[mode] }, now }) => {
223
+ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs = WINDOW_MS }, now }) => {
234
224
  if (!schema.models.has(LEASE_TABLE)) throw new require_errors.DatabaseTransactionError("An engine that batches aggregates needs aggregateBatchingModule in its schema.");
235
225
  const holder = crypto.randomUUID().replaceAll("-", "");
236
226
  const table = (name) => schema.models.get(name).table;
@@ -258,68 +248,6 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
258
248
  }
259
249
  return changes;
260
250
  };
261
- /**
262
- * Writes changes in atomic chunks within `fits`, and returns the ones it
263
- * could not apply. A write whose outcome is unknown is dropped, never
264
- * resent, so no change applies twice.
265
- */
266
- const apply = async (changes, shard) => {
267
- let rest = changes;
268
- let ops = [];
269
- let read = true;
270
- for (let failures = 0; rest.length > 0 && failures < ATTEMPTS;) try {
271
- if (read) ops = await compile(adapter, rest, shard);
272
- let size = rest.length;
273
- const chunk = () => ops.slice(0, size).filter(isOp);
274
- while (size > 1 && !adapter.fits(chunk())) size = Math.ceil(size / 2);
275
- let result = { ok: true };
276
- if (chunk().length > 0) result = await adapter.write(chunk()).catch((error) => {
277
- warn("flush")(error);
278
- return { ok: true };
279
- });
280
- read = !result.ok && !("retry" in result);
281
- if (result.ok) {
282
- rest = rest.slice(size);
283
- ops = ops.slice(size);
284
- failures = 0;
285
- } else {
286
- failures += 1;
287
- if (!read) await sleep(failures);
288
- }
289
- } catch (error) {
290
- warn("flush")(error);
291
- return rest;
292
- }
293
- return rest;
294
- };
295
- let buffer = /* @__PURE__ */ new Map();
296
- let timer;
297
- let flushing;
298
- const shards = /* @__PURE__ */ new Map();
299
- /** Each process writes its own shard, so flushes of two processes rarely meet. */
300
- const processShard = (model) => {
301
- if (!shards.has(model)) shards.set(model, Math.floor(Math.random() * shapeOf(model).shards));
302
- return shards.get(model);
303
- };
304
- const schedule = () => {
305
- if (timer !== void 0 || buffer.size === 0) return;
306
- timer = setTimeout(() => {
307
- timer = void 0;
308
- flushBuffer();
309
- }, windowMs);
310
- timer.unref?.();
311
- };
312
- /** Never rejects: what it cannot apply goes back into the buffer. */
313
- const flushBuffer = () => flushing ??= (async () => {
314
- clearTimeout(timer);
315
- timer = void 0;
316
- const pending = [...buffer.values()];
317
- buffer = /* @__PURE__ */ new Map();
318
- mergeAll(buffer, await apply(pending, processShard));
319
- })().catch(warn("flush")).finally(() => {
320
- flushing = void 0;
321
- schedule();
322
- });
323
251
  let nextDue = 0;
324
252
  let compacting;
325
253
  /** Log rows this process read, by `[log table's index, id]`, for the deletes after a group. */
@@ -454,7 +382,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
454
382
  more
455
383
  };
456
384
  };
457
- const rowsFor = async (changes) => (await compile(adapter, changes, () => 0)).filter(isOp);
385
+ const rowsFor = async (changes) => (await compile(adapter, changes)).filter(isOp);
458
386
  /**
459
387
  * Applies the oldest pending log rows whose merged changes fit in one
460
388
  * atomic write with the lease, which lists them as applied; the rows are
@@ -548,20 +476,6 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
548
476
  }))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
549
477
  checking = void 0;
550
478
  });
551
- /** Takes a committed transaction's changes; never rejects, since the transaction already committed. */
552
- const committed = async (changes) => {
553
- if (mode === "log") {
554
- if (now() >= nextDue) await compact(false, GROUPS.commit);
555
- return;
556
- }
557
- mergeAll(buffer, changes.values());
558
- schedule();
559
- if (buffer.size >= MAX_BUFFERED) await flushBuffer();
560
- };
561
- const flush = async () => {
562
- await flushBuffer();
563
- if (mode === "log" && await hasPending()) await compact(true, GROUPS.flush);
564
- };
565
479
  return {
566
480
  async transaction(fn) {
567
481
  let changes = /* @__PURE__ */ new Map();
@@ -587,7 +501,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
587
501
  aggregate
588
502
  });
589
503
  if (failure) throw failure.error;
590
- if (mode === "log" && attempt.size > 0) {
504
+ if (attempt.size > 0) {
591
505
  const id = `${now().toString(36).padStart(9, "0")}${holder.slice(0, 8)}${crypto.randomUUID().slice(0, 8)}`;
592
506
  const shard = Math.floor(Math.random() * LOG_TABLES.length);
593
507
  const merged = mergeAll(/* @__PURE__ */ new Map(), attempt.values());
@@ -601,24 +515,18 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
601
515
  open = false;
602
516
  }
603
517
  });
604
- if (changes.size > 0) await committed(changes);
518
+ if (changes.size > 0 && now() >= nextDue) await compact(false, GROUPS.commit);
605
519
  return result;
606
520
  },
607
521
  async beforeRead(name) {
608
522
  if (!isBatched(schema.models.get(name))) return;
609
- if (buffer.size > 0 || flushing !== void 0) await flushBuffer();
610
- if (mode === "log") {
611
- if (await hasPending().catch((error) => {
612
- warn("read")(error);
613
- return false;
614
- })) await compact(true, GROUPS.read);
615
- }
523
+ if (await hasPending().catch((error) => {
524
+ warn("read")(error);
525
+ return false;
526
+ })) await compact(true, GROUPS.read);
616
527
  },
617
- flush,
618
- async dispose() {
619
- clearTimeout(timer);
620
- timer = void 0;
621
- await flush();
528
+ async flush() {
529
+ if (await hasPending()) await compact(true, GROUPS.flush);
622
530
  }
623
531
  };
624
532
  };
@@ -19,15 +19,8 @@ const LEASE_TABLE = "aggregate_lease";
19
19
  const LEASE = { id: "compaction" };
20
20
  /** How long a compaction holds the lease before another process may take it. */
21
21
  const LEASE_MS = 3e4;
22
- /**
23
- * Default windows: log mode compacts every 60 seconds, since reads compact
24
- * first; memory mode flushes every 15, since its window is what a crash
25
- * loses.
26
- */
27
- const WINDOW_MS = {
28
- log: 6e4,
29
- memory: 15e3
30
- };
22
+ /** A commit compacts once this has passed since the last compaction. */
23
+ const WINDOW_MS = 6e4;
31
24
  /** Log rows a compaction reads from each log table for one group. */
32
25
  const LOG_PAGE = 200;
33
26
  /**
@@ -41,8 +34,6 @@ const GROUPS = {
41
34
  };
42
35
  /** Tries per write after a conflict or a transient error. */
43
36
  const ATTEMPTS = 5;
44
- /** Aggregate rows a memory buffer holds before a commit waits for a flush. */
45
- const MAX_BUFFERED = 1e4;
46
37
  const log = defineTable({
47
38
  id: {
48
39
  type: "string",
@@ -92,7 +83,7 @@ const valuesOf = ({ deltas, sketches }) => ({
92
83
  /**
93
84
  * Merges `values` into the change for `key`'s identity as `tx.aggregate`
94
85
  * does: deltas add up and sketches merge. One constant `shardBy` keys each
95
- * identity to one entry; the write picks the shard.
86
+ * identity to one entry; `compile` writes it to shard 0.
96
87
  */
97
88
  const merge = (into, model, key, values) => recordAggregate(into, model, Object.fromEntries(shapeOf(model).key.map((field, at) => [field, key[at]])), values, "");
98
89
  const mergeAll = (into, changes) => {
@@ -126,7 +117,7 @@ const increment = ({ model, deltas }, key) => Object.values(deltas).some((delta)
126
117
  /**
127
118
  * The guarded write that merges `change` into `current`: insert, patch, or
128
119
  * delete at zero. Unlike a transaction's, a gauge may go below zero here: a
129
- * shard row holds one writer's net changes, and reads sum every shard.
120
+ * group can hold a loss without the gain before it, and reads sum every shard.
130
121
  */
131
122
  const rewrite = (change, key, current) => {
132
123
  const { model } = change;
@@ -164,12 +155,12 @@ const rewrite = (change, key, current) => {
164
155
  };
165
156
  };
166
157
  /**
167
- * The write for each change on its shard: a blind increment that creates
168
- * the row for counters, and a guarded rewrite for gauges and sketches, whose
169
- * rows are read in one batch per table.
158
+ * The write for each change on shard 0, since one compaction runs at a time:
159
+ * a blind increment that creates the row for counters, and a guarded rewrite
160
+ * for gauges and sketches, whose rows are read in one batch per table.
170
161
  */
171
- const compile = async (adapter, changes, shard) => {
172
- const keys = changes.map(({ model, key }) => [...key.slice(0, -1), shard(model)]);
162
+ const compile = async (adapter, changes) => {
163
+ const keys = changes.map(({ key }) => [...key.slice(0, -1), 0]);
173
164
  const reads = /* @__PURE__ */ new Map();
174
165
  changes.forEach((change, at) => {
175
166
  if (rewrites(change)) reads.set(change.model, [...reads.get(change.model) ?? [], at]);
@@ -223,14 +214,13 @@ const encode = async (changes) => {
223
214
  return zipped !== void 0 && zipped.length < json.length ? `z${zipped}` : json;
224
215
  };
225
216
  /**
226
- * Batches changes to aggregates declared `batched`. A transaction records
227
- * them without writing their rows; once it commits, "memory" mode keeps
228
- * them in this process until its timer flushes them, and "log" mode has
229
- * written them as one log row in the same atomic write, which a compaction
230
- * later merges into the aggregates and deletes, atomically again, so each
231
- * applies exactly once. One lease row keeps compactions one at a time.
217
+ * Batches changes to aggregates declared `batched`. A transaction writes
218
+ * them as one log row in its own atomic write, in place of their rows; a
219
+ * compaction later merges log rows into the aggregates and deletes them,
220
+ * atomically again, so each applies exactly once. One lease row keeps
221
+ * compactions one at a time.
232
222
  */
233
- const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "log", windowMs = WINDOW_MS[mode] }, now }) => {
223
+ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs = WINDOW_MS }, now }) => {
234
224
  if (!schema.models.has(LEASE_TABLE)) throw new DatabaseTransactionError("An engine that batches aggregates needs aggregateBatchingModule in its schema.");
235
225
  const holder = crypto.randomUUID().replaceAll("-", "");
236
226
  const table = (name) => schema.models.get(name).table;
@@ -258,68 +248,6 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
258
248
  }
259
249
  return changes;
260
250
  };
261
- /**
262
- * Writes changes in atomic chunks within `fits`, and returns the ones it
263
- * could not apply. A write whose outcome is unknown is dropped, never
264
- * resent, so no change applies twice.
265
- */
266
- const apply = async (changes, shard) => {
267
- let rest = changes;
268
- let ops = [];
269
- let read = true;
270
- for (let failures = 0; rest.length > 0 && failures < ATTEMPTS;) try {
271
- if (read) ops = await compile(adapter, rest, shard);
272
- let size = rest.length;
273
- const chunk = () => ops.slice(0, size).filter(isOp);
274
- while (size > 1 && !adapter.fits(chunk())) size = Math.ceil(size / 2);
275
- let result = { ok: true };
276
- if (chunk().length > 0) result = await adapter.write(chunk()).catch((error) => {
277
- warn("flush")(error);
278
- return { ok: true };
279
- });
280
- read = !result.ok && !("retry" in result);
281
- if (result.ok) {
282
- rest = rest.slice(size);
283
- ops = ops.slice(size);
284
- failures = 0;
285
- } else {
286
- failures += 1;
287
- if (!read) await sleep(failures);
288
- }
289
- } catch (error) {
290
- warn("flush")(error);
291
- return rest;
292
- }
293
- return rest;
294
- };
295
- let buffer = /* @__PURE__ */ new Map();
296
- let timer;
297
- let flushing;
298
- const shards = /* @__PURE__ */ new Map();
299
- /** Each process writes its own shard, so flushes of two processes rarely meet. */
300
- const processShard = (model) => {
301
- if (!shards.has(model)) shards.set(model, Math.floor(Math.random() * shapeOf(model).shards));
302
- return shards.get(model);
303
- };
304
- const schedule = () => {
305
- if (timer !== void 0 || buffer.size === 0) return;
306
- timer = setTimeout(() => {
307
- timer = void 0;
308
- flushBuffer();
309
- }, windowMs);
310
- timer.unref?.();
311
- };
312
- /** Never rejects: what it cannot apply goes back into the buffer. */
313
- const flushBuffer = () => flushing ??= (async () => {
314
- clearTimeout(timer);
315
- timer = void 0;
316
- const pending = [...buffer.values()];
317
- buffer = /* @__PURE__ */ new Map();
318
- mergeAll(buffer, await apply(pending, processShard));
319
- })().catch(warn("flush")).finally(() => {
320
- flushing = void 0;
321
- schedule();
322
- });
323
251
  let nextDue = 0;
324
252
  let compacting;
325
253
  /** Log rows this process read, by `[log table's index, id]`, for the deletes after a group. */
@@ -454,7 +382,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
454
382
  more
455
383
  };
456
384
  };
457
- const rowsFor = async (changes) => (await compile(adapter, changes, () => 0)).filter(isOp);
385
+ const rowsFor = async (changes) => (await compile(adapter, changes)).filter(isOp);
458
386
  /**
459
387
  * Applies the oldest pending log rows whose merged changes fit in one
460
388
  * atomic write with the lease, which lists them as applied; the rows are
@@ -548,20 +476,6 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
548
476
  }))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
549
477
  checking = void 0;
550
478
  });
551
- /** Takes a committed transaction's changes; never rejects, since the transaction already committed. */
552
- const committed = async (changes) => {
553
- if (mode === "log") {
554
- if (now() >= nextDue) await compact(false, GROUPS.commit);
555
- return;
556
- }
557
- mergeAll(buffer, changes.values());
558
- schedule();
559
- if (buffer.size >= MAX_BUFFERED) await flushBuffer();
560
- };
561
- const flush = async () => {
562
- await flushBuffer();
563
- if (mode === "log" && await hasPending()) await compact(true, GROUPS.flush);
564
- };
565
479
  return {
566
480
  async transaction(fn) {
567
481
  let changes = /* @__PURE__ */ new Map();
@@ -587,7 +501,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
587
501
  aggregate
588
502
  });
589
503
  if (failure) throw failure.error;
590
- if (mode === "log" && attempt.size > 0) {
504
+ if (attempt.size > 0) {
591
505
  const id = `${now().toString(36).padStart(9, "0")}${holder.slice(0, 8)}${crypto.randomUUID().slice(0, 8)}`;
592
506
  const shard = Math.floor(Math.random() * LOG_TABLES.length);
593
507
  const merged = mergeAll(/* @__PURE__ */ new Map(), attempt.values());
@@ -601,24 +515,18 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
601
515
  open = false;
602
516
  }
603
517
  });
604
- if (changes.size > 0) await committed(changes);
518
+ if (changes.size > 0 && now() >= nextDue) await compact(false, GROUPS.commit);
605
519
  return result;
606
520
  },
607
521
  async beforeRead(name) {
608
522
  if (!isBatched(schema.models.get(name))) return;
609
- if (buffer.size > 0 || flushing !== void 0) await flushBuffer();
610
- if (mode === "log") {
611
- if (await hasPending().catch((error) => {
612
- warn("read")(error);
613
- return false;
614
- })) await compact(true, GROUPS.read);
615
- }
523
+ if (await hasPending().catch((error) => {
524
+ warn("read")(error);
525
+ return false;
526
+ })) await compact(true, GROUPS.read);
616
527
  },
617
- flush,
618
- async dispose() {
619
- clearTimeout(timer);
620
- timer = void 0;
621
- await flush();
528
+ async flush() {
529
+ if (await hasPending()) await compact(true, GROUPS.flush);
622
530
  }
623
531
  };
624
532
  };
@@ -35,13 +35,10 @@ const createDatabaseEngine = ({ batching, now = Date.now, meter, ...options }) =
35
35
  };
36
36
  return {
37
37
  ...engine,
38
- /** Applies batched aggregate changes still pending: this process's buffer and the log. */
38
+ /** Applies the batched aggregate changes still in the log. */
39
39
  flush: async () => {
40
40
  await batches?.flush();
41
41
  },
42
- dispose: async () => {
43
- await batches?.dispose();
44
- },
45
42
  database(module) {
46
43
  const name = (model) => module.namespace ? `${module.namespace}_${model}` : model;
47
44
  return {
@@ -35,13 +35,10 @@ const createDatabaseEngine = ({ batching, now = Date.now, meter, ...options }) =
35
35
  };
36
36
  return {
37
37
  ...engine,
38
- /** Applies batched aggregate changes still pending: this process's buffer and the log. */
38
+ /** Applies the batched aggregate changes still in the log. */
39
39
  flush: async () => {
40
40
  await batches?.flush();
41
41
  },
42
- dispose: async () => {
43
- await batches?.dispose();
44
- },
45
42
  database(module) {
46
43
  const name = (model) => module.namespace ? `${module.namespace}_${model}` : model;
47
44
  return {
package/dist/index.d.cts CHANGED
@@ -17,7 +17,7 @@ import { RetryOptions } from "./engine/database/engineTransaction.cjs";
17
17
  import { AggregateBatching, ConfiguredDatabase, EngineDatabase, RemoteDatabase, isRemoteDatabase } from "./types/databaseConfig.cjs";
18
18
  import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./types/utils.cjs";
19
19
  import { BundleRowUpdate, ReleaseCatalogRowUpdate, ReleaseRowUpdate } from "./types/databaseOperations.cjs";
20
- import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult } from "./types/models.cjs";
20
+ import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult, NativeBuildMarkResult } from "./types/models.cjs";
21
21
  import { ApplePlatform, BuildAdapter, BuildAdapterArgs, BuildAdapterConfig, Bundle, ConfigInput, FingerprintExtraSources, IosBuildDestination, Lazy, LocalSigningConfig, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NativeFingerprint, NativeFingerprintOptions, NativeFingerprintProvider, NativeFingerprintSource, Platform, PlatformConfig, SecretRef, SecretsAdapter, SecretsContext, SigningConfig, StorageAdapter, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StoragePutInput, StoragePutResult, resolveLazy, supportedIosPlatforms } from "./types/index.cjs";
22
22
  import { ReleaseCatalogMutationError, ReleaseCatalogMutationPreflight, ReleaseCatalogMutationResult, ReleaseCatalogRebuildPreflight, ReleaseCatalogRebuildResult, ReleaseCatalogScope } from "./releaseCatalogMutation.cjs";
23
23
  import { PromoteReleaseResult, ReleaseManagementError, ReleasePolicyPatch } from "./releaseManagement.cjs";
@@ -51,4 +51,4 @@ import { EngineSqlOptions, generateEngineSql } from "./engine/db/engineSql.cjs";
51
51
  import { EngineSqlMigratorOptions, createEngineSqlMigrator } from "./engine/db/engineSqlMigrator.cjs";
52
52
  import { writeSchemaSettings } from "./engine/db/schemaSettings.cjs";
53
53
  import { createSettingsMigrator } from "./engine/db/settingsMigrator.cjs";
54
- export { type AggregateBatching, type AggregateChanges, type AggregateDefinition, type AggregateIdentity, type AggregateRow, type AnyHotUpdaterPlugin, ApplePlatform, BUNDLE_STORAGE_PREFIX, type BaseCandidateQuery, type BaseCandidateTarget, BuildAdapter, BuildAdapterArgs, BuildAdapterConfig, BuiltIns, type Bundle, type BundleDeployment, type BundleDetail, type BundlePatchRow, type BundleRow, BundleRowHydrationError, BundleRowHydrationErrorReason, type BundleRowUpdate, CONTENT_ADDRESSED_ASSET_PREFIX, CatalogVersionBound, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, type ClientAuth, CompiledCatalogSegment, CompiledReleaseCatalog, ConfigInput, type ConfiguredDatabase, type ConstraintReason, type CoreReader, type CoreReads, type CoreSchema, type CreateRow, CreateStorageAdapterOptions, CreateStorageUriInput, DATABASE_VERSION_COLUMN, type DatabaseAdapter, DatabaseAdapterContractError, DatabaseAdapterInputError, type DatabaseAdapterInputErrorCode, DatabaseAmbiguousCommitError, type DatabaseBundleMetadata, DatabaseBundleNotFoundError, DatabaseConflictError, DatabaseConstraintError, DatabaseCursorError, type DatabaseJson, type DatabaseJsonObject, type DatabaseJsonValue, type DatabaseKey, type DatabaseKeyValue, DatabaseQueryError, type DatabaseReadCount, type DatabaseReadMeter, DatabaseRowReferencedError, DatabaseSchemaError, type DatabaseTooling, DatabaseTransactionError, type DatabaseValue, type DeployReleasePolicy, type Deployment, type DerivedDefinition, type DerivedFields, type Engine, type EngineColumns, type EngineDatabase, type EngineDatabaseOptions, type EngineOptions, type EngineReadCount, type EngineSqlMigratorOptions, type EngineSqlOptions, type FieldDefinition, type FieldReference, type FieldType, type FieldValue, type FindAggregatesModel, type FindManyModel, FingerprintExtraSources, HasMultipleCallSignatures, HotUpdaterConfigError, type HotUpdaterCoreApi, type HotUpdaterDatabase, type HotUpdaterPlugin, HotUpdaterSchemaMigrationRequiredError, type HotUpdaterTransaction, type IndexDefinition, IosBuildDestination, type KeyLookup, type KeyValueStore, type KeysetInput, type KvAdapterOptions, type KvCondition, type KvItem, type KvKey, type KvOp, type KvRange, Lazy, LocalSigningConfig, type Lookup, type MemoryAdapterOptions, type MeteredDatabase, type MigrateOptions, type MigrationResult, type Migrator, type ModelDefinition, type ModuleSchema, NativeBuildAndroidScheme, NativeBuildArgs, type NativeBuildArtifactKind, type NativeBuildDeleteResult, NativeBuildIosScheme, NativeBuildOptions, type NativeBuildRegistration, type NativeBuildRow, type NativeBuildScope, type NativeBuildSubmissionDestination, NativeFingerprint, NativeFingerprintOptions, NativeFingerprintProvider, NativeFingerprintSource, type NormalizeOptions, type Page, ParsedStorageUri, type PhysicalColumn, type PhysicalColumnType, type PhysicalIndex, type PhysicalRetention, type PhysicalTable, type Platform, PlatformConfig, type PluginApis, type PluginCli, type PluginClientCredential, type PluginClientPlugin, type PluginContext, type PluginEndpoint, type PluginEndpointMethod, type PluginInstance, type PluginProvides, type PluginTables, Primitive, PromoteReleaseResult, type QueryBound, type QueryRequest, type ReadMeasurement, type ReadOptions, type ReadRow, type ReferenceAction, ReleaseCatalogCompilation, ReleaseCatalogCompilationError, ReleaseCatalogCompilerDiagnostics, ReleaseCatalogMutationError, ReleaseCatalogMutationPreflight, ReleaseCatalogMutationResult, ReleaseCatalogRebuildPreflight, ReleaseCatalogRebuildResult, type ReleaseCatalogRequest, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, ReleaseCatalogScope, type ReleaseFilter, ReleaseManagementError, ReleasePolicyPatch, type ReleaseRow, type ReleaseRowUpdate, type ReleaseTarget, type RemoteDatabase, RequiredDeep, type ResolvedModel, type ResolvedSchema, type RetentionDefinition, type RetryOptions, type RowOf, SETTINGS_TABLE, type SchemaGenerator, type SchemaSettings, SecretRef, SecretsAdapter, SecretsContext, SigningConfig, type SqlAdapterOptions, type SqlColumnShape, type SqlConnection, type SqlDialect, type SqlExecutor, type SqlResult, type SqlStatement, type SqlTableShape, StorageAdapter, StorageAdapterWith, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StorageOperation, StoragePutInput, StoragePutResult, type StoredBundleDeployment, type StoredRow, type TableDefinition, type TableRow, type ToolingDatabase, type ToolingTarget, type UpdateSet, type VerifiedDatabaseAdapter, type VerifyAdapterOptions, WRITE_GUARD_TABLE, type WriteGuard, type WriteOp, type WriteResult, addDistinct, aggregateBatchingTables, assertStorageOperations, bundleToPatchRows, bundleToRow, canonicalizeAppVersion, compareUtf8, compileReleaseCatalog, coreSchema, coreSettings, coreTarget, countDistinct, createBundleStorageKey, createEngine, createEngineDatabase, createEngineSqlMigrator, createKvAdapter, createMemoryAdapter, createSettingsMigrator, createSqlAdapter, createStorageAdapter, createStorageKeyBuilder, createStorageRootUriWithPath, createStorageUri, createStorageUriWithRelativePath, createTableStatements, createUUIDv7, createUUIDv7After, createUUIDv7WithSameTimestamp, defineAggregate, definePlugin, defineTable, encodeKvKey, expiresAt, extractTimestampFromUUIDv7, findPhysicalColumn, findPhysicalIndex, generateEngineSql, generateMinBundleId, getBundleArchiveStorageUri, getContentAddressedAssetStoragePath, getContentType, getManifestAssetDownloadPath, getManifestAssetStoragePath, indexOrderColumns, isBrotliManifestAssetPath, isContentAddressedAssetFileHash, isDatabaseBusyError, isDatabaseJsonObject, isDatabaseMetadataObject, isMultiIndex, isRemoteDatabase, isUUIDv7, mergeDistinct, meterReads, migrateCoreSchema, normalizeStoredRow, parseBaseCandidateKey, parseStorageUri, projectCompiledCatalog, projectCompiledRollbackCatalog, quoteSql, referenceCompatibleReleases, releaseRowToRelease, releaseToRow, replaceStorageUriKeySuffix, resolveLazy, resolveManifestAssetStorageFileHash, resolveManifestAssetStorageUri, rowKey, rowToBundle, rowsToBundles, semverSatisfies, sqlTableShapes, supportedIosPlatforms, targetBaseCandidateKey, toolingTargetOf, verifyAdapter, writeSchemaSettings };
54
+ export { type AggregateBatching, type AggregateChanges, type AggregateDefinition, type AggregateIdentity, type AggregateRow, type AnyHotUpdaterPlugin, ApplePlatform, BUNDLE_STORAGE_PREFIX, type BaseCandidateQuery, type BaseCandidateTarget, BuildAdapter, BuildAdapterArgs, BuildAdapterConfig, BuiltIns, type Bundle, type BundleDeployment, type BundleDetail, type BundlePatchRow, type BundleRow, BundleRowHydrationError, BundleRowHydrationErrorReason, type BundleRowUpdate, CONTENT_ADDRESSED_ASSET_PREFIX, CatalogVersionBound, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, type ClientAuth, CompiledCatalogSegment, CompiledReleaseCatalog, ConfigInput, type ConfiguredDatabase, type ConstraintReason, type CoreReader, type CoreReads, type CoreSchema, type CreateRow, CreateStorageAdapterOptions, CreateStorageUriInput, DATABASE_VERSION_COLUMN, type DatabaseAdapter, DatabaseAdapterContractError, DatabaseAdapterInputError, type DatabaseAdapterInputErrorCode, DatabaseAmbiguousCommitError, type DatabaseBundleMetadata, DatabaseBundleNotFoundError, DatabaseConflictError, DatabaseConstraintError, DatabaseCursorError, type DatabaseJson, type DatabaseJsonObject, type DatabaseJsonValue, type DatabaseKey, type DatabaseKeyValue, DatabaseQueryError, type DatabaseReadCount, type DatabaseReadMeter, DatabaseRowReferencedError, DatabaseSchemaError, type DatabaseTooling, DatabaseTransactionError, type DatabaseValue, type DeployReleasePolicy, type Deployment, type DerivedDefinition, type DerivedFields, type Engine, type EngineColumns, type EngineDatabase, type EngineDatabaseOptions, type EngineOptions, type EngineReadCount, type EngineSqlMigratorOptions, type EngineSqlOptions, type FieldDefinition, type FieldReference, type FieldType, type FieldValue, type FindAggregatesModel, type FindManyModel, FingerprintExtraSources, HasMultipleCallSignatures, HotUpdaterConfigError, type HotUpdaterCoreApi, type HotUpdaterDatabase, type HotUpdaterPlugin, HotUpdaterSchemaMigrationRequiredError, type HotUpdaterTransaction, type IndexDefinition, IosBuildDestination, type KeyLookup, type KeyValueStore, type KeysetInput, type KvAdapterOptions, type KvCondition, type KvItem, type KvKey, type KvOp, type KvRange, Lazy, LocalSigningConfig, type Lookup, type MemoryAdapterOptions, type MeteredDatabase, type MigrateOptions, type MigrationResult, type Migrator, type ModelDefinition, type ModuleSchema, NativeBuildAndroidScheme, NativeBuildArgs, type NativeBuildArtifactKind, type NativeBuildDeleteResult, NativeBuildIosScheme, type NativeBuildMarkResult, NativeBuildOptions, type NativeBuildRegistration, type NativeBuildRow, type NativeBuildScope, type NativeBuildSubmissionDestination, NativeFingerprint, NativeFingerprintOptions, NativeFingerprintProvider, NativeFingerprintSource, type NormalizeOptions, type Page, ParsedStorageUri, type PhysicalColumn, type PhysicalColumnType, type PhysicalIndex, type PhysicalRetention, type PhysicalTable, type Platform, PlatformConfig, type PluginApis, type PluginCli, type PluginClientCredential, type PluginClientPlugin, type PluginContext, type PluginEndpoint, type PluginEndpointMethod, type PluginInstance, type PluginProvides, type PluginTables, Primitive, PromoteReleaseResult, type QueryBound, type QueryRequest, type ReadMeasurement, type ReadOptions, type ReadRow, type ReferenceAction, ReleaseCatalogCompilation, ReleaseCatalogCompilationError, ReleaseCatalogCompilerDiagnostics, ReleaseCatalogMutationError, ReleaseCatalogMutationPreflight, ReleaseCatalogMutationResult, ReleaseCatalogRebuildPreflight, ReleaseCatalogRebuildResult, type ReleaseCatalogRequest, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, ReleaseCatalogScope, type ReleaseFilter, ReleaseManagementError, ReleasePolicyPatch, type ReleaseRow, type ReleaseRowUpdate, type ReleaseTarget, type RemoteDatabase, RequiredDeep, type ResolvedModel, type ResolvedSchema, type RetentionDefinition, type RetryOptions, type RowOf, SETTINGS_TABLE, type SchemaGenerator, type SchemaSettings, SecretRef, SecretsAdapter, SecretsContext, SigningConfig, type SqlAdapterOptions, type SqlColumnShape, type SqlConnection, type SqlDialect, type SqlExecutor, type SqlResult, type SqlStatement, type SqlTableShape, StorageAdapter, StorageAdapterWith, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StorageOperation, StoragePutInput, StoragePutResult, type StoredBundleDeployment, type StoredRow, type TableDefinition, type TableRow, type ToolingDatabase, type ToolingTarget, type UpdateSet, type VerifiedDatabaseAdapter, type VerifyAdapterOptions, WRITE_GUARD_TABLE, type WriteGuard, type WriteOp, type WriteResult, addDistinct, aggregateBatchingTables, assertStorageOperations, bundleToPatchRows, bundleToRow, canonicalizeAppVersion, compareUtf8, compileReleaseCatalog, coreSchema, coreSettings, coreTarget, countDistinct, createBundleStorageKey, createEngine, createEngineDatabase, createEngineSqlMigrator, createKvAdapter, createMemoryAdapter, createSettingsMigrator, createSqlAdapter, createStorageAdapter, createStorageKeyBuilder, createStorageRootUriWithPath, createStorageUri, createStorageUriWithRelativePath, createTableStatements, createUUIDv7, createUUIDv7After, createUUIDv7WithSameTimestamp, defineAggregate, definePlugin, defineTable, encodeKvKey, expiresAt, extractTimestampFromUUIDv7, findPhysicalColumn, findPhysicalIndex, generateEngineSql, generateMinBundleId, getBundleArchiveStorageUri, getContentAddressedAssetStoragePath, getContentType, getManifestAssetDownloadPath, getManifestAssetStoragePath, indexOrderColumns, isBrotliManifestAssetPath, isContentAddressedAssetFileHash, isDatabaseBusyError, isDatabaseJsonObject, isDatabaseMetadataObject, isMultiIndex, isRemoteDatabase, isUUIDv7, mergeDistinct, meterReads, migrateCoreSchema, normalizeStoredRow, parseBaseCandidateKey, parseStorageUri, projectCompiledCatalog, projectCompiledRollbackCatalog, quoteSql, referenceCompatibleReleases, releaseRowToRelease, releaseToRow, replaceStorageUriKeySuffix, resolveLazy, resolveManifestAssetStorageFileHash, resolveManifestAssetStorageUri, rowKey, rowToBundle, rowsToBundles, semverSatisfies, sqlTableShapes, supportedIosPlatforms, targetBaseCandidateKey, toolingTargetOf, verifyAdapter, writeSchemaSettings };
package/dist/index.d.mts CHANGED
@@ -17,7 +17,7 @@ import { RetryOptions } from "./engine/database/engineTransaction.mjs";
17
17
  import { AggregateBatching, ConfiguredDatabase, EngineDatabase, RemoteDatabase, isRemoteDatabase } from "./types/databaseConfig.mjs";
18
18
  import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./types/utils.mjs";
19
19
  import { BundleRowUpdate, ReleaseCatalogRowUpdate, ReleaseRowUpdate } from "./types/databaseOperations.mjs";
20
- import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult } from "./types/models.mjs";
20
+ import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult, NativeBuildMarkResult } from "./types/models.mjs";
21
21
  import { ApplePlatform, BuildAdapter, BuildAdapterArgs, BuildAdapterConfig, Bundle, ConfigInput, FingerprintExtraSources, IosBuildDestination, Lazy, LocalSigningConfig, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NativeFingerprint, NativeFingerprintOptions, NativeFingerprintProvider, NativeFingerprintSource, Platform, PlatformConfig, SecretRef, SecretsAdapter, SecretsContext, SigningConfig, StorageAdapter, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StoragePutInput, StoragePutResult, resolveLazy, supportedIosPlatforms } from "./types/index.mjs";
22
22
  import { ReleaseCatalogMutationError, ReleaseCatalogMutationPreflight, ReleaseCatalogMutationResult, ReleaseCatalogRebuildPreflight, ReleaseCatalogRebuildResult, ReleaseCatalogScope } from "./releaseCatalogMutation.mjs";
23
23
  import { PromoteReleaseResult, ReleaseManagementError, ReleasePolicyPatch } from "./releaseManagement.mjs";
@@ -51,4 +51,4 @@ import { EngineSqlOptions, generateEngineSql } from "./engine/db/engineSql.mjs";
51
51
  import { EngineSqlMigratorOptions, createEngineSqlMigrator } from "./engine/db/engineSqlMigrator.mjs";
52
52
  import { writeSchemaSettings } from "./engine/db/schemaSettings.mjs";
53
53
  import { createSettingsMigrator } from "./engine/db/settingsMigrator.mjs";
54
- export { type AggregateBatching, type AggregateChanges, type AggregateDefinition, type AggregateIdentity, type AggregateRow, type AnyHotUpdaterPlugin, ApplePlatform, BUNDLE_STORAGE_PREFIX, type BaseCandidateQuery, type BaseCandidateTarget, BuildAdapter, BuildAdapterArgs, BuildAdapterConfig, BuiltIns, type Bundle, type BundleDeployment, type BundleDetail, type BundlePatchRow, type BundleRow, BundleRowHydrationError, BundleRowHydrationErrorReason, type BundleRowUpdate, CONTENT_ADDRESSED_ASSET_PREFIX, CatalogVersionBound, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, type ClientAuth, CompiledCatalogSegment, CompiledReleaseCatalog, ConfigInput, type ConfiguredDatabase, type ConstraintReason, type CoreReader, type CoreReads, type CoreSchema, type CreateRow, CreateStorageAdapterOptions, CreateStorageUriInput, DATABASE_VERSION_COLUMN, type DatabaseAdapter, DatabaseAdapterContractError, DatabaseAdapterInputError, type DatabaseAdapterInputErrorCode, DatabaseAmbiguousCommitError, type DatabaseBundleMetadata, DatabaseBundleNotFoundError, DatabaseConflictError, DatabaseConstraintError, DatabaseCursorError, type DatabaseJson, type DatabaseJsonObject, type DatabaseJsonValue, type DatabaseKey, type DatabaseKeyValue, DatabaseQueryError, type DatabaseReadCount, type DatabaseReadMeter, DatabaseRowReferencedError, DatabaseSchemaError, type DatabaseTooling, DatabaseTransactionError, type DatabaseValue, type DeployReleasePolicy, type Deployment, type DerivedDefinition, type DerivedFields, type Engine, type EngineColumns, type EngineDatabase, type EngineDatabaseOptions, type EngineOptions, type EngineReadCount, type EngineSqlMigratorOptions, type EngineSqlOptions, type FieldDefinition, type FieldReference, type FieldType, type FieldValue, type FindAggregatesModel, type FindManyModel, FingerprintExtraSources, HasMultipleCallSignatures, HotUpdaterConfigError, type HotUpdaterCoreApi, type HotUpdaterDatabase, type HotUpdaterPlugin, HotUpdaterSchemaMigrationRequiredError, type HotUpdaterTransaction, type IndexDefinition, IosBuildDestination, type KeyLookup, type KeyValueStore, type KeysetInput, type KvAdapterOptions, type KvCondition, type KvItem, type KvKey, type KvOp, type KvRange, Lazy, LocalSigningConfig, type Lookup, type MemoryAdapterOptions, type MeteredDatabase, type MigrateOptions, type MigrationResult, type Migrator, type ModelDefinition, type ModuleSchema, NativeBuildAndroidScheme, NativeBuildArgs, type NativeBuildArtifactKind, type NativeBuildDeleteResult, NativeBuildIosScheme, NativeBuildOptions, type NativeBuildRegistration, type NativeBuildRow, type NativeBuildScope, type NativeBuildSubmissionDestination, NativeFingerprint, NativeFingerprintOptions, NativeFingerprintProvider, NativeFingerprintSource, type NormalizeOptions, type Page, ParsedStorageUri, type PhysicalColumn, type PhysicalColumnType, type PhysicalIndex, type PhysicalRetention, type PhysicalTable, type Platform, PlatformConfig, type PluginApis, type PluginCli, type PluginClientCredential, type PluginClientPlugin, type PluginContext, type PluginEndpoint, type PluginEndpointMethod, type PluginInstance, type PluginProvides, type PluginTables, Primitive, PromoteReleaseResult, type QueryBound, type QueryRequest, type ReadMeasurement, type ReadOptions, type ReadRow, type ReferenceAction, ReleaseCatalogCompilation, ReleaseCatalogCompilationError, ReleaseCatalogCompilerDiagnostics, ReleaseCatalogMutationError, ReleaseCatalogMutationPreflight, ReleaseCatalogMutationResult, ReleaseCatalogRebuildPreflight, ReleaseCatalogRebuildResult, type ReleaseCatalogRequest, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, ReleaseCatalogScope, type ReleaseFilter, ReleaseManagementError, ReleasePolicyPatch, type ReleaseRow, type ReleaseRowUpdate, type ReleaseTarget, type RemoteDatabase, RequiredDeep, type ResolvedModel, type ResolvedSchema, type RetentionDefinition, type RetryOptions, type RowOf, SETTINGS_TABLE, type SchemaGenerator, type SchemaSettings, SecretRef, SecretsAdapter, SecretsContext, SigningConfig, type SqlAdapterOptions, type SqlColumnShape, type SqlConnection, type SqlDialect, type SqlExecutor, type SqlResult, type SqlStatement, type SqlTableShape, StorageAdapter, StorageAdapterWith, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StorageOperation, StoragePutInput, StoragePutResult, type StoredBundleDeployment, type StoredRow, type TableDefinition, type TableRow, type ToolingDatabase, type ToolingTarget, type UpdateSet, type VerifiedDatabaseAdapter, type VerifyAdapterOptions, WRITE_GUARD_TABLE, type WriteGuard, type WriteOp, type WriteResult, addDistinct, aggregateBatchingTables, assertStorageOperations, bundleToPatchRows, bundleToRow, canonicalizeAppVersion, compareUtf8, compileReleaseCatalog, coreSchema, coreSettings, coreTarget, countDistinct, createBundleStorageKey, createEngine, createEngineDatabase, createEngineSqlMigrator, createKvAdapter, createMemoryAdapter, createSettingsMigrator, createSqlAdapter, createStorageAdapter, createStorageKeyBuilder, createStorageRootUriWithPath, createStorageUri, createStorageUriWithRelativePath, createTableStatements, createUUIDv7, createUUIDv7After, createUUIDv7WithSameTimestamp, defineAggregate, definePlugin, defineTable, encodeKvKey, expiresAt, extractTimestampFromUUIDv7, findPhysicalColumn, findPhysicalIndex, generateEngineSql, generateMinBundleId, getBundleArchiveStorageUri, getContentAddressedAssetStoragePath, getContentType, getManifestAssetDownloadPath, getManifestAssetStoragePath, indexOrderColumns, isBrotliManifestAssetPath, isContentAddressedAssetFileHash, isDatabaseBusyError, isDatabaseJsonObject, isDatabaseMetadataObject, isMultiIndex, isRemoteDatabase, isUUIDv7, mergeDistinct, meterReads, migrateCoreSchema, normalizeStoredRow, parseBaseCandidateKey, parseStorageUri, projectCompiledCatalog, projectCompiledRollbackCatalog, quoteSql, referenceCompatibleReleases, releaseRowToRelease, releaseToRow, replaceStorageUriKeySuffix, resolveLazy, resolveManifestAssetStorageFileHash, resolveManifestAssetStorageUri, rowKey, rowToBundle, rowsToBundles, semverSatisfies, sqlTableShapes, supportedIosPlatforms, targetBaseCandidateKey, toolingTargetOf, verifyAdapter, writeSchemaSettings };
54
+ export { type AggregateBatching, type AggregateChanges, type AggregateDefinition, type AggregateIdentity, type AggregateRow, type AnyHotUpdaterPlugin, ApplePlatform, BUNDLE_STORAGE_PREFIX, type BaseCandidateQuery, type BaseCandidateTarget, BuildAdapter, BuildAdapterArgs, BuildAdapterConfig, BuiltIns, type Bundle, type BundleDeployment, type BundleDetail, type BundlePatchRow, type BundleRow, BundleRowHydrationError, BundleRowHydrationErrorReason, type BundleRowUpdate, CONTENT_ADDRESSED_ASSET_PREFIX, CatalogVersionBound, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, type ClientAuth, CompiledCatalogSegment, CompiledReleaseCatalog, ConfigInput, type ConfiguredDatabase, type ConstraintReason, type CoreReader, type CoreReads, type CoreSchema, type CreateRow, CreateStorageAdapterOptions, CreateStorageUriInput, DATABASE_VERSION_COLUMN, type DatabaseAdapter, DatabaseAdapterContractError, DatabaseAdapterInputError, type DatabaseAdapterInputErrorCode, DatabaseAmbiguousCommitError, type DatabaseBundleMetadata, DatabaseBundleNotFoundError, DatabaseConflictError, DatabaseConstraintError, DatabaseCursorError, type DatabaseJson, type DatabaseJsonObject, type DatabaseJsonValue, type DatabaseKey, type DatabaseKeyValue, DatabaseQueryError, type DatabaseReadCount, type DatabaseReadMeter, DatabaseRowReferencedError, DatabaseSchemaError, type DatabaseTooling, DatabaseTransactionError, type DatabaseValue, type DeployReleasePolicy, type Deployment, type DerivedDefinition, type DerivedFields, type Engine, type EngineColumns, type EngineDatabase, type EngineDatabaseOptions, type EngineOptions, type EngineReadCount, type EngineSqlMigratorOptions, type EngineSqlOptions, type FieldDefinition, type FieldReference, type FieldType, type FieldValue, type FindAggregatesModel, type FindManyModel, FingerprintExtraSources, HasMultipleCallSignatures, HotUpdaterConfigError, type HotUpdaterCoreApi, type HotUpdaterDatabase, type HotUpdaterPlugin, HotUpdaterSchemaMigrationRequiredError, type HotUpdaterTransaction, type IndexDefinition, IosBuildDestination, type KeyLookup, type KeyValueStore, type KeysetInput, type KvAdapterOptions, type KvCondition, type KvItem, type KvKey, type KvOp, type KvRange, Lazy, LocalSigningConfig, type Lookup, type MemoryAdapterOptions, type MeteredDatabase, type MigrateOptions, type MigrationResult, type Migrator, type ModelDefinition, type ModuleSchema, NativeBuildAndroidScheme, NativeBuildArgs, type NativeBuildArtifactKind, type NativeBuildDeleteResult, NativeBuildIosScheme, type NativeBuildMarkResult, NativeBuildOptions, type NativeBuildRegistration, type NativeBuildRow, type NativeBuildScope, type NativeBuildSubmissionDestination, NativeFingerprint, NativeFingerprintOptions, NativeFingerprintProvider, NativeFingerprintSource, type NormalizeOptions, type Page, ParsedStorageUri, type PhysicalColumn, type PhysicalColumnType, type PhysicalIndex, type PhysicalRetention, type PhysicalTable, type Platform, PlatformConfig, type PluginApis, type PluginCli, type PluginClientCredential, type PluginClientPlugin, type PluginContext, type PluginEndpoint, type PluginEndpointMethod, type PluginInstance, type PluginProvides, type PluginTables, Primitive, PromoteReleaseResult, type QueryBound, type QueryRequest, type ReadMeasurement, type ReadOptions, type ReadRow, type ReferenceAction, ReleaseCatalogCompilation, ReleaseCatalogCompilationError, ReleaseCatalogCompilerDiagnostics, ReleaseCatalogMutationError, ReleaseCatalogMutationPreflight, ReleaseCatalogMutationResult, ReleaseCatalogRebuildPreflight, ReleaseCatalogRebuildResult, type ReleaseCatalogRequest, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, ReleaseCatalogScope, type ReleaseFilter, ReleaseManagementError, ReleasePolicyPatch, type ReleaseRow, type ReleaseRowUpdate, type ReleaseTarget, type RemoteDatabase, RequiredDeep, type ResolvedModel, type ResolvedSchema, type RetentionDefinition, type RetryOptions, type RowOf, SETTINGS_TABLE, type SchemaGenerator, type SchemaSettings, SecretRef, SecretsAdapter, SecretsContext, SigningConfig, type SqlAdapterOptions, type SqlColumnShape, type SqlConnection, type SqlDialect, type SqlExecutor, type SqlResult, type SqlStatement, type SqlTableShape, StorageAdapter, StorageAdapterWith, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StorageOperation, StoragePutInput, StoragePutResult, type StoredBundleDeployment, type StoredRow, type TableDefinition, type TableRow, type ToolingDatabase, type ToolingTarget, type UpdateSet, type VerifiedDatabaseAdapter, type VerifyAdapterOptions, WRITE_GUARD_TABLE, type WriteGuard, type WriteOp, type WriteResult, addDistinct, aggregateBatchingTables, assertStorageOperations, bundleToPatchRows, bundleToRow, canonicalizeAppVersion, compareUtf8, compileReleaseCatalog, coreSchema, coreSettings, coreTarget, countDistinct, createBundleStorageKey, createEngine, createEngineDatabase, createEngineSqlMigrator, createKvAdapter, createMemoryAdapter, createSettingsMigrator, createSqlAdapter, createStorageAdapter, createStorageKeyBuilder, createStorageRootUriWithPath, createStorageUri, createStorageUriWithRelativePath, createTableStatements, createUUIDv7, createUUIDv7After, createUUIDv7WithSameTimestamp, defineAggregate, definePlugin, defineTable, encodeKvKey, expiresAt, extractTimestampFromUUIDv7, findPhysicalColumn, findPhysicalIndex, generateEngineSql, generateMinBundleId, getBundleArchiveStorageUri, getContentAddressedAssetStoragePath, getContentType, getManifestAssetDownloadPath, getManifestAssetStoragePath, indexOrderColumns, isBrotliManifestAssetPath, isContentAddressedAssetFileHash, isDatabaseBusyError, isDatabaseJsonObject, isDatabaseMetadataObject, isMultiIndex, isRemoteDatabase, isUUIDv7, mergeDistinct, meterReads, migrateCoreSchema, normalizeStoredRow, parseBaseCandidateKey, parseStorageUri, projectCompiledCatalog, projectCompiledRollbackCatalog, quoteSql, referenceCompatibleReleases, releaseRowToRelease, releaseToRow, replaceStorageUriKeySuffix, resolveLazy, resolveManifestAssetStorageFileHash, resolveManifestAssetStorageUri, rowKey, rowToBundle, rowsToBundles, semverSatisfies, sqlTableShapes, supportedIosPlatforms, targetBaseCandidateKey, toolingTargetOf, verifyAdapter, writeSchemaSettings };
@@ -3,28 +3,17 @@ import { RetryOptions } from "../engine/database/engineTransaction.cjs";
3
3
  import { HotUpdaterCoreApi } from "../coreApi.cjs";
4
4
  //#region src/types/databaseConfig.d.ts
5
5
  /**
6
- * How changes to aggregates declared `batched` reach their rows: after the
7
- * transaction that made them commits, merged with other transactions'
8
- * changes into one write per aggregate row. Databases that bill each write
9
- * (DynamoDB, Firestore) batch them.
6
+ * How changes to aggregates declared `batched` reach their rows: each
7
+ * transaction writes its changes as one log row, and a compaction merges
8
+ * pending log rows into one write per aggregate row. Databases that bill each
9
+ * write (DynamoDB, Firestore, Cosmos DB) batch them.
10
10
  */
11
11
  interface AggregateBatching {
12
12
  /**
13
- * `"log"` (the default) writes each transaction's changes as one log row
14
- * in that transaction, and a compaction merges pending log rows into the
15
- * aggregates. It loses nothing and suits every runtime. `"memory"` keeps
16
- * changes in the process until a timer flushes them. It writes no log
17
- * rows, but a crash loses up to one window, and a runtime that freezes
18
- * or drops the process between requests (Lambda, Cloud Functions,
19
- * Workers) loses more, so use it only on a long-lived server.
20
- */
21
- readonly mode?: "log" | "memory";
22
- /**
23
- * How long changes wait before a compaction or a flush: `"log"` compacts
24
- * after a commit once this has passed since the last compaction, 60
25
- * seconds by default, and `"memory"` flushes this often, 15 seconds by
26
- * default. A read that cannot compact (read-only credentials) shows
27
- * aggregates that can leave out up to one window of the latest changes.
13
+ * A commit compacts once this has passed since the last compaction, 60
14
+ * seconds by default. A read compacts first; one that cannot (read-only
15
+ * credentials) shows aggregates that can leave out up to one window of the
16
+ * latest changes.
28
17
  */
29
18
  readonly windowMs?: number;
30
19
  }
@@ -3,28 +3,17 @@ import { RetryOptions } from "../engine/database/engineTransaction.mjs";
3
3
  import { HotUpdaterCoreApi } from "../coreApi.mjs";
4
4
  //#region src/types/databaseConfig.d.ts
5
5
  /**
6
- * How changes to aggregates declared `batched` reach their rows: after the
7
- * transaction that made them commits, merged with other transactions'
8
- * changes into one write per aggregate row. Databases that bill each write
9
- * (DynamoDB, Firestore) batch them.
6
+ * How changes to aggregates declared `batched` reach their rows: each
7
+ * transaction writes its changes as one log row, and a compaction merges
8
+ * pending log rows into one write per aggregate row. Databases that bill each
9
+ * write (DynamoDB, Firestore, Cosmos DB) batch them.
10
10
  */
11
11
  interface AggregateBatching {
12
12
  /**
13
- * `"log"` (the default) writes each transaction's changes as one log row
14
- * in that transaction, and a compaction merges pending log rows into the
15
- * aggregates. It loses nothing and suits every runtime. `"memory"` keeps
16
- * changes in the process until a timer flushes them. It writes no log
17
- * rows, but a crash loses up to one window, and a runtime that freezes
18
- * or drops the process between requests (Lambda, Cloud Functions,
19
- * Workers) loses more, so use it only on a long-lived server.
20
- */
21
- readonly mode?: "log" | "memory";
22
- /**
23
- * How long changes wait before a compaction or a flush: `"log"` compacts
24
- * after a commit once this has passed since the last compaction, 60
25
- * seconds by default, and `"memory"` flushes this often, 15 seconds by
26
- * default. A read that cannot compact (read-only credentials) shows
27
- * aggregates that can leave out up to one window of the latest changes.
13
+ * A commit compacts once this has passed since the last compaction, 60
14
+ * seconds by default. A read compacts first; one that cannot (read-only
15
+ * credentials) shows aggregates that can leave out up to one window of the
16
+ * latest changes.
28
17
  */
29
18
  readonly windowMs?: number;
30
19
  }
@@ -105,6 +105,11 @@ interface NativeBuildRow {
105
105
  * by the build number, and a fingerprint build records no app version.
106
106
  */
107
107
  readonly submitted_version: string | null;
108
+ /**
109
+ * True on the build marked as what the store sells, which deploys patch from
110
+ * over the scope's newest build; null on every other. A scope has one.
111
+ */
112
+ readonly store_build: true | null;
108
113
  }
109
114
  //#endregion
110
115
  export { BundlePatchRow, BundleRow, ChannelRow, DatabaseBundleMetadata, DatabaseJsonObject, DatabaseJsonValue, NativeBuildArtifactKind, NativeBuildRow, NativeBuildSubmissionDestination, ReleaseCatalogRow, ReleaseRow };
@@ -105,6 +105,11 @@ interface NativeBuildRow {
105
105
  * by the build number, and a fingerprint build records no app version.
106
106
  */
107
107
  readonly submitted_version: string | null;
108
+ /**
109
+ * True on the build marked as what the store sells, which deploys patch from
110
+ * over the scope's newest build; null on every other. A scope has one.
111
+ */
112
+ readonly store_build: true | null;
108
113
  }
109
114
  //#endregion
110
115
  export { BundlePatchRow, BundleRow, ChannelRow, DatabaseBundleMetadata, DatabaseJsonObject, DatabaseJsonValue, NativeBuildArtifactKind, NativeBuildRow, NativeBuildSubmissionDestination, ReleaseCatalogRow, ReleaseRow };
@@ -3,7 +3,7 @@ import { AnyHotUpdaterPlugin } from "../serverPlugin/definePlugin.cjs";
3
3
  import { AggregateBatching, ConfiguredDatabase, EngineDatabase, RemoteDatabase, isRemoteDatabase } from "./databaseConfig.cjs";
4
4
  import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./utils.cjs";
5
5
  import { BundleRowUpdate, ReleaseCatalogRowUpdate, ReleaseRowUpdate } from "./databaseOperations.cjs";
6
- import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult } from "./models.cjs";
6
+ import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult, NativeBuildMarkResult } from "./models.cjs";
7
7
  import "./public.cjs";
8
8
  import { Bundle as Bundle$1, Platform, Platform as Platform$1 } from "@hot-updater/protocol";
9
9
  //#region src/types/index.d.ts
@@ -181,6 +181,15 @@ interface NativeBuildAndroidScheme {
181
181
  signing?: {
182
182
  keystore: SecretRef;
183
183
  };
184
+ /**
185
+ * Builds the app with the sandbox native layer, for testing OTA bundles on
186
+ * a device, as a separate app: the application ID gets a `.sandbox` suffix.
187
+ * It registers on the reserved channel `sandbox-<scheme>`, and reaches
188
+ * Google Play's internal testing only. No other build compiles the layer.
189
+ *
190
+ * @default false
191
+ */
192
+ sandbox?: boolean;
184
193
  }
185
194
  type IosBuildDestination = {
186
195
  id: string;
@@ -279,6 +288,18 @@ interface NativeBuildIosScheme {
279
288
  signing?: {
280
289
  ascApiKey: SecretRef;
281
290
  };
291
+ /**
292
+ * Builds the app with the sandbox native layer, for testing OTA bundles on
293
+ * a device. It has the bundle identifier its Xcode configuration builds,
294
+ * which `bundleIdentifier` must name: the store app's by default, which it
295
+ * replaces on a device, or its own from a separate configuration. It
296
+ * registers on the reserved channel `sandbox-<scheme>`, and its `.ipa` is for
297
+ * TestFlight internal testing only, never App Store review. No other build
298
+ * compiles the layer.
299
+ *
300
+ * @default false
301
+ */
302
+ sandbox?: boolean;
282
303
  }
283
304
  interface PlatformConfig {
284
305
  /**
@@ -601,4 +622,4 @@ interface NativeBuildOptions {
601
622
  scheme?: string;
602
623
  }
603
624
  //#endregion
604
- export { type AggregateBatching, ApplePlatform, BuildAdapter, BuildAdapterArgs, BuildAdapterConfig, BuiltIns, type Bundle$1 as Bundle, type BundlePatchRow, type BundleRow, type BundleRowUpdate, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, ConfigInput, type ConfiguredDatabase, type DatabaseBundleMetadata, type DatabaseJsonObject, type DatabaseJsonValue, type EngineDatabase, FingerprintExtraSources, HasMultipleCallSignatures, IosBuildDestination, Lazy, LocalSigningConfig, NativeBuildAndroidScheme, NativeBuildArgs, type NativeBuildArtifactKind, type NativeBuildDeleteResult, NativeBuildIosScheme, NativeBuildOptions, type NativeBuildRow, type NativeBuildSubmissionDestination, NativeFingerprint, NativeFingerprintOptions, NativeFingerprintProvider, NativeFingerprintSource, type Platform$1 as Platform, PlatformConfig, Primitive, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, type ReleaseRow, type ReleaseRowUpdate, type RemoteDatabase, RequiredDeep, SecretRef, SecretsAdapter, SecretsContext, SigningConfig, StorageAdapter, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StoragePutInput, StoragePutResult, isRemoteDatabase, resolveLazy, supportedIosPlatforms };
625
+ export { type AggregateBatching, ApplePlatform, BuildAdapter, BuildAdapterArgs, BuildAdapterConfig, BuiltIns, type Bundle$1 as Bundle, type BundlePatchRow, type BundleRow, type BundleRowUpdate, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, ConfigInput, type ConfiguredDatabase, type DatabaseBundleMetadata, type DatabaseJsonObject, type DatabaseJsonValue, type EngineDatabase, FingerprintExtraSources, HasMultipleCallSignatures, IosBuildDestination, Lazy, LocalSigningConfig, NativeBuildAndroidScheme, NativeBuildArgs, type NativeBuildArtifactKind, type NativeBuildDeleteResult, NativeBuildIosScheme, type NativeBuildMarkResult, NativeBuildOptions, type NativeBuildRow, type NativeBuildSubmissionDestination, NativeFingerprint, NativeFingerprintOptions, NativeFingerprintProvider, NativeFingerprintSource, type Platform$1 as Platform, PlatformConfig, Primitive, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, type ReleaseRow, type ReleaseRowUpdate, type RemoteDatabase, RequiredDeep, SecretRef, SecretsAdapter, SecretsContext, SigningConfig, StorageAdapter, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StoragePutInput, StoragePutResult, isRemoteDatabase, resolveLazy, supportedIosPlatforms };
@@ -3,7 +3,7 @@ import { AnyHotUpdaterPlugin } from "../serverPlugin/definePlugin.mjs";
3
3
  import { AggregateBatching, ConfiguredDatabase, EngineDatabase, RemoteDatabase, isRemoteDatabase } from "./databaseConfig.mjs";
4
4
  import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./utils.mjs";
5
5
  import { BundleRowUpdate, ReleaseCatalogRowUpdate, ReleaseRowUpdate } from "./databaseOperations.mjs";
6
- import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult } from "./models.mjs";
6
+ import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult, NativeBuildMarkResult } from "./models.mjs";
7
7
  import "./public.mjs";
8
8
  import { Bundle as Bundle$1, Platform, Platform as Platform$1 } from "@hot-updater/protocol";
9
9
  //#region src/types/index.d.ts
@@ -181,6 +181,15 @@ interface NativeBuildAndroidScheme {
181
181
  signing?: {
182
182
  keystore: SecretRef;
183
183
  };
184
+ /**
185
+ * Builds the app with the sandbox native layer, for testing OTA bundles on
186
+ * a device, as a separate app: the application ID gets a `.sandbox` suffix.
187
+ * It registers on the reserved channel `sandbox-<scheme>`, and reaches
188
+ * Google Play's internal testing only. No other build compiles the layer.
189
+ *
190
+ * @default false
191
+ */
192
+ sandbox?: boolean;
184
193
  }
185
194
  type IosBuildDestination = {
186
195
  id: string;
@@ -279,6 +288,18 @@ interface NativeBuildIosScheme {
279
288
  signing?: {
280
289
  ascApiKey: SecretRef;
281
290
  };
291
+ /**
292
+ * Builds the app with the sandbox native layer, for testing OTA bundles on
293
+ * a device. It has the bundle identifier its Xcode configuration builds,
294
+ * which `bundleIdentifier` must name: the store app's by default, which it
295
+ * replaces on a device, or its own from a separate configuration. It
296
+ * registers on the reserved channel `sandbox-<scheme>`, and its `.ipa` is for
297
+ * TestFlight internal testing only, never App Store review. No other build
298
+ * compiles the layer.
299
+ *
300
+ * @default false
301
+ */
302
+ sandbox?: boolean;
282
303
  }
283
304
  interface PlatformConfig {
284
305
  /**
@@ -601,4 +622,4 @@ interface NativeBuildOptions {
601
622
  scheme?: string;
602
623
  }
603
624
  //#endregion
604
- export { type AggregateBatching, ApplePlatform, BuildAdapter, BuildAdapterArgs, BuildAdapterConfig, BuiltIns, type Bundle$1 as Bundle, type BundlePatchRow, type BundleRow, type BundleRowUpdate, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, ConfigInput, type ConfiguredDatabase, type DatabaseBundleMetadata, type DatabaseJsonObject, type DatabaseJsonValue, type EngineDatabase, FingerprintExtraSources, HasMultipleCallSignatures, IosBuildDestination, Lazy, LocalSigningConfig, NativeBuildAndroidScheme, NativeBuildArgs, type NativeBuildArtifactKind, type NativeBuildDeleteResult, NativeBuildIosScheme, NativeBuildOptions, type NativeBuildRow, type NativeBuildSubmissionDestination, NativeFingerprint, NativeFingerprintOptions, NativeFingerprintProvider, NativeFingerprintSource, type Platform$1 as Platform, PlatformConfig, Primitive, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, type ReleaseRow, type ReleaseRowUpdate, type RemoteDatabase, RequiredDeep, SecretRef, SecretsAdapter, SecretsContext, SigningConfig, StorageAdapter, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StoragePutInput, StoragePutResult, isRemoteDatabase, resolveLazy, supportedIosPlatforms };
625
+ export { type AggregateBatching, ApplePlatform, BuildAdapter, BuildAdapterArgs, BuildAdapterConfig, BuiltIns, type Bundle$1 as Bundle, type BundlePatchRow, type BundleRow, type BundleRowUpdate, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, ConfigInput, type ConfiguredDatabase, type DatabaseBundleMetadata, type DatabaseJsonObject, type DatabaseJsonValue, type EngineDatabase, FingerprintExtraSources, HasMultipleCallSignatures, IosBuildDestination, Lazy, LocalSigningConfig, NativeBuildAndroidScheme, NativeBuildArgs, type NativeBuildArtifactKind, type NativeBuildDeleteResult, NativeBuildIosScheme, type NativeBuildMarkResult, NativeBuildOptions, type NativeBuildRow, type NativeBuildSubmissionDestination, NativeFingerprint, NativeFingerprintOptions, NativeFingerprintProvider, NativeFingerprintSource, type Platform$1 as Platform, PlatformConfig, Primitive, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, type ReleaseRow, type ReleaseRowUpdate, type RemoteDatabase, RequiredDeep, SecretRef, SecretsAdapter, SecretsContext, SigningConfig, StorageAdapter, StorageDeleteInput, StorageDeleteResult, StorageExistsInput, StorageExistsResult, StorageGetDownloadUrlInput, StorageGetDownloadUrlResult, StorageGetInput, StorageGetResult, StorageObject, StoragePutInput, StoragePutResult, isRemoteDatabase, resolveLazy, supportedIosPlatforms };
@@ -21,5 +21,13 @@ type NativeBuildDeleteResult = {
21
21
  readonly deleted: false;
22
22
  readonly reason: "not_found";
23
23
  };
24
+ /**
25
+ * A store build mark's result: the build, and the build whose mark it replaced,
26
+ * or null when it replaced none.
27
+ */
28
+ interface NativeBuildMarkResult {
29
+ readonly nativeBuild: NativeBuildRow;
30
+ readonly previous: NativeBuildRow | null;
31
+ }
24
32
  //#endregion
25
- export { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult };
33
+ export { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult, NativeBuildMarkResult };
@@ -21,5 +21,13 @@ type NativeBuildDeleteResult = {
21
21
  readonly deleted: false;
22
22
  readonly reason: "not_found";
23
23
  };
24
+ /**
25
+ * A store build mark's result: the build, and the build whose mark it replaced,
26
+ * or null when it replaced none.
27
+ */
28
+ interface NativeBuildMarkResult {
29
+ readonly nativeBuild: NativeBuildRow;
30
+ readonly previous: NativeBuildRow | null;
31
+ }
24
32
  //#endregion
25
- export { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult };
33
+ export { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult, NativeBuildMarkResult };
@@ -1,5 +1,5 @@
1
1
  import { BundlePatchRow, BundleRow, ChannelRow, DatabaseBundleMetadata, DatabaseJsonObject, DatabaseJsonValue, NativeBuildArtifactKind, NativeBuildRow, NativeBuildSubmissionDestination, ReleaseCatalogRow, ReleaseRow } from "./databaseRows.cjs";
2
2
  import { AggregateBatching, ConfiguredDatabase, EngineDatabase, RemoteDatabase, isRemoteDatabase } from "./databaseConfig.cjs";
3
3
  import { BundleRowUpdate, ReleaseCatalogRowUpdate, ReleaseRowUpdate } from "./databaseOperations.cjs";
4
- import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult } from "./models.cjs";
5
- export { type AggregateBatching, type BundlePatchRow, type BundleRow, type BundleRowUpdate, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, type ConfiguredDatabase, type DatabaseBundleMetadata, type DatabaseJsonObject, type DatabaseJsonValue, type EngineDatabase, type NativeBuildArtifactKind, type NativeBuildDeleteResult, type NativeBuildRow, type NativeBuildSubmissionDestination, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, type ReleaseRow, type ReleaseRowUpdate, type RemoteDatabase, isRemoteDatabase };
4
+ import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult, NativeBuildMarkResult } from "./models.cjs";
5
+ export { type AggregateBatching, type BundlePatchRow, type BundleRow, type BundleRowUpdate, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, type ConfiguredDatabase, type DatabaseBundleMetadata, type DatabaseJsonObject, type DatabaseJsonValue, type EngineDatabase, type NativeBuildArtifactKind, type NativeBuildDeleteResult, type NativeBuildMarkResult, type NativeBuildRow, type NativeBuildSubmissionDestination, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, type ReleaseRow, type ReleaseRowUpdate, type RemoteDatabase, isRemoteDatabase };
@@ -1,5 +1,5 @@
1
1
  import { BundlePatchRow, BundleRow, ChannelRow, DatabaseBundleMetadata, DatabaseJsonObject, DatabaseJsonValue, NativeBuildArtifactKind, NativeBuildRow, NativeBuildSubmissionDestination, ReleaseCatalogRow, ReleaseRow } from "./databaseRows.mjs";
2
2
  import { AggregateBatching, ConfiguredDatabase, EngineDatabase, RemoteDatabase, isRemoteDatabase } from "./databaseConfig.mjs";
3
3
  import { BundleRowUpdate, ReleaseCatalogRowUpdate, ReleaseRowUpdate } from "./databaseOperations.mjs";
4
- import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult } from "./models.mjs";
5
- export { type AggregateBatching, type BundlePatchRow, type BundleRow, type BundleRowUpdate, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, type ConfiguredDatabase, type DatabaseBundleMetadata, type DatabaseJsonObject, type DatabaseJsonValue, type EngineDatabase, type NativeBuildArtifactKind, type NativeBuildDeleteResult, type NativeBuildRow, type NativeBuildSubmissionDestination, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, type ReleaseRow, type ReleaseRowUpdate, type RemoteDatabase, isRemoteDatabase };
4
+ import { ChannelDeleteResult, ChannelInsertResult, NativeBuildDeleteResult, NativeBuildMarkResult } from "./models.mjs";
5
+ export { type AggregateBatching, type BundlePatchRow, type BundleRow, type BundleRowUpdate, type ChannelDeleteResult, type ChannelInsertResult, type ChannelRow, type ConfiguredDatabase, type DatabaseBundleMetadata, type DatabaseJsonObject, type DatabaseJsonValue, type EngineDatabase, type NativeBuildArtifactKind, type NativeBuildDeleteResult, type NativeBuildMarkResult, type NativeBuildRow, type NativeBuildSubmissionDestination, type ReleaseCatalogRow, type ReleaseCatalogRowUpdate, type ReleaseRow, type ReleaseRowUpdate, type RemoteDatabase, isRemoteDatabase };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/plugin-core",
3
- "version": "1.2.0-rc.12",
3
+ "version": "1.2.0-rc.13",
4
4
  "type": "module",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "sideEffects": false,
@@ -45,7 +45,7 @@
45
45
  "es-toolkit": "^1.32.0",
46
46
  "mime": "^4.0.4",
47
47
  "verkit": "0.4.0",
48
- "@hot-updater/protocol": "1.2.0-rc.12"
48
+ "@hot-updater/protocol": "1.2.0-rc.13"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@electric-sql/pglite": "0.4.1",