@fastly/compute-js-static-publish 4.0.0-alpha.0 → 4.0.0-alpha.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.
package/README.md CHANGED
@@ -422,6 +422,7 @@ const storeEntry = await asset.getStoreEntry();
422
422
 
423
423
  storeEntry.contentEncoding; // null, 'br', 'gzip'
424
424
  storeEntry.hash; // SHA256 of the contents of the file
425
+ storeEntry.size; // Size of file in bytes
425
426
  ```
426
427
 
427
428
  Regardless of which store these objects come from, they implement the `Body` interface as defined by `@fastly/js-compute`.
@@ -1 +1 @@
1
- {"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build-static.ts"],"names":[],"mappings":"AAuCA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AA0IhD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBA6d5F"}
1
+ {"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build-static.ts"],"names":[],"mappings":"AAuCA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AA6IhD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBA+d5F"}
@@ -34,7 +34,7 @@ import * as path from "path";
34
34
  import * as url from "url";
35
35
  import { loadConfigFile } from "../load-config.js";
36
36
  import { applyDefaults } from "../util/data.js";
37
- import { calculateFileHash } from "../util/hash.js";
37
+ import { calculateFileSizeAndHash } from "../util/hash.js";
38
38
  import { getFiles } from "../util/files.js";
39
39
  import { generateOrLoadPublishId } from "../util/publish-id.js";
40
40
  import { loadApiKey } from "../util/fastly-api.js";
@@ -220,12 +220,13 @@ export async function buildStaticLoader(commandLineValues) {
220
220
  });
221
221
  const stats = fs.statSync(file);
222
222
  const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
223
- const hash = calculateFileHash(file);
223
+ const { size, hash } = calculateFileSizeAndHash(file);
224
224
  return {
225
225
  file,
226
226
  assetKey,
227
227
  lastModifiedTime,
228
228
  hash,
229
+ size,
229
230
  ...contentAssetInclusionResult,
230
231
  ...moduleAssetInclusionResult,
231
232
  ...contentTypeTestResult,
@@ -255,15 +256,15 @@ export async function buildStaticLoader(commandLineValues) {
255
256
  }
256
257
  contentItems++;
257
258
  console.log(`✔️ [${contentItems}] ${assetInfo.assetKey}: ${JSON.stringify(assetInfo.contentType)}`);
258
- const { file, assetKey, contentType, text, hash, lastModifiedTime, } = assetInfo;
259
+ const { file, assetKey, contentType, text, hash, size, lastModifiedTime, } = assetInfo;
259
260
  const entryBase = {
260
261
  assetKey,
261
262
  contentType,
262
263
  lastModifiedTime,
263
- hash,
264
264
  text,
265
265
  fileInfo: {
266
266
  hash,
267
+ size,
267
268
  },
268
269
  };
269
270
  let metadata;
@@ -278,8 +279,8 @@ export async function buildStaticLoader(commandLineValues) {
278
279
  const staticFilePath = `${staticContentFilePath}_${alg}`;
279
280
  if (await compressTo(file, staticFilePath, text)) {
280
281
  console.log(`✔️ Compressed ${text ? 'text' : 'binary'} asset "${file}" to "${staticFilePath}" [${alg}].`);
281
- const hash = calculateFileHash(staticFilePath);
282
- func(alg, staticFilePath, hash);
282
+ const { size, hash } = calculateFileSizeAndHash(staticFilePath);
283
+ func(alg, staticFilePath, hash, size);
283
284
  }
284
285
  }
285
286
  }
@@ -292,8 +293,8 @@ export async function buildStaticLoader(commandLineValues) {
292
293
  fs.cpSync(file, staticFilePath);
293
294
  console.log(`✔️ Copied ${text ? 'text' : 'binary'} asset "${file}" to "${staticFilePath}".`);
294
295
  const compressedFileInfos = {};
295
- await prepareCompressedVersions(contentCompression, (alg, staticFilePath, hash) => {
296
- compressedFileInfos[alg] = { staticFilePath, hash };
296
+ await prepareCompressedVersions(contentCompression, (alg, staticFilePath, hash, size) => {
297
+ compressedFileInfos[alg] = { staticFilePath, hash, size };
297
298
  });
298
299
  metadata = {
299
300
  ...entryBase,
@@ -318,9 +319,9 @@ export async function buildStaticLoader(commandLineValues) {
318
319
  text,
319
320
  });
320
321
  const compressedFileInfos = {};
321
- await prepareCompressedVersions(contentCompression, (alg, staticFilePath, hash) => {
322
+ await prepareCompressedVersions(contentCompression, (alg, staticFilePath, hash, size) => {
322
323
  const objectStoreKey = `${publishId}:${assetKey}_${alg}_${hash}`;
323
- compressedFileInfos[alg] = { staticFilePath, objectStoreKey, hash };
324
+ compressedFileInfos[alg] = { staticFilePath, objectStoreKey, hash, size };
324
325
  objectStoreItems.push({
325
326
  objectStoreKey,
326
327
  staticFilePath,
@@ -1,9 +1,9 @@
1
1
  import fs from 'fs';
2
- import brotliCompress from 'brotli-compress';
2
+ import zlib from 'zlib';
3
3
  export const key = 'br';
4
4
  export async function compressTo(src, dest, isText) {
5
5
  const buffer = fs.readFileSync(src);
6
- const resultBuffer = await brotliCompress.compress(buffer);
6
+ const resultBuffer = zlib.brotliCompressSync(buffer);
7
7
  // Don't actually create the file if it would be bigger
8
8
  if (resultBuffer.length < buffer.length) {
9
9
  fs.writeFileSync(dest, resultBuffer);
@@ -1,2 +1,5 @@
1
- export declare function calculateFileHash(filename: string): string;
1
+ export declare function calculateFileSizeAndHash(filename: string): {
2
+ size: number;
3
+ hash: string;
4
+ };
2
5
  //# sourceMappingURL=hash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/cli/util/hash.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,UASjD"}
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/cli/util/hash.ts"],"names":[],"mappings":"AAGA,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM;;;EAUxD"}
@@ -1,8 +1,9 @@
1
1
  import crypto from 'crypto';
2
2
  import fs from 'fs';
3
- export function calculateFileHash(filename) {
3
+ export function calculateFileSizeAndHash(filename) {
4
4
  const fileBuffer = fs.readFileSync(filename);
5
+ const size = fileBuffer.length;
5
6
  const hash = crypto.createHash('sha256');
6
7
  hash.update(fileBuffer);
7
- return hash.digest('hex');
8
+ return { size, hash: hash.digest('hex') };
8
9
  }
@@ -5,11 +5,11 @@ import type { ContentCompressionTypes } from "../../constants/compression.js";
5
5
  export declare class ContentInlineAsset implements ContentAsset {
6
6
  readonly isInline: boolean;
7
7
  private readonly metadata;
8
- private readonly sourceAndHash;
9
- private readonly compressedSourcesAndHashes;
8
+ private readonly sourceAndInfo;
9
+ private readonly compressedSourcesAndInfo;
10
10
  constructor(metadata: ContentAssetMetadataMapEntryInline);
11
11
  get assetKey(): string;
12
- getStoreEntry(acceptEncodings?: ContentCompressionTypes[]): Promise<StoreEntry>;
12
+ getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
13
13
  getBytes(): Uint8Array;
14
14
  getText(): string;
15
15
  getMetadata(): ContentAssetMetadataMapEntry;
@@ -18,11 +18,11 @@ export declare class ContentObjectStoreAsset implements ContentAsset {
18
18
  readonly isInline: boolean;
19
19
  private readonly metadata;
20
20
  private readonly objectStoreName;
21
- private readonly sourceAndHash;
22
- private readonly compressedSourcesAndHashes;
21
+ private readonly sourceAndInfo;
22
+ private readonly compressedSourcesAndInfo;
23
23
  constructor(metadata: ContentAssetMetadataMapEntryObjectStore, objectStoreName: string);
24
24
  get assetKey(): string;
25
- getStoreEntry(acceptEncodings?: ContentCompressionTypes[]): Promise<StoreEntry>;
25
+ getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
26
26
  getBytes(): Uint8Array;
27
27
  getText(): string;
28
28
  getMetadata(): ContentAssetMetadataMapEntry;
@@ -1 +1 @@
1
- {"version":3,"file":"content-assets.d.ts","sourceRoot":"","sources":["../../../src/server/assets/content-assets.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,KAAK,EAEV,YAAY,EACZ,uBAAuB,EACvB,4BAA4B,EAC5B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CAAC,UAAU,CAAC;IA4BjG,QAAQ,IAAI,UAAU;IAItB,OAAO,IAAI,MAAM;IAIjB,WAAW,IAAI,4BAA4B;CAI5C;AAED,qBAAa,aAAc,SAAQ,YAAY,CAAC,YAAY,CAAC;gBAE/C,eAAe,EAAE,MAAM,GAAG,IAAI,EAAE,uBAAuB,EAAE,uBAAuB;CAsB7F"}
@@ -3,19 +3,45 @@ import { ObjectStore } from "fastly:object-store";
3
3
  import { AssetManager } from "./asset-manager.js";
4
4
  import { InlineStoreEntry } from "../object-store/inline-store-entry.js";
5
5
  const decoder = new TextDecoder();
6
+ function findMatchingSourceAndInfo(acceptEncodingsGroups, defaultSourceAndInfo, sourceAndInfoForEncodingFn) {
7
+ let sourceAndInfo;
8
+ let contentEncoding = null;
9
+ if (acceptEncodingsGroups != null) {
10
+ for (const encodingGroup of acceptEncodingsGroups) {
11
+ const sourceAndInfosForEncodingsGroup = encodingGroup
12
+ .map(encoding => ({ encoding, sourceAndInfo: sourceAndInfoForEncodingFn(encoding) }))
13
+ .filter(x => x.sourceAndInfo != null);
14
+ if (sourceAndInfosForEncodingsGroup.length === 0) {
15
+ // If no encoding in this group is available then move to next group
16
+ continue;
17
+ }
18
+ // Sort the items, putting the smallest size first
19
+ sourceAndInfosForEncodingsGroup
20
+ .sort((a, b) => a.sourceAndInfo.size - b.sourceAndInfo.size);
21
+ // The first item is the one we want.
22
+ sourceAndInfo = sourceAndInfosForEncodingsGroup[0].sourceAndInfo;
23
+ contentEncoding = sourceAndInfosForEncodingsGroup[0].encoding;
24
+ break;
25
+ }
26
+ }
27
+ sourceAndInfo ?? (sourceAndInfo = defaultSourceAndInfo);
28
+ return { sourceAndInfo, contentEncoding };
29
+ }
6
30
  export class ContentInlineAsset {
7
31
  constructor(metadata) {
8
32
  this.isInline = true;
9
33
  this.metadata = metadata;
10
- this.sourceAndHash = {
34
+ this.sourceAndInfo = {
11
35
  source: includeBytes(metadata.fileInfo.staticFilePath),
12
36
  hash: metadata.fileInfo.hash,
37
+ size: metadata.fileInfo.size,
13
38
  };
14
- this.compressedSourcesAndHashes = Object.entries(metadata.compressedFileInfos)
39
+ this.compressedSourcesAndInfo = Object.entries(metadata.compressedFileInfos)
15
40
  .reduce((obj, [key, value]) => {
16
41
  obj[key] = {
17
42
  source: includeBytes(value.staticFilePath),
18
43
  hash: value.hash,
44
+ size: value.size,
19
45
  };
20
46
  return obj;
21
47
  }, {});
@@ -23,29 +49,19 @@ export class ContentInlineAsset {
23
49
  get assetKey() {
24
50
  return this.metadata.assetKey;
25
51
  }
26
- async getStoreEntry(acceptEncodings) {
27
- let sourceAndHash;
28
- let contentEncoding = null;
29
- if (acceptEncodings != null) {
30
- for (const encoding of acceptEncodings) {
31
- sourceAndHash = this.compressedSourcesAndHashes[encoding];
32
- if (sourceAndHash != null) {
33
- contentEncoding = encoding;
34
- break;
35
- }
36
- }
37
- }
38
- sourceAndHash ?? (sourceAndHash = this.sourceAndHash);
39
- return new InlineStoreEntry(sourceAndHash.source, contentEncoding, sourceAndHash.hash);
52
+ async getStoreEntry(acceptEncodingsGroups = []) {
53
+ const { sourceAndInfo, contentEncoding } = findMatchingSourceAndInfo(acceptEncodingsGroups, this.sourceAndInfo, encoding => this.compressedSourcesAndInfo[encoding]);
54
+ const { source, hash, size } = sourceAndInfo;
55
+ return new InlineStoreEntry(source, contentEncoding, hash, size);
40
56
  }
41
57
  getBytes() {
42
- return this.sourceAndHash.source;
58
+ return this.sourceAndInfo.source;
43
59
  }
44
60
  getText() {
45
61
  if (!this.metadata.text) {
46
62
  throw new Error("Can't getText() for non-text content");
47
63
  }
48
- return decoder.decode(this.sourceAndHash.source);
64
+ return decoder.decode(this.sourceAndInfo.source);
49
65
  }
50
66
  getMetadata() {
51
67
  return this.metadata;
@@ -56,15 +72,17 @@ export class ContentObjectStoreAsset {
56
72
  this.isInline = false;
57
73
  this.metadata = metadata;
58
74
  this.objectStoreName = objectStoreName;
59
- this.sourceAndHash = {
75
+ this.sourceAndInfo = {
60
76
  source: metadata.fileInfo.objectStoreKey,
61
77
  hash: metadata.fileInfo.hash,
78
+ size: metadata.fileInfo.size,
62
79
  };
63
- this.compressedSourcesAndHashes = Object.entries(metadata.compressedFileInfos)
80
+ this.compressedSourcesAndInfo = Object.entries(metadata.compressedFileInfos)
64
81
  .reduce((obj, [key, value]) => {
65
82
  obj[key] = {
66
83
  source: value.objectStoreKey,
67
84
  hash: value.hash,
85
+ size: value.size,
68
86
  };
69
87
  return obj;
70
88
  }, {});
@@ -72,26 +90,15 @@ export class ContentObjectStoreAsset {
72
90
  get assetKey() {
73
91
  return this.metadata.assetKey;
74
92
  }
75
- async getStoreEntry(acceptEncodings = []) {
76
- let sourceAndHash;
77
- let contentEncoding = null;
78
- if (acceptEncodings != null) {
79
- for (const encoding of acceptEncodings) {
80
- sourceAndHash = this.compressedSourcesAndHashes[encoding];
81
- if (sourceAndHash != null) {
82
- contentEncoding = encoding;
83
- break;
84
- }
85
- }
86
- }
87
- sourceAndHash ?? (sourceAndHash = this.sourceAndHash);
88
- const hash = sourceAndHash.hash;
93
+ async getStoreEntry(acceptEncodingsGroups = []) {
94
+ const { sourceAndInfo, contentEncoding } = findMatchingSourceAndInfo(acceptEncodingsGroups, this.sourceAndInfo, encoding => this.compressedSourcesAndInfo[encoding]);
89
95
  const objectStore = new ObjectStore(this.objectStoreName);
90
96
  let retries = 3;
91
97
  while (retries > 0) {
92
- const storeEntry = await objectStore.get(sourceAndHash.source);
98
+ const storeEntry = await objectStore.get(sourceAndInfo.source);
93
99
  if (storeEntry != null) {
94
- return Object.assign(storeEntry, { contentEncoding, hash });
100
+ const { hash, size } = sourceAndInfo;
101
+ return Object.assign(storeEntry, { contentEncoding, hash, size });
95
102
  }
96
103
  // Note the null does NOT mean 404. The fact that we are here means
97
104
  // metadata exists for this path, and we're just trying to get the data from
@@ -4,7 +4,8 @@ export declare class InlineStoreEntry implements StoreEntry {
4
4
  _body: ReadableStreamForBytes;
5
5
  _contentEncoding: string | null;
6
6
  _hash: string;
7
- constructor(array: Uint8Array, contentEncoding: string | null, hash: string);
7
+ _size: number;
8
+ constructor(array: Uint8Array, contentEncoding: string | null, hash: string, size: number);
8
9
  get body(): ReadableStream<Uint8Array>;
9
10
  get bodyUsed(): boolean;
10
11
  arrayBuffer(): Promise<ArrayBuffer>;
@@ -13,6 +14,7 @@ export declare class InlineStoreEntry implements StoreEntry {
13
14
  json(): Promise<any>;
14
15
  get contentEncoding(): string | null;
15
16
  get hash(): string;
17
+ get size(): number;
16
18
  }
17
19
  declare class ReadableStreamForBytes extends ReadableStream<Uint8Array> {
18
20
  _disturbed: boolean;
@@ -1 +1 @@
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;gBAEF,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM;IAO3E,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;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
+ {"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,11 +1,12 @@
1
1
  // A class designed to give a Body-style interface to Uint8Array.
2
2
  // The intended use case is arrays brought in from includeBytes().
3
3
  export class InlineStoreEntry {
4
- constructor(array, contentEncoding, hash) {
4
+ constructor(array, contentEncoding, hash, size) {
5
5
  this._body = new ReadableStreamForBytes(array);
6
6
  this._consumed = false;
7
7
  this._contentEncoding = contentEncoding;
8
8
  this._hash = hash;
9
+ this._size = size;
9
10
  }
10
11
  get body() {
11
12
  return this._body;
@@ -57,6 +58,9 @@ export class InlineStoreEntry {
57
58
  get hash() {
58
59
  return this._hash;
59
60
  }
61
+ get size() {
62
+ return this._size;
63
+ }
60
64
  }
61
65
  InlineStoreEntry.decoder = new TextDecoder();
62
66
  class ReadableStreamForBytes extends ReadableStream {
@@ -13,7 +13,7 @@ export declare class PublisherServer {
13
13
  private readonly contentAssets;
14
14
  constructor(serverConfig: PublisherServerConfigNormalized, contentAssets: ContentAssets);
15
15
  getMatchingAsset(path: string): ContentAsset | null;
16
- findAcceptEncodings(request: Request): ContentCompressionTypes[];
16
+ findAcceptEncodings(request: Request): ContentCompressionTypes[][];
17
17
  testExtendedCache(pathname: string): boolean;
18
18
  handlePreconditions(request: Request, asset: ContentAsset, responseHeaders: Record<string, string>): Response | null;
19
19
  serveAsset(request: Request, asset: ContentAsset, init?: AssetInit): Promise<Response>;
@@ -1 +1 @@
1
- {"version":3,"file":"publisher-server.d.ts","sourceRoot":"","sources":["../../src/server/publisher-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAK3D,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAmB3E,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,IAAI,CAAC;CACrC,CAAC;AAEF,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;IAC/D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;gB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AAgB;gBAG5C,YAAY,EAAE,+BAA+B,EAC7C,aAAa,EAAE,aAAa;IAoB9B,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IA2CnD,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,uBAAuB,EAAE,EAAE;IAgDlE,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAalC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,QAAQ,GAAG,IAAI;IA6D9G,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IA0CtF,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CA8C/D"}
@@ -78,9 +78,42 @@ export class PublisherServer {
78
78
  }
79
79
  const found = (request.headers.get('accept-encoding') ?? '')
80
80
  .split(',')
81
- .map(x => x.trim())
82
- .filter(x => this.serverConfig.compression.includes(x));
83
- return found;
81
+ .map(x => {
82
+ let [encodingValue, qValueStr] = x.trim().split(';');
83
+ let qValue; // q value multiplied by 1000
84
+ if (qValueStr == null || !qValueStr.startsWith('q=')) {
85
+ // use default of 1.0
86
+ qValue = 1000;
87
+ }
88
+ else {
89
+ qValueStr = qValueStr.slice(2); // remove the q=
90
+ qValue = parseFloat(qValueStr);
91
+ if (Number.isNaN(qValue) || qValue > 1) {
92
+ qValue = 1;
93
+ }
94
+ if (qValue < 0) {
95
+ qValue = 0;
96
+ }
97
+ // q values can have up to 3 decimal digits
98
+ qValue = Math.floor(qValue * 1000);
99
+ }
100
+ return [encodingValue.trim(), qValue];
101
+ })
102
+ .filter(([encoding]) => this.serverConfig.compression.includes(encoding));
103
+ const priorityMap = new Map;
104
+ for (const [encoding, qValue] of found) {
105
+ let typesForQValue = priorityMap.get(qValue);
106
+ if (typesForQValue == null) {
107
+ typesForQValue = [];
108
+ priorityMap.set(qValue, typesForQValue);
109
+ }
110
+ typesForQValue.push(encoding);
111
+ }
112
+ // Sort keys, larger numbers to come first
113
+ const keysSorted = [...priorityMap.keys()]
114
+ .sort((qValueA, qValueB) => qValueB - qValueA);
115
+ return keysSorted
116
+ .map(qValue => priorityMap.get(qValue));
84
117
  }
85
118
  testExtendedCache(pathname) {
86
119
  return this.staticItems
@@ -6,5 +6,6 @@ export interface StoreEntry {
6
6
  text(): Promise<string>;
7
7
  readonly contentEncoding: string | null;
8
8
  readonly hash: string;
9
+ readonly size: number;
9
10
  }
10
11
  //# sourceMappingURL=compute.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../src/types/compute.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAGpC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IACrB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
1
+ {"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../src/types/compute.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAGpC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IACrB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
@@ -3,6 +3,7 @@ import type { StoreEntry } from "../types/compute.js";
3
3
  export type CompressedFileInfos<TData> = Partial<Record<ContentCompressionTypes, TData>>;
4
4
  export type ContentFileInfo = {
5
5
  hash: string;
6
+ size: number;
6
7
  staticFilePath: string;
7
8
  };
8
9
  export type ContentFileInfoForObjectStore = ContentFileInfo & {
@@ -29,7 +30,7 @@ export type ContentAssetMetadataMap = {
29
30
  export interface ContentAsset {
30
31
  readonly assetKey: string;
31
32
  getMetadata(): ContentAssetMetadataMapEntry;
32
- getStoreEntry(acceptEncodings?: ContentCompressionTypes[]): Promise<StoreEntry>;
33
+ getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
33
34
  getBytes(): Uint8Array;
34
35
  getText(): string;
35
36
  readonly isInline: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"content-assets.d.ts","sourceRoot":"","sources":["../../src/types/content-assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC,CAAC;AAEzF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,eAAe,GAAG;IAC5D,cAAc,EAAE,MAAM,CAAC;CACxB,CAAA;AAED,MAAM,MAAM,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"@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "4.0.0-alpha.0",
4
+ "version": "4.0.0-alpha.1",
5
5
  "description": "Static Publisher for Compute@Edge JavaScript",
6
6
  "main": "./build/index.js",
7
7
  "types": "./build/index.d.ts",
@@ -32,7 +32,6 @@
32
32
  "homepage": "https://github.com/fastly/compute-js-static-publish#readme",
33
33
  "dependencies": {
34
34
  "@fastly/js-compute": "^1.4.0",
35
- "brotli-compress": "^1.3.3",
36
35
  "command-line-args": "^5.2.1",
37
36
  "glob-to-regexp": "^0.4.1"
38
37
  },