@fastly/compute-js-static-publish 8.0.1 → 8.0.3-rc.1

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 (63) hide show
  1. package/CHANGELOG.md +557 -0
  2. package/DOCUMENTATION.md +59 -38
  3. package/MIGRATING.md +128 -0
  4. package/README.md +3 -3
  5. package/README.short.md +3 -3
  6. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  7. package/build/cli/cli/commands/manage/clean.js +27 -0
  8. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  9. package/build/cli/cli/commands/manage/collections/promote.js +43 -4
  10. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  11. package/build/cli/cli/commands/manage/publish-content.js +43 -14
  12. package/build/cli/cli/commands/scaffold/index.js +12 -13
  13. package/build/cli/cli/storage/kv-store-local-provider.d.ts +3 -2
  14. package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
  15. package/build/cli/cli/storage/kv-store-local-provider.js +6 -15
  16. package/build/cli/cli/storage/kv-store-provider.d.ts +3 -2
  17. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
  18. package/build/cli/cli/storage/kv-store-provider.js +11 -2
  19. package/build/cli/cli/storage/s3-storage-provider.d.ts +3 -2
  20. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  21. package/build/cli/cli/storage/s3-storage-provider.js +6 -1
  22. package/build/cli/cli/storage/storage-provider.d.ts +6 -1
  23. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
  24. package/build/cli/cli/storage/storage-provider.js +48 -0
  25. package/build/cli/cli/util/kv-store-items.d.ts +1 -0
  26. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
  27. package/build/cli/cli/util/kv-store-items.js +16 -40
  28. package/build/cli/cli/util/kv-store.d.ts +1 -1
  29. package/build/cli/cli/util/kv-store.d.ts.map +1 -1
  30. package/build/cli/cli/util/s3.d.ts +10 -4
  31. package/build/cli/cli/util/s3.d.ts.map +1 -1
  32. package/build/cli/cli/util/s3.js +13 -35
  33. package/build/cli/models/index-parts/index.d.ts +20 -0
  34. package/build/cli/models/index-parts/index.d.ts.map +1 -0
  35. package/build/cli/models/index-parts/index.js +76 -0
  36. package/build/cli/models/server/index.d.ts +2 -0
  37. package/build/cli/models/server/index.d.ts.map +1 -1
  38. package/build/cli/models/server/index.js +7 -1
  39. package/build/server/models/index-parts/index.d.ts +20 -0
  40. package/build/server/models/index-parts/index.d.ts.map +1 -0
  41. package/build/server/models/index-parts/index.js +76 -0
  42. package/build/server/models/server/index.d.ts +2 -0
  43. package/build/server/models/server/index.d.ts.map +1 -1
  44. package/build/server/models/server/index.js +7 -1
  45. package/build/server/server/index.d.ts +1 -1
  46. package/build/server/server/index.d.ts.map +1 -1
  47. package/build/server/server/publisher-server/accept-html.d.ts +2 -0
  48. package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
  49. package/build/server/server/publisher-server/accept-html.js +50 -0
  50. package/build/server/server/publisher-server/index.d.ts +5 -0
  51. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  52. package/build/server/server/publisher-server/index.js +103 -33
  53. package/build/server/server/publisher-server/response-cache.d.ts +3 -0
  54. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
  55. package/build/server/server/publisher-server/response-cache.js +24 -1
  56. package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
  57. package/build/server/server/storage/kv-store-provider.js +1 -0
  58. package/build/server/server/storage/s3-storage-provider.d.ts +2 -2
  59. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
  60. package/build/server/server/storage/s3-storage-provider.js +5 -2
  61. package/build/server/server/storage/storage-provider.d.ts +12 -1
  62. package/build/server/server/storage/storage-provider.d.ts.map +1 -1
  63. package/package.json +4 -2
@@ -3,9 +3,16 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import fs from 'node:fs';
6
+ import { pipeline } from 'node:stream/promises';
6
7
  import { directoryExists, getFileSize } from './files.js';
7
8
  // split large files into 20MiB chunks
8
9
  export const KV_STORE_CHUNK_SIZE = 1_024 * 1_024 * 20;
