@fastly/compute-js-static-publish 8.0.1 → 8.0.2

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 (35) hide show
  1. package/CHANGELOG.md +544 -0
  2. package/DOCUMENTATION.md +31 -15
  3. package/MIGRATING.md +128 -0
  4. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  5. package/build/cli/cli/commands/manage/collections/promote.js +43 -4
  6. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  7. package/build/cli/cli/commands/manage/publish-content.js +5 -13
  8. package/build/cli/cli/commands/scaffold/index.js +12 -13
  9. package/build/cli/cli/storage/kv-store-local-provider.d.ts +1 -0
  10. package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
  11. package/build/cli/cli/storage/kv-store-local-provider.js +4 -1
  12. package/build/cli/cli/storage/kv-store-provider.d.ts +1 -0
  13. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
  14. package/build/cli/cli/storage/kv-store-provider.js +9 -1
  15. package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
  16. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  17. package/build/cli/cli/storage/s3-storage-provider.js +4 -0
  18. package/build/cli/cli/storage/storage-provider.d.ts +3 -0
  19. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
  20. package/build/cli/cli/storage/storage-provider.js +32 -0
  21. package/build/cli/cli/util/kv-store-items.d.ts +1 -0
  22. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
  23. package/build/cli/cli/util/kv-store-items.js +16 -40
  24. package/build/cli/cli/util/s3.d.ts +10 -4
  25. package/build/cli/cli/util/s3.d.ts.map +1 -1
  26. package/build/cli/cli/util/s3.js +13 -35
  27. package/build/server/server/publisher-server/accept-html.d.ts +2 -0
  28. package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
  29. package/build/server/server/publisher-server/accept-html.js +50 -0
  30. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  31. package/build/server/server/publisher-server/index.js +8 -12
  32. package/build/server/server/publisher-server/response-cache.d.ts +3 -0
  33. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
  34. package/build/server/server/publisher-server/response-cache.js +24 -1
  35. package/package.json +4 -2
package/DOCUMENTATION.md CHANGED
@@ -131,10 +131,12 @@ npx @fastly/compute-js-static-publish@latest \
131
131
  > npx @fastly/compute-js-static-publish@latest \
132
132
  > --root-dir=./public \
133
133
  > --storage-mode=s3 \
134
- > --s3-region=us-east \
134
+ > --s3-region=us-east-1 \
135
135
  > --s3-bucket=my-static-content-bucket \
136
- > --s3-endpoint=https://us-east.object.fastlystorage.app
136
+ > --s3-endpoint=https://us-east-1.object.fastlystorage.app
137
137
  > ```
138
+ >
139
+ > For the regions of Fastly Object Storage and their endpoints, see [Working with Object Storage](https://www.fastly.com/documentation/guides/platform/object-storage/working-with-object-storage/#managing-object-storage-buckets-and-objects).
138
140
 
139
141
  You get a Compute app in `./compute-js` with:
140
142
 
@@ -343,7 +345,10 @@ You can override this file for a single `publish-content` command by specifying
343
345
  `'../site/public'`, set it to `'/public'`. The value starts with `/` and does not
344
346
  end with `/` (default: `''`). The scaffolder sets it from `--root-dir` and `--public-dir`.
345
347
  - `spaFile` - Path to a file to be used to serve in a SPA application.
346
- - `notFoundPageFile` - Path to a file to be used to serve as a 404 not found page.
348
+ - `notFoundPageFile` - Path to a file to be used to serve as a 404 not found page.
349
+ The server serves `spaFile` or `notFoundPageFile` only to a request that accepts HTML: its `Accept`
350
+ header is missing or empty, or has `text/html`, `text/*`, or `*/*` with a q-value that is not 0.
351
+ For other requests, `serveRequest()` returns `null`.
347
352
  - `autoIndex` - List of files to automatically use as index.
348
353
  - `autoExt` - List of extensions to automatically apply to a path and retry when
349
354
  the requested path is not found.
@@ -675,7 +680,9 @@ Assets are stored in multiple formats (uncompressed + compressed) if configured.
675
680
 
676
681
  ## 🧩 Using PublisherServer in Custom Apps
677
682
 
678
- You can combine PublisherServer with custom logic to support APIs, authentication, redirects, or A/B testing. `PublisherServer` returns `null` when it cannot handle a request, allowing you to chain in your own logic.
683
+ You can combine PublisherServer with custom logic to support APIs, authentication, redirects, or A/B testing. Handle your own routes before you call `serveRequest()`.
684
+
685
+ `serveRequest()` returns `null` for a method other than `GET` or `HEAD`, and when no file matches and no SPA file or 404 page applies. If `publish-content.config.js` sets a 404 page or an SPA file, `serveRequest()` serves that page for each path that has no file. Thus, code after `serveRequest()` does not run for those requests.
679
686
 
680
687
  ```js
