@hot-updater/plugin-core 0.36.7 → 1.0.0-rc.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 (161) hide show
  1. package/dist/assetStorageLayout.cjs +36 -18
  2. package/dist/assetStorageLayout.d.cts +21 -6
  3. package/dist/assetStorageLayout.d.mts +21 -6
  4. package/dist/assetStorageLayout.mjs +36 -18
  5. package/dist/bundleStorageLayout.cjs +2 -3
  6. package/dist/bundleStorageLayout.mjs +2 -3
  7. package/dist/contentAddressedAssets.cjs +5 -0
  8. package/dist/contentAddressedAssets.d.cts +2 -1
  9. package/dist/contentAddressedAssets.d.mts +2 -1
  10. package/dist/contentAddressedAssets.mjs +5 -1
  11. package/dist/createDatabasePlugin.cjs +775 -284
  12. package/dist/createDatabasePlugin.d.cts +20 -64
  13. package/dist/createDatabasePlugin.d.mts +20 -64
  14. package/dist/createDatabasePlugin.mjs +773 -284
  15. package/dist/createStorageKeyBuilder.cjs +9 -2
  16. package/dist/createStorageKeyBuilder.mjs +9 -2
  17. package/dist/createStoragePlugin.cjs +6 -145
  18. package/dist/createStoragePlugin.d.cts +7 -52
  19. package/dist/createStoragePlugin.d.mts +7 -52
  20. package/dist/createStoragePlugin.mjs +5 -143
  21. package/dist/databaseClient.cjs +112 -0
  22. package/dist/databaseClient.d.cts +33 -0
  23. package/dist/databaseClient.d.mts +33 -0
  24. package/dist/databaseClient.mjs +110 -0
  25. package/dist/databaseClientReads.cjs +113 -0
  26. package/dist/databaseClientReads.mjs +112 -0
  27. package/dist/databaseClientUpdates.cjs +39 -0
  28. package/dist/databaseClientUpdates.d.cts +11 -0
  29. package/dist/databaseClientUpdates.d.mts +11 -0
  30. package/dist/databaseClientUpdates.mjs +36 -0
  31. package/dist/databaseJsonValue.cjs +37 -0
  32. package/dist/databaseJsonValue.d.cts +5 -0
  33. package/dist/databaseJsonValue.d.mts +5 -0
  34. package/dist/databaseJsonValue.mjs +37 -0
  35. package/dist/databaseMetadata.cjs +13 -0
  36. package/dist/databaseMetadata.mjs +12 -0
  37. package/dist/databasePluginCrud.cjs +86 -0
  38. package/dist/databasePluginCrud.d.cts +1 -0
  39. package/dist/databasePluginCrud.d.mts +1 -0
  40. package/dist/databasePluginCrud.mjs +86 -0
  41. package/dist/databasePluginCrudValidation.d.cts +1 -0
  42. package/dist/databasePluginCrudValidation.d.mts +1 -0
  43. package/dist/databasePluginCrudValidationErrors.cjs +10 -0
  44. package/dist/databasePluginCrudValidationErrors.d.cts +9 -0
  45. package/dist/databasePluginCrudValidationErrors.d.mts +9 -0
  46. package/dist/databasePluginCrudValidationErrors.mjs +10 -0
  47. package/dist/databasePluginCrudValidationFields.cjs +291 -0
  48. package/dist/databasePluginCrudValidationFields.d.cts +1 -0
  49. package/dist/databasePluginCrudValidationFields.d.mts +1 -0
  50. package/dist/databasePluginCrudValidationFields.mjs +281 -0
  51. package/dist/databasePluginCrudValidationMutations.cjs +88 -0
  52. package/dist/databasePluginCrudValidationMutations.d.cts +1 -0
  53. package/dist/databasePluginCrudValidationMutations.d.mts +1 -0
  54. package/dist/databasePluginCrudValidationMutations.mjs +82 -0
  55. package/dist/databasePluginCrudValidationQueries.cjs +103 -0
  56. package/dist/databasePluginCrudValidationQueries.d.cts +1 -0
  57. package/dist/databasePluginCrudValidationQueries.d.mts +1 -0
  58. package/dist/databasePluginCrudValidationQueries.mjs +97 -0
  59. package/dist/databasePluginCrudValidationRows.cjs +55 -0
  60. package/dist/databasePluginCrudValidationRows.d.cts +1 -0
  61. package/dist/databasePluginCrudValidationRows.d.mts +1 -0
  62. package/dist/databasePluginCrudValidationRows.mjs +53 -0
  63. package/dist/databasePluginTransaction.cjs +7 -0
  64. package/dist/databasePluginTransaction.mjs +7 -0
  65. package/dist/databaseRows.cjs +149 -0
  66. package/dist/databaseRows.d.cts +34 -0
  67. package/dist/databaseRows.d.mts +34 -0
  68. package/dist/databaseRows.mjs +141 -0
  69. package/dist/index.cjs +76 -24
  70. package/dist/index.d.cts +22 -12
  71. package/dist/index.d.mts +22 -12
  72. package/dist/index.mjs +21 -14
  73. package/dist/internal.cjs +6 -0
  74. package/dist/internal.d.cts +9 -0
  75. package/dist/internal.d.mts +9 -0
  76. package/dist/internal.mjs +3 -0
  77. package/dist/node_modules/.pnpm/verkit@0.3.2/node_modules/verkit/dist/index.cjs +345 -0
  78. package/dist/node_modules/.pnpm/verkit@0.3.2/node_modules/verkit/dist/index.mjs +341 -0
  79. package/dist/paginateBundles.d.cts +6 -4
  80. package/dist/paginateBundles.d.mts +6 -4
  81. package/dist/parseStorageUri.cjs +46 -30
  82. package/dist/parseStorageUri.d.cts +20 -17
  83. package/dist/parseStorageUri.d.mts +20 -17
  84. package/dist/parseStorageUri.mjs +46 -30
  85. package/dist/queryBundles.cjs +1 -7
  86. package/dist/queryBundles.d.cts +3 -1
  87. package/dist/queryBundles.d.mts +3 -1
  88. package/dist/queryBundles.mjs +1 -7
  89. package/dist/releaseCatalogCompiler.cjs +391 -0
  90. package/dist/releaseCatalogCompiler.d.cts +55 -0
  91. package/dist/releaseCatalogCompiler.d.mts +55 -0
  92. package/dist/releaseCatalogCompiler.mjs +386 -0
  93. package/dist/releaseCatalogMutation.cjs +303 -0
  94. package/dist/releaseCatalogMutation.d.cts +86 -0
  95. package/dist/releaseCatalogMutation.d.mts +86 -0
  96. package/dist/releaseCatalogMutation.mjs +297 -0
  97. package/dist/releaseManagement.cjs +231 -0
  98. package/dist/releaseManagement.d.cts +48 -0
  99. package/dist/releaseManagement.d.mts +48 -0
  100. package/dist/releaseManagement.mjs +224 -0
  101. package/dist/remoteBundleSigning.cjs +296 -0
  102. package/dist/remoteBundleSigning.d.cts +43 -0
  103. package/dist/remoteBundleSigning.d.mts +43 -0
  104. package/dist/remoteBundleSigning.mjs +291 -0
  105. package/dist/requestBundleCache.cjs +22 -0
  106. package/dist/requestBundleCache.d.cts +9 -0
  107. package/dist/requestBundleCache.d.mts +9 -0
  108. package/dist/requestBundleCache.mjs +22 -0
  109. package/dist/semverSatisfies.cjs +3 -4
  110. package/dist/semverSatisfies.mjs +1 -1
  111. package/dist/storageDownloadPath.cjs +48 -0
  112. package/dist/storageDownloadPath.d.cts +15 -0
  113. package/dist/storageDownloadPath.d.mts +15 -0
  114. package/dist/storageDownloadPath.mjs +46 -0
  115. package/dist/types/database.d.cts +4 -0
  116. package/dist/types/database.d.mts +4 -0
  117. package/dist/types/databaseFields.cjs +92 -0
  118. package/dist/types/databaseFields.d.cts +12 -0
  119. package/dist/types/databaseFields.d.mts +12 -0
  120. package/dist/types/databaseFields.mjs +92 -0
  121. package/dist/types/databaseOperations.d.cts +173 -0
  122. package/dist/types/databaseOperations.d.mts +173 -0
  123. package/dist/types/databasePlugin.d.cts +240 -0
  124. package/dist/types/databasePlugin.d.mts +240 -0
  125. package/dist/types/databaseQuery.d.cts +47 -0
  126. package/dist/types/databaseQuery.d.mts +47 -0
  127. package/dist/types/databaseRows.d.cts +120 -0
  128. package/dist/types/databaseRows.d.mts +120 -0
  129. package/dist/types/index.d.cts +120 -162
  130. package/dist/types/index.d.mts +120 -162
  131. package/dist/types/internal.d.cts +7 -0
  132. package/dist/types/internal.d.mts +7 -0
  133. package/dist/types/public.d.cts +3 -0
  134. package/dist/types/public.d.mts +3 -0
  135. package/dist/uuidv7.cjs +9 -0
  136. package/dist/uuidv7.d.cts +4 -1
  137. package/dist/uuidv7.d.mts +4 -1
  138. package/dist/uuidv7.mjs +8 -1
  139. package/package.json +10 -5
  140. package/dist/bundleUnitOfWork.cjs +0 -158
  141. package/dist/bundleUnitOfWork.mjs +0 -158
  142. package/dist/bundleUnitOfWorkStore.cjs +0 -15
  143. package/dist/bundleUnitOfWorkStore.mjs +0 -15
  144. package/dist/createBlobDatabasePlugin.cjs +0 -382
  145. package/dist/createBlobDatabasePlugin.d.cts +0 -29
  146. package/dist/createBlobDatabasePlugin.d.mts +0 -29
  147. package/dist/createBlobDatabasePlugin.mjs +0 -381
  148. package/dist/legacyAssetStorageLayout.cjs +0 -12
  149. package/dist/legacyAssetStorageLayout.mjs +0 -12
  150. package/dist/requestUpdateBundleState.cjs +0 -26
  151. package/dist/requestUpdateBundleState.d.cts +0 -12
  152. package/dist/requestUpdateBundleState.d.mts +0 -12
  153. package/dist/requestUpdateBundleState.mjs +0 -24
  154. package/dist/resolveUpdateInfoFromBundles.cjs +0 -14
  155. package/dist/resolveUpdateInfoFromBundles.d.cts +0 -16
  156. package/dist/resolveUpdateInfoFromBundles.d.mts +0 -16
  157. package/dist/resolveUpdateInfoFromBundles.mjs +0 -13
  158. package/dist/storageProfile.cjs +0 -15
  159. package/dist/storageProfile.d.cts +0 -9
  160. package/dist/storageProfile.d.mts +0 -9
  161. package/dist/storageProfile.mjs +0 -12
