@lwrjs/resource-registry 0.10.0-alpha.9 → 0.10.1
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 +22 -1
- package/build/es/index.d.ts +4 -2
- package/build/es/index.js +26 -1
- package/package.json +5 -5
package/build/cjs/index.cjs
CHANGED
|
@@ -30,21 +30,42 @@ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
|
30
30
|
var LwrResourceRegistry = class {
|
|
31
31
|
constructor() {
|
|
32
32
|
this.providers = [];
|
|
33
|
+
this.transformers = [];
|
|
33
34
|
this.name = "lwr-resource-registry";
|
|
34
35
|
}
|
|
35
36
|
addResourceProviders(providers) {
|
|
36
37
|
this.providers.push(...providers);
|
|
37
38
|
}
|
|
39
|
+
addResourceTransformers(transformers) {
|
|
40
|
+
this.transformers.push(...transformers);
|
|
41
|
+
}
|
|
38
42
|
async getResource(resourceId, runtimeEnvironment, runtimeParams) {
|
|
39
43
|
for (const provider of this.providers) {
|
|
40
44
|
const result = await provider.getResource(resourceId, runtimeEnvironment, runtimeParams);
|
|
41
45
|
if (result) {
|
|
46
|
+
if (result.src) {
|
|
47
|
+
const defaultUri = result.src;
|
|
48
|
+
const resourceUri = {
|
|
49
|
+
artifactType: "resource",
|
|
50
|
+
uri: defaultUri,
|
|
51
|
+
immutable: runtimeEnvironment.immutableAssets,
|
|
52
|
+
entry: defaultUri
|
|
53
|
+
};
|
|
54
|
+
let uri = defaultUri;
|
|
55
|
+
for (const transformPlugin of this.transformers) {
|
|
56
|
+
const resolveUriResult = await transformPlugin.transformUri?.(resourceUri, result, runtimeEnvironment);
|
|
57
|
+
if (resolveUriResult && resolveUriResult.uri) {
|
|
58
|
+
uri = resolveUriResult.uri;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
result.src = uri;
|
|
62
|
+
}
|
|
42
63
|
return result;
|
|
43
64
|
}
|
|
44
65
|
}
|
|
45
66
|
return void 0;
|
|
46
67
|
}
|
|
47
|
-
resolveResourceUri({specifier, version = ""}, {apiVersion, format, basePath}) {
|
|
68
|
+
async resolveResourceUri({specifier, version = ""}, {apiVersion, format, basePath}) {
|
|
48
69
|
const prettyUrl = specifier;
|
|
49
70
|
const versionedSpecifier = (0, import_shared_utils.getSpecifier)({specifier, version: (0, import_shared_utils.normalizeVersionToUri)(version)});
|
|
50
71
|
return `${basePath}/${apiVersion}/resource/${format}/${encodeURIComponent(versionedSpecifier)}/${prettyUrl}`;
|
package/build/es/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { PublicResourceRegistry, ResourceDefinition, ResourceIdentifier, ResourceProvider, ResourceRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
1
|
+
import type { PublicResourceRegistry, ResourceDefinition, ResourceIdentifier, ResourceProvider, ResourceRegistry, RuntimeEnvironment, RuntimeParams, UriTransformPlugin } from '@lwrjs/types';
|
|
2
2
|
export declare class LwrResourceRegistry implements ResourceRegistry {
|
|
3
3
|
name: string;
|
|
4
4
|
providers: ResourceProvider[];
|
|
5
|
+
transformers: UriTransformPlugin[];
|
|
5
6
|
constructor();
|
|
6
7
|
addResourceProviders(providers: ResourceProvider[]): void;
|
|
8
|
+
addResourceTransformers(transformers: UriTransformPlugin[]): void;
|
|
7
9
|
getResource<T extends ResourceIdentifier, R extends RuntimeEnvironment>(resourceId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams): Promise<ResourceDefinition | undefined>;
|
|
8
|
-
resolveResourceUri<M extends ResourceIdentifier, R extends RuntimeEnvironment>({ specifier, version }: M, { apiVersion, format, basePath }: R): string
|
|
10
|
+
resolveResourceUri<M extends ResourceIdentifier, R extends RuntimeEnvironment>({ specifier, version }: M, { apiVersion, format, basePath }: R): Promise<string>;
|
|
9
11
|
getPublicApi(): PublicResourceRegistry;
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
package/build/es/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { normalizeVersionToUri, getSpecifier } from '@lwrjs/shared-utils';
|
|
|
2
2
|
export class LwrResourceRegistry {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.providers = [];
|
|
5
|
+
this.transformers = [];
|
|
5
6
|
this.name = 'lwr-resource-registry';
|
|
6
7
|
}
|
|
7
8
|
// -- Public API --------------------------------------------------------------------
|
|
@@ -9,19 +10,43 @@ export class LwrResourceRegistry {
|
|
|
9
10
|
addResourceProviders(providers) {
|
|
10
11
|
this.providers.push(...providers);
|
|
11
12
|
}
|
|
13
|
+
// add resource transformers
|
|
14
|
+
addResourceTransformers(transformers) {
|
|
15
|
+
this.transformers.push(...transformers);
|
|
16
|
+
}
|
|
12
17
|
// Retrieve a resource from the providers
|
|
13
18
|
async getResource(resourceId, runtimeEnvironment, runtimeParams) {
|
|
14
19
|
for (const provider of this.providers) {
|
|
15
20
|
// eslint-disable-next-line no-await-in-loop
|
|
16
21
|
const result = await provider.getResource(resourceId, runtimeEnvironment, runtimeParams);
|
|
17
22
|
if (result) {
|
|
23
|
+
// TODO re-work this pattern to better match bundles / assets. Resources resolve the definition and than read the src attribute so transforming here.
|
|
24
|
+
if (result.src) {
|
|
25
|
+
const defaultUri = result.src;
|
|
26
|
+
const resourceUri = {
|
|
27
|
+
artifactType: 'resource',
|
|
28
|
+
uri: defaultUri,
|
|
29
|
+
immutable: runtimeEnvironment.immutableAssets,
|
|
30
|
+
entry: defaultUri,
|
|
31
|
+
};
|
|
32
|
+
// Perform any transforms
|
|
33
|
+
let uri = defaultUri;
|
|
34
|
+
for (const transformPlugin of this.transformers) {
|
|
35
|
+
// eslint-disable-next-line no-await-in-loop
|
|
36
|
+
const resolveUriResult = await transformPlugin.transformUri?.(resourceUri, result, runtimeEnvironment);
|
|
37
|
+
if (resolveUriResult && resolveUriResult.uri) {
|
|
38
|
+
uri = resolveUriResult.uri;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
result.src = uri;
|
|
42
|
+
}
|
|
18
43
|
return result;
|
|
19
44
|
}
|
|
20
45
|
}
|
|
21
46
|
return undefined;
|
|
22
47
|
}
|
|
23
48
|
// Given a resource and environment, return a resource URI
|
|
24
|
-
resolveResourceUri({ specifier, version = '' }, { apiVersion, format, basePath }) {
|
|
49
|
+
async resolveResourceUri({ specifier, version = '' }, { apiVersion, format, basePath }) {
|
|
25
50
|
// re-add the specifier at the end for a URL with the right extension
|
|
26
51
|
const prettyUrl = specifier;
|
|
27
52
|
const versionedSpecifier = getSpecifier({ specifier, version: normalizeVersionToUri(version) });
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.10.
|
|
7
|
+
"version": "0.10.1",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/shared-utils": "0.10.
|
|
33
|
+
"@lwrjs/shared-utils": "0.10.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@lwrjs/types": "0.10.
|
|
36
|
+
"@lwrjs/types": "0.10.1"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": ">=16.0.0
|
|
39
|
+
"node": ">=16.0.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "7251846486eb5a1f60bc418fac7967effea57898"
|
|
42
42
|
}
|