@hot-updater/plugin-core 0.28.0 → 0.29.0

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.
Files changed (50) hide show
  1. package/dist/_virtual/{rolldown_runtime.cjs → _rolldown/runtime.cjs} +2 -4
  2. package/dist/calculatePagination.cjs +1 -3
  3. package/dist/{calculatePagination.d.ts → calculatePagination.d.mts} +1 -1
  4. package/dist/{calculatePagination.js → calculatePagination.mjs} +1 -2
  5. package/dist/compressionFormat.cjs +6 -8
  6. package/dist/{compressionFormat.js → compressionFormat.mjs} +2 -4
  7. package/dist/createBlobDatabasePlugin.cjs +31 -34
  8. package/dist/createBlobDatabasePlugin.d.cts +1 -1
  9. package/dist/{createBlobDatabasePlugin.d.ts → createBlobDatabasePlugin.d.mts} +2 -2
  10. package/dist/{createBlobDatabasePlugin.js → createBlobDatabasePlugin.mjs} +29 -31
  11. package/dist/createDatabasePlugin.cjs +26 -17
  12. package/dist/createDatabasePlugin.d.cts +11 -18
  13. package/dist/{createDatabasePlugin.d.ts → createDatabasePlugin.d.mts} +11 -18
  14. package/dist/{createDatabasePlugin.js → createDatabasePlugin.mjs} +26 -16
  15. package/dist/createStorageKeyBuilder.cjs +1 -3
  16. package/dist/{createStorageKeyBuilder.js → createStorageKeyBuilder.mjs} +1 -2
  17. package/dist/createStoragePlugin.cjs +4 -6
  18. package/dist/createStoragePlugin.d.cts +6 -7
  19. package/dist/{createStoragePlugin.d.ts → createStoragePlugin.d.mts} +7 -8
  20. package/dist/{createStoragePlugin.js → createStoragePlugin.mjs} +4 -5
  21. package/dist/filterCompatibleAppVersions.cjs +2 -4
  22. package/dist/{filterCompatibleAppVersions.js → filterCompatibleAppVersions.mjs} +2 -4
  23. package/dist/generateMinBundleId.cjs +1 -3
  24. package/dist/{generateMinBundleId.js → generateMinBundleId.mjs} +1 -2
  25. package/dist/index.cjs +17 -13
  26. package/dist/index.d.cts +3 -2
  27. package/dist/index.d.mts +14 -0
  28. package/dist/index.mjs +13 -0
  29. package/dist/parseStorageUri.cjs +1 -3
  30. package/dist/{parseStorageUri.js → parseStorageUri.mjs} +1 -2
  31. package/dist/queryBundles.cjs +40 -0
  32. package/dist/queryBundles.d.cts +8 -0
  33. package/dist/queryBundles.d.mts +8 -0
  34. package/dist/queryBundles.mjs +38 -0
  35. package/dist/semverSatisfies.cjs +3 -5
  36. package/dist/{semverSatisfies.js → semverSatisfies.mjs} +1 -3
  37. package/dist/types/index.cjs +1 -3
  38. package/dist/types/index.d.cts +45 -18
  39. package/dist/types/{index.d.ts → index.d.mts} +46 -19
  40. package/dist/types/{index.js → index.mjs} +1 -2
  41. package/package.json +6 -5
  42. package/dist/index.d.ts +0 -13
  43. package/dist/index.js +0 -13
  44. /package/dist/{compressionFormat.d.ts → compressionFormat.d.mts} +0 -0
  45. /package/dist/{createStorageKeyBuilder.d.ts → createStorageKeyBuilder.d.mts} +0 -0
  46. /package/dist/{filterCompatibleAppVersions.d.ts → filterCompatibleAppVersions.d.mts} +0 -0
  47. /package/dist/{generateMinBundleId.d.ts → generateMinBundleId.d.mts} +0 -0
  48. /package/dist/{parseStorageUri.d.ts → parseStorageUri.d.mts} +0 -0
  49. /package/dist/{semverSatisfies.d.ts → semverSatisfies.d.mts} +0 -0
  50. /package/dist/types/{utils.d.ts → utils.d.mts} +0 -0
@@ -1,4 +1,4 @@
1
- //#region rolldown:runtime
1
+ //#region \0rolldown/runtime.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -19,7 +19,5 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
19
19
  value: mod,
20
20
  enumerable: true
21
21
  }) : target, mod));
22
-
23
22
  //#endregion
