@hot-updater/aws 1.1.16 → 1.1.18
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/lambda/index.cjs +110 -46
- package/package.json +8 -8
package/dist/lambda/index.cjs
CHANGED
|
@@ -1925,6 +1925,23 @@ const SETTINGS_TABLE = {
|
|
|
1925
1925
|
/** The engine's storage-layout generation; it changes only with a migration. */
|
|
1926
1926
|
const ENGINE_SCHEMA_KEY = "schema.engine";
|
|
1927
1927
|
const CORE_SCHEMA_KEY = "schema.core";
|
|
1928
|
+
/** Compares dotted numeric versions, such as "1" and "1.2.0"; NaN when either is not one. */
|
|
1929
|
+
const compareVersions = (left, right) => {
|
|
1930
|
+
const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
|
|
1931
|
+
const [a, b] = [parse(left), parse(right)];
|
|
1932
|
+
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
1933
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
1934
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
1935
|
+
if (difference !== 0) return difference;
|
|
1936
|
+
}
|
|
1937
|
+
return 0;
|
|
1938
|
+
};
|
|
1939
|
+
/**
|
|
1940
|
+
* The `schema.core` a newer release recorded, which `hot-updater db migrate`
|
|
1941
|
+
* never moves back: the fix is to upgrade, not to migrate.
|
|
1942
|
+
*/
|
|
1943
|
+
const newerCore = (settings) => settings.find(({ key, expected, found }) => key === CORE_SCHEMA_KEY && found !== null && compareVersions(found, expected) > 0);
|
|
1944
|
+
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.`;
|
|
1928
1945
|
const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
|
|
1929
1946
|
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\`.`;
|
|
1930
1947
|
/** The plugin a `schema.<id>` setting belongs to; undefined for core's and the engine's. */
|
|
@@ -1933,7 +1950,10 @@ const listed = (items) => items.length < 2 ? items.join("") : `${items.slice(0,
|
|
|
1933
1950
|
/** How to create plugins' tables when the fence was given no fix. */
|
|
1934
1951
|
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.";
|
|
1935
1952
|
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}`;
|
|
1936
|
-
/**
|
|
1953
|
+
/**
|
|
1954
|
+
* The database needs `hot-updater db migrate`, a new database, or a newer
|
|
1955
|
+
* Hot Updater; the handler answers 503.
|
|
1956
|
+
*/
|
|
1937
1957
|
var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
1938
1958
|
adapterName;
|
|
1939
1959
|
currentVersion;
|
|
@@ -1948,7 +1968,8 @@ var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
|
1948
1968
|
constructor(adapterName, currentVersion, setting, options) {
|
|
1949
1969
|
const settings = options?.settings ?? (setting === void 0 ? [] : [setting]);
|
|
1950
1970
|
const plugins = settings.flatMap((mismatch) => pluginOf(mismatch) ?? []);
|
|
1951
|
-
|
|
1971
|
+
const newer = newerCore(settings);
|
|
1972
|
+
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 });
|
|
1952
1973
|
this.adapterName = adapterName;
|
|
1953
1974
|
this.currentVersion = currentVersion;
|
|
1954
1975
|
this.setting = setting;
|
|
@@ -2043,45 +2064,6 @@ const METER = Symbol.for("@hot-updater/plugin-core/read-meter");
|
|
|
2043
2064
|
/** The meter `meterReads` gave `database`, if it did. */
|
|
2044
2065
|
const readMeterOf = (database) => typeof database === "object" && database !== null ? database[METER] : void 0;
|
|
2045
2066
|
//#endregion
|
|
2046
|
-
//#region ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
2047
|
-
const storedSettings = async (adapter, keys) => {
|
|
2048
|
-
const rows = await readSettings(adapter, keys);
|
|
2049
|
-
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
2050
|
-
};
|
|
2051
|
-
/** Writes the settings rows after every table exists. */
|
|
2052
|
-
const writeSchemaSettings = async (adapter, adapterName, settings) => {
|
|
2053
|
-
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
2054
|
-
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
2055
|
-
const row = stored.get(key);
|
|
2056
|
-
if (row === null || row === void 0) return [{
|
|
2057
|
-
type: "insert",
|
|
2058
|
-
table: SETTINGS_TABLE,
|
|
2059
|
-
row: {
|
|
2060
|
-
key,
|
|
2061
|
-
value,
|
|
2062
|
-
_v: 0
|
|
2063
|
-
}
|
|
2064
|
-
}];
|
|
2065
|
-
if (row.value === value) return [];
|
|
2066
|
-
return [{
|
|
2067
|
-
type: "patch",
|
|
2068
|
-
table: SETTINGS_TABLE,
|
|
2069
|
-
key: [key],
|
|
2070
|
-
set: { value },
|
|
2071
|
-
guard: { v: Number(row._v) },
|
|
2072
|
-
previous: row
|
|
2073
|
-
}];
|
|
2074
|
-
});
|
|
2075
|
-
if (ops.length === 0) return;
|
|
2076
|
-
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
2077
|
-
};
|
|
2078
|
-
/** Creates or updates every table, then writes the settings rows last. */
|
|
2079
|
-
const migrateSchema = async (adapter, adapterName, tables, settings) => {
|
|
2080
|
-
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2081
|
-
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2082
|
-
await writeSchemaSettings(adapter, adapterName, settings);
|
|
2083
|
-
};
|
|
2084
|
-
//#endregion
|
|
2085
2067
|
//#region ../plugin-core/dist/engine/core/schema.mjs
|
|
2086
2068
|
/** A channel's id is `channel:` and its name's channel key, so ids share channel_key's bound. */
|
|
2087
2069
|
const CHANNEL_ID = {
|
|
@@ -2378,6 +2360,85 @@ const refuseV0Database = (adapterName, stored) => {
|
|
|
2378
2360
|
if (typeof version !== "string" || stored.has("schema.engine")) return;
|
|
2379
2361
|
throw new HotUpdaterSchemaMigrationRequiredError(adapterName, version);
|
|
2380
2362
|
};
|
|
2363
|
+
/**
|
|
2364
|
+
* The settings whose versions only move forward when a `ToolingTarget` names
|
|
2365
|
+
* none. `schema.engine` is a storage layout, not a release: a store refuses
|
|
2366
|
+
* another layout itself.
|
|
2367
|
+
*/
|
|
2368
|
+
const DEFAULT_ORDERED_SETTINGS = ["schema.core"];
|
|
2369
|
+
/**
|
|
2370
|
+
* Refuses a database a newer release migrated, one whose `schema.core` is
|
|
2371
|
+
* newer than this release's: writing this release's settings would move the
|
|
2372
|
+
* schema back, and every server of the newer release would answer 503. Only
|
|
2373
|
+
* `ordered` settings are compared, `schema.core` among them, and the message
|
|
2374
|
+
* lists each that is newer. An official plugin's
|
|
2375
|
+
* newer version alone is no newer release: Insights recorded "1.2.0" in
|
|
2376
|
+
* 1.0.0-rc.23 and rc.24, then went back to "1.0.0" with the same tables.
|
|
2377
|
+
*/
|
|
2378
|
+
const refuseNewerSchema = (adapterName, stored, settings, ordered = DEFAULT_ORDERED_SETTINGS) => {
|
|
2379
|
+
const newer = ordered.flatMap((key) => {
|
|
2380
|
+
const found = stored.get(key);
|
|
2381
|
+
const expected = settings[key];
|
|
2382
|
+
return typeof found === "string" && expected !== void 0 && compareVersions(found, expected) > 0 ? [{
|
|
2383
|
+
key,
|
|
2384
|
+
found,
|
|
2385
|
+
expected
|
|
2386
|
+
}] : [];
|
|
2387
|
+
});
|
|
2388
|
+
const core = newer.find(({ key }) => key === "schema.core");
|
|
2389
|
+
if (core === void 0) return;
|
|
2390
|
+
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.`);
|
|
2391
|
+
};
|
|
2392
|
+
//#endregion
|
|
2393
|
+
//#region ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
2394
|
+
const storedSettings = async (adapter, keys) => {
|
|
2395
|
+
const rows = await readSettings(adapter, keys);
|
|
2396
|
+
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
2397
|
+
};
|
|
2398
|
+
/**
|
|
2399
|
+
* Writes the settings rows after every table exists, and refuses a database
|
|
2400
|
+
* whose `ordered` settings a newer release recorded.
|
|
2401
|
+
*/
|
|
2402
|
+
const writeSchemaSettings = async (adapter, adapterName, settings, ordered) => {
|
|
2403
|
+
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
2404
|
+
refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2405
|
+
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
2406
|
+
const row = stored.get(key);
|
|
2407
|
+
if (row === null || row === void 0) return [{
|
|
2408
|
+
type: "insert",
|
|
2409
|
+
table: SETTINGS_TABLE,
|
|
2410
|
+
row: {
|
|
2411
|
+
key,
|
|
2412
|
+
value,
|
|
2413
|
+
_v: 0
|
|
2414
|
+
}
|
|
2415
|
+
}];
|
|
2416
|
+
if (row.value === value) return [];
|
|
2417
|
+
return [{
|
|
2418
|
+
type: "patch",
|
|
2419
|
+
table: SETTINGS_TABLE,
|
|
2420
|
+
key: [key],
|
|
2421
|
+
set: { value },
|
|
2422
|
+
guard: { v: Number(row._v) },
|
|
2423
|
+
previous: row
|
|
2424
|
+
}];
|
|
2425
|
+
});
|
|
2426
|
+
if (ops.length === 0) return;
|
|
2427
|
+
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
2428
|
+
};
|
|
2429
|
+
/**
|
|
2430
|
+
* Creates or updates every table, then writes the settings rows last. A
|
|
2431
|
+
* database a newer release migrated is refused before anything is written:
|
|
2432
|
+
* its settings are read first, and a store without them yet, whose read
|
|
2433
|
+
* fails, has none to refuse.
|
|
2434
|
+
*/
|
|
2435
|
+
const migrateSchema = async (adapter, adapterName, tables, settings, ordered) => {
|
|
2436
|
+
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2437
|
+
const stored = await storedSettings(adapter, Object.keys(settings)).catch(() => void 0);
|
|
2438
|
+
if (stored !== void 0) refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2439
|
+
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2440
|
+
await writeSchemaSettings(adapter, adapterName, settings, ordered);
|
|
2441
|
+
};
|
|
2381
2442
|
//#endregion
|
|
2382
2443
|
//#region ../plugin-core/dist/engine/database/cursor.mjs
|
|
2383
2444
|
const encoder$1 = new TextEncoder();
|
|
@@ -3491,13 +3552,14 @@ const resolveSchema = (modules) => {
|
|
|
3491
3552
|
* `hot-updater db migrate` for a store whose adapter creates its own tables
|
|
3492
3553
|
* (MongoDB and the key-value stores): the tables and indexes, then the
|
|
3493
3554
|
* settings rows, applied when a setting is missing or different, and refused
|
|
3494
|
-
* on a v0 database.
|
|
3555
|
+
* on a v0 database or one a newer release migrated.
|
|
3495
3556
|
*/
|
|
3496
3557
|
const createEngineMigrator = (options) => {
|
|
3497
3558
|
const getVersion = async () => storedSchemaVersion(await options.readSettings());
|
|
3498
3559
|
const makeResult = async (migrate = {}) => {
|
|
3499
3560
|
const stored = await options.readSettings();
|
|
3500
3561
|
refuseV0Database(options.adapterName, stored);
|
|
3562
|
+
refuseNewerSchema(options.adapterName, stored, options.settings, options.ordered);
|
|
3501
3563
|
if (Object.entries(options.settings).every(([key, value]) => stored.get(key) === value)) return getEmptyMigrationResult();
|
|
3502
3564
|
return {
|
|
3503
3565
|
operations: [...options.schema.tables.map((table) => ({
|
|
@@ -3513,7 +3575,7 @@ const createEngineMigrator = (options) => {
|
|
|
3513
3575
|
type: "custom",
|
|
3514
3576
|
description: `Write the schema settings: ${Object.keys(options.settings).join(", ")}`
|
|
3515
3577
|
}]],
|
|
3516
|
-
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings)
|
|
3578
|
+
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings, options.ordered)
|
|
3517
3579
|
};
|
|
3518
3580
|
};
|
|
3519
3581
|
return {
|
|
@@ -3544,7 +3606,8 @@ const coreSettings = {
|
|
|
3544
3606
|
/** What `hot-updater db` creates for a server without plugins. */
|
|
3545
3607
|
const coreTarget = {
|
|
3546
3608
|
schema: coreSchema,
|
|
3547
|
-
settings: coreSettings
|
|
3609
|
+
settings: coreSettings,
|
|
3610
|
+
ordered: ["schema.core"]
|
|
3548
3611
|
};
|
|
3549
3612
|
resolveSchema([aggregateBatchingModule]).tables;
|
|
3550
3613
|
/** Each plugin's `schema.<id>` settings row. */
|
|
@@ -3564,11 +3627,12 @@ const pluginModule = ({ id, schema, namespace }) => ({
|
|
|
3564
3627
|
*/
|
|
3565
3628
|
const createEngineDatabase = ({ name, adapter, onCachedRoutesChange, aggregateBatching, retry, readSettings: readStored }) => {
|
|
3566
3629
|
const fenced = withSchemaFence(adapter, name, coreSettings);
|
|
3567
|
-
const createMigrator = ({ schema, settings } = coreTarget) => createEngineMigrator({
|
|
3630
|
+
const createMigrator = ({ schema, settings, ordered } = coreTarget) => createEngineMigrator({
|
|
3568
3631
|
adapterName: name,
|
|
3569
3632
|
adapter,
|
|
3570
3633
|
schema,
|
|
3571
3634
|
settings,
|
|
3635
|
+
ordered,
|
|
3572
3636
|
readSettings: readStored ?? (async () => {
|
|
3573
3637
|
const rows = await readSettings(adapter, Object.keys(settings)).catch((error) => {
|
|
3574
3638
|
if (isMissingSchemaError(error)) return [];
|
|
@@ -4602,7 +4666,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
4602
4666
|
};
|
|
4603
4667
|
//#endregion
|
|
4604
4668
|
//#region ../../packages/server/dist/version.mjs
|
|
4605
|
-
const HOT_UPDATER_SERVER_VERSION = "1.1.
|
|
4669
|
+
const HOT_UPDATER_SERVER_VERSION = "1.1.18";
|
|
4606
4670
|
//#endregion
|
|
4607
4671
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
4608
4672
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/aws",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.18",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"es-toolkit": "^1.32.0",
|
|
46
46
|
"execa": "9.5.2",
|
|
47
47
|
"mime": "^4.0.4",
|
|
48
|
-
"@hot-updater/
|
|
49
|
-
"@hot-updater/
|
|
50
|
-
"@hot-updater/
|
|
48
|
+
"@hot-updater/protocol": "1.1.18",
|
|
49
|
+
"@hot-updater/mock": "1.1.18",
|
|
50
|
+
"@hot-updater/test-utils": "1.1.18"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@aws-sdk/client-cloudfront": "3.1066.0",
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"@aws-sdk/lib-dynamodb": "3.1066.0",
|
|
64
64
|
"@aws-sdk/s3-request-presigner": "3.1066.0",
|
|
65
65
|
"hono": "4.12.34",
|
|
66
|
-
"@hot-updater/cli-tools": "1.1.
|
|
67
|
-
"@hot-updater/plugin-core": "1.1.
|
|
68
|
-
"@hot-updater/server": "1.1.
|
|
69
|
-
"@hot-updater/storage-s3": "1.1.
|
|
66
|
+
"@hot-updater/cli-tools": "1.1.18",
|
|
67
|
+
"@hot-updater/plugin-core": "1.1.18",
|
|
68
|
+
"@hot-updater/server": "1.1.18",
|
|
69
|
+
"@hot-updater/storage-s3": "1.1.18"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "tsdown",
|