@hot-updater/cloudflare 0.18.3 → 0.18.5

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
@@ -399,34 +399,56 @@ const d1Database = (config, hooks) => {
399
399
  },
400
400
  async commitBundle(context, { changedSets }) {
401
401
  if (changedSets.length === 0) return;
402
- const bundles$1 = changedSets.map((op) => op.data);
403
- const params = [];
404
- const valuesSql = bundles$1.map((b) => {
405
- params.push(b.id, b.channel, b.enabled ? 1 : 0, b.shouldForceUpdate ? 1 : 0, b.fileHash, b.gitCommitHash || null, b.message || null, b.platform, b.targetAppVersion, b.storageUri, b.fingerprintHash, b.metadata ? JSON.stringify(b.metadata) : JSON.stringify({}));
406
- return "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
407
- }).join(",\n");
408
- const sql = (0, import_lib.default)(`
409
- INSERT OR REPLACE INTO bundles (
410
- id,
411
- channel,
412
- enabled,
413
- should_force_update,
414
- file_hash,
415
- git_commit_hash,
416
- message,
417
- platform,
418
- target_app_version,
419
- storage_uri,
420
- fingerprint_hash,
421
- metadata
422
- )
423
- VALUES
424
- ${valuesSql};`);
425
- await context.cf.d1.database.query(config.databaseId, {
426
- account_id: config.accountId,
427
- sql,
428
- params
429
- });
402
+ for (const op of changedSets) if (op.operation === "delete") {
403
+ const deleteSql = (0, import_lib.default)(`
404
+ DELETE FROM bundles WHERE id = ?
405
+ `);
406
+ await context.cf.d1.database.query(config.databaseId, {
407
+ account_id: config.accountId,
408
+ sql: deleteSql,
409
+ params: [op.data.id]
410
+ });
411
+ bundles = bundles.filter((b) => b.id !== op.data.id);
412
+ } else if (op.operation === "insert" || op.operation === "update") {
413
+ const bundle = op.data;
414
+ const upsertSql = (0, import_lib.default)(`
415
+ INSERT OR REPLACE INTO bundles (
416
+ id,
417
+ channel,
418
+ enabled,
419
+ should_force_update,
420
+ file_hash,
421
+ git_commit_hash,
422
+ message,
423
+ platform,
424
+ target_app_version,
425
+ storage_uri,
426
+ fingerprint_hash,
427
+ metadata
428
+ )
429
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
430
+ `);
431
+ const params = [
432
+ bundle.id,
433
+ bundle.channel,
434
+ bundle.enabled ? 1 : 0,
435
+ bundle.shouldForceUpdate ? 1 : 0,
436
+ bundle.fileHash,
437
+ bundle.gitCommitHash || null,
438
+ bundle.message || null,
439
+ bundle.platform,
440
+ bundle.targetAppVersion,
441
+ bundle.storageUri,
442
+ bundle.fingerprintHash,
443
+ bundle.metadata ? JSON.stringify(bundle.metadata) : JSON.stringify({})
444
+ ];
445
+ await context.cf.d1.database.query(config.databaseId, {
446
+ account_id: config.accountId,
447
+ sql: upsertSql,
448
+ params
449
+ });
450
+ }
451
+ hooks?.onDatabaseUpdated?.();
430
452
  }
431
453
  }, hooks);
432
454
  };
