@hot-updater/vercel 1.2.0-rc.50 → 1.2.0-rc.51
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 +563 -46
- package/dist/init/index.cjs +1 -0
- package/dist/init/index.mjs +2 -1
- package/package.json +7 -7
package/dist/function/index.mjs
CHANGED
|
@@ -615,7 +615,8 @@ const releaseRowToRelease = (row) => ({
|
|
|
615
615
|
operation: row.operation,
|
|
616
616
|
sourceReleaseId: row.source_release_id,
|
|
617
617
|
createdAtMs: row.created_at_ms,
|
|
618
|
-
updatedAtMs: row.updated_at_ms
|
|
618
|
+
updatedAtMs: row.updated_at_ms,
|
|
619
|
+
label: row.label ?? null
|
|
619
620
|
});
|
|
620
621
|
const bundleToRow = (bundle) => {
|
|
621
622
|
const metadata = bundleMetadataToRow(bundle.metadata);
|
|
@@ -1124,7 +1125,7 @@ function rangeToIntervals(range) {
|
|
|
1124
1125
|
throw new ReleaseCatalogCompilationError("INVALID_TARGET_RANGE", `Invalid target app-version range: ${range}`);
|
|
1125
1126
|
}
|
|
1126
1127
|
}
|
|
1127
|
-
function releaseDescriptor(release) {
|
|
1128
|
+
function releaseDescriptor(release, labels) {
|
|
1128
1129
|
return {
|
|
1129
1130
|
releaseId: release.id,
|
|
1130
1131
|
kind: release.kind,
|
|
@@ -1132,7 +1133,8 @@ function releaseDescriptor(release) {
|
|
|
1132
1133
|
rolloutCohortCount: release.rolloutCohortCount,
|
|
1133
1134
|
targetCohorts: [...new Set(release.targetCohorts)].sort(),
|
|
1134
1135
|
shouldForceUpdate: release.shouldForceUpdate,
|
|
1135
|
-
message: release.message
|
|
1136
|
+
message: release.message,
|
|
1137
|
+
...labels && typeof release.label === "number" ? { label: release.label } : {}
|
|
1136
1138
|
};
|
|
1137
1139
|
}
|
|
1138
1140
|
function validateReleases(releases, strategy) {
|
|
@@ -1345,12 +1347,21 @@ async function compileReleaseCatalog(input) {
|
|
|
1345
1347
|
const targetCohorts = new Set(releases.flatMap((release) => release.targetCohorts));
|
|
1346
1348
|
if (targetCohorts.size > 512) throw new ReleaseCatalogCompilationError("DISTINCT_TARGET_COHORT_LIMIT", `Scope exceeds 512 distinct target cohorts`);
|
|
1347
1349
|
const { envelope, retainedReleases } = input.strategy === "APP_VERSION" ? compileAppVersion(releases) : compileFingerprint(releases);
|
|
1348
|
-
const
|
|
1349
|
-
|
|
1350
|
-
|
|
1350
|
+
const compile = (labels) => {
|
|
1351
|
+
const payload = {
|
|
1352
|
+
...envelope,
|
|
1353
|
+
releaseDescriptors: retainedReleases.map((release) => releaseDescriptor(release, labels))
|
|
1354
|
+
};
|
|
1355
|
+
const canonicalPayload = canonicalStringify(payload);
|
|
1356
|
+
return {
|
|
1357
|
+
payload,
|
|
1358
|
+
canonicalPayload,
|
|
1359
|
+
byteSize: new TextEncoder().encode(canonicalPayload).byteLength
|
|
1360
|
+
};
|
|
1351
1361
|
};
|
|
1352
|
-
|
|
1353
|
-
|
|
1362
|
+
let compiled = compile(true);
|
|
1363
|
+
if (compiled.byteSize > 262144 && retainedReleases.some((release) => typeof release.label === "number")) compiled = compile(false);
|
|
1364
|
+
const { payload, canonicalPayload, byteSize } = compiled;
|
|
1354
1365
|
if (byteSize > 262144) throw new ReleaseCatalogCompilationError("CATALOG_OVERSIZE", `Compiled Release catalog is ${byteSize} bytes; maximum is ${MAX_COMPILED_CATALOG_BYTES}`);
|
|
1355
1366
|
return {
|
|
1356
1367
|
byteSize,
|
|
@@ -2274,7 +2285,11 @@ const releases = defineTable({
|
|
|
2274
2285
|
}
|
|
2275
2286
|
},
|
|
2276
2287
|
created_at_ms: { type: "integer" },
|
|
2277
|
-
updated_at_ms: { type: "integer" }
|
|
2288
|
+
updated_at_ms: { type: "integer" },
|
|
2289
|
+
label: {
|
|
2290
|
+
type: "integer",
|
|
2291
|
+
required: false
|
|
2292
|
+
}
|
|
2278
2293
|
}, {
|
|
2279
2294
|
key: ["id"],
|
|
2280
2295
|
indexes: {
|
|
@@ -2311,6 +2326,15 @@ const releases = defineTable({
|
|
|
2311
2326
|
scopes: {
|
|
2312
2327
|
eq: [],
|
|
2313
2328
|
sort: ["scope_key"]
|
|
2329
|
+
},
|
|
2330
|
+
byLabel: {
|
|
2331
|
+
eq: [
|
|
2332
|
+
"channel_id",
|
|
2333
|
+
"platform",
|
|
2334
|
+
"label"
|
|
2335
|
+
],
|
|
2336
|
+
sort: [],
|
|
2337
|
+
unique: true
|
|
2314
2338
|
}
|
|
2315
2339
|
}
|
|
2316
2340
|
});
|
|
@@ -2318,6 +2342,25 @@ const LATE_INDEXES = [{
|
|
|
2318
2342
|
table: "releases",
|
|
2319
2343
|
index: "scopes"
|
|
2320
2344
|
}];
|
|
2345
|
+
const LATE_COLUMNS = [{
|
|
2346
|
+
table: "releases",
|
|
2347
|
+
column: "label"
|
|
2348
|
+
}];
|
|
2349
|
+
const labelSequences = defineTable({
|
|
2350
|
+
id: {
|
|
2351
|
+
type: "string",
|
|
2352
|
+
maxLength: 1440,
|
|
2353
|
+
ascii: true
|
|
2354
|
+
},
|
|
2355
|
+
last_label: { type: "integer" },
|
|
2356
|
+
is_filled: { type: "boolean" }
|
|
2357
|
+
}, {
|
|
2358
|
+
key: ["id"],
|
|
2359
|
+
indexes: { all: {
|
|
2360
|
+
eq: [],
|
|
2361
|
+
sort: ["id"]
|
|
2362
|
+
} }
|
|
2363
|
+
});
|
|
2321
2364
|
const releaseCatalogs = defineTable({
|
|
2322
2365
|
scope_key: {
|
|
2323
2366
|
type: "string",
|
|
@@ -2624,7 +2667,8 @@ const coreModule = {
|
|
|
2624
2667
|
}),
|
|
2625
2668
|
native_builds: nativeBuilds,
|
|
2626
2669
|
ios_devices: iosDevices,
|
|
2627
|
-
ios_device_account: iosDeviceAccount
|
|
2670
|
+
ios_device_account: iosDeviceAccount,
|
|
2671
|
+
label_sequences: labelSequences
|
|
2628
2672
|
}
|
|
2629
2673
|
};
|
|
2630
2674
|
//#endregion
|
|
@@ -2635,6 +2679,58 @@ const getEmptyMigrationResult = () => ({
|
|
|
2635
2679
|
getSQL: () => ""
|
|
2636
2680
|
});
|
|
2637
2681
|
//#endregion
|
|
2682
|
+
//#region ../plugin-core/dist/engine/db/sqlSchemaState.mjs
|
|
2683
|
+
const POSTGRES_NAME_BYTES = 63;
|
|
2684
|
+
const postgresName = (name) => {
|
|
2685
|
+
const encoder = new TextEncoder();
|
|
2686
|
+
let bytes = 0;
|
|
2687
|
+
let cut = "";
|
|
2688
|
+
for (const character of name) {
|
|
2689
|
+
bytes += encoder.encode(character).length;
|
|
2690
|
+
if (bytes > POSTGRES_NAME_BYTES) break;
|
|
2691
|
+
cut += character;
|
|
2692
|
+
}
|
|
2693
|
+
return cut;
|
|
2694
|
+
};
|
|
2695
|
+
const fold = (dialect, name) => dialect === "mysql" ? String(name).toLowerCase() : dialect === "postgresql" ? postgresName(String(name)) : String(name);
|
|
2696
|
+
const CATALOG = {
|
|
2697
|
+
postgresql: {
|
|
2698
|
+
tables: "SELECT c.relname AS t FROM pg_class c WHERE c.relkind IN ('r', 'p') AND pg_table_is_visible(c.oid)",
|
|
2699
|
+
indexes: "SELECT t.relname AS t, c.relname AS i FROM pg_index x JOIN pg_class c ON c.oid = x.indexrelid JOIN pg_class t ON t.oid = x.indrelid WHERE pg_table_is_visible(t.oid)",
|
|
2700
|
+
columns: "SELECT c.relname AS t, a.attname AS c FROM pg_attribute a JOIN pg_class c ON c.oid = a.attrelid WHERE c.relkind IN ('r', 'p') AND a.attnum > 0 AND NOT a.attisdropped AND pg_table_is_visible(c.oid)"
|
|
2701
|
+
},
|
|
2702
|
+
mysql: {
|
|
2703
|
+
tables: "SELECT TABLE_NAME AS t FROM information_schema.tables WHERE TABLE_SCHEMA = DATABASE()",
|
|
2704
|
+
indexes: "SELECT DISTINCT TABLE_NAME AS t, INDEX_NAME AS i FROM information_schema.statistics WHERE TABLE_SCHEMA = DATABASE()",
|
|
2705
|
+
columns: "SELECT TABLE_NAME AS t, COLUMN_NAME AS c FROM information_schema.columns WHERE TABLE_SCHEMA = DATABASE()"
|
|
2706
|
+
},
|
|
2707
|
+
sqlite: {
|
|
2708
|
+
tables: "SELECT name AS t FROM sqlite_master WHERE type = 'table'",
|
|
2709
|
+
indexes: "SELECT tbl_name AS t, name AS i FROM sqlite_master WHERE type = 'index'",
|
|
2710
|
+
columns: "SELECT m.name AS t, p.name AS c FROM sqlite_master m JOIN pragma_table_info(m.name) p WHERE m.type = 'table'"
|
|
2711
|
+
}
|
|
2712
|
+
};
|
|
2713
|
+
const readSqlSchemaState = async (executor) => {
|
|
2714
|
+
const { dialect } = executor;
|
|
2715
|
+
const read = (sql) => executor.execute({
|
|
2716
|
+
sql,
|
|
2717
|
+
params: []
|
|
2718
|
+
});
|
|
2719
|
+
const [tables, indexes, columns] = await Promise.all([
|
|
2720
|
+
read(CATALOG[dialect].tables),
|
|
2721
|
+
read(CATALOG[dialect].indexes),
|
|
2722
|
+
read(CATALOG[dialect].columns)
|
|
2723
|
+
]);
|
|
2724
|
+
const columnNames = new Set(columns.rows.map(({ t, c }) => JSON.stringify([fold(dialect, t), fold(dialect, c)])));
|
|
2725
|
+
const tableNames = new Set(tables.rows.map(({ t }) => fold(dialect, t)));
|
|
2726
|
+
const indexNames = new Set(indexes.rows.map(({ t, i }) => JSON.stringify([fold(dialect, t), fold(dialect, i)])));
|
|
2727
|
+
return {
|
|
2728
|
+
hasTable: (table) => tableNames.has(fold(dialect, table)),
|
|
2729
|
+
hasIndex: (table, index) => indexNames.has(JSON.stringify([fold(dialect, table), fold(dialect, index)])),
|
|
2730
|
+
hasColumn: (table, column) => columnNames.has(JSON.stringify([fold(dialect, table), fold(dialect, column)]))
|
|
2731
|
+
};
|
|
2732
|
+
};
|
|
2733
|
+
//#endregion
|
|
2638
2734
|
//#region ../plugin-core/dist/engine/db/settingsMigrator.mjs
|
|
2639
2735
|
const storedSchemaVersion = (stored) => {
|
|
2640
2736
|
const version = stored?.get("schema.core") ?? stored?.get("version");
|
|
@@ -2721,10 +2817,23 @@ const fillLateIndexes = async (adapter, tables, { dryRun = false } = {}) => {
|
|
|
2721
2817
|
}
|
|
2722
2818
|
return lacking;
|
|
2723
2819
|
};
|
|
2820
|
+
const addLateColumns = async (adapter, tables, { dryRun = false } = {}) => {
|
|
2821
|
+
const addColumns = adapter.migrations?.addColumns;
|
|
2822
|
+
if (addColumns === void 0) return [];
|
|
2823
|
+
const lacking = [];
|
|
2824
|
+
for (const table of tables) {
|
|
2825
|
+
const columns = LATE_COLUMNS.filter(({ table: name }) => name === table.name).map(({ column }) => column);
|
|
2826
|
+
if (columns.length === 0) continue;
|
|
2827
|
+
const added = await addColumns(table, columns, { dryRun });
|
|
2828
|
+
lacking.push(...added.map((column) => `${table.name}.${column}`));
|
|
2829
|
+
}
|
|
2830
|
+
return lacking;
|
|
2831
|
+
};
|
|
2724
2832
|
const migrateSchema = async (adapter, adapterName, tables, settings, ordered) => {
|
|
2725
2833
|
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2726
2834
|
const stored = await storedSettings(adapter, Object.keys(settings)).catch(() => void 0);
|
|
2727
2835
|
if (stored !== void 0) refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2836
|
+
await addLateColumns(adapter, tables);
|
|
2728
2837
|
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2729
2838
|
await fillLateIndexes(adapter, tables);
|
|
2730
2839
|
await writeSchemaSettings(adapter, adapterName, settings, ordered);
|
|
@@ -3616,23 +3725,45 @@ const createEngineMigrator = (options) => {
|
|
|
3616
3725
|
refuseNewerSchema(options.adapterName, stored, options.settings, options.ordered);
|
|
3617
3726
|
const changed = Object.entries(options.settings).filter(([key, value]) => stored.get(key) !== value);
|
|
3618
3727
|
if (changed.length === 0) {
|
|
3728
|
+
const columns = await addLateColumns(options.adapter, options.schema.tables, { dryRun: true });
|
|
3619
3729
|
const lacking = await fillLateIndexes(options.adapter, options.schema.tables, { dryRun: true });
|
|
3620
|
-
if (lacking.length === 0) return getEmptyMigrationResult();
|
|
3730
|
+
if (columns.length === 0 && lacking.length === 0) return getEmptyMigrationResult();
|
|
3621
3731
|
return {
|
|
3622
|
-
operations: [
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3732
|
+
operations: [
|
|
3733
|
+
...columns.map((column) => ({
|
|
3734
|
+
type: "custom",
|
|
3735
|
+
description: `Add column: ${column}`
|
|
3736
|
+
})),
|
|
3737
|
+
...columns.length === 0 ? [] : [{
|
|
3738
|
+
type: "custom",
|
|
3739
|
+
description: "Create the tables and indexes the database lacks"
|
|
3740
|
+
}],
|
|
3741
|
+
...lacking.length === 0 ? [] : [{
|
|
3742
|
+
type: "custom",
|
|
3743
|
+
description: `Write the index items rows lack: ${lacking.join(", ")}`
|
|
3744
|
+
}]
|
|
3745
|
+
],
|
|
3626
3746
|
execute: async () => {
|
|
3747
|
+
if (columns.length > 0) {
|
|
3748
|
+
await addLateColumns(options.adapter, options.schema.tables);
|
|
3749
|
+
await options.adapter.migrations.apply([...options.schema.tables, SETTINGS_TABLE]);
|
|
3750
|
+
}
|
|
3627
3751
|
await fillLateIndexes(options.adapter, options.schema.tables);
|
|
3628
3752
|
}
|
|
3629
3753
|
};
|
|
3630
3754
|
}
|
|
3631
3755
|
return {
|
|
3632
|
-
operations: [
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3756
|
+
operations: [
|
|
3757
|
+
...(await addLateColumns(options.adapter, options.schema.tables, { dryRun: true }).catch(() => [])).map((column) => ({
|
|
3758
|
+
type: "custom",
|
|
3759
|
+
description: `Add column: ${column}`
|
|
3760
|
+
})),
|
|
3761
|
+
{
|
|
3762
|
+
type: "custom",
|
|
3763
|
+
description: "Create the tables and indexes the database lacks"
|
|
3764
|
+
},
|
|
3765
|
+
...migrate.updateSettings === false ? [] : [settingsOperation(stored, changed)]
|
|
3766
|
+
],
|
|
3636
3767
|
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings, options.ordered)
|
|
3637
3768
|
};
|
|
3638
3769
|
};
|
|
@@ -4635,14 +4766,32 @@ const createSqlAdapter = ({ executor, tablePrefix = "", maxOps = 1e3, maxParams
|
|
|
4635
4766
|
return done;
|
|
4636
4767
|
})).at(-1)?.changes ?? 0;
|
|
4637
4768
|
},
|
|
4638
|
-
migrations: {
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4769
|
+
migrations: {
|
|
4770
|
+
async apply(tables) {
|
|
4771
|
+
const created = executor.batch && !tables.includes(WRITE_GUARD_TABLE) ? [...tables, WRITE_GUARD_TABLE] : tables;
|
|
4772
|
+
const statements = createTableStatements(dialect, created, tablePrefix);
|
|
4773
|
+
for (const text of statements) await executor.execute({
|
|
4774
|
+
sql: text,
|
|
4775
|
+
params: []
|
|
4776
|
+
});
|
|
4777
|
+
},
|
|
4778
|
+
async addColumns(table, columns, { dryRun = false } = {}) {
|
|
4779
|
+
const [shape] = sqlTableShapes(dialect, [table], tablePrefix);
|
|
4780
|
+
const state = await readSqlSchemaState(executor);
|
|
4781
|
+
if (shape === void 0 || !state.hasTable(shape.name)) return [];
|
|
4782
|
+
const missing = columns.filter((column) => !state.hasColumn(shape.name, column));
|
|
4783
|
+
if (dryRun) return missing;
|
|
4784
|
+
for (const name of missing) {
|
|
4785
|
+
const column = shape.columns.find((candidate) => candidate.name === name);
|
|
4786
|
+
if (column === void 0 || column.notNull) throw new Error(`${table.name}.${name} can't be added to an existing table: only an optional column can.`);
|
|
4787
|
+
await executor.execute({
|
|
4788
|
+
sql: `ALTER TABLE ${quoteSql(dialect, shape.name)} ADD COLUMN ${quoteSql(dialect, name)} ${column.type}`,
|
|
4789
|
+
params: []
|
|
4790
|
+
});
|
|
4791
|
+
}
|
|
4792
|
+
return missing;
|
|
4793
|
+
}
|
|
4794
|
+
}
|
|
4646
4795
|
};
|
|
4647
4796
|
};
|
|
4648
4797
|
//#endregion
|
|
@@ -17873,7 +18022,7 @@ const postgres = (config) => {
|
|
|
17873
18022
|
};
|
|
17874
18023
|
//#endregion
|
|
17875
18024
|
//#region ../../packages/server/dist/version.mjs
|
|
17876
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
18025
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.51";
|
|
17877
18026
|
//#endregion
|
|
17878
18027
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
17879
18028
|
const createVersionRouteHandlers = (plugins = []) => {
|
|
@@ -18611,7 +18760,7 @@ const baseBundleIdsOf = (row, range, bundleId, limit) => {
|
|
|
18611
18760
|
};
|
|
18612
18761
|
//#endregion
|
|
18613
18762
|
//#region ../../packages/server/dist/core/reads.mjs
|
|
18614
|
-
const PAGE$
|
|
18763
|
+
const PAGE$4 = 500;
|
|
18615
18764
|
const pick$2 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
|
|
18616
18765
|
const toBundleRow = pick$2([
|
|
18617
18766
|
"id",
|
|
@@ -18632,7 +18781,7 @@ const toPatchRow = pick$2([
|
|
|
18632
18781
|
"byte_size",
|
|
18633
18782
|
"order_index"
|
|
18634
18783
|
]);
|
|
18635
|
-
const
|
|
18784
|
+
const pickReleaseRow = pick$2([
|
|
18636
18785
|
"id",
|
|
18637
18786
|
"revision",
|
|
18638
18787
|
"scope_key",
|
|
@@ -18653,6 +18802,12 @@ const toReleaseRow = pick$2([
|
|
|
18653
18802
|
"created_at_ms",
|
|
18654
18803
|
"updated_at_ms"
|
|
18655
18804
|
]);
|
|
18805
|
+
const toReleaseRow = (row) => {
|
|
18806
|
+
return {
|
|
18807
|
+
...pickReleaseRow(row),
|
|
18808
|
+
label: typeof row.label === "number" ? row.label : null
|
|
18809
|
+
};
|
|
18810
|
+
};
|
|
18656
18811
|
const toCatalogRow = pick$2([
|
|
18657
18812
|
"scope_key",
|
|
18658
18813
|
"catalog_id",
|
|
@@ -18696,7 +18851,7 @@ const createCoreReads = (db, storage) => {
|
|
|
18696
18851
|
const page = await db.findMany("bundle_patches", {
|
|
18697
18852
|
index: "byBundle",
|
|
18698
18853
|
where: { bundle_id: row.id },
|
|
18699
|
-
limit: Math.min(count - patches.length, PAGE$
|
|
18854
|
+
limit: Math.min(count - patches.length, PAGE$4),
|
|
18700
18855
|
...cursor === void 0 ? {} : { cursor }
|
|
18701
18856
|
});
|
|
18702
18857
|
patches.push(...page.rows.map(toPatchRow));
|
|
@@ -18797,6 +18952,18 @@ const createCoreReads = (db, storage) => {
|
|
|
18797
18952
|
const row = await db.findOne("releases", { id });
|
|
18798
18953
|
return row === null ? null : toReleaseRow(row);
|
|
18799
18954
|
},
|
|
18955
|
+
async getReleaseByLabel({ channel, platform, label }) {
|
|
18956
|
+
const found = await db.findOne("releases", {
|
|
18957
|
+
channel_id: `channel:${encodeChannelKey(channel)}`,
|
|
18958
|
+
platform,
|
|
18959
|
+
label
|
|
18960
|
+
});
|
|
18961
|
+
if (found === null) return null;
|
|
18962
|
+
const row = await db.findOne("releases", { id: found.id });
|
|
18963
|
+
if (row === null) return null;
|
|
18964
|
+
const release = toReleaseRow(row);
|
|
18965
|
+
return release.label === label && release.platform === platform ? release : null;
|
|
18966
|
+
},
|
|
18800
18967
|
async listReleases(input) {
|
|
18801
18968
|
const { filter } = input;
|
|
18802
18969
|
const options = {
|
|
@@ -18888,7 +19055,7 @@ const createCoreReads = (db, storage) => {
|
|
|
18888
19055
|
return (await drain$1((page) => db.findMany("channels", {
|
|
18889
19056
|
index: "all",
|
|
18890
19057
|
where: {},
|
|
18891
|
-
limit: PAGE$
|
|
19058
|
+
limit: PAGE$4,
|
|
18892
19059
|
...page
|
|
18893
19060
|
}))).map(toChannelRow);
|
|
18894
19061
|
},
|
|
@@ -19187,6 +19354,269 @@ const NATIVE_BUILD_SUBMISSION_DESTINATIONS = {
|
|
|
19187
19354
|
ios: ["testflight"]
|
|
19188
19355
|
};
|
|
19189
19356
|
//#endregion
|
|
19357
|
+
//#region ../../packages/server/dist/core/labels.mjs
|
|
19358
|
+
const labelSequenceId = (channelId, platform) => `releases/${platform}/${channelId}`;
|
|
19359
|
+
const LABEL_PLATFORMS = ["ios", "android"];
|
|
19360
|
+
var NeedsLabelFill = class extends Error {
|
|
19361
|
+
channelId;
|
|
19362
|
+
platform;
|
|
19363
|
+
constructor(channelId, platform) {
|
|
19364
|
+
super(`Release labels of ${platform} ${channelId} need a fill first.`);
|
|
19365
|
+
this.channelId = channelId;
|
|
19366
|
+
this.platform = platform;
|
|
19367
|
+
}
|
|
19368
|
+
};
|
|
19369
|
+
const createLabelAllocator = (tx, used, caughtUp) => {
|
|
19370
|
+
const sequences = /* @__PURE__ */ new Map();
|
|
19371
|
+
return {
|
|
19372
|
+
async next(channelId, platform) {
|
|
19373
|
+
const id = labelSequenceId(channelId, platform);
|
|
19374
|
+
let sequence = sequences.get(id);
|
|
19375
|
+
if (sequence === void 0) {
|
|
19376
|
+
const row = await tx.findOne("label_sequences", { id });
|
|
19377
|
+
if (row === null || !row.is_filled) {
|
|
19378
|
+
const channel = row === null ? await tx.findOne("channels", { id: channelId }) : null;
|
|
19379
|
+
if (channel === null || (channel._refs_releases_channel_id ?? 0) > 0) throw new NeedsLabelFill(channelId, platform);
|
|
19380
|
+
}
|
|
19381
|
+
const read = row?.last_label ?? 0;
|
|
19382
|
+
sequence = {
|
|
19383
|
+
row,
|
|
19384
|
+
read,
|
|
19385
|
+
last: read
|
|
19386
|
+
};
|
|
19387
|
+
sequences.set(id, sequence);
|
|
19388
|
+
used.set(id, {
|
|
19389
|
+
channelId,
|
|
19390
|
+
platform,
|
|
19391
|
+
read
|
|
19392
|
+
});
|
|
19393
|
+
}
|
|
19394
|
+
sequence.last += 1;
|
|
19395
|
+
return sequence.last;
|
|
19396
|
+
},
|
|
19397
|
+
caughtUp(channelId, platform) {
|
|
19398
|
+
caughtUp.set(labelSequenceId(channelId, platform), {
|
|
19399
|
+
channelId,
|
|
19400
|
+
platform
|
|
19401
|
+
});
|
|
19402
|
+
},
|
|
19403
|
+
flush() {
|
|
19404
|
+
for (const [id, { row, read, last }] of sequences) if (row === null) tx.create("label_sequences", {
|
|
19405
|
+
id,
|
|
19406
|
+
last_label: last,
|
|
19407
|
+
is_filled: true
|
|
19408
|
+
});
|
|
19409
|
+
else if (last !== read) tx.update("label_sequences", row, { last_label: last });
|
|
19410
|
+
}
|
|
19411
|
+
};
|
|
19412
|
+
};
|
|
19413
|
+
const FILL_BATCH = 25;
|
|
19414
|
+
const PAGE$3 = 500;
|
|
19415
|
+
const fillLabels = async (db, { channelId, platform }, { dryRun = false } = {}) => {
|
|
19416
|
+
const id = labelSequenceId(channelId, platform);
|
|
19417
|
+
let labeled = 0;
|
|
19418
|
+
let batchSize = FILL_BATCH;
|
|
19419
|
+
const label = async (ids) => {
|
|
19420
|
+
for (let at = 0; at < ids.length;) {
|
|
19421
|
+
const batch = ids.slice(at, at + batchSize);
|
|
19422
|
+
try {
|
|
19423
|
+
labeled += await db.transaction(async (tx) => {
|
|
19424
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
19425
|
+
let last = counter?.last_label ?? 0;
|
|
19426
|
+
let count = 0;
|
|
19427
|
+
for (const releaseId of batch) {
|
|
19428
|
+
const row = await tx.findOne("releases", { id: releaseId });
|
|
19429
|
+
if (row === null || typeof row.label === "number") continue;
|
|
19430
|
+
last += 1;
|
|
19431
|
+
count += 1;
|
|
19432
|
+
tx.update("releases", row, { label: last });
|
|
19433
|
+
}
|
|
19434
|
+
if (counter === null) tx.create("label_sequences", {
|
|
19435
|
+
id,
|
|
19436
|
+
last_label: last,
|
|
19437
|
+
is_filled: false
|
|
19438
|
+
});
|
|
19439
|
+
else if (last !== counter.last_label) tx.update("label_sequences", counter, { last_label: last });
|
|
19440
|
+
return count;
|
|
19441
|
+
});
|
|
19442
|
+
at += batch.length;
|
|
19443
|
+
} catch (error) {
|
|
19444
|
+
if (batchSize > 1 && error instanceof DatabaseConstraintError && error.reason === "too_large") {
|
|
19445
|
+
batchSize = Math.max(1, Math.floor(batchSize / 2));
|
|
19446
|
+
continue;
|
|
19447
|
+
}
|
|
19448
|
+
throw error;
|
|
19449
|
+
}
|
|
19450
|
+
}
|
|
19451
|
+
};
|
|
19452
|
+
let cursor;
|
|
19453
|
+
do {
|
|
19454
|
+
const page = await db.findMany("releases", {
|
|
19455
|
+
index: "byChannelPlatform",
|
|
19456
|
+
where: {
|
|
19457
|
+
channel_id: channelId,
|
|
19458
|
+
platform
|
|
19459
|
+
},
|
|
19460
|
+
limit: PAGE$3,
|
|
19461
|
+
...cursor === void 0 ? {} : { cursor }
|
|
19462
|
+
});
|
|
19463
|
+
const unlabeled = page.rows.filter((row) => typeof row.label !== "number").map((row) => row.id);
|
|
19464
|
+
if (dryRun) labeled += unlabeled.length;
|
|
19465
|
+
else await label(unlabeled);
|
|
19466
|
+
cursor = page.next;
|
|
19467
|
+
} while (cursor !== void 0);
|
|
19468
|
+
if (dryRun) return labeled;
|
|
19469
|
+
await db.transaction(async (tx) => {
|
|
19470
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
19471
|
+
if (counter === null) tx.create("label_sequences", {
|
|
19472
|
+
id,
|
|
19473
|
+
last_label: 0,
|
|
19474
|
+
is_filled: true
|
|
19475
|
+
});
|
|
19476
|
+
else if (!counter.is_filled) tx.update("label_sequences", counter, { is_filled: true });
|
|
19477
|
+
});
|
|
19478
|
+
return labeled;
|
|
19479
|
+
};
|
|
19480
|
+
const probeLabelSchema = async (db, { channelId, platform }) => {
|
|
19481
|
+
await db.findOne("label_sequences", { id: labelSequenceId(channelId, platform) });
|
|
19482
|
+
await db.findMany("releases", {
|
|
19483
|
+
index: "byLabel",
|
|
19484
|
+
where: {
|
|
19485
|
+
channel_id: channelId,
|
|
19486
|
+
platform,
|
|
19487
|
+
label: 0
|
|
19488
|
+
},
|
|
19489
|
+
limit: 1
|
|
19490
|
+
});
|
|
19491
|
+
};
|
|
19492
|
+
const REPAIRS = 4;
|
|
19493
|
+
const RACES = 32;
|
|
19494
|
+
const writeWithLabels = async (db, write) => {
|
|
19495
|
+
const filled = /* @__PURE__ */ new Set();
|
|
19496
|
+
const fill = async (pairs) => {
|
|
19497
|
+
for (const pair of pairs) {
|
|
19498
|
+
filled.add(labelSequenceId(pair.channelId, pair.platform));
|
|
19499
|
+
await fillLabels(db, pair);
|
|
19500
|
+
}
|
|
19501
|
+
};
|
|
19502
|
+
for (let repairs = 0, races = 0;;) {
|
|
19503
|
+
const used = /* @__PURE__ */ new Map();
|
|
19504
|
+
const caughtUp = /* @__PURE__ */ new Map();
|
|
19505
|
+
try {
|
|
19506
|
+
return await db.transaction(async (tx) => {
|
|
19507
|
+
used.clear();
|
|
19508
|
+
caughtUp.clear();
|
|
19509
|
+
const labels = createLabelAllocator(tx, used, caughtUp);
|
|
19510
|
+
const result = await write(tx, labels);
|
|
19511
|
+
labels.flush();
|
|
19512
|
+
return result;
|
|
19513
|
+
});
|
|
19514
|
+
} catch (error) {
|
|
19515
|
+
const needs = error instanceof NeedsLabelFill ? [error] : error instanceof DatabaseConstraintError && error.reason === "too_large" ? [...caughtUp.values()] : [];
|
|
19516
|
+
if (needs.length > 0) {
|
|
19517
|
+
const fresh = needs.some(({ channelId, platform }) => !filled.has(labelSequenceId(channelId, platform)));
|
|
19518
|
+
if (fresh || repairs < REPAIRS) {
|
|
19519
|
+
if (!fresh) repairs += 1;
|
|
19520
|
+
await fill(needs);
|
|
19521
|
+
continue;
|
|
19522
|
+
}
|
|
19523
|
+
}
|
|
19524
|
+
if (error instanceof DatabaseConstraintError && error.reason === "unique" && error.model === "releases" && used.size > 0) {
|
|
19525
|
+
if (await db.transaction(async (tx) => {
|
|
19526
|
+
const moves = [];
|
|
19527
|
+
for (const [id, { channelId, read }] of used) {
|
|
19528
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
19529
|
+
if (counter !== null) {
|
|
19530
|
+
if (counter.last_label !== read) return false;
|
|
19531
|
+
moves.push(() => tx.update("label_sequences", counter, { last_label: read + 1 }));
|
|
19532
|
+
continue;
|
|
19533
|
+
}
|
|
19534
|
+
const channel = await tx.findOne("channels", { id: channelId });
|
|
19535
|
+
if (channel === null || (channel._refs_releases_channel_id ?? 0) > 0) return false;
|
|
19536
|
+
moves.push(() => tx.create("label_sequences", {
|
|
19537
|
+
id,
|
|
19538
|
+
last_label: read + 1,
|
|
19539
|
+
is_filled: true
|
|
19540
|
+
}));
|
|
19541
|
+
}
|
|
19542
|
+
for (const move of moves) move();
|
|
19543
|
+
return true;
|
|
19544
|
+
}) ? (repairs += 1) <= REPAIRS : (races += 1) <= RACES) continue;
|
|
19545
|
+
}
|
|
19546
|
+
throw error;
|
|
19547
|
+
}
|
|
19548
|
+
}
|
|
19549
|
+
};
|
|
19550
|
+
const catchUpLabels = async (tx, labels, latest) => {
|
|
19551
|
+
const given = /* @__PURE__ */ new Map();
|
|
19552
|
+
if (latest === null || typeof latest.label === "number") return given;
|
|
19553
|
+
const unlabeled = [];
|
|
19554
|
+
let cursor;
|
|
19555
|
+
scan: do {
|
|
19556
|
+
const page = await tx.findMany("releases", {
|
|
19557
|
+
index: "byScope",
|
|
19558
|
+
where: { scope_key: latest.scope_key },
|
|
19559
|
+
order: "desc",
|
|
19560
|
+
limit: FILL_BATCH,
|
|
19561
|
+
...cursor === void 0 ? {} : { cursor }
|
|
19562
|
+
});
|
|
19563
|
+
for (const row of page.rows) {
|
|
19564
|
+
if (typeof row.label === "number") break scan;
|
|
19565
|
+
unlabeled.push(row);
|
|
19566
|
+
}
|
|
19567
|
+
cursor = page.next;
|
|
19568
|
+
} while (cursor !== void 0);
|
|
19569
|
+
labels.caughtUp(latest.channel_id, latest.platform);
|
|
19570
|
+
for (const row of unlabeled.reverse()) {
|
|
19571
|
+
const { id, channel_id, platform } = toReleaseRow(row);
|
|
19572
|
+
const label = await labels.next(channel_id, platform);
|
|
19573
|
+
tx.update("releases", row, { label });
|
|
19574
|
+
given.set(id, label);
|
|
19575
|
+
}
|
|
19576
|
+
return given;
|
|
19577
|
+
};
|
|
19578
|
+
const pendingLabelPairs = async (db) => {
|
|
19579
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
19580
|
+
for (let last = "";;) {
|
|
19581
|
+
const { rows } = await db.findMany("releases", {
|
|
19582
|
+
index: "scopes",
|
|
19583
|
+
where: {},
|
|
19584
|
+
limit: 1,
|
|
19585
|
+
range: { gt: last }
|
|
19586
|
+
});
|
|
19587
|
+
if (rows[0] === void 0) break;
|
|
19588
|
+
last = rows[0].scope_key;
|
|
19589
|
+
const { rows: newest } = await db.findMany("releases", {
|
|
19590
|
+
index: "byScope",
|
|
19591
|
+
where: { scope_key: last },
|
|
19592
|
+
order: "desc",
|
|
19593
|
+
limit: 1
|
|
19594
|
+
});
|
|
19595
|
+
if (newest[0] === void 0) continue;
|
|
19596
|
+
const { channel_id: channelId, platform, label } = toReleaseRow(newest[0]);
|
|
19597
|
+
const id = labelSequenceId(channelId, platform);
|
|
19598
|
+
const pair = pairs.get(id) ?? {
|
|
19599
|
+
channelId,
|
|
19600
|
+
platform,
|
|
19601
|
+
pending: false
|
|
19602
|
+
};
|
|
19603
|
+
pair.pending ||= label === null;
|
|
19604
|
+
pairs.set(id, pair);
|
|
19605
|
+
}
|
|
19606
|
+
const pending = [];
|
|
19607
|
+
for (const [id, { channelId, platform, pending: unlabeled }] of pairs) {
|
|
19608
|
+
if (!unlabeled) {
|
|
19609
|
+
const counter = await db.findOne("label_sequences", { id });
|
|
19610
|
+
if (counter !== null && counter.is_filled) continue;
|
|
19611
|
+
}
|
|
19612
|
+
pending.push({
|
|
19613
|
+
channelId,
|
|
19614
|
+
platform
|
|
19615
|
+
});
|
|
19616
|
+
}
|
|
19617
|
+
return pending;
|
|
19618
|
+
};
|
|
19619
|
+
//#endregion
|
|
19190
19620
|
//#region ../../packages/server/dist/core/writes.mjs
|
|
19191
19621
|
const PAGE$2 = 500;
|
|
19192
19622
|
const countBundle = (tx, platform, delta) => {
|
|
@@ -19273,6 +19703,10 @@ const deleteChannel = (db, id) => db.transaction(async (tx) => {
|
|
|
19273
19703
|
deleted: false,
|
|
19274
19704
|
reason: "not_empty"
|
|
19275
19705
|
};
|
|
19706
|
+
for (const platform of LABEL_PLATFORMS) {
|
|
19707
|
+
const counter = await tx.findOne("label_sequences", { id: labelSequenceId(id, platform) });
|
|
19708
|
+
if (counter !== null) await tx.delete("label_sequences", counter);
|
|
19709
|
+
}
|
|
19276
19710
|
await tx.delete("channels", row);
|
|
19277
19711
|
return { deleted: true };
|
|
19278
19712
|
});
|
|
@@ -19732,14 +20166,14 @@ const enabledIn = (scopeKey, cursor) => ({
|
|
|
19732
20166
|
...cursor === void 0 ? {} : { cursor }
|
|
19733
20167
|
});
|
|
19734
20168
|
const enabledReleases = (tx, scopeKey) => drainReleases((cursor) => tx.findMany("releases", enabledIn(scopeKey, cursor)));
|
|
19735
|
-
const
|
|
20169
|
+
const latestRelease = async (tx, scopeKey) => {
|
|
19736
20170
|
const { rows } = await tx.findMany("releases", {
|
|
19737
20171
|
index: "byScope",
|
|
19738
20172
|
where: { scope_key: scopeKey },
|
|
19739
20173
|
order: "desc",
|
|
19740
20174
|
limit: 1
|
|
19741
20175
|
});
|
|
19742
|
-
return rows[0]
|
|
20176
|
+
return rows[0] === void 0 ? null : toReleaseRow(rows[0]);
|
|
19743
20177
|
};
|
|
19744
20178
|
const nextCatalog = (scope, stored, compilation, updatedAtMs) => {
|
|
19745
20179
|
const generation = (stored.catalog?.generation ?? 0) + 1;
|
|
@@ -19793,10 +20227,10 @@ const readCatalog = async (tx, scopeKey) => {
|
|
|
19793
20227
|
const assertHistory = (stored, hasReleases) => {
|
|
19794
20228
|
if (stored.catalog === null && hasReleases) fail$1("CATALOG_IDENTITY_MISSING", "Catalog history is missing. Restore its catalog row from backup before rebuilding or deploying.");
|
|
19795
20229
|
};
|
|
19796
|
-
const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
20230
|
+
const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }, labels) => {
|
|
19797
20231
|
checkScope(scope);
|
|
19798
20232
|
const stored = await readCatalog(tx, scope.scopeKey);
|
|
19799
|
-
|
|
20233
|
+
let enabled = await enabledReleases(tx, scope.scopeKey);
|
|
19800
20234
|
if (bundle !== void 0) {
|
|
19801
20235
|
insertBundle(tx, bundle.row);
|
|
19802
20236
|
for (const patch of bundle.patches) tx.create("bundle_patches", patch);
|
|
@@ -19804,14 +20238,22 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
19804
20238
|
let before = null;
|
|
19805
20239
|
let release;
|
|
19806
20240
|
if (change.operation === "insert") {
|
|
19807
|
-
|
|
20241
|
+
if (labels === void 0) throw new Error("A release insert takes its label from an allocator.");
|
|
20242
|
+
const newest = await latestRelease(tx, scope.scopeKey);
|
|
20243
|
+
const latest = newest?.id ?? null;
|
|
19808
20244
|
assertHistory(stored, latest !== null);
|
|
19809
20245
|
const floor = [latest, bundle && isUUIDv7(bundle.row.id) ? bundle.row.id : null].filter((id) => id !== null).sort().at(-1);
|
|
19810
20246
|
const id = change.row.id ?? createUUIDv7After(floor ?? null);
|
|
19811
20247
|
if (latest !== null && id <= latest) fail$1("NON_MONOTONIC_RELEASE_ID", `Release "${id}" must sort after "${latest}"`);
|
|
20248
|
+
const given = await catchUpLabels(tx, labels, newest);
|
|
20249
|
+
if (given.size > 0) enabled = enabled.map((row) => given.has(row.id) ? {
|
|
20250
|
+
...row,
|
|
20251
|
+
label: given.get(row.id)
|
|
20252
|
+
} : row);
|
|
19812
20253
|
release = {
|
|
19813
20254
|
...change.row,
|
|
19814
|
-
id
|
|
20255
|
+
id,
|
|
20256
|
+
label: await labels.next(scope.channelId, scope.platform)
|
|
19815
20257
|
};
|
|
19816
20258
|
if (release.scope_key !== scope.scopeKey || release.channel_id !== scope.channelId || release.platform !== scope.platform || release.strategy !== scope.strategy || release.fingerprint_hash !== scope.fingerprintHash || release.revision !== 1) fail$1("INVALID_SCOPE", "Inserted Release does not match its catalog scope");
|
|
19817
20259
|
tx.create("releases", release);
|
|
@@ -19824,8 +20266,9 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
19824
20266
|
await tx.delete("releases", row);
|
|
19825
20267
|
release = null;
|
|
19826
20268
|
} else {
|
|
20269
|
+
const { label: _label, ...update } = change.update;
|
|
19827
20270
|
const set = {
|
|
19828
|
-
...
|
|
20271
|
+
...update,
|
|
19829
20272
|
revision: before.revision + 1
|
|
19830
20273
|
};
|
|
19831
20274
|
tx.update("releases", row, set);
|
|
@@ -19846,13 +20289,21 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
19846
20289
|
};
|
|
19847
20290
|
const changeReleases = (db, inputs) => {
|
|
19848
20291
|
if (new Set(inputs.map(({ scope }) => scope.scopeKey)).size !== inputs.length) fail$1("INVALID_SCOPE", "A batch cannot change one catalog scope twice");
|
|
19849
|
-
return db
|
|
20292
|
+
return writeWithLabels(db, async (tx, labels) => {
|
|
19850
20293
|
const results = [];
|
|
19851
|
-
for (const input of inputs) results.push(await changeRelease(tx, input));
|
|
20294
|
+
for (const input of inputs) results.push(await changeRelease(tx, input, labels));
|
|
19852
20295
|
return results;
|
|
19853
20296
|
});
|
|
19854
20297
|
};
|
|
19855
20298
|
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;
|
|
20299
|
+
const withoutLabels = (payload) => {
|
|
20300
|
+
const parsed = JSON.parse(payload);
|
|
20301
|
+
return JSON.stringify({
|
|
20302
|
+
...parsed,
|
|
20303
|
+
releaseDescriptors: (parsed.releaseDescriptors ?? []).map(({ label: _label, ...descriptor }) => descriptor)
|
|
20304
|
+
});
|
|
20305
|
+
};
|
|
20306
|
+
const differsInLabelsOnly = (current, projected) => current.payload !== projected.payload && current.strategy === projected.strategy && current.channel_id === projected.channel_id && current.channel_key === projected.channel_key && current.platform === projected.platform && current.fingerprint_hash === projected.fingerprint_hash && withoutLabels(current.payload) === withoutLabels(projected.payload);
|
|
19856
20307
|
const catalogRowScope = (row) => ({
|
|
19857
20308
|
channelId: row.channel_id,
|
|
19858
20309
|
channelName: decodeChannelKey(row.channel_key),
|
|
@@ -19870,17 +20321,19 @@ const preflightRebuild = async (db, scopeKey, updatedAtMs) => {
|
|
|
19870
20321
|
const enabled = await drainReleases((cursor) => db.findMany("releases", enabledIn(scopeKey, cursor)));
|
|
19871
20322
|
const compilation = await compileScope(scope, enabled);
|
|
19872
20323
|
const changed = !isCurrent(scope, current, compilation);
|
|
20324
|
+
const projectedCatalog = changed ? nextCatalog(scope, { catalog: current }, compilation, updatedAtMs) : current;
|
|
19873
20325
|
return {
|
|
19874
20326
|
changed,
|
|
20327
|
+
labelsOnly: changed && differsInLabelsOnly(current, projectedCatalog),
|
|
19875
20328
|
currentCatalog: current,
|
|
19876
20329
|
diagnostics: compilation.diagnostics,
|
|
19877
|
-
projectedCatalog
|
|
20330
|
+
projectedCatalog
|
|
19878
20331
|
};
|
|
19879
20332
|
};
|
|
19880
20333
|
const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
19881
20334
|
checkScope(scope);
|
|
19882
20335
|
const stored = await readCatalog(tx, scope.scopeKey);
|
|
19883
|
-
assertHistory(stored, await
|
|
20336
|
+
assertHistory(stored, await latestRelease(tx, scope.scopeKey) !== null);
|
|
19884
20337
|
const enabled = await enabledReleases(tx, scope.scopeKey);
|
|
19885
20338
|
const compilation = await compileScope(scope, enabled);
|
|
19886
20339
|
const current = stored.catalog;
|
|
@@ -19900,6 +20353,7 @@ const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
|
19900
20353
|
};
|
|
19901
20354
|
//#endregion
|
|
19902
20355
|
//#region ../../packages/server/dist/core/operations.mjs
|
|
20356
|
+
const CATALOG_PAGE = 100;
|
|
19903
20357
|
var Preflight = class extends Error {
|
|
19904
20358
|
result;
|
|
19905
20359
|
constructor(result) {
|
|
@@ -20118,7 +20572,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
20118
20572
|
if (targetChannel.length === 0) throw new ReleaseManagementError("TARGET_RELEASE_INVALID", "Promotion requires a target channel.");
|
|
20119
20573
|
const channel = await ensureChannel(targetChannel);
|
|
20120
20574
|
const updatedAtMs = now();
|
|
20121
|
-
return db
|
|
20575
|
+
return writeWithLabels(db, async (tx, labels) => {
|
|
20122
20576
|
const { release: source, scope: sourceScope } = await loadTarget(tx, input);
|
|
20123
20577
|
checkSource(source);
|
|
20124
20578
|
const targetScope = scopeOf$1(channel, source.platform, source.fingerprint_hash);
|
|
@@ -20146,12 +20600,13 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
20146
20600
|
},
|
|
20147
20601
|
updatedAtMs
|
|
20148
20602
|
}) : null;
|
|
20603
|
+
const { label: _label, ...copied } = source;
|
|
20149
20604
|
const target = await changeRelease(tx, {
|
|
20150
20605
|
scope: targetScope,
|
|
20151
20606
|
change: {
|
|
20152
20607
|
operation: "insert",
|
|
20153
20608
|
row: {
|
|
20154
|
-
...
|
|
20609
|
+
...copied,
|
|
20155
20610
|
id: createUUIDv7After(floor ?? null, updatedAtMs),
|
|
20156
20611
|
revision: 1,
|
|
20157
20612
|
scope_key: targetScope.scopeKey,
|
|
@@ -20166,7 +20621,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
20166
20621
|
}
|
|
20167
20622
|
},
|
|
20168
20623
|
updatedAtMs
|
|
20169
|
-
});
|
|
20624
|
+
}, labels);
|
|
20170
20625
|
return {
|
|
20171
20626
|
source: moved === null ? null : mutationResult(moved),
|
|
20172
20627
|
target: mutationResult(target)
|
|
@@ -20184,6 +20639,38 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
20184
20639
|
});
|
|
20185
20640
|
},
|
|
20186
20641
|
preflightReleaseCatalogRebuild: (scopeKey) => preflightRebuild(db, scopeKey, now()),
|
|
20642
|
+
fillReleaseLabels: async ({ dryRun = false, catalogs = true } = {}) => {
|
|
20643
|
+
let releases = 0;
|
|
20644
|
+
const pairs = await pendingLabelPairs(db);
|
|
20645
|
+
if (dryRun && pairs[0] !== void 0) await probeLabelSchema(db, pairs[0]);
|
|
20646
|
+
for (const pair of pairs) releases += await fillLabels(db, pair, { dryRun });
|
|
20647
|
+
let rebuilt = 0;
|
|
20648
|
+
if (catalogs) {
|
|
20649
|
+
let cursor;
|
|
20650
|
+
do {
|
|
20651
|
+
const page = await db.findMany("release_catalogs", {
|
|
20652
|
+
index: "all",
|
|
20653
|
+
where: {},
|
|
20654
|
+
limit: CATALOG_PAGE,
|
|
20655
|
+
...cursor === void 0 ? {} : { cursor }
|
|
20656
|
+
});
|
|
20657
|
+
for (const row of page.rows) {
|
|
20658
|
+
if (row.is_tombstone) continue;
|
|
20659
|
+
const preflight = await preflightRebuild(db, row.scope_key, now()).catch(() => null);
|
|
20660
|
+
if (preflight === null || !preflight.labelsOnly) continue;
|
|
20661
|
+
rebuilt += 1;
|
|
20662
|
+
if (dryRun) continue;
|
|
20663
|
+
const updatedAtMs = now();
|
|
20664
|
+
await db.transaction((tx) => rebuildScope(tx, catalogRowScope(toCatalogRow(row)), updatedAtMs));
|
|
20665
|
+
}
|
|
20666
|
+
cursor = page.next;
|
|
20667
|
+
} while (cursor !== void 0);
|
|
20668
|
+
}
|
|
20669
|
+
return {
|
|
20670
|
+
releases,
|
|
20671
|
+
catalogs: rebuilt
|
|
20672
|
+
};
|
|
20673
|
+
},
|
|
20187
20674
|
ensureChannel,
|
|
20188
20675
|
deleteChannel: (id) => deleteChannel(db, id),
|
|
20189
20676
|
updateBundle: (id, update) => db.transaction(async (tx) => {
|
|
@@ -20714,6 +21201,26 @@ const createAdminRouteHandlers = () => ({
|
|
|
20714
21201
|
return row === null ? notFound() : json$2({ data: row });
|
|
20715
21202
|
}),
|
|
20716
21203
|
rebuildReleaseCatalog: onCore(async (core, _request, params) => json$2({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
|
|
21204
|
+
getReleaseByLabel: onCore(async (core, request) => {
|
|
21205
|
+
const url = new URL(request.url);
|
|
21206
|
+
const channel = url.searchParams.get("channel");
|
|
21207
|
+
const platform = platformOf(url);
|
|
21208
|
+
const label = Number(url.searchParams.get("label"));
|
|
21209
|
+
if (channel === null || channel.length === 0 || platform === void 0 || !Number.isSafeInteger(label) || label < 1) throw new HandlerBadRequestError("A release label lookup takes channel, platform, and a label of 1 or more.");
|
|
21210
|
+
return json$2({ data: await core.getReleaseByLabel({
|
|
21211
|
+
channel,
|
|
21212
|
+
platform,
|
|
21213
|
+
label
|
|
21214
|
+
}) });
|
|
21215
|
+
}),
|
|
21216
|
+
fillReleaseLabels: onCore(async (core, request) => {
|
|
21217
|
+
const body = await request.json().catch(() => ({}));
|
|
21218
|
+
const input = body !== null && typeof body === "object" ? body : {};
|
|
21219
|
+
return json$2({ data: await core.fillReleaseLabels({
|
|
21220
|
+
dryRun: input.dryRun === true,
|
|
21221
|
+
catalogs: input.catalogs !== false
|
|
21222
|
+
}) });
|
|
21223
|
+
}),
|
|
20717
21224
|
updateBundle: onCore(async (core, request, params) => {
|
|
20718
21225
|
const bundleId = requireRouteParam(params, "id");
|
|
20719
21226
|
const update = bundleUpdateOf(await request.json(), bundleId);
|
|
@@ -20940,6 +21447,16 @@ const ADMIN_ROUTES = [
|
|
|
20940
21447
|
path: "/release-scopes",
|
|
20941
21448
|
handler: "listReleaseScopeKeys"
|
|
20942
21449
|
},
|
|
21450
|
+
{
|
|
21451
|
+
method: "GET",
|
|
21452
|
+
path: "/release-labels",
|
|
21453
|
+
handler: "getReleaseByLabel"
|
|
21454
|
+
},
|
|
21455
|
+
{
|
|
21456
|
+
method: "POST",
|
|
21457
|
+
path: "/release-labels/fill",
|
|
21458
|
+
handler: "fillReleaseLabels"
|
|
21459
|
+
},
|
|
20943
21460
|
{
|
|
20944
21461
|
method: "POST",
|
|
20945
21462
|
path: "/release-catalogs/:scopeKey/rebuild",
|
package/dist/init/index.cjs
CHANGED
|
@@ -7135,6 +7135,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7135
7135
|
});
|
|
7136
7136
|
let credential;
|
|
7137
7137
|
try {
|
|
7138
|
+
await (0, _hot_updater_cli_tools.fillReleaseLabels)(server);
|
|
7138
7139
|
credential = await (0, _hot_updater_cli_tools.provisionClientCredential)(server, {
|
|
7139
7140
|
env: initInputEnv,
|
|
7140
7141
|
name: "Vercel init"
|
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, resolveInitProviderInputs, shouldAutoSelectOnlyInitResource, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
5
|
+
import { ConfigBuilder, InitError, LegacyInfrastructureError, assembleServer, assertInfrastructureGenerationPayload, confirmInitInputPersistence, createHotUpdaterConfigScaffoldFromBuilder, createMigrator, fillReleaseLabels, 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";
|
|
@@ -7129,6 +7129,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7129
7129
|
});
|
|
7130
7130
|
let credential;
|
|
7131
7131
|
try {
|
|
7132
|
+
await fillReleaseLabels(server);
|
|
7132
7133
|
credential = await provisionClientCredential(server, {
|
|
7133
7134
|
env: initInputEnv,
|
|
7134
7135
|
name: "Vercel init"
|
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.51",
|
|
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/cli-tools": "1.2.0-rc.
|
|
45
|
-
"@hot-updater/plugin-core": "1.2.0-rc.
|
|
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.51",
|
|
45
|
+
"@hot-updater/plugin-core": "1.2.0-rc.51",
|
|
46
|
+
"@hot-updater/postgres": "1.2.0-rc.51",
|
|
47
|
+
"@hot-updater/protocol": "1.2.0-rc.51",
|
|
48
|
+
"@hot-updater/server": "1.2.0-rc.51"
|
|
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.51"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "tsdown",
|