@fastly/compute-js-static-publish 8.0.1 → 8.0.3-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +557 -0
- package/DOCUMENTATION.md +59 -38
- package/MIGRATING.md +128 -0
- package/README.md +3 -3
- package/README.short.md +3 -3
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +27 -0
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +43 -4
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +43 -14
- package/build/cli/cli/commands/scaffold/index.js +12 -13
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +3 -2
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-local-provider.js +6 -15
- package/build/cli/cli/storage/kv-store-provider.d.ts +3 -2
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +11 -2
- package/build/cli/cli/storage/s3-storage-provider.d.ts +3 -2
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +6 -1
- package/build/cli/cli/storage/storage-provider.d.ts +6 -1
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/storage-provider.js +48 -0
- package/build/cli/cli/util/kv-store-items.d.ts +1 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-items.js +16 -40
- package/build/cli/cli/util/kv-store.d.ts +1 -1
- package/build/cli/cli/util/kv-store.d.ts.map +1 -1
- package/build/cli/cli/util/s3.d.ts +10 -4
- package/build/cli/cli/util/s3.d.ts.map +1 -1
- package/build/cli/cli/util/s3.js +13 -35
- package/build/cli/models/index-parts/index.d.ts +20 -0
- package/build/cli/models/index-parts/index.d.ts.map +1 -0
- package/build/cli/models/index-parts/index.js +76 -0
- package/build/cli/models/server/index.d.ts +2 -0
- package/build/cli/models/server/index.d.ts.map +1 -1
- package/build/cli/models/server/index.js +7 -1
- package/build/server/models/index-parts/index.d.ts +20 -0
- package/build/server/models/index-parts/index.d.ts.map +1 -0
- package/build/server/models/index-parts/index.js +76 -0
- package/build/server/models/server/index.d.ts +2 -0
- package/build/server/models/server/index.d.ts.map +1 -1
- package/build/server/models/server/index.js +7 -1
- package/build/server/server/index.d.ts +1 -1
- package/build/server/server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/accept-html.d.ts +2 -0
- package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
- package/build/server/server/publisher-server/accept-html.js +50 -0
- package/build/server/server/publisher-server/index.d.ts +5 -0
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +103 -33
- package/build/server/server/publisher-server/response-cache.d.ts +3 -0
- package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
- package/build/server/server/publisher-server/response-cache.js +24 -1
- package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
- package/build/server/server/storage/kv-store-provider.js +1 -0
- package/build/server/server/storage/s3-storage-provider.d.ts +2 -2
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.js +5 -2
- package/build/server/server/storage/storage-provider.d.ts +12 -1
- package/build/server/server/storage/storage-provider.d.ts.map +1 -1
- package/package.json +4 -2
|
@@ -9,6 +9,7 @@ import { calcExpirationTime } from '../../../../models/time/index.js';
|
|
|
9
9
|
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
10
10
|
import { parseCommandLine } from '../../../util/args.js';
|
|
11
11
|
import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
|
|
12
|
+
import { loadPurgeTarget, purgeCollection } from '../../../util/purge.js';
|
|
12
13
|
function help() {
|
|
13
14
|
console.log(`\
|
|
14
15
|
|
|
@@ -21,6 +22,9 @@ Usage:
|
|
|
21
22
|
Description:
|
|
22
23
|
Copies an existing collection (content + config) to a new collection name.
|
|
23
24
|
|
|
25
|
+
If a Service ID is found, the tool then purges the cached responses of the target
|
|
26
|
+
collection from that service.
|
|
27
|
+
|
|
24
28
|
Required:
|
|
25
29
|
--collection-name=<name> The name of the collection to promote
|
|
26
30
|
--to=<name> The name of the new (target) collection to create or overwrite
|
|
@@ -45,10 +49,21 @@ KV Store Options:
|
|
|
45
49
|
with the local development environment.
|
|
46
50
|
KV Store mode only. In S3 mode, --local is an error.
|
|
47
51
|
|
|
48
|
-
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
52
|
+
--fastly-api-token=<token> Fastly API token for KV Store or cache access.
|
|
49
53
|
If not set, the tool uses the FASTLY_API_TOKEN
|
|
50
54
|
environment variable.
|
|
51
55
|
|
|
56
|
+
Purge Options:
|
|
57
|
+
--fastly-service-id=<id> Fastly Service ID to purge after promoting (not with --local).
|
|
58
|
+
If not set, the tool will check:
|
|
59
|
+
1. FASTLY_SERVICE_ID environment variable
|
|
60
|
+
2. service_id in fastly.toml
|
|
61
|
+
If none is found, the purge is skipped.
|
|
62
|
+
|
|
63
|
+
--purge-environment=<env> Environment to purge: production, staging, or a
|
|
64
|
+
comma-separated list of both. Can be repeated.
|
|
65
|
+
Default: production
|
|
66
|
+
|
|
52
67
|
S3 Storage Options (BETA):
|
|
53
68
|
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
54
69
|
--s3-secret-access-key=<key> interface with S3 or compatible storage.
|
|
@@ -69,6 +84,8 @@ export async function action(actionArgs) {
|
|
|
69
84
|
{ name: 'expires-never', type: Boolean },
|
|
70
85
|
{ name: 'local', type: Boolean },
|
|
71
86
|
{ name: 'fastly-api-token', type: String, },
|
|
87
|
+
{ name: 'fastly-service-id', type: String, },
|
|
88
|
+
{ name: 'purge-environment', type: String, multiple: true, },
|
|
72
89
|
{ name: 's3-access-key-id', type: String, },
|
|
73
90
|
{ name: 's3-secret-access-key', type: String, },
|
|
74
91
|
];
|
|
@@ -82,7 +99,7 @@ export async function action(actionArgs) {
|
|
|
82
99
|
help();
|
|
83
100
|
return;
|
|
84
101
|
}
|
|
85
|
-
const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
102
|
+
const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['fastly-service-id']: fastlyServiceId, ['purge-environment']: purgeEnvironmentValues, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
86
103
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
87
104
|
// in other words, the directory that contains `fastly.toml`.
|
|
88
105
|
const computeAppDir = path.resolve();
|
|
@@ -148,6 +165,22 @@ export async function action(actionArgs) {
|
|
|
148
165
|
}
|
|
149
166
|
const sourceCollectionName = collectionNameValue;
|
|
150
167
|
console.log(`✔️ Collection to copy: ${sourceCollectionName}`);
|
|
168
|
+
// Purge target: checked now, so that a missing API token fails before anything is written.
|
|
169
|
+
let purgeTarget;
|
|
170
|
+
try {
|
|
171
|
+
purgeTarget = loadPurgeTarget({
|
|
172
|
+
localMode: localMode ?? false,
|
|
173
|
+
computeAppDir,
|
|
174
|
+
fastlyServiceId,
|
|
175
|
+
fastlyApiToken,
|
|
176
|
+
purgeEnvironments: purgeEnvironmentValues,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
console.error(String(err));
|
|
181
|
+
process.exitCode = 1;
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
151
184
|
const targetCollectionName = toCollectionNameValue;
|
|
152
185
|
console.log(`✔️ Collection to promote to: ${targetCollectionName}`);
|
|
153
186
|
if (expirationTime === undefined) {
|
|
@@ -191,11 +224,17 @@ export async function action(actionArgs) {
|
|
|
191
224
|
console.log(`Uploading to storage: '${targetCollectionName}'`);
|
|
192
225
|
const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
|
|
193
226
|
fs.mkdirSync(storageContentDir, { recursive: true });
|
|
194
|
-
|
|
227
|
+
// The files have the name of the target collection, as in publish-content. In
|
|
228
|
+
// --local mode, kvstore.json refers to them, so the target must not share a
|
|
229
|
+
// file with the source.
|
|
230
|
+
const indexFileName = `index_${targetCollectionName}.json`;
|
|
195
231
|
const indexFilePath = path.resolve(storageContentDir, indexFileName);
|
|
196
232
|
await storageProvider.submitStorageEntry(targetCollectionIndexKey, indexFilePath, indexEntryInfo.data, encodeIndexMetadata(indexMetadata));
|
|
197
|
-
const settingsFileName = `settings_${
|
|
233
|
+
const settingsFileName = `settings_${targetCollectionName}.json`;
|
|
198
234
|
const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
|
|
199
235
|
await storageProvider.submitStorageEntry(targetCollectionSettingsKey, settingsFilePath, settingsEntryInfo.data);
|
|
236
|
+
if (purgeTarget != null) {
|
|
237
|
+
await purgeCollection(purgeTarget, publishId, targetCollectionName);
|
|
238
|
+
}
|
|
200
239
|
console.log("✅ Completed.");
|
|
201
240
|
}
|
|
@@ -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":"AAuIA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA4lBhD"}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
+
import * as crypto from 'node:crypto';
|
|
5
6
|
import * as fs from 'node:fs';
|
|
6
7
|
import * as path from 'node:path';
|
|
8
|
+
import { chooseIndexPartCount, getIndexPartKey, getIndexPartsSetPrefix, splitAssetEntryMap, } from '../../../models/index-parts/index.js';
|
|
7
9
|
import { encodeIndexMetadata } from '../../../models/server/index.js';
|
|
8
10
|
import { calcExpirationTime } from '../../../models/time/index.js';
|
|
9
11
|
import { parseCommandLine } from '../../util/args.js';
|
|
@@ -15,7 +17,7 @@ import { ensureVariantFileExists, OncePerKey } from '../../util/variants.js';
|
|
|
15
17
|
import { concurrentMap } from '../../util/retryable.js';
|
|
16
18
|
import { ProgressLog } from '../../util/progress.js';
|
|
17
19
|
import { loadPurgeTarget, purgeCollection } from '../../util/purge.js';
|
|
18
|
-
import { getStorageKeysByHexPrefix, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
|
|
20
|
+
import { getStorageKeysByHexPrefix, isVariantInStorage, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
|
|
19
21
|
// Storage key format:
|
|
20
22
|
// <publishId>_index_<preview_id>.json
|
|
21
23
|
// <publishId>_settings_<preview_id>.json
|
|
@@ -319,6 +321,8 @@ export async function action(actionArgs) {
|
|
|
319
321
|
// #### Keys that are already in storage
|
|
320
322
|
// The key of a file is the hash of its content. If the key exists, storage
|
|
321
323
|
// already has the same content. Thus we do not compress, hash, or upload it again.
|
|
324
|
+
// For a file in more than one chunk, isVariantInStorage() also compares the
|
|
325
|
+
// stored size of each chunk.
|
|
322
326
|
// In local mode, a key can refer to a working file that was deleted, so we do not list.
|
|
323
327
|
// All the keys that the scan looks for start with `<publishId>_files_sha256_` and a hex
|
|
324
328
|
// hash, so we list them in 16 parts at the same time.
|
|
@@ -330,17 +334,6 @@ export async function action(actionArgs) {
|
|
|
330
334
|
console.log(`✅ Found ${existingKeys.size} key(s) in ${((Date.now() - listStart) / 1000).toFixed(1)} s.`);
|
|
331
335
|
}
|
|
332
336
|
let existingVariantCount = 0;
|
|
333
|
-
function isVariantInStorage(variantKey, numChunks) {
|
|
334
|
-
if (existingKeys == null || !existingKeys.has(variantKey)) {
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
|
-
for (let chunkIndex = 1; chunkIndex < numChunks; chunkIndex++) {
|
|
338
|
-
if (!existingKeys.has(`${variantKey}_${chunkIndex}`)) {
|
|
339
|
-
return false;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
337
|
// #### Iterate files
|
|
345
338
|
const scanProgress = new ProgressLog('Files scanned', verbose);
|
|
346
339
|
const fileResults = await concurrentMap(files, async (file) => {
|
|
@@ -392,7 +385,8 @@ export async function action(actionArgs) {
|
|
|
392
385
|
// Returns true if the index keeps the variant.
|
|
393
386
|
async function prepareVariant(variant, variantKey, variantFilePath) {
|
|
394
387
|
if ((variant === 'original' || baseNumChunks === 1) &&
|
|
395
|
-
|
|
388
|
+
existingKeys != null &&
|
|
389
|
+
await isVariantInStorage(storageProvider, existingKeys, variantKey, baseSize, variant === 'original' ? baseNumChunks : 1)) {
|
|
396
390
|
if (verbose) {
|
|
397
391
|
console.log(` ・ Asset found in storage with key "${variantKey}".`);
|
|
398
392
|
}
|
|
@@ -485,16 +479,51 @@ export async function action(actionArgs) {
|
|
|
485
479
|
console.log(` | ${batch.storageProviderBatchEntries.length} variant(s) to upload.`);
|
|
486
480
|
}
|
|
487
481
|
await storageProvider.applyBatch(batch, { existingKeys, verbose });
|
|
482
|
+
const indexText = JSON.stringify(assetsIndex);
|
|
483
|
+
// #### INDEX PARTS
|
|
484
|
+
// These are saved before the index, so that the index never points to parts
|
|
485
|
+
// that are not in storage yet.
|
|
486
|
+
let indexParts;
|
|
487
|
+
const indexPartCount = chooseIndexPartCount(Object.keys(assetsIndex).length);
|
|
488
|
+
if (indexPartCount > 0) {
|
|
489
|
+
indexParts = {
|
|
490
|
+
count: indexPartCount,
|
|
491
|
+
hash: crypto.createHash('sha256').update(indexText).digest('hex'),
|
|
492
|
+
};
|
|
493
|
+
console.log(`🧩 Saving index parts...`);
|
|
494
|
+
const parts = splitAssetEntryMap(assetsIndex, indexPartCount);
|
|
495
|
+
const partItems = parts.map((part, partNumber) => ({
|
|
496
|
+
key: getIndexPartKey(publishId, indexParts, partNumber),
|
|
497
|
+
partNumber,
|
|
498
|
+
part,
|
|
499
|
+
}));
|
|
500
|
+
// Parts of the same index are already in storage if this content was
|
|
501
|
+
// published before.
|
|
502
|
+
let existingPartKeys = null;
|
|
503
|
+
if (!overwriteExisting && !localMode) {
|
|
504
|
+
const keys = await storageProvider.getStorageKeys(getIndexPartsSetPrefix(publishId, indexParts));
|
|
505
|
+
existingPartKeys = keys != null ? new Set(keys) : null;
|
|
506
|
+
}
|
|
507
|
+
const partItemsToWrite = partItems.filter(item => !existingPartKeys?.has(item.key));
|
|
508
|
+
await storageProvider.doConcurrentParallel(partItemsToWrite, async ({ partNumber, part }, key) => {
|
|
509
|
+
const partFilePath = path.resolve(storageContentDir, `index_parts_${indexParts.hash}_${indexPartCount}_${partNumber}.json`);
|
|
510
|
+
await storageProvider.submitStorageEntry(key, partFilePath, JSON.stringify(part));
|
|
511
|
+
}, undefined,
|
|
512
|
+
// The index must not point to parts that could not be saved.
|
|
513
|
+
true);
|
|
514
|
+
console.log(`✅ ${indexPartCount} index parts: ${partItemsToWrite.length} saved, ${indexPartCount - partItemsToWrite.length} already in storage.`);
|
|
515
|
+
}
|
|
488
516
|
// #### INDEX FILE
|
|
489
517
|
console.log(`🗂️ Saving Index...`);
|
|
490
518
|
const indexFileKey = `${publishId}_index_${collectionName}`;
|
|
491
519
|
const indexMetadata = {
|
|
492
520
|
publishedTime: Math.floor(Date.now() / 1000),
|
|
493
521
|
expirationTime: expirationTime ?? undefined,
|
|
522
|
+
indexParts,
|
|
494
523
|
};
|
|
495
524
|
const indexFileName = `index_${collectionName}.json`;
|
|
496
525
|
const indexFilePath = path.resolve(storageContentDir, indexFileName);
|
|
497
|
-
await storageProvider.submitStorageEntry(indexFileKey, indexFilePath,
|
|
526
|
+
await storageProvider.submitStorageEntry(indexFileKey, indexFilePath, indexText, encodeIndexMetadata(indexMetadata));
|
|
498
527
|
console.log(`✅ Index has been saved.`);
|
|
499
528
|
// #### SERVER SETTINGS
|
|
500
529
|
// These are saved to storage
|
|
@@ -590,19 +590,16 @@ export async function action(actionArgs) {
|
|
|
590
590
|
}
|
|
591
591
|
let s3Endpoint = options.s3Endpoint;
|
|
592
592
|
if (s3Endpoint == null || s3Endpoint === '') {
|
|
593
|
-
//
|
|
594
|
-
//
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
if (s3Endpoint) {
|
|
599
|
-
console.log('✅ S3 endpoint resolved:', s3Endpoint);
|
|
600
|
-
}
|
|
601
|
-
else {
|
|
602
|
-
console.error(`❌ Unable to resolve S3 endpoint from region '${s3Region}' and bucket '${s3Bucket}.`);
|
|
593
|
+
// Without an endpoint, the bucket is on AWS. The app needs its host name
|
|
594
|
+
// for the backend in the Compute service.
|
|
595
|
+
const hostname = findHostnameForAwsS3RegionAndBucket(s3Region, s3Bucket);
|
|
596
|
+
if (hostname == null) {
|
|
597
|
+
console.error(`❌ The bucket name '${s3Bucket}' has a dot, so it cannot be a host name of AWS S3 under HTTPS. Set --s3-endpoint, for example --s3-endpoint=https://s3.${s3Region}.amazonaws.com. Then the bucket is in the path of the URL.`);
|
|
603
598
|
process.exitCode = 1;
|
|
604
599
|
return;
|
|
605
600
|
}
|
|
601
|
+
s3Endpoint = hostname;
|
|
602
|
+
console.log('✅ S3 endpoint resolved:', s3Endpoint);
|
|
606
603
|
s3EndpointUrl = new URL(`https://${s3Endpoint}/`);
|
|
607
604
|
s3EndpointGenerated = true;
|
|
608
605
|
}
|
|
@@ -903,14 +900,16 @@ async function handleRequest(event) {
|
|
|
903
900
|
|
|
904
901
|
const request = event.request;
|
|
905
902
|
|
|
903
|
+
// Do custom things here!
|
|
904
|
+
// Handle API requests, serve non-static responses, etc.
|
|
905
|
+
// serveRequest() serves the 404 page or the SPA file for each path that
|
|
906
|
+
// has no file, so code after it does not run for those requests.
|
|
907
|
+
|
|
906
908
|
const response = await publisherServer.serveRequest(request);
|
|
907
909
|
if (response != null) {
|
|
908
910
|
return response;
|
|
909
911
|
}
|
|
910
912
|
|
|
911
|
-
// Do custom things here!
|
|
912
|
-
// Handle API requests, serve non-static responses, etc.
|
|
913
|
-
|
|
914
913
|
return new Response('Not found', { status: 404 });
|
|
915
914
|
}
|
|
916
915
|
`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type ApplyBatchOptions } from './storage-provider.js';
|
|
1
|
+
import { type StorageEntry, type StorageEntryData, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type ApplyBatchOptions } from './storage-provider.js';
|
|
2
2
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
3
3
|
export declare class KvStoreLocalProvider implements StorageProvider {
|
|
4
4
|
constructor(storeFile: string, computeAppDir: string);
|
|
@@ -7,12 +7,13 @@ export declare class KvStoreLocalProvider implements StorageProvider {
|
|
|
7
7
|
getStorageKeys(prefix?: string): Promise<string[] | null>;
|
|
8
8
|
getStorageEntry(key: string): Promise<StorageEntry | null>;
|
|
9
9
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
10
|
-
submitStorageEntry(key: string, filePath: string, data:
|
|
10
|
+
submitStorageEntry(key: string, filePath: string, data: StorageEntryData, metadata?: Record<string, string>): Promise<void>;
|
|
11
11
|
deleteStorageEntry(key: string): Promise<void>;
|
|
12
12
|
applyBatch(batch: StorageProviderBatch, _options?: ApplyBatchOptions): Promise<void>;
|
|
13
13
|
doConcurrentParallel<TObject extends {
|
|
14
14
|
key: string;
|
|
15
15
|
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
16
16
|
calculateNumChunks(size: number): number;
|
|
17
|
+
calculateChunkSizes(size: number): number[];
|
|
17
18
|
}
|
|
18
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":"AA2BA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EAEvB,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,gBAAgB,EACtB,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;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;IAIxC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;CAG5C"}
|
|
@@ -6,9 +6,10 @@ import fs from 'node:fs';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { isKvStoreConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
8
8
|
import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
|
|
9
|
-
import { applyKVStoreEntriesChunks, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
9
|
+
import { applyKVStoreEntriesChunks, chunkSizes, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
10
10
|
import { getLocalKvStoreEntry, getLocalKVStoreKeys, localKvStoreDeleteEntry, localKvStoreSubmitEntry, writeKVStoreEntriesForLocal, } from '../util/kv-store-local-server.js';
|
|
11
11
|
import { concurrentParallel } from '../util/retryable.js';
|
|
12
|
+
import { storageEntryDataToBytes, } from './storage-provider.js';
|
|
12
13
|
import { kvStoreEntryToStorageEntry, } from './kv-store-provider.js';
|
|
13
14
|
export const buildStoreProvider = (config, context) => {
|
|
14
15
|
if (isKvStoreConfigRc(config) && context.localMode) {
|
|
@@ -45,20 +46,7 @@ export class KvStoreLocalProvider {
|
|
|
45
46
|
return kvStoreEntryToStorageEntry(kvStoreEntry);
|
|
46
47
|
}
|
|
47
48
|
async submitStorageEntry(key, filePath, data, metadata) {
|
|
48
|
-
|
|
49
|
-
if (data == null) {
|
|
50
|
-
fileData = new Uint8Array(0);
|
|
51
|
-
}
|
|
52
|
-
else if (data instanceof ReadableStream) {
|
|
53
|
-
fileData = Buffer.from(await new Response(data).arrayBuffer());
|
|
54
|
-
}
|
|
55
|
-
else if (typeof data === 'string') {
|
|
56
|
-
fileData = new TextEncoder().encode(data);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
fileData = data;
|
|
60
|
-
}
|
|
61
|
-
fs.writeFileSync(filePath, fileData);
|
|
49
|
+
fs.writeFileSync(filePath, await storageEntryDataToBytes(data));
|
|
62
50
|
await localKvStoreSubmitEntry(this.storeFile, key, path.relative(this.computeAppDir, filePath), metadata != null ? JSON.stringify(metadata) : undefined);
|
|
63
51
|
}
|
|
64
52
|
async deleteStorageEntry(key) {
|
|
@@ -78,4 +66,7 @@ export class KvStoreLocalProvider {
|
|
|
78
66
|
calculateNumChunks(size) {
|
|
79
67
|
return Math.ceil(size / KV_STORE_CHUNK_SIZE);
|
|
80
68
|
}
|
|
69
|
+
calculateChunkSizes(size) {
|
|
70
|
+
return chunkSizes(size, KV_STORE_CHUNK_SIZE);
|
|
71
|
+
}
|
|
81
72
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FastlyApiContext } from '../util/api-token.js';
|
|
2
2
|
import { type KvStoreEntryInfo } from '../util/kv-store.js';
|
|
3
|
-
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type StorageProviderBatchEntry, type ApplyBatchOptions } from './storage-provider.js';
|
|
3
|
+
import { type StorageEntry, type StorageEntryData, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type StorageProviderBatchEntry, type ApplyBatchOptions } from './storage-provider.js';
|
|
4
4
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
5
5
|
export declare class KvStoreProvider implements StorageProvider {
|
|
6
6
|
constructor(storeName: string, fastlyApiToken: string);
|
|
@@ -9,7 +9,7 @@ export declare class KvStoreProvider implements StorageProvider {
|
|
|
9
9
|
getStorageKeys(prefix?: string): Promise<string[] | null>;
|
|
10
10
|
getStorageEntry(key: string): Promise<StorageEntry | null>;
|
|
11
11
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
12
|
-
submitStorageEntry(key: string, _filePath: string, data:
|
|
12
|
+
submitStorageEntry(key: string, _filePath: string, data: StorageEntryData, metadata?: Record<string, string>): Promise<void>;
|
|
13
13
|
deleteStorageEntry(key: string): Promise<void>;
|
|
14
14
|
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
15
15
|
uploadEntries(entries: StorageProviderBatchEntry[], verbose?: boolean): Promise<void>;
|
|
@@ -17,6 +17,7 @@ export declare class KvStoreProvider implements StorageProvider {
|
|
|
17
17
|
key: string;
|
|
18
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
|
+
calculateChunkSizes(size: number): number[];
|
|
20
21
|
}
|
|
21
22
|
export declare function kvStoreEntryToStorageEntry(kvStoreEntry: KvStoreEntryInfo): StorageEntry;
|
|
22
23
|
export declare function parseKvStoreMetadata(metadata: string): Record<string, string> | null;
|
|
@@ -1 +1 @@
|
|
|
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;AAK9B,OAAO,EACL,KAAK,gBAAgB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aAAa,CAAC,OAAO,EAAE,yBAAyB,EAAE,EAAE,OAAO,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IA4C5F,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;IAIxC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;CAI5C;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,gBAAgB,gBA6B/B;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,iCAiCpD"}
|
|
@@ -9,8 +9,9 @@ import { FetchError, loadApiToken, } from '../util/api-token.js';
|
|
|
9
9
|
import { rootRelative, } from '../util/files.js';
|
|
10
10
|
import { ProgressLog } from '../util/progress.js';
|
|
11
11
|
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry, kvStoreSubmitEntry, kvStoreSubmitBatch, } from '../util/kv-store.js';
|
|
12
|
-
import { applyKVStoreEntriesChunks, packNdjsonBatches, ndjsonLineForBatchEntry, entriesToUpload, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
12
|
+
import { applyKVStoreEntriesChunks, chunkSizes, packNdjsonBatches, ndjsonLineForBatchEntry, entriesToUpload, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
13
13
|
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
14
|
+
import { storageEntryDataToBytes, } from './storage-provider.js';
|
|
14
15
|
export const buildStoreProvider = (config, context) => {
|
|
15
16
|
if (isKvStoreConfigRc(config) && !context.localMode) {
|
|
16
17
|
console.log(` Working on the Fastly KV Store...`);
|
|
@@ -50,7 +51,7 @@ export class KvStoreProvider {
|
|
|
50
51
|
return kvStoreEntryToStorageEntry(kvStoreEntry);
|
|
51
52
|
}
|
|
52
53
|
async submitStorageEntry(key, _filePath, data, metadata) {
|
|
53
|
-
await kvStoreSubmitEntry(this.fastlyApiContext, this.kvStoreName, key,
|
|
54
|
+
await kvStoreSubmitEntry(this.fastlyApiContext, this.kvStoreName, key, await storageEntryDataToBytes(data), metadata != null ? JSON.stringify(metadata) : undefined);
|
|
54
55
|
}
|
|
55
56
|
async deleteStorageEntry(key) {
|
|
56
57
|
await kvStoreDeleteEntry(this.fastlyApiContext, this.kvStoreName, key);
|
|
@@ -110,6 +111,9 @@ export class KvStoreProvider {
|
|
|
110
111
|
calculateNumChunks(size) {
|
|
111
112
|
return Math.ceil(size / KV_STORE_CHUNK_SIZE);
|
|
112
113
|
}
|
|
114
|
+
calculateChunkSizes(size) {
|
|
115
|
+
return chunkSizes(size, KV_STORE_CHUNK_SIZE);
|
|
116
|
+
}
|
|
113
117
|
}
|
|
114
118
|
export function kvStoreEntryToStorageEntry(kvStoreEntry) {
|
|
115
119
|
const storageEntry = {};
|
|
@@ -122,6 +126,11 @@ export function kvStoreEntryToStorageEntry(kvStoreEntry) {
|
|
|
122
126
|
storageEntry.metadata = metadata;
|
|
123
127
|
}
|
|
124
128
|
}
|
|
129
|
+
// The API gives the size of the value in this header, also for a HEAD request.
|
|
130
|
+
const storedContentLength = kvStoreEntry.response.headers.get('stored-content-length');
|
|
131
|
+
if (storedContentLength != null) {
|
|
132
|
+
storageEntry.size = Number(storedContentLength);
|
|
133
|
+
}
|
|
125
134
|
if (kvStoreEntry.generation != null) {
|
|
126
135
|
storageEntry.providerMetadata = {
|
|
127
136
|
generation: kvStoreEntry.generation,
|
|
@@ -1,6 +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 StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type ApplyBatchOptions } from './storage-provider.js';
|
|
3
|
+
import { type StorageEntry, type StorageEntryData, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type ApplyBatchOptions } from './storage-provider.js';
|
|
4
4
|
type CommandOutput<C> = C extends Command<any, any, any, infer O, any> ? O : never;
|
|
5
5
|
export declare const DEFAULT_S3_UPLOAD_CONCURRENCY = 64;
|
|
6
6
|
export declare const S3_LOCAL_MODE_ERROR = "--local is available only in KV Store mode. In S3 mode, the commands always use the bucket in static-publish.rc.js.";
|
|
@@ -19,13 +19,14 @@ export declare class S3StorageProvider implements StorageProvider {
|
|
|
19
19
|
getStorageKeys(prefix?: string): Promise<string[] | null>;
|
|
20
20
|
getStorageEntry(key: string): Promise<StorageEntry | null>;
|
|
21
21
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
22
|
-
submitStorageEntry(key: string, _filePath: string, data:
|
|
22
|
+
submitStorageEntry(key: string, _filePath: string, data: StorageEntryData, metadata?: Record<string, string>): Promise<void>;
|
|
23
23
|
deleteStorageEntry(key: string): Promise<void>;
|
|
24
24
|
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
25
25
|
doConcurrentParallel<TObject extends {
|
|
26
26
|
key: string;
|
|
27
27
|
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
28
28
|
calculateNumChunks(_size: number): number;
|
|
29
|
+
calculateChunkSizes(size: number): number[];
|
|
29
30
|
}
|
|
30
31
|
export {};
|
|
31
32
|
//# sourceMappingURL=s3-storage-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAQA,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,
|
|
1
|
+
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAQA,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,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EAEvB,MAAM,uBAAuB,CAAC;AAc/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;AAKnF,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,eAAO,MAAM,mBAAmB,wHAAwH,CAAC;AAEzJ,eAAO,MAAM,kBAAkB,EAAE,sBAyChC,CAAC;AAGF,qBAAa,iBAAkB,YAAW,eAAe;gBAErD,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,EACnB,iBAAiB,GAAE,MAAsC;IAU3D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ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,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,EAC1B,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAmBhB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIzC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;CAI5C"}
|
|
@@ -8,6 +8,7 @@ import https from 'node:https';
|
|
|
8
8
|
import { DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, PutObjectCommand, S3Client, S3ServiceException, paginateListObjectsV2, } from '@aws-sdk/client-s3';
|
|
9
9
|
import { isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
10
10
|
import { getS3StorageConfigFromRc, } from '../../models/config/s3-storage-config.js';
|
|
11
|
+
import { storageEntryDataToBytes, } from './storage-provider.js';
|
|
11
12
|
import { entriesToUpload } from '../util/kv-store-items.js';
|
|
12
13
|
import { loadS3Credentials, } from '../util/s3-credentials.js';
|
|
13
14
|
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
@@ -157,13 +158,14 @@ export class S3StorageProvider {
|
|
|
157
158
|
}
|
|
158
159
|
return {
|
|
159
160
|
metadata: response.Metadata,
|
|
161
|
+
size: response.ContentLength,
|
|
160
162
|
};
|
|
161
163
|
}
|
|
162
164
|
async submitStorageEntry(key, _filePath, data, metadata) {
|
|
163
165
|
const input = {
|
|
164
166
|
Bucket: this.s3Bucket, // required
|
|
165
167
|
Key: key, // required
|
|
166
|
-
Body: data
|
|
168
|
+
Body: await storageEntryDataToBytes(data),
|
|
167
169
|
Metadata: metadata,
|
|
168
170
|
};
|
|
169
171
|
const command = new PutObjectCommand(input);
|
|
@@ -207,4 +209,7 @@ export class S3StorageProvider {
|
|
|
207
209
|
calculateNumChunks(_size) {
|
|
208
210
|
return 1;
|
|
209
211
|
}
|
|
212
|
+
calculateChunkSizes(size) {
|
|
213
|
+
return [size];
|
|
214
|
+
}
|
|
210
215
|
}
|
|
@@ -3,18 +3,22 @@ export interface StorageEntry {
|
|
|
3
3
|
data?: ReadableStream<Uint8Array>;
|
|
4
4
|
metadata?: Record<string, string>;
|
|
5
5
|
providerMetadata?: Record<string, string>;
|
|
6
|
+
size?: number;
|
|
6
7
|
}
|
|
8
|
+
export type StorageEntryData = ReadableStream<Uint8Array> | Uint8Array | string | null | undefined;
|
|
9
|
+
export declare function storageEntryDataToBytes(data: StorageEntryData): Promise<Uint8Array>;
|
|
7
10
|
export interface StorageProvider {
|
|
8
11
|
getStorageKeys(prefix?: string): Promise<string[] | null>;
|
|
9
12
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
10
13
|
getStorageEntry(key: string): Promise<StorageEntry | null>;
|
|
11
|
-
submitStorageEntry(key: string, filePath: string, data:
|
|
14
|
+
submitStorageEntry(key: string, filePath: string, data: StorageEntryData, metadata?: Record<string, string>): Promise<void>;
|
|
12
15
|
deleteStorageEntry(key: string): Promise<void>;
|
|
13
16
|
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
14
17
|
doConcurrentParallel<TObject extends {
|
|
15
18
|
key: string;
|
|
16
19
|
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
17
20
|
calculateNumChunks(size: number): number;
|
|
21
|
+
calculateChunkSizes(size: number): number[];
|
|
18
22
|
}
|
|
19
23
|
export type StorageProviderBatchEntry = {
|
|
20
24
|
size: number;
|
|
@@ -43,4 +47,5 @@ export type StorageProviderBuilder = (config: StaticPublishRc, context: StorageP
|
|
|
43
47
|
export declare function getStorageKeysByHexPrefix(storageProvider: StorageProvider, prefix: string): Promise<string[] | null>;
|
|
44
48
|
export declare function registerStorageProviderBuilder(builder: StorageProviderBuilder): void;
|
|
45
49
|
export declare function loadStorageProviderFromStaticPublishRc(config: StaticPublishRc, context: StorageProviderBuilderContext): Promise<StorageProvider>;
|
|
50
|
+
export declare function isVariantInStorage(storageProvider: StorageProvider, existingKeys: Set<string>, variantKey: string, size: number, numChunks: number): Promise<boolean>;
|
|
46
51
|
//# sourceMappingURL=storage-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE1C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAMnG,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAWzF;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1D,mBAAmB,CAAC,G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C,MAAM,CAAC,CAAC;IAG3B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,qBAAa,oBAAoB;;IAI/B,2BAA2B,EAAE,yBAAyB,EAAE,CAAC;IACzD,GAAG,CAAC,KAAK,EAAE,yBAAyB;CAGrC;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AACF,MAAM,MAAM,sBAAsB,GAChC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,KAAK,CAAC,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC,CAAC;AAQlI,wBAAsB,yBAAyB,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAQ1H;AAGD,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,QAE7E;AAED,wBAAsB,sCAAsC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,4BAS3H;AAOD,wBAAsB,kBAAkB,CACtC,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,EACzB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC,CA6BlB"}
|
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
+
// Reads the data of an entry into memory. An upload of a stream has no
|
|
6
|
+
// Content-Length, and the Fastly KV Store API can refuse such an upload
|
|
7
|
+
// with 400 "must include valid content-length header". Thus the providers
|
|
8
|
+
// upload the bytes.
|
|
9
|
+
export async function storageEntryDataToBytes(data) {
|
|
10
|
+
if (data == null) {
|
|
11
|
+
return new Uint8Array(0);
|
|
12
|
+
}
|
|
13
|
+
if (typeof data === 'string') {
|
|
14
|
+
return new TextEncoder().encode(data);
|
|
15
|
+
}
|
|
16
|
+
if (data instanceof Uint8Array) {
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
return new Uint8Array(await new Response(data).arrayBuffer());
|
|
20
|
+
}
|
|
5
21
|
export class StorageProviderBatch {
|
|
6
22
|
constructor() {
|
|
7
23
|
this.storageProviderBatchEntries = [];
|
|
@@ -37,3 +53,35 @@ export async function loadStorageProviderFromStaticPublishRc(config, context) {
|
|
|
37
53
|
}
|
|
38
54
|
throw new Error('Static Publisher Error: Invalid static-publish.rc.js, storage mode not recognized, or could not instantiate store provider.');
|
|
39
55
|
}
|
|
56
|
+
// Returns true if storage has the variant with the key `variantKey`, which has
|
|
57
|
+
// `size` bytes in `numChunks` chunks. For a variant in more than one chunk, it
|
|
58
|
+
// also compares the stored size of each chunk with its expected size. It removes
|
|
59
|
+
// a chunk that has a different size, or that is not in storage now, from
|
|
60
|
+
// existingKeys, so that applyBatch() uploads the chunk again.
|
|
61
|
+
export async function isVariantInStorage(storageProvider, existingKeys, variantKey, size, numChunks) {
|
|
62
|
+
const chunkKeys = Array.from({ length: numChunks }, (_, chunkIndex) => chunkIndex === 0 ? variantKey : `${variantKey}_${chunkIndex}`);
|
|
63
|
+
if (!chunkKeys.every(key => existingKeys.has(key))) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (numChunks === 1) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
const expectedSizes = storageProvider.calculateChunkSizes(size);
|
|
70
|
+
const entries = await Promise.all(chunkKeys.map(key => storageProvider.getStorageEntryInfo(key)));
|
|
71
|
+
let found = true;
|
|
72
|
+
for (const [chunkIndex, key] of chunkKeys.entries()) {
|
|
73
|
+
const entry = entries[chunkIndex];
|
|
74
|
+
if (entry == null) {
|
|
75
|
+
existingKeys.delete(key);
|
|
76
|
+
found = false;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const storedSize = entry.size;
|
|
80
|
+
if (storedSize != null && storedSize !== expectedSizes[chunkIndex]) {
|
|
81
|
+
console.log(` ‼️ Chunk "${key}" in storage has ${storedSize} bytes, but it must have ${expectedSizes[chunkIndex]} bytes. It will be uploaded again.`);
|
|
82
|
+
existingKeys.delete(key);
|
|
83
|
+
found = false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return found;
|
|
87
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StorageProviderBatchEntry } from '../storage/storage-provider.js';
|
|
2
2
|
export declare const KV_STORE_CHUNK_SIZE: number;
|
|
3
|
+
export declare function chunkSizes(size: number, chunkSize: number): number[];
|
|
3
4
|
export declare function shouldRecreateChunks(chunksDir: string, numChunks: number, item: StorageProviderBatchEntry, chunkSize: number): boolean;
|
|
4
5
|
export declare function applyKVStoreEntriesChunks(kvStoreItemDescriptions: StorageProviderBatchEntry[], chunkSize: number): Promise<void>;
|
|
5
6
|
export declare const KV_BATCH_MAX_ITEMS = 256;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,eAAO,MAAM,mBAAmB,QAAqB,CAAC;AAItD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAGpE;AAED,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,iBAiEtH;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"}
|