@hot-updater/cloudflare 0.21.10 → 0.21.12

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/index.cjs CHANGED
@@ -339,86 +339,88 @@ function transformRowToBundle(row) {
339
339
  metadata: row?.metadata ? JSON.parse(row?.metadata) : {}
340
340
  };
341
341
  }
342
- const d1Database = (config, hooks) => {
343
- let bundles = [];
344
- async function getTotalCount(context, conditions) {
345
- const { sql: whereClause, params } = buildWhereClause(conditions);
346
- const countSql = (0, import_lib.default)(`SELECT COUNT(*) as total FROM bundles${whereClause}`);
347
- return (await resolvePage(await context.cf.d1.database.query(config.databaseId, {
348
- account_id: config.accountId,
349
- sql: countSql,
350
- params
351
- })))[0]?.total || 0;
352
- }
353
- async function getPaginatedBundles(context, conditions, limit, offset) {
354
- const { sql: whereClause, params } = buildWhereClause(conditions);
355
- const sql = (0, import_lib.default)(`
342
+ const d1Database = (0, __hot_updater_plugin_core.createDatabasePlugin)({
343
+ name: "d1Database",
344
+ factory: (config) => {
345
+ let bundles = [];
346
+ const cf = new cloudflare.default({ apiToken: config.cloudflareApiToken });
347
+ async function getTotalCount(conditions) {
348
+ const { sql: whereClause, params } = buildWhereClause(conditions);
349
+ const countSql = (0, import_lib.default)(`SELECT COUNT(*) as total FROM bundles${whereClause}`);
350
+ return (await resolvePage(await cf.d1.database.query(config.databaseId, {
351
+ account_id: config.accountId,
352
+ sql: countSql,
353
+ params
354
+ })))[0]?.total || 0;
355
+ }
356
+ async function getPaginatedBundles(conditions, limit, offset) {
357
+ const { sql: whereClause, params } = buildWhereClause(conditions);
358
+ const sql = (0, import_lib.default)(`
356
359
  SELECT * FROM bundles
357
360
  ${whereClause}
358
361
  ORDER BY id DESC
359
362
  LIMIT ?
360
363
  OFFSET ?
361
364
  `);
362
- params.push(limit, offset);
363
- return (await resolvePage(await context.cf.d1.database.query(config.databaseId, {
364
- account_id: config.accountId,
365
- sql,
366
- params
367
- }))).map(transformRowToBundle);
368
- }
369
- return (0, __hot_updater_plugin_core.createDatabasePlugin)("d1Database", {
370
- getContext: () => ({ cf: new cloudflare.default({ apiToken: config.cloudflareApiToken }) }),
371
- async getBundleById(context, bundleId) {
372
- const found = bundles.find((b) => b.id === bundleId);
373
- if (found) return found;
374
- const sql = (0, import_lib.default)(`
375
- SELECT * FROM bundles WHERE id = ? LIMIT 1`);
376
- const rows = await resolvePage(await context.cf.d1.database.query(config.databaseId, {
365
+ params.push(limit, offset);
366
+ return (await resolvePage(await cf.d1.database.query(config.databaseId, {
377
367
  account_id: config.accountId,
378
368
  sql,
379
- params: [bundleId]
380
- }));
381
- if (rows.length === 0) return null;
382
- return transformRowToBundle(rows[0]);
383
- },
384
- async getBundles(context, options) {
385
- const { where = {}, limit, offset } = options;
386
- const totalCount = await getTotalCount(context, where);
387
- bundles = await getPaginatedBundles(context, where, limit, offset);
388
- const pagination = (0, __hot_updater_plugin_core.calculatePagination)(totalCount, {
389
- limit,
390
- offset
391
- });
392
- return {
393
- data: bundles,
394
- pagination
395
- };
396
- },
397
- async getChannels(context) {
398
- const sql = (0, import_lib.default)(`
369
+ params
370
+ }))).map(transformRowToBundle);
371
+ }
372
+ return {
373
+ async getBundleById(bundleId) {
374
+ const found = bundles.find((b) => b.id === bundleId);
375
+ if (found) return found;
376
+ const sql = (0, import_lib.default)(`
377
+ SELECT * FROM bundles WHERE id = ? LIMIT 1`);
378
+ const rows = await resolvePage(await cf.d1.database.query(config.databaseId, {
379
+ account_id: config.accountId,
380
+ sql,
381
+ params: [bundleId]
382
+ }));
383
+ if (rows.length === 0) return null;
384
+ return transformRowToBundle(rows[0]);
385
+ },
386
+ async getBundles(options) {
387
+ const { where = {}, limit, offset } = options;
388
+ const totalCount = await getTotalCount(where);
389
+ bundles = await getPaginatedBundles(where, limit, offset);
390
+ const pagination = (0, __hot_updater_plugin_core.calculatePagination)(totalCount, {
391
+ limit,
392
+ offset
393
+ });
394
+ return {
395
+ data: bundles,
396
+ pagination
397
+ };
398
+ },
399
+ async getChannels() {
400
+ const sql = (0, import_lib.default)(`
399
401
  SELECT channel FROM bundles GROUP BY channel
400
402
  `);
401
- return (await resolvePage(await context.cf.d1.database.query(config.databaseId, {
402
- account_id: config.accountId,
403
- sql,
404
- params: []
405
- }))).map((row) => row.channel);
406
- },
407
- async commitBundle(context, { changedSets }) {
408
- if (changedSets.length === 0) return;
409
- for (const op of changedSets) if (op.operation === "delete") {
410
- const deleteSql = (0, import_lib.default)(`
403
+ return (await resolvePage(await cf.d1.database.query(config.databaseId, {
404
+ account_id: config.accountId,
405
+ sql,
406
+ params: []
407
+ }))).map((row) => row.channel);
408
+ },
409
+ async commitBundle({ changedSets }) {
410
+ if (changedSets.length === 0) return;
411
+ for (const op of changedSets) if (op.operation === "delete") {
412
+ const deleteSql = (0, import_lib.default)(`
411
413
  DELETE FROM bundles WHERE id = ?
412
414
  `);
413
- await context.cf.d1.database.query(config.databaseId, {
414
- account_id: config.accountId,
415
- sql: deleteSql,
416
- params: [op.data.id]
417
- });
418
- bundles = bundles.filter((b) => b.id !== op.data.id);
419
- } else if (op.operation === "insert" || op.operation === "update") {
420
- const bundle = op.data;
421
- const upsertSql = (0, import_lib.default)(`
415
+ await cf.d1.database.query(config.databaseId, {
416
+ account_id: config.accountId,
417
+ sql: deleteSql,
418
+ params: [op.data.id]
419
+ });
420
+ bundles = bundles.filter((b) => b.id !== op.data.id);
421
+ } else if (op.operation === "insert" || op.operation === "update") {
422
+ const bundle = op.data;
423
+ const upsertSql = (0, import_lib.default)(`
422
424
  INSERT OR REPLACE INTO bundles (
423
425
  id,
424
426
  channel,
@@ -435,30 +437,30 @@ const d1Database = (config, hooks) => {
435
437
  )
436
438
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
437
439
  `);
438
- const params = [
439
- bundle.id,
440
- bundle.channel,
441
- bundle.enabled ? 1 : 0,
442
- bundle.shouldForceUpdate ? 1 : 0,
443
- bundle.fileHash,
444
- bundle.gitCommitHash || null,
445
- bundle.message || null,
446
- bundle.platform,
447
- bundle.targetAppVersion,
448
- bundle.storageUri,
449
- bundle.fingerprintHash,
450
- bundle.metadata ? JSON.stringify(bundle.metadata) : JSON.stringify({})
451
- ];
452
- await context.cf.d1.database.query(config.databaseId, {
453
- account_id: config.accountId,
454
- sql: upsertSql,
455
- params
456
- });
440
+ const params = [
441
+ bundle.id,
442
+ bundle.channel,
443
+ bundle.enabled ? 1 : 0,
444
+ bundle.shouldForceUpdate ? 1 : 0,
445
+ bundle.fileHash,
446
+ bundle.gitCommitHash || null,
447
+ bundle.message || null,
448
+ bundle.platform,
449
+ bundle.targetAppVersion,
450
+ bundle.storageUri,
451
+ bundle.fingerprintHash,
452
+ bundle.metadata ? JSON.stringify(bundle.metadata) : JSON.stringify({})
453
+ ];
454
+ await cf.d1.database.query(config.databaseId, {
455
+ account_id: config.accountId,
456
+ sql: upsertSql,
457
+ params
458
+ });
459
+ }
457
460
  }
458
- hooks?.onDatabaseUpdated?.();
459
- }
460
- }, hooks);
461
- };
461
+ };
462
+ }
463
+ });
462
464
 
