effect 4.0.0-beta.20 → 4.0.0-beta.22

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 (114) hide show
  1. package/dist/Array.d.ts +8 -9
  2. package/dist/Array.d.ts.map +1 -1
  3. package/dist/Array.js.map +1 -1
  4. package/dist/Chunk.d.ts +4 -4
  5. package/dist/Chunk.d.ts.map +1 -1
  6. package/dist/Chunk.js.map +1 -1
  7. package/dist/Duration.d.ts +1 -1
  8. package/dist/Duration.d.ts.map +1 -1
  9. package/dist/Duration.js +1 -1
  10. package/dist/Duration.js.map +1 -1
  11. package/dist/Effect.d.ts +92 -1
  12. package/dist/Effect.d.ts.map +1 -1
  13. package/dist/Effect.js +30 -1
  14. package/dist/Effect.js.map +1 -1
  15. package/dist/Filter.d.ts +4 -4
  16. package/dist/Filter.d.ts.map +1 -1
  17. package/dist/Filter.js.map +1 -1
  18. package/dist/HashMap.d.ts +3 -3
  19. package/dist/HashMap.d.ts.map +1 -1
  20. package/dist/HashMap.js.map +1 -1
  21. package/dist/Iterable.d.ts +4 -5
  22. package/dist/Iterable.d.ts.map +1 -1
  23. package/dist/Iterable.js.map +1 -1
  24. package/dist/Record.d.ts +4 -5
  25. package/dist/Record.d.ts.map +1 -1
  26. package/dist/Record.js.map +1 -1
  27. package/dist/Runtime.d.ts.map +1 -1
  28. package/dist/Runtime.js +7 -1
  29. package/dist/Runtime.js.map +1 -1
  30. package/dist/Schedule.d.ts.map +1 -1
  31. package/dist/Schedule.js +4 -1
  32. package/dist/Schedule.js.map +1 -1
  33. package/dist/SchemaAST.js +6 -6
  34. package/dist/SchemaAST.js.map +1 -1
  35. package/dist/Stream.d.ts +7 -1
  36. package/dist/Stream.d.ts.map +1 -1
  37. package/dist/Stream.js +6 -2
  38. package/dist/Stream.js.map +1 -1
  39. package/dist/Trie.d.ts +3 -3
  40. package/dist/Trie.d.ts.map +1 -1
  41. package/dist/Trie.js.map +1 -1
  42. package/dist/TxHashMap.d.ts +3 -3
  43. package/dist/TxHashMap.d.ts.map +1 -1
  44. package/dist/TxHashMap.js.map +1 -1
  45. package/dist/TxPubSub.d.ts +4 -4
  46. package/dist/TxPubSub.d.ts.map +1 -1
  47. package/dist/internal/effect.js +48 -38
  48. package/dist/internal/effect.js.map +1 -1
  49. package/dist/internal/hashMap.js.map +1 -1
  50. package/dist/internal/trie.js.map +1 -1
  51. package/dist/unstable/ai/Chat.d.ts +2 -2
  52. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  53. package/dist/unstable/ai/Chat.js +35 -42
  54. package/dist/unstable/ai/Chat.js.map +1 -1
  55. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  56. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  57. package/dist/unstable/ai/McpServer.js +2 -1
  58. package/dist/unstable/ai/McpServer.js.map +1 -1
  59. package/dist/unstable/ai/Tool.d.ts +1 -1
  60. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  61. package/dist/unstable/http/HttpEffect.js +2 -2
  62. package/dist/unstable/http/HttpEffect.js.map +1 -1
  63. package/dist/unstable/http/HttpMiddleware.js +2 -2
  64. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  65. package/dist/unstable/http/HttpServerRequest.d.ts +1 -1
  66. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  67. package/dist/unstable/http/internal/preResponseHandler.js +2 -2
  68. package/dist/unstable/http/internal/preResponseHandler.js.map +1 -1
  69. package/dist/unstable/httpapi/HttpApiClient.d.ts +55 -0
  70. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  71. package/dist/unstable/httpapi/HttpApiClient.js +37 -0
  72. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  73. package/dist/unstable/schema/VariantSchema.d.ts +2 -2
  74. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  75. package/dist/unstable/schema/VariantSchema.js +3 -3
  76. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  77. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  78. package/dist/unstable/workflow/Workflow.js +1 -1
  79. package/dist/unstable/workflow/Workflow.js.map +1 -1
  80. package/dist/unstable/workflow/WorkflowEngine.d.ts +5 -1
  81. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  82. package/dist/unstable/workflow/WorkflowEngine.js +5 -1
  83. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  84. package/package.json +1 -1
  85. package/src/Array.ts +15 -13
  86. package/src/Chunk.ts +6 -6
  87. package/src/Duration.ts +2 -2
  88. package/src/Effect.ts +102 -1
  89. package/src/Filter.ts +4 -5
  90. package/src/HashMap.ts +3 -3
  91. package/src/Iterable.ts +6 -7
  92. package/src/Record.ts +6 -7
  93. package/src/Runtime.ts +7 -1
  94. package/src/Schedule.ts +4 -1
  95. package/src/SchemaAST.ts +6 -6
  96. package/src/Stream.ts +13 -4
  97. package/src/Trie.ts +3 -3
  98. package/src/TxHashMap.ts +4 -4
  99. package/src/TxPubSub.ts +4 -4
  100. package/src/internal/effect.ts +107 -49
  101. package/src/internal/hashMap.ts +3 -4
  102. package/src/internal/trie.ts +3 -4
  103. package/src/unstable/ai/Chat.ts +36 -51
  104. package/src/unstable/ai/LanguageModel.ts +0 -1
  105. package/src/unstable/ai/McpServer.ts +2 -1
  106. package/src/unstable/ai/Tool.ts +1 -1
  107. package/src/unstable/http/HttpEffect.ts +2 -2
  108. package/src/unstable/http/HttpMiddleware.ts +3 -3
  109. package/src/unstable/http/HttpServerRequest.ts +1 -1
  110. package/src/unstable/http/internal/preResponseHandler.ts +3 -3
  111. package/src/unstable/httpapi/HttpApiClient.ts +82 -1
  112. package/src/unstable/schema/VariantSchema.ts +3 -3
  113. package/src/unstable/workflow/Workflow.ts +5 -1
  114. package/src/unstable/workflow/WorkflowEngine.ts +5 -1
