@lwrjs/view-registry 0.12.0-alpha.0 → 0.12.0-alpha.2

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.
@@ -32,6 +32,7 @@ var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
32
32
  var import_utils = __toModule(require("./utils.cjs"));
33
33
  var import_link_lwr_resources = __toModule(require("./linkers/link-lwr-resources.cjs"));
34
34
  var import_lru_cache = __toModule(require("lru-cache"));
35
+ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
35
36
  var import_view_handler = __toModule(require("./view-handler.cjs"));
36
37
  var LwrViewRegistry = class {
37
38
  constructor(context, globalConfig) {
@@ -130,6 +131,7 @@ var LwrViewRegistry = class {
130
131
  async getView(viewId, skipCaching = false) {
131
132
  const {contentTemplate, rootComponent} = viewId;
132
133
  const compiledViewCacheKey = (0, import_shared_utils.getCacheKeyFromJson)({contentTemplate, rootComponent});
134
+ import_diagnostics.logger.debug(`[view-registry][getView] compiledViewCacheKey=${compiledViewCacheKey}`);
133
135
  if (!skipCaching && this.compiledViews.has(compiledViewCacheKey)) {
134
136
  return this.compiledViews.get(compiledViewCacheKey);
135
137
  }
@@ -153,7 +155,9 @@ var LwrViewRegistry = class {
153
155
  basePath: runtimeParams?.basePath,
154
156
  debug: runtimeEnvironment.debug
155
157
  });
158
+ import_diagnostics.logger.debug(`[view-registry][hasViewDefinition] viewDefId=${viewDefId}`);
156
159
  const viewParamKey = viewParamCacheKey ? (0, import_shared_utils.getCacheKeyFromJson)(viewParamCacheKey) : (0, import_shared_utils.getCacheKeyFromJson)(viewParams);
160
+ import_diagnostics.logger.debug(`[view-registry][hasViewDefinition] viewParamKey=${viewParamKey}`);
157
161
  if (this.viewDefinitions.has(viewDefId)) {
158
162
  const viewDef = this.viewDefinitions.get(viewDefId);
159
163
  if (viewDef && viewDef.paramKey === viewParamKey) {
@@ -171,7 +175,9 @@ var LwrViewRegistry = class {
171
175
  basePath: runtimeParams?.basePath,
172
176
  debug: runtimeEnvironment.debug
173
177
  });
178
+ import_diagnostics.logger.debug(`[view-registry][getViewDefinition] viewDefCacheKey=${viewDefCacheKey}`);
174
179
  const viewParamKey = viewParamCacheKey ? (0, import_shared_utils.getCacheKeyFromJson)(viewParamCacheKey) : (0, import_shared_utils.getCacheKeyFromJson)(viewParams);
180
+ import_diagnostics.logger.debug(`[view-registry][getViewDefinition] viewParamKey=${viewParamKey}`);
175
181
  const cacheDisabled = process.env.NOCACHE === "true" || skipCaching;
176
182
  if (cacheDisabled === false && this.viewDefinitions.has(viewDefCacheKey)) {
177
183
  const viewDefinition2 = this.viewDefinitions.get(viewDefCacheKey);
@@ -101,11 +101,17 @@ async function getHtmlResources(view, viewParams, resourceContext) {
101
101
  throw Error("Failed to find definition of resource: " + shimBundle);
102
102
  }
103
103
  }
104
+ if (!def.inline && !def.src) {
105
+ throw Error(`Invalid Shim ${shimBundle}: ${JSON.stringify(def)}`);
106
+ }
104
107
  requiredResources.push(def);
105
108
  const errorShimDef = await resourceRegistry.getResource({specifier: "lwr-error-shim.js", version}, runtimeEnvironment, runtimeParams);
106
109
  if (!errorShimDef) {
107
110
  throw Error("Failed to find definition of resource: lwr-error-shim.js");
108
111
  }
112
+ if (!errorShimDef.inline && !errorShimDef.src) {
113
+ throw Error(`Invalid Shim lwr-error-shim.js: ${JSON.stringify(errorShimDef)}`);
114
+ }
109
115
  requiredResources.push(errorShimDef);
110
116
  }
111
117
  const bootstrapModuleGraph = await (0, import_shared_utils.getModuleGraphs)(bootstrapSpecifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visitedCache);
@@ -116,6 +122,9 @@ async function getHtmlResources(view, viewParams, resourceContext) {
116
122
  };
117
123
  versionedSpecifier = bootstrapModuleGraph.graphs[0].specifier;
118
124
  const uri = bootstrapModuleGraph.uriMap[versionedSpecifier];
125
+ if (!uri) {
126
+ throw Error(`Invalid Module Resource ${versionedSpecifier}`);
127
+ }
119
128
  moduleResources.push((0, import_utils.getModuleResourceByUri)(uri, runtimeEnvironment, {isPreload: false, isSSR}));
120
129
  for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
121
130
  if (!isExternal(depSpecifier)) {
@@ -30,6 +30,9 @@ __export(exports, {
30
30
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
31
31
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
32
  function setPreloadModulesMeta(specifier, uri, groups, preloads) {
33
+ if (!uri) {
34
+ throw Error(`Invalid Preload Module ${specifier}`);
35
+ }
33
36
  const [removedVersion, version] = specifier.split("/v/");
34
37
  const normalizedSpecifier = version === import_shared_utils.VERSION_NOT_PROVIDED ? removedVersion : specifier;
35
38
  specifier = normalizedSpecifier;
@@ -64,7 +64,7 @@ function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironm
64
64
  ].filter(Boolean).join("\n");
65
65
  if (viewInfo.configAsSrc) {
66
66
  const viewUrl = viewInfo.url || "/";
67
- const url = (0, import_shared_utils.getClientBootstrapConfigurationUri)({id: viewInfo.id, url: viewUrl}, runtimeEnvironment, runtimeParams, (0, import_shared_utils.hashContent)(configString));
67
+ const url = (0, import_shared_utils.getClientBootstrapConfigurationUri)({id: viewInfo.id, url: viewUrl, query: runtimeParams.query}, runtimeEnvironment, runtimeParams, (0, import_shared_utils.hashContent)(configString));
68
68
  return {
69
69
  type: CONTENT_TYPE,
70
70
  content: configString,
@@ -92,11 +92,17 @@ async function getHtmlResources(view, viewParams, resourceContext) {
92
92
  if (!def) {
93
93
  throw Error("Failed to find definition of resource: " + shimBundle);
94
94
  }
95
+ if (!def.inline && !def.src) {
96
+ throw Error(`Invalid Shim ${shimBundle}: ${JSON.stringify(def)}`);
97
+ }
95
98
  requiredResources.push(def);
96
99
  const errorShimDef = await resourceRegistry.getResource({specifier: "lwr-error-shim.js", version}, runtimeEnvironment, runtimeParams);
97
100
  if (!errorShimDef) {
98
101
  throw Error("Failed to find definition of resource: lwr-error-shim.js");
99
102
  }
103
+ if (!errorShimDef.inline && !errorShimDef.src) {
104
+ throw Error(`Invalid Shim lwr-error-shim.js: ${JSON.stringify(errorShimDef)}`);
105
+ }
100
106
  requiredResources.push(errorShimDef);
101
107
  }
102
108
  const bootstrapModuleGraph = await (0, import_shared_utils.getModuleGraphs)(bootstrapSpecifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visitedCache);
@@ -107,6 +113,9 @@ async function getHtmlResources(view, viewParams, resourceContext) {
107
113
  };
108
114
  versionedSpecifier = bootstrapModuleGraph.graphs[0].specifier;
109
115
  const uri = bootstrapModuleGraph.uriMap[versionedSpecifier];
116
+ if (!uri) {
117
+ throw Error(`Invalid Module Resource ${versionedSpecifier}`);
118
+ }
110
119
  moduleResources.push((0, import_utils.getModuleResourceByUri)(uri, runtimeEnvironment, {isPreload: false, isSSR}));
111
120
  for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
112
121
  if (!isExternal(depSpecifier)) {
@@ -165,7 +165,7 @@ async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironme
165
165
  });
166
166
  resources.push({
167
167
  type: "application/javascript",
168
- src: (0, import_shared_utils.getClientBootstrapConfigurationUri)({url: viewRequest.url, id: route.id}, runtimeEnvironment, runtimeParams)
168
+ src: (0, import_shared_utils.getClientBootstrapConfigurationUri)({url: viewRequest.url, id: route.id, query: viewRequest.query}, runtimeEnvironment, runtimeParams)
169
169
  });
170
170
  }
171
171
  const mappingUrl = (0, import_shared_utils.getMappingUriPrefix)(runtimeEnvironment, runtimeParams);
package/build/es/index.js CHANGED
@@ -3,6 +3,7 @@ import { getTracer, ViewSpan } from '@lwrjs/instrumentation';
3
3
  import { normalizeRenderOptions, normalizeRenderedResult, reduceSourceAssetReferences } from './utils.js';
4
4
  import { linkLwrResources } from './linkers/link-lwr-resources.js';
5
5
  import { LRUCache } from 'lru-cache';
6
+ import { logger } from '@lwrjs/diagnostics';
6
7
  export { LwrViewHandler } from './view-handler.js';
7
8
  export class LwrViewRegistry {
8
9
  constructor(context, globalConfig) {
@@ -114,6 +115,7 @@ export class LwrViewRegistry {
114
115
  async getView(viewId, skipCaching = false) {
115
116
  const { contentTemplate, rootComponent } = viewId;
116
117
  const compiledViewCacheKey = getCacheKeyFromJson({ contentTemplate, rootComponent });
118
+ logger.debug(`[view-registry][getView] compiledViewCacheKey=${compiledViewCacheKey}`);
117
119
  // use cached compiledView if available
118
120
  if (!skipCaching && this.compiledViews.has(compiledViewCacheKey)) {
119
121
  return this.compiledViews.get(compiledViewCacheKey);
@@ -139,12 +141,14 @@ export class LwrViewRegistry {
139
141
  basePath: runtimeParams?.basePath,
140
142
  debug: runtimeEnvironment.debug,
141
143
  });
144
+ logger.debug(`[view-registry][hasViewDefinition] viewDefId=${viewDefId}`);
142
145
  // viewParams is an unbounded object and can be very large (17MB/view for developer.salesforce.com). Allowing conusmers
143
146
  // to provide a simple override avoids the excess memory / performance overhead of serializing & storing the viewParams
144
147
  // on every request, while still reusing our caching logic.
145
148
  const viewParamKey = viewParamCacheKey
146
149
  ? getCacheKeyFromJson(viewParamCacheKey)
147
150
  : getCacheKeyFromJson(viewParams);
151
+ logger.debug(`[view-registry][hasViewDefinition] viewParamKey=${viewParamKey}`);
148
152
  // important: cache key does not include the unbounded viewParams
149
153
  if (this.viewDefinitions.has(viewDefId)) {
150
154
  const viewDef = this.viewDefinitions.get(viewDefId);
@@ -163,12 +167,14 @@ export class LwrViewRegistry {
163
167
  basePath: runtimeParams?.basePath,
164
168
  debug: runtimeEnvironment.debug,
165
169
  });
170
+ logger.debug(`[view-registry][getViewDefinition] viewDefCacheKey=${viewDefCacheKey}`);
166
171
  // viewParams is an unbounded object and can be very large (17MB/view for developer.salesforce.com). Allowing consumers
167
172
  // to provide a simple override avoids the excess memory / performance overhead of serializing & storing the viewParams
168
173
  // on every request, while still reusing our caching logic.
169
174
  const viewParamKey = viewParamCacheKey
170
175
  ? getCacheKeyFromJson(viewParamCacheKey)
171
176
  : getCacheKeyFromJson(viewParams);
177
+ logger.debug(`[view-registry][getViewDefinition] viewParamKey=${viewParamKey}`);
172
178
  const cacheDisabled = process.env.NOCACHE === 'true' || skipCaching;
173
179
  // important: cache key does not include the unbounded viewParams
174
180
  if (cacheDisabled === false && this.viewDefinitions.has(viewDefCacheKey)) {
@@ -94,12 +94,20 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
94
94
  throw Error('Failed to find definition of resource: ' + shimBundle);
95
95
  }
96
96
  }
97
+ // Throw a very specific error if we get this back and the src or inline properties are not set
98
+ if (!def.inline && !def.src) {
99
+ throw Error(`Invalid Shim ${shimBundle}: ${JSON.stringify(def)}`);
100
+ }
97
101
  requiredResources.push(def);
98
102
  // Always inline the error shim script after the shim
99
103
  const errorShimDef = (await resourceRegistry.getResource({ specifier: 'lwr-error-shim.js', version }, runtimeEnvironment, runtimeParams));
100
104
  if (!errorShimDef) {
101
105
  throw Error('Failed to find definition of resource: lwr-error-shim.js');
102
106
  }
107
+ // Throw a very specific error if we get this back and the src or inline properties are not set
108
+ if (!errorShimDef.inline && !errorShimDef.src) {
109
+ throw Error(`Invalid Shim lwr-error-shim.js: ${JSON.stringify(errorShimDef)}`);
110
+ }
103
111
  requiredResources.push(errorShimDef);
104
112
  }
105
113
  // ------- Application Bootstrap module
@@ -115,6 +123,10 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
115
123
  // ADD bootstrap module uri as a script resource
116
124
  versionedSpecifier = bootstrapModuleGraph.graphs[0].specifier;
117
125
  const uri = bootstrapModuleGraph.uriMap[versionedSpecifier];
126
+ // Throw a very specific error if we get this back and the uri property is not set
127
+ if (!uri) {
128
+ throw Error(`Invalid Module Resource ${versionedSpecifier}`);
129
+ }
118
130
  moduleResources.push(getModuleResourceByUri(uri, runtimeEnvironment, { isPreload: false, isSSR }));
119
131
  // PRELOAD the bootstrap module static dependencies as preloaded script resources
120
132
  for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
@@ -4,6 +4,10 @@ import { explodeSpecifier, getGroupName, getVersionedModuleId, normalizeVersionT
4
4
  * keeps track of preloadModules metadata
5
5
  */
6
6
  export function setPreloadModulesMeta(specifier, uri, groups, preloads) {
7
+ // Throw a very specific error if we get this back and the uri property is not set
8
+ if (!uri) {
9
+ throw Error(`Invalid Preload Module ${specifier}`);
10
+ }
7
11
  // We need to support version-less preloadModules, including version-less rootComponents.
8
12
  // Removing the "/v/version_not_provided" hack from the preloadModules specifier
9
13
  // because otherwise the loader will wait for that module that will never get defined.
@@ -41,7 +41,7 @@ export function getViewBootstrapConfigurationResource(viewInfo, config, runtimeE
41
41
  .join('\n');
42
42
  if (viewInfo.configAsSrc) {
43
43
  const viewUrl = viewInfo.url || '/';
44
- const url = getClientBootstrapConfigurationUri({ id: viewInfo.id, url: viewUrl }, runtimeEnvironment, runtimeParams, hashContent(configString));
44
+ const url = getClientBootstrapConfigurationUri({ id: viewInfo.id, url: viewUrl, query: runtimeParams.query }, runtimeEnvironment, runtimeParams, hashContent(configString));
45
45
  return {
46
46
  type: CONTENT_TYPE,
47
47
  content: configString,
@@ -79,12 +79,20 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
79
79
  if (!def) {
80
80
  throw Error('Failed to find definition of resource: ' + shimBundle);
81
81
  }
82
+ // Throw a very specific error if we get this back and the src or inline properties are not set
83
+ if (!def.inline && !def.src) {
84
+ throw Error(`Invalid Shim ${shimBundle}: ${JSON.stringify(def)}`);
85
+ }
82
86
  requiredResources.push(def);
83
87
  // Always inline the error shim script after the shim
84
88
  const errorShimDef = (await resourceRegistry.getResource({ specifier: 'lwr-error-shim.js', version }, runtimeEnvironment, runtimeParams));
85
89
  if (!errorShimDef) {
86
90
  throw Error('Failed to find definition of resource: lwr-error-shim.js');
87
91
  }
92
+ // Throw a very specific error if we get this back and the src or inline properties are not set
93
+ if (!errorShimDef.inline && !errorShimDef.src) {
94
+ throw Error(`Invalid Shim lwr-error-shim.js: ${JSON.stringify(errorShimDef)}`);
95
+ }
88
96
  requiredResources.push(errorShimDef);
89
97
  }
90
98
  // ------- Application Bootstrap module
@@ -99,6 +107,10 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
99
107
  // ADD bootstrap module uri as a script resource
100
108
  versionedSpecifier = bootstrapModuleGraph.graphs[0].specifier;
101
109
  const uri = bootstrapModuleGraph.uriMap[versionedSpecifier];
110
+ // Throw a very specific error if we get this back and the uri property is not set
111
+ if (!uri) {
112
+ throw Error(`Invalid Module Resource ${versionedSpecifier}`);
113
+ }
102
114
  moduleResources.push(getModuleResourceByUri(uri, runtimeEnvironment, { isPreload: false, isSSR }));
103
115
  // PRELOAD the bootstrap module static dependencies as preloaded script resources
104
116
  for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
package/build/es/utils.js CHANGED
@@ -140,7 +140,7 @@ export async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEn
140
140
  // If bootstrapGraph exists exposes its resources via configuration URL
141
141
  resources.push({
142
142
  type: 'application/javascript',
143
- src: getClientBootstrapConfigurationUri({ url: viewRequest.url, id: route.id }, runtimeEnvironment, runtimeParams),
143
+ src: getClientBootstrapConfigurationUri({ url: viewRequest.url, id: route.id, query: viewRequest.query }, runtimeEnvironment, runtimeParams),
144
144
  });
145
145
  }
146
146
  const mappingUrl = getMappingUriPrefix(runtimeEnvironment, runtimeParams);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.12.0-alpha.0",
7
+ "version": "0.12.0-alpha.2",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -30,17 +30,17 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "@lwrjs/app-service": "0.12.0-alpha.0",
34
- "@lwrjs/diagnostics": "0.12.0-alpha.0",
35
- "@lwrjs/instrumentation": "0.12.0-alpha.0",
36
- "@lwrjs/shared-utils": "0.12.0-alpha.0",
33
+ "@lwrjs/app-service": "0.12.0-alpha.2",
34
+ "@lwrjs/diagnostics": "0.12.0-alpha.2",
35
+ "@lwrjs/instrumentation": "0.12.0-alpha.2",
36
+ "@lwrjs/shared-utils": "0.12.0-alpha.2",
37
37
  "lru-cache": "^10.0.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@lwrjs/types": "0.12.0-alpha.0"
40
+ "@lwrjs/types": "0.12.0-alpha.2"
41
41
  },
42
42
  "engines": {
43
- "node": ">=16.0.0"
43
+ "node": ">=18.0.0"
44
44
  },
45
- "gitHead": "e79862bc238ededc3cf61f0d2c7d8120d1105a6b"
45
+ "gitHead": "586a2aa659882483af9249dc3db7fe07bc842a25"
46
46
  }