@lwrjs/view-registry 0.9.0-alpha.12 → 0.9.0-alpha.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.
@@ -42,6 +42,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
42
42
  const {id: appName, bootstrap: {services} = {services: []}} = view;
43
43
  const {lwrVersion, format, hmrEnabled, bundle, debug, minify} = runtimeEnvironment;
44
44
  const {customElements} = viewMetadata;
45
+ const defRegistry = bundle ? moduleBundler : moduleRegistry;
45
46
  const version = lwrVersion;
46
47
  const isAMD = format === "amd";
47
48
  const appIdentity = {
@@ -84,7 +85,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
84
85
  }
85
86
  }
86
87
  const depth = isAMD ? {static: import_shared_utils.GraphDepth.ALL, dynamic: 1} : {static: import_shared_utils.GraphDepth.NONE, dynamic: 1};
87
- const bootstrapModuleGraph = await (0, import_shared_utils.getModuleGraphs)(bootstrapSpecifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams, visitedCache);
88
+ const bootstrapModuleGraph = await (0, import_shared_utils.getModuleGraphs)(bootstrapSpecifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visitedCache);
88
89
  const versionedSpecifier = bootstrapModuleGraph.graphs[0].specifier;
89
90
  const uri = bootstrapModuleGraph.uriMap[versionedSpecifier];
90
91
  moduleResources.push((0, import_utils.getModuleResourceByUri)(uri, runtimeEnvironment, {isPreload: false, isSSR}));
@@ -108,11 +109,11 @@ async function getHtmlResources(view, viewParams, resourceContext) {
108
109
  }
109
110
  }
110
111
  }
111
- let importMetadata = await (0, import_shared_utils.toImportMetadata)(bootstrapModuleGraph, {imports: {}, index: {}}, moduleRegistry, runtimeEnvironment, runtimeParams);
112
+ let importMetadata = await (0, import_shared_utils.toImportMetadata)(bootstrapModuleGraph, {imports: {}, index: {}}, defRegistry, runtimeEnvironment, runtimeParams);
112
113
  const customElementsRecords = [];
113
114
  const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements, isSSR);
114
115
  for (const {tagName: element} of flattenedElements) {
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);
116
+ const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.kebabCaseToModuleSpecifer)(element), {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
116
117
  customElementsRecords.push({elementName: element, flatGraph: graph});
117
118
  const specifier = graph.graphs[0].specifier;
118
119
  const uri2 = graph.uriMap[specifier];
@@ -130,7 +131,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
130
131
  imports[dynamicDep] = uri3;
131
132
  }
132
133
  }
133
- importMetadata = await (0, import_shared_utils.toImportMetadata)(graph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
134
+ importMetadata = await (0, import_shared_utils.toImportMetadata)(graph, importMetadata, defRegistry, runtimeEnvironment, runtimeParams);
134
135
  }
