atomic-di 1.2.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +262 -224
- package/dist/index.d.mts +101 -78
- package/dist/index.d.ts +101 -78
- package/dist/index.js +51 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
@@ -1,50 +1,75 @@
|
|
1
|
+
type PromiseAwarePartial<T> = T extends Promise<infer U> ? Promise<Partial<U>> : Partial<T>;
|
2
|
+
type Mock<T> = {
|
3
|
+
isPartial: false;
|
4
|
+
resolver: Resolver<T>;
|
5
|
+
} | {
|
6
|
+
isPartial: true;
|
7
|
+
resolver: Resolver<PromiseAwarePartial<T>>;
|
8
|
+
};
|
1
9
|
/**
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
10
|
+
* Immutable map that registers and provides mocks.
|
11
|
+
* Is passed in a resolution context and used by resolvers
|
12
|
+
* to replace or partially replace themselves with a mock if one is defined.
|
5
13
|
*/
|
6
|
-
type MockMap =
|
14
|
+
type MockMap = {
|
15
|
+
/**
|
16
|
+
* Registers a mock for a resolver,
|
17
|
+
* creating a new `MockMap` with this registration.
|
18
|
+
*
|
19
|
+
* @param original - The original resolver.
|
20
|
+
* @param mock - The mock resolver.
|
21
|
+
*/
|
22
|
+
mock<T>(original: Resolver<T>, mock: Resolver<T>): MockMap;
|
7
23
|
/**
|
8
|
-
*
|
24
|
+
* Registers a partial mock for a resolver,
|
25
|
+
* creating a new `MockMap` with this registration.
|
26
|
+
* In this case, the mock resolver's resolution object will be
|
27
|
+
* merged with the original resolver's resolution object,
|
28
|
+
* overwriting certain fields.
|
9
29
|
*
|
10
|
-
* @param
|
11
|
-
* @param mock - The mock
|
30
|
+
* @param original - The original resolver.
|
31
|
+
* @param mock - The mock resolver.
|
12
32
|
*/
|
13
|
-
|
33
|
+
mockPartially<T extends object>(original: Resolver<T>, mock: Resolver<PromiseAwarePartial<T>>): MockMap;
|
14
34
|
/**
|
15
|
-
*
|
35
|
+
* Returns a mock of a resolver
|
36
|
+
* or `undefined` if one is not registered.
|
16
37
|
*
|
17
|
-
* @param
|
38
|
+
* @param original - The original resolver.
|
18
39
|
*/
|
19
|
-
get<T>(
|
40
|
+
get<T>(original: Resolver<T>): Mock<T> | undefined;
|
20
41
|
};
|
21
42
|
/**
|
22
|
-
* Creates a
|
23
|
-
*
|
24
|
-
*
|
43
|
+
* Creates a mock map, an immutable map that registers and provides mocks.
|
44
|
+
* Is passed in a resolution context and used by resolvers
|
45
|
+
* to replace or partially replace themselves with a mock if one is defined.
|
25
46
|
*
|
26
47
|
* @example
|
27
48
|
* ```ts
|
28
49
|
* const mocks = createMockMap()
|
29
|
-
* .
|
50
|
+
* .mock(getDependency, getDependencyMock)
|
51
|
+
* .mockPartially(
|
52
|
+
* getOtherDepedency,
|
53
|
+
* transient(() => ({ someField: "mock" }))
|
54
|
+
* )
|
30
55
|
*
|
31
|
-
*
|
56
|
+
* const entityWithMocks = getEntity({ mocks })
|
32
57
|
* ```
|
33
58
|
*
|
34
|
-
* @returns The map
|
59
|
+
* @returns The mock map.
|
35
60
|
*/
|
36
61
|
declare const createMockMap: () => MockMap;
|
37
62
|
|
38
63
|
/**
|
39
|
-
* A `Map` of
|
40
|
-
*
|
41
|
-
* to
|
64
|
+
* A `Map` of resolvers to their resolutions.
|
65
|
+
* Is passed in a resolution context and used by scoped resolvers
|
66
|
+
* to retrieve or save resolution within it.
|
42
67
|
*/
|
43
68
|
type Scope = Map<Resolver<any>, any>;
|
44
69
|
/**
|
45
|
-
* Creates a `Map` of providers to their instances
|
46
|
-
*
|
47
|
-
* to
|
70
|
+
* Creates a `Map` of providers to their instances.
|
71
|
+
* Is passed in a resolution context and used by scoped resolvers
|
72
|
+
* to retrieve or save resolution within it.
|
48
73
|
*
|
49
74
|
* @example
|
50
75
|
* ```ts
|
@@ -52,97 +77,95 @@ type Scope = Map<Resolver<any>, any>;
|
|
52
77
|
*
|
53
78
|
* app.use(() => {
|
54
79
|
* const db = getDb({ scope: requestScope })
|
55
|
-
* // ...
|
56
80
|
* })
|
57
81
|
* ```
|
58
82
|
*
|
59
|
-
* @returns The map
|
83
|
+
* @returns The map.
|
60
84
|
*/
|
61
85
|
declare const createScope: () => Scope;
|
62
86
|
|
63
87
|
/**
|
64
|
-
* A function that
|
65
|
-
*
|
88
|
+
* A function that takes a resolution context
|
89
|
+
* and returns a value of some type.
|
66
90
|
*/
|
67
|
-
type
|
91
|
+
type ResolverFn<T> = (context?: ResolutionContext) => T;
|
68
92
|
/**
|
69
|
-
* A function that
|
70
|
-
* based on a resolution context
|
93
|
+
* A function that returns a value of some type
|
94
|
+
* based on a resolution context.
|
71
95
|
*/
|
72
|
-
type
|
73
|
-
__brand: "provider";
|
74
|
-
};
|
96
|
+
type Resolver<T> = ResolverFn<T>;
|
75
97
|
/**
|
76
|
-
* A context used by
|
77
|
-
*
|
98
|
+
* A context used by resolvers that defines the behaviour of the resolver
|
99
|
+
* with the passed mocks and scope.
|
78
100
|
*/
|
79
101
|
type ResolutionContext = {
|
80
102
|
scope?: Scope;
|
81
103
|
mocks?: MockMap;
|
82
104
|
};
|
83
105
|
/**
|
84
|
-
* Creates a
|
106
|
+
* Creates a resolver that creates a new resolution on each call.
|
85
107
|
*
|
86
108
|
* @example
|
87
109
|
* ```ts
|
88
|
-
* const
|
89
|
-
*
|
110
|
+
* const getEntity = transient(() => createEntity())
|
111
|
+
* getEntity() !== getEntity()
|
90
112
|
* ```
|
91
113
|
*
|
92
114
|
* @param resolver
|
93
|
-
* A function that
|
94
|
-
*
|
115
|
+
* A function that takes a resolution context
|
116
|
+
* and returns a value of some type.
|
95
117
|
*
|
96
|
-
* @returns The transient
|
118
|
+
* @returns The transient resolver.
|
97
119
|
*/
|
98
|
-
declare const transient: <T>(
|
120
|
+
declare const transient: <T>(fn: ResolverFn<T>) => Resolver<T>;
|
99
121
|
/**
|
100
|
-
* Creates a
|
101
|
-
* and return it on
|
122
|
+
* Creates a resolver that creates
|
123
|
+
* a resolution once and return it on each call.
|
102
124
|
*
|
103
125
|
* @example
|
104
126
|
* ```ts
|
105
|
-
* const
|
106
|
-
*
|
127
|
+
* const getEntity = singleton(() => createEntity())
|
128
|
+
* getEntity() === getEntity()
|
107
129
|
* ```
|
108
130
|
*
|
109
|
-
* @param
|
110
|
-
* A function that
|
111
|
-
*
|
131
|
+
* @param fn
|
132
|
+
* A function that takes a resolution context
|
133
|
+
* and returns a value of some type.
|
112
134
|
*
|
113
|
-
* @returns The singleton
|
135
|
+
* @returns The singleton resolver.
|
114
136
|
*/
|
115
|
-
declare const singleton: <T>(
|
137
|
+
declare const singleton: <T>(fn: ResolverFn<T>) => Resolver<T>;
|
116
138
|
/**
|
117
|
-
* Creates a
|
118
|
-
* or create a new one and save it if there is none.
|
119
|
-
* If no scope
|
139
|
+
* Creates a resolver that takes its resolution
|
140
|
+
* from a scope or create a new one and save it if there is none.
|
141
|
+
* If no scope was passed in a resolution context,
|
142
|
+
* it will act as a singleton.
|
120
143
|
*
|
121
144
|
* @example
|
122
145
|
* ```ts
|
123
|
-
* const
|
124
|
-
*
|
146
|
+
* const getEntity = scoped(() => createEntity())
|
147
|
+
* getEntity() === getEntity()
|
125
148
|
* ```
|
126
149
|
*
|
127
150
|
* @example
|
128
151
|
* ```ts
|
129
|
-
* const
|
152
|
+
* const getEntity = scoped(() => createEntity())
|
130
153
|
* const scope = createScope()
|
131
|
-
*
|
154
|
+
* getEntity({ scope }) === getEntity({ scope }) !== getEntity()
|
132
155
|
* ```
|
133
156
|
*
|
134
|
-
* @param
|
135
|
-
* A function that
|
136
|
-
*
|
157
|
+
* @param fn
|
158
|
+
* A function that takes a resolution context
|
159
|
+
* and returns a value of some type.
|
137
160
|
*
|
138
|
-
* @returns The scoped
|
161
|
+
* @returns The scoped resolver.
|
139
162
|
*/
|
140
|
-
declare const scoped: <T>(
|
163
|
+
declare const scoped: <T>(fn: ResolverFn<T>) => Resolver<T>;
|
141
164
|
|
142
|
-
type
|
143
|
-
type
|
144
|
-
type
|
145
|
-
[K in keyof
|
165
|
+
type ResolverList = Resolver<any>[];
|
166
|
+
type ResolverRecord = Record<string, Resolver<any>>;
|
167
|
+
type InferResolverCollectionResolutions<Resolvers extends ResolverList | ResolverRecord> = {
|
168
|
+
[K in keyof Resolvers]: Resolvers[K] extends Resolver<infer T> ? T : never;
|
146
169
|
};
|
147
170
|
/**
|
148
171
|
* Awaits all promises and wraps the collection in a promise
|
@@ -153,12 +176,12 @@ type AwaitValuesInCollection<T extends any[] | Record<any, any>> = Promise<any>
|
|
153
176
|
[I in keyof T]: T[I] extends Promise<infer T> ? T : T[I];
|
154
177
|
}> : T;
|
155
178
|
/**
|
156
|
-
* Calls every
|
179
|
+
* Calls every resolver in a list with a provided resolution context
|
157
180
|
* and returns a list of resolutions. Returns a `Promise` of a list
|
158
181
|
* of awaited resolutions if there's at least one `Promise` in the resolutions.
|
159
182
|
*
|
160
183
|
* @example
|
161
|
-
* Only sync
|
184
|
+
* Only sync resolvers:
|
162
185
|
* ```ts
|
163
186
|
* const getA = scoped(() => createA())
|
164
187
|
* const getB = scoped(() => createB())
|
@@ -178,7 +201,7 @@ type AwaitValuesInCollection<T extends any[] | Record<any, any>> = Promise<any>
|
|
178
201
|
* ```
|
179
202
|
*
|
180
203
|
* @example
|
181
|
-
* Some
|
204
|
+
* Some resolver is async:
|
182
205
|
* ```ts
|
183
206
|
* const getA = scoped(() => createA())
|
184
207
|
* const getB = scoped(async () => await createB())
|
@@ -197,20 +220,20 @@ type AwaitValuesInCollection<T extends any[] | Record<any, any>> = Promise<any>
|
|
197
220
|
* ]
|
198
221
|
* ```
|
199
222
|
*
|
200
|
-
* @param
|
223
|
+
* @param resolvers - The list of resolvers.
|
201
224
|
* @param context - The resolution context.
|
202
225
|
*
|
203
226
|
* @returns The list of resolutions.
|
204
227
|
*/
|
205
|
-
declare const resolveList: <const
|
228
|
+
declare const resolveList: <const Resolvers extends ResolverList>(resolvers: Resolvers, context?: ResolutionContext) => AwaitValuesInCollection<InferResolverCollectionResolutions<Resolvers>>;
|
206
229
|
/**
|
207
|
-
* Calls every
|
230
|
+
* Calls every resolver in a map with a provided resolution context
|
208
231
|
* and returns a map with identical keys but with resolutions in values instead.
|
209
232
|
* Returns a `Promise` of a map of awaited resolutions if there's at least one
|
210
233
|
* `Promise` in the resolutions.
|
211
234
|
*
|
212
235
|
* @example
|
213
|
-
* Only sync
|
236
|
+
* Only sync resolvers:
|
214
237
|
* ```ts
|
215
238
|
* const getA = scoped(() => createA())
|
216
239
|
* const getB = scoped(() => createB())
|
@@ -230,7 +253,7 @@ declare const resolveList: <const Providers extends ProviderList>(providers: Pro
|
|
230
253
|
* ```
|
231
254
|
*
|
232
255
|
* @example
|
233
|
-
* Some
|
256
|
+
* Some resolver is async:
|
234
257
|
* ```ts
|
235
258
|
* const getA = scoped(() => createA())
|
236
259
|
* const getB = scoped(async () => await createB())
|
@@ -249,11 +272,11 @@ declare const resolveList: <const Providers extends ProviderList>(providers: Pro
|
|
249
272
|
* }
|
250
273
|
* ```
|
251
274
|
*
|
252
|
-
* @param
|
275
|
+
* @param resolvers - The map of resolvers.
|
253
276
|
* @param context - The resolution context.
|
254
277
|
*
|
255
278
|
* @returns The map of resolutions.
|
256
279
|
*/
|
257
|
-
declare const resolveMap: <const
|
280
|
+
declare const resolveMap: <const Resolvers extends ResolverRecord>(resolvers: Resolvers, context?: ResolutionContext) => AwaitValuesInCollection<InferResolverCollectionResolutions<Resolvers>>;
|
258
281
|
|
259
|
-
export { type MockMap, type
|
282
|
+
export { type MockMap, type ResolutionContext, type Resolver, type ResolverFn, type Scope, createMockMap, createScope, resolveList, resolveMap, scoped, singleton, transient };
|
package/dist/index.d.ts
CHANGED
@@ -1,50 +1,75 @@
|
|
1
|
+
type PromiseAwarePartial<T> = T extends Promise<infer U> ? Promise<Partial<U>> : Partial<T>;
|
2
|
+
type Mock<T> = {
|
3
|
+
isPartial: false;
|
4
|
+
resolver: Resolver<T>;
|
5
|
+
} | {
|
6
|
+
isPartial: true;
|
7
|
+
resolver: Resolver<PromiseAwarePartial<T>>;
|
8
|
+
};
|
1
9
|
/**
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
10
|
+
* Immutable map that registers and provides mocks.
|
11
|
+
* Is passed in a resolution context and used by resolvers
|
12
|
+
* to replace or partially replace themselves with a mock if one is defined.
|
5
13
|
*/
|
6
|
-
type MockMap =
|
14
|
+
type MockMap = {
|
15
|
+
/**
|
16
|
+
* Registers a mock for a resolver,
|
17
|
+
* creating a new `MockMap` with this registration.
|
18
|
+
*
|
19
|
+
* @param original - The original resolver.
|
20
|
+
* @param mock - The mock resolver.
|
21
|
+
*/
|
22
|
+
mock<T>(original: Resolver<T>, mock: Resolver<T>): MockMap;
|
7
23
|
/**
|
8
|
-
*
|
24
|
+
* Registers a partial mock for a resolver,
|
25
|
+
* creating a new `MockMap` with this registration.
|
26
|
+
* In this case, the mock resolver's resolution object will be
|
27
|
+
* merged with the original resolver's resolution object,
|
28
|
+
* overwriting certain fields.
|
9
29
|
*
|
10
|
-
* @param
|
11
|
-
* @param mock - The mock
|
30
|
+
* @param original - The original resolver.
|
31
|
+
* @param mock - The mock resolver.
|
12
32
|
*/
|
13
|
-
|
33
|
+
mockPartially<T extends object>(original: Resolver<T>, mock: Resolver<PromiseAwarePartial<T>>): MockMap;
|
14
34
|
/**
|
15
|
-
*
|
35
|
+
* Returns a mock of a resolver
|
36
|
+
* or `undefined` if one is not registered.
|
16
37
|
*
|
17
|
-
* @param
|
38
|
+
* @param original - The original resolver.
|
18
39
|
*/
|
19
|
-
get<T>(
|
40
|
+
get<T>(original: Resolver<T>): Mock<T> | undefined;
|
20
41
|
};
|
21
42
|
/**
|
22
|
-
* Creates a
|
23
|
-
*
|
24
|
-
*
|
43
|
+
* Creates a mock map, an immutable map that registers and provides mocks.
|
44
|
+
* Is passed in a resolution context and used by resolvers
|
45
|
+
* to replace or partially replace themselves with a mock if one is defined.
|
25
46
|
*
|
26
47
|
* @example
|
27
48
|
* ```ts
|
28
49
|
* const mocks = createMockMap()
|
29
|
-
* .
|
50
|
+
* .mock(getDependency, getDependencyMock)
|
51
|
+
* .mockPartially(
|
52
|
+
* getOtherDepedency,
|
53
|
+
* transient(() => ({ someField: "mock" }))
|
54
|
+
* )
|
30
55
|
*
|
31
|
-
*
|
56
|
+
* const entityWithMocks = getEntity({ mocks })
|
32
57
|
* ```
|
33
58
|
*
|
34
|
-
* @returns The map
|
59
|
+
* @returns The mock map.
|
35
60
|
*/
|
36
61
|
declare const createMockMap: () => MockMap;
|
37
62
|
|
38
63
|
/**
|
39
|
-
* A `Map` of
|
40
|
-
*
|
41
|
-
* to
|
64
|
+
* A `Map` of resolvers to their resolutions.
|
65
|
+
* Is passed in a resolution context and used by scoped resolvers
|
66
|
+
* to retrieve or save resolution within it.
|
42
67
|
*/
|
43
68
|
type Scope = Map<Resolver<any>, any>;
|
44
69
|
/**
|
45
|
-
* Creates a `Map` of providers to their instances
|
46
|
-
*
|
47
|
-
* to
|
70
|
+
* Creates a `Map` of providers to their instances.
|
71
|
+
* Is passed in a resolution context and used by scoped resolvers
|
72
|
+
* to retrieve or save resolution within it.
|
48
73
|
*
|
49
74
|
* @example
|
50
75
|
* ```ts
|
@@ -52,97 +77,95 @@ type Scope = Map<Resolver<any>, any>;
|
|
52
77
|
*
|
53
78
|
* app.use(() => {
|
54
79
|
* const db = getDb({ scope: requestScope })
|
55
|
-
* // ...
|
56
80
|
* })
|
57
81
|
* ```
|
58
82
|
*
|
59
|
-
* @returns The map
|
83
|
+
* @returns The map.
|
60
84
|
*/
|
61
85
|
declare const createScope: () => Scope;
|
62
86
|
|
63
87
|
/**
|
64
|
-
* A function that
|
65
|
-
*
|
88
|
+
* A function that takes a resolution context
|
89
|
+
* and returns a value of some type.
|
66
90
|
*/
|
67
|
-
type
|
91
|
+
type ResolverFn<T> = (context?: ResolutionContext) => T;
|
68
92
|
/**
|
69
|
-
* A function that
|
70
|
-
* based on a resolution context
|
93
|
+
* A function that returns a value of some type
|
94
|
+
* based on a resolution context.
|
71
95
|
*/
|
72
|
-
type
|
73
|
-
__brand: "provider";
|
74
|
-
};
|
96
|
+
type Resolver<T> = ResolverFn<T>;
|
75
97
|
/**
|
76
|
-
* A context used by
|
77
|
-
*
|
98
|
+
* A context used by resolvers that defines the behaviour of the resolver
|
99
|
+
* with the passed mocks and scope.
|
78
100
|
*/
|
79
101
|
type ResolutionContext = {
|
80
102
|
scope?: Scope;
|
81
103
|
mocks?: MockMap;
|
82
104
|
};
|
83
105
|
/**
|
84
|
-
* Creates a
|
106
|
+
* Creates a resolver that creates a new resolution on each call.
|
85
107
|
*
|
86
108
|
* @example
|
87
109
|
* ```ts
|
88
|
-
* const
|
89
|
-
*
|
110
|
+
* const getEntity = transient(() => createEntity())
|
111
|
+
* getEntity() !== getEntity()
|
90
112
|
* ```
|
91
113
|
*
|
92
114
|
* @param resolver
|
93
|
-
* A function that
|
94
|
-
*
|
115
|
+
* A function that takes a resolution context
|
116
|
+
* and returns a value of some type.
|
95
117
|
*
|
96
|
-
* @returns The transient
|
118
|
+
* @returns The transient resolver.
|
97
119
|
*/
|
98
|
-
declare const transient: <T>(
|
120
|
+
declare const transient: <T>(fn: ResolverFn<T>) => Resolver<T>;
|
99
121
|
/**
|
100
|
-
* Creates a
|
101
|
-
* and return it on
|
122
|
+
* Creates a resolver that creates
|
123
|
+
* a resolution once and return it on each call.
|
102
124
|
*
|
103
125
|
* @example
|
104
126
|
* ```ts
|
105
|
-
* const
|
106
|
-
*
|
127
|
+
* const getEntity = singleton(() => createEntity())
|
128
|
+
* getEntity() === getEntity()
|
107
129
|
* ```
|
108
130
|
*
|
109
|
-
* @param
|
110
|
-
* A function that
|
111
|
-
*
|
131
|
+
* @param fn
|
132
|
+
* A function that takes a resolution context
|
133
|
+
* and returns a value of some type.
|
112
134
|
*
|
113
|
-
* @returns The singleton
|
135
|
+
* @returns The singleton resolver.
|
114
136
|
*/
|
115
|
-
declare const singleton: <T>(
|
137
|
+
declare const singleton: <T>(fn: ResolverFn<T>) => Resolver<T>;
|
116
138
|
/**
|
117
|
-
* Creates a
|
118
|
-
* or create a new one and save it if there is none.
|
119
|
-
* If no scope
|
139
|
+
* Creates a resolver that takes its resolution
|
140
|
+
* from a scope or create a new one and save it if there is none.
|
141
|
+
* If no scope was passed in a resolution context,
|
142
|
+
* it will act as a singleton.
|
120
143
|
*
|
121
144
|
* @example
|
122
145
|
* ```ts
|
123
|
-
* const
|
124
|
-
*
|
146
|
+
* const getEntity = scoped(() => createEntity())
|
147
|
+
* getEntity() === getEntity()
|
125
148
|
* ```
|
126
149
|
*
|
127
150
|
* @example
|
128
151
|
* ```ts
|
129
|
-
* const
|
152
|
+
* const getEntity = scoped(() => createEntity())
|
130
153
|
* const scope = createScope()
|
131
|
-
*
|
154
|
+
* getEntity({ scope }) === getEntity({ scope }) !== getEntity()
|
132
155
|
* ```
|
133
156
|
*
|
134
|
-
* @param
|
135
|
-
* A function that
|
136
|
-
*
|
157
|
+
* @param fn
|
158
|
+
* A function that takes a resolution context
|
159
|
+
* and returns a value of some type.
|
137
160
|
*
|
138
|
-
* @returns The scoped
|
161
|
+
* @returns The scoped resolver.
|
139
162
|
*/
|
140
|
-
declare const scoped: <T>(
|
163
|
+
declare const scoped: <T>(fn: ResolverFn<T>) => Resolver<T>;
|
141
164
|
|
142
|
-
type
|
143
|
-
type
|
144
|
-
type
|
145
|
-
[K in keyof
|
165
|
+
type ResolverList = Resolver<any>[];
|
166
|
+
type ResolverRecord = Record<string, Resolver<any>>;
|
167
|
+
type InferResolverCollectionResolutions<Resolvers extends ResolverList | ResolverRecord> = {
|
168
|
+
[K in keyof Resolvers]: Resolvers[K] extends Resolver<infer T> ? T : never;
|
146
169
|
};
|
147
170
|
/**
|
148
171
|
* Awaits all promises and wraps the collection in a promise
|
@@ -153,12 +176,12 @@ type AwaitValuesInCollection<T extends any[] | Record<any, any>> = Promise<any>
|
|
153
176
|
[I in keyof T]: T[I] extends Promise<infer T> ? T : T[I];
|
154
177
|
}> : T;
|
155
178
|
/**
|
156
|
-
* Calls every
|
179
|
+
* Calls every resolver in a list with a provided resolution context
|
157
180
|
* and returns a list of resolutions. Returns a `Promise` of a list
|
158
181
|
* of awaited resolutions if there's at least one `Promise` in the resolutions.
|
159
182
|
*
|
160
183
|
* @example
|
161
|
-
* Only sync
|
184
|
+
* Only sync resolvers:
|
162
185
|
* ```ts
|
163
186
|
* const getA = scoped(() => createA())
|
164
187
|
* const getB = scoped(() => createB())
|
@@ -178,7 +201,7 @@ type AwaitValuesInCollection<T extends any[] | Record<any, any>> = Promise<any>
|
|
178
201
|
* ```
|
179
202
|
*
|
180
203
|
* @example
|
181
|
-
* Some
|
204
|
+
* Some resolver is async:
|
182
205
|
* ```ts
|
183
206
|
* const getA = scoped(() => createA())
|
184
207
|
* const getB = scoped(async () => await createB())
|
@@ -197,20 +220,20 @@ type AwaitValuesInCollection<T extends any[] | Record<any, any>> = Promise<any>
|
|
197
220
|
* ]
|
198
221
|
* ```
|
199
222
|
*
|
200
|
-
* @param
|
223
|
+
* @param resolvers - The list of resolvers.
|
201
224
|
* @param context - The resolution context.
|
202
225
|
*
|
203
226
|
* @returns The list of resolutions.
|
204
227
|
*/
|
205
|
-
declare const resolveList: <const
|
228
|
+
declare const resolveList: <const Resolvers extends ResolverList>(resolvers: Resolvers, context?: ResolutionContext) => AwaitValuesInCollection<InferResolverCollectionResolutions<Resolvers>>;
|
206
229
|
/**
|
207
|
-
* Calls every
|
230
|
+
* Calls every resolver in a map with a provided resolution context
|
208
231
|
* and returns a map with identical keys but with resolutions in values instead.
|
209
232
|
* Returns a `Promise` of a map of awaited resolutions if there's at least one
|
210
233
|
* `Promise` in the resolutions.
|
211
234
|
*
|
212
235
|
* @example
|
213
|
-
* Only sync
|
236
|
+
* Only sync resolvers:
|
214
237
|
* ```ts
|
215
238
|
* const getA = scoped(() => createA())
|
216
239
|
* const getB = scoped(() => createB())
|
@@ -230,7 +253,7 @@ declare const resolveList: <const Providers extends ProviderList>(providers: Pro
|
|
230
253
|
* ```
|
231
254
|
*
|
232
255
|
* @example
|
233
|
-
* Some
|
256
|
+
* Some resolver is async:
|
234
257
|
* ```ts
|
235
258
|
* const getA = scoped(() => createA())
|
236
259
|
* const getB = scoped(async () => await createB())
|
@@ -249,11 +272,11 @@ declare const resolveList: <const Providers extends ProviderList>(providers: Pro
|
|
249
272
|
* }
|
250
273
|
* ```
|
251
274
|
*
|
252
|
-
* @param
|
275
|
+
* @param resolvers - The map of resolvers.
|
253
276
|
* @param context - The resolution context.
|
254
277
|
*
|
255
278
|
* @returns The map of resolutions.
|
256
279
|
*/
|
257
|
-
declare const resolveMap: <const
|
280
|
+
declare const resolveMap: <const Resolvers extends ResolverRecord>(resolvers: Resolvers, context?: ResolutionContext) => AwaitValuesInCollection<InferResolverCollectionResolutions<Resolvers>>;
|
258
281
|
|
259
|
-
export { type MockMap, type
|
282
|
+
export { type MockMap, type ResolutionContext, type Resolver, type ResolverFn, type Scope, createMockMap, createScope, resolveList, resolveMap, scoped, singleton, transient };
|