@hot-updater/protocol 1.2.0-rc.57 → 1.2.0-rc.59

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/dist/index.cjs CHANGED
@@ -277,14 +277,14 @@ function modularInverse(value, modulus) {
277
277
  if (r > 1) throw new Error(`No modular inverse for ${value} mod ${modulus}`);
278
278
  return positiveMod(t, modulus);
279
279
  }
280
- function getRolloutShuffleParameters(bundleId) {
281
- let multiplier = positiveMod(hashString(`${bundleId}:multiplier`), 997);
280
+ function getRolloutShuffleParameters(releaseId) {
281
+ let multiplier = positiveMod(hashString(`${releaseId}:multiplier`), 997);
282
282
  if (multiplier === 0) multiplier = 1;
283
283
  while (gcd(multiplier, NUMERIC_COHORT_SIZE) !== 1) {
284
284
  multiplier = positiveMod(multiplier + 1, NUMERIC_COHORT_SIZE);
285
285
  if (multiplier === 0) multiplier = 1;
286
286
  }
287
- const offset = positiveMod(hashString(`${bundleId}:offset`), NUMERIC_COHORT_SIZE);
287
+ const offset = positiveMod(hashString(`${releaseId}:offset`), NUMERIC_COHORT_SIZE);
288
288
  return {
289
289
  multiplier,
290
290
  offset,
@@ -321,19 +321,19 @@ function getDefaultNumericCohort(identifier) {
321
321
  const cohortValue = positiveMod(hashString(identifier), NUMERIC_COHORT_SIZE) + 1;
322
322
  return String(cohortValue);
323
323
  }
324
- function getNumericCohortRolloutPosition(bundleId, cohortValue) {
324
+ function getNumericCohortRolloutPosition(releaseId, cohortValue) {
325
325
  if (cohortValue < 1 || cohortValue > 1e3) throw new Error(`Invalid numeric cohort: ${cohortValue}`);
326
- const { offset, inverseMultiplier } = getRolloutShuffleParameters(bundleId);
326
+ const { offset, inverseMultiplier } = getRolloutShuffleParameters(releaseId);
327
327
  return positiveMod(inverseMultiplier * (cohortValue - 1 - offset), NUMERIC_COHORT_SIZE);
328
328
  }
329
- function getRolledOutNumericCohorts(bundleId, rolloutCohortCount) {
329
+ function getRolledOutNumericCohorts(releaseId, rolloutCohortCount) {
330
330
  const normalizedRolloutCount = normalizeRolloutCohortCount(rolloutCohortCount);
331
331
  if (normalizedRolloutCount <= 0) return [];
332
332
  if (normalizedRolloutCount >= 1e3) return Array.from({ length: NUMERIC_COHORT_SIZE }, (_, index) => index + 1);
333
- const { multiplier, offset } = getRolloutShuffleParameters(bundleId);
333
+ const { multiplier, offset } = getRolloutShuffleParameters(releaseId);
334
334
  return Array.from({ length: normalizedRolloutCount }, (_, position) => positiveMod(multiplier * position + offset, NUMERIC_COHORT_SIZE)).map((zeroBasedCohort) => zeroBasedCohort + 1).sort((left, right) => left - right);
335
335
  }
336
- function isCohortEligibleForUpdate(bundleId, cohort, rolloutCohortCount, targetCohorts) {
336
+ function isCohortEligibleForUpdate(releaseId, cohort, rolloutCohortCount, targetCohorts) {
337
337
  const normalizedCohort = cohort === null || cohort === void 0 ? void 0 : normalizeCohortValue(cohort);
338
338
  const normalizedTargetCohorts = targetCohorts?.map((targetCohort) => normalizeCohortValue(targetCohort)) ?? [];
339
339
  if (normalizedCohort !== void 0 && normalizedTargetCohorts.includes(normalizedCohort)) return true;
@@ -343,7 +343,7 @@ function isCohortEligibleForUpdate(bundleId, cohort, rolloutCohortCount, targetC
343
343
  const numericCohort = getNumericCohortValue(normalizedCohort);
344
344
  if (numericCohort === null) return false;
345
345
  if (normalizedRolloutCount >= 1e3) return true;
346
- return getNumericCohortRolloutPosition(bundleId, numericCohort) < normalizedRolloutCount;
346
+ return getNumericCohortRolloutPosition(releaseId, numericCohort) < normalizedRolloutCount;
347
347
  }
348
348
  //#endregion
349
349
  //#region src/releaseCatalog.ts
@@ -370,7 +370,7 @@ function createReleaseSelectionContextHash(input) {
370
370
  activeReleaseId: input.activeReleaseId ?? null,
371
371
  cohort: normalizeCohortValue(input.cohort ?? ""),
372
372
  crashedBundleIds,
373
- minimumReleaseId: input.minimumReleaseId,
373
+ minimumReleaseId: input.minBundleId,
374
374
  selectorSchemaVersion: 1,
375
375
  strategy: input.strategy,
376
376
  strategyValue: input.strategyValue
@@ -385,10 +385,10 @@ function selectDesiredRelease(catalog, input) {
385
385
  const crashedBundleIds = new Set(input.crashedBundleIds);
386
386
  const activeReleaseId = input.activeReleaseId ?? null;
387
387
  const hasActiveBundle = input.currentBundleId !== input.builtInBundleId;
388
- const isSafeBundleRelease = (release) => release.bundleId !== null && !crashedBundleIds.has(release.bundleId) && release.bundleId >= input.minimumReleaseId;
388
+ const isSafeBundleRelease = (release) => release.bundleId !== null && !crashedBundleIds.has(release.bundleId) && release.bundleId >= input.minBundleId;
389
389
  const runningReleaseId = input.runningReleaseId === void 0 ? activeReleaseId : input.runningReleaseId;
390
390
  const isNewerThanRunning = (release) => runningReleaseId !== null ? release.releaseId > runningReleaseId : release.bundleId !== null && release.bundleId > input.currentBundleId;
391
- const passesForcedRelease = (selected) => [selected, ...catalog.rollbackReleases].some((passed) => passed.shouldForceUpdate && passed.bundleId !== null && passed.bundleId >= input.minimumReleaseId && passed.bundleId !== input.currentBundleId && passed.releaseId <= selected.releaseId && isNewerThanRunning(passed) && isReleaseEligibleForCohort(passed, input.cohort));
391
+ const passesForcedRelease = (selected) => [selected, ...catalog.rollbackReleases].some((passed) => passed.shouldForceUpdate && passed.bundleId !== null && passed.bundleId >= input.minBundleId && passed.bundleId !== input.currentBundleId && passed.releaseId <= selected.releaseId && isNewerThanRunning(passed) && isReleaseEligibleForCohort(passed, input.cohort));
392
392
  const desiredBundle = (release, status) => ({
393
393
  bundleId: release.bundleId,
394
394
  kind: "BUNDLE",
@@ -408,7 +408,7 @@ function selectDesiredRelease(catalog, input) {
408
408
  if (current !== void 0 && isSafeBundleRelease(current) && isReleaseEligibleForCohort(current, input.cohort)) return desiredBundle(current, "UPDATE");
409
409
  const rollback = rollbackReleases.find((release) => isSafeBundleRelease(release) && (activeReleaseId !== null ? release.releaseId < activeReleaseId : release.bundleId < input.currentBundleId));
410
410
  if (rollback !== void 0 && isSafeBundleRelease(rollback)) return desiredBundle(rollback, "ROLLBACK");
411
- if (input.currentBundleId <= input.minimumReleaseId) return null;
411
+ if (input.currentBundleId <= input.minBundleId) return null;
412
412
  }
413
413
  if (catalog.fallbackPolicy !== "BUILTIN_IF_ACTIVE_INELIGIBLE") return null;
414
414
  return {
package/dist/index.d.cts CHANGED
@@ -361,7 +361,13 @@ interface HotUpdaterClientContext {
361
361
  readonly minBundleId: string;
362
362
  /** Whether this is a debug build (`__DEV__`). */
363
363
  readonly isDebugBuild: boolean;
364
- /** The bundle native reports as current. */
364
+ /**
365
+ * The same ID as `hotUpdater.getBundleId()`: the selected release's ID, the
366
+ * one the Console shows. It names a staged update before the app reloads,
367
+ * `minBundleId` for the built-in bundle, and the artifact ID only for a
368
+ * bundle installed without a release. A plugin that needs the artifact reads
369
+ * the hooks' `bundleId`, `fromBundleId`, `toBundleId`, and `targetBundleId`.
370
+ */
365
371
  getBundleId(): string;
366
372
  getChannel(): string;
367
373
  getCohort(): string;
@@ -429,6 +435,7 @@ interface PluginHostEnvironment {
429
435
  getInstallId(): string;
430
436
  getAppVersion(): string | null;
431
437
  getMinBundleId(): string;
438
+ /** The selected release's ID, as `hotUpdater.getBundleId()` returns it. */
432
439
  getBundleId(): string;
433
440
  getChannel(): string;
434
441
  getCohort(): string;
@@ -563,7 +570,11 @@ interface ReleaseSelectionInput {
563
570
  * Defaults to `activeReleaseId`; null compares by `currentBundleId`.
564
571
  */
565
572
  readonly runningReleaseId?: string | null;
566
- readonly minimumReleaseId: string;
573
+ /**
574
+ * The selection floor: the built-in bundle's ID (MIN_BUNDLE_ID), or the
575
+ * nil UUID when bundles older than it may be selected.
576
+ */
577
+ readonly minBundleId: string;
567
578
  readonly cohort: string | null | undefined;
568
579
  readonly crashedBundleIds: readonly string[];
569
580
  }
@@ -571,7 +582,11 @@ interface ReleaseSelectionContextInput {
571
582
  readonly activeBundleId?: string | null;
572
583
  readonly activeReleaseId?: string | null;
573
584
  readonly cohort: string | null | undefined;
574
- readonly minimumReleaseId: string;
585
+ /**
586
+ * The selection floor: the built-in bundle's ID (MIN_BUNDLE_ID), or the
587
+ * nil UUID when bundles older than it may be selected.
588
+ */
589
+ readonly minBundleId: string;
575
590
  readonly strategy: ReleaseStrategy;
576
591
  readonly strategyValue: string;
577
592
  readonly crashedBundleIds: readonly string[];
@@ -678,9 +693,9 @@ declare function isNumericCohort(cohort: string): boolean;
678
693
  declare function isCustomCohort(cohort: string): boolean;
679
694
  declare function isValidCohort(cohort: string): boolean;
680
695
  declare function getDefaultNumericCohort(identifier: string): string;
681
- declare function getNumericCohortRolloutPosition(bundleId: string, cohortValue: number): number;
682
- declare function getRolledOutNumericCohorts(bundleId: string, rolloutCohortCount: number | null | undefined): number[];
683
- declare function isCohortEligibleForUpdate(bundleId: string, cohort: string | null | undefined, rolloutCohortCount: number | null | undefined, targetCohorts: readonly string[] | null | undefined): boolean;
696
+ declare function getNumericCohortRolloutPosition(releaseId: string, cohortValue: number): number;
697
+ declare function getRolledOutNumericCohorts(releaseId: string, rolloutCohortCount: number | null | undefined): number[];
698
+ declare function isCohortEligibleForUpdate(releaseId: string, cohort: string | null | undefined, rolloutCohortCount: number | null | undefined, targetCohorts: readonly string[] | null | undefined): boolean;
684
699
  //#endregion
685
700
  //#region src/uuid.d.ts
686
701
  declare const NIL_UUID = "00000000-0000-0000-0000-000000000000";
package/dist/index.d.mts CHANGED
@@ -361,7 +361,13 @@ interface HotUpdaterClientContext {
361
361
  readonly minBundleId: string;
362
362
  /** Whether this is a debug build (`__DEV__`). */
363
363
  readonly isDebugBuild: boolean;
364
- /** The bundle native reports as current. */
364
+ /**
365
+ * The same ID as `hotUpdater.getBundleId()`: the selected release's ID, the
366
+ * one the Console shows. It names a staged update before the app reloads,
367
+ * `minBundleId` for the built-in bundle, and the artifact ID only for a
368
+ * bundle installed without a release. A plugin that needs the artifact reads
369
+ * the hooks' `bundleId`, `fromBundleId`, `toBundleId`, and `targetBundleId`.
370
+ */
365
371
  getBundleId(): string;
366
372
  getChannel(): string;
367
373
  getCohort(): string;
@@ -429,6 +435,7 @@ interface PluginHostEnvironment {
429
435
  getInstallId(): string;
430
436
  getAppVersion(): string | null;
431
437
  getMinBundleId(): string;
438
+ /** The selected release's ID, as `hotUpdater.getBundleId()` returns it. */
432
439
  getBundleId(): string;
433
440
  getChannel(): string;
434
441
  getCohort(): string;
@@ -563,7 +570,11 @@ interface ReleaseSelectionInput {
563
570
  * Defaults to `activeReleaseId`; null compares by `currentBundleId`.
564
571
  */
565
572
  readonly runningReleaseId?: string | null;
566
- readonly minimumReleaseId: string;
573
+ /**
574
+ * The selection floor: the built-in bundle's ID (MIN_BUNDLE_ID), or the
575
+ * nil UUID when bundles older than it may be selected.
576
+ */
577
+ readonly minBundleId: string;
567
578
  readonly cohort: string | null | undefined;
568
579
  readonly crashedBundleIds: readonly string[];
569
580
  }
@@ -571,7 +582,11 @@ interface ReleaseSelectionContextInput {
571
582
  readonly activeBundleId?: string | null;
572
583
  readonly activeReleaseId?: string | null;
573
584
  readonly cohort: string | null | undefined;
574
- readonly minimumReleaseId: string;
585
+ /**
586
+ * The selection floor: the built-in bundle's ID (MIN_BUNDLE_ID), or the
587
+ * nil UUID when bundles older than it may be selected.
588
+ */
589
+ readonly minBundleId: string;
575
590
  readonly strategy: ReleaseStrategy;
576
591
  readonly strategyValue: string;
577
592
  readonly crashedBundleIds: readonly string[];
@@ -678,9 +693,9 @@ declare function isNumericCohort(cohort: string): boolean;
678
693
  declare function isCustomCohort(cohort: string): boolean;
679
694
  declare function isValidCohort(cohort: string): boolean;
680
695
  declare function getDefaultNumericCohort(identifier: string): string;
681
- declare function getNumericCohortRolloutPosition(bundleId: string, cohortValue: number): number;
682
- declare function getRolledOutNumericCohorts(bundleId: string, rolloutCohortCount: number | null | undefined): number[];
683
- declare function isCohortEligibleForUpdate(bundleId: string, cohort: string | null | undefined, rolloutCohortCount: number | null | undefined, targetCohorts: readonly string[] | null | undefined): boolean;
696
+ declare function getNumericCohortRolloutPosition(releaseId: string, cohortValue: number): number;
697
+ declare function getRolledOutNumericCohorts(releaseId: string, rolloutCohortCount: number | null | undefined): number[];
698
+ declare function isCohortEligibleForUpdate(releaseId: string, cohort: string | null | undefined, rolloutCohortCount: number | null | undefined, targetCohorts: readonly string[] | null | undefined): boolean;
684
699
  //#endregion
685
700
  //#region src/uuid.d.ts
686
701
  declare const NIL_UUID = "00000000-0000-0000-0000-000000000000";
package/dist/index.mjs CHANGED
@@ -276,14 +276,14 @@ function modularInverse(value, modulus) {
276
276
  if (r > 1) throw new Error(`No modular inverse for ${value} mod ${modulus}`);
277
277
  return positiveMod(t, modulus);
278
278
  }
279
- function getRolloutShuffleParameters(bundleId) {
280
- let multiplier = positiveMod(hashString(`${bundleId}:multiplier`), 997);
279
+ function getRolloutShuffleParameters(releaseId) {
280
+ let multiplier = positiveMod(hashString(`${releaseId}:multiplier`), 997);
281
281
  if (multiplier === 0) multiplier = 1;
282
282
  while (gcd(multiplier, NUMERIC_COHORT_SIZE) !== 1) {
283
283
  multiplier = positiveMod(multiplier + 1, NUMERIC_COHORT_SIZE);
284
284
  if (multiplier === 0) multiplier = 1;
285
285
  }
286
- const offset = positiveMod(hashString(`${bundleId}:offset`), NUMERIC_COHORT_SIZE);
286
+ const offset = positiveMod(hashString(`${releaseId}:offset`), NUMERIC_COHORT_SIZE);
287
287
  return {
288
288
  multiplier,
289
289
  offset,
@@ -320,19 +320,19 @@ function getDefaultNumericCohort(identifier) {
320
320
  const cohortValue = positiveMod(hashString(identifier), NUMERIC_COHORT_SIZE) + 1;
321
321
  return String(cohortValue);
322
322
  }
323
- function getNumericCohortRolloutPosition(bundleId, cohortValue) {
323
+ function getNumericCohortRolloutPosition(releaseId, cohortValue) {
324
324
  if (cohortValue < 1 || cohortValue > 1e3) throw new Error(`Invalid numeric cohort: ${cohortValue}`);
325
- const { offset, inverseMultiplier } = getRolloutShuffleParameters(bundleId);
325
+ const { offset, inverseMultiplier } = getRolloutShuffleParameters(releaseId);
326
326
  return positiveMod(inverseMultiplier * (cohortValue - 1 - offset), NUMERIC_COHORT_SIZE);
327
327
  }
328
- function getRolledOutNumericCohorts(bundleId, rolloutCohortCount) {
328
+ function getRolledOutNumericCohorts(releaseId, rolloutCohortCount) {
329
329
  const normalizedRolloutCount = normalizeRolloutCohortCount(rolloutCohortCount);
330
330
  if (normalizedRolloutCount <= 0) return [];
331
331
  if (normalizedRolloutCount >= 1e3) return Array.from({ length: NUMERIC_COHORT_SIZE }, (_, index) => index + 1);
332
- const { multiplier, offset } = getRolloutShuffleParameters(bundleId);
332
+ const { multiplier, offset } = getRolloutShuffleParameters(releaseId);
333
333
  return Array.from({ length: normalizedRolloutCount }, (_, position) => positiveMod(multiplier * position + offset, NUMERIC_COHORT_SIZE)).map((zeroBasedCohort) => zeroBasedCohort + 1).sort((left, right) => left - right);
334
334
  }
335
- function isCohortEligibleForUpdate(bundleId, cohort, rolloutCohortCount, targetCohorts) {
335
+ function isCohortEligibleForUpdate(releaseId, cohort, rolloutCohortCount, targetCohorts) {
336
336
  const normalizedCohort = cohort === null || cohort === void 0 ? void 0 : normalizeCohortValue(cohort);
337
337
  const normalizedTargetCohorts = targetCohorts?.map((targetCohort) => normalizeCohortValue(targetCohort)) ?? [];
338
338
  if (normalizedCohort !== void 0 && normalizedTargetCohorts.includes(normalizedCohort)) return true;
@@ -342,7 +342,7 @@ function isCohortEligibleForUpdate(bundleId, cohort, rolloutCohortCount, targetC
342
342
  const numericCohort = getNumericCohortValue(normalizedCohort);
343
343
  if (numericCohort === null) return false;
344
344
  if (normalizedRolloutCount >= 1e3) return true;
345
- return getNumericCohortRolloutPosition(bundleId, numericCohort) < normalizedRolloutCount;
345
+ return getNumericCohortRolloutPosition(releaseId, numericCohort) < normalizedRolloutCount;
346
346
  }
347
347
  //#endregion
348
348
  //#region src/releaseCatalog.ts
@@ -369,7 +369,7 @@ function createReleaseSelectionContextHash(input) {
369
369
  activeReleaseId: input.activeReleaseId ?? null,
370
370
  cohort: normalizeCohortValue(input.cohort ?? ""),
371
371
  crashedBundleIds,
372
- minimumReleaseId: input.minimumReleaseId,
372
+ minimumReleaseId: input.minBundleId,
373
373
  selectorSchemaVersion: 1,
374
374
  strategy: input.strategy,
375
375
  strategyValue: input.strategyValue
@@ -384,10 +384,10 @@ function selectDesiredRelease(catalog, input) {
384
384
  const crashedBundleIds = new Set(input.crashedBundleIds);
385
385
  const activeReleaseId = input.activeReleaseId ?? null;
386
386
  const hasActiveBundle = input.currentBundleId !== input.builtInBundleId;
387
- const isSafeBundleRelease = (release) => release.bundleId !== null && !crashedBundleIds.has(release.bundleId) && release.bundleId >= input.minimumReleaseId;
387
+ const isSafeBundleRelease = (release) => release.bundleId !== null && !crashedBundleIds.has(release.bundleId) && release.bundleId >= input.minBundleId;
388
388
  const runningReleaseId = input.runningReleaseId === void 0 ? activeReleaseId : input.runningReleaseId;
389
389
  const isNewerThanRunning = (release) => runningReleaseId !== null ? release.releaseId > runningReleaseId : release.bundleId !== null && release.bundleId > input.currentBundleId;
390
- const passesForcedRelease = (selected) => [selected, ...catalog.rollbackReleases].some((passed) => passed.shouldForceUpdate && passed.bundleId !== null && passed.bundleId >= input.minimumReleaseId && passed.bundleId !== input.currentBundleId && passed.releaseId <= selected.releaseId && isNewerThanRunning(passed) && isReleaseEligibleForCohort(passed, input.cohort));
390
+ const passesForcedRelease = (selected) => [selected, ...catalog.rollbackReleases].some((passed) => passed.shouldForceUpdate && passed.bundleId !== null && passed.bundleId >= input.minBundleId && passed.bundleId !== input.currentBundleId && passed.releaseId <= selected.releaseId && isNewerThanRunning(passed) && isReleaseEligibleForCohort(passed, input.cohort));
391
391
  const desiredBundle = (release, status) => ({
392
392
  bundleId: release.bundleId,
393
393
  kind: "BUNDLE",
@@ -407,7 +407,7 @@ function selectDesiredRelease(catalog, input) {
407
407
  if (current !== void 0 && isSafeBundleRelease(current) && isReleaseEligibleForCohort(current, input.cohort)) return desiredBundle(current, "UPDATE");
408
408
  const rollback = rollbackReleases.find((release) => isSafeBundleRelease(release) && (activeReleaseId !== null ? release.releaseId < activeReleaseId : release.bundleId < input.currentBundleId));
409
409
  if (rollback !== void 0 && isSafeBundleRelease(rollback)) return desiredBundle(rollback, "ROLLBACK");
410
- if (input.currentBundleId <= input.minimumReleaseId) return null;
410
+ if (input.currentBundleId <= input.minBundleId) return null;
411
411
  }
412
412
  if (catalog.fallbackPolicy !== "BUILTIN_IF_ACTIVE_INELIGIBLE") return null;
413
413
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/protocol",
3
- "version": "1.2.0-rc.57",
3
+ "version": "1.2.0-rc.59",
4
4
  "type": "module",
5
5
  "description": "The data formats and pure computations that Hot Updater's app and server share",
6
6
  "sideEffects": false,