@lwrjs/view-registry 0.9.0-alpha.0 → 0.9.0-alpha.10
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/build/cjs/index.cjs +8 -3
- package/build/cjs/linkers/legacy_view_bootstrap.cjs +3 -0
- package/build/cjs/linkers/view_bootstrap.cjs +5 -2
- package/build/cjs/view-handler.cjs +6 -3
- package/build/es/index.js +8 -2
- package/build/es/linkers/legacy_view_bootstrap.js +4 -0
- package/build/es/linkers/view_bootstrap.js +8 -2
- package/build/es/view-handler.d.ts +2 -2
- package/build/es/view-handler.js +4 -1
- package/package.json +6 -6
package/build/cjs/index.cjs
CHANGED
|
@@ -278,8 +278,11 @@ var LwrViewRegistry = class {
|
|
|
278
278
|
importer: importer || renderedView.compiledView.filePath
|
|
279
279
|
};
|
|
280
280
|
const stringBuilder = (0, import_shared_utils.createStringBuilder)(renderedViewContent);
|
|
281
|
+
let pageTtl;
|
|
281
282
|
for (const viewTransformer of this.viewTransformers) {
|
|
282
|
-
await viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata);
|
|
283
|
+
const linkResults = await viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata);
|
|
284
|
+
const ttl = linkResults && linkResults.cache?.ttl;
|
|
285
|
+
pageTtl = (0, import_shared_utils.shortestTtl)(ttl || void 0, pageTtl);
|
|
283
286
|
}
|
|
284
287
|
const linkedAssetContent = stringBuilder.toString();
|
|
285
288
|
if (linkedAssetContent.includes(lwrResourcesId)) {
|
|
@@ -298,7 +301,8 @@ var LwrViewRegistry = class {
|
|
|
298
301
|
viewRecord: {
|
|
299
302
|
assetReferences: (0, import_utils.reduceSourceAssetReferences)(linkedMetadata.assetReferences),
|
|
300
303
|
...viewRecord
|
|
301
|
-
}
|
|
304
|
+
},
|
|
305
|
+
cache: {ttl: pageTtl}
|
|
302
306
|
};
|
|
303
307
|
}
|
|
304
308
|
return {
|
|
@@ -306,7 +310,8 @@ var LwrViewRegistry = class {
|
|
|
306
310
|
immutable,
|
|
307
311
|
viewRecord: {
|
|
308
312
|
assetReferences: (0, import_utils.reduceSourceAssetReferences)(linkedMetadata.assetReferences)
|
|
309
|
-
}
|
|
313
|
+
},
|
|
314
|
+
cache: {ttl: pageTtl}
|
|
310
315
|
};
|
|
311
316
|
}
|
|
312
317
|
};
|
|
@@ -65,6 +65,9 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
65
65
|
if (!def) {
|
|
66
66
|
throw Error("Failed to find definition of resource: " + shimBundle);
|
|
67
67
|
}
|
|
68
|
+
if (def.stream) {
|
|
69
|
+
def.stream.destroy();
|
|
70
|
+
}
|
|
68
71
|
requiredResources.push(def);
|
|
69
72
|
const errorShimDef = await resourceRegistry.getResource({specifier: "lwr-error-shim.js", version}, runtimeEnvironment, runtimeParams);
|
|
70
73
|
if (!errorShimDef) {
|
|
@@ -65,6 +65,9 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
65
65
|
if (!def) {
|
|
66
66
|
throw Error("Failed to find definition of resource: " + shimBundle);
|
|
67
67
|
}
|
|
68
|
+
if (def.stream) {
|
|
69
|
+
def.stream.destroy();
|
|
70
|
+
}
|
|
68
71
|
requiredResources.push(def);
|
|
69
72
|
const errorShimDef = await resourceRegistry.getResource({specifier: "lwr-error-shim.js", version}, runtimeEnvironment, runtimeParams);
|
|
70
73
|
if (!errorShimDef) {
|
|
@@ -108,7 +111,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
108
111
|
let importMetadata = await (0, import_shared_utils.toImportMetadata)(bootstrapModuleGraph, {imports: {}, index: {}}, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
109
112
|
const customElementsRecords = [];
|
|
110
113
|
const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements, isSSR);
|
|
111
|
-
|
|
114
|
+
for (const {tagName: element} of flattenedElements) {
|
|
112
115
|
const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.kebabCaseToModuleSpecifer)(element), {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
|
|
113
116
|
customElementsRecords.push({elementName: element, flatGraph: graph});
|
|
114
117
|
const specifier = graph.graphs[0].specifier;
|
|
@@ -128,7 +131,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
importMetadata = await (0, import_shared_utils.toImportMetadata)(graph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
131
|
-
}
|
|
134
|
+
}
|
|
132
135
|
configResources.unshift(await (0, import_utils2.getViewBootstrapConfigurationResource)({
|
|
133
136
|
id: view.id,
|
|
134
137
|
url: viewParams?.page?.url,
|
|
@@ -55,7 +55,8 @@ var LwrViewHandler = class {
|
|
|
55
55
|
body: viewDefinition2.renderedView,
|
|
56
56
|
metadata: {
|
|
57
57
|
viewDefinition: viewDefinition2
|
|
58
|
-
}
|
|
58
|
+
},
|
|
59
|
+
cache: {ttl: (0, import_shared_utils.shortestTtl)(response.cache?.ttl, viewDefinition2.cache?.ttl)}
|
|
59
60
|
};
|
|
60
61
|
}
|
|
61
62
|
const viewDefinition = await this.getDefaultRouteViewDefinition(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
@@ -63,7 +64,8 @@ var LwrViewHandler = class {
|
|
|
63
64
|
body: viewDefinition.renderedView,
|
|
64
65
|
metadata: {
|
|
65
66
|
viewDefinition
|
|
66
|
-
}
|
|
67
|
+
},
|
|
68
|
+
cache: viewDefinition.cache
|
|
67
69
|
};
|
|
68
70
|
}
|
|
69
71
|
async getViewJson(viewRequest, route, runtimeEnvironment, runtimeParams = {}) {
|
|
@@ -169,7 +171,8 @@ var LwrViewHandler = class {
|
|
|
169
171
|
body: viewDefinition.renderedView,
|
|
170
172
|
metadata: {
|
|
171
173
|
viewDefinition
|
|
172
|
-
}
|
|
174
|
+
},
|
|
175
|
+
cache: viewDefinition.cache
|
|
173
176
|
};
|
|
174
177
|
}
|
|
175
178
|
};
|
package/build/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extractMetadataFromHtml, getCacheKeyFromJson, getSpecifier, normalizeResourcePath, createStringBuilder, InflightTasks, } from '@lwrjs/shared-utils';
|
|
1
|
+
import { extractMetadataFromHtml, getCacheKeyFromJson, getSpecifier, normalizeResourcePath, createStringBuilder, shortestTtl, InflightTasks, } from '@lwrjs/shared-utils';
|
|
2
2
|
import { normalizeRenderOptions, normalizeRenderedResult, reduceSourceAssetReferences } from './utils.js';
|
|
3
3
|
import { linkLwrResources } from './linkers/link-lwr-resources.js';
|
|
4
4
|
export { LwrViewHandler } from './view-handler.js';
|
|
@@ -295,9 +295,13 @@ export class LwrViewRegistry {
|
|
|
295
295
|
importer: importer || renderedView.compiledView.filePath,
|
|
296
296
|
};
|
|
297
297
|
const stringBuilder = createStringBuilder(renderedViewContent);
|
|
298
|
+
let pageTtl;
|
|
298
299
|
for (const viewTransformer of this.viewTransformers) {
|
|
299
300
|
// eslint-disable-next-line no-await-in-loop
|
|
300
|
-
await viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata);
|
|
301
|
+
const linkResults = await viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata);
|
|
302
|
+
// Keep track of the shortest TTL from each view transformer (e.g. lwcSsrViewTranformer)
|
|
303
|
+
const ttl = linkResults && linkResults.cache?.ttl;
|
|
304
|
+
pageTtl = shortestTtl(ttl || undefined, pageTtl);
|
|
301
305
|
}
|
|
302
306
|
const linkedAssetContent = stringBuilder.toString();
|
|
303
307
|
// Link LWR related resources
|
|
@@ -321,6 +325,7 @@ export class LwrViewRegistry {
|
|
|
321
325
|
assetReferences: reduceSourceAssetReferences(linkedMetadata.assetReferences),
|
|
322
326
|
...viewRecord,
|
|
323
327
|
},
|
|
328
|
+
cache: { ttl: pageTtl },
|
|
324
329
|
};
|
|
325
330
|
}
|
|
326
331
|
return {
|
|
@@ -329,6 +334,7 @@ export class LwrViewRegistry {
|
|
|
329
334
|
viewRecord: {
|
|
330
335
|
assetReferences: reduceSourceAssetReferences(linkedMetadata.assetReferences),
|
|
331
336
|
},
|
|
337
|
+
cache: { ttl: pageTtl },
|
|
332
338
|
};
|
|
333
339
|
}
|
|
334
340
|
}
|
|
@@ -53,6 +53,10 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
53
53
|
if (!def) {
|
|
54
54
|
throw Error('Failed to find definition of resource: ' + shimBundle);
|
|
55
55
|
}
|
|
56
|
+
// HACK: preemptively closing the stream because it is never read
|
|
57
|
+
if (def.stream) {
|
|
58
|
+
def.stream.destroy();
|
|
59
|
+
}
|
|
56
60
|
requiredResources.push(def);
|
|
57
61
|
// Always inline the error shim script after the shim
|
|
58
62
|
const errorShimDef = (await resourceRegistry.getResource({ specifier: 'lwr-error-shim.js', version }, runtimeEnvironment, runtimeParams));
|
|
@@ -53,6 +53,10 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
53
53
|
if (!def) {
|
|
54
54
|
throw Error('Failed to find definition of resource: ' + shimBundle);
|
|
55
55
|
}
|
|
56
|
+
// HACK: preemptively closing the stream because it is never read
|
|
57
|
+
if (def.stream) {
|
|
58
|
+
def.stream.destroy();
|
|
59
|
+
}
|
|
56
60
|
requiredResources.push(def);
|
|
57
61
|
// Always inline the error shim script after the shim
|
|
58
62
|
const errorShimDef = (await resourceRegistry.getResource({ specifier: 'lwr-error-shim.js', version }, runtimeEnvironment, runtimeParams));
|
|
@@ -114,7 +118,8 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
114
118
|
// ------- View related custom element moduleResources
|
|
115
119
|
const customElementsRecords = [];
|
|
116
120
|
const flattenedElements = flattenCustomElements(customElements, isSSR);
|
|
117
|
-
|
|
121
|
+
for (const { tagName: element } of flattenedElements) {
|
|
122
|
+
// eslint-disable-next-line no-await-in-loop
|
|
118
123
|
const graph = await getModuleGraphs(kebabCaseToModuleSpecifer(element), { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
|
|
119
124
|
// add to the viewRecord
|
|
120
125
|
customElementsRecords.push({ elementName: element, flatGraph: graph });
|
|
@@ -138,8 +143,9 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
138
143
|
imports[dynamicDep] = uri;
|
|
139
144
|
}
|
|
140
145
|
}
|
|
146
|
+
// eslint-disable-next-line no-await-in-loop
|
|
141
147
|
importMetadata = await toImportMetadata(graph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
142
|
-
}
|
|
148
|
+
}
|
|
143
149
|
// ADD configuration of the bootstrapModule
|
|
144
150
|
configResources.unshift(await getViewBootstrapConfigurationResource({
|
|
145
151
|
id: view.id,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ViewRegistry, RuntimeEnvironment, NormalizedLwrGlobalConfig, ViewRequest, RuntimeParams, ViewResponse, LwrErrorRoute, LwrRoute, ModuleRegistry, RouteHandlerFunction } from '@lwrjs/types';
|
|
1
|
+
import { ViewRegistry, RuntimeEnvironment, NormalizedLwrGlobalConfig, ViewRequest, RuntimeParams, ViewResponse, LwrErrorRoute, LwrRoute, ModuleRegistry, RouteHandlerFunction, ViewHandler } from '@lwrjs/types';
|
|
2
2
|
export interface ViewHandlerContext {
|
|
3
3
|
viewRegistry: ViewRegistry;
|
|
4
4
|
moduleRegistry: ModuleRegistry;
|
|
5
5
|
}
|
|
6
|
-
export declare class LwrViewHandler {
|
|
6
|
+
export declare class LwrViewHandler implements ViewHandler {
|
|
7
7
|
viewRegistry: ViewRegistry;
|
|
8
8
|
moduleRegistry: ModuleRegistry;
|
|
9
9
|
globalConfig: NormalizedLwrGlobalConfig;
|
package/build/es/view-handler.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeResourcePath } from '@lwrjs/shared-utils';
|
|
1
|
+
import { normalizeResourcePath, shortestTtl } from '@lwrjs/shared-utils';
|
|
2
2
|
import { generateHtmlTag, generatePageContext, getRouteHandler, isViewResponse, toJsonFormat, } from './utils.js';
|
|
3
3
|
import { resolve } from 'path';
|
|
4
4
|
export class LwrViewHandler {
|
|
@@ -38,6 +38,7 @@ export class LwrViewHandler {
|
|
|
38
38
|
metadata: {
|
|
39
39
|
viewDefinition,
|
|
40
40
|
},
|
|
41
|
+
cache: { ttl: shortestTtl(response.cache?.ttl, viewDefinition.cache?.ttl) },
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
// default static view
|
|
@@ -47,6 +48,7 @@ export class LwrViewHandler {
|
|
|
47
48
|
metadata: {
|
|
48
49
|
viewDefinition,
|
|
49
50
|
},
|
|
51
|
+
cache: viewDefinition.cache,
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
// Get the View's JSON Manifest Response
|
|
@@ -202,6 +204,7 @@ export class LwrViewHandler {
|
|
|
202
204
|
metadata: {
|
|
203
205
|
viewDefinition,
|
|
204
206
|
},
|
|
207
|
+
cache: viewDefinition.cache,
|
|
205
208
|
};
|
|
206
209
|
}
|
|
207
210
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.9.0-alpha.
|
|
7
|
+
"version": "0.9.0-alpha.10",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/app-service": "0.9.0-alpha.
|
|
34
|
-
"@lwrjs/diagnostics": "0.9.0-alpha.
|
|
35
|
-
"@lwrjs/shared-utils": "0.9.0-alpha.
|
|
33
|
+
"@lwrjs/app-service": "0.9.0-alpha.10",
|
|
34
|
+
"@lwrjs/diagnostics": "0.9.0-alpha.10",
|
|
35
|
+
"@lwrjs/shared-utils": "0.9.0-alpha.10"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@lwrjs/types": "0.9.0-alpha.
|
|
38
|
+
"@lwrjs/types": "0.9.0-alpha.10"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=14.15.4 <19"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "ecbf031157dd87d2b1a3d528b7fae8f9142eba7e"
|
|
44
44
|
}
|