@fastly/compute-js-static-publish 3.6.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.
Files changed (197) hide show
  1. package/README.md +441 -103
  2. package/build/assets/asset-manager.d.ts +7 -0
  3. package/build/assets/asset-manager.d.ts.map +1 -0
  4. package/build/assets/asset-manager.js +11 -0
  5. package/build/assets/content-assets.d.ts +29 -0
  6. package/build/assets/content-assets.d.ts.map +1 -0
  7. package/build/assets/content-assets.js +88 -0
  8. package/build/assets/module-assets.d.ts +23 -0
  9. package/build/assets/module-assets.d.ts.map +1 -0
  10. package/build/assets/module-assets.js +45 -0
  11. package/build/cli/build-static.d.ts.map +1 -0
  12. package/build/cli/build-static.js +524 -0
  13. package/build/cli/clean-object-store.d.ts +2 -0
  14. package/build/cli/clean-object-store.d.ts.map +1 -0
  15. package/build/cli/cli.d.ts.map +1 -0
  16. package/build/{cli.js → cli/cli.js} +0 -0
  17. package/build/cli/commands/build-static.d.ts +3 -0
  18. package/build/cli/commands/build-static.d.ts.map +1 -0
  19. package/build/cli/commands/build-static.js +502 -0
  20. package/build/cli/commands/clean-object-store.d.ts +3 -0
  21. package/build/cli/commands/clean-object-store.d.ts.map +1 -0
  22. package/build/cli/commands/clean-object-store.js +54 -0
  23. package/build/cli/commands/init-app.d.ts.map +1 -0
  24. package/build/cli/commands/init-app.js +559 -0
  25. package/build/cli/compression/brotli.d.ts +3 -0
  26. package/build/cli/compression/brotli.d.ts.map +1 -0
  27. package/build/cli/compression/brotli.js +15 -0
  28. package/build/cli/compression/gzip.d.ts +3 -0
  29. package/build/cli/compression/gzip.d.ts.map +1 -0
  30. package/build/cli/compression/gzip.js +15 -0
  31. package/build/cli/compression/index.d.ts +8 -0
  32. package/build/cli/compression/index.d.ts.map +1 -0
  33. package/build/cli/compression/index.js +12 -0
  34. package/build/cli/index.d.ts +3 -0
  35. package/build/cli/index.d.ts.map +1 -0
  36. package/build/cli/index.js +86 -0
  37. package/build/cli/init-app.d.ts +3 -0
  38. package/build/cli/init-app.d.ts.map +1 -0
  39. package/build/{init-app.js → cli/init-app.js} +16 -16
  40. package/build/cli/load-config.d.ts +3 -0
  41. package/build/cli/load-config.d.ts.map +1 -0
  42. package/build/cli/load-config.js +357 -0
  43. package/build/cli/presets/implementations/create-react-app.d.ts +11 -0
  44. package/build/cli/presets/implementations/create-react-app.d.ts.map +1 -0
  45. package/build/cli/presets/implementations/create-react-app.js +34 -0
  46. package/build/cli/presets/implementations/docusaurus.d.ts +7 -0
  47. package/build/cli/presets/implementations/docusaurus.d.ts.map +1 -0
  48. package/build/cli/presets/implementations/docusaurus.js +13 -0
  49. package/build/cli/presets/implementations/gatsby.d.ts +7 -0
  50. package/build/cli/presets/implementations/gatsby.d.ts.map +1 -0
  51. package/build/cli/presets/implementations/gatsby.js +13 -0
  52. package/build/cli/presets/implementations/next.d.ts +7 -0
  53. package/build/cli/presets/implementations/next.d.ts.map +1 -0
  54. package/build/cli/presets/implementations/next.js +13 -0
  55. package/build/cli/presets/implementations/sveltekit.d.ts +7 -0
  56. package/build/cli/presets/implementations/sveltekit.d.ts.map +1 -0
  57. package/build/cli/presets/implementations/sveltekit.js +13 -0
  58. package/build/cli/presets/implementations/vite.d.ts +7 -0
  59. package/build/cli/presets/implementations/vite.d.ts.map +1 -0
  60. package/build/cli/presets/implementations/vite.js +13 -0
  61. package/build/cli/presets/index.d.ts +3 -0
  62. package/build/cli/presets/index.d.ts.map +1 -0
  63. package/build/cli/presets/index.js +16 -0
  64. package/build/cli/presets/preset-base.d.ts +19 -0
  65. package/build/cli/presets/preset-base.d.ts.map +1 -0
  66. package/build/cli/util/data.d.ts +7 -0
  67. package/build/cli/util/data.d.ts.map +1 -0
  68. package/build/cli/util/data.js +58 -0
  69. package/build/cli/util/fastly-api.d.ts +10 -0
  70. package/build/cli/util/fastly-api.d.ts.map +1 -0
  71. package/build/cli/util/fastly-api.js +47 -0
  72. package/build/cli/util/files.d.ts +11 -0
  73. package/build/cli/util/files.d.ts.map +1 -0
  74. package/build/cli/util/files.js +33 -0
  75. package/build/cli/util/hash.d.ts +5 -0
  76. package/build/cli/util/hash.d.ts.map +1 -0
  77. package/build/cli/util/hash.js +9 -0
  78. package/build/cli/util/id.d.ts +3 -0
  79. package/build/cli/util/id.d.ts.map +1 -0
  80. package/build/cli/util/id.js +17 -0
  81. package/build/cli/util/object-store.d.ts +16 -0
  82. package/build/cli/util/object-store.d.ts.map +1 -0
  83. package/build/cli/util/object-store.js +108 -0
  84. package/build/cli/util/publish-id.d.ts +5 -0
  85. package/build/cli/util/publish-id.d.ts.map +1 -0
  86. package/build/cli/util/publish-id.js +26 -0
  87. package/build/constants/compression.d.ts +3 -0
  88. package/build/constants/compression.d.ts.map +1 -0
  89. package/build/constants/compression.js +4 -0
  90. package/build/index.d.ts +5 -2
  91. package/build/index.d.ts.map +1 -1
  92. package/build/index.js +5 -1
  93. package/build/presets/implementations/create-react-app.js +1 -2
  94. package/build/presets/preset-base.d.ts +1 -1
  95. package/build/presets/preset-base.d.ts.map +1 -1
  96. package/build/server/assets/asset-manager.d.ts +7 -0
  97. package/build/server/assets/asset-manager.d.ts.map +1 -0
  98. package/build/server/assets/asset-manager.js +11 -0
  99. package/build/server/assets/content-assets.d.ts +33 -0
  100. package/build/server/assets/content-assets.d.ts.map +1 -0
  101. package/build/server/assets/content-assets.js +142 -0
  102. package/build/server/assets/module-assets.d.ts +23 -0
  103. package/build/server/assets/module-assets.d.ts.map +1 -0
  104. package/build/server/assets/module-assets.js +45 -0
  105. package/build/server/object-store/include-bytes-store-entry.d.ts +19 -0
  106. package/build/server/object-store/include-bytes-store-entry.d.ts.map +1 -0
  107. package/build/server/object-store/include-bytes-store-entry.js +87 -0
  108. package/build/server/object-store/inline-store-entry.d.ts +25 -0
  109. package/build/server/object-store/inline-store-entry.d.ts.map +1 -0
  110. package/build/server/object-store/inline-store-entry.js +99 -0
  111. package/build/server/publisher-server.d.ts +23 -0
  112. package/build/server/publisher-server.d.ts.map +1 -0
  113. package/build/server/publisher-server.js +257 -0
  114. package/build/server/serve-preconditions/if-modified-since.d.ts +4 -0
  115. package/build/server/serve-preconditions/if-modified-since.d.ts.map +1 -0
  116. package/build/server/serve-preconditions/if-modified-since.js +26 -0
  117. package/build/server/serve-preconditions/if-none-match.d.ts +3 -0
  118. package/build/server/serve-preconditions/if-none-match.d.ts.map +1 -0
  119. package/build/server/serve-preconditions/if-none-match.js +24 -0
  120. package/build/server/util/http.d.ts +2 -0
  121. package/build/server/util/http.d.ts.map +1 -0
  122. package/build/server/util/http.js +9 -0
  123. package/build/types/compute.d.ts +11 -0
  124. package/build/types/compute.d.ts.map +1 -0
  125. package/build/types/compute.js +1 -0
  126. package/build/types/config-normalized.d.ts +33 -0
  127. package/build/types/config-normalized.d.ts.map +1 -0
  128. package/build/types/config-normalized.js +1 -0
  129. package/build/types/config.d.ts +36 -0
  130. package/build/types/config.d.ts.map +1 -0
  131. package/build/types/config.js +1 -0
  132. package/build/types/content-assets.d.ts +38 -0
  133. package/build/types/content-assets.d.ts.map +1 -0
  134. package/build/types/content-assets.js +1 -0
  135. package/build/types/content-types.d.ts +11 -0
  136. package/build/types/content-types.d.ts.map +1 -0
  137. package/build/types/content-types.js +1 -0
  138. package/build/types/index.d.ts +7 -0
  139. package/build/types/index.d.ts.map +1 -0
  140. package/build/types/index.js +1 -0
  141. package/build/types/module-assets.d.ts +15 -0
  142. package/build/types/module-assets.d.ts.map +1 -0
  143. package/build/types/module-assets.js +1 -0
  144. package/build/types/util.d.ts +7 -0
  145. package/build/types/util.d.ts.map +1 -0
  146. package/build/types/util.js +1 -0
  147. package/build/util/content-types.d.ts +5 -0
  148. package/build/util/content-types.d.ts.map +1 -0
  149. package/build/util/content-types.js +92 -0
  150. package/build/util/data.d.ts +7 -0
  151. package/build/util/data.d.ts.map +1 -0
  152. package/build/util/data.js +58 -0
  153. package/build/util/fastly-api.d.ts +10 -0
  154. package/build/util/fastly-api.d.ts.map +1 -0
  155. package/build/util/fastly-api.js +47 -0
  156. package/build/util/files.d.ts +10 -0
  157. package/build/util/files.d.ts.map +1 -0
  158. package/build/util/files.js +32 -0
  159. package/build/util/hash.d.ts +2 -0
  160. package/build/util/hash.d.ts.map +1 -0
  161. package/build/util/hash.js +8 -0
  162. package/build/util/id.d.ts +3 -0
  163. package/build/util/id.d.ts.map +1 -0
  164. package/build/util/id.js +17 -0
  165. package/build/util/index.d.ts +3 -0
  166. package/build/util/index.d.ts.map +1 -0
  167. package/build/util/index.js +2 -0
  168. package/build/util/metadata.d.ts +3 -0
  169. package/build/util/metadata.d.ts.map +1 -0
  170. package/build/util/metadata.js +12 -0
  171. package/build/util/object-store.d.ts +12 -0
  172. package/build/util/object-store.d.ts.map +1 -0
  173. package/build/util/object-store.js +80 -0
  174. package/package.json +9 -5
  175. package/resources/index.js +9 -114
  176. package/resources/statics-metadata.d.ts +10 -0
  177. package/resources/statics.d.ts +15 -7
  178. package/resources/webpack.config.js +4 -10
  179. package/build/assets.d.ts +0 -8
  180. package/build/assets.d.ts.map +0 -1
  181. package/build/assets.js +0 -24
  182. package/build/build-static.d.ts.map +0 -1
  183. package/build/build-static.js +0 -249
  184. package/build/cli.d.ts.map +0 -1
  185. package/build/init-app.d.ts.map +0 -1
  186. package/build/static-assets.d.ts +0 -11
  187. package/build/static-assets.d.ts.map +0 -1
  188. package/build/static-assets.js +0 -33
  189. package/build/types.d.ts +0 -50
  190. package/build/types.d.ts.map +0 -1
  191. package/resources/default-content-types.cjs +0 -106
  192. package/resources/default-content-types.d.ts +0 -15
  193. /package/build/{build-static.d.ts → cli/build-static.d.ts} +0 -0
  194. /package/build/{content-types.js → cli/clean-object-store.js} +0 -0
  195. /package/build/{cli.d.ts → cli/cli.d.ts} +0 -0
  196. /package/build/{init-app.d.ts → cli/commands/init-app.d.ts} +0 -0
  197. /package/build/{types.js → cli/presets/preset-base.js} +0 -0
