@hot-updater/server 1.2.0-rc.4 → 1.2.0-rc.41
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/core/api.cjs +2 -0
- package/dist/core/api.d.cts +30 -0
- package/dist/core/api.d.mts +30 -0
- package/dist/core/api.mjs +2 -0
- package/dist/core/iosDevices.cjs +314 -0
- package/dist/core/iosDevices.mjs +311 -0
- package/dist/core/nativeBuildDestinations.cjs +13 -0
- package/dist/core/nativeBuildDestinations.mjs +13 -0
- package/dist/core/nativeBuilds.cjs +212 -29
- package/dist/core/nativeBuilds.mjs +212 -30
- package/dist/core/operations.cjs +6 -2
- package/dist/core/operations.mjs +7 -3
- package/dist/core/reads.cjs +9 -1
- package/dist/core/reads.mjs +9 -1
- package/dist/core/writes.cjs +4 -1
- package/dist/core/writes.mjs +4 -1
- package/dist/createHotUpdaterCore.d.cts +2 -4
- package/dist/createHotUpdaterCore.d.mts +2 -4
- package/dist/handlerAdminRoutes.cjs +189 -8
- package/dist/handlerAdminRoutes.mjs +189 -8
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +7 -14
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { after } from "./reads.mjs";
|
|
2
|
+
import { NATIVE_BUILD_SUBMISSION_DESTINATIONS } from "./nativeBuildDestinations.mjs";
|
|
2
3
|
import { insertChannel } from "./writes.mjs";
|
|
3
4
|
import { DatabaseConstraintError, isUUIDv7 } from "@hot-updater/plugin-core";
|
|
4
5
|
import { createReleaseCatalogScopeKey, encodeChannelKey } from "@hot-updater/protocol";
|
|
@@ -18,6 +19,27 @@ const GIT_COMMIT_HASH_MAX_LENGTH = 255;
|
|
|
18
19
|
* and looks up nothing else.
|
|
19
20
|
*/
|
|
20
21
|
const BUILD_KEY = /^nbk1:[0-9a-f]{64}$/;
|
|
22
|
+
/** `native_builds.sandbox_url_scheme`'s bound in core's schema. */
|
|
23
|
+
const SANDBOX_URL_SCHEME_MAX_LENGTH = 255;
|
|
24
|
+
/**
|
|
25
|
+
* A URL scheme as RFC 3986 spells it, in lower case: what a sandbox build's
|
|
26
|
+
* artifact registers, as `@hot-updater/protocol/native-artifact` reads it.
|
|
27
|
+
*/
|
|
28
|
+
const URL_SCHEME = new RegExp(`^[a-z][a-z0-9+.-]{0,254}$`);
|
|
29
|
+
/**
|
|
30
|
+
* A bundle identifier or application ID, as an artifact reports it: letters,
|
|
31
|
+
* digits, dots, dashes and underscores, which a scope key holds as they are.
|
|
32
|
+
*/
|
|
33
|
+
const APP_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,254}$/;
|
|
34
|
+
/** A fingerprint hash as a Release Catalog scope key holds it. */
|
|
35
|
+
const FINGERPRINT_HASH = /^[A-Za-z0-9._~-]{1,255}$/;
|
|
36
|
+
/** How each kind of artifact can install. */
|
|
37
|
+
const DISTRIBUTIONS = {
|
|
38
|
+
apk: ["direct"],
|
|
39
|
+
app: ["direct"],
|
|
40
|
+
aab: ["store"],
|
|
41
|
+
ipa: ["direct", "store"]
|
|
42
|
+
};
|
|
21
43
|
/** A native build or scope core cannot store or look up: the caller's input. */
|
|
22
44
|
var NativeBuildInputError = class extends TypeError {
|
|
23
45
|
name = "NativeBuildInputError";
|
|
@@ -39,24 +61,67 @@ const pick = (row) => ({
|
|
|
39
61
|
build_number: row.build_number ?? null,
|
|
40
62
|
submitted_to: row.submitted_to ?? null,
|
|
41
63
|
submitted_at_ms: row.submitted_at_ms ?? null,
|
|
42
|
-
submitted_version: row.submitted_version ?? null
|
|
64
|
+
submitted_version: row.submitted_version ?? null,
|
|
65
|
+
is_store_build: row.is_store_build === true,
|
|
66
|
+
is_sandbox: row.is_sandbox === true,
|
|
67
|
+
sandbox_url_scheme: row.sandbox_url_scheme ?? null,
|
|
68
|
+
export_method: row.export_method ?? null,
|
|
69
|
+
native_app_version: row.native_app_version ?? null
|
|
43
70
|
});
|
|
44
|
-
/** The
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
71
|
+
/** The export methods an `.ipa` registers with. */
|
|
72
|
+
const EXPORT_METHODS = /* @__PURE__ */ new Set([
|
|
73
|
+
"app-store",
|
|
74
|
+
"ad-hoc",
|
|
75
|
+
"development",
|
|
76
|
+
"enterprise"
|
|
77
|
+
]);
|
|
78
|
+
/**
|
|
79
|
+
* How many older builds of a scope one read takes, looking for one older than
|
|
80
|
+
* a bundle when a build made after the bundle is the newest.
|
|
81
|
+
*/
|
|
82
|
+
const OLDER_BUILDS_PAGE = 20;
|
|
83
|
+
/** How many times a mark runs again after losing its scope's mark to another. */
|
|
84
|
+
const MARK_ATTEMPTS = 8;
|
|
49
85
|
/** `native_builds.build_number`'s bound in core's schema. */
|
|
50
86
|
const BUILD_NUMBER_MAX_LENGTH = 64;
|
|
51
87
|
/** `native_builds.submitted_version`'s bound in core's schema. */
|
|
52
88
|
const SUBMITTED_VERSION_MAX_LENGTH = 255;
|
|
89
|
+
const checkedScopeKey = (scopeKey) => {
|
|
90
|
+
if (scopeKey.length > SCOPE_KEY_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build scope: its key is longer than ${SCOPE_KEY_MAX_LENGTH} characters; shorten the channel or app version.`);
|
|
91
|
+
return scopeKey;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* How a registered artifact installs: an `.ipa` by its export method, and
|
|
95
|
+
* `unknown` for one whose export no profile confirmed, which no lookup asks
|
|
96
|
+
* for, so it is never reused as either.
|
|
97
|
+
*/
|
|
98
|
+
const registeredDistribution = (kind, exportMethod) => kind !== "ipa" ? DISTRIBUTIONS[kind][0] : exportMethod === void 0 || exportMethod === null ? "unknown" : exportMethod === "app-store" ? "store" : "direct";
|
|
99
|
+
/**
|
|
100
|
+
* A sandbox build scope's key, which names no channel: the app ID, URL
|
|
101
|
+
* scheme, artifact kind and distribution in its place, then the fingerprint,
|
|
102
|
+
* or the app-version strategy and the exact app version. `v1:sandbox:` is no
|
|
103
|
+
* Release Catalog strategy, so it never meets a normal build's key.
|
|
104
|
+
*/
|
|
105
|
+
const sandboxScopeKey = (scope, sandbox) => {
|
|
106
|
+
const { appId, urlScheme, artifactKind, distribution } = sandbox;
|
|
107
|
+
const problem = typeof appId !== "string" || !APP_ID.test(appId) ? "its app ID must be a bundle identifier or application ID, up to 255 characters" : typeof urlScheme !== "string" || !URL_SCHEME.test(urlScheme) ? `its URL scheme must be a URL scheme in lower case, up to ${SANDBOX_URL_SCHEME_MAX_LENGTH} characters` : !ARTIFACT_KINDS[scope.platform]?.includes(artifactKind) ? `its artifact kind must be one an ${scope.platform} build makes` : distribution !== "unknown" && !DISTRIBUTIONS[artifactKind].includes(distribution) ? `an .${artifactKind} doesn't install as ${String(distribution)}` : scope.fingerprintHash !== null && !FINGERPRINT_HASH.test(scope.fingerprintHash) ? "its fingerprint hash must be 1-255 URL-safe ASCII characters" : null;
|
|
108
|
+
if (problem !== null) throw new NativeBuildInputError(`Invalid sandbox build scope: ${problem}.`);
|
|
109
|
+
const target = scope.fingerprintHash === null ? `app-version:${encodeURIComponent(scope.appVersion)}` : `fingerprint:${scope.fingerprintHash}`;
|
|
110
|
+
return checkedScopeKey(`v1:sandbox:${scope.platform}:${appId}:${urlScheme}:${artifactKind}:${distribution}:${target}`);
|
|
111
|
+
};
|
|
53
112
|
/**
|
|
54
113
|
* A native build scope's key: the Release Catalog scope key of a
|
|
55
114
|
* fingerprint, or of the app-version strategy followed by the exact app
|
|
56
115
|
* version the build compiled in. One key serves both strategies, so one
|
|
57
|
-
* index finds the newest build of either.
|
|
116
|
+
* index finds the newest build of either. A sandbox scope's key names no
|
|
117
|
+
* channel, so pull requests find a sandbox build on any.
|
|
58
118
|
*/
|
|
59
119
|
const nativeBuildScopeKey = (scope) => {
|
|
120
|
+
const { sandbox } = scope;
|
|
121
|
+
if (sandbox !== void 0 && sandbox !== null) {
|
|
122
|
+
if (sandbox.distribution !== "direct" && sandbox.distribution !== "store") throw new NativeBuildInputError("Invalid sandbox build scope: its distribution must be direct or store.");
|
|
123
|
+
return sandboxScopeKey(scope, sandbox);
|
|
124
|
+
}
|
|
60
125
|
let scopeKey;
|
|
61
126
|
try {
|
|
62
127
|
const channelKey = encodeChannelKey(scope.channel);
|
|
@@ -73,22 +138,71 @@ const nativeBuildScopeKey = (scope) => {
|
|
|
73
138
|
} catch (error) {
|
|
74
139
|
throw new NativeBuildInputError(`Invalid native build scope: ${error instanceof Error ? error.message : String(error)}.`);
|
|
75
140
|
}
|
|
76
|
-
|
|
77
|
-
|
|
141
|
+
return checkedScopeKey(scopeKey);
|
|
142
|
+
};
|
|
143
|
+
/** The channel row a registration names, or the refusal of its channel. */
|
|
144
|
+
const channelIdOf = (channel) => {
|
|
145
|
+
try {
|
|
146
|
+
return `channel:${encodeChannelKey(channel)}`;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
throw new NativeBuildInputError(`Invalid native build scope: ${error instanceof Error ? error.message : String(error)}.`);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* A registration's scope key, from the registration's own facts: a sandbox
|
|
153
|
+
* build's from what its artifact says, whatever `sandbox` it names.
|
|
154
|
+
*/
|
|
155
|
+
const registrationScopeKey = (registration) => {
|
|
156
|
+
channelIdOf(registration.channel);
|
|
157
|
+
return registration.isSandbox === true ? sandboxScopeKey(registration, {
|
|
158
|
+
appId: registration.sandboxAppId,
|
|
159
|
+
urlScheme: registration.sandboxUrlScheme,
|
|
160
|
+
artifactKind: registration.artifact.kind,
|
|
161
|
+
distribution: registeredDistribution(registration.artifact.kind, registration.exportMethod)
|
|
162
|
+
}) : nativeBuildScopeKey({
|
|
163
|
+
...registration,
|
|
164
|
+
sandbox: null
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Refuses a patch from a sandbox build's built-in bundle: no deploy patches
|
|
169
|
+
* from one, so no store or test install of the app gets a patch made for a
|
|
170
|
+
* sandbox build. One unique read of the base.
|
|
171
|
+
*/
|
|
172
|
+
const refuseSandboxPatchBase = async (db, baseBundleId) => {
|
|
173
|
+
if ((await db.findOne("native_builds", { min_bundle_id: baseBundleId }))?.is_sandbox === true) throw new NativeBuildInputError("A sandbox build's built-in bundle is no patch base.");
|
|
78
174
|
};
|
|
79
175
|
/** Whether `bundleId` is a native build's built-in bundle: one unique read. */
|
|
80
176
|
const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
|
|
81
|
-
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, artifact }) => {
|
|
177
|
+
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, sandboxAppId, exportMethod, nativeAppVersion, artifact }) => {
|
|
82
178
|
if (!isUUIDv7(id)) return "id must be a UUIDv7";
|
|
83
179
|
if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
|
|
84
180
|
if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
|
|
85
181
|
if (channel.trim().length === 0) return "channel is required";
|
|
182
|
+
if (isSandbox !== void 0 && typeof isSandbox !== "boolean") return "isSandbox must be true or false";
|
|
183
|
+
if (sandboxUrlScheme !== void 0 && sandboxUrlScheme !== null) {
|
|
184
|
+
if (isSandbox !== true) return "sandboxUrlScheme is a sandbox build's, and this isn't one";
|
|
185
|
+
if (typeof sandboxUrlScheme !== "string" || !URL_SCHEME.test(sandboxUrlScheme)) return `sandboxUrlScheme must be a URL scheme in lower case, up to ${SANDBOX_URL_SCHEME_MAX_LENGTH} characters, or null`;
|
|
186
|
+
}
|
|
187
|
+
if (sandboxAppId !== void 0 && sandboxAppId !== null) {
|
|
188
|
+
if (isSandbox !== true) return "sandboxAppId is a sandbox build's, and this isn't one";
|
|
189
|
+
if (typeof sandboxAppId !== "string" || !APP_ID.test(sandboxAppId)) return "sandboxAppId must be the artifact's bundle identifier or application ID, up to 255 characters";
|
|
190
|
+
}
|
|
191
|
+
if (isSandbox === true) {
|
|
192
|
+
if (sandboxUrlScheme === void 0 || sandboxUrlScheme === null) return "a sandbox build needs the sandboxUrlScheme its artifact registers";
|
|
193
|
+
if (sandboxAppId === void 0 || sandboxAppId === null) return "a sandbox build needs the sandboxAppId its artifact reports, which an older hot-updater CLI doesn't send. Upgrade the hot-updater CLI to the version that matches this server, and build again";
|
|
194
|
+
}
|
|
86
195
|
if (gitCommitHash !== null && gitCommitHash.length > GIT_COMMIT_HASH_MAX_LENGTH) return `gitCommitHash must be at most ${GIT_COMMIT_HASH_MAX_LENGTH} characters`;
|
|
87
196
|
if (fingerprintHash === null === (appVersion === null)) return "exactly one of fingerprintHash and appVersion is required";
|
|
88
197
|
if (buildKey !== null && !BUILD_KEY.test(buildKey)) return "buildKey must be nbk1: and a SHA-256, or null";
|
|
89
198
|
if (buildNumber !== void 0 && buildNumber !== null && (buildNumber.trim().length === 0 || buildNumber.length > BUILD_NUMBER_MAX_LENGTH)) return `buildNumber must be the artifact's build number, up to ${BUILD_NUMBER_MAX_LENGTH} characters, or null`;
|
|
199
|
+
if (nativeAppVersion !== void 0 && nativeAppVersion !== null && (typeof nativeAppVersion !== "string" || nativeAppVersion.trim().length === 0)) return "nativeAppVersion must be the artifact's app version, or null";
|
|
90
200
|
const kinds = ARTIFACT_KINDS[platform];
|
|
91
201
|
if (!kinds.includes(artifact.kind)) return `artifact.kind of an ${platform} build must be ${kinds.join(" or ")}`;
|
|
202
|
+
if (exportMethod !== void 0 && exportMethod !== null) {
|
|
203
|
+
if (artifact.kind !== "ipa") return "exportMethod is an .ipa's, and this artifact isn't one";
|
|
204
|
+
if (!EXPORT_METHODS.has(exportMethod)) return `exportMethod must be ${[...EXPORT_METHODS].join(", ")}, or null`;
|
|
205
|
+
}
|
|
92
206
|
if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
|
|
93
207
|
return null;
|
|
94
208
|
};
|
|
@@ -97,8 +211,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
97
211
|
async registerNativeBuild(registration) {
|
|
98
212
|
const problem = problemOf(registration);
|
|
99
213
|
if (problem !== null) throw new NativeBuildInputError(`Invalid native build: ${problem}.`);
|
|
100
|
-
const scopeKey =
|
|
101
|
-
const channelId =
|
|
214
|
+
const scopeKey = registrationScopeKey(registration);
|
|
215
|
+
const channelId = channelIdOf(registration.channel);
|
|
102
216
|
const { embeddedBundle } = registration;
|
|
103
217
|
const row = {
|
|
104
218
|
id: registration.id,
|
|
@@ -117,7 +231,12 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
117
231
|
build_number: registration.buildNumber ?? null,
|
|
118
232
|
submitted_to: null,
|
|
119
233
|
submitted_at_ms: null,
|
|
120
|
-
submitted_version: null
|
|
234
|
+
submitted_version: null,
|
|
235
|
+
is_store_build: false,
|
|
236
|
+
is_sandbox: registration.isSandbox === true,
|
|
237
|
+
sandbox_url_scheme: registration.sandboxUrlScheme ?? null,
|
|
238
|
+
export_method: registration.exportMethod ?? null,
|
|
239
|
+
native_app_version: registration.nativeAppVersion ?? null
|
|
121
240
|
};
|
|
122
241
|
for (let attempt = 1;; attempt += 1) {
|
|
123
242
|
await insertChannel(db, {
|
|
@@ -155,21 +274,43 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
155
274
|
const scopeKey = nativeBuildScopeKey(scope);
|
|
156
275
|
const buildKey = options?.buildKey;
|
|
157
276
|
if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
277
|
+
if (options?.storeBuild) {
|
|
278
|
+
const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
|
|
279
|
+
return marked === null ? null : pick(marked);
|
|
280
|
+
}
|
|
281
|
+
const read = (limit, before) => {
|
|
282
|
+
const page = {
|
|
283
|
+
order: "desc",
|
|
284
|
+
limit,
|
|
285
|
+
...before === void 0 ? {} : { range: { lt: before } }
|
|
286
|
+
};
|
|
287
|
+
return buildKey === void 0 ? db.findMany("native_builds", {
|
|
288
|
+
index: "byScope",
|
|
289
|
+
where: { scope_key: scopeKey },
|
|
290
|
+
...page
|
|
291
|
+
}) : db.findMany("native_builds", {
|
|
292
|
+
index: "byBuildKey",
|
|
293
|
+
where: {
|
|
294
|
+
scope_key: scopeKey,
|
|
295
|
+
build_key: buildKey
|
|
296
|
+
},
|
|
297
|
+
...page
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
const bundleId = options?.builtInOlderThan;
|
|
301
|
+
if (bundleId !== void 0 && scope.sandbox !== void 0 && scope.sandbox !== null) return null;
|
|
302
|
+
const { rows } = await read(1);
|
|
303
|
+
const newest = rows[0];
|
|
304
|
+
if (newest === void 0) return null;
|
|
305
|
+
if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
|
|
306
|
+
for (let before = newest.id;;) {
|
|
307
|
+
const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
|
|
308
|
+
const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
|
|
309
|
+
if (usable !== void 0) return pick(usable);
|
|
310
|
+
const last = older.at(-1);
|
|
311
|
+
if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
|
|
312
|
+
before = last.id;
|
|
313
|
+
}
|
|
173
314
|
},
|
|
174
315
|
async recordNativeBuildSubmission(id, { destination, version }) {
|
|
175
316
|
if (version.trim().length === 0 || version.length > SUBMITTED_VERSION_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build submission: version must be the store's label of the build, up to ${SUBMITTED_VERSION_MAX_LENGTH} characters.`);
|
|
@@ -177,7 +318,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
177
318
|
const row = await tx.findOne("native_builds", { id });
|
|
178
319
|
if (row === null) return null;
|
|
179
320
|
const build = pick(row);
|
|
180
|
-
if (
|
|
321
|
+
if (!NATIVE_BUILD_SUBMISSION_DESTINATIONS[build.platform].includes(destination)) throw new NativeBuildInputError(`Invalid native build submission: an ${build.platform} build is submitted to ${NATIVE_BUILD_SUBMISSION_DESTINATIONS[build.platform].join(" or ")}, not ${destination}.`);
|
|
322
|
+
if (build.is_sandbox && destination !== "testflight" && destination !== "play-internal") throw new NativeBuildInputError("A sandbox build can submit only to TestFlight or Play internal testing.");
|
|
181
323
|
const set = {
|
|
182
324
|
submitted_to: destination,
|
|
183
325
|
submitted_at_ms: now(),
|
|
@@ -190,6 +332,46 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
190
332
|
};
|
|
191
333
|
});
|
|
192
334
|
},
|
|
335
|
+
async markNativeBuild(id, { storeBuild }) {
|
|
336
|
+
for (let attempt = 1;; attempt += 1) try {
|
|
337
|
+
return await db.transaction(async (tx) => {
|
|
338
|
+
const row = await tx.findOne("native_builds", { id });
|
|
339
|
+
if (row === null) return null;
|
|
340
|
+
const build = pick(row);
|
|
341
|
+
if (!storeBuild) {
|
|
342
|
+
if (build.is_store_build) tx.update("native_builds", row, { is_store_build: false });
|
|
343
|
+
return {
|
|
344
|
+
nativeBuild: {
|
|
345
|
+
...build,
|
|
346
|
+
is_store_build: false
|
|
347
|
+
},
|
|
348
|
+
previous: null
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
if (build.is_sandbox) throw new NativeBuildInputError("A sandbox build can't be the store build.");
|
|
352
|
+
if (build.is_store_build) return {
|
|
353
|
+
nativeBuild: build,
|
|
354
|
+
previous: null
|
|
355
|
+
};
|
|
356
|
+
const holder = await tx.findOne("native_builds", { store_build_scope_key: build.scope_key });
|
|
357
|
+
if (holder !== null) tx.update("native_builds", holder, { is_store_build: false });
|
|
358
|
+
tx.update("native_builds", row, { is_store_build: true });
|
|
359
|
+
return {
|
|
360
|
+
nativeBuild: {
|
|
361
|
+
...build,
|
|
362
|
+
is_store_build: true
|
|
363
|
+
},
|
|
364
|
+
previous: holder === null ? null : {
|
|
365
|
+
...pick(holder),
|
|
366
|
+
is_store_build: false
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
});
|
|
370
|
+
} catch (error) {
|
|
371
|
+
if (attempt < MARK_ATTEMPTS && error instanceof DatabaseConstraintError && error.reason === "unique") continue;
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
374
|
+
},
|
|
193
375
|
async deleteNativeBuild(id) {
|
|
194
376
|
return db.transaction(async (tx) => {
|
|
195
377
|
const row = await tx.findOne("native_builds", { id });
|
|
@@ -226,4 +408,4 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
226
408
|
}
|
|
227
409
|
});
|
|
228
410
|
//#endregion
|
|
229
|
-
export { NativeBuildInputError, createNativeBuildApi, isBuiltInBundle, nativeBuildScopeKey };
|
|
411
|
+
export { NativeBuildInputError, createNativeBuildApi, isBuiltInBundle, nativeBuildScopeKey, refuseSandboxPatchBase };
|
package/dist/core/operations.cjs
CHANGED
|
@@ -129,7 +129,11 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
129
129
|
for (const { release } of deployments) if (!channels.has(release.channel)) channels.set(release.channel, await ensureChannel(release.channel));
|
|
130
130
|
const platforms = /* @__PURE__ */ new Map();
|
|
131
131
|
for (const deployment of deployments) {
|
|
132
|
-
if (!("bundleId" in deployment)
|
|
132
|
+
if (!("bundleId" in deployment)) {
|
|
133
|
+
for (const { baseBundleId } of deployment.bundle.patches ?? []) await require_nativeBuilds.refuseSandboxPatchBase(db, baseBundleId);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (platforms.has(deployment.bundleId)) continue;
|
|
133
137
|
const row = await db.findOne("bundles", { id: deployment.bundleId });
|
|
134
138
|
if (row === null) throw new _hot_updater_plugin_core.DatabaseBundleNotFoundError(deployment.bundleId);
|
|
135
139
|
if (await require_nativeBuilds.isBuiltInBundle(db, deployment.bundleId)) throw new _hot_updater_plugin_core.ReleaseManagementError("TARGET_RELEASE_INVALID", `Bundle "${deployment.bundleId}" is a native build's built-in bundle, which no release publishes.`);
|
|
@@ -333,7 +337,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
333
337
|
if (patches !== void 0) await require_writes.replaceBundlePatches(tx, current, (0, _hot_updater_plugin_core.bundleToPatchRows)({
|
|
334
338
|
...next,
|
|
335
339
|
patches
|
|
336
|
-
}));
|
|
340
|
+
}), (row) => require_nativeBuilds.refuseSandboxPatchBase(tx, row.base_bundle_id));
|
|
337
341
|
}),
|
|
338
342
|
deleteBundles: async (ids) => {
|
|
339
343
|
try {
|
package/dist/core/operations.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toBundleRow, toReleaseRow } from "./reads.mjs";
|
|
2
2
|
import { deleteBundle, deleteChannel, insertChannel, replaceBundlePatches, updateBundle } from "./writes.mjs";
|
|
3
|
-
import { isBuiltInBundle } from "./nativeBuilds.mjs";
|
|
3
|
+
import { isBuiltInBundle, refuseSandboxPatchBase } from "./nativeBuilds.mjs";
|
|
4
4
|
import { changeRelease, changeReleases, 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";
|
|
@@ -129,7 +129,11 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
129
129
|
for (const { release } of deployments) if (!channels.has(release.channel)) channels.set(release.channel, await ensureChannel(release.channel));
|
|
130
130
|
const platforms = /* @__PURE__ */ new Map();
|
|
131
131
|
for (const deployment of deployments) {
|
|
132
|
-
if (!("bundleId" in deployment)
|
|
132
|
+
if (!("bundleId" in deployment)) {
|
|
133
|
+
for (const { baseBundleId } of deployment.bundle.patches ?? []) await refuseSandboxPatchBase(db, baseBundleId);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (platforms.has(deployment.bundleId)) continue;
|
|
133
137
|
const row = await db.findOne("bundles", { id: deployment.bundleId });
|
|
134
138
|
if (row === null) throw new DatabaseBundleNotFoundError(deployment.bundleId);
|
|
135
139
|
if (await isBuiltInBundle(db, deployment.bundleId)) throw new ReleaseManagementError("TARGET_RELEASE_INVALID", `Bundle "${deployment.bundleId}" is a native build's built-in bundle, which no release publishes.`);
|
|
@@ -333,7 +337,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
333
337
|
if (patches !== void 0) await replaceBundlePatches(tx, current, bundleToPatchRows({
|
|
334
338
|
...next,
|
|
335
339
|
patches
|
|
336
|
-
}));
|
|
340
|
+
}), (row) => refuseSandboxPatchBase(tx, row.base_bundle_id));
|
|
337
341
|
}),
|
|
338
342
|
deleteBundles: async (ids) => {
|
|
339
343
|
try {
|
package/dist/core/reads.cjs
CHANGED
|
@@ -74,7 +74,15 @@ const drain = async (read) => {
|
|
|
74
74
|
return rows;
|
|
75
75
|
};
|
|
76
76
|
/** A keyset page's range: the keys strictly after `after`, in `order`. */
|
|
77
|
-
|
|
77
|
+
/** A keyset read's range on its index's order: past `after`, up to `through`. */
|
|
78
|
+
const after = (input) => {
|
|
79
|
+
const asc = (input.order ?? "asc") === "asc";
|
|
80
|
+
const range = {
|
|
81
|
+
...input.after === void 0 ? {} : asc ? { gt: input.after } : { lt: input.after },
|
|
82
|
+
...input.through === void 0 ? {} : asc ? { lte: input.through } : { gte: input.through }
|
|
83
|
+
};
|
|
84
|
+
return Object.keys(range).length === 0 ? {} : { range };
|
|
85
|
+
};
|
|
78
86
|
/** Core's reads, each through one declared index or key. */
|
|
79
87
|
const createCoreReads = (db, storage) => {
|
|
80
88
|
/** A bundle row's patches, exactly as many as its reference counter holds. */
|
package/dist/core/reads.mjs
CHANGED
|
@@ -74,7 +74,15 @@ const drain = async (read) => {
|
|
|
74
74
|
return rows;
|
|
75
75
|
};
|
|
76
76
|
/** A keyset page's range: the keys strictly after `after`, in `order`. */
|
|
77
|
-
|
|
77
|
+
/** A keyset read's range on its index's order: past `after`, up to `through`. */
|
|
78
|
+
const after = (input) => {
|
|
79
|
+
const asc = (input.order ?? "asc") === "asc";
|
|
80
|
+
const range = {
|
|
81
|
+
...input.after === void 0 ? {} : asc ? { gt: input.after } : { lt: input.after },
|
|
82
|
+
...input.through === void 0 ? {} : asc ? { lte: input.through } : { gte: input.through }
|
|
83
|
+
};
|
|
84
|
+
return Object.keys(range).length === 0 ? {} : { range };
|
|
85
|
+
};
|
|
78
86
|
/** Core's reads, each through one declared index or key. */
|
|
79
87
|
const createCoreReads = (db, storage) => {
|
|
80
88
|
/** A bundle row's patches, exactly as many as its reference counter holds. */
|
package/dist/core/writes.cjs
CHANGED
|
@@ -29,8 +29,10 @@ const deleteBundle = async (tx, current) => {
|
|
|
29
29
|
/**
|
|
30
30
|
* Replaces a bundle's patches with `rows`: kept patches are updated where
|
|
31
31
|
* they changed, others deleted or created, so no key is written twice.
|
|
32
|
+
* `checkNew` sees each patch it is about to create, and refuses one by
|
|
33
|
+
* throwing, which leaves the transaction's writes undone.
|
|
32
34
|
*/
|
|
33
|
-
const replaceBundlePatches = async (tx, bundle, rows) => {
|
|
35
|
+
const replaceBundlePatches = async (tx, bundle, rows, checkNew) => {
|
|
34
36
|
const wanted = new Map(rows.map((row) => [row.id, row]));
|
|
35
37
|
const count = bundle._refs_bundle_patches_bundle_id ?? 0;
|
|
36
38
|
let cursor;
|
|
@@ -55,6 +57,7 @@ const replaceBundlePatches = async (tx, bundle, rows) => {
|
|
|
55
57
|
if (page.next === void 0) break;
|
|
56
58
|
cursor = page.next;
|
|
57
59
|
}
|
|
60
|
+
if (checkNew !== void 0) for (const row of wanted.values()) await checkNew(row);
|
|
58
61
|
for (const row of wanted.values()) tx.create("bundle_patches", row);
|
|
59
62
|
};
|
|
60
63
|
/** A channel by name, created when missing; a concurrent creator's row is returned instead. */
|
package/dist/core/writes.mjs
CHANGED
|
@@ -29,8 +29,10 @@ const deleteBundle = async (tx, current) => {
|
|
|
29
29
|
/**
|
|
30
30
|
* Replaces a bundle's patches with `rows`: kept patches are updated where
|
|
31
31
|
* they changed, others deleted or created, so no key is written twice.
|
|
32
|
+
* `checkNew` sees each patch it is about to create, and refuses one by
|
|
33
|
+
* throwing, which leaves the transaction's writes undone.
|
|
32
34
|
*/
|
|
33
|
-
const replaceBundlePatches = async (tx, bundle, rows) => {
|
|
35
|
+
const replaceBundlePatches = async (tx, bundle, rows, checkNew) => {
|
|
34
36
|
const wanted = new Map(rows.map((row) => [row.id, row]));
|
|
35
37
|
const count = bundle._refs_bundle_patches_bundle_id ?? 0;
|
|
36
38
|
let cursor;
|
|
@@ -55,6 +57,7 @@ const replaceBundlePatches = async (tx, bundle, rows) => {
|
|
|
55
57
|
if (page.next === void 0) break;
|
|
56
58
|
cursor = page.next;
|
|
57
59
|
}
|
|
60
|
+
if (checkNew !== void 0) for (const row of wanted.values()) await checkNew(row);
|
|
58
61
|
for (const row of wanted.values()) tx.create("bundle_patches", row);
|
|
59
62
|
};
|
|
60
63
|
/** A channel by name, created when missing; a concurrent creator's row is returned instead. */
|
|
@@ -42,10 +42,8 @@ type RuntimeHotUpdaterAPI<TPlugins extends readonly AnyHotUpdaterPlugin[] = read
|
|
|
42
42
|
/** The database's name, which `hot-updater db` commands read. */
|
|
43
43
|
readonly adapterName: string;
|
|
44
44
|
/**
|
|
45
|
-
* Applies
|
|
46
|
-
*
|
|
47
|
-
* A long-lived server with `aggregateBatching: { mode: "memory" }` calls
|
|
48
|
-
* it before it exits.
|
|
45
|
+
* Applies the log rows of batched aggregates that no compaction has merged
|
|
46
|
+
* yet. Nothing waits on it: they are durable, and a read compacts first.
|
|
49
47
|
*/
|
|
50
48
|
readonly flush: () => Promise<void>;
|
|
51
49
|
/**
|
|
@@ -42,10 +42,8 @@ type RuntimeHotUpdaterAPI<TPlugins extends readonly AnyHotUpdaterPlugin[] = read
|
|
|
42
42
|
/** The database's name, which `hot-updater db` commands read. */
|
|
43
43
|
readonly adapterName: string;
|
|
44
44
|
/**
|
|
45
|
-
* Applies
|
|
46
|
-
*
|
|
47
|
-
* A long-lived server with `aggregateBatching: { mode: "memory" }` calls
|
|
48
|
-
* it before it exits.
|
|
45
|
+
* Applies the log rows of batched aggregates that no compaction has merged
|
|
46
|
+
* yet. Nothing waits on it: they are durable, and a read compacts first.
|
|
49
47
|
*/
|
|
50
48
|
readonly flush: () => Promise<void>;
|
|
51
49
|
/**
|