webpack 5.99.5 → 5.99.6
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 +1 -1
- package/lib/APIPlugin.js +2 -2
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +12 -9
- package/lib/Compilation.js +36 -27
- package/lib/Compiler.js +4 -3
- package/lib/ContextModule.js +2 -1
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/Module.js +10 -2
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +15 -10
- package/lib/NormalModule.js +1 -1
- package/lib/PrefetchPlugin.js +1 -1
- package/lib/RecordIdsPlugin.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +1 -1
- package/lib/Template.js +1 -1
- package/lib/WebpackOptionsApply.js +17 -2
- package/lib/buildChunkGraph.js +7 -2
- package/lib/cache/IdleFileCachePlugin.js +1 -1
- package/lib/cache/MemoryCachePlugin.js +2 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +3 -2
- package/lib/cache/PackFileCacheStrategy.js +13 -21
- package/lib/cache/ResolverCachePlugin.js +14 -16
- package/lib/cli.js +3 -3
- package/lib/config/defaults.js +2 -2
- package/lib/config/target.js +6 -6
- package/lib/css/CssParser.js +1 -1
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/CssIcssImportDependency.js +3 -2
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LocalModulesHelpers.js +1 -1
- package/lib/dependencies/RequireResolveDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingPlugin.js +20 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/NamedChunkIdsPlugin.js +2 -2
- package/lib/ids/NamedModuleIdsPlugin.js +2 -2
- package/lib/index.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/JavascriptParser.js +41 -37
- package/lib/library/EnableLibraryPlugin.js +15 -2
- package/lib/library/ModuleLibraryPlugin.js +6 -1
- package/lib/logging/createConsoleLogger.js +0 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
- package/lib/node/NodeTemplatePlugin.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/SplitChunksPlugin.js +2 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
- package/lib/serialization/BinaryMiddleware.js +22 -38
- package/lib/serialization/FileMiddleware.js +29 -33
- package/lib/serialization/ObjectMiddleware.js +29 -30
- package/lib/serialization/Serializer.js +29 -18
- package/lib/serialization/SerializerMiddleware.js +105 -72
- package/lib/serialization/SingleItemMiddleware.js +4 -5
- package/lib/stats/DefaultStatsFactoryPlugin.js +39 -24
- package/lib/stats/DefaultStatsPrinterPlugin.js +267 -80
- package/lib/stats/StatsFactory.js +47 -10
- package/lib/stats/StatsPrinter.js +52 -31
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/TupleQueue.js +9 -7
- package/lib/util/TupleSet.js +37 -18
- package/lib/util/WeakTupleMap.js +50 -37
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +1 -1
- package/lib/util/createHash.js +1 -1
- package/lib/util/fs.js +1 -1
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/runtime.js +1 -0
- package/lib/util/serialization.js +50 -42
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/web/FetchCompileWasmPlugin.js +2 -2
- package/lib/webpack.js +1 -1
- package/package.json +1 -1
- package/types.d.ts +125 -73
@@ -16,18 +16,14 @@ const RegExpObjectSerializer = require("./RegExpObjectSerializer");
|
|
16
16
|
const SerializerMiddleware = require("./SerializerMiddleware");
|
17
17
|
const SetObjectSerializer = require("./SetObjectSerializer");
|
18
18
|
|
19
|
+
/** @typedef {import("../logging/Logger").Logger} Logger */
|
19
20
|
/** @typedef {typeof import("../util/Hash")} Hash */
|
20
|
-
/** @typedef {import("./SerializerMiddleware").
|
21
|
+
/** @typedef {import("./SerializerMiddleware").LazyOptions} LazyOptions */
|
21
22
|
/** @typedef {import("./types").ComplexSerializableType} ComplexSerializableType */
|
22
23
|
/** @typedef {import("./types").PrimitiveSerializableType} PrimitiveSerializableType */
|
23
24
|
|
24
25
|
/** @typedef {new (...params: EXPECTED_ANY[]) => EXPECTED_ANY} Constructor */
|
25
26
|
|
26
|
-
/**
|
27
|
-
* @template LAZY_RESULT
|
28
|
-
* @typedef {import("./SerializerMiddleware").LazyFunction<LAZY_RESULT>} LazyFunction
|
29
|
-
*/
|
30
|
-
|
31
27
|
/*
|
32
28
|
|
33
29
|
Format:
|
@@ -59,27 +55,29 @@ Technically any value can be used.
|
|
59
55
|
* @property {number} objectTypeLookupSize
|
60
56
|
* @property {number} currentPosTypeLookup
|
61
57
|
*/
|
58
|
+
/** @typedef {TODO} Value */
|
59
|
+
/** @typedef {EXPECTED_OBJECT | string} ReferenceableItem */
|
62
60
|
|
63
61
|
/**
|
64
62
|
* @typedef {object} ObjectSerializerContext
|
65
|
-
* @property {(value:
|
66
|
-
* @property {(value:
|
63
|
+
* @property {(value: Value) => void} write
|
64
|
+
* @property {(value: ReferenceableItem) => void} setCircularReference
|
67
65
|
* @property {() => ObjectSerializerSnapshot} snapshot
|
68
66
|
* @property {(snapshot: ObjectSerializerSnapshot) => void} rollback
|
69
|
-
* @property {((item:
|
70
|
-
* @property {((item:
|
67
|
+
* @property {((item: Value | (() => Value)) => void)=} writeLazy
|
68
|
+
* @property {((item: (Value | (() => Value)), obj: LazyOptions | undefined) => import("./SerializerMiddleware").LazyFunction<EXPECTED_ANY, EXPECTED_ANY, EXPECTED_ANY, LazyOptions>)=} writeSeparate
|
71
69
|
*/
|
72
70
|
|
73
71
|
/**
|
74
72
|
* @typedef {object} ObjectDeserializerContext
|
75
|
-
* @property {() =>
|
76
|
-
* @property {(value:
|
73
|
+
* @property {() => Value} read
|
74
|
+
* @property {(value: ReferenceableItem) => void} setCircularReference
|
77
75
|
*/
|
78
76
|
|
79
77
|
/**
|
80
78
|
* @typedef {object} ObjectSerializer
|
81
|
-
* @property {(value:
|
82
|
-
* @property {(context: ObjectDeserializerContext) =>
|
79
|
+
* @property {(value: Value, context: ObjectSerializerContext) => void} serialize
|
80
|
+
* @property {(context: ObjectDeserializerContext) => Value} deserialize
|
83
81
|
*/
|
84
82
|
|
85
83
|
/**
|
@@ -141,8 +139,6 @@ const loadedRequests = new Set();
|
|
141
139
|
|
142
140
|
const NOT_SERIALIZABLE = {};
|
143
141
|
|
144
|
-
/** @typedef {TODO} Item */
|
145
|
-
|
146
142
|
const jsTypes = new Map();
|
147
143
|
jsTypes.set(Object, new PlainObjectSerializer());
|
148
144
|
jsTypes.set(Array, new ArraySerializer());
|
@@ -195,10 +191,12 @@ for (const { request, name, serializer } of serializers.values()) {
|
|
195
191
|
/** @type {Map<RegExp, (request: string) => boolean>} */
|
196
192
|
const loaders = new Map();
|
197
193
|
|
194
|
+
/** @typedef {ComplexSerializableType[]} DeserializedType */
|
195
|
+
/** @typedef {PrimitiveSerializableType[]} SerializedType */
|
196
|
+
/** @typedef {{ logger: Logger }} Context */
|
197
|
+
|
198
198
|
/**
|
199
|
-
* @
|
200
|
-
* @typedef {PrimitiveSerializableType[]} SerializedType
|
201
|
-
* @extends {SerializerMiddleware<DeserializedType, SerializedType>}
|
199
|
+
* @extends {SerializerMiddleware<DeserializedType, SerializedType, Context>}
|
202
200
|
*/
|
203
201
|
class ObjectMiddleware extends SerializerMiddleware {
|
204
202
|
/**
|
@@ -266,7 +264,7 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
266
264
|
}
|
267
265
|
|
268
266
|
/**
|
269
|
-
* @param {
|
267
|
+
* @param {Constructor} object for serialization
|
270
268
|
* @returns {SerializerConfigWithSerializer} Serializer config
|
271
269
|
*/
|
272
270
|
static getSerializerFor(object) {
|
@@ -324,13 +322,13 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
324
322
|
* @returns {SerializedType | Promise<SerializedType> | null} serialized data
|
325
323
|
*/
|
326
324
|
serialize(data, context) {
|
327
|
-
/** @type {
|
325
|
+
/** @type {Value[]} */
|
328
326
|
let result = [CURRENT_VERSION];
|
329
327
|
let currentPos = 0;
|
330
|
-
/** @type {Map<
|
328
|
+
/** @type {Map<ReferenceableItem, number>} */
|
331
329
|
let referenceable = new Map();
|
332
330
|
/**
|
333
|
-
* @param {
|
331
|
+
* @param {ReferenceableItem} item referenceable item
|
334
332
|
*/
|
335
333
|
const addReferenceable = item => {
|
336
334
|
referenceable.set(item, currentPos++);
|
@@ -401,7 +399,7 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
401
399
|
let objectTypeLookup = new Map();
|
402
400
|
const cycleStack = new Set();
|
403
401
|
/**
|
404
|
-
* @param {
|
402
|
+
* @param {Value} item item to stack
|
405
403
|
* @returns {string} stack
|
406
404
|
*/
|
407
405
|
const stackToString = item => {
|
@@ -497,7 +495,7 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
497
495
|
};
|
498
496
|
this.extendContext(ctx);
|
499
497
|
/**
|
500
|
-
* @param {
|
498
|
+
* @param {Value} item item to serialize
|
501
499
|
*/
|
502
500
|
const process = item => {
|
503
501
|
if (Buffer.isBuffer(item)) {
|
@@ -587,9 +585,11 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
587
585
|
} else if (typeof item === "function") {
|
588
586
|
if (!SerializerMiddleware.isLazy(item))
|
589
587
|
throw new Error(`Unexpected function ${item}`);
|
590
|
-
|
588
|
+
|
589
|
+
/** @type {SerializedType | undefined} */
|
591
590
|
const serializedData =
|
592
591
|
SerializerMiddleware.getLazySerializedValue(item);
|
592
|
+
|
593
593
|
if (serializedData !== undefined) {
|
594
594
|
if (typeof serializedData === "function") {
|
595
595
|
result.push(serializedData);
|
@@ -655,10 +655,10 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
655
655
|
throw new Error("Version mismatch, serializer changed");
|
656
656
|
|
657
657
|
let currentPos = 0;
|
658
|
-
/** @type {
|
658
|
+
/** @type {ReferenceableItem[]} */
|
659
659
|
let referenceable = [];
|
660
660
|
/**
|
661
|
-
* @param {
|
661
|
+
* @param {Value} item referenceable item
|
662
662
|
*/
|
663
663
|
const addReferenceable = item => {
|
664
664
|
referenceable.push(item);
|
@@ -791,8 +791,7 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
791
791
|
return item;
|
792
792
|
} else if (typeof item === "function") {
|
793
793
|
return SerializerMiddleware.deserializeLazy(
|
794
|
-
|
795
|
-
(item),
|
794
|
+
item,
|
796
795
|
data =>
|
797
796
|
/** @type {[DeserializedType]} */
|
798
797
|
(this.deserialize(data, context))[0]
|
@@ -4,17 +4,20 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
/** @typedef {import("./SerializerMiddleware").Context} Context */
|
8
|
-
|
9
7
|
/**
|
10
|
-
* @template T, K
|
11
|
-
* @typedef {import("./SerializerMiddleware")<T, K>} SerializerMiddleware
|
8
|
+
* @template T, K, C
|
9
|
+
* @typedef {import("./SerializerMiddleware")<T, K, C>} SerializerMiddleware
|
12
10
|
*/
|
13
11
|
|
12
|
+
/**
|
13
|
+
* @template DeserializedValue
|
14
|
+
* @template SerializedValue
|
15
|
+
* @template Context
|
16
|
+
*/
|
14
17
|
class Serializer {
|
15
18
|
/**
|
16
|
-
* @param {SerializerMiddleware<
|
17
|
-
* @param {Context}
|
19
|
+
* @param {SerializerMiddleware<EXPECTED_ANY, EXPECTED_ANY, EXPECTED_ANY>[]} middlewares serializer middlewares
|
20
|
+
* @param {Context=} context context
|
18
21
|
*/
|
19
22
|
constructor(middlewares, context) {
|
20
23
|
this.serializeMiddlewares = middlewares.slice();
|
@@ -23,17 +26,22 @@ class Serializer {
|
|
23
26
|
}
|
24
27
|
|
25
28
|
/**
|
26
|
-
* @
|
27
|
-
* @param {
|
28
|
-
* @
|
29
|
+
* @template ExtendedContext
|
30
|
+
* @param {DeserializedValue | Promise<DeserializedValue>} obj object
|
31
|
+
* @param {Context & ExtendedContext} context context object
|
32
|
+
* @returns {Promise<SerializedValue>} result
|
29
33
|
*/
|
30
34
|
serialize(obj, context) {
|
31
35
|
const ctx = { ...context, ...this.context };
|
32
36
|
let current = obj;
|
33
37
|
for (const middleware of this.serializeMiddlewares) {
|
34
|
-
if (
|
38
|
+
if (
|
39
|
+
current &&
|
40
|
+
typeof (/** @type {Promise<DeserializedValue>} */ (current).then) ===
|
41
|
+
"function"
|
42
|
+
) {
|
35
43
|
current =
|
36
|
-
/** @type {Promise<
|
44
|
+
/** @type {Promise<DeserializedValue>} */
|
37
45
|
(current).then(data => data && middleware.serialize(data, ctx));
|
38
46
|
} else if (current) {
|
39
47
|
try {
|
@@ -43,26 +51,29 @@ class Serializer {
|
|
43
51
|
}
|
44
52
|
} else break;
|
45
53
|
}
|
46
|
-
return current;
|
54
|
+
return /** @type {Promise<SerializedValue>} */ (current);
|
47
55
|
}
|
48
56
|
|
49
57
|
/**
|
50
|
-
* @
|
51
|
-
* @param {
|
52
|
-
* @
|
58
|
+
* @template ExtendedContext
|
59
|
+
* @param {SerializedValue | Promise<SerializedValue>} value value
|
60
|
+
* @param {Context & ExtendedContext} context object
|
61
|
+
* @returns {Promise<DeserializedValue>} result
|
53
62
|
*/
|
54
63
|
deserialize(value, context) {
|
55
64
|
const ctx = { ...context, ...this.context };
|
56
65
|
let current = value;
|
57
66
|
for (const middleware of this.deserializeMiddlewares) {
|
58
67
|
current =
|
59
|
-
current &&
|
60
|
-
|
68
|
+
current &&
|
69
|
+
typeof (/** @type {Promise<SerializedValue>} */ (current).then) ===
|
70
|
+
"function"
|
71
|
+
? /** @type {Promise<SerializedValue>} */ (current).then(data =>
|
61
72
|
middleware.deserialize(data, ctx)
|
62
73
|
)
|
63
74
|
: middleware.deserialize(current, ctx);
|
64
75
|
}
|
65
|
-
return current;
|
76
|
+
return /** @type {Promise<DeserializedValue>} */ (current);
|
66
77
|
}
|
67
78
|
}
|
68
79
|
|
@@ -9,23 +9,21 @@ const memoize = require("../util/memoize");
|
|
9
9
|
const LAZY_TARGET = Symbol("lazy serialization target");
|
10
10
|
const LAZY_SERIALIZED_VALUE = Symbol("lazy serialization data");
|
11
11
|
|
12
|
-
/** @typedef {
|
12
|
+
/** @typedef {SerializerMiddleware<EXPECTED_ANY, EXPECTED_ANY, Record<string, EXPECTED_ANY>>} LazyTarget */
|
13
|
+
/** @typedef {Record<string, EXPECTED_ANY>} LazyOptions */
|
13
14
|
|
14
15
|
/**
|
15
|
-
* @template
|
16
|
-
* @
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
/**
|
22
|
-
* @template LazyResult
|
23
|
-
* @typedef {InternalLazyFunction<LazyResult> & { [LAZY_TARGET]: TODO, [LAZY_SERIALIZED_VALUE]?: TODO, options: LazyOptions }} LazyFunction
|
16
|
+
* @template InputValue
|
17
|
+
* @template OutputValue
|
18
|
+
* @template {LazyTarget} InternalLazyTarget
|
19
|
+
* @template {LazyOptions | undefined} InternalLazyOptions
|
20
|
+
* @typedef {(() => InputValue | Promise<InputValue>) & Partial<{ [LAZY_TARGET]: InternalLazyTarget, options: InternalLazyOptions, [LAZY_SERIALIZED_VALUE]?: OutputValue | LazyFunction<OutputValue, InputValue, InternalLazyTarget, InternalLazyOptions> | undefined }>} LazyFunction
|
24
21
|
*/
|
25
22
|
|
26
23
|
/**
|
27
24
|
* @template DeserializedType
|
28
25
|
* @template SerializedType
|
26
|
+
* @template Context
|
29
27
|
*/
|
30
28
|
class SerializerMiddleware {
|
31
29
|
/* istanbul ignore next */
|
@@ -53,17 +51,25 @@ class SerializerMiddleware {
|
|
53
51
|
}
|
54
52
|
|
55
53
|
/**
|
56
|
-
* @template
|
57
|
-
* @
|
58
|
-
* @
|
59
|
-
* @
|
60
|
-
* @param {
|
61
|
-
* @
|
54
|
+
* @template TLazyInputValue
|
55
|
+
* @template TLazyOutputValue
|
56
|
+
* @template {LazyTarget} TLazyTarget
|
57
|
+
* @template {LazyOptions | undefined} TLazyOptions
|
58
|
+
* @param {TLazyInputValue | (() => TLazyInputValue)} value contained value or function to value
|
59
|
+
* @param {TLazyTarget} target target middleware
|
60
|
+
* @param {TLazyOptions=} options lazy options
|
61
|
+
* @param {TLazyOutputValue=} serializedValue serialized value
|
62
|
+
* @returns {LazyFunction<TLazyInputValue, TLazyOutputValue, TLazyTarget, TLazyOptions>} lazy function
|
62
63
|
*/
|
63
|
-
static createLazy(
|
64
|
+
static createLazy(
|
65
|
+
value,
|
66
|
+
target,
|
67
|
+
options = /** @type {TLazyOptions} */ ({}),
|
68
|
+
serializedValue = undefined
|
69
|
+
) {
|
64
70
|
if (SerializerMiddleware.isLazy(value, target)) return value;
|
65
71
|
const fn =
|
66
|
-
/** @type {LazyFunction<
|
72
|
+
/** @type {LazyFunction<TLazyInputValue, TLazyOutputValue, TLazyTarget, TLazyOptions>} */
|
67
73
|
(typeof value === "function" ? value : () => value);
|
68
74
|
fn[LAZY_TARGET] = target;
|
69
75
|
fn.options = options;
|
@@ -72,9 +78,10 @@ class SerializerMiddleware {
|
|
72
78
|
}
|
73
79
|
|
74
80
|
/**
|
81
|
+
* @template {LazyTarget} TLazyTarget
|
75
82
|
* @param {EXPECTED_ANY} fn lazy function
|
76
|
-
* @param {
|
77
|
-
* @returns {
|
83
|
+
* @param {TLazyTarget=} target target middleware
|
84
|
+
* @returns {fn is LazyFunction<EXPECTED_ANY, EXPECTED_ANY, TLazyTarget, EXPECTED_ANY>} true, when fn is a lazy function (optionally of that target)
|
78
85
|
*/
|
79
86
|
static isLazy(fn, target) {
|
80
87
|
if (typeof fn !== "function") return false;
|
@@ -83,19 +90,26 @@ class SerializerMiddleware {
|
|
83
90
|
}
|
84
91
|
|
85
92
|
/**
|
86
|
-
* @template
|
87
|
-
* @
|
93
|
+
* @template TLazyInputValue
|
94
|
+
* @template TLazyOutputValue
|
95
|
+
* @template {LazyTarget} TLazyTarget
|
96
|
+
* @template {Record<string, EXPECTED_ANY>} TLazyOptions
|
97
|
+
* @template TLazySerializedValue
|
98
|
+
* @param {LazyFunction<TLazyInputValue, TLazyOutputValue, TLazyTarget, TLazyOptions>} fn lazy function
|
88
99
|
* @returns {LazyOptions | undefined} options
|
89
100
|
*/
|
90
101
|
static getLazyOptions(fn) {
|
91
102
|
if (typeof fn !== "function") return;
|
92
|
-
return
|
103
|
+
return fn.options;
|
93
104
|
}
|
94
105
|
|
95
106
|
/**
|
96
|
-
* @template
|
97
|
-
* @
|
98
|
-
* @
|
107
|
+
* @template TLazyInputValue
|
108
|
+
* @template TLazyOutputValue
|
109
|
+
* @template {LazyTarget} TLazyTarget
|
110
|
+
* @template {LazyOptions} TLazyOptions
|
111
|
+
* @param {LazyFunction<TLazyInputValue, TLazyOutputValue, TLazyTarget, TLazyOptions> | EXPECTED_ANY} fn lazy function
|
112
|
+
* @returns {TLazyOutputValue | undefined} serialized value
|
99
113
|
*/
|
100
114
|
static getLazySerializedValue(fn) {
|
101
115
|
if (typeof fn !== "function") return;
|
@@ -103,9 +117,12 @@ class SerializerMiddleware {
|
|
103
117
|
}
|
104
118
|
|
105
119
|
/**
|
106
|
-
* @template
|
107
|
-
* @
|
108
|
-
* @
|
120
|
+
* @template TLazyInputValue
|
121
|
+
* @template TLazyOutputValue
|
122
|
+
* @template {LazyTarget} TLazyTarget
|
123
|
+
* @template {LazyOptions} TLazyOptions
|
124
|
+
* @param {LazyFunction<TLazyInputValue, TLazyOutputValue, LazyTarget, LazyOptions>} fn lazy function
|
125
|
+
* @param {TLazyOutputValue} value serialized value
|
109
126
|
* @returns {void}
|
110
127
|
*/
|
111
128
|
static setLazySerializedValue(fn, value) {
|
@@ -113,27 +130,33 @@ class SerializerMiddleware {
|
|
113
130
|
}
|
114
131
|
|
115
132
|
/**
|
116
|
-
* @template
|
117
|
-
* @
|
118
|
-
* @
|
119
|
-
* @
|
133
|
+
* @template TLazyInputValue DeserializedValue
|
134
|
+
* @template TLazyOutputValue SerializedValue
|
135
|
+
* @template {LazyTarget} TLazyTarget
|
136
|
+
* @template {LazyOptions | undefined} TLazyOptions
|
137
|
+
* @param {LazyFunction<TLazyInputValue, TLazyOutputValue, TLazyTarget, TLazyOptions>} lazy lazy function
|
138
|
+
* @param {(value: TLazyInputValue) => TLazyOutputValue} serialize serialize function
|
139
|
+
* @returns {LazyFunction<TLazyOutputValue, TLazyInputValue, TLazyTarget, TLazyOptions>} new lazy
|
120
140
|
*/
|
121
141
|
static serializeLazy(lazy, serialize) {
|
122
|
-
const fn =
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
r
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
142
|
+
const fn =
|
143
|
+
/** @type {LazyFunction<TLazyOutputValue, TLazyInputValue, TLazyTarget, TLazyOptions>} */
|
144
|
+
(
|
145
|
+
memoize(() => {
|
146
|
+
const r = lazy();
|
147
|
+
if (
|
148
|
+
r &&
|
149
|
+
typeof (/** @type {Promise<TLazyInputValue>} */ (r).then) ===
|
150
|
+
"function"
|
151
|
+
) {
|
152
|
+
return (
|
153
|
+
/** @type {Promise<TLazyInputValue>} */
|
154
|
+
(r).then(data => data && serialize(data))
|
155
|
+
);
|
156
|
+
}
|
157
|
+
return serialize(/** @type {TLazyInputValue} */ (r));
|
158
|
+
})
|
159
|
+
);
|
137
160
|
fn[LAZY_TARGET] = lazy[LAZY_TARGET];
|
138
161
|
fn.options = lazy.options;
|
139
162
|
lazy[LAZY_SERIALIZED_VALUE] = fn;
|
@@ -141,27 +164,33 @@ class SerializerMiddleware {
|
|
141
164
|
}
|
142
165
|
|
143
166
|
/**
|
144
|
-
* @template
|
145
|
-
* @
|
146
|
-
* @
|
147
|
-
* @
|
167
|
+
* @template TLazyInputValue SerializedValue
|
168
|
+
* @template TLazyOutputValue DeserializedValue
|
169
|
+
* @template SerializedValue
|
170
|
+
* @template {LazyTarget} TLazyTarget
|
171
|
+
* @template {LazyOptions | undefined} TLazyOptions
|
172
|
+
* @param {LazyFunction<TLazyInputValue, TLazyOutputValue, TLazyTarget, TLazyOptions>} lazy lazy function
|
173
|
+
* @param {(data: TLazyInputValue) => TLazyOutputValue} deserialize deserialize function
|
174
|
+
* @returns {LazyFunction<TLazyOutputValue, TLazyInputValue, TLazyTarget, TLazyOptions>} new lazy
|
148
175
|
*/
|
149
176
|
static deserializeLazy(lazy, deserialize) {
|
150
|
-
const fn =
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
177
|
+
const fn =
|
178
|
+
/** @type {LazyFunction<TLazyOutputValue, TLazyInputValue, TLazyTarget, TLazyOptions>} */ (
|
179
|
+
memoize(() => {
|
180
|
+
const r = lazy();
|
181
|
+
if (
|
182
|
+
r &&
|
183
|
+
typeof (/** @type {Promise<TLazyInputValue>} */ (r).then) ===
|
184
|
+
"function"
|
185
|
+
) {
|
186
|
+
return (
|
187
|
+
/** @type {Promise<TLazyInputValue>} */
|
188
|
+
(r).then(data => deserialize(data))
|
189
|
+
);
|
190
|
+
}
|
191
|
+
return deserialize(/** @type {TLazyInputValue} */ (r));
|
192
|
+
})
|
193
|
+
);
|
165
194
|
fn[LAZY_TARGET] = lazy[LAZY_TARGET];
|
166
195
|
fn.options = lazy.options;
|
167
196
|
fn[LAZY_SERIALIZED_VALUE] = lazy;
|
@@ -169,20 +198,24 @@ class SerializerMiddleware {
|
|
169
198
|
}
|
170
199
|
|
171
200
|
/**
|
172
|
-
* @template
|
173
|
-
* @
|
174
|
-
* @
|
201
|
+
* @template TLazyInputValue
|
202
|
+
* @template TLazyOutputValue
|
203
|
+
* @template {LazyTarget} TLazyTarget
|
204
|
+
* @template {LazyOptions} TLazyOptions
|
205
|
+
* @param {LazyFunction<TLazyInputValue | TLazyOutputValue, TLazyInputValue | TLazyOutputValue, TLazyTarget, TLazyOptions> | undefined} lazy lazy function
|
206
|
+
* @returns {LazyFunction<TLazyInputValue | TLazyOutputValue, TLazyInputValue | TLazyOutputValue, TLazyTarget, TLazyOptions> | undefined} new lazy
|
175
207
|
*/
|
176
208
|
static unMemoizeLazy(lazy) {
|
177
209
|
if (!SerializerMiddleware.isLazy(lazy)) return lazy;
|
178
|
-
/** @type {LazyFunction<
|
210
|
+
/** @type {LazyFunction<TLazyInputValue | TLazyOutputValue, TLazyInputValue | TLazyOutputValue, TLazyTarget, TLazyOptions>} */
|
179
211
|
const fn = () => {
|
180
212
|
throw new Error(
|
181
213
|
"A lazy value that has been unmemorized can't be called again"
|
182
214
|
);
|
183
215
|
};
|
184
216
|
fn[LAZY_SERIALIZED_VALUE] = SerializerMiddleware.unMemoizeLazy(
|
185
|
-
|
217
|
+
/** @type {LazyFunction<TLazyInputValue | TLazyOutputValue, TLazyInputValue | TLazyOutputValue, TLazyTarget, TLazyOptions>} */
|
218
|
+
(lazy[LAZY_SERIALIZED_VALUE])
|
186
219
|
);
|
187
220
|
fn[LAZY_TARGET] = lazy[LAZY_TARGET];
|
188
221
|
fn.options = lazy.options;
|
@@ -6,13 +6,12 @@
|
|
6
6
|
|
7
7
|
const SerializerMiddleware = require("./SerializerMiddleware");
|
8
8
|
|
9
|
-
/** @typedef {
|
10
|
-
|
11
|
-
/** @typedef {
|
12
|
-
/** @typedef {any[]} SerializedType */
|
9
|
+
/** @typedef {EXPECTED_ANY} DeserializedType */
|
10
|
+
/** @typedef {EXPECTED_ANY[]} SerializedType */
|
11
|
+
/** @typedef {{}} Context */
|
13
12
|
|
14
13
|
/**
|
15
|
-
* @extends {SerializerMiddleware<DeserializedType, SerializedType>}
|
14
|
+
* @extends {SerializerMiddleware<DeserializedType, SerializedType, Context>}
|
16
15
|
*/
|
17
16
|
class SingleItemMiddleware extends SerializerMiddleware {
|
18
17
|
/**
|