effect 4.0.0-beta.19 → 4.0.0-beta.20
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/Channel.d.ts +6 -6
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js.map +1 -1
- package/dist/Config.d.ts +5 -6
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +3 -3
- package/dist/Config.js.map +1 -1
- package/dist/Effect.d.ts +22 -22
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +3 -3
- package/dist/Effect.js.map +1 -1
- package/dist/ErrorReporter.js +2 -2
- package/dist/ErrorReporter.js.map +1 -1
- package/dist/Layer.d.ts +9 -9
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js.map +1 -1
- package/dist/Schedule.d.ts +14 -6
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +25 -9
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +21 -0
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js.map +1 -1
- package/dist/ServiceMap.d.ts +39 -30
- package/dist/ServiceMap.d.ts.map +1 -1
- package/dist/ServiceMap.js +3 -3
- package/dist/ServiceMap.js.map +1 -1
- package/dist/Sink.d.ts +2 -2
- package/dist/Sink.d.ts.map +1 -1
- package/dist/Sink.js.map +1 -1
- package/dist/Stream.d.ts +6 -6
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/effect.js +2 -2
- package/dist/internal/effect.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +2 -2
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/AiError.d.ts +90 -10
- package/dist/unstable/ai/AiError.d.ts.map +1 -1
- package/dist/unstable/ai/AiError.js +11 -12
- package/dist/unstable/ai/AiError.js.map +1 -1
- package/dist/unstable/ai/Model.d.ts +25 -7
- package/dist/unstable/ai/Model.d.ts.map +1 -1
- package/dist/unstable/ai/Model.js +22 -6
- package/dist/unstable/ai/Model.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +3 -3
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/ai/index.d.ts +1 -1
- package/dist/unstable/ai/index.js +1 -1
- package/dist/unstable/cli/Command.d.ts +6 -6
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +2 -2
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts +2 -2
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.js +20 -20
- package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts +3 -3
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +7 -2
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +3 -3
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +3 -3
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -4
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSecurity.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiSecurity.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSecurity.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/process/ChildProcess.d.ts +3 -126
- package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
- package/dist/unstable/process/ChildProcess.js +1 -65
- package/dist/unstable/process/ChildProcess.js.map +1 -1
- package/dist/unstable/process/ChildProcessSpawner.d.ts +39 -7
- package/dist/unstable/process/ChildProcessSpawner.d.ts.map +1 -1
- package/dist/unstable/process/ChildProcessSpawner.js +21 -1
- package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +1 -1
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts +2 -2
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcGroup.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +3 -3
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
- package/dist/unstable/sql/SqlClient.d.ts +1 -1
- package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +1 -1
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Channel.ts +9 -9
- package/src/Config.ts +9 -9
- package/src/Effect.ts +24 -32
- package/src/ErrorReporter.ts +2 -2
- package/src/Layer.ts +11 -15
- package/src/Schedule.ts +35 -19
- package/src/Schema.ts +21 -0
- package/src/ServiceMap.ts +47 -38
- package/src/Sink.ts +3 -3
- package/src/Stream.ts +9 -9
- package/src/index.ts +1 -1
- package/src/internal/effect.ts +24 -24
- package/src/testing/TestSchema.ts +2 -2
- package/src/unstable/ai/AiError.ts +95 -42
- package/src/unstable/ai/Model.ts +40 -9
- package/src/unstable/ai/Tool.ts +4 -4
- package/src/unstable/ai/index.ts +1 -1
- package/src/unstable/cli/Command.ts +9 -12
- package/src/unstable/cli/internal/command.ts +2 -2
- package/src/unstable/cluster/Entity.ts +4 -4
- package/src/unstable/cluster/ShardingConfig.ts +20 -20
- package/src/unstable/httpapi/HttpApi.ts +5 -5
- package/src/unstable/httpapi/HttpApiBuilder.ts +2 -2
- package/src/unstable/httpapi/HttpApiClient.ts +11 -3
- package/src/unstable/httpapi/HttpApiEndpoint.ts +7 -7
- package/src/unstable/httpapi/HttpApiGroup.ts +6 -6
- package/src/unstable/httpapi/HttpApiMiddleware.ts +4 -4
- package/src/unstable/httpapi/HttpApiSecurity.ts +3 -3
- package/src/unstable/httpapi/OpenApi.ts +2 -2
- package/src/unstable/process/ChildProcess.ts +4 -206
- package/src/unstable/process/ChildProcessSpawner.ts +69 -14
- package/src/unstable/rpc/Rpc.ts +2 -2
- package/src/unstable/rpc/RpcGroup.ts +4 -4
- package/src/unstable/rpc/RpcMiddleware.ts +3 -3
- package/src/unstable/sql/SqlClient.ts +1 -1
- package/src/unstable/workflow/Workflow.ts +1 -1
|
@@ -32,7 +32,7 @@ import * as HttpApiSchema from "./HttpApiSchema.ts"
|
|
|
32
32
|
* @since 4.0.0
|
|
33
33
|
* @category models
|
|
34
34
|
*/
|
|
35
|
-
export type Client<Groups extends HttpApiGroup.Any, E, R> = Simplify<
|
|
35
|
+
export type Client<Groups extends HttpApiGroup.Any, E = HttpApiSchemaError, R = never> = Simplify<
|
|
36
36
|
& {
|
|
37
37
|
readonly [Group in Extract<Groups, { readonly topLevel: false }> as HttpApiGroup.Name<Group>]: Client.Group<
|
|
38
38
|
Group,
|
|
@@ -46,6 +46,14 @@ export type Client<Groups extends HttpApiGroup.Any, E, R> = Simplify<
|
|
|
46
46
|
}
|
|
47
47
|
>
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* @since 4.0.0
|
|
51
|
+
* @category models
|
|
52
|
+
*/
|
|
53
|
+
export type ForApi<Api extends HttpApi.Any, E = HttpApiSchemaError, R = never> = Api extends
|
|
54
|
+
HttpApi.HttpApi<infer _Id, infer Groups> ? Client<Groups, E, R> :
|
|
55
|
+
never
|
|
56
|
+
|
|
49
57
|
/**
|
|
50
58
|
* @since 4.0.0
|
|
51
59
|
* @category models
|
|
@@ -128,7 +136,7 @@ const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Any, E, R>
|
|
|
128
136
|
readonly group: HttpApiGroup.AnyWithProps
|
|
129
137
|
readonly endpoint: HttpApiEndpoint.AnyWithProps
|
|
130
138
|
readonly mergedAnnotations: ServiceMap.ServiceMap<never>
|
|
131
|
-
readonly middleware: ReadonlySet<HttpApiMiddleware.
|
|
139
|
+
readonly middleware: ReadonlySet<HttpApiMiddleware.AnyService>
|
|
132
140
|
readonly successes: ReadonlyMap<number, readonly [Schema.Top, ...Array<Schema.Top>]>
|
|
133
141
|
readonly errors: ReadonlyMap<number, readonly [Schema.Top, ...Array<Schema.Top>]>
|
|
134
142
|
readonly endpointFn: Function
|
|
@@ -314,7 +322,7 @@ export const make = <ApiId extends string, Groups extends HttpApiGroup.Any>(
|
|
|
314
322
|
readonly baseUrl?: URL | string | undefined
|
|
315
323
|
}
|
|
316
324
|
): Effect.Effect<
|
|
317
|
-
Client<Groups
|
|
325
|
+
Client<Groups>,
|
|
318
326
|
never,
|
|
319
327
|
HttpClient.HttpClient | HttpApiGroup.MiddlewareClient<Groups>
|
|
320
328
|
> =>
|
|
@@ -77,7 +77,7 @@ export interface HttpApiEndpoint<
|
|
|
77
77
|
readonly success: ReadonlySet<Schema.Top>
|
|
78
78
|
readonly error: ReadonlySet<Schema.Top>
|
|
79
79
|
readonly annotations: ServiceMap.ServiceMap<never>
|
|
80
|
-
readonly middlewares: ReadonlySet<ServiceMap.
|
|
80
|
+
readonly middlewares: ReadonlySet<ServiceMap.Key<Middleware, any>>
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* Add a prefix to the path of the endpoint.
|
|
@@ -101,7 +101,7 @@ export interface HttpApiEndpoint<
|
|
|
101
101
|
/**
|
|
102
102
|
* Add an `HttpApiMiddleware` to the endpoint.
|
|
103
103
|
*/
|
|
104
|
-
middleware<I extends HttpApiMiddleware.AnyId, S>(middleware: ServiceMap.
|
|
104
|
+
middleware<I extends HttpApiMiddleware.AnyId, S>(middleware: ServiceMap.Key<I, S>): HttpApiEndpoint<
|
|
105
105
|
Name,
|
|
106
106
|
Method,
|
|
107
107
|
Path,
|
|
@@ -119,7 +119,7 @@ export interface HttpApiEndpoint<
|
|
|
119
119
|
* Add an annotation on the endpoint.
|
|
120
120
|
*/
|
|
121
121
|
annotate<I, S>(
|
|
122
|
-
key: ServiceMap.
|
|
122
|
+
key: ServiceMap.Key<I, S>,
|
|
123
123
|
value: Types.NoInfer<S>
|
|
124
124
|
): HttpApiEndpoint<
|
|
125
125
|
Name,
|
|
@@ -174,7 +174,7 @@ export function getSuccessSchemas(endpoint: AnyWithProps): [Schema.Top, ...Array
|
|
|
174
174
|
export function getErrorSchemas(endpoint: AnyWithProps): [Schema.Top, ...Array<Schema.Top>] {
|
|
175
175
|
const schemas = new Set<Schema.Top>(endpoint.error)
|
|
176
176
|
for (const middleware of endpoint.middlewares) {
|
|
177
|
-
const key = middleware as any as HttpApiMiddleware.
|
|
177
|
+
const key = middleware as any as HttpApiMiddleware.AnyService
|
|
178
178
|
if (key.error !== undefined) {
|
|
179
179
|
schemas.add(key.error)
|
|
180
180
|
}
|
|
@@ -787,13 +787,13 @@ const Proto = {
|
|
|
787
787
|
path: HttpRouter.prefixPath(this.path, prefix)
|
|
788
788
|
})
|
|
789
789
|
},
|
|
790
|
-
middleware(this: AnyWithProps, middleware: HttpApiMiddleware.
|
|
790
|
+
middleware(this: AnyWithProps, middleware: HttpApiMiddleware.AnyService) {
|
|
791
791
|
return makeProto({
|
|
792
792
|
...this,
|
|
793
793
|
middlewares: new Set([...this.middlewares, middleware as any])
|
|
794
794
|
})
|
|
795
795
|
},
|
|
796
|
-
annotate(this: AnyWithProps, key: ServiceMap.
|
|
796
|
+
annotate(this: AnyWithProps, key: ServiceMap.Key<any, any>, value: any) {
|
|
797
797
|
return makeProto({
|
|
798
798
|
...this,
|
|
799
799
|
annotations: ServiceMap.add(this.annotations, key, value)
|
|
@@ -830,7 +830,7 @@ function makeProto<
|
|
|
830
830
|
readonly success: ReadonlySet<Schema.Top>
|
|
831
831
|
readonly error: ReadonlySet<Schema.Top>
|
|
832
832
|
readonly annotations: ServiceMap.ServiceMap<never>
|
|
833
|
-
readonly middlewares: ReadonlySet<ServiceMap.
|
|
833
|
+
readonly middlewares: ReadonlySet<ServiceMap.Key<Middleware, any>>
|
|
834
834
|
}): HttpApiEndpoint<
|
|
835
835
|
Name,
|
|
836
836
|
Method,
|
|
@@ -61,7 +61,7 @@ export interface HttpApiGroup<
|
|
|
61
61
|
* Endpoints added after this api is called **will not** have the middleware
|
|
62
62
|
* applied.
|
|
63
63
|
*/
|
|
64
|
-
middleware<I extends HttpApiMiddleware.AnyId, S>(middleware: ServiceMap.
|
|
64
|
+
middleware<I extends HttpApiMiddleware.AnyId, S>(middleware: ServiceMap.Key<I, S>): HttpApiGroup<
|
|
65
65
|
Id,
|
|
66
66
|
HttpApiEndpoint.AddMiddleware<Endpoints, I>,
|
|
67
67
|
TopLevel
|
|
@@ -75,7 +75,7 @@ export interface HttpApiGroup<
|
|
|
75
75
|
/**
|
|
76
76
|
* Add an annotation to an `HttpApiGroup`.
|
|
77
77
|
*/
|
|
78
|
-
annotate<I, S>(key: ServiceMap.
|
|
78
|
+
annotate<I, S>(key: ServiceMap.Key<I, S>, value: S): HttpApiGroup<Id, Endpoints, TopLevel>
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* For each endpoint in an `HttpApiGroup`, update the annotations with a new
|
|
@@ -91,7 +91,7 @@ export interface HttpApiGroup<
|
|
|
91
91
|
* Note that this will only add the annotation to the endpoints before this api
|
|
92
92
|
* is called.
|
|
93
93
|
*/
|
|
94
|
-
annotateEndpoints<I, S>(key: ServiceMap.
|
|
94
|
+
annotateEndpoints<I, S>(key: ServiceMap.Key<I, S>, value: S): HttpApiGroup<Id, Endpoints, TopLevel>
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/**
|
|
@@ -238,7 +238,7 @@ const Proto = {
|
|
|
238
238
|
annotations: this.annotations
|
|
239
239
|
})
|
|
240
240
|
},
|
|
241
|
-
middleware(this: AnyWithProps, middleware: HttpApiMiddleware.
|
|
241
|
+
middleware(this: AnyWithProps, middleware: HttpApiMiddleware.AnyService) {
|
|
242
242
|
return makeProto({
|
|
243
243
|
identifier: this.identifier,
|
|
244
244
|
topLevel: this.topLevel,
|
|
@@ -254,7 +254,7 @@ const Proto = {
|
|
|
254
254
|
annotations: ServiceMap.merge(this.annotations, annotations)
|
|
255
255
|
})
|
|
256
256
|
},
|
|
257
|
-
annotate<I, S>(this: AnyWithProps, annotation: ServiceMap.
|
|
257
|
+
annotate<I, S>(this: AnyWithProps, annotation: ServiceMap.Key<I, S>, value: S) {
|
|
258
258
|
return makeProto({
|
|
259
259
|
identifier: this.identifier,
|
|
260
260
|
topLevel: this.topLevel,
|
|
@@ -270,7 +270,7 @@ const Proto = {
|
|
|
270
270
|
annotations: this.annotations
|
|
271
271
|
})
|
|
272
272
|
},
|
|
273
|
-
annotateEndpoints<I, S>(this: AnyWithProps, annotation: ServiceMap.
|
|
273
|
+
annotateEndpoints<I, S>(this: AnyWithProps, annotation: ServiceMap.Key<I, S>, value: S) {
|
|
274
274
|
return makeProto({
|
|
275
275
|
identifier: this.identifier,
|
|
276
276
|
topLevel: this.topLevel,
|
|
@@ -25,7 +25,7 @@ const SecurityTypeId = "~effect/httpapi/HttpApiMiddleware/Security"
|
|
|
25
25
|
* @since 4.0.0
|
|
26
26
|
* @category guards
|
|
27
27
|
*/
|
|
28
|
-
export const isSecurity = (u:
|
|
28
|
+
export const isSecurity = (u: AnyService): u is AnyServiceSecurity => hasProperty(u, SecurityTypeId)
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* @since 4.0.0
|
|
@@ -87,7 +87,7 @@ export interface ForClient<Id> {
|
|
|
87
87
|
* @since 4.0.0
|
|
88
88
|
* @category models
|
|
89
89
|
*/
|
|
90
|
-
export interface
|
|
90
|
+
export interface AnyService extends ServiceMap.Key<any, any> {
|
|
91
91
|
readonly [TypeId]: typeof TypeId
|
|
92
92
|
readonly provides: any
|
|
93
93
|
readonly error: Schema.Top
|
|
@@ -99,7 +99,7 @@ export interface AnyKey extends ServiceMap.Service<any, any> {
|
|
|
99
99
|
* @since 4.0.0
|
|
100
100
|
* @category models
|
|
101
101
|
*/
|
|
102
|
-
export interface
|
|
102
|
+
export interface AnyServiceSecurity extends AnyService {
|
|
103
103
|
readonly [SecurityTypeId]: typeof SecurityTypeId
|
|
104
104
|
readonly security: Record<string, HttpApiSecurity.HttpApiSecurity>
|
|
105
105
|
}
|
|
@@ -297,7 +297,7 @@ export const Service = <
|
|
|
297
297
|
* @category client
|
|
298
298
|
*/
|
|
299
299
|
export const layerClient = <Id extends AnyId, S, R, EX = never, RX = never>(
|
|
300
|
-
tag: ServiceMap.
|
|
300
|
+
tag: ServiceMap.Key<Id, S>,
|
|
301
301
|
service:
|
|
302
302
|
| HttpApiMiddlewareClient<Id[typeof TypeId]["error"]["Type"], Id[typeof TypeId]["clientError"], R>
|
|
303
303
|
| Effect.Effect<
|
|
@@ -161,15 +161,15 @@ export const annotate: {
|
|
|
161
161
|
* @since 4.0.0
|
|
162
162
|
* @category annotations
|
|
163
163
|
*/
|
|
164
|
-
<I, S>(service: ServiceMap.
|
|
164
|
+
<I, S>(service: ServiceMap.Key<I, S>, value: S): <A extends HttpApiSecurity>(self: A) => A
|
|
165
165
|
/**
|
|
166
166
|
* @since 4.0.0
|
|
167
167
|
* @category annotations
|
|
168
168
|
*/
|
|
169
|
-
<A extends HttpApiSecurity, I, S>(self: A, service: ServiceMap.
|
|
169
|
+
<A extends HttpApiSecurity, I, S>(self: A, service: ServiceMap.Key<I, S>, value: S): A
|
|
170
170
|
} = dual(
|
|
171
171
|
3,
|
|
172
|
-
<A extends HttpApiSecurity, I, S>(self: A, service: ServiceMap.
|
|
172
|
+
<A extends HttpApiSecurity, I, S>(self: A, service: ServiceMap.Key<I, S>, value: S): A =>
|
|
173
173
|
Object.assign(Object.create(Proto), {
|
|
174
174
|
...self,
|
|
175
175
|
annotations: ServiceMap.add(self.annotations, service, value)
|
|
@@ -111,7 +111,7 @@ export class Transform extends ServiceMap.Service<
|
|
|
111
111
|
(openApiSpec: Record<string, any>) => Record<string, any>
|
|
112
112
|
>()("effect/httpapi/OpenApi/Transform") {}
|
|
113
113
|
|
|
114
|
-
const servicesPartial = <Tags extends Record<string, ServiceMap.
|
|
114
|
+
const servicesPartial = <Tags extends Record<string, ServiceMap.Key<any, any> | ServiceMap.Key<never, any>>>(
|
|
115
115
|
tags: Tags
|
|
116
116
|
): (
|
|
117
117
|
options: {
|
|
@@ -175,7 +175,7 @@ const apiCache = new WeakMap<HttpApi.Any, OpenAPISpec>()
|
|
|
175
175
|
*/
|
|
176
176
|
function processAnnotation<Services, S, I>(
|
|
177
177
|
ctx: ServiceMap.ServiceMap<Services>,
|
|
178
|
-
annotation: ServiceMap.
|
|
178
|
+
annotation: ServiceMap.Key<I, S>,
|
|
179
179
|
f: (s: S) => void
|
|
180
180
|
) {
|
|
181
181
|
const o = ServiceMap.getOption(ctx, annotation)
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
* @since 4.0.0
|
|
42
42
|
*/
|
|
43
43
|
import type * as Duration from "../../Duration.ts"
|
|
44
|
-
import * as Effect from "../../Effect.ts"
|
|
44
|
+
import type * as Effect from "../../Effect.ts"
|
|
45
45
|
import { dual } from "../../Function.ts"
|
|
46
46
|
import { PipeInspectableProto, YieldableProto } from "../../internal/core.ts"
|
|
47
47
|
import type { Pipeable } from "../../Pipeable.ts"
|
|
@@ -49,9 +49,8 @@ import type * as PlatformError from "../../PlatformError.ts"
|
|
|
49
49
|
import * as Predicate from "../../Predicate.ts"
|
|
50
50
|
import type * as Scope from "../../Scope.ts"
|
|
51
51
|
import type * as Sink from "../../Sink.ts"
|
|
52
|
-
import * as Stream from "../../Stream.ts"
|
|
53
|
-
import type
|
|
54
|
-
import { ChildProcessSpawner } from "./ChildProcessSpawner.ts"
|
|
52
|
+
import type * as Stream from "../../Stream.ts"
|
|
53
|
+
import { type ChildProcessHandle, ChildProcessSpawner } from "./ChildProcessSpawner.ts"
|
|
55
54
|
|
|
56
55
|
const TypeId = "~effect/unstable/process/ChildProcess"
|
|
57
56
|
|
|
@@ -515,7 +514,7 @@ const Proto = {
|
|
|
515
514
|
...YieldableProto,
|
|
516
515
|
[TypeId]: TypeId,
|
|
517
516
|
asEffect(this: Command) {
|
|
518
|
-
return spawn(this)
|
|
517
|
+
return ChildProcessSpawner.use((_) => _.spawn(this))
|
|
519
518
|
}
|
|
520
519
|
}
|
|
521
520
|
|
|
@@ -1118,207 +1117,6 @@ export const setEnv: {
|
|
|
1118
1117
|
}
|
|
1119
1118
|
)
|
|
1120
1119
|
|
|
1121
|
-
/**
|
|
1122
|
-
* Spawn a command and return a handle for interaction.
|
|
1123
|
-
*
|
|
1124
|
-
* Unlike `exec`, this does not wait for the process to complete. Instead,
|
|
1125
|
-
* it returns a handle that provides access to the process's stdin, stdout,
|
|
1126
|
-
* stderr streams and exit code.
|
|
1127
|
-
*
|
|
1128
|
-
* Note: For piped commands, only the first command in the pipeline is spawned
|
|
1129
|
-
* and a handle to it is returned.
|
|
1130
|
-
*
|
|
1131
|
-
* @example
|
|
1132
|
-
* ```ts
|
|
1133
|
-
* import { NodeServices } from "@effect/platform-node"
|
|
1134
|
-
* import { Console, Effect, Stream } from "effect"
|
|
1135
|
-
* import { ChildProcess } from "effect/unstable/process"
|
|
1136
|
-
*
|
|
1137
|
-
* const program = Effect.gen(function*() {
|
|
1138
|
-
* const cmd = ChildProcess.make`long-running-process`
|
|
1139
|
-
* const handle = yield* ChildProcess.spawn(cmd)
|
|
1140
|
-
*
|
|
1141
|
-
* // Stream stdout
|
|
1142
|
-
* yield* handle.stdout.pipe(
|
|
1143
|
-
* Stream.decodeText(),
|
|
1144
|
-
* Stream.runForEach(Console.log),
|
|
1145
|
-
* Effect.forkChild
|
|
1146
|
-
* )
|
|
1147
|
-
*
|
|
1148
|
-
* // Wait for exit
|
|
1149
|
-
* const exitCode = yield* handle.exitCode
|
|
1150
|
-
* yield* Console.log(`Process exited with code ${exitCode}`)
|
|
1151
|
-
* }).pipe(Effect.provide(NodeServices.layer))
|
|
1152
|
-
* ```
|
|
1153
|
-
*
|
|
1154
|
-
* @since 4.0.0
|
|
1155
|
-
* @category Execution
|
|
1156
|
-
*/
|
|
1157
|
-
export const spawn = (command: Command): Effect.Effect<
|
|
1158
|
-
ChildProcessHandle,
|
|
1159
|
-
PlatformError.PlatformError,
|
|
1160
|
-
ChildProcessSpawner | Scope.Scope
|
|
1161
|
-
> => ChildProcessSpawner.use((_) => _.spawn(command))
|
|
1162
|
-
|
|
1163
|
-
/**
|
|
1164
|
-
* @since 4.0.0
|
|
1165
|
-
* @category Execution
|
|
1166
|
-
*/
|
|
1167
|
-
export const exitCode = (command: Command): Effect.Effect<
|
|
1168
|
-
ExitCode,
|
|
1169
|
-
PlatformError.PlatformError,
|
|
1170
|
-
ChildProcessSpawner
|
|
1171
|
-
> => Effect.scoped(Effect.flatMap(spawn(command), (handle) => handle.exitCode))
|
|
1172
|
-
|
|
1173
|
-
/**
|
|
1174
|
-
* @since 4.0.0
|
|
1175
|
-
* @category Execution
|
|
1176
|
-
*/
|
|
1177
|
-
export const streamString: {
|
|
1178
|
-
/**
|
|
1179
|
-
* @since 4.0.0
|
|
1180
|
-
* @category Execution
|
|
1181
|
-
*/
|
|
1182
|
-
(
|
|
1183
|
-
options?: {
|
|
1184
|
-
readonly includeStderr?: boolean | undefined
|
|
1185
|
-
}
|
|
1186
|
-
): (self: Command) => Stream.Stream<string, PlatformError.PlatformError, ChildProcessSpawner>
|
|
1187
|
-
/**
|
|
1188
|
-
* @since 4.0.0
|
|
1189
|
-
* @category Execution
|
|
1190
|
-
*/
|
|
1191
|
-
(
|
|
1192
|
-
self: Command,
|
|
1193
|
-
options?: {
|
|
1194
|
-
readonly includeStderr?: boolean | undefined
|
|
1195
|
-
}
|
|
1196
|
-
): Stream.Stream<string, PlatformError.PlatformError, ChildProcessSpawner>
|
|
1197
|
-
} = dual(
|
|
1198
|
-
(args) => isCommand(args[0]),
|
|
1199
|
-
(
|
|
1200
|
-
self: Command,
|
|
1201
|
-
options?: { readonly includeStderr?: boolean | undefined }
|
|
1202
|
-
): Stream.Stream<
|
|
1203
|
-
string,
|
|
1204
|
-
PlatformError.PlatformError,
|
|
1205
|
-
ChildProcessSpawner
|
|
1206
|
-
> =>
|
|
1207
|
-
spawn(self).pipe(
|
|
1208
|
-
Effect.map((handle) =>
|
|
1209
|
-
Stream.decodeText(
|
|
1210
|
-
options?.includeStderr === true ? handle.all : handle.stdout
|
|
1211
|
-
)
|
|
1212
|
-
),
|
|
1213
|
-
Stream.unwrap
|
|
1214
|
-
)
|
|
1215
|
-
)
|
|
1216
|
-
|
|
1217
|
-
/**
|
|
1218
|
-
* @since 4.0.0
|
|
1219
|
-
* @category Execution
|
|
1220
|
-
*/
|
|
1221
|
-
export const streamLines: {
|
|
1222
|
-
/**
|
|
1223
|
-
* @since 4.0.0
|
|
1224
|
-
* @category Execution
|
|
1225
|
-
*/
|
|
1226
|
-
(
|
|
1227
|
-
options?: {
|
|
1228
|
-
readonly includeStderr?: boolean | undefined
|
|
1229
|
-
}
|
|
1230
|
-
): (self: Command) => Stream.Stream<string, PlatformError.PlatformError, ChildProcessSpawner>
|
|
1231
|
-
/**
|
|
1232
|
-
* @since 4.0.0
|
|
1233
|
-
* @category Execution
|
|
1234
|
-
*/
|
|
1235
|
-
(
|
|
1236
|
-
self: Command,
|
|
1237
|
-
options?: {
|
|
1238
|
-
readonly includeStderr?: boolean | undefined
|
|
1239
|
-
}
|
|
1240
|
-
): Stream.Stream<string, PlatformError.PlatformError, ChildProcessSpawner>
|
|
1241
|
-
} = dual(
|
|
1242
|
-
(args) => isCommand(args[0]),
|
|
1243
|
-
(self: Command, options?: { readonly includeStderr?: boolean | undefined }): Stream.Stream<
|
|
1244
|
-
string,
|
|
1245
|
-
PlatformError.PlatformError,
|
|
1246
|
-
ChildProcessSpawner
|
|
1247
|
-
> => Stream.splitLines(streamString(self, options))
|
|
1248
|
-
)
|
|
1249
|
-
|
|
1250
|
-
/**
|
|
1251
|
-
* @since 4.0.0
|
|
1252
|
-
* @category Execution
|
|
1253
|
-
*/
|
|
1254
|
-
export const lines: {
|
|
1255
|
-
/**
|
|
1256
|
-
* @since 4.0.0
|
|
1257
|
-
* @category Execution
|
|
1258
|
-
*/
|
|
1259
|
-
(
|
|
1260
|
-
options?: {
|
|
1261
|
-
readonly includeStderr?: boolean | undefined
|
|
1262
|
-
}
|
|
1263
|
-
): (self: Command) => Effect.Effect<Array<string>, PlatformError.PlatformError, ChildProcessSpawner>
|
|
1264
|
-
/**
|
|
1265
|
-
* @since 4.0.0
|
|
1266
|
-
* @category Execution
|
|
1267
|
-
*/
|
|
1268
|
-
(
|
|
1269
|
-
self: Command,
|
|
1270
|
-
options?: {
|
|
1271
|
-
readonly includeStderr?: boolean | undefined
|
|
1272
|
-
}
|
|
1273
|
-
): Effect.Effect<Array<string>, PlatformError.PlatformError, ChildProcessSpawner>
|
|
1274
|
-
} = dual(
|
|
1275
|
-
(args) => isCommand(args[0]),
|
|
1276
|
-
(
|
|
1277
|
-
self: Command,
|
|
1278
|
-
options?: { readonly includeStderr?: boolean | undefined }
|
|
1279
|
-
): Effect.Effect<
|
|
1280
|
-
Array<string>,
|
|
1281
|
-
PlatformError.PlatformError,
|
|
1282
|
-
ChildProcessSpawner
|
|
1283
|
-
> => Stream.runCollect(streamLines(self, options))
|
|
1284
|
-
)
|
|
1285
|
-
|
|
1286
|
-
/**
|
|
1287
|
-
* @since 4.0.0
|
|
1288
|
-
* @category Execution
|
|
1289
|
-
*/
|
|
1290
|
-
export const string: {
|
|
1291
|
-
/**
|
|
1292
|
-
* @since 4.0.0
|
|
1293
|
-
* @category Execution
|
|
1294
|
-
*/
|
|
1295
|
-
(
|
|
1296
|
-
options?: {
|
|
1297
|
-
readonly includeStderr?: boolean | undefined
|
|
1298
|
-
}
|
|
1299
|
-
): (self: Command) => Effect.Effect<string, PlatformError.PlatformError, ChildProcessSpawner>
|
|
1300
|
-
/**
|
|
1301
|
-
* @since 4.0.0
|
|
1302
|
-
* @category Execution
|
|
1303
|
-
*/
|
|
1304
|
-
(
|
|
1305
|
-
self: Command,
|
|
1306
|
-
options?: {
|
|
1307
|
-
readonly includeStderr?: boolean | undefined
|
|
1308
|
-
}
|
|
1309
|
-
): Effect.Effect<string, PlatformError.PlatformError, ChildProcessSpawner>
|
|
1310
|
-
} = dual(
|
|
1311
|
-
(args) => isCommand(args[0]),
|
|
1312
|
-
(
|
|
1313
|
-
self: Command,
|
|
1314
|
-
options?: { readonly includeStderr?: boolean | undefined }
|
|
1315
|
-
): Effect.Effect<
|
|
1316
|
-
string,
|
|
1317
|
-
PlatformError.PlatformError,
|
|
1318
|
-
ChildProcessSpawner
|
|
1319
|
-
> => Stream.mkString(streamString(self, options))
|
|
1320
|
-
)
|
|
1321
|
-
|
|
1322
1120
|
const isTemplateString = (u: unknown): u is TemplateStringsArray =>
|
|
1323
1121
|
Array.isArray(u) && "raw" in u && Array.isArray(u.raw)
|
|
1324
1122
|
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* @since 4.0.0
|
|
8
8
|
*/
|
|
9
9
|
import * as Brand from "../../Brand.ts"
|
|
10
|
-
import
|
|
10
|
+
import * as Effect from "../../Effect.ts"
|
|
11
11
|
import * as Inspectable from "../../Inspectable.ts"
|
|
12
12
|
import type * as PlatformError from "../../PlatformError.ts"
|
|
13
13
|
import type * as Scope from "../../Scope.ts"
|
|
14
14
|
import * as ServiceMap from "../../ServiceMap.ts"
|
|
15
15
|
import type * as Sink from "../../Sink.ts"
|
|
16
|
-
import
|
|
16
|
+
import * as Stream from "../../Stream.ts"
|
|
17
17
|
import type { Command, KillOptions } from "./ChildProcess.ts"
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -129,18 +129,32 @@ export const makeHandle = (params: Omit<ChildProcessHandle, typeof HandleTypeId>
|
|
|
129
129
|
Object.assign(Object.create(HandleProto), params)
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
*
|
|
132
|
+
* Create a new `ChildProcessSpawner` service from a `spawn` funciton
|
|
133
133
|
*
|
|
134
134
|
* @since 4.0.0
|
|
135
135
|
* @category Models
|
|
136
136
|
*/
|
|
137
|
-
export
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
137
|
+
export const make = (spawn: ChildProcessSpawner["Service"]["spawn"]): ChildProcessSpawner["Service"] => {
|
|
138
|
+
const streamString: ChildProcessSpawner["Service"]["streamLines"] = (command, options) =>
|
|
139
|
+
spawn(command).pipe(
|
|
140
|
+
Effect.map((handle) =>
|
|
141
|
+
Stream.decodeText(
|
|
142
|
+
options?.includeStderr === true ? handle.all : handle.stdout
|
|
143
|
+
)
|
|
144
|
+
),
|
|
145
|
+
Stream.unwrap
|
|
146
|
+
)
|
|
147
|
+
const streamLines: ChildProcessSpawner["Service"]["streamLines"] = (command, options) =>
|
|
148
|
+
Stream.splitLines(streamString(command, options))
|
|
149
|
+
|
|
150
|
+
return ChildProcessSpawner.of({
|
|
151
|
+
spawn,
|
|
152
|
+
exitCode: (command) => Effect.scoped(Effect.flatMap(spawn(command), (handle) => handle.exitCode)),
|
|
153
|
+
streamString,
|
|
154
|
+
streamLines,
|
|
155
|
+
lines: (command, options) => Stream.runCollect(streamLines(command, options)),
|
|
156
|
+
string: (command, options) => Stream.mkString(streamString(command, options))
|
|
157
|
+
})
|
|
144
158
|
}
|
|
145
159
|
|
|
146
160
|
/**
|
|
@@ -149,7 +163,48 @@ export interface ChildProcessSpawner {
|
|
|
149
163
|
* @since 4.0.0
|
|
150
164
|
* @category Service
|
|
151
165
|
*/
|
|
152
|
-
export
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
166
|
+
export class ChildProcessSpawner extends ServiceMap.Service<ChildProcessSpawner, {
|
|
167
|
+
/**
|
|
168
|
+
* Spawn a command and return a handle for interaction.
|
|
169
|
+
*/
|
|
170
|
+
spawn(
|
|
171
|
+
command: Command
|
|
172
|
+
): Effect.Effect<ChildProcessHandle, PlatformError.PlatformError, Scope.Scope>
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Run a command and return its exit code.
|
|
176
|
+
*/
|
|
177
|
+
exitCode(
|
|
178
|
+
command: Command
|
|
179
|
+
): Effect.Effect<ExitCode, PlatformError.PlatformError>
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Stream the output of a command as strings. Optionally include stderr output
|
|
183
|
+
* interleaved with stdout.
|
|
184
|
+
*/
|
|
185
|
+
streamString(command: Command, options?: {
|
|
186
|
+
readonly includeStderr?: boolean | undefined
|
|
187
|
+
}): Stream.Stream<string, PlatformError.PlatformError>
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Stream the output of a command as lines. Optionally include stderr output
|
|
191
|
+
* interleaved with stdout.
|
|
192
|
+
*/
|
|
193
|
+
streamLines(command: Command, options?: {
|
|
194
|
+
readonly includeStderr?: boolean | undefined
|
|
195
|
+
}): Stream.Stream<string, PlatformError.PlatformError>
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Run a command and return the lines of its output as an array of strings.
|
|
199
|
+
*/
|
|
200
|
+
lines(command: Command, options?: {
|
|
201
|
+
readonly includeStderr?: boolean | undefined
|
|
202
|
+
}): Effect.Effect<Array<string>, PlatformError.PlatformError>
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Run a command and return its output as a string.
|
|
206
|
+
*/
|
|
207
|
+
string(command: Command, options?: {
|
|
208
|
+
readonly includeStderr?: boolean | undefined
|
|
209
|
+
}): Effect.Effect<string, PlatformError.PlatformError>
|
|
210
|
+
}>()("effect/process/ChildProcessSpawner") {}
|
package/src/unstable/rpc/Rpc.ts
CHANGED
|
@@ -132,7 +132,7 @@ export interface Rpc<
|
|
|
132
132
|
* Add an annotation on the rpc.
|
|
133
133
|
*/
|
|
134
134
|
annotate<I, S>(
|
|
135
|
-
tag: ServiceMap.
|
|
135
|
+
tag: ServiceMap.Key<I, S>,
|
|
136
136
|
value: S
|
|
137
137
|
): Rpc<Tag, Payload, Success, Error, Middleware, Requires>
|
|
138
138
|
|
|
@@ -660,7 +660,7 @@ const Proto = {
|
|
|
660
660
|
middlewares: this.middlewares
|
|
661
661
|
})
|
|
662
662
|
},
|
|
663
|
-
annotate(this: AnyWithProps, tag: ServiceMap.
|
|
663
|
+
annotate(this: AnyWithProps, tag: ServiceMap.Key<any, any>, value: any) {
|
|
664
664
|
return makeProto({
|
|
665
665
|
_tag: this._tag,
|
|
666
666
|
payloadSchema: this.payloadSchema,
|
|
@@ -131,12 +131,12 @@ export interface RpcGroup<in out R extends Rpc.Any> extends Pipeable {
|
|
|
131
131
|
/**
|
|
132
132
|
* Annotate the group with a value.
|
|
133
133
|
*/
|
|
134
|
-
annotate<I, S>(service: ServiceMap.
|
|
134
|
+
annotate<I, S>(service: ServiceMap.Key<I, S>, value: S): RpcGroup<R>
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
137
|
* Annotate the Rpc's above this point with a value.
|
|
138
138
|
*/
|
|
139
|
-
annotateRpcs<I, S>(service: ServiceMap.
|
|
139
|
+
annotateRpcs<I, S>(service: ServiceMap.Key<I, S>, value: S): RpcGroup<R>
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
142
|
* Annotate the group with the provided annotations.
|
|
@@ -314,13 +314,13 @@ const RpcGroupProto = {
|
|
|
314
314
|
})
|
|
315
315
|
})
|
|
316
316
|
},
|
|
317
|
-
annotate(this: RpcGroup<any>, service: ServiceMap.
|
|
317
|
+
annotate(this: RpcGroup<any>, service: ServiceMap.Key<any, any>, value: any) {
|
|
318
318
|
return makeProto({
|
|
319
319
|
requests: this.requests,
|
|
320
320
|
annotations: ServiceMap.add(this.annotations, service, value)
|
|
321
321
|
})
|
|
322
322
|
},
|
|
323
|
-
annotateRpcs(this: RpcGroup<any>, service: ServiceMap.
|
|
323
|
+
annotateRpcs(this: RpcGroup<any>, service: ServiceMap.Key<any, any>, value: any) {
|
|
324
324
|
return this.annotateRpcsMerge(ServiceMap.make(service, value))
|
|
325
325
|
},
|
|
326
326
|
annotateMerge(this: RpcGroup<any>, context: ServiceMap.ServiceMap<any>) {
|
|
@@ -173,7 +173,7 @@ export type ErrorServicesDecode<A> = ErrorSchema<A>["DecodingServices"]
|
|
|
173
173
|
* @since 4.0.0
|
|
174
174
|
* @category models
|
|
175
175
|
*/
|
|
176
|
-
export interface AnyService extends ServiceMap.
|
|
176
|
+
export interface AnyService extends ServiceMap.Key<any, any> {
|
|
177
177
|
readonly [TypeId]: typeof TypeId
|
|
178
178
|
readonly error: Schema.Top
|
|
179
179
|
readonly requiredForClient: boolean
|
|
@@ -184,7 +184,7 @@ export interface AnyService extends ServiceMap.Service<any, any> {
|
|
|
184
184
|
* @since 4.0.0
|
|
185
185
|
* @category models
|
|
186
186
|
*/
|
|
187
|
-
export interface AnyServiceWithProps extends ServiceMap.
|
|
187
|
+
export interface AnyServiceWithProps extends ServiceMap.Key<any, RpcMiddleware<any, any, any>> {
|
|
188
188
|
readonly [TypeId]: typeof TypeId
|
|
189
189
|
readonly error: Schema.Top
|
|
190
190
|
readonly requiredForClient: boolean
|
|
@@ -253,7 +253,7 @@ export const Service = <
|
|
|
253
253
|
* @category client
|
|
254
254
|
*/
|
|
255
255
|
export const layerClient = <Id extends AnyId, S, R, EX = never, RX = never>(
|
|
256
|
-
tag: ServiceMap.
|
|
256
|
+
tag: ServiceMap.Key<Id, S>,
|
|
257
257
|
service:
|
|
258
258
|
| RpcMiddlewareClient<Id[TypeId]["error"]["Type"], Id[TypeId]["clientError"], R>
|
|
259
259
|
| Effect.Effect<RpcMiddlewareClient<Id[TypeId]["error"]["Type"], Id[TypeId]["clientError"], R>, EX, RX>
|
|
@@ -180,7 +180,7 @@ export const make = Effect.fnUntraced(function*(options: SqlClient.MakeOptions)
|
|
|
180
180
|
* @category transactions
|
|
181
181
|
*/
|
|
182
182
|
export const makeWithTransaction = <I, S>(options: {
|
|
183
|
-
readonly transactionService: ServiceMap.
|
|
183
|
+
readonly transactionService: ServiceMap.Key<I, readonly [conn: S, counter: number]>
|
|
184
184
|
readonly spanAttributes: ReadonlyArray<readonly [string, unknown]>
|
|
185
185
|
readonly acquireConnection: Effect.Effect<readonly [Scope.Closeable | undefined, S], SqlError>
|
|
186
186
|
readonly begin: (conn: NoInfer<S>) => Effect.Effect<void, SqlError>
|