@fastly/compute-js-static-publish 8.0.0-beta.12 → 8.0.0-beta.14

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.
@@ -1 +1 @@
1
- {"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AA8GA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA8hBhD"}
1
+ {"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AA+GA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAiiBhD"}
@@ -13,7 +13,7 @@ import { applyDefaults } from '../../util/data.js';
13
13
  import { calculateFileSizeAndHash, enumerateFiles, rootRelative } from '../../util/files.js';
14
14
  import { ensureVariantFileExists } from '../../util/variants.js';
15
15
  import { concurrentMap } from '../../util/retryable.js';
16
- import { loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
16
+ import { getStorageKeysByHexPrefix, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
17
17
  // Storage key format:
18
18
  // <publishId>_index_<preview_id>.json
19
19
  // <publishId>_settings_<preview_id>.json
@@ -283,11 +283,14 @@ export async function action(actionArgs) {
283
283
  // The key of a file is the hash of its content. If the key exists, storage
284
284
  // already has the same content. Thus we do not compress, hash, or upload it again.
285
285
  // In local mode, a key can refer to a working file that was deleted, so we do not list.
286
+ // All the keys that the scan looks for start with `<publishId>_files_sha256_` and a hex
287
+ // hash, so we list them in 16 parts at the same time.
286
288
  let existingKeys;
287
289
  if (!overwriteExisting && !localMode) {
288
290
  console.log(`🔎 Listing files that are already in storage...`);
289
- existingKeys = new Set(await storageProvider.getStorageKeys(`${publishId}_files_`) ?? []);
290
- console.log(`✅ Found ${existingKeys.size} key(s).`);
291
+ const listStart = Date.now();
292
+ existingKeys = new Set(await getStorageKeysByHexPrefix(storageProvider, `${publishId}_files_sha256_`) ?? []);
293
+ console.log(`✅ Found ${existingKeys.size} key(s) in ${((Date.now() - listStart) / 1000).toFixed(1)} s.`);
291
294
  }
292
295
  let existingVariantCount = 0;
293
296
  function isVariantInStorage(variantKey, numChunks) {
@@ -40,6 +40,7 @@ export type StorageProviderBuilderContext = {
40
40
  s3UploadConcurrency?: number;
41
41
  };
42
42
  export type StorageProviderBuilder = (config: StaticPublishRc, context: StorageProviderBuilderContext) => (Promise<StorageProvider | null> | StorageProvider | null);
43
+ export declare function getStorageKeysByHexPrefix(storageProvider: StorageProvider, prefix: string): Promise<string[] | null>;
43
44
  export declare function registerStorageProviderBuilder(builder: StorageProviderBuilder): void;
44
45
  export declare function loadStorageProviderFromStaticPublishRc(config: StaticPublishRc, context: StorageProviderBuilderContext): Promise<StorageProvider>;
45
46
  //# 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,YA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AAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC5B,CAAC;AAEF,qBAAa,oBAAoB;;IAI/B,2BAA2B,EAAE,yBAAyB,EAAE,CAAC;IACzD,GAAG,CAAC,KAAK,EAAE,yBAAyB;CAGrC;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AACF,MAAM,MAAM,sBAAsB,GAChC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,KAAK,CAAC,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC,CAAC;AAQlI,wBAAsB,yBAAyB,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAQ1H;AAGD,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,QAE7E;AAED,wBAAsB,sCAAsC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,4BAS3H"}
@@ -10,6 +10,19 @@ export class StorageProviderBatch {
10
10
  this.storageProviderBatchEntries.push(entry);
11
11
  }
12
12
  }
13
+ // Lists the keys that start with `prefix` followed by a lowercase hex digit.
14
+ // Use it for a prefix that a hex hash follows, such as `<publishId>_files_sha256_`.
15
+ // A listing gets its keys one page at a time, and each page needs the previous
16
+ // page. Thus this function runs one listing for each of the 16 hex digits at the
17
+ // same time. The total time is approximately the time of the largest part.
18
+ // Returns null only if all the listings return null.
19
+ export async function getStorageKeysByHexPrefix(storageProvider, prefix) {
20
+ const parts = await Promise.all('0123456789abcdef'.split('').map((digit) => storageProvider.getStorageKeys(prefix + digit)));
21
+ if (parts.every((part) => part == null)) {
22
+ return null;
23
+ }
24
+ return parts.flatMap((part) => part ?? []);
25
+ }
13
26
  const _storageProviderBuilders = [];
14
27
  export function registerStorageProviderBuilder(builder) {
15
28
  _storageProviderBuilders.push(builder);
@@ -3,6 +3,7 @@ import { type PublisherServerConfigNormalized } from '../../models/config/publis
3
3
  import { type ContentCompressionTypes } from '../../models/compression/index.js';
4
4
  import { type AssetEntry, type AssetEntryMap, type AssetVariantMetadata } from '../../models/assets/index.js';
5
5
  import { type StorageEntry, type StorageProvider } from '../storage/storage-provider.js';
6
+ import { ServerTiming } from '../util/server-timing.js';
6
7
  type AssetVariant = {
7
8
  storageEntry: StorageEntry;
8
9
  } & AssetVariantMetadata;
@@ -20,10 +21,15 @@ export declare class PublisherServer {
20
21
  defaultCollectionName: string;
21
22
  activeCollectionName: string;
22
23
  collectionNameHeader: string | null;
24
+ serverTimingRequestHeader: string | null;
25
+ serverTiming: ServerTiming | null;
23
26
  settingsCached: PublisherServerConfigNormalized | null | undefined;
24
27
  assetEntryMapCache: AssetEntryMap | null | undefined;
25
28
  setActiveCollectionName(collectionName: string): void;
26
29
  setCollectionNameHeader(collectionHeader: string | null): void;
30
+ setServerTimingRequestHeader(requestHeader: string | null): void;
31
+ beginRequest(request: Request): void;
32
+ private timed;
27
33
  getServerConfig(): Promise<PublisherServerConfigNormalized | null>;
28
34
  getStaticItems(): Promise<(string | RegExp)[]>;
29
35
  getAssetEntryMap(): Promise<AssetEntryMap | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AAOA,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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AAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI;IA6DtF,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;YA8BzG,wCAAwC;IAyChD,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IAqDpF,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAuE/D"}
@@ -8,6 +8,7 @@ import { isExpired } from '../../models/time/index.js';
8
8
  import { loadStorageProviderFromStaticPublishRc, } from '../storage/storage-provider.js';
9
9
  import { checkIfModifiedSince, getIfModifiedSinceHeader } from './serve-preconditions/if-modified-since.js';
10
10
  import { checkIfNoneMatch, getIfNoneMatchHeader } from './serve-preconditions/if-none-match.js';
11
+ import { ServerTiming } from '../util/server-timing.js';
11
12
  export function buildHeadersSubset(responseHeaders, keys) {
12
13
  const resultHeaders = new Headers();
13
14
  for (const value of keys) {
@@ -42,6 +43,8 @@ export class PublisherServer {
42
43
  this.defaultCollectionName = defaultCollectionName;
43
44
  this.activeCollectionName = this.defaultCollectionName;
44
45
  this.collectionNameHeader = 'X-Publisher-Server-Collection';
46
+ this.serverTimingRequestHeader = null;
47
+ this.serverTiming = null;
45
48
  }
46
49
  static fromStaticPublishRc(config) {
47
50
  const storeProvider = loadStorageProviderFromStaticPublishRc(config);
@@ -55,21 +58,35 @@ export class PublisherServer {
55
58
  setCollectionNameHeader(collectionHeader) {
56
59
  this.collectionNameHeader = collectionHeader;
57
60
  }
61
+ // Set the request header that turns on the Server-Timing response header.
62
+ // null (the default) turns timing off.
63
+ setServerTimingRequestHeader(requestHeader) {
64
+ this.serverTimingRequestHeader = requestHeader;
65
+ }
66
+ // Start handling a new request. serveRequest() calls this. If you call
67
+ // getMatchingAsset() and serveAsset() directly, call this first.
68
+ beginRequest(request) {
69
+ const header = this.serverTimingRequestHeader;
70
+ this.serverTiming = header != null && request.headers.has(header) ? new ServerTiming() : null;
71
+ }
72
+ timed(name, fn) {
73
+ return this.serverTiming != null ? this.serverTiming.measure(name, fn) : fn();
74
+ }
58
75
  // Server config is obtained from storage, and cached for the duration of this object.
59
76
  async getServerConfig() {
60
77
  if (this.settingsCached !== undefined) {
61
78
  return this.settingsCached;
62
79
  }
63
80
  const settingsFileKey = `${this.publishId}_settings_${this.activeCollectionName}`;
64
- const settingsFile = await this.storageProvider.getEntry(settingsFileKey, [`${this.publishId}-${this.activeCollectionName}`, 'settings']);
65
- if (settingsFile == null) {
66
- console.error(`Settings File not found at ${settingsFileKey}.`);
67
- console.error(`You may need to publish your application.`);
68
- this.settingsCached = null;
69
- }
70
- else {
71
- this.settingsCached = (await settingsFile.json());
72
- }
81
+ this.settingsCached = await this.timed('settings', async () => {
82
+ const settingsFile = await this.storageProvider.getEntry(settingsFileKey, [`${this.publishId}-${this.activeCollectionName}`, 'settings']);
83
+ if (settingsFile == null) {
84
+ console.error(`Settings File not found at ${settingsFileKey}.`);
85
+ console.error(`You may need to publish your application.`);
86
+ return null;
87
+ }
88
+ return (await settingsFile.json());
89
+ });
73
90
  return this.settingsCached;
74
91
  }
75
92
  async getStaticItems() {
@@ -96,7 +113,7 @@ export class PublisherServer {
96
113
  return this.assetEntryMapCache;
97
114
  }
98
115
  const indexFileKey = `${this.publishId}_index_${this.activeCollectionName}`;
99
- const indexFile = await this.storageProvider.getEntry(indexFileKey, [`${this.publishId}-${this.activeCollectionName}`, 'index']);
116
+ const indexFile = await this.timed('index', () => this.storageProvider.getEntry(indexFileKey, [`${this.publishId}-${this.activeCollectionName}`, 'index']));
100
117
  if (indexFile == null) {
101
118
  console.error(`Index File not found at ${indexFileKey}.`);
102
119
  console.error(`You may need to publish your application.`);
@@ -124,7 +141,9 @@ export class PublisherServer {
124
141
  this.assetEntryMapCache = null;
125
142
  return null;
126
143
  }
127
- this.assetEntryMapCache = (await indexFile.json());
144
+ // Read and parse in two steps, so that Server-Timing can report each one.
145
+ const indexText = await this.timed('index-body', () => indexFile.text());
146
+ this.assetEntryMapCache = await this.timed('index-parse', async () => JSON.parse(indexText));
128
147
  return this.assetEntryMapCache;
129
148
  }
130
149
  async getMatchingAsset(assetKey, applyAuto = false) {
@@ -296,7 +315,7 @@ export class PublisherServer {
296
315
  const baseHash = entry.key.slice(7);
297
316
  const baseKey = `${this.publishId}_files_sha256_${baseHash}`;
298
317
  const variantKey = variant != null ? `${baseKey}_${variant}` : baseKey;
299
- const storageEntry = await this.storageProvider.getEntry(variantKey);
318
+ const storageEntry = await this.timed('asset', () => this.storageProvider.getEntry(variantKey));
300
319
  if (storageEntry == null) {
301
320
  return null;
302
321
  }
@@ -380,6 +399,9 @@ export class PublisherServer {
380
399
  if (asset.lastModifiedTime !== 0) {
381
400
  headers.set('Last-Modified', (new Date(asset.lastModifiedTime * 1000)).toUTCString());
382
401
  }
402
+ if (this.serverTiming != null) {
403
+ headers.append('Server-Timing', this.serverTiming.toHeaderValue());
404
+ }
383
405
  const preconditionResponse = this.handlePreconditions(request, asset, headers);
384
406
  if (preconditionResponse != null) {
385
407
  return preconditionResponse;
@@ -391,6 +413,7 @@ export class PublisherServer {
391
413
  });
392
414
  }
393
415
  async serveRequest(request) {
416
+ this.beginRequest(request);
394
417
  // Only handle GET and HEAD
395
418
  if (request.method !== 'GET' && request.method !== 'HEAD') {
396
419
  return null;
@@ -0,0 +1,7 @@
1
+ export declare class ServerTiming {
2
+ private entries;
3
+ add(name: string, dur: number, desc?: string): void;
4
+ measure<T>(name: string, fn: () => Promise<T>, desc?: string): Promise<T>;
5
+ toHeaderValue(): string;
6
+ }
7
+ //# sourceMappingURL=server-timing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-timing.d.ts","sourceRoot":"","sources":["../../../../src/server/util/server-timing.ts"],"names":[],"mappings":"AAaA,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAA2B;IAE1C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAItC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAS/E,aAAa,IAAI,MAAM;CAWxB"}
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ // Collects durations for one request and formats them as a Server-Timing
6
+ // header value (https://www.w3.org/TR/server-timing/).
7
+ export class ServerTiming {
8
+ constructor() {
9
+ this.entries = [];
10
+ }
11
+ add(name, dur, desc) {
12
+ this.entries.push({ name, dur, desc });
13
+ }
14
+ async measure(name, fn, desc) {
15
+ const start = performance.now();
16
+ try {
17
+ return await fn();
18
+ }
19
+ finally {
20
+ this.add(name, performance.now() - start, desc);
21
+ }
22
+ }
23
+ toHeaderValue() {
24
+ return this.entries
25
+ .map(({ name, dur, desc }) => {
26
+ let value = `${name};dur=${dur.toFixed(1)}`;
27
+ if (desc != null) {
28
+ value += `;desc=${JSON.stringify(desc)}`;
29
+ }
30
+ return value;
31
+ })
32
+ .join(', ');
33
+ }
34
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "8.0.0-beta.12",
4
+ "version": "8.0.0-beta.14",
5
5
  "description": "Static Publisher for Fastly Compute JavaScript",
6
6
  "main": "build/index.js",
7
7
  "exports": {