@esmx/core 3.0.0-rc.60 → 3.0.0-rc.63
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/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/dist/app.d.ts +27 -27
- package/dist/core.d.ts +274 -272
- package/dist/core.mjs +235 -232
- package/dist/pack-config.d.ts +92 -92
- 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 +31 -1
- package/dist/utils/import-map.mjs +18 -0
- package/dist/utils/import-map.test.mjs +577 -1
- 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 +320 -317
- package/src/pack-config.ts +92 -92
- package/src/render-context.ts +465 -465
- package/src/utils/cache.ts +15 -15
- package/src/utils/import-map.test.ts +713 -1
- package/src/utils/import-map.ts +53 -1
- package/src/utils/middleware.ts +19 -19
- package/src/utils/static-import-lexer.ts +18 -18
package/src/utils/cache.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
|
* });
|
|
@@ -27,24 +27,24 @@ export type CacheHandle = <T>(
|
|
|
27
27
|
) => Promise<T>;
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Create a cache handling function
|
|
31
31
|
*
|
|
32
|
-
* @param enable -
|
|
33
|
-
* @returns
|
|
32
|
+
* @param enable - Whether to enable caching functionality
|
|
33
|
+
* @returns Returns a cache handling function
|
|
34
34
|
*
|
|
35
35
|
* @description
|
|
36
|
-
*
|
|
37
|
-
*
|
|
36
|
+
* When enable is true, it creates a processing function with memory cache, the same name will only execute fetch once.
|
|
37
|
+
* When enable is false, each call will execute the fetch function and will not cache the result.
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
40
40
|
* ```ts
|
|
41
|
-
* //
|
|
41
|
+
* // Create a cache-enabled processing function
|
|
42
42
|
* const cacheEnabled = createCache(true);
|
|
43
43
|
*
|
|
44
|
-
* //
|
|
44
|
+
* // Create a cache-disabled processing function
|
|
45
45
|
* const cacheDisabled = createCache(false);
|
|
46
46
|
*
|
|
47
|
-
* //
|
|
47
|
+
* // Use the cache processing function
|
|
48
48
|
* const result = await cacheEnabled('userProfile', async () => {
|
|
49
49
|
* return await fetchUserProfile(userId);
|
|
50
50
|
* });
|