@hot-updater/firebase 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/firebase/functions/index.cjs +584 -44
- package/dist/init/index.cjs +1 -0
- package/dist/init/index.mjs +2 -1
- package/package.json +7 -7
|
@@ -603,7 +603,8 @@ const releaseRowToRelease = (row) => ({
|
|
|
603
603
|
operation: row.operation,
|
|
604
604
|
sourceReleaseId: row.source_release_id,
|
|
605
605
|
createdAtMs: row.created_at_ms,
|
|
606
|
-
updatedAtMs: row.updated_at_ms
|
|
606
|
+
updatedAtMs: row.updated_at_ms,
|
|
607
|
+
label: row.label ?? null
|
|
607
608
|
});
|
|
608
609
|
const bundleToRow = (bundle) => {
|
|
609
610
|
const metadata = bundleMetadataToRow(bundle.metadata);
|
|
@@ -1112,7 +1113,8 @@ function rangeToIntervals(range) {
|
|
|
1112
1113
|
throw new ReleaseCatalogCompilationError("INVALID_TARGET_RANGE", `Invalid target app-version range: ${range}`);
|
|
1113
1114
|
}
|
|
1114
1115
|
}
|
|
1115
|
-
|
|
1116
|
+
/** A release's descriptor; its label only when it has one and `labels`. */
|
|
1117
|
+
function releaseDescriptor(release, labels) {
|
|
1116
1118
|
return {
|
|
1117
1119
|
releaseId: release.id,
|
|
1118
1120
|
kind: release.kind,
|
|
@@ -1120,7 +1122,8 @@ function releaseDescriptor(release) {
|
|
|
1120
1122
|
rolloutCohortCount: release.rolloutCohortCount,
|
|
1121
1123
|
targetCohorts: [...new Set(release.targetCohorts)].sort(),
|
|
1122
1124
|
shouldForceUpdate: release.shouldForceUpdate,
|
|
1123
|
-
message: release.message
|
|
1125
|
+
message: release.message,
|
|
1126
|
+
...labels && typeof release.label === "number" ? { label: release.label } : {}
|
|
1124
1127
|
};
|
|
1125
1128
|
}
|
|
1126
1129
|
function validateReleases(releases, strategy) {
|
|
@@ -1333,12 +1336,21 @@ async function compileReleaseCatalog(input) {
|
|
|
1333
1336
|
const targetCohorts = new Set(releases.flatMap((release) => release.targetCohorts));
|
|
1334
1337
|
if (targetCohorts.size > 512) throw new ReleaseCatalogCompilationError("DISTINCT_TARGET_COHORT_LIMIT", `Scope exceeds 512 distinct target cohorts`);
|
|
1335
1338
|
const { envelope, retainedReleases } = input.strategy === "APP_VERSION" ? compileAppVersion(releases) : compileFingerprint(releases);
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
+
const compile = (labels) => {
|
|
1340
|
+
const payload = {
|
|
1341
|
+
...envelope,
|
|
1342
|
+
releaseDescriptors: retainedReleases.map((release) => releaseDescriptor(release, labels))
|
|
1343
|
+
};
|
|
1344
|
+
const canonicalPayload = canonicalStringify(payload);
|
|
1345
|
+
return {
|
|
1346
|
+
payload,
|
|
1347
|
+
canonicalPayload,
|
|
1348
|
+
byteSize: new TextEncoder().encode(canonicalPayload).byteLength
|
|
1349
|
+
};
|
|
1339
1350
|
};
|
|
1340
|
-
|
|
1341
|
-
|
|
1351
|
+
let compiled = compile(true);
|
|
1352
|
+
if (compiled.byteSize > 262144 && retainedReleases.some((release) => typeof release.label === "number")) compiled = compile(false);
|
|
1353
|
+
const { payload, canonicalPayload, byteSize } = compiled;
|
|
1342
1354
|
if (byteSize > 262144) throw new ReleaseCatalogCompilationError("CATALOG_OVERSIZE", `Compiled Release catalog is ${byteSize} bytes; maximum is ${MAX_COMPILED_CATALOG_BYTES}`);
|
|
1343
1355
|
return {
|
|
1344
1356
|
byteSize,
|
|
@@ -2063,7 +2075,7 @@ const CHANNEL_ID = {
|
|
|
2063
2075
|
* every database's migrator creates missing tables and then records the
|
|
2064
2076
|
* version, and none of them changes an existing table's columns, so changing
|
|
2065
2077
|
* one needs a migration step of its own first. An index added to an existing
|
|
2066
|
-
* table is listed in `LATE_INDEXES`. The schema fence answers 503 on
|
|
2078
|
+
* table is listed in `LATE_INDEXES`, and a column in `LATE_COLUMNS`. The schema fence answers 503 on
|
|
2067
2079
|
* a database whose row differs, until it runs. Before a version is released,
|
|
2068
2080
|
* its tables change in place in its own migration, and a database one of its
|
|
2069
2081
|
* prereleases migrated takes the same change by hand: the fence compares this
|
|
@@ -2216,7 +2228,11 @@ const releases = defineTable({
|
|
|
2216
2228
|
}
|
|
2217
2229
|
},
|
|
2218
2230
|
created_at_ms: { type: "integer" },
|
|
2219
|
-
updated_at_ms: { type: "integer" }
|
|
2231
|
+
updated_at_ms: { type: "integer" },
|
|
2232
|
+
label: {
|
|
2233
|
+
type: "integer",
|
|
2234
|
+
required: false
|
|
2235
|
+
}
|
|
2220
2236
|
}, {
|
|
2221
2237
|
key: ["id"],
|
|
2222
2238
|
indexes: {
|
|
@@ -2253,6 +2269,15 @@ const releases = defineTable({
|
|
|
2253
2269
|
scopes: {
|
|
2254
2270
|
eq: [],
|
|
2255
2271
|
sort: ["scope_key"]
|
|
2272
|
+
},
|
|
2273
|
+
byLabel: {
|
|
2274
|
+
eq: [
|
|
2275
|
+
"channel_id",
|
|
2276
|
+
"platform",
|
|
2277
|
+
"label"
|
|
2278
|
+
],
|
|
2279
|
+
sort: [],
|
|
2280
|
+
unique: true
|
|
2256
2281
|
}
|
|
2257
2282
|
}
|
|
2258
2283
|
});
|
|
@@ -2269,6 +2294,43 @@ const LATE_INDEXES = [{
|
|
|
2269
2294
|
table: "releases",
|
|
2270
2295
|
index: "scopes"
|
|
2271
2296
|
}];
|
|
2297
|
+
/**
|
|
2298
|
+
* Columns added to a table that a released schema created: a migrator whose
|
|
2299
|
+
* store has columns adds each one missing from an existing table, with
|
|
2300
|
+
* `ALTER TABLE … ADD COLUMN`, before it creates the table's indexes, and
|
|
2301
|
+
* `db migrate` on a database whose settings match still looks for them,
|
|
2302
|
+
* since a database a prerelease migrated records the same settings. Each
|
|
2303
|
+
* is optional, so rows written before it, and rows a server of the earlier
|
|
2304
|
+
* release still writes, read as null. `releases.label` arrived in 1.2.0.
|
|
2305
|
+
*/
|
|
2306
|
+
const LATE_COLUMNS = [{
|
|
2307
|
+
table: "releases",
|
|
2308
|
+
column: "label"
|
|
2309
|
+
}];
|
|
2310
|
+
/**
|
|
2311
|
+
* One counter per sequence: `releases/<platform>/<channel ID>` holds the
|
|
2312
|
+
* last label that channel and platform's releases took. A deploy or a
|
|
2313
|
+
* promote reads it and writes the next value in the transaction that writes
|
|
2314
|
+
* the release, so two writers never take one label. `is_filled` is true once
|
|
2315
|
+
* every release of the sequence written before labels has one, in ID order;
|
|
2316
|
+
* until then a writer fills them first. Deleting a channel deletes its
|
|
2317
|
+
* counters, so a channel created again with the name starts at 1.
|
|
2318
|
+
*/
|
|
2319
|
+
const labelSequences = defineTable({
|
|
2320
|
+
id: {
|
|
2321
|
+
type: "string",
|
|
2322
|
+
maxLength: 1440,
|
|
2323
|
+
ascii: true
|
|
2324
|
+
},
|
|
2325
|
+
last_label: { type: "integer" },
|
|
2326
|
+
is_filled: { type: "boolean" }
|
|
2327
|
+
}, {
|
|
2328
|
+
key: ["id"],
|
|
2329
|
+
indexes: { all: {
|
|
2330
|
+
eq: [],
|
|
2331
|
+
sort: ["id"]
|
|
2332
|
+
} }
|
|
2333
|
+
});
|
|
2272
2334
|
/** One compiled catalog per scope; the update check reads exactly this row. */
|
|
2273
2335
|
const releaseCatalogs = defineTable({
|
|
2274
2336
|
scope_key: {
|
|
@@ -2640,7 +2702,8 @@ const coreModule = {
|
|
|
2640
2702
|
}),
|
|
2641
2703
|
native_builds: nativeBuilds,
|
|
2642
2704
|
ios_devices: iosDevices,
|
|
2643
|
-
ios_device_account: iosDeviceAccount
|
|
2705
|
+
ios_device_account: iosDeviceAccount,
|
|
2706
|
+
label_sequences: labelSequences
|
|
2644
2707
|
}
|
|
2645
2708
|
};
|
|
2646
2709
|
//#endregion
|
|
@@ -2768,8 +2831,26 @@ const fillLateIndexes = async (adapter, tables, { dryRun = false } = {}) => {
|
|
|
2768
2831
|
return lacking;
|
|
2769
2832
|
};
|
|
2770
2833
|
/**
|
|
2771
|
-
*
|
|
2772
|
-
*
|
|
2834
|
+
* The `LATE_COLUMNS` among `tables` that an existing table lacks, as
|
|
2835
|
+
* `<table>.<column>`, added unless `dryRun`: none on a store without
|
|
2836
|
+
* `migrations.addColumns`, or for a table not created yet.
|
|
2837
|
+
*/
|
|
2838
|
+
const addLateColumns = async (adapter, tables, { dryRun = false } = {}) => {
|
|
2839
|
+
const addColumns = adapter.migrations?.addColumns;
|
|
2840
|
+
if (addColumns === void 0) return [];
|
|
2841
|
+
const lacking = [];
|
|
2842
|
+
for (const table of tables) {
|
|
2843
|
+
const columns = LATE_COLUMNS.filter(({ table: name }) => name === table.name).map(({ column }) => column);
|
|
2844
|
+
if (columns.length === 0) continue;
|
|
2845
|
+
const added = await addColumns(table, columns, { dryRun });
|
|
2846
|
+
lacking.push(...added.map((column) => `${table.name}.${column}`));
|
|
2847
|
+
}
|
|
2848
|
+
return lacking;
|
|
2849
|
+
};
|
|
2850
|
+
/**
|
|
2851
|
+
* Adds the late columns existing tables lack, creates or updates every
|
|
2852
|
+
* table, writes the late indexes' missing items, then writes the settings
|
|
2853
|
+
* rows last. A database a newer release migrated is
|
|
2773
2854
|
* refused before anything is written: its settings are read first, and a
|
|
2774
2855
|
* store without them yet, whose read fails, has none to refuse.
|
|
2775
2856
|
*/
|
|
@@ -2777,6 +2858,7 @@ const migrateSchema = async (adapter, adapterName, tables, settings, ordered) =>
|
|
|
2777
2858
|
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2778
2859
|
const stored = await storedSettings(adapter, Object.keys(settings)).catch(() => void 0);
|
|
2779
2860
|
if (stored !== void 0) refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2861
|
+
await addLateColumns(adapter, tables);
|
|
2780
2862
|
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2781
2863
|
await fillLateIndexes(adapter, tables);
|
|
2782
2864
|
await writeSchemaSettings(adapter, adapterName, settings, ordered);
|
|
@@ -3813,23 +3895,45 @@ const createEngineMigrator = (options) => {
|
|
|
3813
3895
|
refuseNewerSchema(options.adapterName, stored, options.settings, options.ordered);
|
|
3814
3896
|
const changed = Object.entries(options.settings).filter(([key, value]) => stored.get(key) !== value);
|
|
3815
3897
|
if (changed.length === 0) {
|
|
3898
|
+
const columns = await addLateColumns(options.adapter, options.schema.tables, { dryRun: true });
|
|
3816
3899
|
const lacking = await fillLateIndexes(options.adapter, options.schema.tables, { dryRun: true });
|
|
3817
|
-
if (lacking.length === 0) return getEmptyMigrationResult();
|
|
3900
|
+
if (columns.length === 0 && lacking.length === 0) return getEmptyMigrationResult();
|
|
3818
3901
|
return {
|
|
3819
|
-
operations: [
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3902
|
+
operations: [
|
|
3903
|
+
...columns.map((column) => ({
|
|
3904
|
+
type: "custom",
|
|
3905
|
+
description: `Add column: ${column}`
|
|
3906
|
+
})),
|
|
3907
|
+
...columns.length === 0 ? [] : [{
|
|
3908
|
+
type: "custom",
|
|
3909
|
+
description: "Create the tables and indexes the database lacks"
|
|
3910
|
+
}],
|
|
3911
|
+
...lacking.length === 0 ? [] : [{
|
|
3912
|
+
type: "custom",
|
|
3913
|
+
description: `Write the index items rows lack: ${lacking.join(", ")}`
|
|
3914
|
+
}]
|
|
3915
|
+
],
|
|
3823
3916
|
execute: async () => {
|
|
3917
|
+
if (columns.length > 0) {
|
|
3918
|
+
await addLateColumns(options.adapter, options.schema.tables);
|
|
3919
|
+
await options.adapter.migrations.apply([...options.schema.tables, SETTINGS_TABLE]);
|
|
3920
|
+
}
|
|
3824
3921
|
await fillLateIndexes(options.adapter, options.schema.tables);
|
|
3825
3922
|
}
|
|
3826
3923
|
};
|
|
3827
3924
|
}
|
|
3828
3925
|
return {
|
|
3829
|
-
operations: [
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3926
|
+
operations: [
|
|
3927
|
+
...(await addLateColumns(options.adapter, options.schema.tables, { dryRun: true }).catch(() => [])).map((column) => ({
|
|
3928
|
+
type: "custom",
|
|
3929
|
+
description: `Add column: ${column}`
|
|
3930
|
+
})),
|
|
3931
|
+
{
|
|
3932
|
+
type: "custom",
|
|
3933
|
+
description: "Create the tables and indexes the database lacks"
|
|
3934
|
+
},
|
|
3935
|
+
...migrate.updateSettings === false ? [] : [settingsOperation(stored, changed)]
|
|
3936
|
+
],
|
|
3833
3937
|
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings, options.ordered)
|
|
3834
3938
|
};
|
|
3835
3939
|
};
|
|
@@ -5013,7 +5117,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
5013
5117
|
};
|
|
5014
5118
|
//#endregion
|
|
5015
5119
|
//#region ../../packages/server/dist/version.mjs
|
|
5016
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
5120
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.51";
|
|
5017
5121
|
//#endregion
|
|
5018
5122
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
5019
5123
|
/**
|
|
@@ -5812,7 +5916,7 @@ const baseBundleIdsOf = (row, range, bundleId, limit) => {
|
|
|
5812
5916
|
};
|
|
5813
5917
|
//#endregion
|
|
5814
5918
|
//#region ../../packages/server/dist/core/reads.mjs
|
|
5815
|
-
const PAGE$
|
|
5919
|
+
const PAGE$4 = 500;
|
|
5816
5920
|
const pick$2 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
|
|
5817
5921
|
const toBundleRow = pick$2([
|
|
5818
5922
|
"id",
|
|
@@ -5833,7 +5937,7 @@ const toPatchRow = pick$2([
|
|
|
5833
5937
|
"byte_size",
|
|
5834
5938
|
"order_index"
|
|
5835
5939
|
]);
|
|
5836
|
-
const
|
|
5940
|
+
const pickReleaseRow = pick$2([
|
|
5837
5941
|
"id",
|
|
5838
5942
|
"revision",
|
|
5839
5943
|
"scope_key",
|
|
@@ -5854,6 +5958,13 @@ const toReleaseRow = pick$2([
|
|
|
5854
5958
|
"created_at_ms",
|
|
5855
5959
|
"updated_at_ms"
|
|
5856
5960
|
]);
|
|
5961
|
+
/** A release row; `label` null where the store holds none, as before the column. */
|
|
5962
|
+
const toReleaseRow = (row) => {
|
|
5963
|
+
return {
|
|
5964
|
+
...pickReleaseRow(row),
|
|
5965
|
+
label: typeof row.label === "number" ? row.label : null
|
|
5966
|
+
};
|
|
5967
|
+
};
|
|
5857
5968
|
const toCatalogRow = pick$2([
|
|
5858
5969
|
"scope_key",
|
|
5859
5970
|
"catalog_id",
|
|
@@ -5902,7 +6013,7 @@ const createCoreReads = (db, storage) => {
|
|
|
5902
6013
|
const page = await db.findMany("bundle_patches", {
|
|
5903
6014
|
index: "byBundle",
|
|
5904
6015
|
where: { bundle_id: row.id },
|
|
5905
|
-
limit: Math.min(count - patches.length, PAGE$
|
|
6016
|
+
limit: Math.min(count - patches.length, PAGE$4),
|
|
5906
6017
|
...cursor === void 0 ? {} : { cursor }
|
|
5907
6018
|
});
|
|
5908
6019
|
patches.push(...page.rows.map(toPatchRow));
|
|
@@ -6012,6 +6123,23 @@ const createCoreReads = (db, storage) => {
|
|
|
6012
6123
|
const row = await db.findOne("releases", { id });
|
|
6013
6124
|
return row === null ? null : toReleaseRow(row);
|
|
6014
6125
|
},
|
|
6126
|
+
/**
|
|
6127
|
+
* The release a label names: its unique index, then the row itself,
|
|
6128
|
+
* since a key-value store keeps an index copy a server of an earlier
|
|
6129
|
+
* release may have left behind when it changed or deleted the row.
|
|
6130
|
+
*/
|
|
6131
|
+
async getReleaseByLabel({ channel, platform, label }) {
|
|
6132
|
+
const found = await db.findOne("releases", {
|
|
6133
|
+
channel_id: `channel:${encodeChannelKey(channel)}`,
|
|
6134
|
+
platform,
|
|
6135
|
+
label
|
|
6136
|
+
});
|
|
6137
|
+
if (found === null) return null;
|
|
6138
|
+
const row = await db.findOne("releases", { id: found.id });
|
|
6139
|
+
if (row === null) return null;
|
|
6140
|
+
const release = toReleaseRow(row);
|
|
6141
|
+
return release.label === label && release.platform === platform ? release : null;
|
|
6142
|
+
},
|
|
6015
6143
|
/** One page of releases through the index its filter names. */
|
|
6016
6144
|
async listReleases(input) {
|
|
6017
6145
|
const { filter } = input;
|
|
@@ -6111,7 +6239,7 @@ const createCoreReads = (db, storage) => {
|
|
|
6111
6239
|
return (await drain$1((page) => db.findMany("channels", {
|
|
6112
6240
|
index: "all",
|
|
6113
6241
|
where: {},
|
|
6114
|
-
limit: PAGE$
|
|
6242
|
+
limit: PAGE$4,
|
|
6115
6243
|
...page
|
|
6116
6244
|
}))).map(toChannelRow);
|
|
6117
6245
|
},
|
|
@@ -6439,6 +6567,313 @@ const NATIVE_BUILD_SUBMISSION_DESTINATIONS = {
|
|
|
6439
6567
|
ios: ["testflight"]
|
|
6440
6568
|
};
|
|
6441
6569
|
//#endregion
|
|
6570
|
+
//#region ../../packages/server/dist/core/labels.mjs
|
|
6571
|
+
/**
|
|
6572
|
+
* The counter of a channel and platform's release labels: one
|
|
6573
|
+
* `label_sequences` row, which every writer of the pair reads and bumps.
|
|
6574
|
+
*/
|
|
6575
|
+
const labelSequenceId = (channelId, platform) => `releases/${platform}/${channelId}`;
|
|
6576
|
+
/** The pairs a channel's counters belong to, which deleting it removes. */
|
|
6577
|
+
const LABEL_PLATFORMS = ["ios", "android"];
|
|
6578
|
+
/**
|
|
6579
|
+
* A channel and platform whose releases written before labels have none
|
|
6580
|
+
* yet, or that has no counter: the write stops before taking a label, the
|
|
6581
|
+
* core labels the pair with `fillLabels`, and the write runs again.
|
|
6582
|
+
*/
|
|
6583
|
+
var NeedsLabelFill = class extends Error {
|
|
6584
|
+
channelId;
|
|
6585
|
+
platform;
|
|
6586
|
+
constructor(channelId, platform) {
|
|
6587
|
+
super(`Release labels of ${platform} ${channelId} need a fill first.`);
|
|
6588
|
+
this.channelId = channelId;
|
|
6589
|
+
this.platform = platform;
|
|
6590
|
+
}
|
|
6591
|
+
};
|
|
6592
|
+
const createLabelAllocator = (tx, used, caughtUp) => {
|
|
6593
|
+
const sequences = /* @__PURE__ */ new Map();
|
|
6594
|
+
return {
|
|
6595
|
+
async next(channelId, platform) {
|
|
6596
|
+
const id = labelSequenceId(channelId, platform);
|
|
6597
|
+
let sequence = sequences.get(id);
|
|
6598
|
+
if (sequence === void 0) {
|
|
6599
|
+
const row = await tx.findOne("label_sequences", { id });
|
|
6600
|
+
if (row === null || !row.is_filled) {
|
|
6601
|
+
const channel = row === null ? await tx.findOne("channels", { id: channelId }) : null;
|
|
6602
|
+
if (channel === null || (channel._refs_releases_channel_id ?? 0) > 0) throw new NeedsLabelFill(channelId, platform);
|
|
6603
|
+
}
|
|
6604
|
+
const read = row?.last_label ?? 0;
|
|
6605
|
+
sequence = {
|
|
6606
|
+
row,
|
|
6607
|
+
read,
|
|
6608
|
+
last: read
|
|
6609
|
+
};
|
|
6610
|
+
sequences.set(id, sequence);
|
|
6611
|
+
used.set(id, {
|
|
6612
|
+
channelId,
|
|
6613
|
+
platform,
|
|
6614
|
+
read
|
|
6615
|
+
});
|
|
6616
|
+
}
|
|
6617
|
+
sequence.last += 1;
|
|
6618
|
+
return sequence.last;
|
|
6619
|
+
},
|
|
6620
|
+
caughtUp(channelId, platform) {
|
|
6621
|
+
caughtUp.set(labelSequenceId(channelId, platform), {
|
|
6622
|
+
channelId,
|
|
6623
|
+
platform
|
|
6624
|
+
});
|
|
6625
|
+
},
|
|
6626
|
+
flush() {
|
|
6627
|
+
for (const [id, { row, read, last }] of sequences) if (row === null) tx.create("label_sequences", {
|
|
6628
|
+
id,
|
|
6629
|
+
last_label: last,
|
|
6630
|
+
is_filled: true
|
|
6631
|
+
});
|
|
6632
|
+
else if (last !== read) tx.update("label_sequences", row, { last_label: last });
|
|
6633
|
+
}
|
|
6634
|
+
};
|
|
6635
|
+
};
|
|
6636
|
+
const FILL_BATCH = 25;
|
|
6637
|
+
const PAGE$3 = 500;
|
|
6638
|
+
/**
|
|
6639
|
+
* Labels a channel and platform's releases that have none, in ID order,
|
|
6640
|
+
* which is the order they were created in, and marks its counter filled:
|
|
6641
|
+
* each batch reads the counter and its rows guarded, so a concurrent fill or
|
|
6642
|
+
* write serializes on the counter and skips what another labeled. With
|
|
6643
|
+
* `dryRun`, it only counts them. Answers how many it labeled.
|
|
6644
|
+
*/
|
|
6645
|
+
const fillLabels = async (db, { channelId, platform }, { dryRun = false } = {}) => {
|
|
6646
|
+
const id = labelSequenceId(channelId, platform);
|
|
6647
|
+
let labeled = 0;
|
|
6648
|
+
let batchSize = FILL_BATCH;
|
|
6649
|
+
const label = async (ids) => {
|
|
6650
|
+
for (let at = 0; at < ids.length;) {
|
|
6651
|
+
const batch = ids.slice(at, at + batchSize);
|
|
6652
|
+
try {
|
|
6653
|
+
labeled += await db.transaction(async (tx) => {
|
|
6654
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
6655
|
+
let last = counter?.last_label ?? 0;
|
|
6656
|
+
let count = 0;
|
|
6657
|
+
for (const releaseId of batch) {
|
|
6658
|
+
const row = await tx.findOne("releases", { id: releaseId });
|
|
6659
|
+
if (row === null || typeof row.label === "number") continue;
|
|
6660
|
+
last += 1;
|
|
6661
|
+
count += 1;
|
|
6662
|
+
tx.update("releases", row, { label: last });
|
|
6663
|
+
}
|
|
6664
|
+
if (counter === null) tx.create("label_sequences", {
|
|
6665
|
+
id,
|
|
6666
|
+
last_label: last,
|
|
6667
|
+
is_filled: false
|
|
6668
|
+
});
|
|
6669
|
+
else if (last !== counter.last_label) tx.update("label_sequences", counter, { last_label: last });
|
|
6670
|
+
return count;
|
|
6671
|
+
});
|
|
6672
|
+
at += batch.length;
|
|
6673
|
+
} catch (error) {
|
|
6674
|
+
if (batchSize > 1 && error instanceof DatabaseConstraintError && error.reason === "too_large") {
|
|
6675
|
+
batchSize = Math.max(1, Math.floor(batchSize / 2));
|
|
6676
|
+
continue;
|
|
6677
|
+
}
|
|
6678
|
+
throw error;
|
|
6679
|
+
}
|
|
6680
|
+
}
|
|
6681
|
+
};
|
|
6682
|
+
let cursor;
|
|
6683
|
+
do {
|
|
6684
|
+
const page = await db.findMany("releases", {
|
|
6685
|
+
index: "byChannelPlatform",
|
|
6686
|
+
where: {
|
|
6687
|
+
channel_id: channelId,
|
|
6688
|
+
platform
|
|
6689
|
+
},
|
|
6690
|
+
limit: PAGE$3,
|
|
6691
|
+
...cursor === void 0 ? {} : { cursor }
|
|
6692
|
+
});
|
|
6693
|
+
const unlabeled = page.rows.filter((row) => typeof row.label !== "number").map((row) => row.id);
|
|
6694
|
+
if (dryRun) labeled += unlabeled.length;
|
|
6695
|
+
else await label(unlabeled);
|
|
6696
|
+
cursor = page.next;
|
|
6697
|
+
} while (cursor !== void 0);
|
|
6698
|
+
if (dryRun) return labeled;
|
|
6699
|
+
await db.transaction(async (tx) => {
|
|
6700
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
6701
|
+
if (counter === null) tx.create("label_sequences", {
|
|
6702
|
+
id,
|
|
6703
|
+
last_label: 0,
|
|
6704
|
+
is_filled: true
|
|
6705
|
+
});
|
|
6706
|
+
else if (!counter.is_filled) tx.update("label_sequences", counter, { is_filled: true });
|
|
6707
|
+
});
|
|
6708
|
+
return labeled;
|
|
6709
|
+
};
|
|
6710
|
+
/**
|
|
6711
|
+
* Reads what a pair's fill writes, its counter and its label index, without
|
|
6712
|
+
* writing: a database without release labels' schema, such as one a 1.2
|
|
6713
|
+
* prerelease migrated, fails here as the fill would. The schema is the
|
|
6714
|
+
* database's, so one pair tells. Two reads.
|
|
6715
|
+
*/
|
|
6716
|
+
const probeLabelSchema = async (db, { channelId, platform }) => {
|
|
6717
|
+
await db.findOne("label_sequences", { id: labelSequenceId(channelId, platform) });
|
|
6718
|
+
await db.findMany("releases", {
|
|
6719
|
+
index: "byLabel",
|
|
6720
|
+
where: {
|
|
6721
|
+
channel_id: channelId,
|
|
6722
|
+
platform,
|
|
6723
|
+
label: 0
|
|
6724
|
+
},
|
|
6725
|
+
limit: 1
|
|
6726
|
+
});
|
|
6727
|
+
};
|
|
6728
|
+
const REPAIRS = 4;
|
|
6729
|
+
const RACES = 32;
|
|
6730
|
+
/**
|
|
6731
|
+
* Runs a release write that takes labels, in one transaction with the
|
|
6732
|
+
* counters it bumps. A pair that still needs its fill is filled, and the
|
|
6733
|
+
* write runs again; so is a pair whose catch-up made the write too large for
|
|
6734
|
+
* the store. A label another row holds, such as an index item a release
|
|
6735
|
+
* deleted by a server of an earlier release left on a key-value store, is
|
|
6736
|
+
* skipped: its counters move past it and the write runs again.
|
|
6737
|
+
*/
|
|
6738
|
+
const writeWithLabels = async (db, write) => {
|
|
6739
|
+
const filled = /* @__PURE__ */ new Set();
|
|
6740
|
+
const fill = async (pairs) => {
|
|
6741
|
+
for (const pair of pairs) {
|
|
6742
|
+
filled.add(labelSequenceId(pair.channelId, pair.platform));
|
|
6743
|
+
await fillLabels(db, pair);
|
|
6744
|
+
}
|
|
6745
|
+
};
|
|
6746
|
+
for (let repairs = 0, races = 0;;) {
|
|
6747
|
+
const used = /* @__PURE__ */ new Map();
|
|
6748
|
+
const caughtUp = /* @__PURE__ */ new Map();
|
|
6749
|
+
try {
|
|
6750
|
+
return await db.transaction(async (tx) => {
|
|
6751
|
+
used.clear();
|
|
6752
|
+
caughtUp.clear();
|
|
6753
|
+
const labels = createLabelAllocator(tx, used, caughtUp);
|
|
6754
|
+
const result = await write(tx, labels);
|
|
6755
|
+
labels.flush();
|
|
6756
|
+
return result;
|
|
6757
|
+
});
|
|
6758
|
+
} catch (error) {
|
|
6759
|
+
const needs = error instanceof NeedsLabelFill ? [error] : error instanceof DatabaseConstraintError && error.reason === "too_large" ? [...caughtUp.values()] : [];
|
|
6760
|
+
if (needs.length > 0) {
|
|
6761
|
+
const fresh = needs.some(({ channelId, platform }) => !filled.has(labelSequenceId(channelId, platform)));
|
|
6762
|
+
if (fresh || repairs < REPAIRS) {
|
|
6763
|
+
if (!fresh) repairs += 1;
|
|
6764
|
+
await fill(needs);
|
|
6765
|
+
continue;
|
|
6766
|
+
}
|
|
6767
|
+
}
|
|
6768
|
+
if (error instanceof DatabaseConstraintError && error.reason === "unique" && error.model === "releases" && used.size > 0) {
|
|
6769
|
+
if (await db.transaction(async (tx) => {
|
|
6770
|
+
const moves = [];
|
|
6771
|
+
for (const [id, { channelId, read }] of used) {
|
|
6772
|
+
const counter = await tx.findOne("label_sequences", { id });
|
|
6773
|
+
if (counter !== null) {
|
|
6774
|
+
if (counter.last_label !== read) return false;
|
|
6775
|
+
moves.push(() => tx.update("label_sequences", counter, { last_label: read + 1 }));
|
|
6776
|
+
continue;
|
|
6777
|
+
}
|
|
6778
|
+
const channel = await tx.findOne("channels", { id: channelId });
|
|
6779
|
+
if (channel === null || (channel._refs_releases_channel_id ?? 0) > 0) return false;
|
|
6780
|
+
moves.push(() => tx.create("label_sequences", {
|
|
6781
|
+
id,
|
|
6782
|
+
last_label: read + 1,
|
|
6783
|
+
is_filled: true
|
|
6784
|
+
}));
|
|
6785
|
+
}
|
|
6786
|
+
for (const move of moves) move();
|
|
6787
|
+
return true;
|
|
6788
|
+
}) ? (repairs += 1) <= REPAIRS : (races += 1) <= RACES) continue;
|
|
6789
|
+
}
|
|
6790
|
+
throw error;
|
|
6791
|
+
}
|
|
6792
|
+
}
|
|
6793
|
+
};
|
|
6794
|
+
/**
|
|
6795
|
+
* Labels a scope's releases a server of an earlier release wrote after its
|
|
6796
|
+
* newest labeled one, oldest first, before the write takes its own label:
|
|
6797
|
+
* `latest` is the scope's newest release, so a labeled one costs no read.
|
|
6798
|
+
* Answers the labels it gave, by release ID.
|
|
6799
|
+
*/
|
|
6800
|
+
const catchUpLabels = async (tx, labels, latest) => {
|
|
6801
|
+
const given = /* @__PURE__ */ new Map();
|
|
6802
|
+
if (latest === null || typeof latest.label === "number") return given;
|
|
6803
|
+
const unlabeled = [];
|
|
6804
|
+
let cursor;
|
|
6805
|
+
scan: do {
|
|
6806
|
+
const page = await tx.findMany("releases", {
|
|
6807
|
+
index: "byScope",
|
|
6808
|
+
where: { scope_key: latest.scope_key },
|
|
6809
|
+
order: "desc",
|
|
6810
|
+
limit: FILL_BATCH,
|
|
6811
|
+
...cursor === void 0 ? {} : { cursor }
|
|
6812
|
+
});
|
|
6813
|
+
for (const row of page.rows) {
|
|
6814
|
+
if (typeof row.label === "number") break scan;
|
|
6815
|
+
unlabeled.push(row);
|
|
6816
|
+
}
|
|
6817
|
+
cursor = page.next;
|
|
6818
|
+
} while (cursor !== void 0);
|
|
6819
|
+
labels.caughtUp(latest.channel_id, latest.platform);
|
|
6820
|
+
for (const row of unlabeled.reverse()) {
|
|
6821
|
+
const { id, channel_id, platform } = toReleaseRow(row);
|
|
6822
|
+
const label = await labels.next(channel_id, platform);
|
|
6823
|
+
tx.update("releases", row, { label });
|
|
6824
|
+
given.set(id, label);
|
|
6825
|
+
}
|
|
6826
|
+
return given;
|
|
6827
|
+
};
|
|
6828
|
+
/**
|
|
6829
|
+
* The channels and platforms whose releases need labels: a scope whose
|
|
6830
|
+
* newest release has none, or a pair without a filled counter. Releases a
|
|
6831
|
+
* server of an earlier release wrote in a filled pair come after its
|
|
6832
|
+
* labeled ones in their scope, so the newest release of each scope tells.
|
|
6833
|
+
* Two reads per scope, one per pair.
|
|
6834
|
+
*/
|
|
6835
|
+
const pendingLabelPairs = async (db) => {
|
|
6836
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
6837
|
+
for (let last = "";;) {
|
|
6838
|
+
const { rows } = await db.findMany("releases", {
|
|
6839
|
+
index: "scopes",
|
|
6840
|
+
where: {},
|
|
6841
|
+
limit: 1,
|
|
6842
|
+
range: { gt: last }
|
|
6843
|
+
});
|
|
6844
|
+
if (rows[0] === void 0) break;
|
|
6845
|
+
last = rows[0].scope_key;
|
|
6846
|
+
const { rows: newest } = await db.findMany("releases", {
|
|
6847
|
+
index: "byScope",
|
|
6848
|
+
where: { scope_key: last },
|
|
6849
|
+
order: "desc",
|
|
6850
|
+
limit: 1
|
|
6851
|
+
});
|
|
6852
|
+
if (newest[0] === void 0) continue;
|
|
6853
|
+
const { channel_id: channelId, platform, label } = toReleaseRow(newest[0]);
|
|
6854
|
+
const id = labelSequenceId(channelId, platform);
|
|
6855
|
+
const pair = pairs.get(id) ?? {
|
|
6856
|
+
channelId,
|
|
6857
|
+
platform,
|
|
6858
|
+
pending: false
|
|
6859
|
+
};
|
|
6860
|
+
pair.pending ||= label === null;
|
|
6861
|
+
pairs.set(id, pair);
|
|
6862
|
+
}
|
|
6863
|
+
const pending = [];
|
|
6864
|
+
for (const [id, { channelId, platform, pending: unlabeled }] of pairs) {
|
|
6865
|
+
if (!unlabeled) {
|
|
6866
|
+
const counter = await db.findOne("label_sequences", { id });
|
|
6867
|
+
if (counter !== null && counter.is_filled) continue;
|
|
6868
|
+
}
|
|
6869
|
+
pending.push({
|
|
6870
|
+
channelId,
|
|
6871
|
+
platform
|
|
6872
|
+
});
|
|
6873
|
+
}
|
|
6874
|
+
return pending;
|
|
6875
|
+
};
|
|
6876
|
+
//#endregion
|
|
6442
6877
|
//#region ../../packages/server/dist/core/writes.mjs
|
|
6443
6878
|
const PAGE$2 = 500;
|
|
6444
6879
|
/** Moves one bundle into or out of its platform's total and the overall total. */
|
|
@@ -6519,7 +6954,11 @@ const insertChannel = async (db, row) => {
|
|
|
6519
6954
|
throw error;
|
|
6520
6955
|
}
|
|
6521
6956
|
};
|
|
6522
|
-
/**
|
|
6957
|
+
/**
|
|
6958
|
+
* Deletes a channel no release or native build uses, with its label
|
|
6959
|
+
* counters, so one created again with its name starts at 1: 3 reads,
|
|
6960
|
+
* 1 query, 1 write.
|
|
6961
|
+
*/
|
|
6523
6962
|
const deleteChannel = (db, id) => db.transaction(async (tx) => {
|
|
6524
6963
|
const row = await tx.findOne("channels", { id });
|
|
6525
6964
|
if (row === null) return {
|
|
@@ -6539,6 +6978,10 @@ const deleteChannel = (db, id) => db.transaction(async (tx) => {
|
|
|
6539
6978
|
deleted: false,
|
|
6540
6979
|
reason: "not_empty"
|
|
6541
6980
|
};
|
|
6981
|
+
for (const platform of LABEL_PLATFORMS) {
|
|
6982
|
+
const counter = await tx.findOne("label_sequences", { id: labelSequenceId(id, platform) });
|
|
6983
|
+
if (counter !== null) await tx.delete("label_sequences", counter);
|
|
6984
|
+
}
|
|
6542
6985
|
await tx.delete("channels", row);
|
|
6543
6986
|
return { deleted: true };
|
|
6544
6987
|
});
|
|
@@ -7075,15 +7518,15 @@ const enabledIn = (scopeKey, cursor) => ({
|
|
|
7075
7518
|
});
|
|
7076
7519
|
/** A scope's enabled releases, all of them, under the catalog's guard. */
|
|
7077
7520
|
const enabledReleases = (tx, scopeKey) => drainReleases((cursor) => tx.findMany("releases", enabledIn(scopeKey, cursor)));
|
|
7078
|
-
/** The scope's newest release
|
|
7079
|
-
const
|
|
7521
|
+
/** The scope's newest release: `byScope` descending, limit 1. */
|
|
7522
|
+
const latestRelease = async (tx, scopeKey) => {
|
|
7080
7523
|
const { rows } = await tx.findMany("releases", {
|
|
7081
7524
|
index: "byScope",
|
|
7082
7525
|
where: { scope_key: scopeKey },
|
|
7083
7526
|
order: "desc",
|
|
7084
7527
|
limit: 1
|
|
7085
7528
|
});
|
|
7086
|
-
return rows[0]
|
|
7529
|
+
return rows[0] === void 0 ? null : toReleaseRow(rows[0]);
|
|
7087
7530
|
};
|
|
7088
7531
|
/** The scope's next catalog generation, compiled as `compilation`. */
|
|
7089
7532
|
const nextCatalog = (scope, stored, compilation, updatedAtMs) => {
|
|
@@ -7145,11 +7588,16 @@ const readCatalog = async (tx, scopeKey) => {
|
|
|
7145
7588
|
const assertHistory = (stored, hasReleases) => {
|
|
7146
7589
|
if (stored.catalog === null && hasReleases) fail$1("CATALOG_IDENTITY_MISSING", "Catalog history is missing. Restore its catalog row from backup before rebuilding or deploying.");
|
|
7147
7590
|
};
|
|
7148
|
-
/**
|
|
7149
|
-
|
|
7591
|
+
/**
|
|
7592
|
+
* One release change and its scope's next catalog, inside `tx`. An insert
|
|
7593
|
+
* takes its channel and platform's next label from `labels`, after labeling
|
|
7594
|
+
* the releases a server of an earlier release wrote in the scope since its
|
|
7595
|
+
* last labeled one.
|
|
7596
|
+
*/
|
|
7597
|
+
const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }, labels) => {
|
|
7150
7598
|
checkScope(scope);
|
|
7151
7599
|
const stored = await readCatalog(tx, scope.scopeKey);
|
|
7152
|
-
|
|
7600
|
+
let enabled = await enabledReleases(tx, scope.scopeKey);
|
|
7153
7601
|
if (bundle !== void 0) {
|
|
7154
7602
|
insertBundle(tx, bundle.row);
|
|
7155
7603
|
for (const patch of bundle.patches) tx.create("bundle_patches", patch);
|
|
@@ -7157,14 +7605,22 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
7157
7605
|
let before = null;
|
|
7158
7606
|
let release;
|
|
7159
7607
|
if (change.operation === "insert") {
|
|
7160
|
-
|
|
7608
|
+
if (labels === void 0) throw new Error("A release insert takes its label from an allocator.");
|
|
7609
|
+
const newest = await latestRelease(tx, scope.scopeKey);
|
|
7610
|
+
const latest = newest?.id ?? null;
|
|
7161
7611
|
assertHistory(stored, latest !== null);
|
|
7162
7612
|
const floor = [latest, bundle && isUUIDv7(bundle.row.id) ? bundle.row.id : null].filter((id) => id !== null).sort().at(-1);
|
|
7163
7613
|
const id = change.row.id ?? createUUIDv7After(floor ?? null);
|
|
7164
7614
|
if (latest !== null && id <= latest) fail$1("NON_MONOTONIC_RELEASE_ID", `Release "${id}" must sort after "${latest}"`);
|
|
7615
|
+
const given = await catchUpLabels(tx, labels, newest);
|
|
7616
|
+
if (given.size > 0) enabled = enabled.map((row) => given.has(row.id) ? {
|
|
7617
|
+
...row,
|
|
7618
|
+
label: given.get(row.id)
|
|
7619
|
+
} : row);
|
|
7165
7620
|
release = {
|
|
7166
7621
|
...change.row,
|
|
7167
|
-
id
|
|
7622
|
+
id,
|
|
7623
|
+
label: await labels.next(scope.channelId, scope.platform)
|
|
7168
7624
|
};
|
|
7169
7625
|
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");
|
|
7170
7626
|
tx.create("releases", release);
|
|
@@ -7177,8 +7633,9 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
7177
7633
|
await tx.delete("releases", row);
|
|
7178
7634
|
release = null;
|
|
7179
7635
|
} else {
|
|
7636
|
+
const { label: _label, ...update } = change.update;
|
|
7180
7637
|
const set = {
|
|
7181
|
-
...
|
|
7638
|
+
...update,
|
|
7182
7639
|
revision: before.revision + 1
|
|
7183
7640
|
};
|
|
7184
7641
|
tx.update("releases", row, set);
|
|
@@ -7206,14 +7663,27 @@ const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }) => {
|
|
|
7206
7663
|
*/
|
|
7207
7664
|
const changeReleases = (db, inputs) => {
|
|
7208
7665
|
if (new Set(inputs.map(({ scope }) => scope.scopeKey)).size !== inputs.length) fail$1("INVALID_SCOPE", "A batch cannot change one catalog scope twice");
|
|
7209
|
-
return db
|
|
7666
|
+
return writeWithLabels(db, async (tx, labels) => {
|
|
7210
7667
|
const results = [];
|
|
7211
|
-
for (const input of inputs) results.push(await changeRelease(tx, input));
|
|
7668
|
+
for (const input of inputs) results.push(await changeRelease(tx, input, labels));
|
|
7212
7669
|
return results;
|
|
7213
7670
|
});
|
|
7214
7671
|
};
|
|
7215
7672
|
/** Whether `current` is what the scope's enabled releases compile to. */
|
|
7216
7673
|
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;
|
|
7674
|
+
/** A compiled payload with its descriptors' labels left out. */
|
|
7675
|
+
const withoutLabels = (payload) => {
|
|
7676
|
+
const parsed = JSON.parse(payload);
|
|
7677
|
+
return JSON.stringify({
|
|
7678
|
+
...parsed,
|
|
7679
|
+
releaseDescriptors: (parsed.releaseDescriptors ?? []).map(({ label: _label, ...descriptor }) => descriptor)
|
|
7680
|
+
});
|
|
7681
|
+
};
|
|
7682
|
+
/**
|
|
7683
|
+
* Whether `projected` differs from `current` only by release labels, as a
|
|
7684
|
+
* catalog compiled before its releases had them does.
|
|
7685
|
+
*/
|
|
7686
|
+
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);
|
|
7217
7687
|
/** The scope a catalog row names. */
|
|
7218
7688
|
const catalogRowScope = (row) => ({
|
|
7219
7689
|
channelId: row.channel_id,
|
|
@@ -7239,18 +7709,20 @@ const preflightRebuild = async (db, scopeKey, updatedAtMs) => {
|
|
|
7239
7709
|
const enabled = await drainReleases((cursor) => db.findMany("releases", enabledIn(scopeKey, cursor)));
|
|
7240
7710
|
const compilation = await compileScope(scope, enabled);
|
|
7241
7711
|
const changed = !isCurrent(scope, current, compilation);
|
|
7712
|
+
const projectedCatalog = changed ? nextCatalog(scope, { catalog: current }, compilation, updatedAtMs) : current;
|
|
7242
7713
|
return {
|
|
7243
7714
|
changed,
|
|
7715
|
+
labelsOnly: changed && differsInLabelsOnly(current, projectedCatalog),
|
|
7244
7716
|
currentCatalog: current,
|
|
7245
7717
|
diagnostics: compilation.diagnostics,
|
|
7246
|
-
projectedCatalog
|
|
7718
|
+
projectedCatalog
|
|
7247
7719
|
};
|
|
7248
7720
|
};
|
|
7249
7721
|
/** Recompiles a scope's catalog from its enabled releases inside `tx`; an unchanged catalog is not rewritten. */
|
|
7250
7722
|
const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
7251
7723
|
checkScope(scope);
|
|
7252
7724
|
const stored = await readCatalog(tx, scope.scopeKey);
|
|
7253
|
-
assertHistory(stored, await
|
|
7725
|
+
assertHistory(stored, await latestRelease(tx, scope.scopeKey) !== null);
|
|
7254
7726
|
const enabled = await enabledReleases(tx, scope.scopeKey);
|
|
7255
7727
|
const compilation = await compileScope(scope, enabled);
|
|
7256
7728
|
const current = stored.catalog;
|
|
@@ -7270,6 +7742,7 @@ const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
|
7270
7742
|
};
|
|
7271
7743
|
//#endregion
|
|
7272
7744
|
//#region ../../packages/server/dist/core/operations.mjs
|
|
7745
|
+
const CATALOG_PAGE = 100;
|
|
7273
7746
|
/** Carries a preflight's result out of the transaction it stops, so nothing is written. */
|
|
7274
7747
|
var Preflight = class extends Error {
|
|
7275
7748
|
result;
|
|
@@ -7501,7 +7974,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
7501
7974
|
if (targetChannel.length === 0) throw new ReleaseManagementError("TARGET_RELEASE_INVALID", "Promotion requires a target channel.");
|
|
7502
7975
|
const channel = await ensureChannel(targetChannel);
|
|
7503
7976
|
const updatedAtMs = now();
|
|
7504
|
-
return db
|
|
7977
|
+
return writeWithLabels(db, async (tx, labels) => {
|
|
7505
7978
|
const { release: source, scope: sourceScope } = await loadTarget(tx, input);
|
|
7506
7979
|
checkSource(source);
|
|
7507
7980
|
const targetScope = scopeOf$1(channel, source.platform, source.fingerprint_hash);
|
|
@@ -7529,12 +8002,13 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
7529
8002
|
},
|
|
7530
8003
|
updatedAtMs
|
|
7531
8004
|
}) : null;
|
|
8005
|
+
const { label: _label, ...copied } = source;
|
|
7532
8006
|
const target = await changeRelease(tx, {
|
|
7533
8007
|
scope: targetScope,
|
|
7534
8008
|
change: {
|
|
7535
8009
|
operation: "insert",
|
|
7536
8010
|
row: {
|
|
7537
|
-
...
|
|
8011
|
+
...copied,
|
|
7538
8012
|
id: createUUIDv7After(floor ?? null, updatedAtMs),
|
|
7539
8013
|
revision: 1,
|
|
7540
8014
|
scope_key: targetScope.scopeKey,
|
|
@@ -7549,7 +8023,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
7549
8023
|
}
|
|
7550
8024
|
},
|
|
7551
8025
|
updatedAtMs
|
|
7552
|
-
});
|
|
8026
|
+
}, labels);
|
|
7553
8027
|
return {
|
|
7554
8028
|
source: moved === null ? null : mutationResult(moved),
|
|
7555
8029
|
target: mutationResult(target)
|
|
@@ -7567,6 +8041,38 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
7567
8041
|
});
|
|
7568
8042
|
},
|
|
7569
8043
|
preflightReleaseCatalogRebuild: (scopeKey) => preflightRebuild(db, scopeKey, now()),
|
|
8044
|
+
fillReleaseLabels: async ({ dryRun = false, catalogs = true } = {}) => {
|
|
8045
|
+
let releases = 0;
|
|
8046
|
+
const pairs = await pendingLabelPairs(db);
|
|
8047
|
+
if (dryRun && pairs[0] !== void 0) await probeLabelSchema(db, pairs[0]);
|
|
8048
|
+
for (const pair of pairs) releases += await fillLabels(db, pair, { dryRun });
|
|
8049
|
+
let rebuilt = 0;
|
|
8050
|
+
if (catalogs) {
|
|
8051
|
+
let cursor;
|
|
8052
|
+
do {
|
|
8053
|
+
const page = await db.findMany("release_catalogs", {
|
|
8054
|
+
index: "all",
|
|
8055
|
+
where: {},
|
|
8056
|
+
limit: CATALOG_PAGE,
|
|
8057
|
+
...cursor === void 0 ? {} : { cursor }
|
|
8058
|
+
});
|
|
8059
|
+
for (const row of page.rows) {
|
|
8060
|
+
if (row.is_tombstone) continue;
|
|
8061
|
+
const preflight = await preflightRebuild(db, row.scope_key, now()).catch(() => null);
|
|
8062
|
+
if (preflight === null || !preflight.labelsOnly) continue;
|
|
8063
|
+
rebuilt += 1;
|
|
8064
|
+
if (dryRun) continue;
|
|
8065
|
+
const updatedAtMs = now();
|
|
8066
|
+
await db.transaction((tx) => rebuildScope(tx, catalogRowScope(toCatalogRow(row)), updatedAtMs));
|
|
8067
|
+
}
|
|
8068
|
+
cursor = page.next;
|
|
8069
|
+
} while (cursor !== void 0);
|
|
8070
|
+
}
|
|
8071
|
+
return {
|
|
8072
|
+
releases,
|
|
8073
|
+
catalogs: rebuilt
|
|
8074
|
+
};
|
|
8075
|
+
},
|
|
7570
8076
|
ensureChannel,
|
|
7571
8077
|
deleteChannel: (id) => deleteChannel(db, id),
|
|
7572
8078
|
updateBundle: (id, update) => db.transaction(async (tx) => {
|
|
@@ -8137,6 +8643,30 @@ const createAdminRouteHandlers = () => ({
|
|
|
8137
8643
|
return row === null ? notFound() : json$2({ data: row });
|
|
8138
8644
|
}),
|
|
8139
8645
|
rebuildReleaseCatalog: onCore(async (core, _request, params) => json$2({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
|
|
8646
|
+
/**
|
|
8647
|
+
* The release a label names, or `null`: never 404, which tells a client
|
|
8648
|
+
* the server has no such route.
|
|
8649
|
+
*/
|
|
8650
|
+
getReleaseByLabel: onCore(async (core, request) => {
|
|
8651
|
+
const url = new URL(request.url);
|
|
8652
|
+
const channel = url.searchParams.get("channel");
|
|
8653
|
+
const platform = platformOf(url);
|
|
8654
|
+
const label = Number(url.searchParams.get("label"));
|
|
8655
|
+
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.");
|
|
8656
|
+
return json$2({ data: await core.getReleaseByLabel({
|
|
8657
|
+
channel,
|
|
8658
|
+
platform,
|
|
8659
|
+
label
|
|
8660
|
+
}) });
|
|
8661
|
+
}),
|
|
8662
|
+
fillReleaseLabels: onCore(async (core, request) => {
|
|
8663
|
+
const body = await request.json().catch(() => ({}));
|
|
8664
|
+
const input = body !== null && typeof body === "object" ? body : {};
|
|
8665
|
+
return json$2({ data: await core.fillReleaseLabels({
|
|
8666
|
+
dryRun: input.dryRun === true,
|
|
8667
|
+
catalogs: input.catalogs !== false
|
|
8668
|
+
}) });
|
|
8669
|
+
}),
|
|
8140
8670
|
updateBundle: onCore(async (core, request, params) => {
|
|
8141
8671
|
const bundleId = requireRouteParam(params, "id");
|
|
8142
8672
|
const update = bundleUpdateOf(await request.json(), bundleId);
|
|
@@ -8364,6 +8894,16 @@ const ADMIN_ROUTES = [
|
|
|
8364
8894
|
path: "/release-scopes",
|
|
8365
8895
|
handler: "listReleaseScopeKeys"
|
|
8366
8896
|
},
|
|
8897
|
+
{
|
|
8898
|
+
method: "GET",
|
|
8899
|
+
path: "/release-labels",
|
|
8900
|
+
handler: "getReleaseByLabel"
|
|
8901
|
+
},
|
|
8902
|
+
{
|
|
8903
|
+
method: "POST",
|
|
8904
|
+
path: "/release-labels/fill",
|
|
8905
|
+
handler: "fillReleaseLabels"
|
|
8906
|
+
},
|
|
8367
8907
|
{
|
|
8368
8908
|
method: "POST",
|
|
8369
8909
|
path: "/release-catalogs/:scopeKey/rebuild",
|
package/dist/init/index.cjs
CHANGED
|
@@ -7949,6 +7949,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7949
7949
|
let clientCredential;
|
|
7950
7950
|
try {
|
|
7951
7951
|
await migrateFirebaseDatabase(databaseConfig, server.plugins);
|
|
7952
|
+
await (0, _hot_updater_cli_tools.fillReleaseLabels)(server);
|
|
7952
7953
|
clientCredential = await (0, _hot_updater_cli_tools.provisionClientCredential)(server, {
|
|
7953
7954
|
env: initInputEnv,
|
|
7954
7955
|
name: "Firebase init"
|
package/dist/init/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import { ConfigBuilder, HOT_UPDATER_SERVER_PACKAGE_VERSION_ENV, InitError, LegacyInfrastructureError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInitProviderInputs, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveHotUpdaterServerVersion, resolveInitProviderInput, resolvePackageVersion, transformEnv, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
4
|
+
import { ConfigBuilder, HOT_UPDATER_SERVER_PACKAGE_VERSION_ENV, InitError, LegacyInfrastructureError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInitProviderInputs, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, fillReleaseLabels, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveHotUpdaterServerVersion, resolveInitProviderInput, resolvePackageVersion, transformEnv, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
|
|
5
5
|
import { apiKeys, insights, remoteConfig } from "@hot-updater/server/plugins";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
|
|
@@ -7942,6 +7942,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7942
7942
|
let clientCredential;
|
|
7943
7943
|
try {
|
|
7944
7944
|
await migrateFirebaseDatabase(databaseConfig, server.plugins);
|
|
7945
|
+
await fillReleaseLabels(server);
|
|
7945
7946
|
clientCredential = await provisionClientCredential(server, {
|
|
7946
7947
|
env: initInputEnv,
|
|
7947
7948
|
name: "Firebase init"
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/firebase",
|
|
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
|
"types": "dist/index.d.cts",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"hono": "4.12.34",
|
|
40
40
|
"google-auth-library": "10.7.0",
|
|
41
|
-
"@hot-updater/
|
|
42
|
-
"@hot-updater/
|
|
43
|
-
"@hot-updater/plugin-core": "1.2.0-rc.
|
|
44
|
-
"@hot-updater/server": "1.2.0-rc.
|
|
41
|
+
"@hot-updater/cli-tools": "1.2.0-rc.51",
|
|
42
|
+
"@hot-updater/protocol": "1.2.0-rc.51",
|
|
43
|
+
"@hot-updater/plugin-core": "1.2.0-rc.51",
|
|
44
|
+
"@hot-updater/server": "1.2.0-rc.51"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"firebase-tools": "15.29.0",
|
|
57
57
|
"fkill": "^9.0.0",
|
|
58
58
|
"mime": "^4.0.4",
|
|
59
|
-
"@hot-updater/mock": "1.2.0-rc.
|
|
60
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
59
|
+
"@hot-updater/mock": "1.2.0-rc.51",
|
|
60
|
+
"@hot-updater/test-utils": "1.2.0-rc.51"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"firebase-admin": ">=11.10.0",
|