@fastly/compute-js-static-publish 8.0.0-beta.1 → 8.0.0-beta.11
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 +19 -5
- package/README.short.md +19 -5
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +16 -22
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +12 -21
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +6 -13
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +11 -20
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +11 -20
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +11 -20
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +6 -13
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +142 -92
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +53 -31
- package/build/cli/cli/compression/brotli.d.ts +2 -1
- package/build/cli/cli/compression/brotli.d.ts.map +1 -1
- package/build/cli/cli/compression/brotli.js +15 -4
- package/build/cli/cli/compression/gzip.d.ts +2 -1
- package/build/cli/cli/compression/gzip.d.ts.map +1 -1
- package/build/cli/cli/compression/gzip.js +8 -4
- package/build/cli/cli/compression/index.d.ts +4 -1
- package/build/cli/cli/compression/index.d.ts.map +1 -1
- package/build/cli/cli/index.js +8 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +4 -5
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-local-provider.js +4 -7
- package/build/cli/cli/storage/kv-store-provider.d.ts +5 -5
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +39 -65
- package/build/cli/cli/storage/s3-storage-provider.d.ts +7 -6
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +76 -48
- package/build/cli/cli/storage/storage-provider.d.ts +8 -8
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/util/config.d.ts.map +1 -1
- package/build/cli/cli/util/config.js +27 -11
- package/build/cli/cli/util/content-types.d.ts.map +1 -1
- package/build/cli/cli/util/content-types.js +4 -1
- package/build/cli/cli/util/kv-store-items.d.ts +12 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-items.js +49 -0
- package/build/cli/cli/util/kv-store.d.ts +6 -0
- package/build/cli/cli/util/kv-store.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store.js +39 -2
- package/build/cli/cli/util/purge.d.ts +3 -0
- package/build/cli/cli/util/purge.d.ts.map +1 -0
- package/build/cli/cli/util/purge.js +23 -0
- package/build/cli/cli/util/retryable.d.ts +2 -1
- package/build/cli/cli/util/retryable.d.ts.map +1 -1
- package/build/cli/cli/util/retryable.js +34 -1
- package/build/cli/cli/util/s3-credentials.d.ts +11 -0
- package/build/cli/cli/util/s3-credentials.d.ts.map +1 -0
- package/build/cli/cli/util/s3-credentials.js +38 -0
- package/build/cli/cli/util/s3.d.ts +1 -1
- package/build/cli/cli/util/s3.d.ts.map +1 -1
- package/build/cli/cli/util/s3.js +1 -1
- package/build/cli/cli/util/variants.d.ts +2 -1
- package/build/cli/cli/util/variants.d.ts.map +1 -1
- package/build/cli/cli/util/variants.js +8 -4
- package/build/cli/models/assets/index.js +1 -1
- package/build/cli/models/config/publish-content-config.d.ts +2 -0
- package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
- package/build/cli/models/config/s3-storage-config.d.ts +1 -0
- package/build/cli/models/config/s3-storage-config.d.ts.map +1 -1
- package/build/cli/models/config/s3-storage-config.js +1 -0
- package/build/cli/models/config/static-publish-rc.d.ts +1 -0
- package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-rc.js +3 -1
- package/build/cli/models/metadata/index.js +1 -1
- package/build/server/models/assets/index.js +1 -1
- package/build/server/models/config/publish-content-config.d.ts +2 -0
- package/build/server/models/config/publish-content-config.d.ts.map +1 -1
- package/build/server/models/config/s3-storage-config.d.ts +1 -0
- package/build/server/models/config/s3-storage-config.d.ts.map +1 -1
- package/build/server/models/config/s3-storage-config.js +1 -0
- package/build/server/models/config/static-publish-rc.d.ts +1 -0
- package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/server/models/config/static-publish-rc.js +3 -1
- package/build/server/models/metadata/index.js +1 -1
- package/build/server/server/index.d.ts +1 -1
- package/build/server/server/index.d.ts.map +1 -1
- package/build/server/server/index.js +1 -1
- package/build/server/server/publisher-server/index.js +2 -2
- package/build/server/server/storage/s3-storage-provider.d.ts +19 -15
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.js +52 -38
- package/build/server/server/storage/storage-provider.d.ts +1 -1
- package/build/server/server/storage/storage-provider.d.ts.map +1 -1
- package/package.json +2 -3
- package/build/cli/cli/util/aws-credentials.d.ts +0 -12
- package/build/cli/cli/util/aws-credentials.d.ts.map +0 -1
- package/build/cli/cli/util/aws-credentials.js +0 -67
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type ContentCompressionTypes } from '../../models/compression/index.js';
|
|
2
|
-
export type
|
|
2
|
+
export type CompressOptions = {
|
|
3
|
+
brotliQuality?: number;
|
|
4
|
+
};
|
|
5
|
+
export type CompressAlg = (src: string, dest: string, options?: CompressOptions) => Promise<void>;
|
|
3
6
|
declare const algs: Record<ContentCompressionTypes, CompressAlg>;
|
|
4
7
|
export { algs };
|
|
5
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +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;
|
|
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,eAAe,GAAG;IAE5B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAElG,QAAA,MAAM,IAAI,EAAE,MAAM,CAAC,uBAAuB,EAAE,WAAW,CAGtD,CAAC;AAEF,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/build/cli/cli/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
5
5
|
*/
|
|
6
6
|
import fs from 'node:fs';
|
|
7
|
+
import { availableParallelism } from 'node:os';
|
|
7
8
|
import * as scaffoldCommand from './commands/scaffold/index.js';
|
|
8
9
|
import * as manageCommands from './commands/manage/index.js';
|
|
9
10
|
// Register storage builder providers
|
|
@@ -14,6 +15,13 @@ import * as s3StorageProvider from './storage/s3-storage-provider.js';
|
|
|
14
15
|
registerStorageProviderBuilder(kvStoreProvider.buildStoreProvider);
|
|
15
16
|
registerStorageProviderBuilder(kvStoreLocalProvider.buildStoreProvider);
|
|
16
17
|
registerStorageProviderBuilder(s3StorageProvider.buildStoreProvider);
|
|
18
|
+
// Compression runs on the libuv thread pool, which has 4 threads by default.
|
|
19
|
+
// Use more threads on machines with more cores. libuv reads this value when it
|
|
20
|
+
// first uses the pool, so set it before any async work. A value that the user
|
|
21
|
+
// sets is kept.
|
|
22
|
+
if (process.env.UV_THREADPOOL_SIZE == null) {
|
|
23
|
+
process.env.UV_THREADPOOL_SIZE = String(Math.max(4, Math.min(availableParallelism(), 16)));
|
|
24
|
+
}
|
|
17
25
|
if (!fs.existsSync('./static-publish.rc.js')) {
|
|
18
26
|
console.log("🧑💻Fastly Compute JavaScript Static Publisher (Scaffolding mode)");
|
|
19
27
|
await scaffoldCommand.action(process.argv);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch } from './storage-provider.js';
|
|
1
|
+
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type ApplyBatchOptions } from './storage-provider.js';
|
|
3
2
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
4
3
|
export declare class KvStoreLocalProvider implements StorageProvider {
|
|
5
4
|
constructor(storeFile: string, computeAppDir: string);
|
|
@@ -10,11 +9,11 @@ export declare class KvStoreLocalProvider implements StorageProvider {
|
|
|
10
9
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
11
10
|
submitStorageEntry(key: string, filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
12
11
|
deleteStorageEntry(key: string): Promise<void>;
|
|
13
|
-
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
12
|
+
applyBatch(batch: StorageProviderBatch, _options?: ApplyBatchOptions): Promise<void>;
|
|
14
13
|
doConcurrentParallel<TObject extends {
|
|
15
14
|
key: string;
|
|
16
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
15
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
17
16
|
calculateNumChunks(size: number): number;
|
|
18
|
-
|
|
17
|
+
purgeSurrogateKey(_surrogateKey: string): Promise<void>;
|
|
19
18
|
}
|
|
20
19
|
//# sourceMappingURL=kv-store-local-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-local-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-local-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kv-store-local-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-local-provider.ts"],"names":[],"mappings":"AA0BA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAK/B,eAAO,MAAM,kBAAkB,EAAE,sBAkBhC,CAAC;AAEF,qBAAa,oBAAqB,YAAW,eAAe;gBAExD,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM;IAMvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAEzB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAQzD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAc1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAe9D,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAsBV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,QAAQ,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBxF,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,CAAC,EAAE,MAAM,EACtB,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAYhB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIlC,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAE9D"}
|
|
@@ -64,7 +64,7 @@ export class KvStoreLocalProvider {
|
|
|
64
64
|
async deleteStorageEntry(key) {
|
|
65
65
|
await localKvStoreDeleteEntry(this.storeFile, key);
|
|
66
66
|
}
|
|
67
|
-
async applyBatch(batch) {
|
|
67
|
+
async applyBatch(batch, _options = {}) {
|
|
68
68
|
console.log(`🍪 Chunking large files...`);
|
|
69
69
|
await applyKVStoreEntriesChunks(batch.storageProviderBatchEntries, KV_STORE_CHUNK_SIZE);
|
|
70
70
|
console.log(`✅ Large files have been chunked.`);
|
|
@@ -72,15 +72,12 @@ export class KvStoreLocalProvider {
|
|
|
72
72
|
writeKVStoreEntriesForLocal(this.storeFile, this.computeAppDir, batch.storageProviderBatchEntries);
|
|
73
73
|
console.log(`✅ Wrote KV Store entries for local server.`);
|
|
74
74
|
}
|
|
75
|
-
async doConcurrentParallel(objects, fn, maxConcurrent) {
|
|
76
|
-
await concurrentParallel(objects, fn, () => null, maxConcurrent);
|
|
75
|
+
async doConcurrentParallel(objects, fn, maxConcurrent, throwOnError = false) {
|
|
76
|
+
await concurrentParallel(objects, fn, () => null, maxConcurrent, throwOnError);
|
|
77
77
|
}
|
|
78
78
|
calculateNumChunks(size) {
|
|
79
79
|
return Math.ceil(size / KV_STORE_CHUNK_SIZE);
|
|
80
80
|
}
|
|
81
|
-
async
|
|
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;
|
|
81
|
+
async purgeSurrogateKey(_surrogateKey) {
|
|
85
82
|
}
|
|
86
83
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type AssetVariantMetadata } from '../../models/assets/index.js';
|
|
2
1
|
import { type FastlyApiContext } from '../util/api-token.js';
|
|
3
2
|
import { type KvStoreEntryInfo } from '../util/kv-store.js';
|
|
4
|
-
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch } from './storage-provider.js';
|
|
3
|
+
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type StorageProviderBatchEntry, type ApplyBatchOptions } from './storage-provider.js';
|
|
5
4
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
6
5
|
export declare class KvStoreProvider implements StorageProvider {
|
|
7
6
|
constructor(storeName: string, fastlyApiToken: string);
|
|
@@ -12,12 +11,13 @@ export declare class KvStoreProvider implements StorageProvider {
|
|
|
12
11
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
13
12
|
submitStorageEntry(key: string, _filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
14
13
|
deleteStorageEntry(key: string): Promise<void>;
|
|
15
|
-
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
14
|
+
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
15
|
+
uploadEntries(entries: StorageProviderBatchEntry[]): Promise<void>;
|
|
16
16
|
doConcurrentParallel<TObject extends {
|
|
17
17
|
key: string;
|
|
18
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
18
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
19
19
|
calculateNumChunks(size: number): number;
|
|
20
|
-
|
|
20
|
+
purgeSurrogateKey(_surrogateKey: string): Promise<void>;
|
|
21
21
|
}
|
|
22
22
|
export declare function kvStoreEntryToStorageEntry(kvStoreEntry: KvStoreEntryInfo): StorageEntry;
|
|
23
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":"
|
|
1
|
+
{"version":3,"file":"kv-store-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-provider.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EACL,KAAK,gBAAgB,EAMtB,MAAM,qBAAqB,CAAC;AAY7B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,kBAAkB,EAAE,sBAsBhC,CAAC;AAEF,qBAAa,eAAgB,YAAW,eAAe;gBAEnD,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM;IAMxB,gBAAgB,EA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,0BAA0B,CACxC,YAAY,EAAE,gBAAgB,gBAuB/B;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,iCAiCpD"}
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
-
import { decodeAssetVariantMetadata, } from '../../models/assets/index.js';
|
|
7
6
|
import { isKvStoreConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
8
7
|
import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
|
|
9
8
|
import { FetchError, loadApiToken, } from '../util/api-token.js';
|
|
10
9
|
import { rootRelative, } from '../util/files.js';
|
|
11
|
-
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry, kvStoreSubmitEntry,
|
|
12
|
-
import { applyKVStoreEntriesChunks, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
13
|
-
import { concurrentParallel, } from '../util/retryable.js';
|
|
10
|
+
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry, kvStoreSubmitEntry, kvStoreSubmitBatch, } from '../util/kv-store.js';
|
|
11
|
+
import { applyKVStoreEntriesChunks, packNdjsonBatches, ndjsonLineForBatchEntry, entriesToUpload, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
12
|
+
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
14
13
|
export const buildStoreProvider = (config, context) => {
|
|
15
14
|
if (isKvStoreConfigRc(config) && !context.localMode) {
|
|
16
15
|
console.log(` Working on the Fastly KV Store...`);
|
|
@@ -55,20 +54,43 @@ export class KvStoreProvider {
|
|
|
55
54
|
async deleteStorageEntry(key) {
|
|
56
55
|
await kvStoreDeleteEntry(this.fastlyApiContext, this.kvStoreName, key);
|
|
57
56
|
}
|
|
58
|
-
async applyBatch(batch) {
|
|
57
|
+
async applyBatch(batch, options = {}) {
|
|
58
|
+
const { existingKeys } = options;
|
|
59
59
|
console.log(`🍪 Chunking large files...`);
|
|
60
60
|
await applyKVStoreEntriesChunks(batch.storageProviderBatchEntries, KV_STORE_CHUNK_SIZE);
|
|
61
61
|
console.log(`✅ Large files have been chunked.`);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
let toWrite = batch.storageProviderBatchEntries;
|
|
63
|
+
if (existingKeys != null) {
|
|
64
|
+
toWrite = entriesToUpload(toWrite, existingKeys);
|
|
65
|
+
console.log(` | ${batch.storageProviderBatchEntries.length - toWrite.length} chunk(s) already present in the KV Store.`);
|
|
66
|
+
}
|
|
67
|
+
console.log(`📤 Uploading ${toWrite.length} entries to KV Store.`);
|
|
68
|
+
await this.uploadEntries(toWrite);
|
|
69
|
+
console.log(`✅ Uploaded entries to KV Store.`);
|
|
70
|
+
}
|
|
71
|
+
async uploadEntries(entries) {
|
|
72
|
+
const { batches, oversized } = packNdjsonBatches(entries);
|
|
73
|
+
await this.doConcurrentParallel(oversized, async ({ filePath, metadataJson }, key) => {
|
|
65
74
|
const fileBytes = fs.readFileSync(filePath);
|
|
66
75
|
await kvStoreSubmitEntry(this.fastlyApiContext, this.kvStoreName, key, fileBytes, metadataJson != null ? JSON.stringify(metadataJson) : undefined);
|
|
67
|
-
console.log(` 🌐 Submitted asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
|
|
68
|
-
});
|
|
69
|
-
|
|
76
|
+
console.log(` 🌐 Submitted large asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
|
|
77
|
+
}, 12, true);
|
|
78
|
+
await this.doConcurrentParallel(batches, async (batch, key) => {
|
|
79
|
+
const lines = batch.entries.map(ndjsonLineForBatchEntry);
|
|
80
|
+
const failures = await kvStoreSubmitBatch(this.fastlyApiContext, this.kvStoreName, lines);
|
|
81
|
+
if (failures.length > 0) {
|
|
82
|
+
// Keep only the entries that failed. The retry submits only these entries.
|
|
83
|
+
const failedKeys = new Set(failures.map(f => f.key));
|
|
84
|
+
const submittedCount = batch.entries.length;
|
|
85
|
+
batch.entries = batch.entries.filter(entry => failedKeys.has(entry.key));
|
|
86
|
+
const shown = failures.slice(0, 5).map(f => `${f.key} (${f.code ?? 'unknown'}: ${f.reason ?? 'unknown'})`).join(', ');
|
|
87
|
+
const more = failures.length > 5 ? `, and ${failures.length - 5} more` : '';
|
|
88
|
+
throw makeRetryable(new Error(`${failures.length} of ${submittedCount} entries failed: ${shown}${more}`));
|
|
89
|
+
}
|
|
90
|
+
console.log(` 🌐 Submitted ${batch.entries.length} entries to KV Store ("${key}").`);
|
|
91
|
+
}, 12, true);
|
|
70
92
|
}
|
|
71
|
-
async doConcurrentParallel(objects, fn, maxConcurrent = 12) {
|
|
93
|
+
async doConcurrentParallel(objects, fn, maxConcurrent = 12, throwOnError = false) {
|
|
72
94
|
await concurrentParallel(objects, fn, (err) => {
|
|
73
95
|
if (err instanceof FetchError) {
|
|
74
96
|
return `HTTP ${err.status}`;
|
|
@@ -76,64 +98,16 @@ export class KvStoreProvider {
|
|
|
76
98
|
else if (err instanceof TypeError) {
|
|
77
99
|
return 'transport';
|
|
78
100
|
}
|
|
101
|
+
else if (err instanceof Error) {
|
|
102
|
+
return err.message;
|
|
103
|
+
}
|
|
79
104
|
return null;
|
|
80
|
-
}, maxConcurrent);
|
|
105
|
+
}, maxConcurrent, throwOnError);
|
|
81
106
|
}
|
|
82
107
|
calculateNumChunks(size) {
|
|
83
108
|
return Math.ceil(size / KV_STORE_CHUNK_SIZE);
|
|
84
109
|
}
|
|
85
|
-
async
|
|
86
|
-
let kvStoreItemMetadata = null;
|
|
87
|
-
const items = [{
|
|
88
|
-
key: variantKey,
|
|
89
|
-
}];
|
|
90
|
-
await this.doConcurrentParallel(items, async (_, variantKey) => {
|
|
91
|
-
// fastlyApiContext is non-null if useKvStore is true
|
|
92
|
-
const kvStoreEntryInfo = await getKvStoreEntryInfo(this.fastlyApiContext, this.kvStoreName, variantKey);
|
|
93
|
-
if (!kvStoreEntryInfo) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
let itemMetadata;
|
|
97
|
-
if (kvStoreEntryInfo.metadata != null) {
|
|
98
|
-
try {
|
|
99
|
-
itemMetadata = JSON.parse(kvStoreEntryInfo.metadata);
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
// if the metadata does not parse successfully as JSON,
|
|
103
|
-
// treat it as though it didn't exist.
|
|
104
|
-
}
|
|
105
|
-
itemMetadata = decodeAssetVariantMetadata(itemMetadata);
|
|
106
|
-
}
|
|
107
|
-
if (itemMetadata != null) {
|
|
108
|
-
let exists = false;
|
|
109
|
-
if (itemMetadata.size <= KV_STORE_CHUNK_SIZE) {
|
|
110
|
-
// For an item equal to or smaller than the chunk size, if it exists
|
|
111
|
-
// and its metadata asserts no chunk count, then we assume it exists.
|
|
112
|
-
if (itemMetadata.numChunks === undefined) {
|
|
113
|
-
exists = true;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
// For chunked objects, if the first chunk exists, and its metadata asserts
|
|
118
|
-
// the same number of chunks based on size, then we assume it exists (for now).
|
|
119
|
-
// In the future we might actually check for the existence and sizes of
|
|
120
|
-
// every chunk in the KV Store.
|
|
121
|
-
const expectedNumChunks = Math.ceil(itemMetadata.size / KV_STORE_CHUNK_SIZE);
|
|
122
|
-
if (itemMetadata.numChunks === expectedNumChunks) {
|
|
123
|
-
exists = true;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (exists) {
|
|
127
|
-
kvStoreItemMetadata = {
|
|
128
|
-
contentEncoding: itemMetadata.contentEncoding,
|
|
129
|
-
size: itemMetadata.size,
|
|
130
|
-
hash: itemMetadata.hash,
|
|
131
|
-
numChunks: itemMetadata.numChunks,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
return kvStoreItemMetadata;
|
|
110
|
+
async purgeSurrogateKey(_surrogateKey) {
|
|
137
111
|
}
|
|
138
112
|
}
|
|
139
113
|
export function kvStoreEntryToStorageEntry(kvStoreEntry) {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
2
|
import { type Command, type HttpHandlerOptions } from '@aws-sdk/types';
|
|
3
|
-
import { type
|
|
4
|
-
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch } from './storage-provider.js';
|
|
3
|
+
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type ApplyBatchOptions } from './storage-provider.js';
|
|
5
4
|
type CommandOutput<C> = C extends Command<any, any, any, infer O, any> ? O : never;
|
|
6
5
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
7
6
|
export declare class S3StorageProvider implements StorageProvider {
|
|
8
|
-
constructor(s3Region: string, accessKeyId: string, secretAccessKey: string, s3Bucket: string, s3Endpoint?: string);
|
|
7
|
+
constructor(fastlyServiceId: string | undefined, fastlyApiToken: string | undefined, s3Region: string, accessKeyId: string, secretAccessKey: string, s3Bucket: string, s3Endpoint?: string);
|
|
8
|
+
private readonly fastlyServiceId?;
|
|
9
|
+
private readonly fastlyApiContext?;
|
|
9
10
|
private readonly s3Region;
|
|
10
11
|
private readonly accessKeyId;
|
|
11
12
|
private readonly secretAccessKey;
|
|
@@ -19,12 +20,12 @@ export declare class S3StorageProvider implements StorageProvider {
|
|
|
19
20
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
20
21
|
submitStorageEntry(key: string, _filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
21
22
|
deleteStorageEntry(key: string): Promise<void>;
|
|
22
|
-
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
23
|
+
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
23
24
|
doConcurrentParallel<TObject extends {
|
|
24
25
|
key: string;
|
|
25
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
26
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
26
27
|
calculateNumChunks(_size: number): number;
|
|
27
|
-
|
|
28
|
+
purgeSurrogateKey(surrogateKey: string): Promise<void>;
|
|
28
29
|
}
|
|
29
30
|
export {};
|
|
30
31
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAOA,OAAO,EAUL,QAAQ,EAIT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AASxB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAuB/B,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEnF,eAAO,MAAM,kBAAkB,EAAE,sBAuDhC,CAAC;AAGF,qBAAa,iBAAkB,YAAW,eAAe;gBAErD,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,M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AAG,OAAO,CAAC,IAAI,CAAC;IA+BvF,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,EAC1B,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAmBhB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAInC,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA4B7D"}
|
|
@@ -3,38 +3,58 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, PutObjectCommand, S3Client, S3ServiceException, paginateListObjectsV2, } from '@aws-sdk/client-s3';
|
|
8
8
|
import { isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
9
9
|
import { getS3StorageConfigFromRc, } from '../../models/config/s3-storage-config.js';
|
|
10
|
-
import {
|
|
10
|
+
import { entriesToUpload } from '../util/kv-store-items.js';
|
|
11
|
+
import { loadS3Credentials, } from '../util/s3-credentials.js';
|
|
11
12
|
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
12
13
|
import { rootRelative, } from '../util/files.js';
|
|
14
|
+
import { loadApiToken, } from '../util/api-token.js';
|
|
15
|
+
import { readServiceId, } from '../util/fastly-toml.js';
|
|
16
|
+
import { purgeSurrogateKey, } from '../util/purge.js';
|
|
13
17
|
export const buildStoreProvider = async (config, context) => {
|
|
14
18
|
if (isS3StorageConfigRc(config)) {
|
|
15
|
-
console.log(` Working on S3 (or compatible) storage...`);
|
|
19
|
+
console.log(` Working on S3 (or compatible) storage (BETA)...`);
|
|
16
20
|
}
|
|
17
21
|
else {
|
|
18
22
|
return null;
|
|
19
23
|
}
|
|
20
24
|
const { region, bucket, endpoint, } = getS3StorageConfigFromRc(config);
|
|
21
|
-
console.log(` | Using S3 storage`);
|
|
25
|
+
console.log(` | Using S3 storage (BETA)`);
|
|
22
26
|
console.log(` Region : ${region}`);
|
|
23
27
|
console.log(` Bucket : ${bucket}`);
|
|
24
28
|
console.log(` Endpoint: ${endpoint ?? 'default'}`);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
awsSecretAccessKey: context.awsSecretAccessKey,
|
|
29
|
+
const s3CredentialsResult = await loadS3Credentials({
|
|
30
|
+
s3AccessKeyId: context.s3AccessKeyId,
|
|
31
|
+
s3SecretAccessKey: context.s3SecretAccessKey,
|
|
29
32
|
});
|
|
30
|
-
if (
|
|
31
|
-
throw new Error("❌ S3 Credentials not provided.\nProvide an
|
|
33
|
+
if (s3CredentialsResult == null) {
|
|
34
|
+
throw new Error("❌ S3 Credentials not provided.\nProvide an access key ID and secret access key that have write access to the S3 or compatible storage.\nRefer to the README file and --help for additional information.");
|
|
32
35
|
}
|
|
33
|
-
console.log(`✔️ S3 Credentials: ${
|
|
34
|
-
|
|
36
|
+
console.log(`✔️ S3 Credentials: ${s3CredentialsResult.s3AccessKeyId.slice(0, 4)}${'*'.repeat(s3CredentialsResult.s3AccessKeyId.length - 4)} from '${s3CredentialsResult.source}'`);
|
|
37
|
+
const fastlyTomlPath = path.resolve(context.computeAppDir, 'fastly.toml');
|
|
38
|
+
const serviceId = readServiceId(fastlyTomlPath);
|
|
39
|
+
let apiToken = undefined;
|
|
40
|
+
if (serviceId == null) {
|
|
41
|
+
console.log(`- Service ID not found in fastly.toml, application may not have been deployed yet. Will skip purge step after publish.`);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.log(`✔️ Service ID from fastly.toml: ${serviceId}`);
|
|
45
|
+
const apiTokenResult = loadApiToken({ commandLine: context.fastlyApiToken });
|
|
46
|
+
if (apiTokenResult == null) {
|
|
47
|
+
throw new Error("❌ Fastly API Token not provided.\nSet the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
48
|
+
}
|
|
49
|
+
console.log(`✔️ Fastly API Token: ${apiTokenResult.apiToken.slice(0, 4)}${'*'.repeat(apiTokenResult.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
50
|
+
apiToken = apiTokenResult.apiToken;
|
|
51
|
+
}
|
|
52
|
+
return new S3StorageProvider(serviceId, apiToken, region, s3CredentialsResult.s3AccessKeyId, s3CredentialsResult.s3SecretAccessKey, bucket, endpoint);
|
|
35
53
|
};
|
|
36
54
|
export class S3StorageProvider {
|
|
37
|
-
constructor(s3Region, accessKeyId, secretAccessKey, s3Bucket, s3Endpoint) {
|
|
55
|
+
constructor(fastlyServiceId, fastlyApiToken, s3Region, accessKeyId, secretAccessKey, s3Bucket, s3Endpoint) {
|
|
56
|
+
this.fastlyServiceId = fastlyServiceId;
|
|
57
|
+
this.fastlyApiContext = fastlyApiToken != null ? { apiToken: fastlyApiToken } : undefined;
|
|
38
58
|
this.s3Region = s3Region;
|
|
39
59
|
this.accessKeyId = accessKeyId;
|
|
40
60
|
this.secretAccessKey = secretAccessKey;
|
|
@@ -69,20 +89,26 @@ export class S3StorageProvider {
|
|
|
69
89
|
}
|
|
70
90
|
}
|
|
71
91
|
async getStorageKeys(prefix) {
|
|
92
|
+
const paginationConfig = {
|
|
93
|
+
client: this.getS3Client(),
|
|
94
|
+
};
|
|
72
95
|
const input = {
|
|
73
96
|
Bucket: this.s3Bucket,
|
|
74
|
-
MaxKeys: 4096,
|
|
75
97
|
Prefix: prefix,
|
|
76
|
-
ContinuationToken: undefined, // pagination
|
|
77
98
|
};
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
99
|
+
const paginator = paginateListObjectsV2(paginationConfig, input);
|
|
100
|
+
const objectKeys = [];
|
|
101
|
+
for await (const { Contents } of paginator) {
|
|
102
|
+
if (Contents == null) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
for (const obj of Contents) {
|
|
106
|
+
if (obj.Key != null) {
|
|
107
|
+
objectKeys.push(obj.Key);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
82
110
|
}
|
|
83
|
-
return
|
|
84
|
-
.map(c => c.Key)
|
|
85
|
-
.filter(c => c != null);
|
|
111
|
+
return objectKeys.length > 0 ? objectKeys : null;
|
|
86
112
|
}
|
|
87
113
|
async getStorageEntry(key) {
|
|
88
114
|
const input = {
|
|
@@ -152,18 +178,23 @@ export class S3StorageProvider {
|
|
|
152
178
|
const command = new DeleteObjectCommand(input);
|
|
153
179
|
await this.sendS3ClientCommand(command);
|
|
154
180
|
}
|
|
155
|
-
async applyBatch(batch) {
|
|
181
|
+
async applyBatch(batch, options = {}) {
|
|
182
|
+
const { existingKeys } = options;
|
|
183
|
+
let toWrite = batch.storageProviderBatchEntries;
|
|
184
|
+
if (existingKeys != null) {
|
|
185
|
+
toWrite = entriesToUpload(toWrite, existingKeys);
|
|
186
|
+
}
|
|
156
187
|
console.log(`📤 Uploading entries to S3 storage.`);
|
|
157
188
|
// fastlyApiContext is non-null if useKvStore is true
|
|
158
|
-
await this.doConcurrentParallel(
|
|
189
|
+
await this.doConcurrentParallel(toWrite, async ({ filePath, metadataJson }, key) => {
|
|
159
190
|
// const fileStream = fs.createReadStream(filePath);
|
|
160
191
|
const fileData = fs.readFileSync(filePath);
|
|
161
192
|
await this.submitStorageEntry(key, filePath, fileData, metadataJson);
|
|
162
193
|
console.log(` 🌐 Submitted asset "${rootRelative(filePath)}" to S3 storage with key "${key}".`);
|
|
163
|
-
});
|
|
194
|
+
}, 12, true);
|
|
164
195
|
console.log(`✅ Uploaded entries to S3 storage.`);
|
|
165
196
|
}
|
|
166
|
-
async doConcurrentParallel(objects, fn, maxConcurrent = 12) {
|
|
197
|
+
async doConcurrentParallel(objects, fn, maxConcurrent = 12, throwOnError = false) {
|
|
167
198
|
await concurrentParallel(objects, fn, (err) => {
|
|
168
199
|
if (err instanceof S3ServiceException) {
|
|
169
200
|
return `S3 error [${err.name}] - ${err.message}`;
|
|
@@ -172,30 +203,27 @@ export class S3StorageProvider {
|
|
|
172
203
|
return 'transport';
|
|
173
204
|
}
|
|
174
205
|
return null;
|
|
175
|
-
}, maxConcurrent);
|
|
206
|
+
}, maxConcurrent, throwOnError);
|
|
176
207
|
}
|
|
177
208
|
calculateNumChunks(_size) {
|
|
178
209
|
return 1;
|
|
179
210
|
}
|
|
180
|
-
async
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
return assetVariantMetadata;
|
|
211
|
+
async purgeSurrogateKey(surrogateKey) {
|
|
212
|
+
if (this.fastlyServiceId == null) {
|
|
213
|
+
console.log('Fastly Service ID not set, skipping purge...');
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (this.fastlyApiContext?.apiToken == null) {
|
|
217
|
+
console.log('Fastly API token not set, skipping purge...');
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
console.log(`Purging surrogate key [${surrogateKey}] on service [${this.fastlyServiceId}]...`);
|
|
221
|
+
const result = await purgeSurrogateKey(this.fastlyApiContext, this.fastlyServiceId, surrogateKey, true);
|
|
222
|
+
if (result) {
|
|
223
|
+
console.log('Purged');
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
console.log('Failed purging');
|
|
227
|
+
}
|
|
200
228
|
}
|
|
201
229
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type AssetVariantMetadata } from '../../models/assets/index.js';
|
|
2
1
|
import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
|
|
3
2
|
export interface StorageEntry {
|
|
4
3
|
data?: ReadableStream<Uint8Array>;
|
|
@@ -11,20 +10,22 @@ export interface StorageProvider {
|
|
|
11
10
|
getStorageEntry(key: string): Promise<StorageEntry | null>;
|
|
12
11
|
submitStorageEntry(key: string, filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
13
12
|
deleteStorageEntry(key: string): Promise<void>;
|
|
14
|
-
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
13
|
+
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
15
14
|
doConcurrentParallel<TObject extends {
|
|
16
15
|
key: string;
|
|
17
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
16
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
18
17
|
calculateNumChunks(size: number): number;
|
|
19
|
-
|
|
18
|
+
purgeSurrogateKey(surrogateKey: string): Promise<void>;
|
|
20
19
|
}
|
|
21
20
|
export type StorageProviderBatchEntry = {
|
|
22
|
-
write: boolean;
|
|
23
21
|
size: number;
|
|
24
22
|
key: string;
|
|
25
23
|
filePath: string;
|
|
26
24
|
metadataJson?: Record<string, string>;
|
|
27
25
|
};
|
|
26
|
+
export type ApplyBatchOptions = {
|
|
27
|
+
existingKeys?: Set<string>;
|
|
28
|
+
};
|
|
28
29
|
export declare class StorageProviderBatch {
|
|
29
30
|
constructor();
|
|
30
31
|
storageProviderBatchEntries: StorageProviderBatchEntry[];
|
|
@@ -34,9 +35,8 @@ export type StorageProviderBuilderContext = {
|
|
|
34
35
|
computeAppDir: string;
|
|
35
36
|
localMode?: boolean;
|
|
36
37
|
fastlyApiToken?: string;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
awsSecretAccessKey?: string;
|
|
38
|
+
s3AccessKeyId?: string;
|
|
39
|
+
s3SecretAccessKey?: string;
|
|
40
40
|
};
|
|
41
41
|
export type StorageProviderBuilder = (config: StaticPublishRc, context: StorageProviderBuilderContext) => (Promise<StorageProvider | null> | StorageProvider | null);
|
|
42
42
|
export declare function registerStorageProviderBuilder(builder: StorageProviderBuilder): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,
|
|
1
|
+
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"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;CAC3C;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC/D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC3D,kBAAkB,CAChB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,G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CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,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;AAGlI,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,QAE7E;AAED,wBAAsB,sCAAsC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,4BAS3H"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/config.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,0CAA0C,CAAC;AAOlD,OAAO,EACL,KAAK,8BAA8B,EAEpC,MAAM,+CAA+C,CAAC;AAOvD,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AAEtG,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;gBAEL,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;CAIrD;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,eAAe,CAAC,CA+B1E;AAGD,eAAO,MAAM,0BAA0B,6DAmErC,CAAC;AAEH,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA6B9G;AA4CD,eAAO,MAAM,6BAA6B,4EAsKxC,CAAC;AAEH,eAAO,MAAM,8BAA8B,6EAkIzC,CAAC"}
|