@hot-updater/server 1.2.0-rc.49 → 1.2.0-rc.50
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/adapters/drizzle.cjs +8 -4
- package/dist/adapters/drizzle.d.cts +3 -2
- package/dist/adapters/drizzle.d.mts +3 -2
- package/dist/adapters/drizzle.mjs +8 -4
- package/dist/adapters/drizzleExecutor.cjs +4 -2
- package/dist/adapters/drizzleExecutor.mjs +4 -2
- package/dist/adapters/kysely.cjs +3 -2
- package/dist/adapters/kysely.mjs +3 -2
- package/dist/adapters/mongodb.cjs +1 -1
- package/dist/adapters/mongodb.mjs +1 -1
- package/dist/adapters/mongodbAdapter.cjs +15 -3
- package/dist/adapters/mongodbAdapter.mjs +15 -3
- package/dist/adapters/prisma.cjs +9 -13
- package/dist/adapters/prisma.mjs +10 -14
- package/dist/adapters/prismaExecutor.cjs +25 -20
- package/dist/adapters/prismaExecutor.mjs +25 -20
- package/dist/core/api.d.cts +6 -1
- package/dist/core/api.d.mts +6 -1
- package/dist/core/operations.cjs +2 -20
- package/dist/core/operations.mjs +4 -22
- package/dist/core/reads.cjs +35 -3
- package/dist/core/reads.mjs +35 -3
- package/dist/core/releases.cjs +78 -26
- package/dist/core/releases.mjs +79 -29
- package/dist/db/engineDrizzleSchema.cjs +21 -5
- package/dist/db/engineDrizzleSchema.mjs +21 -6
- package/dist/db/enginePrismaSchema.cjs +6 -14
- package/dist/db/enginePrismaSchema.mjs +7 -15
- package/dist/db/releaseCatalog.cjs +13 -4
- package/dist/db/releaseCatalog.mjs +12 -5
- package/dist/handlerAdminRoutes.cjs +48 -8
- package/dist/handlerAdminRoutes.mjs +49 -9
- package/dist/handlerReleaseCatalogRoutes.cjs +43 -27
- package/dist/handlerReleaseCatalogRoutes.mjs +43 -27
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +6 -6
|
@@ -7,8 +7,9 @@ let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
|
7
7
|
/**
|
|
8
8
|
* Hot Updater's database on a Drizzle instance: the storage engine through the
|
|
9
9
|
* shared SQL core, fenced by the schema settings. `db generate` writes the
|
|
10
|
-
* Drizzle schema drizzle-kit applies; `db migrate` then
|
|
11
|
-
*
|
|
10
|
+
* Drizzle schema drizzle-kit applies; `db migrate` then checks the tables,
|
|
11
|
+
* sets the PostgreSQL collations drizzle-kit cannot read back, and writes the
|
|
12
|
+
* settings rows the fence checks.
|
|
12
13
|
*/
|
|
13
14
|
const drizzleAdapter = (config) => {
|
|
14
15
|
const provider = require_sqlProviders.checkSqlProvider("drizzleAdapter", config.provider);
|
|
@@ -26,11 +27,14 @@ const drizzleAdapter = (config) => {
|
|
|
26
27
|
path: "hot-updater-schema.ts"
|
|
27
28
|
};
|
|
28
29
|
}),
|
|
29
|
-
createMigrator: ({ settings } = _hot_updater_plugin_core.coreTarget) => (0, _hot_updater_plugin_core.createSettingsMigrator)({
|
|
30
|
+
createMigrator: ({ schema, settings, ordered } = _hot_updater_plugin_core.coreTarget) => (0, _hot_updater_plugin_core.createSettingsMigrator)({
|
|
30
31
|
adapterName: "drizzle",
|
|
31
32
|
executor,
|
|
33
|
+
schema,
|
|
32
34
|
settings,
|
|
33
|
-
|
|
35
|
+
ordered,
|
|
36
|
+
applyTables: provider === "mysql" ? "`npx drizzle-kit generate` and `npx drizzle-kit migrate`" : "`npx drizzle-kit push`",
|
|
37
|
+
collate: () => provider === "postgresql"
|
|
34
38
|
})
|
|
35
39
|
};
|
|
36
40
|
};
|
|
@@ -10,8 +10,9 @@ interface DrizzleConfig {
|
|
|
10
10
|
/**
|
|
11
11
|
* Hot Updater's database on a Drizzle instance: the storage engine through the
|
|
12
12
|
* shared SQL core, fenced by the schema settings. `db generate` writes the
|
|
13
|
-
* Drizzle schema drizzle-kit applies; `db migrate` then
|
|
14
|
-
*
|
|
13
|
+
* Drizzle schema drizzle-kit applies; `db migrate` then checks the tables,
|
|
14
|
+
* sets the PostgreSQL collations drizzle-kit cannot read back, and writes the
|
|
15
|
+
* settings rows the fence checks.
|
|
15
16
|
*/
|
|
16
17
|
declare const drizzleAdapter: (config: DrizzleConfig) => ToolingDatabase;
|
|
17
18
|
//#endregion
|
|
@@ -10,8 +10,9 @@ interface DrizzleConfig {
|
|
|
10
10
|
/**
|
|
11
11
|
* Hot Updater's database on a Drizzle instance: the storage engine through the
|
|
12
12
|
* shared SQL core, fenced by the schema settings. `db generate` writes the
|
|
13
|
-
* Drizzle schema drizzle-kit applies; `db migrate` then
|
|
14
|
-
*
|
|
13
|
+
* Drizzle schema drizzle-kit applies; `db migrate` then checks the tables,
|
|
14
|
+
* sets the PostgreSQL collations drizzle-kit cannot read back, and writes the
|
|
15
|
+
* settings rows the fence checks.
|
|
15
16
|
*/
|
|
16
17
|
declare const drizzleAdapter: (config: DrizzleConfig) => ToolingDatabase;
|
|
17
18
|
//#endregion
|
|
@@ -6,8 +6,9 @@ import { coreSettings, coreTarget, createEngineDatabase, createSettingsMigrator,
|
|
|
6
6
|
/**
|
|
7
7
|
* Hot Updater's database on a Drizzle instance: the storage engine through the
|
|
8
8
|
* shared SQL core, fenced by the schema settings. `db generate` writes the
|
|
9
|
-
* Drizzle schema drizzle-kit applies; `db migrate` then
|
|
10
|
-
*
|
|
9
|
+
* Drizzle schema drizzle-kit applies; `db migrate` then checks the tables,
|
|
10
|
+
* sets the PostgreSQL collations drizzle-kit cannot read back, and writes the
|
|
11
|
+
* settings rows the fence checks.
|
|
11
12
|
*/
|
|
12
13
|
const drizzleAdapter = (config) => {
|
|
13
14
|
const provider = checkSqlProvider("drizzleAdapter", config.provider);
|
|
@@ -25,11 +26,14 @@ const drizzleAdapter = (config) => {
|
|
|
25
26
|
path: "hot-updater-schema.ts"
|
|
26
27
|
};
|
|
27
28
|
}),
|
|
28
|
-
createMigrator: ({ settings } = coreTarget) => createSettingsMigrator({
|
|
29
|
+
createMigrator: ({ schema, settings, ordered } = coreTarget) => createSettingsMigrator({
|
|
29
30
|
adapterName: "drizzle",
|
|
30
31
|
executor,
|
|
32
|
+
schema,
|
|
31
33
|
settings,
|
|
32
|
-
|
|
34
|
+
ordered,
|
|
35
|
+
applyTables: provider === "mysql" ? "`npx drizzle-kit generate` and `npx drizzle-kit migrate`" : "`npx drizzle-kit push`",
|
|
36
|
+
collate: () => provider === "postgresql"
|
|
33
37
|
})
|
|
34
38
|
};
|
|
35
39
|
};
|
|
@@ -47,14 +47,16 @@ const changesOf = (result) => {
|
|
|
47
47
|
* The SQL core's executor over a Drizzle database, or a function that
|
|
48
48
|
* returns one. Async drivers run Drizzle's transactions; sync SQLite drivers
|
|
49
49
|
* run one statement at a time, beginning transactions with BEGIN IMMEDIATE.
|
|
50
|
-
* First use checks that the driver can run a transaction at all.
|
|
50
|
+
* First use checks that the driver can run a transaction at all. Under
|
|
51
|
+
* `withReplicas`, it runs on `$primary`.
|
|
51
52
|
*/
|
|
52
53
|
const drizzleExecutor = (source, dialect) => {
|
|
53
54
|
const isSync = (runner) => dialect === "sqlite" && runner.resultKind === "sync";
|
|
54
55
|
let ready;
|
|
55
56
|
const resolve = () => {
|
|
56
57
|
ready ??= (async () => {
|
|
57
|
-
const
|
|
58
|
+
const database = await (typeof source === "function" ? source() : source);
|
|
59
|
+
const runner = database.$primary ?? database;
|
|
58
60
|
if (isSync(runner)) return runner;
|
|
59
61
|
let started = false;
|
|
60
62
|
try {
|
|
@@ -47,14 +47,16 @@ const changesOf = (result) => {
|
|
|
47
47
|
* The SQL core's executor over a Drizzle database, or a function that
|
|
48
48
|
* returns one. Async drivers run Drizzle's transactions; sync SQLite drivers
|
|
49
49
|
* run one statement at a time, beginning transactions with BEGIN IMMEDIATE.
|
|
50
|
-
* First use checks that the driver can run a transaction at all.
|
|
50
|
+
* First use checks that the driver can run a transaction at all. Under
|
|
51
|
+
* `withReplicas`, it runs on `$primary`.
|
|
51
52
|
*/
|
|
52
53
|
const drizzleExecutor = (source, dialect) => {
|
|
53
54
|
const isSync = (runner) => dialect === "sqlite" && runner.resultKind === "sync";
|
|
54
55
|
let ready;
|
|
55
56
|
const resolve = () => {
|
|
56
57
|
ready ??= (async () => {
|
|
57
|
-
const
|
|
58
|
+
const database = await (typeof source === "function" ? source() : source);
|
|
59
|
+
const runner = database.$primary ?? database;
|
|
58
60
|
if (isSync(runner)) return runner;
|
|
59
61
|
let started = false;
|
|
60
62
|
try {
|
package/dist/adapters/kysely.cjs
CHANGED
|
@@ -17,11 +17,12 @@ const kyselyAdapter = (config) => {
|
|
|
17
17
|
adapter: (0, _hot_updater_plugin_core.createSqlAdapter)({ executor })
|
|
18
18
|
}),
|
|
19
19
|
provider,
|
|
20
|
-
createMigrator: ({ schema, settings } = _hot_updater_plugin_core.coreTarget) => (0, _hot_updater_plugin_core.createEngineSqlMigrator)({
|
|
20
|
+
createMigrator: ({ schema, settings, ordered } = _hot_updater_plugin_core.coreTarget) => (0, _hot_updater_plugin_core.createEngineSqlMigrator)({
|
|
21
21
|
adapterName: "kysely",
|
|
22
22
|
executor,
|
|
23
23
|
schema,
|
|
24
|
-
settings
|
|
24
|
+
settings,
|
|
25
|
+
ordered
|
|
25
26
|
})
|
|
26
27
|
};
|
|
27
28
|
};
|
package/dist/adapters/kysely.mjs
CHANGED
|
@@ -16,11 +16,12 @@ const kyselyAdapter = (config) => {
|
|
|
16
16
|
adapter: createSqlAdapter({ executor })
|
|
17
17
|
}),
|
|
18
18
|
provider,
|
|
19
|
-
createMigrator: ({ schema, settings } = coreTarget) => createEngineSqlMigrator({
|
|
19
|
+
createMigrator: ({ schema, settings, ordered } = coreTarget) => createEngineSqlMigrator({
|
|
20
20
|
adapterName: "kysely",
|
|
21
21
|
executor,
|
|
22
22
|
schema,
|
|
23
|
-
settings
|
|
23
|
+
settings,
|
|
24
|
+
ordered
|
|
24
25
|
})
|
|
25
26
|
};
|
|
26
27
|
};
|
|
@@ -4,7 +4,7 @@ let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
|
4
4
|
//#region src/adapters/mongodb.ts
|
|
5
5
|
/** Settings rows by their `key` field: the engine's rows and a v0 database's alike. */
|
|
6
6
|
const readSettings = (client) => async () => {
|
|
7
|
-
const rows = await client.db().collection(_hot_updater_plugin_core.SETTINGS_TABLE.name).find({ key: { $type: "string" } }).toArray();
|
|
7
|
+
const rows = await client.db().collection(_hot_updater_plugin_core.SETTINGS_TABLE.name).find({ key: { $type: "string" } }, { readPreference: "primary" }).toArray();
|
|
8
8
|
return new Map(rows.map((row) => [String(row.key), row.value]));
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
@@ -3,7 +3,7 @@ import { SETTINGS_TABLE, createEngineDatabase } from "@hot-updater/plugin-core";
|
|
|
3
3
|
//#region src/adapters/mongodb.ts
|
|
4
4
|
/** Settings rows by their `key` field: the engine's rows and a v0 database's alike. */
|
|
5
5
|
const readSettings = (client) => async () => {
|
|
6
|
-
const rows = await client.db().collection(SETTINGS_TABLE.name).find({ key: { $type: "string" } }).toArray();
|
|
6
|
+
const rows = await client.db().collection(SETTINGS_TABLE.name).find({ key: { $type: "string" } }, { readPreference: "primary" }).toArray();
|
|
7
7
|
return new Map(rows.map((row) => [String(row.key), row.value]));
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
@@ -51,6 +51,11 @@ const indexDescription = (table, index) => {
|
|
|
51
51
|
};
|
|
52
52
|
const mongoError = (error) => error instanceof mongodb.MongoError ? error : void 0;
|
|
53
53
|
/**
|
|
54
|
+
* Every read goes to the primary, whatever the client's read preference: a
|
|
55
|
+
* secondary can lag, and `get` and `query` promise every committed write.
|
|
56
|
+
*/
|
|
57
|
+
const PRIMARY = { readPreference: "primary" };
|
|
58
|
+
/**
|
|
54
59
|
* The storage engine's adapter over MongoDB: one collection per table, the
|
|
55
60
|
* key as `_id`, and indexes as declared, with multi-valued fields as multikey
|
|
56
61
|
* indexes. A write runs in one transaction. Guards are conditional updates,
|
|
@@ -115,7 +120,7 @@ const createMongoAdapter = (options) => {
|
|
|
115
120
|
async get(table, keys) {
|
|
116
121
|
if (keys.length === 0) return [];
|
|
117
122
|
const ids = keys.map((key) => idOf(table, key));
|
|
118
|
-
const documents = await collection(table).find(byId({ $in: ids })).toArray();
|
|
123
|
+
const documents = await collection(table).find(byId({ $in: ids }), PRIMARY).toArray();
|
|
119
124
|
const found = new Map(documents.map((document) => [JSON.stringify(document._id), document]));
|
|
120
125
|
return ids.map((id) => {
|
|
121
126
|
const document = found.get(JSON.stringify(id));
|
|
@@ -131,6 +136,7 @@ const createMongoAdapter = (options) => {
|
|
|
131
136
|
...Object.fromEntries(index.eq.map((column, at) => [column, request.eq[at]])),
|
|
132
137
|
...bounds.length > 0 && { $and: bounds }
|
|
133
138
|
}, {
|
|
139
|
+
...PRIMARY,
|
|
134
140
|
sort: Object.fromEntries(columns.map((column) => [column, direction])),
|
|
135
141
|
limit: request.limit,
|
|
136
142
|
...options.batchSize && { batchSize: options.batchSize }
|
|
@@ -181,8 +187,14 @@ const createMongoAdapter = (options) => {
|
|
|
181
187
|
if (mongoError(error)?.code !== 48) throw error;
|
|
182
188
|
});
|
|
183
189
|
if (table.retention) await collection(table).createIndexes([TTL]);
|
|
184
|
-
|
|
185
|
-
|
|
190
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
191
|
+
for (const index of table.indexes) {
|
|
192
|
+
const description = indexDescription(table, index);
|
|
193
|
+
const keys = JSON.stringify([description.key, description.unique]);
|
|
194
|
+
if (!indexes.has(keys)) indexes.set(keys, description);
|
|
195
|
+
}
|
|
196
|
+
if (indexes.size === 0) continue;
|
|
197
|
+
await collection(table).createIndexes([...indexes.values()]);
|
|
186
198
|
}
|
|
187
199
|
} }
|
|
188
200
|
};
|
|
@@ -51,6 +51,11 @@ const indexDescription = (table, index) => {
|
|
|
51
51
|
};
|
|
52
52
|
const mongoError = (error) => error instanceof MongoError ? error : void 0;
|
|
53
53
|
/**
|
|
54
|
+
* Every read goes to the primary, whatever the client's read preference: a
|
|
55
|
+
* secondary can lag, and `get` and `query` promise every committed write.
|
|
56
|
+
*/
|
|
57
|
+
const PRIMARY = { readPreference: "primary" };
|
|
58
|
+
/**
|
|
54
59
|
* The storage engine's adapter over MongoDB: one collection per table, the
|
|
55
60
|
* key as `_id`, and indexes as declared, with multi-valued fields as multikey
|
|
56
61
|
* indexes. A write runs in one transaction. Guards are conditional updates,
|
|
@@ -115,7 +120,7 @@ const createMongoAdapter = (options) => {
|
|
|
115
120
|
async get(table, keys) {
|
|
116
121
|
if (keys.length === 0) return [];
|
|
117
122
|
const ids = keys.map((key) => idOf(table, key));
|
|
118
|
-
const documents = await collection(table).find(byId({ $in: ids })).toArray();
|
|
123
|
+
const documents = await collection(table).find(byId({ $in: ids }), PRIMARY).toArray();
|
|
119
124
|
const found = new Map(documents.map((document) => [JSON.stringify(document._id), document]));
|
|
120
125
|
return ids.map((id) => {
|
|
121
126
|
const document = found.get(JSON.stringify(id));
|
|
@@ -131,6 +136,7 @@ const createMongoAdapter = (options) => {
|
|
|
131
136
|
...Object.fromEntries(index.eq.map((column, at) => [column, request.eq[at]])),
|
|
132
137
|
...bounds.length > 0 && { $and: bounds }
|
|
133
138
|
}, {
|
|
139
|
+
...PRIMARY,
|
|
134
140
|
sort: Object.fromEntries(columns.map((column) => [column, direction])),
|
|
135
141
|
limit: request.limit,
|
|
136
142
|
...options.batchSize && { batchSize: options.batchSize }
|
|
@@ -181,8 +187,14 @@ const createMongoAdapter = (options) => {
|
|
|
181
187
|
if (mongoError(error)?.code !== 48) throw error;
|
|
182
188
|
});
|
|
183
189
|
if (table.retention) await collection(table).createIndexes([TTL]);
|
|
184
|
-
|
|
185
|
-
|
|
190
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
191
|
+
for (const index of table.indexes) {
|
|
192
|
+
const description = indexDescription(table, index);
|
|
193
|
+
const keys = JSON.stringify([description.key, description.unique]);
|
|
194
|
+
if (!indexes.has(keys)) indexes.set(keys, description);
|
|
195
|
+
}
|
|
196
|
+
if (indexes.size === 0) continue;
|
|
197
|
+
await collection(table).createIndexes([...indexes.values()]);
|
|
186
198
|
}
|
|
187
199
|
} }
|
|
188
200
|
};
|
package/dist/adapters/prisma.cjs
CHANGED
|
@@ -26,19 +26,15 @@ const prismaAdapter = (config) => {
|
|
|
26
26
|
path: "prisma/schema.prisma"
|
|
27
27
|
};
|
|
28
28
|
}),
|
|
29
|
-
createMigrator: ({ schema, settings } = _hot_updater_plugin_core.coreTarget) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
statements: collations
|
|
39
|
-
} }
|
|
40
|
-
});
|
|
41
|
-
}
|
|
29
|
+
createMigrator: ({ schema, settings, ordered } = _hot_updater_plugin_core.coreTarget) => (0, _hot_updater_plugin_core.createSettingsMigrator)({
|
|
30
|
+
adapterName: "prisma",
|
|
31
|
+
executor,
|
|
32
|
+
schema,
|
|
33
|
+
settings,
|
|
34
|
+
ordered,
|
|
35
|
+
applyTables: "`npx prisma db push`",
|
|
36
|
+
collate: (column) => require_enginePrismaSchema.prismaCollates(provider, column)
|
|
37
|
+
})
|
|
42
38
|
};
|
|
43
39
|
};
|
|
44
40
|
//#endregion
|
package/dist/adapters/prisma.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { checkSqlProvider } from "./sqlProviders.mjs";
|
|
2
|
-
import { generatePrismaEngineSchema,
|
|
2
|
+
import { generatePrismaEngineSchema, prismaCollates } from "../db/enginePrismaSchema.mjs";
|
|
3
3
|
import { prismaExecutor } from "./prismaExecutor.mjs";
|
|
4
4
|
import { coreSettings, coreTarget, createEngineDatabase, createSettingsMigrator, createSqlAdapter } from "@hot-updater/plugin-core";
|
|
5
5
|
//#region src/adapters/prisma.ts
|
|
@@ -25,19 +25,15 @@ const prismaAdapter = (config) => {
|
|
|
25
25
|
path: "prisma/schema.prisma"
|
|
26
26
|
};
|
|
27
27
|
}),
|
|
28
|
-
createMigrator: ({ schema, settings } = coreTarget) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
statements: collations
|
|
38
|
-
} }
|
|
39
|
-
});
|
|
40
|
-
}
|
|
28
|
+
createMigrator: ({ schema, settings, ordered } = coreTarget) => createSettingsMigrator({
|
|
29
|
+
adapterName: "prisma",
|
|
30
|
+
executor,
|
|
31
|
+
schema,
|
|
32
|
+
settings,
|
|
33
|
+
ordered,
|
|
34
|
+
applyTables: "`npx prisma db push`",
|
|
35
|
+
collate: (column) => prismaCollates(provider, column)
|
|
36
|
+
})
|
|
41
37
|
};
|
|
42
38
|
};
|
|
43
39
|
//#endregion
|
|
@@ -36,28 +36,33 @@ const writeLock = (dialect) => `UPDATE ${(0, _hot_updater_plugin_core.quoteSql)(
|
|
|
36
36
|
/**
|
|
37
37
|
* The SQL core's executor over a Prisma client, through raw queries and
|
|
38
38
|
* interactive transactions. A SQLite transaction takes the write lock with
|
|
39
|
-
* its first statement, as BEGIN IMMEDIATE would.
|
|
39
|
+
* its first statement, as BEGIN IMMEDIATE would. Under a read-replica
|
|
40
|
+
* extension, every statement runs on `$primary()`: the engine's reads must
|
|
41
|
+
* see every committed write, which a lagging replica may not have.
|
|
40
42
|
*/
|
|
41
|
-
const prismaExecutor = (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
const prismaExecutor = (root, dialect) => {
|
|
44
|
+
const client = typeof root.$primary === "function" ? root.$primary() : root;
|
|
45
|
+
return {
|
|
46
|
+
dialect,
|
|
47
|
+
...over(dialect, client),
|
|
48
|
+
async transaction(fn) {
|
|
49
|
+
try {
|
|
50
|
+
return await client.$transaction(async (tx) => {
|
|
51
|
+
const connection = over(dialect, tx);
|
|
52
|
+
if (dialect === "sqlite") await connection.execute({
|
|
53
|
+
sql: writeLock(dialect),
|
|
54
|
+
params: []
|
|
55
|
+
});
|
|
56
|
+
return fn(connection);
|
|
57
|
+
}, {
|
|
58
|
+
maxWait: 1e4,
|
|
59
|
+
timeout: 3e4
|
|
51
60
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
timeout: 3e4
|
|
56
|
-
});
|
|
57
|
-
} catch (error) {
|
|
58
|
-
throw withDatabaseCode(dialect, error);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw withDatabaseCode(dialect, error);
|
|
63
|
+
}
|
|
59
64
|
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
62
67
|
//#endregion
|
|
63
68
|
exports.prismaExecutor = prismaExecutor;
|
|
@@ -36,28 +36,33 @@ const writeLock = (dialect) => `UPDATE ${quoteSql(dialect, SETTINGS_TABLE.name)}
|
|
|
36
36
|
/**
|
|
37
37
|
* The SQL core's executor over a Prisma client, through raw queries and
|
|
38
38
|
* interactive transactions. A SQLite transaction takes the write lock with
|
|
39
|
-
* its first statement, as BEGIN IMMEDIATE would.
|
|
39
|
+
* its first statement, as BEGIN IMMEDIATE would. Under a read-replica
|
|
40
|
+
* extension, every statement runs on `$primary()`: the engine's reads must
|
|
41
|
+
* see every committed write, which a lagging replica may not have.
|
|
40
42
|
*/
|
|
41
|
-
const prismaExecutor = (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
const prismaExecutor = (root, dialect) => {
|
|
44
|
+
const client = typeof root.$primary === "function" ? root.$primary() : root;
|
|
45
|
+
return {
|
|
46
|
+
dialect,
|
|
47
|
+
...over(dialect, client),
|
|
48
|
+
async transaction(fn) {
|
|
49
|
+
try {
|
|
50
|
+
return await client.$transaction(async (tx) => {
|
|
51
|
+
const connection = over(dialect, tx);
|
|
52
|
+
if (dialect === "sqlite") await connection.execute({
|
|
53
|
+
sql: writeLock(dialect),
|
|
54
|
+
params: []
|
|
55
|
+
});
|
|
56
|
+
return fn(connection);
|
|
57
|
+
}, {
|
|
58
|
+
maxWait: 1e4,
|
|
59
|
+
timeout: 3e4
|
|
51
60
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
timeout: 3e4
|
|
56
|
-
});
|
|
57
|
-
} catch (error) {
|
|
58
|
-
throw withDatabaseCode(dialect, error);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw withDatabaseCode(dialect, error);
|
|
63
|
+
}
|
|
59
64
|
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
62
67
|
//#endregion
|
|
63
68
|
export { prismaExecutor };
|
package/dist/core/api.d.cts
CHANGED
|
@@ -94,8 +94,13 @@ declare const createCoreApi: (db: CoreDatabase, storage: CoreStorage, options?:
|
|
|
94
94
|
latestReleaseId(scopeKey: string): Promise<string | null>;
|
|
95
95
|
getReleaseCatalogRow(scopeKey: string): Promise<import("@hot-updater/plugin-core").ReleaseCatalogRow | null>;
|
|
96
96
|
listReleaseCatalogs(input: import("@hot-updater/plugin-core").KeysetInput): Promise<import("@hot-updater/plugin-core").ReleaseCatalogRow[]>;
|
|
97
|
-
listChannels(): Promise<import("@hot-updater/plugin-core").ChannelRow[]>;
|
|
97
|
+
listChannels(input?: import("@hot-updater/plugin-core").KeysetInput): Promise<import("@hot-updater/plugin-core").ChannelRow[]>;
|
|
98
|
+
getChannels(ids: readonly string[]): Promise<import("@hot-updater/plugin-core").ChannelRow[]>;
|
|
98
99
|
findChannelByName(name: string): Promise<import("@hot-updater/plugin-core").ChannelRow | null>;
|
|
100
|
+
listReleaseScopeKeys: (input: {
|
|
101
|
+
readonly after?: string;
|
|
102
|
+
readonly limit: number;
|
|
103
|
+
}) => Promise<string[]>;
|
|
99
104
|
};
|
|
100
105
|
type CoreApi = ReturnType<typeof createCoreApi>;
|
|
101
106
|
//#endregion
|
package/dist/core/api.d.mts
CHANGED
|
@@ -94,8 +94,13 @@ declare const createCoreApi: (db: CoreDatabase, storage: CoreStorage, options?:
|
|
|
94
94
|
latestReleaseId(scopeKey: string): Promise<string | null>;
|
|
95
95
|
getReleaseCatalogRow(scopeKey: string): Promise<import("@hot-updater/plugin-core").ReleaseCatalogRow | null>;
|
|
96
96
|
listReleaseCatalogs(input: import("@hot-updater/plugin-core").KeysetInput): Promise<import("@hot-updater/plugin-core").ReleaseCatalogRow[]>;
|
|
97
|
-
listChannels(): Promise<import("@hot-updater/plugin-core").ChannelRow[]>;
|
|
97
|
+
listChannels(input?: import("@hot-updater/plugin-core").KeysetInput): Promise<import("@hot-updater/plugin-core").ChannelRow[]>;
|
|
98
|
+
getChannels(ids: readonly string[]): Promise<import("@hot-updater/plugin-core").ChannelRow[]>;
|
|
98
99
|
findChannelByName(name: string): Promise<import("@hot-updater/plugin-core").ChannelRow | null>;
|
|
100
|
+
listReleaseScopeKeys: (input: {
|
|
101
|
+
readonly after?: string;
|
|
102
|
+
readonly limit: number;
|
|
103
|
+
}) => Promise<string[]>;
|
|
99
104
|
};
|
|
100
105
|
type CoreApi = ReturnType<typeof createCoreApi>;
|
|
101
106
|
//#endregion
|
package/dist/core/operations.cjs
CHANGED
|
@@ -93,14 +93,7 @@ const mutationResult = ({ catalog, release }) => ({
|
|
|
93
93
|
const catalogScope = async (tx, scopeKey) => {
|
|
94
94
|
const row = await tx.findOne("release_catalogs", { scope_key: scopeKey });
|
|
95
95
|
if (row === null) throw new Error(`Release catalog "${scopeKey}" was not found.`);
|
|
96
|
-
return
|
|
97
|
-
channelId: row.channel_id,
|
|
98
|
-
channelName: (0, _hot_updater_protocol.decodeChannelKey)(row.channel_key),
|
|
99
|
-
fingerprintHash: row.fingerprint_hash,
|
|
100
|
-
platform: row.platform,
|
|
101
|
-
scopeKey: row.scope_key,
|
|
102
|
-
strategy: row.strategy
|
|
103
|
-
};
|
|
96
|
+
return require_releases.catalogRowScope(require_reads.toCatalogRow(row));
|
|
104
97
|
};
|
|
105
98
|
/**
|
|
106
99
|
* Core's typed writes: each runs in one engine transaction rooted at the
|
|
@@ -308,18 +301,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
308
301
|
};
|
|
309
302
|
});
|
|
310
303
|
},
|
|
311
|
-
preflightReleaseCatalogRebuild: (scopeKey) =>
|
|
312
|
-
const updatedAtMs = now();
|
|
313
|
-
return dryRun(db, async (tx) => {
|
|
314
|
-
const rebuilt = await require_releases.rebuildScope(tx, await catalogScope(tx, scopeKey), updatedAtMs);
|
|
315
|
-
return {
|
|
316
|
-
changed: rebuilt.changed,
|
|
317
|
-
currentCatalog: rebuilt.current,
|
|
318
|
-
diagnostics: rebuilt.diagnostics,
|
|
319
|
-
projectedCatalog: rebuilt.catalog
|
|
320
|
-
};
|
|
321
|
-
});
|
|
322
|
-
},
|
|
304
|
+
preflightReleaseCatalogRebuild: (scopeKey) => require_releases.preflightRebuild(db, scopeKey, now()),
|
|
323
305
|
ensureChannel,
|
|
324
306
|
deleteChannel: (id) => require_writes.deleteChannel(db, id),
|
|
325
307
|
updateBundle: (id, update) => db.transaction(async (tx) => {
|
package/dist/core/operations.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { toBundleRow, toReleaseRow } from "./reads.mjs";
|
|
1
|
+
import { toBundleRow, toCatalogRow, toReleaseRow } from "./reads.mjs";
|
|
2
2
|
import { deleteBundle, deleteChannel, insertChannel, replaceBundlePatches, updateBundle } from "./writes.mjs";
|
|
3
3
|
import { isBuiltInBundle, refuseSandboxPatchBase } from "./nativeBuilds.mjs";
|
|
4
|
-
import { changeRelease, changeReleases, readCatalog, rebuildScope } from "./releases.mjs";
|
|
4
|
+
import { catalogRowScope, changeRelease, changeReleases, preflightRebuild, readCatalog, rebuildScope } from "./releases.mjs";
|
|
5
5
|
import { DatabaseBundleNotFoundError, DatabaseConstraintError, DatabaseRowReferencedError, ReleaseCatalogMutationError, ReleaseManagementError, bundleToPatchRows, bundleToRow, createUUIDv7After, isUUIDv7, rowToBundle } from "@hot-updater/plugin-core";
|
|
6
6
|
import { createReleaseCatalogScopeKey, decodeChannelKey, encodeChannelKey } from "@hot-updater/protocol";
|
|
7
7
|
//#region src/core/operations.ts
|
|
@@ -93,14 +93,7 @@ const mutationResult = ({ catalog, release }) => ({
|
|
|
93
93
|
const catalogScope = async (tx, scopeKey) => {
|
|
94
94
|
const row = await tx.findOne("release_catalogs", { scope_key: scopeKey });
|
|
95
95
|
if (row === null) throw new Error(`Release catalog "${scopeKey}" was not found.`);
|
|
96
|
-
return
|
|
97
|
-
channelId: row.channel_id,
|
|
98
|
-
channelName: decodeChannelKey(row.channel_key),
|
|
99
|
-
fingerprintHash: row.fingerprint_hash,
|
|
100
|
-
platform: row.platform,
|
|
101
|
-
scopeKey: row.scope_key,
|
|
102
|
-
strategy: row.strategy
|
|
103
|
-
};
|
|
96
|
+
return catalogRowScope(toCatalogRow(row));
|
|
104
97
|
};
|
|
105
98
|
/**
|
|
106
99
|
* Core's typed writes: each runs in one engine transaction rooted at the
|
|
@@ -308,18 +301,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
308
301
|
};
|
|
309
302
|
});
|
|
310
303
|
},
|
|
311
|
-
preflightReleaseCatalogRebuild: (scopeKey) =>
|
|
312
|
-
const updatedAtMs = now();
|
|
313
|
-
return dryRun(db, async (tx) => {
|
|
314
|
-
const rebuilt = await rebuildScope(tx, await catalogScope(tx, scopeKey), updatedAtMs);
|
|
315
|
-
return {
|
|
316
|
-
changed: rebuilt.changed,
|
|
317
|
-
currentCatalog: rebuilt.current,
|
|
318
|
-
diagnostics: rebuilt.diagnostics,
|
|
319
|
-
projectedCatalog: rebuilt.catalog
|
|
320
|
-
};
|
|
321
|
-
});
|
|
322
|
-
},
|
|
304
|
+
preflightReleaseCatalogRebuild: (scopeKey) => preflightRebuild(db, scopeKey, now()),
|
|
323
305
|
ensureChannel,
|
|
324
306
|
deleteChannel: (id) => deleteChannel(db, id),
|
|
325
307
|
updateBundle: (id, update) => db.transaction(async (tx) => {
|
package/dist/core/reads.cjs
CHANGED
|
@@ -83,7 +83,7 @@ const after = (input) => {
|
|
|
83
83
|
};
|
|
84
84
|
return Object.keys(range).length === 0 ? {} : { range };
|
|
85
85
|
};
|
|
86
|
-
/** Core's reads, each through one declared index or key
|
|
86
|
+
/** Core's reads, each through one declared index or key; plugins get `CoreReads`. */
|
|
87
87
|
const createCoreReads = (db, storage) => {
|
|
88
88
|
/** A bundle row's patches, exactly as many as its reference counter holds. */
|
|
89
89
|
const detail = async (row) => {
|
|
@@ -271,8 +271,35 @@ const createCoreReads = (db, storage) => {
|
|
|
271
271
|
...after(input)
|
|
272
272
|
})).rows.map(toCatalogRow);
|
|
273
273
|
},
|
|
274
|
-
/**
|
|
275
|
-
|
|
274
|
+
/**
|
|
275
|
+
* Up to `limit` scope keys that have releases, ascending after `after`:
|
|
276
|
+
* one limit-1 seek of the `scopes` index past each scope, so the reads
|
|
277
|
+
* grow with the scopes, not with their releases.
|
|
278
|
+
*/
|
|
279
|
+
async listReleaseScopeKeys(input) {
|
|
280
|
+
const scopeKeys = [];
|
|
281
|
+
for (let last = input.after ?? ""; scopeKeys.length < input.limit;) {
|
|
282
|
+
const { rows } = await db.findMany("releases", {
|
|
283
|
+
index: "scopes",
|
|
284
|
+
where: {},
|
|
285
|
+
limit: 1,
|
|
286
|
+
range: { gt: last }
|
|
287
|
+
});
|
|
288
|
+
if (rows[0] === void 0) break;
|
|
289
|
+
last = rows[0].scope_key;
|
|
290
|
+
scopeKeys.push(last);
|
|
291
|
+
}
|
|
292
|
+
return scopeKeys;
|
|
293
|
+
},
|
|
294
|
+
/** Every channel by name; with `input`, one keyset page of them. */
|
|
295
|
+
async listChannels(input) {
|
|
296
|
+
if (input !== void 0) return (await db.findMany("channels", {
|
|
297
|
+
index: "all",
|
|
298
|
+
where: {},
|
|
299
|
+
order: input.order ?? "asc",
|
|
300
|
+
limit: input.limit,
|
|
301
|
+
...after(input)
|
|
302
|
+
})).rows.map(toChannelRow);
|
|
276
303
|
return (await drain((page) => db.findMany("channels", {
|
|
277
304
|
index: "all",
|
|
278
305
|
where: {},
|
|
@@ -280,6 +307,11 @@ const createCoreReads = (db, storage) => {
|
|
|
280
307
|
...page
|
|
281
308
|
}))).map(toChannelRow);
|
|
282
309
|
},
|
|
310
|
+
async getChannels(ids) {
|
|
311
|
+
const unique = [...new Set(ids)];
|
|
312
|
+
if (unique.length === 0) return [];
|
|
313
|
+
return (await db.findByKeys("channels", unique.map((id) => ({ id })))).flatMap((row) => row ? [toChannelRow(row)] : []);
|
|
314
|
+
},
|
|
283
315
|
async findChannelByName(name) {
|
|
284
316
|
const row = await db.findOne("channels", { name });
|
|
285
317
|
return row === null ? null : toChannelRow(row);
|