effect 4.0.0-beta.85 → 4.0.0-beta.87
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/ChannelSchema.d.ts +8 -8
- package/dist/ChannelSchema.d.ts.map +1 -1
- package/dist/Config.d.ts +2 -2
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +10 -3
- package/dist/Config.js.map +1 -1
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +4 -0
- package/dist/Cron.js.map +1 -1
- package/dist/Schema.d.ts +749 -393
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +95 -65
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +20 -29
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaParser.d.ts +24 -24
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +43 -39
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +300 -300
- package/dist/SchemaTransformation.d.ts +2 -2
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +5 -8
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/internal/effect.js +6 -7
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/matcher.js +0 -2
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/schema/representation.js +1 -5
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +9 -9
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +3 -2
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +2 -2
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +1 -1
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +4 -4
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +13 -6
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +4 -4
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +2 -2
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Response.d.ts +2 -2
- package/dist/unstable/ai/Response.d.ts.map +1 -1
- package/dist/unstable/ai/Response.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +26 -26
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/Argument.d.ts +8 -7
- package/dist/unstable/cli/Argument.d.ts.map +1 -1
- package/dist/unstable/cli/Argument.js.map +1 -1
- package/dist/unstable/cli/Flag.d.ts +8 -7
- package/dist/unstable/cli/Flag.d.ts.map +1 -1
- package/dist/unstable/cli/Flag.js.map +1 -1
- package/dist/unstable/cli/Param.d.ts +1806 -168
- package/dist/unstable/cli/Param.d.ts.map +1 -1
- package/dist/unstable/cli/Param.js +0 -70
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Primitive.d.ts +3 -4
- package/dist/unstable/cli/Primitive.d.ts.map +1 -1
- package/dist/unstable/cli/Primitive.js.map +1 -1
- package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
- package/dist/unstable/cli/internal/ansi.js +0 -22
- package/dist/unstable/cli/internal/ansi.js.map +1 -1
- package/dist/unstable/cli/internal/config.d.ts +48 -0
- package/dist/unstable/cli/internal/config.d.ts.map +1 -1
- package/dist/unstable/cli/internal/config.js +0 -6
- package/dist/unstable/cli/internal/config.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +3 -3
- package/dist/unstable/cluster/Reply.d.ts +2 -2
- package/dist/unstable/cluster/Reply.d.ts.map +1 -1
- package/dist/unstable/cluster/Reply.js.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
- package/dist/unstable/encoding/Msgpack.d.ts +6 -6
- package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
- package/dist/unstable/encoding/Msgpack.js.map +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +8 -8
- package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.d.ts +1 -1
- package/dist/unstable/encoding/Sse.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.d.ts +22 -22
- package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.d.ts +15 -15
- package/dist/unstable/http/HttpBody.d.ts +1 -1
- package/dist/unstable/http/HttpBody.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
- package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +12 -3
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +2 -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 +32 -32
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +13 -6
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js +0 -13
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/internal/otlpProtobuf.js +0 -68
- package/dist/unstable/observability/internal/otlpProtobuf.js.map +1 -1
- package/dist/unstable/observability/internal/protobuf.js +0 -28
- package/dist/unstable/observability/internal/protobuf.js.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.d.ts +2 -2
- package/dist/unstable/persistence/KeyValueStore.d.ts.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
- package/dist/unstable/persistence/Persistable.d.ts +6 -6
- package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.d.ts +3 -3
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Persistence.d.ts +5 -5
- package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.d.ts +2 -2
- package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +1 -1
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +3 -4
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js +1 -1
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +25 -4
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcMessage.d.ts +7 -0
- package/dist/unstable/rpc/RpcMessage.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMessage.js +20 -0
- package/dist/unstable/rpc/RpcMessage.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +2 -2
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.d.ts +10 -3
- package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.js.map +1 -1
- package/dist/unstable/rpc/RpcWorker.d.ts +3 -3
- package/dist/unstable/rpc/RpcWorker.d.ts.map +1 -1
- package/dist/unstable/schema/Model.d.ts +2 -2
- package/dist/unstable/schema/Model.d.ts.map +1 -1
- package/dist/unstable/schema/Model.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +16 -2
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/sql/SqlConnection.d.ts +1 -0
- package/dist/unstable/sql/SqlConnection.d.ts.map +1 -1
- package/dist/unstable/sql/SqlConnection.js.map +1 -1
- package/dist/unstable/sql/SqlModel.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.d.ts +4 -4
- package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/sql/SqlSchema.d.ts +5 -5
- package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.d.ts +1 -0
- package/dist/unstable/sql/Statement.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.js +3 -0
- package/dist/unstable/sql/Statement.js.map +1 -1
- package/dist/unstable/workflow/Activity.d.ts +2 -2
- package/dist/unstable/workflow/Activity.d.ts.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.d.ts +18 -18
- package/dist/unstable/workflow/DurableDeferred.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +3 -3
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +3 -3
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ChannelSchema.ts +9 -9
- package/src/Config.ts +12 -5
- package/src/Cron.ts +4 -0
- package/src/Schema.ts +968 -689
- package/src/SchemaAST.ts +25 -35
- package/src/SchemaParser.ts +85 -77
- package/src/SchemaTransformation.ts +5 -6
- package/src/internal/effect.ts +6 -22
- package/src/internal/matcher.ts +0 -5
- package/src/internal/schema/arbitrary.ts +1 -1
- package/src/internal/schema/representation.ts +1 -5
- package/src/internal/schema/schema.ts +1 -1
- package/src/testing/TestSchema.ts +14 -13
- package/src/unstable/ai/AnthropicStructuredOutput.ts +2 -2
- package/src/unstable/ai/Chat.ts +1 -1
- package/src/unstable/ai/LanguageModel.ts +7 -7
- package/src/unstable/ai/McpSchema.ts +16 -14
- package/src/unstable/ai/McpServer.ts +7 -7
- package/src/unstable/ai/OpenAiStructuredOutput.ts +2 -2
- package/src/unstable/ai/Response.ts +9 -5
- package/src/unstable/ai/Tool.ts +49 -47
- package/src/unstable/cli/Argument.ts +9 -8
- package/src/unstable/cli/Flag.ts +9 -8
- package/src/unstable/cli/Param.ts +6 -146
- package/src/unstable/cli/Primitive.ts +5 -6
- package/src/unstable/cli/internal/ansi.ts +0 -33
- package/src/unstable/cli/internal/config.ts +0 -8
- package/src/unstable/cli/internal/parser.ts +2 -2
- package/src/unstable/cluster/MessageStorage.ts +1 -1
- package/src/unstable/cluster/Reply.ts +6 -2
- package/src/unstable/devtools/DevToolsSchema.ts +1 -1
- package/src/unstable/encoding/Msgpack.ts +9 -7
- package/src/unstable/encoding/Ndjson.ts +10 -10
- package/src/unstable/encoding/Sse.ts +1 -1
- package/src/unstable/eventlog/Event.ts +3 -3
- package/src/unstable/http/HttpBody.ts +1 -1
- package/src/unstable/http/HttpClientRequest.ts +1 -1
- package/src/unstable/http/HttpIncomingMessage.ts +1 -1
- package/src/unstable/http/HttpMiddleware.ts +12 -3
- package/src/unstable/httpapi/HttpApi.ts +1 -1
- package/src/unstable/httpapi/HttpApiBuilder.ts +9 -5
- package/src/unstable/httpapi/HttpApiClient.ts +10 -10
- package/src/unstable/httpapi/HttpApiEndpoint.ts +45 -33
- package/src/unstable/httpapi/HttpApiMiddleware.ts +2 -2
- package/src/unstable/httpapi/HttpApiSchema.ts +16 -43
- package/src/unstable/httpapi/OpenApi.ts +5 -5
- package/src/unstable/observability/internal/otlpProtobuf.ts +0 -75
- package/src/unstable/observability/internal/protobuf.ts +0 -42
- package/src/unstable/persistence/KeyValueStore.ts +2 -2
- package/src/unstable/persistence/Persistable.ts +7 -7
- package/src/unstable/persistence/PersistedQueue.ts +3 -3
- package/src/unstable/persistence/Persistence.ts +5 -5
- package/src/unstable/reactivity/AsyncResult.ts +4 -4
- package/src/unstable/reactivity/Atom.ts +1 -1
- package/src/unstable/reactivity/AtomHttpApi.ts +1 -1
- package/src/unstable/rpc/Rpc.ts +7 -8
- package/src/unstable/rpc/RpcClient.ts +26 -4
- package/src/unstable/rpc/RpcMessage.ts +19 -0
- package/src/unstable/rpc/RpcMiddleware.ts +2 -2
- package/src/unstable/rpc/RpcSchema.ts +12 -9
- package/src/unstable/rpc/RpcWorker.ts +3 -3
- package/src/unstable/schema/Model.ts +2 -2
- package/src/unstable/schema/VariantSchema.ts +19 -17
- package/src/unstable/sql/SqlConnection.ts +5 -0
- package/src/unstable/sql/SqlModel.ts +2 -2
- package/src/unstable/sql/SqlResolver.ts +6 -6
- package/src/unstable/sql/SqlSchema.ts +5 -5
- package/src/unstable/sql/Statement.ts +11 -0
- package/src/unstable/workflow/Activity.ts +6 -6
- package/src/unstable/workflow/DurableDeferred.ts +33 -33
- package/src/unstable/workflow/Workflow.ts +5 -5
- package/src/unstable/workflow/WorkflowEngine.ts +10 -10
- package/dist/internal/concurrency.d.ts +0 -2
- package/dist/internal/concurrency.d.ts.map +0 -1
- package/dist/internal/concurrency.js +0 -29
- package/dist/internal/concurrency.js.map +0 -1
- package/src/internal/concurrency.ts +0 -52
package/src/SchemaAST.ts
CHANGED
|
@@ -680,7 +680,7 @@ export class Declaration extends Base {
|
|
|
680
680
|
}
|
|
681
681
|
private _rebuild(recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) {
|
|
682
682
|
const tps = mapOrSame(this.typeParameters, recur)
|
|
683
|
-
return tps === this.typeParameters ?
|
|
683
|
+
return tps === this.typeParameters && checks === this.checks && encodingChecks === this.encodingChecks ?
|
|
684
684
|
this :
|
|
685
685
|
new Declaration(tps, this.run, this.annotations, checks, undefined, this.context, encodingChecks)
|
|
686
686
|
}
|
|
@@ -1704,7 +1704,8 @@ export class Arrays extends Base {
|
|
|
1704
1704
|
private _rebuild(recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) {
|
|
1705
1705
|
const elements = mapOrSame(this.elements, recur)
|
|
1706
1706
|
const rest = mapOrSame(this.rest, recur)
|
|
1707
|
-
return elements === this.elements && rest === this.rest
|
|
1707
|
+
return elements === this.elements && rest === this.rest && checks === this.checks &&
|
|
1708
|
+
encodingChecks === this.encodingChecks ?
|
|
1708
1709
|
this :
|
|
1709
1710
|
new Arrays(
|
|
1710
1711
|
this.isMutable,
|
|
@@ -2245,7 +2246,8 @@ export class Objects extends Base {
|
|
|
2245
2246
|
: new IndexSignature(p, t, merge)
|
|
2246
2247
|
})
|
|
2247
2248
|
|
|
2248
|
-
return props === this.propertySignatures && indexes === this.indexSignatures
|
|
2249
|
+
return props === this.propertySignatures && indexes === this.indexSignatures && checks === this.checks &&
|
|
2250
|
+
encodingChecks === this.encodingChecks
|
|
2249
2251
|
? this
|
|
2250
2252
|
: new Objects(
|
|
2251
2253
|
props,
|
|
@@ -2345,7 +2347,7 @@ export function struct<Fields extends Schema.Struct.Fields>(
|
|
|
2345
2347
|
}
|
|
2346
2348
|
|
|
2347
2349
|
/** @internal */
|
|
2348
|
-
export function getAST<S extends
|
|
2350
|
+
export function getAST<S extends { readonly ast: AST }>(self: S): S["ast"] {
|
|
2349
2351
|
return self.ast
|
|
2350
2352
|
}
|
|
2351
2353
|
|
|
@@ -2358,7 +2360,7 @@ export function tuple<Elements extends Schema.Tuple.Elements>(
|
|
|
2358
2360
|
}
|
|
2359
2361
|
|
|
2360
2362
|
/** @internal */
|
|
2361
|
-
export function union<Members extends ReadonlyArray<
|
|
2363
|
+
export function union<Members extends ReadonlyArray<{ readonly ast: AST }>>(
|
|
2362
2364
|
members: Members,
|
|
2363
2365
|
mode: "anyOf" | "oneOf",
|
|
2364
2366
|
checks: Checks | undefined
|
|
@@ -2661,7 +2663,7 @@ export class Union<A extends AST = AST> extends Base {
|
|
|
2661
2663
|
}
|
|
2662
2664
|
private _rebuild(recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) {
|
|
2663
2665
|
const types = mapOrSame(this.types, recur)
|
|
2664
|
-
return types === this.types ?
|
|
2666
|
+
return types === this.types && checks === this.checks && encodingChecks === this.encodingChecks ?
|
|
2665
2667
|
this :
|
|
2666
2668
|
new Union(types, this.mode, this.annotations, checks, undefined, this.context, encodingChecks)
|
|
2667
2669
|
}
|
|
@@ -2860,19 +2862,6 @@ export class Suspend extends Base {
|
|
|
2860
2862
|
}
|
|
2861
2863
|
}
|
|
2862
2864
|
|
|
2863
|
-
/** @internal */
|
|
2864
|
-
export function getEncodingChecks(ast: AST): Checks | undefined {
|
|
2865
|
-
switch (ast._tag) {
|
|
2866
|
-
case "Declaration":
|
|
2867
|
-
case "Arrays":
|
|
2868
|
-
case "Objects":
|
|
2869
|
-
case "Union":
|
|
2870
|
-
return ast.encodingChecks
|
|
2871
|
-
default:
|
|
2872
|
-
return undefined
|
|
2873
|
-
}
|
|
2874
|
-
}
|
|
2875
|
-
|
|
2876
2865
|
// -----------------------------------------------------------------------------
|
|
2877
2866
|
// Checks
|
|
2878
2867
|
// -----------------------------------------------------------------------------
|
|
@@ -3140,6 +3129,14 @@ export function applyToLastLink(f: (ast: AST) => AST) {
|
|
|
3140
3129
|
return <A extends AST>(ast: A): A => ast.encoding ? replaceEncoding(ast, updateLastLink(ast.encoding, f)) : ast
|
|
3141
3130
|
}
|
|
3142
3131
|
|
|
3132
|
+
/** @internal */
|
|
3133
|
+
export function applyToSelfOrLastLinkEncoding(f: (ast: AST) => AST) {
|
|
3134
|
+
function out(ast: AST): AST {
|
|
3135
|
+
return ast.encoding ? replaceEncoding(ast, updateLastLink(ast.encoding, out)) : f(ast)
|
|
3136
|
+
}
|
|
3137
|
+
return memoize(out)
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3143
3140
|
/** @internal */
|
|
3144
3141
|
export function middlewareDecoding(
|
|
3145
3142
|
ast: AST,
|
|
@@ -3384,9 +3381,13 @@ export const toType = memoize(<A extends AST>(ast: A): A => {
|
|
|
3384
3381
|
}
|
|
3385
3382
|
const out: any = ast
|
|
3386
3383
|
const type = out.recur?.(toType) ?? out
|
|
3387
|
-
|
|
3384
|
+
const encodingChecks = type.encodingChecks
|
|
3385
|
+
if (encodingChecks) {
|
|
3388
3386
|
return modifyOwnPropertyDescriptors(type, (d) => {
|
|
3389
3387
|
d.encodingChecks.value = undefined
|
|
3388
|
+
if (type === ast) {
|
|
3389
|
+
d.checks.value = combineChecks(type.checks, encodingChecks)
|
|
3390
|
+
}
|
|
3390
3391
|
})
|
|
3391
3392
|
}
|
|
3392
3393
|
return type
|
|
@@ -3560,15 +3561,7 @@ export const enumsToLiterals = memoize((ast: Enum): Union<Literal> => {
|
|
|
3560
3561
|
)
|
|
3561
3562
|
})
|
|
3562
3563
|
|
|
3563
|
-
|
|
3564
|
-
export function toCodec(f: (ast: AST) => AST) {
|
|
3565
|
-
function out(ast: AST): AST {
|
|
3566
|
-
return ast.encoding ? replaceEncoding(ast, updateLastLink(ast.encoding, out)) : f(ast)
|
|
3567
|
-
}
|
|
3568
|
-
return memoize(out)
|
|
3569
|
-
}
|
|
3570
|
-
|
|
3571
|
-
const parameterFromPropertyKey = toCodec((ast) => {
|
|
3564
|
+
const parameterFromPropertyKey = applyToSelfOrLastLinkEncoding((ast) => {
|
|
3572
3565
|
switch (ast._tag) {
|
|
3573
3566
|
default:
|
|
3574
3567
|
return ast
|
|
@@ -3580,7 +3573,7 @@ const parameterFromPropertyKey = toCodec((ast) => {
|
|
|
3580
3573
|
})
|
|
3581
3574
|
|
|
3582
3575
|
/** @internal */
|
|
3583
|
-
export const parameterFromString =
|
|
3576
|
+
export const parameterFromString = applyToSelfOrLastLinkEncoding((ast) => {
|
|
3584
3577
|
switch (ast._tag) {
|
|
3585
3578
|
default:
|
|
3586
3579
|
return ast
|
|
@@ -3592,7 +3585,7 @@ export const parameterFromString = toCodec((ast) => {
|
|
|
3592
3585
|
}
|
|
3593
3586
|
})
|
|
3594
3587
|
|
|
3595
|
-
const partFromString =
|
|
3588
|
+
const partFromString = applyToSelfOrLastLinkEncoding((ast) => {
|
|
3596
3589
|
switch (ast._tag) {
|
|
3597
3590
|
default:
|
|
3598
3591
|
return ast
|
|
@@ -3970,10 +3963,7 @@ const StringTree = new Declaration(
|
|
|
3970
3963
|
isStringTree(input) ?
|
|
3971
3964
|
Effect.succeed(input) :
|
|
3972
3965
|
Effect.fail(new SchemaIssue.InvalidType(ast, Option.some(input))),
|
|
3973
|
-
{
|
|
3974
|
-
expected: "StringTree",
|
|
3975
|
-
toCodecStringTree: () => new Link(unknown, SchemaTransformation.passthrough())
|
|
3976
|
-
}
|
|
3966
|
+
{ expected: "StringTree" }
|
|
3977
3967
|
)
|
|
3978
3968
|
|
|
3979
3969
|
/** @internal */
|
package/src/SchemaParser.ts
CHANGED
|
@@ -67,7 +67,7 @@ const recurDefaults = memoize((ast: SchemaAST.AST): SchemaAST.AST => {
|
|
|
67
67
|
* @category constructors
|
|
68
68
|
* @since 4.0.0
|
|
69
69
|
*/
|
|
70
|
-
export function makeEffect<S extends Schema.
|
|
70
|
+
export function makeEffect<S extends Schema.Constraint>(schema: S) {
|
|
71
71
|
const ast = recurDefaults(SchemaAST.toType(schema.ast))
|
|
72
72
|
const parser = run<S["Type"], never>(ast)
|
|
73
73
|
return (input: S["~type.make.in"], options?: Schema.MakeOptions): Effect.Effect<S["Type"], SchemaIssue.Issue> => {
|
|
@@ -98,7 +98,7 @@ export function makeEffect<S extends Schema.Top>(schema: S) {
|
|
|
98
98
|
* @category constructors
|
|
99
99
|
* @since 4.0.0
|
|
100
100
|
*/
|
|
101
|
-
export function makeOption<S extends Schema.
|
|
101
|
+
export function makeOption<S extends Schema.Constraint>(schema: S) {
|
|
102
102
|
const parser = makeEffect(schema)
|
|
103
103
|
return (input: S["~type.make.in"], options?: Schema.MakeOptions): Option.Option<S["Type"]> => {
|
|
104
104
|
const exit = Effect.runSyncExit(parser(input, options))
|
|
@@ -132,7 +132,7 @@ export function makeOption<S extends Schema.Top>(schema: S) {
|
|
|
132
132
|
* @category constructors
|
|
133
133
|
* @since 4.0.0
|
|
134
134
|
*/
|
|
135
|
-
export function make<S extends Schema.
|
|
135
|
+
export function make<S extends Schema.Constraint>(schema: S) {
|
|
136
136
|
const parser = makeEffect(schema)
|
|
137
137
|
return (input: S["~type.make.in"], options?: Schema.MakeOptions): S["Type"] => {
|
|
138
138
|
const exit = Effect.runSyncExit(parser(input, options))
|
|
@@ -222,7 +222,7 @@ export function _issue<T>(ast: SchemaAST.AST) {
|
|
|
222
222
|
* @category Asserting
|
|
223
223
|
* @since 4.0.0
|
|
224
224
|
*/
|
|
225
|
-
export function asserts<S extends Schema.
|
|
225
|
+
export function asserts<S extends Schema.Constraint, I>(schema: S, input: I): asserts input is I & S["Type"] {
|
|
226
226
|
const parser = asExit(run<S["Type"], never>(SchemaAST.toType(schema.ast)))
|
|
227
227
|
const exit = parser(input, SchemaAST.defaultParseOptions)
|
|
228
228
|
if (Exit.isFailure(exit)) {
|
|
@@ -255,7 +255,7 @@ export function asserts<S extends Schema.Top, I>(schema: S, input: I): asserts i
|
|
|
255
255
|
* @category decoding
|
|
256
256
|
* @since 4.0.0
|
|
257
257
|
*/
|
|
258
|
-
export function decodeUnknownEffect<S extends Schema.
|
|
258
|
+
export function decodeUnknownEffect<S extends Schema.Constraint>(
|
|
259
259
|
schema: S,
|
|
260
260
|
options?: SchemaAST.ParseOptions
|
|
261
261
|
): (
|
|
@@ -290,7 +290,7 @@ export function decodeUnknownEffect<S extends Schema.Top>(
|
|
|
290
290
|
* @category decoding
|
|
291
291
|
* @since 4.0.0
|
|
292
292
|
*/
|
|
293
|
-
export const decodeEffect: <S extends Schema.
|
|
293
|
+
export const decodeEffect: <S extends Schema.Constraint>(
|
|
294
294
|
schema: S,
|
|
295
295
|
options?: SchemaAST.ParseOptions
|
|
296
296
|
) => (
|
|
@@ -322,7 +322,7 @@ export const decodeEffect: <S extends Schema.Top>(
|
|
|
322
322
|
* @category decoding
|
|
323
323
|
* @since 3.10.0
|
|
324
324
|
*/
|
|
325
|
-
export function decodeUnknownPromise<S extends Schema.
|
|
325
|
+
export function decodeUnknownPromise<S extends Schema.ConstraintDecoder<unknown>>(
|
|
326
326
|
schema: S,
|
|
327
327
|
options?: SchemaAST.ParseOptions
|
|
328
328
|
): (input: unknown, options?: SchemaAST.ParseOptions) => Promise<S["Type"]> {
|
|
@@ -354,7 +354,7 @@ export function decodeUnknownPromise<S extends Schema.Decoder<unknown>>(
|
|
|
354
354
|
* @category decoding
|
|
355
355
|
* @since 3.10.0
|
|
356
356
|
*/
|
|
357
|
-
export function decodePromise<S extends Schema.
|
|
357
|
+
export function decodePromise<S extends Schema.ConstraintDecoder<unknown>>(
|
|
358
358
|
schema: S,
|
|
359
359
|
options?: SchemaAST.ParseOptions
|
|
360
360
|
): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Promise<S["Type"]> {
|
|
@@ -390,7 +390,7 @@ export function decodePromise<S extends Schema.Decoder<unknown>>(
|
|
|
390
390
|
* @category decoding
|
|
391
391
|
* @since 4.0.0
|
|
392
392
|
*/
|
|
393
|
-
export function decodeUnknownExit<S extends Schema.
|
|
393
|
+
export function decodeUnknownExit<S extends Schema.ConstraintDecoder<unknown>>(
|
|
394
394
|
schema: S,
|
|
395
395
|
options?: SchemaAST.ParseOptions
|
|
396
396
|
): (input: unknown, options?: SchemaAST.ParseOptions) => Exit.Exit<S["Type"], SchemaIssue.Issue> {
|
|
@@ -423,14 +423,14 @@ export function decodeUnknownExit<S extends Schema.Decoder<unknown>>(
|
|
|
423
423
|
* @category decoding
|
|
424
424
|
* @since 4.0.0
|
|
425
425
|
*/
|
|
426
|
-
export const decodeExit: <S extends Schema.
|
|
426
|
+
export const decodeExit: <S extends Schema.ConstraintDecoder<unknown>>(
|
|
427
427
|
schema: S,
|
|
428
428
|
options?: SchemaAST.ParseOptions
|
|
429
429
|
) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Exit.Exit<S["Type"], SchemaIssue.Issue> =
|
|
430
430
|
decodeUnknownExit
|
|
431
431
|
|
|
432
432
|
/** @internal */
|
|
433
|
-
export function decodeUnknownOption<S extends Schema.
|
|
433
|
+
export function decodeUnknownOption<S extends Schema.ConstraintDecoder<unknown>>(
|
|
434
434
|
schema: S,
|
|
435
435
|
options?: SchemaAST.ParseOptions
|
|
436
436
|
): (input: unknown, options?: SchemaAST.ParseOptions) => Option.Option<S["Type"]> {
|
|
@@ -438,7 +438,7 @@ export function decodeUnknownOption<S extends Schema.Decoder<unknown>>(
|
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
/** @internal */
|
|
441
|
-
export const decodeOption: <S extends Schema.
|
|
441
|
+
export const decodeOption: <S extends Schema.ConstraintDecoder<unknown>>(
|
|
442
442
|
schema: S,
|
|
443
443
|
options?: SchemaAST.ParseOptions
|
|
444
444
|
) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Option.Option<S["Type"]> = decodeUnknownOption
|
|
@@ -469,7 +469,7 @@ export const decodeOption: <S extends Schema.Decoder<unknown>>(
|
|
|
469
469
|
* @category decoding
|
|
470
470
|
* @since 4.0.0
|
|
471
471
|
*/
|
|
472
|
-
export function decodeUnknownResult<S extends Schema.
|
|
472
|
+
export function decodeUnknownResult<S extends Schema.ConstraintDecoder<unknown>>(
|
|
473
473
|
schema: S,
|
|
474
474
|
options?: SchemaAST.ParseOptions
|
|
475
475
|
): (input: unknown, options?: SchemaAST.ParseOptions) => Result.Result<S["Type"], SchemaIssue.Issue> {
|
|
@@ -502,7 +502,7 @@ export function decodeUnknownResult<S extends Schema.Decoder<unknown>>(
|
|
|
502
502
|
* @category decoding
|
|
503
503
|
* @since 4.0.0
|
|
504
504
|
*/
|
|
505
|
-
export const decodeResult: <S extends Schema.
|
|
505
|
+
export const decodeResult: <S extends Schema.ConstraintDecoder<unknown>>(
|
|
506
506
|
schema: S,
|
|
507
507
|
options?: SchemaAST.ParseOptions
|
|
508
508
|
) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Result.Result<S["Type"], SchemaIssue.Issue> =
|
|
@@ -534,7 +534,7 @@ export const decodeResult: <S extends Schema.Decoder<unknown>>(
|
|
|
534
534
|
* @category decoding
|
|
535
535
|
* @since 3.10.0
|
|
536
536
|
*/
|
|
537
|
-
export function decodeUnknownSync<S extends Schema.
|
|
537
|
+
export function decodeUnknownSync<S extends Schema.ConstraintDecoder<unknown>>(
|
|
538
538
|
schema: S,
|
|
539
539
|
options?: SchemaAST.ParseOptions
|
|
540
540
|
): (input: unknown, options?: SchemaAST.ParseOptions) => S["Type"] {
|
|
@@ -568,7 +568,7 @@ export function decodeUnknownSync<S extends Schema.Decoder<unknown>>(
|
|
|
568
568
|
* @category decoding
|
|
569
569
|
* @since 3.10.0
|
|
570
570
|
*/
|
|
571
|
-
export const decodeSync: <S extends Schema.
|
|
571
|
+
export const decodeSync: <S extends Schema.ConstraintDecoder<unknown>>(
|
|
572
572
|
schema: S,
|
|
573
573
|
options?: SchemaAST.ParseOptions
|
|
574
574
|
) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => S["Type"] = decodeUnknownSync
|
|
@@ -594,7 +594,7 @@ export const decodeSync: <S extends Schema.Decoder<unknown>>(
|
|
|
594
594
|
* @category encoding
|
|
595
595
|
* @since 4.0.0
|
|
596
596
|
*/
|
|
597
|
-
export function encodeUnknownEffect<S extends Schema.
|
|
597
|
+
export function encodeUnknownEffect<S extends Schema.Constraint>(
|
|
598
598
|
schema: S,
|
|
599
599
|
options?: SchemaAST.ParseOptions
|
|
600
600
|
): (
|
|
@@ -628,7 +628,7 @@ export function encodeUnknownEffect<S extends Schema.Top>(
|
|
|
628
628
|
* @category encoding
|
|
629
629
|
* @since 4.0.0
|
|
630
630
|
*/
|
|
631
|
-
export const encodeEffect: <S extends Schema.
|
|
631
|
+
export const encodeEffect: <S extends Schema.Constraint>(
|
|
632
632
|
schema: S,
|
|
633
633
|
options?: SchemaAST.ParseOptions
|
|
634
634
|
) => (
|
|
@@ -660,7 +660,7 @@ export const encodeEffect: <S extends Schema.Top>(
|
|
|
660
660
|
* @category encoding
|
|
661
661
|
* @since 3.10.0
|
|
662
662
|
*/
|
|
663
|
-
export const encodeUnknownPromise = <S extends Schema.
|
|
663
|
+
export const encodeUnknownPromise = <S extends Schema.ConstraintEncoder<unknown>>(
|
|
664
664
|
schema: S,
|
|
665
665
|
options?: SchemaAST.ParseOptions
|
|
666
666
|
): (input: unknown, options?: SchemaAST.ParseOptions) => Promise<S["Encoded"]> =>
|
|
@@ -691,7 +691,7 @@ export const encodeUnknownPromise = <S extends Schema.Encoder<unknown>>(
|
|
|
691
691
|
* @category encoding
|
|
692
692
|
* @since 3.10.0
|
|
693
693
|
*/
|
|
694
|
-
export const encodePromise: <S extends Schema.
|
|
694
|
+
export const encodePromise: <S extends Schema.ConstraintEncoder<unknown>>(
|
|
695
695
|
schema: S,
|
|
696
696
|
options?: SchemaAST.ParseOptions
|
|
697
697
|
) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Promise<S["Encoded"]> = encodeUnknownPromise
|
|
@@ -722,7 +722,7 @@ export const encodePromise: <S extends Schema.Encoder<unknown>>(
|
|
|
722
722
|
* @category encoding
|
|
723
723
|
* @since 4.0.0
|
|
724
724
|
*/
|
|
725
|
-
export function encodeUnknownExit<S extends Schema.
|
|
725
|
+
export function encodeUnknownExit<S extends Schema.ConstraintEncoder<unknown>>(
|
|
726
726
|
schema: S,
|
|
727
727
|
options?: SchemaAST.ParseOptions
|
|
728
728
|
): (input: unknown, options?: SchemaAST.ParseOptions) => Exit.Exit<S["Encoded"], SchemaIssue.Issue> {
|
|
@@ -755,14 +755,14 @@ export function encodeUnknownExit<S extends Schema.Encoder<unknown>>(
|
|
|
755
755
|
* @category encoding
|
|
756
756
|
* @since 4.0.0
|
|
757
757
|
*/
|
|
758
|
-
export const encodeExit: <S extends Schema.
|
|
758
|
+
export const encodeExit: <S extends Schema.ConstraintEncoder<unknown>>(
|
|
759
759
|
schema: S,
|
|
760
760
|
options?: SchemaAST.ParseOptions
|
|
761
761
|
) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Exit.Exit<S["Encoded"], SchemaIssue.Issue> =
|
|
762
762
|
encodeUnknownExit
|
|
763
763
|
|
|
764
764
|
/** @internal */
|
|
765
|
-
export function encodeUnknownOption<S extends Schema.
|
|
765
|
+
export function encodeUnknownOption<S extends Schema.ConstraintEncoder<unknown>>(
|
|
766
766
|
schema: S,
|
|
767
767
|
options?: SchemaAST.ParseOptions
|
|
768
768
|
): (input: unknown, options?: SchemaAST.ParseOptions) => Option.Option<S["Encoded"]> {
|
|
@@ -770,7 +770,7 @@ export function encodeUnknownOption<S extends Schema.Encoder<unknown>>(
|
|
|
770
770
|
}
|
|
771
771
|
|
|
772
772
|
/** @internal */
|
|
773
|
-
export const encodeOption: <S extends Schema.
|
|
773
|
+
export const encodeOption: <S extends Schema.ConstraintEncoder<unknown>>(
|
|
774
774
|
schema: S,
|
|
775
775
|
options?: SchemaAST.ParseOptions
|
|
776
776
|
) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Option.Option<S["Encoded"]> = encodeUnknownOption
|
|
@@ -803,7 +803,7 @@ export const encodeOption: <S extends Schema.Encoder<unknown>>(
|
|
|
803
803
|
* @category encoding
|
|
804
804
|
* @since 4.0.0
|
|
805
805
|
*/
|
|
806
|
-
export function encodeUnknownResult<S extends Schema.
|
|
806
|
+
export function encodeUnknownResult<S extends Schema.ConstraintEncoder<unknown>>(
|
|
807
807
|
schema: S,
|
|
808
808
|
options?: SchemaAST.ParseOptions
|
|
809
809
|
): (input: unknown, options?: SchemaAST.ParseOptions) => Result.Result<S["Encoded"], SchemaIssue.Issue> {
|
|
@@ -836,7 +836,7 @@ export function encodeUnknownResult<S extends Schema.Encoder<unknown>>(
|
|
|
836
836
|
* @category encoding
|
|
837
837
|
* @since 4.0.0
|
|
838
838
|
*/
|
|
839
|
-
export const encodeResult: <S extends Schema.
|
|
839
|
+
export const encodeResult: <S extends Schema.ConstraintEncoder<unknown>>(
|
|
840
840
|
schema: S,
|
|
841
841
|
options?: SchemaAST.ParseOptions
|
|
842
842
|
) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Result.Result<S["Encoded"], SchemaIssue.Issue> =
|
|
@@ -867,7 +867,7 @@ export const encodeResult: <S extends Schema.Encoder<unknown>>(
|
|
|
867
867
|
* @category encoding
|
|
868
868
|
* @since 3.10.0
|
|
869
869
|
*/
|
|
870
|
-
export function encodeUnknownSync<S extends Schema.
|
|
870
|
+
export function encodeUnknownSync<S extends Schema.ConstraintEncoder<unknown>>(
|
|
871
871
|
schema: S,
|
|
872
872
|
options?: SchemaAST.ParseOptions
|
|
873
873
|
): (input: unknown, options?: SchemaAST.ParseOptions) => S["Encoded"] {
|
|
@@ -901,7 +901,7 @@ export function encodeUnknownSync<S extends Schema.Encoder<unknown>>(
|
|
|
901
901
|
* @category encoding
|
|
902
902
|
* @since 3.10.0
|
|
903
903
|
*/
|
|
904
|
-
export const encodeSync: <S extends Schema.
|
|
904
|
+
export const encodeSync: <S extends Schema.ConstraintEncoder<unknown>>(
|
|
905
905
|
schema: S,
|
|
906
906
|
options?: SchemaAST.ParseOptions
|
|
907
907
|
) => (input: S["Type"], options?: SchemaAST.ParseOptions) => S["Encoded"] = encodeUnknownSync
|
|
@@ -1007,11 +1007,14 @@ export interface Parser {
|
|
|
1007
1007
|
const recur = memoize(
|
|
1008
1008
|
(ast: SchemaAST.AST): Parser => {
|
|
1009
1009
|
let parser: Parser
|
|
1010
|
-
const
|
|
1011
|
-
const
|
|
1012
|
-
const
|
|
1010
|
+
const checks = ast.checks
|
|
1011
|
+
const encoding = ast.encoding
|
|
1012
|
+
const links = encoding
|
|
1013
|
+
const len = links?.length ?? 0
|
|
1014
|
+
const encodingChecks = (ast as any).encodingChecks
|
|
1015
|
+
const astOptions = (checks ? checks[checks.length - 1].annotations : ast.annotations)
|
|
1013
1016
|
?.["parseOptions"]
|
|
1014
|
-
if (!ast.context && !
|
|
1017
|
+
if (!ast.context && !encoding && !checks && !encodingChecks) {
|
|
1015
1018
|
return (ou, options) => {
|
|
1016
1019
|
parser ??= ast.getParser(recur)
|
|
1017
1020
|
if (astOptions) {
|
|
@@ -1022,15 +1025,15 @@ const recur = memoize(
|
|
|
1022
1025
|
}
|
|
1023
1026
|
const isStructural = SchemaAST.isArrays(ast) || SchemaAST.isObjects(ast) ||
|
|
1024
1027
|
(SchemaAST.isDeclaration(ast) && ast.typeParameters.length > 0)
|
|
1028
|
+
const structuralChecks = checks && isStructural ?
|
|
1029
|
+
checks.filter((check) => check.annotations?.[SchemaAST.STRUCTURAL_ANNOTATION_KEY]) :
|
|
1030
|
+
undefined
|
|
1025
1031
|
return (ou, options) => {
|
|
1026
1032
|
if (astOptions) {
|
|
1027
1033
|
options = { ...options, ...astOptions }
|
|
1028
1034
|
}
|
|
1029
|
-
const encoding = ast.encoding
|
|
1030
1035
|
let srou: Effect.Effect<Option.Option<unknown>, SchemaIssue.Issue, unknown> | undefined
|
|
1031
|
-
if (
|
|
1032
|
-
const links = encoding
|
|
1033
|
-
const len = links.length
|
|
1036
|
+
if (links) {
|
|
1034
1037
|
for (let i = len - 1; i >= 0; i--) {
|
|
1035
1038
|
const link = links[i]
|
|
1036
1039
|
const to = link.to
|
|
@@ -1047,58 +1050,63 @@ const recur = memoize(
|
|
|
1047
1050
|
}
|
|
1048
1051
|
|
|
1049
1052
|
parser ??= ast.getParser(recur)
|
|
1050
|
-
|
|
1053
|
+
const parseLocal = (localOu: Option.Option<unknown>) => {
|
|
1054
|
+
let sroa = parser(localOu, options)
|
|
1051
1055
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
+
if (encodingChecks && !options?.disableChecks) {
|
|
1057
|
+
sroa = Effect.flatMapEager(sroa, (oa) => {
|
|
1058
|
+
if (Option.isSome(localOu) && Option.isSome(oa)) {
|
|
1059
|
+
const issues: Array<SchemaIssue.Issue> = []
|
|
1056
1060
|
|
|
1057
|
-
|
|
1061
|
+
SchemaAST.collectIssues(encodingChecks, localOu.value, issues, ast, options)
|
|
1058
1062
|
|
|
1059
|
-
|
|
1060
|
-
|
|
1063
|
+
if (Arr.isArrayNonEmpty(issues)) {
|
|
1064
|
+
return Effect.fail(new SchemaIssue.Composite(ast, localOu, issues))
|
|
1065
|
+
}
|
|
1061
1066
|
}
|
|
1062
|
-
|
|
1063
|
-
return Effect.succeed(oa)
|
|
1064
|
-
})
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
if (ast.checks && !options?.disableChecks) {
|
|
1068
|
-
const checks = ast.checks
|
|
1069
|
-
if (options?.errors === "all" && isStructural && Option.isSome(ou)) {
|
|
1070
|
-
sroa = mapSchemaIssueEffect(sroa, (issue) => {
|
|
1071
|
-
const issues: Array<SchemaIssue.Issue> = []
|
|
1072
|
-
SchemaAST.collectIssues(
|
|
1073
|
-
checks.filter((check) => check.annotations?.[SchemaAST.STRUCTURAL_ANNOTATION_KEY]),
|
|
1074
|
-
ou.value,
|
|
1075
|
-
issues,
|
|
1076
|
-
ast,
|
|
1077
|
-
options
|
|
1078
|
-
)
|
|
1079
|
-
const out: SchemaIssue.Issue = Arr.isArrayNonEmpty(issues)
|
|
1080
|
-
? issue._tag === "Composite" && issue.ast === ast
|
|
1081
|
-
? new SchemaIssue.Composite(ast, issue.actual, [...issue.issues, ...issues])
|
|
1082
|
-
: new SchemaIssue.Composite(ast, ou, [issue, ...issues])
|
|
1083
|
-
: issue
|
|
1084
|
-
return out
|
|
1067
|
+
return Effect.succeed(oa)
|
|
1085
1068
|
})
|
|
1086
1069
|
}
|
|
1087
|
-
sroa = Effect.flatMapEager(sroa, (oa) => {
|
|
1088
|
-
if (Option.isSome(oa)) {
|
|
1089
|
-
const value = oa.value
|
|
1090
|
-
const issues: Array<SchemaIssue.Issue> = []
|
|
1091
1070
|
|
|
1092
|
-
|
|
1071
|
+
if (checks && !options?.disableChecks) {
|
|
1072
|
+
if (options?.errors === "all" && structuralChecks && structuralChecks.length > 0 && Option.isSome(localOu)) {
|
|
1073
|
+
sroa = mapSchemaIssueEffect(sroa, (issue) => {
|
|
1074
|
+
const issues: Array<SchemaIssue.Issue> = []
|
|
1075
|
+
SchemaAST.collectIssues(
|
|
1076
|
+
structuralChecks,
|
|
1077
|
+
localOu.value,
|
|
1078
|
+
issues,
|
|
1079
|
+
ast,
|
|
1080
|
+
options
|
|
1081
|
+
)
|
|
1082
|
+
const out: SchemaIssue.Issue = Arr.isArrayNonEmpty(issues)
|
|
1083
|
+
? issue._tag === "Composite" && issue.ast === ast
|
|
1084
|
+
? new SchemaIssue.Composite(ast, issue.actual, [...issue.issues, ...issues])
|
|
1085
|
+
: new SchemaIssue.Composite(ast, localOu, [issue, ...issues])
|
|
1086
|
+
: issue
|
|
1087
|
+
return out
|
|
1088
|
+
})
|
|
1089
|
+
}
|
|
1090
|
+
sroa = Effect.flatMapEager(sroa, (oa) => {
|
|
1091
|
+
if (Option.isSome(oa)) {
|
|
1092
|
+
const value = oa.value
|
|
1093
|
+
const issues: Array<SchemaIssue.Issue> = []
|
|
1094
|
+
|
|
1095
|
+
SchemaAST.collectIssues(checks, value, issues, ast, options)
|
|
1093
1096
|
|
|
1094
|
-
|
|
1095
|
-
|
|
1097
|
+
if (Arr.isArrayNonEmpty(issues)) {
|
|
1098
|
+
return Effect.fail(new SchemaIssue.Composite(ast, oa, issues))
|
|
1099
|
+
}
|
|
1096
1100
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
}
|
|
1101
|
+
return Effect.succeed(oa)
|
|
1102
|
+
})
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
return sroa
|
|
1100
1106
|
}
|
|
1101
1107
|
|
|
1108
|
+
const sroa = srou ? Effect.flatMapEager(srou, parseLocal) : parseLocal(ou)
|
|
1109
|
+
|
|
1102
1110
|
return sroa
|
|
1103
1111
|
}
|
|
1104
1112
|
}
|
|
@@ -1312,8 +1312,8 @@ export function optionFromOptional<T>(): Transformation<Option.Option<T>, T | un
|
|
|
1312
1312
|
*
|
|
1313
1313
|
* **Details**
|
|
1314
1314
|
*
|
|
1315
|
-
* Decoding
|
|
1316
|
-
* not a valid URL. Encoding returns `url.href`.
|
|
1315
|
+
* Decoding checks `URL.canParse(s)` and fails with `InvalidValue` if the string
|
|
1316
|
+
* is not a valid URL. Encoding returns `url.href`.
|
|
1317
1317
|
*
|
|
1318
1318
|
* **Example** (Converting a string to a URL)
|
|
1319
1319
|
*
|
|
@@ -1333,10 +1333,9 @@ export function optionFromOptional<T>(): Transformation<Option.Option<T>, T | un
|
|
|
1333
1333
|
*/
|
|
1334
1334
|
export const urlFromString: Transformation<URL, string> = transformOrFail<URL, string>({
|
|
1335
1335
|
decode: (s) =>
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
}),
|
|
1336
|
+
URL.canParse(s)
|
|
1337
|
+
? Effect.succeed(new URL(s))
|
|
1338
|
+
: Effect.fail(new SchemaIssue.InvalidValue(Option.some(s), { message: `Invalid URL string: ${s}` })),
|
|
1340
1339
|
encode: (url) => Effect.succeed(url.href)
|
|
1341
1340
|
})
|
|
1342
1341
|
|
package/src/internal/effect.ts
CHANGED
|
@@ -3154,23 +3154,6 @@ export const unwrapReason: {
|
|
|
3154
3154
|
) as any
|
|
3155
3155
|
)
|
|
3156
3156
|
|
|
3157
|
-
/** @internal */
|
|
3158
|
-
export const mapErrorCause: {
|
|
3159
|
-
<E, E2>(
|
|
3160
|
-
f: (e: Cause.Cause<E>) => Cause.Cause<E2>
|
|
3161
|
-
): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E2, R>
|
|
3162
|
-
<A, E, R, E2>(
|
|
3163
|
-
self: Effect.Effect<A, E, R>,
|
|
3164
|
-
f: (e: Cause.Cause<E>) => Cause.Cause<E2>
|
|
3165
|
-
): Effect.Effect<A, E2, R>
|
|
3166
|
-
} = dual(
|
|
3167
|
-
2,
|
|
3168
|
-
<A, E, R, E2>(
|
|
3169
|
-
self: Effect.Effect<A, E, R>,
|
|
3170
|
-
f: (e: Cause.Cause<E>) => Cause.Cause<E2>
|
|
3171
|
-
): Effect.Effect<A, E2, R> => catchCause(self, (cause) => failCauseSync(() => f(cause)))
|
|
3172
|
-
)
|
|
3173
|
-
|
|
3174
3157
|
/** @internal */
|
|
3175
3158
|
export const mapError: {
|
|
3176
3159
|
<E, E2>(
|
|
@@ -5827,11 +5810,12 @@ const performanceNowNanos = (function() {
|
|
|
5827
5810
|
const bigint1e6 = BigInt(1_000_000)
|
|
5828
5811
|
if (typeof performance === "undefined" || typeof performance.now === "undefined") {
|
|
5829
5812
|
return () => BigInt(Date.now()) * bigint1e6
|
|
5830
|
-
} else if (typeof performance.timeOrigin === "number" && performance.timeOrigin === 0) {
|
|
5831
|
-
return () => BigInt(Math.round(performance.now() * 1_000_000))
|
|
5832
5813
|
}
|
|
5833
|
-
|
|
5834
|
-
return () =>
|
|
5814
|
+
let origin: bigint
|
|
5815
|
+
return () => {
|
|
5816
|
+
origin ??= (BigInt(Date.now()) * bigint1e6) - BigInt(Math.round(performance.now() * 1_000_000))
|
|
5817
|
+
return origin + BigInt(Math.round(performance.now() * 1_000_000))
|
|
5818
|
+
}
|
|
5835
5819
|
})()
|
|
5836
5820
|
const processOrPerformanceNow = (function() {
|
|
5837
5821
|
const processHrtime =
|
|
@@ -5841,7 +5825,7 @@ const processOrPerformanceNow = (function() {
|
|
|
5841
5825
|
if (!processHrtime) {
|
|
5842
5826
|
return performanceNowNanos
|
|
5843
5827
|
}
|
|
5844
|
-
const origin =
|
|
5828
|
+
const origin = (BigInt(Date.now()) * BigInt(1e6)) - processHrtime.bigint()
|
|
5845
5829
|
return () => origin + processHrtime.bigint()
|
|
5846
5830
|
})()
|
|
5847
5831
|
|
package/src/internal/matcher.ts
CHANGED
|
@@ -520,11 +520,6 @@ export const instanceOf = <A extends abstract new(...args: any) => any>(
|
|
|
520
520
|
constructor: A
|
|
521
521
|
): SafeRefinement<InstanceType<A>, never> => ((u: unknown) => u instanceof constructor) as any
|
|
522
522
|
|
|
523
|
-
/** @internal */
|
|
524
|
-
export const instanceOfUnsafe: <A extends abstract new(...args: any) => any>(
|
|
525
|
-
constructor: A
|
|
526
|
-
) => SafeRefinement<InstanceType<A>, InstanceType<A>> = instanceOf
|
|
527
|
-
|
|
528
523
|
/** @internal */
|
|
529
524
|
export const orElse =
|
|
530
525
|
<RA, Ret, F extends (_: RA) => Ret>(f: F) =>
|
|
@@ -22,7 +22,7 @@ const emptyRecursionStack: RecursionStack = []
|
|
|
22
22
|
type RecursionStack = ReadonlyArray<SchemaAST.Suspend>
|
|
23
23
|
|
|
24
24
|
type Context = Schema.Annotations.ToArbitrary.Context
|
|
25
|
-
type Constraint = Schema.Annotations.ToArbitrary.
|
|
25
|
+
type Constraint = Schema.Annotations.ToArbitrary.GenerationConstraint
|
|
26
26
|
type OrderedConstraint = Schema.Annotations.ToArbitrary.OrderedConstraint<any>
|
|
27
27
|
type ArbitraryFilter = Schema.Annotations.ToArbitrary.Filter
|
|
28
28
|
|
|
@@ -127,6 +127,7 @@ export function fromASTs(asts: readonly [SchemaAST.AST, ...Array<SchemaAST.AST>]
|
|
|
127
127
|
case "Any":
|
|
128
128
|
case "Boolean":
|
|
129
129
|
case "Symbol":
|
|
130
|
+
case "ObjectKeyword":
|
|
130
131
|
return { _tag: last._tag, ...annotations }
|
|
131
132
|
case "String": {
|
|
132
133
|
const contentMediaType = last.annotations?.contentMediaType
|
|
@@ -159,11 +160,6 @@ export function fromASTs(asts: readonly [SchemaAST.AST, ...Array<SchemaAST.AST>]
|
|
|
159
160
|
symbol: last.symbol,
|
|
160
161
|
...annotations
|
|
161
162
|
}
|
|
162
|
-
case "ObjectKeyword":
|
|
163
|
-
return {
|
|
164
|
-
_tag: last._tag,
|
|
165
|
-
...annotations
|
|
166
|
-
}
|
|
167
163
|
case "Enum":
|
|
168
164
|
return {
|
|
169
165
|
_tag: last._tag,
|
|
@@ -28,7 +28,7 @@ const SchemaProto = {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/** @internal */
|
|
31
|
-
export function make<S extends Schema.
|
|
31
|
+
export function make<S extends Schema.Constraint>(ast: S["ast"], options?: object): S {
|
|
32
32
|
const self = Object.create(SchemaProto)
|
|
33
33
|
if (options) {
|
|
34
34
|
Object.assign(self, options)
|