@hot-updater/vercel 1.2.0-rc.49 → 1.2.0-rc.50
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/function/index.mjs +375 -151
- package/dist/init/index.cjs +3 -2
- package/dist/init/index.mjs +4 -3
- package/package.json +7 -7
package/dist/function/index.mjs
CHANGED
|
@@ -1969,43 +1969,6 @@ const withSchemaFence = (adapter, adapterName, expected, fix) => {
|
|
|
1969
1969
|
const METER = Symbol.for("@hot-updater/plugin-core/read-meter");
|
|
1970
1970
|
const readMeterOf = (database) => typeof database === "object" && database !== null ? database[METER] : void 0;
|
|
1971
1971
|
//#endregion
|
|
1972
|
-
//#region ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
1973
|
-
const storedSettings = async (adapter, keys) => {
|
|
1974
|
-
const rows = await readSettings(adapter, keys);
|
|
1975
|
-
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
1976
|
-
};
|
|
1977
|
-
const writeSchemaSettings = async (adapter, adapterName, settings) => {
|
|
1978
|
-
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
1979
|
-
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
1980
|
-
const row = stored.get(key);
|
|
1981
|
-
if (row === null || row === void 0) return [{
|
|
1982
|
-
type: "insert",
|
|
1983
|
-
table: SETTINGS_TABLE,
|
|
1984
|
-
row: {
|
|
1985
|
-
key,
|
|
1986
|
-
value,
|
|
1987
|
-
_v: 0
|
|
1988
|
-
}
|
|
1989
|
-
}];
|
|
1990
|
-
if (row.value === value) return [];
|
|
1991
|
-
return [{
|
|
1992
|
-
type: "patch",
|
|
1993
|
-
table: SETTINGS_TABLE,
|
|
1994
|
-
key: [key],
|
|
1995
|
-
set: { value },
|
|
1996
|
-
guard: { v: Number(row._v) },
|
|
1997
|
-
previous: row
|
|
1998
|
-
}];
|
|
1999
|
-
});
|
|
2000
|
-
if (ops.length === 0) return;
|
|
2001
|
-
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
2002
|
-
};
|
|
2003
|
-
const migrateSchema = async (adapter, adapterName, tables, settings) => {
|
|
2004
|
-
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2005
|
-
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2006
|
-
await writeSchemaSettings(adapter, adapterName, settings);
|
|
2007
|
-
};
|
|
2008
|
-
//#endregion
|
|
2009
1972
|
//#region ../plugin-core/dist/engine/database/sql/sqlSchema.mjs
|
|
2010
1973
|
const quoteSql = (dialect, name) => dialect === "mysql" ? `\`${name.replaceAll("`", "``")}\`` : `"${name.replaceAll("\"", "\"\"")}"`;
|
|
2011
1974
|
const isMultiIndex = (table, index) => index.eq.some((column) => findPhysicalColumn(table, column).multi);
|
|
@@ -2049,6 +2012,7 @@ const sqlTableShapes = (dialect, tables, tablePrefix = "") => tables.map((table)
|
|
|
2049
2012
|
const name = tablePrefix + table.name;
|
|
2050
2013
|
const indexed = /* @__PURE__ */ new Set([...table.key, ...table.indexes.flatMap(({ eq, sort }) => [...eq, ...sort])]);
|
|
2051
2014
|
if (dialect === "mysql") checkMysqlKey(table, "key", table.key);
|
|
2015
|
+
const covered = /* @__PURE__ */ new Set([JSON.stringify(table.key)]);
|
|
2052
2016
|
const indexes = table.indexes.flatMap((index) => {
|
|
2053
2017
|
const columns = [...index.eq, ...indexOrderColumns(table, index)];
|
|
2054
2018
|
if (dialect === "mysql") checkMysqlKey(table, `index ${index.name}`, columns);
|
|
@@ -2073,7 +2037,10 @@ const sqlTableShapes = (dialect, tables, tablePrefix = "") => tables.map((table)
|
|
|
2073
2037
|
}
|
|
2074
2038
|
}];
|
|
2075
2039
|
}
|
|
2076
|
-
if (!index.unique
|
|
2040
|
+
if (!index.unique) {
|
|
2041
|
+
if (covered.has(JSON.stringify(columns))) return [];
|
|
2042
|
+
covered.add(JSON.stringify(columns));
|
|
2043
|
+
}
|
|
2077
2044
|
return [{
|
|
2078
2045
|
kind: "index",
|
|
2079
2046
|
name: shortSqlName(`${name}_${index.name}`),
|
|
@@ -2340,9 +2307,17 @@ const releases = defineTable({
|
|
|
2340
2307
|
all: {
|
|
2341
2308
|
eq: [],
|
|
2342
2309
|
sort: ["id"]
|
|
2310
|
+
},
|
|
2311
|
+
scopes: {
|
|
2312
|
+
eq: [],
|
|
2313
|
+
sort: ["scope_key"]
|
|
2343
2314
|
}
|
|
2344
2315
|
}
|
|
2345
2316
|
});
|
|
2317
|
+
const LATE_INDEXES = [{
|
|
2318
|
+
table: "releases",
|
|
2319
|
+
index: "scopes"
|
|
2320
|
+
}];
|
|
2346
2321
|
const releaseCatalogs = defineTable({
|
|
2347
2322
|
scope_key: {
|
|
2348
2323
|
type: "string",
|
|
@@ -2670,6 +2645,90 @@ const refuseV0Database = (adapterName, stored) => {
|
|
|
2670
2645
|
if (typeof version !== "string" || stored.has("schema.engine")) return;
|
|
2671
2646
|
throw new HotUpdaterSchemaMigrationRequiredError(adapterName, version);
|
|
2672
2647
|
};
|
|
2648
|
+
const compareVersions = (left, right) => {
|
|
2649
|
+
const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
|
|
2650
|
+
const [a, b] = [parse(left), parse(right)];
|
|
2651
|
+
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
2652
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
2653
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
2654
|
+
if (difference !== 0) return difference;
|
|
2655
|
+
}
|
|
2656
|
+
return 0;
|
|
2657
|
+
};
|
|
2658
|
+
const DEFAULT_ORDERED_SETTINGS = ["schema.core"];
|
|
2659
|
+
const refuseNewerSchema = (adapterName, stored, settings, ordered = DEFAULT_ORDERED_SETTINGS) => {
|
|
2660
|
+
const newer = ordered.flatMap((key) => {
|
|
2661
|
+
const found = stored.get(key);
|
|
2662
|
+
const expected = settings[key];
|
|
2663
|
+
return typeof found === "string" && expected !== void 0 && compareVersions(found, expected) > 0 ? [{
|
|
2664
|
+
key,
|
|
2665
|
+
found,
|
|
2666
|
+
expected
|
|
2667
|
+
}] : [];
|
|
2668
|
+
});
|
|
2669
|
+
const core = newer.find(({ key }) => key === "schema.core");
|
|
2670
|
+
if (core === void 0) return;
|
|
2671
|
+
throw new Error(`${adapterName}: the database was migrated by Hot Updater ${core.found} (${newer.map(({ key, found, expected }) => `${key} "${found}", this CLI's "${expected}"`).join("; ")}). Upgrade hot-updater to ${core.found} or later; nothing was written.`);
|
|
2672
|
+
};
|
|
2673
|
+
const settingsOperation = (stored, changed) => ({
|
|
2674
|
+
type: "custom",
|
|
2675
|
+
description: `Record ${changed.map(([key, value]) => {
|
|
2676
|
+
const found = stored.get(key);
|
|
2677
|
+
return typeof found === "string" ? `${key} ${found} → ${value}` : `${key} ${value}`;
|
|
2678
|
+
}).join(", ")}`
|
|
2679
|
+
});
|
|
2680
|
+
//#endregion
|
|
2681
|
+
//#region ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
2682
|
+
const storedSettings = async (adapter, keys) => {
|
|
2683
|
+
const rows = await readSettings(adapter, keys);
|
|
2684
|
+
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
2685
|
+
};
|
|
2686
|
+
const writeSchemaSettings = async (adapter, adapterName, settings, ordered) => {
|
|
2687
|
+
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
2688
|
+
refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2689
|
+
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
2690
|
+
const row = stored.get(key);
|
|
2691
|
+
if (row === null || row === void 0) return [{
|
|
2692
|
+
type: "insert",
|
|
2693
|
+
table: SETTINGS_TABLE,
|
|
2694
|
+
row: {
|
|
2695
|
+
key,
|
|
2696
|
+
value,
|
|
2697
|
+
_v: 0
|
|
2698
|
+
}
|
|
2699
|
+
}];
|
|
2700
|
+
if (row.value === value) return [];
|
|
2701
|
+
return [{
|
|
2702
|
+
type: "patch",
|
|
2703
|
+
table: SETTINGS_TABLE,
|
|
2704
|
+
key: [key],
|
|
2705
|
+
set: { value },
|
|
2706
|
+
guard: { v: Number(row._v) },
|
|
2707
|
+
previous: row
|
|
2708
|
+
}];
|
|
2709
|
+
});
|
|
2710
|
+
if (ops.length === 0) return;
|
|
2711
|
+
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
2712
|
+
};
|
|
2713
|
+
const fillLateIndexes = async (adapter, tables, { dryRun = false } = {}) => {
|
|
2714
|
+
const fillIndex = adapter.migrations?.fillIndex;
|
|
2715
|
+
if (fillIndex === void 0) return [];
|
|
2716
|
+
const lacking = [];
|
|
2717
|
+
for (const { table: name, index } of LATE_INDEXES) {
|
|
2718
|
+
const table = tables.find((candidate) => candidate.name === name);
|
|
2719
|
+
if (table === void 0) continue;
|
|
2720
|
+
if (await fillIndex(table, index, { dryRun }) > 0) lacking.push(`${name}.${index}`);
|
|
2721
|
+
}
|
|
2722
|
+
return lacking;
|
|
2723
|
+
};
|
|
2724
|
+
const migrateSchema = async (adapter, adapterName, tables, settings, ordered) => {
|
|
2725
|
+
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2726
|
+
const stored = await storedSettings(adapter, Object.keys(settings)).catch(() => void 0);
|
|
2727
|
+
if (stored !== void 0) refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2728
|
+
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2729
|
+
await fillLateIndexes(adapter, tables);
|
|
2730
|
+
await writeSchemaSettings(adapter, adapterName, settings, ordered);
|
|
2731
|
+
};
|
|
2673
2732
|
//#endregion
|
|
2674
2733
|
//#region ../plugin-core/dist/engine/database/cursor.mjs
|
|
2675
2734
|
const encoder$1 = new TextEncoder();
|
|
@@ -3554,22 +3613,27 @@ const createEngineMigrator = (options) => {
|
|
|
3554
3613
|
const makeResult = async (migrate = {}) => {
|
|
3555
3614
|
const stored = await options.readSettings();
|
|
3556
3615
|
refuseV0Database(options.adapterName, stored);
|
|
3557
|
-
|
|
3616
|
+
refuseNewerSchema(options.adapterName, stored, options.settings, options.ordered);
|
|
3617
|
+
const changed = Object.entries(options.settings).filter(([key, value]) => stored.get(key) !== value);
|
|
3618
|
+
if (changed.length === 0) {
|
|
3619
|
+
const lacking = await fillLateIndexes(options.adapter, options.schema.tables, { dryRun: true });
|
|
3620
|
+
if (lacking.length === 0) return getEmptyMigrationResult();
|
|
3621
|
+
return {
|
|
3622
|
+
operations: [{
|
|
3623
|
+
type: "custom",
|
|
3624
|
+
description: `Write the index items rows lack: ${lacking.join(", ")}`
|
|
3625
|
+
}],
|
|
3626
|
+
execute: async () => {
|
|
3627
|
+
await fillLateIndexes(options.adapter, options.schema.tables);
|
|
3628
|
+
}
|
|
3629
|
+
};
|
|
3630
|
+
}
|
|
3558
3631
|
return {
|
|
3559
|
-
operations: [
|
|
3560
|
-
type: "create-table",
|
|
3561
|
-
value: {
|
|
3562
|
-
ormName: table.name,
|
|
3563
|
-
columns: Object.fromEntries(table.columns.map((column) => [column.name, {
|
|
3564
|
-
ormName: column.name,
|
|
3565
|
-
type: column.type
|
|
3566
|
-
}]))
|
|
3567
|
-
}
|
|
3568
|
-
})), ...migrate.updateSettings === false ? [] : [{
|
|
3632
|
+
operations: [{
|
|
3569
3633
|
type: "custom",
|
|
3570
|
-
description:
|
|
3571
|
-
}]],
|
|
3572
|
-
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings)
|
|
3634
|
+
description: "Create the tables and indexes the database lacks"
|
|
3635
|
+
}, ...migrate.updateSettings === false ? [] : [settingsOperation(stored, changed)]],
|
|
3636
|
+
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings, options.ordered)
|
|
3573
3637
|
};
|
|
3574
3638
|
};
|
|
3575
3639
|
return {
|
|
@@ -3597,7 +3661,8 @@ const coreSettings = {
|
|
|
3597
3661
|
};
|
|
3598
3662
|
const coreTarget = {
|
|
3599
3663
|
schema: coreSchema,
|
|
3600
|
-
settings: coreSettings
|
|
3664
|
+
settings: coreSettings,
|
|
3665
|
+
ordered: ["schema.core"]
|
|
3601
3666
|
};
|
|
3602
3667
|
resolveSchema([aggregateBatchingModule]).tables;
|
|
3603
3668
|
const pluginSettings = (plugins) => Object.fromEntries(plugins.map(({ id, schemaVersion }) => [`schema.${id}`, schemaVersion]));
|
|
@@ -3608,11 +3673,12 @@ const pluginModule = ({ id, schema, namespace }) => ({
|
|
|
3608
3673
|
});
|
|
3609
3674
|
const createEngineDatabase = ({ name, adapter, onCachedRoutesChange, aggregateBatching, retry, readSettings: readStored }) => {
|
|
3610
3675
|
const fenced = withSchemaFence(adapter, name, coreSettings);
|
|
3611
|
-
const createMigrator = ({ schema, settings } = coreTarget) => createEngineMigrator({
|
|
3676
|
+
const createMigrator = ({ schema, settings, ordered } = coreTarget) => createEngineMigrator({
|
|
3612
3677
|
adapterName: name,
|
|
3613
3678
|
adapter,
|
|
3614
3679
|
schema,
|
|
3615
3680
|
settings,
|
|
3681
|
+
ordered,
|
|
3616
3682
|
readSettings: readStored ?? (async () => {
|
|
3617
3683
|
const rows = await readSettings(adapter, Object.keys(settings)).catch((error) => {
|
|
3618
3684
|
if (isMissingSchemaError(error)) return [];
|
|
@@ -3635,6 +3701,11 @@ const createEngineDatabase = ({ name, adapter, onCachedRoutesChange, aggregateBa
|
|
|
3635
3701
|
//#region ../plugin-core/dist/engine/database/engineTransaction.mjs
|
|
3636
3702
|
var StaleReadError = class extends Error {};
|
|
3637
3703
|
const idOf = (table, key) => JSON.stringify([table, key]);
|
|
3704
|
+
const versionsOf = (ops) => JSON.stringify(ops.map((op) => op.type === "insert" ? [op.table.name, rowKey(op.table, op.row)] : [
|
|
3705
|
+
op.table.name,
|
|
3706
|
+
op.key,
|
|
3707
|
+
"guard" in op ? op.guard?.v : void 0
|
|
3708
|
+
]));
|
|
3638
3709
|
const versionOf = (row) => Number(row["_v"]);
|
|
3639
3710
|
const isKeyed = (value) => value !== null && value !== void 0;
|
|
3640
3711
|
const misuse = (table, message) => new DatabaseTransactionError(`${table}: ${message}`);
|
|
@@ -3966,7 +4037,9 @@ const createTransactions = ({ adapter, schema, reads, retry = {} }) => {
|
|
|
3966
4037
|
assertOutsideTransaction();
|
|
3967
4038
|
let run;
|
|
3968
4039
|
let negative;
|
|
3969
|
-
|
|
4040
|
+
let failures = 0;
|
|
4041
|
+
let lost;
|
|
4042
|
+
for (let round = 0;; round += 1) {
|
|
3970
4043
|
const delay = round && Math.min(maxDelayMs, baseDelayMs * 2 ** (round - 1));
|
|
3971
4044
|
if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay / 2 + Math.random() * (delay / 2)));
|
|
3972
4045
|
run ??= await attempt(fn).catch((error) => {
|
|
@@ -3975,6 +4048,8 @@ const createTransactions = ({ adapter, schema, reads, retry = {} }) => {
|
|
|
3975
4048
|
});
|
|
3976
4049
|
if (run === void 0) {
|
|
3977
4050
|
onRetry?.("rerun", round + 1);
|
|
4051
|
+
lost = void 0;
|
|
4052
|
+
if ((failures += 1) >= attempts) break;
|
|
3978
4053
|
continue;
|
|
3979
4054
|
}
|
|
3980
4055
|
let aggregates;
|
|
@@ -3985,8 +4060,14 @@ const createTransactions = ({ adapter, schema, reads, retry = {} }) => {
|
|
|
3985
4060
|
negative = error;
|
|
3986
4061
|
onRetry?.("rerun", round + 1);
|
|
3987
4062
|
run = void 0;
|
|
4063
|
+
lost = void 0;
|
|
4064
|
+
if ((failures += 1) >= attempts) break;
|
|
3988
4065
|
continue;
|
|
3989
4066
|
}
|
|
4067
|
+
const versions = versionsOf(aggregates);
|
|
4068
|
+
if (lost !== void 0 && versions !== lost) failures -= 1;
|
|
4069
|
+
lost = void 0;
|
|
4070
|
+
if (failures >= attempts) break;
|
|
3990
4071
|
const ops = [...run.ops, ...aggregates];
|
|
3991
4072
|
if (ops.length <= 1 && ops.every(({ type }) => type === "check")) return run.result;
|
|
3992
4073
|
if (!adapter.fits(ops)) throw new DatabaseConstraintError("too_large", ops[0].table.name);
|
|
@@ -4000,12 +4081,16 @@ const createTransactions = ({ adapter, schema, reads, retry = {} }) => {
|
|
|
4000
4081
|
const failed = "failedOp" in outcome ? outcome.failedOp : void 0;
|
|
4001
4082
|
if (failed === void 0 || failed >= run.ops.length) {
|
|
4002
4083
|
onRetry?.("resend", round + 1);
|
|
4084
|
+
failures += 1;
|
|
4085
|
+
if (failed !== void 0) lost = versions;
|
|
4086
|
+
else if (failures >= attempts) break;
|
|
4003
4087
|
continue;
|
|
4004
4088
|
}
|
|
4005
4089
|
const reason = await classify(ops[failed], run.read);
|
|
4006
4090
|
if (reason) throw new DatabaseConstraintError(reason, ops[failed].table.name);
|
|
4007
4091
|
onRetry?.("rerun", round + 1);
|
|
4008
4092
|
run = void 0;
|
|
4093
|
+
if ((failures += 1) >= attempts) break;
|
|
4009
4094
|
}
|
|
4010
4095
|
throw negative ?? new DatabaseConflictError(`The transaction conflicted ${attempts} times.`);
|
|
4011
4096
|
} };
|
|
@@ -17788,7 +17873,7 @@ const postgres = (config) => {
|
|
|
17788
17873
|
};
|
|
17789
17874
|
//#endregion
|
|
17790
17875
|
//#region ../../packages/server/dist/version.mjs
|
|
17791
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
17876
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.50";
|
|
17792
17877
|
//#endregion
|
|
17793
17878
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
17794
17879
|
const createVersionRouteHandlers = (plugins = []) => {
|
|
@@ -17914,9 +17999,14 @@ const releaseCatalogScopeKeyOf = (input) => input.strategy === "APP_VERSION" ? c
|
|
|
17914
17999
|
platform: input.platform,
|
|
17915
18000
|
strategy: "FINGERPRINT"
|
|
17916
18001
|
});
|
|
17917
|
-
const
|
|
17918
|
-
|
|
17919
|
-
|
|
18002
|
+
const parseReleaseCatalogRow = ({ payload, ...row }) => ({
|
|
18003
|
+
row,
|
|
18004
|
+
compiled: parseCompiledCatalog(payload, row.strategy)
|
|
18005
|
+
});
|
|
18006
|
+
const projectParsedReleaseCatalogRow = (parsed, input, scopeKey = releaseCatalogScopeKeyOf(input)) => {
|
|
18007
|
+
if (parsed === null) return null;
|
|
18008
|
+
const { row, compiled } = parsed;
|
|
18009
|
+
if (row.platform !== input.platform || row.strategy !== input.strategy || row.channel_key !== input.channelKey || row.scope_key !== scopeKey || row.fingerprint_hash !== (input.strategy === "FINGERPRINT" ? input.fingerprintHash : null)) return null;
|
|
17920
18010
|
const appVersion = input.strategy === "APP_VERSION" ? input.appVersion : void 0;
|
|
17921
18011
|
return {
|
|
17922
18012
|
catalogId: row.catalog_id,
|
|
@@ -17929,6 +18019,7 @@ const projectReleaseCatalogRow = (row, input, scopeKey = releaseCatalogScopeKeyO
|
|
|
17929
18019
|
scopeKey
|
|
17930
18020
|
};
|
|
17931
18021
|
};
|
|
18022
|
+
const projectReleaseCatalogRow = (row, input, scopeKey = releaseCatalogScopeKeyOf(input)) => projectParsedReleaseCatalogRow(row === null ? null : parseReleaseCatalogRow(row), input, scopeKey);
|
|
17932
18023
|
//#endregion
|
|
17933
18024
|
//#region ../../packages/server/dist/db/updateArtifacts.mjs
|
|
17934
18025
|
const HBC_ASSET_PATH_RE = /\.bundle$/;
|
|
@@ -18771,7 +18862,29 @@ const createCoreReads = (db, storage) => {
|
|
|
18771
18862
|
...after(input)
|
|
18772
18863
|
})).rows.map(toCatalogRow);
|
|
18773
18864
|
},
|
|
18774
|
-
async
|
|
18865
|
+
async listReleaseScopeKeys(input) {
|
|
18866
|
+
const scopeKeys = [];
|
|
18867
|
+
for (let last = input.after ?? ""; scopeKeys.length < input.limit;) {
|
|
18868
|
+
const { rows } = await db.findMany("releases", {
|
|
18869
|
+
index: "scopes",
|
|
18870
|
+
where: {},
|
|
18871
|
+
limit: 1,
|
|
18872
|
+
range: { gt: last }
|
|
18873
|
+
});
|
|
18874
|
+
if (rows[0] === void 0) break;
|
|
18875
|
+
last = rows[0].scope_key;
|
|
18876
|
+
scopeKeys.push(last);
|
|
18877
|
+
}
|
|
18878
|
+
return scopeKeys;
|
|
18879
|
+
},
|
|
18880
|
+
async listChannels(input) {
|
|
18881
|
+
if (input !== void 0) return (await db.findMany("channels", {
|
|
18882
|
+
index: "all",
|
|
18883
|
+
where: {},
|
|
18884
|
+
order: input.order ?? "asc",
|
|
18885
|
+
limit: input.limit,
|
|
18886
|
+
...after(input)
|
|
18887
|
+
})).rows.map(toChannelRow);
|
|
18775
18888
|
return (await drain$1((page) => db.findMany("channels", {
|
|
18776
18889
|
index: "all",
|
|
18777
18890
|
where: {},
|
|
@@ -18779,6 +18892,11 @@ const createCoreReads = (db, storage) => {
|
|
|
18779
18892
|
...page
|
|
18780
18893
|
}))).map(toChannelRow);
|
|
18781
18894
|
},
|
|
18895
|
+
async getChannels(ids) {
|
|
18896
|
+
const unique = [...new Set(ids)];
|
|
18897
|
+
if (unique.length === 0) return [];
|
|
18898
|
+
return (await db.findByKeys("channels", unique.map((id) => ({ id })))).flatMap((row) => row ? [toChannelRow(row)] : []);
|
|
18899
|
+
},
|
|
18782
18900
|
async findChannelByName(name) {
|
|
18783
18901
|
const row = await db.findOne("channels", { name });
|
|
18784
18902
|
return row === null ? null : toChannelRow(row);
|
|
@@ -19594,24 +19712,26 @@ const checkScope = (scope) => {
|
|
|
19594
19712
|
});
|
|
19595
19713
|
if (scope.strategy === "FINGERPRINT" !== (scope.fingerprintHash !== null) || scope.scopeKey !== expected) fail$1("INVALID_SCOPE", "Release catalog scope metadata is inconsistent");
|
|
19596
19714
|
};
|
|
19597
|
-
const
|
|
19715
|
+
const drainReleases = async (page) => {
|
|
19598
19716
|
const rows = [];
|
|
19599
19717
|
let cursor;
|
|
19600
19718
|
do {
|
|
19601
|
-
const
|
|
19602
|
-
|
|
19603
|
-
|
|
19604
|
-
scope_key: scopeKey,
|
|
19605
|
-
enabled: true
|
|
19606
|
-
},
|
|
19607
|
-
limit: PAGE$1,
|
|
19608
|
-
...cursor === void 0 ? {} : { cursor }
|
|
19609
|
-
});
|
|
19610
|
-
rows.push(...page.rows.map(toReleaseRow));
|
|
19611
|
-
cursor = page.next;
|
|
19719
|
+
const found = await page(cursor);
|
|
19720
|
+
rows.push(...found.rows.map((row) => toReleaseRow(row)));
|
|
19721
|
+
cursor = found.next;
|
|
19612
19722
|
} while (cursor !== void 0);
|
|
19613
19723
|
return rows;
|
|
19614
19724
|
};
|
|
19725
|
+
const enabledIn = (scopeKey, cursor) => ({
|
|
19726
|
+
index: "byScopeEnabled",
|
|
19727
|
+
where: {
|
|
19728
|
+
scope_key: scopeKey,
|
|
19729
|
+
enabled: true
|
|
19730
|
+
},
|
|
19731
|
+
limit: PAGE$1,
|
|
19732
|
+
...cursor === void 0 ? {} : { cursor }
|
|
19733
|
+
});
|
|
19734
|
+
const enabledReleases = (tx, scopeKey) => drainReleases((cursor) => tx.findMany("releases", enabledIn(scopeKey, cursor)));
|
|
19615
19735
|
const latestReleaseId = async (tx, scopeKey) => {
|
|
19616
19736
|
const { rows } = await tx.findMany("releases", {
|
|
19617
19737
|
index: "byScope",
|
|
@@ -19621,14 +19741,10 @@ const latestReleaseId = async (tx, scopeKey) => {
|
|
|
19621
19741
|
});
|
|
19622
19742
|
return rows[0]?.id ?? null;
|
|
19623
19743
|
};
|
|
19624
|
-
const
|
|
19625
|
-
const
|
|
19626
|
-
strategy: scope.strategy,
|
|
19627
|
-
releases: enabled.map(releaseRowToRelease)
|
|
19628
|
-
});
|
|
19629
|
-
const generation = (stored.generation ?? 0) + 1;
|
|
19744
|
+
const nextCatalog = (scope, stored, compilation, updatedAtMs) => {
|
|
19745
|
+
const generation = (stored.catalog?.generation ?? 0) + 1;
|
|
19630
19746
|
if (!Number.isSafeInteger(generation)) fail$1("CATALOG_GENERATION_EXHAUSTED", `Catalog "${scope.scopeKey}" exhausted its generation counter`);
|
|
19631
|
-
|
|
19747
|
+
return {
|
|
19632
19748
|
scope_key: scope.scopeKey,
|
|
19633
19749
|
catalog_id: stored.catalog?.catalog_id ?? createUUIDv7(),
|
|
19634
19750
|
strategy: scope.strategy,
|
|
@@ -19643,6 +19759,21 @@ const writeCatalog = async (tx, scope, stored, enabled, updatedAtMs) => {
|
|
|
19643
19759
|
is_tombstone: compilation.payload.releaseDescriptors.length === 0,
|
|
19644
19760
|
updated_at_ms: updatedAtMs
|
|
19645
19761
|
};
|
|
19762
|
+
};
|
|
19763
|
+
const compileScope = async (scope, enabled) => {
|
|
19764
|
+
try {
|
|
19765
|
+
return await compileReleaseCatalog({
|
|
19766
|
+
strategy: scope.strategy,
|
|
19767
|
+
releases: enabled.map(releaseRowToRelease)
|
|
19768
|
+
});
|
|
19769
|
+
} catch (error) {
|
|
19770
|
+
if (!(error instanceof ReleaseCatalogCompilationError) || error.code !== "CATALOG_OVERSIZE") throw error;
|
|
19771
|
+
throw new ReleaseCatalogCompilationError("CATALOG_OVERSIZE", `The ${scope.platform} release catalog of channel "${scope.channelName}" would be over its ${MAX_COMPILED_CATALOG_BYTES / 1024} KiB limit.\nDisable or delete old bundles on that channel, then try again.`);
|
|
19772
|
+
}
|
|
19773
|
+
};
|
|
19774
|
+
const writeCatalog = async (tx, scope, stored, enabled, updatedAtMs) => {
|
|
19775
|
+
const compilation = await compileScope(scope, enabled);
|
|
19776
|
+
const catalog = nextCatalog(scope, stored, compilation, updatedAtMs);
|
|
19646
19777
|
const { scope_key: _scopeKey, ...set } = catalog;
|
|
19647
19778
|
if (stored.row === null) tx.create("release_catalogs", catalog);
|
|
19648
19779
|
else tx.update("release_catalogs", stored.row, set);
|
|
@@ -19721,17 +19852,39 @@ const changeReleases = (db, inputs) => {
|
|
|
19721
19852
|
return results;
|
|
19722
19853
|
});
|
|
19723
19854
|
};
|
|
19855
|
+
const isCurrent = (scope, current, compilation) => current.strategy === scope.strategy && current.channel_id === scope.channelId && current.channel_key === encodeChannelKey(scope.channelName) && current.platform === scope.platform && current.fingerprint_hash === scope.fingerprintHash && current.catalog_hash === compilation.catalogHash;
|
|
19856
|
+
const catalogRowScope = (row) => ({
|
|
19857
|
+
channelId: row.channel_id,
|
|
19858
|
+
channelName: decodeChannelKey(row.channel_key),
|
|
19859
|
+
fingerprintHash: row.fingerprint_hash,
|
|
19860
|
+
platform: row.platform,
|
|
19861
|
+
scopeKey: row.scope_key,
|
|
19862
|
+
strategy: row.strategy
|
|
19863
|
+
});
|
|
19864
|
+
const preflightRebuild = async (db, scopeKey, updatedAtMs) => {
|
|
19865
|
+
const row = await db.findOne("release_catalogs", { scope_key: scopeKey });
|
|
19866
|
+
if (row === null) throw new Error(`Release catalog "${scopeKey}" was not found.`);
|
|
19867
|
+
const current = toCatalogRow(row);
|
|
19868
|
+
const scope = catalogRowScope(current);
|
|
19869
|
+
checkScope(scope);
|
|
19870
|
+
const enabled = await drainReleases((cursor) => db.findMany("releases", enabledIn(scopeKey, cursor)));
|
|
19871
|
+
const compilation = await compileScope(scope, enabled);
|
|
19872
|
+
const changed = !isCurrent(scope, current, compilation);
|
|
19873
|
+
return {
|
|
19874
|
+
changed,
|
|
19875
|
+
currentCatalog: current,
|
|
19876
|
+
diagnostics: compilation.diagnostics,
|
|
19877
|
+
projectedCatalog: changed ? nextCatalog(scope, { catalog: current }, compilation, updatedAtMs) : current
|
|
19878
|
+
};
|
|
19879
|
+
};
|
|
19724
19880
|
const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
19725
19881
|
checkScope(scope);
|
|
19726
19882
|
const stored = await readCatalog(tx, scope.scopeKey);
|
|
19727
19883
|
assertHistory(stored, await latestReleaseId(tx, scope.scopeKey) !== null);
|
|
19728
19884
|
const enabled = await enabledReleases(tx, scope.scopeKey);
|
|
19729
|
-
const compilation = await
|
|
19730
|
-
strategy: scope.strategy,
|
|
19731
|
-
releases: enabled.map(releaseRowToRelease)
|
|
19732
|
-
});
|
|
19885
|
+
const compilation = await compileScope(scope, enabled);
|
|
19733
19886
|
const current = stored.catalog;
|
|
19734
|
-
if (current !== null &&
|
|
19887
|
+
if (current !== null && isCurrent(scope, current, compilation)) return {
|
|
19735
19888
|
catalog: current,
|
|
19736
19889
|
current,
|
|
19737
19890
|
changed: false,
|
|
@@ -19831,14 +19984,7 @@ const mutationResult = ({ catalog, release }) => ({
|
|
|
19831
19984
|
const catalogScope = async (tx, scopeKey) => {
|
|
19832
19985
|
const row = await tx.findOne("release_catalogs", { scope_key: scopeKey });
|
|
19833
19986
|
if (row === null) throw new Error(`Release catalog "${scopeKey}" was not found.`);
|
|
19834
|
-
return
|
|
19835
|
-
channelId: row.channel_id,
|
|
19836
|
-
channelName: decodeChannelKey(row.channel_key),
|
|
19837
|
-
fingerprintHash: row.fingerprint_hash,
|
|
19838
|
-
platform: row.platform,
|
|
19839
|
-
scopeKey: row.scope_key,
|
|
19840
|
-
strategy: row.strategy
|
|
19841
|
-
};
|
|
19987
|
+
return catalogRowScope(toCatalogRow(row));
|
|
19842
19988
|
};
|
|
19843
19989
|
const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
19844
19990
|
const ensureChannel = async (name) => (await insertChannel(db, {
|
|
@@ -20037,18 +20183,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
20037
20183
|
};
|
|
20038
20184
|
});
|
|
20039
20185
|
},
|
|
20040
|
-
preflightReleaseCatalogRebuild: (scopeKey) =>
|
|
20041
|
-
const updatedAtMs = now();
|
|
20042
|
-
return dryRun(db, async (tx) => {
|
|
20043
|
-
const rebuilt = await rebuildScope(tx, await catalogScope(tx, scopeKey), updatedAtMs);
|
|
20044
|
-
return {
|
|
20045
|
-
changed: rebuilt.changed,
|
|
20046
|
-
currentCatalog: rebuilt.current,
|
|
20047
|
-
diagnostics: rebuilt.diagnostics,
|
|
20048
|
-
projectedCatalog: rebuilt.catalog
|
|
20049
|
-
};
|
|
20050
|
-
});
|
|
20051
|
-
},
|
|
20186
|
+
preflightReleaseCatalogRebuild: (scopeKey) => preflightRebuild(db, scopeKey, now()),
|
|
20052
20187
|
ensureChannel,
|
|
20053
20188
|
deleteChannel: (id) => deleteChannel(db, id),
|
|
20054
20189
|
updateBundle: (id, update) => db.transaction(async (tx) => {
|
|
@@ -20306,6 +20441,10 @@ const answer = async (operation) => {
|
|
|
20306
20441
|
error: error.message
|
|
20307
20442
|
}, status);
|
|
20308
20443
|
}
|
|
20444
|
+
if (error instanceof ReleaseCatalogCompilationError && error.code === "CATALOG_OVERSIZE") return json$2({
|
|
20445
|
+
code: error.code,
|
|
20446
|
+
error: error.message
|
|
20447
|
+
}, 400);
|
|
20309
20448
|
if (error instanceof DatabaseBundleNotFoundError) return json$2({
|
|
20310
20449
|
code: "BUNDLE_NOT_FOUND",
|
|
20311
20450
|
error: error.message
|
|
@@ -20325,8 +20464,9 @@ const LIMITS = {
|
|
|
20325
20464
|
defaultValue: 50,
|
|
20326
20465
|
maxValue: 500
|
|
20327
20466
|
};
|
|
20328
|
-
const
|
|
20329
|
-
|
|
20467
|
+
const MAX_IDS = 100;
|
|
20468
|
+
const keyset = (url, maxValue = LIMITS.maxValue, defaultOrder = "desc") => {
|
|
20469
|
+
const order = url.searchParams.get("order") ?? defaultOrder;
|
|
20330
20470
|
if (order !== "asc" && order !== "desc") throw new HandlerBadRequestError("order must be 'asc' or 'desc'.");
|
|
20331
20471
|
const limitParam = url.searchParams.get("limit");
|
|
20332
20472
|
const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
|
|
@@ -20508,11 +20648,34 @@ const createAdminRouteHandlers = () => ({
|
|
|
20508
20648
|
const rows = await core.listReleaseCatalogs(input);
|
|
20509
20649
|
return page(rows, input, (row) => row.scope_key);
|
|
20510
20650
|
}),
|
|
20651
|
+
listReleaseScopeKeys: onCore(async (core, request) => {
|
|
20652
|
+
const input = keyset(new URL(request.url), 100, "asc");
|
|
20653
|
+
if (input.order !== "asc" || input.through !== void 0) throw new HandlerBadRequestError("Release scopes are listed ascending, by limit and cursor only.");
|
|
20654
|
+
const rows = await core.listReleaseScopeKeys({
|
|
20655
|
+
limit: input.limit,
|
|
20656
|
+
...input.after === void 0 ? {} : { after: input.after }
|
|
20657
|
+
});
|
|
20658
|
+
return page(rows, input, (scopeKey) => scopeKey);
|
|
20659
|
+
}),
|
|
20511
20660
|
getChannels: onCore(async (core, request) => {
|
|
20512
|
-
const
|
|
20513
|
-
|
|
20514
|
-
|
|
20515
|
-
|
|
20661
|
+
const url = new URL(request.url);
|
|
20662
|
+
const name = url.searchParams.get("name");
|
|
20663
|
+
if (name !== null) {
|
|
20664
|
+
const channel = await core.findChannelByName(name);
|
|
20665
|
+
return channel === null ? notFound() : json$2({ data: channel });
|
|
20666
|
+
}
|
|
20667
|
+
const ids = url.searchParams.get("ids");
|
|
20668
|
+
if (ids !== null) {
|
|
20669
|
+
const list = ids.split(",").filter((id) => id.length > 0);
|
|
20670
|
+
if (list.length === 0 || list.length > MAX_IDS) throw new HandlerBadRequestError(`Channels by ID take ids=<channel id>,... with 1 to ${MAX_IDS} ids.`);
|
|
20671
|
+
return json$2({ data: await core.getChannels(list) });
|
|
20672
|
+
}
|
|
20673
|
+
if (url.searchParams.has("limit") || url.searchParams.has("cursor")) {
|
|
20674
|
+
const input = keyset(url, LIMITS.maxValue, "asc");
|
|
20675
|
+
const rows = await core.listChannels(input);
|
|
20676
|
+
return page(rows, input, (row) => row.name);
|
|
20677
|
+
}
|
|
20678
|
+
return json$2({ data: await core.listChannels() });
|
|
20516
20679
|
}),
|
|
20517
20680
|
createChannel: onCore(async (core, request) => {
|
|
20518
20681
|
const { name } = await body(request);
|
|
@@ -20560,7 +20723,7 @@ const createAdminRouteHandlers = () => ({
|
|
|
20560
20723
|
countBundles: onCore(async (core, request) => json$2({ data: await core.countBundles(platformOf(new URL(request.url))) })),
|
|
20561
20724
|
countBundleChildren: onCore(async (core, request) => {
|
|
20562
20725
|
const ids = (new URL(request.url).searchParams.get("ids") ?? "").split(",").filter((id) => id.length > 0);
|
|
20563
|
-
if (ids.length === 0 || ids.length >
|
|
20726
|
+
if (ids.length === 0 || ids.length > MAX_IDS) throw new HandlerBadRequestError(`Bundle child counts take ids=<bundle id>,... with 1 to ${MAX_IDS} ids.`);
|
|
20564
20727
|
return json$2({ data: await core.countBundleChildren(ids) });
|
|
20565
20728
|
}),
|
|
20566
20729
|
listBundleChildren: onCore(async (core, request, params) => {
|
|
@@ -20702,6 +20865,7 @@ const createAdminRouteHandlers = () => ({
|
|
|
20702
20865
|
markIosDevicesInBuild: onCore(async (core, request) => {
|
|
20703
20866
|
const { buildId, ids } = await body(request);
|
|
20704
20867
|
if (!isText$2(buildId) || !Array.isArray(ids) || !ids.every((id) => isText$2(id))) throw new HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
|
|
20868
|
+
if (ids.length > MAX_IDS) throw new HandlerBadRequestError(`Marking iOS devices in a build takes at most ${MAX_IDS} ids a request.`);
|
|
20705
20869
|
await core.markIosDevicesInBuild({
|
|
20706
20870
|
buildId,
|
|
20707
20871
|
ids
|
|
@@ -20771,6 +20935,11 @@ const ADMIN_ROUTES = [
|
|
|
20771
20935
|
path: "/release-catalogs",
|
|
20772
20936
|
handler: "listReleaseCatalogs"
|
|
20773
20937
|
},
|
|
20938
|
+
{
|
|
20939
|
+
method: "GET",
|
|
20940
|
+
path: "/release-scopes",
|
|
20941
|
+
handler: "listReleaseScopeKeys"
|
|
20942
|
+
},
|
|
20774
20943
|
{
|
|
20775
20944
|
method: "POST",
|
|
20776
20945
|
path: "/release-catalogs/:scopeKey/rebuild",
|
|
@@ -21004,38 +21173,53 @@ const catalogResponse = async (catalog, request) => {
|
|
|
21004
21173
|
};
|
|
21005
21174
|
const createReleaseCatalogRouteHandlers = () => {
|
|
21006
21175
|
const cache = /* @__PURE__ */ new Map();
|
|
21176
|
+
const evict = (insertedHit) => {
|
|
21177
|
+
const now = Date.now();
|
|
21178
|
+
let oldestMiss;
|
|
21179
|
+
let oldest;
|
|
21180
|
+
for (const [key, entry] of cache) if (entry.expiresAt <= now) cache.delete(key);
|
|
21181
|
+
else {
|
|
21182
|
+
if (entry.row === null) oldestMiss ??= key;
|
|
21183
|
+
oldest ??= key;
|
|
21184
|
+
}
|
|
21185
|
+
if (cache.size <= ORIGIN_CACHE_MAX_ENTRIES) return;
|
|
21186
|
+
const victim = oldestMiss ?? (insertedHit ? oldest : void 0);
|
|
21187
|
+
if (victim !== void 0) cache.delete(victim);
|
|
21188
|
+
};
|
|
21007
21189
|
const inFlight = /* @__PURE__ */ new Map();
|
|
21008
|
-
const
|
|
21009
|
-
const cached = cache.get(
|
|
21190
|
+
const loadRow = async (scopeKey, load) => {
|
|
21191
|
+
const cached = cache.get(scopeKey);
|
|
21010
21192
|
if (cached !== void 0 && cached.expiresAt > Date.now()) {
|
|
21011
|
-
cache.delete(
|
|
21012
|
-
cache.set(
|
|
21013
|
-
return cached.
|
|
21193
|
+
cache.delete(scopeKey);
|
|
21194
|
+
cache.set(scopeKey, cached);
|
|
21195
|
+
return cached.row;
|
|
21014
21196
|
}
|
|
21015
|
-
if (cached !== void 0) cache.delete(
|
|
21016
|
-
const pending = inFlight.get(
|
|
21197
|
+
if (cached !== void 0) cache.delete(scopeKey);
|
|
21198
|
+
const pending = inFlight.get(scopeKey);
|
|
21017
21199
|
if (pending !== void 0) return pending;
|
|
21018
|
-
const next = load().then((
|
|
21019
|
-
|
|
21020
|
-
|
|
21021
|
-
|
|
21022
|
-
|
|
21023
|
-
|
|
21024
|
-
|
|
21025
|
-
const oldestKey = cache.keys().next().value;
|
|
21026
|
-
if (oldestKey === void 0) break;
|
|
21027
|
-
cache.delete(oldestKey);
|
|
21028
|
-
}
|
|
21029
|
-
}
|
|
21030
|
-
return catalog;
|
|
21200
|
+
const next = load().then((row) => {
|
|
21201
|
+
cache.set(scopeKey, {
|
|
21202
|
+
row,
|
|
21203
|
+
expiresAt: Date.now() + ORIGIN_CACHE_TTL_MS
|
|
21204
|
+
});
|
|
21205
|
+
if (cache.size > ORIGIN_CACHE_MAX_ENTRIES) evict(row !== null);
|
|
21206
|
+
return row;
|
|
21031
21207
|
});
|
|
21032
|
-
inFlight.set(
|
|
21208
|
+
inFlight.set(scopeKey, next);
|
|
21033
21209
|
try {
|
|
21034
21210
|
return await next;
|
|
21035
21211
|
} finally {
|
|
21036
|
-
inFlight.delete(
|
|
21212
|
+
inFlight.delete(scopeKey);
|
|
21037
21213
|
}
|
|
21038
21214
|
};
|
|
21215
|
+
const loadCatalog = async (core, input) => {
|
|
21216
|
+
const scopeKey = releaseCatalogScopeKeyOf(input);
|
|
21217
|
+
const parsed = await loadRow(scopeKey, async () => {
|
|
21218
|
+
const row = await core.getReleaseCatalogRow(scopeKey);
|
|
21219
|
+
return row === null ? null : parseReleaseCatalogRow(row);
|
|
21220
|
+
});
|
|
21221
|
+
return projectParsedReleaseCatalogRow(parsed, input, scopeKey);
|
|
21222
|
+
};
|
|
21039
21223
|
return {
|
|
21040
21224
|
appVersionReleaseCatalog: async (params, request, { core }) => {
|
|
21041
21225
|
const rawAppVersion = requireRouteParam(params, "appVersion");
|
|
@@ -21049,7 +21233,7 @@ const createReleaseCatalogRouteHandlers = () => {
|
|
|
21049
21233
|
};
|
|
21050
21234
|
const invalid = invalidScope(input);
|
|
21051
21235
|
if (invalid) return invalid;
|
|
21052
|
-
return catalogResponse(await loadCatalog(
|
|
21236
|
+
return catalogResponse(await loadCatalog(core, input), request);
|
|
21053
21237
|
},
|
|
21054
21238
|
fingerprintReleaseCatalog: async (params, request, { core }) => {
|
|
21055
21239
|
const input = {
|
|
@@ -21060,7 +21244,7 @@ const createReleaseCatalogRouteHandlers = () => {
|
|
|
21060
21244
|
};
|
|
21061
21245
|
const invalid = invalidScope(input);
|
|
21062
21246
|
if (invalid) return invalid;
|
|
21063
|
-
return catalogResponse(await loadCatalog(
|
|
21247
|
+
return catalogResponse(await loadCatalog(core, input), request);
|
|
21064
21248
|
},
|
|
21065
21249
|
artifactV2: async (params, _request, { core }) => {
|
|
21066
21250
|
const info = await core.getArtifactInfo(requireRouteParam(params, "targetBundleId"), requireRouteParam(params, "currentBundleId"), 2);
|
|
@@ -23974,6 +24158,53 @@ const breakdownOf = (rows) => {
|
|
|
23974
24158
|
};
|
|
23975
24159
|
});
|
|
23976
24160
|
};
|
|
24161
|
+
const FAILURE_ROWS_PER_HOUR = 20;
|
|
24162
|
+
const FAILURE_QUERY_LIMIT = Math.min(PAGE, 168);
|
|
24163
|
+
const failureRowsByHour = async (db, platform, channel, timeRange) => {
|
|
24164
|
+
const read = (end, cursor) => db.findAggregates("insights_failures", {
|
|
24165
|
+
index: "byScope",
|
|
24166
|
+
where: {
|
|
24167
|
+
platform,
|
|
24168
|
+
channel
|
|
24169
|
+
},
|
|
24170
|
+
range: {
|
|
24171
|
+
gte: timeRange.start,
|
|
24172
|
+
lt: end
|
|
24173
|
+
},
|
|
24174
|
+
order: "desc",
|
|
24175
|
+
limit: FAILURE_QUERY_LIMIT,
|
|
24176
|
+
...cursor === void 0 ? {} : { cursor }
|
|
24177
|
+
});
|
|
24178
|
+
const rows = [];
|
|
24179
|
+
const cappedHours = [];
|
|
24180
|
+
const perHour = /* @__PURE__ */ new Map();
|
|
24181
|
+
let end = timeRange.end;
|
|
24182
|
+
let cursor;
|
|
24183
|
+
while (end > timeRange.start) {
|
|
24184
|
+
const page = await read(end, cursor);
|
|
24185
|
+
let capped;
|
|
24186
|
+
for (const row of page.rows) {
|
|
24187
|
+
const hour = row.bucket_start_ms;
|
|
24188
|
+
const count = (perHour.get(hour) ?? 0) + 1;
|
|
24189
|
+
if (count > FAILURE_ROWS_PER_HOUR) {
|
|
24190
|
+
capped = hour;
|
|
24191
|
+
break;
|
|
24192
|
+
}
|
|
24193
|
+
perHour.set(hour, count);
|
|
24194
|
+
rows.push(row);
|
|
24195
|
+
}
|
|
24196
|
+
if (capped !== void 0) {
|
|
24197
|
+
cappedHours.unshift(capped);
|
|
24198
|
+
end = capped;
|
|
24199
|
+
cursor = void 0;
|
|
24200
|
+
} else if (page.next === void 0) break;
|
|
24201
|
+
else cursor = page.next;
|
|
24202
|
+
}
|
|
24203
|
+
return {
|
|
24204
|
+
rows,
|
|
24205
|
+
cappedHours
|
|
24206
|
+
};
|
|
24207
|
+
};
|
|
23977
24208
|
const getUpdateFailures = async (db, input, now, retention) => {
|
|
23978
24209
|
const { platform, channel, releaseId, timeRange } = input;
|
|
23979
24210
|
if (platform !== "ios" && platform !== "android" || !isText(channel, 1024) || releaseId !== void 0 && !isText(releaseId, 36) || !isRange(timeRange) || releaseId === void 0 && timeRange === void 0) throw new DatabaseAdapterInputError("invalid-query");
|
|
@@ -24034,7 +24265,7 @@ const getUpdateFailures = async (db, input, now, retention) => {
|
|
|
24034
24265
|
days,
|
|
24035
24266
|
kept.hour
|
|
24036
24267
|
];
|
|
24037
|
-
const [counters, failures, checks, active, rows] = await Promise.all([
|
|
24268
|
+
const [counters, failures, checks, active, { rows, cappedHours }] = await Promise.all([
|
|
24038
24269
|
counterRows(db, parts, ...window),
|
|
24039
24270
|
sketchRows(db, failure, ...window),
|
|
24040
24271
|
days ? sketchRows(db, {
|
|
@@ -24042,25 +24273,17 @@ const getUpdateFailures = async (db, input, now, retention) => {
|
|
|
24042
24273
|
scopeKind: "check"
|
|
24043
24274
|
}, ...window) : [],
|
|
24044
24275
|
days ? sketchRows(db, usageParts(channel, platform), ...window) : [],
|
|
24045
|
-
|
|
24046
|
-
index: "byScope",
|
|
24047
|
-
where: {
|
|
24048
|
-
platform,
|
|
24049
|
-
channel
|
|
24050
|
-
},
|
|
24051
|
-
range: {
|
|
24052
|
-
gte: timeRange.start,
|
|
24053
|
-
lt: timeRange.end
|
|
24054
|
-
},
|
|
24055
|
-
limit: PAGE,
|
|
24056
|
-
...page
|
|
24057
|
-
}))
|
|
24276
|
+
failureRowsByHour(db, platform, channel, timeRange)
|
|
24058
24277
|
]);
|
|
24059
24278
|
const total = (field) => counters.reduce((sum, row) => sum + row[field], 0);
|
|
24060
24279
|
const scoped = rows.filter((row) => FAILURE_STAGES.has(row.stage) && (releaseId === void 0 || row.release_id === releaseId));
|
|
24061
24280
|
const failuresAt = (counted) => scoped.reduce((sum, row) => sum + (counted(row.stage) ? Math.max(0, row.events) : 0), 0);
|
|
24281
|
+
const coverage = coverageOf(timeRange.start, kept.hour);
|
|
24062
24282
|
return {
|
|
24063
|
-
coverage:
|
|
24283
|
+
coverage: cappedHours.length === 0 ? coverage : {
|
|
24284
|
+
kind: "partial",
|
|
24285
|
+
sinceMs: coverage.sinceMs
|
|
24286
|
+
},
|
|
24064
24287
|
measuredAtMs: at,
|
|
24065
24288
|
failedUpdates: failuresAt((stage) => stage !== "check"),
|
|
24066
24289
|
failedInstallations: failed(failures),
|
|
@@ -24072,7 +24295,8 @@ const getUpdateFailures = async (db, input, now, retention) => {
|
|
|
24072
24295
|
failedInstallations: failed(checks),
|
|
24073
24296
|
activeInstallations: countDistinct(mergeDistinct(active.map((row) => row.activity_users)))
|
|
24074
24297
|
} } : {},
|
|
24075
|
-
breakdown: breakdownOf(scoped)
|
|
24298
|
+
breakdown: breakdownOf(scoped),
|
|
24299
|
+
...cappedHours.length === 0 ? {} : { cappedHours }
|
|
24076
24300
|
};
|
|
24077
24301
|
};
|
|
24078
24302
|
//#endregion
|
package/dist/init/index.cjs
CHANGED
|
@@ -6281,7 +6281,8 @@ const getConfigScaffold = (build) => {
|
|
|
6281
6281
|
}],
|
|
6282
6282
|
configString: `vercelBlobStorage({
|
|
6283
6283
|
token: secret("HOT_UPDATER_VERCEL_BLOB_READ_WRITE_TOKEN"),
|
|
6284
|
-
})
|
|
6284
|
+
})`,
|
|
6285
|
+
removedOptions: ["access"]
|
|
6285
6286
|
}).setDatabase({
|
|
6286
6287
|
imports: [{
|
|
6287
6288
|
pkg: "@hot-updater/vercel",
|
|
@@ -7018,7 +7019,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7018
7019
|
const initEnvSources = await (0, _hot_updater_cli_tools.readHotUpdaterInitEnv)(cwd, envFile, secretsEnv);
|
|
7019
7020
|
const { managedEnv } = initEnvSources;
|
|
7020
7021
|
const initInputEnv = (0, _hot_updater_cli_tools.getHotUpdaterInitInputEnv)(initEnvSources, nonInteractive);
|
|
7021
|
-
const saved =
|
|
7022
|
+
const saved = (0, _hot_updater_cli_tools.resolveInitProviderInputs)(initInputEnv, initProvider);
|
|
7022
7023
|
const token = await resolveVercelToken({
|
|
7023
7024
|
cwd,
|
|
7024
7025
|
nonInteractive,
|
package/dist/init/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import fs from "fs/promises";
|
|
3
3
|
import os from "os";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import { ConfigBuilder, InitError, LegacyInfrastructureError, assembleServer, assertInfrastructureGenerationPayload, confirmInitInputPersistence, createHotUpdaterConfigScaffoldFromBuilder, createMigrator, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, shouldAutoSelectOnlyInitResource, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
5
|
+
import { ConfigBuilder, InitError, LegacyInfrastructureError, assembleServer, assertInfrastructureGenerationPayload, confirmInitInputPersistence, createHotUpdaterConfigScaffoldFromBuilder, createMigrator, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInputs, shouldAutoSelectOnlyInitResource, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
6
6
|
import { postgres } from "@hot-updater/postgres";
|
|
7
7
|
import { apiKeys, insights, remoteConfig } from "@hot-updater/server/plugins";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
@@ -6275,7 +6275,8 @@ const getConfigScaffold = (build) => {
|
|
|
6275
6275
|
}],
|
|
6276
6276
|
configString: `vercelBlobStorage({
|
|
6277
6277
|
token: secret("HOT_UPDATER_VERCEL_BLOB_READ_WRITE_TOKEN"),
|
|
6278
|
-
})
|
|
6278
|
+
})`,
|
|
6279
|
+
removedOptions: ["access"]
|
|
6279
6280
|
}).setDatabase({
|
|
6280
6281
|
imports: [{
|
|
6281
6282
|
pkg: "@hot-updater/vercel",
|
|
@@ -7012,7 +7013,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7012
7013
|
const initEnvSources = await readHotUpdaterInitEnv(cwd, envFile, secretsEnv);
|
|
7013
7014
|
const { managedEnv } = initEnvSources;
|
|
7014
7015
|
const initInputEnv = getHotUpdaterInitInputEnv(initEnvSources, nonInteractive);
|
|
7015
|
-
const saved =
|
|
7016
|
+
const saved = resolveInitProviderInputs(initInputEnv, initProvider);
|
|
7016
7017
|
const token = await resolveVercelToken({
|
|
7017
7018
|
cwd,
|
|
7018
7019
|
nonInteractive,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/vercel",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.50",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"@vercel/cli-auth": "0.3.10",
|
|
42
42
|
"@vercel/cli-config": "0.3.1",
|
|
43
43
|
"pg": "8.13.1",
|
|
44
|
-
"@hot-updater/
|
|
45
|
-
"@hot-updater/
|
|
46
|
-
"@hot-updater/postgres": "1.2.0-rc.
|
|
47
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
48
|
-
"@hot-updater/server": "1.2.0-rc.
|
|
44
|
+
"@hot-updater/cli-tools": "1.2.0-rc.50",
|
|
45
|
+
"@hot-updater/plugin-core": "1.2.0-rc.50",
|
|
46
|
+
"@hot-updater/postgres": "1.2.0-rc.50",
|
|
47
|
+
"@hot-updater/protocol": "1.2.0-rc.50",
|
|
48
|
+
"@hot-updater/server": "1.2.0-rc.50"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^20",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"execa": "9.5.2",
|
|
55
55
|
"kysely": "0.28.17",
|
|
56
56
|
"vitest": "4.1.4",
|
|
57
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
57
|
+
"@hot-updater/test-utils": "1.2.0-rc.50"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "tsdown",
|