@hot-updater/azure 1.1.15 → 1.1.17

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.
@@ -6196,6 +6196,7 @@ const WINDOW_MS$1 = {
6196
6196
  memory: 15e3
6197
6197
  };
6198
6198
  const LOG_PAGE = 200;
6199
+ const SKIP_AFTER_MS = 3e5;
6199
6200
  const GROUPS = {
6200
6201
  commit: 1,
6201
6202
  read: 8,
@@ -6303,19 +6304,32 @@ const rewrite = (change, key, current) => {
6303
6304
  previous: current
6304
6305
  };
6305
6306
  };
6306
- const compile = async (adapter, changes, shard) => {
6307
- const keys = changes.map(({ model, key }) => [...key.slice(0, -1), shard(model)]);
6307
+ const rowId = (model, key) => JSON.stringify([model.table.name, key]);
6308
+ const keysOf = (changes, shard) => changes.map(({ model, key }) => [...key.slice(0, -1), shard(model)]);
6309
+ const readCurrent = async (adapter, changes, shard) => {
6310
+ const keys = keysOf(changes, shard);
6308
6311
  const reads = /* @__PURE__ */ new Map();
6309
6312
  changes.forEach((change, at) => {
6310
- if (rewrites(change)) reads.set(change.model, [...reads.get(change.model) ?? [], at]);
6313
+ if (!rewrites(change)) return;
6314
+ const wanted = reads.get(change.model) ?? /* @__PURE__ */ new Map();
6315
+ wanted.set(rowId(change.model, keys[at]), keys[at]);
6316
+ reads.set(change.model, wanted);
6311
6317
  });
6312
6318
  const current = /* @__PURE__ */ new Map();
6313
- await Promise.all([...reads].map(async ([model, positions]) => {
6314
- const rows = await adapter.get(model.table, positions.map((at) => keys[at]));
6315
- positions.forEach((at, index) => current.set(at, rows[index] ?? null));
6319
+ await Promise.all([...reads].map(async ([model, wanted]) => {
6320
+ const keys = [...wanted.values()];
6321
+ const rows = await adapter.get(model.table, keys);
6322
+ keys.forEach((key, at) => {
6323
+ current.set(rowId(model, key), rows[at] ?? null);
6324
+ });
6316
6325
  }));
6317
- return changes.map((change, at) => current.has(at) ? rewrite(change, keys[at], current.get(at)) : increment(change, keys[at]));
6326
+ return current;
6327
+ };
6328
+ const build = (changes, shard, current) => {
6329
+ const keys = keysOf(changes, shard);
6330
+ return changes.map((change, at) => rewrites(change) ? rewrite(change, keys[at], current.get(rowId(change.model, keys[at])) ?? null) : increment(change, keys[at]));
6318
6331
  };
6332
+ const compile = async (adapter, changes, shard) => build(changes, shard, await readCurrent(adapter, changes, shard));
6319
6333
  const isOp = (op) => op !== void 0;
6320
6334
  const sleep$1 = (attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random()));
6321
6335
  const pack = (text) => {
@@ -6435,6 +6449,9 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
6435
6449
  let nextDue = 0;
6436
6450
  let compacting;
6437
6451
  const known = /* @__PURE__ */ new Map();
6452
+ const skipped = LOG_TABLES.map(() => void 0);
6453
+ const past = (shard) => skipped[shard] === void 0 ? {} : { range: { gt: skipped[shard] } };
6454
+ const stampOf = (id) => Number.parseInt(id.slice(0, 9), 36);
6438
6455
  const idOf = (shard, id) => JSON.stringify([shard, id]);
6439
6456
  const leaseOp = (held, set) => {
6440
6457
  const next = {
@@ -6538,14 +6555,22 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
6538
6555
  logs: (await Promise.all(LOG_TABLES.map(async (name, shard) => {
6539
6556
  const page = await engine.reads.findMany(name, {
6540
6557
  index: "oldest",
6541
- limit: LOG_PAGE
6558
+ limit: LOG_PAGE,
6559
+ ...past(shard)
6542
6560
  });
6543
6561
  more ||= page.next !== void 0;
6544
- return (await Promise.all(page.rows.map(async (row) => ({
6562
+ const decoded = await Promise.all(page.rows.map(async (row) => ({
6545
6563
  shard,
6546
6564
  row,
6547
6565
  changes: await decode(String(row.changes))
6548
- })))).flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
6566
+ })));
6567
+ const settled = now() - SKIP_AFTER_MS;
6568
+ for (const { row, changes } of decoded) {
6569
+ const id = String(row.id);
6570
+ if (changes !== void 0 || stampOf(id) >= settled) break;
6571
+ skipped[shard] = id;
6572
+ }
6573
+ return decoded.flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
6549
6574
  ...entry,
6550
6575
  changes
6551
6576
  }]);
@@ -6553,14 +6578,15 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
6553
6578
  more
6554
6579
  };
6555
6580
  };
6556
- const rowsFor = async (changes) => (await compile(adapter, changes, () => 0)).filter(isOp);
6557
6581
  const applyGroup = async (held, logs) => {
6582
+ const current = await readCurrent(adapter, logs.flatMap((entry) => [...entry.changes.values()]), () => 0);
6583
+ const rowsFor = (changes) => build(changes, () => 0, current).filter(isOp);
6558
6584
  for (let count = logs.length; count > 0; count = Math.floor(count / 2)) {
6559
6585
  const batch = logs.slice(0, count);
6560
6586
  const changes = mergeAll(/* @__PURE__ */ new Map(), batch.flatMap((entry) => [...entry.changes.values()]));
6561
6587
  const applied = batch.map(({ shard, row }) => [shard, row.id]);
6562
6588
  const lease = leaseOp(held, { applied: JSON.stringify(applied) });
6563
- const ops = [...await rowsFor([...changes.values()]), lease.op];
6589
+ const ops = [...rowsFor([...changes.values()]), lease.op];
6564
6590
  if (!adapter.fits(ops)) continue;
6565
6591
  for (const { shard, row } of batch) known.set(idOf(shard, row.id), row);
6566
6592
  return await commit(ops) ? {
@@ -6582,7 +6608,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
6582
6608
  };
6583
6609
  const lease = leaseOp(held, {});
6584
6610
  const ops = [
6585
- ...await rowsFor(entries.slice(0, take)),
6611
+ ...rowsFor(entries.slice(0, take)),
6586
6612
  kept,
6587
6613
  lease.op
6588
6614
  ];
@@ -6598,11 +6624,12 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
6598
6624
  if (held === void 0) return;
6599
6625
  let pending = true;
6600
6626
  let clear = false;
6627
+ let carried;
6601
6628
  try {
6602
6629
  for (let group = 0;; group += 1) {
6603
6630
  clear = await deleteApplied(held);
6604
6631
  if (!clear || !pending || group === groups) break;
6605
- const { logs, more } = await readLogs();
6632
+ const { logs, more } = carried ?? await readLogs();
6606
6633
  if (logs.length === 0) {
6607
6634
  pending = false;
6608
6635
  break;
@@ -6610,6 +6637,11 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
6610
6637
  const applied = await applyGroup(held, logs);
6611
6638
  if (applied === void 0) break;
6612
6639
  [held, clear] = [applied.held, false];
6640
+ const rest = applied.count === 0 ? [] : logs.slice(applied.count);
6641
+ carried = rest.length > 0 ? {
6642
+ logs: rest,
6643
+ more
6644
+ } : void 0;
6613
6645
  pending = more || applied.count < logs.length;
6614
6646
  }
6615
6647
  } finally {
@@ -6627,9 +6659,10 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
6627
6659
  compacting = void 0;
6628
6660
  });
6629
6661
  let checking;
6630
- const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name) => engine.reads.findMany(name, {
6662
+ const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name, shard) => engine.reads.findMany(name, {
6631
6663
  index: "oldest",
6632
- limit: 1
6664
+ limit: 1,
6665
+ ...past(shard)
6633
6666
  }))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
6634
6667
  checking = void 0;
6635
6668
  });
@@ -7998,7 +8031,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
7998
8031
  };
7999
8032
  //#endregion
8000
8033
  //#region ../../packages/server/dist/version.mjs
8001
- const HOT_UPDATER_SERVER_VERSION = "1.1.15";
8034
+ const HOT_UPDATER_SERVER_VERSION = "1.1.17";
8002
8035
  //#endregion
8003
8036
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
8004
8037
  const createVersionRouteHandlers = (plugins = []) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/azure",
3
3
  "type": "module",
4
- "version": "1.1.15",
4
+ "version": "1.1.17",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "engines": {
7
7
  "node": "^22.23.4 || ^24.22.1 || >=26.12.1"
@@ -42,10 +42,10 @@
42
42
  "@azure/core-auth": "1.11.0",
43
43
  "@azure/cosmos": "4.10.1",
44
44
  "@azure/storage-blob": "12.34.0",
45
- "@hot-updater/plugin-core": "1.1.15",
46
- "@hot-updater/protocol": "1.1.15",
47
- "@hot-updater/server": "1.1.15",
48
- "@hot-updater/cli-tools": "1.1.15"
45
+ "@hot-updater/cli-tools": "1.1.17",
46
+ "@hot-updater/plugin-core": "1.1.17",
47
+ "@hot-updater/protocol": "1.1.17",
48
+ "@hot-updater/server": "1.1.17"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@azure/functions": "4.16.5",
@@ -53,7 +53,7 @@
53
53
  "execa": "9.5.2",
54
54
  "jszip": "^3.10.1",
55
55
  "vitest": "4.1.4",
56
- "@hot-updater/test-utils": "1.1.15"
56
+ "@hot-updater/test-utils": "1.1.17"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsdown",