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.
Files changed (87) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +2 -2
  3. package/lib/Cache.js +1 -1
  4. package/lib/Chunk.js +12 -9
  5. package/lib/Compilation.js +36 -27
  6. package/lib/Compiler.js +4 -3
  7. package/lib/ContextModule.js +2 -1
  8. package/lib/HotModuleReplacementPlugin.js +3 -3
  9. package/lib/Module.js +10 -2
  10. package/lib/ModuleFilenameHelpers.js +1 -1
  11. package/lib/ModuleGraph.js +15 -10
  12. package/lib/NormalModule.js +1 -1
  13. package/lib/PrefetchPlugin.js +1 -1
  14. package/lib/RecordIdsPlugin.js +1 -1
  15. package/lib/SourceMapDevToolPlugin.js +1 -1
  16. package/lib/Template.js +1 -1
  17. package/lib/WebpackOptionsApply.js +17 -2
  18. package/lib/buildChunkGraph.js +7 -2
  19. package/lib/cache/IdleFileCachePlugin.js +1 -1
  20. package/lib/cache/MemoryCachePlugin.js +2 -1
  21. package/lib/cache/MemoryWithGcCachePlugin.js +3 -2
  22. package/lib/cache/PackFileCacheStrategy.js +13 -21
  23. package/lib/cache/ResolverCachePlugin.js +14 -16
  24. package/lib/cli.js +3 -3
  25. package/lib/config/defaults.js +2 -2
  26. package/lib/config/target.js +6 -6
  27. package/lib/css/CssParser.js +1 -1
  28. package/lib/debug/ProfilingPlugin.js +1 -1
  29. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  30. package/lib/dependencies/CssIcssImportDependency.js +3 -2
  31. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  32. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  33. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
  34. package/lib/dependencies/JsonExportsDependency.js +1 -1
  35. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  36. package/lib/dependencies/RequireResolveDependency.js +1 -1
  37. package/lib/dependencies/WorkerPlugin.js +2 -2
  38. package/lib/esm/ModuleChunkLoadingPlugin.js +20 -0
  39. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
  40. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  41. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  42. package/lib/ids/NamedChunkIdsPlugin.js +2 -2
  43. package/lib/ids/NamedModuleIdsPlugin.js +2 -2
  44. package/lib/index.js +1 -1
  45. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  46. package/lib/javascript/JavascriptParser.js +41 -37
  47. package/lib/library/EnableLibraryPlugin.js +15 -2
  48. package/lib/library/ModuleLibraryPlugin.js +6 -1
  49. package/lib/logging/createConsoleLogger.js +0 -1
  50. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
  51. package/lib/node/NodeTemplatePlugin.js +2 -2
  52. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
  53. package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
  54. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  55. package/lib/optimize/SplitChunksPlugin.js +2 -1
  56. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
  57. package/lib/serialization/BinaryMiddleware.js +22 -38
  58. package/lib/serialization/FileMiddleware.js +29 -33
  59. package/lib/serialization/ObjectMiddleware.js +29 -30
  60. package/lib/serialization/Serializer.js +29 -18
  61. package/lib/serialization/SerializerMiddleware.js +105 -72
  62. package/lib/serialization/SingleItemMiddleware.js +4 -5
  63. package/lib/stats/DefaultStatsFactoryPlugin.js +39 -24
  64. package/lib/stats/DefaultStatsPrinterPlugin.js +267 -80
  65. package/lib/stats/StatsFactory.js +47 -10
  66. package/lib/stats/StatsPrinter.js +52 -31
  67. package/lib/util/ArrayQueue.js +1 -1
  68. package/lib/util/AsyncQueue.js +1 -1
  69. package/lib/util/TupleQueue.js +9 -7
  70. package/lib/util/TupleSet.js +37 -18
  71. package/lib/util/WeakTupleMap.js +50 -37
  72. package/lib/util/cleverMerge.js +2 -2
  73. package/lib/util/comparators.js +1 -1
  74. package/lib/util/createHash.js +1 -1
  75. package/lib/util/fs.js +1 -1
  76. package/lib/util/makeSerializable.js +1 -1
  77. package/lib/util/runtime.js +1 -0
  78. package/lib/util/serialization.js +50 -42
  79. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  80. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
  81. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  82. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
  83. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  84. package/lib/web/FetchCompileWasmPlugin.js +2 -2
  85. package/lib/webpack.js +1 -1
  86. package/package.json +1 -1
  87. 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").Context} Context */
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: any) => void} write
66
- * @property {(value: any) => void} setCircularReference
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: any) => void)=} writeLazy
70
- * @property {((item: any, obj?: TODO) => (() => Promise<any> | any))=} writeSeparate
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 {() => any} read
76
- * @property {(value: any) => void} setCircularReference
73
+ * @property {() => Value} read
74
+ * @property {(value: ReferenceableItem) => void} setCircularReference
77
75
  */
78
76
 