24
-
25
- exports.__toESM = __toESM;
23
+ exports.__toESM = __toESM;
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/calculatePagination.ts
3
2
  /**
4
3
  * Calculate pagination information based on total count, limit, and offset
@@ -22,6 +21,5 @@ function calculatePagination(total, options) {
22
21
  totalPages
23
22
  };
24
23
  }
25
-
26
24
  //#endregion
27
- exports.calculatePagination = calculatePagination;
25
+ exports.calculatePagination = calculatePagination;
@@ -1,4 +1,4 @@
1
- import { Bundle, PaginationInfo } from "./types/index.js";
1
+ import { Bundle, PaginationInfo } from "./types/index.mjs";
2
2
 
3
3
  //#region src/calculatePagination.d.ts
4
4
  interface PaginationOptions {
@@ -21,6 +21,5 @@ function calculatePagination(total, options) {
21
21
  totalPages
22
22
  };
23
23
  }
24
-
25
24
  //#endregion
26
- export { calculatePagination };
25
+ export { calculatePagination };
@@ -1,9 +1,8 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
+ let node_path = require("node:path");
3
+ node_path = require_runtime.__toESM(node_path);
2
4
  let mime = require("mime");
3
- mime = require_rolldown_runtime.__toESM(mime);
4
- let path = require("path");
5
- path = require_rolldown_runtime.__toESM(path);
6
-
5
+ mime = require_runtime.__toESM(mime);
7
6
  //#region src/compressionFormat.ts
8
7
  /**
9
8
  * Compression formats registry
@@ -49,11 +48,10 @@ function getCompressionMimeType(filename) {
49
48
  * @returns Content-Type string (never undefined, falls back to application/octet-stream)
50
49
  */
51
50
  function getContentType(bundlePath) {
52
- const filename = path.default.basename(bundlePath);
51
+ const filename = node_path.default.basename(bundlePath);
53
52
  return mime.default.getType(bundlePath) ?? getCompressionMimeType(filename) ?? "application/octet-stream";
54
53
  }
55
-
56
54
  //#endregion
57
55
  exports.detectCompressionFormat = detectCompressionFormat;
58
56
  exports.getCompressionMimeType = getCompressionMimeType;
59
- exports.getContentType = getContentType;
57
+ exports.getContentType = getContentType;
@@ -1,6 +1,5 @@
1
+ import path from "node:path";
1
2
  import mime from "mime";
2
- import path from "path";
3
-
4
3
  //#region src/compressionFormat.ts
5
4
  /**
6
5
  * Compression formats registry
@@ -49,6 +48,5 @@ function getContentType(bundlePath) {
49
48
  const filename = path.basename(bundlePath);
50
49
  return mime.getType(bundlePath) ?? getCompressionMimeType(filename) ?? "application/octet-stream";
51
50
  }
52
-
53
51
  //#endregion
54
- export { detectCompressionFormat, getCompressionMimeType, getContentType };
52
+ export { detectCompressionFormat, getCompressionMimeType, getContentType };
@@ -1,14 +1,13 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
- const require_calculatePagination = require('./calculatePagination.cjs');
3
- const require_createDatabasePlugin = require('./createDatabasePlugin.cjs');
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
+ const require_calculatePagination = require("./calculatePagination.cjs");
3
+ const require_createDatabasePlugin = require("./createDatabasePlugin.cjs");
4
+ const require_queryBundles = require("./queryBundles.cjs");
4
5
  let es_toolkit = require("es-toolkit");
5
- es_toolkit = require_rolldown_runtime.__toESM(es_toolkit);
6
6
  let semver = require("semver");
7
- semver = require_rolldown_runtime.__toESM(semver);
8
-
7
+ semver = require_runtime.__toESM(semver);
9
8
  //#region src/createBlobDatabasePlugin.ts
10
9
  function removeBundleInternalKeys(bundle) {
11
- const { _updateJsonKey, _oldUpdateJsonKey,...pureBundle } = bundle;
10
+ const { _updateJsonKey, _oldUpdateJsonKey, ...pureBundle } = bundle;
12
11
  return pureBundle;
13
12
  }
14
13
  function normalizeTargetAppVersion(version) {
@@ -76,8 +75,8 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
76
75
  * Returns true if the file was updated, false if no changes were made.
77
76
  */
