@fastly/compute-js-static-publish 4.0.0-alpha.4 → 4.1.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 (102) hide show
  1. package/README.md +51 -27
  2. package/build/cli/commands/build-static.d.ts.map +1 -1
  3. package/build/cli/commands/build-static.js +5 -4
  4. package/build/cli/commands/clean-object-store.d.ts.map +1 -1
  5. package/build/cli/commands/init-app.d.ts.map +1 -1
  6. package/build/cli/commands/init-app.js +0 -1
  7. package/build/cli/index.js +2 -0
  8. package/build/cli/presets/implementations/astro.d.ts +7 -0
  9. package/build/cli/presets/implementations/astro.d.ts.map +1 -0
  10. package/build/cli/presets/implementations/astro.js +23 -0
  11. package/build/cli/presets/implementations/vue.d.ts +7 -0
  12. package/build/cli/presets/implementations/vue.d.ts.map +1 -0
  13. package/build/cli/presets/implementations/vue.js +24 -0
  14. package/build/cli/presets/index.d.ts.map +1 -1
  15. package/build/cli/presets/index.js +4 -0
  16. package/build/compute-js.d.ts +3 -0
  17. package/build/compute-js.d.ts.map +1 -0
  18. package/build/compute-js.js +2 -0
  19. package/build/server/assets/asset-manager.d.ts +1 -0
  20. package/build/server/assets/asset-manager.d.ts.map +1 -1
  21. package/build/server/assets/asset-manager.js +3 -0
  22. package/build/server/assets/content-asset-object-store.d.ts +18 -0
  23. package/build/server/assets/content-asset-object-store.d.ts.map +1 -0
  24. package/build/server/assets/content-asset-object-store.js +67 -0
  25. package/build/server/assets/content-asset-wasm-inline.d.ts +17 -0
  26. package/build/server/assets/content-asset-wasm-inline.d.ts.map +1 -0
  27. package/build/server/assets/content-asset-wasm-inline.js +48 -0
  28. package/build/server/assets/content-assets-runtime.d.ts +2 -0
  29. package/build/server/assets/content-assets-runtime.d.ts.map +1 -0
  30. package/build/server/assets/content-assets.d.ts +33 -21
  31. package/build/server/assets/content-assets.d.ts.map +1 -1
  32. package/build/server/assets/content-assets.js +39 -85
  33. package/build/types/content-assets.d.ts +23 -7
  34. package/build/types/content-assets.d.ts.map +1 -1
  35. package/build/util/metadata.js +1 -1
  36. package/package.json +1 -1
  37. package/build/assets/asset-manager.d.ts +0 -7
  38. package/build/assets/asset-manager.d.ts.map +0 -1
  39. package/build/assets/asset-manager.js +0 -11
  40. package/build/assets/content-assets.d.ts +0 -29
  41. package/build/assets/content-assets.d.ts.map +0 -1
  42. package/build/assets/content-assets.js +0 -88
  43. package/build/assets/module-assets.d.ts +0 -23
  44. package/build/assets/module-assets.d.ts.map +0 -1
  45. package/build/assets/module-assets.js +0 -45
  46. package/build/cli/build-static.d.ts +0 -3
  47. package/build/cli/build-static.d.ts.map +0 -1
  48. package/build/cli/build-static.js +0 -524
  49. package/build/cli/clean-object-store.d.ts +0 -2
  50. package/build/cli/clean-object-store.d.ts.map +0 -1
  51. package/build/cli/cli.d.ts +0 -3
  52. package/build/cli/cli.d.ts.map +0 -1
  53. package/build/cli/cli.js +0 -77
  54. package/build/cli/init-app.d.ts +0 -3
  55. package/build/cli/init-app.d.ts.map +0 -1
  56. package/build/cli/init-app.js +0 -283
  57. package/build/presets/implementations/create-react-app.d.ts +0 -16
  58. package/build/presets/implementations/create-react-app.d.ts.map +0 -1
  59. package/build/presets/implementations/create-react-app.js +0 -34
  60. package/build/presets/implementations/docusaurus.d.ts +0 -11
  61. package/build/presets/implementations/docusaurus.d.ts.map +0 -1
  62. package/build/presets/implementations/docusaurus.js +0 -13
  63. package/build/presets/implementations/gatsby.d.ts +0 -11
  64. package/build/presets/implementations/gatsby.d.ts.map +0 -1
  65. package/build/presets/implementations/gatsby.js +0 -13
  66. package/build/presets/implementations/next.d.ts +0 -11
  67. package/build/presets/implementations/next.d.ts.map +0 -1
  68. package/build/presets/implementations/next.js +0 -13
  69. package/build/presets/implementations/sveltekit.d.ts +0 -11
  70. package/build/presets/implementations/sveltekit.d.ts.map +0 -1
  71. package/build/presets/implementations/sveltekit.js +0 -13
  72. package/build/presets/implementations/vite.d.ts +0 -11
  73. package/build/presets/implementations/vite.d.ts.map +0 -1
  74. package/build/presets/implementations/vite.js +0 -13
  75. package/build/presets/index.d.ts +0 -3
  76. package/build/presets/index.d.ts.map +0 -1
  77. package/build/presets/index.js +0 -16
  78. package/build/presets/preset-base.d.ts +0 -18
  79. package/build/presets/preset-base.d.ts.map +0 -1
  80. package/build/presets/preset-base.js +0 -1
  81. package/build/server/object-store/include-bytes-store-entry.d.ts +0 -19
  82. package/build/server/object-store/include-bytes-store-entry.d.ts.map +0 -1
  83. package/build/server/object-store/include-bytes-store-entry.js +0 -87
  84. package/build/util/data.d.ts +0 -7
  85. package/build/util/data.d.ts.map +0 -1
  86. package/build/util/data.js +0 -58
  87. package/build/util/fastly-api.d.ts +0 -10
  88. package/build/util/fastly-api.d.ts.map +0 -1
  89. package/build/util/fastly-api.js +0 -47
  90. package/build/util/files.d.ts +0 -10
  91. package/build/util/files.d.ts.map +0 -1
  92. package/build/util/files.js +0 -32
  93. package/build/util/hash.d.ts +0 -2
  94. package/build/util/hash.d.ts.map +0 -1
  95. package/build/util/hash.js +0 -8
  96. package/build/util/id.d.ts +0 -3
  97. package/build/util/id.d.ts.map +0 -1
  98. package/build/util/id.js +0 -17
  99. package/build/util/object-store.d.ts +0 -12
  100. package/build/util/object-store.d.ts.map +0 -1
  101. package/build/util/object-store.js +0 -80
  102. /package/build/{cli/clean-object-store.js → server/assets/content-assets-runtime.js} +0 -0
