@hot-updater/cloudflare 1.2.0-rc.43 → 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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/cloudflare",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.43",
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",
@@ -52,11 +52,11 @@
52
52
  "cloudflare": "4.2.0",
53
53
  "hono": "4.12.34",
54
54
  "uuidv7": "^1.0.2",
55
- "@hot-updater/protocol": "1.2.0-rc.43",
56
- "@hot-updater/plugin-core": "1.2.0-rc.43",
57
- "@hot-updater/storage-s3": "1.2.0-rc.43",
58
- "@hot-updater/server": "1.2.0-rc.43",
59
- "@hot-updater/cli-tools": "1.2.0-rc.43"
55
+ "@hot-updater/cli-tools": "1.2.0-rc.45",
56
+ "@hot-updater/protocol": "1.2.0-rc.45",
57
+ "@hot-updater/plugin-core": "1.2.0-rc.45",
58
+ "@hot-updater/server": "1.2.0-rc.45",
59
+ "@hot-updater/storage-s3": "1.2.0-rc.45"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@aws-sdk/client-s3": "3.1066.0",
@@ -75,7 +75,7 @@
75
75
  "vitest": "4.1.4",
76
76
  "wrangler": "^4.69.0",
77
77
  "xdg-app-paths": "^8.3.0",
78
- "@hot-updater/test-utils": "1.2.0-rc.43"
78
+ "@hot-updater/test-utils": "1.2.0-rc.45"
79
79
  },
80
80
  "scripts": {
81
81
  "build": "tsdown && pnpm build:worker",
package/sql/bundles.sql CHANGED
@@ -54,6 +54,8 @@ CREATE TABLE IF NOT EXISTS "ios_devices" ("id" TEXT NOT NULL, "udid" TEXT NOT NU
54
54
 
55
55
  CREATE INDEX IF NOT EXISTS "ios_devices_byStatus" ON "ios_devices" ("status", "id");
56
56
 
57
+ CREATE INDEX IF NOT EXISTS "ios_devices_byRegistration" ON "ios_devices" ("registered_at_ms", "id");
58
+
57
59
  CREATE UNIQUE INDEX IF NOT EXISTS "ios_devices_udid" ON "ios_devices" ("udid");
58
60
 
59
61
  CREATE TABLE IF NOT EXISTS "ios_device_account" ("id" TEXT NOT NULL, "apple_issuer_id" TEXT NOT NULL, "claimed_at_ms" INTEGER NOT NULL, "_v" INTEGER NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
@@ -64,6 +66,8 @@ CREATE INDEX IF NOT EXISTS "bundle_events_movementsByInstall" ON "bundle_events"
64
66
 
65
67
  CREATE TABLE IF NOT EXISTS "bundle_events__byBundle" ("platform" TEXT NOT NULL, "channel" TEXT NOT NULL, "type" TEXT NOT NULL, "bundle_ref" TEXT NOT NULL, "day" INTEGER NOT NULL, "received_at_ms" INTEGER NOT NULL, "id" TEXT NOT NULL, PRIMARY KEY ("platform", "channel", "type", "bundle_ref", "day", "received_at_ms", "id"));
66
68
 
69
+ CREATE INDEX IF NOT EXISTS "bundle_events__byBundle__key" ON "bundle_events__byBundle" ("id");
70
+
67
71
  CREATE INDEX IF NOT EXISTS "bundle_events_byDay" ON "bundle_events" ("day", "received_at_ms", "id");
68
72
 
69
73
  CREATE TABLE IF NOT EXISTS "bundle_event_heads" ("install_id" TEXT NOT NULL, "id" TEXT NOT NULL, "type" TEXT NOT NULL, "user_id" TEXT, "from_release_id" TEXT, "from_bundle_id" TEXT, "to_release_id" TEXT, "to_bundle_id" TEXT NOT NULL, "platform" TEXT NOT NULL, "app_version" TEXT NOT NULL, "channel" TEXT NOT NULL, "metadata" TEXT NOT NULL, "received_at_ms" INTEGER NOT NULL, "_v" INTEGER NOT NULL DEFAULT 0, PRIMARY KEY ("install_id"));
@@ -1 +1 @@
1
- This folder contains the built output assets for the worker "hot-updater" generated at 2026-11-13T16:53:15.829Z.
1
+ This folder contains the built output assets for the worker "hot-updater" generated at 2026-11-15T02:41:02.703Z.
@@ -1090,8 +1090,8 @@ function coerce2(value, options = {}) {
1090
1090
  const minor = match2[3] || "0";
1091
1091
  const patch = match2[4] || "0";
1092
1092
  const prerelease = options.includePrerelease && match2[5] ? `-${match2[5]}` : "";
1093
- const build = options.includePrerelease && match2[6] ? `+${match2[6]}` : "";
1094
- return tryParse2(`${major}.${minor}.${patch}${prerelease}${build}`, options);
1093
+ const build2 = options.includePrerelease && match2[6] ? `+${match2[6]}` : "";
1094
+ return tryParse2(`${major}.${minor}.${patch}${prerelease}${build2}`, options);
1095
1095
  }
1096
1096
  __name(coerce2, "coerce");
1097
1097
 
@@ -2194,7 +2194,12 @@ var sqlTableShapes = /* @__PURE__ */ __name((dialect, tables, tablePrefix = "")
2194
2194
  name: `${name}__${index.name}`,
2195
2195
  columns: entries,
2196
2196
  key: columns,
2197
- indexes: []
2197
+ indexes: [{
2198
+ kind: "index",
2199
+ name: shortSqlName(`${name}__${index.name}__key`),
2200
+ unique: false,
2201
+ columns: table.key
2202
+ }]
2198
2203
  }
2199
2204
  }];
2200
2205
  }
