@hot-updater/plugin-core 0.33.0 → 0.33.1

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.
@@ -1,5 +1,7 @@
1
1
  require("./_virtual/_rolldown/runtime.cjs");
2
2
  const require_calculatePagination = require("./calculatePagination.cjs");
3
+ const require_bundleUnitOfWork = require("./bundleUnitOfWork.cjs");
4
+ const require_bundleUnitOfWorkStore = require("./bundleUnitOfWorkStore.cjs");
3
5
  let es_toolkit = require("es-toolkit");
4
6
  //#region src/createDatabasePlugin.ts
5
7
  const REPLACE_ON_UPDATE_KEYS = ["patches", "targetCohorts"];
@@ -12,7 +14,7 @@ function normalizePage(value) {
12
14
  return value;
13
15
  }
14
16
  function mergeBundleUpdate(baseBundle, patch) {
15
- return (0, es_toolkit.mergeWith)(baseBundle, patch, (_targetValue, sourceValue, key) => {
17
+ return (0, es_toolkit.mergeWith)({ ...baseBundle }, patch, (_targetValue, sourceValue, key) => {
16
18
  if (REPLACE_ON_UPDATE_KEYS.includes(key)) return sourceValue;
17
19
  });
18
20
  }
@@ -68,6 +70,27 @@ function createPaginatedResult(total, limit, startIndex, data) {
68
70
  }
69
71
  };
70
72
  }