135
136
  configResources.unshift(await (0, import_utils2.getViewBootstrapConfigurationResource)({
136
137
  id: view.id,
@@ -29,19 +29,15 @@ __export(exports, {
29
29
  generatePageContext: () => generatePageContext,
30
30
  getModuleResource: () => getModuleResource,
31
31
  getModuleResourceByUri: () => getModuleResourceByUri,
32
- getRouteHandler: () => getRouteHandler,
33
32
  isViewResponse: () => isViewResponse,
34
33
  normalizeRenderOptions: () => normalizeRenderOptions,
35
34
  normalizeRenderedResult: () => normalizeRenderedResult,
36
35
  reduceSourceAssetReferences: () => reduceSourceAssetReferences,
37
36
  toJsonFormat: () => toJsonFormat
38
37
  });
39
- var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
40
38
  var import_path = __toModule(require("path"));
41
- var import_path2 = __toModule(require("path"));
42
- var import_shared_utils2 = __toModule(require("@lwrjs/shared-utils"));
39
+ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
43
40
  var import_identity = __toModule(require("@lwrjs/app-service/identity"));
44
- var import_shared_utils3 = __toModule(require("@lwrjs/shared-utils"));
45
41
  function streamToString(stream) {
46
42
  const chunks = [];
47
43
  return new Promise((resolve, reject) => {
@@ -132,7 +128,7 @@ function normalizeRenderOptions(runtimeEnvironment, overrideRenderOptions, baseR
132
128
  };
133
129
  }
134
130
  function getTitleFromFilePath(filePath) {
135
- return filePath ? (0, import_path2.basename)(filePath, (0, import_path2.extname)(filePath)) : import_shared_utils.DEFAULT_TITLE;
131
+ return filePath ? (0, import_path.basename)(filePath, (0, import_path.extname)(filePath)) : import_shared_utils.DEFAULT_TITLE;
136
132
  }
137
133
  function generatePageContext({requestPath: url}, {id, contentTemplate, properties}) {
138
134
  const title = properties?.title || getTitleFromFilePath(contentTemplate);
@@ -141,19 +137,6 @@ function generatePageContext({requestPath: url}, {id, contentTemplate, propertie
141
137
  function isViewResponse(response) {
142
138
  return response.body !== void 0;
143
139
  }
144
- async function getRouteHandler(path, {cacheDir, rootDir}) {
145
- try {
146
- const fullPath = (0, import_shared_utils.resolveFileExtension)(path);
147
- if (fullPath.endsWith(".ts")) {
148
- path = await (0, import_shared_utils.transpileTs)(path, {rootDir, cacheDir: import_path.default.join(cacheDir, "routeHandlers")});
149
- }
150
- const moduleEntry = await Promise.resolve().then(() => __toModule(require(path)));
151
- return moduleEntry.default || moduleEntry;
152
- } catch (err) {
153
- console.log(err);
154
- throw new Error(`Unable to get routeHandler: ${path}`);
155
- }
156
- }
157
140
  async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironment, runtimeParams, moduleRegistry) {
158
141
  const {viewRecord} = viewDefinition;
159
142
  const {bootstrap, id: appName} = route;
@@ -186,7 +169,7 @@ async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironme
186
169
  });
187
170
  resources.push({
188
171
  type: "application/javascript",
189
- src: (0, import_shared_utils3.getClientBootstrapConfigurationUri)({url: viewRequest.url, id: route.id}, runtimeEnvironment, runtimeParams)
172
+ src: (0, import_shared_utils.getClientBootstrapConfigurationUri)({url: viewRequest.url, id: route.id}, runtimeEnvironment, runtimeParams)
190
173
  });
191
174
  }
192
175
  const mappingUrl = (0, import_shared_utils.getMappingUriPrefix)(runtimeEnvironment, runtimeParams);
@@ -206,7 +189,7 @@ async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironme
206
189
  });
207
190
  viewRecord.assetReferences?.forEach((asset) => {
208
191
  if (asset.override?.uri) {
209
- const type = (0, import_shared_utils2.mimeLookup)(asset.override?.uri);
192
+ const type = (0, import_shared_utils.mimeLookup)(asset.override?.uri);
210
193
  resources.push({type, src: asset.override?.uri});
211
194
  }
212
195
  });
@@ -229,10 +212,10 @@ async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironme
229
212
  }
230
213
  };
231
214
  }
