@hot-updater/aws 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/init/index.cjs +1 -0
- package/dist/init/index.mjs +2 -1
- package/dist/lambda/index.cjs +584 -44
- package/package.json +8 -8
package/dist/init/index.cjs
CHANGED
|
@@ -8775,6 +8775,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
8775
8775
|
});
|
|
8776
8776
|
let credential;
|
|
8777
8777
|
try {
|
|
8778
|
+
await (0, _hot_updater_cli_tools.fillReleaseLabels)(server);
|
|
8778
8779
|
credential = await (0, _hot_updater_cli_tools.provisionClientCredential)(server, {
|
|
8779
8780
|
env: providerEnv,
|
|
8780
8781
|
name: "AWS init"
|
package/dist/init/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { ConfigBuilder, InitError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInfrastructureGenerationPayload, assertInitProviderInputs, colors, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, createZip, ensureInstallPackages, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInput, transformEnv, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
2
|
+
import { ConfigBuilder, InitError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInfrastructureGenerationPayload, assertInitProviderInputs, colors, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, createZip, ensureInstallPackages, fillReleaseLabels, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInput, transformEnv, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
3
3
|
import { apiKeys, insights, remoteConfig } from "@hot-updater/server/plugins";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
|
|
@@ -8770,6 +8770,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
8770
8770
|
});
|
|
8771
8771
|
let credential;
|
|
8772
8772
|
try {
|
|
8773
|
+
await fillReleaseLabels(server);
|
|
8773
8774
|
credential = await provisionClientCredential(server, {
|
|
8774
8775
|
env: providerEnv,
|
|
8775
8776
|
name: "AWS init"
|
package/dist/lambda/index.cjs
CHANGED
|
@@ -628,7 +628,8 @@ const releaseRowToRelease = (row) => ({
|
|
|
628
628
|
operation: row.operation,
|
|
629
629
|
sourceReleaseId: row.source_release_id,
|
|
630
630
|
createdAtMs: row.created_at_ms,
|
|
631
|
-
updatedAtMs: row.updated_at_ms
|
|
631
|
+
updatedAtMs: row.updated_at_ms,
|
|
632
|
+
label: row.label ?? null
|
|
632
633
|
});
|
|
633
634
|
const bundleToRow = (bundle) => {
|
|
634
635
|
const metadata = bundleMetadataToRow(bundle.metadata);
|
|
@@ -1137,7 +1138,8 @@ function rangeToIntervals(range) {
|
|
|
1137
1138
|
throw new ReleaseCatalogCompilationError("INVALID_TARGET_RANGE", `Invalid target app-version range: ${range}`);
|
|
1138
1139
|
}
|
|
1139
1140
|
}
|
|
1140
|
-
|
|
1141
|
+
/** A release's descriptor; its label only when it has one and `labels`. */
|
|
1142
|
+
function releaseDescriptor(release, labels) {
|
|
1141
1143
|
return {
|
|
1142
1144
|
releaseId: release.id,
|
|
1143
1145
|
kind: release.kind,
|
|
@@ -1145,7 +1147,8 @@ function releaseDescriptor(release) {
|
|
|
1145
1147
|
rolloutCohortCount: release.rolloutCohortCount,
|
|
1146
1148
|
targetCohorts: [...new Set(release.targetCohorts)].sort(),
|
|
1147
1149
|
shouldForceUpdate: release.shouldForceUpdate,
|
|
1148
|
-
message: release.message
|
|
1150
|
+
message: release.message,
|
|
1151
|
+
...labels && typeof release.label === "number" ? { label: release.label } : {}
|
|
1149
1152
|
};
|
|
1150
1153
|
}
|
|
1151
1154
|
function validateReleases(releases, strategy) {
|
|
@@ -1358,12 +1361,21 @@ async function compileReleaseCatalog(input) {
|
|
|
1358
1361
|
const targetCohorts = new Set(releases.flatMap((release) => release.targetCohorts));
|
|
1359
1362
|
if (targetCohorts.size > 512) throw new ReleaseCatalogCompilationError("DISTINCT_TARGET_COHORT_LIMIT", `Scope exceeds 512 distinct target cohorts`);
|
|
1360
1363
|
const { envelope, retainedReleases } = input.strategy === "APP_VERSION" ? compileAppVersion(releases) : compileFingerprint(releases);
|
|
1361
|
-
const
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
+
const compile = (labels) => {
|
|
1365
|
+
const payload = {
|
|
1366
|
+
...envelope,
|
|
1367
|
+
releaseDescriptors: retainedReleases.map((release) => releaseDescriptor(release, labels))
|
|
1368
|
+
};
|
|
1369
|
+
const canonicalPayload = canonicalStringify(payload);
|
|
1370
|
+
return {
|
|
1371
|
+
payload,
|
|
1372
|
+
canonicalPayload,
|
|
1373
|
+
byteSize: new TextEncoder().encode(canonicalPayload).byteLength
|
|
1374
|
+
};
|
|
1364
1375
|
};
|
|
1365
|
-
|
|
1366
|
-
|
|
1376
|
+
let compiled = compile(true);
|
|
1377
|
+
if (compiled.byteSize > 262144 && retainedReleases.some((release) => typeof release.label === "number")) compiled = compile(false);
|
|
1378
|
+
const { payload, canonicalPayload, byteSize } = compiled;
|
|
1367
1379
|
if (byteSize > 262144) throw new ReleaseCatalogCompilationError("CATALOG_OVERSIZE", `Compiled Release catalog is ${byteSize} bytes; maximum is ${MAX_COMPILED_CATALOG_BYTES}`);
|
|
1368
1380
|
return {
|
|
1369
1381
|
byteSize,
|
|
@@ -2092,7 +2104,7 @@ const CHANNEL_ID = {
|
|
|
2092
2104
|
* every database's migrator creates missing tables and then records the
|
|
2093
2105
|
* version, and none of them changes an existing table's columns, so changing
|
|
2094
2106
|
* one needs a migration step of its own first. An index added to an existing
|
|
2095
|
-
* table is listed in `LATE_INDEXES`. The schema fence answers 503 on
|
|
2107
|
+
* table is listed in `LATE_INDEXES`, and a column in `LATE_COLUMNS`. The schema fence answers 503 on
|
|
2096
2108
|
* a database whose row differs, until it runs. Before a version is released,
|
|
2097
2109
|
* its tables change in place in its own migration, and a database one of its
|
|
2098
2110
|
* prereleases migrated takes the same change by hand: the fence compares this
|
|
@@ -2245,7 +2257,11 @@ const releases = defineTable({
|
|
|
2245
2257
|
}
|
|
2246
2258
|
},
|
|
2247
2259
|
created_at_ms: { type: "integer" },
|
|
2248
|
-
updated_at_ms: { type: "integer" }
|
|
2260
|
+
updated_at_ms: { type: "integer" },
|
|
2261
|
+
label: {
|
|
2262
|
+
type: "integer",
|
|
2263
|
+
required: false
|
|
2264
|
+
}
|
|
2249
2265
|
}, {
|
|
2250
2266
|
key: ["id"],
|
|
2251
2267
|
indexes: {
|
|
@@ -2282,6 +2298,15 @@ const releases = defineTable({
|
|
|
2282
2298
|
scopes: {
|
|
2283
2299
|
eq: [],
|
|
2284
2300
|
sort: ["scope_key"]
|
|
2301
|
+
},
|
|
2302
|
+
byLabel: {
|
|
2303
|
+
eq: [
|
|
2304
|
+
"channel_id",
|
|
2305
|
+
"platform",
|
|
2306
|
+
"label"
|
|
2307
|
+
],
|
|
2308
|
+
sort: [],
|
|
2309
|
+
unique: true
|
|
2285
2310
|
}
|
|
2286
2311
|
}
|
|
2287
2312
|
});
|
|
@@ -2298,6 +2323,43 @@ const LATE_INDEXES = [{
|
|
|
2298
2323
|
table: "releases",
|
|
2299
2324
|
index: "scopes"
|
|
2300
2325
|
}];
|
|
2326
|
+
/**
|
|
2327
|
+
* Columns added to a table that a released schema created: a migrator whose
|
|
2328
|
+
* store has columns adds each one missing from an existing table, with
|
|
2329
|
+
* `ALTER TABLE … ADD COLUMN`, before it creates the table's indexes, and
|
|
2330
|
+
* `db migrate` on a database whose settings match still looks for them,
|
|
2331
|
+
* since a database a prerelease migrated records the same settings. Each
|
|
2332
|
+
* is optional, so rows written before it, and rows a server of the earlier
|
|
2333
|
+
* release still writes, read as null. `releases.label` arrived in 1.2.0.
|
|
2334
|
+
*/
|
|
2335
|
+
const LATE_COLUMNS = [{
|
|
2336
|
+
table: "releases",
|
|
2337
|
+
column: "label"
|
|
2338
|
+
}];
|
|
2339
|
+
/**
|
|
2340
|
+
* One counter per sequence: `releases/<platform>/<channel ID>` holds the
|
|
2341
|
+
* last label that channel and platform's releases took. A deploy or a
|
|
2342
|
+
* promote reads it and writes the next value in the transaction that writes
|
|
2343
|
+
* the release, so two writers never take one label. `is_filled` is true once
|
|
2344
|
+
* every release of the sequence written before labels has one, in ID order;
|
|
2345
|
+
* until then a writer fills them first. Deleting a channel deletes its
|
|
2346
|
+
* counters, so a channel created again with the name starts at 1.
|
|
2347
|
+
*/
|
|
2348
|
+
const labelSequences = defineTable({
|
|
2349
|
+
id: {
|
|
2350
|
+
type: "string",
|
|
2351
|
+
maxLength: 1440,
|
|
2352
|
+
ascii: true
|
|
2353
|
+
},
|
|
2354
|
+
last_label: { type: "integer" },
|
|
2355
|
+
is_filled: { type: "boolean" }
|
|
2356
|
+
}, {
|
|
2357
|
+
key: ["id"],
|
|
2358
|
+
indexes: { all: {
|
|
2359
|
+
eq: [],
|
|
2360
|
+
sort: ["id"]
|
|
2361
|
+
} }
|
|
2362
|
+
});
|
|
2301
2363
|
/** One compiled catalog per scope; the update check reads exactly this row. */
|
|
2302
2364
|
const releaseCatalogs = defineTable({
|
|
2303
2365
|
scope_key: {
|
|
@@ -2669,7 +2731,8 @@ const coreModule = {
|
|
|
2669
2731
|
}),
|
|
2670
2732
|
native_builds: nativeBuilds,
|
|
2671
2733
|
ios_devices: iosDevices,
|
|
2672
|
-
ios_device_account: iosDeviceAccount
|
|
2734
|
+
ios_device_account: iosDeviceAccount,
|
|
2735
|
+
label_sequences: labelSequences
|
|
2673
2736
|
}
|
|
2674
2737
|
};
|
|
2675
2738
|
//#endregion
|
|
@@ -2797,8 +2860,26 @@ const fillLateIndexes = async (adapter, tables, { dryRun = false } = {}) => {
|
|
|
2797
2860
|
return lacking;
|
|
2798
2861
|
};
|
|
2799
2862
|
/**
|
|
2800
|
-
*
|
|
2801
|
-
*
|
|
2863
|
+
* The `LATE_COLUMNS` among `tables` that an existing table lacks, as
|
|
2864
|
+
* `<table>.<column>`, added unless `dryRun`: none on a store without
|
|
2865
|
+
* `migrations.addColumns`, or for a table not created yet.
|
|
2866
|
+
*/
|
|
2867
|
+
const addLateColumns = async (adapter, tables, { dryRun = false } = {}) => {
|
|
2868
|
+
const addColumns = adapter.migrations?.addColumns;
|
|
2869
|
+
if (addColumns === void 0) return [];
|
|
2870
|
+
const lacking = [];
|
|
2871
|
+
for (const table of tables) {
|
|
2872
|
+
const columns = LATE_COLUMNS.filter(({ table: name }) => name === table.name).map(({ column }) => column);
|
|
2873
|
+
if (columns.length === 0) continue;
|
|
2874
|
+
const added = await addColumns(table, columns, { dryRun });
|
|
2875
|
+
lacking.push(...added.map((column) => `${table.name}.${column}`));
|
|
2876
|
+
}
|
|
2877
|
+
return lacking;
|
|
2878
|
+
};
|
|
2879
|
+
/**
|
|
2880
|
+
* Adds the late columns existing tables lack, creates or updates every
|
|
2881
|
+
* table, writes the late indexes' missing items, then writes the settings
|
|
2882
|
+
* rows last. A database a newer release migrated is
|
|
2802
2883
|
* refused before anything is written: its settings are read first, and a
|
|
2803
2884
|
* store without them yet, whose read fails, has none to refuse.
|
|
2804
2885
|
*/
|
|
@@ -2806,6 +2887,7 @@ const migrateSchema = async (adapter, adapterName, tables, settings, ordered) =>
|
|
|
2806
2887
|
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2807
2888
|
const stored = await storedSettings(adapter, Object.keys(settings)).catch(() => void 0);
|
|
2808
2889
|
if (stored !== void 0) refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2890
|
+
await addLateColumns(adapter, tables);
|
|
2809
2891
|
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2810
2892
|
await fillLateIndexes(adapter, tables);
|
|
2811
2893
|
await writeSchemaSettings(adapter, adapterName, settings, ordered);
|
|
@@ -3842,23 +3924,45 @@ const createEngineMigrator = (options) => {
|
|
|
3842
3924
|
refuseNewerSchema(options.adapterName, stored, options.settings, options.ordered);
|
|
3843
3925
|
const changed = Object.entries(options.settings).filter(([key, value]) => stored.get(key) !== value);
|
|
3844
3926
|
if (changed.length === 0) {
|
|
3927
|
+
const columns = await addLateColumns(options.adapter, options.schema.tables, { dryRun: true });
|
|
3845
3928
|
const lacking = await fillLateIndexes(options.adapter, options.schema.tables, { dryRun: true });
|
|
3846
|
-
if (lacking.length === 0) return getEmptyMigrationResult();
|
|
3929
|
+
if (columns.length === 0 && lacking.length === 0) return getEmptyMigrationResult();
|
|
3847
3930
|
return {
|
|
3848
|
-
operations: [
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3931
|
+
operations: [
|
|
3932
|
+
...columns.map((column) => ({
|
|
3933
|
+
type: "custom",
|
|
3934
|
+
description: `Add column: ${column}`
|
|
3935
|
+
})),
|
|
3936
|
+
...columns.length === 0 ? [] : [{
|
|
3937
|
+
type: "custom",
|
|
3938
|
+
description: "Create the tables and indexes the database lacks"
|
|
3939
|
+
}],
|
|
3940
|
+
...lacking.length === 0 ? [] : [{
|
|
3941
|
+
type: "custom",
|
|
3942
|
+
description: `Write the index items rows lack: ${lacking.join(", ")}`
|
|
3943
|
+
}]
|
|
3944
|
+
],
|
|
3852
3945
|
execute: async () => {
|
|
3946
|
+
if (columns.length > 0) {
|
|
3947
|
+
await addLateColumns(options.adapter, options.schema.tables);
|
|
3948
|
+
await options.adapter.migrations.apply([...options.schema.tables, SETTINGS_TABLE]);
|
|
3949
|
+
}
|
|
3853
3950
|
await fillLateIndexes(options.adapter, options.schema.tables);
|
|
3854
3951
|
}
|
|
3855
3952
|
};
|
|
3856
3953
|
}
|
|
3857
3954
|
return {
|
|
3858
|
-
operations: [
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3955
|
+
operations: [
|
|
3956
|
+
...(await addLateColumns(options.adapter, options.schema.tables, { dryRun: true }).catch(() => [])).map((column) => ({
|
|
3957
|
+
type: "custom",
|
|
3958
|
+
description: `Add column: ${column}`
|
|
3959
|
+
})),
|
|
3960
|
+
{
|
|
3961
|
+
type: "custom",
|
|
3962
|
+
description: "Create the tables and indexes the database lacks"
|
|
3963
|
+
},
|
|
3964
|
+
...migrate.updateSettings === false ? [] : [settingsOperation(stored, changed)]
|
|
3965
|
+
],
|
|
3862
3966
|
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings, options.ordered)
|
|
3863
3967
|
};
|
|
3864
3968
|
};
|
|
@@ -5042,7 +5146,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
5042
5146
|
};
|
|
5043
5147
|
//#endregion
|
|
5044
5148
|
//#region ../../packages/server/dist/version.mjs
|
|
5045
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
5149
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.51";
|
|
5046
5150
|
//#endregion
|
|
5047
5151
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
5048
5152
|
/**
|
|
@@ -5841,7 +5945,7 @@ const baseBundleIdsOf = (row, range, bundleId, limit) => {
|
|
|
5841
5945
|
};
|
|
5842
5946
|
//#endregion
|
|
5843
5947
|
//#region ../../packages/server/dist/core/reads.mjs
|
|
5844
|
-
const PAGE$
|
|
5948
|
+
const PAGE$4 = 500;
|
|
5845
5949
|
const pick$2 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
|
|
5846
5950
|
const toBundleRow = pick$2([
|
|
5847
5951
|
"id",
|
|
@@ -5862,7 +5966,7 @@ const toPatchRow = pick$2([
|
|
|
5862
5966
|
"byte_size",
|
|
5863
5967
|
"order_index"
|
|
5864
5968
|
]);
|
|
5865
|
-
const
|
|
5969
|
+
const pickReleaseRow = pick$2([
|
|
5866
5970
|
"id",
|
|
5867
5971
|
"revision",
|
|
5868
5972
|
"scope_key",
|
|
@@ -5883,6 +5987,13 @@ const toReleaseRow = pick$2([
|
|
|
5883
5987
|
"created_at_ms",
|
|
5884
5988
|
"updated_at_ms"
|
|
5885
5989
|
]);
|
|
5990
|
+
/** A release row; `label` null where the store holds none, as before the column. */
|
|
5991
|
+
const toReleaseRow = (row) => {
|
|
5992
|
+
return {
|
|
5993
|
+
...pickReleaseRow(row),
|
|
5994
|
+
label: typeof row.label === "number" ? row.label : null
|
|
5995
|
+
};
|
|
5996
|
+
};
|
|
5886
5997
|
const toCatalogRow = pick$2([
|
|
5887
5998
|
"scope_key",
|
|
5888
5999
|
"catalog_id",
|
|
@@ -5931,7 +6042,7 @@ const createCoreReads = (db, storage) => {
|
|
|
5931
6042
|
const page = await db.findMany("bundle_patches", {
|
|
5932
6043
|
index: "byBundle",
|
|
5933
6044
|
where: { bundle_id: row.id },
|
|
5934
|
-
limit: Math.min(count - patches.length, PAGE$
|
|
6045
|
+
limit: Math.min(count - patches.length, PAGE$4),
|
|
5935
6046
|
...cursor === void 0 ? {} : { cursor }
|
|
5936
6047
|
});
|
|
5937
6048
|
patches.push(...page.rows.map(toPatchRow));
|
|
@@ -6041,6 +6152,23 @@ const createCoreReads = (db, storage) => {
|
|
|
6041
6152
|
const row = await db.findOne("releases", { id });
|
|
6042
6153
|
return row === null ? null : toReleaseRow(row);
|
|
6043
6154
|
},
|
|
6155
|
+
/**
|
|
6156
|
+
* The release a label names: its unique index, then the row itself,
|
|
6157
|
+
* since a key-value store keeps an index copy a server of an earlier
|
|
6158
|
+
* release may have left behind when it changed or deleted the row.
|
|
6159
|
+
*/
|
|
6160
|
+
async getReleaseByLabel({ channel, platform, label }) {
|
|
6161
|
+
const found = await db.findOne("releases", {
|
|
6162
|
+
channel_id: `channel:${encodeChannelKey(channel)}`,
|
|
6163
|
+
platform,
|
|
6164
|
+
label
|
|
6165
|
+
});
|
|
6166
|
+
if (found === null) return null;
|
|
6167
|
+
const row = await db.findOne("releases", { id: found.id });
|
|
6168
|
+
if (row === null) return null;
|
|
6169
|
+
const release = toReleaseRow(row);
|
|
6170
|
+
return release.label === label && release.platform === platform ? release : null;
|
|
6171
|
+
},
|
|
6044
6172
|
/** One page of releases through the index its filter names. */
|
|
6045
6173
|
async listReleases(input) {
|
|
6046
6174
|
const { filter } = input;
|
|
@@ -6140,7 +6268,7 @@ const createCoreReads = (db, storage) => {
|
|
|
6140
6268
|
return (await drain$1((page) => db.findMany("channels", {
|
|
6141
6269
|
index: "all",
|
|
6142
6270
|
where: {},
|
|
6143
|
-
limit: PAGE$
|
|
6271
|
+
limit: PAGE$4,
|
|
6144
6272
|
...page
|
|
6145
6273
|
}))).map(toChannelRow);
|
|
6146
6274
|
},
|
|
@@ -6468,6 +6596,313 @@ const NATIVE_BUILD_SUBMISSION_DESTINATIONS = {
|
|
|
6468
6596
|
ios: ["testflight"]
|
|
6469
6597
|
};
|
|
6470
6598
|
//#endregion
|
|
6599
|
+
//#region ../../packages/server/dist/core/labels.mjs
|
|
6600
|
+
/**
|
|
6601
|
+
* The counter of a channel and platform's release labels: one
|
|
6602
|
+
* `label_sequences` row, which every writer of the pair reads and bumps.
|
|
6603
|
+
*/
|
|
6604
|
+
const labelSequenceId = (channelId, platform) => `releases/${platform}/${channelId}`;
|
|
6605
|
+
/** The pairs a channel's counters belong to, which deleting it removes. */
|
|
6606
|
+
const LABEL_PLATFORMS = ["ios", "android"];
|
|
6607
|
+
/**
|
|
6608
|
+
* A channel and platform whose releases written before labels have none
|
|
6609
|
+
* yet, or that has no counter: the write stops before taking a label, the
|
|
6610
|
+
* core labels the pair with `fillLabels`, and the write runs again.
|
|
6611
|
+
*/
|
|
6612
|
+
var NeedsLabelFill = class extends Error {
|
|
6613
|
+
channelId;
|
|
6614
|
+
platform;
|
|
6615
|
+
constructor(channelId, platform) {
|
|
6616
|
+
super(`Release labels of ${platform} ${channelId} need a fill first.`);
|
|
6617
|
+
this.channelId = channelId;
|
|
6618
|
+
this.platform = platform;
|
|
6619
|
+
}
|
|
6620
|
+
};
|
|
6621
|
+
const createLabelAllocator = (tx, used, caughtUp) => {
|
|
6622
|
+
const sequences = /* @__PURE__ */ new Map();
|
|
6623
|
+
return {
|
|
6624
|
+
async next(channelId, platform) {
|
|
6625
|
+
const id = labelSequenceId(channelId, platform);
|
|
6626
|
+
let sequence = sequences.get(id);
|
|
6627
|
+
if (sequence === void 0) {
|
|
6628
|
+
const row = await tx.findOne("label_sequences", { id });
|
|
6629
|
+
if (row === null || !row.is_filled) {
|
|
6630
|
+
const channel = row === null ? await tx.findOne("channels", { id: channelId }) : null;
|
|
6631
|
+
if (channel === null || (channel._refs_releases_channel_id ?? 0) > 0) throw new NeedsLabelFill(channelId, platform);
|
|
6632
|
+
}
|
|
6633
|
+
const read = row?.last_label ?? 0;
|
|
6634
|
+
sequence = {
|
|
6635
|
+
row,
|
|
6636
|
+
read,
|
|
6637
|
+
last: read
|
|
6638
|
+
};
|
|
6639
|
+
sequences.set(id, sequence);
|
|
6640
|
+
used.set(id, {
|
|
6641
|
+
channelId,
|
|
6642
|
+
platform,
|
|
6643
|
+
read
|
|
6644
|
+
});
|
|
6645
|
+
}
|
|
6646
|
+
sequence.last += 1;
|
|
6647
|
+
return sequence.last;
|
|
6648
|
+
},
|
|
6649
|
+
caughtUp(channelId, platform) {
|
|
6650
|
+
caughtUp.set(labelSequenceId(channelId, platform), {
|
|
6651
|
+
channelId,
|
|
6652
|
+
platform
|
|
6653
|
+
});
|
|
6654
|
+
},
|
|
6655
|
+
flush() {
|
|
6656
|
+
for (const [id, { row, read, last }] of sequences) if (row === null) tx.create("label_sequences", {
|
|
6657
|
+
id,
|
|
6658
|
+
last_label: last,
|
|
6659
|
+
is_filled: true
|
|
6660
|
+
});
|
|
6661
|
+
else if (last !== read) tx.update("label_sequences", row, { last_label: last });
|
|
6662
|
+
}
|
|
6663
|
+
};
|
|
6664
|
+
};
|
|
6665
|
+
const FILL_BATCH = 25;
|
|
6666
|
+
const PAGE$3 = 500;
|
|
6667
|
+
/**
|
|
6668
|
+
* Labels a channel and platform's releases that have none, in ID order,
|
|
6669
|
+
* which is the order they were created in, and marks its counter filled:
|
|
6670
|
+
* each batch reads the counter and its rows guarded, so a concurrent fill or
|
|
6671
|
+
* write serializes on the counter and skips what another labeled. With
|
|
6672
|
+
* `dryRun`, it only counts them. Answers how many it labeled.
|
|
6673
|
+
*/
|
|
6674
|
+
const fillLabels = async (db, { channelId, platform }, { dryRun = false } = {}) => {
|
|
6675
|
+
const id = labelSequenceId(channelId, platform);
|
|
6676
|
+
let labeled = 0;
|
|
6677
|
+
let batchSize = FILL_BATCH;
|
|
6678
|
+
const label = async (ids) => {
|
|
6679
|
+
for (let at = 0; at < ids.length;) {
|
|
6680
|
+
const batch = ids.slice(at, at + batchSize);
|
|
6681
|
+
try {
|
|
6682
|
+
labeled += await db.transaction(async (tx) => {
|
|
6683
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
6684
|
+
let last = counter?.last_label ?? 0;
|
|
6685
|
+
let count = 0;
|
|
6686
|
+
for (const releaseId of batch) {
|
|
6687
|
+
const row = await tx.findOne("releases", { id: releaseId });
|
|
6688
|
+
if (row === null || typeof row.label === "number") continue;
|
|
6689
|
+
last += 1;
|
|
6690
|
+
count += 1;
|
|
6691
|
+
tx.update("releases", row, { label: last });
|
|
6692
|
+
}
|
|
6693
|
+
if (counter === null) tx.create("label_sequences", {
|
|
6694
|
+
id,
|
|
6695
|
+
last_label: last,
|
|
6696
|
+
is_filled: false
|
|
6697
|
+
});
|
|
6698
|
+
else if (last !== counter.last_label) tx.update("label_sequences", counter, { last_label: last });
|
|
6699
|
+
return count;
|
|
6700
|
+
});
|
|
6701
|
+
at += batch.length;
|
|
6702
|
+
} catch (error) {
|
|
6703
|
+
if (batchSize > 1 && error instanceof DatabaseConstraintError && error.reason === "too_large") {
|
|
6704
|
+
batchSize = Math.max(1, Math.floor(batchSize / 2));
|
|
6705
|
+
continue;
|
|
6706
|
+
}
|
|
6707
|
+
throw error;
|
|
6708
|
+
}
|
|
6709
|
+
}
|
|
6710
|
+
};
|
|
6711
|
+
let cursor;
|
|
6712
|
+
do {
|
|
6713
|
+
const page = await db.findMany("releases", {
|
|
6714
|
+
index: "byChannelPlatform",
|
|
6715
|
+
where: {
|
|
6716
|
+
channel_id: channelId,
|
|
6717
|
+
platform
|
|
6718
|
+
},
|
|
6719
|
+
limit: PAGE$3,
|
|
6720
|
+
...cursor === void 0 ? {} : { cursor }
|
|
6721
|
+
});
|
|
6722
|
+
const unlabeled = page.rows.filter((row) => typeof row.label !== "number").map((row) => row.id);
|
|
6723
|
+
if (dryRun) labeled += unlabeled.length;
|
|
6724
|
+
else await label(unlabeled);
|
|
6725
|
+
cursor = page.next;
|
|
6726
|
+
} while (cursor !== void 0);
|
|
6727
|
+
if (dryRun) return labeled;
|
|
6728
|
+
await db.transaction(async (tx) => {
|
|
6729
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
6730
|
+
if (counter === null) tx.create("label_sequences", {
|
|
6731
|
+
id,
|
|
6732
|
+
last_label: 0,
|
|
6733
|
+
is_filled: true
|
|
6734
|
+
});
|
|
6735
|
+
else if (!counter.is_filled) tx.update("label_sequences", counter, { is_filled: true });
|
|
6736
|
+
});
|
|
6737
|
+
return labeled;
|
|
6738
|
+
};
|
|
6739
|
+
/**
|
|
6740
|
+
* Reads what a pair's fill writes, its counter and its label index, without
|
|
6741
|
+
* writing: a database without release labels' schema, such as one a 1.2
|
|
6742
|
+
* prerelease migrated, fails here as the fill would. The schema is the
|
|
6743
|
+
* database's, so one pair tells. Two reads.
|
|
6744
|
+
*/
|
|
6745
|
+
const probeLabelSchema = async (db, { channelId, platform }) => {
|
|
6746
|
+
await db.findOne("label_sequences", { id: labelSequenceId(channelId, platform) });
|
|
6747
|
+
await db.findMany("releases", {
|
|
6748
|
+
index: "byLabel",
|
|
6749
|
+
where: {
|
|
6750
|
+
channel_id: channelId,
|
|
6751
|
+
platform,
|
|
6752
|
+
label: 0
|
|
6753
|
+
},
|
|
6754
|
+
limit: 1
|
|
6755
|
+
});
|
|
6756
|
+
};
|
|
6757
|
+
const REPAIRS = 4;
|
|
6758
|
+
const RACES = 32;
|
|
6759
|
+
/**
|
|
6760
|
+
* Runs a release write that takes labels, in one transaction with the
|
|
6761
|
+
* counters it bumps. A pair that still needs its fill is filled, and the
|
|
6762
|
+
* write runs again; so is a pair whose catch-up made the write too large for
|
|
6763
|
+
* the store. A label another row holds, such as an index item a release
|
|
6764
|
+
* deleted by a server of an earlier release left on a key-value store, is
|
|
6765
|
+
* skipped: its counters move past it and the write runs again.
|
|
6766
|
+
*/
|
|
6767
|
+
const writeWithLabels = async (db, write) => {
|
|
6768
|
+
const filled = /* @__PURE__ */ new Set();
|
|
6769
|
+
const fill = async (pairs) => {
|
|
6770
|
+
for (const pair of pairs) {
|
|
6771
|
+
filled.add(labelSequenceId(pair.channelId, pair.platform));
|
|
6772
|
+
await fillLabels(db, pair);
|
|
6773
|
+
}
|
|
6774
|
+
};
|
|
6775
|
+
for (let repairs = 0, races = 0;;) {
|
|
6776
|
+
const used = /* @__PURE__ */ new Map();
|
|
6777
|
+
const caughtUp = /* @__PURE__ */ new Map();
|
|
6778
|
+
try {
|
|
6779
|
+
return await db.transaction(async (tx) => {
|
|
6780
|
+
used.clear();
|
|
6781
|
+
caughtUp.clear();
|
|
6782
|
+
const labels = createLabelAllocator(tx, used, caughtUp);
|
|
6783
|
+
const result = await write(tx, labels);
|
|
6784
|
+
labels.flush();
|
|
6785
|
+
return result;
|
|
6786
|
+
});
|
|
6787
|
+
} catch (error) {
|
|
6788
|
+
const needs = error instanceof NeedsLabelFill ? [error] : error instanceof DatabaseConstraintError && error.reason === "too_large" ? [...caughtUp.values()] : [];
|
|
6789
|
+
if (needs.length > 0) {
|
|
6790
|
+
const fresh = needs.some(({ channelId, platform }) => !filled.has(labelSequenceId(channelId, platform)));
|
|
6791
|
+
if (fresh || repairs < REPAIRS) {
|
|
6792
|
+
if (!fresh) repairs += 1;
|
|
6793
|
+
await fill(needs);
|
|
6794
|
+
continue;
|
|
6795
|
+
}
|
|
6796
|
+
}
|
|
6797
|
+
if (error instanceof DatabaseConstraintError && error.reason === "unique" && error.model === "releases" && used.size > 0) {
|
|
6798
|
+
if (await db.transaction(async (tx) => {
|
|
6799
|
+
const moves = [];
|
|
6800
|
+
for (const [id, { channelId, read }] of used) {
|
|
6801
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
6802
|
+
if (counter !== null) {
|
|
6803
|
+
if (counter.last_label !== read) return false;
|
|
6804
|
+
moves.push(() => tx.update("label_sequences", counter, { last_label: read + 1 }));
|
|
6805
|
+
continue;
|
|
6806
|
+
}
|
|
6807
|
+
const channel = await tx.findOne("channels", { id: channelId });
|
|
6808
|
+
if (channel === null || (channel._refs_releases_channel_id ?? 0) > 0) return false;
|
|
6809
|
+
moves.push(() => tx.create("label_sequences", {
|
|
6810
|
+
id,
|
|
6811
|
+
last_label: read + 1,
|
|
6812
|
+
is_filled: true
|
|
6813
|
+
}));
|
|
6814
|
+
}
|
|
6815
|
+
for (const move of moves) move();
|
|
6816
|
+
return true;
|
|
6817
|
+
}) ? (repairs += 1) <= REPAIRS : (races += 1) <= RACES) continue;
|
|
6818
|
+
}
|
|
6819
|
+
throw error;
|
|
6820
|
+
}
|
|
6821
|
+
}
|
|
6822
|
+
};
|
|
6823
|
+
/**
|
|
6824
|
+
* Labels a scope's releases a server of an earlier release wrote after its
|
|
6825
|
+
* newest labeled one, oldest first, before the write takes its own label:
|
|
6826
|
+
* `latest` is the scope's newest release, so a labeled one costs no read.
|
|
6827
|
+
* Answers the labels it gave, by release ID.
|
|
6828
|
+
*/
|
|
6829
|
+
const catchUpLabels = async (tx, labels, latest) => {
|
|
6830
|
+
const given = /* @__PURE__ */ new Map();
|
|
6831
|
+
if (latest === null || typeof latest.label === "number") return given;
|
|
6832
|
+
const unlabeled = [];
|
|
6833
|
+
let cursor;
|
|
6834
|
+
scan: do {
|
|
6835
|
+
const page = await tx.findMany("releases", {
|
|
6836
|
+
index: "byScope",
|
|
6837
|
+
where: { scope_key: latest.scope_key },
|
|
6838
|
+
order: "desc",
|
|
6839
|
+
limit: FILL_BATCH,
|
|
6840
|
+
...cursor === void 0 ? {} : { cursor }
|
|
6841
|
+
});
|
|
6842
|
+
for (const row of page.rows) {
|
|
6843
|
+
if (typeof row.label === "number") break scan;
|
|
6844
|
+
unlabeled.push(row);
|
|
6845
|
+
}
|
|
6846
|
+
cursor = page.next;
|
|
6847
|
+
} while (cursor !== void 0);
|
|
6848
|
+
labels.caughtUp(latest.channel_id, latest.platform);
|
|
6849
|
+
for (const row of unlabeled.reverse()) {
|
|
6850
|
+
const { id, channel_id, platform } = toReleaseRow(row);
|
|
6851
|
+
const label = await labels.next(channel_id, platform);
|
|
6852
|
+
tx.update("releases", row, { label });
|
|
6853
|
+
given.set(id, label);
|
|
6854
|
+
}
|
|
6855
|
+
return given;
|
|
6856
|
+
};
|
|
6857
|
+
/**
|
|
6858
|
+
* The channels and platforms whose releases need labels: a scope whose
|
|
6859
|
+
* newest release has none, or a pair without a filled counter. Releases a
|
|
6860
|
+
* server of an earlier release wrote in a filled pair come after its
|
|
6861
|
+
* labeled ones in their scope, so the newest release of each scope tells.
|
|
6862
|
+
* Two reads per scope, one per pair.
|
|
6863
|
+
*/
|
|
6864
|
+
const pendingLabelPairs = async (db) => {
|
|
6865
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
6866
|
+
for (let last = "";;) {
|
|
6867
|
+
const { rows } = await db.findMany("releases", {
|
|
6868
|
+
index: "scopes",
|
|
6869
|
+
where: {},
|
|
6870
|
+
limit: 1,
|
|
6871
|
+
range: { gt: last }
|
|
6872
|
+
});
|
|
6873
|
+
if (rows[0] === void 0) break;
|
|
6874
|
+
last = rows[0].scope_key;
|
|
6875
|
+
const { rows: newest } = await db.findMany("releases", {
|
|
6876
|
+
index: "byScope",
|
|
6877
|
+
where: { scope_key: last },
|
|
6878
|
+
order: "desc",
|
|
6879
|
+
limit: 1
|
|
6880
|
+
});
|
|
6881
|
+
if (newest[0] === void 0) continue;
|
|
6882
|
+
const { channel_id: channelId, platform, label } = toReleaseRow(newest[0]);
|
|
6883
|
+
const id = labelSequenceId(channelId, platform);
|
|
6884
|
+
const pair = pairs.get(id) ?? {
|
|
6885
|
+
channelId,
|
|
6886
|
+
platform,
|
|
6887
|
+
pending: false
|
|
6888
|
+
};
|
|
6889
|
+
pair.pending ||= label === null;
|
|
6890
|
+
pairs.set(id, pair);
|
|
6891
|
+
}
|
|
6892
|
+
const pending = [];
|
|
6893
|
+
for (const [id, { channelId, platform, pending: unlabeled }] of pairs) {
|
|
6894
|
+
if (!unlabeled) {
|
|
6895
|
+
const counter = await db.findOne("label_sequences", { id });
|
|
6896
|
+
if (counter !== null && counter.is_filled) continue;
|
|
6897
|
+
}
|
|
6898
|
+
pending.push({
|
|
6899
|
+
channelId,
|
|
6900
|
+
platform
|
|
6901
|
+
});
|
|
6902
|
+
}
|
|
6903
|
+
return pending;
|
|
6904
|
+
};
|
|
6905
|
+
//#endregion
|
|
6471
6906
|
//#region ../../packages/server/dist/core/writes.mjs
|
|
6472
6907
|
const PAGE$2 = 500;
|
|
6473
6908
|
/** Moves one bundle into or out of its platform's total and the overall total. */
|
|
@@ -6548,7 +6983,11 @@ const insertChannel = async (db, row) => {
|
|
|
6548
6983
|
throw error;
|
|
6549
6984
|
}
|
|
6550
6985
|
};
|
|
6551
|
-
/**
|
|
6986
|
+
/**
|
|
6987
|
+
* Deletes a channel no release or native build uses, with its label
|
|
6988
|
+
* counters, so one created again with its name starts at 1: 3 reads,
|
|
6989
|
+
* 1 query, 1 write.
|
|
6990
|
+
*/
|
|
6552
6991
|
const deleteChannel = (db, id) => db.transaction(async (tx) => {
|
|
6553
6992
|
const row = await tx.findOne("channels", { id });
|
|
6554
6993
|
if (row === null) return {
|
|
@@ -6568,6 +7007,10 @@ const deleteChannel = (db, id) => db.transaction(async (tx) => {
|
|
|
6568
7007
|
deleted: false,
|
|
6569
7008
|
reason: "not_empty"
|
|
6570
7009
|
};
|
|
7010
|
+
for (const platform of LABEL_PLATFORMS) {
|
|
7011
|
+
const counter = await tx.findOne("label_sequences", { id: labelSequenceId(id, platform) });
|
|
7012
|
+
if (counter !== null) await tx.delete("label_sequences", counter);
|
|
7013
|
+
}
|
|
6571
7014
|
await tx.delete("channels", row);
|
|
6572
7015
|
return { deleted: true };
|
|
6573
7016
|
});
|
|
@@ -7104,15 +7547,15 @@ const enabledIn = (scopeKey, cursor) => ({
|
|
|
7104
7547
|
});
|
|
7105
7548
|
/** A scope's enabled releases, all of them, under the catalog's guard. */
|
|
7106
7549
|
const enabledReleases = (tx, scopeKey) => drainReleases((cursor) => tx.findMany("releases", enabledIn(scopeKey, cursor)));
|
|
7107
|
-
/** The scope's newest release
|
|
7108
|
-
const
|
|
7550
|
+
/** The scope's newest release: `byScope` descending, limit 1. */
|
|
7551
|
+
const latestRelease = async (tx, scopeKey) => {
|
|
7109
7552
|
const { rows } = await tx.findMany("releases", {
|
|
7110
7553
|
index: "byScope",
|
|
7111
7554
|
where: { scope_key: scopeKey },
|
|
7112
7555
|
order: "desc",
|
|
7113
7556
|
limit: 1
|
|
7114
7557
|
});
|
|
7115
|
-
return rows[0]
|
|
7558
|
+
return rows[0] === void 0 ? null : toReleaseRow(rows[0]);
|
|
7116
7559
|
};
|
|
7117
7560
|
/** The scope's next catalog generation, compiled as `compilation`. */
|
|
7118
7561
|
const nextCatalog = (scope, stored, compilation, updatedAtMs) => {
|
|
@@ -7174,11 +7617,16 @@ const readCatalog = async (tx, scopeKey) => {
|
|
|
7174
7617
|
const assertHistory = (stored, hasReleases) => {
|
|
7175
7618
|
if (stored.catalog === null && hasReleases) fail$1("CATALOG_IDENTITY_MISSING", "Catalog history is missing. Restore its catalog row from backup before rebuilding or deploying.");
|
|
7176
7619
|
};
|
|
7177
|
-
/**
|
|
7178
|
-
|
|
7620
|
+
/**
|
|
7621
|
+
* One release change and its scope's next catalog, inside `tx`. An insert
|
|
7622
|
+
* takes its channel and platform's next label from `labels`, after labeling
|
|
7623
|
+
* the releases a server of an earlier release wrote in the scope since its
|
|
7624
|
+
* last labeled one.
|
|
7625
|
+
*/
|
|
7626
|
+
const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }, labels) => {
|
|
7179
7627
|
checkScope(scope);
|
|
7180
7628
|
const stored = await readCatalog(tx, scope.scopeKey);
|
|
7181
|
-
|
|
7629
|
+
let enabled = await enabledReleases(tx, scope.scopeKey);
|
|
7182
7630
|
if (bundle !== void 0) {
|
|
7183
7631
|
insertBundle(tx, bundle.row);
|
|
7184
7632
|
for (const patch of bundle.patches) tx.create("bundle_patches", patch);
|
|
@@ -7186,14 +7634,22 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
7186
7634
|
let before = null;
|
|
7187
7635
|
let release;
|
|
7188
7636
|
if (change.operation === "insert") {
|
|
7189
|
-
|
|
7637
|
+
if (labels === void 0) throw new Error("A release insert takes its label from an allocator.");
|
|
7638
|
+
const newest = await latestRelease(tx, scope.scopeKey);
|
|
7639
|
+
const latest = newest?.id ?? null;
|
|
7190
7640
|
assertHistory(stored, latest !== null);
|
|
7191
7641
|
const floor = [latest, bundle && isUUIDv7(bundle.row.id) ? bundle.row.id : null].filter((id) => id !== null).sort().at(-1);
|
|
7192
7642
|
const id = change.row.id ?? createUUIDv7After(floor ?? null);
|
|
7193
7643
|
if (latest !== null && id <= latest) fail$1("NON_MONOTONIC_RELEASE_ID", `Release "${id}" must sort after "${latest}"`);
|
|
7644
|
+
const given = await catchUpLabels(tx, labels, newest);
|
|
7645
|
+
if (given.size > 0) enabled = enabled.map((row) => given.has(row.id) ? {
|
|
7646
|
+
...row,
|
|
7647
|
+
label: given.get(row.id)
|
|
7648
|
+
} : row);
|
|
7194
7649
|
release = {
|
|
7195
7650
|
...change.row,
|
|
7196
|
-
id
|
|
7651
|
+
id,
|
|
7652
|
+
label: await labels.next(scope.channelId, scope.platform)
|
|
7197
7653
|
};
|
|
7198
7654
|
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");
|
|
7199
7655
|
tx.create("releases", release);
|
|
@@ -7206,8 +7662,9 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
7206
7662
|
await tx.delete("releases", row);
|
|
7207
7663
|
release = null;
|
|
7208
7664
|
} else {
|
|
7665
|
+
const { label: _label, ...update } = change.update;
|
|
7209
7666
|
const set = {
|
|
7210
|
-
...
|
|
7667
|
+
...update,
|
|
7211
7668
|
revision: before.revision + 1
|
|
7212
7669
|
};
|
|
7213
7670
|
tx.update("releases", row, set);
|
|
@@ -7235,14 +7692,27 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
7235
7692
|
*/
|
|
7236
7693
|
const changeReleases = (db, inputs) => {
|
|
7237
7694
|
if (new Set(inputs.map(({ scope }) => scope.scopeKey)).size !== inputs.length) fail$1("INVALID_SCOPE", "A batch cannot change one catalog scope twice");
|
|
7238
|
-
return db
|
|
7695
|
+
return writeWithLabels(db, async (tx, labels) => {
|
|
7239
7696
|
const results = [];
|
|
7240
|
-
for (const input of inputs) results.push(await changeRelease(tx, input));
|
|
7697
|
+
for (const input of inputs) results.push(await changeRelease(tx, input, labels));
|
|
7241
7698
|
return results;
|
|
7242
7699
|
});
|
|
7243
7700
|
};
|
|
7244
7701
|
/** Whether `current` is what the scope's enabled releases compile to. */
|
|
7245
7702
|
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;
|
|
7703
|
+
/** A compiled payload with its descriptors' labels left out. */
|
|
7704
|
+
const withoutLabels = (payload) => {
|
|
7705
|
+
const parsed = JSON.parse(payload);
|
|
7706
|
+
return JSON.stringify({
|
|
7707
|
+
...parsed,
|
|
7708
|
+
releaseDescriptors: (parsed.releaseDescriptors ?? []).map(({ label: _label, ...descriptor }) => descriptor)
|
|
7709
|
+
});
|
|
7710
|
+
};
|
|
7711
|
+
/**
|
|
7712
|
+
* Whether `projected` differs from `current` only by release labels, as a
|
|
7713
|
+
* catalog compiled before its releases had them does.
|
|
7714
|
+
*/
|
|
7715
|
+
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);
|
|
7246
7716
|
/** The scope a catalog row names. */
|
|
7247
7717
|
const catalogRowScope = (row) => ({
|
|
7248
7718
|
channelId: row.channel_id,
|
|
@@ -7268,18 +7738,20 @@ const preflightRebuild = async (db, scopeKey, updatedAtMs) => {
|
|
|
7268
7738
|
const enabled = await drainReleases((cursor) => db.findMany("releases", enabledIn(scopeKey, cursor)));
|
|
7269
7739
|
const compilation = await compileScope(scope, enabled);
|
|
7270
7740
|
const changed = !isCurrent(scope, current, compilation);
|
|
7741
|
+
const projectedCatalog = changed ? nextCatalog(scope, { catalog: current }, compilation, updatedAtMs) : current;
|
|
7271
7742
|
return {
|
|
7272
7743
|
changed,
|
|
7744
|
+
labelsOnly: changed && differsInLabelsOnly(current, projectedCatalog),
|
|
7273
7745
|
currentCatalog: current,
|
|
7274
7746
|
diagnostics: compilation.diagnostics,
|
|
7275
|
-
projectedCatalog
|
|
7747
|
+
projectedCatalog
|
|
7276
7748
|
};
|
|
7277
7749
|
};
|
|
7278
7750
|
/** Recompiles a scope's catalog from its enabled releases inside `tx`; an unchanged catalog is not rewritten. */
|
|
7279
7751
|
const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
7280
7752
|
checkScope(scope);
|
|
7281
7753
|
const stored = await readCatalog(tx, scope.scopeKey);
|
|
7282
|
-
assertHistory(stored, await
|
|
7754
|
+
assertHistory(stored, await latestRelease(tx, scope.scopeKey) !== null);
|
|
7283
7755
|
const enabled = await enabledReleases(tx, scope.scopeKey);
|
|
7284
7756
|
const compilation = await compileScope(scope, enabled);
|
|
7285
7757
|
const current = stored.catalog;
|
|
@@ -7299,6 +7771,7 @@ const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
|
7299
7771
|
};
|
|
7300
7772
|
//#endregion
|
|
7301
7773
|
//#region ../../packages/server/dist/core/operations.mjs
|
|
7774
|
+
const CATALOG_PAGE = 100;
|
|
7302
7775
|
/** Carries a preflight's result out of the transaction it stops, so nothing is written. */
|
|
7303
7776
|
var Preflight = class extends Error {
|
|
7304
7777
|
result;
|
|
@@ -7530,7 +8003,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
7530
8003
|
if (targetChannel.length === 0) throw new ReleaseManagementError("TARGET_RELEASE_INVALID", "Promotion requires a target channel.");
|
|
7531
8004
|
const channel = await ensureChannel(targetChannel);
|
|
7532
8005
|
const updatedAtMs = now();
|
|
7533
|
-
return db
|
|
8006
|
+
return writeWithLabels(db, async (tx, labels) => {
|
|
7534
8007
|
const { release: source, scope: sourceScope } = await loadTarget(tx, input);
|
|
7535
8008
|
checkSource(source);
|
|
7536
8009
|
const targetScope = scopeOf$1(channel, source.platform, source.fingerprint_hash);
|
|
@@ -7558,12 +8031,13 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
7558
8031
|
},
|
|
7559
8032
|
updatedAtMs
|
|
7560
8033
|
}) : null;
|
|
8034
|
+
const { label: _label, ...copied } = source;
|
|
7561
8035
|
const target = await changeRelease(tx, {
|
|
7562
8036
|
scope: targetScope,
|
|
7563
8037
|
change: {
|
|
7564
8038
|
operation: "insert",
|
|
7565
8039
|
row: {
|
|
7566
|
-
...
|
|
8040
|
+
...copied,
|
|
7567
8041
|
id: createUUIDv7After(floor ?? null, updatedAtMs),
|
|
7568
8042
|
revision: 1,
|
|
7569
8043
|
scope_key: targetScope.scopeKey,
|
|
@@ -7578,7 +8052,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
7578
8052
|
}
|
|
7579
8053
|
},
|
|
7580
8054
|
updatedAtMs
|
|
7581
|
-
});
|
|
8055
|
+
}, labels);
|
|
7582
8056
|
return {
|
|
7583
8057
|
source: moved === null ? null : mutationResult(moved),
|
|
7584
8058
|
target: mutationResult(target)
|
|
@@ -7596,6 +8070,38 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
7596
8070
|
});
|
|
7597
8071
|
},
|
|
7598
8072
|
preflightReleaseCatalogRebuild: (scopeKey) => preflightRebuild(db, scopeKey, now()),
|
|
8073
|
+
fillReleaseLabels: async ({ dryRun = false, catalogs = true } = {}) => {
|
|
8074
|
+
let releases = 0;
|
|
8075
|
+
const pairs = await pendingLabelPairs(db);
|
|
8076
|
+
if (dryRun && pairs[0] !== void 0) await probeLabelSchema(db, pairs[0]);
|
|
8077
|
+
for (const pair of pairs) releases += await fillLabels(db, pair, { dryRun });
|
|
8078
|
+
let rebuilt = 0;
|
|
8079
|
+
if (catalogs) {
|
|
8080
|
+
let cursor;
|
|
8081
|
+
do {
|
|
8082
|
+
const page = await db.findMany("release_catalogs", {
|
|
8083
|
+
index: "all",
|
|
8084
|
+
where: {},
|
|
8085
|
+
limit: CATALOG_PAGE,
|
|
8086
|
+
...cursor === void 0 ? {} : { cursor }
|
|
8087
|
+
});
|
|
8088
|
+
for (const row of page.rows) {
|
|
8089
|
+
if (row.is_tombstone) continue;
|
|
8090
|
+
const preflight = await preflightRebuild(db, row.scope_key, now()).catch(() => null);
|
|
8091
|
+
if (preflight === null || !preflight.labelsOnly) continue;
|
|
8092
|
+
rebuilt += 1;
|
|
8093
|
+
if (dryRun) continue;
|
|
8094
|
+
const updatedAtMs = now();
|
|
8095
|
+
await db.transaction((tx) => rebuildScope(tx, catalogRowScope(toCatalogRow(row)), updatedAtMs));
|
|
8096
|
+
}
|
|
8097
|
+
cursor = page.next;
|
|
8098
|
+
} while (cursor !== void 0);
|
|
8099
|
+
}
|
|
8100
|
+
return {
|
|
8101
|
+
releases,
|
|
8102
|
+
catalogs: rebuilt
|
|
8103
|
+
};
|
|
8104
|
+
},
|
|
7599
8105
|
ensureChannel,
|
|
7600
8106
|
deleteChannel: (id) => deleteChannel(db, id),
|
|
7601
8107
|
updateBundle: (id, update) => db.transaction(async (tx) => {
|
|
@@ -8166,6 +8672,30 @@ const createAdminRouteHandlers = () => ({
|
|
|
8166
8672
|
return row === null ? notFound() : json$2({ data: row });
|
|
8167
8673
|
}),
|
|
8168
8674
|
rebuildReleaseCatalog: onCore(async (core, _request, params) => json$2({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
|
|
8675
|
+
/**
|
|
8676
|
+
* The release a label names, or `null`: never 404, which tells a client
|
|
8677
|
+
* the server has no such route.
|
|
8678
|
+
*/
|
|
8679
|
+
getReleaseByLabel: onCore(async (core, request) => {
|
|
8680
|
+
const url = new URL(request.url);
|
|
8681
|
+
const channel = url.searchParams.get("channel");
|
|
8682
|
+
const platform = platformOf(url);
|
|
8683
|
+
const label = Number(url.searchParams.get("label"));
|
|
8684
|
+
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.");
|
|
8685
|
+
return json$2({ data: await core.getReleaseByLabel({
|
|
8686
|
+
channel,
|
|
8687
|
+
platform,
|
|
8688
|
+
label
|
|
8689
|
+
}) });
|
|
8690
|
+
}),
|
|
8691
|
+
fillReleaseLabels: onCore(async (core, request) => {
|
|
8692
|
+
const body = await request.json().catch(() => ({}));
|
|
8693
|
+
const input = body !== null && typeof body === "object" ? body : {};
|
|
8694
|
+
return json$2({ data: await core.fillReleaseLabels({
|
|
8695
|
+
dryRun: input.dryRun === true,
|
|
8696
|
+
catalogs: input.catalogs !== false
|
|
8697
|
+
}) });
|
|
8698
|
+
}),
|
|
8169
8699
|
updateBundle: onCore(async (core, request, params) => {
|
|
8170
8700
|
const bundleId = requireRouteParam(params, "id");
|
|
8171
8701
|
const update = bundleUpdateOf(await request.json(), bundleId);
|
|
@@ -8393,6 +8923,16 @@ const ADMIN_ROUTES = [
|
|
|
8393
8923
|
path: "/release-scopes",
|
|
8394
8924
|
handler: "listReleaseScopeKeys"
|
|
8395
8925
|
},
|
|
8926
|
+
{
|
|
8927
|
+
method: "GET",
|
|
8928
|
+
path: "/release-labels",
|
|
8929
|
+
handler: "getReleaseByLabel"
|
|
8930
|
+
},
|
|
8931
|
+
{
|
|
8932
|
+
method: "POST",
|
|
8933
|
+
path: "/release-labels/fill",
|
|
8934
|
+
handler: "fillReleaseLabels"
|
|
8935
|
+
},
|
|
8396
8936
|
{
|
|
8397
8937
|
method: "POST",
|
|
8398
8938
|
path: "/release-catalogs/:scopeKey/rebuild",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/aws",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.51",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"es-toolkit": "^1.32.0",
|
|
46
46
|
"execa": "9.5.2",
|
|
47
47
|
"mime": "^4.0.4",
|
|
48
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
49
|
-
"@hot-updater/mock": "1.2.0-rc.
|
|
50
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
48
|
+
"@hot-updater/protocol": "1.2.0-rc.51",
|
|
49
|
+
"@hot-updater/mock": "1.2.0-rc.51",
|
|
50
|
+
"@hot-updater/test-utils": "1.2.0-rc.51"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@aws-sdk/client-cloudfront": "3.1066.0",
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
"@aws-sdk/lib-dynamodb": "3.1066.0",
|
|
65
65
|
"@aws-sdk/s3-request-presigner": "3.1066.0",
|
|
66
66
|
"hono": "4.12.34",
|
|
67
|
-
"@hot-updater/
|
|
68
|
-
"@hot-updater/
|
|
69
|
-
"@hot-updater/
|
|
70
|
-
"@hot-updater/
|
|
67
|
+
"@hot-updater/cli-tools": "1.2.0-rc.51",
|
|
68
|
+
"@hot-updater/plugin-core": "1.2.0-rc.51",
|
|
69
|
+
"@hot-updater/server": "1.2.0-rc.51",
|
|
70
|
+
"@hot-updater/storage-s3": "1.2.0-rc.51"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "tsdown",
|