@hot-updater/cloudflare 0.29.2 → 0.29.4
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/iac/index.cjs +6 -6
- package/dist/iac/index.mjs +29 -29
- package/dist/index.cjs +7 -13
- package/dist/index.mjs +19 -25
- package/dist/worker/index.cjs +5 -10
- package/dist/worker/index.mjs +5 -10
- package/package.json +8 -8
- package/src/cloudflareWorkerDatabase.ts +3 -13
- package/src/d1Database.spec.ts +126 -1
- package/src/d1Database.ts +6 -10
- package/src/r2Storage.ts +2 -1
- package/src/r2WorkerStorage.ts +2 -2
- package/src/worker/index.ts +6 -6
- package/worker/dist/README.md +1 -1
- package/worker/dist/index.js +59 -42
- package/worker/dist/index.js.map +3 -3
- package/worker/src/getUpdateInfo.ts +6 -12
- package/worker/src/index.integration.spec.ts +2 -1
- package/worker/src/index.ts +1 -0
package/dist/iac/index.cjs
CHANGED
|
@@ -22,10 +22,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
enumerable: true
|
|
23
23
|
}) : target, mod));
|
|
24
24
|
//#endregion
|
|
25
|
-
let _hot_updater_cli_tools = require("@hot-updater/cli-tools");
|
|
26
|
-
let cloudflare = require("cloudflare");
|
|
27
25
|
let crypto = require("crypto");
|
|
28
26
|
crypto = __toESM(crypto);
|
|
27
|
+
let fs_promises = require("fs/promises");
|
|
28
|
+
fs_promises = __toESM(fs_promises);
|
|
29
|
+
let path = require("path");
|
|
30
|
+
path = __toESM(path);
|
|
31
|
+
let _hot_updater_cli_tools = require("@hot-updater/cli-tools");
|
|
32
|
+
let cloudflare = require("cloudflare");
|
|
29
33
|
let node_url = require("node:url");
|
|
30
34
|
let node_child_process = require("node:child_process");
|
|
31
35
|
let node_string_decoder = require("node:string_decoder");
|
|
@@ -36,8 +40,6 @@ let node_tty = require("node:tty");
|
|
|
36
40
|
node_tty = __toESM(node_tty);
|
|
37
41
|
let node_path = require("node:path");
|
|
38
42
|
node_path = __toESM(node_path);
|
|
39
|
-
let path = require("path");
|
|
40
|
-
path = __toESM(path);
|
|
41
43
|
let fs = require("fs");
|
|
42
44
|
fs = __toESM(fs);
|
|
43
45
|
let node_timers_promises = require("node:timers/promises");
|
|
@@ -48,8 +50,6 @@ let node_fs = require("node:fs");
|
|
|
48
50
|
let node_stream_promises = require("node:stream/promises");
|
|
49
51
|
let node_stream = require("node:stream");
|
|
50
52
|
let node_buffer = require("node:buffer");
|
|
51
|
-
let fs_promises = require("fs/promises");
|
|
52
|
-
fs_promises = __toESM(fs_promises);
|
|
53
53
|
let os = require("os");
|
|
54
54
|
os = __toESM(os);
|
|
55
55
|
//#endregion
|
package/dist/iac/index.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
import fs from "fs/promises";
|
|
4
|
+
import path from "path";
|
|
2
5
|
import { ConfigBuilder, copyDirToTmp, getCwd, link, makeEnv, p, transformTemplate } from "@hot-updater/cli-tools";
|
|
3
6
|
import { Cloudflare } from "cloudflare";
|
|
4
|
-
import crypto from "crypto";
|
|
5
7
|
import { fileURLToPath } from "node:url";
|
|
6
8
|
import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
|
|
7
9
|
import { StringDecoder } from "node:string_decoder";
|
|
8
10
|
import { aborted, callbackify, debuglog, inspect, promisify, stripVTControlCharacters } from "node:util";
|
|
9
11
|
import process$1, { execArgv, execPath, hrtime, platform } from "node:process";
|
|
10
12
|
import tty from "node:tty";
|
|
11
|
-
import path from "node:path";
|
|
12
|
-
import
|
|
13
|
-
import fs from "fs";
|
|
13
|
+
import path$1 from "node:path";
|
|
14
|
+
import fs$1 from "fs";
|
|
14
15
|
import { scheduler, setImmediate, setTimeout } from "node:timers/promises";
|
|
15
16
|
import { constants } from "node:os";
|
|
16
17
|
import { EventEmitter, addAbortListener, on, once, setMaxListeners } from "node:events";
|
|
@@ -19,7 +20,6 @@ import { appendFileSync, createReadStream, createWriteStream, readFileSync, stat
|
|
|
19
20
|
import { finished } from "node:stream/promises";
|
|
20
21
|
import { Duplex, PassThrough, Readable, Transform, Writable, getDefaultHighWaterMark } from "node:stream";
|
|
21
22
|
import { Buffer as Buffer$1 } from "node:buffer";
|
|
22
|
-
import fs$1 from "fs/promises";
|
|
23
23
|
import os from "os";
|
|
24
24
|
//#region \0rolldown/runtime.js
|
|
25
25
|
var __create = Object.create;
|
|
@@ -1512,33 +1512,33 @@ function toPath(urlOrPath) {
|
|
|
1512
1512
|
}
|
|
1513
1513
|
function traversePathUp(startPath) {
|
|
1514
1514
|
return { *[Symbol.iterator]() {
|
|
1515
|
-
let currentPath = path.resolve(toPath(startPath));
|
|
1515
|
+
let currentPath = path$1.resolve(toPath(startPath));
|
|
1516
1516
|
let previousPath;
|
|
1517
1517
|
while (previousPath !== currentPath) {
|
|
1518
1518
|
yield currentPath;
|
|
1519
1519
|
previousPath = currentPath;
|
|
1520
|
-
currentPath = path.resolve(currentPath, "..");
|
|
1520
|
+
currentPath = path$1.resolve(currentPath, "..");
|
|
1521
1521
|
}
|
|
1522
1522
|
} };
|
|
1523
1523
|
}
|
|
1524
1524
|
//#endregion
|
|
1525
1525
|
//#region ../../node_modules/.pnpm/npm-run-path@6.0.0/node_modules/npm-run-path/index.js
|
|
1526
1526
|
const npmRunPath = ({ cwd = process$1.cwd(), path: pathOption = process$1.env[pathKey()], preferLocal = true, execPath = process$1.execPath, addExecPath = true } = {}) => {
|
|
1527
|
-
const cwdPath = path.resolve(toPath(cwd));
|
|
1527
|
+
const cwdPath = path$1.resolve(toPath(cwd));
|
|
1528
1528
|
const result = [];
|
|
1529
|
-
const pathParts = pathOption.split(path.delimiter);
|
|
1529
|
+
const pathParts = pathOption.split(path$1.delimiter);
|
|
1530
1530
|
if (preferLocal) applyPreferLocal(result, pathParts, cwdPath);
|
|
1531
1531
|
if (addExecPath) applyExecPath(result, pathParts, execPath, cwdPath);
|
|
1532
|
-
return pathOption === "" || pathOption === path.delimiter ? `${result.join(path.delimiter)}${pathOption}` : [...result, pathOption].join(path.delimiter);
|
|
1532
|
+
return pathOption === "" || pathOption === path$1.delimiter ? `${result.join(path$1.delimiter)}${pathOption}` : [...result, pathOption].join(path$1.delimiter);
|
|
1533
1533
|
};
|
|
1534
1534
|
const applyPreferLocal = (result, pathParts, cwdPath) => {
|
|
1535
1535
|
for (const directory of traversePathUp(cwdPath)) {
|
|
1536
|
-
const pathPart = path.join(directory, "node_modules/.bin");
|
|
1536
|
+
const pathPart = path$1.join(directory, "node_modules/.bin");
|
|
1537
1537
|
if (!pathParts.includes(pathPart)) result.push(pathPart);
|
|
1538
1538
|
}
|
|
1539
1539
|
};
|
|
1540
1540
|
const applyExecPath = (result, pathParts, execPath, cwdPath) => {
|
|
1541
|
-
const pathPart = path.resolve(cwdPath, toPath(execPath), "..");
|
|
1541
|
+
const pathPart = path$1.resolve(cwdPath, toPath(execPath), "..");
|
|
1542
1542
|
if (!pathParts.includes(pathPart)) result.push(pathPart);
|
|
1543
1543
|
};
|
|
1544
1544
|
const npmRunPathEnv = ({ env = process$1.env, ...options } = {}) => {
|
|
@@ -2548,7 +2548,7 @@ const mapNode = ({ options }) => {
|
|
|
2548
2548
|
const handleNodeOption = (file, commandArguments, { node: shouldHandleNode = false, nodePath = execPath, nodeOptions = execArgv.filter((nodeOption) => !nodeOption.startsWith("--inspect")), cwd, execPath: formerNodePath, ...options }) => {
|
|
2549
2549
|
if (formerNodePath !== void 0) throw new TypeError("The \"execPath\" option has been removed. Please use the \"nodePath\" option instead.");
|
|
2550
2550
|
const normalizedNodePath = safeNormalizeFileUrl(nodePath, "The \"nodePath\" option");
|
|
2551
|
-
const resolvedNodePath = path.resolve(cwd, normalizedNodePath);
|
|
2551
|
+
const resolvedNodePath = path$1.resolve(cwd, normalizedNodePath);
|
|
2552
2552
|
const newOptions = {
|
|
2553
2553
|
...options,
|
|
2554
2554
|
nodePath: resolvedNodePath,
|
|
@@ -2560,7 +2560,7 @@ const handleNodeOption = (file, commandArguments, { node: shouldHandleNode = fal
|
|
|
2560
2560
|
commandArguments,
|
|
2561
2561
|
newOptions
|
|
2562
2562
|
];
|
|
2563
|
-
if (path.basename(file, ".exe") === "node") throw new TypeError("When the \"node\" option is true, the first argument does not need to be \"node\".");
|
|
2563
|
+
if (path$1.basename(file, ".exe") === "node") throw new TypeError("When the \"node\" option is true, the first argument does not need to be \"node\".");
|
|
2564
2564
|
return [
|
|
2565
2565
|
resolvedNodePath,
|
|
2566
2566
|
[
|
|
@@ -2644,7 +2644,7 @@ const serializeEncoding = (encoding) => typeof encoding === "string" ? `"${encod
|
|
|
2644
2644
|
//#region ../../node_modules/.pnpm/execa@9.5.2/node_modules/execa/lib/arguments/cwd.js
|
|
2645
2645
|
const normalizeCwd = (cwd = getDefaultCwd()) => {
|
|
2646
2646
|
const cwdString = safeNormalizeFileUrl(cwd, "The \"cwd\" option");
|
|
2647
|
-
return path.resolve(cwdString);
|
|
2647
|
+
return path$1.resolve(cwdString);
|
|
2648
2648
|
};
|
|
2649
2649
|
const getDefaultCwd = () => {
|
|
2650
2650
|
try {
|
|
@@ -2682,7 +2682,7 @@ const normalizeOptions = (filePath, rawArguments, rawOptions) => {
|
|
|
2682
2682
|
options.killSignal = normalizeKillSignal(options.killSignal);
|
|
2683
2683
|
options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);
|
|
2684
2684
|
options.lines = options.lines.map((lines, fdNumber) => lines && !BINARY_ENCODINGS.has(options.encoding) && options.buffer[fdNumber]);
|
|
2685
|
-
if (process$1.platform === "win32" && path.basename(file, ".exe") === "cmd") commandArguments.unshift("/q");
|
|
2685
|
+
if (process$1.platform === "win32" && path$1.basename(file, ".exe") === "cmd") commandArguments.unshift("/q");
|
|
2686
2686
|
return {
|
|
2687
2687
|
file,
|
|
2688
2688
|
commandArguments,
|
|
@@ -10807,21 +10807,21 @@ var mod_esm_default = (/* @__PURE__ */ __toESM(require_mod_cjs())).default;
|
|
|
10807
10807
|
//#region iac/getWranglerLoginAuthToken.ts
|
|
10808
10808
|
const isDirectory = (configPath) => {
|
|
10809
10809
|
try {
|
|
10810
|
-
return fs.statSync(configPath).isDirectory();
|
|
10810
|
+
return fs$1.statSync(configPath).isDirectory();
|
|
10811
10811
|
} catch {
|
|
10812
10812
|
return false;
|
|
10813
10813
|
}
|
|
10814
10814
|
};
|
|
10815
10815
|
const getGlobalWranglerConfigPath = () => {
|
|
10816
10816
|
const configDir = mod_esm_default(".wrangler").config();
|
|
10817
|
-
const legacyConfigDir = path
|
|
10817
|
+
const legacyConfigDir = path.join(os.homedir(), ".wrangler");
|
|
10818
10818
|
if (isDirectory(legacyConfigDir)) return legacyConfigDir;
|
|
10819
10819
|
return configDir;
|
|
10820
10820
|
};
|
|
10821
10821
|
const getWranglerLoginAuthToken = () => {
|
|
10822
10822
|
try {
|
|
10823
10823
|
const wranglerConfigPath = getGlobalWranglerConfigPath();
|
|
10824
|
-
const wranglerConfig = fs.readFileSync(path
|
|
10824
|
+
const wranglerConfig = fs$1.readFileSync(path.join(wranglerConfigPath, "config", "default.toml"), "utf8");
|
|
10825
10825
|
return import_toml.default.parse(wranglerConfig);
|
|
10826
10826
|
} catch {
|
|
10827
10827
|
return null;
|
|
@@ -10867,10 +10867,10 @@ export default HotUpdater.wrap({
|
|
|
10867
10867
|
const deployWorker = async (oauth_token, accountId, { d1DatabaseId, d1DatabaseName, r2BucketName }) => {
|
|
10868
10868
|
const cwd = getCwd();
|
|
10869
10869
|
const cloudflarePackagePath = __require.resolve("@hot-updater/cloudflare/package.json", { paths: [cwd] });
|
|
10870
|
-
const { tmpDir, removeTmpDir } = await copyDirToTmp(path
|
|
10871
|
-
const workerRoot = path
|
|
10870
|
+
const { tmpDir, removeTmpDir } = await copyDirToTmp(path.dirname(cloudflarePackagePath));
|
|
10871
|
+
const workerRoot = path.join(tmpDir, "worker");
|
|
10872
10872
|
try {
|
|
10873
|
-
const wranglerConfig = JSON.parse(await fs
|
|
10873
|
+
const wranglerConfig = JSON.parse(await fs.readFile(path.join(workerRoot, "wrangler.json"), "utf-8"));
|
|
10874
10874
|
wranglerConfig.d1_databases = [{
|
|
10875
10875
|
binding: "DB",
|
|
10876
10876
|
database_id: d1DatabaseId,
|
|
@@ -10881,19 +10881,19 @@ const deployWorker = async (oauth_token, accountId, { d1DatabaseId, d1DatabaseNa
|
|
|
10881
10881
|
bucket_name: r2BucketName
|
|
10882
10882
|
}];
|
|
10883
10883
|
wranglerConfig.vars = { JWT_SECRET: crypto.randomBytes(32).toString("hex") };
|
|
10884
|
-
await fs
|
|
10884
|
+
await fs.writeFile(path.join(workerRoot, "wrangler.json"), JSON.stringify(wranglerConfig, null, 2));
|
|
10885
10885
|
const wrangler = await createWrangler({
|
|
10886
10886
|
stdio: "inherit",
|
|
10887
10887
|
cloudflareApiToken: oauth_token,
|
|
10888
10888
|
cwd: workerRoot,
|
|
10889
10889
|
accountId
|
|
10890
10890
|
});
|
|
10891
|
-
const migrationPath = await path
|
|
10892
|
-
const migrationFiles = await fs
|
|
10891
|
+
const migrationPath = await path.join(workerRoot, "migrations");
|
|
10892
|
+
const migrationFiles = await fs.readdir(migrationPath);
|
|
10893
10893
|
for (const file of migrationFiles) if (file.endsWith(".sql")) {
|
|
10894
|
-
const filePath = path
|
|
10895
|
-
const content = await fs
|
|
10896
|
-
await fs
|
|
10894
|
+
const filePath = path.join(migrationPath, file);
|
|
10895
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
10896
|
+
await fs.writeFile(filePath, transformTemplate(content, { BUCKET_NAME: r2BucketName }));
|
|
10897
10897
|
}
|
|
10898
10898
|
await wrangler("d1", "migrations", "apply", d1DatabaseName, "--remote");
|
|
10899
10899
|
const workerName = await p.text({
|
|
@@ -11058,7 +11058,7 @@ const runInit = async ({ build }) => {
|
|
|
11058
11058
|
d1DatabaseName,
|
|
11059
11059
|
r2BucketName: selectedBucketName
|
|
11060
11060
|
});
|
|
11061
|
-
await fs
|
|
11061
|
+
await fs.writeFile("hot-updater.config.ts", getConfigTemplate(build));
|
|
11062
11062
|
await makeEnv({
|
|
11063
11063
|
HOT_UPDATER_CLOUDFLARE_API_TOKEN: apiToken,
|
|
11064
11064
|
HOT_UPDATER_CLOUDFLARE_ACCOUNT_ID: accountId,
|
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,8 @@ let _hot_updater_core = require("@hot-updater/core");
|
|
|
26
26
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
27
27
|
let cloudflare = require("cloudflare");
|
|
28
28
|
cloudflare = __toESM(cloudflare);
|
|
29
|
+
let path = require("path");
|
|
30
|
+
path = __toESM(path);
|
|
29
31
|
let node_url = require("node:url");
|
|
30
32
|
let node_child_process = require("node:child_process");
|
|
31
33
|
let node_string_decoder = require("node:string_decoder");
|
|
@@ -36,8 +38,6 @@ let node_tty = require("node:tty");
|
|
|
36
38
|
node_tty = __toESM(node_tty);
|
|
37
39
|
let node_path = require("node:path");
|
|
38
40
|
node_path = __toESM(node_path);
|
|
39
|
-
let path = require("path");
|
|
40
|
-
path = __toESM(path);
|
|
41
41
|
let node_timers_promises = require("node:timers/promises");
|
|
42
42
|
let node_os = require("node:os");
|
|
43
43
|
let node_events = require("node:events");
|
|
@@ -378,7 +378,6 @@ function transformRowToBundle(row) {
|
|
|
378
378
|
const d1Database = (0, _hot_updater_plugin_core.createDatabasePlugin)({
|
|
379
379
|
name: "d1Database",
|
|
380
380
|
factory: (config) => {
|
|
381
|
-
let bundles = [];
|
|
382
381
|
const cf = new cloudflare.default({ apiToken: config.cloudflareApiToken });
|
|
383
382
|
async function getTotalCount(conditions) {
|
|
384
383
|
const { sql: whereClause, params } = buildWhereClause(conditions);
|
|
@@ -407,8 +406,6 @@ const d1Database = (0, _hot_updater_plugin_core.createDatabasePlugin)({
|
|
|
407
406
|
}
|
|
408
407
|
return {
|
|
409
408
|
async getBundleById(bundleId) {
|
|
410
|
-
const found = bundles.find((b) => b.id === bundleId);
|
|
411
|
-
if (found) return found;
|
|
412
409
|
const sql = (0, import_lib.default)(`
|
|
413
410
|
SELECT * FROM bundles WHERE id = ? LIMIT 1`);
|
|
414
411
|
const rows = await resolvePage(await cf.d1.database.query(config.databaseId, {
|
|
@@ -422,14 +419,12 @@ const d1Database = (0, _hot_updater_plugin_core.createDatabasePlugin)({
|
|
|
422
419
|
async getBundles(options) {
|
|
423
420
|
const { where = {}, limit, offset, orderBy } = options;
|
|
424
421
|
const totalCount = await getTotalCount(where);
|
|
425
|
-
bundles = await getPaginatedBundles(where, limit, offset, orderBy);
|
|
426
|
-
const pagination = (0, _hot_updater_plugin_core.calculatePagination)(totalCount, {
|
|
427
|
-
limit,
|
|
428
|
-
offset
|
|
429
|
-
});
|
|
430
422
|
return {
|
|
431
|
-
data:
|
|
432
|
-
pagination
|
|
423
|
+
data: await getPaginatedBundles(where, limit, offset, orderBy),
|
|
424
|
+
pagination: (0, _hot_updater_plugin_core.calculatePagination)(totalCount, {
|
|
425
|
+
limit,
|
|
426
|
+
offset
|
|
427
|
+
})
|
|
433
428
|
};
|
|
434
429
|
},
|
|
435
430
|
async getChannels() {
|
|
@@ -453,7 +448,6 @@ const d1Database = (0, _hot_updater_plugin_core.createDatabasePlugin)({
|
|
|
453
448
|
sql: deleteSql,
|
|
454
449
|
params: [op.data.id]
|
|
455
450
|
});
|
|
456
|
-
bundles = bundles.filter((b) => b.id !== op.data.id);
|
|
457
451
|
} else if (op.operation === "insert" || op.operation === "update") {
|
|
458
452
|
const bundle = op.data;
|
|
459
453
|
const upsertSql = (0, import_lib.default)(`
|
package/dist/index.mjs
CHANGED
|
@@ -2,14 +2,14 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { DEFAULT_ROLLOUT_COHORT_COUNT } from "@hot-updater/core";
|
|
3
3
|
import { calculatePagination, createDatabasePlugin, createStorageKeyBuilder, createStoragePlugin, getContentType, parseStorageUri } from "@hot-updater/plugin-core";
|
|
4
4
|
import Cloudflare from "cloudflare";
|
|
5
|
+
import path from "path";
|
|
5
6
|
import { fileURLToPath } from "node:url";
|
|
6
7
|
import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
|
|
7
8
|
import { StringDecoder } from "node:string_decoder";
|
|
8
9
|
import { aborted, callbackify, debuglog, inspect, promisify, stripVTControlCharacters } from "node:util";
|
|
9
10
|
import process$1, { execArgv, execPath, hrtime, platform } from "node:process";
|
|
10
11
|
import tty from "node:tty";
|
|
11
|
-
import path from "node:path";
|
|
12
|
-
import path$1 from "path";
|
|
12
|
+
import path$1 from "node:path";
|
|
13
13
|
import { scheduler, setImmediate, setTimeout } from "node:timers/promises";
|
|
14
14
|
import { constants } from "node:os";
|
|
15
15
|
import { EventEmitter, addAbortListener, on, once, setMaxListeners } from "node:events";
|
|
@@ -374,7 +374,6 @@ function transformRowToBundle(row) {
|
|
|
374
374
|
const d1Database = createDatabasePlugin({
|
|
375
375
|
name: "d1Database",
|
|
376
376
|
factory: (config) => {
|
|
377
|
-
let bundles = [];
|
|
378
377
|
const cf = new Cloudflare({ apiToken: config.cloudflareApiToken });
|
|
379
378
|
async function getTotalCount(conditions) {
|
|
380
379
|
const { sql: whereClause, params } = buildWhereClause(conditions);
|
|
@@ -403,8 +402,6 @@ const d1Database = createDatabasePlugin({
|
|
|
403
402
|
}
|
|
404
403
|
return {
|
|
405
404
|
async getBundleById(bundleId) {
|
|
406
|
-
const found = bundles.find((b) => b.id === bundleId);
|
|
407
|
-
if (found) return found;
|
|
408
405
|
const sql = (0, import_lib.default)(`
|
|
409
406
|
SELECT * FROM bundles WHERE id = ? LIMIT 1`);
|
|
410
407
|
const rows = await resolvePage(await cf.d1.database.query(config.databaseId, {
|
|
@@ -418,14 +415,12 @@ const d1Database = createDatabasePlugin({
|
|
|
418
415
|
async getBundles(options) {
|
|
419
416
|
const { where = {}, limit, offset, orderBy } = options;
|
|
420
417
|
const totalCount = await getTotalCount(where);
|
|
421
|
-
bundles = await getPaginatedBundles(where, limit, offset, orderBy);
|
|
422
|
-
const pagination = calculatePagination(totalCount, {
|
|
423
|
-
limit,
|
|
424
|
-
offset
|
|
425
|
-
});
|
|
426
418
|
return {
|
|
427
|
-
data:
|
|
428
|
-
pagination
|
|
419
|
+
data: await getPaginatedBundles(where, limit, offset, orderBy),
|
|
420
|
+
pagination: calculatePagination(totalCount, {
|
|
421
|
+
limit,
|
|
422
|
+
offset
|
|
423
|
+
})
|
|
429
424
|
};
|
|
430
425
|
},
|
|
431
426
|
async getChannels() {
|
|
@@ -449,7 +444,6 @@ const d1Database = createDatabasePlugin({
|
|
|
449
444
|
sql: deleteSql,
|
|
450
445
|
params: [op.data.id]
|
|
451
446
|
});
|
|
452
|
-
bundles = bundles.filter((b) => b.id !== op.data.id);
|
|
453
447
|
} else if (op.operation === "insert" || op.operation === "update") {
|
|
454
448
|
const bundle = op.data;
|
|
455
449
|
const upsertSql = (0, import_lib.default)(`
|
|
@@ -1669,33 +1663,33 @@ function toPath(urlOrPath) {
|
|
|
1669
1663
|
}
|
|
1670
1664
|
function traversePathUp(startPath) {
|
|
1671
1665
|
return { *[Symbol.iterator]() {
|
|
1672
|
-
let currentPath = path.resolve(toPath(startPath));
|
|
1666
|
+
let currentPath = path$1.resolve(toPath(startPath));
|
|
1673
1667
|
let previousPath;
|
|
1674
1668
|
while (previousPath !== currentPath) {
|
|
1675
1669
|
yield currentPath;
|
|
1676
1670
|
previousPath = currentPath;
|
|
1677
|
-
currentPath = path.resolve(currentPath, "..");
|
|
1671
|
+
currentPath = path$1.resolve(currentPath, "..");
|
|
1678
1672
|
}
|
|
1679
1673
|
} };
|
|
1680
1674
|
}
|
|
1681
1675
|
//#endregion
|
|
1682
1676
|
//#region ../../node_modules/.pnpm/npm-run-path@6.0.0/node_modules/npm-run-path/index.js
|
|
1683
1677
|
const npmRunPath = ({ cwd = process$1.cwd(), path: pathOption = process$1.env[pathKey()], preferLocal = true, execPath = process$1.execPath, addExecPath = true } = {}) => {
|
|
1684
|
-
const cwdPath = path.resolve(toPath(cwd));
|
|
1678
|
+
const cwdPath = path$1.resolve(toPath(cwd));
|
|
1685
1679
|
const result = [];
|
|
1686
|
-
const pathParts = pathOption.split(path.delimiter);
|
|
1680
|
+
const pathParts = pathOption.split(path$1.delimiter);
|
|
1687
1681
|
if (preferLocal) applyPreferLocal(result, pathParts, cwdPath);
|
|
1688
1682
|
if (addExecPath) applyExecPath(result, pathParts, execPath, cwdPath);
|
|
1689
|
-
return pathOption === "" || pathOption === path.delimiter ? `${result.join(path.delimiter)}${pathOption}` : [...result, pathOption].join(path.delimiter);
|
|
1683
|
+
return pathOption === "" || pathOption === path$1.delimiter ? `${result.join(path$1.delimiter)}${pathOption}` : [...result, pathOption].join(path$1.delimiter);
|
|
1690
1684
|
};
|
|
1691
1685
|
const applyPreferLocal = (result, pathParts, cwdPath) => {
|
|
1692
1686
|
for (const directory of traversePathUp(cwdPath)) {
|
|
1693
|
-
const pathPart = path.join(directory, "node_modules/.bin");
|
|
1687
|
+
const pathPart = path$1.join(directory, "node_modules/.bin");
|
|
1694
1688
|
if (!pathParts.includes(pathPart)) result.push(pathPart);
|
|
1695
1689
|
}
|
|
1696
1690
|
};
|
|
1697
1691
|
const applyExecPath = (result, pathParts, execPath, cwdPath) => {
|
|
1698
|
-
const pathPart = path.resolve(cwdPath, toPath(execPath), "..");
|
|
1692
|
+
const pathPart = path$1.resolve(cwdPath, toPath(execPath), "..");
|
|
1699
1693
|
if (!pathParts.includes(pathPart)) result.push(pathPart);
|
|
1700
1694
|
};
|
|
1701
1695
|
const npmRunPathEnv = ({ env = process$1.env, ...options } = {}) => {
|
|
@@ -2705,7 +2699,7 @@ const mapNode = ({ options }) => {
|
|
|
2705
2699
|
const handleNodeOption = (file, commandArguments, { node: shouldHandleNode = false, nodePath = execPath, nodeOptions = execArgv.filter((nodeOption) => !nodeOption.startsWith("--inspect")), cwd, execPath: formerNodePath, ...options }) => {
|
|
2706
2700
|
if (formerNodePath !== void 0) throw new TypeError("The \"execPath\" option has been removed. Please use the \"nodePath\" option instead.");
|
|
2707
2701
|
const normalizedNodePath = safeNormalizeFileUrl(nodePath, "The \"nodePath\" option");
|
|
2708
|
-
const resolvedNodePath = path.resolve(cwd, normalizedNodePath);
|
|
2702
|
+
const resolvedNodePath = path$1.resolve(cwd, normalizedNodePath);
|
|
2709
2703
|
const newOptions = {
|
|
2710
2704
|
...options,
|
|
2711
2705
|
nodePath: resolvedNodePath,
|
|
@@ -2717,7 +2711,7 @@ const handleNodeOption = (file, commandArguments, { node: shouldHandleNode = fal
|
|
|
2717
2711
|
commandArguments,
|
|
2718
2712
|
newOptions
|
|
2719
2713
|
];
|
|
2720
|
-
if (path.basename(file, ".exe") === "node") throw new TypeError("When the \"node\" option is true, the first argument does not need to be \"node\".");
|
|
2714
|
+
if (path$1.basename(file, ".exe") === "node") throw new TypeError("When the \"node\" option is true, the first argument does not need to be \"node\".");
|
|
2721
2715
|
return [
|
|
2722
2716
|
resolvedNodePath,
|
|
2723
2717
|
[
|
|
@@ -2801,7 +2795,7 @@ const serializeEncoding = (encoding) => typeof encoding === "string" ? `"${encod
|
|
|
2801
2795
|
//#region ../../node_modules/.pnpm/execa@9.5.2/node_modules/execa/lib/arguments/cwd.js
|
|
2802
2796
|
const normalizeCwd = (cwd = getDefaultCwd()) => {
|
|
2803
2797
|
const cwdString = safeNormalizeFileUrl(cwd, "The \"cwd\" option");
|
|
2804
|
-
return path.resolve(cwdString);
|
|
2798
|
+
return path$1.resolve(cwdString);
|
|
2805
2799
|
};
|
|
2806
2800
|
const getDefaultCwd = () => {
|
|
2807
2801
|
try {
|
|
@@ -2839,7 +2833,7 @@ const normalizeOptions = (filePath, rawArguments, rawOptions) => {
|
|
|
2839
2833
|
options.killSignal = normalizeKillSignal(options.killSignal);
|
|
2840
2834
|
options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);
|
|
2841
2835
|
options.lines = options.lines.map((lines, fdNumber) => lines && !BINARY_ENCODINGS.has(options.encoding) && options.buffer[fdNumber]);
|
|
2842
|
-
if (process$1.platform === "win32" && path.basename(file, ".exe") === "cmd") commandArguments.unshift("/q");
|
|
2836
|
+
if (process$1.platform === "win32" && path$1.basename(file, ".exe") === "cmd") commandArguments.unshift("/q");
|
|
2843
2837
|
return {
|
|
2844
2838
|
file,
|
|
2845
2839
|
commandArguments,
|
|
@@ -6718,7 +6712,7 @@ const r2Storage = createStoragePlugin({
|
|
|
6718
6712
|
},
|
|
6719
6713
|
async upload(key, filePath) {
|
|
6720
6714
|
const contentType = getContentType(filePath);
|
|
6721
|
-
const Key = getStorageKey(key, path
|
|
6715
|
+
const Key = getStorageKey(key, path.basename(filePath));
|
|
6722
6716
|
try {
|
|
6723
6717
|
const { stderr, exitCode } = await wrangler("r2", "object", "put", [bucketName, Key].join("/"), "--file", filePath, "--content-type", contentType, "--remote");
|
|
6724
6718
|
if (exitCode !== 0 && stderr) throw new Error(stderr);
|
package/dist/worker/index.cjs
CHANGED
|
@@ -105,7 +105,6 @@ const resolveDbFromContext = (context) => {
|
|
|
105
105
|
const d1WorkerDatabase = () => (0, _hot_updater_plugin_core.createDatabasePlugin)({
|
|
106
106
|
name: "d1WorkerDatabase",
|
|
107
107
|
factory: (config) => {
|
|
108
|
-
let bundles = [];
|
|
109
108
|
const queryAll = async (sql, params = [], context) => {
|
|
110
109
|
return (await config.getDb(context).prepare(sql).bind(...params).all()).results ?? [];
|
|
111
110
|
};
|
|
@@ -114,8 +113,6 @@ const d1WorkerDatabase = () => (0, _hot_updater_plugin_core.createDatabasePlugin
|
|
|
114
113
|
};
|
|
115
114
|
return {
|
|
116
115
|
async getBundleById(bundleId, context) {
|
|
117
|
-
const found = bundles.find((bundle) => bundle.id === bundleId);
|
|
118
|
-
if (found) return found;
|
|
119
116
|
const row = await queryFirst("SELECT * FROM bundles WHERE id = ? LIMIT 1", [bundleId], context);
|
|
120
117
|
return row ? transformRowToBundle(row) : null;
|
|
121
118
|
},
|
|
@@ -124,13 +121,12 @@ const d1WorkerDatabase = () => (0, _hot_updater_plugin_core.createDatabasePlugin
|
|
|
124
121
|
const { sql: whereClause, params } = buildWhereClause(where);
|
|
125
122
|
const orderSql = orderBy?.direction === "asc" ? "ORDER BY id ASC" : "ORDER BY id DESC";
|
|
126
123
|
const total = (await queryAll(`SELECT COUNT(*) as total FROM bundles${whereClause}`, params, context))[0]?.total ?? 0;
|
|
127
|
-
bundles = (await queryAll(`SELECT * FROM bundles${whereClause} ${orderSql} LIMIT ? OFFSET ?`, [
|
|
128
|
-
...params,
|
|
129
|
-
limit,
|
|
130
|
-
offset
|
|
131
|
-
], context)).map(transformRowToBundle);
|
|
132
124
|
return {
|
|
133
|
-
data: bundles
|
|
125
|
+
data: (await queryAll(`SELECT * FROM bundles${whereClause} ${orderSql} LIMIT ? OFFSET ?`, [
|
|
126
|
+
...params,
|
|
127
|
+
limit,
|
|
128
|
+
offset
|
|
129
|
+
], context)).map(transformRowToBundle),
|
|
134
130
|
pagination: (0, _hot_updater_plugin_core.calculatePagination)(total, {
|
|
135
131
|
limit,
|
|
136
132
|
offset
|
|
@@ -146,7 +142,6 @@ const d1WorkerDatabase = () => (0, _hot_updater_plugin_core.createDatabasePlugin
|
|
|
146
142
|
for (const operation of changedSets) {
|
|
147
143
|
if (operation.operation === "delete") {
|
|
148
144
|
await db.prepare("DELETE FROM bundles WHERE id = ?").bind(operation.data.id).run();
|
|
149
|
-
bundles = bundles.filter((bundle) => bundle.id !== operation.data.id);
|
|
150
145
|
continue;
|
|
151
146
|
}
|
|
152
147
|
const bundle = operation.data;
|
package/dist/worker/index.mjs
CHANGED
|
@@ -104,7 +104,6 @@ const resolveDbFromContext = (context) => {
|
|
|
104
104
|
const d1WorkerDatabase = () => createDatabasePlugin({
|
|
105
105
|
name: "d1WorkerDatabase",
|
|
106
106
|
factory: (config) => {
|
|
107
|
-
let bundles = [];
|
|
108
107
|
const queryAll = async (sql, params = [], context) => {
|
|
109
108
|
return (await config.getDb(context).prepare(sql).bind(...params).all()).results ?? [];
|
|
110
109
|
};
|
|
@@ -113,8 +112,6 @@ const d1WorkerDatabase = () => createDatabasePlugin({
|
|
|
113
112
|
};
|
|
114
113
|
return {
|
|
115
114
|
async getBundleById(bundleId, context) {
|
|
116
|
-
const found = bundles.find((bundle) => bundle.id === bundleId);
|
|
117
|
-
if (found) return found;
|
|
118
115
|
const row = await queryFirst("SELECT * FROM bundles WHERE id = ? LIMIT 1", [bundleId], context);
|
|
119
116
|
return row ? transformRowToBundle(row) : null;
|
|
120
117
|
},
|
|
@@ -123,13 +120,12 @@ const d1WorkerDatabase = () => createDatabasePlugin({
|
|
|
123
120
|
const { sql: whereClause, params } = buildWhereClause(where);
|
|
124
121
|
const orderSql = orderBy?.direction === "asc" ? "ORDER BY id ASC" : "ORDER BY id DESC";
|
|
125
122
|
const total = (await queryAll(`SELECT COUNT(*) as total FROM bundles${whereClause}`, params, context))[0]?.total ?? 0;
|
|
126
|
-
bundles = (await queryAll(`SELECT * FROM bundles${whereClause} ${orderSql} LIMIT ? OFFSET ?`, [
|
|
127
|
-
...params,
|
|
128
|
-
limit,
|
|
129
|
-
offset
|
|
130
|
-
], context)).map(transformRowToBundle);
|
|
131
123
|
return {
|
|
132
|
-
data: bundles
|
|
124
|
+
data: (await queryAll(`SELECT * FROM bundles${whereClause} ${orderSql} LIMIT ? OFFSET ?`, [
|
|
125
|
+
...params,
|
|
126
|
+
limit,
|
|
127
|
+
offset
|
|
128
|
+
], context)).map(transformRowToBundle),
|
|
133
129
|
pagination: calculatePagination(total, {
|
|
134
130
|
limit,
|
|
135
131
|
offset
|
|
@@ -145,7 +141,6 @@ const d1WorkerDatabase = () => createDatabasePlugin({
|
|
|
145
141
|
for (const operation of changedSets) {
|
|
146
142
|
if (operation.operation === "delete") {
|
|
147
143
|
await db.prepare("DELETE FROM bundles WHERE id = ?").bind(operation.data.id).run();
|
|
148
|
-
bundles = bundles.filter((bundle) => bundle.id !== operation.data.id);
|
|
149
144
|
continue;
|
|
150
145
|
}
|
|
151
146
|
const bundle = operation.data;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/cloudflare",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.29.
|
|
4
|
+
"version": "0.29.4",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
"cloudflare": "4.2.0",
|
|
51
51
|
"hono": "4.12.9",
|
|
52
52
|
"uuidv7": "^1.0.2",
|
|
53
|
-
"@hot-updater/cli-tools": "0.29.
|
|
54
|
-
"@hot-updater/core": "0.29.
|
|
55
|
-
"@hot-updater/js": "0.29.
|
|
56
|
-
"@hot-updater/plugin-core": "0.29.
|
|
57
|
-
"@hot-updater/server": "0.29.
|
|
53
|
+
"@hot-updater/cli-tools": "0.29.4",
|
|
54
|
+
"@hot-updater/core": "0.29.4",
|
|
55
|
+
"@hot-updater/js": "0.29.4",
|
|
56
|
+
"@hot-updater/plugin-core": "0.29.4",
|
|
57
|
+
"@hot-updater/server": "0.29.4"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@cloudflare/vitest-pool-workers": "0.13.0",
|
|
@@ -67,11 +67,11 @@
|
|
|
67
67
|
"pg-minify": "^1.6.5",
|
|
68
68
|
"semver": "^7.6.3",
|
|
69
69
|
"toml": "^3.0.0",
|
|
70
|
-
"typescript": "^
|
|
70
|
+
"typescript": "^6.0.2",
|
|
71
71
|
"vitest": "4.1.0",
|
|
72
72
|
"wrangler": "^4.5.0",
|
|
73
73
|
"xdg-app-paths": "^8.3.0",
|
|
74
|
-
"@hot-updater/test-utils": "0.29.
|
|
74
|
+
"@hot-updater/test-utils": "0.29.4"
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|
|
77
77
|
"build": "tsdown && pnpm build:worker",
|
|
@@ -203,14 +203,12 @@ const resolveDbFromContext = (
|
|
|
203
203
|
};
|
|
204
204
|
|
|
205
205
|
export const d1WorkerDatabase = <
|
|
206
|
-
TContext extends
|
|
207
|
-
RequestEnvContext<CloudflareWorkerDatabaseEnv
|
|
206
|
+
TContext extends RequestEnvContext<CloudflareWorkerDatabaseEnv> =
|
|
207
|
+
RequestEnvContext<CloudflareWorkerDatabaseEnv>,
|
|
208
208
|
>() =>
|
|
209
209
|
createDatabasePlugin<CloudflareWorkerDatabaseConfig<TContext>, TContext>({
|
|
210
210
|
name: "d1WorkerDatabase",
|
|
211
211
|
factory: (config) => {
|
|
212
|
-
let bundles: Bundle[] = [];
|
|
213
|
-
|
|
214
212
|
const queryAll = async <TRow>(
|
|
215
213
|
sql: string,
|
|
216
214
|
params: unknown[] = [],
|
|
@@ -239,11 +237,6 @@ export const d1WorkerDatabase = <
|
|
|
239
237
|
|
|
240
238
|
return {
|
|
241
239
|
async getBundleById(bundleId, context) {
|
|
242
|
-
const found = bundles.find((bundle) => bundle.id === bundleId);
|
|
243
|
-
if (found) {
|
|
244
|
-
return found;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
240
|
const row = await queryFirst<SnakeCaseBundle>(
|
|
248
241
|
"SELECT * FROM bundles WHERE id = ? LIMIT 1",
|
|
249
242
|
[bundleId],
|
|
@@ -274,7 +267,7 @@ export const d1WorkerDatabase = <
|
|
|
274
267
|
context,
|
|
275
268
|
);
|
|
276
269
|
|
|
277
|
-
bundles = rows.map(transformRowToBundle);
|
|
270
|
+
const bundles = rows.map(transformRowToBundle);
|
|
278
271
|
|
|
279
272
|
const paginationOptions: PaginationOptions = { limit, offset };
|
|
280
273
|
return {
|
|
@@ -305,9 +298,6 @@ export const d1WorkerDatabase = <
|
|
|
305
298
|
.prepare("DELETE FROM bundles WHERE id = ?")
|
|
306
299
|
.bind(operation.data.id)
|
|
307
300
|
.run();
|
|
308
|
-
bundles = bundles.filter(
|
|
309
|
-
(bundle) => bundle.id !== operation.data.id,
|
|
310
|
-
);
|
|
311
301
|
continue;
|
|
312
302
|
}
|
|
313
303
|
|