effect 4.0.0-beta.13 → 4.0.0-beta.15

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 (64) hide show
  1. package/dist/Channel.d.ts +6 -6
  2. package/dist/Channel.d.ts.map +1 -1
  3. package/dist/Channel.js +4 -4
  4. package/dist/Channel.js.map +1 -1
  5. package/dist/Effect.d.ts +7 -7
  6. package/dist/Effect.d.ts.map +1 -1
  7. package/dist/Effect.js.map +1 -1
  8. package/dist/Stream.d.ts +7 -7
  9. package/dist/Stream.d.ts.map +1 -1
  10. package/dist/Stream.js +8 -6
  11. package/dist/Stream.js.map +1 -1
  12. package/dist/Types.d.ts +70 -0
  13. package/dist/Types.d.ts.map +1 -1
  14. package/dist/internal/effect.js +4 -4
  15. package/dist/internal/effect.js.map +1 -1
  16. package/dist/unstable/ai/LanguageModel.d.ts +2 -0
  17. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  18. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  19. package/dist/unstable/cli/Command.d.ts +34 -4
  20. package/dist/unstable/cli/Command.d.ts.map +1 -1
  21. package/dist/unstable/cli/Command.js +75 -20
  22. package/dist/unstable/cli/Command.js.map +1 -1
  23. package/dist/unstable/cli/GlobalFlag.d.ts +25 -62
  24. package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
  25. package/dist/unstable/cli/GlobalFlag.js +41 -87
  26. package/dist/unstable/cli/GlobalFlag.js.map +1 -1
  27. package/dist/unstable/cli/internal/command.d.ts +3 -0
  28. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  29. package/dist/unstable/cli/internal/command.js +2 -0
  30. package/dist/unstable/cli/internal/command.js.map +1 -1
  31. package/dist/unstable/cli/internal/help.d.ts +18 -4
  32. package/dist/unstable/cli/internal/help.d.ts.map +1 -1
  33. package/dist/unstable/cli/internal/help.js +62 -9
  34. package/dist/unstable/cli/internal/help.js.map +1 -1
  35. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +10 -4
  36. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  37. package/dist/unstable/httpapi/HttpApiBuilder.js +17 -6
  38. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  39. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +7 -2
  40. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  41. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  42. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  43. package/dist/unstable/httpapi/OpenApi.js +3 -4
  44. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  45. package/dist/unstable/reactivity/AtomHttpApi.d.ts +2 -2
  46. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  47. package/dist/unstable/reactivity/AtomRegistry.js +2 -6
  48. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/Channel.ts +24 -14
  51. package/src/Effect.ts +30 -8
  52. package/src/Stream.ts +46 -22
  53. package/src/Types.ts +66 -0
  54. package/src/internal/effect.ts +41 -14
  55. package/src/unstable/ai/LanguageModel.ts +9 -6
  56. package/src/unstable/cli/Command.ts +122 -24
  57. package/src/unstable/cli/GlobalFlag.ts +98 -197
  58. package/src/unstable/cli/internal/command.ts +5 -0
  59. package/src/unstable/cli/internal/help.ts +104 -24
  60. package/src/unstable/httpapi/HttpApiBuilder.ts +68 -13
  61. package/src/unstable/httpapi/HttpApiEndpoint.ts +13 -4
  62. package/src/unstable/httpapi/OpenApi.ts +3 -4
  63. package/src/unstable/reactivity/AtomHttpApi.ts +2 -2
  64. package/src/unstable/reactivity/AtomRegistry.ts +2 -6
@@ -20,7 +20,7 @@ import * as Transformation from "../../SchemaTransformation.ts"
20
20
  import type * as Scope from "../../Scope.ts"
21
21
  import * as ServiceMap from "../../ServiceMap.ts"
22
22
  import * as Stream from "../../Stream.ts"
23
- import type { Covariant } from "../../Types.ts"
23
+ import type { Covariant, NoInfer } from "../../Types.ts"
24
24
  import * as UndefinedOr from "../../UndefinedOr.ts"
25
25
  import type { Cookie } from "../http/Cookies.ts"
26
26
  import type * as Etag from "../http/Etag.ts"
