@fastly/compute-js-static-publish 7.0.0-beta.1 → 7.0.0-beta.3
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 +11 -3
- package/README.short.md +11 -3
- package/build/cli/commands/manage/clean.d.ts +2 -0
- package/build/cli/commands/manage/clean.d.ts.map +1 -0
- package/build/cli/commands/manage/clean.js +277 -0
- package/build/cli/commands/manage/collections/delete.d.ts +2 -0
- package/build/cli/commands/manage/collections/delete.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/delete.js +180 -0
- package/build/cli/commands/manage/collections/index.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/index.js +63 -0
- package/build/cli/commands/manage/collections/list.d.ts +2 -0
- package/build/cli/commands/manage/collections/list.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/list.js +191 -0
- package/build/cli/commands/manage/collections/promote.d.ts +2 -0
- package/build/cli/commands/manage/collections/promote.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/promote.js +247 -0
- package/build/cli/commands/manage/collections/update-expiration.d.ts +2 -0
- package/build/cli/commands/manage/collections/update-expiration.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/update-expiration.js +215 -0
- package/build/cli/commands/manage/index.d.ts.map +1 -0
- package/build/cli/commands/{index.js → manage/index.js} +36 -34
- package/build/cli/commands/manage/publish-content.d.ts +2 -0
- package/build/cli/commands/manage/publish-content.d.ts.map +1 -0
- package/build/cli/commands/{publish-content.js → manage/publish-content.js} +186 -85
- package/build/cli/commands/{init-app.d.ts → scaffold/index.d.ts} +2 -2
- package/build/cli/commands/scaffold/index.d.ts.map +1 -0
- package/build/cli/commands/{init-app.js → scaffold/index.js} +80 -31
- package/build/cli/index.js +11 -3
- package/build/cli/util/api-token.d.ts.map +1 -0
- package/build/cli/{fastly-api → util}/api-token.js +8 -2
- package/build/cli/util/args.d.ts +16 -2
- package/build/cli/util/args.d.ts.map +1 -1
- package/build/cli/util/args.js +32 -6
- package/build/cli/util/config.d.ts.map +1 -1
- package/build/cli/util/config.js +19 -19
- package/build/cli/util/fastly-toml.d.ts +2 -0
- package/build/cli/util/fastly-toml.d.ts.map +1 -0
- package/build/cli/util/fastly-toml.js +15 -0
- package/build/cli/util/kv-store-items.d.ts +3 -2
- package/build/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/util/kv-store-items.js +7 -13
- package/build/cli/util/kv-store-local-server.d.ts +8 -0
- package/build/cli/util/kv-store-local-server.d.ts.map +1 -1
- package/build/cli/util/kv-store-local-server.js +76 -0
- package/build/cli/{fastly-api → util}/kv-store.d.ts +6 -6
- package/build/cli/util/kv-store.d.ts.map +1 -0
- package/build/cli/{fastly-api → util}/kv-store.js +4 -4
- package/build/cli/util/node.d.ts +2 -0
- package/build/cli/util/node.d.ts.map +1 -0
- package/build/cli/util/node.js +10 -0
- package/build/models/config/publish-content-config.d.ts +0 -2
- package/build/models/config/publish-content-config.d.ts.map +1 -1
- package/build/models/config/static-publish-rc.d.ts +1 -0
- package/build/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/models/server/index.d.ts +5 -0
- package/build/models/server/index.d.ts.map +1 -0
- package/build/models/server/index.js +1 -0
- package/build/models/time/index.d.ts +8 -0
- package/build/models/time/index.d.ts.map +1 -0
- package/build/models/time/index.js +54 -0
- package/build/server/publisher-server/index.d.ts +2 -0
- package/build/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/publisher-server/index.js +34 -3
- package/package.json +3 -2
- package/build/cli/commands/clean.d.ts +0 -2
- package/build/cli/commands/clean.d.ts.map +0 -1
- package/build/cli/commands/clean.js +0 -121
- package/build/cli/commands/collections/delete.d.ts +0 -2
- package/build/cli/commands/collections/delete.d.ts.map +0 -1
- package/build/cli/commands/collections/delete.js +0 -88
- package/build/cli/commands/collections/index.d.ts.map +0 -1
- package/build/cli/commands/collections/index.js +0 -52
- package/build/cli/commands/collections/list.d.ts +0 -2
- package/build/cli/commands/collections/list.d.ts.map +0 -1
- package/build/cli/commands/collections/list.js +0 -62
- package/build/cli/commands/index.d.ts.map +0 -1
- package/build/cli/commands/init-app.d.ts.map +0 -1
- package/build/cli/commands/publish-content.d.ts +0 -2
- package/build/cli/commands/publish-content.d.ts.map +0 -1
- package/build/cli/fastly-api/api-token.d.ts.map +0 -1
- package/build/cli/fastly-api/kv-store.d.ts.map +0 -1
- /package/build/cli/commands/{collections → manage/collections}/index.d.ts +0 -0
- /package/build/cli/commands/{index.d.ts → manage/index.d.ts} +0 -0
- /package/build/cli/{fastly-api → util}/api-token.d.ts +0 -0
|
@@ -4,6 +4,82 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
+
export async function getLocalKVStoreKeys(storeFile, prefix) {
|
|
8
|
+
let store;
|
|
9
|
+
try {
|
|
10
|
+
// If the local KV store file exists, we have to add to it.
|
|
11
|
+
const storeFileJson = fs.readFileSync(storeFile, 'utf-8');
|
|
12
|
+
store = JSON.parse(storeFileJson);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
store = {};
|
|
16
|
+
}
|
|
17
|
+
let keys = Object.keys(store);
|
|
18
|
+
if (prefix != null) {
|
|
19
|
+
keys = keys.filter(key => key.startsWith(prefix));
|
|
20
|
+
}
|
|
21
|
+
return keys;
|
|
22
|
+
}
|
|
23
|
+
export async function getLocalKvStoreEntry(storeFile, key, metadataOnly) {
|
|
24
|
+
let store;
|
|
25
|
+
try {
|
|
26
|
+
// If the local KV store file exists, we have to add to it.
|
|
27
|
+
const storeFileJson = fs.readFileSync(storeFile, 'utf-8');
|
|
28
|
+
store = JSON.parse(storeFileJson);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
store = {};
|
|
32
|
+
}
|
|
33
|
+
const obj = store[key];
|
|
34
|
+
if (obj == null) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
let response;
|
|
38
|
+
if (metadataOnly) {
|
|
39
|
+
response = new Response(null);
|
|
40
|
+
}
|
|
41
|
+
else if ('data' in obj) {
|
|
42
|
+
response = new Response(obj.data);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const fileData = fs.readFileSync(obj.file);
|
|
46
|
+
response = new Response(fileData);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
metadata: obj.metadata ?? null,
|
|
50
|
+
generation: null,
|
|
51
|
+
response,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export async function localKvStoreSubmitEntry(storeFile, key, file, metadata) {
|
|
55
|
+
let store;
|
|
56
|
+
try {
|
|
57
|
+
// If the local KV store file exists, we have to add to it.
|
|
58
|
+
const storeFileJson = fs.readFileSync(storeFile, 'utf-8');
|
|
59
|
+
store = JSON.parse(storeFileJson);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
store = {};
|
|
63
|
+
}
|
|
64
|
+
store[key] = {
|
|
65
|
+
file,
|
|
66
|
+
metadata,
|
|
67
|
+
};
|
|
68
|
+
fs.writeFileSync(storeFile, JSON.stringify(store));
|
|
69
|
+
}
|
|
70
|
+
export async function localKvStoreDeleteEntry(storeFile, key) {
|
|
71
|
+
let store;
|
|
72
|
+
try {
|
|
73
|
+
// If the local KV store file exists, we have to add to it.
|
|
74
|
+
const storeFileJson = fs.readFileSync(storeFile, 'utf-8');
|
|
75
|
+
store = JSON.parse(storeFileJson);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
store = {};
|
|
79
|
+
}
|
|
80
|
+
delete store[key];
|
|
81
|
+
fs.writeFileSync(storeFile, JSON.stringify(store));
|
|
82
|
+
}
|
|
7
83
|
export function writeKVStoreEntriesForLocal(storeFile, computeAppDir, kvStoreItemDescriptions) {
|
|
8
84
|
let store;
|
|
9
85
|
try {
|
|
@@ -8,17 +8,17 @@ export declare function getKVStoreIdForName(fastlyApiContext: FastlyApiContext,
|
|
|
8
8
|
export declare function getKVStoreInfos(fastlyApiContext: FastlyApiContext): Promise<KVStoreInfo[]>;
|
|
9
9
|
export declare const _getKVStoreKeys: (fastlyApiContext: FastlyApiContext, operationName: string, kvStoreId: string, prefix?: string | undefined) => Promise<string[]>;
|
|
10
10
|
export declare function getKVStoreKeys(fastlyApiContext: FastlyApiContext, kvStoreName: string, prefix?: string): Promise<string[] | null>;
|
|
11
|
-
export declare function getKvStoreEntryInfo(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<
|
|
11
|
+
export declare function getKvStoreEntryInfo(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<{
|
|
12
12
|
metadata: string | null;
|
|
13
13
|
generation: string | null;
|
|
14
14
|
response: Response;
|
|
15
|
-
}>;
|
|
16
|
-
export declare function getKvStoreEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, metadataOnly?: boolean): Promise<
|
|
15
|
+
} | null>;
|
|
16
|
+
export declare function getKvStoreEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, metadataOnly?: boolean): Promise<{
|
|
17
17
|
metadata: string | null;
|
|
18
18
|
generation: string | null;
|
|
19
19
|
response: Response;
|
|
20
|
-
}>;
|
|
21
|
-
export declare function
|
|
22
|
-
export declare function
|
|
20
|
+
} | null>;
|
|
21
|
+
export declare function kvStoreSubmitEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, data: ReadableStream<Uint8Array> | Uint8Array | string, metadata: string | undefined): Promise<void>;
|
|
22
|
+
export declare function kvStoreDeleteEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<void>;
|
|
23
23
|
export {};
|
|
24
24
|
//# sourceMappingURL=kv-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kv-store.d.ts","sourceRoot":"","sources":["../../../src/cli/util/kv-store.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,KAAK,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAElF,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAmBF,wBAAsB,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,mCAkB9E;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,mBAKhG;AAqCD,wBAAsB,eAAe,CAAC,gBAAgB,EAAE,gBAAgB,0BAcvE;AAED,eAAO,MAAM,eAAe,qBAjDgB,gBAAgB,iBAAiB,MAAM,sEAyDlF,CAAC;AAEF,wBAAsB,cAAc,CAClC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,4BAchB;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;;;;UAI7G;AAED,wBAAsB,eAAe,CACnC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,OAAO;;;;UA8BvB;AAGD,wBAAsB,kBAAkB,CACtC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,EACtD,QAAQ,EAAE,MAAM,GAAG,SAAS,iBAoB7B;AAED,wBAAsB,kBAAkB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,iBAa5G"}
|
|
@@ -78,7 +78,7 @@ export async function getKvStoreEntryInfo(fastlyApiContext, kvStoreName, key) {
|
|
|
78
78
|
export async function getKvStoreEntry(fastlyApiContext, kvStoreName, key, metadataOnly) {
|
|
79
79
|
const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
|
|
80
80
|
if (kvStoreId == null) {
|
|
81
|
-
return
|
|
81
|
+
return null;
|
|
82
82
|
}
|
|
83
83
|
const endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys/${encodeURIComponent(key)}`;
|
|
84
84
|
let response;
|
|
@@ -87,7 +87,7 @@ export async function getKvStoreEntry(fastlyApiContext, kvStoreName, key, metada
|
|
|
87
87
|
}
|
|
88
88
|
catch (err) {
|
|
89
89
|
if (err instanceof FetchError && err.status === 404) {
|
|
90
|
-
return
|
|
90
|
+
return null;
|
|
91
91
|
}
|
|
92
92
|
throw err;
|
|
93
93
|
}
|
|
@@ -100,7 +100,7 @@ export async function getKvStoreEntry(fastlyApiContext, kvStoreName, key, metada
|
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
const encoder = new TextEncoder();
|
|
103
|
-
export async function
|
|
103
|
+
export async function kvStoreSubmitEntry(fastlyApiContext, kvStoreName, key, data, metadata) {
|
|
104
104
|
const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
|
|
105
105
|
if (kvStoreId == null) {
|
|
106
106
|
throw new Error('KV Store not found');
|
|
@@ -116,7 +116,7 @@ export async function kvStoreSubmitFile(fastlyApiContext, kvStoreName, key, data
|
|
|
116
116
|
body,
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
|
-
export async function
|
|
119
|
+
export async function kvStoreDeleteEntry(fastlyApiContext, kvStoreName, key) {
|
|
120
120
|
const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
|
|
121
121
|
if (kvStoreId == null) {
|
|
122
122
|
throw new Error('KV Store not found');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/cli/util/node.ts"],"names":[],"mappings":"AAKA,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,cAAc,CAKtE"}
|
|
@@ -18,7 +18,6 @@ export interface ExcludeDirTest {
|
|
|
18
18
|
export type KVStoreAssetInclusionTest = (assetKey: string, contentType?: string) => boolean;
|
|
19
19
|
export type PublishContentConfig = {
|
|
20
20
|
rootDir: string;
|
|
21
|
-
staticPublisherWorkingDir: string;
|
|
22
21
|
excludeDirs?: (string | ExcludeDirTest)[] | string | ExcludeDirTest | null;
|
|
23
22
|
excludeDotFiles?: boolean;
|
|
24
23
|
includeWellKnown?: boolean;
|
|
@@ -29,7 +28,6 @@ export type PublishContentConfig = {
|
|
|
29
28
|
};
|
|
30
29
|
export type PublishContentConfigNormalized = {
|
|
31
30
|
rootDir: string;
|
|
32
|
-
staticPublisherWorkingDir: string;
|
|
33
31
|
excludeDirs: ExcludeDirTest[];
|
|
34
32
|
excludeDotFiles: boolean;
|
|
35
33
|
includeWellKnown: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-content-config.d.ts","sourceRoot":"","sources":["../../../src/models/config/publish-content-config.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,+BAA+B,EACrC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAGxD,MAAM,MAAM,cAAc,GAAG;IAE3B,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IAG/B,WAAW,EAAE,MAAM,CAAC;IAIpB,IAAI,CAAC,EAAE,OAAO,CAAC;IAIf,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AAED,MAAM,MAAM,yBAAyB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;AAE5F,MAAM,MAAM,oBAAoB,GAAG;IAEjC,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"publish-content-config.d.ts","sourceRoot":"","sources":["../../../src/models/config/publish-content-config.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,+BAA+B,EACrC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAGxD,MAAM,MAAM,cAAc,GAAG;IAE3B,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IAG/B,WAAW,EAAE,MAAM,CAAC;IAIpB,IAAI,CAAC,EAAE,OAAO,CAAC;IAIf,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AAED,MAAM,MAAM,yBAAyB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;AAE5F,MAAM,MAAM,oBAAoB,GAAG;IAEjC,OAAO,EAAE,MAAM,CAAC;IAMhB,WAAW,CAAC,EAAE,CAAC,MAAM,GAAG,cAAc,CAAC,EAAE,GAAG,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC;IAI3E,eAAe,CAAC,EAAE,OAAO,CAAC;IAI1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAG3B,yBAAyB,CAAC,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAI7D,kBAAkB,CAAC,EAAE,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC;IAGvC,YAAY,CAAC,EAAE,cAAc,EAAE,CAAC;IAGhC,MAAM,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,cAAc,EAAE,CAAC;IAC9B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,yBAAyB,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAC5D,kBAAkB,EAAE,uBAAuB,EAAE,CAAC;IAC9C,YAAY,EAAE,cAAc,EAAE,CAAC;IAC/B,MAAM,EAAE,+BAA+B,GAAG,IAAI,CAAC;CAChD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static-publish-rc.d.ts","sourceRoot":"","sources":["../../../src/models/config/static-publish-rc.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,eAAe,GAAG;IAE5B,WAAW,EAAE,MAAM,CAAC;IAIpB,SAAS,EAAE,MAAM,CAAC;IAGlB,qBAAqB,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"static-publish-rc.d.ts","sourceRoot":"","sources":["../../../src/models/config/static-publish-rc.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,eAAe,GAAG;IAE5B,WAAW,EAAE,MAAM,CAAC;IAIpB,SAAS,EAAE,MAAM,CAAC;IAGlB,qBAAqB,EAAE,MAAM,CAAC;IAK9B,yBAAyB,EAAE,MAAM,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/models/server/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type CalcExpirationTimeArg = {
|
|
2
|
+
expiresIn?: string;
|
|
3
|
+
expiresAt?: string;
|
|
4
|
+
expiresNever?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function calcExpirationTime({ expiresIn, expiresAt, expiresNever }: CalcExpirationTimeArg): number | null | undefined;
|
|
7
|
+
export declare function isExpired(unixTime: number): boolean;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/models/time/index.ts"],"names":[],"mappings":"AAkCA,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,qBAAqB,6BA0B/F;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,WAEzC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
const DURATION_MS = {
|
|
6
|
+
w: 604800000,
|
|
7
|
+
d: 86400000,
|
|
8
|
+
h: 3600000,
|
|
9
|
+
m: 60000,
|
|
10
|
+
s: 1000,
|
|
11
|
+
ms: 1,
|
|
12
|
+
};
|
|
13
|
+
// Parses something like "1d2h30m" or "5m15s" or "150ms"
|
|
14
|
+
function parseDuration(durationStr) {
|
|
15
|
+
const regex = /(\d+(?:\.\d+)?)(ms|[dhms])/g;
|
|
16
|
+
let totalMs = 0;
|
|
17
|
+
let matchedLength = 0;
|
|
18
|
+
for (const match of durationStr.matchAll(regex)) {
|
|
19
|
+
const [res, valueStr, unit] = match;
|
|
20
|
+
const value = parseFloat(valueStr);
|
|
21
|
+
totalMs += value * DURATION_MS[unit];
|
|
22
|
+
matchedLength += res.length;
|
|
23
|
+
}
|
|
24
|
+
if (matchedLength !== durationStr.length) {
|
|
25
|
+
throw new Error(`Invalid duration format: '${durationStr}'`);
|
|
26
|
+
}
|
|
27
|
+
return totalMs;
|
|
28
|
+
}
|
|
29
|
+
export function calcExpirationTime({ expiresIn, expiresAt, expiresNever }) {
|
|
30
|
+
if ([expiresIn, expiresAt, expiresNever].filter(x => x !== undefined).length > 1) {
|
|
31
|
+
throw new Error('Only one of expiresIn or expiresAt or expiresNever may be provided');
|
|
32
|
+
}
|
|
33
|
+
if (expiresNever) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
if (expiresIn) {
|
|
37
|
+
const deltaMs = parseDuration(expiresIn);
|
|
38
|
+
console.log(` ⏳ Expiration duration '${expiresIn}' = ${deltaMs} ms`);
|
|
39
|
+
return Math.floor((Date.now() + deltaMs) / 1000); // return UNIX timestamp
|
|
40
|
+
}
|
|
41
|
+
if (expiresAt) {
|
|
42
|
+
const time = Date.parse(expiresAt);
|
|
43
|
+
if (isNaN(time)) {
|
|
44
|
+
throw new Error(`Invalid expiresAt value: '${expiresAt}'`);
|
|
45
|
+
}
|
|
46
|
+
console.log(` ⏰️ Expiration timestamp '${expiresAt}' = '${new Date(time)}'`);
|
|
47
|
+
console.log(` → ${new Date(time).toISOString()}`);
|
|
48
|
+
return Math.floor(time / 1000);
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
export function isExpired(unixTime) {
|
|
53
|
+
return unixTime < Math.floor(Date.now() / 1000);
|
|
54
|
+
}
|
|
@@ -20,6 +20,8 @@ export declare class PublisherServer {
|
|
|
20
20
|
defaultCollectionName: string;
|
|
21
21
|
activeCollectionName: string;
|
|
22
22
|
collectionNameHeader: string | null;
|
|
23
|
+
settingsCached: PublisherServerConfigNormalized | null | undefined;
|
|
24
|
+
kvAssetsIndex: KVAssetEntryMap | null | undefined;
|
|
23
25
|
setActiveCollectionName(collectionName: string): void;
|
|
24
26
|
setCollectionNameHeader(collectionHeader: string | null): void;
|
|
25
27
|
getServerConfig(): Promise<PublisherServerConfigNormalized | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,+BAA+B,EACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC5B,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,+BAA+B,EACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC5B,MAAM,uCAAuC,CAAC;AAO/C,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,sBAAsB,CAAC;AAE3B,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,WAWpF;AAmBD,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,IAAI,CAAC;CACrC,CAAC;AAEF,qBAAa,eAAe;gBAExB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,qBAAqB,EAAE,MAAM;IAS/B,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,eAAe;IAQlD,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IAGpC,cAAc,EAAE,+BAA+B,GAAG,IAAI,GAAG,SAAS,CAAC;IAGnE,aAAa,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC;IAElD,uBAAuB,CAAC,cAAc,EAAE,MAAM;IAM9C,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI;IAKjD,eAAe;IAiBf,cAAc;IAoBd,gBAAgB;IAoChB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IA2D5F,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC;IAoDjF,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAcxC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI;IA6DxF,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;YAkC/G,0CAA0C;IAyClD,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiDtF,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAqE/D"}
|
|
@@ -8,6 +8,7 @@ import { isKVAssetVariantMetadata, } from '../../models/assets/kvstore-assets.js
|
|
|
8
8
|
import { getKVStoreEntry } from '../util/kv-store.js';
|
|
9
9
|
import { checkIfModifiedSince, getIfModifiedSinceHeader } from './serve-preconditions/if-modified-since.js';
|
|
10
10
|
import { checkIfNoneMatch, getIfNoneMatchHeader } from './serve-preconditions/if-none-match.js';
|
|
11
|
+
import { isExpired } from "../../models/time/index.js";
|
|
11
12
|
export function buildHeadersSubset(responseHeaders, keys) {
|
|
12
13
|
const resultHeaders = new Headers();
|
|
13
14
|
for (const value of keys) {
|
|
@@ -48,21 +49,29 @@ export class PublisherServer {
|
|
|
48
49
|
}
|
|
49
50
|
setActiveCollectionName(collectionName) {
|
|
50
51
|
this.activeCollectionName = collectionName;
|
|
52
|
+
this.settingsCached = undefined;
|
|
53
|
+
this.kvAssetsIndex = undefined;
|
|
51
54
|
}
|
|
52
55
|
setCollectionNameHeader(collectionHeader) {
|
|
53
56
|
this.collectionNameHeader = collectionHeader;
|
|
54
57
|
}
|
|
55
58
|
// Server config is obtained from the KV Store, and cached for the duration of this object.
|
|
56
59
|
async getServerConfig() {
|
|
60
|
+
if (this.settingsCached !== undefined) {
|
|
61
|
+
return this.settingsCached;
|
|
62
|
+
}
|
|
57
63
|
const settingsFileKey = `${this.publishId}_settings_${this.activeCollectionName}`;
|
|
58
64
|
const kvStore = new KVStore(this.kvStoreName);
|
|
59
65
|
const settingsFile = await getKVStoreEntry(kvStore, settingsFileKey);
|
|
60
66
|
if (settingsFile == null) {
|
|
61
67
|
console.error(`Settings File not found at ${settingsFileKey}.`);
|
|
62
68
|
console.error(`You may need to publish your application.`);
|
|
63
|
-
|
|
69
|
+
this.settingsCached = null;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.settingsCached = (await settingsFile.json());
|
|
64
73
|
}
|
|
65
|
-
return
|
|
74
|
+
return this.settingsCached;
|
|
66
75
|
}
|
|
67
76
|
async getStaticItems() {
|
|
68
77
|
const serverConfig = await this.getServerConfig();
|
|
@@ -84,15 +93,37 @@ export class PublisherServer {
|
|
|
84
93
|
.filter(x => Boolean(x));
|
|
85
94
|
}
|
|
86
95
|
async getKvAssetsIndex() {
|
|
96
|
+
if (this.kvAssetsIndex !== undefined) {
|
|
97
|
+
return this.kvAssetsIndex;
|
|
98
|
+
}
|
|
87
99
|
const indexFileKey = `${this.publishId}_index_${this.activeCollectionName}`;
|
|
88
100
|
const kvStore = new KVStore(this.kvStoreName);
|
|
89
101
|
const indexFile = await getKVStoreEntry(kvStore, indexFileKey);
|
|
90
102
|
if (indexFile == null) {
|
|
91
103
|
console.error(`Index File not found at ${indexFileKey}.`);
|
|
92
104
|
console.error(`You may need to publish your application.`);
|
|
105
|
+
this.kvAssetsIndex = null;
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
let collectionIsExpired = false;
|
|
109
|
+
if (this.activeCollectionName !== this.defaultCollectionName) {
|
|
110
|
+
const metadataText = indexFile.metadataText();
|
|
111
|
+
if (metadataText != null) {
|
|
112
|
+
try {
|
|
113
|
+
const metadata = JSON.parse(metadataText);
|
|
114
|
+
collectionIsExpired = metadata.expirationTime != null && isExpired(metadata.expirationTime);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (collectionIsExpired) {
|
|
121
|
+
console.error(`Requested collection expired at ${indexFileKey}.`);
|
|
122
|
+
this.kvAssetsIndex = null;
|
|
93
123
|
return null;
|
|
94
124
|
}
|
|
95
|
-
|
|
125
|
+
this.kvAssetsIndex = (await indexFile.json());
|
|
126
|
+
return this.kvAssetsIndex;
|
|
96
127
|
}
|
|
97
128
|
async getMatchingAsset(assetKey, applyAuto = false) {
|
|
98
129
|
const serverConfig = await this.getServerConfig();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastly/compute-js-static-publish",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-beta.
|
|
4
|
+
"version": "7.0.0-beta.3",
|
|
5
5
|
"description": "Static Publisher for Fastly Compute JavaScript",
|
|
6
6
|
"main": "build/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@fastly/cli": "^11.2.0",
|
|
42
42
|
"command-line-args": "^5.2.1",
|
|
43
|
-
"glob-to-regexp": "^0.4.1"
|
|
43
|
+
"glob-to-regexp": "^0.4.1",
|
|
44
|
+
"toml": "^3.0.0"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
47
|
"@fastly/js-compute": "^3.33.2"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/clean.ts"],"names":[],"mappings":"AAYA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,iBAoJ1C"}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright Fastly, Inc.
|
|
3
|
-
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
-
*/
|
|
5
|
-
import commandLineArgs from 'command-line-args';
|
|
6
|
-
import { LoadConfigError, loadStaticPublisherRcFile } from '../util/config.js';
|
|
7
|
-
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteFile } from '../fastly-api/kv-store.js';
|
|
8
|
-
import { loadApiToken } from '../fastly-api/api-token.js';
|
|
9
|
-
export async function action(argv) {
|
|
10
|
-
const optionDefinitions = [
|
|
11
|
-
{ name: 'verbose', type: Boolean },
|
|
12
|
-
{ name: 'fastly-api-token', type: String, },
|
|
13
|
-
];
|
|
14
|
-
const commandLineValues = commandLineArgs(optionDefinitions, { argv });
|
|
15
|
-
const { verbose, ['fastly-api-token']: fastlyApiToken, } = commandLineValues;
|
|
16
|
-
const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
|
|
17
|
-
if (apiTokenResult == null) {
|
|
18
|
-
console.error("❌ Fastly API Token not provided.");
|
|
19
|
-
console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
20
|
-
process.exitCode = 1;
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const fastlyApiContext = { apiToken: apiTokenResult.apiToken };
|
|
24
|
-
console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
25
|
-
// #### load config
|
|
26
|
-
let staticPublisherRc;
|
|
27
|
-
try {
|
|
28
|
-
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
console.error("❌ Can't load static-publish.rc.js");
|
|
32
|
-
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
33
|
-
if (err instanceof LoadConfigError) {
|
|
34
|
-
for (const error of err.errors) {
|
|
35
|
-
console.error(error);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
process.exitCode = 1;
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const publishId = staticPublisherRc.publishId;
|
|
42
|
-
console.log(`✔️ Publish ID: ${publishId}`);
|
|
43
|
-
const kvStoreName = staticPublisherRc.kvStoreName;
|
|
44
|
-
console.log(`✔️ Using KV Store: ${kvStoreName}`);
|
|
45
|
-
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
46
|
-
console.log(`✔️ Default Collection Name: ${defaultCollectionName}`);
|
|
47
|
-
// ### KVStore Keys to delete
|
|
48
|
-
const kvKeysToDelete = new Set();
|
|
49
|
-
// ### List all indexes ###
|
|
50
|
-
const indexesPrefix = publishId + '_index_';
|
|
51
|
-
const indexKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, indexesPrefix);
|
|
52
|
-
if (indexKeys == null) {
|
|
53
|
-
throw new Error(`Can't query indexes in KV Store`);
|
|
54
|
-
}
|
|
55
|
-
// ### Found collections ###
|
|
56
|
-
const foundCollections = indexKeys.map(x => x.slice(indexesPrefix.length));
|
|
57
|
-
console.log('Found collections');
|
|
58
|
-
for (const collection of foundCollections) {
|
|
59
|
-
console.log(collection);
|
|
60
|
-
}
|
|
61
|
-
// TODO ### Determine which ones are not expired, based on an expiration meta
|
|
62
|
-
const liveCollections = foundCollections;
|
|
63
|
-
// ### List all settings ###
|
|
64
|
-
const settingsPrefix = publishId + '_index_';
|
|
65
|
-
const settingsKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, settingsPrefix);
|
|
66
|
-
if (settingsKeys == null) {
|
|
67
|
-
throw new Error(`Can't query settings in KV Store`);
|
|
68
|
-
}
|
|
69
|
-
// If a settings object is found that doesn't match a live collection name then
|
|
70
|
-
// mark it for deletion
|
|
71
|
-
const foundSettingsCollections = settingsKeys.map(key => ({ key, name: key.slice(settingsPrefix.length) }));
|
|
72
|
-
for (const foundSettings of foundSettingsCollections) {
|
|
73
|
-
if (!foundCollections.includes(foundSettings.name)) {
|
|
74
|
-
kvKeysToDelete.add(foundSettings.key);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// ### Go through the index files and make a list of all keys (hashes) that we are keeping
|
|
78
|
-
const assetsIdsInUse = new Set();
|
|
79
|
-
for (const collection of liveCollections) {
|
|
80
|
-
// TODO deal with when the index file is > 20MB
|
|
81
|
-
const kvAssetsIndexResponse = await getKvStoreEntry(fastlyApiContext, kvStoreName, indexesPrefix + collection);
|
|
82
|
-
if (!kvAssetsIndexResponse) {
|
|
83
|
-
throw new Error(`Can't load KV Store entry ${indexesPrefix + collection}`);
|
|
84
|
-
}
|
|
85
|
-
const kvAssetsIndex = (await kvAssetsIndexResponse.response.json());
|
|
86
|
-
for (const [_assetKey, assetEntry] of Object.entries(kvAssetsIndex)) {
|
|
87
|
-
if (assetEntry.key.startsWith('sha256:')) {
|
|
88
|
-
assetsIdsInUse.add(`sha256_${assetEntry.key.slice('sha256:'.length)}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// ### Obtain the assets in the KV Store and find the ones that are not in use
|
|
93
|
-
const assetPrefix = publishId + '_files_';
|
|
94
|
-
const assetKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, assetPrefix);
|
|
95
|
-
if (assetKeys == null) {
|
|
96
|
-
throw new Error(`Can't query assets in KV Store`);
|
|
97
|
-
}
|
|
98
|
-
for (const assetKey of assetKeys) {
|
|
99
|
-
let assetId = assetKey.slice(assetPrefix.length);
|
|
100
|
-
if (assetId.startsWith('sha256_')) {
|
|
101
|
-
assetId = assetId.slice(0, 'sha256_'.length + 64);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
// If we don't know what the prefix is, we ignore it
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (assetsIdsInUse.has(assetId)) {
|
|
108
|
-
console.log('Asset ID ' + assetId + ' in use');
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
kvKeysToDelete.add(assetKey);
|
|
112
|
-
console.log('Asset ID ' + assetId + ' not in use');
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// ### Delete items that have been flagged
|
|
116
|
-
for (const key of kvKeysToDelete) {
|
|
117
|
-
console.log("Deleting item: " + key);
|
|
118
|
-
await kvStoreDeleteFile(fastlyApiContext, kvStoreName, key);
|
|
119
|
-
}
|
|
120
|
-
console.log("✅ Completed.");
|
|
121
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/collections/delete.ts"],"names":[],"mappings":"AAWA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,iBAmG1C"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright Fastly, Inc.
|
|
3
|
-
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
-
*/
|
|
5
|
-
import commandLineArgs from 'command-line-args';
|
|
6
|
-
import { LoadConfigError, loadStaticPublisherRcFile } from '../../util/config.js';
|
|
7
|
-
import { getKVStoreKeys, kvStoreDeleteFile } from '../../fastly-api/kv-store.js';
|
|
8
|
-
import { loadApiToken } from '../../fastly-api/api-token.js';
|
|
9
|
-
export async function action(argv) {
|
|
10
|
-
const optionDefinitions = [
|
|
11
|
-
{ name: 'verbose', type: Boolean },
|
|
12
|
-
{ name: 'fastly-api-token', type: String, },
|
|
13
|
-
{ name: 'collection-name', type: String, multiple: true }
|
|
14
|
-
];
|
|
15
|
-
const commandLineValues = commandLineArgs(optionDefinitions, { argv });
|
|
16
|
-
const { verbose, ['fastly-api-token']: fastlyApiToken, ['collection-name']: collectionNameValue, } = commandLineValues;
|
|
17
|
-
const collectionNamesAsArray = (Array.isArray(collectionNameValue) ? collectionNameValue : [collectionNameValue])
|
|
18
|
-
.filter(x => typeof x === 'string')
|
|
19
|
-
.map(x => x.split(','))
|
|
20
|
-
.flat()
|
|
21
|
-
.map(x => x.trim())
|
|
22
|
-
.filter(Boolean);
|
|
23
|
-
if (collectionNamesAsArray.length === 0) {
|
|
24
|
-
console.error("❌ Required argument '--collection-name' not specified.");
|
|
25
|
-
process.exitCode = 1;
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
|
|
29
|
-
if (apiTokenResult == null) {
|
|
30
|
-
console.error("❌ Fastly API Token not provided.");
|
|
31
|
-
console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
32
|
-
process.exitCode = 1;
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const fastlyApiContext = { apiToken: apiTokenResult.apiToken };
|
|
36
|
-
console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
37
|
-
// #### load config
|
|
38
|
-
let staticPublisherRc;
|
|
39
|
-
try {
|
|
40
|
-
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
console.error("❌ Can't load static-publish.rc.js");
|
|
44
|
-
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
45
|
-
if (err instanceof LoadConfigError) {
|
|
46
|
-
for (const error of err.errors) {
|
|
47
|
-
console.error(error);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
process.exitCode = 1;
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const publishId = staticPublisherRc.publishId;
|
|
54
|
-
console.log(`✔️ Publish ID: ${publishId}`);
|
|
55
|
-
const kvStoreName = staticPublisherRc.kvStoreName;
|
|
56
|
-
console.log(`✔️ Using KV Store: ${kvStoreName}`);
|
|
57
|
-
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
58
|
-
console.log(`✔️ Default Collection Name: ${defaultCollectionName}`);
|
|
59
|
-
console.log(`✔️ Collections to delete: ${collectionNamesAsArray.map(x => `'${x}'`).join(', ')}`);
|
|
60
|
-
const collectionNames = new Set(collectionNamesAsArray);
|
|
61
|
-
const kvKeysToDelete = new Set();
|
|
62
|
-
// ### List all indexes ###
|
|
63
|
-
const indexesPrefix = publishId + '_index_';
|
|
64
|
-
const indexKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, indexesPrefix);
|
|
65
|
-
if (indexKeys == null) {
|
|
66
|
-
throw new Error(`Can't query indexes in KV Store`);
|
|
67
|
-
}
|
|
68
|
-
// ### Found collections ###
|
|
69
|
-
const foundCollections = indexKeys.map(key => ({ key, name: key.slice(indexesPrefix.length), }));
|
|
70
|
-
if (foundCollections.length === 0) {
|
|
71
|
-
console.log('No collections found.');
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
console.log(`Found collections: ${foundCollections.map(x => `'${x.name}'`).join(', ')}`);
|
|
75
|
-
for (const collection of foundCollections) {
|
|
76
|
-
if (collectionNames.has(collection.name)) {
|
|
77
|
-
console.log(`Flagging collection '${collection.name}' for deletion: ${collection.key}`);
|
|
78
|
-
kvKeysToDelete.add(collection.key);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// ### Delete items that have been flagged
|
|
83
|
-
for (const key of kvKeysToDelete) {
|
|
84
|
-
console.log("Deleting key from KV Store: " + key);
|
|
85
|
-
await kvStoreDeleteFile(fastlyApiContext, kvStoreName, key);
|
|
86
|
-
}
|
|
87
|
-
console.log("✅ Completed.");
|
|
88
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/collections/index.ts"],"names":[],"mappings":"AASA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA2BhD"}
|