463
465
  //#endregion
464
466
  //#region ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
@@ -6812,44 +6814,45 @@ const createWrangler = ({ stdio, accountId, cloudflareApiToken, cwd }) => {
6812
6814
  * })
6813
6815
  * ```
6814
6816
  */
6815
- const r2Storage = (config, hooks) => (_) => {
6816
- const { bucketName, cloudflareApiToken, accountId } = config;
6817
- const wrangler = createWrangler({
6818
- accountId,
6819
- cloudflareApiToken,
6820
- cwd: process.cwd()
6821
- });
6822
- const getStorageKey = (0, __hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
6823
- return {
6824
- name: "r2Storage",
6825
- supportedProtocol: "r2",
6826
- async delete(storageUri) {
6827
- const { bucket, key } = (0, __hot_updater_plugin_core.parseStorageUri)(storageUri, "r2");
6828
- if (bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${bucket}".`);
6829
- try {
6830
- await wrangler("r2", "object", "delete", [bucketName, key].join("/"), "--remote");
6831
- } catch {
6832
- throw new Error("Can not delete bundle");
6833
- }
6834
- },
6835
- async upload(key, filePath) {
6836
- const contentType = (0, __hot_updater_plugin_core.getContentType)(filePath);
6837
- const Key = getStorageKey(key, path.default.basename(filePath));
6838
- try {
6839
- const { stderr, exitCode } = await wrangler("r2", "object", "put", [bucketName, Key].join("/"), "--file", filePath, "--content-type", contentType, "--remote");
6840
- if (exitCode !== 0 && stderr) throw new Error(stderr);
6841
- } catch (error$1) {
6842
- if (error$1 instanceof ExecaError) throw new Error(error$1.stderr || error$1.stdout);
6843
- throw error$1;
6817
+ const r2Storage = (0, __hot_updater_plugin_core.createStoragePlugin)({
6818
+ name: "r2Storage",
6819
+ supportedProtocol: "r2",
6820
+ factory: (config) => {
6821
+ const { bucketName, cloudflareApiToken, accountId } = config;
6822
+ const wrangler = createWrangler({
6823
+ accountId,
6824
+ cloudflareApiToken,
6825
+ cwd: process.cwd()
6826
+ });
6827
+ const getStorageKey = (0, __hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
6828
+ return {
6829
+ async delete(storageUri) {
6830
+ const { bucket, key } = (0, __hot_updater_plugin_core.parseStorageUri)(storageUri, "r2");
6831
+ if (bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${bucket}".`);
6832
+ try {
6833
+ await wrangler("r2", "object", "delete", [bucketName, key].join("/"), "--remote");
6834
+ } catch {
6835
+ throw new Error("Can not delete bundle");
6836
+ }
6837
+ },
6838
+ async upload(key, filePath) {
6839
+ const contentType = (0, __hot_updater_plugin_core.getContentType)(filePath);
6840
+ const Key = getStorageKey(key, path.default.basename(filePath));
6841
+ try {
6842
+ const { stderr, exitCode } = await wrangler("r2", "object", "put", [bucketName, Key].join("/"), "--file", filePath, "--content-type", contentType, "--remote");
6843
+ if (exitCode !== 0 && stderr) throw new Error(stderr);
6844
+ } catch (error$1) {
6845
+ if (error$1 instanceof ExecaError) throw new Error(error$1.stderr || error$1.stdout);
6846
+ throw error$1;
6847
+ }
6848
+ return { storageUri: `r2://${bucketName}/${Key}` };
6849
+ },
6850
+ async getDownloadUrl() {
6851
+ throw new Error("`r2Storage` does not support `getDownloadUrl()`. Use `s3Storage` from `@hot-updater/aws` instead (compatible with Cloudflare R2).\n\nExample:\ns3Storage({\n region: 'auto',\n endpoint: 'https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com',\n credentials: {\n accessKeyId: 'YOUR_ACCESS_KEY_ID',\n secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',\n },\n bucketName: 'YOUR_BUCKET_NAME',\n})");
6844
6852
  }
6845
- hooks?.onStorageUploaded?.();
6846
- return { storageUri: `r2://${bucketName}/${Key}` };
6847
- },
6848
- async getDownloadUrl() {
6849
- throw new Error("`r2Storage` does not support `getDownloadUrl()`. Use `s3Storage` from `@hot-updater/aws` instead (compatible with Cloudflare R2).\n\nExample:\ns3Storage({\n region: 'auto',\n endpoint: 'https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com',\n credentials: {\n accessKeyId: 'YOUR_ACCESS_KEY_ID',\n secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',\n },\n bucketName: 'YOUR_BUCKET_NAME',\n})");
6850
- }
6851
- };
6852
- };
6853
+ };
6854
+ }
6855
+ });
6853
6856
 
6854
6857
  //#endregion
6855
6858
  exports.d1Database = d1Database;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
- import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
2
- import { BasePluginArgs, DatabasePluginHooks, StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
1
+ import * as _hot_updater_plugin_core1 from "@hot-updater/plugin-core";
3
2
 
4
3
  //#region src/d1Database.d.ts
5
4
  interface D1DatabaseConfig {
@@ -7,7 +6,7 @@ interface D1DatabaseConfig {
7
6
  accountId: string;
8
7
  cloudflareApiToken: string;
9
8
  }
10
- declare const d1Database: (config: D1DatabaseConfig, hooks?: DatabasePluginHooks) => (options: _hot_updater_plugin_core0.BasePluginArgs) => _hot_updater_plugin_core0.DatabasePlugin;
9
+ declare const d1Database: (config: D1DatabaseConfig, hooks?: _hot_updater_plugin_core1.DatabasePluginHooks) => (() => _hot_updater_plugin_core1.DatabasePlugin);
11
10
  //#endregion
12
11
  //#region src/r2Storage.d.ts
13
12
  interface R2StorageConfig {
@@ -42,6 +41,6 @@ interface R2StorageConfig {
42
41
  * })
43
42
  * ```
44
43
  */
45
- declare const r2Storage: (config: R2StorageConfig, hooks?: StoragePluginHooks) => (_: BasePluginArgs) => StoragePlugin;
44
+ declare const r2Storage: (config: R2StorageConfig, hooks?: _hot_updater_plugin_core1.StoragePluginHooks) => () => _hot_updater_plugin_core1.StoragePlugin;
46
45
  //#endregion
47
46
  export { D1DatabaseConfig, R2StorageConfig, d1Database, r2Storage };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
2
- import { BasePluginArgs, DatabasePluginHooks, StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
1
+ import * as _hot_updater_plugin_core1 from "@hot-updater/plugin-core";
3
2
 
4
3
  //#region src/d1Database.d.ts
5
4
  interface D1DatabaseConfig {
@@ -7,7 +6,7 @@ interface D1DatabaseConfig {
7
6
  accountId: string;
8
7
  cloudflareApiToken: string;
9
8
  }
10
- declare const d1Database: (config: D1DatabaseConfig, hooks?: DatabasePluginHooks) => (options: _hot_updater_plugin_core0.BasePluginArgs) => _hot_updater_plugin_core0.DatabasePlugin;
9
+ declare const d1Database: (config: D1DatabaseConfig, hooks?: _hot_updater_plugin_core1.DatabasePluginHooks) => (() => _hot_updater_plugin_core1.DatabasePlugin);
11
10
  //#endregion
12
11
  //#region src/r2Storage.d.ts
13
12
  interface R2StorageConfig {
@@ -42,6 +41,6 @@ interface R2StorageConfig {
42
41
  * })
43
42
  * ```
44
43
  */
45
- declare const r2Storage: (config: R2StorageConfig, hooks?: StoragePluginHooks) => (_: BasePluginArgs) => StoragePlugin;
44
+ declare const r2Storage: (config: R2StorageConfig, hooks?: _hot_updater_plugin_core1.StoragePluginHooks) => () => _hot_updater_plugin_core1.StoragePlugin;
46
45
  //#endregion
47
46
  export { D1DatabaseConfig, R2StorageConfig, d1Database, r2Storage };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { calculatePagination, createDatabasePlugin, createStorageKeyBuilder, getContentType, parseStorageUri } from "@hot-updater/plugin-core";
2
+ import { calculatePagination, createDatabasePlugin, createStorageKeyBuilder, createStoragePlugin, getContentType, parseStorageUri } from "@hot-updater/plugin-core";
3
3
  import Cloudflare from "cloudflare";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
@@ -323,86 +323,88 @@ function transformRowToBundle(row) {
323
323
  metadata: row?.metadata ? JSON.parse(row?.metadata) : {}
324
324
  };
325
325
  }
326
- const d1Database = (config, hooks) => {
327
- let bundles = [];
328
- async function getTotalCount(context, conditions) {
329
- const { sql: whereClause, params } = buildWhereClause(conditions);
330
- const countSql = (0, import_lib.default)(`SELECT COUNT(*) as total FROM bundles${whereClause}`);
331
- return (await resolvePage(await context.cf.d1.database.query(config.databaseId, {
332
- account_id: config.accountId,
333
- sql: countSql,
334
- params
335
- })))[0]?.total || 0;
336
- }
337
- async function getPaginatedBundles(context, conditions, limit, offset) {
338
- const { sql: whereClause, params } = buildWhereClause(conditions);
339
- const sql = (0, import_lib.default)(`
326
+ const d1Database = createDatabasePlugin({
327
+ name: "d1Database",
328
+ factory: (config) => {
329
+ let bundles = [];
330
+ const cf = new Cloudflare({ apiToken: config.cloudflareApiToken });
331
+ async function getTotalCount(conditions) {
332
+ const { sql: whereClause, params } = buildWhereClause(conditions);
333
+ const countSql = (0, import_lib.default)(`SELECT COUNT(*) as total FROM bundles${whereClause}`);
334
+ return (await resolvePage(await cf.d1.database.query(config.databaseId, {
335
+ account_id: config.accountId,
336
+ sql: countSql,
337
+ params
338
+ })))[0]?.total || 0;
339
+ }
340
+ async function getPaginatedBundles(conditions, limit, offset) {
341
+ const { sql: whereClause, params } = buildWhereClause(conditions);
342
+ const sql = (0, import_lib.default)(`
340
343
  SELECT * FROM bundles
341
344
  ${whereClause}
342
345
  ORDER BY id DESC
343
346
  LIMIT ?
344
347
  OFFSET ?
345
348
  `);
346
- params.push(limit, offset);
347
- return (await resolvePage(await context.cf.d1.database.query(config.databaseId, {
348
- account_id: config.accountId,
349
- sql,
350
- params
351
- }))).map(transformRowToBundle);
352
- }
353
- return createDatabasePlugin("d1Database", {
354
- getContext: () => ({ cf: new Cloudflare({ apiToken: config.cloudflareApiToken }) }),
355
- async getBundleById(context, bundleId) {
356
- const found = bundles.find((b) => b.id === bundleId);
357
- if (found) return found;
358
- const sql = (0, import_lib.default)(`
359
- SELECT * FROM bundles WHERE id = ? LIMIT 1`);
360
- const rows = await resolvePage(await context.cf.d1.database.query(config.databaseId, {
349
+ params.push(limit, offset);
350
+ return (await resolvePage(await cf.d1.database.query(config.databaseId, {
361
351
  account_id: config.accountId,
362
352
  sql,
363
- params: [bundleId]
364
- }));
365
- if (rows.length === 0) return null;
366
- return transformRowToBundle(rows[0]);
367
- },
368
- async getBundles(context, options) {
369
- const { where = {}, limit, offset } = options;
370
- const totalCount = await getTotalCount(context, where);
371
- bundles = await getPaginatedBundles(context, where, limit, offset);
372
- const pagination = calculatePagination(totalCount, {
373
- limit,
374
- offset
375
- });
376
- return {
377
- data: bundles,
378
- pagination
379
- };
380
- },
381
- async getChannels(context) {
382
- const sql = (0, import_lib.default)(`
353
+ params
354
+ }))).map(transformRowToBundle);
355
+ }
356
+ return {
357
+ async getBundleById(bundleId) {
358
+ const found = bundles.find((b) => b.id === bundleId);
359
+ if (found) return found;
360
+ const sql = (0, import_lib.default)(`
361
+ SELECT * FROM bundles WHERE id = ? LIMIT 1`);
362
+ const rows = await resolvePage(await cf.d1.database.query(config.databaseId, {
363
+ account_id: config.accountId,
364
+ sql,
365
+ params: [bundleId]
366
+ }));
367
+ if (rows.length === 0) return null;
368
+ return transformRowToBundle(rows[0]);
369
+ },
370
+ async getBundles(options) {
371
+ const { where = {}, limit, offset } = options;
372
+ const totalCount = await getTotalCount(where);
373
+ bundles = await getPaginatedBundles(where, limit, offset);
374
+ const pagination = calculatePagination(totalCount, {
375
+ limit,
376
+ offset
377
+ });
378
+ return {
379
+ data: bundles,
380
+ pagination
381
+ };
382
+ },
383
+ async getChannels() {
384
+ const sql = (0, import_lib.default)(`
383
385
  SELECT channel FROM bundles GROUP BY channel
384
386
  `);
385
- return (await resolvePage(await context.cf.d1.database.query(config.databaseId, {
386
- account_id: config.accountId,
387
- sql,
388
- params: []
389
- }))).map((row) => row.channel);
390
- },
391
- async commitBundle(context, { changedSets }) {
392
- if (changedSets.length === 0) return;
393
- for (const op of changedSets) if (op.operation === "delete") {
394
- const deleteSql = (0, import_lib.default)(`
387
+ return (await resolvePage(await cf.d1.database.query(config.databaseId, {
388
+ account_id: config.accountId,
389
+ sql,
390
+ params: []
391
+ }))).map((row) => row.channel);
392
+ },
393
+ async commitBundle({ changedSets }) {
394
+ if (changedSets.length === 0) return;
395
+ for (const op of changedSets) if (op.operation === "delete") {
396
+ const deleteSql = (0, import_lib.default)(`
395
397
  DELETE FROM bundles WHERE id = ?
396
398
  `);
397
- await context.cf.d1.database.query(config.databaseId, {
398
- account_id: config.accountId,
399
- sql: deleteSql,
400
- params: [op.data.id]
401
- });
402
- bundles = bundles.filter((b) => b.id !== op.data.id);
403
- } else if (op.operation === "insert" || op.operation === "update") {
404
- const bundle = op.data;
405
- const upsertSql = (0, import_lib.default)(`
399
+ await cf.d1.database.query(config.databaseId, {
400
+ account_id: config.accountId,
401
+ sql: deleteSql,
402
+ params: [op.data.id]
403
+ });
404
+ bundles = bundles.filter((b) => b.id !== op.data.id);
405
+ } else if (op.operation === "insert" || op.operation === "update") {
406
+ const bundle = op.data;
407
+ const upsertSql = (0, import_lib.default)(`
406
408
  INSERT OR REPLACE INTO bundles (
407
409
  id,
408
410
  channel,
@@ -419,30 +421,30 @@ const d1Database = (config, hooks) => {
419
421
  )
420
422
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
421
423
  `);
422
- const params = [
423
- bundle.id,
424
- bundle.channel,
425
- bundle.enabled ? 1 : 0,
426
- bundle.shouldForceUpdate ? 1 : 0,
427
- bundle.fileHash,
428
- bundle.gitCommitHash || null,
429
- bundle.message || null,
430
- bundle.platform,
431
- bundle.targetAppVersion,
432
- bundle.storageUri,
433
- bundle.fingerprintHash,
434
- bundle.metadata ? JSON.stringify(bundle.metadata) : JSON.stringify({})
435
- ];
436
- await context.cf.d1.database.query(config.databaseId, {
437
- account_id: config.accountId,
438
- sql: upsertSql,
439
- params
440
- });
424
+ const params = [
425
+ bundle.id,
426
+ bundle.channel,
427
+ bundle.enabled ? 1 : 0,
428
+ bundle.shouldForceUpdate ? 1 : 0,
429
+ bundle.fileHash,
430
+ bundle.gitCommitHash || null,
431
+ bundle.message || null,
432
+ bundle.platform,
433
+ bundle.targetAppVersion,
434
+ bundle.storageUri,
435
+ bundle.fingerprintHash,
436
+ bundle.metadata ? JSON.stringify(bundle.metadata) : JSON.stringify({})
437
+ ];
438
+ await cf.d1.database.query(config.databaseId, {
439
+ account_id: config.accountId,
440
+ sql: upsertSql,
441
+ params
442
+ });
443
+ }
441
444
  }
442
- hooks?.onDatabaseUpdated?.();
443
- }
444
- }, hooks);
445
- };
445
+ };
446
+ }
447
+ });
446
448
 
