@lwrjs/view-registry 0.9.0-alpha.11 → 0.9.0-alpha.13

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.
@@ -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
  });
@@ -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) {
@@ -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 { NormalizedRenderingResult, RenderingResult, ResourceDefinition, AssetReference, RenderedAssetReference, RenderOptions, ModuleId, ViewModuleResourceContext, ViewPageContext, JsonCompatible, LwrRoute, LwrErrorRoute, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams, ModuleJson, RouteHandlerViewResponse, ViewResponse, Route, ViewRequest, LinkedViewDefinition, ModuleRegistry } 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>;
9
+ export declare function toJsonFormat(viewRequest: ViewRequest, viewDefinition: LinkedViewDefinition, route: Route<LwrRoute | LwrErrorRoute>, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, moduleRegistry: ModuleRegistry): Promise<ViewResponse>;
21
10
  export declare function getModuleResource(moduleId: Pick<ModuleId, 'specifier' | 'version'>, runtimeEnvironment: RuntimeEnvironment, moduleResouceMeta: ViewModuleResourceContext, moduleRegistry: ModuleRegistry, 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;
@@ -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.11",
7
+ "version": "0.9.0-alpha.13",
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.11",
34
- "@lwrjs/diagnostics": "0.9.0-alpha.11",
35
- "@lwrjs/shared-utils": "0.9.0-alpha.11"
33
+ "@lwrjs/app-service": "0.9.0-alpha.13",
34
+ "@lwrjs/diagnostics": "0.9.0-alpha.13",
35
+ "@lwrjs/shared-utils": "0.9.0-alpha.13"
36
36
  },
37
37
  "devDependencies": {
38
- "@lwrjs/types": "0.9.0-alpha.11"
38
+ "@lwrjs/types": "0.9.0-alpha.13"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=14.15.4 <19"
42
42
  },
43
- "gitHead": "3cb1275b364ae7373c1868c79e6082a122dbef9c"
43
+ "gitHead": "fa30915a685f6e8c5c2895d0c053d59145780123"
44
44
  }