79
77
  /**
80
78
  * @typedef {object} ObjectSerializer
81
- * @property {(value: any, context: ObjectSerializerContext) => void} serialize
82
- * @property {(context: ObjectDeserializerContext) => any} deserialize
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
- * @typedef {ComplexSerializableType[]} DeserializedType
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 {TODO} object for serialization
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 {Item[]} */
325
+ /** @type {Value[]} */
328
326
  let result = [CURRENT_VERSION];
329
327
  let currentPos = 0;
330
- /** @type {Map<Item, number>} */
328
+ /** @type {Map<ReferenceableItem, number>} */
331
329
  let referenceable = new Map();
332
330
  /**
333
- * @param {Item} item referenceable item
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 {Item} item item to stack
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 {Item} item item to serialize
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
- /** @type {SerializedType} */
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 {Item[]} */
658
+ /** @type {ReferenceableItem[]} */
659
659
  let referenceable = [];
660
660
  /**
661
- * @param {Item} item referenceable item
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
- /** @type {LazyFunction<SerializedType>} */
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<any, any>[]} middlewares serializer middlewares
17
- * @param {Context} [context] 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
- * @param {TODO | Promise<TODO>} obj object
27
- * @param {Context} context context object
28
- * @returns {Promise<TODO>} result
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 (current && typeof current.then === "function") {
38
+ if (
39
+ current &&
40
+ typeof (/** @type {Promise<DeserializedValue>} */ (current).then) ===
41
+ "function"
42
+ ) {
35
43
  current =
36
- /** @type {Promise<TODO>} */
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
- * @param {TODO | Promise<TODO>} value value
51
- * @param {Context} context object
52
- * @returns {Promise<TODO>} result
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 && typeof current.then === "function"
60
- ? /** @type {Promise<TODO>} */ (current).then(data =>
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 {TODO} Context */
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 LazyResult
16
- * @typedef {() => LazyResult | Promise<LazyResult>} InternalLazyFunction
17
- */
18
-
19
- /** @typedef {Record<string, any>} LazyOptions */
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 LazyResult
57
- * @param {LazyFunction<LazyResult> | EXPECTED_ANY} value contained value or function to value
58
- * @param {SerializerMiddleware<any, any>} target target middleware
59
- * @param {LazyOptions=} options lazy options
60
- * @param {any=} serializedValue serialized value
61
- * @returns {LazyFunction<LazyResult>} lazy function
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(value, target, options = {}, serializedValue = undefined) {
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<LazyResult>} */
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 {SerializerMiddleware<any, any>=} target target middleware
77
- * @returns {boolean} true, when fn is a lazy function (optionally of that target)
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 LazyResult
87
- * @param {LazyFunction<LazyResult>} fn lazy function
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 /** @type {any} */ (fn).options;
103
+ return fn.options;
93
104
  }
94
105
 
95
106
  /**
96
- * @template LazyResult
97
- * @param {LazyFunction<LazyResult> | EXPECTED_ANY} fn lazy function
98
- * @returns {any | undefined} serialized value
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 LazyResult
107
- * @param {LazyFunction<LazyResult>} fn lazy function
108
- * @param {TODO} value serialized value
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 LazyResult, R
117
- * @param {LazyFunction<LazyResult>} lazy lazy function
118
- * @param {(lazyResult: LazyResult) => Promise<R> | R} serialize serialize function
119
- * @returns {LazyFunction<R>} new lazy
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 = /** @type {LazyFunction<R>} */ (
123
- memoize(() => {
124
- const r = lazy();
125
- if (
126
- r &&
127
- typeof (/** @type {Promise<LazyResult>} */ (r).then) === "function"
128
- ) {
129
- return (
130
- /** @type {Promise<LazyResult>} */
131
- (r).then(data => data && serialize(data))
132
- );
133
- }
134
- return serialize(/** @type {LazyResult} */ (r));
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 LazyResult, R
145
- * @param {LazyFunction<LazyResult>} lazy lazy function
146
- * @param {(lazyResult: LazyResult) => Promise<R> | R} deserialize deserialize function
147
- * @returns {LazyFunction<R>} new lazy
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 = /** @type {LazyFunction<R>} */ (
151
- memoize(() => {
152
- const r = lazy();
153
- if (
154
- r &&
155
- typeof (/** @type {Promise<LazyResult>} */ (r).then) === "function"
156
- ) {
157
- return (
158
- /** @type {Promise<LazyResult>} */
159
- (r).then(data => deserialize(data))
160
- );
161
- }
162
- return deserialize(/** @type {LazyResult} */ (r));
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 LazyResult
173
- * @param {LazyFunction<LazyResult> | EXPECTED_ANY} lazy lazy function
174
- * @returns {LazyFunction<LazyResult> | EXPECTED_ANY} new lazy
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<LazyResult>} */
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
- lazy[LAZY_SERIALIZED_VALUE]
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 {import("./SerializerMiddleware").Context} Context */
10
-
11
- /** @typedef {any} DeserializedType */
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
  /**