@@ -2264,9 +2269,17 @@ var pruneStatements = /* @__PURE__ */ __name((dialect, table, tablePrefix, limit
2264
2269
  const order = retentionOrder(table).columns.map(quote);
2265
2270
  const list = /* @__PURE__ */ __name((alias, direction = "") => order.map((column) => `${alias}.${column}${direction}`).join(", "), "list");
2266
2271
  const oldest = /* @__PURE__ */ __name((before) => `SELECT ${list("i")} FROM ${name} i WHERE i.${at} <= ${before()} ORDER BY ${list("i", " ASC")} LIMIT ${limit}`, "oldest");
2267
- const doomed = /* @__PURE__ */ __name((alias, before) => `${alias}.${at} <= ${before()} AND (${list(alias)}) <= (SELECT ${list("b")} FROM (${oldest(before)}) b ORDER BY ${list("b", " DESC")} LIMIT 1)`, "doomed");
2272
+ const doomed = /* @__PURE__ */ __name((alias, before) => `(${list(alias)}) <= (SELECT ${list("b")} FROM (${oldest(before)}) b ORDER BY ${list("b", " DESC")} LIMIT 1) AND ${alias}.${at} <= ${before()}`, "doomed");
2268
2273
  const entries = table.indexes.filter((index) => isMultiIndex(table, index)).map((index) => quote(`${tablePrefix}${table.name}__${index.name}`));
2269
2274
  const keyOf = /* @__PURE__ */ __name((left, right) => table.key.map((column) => `${left}.${quote(column)} = ${right}.${quote(column)}`).join(" AND "), "keyOf");
2275
+ if (dialect === "sqlite") return [...table.indexes.filter((index) => isMultiIndex(table, index)).map((index) => {
2276
+ const columns = [...index.eq, ...indexOrderColumns(table, index)];
2277
+ const multi = columns.filter((column) => findPhysicalColumn(table, column).multi);
2278
+ const values = columns.map((column) => multi.includes(column) ? `j${multi.indexOf(column)}.${quote("value")}` : `b.${quote(column)}`);
2279
+ const each = multi.map((column, at2) => `, json_each(b.${quote(column)}) j${at2}`);
2280
+ const into = quote(`${tablePrefix}${table.name}__${index.name}`);
2281
+ return (before) => `DELETE FROM ${into} WHERE (${columns.map(quote).join(", ")}) IN (SELECT ${values.join(", ")} FROM ${name} b${each.join("")} WHERE ${doomed("b", before)})`;
2282
+ }), (before) => `DELETE FROM ${name} WHERE ${doomed(name, before)}`];
2270
2283
  if (dialect === "mysql") return [...entries.map((index) => (before) => `DELETE e FROM ${index} e JOIN (${oldest(before)}) d ON ${keyOf("e", "d")}`), (before) => `DELETE FROM ${name} WHERE ${at} <= ${before()} ORDER BY ${order.join(", ")} LIMIT ${limit}`];
2271
2284
  return [...entries.map((index) => (before) => `DELETE FROM ${index} WHERE EXISTS (SELECT * FROM ${name} b WHERE ${keyOf("b", index)} AND ${doomed("b", before)})`), (before) => `DELETE FROM ${name} WHERE ${doomed(name, before)}`];
2272
2285
  }, "pruneStatements");
