@esmx/core 3.0.0-rc.59 → 3.0.0-rc.62
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/dist/app.d.ts +27 -27
- package/dist/core.d.ts +274 -272
- package/dist/core.mjs +237 -235
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +0 -6
- package/dist/manifest-json.d.ts +8 -21
- package/dist/module-config.d.ts +39 -144
- package/dist/module-config.mjs +145 -57
- package/dist/module-config.test.mjs +620 -509
- package/dist/pack-config.d.ts +94 -94
- package/dist/render-context.d.ts +465 -465
- package/dist/render-context.mjs +338 -338
- package/dist/utils/cache.d.ts +15 -15
- package/dist/utils/import-map.d.ts +9 -5
- package/dist/utils/import-map.mjs +36 -23
- package/dist/utils/import-map.test.mjs +1139 -103
- package/dist/utils/middleware.d.ts +19 -19
- package/dist/utils/static-import-lexer.d.ts +12 -12
- package/dist/utils/static-import-lexer.mjs +1 -1
- package/package.json +3 -3
- package/src/app.ts +34 -34
- package/src/core.ts +323 -320
- package/src/index.ts +14 -9
- package/src/manifest-json.ts +8 -22
- package/src/module-config.test.ts +636 -637
- package/src/module-config.ts +242 -257
- package/src/pack-config.ts +94 -94
- package/src/render-context.ts +465 -465
- package/src/utils/cache.ts +15 -15
- package/src/utils/import-map.test.ts +1207 -110
- package/src/utils/import-map.ts +63 -29
- package/src/utils/middleware.ts +19 -19
- package/src/utils/static-import-lexer.ts +18 -18
package/dist/utils/cache.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Type definition for cache handling function
|
|
3
3
|
*
|
|
4
|
-
* @template T -
|
|
5
|
-
* @param name -
|
|
6
|
-
* @param fetch -
|
|
7
|
-
* @returns
|
|
4
|
+
* @template T - Type of cached data
|
|
5
|
+
* @param name - Unique identifier for the cache item
|
|
6
|
+
* @param fetch - Asynchronous function to fetch data
|
|
7
|
+
* @returns Returns cached data or newly fetched data
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```ts
|
|
11
11
|
* const cache = createCache(true);
|
|
12
12
|
*
|
|
13
|
-
* //
|
|
13
|
+
* // First call will execute the fetch function
|
|
14
14
|
* const data1 = await cache('key', async () => {
|
|
15
15
|
* return await fetchSomeData();
|
|
16
16
|
* });
|
|
17
17
|
*
|
|
18
|
-
* //
|
|
18
|
+
* // Second call will directly return the cached result
|
|
19
19
|
* const data2 = await cache('key', async () => {
|
|
20
20
|
* return await fetchSomeData();
|
|
21
21
|
* });
|
|
@@ -23,24 +23,24 @@
|
|
|
23
23
|
*/
|
|
24
24
|
export type CacheHandle = <T>(name: string, fetch: () => Promise<T>) => Promise<T>;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Create a cache handling function
|
|
27
27
|
*
|
|
28
|
-
* @param enable -
|
|
29
|
-
* @returns
|
|
28
|
+
* @param enable - Whether to enable caching functionality
|
|
29
|
+
* @returns Returns a cache handling function
|
|
30
30
|
*
|
|
31
31
|
* @description
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* When enable is true, it creates a processing function with memory cache, the same name will only execute fetch once.
|
|
33
|
+
* When enable is false, each call will execute the fetch function and will not cache the result.
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
36
|
* ```ts
|
|
37
|
-
* //
|
|
37
|
+
* // Create a cache-enabled processing function
|
|
38
38
|
* const cacheEnabled = createCache(true);
|
|
39
39
|
*
|
|
40
|
-
* //
|
|
40
|
+
* // Create a cache-disabled processing function
|
|
41
41
|
* const cacheDisabled = createCache(false);
|
|
42
42
|
*
|
|
43
|
-
* //
|
|
43
|
+
* // Use the cache processing function
|
|
44
44
|
* const result = await cacheEnabled('userProfile', async () => {
|
|
45
45
|
* return await fetchUserProfile(userId);
|
|
46
46
|
* });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ImportMap } from '@esmx/import';
|
|
1
|
+
import type { ImportMap, ScopesMap, SpecifierMap } from '@esmx/import';
|
|
2
2
|
export interface ImportMapManifest {
|
|
3
3
|
name: string;
|
|
4
4
|
imports: Record<string, string>;
|
|
@@ -6,11 +6,15 @@ export interface ImportMapManifest {
|
|
|
6
6
|
name: string;
|
|
7
7
|
file: string;
|
|
8
8
|
identifier: string;
|
|
9
|
-
|
|
9
|
+
pkg: boolean;
|
|
10
10
|
}>;
|
|
11
|
+
scopes: Record<string, Record<string, string>>;
|
|
11
12
|
}
|
|
12
|
-
export
|
|
13
|
+
export interface GetImportMapOptions {
|
|
13
14
|
manifests: readonly ImportMapManifest[];
|
|
14
|
-
getScope: (name: string) => string;
|
|
15
|
+
getScope: (name: string, scope: string) => string;
|
|
15
16
|
getFile: (name: string, file: string) => string;
|
|
16
|
-
}
|
|
17
|
+
}
|
|
18
|
+
export declare function buildImportsMap(manifests: readonly ImportMapManifest[], getFile: (name: string, file: string) => string): SpecifierMap;
|
|
19
|
+
export declare function buildScopesMap(imports: SpecifierMap, manifests: readonly ImportMapManifest[], getScope: (name: string, scope: string) => string): ScopesMap;
|
|
20
|
+
export declare function getImportMap({ manifests, getFile, getScope }: GetImportMapOptions): ImportMap;
|
|
@@ -1,35 +1,48 @@
|
|
|
1
1
|
import { pathWithoutIndex } from "./path-without-index.mjs";
|
|
2
|
-
export function
|
|
3
|
-
manifests,
|
|
4
|
-
getFile,
|
|
5
|
-
getScope
|
|
6
|
-
}) {
|
|
2
|
+
export function buildImportsMap(manifests, getFile) {
|
|
7
3
|
const imports = {};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const scopeImports = {};
|
|
11
|
-
Object.entries(manifest.exports).forEach(([key, exportItem]) => {
|
|
12
|
-
if (typeof exportItem === "string") {
|
|
13
|
-
throw new Error(
|
|
14
|
-
`Detected incompatible legacy manifest format in ${manifest.name}. Please upgrade your ESMX dependencies first, then rebuild and redeploy your service.`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
4
|
+
manifests.forEach((manifest) => {
|
|
5
|
+
Object.entries(manifest.exports).forEach(([, exportItem]) => {
|
|
17
6
|
const file = getFile(manifest.name, exportItem.file);
|
|
18
7
|
imports[exportItem.identifier] = file;
|
|
19
|
-
if (!exportItem.rewrite) {
|
|
20
|
-
scopeImports[exportItem.name] = file;
|
|
21
|
-
}
|
|
22
8
|
});
|
|
23
|
-
if (Object.keys(scopeImports).length || Object.keys(imports).length) {
|
|
24
|
-
scopes[getScope(manifest.name)] = scopeImports;
|
|
25
|
-
}
|
|
26
9
|
});
|
|
27
|
-
|
|
28
|
-
Object.values(manifests).forEach((manifest) => {
|
|
10
|
+
manifests.forEach((manifest) => {
|
|
29
11
|
Object.entries(manifest.imports).forEach(([name, identifier]) => {
|
|
30
|
-
|
|
12
|
+
const fullName = `${manifest.name}/${name}`;
|
|
13
|
+
imports[fullName] = imports[identifier] ?? identifier;
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
pathWithoutIndex(imports);
|
|
17
|
+
return imports;
|
|
18
|
+
}
|
|
19
|
+
export function buildScopesMap(imports, manifests, getScope) {
|
|
20
|
+
const scopes = {};
|
|
21
|
+
manifests.forEach((manifest) => {
|
|
22
|
+
if (!manifest.scopes) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
Object.entries(manifest.scopes).forEach(([scopeName, specifierMap]) => {
|
|
26
|
+
const scopedImports = {};
|
|
27
|
+
Object.entries(specifierMap).forEach(
|
|
28
|
+
([specifierName, identifier]) => {
|
|
29
|
+
scopedImports[specifierName] = imports[identifier] ?? identifier;
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
const scopePath = imports[`${manifest.name}/${scopeName}`] ?? `/${scopeName}`;
|
|
33
|
+
const scopeKey = getScope(manifest.name, scopePath);
|
|
34
|
+
scopes[scopeKey] = scopedImports;
|
|
31
35
|
});
|
|
32
36
|
});
|
|
37
|
+
return scopes;
|
|
38
|
+
}
|
|
39
|
+
export function getImportMap({
|
|
40
|
+
manifests,
|
|
41
|
+
getFile,
|
|
42
|
+
getScope
|
|
43
|
+
}) {
|
|
44
|
+
const imports = buildImportsMap(manifests, getFile);
|
|
45
|
+
const scopes = buildScopesMap(imports, manifests, getScope);
|
|
33
46
|
return {
|
|
34
47
|
imports,
|
|
35
48
|
scopes
|