78
77
  async function updateTargetVersionsForPlatform(platform) {
79
- const updateJsonPattern = /* @__PURE__ */ new RegExp(`^[^/]+/${platform}/[^/]+/update\\.json$`);
80
- const targetVersionsPattern = /* @__PURE__ */ new RegExp(`^[^/]+/${platform}/target-app-versions\\.json$`);
78
+ const updateJsonPattern = new RegExp(`^[^/]+/${platform}/[^/]+/update\\.json$`);
79
+ const targetVersionsPattern = new RegExp(`^[^/]+/${platform}/target-app-versions\\.json$`);
81
80
  const allKeys = await listObjects("");
82
81
  const updateJsonKeys = allKeys.filter((key) => updateJsonPattern.test(key));
83
82
  const targetVersionsKeys = allKeys.filter((key) => targetVersionsPattern.test(key));
@@ -109,7 +108,7 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
109
108
  */
110
109
  async function listUpdateJsonKeys(platform, channel) {
111
110
  const prefix = channel ? platform ? `${channel}/${platform}/` : `${channel}/` : "";
112
- const pattern = channel ? platform ? /* @__PURE__ */ new RegExp(`^${channel}/${platform}/[^/]+/update\\.json$`) : /* @__PURE__ */ new RegExp(`^${channel}/[^/]+/[^/]+/update\\.json$`) : platform ? /* @__PURE__ */ new RegExp(`^[^/]+/${platform}/[^/]+/update\\.json$`) : /^[^/]+\/[^/]+\/[^/]+\/update\.json$/;
111
+ const pattern = channel ? platform ? new RegExp(`^${channel}/${platform}/[^/]+/update\\.json$`) : new RegExp(`^${channel}/[^/]+/[^/]+/update\\.json$`) : platform ? new RegExp(`^[^/]+/${platform}/[^/]+/update\\.json$`) : /^[^/]+\/[^/]+\/[^/]+\/update\.json$/;
113
112
  return listObjects(prefix).then((keys) => keys.filter((key) => pattern.test(key)));
114
113
  }
115
114
  const addAppVersionInvalidationPaths = (pathsToInvalidate, { platform, channel, targetAppVersion }) => {
@@ -139,16 +138,15 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
139
138
  if (pendingBundle) return removeBundleInternalKeys(pendingBundle);
140
139
  const bundle = bundlesMap.get(bundleId);
141
140
  if (bundle) return removeBundleInternalKeys(bundle);
142
- return (await reloadBundles()).find((bundle$1) => bundle$1.id === bundleId) ?? null;
141
+ return (await reloadBundles()).find((bundle) => bundle.id === bundleId) ?? null;
143
142
  },
144
143
  async getBundles(options) {
145
144
  let allBundles = await reloadBundles();
146
- const { where, limit, offset } = options;
147
- if (where) allBundles = allBundles.filter((bundle) => {
148
- return Object.entries(where).every(([key, value]) => value === void 0 || value === null || bundle[key] === value);
149
- });
150
- const total = allBundles.length;
151
- let paginatedData = allBundles.map(removeBundleInternalKeys);
145
+ const { where, limit, offset, orderBy } = options;
146
+ if (where) allBundles = allBundles.filter((bundle) => require_queryBundles.bundleMatchesQueryWhere(bundle, where));
147
+ const cleanBundles = require_queryBundles.sortBundles(allBundles.map(removeBundleInternalKeys), orderBy);
148
+ const total = cleanBundles.length;
149
+ let paginatedData = cleanBundles;
152
150
  if (offset > 0) paginatedData = paginatedData.slice(offset);
153
151
  if (limit) paginatedData = paginatedData.slice(0, limit);
154
152
  return {
@@ -193,15 +191,15 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
193
191
  continue;
194
192
  }
195
193
  if (operation === "delete") {
196
- let bundle$1 = pendingBundlesMap.get(data.id);
197
- if (!bundle$1) bundle$1 = bundlesMap.get(data.id);
198
- if (!bundle$1) throw new Error("Bundle to delete not found");
194
+ let bundle = pendingBundlesMap.get(data.id);
195
+ if (!bundle) bundle = bundlesMap.get(data.id);
196
+ if (!bundle) throw new Error("Bundle to delete not found");
199
197
  bundlesMap.delete(data.id);
200
198
  pendingBundlesMap.delete(data.id);
201
- const key = bundle$1._updateJsonKey;
199
+ const key = bundle._updateJsonKey;
202
200
  removalsByKey[key] = removalsByKey[key] || [];
203
- removalsByKey[key].push(bundle$1.id);
204
- addLookupInvalidationPaths(pathsToInvalidate, bundle$1);
201
+ removalsByKey[key].push(bundle.id);
202
+ addLookupInvalidationPaths(pathsToInvalidate, bundle);
205
203
  continue;
206
204
  }
207
205
  let bundle = pendingBundlesMap.get(data.id);
@@ -218,17 +216,17 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
218
216
  removalsByKey[oldKey] = removalsByKey[oldKey] || [];
219
217
  removalsByKey[oldKey].push(bundle.id);
220
218
  changedBundlesByKey[newKey] = changedBundlesByKey[newKey] || [];
221
- const updatedBundle$1 = {
219
+ const updatedBundle = {
222
220
  ...bundle,
223
221
  ...data
224
222
  };
225
- updatedBundle$1._oldUpdateJsonKey = oldKey;
226
- updatedBundle$1._updateJsonKey = newKey;
227
- bundlesMap.set(data.id, updatedBundle$1);
228
- pendingBundlesMap.set(data.id, updatedBundle$1);
229
- changedBundlesByKey[newKey].push(removeBundleInternalKeys(updatedBundle$1));
223
+ updatedBundle._oldUpdateJsonKey = oldKey;
224
+ updatedBundle._updateJsonKey = newKey;
225
+ bundlesMap.set(data.id, updatedBundle);
226
+ pendingBundlesMap.set(data.id, updatedBundle);
227
+ changedBundlesByKey[newKey].push(removeBundleInternalKeys(updatedBundle));
230
228
  const oldChannel = bundle.channel;
231
- const nextChannel = updatedBundle$1.channel;
229
+ const nextChannel = updatedBundle.channel;
232
230
  if (oldChannel !== nextChannel) {
233
231
  addLookupInvalidationPaths(pathsToInvalidate, bundle);
234
232
  if (bundle.targetAppVersion && !bundle.fingerprintHash) addLookupInvalidationPaths(pathsToInvalidate, {
@@ -236,8 +234,8 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
236
234
  channel: nextChannel
237
235
  });
238
236
  }
239
- addLookupInvalidationPaths(pathsToInvalidate, updatedBundle$1);
240
- if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle$1.targetAppVersion) addLookupInvalidationPaths(pathsToInvalidate, bundle);
237
+ addLookupInvalidationPaths(pathsToInvalidate, updatedBundle);
238
+ if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle.targetAppVersion) addLookupInvalidationPaths(pathsToInvalidate, bundle);
241
239
  continue;
242
240
  }
