@hot-updater/plugin-core 1.2.0-rc.42 → 1.2.0-rc.44
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/coreApi.d.cts +16 -1
- package/dist/coreApi.d.mts +16 -1
- package/dist/engine/core/schema.cjs +4 -0
- package/dist/engine/core/schema.d.cts +4 -0
- package/dist/engine/core/schema.d.mts +4 -0
- package/dist/engine/core/schema.mjs +4 -0
- package/dist/engine/database/sql/sqlAdapter.cjs +9 -4
- package/dist/engine/database/sql/sqlAdapter.mjs +9 -4
- package/dist/engine/database/sql/sqlSchema.cjs +18 -4
- package/dist/engine/database/sql/sqlSchema.mjs +18 -4
- package/package.json +2 -2
package/dist/coreApi.d.cts
CHANGED
|
@@ -254,13 +254,28 @@ interface HotUpdaterCoreApi {
|
|
|
254
254
|
* builds of that key. With `scope.sandbox`, sandbox builds on any channel;
|
|
255
255
|
* without it, never one. A sandbox build's built-in bundle is no patch
|
|
256
256
|
* base, so with `builtInOlderThan` a sandbox scope answers null without a
|
|
257
|
-
* read.
|
|
257
|
+
* read. With `artifactKind`, only a build of that kind, with any other
|
|
258
|
+
* option. Alone, it reads the scope's builds of that kind, so a newer
|
|
259
|
+
* `.app` doesn't hide the scope's `.ipa`: one read, and when that finds
|
|
260
|
+
* none, a second of the scope's newest, kept only when it is of the kind.
|
|
261
|
+
* A key-value store holds no index copy of this for a row written before
|
|
262
|
+
* it, so such a row is found only while it is its scope's newest.
|
|
258
263
|
*/
|
|
259
264
|
findNativeBuild(scope: NativeBuildScope, options?: {
|
|
260
265
|
readonly buildKey?: string;
|
|
261
266
|
readonly storeBuild?: true;
|
|
262
267
|
readonly builtInOlderThan?: string;
|
|
268
|
+
readonly artifactKind?: NativeBuildArtifactKind;
|
|
263
269
|
}): Promise<NativeBuildRow | null>;
|
|
270
|
+
/**
|
|
271
|
+
* The newest build of the other install target of an iOS sandbox build's
|
|
272
|
+
* native code: its Simulator `.app` for a direct-install `.ipa`, or the
|
|
273
|
+
* reverse, of the same app ID, URL scheme and fingerprint or app version,
|
|
274
|
+
* on any channel. Null, with no read, for any other build, and for a store
|
|
275
|
+
* or store-marked build on either side. One read. The Console's build page
|
|
276
|
+
* offers it beside its install.
|
|
277
|
+
*/
|
|
278
|
+
findNativeBuildSibling(build: NativeBuildRow): Promise<NativeBuildRow | null>;
|
|
264
279
|
/**
|
|
265
280
|
* One page of native builds, by ID: oldest or newest first. With
|
|
266
281
|
* `channelId`, only the builds that embed that channel, also one read.
|
package/dist/coreApi.d.mts
CHANGED
|
@@ -254,13 +254,28 @@ interface HotUpdaterCoreApi {
|
|
|
254
254
|
* builds of that key. With `scope.sandbox`, sandbox builds on any channel;
|
|
255
255
|
* without it, never one. A sandbox build's built-in bundle is no patch
|
|
256
256
|
* base, so with `builtInOlderThan` a sandbox scope answers null without a
|
|
257
|
-
* read.
|
|
257
|
+
* read. With `artifactKind`, only a build of that kind, with any other
|
|
258
|
+
* option. Alone, it reads the scope's builds of that kind, so a newer
|
|
259
|
+
* `.app` doesn't hide the scope's `.ipa`: one read, and when that finds
|
|
260
|
+
* none, a second of the scope's newest, kept only when it is of the kind.
|
|
261
|
+
* A key-value store holds no index copy of this for a row written before
|
|
262
|
+
* it, so such a row is found only while it is its scope's newest.
|
|
258
263
|
*/
|
|
259
264
|
findNativeBuild(scope: NativeBuildScope, options?: {
|
|
260
265
|
readonly buildKey?: string;
|
|
261
266
|
readonly storeBuild?: true;
|
|
262
267
|
readonly builtInOlderThan?: string;
|
|
268
|
+
readonly artifactKind?: NativeBuildArtifactKind;
|
|
263
269
|
}): Promise<NativeBuildRow | null>;
|
|
270
|
+
/**
|
|
271
|
+
* The newest build of the other install target of an iOS sandbox build's
|
|
272
|
+
* native code: its Simulator `.app` for a direct-install `.ipa`, or the
|
|
273
|
+
* reverse, of the same app ID, URL scheme and fingerprint or app version,
|
|
274
|
+
* on any channel. Null, with no read, for any other build, and for a store
|
|
275
|
+
* or store-marked build on either side. One read. The Console's build page
|
|
276
|
+
* offers it beside its install.
|
|
277
|
+
*/
|
|
278
|
+
findNativeBuildSibling(build: NativeBuildRow): Promise<NativeBuildRow | null>;
|
|
264
279
|
/**
|
|
265
280
|
* One page of native builds, by ID: oldest or newest first. With
|
|
266
281
|
* `channelId`, only the builds that embed that channel, also one read.
|
|
@@ -417,6 +417,10 @@ declare const coreSchema: {
|
|
|
417
417
|
readonly eq: readonly ["scope_key", "build_key"];
|
|
418
418
|
readonly sort: readonly ["id"];
|
|
419
419
|
};
|
|
420
|
+
readonly byScopeKind: {
|
|
421
|
+
readonly eq: readonly ["scope_key", "artifact_kind"];
|
|
422
|
+
readonly sort: readonly ["id"];
|
|
423
|
+
};
|
|
420
424
|
readonly byStoreBuild: {
|
|
421
425
|
readonly eq: readonly ["store_build_scope_key"];
|
|
422
426
|
readonly sort: readonly [];
|
|
@@ -417,6 +417,10 @@ declare const coreSchema: {
|
|
|
417
417
|
readonly eq: readonly ["scope_key", "build_key"];
|
|
418
418
|
readonly sort: readonly ["id"];
|
|
419
419
|
};
|
|
420
|
+
readonly byScopeKind: {
|
|
421
|
+
readonly eq: readonly ["scope_key", "artifact_kind"];
|
|
422
|
+
readonly sort: readonly ["id"];
|
|
423
|
+
};
|
|
420
424
|
readonly byStoreBuild: {
|
|
421
425
|
readonly eq: readonly ["store_build_scope_key"];
|
|
422
426
|
readonly sort: readonly [];
|
|
@@ -105,20 +105,25 @@ const createSqlAdapter = ({ executor, tablePrefix = "", maxOps = 1e3, maxParams
|
|
|
105
105
|
const insert = (bind, into, columns, values) => `INSERT INTO ${into} (${columns.map(quote).join(", ")}) ${when ? `SELECT ${values.join(", ")} WHERE ${when(bind)}` : `VALUES (${values.join(", ")})`}`;
|
|
106
106
|
/** Inserts `row` into the op's table, each value bound as its column's type. */
|
|
107
107
|
const insertRow = (bind, row) => insert(bind, name, table.columns.map((column) => column.name), table.columns.map((column) => bind(row[column.name], column)));
|
|
108
|
-
/**
|
|
109
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Replaces the row's entries in the index table of every multi-valued
|
|
110
|
+
* index. A row being inserted has none to replace (`stale` false), and
|
|
111
|
+
* deleting them would read the whole index table: its key ends with the
|
|
112
|
+
* row's key, so no index leads with it.
|
|
113
|
+
*/
|
|
114
|
+
const entries = (key, row, changed, stale = true) => table.indexes.flatMap((index) => {
|
|
110
115
|
const columns = [...index.eq, ...require_adapter.indexOrderColumns(table, index)];
|
|
111
116
|
if (!require_sqlSchema.isMultiIndex(table, index) || changed && !columns.some((column) => changed.includes(column))) return [];
|
|
112
117
|
const into = tableOf(table, index);
|
|
113
118
|
const found = row ? require_values.indexEntries(table, index, row) : [];
|
|
114
119
|
const order = found.length > 0 ? require_values.indexOrderTuple(table, index, row) : [];
|
|
115
|
-
return [sql((bind) => `DELETE FROM ${into} WHERE ${where(bind, key)}`), ...found.map((eq) => sql((bind) => {
|
|
120
|
+
return [...stale ? [sql((bind) => `DELETE FROM ${into} WHERE ${where(bind, key)}`)] : [], ...found.map((eq) => sql((bind) => {
|
|
116
121
|
const values = [...eq, ...order].map((value) => bind(value));
|
|
117
122
|
return insert(bind, into, columns, values);
|
|
118
123
|
}))];
|
|
119
124
|
});
|
|
120
125
|
switch (op.type) {
|
|
121
|
-
case "insert": return [sql((bind) => insertRow(bind, op.row)), ...entries(require_adapter.rowKey(table, op.row), op.row)];
|
|
126
|
+
case "insert": return [sql((bind) => insertRow(bind, op.row)), ...entries(require_adapter.rowKey(table, op.row), op.row, void 0, false)];
|
|
122
127
|
case "patch": return [sql((bind) => {
|
|
123
128
|
const set = Object.entries(op.set).map(([column, value]) => `${quote(column)} = ${bind(value, require_adapter.findPhysicalColumn(table, column))}`);
|
|
124
129
|
return `UPDATE ${name} SET ${[...set, `${version} = ${version} + 1`].join(", ")} WHERE ${where(bind, op.key, op.guard.v)}`;
|
|
@@ -105,20 +105,25 @@ const createSqlAdapter = ({ executor, tablePrefix = "", maxOps = 1e3, maxParams
|
|
|
105
105
|
const insert = (bind, into, columns, values) => `INSERT INTO ${into} (${columns.map(quote).join(", ")}) ${when ? `SELECT ${values.join(", ")} WHERE ${when(bind)}` : `VALUES (${values.join(", ")})`}`;
|
|
106
106
|
/** Inserts `row` into the op's table, each value bound as its column's type. */
|
|
107
107
|
const insertRow = (bind, row) => insert(bind, name, table.columns.map((column) => column.name), table.columns.map((column) => bind(row[column.name], column)));
|
|
108
|
-
/**
|
|
109
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Replaces the row's entries in the index table of every multi-valued
|
|
110
|
+
* index. A row being inserted has none to replace (`stale` false), and
|
|
111
|
+
* deleting them would read the whole index table: its key ends with the
|
|
112
|
+
* row's key, so no index leads with it.
|
|
113
|
+
*/
|
|
114
|
+
const entries = (key, row, changed, stale = true) => table.indexes.flatMap((index) => {
|
|
110
115
|
const columns = [...index.eq, ...indexOrderColumns(table, index)];
|
|
111
116
|
if (!isMultiIndex(table, index) || changed && !columns.some((column) => changed.includes(column))) return [];
|
|
112
117
|
const into = tableOf(table, index);
|
|
113
118
|
const found = row ? indexEntries(table, index, row) : [];
|
|
114
119
|
const order = found.length > 0 ? indexOrderTuple(table, index, row) : [];
|
|
115
|
-
return [sql((bind) => `DELETE FROM ${into} WHERE ${where(bind, key)}`), ...found.map((eq) => sql((bind) => {
|
|
120
|
+
return [...stale ? [sql((bind) => `DELETE FROM ${into} WHERE ${where(bind, key)}`)] : [], ...found.map((eq) => sql((bind) => {
|
|
116
121
|
const values = [...eq, ...order].map((value) => bind(value));
|
|
117
122
|
return insert(bind, into, columns, values);
|
|
118
123
|
}))];
|
|
119
124
|
});
|
|
120
125
|
switch (op.type) {
|
|
121
|
-
case "insert": return [sql((bind) => insertRow(bind, op.row)), ...entries(rowKey(table, op.row), op.row)];
|
|
126
|
+
case "insert": return [sql((bind) => insertRow(bind, op.row)), ...entries(rowKey(table, op.row), op.row, void 0, false)];
|
|
122
127
|
case "patch": return [sql((bind) => {
|
|
123
128
|
const set = Object.entries(op.set).map(([column, value]) => `${quote(column)} = ${bind(value, findPhysicalColumn(table, column))}`);
|
|
124
129
|
return `UPDATE ${name} SET ${[...set, `${version} = ${version} + 1`].join(", ")} WHERE ${where(bind, op.key, op.guard.v)}`;
|
|
@@ -72,7 +72,12 @@ const sqlTableShapes = (dialect, tables, tablePrefix = "") => tables.map((table)
|
|
|
72
72
|
name: `${name}__${index.name}`,
|
|
73
73
|
columns: entries,
|
|
74
74
|
key: columns,
|
|
75
|
-
indexes: [
|
|
75
|
+
indexes: [{
|
|
76
|
+
kind: "index",
|
|
77
|
+
name: shortSqlName(`${name}__${index.name}__key`),
|
|
78
|
+
unique: false,
|
|
79
|
+
columns: table.key
|
|
80
|
+
}]
|
|
76
81
|
}
|
|
77
82
|
}];
|
|
78
83
|
}
|
|
@@ -149,8 +154,9 @@ const retentionOrder = (table) => {
|
|
|
149
154
|
* column past `before` keeps. `before` renders the bound each time it
|
|
150
155
|
* appears. MySQL deletes with ORDER BY and LIMIT. Elsewhere the cutoff is
|
|
151
156
|
* the last of the `limit` oldest expired rows in that order, a row value
|
|
152
|
-
* the index ranges over
|
|
153
|
-
* AS, aliases `i` and `b
|
|
157
|
+
* the index ranges over. PostgreSQL's shapes pass Supabase's apply RPC: no
|
|
158
|
+
* IN, no AS, aliases `i` and `b`; SQLite's (D1's) delete each doomed row's
|
|
159
|
+
* entries by the index table's key.
|
|
154
160
|
*/
|
|
155
161
|
const pruneStatements = (dialect, table, tablePrefix, limit) => {
|
|
156
162
|
const quote = (name) => quoteSql(dialect, name);
|
|
@@ -159,9 +165,17 @@ const pruneStatements = (dialect, table, tablePrefix, limit) => {
|
|
|
159
165
|
const order = retentionOrder(table).columns.map(quote);
|
|
160
166
|
const list = (alias, direction = "") => order.map((column) => `${alias}.${column}${direction}`).join(", ");
|
|
161
167
|
const oldest = (before) => `SELECT ${list("i")} FROM ${name} i WHERE i.${at} <= ${before()} ORDER BY ${list("i", " ASC")} LIMIT ${limit}`;
|
|
162
|
-
const doomed = (alias, before) =>
|
|
168
|
+
const doomed = (alias, before) => `(${list(alias)}) <= (SELECT ${list("b")} FROM (${oldest(before)}) b ORDER BY ${list("b", " DESC")} LIMIT 1) AND ${alias}.${at} <= ${before()}`;
|
|
163
169
|
const entries = table.indexes.filter((index) => isMultiIndex(table, index)).map((index) => quote(`${tablePrefix}${table.name}__${index.name}`));
|
|
164
170
|
const keyOf = (left, right) => table.key.map((column) => `${left}.${quote(column)} = ${right}.${quote(column)}`).join(" AND ");
|
|
171
|
+
if (dialect === "sqlite") return [...table.indexes.filter((index) => isMultiIndex(table, index)).map((index) => {
|
|
172
|
+
const columns = [...index.eq, ...require_adapter.indexOrderColumns(table, index)];
|
|
173
|
+
const multi = columns.filter((column) => require_adapter.findPhysicalColumn(table, column).multi);
|
|
174
|
+
const values = columns.map((column) => multi.includes(column) ? `j${multi.indexOf(column)}.${quote("value")}` : `b.${quote(column)}`);
|
|
175
|
+
const each = multi.map((column, at) => `, json_each(b.${quote(column)}) j${at}`);
|
|
176
|
+
const into = quote(`${tablePrefix}${table.name}__${index.name}`);
|
|
177
|
+
return (before) => `DELETE FROM ${into} WHERE (${columns.map(quote).join(", ")}) IN (SELECT ${values.join(", ")} FROM ${name} b${each.join("")} WHERE ${doomed("b", before)})`;
|
|
178
|
+
}), (before) => `DELETE FROM ${name} WHERE ${doomed(name, before)}`];
|
|
165
179
|
if (dialect === "mysql") return [...entries.map((index) => (before) => `DELETE e FROM ${index} e JOIN (${oldest(before)}) d ON ${keyOf("e", "d")}`), (before) => `DELETE FROM ${name} WHERE ${at} <= ${before()} ORDER BY ${order.join(", ")} LIMIT ${limit}`];
|
|
166
180
|
return [...entries.map((index) => (before) => `DELETE FROM ${index} WHERE EXISTS (SELECT * FROM ${name} b WHERE ${keyOf("b", index)} AND ${doomed("b", before)})`), (before) => `DELETE FROM ${name} WHERE ${doomed(name, before)}`];
|
|
167
181
|
};
|
|
@@ -72,7 +72,12 @@ const sqlTableShapes = (dialect, tables, tablePrefix = "") => tables.map((table)
|
|
|
72
72
|
name: `${name}__${index.name}`,
|
|
73
73
|
columns: entries,
|
|
74
74
|
key: columns,
|
|
75
|
-
indexes: [
|
|
75
|
+
indexes: [{
|
|
76
|
+
kind: "index",
|
|
77
|
+
name: shortSqlName(`${name}__${index.name}__key`),
|
|
78
|
+
unique: false,
|
|
79
|
+
columns: table.key
|
|
80
|
+
}]
|
|
76
81
|
}
|
|
77
82
|
}];
|
|
78
83
|
}
|
|
@@ -149,8 +154,9 @@ const retentionOrder = (table) => {
|
|
|
149
154
|
* column past `before` keeps. `before` renders the bound each time it
|
|
150
155
|
* appears. MySQL deletes with ORDER BY and LIMIT. Elsewhere the cutoff is
|
|
151
156
|
* the last of the `limit` oldest expired rows in that order, a row value
|
|
152
|
-
* the index ranges over
|
|
153
|
-
* AS, aliases `i` and `b
|
|
157
|
+
* the index ranges over. PostgreSQL's shapes pass Supabase's apply RPC: no
|
|
158
|
+
* IN, no AS, aliases `i` and `b`; SQLite's (D1's) delete each doomed row's
|
|
159
|
+
* entries by the index table's key.
|
|
154
160
|
*/
|
|
155
161
|
const pruneStatements = (dialect, table, tablePrefix, limit) => {
|
|
156
162
|
const quote = (name) => quoteSql(dialect, name);
|
|
@@ -159,9 +165,17 @@ const pruneStatements = (dialect, table, tablePrefix, limit) => {
|
|
|
159
165
|
const order = retentionOrder(table).columns.map(quote);
|
|
160
166
|
const list = (alias, direction = "") => order.map((column) => `${alias}.${column}${direction}`).join(", ");
|
|
161
167
|
const oldest = (before) => `SELECT ${list("i")} FROM ${name} i WHERE i.${at} <= ${before()} ORDER BY ${list("i", " ASC")} LIMIT ${limit}`;
|
|
162
|
-
const doomed = (alias, before) =>
|
|
168
|
+
const doomed = (alias, before) => `(${list(alias)}) <= (SELECT ${list("b")} FROM (${oldest(before)}) b ORDER BY ${list("b", " DESC")} LIMIT 1) AND ${alias}.${at} <= ${before()}`;
|
|
163
169
|
const entries = table.indexes.filter((index) => isMultiIndex(table, index)).map((index) => quote(`${tablePrefix}${table.name}__${index.name}`));
|
|
164
170
|
const keyOf = (left, right) => table.key.map((column) => `${left}.${quote(column)} = ${right}.${quote(column)}`).join(" AND ");
|
|
171
|
+
if (dialect === "sqlite") return [...table.indexes.filter((index) => isMultiIndex(table, index)).map((index) => {
|
|
172
|
+
const columns = [...index.eq, ...indexOrderColumns(table, index)];
|
|
173
|
+
const multi = columns.filter((column) => findPhysicalColumn(table, column).multi);
|
|
174
|
+
const values = columns.map((column) => multi.includes(column) ? `j${multi.indexOf(column)}.${quote("value")}` : `b.${quote(column)}`);
|
|
175
|
+
const each = multi.map((column, at) => `, json_each(b.${quote(column)}) j${at}`);
|
|
176
|
+
const into = quote(`${tablePrefix}${table.name}__${index.name}`);
|
|
177
|
+
return (before) => `DELETE FROM ${into} WHERE (${columns.map(quote).join(", ")}) IN (SELECT ${values.join(", ")} FROM ${name} b${each.join("")} WHERE ${doomed("b", before)})`;
|
|
178
|
+
}), (before) => `DELETE FROM ${name} WHERE ${doomed(name, before)}`];
|
|
165
179
|
if (dialect === "mysql") return [...entries.map((index) => (before) => `DELETE e FROM ${index} e JOIN (${oldest(before)}) d ON ${keyOf("e", "d")}`), (before) => `DELETE FROM ${name} WHERE ${at} <= ${before()} ORDER BY ${order.join(", ")} LIMIT ${limit}`];
|
|
166
180
|
return [...entries.map((index) => (before) => `DELETE FROM ${index} WHERE EXISTS (SELECT * FROM ${name} b WHERE ${keyOf("b", index)} AND ${doomed("b", before)})`), (before) => `DELETE FROM ${name} WHERE ${doomed(name, before)}`];
|
|
167
181
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/plugin-core",
|
|
3
|
-
"version": "1.2.0-rc.
|
|
3
|
+
"version": "1.2.0-rc.44",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"es-toolkit": "^1.32.0",
|
|
46
46
|
"mime": "^4.0.4",
|
|
47
47
|
"verkit": "0.4.0",
|
|
48
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
48
|
+
"@hot-updater/protocol": "1.2.0-rc.44"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@electric-sql/pglite": "0.4.1",
|