effect 4.0.0-beta.51 → 4.0.0-beta.53
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/Data.js +2 -2
- package/dist/Data.js.map +1 -1
- package/dist/Effect.d.ts +2 -1
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js.map +1 -1
- package/dist/Effectable.d.ts +29 -0
- package/dist/Effectable.d.ts.map +1 -0
- package/dist/Effectable.js +31 -0
- package/dist/Effectable.js.map +1 -0
- package/dist/Schema.d.ts +0 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +83 -12
- package/dist/Schema.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +1 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/representation.js +1 -2
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +37 -0
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/testing/TestClock.js +1 -1
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +7 -0
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +2 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +2 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.js +4 -8
- package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +11 -6
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +5 -6
- 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 +17 -18
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +1 -2
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +28 -8
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +28 -15
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -3
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +2 -2
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +7 -4
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/sql/Statement.d.ts +1 -3
- package/dist/unstable/sql/Statement.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.js +12 -11
- package/dist/unstable/sql/Statement.js.map +1 -1
- package/dist/unstable/workflow/Activity.d.ts +1 -1
- package/dist/unstable/workflow/Activity.d.ts.map +1 -1
- package/dist/unstable/workflow/Activity.js +8 -7
- package/dist/unstable/workflow/Activity.js.map +1 -1
- package/package.json +1 -1
- package/src/Data.ts +1 -1
- package/src/Effect.ts +4 -1
- package/src/Effectable.ts +47 -0
- package/src/Schema.ts +97 -13
- package/src/index.ts +8 -0
- package/src/internal/effect.ts +1 -1
- package/src/internal/schema/representation.ts +1 -2
- package/src/internal/schema/schema.ts +43 -0
- package/src/testing/TestClock.ts +1 -1
- package/src/unstable/ai/McpServer.ts +8 -0
- package/src/unstable/cli/index.ts +2 -0
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +1 -1
- package/src/unstable/http/HttpIncomingMessage.ts +4 -4
- package/src/unstable/httpapi/HttpApi.ts +1 -1
- package/src/unstable/httpapi/HttpApiBuilder.ts +13 -6
- package/src/unstable/httpapi/HttpApiClient.ts +5 -6
- package/src/unstable/httpapi/HttpApiEndpoint.ts +6 -7
- package/src/unstable/httpapi/HttpApiError.ts +43 -22
- package/src/unstable/httpapi/HttpApiMiddleware.ts +6 -5
- package/src/unstable/httpapi/OpenApi.ts +1 -1
- package/src/unstable/reactivity/AtomHttpApi.ts +14 -4
- package/src/unstable/sql/Statement.ts +19 -23
- package/src/unstable/workflow/Activity.ts +9 -9
- package/dist/internal/schema/to-codec.d.ts +0 -2
- package/dist/internal/schema/to-codec.d.ts.map +0 -1
- package/dist/internal/schema/to-codec.js +0 -126
- package/dist/internal/schema/to-codec.js.map +0 -1
- package/src/internal/schema/to-codec.ts +0 -138
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as Cause from "../../Cause.js";
|
|
2
2
|
import * as Context from "../../Context.js";
|
|
3
3
|
import * as Effect from "../../Effect.js";
|
|
4
|
+
import * as Effectable from "../../Effectable.js";
|
|
4
5
|
import { dual } from "../../Function.js";
|
|
5
|
-
import { PipeInspectableProto, YieldableProto } from "../../internal/core.js";
|
|
6
6
|
import * as Schedule from "../../Schedule.js";
|
|
7
7
|
import * as Schema from "../../Schema.js";
|
|
8
8
|
import * as DurableDeferred from "./DurableDeferred.js";
|
|
@@ -22,8 +22,12 @@ export const make = options => {
|
|
|
22
22
|
let execute;
|
|
23
23
|
const executeWithoutInterrupt = retryOnInterrupt(options.name, options.interruptRetryPolicy)(options.execute);
|
|
24
24
|
const self = {
|
|
25
|
-
...
|
|
26
|
-
|
|
25
|
+
...Effectable.Prototype({
|
|
26
|
+
label: "Activity",
|
|
27
|
+
evaluate(_) {
|
|
28
|
+
return execute;
|
|
29
|
+
}
|
|
30
|
+
}),
|
|
27
31
|
[TypeId]: TypeId,
|
|
28
32
|
name: options.name,
|
|
29
33
|
successSchema,
|
|
@@ -46,10 +50,7 @@ export const make = options => {
|
|
|
46
50
|
executeEncoded: Effect.matchEffect(executeWithoutInterrupt, {
|
|
47
51
|
onFailure: error => Effect.flatMap(Effect.orDie(Schema.encodeEffect(errorSchemaJson)(error)), Effect.fail),
|
|
48
52
|
onSuccess: value => Effect.orDie(Schema.encodeEffect(successSchemaJson)(value))
|
|
49
|
-
})
|
|
50
|
-
asEffect() {
|
|
51
|
-
return execute;
|
|
52
|
-
}
|
|
53
|
+
})
|
|
53
54
|
};
|
|
54
55
|
execute = makeExecute(self);
|
|
55
56
|
return self;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Activity.js","names":["Cause","Context","Effect","
|
|
1
|
+
{"version":3,"file":"Activity.js","names":["Cause","Context","Effect","Effectable","dual","Schedule","Schema","DurableDeferred","makeHashDigest","Workflow","TypeId","make","options","successSchema","success","Void","errorSchema","error","Never","successSchemaJson","toCodecJson","errorSchemaJson","execute","executeWithoutInterrupt","retryOnInterrupt","name","interruptRetryPolicy","self","Prototype","label","evaluate","_","exitSchema","Exit","Defect","annotations","empty","annotate","tag","value","add","annotateMerge","context","merge","executeEncoded","matchEffect","onFailure","flatMap","orDie","encodeEffect","fail","onSuccess","makeExecute","exponential","pipe","either","spaced","recurs","satisfiesInputType","while","meta","succeed","hasInterrupts","input","policy","effect","sandbox","retry","catch","cause","failCause","die","suspend","attempt","provideService","CurrentAttempt","Reference","defaultValue","idempotencyKey","fnUntraced","instance","InstanceTag","key","executionId","includeAttempt","raceAll","activities","Union","map","activity","effects","asEffect","EngineTag","Service","engine","annotateCurrentSpan","result","wrapActivityResult","activityExecute","_tag","exit","withSpan","captureStackTrace"],"sources":["../../../src/unstable/workflow/Activity.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,gBAAgB;AACvC,OAAO,KAAKC,OAAO,MAAM,kBAAkB;AAC3C,OAAO,KAAKC,MAAM,MAAM,iBAAiB;AACzC,OAAO,KAAKC,UAAU,MAAM,qBAAqB;AACjD,SAASC,IAAI,QAAQ,mBAAmB;AACxC,OAAO,KAAKC,QAAQ,MAAM,mBAAmB;AAC7C,OAAO,KAAKC,MAAM,MAAM,iBAAiB;AAGzC,OAAO,KAAKC,eAAe,MAAM,sBAAsB;AACvD,SAASC,cAAc,QAAQ,sBAAsB;AACrD,OAAO,KAAKC,QAAQ,MAAM,eAAe;AAGzC,MAAMC,MAAM,GAAG,2BAA2B;AA+E1C;;;;AAIA,OAAO,MAAMC,IAAI,GAIfC,OAOD,IAAqF;EACpF,MAAMC,aAAa,GAAGD,OAAO,CAACE,OAAO,IAAKR,MAAM,CAACS,IAAuB;EACxE,MAAMC,WAAW,GAAGJ,OAAO,CAACK,KAAK,IAAKX,MAAM,CAACY,KAAsB;EACnE,MAAMC,iBAAiB,GAAGb,MAAM,CAACc,WAAW,CAACP,aAAa,CAAC;EAC3D,MAAMQ,eAAe,GAAGf,MAAM,CAACc,WAAW,CAACJ,WAAW,CAAC;EACvD;EACA,IAAIM,OAA4D;EAChE,MAAMC,uBAAuB,GAAGC,gBAAgB,CAC9CZ,OAAO,CAACa,IAAI,EACZb,OAAO,CAACc,oBAAoB,CAC7B,CAACd,OAAO,CAACU,OAAO,CAAC;EAClB,MAAMK,IAAI,GAA4E;IACpF,GAAGxB,UAAU,CAACyB,SAAS,CAA8B;MACnDC,KAAK,EAAE,UAAU;MACjBC,QAAQA,CAACC,CAAC;QACR,OAAOT,OAAO;MAChB;KACD,CAAC;IACF,CAACZ,MAAM,GAAGA,MAAM;IAChBe,IAAI,EAAEb,OAAO,CAACa,IAAI;IAClBZ,aAAa;IACb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AMR,OAAO,GAAG,OAAOE,cAAc;EACrC,OAAOzE,MAAM,CAAC6F,mBAAmB,CAAC;IAAEZ,WAAW,EAAEH,QAAQ,CAACG;EAAW,CAAE,CAAC;EACxE,MAAMa,MAAM,GAAG,OAAOvF,QAAQ,CAACwF,kBAAkB,CAC/CH,MAAM,CAACI,eAAe,CAACT,QAAQ,EAAEhB,OAAO,CAAC,EACxC1C,CAAC,IAAKA,CAAC,CAACoE,IAAI,KAAK,WAAW,CAC9B;EACD,IAAIH,MAAM,CAACG,IAAI,KAAK,WAAW,EAAE;IAC/B,OAAO,OAAO1F,QAAQ,CAAC+D,OAAO,CAACQ,QAAQ,CAAC;EAC1C;EACA,OAAO,OAAOgB,MAAM,CAACI,IAAI;AAC3B,CAAC,EAAE,CAACnC,MAAM,EAAEwB,QAAQ,KAClBvF,MAAM,CAACmG,QAAQ,CAACpC,MAAM,EAAEwB,QAAQ,CAAChE,IAAI,EAAE;EACrC6E,iBAAiB,EAAE;CACpB,CAAC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
package/src/Data.ts
CHANGED
package/src/Effect.ts
CHANGED
|
@@ -79,6 +79,7 @@ import type { Fiber } from "./Fiber.ts"
|
|
|
79
79
|
import type * as Filter from "./Filter.ts"
|
|
80
80
|
import { constant, dual, type LazyArg } from "./Function.ts"
|
|
81
81
|
import type { TypeLambda } from "./HKT.ts"
|
|
82
|
+
import type { Inspectable } from "./Inspectable.ts"
|
|
82
83
|
import * as core from "./internal/core.ts"
|
|
83
84
|
import * as internal from "./internal/effect.ts"
|
|
84
85
|
import * as internalExecutionPlan from "./internal/executionPlan.ts"
|
|
@@ -169,7 +170,9 @@ const TypeId = core.EffectTypeId
|
|
|
169
170
|
* @since 2.0.0
|
|
170
171
|
* @category Models
|
|
171
172
|
*/
|
|
172
|
-
export interface Effect<out A, out E = never, out R = never>
|
|
173
|
+
export interface Effect<out A, out E = never, out R = never>
|
|
174
|
+
extends Pipeable, Inspectable, Yieldable<Effect<A, E, R>, A, E, R>
|
|
175
|
+
{
|
|
173
176
|
readonly [TypeId]: Variance<A, E, R>
|
|
174
177
|
[Unify.typeSymbol]?: unknown
|
|
175
178
|
[Unify.unifySymbol]?: EffectUnify<this>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 4.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type * as Effect from "./Effect.ts"
|
|
5
|
+
import type * as Fiber from "./Fiber.ts"
|
|
6
|
+
import { evaluate, makePrimitiveProto } from "./internal/core.ts"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create a low-level `Effect` prototype.
|
|
10
|
+
*
|
|
11
|
+
* When the effect is evaluated, it will call `evaluate` with the current fiber.
|
|
12
|
+
*
|
|
13
|
+
* @since 4.0.0
|
|
14
|
+
* @category Prototypes
|
|
15
|
+
*/
|
|
16
|
+
export const Prototype = <A extends Effect.Effect<any, any, any>>(options: {
|
|
17
|
+
readonly label: string
|
|
18
|
+
readonly evaluate: (
|
|
19
|
+
this: A,
|
|
20
|
+
fiber: Fiber.Fiber<any, any>
|
|
21
|
+
) => Effect.Effect<Effect.Success<A>, Effect.Error<A>, Effect.Services<A>>
|
|
22
|
+
}): Effect.Effect<Effect.Success<A>, Effect.Error<A>, Effect.Services<A>> =>
|
|
23
|
+
makePrimitiveProto({
|
|
24
|
+
op: options.label,
|
|
25
|
+
[evaluate]: options.evaluate
|
|
26
|
+
}) as any
|
|
27
|
+
|
|
28
|
+
const Base: new<A, E, R>() => Effect.Effect<A, E, R> = (() => {
|
|
29
|
+
const Base = function() {}
|
|
30
|
+
Base.prototype = Prototype({
|
|
31
|
+
label: "Effectable",
|
|
32
|
+
evaluate(_) {
|
|
33
|
+
return this.asEffect()
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
return Base as any
|
|
37
|
+
})()
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* An abstract class that can be extended to create an `Effect`.
|
|
41
|
+
*
|
|
42
|
+
* @since 4.0.0
|
|
43
|
+
* @category Constructors
|
|
44
|
+
*/
|
|
45
|
+
export abstract class Class<A, E = never, R = never> extends Base<A, E, R> {
|
|
46
|
+
abstract override asEffect(): Effect.Effect<A, E, R>
|
|
47
|
+
}
|
package/src/Schema.ts
CHANGED
|
@@ -103,7 +103,7 @@ import * as Equivalence from "./Equivalence.ts"
|
|
|
103
103
|
import * as Exit_ from "./Exit.ts"
|
|
104
104
|
import type { Formatter } from "./Formatter.ts"
|
|
105
105
|
import { format, formatPropertyKey } from "./Formatter.ts"
|
|
106
|
-
import { identity } from "./Function.ts"
|
|
106
|
+
import { identity, memoize } from "./Function.ts"
|
|
107
107
|
import * as HashMap_ from "./HashMap.ts"
|
|
108
108
|
import * as HashSet_ from "./HashSet.ts"
|
|
109
109
|
import * as core from "./internal/core.ts"
|
|
@@ -113,7 +113,6 @@ import * as InternalEquivalence from "./internal/schema/equivalence.ts"
|
|
|
113
113
|
import * as InternalStandard from "./internal/schema/representation.ts"
|
|
114
114
|
import * as InternalSchema from "./internal/schema/schema.ts"
|
|
115
115
|
import { SchemaError } from "./internal/schema/schema.ts"
|
|
116
|
-
import * as InternalToCodec from "./internal/schema/to-codec.ts"
|
|
117
116
|
import * as JsonPatch from "./JsonPatch.ts"
|
|
118
117
|
import * as JsonSchema from "./JsonSchema.ts"
|
|
119
118
|
import { remainder } from "./Number.ts"
|
|
@@ -1995,7 +1994,7 @@ export interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts> exte
|
|
|
1995
1994
|
export function TemplateLiteralParser<const Parts extends TemplateLiteral.Parts>(
|
|
1996
1995
|
parts: Parts
|
|
1997
1996
|
): TemplateLiteralParser<Parts> {
|
|
1998
|
-
return make(templateLiteralFromParts(parts).asTemplateLiteralParser(), { parts
|
|
1997
|
+
return make(templateLiteralFromParts(parts).asTemplateLiteralParser(), { parts })
|
|
1999
1998
|
}
|
|
2000
1999
|
|
|
2001
2000
|
/**
|
|
@@ -4930,9 +4929,8 @@ export function instanceOf<C extends abstract new(...args: any) => any, Iso = In
|
|
|
4930
4929
|
* Used when building low-level AST transformations that bridge two schema types.
|
|
4931
4930
|
*
|
|
4932
4931
|
* @since 4.0.0
|
|
4933
|
-
* @experimental
|
|
4934
4932
|
*/
|
|
4935
|
-
export function link<T>() {
|
|
4933
|
+
export function link<T>() {
|
|
4936
4934
|
return <To extends Top>(
|
|
4937
4935
|
encodeTo: To,
|
|
4938
4936
|
transformation: {
|
|
@@ -11496,7 +11494,66 @@ export function toJsonSchemaDocument(schema: Top, options?: ToJsonSchemaOptions)
|
|
|
11496
11494
|
* @since 4.0.0
|
|
11497
11495
|
*/
|
|
11498
11496
|
export function toCodecJson<T, E, RD, RE>(schema: Codec<T, E, RD, RE>): Codec<T, Json, RD, RE> {
|
|
11499
|
-
return make(
|
|
11497
|
+
return make(toCodecJsonTop(schema.ast))
|
|
11498
|
+
}
|
|
11499
|
+
|
|
11500
|
+
const toCodecJsonTop = AST.toCodec((ast) => {
|
|
11501
|
+
const out = toCodecJsonBase(ast, toCodecJsonTop)
|
|
11502
|
+
return out !== ast && AST.isOptional(ast) ? AST.optionalKeyLastLink(out) : out
|
|
11503
|
+
})
|
|
11504
|
+
|
|
11505
|
+
function toCodecJsonBase(ast: AST.AST, recur: (ast: AST.AST) => AST.AST): AST.AST {
|
|
11506
|
+
switch (ast._tag) {
|
|
11507
|
+
case "Declaration": {
|
|
11508
|
+
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec
|
|
11509
|
+
if (Predicate.isFunction(getLink)) {
|
|
11510
|
+
const tps = AST.isDeclaration(ast)
|
|
11511
|
+
? ast.typeParameters.map((tp) => InternalSchema.make(AST.toEncoded(tp)))
|
|
11512
|
+
: []
|
|
11513
|
+
const link = getLink(tps)
|
|
11514
|
+
const to = recur(link.to)
|
|
11515
|
+
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)])
|
|
11516
|
+
}
|
|
11517
|
+
return AST.replaceEncoding(ast, [AST.unknownToNull])
|
|
11518
|
+
}
|
|
11519
|
+
case "Unknown":
|
|
11520
|
+
case "ObjectKeyword":
|
|
11521
|
+
return AST.replaceEncoding(ast, [AST.unknownToJson])
|
|
11522
|
+
case "Undefined":
|
|
11523
|
+
case "Void":
|
|
11524
|
+
case "Literal":
|
|
11525
|
+
case "Number":
|
|
11526
|
+
return ast.toCodecJson()
|
|
11527
|
+
case "UniqueSymbol":
|
|
11528
|
+
case "Symbol":
|
|
11529
|
+
case "BigInt":
|
|
11530
|
+
return ast.toCodecStringTree()
|
|
11531
|
+
case "Objects": {
|
|
11532
|
+
if (ast.propertySignatures.some((ps) => typeof ps.name !== "string")) {
|
|
11533
|
+
throw new globalThis.Error("Objects property names must be strings", { cause: ast })
|
|
11534
|
+
}
|
|
11535
|
+
return ast.recur(recur)
|
|
11536
|
+
}
|
|
11537
|
+
case "Union": {
|
|
11538
|
+
const sortedTypes = InternalSchema.jsonReorder(ast.types)
|
|
11539
|
+
if (sortedTypes !== ast.types) {
|
|
11540
|
+
return new AST.Union(
|
|
11541
|
+
sortedTypes,
|
|
11542
|
+
ast.mode,
|
|
11543
|
+
ast.annotations,
|
|
11544
|
+
ast.checks,
|
|
11545
|
+
ast.encoding,
|
|
11546
|
+
ast.context
|
|
11547
|
+
).recur(recur)
|
|
11548
|
+
}
|
|
11549
|
+
return ast.recur(recur)
|
|
11550
|
+
}
|
|
11551
|
+
case "Arrays":
|
|
11552
|
+
case "Suspend":
|
|
11553
|
+
return ast.recur(recur)
|
|
11554
|
+
}
|
|
11555
|
+
// `Schema.Any` is used as an escape hatch
|
|
11556
|
+
return ast
|
|
11500
11557
|
}
|
|
11501
11558
|
|
|
11502
11559
|
/**
|
|
@@ -11507,7 +11564,32 @@ export function toCodecJson<T, E, RD, RE>(schema: Codec<T, E, RD, RE>): Codec<T,
|
|
|
11507
11564
|
* @since 4.0.0
|
|
11508
11565
|
*/
|
|
11509
11566
|
export function toCodecIso<S extends Top>(schema: S): Codec<S["Type"], S["Iso"]> {
|
|
11510
|
-
return make(
|
|
11567
|
+
return make(toCodecIsoTop(AST.toType(schema.ast)))
|
|
11568
|
+
}
|
|
11569
|
+
|
|
11570
|
+
const toCodecIsoTop = memoize((ast: AST.AST): AST.AST => {
|
|
11571
|
+
const out = toCodecIsoBase(ast, toCodecIsoTop)
|
|
11572
|
+
return out !== ast && AST.isOptional(ast) ? AST.optionalKeyLastLink(out) : out
|
|
11573
|
+
})
|
|
11574
|
+
|
|
11575
|
+
function toCodecIsoBase(ast: AST.AST, recur: (ast: AST.AST) => AST.AST): AST.AST {
|
|
11576
|
+
switch (ast._tag) {
|
|
11577
|
+
case "Declaration": {
|
|
11578
|
+
const getLink = ast.annotations?.toCodecIso ?? ast.annotations?.toCodec
|
|
11579
|
+
if (Predicate.isFunction(getLink)) {
|
|
11580
|
+
const link = getLink(ast.typeParameters.map((tp) => InternalSchema.make(tp)))
|
|
11581
|
+
const to = recur(link.to)
|
|
11582
|
+
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)])
|
|
11583
|
+
}
|
|
11584
|
+
return ast
|
|
11585
|
+
}
|
|
11586
|
+
case "Arrays":
|
|
11587
|
+
case "Objects":
|
|
11588
|
+
case "Union":
|
|
11589
|
+
case "Suspend":
|
|
11590
|
+
return ast.recur(recur)
|
|
11591
|
+
}
|
|
11592
|
+
return ast
|
|
11511
11593
|
}
|
|
11512
11594
|
|
|
11513
11595
|
/**
|
|
@@ -11546,11 +11628,13 @@ export function toCodecStringTree<T, E, RD, RE>(
|
|
|
11546
11628
|
schema: Codec<T, E, RD, RE>,
|
|
11547
11629
|
options?: { readonly keepDeclarations?: boolean | undefined }
|
|
11548
11630
|
): Codec<T, unknown, RD, RE> {
|
|
11549
|
-
|
|
11550
|
-
|
|
11551
|
-
|
|
11552
|
-
|
|
11553
|
-
|
|
11631
|
+
return make(
|
|
11632
|
+
toCodecEnsureArray(
|
|
11633
|
+
options?.keepDeclarations === true
|
|
11634
|
+
? serializerStringTreeKeepDeclarations(schema.ast)
|
|
11635
|
+
: serializerStringTree(schema.ast)
|
|
11636
|
+
)
|
|
11637
|
+
)
|
|
11554
11638
|
}
|
|
11555
11639
|
|
|
11556
11640
|
type XmlEncoderOptions = {
|
|
@@ -11683,7 +11767,7 @@ function getStringTreePriority(ast: AST.AST): number {
|
|
|
11683
11767
|
}
|
|
11684
11768
|
}
|
|
11685
11769
|
|
|
11686
|
-
const treeReorder =
|
|
11770
|
+
const treeReorder = InternalSchema.makeReorder(getStringTreePriority)
|
|
11687
11771
|
|
|
11688
11772
|
function serializerTree(
|
|
11689
11773
|
ast: AST.AST,
|
package/src/index.ts
CHANGED
|
@@ -1000,6 +1000,11 @@ export * as Duration from "./Duration.ts"
|
|
|
1000
1000
|
*/
|
|
1001
1001
|
export * as Effect from "./Effect.ts"
|
|
1002
1002
|
|
|
1003
|
+
/**
|
|
1004
|
+
* @since 4.0.0
|
|
1005
|
+
*/
|
|
1006
|
+
export * as Effectable from "./Effectable.ts"
|
|
1007
|
+
|
|
1003
1008
|
/**
|
|
1004
1009
|
* Encoding & decoding for Base64 (RFC4648), Base64Url, and Hex.
|
|
1005
1010
|
*
|
|
@@ -3528,6 +3533,7 @@ export * as SchemaAST from "./SchemaAST.ts"
|
|
|
3528
3533
|
* - Parse/stringify JSON → {@link parseJson}, {@link stringifyJson}
|
|
3529
3534
|
* - Encode/decode Base64 → {@link encodeBase64}, {@link decodeBase64}, {@link decodeBase64String}
|
|
3530
3535
|
* - Encode/decode Hex → {@link encodeHex}, {@link decodeHex}, {@link decodeHexString}
|
|
3536
|
+
* - Encode/decode URI components → {@link encodeUriComponent}, {@link decodeUriComponent}
|
|
3531
3537
|
* - Parse DateTime → {@link dateTimeUtcFromInput}
|
|
3532
3538
|
* - Decode/encode FormData → {@link decodeFormData}, {@link encodeFormData}
|
|
3533
3539
|
* - Decode/encode URLSearchParams → {@link decodeURLSearchParams}, {@link encodeURLSearchParams}
|
|
@@ -3795,6 +3801,8 @@ export * as SchemaRepresentation from "./SchemaRepresentation.ts"
|
|
|
3795
3801
|
* - Wrap nullable/optional as Option → {@link optionFromNullOr}, {@link optionFromOptionalKey}, {@link optionFromOptional}
|
|
3796
3802
|
* - Parse URLs → {@link urlFromString}
|
|
3797
3803
|
* - Base64 ↔ Uint8Array → {@link uint8ArrayFromBase64String}
|
|
3804
|
+
* - Base64 ↔ string → {@link stringFromBase64String}
|
|
3805
|
+
* - URI component ↔ string → {@link stringFromUriComponent}
|
|
3798
3806
|
* - JSON string ↔ unknown → {@link fromJsonString}
|
|
3799
3807
|
* - FormData/URLSearchParams ↔ unknown → {@link fromFormData}, {@link fromURLSearchParams}
|
|
3800
3808
|
* - Check if a value is a Transformation → {@link isTransformation}
|
package/src/internal/effect.ts
CHANGED
|
@@ -5307,7 +5307,7 @@ class Latch implements _Latch.Latch {
|
|
|
5307
5307
|
this.isOpen = true
|
|
5308
5308
|
return this.scheduleUnsafe(fiber)
|
|
5309
5309
|
})
|
|
5310
|
-
release = withFiber<boolean>((fiber) => this.
|
|
5310
|
+
release = withFiber<boolean>((fiber) => this.isOpen ? succeedFalse : this.scheduleUnsafe(fiber))
|
|
5311
5311
|
openUnsafe() {
|
|
5312
5312
|
if (this.isOpen) return false
|
|
5313
5313
|
this.isOpen = true
|
|
@@ -11,7 +11,6 @@ import * as AST from "../../SchemaAST.ts"
|
|
|
11
11
|
import type * as SchemaRepresentation from "../../SchemaRepresentation.ts"
|
|
12
12
|
import * as InternalAnnotations from "./annotations.ts"
|
|
13
13
|
import * as InternalSchema from "./schema.ts"
|
|
14
|
-
import * as InternalToCodec from "./to-codec.ts"
|
|
15
14
|
|
|
16
15
|
/** @internal */
|
|
17
16
|
export function fromAST(ast: AST.AST): SchemaRepresentation.Document {
|
|
@@ -213,7 +212,7 @@ export function fromASTs(asts: readonly [AST.AST, ...Array<AST.AST>]): SchemaRep
|
|
|
213
212
|
...annotations
|
|
214
213
|
}
|
|
215
214
|
case "Union": {
|
|
216
|
-
const types =
|
|
215
|
+
const types = InternalSchema.jsonReorder(last.types)
|
|
217
216
|
return {
|
|
218
217
|
_tag: last._tag,
|
|
219
218
|
types: types.map((ast) => recur(ast)),
|
|
@@ -42,6 +42,7 @@ export function make<S extends Schema.Top>(ast: S["ast"], options?: object): S {
|
|
|
42
42
|
/** @internal */
|
|
43
43
|
export const SchemaErrorTypeId = "~effect/Schema/SchemaError"
|
|
44
44
|
|
|
45
|
+
// not internal
|
|
45
46
|
export class SchemaError {
|
|
46
47
|
readonly [SchemaErrorTypeId] = SchemaErrorTypeId
|
|
47
48
|
readonly _tag = "SchemaError"
|
|
@@ -57,3 +58,45 @@ export class SchemaError {
|
|
|
57
58
|
return `SchemaError(${this.message})`
|
|
58
59
|
}
|
|
59
60
|
}
|
|
61
|
+
|
|
62
|
+
/** @internal */
|
|
63
|
+
export const jsonReorder = makeReorder(getJsonPriority)
|
|
64
|
+
|
|
65
|
+
function getJsonPriority(ast: AST.AST): number {
|
|
66
|
+
switch (ast._tag) {
|
|
67
|
+
case "BigInt":
|
|
68
|
+
case "Symbol":
|
|
69
|
+
case "UniqueSymbol":
|
|
70
|
+
return 0
|
|
71
|
+
default:
|
|
72
|
+
return 1
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** @internal */
|
|
77
|
+
export function makeReorder(getPriority: (ast: AST.AST) => number) {
|
|
78
|
+
return (types: ReadonlyArray<AST.AST>): ReadonlyArray<AST.AST> => {
|
|
79
|
+
// Create a map of original indices for O(1) lookup
|
|
80
|
+
const indexMap = new Map<AST.AST, number>()
|
|
81
|
+
for (let i = 0; i < types.length; i++) {
|
|
82
|
+
indexMap.set(AST.toEncoded(types[i]), i)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Create a sorted copy of the types array
|
|
86
|
+
const sortedTypes = [...types].sort((a, b) => {
|
|
87
|
+
a = AST.toEncoded(a)
|
|
88
|
+
b = AST.toEncoded(b)
|
|
89
|
+
const pa = getPriority(a)
|
|
90
|
+
const pb = getPriority(b)
|
|
91
|
+
if (pa !== pb) return pa - pb
|
|
92
|
+
// If priorities are equal, maintain original order (stable sort)
|
|
93
|
+
return indexMap.get(a)! - indexMap.get(b)!
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
// Check if order changed by comparing arrays
|
|
97
|
+
const orderChanged = sortedTypes.some((ast, index) => ast !== types[index])
|
|
98
|
+
|
|
99
|
+
if (!orderChanged) return types
|
|
100
|
+
return sortedTypes
|
|
101
|
+
}
|
|
102
|
+
}
|
package/src/testing/TestClock.ts
CHANGED
|
@@ -235,7 +235,7 @@ export const make = Effect.fnUntraced(function*(
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
function currentTimeNanosUnsafe(): bigint {
|
|
238
|
-
return BigInt(currentTimestamp * 1000000)
|
|
238
|
+
return BigInt(Math.floor(currentTimestamp * 1000000))
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
const currentTimeMillis = Effect.sync(currentTimeMillisUnsafe)
|
|
@@ -383,6 +383,14 @@ export const run: (options: {
|
|
|
383
383
|
const initializePayload = getInitializedClient(clientSessions, client.id, headers)
|
|
384
384
|
const isInitialize = rpc._tag === "initialize"
|
|
385
385
|
if (!isInitialize && !initializePayload) {
|
|
386
|
+
const fiber = Fiber.getCurrent()!
|
|
387
|
+
const httpRequest = Context.getOrUndefined(fiber.context, HttpServerRequest.HttpServerRequest)
|
|
388
|
+
if (httpRequest) {
|
|
389
|
+
appendPreResponseHandlerUnsafe(
|
|
390
|
+
httpRequest,
|
|
391
|
+
() => Effect.succeed(HttpServerResponse.empty({ status: 404 }))
|
|
392
|
+
)
|
|
393
|
+
}
|
|
386
394
|
return Effect.die(new Error(`Mcp-Session-Id does not exist`))
|
|
387
395
|
}
|
|
388
396
|
return Effect.provideService(
|
|
@@ -472,7 +472,7 @@ export const make = Effect.gen(function*() {
|
|
|
472
472
|
activities.set(activityId, { activity, context: services })
|
|
473
473
|
const latch = activityLatches.get(activityId)
|
|
474
474
|
if (latch) {
|
|
475
|
-
yield* latch.
|
|
475
|
+
yield* latch.open
|
|
476
476
|
activityLatches.delete(activityId)
|
|
477
477
|
}
|
|
478
478
|
}
|
|
@@ -46,10 +46,11 @@ export interface HttpIncomingMessage<E = unknown> extends Inspectable.Inspectabl
|
|
|
46
46
|
* @category schema
|
|
47
47
|
*/
|
|
48
48
|
export const schemaBodyJson = <S extends Schema.Top>(schema: S, options?: ParseOptions | undefined) => {
|
|
49
|
-
const decode = Schema.decodeEffect(Schema.toCodecJson(schema)
|
|
49
|
+
const decode = Schema.decodeEffect(Schema.toCodecJson(schema))
|
|
50
50
|
return <E>(
|
|
51
51
|
self: HttpIncomingMessage<E>
|
|
52
|
-
): Effect.Effect<S["Type"], E | Schema.SchemaError, S["DecodingServices"]> =>
|
|
52
|
+
): Effect.Effect<S["Type"], E | Schema.SchemaError, S["DecodingServices"]> =>
|
|
53
|
+
Effect.flatMap(self.json, (u) => decode(u, options))
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
/**
|
|
@@ -67,11 +68,10 @@ export const schemaBodyUrlParams = <
|
|
|
67
68
|
) => {
|
|
68
69
|
const decode = UrlParams.schemaRecord.pipe(
|
|
69
70
|
Schema.decodeTo(schema),
|
|
70
|
-
Schema.annotate({ options }),
|
|
71
71
|
Schema.decodeEffect
|
|
72
72
|
)
|
|
73
73
|
return <E>(self: HttpIncomingMessage<E>): Effect.Effect<A, E | Schema.SchemaError, RD> =>
|
|
74
|
-
Effect.flatMap(self.urlParamsBody, decode)
|
|
74
|
+
Effect.flatMap(self.urlParamsBody, (u) => decode(u, options))
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -255,7 +255,7 @@ export const reflect = <Id extends string, Groups extends HttpApiGroup.Any>(
|
|
|
255
255
|
// -------------------------------------------------------------------------------------
|
|
256
256
|
|
|
257
257
|
const extractResponseContent = (
|
|
258
|
-
schemas:
|
|
258
|
+
schemas: Array<Schema.Top>,
|
|
259
259
|
getStatus: (ast: AST.AST) => number
|
|
260
260
|
): ReadonlyMap<number, [Schema.Top, ...Array<Schema.Top>]> => {
|
|
261
261
|
const map = new Map<number, [Schema.Top, ...Array<Schema.Top>]>()
|
|
@@ -36,6 +36,7 @@ import * as Multipart from "../http/Multipart.ts"
|
|
|
36
36
|
import * as UrlParams from "../http/UrlParams.ts"
|
|
37
37
|
import type * as HttpApi from "./HttpApi.ts"
|
|
38
38
|
import * as HttpApiEndpoint from "./HttpApiEndpoint.ts"
|
|
39
|
+
import { HttpApiSchemaError } from "./HttpApiError.ts"
|
|
39
40
|
import type * as HttpApiGroup from "./HttpApiGroup.ts"
|
|
40
41
|
import * as HttpApiMiddleware from "./HttpApiMiddleware.ts"
|
|
41
42
|
import * as HttpApiSchema from "./HttpApiSchema.ts"
|
|
@@ -589,13 +590,13 @@ function handlerToHttpEffect(
|
|
|
589
590
|
group
|
|
590
591
|
}
|
|
591
592
|
if (decodeParams) {
|
|
592
|
-
request.params = yield* decodeParams(routeContext.params)
|
|
593
|
+
request.params = yield* HttpApiSchemaError.wrap("Params", decodeParams(routeContext.params))
|
|
593
594
|
}
|
|
594
595
|
if (decodeHeaders) {
|
|
595
|
-
request.headers = yield* decodeHeaders(httpRequest.headers)
|
|
596
|
+
request.headers = yield* HttpApiSchemaError.wrap("Headers", decodeHeaders(httpRequest.headers))
|
|
596
597
|
}
|
|
597
598
|
if (decodeQuery) {
|
|
598
|
-
request.query = yield* decodeQuery(query)
|
|
599
|
+
request.query = yield* HttpApiSchemaError.wrap("Query", decodeQuery(query))
|
|
599
600
|
}
|
|
600
601
|
if (payloadBy) {
|
|
601
602
|
const result = decodePayload(payloadBy, httpRequest, query)
|
|
@@ -603,15 +604,20 @@ function handlerToHttpEffect(
|
|
|
603
604
|
return result
|
|
604
605
|
}
|
|
605
606
|
if (result !== undefined) {
|
|
606
|
-
request.payload = yield* result
|
|
607
|
+
request.payload = yield* HttpApiSchemaError.wrap("Payload", result)
|
|
607
608
|
}
|
|
608
609
|
}
|
|
609
610
|
const response = yield* handler(request)
|
|
610
|
-
return Response.isHttpServerResponse(response)
|
|
611
|
+
return Response.isHttpServerResponse(response)
|
|
612
|
+
? response
|
|
613
|
+
: yield* HttpApiSchemaError.wrap("Body", encodeSuccess(response))
|
|
611
614
|
})
|
|
612
615
|
).pipe(
|
|
613
616
|
Effect.withErrorReporting,
|
|
614
|
-
Effect.catch((error) =>
|
|
617
|
+
Effect.catch((error) => {
|
|
618
|
+
if (HttpApiSchemaError.is(error)) return Effect.die(error)
|
|
619
|
+
return Effect.orDie(encodeError(error))
|
|
620
|
+
}),
|
|
615
621
|
Effect.provideContext(context)
|
|
616
622
|
)
|
|
617
623
|
}
|
|
@@ -719,6 +725,7 @@ function makeSuccessSchema(endpoint: HttpApiEndpoint.AnyWithProps): Schema.Encod
|
|
|
719
725
|
|
|
720
726
|
function makeErrorSchema(endpoint: HttpApiEndpoint.AnyWithProps): Schema.Encoder<HttpServerResponse, unknown> {
|
|
721
727
|
const schemas = HttpApiEndpoint.getErrorSchemas(endpoint).map(toResponseErrorSchema)
|
|
728
|
+
if (schemas.length === 0) return Schema.Never
|
|
722
729
|
return schemas.length === 1 ? schemas[0] : Schema.Union(schemas)
|
|
723
730
|
}
|
|
724
731
|
|
|
@@ -23,7 +23,6 @@ import * as HttpMethod from "../http/HttpMethod.ts"
|
|
|
23
23
|
import * as UrlParams from "../http/UrlParams.ts"
|
|
24
24
|
import * as HttpApi from "./HttpApi.ts"
|
|
25
25
|
import * as HttpApiEndpoint from "./HttpApiEndpoint.ts"
|
|
26
|
-
import type { BadRequest } from "./HttpApiError.ts"
|
|
27
26
|
import type * as HttpApiGroup from "./HttpApiGroup.ts"
|
|
28
27
|
import type * as HttpApiMiddleware from "./HttpApiMiddleware.ts"
|
|
29
28
|
import * as HttpApiSchema from "./HttpApiSchema.ts"
|
|
@@ -32,7 +31,7 @@ import * as HttpApiSchema from "./HttpApiSchema.ts"
|
|
|
32
31
|
* @since 4.0.0
|
|
33
32
|
* @category models
|
|
34
33
|
*/
|
|
35
|
-
export type Client<Groups extends HttpApiGroup.Any, E =
|
|
34
|
+
export type Client<Groups extends HttpApiGroup.Any, E = never, R = never> = Simplify<
|
|
36
35
|
& {
|
|
37
36
|
readonly [Group in Extract<Groups, { readonly topLevel: false }> as HttpApiGroup.Name<Group>]: Client.Group<
|
|
38
37
|
Group,
|
|
@@ -50,7 +49,7 @@ export type Client<Groups extends HttpApiGroup.Any, E = BadRequest, R = never> =
|
|
|
50
49
|
* @since 4.0.0
|
|
51
50
|
* @category models
|
|
52
51
|
*/
|
|
53
|
-
export type ForApi<Api extends HttpApi.Any, E =
|
|
52
|
+
export type ForApi<Api extends HttpApi.Any, E = never, R = never> = Api extends
|
|
54
53
|
HttpApi.HttpApi<infer _Id, infer Groups> ? Client<Groups, E, R> :
|
|
55
54
|
never
|
|
56
55
|
|
|
@@ -405,7 +404,7 @@ export const makeWith = <ApiId extends string, Groups extends HttpApiGroup.Any,
|
|
|
405
404
|
| undefined
|
|
406
405
|
readonly baseUrl?: URL | string | undefined
|
|
407
406
|
}
|
|
408
|
-
): Effect.Effect<Client<Groups,
|
|
407
|
+
): Effect.Effect<Client<Groups, E, R>, never, HttpApiGroup.MiddlewareClient<Groups>> => {
|
|
409
408
|
const client: Record<string, Record<string, any>> = {}
|
|
410
409
|
return makeClient(api, {
|
|
411
410
|
...options,
|
|
@@ -440,7 +439,7 @@ export const group = <
|
|
|
440
439
|
readonly baseUrl?: URL | string | undefined
|
|
441
440
|
}
|
|
442
441
|
): Effect.Effect<
|
|
443
|
-
Client.Group<Groups, GroupName,
|
|
442
|
+
Client.Group<Groups, GroupName, E, R>,
|
|
444
443
|
never,
|
|
445
444
|
HttpApiGroup.MiddlewareClient<HttpApiGroup.WithName<Groups, GroupName>>
|
|
446
445
|
> => {
|
|
@@ -480,7 +479,7 @@ export const endpoint = <
|
|
|
480
479
|
): Effect.Effect<
|
|
481
480
|
Client.Method<
|
|
482
481
|
HttpApiEndpoint.WithName<HttpApiGroup.Endpoints<HttpApiGroup.WithName<Groups, GroupName>>, EndpointName>,
|
|
483
|
-
|
|
482
|
+
E,
|
|
484
483
|
R
|
|
485
484
|
>,
|
|
486
485
|
never,
|