@hot-updater/firebase 1.1.17 → 1.1.19
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 +110 -46
- package/package.json +7 -7
|
@@ -1900,6 +1900,23 @@ const SETTINGS_TABLE = {
|
|
|
1900
1900
|
/** The engine's storage-layout generation; it changes only with a migration. */
|
|
1901
1901
|
const ENGINE_SCHEMA_KEY = "schema.engine";
|
|
1902
1902
|
const CORE_SCHEMA_KEY = "schema.core";
|
|
1903
|
+
/** Compares dotted numeric versions, such as "1" and "1.2.0"; NaN when either is not one. */
|
|
1904
|
+
const compareVersions = (left, right) => {
|
|
1905
|
+
const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
|
|
1906
|
+
const [a, b] = [parse(left), parse(right)];
|
|
1907
|
+
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
1908
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
1909
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
1910
|
+
if (difference !== 0) return difference;
|
|
1911
|
+
}
|
|
1912
|
+
return 0;
|
|
1913
|
+
};
|
|
1914
|
+
/**
|
|
1915
|
+
* The `schema.core` a newer release recorded, which `hot-updater db migrate`
|
|
1916
|
+
* never moves back: the fix is to upgrade, not to migrate.
|
|
1917
|
+
*/
|
|
1918
|
+
const newerCore = (settings) => settings.find(({ key, expected, found }) => key === CORE_SCHEMA_KEY && found !== null && compareVersions(found, expected) > 0);
|
|
1919
|
+
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.`;
|
|
1903
1920
|
const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
|
|
1904
1921
|
const settingMessage = (adapterName, { key, expected, found }) => `Hot Updater schema setting "${key}" for ${adapterName} is ${found === null ? "missing" : `"${found}"`}; expected "${expected}". Run \`hot-updater db migrate\`.`;
|
|
1905
1922
|
/** The plugin a `schema.<id>` setting belongs to; undefined for core's and the engine's. */
|
|
@@ -1908,7 +1925,10 @@ const listed = (items) => items.length < 2 ? items.join("") : `${items.slice(0,
|
|
|
1908
1925
|
/** How to create plugins' tables when the fence was given no fix. */
|
|
1909
1926
|
const PLUGIN_TABLES_FIX = "Run `hot-updater db migrate`. A managed server runs only its provider's plugins, and rerunning `hot-updater init --provider <provider>` applies the provider's migrations. Run `hot-updater db` commands in the server's project: they load the server file named on the command line, or src/hotUpdater.* or src/db.*, and don't read hot-updater.config.ts.";
|
|
1910
1927
|
const pluginsMessage = (adapterName, plugins, settings, fix) => `The tables of ${plugins.length === 1 ? "plugin" : "plugins"} ${listed(plugins.map((id) => `"${id}"`))} are not migrated on ${adapterName}: schema ${settings.length === 1 ? "setting" : "settings"} ${settings.map(stored).join(", and ")}. ${fix}`;
|
|
1911
|
-
/**
|
|
1928
|
+
/**
|
|
1929
|
+
* The database needs `hot-updater db migrate`, a new database, or a newer
|
|
1930
|
+
* Hot Updater; the handler answers 503.
|
|
1931
|
+
*/
|
|
1912
1932
|
var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
1913
1933
|
adapterName;
|
|
1914
1934
|
currentVersion;
|
|
@@ -1923,7 +1943,8 @@ var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
|
1923
1943
|
constructor(adapterName, currentVersion, setting, options) {
|
|
1924
1944
|
const settings = options?.settings ?? (setting === void 0 ? [] : [setting]);
|
|
1925
1945
|
const plugins = settings.flatMap((mismatch) => pluginOf(mismatch) ?? []);
|
|
1926
|
-
|
|
1946
|
+
const newer = newerCore(settings);
|
|
1947
|
+
super(newer !== void 0 ? newerMessage(adapterName, newer) : setting === void 0 ? currentVersion === void 0 ? `Hot Updater database schema is not initialized for ${adapterName}. Run \`hot-updater db migrate\` before using this adapter.` : `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 ?? PLUGIN_TABLES_FIX) : settingMessage(adapterName, setting), options?.cause === void 0 ? void 0 : { cause: options.cause });
|
|
1927
1948
|
this.adapterName = adapterName;
|
|
1928
1949
|
this.currentVersion = currentVersion;
|
|
1929
1950
|
this.setting = setting;
|
|
@@ -2018,45 +2039,6 @@ const METER = Symbol.for("@hot-updater/plugin-core/read-meter");
|
|
|
2018
2039
|
/** The meter `meterReads` gave `database`, if it did. */
|
|
2019
2040
|
const readMeterOf = (database) => typeof database === "object" && database !== null ? database[METER] : void 0;
|
|
2020
2041
|
//#endregion
|
|
2021
|
-
//#region ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
2022
|
-
const storedSettings = async (adapter, keys) => {
|
|
2023
|
-
const rows = await readSettings(adapter, keys);
|
|
2024
|
-
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
2025
|
-
};
|
|
2026
|
-
/** Writes the settings rows after every table exists. */
|
|
2027
|
-
const writeSchemaSettings = async (adapter, adapterName, settings) => {
|
|
2028
|
-
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
2029
|
-
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
2030
|
-
const row = stored.get(key);
|
|
2031
|
-
if (row === null || row === void 0) return [{
|
|
2032
|
-
type: "insert",
|
|
2033
|
-
table: SETTINGS_TABLE,
|
|
2034
|
-
row: {
|
|
2035
|
-
key,
|
|
2036
|
-
value,
|
|
2037
|
-
_v: 0
|
|
2038
|
-
}
|
|
2039
|
-
}];
|
|
2040
|
-
if (row.value === value) return [];
|
|
2041
|
-
return [{
|
|
2042
|
-
type: "patch",
|
|
2043
|
-
table: SETTINGS_TABLE,
|
|
2044
|
-
key: [key],
|
|
2045
|
-
set: { value },
|
|
2046
|
-
guard: { v: Number(row._v) },
|
|
2047
|
-
previous: row
|
|
2048
|
-
}];
|
|
2049
|
-
});
|
|
2050
|
-
if (ops.length === 0) return;
|
|
2051
|
-
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
2052
|
-
};
|
|
2053
|
-
/** Creates or updates every table, then writes the settings rows last. */
|
|
2054
|
-
const migrateSchema = async (adapter, adapterName, tables, settings) => {
|
|
2055
|
-
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2056
|
-
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2057
|
-
await writeSchemaSettings(adapter, adapterName, settings);
|
|
2058
|
-
};
|
|
2059
|
-
//#endregion
|
|
2060
2042
|
//#region ../plugin-core/dist/engine/core/schema.mjs
|
|
2061
2043
|
/** A channel's id is `channel:` and its name's channel key, so ids share channel_key's bound. */
|
|
2062
2044
|
const CHANNEL_ID = {
|
|
@@ -2353,6 +2335,85 @@ const refuseV0Database = (adapterName, stored) => {
|
|
|
2353
2335
|
if (typeof version !== "string" || stored.has("schema.engine")) return;
|
|
2354
2336
|
throw new HotUpdaterSchemaMigrationRequiredError(adapterName, version);
|
|
2355
2337
|
};
|
|
2338
|
+
/**
|
|
2339
|
+
* The settings whose versions only move forward when a `ToolingTarget` names
|
|
2340
|
+
* none. `schema.engine` is a storage layout, not a release: a store refuses
|
|
2341
|
+
* another layout itself.
|
|
2342
|
+
*/
|
|
2343
|
+
const DEFAULT_ORDERED_SETTINGS = ["schema.core"];
|
|
2344
|
+
/**
|
|
2345
|
+
* Refuses a database a newer release migrated, one whose `schema.core` is
|
|
2346
|
+
* newer than this release's: writing this release's settings would move the
|
|
2347
|
+
* schema back, and every server of the newer release would answer 503. Only
|
|
2348
|
+
* `ordered` settings are compared, `schema.core` among them, and the message
|
|
2349
|
+
* lists each that is newer. An official plugin's
|
|
2350
|
+
* newer version alone is no newer release: Insights recorded "1.2.0" in
|
|
2351
|
+
* 1.0.0-rc.23 and rc.24, then went back to "1.0.0" with the same tables.
|
|
2352
|
+
*/
|
|
2353
|
+
const refuseNewerSchema = (adapterName, stored, settings, ordered = DEFAULT_ORDERED_SETTINGS) => {
|
|
2354
|
+
const newer = ordered.flatMap((key) => {
|
|
2355
|
+
const found = stored.get(key);
|
|
2356
|
+
const expected = settings[key];
|
|
2357
|
+
return typeof found === "string" && expected !== void 0 && compareVersions(found, expected) > 0 ? [{
|
|
2358
|
+
key,
|
|
2359
|
+
found,
|
|
2360
|
+
expected
|
|
2361
|
+
}] : [];
|
|
2362
|
+
});
|
|
2363
|
+
const core = newer.find(({ key }) => key === "schema.core");
|
|
2364
|
+
if (core === void 0) return;
|
|
2365
|
+
throw new Error(`${adapterName}: the database was migrated by Hot Updater ${core.found} (${newer.map(({ key, found, expected }) => `${key} "${found}", this CLI's "${expected}"`).join("; ")}). Upgrade hot-updater to ${core.found} or later; nothing was written.`);
|
|
2366
|
+
};
|
|
2367
|
+
//#endregion
|
|
2368
|
+
//#region ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
2369
|
+
const storedSettings = async (adapter, keys) => {
|
|
2370
|
+
const rows = await readSettings(adapter, keys);
|
|
2371
|
+
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
2372
|
+
};
|
|
2373
|
+
/**
|
|
2374
|
+
* Writes the settings rows after every table exists, and refuses a database
|
|
2375
|
+
* whose `ordered` settings a newer release recorded.
|
|
2376
|
+
*/
|
|
2377
|
+
const writeSchemaSettings = async (adapter, adapterName, settings, ordered) => {
|
|
2378
|
+
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
2379
|
+
refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2380
|
+
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
2381
|
+
const row = stored.get(key);
|
|
2382
|
+
if (row === null || row === void 0) return [{
|
|
2383
|
+
type: "insert",
|
|
2384
|
+
table: SETTINGS_TABLE,
|
|
2385
|
+
row: {
|
|
2386
|
+
key,
|
|
2387
|
+
value,
|
|
2388
|
+
_v: 0
|
|
2389
|
+
}
|
|
2390
|
+
}];
|
|
2391
|
+
if (row.value === value) return [];
|
|
2392
|
+
return [{
|
|
2393
|
+
type: "patch",
|
|
2394
|
+
table: SETTINGS_TABLE,
|
|
2395
|
+
key: [key],
|
|
2396
|
+
set: { value },
|
|
2397
|
+
guard: { v: Number(row._v) },
|
|
2398
|
+
previous: row
|
|
2399
|
+
}];
|
|
2400
|
+
});
|
|
2401
|
+
if (ops.length === 0) return;
|
|
2402
|
+
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
2403
|
+
};
|
|
2404
|
+
/**
|
|
2405
|
+
* Creates or updates every table, then writes the settings rows last. A
|
|
2406
|
+
* database a newer release migrated is refused before anything is written:
|
|
2407
|
+
* its settings are read first, and a store without them yet, whose read
|
|
2408
|
+
* fails, has none to refuse.
|
|
2409
|
+
*/
|
|
2410
|
+
const migrateSchema = async (adapter, adapterName, tables, settings, ordered) => {
|
|
2411
|
+
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2412
|
+
const stored = await storedSettings(adapter, Object.keys(settings)).catch(() => void 0);
|
|
2413
|
+
if (stored !== void 0) refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2414
|
+
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2415
|
+
await writeSchemaSettings(adapter, adapterName, settings, ordered);
|
|
2416
|
+
};
|
|
2356
2417
|
//#endregion
|
|
2357
2418
|
//#region ../plugin-core/dist/engine/database/cursor.mjs
|
|
2358
2419
|
const encoder$1 = new TextEncoder();
|
|
@@ -3466,13 +3527,14 @@ const resolveSchema = (modules) => {
|
|
|
3466
3527
|
* `hot-updater db migrate` for a store whose adapter creates its own tables
|
|
3467
3528
|
* (MongoDB and the key-value stores): the tables and indexes, then the
|
|
3468
3529
|
* settings rows, applied when a setting is missing or different, and refused
|
|
3469
|
-
* on a v0 database.
|
|
3530
|
+
* on a v0 database or one a newer release migrated.
|
|
3470
3531
|
*/
|
|
3471
3532
|
const createEngineMigrator = (options) => {
|
|
3472
3533
|
const getVersion = async () => storedSchemaVersion(await options.readSettings());
|
|
3473
3534
|
const makeResult = async (migrate = {}) => {
|
|
3474
3535
|
const stored = await options.readSettings();
|
|
3475
3536
|
refuseV0Database(options.adapterName, stored);
|
|
3537
|
+
refuseNewerSchema(options.adapterName, stored, options.settings, options.ordered);
|
|
3476
3538
|
if (Object.entries(options.settings).every(([key, value]) => stored.get(key) === value)) return getEmptyMigrationResult();
|
|
3477
3539
|
return {
|
|
3478
3540
|
operations: [...options.schema.tables.map((table) => ({
|
|
@@ -3488,7 +3550,7 @@ const createEngineMigrator = (options) => {
|
|
|
3488
3550
|
type: "custom",
|
|
3489
3551
|
description: `Write the schema settings: ${Object.keys(options.settings).join(", ")}`
|
|
3490
3552
|
}]],
|
|
3491
|
-
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings)
|
|
3553
|
+
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings, options.ordered)
|
|
3492
3554
|
};
|
|
3493
3555
|
};
|
|
3494
3556
|
return {
|
|
@@ -3519,7 +3581,8 @@ const coreSettings = {
|
|
|
3519
3581
|
/** What `hot-updater db` creates for a server without plugins. */
|
|
3520
3582
|
const coreTarget = {
|
|
3521
3583
|
schema: coreSchema,
|
|
3522
|
-
settings: coreSettings
|
|
3584
|
+
settings: coreSettings,
|
|
3585
|
+
ordered: ["schema.core"]
|
|
3523
3586
|
};
|
|
3524
3587
|
resolveSchema([aggregateBatchingModule]).tables;
|
|
3525
3588
|
/** Each plugin's `schema.<id>` settings row. */
|
|
@@ -3539,11 +3602,12 @@ const pluginModule = ({ id, schema, namespace }) => ({
|
|
|
3539
3602
|
*/
|
|
3540
3603
|
const createEngineDatabase = ({ name, adapter, onCachedRoutesChange, aggregateBatching, retry, readSettings: readStored }) => {
|
|
3541
3604
|
const fenced = withSchemaFence(adapter, name, coreSettings);
|
|
3542
|
-
const createMigrator = ({ schema, settings } = coreTarget) => createEngineMigrator({
|
|
3605
|
+
const createMigrator = ({ schema, settings, ordered } = coreTarget) => createEngineMigrator({
|
|
3543
3606
|
adapterName: name,
|
|
3544
3607
|
adapter,
|
|
3545
3608
|
schema,
|
|
3546
3609
|
settings,
|
|
3610
|
+
ordered,
|
|
3547
3611
|
readSettings: readStored ?? (async () => {
|
|
3548
3612
|
const rows = await readSettings(adapter, Object.keys(settings)).catch((error) => {
|
|
3549
3613
|
if (isMissingSchemaError(error)) return [];
|
|
@@ -4577,7 +4641,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
4577
4641
|
};
|
|
4578
4642
|
//#endregion
|
|
4579
4643
|
//#region ../../packages/server/dist/version.mjs
|
|
4580
|
-
const HOT_UPDATER_SERVER_VERSION = "1.1.
|
|
4644
|
+
const HOT_UPDATER_SERVER_VERSION = "1.1.19";
|
|
4581
4645
|
//#endregion
|
|
4582
4646
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
4583
4647
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/firebase",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.19",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"hono": "4.12.34",
|
|
40
|
-
"@hot-updater/
|
|
41
|
-
"@hot-updater/
|
|
42
|
-
"@hot-updater/
|
|
43
|
-
"@hot-updater/
|
|
40
|
+
"@hot-updater/protocol": "1.1.19",
|
|
41
|
+
"@hot-updater/plugin-core": "1.1.19",
|
|
42
|
+
"@hot-updater/server": "1.1.19",
|
|
43
|
+
"@hot-updater/cli-tools": "1.1.19"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"firebase-tools": "15.29.0",
|
|
56
56
|
"fkill": "^9.0.0",
|
|
57
57
|
"mime": "^4.0.4",
|
|
58
|
-
"@hot-updater/mock": "1.1.
|
|
59
|
-
"@hot-updater/test-utils": "1.1.
|
|
58
|
+
"@hot-updater/mock": "1.1.19",
|
|
59
|
+
"@hot-updater/test-utils": "1.1.19"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"firebase-admin": ">=11.10.0",
|