@fastly/compute-js-static-publish 8.0.0-beta.8 → 8.0.0-beta.9
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/README.md +18 -4
- package/README.short.md +18 -4
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +5 -2
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +1 -1
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +83 -61
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +4 -2
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +3 -5
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-local-provider.js +3 -8
- package/build/cli/cli/storage/kv-store-provider.d.ts +4 -5
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +38 -66
- package/build/cli/cli/storage/s3-storage-provider.d.ts +3 -5
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +27 -37
- package/build/cli/cli/storage/storage-provider.d.ts +5 -5
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/util/content-types.d.ts.map +1 -1
- package/build/cli/cli/util/content-types.js +4 -1
- package/build/cli/cli/util/kv-store-items.d.ts +12 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-items.js +49 -0
- package/build/cli/cli/util/kv-store.d.ts +6 -0
- package/build/cli/cli/util/kv-store.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store.js +39 -2
- package/build/cli/cli/util/retryable.d.ts +2 -1
- package/build/cli/cli/util/retryable.d.ts.map +1 -1
- package/build/cli/cli/util/retryable.js +34 -1
- package/build/cli/models/assets/index.js +1 -1
- package/build/server/models/assets/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,22 +24,26 @@ npx @fastly/compute-js-static-publish@latest --root-dir=./public --kv-store-name
|
|
|
24
24
|
**New in v8:** S3-compatible storage (such as Fastly Object Storage) is also supported (Beta). To use this mode, type:
|
|
25
25
|
|
|
26
26
|
```sh
|
|
27
|
-
npx @fastly/compute-js-static-publish@latest --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket
|
|
27
|
+
npx @fastly/compute-js-static-publish@latest --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
If the storage needs a custom endpoint, as Fastly Object Storage does, add `--s3-endpoint=<endpoint>` (for example, `--s3-endpoint=https://us-east-1.object.fastlystorage.app`).
|
|
31
|
+
|
|
32
|
+
For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/v8/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
|
|
31
33
|
|
|
32
34
|
### 🔧 Local Preview
|
|
33
35
|
|
|
34
36
|
```sh
|
|
35
37
|
cd compute-js
|
|
36
38
|
npm install
|
|
37
|
-
npm run dev:publish # 'publish' your files to the simulated local KV Store
|
|
39
|
+
npm run dev:publish # 'publish' your files to the simulated local KV Store
|
|
38
40
|
npm run dev:start # preview locally
|
|
39
41
|
```
|
|
40
42
|
|
|
41
43
|
Serves your app at `http://127.0.0.1:7676`. If the app is using the KV Store, your content is served from a simulated KV Store managed by the development server.
|
|
42
44
|
|
|
45
|
+
If the app uses S3-compatible storage, use `npm run s3:publish` in place of `npm run dev:publish`. This uploads your files to the bucket. Set the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables before you run `s3:publish` and `dev:start`.
|
|
46
|
+
|
|
43
47
|
### 🚀 Deploy to Production
|
|
44
48
|
|
|
45
49
|
When you're ready to go live, [create a free Fastly account](https://www.fastly.com/signup/?tier=free) if you haven't already, and then:
|
|
@@ -57,6 +61,8 @@ cd compute-js
|
|
|
57
61
|
npm run fastly:publish # upload your static files
|
|
58
62
|
```
|
|
59
63
|
|
|
64
|
+
If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates.
|
|
65
|
+
|
|
60
66
|
## Features
|
|
61
67
|
|
|
62
68
|
- Named collections for previews, staging, production
|
|
@@ -67,4 +73,12 @@ npm run fastly:publish # upload your static files
|
|
|
67
73
|
## Documentation
|
|
68
74
|
|
|
69
75
|
📘 Full documentation available on GitHub:
|
|
70
|
-
[https://github.com/fastly/compute-js-static-publish](https://github.com/fastly/compute-js-static-publish)
|
|
76
|
+
[https://github.com/fastly/compute-js-static-publish/tree/v8](https://github.com/fastly/compute-js-static-publish/tree/v8)
|
|
77
|
+
|
|
78
|
+
### Security issues
|
|
79
|
+
|
|
80
|
+
Please see our [SECURITY.md](SECURITY.md) for guidance on reporting security-related issues.
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
[MIT](./LICENSE).
|
package/README.short.md
CHANGED
|
@@ -24,22 +24,26 @@ npx @fastly/compute-js-static-publish@latest --root-dir=./public --kv-store-name
|
|
|
24
24
|
**New in v8:** S3-compatible storage (such as Fastly Object Storage) is also supported (Beta). To use this mode, type:
|
|
25
25
|
|
|
26
26
|
```sh
|
|
27
|
-
npx @fastly/compute-js-static-publish@latest --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket
|
|
27
|
+
npx @fastly/compute-js-static-publish@latest --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
If the storage needs a custom endpoint, as Fastly Object Storage does, add `--s3-endpoint=<endpoint>` (for example, `--s3-endpoint=https://us-east-1.object.fastlystorage.app`).
|
|
31
|
+
|
|
32
|
+
For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/v8/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
|
|
31
33
|
|
|
32
34
|
### 🔧 Local Preview
|
|
33
35
|
|
|
34
36
|
```sh
|
|
35
37
|
cd compute-js
|
|
36
38
|
npm install
|
|
37
|
-
npm run dev:publish # 'publish' your files to the simulated local KV Store
|
|
39
|
+
npm run dev:publish # 'publish' your files to the simulated local KV Store
|
|
38
40
|
npm run dev:start # preview locally
|
|
39
41
|
```
|
|
40
42
|
|
|
41
43
|
Serves your app at `http://127.0.0.1:7676`. If the app is using the KV Store, your content is served from a simulated KV Store managed by the development server.
|
|
42
44
|
|
|
45
|
+
If the app uses S3-compatible storage, use `npm run s3:publish` in place of `npm run dev:publish`. This uploads your files to the bucket. Set the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables before you run `s3:publish` and `dev:start`.
|
|
46
|
+
|
|
43
47
|
### 🚀 Deploy to Production
|
|
44
48
|
|
|
45
49
|
When you're ready to go live, [create a free Fastly account](https://www.fastly.com/signup/?tier=free) if you haven't already, and then:
|
|
@@ -57,6 +61,8 @@ cd compute-js
|
|
|
57
61
|
npm run fastly:publish # upload your static files
|
|
58
62
|
```
|
|
59
63
|
|
|
64
|
+
If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates.
|
|
65
|
+
|
|
60
66
|
## Features
|
|
61
67
|
|
|
62
68
|
- Named collections for previews, staging, production
|
|
@@ -67,4 +73,12 @@ npm run fastly:publish # upload your static files
|
|
|
67
73
|
## Documentation
|
|
68
74
|
|
|
69
75
|
📘 Full documentation available on GitHub:
|
|
70
|
-
[https://github.com/fastly/compute-js-static-publish](https://github.com/fastly/compute-js-static-publish)
|
|
76
|
+
[https://github.com/fastly/compute-js-static-publish/tree/v8](https://github.com/fastly/compute-js-static-publish/tree/v8)
|
|
77
|
+
|
|
78
|
+
### Security issues
|
|
79
|
+
|
|
80
|
+
Please see our [SECURITY.md](SECURITY.md) for guidance on reporting security-related issues.
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
[MIT](./LICENSE).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}
|
|
@@ -162,7 +162,10 @@ export async function action(actionArgs) {
|
|
|
162
162
|
assetsIdsInUse.add(`sha256_${assetEntry.key.slice('sha256:'.length)}`);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
}
|
|
165
|
+
}, undefined,
|
|
166
|
+
// If an index cannot be read, stop. If we continue, we mark the files
|
|
167
|
+
// and settings of that collection as not in use, and delete them.
|
|
168
|
+
true);
|
|
166
169
|
console.log('');
|
|
167
170
|
// ### List all settings ###
|
|
168
171
|
console.log('Enumerating settings:');
|
|
@@ -217,6 +220,6 @@ export async function action(actionArgs) {
|
|
|
217
220
|
console.log(`Deleting key from storage: ${key}`);
|
|
218
221
|
await storageProvider.deleteStorageEntry(key);
|
|
219
222
|
}
|
|
220
|
-
});
|
|
223
|
+
}, undefined, true);
|
|
221
224
|
console.log('✅ Completed.');
|
|
222
225
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAkDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAkDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuIhD"}
|
|
@@ -144,6 +144,6 @@ export async function action(actionArgs) {
|
|
|
144
144
|
await storageProvider.doConcurrentParallel(items, async (_, key) => {
|
|
145
145
|
console.log(`Deleting key from storage: ${key}`);
|
|
146
146
|
await storageProvider.deleteStorageEntry(key);
|
|
147
|
-
});
|
|
147
|
+
}, undefined, true);
|
|
148
148
|
console.log("✅ Completed.");
|
|
149
149
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AAuGA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA8fhD"}
|
|
@@ -12,6 +12,7 @@ import { LoadConfigError, loadPublishContentConfigFile, loadStaticPublisherRcFil
|
|
|
12
12
|
import { applyDefaults } from '../../util/data.js';
|
|
13
13
|
import { calculateFileSizeAndHash, enumerateFiles, rootRelative } from '../../util/files.js';
|
|
14
14
|
import { ensureVariantFileExists } from '../../util/variants.js';
|
|
15
|
+
import { concurrentMap } from '../../util/retryable.js';
|
|
15
16
|
import { loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
|
|
16
17
|
// Storage key format:
|
|
17
18
|
// <publishId>_index_<preview_id>.json
|
|
@@ -239,15 +240,35 @@ export async function action(actionArgs) {
|
|
|
239
240
|
// and for serving using the local development server.
|
|
240
241
|
const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
|
|
241
242
|
fs.mkdirSync(storageContentDir, { recursive: true });
|
|
242
|
-
//
|
|
243
|
-
// Includes items that already exist as well. 'write' signifies
|
|
244
|
-
// that the item is to be written
|
|
243
|
+
// The items to write to storage.
|
|
245
244
|
const batch = new StorageProviderBatch();
|
|
246
245
|
// Assets included in the publishing, keyed by asset key
|
|
247
246
|
const assetsIndex = {};
|
|
248
|
-
const
|
|
247
|
+
const baseHashToVariantKeepMap = new Map();
|
|
248
|
+
// #### Keys that are already in storage
|
|
249
|
+
// The key of a file is the hash of its content. If the key exists, storage
|
|
250
|
+
// already has the same content. Thus we do not compress, hash, or upload it again.
|
|
251
|
+
// In local mode, a key can refer to a working file that was deleted, so we do not list.
|
|
252
|
+
let existingKeys;
|
|
253
|
+
if (!overwriteExisting && !localMode) {
|
|
254
|
+
console.log(`🔎 Listing files that are already in storage...`);
|
|
255
|
+
existingKeys = new Set(await storageProvider.getStorageKeys(`${publishId}_files_`) ?? []);
|
|
256
|
+
console.log(`✅ Found ${existingKeys.size} key(s).`);
|
|
257
|
+
}
|
|
258
|
+
let existingVariantCount = 0;
|
|
259
|
+
function isVariantInStorage(variantKey, numChunks) {
|
|
260
|
+
if (existingKeys == null || !existingKeys.has(variantKey)) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
for (let chunkIndex = 1; chunkIndex < numChunks; chunkIndex++) {
|
|
264
|
+
if (!existingKeys.has(`${variantKey}_${chunkIndex}`)) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
249
270
|
// #### Iterate files
|
|
250
|
-
const
|
|
271
|
+
const fileResults = await concurrentMap(files, async (file) => {
|
|
251
272
|
// #### asset key
|
|
252
273
|
const assetKey = file.slice(publicDirRoot.length)
|
|
253
274
|
// in Windows, assetKey will otherwise end up as \path\file.html
|
|
@@ -283,12 +304,15 @@ export async function action(actionArgs) {
|
|
|
283
304
|
console.log(`📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}`);
|
|
284
305
|
const stats = fs.statSync(file);
|
|
285
306
|
const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
|
|
286
|
-
// ####
|
|
287
|
-
let
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
|
|
307
|
+
// #### Keep flag per variant
|
|
308
|
+
let variantKeeps = baseHashToVariantKeepMap.get(baseHash);
|
|
309
|
+
if (variantKeeps == null) {
|
|
310
|
+
variantKeeps = new Map();
|
|
311
|
+
baseHashToVariantKeepMap.set(baseHash, variantKeeps);
|
|
291
312
|
}
|
|
313
|
+
// We know the number of chunks of the original before we read it. For a
|
|
314
|
+
// compressed variant, we know it only if the original fits in one chunk.
|
|
315
|
+
const baseNumChunks = storageProvider.calculateNumChunks(baseSize);
|
|
292
316
|
const variantsToKeep = [];
|
|
293
317
|
const variants = [
|
|
294
318
|
'original',
|
|
@@ -303,67 +327,63 @@ export async function action(actionArgs) {
|
|
|
303
327
|
variantFilename = `${variantFilename}_${variant}`;
|
|
304
328
|
}
|
|
305
329
|
const variantFilePath = path.resolve(storageContentDir, variantFilename);
|
|
306
|
-
let
|
|
307
|
-
if (
|
|
330
|
+
let keep = variantKeeps.get(variant);
|
|
331
|
+
if (keep != null) {
|
|
308
332
|
if (verbose) {
|
|
309
333
|
console.log(` 🏃♂️ Asset "${variantKey}" is identical to an item we already know about, reusing existing copy.`);
|
|
310
334
|
}
|
|
311
335
|
}
|
|
336
|
+
else if ((variant === 'original' || baseNumChunks === 1) &&
|
|
337
|
+
isVariantInStorage(variantKey, variant === 'original' ? baseNumChunks : 1)) {
|
|
338
|
+
if (verbose) {
|
|
339
|
+
console.log(` ・ Asset found in storage with key "${variantKey}".`);
|
|
340
|
+
}
|
|
341
|
+
existingVariantCount++;
|
|
342
|
+
// We upload a compressed variant only if it is smaller than the
|
|
343
|
+
// original. Thus if it is in storage, the index keeps it.
|
|
344
|
+
keep = true;
|
|
345
|
+
variantKeeps.set(variant, keep);
|
|
346
|
+
}
|
|
312
347
|
else {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
// And we already know its hash and size.
|
|
320
|
-
variantMetadata = Object.assign(assetVariantMetadata, { existsInKvStore: true });
|
|
321
|
-
}
|
|
348
|
+
await ensureVariantFileExists(variantFilePath, variant, file, verbose);
|
|
349
|
+
let contentEncoding, hash, size;
|
|
350
|
+
if (variant === 'original') {
|
|
351
|
+
contentEncoding = undefined;
|
|
352
|
+
hash = baseHash;
|
|
353
|
+
size = baseSize;
|
|
322
354
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
else {
|
|
333
|
-
contentEncoding = variant;
|
|
334
|
-
({ hash, size } = await calculateFileSizeAndHash(variantFilePath));
|
|
335
|
-
}
|
|
355
|
+
else {
|
|
356
|
+
contentEncoding = variant;
|
|
357
|
+
({ hash, size } = await calculateFileSizeAndHash(variantFilePath));
|
|
358
|
+
}
|
|
359
|
+
// Only keep variants whose file size actually ends up smaller than
|
|
360
|
+
// what we started with. Do not upload the other variants.
|
|
361
|
+
keep = variant === 'original' || size < baseSize;
|
|
362
|
+
variantKeeps.set(variant, keep);
|
|
363
|
+
if (keep) {
|
|
336
364
|
const numChunks = storageProvider.calculateNumChunks(size);
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
size,
|
|
365
|
+
const metadataJson = {
|
|
366
|
+
size: String(size),
|
|
340
367
|
hash,
|
|
341
|
-
numChunks: numChunks > 1 ? numChunks : undefined,
|
|
342
|
-
existsInKvStore: false,
|
|
343
368
|
};
|
|
369
|
+
if (contentEncoding != null) {
|
|
370
|
+
metadataJson.contentEncoding = contentEncoding;
|
|
371
|
+
}
|
|
372
|
+
if (numChunks > 1) {
|
|
373
|
+
metadataJson.numChunks = String(numChunks);
|
|
374
|
+
}
|
|
375
|
+
batchItems.push({
|
|
376
|
+
size,
|
|
377
|
+
key: variantKey,
|
|
378
|
+
filePath: variantFilePath,
|
|
379
|
+
metadataJson,
|
|
380
|
+
});
|
|
344
381
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
size: String(variantMetadata.size),
|
|
348
|
-
hash: variantMetadata.hash,
|
|
349
|
-
};
|
|
350
|
-
if (variantMetadata.contentEncoding != null) {
|
|
351
|
-
metadataJson.contentEncoding = variantMetadata.contentEncoding;
|
|
352
|
-
}
|
|
353
|
-
if (variantMetadata.numChunks != null) {
|
|
354
|
-
metadataJson.numChunks = String(variantMetadata.numChunks);
|
|
382
|
+
else if (verbose) {
|
|
383
|
+
console.log(` ・ Variant "${variantKey}" is not smaller than the original, not uploading.`);
|
|
355
384
|
}
|
|
356
|
-
batchItems.push({
|
|
357
|
-
write: !variantMetadata.existsInKvStore,
|
|
358
|
-
size: variantMetadata.size,
|
|
359
|
-
key: variantKey,
|
|
360
|
-
filePath: variantFilePath,
|
|
361
|
-
metadataJson,
|
|
362
|
-
});
|
|
363
385
|
}
|
|
364
|
-
|
|
365
|
-
// what we started with.
|
|
366
|
-
if (variant !== 'original' && variantMetadata.size < baseSize) {
|
|
386
|
+
if (variant !== 'original' && keep) {
|
|
367
387
|
variantsToKeep.push(variant);
|
|
368
388
|
}
|
|
369
389
|
}
|
|
@@ -379,7 +399,6 @@ export async function action(actionArgs) {
|
|
|
379
399
|
batchItems,
|
|
380
400
|
};
|
|
381
401
|
});
|
|
382
|
-
const fileResults = await Promise.all(filePromises);
|
|
383
402
|
for (const result of fileResults) {
|
|
384
403
|
if (result == null) {
|
|
385
404
|
continue;
|
|
@@ -390,7 +409,10 @@ export async function action(actionArgs) {
|
|
|
390
409
|
}
|
|
391
410
|
}
|
|
392
411
|
console.log(`✅ Scan complete.`);
|
|
393
|
-
|
|
412
|
+
if (existingKeys != null) {
|
|
413
|
+
console.log(` | ${existingVariantCount} variant(s) already in storage, ${batch.storageProviderBatchEntries.length} to upload.`);
|
|
414
|
+
}
|
|
415
|
+
await storageProvider.applyBatch(batch, { existingKeys });
|
|
394
416
|
// #### INDEX FILE
|
|
395
417
|
console.log(`🗂️ Saving Index...`);
|
|
396
418
|
const indexFileKey = `${publishId}_index_${collectionName}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAuEA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AA0TF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAuEA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AA0TF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAwqBhD"}
|
|
@@ -202,7 +202,7 @@ function buildOptions(packageJson, commandLineOptions) {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
{
|
|
205
|
-
let autoExt
|
|
205
|
+
let autoExt;
|
|
206
206
|
const autoExtValue = commandLineOptions['auto-ext'];
|
|
207
207
|
const asArray = Array.isArray(autoExtValue) ? autoExtValue : [autoExtValue];
|
|
208
208
|
if (asArray.every((x) => typeof x === 'string')) {
|
|
@@ -505,6 +505,7 @@ export async function action(actionArgs) {
|
|
|
505
505
|
else if (!fs.existsSync(spaFilename)) {
|
|
506
506
|
console.log(`⚠️ Warning: Ignoring specified SPA file '${SPA}' does not exist.`);
|
|
507
507
|
console.log(` * ${rootRelative(spaFilename)} does not exist.`);
|
|
508
|
+
spaFilename = undefined;
|
|
508
509
|
}
|
|
509
510
|
}
|
|
510
511
|
const NOT_FOUND_PAGE = options.notFoundPage;
|
|
@@ -521,6 +522,7 @@ export async function action(actionArgs) {
|
|
|
521
522
|
else if (!fs.existsSync(notFoundPageFilename)) {
|
|
522
523
|
console.log(`⚠️ Warning: Ignoring specified Not Found file '${NOT_FOUND_PAGE}' as it does not exist.`);
|
|
523
524
|
console.log(` * ${rootRelative(notFoundPageFilename)} does not exist.`);
|
|
525
|
+
notFoundPageFilename = undefined;
|
|
524
526
|
}
|
|
525
527
|
}
|
|
526
528
|
const autoIndex = options.autoIndex;
|
|
@@ -676,7 +678,7 @@ export async function action(actionArgs) {
|
|
|
676
678
|
author,
|
|
677
679
|
type: 'module',
|
|
678
680
|
devDependencies: {
|
|
679
|
-
"@fastly/cli": "^
|
|
681
|
+
"@fastly/cli": "^16.0.0",
|
|
680
682
|
'@fastly/compute-js-static-publish': computeJsStaticPublisherVersion,
|
|
681
683
|
},
|
|
682
684
|
dependencies: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch } from './storage-provider.js';
|
|
1
|
+
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type ApplyBatchOptions } from './storage-provider.js';
|
|
3
2
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
4
3
|
export declare class KvStoreLocalProvider implements StorageProvider {
|
|
5
4
|
constructor(storeFile: string, computeAppDir: string);
|
|
@@ -10,12 +9,11 @@ export declare class KvStoreLocalProvider implements StorageProvider {
|
|
|
10
9
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
11
10
|
submitStorageEntry(key: string, filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
12
11
|
deleteStorageEntry(key: string): Promise<void>;
|
|
13
|
-
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
12
|
+
applyBatch(batch: StorageProviderBatch, _options?: ApplyBatchOptions): Promise<void>;
|
|
14
13
|
doConcurrentParallel<TObject extends {
|
|
15
14
|
key: string;
|
|
16
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
15
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
17
16
|
calculateNumChunks(size: number): number;
|
|
18
|
-
getExistingAssetVariant(_variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
19
17
|
purgeSurrogateKey(_surrogateKey: string): Promise<void>;
|
|
20
18
|
}
|
|
21
19
|
//# sourceMappingURL=kv-store-local-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-local-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-local-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kv-store-local-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-local-provider.ts"],"names":[],"mappings":"AA0BA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAK/B,eAAO,MAAM,kBAAkB,EAAE,sBAkBhC,CAAC;AAEF,qBAAa,oBAAqB,YAAW,eAAe;gBAExD,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM;IAMvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAEzB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAQzD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAc1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAe9D,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAsBV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,QAAQ,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBxF,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,CAAC,EAAE,MAAM,EACtB,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAYhB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIlC,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAE9D"}
|
|
@@ -64,7 +64,7 @@ export class KvStoreLocalProvider {
|
|
|
64
64
|
async deleteStorageEntry(key) {
|
|
65
65
|
await localKvStoreDeleteEntry(this.storeFile, key);
|
|
66
66
|
}
|
|
67
|
-
async applyBatch(batch) {
|
|
67
|
+
async applyBatch(batch, _options = {}) {
|
|
68
68
|
console.log(`🍪 Chunking large files...`);
|
|
69
69
|
await applyKVStoreEntriesChunks(batch.storageProviderBatchEntries, KV_STORE_CHUNK_SIZE);
|
|
70
70
|
console.log(`✅ Large files have been chunked.`);
|
|
@@ -72,17 +72,12 @@ export class KvStoreLocalProvider {
|
|
|
72
72
|
writeKVStoreEntriesForLocal(this.storeFile, this.computeAppDir, batch.storageProviderBatchEntries);
|
|
73
73
|
console.log(`✅ Wrote KV Store entries for local server.`);
|
|
74
74
|
}
|
|
75
|
-
async doConcurrentParallel(objects, fn, maxConcurrent) {
|
|
76
|
-
await concurrentParallel(objects, fn, () => null, maxConcurrent);
|
|
75
|
+
async doConcurrentParallel(objects, fn, maxConcurrent, throwOnError = false) {
|
|
76
|
+
await concurrentParallel(objects, fn, () => null, maxConcurrent, throwOnError);
|
|
77
77
|
}
|
|
78
78
|
calculateNumChunks(size) {
|
|
79
79
|
return Math.ceil(size / KV_STORE_CHUNK_SIZE);
|
|
80
80
|
}
|
|
81
|
-
async getExistingAssetVariant(_variantKey) {
|
|
82
|
-
// The purpose of this function is to use a HEAD request against storage
|
|
83
|
-
// to save time by checking for an existing item. This is not applicable for local.
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
81
|
async purgeSurrogateKey(_surrogateKey) {
|
|
87
82
|
}
|
|
88
83
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type AssetVariantMetadata } from '../../models/assets/index.js';
|
|
2
1
|
import { type FastlyApiContext } from '../util/api-token.js';
|
|
3
2
|
import { type KvStoreEntryInfo } from '../util/kv-store.js';
|
|
4
|
-
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch } from './storage-provider.js';
|
|
3
|
+
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type StorageProviderBatchEntry, type ApplyBatchOptions } from './storage-provider.js';
|
|
5
4
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
6
5
|
export declare class KvStoreProvider implements StorageProvider {
|
|
7
6
|
constructor(storeName: string, fastlyApiToken: string);
|
|
@@ -12,12 +11,12 @@ export declare class KvStoreProvider implements StorageProvider {
|
|
|
12
11
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
13
12
|
submitStorageEntry(key: string, _filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
14
13
|
deleteStorageEntry(key: string): Promise<void>;
|
|
15
|
-
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
14
|
+
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
15
|
+
uploadEntries(entries: StorageProviderBatchEntry[]): Promise<void>;
|
|
16
16
|
doConcurrentParallel<TObject extends {
|
|
17
17
|
key: string;
|
|
18
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
18
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
19
19
|
calculateNumChunks(size: number): number;
|
|
20
|
-
getExistingAssetVariant(variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
21
20
|
purgeSurrogateKey(_surrogateKey: string): Promise<void>;
|
|
22
21
|
}
|
|
23
22
|
export declare function kvStoreEntryToStorageEntry(kvStoreEntry: KvStoreEntryInfo): StorageEntry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kv-store-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-provider.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EACL,KAAK,gBAAgB,EAMtB,MAAM,qBAAqB,CAAC;AAY7B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,kBAAkB,EAAE,sBAsBhC,CAAC;AAEF,qBAAa,eAAgB,YAAW,eAAe;gBAEnD,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM;IAMxB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;IAEd,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAUzD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAe1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAiB9D,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAYV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBvF,aAAa,CAAC,OAAO,EAAE,yBAAyB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA0ClE,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,EAC1B,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAqBhB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIlC,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAE9D;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,gBAAgB,gBAuB/B;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,iCAiCpD"}
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
-
import { decodeAssetVariantMetadata, } from '../../models/assets/index.js';
|
|
7
6
|
import { isKvStoreConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
8
7
|
import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
|
|
9
8
|
import { FetchError, loadApiToken, } from '../util/api-token.js';
|
|
10
9
|
import { rootRelative, } from '../util/files.js';
|
|
11
|
-
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry, kvStoreSubmitEntry,
|
|
12
|
-
import { applyKVStoreEntriesChunks, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
13
|
-
import { concurrentParallel, } from '../util/retryable.js';
|
|
10
|
+
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry, kvStoreSubmitEntry, kvStoreSubmitBatch, } from '../util/kv-store.js';
|
|
11
|
+
import { applyKVStoreEntriesChunks, packNdjsonBatches, ndjsonLineForBatchEntry, entriesToUpload, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
12
|
+
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
14
13
|
export const buildStoreProvider = (config, context) => {
|
|
15
14
|
if (isKvStoreConfigRc(config) && !context.localMode) {
|
|
16
15
|
console.log(` Working on the Fastly KV Store...`);
|
|
@@ -55,20 +54,43 @@ export class KvStoreProvider {
|
|
|
55
54
|
async deleteStorageEntry(key) {
|
|
56
55
|
await kvStoreDeleteEntry(this.fastlyApiContext, this.kvStoreName, key);
|
|
57
56
|
}
|
|
58
|
-
async applyBatch(batch) {
|
|
57
|
+
async applyBatch(batch, options = {}) {
|
|
58
|
+
const { existingKeys } = options;
|
|
59
59
|
console.log(`🍪 Chunking large files...`);
|
|
60
60
|
await applyKVStoreEntriesChunks(batch.storageProviderBatchEntries, KV_STORE_CHUNK_SIZE);
|
|
61
61
|
console.log(`✅ Large files have been chunked.`);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
let toWrite = batch.storageProviderBatchEntries;
|
|
63
|
+
if (existingKeys != null) {
|
|
64
|
+
toWrite = entriesToUpload(toWrite, existingKeys);
|
|
65
|
+
console.log(` | ${batch.storageProviderBatchEntries.length - toWrite.length} chunk(s) already present in the KV Store.`);
|
|
66
|
+
}
|
|
67
|
+
console.log(`📤 Uploading ${toWrite.length} entries to KV Store.`);
|
|
68
|
+
await this.uploadEntries(toWrite);
|
|
69
|
+
console.log(`✅ Uploaded entries to KV Store.`);
|
|
70
|
+
}
|
|
71
|
+
async uploadEntries(entries) {
|
|
72
|
+
const { batches, oversized } = packNdjsonBatches(entries);
|
|
73
|
+
await this.doConcurrentParallel(oversized, async ({ filePath, metadataJson }, key) => {
|
|
65
74
|
const fileBytes = fs.readFileSync(filePath);
|
|
66
75
|
await kvStoreSubmitEntry(this.fastlyApiContext, this.kvStoreName, key, fileBytes, metadataJson != null ? JSON.stringify(metadataJson) : undefined);
|
|
67
|
-
console.log(` 🌐 Submitted asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
|
|
68
|
-
});
|
|
69
|
-
|
|
76
|
+
console.log(` 🌐 Submitted large asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
|
|
77
|
+
}, 12, true);
|
|
78
|
+
await this.doConcurrentParallel(batches, async (batch, key) => {
|
|
79
|
+
const lines = batch.entries.map(ndjsonLineForBatchEntry);
|
|
80
|
+
const failures = await kvStoreSubmitBatch(this.fastlyApiContext, this.kvStoreName, lines);
|
|
81
|
+
if (failures.length > 0) {
|
|
82
|
+
// Keep only the entries that failed. The retry submits only these entries.
|
|
83
|
+
const failedKeys = new Set(failures.map(f => f.key));
|
|
84
|
+
const submittedCount = batch.entries.length;
|
|
85
|
+
batch.entries = batch.entries.filter(entry => failedKeys.has(entry.key));
|
|
86
|
+
const shown = failures.slice(0, 5).map(f => `${f.key} (${f.code ?? 'unknown'}: ${f.reason ?? 'unknown'})`).join(', ');
|
|
87
|
+
const more = failures.length > 5 ? `, and ${failures.length - 5} more` : '';
|
|
88
|
+
throw makeRetryable(new Error(`${failures.length} of ${submittedCount} entries failed: ${shown}${more}`));
|
|
89
|
+
}
|
|
90
|
+
console.log(` 🌐 Submitted ${batch.entries.length} entries to KV Store ("${key}").`);
|
|
91
|
+
}, 12, true);
|
|
70
92
|
}
|
|
71
|
-
async doConcurrentParallel(objects, fn, maxConcurrent = 12) {
|
|
93
|
+
async doConcurrentParallel(objects, fn, maxConcurrent = 12, throwOnError = false) {
|
|
72
94
|
await concurrentParallel(objects, fn, (err) => {
|
|
73
95
|
if (err instanceof FetchError) {
|
|
74
96
|
return `HTTP ${err.status}`;
|
|
@@ -76,65 +98,15 @@ export class KvStoreProvider {
|
|
|
76
98
|
else if (err instanceof TypeError) {
|
|
77
99
|
return 'transport';
|
|
78
100
|
}
|
|
101
|
+
else if (err instanceof Error) {
|
|
102
|
+
return err.message;
|
|
103
|
+
}
|
|
79
104
|
return null;
|
|
80
|
-
}, maxConcurrent);
|
|
105
|
+
}, maxConcurrent, throwOnError);
|
|
81
106
|
}
|
|
82
107
|
calculateNumChunks(size) {
|
|
83
108
|
return Math.ceil(size / KV_STORE_CHUNK_SIZE);
|
|
84
109
|
}
|
|
85
|
-
async getExistingAssetVariant(variantKey) {
|
|
86
|
-
let kvStoreItemMetadata = null;
|
|
87
|
-
const items = [{
|
|
88
|
-
key: variantKey,
|
|
89
|
-
}];
|
|
90
|
-
await this.doConcurrentParallel(items, async (_, variantKey) => {
|
|
91
|
-
// fastlyApiContext is non-null if useKvStore is true
|
|
92
|
-
const kvStoreEntryInfo = await getKvStoreEntryInfo(this.fastlyApiContext, this.kvStoreName, variantKey);
|
|
93
|
-
if (!kvStoreEntryInfo) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
let itemMetadata;
|
|
97
|
-
if (kvStoreEntryInfo.metadata != null) {
|
|
98
|
-
try {
|
|
99
|
-
itemMetadata = JSON.parse(kvStoreEntryInfo.metadata);
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
// if the metadata does not parse successfully as JSON,
|
|
103
|
-
// treat it as though it didn't exist.
|
|
104
|
-
}
|
|
105
|
-
itemMetadata = decodeAssetVariantMetadata(itemMetadata);
|
|
106
|
-
}
|
|
107
|
-
if (itemMetadata != null) {
|
|
108
|
-
let exists = false;
|
|
109
|
-
if (itemMetadata.size <= KV_STORE_CHUNK_SIZE) {
|
|
110
|
-
// For an item equal to or smaller than the chunk size, if it exists
|
|
111
|
-
// and its metadata asserts no chunk count, then we assume it exists.
|
|
112
|
-
if (itemMetadata.numChunks === undefined) {
|
|
113
|
-
exists = true;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
// For chunked objects, if the first chunk exists, and its metadata asserts
|
|
118
|
-
// the same number of chunks based on size, then we assume it exists (for now).
|
|
119
|
-
// In the future we might actually check for the existence and sizes of
|
|
120
|
-
// every chunk in the KV Store.
|
|
121
|
-
const expectedNumChunks = Math.ceil(itemMetadata.size / KV_STORE_CHUNK_SIZE);
|
|
122
|
-
if (itemMetadata.numChunks === expectedNumChunks) {
|
|
123
|
-
exists = true;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (exists) {
|
|
127
|
-
kvStoreItemMetadata = {
|
|
128
|
-
contentEncoding: itemMetadata.contentEncoding,
|
|
129
|
-
size: itemMetadata.size,
|
|
130
|
-
hash: itemMetadata.hash,
|
|
131
|
-
numChunks: itemMetadata.numChunks,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
return kvStoreItemMetadata;
|
|
137
|
-
}
|
|
138
110
|
async purgeSurrogateKey(_surrogateKey) {
|
|
139
111
|
}
|
|
140
112
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
2
|
import { type Command, type HttpHandlerOptions } from '@aws-sdk/types';
|
|
3
|
-
import { type
|
|
4
|
-
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch } from './storage-provider.js';
|
|
3
|
+
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type ApplyBatchOptions } from './storage-provider.js';
|
|
5
4
|
type CommandOutput<C> = C extends Command<any, any, any, infer O, any> ? O : never;
|
|
6
5
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
7
6
|
export declare class S3StorageProvider implements StorageProvider {
|
|
@@ -21,12 +20,11 @@ export declare class S3StorageProvider implements StorageProvider {
|
|
|
21
20
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
22
21
|
submitStorageEntry(key: string, _filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
23
22
|
deleteStorageEntry(key: string): Promise<void>;
|
|
24
|
-
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
23
|
+
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
25
24
|
doConcurrentParallel<TObject extends {
|
|
26
25
|
key: string;
|
|
27
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
26
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
28
27
|
calculateNumChunks(_size: number): number;
|
|
29
|
-
getExistingAssetVariant(variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
30
28
|
purgeSurrogateKey(surrogateKey: string): Promise<void>;
|
|
31
29
|
}
|
|
32
30
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAOA,OAAO,
|
|
1
|
+
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAOA,OAAO,EAUL,QAAQ,EAIT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AASxB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAuB/B,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEnF,eAAO,MAAM,kBAAkB,EAAE,sBAuDhC,CAAC;AAGF,qBAAa,iBAAkB,YAAW,eAAe;gBAErD,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM;IAWrB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAS;IAErC,OAAO,CAAC,QAAQ,CAAC,CAAW;IAC5B,WAAW;IAiBL,mBAAmB,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAClE,OAAO,EAAE,CAAC,EACV,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAWtB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IA8BzD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IA6B1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAwB9D,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAaV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BvF,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,EAC1B,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAmBhB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAInC,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA4B7D"}
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
-
import { DeleteObjectCommand, GetObjectCommand, HeadObjectCommand,
|
|
8
|
-
import { decodeAssetVariantMetadata, } from '../../models/assets/index.js';
|
|
7
|
+
import { DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, PutObjectCommand, S3Client, S3ServiceException, paginateListObjectsV2, } from '@aws-sdk/client-s3';
|
|
9
8
|
import { isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
10
9
|
import { getS3StorageConfigFromRc, } from '../../models/config/s3-storage-config.js';
|
|
10
|
+
import { entriesToUpload } from '../util/kv-store-items.js';
|
|
11
11
|
import { loadS3Credentials, } from '../util/s3-credentials.js';
|
|
12
12
|
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
13
13
|
import { rootRelative, } from '../util/files.js';
|
|
@@ -89,20 +89,26 @@ export class S3StorageProvider {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
async getStorageKeys(prefix) {
|
|
92
|
+
const paginationConfig = {
|
|
93
|
+
client: this.getS3Client(),
|
|
94
|
+
};
|
|
92
95
|
const input = {
|
|
93
96
|
Bucket: this.s3Bucket,
|
|
94
|
-
MaxKeys: 4096,
|
|
95
97
|
Prefix: prefix,
|
|
96
|
-
ContinuationToken: undefined, // pagination
|
|
97
98
|
};
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
const paginator = paginateListObjectsV2(paginationConfig, input);
|
|
100
|
+
const objectKeys = [];
|
|
101
|
+
for await (const { Contents } of paginator) {
|
|
102
|
+
if (Contents == null) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
for (const obj of Contents) {
|
|
106
|
+
if (obj.Key != null) {
|
|
107
|
+
objectKeys.push(obj.Key);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
102
110
|
}
|
|
103
|
-
return
|
|
104
|
-
.map(c => c.Key)
|
|
105
|
-
.filter(c => c != null);
|
|
111
|
+
return objectKeys.length > 0 ? objectKeys : null;
|
|
106
112
|
}
|
|
107
113
|
async getStorageEntry(key) {
|
|
108
114
|
const input = {
|
|
@@ -172,18 +178,23 @@ export class S3StorageProvider {
|
|
|
172
178
|
const command = new DeleteObjectCommand(input);
|
|
173
179
|
await this.sendS3ClientCommand(command);
|
|
174
180
|
}
|
|
175
|
-
async applyBatch(batch) {
|
|
181
|
+
async applyBatch(batch, options = {}) {
|
|
182
|
+
const { existingKeys } = options;
|
|
183
|
+
let toWrite = batch.storageProviderBatchEntries;
|
|
184
|
+
if (existingKeys != null) {
|
|
185
|
+
toWrite = entriesToUpload(toWrite, existingKeys);
|
|
186
|
+
}
|
|
176
187
|
console.log(`📤 Uploading entries to S3 storage.`);
|
|
177
188
|
// fastlyApiContext is non-null if useKvStore is true
|
|
178
|
-
await this.doConcurrentParallel(
|
|
189
|
+
await this.doConcurrentParallel(toWrite, async ({ filePath, metadataJson }, key) => {
|
|
179
190
|
// const fileStream = fs.createReadStream(filePath);
|
|
180
191
|
const fileData = fs.readFileSync(filePath);
|
|
181
192
|
await this.submitStorageEntry(key, filePath, fileData, metadataJson);
|
|
182
193
|
console.log(` 🌐 Submitted asset "${rootRelative(filePath)}" to S3 storage with key "${key}".`);
|
|
183
|
-
});
|
|
194
|
+
}, 12, true);
|
|
184
195
|
console.log(`✅ Uploaded entries to S3 storage.`);
|
|
185
196
|
}
|
|
186
|
-
async doConcurrentParallel(objects, fn, maxConcurrent = 12) {
|
|
197
|
+
async doConcurrentParallel(objects, fn, maxConcurrent = 12, throwOnError = false) {
|
|
187
198
|
await concurrentParallel(objects, fn, (err) => {
|
|
188
199
|
if (err instanceof S3ServiceException) {
|
|
189
200
|
return `S3 error [${err.name}] - ${err.message}`;
|
|
@@ -192,32 +203,11 @@ export class S3StorageProvider {
|
|
|
192
203
|
return 'transport';
|
|
193
204
|
}
|
|
194
205
|
return null;
|
|
195
|
-
}, maxConcurrent);
|
|
206
|
+
}, maxConcurrent, throwOnError);
|
|
196
207
|
}
|
|
197
208
|
calculateNumChunks(_size) {
|
|
198
209
|
return 1;
|
|
199
210
|
}
|
|
200
|
-
async getExistingAssetVariant(variantKey) {
|
|
201
|
-
let assetVariantMetadata = null;
|
|
202
|
-
await this.doConcurrentParallel([{ key: variantKey }], async (_, variantKey) => {
|
|
203
|
-
const entryInfo = await this.getStorageEntryInfo(variantKey);
|
|
204
|
-
if (entryInfo == null) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
const metadata = decodeAssetVariantMetadata(entryInfo.metadata);
|
|
208
|
-
if (metadata != null) {
|
|
209
|
-
if (metadata.numChunks !== undefined) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
assetVariantMetadata = {
|
|
213
|
-
contentEncoding: metadata.contentEncoding,
|
|
214
|
-
size: metadata.size,
|
|
215
|
-
hash: metadata.hash,
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
return assetVariantMetadata;
|
|
220
|
-
}
|
|
221
211
|
async purgeSurrogateKey(surrogateKey) {
|
|
222
212
|
if (this.fastlyServiceId == null) {
|
|
223
213
|
console.log('Fastly Service ID not set, skipping purge...');
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type AssetVariantMetadata } from '../../models/assets/index.js';
|
|
2
1
|
import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
|
|
3
2
|
export interface StorageEntry {
|
|
4
3
|
data?: ReadableStream<Uint8Array>;
|
|
@@ -11,21 +10,22 @@ export interface StorageProvider {
|
|
|
11
10
|
getStorageEntry(key: string): Promise<StorageEntry | null>;
|
|
12
11
|
submitStorageEntry(key: string, filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
13
12
|
deleteStorageEntry(key: string): Promise<void>;
|
|
14
|
-
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
13
|
+
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
15
14
|
doConcurrentParallel<TObject extends {
|
|
16
15
|
key: string;
|
|
17
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
16
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
18
17
|
calculateNumChunks(size: number): number;
|
|
19
|
-
getExistingAssetVariant(variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
20
18
|
purgeSurrogateKey(surrogateKey: string): Promise<void>;
|
|
21
19
|
}
|
|
22
20
|
export type StorageProviderBatchEntry = {
|
|
23
|
-
write: boolean;
|
|
24
21
|
size: number;
|
|
25
22
|
key: string;
|
|
26
23
|
filePath: string;
|
|
27
24
|
metadataJson?: Record<string, string>;
|
|
28
25
|
};
|
|
26
|
+
export type ApplyBatchOptions = {
|
|
27
|
+
existingKeys?: Set<string>;
|
|
28
|
+
};
|
|
29
29
|
export declare class StorageProviderBatch {
|
|
30
30
|
constructor();
|
|
31
31
|
storageProviderBatchEntries: StorageProviderBatchEntry[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,
|
|
1
|
+
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-types.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/content-types.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC3B,MAAM,+CAA+C,CAAC;
|
|
1
|
+
{"version":3,"file":"content-types.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/content-types.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC3B,MAAM,+CAA+C,CAAC;AAwCvD,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,cAAc,EAAE,oBAmD/D;AAED,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,cAAc,EAAE,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,qBAAqB,GAAG,IAAI,CAkBrI"}
|
|
@@ -18,8 +18,10 @@ const defaultContentTypes = [
|
|
|
18
18
|
{ test: /\.gif$/, contentType: 'image/gif', text: false },
|
|
19
19
|
{ test: /\.jp(e)?g$/, contentType: 'image/jpeg', text: false },
|
|
20
20
|
{ test: /\.ico$/, contentType: 'image/vnd.microsoft.icon', text: false },
|
|
21
|
-
{ test: /\.tif(f)?$/, contentType: 'image/
|
|
21
|
+
{ test: /\.tif(f)?$/, contentType: 'image/tiff', text: false },
|
|
22
22
|
{ test: /\.webp$/, contentType: 'image/webp', text: false },
|
|
23
|
+
{ test: /\.avif$/, contentType: 'image/avif', text: false },
|
|
24
|
+
{ test: /\.jxl$/, contentType: 'image/jxl', text: false },
|
|
23
25
|
{ test: /\.aac$/, contentType: 'audio/aac', text: false },
|
|
24
26
|
{ test: /\.mp3$/, contentType: 'audio/mpeg', text: false },
|
|
25
27
|
{ test: /\.avi$/, contentType: 'video/x-msvideo', text: false },
|
|
@@ -29,6 +31,7 @@ const defaultContentTypes = [
|
|
|
29
31
|
{ test: /\.pdf$/, contentType: 'application/pdf', text: false },
|
|
30
32
|
{ test: /\.tar$/, contentType: 'application/x-tar', text: false, precompressAsset: true, },
|
|
31
33
|
{ test: /\.zip$/, contentType: 'application/zip', text: false },
|
|
34
|
+
{ test: /\.wasm$/, contentType: 'application/wasm', text: false },
|
|
32
35
|
{ test: /\.eot$/, contentType: 'application/vnd.ms-fontobject', text: false },
|
|
33
36
|
{ test: /\.otf$/, contentType: 'font/otf', text: false },
|
|
34
37
|
{ test: /\.ttf$/, contentType: 'font/ttf', text: false },
|
|
@@ -2,4 +2,16 @@ import { StorageProviderBatchEntry } from '../storage/storage-provider.js';
|
|
|
2
2
|
export declare const KV_STORE_CHUNK_SIZE: number;
|
|
3
3
|
export declare function shouldRecreateChunks(chunksDir: string, numChunks: number, item: StorageProviderBatchEntry, chunkSize: number): boolean;
|
|
4
4
|
export declare function applyKVStoreEntriesChunks(kvStoreItemDescriptions: StorageProviderBatchEntry[], chunkSize: number): Promise<void>;
|
|
5
|
+
export declare const KV_BATCH_MAX_ITEMS = 256;
|
|
6
|
+
export declare const KV_BATCH_MAX_BYTES: number;
|
|
7
|
+
export type NdjsonBatch = {
|
|
8
|
+
key: string;
|
|
9
|
+
entries: StorageProviderBatchEntry[];
|
|
10
|
+
};
|
|
11
|
+
export declare function packNdjsonBatches(entries: StorageProviderBatchEntry[], maxItems?: number, maxBytes?: number): {
|
|
12
|
+
batches: NdjsonBatch[];
|
|
13
|
+
oversized: StorageProviderBatchEntry[];
|
|
14
|
+
};
|
|
15
|
+
export declare function ndjsonLineForBatchEntry(entry: StorageProviderBatchEntry): string;
|
|
16
|
+
export declare function entriesToUpload(entries: StorageProviderBatchEntry[], existingKeys: Set<string>): StorageProviderBatchEntry[];
|
|
5
17
|
//# sourceMappingURL=kv-store-items.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,eAAO,MAAM,mBAAmB,QAAqB,CAAC;AAEtD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,EAAE,SAAS,EAAE,MAAM,WAkC5H;AAED,wBAAsB,yBAAyB,CAAC,uBAAuB,EAAE,yBAAyB,EAAE,EAAE,SAAS,EAAE,MAAM,iBAoGtH"}
|
|
1
|
+
{"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,eAAO,MAAM,mBAAmB,QAAqB,CAAC;AAEtD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,EAAE,SAAS,EAAE,MAAM,WAkC5H;AAED,wBAAsB,yBAAyB,CAAC,uBAAuB,EAAE,yBAAyB,EAAE,EAAE,SAAS,EAAE,MAAM,iBAoGtH;AAED,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,kBAAkB,QAAoB,CAAC;AAEpD,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,yBAAyB,EAAE,CAAC;CACtC,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,yBAAyB,EAAE,EACpC,QAAQ,GAAE,MAA2B,EACrC,QAAQ,GAAE,MAA2B,GACpC;IAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAAC,SAAS,EAAE,yBAAyB,EAAE,CAAA;CAAE,CAuCpE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,yBAAyB,GAAG,MAAM,CAOhF;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,yBAAyB,EAAE,EACpC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,GACxB,yBAAyB,EAAE,CAE7B"}
|
|
@@ -114,3 +114,52 @@ export async function applyKVStoreEntriesChunks(kvStoreItemDescriptions, chunkSi
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
+
export const KV_BATCH_MAX_ITEMS = 256;
|
|
118
|
+
export const KV_BATCH_MAX_BYTES = 8 * 1_024 * 1_024;
|
|
119
|
+
export function packNdjsonBatches(entries, maxItems = KV_BATCH_MAX_ITEMS, maxBytes = KV_BATCH_MAX_BYTES) {
|
|
120
|
+
const lineBytesFor = (entry) => {
|
|
121
|
+
const envelope = JSON.stringify({
|
|
122
|
+
key: entry.key,
|
|
123
|
+
value: '',
|
|
124
|
+
...(entry.metadataJson != null ? { metadata: JSON.stringify(entry.metadataJson) } : {}),
|
|
125
|
+
});
|
|
126
|
+
return envelope.length + Math.ceil(entry.size / 3) * 4;
|
|
127
|
+
};
|
|
128
|
+
const oversized = [];
|
|
129
|
+
const groups = [];
|
|
130
|
+
let current = [];
|
|
131
|
+
let currentBytes = 0;
|
|
132
|
+
for (const entry of entries) {
|
|
133
|
+
const lineBytes = lineBytesFor(entry);
|
|
134
|
+
if (lineBytes > maxBytes) {
|
|
135
|
+
oversized.push(entry);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (current.length > 0 && (current.length >= maxItems || currentBytes + lineBytes > maxBytes)) {
|
|
139
|
+
groups.push(current);
|
|
140
|
+
current = [];
|
|
141
|
+
currentBytes = 0;
|
|
142
|
+
}
|
|
143
|
+
current.push(entry);
|
|
144
|
+
currentBytes += lineBytes;
|
|
145
|
+
}
|
|
146
|
+
if (current.length > 0) {
|
|
147
|
+
groups.push(current);
|
|
148
|
+
}
|
|
149
|
+
const batches = groups.map((groupEntries, i) => ({
|
|
150
|
+
key: `batch-${i}`,
|
|
151
|
+
entries: groupEntries,
|
|
152
|
+
}));
|
|
153
|
+
return { batches, oversized };
|
|
154
|
+
}
|
|
155
|
+
export function ndjsonLineForBatchEntry(entry) {
|
|
156
|
+
const value = fs.readFileSync(entry.filePath).toString('base64');
|
|
157
|
+
return JSON.stringify({
|
|
158
|
+
key: entry.key,
|
|
159
|
+
value,
|
|
160
|
+
...(entry.metadataJson != null ? { metadata: JSON.stringify(entry.metadataJson) } : {}),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
export function entriesToUpload(entries, existingKeys) {
|
|
164
|
+
return entries.filter((entry) => !existingKeys.has(entry.key));
|
|
165
|
+
}
|
|
@@ -17,5 +17,11 @@ export declare function getKvStoreEntryInfo(fastlyApiContext: FastlyApiContext,
|
|
|
17
17
|
export declare function getKvStoreEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, metadataOnly?: boolean): Promise<KvStoreEntryInfo | null>;
|
|
18
18
|
export declare function kvStoreSubmitEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, data: ReadableStream<Uint8Array> | Uint8Array | string, metadata: string | undefined): Promise<void>;
|
|
19
19
|
export declare function kvStoreDeleteEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<void>;
|
|
20
|
+
export type KvStoreBatchError = {
|
|
21
|
+
key: string;
|
|
22
|
+
code?: string;
|
|
23
|
+
reason?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function kvStoreSubmitBatch(fastlyApiContext: FastlyApiContext, kvStoreName: string, ndjsonLines: string[]): Promise<KvStoreBatchError[]>;
|
|
20
26
|
export {};
|
|
21
27
|
//# sourceMappingURL=kv-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,KAAK,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"kv-store.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,KAAK,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAGlF,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAUF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AASF,wBAAsB,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,mCAkB9E;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,mBAKhG;AAqCD,wBAAsB,eAAe,CAAC,gBAAgB,EAAE,gBAAgB,0BAcvE;AAED,eAAO,MAAM,eAAe,qBAjDgB,gBAAgB,iBAAiB,MAAM,sEA4DlF,CAAC;AAEF,wBAAsB,cAAc,CAClC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,4BAchB;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAIhJ;AAED,wBAAsB,eAAe,CACnC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,OAAO,GACrB,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA6BlC;AAGD,wBAAsB,kBAAkB,CACtC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,EACtD,QAAQ,EAAE,MAAM,GAAG,SAAS,iBAoB7B;AAED,wBAAsB,kBAAkB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,iBAa5G;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAKF,wBAAsB,kBAAkB,CACtC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAwC9B"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import { callFastlyApi, FetchError } from './api-token.js';
|
|
6
|
+
import { makeRetryable } from './retryable.js';
|
|
6
7
|
const cache = new WeakMap();
|
|
7
8
|
export async function getKVStoreIdForNameMap(fastlyApiContext) {
|
|
8
9
|
const cacheEntry = cache.get(fastlyApiContext);
|
|
@@ -59,9 +60,12 @@ export async function getKVStoreInfos(fastlyApiContext) {
|
|
|
59
60
|
return kvStoreInfos;
|
|
60
61
|
}
|
|
61
62
|
export const _getKVStoreKeys = createArrayGetter()((kvStoreId, prefix) => {
|
|
62
|
-
|
|
63
|
+
// Read from the primary data source. An eventual read can show a key
|
|
64
|
+
// that was deleted a short time ago. Then publish-content does not upload
|
|
65
|
+
// an item that the new index needs.
|
|
66
|
+
let endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys?consistency=strong`;
|
|
63
67
|
if (prefix != null) {
|
|
64
|
-
endpoint += '
|
|
68
|
+
endpoint += '&prefix=' + encodeURIComponent(prefix);
|
|
65
69
|
}
|
|
66
70
|
return endpoint;
|
|
67
71
|
});
|
|
@@ -126,3 +130,36 @@ export async function kvStoreDeleteEntry(fastlyApiContext, kvStoreName, key) {
|
|
|
126
130
|
method: 'DELETE',
|
|
127
131
|
});
|
|
128
132
|
}
|
|
133
|
+
// Returns the items that the KV Store reports as failed. The caller can
|
|
134
|
+
// submit only these items again. Throws if the response does not identify
|
|
135
|
+
// the failed items.
|
|
136
|
+
export async function kvStoreSubmitBatch(fastlyApiContext, kvStoreName, ndjsonLines) {
|
|
137
|
+
const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
|
|
138
|
+
if (kvStoreId == null) {
|
|
139
|
+
throw new Error(`KV Store '${kvStoreName}' not found.`);
|
|
140
|
+
}
|
|
141
|
+
const response = await callFastlyApi(fastlyApiContext, `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/batch`, `Submitting batch of ${ndjsonLines.length} item(s) to KV Store`, null, {
|
|
142
|
+
method: 'PUT',
|
|
143
|
+
headers: { 'Content-Type': 'application/x-ndjson' },
|
|
144
|
+
body: ndjsonLines.join('\n'),
|
|
145
|
+
});
|
|
146
|
+
// A 207 response has the body
|
|
147
|
+
// {"title":"some inserts failed","errors":[{"key":"...","code":"...","reason":"..."}]}
|
|
148
|
+
// A 200 response has the body {"title":"success","errors":[]}.
|
|
149
|
+
// Read the body in all cases, so that the connection can be used again.
|
|
150
|
+
const detail = await response.text().catch(() => '');
|
|
151
|
+
let errors;
|
|
152
|
+
try {
|
|
153
|
+
errors = JSON.parse(detail)?.errors;
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
errors = undefined;
|
|
157
|
+
}
|
|
158
|
+
if (Array.isArray(errors) && errors.every(e => typeof e?.key === 'string')) {
|
|
159
|
+
return errors.map(e => ({ key: e.key, code: e.code, reason: e.reason }));
|
|
160
|
+
}
|
|
161
|
+
if (response.status === 207) {
|
|
162
|
+
throw makeRetryable(new FetchError(`Batch upload partially failed (207): ${detail.slice(0, 300)}`, 207));
|
|
163
|
+
}
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
@@ -10,6 +10,7 @@ type RetryWithBackoffOptions = {
|
|
|
10
10
|
export declare function attemptWithRetries<TResult>(fn: () => Promise<TResult>, options?: RetryWithBackoffOptions): Promise<TResult>;
|
|
11
11
|
export declare function concurrentParallel<TObject extends {
|
|
12
12
|
key: string;
|
|
13
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, buildStatusMessage: (err: unknown) => (string | null), maxConcurrent?: number): Promise<void>;
|
|
13
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, buildStatusMessage: (err: unknown) => (string | null), maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
14
|
+
export declare function concurrentMap<TItem, TResult>(items: TItem[], fn: (item: TItem, index: number) => Promise<TResult>, maxConcurrent?: number): Promise<TResult[]>;
|
|
14
15
|
export {};
|
|
15
16
|
//# sourceMappingURL=retryable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryable.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/retryable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retryable.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/retryable.ts"],"names":[],"mappings":"AAUA,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,SAGzC;AACD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,OAK9C;AAED,KAAK,uBAAuB,GAAG;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAClE,CAAC;AACF,wBAAsB,kBAAkB,CAAC,OAAO,EAC9C,EAAE,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC1B,OAAO,GAAE,uBAA4B,oBAsCtC;AAED,wBAAsB,kBAAkB,CAAC,OAAO,SAAS;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EACtE,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,kBAAkB,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,EACrD,aAAa,GAAE,MAAW,EAC1B,YAAY,GAAE,OAAe,iBAgD9B;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,OAAO,EAChD,KAAK,EAAE,KAAK,EAAE,EACd,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EAEpD,aAAa,GAAE,MAA6C,GAC3D,OAAO,CAAC,OAAO,EAAE,CAAC,CA4BpB"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
+
import { availableParallelism } from 'node:os';
|
|
5
6
|
let _globalBackoffUntil = 0;
|
|
6
7
|
const retryableSymbol = Symbol();
|
|
7
8
|
export function makeRetryable(error) {
|
|
@@ -41,8 +42,9 @@ export async function attemptWithRetries(fn, options = {}) {
|
|
|
41
42
|
}
|
|
42
43
|
return result;
|
|
43
44
|
}
|
|
44
|
-
export async function concurrentParallel(objects, fn, buildStatusMessage, maxConcurrent = 12) {
|
|
45
|
+
export async function concurrentParallel(objects, fn, buildStatusMessage, maxConcurrent = 12, throwOnError = false) {
|
|
45
46
|
let index = 0; // Shared among workers
|
|
47
|
+
const failures = [];
|
|
46
48
|
async function worker() {
|
|
47
49
|
while (index < objects.length) {
|
|
48
50
|
const currentIndex = index;
|
|
@@ -68,9 +70,40 @@ export async function concurrentParallel(objects, fn, buildStatusMessage, maxCon
|
|
|
68
70
|
const e = err instanceof Error ? err : new Error(String(err));
|
|
69
71
|
console.error(` ❌ Failed: ${key} → ${e.message}`);
|
|
70
72
|
console.error(e.stack);
|
|
73
|
+
failures.push(key);
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
const workers = Array.from({ length: maxConcurrent }, () => worker());
|
|
75
78
|
await Promise.all(workers);
|
|
79
|
+
if (throwOnError && failures.length > 0) {
|
|
80
|
+
const shown = failures.slice(0, 10).join(', ');
|
|
81
|
+
const more = failures.length > 10 ? `, and ${failures.length - 10} more` : '';
|
|
82
|
+
throw new Error(`${failures.length} of ${objects.length} operation(s) failed: ${shown}${more}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export async function concurrentMap(items, fn,
|
|
86
|
+
// Each call can keep files open, so do not use too many at a time.
|
|
87
|
+
maxConcurrent = Math.min(availableParallelism(), 16)) {
|
|
88
|
+
const results = new Array(items.length);
|
|
89
|
+
let index = 0;
|
|
90
|
+
let failed = false;
|
|
91
|
+
async function worker() {
|
|
92
|
+
// If one item fails, do not start more items.
|
|
93
|
+
while (!failed && index < items.length) {
|
|
94
|
+
const currentIndex = index;
|
|
95
|
+
index = index + 1;
|
|
96
|
+
try {
|
|
97
|
+
results[currentIndex] = await fn(items[currentIndex], currentIndex);
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
failed = true;
|
|
101
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
102
|
+
throw Object.assign(new Error(`Failed to process '${String(items[currentIndex])}': ${message}`), { cause: err });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const workers = Array.from({ length: Math.min(maxConcurrent, items.length) }, () => worker());
|
|
107
|
+
await Promise.all(workers);
|
|
108
|
+
return results;
|
|
76
109
|
}
|
|
@@ -20,7 +20,7 @@ export function decodeAssetVariantMetadata(obj) {
|
|
|
20
20
|
if (hash == null) {
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
|
-
const numChunks =
|
|
23
|
+
const numChunks = parseInt(getMetadataFieldValue(obj, 'numChunks'), 10);
|
|
24
24
|
const assetVariantMetadata = {
|
|
25
25
|
size,
|
|
26
26
|
hash,
|
|
@@ -20,7 +20,7 @@ export function decodeAssetVariantMetadata(obj) {
|
|
|
20
20
|
if (hash == null) {
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
|
-
const numChunks =
|
|
23
|
+
const numChunks = parseInt(getMetadataFieldValue(obj, 'numChunks'), 10);
|
|
24
24
|
const assetVariantMetadata = {
|
|
25
25
|
size,
|
|
26
26
|
hash,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastly/compute-js-static-publish",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "8.0.0-beta.
|
|
4
|
+
"version": "8.0.0-beta.9",
|
|
5
5
|
"description": "Static Publisher for Fastly Compute JavaScript",
|
|
6
6
|
"main": "build/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"homepage": "https://github.com/fastly/compute-js-static-publish#readme",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@aws-sdk/client-s3": "3.888.0",
|
|
44
|
-
"@fastly/cli": "^
|
|
44
|
+
"@fastly/cli": "^16.0.0",
|
|
45
45
|
"command-line-args": "^5.2.1",
|
|
46
46
|
"glob-to-regexp": "^0.4.1",
|
|
47
47
|
"toml": "^3.0.0"
|