package/README.md CHANGED
@@ -1,6 +1,3 @@
1
- PRO TIP - If you are viewing this README in GitHub, click the hamburger menu on the row right above this to see a Table
2
- of Contents!
3
-
4
1
  # Static Publisher for JavaScript on Compute@Edge
5
2
 
6
3
  Using a static site generator to build your website? Do you simply need to serve some static files? With `compute-js-static-publish`, now you can deploy and serve everything from Fastly's blazing-fast [Compute@Edge](https://developer.fastly.com/learning/compute/).
@@ -16,6 +13,7 @@ Version 4 of this tool has some awesome new features:
16
13
  - Support for publishing files that won't necessarily be served by `PublisherServer`. File contents are made available to your application–useful, e.g., for reading data written by third-party tools, etc.
17
14
  - Makes content and metadata available to your application, via pre-package path/file.
18
15
  - Support for loading JavaScript files as code into your Compute@Edge application.
16
+ - Added presets for [Vue](https://vuejs.org/) and [Astro](https://astro.build/).
19
17
 
20
18
  If you wish to update to this version, you may need to re-scaffold your application, or follow the steps outlined in [MIGRATING.md](./MIGRATING.md).
21
19
 
@@ -140,13 +138,13 @@ Note that the files referenced by `--spa` and `--not-found-page` do not necessar
140
138
 
141
139
  These arguments are used to populate the `fastly.toml` and `package.json` files of your Compute@Edge application.
142
140
 
143
- | Option | Default | Description |
144
- |---------------------|------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
145
- | `name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute@Edge application. |
146
- | `description` | `description` from `package.json`, or `Compute@Edge static site` | The description of your Compute@Edge application. |
147
- | `author` | `author` from `package.json`, or `you@example.com` | The author of your Compute@Edge application. |
148
- | `service-id` | (None) | The ID of an existing Fastly WASM service for your Compute@Edge application. |
149
- | `object-store-name` | (None) | The name of a [Fastly Object Store](https://www.fastly.com/blog/introducing-the-compute-edge-object-store-global-persistent-storage-for-compute-functions) to hold the content assets. 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
+ | `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`. |
150
148
 
151
149
  ## Usage with frameworks and static site generators
152
150
 
@@ -158,7 +156,9 @@ These arguments are used to populate the `fastly.toml` and `package.json` files
158
156
  | `cra-eject` | `./build` | `./build/static` | For apps written using Create React App, but which have since been ejected via `npm run eject`. Does not check for `react-scripts`. |
159
157
  | `vite` | `./dist` | (None) | For apps written using [Vite](https://vitejs.dev). |
160
158
  | `sveltekit` | `./dist` | (None) | For apps written using [SvelteKit](https://kit.svelte.dev). |
159
+ | `vue` | `./dist` | (None) | For apps written using [Vue](https://vuejs.org), and that were created using [create-vue](https://github.com/vuejs/create-vue). |
161
160
  | `next` | `./out` | (None) | For apps written using [Next.js](https://nextjs.org), using `npm run export`. *1 |
161
+ | `astro` | `./dist` | (None) | For apps written using [Astro](https://astro.build) (static apps only). *2 |
162
162
  | `gatsby` | `./public` | (None) | For apps written using [Gatsby](https://www.gatsbyjs.com). |
163
163
  | `docusaurus` | `./build` | (None) | For apps written using [Docusaurus](https://docusaurus.io) |
164
164
 
@@ -167,6 +167,8 @@ You may still override any of these options individually.
167
167
  *1 - For Next.js, consider using `@fastly/next-compute-js`, a Next.js server implementation that allows you to run
168
168
  your Next.js application on Compute@Edge.
169
169
 
170
+ *2 - Astro support does not support SSR.
171
+
170
172
  ## PublisherServer
171
173
 
172
174
  `PublisherServer` is a simple yet powerful server that can be used out of the box to serve the files prepared by this tool.
@@ -208,20 +210,42 @@ For `compression`, the following values are allowed:
208
210
  * `'br'` - Brotli
209
211
  * `'gzip'` - Gzip
210
212
 
213
+ ## Associating your project with a Fastly Service
214
+
215
+ The project created by this tool is a Fastly Compute@Edge JavaScript application, complete with a `fastly.toml` file that
216
+ describes your project to the Fastly CLI.
217
+
218
+ To deploy your project to production, you deploy it to a [Fastly service](https://developer.fastly.com/reference/glossary#term-service)
219
+ in your account. Usually, you create your service automatically as part of your first deployment of the project.
220
+
221
+ In this case, `fastly.toml` has no value for `service_id` at the time you deploy, so `fastly compute publish` will prompt
222
+ you to create a Fastly service in your account for you (afterwards saving the new service's ID to your `fastly.toml` file).
223
+
224
+ Alternatively, you may deploy to a service that already exists. You can create this service using the
225
+ [Fastly CLI](https://developer.fastly.com/reference/cli/service/create/) or the [Fastly web app](https://manage.fastly.com/).
226
+ Note that since this is a Compute@Edge application, the service must be created as a Wasm service.
227
+
228
+ Before deploying your application, specify the service by setting the `service_id` value in the `fastly.toml` file to the
229
+ ID of the service. The `fastly compute publish` will deploy to the service identified by this value.
230
+
231
+ To specify the service at the time you are scaffolding the project (for example, if you are running this tool and deploying
232
+ as part of a CI process), specify the `--service-id` command line argument to populate `fastly.toml` with this value.
233
+
211
234
  ## Using the Object Store (BETA) <a name="object-store"></a>
212
235
 
213
- Starting with v4, it's now possible to upload assets to and serve them from a [Fastly Object Store](https://www.fastly.com/blog/introducing-the-compute-edge-object-store-global-persistent-storage-for-compute-functions).
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).
214
237
 
215
- Fastly Object Store (globally persistent storage for Compute@Edge applications) is currently part of a [beta release](https://docs.fastly.com/products/fastly-product-lifecycle#beta),
216
- and to use it you will need to have the feature enabled for your account.
238
+ You can enable the use of Object Store with `@fastly/compute-js-static-publish` as you scaffold your application, or
239
+ at any later time.
217
240
 
218
- To enable the use of Object Store with `@fastly/compute-js-static-publish`, you will need to perform the following steps:
241
+ At the time you enable the use of Object Store:
219
242
 
220
- * Create a service on Fastly to host your Compute@Edge application. One way to do this would be to simply run `fastly
221
- compute publish` your application.
243
+ * Your Fastly service must already exist. See [Associating your project with a Fastly Service](#associating-your-project-with-a-fastly-service) above.
222
244
 
223
- * Create an Object Store under your Fastly account. At the moment you need to use the Fastly CLI. Once the Object Store
224
- is created, it must be linked to your Fastly service using the [Resource API](https://developer.fastly.com/reference/api/services/resource/#create-resource).
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).
225
249
 
226
250
  ```shell
227
251
  # Create an object store
@@ -231,17 +255,17 @@ $ curl -i -X POST "https://api.fastly.com/resources/stores/object" -H "Fastly-Ke
231
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"
232
256
  ```
233
257
 
234
- Object Store API: https://developer.fastly.com/reference/cli/object-store/create/
235
-
236
- Resource API: https://developer.fastly.com/reference/api/services/resource/
237
-
238
- * Once the Object Store is created and linked to your service, add its name to your `static-publish.rc.js`
258
+ Once the Object Store is created and linked to your service, add its name to your `static-publish.rc.js`
239
259
  file under the `objectStore` key.
240
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
263
+ the respective files with these values.
264
+
241
265
  After you have done the above steps, go ahead and build your application as normal. If you use `fastly compute build --verbose`
242
266
  (or run `npm run build` directly), you should see output in your logs saying that files are being sent to the Object Store.
243
267
 
244
- The `statics-metadata.js` file should now show `"isInline":false` for content assets.
268
+ The `statics-metadata.js` file should now show `"type": "object-store"` for content assets.
245
269
  Your Wasm binary should also be smaller, as the content of the files are no longer inlined in the build artifact.
246
270
  You can deploy this and run it from Fastly, and the referenced files will be served from Object Store.
247
271
 
@@ -428,9 +452,9 @@ import { contentAssets } from './statics';
428
452
  // Obtain a content asset named '/public/index.html'
429
453
  const asset = contentAssets.getAsset('/public/index.html');
430
454
 
431
- // true if object's data is 'inlined' into Wasm binary
432
- // false if object's data exists in Fastly Object Store
433
- const isInline = asset.isInline;
455
+ // 'wasm-inline' if object's data is 'inlined' into Wasm binary
456
+ // 'object-store' if object's data exists in Fastly Object Store
457
+ asset.type;
434
458
 
435
459
  // Get the "store entry"
436
460
  const storeEntry = await asset.getStoreEntry();
@@ -1 +1 @@
1
- {"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build-static.ts"],"names":[],"mappings":"AA+DA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AA6IhD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBAoe5F"}
1
+ {"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build-static.ts"],"names":[],"mappings":"AA+DA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AA6IhD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBAqe5F"}
@@ -19,7 +19,7 @@
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
- // - isInline: boolean - whether this file is "inline". If false, object is in the object store.
22
+ // - type: string - where the data is available. Usually 'wasm-inline' or 'object-store'.
23
23
  // FileInfo structure
24
24
  // - hash: string - SHA-256 hash of file
25
25
  // - size: number - file size in bytes
@@ -329,7 +329,7 @@ export async function buildStaticLoader(commandLineValues) {
329
329
  });
330
330
  metadata = {
331
331
  ...entryBase,
332
- isInline,
332
+ type: 'wasm-inline',
333
333
  fileInfo: {
334
334
  ...entryBase.fileInfo,
335
335
  staticFilePath,
@@ -361,7 +361,7 @@ export async function buildStaticLoader(commandLineValues) {
361
361
  });
362
362
  metadata = {
363
363
  ...entryBase,
364
- isInline,
364
+ type: 'object-store',
365
365
  fileInfo: {
366
366
  ...entryBase.fileInfo,
367
367
  staticFilePath,
@@ -414,6 +414,7 @@ export async function buildStaticLoader(commandLineValues) {
414
414
 
415
415
  `;
416
416
  fileContents += 'import { ContentAssets, ModuleAssets, PublisherServer } from "@fastly/compute-js-static-publish";\n\n';
417
+ fileContents += 'import "@fastly/compute-js-static-publish/build/compute-js";\n\n';
417
418
  fileContents += 'import { objectStoreName, contentAssetMetadataMap } from "./statics-metadata";\n';
418
419
  // Add import statements for assets that are modules and that need to be statically imported.
419
420
  const staticImportModuleNumbers = {};
@@ -510,7 +511,7 @@ export async function buildStaticLoader(commandLineValues) {
510
511
  autoIndex,
511
512
  };
512
513
  fileContents += `\nexport const serverConfig = ${JSON.stringify(serverConfig, null, 2)};\n`;
513
- fileContents += '\nexport const contentAssets = new ContentAssets(objectStoreName, contentAssetMetadataMap);';
514
+ fileContents += '\nexport const contentAssets = new ContentAssets(contentAssetMetadataMap, {objectStoreName});';
514
515
  fileContents += '\nexport const moduleAssets = new ModuleAssets(moduleAssetsMap);\n';
515
516
  fileContents += '\nlet server = null;';
516
517
  fileContents += '\nexport function getServer() {' +
@@ -1 +1 @@
1
- {"version":3,"file":"clean-object-store.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/clean-object-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAS5D,wBAAsB,gBAAgB,CAAC,iBAAiB,EAAE,kBAAkB,iBAgE3E"}
1
+ {"version":3,"file":"clean-object-store.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/clean-object-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAc5D,wBAAsB,gBAAgB,CAAC,iBAAiB,EAAE,kBAAkB,iBAgE3E"}
@@ -1 +1 @@
1
- {"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAoPvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QAma5D"}
1
+ {"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAoPvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QAka5D"}
@@ -467,7 +467,6 @@ ${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
467
467
  fs.writeFileSync(fastlyTomlPath, fastlyTomlContent, "utf-8");
468
468
  // static-publish.rc.js
469
469
  const rootDirRel = path.relative(computeJsDir, rootDir);
470
- const publicDirRel = path.relative(computeJsDir, publicDir);
471
470
  // publicDirPrefix -- if public dir is deeper than the root dir, then
472
471
  // public dir is used as a prefix to drill into asset names.
473
472
  // e.g.,
@@ -8,7 +8,9 @@ const optionDefinitions = [
8
8
  // - cra (or create-react-app)
9
9
  // - vite
10
10
  // - sveltekit
11
+ // - vue
11
12
  // - next
13
+ // - astro
12
14
  // - gatsby
13
15
  // - docusaurus
14
16
  { name: 'preset', type: String, },
@@ -0,0 +1,7 @@
1
+ import { AppOptions, IPresetBase } from '../preset-base.js';
2
+ export declare class AstroPreset implements IPresetBase {
3
+ name: string;
4
+ defaultOptions: Partial<AppOptions>;
5
+ check(packageJson: any): boolean;
6
+ }
7
+ //# sourceMappingURL=astro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro.d.ts","sourceRoot":"","sources":["../../../../src/cli/presets/implementations/astro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,WAAY,YAAW,WAAW;IAC7C,IAAI,SAAW;IACf,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAIjC;IACF,KAAK,CAAC,WAAW,EAAE,GAAG;CAavB"}
@@ -0,0 +1,23 @@
1
+ export class AstroPreset {
2
+ constructor() {
3
+ this.name = 'Astro';
4
+ this.defaultOptions = {
5
+ rootDir: './dist',
6
+ name: 'my-astro-app',
7
+ description: 'Compute@Edge static site from Astro',
8
+ };
9
+ }
10
+ check(packageJson) {
11
+ if (packageJson == null) {
12
+ console.error("❌ Can't read/parse package.json");
13
+ console.error("Run this from a Astro project directory.");
14
+ return false;
15
+ }
16
+ if (packageJson?.dependencies?.['astro'] == null) {
17
+ console.error("❌ Can't find astro in dependencies");
18
+ console.error("Run this from a Astro project directory.");
19
+ return false;
20
+ }
21
+ return true;
22
+ }
23
+ }
@@ -0,0 +1,7 @@
1
+ import { AppOptions, IPresetBase } from '../preset-base.js';
2
+ export declare class VuePreset implements IPresetBase {
3
+ name: string;
4
+ defaultOptions: Partial<AppOptions>;
5
+ check(packageJson: any): boolean;
6
+ }
7
+ //# sourceMappingURL=vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../../../../src/cli/presets/implementations/vue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,SAAU,YAAW,WAAW;IAC3C,IAAI,SAAS;IACb,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAIjC;IACF,KAAK,CAAC,WAAW,EAAE,GAAG;CAcvB"}
@@ -0,0 +1,24 @@
1
+ export class VuePreset {
2
+ constructor() {
3
+ this.name = 'Vue';
4
+ this.defaultOptions = {
5
+ rootDir: './dist',
6
+ name: 'my-vue-app',
7
+ description: 'Compute@Edge static site from Vue (create-vue)',
8
+ };
9
+ }
10
+ check(packageJson) {
11
+ if (packageJson == null) {
12
+ console.error("❌ Can't read/parse package.json");
13
+ console.error("Run this from a Vue project directory created by create-vue.");
14
+ return false;
15
+ }
16
+ if (packageJson?.devDependencies?.['vite'] == null) {
17
+ console.error("❌ Can't find vite in dependencies");
18
+ console.error("Run this from a Vue project directory created by create-vue.");
19
+ console.log("If this is a project created with the Vue CLI, migrate it to use Vite first. Refer to the create-vue documentation at https://www.npmjs.com/package/create-vue (not authored or maintained by Fastly) for details on this process.");
20
+ return false;
21
+ }
22
+ return true;
23
+ }
24
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQ/C,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAS,WAAW,CASxD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAU/C,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAS,WAAW,CAWxD,CAAC"}
@@ -1,7 +1,9 @@
1
1
  import { CreateReactAppPreset, CreateReactAppEjectedPreset } from './implementations/create-react-app.js';
2
2
  import { VitePreset } from './implementations/vite.js';
3
3
  import { SvelteKitPreset } from './implementations/sveltekit.js';
4
+ import { VuePreset } from './implementations/vue.js';
4
5
  import { NextJsPreset } from './implementations/next.js';
6
+ import { AstroPreset } from "./implementations/astro.js";
5
7
  import { GatsbyPreset } from './implementations/gatsby.js';
6
8
  import { DocusaurusPreset } from './implementations/docusaurus.js';
7
9
  export const presets = {
@@ -10,7 +12,9 @@ export const presets = {
10
12
  'cra-eject': CreateReactAppEjectedPreset,
11
13
  'vite': VitePreset,
12
14
  'sveltekit': SvelteKitPreset,
15
+ 'vue': VuePreset,
13
16
  'next': NextJsPreset,
17
+ 'astro': AstroPreset,
14
18
  'gatsby': GatsbyPreset,
15
19
  'docusaurus': DocusaurusPreset,
16
20
  };
@@ -0,0 +1,3 @@
1
+ import './server/assets/content-asset-wasm-inline.js';
2
+ import './server/assets/content-asset-object-store.js';
3
+ //# sourceMappingURL=compute-js.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ import './server/assets/content-asset-wasm-inline.js';
2
+ import './server/assets/content-asset-object-store.js';
@@ -3,5 +3,6 @@ export declare abstract class AssetManager<TAsset> {
3
3
  protected constructor();
4
4
  protected initAsset(assetKey: string, asset: TAsset): void;
5
5
  getAsset(assetKey: string): TAsset | null;
6
+ getAssetKeys(): string[];
6
7
  }
7
8
  //# sourceMappingURL=asset-manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"asset-manager.d.ts","sourceRoot":"","sources":["../../../src/server/assets/asset-manager.ts"],"names":[],"mappings":"AAAA,8BAAsB,YAAY,CAAC,MAAM;IAEvC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAElD,SAAS;IAIT,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAInD,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAI1C"}
1
+ {"version":3,"file":"asset-manager.d.ts","sourceRoot":"","sources":["../../../src/server/assets/asset-manager.ts"],"names":[],"mappings":"AAAA,8BAAsB,YAAY,CAAC,MAAM;IAEvC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAElD,SAAS;IAIT,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAInD,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIzC,YAAY,IAAI,MAAM,EAAE;CAIzB"}
@@ -8,4 +8,7 @@ export class AssetManager {
8
8
  getAsset(assetKey) {
9
9
  return this.assets[assetKey] ?? null;
10
10
  }
11
+ getAssetKeys() {
12
+ return Object.keys(this.assets);
13
+ }
11
14
  }
@@ -0,0 +1,18 @@
1
+ import { ContentAsset, ContentAssetMetadataMapEntry, StoreEntry } from "../../types/index.js";
2
+ import { ContentAssetMetadataMapEntryObjectStore } from "../../types/content-assets.js";
3
+ import { ContentCompressionTypes } from "../../constants/compression.js";
4
+ export declare class ContentObjectStoreAsset implements ContentAsset {
5
+ readonly type = "object-store";
6
+ private readonly metadata;
7
+ private readonly objectStoreName;
8
+ private readonly sourceAndInfo;
9
+ private readonly compressedSourcesAndInfo;
10
+ constructor(metadata: ContentAssetMetadataMapEntryObjectStore, objectStoreName: 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-object-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-asset-object-store.d.ts","sourceRoot":"","sources":["../../../src/server/assets/content-asset-object-store.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,UAAU,EACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,uCAAuC,EACxC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,qBAAa,uBAAwB,YAAW,YAAY;IAC1D,QAAQ,CAAC,IAAI,kBAAkB;IAE/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0C;IAEnE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IAEzC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAwB;IACtD,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA6C;gBAE1E,QAAQ,EAAE,uCAAuC,EAAE,eAAe,EAAE,MAAM;IAqBtF,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 { ObjectStore } from "fastly:object-store";
2
+ import { ContentAssets, findMatchingSourceAndInfo } from "./content-assets.js";
3
+ export class ContentObjectStoreAsset {
4
+ constructor(metadata, objectStoreName) {
5
+ this.type = 'object-store';
6
+ this.metadata = metadata;
7
+ this.objectStoreName = objectStoreName;
8
+ this.sourceAndInfo = {
9
+ source: metadata.fileInfo.objectStoreKey,
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.objectStoreKey,
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 objectStore = new ObjectStore(this.objectStoreName);
32
+ let retries = 3;
33
+ while (retries > 0) {
34
+ const storeEntry = await objectStore.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 object 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 Object Store.");
50
+ }
51
+ getBytes() {
52
+ throw new Error("Can't getBytes() for Object Store asset");
53
+ }
54
+ getText() {
55
+ throw new Error("Can't getText() for Object Store asset");
56
+ }
57
+ getMetadata() {
58
+ return this.metadata;
59
+ }
60
+ }
61
+ ContentAssets.registerAssetBuilder('object-store', (metadata, context) => {
62
+ const { objectStoreName } = context;
63
+ if (objectStoreName == null) {
64
+ throw new Error("Unexpected! Object Store should be specified!!");
65
+ }
66
+ return new ContentObjectStoreAsset(metadata, objectStoreName);
67
+ });
@@ -0,0 +1,17 @@
1
+ import { ContentAsset, ContentAssetMetadataMapEntry, StoreEntry } from "../../types/index.js";
2
+ import { ContentAssetMetadataMapEntryWasmInline } from "../../types/content-assets.js";
3
+ import { ContentCompressionTypes } from "../../constants/compression.js";
4
+ export declare class ContentWasmInlineAsset implements ContentAsset {
5
+ readonly type = "wasm-inline";
6
+ private readonly metadata;
7
+ private readonly sourceAndInfo;
8
+ private readonly compressedSourcesAndInfo;
9
+ constructor(metadata: ContentAssetMetadataMapEntryWasmInline);
10
+ get isLocal(): boolean;
11
+ get assetKey(): string;
12
+ getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
13
+ getBytes(): Uint8Array;
14
+ getText(): string;
15
+ getMetadata(): ContentAssetMetadataMapEntry;
16
+ }
17
+ //# sourceMappingURL=content-asset-wasm-inline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-asset-wasm-inline.d.ts","sourceRoot":"","sources":["../../../src/server/assets/content-asset-wasm-inline.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,UAAU,EACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,sCAAsC,EACvC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAMzE,qBAAa,sBAAuB,YAAW,YAAY;IACzD,QAAQ,CAAC,IAAI,iBAAiB;IAE9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyC;IAElE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAC1D,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAiD;gBAE9E,QAAQ,EAAE,sCAAsC;IAoB5D,IAAI,OAAO,YAEV;IAED,IAAI,QAAQ,WAEX;IAEK,aAAa,CAAC,qBAAqB,GAAE,uBAAuB,EAAE,EAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IAMjG,QAAQ,IAAI,UAAU;IAItB,OAAO,IAAI,MAAM;IAOjB,WAAW,IAAI,4BAA4B;CAG5C"}
@@ -0,0 +1,48 @@
1
+ import { includeBytes } from "fastly:experimental";
2
+ import { InlineStoreEntry } from "../object-store/inline-store-entry.js";
3
+ import { ContentAssets, findMatchingSourceAndInfo } from "./content-assets.js";
4
+ const decoder = new TextDecoder();
5
+ export class ContentWasmInlineAsset {
6
+ constructor(metadata) {
7
+ this.type = 'wasm-inline';
8
+ this.metadata = metadata;
9
+ this.sourceAndInfo = {
10
+ source: includeBytes(metadata.fileInfo.staticFilePath),
11
+ hash: metadata.fileInfo.hash,
12
+ size: metadata.fileInfo.size,
13
+ };
14
+ this.compressedSourcesAndInfo = Object.entries(metadata.compressedFileInfos)
15
+ .reduce((obj, [key, value]) => {
16
+ obj[key] = {
17
+ source: includeBytes(value.staticFilePath),
18
+ hash: value.hash,
19
+ size: value.size,
20
+ };
21
+ return obj;
22
+ }, {});
23
+ }
24
+ get isLocal() {
25
+ return true;
26
+ }
27
+ get assetKey() {
28
+ return this.metadata.assetKey;
29
+ }
30
+ async getStoreEntry(acceptEncodingsGroups = []) {
31
+ const { sourceAndInfo, contentEncoding } = findMatchingSourceAndInfo(acceptEncodingsGroups, this.sourceAndInfo, encoding => this.compressedSourcesAndInfo[encoding]);
32
+ const { source, hash, size } = sourceAndInfo;
33
+ return new InlineStoreEntry(source, contentEncoding, hash, size);
34
+ }
35
+ getBytes() {
36
+ return this.sourceAndInfo.source;
37
+ }
38
+ getText() {
39
+ if (!this.metadata.text) {
40
+ throw new Error("Can't getText() for non-text content");
41
+ }
42
+ return decoder.decode(this.sourceAndInfo.source);
43
+ }
44
+ getMetadata() {
45
+ return this.metadata;
46
+ }
47
+ }
48
+ ContentAssets.registerAssetBuilder('wasm-inline', metadata => new ContentWasmInlineAsset(metadata));
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=content-assets-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-assets-runtime.d.ts","sourceRoot":"","sources":["../../../src/server/assets/content-assets-runtime.ts"],"names":[],"mappings":""}
@@ -1,33 +1,45 @@
1
1
  import { AssetManager } from "./asset-manager.js";
2
- import type { ContentAsset, ContentAssetMetadataMap, ContentAssetMetadataMapEntry, ContentAssetMetadataMapEntryInline, ContentAssetMetadataMapEntryObjectStore } from "../../types/content-assets.js";
2
+ import type { ContentAsset, ContentAssetMetadataMap, ContentAssetMetadataMapEntry, ContentAssetMetadataMapEntryBytes, ContentAssetMetadataMapEntryString } from "../../types/content-assets.js";
3
3
  import type { StoreEntry } from "../../types/compute.js";
4
4
  import type { ContentCompressionTypes } from "../../constants/compression.js";
5
- export declare class ContentInlineAsset implements ContentAsset {
6
- readonly isInline: boolean;
7
- private readonly metadata;
8
- private readonly sourceAndInfo;
9
- private readonly compressedSourcesAndInfo;
10
- constructor(metadata: ContentAssetMetadataMapEntryInline);
5
+ export type SourceAndInfo<TSource> = {
6
+ source: TSource;
7
+ hash: string;
8
+ size: number;
9
+ };
10
+ type SourceAndInfoForEncodingFn<TSource> = (contentEncoding: ContentCompressionTypes) => SourceAndInfo<TSource> | undefined;
11
+ export declare function findMatchingSourceAndInfo<TSource>(acceptEncodingsGroups: ContentCompressionTypes[][], defaultSourceAndInfo: SourceAndInfo<TSource>, sourceAndInfoForEncodingFn: SourceAndInfoForEncodingFn<TSource>): {
12
+ sourceAndInfo: SourceAndInfo<TSource>;
13
+ contentEncoding: "br" | "gzip" | null;
14
+ };
15
+ declare abstract class ContentRuntimeAsset<TMetadataMapEntry extends ContentAssetMetadataMapEntry> {
16
+ protected readonly metadata: TMetadataMapEntry;
17
+ protected sourceAndInfo: SourceAndInfo<Uint8Array>;
18
+ protected constructor(metadata: TMetadataMapEntry, sourceAndInfo: SourceAndInfo<Uint8Array>);
19
+ get isLocal(): boolean;
11
20
  get assetKey(): string;
12
- getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
21
+ getStoreEntry(): Promise<StoreEntry>;
13
22
  getBytes(): Uint8Array;
14
23
  getText(): string;
15
24
  getMetadata(): ContentAssetMetadataMapEntry;
16
25
  }
17
- export declare class ContentObjectStoreAsset implements ContentAsset {
18
- readonly isInline: boolean;
19
- private readonly metadata;
20
- private readonly objectStoreName;
21
- private readonly sourceAndInfo;
22
- private readonly compressedSourcesAndInfo;
23
- constructor(metadata: ContentAssetMetadataMapEntryObjectStore, objectStoreName: string);
24
- get assetKey(): string;
25
- getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
26
- getBytes(): Uint8Array;
27
- getText(): string;
28
- getMetadata(): ContentAssetMetadataMapEntry;
26
+ export declare class ContentBytesAsset extends ContentRuntimeAsset<ContentAssetMetadataMapEntryBytes> implements ContentAsset {
27
+ readonly type = "bytes";
28
+ constructor(metadata: ContentAssetMetadataMapEntryBytes);
29
+ }
30
+ export declare class ContentStringAsset extends ContentRuntimeAsset<ContentAssetMetadataMapEntryString> implements ContentAsset {
31
+ readonly type = "string";
32
+ static encoder: TextEncoder;
33
+ constructor(metadata: ContentAssetMetadataMapEntryString);
29
34
  }
35
+ export type AssetBuilder<TType extends string> = (metadata: ContentAssetMetadataMapEntry & {
36
+ type: TType;
37
+ }, assetBuilderContext: AssetBuilderContext) => ContentAsset;
38
+ type AssetBuilderContext = any;
30
39
  export declare class ContentAssets extends AssetManager<ContentAsset> {
31
- constructor(objectStoreName: string | null, contentAssetMetadataMap: ContentAssetMetadataMap);
40
+ static builders: Record<string, AssetBuilder<any>>;
41
+ constructor(contentAssetMetadataMap: ContentAssetMetadataMap, assetBuilderContext?: AssetBuilderContext);
42
+ static registerAssetBuilder<TType extends string>(type: TType, builder: AssetBuilder<TType>): void;
32
43
  }
44
+ export {};
33
45
  //# sourceMappingURL=content-assets.d.ts.map