@hot-updater/cloudflare 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.
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.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",
@@ -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/cli-tools": "1.2.0-rc.44",
56
- "@hot-updater/plugin-core": "1.2.0-rc.44",
57
- "@hot-updater/protocol": "1.2.0-rc.44",
58
- "@hot-updater/server": "1.2.0-rc.44",
59
- "@hot-updater/storage-s3": "1.2.0-rc.44"
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.44"
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"));
@@ -1 +1 @@
1
- This folder contains the built output assets for the worker "hot-updater" generated at 2026-11-14T13:37:26.058Z.
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
 
@@ -2732,6 +2732,10 @@ var iosDevices = defineTable({
2732
2732
  eq: ["status"],
2733
2733
  sort: ["id"]
2734
2734
  },
2735
+ byRegistration: {
2736
+ eq: [],
2737
+ sort: ["registered_at_ms"]
2738
+ },
2735
2739
  all: {
2736
2740
  eq: [],
2737
2741
  sort: ["id"]
@@ -2951,6 +2955,7 @@ var LEASE = { id: "compaction" };
2951
2955
  var LEASE_MS = 3e4;
2952
2956
  var WINDOW_MS = 6e4;
2953
2957
  var LOG_PAGE = 200;
2958
+ var SKIP_AFTER_MS = 3e5;
2954
2959
  var GROUPS = {
2955
2960
  commit: 1,
2956
2961
  read: 8,
@@ -3058,19 +3063,31 @@ var rewrite2 = /* @__PURE__ */ __name((change, key, current) => {
3058
3063
  previous: current
3059
3064
  };
3060
3065
  }, "rewrite");
3061
- var compile = /* @__PURE__ */ __name(async (adapter, changes) => {
3062
- 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);
3063
3070
  const reads = /* @__PURE__ */ new Map();
3064
3071
  changes.forEach((change, at) => {
3065
- 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);
3066
3076
  });
3067
3077
  const current = /* @__PURE__ */ new Map();
3068
- await Promise.all([...reads].map(async ([model, positions]) => {
3069
- const rows = await adapter.get(model.table, positions.map((at) => keys[at]));
3070
- 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
+ });
3071
3084
  }));
3072
- return changes.map((change, at) => current.has(at) ? rewrite2(change, keys[at], current.get(at)) : increment(change, keys[at]));
3073
- }, "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");
3074
3091
  var isOp = /* @__PURE__ */ __name((op) => op !== void 0, "isOp");
3075
3092
  var sleep = /* @__PURE__ */ __name((attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250, 5 * 2 ** attempt) * Math.random())), "sleep");