@@ -1,382 +0,0 @@
1
- require("./_virtual/_rolldown/runtime.cjs");
2
- const require_queryBundles = require("./queryBundles.cjs");
3
- const require_createDatabasePlugin = require("./createDatabasePlugin.cjs");
4
- const require_filterCompatibleAppVersions = require("./filterCompatibleAppVersions.cjs");
5
- const require_paginateBundles = require("./paginateBundles.cjs");
6
- const require_resolveUpdateInfoFromBundles = require("./resolveUpdateInfoFromBundles.cjs");
7
- let es_toolkit = require("es-toolkit");
8
- let verkit = require("verkit");
9
- //#region src/createBlobDatabasePlugin.ts
10
- const STORAGE_OPERATION_CONCURRENCY = 8;
11
- async function mapWithConcurrency(items, concurrency, mapper) {
12
- const results = [];
13
- let nextIndex = 0;
14
- const workerCount = Math.min(concurrency, items.length);
15
- await Promise.all(Array.from({ length: workerCount }, async () => {
16
- while (true) {
17
- const index = nextIndex;
18
- nextIndex += 1;
19
- if (index >= items.length) break;
20
- results[index] = await mapper(items[index], index);
21
- }
22
- }));
23
- return results;
24
- }
25
- async function forEachWithConcurrency(items, concurrency, mapper) {
26
- await mapWithConcurrency(items, concurrency, mapper);
27
- }
28
- function removeBundleInternalKeys(bundle) {
29
- const { _updateJsonKey, _oldUpdateJsonKey, ...pureBundle } = bundle;
30
- return pureBundle;
31
- }
32
- function normalizeTargetAppVersion(version) {
33
- if (!version) return null;
34
- let normalized = version.replace(/\s+/g, " ").trim();
35
- normalized = normalized.replace(/([><=~^]+)\s+(\d)/g, (_match, operator, digit) => `${operator}${digit}`);
36
- return normalized;
37
- }
38
- function isExactVersion(version) {
39
- if (!version) return false;
40
- const normalized = normalizeTargetAppVersion(version);
41
- if (!normalized) return false;
42
- return (0, verkit.normalize)(normalized) !== null;
43
- }
44
- /**
45
- * Get all normalized semver versions for a version string.
46
- * This handles the case where clients may request with different normalized forms.
47
- *
48
- * Examples:
49
- * - "1.0.0" generates ["1.0.0", "1.0", "1"]
50
- * - "2.1.0" generates ["2.1.0", "2.1"]
51
- * - "1.2.3" generates ["1.2.3"]
52
- */
53
- function getSemverNormalizedVersions(version) {
54
- const normalized = normalizeTargetAppVersion(version) || version;
55
- const coerced = (0, verkit.coerce)(normalized);
56
- if (!coerced) return [normalized];
57
- const { major, minor, patch } = (0, verkit.parse)(coerced);
58
- const versions = /* @__PURE__ */ new Set();
59
- versions.add(coerced);
60
- if (patch === 0) versions.add(`${major}.${minor}`);
61
- if (minor === 0 && patch === 0) versions.add(`${major}`);
62
- return Array.from(versions);
63
- }
64
- function resolveStorageTarget({ targetAppVersion, fingerprintHash }) {
65
- const target = normalizeTargetAppVersion(targetAppVersion) ?? fingerprintHash;
66
- if (!target) throw new Error("target not found");
67
- return target;
68
- }
69
- function targetVersionMutationKey(bundle) {
70
- return `${bundle.channel}/${bundle.platform}`;
71
- }
72
- function getTargetVersionMutation(mutations, bundle) {
73
- const key = targetVersionMutationKey(bundle);
74
- const existingMutation = mutations.get(key);
75
- if (existingMutation) return existingMutation;
76
- const mutation = {
77
- additions: /* @__PURE__ */ new Set(),
78
- channel: bundle.channel,
79
- platform: bundle.platform,
80
- removals: /* @__PURE__ */ new Set()
81
- };
82
- mutations.set(key, mutation);
83
- return mutation;
84
- }
85
- function addTargetVersionAddition(mutations, bundle) {
86
- const targetAppVersion = normalizeTargetAppVersion(bundle.targetAppVersion);
87
- if (targetAppVersion == null) return;
88
- getTargetVersionMutation(mutations, bundle).additions.add(targetAppVersion);
89
- }
90
- function addTargetVersionRemoval(mutations, bundle) {
91
- const targetAppVersion = normalizeTargetAppVersion(bundle.targetAppVersion);
92
- if (targetAppVersion == null) return;
93
- getTargetVersionMutation(mutations, bundle).removals.add(targetAppVersion);
94
- }
95
- function getManagementListPrefixes(where) {
96
- if (where?.channel && where.platform && typeof where.targetAppVersion === "string") {
97
- const targetAppVersion = normalizeTargetAppVersion(where.targetAppVersion);
98
- if (targetAppVersion) return [`${where.channel}/${where.platform}/${targetAppVersion}/`];
99
- }
100
- if (where?.channel && where.platform) return [`${where.channel}/${where.platform}/`];
101
- if (where?.channel) return [`${where.channel}/`];
102
- return [""];
103
- }
104
- function getChannelFromUpdateJsonKey(key) {
105
- return key.match(/^([^/]+)\/(?:ios|android)\/[^/]+\/update\.json$/)?.[1] ?? null;
106
- }
107
- const DEFAULT_DESC_ORDER = {
108
- field: "id",
109
- direction: "desc"
110
- };
111
- function sortManagedBundles(bundles, orderBy = DEFAULT_DESC_ORDER) {
112
- return require_queryBundles.sortBundles(bundles, orderBy);
113
- }
114
- /**
115
- * Creates a blob storage-based database plugin with lazy initialization.
116
- *
117
- * @param name - The name of the database plugin
118
- * @param factory - Function that creates blob storage operations from config
119
- * @returns A double-curried function that lazily initializes the database plugin
120
- */
121
- const createBlobDatabasePlugin = ({ name, factory }) => {
122
- return (config, hooks) => {
123
- const { listObjects, loadObject, uploadObject, deleteObject, shouldSkipLoadObjectError, validateChannel, invalidatePaths, apiBasePath } = factory(config);
124
- const bundlesMap = /* @__PURE__ */ new Map();
125
- const pendingBundlesMap = /* @__PURE__ */ new Map();
126
- const locallyDeletedBundleIds = /* @__PURE__ */ new Set();
127
- const loadOptionalObject = async (key) => {
128
- try {
129
- return await loadObject(key);
130
- } catch (error) {
131
- if (shouldSkipLoadObjectError?.(error, key)) return null;
132
- throw error;
133
- }
134
- };
135
- const loadAllBundlesForManagementFallback = async (where) => {
136
- return sortManagedBundles((await reloadBundles(getManagementListPrefixes(where))).map((bundle) => removeBundleInternalKeys(bundle)));
137
- };
138
- const cacheBundlesFromObject = (key, bundles) => {
139
- for (const bundle of bundles) {
140
- if (locallyDeletedBundleIds.has(bundle.id) || pendingBundlesMap.has(bundle.id)) continue;
141
- bundlesMap.set(bundle.id, {
142
- ...bundle,
143
- _updateJsonKey: key
144
- });
145
- }
146
- };
147
- const loadBundleObject = async (key) => {
148
- const bundles = await loadOptionalObject(key) ?? [];
149
- cacheBundlesFromObject(key, bundles);
150
- return bundles;
151
- };
152
- async function reloadBundles(prefixes = [""]) {
153
- bundlesMap.clear();
154
- pendingBundlesMap.clear();
155
- locallyDeletedBundleIds.clear();
156
- const allBundles = (await mapWithConcurrency((await mapWithConcurrency(prefixes, STORAGE_OPERATION_CONCURRENCY, (prefix) => listObjects(prefix))).flat().filter((key) => /^[^/]+\/(?:ios|android)\/[^/]+\/update\.json$/.test(key)), STORAGE_OPERATION_CONCURRENCY, async (key) => {
157
- return (await loadBundleObject(key)).map((bundle) => ({
158
- ...bundle,
159
- _updateJsonKey: key
160
- }));
161
- })).flat();
162
- for (const bundle of allBundles) bundlesMap.set(bundle.id, bundle);
163
- for (const [id, bundle] of pendingBundlesMap.entries()) bundlesMap.set(id, bundle);
164
- return (0, es_toolkit.orderBy)(Array.from(bundlesMap.values()), [(v) => v.id], ["desc"]);
165
- }
166
- async function applyTargetVersionMutations(mutations) {
167
- await Promise.all(Array.from(mutations.values()).map(async ({ additions, channel, platform, removals }) => {
168
- const targetKey = `${channel}/${platform}/target-app-versions.json`;
169
- const oldTargetVersions = await loadOptionalObject(targetKey) ?? [];
170
- const newTargetVersions = oldTargetVersions.filter((version) => !removals.has(version) || additions.has(version));
171
- for (const version of additions) if (!newTargetVersions.includes(version)) newTargetVersions.push(version);
172
- if (JSON.stringify(oldTargetVersions) !== JSON.stringify(newTargetVersions)) await uploadObject(targetKey, newTargetVersions);
173
- }));
174
- }
175
- const getAppVersionUpdateInfo = async ({ appVersion, bundleId, channel = "production", cohort, minBundleId, platform }, context) => {
176
- const bundles = (await mapWithConcurrency(require_filterCompatibleAppVersions.filterCompatibleAppVersions(await loadOptionalObject(`${channel}/${platform}/target-app-versions.json`) ?? [], appVersion), STORAGE_OPERATION_CONCURRENCY, async (targetAppVersion) => {
177
- return loadBundleObject(`${channel}/${platform}/${normalizeTargetAppVersion(targetAppVersion) ?? targetAppVersion}/update.json`);
178
- })).flat();
179
- return require_resolveUpdateInfoFromBundles.resolveUpdateInfoFromBundles({
180
- args: {
181
- _updateStrategy: "appVersion",
182
- appVersion,
183
- bundleId,
184
- channel,
185
- cohort,
186
- minBundleId,
187
- platform
188
- },
189
- bundles,
190
- context
191
- });
192
- };
193
- const getFingerprintUpdateInfo = async ({ bundleId, channel = "production", cohort, fingerprintHash, minBundleId, platform }, context) => {
194
- const bundles = await loadBundleObject(`${channel}/${platform}/${fingerprintHash}/update.json`);
195
- return require_resolveUpdateInfoFromBundles.resolveUpdateInfoFromBundles({
196
- args: {
197
- _updateStrategy: "fingerprint",
198
- bundleId,
199
- channel,
200
- cohort,
201
- fingerprintHash,
202
- minBundleId,
203
- platform
204
- },
205
- bundles,
206
- context
207
- });
208
- };
209
- const addAppVersionInvalidationPaths = (pathsToInvalidate, { platform, channel, targetAppVersion }) => {
210
- if (!isExactVersion(targetAppVersion)) {
211
- pathsToInvalidate.add(`${apiBasePath}/app-version/${platform}/*`);
212
- return;
213
- }
214
- const normalizedVersions = getSemverNormalizedVersions(targetAppVersion);
215
- for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${platform}/${version}/${channel}/*`);
216
- };
217
- const addLookupInvalidationPaths = (pathsToInvalidate, { platform, channel, targetAppVersion, fingerprintHash }) => {
218
- if (fingerprintHash) {
219
- pathsToInvalidate.add(`${apiBasePath}/fingerprint/${platform}/${fingerprintHash}/${channel}/*`);
220
- return;
221
- }
222
- if (targetAppVersion) addAppVersionInvalidationPaths(pathsToInvalidate, {
223
- platform,
224
- channel,
225
- targetAppVersion
226
- });
227
- };
228
- const createPlugin = require_createDatabasePlugin.createDatabasePlugin({
229
- name,
230
- factory: () => ({
231
- supportsCursorPagination: true,
232
- async getBundleById(bundleId) {
233
- if (locallyDeletedBundleIds.has(bundleId)) return null;
234
- const pendingBundle = pendingBundlesMap.get(bundleId);
235
- if (pendingBundle) return removeBundleInternalKeys(pendingBundle);
236
- const bundle = bundlesMap.get(bundleId);
237
- if (bundle) return removeBundleInternalKeys(bundle);
238
- const matchedBundle = (await reloadBundles()).find((item) => item.id === bundleId);
239
- if (!matchedBundle) return null;
240
- return removeBundleInternalKeys(matchedBundle);
241
- },
242
- async getUpdateInfo(args, context) {
243
- if (args._updateStrategy === "appVersion") return getAppVersionUpdateInfo(args, context);
244
- return getFingerprintUpdateInfo(args, context);
245
- },
246
- async getBundles(options) {
247
- const { where, limit, offset, orderBy, cursor } = options;
248
- let allBundles = await loadAllBundlesForManagementFallback(where);
249
- if (where) allBundles = allBundles.filter((bundle) => require_queryBundles.bundleMatchesQueryWhere(bundle, where));
250
- return require_paginateBundles.paginateBundles({
251
- bundles: allBundles,
252
- limit,
253
- offset,
254
- cursor,
255
- orderBy
256
- });
257
- },
258
- async getChannels() {
259
- const channels = (await listObjects("")).map(getChannelFromUpdateJsonKey).filter((channel) => channel !== null);
260
- return [...new Set(channels)].sort();
261
- },
262
- async commitBundle({ changedSets }) {
263
- if (changedSets.length === 0) return;
264
- for (const { operation, data } of changedSets) if (operation === "insert" || operation === "update" && data.channel !== void 0) validateChannel?.(data.channel);
265
- const changedBundlesByKey = {};
266
- const removalsByKey = {};
267
- const targetVersionRemovalsByKey = {};
268
- const pathsToInvalidate = /* @__PURE__ */ new Set();
269
- const targetVersionMutations = /* @__PURE__ */ new Map();
270
- for (const { operation, data } of changedSets) {
271
- if (operation === "insert") {
272
- const target = resolveStorageTarget(data);
273
- const key = `${data.channel}/${data.platform}/${target}/update.json`;
274
- const bundleWithKey = {
275
- ...data,
276
- _updateJsonKey: key
277
- };
278
- locallyDeletedBundleIds.delete(data.id);
279
- bundlesMap.set(data.id, bundleWithKey);
280
- pendingBundlesMap.set(data.id, bundleWithKey);
281
- changedBundlesByKey[key] = changedBundlesByKey[key] || [];
282
- changedBundlesByKey[key].push(removeBundleInternalKeys(bundleWithKey));
283
- addTargetVersionAddition(targetVersionMutations, data);
284
- addLookupInvalidationPaths(pathsToInvalidate, data);
285
- continue;
286
- }
287
- if (operation === "delete") {
288
- let bundle = pendingBundlesMap.get(data.id);
289
- if (!bundle) bundle = bundlesMap.get(data.id);
290
- if (!bundle) throw new Error("Bundle to delete not found");
291
- bundlesMap.delete(data.id);
292
- pendingBundlesMap.delete(data.id);
293
- locallyDeletedBundleIds.add(data.id);
294
- const key = bundle._updateJsonKey;
295
- removalsByKey[key] = removalsByKey[key] || [];
296
- removalsByKey[key].push(bundle.id);
297
- targetVersionRemovalsByKey[key] = targetVersionRemovalsByKey[key] || [];
298
- targetVersionRemovalsByKey[key].push(bundle);
299
- addLookupInvalidationPaths(pathsToInvalidate, bundle);
300
- continue;
301
- }
302
- let bundle = pendingBundlesMap.get(data.id);
303
- if (!bundle) bundle = bundlesMap.get(data.id);
304
- if (!bundle) throw new Error("targetBundleId not found");
305
- if (operation === "update") {
306
- const updatedBundle = {
307
- ...bundle,
308
- ...data
309
- };
310
- const newKey = `${updatedBundle.channel}/${updatedBundle.platform}/${resolveStorageTarget(updatedBundle)}/update.json`;
311
- if (newKey !== bundle._updateJsonKey) {
312
- const oldKey = bundle._updateJsonKey;
313
- removalsByKey[oldKey] = removalsByKey[oldKey] || [];
314
- removalsByKey[oldKey].push(bundle.id);
315
- targetVersionRemovalsByKey[oldKey] = targetVersionRemovalsByKey[oldKey] || [];
316
- targetVersionRemovalsByKey[oldKey].push(bundle);
317
- changedBundlesByKey[newKey] = changedBundlesByKey[newKey] || [];
318
- updatedBundle._oldUpdateJsonKey = oldKey;
319
- updatedBundle._updateJsonKey = newKey;
320
- bundlesMap.set(data.id, updatedBundle);
321
- pendingBundlesMap.set(data.id, updatedBundle);
322
- locallyDeletedBundleIds.delete(data.id);
323
- changedBundlesByKey[newKey].push(removeBundleInternalKeys(updatedBundle));
324
- const oldChannel = bundle.channel;
325
- const nextChannel = updatedBundle.channel;
326
- if (oldChannel !== nextChannel) {
327
- addLookupInvalidationPaths(pathsToInvalidate, bundle);
328
- if (bundle.targetAppVersion && !bundle.fingerprintHash) addLookupInvalidationPaths(pathsToInvalidate, {
329
- ...bundle,
330
- channel: nextChannel
331
- });
332
- }
333
- addTargetVersionAddition(targetVersionMutations, updatedBundle);
334
- addLookupInvalidationPaths(pathsToInvalidate, updatedBundle);
335
- if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle.targetAppVersion) addLookupInvalidationPaths(pathsToInvalidate, bundle);
336
- continue;
337
- }
338
- const currentKey = bundle._updateJsonKey;
339
- bundlesMap.set(data.id, updatedBundle);
340
- pendingBundlesMap.set(data.id, updatedBundle);
341
- locallyDeletedBundleIds.delete(data.id);
342
- changedBundlesByKey[currentKey] = changedBundlesByKey[currentKey] || [];
343
- changedBundlesByKey[currentKey].push(removeBundleInternalKeys(updatedBundle));
344
- addLookupInvalidationPaths(pathsToInvalidate, updatedBundle);
345
- addTargetVersionAddition(targetVersionMutations, updatedBundle);
346
- if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle.targetAppVersion) addLookupInvalidationPaths(pathsToInvalidate, bundle);
347
- }
348
- }
349
- await forEachWithConcurrency(Object.keys(removalsByKey), STORAGE_OPERATION_CONCURRENCY, async (oldKey) => {
350
- const updatedBundles = (await loadOptionalObject(oldKey) ?? []).filter((b) => !removalsByKey[oldKey].includes(b.id));
351
- updatedBundles.sort((a, b) => b.id.localeCompare(a.id));
352
- if (updatedBundles.length === 0) {
353
- await deleteObject(oldKey);
354
- for (const removedBundle of targetVersionRemovalsByKey[oldKey] ?? []) addTargetVersionRemoval(targetVersionMutations, removedBundle);
355
- } else await uploadObject(oldKey, updatedBundles);
356
- });
357
- await forEachWithConcurrency(Object.keys(changedBundlesByKey), STORAGE_OPERATION_CONCURRENCY, async (key) => {
358
- const currentBundles = await loadOptionalObject(key) ?? [];
359
- const pureBundles = changedBundlesByKey[key].map((bundle) => bundle);
360
- for (const changedBundle of pureBundles) {
361
- const index = currentBundles.findIndex((b) => b.id === changedBundle.id);
362
- if (index >= 0) currentBundles[index] = changedBundle;
363
- else currentBundles.push(changedBundle);
364
- }
365
- currentBundles.sort((a, b) => b.id.localeCompare(a.id));
366
- await uploadObject(key, currentBundles);
367
- });
368
- if (targetVersionMutations.size > 0) await applyTargetVersionMutations(targetVersionMutations);
369
- const encondedPaths = /* @__PURE__ */ new Set();
370
- for (const path of pathsToInvalidate) encondedPaths.add(encodeURI(path));
371
- await invalidatePaths(Array.from(encondedPaths));
372
- pendingBundlesMap.clear();
373
- }
374
- })
375
- })({}, hooks);
376
- return () => {
377
- return createPlugin();
378
- };
379
- };
380
- };
381
- //#endregion
382
- exports.createBlobDatabasePlugin = createBlobDatabasePlugin;
@@ -1,29 +0,0 @@
1
- import { DatabasePlugin, DatabasePluginHooks } from "./types/index.cjs";
2
-
3
- //#region src/createBlobDatabasePlugin.d.ts
4
- interface BlobOperations {
5
- listObjects: (prefix: string) => Promise<string[]>;
6
- loadObject: <T>(key: string) => Promise<T | null>;
7
- uploadObject: <T>(key: string, data: T) => Promise<void>;
8
- deleteObject: (key: string) => Promise<void>;
9
- shouldSkipLoadObjectError?: (error: unknown, key: string) => boolean;
10
- validateChannel?: (channel: string) => void;
11
- invalidatePaths: (paths: string[]) => Promise<void>;
12
- apiBasePath: string;
13
- }
14
- /**
15
- * Creates a blob storage-based database plugin with lazy initialization.
16
- *
17
- * @param name - The name of the database plugin
18
- * @param factory - Function that creates blob storage operations from config
19
- * @returns A double-curried function that lazily initializes the database plugin
20
- */
21
- declare const createBlobDatabasePlugin: <TConfig>({
22
- name,
23
- factory
24
- }: {
25
- name: string;
26
- factory: (config: TConfig) => BlobOperations;
27
- }) => (config: TConfig, hooks?: DatabasePluginHooks) => () => DatabasePlugin<unknown>;
28
- //#endregion
29
- export { BlobOperations, createBlobDatabasePlugin };
@@ -1,29 +0,0 @@
1
- import { DatabasePlugin, DatabasePluginHooks } from "./types/index.mjs";
2
-
3
- //#region src/createBlobDatabasePlugin.d.ts
4
- interface BlobOperations {
5
- listObjects: (prefix: string) => Promise<string[]>;
6
- loadObject: <T>(key: string) => Promise<T | null>;
7
- uploadObject: <T>(key: string, data: T) => Promise<void>;
8
- deleteObject: (key: string) => Promise<void>;
9
- shouldSkipLoadObjectError?: (error: unknown, key: string) => boolean;
10
- validateChannel?: (channel: string) => void;
11
- invalidatePaths: (paths: string[]) => Promise<void>;
12
- apiBasePath: string;
13
- }
14
- /**
15
- * Creates a blob storage-based database plugin with lazy initialization.
16
- *
17
- * @param name - The name of the database plugin
18
- * @param factory - Function that creates blob storage operations from config
19
- * @returns A double-curried function that lazily initializes the database plugin
20
- */
21
- declare const createBlobDatabasePlugin: <TConfig>({
22
- name,
23
- factory
24
- }: {
25
- name: string;
26
- factory: (config: TConfig) => BlobOperations;
27
- }) => (config: TConfig, hooks?: DatabasePluginHooks) => () => DatabasePlugin<unknown>;
28
- //#endregion
29
- export { BlobOperations, createBlobDatabasePlugin };