@hot-updater/azure 1.2.0-rc.57 → 1.2.0-rc.58

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.
@@ -4339,14 +4339,14 @@ function modularInverse(value, modulus) {
4339
4339
  if (r > 1) throw new Error(`No modular inverse for ${value} mod ${modulus}`);
4340
4340
  return positiveMod(t, modulus);
4341
4341
  }
4342
- function getRolloutShuffleParameters(bundleId) {
4343
- let multiplier = positiveMod(hashString(`${bundleId}:multiplier`), 997);
4342
+ function getRolloutShuffleParameters(releaseId) {
4343
+ let multiplier = positiveMod(hashString(`${releaseId}:multiplier`), 997);
4344
4344
  if (multiplier === 0) multiplier = 1;
4345
4345
  while (gcd(multiplier, NUMERIC_COHORT_SIZE) !== 1) {
4346
4346
  multiplier = positiveMod(multiplier + 1, NUMERIC_COHORT_SIZE);
4347
4347
  if (multiplier === 0) multiplier = 1;
4348
4348
  }
4349
- const offset = positiveMod(hashString(`${bundleId}:offset`), NUMERIC_COHORT_SIZE);
4349
+ const offset = positiveMod(hashString(`${releaseId}:offset`), NUMERIC_COHORT_SIZE);
4350
4350
  return {
4351
4351
  multiplier,
4352
4352
  offset,
@@ -4379,16 +4379,16 @@ function isValidCohort(cohort) {
4379
4379
  const normalized = normalizeCohortValue(cohort);
4380
4380
  return isNumericCohort(normalized) || isCustomCohort(normalized);
4381
4381
  }
4382
- function getNumericCohortRolloutPosition(bundleId, cohortValue) {
4382
+ function getNumericCohortRolloutPosition(releaseId, cohortValue) {
4383
4383
  if (cohortValue < 1 || cohortValue > 1e3) throw new Error(`Invalid numeric cohort: ${cohortValue}`);
4384
- const { offset, inverseMultiplier } = getRolloutShuffleParameters(bundleId);
4384
+ const { offset, inverseMultiplier } = getRolloutShuffleParameters(releaseId);
4385
4385
  return positiveMod(inverseMultiplier * (cohortValue - 1 - offset), NUMERIC_COHORT_SIZE);
4386
4386
  }
4387
- function getRolledOutNumericCohorts(bundleId, rolloutCohortCount) {
4387
+ function getRolledOutNumericCohorts(releaseId, rolloutCohortCount) {
4388
4388
  const normalizedRolloutCount = normalizeRolloutCohortCount(rolloutCohortCount);
4389
4389
  if (normalizedRolloutCount <= 0) return [];
4390
4390
  if (normalizedRolloutCount >= 1e3) return Array.from({ length: NUMERIC_COHORT_SIZE }, (_, index) => index + 1);
4391
- const { multiplier, offset } = getRolloutShuffleParameters(bundleId);
4391
+ const { multiplier, offset } = getRolloutShuffleParameters(releaseId);
4392
4392
  return Array.from({ length: normalizedRolloutCount }, (_, position) => positiveMod(multiplier * position + offset, NUMERIC_COHORT_SIZE)).map((zeroBasedCohort) => zeroBasedCohort + 1).sort((left, right) => left - right);
4393
4393
  }
4394
4394
  const RELEASE_CATALOG_FALLBACK_POLICY = "BUILTIN_IF_ACTIVE_INELIGIBLE";
@@ -8484,7 +8484,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
8484
8484
  };
8485
8485
  //#endregion
8486
8486
  //#region ../../packages/server/dist/version.mjs
8487
- const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.57";
8487
+ const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.58";
8488
8488
  //#endregion
8489
8489
  //#region ../../packages/server/dist/handlerVersionRoutes.mjs
8490
8490
  const createVersionRouteHandlers = (plugins = []) => {
@@ -9222,7 +9222,7 @@ const baseBundleIdsOf = (row, range, bundleId, limit) => {
9222
9222
  };
9223
9223
  //#endregion
9224
9224
  //#region ../../packages/server/dist/core/reads.mjs
9225
- const PAGE$4 = 500;
9225
+ const PAGE$5 = 500;
9226
9226
  const pick$2 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
9227
9227
  const toBundleRow = pick$2([
9228
9228
  "id",
@@ -9313,7 +9313,7 @@ const createCoreReads = (db, storage) => {
9313
9313
  const page = await db.findMany("bundle_patches", {
9314
9314
  index: "byBundle",
9315
9315
  where: { bundle_id: row.id },
9316
- limit: Math.min(count - patches.length, PAGE$4),
9316
+ limit: Math.min(count - patches.length, PAGE$5),
9317
9317
  ...cursor === void 0 ? {} : { cursor }
9318
9318
  });
9319
9319
  patches.push(...page.rows.map(toPatchRow));
@@ -9517,7 +9517,7 @@ const createCoreReads = (db, storage) => {
9517
9517
  return (await drain$1((page) => db.findMany("channels", {
9518
9518
  index: "all",
9519
9519
  where: {},
9520
- limit: PAGE$4,
9520
+ limit: PAGE$5,
9521
9521
  ...page
9522
9522
  }))).map(toChannelRow);
9523
9523
  },
@@ -9873,7 +9873,7 @@ const createLabelAllocator = (tx, used, caughtUp) => {
9873
9873
  };
9874
9874
  };
9875
9875
  const FILL_BATCH = 25;
9876
- const PAGE$3 = 500;
9876
+ const PAGE$4 = 500;
9877
9877
  const fillLabels = async (db, { channelId, platform }, { dryRun = false } = {}) => {
9878
9878
  const id = labelSequenceId(channelId, platform);
9879
9879
  let labeled = 0;
@@ -9919,7 +9919,7 @@ const fillLabels = async (db, { channelId, platform }, { dryRun = false } = {})
9919
9919
  channel_id: channelId,
9920
9920
  platform
9921
9921
  },
9922
- limit: PAGE$3,
9922
+ limit: PAGE$4,
9923
9923
  ...cursor === void 0 ? {} : { cursor }
9924
9924
  });
9925
9925
  const unlabeled = page.rows.filter((row) => typeof row.label !== "number").map((row) => row.id);
@@ -10080,7 +10080,7 @@ const pendingLabelPairs = async (db) => {
10080
10080
  };
10081
10081
  //#endregion
10082
10082
  //#region ../../packages/server/dist/core/writes.mjs
10083
- const PAGE$2 = 500;
10083
+ const PAGE$3 = 500;
10084
10084
  const countBundle = (tx, platform, delta) => {
10085
10085
  for (const key of [platform, "*"]) tx.aggregate("bundle_totals", { platform_key: key }, { bundles: delta });
10086
10086
  };
@@ -10107,7 +10107,7 @@ const replaceBundlePatches = async (tx, bundle, rows, checkNew) => {
10107
10107
  const page = await tx.findMany("bundle_patches", {
10108
10108
  index: "byBundle",
10109
10109
  where: { bundle_id: bundle.id },
10110
- limit: Math.min(count - seen, PAGE$2),
10110
+ limit: Math.min(count - seen, PAGE$3),
10111
10111
  ...cursor === void 0 ? {} : { cursor }
10112
10112
  });
10113
10113
  for (const stored of page.rows) {
@@ -10590,7 +10590,7 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
10590
10590
  });
10591
10591
  //#endregion
10592
10592
  //#region ../../packages/server/dist/core/releases.mjs
10593
- const PAGE$1 = 500;
10593
+ const PAGE$2 = 500;
10594
10594
  const fail$1 = (code, message) => {
10595
10595
  throw new ReleaseCatalogMutationError(code, message);
10596
10596
  };
@@ -10624,7 +10624,7 @@ const enabledIn = (scopeKey, cursor) => ({
10624
10624
  scope_key: scopeKey,
10625
10625
  enabled: true
10626
10626
  },
10627
- limit: PAGE$1,
10627
+ limit: PAGE$2,
10628
10628
  ...cursor === void 0 ? {} : { cursor }
10629
10629
  });
10630
10630
  const enabledReleases = (tx, scopeKey) => drainReleases((cursor) => tx.findMany("releases", enabledIn(scopeKey, cursor)));
@@ -12862,13 +12862,15 @@ const isLaunch = (row) => {
12862
12862
  const kinds = metadataOf(row).change?.kinds ?? [];
12863
12863
  return kinds.includes("bundle") && !kinds.includes("first_seen") && row.to_release_id !== null;
12864
12864
  };
12865
- const bundleRefsOf = (row) => {
12865
+ const sideRef = (key, releaseId, bundleId) => key === "release" ? releaseId ?? bundleId : bundleId;
12866
+ const bundleRefsOf = (row, key = "release") => {
12866
12867
  if (isFailedCheck(row) || isLateEvent(row)) return [];
12867
- if (row.type === "RECOVERED") return [`from:${row.from_bundle_id}`];
12868
- if (row.type === "UNCHANGED") return isLaunch(row) ? [`on:${row.to_bundle_id}`] : [];
12869
- return [`to:${row.to_bundle_id}`];
12868
+ if (row.type === "RECOVERED") return [`from:${sideRef(key, row.from_release_id, row.from_bundle_id)}`];
12869
+ if (row.type === "UNCHANGED") return isLaunch(row) ? [`on:${sideRef(key, row.to_release_id, row.to_bundle_id)}`] : [];
12870
+ return [`to:${sideRef(key, row.to_release_id, row.to_bundle_id)}`];
12870
12871
  };
12871
- const bundleRefOfFilter = (filter) => filter.type === "RECOVERED" ? `from:${filter.fromBundleId}` : filter.type === "UNCHANGED" ? `on:${filter.toBundleId}` : `to:${filter.toBundleId}`;
12872
+ const outcomeRefsOf = (row, key = "release") => [...bundleRefsOf(row, key).map((ref) => [row.type, ref]), ...metadataOf(row).implied_download === true ? [["UPDATE_DOWNLOADED", row.type === "RECOVERED" ? `to:${sideRef(key, row.from_release_id, row.from_bundle_id)}` : `to:${sideRef(key, row.to_release_id, row.to_bundle_id)}`]] : []];
12873
+ const bundleRefOfFilter = (filter) => filter.type === "RECOVERED" ? `from:${filter.fromReleaseId}` : filter.type === "UNCHANGED" ? `on:${filter.toReleaseId}` : `to:${filter.toReleaseId}`;
12872
12874
  const bundleEvents = (days) => defineTable({
12873
12875
  id: {
12874
12876
  type: "string",
@@ -13298,6 +13300,70 @@ const createInsightsSchema = ({ rawDays, dailyDays } = DEFAULT_INSIGHTS_RETENTIO
13298
13300
  };
13299
13301
  createInsightsSchema();
13300
13302
  //#endregion
13303
+ //#region ../insights/dist/server/backfill.mjs
13304
+ const PAGE$1 = 500;
13305
+ const BATCH = 25;
13306
+ const sameRefs = (stored, refs) => {
13307
+ const values = Array.isArray(stored) ? stored : [];
13308
+ return values.length === refs.length && values.every((value) => refs.includes(value));
13309
+ };
13310
+ const namesArtifact = (row) => {
13311
+ const byKey = (key) => bundleRefsOf(row, key);
13312
+ return sameRefs(row.bundle_ref, byKey("artifact")) && !sameRefs(row.bundle_ref, byKey("release"));
13313
+ };
13314
+ const backfillReleaseRefs = async (db, now, { rawDays }, { dryRun = false } = {}) => {
13315
+ const today = now() - now() % DAY_MS$1;
13316
+ let events = 0;
13317
+ const move = async (candidates) => {
13318
+ if (dryRun) {
13319
+ events += candidates.length;
13320
+ return;
13321
+ }
13322
+ const moved = await rewrite(candidates).catch(async (error) => {
13323
+ if (!(error instanceof DatabaseConstraintError) || error.reason !== "too_large" || candidates.length === 1) throw error;
13324
+ const half = Math.ceil(candidates.length / 2);
13325
+ await move(candidates.slice(0, half));
13326
+ await move(candidates.slice(half));
13327
+ return 0;
13328
+ });
13329
+ events += moved;
13330
+ };
13331
+ const rewrite = (candidates) => db.transaction(async (tx) => {
13332
+ const rows = await Promise.all(candidates.map(({ id }) => tx.findOne("bundle_events", { id })));
13333
+ let moved = 0;
13334
+ for (const row of rows) {
13335
+ if (row === null || !namesArtifact(row)) continue;
13336
+ tx.update("bundle_events", row, {});
13337
+ const outcome = (ref, delta) => tx.aggregate("insights_outcomes", {
13338
+ platform: row.platform,
13339
+ channel: row.channel,
13340
+ type: ref[0],
13341
+ bundle_ref: ref[1],
13342
+ bucket_start_ms: row.received_at_ms - row.received_at_ms % HOUR_MS$1
13343
+ }, { events: delta }, { shardBy: row.install_id });
13344
+ for (const ref of outcomeRefsOf(row, "artifact")) outcome(ref, -1);
13345
+ for (const ref of outcomeRefsOf(row, "release")) outcome(ref, 1);
13346
+ moved += 1;
13347
+ }
13348
+ return moved;
13349
+ });
13350
+ for (let day = today - rawDays * DAY_MS$1; day <= today; day += DAY_MS$1) {
13351
+ let cursor;
13352
+ do {
13353
+ const page = await db.findMany("bundle_events", {
13354
+ index: "byDay",
13355
+ where: { day },
13356
+ limit: PAGE$1,
13357
+ ...cursor === void 0 ? {} : { cursor }
13358
+ });
13359
+ const stale = page.rows.filter(namesArtifact);
13360
+ for (let start = 0; start < stale.length; start += BATCH) await move(stale.slice(start, start + BATCH));
13361
+ cursor = page.next;
13362
+ } while (cursor !== void 0);
13363
+ }
13364
+ return { events };
13365
+ };
13366
+ //#endregion
13301
13367
  //#region ../insights/dist/server/eventRow.mjs
13302
13368
  const CHANGE_KINDS = /* @__PURE__ */ new Set([
13303
13369
  "first_seen",
@@ -13375,7 +13441,7 @@ const isBundleFilter = (value, withKind = false) => {
13375
13441
  "type",
13376
13442
  ...withKind ? ["kind"] : []
13377
13443
  ];
13378
- return value.type === "RECOVERED" ? isText$1(value.fromBundleId) && hasOnlyKeys(value, [...keys, "fromBundleId"]) : (value.type === "UPDATE_DOWNLOADED" || value.type === "UPDATE_APPLIED" || value.type === "UPDATE_FAILED" || value.type === "UNCHANGED") && isText$1(value.toBundleId) && hasOnlyKeys(value, [...keys, "toBundleId"]);
13444
+ return value.type === "RECOVERED" ? isText$1(value.fromReleaseId) && hasOnlyKeys(value, [...keys, "fromReleaseId"]) : (value.type === "UPDATE_DOWNLOADED" || value.type === "UPDATE_APPLIED" || value.type === "UPDATE_FAILED" || value.type === "UNCHANGED") && isText$1(value.toReleaseId) && hasOnlyKeys(value, [...keys, "toReleaseId"]);
13379
13445
  };
13380
13446
  const isEventFilter = (value) => {
13381
13447
  if (!isRecord$3(value)) return false;
@@ -13470,20 +13536,24 @@ const createValidatedInsightsModel = (model) => ({
13470
13536
  if (!isRecord$3(input) || !hasOnlyKeys(input, [
13471
13537
  "platform",
13472
13538
  "channel",
13473
- "sinceMs",
13474
- "bundle"
13475
- ]) || !hasScope(input) || !isTimestamp(input.sinceMs) || input.bundle !== void 0 && (!Array.isArray(input.bundle) || input.bundle.length < 1 || input.bundle.length > 2 || input.bundle.some((bundle) => !isRecord$3(bundle) || !hasOnlyKeys(bundle, [
13476
- "field",
13477
- "value",
13478
- "types"
13479
- ]) || bundle.field !== "from_bundle_id" && bundle.field !== "to_bundle_id" || !isText$1(bundle.value) || !Array.isArray(bundle.types) || bundle.types.length === 0 || bundle.types.some((type) => ![
13480
- "UNCHANGED",
13481
- "UPDATE_DOWNLOADED",
13482
- "UPDATE_APPLIED",
13483
- "RECOVERED"
13484
- ].includes(type))))) invalidQuery();
13539
+ "sinceMs"
13540
+ ]) || !hasScope(input) || !isTimestamp(input.sinceMs)) invalidQuery();
13485
13541
  return validateCount(await model.countLatestEvents(input));
13486
13542
  },
13543
+ async countReleaseInstallations(input) {
13544
+ if (!isRecord$3(input) || !hasOnlyKeys(input, [
13545
+ "platform",
13546
+ "channel",
13547
+ "sinceMs",
13548
+ "releaseId"
13549
+ ]) || !hasScope(input) || !isTimestamp(input.sinceMs) || !isText$1(input.releaseId)) invalidQuery();
13550
+ const counts = await model.countReleaseInstallations(input);
13551
+ if (!isRecord$3(counts) || !hasOnlyKeys(counts, ["installations", "release"])) invalidResult();
13552
+ return {
13553
+ installations: validateCount(counts.installations),
13554
+ release: validateCount(counts.release)
13555
+ };
13556
+ },
13487
13557
  async countEvents(input) {
13488
13558
  if (!isRecord$3(input) || !hasOnlyKeys(input, [
13489
13559
  "filter",
@@ -13536,6 +13606,7 @@ const createInsightsModel = (api) => createValidatedInsightsModel({
13536
13606
  listEvents: api.listEvents,
13537
13607
  findLatestEvents: api.findLatestEvents,
13538
13608
  countLatestEvents: api.countLatestEvents,
13609
+ countReleaseInstallations: api.countReleaseInstallations,
13539
13610
  countEvents: api.countEvents,
13540
13611
  countEventSeries: api.countEventSeries,
13541
13612
  getReleaseActivity: api.getReleaseActivity,
@@ -13904,27 +13975,27 @@ const readScope$1 = (input) => {
13904
13975
  };
13905
13976
  const bundleFilter = (input) => {
13906
13977
  const scope = readScope$1(input);
13907
- const bundleId = requireString(input.bundleId, "bundle ID", MAX_EVENT_ID_LENGTH);
13978
+ const releaseId = requireString(input.releaseId, "bundle ID", MAX_EVENT_ID_LENGTH);
13908
13979
  switch (input.outcome) {
13909
13980
  case "downloaded": return {
13910
13981
  ...scope,
13911
13982
  type: "UPDATE_DOWNLOADED",
13912
- toBundleId: bundleId
13983
+ toReleaseId: releaseId
13913
13984
  };
13914
13985
  case "applied": return {
13915
13986
  ...scope,
13916
13987
  type: "UPDATE_APPLIED",
13917
- toBundleId: bundleId
13988
+ toReleaseId: releaseId
13918
13989
  };
13919
13990
  case "recovered": return {
13920
13991
  ...scope,
13921
13992
  type: "RECOVERED",
13922
- fromBundleId: bundleId
13993
+ fromReleaseId: releaseId
13923
13994
  };
13924
13995
  case "failed": return {
13925
13996
  ...scope,
13926
13997
  type: "UPDATE_FAILED",
13927
- toBundleId: bundleId
13998
+ toReleaseId: releaseId
13928
13999
  };
13929
14000
  default: throw new InsightsBadRequestError("Invalid Insights outcome.");
13930
14001
  }
@@ -13934,7 +14005,7 @@ const sameFilter = (left, right) => {
13934
14005
  switch (right.kind) {
13935
14006
  case "all": return true;
13936
14007
  case "installationMovement": return left.installId === right.installId;
13937
- case "bundle": return left.platform === right.platform && left.channel === right.channel && left.type === right.type && (right.type === "RECOVERED" ? left.fromBundleId === right.fromBundleId : left.toBundleId === right.toBundleId);
14008
+ case "bundle": return left.platform === right.platform && left.channel === right.channel && left.type === right.type && (right.type === "RECOVERED" ? left.fromReleaseId === right.fromReleaseId : left.toReleaseId === right.toReleaseId);
13938
14009
  }
13939
14010
  };
13940
14011
  const readEventCursor = (value, filter) => {
@@ -13971,7 +14042,7 @@ const assertEventRows = (rows, input) => {
13971
14042
  for (let index = 0; index < rows.length; index += 1) {
13972
14043
  const row = rows[index];
13973
14044
  const previous = rows[index - 1];
13974
- if (!row || typeof row.id !== "string" || !isUUIDv7(row.id) || !Number.isSafeInteger(row.received_at_ms) || row.received_at_ms >= input.beforeReceivedAtMs || row.received_at_ms < input.sinceMs || previous !== void 0 && compareEventNewest(previous, row) >= 0 || input.after !== void 0 && !isAfterEventCursor(row, input.after) || input.filter.kind === "installationMovement" && (row.install_id !== input.filter.installId || !isInsightsMovementEvent(row)) || input.filter.kind === "bundle" && (row.platform !== input.filter.platform || row.channel !== input.filter.channel || row.type !== input.filter.type || (input.filter.type === "RECOVERED" ? row.from_bundle_id !== input.filter.fromBundleId : row.to_bundle_id !== input.filter.toBundleId))) throw new Error("Insights database returned invalid event rows.");
14045
+ if (!row || typeof row.id !== "string" || !isUUIDv7(row.id) || !Number.isSafeInteger(row.received_at_ms) || row.received_at_ms >= input.beforeReceivedAtMs || row.received_at_ms < input.sinceMs || previous !== void 0 && compareEventNewest(previous, row) >= 0 || input.after !== void 0 && !isAfterEventCursor(row, input.after) || input.filter.kind === "installationMovement" && (row.install_id !== input.filter.installId || !isInsightsMovementEvent(row)) || input.filter.kind === "bundle" && (row.platform !== input.filter.platform || row.channel !== input.filter.channel || row.type !== input.filter.type || (input.filter.type === "RECOVERED" ? (row.from_release_id ?? row.from_bundle_id) !== input.filter.fromReleaseId : (row.to_release_id ?? row.to_bundle_id) !== input.filter.toReleaseId))) throw new Error("Insights database returned invalid event rows.");
13975
14046
  }
13976
14047
  };
13977
14048
  const toFailure = (failure) => ({
@@ -14010,6 +14081,7 @@ const eventDetails = ({ type, metadata }) => ({
14010
14081
  ...metadata.implied_download === true ? { impliedDownload: true } : {}
14011
14082
  });
14012
14083
  const toEventHistoryRow = (row) => ({
14084
+ ...row.from_release_id == null ? {} : { fromReleaseId: row.from_release_id },
14013
14085
  ...row.to_release_id == null ? {} : { toReleaseId: row.to_release_id },
14014
14086
  ...row.metadata.sdk_version == null ? {} : { sdkVersion: row.metadata.sdk_version },
14015
14087
  ...row.metadata.min_bundle_id === void 0 ? {} : { minBundleId: row.metadata.min_bundle_id },
@@ -14034,6 +14106,7 @@ const toInstallationRow = (row) => ({
14034
14106
  cohort: row.metadata.cohort,
14035
14107
  installId: row.install_id,
14036
14108
  lastKnownBundleId: row.type === "UPDATE_DOWNLOADED" ? row.from_bundle_id : row.to_bundle_id,
14109
+ lastKnownReleaseId: row.type === "UPDATE_DOWNLOADED" ? row.from_release_id : row.to_release_id,
14037
14110
  pendingBundleId: row.type === "UPDATE_DOWNLOADED" ? row.to_bundle_id : null,
14038
14111
  pendingReleaseId: row.type === "UPDATE_DOWNLOADED" ? row.to_release_id : null,
14039
14112
  latestStatus: row.type,
@@ -14156,46 +14229,33 @@ const createInsightsProvider = (model) => Object.freeze({
14156
14229
  measuredAtMs: Date.now()
14157
14230
  };
14158
14231
  };
14159
- const bundleId = input.bundleId === void 0 ? void 0 : requireString(input.bundleId, "bundle ID", MAX_EVENT_ID_LENGTH);
14160
- const reporting = measure(model.countLatestEvents({
14161
- ...scope,
14162
- sinceMs
14163
- }));
14164
- if (bundleId === void 0) return {
14232
+ const releaseId = input.releaseId === void 0 ? void 0 : requireString(input.releaseId, "bundle ID", MAX_EVENT_ID_LENGTH);
14233
+ if (releaseId === void 0) return {
14165
14234
  ...scope,
14166
14235
  window,
14167
14236
  sinceMs,
14168
14237
  beforeReceivedAtMs,
14169
- reportingInstallations: await reporting
14238
+ reportingInstallations: await measure(model.countLatestEvents({
14239
+ ...scope,
14240
+ sinceMs
14241
+ }))
14170
14242
  };
14243
+ const installations = model.countReleaseInstallations({
14244
+ ...scope,
14245
+ sinceMs,
14246
+ releaseId
14247
+ }).then(async (counts) => [await measure(Promise.resolve(counts.installations)), await measure(Promise.resolve(counts.release))]);
14171
14248
  const countOutcome = (outcome) => measure(model.countEvents({
14172
14249
  filter: bundleFilter({
14173
14250
  ...scope,
14174
- bundleId,
14251
+ releaseId,
14175
14252
  outcome
14176
14253
  }),
14177
14254
  sinceMs,
14178
14255
  beforeReceivedAtMs
14179
14256
  }));
14180
- const [reportingInstallations, bundleInstallations, downloadedReports, appliedReports, recoveredReports, failedReports] = await Promise.all([
14181
- reporting,
14182
- measure(model.countLatestEvents({
14183
- ...scope,
14184
- sinceMs,
14185
- bundle: [{
14186
- field: "from_bundle_id",
14187
- value: bundleId,
14188
- types: ["UPDATE_DOWNLOADED"]
14189
- }, {
14190
- field: "to_bundle_id",
14191
- value: bundleId,
14192
- types: [
14193
- "UNCHANGED",
14194
- "UPDATE_APPLIED",
14195
- "RECOVERED"
14196
- ]
14197
- }]
14198
- })),
14257
+ const [[reportingInstallations, bundleInstallations], downloadedReports, appliedReports, recoveredReports, failedReports] = await Promise.all([
14258
+ installations,
14199
14259
  countOutcome("downloaded"),
14200
14260
  countOutcome("applied"),
14201
14261
  countOutcome("recovered"),
@@ -14208,7 +14268,7 @@ const createInsightsProvider = (model) => Object.freeze({
14208
14268
  beforeReceivedAtMs,
14209
14269
  reportingInstallations,
14210
14270
  bundle: {
14211
- bundleId,
14271
+ releaseId,
14212
14272
  reportingInstallations: bundleInstallations,
14213
14273
  downloadedReports,
14214
14274
  appliedReports,
@@ -14333,8 +14393,6 @@ const gaugeSlot = (head) => ({
14333
14393
  releaseId: head.type === "UPDATE_DOWNLOADED" ? head.from_release_id : head.to_release_id,
14334
14394
  builtinBundleId: runningBuiltinBundleId(head)
14335
14395
  });
14336
- const PAIR_FIELD = "from_to";
14337
- const bundlePairKey = (from, to) => insightsKey(`${from.length}:${from}${to.length}:${to}`);
14338
14396
  const countHead = (tx, head, delta) => {
14339
14397
  const { bucket, releaseId, builtinBundleId } = gaugeSlot(head);
14340
14398
  const shardBy = head.install_id;
@@ -14353,26 +14411,6 @@ const countHead = (tx, head, delta) => {
14353
14411
  builtin_bundle_id: builtinBundleId,
14354
14412
  bucket_start_ms: bucket
14355
14413
  }, { latest_installations: delta }, { shardBy });
14356
- for (const field of ["from_bundle_id", "to_bundle_id"]) {
14357
- const bundleId = head[field];
14358
- if (bundleId === null) continue;
14359
- tx.aggregate("insights_latest_by_bundle", {
14360
- platform: head.platform,
14361
- channel: head.channel,
14362
- bundle_field: field,
14363
- bundle_id: bundleId,
14364
- type: head.type,
14365
- bucket_start_ms: bucket
14366
- }, { installations: delta }, { shardBy });
14367
- }
14368
- if (head.from_bundle_id !== null) tx.aggregate("insights_latest_by_bundle", {
14369
- platform: head.platform,
14370
- channel: head.channel,
14371
- bundle_field: PAIR_FIELD,
14372
- bundle_id: bundlePairKey(head.from_bundle_id, head.to_bundle_id),
14373
- type: head.type,
14374
- bucket_start_ms: bucket
14375
- }, { installations: delta }, { shardBy });
14376
14414
  };
14377
14415
  const PERIOD_MODELS = {
14378
14416
  hour: {
@@ -14422,18 +14460,13 @@ const countEvent = (tx, event) => {
14422
14460
  };
14423
14461
  const countOutcome = (tx, event) => {
14424
14462
  const shardBy = event.install_id;
14425
- const hour = (type, bundleRef) => tx.aggregate("insights_outcomes", {
14463
+ for (const [type, bundleRef] of outcomeRefsOf(event)) tx.aggregate("insights_outcomes", {
14426
14464
  platform: event.platform,
14427
14465
  channel: event.channel,
14428
14466
  type,
14429
14467
  bundle_ref: bundleRef,
14430
14468
  bucket_start_ms: hourOf(event.received_at_ms)
14431
14469
  }, { events: 1 }, { shardBy });
14432
- for (const bundleRef of bundleRefsOf(event)) hour(event.type, bundleRef);
14433
- if (event.metadata.implied_download === true) hour("UPDATE_DOWNLOADED", bundleRefOfFilter({
14434
- type: "UPDATE_DOWNLOADED",
14435
- toBundleId: event.type === "RECOVERED" ? event.from_bundle_id : event.to_bundle_id
14436
- }));
14437
14470
  tx.aggregate("insights_outcomes", {
14438
14471
  ...DAILY_EVENTS,
14439
14472
  bucket_start_ms: dayOf(event.received_at_ms)
@@ -14819,25 +14852,34 @@ const countEventSeries = async (db, input) => {
14819
14852
  events: count
14820
14853
  }));
14821
14854
  };
14822
- const latestPredicates = (bundle) => {
14823
- if (bundle === void 0) return void 0;
14824
- return [...new Map(bundle.flatMap(({ field, value, types }) => types.map((type) => [JSON.stringify([
14825
- field,
14826
- value,
14827
- type
14828
- ]), {
14829
- field,
14830
- value,
14831
- type
14832
- }]))).values()];
14833
- };
14834
- const countLatestEvents = async (db, input) => {
14835
- const { platform, channel, sinceMs: start } = input;
14855
+ const distributionRows = (db, { platform, channel, sinceMs: start }) => {
14836
14856
  if (start % 864e5 !== 0) throw new DatabaseAdapterInputError("invalid-query");
14837
- const predicates = latestPredicates(input.bundle);
14857
+ return drain((page) => db.findAggregates("insights_distribution", {
14858
+ index: "byScope",
14859
+ where: {
14860
+ channel,
14861
+ platform
14862
+ },
14863
+ range: { gte: start },
14864
+ limit: PAGE,
14865
+ ...page
14866
+ }));
14867
+ };
14868
+ const installations = (count) => Math.max(0, count);
14869
+ const countLatestEvents = async (db, input) => installations((await distributionRows(db, input)).reduce((sum, row) => sum + row.latest_installations, 0));
14870
+ const countReleaseInstallations = async (db, input) => {
14871
+ const { platform, channel, sinceMs: start, releaseId } = input;
14838
14872
  let total = 0;
14839
- if (predicates === void 0) {
14840
- const rows = await drain((page) => db.findAggregates("insights_distribution", {
14873
+ let release = 0;
14874
+ let named = false;
14875
+ for (const row of await distributionRows(db, input)) {
14876
+ total += row.latest_installations;
14877
+ if (row.release_id !== releaseId) continue;
14878
+ named = true;
14879
+ release += row.latest_installations;
14880
+ }
14881
+ if (!named) {
14882
+ const builtin = await drain((page) => db.findAggregates("insights_builtin_distribution", {
14841
14883
  index: "byScope",
14842
14884
  where: {
14843
14885
  channel,
@@ -14847,33 +14889,12 @@ const countLatestEvents = async (db, input) => {
14847
14889
  limit: PAGE,
14848
14890
  ...page
14849
14891
  }));
14850
- total += rows.reduce((sum, row) => sum + row.latest_installations, 0);
14851
- } else {
14852
- const gauge = async (bundleField, bundleId, type) => {
14853
- return (await drain((page) => db.findAggregates("insights_latest_by_bundle", {
14854
- index: "byBundle",
14855
- where: {
14856
- platform,
14857
- channel,
14858
- bundle_field: bundleField,
14859
- bundle_id: bundleId,
14860
- type
14861
- },
14862
- range: { gte: start },
14863
- limit: PAGE,
14864
- ...page
14865
- }))).reduce((sum, row) => sum + row.installations, 0);
14866
- };
14867
- for (const { field, value, type } of predicates) total += await gauge(field, value, type);
14868
- for (const from of predicates) {
14869
- if (from.field !== "from_bundle_id") continue;
14870
- for (const to of predicates) {
14871
- if (to.field !== "to_bundle_id" || to.type !== from.type) continue;
14872
- total -= await gauge(PAIR_FIELD, bundlePairKey(from.value, to.value), from.type);
14873
- }
14874
- }
14892
+ for (const row of builtin) if (row.release_id === "" && row.builtin_bundle_id === releaseId) release += row.latest_installations;
14875
14893
  }
14876
- return Math.max(0, total);
14894
+ return {
14895
+ installations: installations(total),
14896
+ release: installations(release)
14897
+ };
14877
14898
  };
14878
14899
  const retained = (now, { rawDays, dailyDays }) => ({
14879
14900
  hour: hourCeil(now - rawDays * DAY_MS$1),
@@ -15290,6 +15311,20 @@ const getUpdateFailures = async (db, input, now, retention) => {
15290
15311
  };
15291
15312
  };
15292
15313
  //#endregion
15314
+ //#region ../insights/dist/server/wire.mjs
15315
+ const RELEASE_ID_PARAM = "bundleId";
15316
+ const toWireOverview = ({ bundle, ...overview }) => {
15317
+ if (bundle === void 0) return overview;
15318
+ const { releaseId, ...counts } = bundle;
15319
+ return {
15320
+ ...overview,
15321
+ bundle: {
15322
+ ...counts,
15323
+ bundleId: releaseId
15324
+ }
15325
+ };
15326
+ };
15327
+ //#endregion
15293
15328
  //#region ../insights/dist/server/queryInput.mjs
15294
15329
  const MAX_PAGE_LIMIT = 100;
15295
15330
  const MAX_IDENTITY_LENGTH = 255;
@@ -15334,7 +15369,7 @@ const readScope = (url) => {
15334
15369
  const parseEventPageInput = (request) => {
15335
15370
  const url = new URL(request.url);
15336
15371
  const bundleFields = [
15337
- "bundleId",
15372
+ RELEASE_ID_PARAM,
15338
15373
  "outcome",
15339
15374
  "platform",
15340
15375
  "channel"
@@ -15345,7 +15380,7 @@ const parseEventPageInput = (request) => {
15345
15380
  if (outcome !== "downloaded" && outcome !== "applied" && outcome !== "recovered" && outcome !== "failed") throw new InsightsBadRequestError("Invalid 'outcome' query parameter.");
15346
15381
  bundle = {
15347
15382
  ...readScope(url),
15348
- bundleId: readId(url, "bundleId", 1024),
15383
+ releaseId: readId(url, RELEASE_ID_PARAM, 1024),
15349
15384
  outcome
15350
15385
  };
15351
15386
  }
@@ -15371,11 +15406,10 @@ const parseReportingOverviewInput = (request) => {
15371
15406
  const url = new URL(request.url);
15372
15407
  const window = readSingle(url, "window") ?? "30d";
15373
15408
  if (window !== "24h" && window !== "7d" && window !== "30d") throw new InsightsBadRequestError("Invalid 'window' query parameter.");
15374
- const bundleId = readSingle(url, "bundleId");
15375
15409
  return {
15376
15410
  ...readScope(url),
15377
15411
  window,
15378
- ...bundleId === void 0 ? {} : { bundleId: readId(url, "bundleId", 1024) }
15412
+ ...readSingle(url, "bundleId") === void 0 ? {} : { releaseId: readId(url, RELEASE_ID_PARAM, 1024) }
15379
15413
  };
15380
15414
  };
15381
15415
  //#endregion
@@ -15454,7 +15488,7 @@ const createInsightsRouteHandlers = (provider) => ({
15454
15488
  await provider.appendBundleEvent(await parseBundleEventRequest(request));
15455
15489
  return new Response(null, { status: 204 });
15456
15490
  }),
15457
- getReportingOverview: (_params, request) => query(() => provider.getReportingOverview(parseReportingOverviewInput(request))),
15491
+ getReportingOverview: (_params, request) => query(async () => toWireOverview(await provider.getReportingOverview(parseReportingOverviewInput(request)))),
15458
15492
  getInstallation: (params) => run$1(async () => {
15459
15493
  const installation = await provider.getInstallation({ installId: requireParam(params, "installId") });
15460
15494
  return installation === null ? json$1({ error: "Installation not found" }, 404) : json$1(installation, 200);
@@ -15474,11 +15508,13 @@ const createInsightsApi = (db, now, retention) => ({
15474
15508
  listEvents: (input) => listEvents(db, input),
15475
15509
  findLatestEvents: (input) => findLatestEvents(db, input),
15476
15510
  countLatestEvents: (input) => countLatestEvents(db, input),
15511
+ countReleaseInstallations: (input) => countReleaseInstallations(db, input),
15477
15512
  countEvents: (input) => countEvents(db, input),
15478
15513
  countEventSeries: (input) => countEventSeries(db, input),
15479
15514
  getReleaseActivity: (input) => getReleaseActivity(db, input, now),
15480
15515
  getAppUsage: (input) => getAppUsage(db, input, now, retention),
15481
- getUpdateFailures: (input) => getUpdateFailures(db, input, now, retention)
15516
+ getUpdateFailures: (input) => getUpdateFailures(db, input, now, retention),
15517
+ backfillReleaseRefs: (options) => backfillReleaseRefs(db, now, retention, options)
15482
15518
  });
15483
15519
  const readFailuresQuery = (url) => {
15484
15520
  const query = url.searchParams;
@@ -7884,6 +7884,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
7884
7884
  let credential;
7885
7885
  try {
7886
7886
  await (0, _hot_updater_cli_tools.fillReleaseLabels)(server);
7887
+ await (0, _hot_updater_cli_tools.backfillInsightsReleaseRefs)(server);
7887
7888
  credential = await (0, _hot_updater_cli_tools.provisionClientCredential)(server, {
7888
7889
  env: initInputEnv,
7889
7890
  name: "Azure init"
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { createHash } from "crypto";
3
3
  import path from "path";
4
- import { ConfigBuilder, InitError, assembleServer, createHotUpdaterConfigScaffoldFromBuilder, createZip, fillReleaseLabels, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInputs, shouldAutoSelectOnlyInitResource, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
4
+ import { ConfigBuilder, InitError, assembleServer, backfillInsightsReleaseRefs, createHotUpdaterConfigScaffoldFromBuilder, createZip, fillReleaseLabels, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInputs, shouldAutoSelectOnlyInitResource, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
5
5
  import { apiKeys, insights, remoteConfig } from "@hot-updater/server/plugins";
6
6
  import { CosmosClient } from "@azure/cosmos";
7
7
  import { SETTINGS_TABLE, createEngineDatabase, createKvAdapter, encodeKvKey, migrateCoreSchema, toolingTargetOf } from "@hot-updater/plugin-core";
@@ -7879,6 +7879,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
7879
7879
  let credential;
7880
7880
  try {
7881
7881
  await fillReleaseLabels(server);
7882
+ await backfillInsightsReleaseRefs(server);
7882
7883
  credential = await provisionClientCredential(server, {
7883
7884
  env: initInputEnv,
7884
7885
  name: "Azure init"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/azure",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.57",
4
+ "version": "1.2.0-rc.58",
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"
@@ -44,10 +44,10 @@
44
44
  "@azure/identity": "4.14.0",
45
45
  "@azure/keyvault-secrets": "4.11.2",
46
46
  "@azure/storage-blob": "12.34.0",
47
- "@hot-updater/cli-tools": "1.2.0-rc.57",
48
- "@hot-updater/protocol": "1.2.0-rc.57",
49
- "@hot-updater/server": "1.2.0-rc.57",
50
- "@hot-updater/plugin-core": "1.2.0-rc.57"
47
+ "@hot-updater/cli-tools": "1.2.0-rc.58",
48
+ "@hot-updater/plugin-core": "1.2.0-rc.58",
49
+ "@hot-updater/protocol": "1.2.0-rc.58",
50
+ "@hot-updater/server": "1.2.0-rc.58"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@azure/functions": "4.16.5",
@@ -55,7 +55,7 @@
55
55
  "execa": "9.5.2",
56
56
  "jszip": "^3.10.1",
57
57
  "vitest": "4.1.4",
58
- "@hot-updater/test-utils": "1.2.0-rc.57"
58
+ "@hot-updater/test-utils": "1.2.0-rc.58"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "tsdown",