3076
3093
  var pack = /* @__PURE__ */ __name((text) => {
@@ -3135,6 +3152,9 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3135
3152
  let nextDue = 0;
3136
3153
  let compacting;
3137
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");
3138
3158
  const idOf2 = /* @__PURE__ */ __name((shard, id) => JSON.stringify([shard, id]), "idOf");
3139
3159
  const leaseOp = /* @__PURE__ */ __name((held, set) => {
3140
3160
  const next = {
@@ -3238,14 +3258,22 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3238
3258
  logs: (await Promise.all(LOG_TABLES.map(async (name, shard) => {
3239
3259
  const page2 = await engine.reads.findMany(name, {
3240
3260
  index: "oldest",
3241
- limit: LOG_PAGE
3261
+ limit: LOG_PAGE,
3262
+ ...past(shard)
3242
3263
  });
3243
3264
  more ||= page2.next !== void 0;
3244
- return (await Promise.all(page2.rows.map(async (row) => ({
3265
+ const decoded = await Promise.all(page2.rows.map(async (row) => ({
3245
3266
  shard,
3246
3267
  row,
3247
3268
  changes: await decode2(String(row.changes))
3248
- })))).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 ? [] : [{
3249
3277
  ...entry,
3250
3278
  changes
3251
3279
  }]);
@@ -3253,14 +3281,15 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3253
3281
  more
3254
3282
  };
3255
3283
  }, "readLogs");
3256
- const rowsFor = /* @__PURE__ */ __name(async (changes) => (await compile(adapter, changes)).filter(isOp), "rowsFor");
3257
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");
3258
3287
  for (let count = logs.length; count > 0; count = Math.floor(count / 2)) {
3259
3288
  const batch = logs.slice(0, count);
3260
3289
  const changes2 = mergeAll(/* @__PURE__ */ new Map(), batch.flatMap((entry) => [...entry.changes.values()]));
3261
3290
  const applied = batch.map(({ shard: shard2, row: row2 }) => [shard2, row2.id]);
3262
3291
  const lease2 = leaseOp(held, { applied: JSON.stringify(applied) });
3263
- const ops = [...await rowsFor([...changes2.values()]), lease2.op];
3292
+ const ops = [...rowsFor([...changes2.values()]), lease2.op];
3264
3293
  if (!adapter.fits(ops)) continue;
3265
3294
  for (const { shard: shard2, row: row2 } of batch) known.set(idOf2(shard2, row2.id), row2);
3266
3295
  return await commit(ops) ? {
@@ -3282,7 +3311,7 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3282
3311
  };
3283
3312
  const lease2 = leaseOp(held, {});
3284
3313
  const ops = [
3285
- ...await rowsFor(entries.slice(0, take)),
3314
+ ...rowsFor(entries.slice(0, take)),
3286
3315
  kept,
3287
3316
  lease2.op
3288
3317
  ];
@@ -3298,11 +3327,12 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3298
3327
  if (held === void 0) return;
3299
3328
  let pending = true;
3300
3329
  let clear = false;
3330
+ let carried;
3301
3331
  try {
3302
3332
  for (let group = 0; ; group += 1) {
3303
3333
  clear = await deleteApplied(held);
3304
3334
  if (!clear || !pending || group === groups) break;
3305
- const { logs, more } = await readLogs();
3335
+ const { logs, more } = carried ?? await readLogs();
3306
3336
  if (logs.length === 0) {
3307
3337
  pending = false;
3308
3338
  break;
@@ -3310,6 +3340,11 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3310
3340
  const applied = await applyGroup(held, logs);
3311
3341
  if (applied === void 0) break;
3312
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;
3313
3348
  pending = more || applied.count < logs.length;
3314
3349
  }
3315
3350
  } finally {
@@ -3327,9 +3362,10 @@ var createAggregateBatches = /* @__PURE__ */ __name(({ engine, adapter, schema,
3327
3362
  compacting = void 0;
3328
3363
  }), "compact");
3329
3364
  let checking;
3330
- 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, {
3331
3366
  index: "oldest",
3332
- limit: 1
3367
+ limit: 1,
3368
+ ...past(shard)
3333
3369
  }))).then((pages) => pages.some((page2) => page2.rows.length > 0)).finally(() => {
3334
3370
  checking = void 0;
3335
3371
  }), "hasPending");
@@ -3977,7 +4013,7 @@ var createTransactions = /* @__PURE__ */ __name(({ adapter, schema, reads, retry
3977
4013
  return {
3978
4014
  result,
3979
4015
  read,
3980
- ops: compile2(writes, read, deleted),
4016
+ ops: compile(writes, read, deleted),
3981
4017
  aggregates: [...aggregates.values()]
3982
4018
  };
3983
4019
  } catch (error) {
@@ -3986,7 +4022,7 @@ var createTransactions = /* @__PURE__ */ __name(({ adapter, schema, reads, retry
3986
4022
  open = false;
3987
4023
  }
3988
4024
  }, "attempt");
3989
- const compile2 = /* @__PURE__ */ __name((writes, read, deleted) => {
4025
+ const compile = /* @__PURE__ */ __name((writes, read, deleted) => {
3990
4026
  const toOp = /* @__PURE__ */ __name((id) => {
3991
4027
  const { model, key, type, row, read: previous } = writes.get(id);
3992
4028
  const { table } = model;
@@ -4488,7 +4524,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4488
4524
  const quote = /* @__PURE__ */ __name((name) => quoteSql(dialect, name), "quote");
4489
4525
  const tableOf = /* @__PURE__ */ __name((table, index) => quote(`${tablePrefix}${table.name}${index ? `__${index.name}` : ""}`), "tableOf");
4490
4526
  const version2 = quote("_v");
4491
- const sql = /* @__PURE__ */ __name((build) => {
4527
+ const sql = /* @__PURE__ */ __name((build2) => {
4492
4528
  const params = [];
4493
4529
  const bind = /* @__PURE__ */ __name((value, column) => {
4494
4530
  const json4 = column?.multi || column?.type === "json";
@@ -4496,7 +4532,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4496
4532
  return postgres ? `$${params.length}${json4 ? "::jsonb" : ""}` : "?";
4497
4533
  }, "bind");
4498
4534
  return {
4499
- sql: build(bind),
4535
+ sql: build2(bind),
4500
4536
  params
4501
4537
  };
4502
4538
  }, "sql");
@@ -4511,7 +4547,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4511
4547
  }
4512
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 ")})`;
4513
4549
  }, "compare");
4514
- const compile2 = /* @__PURE__ */ __name((op, when) => {
4550
+ const compile = /* @__PURE__ */ __name((op, when) => {
4515
4551
  const { table } = op;
4516
4552
  const name = tableOf(table);
4517
4553
  const where = /* @__PURE__ */ __name((bind, key, v) => `${keyMatch(bind, table, key)}${v === void 0 ? "" : ` AND ${version2} = ${bind(v)}`}${when ? ` AND ${when(bind)}` : ""}`, "where");
@@ -4585,7 +4621,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4585
4621
  return [
4586
4622
  sql((bind) => `INSERT INTO ${guard} (${idColumn}, ${failed2}) VALUES (${bind(id)}, NULL)`),
4587
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)}`)]),
4588
- ...ops.flatMap((op) => compile2(op, when)),
4624
+ ...ops.flatMap((op) => compile(op, when)),
4589
4625
  sql((bind) => `SELECT ${failed2} FROM ${guard} WHERE ${byId(bind)}`),
4590
4626
  sql((bind) => `DELETE FROM ${guard} WHERE ${byId(bind)}`)
4591
4627
  ];
@@ -4639,7 +4675,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4639
4675
  }
4640
4676
  await executor.transaction(async (connection) => {
4641
4677
  for (const [position, op] of ops.entries()) {
4642
- const [first, ...rest] = compile2(op);
4678
+ const [first, ...rest] = compile(op);
4643
4679
  let result;
4644
4680
  try {
4645
4681
  result = await connection.execute(first);
@@ -4689,7 +4725,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
4689
4725
  }, "createSqlAdapter");
4690
4726
 
4691
4727
  // ../../packages/server/dist/package.mjs
4692
- var version = "1.2.0-rc.44";
4728
+ var version = "1.2.0-rc.45";
4693
4729
 
4694
4730
  // ../../packages/server/dist/version.mjs
4695
4731
  var HOT_UPDATER_SERVER_VERSION = version;
@@ -5760,7 +5796,6 @@ var normalizeIosUdid = /* @__PURE__ */ __name((value) => {
5760
5796
  var NAME_MAX_LENGTH = 100;
5761
5797
  var EMAIL_MAX_LENGTH = 320;
5762
5798
  var ISSUER_MAX_LENGTH = 64;
5763
- var ACCOUNT_SCAN_PAGE = 200;
5764
5799
  var ACCOUNT_ROW = "registry";
5765
5800
  var ERROR_MAX_LENGTH = 512;
5766
5801
  var STATUSES = [
@@ -5824,22 +5859,14 @@ var createIosDeviceApi = /* @__PURE__ */ __name((db, { now = Date.now } = {}) =>
5824
5859
  return row === null ? null : pick2(row);
5825
5860
  }, "findIosDevice");
5826
5861
  const accountOfRows = /* @__PURE__ */ __name(async () => {
5827
- let earliest = null;
5828
- for (let after2; ; ) {
5829
- const { rows } = await db.findMany("ios_devices", {
5830
- index: "all",
5831
- where: {},
5832
- order: "asc",
5833
- limit: ACCOUNT_SCAN_PAGE,
5834
- ...after2 === void 0 ? {} : { range: { gt: after2 } }
5835
- });
5836
- for (const row of rows.map(pick2)) {
5837
- if (row.apple_issuer_id === null) continue;
5838
- if (earliest === null || (row.registered_at_ms ?? 0) < (earliest.registered_at_ms ?? 0)) earliest = row;
5839
- }
5840
- if (rows.length < ACCOUNT_SCAN_PAGE) return earliest?.apple_issuer_id ?? null;
5841
- after2 = rows.at(-1).id;
5842
- }
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;
5843
5870
  }, "accountOfRows");
5844
5871
  return {
5845
5872
  async listIosDevices(input) {
@@ -6191,6 +6218,7 @@ var EXPORT_METHODS = /* @__PURE__ */ new Set([
6191
6218
  "enterprise"
6192
6219
  ]);
6193
6220
  var OLDER_BUILDS_PAGE = 20;
6221
+ var OLDER_BUILDS_PAGES = 5;
6194
6222
  var MARK_ATTEMPTS = 8;
6195
6223
  var BUILD_NUMBER_MAX_LENGTH = 64;
6196
6224
  var SUBMITTED_VERSION_MAX_LENGTH = 255;
@@ -6289,26 +6317,26 @@ var SIBLING_KINDS = {
6289
6317
  app: "ipa",
6290
6318
  ipa: "app"
6291
6319
  };
6292
- 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");
6293
- var siblingSandboxScopeKey = /* @__PURE__ */ __name((build, artifactKind) => {
6294
- const [version2, sandbox, platform, appId, urlScheme] = build.scope_key.split(":");
6295
- if (version2 !== "v1" || sandbox !== "sandbox" || platform !== build.platform || appId === void 0 || urlScheme === void 0) return null;
6296
- const target = build.fingerprint_hash === null ? {
6297
- 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,
6298
6326
  fingerprintHash: null,
6299
- appVersion: build.app_version ?? ""
6327
+ appVersion: build2.app_version ?? ""
6300
6328
  } : {
6301
- platform: build.platform,
6302
- fingerprintHash: build.fingerprint_hash,
6329
+ platform: build2.platform,
6330
+ fingerprintHash: build2.fingerprint_hash,
6303
6331
  appVersion: null
6304
6332
  };
6305
6333
  try {
6306
6334
  return sandboxScopeKey(target, {
6307
6335
  appId,
6308
6336
  urlScheme,
6309
- artifactKind: build.artifact_kind,
6310
- distribution: registeredDistribution(build.artifact_kind, build.export_method)
6311
- }) === 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, {
6312
6340
  appId,
6313
6341
  urlScheme,
6314
6342
  artifactKind,
@@ -6381,6 +6409,10 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6381
6409
  const row = await db.findOne("native_builds", { id });
6382
6410
  return row === null ? null : pick3(row);
6383
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
+ },
6384
6416
  async findNativeBuild(scope, options) {
6385
6417
  const scopeKey = nativeBuildScopeKey(scope);
6386
6418
  const buildKey = options?.buildKey;
@@ -6392,11 +6424,11 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6392
6424
  const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
6393
6425
  return marked === null || !ofKind(marked) ? null : pick3(marked);
6394
6426
  }
6395
- const read = /* @__PURE__ */ __name((limit, before) => {
6427
+ const read = /* @__PURE__ */ __name((limit, before2) => {
6396
6428
  const page2 = {
6397
6429
  order: "desc",
6398
6430
  limit,
6399
- ...before === void 0 ? {} : { range: { lt: before } }
6431
+ ...before2 === void 0 ? {} : { range: { lt: before2 } }
6400
6432
  };
6401
6433
  return buildKey !== void 0 ? db.findMany("native_builds", {
6402
6434
  index: "byBuildKey",
@@ -6429,7 +6461,8 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6429
6461
  }).then(({ rows: [row] }) => row?.artifact_kind === artifactKind ? pick3(row) : void 0) : void 0);
6430
6462
  if (newest === void 0 || !ofKind(newest)) return null;
6431
6463
  if (bundleId === void 0 || newest.min_bundle_id < bundleId) return newest;
6432
- for (let before = newest.id; ; ) {
6464
+ let before = newest.id;
6465
+ for (let page2 = 0; page2 < OLDER_BUILDS_PAGES; page2 += 1) {
6433
6466
  const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
6434
6467
  const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
6435
6468
  if (usable !== void 0) return ofKind(usable) ? pick3(usable) : null;
@@ -6437,11 +6470,12 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6437
6470
  if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
6438
6471
  before = last.id;
6439
6472
  }
6473
+ return null;
6440
6474
  },
6441
- async findNativeBuildSibling(build) {
6442
- const artifactKind = SIBLING_KINDS[build.artifact_kind];
6443
- if (build.platform !== "ios" || !build.is_sandbox || artifactKind === void 0 || !isInstallTarget(build)) return null;
6444
- 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);
6445
6479
  if (scopeKey === null) return null;
6446
6480
  const { rows } = await db.findMany("native_builds", {
6447
6481
  index: "byScope",
@@ -6457,9 +6491,9 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6457
6491
  return db.transaction(async (tx) => {
6458
6492
  const row = await tx.findOne("native_builds", { id });
6459
6493
  if (row === null) return null;
6460
- const build = pick3(row);
6461
- 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}.`);
6462
- 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.");
6463
6497
  const set = {
6464
6498
  submitted_to: destination,
6465
6499
  submitted_at_ms: now(),
@@ -6467,7 +6501,7 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6467
6501
  };
6468
6502
  tx.update("native_builds", row, set);
6469
6503
  return {
6470
- ...build,
6504
+ ...build2,
6471
6505
  ...set
6472
6506
  };
6473
6507
  });
@@ -6477,28 +6511,28 @@ var createNativeBuildApi = /* @__PURE__ */ __name((db, { now = Date.now } = {})
6477
6511
  return await db.transaction(async (tx) => {
6478
6512
  const row = await tx.findOne("native_builds", { id });
6479
6513
  if (row === null) return null;
6480
- const build = pick3(row);
6514
+ const build2 = pick3(row);
6481
6515
  if (!storeBuild) {
6482
- 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 });
6483
6517
  return {
6484
6518
  nativeBuild: {
6485
- ...build,
6519
+ ...build2,
6486
6520
  is_store_build: false
6487
6521
  },
6488
6522
  previous: null
6489
6523
  };
6490
6524
  }
6491
- if (build.is_sandbox) throw new NativeBuildInputError("A sandbox build can't be the store build.");
6492
- if (build.is_store_build) return {
6493
- 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,
6494
6528
  previous: null
6495
6529
  };
6496
- 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 });
6497
6531
  if (holder !== null) tx.update("native_builds", holder, { is_store_build: false });
6498
6532
  tx.update("native_builds", row, { is_store_build: true });
6499
6533
  return {
6500
6534
  nativeBuild: {
6501
- ...build,
6535
+ ...build2,
6502
6536
  is_store_build: true
6503
6537
  },
6504
6538
  previous: holder === null ? null : {
@@ -7596,10 +7630,11 @@ var createAdminRouteHandlers = /* @__PURE__ */ __name(() => ({
7596
7630
  return json({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
7597
7631
  }),
7598
7632
  findNativeBuildSibling: onCore(async (core, _request, params) => {
7599
- const build = await core.getNativeBuild(requireRouteParam(params, "id"));
7600
- 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) });
7601
7635
  }),
7602
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")) })),
7603
7638
  listNativeBuilds: onCore(async (core, request) => {
7604
7639
  const url = new URL(request.url);
7605
7640
  const input = keyset(url);
@@ -7829,6 +7864,11 @@ var ADMIN_ROUTES = [
7829
7864
  path: "/native-builds/latest",
7830
7865
  handler: "findNativeBuild"
7831
7866
  },
7867
+ {
7868
+ method: "GET",
7869
+ path: "/native-builds/built-in/:bundleId",
7870
+ handler: "findNativeBuildByBuiltInBundle"
7871
+ },
7832
7872
  {
7833
7873
  method: "GET",
7834
7874
  path: "/native-builds/:id/sibling",
@@ -10401,14 +10441,14 @@ var changeOf = /* @__PURE__ */ __name((event, head) => {
10401
10441
  };
10402
10442
  if (!isNewer(event, head)) return null;
10403
10443
  const running = runningOf(head);
10404
- const build = minBundleIdOf(event);
10444
+ const build2 = minBundleIdOf(event);
10405
10445
  const headBuild = minBundleIdOf(head);
10406
10446
  const kinds = [];
10407
10447
  if (event.to_bundle_id !== running.bundle_id) kinds.push("bundle");
10408
10448
  if (event.to_release_id !== running.release_id) kinds.push("release");
10409
10449
  if (event.app_version !== head.app_version) kinds.push("app_version");
10410
10450
  if (event.channel !== head.channel) kinds.push("channel");
10411
- 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");
10412
10452
  return kinds.length === 0 ? null : {
10413
10453
  kinds,
10414
10454
  previous: {