@@ -8208,8 +8230,13 @@ const r2Storage = (config, hooks) => (_) => {
8208
8230
  return {
8209
8231
  name: "r2Storage",
8210
8232
  async deleteBundle(bundleId) {
8211
- await wrangler("r2", "object", "delete", [bucketName, bundleId].join("/"), "--remote");
8212
- throw new Error("Bundle Not Found");
8233
+ const Key = `${bundleId}/bundle.zip `;
8234
+ try {
8235
+ await wrangler("r2", "object", "delete", [bucketName, Key].join("/"), "--remote");
8236
+ return { storageUri: `r2://${bucketName}/${Key}` };
8237
+ } catch (error$1) {
8238
+ throw new Error("Can not delete bundle");
8239
+ }
8213
8240
  },
8214
8241
  async uploadBundle(bundleId, bundlePath) {
8215
8242
  const contentType = src_default.getType(bundlePath) ?? void 0;
package/dist/index.js CHANGED
@@ -401,34 +401,56 @@ const d1Database = (config, hooks) => {
401
401
  },
402
402
  async commitBundle(context, { changedSets }) {
403
403
  if (changedSets.length === 0) return;
404
- const bundles$1 = changedSets.map((op) => op.data);
405
- const params = [];
406
- const valuesSql = bundles$1.map((b) => {
407
- params.push(b.id, b.channel, b.enabled ? 1 : 0, b.shouldForceUpdate ? 1 : 0, b.fileHash, b.gitCommitHash || null, b.message || null, b.platform, b.targetAppVersion, b.storageUri, b.fingerprintHash, b.metadata ? JSON.stringify(b.metadata) : JSON.stringify({}));
408
- return "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
409
- }).join(",\n");
410
- const sql = (0, import_lib.default)(`
411
- INSERT OR REPLACE INTO bundles (
412
- id,
413
- channel,
414
- enabled,
415
- should_force_update,
416
- file_hash,
417
- git_commit_hash,
418
- message,
419
- platform,
420
- target_app_version,
421
- storage_uri,
422
- fingerprint_hash,
423
- metadata
424
- )
425
- VALUES
426
- ${valuesSql};`);
427
- await context.cf.d1.database.query(config.databaseId, {
428
- account_id: config.accountId,
429
- sql,
430
- params
431
- });
404
+ for (const op of changedSets) if (op.operation === "delete") {
405
+ const deleteSql = (0, import_lib.default)(`
406
+ DELETE FROM bundles WHERE id = ?
407
+ `);
408
+ await context.cf.d1.database.query(config.databaseId, {
409
+ account_id: config.accountId,
410
+ sql: deleteSql,
411
+ params: [op.data.id]
412
+ });
413
+ bundles = bundles.filter((b) => b.id !== op.data.id);
414
+ } else if (op.operation === "insert" || op.operation === "update") {
415
+ const bundle = op.data;
416
+ const upsertSql = (0, import_lib.default)(`
417
+ INSERT OR REPLACE INTO bundles (
418
+ id,
419
+ channel,
420
+ enabled,
421
+ should_force_update,
422
+ file_hash,
423
+ git_commit_hash,
424
+ message,
425
+ platform,
426
+ target_app_version,
427
+ storage_uri,
428
+ fingerprint_hash,
429
+ metadata
430
+ )
431
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
432
+ `);
433
+ const params = [
434
+ bundle.id,
435
+ bundle.channel,
436
+ bundle.enabled ? 1 : 0,
437
+ bundle.shouldForceUpdate ? 1 : 0,
438
+ bundle.fileHash,
439
+ bundle.gitCommitHash || null,
440
+ bundle.message || null,
441
+ bundle.platform,
442
+ bundle.targetAppVersion,
443
+ bundle.storageUri,
444
+ bundle.fingerprintHash,
445
+ bundle.metadata ? JSON.stringify(bundle.metadata) : JSON.stringify({})
446
+ ];
447
+ await context.cf.d1.database.query(config.databaseId, {
448
+ account_id: config.accountId,
449
+ sql: upsertSql,
450
+ params
451
+ });
452
+ }
453
+ hooks?.onDatabaseUpdated?.();
432
454
  }
433
455
  }, hooks);
434
456
  };
@@ -8210,8 +8232,13 @@ const r2Storage = (config, hooks) => (_) => {
8210
8232
  return {
8211
8233
  name: "r2Storage",
8212
8234
  async deleteBundle(bundleId) {
8213
- await wrangler("r2", "object", "delete", [bucketName, bundleId].join("/"), "--remote");
8214
- throw new Error("Bundle Not Found");
8235
+ const Key = `${bundleId}/bundle.zip `;
8236
+ try {
8237
+ await wrangler("r2", "object", "delete", [bucketName, Key].join("/"), "--remote");
8238
+ return { storageUri: `r2://${bucketName}/${Key}` };
8239
+ } catch (error$1) {
8240
+ throw new Error("Can not delete bundle");
8241
+ }
8215
8242
  },
8216
8243
  async uploadBundle(bundleId, bundlePath) {
8217
8244
  const contentType = src_default.getType(bundlePath) ?? void 0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/cloudflare",
3
3
  "type": "module",
4
- "version": "0.18.3",
4
+ "version": "0.18.5",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
@@ -40,9 +40,9 @@
40
40
  ],
41
41
  "dependencies": {
42
42
  "cloudflare": "4.2.0",
43
- "@hot-updater/core": "0.18.3",
44
- "@hot-updater/js": "0.18.3",
45
- "@hot-updater/plugin-core": "0.18.3"
43
+ "@hot-updater/core": "0.18.5",
44
+ "@hot-updater/plugin-core": "0.18.5",
45
+ "@hot-updater/js": "0.18.5"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@clack/prompts": "0.10.0",
@@ -1 +1 @@
1
- This folder contains the built output assets for the worker "hot-updater" generated at 2025-06-05T13:05:46.930Z.
1
+ This folder contains the built output assets for the worker "hot-updater" generated at 2025-06-10T01:49:43.561Z.