@@ -120,6 +120,44 @@ export declare namespace Client {
120
120
  never
121
121
  }
122
122
 
123
+ type ApiGroups<Api extends HttpApi.Any> = Api extends HttpApi.HttpApi<infer _ApiId, infer Groups> ? Groups : never
124
+
125
+ type EndpointId<Endpoint extends HttpApiEndpoint.Any> = Endpoint extends {
126
+ readonly method: infer Method extends HttpMethod.HttpMethod
127
+ readonly path: infer Path extends string
128
+ } ? `${Method} ${Path}`
129
+ : never
130
+
131
+ type EndpointWithId<Endpoints extends HttpApiEndpoint.Any, Id extends string> = Id extends
132
+ `${infer Method extends HttpMethod.HttpMethod} ${infer Path extends string}` ?
133
+ Extract<Endpoints, { readonly method: Method; readonly path: Path }> :
134
+ never
135
+
136
+ type UrlBuilderRequest<Endpoint extends HttpApiEndpoint.Any> = (
137
+ & ([HttpApiEndpoint.Params<Endpoint>["Encoded"]] extends [never] ? {}
138
+ : { readonly params: HttpApiEndpoint.Params<Endpoint>["Encoded"] })
139
+ & ([HttpApiEndpoint.Query<Endpoint>["Encoded"]] extends [never] ? {}
140
+ : { readonly query: HttpApiEndpoint.Query<Endpoint>["Encoded"] })
141
+ ) extends infer Request ? keyof Request extends never ? void | undefined : Request
142
+ : never
143
+
144
+ type UrlBuilderArgs<Endpoint extends HttpApiEndpoint.Any> = [UrlBuilderRequest<Endpoint>] extends [void | undefined] ?
145
+ [request?: UrlBuilderRequest<Endpoint>]
146
+ : [request: UrlBuilderRequest<Endpoint>]
147
+
148
+ /**
149
+ * @since 4.0.0
150
+ * @category models
151
+ */
152
+ export type UrlBuilder<Api extends HttpApi.Any> = <
153
+ const GroupName extends HttpApiGroup.Name<ApiGroups<Api>>,
154
+ const Id extends EndpointId<HttpApiGroup.EndpointsWithName<ApiGroups<Api>, GroupName>>
155
+ >(
156
+ group: GroupName,
157
+ endpoint: Id,
158
+ ...args: UrlBuilderArgs<EndpointWithId<HttpApiGroup.EndpointsWithName<ApiGroups<Api>, GroupName>, Id>>
159
+ ) => string
160
+
123
161
  const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Any, E, R>(
124
162
  api: HttpApi.HttpApi<ApiId, Groups>,
125
163
  options: {
@@ -438,6 +476,49 @@ export const endpoint = <
438
476
  }).pipe(Effect.map(() => client)) as any
439
477
  }
440
478
 
