@fastly/compute-js-static-publish 4.2.1 → 5.0.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.
Files changed (33) hide show
  1. package/README.md +50 -50
  2. package/build/cli/commands/build-static.js +49 -49
  3. package/build/cli/commands/clean-kv-store.d.ts +3 -0
  4. package/build/cli/commands/clean-kv-store.d.ts.map +1 -0
  5. package/build/cli/commands/clean-kv-store.js +54 -0
  6. package/build/cli/commands/init-app.js +11 -11
  7. package/build/cli/index.js +9 -9
  8. package/build/cli/load-config.js +9 -9
  9. package/build/cli/presets/preset-base.d.ts +1 -1
  10. package/build/cli/presets/preset-base.d.ts.map +1 -1
  11. package/build/cli/util/kv-store.d.ts +16 -0
  12. package/build/cli/util/kv-store.d.ts.map +1 -0
  13. package/build/cli/util/kv-store.js +108 -0
  14. package/build/compute-js.d.ts +1 -1
  15. package/build/compute-js.d.ts.map +1 -1
  16. package/build/compute-js.js +1 -1
  17. package/build/server/assets/content-asset-kv-store.d.ts +18 -0
  18. package/build/server/assets/content-asset-kv-store.d.ts.map +1 -0
  19. package/build/server/assets/content-asset-kv-store.js +67 -0
  20. package/build/server/assets/content-asset-wasm-inline.js +1 -1
  21. package/build/server/assets/content-assets.js +1 -1
  22. package/build/server/kv-store/inline-store-entry.d.ts +25 -0
  23. package/build/server/kv-store/inline-store-entry.d.ts.map +1 -0
  24. package/build/server/kv-store/inline-store-entry.js +100 -0
  25. package/build/types/config-normalized.d.ts +1 -1
  26. package/build/types/config.d.ts +1 -1
  27. package/build/types/content-assets.d.ts +6 -6
  28. package/build/types/content-assets.d.ts.map +1 -1
  29. package/build/util/metadata.d.ts +1 -1
  30. package/build/util/metadata.d.ts.map +1 -1
  31. package/build/util/metadata.js +4 -4
  32. package/package.json +2 -2
  33. package/resources/statics-metadata.d.ts +1 -1
package/README.md CHANGED
@@ -5,7 +5,7 @@ Using a static site generator to build your website? Do you simply need to serve
5
5
  ## New! Version 4
6
6
 
7
7
  Version 4 of this tool has some awesome new features:
8
- - Support for serving files from Fastly's [Object Store](#object-store) instead of bundling them into the Wasm module.
8
+ - Support for serving files from Fastly's [KV Store](#kv-store) instead of/alongside bundling them into the Wasm module.
9
9
  - Scaffolded applications no longer use a bundler by default (Webpack is optional).
10
10
  - Brotli and Gzip compression.
11
11
  - Support for returning `304 Not Modified` status based on `If-None-Match` and `If-Modified-Since` request headers.
@@ -63,7 +63,7 @@ Once your application is scaffolded, `@fastly/compute-js-static-publish` integra
63
63
  running as part of your build process.
64
64
 
65
65
  The files you have configured to be included (`--root-dir`) are enumerated and prepared. Their contents are included into
