@hot-updater/plugin-core 1.2.0-rc.2 → 1.2.0-rc.20

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
  };