@lwrjs/view-registry 0.9.0-alpha.9 → 0.9.0
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 +10 -4
- package/build/cjs/linkers/legacy_view_bootstrap.cjs +55 -24
- package/build/cjs/linkers/utils.cjs +39 -0
- package/build/cjs/linkers/view_bootstrap.cjs +43 -21
- package/build/cjs/utils.cjs +8 -25
- package/build/cjs/view-handler.cjs +19 -30
- package/build/es/index.js +9 -2
- package/build/es/linkers/legacy_view_bootstrap.d.ts +2 -1
- package/build/es/linkers/legacy_view_bootstrap.js +74 -39
- package/build/es/linkers/link-lwr-resources.d.ts +2 -1
- package/build/es/linkers/utils.d.ts +7 -1
- package/build/es/linkers/utils.js +52 -1
- package/build/es/linkers/view_bootstrap.d.ts +2 -1
- package/build/es/linkers/view_bootstrap.js +55 -35
- package/build/es/utils.d.ts +2 -14
- package/build/es/utils.js +5 -27
- package/build/es/view-handler.d.ts +5 -5
- package/build/es/view-handler.js +18 -35
- package/package.json +9 -9
package/build/es/view-handler.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { normalizeResourcePath } from '@lwrjs/shared-utils';
|
|
2
|
-
import { generateHtmlTag, generatePageContext,
|
|
1
|
+
import { normalizeResourcePath, shortestTtl } from '@lwrjs/shared-utils';
|
|
2
|
+
import { generateHtmlTag, generatePageContext, isViewResponse, toJsonFormat } from './utils.js';
|
|
3
3
|
import { resolve } from 'path';
|
|
4
4
|
export class LwrViewHandler {
|
|
5
5
|
constructor(context, globalConfig) {
|
|
6
|
-
// TODO convert to using InflightTasks in the shared utils
|
|
7
|
-
this.inflightRouteHandlerEvalMap = new Map();
|
|
8
|
-
this.routeHandlerFunctionMap = new Map();
|
|
9
|
-
this.viewRegistry = context.viewRegistry;
|
|
10
6
|
this.globalConfig = globalConfig;
|
|
7
|
+
this.routeHandlers = context.routeHandlers;
|
|
8
|
+
this.viewRegistry = context.viewRegistry;
|
|
11
9
|
this.moduleRegistry = context.moduleRegistry;
|
|
12
10
|
}
|
|
13
11
|
// Get the View's HTML Response
|
|
@@ -18,8 +16,7 @@ export class LwrViewHandler {
|
|
|
18
16
|
route,
|
|
19
17
|
// context
|
|
20
18
|
runtimeEnvironment, runtimeParams = {}) {
|
|
21
|
-
|
|
22
|
-
if (routeHandler) {
|
|
19
|
+
if (route.routeHandler) {
|
|
23
20
|
const response = await this.getRouteHandlerResponse(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
24
21
|
if (isViewResponse(response)) {
|
|
25
22
|
// Return custom view response payload as-is
|
|
@@ -38,6 +35,7 @@ export class LwrViewHandler {
|
|
|
38
35
|
metadata: {
|
|
39
36
|
viewDefinition,
|
|
40
37
|
},
|
|
38
|
+
cache: { ttl: shortestTtl(response.cache?.ttl, viewDefinition.cache?.ttl) },
|
|
41
39
|
};
|
|
42
40
|
}
|
|
43
41
|
// default static view
|
|
@@ -47,6 +45,7 @@ export class LwrViewHandler {
|
|
|
47
45
|
metadata: {
|
|
48
46
|
viewDefinition,
|
|
49
47
|
},
|
|
48
|
+
cache: viewDefinition.cache,
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
51
|
// Get the View's JSON Manifest Response
|
|
@@ -57,8 +56,7 @@ export class LwrViewHandler {
|
|
|
57
56
|
route,
|
|
58
57
|
// context
|
|
59
58
|
runtimeEnvironment, runtimeParams = {}) {
|
|
60
|
-
|
|
61
|
-
if (routeHandler) {
|
|
59
|
+
if (route.routeHandler) {
|
|
62
60
|
const response = await this.getRouteHandlerResponse(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
63
61
|
if (isViewResponse(response)) {
|
|
64
62
|
// Return custom view response payload as-is
|
|
@@ -86,9 +84,8 @@ export class LwrViewHandler {
|
|
|
86
84
|
route,
|
|
87
85
|
// context
|
|
88
86
|
runtimeEnvironment, runtimeParams = {}) {
|
|
89
|
-
const { routeHandler } = route;
|
|
90
87
|
let viewDefinition;
|
|
91
|
-
if (routeHandler) {
|
|
88
|
+
if (route.routeHandler) {
|
|
92
89
|
const response = await this.getRouteHandlerResponse(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
93
90
|
if (isViewResponse(response)) {
|
|
94
91
|
// Return custom view response payload as-is
|
|
@@ -143,33 +140,18 @@ export class LwrViewHandler {
|
|
|
143
140
|
viewRequest, route,
|
|
144
141
|
// context
|
|
145
142
|
runtimeEnvironment, runtimeParams = {}) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const { routeHandler } = route;
|
|
149
|
-
if (!routeHandler) {
|
|
150
|
-
throw new Error('Route Handler is required for a CustomView');
|
|
143
|
+
if (!route.routeHandler) {
|
|
144
|
+
throw new Error('Route handler is required for a CustomView');
|
|
151
145
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const inflightRouteHandlerPromise = this.inflightRouteHandlerEvalMap.get(routeHandler);
|
|
156
|
-
if (inflightRouteHandlerPromise) {
|
|
157
|
-
// wait on the current inflight route handler promise
|
|
158
|
-
routeHandlerFunction = await inflightRouteHandlerPromise;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
// get the route handler eval promise
|
|
162
|
-
const handlerPromise = getRouteHandler(routeHandler, { cacheDir, rootDir });
|
|
163
|
-
this.inflightRouteHandlerEvalMap.set(routeHandler, handlerPromise);
|
|
164
|
-
routeHandlerFunction = await handlerPromise;
|
|
165
|
-
}
|
|
166
|
-
// add the resolved route handler function into the cache and delete the inflight entry
|
|
167
|
-
this.routeHandlerFunctionMap.set(routeHandler, routeHandlerFunction);
|
|
168
|
-
this.inflightRouteHandlerEvalMap.delete(routeHandler);
|
|
146
|
+
const routeHandler = this.routeHandlers[route.routeHandler];
|
|
147
|
+
if (!routeHandler) {
|
|
148
|
+
throw new Error(`Route handler does not exist for id: ${route.routeHandler}`);
|
|
169
149
|
}
|
|
150
|
+
const { rootDir, assets, contentDir, layoutsDir } = this.globalConfig;
|
|
151
|
+
const paths = { rootDir, assets, contentDir, layoutsDir };
|
|
170
152
|
const locale = runtimeParams.locale;
|
|
171
153
|
const viewApi = this.getBoundApi(route, runtimeEnvironment, runtimeParams);
|
|
172
|
-
const response = await
|
|
154
|
+
const response = await routeHandler({ ...viewRequest, locale }, { route: route, viewApi, ...paths });
|
|
173
155
|
return response;
|
|
174
156
|
}
|
|
175
157
|
/*
|
|
@@ -202,6 +184,7 @@ export class LwrViewHandler {
|
|
|
202
184
|
metadata: {
|
|
203
185
|
viewDefinition,
|
|
204
186
|
},
|
|
187
|
+
cache: viewDefinition.cache,
|
|
205
188
|
};
|
|
206
189
|
}
|
|
207
190
|
}
|
package/package.json
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.9.0
|
|
7
|
+
"version": "0.9.0",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/salesforce/lwr.git",
|
|
11
|
+
"url": "https://github.com/salesforce-experience-platform-emu/lwr.git",
|
|
12
12
|
"directory": "packages/@lwrjs/view-registry"
|
|
13
13
|
},
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/salesforce/lwr/issues"
|
|
15
|
+
"url": "https://github.com/salesforce-experience-platform-emu/lwr/issues"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
18
|
"types": "build/es/index.d.ts",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/app-service": "0.9.0
|
|
34
|
-
"@lwrjs/diagnostics": "0.9.0
|
|
35
|
-
"@lwrjs/shared-utils": "0.9.0
|
|
33
|
+
"@lwrjs/app-service": "0.9.0",
|
|
34
|
+
"@lwrjs/diagnostics": "0.9.0",
|
|
35
|
+
"@lwrjs/shared-utils": "0.9.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@lwrjs/types": "0.9.0
|
|
38
|
+
"@lwrjs/types": "0.9.0"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
41
|
+
"node": ">=16.0.0 <20"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "4e42b0dc5453f92b36b42aa8132c5bc281e616b7"
|
|
44
44
|
}
|