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.
- package/dist/Array.d.ts +8 -9
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js.map +1 -1
- package/dist/Chunk.d.ts +4 -4
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js.map +1 -1
- package/dist/Duration.d.ts +1 -1
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +1 -1
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +92 -1
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +30 -1
- package/dist/Effect.js.map +1 -1
- package/dist/Filter.d.ts +4 -4
- package/dist/Filter.d.ts.map +1 -1
- package/dist/Filter.js.map +1 -1
- package/dist/HashMap.d.ts +3 -3
- package/dist/HashMap.d.ts.map +1 -1
- package/dist/HashMap.js.map +1 -1
- package/dist/Iterable.d.ts +4 -5
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js.map +1 -1
- package/dist/Record.d.ts +4 -5
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js.map +1 -1
- package/dist/Runtime.d.ts.map +1 -1
- package/dist/Runtime.js +7 -1
- package/dist/Runtime.js.map +1 -1
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +4 -1
- package/dist/Schedule.js.map +1 -1
- package/dist/SchemaAST.js +6 -6
- package/dist/SchemaAST.js.map +1 -1
- package/dist/Stream.d.ts +7 -1
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +6 -2
- package/dist/Stream.js.map +1 -1
- package/dist/Trie.d.ts +3 -3
- package/dist/Trie.d.ts.map +1 -1
- package/dist/Trie.js.map +1 -1
- package/dist/TxHashMap.d.ts +3 -3
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js.map +1 -1
- package/dist/TxPubSub.d.ts +4 -4
- package/dist/TxPubSub.d.ts.map +1 -1
- package/dist/internal/effect.js +48 -38
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/trie.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +2 -2
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js +35 -42
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpServer.js +2 -1
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/http/HttpEffect.js +2 -2
- package/dist/unstable/http/HttpEffect.js.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +2 -2
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/internal/preResponseHandler.js +2 -2
- package/dist/unstable/http/internal/preResponseHandler.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +55 -0
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +37 -0
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +2 -2
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js +3 -3
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js +1 -1
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +5 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +5 -1
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +15 -13
- package/src/Chunk.ts +6 -6
- package/src/Duration.ts +2 -2
- package/src/Effect.ts +102 -1
- package/src/Filter.ts +4 -5
- package/src/HashMap.ts +3 -3
- package/src/Iterable.ts +6 -7
- package/src/Record.ts +6 -7
- package/src/Runtime.ts +7 -1
- package/src/Schedule.ts +4 -1
- package/src/SchemaAST.ts +6 -6
- package/src/Stream.ts +13 -4
- package/src/Trie.ts +3 -3
- package/src/TxHashMap.ts +4 -4
- package/src/TxPubSub.ts +4 -4
- package/src/internal/effect.ts +107 -49
- package/src/internal/hashMap.ts +3 -4
- package/src/internal/trie.ts +3 -4
- package/src/unstable/ai/Chat.ts +36 -51
- package/src/unstable/ai/LanguageModel.ts +0 -1
- package/src/unstable/ai/McpServer.ts +2 -1
- package/src/unstable/ai/Tool.ts +1 -1
- package/src/unstable/http/HttpEffect.ts +2 -2
- package/src/unstable/http/HttpMiddleware.ts +3 -3
- package/src/unstable/http/HttpServerRequest.ts +1 -1
- package/src/unstable/http/internal/preResponseHandler.ts +3 -3
- package/src/unstable/httpapi/HttpApiClient.ts +82 -1
- package/src/unstable/schema/VariantSchema.ts +3 -3
- package/src/unstable/workflow/Workflow.ts +5 -1
- 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/
|
|
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/
|
|
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
|
-
|
|
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) =>
|
|
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
|
|
512
|
+
export const layerMemory: Layer.Layer<WorkflowEngine> = Layer.effect(WorkflowEngine)(
|
|
509
513
|
Effect.gen(function*() {
|
|
510
514
|
const scope = yield* Effect.scope
|
|
511
515
|
|