@hot-updater/aws 1.2.0-rc.56 → 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.
- package/dist/init/index.cjs +1 -0
- package/dist/init/index.mjs +2 -1
- package/dist/lambda/index.cjs +260 -166
- package/package.json +8 -8
package/dist/init/index.cjs
CHANGED
|
@@ -8776,6 +8776,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
8776
8776
|
let credential;
|
|
8777
8777
|
try {
|
|
8778
8778
|
await (0, _hot_updater_cli_tools.fillReleaseLabels)(server);
|
|
8779
|
+
await (0, _hot_updater_cli_tools.backfillInsightsReleaseRefs)(server);
|
|
8779
8780
|
credential = await (0, _hot_updater_cli_tools.provisionClientCredential)(server, {
|
|
8780
8781
|
env: providerEnv,
|
|
8781
8782
|
name: "AWS init"
|
package/dist/init/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { ConfigBuilder, InitError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInfrastructureGenerationPayload, assertInitProviderInputs, colors, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, createZip, ensureInstallPackages, fillReleaseLabels, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInput, transformEnv, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
2
|
+
import { ConfigBuilder, InitError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInfrastructureGenerationPayload, assertInitProviderInputs, backfillInsightsReleaseRefs, colors, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, createZip, ensureInstallPackages, fillReleaseLabels, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInput, transformEnv, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
3
3
|
import { apiKeys, insights, remoteConfig } from "@hot-updater/server/plugins";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
|
|
@@ -8771,6 +8771,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
8771
8771
|
let credential;
|
|
8772
8772
|
try {
|
|
8773
8773
|
await fillReleaseLabels(server);
|
|
8774
|
+
await backfillInsightsReleaseRefs(server);
|
|
8774
8775
|
credential = await provisionClientCredential(server, {
|
|
8775
8776
|
env: providerEnv,
|
|
8776
8777
|
name: "AWS init"
|
package/dist/lambda/index.cjs
CHANGED
|
@@ -554,14 +554,14 @@ function modularInverse(value, modulus) {
|
|
|
554
554
|
if (r > 1) throw new Error(`No modular inverse for ${value} mod ${modulus}`);
|
|
555
555
|
return positiveMod(t, modulus);
|
|
556
556
|
}
|
|
557
|
-
function getRolloutShuffleParameters(
|
|
558
|
-
let multiplier = positiveMod(hashString(`${
|
|
557
|
+
function getRolloutShuffleParameters(releaseId) {
|
|
558
|
+
let multiplier = positiveMod(hashString(`${releaseId}:multiplier`), 997);
|
|
559
559
|
if (multiplier === 0) multiplier = 1;
|
|
560
560
|
while (gcd(multiplier, NUMERIC_COHORT_SIZE) !== 1) {
|
|
561
561
|
multiplier = positiveMod(multiplier + 1, NUMERIC_COHORT_SIZE);
|
|
562
562
|
if (multiplier === 0) multiplier = 1;
|
|
563
563
|
}
|
|
564
|
-
const offset = positiveMod(hashString(`${
|
|
564
|
+
const offset = positiveMod(hashString(`${releaseId}:offset`), NUMERIC_COHORT_SIZE);
|
|
565
565
|
return {
|
|
566
566
|
multiplier,
|
|
567
567
|
offset,
|
|
@@ -594,16 +594,16 @@ function isValidCohort(cohort) {
|
|
|
594
594
|
const normalized = normalizeCohortValue(cohort);
|
|
595
595
|
return isNumericCohort(normalized) || isCustomCohort(normalized);
|
|
596
596
|
}
|
|
597
|
-
function getNumericCohortRolloutPosition(
|
|
597
|
+
function getNumericCohortRolloutPosition(releaseId, cohortValue) {
|
|
598
598
|
if (cohortValue < 1 || cohortValue > 1e3) throw new Error(`Invalid numeric cohort: ${cohortValue}`);
|
|
599
|
-
const { offset, inverseMultiplier } = getRolloutShuffleParameters(
|
|
599
|
+
const { offset, inverseMultiplier } = getRolloutShuffleParameters(releaseId);
|
|
600
600
|
return positiveMod(inverseMultiplier * (cohortValue - 1 - offset), NUMERIC_COHORT_SIZE);
|
|
601
601
|
}
|
|
602
|
-
function getRolledOutNumericCohorts(
|
|
602
|
+
function getRolledOutNumericCohorts(releaseId, rolloutCohortCount) {
|
|
603
603
|
const normalizedRolloutCount = normalizeRolloutCohortCount(rolloutCohortCount);
|
|
604
604
|
if (normalizedRolloutCount <= 0) return [];
|
|
605
605
|
if (normalizedRolloutCount >= 1e3) return Array.from({ length: NUMERIC_COHORT_SIZE }, (_, index) => index + 1);
|
|
606
|
-
const { multiplier, offset } = getRolloutShuffleParameters(
|
|
606
|
+
const { multiplier, offset } = getRolloutShuffleParameters(releaseId);
|
|
607
607
|
return Array.from({ length: normalizedRolloutCount }, (_, position) => positiveMod(multiplier * position + offset, NUMERIC_COHORT_SIZE)).map((zeroBasedCohort) => zeroBasedCohort + 1).sort((left, right) => left - right);
|
|
608
608
|
}
|
|
609
609
|
const RELEASE_CATALOG_FALLBACK_POLICY = "BUILTIN_IF_ACTIVE_INELIGIBLE";
|
|
@@ -5226,7 +5226,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
5226
5226
|
};
|
|
5227
5227
|
//#endregion
|
|
5228
5228
|
//#region ../../packages/server/dist/version.mjs
|
|
5229
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
5229
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.58";
|
|
5230
5230
|
//#endregion
|
|
5231
5231
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
5232
5232
|
/**
|
|
@@ -6025,7 +6025,7 @@ const baseBundleIdsOf = (row, range, bundleId, limit) => {
|
|
|
6025
6025
|
};
|
|
6026
6026
|
//#endregion
|
|
6027
6027
|
//#region ../../packages/server/dist/core/reads.mjs
|
|
6028
|
-
const PAGE$
|
|
6028
|
+
const PAGE$5 = 500;
|
|
6029
6029
|
const pick$2 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
|
|
6030
6030
|
const toBundleRow = pick$2([
|
|
6031
6031
|
"id",
|
|
@@ -6122,7 +6122,7 @@ const createCoreReads = (db, storage) => {
|
|
|
6122
6122
|
const page = await db.findMany("bundle_patches", {
|
|
6123
6123
|
index: "byBundle",
|
|
6124
6124
|
where: { bundle_id: row.id },
|
|
6125
|
-
limit: Math.min(count - patches.length, PAGE$
|
|
6125
|
+
limit: Math.min(count - patches.length, PAGE$5),
|
|
6126
6126
|
...cursor === void 0 ? {} : { cursor }
|
|
6127
6127
|
});
|
|
6128
6128
|
patches.push(...page.rows.map(toPatchRow));
|
|
@@ -6348,7 +6348,7 @@ const createCoreReads = (db, storage) => {
|
|
|
6348
6348
|
return (await drain$1((page) => db.findMany("channels", {
|
|
6349
6349
|
index: "all",
|
|
6350
6350
|
where: {},
|
|
6351
|
-
limit: PAGE$
|
|
6351
|
+
limit: PAGE$5,
|
|
6352
6352
|
...page
|
|
6353
6353
|
}))).map(toChannelRow);
|
|
6354
6354
|
},
|
|
@@ -6743,7 +6743,7 @@ const createLabelAllocator = (tx, used, caughtUp) => {
|
|
|
6743
6743
|
};
|
|
6744
6744
|
};
|
|
6745
6745
|
const FILL_BATCH = 25;
|
|
6746
|
-
const PAGE$
|
|
6746
|
+
const PAGE$4 = 500;
|
|
6747
6747
|
/**
|
|
6748
6748
|
* Labels a channel and platform's releases that have none, in ID order,
|
|
6749
6749
|
* which is the order they were created in, and marks its counter filled:
|
|
@@ -6796,7 +6796,7 @@ const fillLabels = async (db, { channelId, platform }, { dryRun = false } = {})
|
|
|
6796
6796
|
channel_id: channelId,
|
|
6797
6797
|
platform
|
|
6798
6798
|
},
|
|
6799
|
-
limit: PAGE$
|
|
6799
|
+
limit: PAGE$4,
|
|
6800
6800
|
...cursor === void 0 ? {} : { cursor }
|
|
6801
6801
|
});
|
|
6802
6802
|
const unlabeled = page.rows.filter((row) => typeof row.label !== "number").map((row) => row.id);
|
|
@@ -6984,7 +6984,7 @@ const pendingLabelPairs = async (db) => {
|
|
|
6984
6984
|
};
|
|
6985
6985
|
//#endregion
|
|
6986
6986
|
//#region ../../packages/server/dist/core/writes.mjs
|
|
6987
|
-
const PAGE$
|
|
6987
|
+
const PAGE$3 = 500;
|
|
6988
6988
|
/** Moves one bundle into or out of its platform's total and the overall total. */
|
|
6989
6989
|
const countBundle = (tx, platform, delta) => {
|
|
6990
6990
|
for (const key of [platform, "*"]) tx.aggregate("bundle_totals", { platform_key: key }, { bundles: delta });
|
|
@@ -7023,7 +7023,7 @@ const replaceBundlePatches = async (tx, bundle, rows, checkNew) => {
|
|
|
7023
7023
|
const page = await tx.findMany("bundle_patches", {
|
|
7024
7024
|
index: "byBundle",
|
|
7025
7025
|
where: { bundle_id: bundle.id },
|
|
7026
|
-
limit: Math.min(count - seen, PAGE$
|
|
7026
|
+
limit: Math.min(count - seen, PAGE$3),
|
|
7027
7027
|
...cursor === void 0 ? {} : { cursor }
|
|
7028
7028
|
});
|
|
7029
7029
|
for (const stored of page.rows) {
|
|
@@ -7587,7 +7587,7 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
7587
7587
|
});
|
|
7588
7588
|
//#endregion
|
|
7589
7589
|
//#region ../../packages/server/dist/core/releases.mjs
|
|
7590
|
-
const PAGE$
|
|
7590
|
+
const PAGE$2 = 500;
|
|
7591
7591
|
const fail$1 = (code, message) => {
|
|
7592
7592
|
throw new ReleaseCatalogMutationError(code, message);
|
|
7593
7593
|
};
|
|
@@ -7622,7 +7622,7 @@ const enabledIn = (scopeKey, cursor) => ({
|
|
|
7622
7622
|
scope_key: scopeKey,
|
|
7623
7623
|
enabled: true
|
|
7624
7624
|
},
|
|
7625
|
-
limit: PAGE$
|
|
7625
|
+
limit: PAGE$2,
|
|
7626
7626
|
...cursor === void 0 ? {} : { cursor }
|
|
7627
7627
|
});
|
|
7628
7628
|
/** A scope's enabled releases, all of them, under the catalog's guard. */
|
|
@@ -9491,7 +9491,8 @@ const createRequestHandler = ({ api, clientPolicy, privateResponses = false, rou
|
|
|
9491
9491
|
let authenticated;
|
|
9492
9492
|
try {
|
|
9493
9493
|
authenticated = await clientPolicy.authenticate(request);
|
|
9494
|
-
} catch {
|
|
9494
|
+
} catch (error) {
|
|
9495
|
+
console.error("Hot Updater client authentication failed:", error);
|
|
9495
9496
|
return errorResponse("Service unavailable", 503);
|
|
9496
9497
|
}
|
|
9497
9498
|
if (!authenticated) return errorResponse("Unauthorized", 401);
|
|
@@ -10036,21 +10037,29 @@ const isLaunch = (row) => {
|
|
|
10036
10037
|
const kinds = metadataOf(row).change?.kinds ?? [];
|
|
10037
10038
|
return kinds.includes("bundle") && !kinds.includes("first_seen") && row.to_release_id !== null;
|
|
10038
10039
|
};
|
|
10040
|
+
const sideRef = (key, releaseId, bundleId) => key === "release" ? releaseId ?? bundleId : bundleId;
|
|
10039
10041
|
/**
|
|
10040
10042
|
* The bundle a stored row's bundle filter matches: `from:<bundle>` for a
|
|
10041
10043
|
* recovery; `to:<bundle>` for a download, an apply, and an update failure;
|
|
10042
10044
|
* `on:<bundle>` for an UNCHANGED row that launched a bundle (`isLaunch`), a
|
|
10043
10045
|
* key no other row uses. None for a failed check, which targets no bundle, a
|
|
10044
|
-
* late row, or any other UNCHANGED row.
|
|
10046
|
+
* late row, or any other UNCHANGED row. Each names its bundle by `key`.
|
|
10045
10047
|
*/
|
|
10046
|
-
const bundleRefsOf = (row) => {
|
|
10048
|
+
const bundleRefsOf = (row, key = "release") => {
|
|
10047
10049
|
if (isFailedCheck(row) || isLateEvent(row)) return [];
|
|
10048
|
-
if (row.type === "RECOVERED") return [`from:${row.from_bundle_id}`];
|
|
10049
|
-
if (row.type === "UNCHANGED") return isLaunch(row) ? [`on:${row.to_bundle_id}`] : [];
|
|
10050
|
-
return [`to:${row.to_bundle_id}`];
|
|
10050
|
+
if (row.type === "RECOVERED") return [`from:${sideRef(key, row.from_release_id, row.from_bundle_id)}`];
|
|
10051
|
+
if (row.type === "UNCHANGED") return isLaunch(row) ? [`on:${sideRef(key, row.to_release_id, row.to_bundle_id)}`] : [];
|
|
10052
|
+
return [`to:${sideRef(key, row.to_release_id, row.to_bundle_id)}`];
|
|
10051
10053
|
};
|
|
10054
|
+
/**
|
|
10055
|
+
* The hourly outcome rows a stored row counts in, as `[type, bundle ref]`:
|
|
10056
|
+
* its bundle filter's (`bundleRefsOf`), and a download that a launch or
|
|
10057
|
+
* crash implied, in its bundle's download hour, so the download series
|
|
10058
|
+
* covers what the release's downloads count.
|
|
10059
|
+
*/
|
|
10060
|
+
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)}`]] : []];
|
|
10052
10061
|
/** The key a bundle filter reads, as `bundleRefsOf` writes it. */
|
|
10053
|
-
const bundleRefOfFilter = (filter) => filter.type === "RECOVERED" ? `from:${filter.
|
|
10062
|
+
const bundleRefOfFilter = (filter) => filter.type === "RECOVERED" ? `from:${filter.fromReleaseId}` : filter.type === "UNCHANGED" ? `on:${filter.toReleaseId}` : `to:${filter.toReleaseId}`;
|
|
10054
10063
|
/**
|
|
10055
10064
|
* Downloads, applies, recoveries, update failures, and the UNCHANGED
|
|
10056
10065
|
* reports that changed what their installation runs, whole. An UNCHANGED
|
|
@@ -10115,7 +10124,11 @@ const bundleEvents = (days) => defineTable({
|
|
|
10115
10124
|
type: "string",
|
|
10116
10125
|
compute: (row) => MOVEMENTS.has(row.type) ? row.install_id : null
|
|
10117
10126
|
},
|
|
10118
|
-
/**
|
|
10127
|
+
/**
|
|
10128
|
+
* The bundle a bundle filter matches (`bundleRefsOf`), by release.
|
|
10129
|
+
* Rows a 1.1 server wrote name the artifact until
|
|
10130
|
+
* `backfillReleaseRefs` rewrites them.
|
|
10131
|
+
*/
|
|
10119
10132
|
bundle_ref: {
|
|
10120
10133
|
type: "string",
|
|
10121
10134
|
multi: true,
|
|
@@ -10434,7 +10447,13 @@ const insightsBuiltinDistribution = (retention) => defineAggregate({
|
|
|
10434
10447
|
},
|
|
10435
10448
|
retention
|
|
10436
10449
|
});
|
|
10437
|
-
/**
|
|
10450
|
+
/**
|
|
10451
|
+
* Latest events by the artifact they came from or went to, bucketed like
|
|
10452
|
+
* the distribution, as 1.1 servers wrote them. Nothing writes or reads it
|
|
10453
|
+
* since a bundle's installations come from `insights_distribution`, which
|
|
10454
|
+
* names the release; it stays declared so retention still empties the rows
|
|
10455
|
+
* a 1.1 server wrote.
|
|
10456
|
+
*/
|
|
10438
10457
|
const insightsLatestByBundle = (retention) => defineAggregate({
|
|
10439
10458
|
platform: {
|
|
10440
10459
|
type: "string",
|
|
@@ -10482,7 +10501,9 @@ const insightsLatestByBundle = (retention) => defineAggregate({
|
|
|
10482
10501
|
* Stored events by outcome and the bundle a bundle filter matches, a row an
|
|
10483
10502
|
* hour, which a failed check has none of; and every stored event, a row a UTC
|
|
10484
10503
|
* day (`DAILY_EVENTS`). Bundle counts sum the hourly rows, and event lists
|
|
10485
|
-
* read either to skip days without events.
|
|
10504
|
+
* read either to skip days without events. `bundle_ref` names the release
|
|
10505
|
+
* (`outcomeRefsOf`); a 1.1 server's rows name the artifact until
|
|
10506
|
+
* `backfillReleaseRefs` moves their counts.
|
|
10486
10507
|
*/
|
|
10487
10508
|
const insightsOutcomes = (retention) => defineAggregate({
|
|
10488
10509
|
platform: {
|
|
@@ -10561,6 +10582,96 @@ const createInsightsSchema = ({ rawDays, dailyDays } = DEFAULT_INSIGHTS_RETENTIO
|
|
|
10561
10582
|
};
|
|
10562
10583
|
createInsightsSchema();
|
|
10563
10584
|
//#endregion
|
|
10585
|
+
//#region ../insights/dist/server/backfill.mjs
|
|
10586
|
+
/**
|
|
10587
|
+
* Stored events read a page, and rewritten up to `BATCH` a transaction. A
|
|
10588
|
+
* store that takes fewer physical writes a transaction, as DynamoDB's 100
|
|
10589
|
+
* items hold fewer than 25 rewrites with their index copies and counts,
|
|
10590
|
+
* refuses the batch before writing anything; it is then rewritten in halves.
|
|
10591
|
+
*/
|
|
10592
|
+
const PAGE$1 = 500;
|
|
10593
|
+
const BATCH = 25;
|
|
10594
|
+
const sameRefs = (stored, refs) => {
|
|
10595
|
+
const values = Array.isArray(stored) ? stored : [];
|
|
10596
|
+
return values.length === refs.length && values.every((value) => refs.includes(value));
|
|
10597
|
+
};
|
|
10598
|
+
/**
|
|
10599
|
+
* Whether a stored event still names its artifact, as a 1.1 server wrote
|
|
10600
|
+
* it: its stored refs are the artifact's and differ from the release's. Its
|
|
10601
|
+
* stored refs are how its outcome rows counted it, so they are what a
|
|
10602
|
+
* rewrite moves, and a rewritten event reads as done.
|
|
10603
|
+
*/
|
|
10604
|
+
const namesArtifact = (row) => {
|
|
10605
|
+
const byKey = (key) => bundleRefsOf(row, key);
|
|
10606
|
+
return sameRefs(row.bundle_ref, byKey("artifact")) && !sameRefs(row.bundle_ref, byKey("release"));
|
|
10607
|
+
};
|
|
10608
|
+
/**
|
|
10609
|
+
* Rewrites the stored events in the raw period whose refs name their
|
|
10610
|
+
* artifact, as 1.1 servers wrote them, to name their release, and moves
|
|
10611
|
+
* their hourly outcome counts with them, each event in the transaction that
|
|
10612
|
+
* rewrites it. Each event carries its own release IDs, so two releases of
|
|
10613
|
+
* one artifact in one scope come apart; an event without a release ID keeps
|
|
10614
|
+
* the bundle ID it reports, as new events do.
|
|
10615
|
+
*
|
|
10616
|
+
* It reads every stored event once and writes only those still to move, so
|
|
10617
|
+
* an interrupted run can run again. `hot-updater db migrate` and `hot-updater
|
|
10618
|
+
* init` run it once a database: when it completes they record the settings
|
|
10619
|
+
* row `insights.releaseRefs`, and later runs read no event. Installation
|
|
10620
|
+
* gauges need nothing: they name releases already.
|
|
10621
|
+
*/
|
|
10622
|
+
const backfillReleaseRefs = async (db, now, { rawDays }, { dryRun = false } = {}) => {
|
|
10623
|
+
const today = now() - now() % DAY_MS$1;
|
|
10624
|
+
let events = 0;
|
|
10625
|
+
const move = async (candidates) => {
|
|
10626
|
+
if (dryRun) {
|
|
10627
|
+
events += candidates.length;
|
|
10628
|
+
return;
|
|
10629
|
+
}
|
|
10630
|
+
const moved = await rewrite(candidates).catch(async (error) => {
|
|
10631
|
+
if (!(error instanceof DatabaseConstraintError) || error.reason !== "too_large" || candidates.length === 1) throw error;
|
|
10632
|
+
const half = Math.ceil(candidates.length / 2);
|
|
10633
|
+
await move(candidates.slice(0, half));
|
|
10634
|
+
await move(candidates.slice(half));
|
|
10635
|
+
return 0;
|
|
10636
|
+
});
|
|
10637
|
+
events += moved;
|
|
10638
|
+
};
|
|
10639
|
+
const rewrite = (candidates) => db.transaction(async (tx) => {
|
|
10640
|
+
const rows = await Promise.all(candidates.map(({ id }) => tx.findOne("bundle_events", { id })));
|
|
10641
|
+
let moved = 0;
|
|
10642
|
+
for (const row of rows) {
|
|
10643
|
+
if (row === null || !namesArtifact(row)) continue;
|
|
10644
|
+
tx.update("bundle_events", row, {});
|
|
10645
|
+
const outcome = (ref, delta) => tx.aggregate("insights_outcomes", {
|
|
10646
|
+
platform: row.platform,
|
|
10647
|
+
channel: row.channel,
|
|
10648
|
+
type: ref[0],
|
|
10649
|
+
bundle_ref: ref[1],
|
|
10650
|
+
bucket_start_ms: row.received_at_ms - row.received_at_ms % HOUR_MS$1
|
|
10651
|
+
}, { events: delta }, { shardBy: row.install_id });
|
|
10652
|
+
for (const ref of outcomeRefsOf(row, "artifact")) outcome(ref, -1);
|
|
10653
|
+
for (const ref of outcomeRefsOf(row, "release")) outcome(ref, 1);
|
|
10654
|
+
moved += 1;
|
|
10655
|
+
}
|
|
10656
|
+
return moved;
|
|
10657
|
+
});
|
|
10658
|
+
for (let day = today - rawDays * DAY_MS$1; day <= today; day += DAY_MS$1) {
|
|
10659
|
+
let cursor;
|
|
10660
|
+
do {
|
|
10661
|
+
const page = await db.findMany("bundle_events", {
|
|
10662
|
+
index: "byDay",
|
|
10663
|
+
where: { day },
|
|
10664
|
+
limit: PAGE$1,
|
|
10665
|
+
...cursor === void 0 ? {} : { cursor }
|
|
10666
|
+
});
|
|
10667
|
+
const stale = page.rows.filter(namesArtifact);
|
|
10668
|
+
for (let start = 0; start < stale.length; start += BATCH) await move(stale.slice(start, start + BATCH));
|
|
10669
|
+
cursor = page.next;
|
|
10670
|
+
} while (cursor !== void 0);
|
|
10671
|
+
}
|
|
10672
|
+
return { events };
|
|
10673
|
+
};
|
|
10674
|
+
//#endregion
|
|
10564
10675
|
//#region ../insights/dist/server/eventRow.mjs
|
|
10565
10676
|
const CHANGE_KINDS = /* @__PURE__ */ new Set([
|
|
10566
10677
|
"first_seen",
|
|
@@ -10657,7 +10768,7 @@ const isBundleFilter = (value, withKind = false) => {
|
|
|
10657
10768
|
"type",
|
|
10658
10769
|
...withKind ? ["kind"] : []
|
|
10659
10770
|
];
|
|
10660
|
-
return value.type === "RECOVERED" ? isText$1(value.
|
|
10771
|
+
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"]);
|
|
10661
10772
|
};
|
|
10662
10773
|
const isEventFilter = (value) => {
|
|
10663
10774
|
if (!isRecord$3(value)) return false;
|
|
@@ -10758,20 +10869,24 @@ const createValidatedInsightsModel = (model) => ({
|
|
|
10758
10869
|
if (!isRecord$3(input) || !hasOnlyKeys(input, [
|
|
10759
10870
|
"platform",
|
|
10760
10871
|
"channel",
|
|
10761
|
-
"sinceMs"
|
|
10762
|
-
|
|
10763
|
-
]) || !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, [
|
|
10764
|
-
"field",
|
|
10765
|
-
"value",
|
|
10766
|
-
"types"
|
|
10767
|
-
]) || 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) => ![
|
|
10768
|
-
"UNCHANGED",
|
|
10769
|
-
"UPDATE_DOWNLOADED",
|
|
10770
|
-
"UPDATE_APPLIED",
|
|
10771
|
-
"RECOVERED"
|
|
10772
|
-
].includes(type))))) invalidQuery();
|
|
10872
|
+
"sinceMs"
|
|
10873
|
+
]) || !hasScope(input) || !isTimestamp(input.sinceMs)) invalidQuery();
|
|
10773
10874
|
return validateCount(await model.countLatestEvents(input));
|
|
10774
10875
|
},
|
|
10876
|
+
async countReleaseInstallations(input) {
|
|
10877
|
+
if (!isRecord$3(input) || !hasOnlyKeys(input, [
|
|
10878
|
+
"platform",
|
|
10879
|
+
"channel",
|
|
10880
|
+
"sinceMs",
|
|
10881
|
+
"releaseId"
|
|
10882
|
+
]) || !hasScope(input) || !isTimestamp(input.sinceMs) || !isText$1(input.releaseId)) invalidQuery();
|
|
10883
|
+
const counts = await model.countReleaseInstallations(input);
|
|
10884
|
+
if (!isRecord$3(counts) || !hasOnlyKeys(counts, ["installations", "release"])) invalidResult();
|
|
10885
|
+
return {
|
|
10886
|
+
installations: validateCount(counts.installations),
|
|
10887
|
+
release: validateCount(counts.release)
|
|
10888
|
+
};
|
|
10889
|
+
},
|
|
10775
10890
|
async countEvents(input) {
|
|
10776
10891
|
if (!isRecord$3(input) || !hasOnlyKeys(input, [
|
|
10777
10892
|
"filter",
|
|
@@ -10828,6 +10943,7 @@ const createInsightsModel = (api) => createValidatedInsightsModel({
|
|
|
10828
10943
|
listEvents: api.listEvents,
|
|
10829
10944
|
findLatestEvents: api.findLatestEvents,
|
|
10830
10945
|
countLatestEvents: api.countLatestEvents,
|
|
10946
|
+
countReleaseInstallations: api.countReleaseInstallations,
|
|
10831
10947
|
countEvents: api.countEvents,
|
|
10832
10948
|
countEventSeries: api.countEventSeries,
|
|
10833
10949
|
getReleaseActivity: api.getReleaseActivity,
|
|
@@ -11230,27 +11346,27 @@ const readScope$1 = (input) => {
|
|
|
11230
11346
|
};
|
|
11231
11347
|
const bundleFilter = (input) => {
|
|
11232
11348
|
const scope = readScope$1(input);
|
|
11233
|
-
const
|
|
11349
|
+
const releaseId = requireString(input.releaseId, "bundle ID", MAX_EVENT_ID_LENGTH);
|
|
11234
11350
|
switch (input.outcome) {
|
|
11235
11351
|
case "downloaded": return {
|
|
11236
11352
|
...scope,
|
|
11237
11353
|
type: "UPDATE_DOWNLOADED",
|
|
11238
|
-
|
|
11354
|
+
toReleaseId: releaseId
|
|
11239
11355
|
};
|
|
11240
11356
|
case "applied": return {
|
|
11241
11357
|
...scope,
|
|
11242
11358
|
type: "UPDATE_APPLIED",
|
|
11243
|
-
|
|
11359
|
+
toReleaseId: releaseId
|
|
11244
11360
|
};
|
|
11245
11361
|
case "recovered": return {
|
|
11246
11362
|
...scope,
|
|
11247
11363
|
type: "RECOVERED",
|
|
11248
|
-
|
|
11364
|
+
fromReleaseId: releaseId
|
|
11249
11365
|
};
|
|
11250
11366
|
case "failed": return {
|
|
11251
11367
|
...scope,
|
|
11252
11368
|
type: "UPDATE_FAILED",
|
|
11253
|
-
|
|
11369
|
+
toReleaseId: releaseId
|
|
11254
11370
|
};
|
|
11255
11371
|
default: throw new InsightsBadRequestError("Invalid Insights outcome.");
|
|
11256
11372
|
}
|
|
@@ -11260,7 +11376,7 @@ const sameFilter = (left, right) => {
|
|
|
11260
11376
|
switch (right.kind) {
|
|
11261
11377
|
case "all": return true;
|
|
11262
11378
|
case "installationMovement": return left.installId === right.installId;
|
|
11263
|
-
case "bundle": return left.platform === right.platform && left.channel === right.channel && left.type === right.type && (right.type === "RECOVERED" ? left.
|
|
11379
|
+
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);
|
|
11264
11380
|
}
|
|
11265
11381
|
};
|
|
11266
11382
|
const readEventCursor = (value, filter) => {
|
|
@@ -11297,7 +11413,7 @@ const assertEventRows = (rows, input) => {
|
|
|
11297
11413
|
for (let index = 0; index < rows.length; index += 1) {
|
|
11298
11414
|
const row = rows[index];
|
|
11299
11415
|
const previous = rows[index - 1];
|
|
11300
|
-
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.
|
|
11416
|
+
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.");
|
|
11301
11417
|
}
|
|
11302
11418
|
};
|
|
11303
11419
|
/** An `UPDATE_FAILED` row's failure, as the event lists show it. */
|
|
@@ -11338,6 +11454,7 @@ const eventDetails = ({ type, metadata }) => ({
|
|
|
11338
11454
|
...metadata.implied_download === true ? { impliedDownload: true } : {}
|
|
11339
11455
|
});
|
|
11340
11456
|
const toEventHistoryRow = (row) => ({
|
|
11457
|
+
...row.from_release_id == null ? {} : { fromReleaseId: row.from_release_id },
|
|
11341
11458
|
...row.to_release_id == null ? {} : { toReleaseId: row.to_release_id },
|
|
11342
11459
|
...row.metadata.sdk_version == null ? {} : { sdkVersion: row.metadata.sdk_version },
|
|
11343
11460
|
...row.metadata.min_bundle_id === void 0 ? {} : { minBundleId: row.metadata.min_bundle_id },
|
|
@@ -11362,6 +11479,7 @@ const toInstallationRow = (row) => ({
|
|
|
11362
11479
|
cohort: row.metadata.cohort,
|
|
11363
11480
|
installId: row.install_id,
|
|
11364
11481
|
lastKnownBundleId: row.type === "UPDATE_DOWNLOADED" ? row.from_bundle_id : row.to_bundle_id,
|
|
11482
|
+
lastKnownReleaseId: row.type === "UPDATE_DOWNLOADED" ? row.from_release_id : row.to_release_id,
|
|
11365
11483
|
pendingBundleId: row.type === "UPDATE_DOWNLOADED" ? row.to_bundle_id : null,
|
|
11366
11484
|
pendingReleaseId: row.type === "UPDATE_DOWNLOADED" ? row.to_release_id : null,
|
|
11367
11485
|
latestStatus: row.type,
|
|
@@ -11490,46 +11608,33 @@ const createInsightsProvider = (model) => Object.freeze({
|
|
|
11490
11608
|
measuredAtMs: Date.now()
|
|
11491
11609
|
};
|
|
11492
11610
|
};
|
|
11493
|
-
const
|
|
11494
|
-
|
|
11495
|
-
...scope,
|
|
11496
|
-
sinceMs
|
|
11497
|
-
}));
|
|
11498
|
-
if (bundleId === void 0) return {
|
|
11611
|
+
const releaseId = input.releaseId === void 0 ? void 0 : requireString(input.releaseId, "bundle ID", MAX_EVENT_ID_LENGTH);
|
|
11612
|
+
if (releaseId === void 0) return {
|
|
11499
11613
|
...scope,
|
|
11500
11614
|
window,
|
|
11501
11615
|
sinceMs,
|
|
11502
11616
|
beforeReceivedAtMs,
|
|
11503
|
-
reportingInstallations: await
|
|
11617
|
+
reportingInstallations: await measure(model.countLatestEvents({
|
|
11618
|
+
...scope,
|
|
11619
|
+
sinceMs
|
|
11620
|
+
}))
|
|
11504
11621
|
};
|
|
11622
|
+
const installations = model.countReleaseInstallations({
|
|
11623
|
+
...scope,
|
|
11624
|
+
sinceMs,
|
|
11625
|
+
releaseId
|
|
11626
|
+
}).then(async (counts) => [await measure(Promise.resolve(counts.installations)), await measure(Promise.resolve(counts.release))]);
|
|
11505
11627
|
const countOutcome = (outcome) => measure(model.countEvents({
|
|
11506
11628
|
filter: bundleFilter({
|
|
11507
11629
|
...scope,
|
|
11508
|
-
|
|
11630
|
+
releaseId,
|
|
11509
11631
|
outcome
|
|
11510
11632
|
}),
|
|
11511
11633
|
sinceMs,
|
|
11512
11634
|
beforeReceivedAtMs
|
|
11513
11635
|
}));
|
|
11514
|
-
const [reportingInstallations, bundleInstallations, downloadedReports, appliedReports, recoveredReports, failedReports] = await Promise.all([
|
|
11515
|
-
|
|
11516
|
-
measure(model.countLatestEvents({
|
|
11517
|
-
...scope,
|
|
11518
|
-
sinceMs,
|
|
11519
|
-
bundle: [{
|
|
11520
|
-
field: "from_bundle_id",
|
|
11521
|
-
value: bundleId,
|
|
11522
|
-
types: ["UPDATE_DOWNLOADED"]
|
|
11523
|
-
}, {
|
|
11524
|
-
field: "to_bundle_id",
|
|
11525
|
-
value: bundleId,
|
|
11526
|
-
types: [
|
|
11527
|
-
"UNCHANGED",
|
|
11528
|
-
"UPDATE_APPLIED",
|
|
11529
|
-
"RECOVERED"
|
|
11530
|
-
]
|
|
11531
|
-
}]
|
|
11532
|
-
})),
|
|
11636
|
+
const [[reportingInstallations, bundleInstallations], downloadedReports, appliedReports, recoveredReports, failedReports] = await Promise.all([
|
|
11637
|
+
installations,
|
|
11533
11638
|
countOutcome("downloaded"),
|
|
11534
11639
|
countOutcome("applied"),
|
|
11535
11640
|
countOutcome("recovered"),
|
|
@@ -11542,7 +11647,7 @@ const createInsightsProvider = (model) => Object.freeze({
|
|
|
11542
11647
|
beforeReceivedAtMs,
|
|
11543
11648
|
reportingInstallations,
|
|
11544
11649
|
bundle: {
|
|
11545
|
-
|
|
11650
|
+
releaseId,
|
|
11546
11651
|
reportingInstallations: bundleInstallations,
|
|
11547
11652
|
downloadedReports,
|
|
11548
11653
|
appliedReports,
|
|
@@ -11677,17 +11782,10 @@ const gaugeSlot = (head) => ({
|
|
|
11677
11782
|
builtinBundleId: runningBuiltinBundleId(head)
|
|
11678
11783
|
});
|
|
11679
11784
|
/**
|
|
11680
|
-
* The `insights_latest_by_bundle` field of a head's (from, to) pair. A head
|
|
11681
|
-
* matches a `from` and a `to` predicate of one type at once only through its
|
|
11682
|
-
* pair, so this gauge is what a count subtracts to count it once.
|
|
11683
|
-
*/
|
|
11684
|
-
const PAIR_FIELD = "from_to";
|
|
11685
|
-
/** The pair gauge's `bundle_id`: a hash of the two bundle ids, which fit no single 36-character column. */
|
|
11686
|
-
const bundlePairKey = (from, to) => insightsKey(`${from.length}:${from}${to.length}:${to}`);
|
|
11687
|
-
/**
|
|
11688
11785
|
* Moves a head's gauges: the distribution row, and the built-in one when it
|
|
11689
|
-
* runs its build's built-in bundle
|
|
11690
|
-
*
|
|
11786
|
+
* runs its build's built-in bundle; -1 takes back the head an event
|
|
11787
|
+
* replaces. The distribution row names the release the head runs, so it is
|
|
11788
|
+
* also each release's installation gauge.
|
|
11691
11789
|
*/
|
|
11692
11790
|
const countHead = (tx, head, delta) => {
|
|
11693
11791
|
const { bucket, releaseId, builtinBundleId } = gaugeSlot(head);
|
|
@@ -11707,26 +11805,6 @@ const countHead = (tx, head, delta) => {
|
|
|
11707
11805
|
builtin_bundle_id: builtinBundleId,
|
|
11708
11806
|
bucket_start_ms: bucket
|
|
11709
11807
|
}, { latest_installations: delta }, { shardBy });
|
|
11710
|
-
for (const field of ["from_bundle_id", "to_bundle_id"]) {
|
|
11711
|
-
const bundleId = head[field];
|
|
11712
|
-
if (bundleId === null) continue;
|
|
11713
|
-
tx.aggregate("insights_latest_by_bundle", {
|
|
11714
|
-
platform: head.platform,
|
|
11715
|
-
channel: head.channel,
|
|
11716
|
-
bundle_field: field,
|
|
11717
|
-
bundle_id: bundleId,
|
|
11718
|
-
type: head.type,
|
|
11719
|
-
bucket_start_ms: bucket
|
|
11720
|
-
}, { installations: delta }, { shardBy });
|
|
11721
|
-
}
|
|
11722
|
-
if (head.from_bundle_id !== null) tx.aggregate("insights_latest_by_bundle", {
|
|
11723
|
-
platform: head.platform,
|
|
11724
|
-
channel: head.channel,
|
|
11725
|
-
bundle_field: PAIR_FIELD,
|
|
11726
|
-
bundle_id: bundlePairKey(head.from_bundle_id, head.to_bundle_id),
|
|
11727
|
-
type: head.type,
|
|
11728
|
-
bucket_start_ms: bucket
|
|
11729
|
-
}, { installations: delta }, { shardBy });
|
|
11730
11808
|
};
|
|
11731
11809
|
/**
|
|
11732
11810
|
* Where each period's rows go, each with its retention: hours for 90 days,
|
|
@@ -11787,26 +11865,19 @@ const countEvent = (tx, event) => {
|
|
|
11787
11865
|
}
|
|
11788
11866
|
};
|
|
11789
11867
|
/**
|
|
11790
|
-
* A stored event's outcome rows: its bundle filter's hour,
|
|
11791
|
-
*
|
|
11792
|
-
*
|
|
11793
|
-
* hour of that launch or crash, so the download series covers what the
|
|
11794
|
-
* release's downloads count; the launch or crash is its row.
|
|
11868
|
+
* A stored event's outcome rows: its bundle filter's hour, and the download
|
|
11869
|
+
* hour of a download its launch or crash implied, each by release
|
|
11870
|
+
* (`outcomeRefsOf`); and every stored event's UTC day.
|
|
11795
11871
|
*/
|
|
11796
11872
|
const countOutcome = (tx, event) => {
|
|
11797
11873
|
const shardBy = event.install_id;
|
|
11798
|
-
const
|
|
11874
|
+
for (const [type, bundleRef] of outcomeRefsOf(event)) tx.aggregate("insights_outcomes", {
|
|
11799
11875
|
platform: event.platform,
|
|
11800
11876
|
channel: event.channel,
|
|
11801
11877
|
type,
|
|
11802
11878
|
bundle_ref: bundleRef,
|
|
11803
11879
|
bucket_start_ms: hourOf(event.received_at_ms)
|
|
11804
11880
|
}, { events: 1 }, { shardBy });
|
|
11805
|
-
for (const bundleRef of bundleRefsOf(event)) hour(event.type, bundleRef);
|
|
11806
|
-
if (event.metadata.implied_download === true) hour("UPDATE_DOWNLOADED", bundleRefOfFilter({
|
|
11807
|
-
type: "UPDATE_DOWNLOADED",
|
|
11808
|
-
toBundleId: event.type === "RECOVERED" ? event.from_bundle_id : event.to_bundle_id
|
|
11809
|
-
}));
|
|
11810
11881
|
tx.aggregate("insights_outcomes", {
|
|
11811
11882
|
...DAILY_EVENTS,
|
|
11812
11883
|
bucket_start_ms: dayOf(event.received_at_ms)
|
|
@@ -12286,31 +12357,48 @@ const countEventSeries = async (db, input) => {
|
|
|
12286
12357
|
events: count
|
|
12287
12358
|
}));
|
|
12288
12359
|
};
|
|
12289
|
-
/**
|
|
12290
|
-
const
|
|
12291
|
-
if (
|
|
12292
|
-
return
|
|
12293
|
-
|
|
12294
|
-
|
|
12295
|
-
|
|
12296
|
-
|
|
12297
|
-
|
|
12298
|
-
|
|
12299
|
-
|
|
12300
|
-
|
|
12360
|
+
/** The distribution rows at or after `start`, a UTC day's start. */
|
|
12361
|
+
const distributionRows = (db, { platform, channel, sinceMs: start }) => {
|
|
12362
|
+
if (start % 864e5 !== 0) throw new DatabaseAdapterInputError("invalid-query");
|
|
12363
|
+
return drain((page) => db.findAggregates("insights_distribution", {
|
|
12364
|
+
index: "byScope",
|
|
12365
|
+
where: {
|
|
12366
|
+
channel,
|
|
12367
|
+
platform
|
|
12368
|
+
},
|
|
12369
|
+
range: { gte: start },
|
|
12370
|
+
limit: PAGE,
|
|
12371
|
+
...page
|
|
12372
|
+
}));
|
|
12301
12373
|
};
|
|
12374
|
+
const installations = (count) => Math.max(0, count);
|
|
12302
12375
|
/**
|
|
12303
12376
|
* Latest events at or after `sinceMs`, a UTC day's start: the gauges count
|
|
12304
12377
|
* each installation in the UTC day of its latest event, so they answer whole
|
|
12305
12378
|
* days only, and a later start is rejected rather than rounded.
|
|
12306
12379
|
*/
|
|
12307
|
-
const countLatestEvents = async (db, input) =>
|
|
12308
|
-
|
|
12309
|
-
|
|
12310
|
-
|
|
12380
|
+
const countLatestEvents = async (db, input) => installations((await distributionRows(db, input)).reduce((sum, row) => sum + row.latest_installations, 0));
|
|
12381
|
+
/**
|
|
12382
|
+
* `countLatestEvents`, and of those the installations it leaves running
|
|
12383
|
+
* `releaseId`, from the same distribution rows in one read: each names the
|
|
12384
|
+
* release its installations run. An ID no row names as a release may be a
|
|
12385
|
+
* built-in bundle's, which a report without a release names, as event
|
|
12386
|
+
* counts match it: its installations outside any release are in the
|
|
12387
|
+
* built-in rows, read only then. Release and bundle IDs never coincide.
|
|
12388
|
+
*/
|
|
12389
|
+
const countReleaseInstallations = async (db, input) => {
|
|
12390
|
+
const { platform, channel, sinceMs: start, releaseId } = input;
|
|
12311
12391
|
let total = 0;
|
|
12312
|
-
|
|
12313
|
-
|
|
12392
|
+
let release = 0;
|
|
12393
|
+
let named = false;
|
|
12394
|
+
for (const row of await distributionRows(db, input)) {
|
|
12395
|
+
total += row.latest_installations;
|
|
12396
|
+
if (row.release_id !== releaseId) continue;
|
|
12397
|
+
named = true;
|
|
12398
|
+
release += row.latest_installations;
|
|
12399
|
+
}
|
|
12400
|
+
if (!named) {
|
|
12401
|
+
const builtin = await drain((page) => db.findAggregates("insights_builtin_distribution", {
|
|
12314
12402
|
index: "byScope",
|
|
12315
12403
|
where: {
|
|
12316
12404
|
channel,
|
|
@@ -12320,33 +12408,12 @@ const countLatestEvents = async (db, input) => {
|
|
|
12320
12408
|
limit: PAGE,
|
|
12321
12409
|
...page
|
|
12322
12410
|
}));
|
|
12323
|
-
|
|
12324
|
-
} else {
|
|
12325
|
-
const gauge = async (bundleField, bundleId, type) => {
|
|
12326
|
-
return (await drain((page) => db.findAggregates("insights_latest_by_bundle", {
|
|
12327
|
-
index: "byBundle",
|
|
12328
|
-
where: {
|
|
12329
|
-
platform,
|
|
12330
|
-
channel,
|
|
12331
|
-
bundle_field: bundleField,
|
|
12332
|
-
bundle_id: bundleId,
|
|
12333
|
-
type
|
|
12334
|
-
},
|
|
12335
|
-
range: { gte: start },
|
|
12336
|
-
limit: PAGE,
|
|
12337
|
-
...page
|
|
12338
|
-
}))).reduce((sum, row) => sum + row.installations, 0);
|
|
12339
|
-
};
|
|
12340
|
-
for (const { field, value, type } of predicates) total += await gauge(field, value, type);
|
|
12341
|
-
for (const from of predicates) {
|
|
12342
|
-
if (from.field !== "from_bundle_id") continue;
|
|
12343
|
-
for (const to of predicates) {
|
|
12344
|
-
if (to.field !== "to_bundle_id" || to.type !== from.type) continue;
|
|
12345
|
-
total -= await gauge(PAIR_FIELD, bundlePairKey(from.value, to.value), from.type);
|
|
12346
|
-
}
|
|
12347
|
-
}
|
|
12411
|
+
for (const row of builtin) if (row.release_id === "" && row.builtin_bundle_id === releaseId) release += row.latest_installations;
|
|
12348
12412
|
}
|
|
12349
|
-
return
|
|
12413
|
+
return {
|
|
12414
|
+
installations: installations(total),
|
|
12415
|
+
release: installations(release)
|
|
12416
|
+
};
|
|
12350
12417
|
};
|
|
12351
12418
|
/** The oldest whole hour and UTC day that hourly and daily rows still hold. */
|
|
12352
12419
|
const retained = (now, { rawDays, dailyDays }) => ({
|
|
@@ -12816,6 +12883,26 @@ const getUpdateFailures = async (db, input, now, retention) => {
|
|
|
12816
12883
|
};
|
|
12817
12884
|
};
|
|
12818
12885
|
//#endregion
|
|
12886
|
+
//#region ../insights/dist/server/wire.mjs
|
|
12887
|
+
/**
|
|
12888
|
+
* The HTTP API calls a release ID `bundleId`, the word users have for it, in
|
|
12889
|
+
* its query parameters and its overview's JSON. The code calls it
|
|
12890
|
+
* `releaseId`; only this module maps between the two names.
|
|
12891
|
+
*/
|
|
12892
|
+
const RELEASE_ID_PARAM = "bundleId";
|
|
12893
|
+
/** An overview as the HTTP API and the CLI's `--json` send it. */
|
|
12894
|
+
const toWireOverview = ({ bundle, ...overview }) => {
|
|
12895
|
+
if (bundle === void 0) return overview;
|
|
12896
|
+
const { releaseId, ...counts } = bundle;
|
|
12897
|
+
return {
|
|
12898
|
+
...overview,
|
|
12899
|
+
bundle: {
|
|
12900
|
+
...counts,
|
|
12901
|
+
bundleId: releaseId
|
|
12902
|
+
}
|
|
12903
|
+
};
|
|
12904
|
+
};
|
|
12905
|
+
//#endregion
|
|
12819
12906
|
//#region ../insights/dist/server/queryInput.mjs
|
|
12820
12907
|
const MAX_PAGE_LIMIT = 100;
|
|
12821
12908
|
const MAX_IDENTITY_LENGTH = 255;
|
|
@@ -12860,7 +12947,7 @@ const readScope = (url) => {
|
|
|
12860
12947
|
const parseEventPageInput = (request) => {
|
|
12861
12948
|
const url = new URL(request.url);
|
|
12862
12949
|
const bundleFields = [
|
|
12863
|
-
|
|
12950
|
+
RELEASE_ID_PARAM,
|
|
12864
12951
|
"outcome",
|
|
12865
12952
|
"platform",
|
|
12866
12953
|
"channel"
|
|
@@ -12871,7 +12958,7 @@ const parseEventPageInput = (request) => {
|
|
|
12871
12958
|
if (outcome !== "downloaded" && outcome !== "applied" && outcome !== "recovered" && outcome !== "failed") throw new InsightsBadRequestError("Invalid 'outcome' query parameter.");
|
|
12872
12959
|
bundle = {
|
|
12873
12960
|
...readScope(url),
|
|
12874
|
-
|
|
12961
|
+
releaseId: readId(url, RELEASE_ID_PARAM, 1024),
|
|
12875
12962
|
outcome
|
|
12876
12963
|
};
|
|
12877
12964
|
}
|
|
@@ -12897,11 +12984,10 @@ const parseReportingOverviewInput = (request) => {
|
|
|
12897
12984
|
const url = new URL(request.url);
|
|
12898
12985
|
const window = readSingle(url, "window") ?? "30d";
|
|
12899
12986
|
if (window !== "24h" && window !== "7d" && window !== "30d") throw new InsightsBadRequestError("Invalid 'window' query parameter.");
|
|
12900
|
-
const bundleId = readSingle(url, "bundleId");
|
|
12901
12987
|
return {
|
|
12902
12988
|
...readScope(url),
|
|
12903
12989
|
window,
|
|
12904
|
-
...bundleId === void 0 ? {} : {
|
|
12990
|
+
...readSingle(url, "bundleId") === void 0 ? {} : { releaseId: readId(url, RELEASE_ID_PARAM, 1024) }
|
|
12905
12991
|
};
|
|
12906
12992
|
};
|
|
12907
12993
|
//#endregion
|
|
@@ -12982,7 +13068,7 @@ const createInsightsRouteHandlers = (provider) => ({
|
|
|
12982
13068
|
await provider.appendBundleEvent(await parseBundleEventRequest(request));
|
|
12983
13069
|
return new Response(null, { status: 204 });
|
|
12984
13070
|
}),
|
|
12985
|
-
getReportingOverview: (_params, request) => query(() => provider.getReportingOverview(parseReportingOverviewInput(request))),
|
|
13071
|
+
getReportingOverview: (_params, request) => query(async () => toWireOverview(await provider.getReportingOverview(parseReportingOverviewInput(request)))),
|
|
12986
13072
|
getInstallation: (params) => run$1(async () => {
|
|
12987
13073
|
const installation = await provider.getInstallation({ installId: requireParam(params, "installId") });
|
|
12988
13074
|
return installation === null ? json$1({ error: "Installation not found" }, 404) : json$1(installation, 200);
|
|
@@ -13004,12 +13090,20 @@ const createInsightsApi = (db, now, retention) => ({
|
|
|
13004
13090
|
listEvents: (input) => listEvents(db, input),
|
|
13005
13091
|
findLatestEvents: (input) => findLatestEvents(db, input),
|
|
13006
13092
|
countLatestEvents: (input) => countLatestEvents(db, input),
|
|
13093
|
+
countReleaseInstallations: (input) => countReleaseInstallations(db, input),
|
|
13007
13094
|
countEvents: (input) => countEvents(db, input),
|
|
13008
13095
|
countEventSeries: (input) => countEventSeries(db, input),
|
|
13009
13096
|
getReleaseActivity: (input) => getReleaseActivity(db, input, now),
|
|
13010
13097
|
getAppUsage: (input) => getAppUsage(db, input, now, retention),
|
|
13011
13098
|
/** A release's or a channel's update failures, and their breakdown over a time range. */
|
|
13012
|
-
getUpdateFailures: (input) => getUpdateFailures(db, input, now, retention)
|
|
13099
|
+
getUpdateFailures: (input) => getUpdateFailures(db, input, now, retention),
|
|
13100
|
+
/**
|
|
13101
|
+
* Moves the stored events a 1.1 server keyed by artifact, and their
|
|
13102
|
+
* outcome counts, to their release, reading every stored event of the
|
|
13103
|
+
* raw period: `hot-updater db migrate` and `hot-updater init` run it once
|
|
13104
|
+
* a database, and an interrupted run can run again.
|
|
13105
|
+
*/
|
|
13106
|
+
backfillReleaseRefs: (options) => backfillReleaseRefs(db, now, retention, options)
|
|
13013
13107
|
});
|
|
13014
13108
|
/** `GET /failures`'s query: a scope, an optional release, and a time range or none. */
|
|
13015
13109
|
const readFailuresQuery = (url) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/aws",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.58",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"es-toolkit": "^1.32.0",
|
|
46
46
|
"execa": "9.5.2",
|
|
47
47
|
"mime": "^4.0.4",
|
|
48
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
49
|
-
"@hot-updater/mock": "1.2.0-rc.
|
|
50
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
48
|
+
"@hot-updater/protocol": "1.2.0-rc.58",
|
|
49
|
+
"@hot-updater/mock": "1.2.0-rc.58",
|
|
50
|
+
"@hot-updater/test-utils": "1.2.0-rc.58"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@aws-sdk/client-cloudfront": "3.1066.0",
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
"@aws-sdk/lib-dynamodb": "3.1066.0",
|
|
65
65
|
"@aws-sdk/s3-request-presigner": "3.1066.0",
|
|
66
66
|
"hono": "4.12.34",
|
|
67
|
-
"@hot-updater/cli-tools": "1.2.0-rc.
|
|
68
|
-
"@hot-updater/plugin-core": "1.2.0-rc.
|
|
69
|
-
"@hot-updater/server": "1.2.0-rc.
|
|
70
|
-
"@hot-updater/storage-s3": "1.2.0-rc.
|
|
67
|
+
"@hot-updater/cli-tools": "1.2.0-rc.58",
|
|
68
|
+
"@hot-updater/plugin-core": "1.2.0-rc.58",
|
|
69
|
+
"@hot-updater/server": "1.2.0-rc.58",
|
|
70
|
+
"@hot-updater/storage-s3": "1.2.0-rc.58"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "tsdown",
|