effect 4.0.0-rc.118 → 4.0.0
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/README.md +17 -4
- package/dist/Array.d.ts +25 -25
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +16 -16
- package/dist/Array.js.map +1 -1
- package/dist/Chunk.d.ts +26 -26
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +15 -15
- package/dist/Chunk.js.map +1 -1
- package/dist/Effect.d.ts +17 -17
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +5 -5
- package/dist/MutableHashMap.d.ts.map +1 -1
- package/dist/MutableHashMap.js +4 -22
- package/dist/MutableHashMap.js.map +1 -1
- package/dist/Option.d.ts +17 -17
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +6 -6
- package/dist/Option.js.map +1 -1
- package/dist/Queue.d.ts +19 -2
- package/dist/Queue.d.ts.map +1 -1
- package/dist/Queue.js +9 -4
- package/dist/Queue.js.map +1 -1
- package/dist/Record.d.ts +14 -14
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js +10 -10
- package/dist/Record.js.map +1 -1
- package/dist/Schema.d.ts +37 -21
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +29 -10
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +116 -97
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +3 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +3 -1
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/ai/McpSchema.d.ts +110 -110
- package/dist/ai/McpSchema.d.ts.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.js +5 -1
- package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/cluster/MessageStorage.d.ts +32 -8
- package/dist/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/cluster/MessageStorage.js +2 -1
- package/dist/cluster/MessageStorage.js.map +1 -1
- package/dist/cluster/Sharding.d.ts +5 -2
- package/dist/cluster/Sharding.d.ts.map +1 -1
- package/dist/cluster/Sharding.js +1 -1
- package/dist/cluster/Sharding.js.map +1 -1
- package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/cluster/SqlMessageStorage.js +15 -4
- package/dist/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/http/HttpEffect.d.ts +1 -0
- package/dist/http/HttpEffect.d.ts.map +1 -1
- package/dist/http/HttpEffect.js +29 -22
- package/dist/http/HttpEffect.js.map +1 -1
- package/dist/internal/effect.js +75 -84
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/annotations.js +1 -7
- package/dist/internal/schema/annotations.js.map +1 -1
- package/dist/internal/schema/codegen.js +56 -28
- package/dist/internal/schema/codegen.js.map +1 -1
- package/dist/internal/schema/toCodeDocument.js +10 -30
- package/dist/internal/schema/toCodeDocument.js.map +1 -1
- package/dist/internal/schema/toCodec.js +1 -15
- package/dist/internal/schema/toCodec.js.map +1 -1
- package/dist/internal/schema/toEquivalence.js +4 -3
- package/dist/internal/schema/toEquivalence.js.map +1 -1
- package/dist/internal/schema/toFormatter.js +4 -4
- package/dist/internal/schema/toFormatter.js.map +1 -1
- package/dist/reactivity/Atom.d.ts.map +1 -1
- package/dist/reactivity/Atom.js +6 -2
- package/dist/reactivity/Atom.js.map +1 -1
- package/dist/reactivity/AtomRpc.d.ts +3 -3
- package/dist/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/rpc/Rpc.d.ts +2 -2
- package/dist/rpc/Rpc.d.ts.map +1 -1
- package/dist/rpc/RpcClient.d.ts +7 -7
- package/dist/rpc/RpcClient.d.ts.map +1 -1
- package/dist/rpc/RpcClient.js +1 -2
- package/dist/rpc/RpcClient.js.map +1 -1
- package/dist/rpc/RpcMessage.d.ts +1 -1
- package/dist/rpc/RpcMessage.d.ts.map +1 -1
- package/dist/schema/SchemaCompiler/runtime.js +6 -1
- package/dist/schema/SchemaCompiler/runtime.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +234 -6
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +244 -25
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/workflow/DurableDeferred.js +1 -1
- package/dist/workflow/DurableDeferred.js.map +1 -1
- package/dist/workflow/Workflow.js +1 -1
- package/dist/workflow/Workflow.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +31 -31
- package/src/Chunk.ts +29 -29
- package/src/Effect.ts +17 -17
- package/src/MutableHashMap.ts +4 -24
- package/src/Option.ts +19 -19
- package/src/Queue.ts +26 -6
- package/src/Record.ts +20 -20
- package/src/Schema.ts +48 -24
- package/src/SchemaAST.ts +135 -115
- package/src/SchemaRepresentation.ts +3 -1
- package/src/cluster/ClusterWorkflowEngine.ts +8 -1
- package/src/cluster/MessageStorage.ts +22 -5
- package/src/cluster/Sharding.ts +8 -4
- package/src/cluster/SqlMessageStorage.ts +19 -8
- package/src/http/HttpEffect.ts +15 -9
- package/src/internal/effect.ts +37 -62
- package/src/internal/schema/annotations.ts +0 -9
- package/src/internal/schema/codegen.ts +90 -43
- package/src/internal/schema/toCodeDocument.ts +10 -47
- package/src/internal/schema/toCodec.ts +3 -16
- package/src/internal/schema/toEquivalence.ts +4 -5
- package/src/internal/schema/toFormatter.ts +4 -6
- package/src/reactivity/Atom.ts +6 -2
- package/src/reactivity/AtomRpc.ts +5 -5
- package/src/rpc/Rpc.ts +2 -2
- package/src/rpc/RpcClient.ts +9 -10
- package/src/rpc/RpcMessage.ts +1 -1
- package/src/schema/SchemaCompiler/runtime.ts +17 -1
- package/src/testing/TestSchema.ts +315 -63
- package/src/testing/index.ts +1 -0
- package/src/workflow/DurableDeferred.ts +1 -1
- package/src/workflow/Workflow.ts +1 -1
|
@@ -33,22 +33,9 @@ function validateCanonicalObjectPropertyNames(ast: SchemaAST.Objects): void {
|
|
|
33
33
|
|
|
34
34
|
function makeReorder(getPriority: (ast: SchemaAST.AST) => number) {
|
|
35
35
|
return (types: ReadonlyArray<SchemaAST.AST>): ReadonlyArray<SchemaAST.AST> => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
indexMap.set(SchemaAST.toEncoded(types[i]), i)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Create a sorted copy of the types array
|
|
43
|
-
const sortedTypes = [...types].sort((a, b) => {
|
|
44
|
-
a = SchemaAST.toEncoded(a)
|
|
45
|
-
b = SchemaAST.toEncoded(b)
|
|
46
|
-
const pa = getPriority(a)
|
|
47
|
-
const pb = getPriority(b)
|
|
48
|
-
if (pa !== pb) return pa - pb
|
|
49
|
-
// If priorities are equal, maintain original order (stable sort)
|
|
50
|
-
return indexMap.get(a)! - indexMap.get(b)!
|
|
51
|
-
})
|
|
36
|
+
const sortedTypes = [...types].sort((a, b) =>
|
|
37
|
+
getPriority(SchemaAST.toEncoded(a)) - getPriority(SchemaAST.toEncoded(b))
|
|
38
|
+
)
|
|
52
39
|
|
|
53
40
|
// Check if order changed by comparing arrays
|
|
54
41
|
const orderChanged = sortedTypes.some((ast, index) => ast !== types[index])
|
|
@@ -136,13 +136,12 @@ function recur(ast: SchemaAST.AST): Equivalence.Equivalence<any> {
|
|
|
136
136
|
}
|
|
137
137
|
case "Union": {
|
|
138
138
|
const types = SchemaAST.toType(ast).types
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
)
|
|
139
|
+
const index = SchemaAST.getCandidateIndex(types)
|
|
140
|
+
const compiled = types.map((candidate, i) => [SchemaParser._is(candidate), recur(ast.types[i])] as const)
|
|
142
141
|
return Equivalence.make((a, b) => {
|
|
143
|
-
const candidates =
|
|
142
|
+
const candidates = index(a, false)
|
|
144
143
|
for (let i = 0; i < candidates.length; i++) {
|
|
145
|
-
const [is, equivalence] = compiled
|
|
144
|
+
const [is, equivalence] = compiled[candidates[i]]
|
|
146
145
|
if (is(a) && is(b)) {
|
|
147
146
|
return equivalence(a, b)
|
|
148
147
|
}
|
|
@@ -217,14 +217,12 @@ export function toFormatter<T>(ast: SchemaAST.AST, options?: {
|
|
|
217
217
|
}
|
|
218
218
|
case "Union": {
|
|
219
219
|
const types = SchemaAST.toType(ast).types
|
|
220
|
-
const
|
|
221
|
-
const compiled =
|
|
222
|
-
types.map((candidate, i) => [candidate, [SchemaParser._is(candidate), recur(ast.types[i])] as const] as const)
|
|
223
|
-
)
|
|
220
|
+
const index = SchemaAST.getCandidateIndex(types)
|
|
221
|
+
const compiled = types.map((candidate, i) => [SchemaParser._is(candidate), recur(ast.types[i])] as const)
|
|
224
222
|
return (value) => {
|
|
225
|
-
const candidates =
|
|
223
|
+
const candidates = index(value, false)
|
|
226
224
|
for (let i = 0; i < candidates.length; i++) {
|
|
227
|
-
const [is, formatter] = compiled
|
|
225
|
+
const [is, formatter] = compiled[candidates[i]]
|
|
228
226
|
if (is(value)) {
|
|
229
227
|
return formatter(value)
|
|
230
228
|
}
|
package/src/reactivity/Atom.ts
CHANGED
|
@@ -1453,8 +1453,9 @@ function makeResultFn<Arg, E, A>(
|
|
|
1453
1453
|
Effect.forkDetach(eff, { startImmediately: true }),
|
|
1454
1454
|
(fiber) => {
|
|
1455
1455
|
fibers.add(fiber)
|
|
1456
|
+
const runningFibers = Array.from(fibers)
|
|
1456
1457
|
fiber.addObserver(() => fibers.delete(fiber))
|
|
1457
|
-
return Effect.map(Fiber.joinAll(
|
|
1458
|
+
return Effect.map(Fiber.joinAll(runningFibers), (arr) => arr[0])
|
|
1458
1459
|
}
|
|
1459
1460
|
)
|
|
1460
1461
|
}
|
|
@@ -1619,7 +1620,10 @@ export const family = typeof WeakRef === "undefined" || typeof FinalizationRegis
|
|
|
1619
1620
|
): (arg: Arg) => T => {
|
|
1620
1621
|
const atoms = MutableHashMap.empty<Arg, WeakRef<T>>()
|
|
1621
1622
|
const registry = new FinalizationRegistry<Arg>((arg) => {
|
|
1622
|
-
MutableHashMap.
|
|
1623
|
+
const entry = MutableHashMap.get(atoms, arg)
|
|
1624
|
+
if (entry._tag === "Some" && entry.value.deref() === undefined) {
|
|
1625
|
+
MutableHashMap.remove(atoms, arg)
|
|
1626
|
+
}
|
|
1623
1627
|
})
|
|
1624
1628
|
return function(arg) {
|
|
1625
1629
|
const atomEntry = MutableHashMap.get(atoms, arg).pipe(
|
|
@@ -57,8 +57,8 @@ export interface AtomRpcClient<Self, Id extends string, Rpcs extends Rpc.Any> ex
|
|
|
57
57
|
|
|
58
58
|
readonly mutation: <Tag extends Rpc.Tag<Rpcs>>(
|
|
59
59
|
arg: Tag
|
|
60
|
-
) =>
|
|
61
|
-
infer _Tag,
|
|
60
|
+
) => Rpcs extends Rpc.Rpc<
|
|
61
|
+
infer _Tag extends Tag,
|
|
62
62
|
infer _Payload,
|
|
63
63
|
infer _Success,
|
|
64
64
|
infer _Error,
|
|
@@ -67,7 +67,7 @@ export interface AtomRpcClient<Self, Id extends string, Rpcs extends Rpc.Any> ex
|
|
|
67
67
|
> ? [_Success] extends [RpcSchema.Stream<infer _A, infer _E>] ? never
|
|
68
68
|
: Atom.AtomResultFn<
|
|
69
69
|
{
|
|
70
|
-
readonly payload: Rpc.PayloadConstructor<
|
|
70
|
+
readonly payload: Rpc.PayloadConstructor<Rpcs>
|
|
71
71
|
readonly reactivityKeys?:
|
|
72
72
|
| ReadonlyArray<unknown>
|
|
73
73
|
| ReadonlyRecord<string, ReadonlyArray<unknown>>
|
|
@@ -91,8 +91,8 @@ export interface AtomRpcClient<Self, Id extends string, Rpcs extends Rpc.Any> ex
|
|
|
91
91
|
readonly timeToLive?: Duration.Input | undefined
|
|
92
92
|
readonly serializationKey?: string | undefined
|
|
93
93
|
}
|
|
94
|
-
) =>
|
|
95
|
-
infer _Tag,
|
|
94
|
+
) => Rpcs extends Rpc.Rpc<
|
|
95
|
+
infer _Tag extends Tag,
|
|
96
96
|
infer _Payload,
|
|
97
97
|
infer _Success,
|
|
98
98
|
infer _Error,
|
package/src/rpc/Rpc.ts
CHANGED
|
@@ -687,14 +687,14 @@ export type IsStream<R extends Any, Tag extends string> = R extends Rpc<
|
|
|
687
687
|
never
|
|
688
688
|
|
|
689
689
|
/**
|
|
690
|
-
* Extracts
|
|
690
|
+
* Extracts RPCs whose tags match the given tag or union of tags.
|
|
691
691
|
*
|
|
692
692
|
* @stability unstable
|
|
693
693
|
* @category utility types
|
|
694
694
|
* @since 4.0.0
|
|
695
695
|
*/
|
|
696
696
|
export type ExtractTag<R extends Any, Tag extends string> = R extends Rpc<
|
|
697
|
-
Tag,
|
|
697
|
+
infer _Tag extends Tag,
|
|
698
698
|
infer _Payload,
|
|
699
699
|
infer _Success,
|
|
700
700
|
infer _Error,
|
package/src/rpc/RpcClient.ts
CHANGED
|
@@ -166,8 +166,8 @@ export declare namespace RpcClient {
|
|
|
166
166
|
readonly context?: Context.Context<never> | undefined
|
|
167
167
|
readonly discard?: Discard | undefined
|
|
168
168
|
}
|
|
169
|
-
) =>
|
|
170
|
-
infer _Tag,
|
|
169
|
+
) => Rpcs extends Rpc.Rpc<
|
|
170
|
+
infer _Tag extends Tag,
|
|
171
171
|
infer _Payload,
|
|
172
172
|
infer _Success,
|
|
173
173
|
infer _Error,
|
|
@@ -1051,9 +1051,9 @@ export const makeProtocolSocket = (options?: {
|
|
|
1051
1051
|
readonly retryPolicy?: Schedule.Schedule<any, Socket.SocketError> | undefined
|
|
1052
1052
|
/**
|
|
1053
1053
|
* Runs for each retried `SocketOpenError` when `retryTransientErrors` is enabled.
|
|
1054
|
-
*
|
|
1055
|
-
*
|
|
1056
|
-
*
|
|
1054
|
+
* A missed pong fails in-flight calls and is not reported through this hook.
|
|
1055
|
+
* The returned `Effect<void>` cannot fail with a typed error or require
|
|
1056
|
+
* services; defects are logged and ignored so retries can continue.
|
|
1057
1057
|
*/
|
|
1058
1058
|
readonly onTransientError?: ((error: RpcClientError) => Effect.Effect<void>) | undefined
|
|
1059
1059
|
}): Effect.Effect<
|
|
@@ -1149,8 +1149,7 @@ export const makeProtocolSocket = (options?: {
|
|
|
1149
1149
|
() =>
|
|
1150
1150
|
Effect.fail(
|
|
1151
1151
|
new Socket.SocketError({
|
|
1152
|
-
reason: new Socket.
|
|
1153
|
-
kind: "Timeout",
|
|
1152
|
+
reason: new Socket.SocketReadError({
|
|
1154
1153
|
cause: new Error("ping timeout")
|
|
1155
1154
|
})
|
|
1156
1155
|
})
|
|
@@ -1251,9 +1250,9 @@ export const layerProtocolSocket = (options?: {
|
|
|
1251
1250
|
readonly retryTransientErrors?: boolean | undefined
|
|
1252
1251
|
/**
|
|
1253
1252
|
* Runs for each retried `SocketOpenError` when `retryTransientErrors` is enabled.
|
|
1254
|
-
*
|
|
1255
|
-
*
|
|
1256
|
-
*
|
|
1253
|
+
* A missed pong fails in-flight calls and is not reported through this hook.
|
|
1254
|
+
* The returned `Effect<void>` cannot fail with a typed error or require
|
|
1255
|
+
* services; defects are logged and ignored so retries can continue.
|
|
1257
1256
|
*/
|
|
1258
1257
|
readonly onTransientError?: ((error: RpcClientError) => Effect.Effect<void>) | undefined
|
|
1259
1258
|
}): Layer.Layer<
|
package/src/rpc/RpcMessage.ts
CHANGED
|
@@ -237,6 +237,21 @@ const invalidEncoding = (
|
|
|
237
237
|
? invalidType(ast, value, options)
|
|
238
238
|
: Interpreter.wrapEncoding(ast, input, options, invalidType(ast.encoding[index - 1].to, value, options))
|
|
239
239
|
|
|
240
|
+
const invalidEncodingChecks = (
|
|
241
|
+
ast: SchemaAST.AST & { readonly encoding: SchemaAST.Encoding },
|
|
242
|
+
input: unknown,
|
|
243
|
+
issues: readonly [SchemaIssue.Issue, ...Array<SchemaIssue.Issue>],
|
|
244
|
+
options: SchemaAST.ParseOptions
|
|
245
|
+
) => {
|
|
246
|
+
const source = ast.encoding[ast.encoding.length - 1].to
|
|
247
|
+
return Interpreter.wrapEncoding(
|
|
248
|
+
ast,
|
|
249
|
+
input,
|
|
250
|
+
options,
|
|
251
|
+
Effect.fail(new SchemaIssue.Composite(source, issues, input, options))
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
240
255
|
/**
|
|
241
256
|
* @internal
|
|
242
257
|
*/
|
|
@@ -255,6 +270,7 @@ export const runtime = {
|
|
|
255
270
|
die: Effect.die,
|
|
256
271
|
invalidType,
|
|
257
272
|
invalidEncoding,
|
|
273
|
+
invalidEncodingChecks,
|
|
258
274
|
getCheckIssues,
|
|
259
275
|
check,
|
|
260
276
|
getExpectedKeys: (ast: SchemaAST.Objects) =>
|
|
@@ -262,7 +278,7 @@ export const runtime = {
|
|
|
262
278
|
hasExcessProperties,
|
|
263
279
|
matchesTemplateLiteral: (ast: SchemaAST.TemplateLiteral, input: unknown, options: SchemaAST.ParseOptions) =>
|
|
264
280
|
typeof input === "string" && ast.matchPart(input, options) !== undefined,
|
|
265
|
-
|
|
281
|
+
getCandidateIndex: SchemaAST.getCandidateIndex,
|
|
266
282
|
getIndexSignatureKeys: SchemaAST.getIndexSignatureKeys,
|
|
267
283
|
parameterFromPropertyKey: SchemaAST.parameterFromPropertyKey,
|
|
268
284
|
getConstructorDescriptor: SchemaAST.getConstructorDescriptor,
|