@@ -0,0 +1,33 @@
1
+ import { AssetManager } from "./asset-manager.js";
2
+ import type { ContentAsset, ContentAssetMetadataMap, ContentAssetMetadataMapEntry, ContentAssetMetadataMapEntryInline, ContentAssetMetadataMapEntryObjectStore } from "../../types/content-assets.js";
3
+ import type { StoreEntry } from "../../types/compute.js";
4
+ import type { ContentCompressionTypes } from "../../constants/compression.js";
5
+ export declare class ContentInlineAsset implements ContentAsset {
6
+ readonly isInline: boolean;
7
+ private readonly metadata;
8
+ private readonly sourceAndInfo;
9
+ private readonly compressedSourcesAndInfo;
10
+ constructor(metadata: ContentAssetMetadataMapEntryInline);
11
+ get assetKey(): string;
12
+ getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
13
+ getBytes(): Uint8Array;
14
+ getText(): string;
15
+ getMetadata(): ContentAssetMetadataMapEntry;
16
+ }
17
+ export declare class ContentObjectStoreAsset implements ContentAsset {
18
+ readonly isInline: boolean;
19
+ private readonly metadata;
20
+ private readonly objectStoreName;
21
+ private readonly sourceAndInfo;
22
+ private readonly compressedSourcesAndInfo;
23
+ constructor(metadata: ContentAssetMetadataMapEntryObjectStore, objectStoreName: string);
24
+ get assetKey(): string;
25
+ getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
26
+ getBytes(): Uint8Array;
27
+ getText(): string;
28
+ getMetadata(): ContentAssetMetadataMapEntry;
29
+ }
30
+ export declare class ContentAssets extends AssetManager<ContentAsset> {
31
+ constructor(objectStoreName: string | null, contentAssetMetadataMap: ContentAssetMetadataMap);
32
+ }
33
+ //# sourceMappingURL=content-assets.d.ts.map
@@ -0,0 +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,kCAAkC,EAClC,uCAAuC,EACxC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AA0C9E,qBAAa,kBAAmB,YAAW,YAAY;IACrD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAQ;IAElC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;IAE9D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAC1D,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAiD;gBAE9E,QAAQ,EAAE,kCAAkC;IAoBxD,IAAI,QAAQ,WAEX;IAEK,aAAa,CAAC,qBAAqB,GAAE,uBAAuB,EAAE,EAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IAMjG,QAAQ,IAAI,UAAU;IAItB,OAAO,IAAI,MAAM;IAOjB,WAAW,IAAI,4BAA4B;CAG5C;AAED,qBAAa,uBAAwB,YAAW,YAAY;IAC1D,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAS;IAEnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0C;IAEnE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IAEzC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAwB;IACtD,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA6C;gBAE1E,QAAQ,EAAE,uCAAuC,EAAE,eAAe,EAAE,MAAM;IAqBtF,IAAI,QAAQ,WAEX;IAEK,aAAa,CAAC,qBAAqB,GAAE,uBAAuB,EAAE,EAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IA4BjG,QAAQ,IAAI,UAAU;IAItB,OAAO,IAAI,MAAM;IAIjB,WAAW,IAAI,4BAA4B;CAI5C;AAED,qBAAa,aAAc,SAAQ,YAAY,CAAC,YAAY,CAAC;gBAE/C,eAAe,EAAE,MAAM,GAAG,IAAI,EAAE,uBAAuB,EAAE,uBAAuB;CAsB7F"}
@@ -0,0 +1,142 @@
1
+ import { includeBytes } from "fastly:experimental";
2
+ import { ObjectStore } from "fastly:object-store";
3
+ import { AssetManager } from "./asset-manager.js";
4
+ import { InlineStoreEntry } from "../object-store/inline-store-entry.js";
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
+ }
30
+ export class ContentInlineAsset {
31
+ constructor(metadata) {
32
+ this.isInline = true;
33
+ this.metadata = metadata;
34
+ this.sourceAndInfo = {
35
+ source: includeBytes(metadata.fileInfo.staticFilePath),
36
+ hash: metadata.fileInfo.hash,
37
+ size: metadata.fileInfo.size,
38
+ };
39
+ this.compressedSourcesAndInfo = Object.entries(metadata.compressedFileInfos)
40
+ .reduce((obj, [key, value]) => {
41
+ obj[key] = {
42
+ source: includeBytes(value.staticFilePath),
43
+ hash: value.hash,
44
+ size: value.size,
45
+ };
46
+ return obj;
47
+ }, {});
48
+ }
49
+ get assetKey() {
50
+ return this.metadata.assetKey;
51
+ }
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);
56
+ }
57
+ getBytes() {
58
+ return this.sourceAndInfo.source;
59
+ }
60
+ getText() {
61
+ if (!this.metadata.text) {
62
+ throw new Error("Can't getText() for non-text content");
63
+ }
64
+ return decoder.decode(this.sourceAndInfo.source);
65
+ }
66
+ getMetadata() {
67
+ return this.metadata;
68
+ }
69
+ }
70
+ export class ContentObjectStoreAsset {
71
+ constructor(metadata, objectStoreName) {
72
+ this.isInline = false;
73
+ this.metadata = metadata;
74
+ this.objectStoreName = objectStoreName;
75
+ this.sourceAndInfo = {
76
+ source: metadata.fileInfo.objectStoreKey,
77
+ hash: metadata.fileInfo.hash,
78
+ size: metadata.fileInfo.size,
79
+ };
80
+ this.compressedSourcesAndInfo = Object.entries(metadata.compressedFileInfos)
81
+ .reduce((obj, [key, value]) => {
82
+ obj[key] = {
83
+ source: value.objectStoreKey,
84
+ hash: value.hash,
85
+ size: value.size,
86
+ };
87
+ return obj;
88
+ }, {});
89
+ }
90
+ get assetKey() {
91
+ return this.metadata.assetKey;
92
+ }
93
+ async getStoreEntry(acceptEncodingsGroups = []) {
94
+ const { sourceAndInfo, contentEncoding } = findMatchingSourceAndInfo(acceptEncodingsGroups, this.sourceAndInfo, encoding => this.compressedSourcesAndInfo[encoding]);
95
+ const objectStore = new ObjectStore(this.objectStoreName);
96
+ let retries = 3;
97
+ while (retries > 0) {
98
+ const storeEntry = await objectStore.get(sourceAndInfo.source);
99
+ if (storeEntry != null) {
100
+ const { hash, size } = sourceAndInfo;
101
+ return Object.assign(storeEntry, { contentEncoding, hash, size });
102
+ }
103
+ // Note the null does NOT mean 404. The fact that we are here means
104
+ // metadata exists for this path, and we're just trying to get the data from
105
+ // the object store.
106
+ // So if we're here then the data is either not available yet (in which case
107
+ // we can wait just a bit and try again), or the data was deleted.
108
+ retries--;
109
+ // We're going to wait 250ms/500ms/750ms and try again.
110
+ const delay = (3 - retries) * 250;
111
+ await new Promise(resolve => setTimeout(resolve, delay));
112
+ }
113
+ throw new Error("Asset could not be retrieved from the Object Store.");
114
+ }
115
+ getBytes() {
116
+ throw new Error("Can't getBytes() for Object Store asset");
117
+ }
118
+ getText() {
119
+ throw new Error("Can't getText() for Object Store asset");
120
+ }
121
+ getMetadata() {
122
+ return this.metadata;
123
+ }
124
+ }
125
+ export class ContentAssets extends AssetManager {
126
+ constructor(objectStoreName, contentAssetMetadataMap) {
127
+ super();
128
+ for (const [assetKey, metadata] of Object.entries(contentAssetMetadataMap)) {
129
+ let asset;
130
+ if (metadata.isInline) {
131
+ asset = new ContentInlineAsset(metadata);
132
+ }
133
+ else {
134
+ if (objectStoreName == null) {
135
+ throw new Error("Unexpected! Object Store should be specified!!");
136
+ }
137
+ asset = new ContentObjectStoreAsset(metadata, objectStoreName);
138
+ }
139
+ this.setAsset(assetKey, asset);
140
+ }
141
+ }
142
+ }
@@ -0,0 +1,23 @@
1
+ import { AssetManager } from "./asset-manager.js";
2
+ import type { ModuleAsset, ModuleAssetMap } from "../../types/module-assets.js";
3
+ export declare class ModuleAssetDynamic implements ModuleAsset {
4
+ readonly assetKey: string;
5
+ readonly isStaticImport: boolean;
6
+ private readonly loadModule;
7
+ constructor(assetKey: string, loadModule: () => Promise<any>);
8
+ private _modulePromise;
9
+ getModule(): Promise<any>;
10
+ getStaticModule(): any;
11
+ }
12
+ export declare class ModuleAssetStatic implements ModuleAsset {
13
+ readonly assetKey: string;
14
+ readonly isStaticImport: boolean;
15
+ private readonly module;
16
+ constructor(assetKey: string, module: any);
17
+ getModule(): Promise<any>;
18
+ getStaticModule(): any;
19
+ }
20
+ export declare class ModuleAssets extends AssetManager<ModuleAsset> {
21
+ constructor(moduleAssetMap: ModuleAssetMap);
22
+ }
23
+ //# sourceMappingURL=module-assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-assets.d.ts","sourceRoot":"","sources":["../../../src/server/assets/module-assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEhF,qBAAa,kBAAmB,YAAW,WAAW;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAS;IAEzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAqB;gBAEpC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC;IAK5D,OAAO,CAAC,cAAc,CAA2B;IACjD,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC;IAOzB,eAAe,IAAI,GAAG;CAIvB;AAED,qBAAa,iBAAkB,YAAW,WAAW;IACnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAQ;IAExC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAM;gBACjB,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG;IAKzC,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC;IAIzB,eAAe,IAAI,GAAG;CAIvB;AAED,qBAAa,YAAa,SAAQ,YAAY,CAAC,WAAW,CAAC;gBAE7C,cAAc,EAAE,cAAc;CAmB3C"}
@@ -0,0 +1,45 @@
1
+ import { AssetManager } from "./asset-manager.js";
2
+ export class ModuleAssetDynamic {
3
+ constructor(assetKey, loadModule) {
4
+ this.isStaticImport = false;
5
+ this.assetKey = assetKey;
6
+ this.loadModule = loadModule;
7
+ }
8
+ getModule() {
9
+ if (this._modulePromise === undefined) {
10
+ this._modulePromise = this.loadModule();
11
+ }
12
+ return this._modulePromise;
13
+ }
14
+ getStaticModule() {
15
+ return null;
16
+ }
17
+ }
18
+ export class ModuleAssetStatic {
19
+ constructor(assetKey, module) {
20
+ this.isStaticImport = true;
21
+ this.assetKey = assetKey;
22
+ this.module = module;
23
+ }
24
+ getModule() {
25
+ return Promise.resolve(this.module);
26
+ }
27
+ getStaticModule() {
28
+ return this.module;
29
+ }
30
+ }
31
+ export class ModuleAssets extends AssetManager {
32
+ constructor(moduleAssetMap) {
33
+ super();
34
+ for (const [assetKey, moduleEntry] of Object.entries(moduleAssetMap)) {
35
+ let asset;
36
+ if (moduleEntry.isStaticImport) {
37
+ asset = new ModuleAssetStatic(assetKey, moduleEntry.module);
38
+ }
39
+ else {
40
+ asset = new ModuleAssetDynamic(assetKey, moduleEntry.loadModule);
41
+ }
42
+ this.setAsset(assetKey, asset);
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,19 @@
1
+ import { StoreEntry } from "../../types/compute.js";
2
+ export declare class IncludeBytesStoreEntry implements StoreEntry {
3
+ _consumed: boolean;
4
+ _body: ReadableStreamForBytes;
5
+ constructor(array: Uint8Array);
6
+ get body(): ReadableStream<Uint8Array>;
7
+ get bodyUsed(): boolean;
8
+ arrayBuffer(): Promise<ArrayBuffer>;
9
+ static decoder: TextDecoder;
10
+ text(): Promise<string>;
11
+ json(): Promise<any>;
12
+ }
13
+ declare class ReadableStreamForBytes extends ReadableStream<Uint8Array> {
14
+ _disturbed: boolean;
15
+ constructor(array: Uint8Array);
16
+ getReader(): ReadableStreamDefaultReader<Uint8Array>;
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=include-bytes-store-entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"include-bytes-store-entry.d.ts","sourceRoot":"","sources":["../../../src/server/object-store/include-bytes-store-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKpD,qBAAa,sBAAuB,YAAW,UAAU;IACvD,SAAS,EAAE,OAAO,CAAC;IAEnB,KAAK,EAAE,sBAAsB,CAAC;gBAElB,KAAK,EAAE,UAAU;IAK7B,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;CAI3B;AAED,cAAM,sBAAuB,SAAQ,cAAc,CAAC,UAAU,CAAC;IAG7D,UAAU,UAAS;gBAEP,KAAK,EAAE,UAAU;IASpB,SAAS,IAAI,2BAA2B,CAAC,UAAU,CAAC;CA6B9D"}
@@ -0,0 +1,87 @@
1
+ // A class designed to give a Body-style interface to Uint8Array.
2
+ // The intended use case is arrays brought in from includeBytes().
3
+ export class IncludeBytesStoreEntry {
4
+ constructor(array) {
5
+ this._body = new ReadableStreamForBytes(array);
6
+ this._consumed = false;
7
+ }
8
+ get body() {
9
+ return this._body;
10
+ }
11
+ get bodyUsed() {
12
+ return this._consumed;
13
+ }
14
+ async arrayBuffer() {
15
+ if (this._consumed) {
16
+ throw new Error('Body has already been consumed');
17
+ }
18
+ if (this._body.locked) {
19
+ throw new Error('The ReadableStream body is already locked and can\'t be consumed');
20
+ }
21
+ if (this._body._disturbed) {
22
+ throw new Error('Body object should not be disturbed or locked');
23
+ }
24
+ this._consumed = true;
25
+ let result = new Uint8Array(0);
26
+ const reader = this._body.getReader();
27
+ try {
28
+ while (true) {
29
+ const { done, value } = await reader.read();
30
+ if (done) {
31
+ break;
32
+ }
33
+ const newResult = new Uint8Array(result.length + value.length);
34
+ newResult.set(result);
35
+ newResult.set(value, result.length);
36
+ result = newResult;
37
+ }
38
+ return result;
39
+ }
40
+ finally {
41
+ reader.releaseLock();
42
+ }
43
+ }
44
+ async text() {
45
+ const data = await this.arrayBuffer();
46
+ return IncludeBytesStoreEntry.decoder.decode(data);
47
+ }
48
+ async json() {
49
+ const text = await this.text();
50
+ return JSON.parse(text);
51
+ }
52
+ }
53
+ IncludeBytesStoreEntry.decoder = new TextDecoder();
54
+ class ReadableStreamForBytes extends ReadableStream {
55
+ constructor(array) {
56
+ super({
57
+ async start(controller) {
58
+ controller.enqueue(array);
59
+ controller.close();
60
+ },
61
+ });
62
+ // Closest we can get to the "disturbed" flag
63
+ this._disturbed = false;
64
+ }
65
+ getReader() {
66
+ const reader = super.getReader();
67
+ const stream = this;
68
+ // Monkey-patch read
69
+ const _read = reader.read;
70
+ reader.read = async () => {
71
+ const result = await _read.call(reader);
72
+ if (result.done) {
73
+ // NOTE: C@E Request body does not seem to get marked as "disturbed" until
74
+ // end of stream is reached either...
75
+ stream._disturbed = true;
76
+ }
77
+ return result;
78
+ };
79
+ // Monkey-patch cancel
80
+ const _cancel = reader.cancel;
81
+ reader.cancel = async (reason) => {
82
+ await _cancel.call(reader, reason);
83
+ stream._disturbed = true;
84
+ };
85
+ return reader;
86
+ }
87
+ }
@@ -0,0 +1,25 @@
1
+ import { StoreEntry } from "../../types/compute.js";
2
+ export declare class InlineStoreEntry implements StoreEntry {
3
+ _consumed: boolean;
4
+ _body: ReadableStreamForBytes;
5
+ _contentEncoding: string | null;
6
+ _hash: string;
7
+ _size: number;
8
+ constructor(array: Uint8Array, contentEncoding: string | null, hash: string, size: number);
9
+ get body(): ReadableStream<Uint8Array>;
10
+ get bodyUsed(): boolean;
11
+ arrayBuffer(): Promise<ArrayBuffer>;
12
+ static decoder: TextDecoder;
13
+ text(): Promise<string>;
14
+ json(): Promise<any>;
15
+ get contentEncoding(): string | null;
16
+ get hash(): string;
17
+ get size(): number;
18
+ }
19
+ declare class ReadableStreamForBytes extends ReadableStream<Uint8Array> {
20
+ _disturbed: boolean;
21
+ constructor(array: Uint8Array);
22
+ getReader(): ReadableStreamDefaultReader<Uint8Array>;
23
+ }
24
+ export {};
25
+ //# sourceMappingURL=inline-store-entry.d.ts.map
@@ -0,0 +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;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"}
@@ -0,0 +1,99 @@
1
+ // A class designed to give a Body-style interface to Uint8Array.
2
+ // The intended use case is arrays brought in from includeBytes().
3
+ export class InlineStoreEntry {
4
+ constructor(array, contentEncoding, hash, size) {
5
+ this._body = new ReadableStreamForBytes(array);
6
+ this._consumed = false;
7
+ this._contentEncoding = contentEncoding;
8
+ this._hash = hash;
9
+ this._size = size;
10
+ }
11
+ get body() {
12
+ return this._body;
13
+ }
14
+ get bodyUsed() {
15
+ return this._consumed;
16
+ }
17
+ async arrayBuffer() {
18
+ if (this._consumed) {
19
+ throw new Error('Body has already been consumed');
20
+ }
21
+ if (this._body.locked) {
22
+ throw new Error('The ReadableStream body is already locked and can\'t be consumed');
23
+ }
24
+ if (this._body._disturbed) {
25
+ throw new Error('Body object should not be disturbed or locked');
26
+ }
27
+ this._consumed = true;
28
+ let result = new Uint8Array(0);
29
+ const reader = this._body.getReader();
30
+ try {
31
+ while (true) {
32
+ const { done, value } = await reader.read();
33
+ if (done) {
34
+ break;
35
+ }
36
+ const newResult = new Uint8Array(result.length + value.length);
37
+ newResult.set(result);
38
+ newResult.set(value, result.length);
39
+ result = newResult;
40
+ }
41
+ return result;
42
+ }
43
+ finally {
44
+ reader.releaseLock();
45
+ }
46
+ }
47
+ async text() {
48
+ const data = await this.arrayBuffer();
49
+ return InlineStoreEntry.decoder.decode(data);
50
+ }
51
+ async json() {
52
+ const text = await this.text();
53
+ return JSON.parse(text);
54
+ }
55
+ get contentEncoding() {
56
+ return this._contentEncoding;
57
+ }
58
+ get hash() {
59
+ return this._hash;
60
+ }
61
+ get size() {
62
+ return this._size;
63
+ }
64
+ }
65
+ InlineStoreEntry.decoder = new TextDecoder();
66
+ class ReadableStreamForBytes extends ReadableStream {
67
+ constructor(array) {
68
+ super({
69
+ async start(controller) {
70
+ controller.enqueue(array);
71
+ controller.close();
72
+ },
73
+ });
74
+ // Closest we can get to the "disturbed" flag
75
+ this._disturbed = false;
76
+ }
77
+ getReader() {
78
+ const reader = super.getReader();
79
+ const stream = this;
80
+ // Monkey-patch read
81
+ const _read = reader.read;
82
+ reader.read = async () => {
83
+ const result = await _read.call(reader);
84
+ if (result.done) {
85
+ // NOTE: C@E Request body does not seem to get marked as "disturbed" until
86
+ // end of stream is reached either...
87
+ stream._disturbed = true;
88
+ }
89
+ return result;
90
+ };
91
+ // Monkey-patch cancel
92
+ const _cancel = reader.cancel;
93
+ reader.cancel = async (reason) => {
94
+ await _cancel.call(reader, reason);
95
+ stream._disturbed = true;
96
+ };
97
+ return reader;
98
+ }
99
+ }
@@ -0,0 +1,23 @@
1
+ import { ContentAssets } from "./assets/content-assets.js";
2
+ import type { PublisherServerConfigNormalized } from "../types/config-normalized.js";
3
+ import type { ContentAsset } from "../types/content-assets.js";
4
+ import type { ContentCompressionTypes } from "../constants/compression.js";
5
+ type AssetInit = {
6
+ status?: number;
7
+ headers?: Record<string, string>;
8
+ cache?: 'extended' | 'never' | null;
9
+ };
10
+ export declare class PublisherServer {
11
+ private readonly serverConfig;
12
+ private readonly staticItems;
13
+ private readonly contentAssets;
14
+ constructor(serverConfig: PublisherServerConfigNormalized, contentAssets: ContentAssets);
15
+ getMatchingAsset(path: string): ContentAsset | null;
16
+ findAcceptEncodings(request: Request): ContentCompressionTypes[][];
17
+ testExtendedCache(pathname: string): boolean;
18
+ handlePreconditions(request: Request, asset: ContentAsset, responseHeaders: Record<string, string>): Response | null;
19
+ serveAsset(request: Request, asset: ContentAsset, init?: AssetInit): Promise<Response>;
20
+ serveRequest(request: Request): Promise<Response | null>;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=publisher-server.d.ts.map
@@ -0,0 +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;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"}