447
449
  //#endregion
448
450
  //#region ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
@@ -6796,44 +6798,45 @@ const createWrangler = ({ stdio, accountId, cloudflareApiToken, cwd }) => {
6796
6798
  * })
6797
6799
  * ```
6798
6800
  */
6799
- const r2Storage = (config, hooks) => (_) => {
6800
- const { bucketName, cloudflareApiToken, accountId } = config;
6801
- const wrangler = createWrangler({
6802
- accountId,
6803
- cloudflareApiToken,
6804
- cwd: process.cwd()
6805
- });
6806
- const getStorageKey = createStorageKeyBuilder(config.basePath);
6807
- return {
6808
- name: "r2Storage",
6809
- supportedProtocol: "r2",
6810
- async delete(storageUri) {
6811
- const { bucket, key } = parseStorageUri(storageUri, "r2");
6812
- if (bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${bucket}".`);
6813
- try {
6814
- await wrangler("r2", "object", "delete", [bucketName, key].join("/"), "--remote");
6815
- } catch {
6816
- throw new Error("Can not delete bundle");
6817
- }
6818
- },
6819
- async upload(key, filePath) {
6820
- const contentType = getContentType(filePath);
6821
- const Key = getStorageKey(key, path$1.basename(filePath));
6822
- try {
6823
- const { stderr, exitCode } = await wrangler("r2", "object", "put", [bucketName, Key].join("/"), "--file", filePath, "--content-type", contentType, "--remote");
6824
- if (exitCode !== 0 && stderr) throw new Error(stderr);
6825
- } catch (error$1) {
6826
- if (error$1 instanceof ExecaError) throw new Error(error$1.stderr || error$1.stdout);
6827
- throw error$1;
6801
+ const r2Storage = createStoragePlugin({
6802
+ name: "r2Storage",
6803
+ supportedProtocol: "r2",
6804
+ factory: (config) => {
6805
+ const { bucketName, cloudflareApiToken, accountId } = config;
6806
+ const wrangler = createWrangler({
6807
+ accountId,
6808
+ cloudflareApiToken,
6809
+ cwd: process.cwd()
6810
+ });
6811
+ const getStorageKey = createStorageKeyBuilder(config.basePath);
6812
+ return {
6813
+ async delete(storageUri) {
6814
+ const { bucket, key } = parseStorageUri(storageUri, "r2");
6815
+ if (bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${bucket}".`);
6816
+ try {
6817
+ await wrangler("r2", "object", "delete", [bucketName, key].join("/"), "--remote");
6818
+ } catch {
6819
+ throw new Error("Can not delete bundle");
6820
+ }
6821
+ },
6822
+ async upload(key, filePath) {
6823
+ const contentType = getContentType(filePath);
6824
+ const Key = getStorageKey(key, path$1.basename(filePath));
6825
+ try {
6826
+ const { stderr, exitCode } = await wrangler("r2", "object", "put", [bucketName, Key].join("/"), "--file", filePath, "--content-type", contentType, "--remote");
6827
+ if (exitCode !== 0 && stderr) throw new Error(stderr);
6828
+ } catch (error$1) {
6829
+ if (error$1 instanceof ExecaError) throw new Error(error$1.stderr || error$1.stdout);
6830
+ throw error$1;
6831
+ }
6832
+ return { storageUri: `r2://${bucketName}/${Key}` };
6833
+ },
6834
+ async getDownloadUrl() {
6835
+ throw new Error("`r2Storage` does not support `getDownloadUrl()`. Use `s3Storage` from `@hot-updater/aws` instead (compatible with Cloudflare R2).\n\nExample:\ns3Storage({\n region: 'auto',\n endpoint: 'https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com',\n credentials: {\n accessKeyId: 'YOUR_ACCESS_KEY_ID',\n secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',\n },\n bucketName: 'YOUR_BUCKET_NAME',\n})");
6828
6836
  }
6829
- hooks?.onStorageUploaded?.();
6830
- return { storageUri: `r2://${bucketName}/${Key}` };
6831
- },
6832
- async getDownloadUrl() {
6833
- throw new Error("`r2Storage` does not support `getDownloadUrl()`. Use `s3Storage` from `@hot-updater/aws` instead (compatible with Cloudflare R2).\n\nExample:\ns3Storage({\n region: 'auto',\n endpoint: 'https://YOUR_ACCOUNT_ID.r2.cloudflarestorage.com',\n credentials: {\n accessKeyId: 'YOUR_ACCESS_KEY_ID',\n secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',\n },\n bucketName: 'YOUR_BUCKET_NAME',\n})");
6834
- }
6835
- };
6836
- };
6837
+ };
6838
+ }
6839
+ });
6837
6840
 
