@lwrjs/view-registry 0.13.0-alpha.27 → 0.13.0-alpha.28
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 +16 -22
- package/build/cjs/utils.cjs +0 -1
- package/build/es/index.d.ts +1 -1
- package/build/es/index.js +19 -27
- package/build/es/utils.js +0 -1
- package/package.json +7 -7
package/build/cjs/index.cjs
CHANGED
|
@@ -136,17 +136,15 @@ var LwrViewRegistry = class {
|
|
|
136
136
|
}
|
|
137
137
|
throw new Error(`No View provider was able to resolve a view for template: ${viewId.contentTemplate}`);
|
|
138
138
|
}
|
|
139
|
-
async getView(viewId
|
|
139
|
+
async getView(viewId) {
|
|
140
140
|
const {contentTemplate, rootComponent} = viewId;
|
|
141
141
|
const compiledViewCacheKey = (0, import_shared_utils.getCacheKeyFromJson)({contentTemplate, rootComponent});
|
|
142
142
|
import_diagnostics.logger.debug(`[view-registry][getView] compiledViewCacheKey=${compiledViewCacheKey}`);
|
|
143
|
-
if (
|
|
143
|
+
if (this.compiledViews.has(compiledViewCacheKey)) {
|
|
144
144
|
return this.compiledViews.get(compiledViewCacheKey);
|
|
145
145
|
}
|
|
146
146
|
const compiledView = await this.delegateGetView(viewId);
|
|
147
|
-
|
|
148
|
-
this.compiledViews.set(compiledViewCacheKey, compiledView);
|
|
149
|
-
}
|
|
147
|
+
this.compiledViews.set(compiledViewCacheKey, compiledView);
|
|
150
148
|
return compiledView;
|
|
151
149
|
}
|
|
152
150
|
hasViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions) {
|
|
@@ -177,7 +175,7 @@ var LwrViewRegistry = class {
|
|
|
177
175
|
}
|
|
178
176
|
async getViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions) {
|
|
179
177
|
try {
|
|
180
|
-
const {
|
|
178
|
+
const {freezeAssets, viewParamCacheKey} = (0, import_utils.normalizeRenderOptions)(this.runtimeEnvironment, renderOptions);
|
|
181
179
|
const viewDefCacheKey = (0, import_shared_utils.getCacheKeyFromJson)({
|
|
182
180
|
...view,
|
|
183
181
|
freezeAssets,
|
|
@@ -189,8 +187,7 @@ var LwrViewRegistry = class {
|
|
|
189
187
|
import_diagnostics.logger.debug(`[view-registry][getViewDefinition] viewDefCacheKey=${viewDefCacheKey}`);
|
|
190
188
|
const viewParamKey = viewParamCacheKey ? (0, import_shared_utils.getCacheKeyFromJson)(viewParamCacheKey) : (0, import_shared_utils.getCacheKeyFromJson)(viewParams);
|
|
191
189
|
import_diagnostics.logger.debug(`[view-registry][getViewDefinition] viewParamKey=${viewParamKey}`);
|
|
192
|
-
|
|
193
|
-
if (cacheDisabled === false && this.viewDefinitions.has(viewDefCacheKey)) {
|
|
190
|
+
if (this.viewDefinitions.has(viewDefCacheKey)) {
|
|
194
191
|
const viewDefinition2 = this.viewDefinitions.get(viewDefCacheKey);
|
|
195
192
|
if (viewDefinition2 && viewDefinition2.paramKey === viewParamKey && viewDefinition2.viewDefinition.immutable) {
|
|
196
193
|
return viewDefinition2.viewDefinition;
|
|
@@ -207,19 +204,16 @@ var LwrViewRegistry = class {
|
|
|
207
204
|
}
|
|
208
205
|
}, () => this.renderView(view, updatableViewParams, runtimeEnvironment, runtimeParams, renderOptions)));
|
|
209
206
|
viewDefinition.nonce = (0, import_utils.getViewNonce)(updatableViewParams);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}, {ttl: ttl ? ttl * 1e3 : void 0});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
207
|
+
const route = this.globalConfig.routes.find((r) => r.id === view.id);
|
|
208
|
+
const maxViewCacheTtl = (0, import_shared_utils.getFeatureFlags)().MAX_VIEW_CACHE_TTL;
|
|
209
|
+
const maxTtl = maxViewCacheTtl && parseInt(maxViewCacheTtl, 10);
|
|
210
|
+
const leastTtl = (0, import_shared_utils.shortestTtl)(viewDefinition.cache?.ttl, route?.cache?.ttl, maxTtl);
|
|
211
|
+
const ttl = leastTtl !== void 0 ? leastTtl === 0 ? 10 : leastTtl * 1e3 : void 0;
|
|
212
|
+
this.viewDefinitions.set(viewDefCacheKey, {
|
|
213
|
+
view,
|
|
214
|
+
viewDefinition,
|
|
215
|
+
paramKey: viewParamKey
|
|
216
|
+
}, {ttl});
|
|
223
217
|
return viewDefinition;
|
|
224
218
|
} catch (err) {
|
|
225
219
|
if (err instanceof import_diagnostics.DiagnosticsError) {
|
|
@@ -295,7 +289,7 @@ var LwrViewRegistry = class {
|
|
|
295
289
|
async render(viewId, viewParams, runtimeParams, runtimeEnvironment, renderOptions) {
|
|
296
290
|
const globalContext = this.globalData;
|
|
297
291
|
const {id, rootComponent, contentTemplate} = viewId;
|
|
298
|
-
const compiledView = await this.getView({id, contentTemplate, rootComponent}
|
|
292
|
+
const compiledView = await this.getView({id, contentTemplate, rootComponent});
|
|
299
293
|
const result = await compiledView.render({
|
|
300
294
|
...runtimeParams,
|
|
301
295
|
...globalContext,
|
package/build/cjs/utils.cjs
CHANGED
|
@@ -137,7 +137,6 @@ function normalizeRenderOptions(runtimeEnvironment, overrideRenderOptions, baseR
|
|
|
137
137
|
return {
|
|
138
138
|
skipMetadataCollection: false,
|
|
139
139
|
freezeAssets: runtimeEnvironment.immutableAssets,
|
|
140
|
-
skipCaching: false,
|
|
141
140
|
viewParamCacheKey: null,
|
|
142
141
|
...baseRenderOptions,
|
|
143
142
|
...overrideRenderOptions
|
package/build/es/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare class LwrViewRegistry implements ViewRegistry {
|
|
|
42
42
|
addViewTransformers(transformers: ViewTransformPlugin[]): void;
|
|
43
43
|
initializeViewProviders(): Promise<void[]>;
|
|
44
44
|
delegateGetView(viewId: ViewIdentity): Promise<CompiledView>;
|
|
45
|
-
getView(viewId: ViewIdentity
|
|
45
|
+
getView(viewId: ViewIdentity): Promise<CompiledView>;
|
|
46
46
|
hasViewDefinition(view: View, viewParams: ViewParams, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, renderOptions?: RenderOptions): boolean;
|
|
47
47
|
getViewDefinition(view: View, viewParams: ViewParams, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, renderOptions?: RenderOptions): Promise<LinkedViewDefinition>;
|
|
48
48
|
private renderView;
|
package/build/es/index.js
CHANGED
|
@@ -123,19 +123,16 @@ export class LwrViewRegistry {
|
|
|
123
123
|
}
|
|
124
124
|
throw new Error(`No View provider was able to resolve a view for template: ${viewId.contentTemplate}`);
|
|
125
125
|
}
|
|
126
|
-
async getView(viewId
|
|
126
|
+
async getView(viewId) {
|
|
127
127
|
const { contentTemplate, rootComponent } = viewId;
|
|
128
128
|
const compiledViewCacheKey = getCacheKeyFromJson({ contentTemplate, rootComponent });
|
|
129
129
|
logger.debug(`[view-registry][getView] compiledViewCacheKey=${compiledViewCacheKey}`);
|
|
130
130
|
// use cached compiledView if available
|
|
131
|
-
if (
|
|
131
|
+
if (this.compiledViews.has(compiledViewCacheKey)) {
|
|
132
132
|
return this.compiledViews.get(compiledViewCacheKey);
|
|
133
133
|
}
|
|
134
134
|
const compiledView = await this.delegateGetView(viewId);
|
|
135
|
-
|
|
136
|
-
if (!skipCaching) {
|
|
137
|
-
this.compiledViews.set(compiledViewCacheKey, compiledView);
|
|
138
|
-
}
|
|
135
|
+
this.compiledViews.set(compiledViewCacheKey, compiledView);
|
|
139
136
|
return compiledView;
|
|
140
137
|
}
|
|
141
138
|
hasViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions) {
|
|
@@ -173,7 +170,7 @@ export class LwrViewRegistry {
|
|
|
173
170
|
}
|
|
174
171
|
async getViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions) {
|
|
175
172
|
try {
|
|
176
|
-
const {
|
|
173
|
+
const { freezeAssets, viewParamCacheKey } = normalizeRenderOptions(this.runtimeEnvironment, renderOptions);
|
|
177
174
|
const viewDefCacheKey = getCacheKeyFromJson({
|
|
178
175
|
...view,
|
|
179
176
|
freezeAssets,
|
|
@@ -191,9 +188,8 @@ export class LwrViewRegistry {
|
|
|
191
188
|
? getCacheKeyFromJson(viewParamCacheKey)
|
|
192
189
|
: getCacheKeyFromJson(viewParams);
|
|
193
190
|
logger.debug(`[view-registry][getViewDefinition] viewParamKey=${viewParamKey}`);
|
|
194
|
-
const cacheDisabled = process.env.NOCACHE === 'true' || skipCaching;
|
|
195
191
|
// important: cache key does not include the unbounded viewParams
|
|
196
|
-
if (
|
|
192
|
+
if (this.viewDefinitions.has(viewDefCacheKey)) {
|
|
197
193
|
const viewDefinition = this.viewDefinitions.get(viewDefCacheKey);
|
|
198
194
|
if (viewDefinition &&
|
|
199
195
|
viewDefinition.paramKey === viewParamKey &&
|
|
@@ -214,23 +210,19 @@ export class LwrViewRegistry {
|
|
|
214
210
|
}, () => this.renderView(view, updatableViewParams, runtimeEnvironment, runtimeParams, renderOptions)));
|
|
215
211
|
// Once the view is generated add the nonce to the response so it can be cached and then added to the headers
|
|
216
212
|
viewDefinition.nonce = getViewNonce(updatableViewParams);
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
// s -> ms
|
|
231
|
-
{ ttl: ttl ? ttl * 1000 : undefined });
|
|
232
|
-
}
|
|
233
|
-
}
|
|
213
|
+
const route = this.globalConfig.routes.find((r) => r.id === view.id);
|
|
214
|
+
const maxViewCacheTtl = getFeatureFlags().MAX_VIEW_CACHE_TTL;
|
|
215
|
+
// optionally set a max TTL on the view registry cache
|
|
216
|
+
// use a very low TTL if the shortest is 0, to allow the view to be fetched > once during a single request
|
|
217
|
+
const maxTtl = maxViewCacheTtl && parseInt(maxViewCacheTtl, 10);
|
|
218
|
+
const leastTtl = shortestTtl(viewDefinition.cache?.ttl, route?.cache?.ttl, maxTtl);
|
|
219
|
+
const ttl = leastTtl !== undefined ? (leastTtl === 0 ? 10 : leastTtl * 1000) : undefined;
|
|
220
|
+
// cache view definition for the shortest ttl or until it is the least recently used when ttl is undefined
|
|
221
|
+
this.viewDefinitions.set(viewDefCacheKey, {
|
|
222
|
+
view,
|
|
223
|
+
viewDefinition,
|
|
224
|
+
paramKey: viewParamKey,
|
|
225
|
+
}, { ttl });
|
|
234
226
|
return viewDefinition;
|
|
235
227
|
}
|
|
236
228
|
catch (err) {
|
|
@@ -317,7 +309,7 @@ export class LwrViewRegistry {
|
|
|
317
309
|
async render(viewId, viewParams, runtimeParams, runtimeEnvironment, renderOptions) {
|
|
318
310
|
const globalContext = this.globalData;
|
|
319
311
|
const { id, rootComponent, contentTemplate } = viewId;
|
|
320
|
-
const compiledView = await this.getView({ id, contentTemplate, rootComponent }
|
|
312
|
+
const compiledView = await this.getView({ id, contentTemplate, rootComponent });
|
|
321
313
|
// Get content/body of the view
|
|
322
314
|
/*
|
|
323
315
|
When rendering the compiled view, a collection variable properties can be passed to the render() to be rendered in
|
package/build/es/utils.js
CHANGED
|
@@ -95,7 +95,6 @@ export function normalizeRenderOptions(runtimeEnvironment, overrideRenderOptions
|
|
|
95
95
|
// Default render options
|
|
96
96
|
skipMetadataCollection: false,
|
|
97
97
|
freezeAssets: runtimeEnvironment.immutableAssets,
|
|
98
|
-
skipCaching: false,
|
|
99
98
|
viewParamCacheKey: null,
|
|
100
99
|
...baseRenderOptions,
|
|
101
100
|
...overrideRenderOptions,
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.13.0-alpha.
|
|
7
|
+
"version": "0.13.0-alpha.28",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"build": "tsc -b"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@lwrjs/app-service": "0.13.0-alpha.
|
|
37
|
-
"@lwrjs/diagnostics": "0.13.0-alpha.
|
|
38
|
-
"@lwrjs/instrumentation": "0.13.0-alpha.
|
|
39
|
-
"@lwrjs/shared-utils": "0.13.0-alpha.
|
|
36
|
+
"@lwrjs/app-service": "0.13.0-alpha.28",
|
|
37
|
+
"@lwrjs/diagnostics": "0.13.0-alpha.28",
|
|
38
|
+
"@lwrjs/instrumentation": "0.13.0-alpha.28",
|
|
39
|
+
"@lwrjs/shared-utils": "0.13.0-alpha.28",
|
|
40
40
|
"lru-cache": "^10.2.2"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@lwrjs/types": "0.13.0-alpha.
|
|
43
|
+
"@lwrjs/types": "0.13.0-alpha.28"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=18.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "3c8caa1fd5ce8c2360cd63049865aac499e30881"
|
|
49
49
|
}
|