effect 4.0.0-beta.104 → 4.0.0-beta.106
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/AGENTS.md +381 -0
- package/CLAUDE.md +381 -0
- package/ai-docs/README.md +44 -0
- package/ai-docs/package.json +36 -0
- package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
- package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +39 -0
- package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
- package/ai-docs/src/01_effect/01_basics/index.md +5 -0
- package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
- package/ai-docs/src/01_effect/02_schema/index.md +7 -0
- package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
- package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
- package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
- package/ai-docs/src/01_effect/03_services/index.md +5 -0
- package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
- package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
- package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
- package/ai-docs/src/01_effect/04_errors/index.md +1 -0
- package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
- package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
- package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
- package/ai-docs/src/01_effect/05_resources/index.md +3 -0
- package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
- package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
- package/ai-docs/src/01_effect/06_running/index.md +1 -0
- package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
- package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
- package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
- package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
- package/ai-docs/src/03_stream/30_encoding.ts +165 -0
- package/ai-docs/src/03_stream/index.md +4 -0
- package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
- package/ai-docs/src/04_integration/index.md +5 -0
- package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
- package/ai-docs/src/05_batching/index.md +3 -0
- package/ai-docs/src/06_schedule/10_schedules.ts +110 -0
- package/ai-docs/src/06_schedule/index.md +3 -0
- package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
- package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
- package/ai-docs/src/07_datetime/index.md +5 -0
- package/ai-docs/src/08_observability/10_logging.ts +66 -0
- package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
- package/ai-docs/src/08_observability/index.md +7 -0
- package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
- package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
- package/ai-docs/src/09_testing/index.md +1 -0
- package/ai-docs/src/10_predicate/01_basics.ts +14 -0
- package/ai-docs/src/10_predicate/index.md +9 -0
- package/ai-docs/src/50_http-client/10_basics.ts +102 -0
- package/ai-docs/src/50_http-client/index.md +3 -0
- package/ai-docs/src/51_http-server/10_basics.ts +116 -0
- package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
- package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
- package/ai-docs/src/51_http-server/fixtures/api/Users.ts +91 -0
- package/ai-docs/src/51_http-server/fixtures/domain/User.ts +12 -0
- package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
- package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +71 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users.ts +62 -0
- package/ai-docs/src/51_http-server/index.md +3 -0
- package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
- package/ai-docs/src/60_child-process/index.md +3 -0
- package/ai-docs/src/70_cli/10_basics.ts +136 -0
- package/ai-docs/src/70_cli/index.md +5 -0
- package/ai-docs/src/71_ai/10_language-model.ts +156 -0
- package/ai-docs/src/71_ai/20_tools.ts +226 -0
- package/ai-docs/src/71_ai/30_chat.ts +158 -0
- package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
- package/ai-docs/src/71_ai/index.md +5 -0
- package/ai-docs/src/80_cluster/10_entities.ts +97 -0
- package/ai-docs/src/80_cluster/index.md +4 -0
- package/ai-docs/src/index.md +10 -0
- package/ai-docs/tsconfig.json +24 -0
- package/dist/Brand.d.ts +3 -3
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +4 -3
- package/dist/Brand.js.map +1 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +5 -4
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +35 -3
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +41 -8
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Context.d.ts +0 -1
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +1 -22
- package/dist/Context.js.map +1 -1
- package/dist/Cron.d.ts +31 -0
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +58 -2
- package/dist/Cron.js.map +1 -1
- package/dist/Fiber.d.ts +1 -1
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Function.d.ts +26 -0
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +36 -0
- package/dist/Function.js.map +1 -1
- package/dist/JsonSchema.d.ts.map +1 -1
- package/dist/JsonSchema.js +34 -17
- package/dist/JsonSchema.js.map +1 -1
- package/dist/Optic.d.ts +35 -21
- package/dist/Optic.d.ts.map +1 -1
- package/dist/Optic.js +33 -34
- package/dist/Optic.js.map +1 -1
- package/dist/Schema.d.ts +105 -109
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +141 -104
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +32 -17
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +79 -60
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaError.d.ts +8 -8
- package/dist/SchemaError.d.ts.map +1 -1
- package/dist/SchemaError.js +7 -6
- package/dist/SchemaError.js.map +1 -1
- package/dist/SchemaGetter.d.ts +8 -5
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +41 -37
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaIssue.d.ts +195 -38
- package/dist/SchemaIssue.d.ts.map +1 -1
- package/dist/SchemaIssue.js +243 -68
- package/dist/SchemaIssue.js.map +1 -1
- package/dist/SchemaParser.d.ts +30 -0
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +39 -9
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +15 -3
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +8 -2
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +2 -2
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +26 -26
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/ScopedRef.d.ts.map +1 -1
- package/dist/ScopedRef.js +1 -1
- package/dist/ScopedRef.js.map +1 -1
- package/dist/Stdio.d.ts +17 -4
- package/dist/Stdio.d.ts.map +1 -1
- package/dist/Stdio.js +6 -3
- package/dist/Stdio.js.map +1 -1
- package/dist/TxQueue.js +1 -1
- package/dist/TxQueue.js.map +1 -1
- package/dist/internal/effect.js +2 -4
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/executionPlan.js +3 -2
- package/dist/internal/executionPlan.js.map +1 -1
- package/dist/internal/rcRef.js +18 -13
- package/dist/internal/rcRef.js.map +1 -1
- package/dist/internal/schema/fromJsonSchemaDocument.js +10 -6
- package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
- package/dist/internal/schema/schema.js +1 -9
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/internal/schema/toArbitrary.d.ts +1 -4
- package/dist/internal/schema/toArbitrary.d.ts.map +1 -1
- package/dist/internal/schema/toArbitrary.js +0 -74
- package/dist/internal/schema/toArbitrary.js.map +1 -1
- package/dist/internal/schema/toJsonSchemaDocument.js +18 -4
- package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
- package/dist/internal/schema/toRepresentation.js +45 -43
- package/dist/internal/schema/toRepresentation.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +1 -1
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +10 -9
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +110 -110
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +23 -11
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts +4 -3
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Prompt.js +42 -17
- package/dist/unstable/ai/Prompt.js.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts +2 -2
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/EntityProxy.d.ts +3 -3
- package/dist/unstable/cluster/EntityProxy.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityProxy.js +4 -3
- package/dist/unstable/cluster/EntityProxy.js.map +1 -1
- package/dist/unstable/cluster/Reply.js +4 -4
- package/dist/unstable/cluster/Reply.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts +2 -2
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +14 -5
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
- package/dist/unstable/encoding/Msgpack.js +6 -6
- package/dist/unstable/encoding/Msgpack.js.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.d.ts +6 -5
- package/dist/unstable/eventlog/EventLogEncryption.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.js +14 -12
- package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.d.ts +3 -3
- package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.js +2 -3
- package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.js +4 -4
- package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
- package/dist/unstable/eventlog/EventLogServerEncrypted.js +3 -2
- package/dist/unstable/eventlog/EventLogServerEncrypted.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts +59 -3
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +33 -19
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +7 -1
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/MultipartParser/internal/multipart.d.ts.map +1 -1
- package/dist/unstable/http/MultipartParser/internal/multipart.js +18 -6
- package/dist/unstable/http/MultipartParser/internal/multipart.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +10 -10
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +9 -9
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +1 -1
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.js +4 -4
- package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +26 -11
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +9 -22
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +8 -1
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +3 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +20 -16
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/workers/Worker.d.ts.map +1 -1
- package/dist/unstable/workers/Worker.js +11 -12
- package/dist/unstable/workers/Worker.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js +2 -2
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/package.json +5 -2
- package/src/Brand.ts +4 -4
- package/src/Config.ts +6 -4
- package/src/ConfigProvider.ts +43 -8
- package/src/Context.ts +1 -23
- package/src/Cron.ts +65 -2
- package/src/Fiber.ts +1 -1
- package/src/Function.ts +37 -0
- package/src/JsonSchema.ts +43 -42
- package/src/Optic.ts +59 -58
- package/src/Schema.ts +213 -217
- package/src/SchemaAST.ts +135 -78
- package/src/SchemaError.ts +9 -9
- package/src/SchemaGetter.ts +89 -30
- package/src/SchemaIssue.ts +285 -80
- package/src/SchemaParser.ts +51 -17
- package/src/SchemaRepresentation.ts +15 -3
- package/src/SchemaTransformation.ts +66 -18
- package/src/ScopedRef.ts +3 -1
- package/src/Stdio.ts +23 -4
- package/src/TxQueue.ts +1 -1
- package/src/internal/effect.ts +3 -6
- package/src/internal/executionPlan.ts +3 -2
- package/src/internal/rcRef.ts +24 -16
- package/src/internal/schema/fromJsonSchemaDocument.ts +19 -14
- package/src/internal/schema/schema.ts +1 -17
- package/src/internal/schema/toArbitrary.ts +0 -72
- package/src/internal/schema/toJsonSchemaDocument.ts +24 -4
- package/src/internal/schema/toRepresentation.ts +66 -48
- package/src/testing/TestSchema.ts +10 -10
- package/src/unstable/ai/McpServer.ts +23 -11
- package/src/unstable/ai/Prompt.ts +51 -19
- package/src/unstable/cluster/Entity.ts +7 -2
- package/src/unstable/cluster/EntityProxy.ts +12 -5
- package/src/unstable/cluster/Reply.ts +4 -4
- package/src/unstable/cluster/Sharding.ts +29 -17
- package/src/unstable/encoding/Msgpack.ts +12 -8
- package/src/unstable/eventlog/EventLogEncryption.ts +15 -16
- package/src/unstable/eventlog/EventLogMessage.ts +2 -3
- package/src/unstable/eventlog/EventLogRemote.ts +4 -4
- package/src/unstable/eventlog/EventLogServerEncrypted.ts +2 -2
- package/src/unstable/http/HttpClient.ts +132 -23
- package/src/unstable/http/HttpServerRequest.ts +8 -3
- package/src/unstable/http/MultipartParser/internal/multipart.ts +19 -6
- package/src/unstable/httpapi/HttpApiBuilder.ts +32 -13
- package/src/unstable/httpapi/HttpApiClient.ts +26 -8
- package/src/unstable/httpapi/OpenApi.ts +4 -1
- package/src/unstable/reactivity/AsyncResult.ts +11 -6
- package/src/unstable/reactivity/Atom.ts +44 -25
- package/src/unstable/rpc/RpcClient.ts +9 -1
- package/src/unstable/rpc/RpcServer.ts +4 -2
- package/src/unstable/sql/SqlResolver.ts +28 -20
- package/src/unstable/workers/Worker.ts +13 -14
- package/src/unstable/workflow/Workflow.ts +2 -5
package/src/SchemaAST.ts
CHANGED
|
@@ -16,7 +16,7 @@ import * as Cause from "./Cause.ts"
|
|
|
16
16
|
import * as Effect from "./Effect.ts"
|
|
17
17
|
import * as Exit from "./Exit.ts"
|
|
18
18
|
import { format, formatPropertyKey } from "./Formatter.ts"
|
|
19
|
-
import { identity, memoize } from "./Function.ts"
|
|
19
|
+
import { identity, memoize, memoizeIdempotent } from "./Function.ts"
|
|
20
20
|
import { effectIsExit, iterateEager } from "./internal/effect.ts"
|
|
21
21
|
import * as InternalRecord from "./internal/record.ts"
|
|
22
22
|
import * as InternalAnnotations from "./internal/schema/annotations.ts"
|
|
@@ -450,6 +450,8 @@ export type Encoding = readonly [Link, ...Array<Link>]
|
|
|
450
450
|
* transformations.
|
|
451
451
|
* - `concurrency` — maximum number of async parse effects to run concurrently;
|
|
452
452
|
* defaults to `1`, or use `"unbounded"`.
|
|
453
|
+
* - `reportInput` — includes rejected input values in value-bearing schema
|
|
454
|
+
* issues.
|
|
453
455
|
*
|
|
454
456
|
* @category options
|
|
455
457
|
* @since 3.10.0
|
|
@@ -516,6 +518,35 @@ export interface ParseOptions {
|
|
|
516
518
|
* @default 1
|
|
517
519
|
*/
|
|
518
520
|
readonly concurrency?: number | "unbounded" | undefined
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Whether schema issues should retain and report rejected input values.
|
|
524
|
+
*
|
|
525
|
+
* **Details**
|
|
526
|
+
*
|
|
527
|
+
* When enabled, value-bearing issues created by the parser expose an `input`
|
|
528
|
+
* field. Built-in formatters may include reported input in default messages.
|
|
529
|
+
* The input is retained by reference rather than copied.
|
|
530
|
+
*
|
|
531
|
+
* **Gotchas**
|
|
532
|
+
*
|
|
533
|
+
* Enabling this option can retain or disclose secrets, personally
|
|
534
|
+
* identifiable information, and large object graphs. The `input` field is
|
|
535
|
+
* enumerable and may be included by object enumeration, spread, or
|
|
536
|
+
* serialization. Disabling it on a nested schema does not redact that value
|
|
537
|
+
* from an ancestor issue whose input reporting remains enabled. Issues
|
|
538
|
+
* returned directly by user-defined declarations, checks, transformations,
|
|
539
|
+
* and middleware are not modified; their authors decide whether to retain an
|
|
540
|
+
* input. To respect this option, pass the callback's input and parse options
|
|
541
|
+
* directly to a value-bearing issue constructor. Custom messages and
|
|
542
|
+
* annotations remain the caller's responsibility regardless of this option.
|
|
543
|
+
* Formatting an issue with `SchemaIssue.makeFormatterDefault()`, reading
|
|
544
|
+
* `SchemaError.message`, or formatting a Standard Schema failure can disclose
|
|
545
|
+
* retained input.
|
|
546
|
+
*
|
|
547
|
+
* @default false
|
|
548
|
+
*/
|
|
549
|
+
readonly reportInput?: boolean | undefined
|
|
519
550
|
}
|
|
520
551
|
|
|
521
552
|
/** @internal */
|
|
@@ -1151,7 +1182,7 @@ export class TemplateLiteral extends Base {
|
|
|
1151
1182
|
}
|
|
1152
1183
|
return Effect.mapBothEager(result, {
|
|
1153
1184
|
onSuccess: () => input,
|
|
1154
|
-
onFailure: (issue) => new SchemaIssue.Composite(this, [issue])
|
|
1185
|
+
onFailure: (issue) => new SchemaIssue.Composite(this, [issue], input, options)
|
|
1155
1186
|
})
|
|
1156
1187
|
}
|
|
1157
1188
|
}
|
|
@@ -1174,9 +1205,11 @@ export class TemplateLiteral extends Base {
|
|
|
1174
1205
|
const segments = segmentTemplateLiteralParts(this, s, options)
|
|
1175
1206
|
if (segments) return Effect.succeed(segments)
|
|
1176
1207
|
return Effect.fail(
|
|
1177
|
-
new SchemaIssue.InvalidValue(
|
|
1178
|
-
|
|
1179
|
-
|
|
1208
|
+
new SchemaIssue.InvalidValue(
|
|
1209
|
+
{ expected: "a string matching template literal parts" },
|
|
1210
|
+
s,
|
|
1211
|
+
options
|
|
1212
|
+
)
|
|
1180
1213
|
)
|
|
1181
1214
|
}),
|
|
1182
1215
|
SchemaGetter.transform((parts) => parts.join(""))
|
|
@@ -1715,7 +1748,7 @@ export class Arrays extends Base {
|
|
|
1715
1748
|
|
|
1716
1749
|
// If the input is not an array, return early with an error
|
|
1717
1750
|
if (!Array.isArray(input)) {
|
|
1718
|
-
return yield* Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
1751
|
+
return yield* Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
1719
1752
|
}
|
|
1720
1753
|
if (!elements) {
|
|
1721
1754
|
elements = ast.elements.map((ast) => ({ ast, parser: compileConstructorDefault(ast) }))
|
|
@@ -1745,20 +1778,21 @@ export class Arrays extends Base {
|
|
|
1745
1778
|
// ---------------------------------------------
|
|
1746
1779
|
if (ast.rest.length === 0 && len > elementLen) {
|
|
1747
1780
|
for (let i = elementLen; i <= len - 1; i++) {
|
|
1748
|
-
const
|
|
1781
|
+
const unexpected = new SchemaIssue.UnexpectedKey(ast, input[i], options)
|
|
1782
|
+
const issue = new SchemaIssue.Pointer([i], unexpected)
|
|
1749
1783
|
if (options.errors === "all") {
|
|
1750
1784
|
if (state.issues) state.issues.push(issue)
|
|
1751
1785
|
else state.issues = [issue]
|
|
1752
1786
|
} else {
|
|
1753
1787
|
return yield* Effect.fail(
|
|
1754
|
-
new SchemaIssue.Composite(ast, [issue])
|
|
1788
|
+
new SchemaIssue.Composite(ast, [issue], input, options)
|
|
1755
1789
|
)
|
|
1756
1790
|
}
|
|
1757
1791
|
}
|
|
1758
1792
|
}
|
|
1759
1793
|
if (state.issues) {
|
|
1760
1794
|
return yield* Effect.fail(
|
|
1761
|
-
new SchemaIssue.Composite(ast, state.issues)
|
|
1795
|
+
new SchemaIssue.Composite(ast, state.issues, input, options)
|
|
1762
1796
|
)
|
|
1763
1797
|
}
|
|
1764
1798
|
return state.output
|
|
@@ -1829,7 +1863,7 @@ const parseArray = iterateEager<{
|
|
|
1829
1863
|
else s.issues = [issue]
|
|
1830
1864
|
} else {
|
|
1831
1865
|
return Exit.fail(
|
|
1832
|
-
new SchemaIssue.Composite(s.ast, [issue])
|
|
1866
|
+
new SchemaIssue.Composite(s.ast, [issue], s.input, s.options)
|
|
1833
1867
|
)
|
|
1834
1868
|
}
|
|
1835
1869
|
}
|
|
@@ -1862,7 +1896,9 @@ const wrapPropertyKeyIssue = (
|
|
|
1862
1896
|
(issue) =>
|
|
1863
1897
|
new SchemaIssue.Composite(
|
|
1864
1898
|
ast,
|
|
1865
|
-
[new SchemaIssue.Pointer([key], issue)]
|
|
1899
|
+
[new SchemaIssue.Pointer([key], issue)],
|
|
1900
|
+
s.input,
|
|
1901
|
+
s.options
|
|
1866
1902
|
)
|
|
1867
1903
|
)
|
|
1868
1904
|
)
|
|
@@ -1873,7 +1909,7 @@ const wrapPropertyKeyIssue = (
|
|
|
1873
1909
|
else s.issues = [pointer]
|
|
1874
1910
|
} else {
|
|
1875
1911
|
return Exit.fail(
|
|
1876
|
-
new SchemaIssue.Composite(ast, [pointer])
|
|
1912
|
+
new SchemaIssue.Composite(ast, [pointer], s.input, s.options)
|
|
1877
1913
|
)
|
|
1878
1914
|
}
|
|
1879
1915
|
}
|
|
@@ -2177,7 +2213,7 @@ export class Objects extends Base {
|
|
|
2177
2213
|
|
|
2178
2214
|
// If the input is not a record, return early with an error
|
|
2179
2215
|
if (!(typeof input === "object" && input !== null && !Array.isArray(input))) {
|
|
2180
|
-
return yield* Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
2216
|
+
return yield* Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
2181
2217
|
}
|
|
2182
2218
|
if (!properties) {
|
|
2183
2219
|
properties = ast.propertySignatures.map((ps) => ({
|
|
@@ -2219,7 +2255,8 @@ export class Objects extends Base {
|
|
|
2219
2255
|
if (!expectedKeysSet.has(key)) {
|
|
2220
2256
|
// key is unexpected
|
|
2221
2257
|
if (onExcessPropertyError) {
|
|
2222
|
-
const
|
|
2258
|
+
const unexpected = new SchemaIssue.UnexpectedKey(ast, record[key], options)
|
|
2259
|
+
const issue = new SchemaIssue.Pointer([key], unexpected)
|
|
2223
2260
|
if (errorsAllOption) {
|
|
2224
2261
|
if (state.issues) {
|
|
2225
2262
|
state.issues.push(issue)
|
|
@@ -2229,7 +2266,7 @@ export class Objects extends Base {
|
|
|
2229
2266
|
continue
|
|
2230
2267
|
} else {
|
|
2231
2268
|
return yield* Effect.fail(
|
|
2232
|
-
new SchemaIssue.Composite(ast, [issue])
|
|
2269
|
+
new SchemaIssue.Composite(ast, [issue], input, options)
|
|
2233
2270
|
)
|
|
2234
2271
|
}
|
|
2235
2272
|
} else {
|
|
@@ -2281,7 +2318,7 @@ export class Objects extends Base {
|
|
|
2281
2318
|
|
|
2282
2319
|
if (state.issues) {
|
|
2283
2320
|
return yield* Effect.fail(
|
|
2284
|
-
new SchemaIssue.Composite(ast, state.issues)
|
|
2321
|
+
new SchemaIssue.Composite(ast, state.issues, input, options)
|
|
2285
2322
|
)
|
|
2286
2323
|
}
|
|
2287
2324
|
if (options.propertyOrder === "original") {
|
|
@@ -2387,7 +2424,7 @@ const parseProperties = iterateEager<ObjectParserState, ParsedProperty>()({
|
|
|
2387
2424
|
return
|
|
2388
2425
|
} else {
|
|
2389
2426
|
return Exit.fail(
|
|
2390
|
-
new SchemaIssue.Composite(s.ast, [issue])
|
|
2427
|
+
new SchemaIssue.Composite(s.ast, [issue], s.input, s.options)
|
|
2391
2428
|
)
|
|
2392
2429
|
}
|
|
2393
2430
|
}
|
|
@@ -2480,7 +2517,7 @@ export type Sentinel = {
|
|
|
2480
2517
|
readonly literal: LiteralValue | symbol
|
|
2481
2518
|
}
|
|
2482
2519
|
|
|
2483
|
-
const toCandidate =
|
|
2520
|
+
const toCandidate = memoizeIdempotent((ast: AST): AST => {
|
|
2484
2521
|
while (true) {
|
|
2485
2522
|
if (isSuspend(ast)) return unknown
|
|
2486
2523
|
const encoding = ast.encoding
|
|
@@ -2544,7 +2581,7 @@ function getCandidateTypes(ast: AST): ReadonlyArray<Type> {
|
|
|
2544
2581
|
}
|
|
2545
2582
|
|
|
2546
2583
|
/** @internal */
|
|
2547
|
-
export function collectSentinels(ast: AST):
|
|
2584
|
+
export function collectSentinels(ast: AST): ReadonlyArray<Sentinel> {
|
|
2548
2585
|
switch (ast._tag) {
|
|
2549
2586
|
default:
|
|
2550
2587
|
return []
|
|
@@ -2779,8 +2816,8 @@ export class Union<A extends AST = AST> extends Base {
|
|
|
2779
2816
|
const result = compile(candidates[0])(input, options)
|
|
2780
2817
|
if ((result as Exit.Exit<unknown, SchemaIssue.Issue>)._tag === "Success") return result
|
|
2781
2818
|
return effectIsExit(result)
|
|
2782
|
-
? failSingleUnionCandidate(ast, (result as Exit.Failure<unknown, SchemaIssue.Issue>).cause)
|
|
2783
|
-
: Effect.catchCause(result, (cause) => failSingleUnionCandidate(ast, cause))
|
|
2819
|
+
? failSingleUnionCandidate(ast, (result as Exit.Failure<unknown, SchemaIssue.Issue>).cause, input, options)
|
|
2820
|
+
: Effect.catchCause(result, (cause) => failSingleUnionCandidate(ast, cause, input, options))
|
|
2784
2821
|
}
|
|
2785
2822
|
|
|
2786
2823
|
const state = {
|
|
@@ -2795,12 +2832,13 @@ export class Union<A extends AST = AST> extends Base {
|
|
|
2795
2832
|
const concurrency = resolveConcurrency(options?.concurrency)
|
|
2796
2833
|
const eff = parseUnion(state, candidates, concurrency ? { ...concurrency, orderedStep: true } : undefined)
|
|
2797
2834
|
if (!eff) {
|
|
2798
|
-
|
|
2835
|
+
if (state.out) return state.out
|
|
2836
|
+
return Effect.fail(new SchemaIssue.AnyOf(ast, state.issues ?? [], input, options))
|
|
2799
2837
|
}
|
|
2800
2838
|
return Effect.flatMapEager(eff, (_) => {
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2839
|
+
if (state.out === InternalParser.sameExit) return Effect.succeed(input)
|
|
2840
|
+
if (state.out) return state.out
|
|
2841
|
+
return Effect.fail(new SchemaIssue.AnyOf(ast, state.issues ?? [], input, options))
|
|
2804
2842
|
})
|
|
2805
2843
|
}
|
|
2806
2844
|
}
|
|
@@ -2867,12 +2905,13 @@ export class Union<A extends AST = AST> extends Base {
|
|
|
2867
2905
|
|
|
2868
2906
|
function failSingleUnionCandidate(
|
|
2869
2907
|
ast: Union,
|
|
2870
|
-
cause: Cause.Cause<SchemaIssue.Issue
|
|
2908
|
+
cause: Cause.Cause<SchemaIssue.Issue>,
|
|
2909
|
+
input: unknown,
|
|
2910
|
+
options: ParseOptions
|
|
2871
2911
|
) {
|
|
2872
2912
|
const issue = InternalSchemaCause.getSchemaIssue(cause)
|
|
2873
|
-
return
|
|
2874
|
-
|
|
2875
|
-
: Exit.failCause(cause)
|
|
2913
|
+
if (!issue) return Exit.failCause(cause)
|
|
2914
|
+
return Exit.fail(new SchemaIssue.AnyOf(ast, [issue], input, options))
|
|
2876
2915
|
}
|
|
2877
2916
|
|
|
2878
2917
|
const parseUnion = iterateEager<{
|
|
@@ -2899,7 +2938,7 @@ const parseUnion = iterateEager<{
|
|
|
2899
2938
|
} else {
|
|
2900
2939
|
if (s.out && s.successes) {
|
|
2901
2940
|
s.successes.push(candidate)
|
|
2902
|
-
return Exit.fail(new SchemaIssue.OneOf(s.ast, s.successes))
|
|
2941
|
+
return Exit.fail(new SchemaIssue.OneOf(s.ast, s.successes, s.input, s.options))
|
|
2903
2942
|
}
|
|
2904
2943
|
s.out = exit
|
|
2905
2944
|
if (s.successes) {
|
|
@@ -3125,7 +3164,7 @@ export function makeFilter<T>(
|
|
|
3125
3164
|
aborted: boolean = false
|
|
3126
3165
|
): Filter<T> {
|
|
3127
3166
|
return new Filter(
|
|
3128
|
-
(input, ast, options) => SchemaIssue.normalizeFilterOutput(ast, filter(input, ast, options)),
|
|
3167
|
+
(input, ast, options) => SchemaIssue.normalizeFilterOutput(ast, filter(input, ast, options), input, options),
|
|
3129
3168
|
annotations,
|
|
3130
3169
|
aborted
|
|
3131
3170
|
)
|
|
@@ -3137,7 +3176,7 @@ export function makeFilterByGuard<T extends E, E>(
|
|
|
3137
3176
|
annotations?: Schema.Annotations.Filter
|
|
3138
3177
|
): Filter<any> {
|
|
3139
3178
|
return new Filter(
|
|
3140
|
-
(input: E) => is(input) ? undefined : new SchemaIssue.InvalidValue(),
|
|
3179
|
+
(input: E, _ast, options) => is(input) ? undefined : new SchemaIssue.InvalidValue(undefined, input, options),
|
|
3141
3180
|
annotations,
|
|
3142
3181
|
true // after a guard, we always want to abort
|
|
3143
3182
|
)
|
|
@@ -3241,6 +3280,13 @@ function modifyOwnPropertyDescriptors<A extends AST>(
|
|
|
3241
3280
|
return Object.create(Object.getPrototypeOf(ast), d)
|
|
3242
3281
|
}
|
|
3243
3282
|
|
|
3283
|
+
const contextOwners = new WeakMap<AST, AST>()
|
|
3284
|
+
|
|
3285
|
+
/** @internal */
|
|
3286
|
+
export function getContextOwner(ast: AST): AST {
|
|
3287
|
+
return contextOwners.get(ast) ?? ast
|
|
3288
|
+
}
|
|
3289
|
+
|
|
3244
3290
|
/** @internal */
|
|
3245
3291
|
export function replaceEncoding<A extends AST>(ast: A, encoding: Encoding | undefined): A {
|
|
3246
3292
|
if (ast.encoding === encoding) {
|
|
@@ -3256,9 +3302,15 @@ export function replaceContext<A extends AST>(ast: A, context: Context | undefin
|
|
|
3256
3302
|
if (ast.context === context) {
|
|
3257
3303
|
return ast
|
|
3258
3304
|
}
|
|
3259
|
-
|
|
3305
|
+
const owner = getContextOwner(ast)
|
|
3306
|
+
if (owner.context === context) {
|
|
3307
|
+
return owner as A
|
|
3308
|
+
}
|
|
3309
|
+
const out = modifyOwnPropertyDescriptors(ast, (d) => {
|
|
3260
3310
|
d.context.value = context
|
|
3261
3311
|
})
|
|
3312
|
+
contextOwners.set(out, owner)
|
|
3313
|
+
return out
|
|
3262
3314
|
}
|
|
3263
3315
|
|
|
3264
3316
|
/** @internal */
|
|
@@ -3326,6 +3378,21 @@ export function applyToSelfOrLastLinkEncoding(f: (ast: AST) => AST) {
|
|
|
3326
3378
|
return memoize(out)
|
|
3327
3379
|
}
|
|
3328
3380
|
|
|
3381
|
+
/** @internal */
|
|
3382
|
+
export function applyToSelfOrLastLinkEncodingIdempotent(
|
|
3383
|
+
f: (ast: AST) => AST,
|
|
3384
|
+
options?: { readonly stopAt?: (link: Link) => boolean }
|
|
3385
|
+
) {
|
|
3386
|
+
function out(ast: AST): AST {
|
|
3387
|
+
if (ast.encoding) {
|
|
3388
|
+
const last = ast.encoding[ast.encoding.length - 1]
|
|
3389
|
+
return options?.stopAt?.(last) ? ast : replaceEncoding(ast, updateLastLink(ast.encoding, out))
|
|
3390
|
+
}
|
|
3391
|
+
return f(ast)
|
|
3392
|
+
}
|
|
3393
|
+
return memoizeIdempotent(out)
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3329
3396
|
/** @internal */
|
|
3330
3397
|
export function middlewareDecoding(
|
|
3331
3398
|
ast: AST,
|
|
@@ -3393,42 +3460,34 @@ export function annotateKey<A extends AST>(ast: A, annotations: Schema.Annotatio
|
|
|
3393
3460
|
return replaceContext(ast, context)
|
|
3394
3461
|
}
|
|
3395
3462
|
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
/**
|
|
3399
|
-
* Marks an AST node's property key as optional by setting
|
|
3400
|
-
* {@link Context.isOptional} to `true`.
|
|
3401
|
-
*
|
|
3402
|
-
* **Details**
|
|
3403
|
-
*
|
|
3404
|
-
* Also propagates the optional flag through the last link of the encoding
|
|
3405
|
-
* chain if present.
|
|
3406
|
-
*
|
|
3407
|
-
* @see {@link isOptional}
|
|
3408
|
-
* @see {@link Context}
|
|
3409
|
-
* @category transforming
|
|
3410
|
-
* @since 4.0.0
|
|
3411
|
-
*/
|
|
3412
|
-
export function optionalKey<A extends AST>(ast: A): A {
|
|
3463
|
+
/** @internal */
|
|
3464
|
+
export const optionalKey: <A extends AST>(ast: A) => A = memoizeIdempotent(<A extends AST>(ast: A): A => {
|
|
3413
3465
|
const context = ast.context ?
|
|
3414
3466
|
ast.context.isOptional === false ?
|
|
3415
3467
|
new Context(true, ast.context.isMutable, ast.context.constructorDefault, ast.context.annotations) :
|
|
3416
3468
|
ast.context :
|
|
3417
3469
|
new Context(true, false)
|
|
3418
3470
|
return optionalKeyLastLink(replaceContext(ast, context))
|
|
3419
|
-
}
|
|
3471
|
+
})
|
|
3420
3472
|
|
|
3421
|
-
const
|
|
3473
|
+
const optionalKeyLastLink = applyToLastLink(optionalKey)
|
|
3422
3474
|
|
|
3423
3475
|
/** @internal */
|
|
3424
|
-
export
|
|
3476
|
+
export const optional = memoize(<A extends AST>(ast: A): Union<A | Undefined> =>
|
|
3477
|
+
optionalKey(new Union([ast, undefined_], "anyOf"))
|
|
3478
|
+
)
|
|
3479
|
+
|
|
3480
|
+
/** @internal */
|
|
3481
|
+
export const mutableKey = memoizeIdempotent(<A extends AST>(ast: A): A => {
|
|
3425
3482
|
const context = ast.context ?
|
|
3426
3483
|
ast.context.isMutable === false ?
|
|
3427
3484
|
new Context(ast.context.isOptional, true, ast.context.constructorDefault, ast.context.annotations) :
|
|
3428
3485
|
ast.context :
|
|
3429
3486
|
new Context(false, true)
|
|
3430
3487
|
return mutableKeyLastLink(replaceContext(ast, context))
|
|
3431
|
-
}
|
|
3488
|
+
})
|
|
3489
|
+
|
|
3490
|
+
const mutableKeyLastLink = applyToLastLink(mutableKey)
|
|
3432
3491
|
|
|
3433
3492
|
/** @internal */
|
|
3434
3493
|
export function withConstructorDefault<A extends AST>(
|
|
@@ -3577,7 +3636,7 @@ function extractStructuralChecks(checks: Checks): Checks | undefined {
|
|
|
3577
3636
|
* @category transforming
|
|
3578
3637
|
* @since 4.0.0
|
|
3579
3638
|
*/
|
|
3580
|
-
export const toType =
|
|
3639
|
+
export const toType = memoizeIdempotent(<A extends AST>(ast: A): A => {
|
|
3581
3640
|
if (ast.encoding) {
|
|
3582
3641
|
return toType(replaceEncoding(ast, undefined))
|
|
3583
3642
|
}
|
|
@@ -3624,7 +3683,7 @@ export const toType = memoize(<A extends AST>(ast: A): A => {
|
|
|
3624
3683
|
* @category transforming
|
|
3625
3684
|
* @since 4.0.0
|
|
3626
3685
|
*/
|
|
3627
|
-
export const toEncoded =
|
|
3686
|
+
export const toEncoded = memoizeIdempotent((ast: AST): AST => {
|
|
3628
3687
|
return toType(flip(ast))
|
|
3629
3688
|
})
|
|
3630
3689
|
|
|
@@ -3688,13 +3747,10 @@ function fromConst<const T>(
|
|
|
3688
3747
|
value: T
|
|
3689
3748
|
): SchemaParser.Parser {
|
|
3690
3749
|
const succeed = InternalParser.succeed(value)
|
|
3691
|
-
return (input) => {
|
|
3750
|
+
return (input, options) => {
|
|
3692
3751
|
if (input === InternalParser.missing) return InternalParser.missingExit
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
: Effect.fail(
|
|
3696
|
-
new SchemaIssue.InvalidType(ast)
|
|
3697
|
-
)
|
|
3752
|
+
if (input === value) return succeed
|
|
3753
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
3698
3754
|
}
|
|
3699
3755
|
}
|
|
3700
3756
|
|
|
@@ -3702,13 +3758,10 @@ function fromRefinement<T>(
|
|
|
3702
3758
|
ast: AST,
|
|
3703
3759
|
refinement: (input: unknown) => input is T
|
|
3704
3760
|
): SchemaParser.Parser {
|
|
3705
|
-
return (input) => {
|
|
3761
|
+
return (input, options) => {
|
|
3706
3762
|
if (input === InternalParser.missing) return InternalParser.missingExit
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
: Effect.fail(
|
|
3710
|
-
new SchemaIssue.InvalidType(ast)
|
|
3711
|
-
)
|
|
3763
|
+
if (refinement(input)) return InternalParser.sameExit
|
|
3764
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
3712
3765
|
}
|
|
3713
3766
|
}
|
|
3714
3767
|
|
|
@@ -3774,7 +3827,7 @@ export const enumsToLiterals = memoize((ast: Enum): Union<Literal> => {
|
|
|
3774
3827
|
)
|
|
3775
3828
|
})
|
|
3776
3829
|
|
|
3777
|
-
const parameterFromPropertyKey =
|
|
3830
|
+
const parameterFromPropertyKey = applyToSelfOrLastLinkEncodingIdempotent((ast) => {
|
|
3778
3831
|
switch (ast._tag) {
|
|
3779
3832
|
default:
|
|
3780
3833
|
return ast
|
|
@@ -3786,7 +3839,7 @@ const parameterFromPropertyKey = applyToSelfOrLastLinkEncoding((ast) => {
|
|
|
3786
3839
|
})
|
|
3787
3840
|
|
|
3788
3841
|
/** @internal */
|
|
3789
|
-
export const parameterFromString =
|
|
3842
|
+
export const parameterFromString = applyToSelfOrLastLinkEncodingIdempotent((ast) => {
|
|
3790
3843
|
switch (ast._tag) {
|
|
3791
3844
|
default:
|
|
3792
3845
|
return ast
|
|
@@ -3798,7 +3851,7 @@ export const parameterFromString = applyToSelfOrLastLinkEncoding((ast) => {
|
|
|
3798
3851
|
}
|
|
3799
3852
|
})
|
|
3800
3853
|
|
|
3801
|
-
const partFromString =
|
|
3854
|
+
const partFromString = applyToSelfOrLastLinkEncodingIdempotent((ast) => {
|
|
3802
3855
|
switch (ast._tag) {
|
|
3803
3856
|
default:
|
|
3804
3857
|
return ast
|
|
@@ -3896,13 +3949,17 @@ const symbolToString = new Link(
|
|
|
3896
3949
|
symbolString,
|
|
3897
3950
|
new SchemaTransformation.Transformation(
|
|
3898
3951
|
SchemaGetter.transform((description) => globalThis.Symbol.for(isStringSymbolRegExp.exec(description)![1])),
|
|
3899
|
-
SchemaGetter.transformOrFail((sym: symbol) => {
|
|
3952
|
+
SchemaGetter.transformOrFail((sym: symbol, options) => {
|
|
3900
3953
|
const key = globalThis.Symbol.keyFor(sym)
|
|
3901
3954
|
if (key !== undefined) {
|
|
3902
3955
|
return Effect.succeed(globalThis.String(sym))
|
|
3903
3956
|
}
|
|
3904
3957
|
return Effect.fail(
|
|
3905
|
-
new SchemaIssue.Forbidden(
|
|
3958
|
+
new SchemaIssue.Forbidden(
|
|
3959
|
+
{ message: "cannot serialize to string, Symbol is not registered" },
|
|
3960
|
+
sym,
|
|
3961
|
+
options
|
|
3962
|
+
)
|
|
3906
3963
|
)
|
|
3907
3964
|
})
|
|
3908
3965
|
)
|
|
@@ -3945,7 +4002,7 @@ export function collectIssues<T>(
|
|
|
3945
4002
|
} else {
|
|
3946
4003
|
const issue = check.run(value, ast, options)
|
|
3947
4004
|
if (issue) {
|
|
3948
|
-
const filter = new SchemaIssue.Filter(check, issue)
|
|
4005
|
+
const filter = new SchemaIssue.Filter(check, issue, value, options)
|
|
3949
4006
|
if (issues) issues.push(filter)
|
|
3950
4007
|
else issues = [filter]
|
|
3951
4008
|
if (options.errors !== "all" || check.aborted) {
|
|
@@ -4154,10 +4211,10 @@ export function isJson(u: unknown): u is Schema.Json {
|
|
|
4154
4211
|
/** @internal */
|
|
4155
4212
|
export const Json = new Declaration(
|
|
4156
4213
|
[],
|
|
4157
|
-
() => (input, ast) =>
|
|
4214
|
+
() => (input, ast, options) =>
|
|
4158
4215
|
isJson(input) ?
|
|
4159
4216
|
InternalParser.sameExit :
|
|
4160
|
-
Effect.fail(new SchemaIssue.InvalidType(ast)),
|
|
4217
|
+
Effect.fail(new SchemaIssue.InvalidType(ast, input, options)),
|
|
4161
4218
|
{
|
|
4162
4219
|
representation: {
|
|
4163
4220
|
id: "effect/schema/Json",
|
|
@@ -4206,10 +4263,10 @@ export function isStringTree(u: unknown): u is Schema.StringTree {
|
|
|
4206
4263
|
|
|
4207
4264
|
const StringTree = new Declaration(
|
|
4208
4265
|
[],
|
|
4209
|
-
() => (input, ast) =>
|
|
4266
|
+
() => (input, ast, options) =>
|
|
4210
4267
|
isStringTree(input) ?
|
|
4211
4268
|
InternalParser.sameExit :
|
|
4212
|
-
Effect.fail(new SchemaIssue.InvalidType(ast)),
|
|
4269
|
+
Effect.fail(new SchemaIssue.InvalidType(ast, input, options)),
|
|
4213
4270
|
{ expected: "StringTree", toCodecStringTree: () => undefined }
|
|
4214
4271
|
)
|
|
4215
4272
|
|
package/src/SchemaError.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as Data from "./Data.ts"
|
|
5
5
|
import * as Predicate from "./Predicate.ts"
|
|
6
|
-
import
|
|
6
|
+
import * as SchemaIssue from "./SchemaIssue.ts"
|
|
7
7
|
|
|
8
8
|
const TypeId = "~effect/SchemaError/SchemaError"
|
|
9
9
|
|
|
@@ -13,12 +13,12 @@ const TypeId = "~effect/SchemaError/SchemaError"
|
|
|
13
13
|
*
|
|
14
14
|
* **Details**
|
|
15
15
|
*
|
|
16
|
-
* The `issue` field contains a structured {@link Issue} tree describing
|
|
16
|
+
* The `issue` field contains a structured {@link SchemaIssue.Issue} tree describing
|
|
17
17
|
* every validation failure, including the path to the problematic value and
|
|
18
|
-
* the expected type or constraint.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* the expected type or constraint. The `message` field renders the issue tree
|
|
19
|
+
* with the default formatter. When input reporting is enabled, the message may
|
|
20
|
+
* include reported input. Other Issue fields and custom annotations or messages
|
|
21
|
+
* are not sanitized.
|
|
22
22
|
*
|
|
23
23
|
* Use {@link isSchemaError} to narrow an unknown value to `SchemaError`.
|
|
24
24
|
*
|
|
@@ -40,14 +40,14 @@ const TypeId = "~effect/SchemaError/SchemaError"
|
|
|
40
40
|
* @since 4.0.0
|
|
41
41
|
*/
|
|
42
42
|
export class SchemaError extends Data.TaggedError("SchemaError")<{
|
|
43
|
-
readonly issue: Issue
|
|
43
|
+
readonly issue: SchemaIssue.Issue
|
|
44
44
|
}> {
|
|
45
45
|
readonly [TypeId]: typeof TypeId = TypeId
|
|
46
|
-
constructor(issue: Issue) {
|
|
46
|
+
constructor(issue: SchemaIssue.Issue) {
|
|
47
47
|
super({ issue })
|
|
48
48
|
}
|
|
49
49
|
override get message() {
|
|
50
|
-
return this.issue
|
|
50
|
+
return SchemaIssue.defaultFormatter(this.issue)
|
|
51
51
|
}
|
|
52
52
|
override toString() {
|
|
53
53
|
return `SchemaError(${this.message})`
|