@@ -63,7 +63,6 @@ export const layer = <Id extends string, Groups extends HttpApiGroup.Any>(
63
63
  | HttpPlatform
64
64
  | Path
65
65
  | HttpApiGroup.ToService<Id, Groups>
66
- | HttpApiGroup.ErrorServicesEncode<Groups>
67
66
  > =>
68
67
  HttpRouter.use(Effect.fnUntraced(function*(router) {
69
68
  const services = yield* Effect.services<
@@ -168,7 +167,7 @@ export interface Handlers<
168
167
  | R
169
168
  | HttpApiEndpoint.MiddlewareWithName<Endpoints, Name>
170
169
  | HttpApiEndpoint.MiddlewareServicesWithName<Endpoints, Name>
171
- | HttpApiEndpoint.ExcludeProvided<
170
+ | HttpApiEndpoint.ExcludeProvidedWithName<
172
171
  Endpoints,
173
172
  Name,
174
173
  R1 | HttpApiEndpoint.ServerServicesWithName<Endpoints, Name>
@@ -188,7 +187,7 @@ export interface Handlers<
188
187
  | R
189
188
  | HttpApiEndpoint.MiddlewareWithName<Endpoints, Name>
190
189
  | HttpApiEndpoint.MiddlewareServicesWithName<Endpoints, Name>
191
- | HttpApiEndpoint.ExcludeProvided<
190
+ | HttpApiEndpoint.ExcludeProvidedWithName<
192
191
  Endpoints,
193
192
  Name,
194
193
  R1 | HttpApiEndpoint.ServerServicesWithName<Endpoints, Name>
@@ -284,6 +283,54 @@ export declare namespace Handlers {
284
283
  never
285
284
  }
286
285
 
286
+ /**
287
+ * @since 4.0.0
288
+ * @category handlers
289
+ */
290
+ export const endpoint = <
291
+ ApiId extends string,
292
+ Groups extends HttpApiGroup.Any,
293
+ const GroupName extends HttpApiGroup.Name<Groups>,
294
+ const EndpointName extends HttpApiEndpoint.Name<HttpApiGroup.Endpoints<HttpApiGroup.WithName<Groups, GroupName>>>,
295
+ R,
296
+ Group extends HttpApiGroup.Any = HttpApiGroup.WithName<Groups, GroupName>,
297
+ Endpoint extends HttpApiEndpoint.Any = HttpApiEndpoint.WithName<HttpApiGroup.Endpoints<Group>, EndpointName>
298
+ >(
299
+ api: HttpApi.HttpApi<ApiId, Groups>,
300
+ groupName: GroupName,
301
+ endpointName: EndpointName,
302
+ handler: NoInfer<
303
+ HttpApiEndpoint.HandlerWithName<
304
+ HttpApiGroup.Endpoints<HttpApiGroup.WithName<Groups, GroupName>>,
305
+ EndpointName,
306
+ never,
307
+ R
308
+ >
309
+ >
310
+ ): Effect.Effect<
311
+ Effect.Effect<
312
+ HttpServerResponse,
313
+ never,
314
+ | HttpServerRequest
315
+ | HttpRouter.RouteContext
316
+ | Request.ParsedSearchParams
317
+ | Exclude<R, HttpApiEndpoint.MiddlewareProvides<Endpoint>>
318
+ >,
319
+ never,
320
+ | HttpApiEndpoint.ServerServices<Endpoint>
321
+ | HttpApiEndpoint.Middleware<Endpoint>
322
+ | HttpApiEndpoint.MiddlewareServices<Endpoint>
323
+ | Etag.Generator
324
+ | FileSystem
325
+ | HttpPlatform
326
+ | Path
327
+ > =>
328
+ Effect.servicesWith((services: ServiceMap.ServiceMap<any>) => {
329
+ const group = api.groups[groupName] as unknown as HttpApiGroup.AnyWithProps
330
+ const endpoint = group.endpoints[endpointName] as unknown as HttpApiEndpoint.AnyWithProps
331
+ return Effect.succeed(handlerToHttpEffect(group, endpoint, services, handler as any, false))
332
+ })
333
+
287
334
  /**
288
335
  * @since 4.0.0
289
336
  * @category security
@@ -497,22 +544,23 @@ function decodePayload(
497
544
  }
498
545
  }
499
546
 
500
- function handlerToRoute(
547
+ function handlerToHttpEffect(
501
548
  group: HttpApiGroup.AnyWithProps,
502
- handler: Handlers.Item<any>,
503
- services: ServiceMap.ServiceMap<any>
504
- ): HttpRouter.Route<any, any> {
505
- const endpoint = handler.endpoint
549
+ endpoint: HttpApiEndpoint.AnyWithProps,
550
+ services: ServiceMap.ServiceMap<any>,
551
+ handler: HttpApiEndpoint.Handler<any, any, any>,
552
+ isRaw: boolean
553
+ ) {
506
554
  const encodeSuccess = Schema.encodeUnknownEffect(makeSuccessSchema(endpoint))
507
555
  const encodeError = Schema.encodeUnknownEffect(makeErrorSchema(endpoint))
508
556
  const decodeParams = UndefinedOr.map(endpoint.params, Schema.decodeUnknownEffect)
509
557
  const decodeHeaders = UndefinedOr.map(endpoint.headers, Schema.decodeUnknownEffect)
510
558
  const decodeQuery = UndefinedOr.map(endpoint.query, Schema.decodeUnknownEffect)
511
559
 
512
- const shouldParsePayload = endpoint.payload.size > 0 && !handler.isRaw
560
+ const shouldParsePayload = endpoint.payload.size > 0 && !isRaw
513
561
  const payloadBy = shouldParsePayload ? buildPayloadDecoders(endpoint.payload) : undefined
514
562
 
515
- const effect = applyMiddleware(
563
+ return applyMiddleware(
516
564
  group,
517
565
  endpoint,
518
566
  services,
@@ -545,7 +593,7 @@ function handlerToRoute(
545
593
  request.payload = yield* result
546
594
  }
547
595
  }
548
- const response = yield* handler.handler(request)
596
+ const response = yield* handler(request)
549
597
  return Response.isHttpServerResponse(response) ? response : yield* encodeSuccess(response)
550
598
  })
551
599
  ).pipe(
@@ -558,11 +606,18 @@ function handlerToRoute(
558
606
  }),
559
607
  Effect.provideServices(services)
560
608
  )
609
+ }
561
610
 
611
+ function handlerToRoute(
612
+ group: HttpApiGroup.AnyWithProps,
613
+ handler: Handlers.Item<any>,
614
+ services: ServiceMap.ServiceMap<any>
615
+ ): HttpRouter.Route<any, any> {
616
+ const endpoint = handler.endpoint
562
617
  return HttpRouter.route(
563
618
  endpoint.method,
564
619
  endpoint.path as HttpRouter.PathInput,
565
- effect,
620
+ handlerToHttpEffect(group, endpoint, services, handler.handler, handler.isRaw),
566
621
  { uninterruptible: handler.uninterruptible }
567
622
  )
568
623
  }
@@ -513,8 +513,8 @@ export type ServerServices<Endpoint> = Endpoint extends HttpApiEndpoint<
513
513
  | _Payload["DecodingServices"]
514
514
  | _Headers["DecodingServices"]
515
515
  | _Success["EncodingServices"]
516
- // Error services are handled globally
517
- // | _Error["EncodingServices"]
516
+ | _Error["EncodingServices"]
517
+ | HttpApiMiddleware.ErrorServicesEncode<_M>
518
518
  : never
519
519
 
520
520
  /**
@@ -668,10 +668,19 @@ export type MiddlewareServicesWithName<Endpoints extends Any, Name extends strin
668
668
  * @since 4.0.0
669
669
  * @category models
670
670
  */
671
- export type ExcludeProvided<Endpoints extends Any, Name extends string, R> = Exclude<
671
+ export type ExcludeProvidedWithName<Endpoints extends Any, Name extends string, R> = ExcludeProvided<
672
+ WithName<Endpoints, Name>,
673
+ R
674
+ >
675
+
676
+ /**
677
+ * @since 4.0.0
678
+ * @category models
679
+ */
680
+ export type ExcludeProvided<Endpoint extends Any, R> = Exclude<
672
681
  R,
673
682
  | HttpRouter.Provided
674
- | HttpApiMiddleware.Provides<MiddlewareWithName<Endpoints, Name>>
683
+ | HttpApiMiddleware.Provides<Middleware<Endpoint>>
675
684
  >
676
685
 
677
686
  /**
@@ -351,10 +351,9 @@ export function fromApi<Id extends string, Groups extends HttpApiGroup.Any>(
351
351
  ast: toEncodingAST(ast, encoding),
352
352
  path: ["paths", path, method, "responses", String(status), "content", contentType, "schema"]
353
353
  })
354
- op.responses[status].content = {
355
- [contentType]: {
356
- schema: {}
357
- }
354
+ op.responses[status].content ??= {}
355
+ op.responses[status].content[contentType] = {
356
+ schema: {}
358
357
  }
359
358
  })
360
359
  })
@@ -66,7 +66,7 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
66
66
  readonly reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
67
67
  }
68
68
  >,
69
- WithResponse extends true ? [_Success, HttpClientResponse] : _Success,
69
+ WithResponse extends true ? [_Success["Type"], HttpClientResponse] : _Success["Type"],
70
70
  _Error | HttpClientError.HttpClientError | SchemaError
71
71
  >
72
72
  : never
@@ -123,7 +123,7 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
123
123
  >
124
124
  ] ? Atom.Atom<
125
125
  AsyncResult.AsyncResult<
126
- WithResponse extends true ? [_Success, HttpClientResponse] : _Success,
126
+ WithResponse extends true ? [_Success["Type"], HttpClientResponse] : _Success["Type"],
127
127
  _Error | HttpClientError.HttpClientError | SchemaError
128
128
  >
129
129
  >
@@ -482,9 +482,7 @@ class RegistryImpl implements AtomRegistry {
482
482
 
483
483
  removeNodeTimeout(node: NodeImpl<any>): void {
484
484
  const bucket = this.nodeTimeoutBucket.get(node)
485
- if (bucket === undefined) {
486
- return
487
- }
485
+ if (bucket === undefined) return
488
486
  this.nodeTimeoutBucket.delete(node)
489
487
  this.scheduleNodeRemoval(node)
490
488
 
@@ -502,10 +500,8 @@ class RegistryImpl implements AtomRegistry {
502
500
  this.timeoutBuckets.delete(bucket)
503
501
 
504
502
  nodes.forEach((node) => {
505
- if (!node.canBeRemoved) {
506
- return
507
- }
508
503
  this.nodeTimeoutBucket.delete(node)
504
+ if (!node.canBeRemoved) return
509
505
  this.nodes.delete(atomKey(node.atom))
510
506
  this.onNodeRemoved?.(node)
511
507
  this.#currentSweepTTL = node.atom.idleTTL ?? this.defaultIdleTTL!