@hot-updater/plugin-core 1.0.0-rc.46 → 1.0.0-rc.47
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/engine/database/fence.cjs +1 -1
- package/dist/engine/database/fence.mjs +1 -1
- package/dist/engine/db/coreDatabase.d.cts +3 -3
- package/dist/engine/db/coreDatabase.d.mts +3 -3
- package/dist/engine/db/engineMigrator.cjs +2 -2
- package/dist/engine/db/engineMigrator.mjs +3 -3
- package/dist/engine/db/engineSqlMigrator.cjs +3 -3
- package/dist/engine/db/engineSqlMigrator.d.cts +2 -2
- package/dist/engine/db/engineSqlMigrator.d.mts +2 -2
- package/dist/engine/db/engineSqlMigrator.mjs +4 -4
- package/dist/engine/db/schemaSettings.cjs +4 -25
- package/dist/engine/db/schemaSettings.d.cts +1 -1
- package/dist/engine/db/schemaSettings.d.mts +1 -1
- package/dist/engine/db/schemaSettings.mjs +5 -26
- package/dist/engine/db/settingsMigrator.cjs +12 -14
- package/dist/engine/db/settingsMigrator.d.cts +2 -3
- package/dist/engine/db/settingsMigrator.d.mts +2 -3
- package/dist/engine/db/settingsMigrator.mjs +13 -15
- package/dist/releaseCatalogCompiler.cjs +8 -21
- package/dist/releaseCatalogCompiler.mjs +8 -21
- package/dist/serverPlugin/definePlugin.d.cts +0 -2
- package/dist/serverPlugin/definePlugin.d.mts +0 -2
- package/dist/types/databaseRows.d.cts +1 -1
- package/dist/types/databaseRows.d.mts +1 -1
- package/package.json +3 -3
|
@@ -34,7 +34,7 @@ const SETTINGS_TABLE = {
|
|
|
34
34
|
const ENGINE_SCHEMA_KEY = "schema.engine";
|
|
35
35
|
const CORE_SCHEMA_KEY = "schema.core";
|
|
36
36
|
const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
|
|
37
|
-
const settingMessage = (adapterName, { key, expected, found }) => `Hot Updater schema setting "${key}" for ${adapterName} is ${found === null ? "missing" : `"${found}"`}; expected "${expected}".
|
|
37
|
+
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\`.`;
|
|
38
38
|
/** The plugin a `schema.<id>` setting belongs to; undefined for core's and the engine's. */
|
|
39
39
|
const pluginOf = ({ key }) => key.startsWith("schema.") && key !== "schema.engine" && key !== CORE_SCHEMA_KEY ? key.slice(7) : void 0;
|
|
40
40
|
const listed = (items) => items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
|
|
@@ -34,7 +34,7 @@ const SETTINGS_TABLE = {
|
|
|
34
34
|
const ENGINE_SCHEMA_KEY = "schema.engine";
|
|
35
35
|
const CORE_SCHEMA_KEY = "schema.core";
|
|
36
36
|
const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
|
|
37
|
-
const settingMessage = (adapterName, { key, expected, found }) => `Hot Updater schema setting "${key}" for ${adapterName} is ${found === null ? "missing" : `"${found}"`}; expected "${expected}".
|
|
37
|
+
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\`.`;
|
|
38
38
|
/** The plugin a `schema.<id>` setting belongs to; undefined for core's and the engine's. */
|
|
39
39
|
const pluginOf = ({ key }) => key.startsWith("schema.") && key !== "schema.engine" && key !== CORE_SCHEMA_KEY ? key.slice(7) : void 0;
|
|
40
40
|
const listed = (items) => items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
|
|
@@ -60,9 +60,9 @@ interface EngineDatabaseOptions {
|
|
|
60
60
|
readonly retry?: RetryOptions;
|
|
61
61
|
/**
|
|
62
62
|
* How `hot-updater db migrate` reads the stored settings rows, by key; by
|
|
63
|
-
* default through the adapter. An adapter whose
|
|
64
|
-
*
|
|
65
|
-
*
|
|
63
|
+
* default the engine's keys through the adapter. An adapter whose v0
|
|
64
|
+
* database kept other settings rows reads every row itself, so the
|
|
65
|
+
* migrator refuses a v0 database.
|
|
66
66
|
*/
|
|
67
67
|
readonly readSettings?: () => Promise<ReadonlyMap<string, unknown>>;
|
|
68
68
|
}
|
|
@@ -60,9 +60,9 @@ interface EngineDatabaseOptions {
|
|
|
60
60
|
readonly retry?: RetryOptions;
|
|
61
61
|
/**
|
|
62
62
|
* How `hot-updater db migrate` reads the stored settings rows, by key; by
|
|
63
|
-
* default through the adapter. An adapter whose
|
|
64
|
-
*
|
|
65
|
-
*
|
|
63
|
+
* default the engine's keys through the adapter. An adapter whose v0
|
|
64
|
+
* database kept other settings rows reads every row itself, so the
|
|
65
|
+
* migrator refuses a v0 database.
|
|
66
66
|
*/
|
|
67
67
|
readonly readSettings?: () => Promise<ReadonlyMap<string, unknown>>;
|
|
68
68
|
}
|
|
@@ -7,13 +7,13 @@ const require_settingsMigrator = require("./settingsMigrator.cjs");
|
|
|
7
7
|
* `hot-updater db migrate` for a store whose adapter creates its own tables
|
|
8
8
|
* (MongoDB and the key-value stores): the tables and indexes, then the
|
|
9
9
|
* settings rows, applied when a setting is missing or different, and refused
|
|
10
|
-
* on a database
|
|
10
|
+
* on a v0 database.
|
|
11
11
|
*/
|
|
12
12
|
const createEngineMigrator = (options) => {
|
|
13
13
|
const getVersion = async () => require_settingsMigrator.storedSchemaVersion(await options.readSettings());
|
|
14
14
|
const makeResult = async (migrate = {}) => {
|
|
15
15
|
const stored = await options.readSettings();
|
|
16
|
-
require_settingsMigrator.
|
|
16
|
+
require_settingsMigrator.refuseV0Database(options.adapterName, stored);
|
|
17
17
|
if (Object.entries(options.settings).every(([key, value]) => stored.get(key) === value)) return require_fixedMigratorShared.getEmptyMigrationResult();
|
|
18
18
|
return {
|
|
19
19
|
operations: [...options.schema.tables.map((table) => ({
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { HOT_UPDATER_SCHEMA_VERSION } from "../core/schema.mjs";
|
|
2
2
|
import { getEmptyMigrationResult } from "./fixedMigratorShared.mjs";
|
|
3
3
|
import { migrateSchema } from "./schemaSettings.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { refuseV0Database, storedSchemaVersion } from "./settingsMigrator.mjs";
|
|
5
5
|
//#region src/engine/db/engineMigrator.ts
|
|
6
6
|
/**
|
|
7
7
|
* `hot-updater db migrate` for a store whose adapter creates its own tables
|
|
8
8
|
* (MongoDB and the key-value stores): the tables and indexes, then the
|
|
9
9
|
* settings rows, applied when a setting is missing or different, and refused
|
|
10
|
-
* on a database
|
|
10
|
+
* on a v0 database.
|
|
11
11
|
*/
|
|
12
12
|
const createEngineMigrator = (options) => {
|
|
13
13
|
const getVersion = async () => storedSchemaVersion(await options.readSettings());
|
|
14
14
|
const makeResult = async (migrate = {}) => {
|
|
15
15
|
const stored = await options.readSettings();
|
|
16
|
-
|
|
16
|
+
refuseV0Database(options.adapterName, stored);
|
|
17
17
|
if (Object.entries(options.settings).every(([key, value]) => stored.get(key) === value)) return getEmptyMigrationResult();
|
|
18
18
|
return {
|
|
19
19
|
operations: [...options.schema.tables.map((table) => ({
|
|
@@ -16,8 +16,8 @@ const run = async (executor, statements) => {
|
|
|
16
16
|
/**
|
|
17
17
|
* `hot-updater db migrate` and `db generate` for an SQL provider on the
|
|
18
18
|
* engine: the generated SQL schema, applied when a settings row is missing or
|
|
19
|
-
* different, and refused on a database
|
|
20
|
-
*
|
|
19
|
+
* different, and refused on a v0 database. A SQL adapter's `createMigrator`
|
|
20
|
+
* returns it, as `kyselyAdapter`'s does.
|
|
21
21
|
*/
|
|
22
22
|
const createEngineSqlMigrator = (options) => {
|
|
23
23
|
/** No settings table yet reads as an empty database. */
|
|
@@ -25,7 +25,7 @@ const createEngineSqlMigrator = (options) => {
|
|
|
25
25
|
const getVersion = async () => require_settingsMigrator.storedSchemaVersion(await read());
|
|
26
26
|
const makeResult = async (migrate = {}) => {
|
|
27
27
|
const stored = await read();
|
|
28
|
-
require_settingsMigrator.
|
|
28
|
+
require_settingsMigrator.refuseV0Database(options.adapterName, stored);
|
|
29
29
|
if (Object.entries(options.settings).every(([key, value]) => stored.get(key) === value)) return require_fixedMigratorShared.getEmptyMigrationResult();
|
|
30
30
|
const statements = require_engineSql.generateEngineSql(options.executor.dialect, options.schema, options.settings, options);
|
|
31
31
|
return {
|
|
@@ -13,8 +13,8 @@ interface EngineSqlMigratorOptions extends EngineSqlOptions {
|
|
|
13
13
|
/**
|
|
14
14
|
* `hot-updater db migrate` and `db generate` for an SQL provider on the
|
|
15
15
|
* engine: the generated SQL schema, applied when a settings row is missing or
|
|
16
|
-
* different, and refused on a database
|
|
17
|
-
*
|
|
16
|
+
* different, and refused on a v0 database. A SQL adapter's `createMigrator`
|
|
17
|
+
* returns it, as `kyselyAdapter`'s does.
|
|
18
18
|
*/
|
|
19
19
|
declare const createEngineSqlMigrator: (options: EngineSqlMigratorOptions) => Migrator;
|
|
20
20
|
//#endregion
|
|
@@ -13,8 +13,8 @@ interface EngineSqlMigratorOptions extends EngineSqlOptions {
|
|
|
13
13
|
/**
|
|
14
14
|
* `hot-updater db migrate` and `db generate` for an SQL provider on the
|
|
15
15
|
* engine: the generated SQL schema, applied when a settings row is missing or
|
|
16
|
-
* different, and refused on a database
|
|
17
|
-
*
|
|
16
|
+
* different, and refused on a v0 database. A SQL adapter's `createMigrator`
|
|
17
|
+
* returns it, as `kyselyAdapter`'s does.
|
|
18
18
|
*/
|
|
19
19
|
declare const createEngineSqlMigrator: (options: EngineSqlMigratorOptions) => Migrator;
|
|
20
20
|
//#endregion
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HOT_UPDATER_SCHEMA_VERSION } from "../core/schema.mjs";
|
|
2
2
|
import { getEmptyMigrationResult } from "./fixedMigratorShared.mjs";
|
|
3
3
|
import { generateEngineSql } from "./engineSql.mjs";
|
|
4
|
-
import { readStoredSettings,
|
|
4
|
+
import { readStoredSettings, refuseV0Database, storedSchemaVersion } from "./settingsMigrator.mjs";
|
|
5
5
|
//#region src/engine/db/engineSqlMigrator.ts
|
|
6
6
|
/** Runs the statements in one transaction where the dialect's DDL is transactional. */
|
|
7
7
|
const run = async (executor, statements) => {
|
|
@@ -16,8 +16,8 @@ const run = async (executor, statements) => {
|
|
|
16
16
|
/**
|
|
17
17
|
* `hot-updater db migrate` and `db generate` for an SQL provider on the
|
|
18
18
|
* engine: the generated SQL schema, applied when a settings row is missing or
|
|
19
|
-
* different, and refused on a database
|
|
20
|
-
*
|
|
19
|
+
* different, and refused on a v0 database. A SQL adapter's `createMigrator`
|
|
20
|
+
* returns it, as `kyselyAdapter`'s does.
|
|
21
21
|
*/
|
|
22
22
|
const createEngineSqlMigrator = (options) => {
|
|
23
23
|
/** No settings table yet reads as an empty database. */
|
|
@@ -25,7 +25,7 @@ const createEngineSqlMigrator = (options) => {
|
|
|
25
25
|
const getVersion = async () => storedSchemaVersion(await read());
|
|
26
26
|
const makeResult = async (migrate = {}) => {
|
|
27
27
|
const stored = await read();
|
|
28
|
-
|
|
28
|
+
refuseV0Database(options.adapterName, stored);
|
|
29
29
|
if (Object.entries(options.settings).every(([key, value]) => stored.get(key) === value)) return getEmptyMigrationResult();
|
|
30
30
|
const statements = generateEngineSql(options.executor.dialect, options.schema, options.settings, options);
|
|
31
31
|
return {
|
|
@@ -1,25 +1,12 @@
|
|
|
1
1
|
const require_fence = require("../database/fence.cjs");
|
|
2
2
|
//#region src/engine/db/schemaSettings.ts
|
|
3
|
-
/** Refuses a database with `schema.core` but no `schema.engine`: it predates the engine. */
|
|
4
|
-
const assertEngineDatabase = (adapterName, stored) => {
|
|
5
|
-
if (stored.get("schema.core") && !stored.get("schema.engine")) throw new require_fence.HotUpdaterSchemaMigrationRequiredError(adapterName, String(stored.get("schema.core").value), {
|
|
6
|
-
key: require_fence.ENGINE_SCHEMA_KEY,
|
|
7
|
-
expected: "1",
|
|
8
|
-
found: null
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
3
|
const storedSettings = async (adapter, keys) => {
|
|
12
4
|
const rows = await require_fence.readSettings(adapter, keys);
|
|
13
5
|
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
14
6
|
};
|
|
15
|
-
/** Writes the settings rows after every table exists
|
|
7
|
+
/** Writes the settings rows after every table exists. */
|
|
16
8
|
const writeSchemaSettings = async (adapter, adapterName, settings) => {
|
|
17
|
-
const stored = await storedSettings(adapter,
|
|
18
|
-
"schema.core",
|
|
19
|
-
require_fence.ENGINE_SCHEMA_KEY,
|
|
20
|
-
...Object.keys(settings)
|
|
21
|
-
])]);
|
|
22
|
-
assertEngineDatabase(adapterName, stored);
|
|
9
|
+
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
23
10
|
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
24
11
|
const row = stored.get(key);
|
|
25
12
|
if (row === null || row === void 0) return [{
|
|
@@ -42,19 +29,11 @@ const writeSchemaSettings = async (adapter, adapterName, settings) => {
|
|
|
42
29
|
}];
|
|
43
30
|
});
|
|
44
31
|
if (ops.length === 0) return;
|
|
45
|
-
if (!(await adapter.write(ops)).ok) throw new Error(
|
|
32
|
+
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
46
33
|
};
|
|
47
|
-
/**
|
|
48
|
-
* Creates or updates every table, then writes the settings rows last. A
|
|
49
|
-
* pre-engine database is refused before any table changes.
|
|
50
|
-
*/
|
|
34
|
+
/** Creates or updates every table, then writes the settings rows last. */
|
|
51
35
|
const migrateSchema = async (adapter, adapterName, tables, settings) => {
|
|
52
36
|
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
53
|
-
const stored = await storedSettings(adapter, ["schema.core", require_fence.ENGINE_SCHEMA_KEY]).catch((error) => {
|
|
54
|
-
if (!require_fence.isMissingSchemaError(error)) throw error;
|
|
55
|
-
return /* @__PURE__ */ new Map();
|
|
56
|
-
});
|
|
57
|
-
assertEngineDatabase(adapterName, stored);
|
|
58
37
|
await adapter.migrations.apply([...tables, require_fence.SETTINGS_TABLE]);
|
|
59
38
|
await writeSchemaSettings(adapter, adapterName, settings);
|
|
60
39
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DatabaseAdapter } from "../../database/adapter.cjs";
|
|
2
2
|
import { SchemaSettings } from "../database/fence.cjs";
|
|
3
3
|
//#region src/engine/db/schemaSettings.d.ts
|
|
4
|
-
/** Writes the settings rows after every table exists
|
|
4
|
+
/** Writes the settings rows after every table exists. */
|
|
5
5
|
declare const writeSchemaSettings: (adapter: DatabaseAdapter, adapterName: string, settings: SchemaSettings) => Promise<void>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { writeSchemaSettings };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DatabaseAdapter } from "../../database/adapter.mjs";
|
|
2
2
|
import { SchemaSettings } from "../database/fence.mjs";
|
|
3
3
|
//#region src/engine/db/schemaSettings.d.ts
|
|
4
|
-
/** Writes the settings rows after every table exists
|
|
4
|
+
/** Writes the settings rows after every table exists. */
|
|
5
5
|
declare const writeSchemaSettings: (adapter: DatabaseAdapter, adapterName: string, settings: SchemaSettings) => Promise<void>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { writeSchemaSettings };
|
|
@@ -1,25 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SETTINGS_TABLE, readSettings } from "../database/fence.mjs";
|
|
2
2
|
//#region src/engine/db/schemaSettings.ts
|
|
3
|
-
/** Refuses a database with `schema.core` but no `schema.engine`: it predates the engine. */
|
|
4
|
-
const assertEngineDatabase = (adapterName, stored) => {
|
|
5
|
-
if (stored.get("schema.core") && !stored.get("schema.engine")) throw new HotUpdaterSchemaMigrationRequiredError(adapterName, String(stored.get("schema.core").value), {
|
|
6
|
-
key: ENGINE_SCHEMA_KEY,
|
|
7
|
-
expected: "1",
|
|
8
|
-
found: null
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
3
|
const storedSettings = async (adapter, keys) => {
|
|
12
4
|
const rows = await readSettings(adapter, keys);
|
|
13
5
|
return new Map(keys.map((key, position) => [key, rows[position] ?? null]));
|
|
14
6
|
};
|
|
15
|
-
/** Writes the settings rows after every table exists
|
|
7
|
+
/** Writes the settings rows after every table exists. */
|
|
16
8
|
const writeSchemaSettings = async (adapter, adapterName, settings) => {
|
|
17
|
-
const stored = await storedSettings(adapter,
|
|
18
|
-
"schema.core",
|
|
19
|
-
ENGINE_SCHEMA_KEY,
|
|
20
|
-
...Object.keys(settings)
|
|
21
|
-
])]);
|
|
22
|
-
assertEngineDatabase(adapterName, stored);
|
|
9
|
+
const stored = await storedSettings(adapter, Object.keys(settings));
|
|
23
10
|
const ops = Object.entries(settings).flatMap(([key, value]) => {
|
|
24
11
|
const row = stored.get(key);
|
|
25
12
|
if (row === null || row === void 0) return [{
|
|
@@ -42,19 +29,11 @@ const writeSchemaSettings = async (adapter, adapterName, settings) => {
|
|
|
42
29
|
}];
|
|
43
30
|
});
|
|
44
31
|
if (ops.length === 0) return;
|
|
45
|
-
if (!(await adapter.write(ops)).ok) throw new Error(
|
|
32
|
+
if (!(await adapter.write(ops)).ok) throw new Error(`${adapterName}: the schema settings changed during the migration; run it again.`);
|
|
46
33
|
};
|
|
47
|
-
/**
|
|
48
|
-
* Creates or updates every table, then writes the settings rows last. A
|
|
49
|
-
* pre-engine database is refused before any table changes.
|
|
50
|
-
*/
|
|
34
|
+
/** Creates or updates every table, then writes the settings rows last. */
|
|
51
35
|
const migrateSchema = async (adapter, adapterName, tables, settings) => {
|
|
52
36
|
if (adapter.migrations === void 0) throw new Error(`${adapterName} creates its tables with its own tooling; write only the settings rows.`);
|
|
53
|
-
const stored = await storedSettings(adapter, ["schema.core", ENGINE_SCHEMA_KEY]).catch((error) => {
|
|
54
|
-
if (!isMissingSchemaError(error)) throw error;
|
|
55
|
-
return /* @__PURE__ */ new Map();
|
|
56
|
-
});
|
|
57
|
-
assertEngineDatabase(adapterName, stored);
|
|
58
37
|
await adapter.migrations.apply([...tables, SETTINGS_TABLE]);
|
|
59
38
|
await writeSchemaSettings(adapter, adapterName, settings);
|
|
60
39
|
};
|
|
@@ -26,22 +26,20 @@ const storedSchemaVersion = (stored) => {
|
|
|
26
26
|
const version = stored?.get("schema.core") ?? stored?.get("version");
|
|
27
27
|
return typeof version === "string" ? version : void 0;
|
|
28
28
|
};
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} : void 0);
|
|
29
|
+
/**
|
|
30
|
+
* A v0 database, whose settings hold `version` and no `schema.engine`, is
|
|
31
|
+
* recreated, never converted.
|
|
32
|
+
*/
|
|
33
|
+
const refuseV0Database = (adapterName, stored) => {
|
|
34
|
+
const version = stored.get("version");
|
|
35
|
+
if (typeof version !== "string" || stored.has("schema.engine")) return;
|
|
36
|
+
throw new require_fence.HotUpdaterSchemaMigrationRequiredError(adapterName, version);
|
|
38
37
|
};
|
|
39
38
|
/**
|
|
40
39
|
* `hot-updater db migrate` for an ORM that applies the DDL itself (Drizzle,
|
|
41
40
|
* Prisma): it sets what the ORM cannot declare, writes the settings rows, and
|
|
42
|
-
* refuses a v0
|
|
43
|
-
*
|
|
44
|
-
* adapters' do.
|
|
41
|
+
* refuses a v0 database. The `createMigrator` of an adapter whose ORM
|
|
42
|
+
* creates the tables returns it, as the Drizzle and Prisma adapters' do.
|
|
45
43
|
*/
|
|
46
44
|
const createSettingsMigrator = (options) => {
|
|
47
45
|
const read = () => readStoredSettings(options.executor);
|
|
@@ -49,7 +47,7 @@ const createSettingsMigrator = (options) => {
|
|
|
49
47
|
const makeResult = async (migrate = {}) => {
|
|
50
48
|
const stored = await read();
|
|
51
49
|
if (stored === null) throw new Error(`${options.adapterName}: the Hot Updater tables are missing. Run \`hot-updater db generate\`, apply the schema with ${options.applyTables}, then migrate again.`);
|
|
52
|
-
|
|
50
|
+
refuseV0Database(options.adapterName, stored);
|
|
53
51
|
if (migrate.updateSettings === false || Object.entries(options.settings).every(([key, value]) => stored.get(key) === value)) return require_fixedMigratorShared.getEmptyMigrationResult();
|
|
54
52
|
const fixups = options.fixups?.statements ?? [];
|
|
55
53
|
const statements = [...fixups, ...require_engineSql.settingsStatements(options.executor.dialect, options.settings)];
|
|
@@ -89,5 +87,5 @@ const createSettingsMigrator = (options) => {
|
|
|
89
87
|
//#endregion
|
|
90
88
|
exports.createSettingsMigrator = createSettingsMigrator;
|
|
91
89
|
exports.readStoredSettings = readStoredSettings;
|
|
92
|
-
exports.
|
|
90
|
+
exports.refuseV0Database = refuseV0Database;
|
|
93
91
|
exports.storedSchemaVersion = storedSchemaVersion;
|
|
@@ -5,9 +5,8 @@ import { SqlExecutor } from "../database/sql/sqlAdapter.cjs";
|
|
|
5
5
|
/**
|
|
6
6
|
* `hot-updater db migrate` for an ORM that applies the DDL itself (Drizzle,
|
|
7
7
|
* Prisma): it sets what the ORM cannot declare, writes the settings rows, and
|
|
8
|
-
* refuses a v0
|
|
9
|
-
*
|
|
10
|
-
* adapters' do.
|
|
8
|
+
* refuses a v0 database. The `createMigrator` of an adapter whose ORM
|
|
9
|
+
* creates the tables returns it, as the Drizzle and Prisma adapters' do.
|
|
11
10
|
*/
|
|
12
11
|
declare const createSettingsMigrator: (options: {
|
|
13
12
|
readonly adapterName: string;
|
|
@@ -5,9 +5,8 @@ import { SqlExecutor } from "../database/sql/sqlAdapter.mjs";
|
|
|
5
5
|
/**
|
|
6
6
|
* `hot-updater db migrate` for an ORM that applies the DDL itself (Drizzle,
|
|
7
7
|
* Prisma): it sets what the ORM cannot declare, writes the settings rows, and
|
|
8
|
-
* refuses a v0
|
|
9
|
-
*
|
|
10
|
-
* adapters' do.
|
|
8
|
+
* refuses a v0 database. The `createMigrator` of an adapter whose ORM
|
|
9
|
+
* creates the tables returns it, as the Drizzle and Prisma adapters' do.
|
|
11
10
|
*/
|
|
12
11
|
declare const createSettingsMigrator: (options: {
|
|
13
12
|
readonly adapterName: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HOT_UPDATER_SCHEMA_VERSION } from "../core/schema.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { HotUpdaterSchemaMigrationRequiredError, SETTINGS_TABLE, isMissingSchemaError } from "../database/fence.mjs";
|
|
3
3
|
import { getEmptyMigrationResult } from "./fixedMigratorShared.mjs";
|
|
4
4
|
import { quoteSql } from "../database/sql/sqlSchema.mjs";
|
|
5
5
|
import { settingsStatements } from "./engineSql.mjs";
|
|
@@ -26,22 +26,20 @@ const storedSchemaVersion = (stored) => {
|
|
|
26
26
|
const version = stored?.get("schema.core") ?? stored?.get("version");
|
|
27
27
|
return typeof version === "string" ? version : void 0;
|
|
28
28
|
};
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} : void 0);
|
|
29
|
+
/**
|
|
30
|
+
* A v0 database, whose settings hold `version` and no `schema.engine`, is
|
|
31
|
+
* recreated, never converted.
|
|
32
|
+
*/
|
|
33
|
+
const refuseV0Database = (adapterName, stored) => {
|
|
34
|
+
const version = stored.get("version");
|
|
35
|
+
if (typeof version !== "string" || stored.has("schema.engine")) return;
|
|
36
|
+
throw new HotUpdaterSchemaMigrationRequiredError(adapterName, version);
|
|
38
37
|
};
|
|
39
38
|
/**
|
|
40
39
|
* `hot-updater db migrate` for an ORM that applies the DDL itself (Drizzle,
|
|
41
40
|
* Prisma): it sets what the ORM cannot declare, writes the settings rows, and
|
|
42
|
-
* refuses a v0
|
|
43
|
-
*
|
|
44
|
-
* adapters' do.
|
|
41
|
+
* refuses a v0 database. The `createMigrator` of an adapter whose ORM
|
|
42
|
+
* creates the tables returns it, as the Drizzle and Prisma adapters' do.
|
|
45
43
|
*/
|
|
46
44
|
const createSettingsMigrator = (options) => {
|
|
47
45
|
const read = () => readStoredSettings(options.executor);
|
|
@@ -49,7 +47,7 @@ const createSettingsMigrator = (options) => {
|
|
|
49
47
|
const makeResult = async (migrate = {}) => {
|
|
50
48
|
const stored = await read();
|
|
51
49
|
if (stored === null) throw new Error(`${options.adapterName}: the Hot Updater tables are missing. Run \`hot-updater db generate\`, apply the schema with ${options.applyTables}, then migrate again.`);
|
|
52
|
-
|
|
50
|
+
refuseV0Database(options.adapterName, stored);
|
|
53
51
|
if (migrate.updateSettings === false || Object.entries(options.settings).every(([key, value]) => stored.get(key) === value)) return getEmptyMigrationResult();
|
|
54
52
|
const fixups = options.fixups?.statements ?? [];
|
|
55
53
|
const statements = [...fixups, ...settingsStatements(options.executor.dialect, options.settings)];
|
|
@@ -87,4 +85,4 @@ const createSettingsMigrator = (options) => {
|
|
|
87
85
|
};
|
|
88
86
|
};
|
|
89
87
|
//#endregion
|
|
90
|
-
export { createSettingsMigrator, readStoredSettings,
|
|
88
|
+
export { createSettingsMigrator, readStoredSettings, refuseV0Database, storedSchemaVersion };
|
|
@@ -109,29 +109,23 @@ function validateReleases(releases, strategy) {
|
|
|
109
109
|
if (seenIds.has(release.id)) throw new ReleaseCatalogCompilationError("INVALID_RELEASE", `Duplicate Release ID: ${release.id}`);
|
|
110
110
|
seenIds.add(release.id);
|
|
111
111
|
if (release.strategy !== strategy) throw new ReleaseCatalogCompilationError("INVALID_RELEASE", `Release ${release.id} has the wrong strategy`);
|
|
112
|
-
if (release.
|
|
112
|
+
if (release.bundleId === null) throw new ReleaseCatalogCompilationError("INVALID_RELEASE", `Release ${release.id} has no Bundle`);
|
|
113
113
|
if (release.targetCohorts.length > _hot_updater_protocol.MAX_TARGET_COHORTS_PER_RELEASE) throw new ReleaseCatalogCompilationError("TARGET_COHORT_LIMIT", `Release ${release.id} exceeds ${_hot_updater_protocol.MAX_TARGET_COHORTS_PER_RELEASE} target cohorts`);
|
|
114
114
|
if (strategy === "APP_VERSION" && (release.targetAppVersion === null || release.fingerprintHash !== null)) throw new ReleaseCatalogCompilationError("INVALID_RELEASE", `Release ${release.id} has an invalid app-version target`);
|
|
115
115
|
if (strategy === "FINGERPRINT" && (release.fingerprintHash === null || release.targetAppVersion !== null)) throw new ReleaseCatalogCompilationError("INVALID_RELEASE", `Release ${release.id} has an invalid fingerprint target`);
|
|
116
116
|
}
|
|
117
|
-
return enabled
|
|
117
|
+
return enabled;
|
|
118
118
|
}
|
|
119
119
|
function collectFrontierReleaseIds(releases) {
|
|
120
120
|
if (releases.every((release) => (0, _hot_updater_protocol.normalizeRolloutCohortCount)(release.rolloutCohortCount) >= _hot_updater_protocol.NUMERIC_COHORT_SIZE)) {
|
|
121
121
|
const retained = /* @__PURE__ */ new Set();
|
|
122
122
|
const bundleIds = /* @__PURE__ */ new Set();
|
|
123
|
-
let embedded = false;
|
|
124
123
|
for (const release of releases) {
|
|
125
|
-
if (release.
|
|
126
|
-
if (!embedded) {
|
|
127
|
-
embedded = true;
|
|
128
|
-
retained.add(release.id);
|
|
129
|
-
}
|
|
130
|
-
} else if (release.bundleId !== null && bundleIds.size < 11 && !bundleIds.has(release.bundleId)) {
|
|
124
|
+
if (release.bundleId !== null && !bundleIds.has(release.bundleId)) {
|
|
131
125
|
bundleIds.add(release.bundleId);
|
|
132
126
|
retained.add(release.id);
|
|
133
127
|
}
|
|
134
|
-
if (
|
|
128
|
+
if (bundleIds.size >= 11) break;
|
|
135
129
|
}
|
|
136
130
|
return retained;
|
|
137
131
|
}
|
|
@@ -148,7 +142,6 @@ function collectFrontierReleaseIds(releases) {
|
|
|
148
142
|
normalized,
|
|
149
143
|
numeric: normalized === void 0 ? null : (0, _hot_updater_protocol.getNumericCohortValue)(normalized),
|
|
150
144
|
bundleIds: /* @__PURE__ */ new Set(),
|
|
151
|
-
embedded: false,
|
|
152
145
|
complete: false
|
|
153
146
|
};
|
|
154
147
|
});
|
|
@@ -173,16 +166,11 @@ function collectFrontierReleaseIds(releases) {
|
|
|
173
166
|
for (const index of eligibleStateIndexes) {
|
|
174
167
|
const state = cohortStates[index];
|
|
175
168
|
if (state.complete) continue;
|
|
176
|
-
if (release.
|
|
177
|
-
if (!state.embedded) {
|
|
178
|
-
state.embedded = true;
|
|
179
|
-
retained.add(release.id);
|
|
180
|
-
}
|
|
181
|
-
} else if (release.bundleId !== null && state.bundleIds.size < 11 && !state.bundleIds.has(release.bundleId)) {
|
|
169
|
+
if (release.bundleId !== null && !state.bundleIds.has(release.bundleId)) {
|
|
182
170
|
state.bundleIds.add(release.bundleId);
|
|
183
171
|
retained.add(release.id);
|
|
184
172
|
}
|
|
185
|
-
if (state.
|
|
173
|
+
if (state.bundleIds.size >= 11) {
|
|
186
174
|
state.complete = true;
|
|
187
175
|
incompleteStateCount -= 1;
|
|
188
176
|
}
|
|
@@ -367,12 +355,11 @@ function projectCompiledCatalog(catalog, appVersion) {
|
|
|
367
355
|
}
|
|
368
356
|
function projectCompiledRollbackCatalog(catalog, appVersion) {
|
|
369
357
|
let indexes;
|
|
370
|
-
if (catalog.strategy === "FINGERPRINT") indexes = catalog.rollbackReleaseIndexes
|
|
358
|
+
if (catalog.strategy === "FINGERPRINT") indexes = catalog.rollbackReleaseIndexes;
|
|
371
359
|
else {
|
|
372
360
|
const canonicalVersion = appVersion && (0, _hot_updater_protocol.canonicalizeAppVersion)(appVersion);
|
|
373
361
|
if (!canonicalVersion) return [];
|
|
374
|
-
|
|
375
|
-
indexes = segment?.rollbackReleaseIndexes ?? segment?.releaseIndexes ?? [];
|
|
362
|
+
indexes = catalog.segments.find((segment) => versionInSegment(canonicalVersion, segment))?.rollbackReleaseIndexes ?? [];
|
|
376
363
|
}
|
|
377
364
|
return indexes.map((index) => catalog.releaseDescriptors[index]);
|
|
378
365
|
}
|
|
@@ -110,29 +110,23 @@ function validateReleases(releases, strategy) {
|
|
|
110
110
|
if (seenIds.has(release.id)) throw new ReleaseCatalogCompilationError("INVALID_RELEASE", `Duplicate Release ID: ${release.id}`);
|
|
111
111
|
seenIds.add(release.id);
|
|
112
112
|
if (release.strategy !== strategy) throw new ReleaseCatalogCompilationError("INVALID_RELEASE", `Release ${release.id} has the wrong strategy`);
|
|
113
|
-
if (release.
|
|
113
|
+
if (release.bundleId === null) throw new ReleaseCatalogCompilationError("INVALID_RELEASE", `Release ${release.id} has no Bundle`);
|
|
114
114
|
if (release.targetCohorts.length > MAX_TARGET_COHORTS_PER_RELEASE) throw new ReleaseCatalogCompilationError("TARGET_COHORT_LIMIT", `Release ${release.id} exceeds ${MAX_TARGET_COHORTS_PER_RELEASE} target cohorts`);
|
|
115
115
|
if (strategy === "APP_VERSION" && (release.targetAppVersion === null || release.fingerprintHash !== null)) throw new ReleaseCatalogCompilationError("INVALID_RELEASE", `Release ${release.id} has an invalid app-version target`);
|
|
116
116
|
if (strategy === "FINGERPRINT" && (release.fingerprintHash === null || release.targetAppVersion !== null)) throw new ReleaseCatalogCompilationError("INVALID_RELEASE", `Release ${release.id} has an invalid fingerprint target`);
|
|
117
117
|
}
|
|
118
|
-
return enabled
|
|
118
|
+
return enabled;
|
|
119
119
|
}
|
|
120
120
|
function collectFrontierReleaseIds(releases) {
|
|
121
121
|
if (releases.every((release) => normalizeRolloutCohortCount(release.rolloutCohortCount) >= NUMERIC_COHORT_SIZE)) {
|
|
122
122
|
const retained = /* @__PURE__ */ new Set();
|
|
123
123
|
const bundleIds = /* @__PURE__ */ new Set();
|
|
124
|
-
let embedded = false;
|
|
125
124
|
for (const release of releases) {
|
|
126
|
-
if (release.
|
|
127
|
-
if (!embedded) {
|
|
128
|
-
embedded = true;
|
|
129
|
-
retained.add(release.id);
|
|
130
|
-
}
|
|
131
|
-
} else if (release.bundleId !== null && bundleIds.size < 11 && !bundleIds.has(release.bundleId)) {
|
|
125
|
+
if (release.bundleId !== null && !bundleIds.has(release.bundleId)) {
|
|
132
126
|
bundleIds.add(release.bundleId);
|
|
133
127
|
retained.add(release.id);
|
|
134
128
|
}
|
|
135
|
-
if (
|
|
129
|
+
if (bundleIds.size >= 11) break;
|
|
136
130
|
}
|
|
137
131
|
return retained;
|
|
138
132
|
}
|
|
@@ -149,7 +143,6 @@ function collectFrontierReleaseIds(releases) {
|
|
|
149
143
|
normalized,
|
|
150
144
|
numeric: normalized === void 0 ? null : getNumericCohortValue(normalized),
|
|
151
145
|
bundleIds: /* @__PURE__ */ new Set(),
|
|
152
|
-
embedded: false,
|
|
153
146
|
complete: false
|
|
154
147
|
};
|
|
155
148
|
});
|
|
@@ -174,16 +167,11 @@ function collectFrontierReleaseIds(releases) {
|
|
|
174
167
|
for (const index of eligibleStateIndexes) {
|
|
175
168
|
const state = cohortStates[index];
|
|
176
169
|
if (state.complete) continue;
|
|
177
|
-
if (release.
|
|
178
|
-
if (!state.embedded) {
|
|
179
|
-
state.embedded = true;
|
|
180
|
-
retained.add(release.id);
|
|
181
|
-
}
|
|
182
|
-
} else if (release.bundleId !== null && state.bundleIds.size < 11 && !state.bundleIds.has(release.bundleId)) {
|
|
170
|
+
if (release.bundleId !== null && !state.bundleIds.has(release.bundleId)) {
|
|
183
171
|
state.bundleIds.add(release.bundleId);
|
|
184
172
|
retained.add(release.id);
|
|
185
173
|
}
|
|
186
|
-
if (state.
|
|
174
|
+
if (state.bundleIds.size >= 11) {
|
|
187
175
|
state.complete = true;
|
|
188
176
|
incompleteStateCount -= 1;
|
|
189
177
|
}
|
|
@@ -368,12 +356,11 @@ function projectCompiledCatalog(catalog, appVersion) {
|
|
|
368
356
|
}
|
|
369
357
|
function projectCompiledRollbackCatalog(catalog, appVersion) {
|
|
370
358
|
let indexes;
|
|
371
|
-
if (catalog.strategy === "FINGERPRINT") indexes = catalog.rollbackReleaseIndexes
|
|
359
|
+
if (catalog.strategy === "FINGERPRINT") indexes = catalog.rollbackReleaseIndexes;
|
|
372
360
|
else {
|
|
373
361
|
const canonicalVersion = appVersion && canonicalizeAppVersion(appVersion);
|
|
374
362
|
if (!canonicalVersion) return [];
|
|
375
|
-
|
|
376
|
-
indexes = segment?.rollbackReleaseIndexes ?? segment?.releaseIndexes ?? [];
|
|
363
|
+
indexes = catalog.segments.find((segment) => versionInSegment(canonicalVersion, segment))?.rollbackReleaseIndexes ?? [];
|
|
377
364
|
}
|
|
378
365
|
return indexes.map((index) => catalog.releaseDescriptors[index]);
|
|
379
366
|
}
|
|
@@ -109,8 +109,6 @@ interface HotUpdaterPlugin<TId extends string = string, TSchema extends ModuleSc
|
|
|
109
109
|
init(context: PluginContext<TSchema>): TInstance;
|
|
110
110
|
/** Read by the CLI only; the server never runs it. */
|
|
111
111
|
readonly cli?: PluginCli<TInstance["api"]>;
|
|
112
|
-
/** Only core modules carry a kind. */
|
|
113
|
-
readonly kind?: "Core is built in; it is not a plugin";
|
|
114
112
|
}
|
|
115
113
|
/** Declares a plugin; Hot Updater's own plugins and third-party ones use the same contract. */
|
|
116
114
|
declare const definePlugin: <const TId extends string, const TSchema extends ModuleSchema, TInstance extends PluginInstance, const TProvides extends PluginProvides = {}>(plugin: {
|
|
@@ -109,8 +109,6 @@ interface HotUpdaterPlugin<TId extends string = string, TSchema extends ModuleSc
|
|
|
109
109
|
init(context: PluginContext<TSchema>): TInstance;
|
|
110
110
|
/** Read by the CLI only; the server never runs it. */
|
|
111
111
|
readonly cli?: PluginCli<TInstance["api"]>;
|
|
112
|
-
/** Only core modules carry a kind. */
|
|
113
|
-
readonly kind?: "Core is built in; it is not a plugin";
|
|
114
112
|
}
|
|
115
113
|
/** Declares a plugin; Hot Updater's own plugins and third-party ones use the same contract. */
|
|
116
114
|
declare const definePlugin: <const TId extends string, const TSchema extends ModuleSchema, TInstance extends PluginInstance, const TProvides extends PluginProvides = {}>(plugin: {
|
|
@@ -32,7 +32,7 @@ interface ReleaseRow {
|
|
|
32
32
|
readonly scope_key: string;
|
|
33
33
|
readonly channel_id: string;
|
|
34
34
|
readonly platform: Platform;
|
|
35
|
-
readonly kind: "BUNDLE"
|
|
35
|
+
readonly kind: "BUNDLE";
|
|
36
36
|
readonly bundle_id: string | null;
|
|
37
37
|
readonly strategy: "APP_VERSION" | "FINGERPRINT";
|
|
38
38
|
readonly target_app_version: string | null;
|
|
@@ -32,7 +32,7 @@ interface ReleaseRow {
|
|
|
32
32
|
readonly scope_key: string;
|
|
33
33
|
readonly channel_id: string;
|
|
34
34
|
readonly platform: Platform;
|
|
35
|
-
readonly kind: "BUNDLE"
|
|
35
|
+
readonly kind: "BUNDLE";
|
|
36
36
|
readonly bundle_id: string | null;
|
|
37
37
|
readonly strategy: "APP_VERSION" | "FINGERPRINT";
|
|
38
38
|
readonly target_app_version: string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/plugin-core",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.47",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
"es-toolkit": "^1.32.0",
|
|
46
46
|
"mime": "^4.0.4",
|
|
47
47
|
"verkit": "0.4.0",
|
|
48
|
-
"@hot-updater/protocol": "1.0.0-rc.
|
|
48
|
+
"@hot-updater/protocol": "1.0.0-rc.47"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@electric-sql/pglite": "0.4.1",
|
|
52
52
|
"@types/node": "^20",
|
|
53
53
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
54
54
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
55
|
-
"@hot-updater/test-utils": "1.0.0-rc.
|
|
55
|
+
"@hot-updater/test-utils": "1.0.0-rc.47"
|
|
56
56
|
},
|
|
57
57
|
"nx": {
|
|
58
58
|
"implicitDependencies": [
|