effect 3.17.11 → 3.17.13

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/src/LayerMap.ts CHANGED
@@ -12,7 +12,7 @@ import * as Layer from "./Layer.js"
12
12
  import * as RcMap from "./RcMap.js"
13
13
  import * as Runtime from "./Runtime.js"
14
14
  import * as Scope from "./Scope.js"
15
- import type { Mutable } from "./Types.js"
15
+ import type { Mutable, NoExcessProperties } from "./Types.js"
16
16
 
17
17
  /**
18
18
  * @since 3.14.0
@@ -113,11 +113,13 @@ export interface LayerMap<in K, in out I, out E = never> {
113
113
  */
114
114
  export const make: <
115
115
  K,
116
- L extends Layer.Layer<any, any, any>
116
+ L extends Layer.Layer<any, any, any>,
117
+ PreloadKeys extends Iterable<K> | undefined = undefined
117
118
  >(
118
119
  lookup: (key: K) => L,
119
120
  options?: {
120
121
  readonly idleTimeToLive?: Duration.DurationInput | undefined
122
+ readonly preloadKeys?: PreloadKeys
121
123
  } | undefined
122
124
  ) => Effect.Effect<
123
125
  LayerMap<
@@ -125,12 +127,13 @@ export const make: <
125
127
  L extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : never,
126
128
  L extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never
127
129
  >,
128
- never,
130
+ PreloadKeys extends undefined ? never : L extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never,
129
131
  Scope.Scope | (L extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : never)
130
132
  > = Effect.fnUntraced(function*<I, K, EL, RL>(
131
133
  lookup: (key: K) => Layer.Layer<I, EL, RL>,
132
134
  options?: {
133
135
  readonly idleTimeToLive?: Duration.DurationInput | undefined
136
+ readonly preloadKeys?: Iterable<K> | undefined
134
137
  } | undefined
135
138
  ) {
136
139
  const context = yield* Effect.context<never>()
@@ -174,6 +177,12 @@ export const make: <
174
177
  idleTimeToLive: options?.idleTimeToLive
175
178
  })
176
179
 