681
688
  import { PublisherServer } from '@fastly/compute-js-static-publish';
@@ -688,12 +695,7 @@ addEventListener("fetch", event => {
688
695
  });
689
696
 
690
697
  async function handleRequest(request) {
691
- const response = await publisherServer.serveRequest(request);
692
- if (response) {
693
- return response;
694
- }
695
-
696
- // Add your custom logic here
698
+ // Add your custom logic here, before serveRequest()
697
699
  const url = new URL(request.url);
698
700
  if (url.pathname === '/api/hello') {
699
701
  return new Response(JSON.stringify({ greeting: "hi" }), {
@@ -701,6 +703,11 @@ async function handleRequest(request) {
701
703
  });
702
704
  }
703
705
 
706
+ const response = await publisherServer.serveRequest(request);
707
+ if (response != null) {
708
+ return response;
709
+ }
710
+
704
711
  return new Response("Not Found", { status: 404 });
705
712
  }
706
713
  ```
@@ -752,17 +759,17 @@ publisherServer.setResponseCache({ maxAge: 3600 });
752
759
 
753
760
  `maxAge` is in seconds. This is off by default.
754
761
 
755
- `maxBodySize` sets the largest response, in bytes, to cache. The default is 8 MiB (`8 * 1024 * 1024`). A larger response is served from storage each time:
762
+ `maxBodySize` sets the largest response, in bytes, to cache. The default is 16 MiB (`16 * 1024 * 1024`). A larger response is served from storage each time:
756
763
 
757
764
  ```js
758
- publisherServer.setResponseCache({ maxAge: 3600, maxBodySize: 16 * 1024 * 1024 });
765
+ publisherServer.setResponseCache({ maxAge: 3600, maxBodySize: 4 * 1024 * 1024 });
759
766
  ```
760
767
 
761
768
  - A response is cached by the publish ID, the collection, the path, and the client's `Accept-Encoding`. A cache hit does not read the settings, the index, or the file.
762
769
  - A path that does not match a file is cached, too, so a missing path does not read the index again.
763
770
  - If several requests miss the same response at the same time, one request produces it, and the others wait for it.
764
771
  - Only `200` and `404` responses are cached. Conditional requests (`304`) and `HEAD` requests are answered from the cached response.
765
- - Each cached response has the surrogate key `<publishId>-<collectionName>`. After you publish, `publish-content` purges this key (see [`--fastly-service-id`](#publish-content)), so the next request gets the new content.
772
+ - Each cached response has the surrogate key `<publishId>-<collectionName>`. After you publish, `publish-content` purges this key (see [`--fastly-service-id`](#publish-content)), so the next request gets the new content. `collections promote` and `collections delete` purge the key of the collection that they change.
766
773
 
767
774
  `serveRequest()` uses the response cache automatically. If you call `getMatchingAsset()` and `serveAsset()` directly, wrap them in `serveCached()`. When a response is not cached yet, `serveCached()` calls your function to produce it, with a `GET` request that has no conditional headers:
768
775
 
@@ -781,7 +788,7 @@ The second argument identifies the response in the collection. If anything other
781
788
 
782
789
  Notes:
783
790
 
784
- - A response is read completely before it is cached, so a request uses memory for one response, up to `maxBodySize`. Other requests that wait for the same response get it when it is cached.
791
+ - A response is read completely before it is cached. The request that caches it uses memory of about two times the body, up to two times `maxBodySize`. A Compute instance has a limit on its memory, so do not set `maxBodySize` larger than 48 MiB (`48 * 1024 * 1024`). Other requests that wait for the same response get it when it is cached.
785
792
  - A response is cached only if its body has the size in the file's metadata. If storage returns a different body, nothing is cached, the request gets an error, and the next request reads the file again.
786
793
  - With `--local`, `publish-content` cannot purge the local cache. Restart `fastly compute serve` to see newly published content, or leave the response cache off in local development.
787
794
  - On staging, a purge must include the `Fastly-Purge-Environment: staging` header to clear the staging cache. Without it, a purge clears only the production cache. Use `publish-content --purge-environment=production,staging` to purge both.
@@ -931,7 +938,7 @@ npx @fastly/compute-js-static-publish publish-content \
931
938
 
932
939
  Publishes static files from your local root directory into a named collection, in the storage that `static-publish.rc.js` specifies: the Fastly KV Store, S3-compatible storage (BETA), or a local dev directory (`--local`, KV Store mode only).
933
940
 
934
- Before it scans your files, the command lists the files that are already in storage. Files that already exist with the same hash are not compressed or uploaded again. With the KV Store, the command uploads the remaining files in batches.
941
+ Before it scans your files, the command lists the files that are already in storage. Files that already exist with the same hash are not compressed or uploaded again. With the KV Store, a file larger than 20 MiB is stored in chunks, and the command uploads a chunk again if the chunk in storage does not have the correct size. Then the command uploads the remaining files in batches.
935
942
 
936
943
  After this process is complete, the PublisherServer object in the Compute application will see the updated index of files and updated server settings from the `publish-content.config.js` file.
937
944
 
@@ -1024,6 +1031,8 @@ npx @fastly/compute-js-static-publish collections promote \
1024
1031
  ```
1025
1032
  Copies an existing collection (content + config) to a new collection name.
1026
1033
 
1034
+ If a Service ID is found, the command then purges the surrogate key `<publishId>-<collectionName>` of the target collection, so that the service stops serving cached responses of the old content. This uses the same options as [`publish-content`](#publish-content).
1035
+
1027
1036
  ##### Options:
1028
1037
 
1029
1038
  - `--collection-name`: The name of the source collection to promote (required)
@@ -1043,6 +1052,11 @@ Copies an existing collection (content + config) to a new collection name.
1043
1052
 
1044
1053
  - `--fastly-api-token`: API token to use when publishing. If not set, the tool uses the **`FASTLY_API_TOKEN` environment variable**.
1045
1054
 
1055
+ **Purge Options:**
1056
+
1057
+ - `--fastly-service-id`: The Fastly Service ID to purge after promoting. If not set, the tool checks the `FASTLY_SERVICE_ID` environment variable, then `service_id` in `fastly.toml`. If none is found, the command skips the purge. The purge also needs an API token (see `--fastly-api-token`), also in S3 mode. With `--local`, there is no purge. If the purge fails, the command shows a warning and completes, because the collection is already promoted.
1058
+ - `--purge-environment`: The environments to purge: `production` (the default), `staging`, or both, as a comma-separated list. You can also repeat the option.
1059
+
1046
1060
  **S3 Storage Options (BETA):**
1047
1061
 
1048
1062
  - `--s3-access-key-id`, `--s3-secret-access-key`: Access key ID and secret access key for S3-compatible storage. If not set, the tool will check the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables.
@@ -1212,6 +1226,8 @@ async function handleRequest(event) {
1212
1226
 
1213
1227
  To build the package, run `npm run build`. To run the tests, see [test/README.md](./test/README.md).
1214
1228
 
1229
+ In the code, its comments, and the docs for developers of this package, a **customer** is a developer who uses this package to publish a site, and a **visitor** is a person who opens the customer's site.
1230
+
1215
1231
  ## Issues
1216
1232
 
1217
1233
  If you encounter any non-security-related bug or unexpected behavior, please [file an issue][bug] using the bug report template.
package/MIGRATING.md ADDED
@@ -0,0 +1,128 @@
1
+ # Migration Guide
2
+
3
+ New major versions of `@fastly/compute-js-static-publish` can involve changes to the files that
4
+ are generated during scaffolding. For this reason, it is recommended that you re-scaffold your application.
5
+
6
+ This is straightforward if you're using `compute-js-static-publisher` out-of-the-box. Otherwise, read on.
7
+
8
+ > [!NOTE]
9
+ > This document is under construction.
10
+ >
11
+
12
+ ## Upgrade from v7 to v8
13
+
14
+ v8 can use the files that v7 published. The storage key layout did not change. v8 also accepts the v7 format of
15
+ `static-publish.rc.js` (`kvStoreName` at the top level). Thus, an app that uses the KV Store does not need a new
16
+ scaffold.
17
+
18
+ To upgrade an app that uses the KV Store:
19
+
20
+ 1. In the `compute-js/` directory of your app, install v8:
21
+
22
+ ```sh
23
+ npm install @fastly/compute-js-static-publish@latest
24
+ ```
25
+
26
+ 2. Make sure that the CLI can get a Fastly API token. Set the `FASTLY_API_TOKEN` environment variable, or use
27
+ `--fastly-api-token`. v8 no longer uses the token logged in by the Fastly CLI.
28
+
29
+ 3. Build and deploy your app again. The Wasm binary contains a copy of `static-publish.rc.js`, and the server code
30
+ changed.
31
+
32
+ 4. Publish your content again with `npm run publish-content`. This step is optional. v8 serves the content that v7
33
+ published.
34
+
35
+ ### Changes to examine
36
+
37
+ - **The CLI purges after it publishes.** In v8, `publish-content` purges the surrogate key `<publishId>-<collection>`
38
+ in KV Store mode too. It finds the Service ID from `--fastly-service-id`, then the `FASTLY_SERVICE_ID`
39
+ environment variable, then `service_id` in `fastly.toml`. If it finds a Service ID, the API token must have permission to purge
40
+ that service. If you do not want a purge, make sure that the CLI does not find a Service ID. If the purge fails,
41
+ the CLI shows a warning, and the publish is complete. `collections delete` purges the same way after it deletes a
42
+ collection.
43
+ - **`kvStoreAssetInclusionTest` has a new name.** In `publish-content.config.js`, use `assetInclusionTest`. The old
44
+ name continues to work, but it is deprecated.
45
+ - **Imports of files in `build/` are not supported.** Import the named exports of
46
+ `@fastly/compute-js-static-publish`.
47
+ - **`--public-dir` and `server.publicDirPrefix` are deprecated.** `publish-content` shows a warning if
48
+ `publicDirPrefix` is not empty. See [Stop using `publicDirPrefix`](#stop-using-publicdirprefix-deprecated).
49
+ - **The `@fastly/cli` dependency is removed** from this package. A scaffolded app continues to have `@fastly/cli` as
50
+ its own dependency.
51
+
52
+ ### Stop using `publicDirPrefix` (deprecated)
53
+
54
+ `--public-dir` and `server.publicDirPrefix` are deprecated. A future version will remove them. If `publish-content`
55
+ shows a warning about `server.publicDirPrefix`, do the steps in this section. If it does not show the warning, you do
56
+ not use this feature, and you do not have to do anything.
57
+
58
+ `publicDirPrefix` lets you publish files that requests cannot get. For example, with this layout, `rootDir` is
59
+ `'../site'` and `publicDirPrefix` is `'/public'`:
60
+
61
+ ```
62
+ site/
63
+ 404.html published as /404.html, but /404.html is not a URL
64
+ templates/
65
+ email.html published as /templates/email.html, but it is not a URL
66
+ public/
67
+ index.html published as /public/index.html, served at /index.html
68
+ ```
69
+
70
+ To stop using `publicDirPrefix`:
71
+
72
+ 1. Find the files that are under `rootDir` but not under the public directory (`site/public/` in the example). For
73
+ each file, do one of these steps:
74
+ - If your app does not use the file, do nothing. After step 2, the CLI does not publish it.
75
+ - If the file is your `spaFile` or your `notFoundPageFile`, move it into the public directory. Then requests can
76
+ also get it at its own URL, for example `/404.html`.
77
+ - If your code reads the file with `getMatchingAsset()`, move it into the public directory. Then requests can also
78
+ get it at its own URL. To prevent this, return a response in `src/index.js` before you call `serveRequest()`:
79
+
80
+ ```js
81
+ const url = new URL(request.url);
82
+ if (url.pathname.startsWith('/templates/')) {
83
+ return new Response('Not found', { status: 404 });
84
+ }
85
+ const response = await publisherServer.serveRequest(request);
86
+ ```
87
+
88
+ 2. In `publish-content.config.js`:
89
+ - Set `rootDir` to the public directory, for example `'../site/public'`.
90
+ - Remove `publicDirPrefix` from the `server` section.
91
+ - In `spaFile` and `notFoundPageFile`, remove the prefix, for example change `'/public/404.html'` to
92
+ `'/404.html'`. These values are asset keys, and asset keys are relative to `rootDir`.
93
+ - Do not change `staticItems`. These values are already relative to the public directory.
94
+
95
+ 3. If your code calls `getMatchingAsset()` with a key that starts with the prefix, remove the prefix from the key, for
96
+ example change `'/public/index.html'` to `'/index.html'`. Then build and deploy your app. Between the deploy and
97
+ step 4, your code does not find these files.
98
+
99
+ 4. Publish each collection that you serve again. Each collection keeps its old settings and its old index until you
100
+ publish it again. The keys of the files are the hashes of the content, so the CLI does not upload the same files
101
+ again.
102
+
103
+ ### Move from the KV Store to S3-compatible storage (BETA)
104
+
105
+ You do not have to move to S3-compatible storage. The KV Store continues to be the default storage mode.
106
+
107
+ There is no tool that moves your content from the KV Store to a bucket. The CLI publishes from your source files.
108
+ Thus, to move, you publish your content again into the bucket:
109
+
110
+ 1. Scaffold a new app with `--storage-mode=s3`, `--s3-region`, `--s3-bucket`, and, if necessary, `--s3-endpoint`.
111
+ Scaffold it into a different directory, so that you can compare the new files with your current app.
112
+
113
+ 2. Copy your changes from your current app into the new app, for example the changes to `src/index.js` and to
114
+ `publish-content.config.js`. Keep the same `publishId` and `defaultCollectionName`.
115
+
116
+ 3. Set up the S3 credentials for publishing and for the server. See "Using S3 Compatible Storage (Beta)" in
117
+ `README.md`.
118
+
119
+ 4. Publish each collection that you need again, from its source files. The collections that are in the KV Store
120
+ are not copied.
121
+
122
+ 5. Build and deploy the new app. Then examine your site.
123
+
124
+ 6. When you do not need the KV Store content, delete it. Before you do this, make sure that no service version
125
+ that is active or staged uses that KV Store.
126
+
127
+ > [!NOTE]
128
+ > S3-compatible storage is in beta. The configuration and these steps can change before this feature is stable.
@@ -1 +1 @@
1
- {"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AAmEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuLhD"}
1
+ {"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AAkFA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAmNhD"}
@@ -9,6 +9,7 @@ import { calcExpirationTime } from '../../../../models/time/index.js';
9
9
  import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
10
10
  import { parseCommandLine } from '../../../util/args.js';
11
11
  import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
12
+ import { loadPurgeTarget, purgeCollection } from '../../../util/purge.js';
12
13
  function help() {
13
14
  console.log(`\
14
15
 
@@ -21,6 +22,9 @@ Usage:
21
22
  Description:
22
23
  Copies an existing collection (content + config) to a new collection name.
23
24
 
25
+ If a Service ID is found, the tool then purges the cached responses of the target
26
+ collection from that service.
27
+
24
28
  Required:
25
29
  --collection-name=<name> The name of the collection to promote
26
30
  --to=<name> The name of the new (target) collection to create or overwrite
@@ -45,10 +49,21 @@ KV Store Options:
45
49
  with the local development environment.
46
50
  KV Store mode only. In S3 mode, --local is an error.
47
51
 
48
- --fastly-api-token=<token> Fastly API token for KV Store access.
52
+ --fastly-api-token=<token> Fastly API token for KV Store or cache access.
49
53
  If not set, the tool uses the FASTLY_API_TOKEN
50
54
  environment variable.
51
55
 
56
+ Purge Options:
57
+ --fastly-service-id=<id> Fastly Service ID to purge after promoting (not with --local).
58
+ If not set, the tool will check:
59
+ 1. FASTLY_SERVICE_ID environment variable
60
+ 2. service_id in fastly.toml
61
+ If none is found, the purge is skipped.
62
+
63
+ --purge-environment=<env> Environment to purge: production, staging, or a
64
+ comma-separated list of both. Can be repeated.
65
+ Default: production
66
+
52
67
  S3 Storage Options (BETA):
53
68
  --s3-access-key-id=<id> Access Key ID and Secret Access Key used to
54
69
  --s3-secret-access-key=<key> interface with S3 or compatible storage.
@@ -69,6 +84,8 @@ export async function action(actionArgs) {
69
84
  { name: 'expires-never', type: Boolean },
70
85
  { name: 'local', type: Boolean },
71
86
  { name: 'fastly-api-token', type: String, },
87
+ { name: 'fastly-service-id', type: String, },
88
+ { name: 'purge-environment', type: String, multiple: true, },
72
89
  { name: 's3-access-key-id', type: String, },
73
90
  { name: 's3-secret-access-key', type: String, },
74
91
  ];
@@ -82,7 +99,7 @@ export async function action(actionArgs) {
82
99
  help();
83
100
  return;
84
101
  }
85
- const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
102
+ const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['fastly-service-id']: fastlyServiceId, ['purge-environment']: purgeEnvironmentValues, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
86
103
  // compute-js-static-publisher cli is always run from the Compute application directory
87
104
  // in other words, the directory that contains `fastly.toml`.
88
105
  const computeAppDir = path.resolve();
@@ -148,6 +165,22 @@ export async function action(actionArgs) {
148
165
  }
149
166
  const sourceCollectionName = collectionNameValue;
150
167
  console.log(`✔️ Collection to copy: ${sourceCollectionName}`);
168
+ // Purge target: checked now, so that a missing API token fails before anything is written.
169
+ let purgeTarget;
170
+ try {
171
+ purgeTarget = loadPurgeTarget({
172
+ localMode: localMode ?? false,
173
+ computeAppDir,
174
+ fastlyServiceId,
175
+ fastlyApiToken,
176
+ purgeEnvironments: purgeEnvironmentValues,
177
+ });
178
+ }
179
+ catch (err) {
180
+ console.error(String(err));
181
+ process.exitCode = 1;
182
+ return;
183
+ }
151
184
  const targetCollectionName = toCollectionNameValue;
152
185
  console.log(`✔️ Collection to promote to: ${targetCollectionName}`);
153
186
  if (expirationTime === undefined) {
@@ -191,11 +224,17 @@ export async function action(actionArgs) {
191
224
  console.log(`Uploading to storage: '${targetCollectionName}'`);
192
225
  const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
193
226
  fs.mkdirSync(storageContentDir, { recursive: true });
194
- const indexFileName = `index_${collectionNameValue}.json`;
227
+ // The files have the name of the target collection, as in publish-content. In
228
+ // --local mode, kvstore.json refers to them, so the target must not share a
229
+ // file with the source.
230
+ const indexFileName = `index_${targetCollectionName}.json`;
195
231
  const indexFilePath = path.resolve(storageContentDir, indexFileName);
196
232
  await storageProvider.submitStorageEntry(targetCollectionIndexKey, indexFilePath, indexEntryInfo.data, encodeIndexMetadata(indexMetadata));
197
- const settingsFileName = `settings_${collectionNameValue}.json`;
233
+ const settingsFileName = `settings_${targetCollectionName}.json`;
198
234
  const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
199
235
  await storageProvider.submitStorageEntry(targetCollectionSettingsKey, settingsFilePath, settingsEntryInfo.data);
236
+ if (purgeTarget != null) {
237
+ await purgeCollection(purgeTarget, publishId, targetCollectionName);
238
+ }
200
239
  console.log("✅ Completed.");
201
240
  }
@@ -1 +1 @@
1
- {"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AA8HA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA4jBhD"}
1
+ {"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AA+HA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAmjBhD"}
@@ -15,7 +15,7 @@ import { ensureVariantFileExists, OncePerKey } from '../../util/variants.js';
15
15
  import { concurrentMap } from '../../util/retryable.js';
16
16
  import { ProgressLog } from '../../util/progress.js';
17
17
  import { loadPurgeTarget, purgeCollection } from '../../util/purge.js';
18
- import { getStorageKeysByHexPrefix, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
18
+ import { getStorageKeysByHexPrefix, isVariantInStorage, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
19
19
  // Storage key format:
20
20
  // <publishId>_index_<preview_id>.json
21
21
  // <publishId>_settings_<preview_id>.json
@@ -319,6 +319,8 @@ export async function action(actionArgs) {
319
319
  // #### Keys that are already in storage
320
320
  // The key of a file is the hash of its content. If the key exists, storage
321
321
  // already has the same content. Thus we do not compress, hash, or upload it again.
322
+ // For a file in more than one chunk, isVariantInStorage() also compares the
323
+ // stored size of each chunk.
322
324
  // In local mode, a key can refer to a working file that was deleted, so we do not list.
323
325
  // All the keys that the scan looks for start with `<publishId>_files_sha256_` and a hex
324
326
  // hash, so we list them in 16 parts at the same time.
@@ -330,17 +332,6 @@ export async function action(actionArgs) {
330
332
  console.log(`✅ Found ${existingKeys.size} key(s) in ${((Date.now() - listStart) / 1000).toFixed(1)} s.`);
331
333
  }
332
334
  let existingVariantCount = 0;
333
- function isVariantInStorage(variantKey, numChunks) {
334
- if (existingKeys == null || !existingKeys.has(variantKey)) {
335
- return false;
336
- }
337
- for (let chunkIndex = 1; chunkIndex < numChunks; chunkIndex++) {
338
- if (!existingKeys.has(`${variantKey}_${chunkIndex}`)) {
339
- return false;
340
- }
341
- }
342
- return true;
343
- }
344
335
  // #### Iterate files
345
336
  const scanProgress = new ProgressLog('Files scanned', verbose);
346
337
  const fileResults = await concurrentMap(files, async (file) => {
@@ -392,7 +383,8 @@ export async function action(actionArgs) {
392
383
  // Returns true if the index keeps the variant.
393
384
  async function prepareVariant(variant, variantKey, variantFilePath) {
394
385
  if ((variant === 'original' || baseNumChunks === 1) &&
395
- isVariantInStorage(variantKey, variant === 'original' ? baseNumChunks : 1)) {
386
+ existingKeys != null &&
387
+ await isVariantInStorage(storageProvider, existingKeys, variantKey, baseSize, variant === 'original' ? baseNumChunks : 1)) {
396
388
  if (verbose) {
397
389
  console.log(` ・ Asset found in storage with key "${variantKey}".`);
398
390
  }
@@ -590,19 +590,16 @@ export async function action(actionArgs) {
590
590
  }
591
591
  let s3Endpoint = options.s3Endpoint;
592
592
  if (s3Endpoint == null || s3Endpoint === '') {
593
- // If endpoint is not presented, we assume it's from AWS,
594
- // and ask the SDK what the hostname would be.
595
- // This is required because we need to add the hostname as a
596
- // backend in the Compute service.
597
- s3Endpoint = await findHostnameForAwsS3RegionAndBucket(s3Region, s3Bucket);
598
- if (s3Endpoint) {
599
- console.log('✅ S3 endpoint resolved:', s3Endpoint);
600
- }
601
- else {
602
- console.error(`❌ Unable to resolve S3 endpoint from region '${s3Region}' and bucket '${s3Bucket}.`);
593
+ // Without an endpoint, the bucket is on AWS. The app needs its host name
594
+ // for the backend in the Compute service.
595
+ const hostname = findHostnameForAwsS3RegionAndBucket(s3Region, s3Bucket);
596
+ if (hostname == null) {
597
+ console.error(`❌ The bucket name '${s3Bucket}' has a dot, so it cannot be a host name of AWS S3 under HTTPS. Set --s3-endpoint, for example --s3-endpoint=https://s3.${s3Region}.amazonaws.com. Then the bucket is in the path of the URL.`);
603
598
  process.exitCode = 1;
604
599
  return;
605
600
  }
601
+ s3Endpoint = hostname;
602
+ console.log('✅ S3 endpoint resolved:', s3Endpoint);
606
603
  s3EndpointUrl = new URL(`https://${s3Endpoint}/`);
607
604
  s3EndpointGenerated = true;
608
605
  }
@@ -903,14 +900,16 @@ async function handleRequest(event) {
903
900
 
904
901
  const request = event.request;
905
902
 
903
+ // Do custom things here!
904
+ // Handle API requests, serve non-static responses, etc.
905
+ // serveRequest() serves the 404 page or the SPA file for each path that
906
+ // has no file, so code after it does not run for those requests.
907
+
906
908
  const response = await publisherServer.serveRequest(request);
907
909
  if (response != null) {
908
910
  return response;
909
911
  }
910
912
 
911
- // Do custom things here!
912
- // Handle API requests, serve non-static responses, etc.
913
-
914
913
  return new Response('Not found', { status: 404 });
915
914
  }
916
915
  `;
@@ -14,5 +14,6 @@ export declare class KvStoreLocalProvider implements StorageProvider {
14
14
  key: string;
15
15
  }>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
16
16
  calculateNumChunks(size: number): number;
17
+ calculateChunkSizes(size: number): number[];
17
18
  }
18
19
  //# sourceMappingURL=kv-store-local-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kv-store-local-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-local-provider.ts"],"names":[],"mappings":"AA0BA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAK/B,eAAO,MAAM,kBAAkB,EAAE,sBAkBhC,CAAC;AAEF,qBAAa,oBAAqB,YAAW,eAAe;gBAExD,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM;IAMvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAEzB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAQzD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAc1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAe9D,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAA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AC;IAc1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAe9D,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAsBV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,QAAQ,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBxF,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,CAAC,EAAE,MAAM,EACtB,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAYhB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIxC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;CAG5C"}
@@ -6,7 +6,7 @@ import fs from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import { isKvStoreConfigRc, } from '../../models/config/static-publish-rc.js';
8
8
  import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
9
- import { applyKVStoreEntriesChunks, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
9
+ import { applyKVStoreEntriesChunks, chunkSizes, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
10
10
  import { getLocalKvStoreEntry, getLocalKVStoreKeys, localKvStoreDeleteEntry, localKvStoreSubmitEntry, writeKVStoreEntriesForLocal, } from '../util/kv-store-local-server.js';
11
11
  import { concurrentParallel } from '../util/retryable.js';
12
12
  import { kvStoreEntryToStorageEntry, } from './kv-store-provider.js';
@@ -78,4 +78,7 @@ export class KvStoreLocalProvider {
78
78
  calculateNumChunks(size) {
79
79
  return Math.ceil(size / KV_STORE_CHUNK_SIZE);
80
80
  }
81
+ calculateChunkSizes(size) {
82
+ return chunkSizes(size, KV_STORE_CHUNK_SIZE);
83
+ }
81
84
  }
@@ -17,6 +17,7 @@ export declare class KvStoreProvider implements StorageProvider {
17
17
  key: string;
18
18
  }>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
19
19
  calculateNumChunks(size: number): number;
20
+ calculateChunkSizes(size: number): number[];
20
21
  }
21
22
  export declare function kvStoreEntryToStorageEntry(kvStoreEntry: KvStoreEntryInfo): StorageEntry;
22
23
  export declare function parseKvStoreMetadata(metadata: string): Record<string, string> | null;
@@ -1 +1 @@
1
- {"version":3,"file":"kv-store-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-provider.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EACL,KAAK,gBAAgB,EAMtB,MAAM,qBAAqB,CAAC;AAY7B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,kBAAkB,EAAE,sBAsBhC,CAAC;AAEF,qBAAa,eAAgB,YAAW,eAAe;gBAEnD,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM;IAMxB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,WAA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AG,OAAO,CAAC,IAAI,CAAC;IAsBvF,aAAa,CAAC,OAAO,EAAE,yBAAyB,EAAE,EAAE,OAAO,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IA4C5F,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,EAC1B,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAqBhB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIxC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;CAI5C;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,gBAAgB,gBA6B/B;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,iCAiCpD"}
@@ -9,7 +9,7 @@ import { FetchError, loadApiToken, } from '../util/api-token.js';
9
9
  import { rootRelative, } from '../util/files.js';
10
10
  import { ProgressLog } from '../util/progress.js';
11
11
  import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry, kvStoreSubmitEntry, kvStoreSubmitBatch, } from '../util/kv-store.js';
12
- import { applyKVStoreEntriesChunks, packNdjsonBatches, ndjsonLineForBatchEntry, entriesToUpload, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
12
+ import { applyKVStoreEntriesChunks, chunkSizes, packNdjsonBatches, ndjsonLineForBatchEntry, entriesToUpload, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
13
13
  import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
14
14
  export const buildStoreProvider = (config, context) => {
15
15
  if (isKvStoreConfigRc(config) && !context.localMode) {
@@ -110,6 +110,9 @@ export class KvStoreProvider {
110
110
  calculateNumChunks(size) {
111
111
  return Math.ceil(size / KV_STORE_CHUNK_SIZE);
112
112
  }
113
+ calculateChunkSizes(size) {
114
+ return chunkSizes(size, KV_STORE_CHUNK_SIZE);
115
+ }
113
116
  }
114
117
  export function kvStoreEntryToStorageEntry(kvStoreEntry) {
115
118
  const storageEntry = {};
@@ -122,6 +125,11 @@ export function kvStoreEntryToStorageEntry(kvStoreEntry) {
122
125
  storageEntry.metadata = metadata;
123
126
  }
124
127
  }
128
+ // The API gives the size of the value in this header, also for a HEAD request.
129
+ const storedContentLength = kvStoreEntry.response.headers.get('stored-content-length');
130
+ if (storedContentLength != null) {
131
+ storageEntry.size = Number(storedContentLength);
132
+ }
125
133
  if (kvStoreEntry.generation != null) {
126
134
  storageEntry.providerMetadata = {
127
135
  generation: kvStoreEntry.generation,
@@ -26,6 +26,7 @@ export declare class S3StorageProvider implements StorageProvider {
26
26
  key: string;
27
27
  }>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
28
28
  calculateNumChunks(_size: number): number;
29
+ calculateChunkSizes(size: number): number[];
29
30
  }
30
31
  export {};
31
32
  //# sourceMappingURL=s3-storage-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAQA,OAAO,EAUL,QAAQ,EAIT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AASxB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAc/B,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,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U,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAaV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BvF,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,EAC1B,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAmBhB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIzC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;CAI5C"}
@@ -157,6 +157,7 @@ export class S3StorageProvider {
157
157
  }
158
158
  return {
159
159
  metadata: response.Metadata,
160
+ size: response.ContentLength,
160
161
  };
161
162
  }
162
163
  async submitStorageEntry(key, _filePath, data, metadata) {
@@ -207,4 +208,7 @@ export class S3StorageProvider {
207
208
  calculateNumChunks(_size) {
208
209
  return 1;
209
210
  }
211
+ calculateChunkSizes(size) {
212
+ return [size];
213
+ }
210
214
  }
@@ -3,6 +3,7 @@ export interface StorageEntry {
3
3
  data?: ReadableStream<Uint8Array>;
4
4
  metadata?: Record<string, string>;
5
5
  providerMetadata?: Record<string, string>;
6
+ size?: number;
6
7
  }
7
8
  export interface StorageProvider {
8
9
  getStorageKeys(prefix?: string): Promise<string[] | null>;
@@ -15,6 +16,7 @@ export interface StorageProvider {
15
16
  key: string;
16
17
  }>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
17
18
  calculateNumChunks(size: number): number;
19
+ calculateChunkSizes(size: number): number[];
18
20
  }
19
21
  export type StorageProviderBatchEntry = {
20
22
  size: number;
@@ -43,4 +45,5 @@ export type StorageProviderBuilder = (config: StaticPublishRc, context: StorageP
43
45
  export declare function getStorageKeysByHexPrefix(storageProvider: StorageProvider, prefix: string): Promise<string[] | null>;
44
46
  export declare function registerStorageProviderBuilder(builder: StorageProviderBuilder): void;
45
47
  export declare function loadStorageProviderFromStaticPublishRc(config: StaticPublishRc, context: StorageProviderBuilderContext): Promise<StorageProvider>;
48
+ export declare function isVariantInStorage(storageProvider: StorageProvider, existingKeys: Set<string>, variantKey: string, size: number, numChunks: number): Promise<boolean>;
46
49
  //# sourceMappingURL=storage-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC/D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC3D,kBAAkB,C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