243
241
  const currentKey = bundle._updateJsonKey;
@@ -280,6 +278,5 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
280
278
  })({}, hooks);
281
279
  };
282
280
  };
283
-
284
281
  //#endregion
285
- exports.createBlobDatabasePlugin = createBlobDatabasePlugin;
282
+ exports.createBlobDatabasePlugin = createBlobDatabasePlugin;
@@ -22,6 +22,6 @@ declare const createBlobDatabasePlugin: <TConfig>({
22
22
  }: {
23
23
  name: string;
24
24
  factory: (config: TConfig) => BlobOperations;
25
- }) => (config: TConfig, hooks?: DatabasePluginHooks) => () => DatabasePlugin;
25
+ }) => (config: TConfig, hooks?: DatabasePluginHooks) => () => DatabasePlugin<unknown>;
26
26
  //#endregion
27
27
  export { BlobOperations, createBlobDatabasePlugin };
@@ -1,4 +1,4 @@
1
- import { DatabasePlugin, DatabasePluginHooks } from "./types/index.js";
1
+ import { DatabasePlugin, DatabasePluginHooks } from "./types/index.mjs";
2
2
 
3
3
  //#region src/createBlobDatabasePlugin.d.ts
4
4
  interface BlobOperations {
@@ -22,6 +22,6 @@ declare const createBlobDatabasePlugin: <TConfig>({
22
22
  }: {
23
23
  name: string;
24
24
  factory: (config: TConfig) => BlobOperations;
25
- }) => (config: TConfig, hooks?: DatabasePluginHooks) => () => DatabasePlugin;
25
+ }) => (config: TConfig, hooks?: DatabasePluginHooks) => () => DatabasePlugin<unknown>;
26
26
  //#endregion
27
27
  export { BlobOperations, createBlobDatabasePlugin };
@@ -1,11 +1,11 @@
1
- import { calculatePagination } from "./calculatePagination.js";
2
- import { createDatabasePlugin } from "./createDatabasePlugin.js";
1
+ import { calculatePagination } from "./calculatePagination.mjs";
2
+ import { createDatabasePlugin } from "./createDatabasePlugin.mjs";
3
+ import { bundleMatchesQueryWhere, sortBundles } from "./queryBundles.mjs";
3
4
  import { orderBy } from "es-toolkit";
4
5
  import semver from "semver";
5
-
6
6
  //#region src/createBlobDatabasePlugin.ts
7
7
  function removeBundleInternalKeys(bundle) {
8
- const { _updateJsonKey, _oldUpdateJsonKey,...pureBundle } = bundle;
8
+ const { _updateJsonKey, _oldUpdateJsonKey, ...pureBundle } = bundle;
9
9
  return pureBundle;
10
10
  }