6838
6841
  //#endregion
6839
6842
  export { d1Database, r2Storage };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/cloudflare",
3
3
  "type": "module",
4
- "version": "0.21.10",
4
+ "version": "0.21.12",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
@@ -41,10 +41,10 @@
41
41
  ],
42
42
  "dependencies": {
43
43
  "cloudflare": "4.2.0",
44
- "@hot-updater/cli-tools": "0.21.10",
45
- "@hot-updater/core": "0.21.10",
46
- "@hot-updater/js": "0.21.10",
47
- "@hot-updater/plugin-core": "0.21.10"
44
+ "@hot-updater/cli-tools": "0.21.12",
45
+ "@hot-updater/core": "0.21.12",
46
+ "@hot-updater/js": "0.21.12",
47
+ "@hot-updater/plugin-core": "0.21.12"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@cloudflare/vitest-pool-workers": "^0.8.70",
@@ -62,7 +62,7 @@
62
62
  "vitest": "2.1.8",
63
63
  "wrangler": "^4.5.0",
64
64
  "xdg-app-paths": "^8.3.0",
65
- "@hot-updater/test-utils": "0.21.10"
65
+ "@hot-updater/test-utils": "0.21.12"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsdown && pnpm build:worker",
@@ -1 +1 @@
1
- This folder contains the built output assets for the worker "hot-updater" generated at 2025-11-13T14:01:30.440Z.
1
+ This folder contains the built output assets for the worker "hot-updater" generated at 2025-11-17T16:23:27.792Z.