@hot-updater/vercel 1.2.0-rc.44 → 1.2.0-rc.45

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.
@@ -2599,6 +2599,10 @@ const iosDevices = defineTable({
2599
2599
  eq: ["status"],
2600
2600
  sort: ["id"]
2601
2601
  },
2602
+ byRegistration: {
2603
+ eq: [],
2604
+ sort: ["registered_at_ms"]
2605
+ },
2602
2606
  all: {
2603
2607
  eq: [],
2604
2608
  sort: ["id"]
@@ -2812,6 +2816,7 @@ const LEASE = { id: "compaction" };
2812
2816
  const LEASE_MS = 3e4;
2813
2817
  const WINDOW_MS$1 = 6e4;
2814
2818
  const LOG_PAGE = 200;
2819
+ const SKIP_AFTER_MS = 3e5;
2815
2820
  const GROUPS = {
2816
2821
  commit: 1,
2817
2822
  read: 8,
@@ -2918,18 +2923,30 @@ const rewrite$1 = (change, key, current) => {
2918
2923
  previous: current
2919
2924
  };
2920
2925
  };
2921
- const compile = async (adapter, changes) => {
2922
- const keys = changes.map(({ key }) => [...key.slice(0, -1), 0]);
2926
+ const rowId = (model, key) => JSON.stringify([model.table.name, key]);
2927
+ const keysOf = (changes) => changes.map(({ key }) => [...key.slice(0, -1), 0]);
2928
+ const readCurrent = async (adapter, changes) => {
2929
+ const keys = keysOf(changes);
2923
2930
  const reads = /* @__PURE__ */ new Map();
2924
2931
  changes.forEach((change, at) => {
2925
- if (rewrites(change)) reads.set(change.model, [...reads.get(change.model) ?? [], at]);
2932
+ if (!rewrites(change)) return;
2933
+ const wanted = reads.get(change.model) ?? /* @__PURE__ */ new Map();
2934
+ wanted.set(rowId(change.model, keys[at]), keys[at]);
2935
+ reads.set(change.model, wanted);
2926
2936
  });
2927
2937
  const current = /* @__PURE__ */ new Map();
2928
- await Promise.all([...reads].map(async ([model, positions]) => {
2929
- const rows = await adapter.get(model.table, positions.map((at) => keys[at]));
2930
- positions.forEach((at, index) => current.set(at, rows[index] ?? null));
2938
+ await Promise.all([...reads].map(async ([model, wanted]) => {
2939
+ const keys = [...wanted.values()];
2940
+ const rows = await adapter.get(model.table, keys);
2941
+ keys.forEach((key, at) => {
2942
+ current.set(rowId(model, key), rows[at] ?? null);
2943
+ });
2931
2944
  }));
2932
- return changes.map((change, at) => current.has(at) ? rewrite$1(change, keys[at], current.get(at)) : increment(change, keys[at]));
2945
+ return current;
2946
+ };
2947
+ const build = (changes, current) => {
2948
+ const keys = keysOf(changes);
2949
+ return changes.map((change, at) => rewrites(change) ? rewrite$1(change, keys[at], current.get(rowId(change.model, keys[at])) ?? null) : increment(change, keys[at]));
2933
2950
  };
2934
2951
  const isOp = (op) => op !== void 0;
2935
2952
  const sleep = (attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random()));
@@ -2995,6 +3012,9 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
2995
3012
  let nextDue = 0;
2996
3013
  let compacting;
2997
3014
  const known = /* @__PURE__ */ new Map();
3015
+ const skipped = LOG_TABLES.map(() => void 0);
3016
+ const past = (shard) => skipped[shard] === void 0 ? {} : { range: { gt: skipped[shard] } };
3017
+ const stampOf = (id) => Number.parseInt(id.slice(0, 9), 36);
2998
3018
  const idOf = (shard, id) => JSON.stringify([shard, id]);
2999
3019
  const leaseOp = (held, set) => {
3000
3020
  const next = {
@@ -3098,14 +3118,22 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
3098
3118
  logs: (await Promise.all(LOG_TABLES.map(async (name, shard) => {
3099
3119
  const page = await engine.reads.findMany(name, {
3100
3120
  index: "oldest",
3101
- limit: LOG_PAGE
3121
+ limit: LOG_PAGE,
3122
+ ...past(shard)
3102
3123
  });
3103
3124
  more ||= page.next !== void 0;
3104
- return (await Promise.all(page.rows.map(async (row) => ({
3125
+ const decoded = await Promise.all(page.rows.map(async (row) => ({
3105
3126
  shard,
3106
3127
  row,
3107
3128
  changes: await decode(String(row.changes))
3108
- })))).flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
3129
+ })));
3130
+ const settled = now() - SKIP_AFTER_MS;
3131
+ for (const { row, changes } of decoded) {
3132
+ const id = String(row.id);
3133
+ if (changes !== void 0 || stampOf(id) >= settled) break;
3134
+ skipped[shard] = id;
3135
+ }
3136
+ return decoded.flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
3109
3137
  ...entry,
3110
3138
  changes
3111
3139
  }]);
@@ -3113,14 +3141,15 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
3113
3141
  more
3114
3142
  };
3115
3143
  };
3116
- const rowsFor = async (changes) => (await compile(adapter, changes)).filter(isOp);
3117
3144
  const applyGroup = async (held, logs) => {
3145
+ const current = await readCurrent(adapter, logs.flatMap((entry) => [...entry.changes.values()]));
3146
+ const rowsFor = (changes) => build(changes, current).filter(isOp);
3118
3147
  for (let count = logs.length; count > 0; count = Math.floor(count / 2)) {
3119
3148
  const batch = logs.slice(0, count);
3120
3149
  const changes = mergeAll(/* @__PURE__ */ new Map(), batch.flatMap((entry) => [...entry.changes.values()]));
3121
3150
  const applied = batch.map(({ shard, row }) => [shard, row.id]);
3122
3151
  const lease = leaseOp(held, { applied: JSON.stringify(applied) });
3123
- const ops = [...await rowsFor([...changes.values()]), lease.op];
3152
+ const ops = [...rowsFor([...changes.values()]), lease.op];
3124
3153
  if (!adapter.fits(ops)) continue;
3125
3154
  for (const { shard, row } of batch) known.set(idOf(shard, row.id), row);
3126
3155
  return await commit(ops) ? {
@@ -3142,7 +3171,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
3142
3171
  };
3143
3172
  const lease = leaseOp(held, {});
3144
3173
  const ops = [
3145
- ...await rowsFor(entries.slice(0, take)),
3174
+ ...rowsFor(entries.slice(0, take)),
3146
3175
  kept,
3147
3176
  lease.op
3148
3177
  ];
@@ -3158,11 +3187,12 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
3158
3187
  if (held === void 0) return;
3159
3188
  let pending = true;
3160
3189
  let clear = false;
3190
+ let carried;
3161
3191
  try {
3162
3192
  for (let group = 0;; group += 1) {
3163
3193
  clear = await deleteApplied(held);
3164
3194
  if (!clear || !pending || group === groups) break;
3165
- const { logs, more } = await readLogs();
3195
+ const { logs, more } = carried ?? await readLogs();
3166
3196
  if (logs.length === 0) {
3167
3197
  pending = false;
3168
3198
  break;
@@ -3170,6 +3200,11 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
3170
3200
  const applied = await applyGroup(held, logs);
3171
3201
  if (applied === void 0) break;
3172
3202
  [held, clear] = [applied.held, false];
3203
+ const rest = applied.count === 0 ? [] : logs.slice(applied.count);
3204
+ carried = rest.length > 0 ? {
3205
+ logs: rest,
3206
+ more
3207
+ } : void 0;
3173
3208
  pending = more || applied.count < logs.length;
3174
3209
  }
3175
3210
  } finally {
@@ -3187,9 +3222,10 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs
3187
3222
  compacting = void 0;
3188
3223
  });
3189
3224
  let checking;
3190
- const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name) => engine.reads.findMany(name, {
3225
+ const hasPending = () => checking ??= Promise.all(LOG_TABLES.map((name, shard) => engine.reads.findMany(name, {
3191
3226
  index: "oldest",
3192
- limit: 1
3227
+ limit: 1,
3228
+ ...past(shard)
3193
3229
  }))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
3194
3230
  checking = void 0;
3195
3231
  });
@@ -17752,7 +17788,7 @@ const postgres = (config) => {
17752
17788
  };
17753
17789
  //#endregion
17754
17790
  //#region ../../packages/server/dist/version.mjs
17755
- const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.44";
17791
+ const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.45";
17756
17792
  //#endregion
17757
17793
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
17758
17794
  const createVersionRouteHandlers = (plugins = []) => {
@@ -18759,7 +18795,6 @@ const normalizeIosUdid = (value) => {
18759
18795
  const NAME_MAX_LENGTH = 100;
18760
18796
  const EMAIL_MAX_LENGTH = 320;
18761
18797
  const ISSUER_MAX_LENGTH = 64;
18762
- const ACCOUNT_SCAN_PAGE = 200;
18763
18798
  const ACCOUNT_ROW = "registry";
18764
18799
  const ERROR_MAX_LENGTH = 512;
18765
18800
  const STATUSES = [
@@ -18820,22 +18855,14 @@ const createIosDeviceApi = (db, { now = Date.now } = {}) => {
18820
18855
  return row === null ? null : pick$1(row);
18821
18856
  };
18822
18857
  const accountOfRows = async () => {
18823
- let earliest = null;
18824
- for (let after;;) {
18825
- const { rows } = await db.findMany("ios_devices", {
18826
- index: "all",
18827
- where: {},
18828
- order: "asc",
18829
- limit: ACCOUNT_SCAN_PAGE,
18830
- ...after === void 0 ? {} : { range: { gt: after } }
18831
- });
18832
- for (const row of rows.map(pick$1)) {
18833
- if (row.apple_issuer_id === null) continue;
18834
- if (earliest === null || (row.registered_at_ms ?? 0) < (earliest.registered_at_ms ?? 0)) earliest = row;
18835
- }
18836
- if (rows.length < ACCOUNT_SCAN_PAGE) return earliest?.apple_issuer_id ?? null;
18837
- after = rows.at(-1).id;
18838
- }
18858
+ const { rows } = await db.findMany("ios_devices", {
18859
+ index: "byRegistration",
18860
+ where: {},
18861
+ order: "asc",
18862
+ limit: 1,
18863
+ range: { gte: 0 }
18864
+ });
18865
+ return (rows[0] === void 0 ? null : pick$1(rows[0]))?.apple_issuer_id ?? null;
18839
18866
  };
18840
18867
  return {
18841
18868
  async listIosDevices(input) {
@@ -19184,6 +19211,7 @@ const EXPORT_METHODS = /* @__PURE__ */ new Set([
19184
19211
  "enterprise"
19185
19212
  ]);
19186
19213
  const OLDER_BUILDS_PAGE = 20;
19214
+ const OLDER_BUILDS_PAGES = 5;
19187
19215
  const MARK_ATTEMPTS = 8;
19188
19216
  const BUILD_NUMBER_MAX_LENGTH = 64;
19189
19217
  const SUBMITTED_VERSION_MAX_LENGTH = 255;
@@ -19374,6 +19402,10 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
19374
19402
  const row = await db.findOne("native_builds", { id });
19375
19403
  return row === null ? null : pick(row);
19376
19404
  },
19405
+ async findNativeBuildByBuiltInBundle(bundleId) {
19406
+ const row = await db.findOne("native_builds", { min_bundle_id: bundleId });
19407
+ return row === null ? null : pick(row);
19408
+ },
19377
19409
  async findNativeBuild(scope, options) {
19378
19410
  const scopeKey = nativeBuildScopeKey(scope);
19379
19411
  const buildKey = options?.buildKey;
@@ -19422,7 +19454,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
19422
19454
  }).then(({ rows: [row] }) => row?.artifact_kind === artifactKind ? pick(row) : void 0) : void 0);
19423
19455
  if (newest === void 0 || !ofKind(newest)) return null;
19424
19456
  if (bundleId === void 0 || newest.min_bundle_id < bundleId) return newest;
19425
- for (let before = newest.id;;) {
19457
+ let before = newest.id;
19458
+ for (let page = 0; page < OLDER_BUILDS_PAGES; page += 1) {
19426
19459
  const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
19427
19460
  const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
19428
19461
  if (usable !== void 0) return ofKind(usable) ? pick(usable) : null;
@@ -19430,6 +19463,7 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
19430
19463
  if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
19431
19464
  before = last.id;
19432
19465
  }
19466
+ return null;
19433
19467
  },
19434
19468
  async findNativeBuildSibling(build) {
19435
19469
  const artifactKind = SIBLING_KINDS[build.artifact_kind];
@@ -20582,6 +20616,7 @@ const createAdminRouteHandlers = () => ({
20582
20616
  return json$2({ data: build === null ? null : await core.findNativeBuildSibling(build) });
20583
20617
  }),
20584
20618
  getNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
20619
+ findNativeBuildByBuiltInBundle: onCore(async (core, _request, params) => json$2({ data: await core.findNativeBuildByBuiltInBundle(requireRouteParam(params, "bundleId")) })),
20585
20620
  listNativeBuilds: onCore(async (core, request) => {
20586
20621
  const url = new URL(request.url);
20587
20622
  const input = keyset(url);
@@ -20811,6 +20846,11 @@ const ADMIN_ROUTES = [
20811
20846
  path: "/native-builds/latest",
20812
20847
  handler: "findNativeBuild"
20813
20848
  },
20849
+ {
20850
+ method: "GET",
20851
+ path: "/native-builds/built-in/:bundleId",
20852
+ handler: "findNativeBuildByBuiltInBundle"
20853
+ },
20814
20854
  {
20815
20855
  method: "GET",
20816
20856
  path: "/native-builds/:id/sibling",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/vercel",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.44",
4
+ "version": "1.2.0-rc.45",
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/cli-tools": "1.2.0-rc.44",
45
- "@hot-updater/protocol": "1.2.0-rc.44",
46
- "@hot-updater/plugin-core": "1.2.0-rc.44",
47
- "@hot-updater/postgres": "1.2.0-rc.44",
48
- "@hot-updater/server": "1.2.0-rc.44"
44
+ "@hot-updater/cli-tools": "1.2.0-rc.45",
45
+ "@hot-updater/protocol": "1.2.0-rc.45",
46
+ "@hot-updater/postgres": "1.2.0-rc.45",
47
+ "@hot-updater/plugin-core": "1.2.0-rc.45",
48
+ "@hot-updater/server": "1.2.0-rc.45"
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.2.0-rc.44"
57
+ "@hot-updater/test-utils": "1.2.0-rc.45"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "tsdown",