10
+ // The size of each chunk of a file of `size` bytes. All chunks have chunkSize
11
+ // bytes, except the last, which has the bytes that are left.
12
+ export function chunkSizes(size, chunkSize) {
13
+ const numChunks = Math.ceil(size / chunkSize);
14
+ return Array.from({ length: numChunks }, (_, chunk) => Math.min(chunkSize, size - chunk * chunkSize));
15
+ }
9
16
  export function shouldRecreateChunks(chunksDir, numChunks, item, chunkSize) {
10
17
  console.log(` 📄 '${item.key}' - ${item.size} bytes → ${numChunks} chunks`);
11
18
  if (!directoryExists(chunksDir)) {
@@ -17,7 +24,7 @@ export function shouldRecreateChunks(chunksDir, numChunks, item, chunkSize) {
17
24
  console.log(` ・ Recreating chunks for '${item.key}' - found ${existingChunks} existing chunk(s), expected ${numChunks}`);
18
25
  return true;
19
26
  }
20
- const finalChunkSize = item.size % chunkSize;
27
+ const expectedFileSizes = chunkSizes(item.size, chunkSize);
21
28
  for (let chunk = 0; chunk < numChunks; chunk++) {
22
29
  const chunkFileName = `${chunksDir}/${chunk}`;
23
30
  // If the chunk does not exist
@@ -26,7 +33,7 @@ export function shouldRecreateChunks(chunksDir, numChunks, item, chunkSize) {
26
33
  return true;
27
34
  }
28
35
  // or if the chunk isn't the expected size
29
- const expectedFileSize = chunk === numChunks - 1 ? finalChunkSize : chunkSize;
36
+ const expectedFileSize = expectedFileSizes[chunk];
30
37
  const existingFileSize = getFileSize(chunkFileName);
31
38
  if (existingFileSize !== expectedFileSize) {
32
39
  console.log(` ・ Recreating chunks for '${item.key}' - chunk ${chunk} existing file size ${existingFileSize} does not match expected size ${expectedFileSize}`);
@@ -52,44 +59,13 @@ export async function applyKVStoreEntriesChunks(kvStoreItemDescriptions, chunkSi
52
59
  // Recreate chunks
53
60
  fs.rmSync(chunksDir, { recursive: true, force: true });
54
61
  fs.mkdirSync(chunksDir, { recursive: true });
55
- const numWrittenChunks = await new Promise((resolve, reject) => {
56
- const chunkPaths = [];
57
- let chunkIndex = 0;
58
- let bytesWritten = 0;
59
- let currentStream = null;
60
- const inputStream = fs.createReadStream(item.filePath);
61
- inputStream.on('error', reject);
62
- inputStream.on('data', (chunk) => {
63
- let offset = 0;
64
- while (offset < chunk.length) {
65
- if (!currentStream || bytesWritten >= chunkSize) {
66
- if (currentStream != null) {
67
- currentStream.end();
68
- }
69
- const chunkFileName = `${chunksDir}/${chunkIndex}`;
70
- currentStream = fs.createWriteStream(chunkFileName);
71
- chunkPaths.push(chunkFileName);
72
- chunkIndex++;
73
- bytesWritten = 0;
74
- }
75
- const bytesLeftInChunk = chunkSize - bytesWritten;
76
- const bytesLeftInBuffer = chunk.length - offset;
77
- const bytesToWrite = Math.min(bytesLeftInChunk, bytesLeftInBuffer);
78
- const slice = chunk.slice(offset, offset + bytesToWrite);
79
- currentStream.write(slice);
80
- bytesWritten += bytesToWrite;
81
- offset += bytesToWrite;
82
- }
83
- });
84
- inputStream.on('end', () => {
85
- if (currentStream != null) {
86
- currentStream.end();
87
- }
88
- resolve(chunkPaths.length);
89
- });
90
- });
91
- if (numWrittenChunks !== numChunks) {
92
- throw new Error(`numWrittenChunks (${numWrittenChunks}) does not equal numChunks (${numChunks})`);
62
+ // Each chunk is a copy of a range of the file. pipeline() resolves
63
+ // after the chunk file is completely written, so the upload reads the
64
+ // full chunk.
65
+ let start = 0;
66
+ for (const [chunkIndex, size] of chunkSizes(item.size, chunkSize).entries()) {
67
+ await pipeline(fs.createReadStream(item.filePath, { start, end: start + size - 1 }), fs.createWriteStream(`${chunksDir}/${chunkIndex}`));
68
+ start += size;
93
69
  }
94
70
  }
95
71
  for (let chunkIndex = 0; chunkIndex < numChunks; chunkIndex++) {
@@ -15,7 +15,7 @@ export declare const _getKVStoreKeys: (fastlyApiContext: FastlyApiContext, opera
15
15
  export declare function getKVStoreKeys(fastlyApiContext: FastlyApiContext, kvStoreName: string, prefix?: string): Promise<string[] | null>;
16
16
  export declare function getKvStoreEntryInfo(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<KvStoreEntryInfo | null>;
17
17
  export declare function getKvStoreEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, metadataOnly?: boolean): Promise<KvStoreEntryInfo | null>;
18
- export declare function kvStoreSubmitEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, data: ReadableStream<Uint8Array> | Uint8Array | string, metadata: string | undefined): Promise<void>;
18
+ export declare function kvStoreSubmitEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, data: Uint8Array | string, metadata: string | undefined): Promise<void>;
19
19
  export declare function kvStoreDeleteEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<void>;
20
20
  export type KvStoreBatchError = {
21
21
  key: string;
@@ -1 +1 @@
1
- {"version":3,"file":"kv-store.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,KAAK,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAGlF,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAUF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AASF,wBAAsB,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,mCAkB9E;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,mBAKhG;AAqCD,wBAAsB,eAAe,CAAC,gBAAgB,EAAE,gBAAgB,0BAcvE;AAED,eAAO,MAAM,eAAe,qBAjDgB,gBAAgB,iBAAiB,MAAM,sEA4DlF,CAAC;AAEF,wBAAsB,cAAc,CAClC,gBAAg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AC9B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAKF,wBAAsB,kBAAkB,CACtC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAwC9B"}
@@ -1,7 +1,13 @@
1
1
  /**
2
- * Resolve the AWS S3 hostname for a given region and bucket.
3
- * - Uses client-s3's own endpoint resolution logic (so it's always accurate).
4
- * - No network calls; intercepts at the build step.
2
+ * The AWS S3 host name of a bucket, for the backend of the app:
3
+ * <bucket>.s3.<region>.amazonaws.com. The server uses the same host name for a
4
+ * bucket without an endpoint (see objectUrl() in
5
+ * src/server/storage/s3-storage-provider.ts). It needs no credentials and no
6
+ * network.
7
+ *
8
+ * Returns null for a bucket name with a dot: under HTTPS, such a name does not
9
+ * match the certificate of *.s3.<region>.amazonaws.com. Such a bucket needs
10
+ * an endpoint, so that the bucket is in the path of the URL.
5
11
  */
6
- export declare function findHostnameForAwsS3RegionAndBucket(region: string, bucket: string): Promise<string>;
12
+ export declare function findHostnameForAwsS3RegionAndBucket(region: string, bucket: string): string | null;
7
13
  //# sourceMappingURL=s3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAsB,mCAAmC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqCzG"}
1
+ {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,wBAAgB,mCAAmC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKjG"}
@@ -2,42 +2,20 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- import { S3Client, HeadObjectCommand } from '@aws-sdk/client-s3';
6
- const DUMMY_KEY = 'dummy.dat'; // placeholder, never sent over the network
7
5
  /**
8
- * Resolve the AWS S3 hostname for a given region and bucket.
9
- * - Uses client-s3's own endpoint resolution logic (so it's always accurate).
10
- * - No network calls; intercepts at the build step.
6
+ * The AWS S3 host name of a bucket, for the backend of the app:
7
+ * <bucket>.s3.<region>.amazonaws.com. The server uses the same host name for a
8
+ * bucket without an endpoint (see objectUrl() in
9
+ * src/server/storage/s3-storage-provider.ts). It needs no credentials and no
10
+ * network.
11
+ *
12
+ * Returns null for a bucket name with a dot: under HTTPS, such a name does not
13
+ * match the certificate of *.s3.<region>.amazonaws.com. Such a bucket needs
14
+ * an endpoint, so that the bucket is in the path of the URL.
11
15
  */
12
- export async function findHostnameForAwsS3RegionAndBucket(region, bucket) {
13
- const client = new S3Client({ region });
14
- let hostname = '';
15
- const captureHostname = (_next) => async (args) => {
16
- if (typeof args.request === 'object' &&
17
- args.request != null &&
18
- 'hostname' in args.request &&
19
- typeof args.request['hostname'] === 'string') {
20
- hostname = args.request['hostname'];
21
- }
22
- const err = new Error('SHORT_CIRCUIT');
23
- err.name = 'SHORT_CIRCUIT';
24
- throw err; // short-circuit before auth/send
25
- };
26
- client.middlewareStack.add(captureHostname, {
27
- name: 'captureS3Hostname',
28
- step: 'build',
29
- priority: 'high', // run early in build
30
- });
31
- try {
32
- await client.send(new HeadObjectCommand({ Bucket: bucket, Key: DUMMY_KEY }));
16
+ export function findHostnameForAwsS3RegionAndBucket(region, bucket) {
17
+ if (bucket.includes('.')) {
18
+ return null;
33
19
  }
34
- catch (e) {
35
- if (typeof e !== 'object' ||
36
- e == null ||
37
- !('name' in e) ||
38
- e.name !== 'SHORT_CIRCUIT') {
39
- throw e;
40
- }
41
- }
42
- return hostname;
20
+ return `${bucket}.s3.${region}.amazonaws.com`;
43
21
  }
@@ -0,0 +1,20 @@
1
+ import type { AssetEntryMap } from '../assets/index.js';
2
+ export type IndexPartsInfo = {
3
+ count: number;
4
+ hash: string;
5
+ };
6
+ export declare const INDEX_PARTS_MIN_ENTRIES = 2000;
7
+ export declare const INDEX_PARTS_ENTRIES_PER_PART = 400;
8
+ export declare const INDEX_PARTS_MAX_COUNT = 1024;
9
+ export declare function getIndexPartsPrefix(publishId: string): string;
10
+ export declare function getIndexPartsSetPrefix(publishId: string, info: IndexPartsInfo): string;
11
+ export declare function getIndexPartKey(publishId: string, info: IndexPartsInfo, partNumber: number): string;
12
+ export declare function parseIndexPartKey(publishId: string, key: string): (IndexPartsInfo & {
13
+ partNumber: number;
14
+ }) | null;
15
+ export declare function chooseIndexPartCount(entryCount: number): number;
16
+ export declare function getIndexPartNumber(assetKey: string, count: number): number;
17
+ export declare function splitAssetEntryMap(assetEntryMap: AssetEntryMap, count: number): AssetEntryMap[];
18
+ export declare function encodeIndexPartsInfo(info: IndexPartsInfo): string;
19
+ export declare function decodeIndexPartsInfo(value: string | undefined | null): IndexPartsInfo | null;
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/index-parts/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAuBxD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAIF,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAG5C,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAGhD,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,UAEpD;AAGD,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,UAE7E;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAE1F;AAID,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,cAAc,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,IAAI,CAUlH;AAID,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,UAKtD;AAID,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAOjE;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,CAM/F;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,cAAc,UAExD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,cAAc,GAAG,IAAI,CAa5F"}
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ // Indexes with fewer entries than this are not split. Such an index is small
6
+ // enough to parse on each request.
7
+ export const INDEX_PARTS_MIN_ENTRIES = 2000;
8
+ // The target number of entries in one part.
9
+ export const INDEX_PARTS_ENTRIES_PER_PART = 400;
10
+ // The largest number of parts.
11
+ export const INDEX_PARTS_MAX_COUNT = 1024;
12
+ export function getIndexPartsPrefix(publishId) {
13
+ return `${publishId}_parts_`;
14
+ }
15
+ // The prefix of the keys of all parts of one index.
16
+ export function getIndexPartsSetPrefix(publishId, info) {
17
+ return `${getIndexPartsPrefix(publishId)}${info.hash}_${info.count}_`;
18
+ }
19
+ export function getIndexPartKey(publishId, info, partNumber) {
20
+ return `${getIndexPartsSetPrefix(publishId, info)}${partNumber}`;
21
+ }
22
+ // Gets the hash and the count from a key that starts with getIndexPartsPrefix(),
23
+ // or null if the key does not have this format.
24
+ export function parseIndexPartKey(publishId, key) {
25
+ const prefix = getIndexPartsPrefix(publishId);
26
+ if (!key.startsWith(prefix)) {
27
+ return null;
28
+ }
29
+ const match = /^([0-9a-f]{64})_(\d+)_(\d+)$/.exec(key.slice(prefix.length));
30
+ if (match == null) {
31
+ return null;
32
+ }
33
+ return { hash: match[1], count: Number(match[2]), partNumber: Number(match[3]) };
34
+ }
35
+ // The number of parts for an index with entryCount entries, or 0 if the index
36
+ // is not split.
37
+ export function chooseIndexPartCount(entryCount) {
38
+ if (entryCount < INDEX_PARTS_MIN_ENTRIES) {
39
+ return 0;
40
+ }
41
+ return Math.min(INDEX_PARTS_MAX_COUNT, Math.ceil(entryCount / INDEX_PARTS_ENTRIES_PER_PART));
42
+ }
43
+ // The part that has assetKey: FNV-1a (32 bits) of the UTF-16 code units of
44
+ // assetKey, modulo count.
45
+ export function getIndexPartNumber(assetKey, count) {
46
+ let hash = 0x811c9dc5;
47
+ for (let i = 0; i < assetKey.length; i++) {
48
+ hash ^= assetKey.charCodeAt(i);
49
+ hash = Math.imul(hash, 0x01000193) >>> 0;
50
+ }
51
+ return hash % count;
52
+ }
53
+ export function splitAssetEntryMap(assetEntryMap, count) {
54
+ const parts = Array.from({ length: count }, () => ({}));
55
+ for (const [assetKey, assetEntry] of Object.entries(assetEntryMap)) {
56
+ parts[getIndexPartNumber(assetKey, count)][assetKey] = assetEntry;
57
+ }
58
+ return parts;
59
+ }
60
+ export function encodeIndexPartsInfo(info) {
61
+ return `${info.count}:${info.hash}`;
62
+ }
63
+ export function decodeIndexPartsInfo(value) {
64
+ if (value == null) {
65
+ return null;
66
+ }
67
+ const match = /^(\d+):([0-9a-f]{64})$/.exec(String(value).trim());
68
+ if (match == null) {
69
+ return null;
70
+ }
71
+ const count = Number(match[1]);
72
+ if (count < 1 || count > INDEX_PARTS_MAX_COUNT) {
73
+ return null;
74
+ }
75
+ return { count, hash: match[2] };
76
+ }
@@ -1,7 +1,9 @@
1
+ import { type IndexPartsInfo } from '../index-parts/index.js';
1
2
  export type IndexMetadata = {
2
3
  publishedTime?: number;
3
4
  expirationTime?: number;
4
5
  requires?: string[];
6
+ indexParts?: IndexPartsInfo;
5
7
  otherFields?: Record<string, string>;
6
8
  };
7
9
  export declare const SUPPORTED_INDEX_FEATURES: readonly string[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAAO,CAAC;AAI9D,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAqBxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CA2BjG;AAGD,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,SAAS,MAAM,EAA6B,GAC9D,MAAM,EAAE,CAEV"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpB,UAAU,CAAC,EAAE,cAAc,CAAC;IAG5B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAAO,CAAC;AAI9D,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAyBxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CA6BjG;AAGD,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,SAAS,MAAM,EAA6B,GAC9D,MAAM,EAAE,CAEV"}
@@ -3,12 +3,13 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import { getMetadataFieldValue } from '../metadata/index.js';
6
+ import { decodeIndexPartsInfo, encodeIndexPartsInfo, } from '../index-parts/index.js';
6
7
  // The features that this version of PublisherServer supports. A server does
7
8
  // not serve a collection that requires a feature that is not in this list.
8
9
  // A feature name must not contain a comma, because the metadata uses commas to
9
10
  // separate the names. Use short kebab-case names, for example 'my-feature'.
10
11
  export const SUPPORTED_INDEX_FEATURES = [];
11
- const KNOWN_FIELDS = ['publishedTime', 'expirationTime', 'requires'];
12
+ const KNOWN_FIELDS = ['publishedTime', 'expirationTime', 'requires', 'indexParts'];
12
13
  export function encodeIndexMetadata(indexMetadata) {
13
14
  const result = { ...indexMetadata.otherFields };
14
15
  if (indexMetadata.publishedTime != null && !isNaN(indexMetadata.publishedTime)) {
@@ -25,6 +26,9 @@ export function encodeIndexMetadata(indexMetadata) {
25
26
  }
26
27
  result['requires'] = indexMetadata.requires.join(',');
27
28
  }
29
+ if (indexMetadata.indexParts != null) {
30
+ result['indexParts'] = encodeIndexPartsInfo(indexMetadata.indexParts);
31
+ }
28
32
  return result;
29
33
  }
30
34
  export function decodeIndexMetadata(obj) {
@@ -37,6 +41,7 @@ export function decodeIndexMetadata(obj) {
37
41
  const requires = requiresValue != null
38
42
  ? String(requiresValue).split(',').map(x => x.trim()).filter(x => x !== '')
39
43
  : [];
44
+ const indexParts = decodeIndexPartsInfo(getMetadataFieldValue(obj, 'indexParts'));
40
45
  // S3 makes the metadata keys lowercase, so compare the keys without case.
41
46
  const knownKeys = KNOWN_FIELDS.map(x => x.toLowerCase());
42
47
  let otherFields;
@@ -50,6 +55,7 @@ export function decodeIndexMetadata(obj) {
50
55
  publishedTime: !isNaN(publishedTime) ? publishedTime : undefined,
51
56
  expirationTime: !isNaN(expirationTime) ? expirationTime : undefined,
52
57
  requires: requires.length > 0 ? requires : undefined,
58
+ indexParts: indexParts ?? undefined,
53
59
  otherFields,
54
60
  };
55
61
  }
@@ -0,0 +1,20 @@
1
+ import type { AssetEntryMap } from '../assets/index.js';
2
+ export type IndexPartsInfo = {
3
+ count: number;
4
+ hash: string;
5
+ };
6
+ export declare const INDEX_PARTS_MIN_ENTRIES = 2000;
7
+ export declare const INDEX_PARTS_ENTRIES_PER_PART = 400;
8
+ export declare const INDEX_PARTS_MAX_COUNT = 1024;
9
+ export declare function getIndexPartsPrefix(publishId: string): string;
10
+ export declare function getIndexPartsSetPrefix(publishId: string, info: IndexPartsInfo): string;
11
+ export declare function getIndexPartKey(publishId: string, info: IndexPartsInfo, partNumber: number): string;
12
+ export declare function parseIndexPartKey(publishId: string, key: string): (IndexPartsInfo & {
13
+ partNumber: number;
14
+ }) | null;
15
+ export declare function chooseIndexPartCount(entryCount: number): number;
16
+ export declare function getIndexPartNumber(assetKey: string, count: number): number;
17
+ export declare function splitAssetEntryMap(assetEntryMap: AssetEntryMap, count: number): AssetEntryMap[];
18
+ export declare function encodeIndexPartsInfo(info: IndexPartsInfo): string;
19
+ export declare function decodeIndexPartsInfo(value: string | undefined | null): IndexPartsInfo | null;
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/index-parts/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAuBxD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAIF,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAG5C,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAGhD,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,UAEpD;AAGD,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,UAE7E;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAE1F;AAID,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,cAAc,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,IAAI,CAUlH;AAID,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,UAKtD;AAID,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAOjE;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,CAM/F;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,cAAc,UAExD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,cAAc,GAAG,IAAI,CAa5F"}
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ // Indexes with fewer entries than this are not split. Such an index is small
6
+ // enough to parse on each request.
7
+ export const INDEX_PARTS_MIN_ENTRIES = 2000;
8
+ // The target number of entries in one part.
9
+ export const INDEX_PARTS_ENTRIES_PER_PART = 400;
10
+ // The largest number of parts.
11
+ export const INDEX_PARTS_MAX_COUNT = 1024;
12
+ export function getIndexPartsPrefix(publishId) {
13
+ return `${publishId}_parts_`;
14
+ }
15
+ // The prefix of the keys of all parts of one index.
16
+ export function getIndexPartsSetPrefix(publishId, info) {
17
+ return `${getIndexPartsPrefix(publishId)}${info.hash}_${info.count}_`;
18
+ }
19
+ export function getIndexPartKey(publishId, info, partNumber) {
20
+ return `${getIndexPartsSetPrefix(publishId, info)}${partNumber}`;
21
+ }
22
+ // Gets the hash and the count from a key that starts with getIndexPartsPrefix(),
23
+ // or null if the key does not have this format.
24
+ export function parseIndexPartKey(publishId, key) {
25
+ const prefix = getIndexPartsPrefix(publishId);
26
+ if (!key.startsWith(prefix)) {
27
+ return null;
28
+ }
29
+ const match = /^([0-9a-f]{64})_(\d+)_(\d+)$/.exec(key.slice(prefix.length));
30
+ if (match == null) {
31
+ return null;
32
+ }
33
+ return { hash: match[1], count: Number(match[2]), partNumber: Number(match[3]) };
34
+ }
35
+ // The number of parts for an index with entryCount entries, or 0 if the index
36
+ // is not split.
37
+ export function chooseIndexPartCount(entryCount) {
38
+ if (entryCount < INDEX_PARTS_MIN_ENTRIES) {
39
+ return 0;
40
+ }
41
+ return Math.min(INDEX_PARTS_MAX_COUNT, Math.ceil(entryCount / INDEX_PARTS_ENTRIES_PER_PART));
42
+ }
43
+ // The part that has assetKey: FNV-1a (32 bits) of the UTF-16 code units of
44
+ // assetKey, modulo count.
45
+ export function getIndexPartNumber(assetKey, count) {
46
+ let hash = 0x811c9dc5;
47
+ for (let i = 0; i < assetKey.length; i++) {
48
+ hash ^= assetKey.charCodeAt(i);
49
+ hash = Math.imul(hash, 0x01000193) >>> 0;
50
+ }
51
+ return hash % count;
52
+ }
53
+ export function splitAssetEntryMap(assetEntryMap, count) {
54
+ const parts = Array.from({ length: count }, () => ({}));
55
+ for (const [assetKey, assetEntry] of Object.entries(assetEntryMap)) {
56
+ parts[getIndexPartNumber(assetKey, count)][assetKey] = assetEntry;
57
+ }
58
+ return parts;
59
+ }
60
+ export function encodeIndexPartsInfo(info) {
61
+ return `${info.count}:${info.hash}`;
62
+ }
63
+ export function decodeIndexPartsInfo(value) {
64
+ if (value == null) {
65
+ return null;
66
+ }
67
+ const match = /^(\d+):([0-9a-f]{64})$/.exec(String(value).trim());
68
+ if (match == null) {
69
+ return null;
70
+ }
71
+ const count = Number(match[1]);
72
+ if (count < 1 || count > INDEX_PARTS_MAX_COUNT) {
73
+ return null;
74
+ }
75
+ return { count, hash: match[2] };
76
+ }
@@ -1,7 +1,9 @@
1
+ import { type IndexPartsInfo } from '../index-parts/index.js';
1
2
  export type IndexMetadata = {
2
3
  publishedTime?: number;
3
4
  expirationTime?: number;
4
5
  requires?: string[];
6
+ indexParts?: IndexPartsInfo;
5
7
  otherFields?: Record<string, string>;
6
8
  };
7
9
  export declare const SUPPORTED_INDEX_FEATURES: readonly string[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAAO,CAAC;AAI9D,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAqBxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CA2BjG;AAGD,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,SAAS,MAAM,EAA6B,GAC9D,MAAM,EAAE,CAEV"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpB,UAAU,CAAC,EAAE,cAAc,CAAC;IAG5B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAAO,CAAC;AAI9D,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAyBxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CA6BjG;AAGD,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,SAAS,MAAM,EAA6B,GAC9D,MAAM,EAAE,CAEV"}
@@ -3,12 +3,13 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import { getMetadataFieldValue } from '../metadata/index.js';
6
+ import { decodeIndexPartsInfo, encodeIndexPartsInfo, } from '../index-parts/index.js';
6
7
  // The features that this version of PublisherServer supports. A server does
7
8
  // not serve a collection that requires a feature that is not in this list.
8
9
  // A feature name must not contain a comma, because the metadata uses commas to
9
10
  // separate the names. Use short kebab-case names, for example 'my-feature'.
10
11
  export const SUPPORTED_INDEX_FEATURES = [];
11
- const KNOWN_FIELDS = ['publishedTime', 'expirationTime', 'requires'];
12
+ const KNOWN_FIELDS = ['publishedTime', 'expirationTime', 'requires', 'indexParts'];
12
13
  export function encodeIndexMetadata(indexMetadata) {
13
14
  const result = { ...indexMetadata.otherFields };
14
15
  if (indexMetadata.publishedTime != null && !isNaN(indexMetadata.publishedTime)) {
@@ -25,6 +26,9 @@ export function encodeIndexMetadata(indexMetadata) {
25
26
  }
26
27
  result['requires'] = indexMetadata.requires.join(',');
27
28
  }
29
+ if (indexMetadata.indexParts != null) {
30
+ result['indexParts'] = encodeIndexPartsInfo(indexMetadata.indexParts);
31
+ }
28
32
  return result;
29
33
  }
30
34
  export function decodeIndexMetadata(obj) {
@@ -37,6 +41,7 @@ export function decodeIndexMetadata(obj) {
37
41
  const requires = requiresValue != null
38
42
  ? String(requiresValue).split(',').map(x => x.trim()).filter(x => x !== '')
39
43
  : [];
44
+ const indexParts = decodeIndexPartsInfo(getMetadataFieldValue(obj, 'indexParts'));
40
45
  // S3 makes the metadata keys lowercase, so compare the keys without case.
41
46
  const knownKeys = KNOWN_FIELDS.map(x => x.toLowerCase());
42
47
  let otherFields;
@@ -50,6 +55,7 @@ export function decodeIndexMetadata(obj) {
50
55
  publishedTime: !isNaN(publishedTime) ? publishedTime : undefined,
51
56
  expirationTime: !isNaN(expirationTime) ? expirationTime : undefined,
52
57
  requires: requires.length > 0 ? requires : undefined,
58
+ indexParts: indexParts ?? undefined,
53
59
  otherFields,
54
60
  };
55
61
  }
@@ -2,7 +2,7 @@ export { type StaticPublishRc } from '../models/config/static-publish-rc.js';
2
2
  export { type PublishContentConfig } from '../models/config/publish-content-config.js';
3
3
  export * as collectionSelector from './collection-selector/index.js';
4
4
  export { CookieCollectionSelector, type CookieCollectionSelectorOpts, } from './collection-selector/from-cookie.js';
5
- export { type StorageProvider, type StorageProviderBuilder, type StorageEntry, registerStorageProviderBuilder, } from './storage/storage-provider.js';
5
+ export { type GetEntryOptions, type StorageProvider, type StorageProviderBuilder, type StorageEntry, registerStorageProviderBuilder, } from './storage/storage-provider.js';
6
6
  export { setSecretStoreForS3Credentials, setSecretStoreKeyForS3AccessKeyId, setSecretStoreKeyForS3SecretAccessKey, setS3CredentialsBuilder, } from './storage/s3-storage-provider.js';
7
7
  export { PublisherServer } from './publisher-server/index.js';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,wBAAwB,EACxB,KAAK,4BAA4B,GAClC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,8BAA8B,EAC9B,iCAAiC,EACjC,qCAAqC,EACrC,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,wBAAwB,EACxB,KAAK,4BAA4B,GAClC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,8BAA8B,EAC9B,iCAAiC,EACjC,qCAAqC,EACrC,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function requestAcceptsTextHtml(request: Request): boolean;
2
+ //# sourceMappingURL=accept-html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accept-html.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/accept-html.ts"],"names":[],"mappings":"AAYA,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAyChE"}
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ // Returns true if the request accepts a text/html response.
6
+ // https://httpwg.org/specs/rfc9110.html#field.accept
7
+ // * A missing or empty Accept header accepts all media types.
8
+ // * The most specific media range that matches text/html gives the q-value:
9
+ // text/html, then text/*, then */*. A q-value of 0 means "not acceptable".
10
+ // * The media type parameters other than q are ignored.
11
+ // * A bare '*' is the same as '*/*'.
12
+ export function requestAcceptsTextHtml(request) {
13
+ const header = (request.headers.get('Accept') ?? '').trim();
14
+ if (header === '') {
15
+ return true;
16
+ }
17
+ // The highest q-value for each media range that matches text/html
18
+ let htmlQValue = null;
19
+ let textQValue = null;
20
+ let anyQValue = null;
21
+ for (const item of header.split(',')) {
22
+ const [rangeStr, ...paramStrs] = item.split(';');
23
+ const range = rangeStr.trim().toLowerCase();
24
+ if (range === '') {
25
+ continue;
26
+ }
27
+ let qValue = 1;
28
+ for (const paramStr of paramStrs) {
29
+ const [name, value] = paramStr.split('=');
30
+ if (name.trim().toLowerCase() !== 'q' || value == null) {
31
+ continue;
32
+ }
33
+ const parsed = parseFloat(value.trim());
34
+ if (!Number.isNaN(parsed)) {
35
+ qValue = Math.min(Math.max(parsed, 0), 1);
36
+ }
37
+ }
38
+ if (range === 'text/html') {
39
+ htmlQValue = Math.max(htmlQValue ?? 0, qValue);
40
+ }
41
+ else if (range === 'text/*') {
42
+ textQValue = Math.max(textQValue ?? 0, qValue);
43
+ }
44
+ else if (range === '*/*' || range === '*') {
45
+ anyQValue = Math.max(anyQValue ?? 0, qValue);
46
+ }
47
+ }
48
+ const qValue = htmlQValue ?? textQValue ?? anyQValue;
49
+ return qValue != null && qValue > 0;
50
+ }
@@ -27,6 +27,8 @@ export declare class PublisherServer {
27
27
  responseCache: ResponseCacheOptions | null;
28
28
  settingsCached: PublisherServerConfigNormalized | null | undefined;
29
29
  assetEntryMapCache: AssetEntryMap | null | undefined;
30
+ private indexCache;
31
+ private indexPartsCache;
30
32
  doNotStoreResponse: boolean;
31
33
  setActiveCollectionName(collectionName: string | null): void;
32
34
  setCollectionNameHeader(collectionHeader: string | null): void;
@@ -36,7 +38,10 @@ export declare class PublisherServer {
36
38
  private timed;
37
39
  getServerConfig(): Promise<PublisherServerConfigNormalized | null>;
38
40
  getStaticItems(): Promise<(string | RegExp)[]>;
41
+ private getIndex;
39
42
  getAssetEntryMap(): Promise<AssetEntryMap | null>;
43
+ private getIndexPart;
44
+ private findAssetEntry;
40
45
  getMatchingAsset(assetKey: string, applyAuto?: boolean): Promise<AssetEntry | null>;
41
46
  findAcceptEncodingsGroups(request: Request): Promise<ContentCompressionTypes[][]>;
42
47
  testExtendedCache(pathname: string): Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,+BAA+B,EACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB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