@hot-updater/azure 1.2.0-rc.50 → 1.2.0-rc.52
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/functions/index.mjs +573 -53
- package/dist/index.cjs +6 -4
- package/dist/index.mjs +6 -4
- package/dist/init/index.cjs +1 -0
- package/dist/init/index.mjs +2 -1
- package/package.json +6 -6
package/dist/functions/index.mjs
CHANGED
|
@@ -4413,7 +4413,8 @@ const releaseRowToRelease = (row) => ({
|
|
|
4413
4413
|
operation: row.operation,
|
|
4414
4414
|
sourceReleaseId: row.source_release_id,
|
|
4415
4415
|
createdAtMs: row.created_at_ms,
|
|
4416
|
-
updatedAtMs: row.updated_at_ms
|
|
4416
|
+
updatedAtMs: row.updated_at_ms,
|
|
4417
|
+
label: row.label ?? null
|
|
4417
4418
|
});
|
|
4418
4419
|
const bundleToRow = (bundle) => {
|
|
4419
4420
|
const metadata = bundleMetadataToRow(bundle.metadata);
|
|
@@ -4922,7 +4923,7 @@ function rangeToIntervals(range) {
|
|
|
4922
4923
|
throw new ReleaseCatalogCompilationError("INVALID_TARGET_RANGE", `Invalid target app-version range: ${range}`);
|
|
4923
4924
|
}
|
|
4924
4925
|
}
|
|
4925
|
-
function releaseDescriptor(release) {
|
|
4926
|
+
function releaseDescriptor(release, labels) {
|
|
4926
4927
|
return {
|
|
4927
4928
|
releaseId: release.id,
|
|
4928
4929
|
kind: release.kind,
|
|
@@ -4930,7 +4931,8 @@ function releaseDescriptor(release) {
|
|
|
4930
4931
|
rolloutCohortCount: release.rolloutCohortCount,
|
|
4931
4932
|
targetCohorts: [...new Set(release.targetCohorts)].sort(),
|
|
4932
4933
|
shouldForceUpdate: release.shouldForceUpdate,
|
|
4933
|
-
message: release.message
|
|
4934
|
+
message: release.message,
|
|
4935
|
+
...labels && typeof release.label === "number" ? { label: release.label } : {}
|
|
4934
4936
|
};
|
|
4935
4937
|
}
|
|
4936
4938
|
function validateReleases(releases, strategy) {
|
|
@@ -5138,17 +5140,84 @@ function canonicalStringify(value) {
|
|
|
5138
5140
|
const record = value;
|
|
5139
5141
|
return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonicalStringify(record[key])}`).join(",")}}`;
|
|
5140
5142
|
}
|
|
5143
|
+
const BOUND_SHAPE = {
|
|
5144
|
+
inclusive: null,
|
|
5145
|
+
version: null
|
|
5146
|
+
};
|
|
5147
|
+
const COMPILED_CATALOG_SHAPE = {
|
|
5148
|
+
fallbackPolicy: null,
|
|
5149
|
+
schemaVersion: null,
|
|
5150
|
+
strategy: null,
|
|
5151
|
+
releaseIndexes: null,
|
|
5152
|
+
rollbackReleaseIndexes: null,
|
|
5153
|
+
segments: {
|
|
5154
|
+
lower: BOUND_SHAPE,
|
|
5155
|
+
upper: BOUND_SHAPE,
|
|
5156
|
+
releaseIndexes: null,
|
|
5157
|
+
rollbackReleaseIndexes: null
|
|
5158
|
+
},
|
|
5159
|
+
releaseDescriptors: {
|
|
5160
|
+
releaseId: null,
|
|
5161
|
+
kind: null,
|
|
5162
|
+
bundleId: null,
|
|
5163
|
+
rolloutCohortCount: null,
|
|
5164
|
+
targetCohorts: null,
|
|
5165
|
+
shouldForceUpdate: null,
|
|
5166
|
+
message: null,
|
|
5167
|
+
label: null
|
|
5168
|
+
}
|
|
5169
|
+
};
|
|
5170
|
+
function readCompiledCatalogPayload(payload) {
|
|
5171
|
+
let fromLaterRelease = false;
|
|
5172
|
+
const known = (value, shape) => {
|
|
5173
|
+
if (Array.isArray(value)) return value.map((item) => known(item, shape));
|
|
5174
|
+
if (value === null || typeof value !== "object") return value;
|
|
5175
|
+
const entries = Object.entries(value).filter(([key]) => {
|
|
5176
|
+
if (Object.hasOwn(shape, key)) return true;
|
|
5177
|
+
fromLaterRelease = true;
|
|
5178
|
+
return false;
|
|
5179
|
+
});
|
|
5180
|
+
return Object.fromEntries(entries.map(([key, entry]) => {
|
|
5181
|
+
const inner = shape[key];
|
|
5182
|
+
return [key, inner === null ? entry : known(entry, inner)];
|
|
5183
|
+
}));
|
|
5184
|
+
};
|
|
5185
|
+
let parsed;
|
|
5186
|
+
try {
|
|
5187
|
+
parsed = JSON.parse(payload);
|
|
5188
|
+
} catch {
|
|
5189
|
+
parsed = null;
|
|
5190
|
+
}
|
|
5191
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return {
|
|
5192
|
+
canonicalPayload: payload,
|
|
5193
|
+
fromLaterRelease: false
|
|
5194
|
+
};
|
|
5195
|
+
if ("schemaVersion" in parsed && typeof parsed.schemaVersion === "number" && parsed.schemaVersion > 1) fromLaterRelease = true;
|
|
5196
|
+
return {
|
|
5197
|
+
canonicalPayload: canonicalStringify(known(parsed, COMPILED_CATALOG_SHAPE)),
|
|
5198
|
+
fromLaterRelease
|
|
5199
|
+
};
|
|
5200
|
+
}
|
|
5141
5201
|
async function compileReleaseCatalog(input) {
|
|
5142
5202
|
const releases = validateReleases(input.releases, input.strategy);
|
|
5143
5203
|
const targetCohorts = new Set(releases.flatMap((release) => release.targetCohorts));
|
|
5144
5204
|
if (targetCohorts.size > 512) throw new ReleaseCatalogCompilationError("DISTINCT_TARGET_COHORT_LIMIT", `Scope exceeds 512 distinct target cohorts`);
|
|
5145
5205
|
const { envelope, retainedReleases } = input.strategy === "APP_VERSION" ? compileAppVersion(releases) : compileFingerprint(releases);
|
|
5146
|
-
const
|
|
5147
|
-
|
|
5148
|
-
|
|
5206
|
+
const compile = (labels) => {
|
|
5207
|
+
const payload = {
|
|
5208
|
+
...envelope,
|
|
5209
|
+
releaseDescriptors: retainedReleases.map((release) => releaseDescriptor(release, labels))
|
|
5210
|
+
};
|
|
5211
|
+
const canonicalPayload = canonicalStringify(payload);
|
|
5212
|
+
return {
|
|
5213
|
+
payload,
|
|
5214
|
+
canonicalPayload,
|
|
5215
|
+
byteSize: new TextEncoder().encode(canonicalPayload).byteLength
|
|
5216
|
+
};
|
|
5149
5217
|
};
|
|
5150
|
-
|
|
5151
|
-
|
|
5218
|
+
let compiled = compile(true);
|
|
5219
|
+
if (compiled.byteSize > 262144 && retainedReleases.some((release) => typeof release.label === "number")) compiled = compile(false);
|
|
5220
|
+
const { payload, canonicalPayload, byteSize } = compiled;
|
|
5152
5221
|
if (byteSize > 262144) throw new ReleaseCatalogCompilationError("CATALOG_OVERSIZE", `Compiled Release catalog is ${byteSize} bytes; maximum is ${MAX_COMPILED_CATALOG_BYTES}`);
|
|
5153
5222
|
return {
|
|
5154
5223
|
byteSize,
|
|
@@ -5632,6 +5701,18 @@ const SETTINGS_TABLE = {
|
|
|
5632
5701
|
};
|
|
5633
5702
|
const ENGINE_SCHEMA_KEY = "schema.engine";
|
|
5634
5703
|
const CORE_SCHEMA_KEY = "schema.core";
|
|
5704
|
+
const compareVersions = (left, right) => {
|
|
5705
|
+
const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
|
|
5706
|
+
const [a, b] = [parse(left), parse(right)];
|
|
5707
|
+
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
5708
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
5709
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
5710
|
+
if (difference !== 0) return difference;
|
|
5711
|
+
}
|
|
5712
|
+
return 0;
|
|
5713
|
+
};
|
|
5714
|
+
const newerCore = (settings) => settings.find(({ key, expected, found }) => key === CORE_SCHEMA_KEY && found !== null && compareVersions(found, expected) > 0);
|
|
5715
|
+
const newerMessage = (adapterName, { key, expected, found }) => `Hot Updater schema setting "${key}" for ${adapterName} is "${found}"; expected "${expected}". The database was migrated by Hot Updater ${found}: upgrade hot-updater and the @hot-updater packages to ${found} or later.`;
|
|
5635
5716
|
const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
|
|
5636
5717
|
const MIGRATE_SCHEMA_FIX = "Run `npx hot-updater doctor` in the project whose hot-updater.config.ts names this database: it names the command that migrates it. In a server project, `hot-updater db migrate` migrates the database its server file names.";
|
|
5637
5718
|
const settingMessage = (adapterName, { key, expected, found }) => `Hot Updater schema setting "${key}" for ${adapterName} is ${found === null ? "missing" : `"${found}"`}; expected "${expected}". ${MIGRATE_SCHEMA_FIX}`;
|
|
@@ -5648,7 +5729,8 @@ var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
|
5648
5729
|
constructor(adapterName, currentVersion, setting, options) {
|
|
5649
5730
|
const settings = options?.settings ?? (setting === void 0 ? [] : [setting]);
|
|
5650
5731
|
const plugins = settings.flatMap((mismatch) => pluginOf(mismatch) ?? []);
|
|
5651
|
-
|
|
5732
|
+
const newer = newerCore(settings);
|
|
5733
|
+
super(newer !== void 0 ? newerMessage(adapterName, newer) : setting === void 0 ? currentVersion === void 0 ? `Hot Updater database schema is not initialized for ${adapterName}. ${MIGRATE_SCHEMA_FIX}` : `Hot Updater v1 cannot migrate schema ${currentVersion} in place. Create a new empty database and run \`hot-updater db migrate\`.` : plugins.length > 0 && plugins.length === settings.length ? pluginsMessage(adapterName, plugins, settings, options?.fix ?? MIGRATE_SCHEMA_FIX) : settings.length > 1 && !(setting.key === "schema.engine" && setting.found === null) ? settingsMessage(adapterName, settings) : settingMessage(adapterName, setting), options?.cause === void 0 ? void 0 : { cause: options.cause });
|
|
5652
5734
|
this.adapterName = adapterName;
|
|
5653
5735
|
this.currentVersion = currentVersion;
|
|
5654
5736
|
this.setting = setting;
|
|
@@ -5891,7 +5973,11 @@ const releases = defineTable({
|
|
|
5891
5973
|
}
|
|
5892
5974
|
},
|
|
5893
5975
|
created_at_ms: { type: "integer" },
|
|
5894
|
-
updated_at_ms: { type: "integer" }
|
|
5976
|
+
updated_at_ms: { type: "integer" },
|
|
5977
|
+
label: {
|
|
5978
|
+
type: "integer",
|
|
5979
|
+
required: false
|
|
5980
|
+
}
|
|
5895
5981
|
}, {
|
|
5896
5982
|
key: ["id"],
|
|
5897
5983
|
indexes: {
|
|
@@ -5928,6 +6014,15 @@ const releases = defineTable({
|
|
|
5928
6014
|
scopes: {
|
|
5929
6015
|
eq: [],
|
|
5930
6016
|
sort: ["scope_key"]
|
|
6017
|
+
},
|
|
6018
|
+
byLabel: {
|
|
6019
|
+
eq: [
|
|
6020
|
+
"channel_id",
|
|
6021
|
+
"platform",
|
|
6022
|
+
"label"
|
|
6023
|
+
],
|
|
6024
|
+
sort: [],
|
|
6025
|
+
unique: true
|
|
5931
6026
|
}
|
|
5932
6027
|
}
|
|
5933
6028
|
});
|
|
@@ -5935,6 +6030,25 @@ const LATE_INDEXES = [{
|
|
|
5935
6030
|
table: "releases",
|
|
5936
6031
|
index: "scopes"
|
|
5937
6032
|
}];
|
|
6033
|
+
const LATE_COLUMNS = [{
|
|
6034
|
+
table: "releases",
|
|
6035
|
+
column: "label"
|
|
6036
|
+
}];
|
|
6037
|
+
const labelSequences = defineTable({
|
|
6038
|
+
id: {
|
|
6039
|
+
type: "string",
|
|
6040
|
+
maxLength: 1440,
|
|
6041
|
+
ascii: true
|
|
6042
|
+
},
|
|
6043
|
+
last_label: { type: "integer" },
|
|
6044
|
+
is_filled: { type: "boolean" }
|
|
6045
|
+
}, {
|
|
6046
|
+
key: ["id"],
|
|
6047
|
+
indexes: { all: {
|
|
6048
|
+
eq: [],
|
|
6049
|
+
sort: ["id"]
|
|
6050
|
+
} }
|
|
6051
|
+
});
|
|
5938
6052
|
const releaseCatalogs = defineTable({
|
|
5939
6053
|
scope_key: {
|
|
5940
6054
|
type: "string",
|
|
@@ -6241,7 +6355,8 @@ const coreModule = {
|
|
|
6241
6355
|
}),
|
|
6242
6356
|
native_builds: nativeBuilds,
|
|
6243
6357
|
ios_devices: iosDevices,
|
|
6244
|
-
ios_device_account: iosDeviceAccount
|
|
6358
|
+
ios_device_account: iosDeviceAccount,
|
|
6359
|
+
label_sequences: labelSequences
|
|
6245
6360
|
}
|
|
6246
6361
|
};
|
|
6247
6362
|
//#endregion
|
|
@@ -6262,16 +6377,6 @@ const refuseV0Database = (adapterName, stored) => {
|
|
|
6262
6377
|
if (typeof version !== "string" || stored.has("schema.engine")) return;
|
|
6263
6378
|
throw new HotUpdaterSchemaMigrationRequiredError(adapterName, version);
|
|
6264
6379
|
};
|
|
6265
|
-
const compareVersions = (left, right) => {
|
|
6266
|
-
const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
|
|
6267
|
-
const [a, b] = [parse(left), parse(right)];
|
|
6268
|
-
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
6269
|
-
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
6270
|
-
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
6271
|
-
if (difference !== 0) return difference;
|
|
6272
|
-
}
|
|
6273
|
-
return 0;
|
|
6274
|
-
};
|
|
6275
6380
|
const DEFAULT_ORDERED_SETTINGS = ["schema.core"];
|
|
6276
6381
|
const refuseNewerSchema = (adapterName, stored, settings, ordered = DEFAULT_ORDERED_SETTINGS) => {
|
|
6277
6382
|
const newer = ordered.flatMap((key) => {
|
|
@@ -6338,10 +6443,23 @@ const fillLateIndexes = async (adapter, tables, { dryRun = false } = {}) => {
|
|
|
6338
6443
|
}
|
|
6339
6444
|
return lacking;
|
|
6340
6445
|
};
|
|
6446
|
+
const addLateColumns = async (adapter, tables, { dryRun = false } = {}) => {
|
|
6447
|
+
const addColumns = adapter.migrations?.addColumns;
|
|
6448
|
+
if (addColumns === void 0) return [];
|
|
6449
|
+
const lacking = [];
|
|
6450
|
+
for (const table of tables) {
|
|
6451
|
+
const columns = LATE_COLUMNS.filter(({ table: name }) => name === table.name).map(({ column }) => column);
|
|
6452
|
+
if (columns.length === 0) continue;
|
|
6453
|
+
const added = await addColumns(table, columns, { dryRun });
|
|
6454
|
+
lacking.push(...added.map((column) => `${table.name}.${column}`));
|
|
6455
|
+
}
|
|
6456
|
+
return lacking;
|
|
6457
|
+
};
|
|
6341
6458
|
const migrateSchema = async (adapter, adapterName, tables, settings, ordered) => {
|
|
6342
6459
|
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
6343
6460
|
const stored = await storedSettings(adapter, Object.keys(settings)).catch(() => void 0);
|
|
6344
6461
|
if (stored !== void 0) refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
6462
|
+
await addLateColumns(adapter, tables);
|
|
6345
6463
|
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
6346
6464
|
await fillLateIndexes(adapter, tables);
|
|
6347
6465
|
await writeSchemaSettings(adapter, adapterName, settings, ordered);
|
|
@@ -7233,23 +7351,45 @@ const createEngineMigrator = (options) => {
|
|
|
7233
7351
|
refuseNewerSchema(options.adapterName, stored, options.settings, options.ordered);
|
|
7234
7352
|
const changed = Object.entries(options.settings).filter(([key, value]) => stored.get(key) !== value);
|
|
7235
7353
|
if (changed.length === 0) {
|
|
7354
|
+
const columns = await addLateColumns(options.adapter, options.schema.tables, { dryRun: true });
|
|
7236
7355
|
const lacking = await fillLateIndexes(options.adapter, options.schema.tables, { dryRun: true });
|
|
7237
|
-
if (lacking.length === 0) return getEmptyMigrationResult();
|
|
7356
|
+
if (columns.length === 0 && lacking.length === 0) return getEmptyMigrationResult();
|
|
7238
7357
|
return {
|
|
7239
|
-
operations: [
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7358
|
+
operations: [
|
|
7359
|
+
...columns.map((column) => ({
|
|
7360
|
+
type: "custom",
|
|
7361
|
+
description: `Add column: ${column}`
|
|
7362
|
+
})),
|
|
7363
|
+
...columns.length === 0 ? [] : [{
|
|
7364
|
+
type: "custom",
|
|
7365
|
+
description: "Create the tables and indexes the database lacks"
|
|
7366
|
+
}],
|
|
7367
|
+
...lacking.length === 0 ? [] : [{
|
|
7368
|
+
type: "custom",
|
|
7369
|
+
description: `Write the index items rows lack: ${lacking.join(", ")}`
|
|
7370
|
+
}]
|
|
7371
|
+
],
|
|
7243
7372
|
execute: async () => {
|
|
7373
|
+
if (columns.length > 0) {
|
|
7374
|
+
await addLateColumns(options.adapter, options.schema.tables);
|
|
7375
|
+
await options.adapter.migrations.apply([...options.schema.tables, SETTINGS_TABLE]);
|
|
7376
|
+
}
|
|
7244
7377
|
await fillLateIndexes(options.adapter, options.schema.tables);
|
|
7245
7378
|
}
|
|
7246
7379
|
};
|
|
7247
7380
|
}
|
|
7248
7381
|
return {
|
|
7249
|
-
operations: [
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
|
|
7382
|
+
operations: [
|
|
7383
|
+
...(await addLateColumns(options.adapter, options.schema.tables, { dryRun: true }).catch(() => [])).map((column) => ({
|
|
7384
|
+
type: "custom",
|
|
7385
|
+
description: `Add column: ${column}`
|
|
7386
|
+
})),
|
|
7387
|
+
{
|
|
7388
|
+
type: "custom",
|
|
7389
|
+
description: "Create the tables and indexes the database lacks"
|
|
7390
|
+
},
|
|
7391
|
+
...migrate.updateSettings === false ? [] : [settingsOperation(stored, changed)]
|
|
7392
|
+
],
|
|
7253
7393
|
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings, options.ordered)
|
|
7254
7394
|
};
|
|
7255
7395
|
};
|
|
@@ -8344,7 +8484,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
8344
8484
|
};
|
|
8345
8485
|
//#endregion
|
|
8346
8486
|
//#region ../../packages/server/dist/version.mjs
|
|
8347
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
8487
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.52";
|
|
8348
8488
|
//#endregion
|
|
8349
8489
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
8350
8490
|
const createVersionRouteHandlers = (plugins = []) => {
|
|
@@ -9082,7 +9222,7 @@ const baseBundleIdsOf = (row, range, bundleId, limit) => {
|
|
|
9082
9222
|
};
|
|
9083
9223
|
//#endregion
|
|
9084
9224
|
//#region ../../packages/server/dist/core/reads.mjs
|
|
9085
|
-
const PAGE$
|
|
9225
|
+
const PAGE$4 = 500;
|
|
9086
9226
|
const pick$2 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
|
|
9087
9227
|
const toBundleRow = pick$2([
|
|
9088
9228
|
"id",
|
|
@@ -9103,7 +9243,7 @@ const toPatchRow = pick$2([
|
|
|
9103
9243
|
"byte_size",
|
|
9104
9244
|
"order_index"
|
|
9105
9245
|
]);
|
|
9106
|
-
const
|
|
9246
|
+
const pickReleaseRow = pick$2([
|
|
9107
9247
|
"id",
|
|
9108
9248
|
"revision",
|
|
9109
9249
|
"scope_key",
|
|
@@ -9124,6 +9264,12 @@ const toReleaseRow = pick$2([
|
|
|
9124
9264
|
"created_at_ms",
|
|
9125
9265
|
"updated_at_ms"
|
|
9126
9266
|
]);
|
|
9267
|
+
const toReleaseRow = (row) => {
|
|
9268
|
+
return {
|
|
9269
|
+
...pickReleaseRow(row),
|
|
9270
|
+
label: typeof row.label === "number" ? row.label : null
|
|
9271
|
+
};
|
|
9272
|
+
};
|
|
9127
9273
|
const toCatalogRow = pick$2([
|
|
9128
9274
|
"scope_key",
|
|
9129
9275
|
"catalog_id",
|
|
@@ -9167,7 +9313,7 @@ const createCoreReads = (db, storage) => {
|
|
|
9167
9313
|
const page = await db.findMany("bundle_patches", {
|
|
9168
9314
|
index: "byBundle",
|
|
9169
9315
|
where: { bundle_id: row.id },
|
|
9170
|
-
limit: Math.min(count - patches.length, PAGE$
|
|
9316
|
+
limit: Math.min(count - patches.length, PAGE$4),
|
|
9171
9317
|
...cursor === void 0 ? {} : { cursor }
|
|
9172
9318
|
});
|
|
9173
9319
|
patches.push(...page.rows.map(toPatchRow));
|
|
@@ -9268,6 +9414,18 @@ const createCoreReads = (db, storage) => {
|
|
|
9268
9414
|
const row = await db.findOne("releases", { id });
|
|
9269
9415
|
return row === null ? null : toReleaseRow(row);
|
|
9270
9416
|
},
|
|
9417
|
+
async getReleaseByLabel({ channel, platform, label }) {
|
|
9418
|
+
const found = await db.findOne("releases", {
|
|
9419
|
+
channel_id: `channel:${encodeChannelKey(channel)}`,
|
|
9420
|
+
platform,
|
|
9421
|
+
label
|
|
9422
|
+
});
|
|
9423
|
+
if (found === null) return null;
|
|
9424
|
+
const row = await db.findOne("releases", { id: found.id });
|
|
9425
|
+
if (row === null) return null;
|
|
9426
|
+
const release = toReleaseRow(row);
|
|
9427
|
+
return release.label === label && release.platform === platform ? release : null;
|
|
9428
|
+
},
|
|
9271
9429
|
async listReleases(input) {
|
|
9272
9430
|
const { filter } = input;
|
|
9273
9431
|
const options = {
|
|
@@ -9359,7 +9517,7 @@ const createCoreReads = (db, storage) => {
|
|
|
9359
9517
|
return (await drain$1((page) => db.findMany("channels", {
|
|
9360
9518
|
index: "all",
|
|
9361
9519
|
where: {},
|
|
9362
|
-
limit: PAGE$
|
|
9520
|
+
limit: PAGE$4,
|
|
9363
9521
|
...page
|
|
9364
9522
|
}))).map(toChannelRow);
|
|
9365
9523
|
},
|
|
@@ -9658,6 +9816,269 @@ const NATIVE_BUILD_SUBMISSION_DESTINATIONS = {
|
|
|
9658
9816
|
ios: ["testflight"]
|
|
9659
9817
|
};
|
|
9660
9818
|
//#endregion
|
|
9819
|
+
//#region ../../packages/server/dist/core/labels.mjs
|
|
9820
|
+
const labelSequenceId = (channelId, platform) => `releases/${platform}/${channelId}`;
|
|
9821
|
+
const LABEL_PLATFORMS = ["ios", "android"];
|
|
9822
|
+
var NeedsLabelFill = class extends Error {
|
|
9823
|
+
channelId;
|
|
9824
|
+
platform;
|
|
9825
|
+
constructor(channelId, platform) {
|
|
9826
|
+
super(`Release labels of ${platform} ${channelId} need a fill first.`);
|
|
9827
|
+
this.channelId = channelId;
|
|
9828
|
+
this.platform = platform;
|
|
9829
|
+
}
|
|
9830
|
+
};
|
|
9831
|
+
const createLabelAllocator = (tx, used, caughtUp) => {
|
|
9832
|
+
const sequences = /* @__PURE__ */ new Map();
|
|
9833
|
+
return {
|
|
9834
|
+
async next(channelId, platform) {
|
|
9835
|
+
const id = labelSequenceId(channelId, platform);
|
|
9836
|
+
let sequence = sequences.get(id);
|
|
9837
|
+
if (sequence === void 0) {
|
|
9838
|
+
const row = await tx.findOne("label_sequences", { id });
|
|
9839
|
+
if (row === null || !row.is_filled) {
|
|
9840
|
+
const channel = row === null ? await tx.findOne("channels", { id: channelId }) : null;
|
|
9841
|
+
if (channel === null || (channel._refs_releases_channel_id ?? 0) > 0) throw new NeedsLabelFill(channelId, platform);
|
|
9842
|
+
}
|
|
9843
|
+
const read = row?.last_label ?? 0;
|
|
9844
|
+
sequence = {
|
|
9845
|
+
row,
|
|
9846
|
+
read,
|
|
9847
|
+
last: read
|
|
9848
|
+
};
|
|
9849
|
+
sequences.set(id, sequence);
|
|
9850
|
+
used.set(id, {
|
|
9851
|
+
channelId,
|
|
9852
|
+
platform,
|
|
9853
|
+
read
|
|
9854
|
+
});
|
|
9855
|
+
}
|
|
9856
|
+
sequence.last += 1;
|
|
9857
|
+
return sequence.last;
|
|
9858
|
+
},
|
|
9859
|
+
caughtUp(channelId, platform) {
|
|
9860
|
+
caughtUp.set(labelSequenceId(channelId, platform), {
|
|
9861
|
+
channelId,
|
|
9862
|
+
platform
|
|
9863
|
+
});
|
|
9864
|
+
},
|
|
9865
|
+
flush() {
|
|
9866
|
+
for (const [id, { row, read, last }] of sequences) if (row === null) tx.create("label_sequences", {
|
|
9867
|
+
id,
|
|
9868
|
+
last_label: last,
|
|
9869
|
+
is_filled: true
|
|
9870
|
+
});
|
|
9871
|
+
else if (last !== read) tx.update("label_sequences", row, { last_label: last });
|
|
9872
|
+
}
|
|
9873
|
+
};
|
|
9874
|
+
};
|
|
9875
|
+
const FILL_BATCH = 25;
|
|
9876
|
+
const PAGE$3 = 500;
|
|
9877
|
+
const fillLabels = async (db, { channelId, platform }, { dryRun = false } = {}) => {
|
|
9878
|
+
const id = labelSequenceId(channelId, platform);
|
|
9879
|
+
let labeled = 0;
|
|
9880
|
+
let batchSize = FILL_BATCH;
|
|
9881
|
+
const label = async (ids) => {
|
|
9882
|
+
for (let at = 0; at < ids.length;) {
|
|
9883
|
+
const batch = ids.slice(at, at + batchSize);
|
|
9884
|
+
try {
|
|
9885
|
+
labeled += await db.transaction(async (tx) => {
|
|
9886
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
9887
|
+
let last = counter?.last_label ?? 0;
|
|
9888
|
+
let count = 0;
|
|
9889
|
+
for (const releaseId of batch) {
|
|
9890
|
+
const row = await tx.findOne("releases", { id: releaseId });
|
|
9891
|
+
if (row === null || typeof row.label === "number") continue;
|
|
9892
|
+
last += 1;
|
|
9893
|
+
count += 1;
|
|
9894
|
+
tx.update("releases", row, { label: last });
|
|
9895
|
+
}
|
|
9896
|
+
if (counter === null) tx.create("label_sequences", {
|
|
9897
|
+
id,
|
|
9898
|
+
last_label: last,
|
|
9899
|
+
is_filled: false
|
|
9900
|
+
});
|
|
9901
|
+
else if (last !== counter.last_label) tx.update("label_sequences", counter, { last_label: last });
|
|
9902
|
+
return count;
|
|
9903
|
+
});
|
|
9904
|
+
at += batch.length;
|
|
9905
|
+
} catch (error) {
|
|
9906
|
+
if (batchSize > 1 && error instanceof DatabaseConstraintError && error.reason === "too_large") {
|
|
9907
|
+
batchSize = Math.max(1, Math.floor(batchSize / 2));
|
|
9908
|
+
continue;
|
|
9909
|
+
}
|
|
9910
|
+
throw error;
|
|
9911
|
+
}
|
|
9912
|
+
}
|
|
9913
|
+
};
|
|
9914
|
+
let cursor;
|
|
9915
|
+
do {
|
|
9916
|
+
const page = await db.findMany("releases", {
|
|
9917
|
+
index: "byChannelPlatform",
|
|
9918
|
+
where: {
|
|
9919
|
+
channel_id: channelId,
|
|
9920
|
+
platform
|
|
9921
|
+
},
|
|
9922
|
+
limit: PAGE$3,
|
|
9923
|
+
...cursor === void 0 ? {} : { cursor }
|
|
9924
|
+
});
|
|
9925
|
+
const unlabeled = page.rows.filter((row) => typeof row.label !== "number").map((row) => row.id);
|
|
9926
|
+
if (dryRun) labeled += unlabeled.length;
|
|
9927
|
+
else await label(unlabeled);
|
|
9928
|
+
cursor = page.next;
|
|
9929
|
+
} while (cursor !== void 0);
|
|
9930
|
+
if (dryRun) return labeled;
|
|
9931
|
+
await db.transaction(async (tx) => {
|
|
9932
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
9933
|
+
if (counter === null) tx.create("label_sequences", {
|
|
9934
|
+
id,
|
|
9935
|
+
last_label: 0,
|
|
9936
|
+
is_filled: true
|
|
9937
|
+
});
|
|
9938
|
+
else if (!counter.is_filled) tx.update("label_sequences", counter, { is_filled: true });
|
|
9939
|
+
});
|
|
9940
|
+
return labeled;
|
|
9941
|
+
};
|
|
9942
|
+
const probeLabelSchema = async (db, { channelId, platform }) => {
|
|
9943
|
+
await db.findOne("label_sequences", { id: labelSequenceId(channelId, platform) });
|
|
9944
|
+
await db.findMany("releases", {
|
|
9945
|
+
index: "byLabel",
|
|
9946
|
+
where: {
|
|
9947
|
+
channel_id: channelId,
|
|
9948
|
+
platform,
|
|
9949
|
+
label: 0
|
|
9950
|
+
},
|
|
9951
|
+
limit: 1
|
|
9952
|
+
});
|
|
9953
|
+
};
|
|
9954
|
+
const REPAIRS = 4;
|
|
9955
|
+
const RACES = 32;
|
|
9956
|
+
const writeWithLabels = async (db, write) => {
|
|
9957
|
+
const filled = /* @__PURE__ */ new Set();
|
|
9958
|
+
const fill = async (pairs) => {
|
|
9959
|
+
for (const pair of pairs) {
|
|
9960
|
+
filled.add(labelSequenceId(pair.channelId, pair.platform));
|
|
9961
|
+
await fillLabels(db, pair);
|
|
9962
|
+
}
|
|
9963
|
+
};
|
|
9964
|
+
for (let repairs = 0, races = 0;;) {
|
|
9965
|
+
const used = /* @__PURE__ */ new Map();
|
|
9966
|
+
const caughtUp = /* @__PURE__ */ new Map();
|
|
9967
|
+
try {
|
|
9968
|
+
return await db.transaction(async (tx) => {
|
|
9969
|
+
used.clear();
|
|
9970
|
+
caughtUp.clear();
|
|
9971
|
+
const labels = createLabelAllocator(tx, used, caughtUp);
|
|
9972
|
+
const result = await write(tx, labels);
|
|
9973
|
+
labels.flush();
|
|
9974
|
+
return result;
|
|
9975
|
+
});
|
|
9976
|
+
} catch (error) {
|
|
9977
|
+
const needs = error instanceof NeedsLabelFill ? [error] : error instanceof DatabaseConstraintError && error.reason === "too_large" ? [...caughtUp.values()] : [];
|
|
9978
|
+
if (needs.length > 0) {
|
|
9979
|
+
const fresh = needs.some(({ channelId, platform }) => !filled.has(labelSequenceId(channelId, platform)));
|
|
9980
|
+
if (fresh || repairs < REPAIRS) {
|
|
9981
|
+
if (!fresh) repairs += 1;
|
|
9982
|
+
await fill(needs);
|
|
9983
|
+
continue;
|
|
9984
|
+
}
|
|
9985
|
+
}
|
|
9986
|
+
if (error instanceof DatabaseConstraintError && error.reason === "unique" && error.model === "releases" && used.size > 0) {
|
|
9987
|
+
if (await db.transaction(async (tx) => {
|
|
9988
|
+
const moves = [];
|
|
9989
|
+
for (const [id, { channelId, read }] of used) {
|
|
9990
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
9991
|
+
if (counter !== null) {
|
|
9992
|
+
if (counter.last_label !== read) return false;
|
|
9993
|
+
moves.push(() => tx.update("label_sequences", counter, { last_label: read + 1 }));
|
|
9994
|
+
continue;
|
|
9995
|
+
}
|
|
9996
|
+
const channel = await tx.findOne("channels", { id: channelId });
|
|
9997
|
+
if (channel === null || (channel._refs_releases_channel_id ?? 0) > 0) return false;
|
|
9998
|
+
moves.push(() => tx.create("label_sequences", {
|
|
9999
|
+
id,
|
|
10000
|
+
last_label: read + 1,
|
|
10001
|
+
is_filled: true
|
|
10002
|
+
}));
|
|
10003
|
+
}
|
|
10004
|
+
for (const move of moves) move();
|
|
10005
|
+
return true;
|
|
10006
|
+
}) ? (repairs += 1) <= REPAIRS : (races += 1) <= RACES) continue;
|
|
10007
|
+
}
|
|
10008
|
+
throw error;
|
|
10009
|
+
}
|
|
10010
|
+
}
|
|
10011
|
+
};
|
|
10012
|
+
const catchUpLabels = async (tx, labels, latest) => {
|
|
10013
|
+
const given = /* @__PURE__ */ new Map();
|
|
10014
|
+
if (latest === null || typeof latest.label === "number") return given;
|
|
10015
|
+
const unlabeled = [];
|
|
10016
|
+
let cursor;
|
|
10017
|
+
scan: do {
|
|
10018
|
+
const page = await tx.findMany("releases", {
|
|
10019
|
+
index: "byScope",
|
|
10020
|
+
where: { scope_key: latest.scope_key },
|
|
10021
|
+
order: "desc",
|
|
10022
|
+
limit: FILL_BATCH,
|
|
10023
|
+
...cursor === void 0 ? {} : { cursor }
|
|
10024
|
+
});
|
|
10025
|
+
for (const row of page.rows) {
|
|
10026
|
+
if (typeof row.label === "number") break scan;
|
|
10027
|
+
unlabeled.push(row);
|
|
10028
|
+
}
|
|
10029
|
+
cursor = page.next;
|
|
10030
|
+
} while (cursor !== void 0);
|
|
10031
|
+
labels.caughtUp(latest.channel_id, latest.platform);
|
|
10032
|
+
for (const row of unlabeled.reverse()) {
|
|
10033
|
+
const { id, channel_id, platform } = toReleaseRow(row);
|
|
10034
|
+
const label = await labels.next(channel_id, platform);
|
|
10035
|
+
tx.update("releases", row, { label });
|
|
10036
|
+
given.set(id, label);
|
|
10037
|
+
}
|
|
10038
|
+
return given;
|
|
10039
|
+
};
|
|
10040
|
+
const pendingLabelPairs = async (db) => {
|
|
10041
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
10042
|
+
for (let last = "";;) {
|
|
10043
|
+
const { rows } = await db.findMany("releases", {
|
|
10044
|
+
index: "scopes",
|
|
10045
|
+
where: {},
|
|
10046
|
+
limit: 1,
|
|
10047
|
+
range: { gt: last }
|
|
10048
|
+
});
|
|
10049
|
+
if (rows[0] === void 0) break;
|
|
10050
|
+
last = rows[0].scope_key;
|
|
10051
|
+
const { rows: newest } = await db.findMany("releases", {
|
|
10052
|
+
index: "byScope",
|
|
10053
|
+
where: { scope_key: last },
|
|
10054
|
+
order: "desc",
|
|
10055
|
+
limit: 1
|
|
10056
|
+
});
|
|
10057
|
+
if (newest[0] === void 0) continue;
|
|
10058
|
+
const { channel_id: channelId, platform, label } = toReleaseRow(newest[0]);
|
|
10059
|
+
const id = labelSequenceId(channelId, platform);
|
|
10060
|
+
const pair = pairs.get(id) ?? {
|
|
10061
|
+
channelId,
|
|
10062
|
+
platform,
|
|
10063
|
+
pending: false
|
|
10064
|
+
};
|
|
10065
|
+
pair.pending ||= label === null;
|
|
10066
|
+
pairs.set(id, pair);
|
|
10067
|
+
}
|
|
10068
|
+
const pending = [];
|
|
10069
|
+
for (const [id, { channelId, platform, pending: unlabeled }] of pairs) {
|
|
10070
|
+
if (!unlabeled) {
|
|
10071
|
+
const counter = await db.findOne("label_sequences", { id });
|
|
10072
|
+
if (counter !== null && counter.is_filled) continue;
|
|
10073
|
+
}
|
|
10074
|
+
pending.push({
|
|
10075
|
+
channelId,
|
|
10076
|
+
platform
|
|
10077
|
+
});
|
|
10078
|
+
}
|
|
10079
|
+
return pending;
|
|
10080
|
+
};
|
|
10081
|
+
//#endregion
|
|
9661
10082
|
//#region ../../packages/server/dist/core/writes.mjs
|
|
9662
10083
|
const PAGE$2 = 500;
|
|
9663
10084
|
const countBundle = (tx, platform, delta) => {
|
|
@@ -9744,6 +10165,10 @@ const deleteChannel = (db, id) => db.transaction(async (tx) => {
|
|
|
9744
10165
|
deleted: false,
|
|
9745
10166
|
reason: "not_empty"
|
|
9746
10167
|
};
|
|
10168
|
+
for (const platform of LABEL_PLATFORMS) {
|
|
10169
|
+
const counter = await tx.findOne("label_sequences", { id: labelSequenceId(id, platform) });
|
|
10170
|
+
if (counter !== null) await tx.delete("label_sequences", counter);
|
|
10171
|
+
}
|
|
9747
10172
|
await tx.delete("channels", row);
|
|
9748
10173
|
return { deleted: true };
|
|
9749
10174
|
});
|
|
@@ -10203,14 +10628,14 @@ const enabledIn = (scopeKey, cursor) => ({
|
|
|
10203
10628
|
...cursor === void 0 ? {} : { cursor }
|
|
10204
10629
|
});
|
|
10205
10630
|
const enabledReleases = (tx, scopeKey) => drainReleases((cursor) => tx.findMany("releases", enabledIn(scopeKey, cursor)));
|
|
10206
|
-
const
|
|
10631
|
+
const latestRelease = async (tx, scopeKey) => {
|
|
10207
10632
|
const { rows } = await tx.findMany("releases", {
|
|
10208
10633
|
index: "byScope",
|
|
10209
10634
|
where: { scope_key: scopeKey },
|
|
10210
10635
|
order: "desc",
|
|
10211
10636
|
limit: 1
|
|
10212
10637
|
});
|
|
10213
|
-
return rows[0]
|
|
10638
|
+
return rows[0] === void 0 ? null : toReleaseRow(rows[0]);
|
|
10214
10639
|
};
|
|
10215
10640
|
const nextCatalog = (scope, stored, compilation, updatedAtMs) => {
|
|
10216
10641
|
const generation = (stored.catalog?.generation ?? 0) + 1;
|
|
@@ -10261,13 +10686,17 @@ const readCatalog = async (tx, scopeKey) => {
|
|
|
10261
10686
|
catalog: row === null ? null : toCatalogRow(row)
|
|
10262
10687
|
};
|
|
10263
10688
|
};
|
|
10689
|
+
const refuseLaterCatalog = (scope, catalog) => {
|
|
10690
|
+
if (catalog !== null && readCompiledCatalogPayload(catalog.payload).fromLaterRelease) fail$1("CATALOG_FROM_LATER_RELEASE", `The ${scope.platform} release catalog of channel "${scope.channelName}" was written by a later Hot Updater.\nUpgrade hot-updater, then try again.`);
|
|
10691
|
+
};
|
|
10264
10692
|
const assertHistory = (stored, hasReleases) => {
|
|
10265
10693
|
if (stored.catalog === null && hasReleases) fail$1("CATALOG_IDENTITY_MISSING", "Catalog history is missing. Restore its catalog row from backup before rebuilding or deploying.");
|
|
10266
10694
|
};
|
|
10267
|
-
const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
10695
|
+
const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }, labels) => {
|
|
10268
10696
|
checkScope(scope);
|
|
10269
10697
|
const stored = await readCatalog(tx, scope.scopeKey);
|
|
10270
|
-
|
|
10698
|
+
refuseLaterCatalog(scope, stored.catalog);
|
|
10699
|
+
let enabled = await enabledReleases(tx, scope.scopeKey);
|
|
10271
10700
|
if (bundle !== void 0) {
|
|
10272
10701
|
insertBundle(tx, bundle.row);
|
|
10273
10702
|
for (const patch of bundle.patches) tx.create("bundle_patches", patch);
|
|
@@ -10275,14 +10704,22 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
10275
10704
|
let before = null;
|
|
10276
10705
|
let release;
|
|
10277
10706
|
if (change.operation === "insert") {
|
|
10278
|
-
|
|
10707
|
+
if (labels === void 0) throw new Error("A release insert takes its label from an allocator.");
|
|
10708
|
+
const newest = await latestRelease(tx, scope.scopeKey);
|
|
10709
|
+
const latest = newest?.id ?? null;
|
|
10279
10710
|
assertHistory(stored, latest !== null);
|
|
10280
10711
|
const floor = [latest, bundle && isUUIDv7(bundle.row.id) ? bundle.row.id : null].filter((id) => id !== null).sort().at(-1);
|
|
10281
10712
|
const id = change.row.id ?? createUUIDv7After(floor ?? null);
|
|
10282
10713
|
if (latest !== null && id <= latest) fail$1("NON_MONOTONIC_RELEASE_ID", `Release "${id}" must sort after "${latest}"`);
|
|
10714
|
+
const given = await catchUpLabels(tx, labels, newest);
|
|
10715
|
+
if (given.size > 0) enabled = enabled.map((row) => given.has(row.id) ? {
|
|
10716
|
+
...row,
|
|
10717
|
+
label: given.get(row.id)
|
|
10718
|
+
} : row);
|
|
10283
10719
|
release = {
|
|
10284
10720
|
...change.row,
|
|
10285
|
-
id
|
|
10721
|
+
id,
|
|
10722
|
+
label: await labels.next(scope.channelId, scope.platform)
|
|
10286
10723
|
};
|
|
10287
10724
|
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");
|
|
10288
10725
|
tx.create("releases", release);
|
|
@@ -10295,8 +10732,9 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
10295
10732
|
await tx.delete("releases", row);
|
|
10296
10733
|
release = null;
|
|
10297
10734
|
} else {
|
|
10735
|
+
const { label: _label, ...update } = change.update;
|
|
10298
10736
|
const set = {
|
|
10299
|
-
...
|
|
10737
|
+
...update,
|
|
10300
10738
|
revision: before.revision + 1
|
|
10301
10739
|
};
|
|
10302
10740
|
tx.update("releases", row, set);
|
|
@@ -10317,13 +10755,26 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
10317
10755
|
};
|
|
10318
10756
|
const changeReleases = (db, inputs) => {
|
|
10319
10757
|
if (new Set(inputs.map(({ scope }) => scope.scopeKey)).size !== inputs.length) fail$1("INVALID_SCOPE", "A batch cannot change one catalog scope twice");
|
|
10320
|
-
return db
|
|
10758
|
+
return writeWithLabels(db, async (tx, labels) => {
|
|
10321
10759
|
const results = [];
|
|
10322
|
-
for (const input of inputs) results.push(await changeRelease(tx, input));
|
|
10760
|
+
for (const input of inputs) results.push(await changeRelease(tx, input, labels));
|
|
10323
10761
|
return results;
|
|
10324
10762
|
});
|
|
10325
10763
|
};
|
|
10326
|
-
const isCurrent = (scope, current, compilation) =>
|
|
10764
|
+
const isCurrent = (scope, current, compilation) => {
|
|
10765
|
+
if (current.strategy !== scope.strategy || current.channel_id !== scope.channelId || current.channel_key !== encodeChannelKey(scope.channelName) || current.platform !== scope.platform || current.fingerprint_hash !== scope.fingerprintHash) return false;
|
|
10766
|
+
if (current.catalog_hash === compilation.catalogHash) return true;
|
|
10767
|
+
const read = readCompiledCatalogPayload(current.payload);
|
|
10768
|
+
return read.fromLaterRelease && read.canonicalPayload === compilation.canonicalPayload;
|
|
10769
|
+
};
|
|
10770
|
+
const withoutLabels = (payload) => {
|
|
10771
|
+
const parsed = JSON.parse(payload);
|
|
10772
|
+
return JSON.stringify({
|
|
10773
|
+
...parsed,
|
|
10774
|
+
releaseDescriptors: (parsed.releaseDescriptors ?? []).map(({ label: _label, ...descriptor }) => descriptor)
|
|
10775
|
+
});
|
|
10776
|
+
};
|
|
10777
|
+
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);
|
|
10327
10778
|
const catalogRowScope = (row) => ({
|
|
10328
10779
|
channelId: row.channel_id,
|
|
10329
10780
|
channelName: decodeChannelKey(row.channel_key),
|
|
@@ -10341,17 +10792,19 @@ const preflightRebuild = async (db, scopeKey, updatedAtMs) => {
|
|
|
10341
10792
|
const enabled = await drainReleases((cursor) => db.findMany("releases", enabledIn(scopeKey, cursor)));
|
|
10342
10793
|
const compilation = await compileScope(scope, enabled);
|
|
10343
10794
|
const changed = !isCurrent(scope, current, compilation);
|
|
10795
|
+
const projectedCatalog = changed ? nextCatalog(scope, { catalog: current }, compilation, updatedAtMs) : current;
|
|
10344
10796
|
return {
|
|
10345
10797
|
changed,
|
|
10798
|
+
labelsOnly: changed && differsInLabelsOnly(current, projectedCatalog),
|
|
10346
10799
|
currentCatalog: current,
|
|
10347
10800
|
diagnostics: compilation.diagnostics,
|
|
10348
|
-
projectedCatalog
|
|
10801
|
+
projectedCatalog
|
|
10349
10802
|
};
|
|
10350
10803
|
};
|
|
10351
10804
|
const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
10352
10805
|
checkScope(scope);
|
|
10353
10806
|
const stored = await readCatalog(tx, scope.scopeKey);
|
|
10354
|
-
assertHistory(stored, await
|
|
10807
|
+
assertHistory(stored, await latestRelease(tx, scope.scopeKey) !== null);
|
|
10355
10808
|
const enabled = await enabledReleases(tx, scope.scopeKey);
|
|
10356
10809
|
const compilation = await compileScope(scope, enabled);
|
|
10357
10810
|
const current = stored.catalog;
|
|
@@ -10361,6 +10814,7 @@ const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
|
10361
10814
|
changed: false,
|
|
10362
10815
|
diagnostics: compilation.diagnostics
|
|
10363
10816
|
};
|
|
10817
|
+
refuseLaterCatalog(scope, current);
|
|
10364
10818
|
const written = await writeCatalog(tx, scope, stored, enabled, updatedAtMs);
|
|
10365
10819
|
return {
|
|
10366
10820
|
catalog: written.catalog,
|
|
@@ -10371,6 +10825,7 @@ const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
|
10371
10825
|
};
|
|
10372
10826
|
//#endregion
|
|
10373
10827
|
//#region ../../packages/server/dist/core/operations.mjs
|
|
10828
|
+
const CATALOG_PAGE = 100;
|
|
10374
10829
|
var Preflight = class extends Error {
|
|
10375
10830
|
result;
|
|
10376
10831
|
constructor(result) {
|
|
@@ -10589,7 +11044,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
10589
11044
|
if (targetChannel.length === 0) throw new ReleaseManagementError("TARGET_RELEASE_INVALID", "Promotion requires a target channel.");
|
|
10590
11045
|
const channel = await ensureChannel(targetChannel);
|
|
10591
11046
|
const updatedAtMs = now();
|
|
10592
|
-
return db
|
|
11047
|
+
return writeWithLabels(db, async (tx, labels) => {
|
|
10593
11048
|
const { release: source, scope: sourceScope } = await loadTarget(tx, input);
|
|
10594
11049
|
checkSource(source);
|
|
10595
11050
|
const targetScope = scopeOf$1(channel, source.platform, source.fingerprint_hash);
|
|
@@ -10617,12 +11072,13 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
10617
11072
|
},
|
|
10618
11073
|
updatedAtMs
|
|
10619
11074
|
}) : null;
|
|
11075
|
+
const { label: _label, ...copied } = source;
|
|
10620
11076
|
const target = await changeRelease(tx, {
|
|
10621
11077
|
scope: targetScope,
|
|
10622
11078
|
change: {
|
|
10623
11079
|
operation: "insert",
|
|
10624
11080
|
row: {
|
|
10625
|
-
...
|
|
11081
|
+
...copied,
|
|
10626
11082
|
id: createUUIDv7After(floor ?? null, updatedAtMs),
|
|
10627
11083
|
revision: 1,
|
|
10628
11084
|
scope_key: targetScope.scopeKey,
|
|
@@ -10637,7 +11093,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
10637
11093
|
}
|
|
10638
11094
|
},
|
|
10639
11095
|
updatedAtMs
|
|
10640
|
-
});
|
|
11096
|
+
}, labels);
|
|
10641
11097
|
return {
|
|
10642
11098
|
source: moved === null ? null : mutationResult(moved),
|
|
10643
11099
|
target: mutationResult(target)
|
|
@@ -10655,6 +11111,38 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
10655
11111
|
});
|
|
10656
11112
|
},
|
|
10657
11113
|
preflightReleaseCatalogRebuild: (scopeKey) => preflightRebuild(db, scopeKey, now()),
|
|
11114
|
+
fillReleaseLabels: async ({ dryRun = false, catalogs = true } = {}) => {
|
|
11115
|
+
let releases = 0;
|
|
11116
|
+
const pairs = await pendingLabelPairs(db);
|
|
11117
|
+
if (dryRun && pairs[0] !== void 0) await probeLabelSchema(db, pairs[0]);
|
|
11118
|
+
for (const pair of pairs) releases += await fillLabels(db, pair, { dryRun });
|
|
11119
|
+
let rebuilt = 0;
|
|
11120
|
+
if (catalogs) {
|
|
11121
|
+
let cursor;
|
|
11122
|
+
do {
|
|
11123
|
+
const page = await db.findMany("release_catalogs", {
|
|
11124
|
+
index: "all",
|
|
11125
|
+
where: {},
|
|
11126
|
+
limit: CATALOG_PAGE,
|
|
11127
|
+
...cursor === void 0 ? {} : { cursor }
|
|
11128
|
+
});
|
|
11129
|
+
for (const row of page.rows) {
|
|
11130
|
+
if (row.is_tombstone) continue;
|
|
11131
|
+
const preflight = await preflightRebuild(db, row.scope_key, now()).catch(() => null);
|
|
11132
|
+
if (preflight === null || !preflight.labelsOnly) continue;
|
|
11133
|
+
rebuilt += 1;
|
|
11134
|
+
if (dryRun) continue;
|
|
11135
|
+
const updatedAtMs = now();
|
|
11136
|
+
await db.transaction((tx) => rebuildScope(tx, catalogRowScope(toCatalogRow(row)), updatedAtMs));
|
|
11137
|
+
}
|
|
11138
|
+
cursor = page.next;
|
|
11139
|
+
} while (cursor !== void 0);
|
|
11140
|
+
}
|
|
11141
|
+
return {
|
|
11142
|
+
releases,
|
|
11143
|
+
catalogs: rebuilt
|
|
11144
|
+
};
|
|
11145
|
+
},
|
|
10658
11146
|
ensureChannel,
|
|
10659
11147
|
deleteChannel: (id) => deleteChannel(db, id),
|
|
10660
11148
|
updateBundle: (id, update) => db.transaction(async (tx) => {
|
|
@@ -11185,6 +11673,26 @@ const createAdminRouteHandlers = () => ({
|
|
|
11185
11673
|
return row === null ? notFound() : json$2({ data: row });
|
|
11186
11674
|
}),
|
|
11187
11675
|
rebuildReleaseCatalog: onCore(async (core, _request, params) => json$2({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
|
|
11676
|
+
getReleaseByLabel: onCore(async (core, request) => {
|
|
11677
|
+
const url = new URL(request.url);
|
|
11678
|
+
const channel = url.searchParams.get("channel");
|
|
11679
|
+
const platform = platformOf(url);
|
|
11680
|
+
const label = Number(url.searchParams.get("label"));
|
|
11681
|
+
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.");
|
|
11682
|
+
return json$2({ data: await core.getReleaseByLabel({
|
|
11683
|
+
channel,
|
|
11684
|
+
platform,
|
|
11685
|
+
label
|
|
11686
|
+
}) });
|
|
11687
|
+
}),
|
|
11688
|
+
fillReleaseLabels: onCore(async (core, request) => {
|
|
11689
|
+
const body = await request.json().catch(() => ({}));
|
|
11690
|
+
const input = body !== null && typeof body === "object" ? body : {};
|
|
11691
|
+
return json$2({ data: await core.fillReleaseLabels({
|
|
11692
|
+
dryRun: input.dryRun === true,
|
|
11693
|
+
catalogs: input.catalogs !== false
|
|
11694
|
+
}) });
|
|
11695
|
+
}),
|
|
11188
11696
|
updateBundle: onCore(async (core, request, params) => {
|
|
11189
11697
|
const bundleId = requireRouteParam(params, "id");
|
|
11190
11698
|
const update = bundleUpdateOf(await request.json(), bundleId);
|
|
@@ -11411,6 +11919,16 @@ const ADMIN_ROUTES = [
|
|
|
11411
11919
|
path: "/release-scopes",
|
|
11412
11920
|
handler: "listReleaseScopeKeys"
|
|
11413
11921
|
},
|
|
11922
|
+
{
|
|
11923
|
+
method: "GET",
|
|
11924
|
+
path: "/release-labels",
|
|
11925
|
+
handler: "getReleaseByLabel"
|
|
11926
|
+
},
|
|
11927
|
+
{
|
|
11928
|
+
method: "POST",
|
|
11929
|
+
path: "/release-labels/fill",
|
|
11930
|
+
handler: "fillReleaseLabels"
|
|
11931
|
+
},
|
|
11414
11932
|
{
|
|
11415
11933
|
method: "POST",
|
|
11416
11934
|
path: "/release-catalogs/:scopeKey/rebuild",
|
|
@@ -58587,7 +59105,6 @@ function azureBlobStorage(config) {
|
|
|
58587
59105
|
const blob = (await container()).getBlockBlobClient(storageKey);
|
|
58588
59106
|
if (contentLength === void 0) await blob.uploadData(new Uint8Array(await new Response(body).arrayBuffer()), options);
|
|
58589
59107
|
else {
|
|
58590
|
-
const { Readable } = await import("node:stream");
|
|
58591
59108
|
const source = Readable.fromWeb(body);
|
|
58592
59109
|
const aborted = new AbortController();
|
|
58593
59110
|
let failure;
|
|
@@ -58596,12 +59113,15 @@ function azureBlobStorage(config) {
|
|
|
58596
59113
|
aborted.abort(error);
|
|
58597
59114
|
});
|
|
58598
59115
|
try {
|
|
58599
|
-
await blob.upload(source, contentLength, {
|
|
59116
|
+
await new BlockBlobClient(blob.url, newPipeline(blob.credential, { retryOptions: { maxTries: 1 } })).upload(source, contentLength, {
|
|
58600
59117
|
...options,
|
|
58601
59118
|
abortSignal: aborted.signal
|
|
58602
59119
|
});
|
|
58603
59120
|
} catch (error) {
|
|
58604
|
-
|
|
59121
|
+
const status = failure === void 0 && error instanceof RestError ? error.statusCode : void 0;
|
|
59122
|
+
if (status === void 0) throw failure ?? error;
|
|
59123
|
+
const code = error.code;
|
|
59124
|
+
throw new Error(`Azure Blob Storage answered HTTP ${status} while uploading ${storageKey}${status < 500 && code ? `: ${code}` : ""}`, { cause: error });
|
|
58605
59125
|
}
|
|
58606
59126
|
}
|
|
58607
59127
|
return { storageUri: createStorageUri({
|
package/dist/index.cjs
CHANGED
|
@@ -127,8 +127,7 @@ function azureBlobStorage(config) {
|
|
|
127
127
|
const blob = (await container()).getBlockBlobClient(storageKey);
|
|
128
128
|
if (contentLength === void 0) await blob.uploadData(new Uint8Array(await new Response(body).arrayBuffer()), options);
|
|
129
129
|
else {
|
|
130
|
-
const
|
|
131
|
-
const source = Readable.fromWeb(body);
|
|
130
|
+
const source = node_stream.Readable.fromWeb(body);
|
|
132
131
|
const aborted = new AbortController();
|
|
133
132
|
let failure;
|
|
134
133
|
source.once("error", (error) => {
|
|
@@ -136,12 +135,15 @@ function azureBlobStorage(config) {
|
|
|
136
135
|
aborted.abort(error);
|
|
137
136
|
});
|
|
138
137
|
try {
|
|
139
|
-
await blob.upload(source, contentLength, {
|
|
138
|
+
await new _azure_storage_blob.BlockBlobClient(blob.url, (0, _azure_storage_blob.newPipeline)(blob.credential, { retryOptions: { maxTries: 1 } })).upload(source, contentLength, {
|
|
140
139
|
...options,
|
|
141
140
|
abortSignal: aborted.signal
|
|
142
141
|
});
|
|
143
142
|
} catch (error) {
|
|
144
|
-
|
|
143
|
+
const status = failure === void 0 && error instanceof _azure_storage_blob.RestError ? error.statusCode : void 0;
|
|
144
|
+
if (status === void 0) throw failure ?? error;
|
|
145
|
+
const code = error.code;
|
|
146
|
+
throw new Error(`Azure Blob Storage answered HTTP ${status} while uploading ${storageKey}${status < 500 && code ? `: ${code}` : ""}`, { cause: error });
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
149
|
return { storageUri: (0, _hot_updater_plugin_core.createStorageUri)({
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable } from "node:stream";
|
|
2
2
|
import { isTokenCredential } from "@azure/core-auth";
|
|
3
|
-
import { BlobSASPermissions, BlobServiceClient, RestError, StorageSharedKeyCredential, generateBlobSASQueryParameters } from "@azure/storage-blob";
|
|
3
|
+
import { BlobSASPermissions, BlobServiceClient, BlockBlobClient, RestError, StorageSharedKeyCredential, generateBlobSASQueryParameters, newPipeline } from "@azure/storage-blob";
|
|
4
4
|
import { SETTINGS_TABLE, createEngineDatabase, createKvAdapter, createStorageAdapter, createStorageKeyBuilder, createStorageUri, encodeKvKey, migrateCoreSchema, parseStorageUri, toolingTargetOf } from "@hot-updater/plugin-core";
|
|
5
5
|
import { CosmosClient } from "@azure/cosmos";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
@@ -126,7 +126,6 @@ function azureBlobStorage(config) {
|
|
|
126
126
|
const blob = (await container()).getBlockBlobClient(storageKey);
|
|
127
127
|
if (contentLength === void 0) await blob.uploadData(new Uint8Array(await new Response(body).arrayBuffer()), options);
|
|
128
128
|
else {
|
|
129
|
-
const { Readable } = await import("node:stream");
|
|
130
129
|
const source = Readable.fromWeb(body);
|
|
131
130
|
const aborted = new AbortController();
|
|
132
131
|
let failure;
|
|
@@ -135,12 +134,15 @@ function azureBlobStorage(config) {
|
|
|
135
134
|
aborted.abort(error);
|
|
136
135
|
});
|
|
137
136
|
try {
|
|
138
|
-
await blob.upload(source, contentLength, {
|
|
137
|
+
await new BlockBlobClient(blob.url, newPipeline(blob.credential, { retryOptions: { maxTries: 1 } })).upload(source, contentLength, {
|
|
139
138
|
...options,
|
|
140
139
|
abortSignal: aborted.signal
|
|
141
140
|
});
|
|
142
141
|
} catch (error) {
|
|
143
|
-
|
|
142
|
+
const status = failure === void 0 && error instanceof RestError ? error.statusCode : void 0;
|
|
143
|
+
if (status === void 0) throw failure ?? error;
|
|
144
|
+
const code = error.code;
|
|
145
|
+
throw new Error(`Azure Blob Storage answered HTTP ${status} while uploading ${storageKey}${status < 500 && code ? `: ${code}` : ""}`, { cause: error });
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
return { storageUri: createStorageUri({
|
package/dist/init/index.cjs
CHANGED
|
@@ -7883,6 +7883,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7883
7883
|
});
|
|
7884
7884
|
let credential;
|
|
7885
7885
|
try {
|
|
7886
|
+
await (0, _hot_updater_cli_tools.fillReleaseLabels)(server);
|
|
7886
7887
|
credential = await (0, _hot_updater_cli_tools.provisionClientCredential)(server, {
|
|
7887
7888
|
env: initInputEnv,
|
|
7888
7889
|
name: "Azure init"
|
package/dist/init/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { createHash } from "crypto";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import { ConfigBuilder, InitError, assembleServer, createHotUpdaterConfigScaffoldFromBuilder, createZip, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInputs, shouldAutoSelectOnlyInitResource, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
4
|
+
import { ConfigBuilder, InitError, assembleServer, createHotUpdaterConfigScaffoldFromBuilder, createZip, fillReleaseLabels, getCwd, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInputs, shouldAutoSelectOnlyInitResource, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
5
5
|
import { apiKeys, insights, remoteConfig } from "@hot-updater/server/plugins";
|
|
6
6
|
import { CosmosClient } from "@azure/cosmos";
|
|
7
7
|
import { SETTINGS_TABLE, createEngineDatabase, createKvAdapter, encodeKvKey, migrateCoreSchema, toolingTargetOf } from "@hot-updater/plugin-core";
|
|
@@ -7878,6 +7878,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7878
7878
|
});
|
|
7879
7879
|
let credential;
|
|
7880
7880
|
try {
|
|
7881
|
+
await fillReleaseLabels(server);
|
|
7881
7882
|
credential = await provisionClientCredential(server, {
|
|
7882
7883
|
env: initInputEnv,
|
|
7883
7884
|
name: "Azure init"
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/azure",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.52",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": "^22.23.4 || ^24.22.1 || >=26.12.1"
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"@azure/identity": "4.14.0",
|
|
45
45
|
"@azure/keyvault-secrets": "4.11.2",
|
|
46
46
|
"@azure/storage-blob": "12.34.0",
|
|
47
|
-
"@hot-updater/cli-tools": "1.2.0-rc.
|
|
48
|
-
"@hot-updater/plugin-core": "1.2.0-rc.
|
|
49
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
50
|
-
"@hot-updater/server": "1.2.0-rc.
|
|
47
|
+
"@hot-updater/cli-tools": "1.2.0-rc.52",
|
|
48
|
+
"@hot-updater/plugin-core": "1.2.0-rc.52",
|
|
49
|
+
"@hot-updater/protocol": "1.2.0-rc.52",
|
|
50
|
+
"@hot-updater/server": "1.2.0-rc.52"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@azure/functions": "4.16.5",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"execa": "9.5.2",
|
|
56
56
|
"jszip": "^3.10.1",
|
|
57
57
|
"vitest": "4.1.4",
|
|
58
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
58
|
+
"@hot-updater/test-utils": "1.2.0-rc.52"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "tsdown",
|