66
- your Wasm binary (or made available via [Object Store](#object-store), if so configured). This process is called "publishing".
66
+ your Wasm binary (or made available via [KV Store](#kv-store), if so configured). This process is called "publishing".
67
67
 
68
68
  Once the files are published, they are available to the other source files in the Compute@Edge application. For example,
69
69
  the stock application runs the [PublisherServer](#publisherserver) class to serve these files.
@@ -77,11 +77,11 @@ If the files in `--root-dir` have changed, then a new set of files will be publi
77
77
  ### Content Compression
78
78
 
79
79
  During publishing, this tool supports pre-compression of content. By default, your assets are compressed using the Brotli
80
- and gzip algorithms, and then stored alongside the original files in your Wasm binary (or [Object Store](#object-store)).
80
+ and gzip algorithms, and then stored alongside the original files in your Wasm binary (or [KV Store](#kv-store)).
81
81
 
82
- > Note: By default, pre-compressed content assets are not generated when the Object Store is not used.
82
+ > Note: By default, pre-compressed content assets are not generated when the KV Store is not used.
83
83
  This is done to prevent the inclusion multiple of copies of each asset from making the Wasm binary too large.
84
- If you want to pre-compress assets when not using Object Store, add a value for 'contentCompression' to your
84
+ If you want to pre-compress assets when not using KV Store, add a value for 'contentCompression' to your
85
85
  `static-publish.rc.js` file.
86
86
 
87
87
  ## CLI options
@@ -138,13 +138,13 @@ Note that the files referenced by `--spa` and `--not-found-page` do not necessar
138
138
 
139
139
  These arguments are used to populate the `fastly.toml` and `package.json` files of your Compute@Edge application.
140
140
 
141
- | Option | Default | Description |
142
- |---------------------|------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
143
- | `name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute@Edge application. |
144
- | `description` | `description` from `package.json`, or `Compute@Edge static site` | The description of your Compute@Edge application. |
145
- | `author` | `author` from `package.json`, or `you@example.com` | The author of your Compute@Edge application. |
146
- | `service-id` | (None) | The ID of an existing Fastly WASM service for your Compute@Edge application. |
147
- | `object-store-name` | (None) | The name of an existing [Fastly Object Store](https://developer.fastly.com/learning/concepts/data-stores/#object-stores) to hold the content assets. In addition to already existing, it must be linked to the service specified by `--service-id`. |
141
+ | Option | Default | Description |
142
+ |-----------------|------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
143
+ | `name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute@Edge application. |
144
+ | `description` | `description` from `package.json`, or `Compute@Edge static site` | The description of your Compute@Edge application. |
145
+ | `author` | `author` from `package.json`, or `you@example.com` | The author of your Compute@Edge application. |
146
+ | `service-id` | (None) | The ID of an existing Fastly WASM service for your Compute@Edge application. |
147
+ | `kv-store-name` | (None) | The name of an existing [Fastly KV Store](https://developer.fastly.com/learning/concepts/data-stores/#kv-stores) to hold the content assets. In addition to already existing, it must be linked to the service specified by `--service-id`. |
148
148
 
149
149
  ## Usage with frameworks and static site generators
150
150
 
@@ -176,7 +176,7 @@ You may still override any of these options individually.
176
176
  This server handles the following automatically:
177
177
 
178
178
  * Maps the path of your request to a path under `--public-dir` and serves the content of the asset
179
- * Sources the content from the content packaged in the Wasm binary, or from the [Object Store](#object-store), if configured.
179
+ * Sources the content from the content packaged in the Wasm binary, or from the [KV Store](#kv-store), if configured.
180
180
  * Applies long-lived cache headers to files served from `--static-dir` directories. Files under these directories will be cached by the browser for 1 year. (Use versioned or hashed filenames to avoid serving stale assets.)
181
181
  * Performs Brotli and gzip compression as requested by the `Accept-Encoding` headers.
182
182
  * Provides `Last-Modified` and `ETag` response headers, and uses them with `If-Modified-Since` and `If-None-Match` request headers to produce `304 Not Modified` responses.
@@ -231,58 +231,58 @@ ID of the service. The `fastly compute publish` will deploy to the service ident
231
231
  To specify the service at the time you are scaffolding the project (for example, if you are running this tool and deploying
232
232
  as part of a CI process), specify the `--service-id` command line argument to populate `fastly.toml` with this value.
233
233
 
234
- ## Using the Object Store (BETA) <a name="object-store"></a>
234
+ ## Using the KV Store (BETA) <a name="kv-store"></a>
235
235
 
236
- Starting with v4, it's now possible to upload assets to and serve them from a [Fastly Object Store](https://developer.fastly.com/learning/concepts/data-stores/#object-stores).
236
+ Starting with v4, it's now possible to upload assets to and serve them from a [Fastly KV Store](https://developer.fastly.com/learning/concepts/data-stores/#kv-stores).
237
237
 
238
- You can enable the use of Object Store with `@fastly/compute-js-static-publish` as you scaffold your application, or
238
+ You can enable the use of KV Store with `@fastly/compute-js-static-publish` as you scaffold your application, or
239
239
  at any later time.
240
240
 
241
- At the time you enable the use of Object Store:
241
+ At the time you enable the use of KV Store:
242
242
 
243
243
  * Your Fastly service must already exist. See [Associating your project with a Fastly Service](#associating-your-project-with-a-fastly-service) above.
244
244
 
245
- * Your Object Store must already exist under the same Fastly account, and be linked to the service.
246
- As of this writing, to create the Object Store you will need to use either the Fastly CLI [fastly object-store create](https://developer.fastly.com/reference/cli/object-store/create/)
247
- or the Fastly [Object Store API](https://developer.fastly.com/reference/api/services/resources/object-store/#create-store).
248
- Once the Object Store is created, you must be link it to your Fastly service using the [Resource API](https://developer.fastly.com/reference/api/services/resource/#create-resource).
245
+ * Your KV Store must already exist under the same Fastly account, and be linked to the service.
246
+ As of this writing, to create the KV Store you will need to use either the Fastly CLI [fastly kv-store create](https://developer.fastly.com/reference/cli/kv-store/create/)
247
+ or the Fastly [KV Store API](https://developer.fastly.com/reference/api/services/resources/kv-store/#create-store).
248
+ Once the KV Store is created, you must be link it to your Fastly service using the [Resource API](https://developer.fastly.com/reference/api/services/resource/#create-resource).
249
249
 
250
250
  ```shell
251
- # Create an object store
252
- $ curl -i -X POST "https://api.fastly.com/resources/stores/object" -H "Fastly-Key: YOUR_FASTLY_TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" -d '{"name":"example-store"}'
251
+ # Create a KV Store
252
+ $ curl -i -X POST "https://api.fastly.com/resources/stores/kv" -H "Fastly-Key: YOUR_FASTLY_TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" -d '{"name":"example-store"}'
253
253
 
254
- # Link the object store to a service
255
- $ curl -i -X POST "https://api.fastly.com/service/YOUR_FASTLY_SERVICE_ID/version/YOUR_FASTLY_SERVICE_VERSION/resource" -H "Fastly-Key: YOUR_FASTLY_TOKEN" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -d "name=example-store-service-a&resource_id=YOUR_OBJECT_STORE_ID"
254
+ # Link the KV Store to a service
255
+ $ curl -i -X POST "https://api.fastly.com/service/YOUR_FASTLY_SERVICE_ID/version/YOUR_FASTLY_SERVICE_VERSION/resource" -H "Fastly-Key: YOUR_FASTLY_TOKEN" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -d "name=example-store-service-a&resource_id=YOUR_KV_STORE_ID"
256
256
  ```
257
257
 
258
- Once the Object Store is created and linked to your service, add its name to your `static-publish.rc.js`
259
- file under the `objectStore` key.
258
+ Once the KV Store is created and linked to your service, add its name to your `static-publish.rc.js`
259
+ file under the `kvStoreName` key.
260
260
 
261
- To specify the Object Store at the time you are scaffolding the project (for example, if you are running this tool and
262
- deploying as part of a CI process), specify the `--service-id` and `--object-store-name` command line arguments to populate
261
+ To specify the KV Store at the time you are scaffolding the project (for example, if you are running this tool and
262
+ deploying as part of a CI process), specify the `--service-id` and `--kv-store-name` command line arguments to populate
263
263
  the respective files with these values.
264
264
 
265
265
  After you have done the above steps, go ahead and build your application as normal. If you use `fastly compute build --verbose`
266
- (or run `npm run build` directly), you should see output in your logs saying that files are being sent to the Object Store.
266
+ (or run `npm run build` directly), you should see output in your logs saying that files are being sent to the KV Store.
267
267
 
268
- The `statics-metadata.js` file should now show `"type": "object-store"` for content assets.
268
+ The `statics-metadata.js` file should now show `"type": "kv-store"` for content assets.
269
269
  Your Wasm binary should also be smaller, as the content of the files are no longer inlined in the build artifact.
270
- You can deploy this and run it from Fastly, and the referenced files will be served from Object Store.
270
+ You can deploy this and run it from Fastly, and the referenced files will be served from KV Store.
271
271
 
272
- You will also see entries in `fastly.toml` that represent the local object store.
272
+ You will also see entries in `fastly.toml` that represent the local KV Store.
273
273
  These enable the site to also run correctly when served using the local development environment.
274
274
 
275
- ### Cleaning unused items from Object Store
275
+ ### Cleaning unused items from KV Store
276
276
 
277
- The files that are uploaded to the Object Store are submitted using keys of the following format:
277
+ The files that are uploaded to the KV Store are submitted using keys of the following format:
278
278
 
279
279
  `<publish-id>:<asset-path>_<alg>_<hash>`
280
280
 
281
281
  For example:
282
282
  `12345abcde67890ABCDE00:/public/index.html_br_aeed29478691e67f6d5s36b4ded20c17e9eae437614617067a8751882368b965`
283
283
 
284
- Using such an object key ensures that whenever the file contents are identical, the same key will be generated.
285
- This enables to detect whether an unchanged file already exists in the Object Store, avoiding having to re-submit
284
+ Using such a key ensures that whenever the file contents are identical, the same key will be generated.
285
+ This enables to detect whether an unchanged file already exists in the KV Store, avoiding having to re-submit
286
286
  files that have not changed. If the file contents have changed, then a new hash is generated. This ensures that
287
287
  even during the brief amount of time between deploys, any request served by a prior version will still serve the same
288
288
  corresponding previous version of the content.
@@ -292,12 +292,12 @@ However, this system never deletes files automatically. After many deployments,
292
292
  `@fastly/compute-js-static-publish` includes a feature to delete these old versions of the files that are no longer being
293
293
  used. To run it, type the following command:
294
294
 
295
- `npx @fastly/compute-js-static-publish --clean-object-store`
295
+ `npx @fastly/compute-js-static-publish --clean-kv-store`
296
296
 
297
- It works by scanning `statics-metadata.js` for all currently-used object store keys. Then it enumerates all the existing
298
- keys in the configured object store and that belong to this application (can do so by narrowing down all keys to the ones
297
+ It works by scanning `statics-metadata.js` for all currently-used keys. Then it enumerates all the existing
298
+ keys in the configured KV Store and that belong to this application (can do so by narrowing down all keys to the ones
299
299
  that begin with the "publish id"). If any of the keys is not in the list of currently-used keys, then a request is made
300
- to delete that object store entry.
300
+ to delete that KV Store value.
301
301
 
302
302
  And that's it! It should be possible to run this task to clean up once in a while.
303
303
 
@@ -309,8 +309,8 @@ And that's it! It should be possible to run this task to clean up once in a whil
309
309
  except for those that are excluded using some of the following features. Files outside this root cannot be
310
310
  included in the publishing.
311
311
 
312
- * `objectStore` - Set this value to the _name_ of an existing object store to enable uploading of content assets
313
- to Fastly Object Store. See [Using the Object Store](#using-the-object-store) for more information.
312
+ * `kvStoreName` - Set this value to the _name_ of an existing KV Store to enable uploading of content assets
313
+ to Fastly KV Store. See [Using the KV Store](#kv-store) for more information.
314
314
 
315
315
  * `excludeDirs` - Specifies names of files and directories within `rootDir` to exclude from the publishing. Each entry can
316
316
  be a string or a JavaScript `RegExp` object. Every file and directory under `rootDir` is checked against each entry of
@@ -332,19 +332,19 @@ And that's it! It should be possible to run this task to clean up once in a whil
332
332
  the [asset key](#asset-keys), as well as its content type (MIME type string). You may return one of three values from
333
333
  this function:
334
334
  * Boolean `true` - Include the file as a content asset in this publishing. Upload the file to and serve it from the
335
- Object Store if Object Store mode is enabled, or include the contents of the file in the Wasm binary if Object Store
335
+ KV Store if KV Store mode is enabled, or include the contents of the file in the Wasm binary if KV Store
336
336
  mode is not enabled.
337
337
  * String `"inline"` - Include the file as a content asset in this publishing. Include the contents of the file in the
338
- Wasm binary, regardless of whether Object Store mode is enabled.
338
+ Wasm binary, regardless of whether KV Store mode is enabled.
339
339
  * Boolean `false` - Do not include this file as a content asset in this publishing.
340
340
 
341
341
  If you do not provide a function, then every file will be included in this publishing as a content asset, and their
342
- contents will be uploaded to and served from the Object Store if Object Store mode is enabled, or included in the Wasm
343
- binary if Object Store mode is not enabled.
342
+ contents will be uploaded to and served from the KV Store if KV Store mode is enabled, or included in the Wasm
343
+ binary if KV Store mode is not enabled.
344
344
 
345
345
  * `contentCompression` - During the publishing, the tool will pre-generate compressed versions of content assets in these
346
346
  formats and make them available to the Publisher Server or your application. Default value is [ 'br' | 'gzip' ] if
347
- Object Store is enabled, or [] if Object Store is not enabled.
347
+ KV Store is enabled, or [] if KV Store is not enabled.
348
348
 
349
349
  * `moduleAssetInclusionTest` - Optionally specify a test function that can be run against each enumerated asset during
350
350
  the publishing, to determine whether to include the asset as a module asset. For every file, this function is passed
@@ -426,7 +426,7 @@ binary contents of an asset.
426
426
 
427
427
  The data of each content asset can exist in one of two stores:
428
428
  * Inline Store - this is a data store that exists within the Wasm binary.
429
- * Fastly Object Store - Fastly's distributed edge data store. Data can be placed here without impacting the size of
429
+ * Fastly KV Store - Fastly's distributed edge data store. Data can be placed here without impacting the size of
430
430
  your Wasm binary.
431
431
 
432
432
  Your application can stream the contents of these assets to a visitor, or read from the stream itself and access its
@@ -453,7 +453,7 @@ import { contentAssets } from './statics';
453
453
  const asset = contentAssets.getAsset('/public/index.html');
454
454
 
455
455
  // 'wasm-inline' if object's data is 'inlined' into Wasm binary
456
- // 'object-store' if object's data exists in Fastly Object Store
456
+ // 'kv-store' if object's data exists in Fastly KV Store
457
457
  asset.type;
458
458
 
459
459
  // Get the "store entry"
@@ -5,7 +5,7 @@
5
5
  //
6
6
  // statics-metadata.js
7
7
  //
8
- // objectStoreName: string - Name of object store, or null if not used.
8
+ // kvStoreName: string - Name of KV Store, or null if not used.
9
9
  // contentAssetMetadataMap: Map<string, ContentAssetMetadataMapEntry> - mapping of asset keys to their metadata
10
10
  // - key: string - assetKey, the filename relative to root dir (e.g., /public/foo/index.html)
11
11
  // - value: ContentAssetMetadataMapEntry - metadata for asset
@@ -19,12 +19,12 @@
19
19
  // - compressedFileInfos: Map<string, FileInfo> - information about any compressed versions
20
20
  // - key: string - compression algorithm name (e.g., "gzip", "br", etc.)
21
21
  // - value: FileInfo - information about the compressed version of the file
22
- // - type: string - where the data is available. Usually 'wasm-inline' or 'object-store'.
22
+ // - type: string - where the data is available. Usually 'wasm-inline' or 'kv-store'.
23
23
  // FileInfo structure
24
24
  // - hash: string - SHA-256 hash of file
25
25
  // - size: number - file size in bytes
26
26
  // - staticFilePath: string - path to file in local filesystem, relative to root dir
27
- // - objectStoreKey: string - object store key, present only for items in object store
27
+ // - kvStoreKey: string - KV Store key, present only for items in KV Store
28
28
  //
29
29
  // statics.js
30
30
  // imports statics-metadata.js and adds utilities for working with the content assets, as well as
@@ -65,32 +65,32 @@ import { calculateFileSizeAndHash } from "../util/hash.js";
65
65
  import { getFiles } from "../util/files.js";
66
66
  import { generateOrLoadPublishId } from "../util/publish-id.js";
67
67
  import { loadApiKey } from "../util/fastly-api.js";
68
- import { objectStoreEntryExists, objectStoreSubmitFile } from "../util/object-store.js";
68
+ import { kvStoreEntryExists, kvStoreSubmitFile } from "../util/kv-store.js";
69
69
  import { mergeContentTypes, testFileContentType } from "../../util/content-types.js";
70
70
  import { algs } from "../compression/index.js";
71
- async function uploadFilesToObjectStore(fastlyApiContext, objectStoreName, objectStoreItems) {
72
- for (const { objectStoreKey, staticFilePath, text } of objectStoreItems) {
73
- if (await objectStoreEntryExists(fastlyApiContext, objectStoreName, objectStoreKey)) {
74
- // Already exists in Object Store
75
- console.log(`✔️ Asset already exists in Object Store with key "${objectStoreKey}".`);
71
+ async function uploadFilesToKVStore(fastlyApiContext, kvStoreName, kvStoreItems) {
72
+ for (const { kvStoreKey, staticFilePath, text } of kvStoreItems) {
73
+ if (await kvStoreEntryExists(fastlyApiContext, kvStoreName, kvStoreKey)) {
74
+ // Already exists in KV Store
75
+ console.log(`✔️ Asset already exists in KV Store with key "${kvStoreKey}".`);
76
76
  }
77
77
  else {
78
- // Upload to Object Store
78
+ // Upload to KV Store
79
79
  const fileData = fs.readFileSync(staticFilePath);
80
- await objectStoreSubmitFile(fastlyApiContext, objectStoreName, objectStoreKey, fileData);
81
- console.log(`✔️ Submitted ${text ? 'text' : 'binary'} asset "${staticFilePath}" to Object Store at key "${objectStoreKey}".`);
80
+ await kvStoreSubmitFile(fastlyApiContext, kvStoreName, kvStoreKey, fileData);
81
+ console.log(`✔️ Submitted ${text ? 'text' : 'binary'} asset "${staticFilePath}" to KV Store with key "${kvStoreKey}".`);
82
82
  }
83
83
  }
84
84
  }
85
- function writeObjectStoreEntriesToFastlyToml(objectStoreName, objectStoreItems) {
85
+ function writeKVStoreEntriesToFastlyToml(kvStoreName, kvStoreItems) {
86
86
  let fastlyToml = fs.readFileSync('./fastly.toml', 'utf-8');
87
87
  let before = '';
88
88
  let after = '';
89
- const tableMarker = `[[local_server.object_store.${objectStoreName}]]`;
89
+ const tableMarker = `[[local_server.kv_stores.${kvStoreName}]]`;
90
90
  const startPos = fastlyToml.indexOf(tableMarker);
91
91
  if (startPos === -1) {
92
- // Object store decl not in fastly.toml yet
93
- if (fastlyToml.indexOf(objectStoreName) !== -1) {
92
+ // KV Store decl not in fastly.toml yet
93
+ if (fastlyToml.indexOf(kvStoreName) !== -1) {
94
94
  // don't do this!
95
95
  console.error("Don't do this!");
96
96
  throw "No";
@@ -120,10 +120,10 @@ function writeObjectStoreEntriesToFastlyToml(objectStoreName, objectStoreItems)
120
120
  }
121
121
  }
122
122
  let tablesToml = '';
123
- for (const { objectStoreKey, staticFilePath } of objectStoreItems) {
123
+ for (const { kvStoreKey, staticFilePath } of kvStoreItems) {
124
124
  // Probably, JSON.stringify is wrong, but it should do its job
125
125
  tablesToml += tableMarker + '\n';
126
- tablesToml += 'key = ' + JSON.stringify(objectStoreKey) + '\n';
126
+ tablesToml += 'key = ' + JSON.stringify(kvStoreKey) + '\n';
127
127
  tablesToml += 'path = ' + JSON.stringify(path.relative('./', staticFilePath)) + '\n';
128
128
  tablesToml += '\n';
129
129
  }
@@ -153,9 +153,9 @@ export async function buildStaticLoader(commandLineValues) {
153
153
  const outputDir = path.resolve();
154
154
  const publicDirRoot = path.resolve(config.rootDir);
155
155
  console.log(`✔️ Public directory '${publicDirRoot}'.`);
156
- const objectStoreName = config.objectStore;
156
+ const kvStoreName = config.kvStoreName;
157
157
  let fastlyApiContext = null;
158
- if (objectStoreName != null) {
158
+ if (kvStoreName != null) {
159
159
  // TODO: load api key from command line
160
160
  const apiKeyResult = loadApiKey();
161
161
  if (apiKeyResult == null) {
@@ -165,12 +165,12 @@ export async function buildStaticLoader(commandLineValues) {
165
165
  return;
166
166
  }
167
167
  fastlyApiContext = { apiToken: apiKeyResult.apiToken };
168
- console.log(`✔️ Using Object Store mode, with object store: ${objectStoreName}`);
168
+ console.log(`✔️ Using KV Store mode, with KV Store: ${kvStoreName}`);
169
169
  console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiKeyResult.source}'`);
170
170
  }
171
171
  else {
172
172
  if (displayFrameworkWarnings) {
173
- console.log(`✔️ Not using Object Store mode.`);
173
+ console.log(`✔️ Not using KV Store mode.`);
174
174
  }
175
175
  }
176
176
  const excludeDirs = config.excludeDirs;
@@ -260,8 +260,8 @@ export async function buildStaticLoader(commandLineValues) {
260
260
  };
261
261
  });
262
262
  console.log("🚀 Preparing content assets ...");
263
- if (objectStoreName == null && configRaw != null && !("contentCompression" in configRaw)) {
264
- console.log(`⚠️ Notice: By default, pre-compressed content assets are not generated when object store is not used.`);
263
+ if (kvStoreName == null && configRaw != null && !("contentCompression" in configRaw)) {
264
+ console.log(`⚠️ Notice: By default, pre-compressed content assets are not generated when KV Store is not used.`);
265
265
  console.log(" If you want to pre-compress assets, add a value for 'contentCompression' to your static-publish.rc.js.");
266
266
  }
267
267
  // Create "static content" dir that will be used to hold a copy of static files.
@@ -271,12 +271,12 @@ export async function buildStaticLoader(commandLineValues) {
271
271
  fs.mkdirSync(staticContentDir, { recursive: true });
272
272
  // Build content assets metadata
273
273
  const contentAssetMetadataMap = {};
274
- // Object store items to upload
275
- const objectStoreItems = [];
274
+ // KV Store items to upload
275
+ const kvStoreItems = [];
276
276
  let contentItems = 0;
277
277
  const counts = {
278
278
  inline: 0,
279
- objectStore: 0,
279
+ kvStore: 0,
280
280
  excluded: 0,
281
281
  };
282
282
  for (const assetInfo of assetInfos) {
@@ -299,7 +299,7 @@ export async function buildStaticLoader(commandLineValues) {
299
299
  },
300
300
  };
301
301
  let metadata;
302
- const isInline = objectStoreName == null || assetInfo.inline;
302
+ const isInline = kvStoreName == null || assetInfo.inline;
303
303
  const staticContentFilePath = `${staticContentDir}/file${contentItems}.${assetInfo.text ? 'txt' : 'bin'}`;
304
304
  async function prepareCompressedVersions(contentCompressions, func) {
305
305
  for (const alg of contentCompression) {
@@ -339,50 +339,50 @@ export async function buildStaticLoader(commandLineValues) {
339
339
  counts.inline++;
340
340
  }
341
341
  else {
342
- // For object store mode, we don't need to make a copy of the original file
342
+ // For KV Store mode, we don't need to make a copy of the original file
343
343
  const staticFilePath = file;
344
- // Use the hash as part of the object store key name. This avoids having to
344
+ // Use the hash as part of the key name. This avoids having to
345
345
  // re-upload a file if it already exists.
346
- const objectStoreKey = `${publishId}:${assetKey}_${hash}`;
347
- objectStoreItems.push({
348
- objectStoreKey,
346
+ const kvStoreKey = `${publishId}:${assetKey}_${hash}`;
347
+ kvStoreItems.push({
348
+ kvStoreKey,
349
349
  staticFilePath,
350
350
  text,
351
351
  });
352
352
  const compressedFileInfos = {};
353
353
  await prepareCompressedVersions(contentCompression, (alg, staticFilePath, hash, size) => {
354
- const objectStoreKey = `${publishId}:${assetKey}_${alg}_${hash}`;
355
- compressedFileInfos[alg] = { staticFilePath, objectStoreKey, hash, size };
356
- objectStoreItems.push({
357
- objectStoreKey,
354
+ const kvStoreKey = `${publishId}:${assetKey}_${alg}_${hash}`;
355
+ compressedFileInfos[alg] = { staticFilePath, kvStoreKey, hash, size };
356
+ kvStoreItems.push({
357
+ kvStoreKey,
358
358
  staticFilePath,
359
359
  text,
360
360
  });
361
361
  });
362
362
  metadata = {
363
363
  ...entryBase,
364
- type: 'object-store',
364
+ type: 'kv-store',
365
365
  fileInfo: {
366
366
  ...entryBase.fileInfo,
367
367
  staticFilePath,
368
- objectStoreKey,
368
+ kvStoreKey,
369
369
  },
370
370
  compressedFileInfos,
371
371
  };
372
- counts.objectStore++;
372
+ counts.kvStore++;
373
373
  }
374
374
  contentAssetMetadataMap[assetKey] = metadata;
375
375
  }
376
- if (objectStoreName != null) {
377
- await uploadFilesToObjectStore(fastlyApiContext, objectStoreName, objectStoreItems);
378
- writeObjectStoreEntriesToFastlyToml(objectStoreName, objectStoreItems);
376
+ if (kvStoreName != null) {
377
+ await uploadFilesToKVStore(fastlyApiContext, kvStoreName, kvStoreItems);
378
+ writeKVStoreEntriesToFastlyToml(kvStoreName, kvStoreItems);
379
379
  }
380
- console.log("✅ Prepared " + (counts.inline + counts.objectStore) + " content asset(s):");
380
+ console.log("✅ Prepared " + (counts.inline + counts.kvStore) + " content asset(s):");
381
381
  if (counts.inline > 0) {
382
382
  console.log(" " + counts.inline + " inline");
383
383
  }
384
- if (counts.objectStore > 0) {
385
- console.log(" " + counts.objectStore + " object store");
384
+ if (counts.kvStore > 0) {
385
+ console.log(" " + counts.kvStore + " KV Store");
386
386
  }
387
387
  // Build statics-metadata.js
388
388
  let metadataFileContents = `/*
@@ -390,7 +390,7 @@ export async function buildStaticLoader(commandLineValues) {
390
390
  */
391
391
 
392
392
  `;
393
- metadataFileContents += `\nexport const objectStoreName = ${JSON.stringify(objectStoreName)};\n`;
393
+ metadataFileContents += `\nexport const kvStoreName = ${JSON.stringify(kvStoreName)};\n`;
394
394
  metadataFileContents += `\nexport const contentAssetMetadataMap = {\n`;
395
395
  for (const [key, value] of Object.entries(contentAssetMetadataMap)) {
396
396
  metadataFileContents += ` ${JSON.stringify(key)}: ${JSON.stringify(value)},\n`;
@@ -415,7 +415,7 @@ export async function buildStaticLoader(commandLineValues) {
415
415
  `;
416
416
  fileContents += 'import { ContentAssets, ModuleAssets, PublisherServer } from "@fastly/compute-js-static-publish";\n\n';
417
417
  fileContents += 'import "@fastly/compute-js-static-publish/build/compute-js";\n\n';
418
- fileContents += 'import { objectStoreName, contentAssetMetadataMap } from "./statics-metadata";\n';
418
+ fileContents += 'import { kvStoreName, contentAssetMetadataMap } from "./statics-metadata";\n';
419
419
  // Add import statements for assets that are modules and that need to be statically imported.
420
420
  const staticImportModuleNumbers = {};
421
421
  let staticImportModuleNumber = 0;
@@ -511,7 +511,7 @@ export async function buildStaticLoader(commandLineValues) {
511
511
  autoIndex,
512
512
  };
513
513
  fileContents += `\nexport const serverConfig = ${JSON.stringify(serverConfig, null, 2)};\n`;
514
- fileContents += '\nexport const contentAssets = new ContentAssets(contentAssetMetadataMap, {objectStoreName});';
514
+ fileContents += '\nexport const contentAssets = new ContentAssets(contentAssetMetadataMap, {kvStoreName});';
515
515
  fileContents += '\nexport const moduleAssets = new ModuleAssets(moduleAssetsMap);\n';
516
516
  fileContents += '\nlet server = null;';
517
517
  fileContents += '\nexport function getServer() {' +
@@ -0,0 +1,3 @@
1
+ import type { CommandLineOptions } from "command-line-args";
2
+ export declare function cleanKVStore(commandLineValues: CommandLineOptions): Promise<void>;
3
+ //# sourceMappingURL=clean-kv-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clean-kv-store.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/clean-kv-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAc5D,wBAAsB,YAAY,CAAC,iBAAiB,EAAE,kBAAkB,iBAgEvE"}
@@ -0,0 +1,54 @@
1
+ import path from 'path';
2
+ import { generateOrLoadPublishId } from "../util/publish-id.js";
3
+ import { loadConfigFile } from "../load-config.js";
4
+ import { getKVStoreKeys, kvStoreDeleteFile } from "../util/kv-store.js";
5
+ import { loadApiKey } from "../util/fastly-api.js";
6
+ import { getKVStoreKeysFromMetadata } from "../../util/metadata.js";
7
+ export async function cleanKVStore(commandLineValues) {
8
+ const { publishId } = generateOrLoadPublishId();
9
+ const errors = [];
10
+ const { normalized: config } = await loadConfigFile(errors);
11
+ if (config == null) {
12
+ console.error("❌ Can't load static-publish.rc.js");
13
+ console.error("Run this from a compute-js-static-publish compute-js directory.");
14
+ for (const error of errors) {
15
+ console.error(error);
16
+ }
17
+ process.exitCode = 1;
18
+ return;
19
+ }
20
+ let fastlyApiContext = null;
21
+ const apiKeyResult = loadApiKey();
22
+ if (apiKeyResult == null) {
23
+ console.error("❌ Fastly API Token not provided.");
24
+ console.error("Specify one on the command line, or use the FASTLY_API_TOKEN environment variable.");
25
+ process.exitCode = 1;
26
+ return;
27
+ }
28
+ fastlyApiContext = { apiToken: apiKeyResult.apiToken };
29
+ const staticsMetadata = await import(path.resolve('./src/statics-metadata.js'));
30
+ const { kvStoreName, contentAssetMetadataMap } = staticsMetadata;
31
+ if (kvStoreName == null) {
32
+ console.error("❌ KV Store not specified.");
33
+ console.error("This only has meaning in KV Store mode.");
34
+ process.exitCode = 1;
35
+ return;
36
+ }
37
+ // TODO: Enable getting kvStoreName and publishId from command line
38
+ // These are the items that are currently in the KV Store and that belong to this publish ID.
39
+ const items = ((await getKVStoreKeys(fastlyApiContext, kvStoreName)) ?? [])
40
+ .filter(x => x.startsWith(`${publishId}:`));
41
+ // These are the items that are currently are being used.
42
+ const keys = getKVStoreKeysFromMetadata(contentAssetMetadataMap);
43
+ // So these are the items that we should be deleting.
44
+ const itemsToDelete = items.filter(x => !keys.has(x));
45
+ console.log("Publish ID: " + publishId);
46
+ console.log("KV Store contains " + items.length + " item(s) for this publish ID.");
47
+ console.log("Current site metadata contains " + keys.size + " item(s) (including compressed alternates).");
48
+ console.log("Number of items to delete: " + itemsToDelete.length);
49
+ for (const [index, item] of itemsToDelete.entries()) {
50
+ console.log("Deleting item [" + (index + 1) + "]: " + item);
51
+ await kvStoreDeleteFile(fastlyApiContext, kvStoreName, item);
52
+ }
53
+ console.log("✅ Completed.");
54
+ }
@@ -19,7 +19,7 @@ const defaultOptions = {
19
19
  name: 'compute-js-static-site',
20
20
  description: 'Compute@Edge static site',
21
21
  serviceId: undefined,
22
- objectStoreName: undefined,
22
+ kvStoreName: undefined,
23
23
  };
24
24
  // Current directory of this program that's running.
25
25
  const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
@@ -156,11 +156,11 @@ function processCommandLineArgs(commandLineValues) {
156
156
  serviceId = serviceIdValue;
157
157
  }
158
158
  }
159
- let objectStoreName;
159
+ let kvStoreName;
160
160
  {
161
- const objectStoreNameValue = commandLineValues['object-store-name'];
162
- if (objectStoreNameValue == null || typeof objectStoreNameValue === 'string') {
163
- objectStoreName = objectStoreNameValue;
161
+ const kvStoreNameValue = commandLineValues['kv-store-name'];
162
+ if (kvStoreNameValue == null || typeof kvStoreNameValue === 'string') {
163
+ kvStoreName = kvStoreNameValue;
164
164
  }
165
165
  }
166
166
  return {
@@ -175,7 +175,7 @@ function processCommandLineArgs(commandLineValues) {
175
175
  author,
176
176
  description,
177
177
  serviceId,
178
- objectStoreName,
178
+ kvStoreName,
179
179
  };
180
180
  }
181
181
  function pickKeys(keys, object) {
@@ -254,7 +254,7 @@ export function initApp(commandLineValues) {
254
254
  ...options,
255
255
  ...(preset != null ? preset.defaultOptions : {}),
256
256
  ...pickKeys(['author', 'name', 'description'], (packageJson ?? {})),
257
- ...pickKeys(['rootDir', 'publicDir', 'staticDirs', 'spa', 'notFoundPage', 'autoIndex', 'autoExt', 'author', 'name', 'description', 'serviceId', 'objectStoreName'], commandLineAppOptions),
257
+ ...pickKeys(['rootDir', 'publicDir', 'staticDirs', 'spa', 'notFoundPage', 'autoIndex', 'autoExt', 'author', 'name', 'description', 'serviceId', 'kvStoreName'], commandLineAppOptions),
258
258
  };
259
259
  if (preset != null) {
260
260
  if (!preset.check(packageJson, options)) {
@@ -365,7 +365,7 @@ export function initApp(commandLineValues) {
365
365
  const name = options.name;
366
366
  const description = options.description;
367
367
  const fastlyServiceId = options.serviceId;
368
- const objectStoreName = options.objectStoreName;
368
+ const kvStoreName = options.kvStoreName;
369
369
  function rootRelative(itemPath) {
370
370
  if (itemPath == null) {
371
371
  return null;
@@ -385,7 +385,7 @@ export function initApp(commandLineValues) {
385
385
  console.log('author :', author);
386
386
  console.log('description :', description);
387
387
  console.log('Service ID :', fastlyServiceId ?? '(None)');
388
- console.log('Object Store Name :', objectStoreName ?? '(None)');
388
+ console.log('KV Store Name :', kvStoreName ?? '(None)');
389
389
  console.log('');
390
390
  if (useWebpack) {
391
391
  console.log('Creating project with Webpack.');
@@ -514,12 +514,12 @@ ${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
514
514
  /** @type {import('@fastly/compute-js-static-publish').StaticPublisherConfig} */
515
515
  const config = {
516
516
  rootDir: ${JSON.stringify(rootDirRel)},
517
- ${(objectStoreName != null ? 'objectStore: ' + JSON.stringify(objectStoreName) : '// objectStore: false')},
517
+ ${(kvStoreName != null ? 'kvStoreName: ' + JSON.stringify(kvStoreName) : '// kvStoreName: false')},
518
518
  // excludeDirs: [ './node_modules' ],
519
519
  // excludeDotFiles: true,
520
520
  // includeWellKnown: true,
521
521
  // contentAssetInclusionTest: (filename) => true,
522
- // contentCompression: [ 'br', 'gzip' ], // For this config value, default is [] if objectStoreName is null.
522
+ // contentCompression: [ 'br', 'gzip' ], // For this config value, default is [] if kvStoreName is null.
523
523
  // moduleAssetInclusionTest: (filename) => false,
524
524
  // contentTypes: [
525
525
  // { test: /.custom$/, contentType: 'application/x-custom', text: false },
@@ -2,7 +2,7 @@
2
2
  import commandLineArgs from "command-line-args";
3
3
  import { initApp } from "./commands/init-app.js";
4
4
  import { buildStaticLoader } from "./commands/build-static.js";
5
- import { cleanObjectStore } from "./commands/clean-object-store.js";
5
+ import { cleanKVStore } from "./commands/clean-kv-store.js";
6
6
  const optionDefinitions = [
7
7
  // (optional) Should be one of:
8
8
  // - cra (or create-react-app)
@@ -63,11 +63,11 @@ const optionDefinitions = [
63
63
  { name: 'description', type: String, },
64
64
  // Fastly Service ID to be added to the fastly.toml that is generated.
65
65
  { name: 'service-id', type: String },
66
- // The name of a Fastly Object Store to hold the content assets.
66
+ // The name of a Fastly KV Store to hold the content assets.
67
67
  // It must be linked to the service specified by `--service-id`.
68
- { name: 'object-store-name', type: String },
69
- // Clean object store mode
70
- { name: 'clean-object-store', type: Boolean, },
68
+ { name: 'kv-store-name', type: String },
69
+ // Clean KV Store mode
70
+ { name: 'clean-kv-store', type: Boolean, },
71
71
  ];
72
72
  const commandLineValues = commandLineArgs(optionDefinitions);
73
73
  console.log("Fastly Compute@Edge JavaScript Static Publisher");
@@ -75,8 +75,8 @@ let mode = 'init-app';
75
75
  if (commandLineValues['build-static']) {
76
76
  mode = 'build-static';
77
77
  }
78
- else if (commandLineValues['clean-object-store']) {
79
- mode = 'clean-object-store';
78
+ else if (commandLineValues['clean-kv-store']) {
79
+ mode = 'clean-kv-store';
80
80
  }
81
81
  switch (mode) {
82
82
  case 'build-static':
@@ -85,7 +85,7 @@ switch (mode) {
85
85
  case 'init-app':
86
86
  initApp(commandLineValues);
87
87
  break;
88
- case 'clean-object-store':
89
- await cleanObjectStore(commandLineValues);
88
+ case 'clean-kv-store':
89
+ await cleanKVStore(commandLineValues);
90
90
  break;
91
91
  }
@@ -172,7 +172,7 @@ const normalizePublisherServerConfig = buildNormalizeFunctionForObject((config,
172
172
  };
173
173
  });
174
174
  const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
175
- let { rootDir, objectStore, excludeDirs, excludeDotFiles, includeWellKnown, contentAssetInclusionTest, contentCompression, moduleAssetInclusionTest, contentTypes, server, } = config;
175
+ let { rootDir, kvStoreName, excludeDirs, excludeDotFiles, includeWellKnown, contentAssetInclusionTest, contentCompression, moduleAssetInclusionTest, contentTypes, server, } = config;
176
176
  if (!isSpecified(config, 'rootDir')) {
177
177
  errors.push('rootDir must be specified.');
178
178
  }
@@ -184,18 +184,18 @@ const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
184
184
  errors.push('rootDir must be a non-empty string.');
185
185
  }
186
186
  }
187
- if (!isSpecified(config, 'objectStore')) {
188
- objectStore = null;
187
+ if (!isSpecified(config, 'kvStoreName')) {
188
+ kvStoreName = null;
189
189
  }
190
190
  else {
191
- if (isStringAndNotEmpty(objectStore) || objectStore === null) {
191
+ if (isStringAndNotEmpty(kvStoreName) || kvStoreName === null) {
192
192
  // ok
193
193
  }
194
- else if (objectStore === false) {
195
- objectStore = null;
194
+ else if (kvStoreName === false) {
195
+ kvStoreName = null;
196
196
  }
197
197
  else {
198
- errors.push('objectStore, if specified, must be a non-empty string, false, or null.');
198
+ errors.push('kvStoreName, if specified, must be a non-empty string, false, or null.');
199
199
  }
200
200
  }
201
201
  if (!isSpecified(config, 'excludeDotFiles')) {
@@ -267,7 +267,7 @@ const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
267
267
  errors.push('contentAssetInclusionTest, if specified, must be null or a function.');
268
268
  }
269
269
  if (!isSpecified(config, 'contentCompression')) {
270
- if (objectStore != null) {
270
+ if (kvStoreName != null) {
271
271
  contentCompression = ['br', 'gzip'];
272
272
  }
273
273
  else {
@@ -335,7 +335,7 @@ const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
335
335
  }
336
336
  return {
337
337
  rootDir,
338
- objectStore,
338
+ kvStoreName,
339
339
  excludeDotFiles,
340
340
  includeWellKnown,
341
341
  excludeDirs,
@@ -10,7 +10,7 @@ export type AppOptions = {
10
10
  author: string | undefined;
11
11
  description: string | undefined;
12
12
  serviceId: string | undefined;
13
- objectStoreName: string | undefined;
13
+ kvStoreName: string | undefined;
14
14
  };
15
15
  export interface IPresetBase {
16
16
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"preset-base.d.ts","sourceRoot":"","sources":["../../../src/cli/presets/preset-base.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,Y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C,UAAU,CAAC,CAAC;IACpC,KAAK,CAAC,WAAW,EAAE,GAAG,GAAG,IAAI,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC;CAC9D"}
@@ -0,0 +1,16 @@
1
+ import { FastlyApiContext } from "./fastly-api.js";
2
+ type KVStoreInfo = {
3
+ id: string;
4
+ name: string;
5
+ };
6
+ type KVStoreEntryInfo = string;
7
+ export declare function getKVStoreIdForNameMap(fastlyApiContext: FastlyApiContext): Promise<Record<string, string>>;
8
+ export declare function getKVStoreIdForName(fastlyApiContext: FastlyApiContext, kvStoreName: string): Promise<string | null>;
9
+ export declare function getKVStoreInfos(fastlyApiContext: FastlyApiContext): Promise<KVStoreInfo[]>;
10
+ export declare const _getKVStoreKeys: (fastlyApiContext: FastlyApiContext, kvStoreId: string) => Promise<string[]>;
11
+ export declare function getKVStoreKeys(fastlyApiContext: FastlyApiContext, kvStoreName: string): Promise<KVStoreEntryInfo[] | null>;
12
+ export declare function kvStoreEntryExists(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<boolean>;
13
+ export declare function kvStoreSubmitFile(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, data: Uint8Array | string): Promise<void>;
14
+ export declare function kvStoreDeleteFile(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<void>;
15
+ export {};
16
+ //# 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":"AAAA,OAAO,EAAiB,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAElE,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAUF,KAAK,gBAAgB,GAAG,MAAM,CAAC;AAS/B,wBAAsB,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAkBhH;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAIzH;AAwCD,wBAAsB,eAAe,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAchG;AAED,eAAO,MAAM,eAAe,qBApDgB,gBAAgB,yCAoD6F,CAAC;AAE1J,wBAAsB,cAAc,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAQhI;AAED,wBAAsB,kBAAkB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAa/H;AAGD,wBAAsB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBtJ;AAED,wBAAsB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB3H"}
@@ -0,0 +1,108 @@
1
+ import { callFastlyApi } from "./fastly-api.js";
2
+ const cache = new WeakMap();
3
+ export async function getKVStoreIdForNameMap(fastlyApiContext) {
4
+ const cacheEntry = cache.get(fastlyApiContext);
5
+ let kvStoreNameMap = cacheEntry?.kvStoreNameMap;
6
+ if (kvStoreNameMap != null) {
7
+ return kvStoreNameMap;
8
+ }
9
+ const kvStoreInfos = await getKVStoreInfos(fastlyApiContext);
10
+ kvStoreNameMap = {};
11
+ for (const { id, name } of kvStoreInfos) {
12
+ kvStoreNameMap[name] = id;
13
+ }
14
+ cache.set(fastlyApiContext, { ...cacheEntry, kvStoreNameMap });
15
+ return kvStoreNameMap;
16
+ }
17
+ export async function getKVStoreIdForName(fastlyApiContext, kvStoreName) {
18
+ const kvStoreNameMap = await getKVStoreIdForNameMap(fastlyApiContext);
19
+ return kvStoreNameMap[kvStoreName] ?? null;
20
+ }
21
+ function createArrayGetter() {
22
+ return function (fn) {
23
+ return async function (fastlyApiContext, ...args) {
24
+ const results = [];
25
+ let cursor = null;
26
+ while (true) {
27
+ const queryParams = new URLSearchParams();
28
+ if (cursor != null) {
29
+ queryParams.set('cursor', cursor);
30
+ }
31
+ const endpoint = fn(...args);
32
+ const response = await callFastlyApi(fastlyApiContext, endpoint, queryParams);
33
+ if (response.status !== 200) {
34
+ throw new Error('Unexpected data format');
35
+ }
36
+ const infos = await response.json();
37
+ for (const item of infos.data) {
38
+ results.push(item);
39
+ }
40
+ if (infos.meta.next_cursor === undefined) {
41
+ break;
42
+ }
43
+ cursor = infos.meta.next_cursor;
44
+ }
45
+ return results;
46
+ };
47
+ };
48
+ }
49
+ const _getKVStoreInfos = createArrayGetter()(() => `/resources/stores/kv`);
50
+ export async function getKVStoreInfos(fastlyApiContext) {
51
+ const cacheEntry = cache.get(fastlyApiContext);
52
+ let kvStoreInfos = cacheEntry?.kvStoreInfos;
53
+ if (kvStoreInfos != null) {
54
+ return kvStoreInfos;
55
+ }
56
+ kvStoreInfos = await _getKVStoreInfos(fastlyApiContext);
57
+ cache.set(fastlyApiContext, { ...cacheEntry, kvStoreInfos });
58
+ return kvStoreInfos;
59
+ }
60
+ export const _getKVStoreKeys = createArrayGetter()((kvStoreId) => `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys`);
61
+ export async function getKVStoreKeys(fastlyApiContext, kvStoreName) {
62
+ const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
63
+ if (kvStoreId == null) {
64
+ return null;
65
+ }
66
+ return await _getKVStoreKeys(fastlyApiContext, kvStoreId);
67
+ }
68
+ export async function kvStoreEntryExists(fastlyApiContext, kvStoreName, key) {
69
+ const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
70
+ if (kvStoreId == null) {
71
+ return false;
72
+ }
73
+ const endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys/${encodeURIComponent(key)}`;
74
+ const response = await callFastlyApi(fastlyApiContext, endpoint, null, { method: 'HEAD' });
75
+ return response.status === 200;
76
+ }
77
+ const encoder = new TextEncoder();
78
+ export async function kvStoreSubmitFile(fastlyApiContext, kvStoreName, key, data) {
79
+ const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
80
+ if (kvStoreId == null) {
81
+ throw new Error('KV Store not found');
82
+ }
83
+ const endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys/${encodeURIComponent(key)}`;
84
+ const body = typeof data === 'string' ? encoder.encode(data) : data;
85
+ const response = await callFastlyApi(fastlyApiContext, endpoint, null, {
86
+ method: 'PUT',
87
+ headers: {
88
+ 'content-type': 'application/octet-stream',
89
+ },
90
+ body,
91
+ });
92
+ if (response.status !== 200) {
93
+ throw new Error(`Submitting item ${key} gave error: ${response.status}`);
94
+ }
95
+ }
96
+ export async function kvStoreDeleteFile(fastlyApiContext, kvStoreName, key) {
97
+ const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
98
+ if (kvStoreId == null) {
99
+ throw new Error('KV Store not found');
100
+ }
101
+ const endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys/${encodeURIComponent(key)}`;
102
+ const response = await callFastlyApi(fastlyApiContext, endpoint, null, {
103
+ method: 'DELETE',
104
+ });
105
+ if (response.status < 200 || response.status >= 300) {
106
+ throw new Error(`Deleting item '${key}' gave error: ${response.status}`);
107
+ }
108
+ }
@@ -1,3 +1,3 @@
1
1
  import './server/assets/content-asset-wasm-inline.js';
2
- import './server/assets/content-asset-object-store.js';
2
+ import './server/assets/content-asset-kv-store.js';
3
3
  //# sourceMappingURL=compute-js.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compute-js.d.ts","sourceRoot":"","sources":["../src/compute-js.ts"],"names":[],"mappings":"AAAA,OAAO,8CAA8C,CAAC;AACtD,OAAO,+CAA+C,CAAC"}
1
+ {"version":3,"file":"compute-js.d.ts","sourceRoot":"","sources":["../src/compute-js.ts"],"names":[],"mappings":"AAAA,OAAO,8CAA8C,CAAC;AACtD,OAAO,2CAA2C,CAAC"}
@@ -1,2 +1,2 @@
1
1
  import './server/assets/content-asset-wasm-inline.js';
2
- import './server/assets/content-asset-object-store.js';
2
+ import './server/assets/content-asset-kv-store.js';
@@ -0,0 +1,18 @@
1
+ import { ContentAsset, ContentAssetMetadataMapEntry, StoreEntry } from "../../types/index.js";
2
+ import { ContentAssetMetadataMapEntryKVStore } from "../../types/content-assets.js";
3
+ import { ContentCompressionTypes } from "../../constants/compression.js";
4
+ export declare class ContentKVStoreAsset implements ContentAsset {
5
+ readonly type = "kv-store";
6
+ private readonly metadata;
7
+ private readonly kvStoreName;
8
+ private readonly sourceAndInfo;
9
+ private readonly compressedSourcesAndInfo;
10
+ constructor(metadata: ContentAssetMetadataMapEntryKVStore, kvStoreName: string);
11
+ get isLocal(): boolean;
12
+ get assetKey(): string;
13
+ getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
14
+ getBytes(): Uint8Array;
15
+ getText(): string;
16
+ getMetadata(): ContentAssetMetadataMapEntry;
17
+ }
18
+ //# sourceMappingURL=content-asset-kv-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-asset-kv-store.d.ts","sourceRoot":"","sources":["../../../src/server/assets/content-asset-kv-store.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,UAAU,EACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,mCAAmC,EACpC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,qBAAa,mBAAoB,YAAW,YAAY;IACtD,QAAQ,CAAC,IAAI,cAAc;IAE3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsC;IAE/D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IAErC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAwB;IACtD,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA6C;gBAE1E,QAAQ,EAAE,mCAAmC,EAAE,WAAW,EAAE,MAAM;IAqB9E,IAAI,OAAO,YAEV;IAED,IAAI,QAAQ,WAEX;IAEK,aAAa,CAAC,qBAAqB,GAAE,uBAAuB,EAAE,EAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IA4BjG,QAAQ,IAAI,UAAU;IAItB,OAAO,IAAI,MAAM;IAIjB,WAAW,IAAI,4BAA4B;CAI5C"}
@@ -0,0 +1,67 @@
1
+ import { KVStore } from "fastly:kv-store";
2
+ import { ContentAssets, findMatchingSourceAndInfo } from "./content-assets.js";
3
+ export class ContentKVStoreAsset {
4
+ constructor(metadata, kvStoreName) {
5
+ this.type = 'kv-store';
6
+ this.metadata = metadata;
7
+ this.kvStoreName = kvStoreName;
8
+ this.sourceAndInfo = {
9
+ source: metadata.fileInfo.kvStoreKey,
10
+ hash: metadata.fileInfo.hash,
11
+ size: metadata.fileInfo.size,
12
+ };
13
+ this.compressedSourcesAndInfo = Object.entries(metadata.compressedFileInfos)
14
+ .reduce((obj, [key, value]) => {
15
+ obj[key] = {
16
+ source: value.kvStoreKey,
17
+ hash: value.hash,
18
+ size: value.size,
19
+ };
20
+ return obj;
21
+ }, {});
22
+ }
23
+ get isLocal() {
24
+ return false;
25
+ }
26
+ get assetKey() {
27
+ return this.metadata.assetKey;
28
+ }
29
+ async getStoreEntry(acceptEncodingsGroups = []) {
30
+ const { sourceAndInfo, contentEncoding } = findMatchingSourceAndInfo(acceptEncodingsGroups, this.sourceAndInfo, encoding => this.compressedSourcesAndInfo[encoding]);
31
+ const kvStore = new KVStore(this.kvStoreName);
32
+ let retries = 3;
33
+ while (retries > 0) {
34
+ const storeEntry = await kvStore.get(sourceAndInfo.source);
35
+ if (storeEntry != null) {
36
+ const { hash, size } = sourceAndInfo;
37
+ return Object.assign(storeEntry, { contentEncoding, hash, size });
38
+ }
39
+ // Note the null does NOT mean 404. The fact that we are here means
40
+ // metadata exists for this path, and we're just trying to get the data from
41
+ // the KV Store.
42
+ // So if we're here then the data is either not available yet (in which case
43
+ // we can wait just a bit and try again), or the data was deleted.
44
+ retries--;
45
+ // We're going to wait 250ms/500ms/750ms and try again.
46
+ const delay = (3 - retries) * 250;
47
+ await new Promise(resolve => setTimeout(resolve, delay));
48
+ }
49
+ throw new Error("Asset could not be retrieved from the KV Store.");
50
+ }
51
+ getBytes() {
52
+ throw new Error("Can't getBytes() for KV Store asset");
53
+ }
54
+ getText() {
55
+ throw new Error("Can't getText() for KV Store asset");
56
+ }
57
+ getMetadata() {
58
+ return this.metadata;
59
+ }
60
+ }
61
+ ContentAssets.registerAssetBuilder('kv-store', (metadata, context) => {
62
+ const { kvStoreName } = context;
63
+ if (kvStoreName == null) {
64
+ throw new Error("Unexpected! KV Store name should be specified!!");
65
+ }
66
+ return new ContentKVStoreAsset(metadata, kvStoreName);
67
+ });
@@ -1,5 +1,5 @@
1
1
  import { includeBytes } from "fastly:experimental";
2
- import { InlineStoreEntry } from "../object-store/inline-store-entry.js";
2
+ import { InlineStoreEntry } from "../kv-store/inline-store-entry.js";
3
3
  import { ContentAssets, findMatchingSourceAndInfo } from "./content-assets.js";
4
4
  const decoder = new TextDecoder();
5
5
  export class ContentWasmInlineAsset {
@@ -1,5 +1,5 @@
1
1
  import { AssetManager } from "./asset-manager.js";
2
- import { InlineStoreEntry } from "../object-store/inline-store-entry.js";
2
+ import { InlineStoreEntry } from "../kv-store/inline-store-entry.js";
3
3
  const decoder = new TextDecoder();
4
4
  export function findMatchingSourceAndInfo(acceptEncodingsGroups, defaultSourceAndInfo, sourceAndInfoForEncodingFn) {
5
5
  let sourceAndInfo;
@@ -0,0 +1,25 @@
1
+ import { StoreEntry } from "../../types/compute.js";
2
+ export declare class InlineStoreEntry implements StoreEntry {
3
+ _consumed: boolean;
4
+ _body: ReadableStreamForBytes;
5
+ _contentEncoding: string | null;
6
+ _hash: string;
7
+ _size: number;
8
+ constructor(array: Uint8Array, contentEncoding: string | null, hash: string, size: number);
9
+ get body(): ReadableStream<Uint8Array>;
10
+ get bodyUsed(): boolean;
11
+ arrayBuffer(): Promise<ArrayBuffer>;
12
+ static decoder: TextDecoder;
13
+ text(): Promise<string>;
14
+ json(): Promise<any>;
15
+ get contentEncoding(): string | null;
16
+ get hash(): string;
17
+ get size(): number;
18
+ }
19
+ declare class ReadableStreamForBytes extends ReadableStream<Uint8Array> {
20
+ _disturbed: boolean;
21
+ constructor(array: Uint8Array);
22
+ getReader(): ReadableStreamDefaultReader<Uint8Array>;
23
+ }
24
+ export {};
25
+ //# sourceMappingURL=inline-store-entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-store-entry.d.ts","sourceRoot":"","sources":["../../../src/server/kv-store/inline-store-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKpD,qBAAa,gBAAiB,YAAW,UAAU;IACjD,SAAS,EAAE,OAAO,CAAC;IAEnB,KAAK,EAAE,sBAAsB,CAAC;IAE9B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAEhC,KAAK,EAAE,MAAM,CAAC;IAEd,KAAK,EAAE,MAAM,CAAC;gBAEF,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAQzF,IAAI,IAAI,IAAI,cAAc,CAAC,UAAU,CAAC,CAErC;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAEK,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAiCzC,MAAM,CAAC,OAAO,cAAqB;IAC7B,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAKvB,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;IAK1B,IAAI,eAAe,kBAElB;IAED,IAAI,IAAI,WAEP;IAED,IAAI,IAAI,WAEP;CACF;AAED,cAAM,sBAAuB,SAAQ,cAAc,CAAC,UAAU,CAAC;IAG7D,UAAU,UAAS;gBAEP,KAAK,EAAE,UAAU;IASpB,SAAS,IAAI,2BAA2B,CAAC,UAAU,CAAC;CA6B9D"}
@@ -0,0 +1,100 @@
1
+ // A class designed to give a Body-style interface to Uint8Array.
2
+ // The intended use case is arrays brought in from includeBytes().
3
+ class InlineStoreEntry {
4
+ constructor(array, contentEncoding, hash, size) {
5
+ this._body = new ReadableStreamForBytes(array);
6
+ this._consumed = false;
7
+ this._contentEncoding = contentEncoding;
8
+ this._hash = hash;
9
+ this._size = size;
10
+ }
11
+ get body() {
12
+ return this._body;
13
+ }
14
+ get bodyUsed() {
15
+ return this._consumed;
16
+ }
17
+ async arrayBuffer() {
18
+ if (this._consumed) {
19
+ throw new Error('Body has already been consumed');
20
+ }
21
+ if (this._body.locked) {
22
+ throw new Error('The ReadableStream body is already locked and can\'t be consumed');
23
+ }
24
+ if (this._body._disturbed) {
25
+ throw new Error('Body object should not be disturbed or locked');
26
+ }
27
+ this._consumed = true;
28
+ let result = new Uint8Array(0);
29
+ const reader = this._body.getReader();
30
+ try {
31
+ while (true) {
32
+ const { done, value } = await reader.read();
33
+ if (done) {
34
+ break;
35
+ }
36
+ const newResult = new Uint8Array(result.length + value.length);
37
+ newResult.set(result);
38
+ newResult.set(value, result.length);
39
+ result = newResult;
40
+ }
41
+ return result;
42
+ }
43
+ finally {
44
+ reader.releaseLock();
45
+ }
46
+ }
47
+ async text() {
48
+ const data = await this.arrayBuffer();
49
+ return InlineStoreEntry.decoder.decode(data);
50
+ }
51
+ async json() {
52
+ const text = await this.text();
53
+ return JSON.parse(text);
54
+ }
55
+ get contentEncoding() {
56
+ return this._contentEncoding;
57
+ }
58
+ get hash() {
59
+ return this._hash;
60
+ }
61
+ get size() {
62
+ return this._size;
63
+ }
64
+ }
65
+ InlineStoreEntry.decoder = new TextDecoder();
66
+ export { InlineStoreEntry };
67
+ class ReadableStreamForBytes extends ReadableStream {
68
+ constructor(array) {
69
+ super({
70
+ async start(controller) {
71
+ controller.enqueue(array);
72
+ controller.close();
73
+ },
74
+ });
75
+ // Closest we can get to the "disturbed" flag
76
+ this._disturbed = false;
77
+ }
78
+ getReader() {
79
+ const reader = super.getReader();
80
+ const stream = this;
81
+ // Monkey-patch read
82
+ const _read = reader.read;
83
+ reader.read = async () => {
84
+ const result = await _read.call(reader);
85
+ if (result.done) {
86
+ // NOTE: C@E Request body does not seem to get marked as "disturbed" until
87
+ // end of stream is reached either...
88
+ stream._disturbed = true;
89
+ }
90
+ return result;
91
+ };
92
+ // Monkey-patch cancel
93
+ const _cancel = reader.cancel;
94
+ reader.cancel = async (reason) => {
95
+ await _cancel.call(reader, reason);
96
+ stream._disturbed = true;
97
+ };
98
+ return reader;
99
+ }
100
+ }
@@ -11,7 +11,7 @@ export type ModuleAssetInclusionResultNormalized = {
11
11
  };
12
12
  export type StaticPublisherConfigNormalized = {
13
13
  rootDir: string;
14
- objectStore: string | null;
14
+ kvStoreName: string | null;
15
15
  excludeDirs: ExcludeDirTest[];
16
16
  excludeDotFiles: boolean;
17
17
  includeWellKnown: boolean;
@@ -14,7 +14,7 @@ export type ModuleAssetInclusionResult = {
14
14
  export type ModuleAssetInclusionTest = (assetKey: string, contentType?: string) => ModuleAssetInclusionResult | true | false | 'static-import' | null;
15
15
  export type StaticPublisherConfig = {
16
16
  rootDir: string;
17
- objectStore?: string | false | null;
17
+ kvStoreName?: string | false | null;
18
18
  excludeDirs?: (string | ExcludeDirTest)[] | string | ExcludeDirTest | null;
19
19
  excludeDotFiles?: boolean;
20
20
  includeWellKnown?: boolean;
@@ -15,8 +15,8 @@ export type ContentFileInfoForStaticPublishing = ContentFileInfo & {
15
15
  staticFilePath: string;
16
16
  };
17
17
  export type ContentFileInfoForWasmInline = ContentFileInfoForStaticPublishing;
18
- export type ContentFileInfoForObjectStore = ContentFileInfoForStaticPublishing & {
19
- objectStoreKey: string;
18
+ export type ContentFileInfoForKVStore = ContentFileInfoForStaticPublishing & {
19
+ kvStoreKey: string;
20
20
  };
21
21
  export type ContentAssetMetadataMapEntryBase<TFileInfo> = {
22
22
  assetKey: string;
@@ -35,10 +35,10 @@ export type ContentAssetMetadataMapEntryString = {
35
35
  export type ContentAssetMetadataMapEntryWasmInline = {
36
36
  type: 'wasm-inline';
37
37
  } & ContentAssetMetadataMapEntryBase<ContentFileInfoForWasmInline>;
38
- export type ContentAssetMetadataMapEntryObjectStore = {
39
- type: 'object-store';
40
- } & ContentAssetMetadataMapEntryBase<ContentFileInfoForObjectStore>;
41
- export type ContentAssetMetadataMapEntry = ContentAssetMetadataMapEntryBytes | ContentAssetMetadataMapEntryString | ContentAssetMetadataMapEntryWasmInline | ContentAssetMetadataMapEntryObjectStore;
38
+ export type ContentAssetMetadataMapEntryKVStore = {
39
+ type: 'kv-store';
40
+ } & ContentAssetMetadataMapEntryBase<ContentFileInfoForKVStore>;
41
+ export type ContentAssetMetadataMapEntry = ContentAssetMetadataMapEntryBytes | ContentAssetMetadataMapEntryString | ContentAssetMetadataMapEntryWasmInline | ContentAssetMetadataMapEntryKVStore;
42
42
  export type ContentAssetMetadataMap = {
43
43
  [assetKey: string]: ContentAssetMetadataMapEntry;
44
44
  };
@@ -1 +1 @@
1
- {"version":3,"file":"content-assets.d.ts","sourceRoot":"","sources":["../../src/types/content-assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI,OAAO,CAAC,MA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AAa,CAAC,qBAAqB,CAAC,EAAE,uBAAuB,EAAE,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACxF,QAAQ,IAAI,UAAU,CAAC;IACvB,OAAO,IAAI,MAAM,CAAC;CACnB"}
@@ -1,3 +1,3 @@
1
1
  import type { ContentAssetMetadataMap } from "../types/content-assets.js";
2
- export declare function getObjectStoreKeysFromMetadata(contentAssetMetadataMap: ContentAssetMetadataMap): Set<string>;
2
+ export declare function getKVStoreKeysFromMetadata(contentAssetMetadataMap: ContentAssetMetadataMap): Set<string>;
3
3
  //# sourceMappingURL=metadata.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/util/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAE1E,wBAAgB,8BAA8B,CAAC,uBAAuB,EAAE,uBAAuB,GAAG,GAAG,CAAC,MAAM,CAAC,CAe5G"}
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/util/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAE1E,wBAAgB,0BAA0B,CAAC,uBAAuB,EAAE,uBAAuB,GAAG,GAAG,CAAC,MAAM,CAAC,CAexG"}
@@ -1,10 +1,10 @@
1
- export function getObjectStoreKeysFromMetadata(contentAssetMetadataMap) {
1
+ export function getKVStoreKeysFromMetadata(contentAssetMetadataMap) {
2
2
  const results = new Set();
3
3
  for (const metadata of Object.values(contentAssetMetadataMap)) {
4
- if (metadata.type === 'object-store') {
5
- results.add(metadata.fileInfo.objectStoreKey);
4
+ if (metadata.type === 'kv-store') {
5
+ results.add(metadata.fileInfo.kvStoreKey);
6
6
  for (const fileInfo of Object.values(metadata.compressedFileInfos)) {
7
- results.add(fileInfo.objectStoreKey);
7
+ results.add(fileInfo.kvStoreKey);
8
8
  }
9
9
  }
10
10
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "4.2.1",
4
+ "version": "5.0.0",
5
5
  "description": "Static Publisher for Compute@Edge JavaScript",
6
6
  "main": "./build/index.js",
7
7
  "types": "./build/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "homepage": "https://github.com/fastly/compute-js-static-publish#readme",
33
33
  "dependencies": {
34
- "@fastly/js-compute": "^1.4.0",
34
+ "@fastly/js-compute": "^2.0.0",
35
35
  "command-line-args": "^5.2.1",
36
36
  "glob-to-regexp": "^0.4.1"
37
37
  },
@@ -6,5 +6,5 @@ import type {
6
6
  ContentAssetMetadataMap,
7
7
  } from "@fastly/compute-js-static-publish";
8
8
 
9
- export declare const objectStoreName: string | null;
9
+ export declare const kvStoreName: string | null;
10
10
  export declare const contentAssetMetadataMap: ContentAssetMetadataMap;