11
11
  function normalizeTargetAppVersion(version) {
@@ -73,8 +73,8 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
73
73
  * Returns true if the file was updated, false if no changes were made.
74
74
  */
75
75
  async function updateTargetVersionsForPlatform(platform) {
76
- const updateJsonPattern = /* @__PURE__ */ new RegExp(`^[^/]+/${platform}/[^/]+/update\\.json$`);
77
- const targetVersionsPattern = /* @__PURE__ */ new RegExp(`^[^/]+/${platform}/target-app-versions\\.json$`);
76
+ const updateJsonPattern = new RegExp(`^[^/]+/${platform}/[^/]+/update\\.json$`);
77
+ const targetVersionsPattern = new RegExp(`^[^/]+/${platform}/target-app-versions\\.json$`);
78
78
  const allKeys = await listObjects("");
79
79
  const updateJsonKeys = allKeys.filter((key) => updateJsonPattern.test(key));
80
80
  const targetVersionsKeys = allKeys.filter((key) => targetVersionsPattern.test(key));
@@ -106,7 +106,7 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
106
106
  */
107
107
  async function listUpdateJsonKeys(platform, channel) {
108
108
  const prefix = channel ? platform ? `${channel}/${platform}/` : `${channel}/` : "";
109
- const pattern = channel ? platform ? /* @__PURE__ */ new RegExp(`^${channel}/${platform}/[^/]+/update\\.json$`) : /* @__PURE__ */ new RegExp(`^${channel}/[^/]+/[^/]+/update\\.json$`) : platform ? /* @__PURE__ */ new RegExp(`^[^/]+/${platform}/[^/]+/update\\.json$`) : /^[^/]+\/[^/]+\/[^/]+\/update\.json$/;
109
+ const pattern = channel ? platform ? new RegExp(`^${channel}/${platform}/[^/]+/update\\.json$`) : new RegExp(`^${channel}/[^/]+/[^/]+/update\\.json$`) : platform ? new RegExp(`^[^/]+/${platform}/[^/]+/update\\.json$`) : /^[^/]+\/[^/]+\/[^/]+\/update\.json$/;
110
110
  return listObjects(prefix).then((keys) => keys.filter((key) => pattern.test(key)));
111
111
  }
112
112
  const addAppVersionInvalidationPaths = (pathsToInvalidate, { platform, channel, targetAppVersion }) => {
@@ -136,16 +136,15 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
136
136
  if (pendingBundle) return removeBundleInternalKeys(pendingBundle);
137
137
  const bundle = bundlesMap.get(bundleId);
138
138
  if (bundle) return removeBundleInternalKeys(bundle);
139
- return (await reloadBundles()).find((bundle$1) => bundle$1.id === bundleId) ?? null;
139
+ return (await reloadBundles()).find((bundle) => bundle.id === bundleId) ?? null;
140
140
  },
141
141
  async getBundles(options) {
142
142
  let allBundles = await reloadBundles();
143
- const { where, limit, offset } = options;
144
- if (where) allBundles = allBundles.filter((bundle) => {
145
- return Object.entries(where).every(([key, value]) => value === void 0 || value === null || bundle[key] === value);
146
- });
147
- const total = allBundles.length;
148
- let paginatedData = allBundles.map(removeBundleInternalKeys);
143
+ const { where, limit, offset, orderBy } = options;
144
+ if (where) allBundles = allBundles.filter((bundle) => bundleMatchesQueryWhere(bundle, where));
145
+ const cleanBundles = sortBundles(allBundles.map(removeBundleInternalKeys), orderBy);
146
+ const total = cleanBundles.length;
147
+ let paginatedData = cleanBundles;
149
148
  if (offset > 0) paginatedData = paginatedData.slice(offset);
150
149
  if (limit) paginatedData = paginatedData.slice(0, limit);
151
150
  return {
@@ -190,15 +189,15 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
190
189
  continue;
191
190
  }
192
191
  if (operation === "delete") {
193
- let bundle$1 = pendingBundlesMap.get(data.id);
194
- if (!bundle$1) bundle$1 = bundlesMap.get(data.id);
195
- if (!bundle$1) throw new Error("Bundle to delete not found");
192
+ let bundle = pendingBundlesMap.get(data.id);
193
+ if (!bundle) bundle = bundlesMap.get(data.id);
194
+ if (!bundle) throw new Error("Bundle to delete not found");
196
195
  bundlesMap.delete(data.id);
197
196
  pendingBundlesMap.delete(data.id);
198
- const key = bundle$1._updateJsonKey;
197
+ const key = bundle._updateJsonKey;
199
198
  removalsByKey[key] = removalsByKey[key] || [];
200
- removalsByKey[key].push(bundle$1.id);
201
- addLookupInvalidationPaths(pathsToInvalidate, bundle$1);
199
+ removalsByKey[key].push(bundle.id);
200
+ addLookupInvalidationPaths(pathsToInvalidate, bundle);
202
201
  continue;
203
202
  }
204
203
  let bundle = pendingBundlesMap.get(data.id);
@@ -215,17 +214,17 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
215
214
  removalsByKey[oldKey] = removalsByKey[oldKey] || [];
216
215
  removalsByKey[oldKey].push(bundle.id);
217
216
  changedBundlesByKey[newKey] = changedBundlesByKey[newKey] || [];
218
- const updatedBundle$1 = {
217
+ const updatedBundle = {
219
218
  ...bundle,
220
219
  ...data
221
220
  };
222
- updatedBundle$1._oldUpdateJsonKey = oldKey;
223
- updatedBundle$1._updateJsonKey = newKey;
224
- bundlesMap.set(data.id, updatedBundle$1);
225
- pendingBundlesMap.set(data.id, updatedBundle$1);
226
- changedBundlesByKey[newKey].push(removeBundleInternalKeys(updatedBundle$1));
221
+ updatedBundle._oldUpdateJsonKey = oldKey;
222
+ updatedBundle._updateJsonKey = newKey;
223
+ bundlesMap.set(data.id, updatedBundle);
224
+ pendingBundlesMap.set(data.id, updatedBundle);
225
+ changedBundlesByKey[newKey].push(removeBundleInternalKeys(updatedBundle));
227
226
  const oldChannel = bundle.channel;
228
- const nextChannel = updatedBundle$1.channel;
227
+ const nextChannel = updatedBundle.channel;
229
228
  if (oldChannel !== nextChannel) {
230
229
  addLookupInvalidationPaths(pathsToInvalidate, bundle);
231
230
  if (bundle.targetAppVersion && !bundle.fingerprintHash) addLookupInvalidationPaths(pathsToInvalidate, {
@@ -233,8 +232,8 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
233
232
  channel: nextChannel
234
233
  });
235
234
  }
236
- addLookupInvalidationPaths(pathsToInvalidate, updatedBundle$1);
237
- if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle$1.targetAppVersion) addLookupInvalidationPaths(pathsToInvalidate, bundle);
235
+ addLookupInvalidationPaths(pathsToInvalidate, updatedBundle);
236
+ if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle.targetAppVersion) addLookupInvalidationPaths(pathsToInvalidate, bundle);
238
237
  continue;
239
238
  }
240
239
  const currentKey = bundle._updateJsonKey;
@@ -277,6 +276,5 @@ const createBlobDatabasePlugin = ({ name, factory }) => {
277
276
  })({}, hooks);
