@fastly/compute-js-static-publish 6.1.1 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -51
- package/build/cli/commands/build-static.js +1 -1
- package/build/cli/commands/init-app.d.ts.map +1 -1
- package/build/cli/commands/init-app.js +5 -3
- package/package.json +1 -1
- package/build/cli/commands/clean-object-store.d.ts +0 -3
- package/build/cli/commands/clean-object-store.d.ts.map +0 -1
- package/build/cli/commands/clean-object-store.js +0 -54
- package/build/cli/util/object-store.d.ts +0 -16
- package/build/cli/util/object-store.d.ts.map +0 -1
- package/build/cli/util/object-store.js +0 -108
- package/build/server/assets/content-asset-object-store.d.ts +0 -18
- package/build/server/assets/content-asset-object-store.d.ts.map +0 -1
- package/build/server/assets/content-asset-object-store.js +0 -67
- package/build/server/assets/content-assets-runtime.d.ts +0 -2
- package/build/server/assets/content-assets-runtime.d.ts.map +0 -1
- package/build/server/assets/content-assets-runtime.js +0 -1
- package/build/server/object-store/inline-store-entry.d.ts +0 -25
- package/build/server/object-store/inline-store-entry.d.ts.map +0 -1
- package/build/server/object-store/inline-store-entry.js +0 -100
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Node 18 or newer is required during the build step, as we now rely on its `exper
|
|
|
10
10
|
|
|
11
11
|
You have some HTML files, along with some accompanying CSS, JavaScript, image, and font files in a directory. Perhaps you've used a framework or static site generator to build these files.
|
|
12
12
|
|
|
13
|
-
Assuming the root
|
|
13
|
+
Assuming the root directory that contains your static files is `./public`,
|
|
14
14
|
|
|
15
15
|
### 1. Run `compute-js-static-publish`
|
|
16
16
|
|
|
@@ -18,28 +18,43 @@ Assuming the root of your output directory is `./public`,
|
|
|
18
18
|
npx @fastly/compute-js-static-publish@latest --root-dir=./public
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
This will generate a Compute application at `./compute-js`. It will add a default `./src/index.js` file that instantiates the [`PublisherServer`](#publisherserver) class and runs it to serve the static files from your project.
|
|
21
|
+
This will generate a Compute application at `./compute-js`. It will add a default `./compute-js/src/index.js` file that instantiates the [`PublisherServer`](#publisherserver) class and runs it to serve the static files from your project.
|
|
22
22
|
|
|
23
|
-
>
|
|
23
|
+
> [!TIP]
|
|
24
|
+
> This process creates a `./compute-js/static-publish.rc.js` to hold your configuration. This, as well as the other files created in your new Compute program at `./compute-js`, can be committed to source control (except for the ones we specify in `.gitignore`!)
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
> [!IMPORTANT]
|
|
27
|
+
> This step generates an application that includes your files and a program that serves them, and needs to be run only once. To make modifications to your application, simply make changes to your static files and rebuild it. Read the rest of this section for more details.
|
|
26
28
|
|
|
27
|
-
### 2. Test your application
|
|
29
|
+
### 2. Test your application locally
|
|
30
|
+
|
|
31
|
+
The `start` script builds and runs your application using [Fastly's local development server](https://developer.fastly.com/learning/compute/testing/#running-a-local-testing-server).
|
|
28
32
|
|
|
29
33
|
```shell
|
|
30
34
|
cd ./compute-js
|
|
31
35
|
npm install
|
|
32
|
-
|
|
36
|
+
npm run start
|
|
33
37
|
```
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
The build process scans your `./public` directory to generate files in the `./compute-js/static-publisher` directory. These files are packaged into your application's Wasm binary.
|
|
40
|
+
|
|
41
|
+
Once your application is running, your files will be served under `http://127.0.0.1:7676/` at the corresponding paths relative to the `./public` directory. For example, making a request to `http://127.0.0.1:7676/foo/bar.html` will attempt to serve the file at `./public/foo/bar.html`.
|
|
42
|
+
|
|
43
|
+
### 3. Make changes to your application
|
|
44
|
+
|
|
45
|
+
Now, you're free to make changes to your static files. Add, modify, or remove files in the `./public` directory, and then re-build and re-run your application by typing `npm run start` again.
|
|
46
|
+
|
|
47
|
+
Each time you re-build the project, `compute-js-static-publish` will re-scan your `./public` directory and regenerate the files in the `./compute-js/static-publisher` directory.
|
|
48
|
+
|
|
49
|
+
> [!TIP]
|
|
50
|
+
> You can make further customizations to the behavior of your application, such as specifying directories of your static files, specifying whether to use GZIP compression on your files, specifying custom MIME types of your files, and more. You can also run custom code alongside the default server behavior, or even access the contents of the files directly from custom code. See [Advanced Usages](#advanced-usages) below for details. Rebuilding will not modify the files in your `./compute-js/src` directory, so feel safe making customizations to your code.
|
|
36
51
|
|
|
37
|
-
|
|
52
|
+
### 4. When you're ready to go live, deploy your Compute service
|
|
38
53
|
|
|
39
|
-
|
|
54
|
+
The `deploy` script builds and [publishes your application to a Compute service in your Fastly account](https://developer.fastly.com/reference/cli/compute/publish/).
|
|
40
55
|
|
|
41
56
|
```shell
|
|
42
|
-
|
|
57
|
+
npm run deploy
|
|
43
58
|
```
|
|
44
59
|
|
|
45
60
|
## Features
|
|
@@ -78,7 +93,8 @@ If the files in `--root-dir` have changed, then a new set of files will be publi
|
|
|
78
93
|
During publishing, this tool supports pre-compression of content. By default, your assets are compressed using the Brotli
|
|
79
94
|
and gzip algorithms, and then stored alongside the original files in your Wasm binary (or [KV Store](#kv-store)).
|
|
80
95
|
|
|
81
|
-
>
|
|
96
|
+
> [!IMPORTANT]
|
|
97
|
+
> By default, pre-compressed content assets are not generated when the KV Store is not used.
|
|
82
98
|
This is done to prevent the inclusion multiple of copies of each asset from making the Wasm binary too large.
|
|
83
99
|
If you want to pre-compress assets when not using KV Store, add a value for 'contentCompression' to your
|
|
84
100
|
`static-publish.rc.js` file.
|
|
@@ -102,31 +118,31 @@ Any configuration options will be written to a `static-publish.rc.js` file, and
|
|
|
102
118
|
application.
|
|
103
119
|
|
|
104
120
|
On subsequent builds of your Compute application, `compute-js-static-publish` will run with a special flag, `build-static`,
|
|
105
|
-
reading from stored configuration, then scanning the `--public-dir` directory to recreate `./
|
|
121
|
+
reading from stored configuration, then scanning the `--public-dir` directory to recreate `./compute-js/static-publisher/statics.js`.
|
|
106
122
|
|
|
107
123
|
Any relative file and directory paths passed at the command line are handled as relative to the current directory.
|
|
108
124
|
|
|
109
125
|
### Publishing options:
|
|
110
126
|
|
|
111
|
-
| Option
|
|
112
|
-
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
|
|
|
127
|
+
| Option | Default | Description |
|
|
128
|
+
|-----------------------------|------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
129
|
+
| `--preset` | (None) | Apply default options from a specified preset. See ["Frameworks and Static Site Generators"](#usage-with-frameworks-and-static-site-generators). |
|
|
130
|
+
| `--output` | `./compute-js` | The directory in which to create the Compute application. |
|
|
131
|
+
| `--static-content-root-dir` | (output directory) + `/static-publisher` | The directory under the Compute application where static asset and metadata are written. |
|
|
132
|
+
| `--root-dir` | (None) | **Required**. The root of the directory that contains the files to include in the publishing. All files you wish to include must reside under this root. |
|
|
117
133
|
|
|
118
134
|
### Server options:
|
|
119
135
|
|
|
120
136
|
Used to populate the `server` key under `static-publish.rc.js`.
|
|
121
137
|
|
|
122
|
-
| Option
|
|
123
|
-
|
|
124
|
-
|
|
|
125
|
-
|
|
|
126
|
-
|
|
|
127
|
-
|
|
|
128
|
-
|
|
|
129
|
-
|
|
|
138
|
+
| Option | Default | Description |
|
|
139
|
+
|--------------------|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
140
|
+
| `--public-dir` | <root-dir> | The directory that contains your website's public files. |
|
|
141
|
+
| `--static-dir` | (None) | Any directories under `--public-dir` that contain the website's static assets that will be served with a very long TTL. You can specify as many such directories as you wish, by listing multiple items. |
|
|
142
|
+
| `--auto-ext` | `.html,.htm` | Specify automatic file extensions. |
|
|
143
|
+
| `--auto-index` | `index.html,index.htm` | Specify filenames for automatically serving an index file. |
|
|
144
|
+
| `--spa` | (None) | Path to a fallback file for SPA applications. |
|
|
145
|
+
| `--not-found-page` | `<public-dir>/404.html` | Path to a fallback file for 404 Not Found. |
|
|
130
146
|
|
|
131
147
|
See [PublisherServer](#publisherserver) for more information about these features.
|
|
132
148
|
|
|
@@ -138,13 +154,13 @@ Note that the files referenced by `--spa` and `--not-found-page` do not necessar
|
|
|
138
154
|
|
|
139
155
|
These arguments are used to populate the `fastly.toml` and `package.json` files of your Compute application.
|
|
140
156
|
|
|
141
|
-
| Option
|
|
142
|
-
|
|
143
|
-
|
|
|
144
|
-
|
|
|
145
|
-
|
|
|
146
|
-
|
|
|
147
|
-
|
|
|
157
|
+
| Option | Default | Description |
|
|
158
|
+
|-------------------|--------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
159
|
+
| `--name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute application. |
|
|
160
|
+
| `--description` | `description` from `package.json`, or `Compute static site` | The description of your Compute application. |
|
|
161
|
+
| `--author` | `author` from `package.json`, or `you@example.com` | The author of your Compute application. |
|
|
162
|
+
| `--service-id` | (None) | The ID of an existing Fastly WASM service for your Compute application. |
|
|
163
|
+
| `--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
164
|
|
|
149
165
|
## Usage with frameworks and static site generators
|
|
150
166
|
|
|
@@ -218,23 +234,29 @@ describes your project to the Fastly CLI.
|
|
|
218
234
|
To deploy your project to production, you deploy it to a [Fastly service](https://developer.fastly.com/reference/glossary#term-service)
|
|
219
235
|
in your account. Usually, you create your service automatically as part of your first deployment of the project.
|
|
220
236
|
|
|
221
|
-
In this case, `fastly.toml` has no value for `service_id` at the time you deploy, so
|
|
222
|
-
you to create a Fastly service in your account
|
|
237
|
+
In this case, `fastly.toml` has no value for `service_id` at the time you deploy, so the Fastly CLI will prompt
|
|
238
|
+
you to create a Fastly service in your account, after which it will save the new service's ID to your `fastly.toml` file.
|
|
223
239
|
|
|
224
240
|
Alternatively, you may deploy to a service that already exists. You can create this service using the
|
|
225
241
|
[Fastly CLI](https://developer.fastly.com/reference/cli/service/create/) or the [Fastly web app](https://manage.fastly.com/).
|
|
226
242
|
Note that since this is a Compute application, the service must be created as a Wasm service.
|
|
227
243
|
|
|
228
244
|
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
|
|
245
|
+
ID of the service. The Fastly CLI will deploy to the service identified by this value.
|
|
230
246
|
|
|
231
247
|
To specify the service at the time you are scaffolding the project (for example, if you are running this tool and deploying
|
|
232
248
|
as part of a CI process), specify the `--service-id` command line argument to populate `fastly.toml` with this value.
|
|
233
249
|
|
|
234
|
-
## Using the KV Store (BETA)
|
|
250
|
+
## Using the KV Store (BETA)
|
|
251
|
+
|
|
252
|
+
<div id="kv-store"></div>
|
|
235
253
|
|
|
236
254
|
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
255
|
|
|
256
|
+
When this mode is enabled, you build your application as normal, and as a step during the build, your files
|
|
257
|
+
are uploaded to the Fastly KV Store, and metadata in the application is marked to source them from there instead
|
|
258
|
+
of from bytes in the Wasm binary.
|
|
259
|
+
|
|
238
260
|
You can enable the use of KV Store with `@fastly/compute-js-static-publish` as you scaffold your application, or
|
|
239
261
|
at any later time.
|
|
240
262
|
|
|
@@ -245,25 +267,33 @@ At the time you enable the use of KV Store:
|
|
|
245
267
|
* Your KV Store must already exist under the same Fastly account, and be linked to the service.
|
|
246
268
|
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
269
|
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
|
|
270
|
+
Once the KV Store is created, you must link it to your Fastly service using the [Resource API](https://developer.fastly.com/reference/api/services/resource/#create-resource).
|
|
249
271
|
|
|
250
|
-
```shell
|
|
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"}'
|
|
272
|
+
```shell
|
|
273
|
+
# Create a KV Store
|
|
274
|
+
$ 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"}'
|
|
275
|
+
|
|
276
|
+
# Link the KV Store to a service
|
|
277
|
+
$ 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"
|
|
278
|
+
```
|
|
253
279
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
280
|
+
Once the KV Store is created and linked to your service, add its name to your `static-publish.rc.js`
|
|
281
|
+
file under the `kvStoreName` key.
|
|
282
|
+
|
|
283
|
+
To specify the KV Store at the time you are scaffolding the project (for example, if you are running this tool and
|
|
284
|
+
deploying as part of a CI process), specify the `--service-id` and `--kv-store-name` command line arguments to populate
|
|
285
|
+
the respective files with these values.
|
|
257
286
|
|
|
258
|
-
|
|
259
|
-
|
|
287
|
+
After you have performed the above steps, go ahead and build your application as normal.
|
|
288
|
+
As a new step during the build process, the tool will send these files to the KV Store.
|
|
260
289
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
290
|
+
> [!IMPORTANT]
|
|
291
|
+
> This step writes to your KV Store. When building your application, you must set the environment variable `FASTLY_API_TOKEN` to a Fastly API token that has access to write to this KV Store.
|
|
292
|
+
>
|
|
293
|
+
> Alternatively, if this environment variable is not found, the tool will attempt to detect an API token by calling `fastly profile token`.
|
|
264
294
|
|
|
265
|
-
|
|
266
|
-
(or
|
|
295
|
+
> [!TIP]
|
|
296
|
+
> By running `npx @fastly/cli compute build --verbose` (or `npm run build` directly), you should see output in your logs saying that files are being sent to the KV Store.
|
|
267
297
|
|
|
268
298
|
The `statics-metadata.js` file should now show `"type": "kv-store"` for content assets.
|
|
269
299
|
Your Wasm binary should also be smaller, as the content of the files are no longer inlined in the build artifact.
|
|
@@ -162,7 +162,7 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
162
162
|
const apiKeyResult = loadApiKey();
|
|
163
163
|
if (apiKeyResult == null) {
|
|
164
164
|
console.error("❌ Fastly API Token not provided.");
|
|
165
|
-
console.error("
|
|
165
|
+
console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
166
166
|
process.exitCode = 1;
|
|
167
167
|
return;
|
|
168
168
|
}
|
|
@@ -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;AAiQvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,
|
|
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;AAiQvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QAud5D"}
|
|
@@ -450,6 +450,7 @@ ${staticFiles}
|
|
|
450
450
|
author,
|
|
451
451
|
type: 'module',
|
|
452
452
|
devDependencies: {
|
|
453
|
+
"@fastly/cli": "^10.14.0",
|
|
453
454
|
'@fastly/compute-js-static-publish': computeJsStaticPublisherVersion,
|
|
454
455
|
},
|
|
455
456
|
dependencies: {
|
|
@@ -461,7 +462,8 @@ ${staticFiles}
|
|
|
461
462
|
license: 'UNLICENSED',
|
|
462
463
|
private: true,
|
|
463
464
|
scripts: {
|
|
464
|
-
|
|
465
|
+
start: "fastly compute serve",
|
|
466
|
+
deploy: "fastly compute publish",
|
|
465
467
|
prebuild: 'npx @fastly/compute-js-static-publish --build-static',
|
|
466
468
|
build: 'js-compute-runtime ./src/index.js ./bin/main.wasm'
|
|
467
469
|
},
|
|
@@ -617,11 +619,11 @@ async function handleRequest(event) {
|
|
|
617
619
|
console.log('To run your Compute application locally:');
|
|
618
620
|
console.log('');
|
|
619
621
|
console.log(' cd ' + COMPUTE_JS_DIR);
|
|
620
|
-
console.log('
|
|
622
|
+
console.log(' npm run start');
|
|
621
623
|
console.log('');
|
|
622
624
|
console.log('To build and deploy to your Compute service:');
|
|
623
625
|
console.log('');
|
|
624
626
|
console.log(' cd ' + COMPUTE_JS_DIR);
|
|
625
|
-
console.log('
|
|
627
|
+
console.log(' npm run deploy');
|
|
626
628
|
console.log('');
|
|
627
629
|
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
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,54 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { generateOrLoadPublishId } from "../util/publish-id.js";
|
|
3
|
-
import { loadConfigFile } from "../load-config.js";
|
|
4
|
-
import { getObjectStoreKeys, objectStoreDeleteFile } from "../util/object-store.js";
|
|
5
|
-
import { loadApiKey } from "../util/fastly-api.js";
|
|
6
|
-
import { getObjectStoreKeysFromMetadata } from "../../util/metadata.js";
|
|
7
|
-
export async function cleanObjectStore(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 { objectStoreName, contentAssetMetadataMap } = staticsMetadata;
|
|
31
|
-
if (objectStoreName == null) {
|
|
32
|
-
console.error("❌ Object store not specified.");
|
|
33
|
-
console.error("This only has meaning in object store mode.");
|
|
34
|
-
process.exitCode = 1;
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
// TODO: Enable getting objectStoreName and publishId from command line
|
|
38
|
-
// These are the items that are currently in the object store and that belong to this publish ID.
|
|
39
|
-
const items = ((await getObjectStoreKeys(fastlyApiContext, objectStoreName)) ?? [])
|
|
40
|
-
.filter(x => x.startsWith(`${publishId}:`));
|
|
41
|
-
// These are the items that are currently are being used.
|
|
42
|
-
const keys = getObjectStoreKeysFromMetadata(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("Object 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 objectStoreDeleteFile(fastlyApiContext, objectStoreName, item);
|
|
52
|
-
}
|
|
53
|
-
console.log("✅ Completed.");
|
|
54
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FastlyApiContext } from "./fastly-api.js";
|
|
2
|
-
export declare function getObjectStoreIdForNameMap(fastlyApiContext: FastlyApiContext): Promise<Record<string, string>>;
|
|
3
|
-
export declare function getObjectStoreIdForName(fastlyApiContext: FastlyApiContext, objectStoreName: string): Promise<string | null>;
|
|
4
|
-
type ObjectStoreInfo = {
|
|
5
|
-
id: string;
|
|
6
|
-
name: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function getObjectStoreInfos(fastlyApiContext: FastlyApiContext): Promise<ObjectStoreInfo[]>;
|
|
9
|
-
type ObjectStoreEntryInfo = string;
|
|
10
|
-
export declare const _getObjectStoreKeys: (fastlyApiContext: FastlyApiContext, objectStoreId: string) => Promise<string[]>;
|
|
11
|
-
export declare function getObjectStoreKeys(fastlyApiContext: FastlyApiContext, objectStoreName: string): Promise<ObjectStoreEntryInfo[] | null>;
|
|
12
|
-
export declare function objectStoreEntryExists(fastlyApiContext: FastlyApiContext, objectStoreName: string, key: string): Promise<boolean>;
|
|
13
|
-
export declare function objectStoreSubmitFile(fastlyApiContext: FastlyApiContext, objectStoreName: string, key: string, data: Uint8Array | string): Promise<void>;
|
|
14
|
-
export declare function objectStoreDeleteFile(fastlyApiContext: FastlyApiContext, objectStoreName: string, key: string): Promise<void>;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=object-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object-store.d.ts","sourceRoot":"","sources":["../../../src/cli/util/object-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AASlE,wBAAsB,0BAA0B,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAkBpH;AAED,wBAAsB,uBAAuB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAIjI;AA8CD,KAAK,eAAe,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAIF,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAcxG;AAED,KAAK,oBAAoB,GAAG,MAAM,CAAC;AAEnC,eAAO,MAAM,mBAAmB,qBA3DY,gBAAgB,6CA2DiH,CAAC;AAE9K,wBAAsB,kBAAkB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,EAAE,GAAG,IAAI,CAAC,CAQ5I;AAED,wBAAsB,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAavI;AAGD,wBAAsB,qBAAqB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsB9J;AAED,wBAAsB,qBAAqB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBnI"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { callFastlyApi } from "./fastly-api.js";
|
|
2
|
-
const cache = new WeakMap();
|
|
3
|
-
export async function getObjectStoreIdForNameMap(fastlyApiContext) {
|
|
4
|
-
const cacheEntry = cache.get(fastlyApiContext);
|
|
5
|
-
let objectStoreNameMap = cacheEntry?.objectStoreNameMap;
|
|
6
|
-
if (objectStoreNameMap != null) {
|
|
7
|
-
return objectStoreNameMap;
|
|
8
|
-
}
|
|
9
|
-
const objectStoreInfos = await getObjectStoreInfos(fastlyApiContext);
|
|
10
|
-
objectStoreNameMap = {};
|
|
11
|
-
for (const { id, name } of objectStoreInfos) {
|
|
12
|
-
objectStoreNameMap[name] = id;
|
|
13
|
-
}
|
|
14
|
-
cache.set(fastlyApiContext, { ...cacheEntry, objectStoreNameMap });
|
|
15
|
-
return objectStoreNameMap;
|
|
16
|
-
}
|
|
17
|
-
export async function getObjectStoreIdForName(fastlyApiContext, objectStoreName) {
|
|
18
|
-
const objectStoreNameMap = await getObjectStoreIdForNameMap(fastlyApiContext);
|
|
19
|
-
return objectStoreNameMap[objectStoreName] ?? 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 _getObjectStoreInfos = createArrayGetter()(() => `/resources/stores/object`);
|
|
50
|
-
export async function getObjectStoreInfos(fastlyApiContext) {
|
|
51
|
-
const cacheEntry = cache.get(fastlyApiContext);
|
|
52
|
-
let objectStoreInfos = cacheEntry?.objectStoreInfos;
|
|
53
|
-
if (objectStoreInfos != null) {
|
|
54
|
-
return objectStoreInfos;
|
|
55
|
-
}
|
|
56
|
-
objectStoreInfos = await _getObjectStoreInfos(fastlyApiContext);
|
|
57
|
-
cache.set(fastlyApiContext, { ...cacheEntry, objectStoreInfos });
|
|
58
|
-
return objectStoreInfos;
|
|
59
|
-
}
|
|
60
|
-
export const _getObjectStoreKeys = createArrayGetter()((objectStoreId) => `/resources/stores/object/${encodeURIComponent(objectStoreId)}/keys`);
|
|
61
|
-
export async function getObjectStoreKeys(fastlyApiContext, objectStoreName) {
|
|
62
|
-
const objectStoreId = await getObjectStoreIdForName(fastlyApiContext, objectStoreName);
|
|
63
|
-
if (objectStoreId == null) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
return await _getObjectStoreKeys(fastlyApiContext, objectStoreId);
|
|
67
|
-
}
|
|
68
|
-
export async function objectStoreEntryExists(fastlyApiContext, objectStoreName, key) {
|
|
69
|
-
const objectStoreId = await getObjectStoreIdForName(fastlyApiContext, objectStoreName);
|
|
70
|
-
if (objectStoreId == null) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
const endpoint = `/resources/stores/object/${encodeURIComponent(objectStoreId)}/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 objectStoreSubmitFile(fastlyApiContext, objectStoreName, key, data) {
|
|
79
|
-
const objectStoreId = await getObjectStoreIdForName(fastlyApiContext, objectStoreName);
|
|
80
|
-
if (objectStoreId == null) {
|
|
81
|
-
throw new Error('Object store not found');
|
|
82
|
-
}
|
|
83
|
-
const endpoint = `/resources/stores/object/${encodeURIComponent(objectStoreId)}/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 objectStoreDeleteFile(fastlyApiContext, objectStoreName, key) {
|
|
97
|
-
const objectStoreId = await getObjectStoreIdForName(fastlyApiContext, objectStoreName);
|
|
98
|
-
if (objectStoreId == null) {
|
|
99
|
-
throw new Error('Object store not found');
|
|
100
|
-
}
|
|
101
|
-
const endpoint = `/resources/stores/object/${encodeURIComponent(objectStoreId)}/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,18 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"content-assets-runtime.d.ts","sourceRoot":"","sources":["../../../src/server/assets/content-assets-runtime.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inline-store-entry.d.ts","sourceRoot":"","sources":["../../../src/server/object-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"}
|
|
@@ -1,100 +0,0 @@
|
|
|
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
|
-
}
|