@@ -2719,6 +2732,10 @@ var iosDevices = defineTable({
2719
2732
  eq: ["status"],
2720
2733
  sort: ["id"]
2721
2734
  },
2735
+ byRegistration: {
2736
+ eq: [],
2737
+ sort: ["registered_at_ms"]
2738
+ },
2722
2739
  all: {
2723
2740
  eq: [],
2724
2741
  sort: ["id"]
@@ -2938,6 +2955,7 @@ var LEASE = { id: "compaction" };
2938
2955
  var LEASE_MS = 3e4;
2939
2956
  var WINDOW_MS = 6e4;
2940
2957
  var LOG_PAGE = 200;
2958
+ var SKIP_AFTER_MS = 3e5;
2941
2959
  var GROUPS = {
2942
2960
  commit: 1,
2943
2961
  read: 8,
@@ -3045,19 +3063,31 @@ var rewrite2 = /* @__PURE__ */ __name((change, key, current) => {
3045
3063
  previous: current
3046
3064
  };
3047
3065
  }, "rewrite");
3048
- var compile = /* @__PURE__ */ __name(async (adapter, changes) => {
3049
- const keys = changes.map(({ key }) => [...key.slice(0, -1), 0]);
3066
+ var rowId = /* @__PURE__ */ __name((model, key) => JSON.stringify([model.table.name, key]), "rowId");
3067
+ var keysOf = /* @__PURE__ */ __name((changes) => changes.map(({ key }) => [...key.slice(0, -1), 0]), "keysOf");
3068
+ var readCurrent = /* @__PURE__ */ __name(async (adapter, changes) => {
3069
+ const keys = keysOf(changes);
3050
3070
  const reads = /* @__PURE__ */ new Map();
3051
3071
  changes.forEach((change, at) => {
3052
- if (rewrites(change)) reads.set(change.model, [...reads.get(change.model) ?? [], at]);
3072
+ if (!rewrites(change)) return;
3073
+ const wanted = reads.get(change.model) ?? /* @__PURE__ */ new Map();
3074
+ wanted.set(rowId(change.model, keys[at]), keys[at]);
3075
+ reads.set(change.model, wanted);
3053
3076
  });
3054
3077
  const current = /* @__PURE__ */ new Map();
3055
- await Promise.all([...reads].map(async ([model, positions]) => {
3056
- const rows = await adapter.get(model.table, positions.map((at) => keys[at]));
3057
- positions.forEach((at, index) => current.set(at, rows[index] ?? null));
3078
+ await Promise.all([...reads].map(async ([model, wanted]) => {
3079
+ const keys2 = [...wanted.values()];
3080
+ const rows = await adapter.get(model.table, keys2);
3081
+ keys2.forEach((key, at) => {
3082
+ current.set(rowId(model, key), rows[at] ?? null);
3083
+ });
3058
3084
  }));
3059
- return changes.map((change, at) => current.has(at) ? rewrite2(change, keys[at], current.get(at)) : increment(change, keys[at]));
3060
- }, "compile");
3085
+ return current;
3086
+ }, "readCurrent");
3087
+ var build = /* @__PURE__ */ __name((changes, current) => {
3088
+ const keys = keysOf(changes);
3089
+ return changes.map((change, at) => rewrites(change) ? rewrite2(change, keys[at], current.get(rowId(change.model, keys[at])) ?? null) : increment(change, keys[at]));
3090
+ }, "build");
3061
3091
  var isOp = /* @__PURE__ */ __name((op) => op !== void 0, "isOp");
3062
3092
  var sleep = /* @__PURE__ */ __name((attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random())), "sleep");
3063
3093
  var pack = /* @__PURE__ */ __name((text) => {
@@ -3122,6 +3152,9 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3122
3152
  let nextDue = 0;
3123
3153
  let compacting;
3124
3154
  const known = /* @__PURE__ */ new Map();
3155
+ const skipped = LOG_TABLES.map(() => void 0);
3156
+ const past = /* @__PURE__ */ __name((shard) => skipped[shard] === void 0 ? {} : { range: { gt: skipped[shard] } }, "past");
3157
+ const stampOf = /* @__PURE__ */ __name((id) => Number.parseInt(id.slice(0, 9), 36), "stampOf");
3125
3158
  const idOf2 = /* @__PURE__ */ __name((shard, id) => JSON.stringify([shard, id]), "idOf");
3126
3159
  const leaseOp = /* @__PURE__ */ __name((held, set) => {
3127
3160
  const next = {
@@ -3225,14 +3258,22 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3225
3258
  logs: (await Promise.all(LOG_TABLES.map(async (name, shard) => {
3226
3259
  const page2 = await engine.reads.findMany(name, {
3227
3260
  index: "oldest",
3228
- limit: LOG_PAGE
3261
+ limit: LOG_PAGE,
3262
+ ...past(shard)
3229
3263
  });
3230
3264
  more ||= page2.next !== void 0;
3231
- return (await Promise.all(page2.rows.map(async (row) => ({
3265
+ const decoded = await Promise.all(page2.rows.map(async (row) => ({
3232
3266
  shard,
3233
3267
  row,
3234
3268
  changes: await decode2(String(row.changes))
3235
- })))).flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
3269
+ })));
3270
+ const settled = now() - SKIP_AFTER_MS;
3271
+ for (const { row, changes } of decoded) {
3272
+ const id = String(row.id);
3273
+ if (changes !== void 0 || stampOf(id) >= settled) break;
3274
+ skipped[shard] = id;
3275
+ }
3276
+ return decoded.flatMap(({ changes, ...entry }) => changes === void 0 ? [] : [{
3236
3277
  ...entry,
3237
3278
  changes
3238
3279
  }]);
@@ -3240,14 +3281,15 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3240
3281
  more
3241
3282
  };
3242
3283
  }, "readLogs");
3243
- const rowsFor = /* @__PURE__ */ __name(async (changes) => (await compile(adapter, changes)).filter(isOp), "rowsFor");
3244
3284
  const applyGroup = /* @__PURE__ */ __name(async (held, logs) => {
3285
+ const current = await readCurrent(adapter, logs.flatMap((entry) => [...entry.changes.values()]));
3286
+ const rowsFor = /* @__PURE__ */ __name((changes2) => build(changes2, current).filter(isOp), "rowsFor");
3245
3287
  for (let count = logs.length; count > 0; count = Math.floor(count / 2)) {
3246
3288
  const batch = logs.slice(0, count);
3247
3289
  const changes2 = mergeAll(/* @__PURE__ */ new Map(), batch.flatMap((entry) => [...entry.changes.values()]));
3248
3290
  const applied = batch.map(({ shard: shard2, row: row2 }) => [shard2, row2.id]);
3249
3291
  const lease2 = leaseOp(held, { applied: JSON.stringify(applied) });
3250
- const ops = [...await rowsFor([...changes2.values()]), lease2.op];
3292
+ const ops = [...rowsFor([...changes2.values()]), lease2.op];
3251
3293
  if (!adapter.fits(ops)) continue;
3252
3294
  for (const { shard: shard2, row: row2 } of batch) known.set(idOf2(shard2, row2.id), row2);
3253
3295
  return await commit(ops) ? {
@@ -3269,7 +3311,7 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3269
3311
  };
3270
3312
  const lease2 = leaseOp(held, {});
3271
3313
  const ops = [
3272
- ...await rowsFor(entries.slice(0, take)),
3314
+ ...rowsFor(entries.slice(0, take)),
3273
3315
  kept,
3274
3316
  lease2.op
3275
3317
  ];
@@ -3285,11 +3327,12 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3285
3327
  if (held === void 0) return;
3286
3328
  let pending = true;
3287
3329
  let clear = false;
3330
+ let carried;
3288
3331
  try {
3289
3332
  for (let group = 0; ; group += 1) {
3290
3333
  clear = await deleteApplied(held);
3291
3334
  if (!clear || !pending || group === groups) break;
3292
- const { logs, more } = await readLogs();
3335
+ const { logs, more } = carried ?? await readLogs();
3293
3336
  if (logs.length === 0) {
3294
3337
  pending = false;
3295
3338
  break;
@@ -3297,6 +3340,11 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3297
3340
  const applied = await applyGroup(held, logs);
3298
3341
  if (applied === void 0) break;
3299
3342
  [held, clear] = [applied.held, false];
3343
+ const rest = applied.count === 0 ? [] : logs.slice(applied.count);
3344
+ carried = rest.length > 0 ? {
3345
+ logs: rest,
3346
+ more
3347
+ } : void 0;
3300
3348
  pending = more || applied.count < logs.length;
3301
3349
  }
3302
3350
  } finally {
@@ -3314,9 +3362,10 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3314
3362
  compacting = void 0;
3315
3363
  }), "compact");
3316
3364
  let checking;
3317
- const hasPending = /* @__PURE__ */ __name(() => checking ??= Promise.all(LOG_TABLES.map((name) => engine.reads.findMany(name, {
3365
+ const hasPending = /* @__PURE__ */ __name(() => checking ??= Promise.all(LOG_TABLES.map((name, shard) => engine.reads.findMany(name, {
3318
3366
  index: "oldest",
3319
- limit: 1
3367
+ limit: 1,
3368
+ ...past(shard)
3320
3369
  }))).then((pages) => pages.some((page2) => page2.rows.length > 0)).finally(() => {
3321
3370
  checking = void 0;
3322
3371
  }), "hasPending");
@@ -3964,7 +4013,7 @@ var createTransactions = /* @__PURE__ */ __name(({ adapter, schema, reads, retry
3964
4013
  return {
3965
4014
  result,
3966
4015
  read,
3967
- ops: compile2(writes, read, deleted),
4016
+ ops: compile(writes, read, deleted),
3968
4017
  aggregates: [...aggregates.values()]
3969
4018
  };
3970
4019
  } catch (error) {
@@ -3973,7 +4022,7 @@ var createTransactions = /* @__PURE__ */ __name(({ adapter, schema, reads, retry
3973
4022
  open = false;
3974
4023
  }
3975
4024
  }, "attempt");
3976
- const compile2 = /* @__PURE__ */ __name((writes, read, deleted) => {
4025
+ const compile = /* @__PURE__ */ __name((writes, read, deleted) => {
3977
4026
  const toOp = /* @__PURE__ */ __name((id) => {
3978
4027
  const { model, key, type, row, read: previous } = writes.get(id);
3979
4028
  const { table } = model;
@@ -4475,7 +4524,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4475
4524
  const quote = /* @__PURE__ */ __name((name) => quoteSql(dialect, name), "quote");
4476
4525
  const tableOf = /* @__PURE__ */ __name((table, index) => quote(`${tablePrefix}${table.name}${index ? `__${index.name}` : ""}`), "tableOf");
4477
4526
  const version2 = quote("_v");
4478
- const sql = /* @__PURE__ */ __name((build) => {
4527
+ const sql = /* @__PURE__ */ __name((build2) => {
4479
4528
  const params = [];
4480
4529
  const bind = /* @__PURE__ */ __name((value, column) => {
4481
4530
  const json4 = column?.multi || column?.type === "json";
@@ -4483,7 +4532,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4483
4532
  return postgres ? `$${params.length}${json4 ? "::jsonb" : ""}` : "?";
4484
4533
  }, "bind");
4485
4534
  return {
4486
- sql: build(bind),
4535
+ sql: build2(bind),
4487
4536
  params
4488
4537
  };
4489
4538
  }, "sql");
@@ -4498,26 +4547,26 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4498
4547
  }
4499
4548
  return `(${cols.map((column, position) => [...cols.slice(0, position).map((prefix, at) => `${prefix} = ${bind(bound2.values[at])}`), `${column} ${position === cols.length - 1 ? last : op} ${bind(bound2.values[position])}`].join(" AND ")).map((term) => `(${term})`).join(" OR ")})`;
4500
4549
  }, "compare");
4501
- const compile2 = /* @__PURE__ */ __name((op, when) => {
4550
+ const compile = /* @__PURE__ */ __name((op, when) => {
4502
4551
  const { table } = op;
4503
4552
  const name = tableOf(table);
4504
4553
  const where = /* @__PURE__ */ __name((bind, key, v) => `${keyMatch(bind, table, key)}${v === void 0 ? "" : ` AND ${version2} = ${bind(v)}`}${when ? ` AND ${when(bind)}` : ""}`, "where");
4505
4554
  const insert = /* @__PURE__ */ __name((bind, into, columns, values) => `INSERT INTO ${into} (${columns.map(quote).join(", ")}) ${when ? `SELECT ${values.join(", ")} WHERE ${when(bind)}` : `VALUES (${values.join(", ")})`}`, "insert");
4506
4555
  const insertRow = /* @__PURE__ */ __name((bind, row) => insert(bind, name, table.columns.map((column) => column.name), table.columns.map((column) => bind(row[column.name], column))), "insertRow");
4507
- const entries = /* @__PURE__ */ __name((key, row, changed) => table.indexes.flatMap((index) => {
4556
+ const entries = /* @__PURE__ */ __name((key, row, changed, stale = true) => table.indexes.flatMap((index) => {
4508
4557
  const columns = [...index.eq, ...indexOrderColumns(table, index)];
4509
4558
  if (!isMultiIndex(table, index) || changed && !columns.some((column) => changed.includes(column))) return [];
4510
4559
  const into = tableOf(table, index);
4511
4560
  const found = row ? indexEntries(table, index, row) : [];
4512
4561
  const order = found.length > 0 ? indexOrderTuple(table, index, row) : [];
4513
- return [sql((bind) => `DELETE FROM ${into} WHERE ${where(bind, key)}`), ...found.map((eq) => sql((bind) => {
4562
+ return [...stale ? [sql((bind) => `DELETE FROM ${into} WHERE ${where(bind, key)}`)] : [], ...found.map((eq) => sql((bind) => {
4514
4563
  const values = [...eq, ...order].map((value) => bind(value));
4515
4564
  return insert(bind, into, columns, values);
4516
4565
  }))];
4517
4566
  }), "entries");
4518
4567
  switch (op.type) {
4519
4568
  case "insert":
4520
- return [sql((bind) => insertRow(bind, op.row)), ...entries(rowKey(table, op.row), op.row)];
4569
+ return [sql((bind) => insertRow(bind, op.row)), ...entries(rowKey(table, op.row), op.row, void 0, false)];
4521
4570
  case "patch":
4522
4571
  return [sql((bind) => {
4523
4572
  const set = Object.entries(op.set).map(([column, value]) => `${quote(column)} = ${bind(value, findPhysicalColumn(table, column))}`);
@@ -4572,7 +4621,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4572
4621
  return [
4573
4622
  sql((bind) => `INSERT INTO ${guard} (${idColumn}, ${failed2}) VALUES (${bind(id)}, NULL)`),
4574
4623
  ...ops.flatMap((op, position) => upserts(op) ? [] : [sql((bind) => `UPDATE ${guard} SET ${failed2} = ${position} WHERE ${failed2} IS NULL AND (${failure(bind, op, released(op.table.name))}) AND ${byId(bind)}`)]),
4575
- ...ops.flatMap((op) => compile2(op, when)),
4624
+ ...ops.flatMap((op) => compile(op, when)),
4576
4625
  sql((bind) => `SELECT ${failed2} FROM ${guard} WHERE ${byId(bind)}`),
4577
4626
  sql((bind) => `DELETE FROM ${guard} WHERE ${byId(bind)}`)
4578
4627
  ];
@@ -4626,7 +4675,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4626
4675
  }
4627
4676
  await executor.transaction(async (connection) => {
4628
4677
  for (const [position, op] of ops.entries()) {
4629
- const [first, ...rest] = compile2(op);
4678
+ const [first, ...rest] = compile(op);
4630
4679
  let result;
4631
4680
  try {
4632
4681
  result = await connection.execute(first);
@@ -4676,7 +4725,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4676
4725
  }, "createSqlAdapter");
4677
4726
 
4678
4727
  // ../../packages/server/dist/package.mjs
4679
- var version = "1.2.0-rc.43";
4728
+ var version = "1.2.0-rc.45";
4680
4729
 
4681
4730
  // ../../packages/server/dist/version.mjs
4682
4731
  var HOT_UPDATER_SERVER_VERSION = version;
@@ -5747,7 +5796,6 @@ var normalizeIosUdid = /* @__PURE__ */ __name((value) => {
5747
5796
  var NAME_MAX_LENGTH = 100;
5748
5797
  var EMAIL_MAX_LENGTH = 320;
5749
5798
  var ISSUER_MAX_LENGTH = 64;
5750
- var ACCOUNT_SCAN_PAGE = 200;
5751
5799
  var ACCOUNT_ROW = "registry";
5752
5800
  var ERROR_MAX_LENGTH = 512;
5753
5801
  var STATUSES = [
@@ -5811,22 +5859,14 @@ var createIosDeviceApi = /* @__PURE__ */ __name((db, { now = Date.now } = {}) =>
5811
5859
  return row === null ? null : pick2(row);
5812
5860
  }, "findIosDevice");
5813
5861
  const accountOfRows = /* @__PURE__ */ __name(async () => {
5814
- let earliest = null;
5815
- for (let after2; ; ) {
5816
- const { rows } = await db.findMany("ios_devices", {
5817
- index: "all",
5818
- where: {},
5819
- order: "asc",
5820
- limit: ACCOUNT_SCAN_PAGE,
5821
- ...after2 === void 0 ? {} : { range: { gt: after2 } }
5822
- });
5823
- for (const row of rows.map(pick2)) {
5824
- if (row.apple_issuer_id === null) continue;
5825
- if (earliest === null || (row.registered_at_ms ?? 0) < (earliest.registered_at_ms ?? 0)) earliest = row;
5826
- }
5827
- if (rows.length < ACCOUNT_SCAN_PAGE) return earliest?.apple_issuer_id ?? null;
5828
- after2 = rows.at(-1).id;
5829
- }
5862
+ const { rows } = await db.findMany("ios_devices", {
5863
+ index: "byRegistration",
5864
+ where: {},
5865
+ order: "asc",
5866
+ limit: 1,
5867
+ range: { gte: 0 }
5868
+ });
5869
+ return (rows[0] === void 0 ? null : pick2(rows[0]))?.apple_issuer_id ?? null;
5830
5870
  }, "accountOfRows");
5831
5871
  return {
5832
5872
  async listIosDevices(input) {
@@ -6178,6 +6218,7 @@ var EXPORT_METHODS = /* @__PURE__ */ new Set([
6178
6218
  "enterprise"
6179
6219
  ]);
6180
6220
  var OLDER_BUILDS_PAGE = 20;
6221
+ var OLDER_BUILDS_PAGES = 5;
6181
6222
  var MARK_ATTEMPTS = 8;
6182
6223
  var BUILD_NUMBER_MAX_LENGTH = 64;
6183
6224
  var SUBMITTED_VERSION_MAX_LENGTH = 255;
@@ -6276,26 +6317,26 @@ var SIBLING_KINDS = {
6276
6317
  app: "ipa",
6277
6318
  ipa: "app"
6278
6319
  };
6279
- var isInstallTarget = /* @__PURE__ */ __name((build) => !build.is_store_build && build.submitted_to === null && (build.artifact_kind === "app" || build.artifact_kind === "ipa" && build.export_method !== null && build.export_method !== "app-store"), "isInstallTarget");
6280
- var siblingSandboxScopeKey = /* @__PURE__ */ __name((build, artifactKind) => {
6281
- const [version2, sandbox, platform, appId, urlScheme] = build.scope_key.split(":");
6282
- if (version2 !== "v1" || sandbox !== "sandbox" || platform !== build.platform || appId === void 0 || urlScheme === void 0) return null;
6283
- const target = build.fingerprint_hash === null ? {
6284
- platform: build.platform,
6320
+ var isInstallTarget = /* @__PURE__ */ __name((build2) => !build2.is_store_build && build2.submitted_to === null && (build2.artifact_kind === "app" || build2.artifact_kind === "ipa" && build2.export_method !== null && build2.export_method !== "app-store"), "isInstallTarget");
6321
+ var siblingSandboxScopeKey = /* @__PURE__ */ __name((build2, artifactKind) => {
6322
+ const [version2, sandbox, platform, appId, urlScheme] = build2.scope_key.split(":");
6323
+ if (version2 !== "v1" || sandbox !== "sandbox" || platform !== build2.platform || appId === void 0 || urlScheme === void 0) return null;
6324
+ const target = build2.fingerprint_hash === null ? {
6325
+ platform: build2.platform,
6285
6326
  fingerprintHash: null,
6286
- appVersion: build.app_version ?? ""
6327
+ appVersion: build2.app_version ?? ""
6287
6328
  } : {
6288
- platform: build.platform,
6289
- fingerprintHash: build.fingerprint_hash,
6329
+ platform: build2.platform,
6330
+ fingerprintHash: build2.fingerprint_hash,
6290
6331
  appVersion: null
6291
6332
  };
6292
6333
  try {
6293
6334
  return sandboxScopeKey(target, {
6294
6335
  appId,
6295
6336
  urlScheme,
6296
- artifactKind: build.artifact_kind,
6297
- distribution: registeredDistribution(build.artifact_kind, build.export_method)
6298
- }) === build.scope_key ? sandboxScopeKey(target, {
6337
+ artifactKind: build2.artifact_kind,
6338
+ distribution: registeredDistribution(build2.artifact_kind, build2.export_method)
6339
+ }) === build2.scope_key ? sandboxScopeKey(target, {
6299
6340
  appId,
6300
6341
  urlScheme,
6301
6342
  artifactKind,
@@ -6368,6 +6409,10 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6368
6409
  const row = await db.findOne("native_builds", { id });
6369
6410
  return row === null ? null : pick3(row);
6370
6411
  },
6412
+ async findNativeBuildByBuiltInBundle(bundleId) {
6413
+ const row = await db.findOne("native_builds", { min_bundle_id: bundleId });
6414
+ return row === null ? null : pick3(row);
6415
+ },
6371
6416
  async findNativeBuild(scope, options) {
6372
6417
  const scopeKey = nativeBuildScopeKey(scope);
6373
6418
  const buildKey = options?.buildKey;
@@ -6379,11 +6424,11 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6379
6424
  const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
6380
6425
  return marked === null || !ofKind(marked) ? null : pick3(marked);
6381
6426
  }
6382
- const read = /* @__PURE__ */ __name((limit, before) => {
6427
+ const read = /* @__PURE__ */ __name((limit, before2) => {
6383
6428
  const page2 = {
6384
6429
  order: "desc",
6385
6430
  limit,
6386
- ...before === void 0 ? {} : { range: { lt: before } }
6431
+ ...before2 === void 0 ? {} : { range: { lt: before2 } }
6387
6432
  };
6388
6433
  return buildKey !== void 0 ? db.findMany("native_builds", {
6389
6434
  index: "byBuildKey",
@@ -6416,7 +6461,8 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6416
6461
  }).then(({ rows: [row] }) => row?.artifact_kind === artifactKind ? pick3(row) : void 0) : void 0);
6417
6462
  if (newest === void 0 || !ofKind(newest)) return null;
6418
6463
  if (bundleId === void 0 || newest.min_bundle_id < bundleId) return newest;
6419
- for (let before = newest.id; ; ) {
6464
+ let before = newest.id;
6465
+ for (let page2 = 0; page2 < OLDER_BUILDS_PAGES; page2 += 1) {
6420
6466
  const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
6421
6467
  const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
6422
6468
  if (usable !== void 0) return ofKind(usable) ? pick3(usable) : null;
@@ -6424,11 +6470,12 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6424
6470
  if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
6425
6471
  before = last.id;
6426
6472
  }
6473
+ return null;
6427
6474
  },
6428
- async findNativeBuildSibling(build) {
6429
- const artifactKind = SIBLING_KINDS[build.artifact_kind];
6430
- if (build.platform !== "ios" || !build.is_sandbox || artifactKind === void 0 || !isInstallTarget(build)) return null;
6431
- const scopeKey = siblingSandboxScopeKey(build, artifactKind);
6475
+ async findNativeBuildSibling(build2) {
6476
+ const artifactKind = SIBLING_KINDS[build2.artifact_kind];
6477
+ if (build2.platform !== "ios" || !build2.is_sandbox || artifactKind === void 0 || !isInstallTarget(build2)) return null;
6478
+ const scopeKey = siblingSandboxScopeKey(build2, artifactKind);
6432
6479
  if (scopeKey === null) return null;
6433
6480
  const { rows } = await db.findMany("native_builds", {
6434
6481
  index: "byScope",
@@ -6444,9 +6491,9 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6444
6491
  return db.transaction(async (tx) => {
6445
6492
  const row = await tx.findOne("native_builds", { id });
6446
6493
  if (row === null) return null;
6447
- const build = pick3(row);
6448
- if (!NATIVE_BUILD_SUBMISSION_DESTINATIONS[build.platform].includes(destination)) throw new NativeBuildInputError(`Invalid native build submission: an ${build.platform} build is submitted to ${NATIVE_BUILD_SUBMISSION_DESTINATIONS[build.platform].join(" or ")}, not ${destination}.`);
6449
- if (build.is_sandbox && destination !== "testflight" && destination !== "play-internal") throw new NativeBuildInputError("A sandbox build can submit only to TestFlight or Play internal testing.");
6494
+ const build2 = pick3(row);
6495
+ if (!NATIVE_BUILD_SUBMISSION_DESTINATIONS[build2.platform].includes(destination)) throw new NativeBuildInputError(`Invalid native build submission: an ${build2.platform} build is submitted to ${NATIVE_BUILD_SUBMISSION_DESTINATIONS[build2.platform].join(" or ")}, not ${destination}.`);
6496
+ if (build2.is_sandbox && destination !== "testflight" && destination !== "play-internal") throw new NativeBuildInputError("A sandbox build can submit only to TestFlight or Play internal testing.");
6450
6497
  const set = {
6451
6498
  submitted_to: destination,
6452
6499
  submitted_at_ms: now(),
@@ -6454,7 +6501,7 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6454
6501
  };
6455
6502
  tx.update("native_builds", row, set);
6456
6503
  return {
6457
- ...build,
6504
+ ...build2,
6458
6505
  ...set
6459
6506
  };
6460
6507
  });
@@ -6464,28 +6511,28 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6464
6511
  return await db.transaction(async (tx) => {
6465
6512
  const row = await tx.findOne("native_builds", { id });
6466
6513
  if (row === null) return null;
6467
- const build = pick3(row);
6514
+ const build2 = pick3(row);
6468
6515
  if (!storeBuild) {
6469
- if (build.is_store_build) tx.update("native_builds", row, { is_store_build: false });
6516
+ if (build2.is_store_build) tx.update("native_builds", row, { is_store_build: false });
6470
6517
  return {
6471
6518
  nativeBuild: {
6472
- ...build,
6519
+ ...build2,
6473
6520
  is_store_build: false
6474
6521
  },
6475
6522
  previous: null
6476
6523
  };
6477
6524
  }
6478
- if (build.is_sandbox) throw new NativeBuildInputError("A sandbox build can't be the store build.");
6479
- if (build.is_store_build) return {
6480
- nativeBuild: build,
6525
+ if (build2.is_sandbox) throw new NativeBuildInputError("A sandbox build can't be the store build.");
6526
+ if (build2.is_store_build) return {
6527
+ nativeBuild: build2,
6481
6528
  previous: null
6482
6529
  };
6483
- const holder = await tx.findOne("native_builds", { store_build_scope_key: build.scope_key });
6530
+ const holder = await tx.findOne("native_builds", { store_build_scope_key: build2.scope_key });
6484
6531
  if (holder !== null) tx.update("native_builds", holder, { is_store_build: false });
6485
6532
  tx.update("native_builds", row, { is_store_build: true });
6486
6533
  return {
6487
6534
  nativeBuild: {
6488
- ...build,
6535
+ ...build2,
6489
6536
  is_store_build: true
6490
6537
  },
6491
6538
  previous: holder === null ? null : {
@@ -7583,10 +7630,11 @@ var createAdminRouteHandlers = /* @__PURE__ */ __name(() => ({
7583
7630
  return json({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
7584
7631
  }),
7585
7632
  findNativeBuildSibling: onCore(async (core, _request, params) => {
7586
- const build = await core.getNativeBuild(requireRouteParam(params, "id"));
7587
- return json({ data: build === null ? null : await core.findNativeBuildSibling(build) });
7633
+ const build2 = await core.getNativeBuild(requireRouteParam(params, "id"));
7634
+ return json({ data: build2 === null ? null : await core.findNativeBuildSibling(build2) });
7588
7635
  }),
7589
7636
  getNativeBuild: onCore(async (core, _request, params) => json({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
7637
+ findNativeBuildByBuiltInBundle: onCore(async (core, _request, params) => json({ data: await core.findNativeBuildByBuiltInBundle(requireRouteParam(params, "bundleId")) })),
7590
7638
  listNativeBuilds: onCore(async (core, request) => {
7591
7639
  const url = new URL(request.url);
7592
7640
  const input = keyset(url);
@@ -7816,6 +7864,11 @@ var ADMIN_ROUTES = [
7816
7864
  path: "/native-builds/latest",
7817
7865
  handler: "findNativeBuild"
7818
7866
  },
7867
+ {
7868
+ method: "GET",
7869
+ path: "/native-builds/built-in/:bundleId",
7870
+ handler: "findNativeBuildByBuiltInBundle"
7871
+ },
7819
7872
  {
7820
7873
  method: "GET",
7821
7874
  path: "/native-builds/:id/sibling",
@@ -10388,14 +10441,14 @@ var changeOf = /* @__PURE__ */ __name((event, head) => {
10388
10441
  };
10389
10442
  if (!isNewer(event, head)) return null;
10390
10443
  const running = runningOf(head);
10391
- const build = minBundleIdOf(event);
10444
+ const build2 = minBundleIdOf(event);
10392
10445
  const headBuild = minBundleIdOf(head);
10393
10446
  const kinds = [];
10394
10447
  if (event.to_bundle_id !== running.bundle_id) kinds.push("bundle");
10395
10448
  if (event.to_release_id !== running.release_id) kinds.push("release");
10396
10449
  if (event.app_version !== head.app_version) kinds.push("app_version");
10397
10450
  if (event.channel !== head.channel) kinds.push("channel");
10398
- if (build !== void 0 && headBuild !== void 0 && build !== headBuild) kinds.push("native_build");
10451
+ if (build2 !== void 0 && headBuild !== void 0 && build2 !== headBuild) kinds.push("native_build");
10399
10452
  return kinds.length === 0 ? null : {
10400
10453
  kinds,
10401
10454
  previous: {