278
277
  };
279
278
  };
280
-
281
279
  //#endregion
282
- export { createBlobDatabasePlugin };
280
+ export { createBlobDatabasePlugin };
@@ -1,8 +1,12 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
1
+ require("./_virtual/_rolldown/runtime.cjs");
2
2
  let es_toolkit = require("es-toolkit");
3
- es_toolkit = require_rolldown_runtime.__toESM(es_toolkit);
4
-
5
3
  //#region src/createDatabasePlugin.ts
4
+ const REPLACE_ON_UPDATE_KEYS = ["targetCohorts"];
5
+ function mergeBundleUpdate(baseBundle, patch) {
6
+ return (0, es_toolkit.mergeWith)(baseBundle, patch, (_targetValue, sourceValue, key) => {
7
+ if (REPLACE_ON_UPDATE_KEYS.includes(key)) return sourceValue;
8
+ });
9
+ }
6
10
  /**
7
11
  * Creates a database plugin with lazy initialization and automatic hook execution.
8
12
  *
@@ -46,37 +50,43 @@ function createDatabasePlugin(options) {
46
50
  };
47
51
  return {
48
52
  name: options.name,
49
- async getBundleById(bundleId) {
50
- return getMethods().getBundleById(bundleId);
53
+ async getBundleById(bundleId, context) {
54
+ if (context === void 0) return getMethods().getBundleById(bundleId);
55
+ return getMethods().getBundleById(bundleId, context);
51
56
  },
52
- async getBundles(options$1) {
53
- return getMethods().getBundles(options$1);
57
+ async getBundles(options, context) {
58
+ if (context === void 0) return getMethods().getBundles(options);
59
+ return getMethods().getBundles(options, context);
54
60
  },
55
- async getChannels() {
56
- return getMethods().getChannels();
61
+ async getChannels(context) {
62
+ if (context === void 0) return getMethods().getChannels();
63
+ return getMethods().getChannels(context);
57
64
  },
58
65
  async onUnmount() {
59
66
  const methods = getMethods();
60
67
  if (methods.onUnmount) return methods.onUnmount();
61
68
  },
62
- async commitBundle() {
63
- await getMethods().commitBundle({ changedSets: Array.from(changedMap.values()) });
69
+ async commitBundle(context) {
70
+ const methods = getMethods();
71
+ const params = { changedSets: Array.from(changedMap.values()) };
72
+ if (context === void 0) await methods.commitBundle(params);
73
+ else await methods.commitBundle(params, context);
64
74
  await hooks?.onDatabaseUpdated?.();
65
75
  changedMap.clear();
66
76
  },
67
- async updateBundle(targetBundleId, newBundle) {
77
+ async updateBundle(targetBundleId, newBundle, context) {
68
78
  const pendingChange = changedMap.get(targetBundleId);
69
79
  if (pendingChange) {
70
- const updatedData = (0, es_toolkit.merge)(pendingChange.data, newBundle);
80
+ const updatedData = mergeBundleUpdate(pendingChange.data, newBundle);
71
81
  changedMap.set(targetBundleId, {
72
82
  operation: pendingChange.operation,
73
83
  data: updatedData
74
84
  });
75
85
  return;
76
86
  }
77
- const currentBundle = await getMethods().getBundleById(targetBundleId);
87
+ const currentBundle = context === void 0 ? await getMethods().getBundleById(targetBundleId) : await getMethods().getBundleById(targetBundleId, context);
78
88
  if (!currentBundle) throw new Error("targetBundleId not found");
79
- markChanged("update", (0, es_toolkit.merge)(currentBundle, newBundle));
89
+ markChanged("update", mergeBundleUpdate(currentBundle, newBundle));
80
90
  },
81
91
  async appendBundle(inputBundle) {
82
92
  markChanged("insert", inputBundle);
@@ -88,6 +98,5 @@ function createDatabasePlugin(options) {
88
98
  };
89
99
  };
90
100
  }
91
-
92
101
  //#endregion
93
- exports.createDatabasePlugin = createDatabasePlugin;
102
+ exports.createDatabasePlugin = createDatabasePlugin;
@@ -1,41 +1,34 @@
1
- import { DatabasePlugin, DatabasePluginHooks, PaginationInfo } from "./types/index.cjs";
1
+ import { DatabaseBundleQueryOptions, DatabasePlugin, DatabasePluginHooks, HotUpdaterContext, PaginationInfo } from "./types/index.cjs";
2
2
  import { Bundle } from "@hot-updater/core";
3
3
 
4
4
  //#region src/createDatabasePlugin.d.ts
5
- interface AbstractDatabasePlugin {
6
- getBundleById: (bundleId: string) => Promise<Bundle | null>;
7
- getBundles: (options: {
8
- where?: {
9
- channel?: string;
10
- platform?: string;
11
- };
12
- limit: number;
13
- offset: number;
14
- }) => Promise<{
5
+ interface AbstractDatabasePlugin<TContext = unknown> {
6
+ getBundleById: (bundleId: string, context?: HotUpdaterContext<TContext>) => Promise<Bundle | null>;
7
+ getBundles: (options: DatabaseBundleQueryOptions, context?: HotUpdaterContext<TContext>) => Promise<{
15
8
  data: Bundle[];
16
9
  pagination: PaginationInfo;
17
10
  }>;
18
- getChannels: () => Promise<string[]>;
11
+ getChannels: (context?: HotUpdaterContext<TContext>) => Promise<string[]>;
19
12
  onUnmount?: () => Promise<void>;
20
13
  commitBundle: (params: {
21
14
  changedSets: {
22
15
  operation: "insert" | "update" | "delete";
23
16
  data: Bundle;
24
17
  }[];
25
- }) => Promise<void>;
18
+ }, context?: HotUpdaterContext<TContext>) => Promise<void>;
26
19
  }
27
20
  /**
28
21
  * Database plugin methods without name
29
22
  */
