@hot-updater/plugin-core 0.21.10 → 0.21.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createBlobDatabasePlugin.cjs +245 -245
- package/dist/createBlobDatabasePlugin.d.cts +17 -28
- package/dist/createBlobDatabasePlugin.d.ts +17 -28
- package/dist/createBlobDatabasePlugin.js +245 -245
- package/dist/createDatabasePlugin.cjs +76 -80
- package/dist/createDatabasePlugin.d.cts +49 -41
- package/dist/createDatabasePlugin.d.ts +49 -41
- package/dist/createDatabasePlugin.js +77 -81
- package/dist/createStoragePlugin.cjs +57 -0
- package/dist/createStoragePlugin.d.cts +63 -0
- package/dist/createStoragePlugin.d.ts +63 -0
- package/dist/createStoragePlugin.js +56 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +3 -3
|
@@ -40,269 +40,269 @@ function getSemverNormalizedVersions(version) {
|
|
|
40
40
|
return Array.from(versions);
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
+
* Creates a blob storage-based database plugin with lazy initialization.
|
|
43
44
|
*
|
|
44
45
|
* @param name - The name of the database plugin
|
|
45
|
-
* @param
|
|
46
|
-
* @
|
|
47
|
-
* @param uploadObject - Function to upload an JSON object to the storage
|
|
48
|
-
* @param deleteObject - Function to delete an object from the storage
|
|
49
|
-
* @param invalidatePaths - Function to invalidate paths in the CDN
|
|
50
|
-
* @param hooks - Optional hooks for additional functionality - see createDatabasePlugin
|
|
51
|
-
* @returns
|
|
46
|
+
* @param factory - Function that creates blob storage operations from config
|
|
47
|
+
* @returns A double-curried function that lazily initializes the database plugin
|
|
52
48
|
*/
|
|
53
|
-
const createBlobDatabasePlugin = ({ name,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
const createBlobDatabasePlugin = ({ name, factory }) => {
|
|
50
|
+
return (config, hooks) => {
|
|
51
|
+
const { listObjects, loadObject, uploadObject, deleteObject, invalidatePaths, apiBasePath } = factory(config);
|
|
52
|
+
const bundlesMap = /* @__PURE__ */ new Map();
|
|
53
|
+
const pendingBundlesMap = /* @__PURE__ */ new Map();
|
|
54
|
+
const PLATFORMS = ["ios", "android"];
|
|
55
|
+
async function reloadBundles() {
|
|
56
|
+
bundlesMap.clear();
|
|
57
|
+
const platformPromises = PLATFORMS.map(async (platform) => {
|
|
58
|
+
const filePromises = (await listUpdateJsonKeys(platform)).map(async (key) => {
|
|
59
|
+
return (await loadObject(key) ?? []).map((bundle) => ({
|
|
60
|
+
...bundle,
|
|
61
|
+
_updateJsonKey: key
|
|
62
|
+
}));
|
|
63
|
+
});
|
|
64
|
+
return (await Promise.all(filePromises)).flat();
|
|
65
65
|
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
updatedTargetFiles.add(`/${targetKey}`);
|
|
66
|
+
const allBundles = (await Promise.all(platformPromises)).flat();
|
|
67
|
+
for (const bundle of allBundles) bundlesMap.set(bundle.id, bundle);
|
|
68
|
+
for (const [id, bundle] of pendingBundlesMap.entries()) bundlesMap.set(id, bundle);
|
|
69
|
+
return orderBy(allBundles, [(v) => v.id], ["desc"]);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Updates target-app-versions.json for each channel on the given platform.
|
|
73
|
+
* Returns true if the file was updated, false if no changes were made.
|
|
74
|
+
*/
|
|
75
|
+
async function updateTargetVersionsForPlatform(platform) {
|
|
76
|
+
const pattern = /* @__PURE__ */ new RegExp(`^[^/]+/${platform}/[^/]+/update\\.json$`);
|
|
77
|
+
const keysByChannel = (await listObjects("")).filter((key) => pattern.test(key)).reduce((acc, key) => {
|
|
78
|
+
const channel = key.split("/")[0];
|
|
79
|
+
acc[channel] = acc[channel] || [];
|
|
80
|
+
acc[channel].push(key);
|
|
81
|
+
return acc;
|
|
82
|
+
}, {});
|
|
83
|
+
const updatedTargetFiles = /* @__PURE__ */ new Set();
|
|
84
|
+
for (const channel of Object.keys(keysByChannel)) {
|
|
85
|
+
const updateKeys = keysByChannel[channel];
|
|
86
|
+
const targetKey = `${channel}/${platform}/target-app-versions.json`;
|
|
87
|
+
const currentVersions = updateKeys.map((key) => key.split("/")[2]);
|
|
88
|
+
const oldTargetVersions = await loadObject(targetKey) ?? [];
|
|
89
|
+
const newTargetVersions = oldTargetVersions.filter((v) => currentVersions.includes(v));
|
|
90
|
+
for (const v of currentVersions) if (!newTargetVersions.includes(v)) newTargetVersions.push(v);
|
|
91
|
+
if (JSON.stringify(oldTargetVersions) !== JSON.stringify(newTargetVersions)) {
|
|
92
|
+
await uploadObject(targetKey, newTargetVersions);
|
|
93
|
+
updatedTargetFiles.add(`/${targetKey}`);
|
|
94
|
+
}
|
|
96
95
|
}
|
|
96
|
+
return updatedTargetFiles;
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
})
|
|
136
|
-
};
|
|
137
|
-
},
|
|
138
|
-
async getChannels(context) {
|
|
139
|
-
const total = (await reloadBundles(context)).length;
|
|
140
|
-
const result = await this.getBundles(context, {
|
|
141
|
-
limit: total,
|
|
142
|
-
offset: 0
|
|
143
|
-
});
|
|
144
|
-
return [...new Set(result.data.map((bundle) => bundle.channel))];
|
|
145
|
-
},
|
|
146
|
-
async commitBundle(context, { changedSets }) {
|
|
147
|
-
if (changedSets.length === 0) return;
|
|
148
|
-
const changedBundlesByKey = {};
|
|
149
|
-
const removalsByKey = {};
|
|
150
|
-
const pathsToInvalidate = /* @__PURE__ */ new Set();
|
|
151
|
-
let isTargetAppVersionChanged = false;
|
|
152
|
-
for (const { operation, data } of changedSets) {
|
|
153
|
-
if (data.targetAppVersion !== void 0) isTargetAppVersionChanged = true;
|
|
154
|
-
if (operation === "insert") {
|
|
155
|
-
const target = normalizeTargetAppVersion(data.targetAppVersion) ?? data.fingerprintHash;
|
|
156
|
-
if (!target) throw new Error("target not found");
|
|
157
|
-
const key = `${data.channel}/${data.platform}/${target}/update.json`;
|
|
158
|
-
const bundleWithKey = {
|
|
159
|
-
...data,
|
|
160
|
-
_updateJsonKey: key
|
|
98
|
+
/**
|
|
99
|
+
* Lists update.json keys for a given platform.
|
|
100
|
+
*
|
|
101
|
+
* - If a channel is provided, only that channel's update.json files are listed.
|
|
102
|
+
* - Otherwise, all channels for the given platform are returned.
|
|
103
|
+
*/
|
|
104
|
+
async function listUpdateJsonKeys(platform, channel) {
|
|
105
|
+
const prefix = channel ? platform ? `${channel}/${platform}/` : `${channel}/` : "";
|
|
106
|
+
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$/;
|
|
107
|
+
return listObjects(prefix).then((keys) => keys.filter((key) => pattern.test(key)));
|
|
108
|
+
}
|
|
109
|
+
return createDatabasePlugin({
|
|
110
|
+
name,
|
|
111
|
+
factory: () => ({
|
|
112
|
+
async getBundleById(bundleId) {
|
|
113
|
+
const pendingBundle = pendingBundlesMap.get(bundleId);
|
|
114
|
+
if (pendingBundle) return removeBundleInternalKeys(pendingBundle);
|
|
115
|
+
const bundle = bundlesMap.get(bundleId);
|
|
116
|
+
if (bundle) return removeBundleInternalKeys(bundle);
|
|
117
|
+
return (await reloadBundles()).find((bundle$1) => bundle$1.id === bundleId) ?? null;
|
|
118
|
+
},
|
|
119
|
+
async getBundles(options) {
|
|
120
|
+
let allBundles = await reloadBundles();
|
|
121
|
+
const { where, limit, offset } = options;
|
|
122
|
+
if (where) allBundles = allBundles.filter((bundle) => {
|
|
123
|
+
return Object.entries(where).every(([key, value]) => value === void 0 || value === null || bundle[key] === value);
|
|
124
|
+
});
|
|
125
|
+
const total = allBundles.length;
|
|
126
|
+
let paginatedData = allBundles.map(removeBundleInternalKeys);
|
|
127
|
+
if (offset > 0) paginatedData = paginatedData.slice(offset);
|
|
128
|
+
if (limit) paginatedData = paginatedData.slice(0, limit);
|
|
129
|
+
return {
|
|
130
|
+
data: paginatedData,
|
|
131
|
+
pagination: calculatePagination(total, {
|
|
132
|
+
limit,
|
|
133
|
+
offset
|
|
134
|
+
})
|
|
161
135
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
let
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (!bundle) bundle = bundlesMap.get(data.id);
|
|
195
|
-
if (!bundle) throw new Error("targetBundleId not found");
|
|
196
|
-
if (operation === "update") {
|
|
197
|
-
const newChannel = data.channel !== void 0 ? data.channel : bundle.channel;
|
|
198
|
-
const newPlatform = data.platform !== void 0 ? data.platform : bundle.platform;
|
|
199
|
-
const target = data.fingerprintHash ?? bundle.fingerprintHash ?? normalizeTargetAppVersion(data.targetAppVersion) ?? normalizeTargetAppVersion(bundle.targetAppVersion);
|
|
200
|
-
if (!target) throw new Error("target not found");
|
|
201
|
-
const newKey = `${newChannel}/${newPlatform}/${target}/update.json`;
|
|
202
|
-
if (newKey !== bundle._updateJsonKey) {
|
|
203
|
-
const oldKey = bundle._updateJsonKey;
|
|
204
|
-
removalsByKey[oldKey] = removalsByKey[oldKey] || [];
|
|
205
|
-
removalsByKey[oldKey].push(bundle.id);
|
|
206
|
-
changedBundlesByKey[newKey] = changedBundlesByKey[newKey] || [];
|
|
207
|
-
const updatedBundle$1 = {
|
|
208
|
-
...bundle,
|
|
209
|
-
...data
|
|
210
|
-
};
|
|
211
|
-
updatedBundle$1._oldUpdateJsonKey = oldKey;
|
|
212
|
-
updatedBundle$1._updateJsonKey = newKey;
|
|
213
|
-
bundlesMap.set(data.id, updatedBundle$1);
|
|
214
|
-
pendingBundlesMap.set(data.id, updatedBundle$1);
|
|
215
|
-
changedBundlesByKey[newKey].push(removeBundleInternalKeys(updatedBundle$1));
|
|
216
|
-
pathsToInvalidate.add(`/${oldKey}`);
|
|
217
|
-
pathsToInvalidate.add(`/${newKey}`);
|
|
218
|
-
const oldChannel = bundle.channel;
|
|
219
|
-
const newChannel$1 = data.channel;
|
|
220
|
-
if (oldChannel !== newChannel$1) {
|
|
221
|
-
pathsToInvalidate.add(`/${oldChannel}/${bundle.platform}/target-app-versions.json`);
|
|
222
|
-
pathsToInvalidate.add(`/${newChannel$1}/${bundle.platform}/target-app-versions.json`);
|
|
223
|
-
if (bundle.fingerprintHash) {
|
|
224
|
-
pathsToInvalidate.add(`${apiBasePath}/fingerprint/${bundle.platform}/${bundle.fingerprintHash}/${oldChannel}/*`);
|
|
225
|
-
pathsToInvalidate.add(`${apiBasePath}/fingerprint/${bundle.platform}/${bundle.fingerprintHash}/${newChannel$1}/*`);
|
|
226
|
-
}
|
|
227
|
-
if (bundle.targetAppVersion) if (!isExactVersion(bundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/*`);
|
|
136
|
+
},
|
|
137
|
+
async getChannels() {
|
|
138
|
+
const total = (await reloadBundles()).length;
|
|
139
|
+
const result = await this.getBundles({
|
|
140
|
+
limit: total,
|
|
141
|
+
offset: 0
|
|
142
|
+
});
|
|
143
|
+
return [...new Set(result.data.map((bundle) => bundle.channel))];
|
|
144
|
+
},
|
|
145
|
+
async commitBundle({ changedSets }) {
|
|
146
|
+
if (changedSets.length === 0) return;
|
|
147
|
+
const changedBundlesByKey = {};
|
|
148
|
+
const removalsByKey = {};
|
|
149
|
+
const pathsToInvalidate = /* @__PURE__ */ new Set();
|
|
150
|
+
let isTargetAppVersionChanged = false;
|
|
151
|
+
for (const { operation, data } of changedSets) {
|
|
152
|
+
if (data.targetAppVersion !== void 0) isTargetAppVersionChanged = true;
|
|
153
|
+
if (operation === "insert") {
|
|
154
|
+
const target = normalizeTargetAppVersion(data.targetAppVersion) ?? data.fingerprintHash;
|
|
155
|
+
if (!target) throw new Error("target not found");
|
|
156
|
+
const key = `${data.channel}/${data.platform}/${target}/update.json`;
|
|
157
|
+
const bundleWithKey = {
|
|
158
|
+
...data,
|
|
159
|
+
_updateJsonKey: key
|
|
160
|
+
};
|
|
161
|
+
bundlesMap.set(data.id, bundleWithKey);
|
|
162
|
+
pendingBundlesMap.set(data.id, bundleWithKey);
|
|
163
|
+
changedBundlesByKey[key] = changedBundlesByKey[key] || [];
|
|
164
|
+
changedBundlesByKey[key].push(removeBundleInternalKeys(bundleWithKey));
|
|
165
|
+
pathsToInvalidate.add(`/${key}`);
|
|
166
|
+
if (data.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${data.platform}/${data.fingerprintHash}/${data.channel}/*`);
|
|
167
|
+
else if (data.targetAppVersion) if (!isExactVersion(data.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${data.platform}/*`);
|
|
228
168
|
else {
|
|
229
|
-
const normalizedVersions = getSemverNormalizedVersions(
|
|
230
|
-
for (const version of normalizedVersions) {
|
|
231
|
-
pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${oldChannel}/*`);
|
|
232
|
-
pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${newChannel$1}/*`);
|
|
233
|
-
}
|
|
169
|
+
const normalizedVersions = getSemverNormalizedVersions(data.targetAppVersion);
|
|
170
|
+
for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${data.platform}/${version}/${data.channel}/*`);
|
|
234
171
|
}
|
|
172
|
+
continue;
|
|
235
173
|
}
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
if (!
|
|
174
|
+
if (operation === "delete") {
|
|
175
|
+
let bundle$1 = pendingBundlesMap.get(data.id);
|
|
176
|
+
if (!bundle$1) bundle$1 = bundlesMap.get(data.id);
|
|
177
|
+
if (!bundle$1) throw new Error("Bundle to delete not found");
|
|
178
|
+
bundlesMap.delete(data.id);
|
|
179
|
+
pendingBundlesMap.delete(data.id);
|
|
180
|
+
const key = bundle$1._updateJsonKey;
|
|
181
|
+
removalsByKey[key] = removalsByKey[key] || [];
|
|
182
|
+
removalsByKey[key].push(bundle$1.id);
|
|
183
|
+
pathsToInvalidate.add(`/${key}`);
|
|
184
|
+
if (bundle$1.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${bundle$1.platform}/${bundle$1.fingerprintHash}/${bundle$1.channel}/*`);
|
|
185
|
+
else if (bundle$1.targetAppVersion) if (!isExactVersion(bundle$1.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle$1.platform}/*`);
|
|
239
186
|
else {
|
|
240
|
-
const normalizedVersions = getSemverNormalizedVersions(
|
|
241
|
-
for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${
|
|
187
|
+
const normalizedVersions = getSemverNormalizedVersions(bundle$1.targetAppVersion);
|
|
188
|
+
for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle$1.platform}/${version}/${bundle$1.channel}/*`);
|
|
242
189
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
let bundle = pendingBundlesMap.get(data.id);
|
|
193
|
+
if (!bundle) bundle = bundlesMap.get(data.id);
|
|
194
|
+
if (!bundle) throw new Error("targetBundleId not found");
|
|
195
|
+
if (operation === "update") {
|
|
196
|
+
const newChannel = data.channel !== void 0 ? data.channel : bundle.channel;
|
|
197
|
+
const newPlatform = data.platform !== void 0 ? data.platform : bundle.platform;
|
|
198
|
+
const target = data.fingerprintHash ?? bundle.fingerprintHash ?? normalizeTargetAppVersion(data.targetAppVersion) ?? normalizeTargetAppVersion(bundle.targetAppVersion);
|
|
199
|
+
if (!target) throw new Error("target not found");
|
|
200
|
+
const newKey = `${newChannel}/${newPlatform}/${target}/update.json`;
|
|
201
|
+
if (newKey !== bundle._updateJsonKey) {
|
|
202
|
+
const oldKey = bundle._updateJsonKey;
|
|
203
|
+
removalsByKey[oldKey] = removalsByKey[oldKey] || [];
|
|
204
|
+
removalsByKey[oldKey].push(bundle.id);
|
|
205
|
+
changedBundlesByKey[newKey] = changedBundlesByKey[newKey] || [];
|
|
206
|
+
const updatedBundle$1 = {
|
|
207
|
+
...bundle,
|
|
208
|
+
...data
|
|
209
|
+
};
|
|
210
|
+
updatedBundle$1._oldUpdateJsonKey = oldKey;
|
|
211
|
+
updatedBundle$1._updateJsonKey = newKey;
|
|
212
|
+
bundlesMap.set(data.id, updatedBundle$1);
|
|
213
|
+
pendingBundlesMap.set(data.id, updatedBundle$1);
|
|
214
|
+
changedBundlesByKey[newKey].push(removeBundleInternalKeys(updatedBundle$1));
|
|
215
|
+
pathsToInvalidate.add(`/${oldKey}`);
|
|
216
|
+
pathsToInvalidate.add(`/${newKey}`);
|
|
217
|
+
const oldChannel = bundle.channel;
|
|
218
|
+
const newChannel$1 = data.channel;
|
|
219
|
+
if (oldChannel !== newChannel$1) {
|
|
220
|
+
pathsToInvalidate.add(`/${oldChannel}/${bundle.platform}/target-app-versions.json`);
|
|
221
|
+
pathsToInvalidate.add(`/${newChannel$1}/${bundle.platform}/target-app-versions.json`);
|
|
222
|
+
if (bundle.fingerprintHash) {
|
|
223
|
+
pathsToInvalidate.add(`${apiBasePath}/fingerprint/${bundle.platform}/${bundle.fingerprintHash}/${oldChannel}/*`);
|
|
224
|
+
pathsToInvalidate.add(`${apiBasePath}/fingerprint/${bundle.platform}/${bundle.fingerprintHash}/${newChannel$1}/*`);
|
|
225
|
+
}
|
|
226
|
+
if (bundle.targetAppVersion) if (!isExactVersion(bundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/*`);
|
|
227
|
+
else {
|
|
228
|
+
const normalizedVersions = getSemverNormalizedVersions(bundle.targetAppVersion);
|
|
229
|
+
for (const version of normalizedVersions) {
|
|
230
|
+
pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${oldChannel}/*`);
|
|
231
|
+
pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${newChannel$1}/*`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (updatedBundle$1.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${bundle.platform}/${updatedBundle$1.fingerprintHash}/${updatedBundle$1.channel}/*`);
|
|
236
|
+
else if (updatedBundle$1.targetAppVersion) {
|
|
237
|
+
if (!isExactVersion(updatedBundle$1.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle$1.platform}/*`);
|
|
238
|
+
else {
|
|
239
|
+
const normalizedVersions = getSemverNormalizedVersions(updatedBundle$1.targetAppVersion);
|
|
240
|
+
for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle$1.platform}/${version}/${updatedBundle$1.channel}/*`);
|
|
241
|
+
}
|
|
242
|
+
if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle$1.targetAppVersion) if (!isExactVersion(bundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/*`);
|
|
243
|
+
else {
|
|
244
|
+
const oldNormalizedVersions = getSemverNormalizedVersions(bundle.targetAppVersion);
|
|
245
|
+
for (const version of oldNormalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${bundle.channel}/*`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const currentKey = bundle._updateJsonKey;
|
|
251
|
+
const updatedBundle = {
|
|
252
|
+
...bundle,
|
|
253
|
+
...data
|
|
254
|
+
};
|
|
255
|
+
bundlesMap.set(data.id, updatedBundle);
|
|
256
|
+
pendingBundlesMap.set(data.id, updatedBundle);
|
|
257
|
+
changedBundlesByKey[currentKey] = changedBundlesByKey[currentKey] || [];
|
|
258
|
+
changedBundlesByKey[currentKey].push(removeBundleInternalKeys(updatedBundle));
|
|
259
|
+
pathsToInvalidate.add(`/${currentKey}`);
|
|
260
|
+
if (updatedBundle.fingerprintHash) pathsToInvalidate.add(`${apiBasePath}/fingerprint/${updatedBundle.platform}/${updatedBundle.fingerprintHash}/${updatedBundle.channel}/*`);
|
|
261
|
+
else if (updatedBundle.targetAppVersion) {
|
|
262
|
+
if (!isExactVersion(updatedBundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle.platform}/*`);
|
|
263
|
+
else {
|
|
264
|
+
const normalizedVersions = getSemverNormalizedVersions(updatedBundle.targetAppVersion);
|
|
265
|
+
for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle.platform}/${version}/${updatedBundle.channel}/*`);
|
|
266
|
+
}
|
|
267
|
+
if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle.targetAppVersion) if (!isExactVersion(bundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/*`);
|
|
268
|
+
else {
|
|
269
|
+
const oldNormalizedVersions = getSemverNormalizedVersions(bundle.targetAppVersion);
|
|
270
|
+
for (const version of oldNormalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${bundle.channel}/*`);
|
|
271
|
+
}
|
|
247
272
|
}
|
|
248
273
|
}
|
|
249
|
-
continue;
|
|
250
274
|
}
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
else {
|
|
265
|
-
const normalizedVersions = getSemverNormalizedVersions(updatedBundle.targetAppVersion);
|
|
266
|
-
for (const version of normalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${updatedBundle.platform}/${version}/${updatedBundle.channel}/*`);
|
|
267
|
-
}
|
|
268
|
-
if (bundle.targetAppVersion && bundle.targetAppVersion !== updatedBundle.targetAppVersion) if (!isExactVersion(bundle.targetAppVersion)) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/*`);
|
|
269
|
-
else {
|
|
270
|
-
const oldNormalizedVersions = getSemverNormalizedVersions(bundle.targetAppVersion);
|
|
271
|
-
for (const version of oldNormalizedVersions) pathsToInvalidate.add(`${apiBasePath}/app-version/${bundle.platform}/${version}/${bundle.channel}/*`);
|
|
275
|
+
for (const oldKey of Object.keys(removalsByKey)) await (async () => {
|
|
276
|
+
const updatedBundles = (await loadObject(oldKey) ?? []).filter((b) => !removalsByKey[oldKey].includes(b.id));
|
|
277
|
+
updatedBundles.sort((a, b) => b.id.localeCompare(a.id));
|
|
278
|
+
if (updatedBundles.length === 0) await deleteObject(oldKey);
|
|
279
|
+
else await uploadObject(oldKey, updatedBundles);
|
|
280
|
+
})();
|
|
281
|
+
for (const key of Object.keys(changedBundlesByKey)) await (async () => {
|
|
282
|
+
const currentBundles = await loadObject(key) ?? [];
|
|
283
|
+
const pureBundles = changedBundlesByKey[key].map((bundle) => bundle);
|
|
284
|
+
for (const changedBundle of pureBundles) {
|
|
285
|
+
const index = currentBundles.findIndex((b) => b.id === changedBundle.id);
|
|
286
|
+
if (index >= 0) currentBundles[index] = changedBundle;
|
|
287
|
+
else currentBundles.push(changedBundle);
|
|
272
288
|
}
|
|
289
|
+
currentBundles.sort((a, b) => b.id.localeCompare(a.id));
|
|
290
|
+
await uploadObject(key, currentBundles);
|
|
291
|
+
})();
|
|
292
|
+
const updatedTargetFilePaths = /* @__PURE__ */ new Set();
|
|
293
|
+
if (isTargetAppVersionChanged) for (const platform of PLATFORMS) {
|
|
294
|
+
const updatedPaths = await updateTargetVersionsForPlatform(platform);
|
|
295
|
+
for (const path of updatedPaths) updatedTargetFilePaths.add(path);
|
|
273
296
|
}
|
|
297
|
+
for (const path of updatedTargetFilePaths) pathsToInvalidate.add(path);
|
|
298
|
+
const encondedPaths = /* @__PURE__ */ new Set();
|
|
299
|
+
for (const path of pathsToInvalidate) encondedPaths.add(encodeURI(path));
|
|
300
|
+
await invalidatePaths(Array.from(encondedPaths));
|
|
301
|
+
pendingBundlesMap.clear();
|
|
274
302
|
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
updatedBundles.sort((a, b) => b.id.localeCompare(a.id));
|
|
279
|
-
if (updatedBundles.length === 0) await deleteObject(context, oldKey);
|
|
280
|
-
else await uploadObject(context, oldKey, updatedBundles);
|
|
281
|
-
})();
|
|
282
|
-
for (const key of Object.keys(changedBundlesByKey)) await (async () => {
|
|
283
|
-
const currentBundles = await loadObject(context, key) ?? [];
|
|
284
|
-
const pureBundles = changedBundlesByKey[key].map((bundle) => bundle);
|
|
285
|
-
for (const changedBundle of pureBundles) {
|
|
286
|
-
const index = currentBundles.findIndex((b) => b.id === changedBundle.id);
|
|
287
|
-
if (index >= 0) currentBundles[index] = changedBundle;
|
|
288
|
-
else currentBundles.push(changedBundle);
|
|
289
|
-
}
|
|
290
|
-
currentBundles.sort((a, b) => b.id.localeCompare(a.id));
|
|
291
|
-
await uploadObject(context, key, currentBundles);
|
|
292
|
-
})();
|
|
293
|
-
const updatedTargetFilePaths = /* @__PURE__ */ new Set();
|
|
294
|
-
if (isTargetAppVersionChanged) for (const platform of PLATFORMS) {
|
|
295
|
-
const updatedPaths = await updateTargetVersionsForPlatform(context, platform);
|
|
296
|
-
for (const path of updatedPaths) updatedTargetFilePaths.add(path);
|
|
297
|
-
}
|
|
298
|
-
for (const path of updatedTargetFilePaths) pathsToInvalidate.add(path);
|
|
299
|
-
const encondedPaths = /* @__PURE__ */ new Set();
|
|
300
|
-
for (const path of pathsToInvalidate) encondedPaths.add(encodeURI(path));
|
|
301
|
-
await invalidatePaths(context, Array.from(encondedPaths));
|
|
302
|
-
pendingBundlesMap.clear();
|
|
303
|
-
hooks?.onDatabaseUpdated?.();
|
|
304
|
-
}
|
|
305
|
-
}, hooks);
|
|
303
|
+
})
|
|
304
|
+
})({}, hooks)();
|
|
305
|
+
};
|
|
306
306
|
};
|
|
307
307
|
|
|
308
308
|
//#endregion
|