@hot-updater/vercel 1.1.17 → 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/function/index.mjs +76 -42
- package/package.json +7 -7
package/dist/function/index.mjs
CHANGED
|
@@ -1861,6 +1861,18 @@ const SETTINGS_TABLE = {
|
|
|
1861
1861
|
};
|
|
1862
1862
|
const ENGINE_SCHEMA_KEY = "schema.engine";
|
|
1863
1863
|
const CORE_SCHEMA_KEY = "schema.core";
|
|
1864
|
+
const compareVersions = (left, right) => {
|
|
1865
|
+
const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
|
|
1866
|
+
const [a, b] = [parse(left), parse(right)];
|
|
1867
|
+
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
1868
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
1869
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
1870
|
+
if (difference !== 0) return difference;
|
|
1871
|
+
}
|
|
1872
|
+
return 0;
|
|
1873
|
+
};
|
|
1874
|
+
const newerCore = (settings) => settings.find(({ key, expected, found }) => key === CORE_SCHEMA_KEY && found !== null && compareVersions(found, expected) > 0);
|
|
1875
|
+
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.`;
|
|
1864
1876
|
const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
|
|
1865
1877
|
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\`.`;
|
|
1866
1878
|
const pluginOf = ({ key }) => key.startsWith("schema.") && key !== "schema.engine" && key !== CORE_SCHEMA_KEY ? key.slice(7) : void 0;
|
|
@@ -1876,7 +1888,8 @@ var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
|
1876
1888
|
constructor(adapterName, currentVersion, setting, options) {
|
|
1877
1889
|
const settings = options?.settings ?? (setting === void 0 ? [] : [setting]);
|
|
1878
1890
|
const plugins = settings.flatMap((mismatch) => pluginOf(mismatch) ?? []);
|
|
1879
|
-
|
|
1891
|
+
const newer = newerCore(settings);
|
|
1892
|
+
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 });
|
|
1880
1893
|
this.adapterName = adapterName;
|
|
1881
1894
|
this.currentVersion = currentVersion;
|
|
1882
1895
|
this.setting = setting;
|
|
@@ -1953,43 +1966,6 @@ const withSchemaFence = (adapter, adapterName, expected, fix) => {
|
|
|
1953
1966
|
const METER = Symbol.for("@hot-updater/plugin-core/read-meter");
|
|
1954
1967
|
const readMeterOf = (database) => typeof database === "object" && database !== null ? database[METER] : void 0;
|
|
1955
1968
|
//#endregion
|
|
1956
|
-
//#region ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
1957
|
-
const storedSettings = async (adapter, keys) => {
|
|
1958
|
-
const rows = await readSettings(adapter, keys);
|
|
1959
|
-
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
1960
|
-
};
|
|
1961
|
-
const writeSchemaSettings = async (adapter, adapterName, settings) => {
|
|
1962
|
-
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
1963
|
-
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
1964
|
-
const row = stored.get(key);
|
|
1965
|
-
if (row === null || row === void 0) return [{
|
|
1966
|
-
type: "insert",
|
|
1967
|
-
table: SETTINGS_TABLE,
|
|
1968
|
-
row: {
|
|
1969
|
-
key,
|
|
1970
|
-
value,
|
|
1971
|
-
_v: 0
|
|
1972
|
-
}
|
|
1973
|
-
}];
|
|
1974
|
-
if (row.value === value) return [];
|
|
1975
|
-
return [{
|
|
1976
|
-
type: "patch",
|
|
1977
|
-
table: SETTINGS_TABLE,
|
|
1978
|
-
key: [key],
|
|
1979
|
-
set: { value },
|
|
1980
|
-
guard: { v: Number(row._v) },
|
|
1981
|
-
previous: row
|
|
1982
|
-
}];
|
|
1983
|
-
});
|
|
1984
|
-
if (ops.length === 0) return;
|
|
1985
|
-
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
1986
|
-
};
|
|
1987
|
-
const migrateSchema = async (adapter, adapterName, tables, settings) => {
|
|
1988
|
-
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
1989
|
-
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
1990
|
-
await writeSchemaSettings(adapter, adapterName, settings);
|
|
1991
|
-
};
|
|
1992
|
-
//#endregion
|
|
1993
1969
|
//#region ../plugin-core/dist/engine/database/sql/sqlSchema.mjs
|
|
1994
1970
|
const quoteSql = (dialect, name) => dialect === "mysql" ? `\`${name.replaceAll("`", "``")}\`` : `"${name.replaceAll("\"", "\"\"")}"`;
|
|
1995
1971
|
const isMultiIndex = (table, index) => index.eq.some((column) => findPhysicalColumn(table, column).multi);
|
|
@@ -2421,6 +2397,61 @@ const refuseV0Database = (adapterName, stored) => {
|
|
|
2421
2397
|
if (typeof version !== "string" || stored.has("schema.engine")) return;
|
|
2422
2398
|
throw new HotUpdaterSchemaMigrationRequiredError(adapterName, version);
|
|
2423
2399
|
};
|
|
2400
|
+
const DEFAULT_ORDERED_SETTINGS = ["schema.core"];
|
|
2401
|
+
const refuseNewerSchema = (adapterName, stored, settings, ordered = DEFAULT_ORDERED_SETTINGS) => {
|
|
2402
|
+
const newer = ordered.flatMap((key) => {
|
|
2403
|
+
const found = stored.get(key);
|
|
2404
|
+
const expected = settings[key];
|
|
2405
|
+
return typeof found === "string" && expected !== void 0 && compareVersions(found, expected) > 0 ? [{
|
|
2406
|
+
key,
|
|
2407
|
+
found,
|
|
2408
|
+
expected
|
|
2409
|
+
}] : [];
|
|
2410
|
+
});
|
|
2411
|
+
const core = newer.find(({ key }) => key === "schema.core");
|
|
2412
|
+
if (core === void 0) return;
|
|
2413
|
+
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.`);
|
|
2414
|
+
};
|
|
2415
|
+
//#endregion
|
|
2416
|
+
//#region ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
2417
|
+
const storedSettings = async (adapter, keys) => {
|
|
2418
|
+
const rows = await readSettings(adapter, keys);
|
|
2419
|
+
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
2420
|
+
};
|
|
2421
|
+
const writeSchemaSettings = async (adapter, adapterName, settings, ordered) => {
|
|
2422
|
+
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
2423
|
+
refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2424
|
+
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
2425
|
+
const row = stored.get(key);
|
|
2426
|
+
if (row === null || row === void 0) return [{
|
|
2427
|
+
type: "insert",
|
|
2428
|
+
table: SETTINGS_TABLE,
|
|
2429
|
+
row: {
|
|
2430
|
+
key,
|
|
2431
|
+
value,
|
|
2432
|
+
_v: 0
|
|
2433
|
+
}
|
|
2434
|
+
}];
|
|
2435
|
+
if (row.value === value) return [];
|
|
2436
|
+
return [{
|
|
2437
|
+
type: "patch",
|
|
2438
|
+
table: SETTINGS_TABLE,
|
|
2439
|
+
key: [key],
|
|
2440
|
+
set: { value },
|
|
2441
|
+
guard: { v: Number(row._v) },
|
|
2442
|
+
previous: row
|
|
2443
|
+
}];
|
|
2444
|
+
});
|
|
2445
|
+
if (ops.length === 0) return;
|
|
2446
|
+
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
2447
|
+
};
|
|
2448
|
+
const migrateSchema = async (adapter, adapterName, tables, settings, ordered) => {
|
|
2449
|
+
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
2450
|
+
const stored = await storedSettings(adapter, Object.keys(settings)).catch(() => void 0);
|
|
2451
|
+
if (stored !== void 0) refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
2452
|
+
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
2453
|
+
await writeSchemaSettings(adapter, adapterName, settings, ordered);
|
|
2454
|
+
};
|
|
2424
2455
|
//#endregion
|
|
2425
2456
|
//#region ../plugin-core/dist/engine/database/cursor.mjs
|
|
2426
2457
|
const encoder$1 = new TextEncoder();
|
|
@@ -3381,6 +3412,7 @@ const createEngineMigrator = (options) => {
|
|
|
3381
3412
|
const makeResult = async (migrate = {}) => {
|
|
3382
3413
|
const stored = await options.readSettings();
|
|
3383
3414
|
refuseV0Database(options.adapterName, stored);
|
|
3415
|
+
refuseNewerSchema(options.adapterName, stored, options.settings, options.ordered);
|
|
3384
3416
|
if (Object.entries(options.settings).every(([key, value]) => stored.get(key) === value)) return getEmptyMigrationResult();
|
|
3385
3417
|
return {
|
|
3386
3418
|
operations: [...options.schema.tables.map((table) => ({
|
|
@@ -3396,7 +3428,7 @@ const createEngineMigrator = (options) => {
|
|
|
3396
3428
|
type: "custom",
|
|
3397
3429
|
description: `Write the schema settings: ${Object.keys(options.settings).join(", ")}`
|
|
3398
3430
|
}]],
|
|
3399
|
-
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings)
|
|
3431
|
+
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings, options.ordered)
|
|
3400
3432
|
};
|
|
3401
3433
|
};
|
|
3402
3434
|
return {
|
|
@@ -3424,7 +3456,8 @@ const coreSettings = {
|
|
|
3424
3456
|
};
|
|
3425
3457
|
const coreTarget = {
|
|
3426
3458
|
schema: coreSchema,
|
|
3427
|
-
settings: coreSettings
|
|
3459
|
+
settings: coreSettings,
|
|
3460
|
+
ordered: ["schema.core"]
|
|
3428
3461
|
};
|
|
3429
3462
|
resolveSchema([aggregateBatchingModule]).tables;
|
|
3430
3463
|
const pluginSettings = (plugins) => Object.fromEntries(plugins.map(({ id, schemaVersion }) => [`schema.${id}`, schemaVersion]));
|
|
@@ -3435,11 +3468,12 @@ const pluginModule = ({ id, schema, namespace }) => ({
|
|
|
3435
3468
|
});
|
|
3436
3469
|
const createEngineDatabase = ({ name, adapter, onCachedRoutesChange, aggregateBatching, retry, readSettings: readStored }) => {
|
|
3437
3470
|
const fenced = withSchemaFence(adapter, name, coreSettings);
|
|
3438
|
-
const createMigrator = ({ schema, settings } = coreTarget) => createEngineMigrator({
|
|
3471
|
+
const createMigrator = ({ schema, settings, ordered } = coreTarget) => createEngineMigrator({
|
|
3439
3472
|
adapterName: name,
|
|
3440
3473
|
adapter,
|
|
3441
3474
|
schema,
|
|
3442
3475
|
settings,
|
|
3476
|
+
ordered,
|
|
3443
3477
|
readSettings: readStored ?? (async () => {
|
|
3444
3478
|
const rows = await readSettings(adapter, Object.keys(settings)).catch((error) => {
|
|
3445
3479
|
if (isMissingSchemaError(error)) return [];
|
|
@@ -17599,7 +17633,7 @@ const postgres = (config) => {
|
|
|
17599
17633
|
};
|
|
17600
17634
|
//#endregion
|
|
17601
17635
|
//#region ../../packages/server/dist/version.mjs
|
|
17602
|
-
const HOT_UPDATER_SERVER_VERSION = "1.1.
|
|
17636
|
+
const HOT_UPDATER_SERVER_VERSION = "1.1.18";
|
|
17603
17637
|
//#endregion
|
|
17604
17638
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
17605
17639
|
const createVersionRouteHandlers = (plugins = []) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/vercel",
|
|
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",
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"@vercel/cli-auth": "0.3.10",
|
|
42
42
|
"@vercel/cli-config": "0.3.1",
|
|
43
43
|
"pg": "8.13.1",
|
|
44
|
-
"@hot-updater/
|
|
45
|
-
"@hot-updater/
|
|
46
|
-
"@hot-updater/
|
|
47
|
-
"@hot-updater/
|
|
48
|
-
"@hot-updater/
|
|
44
|
+
"@hot-updater/postgres": "1.1.18",
|
|
45
|
+
"@hot-updater/protocol": "1.1.18",
|
|
46
|
+
"@hot-updater/plugin-core": "1.1.18",
|
|
47
|
+
"@hot-updater/server": "1.1.18",
|
|
48
|
+
"@hot-updater/cli-tools": "1.1.18"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^20",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"execa": "9.5.2",
|
|
55
55
|
"kysely": "0.28.17",
|
|
56
56
|
"vitest": "4.1.4",
|
|
57
|
-
"@hot-updater/test-utils": "1.1.
|
|
57
|
+
"@hot-updater/test-utils": "1.1.18"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "tsdown",
|