30
- type DatabasePluginMethods = Omit<AbstractDatabasePlugin, never>;
23
+ type DatabasePluginMethods<TContext = unknown> = Omit<AbstractDatabasePlugin<TContext>, never>;
31
24
  /**
32
25
  * Factory function that creates database plugin methods
33
26
  */
34
- type DatabasePluginFactory<TConfig> = (config: TConfig) => DatabasePluginMethods;
27
+ type DatabasePluginFactory<TConfig, TContext = unknown> = (config: TConfig) => DatabasePluginMethods<TContext>;
35
28
  /**
36
29
  * Configuration options for creating a database plugin
37
30
  */
38
- interface CreateDatabasePluginOptions<TConfig> {
31
+ interface CreateDatabasePluginOptions<TConfig, TContext = unknown> {
39
32
  /**
40
33
  * The name of the database plugin (e.g., "postgres", "d1Database")
41
34
  */
@@ -43,7 +36,7 @@ interface CreateDatabasePluginOptions<TConfig> {
43
36
  /**
44
37
  * Function that creates the database plugin methods
45
38
  */
46
- factory: DatabasePluginFactory<TConfig>;
39
+ factory: DatabasePluginFactory<TConfig, TContext>;
47
40
  }
48
41
  /**
49
42
  * Creates a database plugin with lazy initialization and automatic hook execution.
@@ -71,6 +64,6 @@ interface CreateDatabasePluginOptions<TConfig> {
71
64
  * });
72
65
  * ```
73
66
  */
74
- declare function createDatabasePlugin<TConfig>(options: CreateDatabasePluginOptions<TConfig>): (config: TConfig, hooks?: DatabasePluginHooks) => (() => DatabasePlugin);
67
+ declare function createDatabasePlugin<TConfig, TContext = unknown>(options: CreateDatabasePluginOptions<TConfig, TContext>): (config: TConfig, hooks?: DatabasePluginHooks) => (() => DatabasePlugin<TContext>);
75
68
  //#endregion
76
69
  export { AbstractDatabasePlugin, CreateDatabasePluginOptions, createDatabasePlugin };
@@ -1,41 +1,34 @@
1
- import { DatabasePlugin, DatabasePluginHooks, PaginationInfo } from "./types/index.js";
1
+ import { DatabaseBundleQueryOptions, DatabasePlugin, DatabasePluginHooks, HotUpdaterContext, PaginationInfo } from "./types/index.mjs";
2
2
  import { Bundle } from "@hot-updater/core";
3
3
 
4
4
  //#region src/createDatabasePlugin.d.ts
5
- interface AbstractDatabasePlugin {
6
- getBundleById: (bundleId: string) => Promise<Bundle | null>;
7
- getBundles: (options: {
8
- where?: {
9
- channel?: string;
10
- platform?: string;
11
- };
12
- limit: number;
13
- offset: number;
14
- }) => Promise<{
5
+ interface AbstractDatabasePlugin<TContext = unknown> {
6
+ getBundleById: (bundleId: string, context?: HotUpdaterContext<TContext>) => Promise<Bundle | null>;
7
+ getBundles: (options: DatabaseBundleQueryOptions, context?: HotUpdaterContext<TContext>) => Promise<{
15
8
  data: Bundle[];
16
9
  pagination: PaginationInfo;
17
10
  }>;
18
- getChannels: () => Promise<string[]>;
11
+ getChannels: (context?: HotUpdaterContext<TContext>) => Promise<string[]>;
19
12
  onUnmount?: () => Promise<void>;
20
13
  commitBundle: (params: {
21
14
  changedSets: {
22
15
  operation: "insert" | "update" | "delete";
23
16
  data: Bundle;
24
17
  }[];
25
- }) => Promise<void>;
18
+ }, context?: HotUpdaterContext<TContext>) => Promise<void>;
26
19
  }
27
20
  /**
28
21
  * Database plugin methods without name
29
22
  */
30
- type DatabasePluginMethods = Omit<AbstractDatabasePlugin, never>;
23
+ type DatabasePluginMethods<TContext = unknown> = Omit<AbstractDatabasePlugin<TContext>, never>;
31
24
  /**
32
25
  * Factory function that creates database plugin methods
33
26
  */
34
- type DatabasePluginFactory<TConfig> = (config: TConfig) => DatabasePluginMethods;
27
+ type DatabasePluginFactory<TConfig, TContext = unknown> = (config: TConfig) => DatabasePluginMethods<TContext>;
35
28
  /**
36
29
  * Configuration options for creating a database plugin
37
30
  */
38
- interface CreateDatabasePluginOptions<TConfig> {
31
+ interface CreateDatabasePluginOptions<TConfig, TContext = unknown> {
39
32
  /**
40
33
  * The name of the database plugin (e.g., "postgres", "d1Database")
41
34
  */
@@ -43,7 +36,7 @@ interface CreateDatabasePluginOptions<TConfig> {
43
36
  /**
44
37
  * Function that creates the database plugin methods
45
38
  */
46
- factory: DatabasePluginFactory<TConfig>;
39
+ factory: DatabasePluginFactory<TConfig, TContext>;
47
40
  }
48
41
  /**
49
42
  * Creates a database plugin with lazy initialization and automatic hook execution.
@@ -71,6 +64,6 @@ interface CreateDatabasePluginOptions<TConfig> {
71
64
  * });
72
65
  * ```
73
66
  */
74
- declare function createDatabasePlugin<TConfig>(options: CreateDatabasePluginOptions<TConfig>): (config: TConfig, hooks?: DatabasePluginHooks) => (() => DatabasePlugin);
67
+ declare function createDatabasePlugin<TConfig, TContext = unknown>(options: CreateDatabasePluginOptions<TConfig, TContext>): (config: TConfig, hooks?: DatabasePluginHooks) => (() => DatabasePlugin<TContext>);
75
68
  //#endregion
76
69
  export { AbstractDatabasePlugin, CreateDatabasePluginOptions, createDatabasePlugin };