@hot-updater/vercel 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.
@@ -2570,6 +2570,7 @@ const WINDOW_MS$1 = {
2570
2570
  memory: 15e3
2571
2571
  };
2572
2572
  const LOG_PAGE = 200;
2573
+ const SKIP_AFTER_MS = 3e5;
2573
2574
  const GROUPS = {
2574
2575
  commit: 1,
2575
2576
  read: 8,
@@ -2677,19 +2678,32 @@ const rewrite$1 = (change, key, current) => {
2677
2678
  previous: current
2678
2679
  };
2679
2680
  };
2680
- const compile = async (adapter, changes, shard) => {
2681
- const keys = changes.map(({ model, key }) => [...key.slice(0, -1), shard(model)]);
2681
+ const rowId = (model, key) => JSON.stringify([model.table.name, key]);
2682
+ const keysOf = (changes, shard) => changes.map(({ model, key }) => [...key.slice(0, -1), shard(model)]);
2683
+ const readCurrent = async (adapter, changes, shard) => {
2684
+ const keys = keysOf(changes, shard);
2682
2685
  const reads = /* @__PURE__ */ new Map();
2683
2686
  changes.forEach((change, at) => {
2684
- if (rewrites(change)) reads.set(change.model, [...reads.get(change.model) ?? [], at]);
2687
+ if (!rewrites(change)) return;
2688
+ const wanted = reads.get(change.model) ?? /* @__PURE__ */ new Map();
2689
+ wanted.set(rowId(change.model, keys[at]), keys[at]);
2690
+ reads.set(change.model, wanted);
2685
2691
  });
2686
2692
  const current = /* @__PURE__ */ new Map();
2687
- await Promise.all([...reads].map(async ([model, positions]) => {
2688
- const rows = await adapter.get(model.table, positions.map((at) => keys[at]));
2689
- positions.forEach((at, index) => current.set(at, rows[index] ?? null));
2693
+ await Promise.all([...reads].map(async ([model, wanted]) => {
2694
+ const keys = [...wanted.values()];
2695
+ const rows = await adapter.get(model.table, keys);
2696
+ keys.forEach((key, at) => {
2697
+ current.set(rowId(model, key), rows[at] ?? null);
2698
+ });
2690
2699
  }));
2691
- return changes.map((change, at) => current.has(at) ? rewrite$1(change, keys[at], current.get(at)) : increment(change, keys[at]));
2700
+ return current;
2701
+ };
2702
+ const build = (changes, shard, current) => {
2703
+ const keys = keysOf(changes, shard);
2704
+ return changes.map((change, at) => rewrites(change) ? rewrite$1(change, keys[at], current.get(rowId(change.model, keys[at])) ?? null) : increment(change, keys[at]));
2692
2705
  };
2706
+ const compile = async (adapter, changes, shard) => build(changes, shard, await readCurrent(adapter, changes, shard));
2693
2707
  const isOp = (op) => op !== void 0;
2694
2708
  const sleep = (attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random()));
2695
2709
  const pack = (text) => {
@@ -2809,6 +2823,9 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
2809
2823
  let nextDue = 0;
2810
2824
  let compacting;
2811
2825
  const known = /* @__PURE__ */ new Map();
2826
+ const skipped = LOG_TABLES.map(() => void 0);
2827
+ const past = (shard) => skipped[shard] === void 0 ? {} : { range: { gt: skipped[shard] } };
2828
+ const stampOf = (id) => Number.parseInt(id.slice(0, 9), 36);
2812
2829
  const idOf = (shard, id) => JSON.stringify([shard, id]);
2813
2830
  const leaseOp = (held, set) => {
2814
2831
  const next = {
@@ -2912,14 +2929,22 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
2912
2929
  logs: (await Promise.all(LOG_TABLES.map(async (name, shard) => {
2913
2930
  const page = await engine.reads.findMany(name, {
2914
2931
  index: "oldest",
2915
- limit: LOG_PAGE
2932
+ limit: LOG_PAGE,
2933
+ ...past(shard)
2916
2934
  });
2917
2935
  more ||= page.next !== void 0;
2918
- return (await Promise.all(page.rows.map(async (row) => ({
2936
+ const decoded = await Promise.all(page.rows.map(async (row) => ({
2919
2937
  shard,
2920
2938
  row,
2921
2939
  changes: await decode(String(row.changes))
2922
- })))).flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
2940
+ })));
2941
+ const settled = now() - SKIP_AFTER_MS;
2942
+ for (const { row, changes } of decoded) {
2943
+ const id = String(row.id);
2944
+ if (changes !== void 0 || stampOf(id) >= settled) break;
2945
+ skipped[shard] = id;
2946
+ }
2947
+ return decoded.flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
2923
2948
  ...entry,
2924
2949
  changes
2925
2950
  }]);
@@ -2927,14 +2952,15 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
2927
2952
  more
2928
2953
  };
2929
2954
  };
2930
- const rowsFor = async (changes) => (await compile(adapter, changes, () => 0)).filter(isOp);
2931
2955
  const applyGroup = async (held, logs) => {
2956
+ const current = await readCurrent(adapter, logs.flatMap((entry) => [...entry.changes.values()]), () => 0);
2957
+ const rowsFor = (changes) => build(changes, () => 0, current).filter(isOp);
2932
2958
  for (let count = logs.length; count > 0; count = Math.floor(count / 2)) {
2933
2959
  const batch = logs.slice(0, count);
2934
2960
  const changes = mergeAll(/* @__PURE__ */ new Map(), batch.flatMap((entry) => [...entry.changes.values()]));
2935
2961
  const applied = batch.map(({ shard, row }) => [shard, row.id]);
2936
2962
  const lease = leaseOp(held, { applied: JSON.stringify(applied) });
2937
- const ops = [...await rowsFor([...changes.values()]), lease.op];
2963
+ const ops = [...rowsFor([...changes.values()]), lease.op];
2938
2964
  if (!adapter.fits(ops)) continue;
2939
2965
  for (const { shard, row } of batch) known.set(idOf(shard, row.id), row);
2940
2966
  return await commit(ops) ? {
@@ -2956,7 +2982,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
2956
2982
  };
2957
2983
  const lease = leaseOp(held, {});
2958
2984
  const ops = [
2959
- ...await rowsFor(entries.slice(0, take)),
2985
+ ...rowsFor(entries.slice(0, take)),
2960
2986
  kept,
2961
2987
  lease.op
2962
2988
  ];
@@ -2972,11 +2998,12 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
2972
2998
  if (held === void 0) return;
2973
2999
  let pending = true;
2974
3000
  let clear = false;
3001
+ let carried;
2975
3002
  try {
2976
3003
  for (let group = 0;; group += 1) {
2977
3004
  clear = await deleteApplied(held);
2978
3005
  if (!clear || !pending || group === groups) break;
2979
- const { logs, more } = await readLogs();
3006
+ const { logs, more } = carried ?? await readLogs();
2980
3007
  if (logs.length === 0) {
2981
3008
  pending = false;
2982
3009
  break;
@@ -2984,6 +3011,11 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
2984
3011
  const applied = await applyGroup(held, logs);
2985
3012
  if (applied === void 0) break;
2986
3013
  [held, clear] = [applied.held, false];
3014
+ const rest = applied.count === 0 ? [] : logs.slice(applied.count);
3015
+ carried = rest.length > 0 ? {
3016
+ logs: rest,
3017
+ more
3018
+ } : void 0;
2987
3019
  pending = more || applied.count < logs.length;
2988
3020
  }
2989
3021
  } finally {
@@ -3001,9 +3033,10 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
3001
3033
  compacting = void 0;
3002
3034
  });
3003
3035
  let checking;
3004
- const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name) => engine.reads.findMany(name, {
3036
+ const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name, shard) => engine.reads.findMany(name, {
3005
3037
  index: "oldest",
3006
- limit: 1
3038
+ limit: 1,
3039
+ ...past(shard)
3007
3040
  }))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
3008
3041
  checking = void 0;
3009
3042
  });
@@ -17566,7 +17599,7 @@ const postgres = (config) => {
17566
17599
  };
17567
17600
  //#endregion
17568
17601
  //#region ../../packages/server/dist/version.mjs
17569
- const HOT_UPDATER_SERVER_VERSION = "1.1.15";
17602
+ const HOT_UPDATER_SERVER_VERSION = "1.1.17";
17570
17603
  //#endregion
17571
17604
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
17572
17605
  const createVersionRouteHandlers = (plugins = []) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/vercel",
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
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.mjs",
@@ -41,11 +41,11 @@
41
41
  "@vercel/cli-auth": "0.3.10",
42
42
  "@vercel/cli-config": "0.3.1",
43
43
  "pg": "8.13.1",
44
- "@hot-updater/plugin-core": "1.1.15",
45
- "@hot-updater/cli-tools": "1.1.15",
46
- "@hot-updater/postgres": "1.1.15",
47
- "@hot-updater/protocol": "1.1.15",
48
- "@hot-updater/server": "1.1.15"
44
+ "@hot-updater/cli-tools": "1.1.17",
45
+ "@hot-updater/plugin-core": "1.1.17",
46
+ "@hot-updater/server": "1.1.17",
47
+ "@hot-updater/postgres": "1.1.17",
48
+ "@hot-updater/protocol": "1.1.17"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^20",
@@ -54,7 +54,7 @@
54
54
  "execa": "9.5.2",
55
55
  "kysely": "0.28.17",
56
56
  "vitest": "4.1.4",
57
- "@hot-updater/test-utils": "1.1.15"
57
+ "@hot-updater/test-utils": "1.1.17"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "tsdown",