180
+ if (options?.preloadKeys) {
181
+ for (const key of options.preloadKeys) {
182
+ yield* (RcMap.get(rcMap, key) as Effect.Effect<any, EL, RL | Scope.Scope>)
183
+ }
184
+ }
185
+
177
186
  return identity<LayerMap<K, Exclude<I, Scope.Scope>, any>>({
178
187
  [TypeId]: TypeId,
179
188
  rcMap,
@@ -189,21 +198,27 @@ export const make: <
189
198
  * @experimental
190
199
  */
191
200
  export const fromRecord = <
192
- const Layers extends Record<string, Layer.Layer<any, any, any>>
201
+ const Layers extends Record<string, Layer.Layer<any, any, any>>,
202
+ const Preload extends boolean = false
193
203
  >(
194
204
  layers: Layers,
195
205
  options?: {
196
206
  readonly idleTimeToLive?: Duration.DurationInput | undefined
207
+ readonly preload?: Preload | undefined
197
208
  } | undefined
198
209
  ): Effect.Effect<
199
210
  LayerMap<
200
211
  keyof Layers,
201
212
  Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : never,
202
- Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never
213
+ Preload extends true ? never : Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never
203
214
  >,
204
- never,
215
+ Preload extends true ? never : Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never,
205
216
  Scope.Scope | (Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : never)
206
- > => make((key: keyof Layers) => layers[key], options)
217
+ > =>
218
+ make((key: keyof Layers) => layers[key], {
219
+ ...options,
220
+ preloadKeys: options?.preload ? Object.keys(layers) : undefined
221
+ }) as any
207
222
 
208
223
  /**
209
224
  * @since 3.14.0
@@ -216,6 +231,7 @@ export interface TagClass<
216
231
  in out I,
217
232
  in out E,
218
233
  in out R,
234
+ in out LE,
219
235
  in out Deps extends Layer.Layer<any, any, any>
220
236
  > extends Context.TagClass<Self, Id, LayerMap<K, I, E>> {
221
237
  /**
@@ -223,7 +239,7 @@ export interface TagClass<
223
239
  */
224
240
  readonly Default: Layer.Layer<
225
241
  Self,
226
- (Deps extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never),
242
+ (Deps extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never) | LE,
227
243
  | Exclude<R, (Deps extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : never)>
228
244
  | (Deps extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : never)
229
245
  >
@@ -231,7 +247,7 @@ export interface TagClass<
231
247
  /**
232
248
  * A default layer for the `LayerMap` service without the dependencies provided.
233
249
  */
234
- readonly DefaultWithoutDependencies: Layer.Layer<Self, never, R>
250
+ readonly DefaultWithoutDependencies: Layer.Layer<Self, LE, R>
235
251
 
236
252
  /**
237
253
  * Retrieves a Layer for the resources associated with the key.
@@ -305,28 +321,40 @@ export interface TagClass<
305
321
  export const Service = <Self>() =>
306
322
  <
307
323
  const Id extends string,
308
- Lookup extends {
309
- readonly lookup: (key: any) => Layer.Layer<any, any, any>
310
- } | {
311
- readonly layers: Record<string, Layer.Layer<any, any, any>>
312
- },
313
- const Deps extends ReadonlyArray<Layer.Layer<any, any, any>> = []
324
+ Options extends
325
+ | NoExcessProperties<
326
+ {
327
+ readonly lookup: (key: any) => Layer.Layer<any, any, any>
328
+ readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>>
329
+ readonly idleTimeToLive?: Duration.DurationInput | undefined
330
+ readonly preloadKeys?:
331
+ | Iterable<Options extends { readonly lookup: (key: infer K) => any } ? K : never>
332
+ | undefined
333
+ },
334
+ Options
335
+ >
336
+ | NoExcessProperties<{
337
+ readonly layers: Record<string, Layer.Layer<any, any, any>>
338
+ readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>>
339
+ readonly idleTimeToLive?: Duration.DurationInput | undefined
340
+ readonly preload?: boolean
341
+ }, Options>
314
342
  >(
315
343
  id: Id,
316
- options: Lookup & {
317
- readonly dependencies?: Deps | undefined
318
- readonly idleTimeToLive?: Duration.DurationInput | undefined
319
- }
344
+ options: Options
320
345
  ): TagClass<
321
346
  Self,
322
347
  Id,
323
- Lookup extends { readonly lookup: (key: infer K) => any } ? K
324
- : Lookup extends { readonly layers: infer Layers } ? keyof Layers
348
+ Options extends { readonly lookup: (key: infer K) => any } ? K
349
+ : Options extends { readonly layers: infer Layers } ? keyof Layers
350
+ : never,
351
+ Service.Success<Options>,
352
+ Options extends { readonly preload: true } ? never : Service.Error<Options>,
353
+ Service.Context<Options>,
354
+ Options extends { readonly preload: true } ? Service.Error<Options>
355
+ : Options extends { readonly preloadKey: Iterable<any> } ? Service.Error<Options>
325
356
  : never,
326
- Service.Success<Lookup>,
327
- Service.Error<Lookup>,
328
- Service.Context<Lookup>,
329
- Deps[number]
357
+ Options extends { readonly dependencies: ReadonlyArray<any> } ? Options["dependencies"][number] : never
330
358
  > => {
331
359
  const Err = globalThis.Error as any
332
360
  const limit = Err.stackTraceLimit
@@ -335,7 +363,7 @@ export const Service = <Self>() =>
335
363
  Err.stackTraceLimit = limit
336
364
 
337
365
  function TagClass() {}
338
- const TagClass_ = TagClass as any as Mutable<TagClass<Self, Id, string, any, any, any, any>>
366
+ const TagClass_ = TagClass as any as Mutable<TagClass<Self, Id, string, any, any, any, any, any>>
339
367
  Object.setPrototypeOf(TagClass, Object.getPrototypeOf(Context.GenericTag<Self, any>(id)))
340
368
  TagClass.key = id
341
369
  Object.defineProperty(TagClass, "stack", {
@@ -1531,7 +1531,7 @@ export const tracerLogger = globalValue(
1531
1531
  }
1532
1532
 
1533
1533
  span.value.event(
1534
- Inspectable.toStringUnknown(Array.isArray(message) ? message[0] : message),
1534
+ Inspectable.toStringUnknown(Array.isArray(message) && message.length === 1 ? message[0] : message),
1535
1535
  clockService.unsafeCurrentTimeNanos(),
1536
1536
  attributes
1537
1537
  )
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.17.11"
1
+ let moduleVersion = "3.17.13"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4