479
+ /**
480
+ * Creates a type-safe URL builder keyed by `${method} ${path}`.
481
+ *
482
+ * @example
483
+ * ```ts
484
+ * import { Schema } from "effect"
485
+ * import { HttpApi, HttpApiClient, HttpApiEndpoint, HttpApiGroup } from "effect/unstable/httpapi"
486
+ *
487
+ * const Api = HttpApi.make("Api").add(
488
+ * HttpApiGroup.make("users").add(
489
+ * HttpApiEndpoint.get("getUser", "/users/:id", {
490
+ * params: { id: Schema.String }
491
+ * })
492
+ * )
493
+ * )
494
+ *
495
+ * const buildUrl = HttpApiClient.urlBuilder<typeof Api>({
496
+ * baseUrl: "https://api.example.com"
497
+ * })
498
+ *
499
+ * buildUrl("users", "GET /users/:id", {
500
+ * params: { id: "123" }
501
+ * })
502
+ * //=> "https://api.example.com/users/123"
503
+ * ```
504
+ * @since 4.0.0
505
+ * @category constructors
506
+ */
507
+ export const urlBuilder = <Api extends HttpApi.Any>(options?: {
508
+ readonly baseUrl?: URL | string | undefined
509
+ }): UrlBuilder<Api> => {
510
+ return ((_: string, endpoint: string, request?: {
511
+ readonly params?: Record<string, string | undefined> | undefined
512
+ readonly query?: UrlParams.Input | undefined
513
+ }) => {
514
+ const path = endpoint.slice(endpoint.indexOf(" ") + 1)
515
+ const withParams = request?.params === undefined ? path : compilePath(path)(request.params)
516
+ const query = request?.query === undefined ? "" : UrlParams.toString(UrlParams.fromInput(request.query))
517
+ const url = query === "" ? withParams : `${withParams}?${query}`
518
+ return options?.baseUrl === undefined ? url : new URL(url, options.baseUrl.toString()).toString()
519
+ }) as UrlBuilder<Api>
520
+ }
521
+
441
522
  // ----------------------------------------------------------------------------
442
523
 
443
524
  const paramsRegExp = /:(\w+)\??/g
@@ -448,7 +529,7 @@ const compilePath = (path: string) => {
448
529
  if (len === 1) {
449
530
  return (_: any) => path
450
531
  }
451
- return (params: Record<string, string>) => {
532
+ return (params: Record<string, string | undefined>) => {
452
533
  let url = segments[0]
453
534
  for (let i = 1; i < len; i++) {
454
535
  if (i % 2 === 0) {
@@ -17,7 +17,7 @@ import * as Struct_ from "../../Struct.ts"
17
17
  * @since 4.0.0
18
18
  * @category Type IDs
19
19
  */
20
- export const TypeId = "~effect/unstable/schema/VariantSchema"
20
+ export const TypeId = "~effect/schema/VariantSchema"
21
21
 
22
22
  const cacheSymbol = Symbol.for(`${TypeId}/cache`)
23
23
 
@@ -71,7 +71,7 @@ export declare namespace Struct {
71
71
  }
72
72
  }
73
73
 
74
- const FieldTypeId = "~effect/unstable/schema/VariantSchema/Field"
74
+ const FieldTypeId = "~effect/schema/VariantSchema/Field"
75
75
 
76
76
  /**
77
77
  * @since 4.0.0
@@ -542,7 +542,7 @@ const Union = <Members extends ReadonlyArray<Struct<any>>, Variants extends Read
542
542
  members: Members,
543
543
  variants: Variants
544
544
  ) => {
545
- class VariantUnion extends (Schema.Union(members.filter((member) => Schema.isSchema(member))) as any) {}
545
+ const VariantUnion = Schema.Union(members.filter((member) => Schema.isSchema(member))) as any
546
546
  for (const variant of variants) {
547
547
  Object.defineProperty(VariantUnion, variant, {
548
548
  value: Schema.Union(members.map((member) => extract(member, variant)))
@@ -374,7 +374,11 @@ export const make = <
374
374
  return yield* engine.register(self, execute)
375
375
  })
376
376
  ),
377
- executionId: (payload) => makeExecutionId(self.payloadSchema.make(payload)),
377
+ executionId: (payload) =>
378
+ Effect.flatMap(
379
+ Effect.sync(() => self.payloadSchema.makeUnsafe(payload)),
380
+ makeExecutionId
381
+ ),
378
382
  withCompensation
379
383
  }
380
384
 
@@ -502,10 +502,14 @@ const defaultRetrySchedule = Schedule.exponential(200, 1.5).pipe(
502
502
  )
503
503
 
504
504
  /**
505
+ * A in-memory implementation of the WorkflowEngine. This is useful for testing
506
+ * and local development, but is not suitable for production use as it does not
507
+ * provide durability guarantees.
508
+ *
505
509
  * @since 4.0.0
506
510
  * @category Layers
507
511
  */
508
- export const layer: Layer.Layer<WorkflowEngine> = Layer.effect(WorkflowEngine)(
512
+ export const layerMemory: Layer.Layer<WorkflowEngine> = Layer.effect(WorkflowEngine)(
509
513
  Effect.gen(function*() {
510
514
  const scope = yield* Effect.scope
511
515