73
+ function expandLimitForUnitOfWork(options, unitOfWork) {
74
+ const extraLimit = unitOfWork.listFetchExtraCount();
75
+ if (extraLimit === 0) return options;
76
+ return {
77
+ ...options,
78
+ limit: options.limit + extraLimit
79
+ };
80
+ }
81
+ function adjustPaginationTotal(pagination, options) {
82
+ if (options.totalDelta === 0) return pagination;
83
+ const total = Math.max(0, pagination.total + options.totalDelta);
84
+ const hasPreviousPage = pagination.currentPage > 1;
85
+ const hasNextPage = pagination.currentPage * options.limit < total;
86
+ return {
87
+ ...pagination,
88
+ total,
89
+ hasNextPage,
90
+ hasPreviousPage,
91
+ totalPages: total === 0 ? 0 : Math.ceil(total / options.limit)
92
+ };
93
+ }
71
94
  /**
72
95
  * Creates a database plugin with lazy initialization and automatic hook execution.
73
96
  *
@@ -102,12 +125,12 @@ function createDatabasePlugin(options) {
102
125
  return cachedMethods;
103
126
  };
104
127
  return () => {
105
- const changedMap = /* @__PURE__ */ new Map();
106
- const markChanged = (operation, data) => {
107
- changedMap.set(data.id, {
108
- operation,
109
- data
110
- });
128
+ const instanceMutationUnitOfWork = new require_bundleUnitOfWork.BundleUnitOfWork();
129
+ const getRequestUnitOfWork = (context) => {
130
+ return require_bundleUnitOfWorkStore.getRequestBundleUnitOfWork(context);
131
+ };
132
+ const getMutationUnitOfWork = (context) => {
133
+ return getRequestUnitOfWork(context) ?? instanceMutationUnitOfWork;
111
134
  };
112
135
  const runGetBundles = async (options, context) => {
113
136
  if (context === void 0) return getMethods().getBundles(options);
@@ -165,22 +188,41 @@ function createDatabasePlugin(options) {
165
188
  const plugin = {
166
189
  name: options.name,
167
190
  async getBundleById(bundleId, context) {
168
- if (context === void 0) return getMethods().getBundleById(bundleId);
169
- return getMethods().getBundleById(bundleId, context);
191
+ const requestUnitOfWork = getRequestUnitOfWork(context);
192
+ if (requestUnitOfWork) return requestUnitOfWork.getById(bundleId, () => getMethods().getBundleById(bundleId, context));
193
+ const pendingMutation = instanceMutationUnitOfWork.peekChanged(bundleId);
194
+ if (pendingMutation.found) return pendingMutation.value;
195
+ return getMethods().getBundleById(bundleId);
170
196
  },
171
197
  async getBundles(options, context) {
172
198
  if (typeof options === "object" && options !== null && "offset" in options && options.offset !== void 0) throw new Error("Bundle offset pagination has been removed. Use cursor.after or cursor.before instead.");
173
199
  const methods = getMethods();
200
+ const requestUnitOfWork = getRequestUnitOfWork(context);
201
+ const unitOfWork = requestUnitOfWork ?? instanceMutationUnitOfWork;
202
+ const shouldOverlay = requestUnitOfWork !== null || instanceMutationUnitOfWork.hasChanges();
174
203
  const normalizedOptions = {
175
204
  ...options,
176
205
  page: normalizePage(options.page),
177
206
  orderBy: options.orderBy ?? DEFAULT_DESC_ORDER
178
207
  };
208
+ const overlayResult = (result) => ({
209
+ ...result,
210
+ data: unitOfWork.overlayList(result.data, {
211
+ limit: normalizedOptions.limit,
212
+ orderBy: normalizedOptions.orderBy,
213
+ where: normalizedOptions.where
214
+ }),
215
+ pagination: adjustPaginationTotal(result.pagination, {
216
+ limit: normalizedOptions.limit,
217
+ totalDelta: unitOfWork.totalDelta(normalizedOptions.where)
218
+ })
219
+ });
179
220
  if (normalizedOptions.page !== void 0) {
180
221
  const { page, ...pageOptions } = normalizedOptions;
181
222
  const requestedOffset = (page - 1) * normalizedOptions.limit;
223
+ const fetchPageOptions = expandLimitForUnitOfWork(pageOptions, unitOfWork);
182
224
  let pageResult = await runGetBundles({
183
- ...pageOptions,
225
+ ...fetchPageOptions,
184
226
  offset: requestedOffset
185
227
  }, context);
186
228
  const total = pageResult.pagination.total;
@@ -188,16 +230,19 @@ function createDatabasePlugin(options) {
188
230
  const maxOffset = totalPages === 0 ? 0 : (Math.max(1, totalPages) - 1) * normalizedOptions.limit;
189
231
  const resolvedOffset = Math.min(requestedOffset, maxOffset);
190
232
  if (resolvedOffset !== requestedOffset) pageResult = await runGetBundles({
191
- ...pageOptions,
233
+ ...fetchPageOptions,
192
234
  offset: resolvedOffset
193
235
  }, context);
194
- return createPaginatedResult(total, normalizedOptions.limit, resolvedOffset, pageResult.data);
236
+ const result = { ...createPaginatedResult(total, normalizedOptions.limit, resolvedOffset, pageResult.data) };
237
+ return shouldOverlay ? overlayResult(result) : result;
195
238
  }
196
239
  if (methods.supportsCursorPagination) {
197
- if (context === void 0) return methods.getBundles(normalizedOptions);
198
- return methods.getBundles(normalizedOptions, context);
240
+ const fetchOptions = expandLimitForUnitOfWork(normalizedOptions, unitOfWork);
241
+ const result = context === void 0 ? await methods.getBundles(fetchOptions) : await methods.getBundles(fetchOptions, context);
242
+ return shouldOverlay ? overlayResult(result) : result;
199
243
  }
200
- return getBundlesWithLegacyCursorFallback(normalizedOptions, context);
244
+ const result = await getBundlesWithLegacyCursorFallback(shouldOverlay ? expandLimitForUnitOfWork(normalizedOptions, unitOfWork) : normalizedOptions, context);
245
+ return shouldOverlay ? overlayResult(result) : result;
201
246
  },
202
247
  async getChannels(context) {
203
248
  if (context === void 0) return getMethods().getChannels();
@@ -209,31 +254,25 @@ function createDatabasePlugin(options) {
209
254
  },
210
255
  async commitBundle(context) {
211
256
  const methods = getMethods();
212
- const params = { changedSets: Array.from(changedMap.values()) };
257
+ const unitOfWork = getMutationUnitOfWork(context);
258
+ const params = { changedSets: unitOfWork.changedSets() };
213
259
  if (context === void 0) await methods.commitBundle(params);
214
260
  else await methods.commitBundle(params, context);
215
- changedMap.clear();
261
+ unitOfWork.clear();
216
262
  await hooks?.onDatabaseUpdated?.();
217
263
  },
218
264
  async updateBundle(targetBundleId, newBundle, context) {
219
- const pendingChange = changedMap.get(targetBundleId);
220
- if (pendingChange) {
221
- const updatedData = mergeBundleUpdate(pendingChange.data, newBundle);
222
- changedMap.set(targetBundleId, {
223
- operation: pendingChange.operation,
224
- data: updatedData
225
- });
226
- return;
227
- }
228
- const currentBundle = context === void 0 ? await getMethods().getBundleById(targetBundleId) : await getMethods().getBundleById(targetBundleId, context);
265
+ const unitOfWork = getMutationUnitOfWork(context);
266
+ const currentBundle = await unitOfWork.getById(targetBundleId, () => context === void 0 ? getMethods().getBundleById(targetBundleId) : getMethods().getBundleById(targetBundleId, context));
229
267
  if (!currentBundle) throw new Error("targetBundleId not found");
230
- markChanged("update", mergeBundleUpdate(currentBundle, newBundle));
268
+ const updatedBundle = mergeBundleUpdate(currentBundle, newBundle);
269
+ unitOfWork.markUpdate(updatedBundle);
231
270
  },
232
- async appendBundle(inputBundle) {
233
- markChanged("insert", inputBundle);
271
+ async appendBundle(inputBundle, context) {
272
+ getMutationUnitOfWork(context).markInsert(inputBundle);
234
273
  },
235
- async deleteBundle(deleteBundle) {
236
- markChanged("delete", deleteBundle);
274
+ async deleteBundle(deleteBundle, context) {
275
+ getMutationUnitOfWork(context).markDelete(deleteBundle);
237
276
  }
238
277
  };
239
278
  Object.defineProperty(plugin, "getUpdateInfo", {
@@ -1,4 +1,6 @@
1
1
  import { calculatePagination } from "./calculatePagination.mjs";
2
+ import { BundleUnitOfWork } from "./bundleUnitOfWork.mjs";
3
+ import { getRequestBundleUnitOfWork } from "./bundleUnitOfWorkStore.mjs";
2
4
  import { mergeWith } from "es-toolkit";
3
5
  //#region src/createDatabasePlugin.ts
4
6
  const REPLACE_ON_UPDATE_KEYS = ["patches", "targetCohorts"];
@@ -11,7 +13,7 @@ function normalizePage(value) {
11
13
  return value;
12
14
  }
13
15
  function mergeBundleUpdate(baseBundle, patch) {
14
- return mergeWith(baseBundle, patch, (_targetValue, sourceValue, key) => {
16
+ return mergeWith({ ...baseBundle }, patch, (_targetValue, sourceValue, key) => {
15
17
  if (REPLACE_ON_UPDATE_KEYS.includes(key)) return sourceValue;
16
18
  });
17
19
  }
@@ -67,6 +69,27 @@ function createPaginatedResult(total, limit, startIndex, data) {
67
69
  }
68
70
  };
69
71
  }
72
+ function expandLimitForUnitOfWork(options, unitOfWork) {
73
+ const extraLimit = unitOfWork.listFetchExtraCount();
74
+ if (extraLimit === 0) return options;
75
+ return {
76
+ ...options,
77
+ limit: options.limit + extraLimit
78
+ };
79
+ }
80
+ function adjustPaginationTotal(pagination, options) {
81
+ if (options.totalDelta === 0) return pagination;
82
+ const total = Math.max(0, pagination.total + options.totalDelta);
83
+ const hasPreviousPage = pagination.currentPage > 1;
84
+ const hasNextPage = pagination.currentPage * options.limit < total;
85
+ return {
86
+ ...pagination,
87
+ total,
88
+ hasNextPage,
89
+ hasPreviousPage,
90
+ totalPages: total === 0 ? 0 : Math.ceil(total / options.limit)
91
+ };
92
+ }
70
93
  /**
71
94
  * Creates a database plugin with lazy initialization and automatic hook execution.
72
95
  *
@@ -101,12 +124,12 @@ function createDatabasePlugin(options) {
101
124
  return cachedMethods;
102
125
  };
103
126
  return () => {
104
- const changedMap = /* @__PURE__ */ new Map();
105
- const markChanged = (operation, data) => {
106
- changedMap.set(data.id, {
107
- operation,
108
- data
109
- });
127
+ const instanceMutationUnitOfWork = new BundleUnitOfWork();
128
+ const getRequestUnitOfWork = (context) => {
129
+ return getRequestBundleUnitOfWork(context);
130
+ };
131
+ const getMutationUnitOfWork = (context) => {
132
+ return getRequestUnitOfWork(context) ?? instanceMutationUnitOfWork;
110
133
  };
111
134
  const runGetBundles = async (options, context) => {
112
135
  if (context === void 0) return getMethods().getBundles(options);
@@ -164,22 +187,41 @@ function createDatabasePlugin(options) {
164
187
  const plugin = {
165
188
  name: options.name,
166
189
  async getBundleById(bundleId, context) {
167
- if (context === void 0) return getMethods().getBundleById(bundleId);
168
- return getMethods().getBundleById(bundleId, context);
190
+ const requestUnitOfWork = getRequestUnitOfWork(context);
191
+ if (requestUnitOfWork) return requestUnitOfWork.getById(bundleId, () => getMethods().getBundleById(bundleId, context));
192
+ const pendingMutation = instanceMutationUnitOfWork.peekChanged(bundleId);
193
+ if (pendingMutation.found) return pendingMutation.value;
194
+ return getMethods().getBundleById(bundleId);
169
195
  },
170
196
  async getBundles(options, context) {
171
197
  if (typeof options === "object" && options !== null && "offset" in options && options.offset !== void 0) throw new Error("Bundle offset pagination has been removed. Use cursor.after or cursor.before instead.");
172
198
  const methods = getMethods();
199
+ const requestUnitOfWork = getRequestUnitOfWork(context);
200
+ const unitOfWork = requestUnitOfWork ?? instanceMutationUnitOfWork;
201
+ const shouldOverlay = requestUnitOfWork !== null || instanceMutationUnitOfWork.hasChanges();
173
202
  const normalizedOptions = {
174
203
  ...options,
175
204
  page: normalizePage(options.page),
176
205
  orderBy: options.orderBy ?? DEFAULT_DESC_ORDER
177
206
  };
207
+ const overlayResult = (result) => ({
208
+ ...result,
209
+ data: unitOfWork.overlayList(result.data, {
210
+ limit: normalizedOptions.limit,
211
+ orderBy: normalizedOptions.orderBy,
212
+ where: normalizedOptions.where
213
+ }),
214
+ pagination: adjustPaginationTotal(result.pagination, {
215
+ limit: normalizedOptions.limit,
216
+ totalDelta: unitOfWork.totalDelta(normalizedOptions.where)
217
+ })
218
+ });
178
219
  if (normalizedOptions.page !== void 0) {
179
220
  const { page, ...pageOptions } = normalizedOptions;
180
221
  const requestedOffset = (page - 1) * normalizedOptions.limit;
222
+ const fetchPageOptions = expandLimitForUnitOfWork(pageOptions, unitOfWork);
181
223
  let pageResult = await runGetBundles({
182
- ...pageOptions,
224
+ ...fetchPageOptions,
183
225
  offset: requestedOffset
184
226
  }, context);
185
227
  const total = pageResult.pagination.total;
@@ -187,16 +229,19 @@ function createDatabasePlugin(options) {
187
229
  const maxOffset = totalPages === 0 ? 0 : (Math.max(1, totalPages) - 1) * normalizedOptions.limit;
188
230
  const resolvedOffset = Math.min(requestedOffset, maxOffset);
189
231
  if (resolvedOffset !== requestedOffset) pageResult = await runGetBundles({
190
- ...pageOptions,
232
+ ...fetchPageOptions,
191
233
  offset: resolvedOffset
192
234
  }, context);
193
- return createPaginatedResult(total, normalizedOptions.limit, resolvedOffset, pageResult.data);
235
+ const result = { ...createPaginatedResult(total, normalizedOptions.limit, resolvedOffset, pageResult.data) };
236
+ return shouldOverlay ? overlayResult(result) : result;
194
237
  }
195
238
  if (methods.supportsCursorPagination) {
196
- if (context === void 0) return methods.getBundles(normalizedOptions);
197
- return methods.getBundles(normalizedOptions, context);
239
+ const fetchOptions = expandLimitForUnitOfWork(normalizedOptions, unitOfWork);
240
+ const result = context === void 0 ? await methods.getBundles(fetchOptions) : await methods.getBundles(fetchOptions, context);
241
+ return shouldOverlay ? overlayResult(result) : result;
198
242
  }
199
- return getBundlesWithLegacyCursorFallback(normalizedOptions, context);
243
+ const result = await getBundlesWithLegacyCursorFallback(shouldOverlay ? expandLimitForUnitOfWork(normalizedOptions, unitOfWork) : normalizedOptions, context);
244
+ return shouldOverlay ? overlayResult(result) : result;
200
245
  },
201
246
  async getChannels(context) {
202
247
  if (context === void 0) return getMethods().getChannels();
@@ -208,31 +253,25 @@ function createDatabasePlugin(options) {
208
253
  },
209
254
  async commitBundle(context) {
210
255
  const methods = getMethods();
211
- const params = { changedSets: Array.from(changedMap.values()) };
256
+ const unitOfWork = getMutationUnitOfWork(context);
257
+ const params = { changedSets: unitOfWork.changedSets() };
212
258
  if (context === void 0) await methods.commitBundle(params);
213
259
  else await methods.commitBundle(params, context);
214
- changedMap.clear();
260
+ unitOfWork.clear();
215
261
  await hooks?.onDatabaseUpdated?.();
216
262
  },
217
263
  async updateBundle(targetBundleId, newBundle, context) {
218
- const pendingChange = changedMap.get(targetBundleId);
219
- if (pendingChange) {
220
- const updatedData = mergeBundleUpdate(pendingChange.data, newBundle);
221
- changedMap.set(targetBundleId, {
222
- operation: pendingChange.operation,
223
- data: updatedData
224
- });
225
- return;
226
- }
227
- const currentBundle = context === void 0 ? await getMethods().getBundleById(targetBundleId) : await getMethods().getBundleById(targetBundleId, context);
264
+ const unitOfWork = getMutationUnitOfWork(context);
265
+ const currentBundle = await unitOfWork.getById(targetBundleId, () => context === void 0 ? getMethods().getBundleById(targetBundleId) : getMethods().getBundleById(targetBundleId, context));
228
266
  if (!currentBundle) throw new Error("targetBundleId not found");
229
- markChanged("update", mergeBundleUpdate(currentBundle, newBundle));
267
+ const updatedBundle = mergeBundleUpdate(currentBundle, newBundle);
268
+ unitOfWork.markUpdate(updatedBundle);
230
269
  },
231
- async appendBundle(inputBundle) {
232
- markChanged("insert", inputBundle);
270
+ async appendBundle(inputBundle, context) {
271
+ getMutationUnitOfWork(context).markInsert(inputBundle);
233
272
  },
234
- async deleteBundle(deleteBundle) {
235
- markChanged("delete", deleteBundle);
273
+ async deleteBundle(deleteBundle, context) {
274
+ getMutationUnitOfWork(context).markDelete(deleteBundle);
236
275
  }
237
276
  };
238
277
  Object.defineProperty(plugin, "getUpdateInfo", {
package/dist/index.cjs CHANGED
@@ -3,10 +3,10 @@ const require_calculatePagination = require("./calculatePagination.cjs");
3
3
  const require_compressionFormat = require("./compressionFormat.cjs");
4
4
  const require_contentAddressedAssets = require("./contentAddressedAssets.cjs");
5
5
  const require_assetStorageLayout = require("./assetStorageLayout.cjs");
6
+ const require_queryBundles = require("./queryBundles.cjs");
6
7
  const require_createDatabasePlugin = require("./createDatabasePlugin.cjs");
7
8
  const require_semverSatisfies = require("./semverSatisfies.cjs");
8
9
  const require_filterCompatibleAppVersions = require("./filterCompatibleAppVersions.cjs");
9
- const require_queryBundles = require("./queryBundles.cjs");
10
10
  const require_paginateBundles = require("./paginateBundles.cjs");
11
11
  const require_requestUpdateBundleState = require("./requestUpdateBundleState.cjs");
12
12
  const require_resolveUpdateInfoFromBundles = require("./resolveUpdateInfoFromBundles.cjs");
@@ -28,6 +28,7 @@ exports.createBlobDatabasePlugin = require_createBlobDatabasePlugin.createBlobDa
28
28
  exports.createDatabasePlugin = require_createDatabasePlugin.createDatabasePlugin;
29
29
  exports.createDatabasePluginGetUpdateInfo = require_createDatabasePluginGetUpdateInfo.createDatabasePluginGetUpdateInfo;
30
30
  exports.createNodeStoragePlugin = require_createStoragePlugin.createNodeStoragePlugin;
31
+ exports.createRequestUpdateBundleResolver = require_requestUpdateBundleState.createRequestUpdateBundleResolver;
31
32
  exports.createRuntimeStoragePlugin = require_createStoragePlugin.createRuntimeStoragePlugin;
32
33
  exports.createStorageKeyBuilder = require_createStorageKeyBuilder.createStorageKeyBuilder;
33
34
  exports.createStorageUriWithRelativePath = require_assetStorageLayout.createStorageUriWithRelativePath;
package/dist/index.d.cts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./types/utils.cjs";
2
- import { AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, BundleIndexDiagnostics, BundleIndexHealth, BundleIndexRepairResult, ConfigInput, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabaseDiagnostics, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NodeStoragePlugin, NodeStorageProfile, Paginated, PaginatedResult, PaginationInfo, Platform, PlatformConfig, RequestEnvContext, RuntimeStoragePlugin, RuntimeStorageProfile, SigningConfig, StoragePlugin, StoragePluginHooks, StoragePluginProfiles, StorageResolveContext, UniversalStoragePlugin, UpdateInfo, supportedIosPlatforms } from "./types/index.cjs";
2
+ import { AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, ConfigInput, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NodeStoragePlugin, NodeStorageProfile, Paginated, PaginatedResult, PaginationInfo, Platform, PlatformConfig, RequestEnvContext, RuntimeStoragePlugin, RuntimeStorageProfile, SigningConfig, StoragePlugin, StoragePluginHooks, StoragePluginProfiles, StorageResolveContext, UniversalStoragePlugin, UpdateInfo, supportedIosPlatforms } from "./types/index.cjs";
3
3
  import { PaginationOptions, calculatePagination } from "./calculatePagination.cjs";
4
4
  import { CompressionFormat, CompressionFormatInfo, detectCompressionFormat, getCompressionMimeType, getContentType } from "./compressionFormat.cjs";
5
5
  import { AssetStorageLayout, createStorageUriWithRelativePath, getAssetStorageLayout, getManifestAssetStoragePath, isContentAddressedAssetBaseStorageUri, resolveManifestAssetStorageUri } from "./assetStorageLayout.cjs";
6
6
  import { getContentAddressedAssetStoragePath } from "./contentAddressedAssets.cjs";
7
- import { BlobDatabasePluginConfig, BlobOperations, createBlobDatabasePlugin } from "./createBlobDatabasePlugin.cjs";
7
+ import { BlobOperations, createBlobDatabasePlugin } from "./createBlobDatabasePlugin.cjs";
8
8
  import { AbstractDatabasePlugin, CreateDatabasePluginOptions, createDatabasePlugin } from "./createDatabasePlugin.cjs";
9
9
  import { CreateDatabasePluginGetUpdateInfoOptions, createDatabasePluginGetUpdateInfo } from "./createDatabasePluginGetUpdateInfo.cjs";
10
10
  import { createStorageKeyBuilder } from "./createStorageKeyBuilder.cjs";
@@ -14,9 +14,9 @@ import { generateMinBundleId } from "./generateMinBundleId.cjs";
14
14
  import { ParsedStorageUri, parseStorageUri } from "./parseStorageUri.cjs";
15
15
  import { paginateBundles } from "./paginateBundles.cjs";
16
16
  import { bundleIdMatchesFilter, bundleMatchesQueryWhere, sortBundles } from "./queryBundles.cjs";
17
- import { getRequestUpdateBundleSeeds } from "./requestUpdateBundleState.cjs";
17
+ import { createRequestUpdateBundleResolver, getRequestUpdateBundleSeeds } from "./requestUpdateBundleState.cjs";
18
18
  import { ResolveUpdateInfoFromBundlesOptions, resolveUpdateInfoFromBundles } from "./resolveUpdateInfoFromBundles.cjs";
19
19
  import { semverSatisfies } from "./semverSatisfies.cjs";
20
20
  import { assertNodeStoragePlugin, assertRuntimeStoragePlugin, isNodeStoragePlugin, isRuntimeStoragePlugin } from "./storageProfile.cjs";
21
21
  import { createUUIDv7, createUUIDv7WithSameTimestamp, extractTimestampFromUUIDv7 } from "./uuidv7.cjs";
22
- export { AbstractDatabasePlugin, AppVersionGetBundlesArgs, ApplePlatform, AssetStorageLayout, BasePluginArgs, BlobDatabasePluginConfig, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, BundleIndexDiagnostics, BundleIndexHealth, BundleIndexRepairResult, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginGetUpdateInfoOptions, CreateDatabasePluginOptions, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabaseDiagnostics, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HasMultipleCallSignatures, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NodeStoragePlugin, NodeStorageProfile, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequestEnvContext, RequiredDeep, ResolveUpdateInfoFromBundlesOptions, RuntimeStoragePlugin, RuntimeStorageProfile, SigningConfig, StoragePlugin, StoragePluginHooks, StoragePluginProfiles, StorageResolveContext, UniversalStoragePlugin, UpdateInfo, assertNodeStoragePlugin, assertRuntimeStoragePlugin, bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createDatabasePluginGetUpdateInfo, createNodeStoragePlugin, createRuntimeStoragePlugin, createStorageKeyBuilder, createStorageUriWithRelativePath, createUUIDv7, createUUIDv7WithSameTimestamp, createUniversalStoragePlugin, detectCompressionFormat, extractTimestampFromUUIDv7, filterCompatibleAppVersions, generateMinBundleId, getAssetStorageLayout, getCompressionMimeType, getContentAddressedAssetStoragePath, getContentType, getManifestAssetStoragePath, getRequestUpdateBundleSeeds, isContentAddressedAssetBaseStorageUri, isNodeStoragePlugin, isRuntimeStoragePlugin, paginateBundles, parseStorageUri, resolveManifestAssetStorageUri, resolveUpdateInfoFromBundles, semverSatisfies, sortBundles, supportedIosPlatforms };
22
+ export { AbstractDatabasePlugin, AppVersionGetBundlesArgs, ApplePlatform, AssetStorageLayout, BasePluginArgs, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginGetUpdateInfoOptions, CreateDatabasePluginOptions, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HasMultipleCallSignatures, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NodeStoragePlugin, NodeStorageProfile, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequestEnvContext, RequiredDeep, ResolveUpdateInfoFromBundlesOptions, RuntimeStoragePlugin, RuntimeStorageProfile, SigningConfig, StoragePlugin, StoragePluginHooks, StoragePluginProfiles, StorageResolveContext, UniversalStoragePlugin, UpdateInfo, assertNodeStoragePlugin, assertRuntimeStoragePlugin, bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createDatabasePluginGetUpdateInfo, createNodeStoragePlugin, createRequestUpdateBundleResolver, createRuntimeStoragePlugin, createStorageKeyBuilder, createStorageUriWithRelativePath, createUUIDv7, createUUIDv7WithSameTimestamp, createUniversalStoragePlugin, detectCompressionFormat, extractTimestampFromUUIDv7, filterCompatibleAppVersions, generateMinBundleId, getAssetStorageLayout, getCompressionMimeType, getContentAddressedAssetStoragePath, getContentType, getManifestAssetStoragePath, getRequestUpdateBundleSeeds, isContentAddressedAssetBaseStorageUri, isNodeStoragePlugin, isRuntimeStoragePlugin, paginateBundles, parseStorageUri, resolveManifestAssetStorageUri, resolveUpdateInfoFromBundles, semverSatisfies, sortBundles, supportedIosPlatforms };
package/dist/index.d.mts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./types/utils.mjs";
2
- import { AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, BundleIndexDiagnostics, BundleIndexHealth, BundleIndexRepairResult, ConfigInput, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabaseDiagnostics, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NodeStoragePlugin, NodeStorageProfile, Paginated, PaginatedResult, PaginationInfo, Platform, PlatformConfig, RequestEnvContext, RuntimeStoragePlugin, RuntimeStorageProfile, SigningConfig, StoragePlugin, StoragePluginHooks, StoragePluginProfiles, StorageResolveContext, UniversalStoragePlugin, UpdateInfo, supportedIosPlatforms } from "./types/index.mjs";
2
+ import { AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, ConfigInput, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NodeStoragePlugin, NodeStorageProfile, Paginated, PaginatedResult, PaginationInfo, Platform, PlatformConfig, RequestEnvContext, RuntimeStoragePlugin, RuntimeStorageProfile, SigningConfig, StoragePlugin, StoragePluginHooks, StoragePluginProfiles, StorageResolveContext, UniversalStoragePlugin, UpdateInfo, supportedIosPlatforms } from "./types/index.mjs";
3
3
  import { PaginationOptions, calculatePagination } from "./calculatePagination.mjs";
4
4
  import { CompressionFormat, CompressionFormatInfo, detectCompressionFormat, getCompressionMimeType, getContentType } from "./compressionFormat.mjs";
5
5
  import { AssetStorageLayout, createStorageUriWithRelativePath, getAssetStorageLayout, getManifestAssetStoragePath, isContentAddressedAssetBaseStorageUri, resolveManifestAssetStorageUri } from "./assetStorageLayout.mjs";
6
6
  import { getContentAddressedAssetStoragePath } from "./contentAddressedAssets.mjs";
7
- import { BlobDatabasePluginConfig, BlobOperations, createBlobDatabasePlugin } from "./createBlobDatabasePlugin.mjs";
7
+ import { BlobOperations, createBlobDatabasePlugin } from "./createBlobDatabasePlugin.mjs";
8
8
  import { AbstractDatabasePlugin, CreateDatabasePluginOptions, createDatabasePlugin } from "./createDatabasePlugin.mjs";
9
9
  import { CreateDatabasePluginGetUpdateInfoOptions, createDatabasePluginGetUpdateInfo } from "./createDatabasePluginGetUpdateInfo.mjs";
10
10
  import { createStorageKeyBuilder } from "./createStorageKeyBuilder.mjs";
@@ -14,9 +14,9 @@ import { generateMinBundleId } from "./generateMinBundleId.mjs";
14
14
  import { ParsedStorageUri, parseStorageUri } from "./parseStorageUri.mjs";
15
15
  import { paginateBundles } from "./paginateBundles.mjs";
16
16
  import { bundleIdMatchesFilter, bundleMatchesQueryWhere, sortBundles } from "./queryBundles.mjs";
17
- import { getRequestUpdateBundleSeeds } from "./requestUpdateBundleState.mjs";
17
+ import { createRequestUpdateBundleResolver, getRequestUpdateBundleSeeds } from "./requestUpdateBundleState.mjs";
18
18
  import { ResolveUpdateInfoFromBundlesOptions, resolveUpdateInfoFromBundles } from "./resolveUpdateInfoFromBundles.mjs";
19
19
  import { semverSatisfies } from "./semverSatisfies.mjs";
20
20
  import { assertNodeStoragePlugin, assertRuntimeStoragePlugin, isNodeStoragePlugin, isRuntimeStoragePlugin } from "./storageProfile.mjs";
21
21
  import { createUUIDv7, createUUIDv7WithSameTimestamp, extractTimestampFromUUIDv7 } from "./uuidv7.mjs";
22
- export { AbstractDatabasePlugin, AppVersionGetBundlesArgs, ApplePlatform, AssetStorageLayout, BasePluginArgs, BlobDatabasePluginConfig, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, BundleIndexDiagnostics, BundleIndexHealth, BundleIndexRepairResult, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginGetUpdateInfoOptions, CreateDatabasePluginOptions, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabaseDiagnostics, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HasMultipleCallSignatures, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NodeStoragePlugin, NodeStorageProfile, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequestEnvContext, RequiredDeep, ResolveUpdateInfoFromBundlesOptions, RuntimeStoragePlugin, RuntimeStorageProfile, SigningConfig, StoragePlugin, StoragePluginHooks, StoragePluginProfiles, StorageResolveContext, UniversalStoragePlugin, UpdateInfo, assertNodeStoragePlugin, assertRuntimeStoragePlugin, bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createDatabasePluginGetUpdateInfo, createNodeStoragePlugin, createRuntimeStoragePlugin, createStorageKeyBuilder, createStorageUriWithRelativePath, createUUIDv7, createUUIDv7WithSameTimestamp, createUniversalStoragePlugin, detectCompressionFormat, extractTimestampFromUUIDv7, filterCompatibleAppVersions, generateMinBundleId, getAssetStorageLayout, getCompressionMimeType, getContentAddressedAssetStoragePath, getContentType, getManifestAssetStoragePath, getRequestUpdateBundleSeeds, isContentAddressedAssetBaseStorageUri, isNodeStoragePlugin, isRuntimeStoragePlugin, paginateBundles, parseStorageUri, resolveManifestAssetStorageUri, resolveUpdateInfoFromBundles, semverSatisfies, sortBundles, supportedIosPlatforms };
22
+ export { AbstractDatabasePlugin, AppVersionGetBundlesArgs, ApplePlatform, AssetStorageLayout, BasePluginArgs, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginGetUpdateInfoOptions, CreateDatabasePluginOptions, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, FingerprintGetBundlesArgs, GetBundlesArgs, HasMultipleCallSignatures, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NodeStoragePlugin, NodeStorageProfile, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequestEnvContext, RequiredDeep, ResolveUpdateInfoFromBundlesOptions, RuntimeStoragePlugin, RuntimeStorageProfile, SigningConfig, StoragePlugin, StoragePluginHooks, StoragePluginProfiles, StorageResolveContext, UniversalStoragePlugin, UpdateInfo, assertNodeStoragePlugin, assertRuntimeStoragePlugin, bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createDatabasePluginGetUpdateInfo, createNodeStoragePlugin, createRequestUpdateBundleResolver, createRuntimeStoragePlugin, createStorageKeyBuilder, createStorageUriWithRelativePath, createUUIDv7, createUUIDv7WithSameTimestamp, createUniversalStoragePlugin, detectCompressionFormat, extractTimestampFromUUIDv7, filterCompatibleAppVersions, generateMinBundleId, getAssetStorageLayout, getCompressionMimeType, getContentAddressedAssetStoragePath, getContentType, getManifestAssetStoragePath, getRequestUpdateBundleSeeds, isContentAddressedAssetBaseStorageUri, isNodeStoragePlugin, isRuntimeStoragePlugin, paginateBundles, parseStorageUri, resolveManifestAssetStorageUri, resolveUpdateInfoFromBundles, semverSatisfies, sortBundles, supportedIosPlatforms };
package/dist/index.mjs CHANGED
@@ -2,12 +2,12 @@ import { calculatePagination } from "./calculatePagination.mjs";
2
2
  import { detectCompressionFormat, getCompressionMimeType, getContentType } from "./compressionFormat.mjs";
3
3
  import { getContentAddressedAssetStoragePath } from "./contentAddressedAssets.mjs";
4
4
  import { createStorageUriWithRelativePath, getAssetStorageLayout, getManifestAssetStoragePath, isContentAddressedAssetBaseStorageUri, resolveManifestAssetStorageUri } from "./assetStorageLayout.mjs";
5
+ import { bundleIdMatchesFilter, bundleMatchesQueryWhere, sortBundles } from "./queryBundles.mjs";
5
6
  import { createDatabasePlugin } from "./createDatabasePlugin.mjs";
6
7
  import { semverSatisfies } from "./semverSatisfies.mjs";
7
8
  import { filterCompatibleAppVersions } from "./filterCompatibleAppVersions.mjs";
8
- import { bundleIdMatchesFilter, bundleMatchesQueryWhere, sortBundles } from "./queryBundles.mjs";
9
9
  import { paginateBundles } from "./paginateBundles.mjs";
10
- import { getRequestUpdateBundleSeeds } from "./requestUpdateBundleState.mjs";
10
+ import { createRequestUpdateBundleResolver, getRequestUpdateBundleSeeds } from "./requestUpdateBundleState.mjs";
11
11
  import { resolveUpdateInfoFromBundles } from "./resolveUpdateInfoFromBundles.mjs";
12
12
  import { createBlobDatabasePlugin } from "./createBlobDatabasePlugin.mjs";
13
13
  import { createDatabasePluginGetUpdateInfo } from "./createDatabasePluginGetUpdateInfo.mjs";
@@ -18,4 +18,4 @@ import { parseStorageUri } from "./parseStorageUri.mjs";
18
18
  import { assertNodeStoragePlugin, assertRuntimeStoragePlugin, isNodeStoragePlugin, isRuntimeStoragePlugin } from "./storageProfile.mjs";
19
19
  import { supportedIosPlatforms } from "./types/index.mjs";
20
20
  import { createUUIDv7, createUUIDv7WithSameTimestamp, extractTimestampFromUUIDv7 } from "./uuidv7.mjs";
21
- export { assertNodeStoragePlugin, assertRuntimeStoragePlugin, bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createDatabasePluginGetUpdateInfo, createNodeStoragePlugin, createRuntimeStoragePlugin, createStorageKeyBuilder, createStorageUriWithRelativePath, createUUIDv7, createUUIDv7WithSameTimestamp, createUniversalStoragePlugin, detectCompressionFormat, extractTimestampFromUUIDv7, filterCompatibleAppVersions, generateMinBundleId, getAssetStorageLayout, getCompressionMimeType, getContentAddressedAssetStoragePath, getContentType, getManifestAssetStoragePath, getRequestUpdateBundleSeeds, isContentAddressedAssetBaseStorageUri, isNodeStoragePlugin, isRuntimeStoragePlugin, paginateBundles, parseStorageUri, resolveManifestAssetStorageUri, resolveUpdateInfoFromBundles, semverSatisfies, sortBundles, supportedIosPlatforms };
21
+ export { assertNodeStoragePlugin, assertRuntimeStoragePlugin, bundleIdMatchesFilter, bundleMatchesQueryWhere, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createDatabasePluginGetUpdateInfo, createNodeStoragePlugin, createRequestUpdateBundleResolver, createRuntimeStoragePlugin, createStorageKeyBuilder, createStorageUriWithRelativePath, createUUIDv7, createUUIDv7WithSameTimestamp, createUniversalStoragePlugin, detectCompressionFormat, extractTimestampFromUUIDv7, filterCompatibleAppVersions, generateMinBundleId, getAssetStorageLayout, getCompressionMimeType, getContentAddressedAssetStoragePath, getContentType, getManifestAssetStoragePath, getRequestUpdateBundleSeeds, isContentAddressedAssetBaseStorageUri, isNodeStoragePlugin, isRuntimeStoragePlugin, paginateBundles, parseStorageUri, resolveManifestAssetStorageUri, resolveUpdateInfoFromBundles, semverSatisfies, sortBundles, supportedIosPlatforms };
@@ -1,20 +1,26 @@
1
+ const require_bundleUnitOfWork = require("./bundleUnitOfWork.cjs");
2
+ const require_bundleUnitOfWorkStore = require("./bundleUnitOfWorkStore.cjs");
1
3
  //#region src/requestUpdateBundleState.ts
2
- const requestUpdateBundleSeeds = /* @__PURE__ */ new WeakMap();
3
- const isWeakMapKey = (value) => typeof value === "object" && value !== null || typeof value === "function";
4
4
  const toBundleSeeds = (seeds) => seeds.filter((seed) => !!seed);
5
5
  const seedRequestUpdateBundles = (context, seeds) => {
6
- if (!isWeakMapKey(context)) return;
6
+ const unitOfWork = require_bundleUnitOfWorkStore.getRequestBundleUnitOfWork(context);
7
+ if (!unitOfWork) return;
7
8
  const nextSeeds = toBundleSeeds(seeds);
8
9
  if (nextSeeds.length === 0) return;
9
- const bundlesById = /* @__PURE__ */ new Map();
10
- for (const seed of requestUpdateBundleSeeds.get(context) ?? []) bundlesById.set(seed.id, seed);
11
- for (const seed of nextSeeds) bundlesById.set(seed.id, seed);
12
- requestUpdateBundleSeeds.set(context, [...bundlesById.values()]);
10
+ unitOfWork.seed(nextSeeds);
13
11
  };
14
12
  const getRequestUpdateBundleSeeds = (context) => {
15
- if (!isWeakMapKey(context)) return [];
16
- return requestUpdateBundleSeeds.get(context) ?? [];
13
+ return require_bundleUnitOfWorkStore.getRequestBundleUnitOfWork(context)?.seededBundles() ?? [];
14
+ };
15
+ const createRequestUpdateBundleResolver = (context) => {
16
+ const unitOfWork = require_bundleUnitOfWorkStore.getRequestBundleUnitOfWork(context) ?? new require_bundleUnitOfWork.BundleUnitOfWork();
17
+ return {
18
+ hasSeededBundles: () => unitOfWork.hasSeeds(),
19
+ peek: (bundleId) => unitOfWork.peek(bundleId),
20
+ getById: (bundleId, loadBundleById) => unitOfWork.getById(bundleId, loadBundleById)
21
+ };
17
22
  };
18
23
  //#endregion
24
+ exports.createRequestUpdateBundleResolver = createRequestUpdateBundleResolver;
19
25
  exports.getRequestUpdateBundleSeeds = getRequestUpdateBundleSeeds;
20
26
  exports.seedRequestUpdateBundles = seedRequestUpdateBundles;
@@ -1,6 +1,12 @@
1
1
  import { Bundle, HotUpdaterContext } from "./types/index.cjs";
2
2
 
3
3
  //#region src/requestUpdateBundleState.d.ts
4
+ interface RequestUpdateBundleResolver {
5
+ readonly hasSeededBundles: () => boolean;
6
+ readonly peek: (bundleId: string) => Bundle | null;
7
+ readonly getById: (bundleId: string, loadBundleById: () => Promise<Bundle | null>) => Promise<Bundle | null>;
8
+ }
4
9
  declare const getRequestUpdateBundleSeeds: <TContext = unknown>(context: HotUpdaterContext<TContext> | undefined) => readonly Bundle[];
10
+ declare const createRequestUpdateBundleResolver: <TContext = unknown>(context: HotUpdaterContext<TContext> | undefined) => RequestUpdateBundleResolver;
5
11
  //#endregion
6
- export { getRequestUpdateBundleSeeds };
12
+ export { createRequestUpdateBundleResolver, getRequestUpdateBundleSeeds };
@@ -1,6 +1,12 @@
1
1
  import { Bundle, HotUpdaterContext } from "./types/index.mjs";
2
2
 
3
3
  //#region src/requestUpdateBundleState.d.ts
4
+ interface RequestUpdateBundleResolver {
5
+ readonly hasSeededBundles: () => boolean;
6
+ readonly peek: (bundleId: string) => Bundle | null;
7
+ readonly getById: (bundleId: string, loadBundleById: () => Promise<Bundle | null>) => Promise<Bundle | null>;
8
+ }
4
9
  declare const getRequestUpdateBundleSeeds: <TContext = unknown>(context: HotUpdaterContext<TContext> | undefined) => readonly Bundle[];
10
+ declare const createRequestUpdateBundleResolver: <TContext = unknown>(context: HotUpdaterContext<TContext> | undefined) => RequestUpdateBundleResolver;
5
11
  //#endregion
6
- export { getRequestUpdateBundleSeeds };
12
+ export { createRequestUpdateBundleResolver, getRequestUpdateBundleSeeds };
@@ -1,19 +1,24 @@
1
+ import { BundleUnitOfWork } from "./bundleUnitOfWork.mjs";
2
+ import { getRequestBundleUnitOfWork } from "./bundleUnitOfWorkStore.mjs";
1
3
  //#region src/requestUpdateBundleState.ts
2
- const requestUpdateBundleSeeds = /* @__PURE__ */ new WeakMap();
3
- const isWeakMapKey = (value) => typeof value === "object" && value !== null || typeof value === "function";
4
4
  const toBundleSeeds = (seeds) => seeds.filter((seed) => !!seed);
5
5
  const seedRequestUpdateBundles = (context, seeds) => {
6
- if (!isWeakMapKey(context)) return;
6
+ const unitOfWork = getRequestBundleUnitOfWork(context);
7
+ if (!unitOfWork) return;
7
8
  const nextSeeds = toBundleSeeds(seeds);
8
9
  if (nextSeeds.length === 0) return;
9
- const bundlesById = /* @__PURE__ */ new Map();
10
- for (const seed of requestUpdateBundleSeeds.get(context) ?? []) bundlesById.set(seed.id, seed);
11
- for (const seed of nextSeeds) bundlesById.set(seed.id, seed);
12
- requestUpdateBundleSeeds.set(context, [...bundlesById.values()]);
10
+ unitOfWork.seed(nextSeeds);
13
11
  };
14
12
  const getRequestUpdateBundleSeeds = (context) => {
15
- if (!isWeakMapKey(context)) return [];
16
- return requestUpdateBundleSeeds.get(context) ?? [];
13
+ return getRequestBundleUnitOfWork(context)?.seededBundles() ?? [];
14
+ };
15
+ const createRequestUpdateBundleResolver = (context) => {
16
+ const unitOfWork = getRequestBundleUnitOfWork(context) ?? new BundleUnitOfWork();
17
+ return {
18
+ hasSeededBundles: () => unitOfWork.hasSeeds(),
19
+ peek: (bundleId) => unitOfWork.peek(bundleId),
20
+ getById: (bundleId, loadBundleById) => unitOfWork.getById(bundleId, loadBundleById)
21
+ };
17
22
  };
18
23
  //#endregion
19
- export { getRequestUpdateBundleSeeds, seedRequestUpdateBundles };
24
+ export { createRequestUpdateBundleResolver, getRequestUpdateBundleSeeds, seedRequestUpdateBundles };
@@ -69,28 +69,6 @@ interface DatabaseBundleQueryOptions {
69
69
  cursor?: DatabaseBundleCursor;
70
70
  orderBy?: DatabaseBundleQueryOrder;
71
71
  }
72
- interface BundleIndexHealth {
73
- status: "ok" | "missing" | "stale";
74
- canonicalBundles: number;
75
- indexedBundles: number;
76
- missingBundles: number;
77
- extraBundles: number;
78
- missingBundleIds: string[];
79
- extraBundleIds: string[];
80
- }
81
- interface BundleIndexRepairResult {
82
- scannedBundles: number;
83
- indexedBundles: number;
84
- pagesWritten: number;
85
- scopesWritten: number;
86
- }
87
- interface BundleIndexDiagnostics<TContext = unknown> {
88
- check: (context?: HotUpdaterContext<TContext>) => Promise<BundleIndexHealth>;
89
- repair?: (context?: HotUpdaterContext<TContext>) => Promise<BundleIndexRepairResult>;
90
- }
91
- interface DatabaseDiagnostics<TContext = unknown> {
92
- bundleIndex?: BundleIndexDiagnostics<TContext>;
93
- }
94
72
  interface BuildPluginConfig {
95
73
  outDir?: string;
96
74
  }
@@ -102,7 +80,6 @@ interface DatabasePlugin<TContext = unknown> {
102
80
  updateBundle: (targetBundleId: string, newBundle: Partial<Bundle>, context?: HotUpdaterContext<TContext>) => Promise<void>;
103
81
  appendBundle: (insertBundle: Bundle, context?: HotUpdaterContext<TContext>) => Promise<void>;
104
82
  commitBundle: (context?: HotUpdaterContext<TContext>) => Promise<void>;
105
- diagnostics?: DatabaseDiagnostics<TContext>;
106
83
  onUnmount?: () => Promise<void>;
107
84
  name: string;
108
85
  deleteBundle: (deleteBundle: Bundle, context?: HotUpdaterContext<TContext>) => Promise<void>;
@@ -527,4 +504,4 @@ interface NativeBuildOptions {
527
504
  scheme?: string;
528
505
  }
529
506
  //#endregion
530
- export { type AppVersionGetBundlesArgs$1 as AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, type Bundle$1 as Bundle, BundleIndexDiagnostics, BundleIndexHealth, BundleIndexRepairResult, ConfigInput, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabaseDiagnostics, DatabasePlugin, DatabasePluginHooks, type FingerprintGetBundlesArgs$1 as FingerprintGetBundlesArgs, type GetBundlesArgs$1 as GetBundlesArgs, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NodeStoragePlugin, NodeStorageProfile, Paginated, PaginatedResult, PaginationInfo, type Platform$1 as Platform, PlatformConfig, RequestEnvContext, RuntimeStoragePlugin, RuntimeStorageProfile, SigningConfig, StoragePlugin, StoragePluginHooks, StoragePluginProfiles, StorageResolveContext, UniversalStoragePlugin, type UpdateInfo$1 as UpdateInfo, supportedIosPlatforms };
507
+ export { type AppVersionGetBundlesArgs$1 as AppVersionGetBundlesArgs, ApplePlatform, BasePluginArgs, BuildPlugin, BuildPluginConfig, type Bundle$1 as Bundle, ConfigInput, DatabaseBundleCursor, DatabaseBundleIdFilter, DatabaseBundleQueryOptions, DatabaseBundleQueryOrder, DatabaseBundleQueryWhere, DatabasePlugin, DatabasePluginHooks, type FingerprintGetBundlesArgs$1 as FingerprintGetBundlesArgs, type GetBundlesArgs$1 as GetBundlesArgs, HotUpdaterContext, IosBuildDestination, NativeBuildAndroidScheme, NativeBuildArgs, NativeBuildIosScheme, NativeBuildOptions, NodeStoragePlugin, NodeStorageProfile, Paginated, PaginatedResult, PaginationInfo, type Platform$1 as Platform, PlatformConfig, RequestEnvContext, RuntimeStoragePlugin, RuntimeStorageProfile, SigningConfig, StoragePlugin, StoragePluginHooks, StoragePluginProfiles, StorageResolveContext, UniversalStoragePlugin, type UpdateInfo$1 as UpdateInfo, supportedIosPlatforms };