@hot-updater/azure 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/functions/index.mjs +79 -43
- package/package.json +6 -6
package/dist/functions/index.mjs
CHANGED
|
@@ -5630,6 +5630,18 @@ const SETTINGS_TABLE = {
|
|
|
5630
5630
|
};
|
|
5631
5631
|
const ENGINE_SCHEMA_KEY = "schema.engine";
|
|
5632
5632
|
const CORE_SCHEMA_KEY = "schema.core";
|
|
5633
|
+
const compareVersions = (left, right) => {
|
|
5634
|
+
const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
|
|
5635
|
+
const [a, b] = [parse(left), parse(right)];
|
|
5636
|
+
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
5637
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
5638
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
5639
|
+
if (difference !== 0) return difference;
|
|
5640
|
+
}
|
|
5641
|
+
return 0;
|
|
5642
|
+
};
|
|
5643
|
+
const newerCore = (settings) => settings.find(({ key, expected, found }) => key === CORE_SCHEMA_KEY && found !== null && compareVersions(found, expected) > 0);
|
|
5644
|
+
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.`;
|
|
5633
5645
|
const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
|
|
5634
5646
|
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\`.`;
|
|
5635
5647
|
const pluginOf = ({ key }) => key.startsWith("schema.") && key !== "schema.engine" && key !== CORE_SCHEMA_KEY ? key.slice(7) : void 0;
|
|
@@ -5645,7 +5657,8 @@ var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
|
5645
5657
|
constructor(adapterName, currentVersion, setting, options) {
|
|
5646
5658
|
const settings = options?.settings ?? (setting === void 0 ? [] : [setting]);
|
|
5647
5659
|
const plugins = settings.flatMap((mismatch) => pluginOf(mismatch) ?? []);
|
|
5648
|
-
|
|
5660
|
+
const newer = newerCore(settings);
|
|
5661
|
+
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 });
|
|
5649
5662
|
this.adapterName = adapterName;
|
|
5650
5663
|
this.currentVersion = currentVersion;
|
|
5651
5664
|
this.setting = setting;
|
|
@@ -5722,43 +5735,6 @@ const withSchemaFence = (adapter, adapterName, expected, fix) => {
|
|
|
5722
5735
|
const METER = Symbol.for("@hot-updater/plugin-core/read-meter");
|
|
5723
5736
|
const readMeterOf = (database) => typeof database === "object" && database !== null ? database[METER] : void 0;
|
|
5724
5737
|
//#endregion
|
|
5725
|
-
//#region ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
5726
|
-
const storedSettings = async (adapter, keys) => {
|
|
5727
|
-
const rows = await readSettings(adapter, keys);
|
|
5728
|
-
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
5729
|
-
};
|
|
5730
|
-
const writeSchemaSettings = async (adapter, adapterName, settings) => {
|
|
5731
|
-
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
5732
|
-
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
5733
|
-
const row = stored.get(key);
|
|
5734
|
-
if (row === null || row === void 0) return [{
|
|
5735
|
-
type: "insert",
|
|
5736
|
-
table: SETTINGS_TABLE,
|
|
5737
|
-
row: {
|
|
5738
|
-
key,
|
|
5739
|
-
value,
|
|
5740
|
-
_v: 0
|
|
5741
|
-
}
|
|
5742
|
-
}];
|
|
5743
|
-
if (row.value === value) return [];
|
|
5744
|
-
return [{
|
|
5745
|
-
type: "patch",
|
|
5746
|
-
table: SETTINGS_TABLE,
|
|
5747
|
-
key: [key],
|
|
5748
|
-
set: { value },
|
|
5749
|
-
guard: { v: Number(row._v) },
|
|
5750
|
-
previous: row
|
|
5751
|
-
}];
|
|
5752
|
-
});
|
|
5753
|
-
if (ops.length === 0) return;
|
|
5754
|
-
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
5755
|
-
};
|
|
5756
|
-
const migrateSchema = async (adapter, adapterName, tables, settings) => {
|
|
5757
|
-
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
5758
|
-
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
5759
|
-
await writeSchemaSettings(adapter, adapterName, settings);
|
|
5760
|
-
};
|
|
5761
|
-
//#endregion
|
|
5762
5738
|
//#region ../plugin-core/dist/engine/core/schema.mjs
|
|
5763
5739
|
const CHANNEL_ID = {
|
|
5764
5740
|
type: "string",
|
|
@@ -6047,6 +6023,61 @@ const refuseV0Database = (adapterName, stored) => {
|
|
|
6047
6023
|
if (typeof version !== "string" || stored.has("schema.engine")) return;
|
|
6048
6024
|
throw new HotUpdaterSchemaMigrationRequiredError(adapterName, version);
|
|
6049
6025
|
};
|
|
6026
|
+
const DEFAULT_ORDERED_SETTINGS = ["schema.core"];
|
|
6027
|
+
const refuseNewerSchema = (adapterName, stored, settings, ordered = DEFAULT_ORDERED_SETTINGS) => {
|
|
6028
|
+
const newer = ordered.flatMap((key) => {
|
|
6029
|
+
const found = stored.get(key);
|
|
6030
|
+
const expected = settings[key];
|
|
6031
|
+
return typeof found === "string" && expected !== void 0 && compareVersions(found, expected) > 0 ? [{
|
|
6032
|
+
key,
|
|
6033
|
+
found,
|
|
6034
|
+
expected
|
|
6035
|
+
}] : [];
|
|
6036
|
+
});
|
|
6037
|
+
const core = newer.find(({ key }) => key === "schema.core");
|
|
6038
|
+
if (core === void 0) return;
|
|
6039
|
+
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.`);
|
|
6040
|
+
};
|
|
6041
|
+
//#endregion
|
|
6042
|
+
//#region ../plugin-core/dist/engine/db/schemaSettings.mjs
|
|
6043
|
+
const storedSettings = async (adapter, keys) => {
|
|
6044
|
+
const rows = await readSettings(adapter, keys);
|
|
6045
|
+
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
6046
|
+
};
|
|
6047
|
+
const writeSchemaSettings = async (adapter, adapterName, settings, ordered) => {
|
|
6048
|
+
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
6049
|
+
refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
6050
|
+
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
6051
|
+
const row = stored.get(key);
|
|
6052
|
+
if (row === null || row === void 0) return [{
|
|
6053
|
+
type: "insert",
|
|
6054
|
+
table: SETTINGS_TABLE,
|
|
6055
|
+
row: {
|
|
6056
|
+
key,
|
|
6057
|
+
value,
|
|
6058
|
+
_v: 0
|
|
6059
|
+
}
|
|
6060
|
+
}];
|
|
6061
|
+
if (row.value === value) return [];
|
|
6062
|
+
return [{
|
|
6063
|
+
type: "patch",
|
|
6064
|
+
table: SETTINGS_TABLE,
|
|
6065
|
+
key: [key],
|
|
6066
|
+
set: { value },
|
|
6067
|
+
guard: { v: Number(row._v) },
|
|
6068
|
+
previous: row
|
|
6069
|
+
}];
|
|
6070
|
+
});
|
|
6071
|
+
if (ops.length === 0) return;
|
|
6072
|
+
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
6073
|
+
};
|
|
6074
|
+
const migrateSchema = async (adapter, adapterName, tables, settings, ordered) => {
|
|
6075
|
+
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
6076
|
+
const stored = await storedSettings(adapter, Object.keys(settings)).catch(() => void 0);
|
|
6077
|
+
if (stored !== void 0) refuseNewerSchema(adapterName, new Map([...stored].map(([key, row]) => [key, row?.value])), settings, ordered);
|
|
6078
|
+
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
6079
|
+
await writeSchemaSettings(adapter, adapterName, settings, ordered);
|
|
6080
|
+
};
|
|
6050
6081
|
//#endregion
|
|
6051
6082
|
//#region ../plugin-core/dist/engine/database/cursor.mjs
|
|
6052
6083
|
const encoder$3 = new TextEncoder();
|
|
@@ -7007,6 +7038,7 @@ const createEngineMigrator = (options) => {
|
|
|
7007
7038
|
const makeResult = async (migrate = {}) => {
|
|
7008
7039
|
const stored = await options.readSettings();
|
|
7009
7040
|
refuseV0Database(options.adapterName, stored);
|
|
7041
|
+
refuseNewerSchema(options.adapterName, stored, options.settings, options.ordered);
|
|
7010
7042
|
if (Object.entries(options.settings).every(([key, value]) => stored.get(key) === value)) return getEmptyMigrationResult();
|
|
7011
7043
|
return {
|
|
7012
7044
|
operations: [...options.schema.tables.map((table) => ({
|
|
@@ -7022,7 +7054,7 @@ const createEngineMigrator = (options) => {
|
|
|
7022
7054
|
type: "custom",
|
|
7023
7055
|
description: `Write the schema settings: ${Object.keys(options.settings).join(", ")}`
|
|
7024
7056
|
}]],
|
|
7025
|
-
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings)
|
|
7057
|
+
execute: () => migrateSchema(options.adapter, options.adapterName, options.schema.tables, options.settings, options.ordered)
|
|
7026
7058
|
};
|
|
7027
7059
|
};
|
|
7028
7060
|
return {
|
|
@@ -7050,8 +7082,10 @@ const coreSettings = {
|
|
|
7050
7082
|
};
|
|
7051
7083
|
const coreTarget = {
|
|
7052
7084
|
schema: coreSchema,
|
|
7053
|
-
settings: coreSettings
|
|
7085
|
+
settings: coreSettings,
|
|
7086
|
+
ordered: ["schema.core"]
|
|
7054
7087
|
};
|
|
7088
|
+
const isOfficialPlugin$1 = (plugin) => Reflect.get(plugin, Symbol.for("@hot-updater/server/official-plugin")) === true;
|
|
7055
7089
|
resolveSchema([aggregateBatchingModule]).tables;
|
|
7056
7090
|
const pluginSettings = (plugins) => Object.fromEntries(plugins.map(({ id, schemaVersion }) => [`schema.${id}`, schemaVersion]));
|
|
7057
7091
|
const pluginModule = ({ id, schema, namespace }) => ({
|
|
@@ -7064,15 +7098,17 @@ const toolingTargetOf = (plugins) => plugins.length === 0 ? coreTarget : {
|
|
|
7064
7098
|
settings: {
|
|
7065
7099
|
...coreSettings,
|
|
7066
7100
|
...pluginSettings(plugins)
|
|
7067
|
-
}
|
|
7101
|
+
},
|
|
7102
|
+
ordered: [...coreTarget.ordered, ...plugins.flatMap((plugin) => isOfficialPlugin$1(plugin) ? [`schema.${plugin.id}`] : [])]
|
|
7068
7103
|
};
|
|
7069
7104
|
const createEngineDatabase = ({ name, adapter, onCachedRoutesChange, aggregateBatching, retry, readSettings: readStored }) => {
|
|
7070
7105
|
const fenced = withSchemaFence(adapter, name, coreSettings);
|
|
7071
|
-
const createMigrator = ({ schema, settings } = coreTarget) => createEngineMigrator({
|
|
7106
|
+
const createMigrator = ({ schema, settings, ordered } = coreTarget) => createEngineMigrator({
|
|
7072
7107
|
adapterName: name,
|
|
7073
7108
|
adapter,
|
|
7074
7109
|
schema,
|
|
7075
7110
|
settings,
|
|
7111
|
+
ordered,
|
|
7076
7112
|
readSettings: readStored ?? (async () => {
|
|
7077
7113
|
const rows = await readSettings(adapter, Object.keys(settings)).catch((error) => {
|
|
7078
7114
|
if (isMissingSchemaError(error)) return [];
|
|
@@ -8031,7 +8067,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
8031
8067
|
};
|
|
8032
8068
|
//#endregion
|
|
8033
8069
|
//#region ../../packages/server/dist/version.mjs
|
|
8034
|
-
const HOT_UPDATER_SERVER_VERSION = "1.1.
|
|
8070
|
+
const HOT_UPDATER_SERVER_VERSION = "1.1.19";
|
|
8035
8071
|
//#endregion
|
|
8036
8072
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
8037
8073
|
const createVersionRouteHandlers = (plugins = []) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/azure",
|
|
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
|
"engines": {
|
|
7
7
|
"node": "^22.23.4 || ^24.22.1 || >=26.12.1"
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"@azure/core-auth": "1.11.0",
|
|
43
43
|
"@azure/cosmos": "4.10.1",
|
|
44
44
|
"@azure/storage-blob": "12.34.0",
|
|
45
|
-
"@hot-updater/cli-tools": "1.1.
|
|
46
|
-
"@hot-updater/plugin-core": "1.1.
|
|
47
|
-
"@hot-updater/protocol": "1.1.
|
|
48
|
-
"@hot-updater/server": "1.1.
|
|
45
|
+
"@hot-updater/cli-tools": "1.1.19",
|
|
46
|
+
"@hot-updater/plugin-core": "1.1.19",
|
|
47
|
+
"@hot-updater/protocol": "1.1.19",
|
|
48
|
+
"@hot-updater/server": "1.1.19"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@azure/functions": "4.16.5",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"execa": "9.5.2",
|
|
54
54
|
"jszip": "^3.10.1",
|
|
55
55
|
"vitest": "4.1.4",
|
|
56
|
-
"@hot-updater/test-utils": "1.1.
|
|
56
|
+
"@hot-updater/test-utils": "1.1.19"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsdown",
|