@hot-updater/cloudflare 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/package.json +7 -7
- package/src/d1Executor.ts +4 -3
- package/worker/dist/README.md +1 -1
- package/worker/dist/index.js +391 -156
- package/worker/dist/index.js.map +4 -4
package/worker/dist/index.js
CHANGED
|
@@ -2099,43 +2099,6 @@ var withSchemaFence = /* @__PURE__ */ __name((adapter, adapterName, expected, fi
|
|
|
2099
2099
|
var METER = /* @__PURE__ */ Symbol.for("@hot-updater/plugin-core/read-meter");
|
|
2100
2100
|
var readMeterOf = /* @__PURE__ */ __name((database) => typeof database === "object" && database !== null ? database[METER] : void 0, "readMeterOf");
|
|
2101
2101
|
|
|
2102
|
-
// ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
2103
|
-
var storedSettings = /* @__PURE__ */ __name(async (adapter, keys) => {
|
|
2104
|
-
const rows = await readSettings(adapter, keys);
|
|
2105
|
-
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
2106
|
-
}, "storedSettings");
|
|
2107
|
-
var writeSchemaSettings = /* @__PURE__ */ __name(async (adapter, adapterName, settings) => {
|
|
2108
|
-
const stored2 = await storedSettings(adapter, Object.keys(settings));
|
|
2109
|
-
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
2110
|
-
const row = stored2.get(key);
|
|
2111
|
-
if (row === null || row === void 0) return [{
|
|
2112
|
-
type: "insert",
|
|
2113
|
-
table: SETTINGS_TABLE,
|
|
2114
|
-
row: {
|
|
2115
|
-
key,
|
|
2116
|
-
value,
|
|
2117
|
-
_v: 0
|
|
2118
|
-
}
|
|
2119
|
-
}];
|
|
2120
|
-
if (row.value === value) return [];
|
|
2121
|
-
return [{
|
|
2122
|
-
type: "patch",
|
|
2123
|
-
table: SETTINGS_TABLE,
|
|
2124
|
-
key: [key],
|
|
2125
|
-
set: { value },
|
|
2126
|
-
guard: { v: Number(row._v) },
|
|
2127
|
-
previous: row
|
|
2128
|
-
}];
|
|
2129
|
-
});
|
|
2130
|
-
if (ops.length === 0) return;
|
|
2131
|
-
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
2132
|
-
}, "writeSchemaSettings");
|
|
2133
|
-
var migrateSchema = /* @__PURE__ */ __name(async (adapter, adapterName, tables, settings) => {
|
|
2134
|
-
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2135
|
-
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2136
|
-
await writeSchemaSettings(adapter, adapterName, settings);
|
|
2137
|
-
}, "migrateSchema");
|
|
2138
|
-
|
|
2139
2102
|
// ../plugin-core/dist/engine/database/sql/sqlSchema.mjs
|
|
2140
2103
|
var quoteSql = /* @__PURE__ */ __name((dialect, name) => dialect === "mysql" ? `\`${name.replaceAll("`", "``")}\`` : `"${name.replaceAll('"', '""')}"`, "quoteSql");
|
|
2141
2104
|
var isMultiIndex = /* @__PURE__ */ __name((table, index) => index.eq.some((column) => findPhysicalColumn(table, column).multi), "isMultiIndex");
|
|
@@ -2179,6 +2142,7 @@ var sqlTableShapes = /* @__PURE__ */ __name((dialect, tables, tablePrefix = "")
|
|
|
2179
2142
|
const name = tablePrefix + table.name;
|
|
2180
2143
|
const indexed = /* @__PURE__ */ new Set([...table.key, ...table.indexes.flatMap(({ eq, sort: sort2 }) => [...eq, ...sort2])]);
|
|
2181
2144
|
if (dialect === "mysql") checkMysqlKey(table, "key", table.key);
|
|
2145
|
+
const covered = /* @__PURE__ */ new Set([JSON.stringify(table.key)]);
|
|
2182
2146
|
const indexes = table.indexes.flatMap((index) => {
|
|
2183
2147
|
const columns = [...index.eq, ...indexOrderColumns(table, index)];
|
|
2184
2148
|
if (dialect === "mysql") checkMysqlKey(table, `index ${index.name}`, columns);
|
|
@@ -2203,7 +2167,10 @@ var sqlTableShapes = /* @__PURE__ */ __name((dialect, tables, tablePrefix = "")
|
|
|
2203
2167
|
}
|
|
2204
2168
|
}];
|
|
2205
2169
|
}
|
|
2206
|
-
if (!index.unique
|
|
2170
|
+
if (!index.unique) {
|
|
2171
|
+
if (covered.has(JSON.stringify(columns))) return [];
|
|
2172
|
+
covered.add(JSON.stringify(columns));
|
|
2173
|
+
}
|
|
2207
2174
|
return [{
|
|
2208
2175
|
kind: "index",
|
|
2209
2176
|
name: shortSqlName(`${name}_${index.name}`),
|
|
@@ -2470,9 +2437,17 @@ var releases = defineTable({
|
|
|
2470
2437
|
all: {
|
|
2471
2438
|
eq: [],
|
|
2472
2439
|
sort: ["id"]
|
|
2440
|
+
},
|
|
2441
|
+
scopes: {
|
|
2442
|
+
eq: [],
|
|
2443
|
+
sort: ["scope_key"]
|
|
2473
2444
|
}
|
|
2474
2445
|
}
|
|
2475
2446
|
});
|
|
2447
|
+
var LATE_INDEXES = [{
|
|
2448
|
+
table: "releases",
|
|
2449
|
+
index: "scopes"
|
|
2450
|
+
}];
|
|
2476
2451
|
var releaseCatalogs = defineTable({
|
|
2477
2452
|
scope_key: {
|
|
2478
2453
|
type: "string",
|
|
@@ -2805,6 +2780,90 @@ var refuseV0Database = /* @__PURE__ */ __name((adapterName, stored2) => {
|
|
|
2805
2780
|
if (typeof version2 !== "string" || stored2.has("schema.engine")) return;
|
|
2806
2781
|
throw new HotUpdaterSchemaMigrationRequiredError(adapterName, version2);
|
|
2807
2782
|
}, "refuseV0Database");
|
|
2783
|
+
var compareVersions = /* @__PURE__ */ __name((left, right) => {
|
|
2784
|
+
const parse4 = /* @__PURE__ */ __name((version2) => /^\d+(?:\.\d+)*$/u.test(version2) ? version2.split(".").map(Number) : [NaN], "parse");
|
|
2785
|
+
const [a, b] = [parse4(left), parse4(right)];
|
|
2786
|
+
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
2787
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
2788
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
2789
|
+
if (difference !== 0) return difference;
|
|
2790
|
+
}
|
|
2791
|
+
return 0;
|
|
2792
|
+
}, "compareVersions");
|
|
2793
|
+
var DEFAULT_ORDERED_SETTINGS = ["schema.core"];
|
|
2794
|
+
var refuseNewerSchema = /* @__PURE__ */ __name((adapterName, stored2, settings, ordered = DEFAULT_ORDERED_SETTINGS) => {
|
|
2795
|
+
const newer = ordered.flatMap((key) => {
|
|
2796
|
+
const found = stored2.get(key);
|
|
2797
|
+
const expected = settings[key];
|
|
2798
|
+
return typeof found === "string" && expected !== void 0 && compareVersions(found, expected) > 0 ? [{
|
|
2799
|
+
key,
|
|
2800
|
+
found,
|
|
2801
|
+
expected
|
|
2802
|
+
}] : [];
|
|
2803
|
+
});
|
|
2804
|
+
const core = newer.find(({ key }) => key === "schema.core");
|
|
2805
|
+
if (core === void 0) return;
|
|
2806
|
+
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.`);
|
|
2807
|
+
}, "refuseNewerSchema");
|
|
2808
|
+
var settingsOperation = /* @__PURE__ */ __name((stored2, changed) => ({
|
|
2809
|
+
type: "custom",
|
|
2810
|
+
description: `Record ${changed.map(([key, value]) => {
|
|
2811
|
+
const found = stored2.get(key);
|
|
2812
|
+
return typeof found === "string" ? `${key} ${found} \u2192 ${value}` : `${key} ${value}`;
|
|
2813
|
+
}).join(", ")}`
|
|
2814
|
+
}), "settingsOperation");
|
|
2815
|
+
|
|
2816
|
+
// ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
2817
|
+
var storedSettings = /* @__PURE__ */ __name(async (adapter, keys) => {
|
|
2818
|
+
const rows = await readSettings(adapter, keys);
|
|
2819
|
+
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
2820
|
+
}, "storedSettings");
|
|
2821
|
+
var writeSchemaSettings = /* @__PURE__ */ __name(async (adapter, adapterName, settings, ordered) => {
|
|
2822
|
+
const stored2 = await storedSettings(adapter, Object.keys(settings));
|
|
2823
|
+
refuseNewerSchema(adapterName, new Map([...stored2].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2824
|
+
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
2825
|
+
const row = stored2.get(key);
|
|
2826
|
+
if (row === null || row === void 0) return [{
|
|
2827
|
+
type: "insert",
|
|
2828
|
+
table: SETTINGS_TABLE,
|
|
2829
|
+
row: {
|
|
2830
|
+
key,
|
|
2831
|
+
value,
|
|
2832
|
+
_v: 0
|
|
2833
|
+
}
|
|
2834
|
+
}];
|
|
2835
|
+
if (row.value === value) return [];
|
|
2836
|
+
return [{
|
|
2837
|
+
type: "patch",
|
|
2838
|
+
table: SETTINGS_TABLE,
|
|
2839
|
+
key: [key],
|
|
2840
|
+
set: { value },
|
|
2841
|
+
guard: { v: Number(row._v) },
|
|
2842
|
+
previous: row
|
|
2843
|
+
}];
|
|
2844
|
+
});
|
|
2845
|
+
if (ops.length === 0) return;
|
|
2846
|
+
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
2847
|
+
}, "writeSchemaSettings");
|
|
2848
|
+
var fillLateIndexes = /* @__PURE__ */ __name(async (adapter, tables, { dryRun: dryRun2 = false } = {}) => {
|
|
2849
|
+
const fillIndex = adapter.migrations?.fillIndex;
|
|
2850
|
+
if (fillIndex === void 0) return [];
|
|
2851
|
+
const lacking = [];
|
|
2852
|
+
for (const { table: name, index } of LATE_INDEXES) {
|
|
2853
|
+
const table = tables.find((candidate) => candidate.name === name);
|
|
2854
|
+
if (table === void 0) continue;
|
|
2855
|
+
if (await fillIndex(table, index, { dryRun: dryRun2 }) > 0) lacking.push(`${name}.${index}`);
|
|
2856
|
+
}
|
|
2857
|
+
return lacking;
|
|
2858
|
+
}, "fillLateIndexes");
|
|
2859
|
+
var migrateSchema = /* @__PURE__ */ __name(async (adapter, adapterName, tables, settings, ordered) => {
|
|
2860
|
+
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2861
|
+
const stored2 = await storedSettings(adapter, Object.keys(settings)).catch(() => void 0);
|
|
2862
|
+
if (stored2 !== void 0) refuseNewerSchema(adapterName, new Map([...stored2].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2863
|
+
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2864
|
+
await fillLateIndexes(adapter, tables);
|
|
2865
|
+
await writeSchemaSettings(adapter, adapterName, settings, ordered);
|
|
2866
|
+
}, "migrateSchema");
|
|
2808
2867
|
|
|
2809
2868
|
// ../plugin-core/dist/engine/database/cursor.mjs
|
|
2810
2869
|
var encoder = new TextEncoder();
|
|
@@ -3695,22 +3754,27 @@ var createEngineMigrator = /* @__PURE__ */ __name((options) => {
|
|
|
3695
3754
|
const makeResult = /* @__PURE__ */ __name(async (migrate = {}) => {
|
|
3696
3755
|
const stored2 = await options.readSettings();
|
|
3697
3756
|
refuseV0Database(options.adapterName, stored2);
|
|
3698
|
-
|
|
3757
|
+
refuseNewerSchema(options.adapterName, stored2, options.settings, options.ordered);
|
|
3758
|
+
const changed = Object.entries(options.settings).filter(([key, value]) => stored2.get(key) !== value);
|
|
3759
|
+
if (changed.length === 0) {
|
|
3760
|
+
const lacking = await fillLateIndexes(options.adapter, options.schema.tables, { dryRun: true });
|
|
3761
|
+
if (lacking.length === 0) return getEmptyMigrationResult();
|
|
3762
|
+
return {
|
|
3763
|
+
operations: [{
|
|
3764
|
+
type: "custom",
|
|
3765
|
+
description: `Write the index items rows lack: ${lacking.join(", ")}`
|
|
3766
|
+
}],
|
|
3767
|
+
execute: /* @__PURE__ */ __name(async () => {
|
|
3768
|
+
await fillLateIndexes(options.adapter, options.schema.tables);
|
|
3769
|
+
}, "execute")
|
|
3770
|
+
};
|
|
3771
|
+
}
|
|
3699
3772
|
return {
|
|
3700
|
-
operations: [
|
|
3701
|
-
type: "create-table",
|
|
3702
|
-
value: {
|
|
3703
|
-
ormName: table.name,
|
|
3704
|
-
columns: Object.fromEntries(table.columns.map((column) => [column.name, {
|
|
3705
|
-
ormName: column.name,
|
|
3706
|
-
type: column.type
|
|
3707
|
-
}]))
|
|
3708
|
-
}
|
|
3709
|
-
})), ...migrate.updateSettings === false ? [] : [{
|
|
3773
|
+
operations: [{
|
|
3710
3774
|
type: "custom",
|
|
3711
|
-
description:
|
|
3712
|
-
}]],
|
|
3713
|
-
execute: /* @__PURE__ */ __name(() => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings), "execute")
|
|
3775
|
+
description: "Create the tables and indexes the database lacks"
|
|
3776
|
+
}, ...migrate.updateSettings === false ? [] : [settingsOperation(stored2, changed)]],
|
|
3777
|
+
execute: /* @__PURE__ */ __name(() => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings, options.ordered), "execute")
|
|
3714
3778
|
};
|
|
3715
3779
|
}, "makeResult");
|
|
3716
3780
|
return {
|
|
@@ -3738,7 +3802,8 @@ var coreSettings = {
|
|
|
3738
3802
|
};
|
|
3739
3803
|
var coreTarget = {
|
|
3740
3804
|
schema: coreSchema2,
|
|
3741
|
-
settings: coreSettings
|
|
3805
|
+
settings: coreSettings,
|
|
3806
|
+
ordered: ["schema.core"]
|
|
3742
3807
|
};
|
|
3743
3808
|
var aggregateBatchingTables = resolveSchema([aggregateBatchingModule]).tables;
|
|
3744
3809
|
var pluginSettings = /* @__PURE__ */ __name((plugins) => Object.fromEntries(plugins.map(({ id, schemaVersion }) => [`schema.${id}`, schemaVersion])), "pluginSettings");
|
|
@@ -3749,11 +3814,12 @@ var pluginModule = /* @__PURE__ */ __name(({ id, schema, namespace }) => ({
|
|
|
3749
3814
|
}), "pluginModule");
|
|
3750
3815
|
var createEngineDatabase = /* @__PURE__ */ __name(({ name, adapter, onCachedRoutesChange, aggregateBatching, retry, readSettings: readStored }) => {
|
|
3751
3816
|
const fenced = withSchemaFence(adapter, name, coreSettings);
|
|
3752
|
-
const createMigrator = /* @__PURE__ */ __name(({ schema, settings } = coreTarget) => createEngineMigrator({
|
|
3817
|
+
const createMigrator = /* @__PURE__ */ __name(({ schema, settings, ordered } = coreTarget) => createEngineMigrator({
|
|
3753
3818
|
adapterName: name,
|
|
3754
3819
|
adapter,
|
|
3755
3820
|
schema,
|
|
3756
3821
|
settings,
|
|
3822
|
+
ordered,
|
|
3757
3823
|
readSettings: readStored ?? (async () => {
|
|
3758
3824
|
const rows = await readSettings(adapter, Object.keys(settings)).catch((error) => {
|
|
3759
3825
|
if (isMissingSchemaError(error)) return [];
|
|
@@ -3780,6 +3846,11 @@ var StaleReadError = class extends Error {
|
|
|
3780
3846
|
}
|
|
3781
3847
|
};
|
|
3782
3848
|
var idOf = /* @__PURE__ */ __name((table, key) => JSON.stringify([table, key]), "idOf");
|
|
3849
|
+
var versionsOf = /* @__PURE__ */ __name((ops) => JSON.stringify(ops.map((op) => op.type === "insert" ? [op.table.name, rowKey(op.table, op.row)] : [
|
|
3850
|
+
op.table.name,
|
|
3851
|
+
op.key,
|
|
3852
|
+
"guard" in op ? op.guard?.v : void 0
|
|
3853
|
+
])), "versionsOf");
|
|
3783
3854
|
var versionOf = /* @__PURE__ */ __name((row) => Number(row["_v"]), "versionOf");
|
|
3784
3855
|
var isKeyed = /* @__PURE__ */ __name((value) => value !== null && value !== void 0, "isKeyed");
|
|
3785
3856
|
var misuse = /* @__PURE__ */ __name((table, message) => new DatabaseTransactionError(`${table}: ${message}`), "misuse");
|
|
@@ -4111,7 +4182,9 @@ var createTransactions = /* @__PURE__ */ __name(({ adapter, schema, reads, retry
|
|
|
4111
4182
|
assertOutsideTransaction();
|
|
4112
4183
|
let run3;
|
|
4113
4184
|
let negative;
|
|
4114
|
-
|
|
4185
|
+
let failures = 0;
|
|
4186
|
+
let lost;
|
|
4187
|
+
for (let round = 0; ; round += 1) {
|
|
4115
4188
|
const delay = round && Math.min(maxDelayMs, baseDelayMs * 2 ** (round - 1));
|
|
4116
4189
|
if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay / 2 + Math.random() * (delay / 2)));
|
|
4117
4190
|
run3 ??= await attempt(fn).catch((error) => {
|
|
@@ -4120,6 +4193,8 @@ var createTransactions = /* @__PURE__ */ __name(({ adapter, schema, reads, retry
|
|
|
4120
4193
|
});
|
|
4121
4194
|
if (run3 === void 0) {
|
|
4122
4195
|
onRetry?.("rerun", round + 1);
|
|
4196
|
+
lost = void 0;
|
|
4197
|
+
if ((failures += 1) >= attempts) break;
|
|
4123
4198
|
continue;
|
|
4124
4199
|
}
|
|
4125
4200
|
let aggregates;
|
|
@@ -4130,8 +4205,14 @@ var createTransactions = /* @__PURE__ */ __name(({ adapter, schema, reads, retry
|
|
|
4130
4205
|
negative = error;
|
|
4131
4206
|
onRetry?.("rerun", round + 1);
|
|
4132
4207
|
run3 = void 0;
|
|
4208
|
+
lost = void 0;
|
|
4209
|
+
if ((failures += 1) >= attempts) break;
|
|
4133
4210
|
continue;
|
|
4134
4211
|
}
|
|
4212
|
+
const versions = versionsOf(aggregates);
|
|
4213
|
+
if (lost !== void 0 && versions !== lost) failures -= 1;
|
|
4214
|
+
lost = void 0;
|
|
4215
|
+
if (failures >= attempts) break;
|
|
4135
4216
|
const ops = [...run3.ops, ...aggregates];
|
|
4136
4217
|
if (ops.length <= 1 && ops.every(({ type }) => type === "check")) return run3.result;
|
|
4137
4218
|
if (!adapter.fits(ops)) throw new DatabaseConstraintError("too_large", ops[0].table.name);
|
|
@@ -4145,12 +4226,16 @@ var createTransactions = /* @__PURE__ */ __name(({ adapter, schema, reads, retry
|
|
|
4145
4226
|
const failed2 = "failedOp" in outcome ? outcome.failedOp : void 0;
|
|
4146
4227
|
if (failed2 === void 0 || failed2 >= run3.ops.length) {
|
|
4147
4228
|
onRetry?.("resend", round + 1);
|
|
4229
|
+
failures += 1;
|
|
4230
|
+
if (failed2 !== void 0) lost = versions;
|
|
4231
|
+
else if (failures >= attempts) break;
|
|
4148
4232
|
continue;
|
|
4149
4233
|
}
|
|
4150
4234
|
const reason = await classify(ops[failed2], run3.read);
|
|
4151
4235
|
if (reason) throw new DatabaseConstraintError(reason, ops[failed2].table.name);
|
|
4152
4236
|
onRetry?.("rerun", round + 1);
|
|
4153
4237
|
run3 = void 0;
|
|
4238
|
+
if ((failures += 1) >= attempts) break;
|
|
4154
4239
|
}
|
|
4155
4240
|
throw negative ?? new DatabaseConflictError(`The transaction conflicted ${attempts} times.`);
|
|
4156
4241
|
} };
|
|
@@ -4725,7 +4810,7 @@ var createSqlAdapter = /* @__PURE__ */ __name(({ executor, tablePrefix = "", max
|
|
|
4725
4810
|
}, "createSqlAdapter");
|
|
4726
4811
|
|
|
4727
4812
|
// ../../packages/server/dist/package.mjs
|
|
4728
|
-
var version = "1.2.0-rc.
|
|
4813
|
+
var version = "1.2.0-rc.50";
|
|
4729
4814
|
|
|
4730
4815
|
// ../../packages/server/dist/version.mjs
|
|
4731
4816
|
var HOT_UPDATER_SERVER_VERSION = version;
|
|
@@ -4854,9 +4939,14 @@ var releaseCatalogScopeKeyOf = /* @__PURE__ */ __name((input) => input.strategy
|
|
|
4854
4939
|
platform: input.platform,
|
|
4855
4940
|
strategy: "FINGERPRINT"
|
|
4856
4941
|
}), "releaseCatalogScopeKeyOf");
|
|
4857
|
-
var
|
|
4858
|
-
|
|
4859
|
-
|
|
4942
|
+
var parseReleaseCatalogRow = /* @__PURE__ */ __name(({ payload, ...row }) => ({
|
|
4943
|
+
row,
|
|
4944
|
+
compiled: parseCompiledCatalog(payload, row.strategy)
|
|
4945
|
+
}), "parseReleaseCatalogRow");
|
|
4946
|
+
var projectParsedReleaseCatalogRow = /* @__PURE__ */ __name((parsed, input, scopeKey = releaseCatalogScopeKeyOf(input)) => {
|
|
4947
|
+
if (parsed === null) return null;
|
|
4948
|
+
const { row, compiled } = parsed;
|
|
4949
|
+
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;
|
|
4860
4950
|
const appVersion = input.strategy === "APP_VERSION" ? input.appVersion : void 0;
|
|
4861
4951
|
return {
|
|
4862
4952
|
catalogId: row.catalog_id,
|
|
@@ -4868,7 +4958,8 @@ var projectReleaseCatalogRow = /* @__PURE__ */ __name((row, input, scopeKey = re
|
|
|
4868
4958
|
schemaVersion: RELEASE_CATALOG_SCHEMA_VERSION,
|
|
4869
4959
|
scopeKey
|
|
4870
4960
|
};
|
|
4871
|
-
}, "
|
|
4961
|
+
}, "projectParsedReleaseCatalogRow");
|
|
4962
|
+
var projectReleaseCatalogRow = /* @__PURE__ */ __name((row, input, scopeKey = releaseCatalogScopeKeyOf(input)) => projectParsedReleaseCatalogRow(row === null ? null : parseReleaseCatalogRow(row), input, scopeKey), "projectReleaseCatalogRow");
|
|
4872
4963
|
|
|
4873
4964
|
// ../../packages/server/dist/db/updateArtifacts.mjs
|
|
4874
4965
|
var HBC_ASSET_PATH_RE = /\.bundle$/;
|
|
@@ -5771,8 +5862,35 @@ var createCoreReads = /* @__PURE__ */ __name((db, storage) => {
|
|
|
5771
5862
|
...after(input)
|
|
5772
5863
|
})).rows.map(toCatalogRow);
|
|
5773
5864
|
},
|
|
5774
|
-
/**
|
|
5775
|
-
|
|
5865
|
+
/**
|
|
5866
|
+
* Up to `limit` scope keys that have releases, ascending after `after`:
|
|
5867
|
+
* one limit-1 seek of the `scopes` index past each scope, so the reads
|
|
5868
|
+
* grow with the scopes, not with their releases.
|
|
5869
|
+
*/
|
|
5870
|
+
async listReleaseScopeKeys(input) {
|
|
5871
|
+
const scopeKeys = [];
|
|
5872
|
+
for (let last = input.after ?? ""; scopeKeys.length < input.limit; ) {
|
|
5873
|
+
const { rows } = await db.findMany("releases", {
|
|
5874
|
+
index: "scopes",
|
|
5875
|
+
where: {},
|
|
5876
|
+
limit: 1,
|
|
5877
|
+
range: { gt: last }
|
|
5878
|
+
});
|
|
5879
|
+
if (rows[0] === void 0) break;
|
|
5880
|
+
last = rows[0].scope_key;
|
|
5881
|
+
scopeKeys.push(last);
|
|
5882
|
+
}
|
|
5883
|
+
return scopeKeys;
|
|
5884
|
+
},
|
|
5885
|
+
/** Every channel by name; with `input`, one keyset page of them. */
|
|
5886
|
+
async listChannels(input) {
|
|
5887
|
+
if (input !== void 0) return (await db.findMany("channels", {
|
|
5888
|
+
index: "all",
|
|
5889
|
+
where: {},
|
|
5890
|
+
order: input.order ?? "asc",
|
|
5891
|
+
limit: input.limit,
|
|
5892
|
+
...after(input)
|
|
5893
|
+
})).rows.map(toChannelRow);
|
|
5776
5894
|
return (await drain((page2) => db.findMany("channels", {
|
|
5777
5895
|
index: "all",
|
|
5778
5896
|
where: {},
|
|
@@ -5780,6 +5898,11 @@ var createCoreReads = /* @__PURE__ */ __name((db, storage) => {
|
|
|
5780
5898
|
...page2
|
|
5781
5899
|
}))).map(toChannelRow);
|
|
5782
5900
|
},
|
|
5901
|
+
async getChannels(ids) {
|
|
5902
|
+
const unique = [...new Set(ids)];
|
|
5903
|
+
if (unique.length === 0) return [];
|
|
5904
|
+
return (await db.findByKeys("channels", unique.map((id) => ({ id })))).flatMap((row) => row ? [toChannelRow(row)] : []);
|
|
5905
|
+
},
|
|
5783
5906
|
async findChannelByName(name) {
|
|
5784
5907
|
const row = await db.findOne("channels", { name });
|
|
5785
5908
|
return row === null ? null : toChannelRow(row);
|
|
@@ -6601,24 +6724,26 @@ var checkScope = /* @__PURE__ */ __name((scope) => {
|
|
|
6601
6724
|
});
|
|
6602
6725
|
if (scope.strategy === "FINGERPRINT" !== (scope.fingerprintHash !== null) || scope.scopeKey !== expected) fail2("INVALID_SCOPE", "Release catalog scope metadata is inconsistent");
|
|
6603
6726
|
}, "checkScope");
|
|
6604
|
-
var
|
|
6727
|
+
var drainReleases = /* @__PURE__ */ __name(async (page2) => {
|
|
6605
6728
|
const rows = [];
|
|
6606
6729
|
let cursor;
|
|
6607
6730
|
do {
|
|
6608
|
-
const
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
scope_key: scopeKey,
|
|
6612
|
-
enabled: true
|
|
6613
|
-
},
|
|
6614
|
-
limit: PAGE3,
|
|
6615
|
-
...cursor === void 0 ? {} : { cursor }
|
|
6616
|
-
});
|
|
6617
|
-
rows.push(...page2.rows.map(toReleaseRow));
|
|
6618
|
-
cursor = page2.next;
|
|
6731
|
+
const found = await page2(cursor);
|
|
6732
|
+
rows.push(...found.rows.map((row) => toReleaseRow(row)));
|
|
6733
|
+
cursor = found.next;
|
|
6619
6734
|
} while (cursor !== void 0);
|
|
6620
6735
|
return rows;
|
|
6621
|
-
}, "
|
|
6736
|
+
}, "drainReleases");
|
|
6737
|
+
var enabledIn = /* @__PURE__ */ __name((scopeKey, cursor) => ({
|
|
6738
|
+
index: "byScopeEnabled",
|
|
6739
|
+
where: {
|
|
6740
|
+
scope_key: scopeKey,
|
|
6741
|
+
enabled: true
|
|
6742
|
+
},
|
|
6743
|
+
limit: PAGE3,
|
|
6744
|
+
...cursor === void 0 ? {} : { cursor }
|
|
6745
|
+
}), "enabledIn");
|
|
6746
|
+
var enabledReleases = /* @__PURE__ */ __name((tx, scopeKey) => drainReleases((cursor) => tx.findMany("releases", enabledIn(scopeKey, cursor))), "enabledReleases");
|
|
6622
6747
|
var latestReleaseId = /* @__PURE__ */ __name(async (tx, scopeKey) => {
|
|
6623
6748
|
const { rows } = await tx.findMany("releases", {
|
|
6624
6749
|
index: "byScope",
|
|
@@ -6628,14 +6753,10 @@ var latestReleaseId = /* @__PURE__ */ __name(async (tx, scopeKey) => {
|
|
|
6628
6753
|
});
|
|
6629
6754
|
return rows[0]?.id ?? null;
|
|
6630
6755
|
}, "latestReleaseId");
|
|
6631
|
-
var
|
|
6632
|
-
const
|
|
6633
|
-
strategy: scope.strategy,
|
|
6634
|
-
releases: enabled.map(releaseRowToRelease)
|
|
6635
|
-
});
|
|
6636
|
-
const generation = (stored2.generation ?? 0) + 1;
|
|
6756
|
+
var nextCatalog = /* @__PURE__ */ __name((scope, stored2, compilation, updatedAtMs) => {
|
|
6757
|
+
const generation = (stored2.catalog?.generation ?? 0) + 1;
|
|
6637
6758
|
if (!Number.isSafeInteger(generation)) fail2("CATALOG_GENERATION_EXHAUSTED", `Catalog "${scope.scopeKey}" exhausted its generation counter`);
|
|
6638
|
-
|
|
6759
|
+
return {
|
|
6639
6760
|
scope_key: scope.scopeKey,
|
|
6640
6761
|
catalog_id: stored2.catalog?.catalog_id ?? createUUIDv7(),
|
|
6641
6762
|
strategy: scope.strategy,
|
|
@@ -6650,6 +6771,22 @@ var writeCatalog = /* @__PURE__ */ __name(async (tx, scope, stored2, enabled, up
|
|
|
6650
6771
|
is_tombstone: compilation.payload.releaseDescriptors.length === 0,
|
|
6651
6772
|
updated_at_ms: updatedAtMs
|
|
6652
6773
|
};
|
|
6774
|
+
}, "nextCatalog");
|
|
6775
|
+
var compileScope = /* @__PURE__ */ __name(async (scope, enabled) => {
|
|
6776
|
+
try {
|
|
6777
|
+
return await compileReleaseCatalog({
|
|
6778
|
+
strategy: scope.strategy,
|
|
6779
|
+
releases: enabled.map(releaseRowToRelease)
|
|
6780
|
+
});
|
|
6781
|
+
} catch (error) {
|
|
6782
|
+
if (!(error instanceof ReleaseCatalogCompilationError) || error.code !== "CATALOG_OVERSIZE") throw error;
|
|
6783
|
+
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.
|
|
6784
|
+
Disable or delete old bundles on that channel, then try again.`);
|
|
6785
|
+
}
|
|
6786
|
+
}, "compileScope");
|
|
6787
|
+
var writeCatalog = /* @__PURE__ */ __name(async (tx, scope, stored2, enabled, updatedAtMs) => {
|
|
6788
|
+
const compilation = await compileScope(scope, enabled);
|
|
6789
|
+
const catalog = nextCatalog(scope, stored2, compilation, updatedAtMs);
|
|
6653
6790
|
const { scope_key: _scopeKey, ...set } = catalog;
|
|
6654
6791
|
if (stored2.row === null) tx.create("release_catalogs", catalog);
|
|
6655
6792
|
else tx.update("release_catalogs", stored2.row, set);
|
|
@@ -6728,17 +6865,39 @@ var changeReleases = /* @__PURE__ */ __name((db, inputs) => {
|
|
|
6728
6865
|
return results;
|
|
6729
6866
|
});
|
|
6730
6867
|
}, "changeReleases");
|
|
6868
|
+
var isCurrent = /* @__PURE__ */ __name((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, "isCurrent");
|
|
6869
|
+
var catalogRowScope = /* @__PURE__ */ __name((row) => ({
|
|
6870
|
+
channelId: row.channel_id,
|
|
6871
|
+
channelName: decodeChannelKey(row.channel_key),
|
|
6872
|
+
fingerprintHash: row.fingerprint_hash,
|
|
6873
|
+
platform: row.platform,
|
|
6874
|
+
scopeKey: row.scope_key,
|
|
6875
|
+
strategy: row.strategy
|
|
6876
|
+
}), "catalogRowScope");
|
|
6877
|
+
var preflightRebuild = /* @__PURE__ */ __name(async (db, scopeKey, updatedAtMs) => {
|
|
6878
|
+
const row = await db.findOne("release_catalogs", { scope_key: scopeKey });
|
|
6879
|
+
if (row === null) throw new Error(`Release catalog "${scopeKey}" was not found.`);
|
|
6880
|
+
const current = toCatalogRow(row);
|
|
6881
|
+
const scope = catalogRowScope(current);
|
|
6882
|
+
checkScope(scope);
|
|
6883
|
+
const enabled = await drainReleases((cursor) => db.findMany("releases", enabledIn(scopeKey, cursor)));
|
|
6884
|
+
const compilation = await compileScope(scope, enabled);
|
|
6885
|
+
const changed = !isCurrent(scope, current, compilation);
|
|
6886
|
+
return {
|
|
6887
|
+
changed,
|
|
6888
|
+
currentCatalog: current,
|
|
6889
|
+
diagnostics: compilation.diagnostics,
|
|
6890
|
+
projectedCatalog: changed ? nextCatalog(scope, { catalog: current }, compilation, updatedAtMs) : current
|
|
6891
|
+
};
|
|
6892
|
+
}, "preflightRebuild");
|
|
6731
6893
|
var rebuildScope = /* @__PURE__ */ __name(async (tx, scope, updatedAtMs) => {
|
|
6732
6894
|
checkScope(scope);
|
|
6733
6895
|
const stored2 = await readCatalog(tx, scope.scopeKey);
|
|
6734
6896
|
assertHistory(stored2, await latestReleaseId(tx, scope.scopeKey) !== null);
|
|
6735
6897
|
const enabled = await enabledReleases(tx, scope.scopeKey);
|
|
6736
|
-
const compilation = await
|
|
6737
|
-
strategy: scope.strategy,
|
|
6738
|
-
releases: enabled.map(releaseRowToRelease)
|
|
6739
|
-
});
|
|
6898
|
+
const compilation = await compileScope(scope, enabled);
|
|
6740
6899
|
const current = stored2.catalog;
|
|
6741
|
-
if (current !== null &&
|
|
6900
|
+
if (current !== null && isCurrent(scope, current, compilation)) return {
|
|
6742
6901
|
catalog: current,
|
|
6743
6902
|
current,
|
|
6744
6903
|
changed: false,
|
|
@@ -6841,14 +7000,7 @@ var mutationResult = /* @__PURE__ */ __name(({ catalog, release }) => ({
|
|
|
6841
7000
|
var catalogScope = /* @__PURE__ */ __name(async (tx, scopeKey) => {
|
|
6842
7001
|
const row = await tx.findOne("release_catalogs", { scope_key: scopeKey });
|
|
6843
7002
|
if (row === null) throw new Error(`Release catalog "${scopeKey}" was not found.`);
|
|
6844
|
-
return
|
|
6845
|
-
channelId: row.channel_id,
|
|
6846
|
-
channelName: decodeChannelKey(row.channel_key),
|
|
6847
|
-
fingerprintHash: row.fingerprint_hash,
|
|
6848
|
-
platform: row.platform,
|
|
6849
|
-
scopeKey: row.scope_key,
|
|
6850
|
-
strategy: row.strategy
|
|
6851
|
-
};
|
|
7003
|
+
return catalogRowScope(toCatalogRow(row));
|
|
6852
7004
|
}, "catalogScope");
|
|
6853
7005
|
var createCoreOperations = /* @__PURE__ */ __name((db, { now = Date.now } = {}) => {
|
|
6854
7006
|
const ensureChannel = /* @__PURE__ */ __name(async (name) => (await insertChannel(db, {
|
|
@@ -7047,18 +7199,7 @@ var createCoreOperations = /* @__PURE__ */ __name((db, { now = Date.now } = {})
|
|
|
7047
7199
|
};
|
|
7048
7200
|
});
|
|
7049
7201
|
}, "rebuildReleaseCatalog"),
|
|
7050
|
-
preflightReleaseCatalogRebuild: /* @__PURE__ */ __name((scopeKey) =>
|
|
7051
|
-
const updatedAtMs = now();
|
|
7052
|
-
return dryRun(db, async (tx) => {
|
|
7053
|
-
const rebuilt = await rebuildScope(tx, await catalogScope(tx, scopeKey), updatedAtMs);
|
|
7054
|
-
return {
|
|
7055
|
-
changed: rebuilt.changed,
|
|
7056
|
-
currentCatalog: rebuilt.current,
|
|
7057
|
-
diagnostics: rebuilt.diagnostics,
|
|
7058
|
-
projectedCatalog: rebuilt.catalog
|
|
7059
|
-
};
|
|
7060
|
-
});
|
|
7061
|
-
}, "preflightReleaseCatalogRebuild"),
|
|
7202
|
+
preflightReleaseCatalogRebuild: /* @__PURE__ */ __name((scopeKey) => preflightRebuild(db, scopeKey, now()), "preflightReleaseCatalogRebuild"),
|
|
7062
7203
|
ensureChannel,
|
|
7063
7204
|
deleteChannel: /* @__PURE__ */ __name((id) => deleteChannel(db, id), "deleteChannel"),
|
|
7064
7205
|
updateBundle: /* @__PURE__ */ __name((id, update) => db.transaction(async (tx) => {
|
|
@@ -7320,6 +7461,10 @@ var answer = /* @__PURE__ */ __name(async (operation) => {
|
|
|
7320
7461
|
error: error.message
|
|
7321
7462
|
}, status);
|
|
7322
7463
|
}
|
|
7464
|
+
if (error instanceof ReleaseCatalogCompilationError && error.code === "CATALOG_OVERSIZE") return json({
|
|
7465
|
+
code: error.code,
|
|
7466
|
+
error: error.message
|
|
7467
|
+
}, 400);
|
|
7323
7468
|
if (error instanceof DatabaseBundleNotFoundError) return json({
|
|
7324
7469
|
code: "BUNDLE_NOT_FOUND",
|
|
7325
7470
|
error: error.message
|
|
@@ -7339,8 +7484,9 @@ var LIMITS = {
|
|
|
7339
7484
|
defaultValue: 50,
|
|
7340
7485
|
maxValue: 500
|
|
7341
7486
|
};
|
|
7342
|
-
var
|
|
7343
|
-
|
|
7487
|
+
var MAX_IDS = 100;
|
|
7488
|
+
var keyset = /* @__PURE__ */ __name((url, maxValue = LIMITS.maxValue, defaultOrder = "desc") => {
|
|
7489
|
+
const order = url.searchParams.get("order") ?? defaultOrder;
|
|
7344
7490
|
if (order !== "asc" && order !== "desc") throw new HandlerBadRequestError("order must be 'asc' or 'desc'.");
|
|
7345
7491
|
const limitParam = url.searchParams.get("limit");
|
|
7346
7492
|
const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
|
|
@@ -7522,12 +7668,40 @@ var createAdminRouteHandlers = /* @__PURE__ */ __name(() => ({
|
|
|
7522
7668
|
const rows = await core.listReleaseCatalogs(input);
|
|
7523
7669
|
return page(rows, input, (row) => row.scope_key);
|
|
7524
7670
|
}),
|
|
7525
|
-
/**
|
|
7671
|
+
/** Up to 100 scope keys that have releases, after `cursor`: one seek each. */
|
|
7672
|
+
listReleaseScopeKeys: onCore(async (core, request) => {
|
|
7673
|
+
const input = keyset(new URL(request.url), 100, "asc");
|
|
7674
|
+
if (input.order !== "asc" || input.through !== void 0) throw new HandlerBadRequestError("Release scopes are listed ascending, by limit and cursor only.");
|
|
7675
|
+
const rows = await core.listReleaseScopeKeys({
|
|
7676
|
+
limit: input.limit,
|
|
7677
|
+
...input.after === void 0 ? {} : { after: input.after }
|
|
7678
|
+
});
|
|
7679
|
+
return page(rows, input, (scopeKey) => scopeKey);
|
|
7680
|
+
}),
|
|
7681
|
+
/**
|
|
7682
|
+
* With `name`, the one channel of that name: 1 read. With `ids`, the
|
|
7683
|
+
* channels of up to 100 IDs: 1 batch read. With `limit` or `cursor`, one
|
|
7684
|
+
* page by name. With none, every channel, as servers before pages answered.
|
|
7685
|
+
*/
|
|
7526
7686
|
getChannels: onCore(async (core, request) => {
|
|
7527
|
-
const
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7687
|
+
const url = new URL(request.url);
|
|
7688
|
+
const name = url.searchParams.get("name");
|
|
7689
|
+
if (name !== null) {
|
|
7690
|
+
const channel = await core.findChannelByName(name);
|
|
7691
|
+
return channel === null ? notFound() : json({ data: channel });
|
|
7692
|
+
}
|
|
7693
|
+
const ids = url.searchParams.get("ids");
|
|
7694
|
+
if (ids !== null) {
|
|
7695
|
+
const list = ids.split(",").filter((id) => id.length > 0);
|
|
7696
|
+
if (list.length === 0 || list.length > MAX_IDS) throw new HandlerBadRequestError(`Channels by ID take ids=<channel id>,... with 1 to ${MAX_IDS} ids.`);
|
|
7697
|
+
return json({ data: await core.getChannels(list) });
|
|
7698
|
+
}
|
|
7699
|
+
if (url.searchParams.has("limit") || url.searchParams.has("cursor")) {
|
|
7700
|
+
const input = keyset(url, LIMITS.maxValue, "asc");
|
|
7701
|
+
const rows = await core.listChannels(input);
|
|
7702
|
+
return page(rows, input, (row) => row.name);
|
|
7703
|
+
}
|
|
7704
|
+
return json({ data: await core.listChannels() });
|
|
7531
7705
|
}),
|
|
7532
7706
|
/** The channel named in the body, created when missing. */
|
|
7533
7707
|
createChannel: onCore(async (core, request) => {
|
|
@@ -7578,7 +7752,7 @@ var createAdminRouteHandlers = /* @__PURE__ */ __name(() => ({
|
|
|
7578
7752
|
countBundles: onCore(async (core, request) => json({ data: await core.countBundles(platformOf(new URL(request.url))) })),
|
|
7579
7753
|
countBundleChildren: onCore(async (core, request) => {
|
|
7580
7754
|
const ids = (new URL(request.url).searchParams.get("ids") ?? "").split(",").filter((id) => id.length > 0);
|
|
7581
|
-
if (ids.length === 0 || ids.length >
|
|
7755
|
+
if (ids.length === 0 || ids.length > MAX_IDS) throw new HandlerBadRequestError(`Bundle child counts take ids=<bundle id>,... with 1 to ${MAX_IDS} ids.`);
|
|
7582
7756
|
return json({ data: await core.countBundleChildren(ids) });
|
|
7583
7757
|
}),
|
|
7584
7758
|
listBundleChildren: onCore(async (core, request, params) => {
|
|
@@ -7720,6 +7894,7 @@ var createAdminRouteHandlers = /* @__PURE__ */ __name(() => ({
|
|
|
7720
7894
|
markIosDevicesInBuild: onCore(async (core, request) => {
|
|
7721
7895
|
const { buildId, ids } = await body(request);
|
|
7722
7896
|
if (!isText(buildId) || !Array.isArray(ids) || !ids.every((id) => isText(id))) throw new HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
|
|
7897
|
+
if (ids.length > MAX_IDS) throw new HandlerBadRequestError(`Marking iOS devices in a build takes at most ${MAX_IDS} ids a request.`);
|
|
7723
7898
|
await core.markIosDevicesInBuild({
|
|
7724
7899
|
buildId,
|
|
7725
7900
|
ids
|
|
@@ -7789,6 +7964,11 @@ var ADMIN_ROUTES = [
|
|
|
7789
7964
|
path: "/release-catalogs",
|
|
7790
7965
|
handler: "listReleaseCatalogs"
|
|
7791
7966
|
},
|
|
7967
|
+
{
|
|
7968
|
+
method: "GET",
|
|
7969
|
+
path: "/release-scopes",
|
|
7970
|
+
handler: "listReleaseScopeKeys"
|
|
7971
|
+
},
|
|
7792
7972
|
{
|
|
7793
7973
|
method: "POST",
|
|
7794
7974
|
path: "/release-catalogs/:scopeKey/rebuild",
|
|
@@ -8022,37 +8202,52 @@ var catalogResponse = /* @__PURE__ */ __name(async (catalog, request) => {
|
|
|
8022
8202
|
}, "catalogResponse");
|
|
8023
8203
|
var createReleaseCatalogRouteHandlers = /* @__PURE__ */ __name(() => {
|
|
8024
8204
|
const cache = /* @__PURE__ */ new Map();
|
|
8205
|
+
const evict = /* @__PURE__ */ __name((insertedHit) => {
|
|
8206
|
+
const now = Date.now();
|
|
8207
|
+
let oldestMiss;
|
|
8208
|
+
let oldest;
|
|
8209
|
+
for (const [key, entry] of cache) if (entry.expiresAt <= now) cache.delete(key);
|
|
8210
|
+
else {
|
|
8211
|
+
if (entry.row === null) oldestMiss ??= key;
|
|
8212
|
+
oldest ??= key;
|
|
8213
|
+
}
|
|
8214
|
+
if (cache.size <= ORIGIN_CACHE_MAX_ENTRIES) return;
|
|
8215
|
+
const victim = oldestMiss ?? (insertedHit ? oldest : void 0);
|
|
8216
|
+
if (victim !== void 0) cache.delete(victim);
|
|
8217
|
+
}, "evict");
|
|
8025
8218
|
const inFlight = /* @__PURE__ */ new Map();
|
|
8026
|
-
const
|
|
8027
|
-
const cached = cache.get(
|
|
8219
|
+
const loadRow = /* @__PURE__ */ __name(async (scopeKey, load) => {
|
|
8220
|
+
const cached = cache.get(scopeKey);
|
|
8028
8221
|
if (cached !== void 0 && cached.expiresAt > Date.now()) {
|
|
8029
|
-
cache.delete(
|
|
8030
|
-
cache.set(
|
|
8031
|
-
return cached.
|
|
8222
|
+
cache.delete(scopeKey);
|
|
8223
|
+
cache.set(scopeKey, cached);
|
|
8224
|
+
return cached.row;
|
|
8032
8225
|
}
|
|
8033
|
-
if (cached !== void 0) cache.delete(
|
|
8034
|
-
const pending = inFlight.get(
|
|
8226
|
+
if (cached !== void 0) cache.delete(scopeKey);
|
|
8227
|
+
const pending = inFlight.get(scopeKey);
|
|
8035
8228
|
if (pending !== void 0) return pending;
|
|
8036
|
-
const next = load().then((
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
const oldestKey = cache.keys().next().value;
|
|
8044
|
-
if (oldestKey === void 0) break;
|
|
8045
|
-
cache.delete(oldestKey);
|
|
8046
|
-
}
|
|
8047
|
-
}
|
|
8048
|
-
return catalog;
|
|
8229
|
+
const next = load().then((row) => {
|
|
8230
|
+
cache.set(scopeKey, {
|
|
8231
|
+
row,
|
|
8232
|
+
expiresAt: Date.now() + ORIGIN_CACHE_TTL_MS
|
|
8233
|
+
});
|
|
8234
|
+
if (cache.size > ORIGIN_CACHE_MAX_ENTRIES) evict(row !== null);
|
|
8235
|
+
return row;
|
|
8049
8236
|
});
|
|
8050
|
-
inFlight.set(
|
|
8237
|
+
inFlight.set(scopeKey, next);
|
|
8051
8238
|
try {
|
|
8052
8239
|
return await next;
|
|
8053
8240
|
} finally {
|
|
8054
|
-
inFlight.delete(
|
|
8055
|
-
}
|
|
8241
|
+
inFlight.delete(scopeKey);
|
|
8242
|
+
}
|
|
8243
|
+
}, "loadRow");
|
|
8244
|
+
const loadCatalog = /* @__PURE__ */ __name(async (core, input) => {
|
|
8245
|
+
const scopeKey = releaseCatalogScopeKeyOf(input);
|
|
8246
|
+
const parsed = await loadRow(scopeKey, async () => {
|
|
8247
|
+
const row = await core.getReleaseCatalogRow(scopeKey);
|
|
8248
|
+
return row === null ? null : parseReleaseCatalogRow(row);
|
|
8249
|
+
});
|
|
8250
|
+
return projectParsedReleaseCatalogRow(parsed, input, scopeKey);
|
|
8056
8251
|
}, "loadCatalog");
|
|
8057
8252
|
return {
|
|
8058
8253
|
appVersionReleaseCatalog: /* @__PURE__ */ __name(async (params, request, { core }) => {
|
|
@@ -8067,7 +8262,7 @@ var createReleaseCatalogRouteHandlers = /* @__PURE__ */ __name(() => {
|
|
|
8067
8262
|
};
|
|
8068
8263
|
const invalid = invalidScope(input);
|
|
8069
8264
|
if (invalid) return invalid;
|
|
8070
|
-
return catalogResponse(await loadCatalog(
|
|
8265
|
+
return catalogResponse(await loadCatalog(core, input), request);
|
|
8071
8266
|
}, "appVersionReleaseCatalog"),
|
|
8072
8267
|
fingerprintReleaseCatalog: /* @__PURE__ */ __name(async (params, request, { core }) => {
|
|
8073
8268
|
const input = {
|
|
@@ -8078,7 +8273,7 @@ var createReleaseCatalogRouteHandlers = /* @__PURE__ */ __name(() => {
|
|
|
8078
8273
|
};
|
|
8079
8274
|
const invalid = invalidScope(input);
|
|
8080
8275
|
if (invalid) return invalid;
|
|
8081
|
-
return catalogResponse(await loadCatalog(
|
|
8276
|
+
return catalogResponse(await loadCatalog(core, input), request);
|
|
8082
8277
|
}, "fingerprintReleaseCatalog"),
|
|
8083
8278
|
artifactV2: /* @__PURE__ */ __name(async (params, _request, { core }) => {
|
|
8084
8279
|
const info = await core.getArtifactInfo(requireRouteParam(params, "targetBundleId"), requireRouteParam(params, "currentBundleId"), 2);
|
|
@@ -11039,6 +11234,53 @@ var breakdownOf = /* @__PURE__ */ __name((rows) => {
|
|
|
11039
11234
|
};
|
|
11040
11235
|
});
|
|
11041
11236
|
}, "breakdownOf");
|
|
11237
|
+
var FAILURE_ROWS_PER_HOUR = 20;
|
|
11238
|
+
var FAILURE_QUERY_LIMIT = Math.min(PAGE4, 168);
|
|
11239
|
+
var failureRowsByHour = /* @__PURE__ */ __name(async (db, platform, channel, timeRange) => {
|
|
11240
|
+
const read = /* @__PURE__ */ __name((end2, cursor2) => db.findAggregates("insights_failures", {
|
|
11241
|
+
index: "byScope",
|
|
11242
|
+
where: {
|
|
11243
|
+
platform,
|
|
11244
|
+
channel
|
|
11245
|
+
},
|
|
11246
|
+
range: {
|
|
11247
|
+
gte: timeRange.start,
|
|
11248
|
+
lt: end2
|
|
11249
|
+
},
|
|
11250
|
+
order: "desc",
|
|
11251
|
+
limit: FAILURE_QUERY_LIMIT,
|
|
11252
|
+
...cursor2 === void 0 ? {} : { cursor: cursor2 }
|
|
11253
|
+
}), "read");
|
|
11254
|
+
const rows = [];
|
|
11255
|
+
const cappedHours = [];
|
|
11256
|
+
const perHour = /* @__PURE__ */ new Map();
|
|
11257
|
+
let end = timeRange.end;
|
|
11258
|
+
let cursor;
|
|
11259
|
+
while (end > timeRange.start) {
|
|
11260
|
+
const page2 = await read(end, cursor);
|
|
11261
|
+
let capped;
|
|
11262
|
+
for (const row of page2.rows) {
|
|
11263
|
+
const hour2 = row.bucket_start_ms;
|
|
11264
|
+
const count = (perHour.get(hour2) ?? 0) + 1;
|
|
11265
|
+
if (count > FAILURE_ROWS_PER_HOUR) {
|
|
11266
|
+
capped = hour2;
|
|
11267
|
+
break;
|
|
11268
|
+
}
|
|
11269
|
+
perHour.set(hour2, count);
|
|
11270
|
+
rows.push(row);
|
|
11271
|
+
}
|
|
11272
|
+
if (capped !== void 0) {
|
|
11273
|
+
cappedHours.unshift(capped);
|
|
11274
|
+
end = capped;
|
|
11275
|
+
cursor = void 0;
|
|
11276
|
+
} else if (page2.next === void 0) break;
|
|
11277
|
+
else cursor = page2.next;
|
|
11278
|
+
}
|
|
11279
|
+
return {
|
|
11280
|
+
rows,
|
|
11281
|
+
cappedHours
|
|
11282
|
+
};
|
|
11283
|
+
}, "failureRowsByHour");
|
|
11042
11284
|
var getUpdateFailures = /* @__PURE__ */ __name(async (db, input, now, retention) => {
|
|
11043
11285
|
const { platform, channel, releaseId, timeRange } = input;
|
|
11044
11286
|
if (platform !== "ios" && platform !== "android" || !isText3(channel, 1024) || releaseId !== void 0 && !isText3(releaseId, 36) || !isRange(timeRange) || releaseId === void 0 && timeRange === void 0) throw new DatabaseAdapterInputError("invalid-query");
|
|
@@ -11099,7 +11341,7 @@ var getUpdateFailures = /* @__PURE__ */ __name(async (db, input, now, retention)
|
|
|
11099
11341
|
days,
|
|
11100
11342
|
kept.hour
|
|
11101
11343
|
];
|
|
11102
|
-
const [counters2, failures, checks, active, rows] = await Promise.all([
|
|
11344
|
+
const [counters2, failures, checks, active, { rows, cappedHours }] = await Promise.all([
|
|
11103
11345
|
counterRows(db, parts, ...window2),
|
|
11104
11346
|
sketchRows(db, failure, ...window2),
|
|
11105
11347
|
days ? sketchRows(db, {
|
|
@@ -11107,25 +11349,17 @@ var getUpdateFailures = /* @__PURE__ */ __name(async (db, input, now, retention)
|
|
|
11107
11349
|
scopeKind: "check"
|
|
11108
11350
|
}, ...window2) : [],
|
|
11109
11351
|
days ? sketchRows(db, usageParts(channel, platform), ...window2) : [],
|
|
11110
|
-
|
|
11111
|
-
index: "byScope",
|
|
11112
|
-
where: {
|
|
11113
|
-
platform,
|
|
11114
|
-
channel
|
|
11115
|
-
},
|
|
11116
|
-
range: {
|
|
11117
|
-
gte: timeRange.start,
|
|
11118
|
-
lt: timeRange.end
|
|
11119
|
-
},
|
|
11120
|
-
limit: PAGE4,
|
|
11121
|
-
...page2
|
|
11122
|
-
}))
|
|
11352
|
+
failureRowsByHour(db, platform, channel, timeRange)
|
|
11123
11353
|
]);
|
|
11124
11354
|
const total = /* @__PURE__ */ __name((field) => counters2.reduce((sum, row) => sum + row[field], 0), "total");
|
|
11125
11355
|
const scoped = rows.filter((row) => FAILURE_STAGES.has(row.stage) && (releaseId === void 0 || row.release_id === releaseId));
|
|
11126
11356
|
const failuresAt = /* @__PURE__ */ __name((counted) => scoped.reduce((sum, row) => sum + (counted(row.stage) ? Math.max(0, row.events) : 0), 0), "failuresAt");
|
|
11357
|
+
const coverage = coverageOf(timeRange.start, kept.hour);
|
|
11127
11358
|
return {
|
|
11128
|
-
coverage:
|
|
11359
|
+
coverage: cappedHours.length === 0 ? coverage : {
|
|
11360
|
+
kind: "partial",
|
|
11361
|
+
sinceMs: coverage.sinceMs
|
|
11362
|
+
},
|
|
11129
11363
|
measuredAtMs: at,
|
|
11130
11364
|
failedUpdates: failuresAt((stage) => stage !== "check"),
|
|
11131
11365
|
failedInstallations: failed(failures),
|
|
@@ -11137,7 +11371,8 @@ var getUpdateFailures = /* @__PURE__ */ __name(async (db, input, now, retention)
|
|
|
11137
11371
|
failedInstallations: failed(checks),
|
|
11138
11372
|
activeInstallations: countDistinct(mergeDistinct(active.map((row) => row.activity_users)))
|
|
11139
11373
|
} } : {},
|
|
11140
|
-
breakdown: breakdownOf(scoped)
|
|
11374
|
+
breakdown: breakdownOf(scoped),
|
|
11375
|
+
...cappedHours.length === 0 ? {} : { cappedHours }
|
|
11141
11376
|
};
|
|
11142
11377
|
}, "getUpdateFailures");
|
|
11143
11378
|
|