232
- async function getModuleResource(moduleId, runtimeEnvironment, moduleResouceMeta, moduleRegistry, runtimeParams) {
215
+ async function getModuleResource(moduleId, runtimeEnvironment, moduleResouceMeta, defRegistry, runtimeParams) {
233
216
  const {format} = runtimeEnvironment;
234
217
  const {isSSR = false, isPreload = false} = moduleResouceMeta;
235
- const moduleUri = await moduleRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
218
+ const moduleUri = await defRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
236
219
  return {
237
220
  src: moduleUri,
238
221
  type: format === "amd" ? "application/javascript" : "module",
@@ -31,8 +31,6 @@ var import_utils = __toModule(require("./utils.cjs"));
31
31
  var import_path = __toModule(require("path"));
32
32
  var LwrViewHandler = class {
33
33
  constructor(context, globalConfig) {
34
- this.inflightRouteHandlerEvalMap = new Map();
35
- this.routeHandlerFunctionMap = new Map();
36
34
  this.viewRegistry = context.viewRegistry;
37
35
  this.globalConfig = globalConfig;
38
36
  this.moduleRegistry = context.moduleRegistry;
@@ -128,28 +126,15 @@ var LwrViewHandler = class {
128
126
  return viewDefinition;
129
127
  }
130
128
  async getRouteHandlerResponse(viewRequest, route, runtimeEnvironment, runtimeParams = {}) {
131
- const {rootDir, assets, contentDir, layoutsDir, cacheDir} = this.globalConfig;
129
+ const {rootDir, assets, contentDir, layoutsDir} = this.globalConfig;
132
130
  const paths = {rootDir, assets, contentDir, layoutsDir};
133
131
  const {routeHandler} = route;
134
132
  if (!routeHandler) {
135
133
  throw new Error("Route Handler is required for a CustomView");
136
134
  }
137
- let routeHandlerFunction = this.routeHandlerFunctionMap.get(routeHandler);
138
- if (!routeHandlerFunction) {
139
- const inflightRouteHandlerPromise = this.inflightRouteHandlerEvalMap.get(routeHandler);
140
- if (inflightRouteHandlerPromise) {
141
- routeHandlerFunction = await inflightRouteHandlerPromise;
142
- } else {
143
- const handlerPromise = (0, import_utils.getRouteHandler)(routeHandler, {cacheDir, rootDir});
144
- this.inflightRouteHandlerEvalMap.set(routeHandler, handlerPromise);
145
- routeHandlerFunction = await handlerPromise;
146
- }
147
- this.routeHandlerFunctionMap.set(routeHandler, routeHandlerFunction);
148
- this.inflightRouteHandlerEvalMap.delete(routeHandler);
149
- }
150
135
  const locale = runtimeParams.locale;
151
136
  const viewApi = this.getBoundApi(route, runtimeEnvironment, runtimeParams);
152
- const response = await routeHandlerFunction({...viewRequest, locale}, {route, viewApi, ...paths});
137
+ const response = await routeHandler({...viewRequest, locale}, {route, viewApi, ...paths});
153
138
  return response;
154
139
  }
155
140
  getBoundApi(route, runtimeEnvironment, runtimeParams) {
@@ -7,6 +7,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
7
7
  const { id: appName, bootstrap: { services } = { services: [] } } = view;
8
8
  const { lwrVersion, format, hmrEnabled, bundle, debug, minify } = runtimeEnvironment;
9
9
  const { customElements } = viewMetadata;
10
+ const defRegistry = bundle ? moduleBundler : moduleRegistry;
10
11
  const version = lwrVersion;
11
12
  const isAMD = format === 'amd';
12
13
  // Application Bootstrap (ABS) module resource: "@lwrjs/app-service/{appName}/module/{format}"
@@ -81,7 +82,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
81
82
  const depth = isAMD
82
83
  ? { static: GraphDepth.ALL, dynamic: 1 }
83
84
  : { static: GraphDepth.NONE, dynamic: 1 };
84
- const bootstrapModuleGraph = await getModuleGraphs(bootstrapSpecifier, { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams, visitedCache);
85
+ const bootstrapModuleGraph = await getModuleGraphs(bootstrapSpecifier, { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visitedCache);
85
86
  // ADD bootstrap module uri as a script resource
86
87
  const versionedSpecifier = bootstrapModuleGraph.graphs[0].specifier;
87
88
  const uri = bootstrapModuleGraph.uriMap[versionedSpecifier];
@@ -114,13 +115,13 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
114
115
  }
115
116
  }
116
117
  }
117
- let importMetadata = await toImportMetadata(bootstrapModuleGraph, { imports: {}, index: {} }, moduleRegistry, runtimeEnvironment, runtimeParams);
118
+ let importMetadata = await toImportMetadata(bootstrapModuleGraph, { imports: {}, index: {} }, defRegistry, runtimeEnvironment, runtimeParams);
118
119
  // ------- View related custom element moduleResources
119
120
  const customElementsRecords = [];
120
121
  const flattenedElements = flattenCustomElements(customElements, isSSR);
121
122
  for (const { tagName: element } of flattenedElements) {
122
123
  // eslint-disable-next-line no-await-in-loop
123
- const graph = await getModuleGraphs(kebabCaseToModuleSpecifer(element), { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
124
+ const graph = await getModuleGraphs(kebabCaseToModuleSpecifer(element), { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
124
125
  // add to the viewRecord
125
126
  customElementsRecords.push({ elementName: element, flatGraph: graph });
126
127
  // PRELOAD custom element static deps as link resource
@@ -144,7 +145,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
144
145
  }
145
146
  }
146
147
  // eslint-disable-next-line no-await-in-loop
147
- importMetadata = await toImportMetadata(graph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
148
+ importMetadata = await toImportMetadata(graph, importMetadata, defRegistry, runtimeEnvironment, runtimeParams);
148
149
  }
149
150
  // ADD configuration of the bootstrapModule
150
151
  configResources.unshift(await getViewBootstrapConfigurationResource({
@@ -1,25 +1,13 @@
1
- import { NormalizedRenderingResult, RenderingResult, ResourceDefinition, AssetReference, RenderedAssetReference, RenderOptions, ModuleId, ViewModuleResourceContext, ViewPageContext, JsonCompatible } from '@lwrjs/types';
2
- import { PublicModuleRegistry, RuntimeEnvironment, RuntimeParams, ModuleJson, RouteHandlerViewResponse, ViewResponse, RouteHandlerFunction, LwrRoute, LwrErrorRoute, ViewRequest, LinkedViewDefinition, ModuleRegistry } from 'packages/@lwrjs/types/src';
1
+ import type { AssetReference, JsonCompatible, LinkedViewDefinition, LwrErrorRoute, LwrRoute, ModuleBundler, ModuleId, ModuleJson, ModuleRegistry, NormalizedRenderingResult, PublicModuleRegistry, RenderOptions, RenderedAssetReference, RenderingResult, ResourceDefinition, Route, RouteHandlerViewResponse, RuntimeEnvironment, RuntimeParams, ViewModuleResourceContext, ViewPageContext, ViewRequest, ViewResponse } from '@lwrjs/types';
3
2
  export declare type HTMLResource = Partial<ResourceDefinition>;
4
3
  export declare function generateHtmlTag(definition: HTMLResource): Promise<string>;
5
4
  export declare function normalizeRenderedResult({ renderedView, metadata, options, }: RenderingResult): NormalizedRenderingResult;
6
5
  export declare function reduceSourceAssetReferences(assets: AssetReference[]): RenderedAssetReference[];
7
6
  export declare function normalizeRenderOptions(runtimeEnvironment: RuntimeEnvironment, overrideRenderOptions?: RenderOptions, baseRenderOptions?: RenderOptions): Required<RenderOptions>;
8
- export declare function generatePageContext({ requestPath: url }: ViewRequest, { id, contentTemplate, properties }: LwrRoute | LwrErrorRoute): JsonCompatible<ViewPageContext>;
7
+ export declare function generatePageContext({ requestPath: url }: ViewRequest, { id, contentTemplate, properties }: Route<LwrRoute | LwrErrorRoute>): JsonCompatible<ViewPageContext>;
9
8
  export declare function isViewResponse(response: RouteHandlerViewResponse): response is ViewResponse;
10
- interface RouteHandlerContext {
11
- cacheDir: string;
12
- rootDir: string;
13
- }
14
- /**
15
- * Load and cache a route handler function (for a view) from the fs
16
- * @param path - path to the route handle code on the fs
17
- * @param param1 - directories
18
- */
19
- export declare function getRouteHandler(path: string, { cacheDir, rootDir }: RouteHandlerContext): Promise<RouteHandlerFunction>;
20
- export declare function toJsonFormat(viewRequest: ViewRequest, viewDefinition: LinkedViewDefinition, route: LwrRoute | LwrErrorRoute, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, moduleRegistry: ModuleRegistry): Promise<ViewResponse>;
21
- export declare function getModuleResource(moduleId: Pick<ModuleId, 'specifier' | 'version'>, runtimeEnvironment: RuntimeEnvironment, moduleResouceMeta: ViewModuleResourceContext, moduleRegistry: ModuleRegistry, runtimeParams?: RuntimeParams): Promise<ResourceDefinition>;
9
+ export declare function toJsonFormat(viewRequest: ViewRequest, viewDefinition: LinkedViewDefinition, route: Route<LwrRoute | LwrErrorRoute>, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, moduleRegistry: ModuleRegistry): Promise<ViewResponse>;
10
+ export declare function getModuleResource(moduleId: Pick<ModuleId, 'specifier' | 'version'>, runtimeEnvironment: RuntimeEnvironment, moduleResouceMeta: ViewModuleResourceContext, defRegistry: ModuleRegistry | ModuleBundler, runtimeParams?: RuntimeParams): Promise<ResourceDefinition>;
22
11
  export declare function getModuleResourceByUri(uri: string, runtimeEnvironment: RuntimeEnvironment, moduleResouceMeta: ViewModuleResourceContext): ResourceDefinition;
23
12
  export declare function createJsonModule(specifier: string, moduleRegistry: PublicModuleRegistry, environment: RuntimeEnvironment, params?: RuntimeParams): Promise<ModuleJson>;
24
- export {};
25
13
  //# sourceMappingURL=utils.d.ts.map
package/build/es/utils.js CHANGED
@@ -1,9 +1,6 @@
1
- import { explodeSpecifier, getMappingUriPrefix, getSpecifier, resolveFileExtension, transpileTs, DEFAULT_TITLE, } from '@lwrjs/shared-utils';
2
- import libPath from 'path';
3
1
  import { basename, extname } from 'path';
4
- import { mimeLookup } from '@lwrjs/shared-utils';
2
+ import { explodeSpecifier, getMappingUriPrefix, getSpecifier, getClientBootstrapConfigurationUri, mimeLookup, DEFAULT_TITLE, } from '@lwrjs/shared-utils';
5
3
  import { AppResourceEnum, getAppSpecifier, ResourceIdentityTypes, } from '@lwrjs/app-service/identity';
6
- import { getClientBootstrapConfigurationUri } from '@lwrjs/shared-utils';
7
4
  function streamToString(stream) {
8
5
  const chunks = [];
9
6
  return new Promise((resolve, reject) => {
@@ -110,25 +107,6 @@ export function generatePageContext({ requestPath: url }, { id, contentTemplate,
110
107
  export function isViewResponse(response) {
111
108
  return response.body !== undefined;
112
109
  }
113
- /**
114
- * Load and cache a route handler function (for a view) from the fs
115
- * @param path - path to the route handle code on the fs
116
- * @param param1 - directories
117
- */
118
- export async function getRouteHandler(path, { cacheDir, rootDir }) {
119
- try {
120
- const fullPath = resolveFileExtension(path);
121
- if (fullPath.endsWith('.ts')) {
122
- path = await transpileTs(path, { rootDir, cacheDir: libPath.join(cacheDir, 'routeHandlers') });
123
- }
124
- const moduleEntry = await import(path);
125
- return moduleEntry.default || moduleEntry;
126
- }
127
- catch (err) {
128
- console.log(err);
129
- throw new Error(`Unable to get routeHandler: ${path}`);
130
- }
131
- }
132
110
  export async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironment, runtimeParams, moduleRegistry) {
133
111
  const { viewRecord } = viewDefinition;
134
112
  const { bootstrap, id: appName } = route;
@@ -213,10 +191,10 @@ export async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEn
213
191
  },
214
192
  };
215
193
  }
216
- export async function getModuleResource(moduleId, runtimeEnvironment, moduleResouceMeta, moduleRegistry, runtimeParams) {
194
+ export async function getModuleResource(moduleId, runtimeEnvironment, moduleResouceMeta, defRegistry, runtimeParams) {
217
195
  const { format } = runtimeEnvironment;
218
196
  const { isSSR = false, isPreload = false } = moduleResouceMeta;
219
- const moduleUri = await moduleRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
197
+ const moduleUri = await defRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
220
198
  return {
221
199
  src: moduleUri,
222
200
  type: format === 'amd' ? 'application/javascript' : 'module',
@@ -1,4 +1,4 @@
1
- import { ViewRegistry, RuntimeEnvironment, NormalizedLwrGlobalConfig, ViewRequest, RuntimeParams, ViewResponse, LwrErrorRoute, LwrRoute, ModuleRegistry, RouteHandlerFunction, ViewHandler } from '@lwrjs/types';
1
+ import { ViewRegistry, RuntimeEnvironment, NormalizedLwrGlobalConfig, ViewRequest, RuntimeParams, ViewResponse, LwrRoute, LwrErrorRoute, Route, ModuleRegistry, ViewHandler } from '@lwrjs/types';
2
2
  export interface ViewHandlerContext {
3
3
  viewRegistry: ViewRegistry;
4
4
  moduleRegistry: ModuleRegistry;
@@ -7,12 +7,10 @@ export declare class LwrViewHandler implements ViewHandler {
7
7
  viewRegistry: ViewRegistry;
8
8
  moduleRegistry: ModuleRegistry;
9
9
  globalConfig: NormalizedLwrGlobalConfig;
10
- inflightRouteHandlerEvalMap: Map<string, Promise<RouteHandlerFunction>>;
11
- routeHandlerFunctionMap: Map<string, RouteHandlerFunction>;
12
10
  constructor(context: ViewHandlerContext, globalConfig: NormalizedLwrGlobalConfig);
13
- getViewContent(viewRequest: ViewRequest, route: LwrRoute | LwrErrorRoute, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ViewResponse>;
14
- getViewJson(viewRequest: ViewRequest, route: LwrRoute | LwrErrorRoute, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ViewResponse>;
15
- getViewConfiguration(viewRequest: ViewRequest, route: LwrRoute | LwrErrorRoute, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ViewResponse | undefined>;
11
+ getViewContent(viewRequest: ViewRequest, route: Route<LwrRoute | LwrErrorRoute>, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ViewResponse>;
12
+ getViewJson(viewRequest: ViewRequest, route: Route<LwrRoute | LwrErrorRoute>, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ViewResponse>;
13
+ getViewConfiguration(viewRequest: ViewRequest, route: Route<LwrRoute | LwrErrorRoute>, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ViewResponse | undefined>;
16
14
  private getDefaultRouteViewDefinition;
17
15
  private getRouteHandlerResponse;
18
16
  private getBoundApi;
@@ -1,11 +1,8 @@
1
1
  import { normalizeResourcePath, shortestTtl } from '@lwrjs/shared-utils';
2
- import { generateHtmlTag, generatePageContext, getRouteHandler, isViewResponse, toJsonFormat, } from './utils.js';
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
6
  this.viewRegistry = context.viewRegistry;
10
7
  this.globalConfig = globalConfig;
11
8
  this.moduleRegistry = context.moduleRegistry;
@@ -145,33 +142,15 @@ export class LwrViewHandler {
145
142
  viewRequest, route,
146
143
  // context
147
144
  runtimeEnvironment, runtimeParams = {}) {
148
- const { rootDir, assets, contentDir, layoutsDir, cacheDir } = this.globalConfig;
145
+ const { rootDir, assets, contentDir, layoutsDir } = this.globalConfig;
149
146
  const paths = { rootDir, assets, contentDir, layoutsDir };
150
147
  const { routeHandler } = route;
151
148
  if (!routeHandler) {
152
149
  throw new Error('Route Handler is required for a CustomView');
153
150
  }
154
- // Import and instantiate route handler
155
- let routeHandlerFunction = this.routeHandlerFunctionMap.get(routeHandler);
156
- if (!routeHandlerFunction) {
157
- const inflightRouteHandlerPromise = this.inflightRouteHandlerEvalMap.get(routeHandler);
158
- if (inflightRouteHandlerPromise) {
159
- // wait on the current inflight route handler promise
160
- routeHandlerFunction = await inflightRouteHandlerPromise;
161
- }
162
- else {
163
- // get the route handler eval promise
164
- const handlerPromise = getRouteHandler(routeHandler, { cacheDir, rootDir });
165
- this.inflightRouteHandlerEvalMap.set(routeHandler, handlerPromise);
166
- routeHandlerFunction = await handlerPromise;
167
- }
168
- // add the resolved route handler function into the cache and delete the inflight entry
169
- this.routeHandlerFunctionMap.set(routeHandler, routeHandlerFunction);
170
- this.inflightRouteHandlerEvalMap.delete(routeHandler);
171
- }
172
151
  const locale = runtimeParams.locale;
173
152
  const viewApi = this.getBoundApi(route, runtimeEnvironment, runtimeParams);
174
- const response = await routeHandlerFunction({ ...viewRequest, locale }, { route, viewApi, ...paths });
153
+ const response = await routeHandler({ ...viewRequest, locale }, { route: route, viewApi, ...paths });
175
154
  return response;
176
155
  }
177
156
  /*
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.9.0-alpha.12",
7
+ "version": "0.9.0-alpha.14",
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.12",
34
- "@lwrjs/diagnostics": "0.9.0-alpha.12",
35
- "@lwrjs/shared-utils": "0.9.0-alpha.12"
33
+ "@lwrjs/app-service": "0.9.0-alpha.14",
34
+ "@lwrjs/diagnostics": "0.9.0-alpha.14",
35
+ "@lwrjs/shared-utils": "0.9.0-alpha.14"
36
36
  },
37
37
  "devDependencies": {
38
- "@lwrjs/types": "0.9.0-alpha.12"
38
+ "@lwrjs/types": "0.9.0-alpha.14"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=14.15.4 <19"
42
42
  },
43
- "gitHead": "f532aa80039acf04e9ad511ed090a2b368837014"
43
+ "gitHead": "64e0ba617151429da6e09f1a9686628f64183d25"
44
44
  }