@fastly/compute-js-static-publish 7.0.1 → 8.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/README.short.md +13 -4
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/clean.js +62 -108
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/collections/delete.js +50 -72
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/collections/index.js +15 -1
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/collections/list.js +45 -73
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/collections/promote.js +56 -93
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/collections/update-expiration.js +48 -77
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/index.js +15 -1
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/publish-content.js +90 -187
- package/build/cli/{commands → cli/commands}/scaffold/index.d.ts +4 -0
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/scaffold/index.js +262 -38
- package/build/cli/cli/compression/brotli.d.ts.map +1 -0
- package/build/cli/cli/compression/gzip.d.ts.map +1 -0
- package/build/cli/cli/compression/index.d.ts.map +1 -0
- package/build/cli/{index.d.ts.map → cli/index.d.ts.map} +1 -1
- package/build/cli/{index.js → cli/index.js} +8 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +20 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -0
- package/build/cli/cli/storage/kv-store-local-provider.js +86 -0
- package/build/cli/cli/storage/kv-store-provider.d.ts +24 -0
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -0
- package/build/cli/cli/storage/kv-store-provider.js +182 -0
- package/build/cli/cli/storage/s3-storage-provider.d.ts +30 -0
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -0
- package/build/cli/cli/storage/s3-storage-provider.js +201 -0
- package/build/cli/cli/storage/storage-provider.d.ts +44 -0
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -0
- package/build/cli/cli/storage/storage-provider.js +26 -0
- package/build/cli/cli/util/api-token.d.ts.map +1 -0
- package/build/cli/cli/util/args.d.ts.map +1 -0
- package/build/cli/cli/util/aws-credentials.d.ts +12 -0
- package/build/cli/cli/util/aws-credentials.d.ts.map +1 -0
- package/build/cli/cli/util/aws-credentials.js +67 -0
- package/build/cli/{util → cli/util}/config.d.ts +1 -1
- package/build/cli/cli/util/config.d.ts.map +1 -0
- package/build/cli/{util → cli/util}/config.js +36 -20
- package/build/cli/cli/util/content-types.d.ts.map +1 -0
- package/build/cli/cli/util/data.d.ts.map +1 -0
- package/build/cli/cli/util/fastly-toml.d.ts.map +1 -0
- package/build/cli/cli/util/files.d.ts.map +1 -0
- package/build/cli/{util → cli/util}/files.js +15 -0
- package/build/cli/cli/util/kv-store-items.d.ts +5 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -0
- package/build/cli/{util → cli/util}/kv-store-items.js +3 -42
- package/build/cli/{util → cli/util}/kv-store-local-server.d.ts +4 -7
- package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -0
- package/build/cli/{util → cli/util}/kv-store.d.ts +7 -10
- package/build/cli/cli/util/kv-store.d.ts.map +1 -0
- package/build/cli/cli/util/node.d.ts.map +1 -0
- package/build/cli/cli/util/package.d.ts.map +1 -0
- package/build/cli/{util → cli/util}/package.js +1 -1
- package/build/cli/{util → cli/util}/retryable.d.ts +3 -0
- package/build/cli/cli/util/retryable.d.ts.map +1 -0
- package/build/cli/cli/util/retryable.js +76 -0
- package/build/cli/cli/util/s3.d.ts +7 -0
- package/build/cli/cli/util/s3.d.ts.map +1 -0
- package/build/cli/cli/util/s3.js +43 -0
- package/build/cli/cli/util/variants.d.ts.map +1 -0
- package/build/{models/assets/kvstore-assets.d.ts → cli/models/assets/index.d.ts} +5 -5
- package/build/cli/models/assets/index.d.ts.map +1 -0
- package/build/cli/models/assets/index.js +33 -0
- package/build/cli/models/compression/index.d.ts.map +1 -0
- package/build/cli/models/config/kv-store-config.d.ts +6 -0
- package/build/cli/models/config/kv-store-config.d.ts.map +1 -0
- package/build/cli/models/config/kv-store-config.js +15 -0
- package/build/{models → cli/models}/config/publish-content-config.d.ts +4 -3
- package/build/cli/models/config/publish-content-config.d.ts.map +1 -0
- package/build/cli/models/config/publisher-server-config.d.ts.map +1 -0
- package/build/cli/models/config/s3-storage-config.d.ts +8 -0
- package/build/cli/models/config/s3-storage-config.d.ts.map +1 -0
- package/build/cli/models/config/s3-storage-config.js +11 -0
- package/build/cli/models/config/static-publish-rc.d.ts +31 -0
- package/build/cli/models/config/static-publish-rc.d.ts.map +1 -0
- package/build/cli/models/config/static-publish-rc.js +39 -0
- package/build/cli/models/metadata/index.d.ts +2 -0
- package/build/cli/models/metadata/index.d.ts.map +1 -0
- package/build/cli/models/metadata/index.js +8 -0
- package/build/cli/models/server/index.d.ts +7 -0
- package/build/cli/models/server/index.d.ts.map +1 -0
- package/build/cli/models/server/index.js +26 -0
- package/build/cli/models/time/index.d.ts.map +1 -0
- package/build/{models → cli/models}/time/index.js +5 -5
- package/build/server/models/assets/index.d.ts +17 -0
- package/build/server/models/assets/index.d.ts.map +1 -0
- package/build/server/models/assets/index.js +33 -0
- package/build/server/models/compression/index.d.ts +4 -0
- package/build/server/models/compression/index.d.ts.map +1 -0
- package/build/server/models/compression/index.js +11 -0
- package/build/server/models/config/kv-store-config.d.ts +6 -0
- package/build/server/models/config/kv-store-config.d.ts.map +1 -0
- package/build/server/models/config/kv-store-config.js +15 -0
- package/build/server/models/config/publish-content-config.d.ts +40 -0
- package/build/server/models/config/publish-content-config.d.ts.map +1 -0
- package/build/server/models/config/publisher-server-config.d.ts +20 -0
- package/build/server/models/config/publisher-server-config.d.ts.map +1 -0
- package/build/server/models/config/s3-storage-config.d.ts +8 -0
- package/build/server/models/config/s3-storage-config.d.ts.map +1 -0
- package/build/server/models/config/s3-storage-config.js +11 -0
- package/build/server/models/config/static-publish-rc.d.ts +31 -0
- package/build/server/models/config/static-publish-rc.d.ts.map +1 -0
- package/build/server/models/config/static-publish-rc.js +39 -0
- package/build/server/models/metadata/index.d.ts +2 -0
- package/build/server/models/metadata/index.d.ts.map +1 -0
- package/build/server/models/metadata/index.js +8 -0
- package/build/server/models/server/index.d.ts +7 -0
- package/build/server/models/server/index.d.ts.map +1 -0
- package/build/server/models/server/index.js +26 -0
- package/build/server/models/time/index.d.ts +8 -0
- package/build/server/models/time/index.d.ts.map +1 -0
- package/build/server/models/time/index.js +54 -0
- package/build/server/server/collection-selector/from-config-store.d.ts.map +1 -0
- package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -0
- package/build/server/server/collection-selector/from-request.d.ts.map +1 -0
- package/build/server/server/collection-selector/index.d.ts.map +1 -0
- package/build/server/server/collection-selector/request-collection-selector.d.ts.map +1 -0
- package/build/server/server/collection-selector/request-collection-selector.js +5 -0
- package/build/server/server/index.d.ts +8 -0
- package/build/server/server/index.d.ts.map +1 -0
- package/build/server/server/index.js +15 -0
- package/build/server/{publisher-server → server/publisher-server}/index.d.ts +14 -14
- package/build/server/server/publisher-server/index.d.ts.map +1 -0
- package/build/server/{publisher-server → server/publisher-server}/index.js +60 -61
- package/build/server/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +1 -0
- package/build/server/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +1 -0
- package/build/server/server/storage/kv-store-provider.d.ts +8 -0
- package/build/server/server/storage/kv-store-provider.d.ts.map +1 -0
- package/build/server/server/storage/kv-store-provider.js +24 -0
- package/build/server/server/storage/s3-storage-provider.d.ts +26 -0
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -0
- package/build/server/server/storage/s3-storage-provider.js +110 -0
- package/build/server/server/storage/storage-provider.d.ts +48 -0
- package/build/server/server/storage/storage-provider.d.ts.map +1 -0
- package/build/server/{util/kv-store.js → server/storage/storage-provider.js} +17 -39
- package/build/server/server/util/cookies.d.ts.map +1 -0
- package/build/server/server/util/kv-store.d.ts.map +1 -0
- package/build/server/server/util/kv-store.js +40 -0
- package/package.json +9 -5
- package/build/cli/commands/manage/clean.d.ts.map +0 -1
- package/build/cli/commands/manage/collections/delete.d.ts.map +0 -1
- package/build/cli/commands/manage/collections/index.d.ts.map +0 -1
- package/build/cli/commands/manage/collections/list.d.ts.map +0 -1
- package/build/cli/commands/manage/collections/promote.d.ts.map +0 -1
- package/build/cli/commands/manage/collections/update-expiration.d.ts.map +0 -1
- package/build/cli/commands/manage/index.d.ts.map +0 -1
- package/build/cli/commands/manage/publish-content.d.ts.map +0 -1
- package/build/cli/commands/scaffold/index.d.ts.map +0 -1
- package/build/cli/compression/brotli.d.ts.map +0 -1
- package/build/cli/compression/gzip.d.ts.map +0 -1
- package/build/cli/compression/index.d.ts.map +0 -1
- package/build/cli/util/api-token.d.ts.map +0 -1
- package/build/cli/util/args.d.ts.map +0 -1
- package/build/cli/util/config.d.ts.map +0 -1
- package/build/cli/util/content-types.d.ts.map +0 -1
- package/build/cli/util/data.d.ts.map +0 -1
- package/build/cli/util/fastly-toml.d.ts.map +0 -1
- package/build/cli/util/files.d.ts.map +0 -1
- package/build/cli/util/kv-store-items.d.ts +0 -13
- package/build/cli/util/kv-store-items.d.ts.map +0 -1
- package/build/cli/util/kv-store-local-server.d.ts.map +0 -1
- package/build/cli/util/kv-store.d.ts.map +0 -1
- package/build/cli/util/node.d.ts.map +0 -1
- package/build/cli/util/package.d.ts.map +0 -1
- package/build/cli/util/retryable.d.ts.map +0 -1
- package/build/cli/util/retryable.js +0 -43
- package/build/cli/util/variants.d.ts.map +0 -1
- package/build/index.d.ts +0 -6
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -7
- package/build/models/assets/kvstore-assets.d.ts.map +0 -1
- package/build/models/assets/kvstore-assets.js +0 -28
- package/build/models/compression/index.d.ts.map +0 -1
- package/build/models/config/publish-content-config.d.ts.map +0 -1
- package/build/models/config/publisher-server-config.d.ts.map +0 -1
- package/build/models/config/static-publish-rc.d.ts +0 -7
- package/build/models/config/static-publish-rc.d.ts.map +0 -1
- package/build/models/server/index.d.ts +0 -5
- package/build/models/server/index.d.ts.map +0 -1
- package/build/models/server/index.js +0 -1
- package/build/models/time/index.d.ts.map +0 -1
- package/build/server/collection-selector/from-config-store.d.ts.map +0 -1
- package/build/server/collection-selector/from-cookie.d.ts.map +0 -1
- package/build/server/collection-selector/from-request.d.ts.map +0 -1
- package/build/server/collection-selector/index.d.ts.map +0 -1
- package/build/server/collection-selector/request-collection-selector.d.ts.map +0 -1
- package/build/server/publisher-server/index.d.ts.map +0 -1
- package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +0 -1
- package/build/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +0 -1
- package/build/server/util/cookies.d.ts.map +0 -1
- package/build/server/util/kv-store.d.ts.map +0 -1
- /package/build/cli/{commands → cli/commands}/manage/clean.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/collections/delete.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/collections/index.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/collections/list.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/collections/promote.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/collections/update-expiration.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/index.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/publish-content.d.ts +0 -0
- /package/build/cli/{compression → cli/compression}/brotli.d.ts +0 -0
- /package/build/cli/{compression → cli/compression}/brotli.js +0 -0
- /package/build/cli/{compression → cli/compression}/gzip.d.ts +0 -0
- /package/build/cli/{compression → cli/compression}/gzip.js +0 -0
- /package/build/cli/{compression → cli/compression}/index.d.ts +0 -0
- /package/build/cli/{compression → cli/compression}/index.js +0 -0
- /package/build/cli/{index.d.ts → cli/index.d.ts} +0 -0
- /package/build/cli/{util → cli/util}/api-token.d.ts +0 -0
- /package/build/cli/{util → cli/util}/api-token.js +0 -0
- /package/build/cli/{util → cli/util}/args.d.ts +0 -0
- /package/build/cli/{util → cli/util}/args.js +0 -0
- /package/build/cli/{util → cli/util}/content-types.d.ts +0 -0
- /package/build/cli/{util → cli/util}/content-types.js +0 -0
- /package/build/cli/{util → cli/util}/data.d.ts +0 -0
- /package/build/cli/{util → cli/util}/data.js +0 -0
- /package/build/cli/{util → cli/util}/fastly-toml.d.ts +0 -0
- /package/build/cli/{util → cli/util}/fastly-toml.js +0 -0
- /package/build/cli/{util → cli/util}/files.d.ts +0 -0
- /package/build/cli/{util → cli/util}/kv-store-local-server.js +0 -0
- /package/build/cli/{util → cli/util}/kv-store.js +0 -0
- /package/build/cli/{util → cli/util}/node.d.ts +0 -0
- /package/build/cli/{util → cli/util}/node.js +0 -0
- /package/build/cli/{util → cli/util}/package.d.ts +0 -0
- /package/build/cli/{util → cli/util}/variants.d.ts +0 -0
- /package/build/cli/{util → cli/util}/variants.js +0 -0
- /package/build/{models → cli/models}/compression/index.d.ts +0 -0
- /package/build/{models → cli/models}/compression/index.js +0 -0
- /package/build/{models → cli/models}/config/publish-content-config.js +0 -0
- /package/build/{models → cli/models}/config/publisher-server-config.d.ts +0 -0
- /package/build/{models → cli/models}/config/publisher-server-config.js +0 -0
- /package/build/{models → cli/models}/time/index.d.ts +0 -0
- /package/build/{models/config/static-publish-rc.js → server/models/config/publish-content-config.js} +0 -0
- /package/build/server/{collection-selector/request-collection-selector.js → models/config/publisher-server-config.js} +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-config-store.d.ts +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-config-store.js +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-cookie.d.ts +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-cookie.js +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-request.d.ts +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-request.js +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/index.d.ts +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/index.js +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/request-collection-selector.d.ts +0 -0
- /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-modified-since.d.ts +0 -0
- /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-modified-since.js +0 -0
- /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-none-match.d.ts +0 -0
- /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-none-match.js +0 -0
- /package/build/server/{util → server/util}/cookies.d.ts +0 -0
- /package/build/server/{util → server/util}/cookies.js +0 -0
- /package/build/server/{util → server/util}/kv-store.d.ts +0 -0
|
@@ -12,6 +12,7 @@ import * as fs from 'node:fs';
|
|
|
12
12
|
import { parseCommandLine } from '../../util/args.js';
|
|
13
13
|
import { dotRelative, rootRelative } from '../../util/files.js';
|
|
14
14
|
import { findComputeJsStaticPublisherVersion } from '../../util/package.js';
|
|
15
|
+
import { resolveS3Hostname } from '../../util/s3.js';
|
|
15
16
|
function help() {
|
|
16
17
|
console.log(`\
|
|
17
18
|
|
|
@@ -25,7 +26,16 @@ Description:
|
|
|
25
26
|
management mode.
|
|
26
27
|
|
|
27
28
|
Options:
|
|
28
|
-
--
|
|
29
|
+
--storage-mode <mode> (required) Storage mode for content storage.
|
|
30
|
+
Can be "kv-store" or "s3".
|
|
31
|
+
If --storage-mode=kv-store, then:
|
|
32
|
+
--kv-store-name <name> (required) Name of the KV Store.
|
|
33
|
+
|
|
34
|
+
If --storage-mode=s3, then:
|
|
35
|
+
--s3-region <region name> (required) Region of the S3-compatible bucket.
|
|
36
|
+
--s3-bucket <name> (required) Name of the S3-compatible bucket.
|
|
37
|
+
--s3-endpoint <endpoint> (optional) Custom endpoint of the S3-compatible bucket, if necessary.
|
|
38
|
+
|
|
29
39
|
--root-dir <path> (required) Path to static content (e.g., ./public)
|
|
30
40
|
-o, --output <dir> Output directory for Compute app (default: ./compute-js)
|
|
31
41
|
--static-publisher-working-dir <dir> Working directory for build artifacts (default: <output>/static-publisher)
|
|
@@ -66,7 +76,11 @@ const defaultOptions = {
|
|
|
66
76
|
description: 'Fastly Compute static site',
|
|
67
77
|
serviceId: undefined,
|
|
68
78
|
publishId: undefined,
|
|
79
|
+
storageMode: undefined,
|
|
69
80
|
kvStoreName: undefined,
|
|
81
|
+
s3Region: undefined,
|
|
82
|
+
s3Bucket: undefined,
|
|
83
|
+
s3Endpoint: undefined,
|
|
70
84
|
};
|
|
71
85
|
function buildOptions(packageJson, commandLineOptions) {
|
|
72
86
|
// Applied in this order for proper overriding
|
|
@@ -257,6 +271,16 @@ function buildOptions(packageJson, commandLineOptions) {
|
|
|
257
271
|
options.publishId = publishId;
|
|
258
272
|
}
|
|
259
273
|
}
|
|
274
|
+
{
|
|
275
|
+
let storageMode;
|
|
276
|
+
const storageModeValue = commandLineOptions['storage-mode'];
|
|
277
|
+
if (storageModeValue == null || typeof storageModeValue === 'string') {
|
|
278
|
+
storageMode = storageModeValue;
|
|
279
|
+
}
|
|
280
|
+
if (storageMode !== undefined) {
|
|
281
|
+
options.storageMode = storageMode;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
260
284
|
{
|
|
261
285
|
let kvStoreName;
|
|
262
286
|
const kvStoreNameValue = commandLineOptions['kv-store-name'];
|
|
@@ -267,6 +291,36 @@ function buildOptions(packageJson, commandLineOptions) {
|
|
|
267
291
|
options.kvStoreName = kvStoreName;
|
|
268
292
|
}
|
|
269
293
|
}
|
|
294
|
+
{
|
|
295
|
+
let s3Region;
|
|
296
|
+
const s3RegionValue = commandLineOptions['s3-region'];
|
|
297
|
+
if (s3RegionValue == null || typeof s3RegionValue === 'string') {
|
|
298
|
+
s3Region = s3RegionValue;
|
|
299
|
+
}
|
|
300
|
+
if (s3Region !== undefined) {
|
|
301
|
+
options.s3Region = s3Region;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
{
|
|
305
|
+
let s3Bucket;
|
|
306
|
+
const s3BucketValue = commandLineOptions['s3-bucket'];
|
|
307
|
+
if (s3BucketValue == null || typeof s3BucketValue === 'string') {
|
|
308
|
+
s3Bucket = s3BucketValue;
|
|
309
|
+
}
|
|
310
|
+
if (s3Bucket !== undefined) {
|
|
311
|
+
options.s3Bucket = s3Bucket;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
{
|
|
315
|
+
let s3Endpoint;
|
|
316
|
+
const s3EndpointValue = commandLineOptions['s3-endpoint'];
|
|
317
|
+
if (s3EndpointValue == null || typeof s3EndpointValue === 'string') {
|
|
318
|
+
s3Endpoint = s3EndpointValue;
|
|
319
|
+
}
|
|
320
|
+
if (s3Endpoint !== undefined) {
|
|
321
|
+
options.s3Endpoint = s3Endpoint;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
270
324
|
return options;
|
|
271
325
|
}
|
|
272
326
|
const PUBLIC_DIR_TOKEN = '[public-dir]';
|
|
@@ -280,9 +334,19 @@ function processPublicDirToken(filepath, publicDir) {
|
|
|
280
334
|
export async function action(actionArgs) {
|
|
281
335
|
const optionDefinitions = [
|
|
282
336
|
{ name: 'verbose', type: Boolean },
|
|
283
|
-
// Required.
|
|
284
|
-
|
|
337
|
+
// Required. Storage mode for content storage. Can be "kv-store" or "s3".
|
|
338
|
+
{ name: 'storage-mode', type: String, },
|
|
339
|
+
// If storage-mode=kv-store, then:
|
|
340
|
+
// Required. The name of a Fastly KV Store to hold the content assets.
|
|
341
|
+
// It is also added to the fastly.toml that is generated.
|
|
285
342
|
{ name: 'kv-store-name', type: String, },
|
|
343
|
+
// If storage-mode=s3, then:
|
|
344
|
+
// Required. Region of the S3-compatible bucket.
|
|
345
|
+
{ name: 's3-region', type: String, },
|
|
346
|
+
// Required. Bucket of the S3-compatible bucket.
|
|
347
|
+
{ name: 's3-bucket', type: String, },
|
|
348
|
+
// Optional. Custom endpoint of the S3-compatible bucket, if necessary.
|
|
349
|
+
{ name: 's3-endpoint', type: String, },
|
|
286
350
|
// Output directory. "Required" (if not specified, then defaultValue is used).
|
|
287
351
|
{ name: 'output', alias: 'o', type: String, defaultValue: './compute-js', },
|
|
288
352
|
// Name of the application, to be inserted into fastly.toml
|
|
@@ -474,12 +538,64 @@ export async function action(actionArgs) {
|
|
|
474
538
|
const name = options.name;
|
|
475
539
|
const description = options.description;
|
|
476
540
|
const fastlyServiceId = options.serviceId;
|
|
477
|
-
const
|
|
478
|
-
if (
|
|
479
|
-
console.error(`❌ required parameter --kv-store
|
|
541
|
+
const storageMode = options.storageMode;
|
|
542
|
+
if (!(storageMode === 'kv-store' || storageMode === 's3')) {
|
|
543
|
+
console.error(`❌ required parameter --storage-mode must be set to 'kv-store' or 's3'.`);
|
|
480
544
|
process.exitCode = 1;
|
|
481
545
|
return;
|
|
482
546
|
}
|
|
547
|
+
const kvStoreName = options.kvStoreName;
|
|
548
|
+
const s3Region = options.s3Region;
|
|
549
|
+
const s3Bucket = options.s3Bucket;
|
|
550
|
+
let s3EndpointUrl;
|
|
551
|
+
let s3EndpointGenerated = false;
|
|
552
|
+
if (storageMode === 'kv-store') {
|
|
553
|
+
if (kvStoreName == null) {
|
|
554
|
+
console.error(`❌ required parameter --kv-store-name not provided.`);
|
|
555
|
+
process.exitCode = 1;
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
else if (storageMode === 's3') {
|
|
560
|
+
if (s3Region == null) {
|
|
561
|
+
console.error(`❌ required parameter --s3-region not provided.`);
|
|
562
|
+
process.exitCode = 1;
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (s3Bucket == null) {
|
|
566
|
+
console.error(`❌ required parameter --s3-bucket not provided.`);
|
|
567
|
+
process.exitCode = 1;
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
let s3Endpoint = options.s3Endpoint;
|
|
571
|
+
if (s3Endpoint == null || s3Endpoint === '') {
|
|
572
|
+
s3Endpoint = await resolveS3Hostname(s3Region, s3Bucket);
|
|
573
|
+
if (s3Endpoint) {
|
|
574
|
+
console.log('✅ S3 endpoint resolved:', s3Endpoint);
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
console.error(`❌ Unable to resolve S3 endpoint from region '${s3Region}' and bucket '${s3Bucket}.`);
|
|
578
|
+
process.exitCode = 1;
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
s3EndpointUrl = new URL(`https://${s3Endpoint}/`);
|
|
582
|
+
s3EndpointGenerated = true;
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
if (!(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(s3Endpoint))) {
|
|
586
|
+
s3Endpoint = `https://${s3Endpoint}`;
|
|
587
|
+
}
|
|
588
|
+
// Check if s3Endpoint is a full URL or just a domain name
|
|
589
|
+
try {
|
|
590
|
+
s3EndpointUrl = new URL(s3Endpoint);
|
|
591
|
+
}
|
|
592
|
+
catch {
|
|
593
|
+
console.error(`❌ Unable to parse '${s3Endpoint}' as a valid URL.`);
|
|
594
|
+
process.exitCode = 1;
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
483
599
|
let publishId = options.publishId;
|
|
484
600
|
if (publishId == null) {
|
|
485
601
|
publishId = 'default';
|
|
@@ -493,7 +609,19 @@ export async function action(actionArgs) {
|
|
|
493
609
|
console.log('author :', author);
|
|
494
610
|
console.log('description :', description);
|
|
495
611
|
console.log('Service ID :', fastlyServiceId ?? '(None)');
|
|
496
|
-
|
|
612
|
+
if (storageMode === 'kv-store') {
|
|
613
|
+
console.log('Storage Mode : Fastly KV Store');
|
|
614
|
+
console.log('KV Store Name :', kvStoreName);
|
|
615
|
+
}
|
|
616
|
+
else if (storageMode === 's3') {
|
|
617
|
+
console.log('Storage Name : S3-compatible storage');
|
|
618
|
+
console.log('S3 Region :', s3Region);
|
|
619
|
+
console.log('S3 Bucket :', s3Bucket);
|
|
620
|
+
console.log('S3 Endpoint :', String(s3EndpointUrl));
|
|
621
|
+
if (s3EndpointGenerated) {
|
|
622
|
+
console.log(' (Generated)');
|
|
623
|
+
}
|
|
624
|
+
}
|
|
497
625
|
console.log('Default Collection Name :', defaultCollectionName);
|
|
498
626
|
console.log('Publish ID :', publishId);
|
|
499
627
|
console.log('');
|
|
@@ -524,6 +652,18 @@ export async function action(actionArgs) {
|
|
|
524
652
|
`;
|
|
525
653
|
// package.json
|
|
526
654
|
const computeJsStaticPublisherVersion = findComputeJsStaticPublisherVersion(packageJson);
|
|
655
|
+
const packageJsonScripts = {
|
|
656
|
+
'dev:start': 'fastly compute serve',
|
|
657
|
+
'fastly:deploy': 'fastly compute publish',
|
|
658
|
+
'build': 'js-compute-runtime ./src/index.js ./bin/main.wasm',
|
|
659
|
+
};
|
|
660
|
+
if (storageMode === 'kv-store') {
|
|
661
|
+
packageJsonScripts['dev:publish'] = 'npx @fastly/compute-js-static-publish publish-content --local';
|
|
662
|
+
packageJsonScripts['fastly:publish'] = 'npx @fastly/compute-js-static-publish publish-content';
|
|
663
|
+
}
|
|
664
|
+
else if (storageMode === 's3') {
|
|
665
|
+
packageJsonScripts['publish'] = 'npx @fastly/compute-js-static-publish publish-content --local';
|
|
666
|
+
}
|
|
527
667
|
resourceFiles['package.json'] = JSON.stringify({
|
|
528
668
|
name,
|
|
529
669
|
version: '0.1.0',
|
|
@@ -531,7 +671,7 @@ export async function action(actionArgs) {
|
|
|
531
671
|
author,
|
|
532
672
|
type: 'module',
|
|
533
673
|
devDependencies: {
|
|
534
|
-
"@fastly/cli": "^
|
|
674
|
+
"@fastly/cli": "^12.0.0",
|
|
535
675
|
'@fastly/compute-js-static-publish': computeJsStaticPublisherVersion,
|
|
536
676
|
},
|
|
537
677
|
dependencies: {
|
|
@@ -541,16 +681,45 @@ export async function action(actionArgs) {
|
|
|
541
681
|
node: '>=20.11.0',
|
|
542
682
|
},
|
|
543
683
|
private: true,
|
|
544
|
-
scripts:
|
|
545
|
-
'dev:publish': 'npx @fastly/compute-js-static-publish publish-content --local',
|
|
546
|
-
'dev:start': 'fastly compute serve',
|
|
547
|
-
'fastly:deploy': 'fastly compute publish',
|
|
548
|
-
'fastly:publish': 'npx @fastly/compute-js-static-publish publish-content',
|
|
549
|
-
'build': 'js-compute-runtime ./src/index.js ./bin/main.wasm'
|
|
550
|
-
},
|
|
684
|
+
scripts: packageJsonScripts,
|
|
551
685
|
}, undefined, 2);
|
|
552
686
|
// fastly.toml
|
|
553
|
-
|
|
687
|
+
let fastlyTomlLocalServer = '';
|
|
688
|
+
let fastlyTomlSetup = '';
|
|
689
|
+
if (storageMode === 'kv-store') {
|
|
690
|
+
const localServerKvStorePath = dotRelative(computeJsDir, path.resolve(staticPublisherWorkingDir, 'kvstore.json'));
|
|
691
|
+
fastlyTomlLocalServer = /* language=text */ `\
|
|
692
|
+
[local_server.kv_stores]
|
|
693
|
+
${kvStoreName} = { file = "${localServerKvStorePath}", format = "json" }
|
|
694
|
+
`;
|
|
695
|
+
fastlyTomlSetup = /* language=text */ `\
|
|
696
|
+
[setup.kv_stores.${kvStoreName}]
|
|
697
|
+
`;
|
|
698
|
+
// kvstore.json
|
|
699
|
+
resourceFiles[localServerKvStorePath] = '{}';
|
|
700
|
+
}
|
|
701
|
+
else if (storageMode === 's3') {
|
|
702
|
+
fastlyTomlLocalServer = /* language=text */ `\
|
|
703
|
+
[local_server.secret_stores]
|
|
704
|
+
[[local_server.secret_stores.AWS_CREDENTIALS]]
|
|
705
|
+
key = "AWS_ACCESS_KEY_ID"
|
|
706
|
+
env = "AWS_ACCESS_KEY_ID"
|
|
707
|
+
[[local_server.secret_stores.AWS_CREDENTIALS]]
|
|
708
|
+
key = "AWS_SECRET_ACCESS_KEY"
|
|
709
|
+
env = "AWS_SECRET_ACCESS_KEY"
|
|
710
|
+
|
|
711
|
+
[local_server.backends]
|
|
712
|
+
[local_server.backends.aws]
|
|
713
|
+
url = "${String(s3EndpointUrl)}"
|
|
714
|
+
override_host = "${s3EndpointUrl.hostname}"
|
|
715
|
+
`;
|
|
716
|
+
fastlyTomlSetup = /* language=text */ `\
|
|
717
|
+
[setup.backends.aws]
|
|
718
|
+
address = "${s3EndpointUrl.hostname}"
|
|
719
|
+
description = "S3 API endpoint"
|
|
720
|
+
port = 443
|
|
721
|
+
`;
|
|
722
|
+
}
|
|
554
723
|
resourceFiles['fastly.toml'] = /* language=text */ `\
|
|
555
724
|
# This file describes a Fastly Compute package. To learn more visit:
|
|
556
725
|
# https://developer.fastly.com/reference/fastly-toml/
|
|
@@ -564,14 +733,31 @@ ${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"\n` : ''}
|
|
|
564
733
|
[scripts]
|
|
565
734
|
build = "npm run build"
|
|
566
735
|
|
|
567
|
-
|
|
568
|
-
${
|
|
569
|
-
|
|
570
|
-
[setup.kv_stores.${kvStoreName}]
|
|
736
|
+
${fastlyTomlLocalServer}
|
|
737
|
+
${fastlyTomlSetup}
|
|
571
738
|
`;
|
|
572
|
-
// kvstore.json
|
|
573
|
-
resourceFiles[localServerKvStorePath] = '{}';
|
|
574
739
|
// static-publish.rc.js
|
|
740
|
+
let staticPublishStorage = '';
|
|
741
|
+
if (storageMode === 'kv-store') {
|
|
742
|
+
staticPublishStorage = `\
|
|
743
|
+
storageMode: "kv-store",
|
|
744
|
+
kvStore: {
|
|
745
|
+
kvStoreName: ${JSON.stringify(kvStoreName)},
|
|
746
|
+
},\
|
|
747
|
+
`;
|
|
748
|
+
}
|
|
749
|
+
else if (storageMode === 's3') {
|
|
750
|
+
staticPublishStorage = `\
|
|
751
|
+
storageMode: "s3",
|
|
752
|
+
s3: {
|
|
753
|
+
region: ${JSON.stringify(s3Region)},
|
|
754
|
+
bucket: ${JSON.stringify(s3Bucket)},\
|
|
755
|
+
` + (!s3EndpointGenerated ? `
|
|
756
|
+
endpoint: ${JSON.stringify(String(s3EndpointUrl))},\
|
|
757
|
+
` : '') + `
|
|
758
|
+
},\
|
|
759
|
+
`;
|
|
760
|
+
}
|
|
575
761
|
resourceFiles['static-publish.rc.js'] = `\
|
|
576
762
|
/*
|
|
577
763
|
* Generated by @fastly/compute-js-static-publish.
|
|
@@ -579,7 +765,7 @@ ${kvStoreName} = { file = "${localServerKvStorePath}", format = "json" }
|
|
|
579
765
|
|
|
580
766
|
/** @type {import('@fastly/compute-js-static-publish').StaticPublishRc} */
|
|
581
767
|
const rc = {
|
|
582
|
-
|
|
768
|
+
${staticPublishStorage}
|
|
583
769
|
publishId: ${JSON.stringify(publishId)},
|
|
584
770
|
defaultCollectionName: ${JSON.stringify(defaultCollectionName)},
|
|
585
771
|
staticPublisherWorkingDir: ${JSON.stringify(dotRelative(computeJsDir, staticPublisherWorkingDir))},
|
|
@@ -637,13 +823,13 @@ const config = {
|
|
|
637
823
|
// excludeDirs: [ './node_modules' ],
|
|
638
824
|
// excludeDotFiles: true,
|
|
639
825
|
// includeWellKnown: true,
|
|
640
|
-
//
|
|
826
|
+
// assetInclusionTest: (assetKey) => true,
|
|
641
827
|
// contentCompression: [ 'br', 'gzip' ],
|
|
642
828
|
// contentTypes: [
|
|
643
829
|
// { test: /.custom$/, contentType: 'application/x-custom', text: false },
|
|
644
830
|
// ],
|
|
645
831
|
|
|
646
|
-
// Server settings are saved to
|
|
832
|
+
// Server settings are saved to storage per collection
|
|
647
833
|
server: {
|
|
648
834
|
publicDirPrefix: ${JSON.stringify(publicDirPrefix)},
|
|
649
835
|
staticItems: ${JSON.stringify(staticItems)},
|
|
@@ -695,17 +881,55 @@ async function handleRequest(event) {
|
|
|
695
881
|
console.log(`npm --prefix ${COMPUTE_JS_DIR} install`);
|
|
696
882
|
child_process.spawnSync('npm', ['--prefix', COMPUTE_JS_DIR, 'install'], { stdio: 'inherit' });
|
|
697
883
|
console.log('');
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
884
|
+
if (storageMode === 'kv-store') {
|
|
885
|
+
console.log(`
|
|
886
|
+
To run your Compute application locally:
|
|
887
|
+
|
|
888
|
+
cd ${COMPUTE_JS_DIR}
|
|
889
|
+
npm run dev:publish
|
|
890
|
+
npm run dev:start
|
|
891
|
+
|
|
892
|
+
To build and deploy to your Compute service:
|
|
893
|
+
|
|
894
|
+
cd ${COMPUTE_JS_DIR}
|
|
895
|
+
npm run fastly:publish
|
|
896
|
+
npm run fastly:start
|
|
897
|
+
|
|
898
|
+
`);
|
|
899
|
+
}
|
|
900
|
+
else if (storageMode === 's3') {
|
|
901
|
+
console.log(`
|
|
902
|
+
To publish your content to your S3-compatible bucket
|
|
903
|
+
|
|
904
|
+
Ensure that your S3-compatible bucket already exists:
|
|
905
|
+
Region: ${s3Region}
|
|
906
|
+
Bucket: ${s3Bucket}
|
|
907
|
+
Endpoint: ${String(s3EndpointUrl)}
|
|
908
|
+
|
|
909
|
+
Using an AWS profile set with "aws configure", type:
|
|
910
|
+
cd ${COMPUTE_JS_DIR}
|
|
911
|
+
AWS_PROFILE=xxxx npm run publish
|
|
912
|
+
|
|
913
|
+
Using AWS IAM credentials, type:
|
|
914
|
+
cd ${COMPUTE_JS_DIR}
|
|
915
|
+
AWS_ACCESS_KEY_ID=xxxx AWS_SECRET_ACCESS_KEY=xxxx npm run publish
|
|
916
|
+
|
|
917
|
+
To run your Compute application locally
|
|
918
|
+
|
|
919
|
+
Run the following commands:
|
|
920
|
+
cd ${COMPUTE_JS_DIR}
|
|
921
|
+
AWS_ACCESS_KEY_ID=xxxx AWS_SECRET_ACCESS_KEY=xxxx npm run dev:start
|
|
922
|
+
|
|
923
|
+
To build and deploy to your Compute service:
|
|
924
|
+
|
|
925
|
+
Create a Secret Store in your account named AWS_CREDENTIALS, and set the following values:
|
|
926
|
+
AWS_ACCESS_KEY_ID: xxxx
|
|
927
|
+
AWS_SECRET_ACCESS_KEY: xxxx
|
|
928
|
+
|
|
929
|
+
Run the following commands:
|
|
930
|
+
cd ${COMPUTE_JS_DIR}
|
|
931
|
+
npm run fastly:start
|
|
932
|
+
|
|
933
|
+
`);
|
|
934
|
+
}
|
|
711
935
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brotli.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/brotli.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,GAAG,OAAO,CAAC;AAExB,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gzip.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/gzip.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,GAAG,SAAS,CAAC;AAE1B,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAEjF,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvE,QAAA,MAAM,IAAI,EAAE,MAAM,CAAC,uBAAuB,EAAE,WAAW,CAGtD,CAAC;AAEF,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":""}
|
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import * as scaffoldCommand from './commands/scaffold/index.js';
|
|
8
8
|
import * as manageCommands from './commands/manage/index.js';
|
|
9
|
+
// Register storage builder providers
|
|
10
|
+
import { registerStorageProviderBuilder } from './storage/storage-provider.js';
|
|
11
|
+
import * as kvStoreProvider from './storage/kv-store-provider.js';
|
|
12
|
+
import * as kvStoreLocalProvider from './storage/kv-store-local-provider.js';
|
|
13
|
+
import * as s3StorageProvider from './storage/s3-storage-provider.js';
|
|
14
|
+
registerStorageProviderBuilder(kvStoreProvider.buildStoreProvider);
|
|
15
|
+
registerStorageProviderBuilder(kvStoreLocalProvider.buildStoreProvider);
|
|
16
|
+
registerStorageProviderBuilder(s3StorageProvider.buildStoreProvider);
|
|
9
17
|
if (!fs.existsSync('./static-publish.rc.js')) {
|
|
10
18
|
console.log("🧑💻Fastly Compute JavaScript Static Publisher (Scaffolding mode)");
|
|
11
19
|
await scaffoldCommand.action(process.argv);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type AssetVariantMetadata } from '../../models/assets/index.js';
|
|
2
|
+
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch } from './storage-provider.js';
|
|
3
|
+
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
4
|
+
export declare class KvStoreLocalProvider implements StorageProvider {
|
|
5
|
+
constructor(storeFile: string, computeAppDir: string);
|
|
6
|
+
readonly storeFile: string;
|
|
7
|
+
readonly computeAppDir: string;
|
|
8
|
+
getStorageKeys(prefix?: string): Promise<string[] | null>;
|
|
9
|
+
getStorageEntry(key: string): Promise<StorageEntry | null>;
|
|
10
|
+
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
11
|
+
submitStorageEntry(key: string, filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
12
|
+
deleteStorageEntry(key: string): Promise<void>;
|
|
13
|
+
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
14
|
+
doConcurrentParallel<TObject extends {
|
|
15
|
+
key: string;
|
|
16
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
17
|
+
calculateNumChunks(size: number): number;
|
|
18
|
+
getExistingAssetVariant(_variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=kv-store-local-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kv-store-local-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-local-provider.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,oBAAoB,EAC1B,MAAM,8BAA8B,CAAC;AAoBtC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EAC1B,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,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBtD,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,GACrB,OAAO,CAAC,IAAI,CAAC;IAWhB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIlC,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;CAKzF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { isKvStoreConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
8
|
+
import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
|
|
9
|
+
import { applyKVStoreEntriesChunks, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
10
|
+
import { getLocalKvStoreEntry, getLocalKVStoreKeys, localKvStoreDeleteEntry, localKvStoreSubmitEntry, writeKVStoreEntriesForLocal, } from '../util/kv-store-local-server.js';
|
|
11
|
+
import { concurrentParallel } from '../util/retryable.js';
|
|
12
|
+
import { kvStoreEntryToStorageEntry, } from './kv-store-provider.js';
|
|
13
|
+
export const buildStoreProvider = (config, context) => {
|
|
14
|
+
if (isKvStoreConfigRc(config) && context.localMode) {
|
|
15
|
+
console.log(` Working on local simulated KV Store...`);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const { kvStoreName } = getKvStoreConfigFromRc(config);
|
|
21
|
+
console.log(` | Using KV Store: ${kvStoreName}`);
|
|
22
|
+
const storeFile = path.resolve(config.staticPublisherWorkingDir, `./kvstore.json`);
|
|
23
|
+
return new KvStoreLocalProvider(storeFile, context.computeAppDir);
|
|
24
|
+
};
|
|
25
|
+
export class KvStoreLocalProvider {
|
|
26
|
+
constructor(storeFile, computeAppDir) {
|
|
27
|
+
this.storeFile = storeFile;
|
|
28
|
+
this.computeAppDir = computeAppDir;
|
|
29
|
+
}
|
|
30
|
+
async getStorageKeys(prefix) {
|
|
31
|
+
return await getLocalKVStoreKeys(this.storeFile, prefix);
|
|
32
|
+
}
|
|
33
|
+
async getStorageEntry(key) {
|
|
34
|
+
const kvStoreEntry = await getLocalKvStoreEntry(this.storeFile, key);
|
|
35
|
+
if (kvStoreEntry == null) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return kvStoreEntryToStorageEntry(kvStoreEntry);
|
|
39
|
+
}
|
|
40
|
+
async getStorageEntryInfo(key) {
|
|
41
|
+
const kvStoreEntry = await getLocalKvStoreEntry(this.storeFile, key, true);
|
|
42
|
+
if (kvStoreEntry == null) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return kvStoreEntryToStorageEntry(kvStoreEntry);
|
|
46
|
+
}
|
|
47
|
+
async submitStorageEntry(key, filePath, data, metadata) {
|
|
48
|
+
let fileData;
|
|
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);
|
|
62
|
+
await localKvStoreSubmitEntry(this.storeFile, key, path.relative(this.computeAppDir, filePath), metadata != null ? JSON.stringify(metadata) : undefined);
|
|
63
|
+
}
|
|
64
|
+
async deleteStorageEntry(key) {
|
|
65
|
+
await localKvStoreDeleteEntry(this.storeFile, key);
|
|
66
|
+
}
|
|
67
|
+
async applyBatch(batch) {
|
|
68
|
+
console.log(`🍪 Chunking large files...`);
|
|
69
|
+
await applyKVStoreEntriesChunks(batch.storageProviderBatchEntries, KV_STORE_CHUNK_SIZE);
|
|
70
|
+
console.log(`✅ Large files have been chunked.`);
|
|
71
|
+
console.log(`📝 Writing local server KV Store entries.`);
|
|
72
|
+
writeKVStoreEntriesForLocal(this.storeFile, this.computeAppDir, batch.storageProviderBatchEntries);
|
|
73
|
+
console.log(`✅ Wrote KV Store entries for local server.`);
|
|
74
|
+
}
|
|
75
|
+
async doConcurrentParallel(objects, fn, maxConcurrent) {
|
|
76
|
+
await concurrentParallel(objects, fn, () => null, maxConcurrent);
|
|
77
|
+
}
|
|
78
|
+
calculateNumChunks(size) {
|
|
79
|
+
return Math.ceil(size / KV_STORE_CHUNK_SIZE);
|
|
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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type AssetVariantMetadata } from '../../models/assets/index.js';
|
|
2
|
+
import { type FastlyApiContext } from '../util/api-token.js';
|
|
3
|
+
import { type KvStoreEntryInfo } from '../util/kv-store.js';
|
|
4
|
+
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch } from './storage-provider.js';
|
|
5
|
+
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
6
|
+
export declare class KvStoreProvider implements StorageProvider {
|
|
7
|
+
constructor(storeName: string, fastlyApiToken: string);
|
|
8
|
+
fastlyApiContext: FastlyApiContext;
|
|
9
|
+
kvStoreName: string;
|
|
10
|
+
getStorageKeys(prefix?: string): Promise<string[] | null>;
|
|
11
|
+
getStorageEntry(key: string): Promise<StorageEntry | null>;
|
|
12
|
+
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
13
|
+
submitStorageEntry(key: string, _filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
14
|
+
deleteStorageEntry(key: string): Promise<void>;
|
|
15
|
+
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
16
|
+
doConcurrentParallel<TObject extends {
|
|
17
|
+
key: string;
|
|
18
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
19
|
+
calculateNumChunks(size: number): number;
|
|
20
|
+
getExistingAssetVariant(variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
21
|
+
}
|
|
22
|
+
export declare function kvStoreEntryToStorageEntry(kvStoreEntry: KvStoreEntryInfo): StorageEntry;
|
|
23
|
+
export declare function parseKvStoreMetadata(metadata: string): Record<string, string> | null;
|
|
24
|
+
//# sourceMappingURL=kv-store-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kv-store-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-provider.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAQtC,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EACL,KAAK,gBAAgB,EAMtB,MAAM,qBAAqB,CAAC;AAQ7B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EAC1B,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,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BtD,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,GACzB,OAAO,CAAC,IAAI,CAAC;IAkBhB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIlC,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;CA8DxF;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,gBAAgB,gBAuB/B;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,iCAiCpD"}
|