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/SchemaGetter.ts
CHANGED
|
@@ -133,7 +133,8 @@ export function succeed<const T, E>(t: T): Getter<T, E> {
|
|
|
133
133
|
* **Details**
|
|
134
134
|
*
|
|
135
135
|
* - Always fails with the `Issue` returned by `f`.
|
|
136
|
-
* - The failure function receives the original `Option<E>` input
|
|
136
|
+
* - The failure function receives the original `Option<E>` input and the
|
|
137
|
+
* effective `ParseOptions` for error context.
|
|
137
138
|
*
|
|
138
139
|
* **Example** (Defining an always-failing getter)
|
|
139
140
|
*
|
|
@@ -153,8 +154,10 @@ export function succeed<const T, E>(t: T): Getter<T, E> {
|
|
|
153
154
|
* @category constructors
|
|
154
155
|
* @since 4.0.0
|
|
155
156
|
*/
|
|
156
|
-
export function fail<T, E>(
|
|
157
|
-
|
|
157
|
+
export function fail<T, E>(
|
|
158
|
+
f: (oe: Option.Option<E>, options: SchemaAST.ParseOptions) => SchemaIssue.Issue
|
|
159
|
+
): Getter<T, E> {
|
|
160
|
+
return new Getter((oe, options) => Effect.fail(f(oe, options)))
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
/**
|
|
@@ -189,7 +192,12 @@ export function fail<T, E>(f: (oe: Option.Option<E>) => SchemaIssue.Issue): Gett
|
|
|
189
192
|
* @since 4.0.0
|
|
190
193
|
*/
|
|
191
194
|
export function forbidden<T, E>(message: (oe: Option.Option<E>) => string): Getter<T, E> {
|
|
192
|
-
return fail<T, E>((oe) =>
|
|
195
|
+
return fail<T, E>((oe, options) => {
|
|
196
|
+
const annotations = { message: message(oe) }
|
|
197
|
+
return Option.isSome(oe)
|
|
198
|
+
? new SchemaIssue.Forbidden(annotations, oe.value, options)
|
|
199
|
+
: new SchemaIssue.Forbidden(annotations)
|
|
200
|
+
})
|
|
193
201
|
}
|
|
194
202
|
|
|
195
203
|
const passthrough_ = new Getter<any, any>(Effect.succeed)
|
|
@@ -465,7 +473,7 @@ export function checkEffect<T, R = never>(
|
|
|
465
473
|
): Getter<T, T, R> {
|
|
466
474
|
return onSome((t, options) => {
|
|
467
475
|
return f(t, options).pipe(Effect.flatMapEager((out) => {
|
|
468
|
-
const issue = SchemaIssue.makeSingle(out)
|
|
476
|
+
const issue = SchemaIssue.makeSingle(out, t, options)
|
|
469
477
|
return issue ?
|
|
470
478
|
Effect.fail(issue) :
|
|
471
479
|
Effect.succeed(Option.some(t))
|
|
@@ -534,10 +542,10 @@ export function transform<T, E>(f: (e: E) => T): Getter<T, E> {
|
|
|
534
542
|
* import { Effect, Option, SchemaGetter, SchemaIssue } from "effect"
|
|
535
543
|
*
|
|
536
544
|
* const safeParseInt = SchemaGetter.transformOrFail<number, string>(
|
|
537
|
-
* (s) => {
|
|
545
|
+
* (s, options) => {
|
|
538
546
|
* const n = parseInt(s, 10)
|
|
539
547
|
* return isNaN(n)
|
|
540
|
-
* ? Effect.fail(new SchemaIssue.InvalidValue({ message: "not an integer" }))
|
|
548
|
+
* ? Effect.fail(new SchemaIssue.InvalidValue({ message: "not an integer" }, s, options))
|
|
541
549
|
* : Effect.succeed(n)
|
|
542
550
|
* }
|
|
543
551
|
* )
|
|
@@ -996,7 +1004,9 @@ type ParseJsonOptions = {
|
|
|
996
1004
|
* - Skips `None` inputs.
|
|
997
1005
|
* - Without `reviver`: returns `Schema.MutableJson` (typed JSON).
|
|
998
1006
|
* - With `reviver`: returns `unknown` (reviver may produce arbitrary values).
|
|
999
|
-
* - On parse failure, fails with `SchemaIssue.InvalidValue`
|
|
1007
|
+
* - On parse failure, fails with `SchemaIssue.InvalidValue` whose `expected`
|
|
1008
|
+
* annotation is `"a valid JSON string"`. Its default message includes the
|
|
1009
|
+
* reported input when `reportInput` is enabled.
|
|
1000
1010
|
*
|
|
1001
1011
|
* **Example** (Parsing JSON)
|
|
1002
1012
|
*
|
|
@@ -1015,10 +1025,15 @@ type ParseJsonOptions = {
|
|
|
1015
1025
|
export function parseJson<E extends string>(): Getter<Schema.MutableJson, E>
|
|
1016
1026
|
export function parseJson<E extends string>(options: ParseJsonOptions): Getter<unknown, E>
|
|
1017
1027
|
export function parseJson<E extends string>(options?: ParseJsonOptions | undefined): Getter<unknown, E> {
|
|
1018
|
-
return onSome((input) =>
|
|
1028
|
+
return onSome((input, parseOptions) =>
|
|
1019
1029
|
Effect.try({
|
|
1020
1030
|
try: () => Option.some(JSON.parse(input, options?.reviver)),
|
|
1021
|
-
catch: () =>
|
|
1031
|
+
catch: () =>
|
|
1032
|
+
new SchemaIssue.InvalidValue(
|
|
1033
|
+
{ expected: "a valid JSON string" },
|
|
1034
|
+
input,
|
|
1035
|
+
parseOptions
|
|
1036
|
+
)
|
|
1022
1037
|
})
|
|
1023
1038
|
)
|
|
1024
1039
|
}
|
|
@@ -1070,7 +1085,7 @@ type StringifyJsonOptions = {
|
|
|
1070
1085
|
* @since 4.0.0
|
|
1071
1086
|
*/
|
|
1072
1087
|
export function stringifyJson(options?: StringifyJsonOptions): Getter<string, unknown> {
|
|
1073
|
-
return onSome((input) =>
|
|
1088
|
+
return onSome((input, parseOptions) =>
|
|
1074
1089
|
Effect.try({
|
|
1075
1090
|
try: () => {
|
|
1076
1091
|
const output = JSON.stringify(input, options?.replacer as any, options?.space)
|
|
@@ -1079,7 +1094,12 @@ export function stringifyJson(options?: StringifyJsonOptions): Getter<string, un
|
|
|
1079
1094
|
}
|
|
1080
1095
|
return Option.some(output)
|
|
1081
1096
|
},
|
|
1082
|
-
catch: () =>
|
|
1097
|
+
catch: () =>
|
|
1098
|
+
new SchemaIssue.InvalidValue(
|
|
1099
|
+
{ expected: "a JSON-serializable value" },
|
|
1100
|
+
input,
|
|
1101
|
+
parseOptions
|
|
1102
|
+
)
|
|
1083
1103
|
})
|
|
1084
1104
|
)
|
|
1085
1105
|
}
|
|
@@ -1307,10 +1327,15 @@ export function encodeHex<E extends Uint8Array | string>(): Getter<string, E> {
|
|
|
1307
1327
|
* @since 4.0.0
|
|
1308
1328
|
*/
|
|
1309
1329
|
export function decodeBase64<E extends string>(): Getter<Uint8Array, E> {
|
|
1310
|
-
return transformOrFail((input) =>
|
|
1330
|
+
return transformOrFail((input, options) =>
|
|
1311
1331
|
Effect.mapErrorEager(
|
|
1312
1332
|
Effect.fromResult(Encoding.decodeBase64(input)),
|
|
1313
|
-
() =>
|
|
1333
|
+
() =>
|
|
1334
|
+
new SchemaIssue.InvalidValue(
|
|
1335
|
+
{ expected: "a valid Base64 string" },
|
|
1336
|
+
input,
|
|
1337
|
+
options
|
|
1338
|
+
)
|
|
1314
1339
|
)
|
|
1315
1340
|
)
|
|
1316
1341
|
}
|
|
@@ -1338,9 +1363,16 @@ export function decodeBase64<E extends string>(): Getter<Uint8Array, E> {
|
|
|
1338
1363
|
* @since 4.0.0
|
|
1339
1364
|
*/
|
|
1340
1365
|
export function decodeBase64String<E extends string>(): Getter<string, E> {
|
|
1341
|
-
return transformOrFail((input) =>
|
|
1366
|
+
return transformOrFail((input, options) =>
|
|
1342
1367
|
Result.match(Encoding.decodeBase64String(input), {
|
|
1343
|
-
onFailure: () =>
|
|
1368
|
+
onFailure: () =>
|
|
1369
|
+
Effect.fail(
|
|
1370
|
+
new SchemaIssue.InvalidValue(
|
|
1371
|
+
{ expected: "a valid Base64 string" },
|
|
1372
|
+
input,
|
|
1373
|
+
options
|
|
1374
|
+
)
|
|
1375
|
+
),
|
|
1344
1376
|
onSuccess: Effect.succeed
|
|
1345
1377
|
})
|
|
1346
1378
|
)
|
|
@@ -1370,9 +1402,16 @@ export function decodeBase64String<E extends string>(): Getter<string, E> {
|
|
|
1370
1402
|
* @since 4.0.0
|
|
1371
1403
|
*/
|
|
1372
1404
|
export function decodeBase64Url<E extends string>(): Getter<Uint8Array, E> {
|
|
1373
|
-
return transformOrFail((input) =>
|
|
1405
|
+
return transformOrFail((input, options) =>
|
|
1374
1406
|
Result.match(Encoding.decodeBase64Url(input), {
|
|
1375
|
-
onFailure: () =>
|
|
1407
|
+
onFailure: () =>
|
|
1408
|
+
Effect.fail(
|
|
1409
|
+
new SchemaIssue.InvalidValue(
|
|
1410
|
+
{ expected: "a valid Base64Url string" },
|
|
1411
|
+
input,
|
|
1412
|
+
options
|
|
1413
|
+
)
|
|
1414
|
+
),
|
|
1376
1415
|
onSuccess: Effect.succeed
|
|
1377
1416
|
})
|
|
1378
1417
|
)
|
|
@@ -1401,9 +1440,16 @@ export function decodeBase64Url<E extends string>(): Getter<Uint8Array, E> {
|
|
|
1401
1440
|
* @since 4.0.0
|
|
1402
1441
|
*/
|
|
1403
1442
|
export function decodeBase64UrlString<E extends string>(): Getter<string, E> {
|
|
1404
|
-
return transformOrFail((input) =>
|
|
1443
|
+
return transformOrFail((input, options) =>
|
|
1405
1444
|
Result.match(Encoding.decodeBase64UrlString(input), {
|
|
1406
|
-
onFailure: () =>
|
|
1445
|
+
onFailure: () =>
|
|
1446
|
+
Effect.fail(
|
|
1447
|
+
new SchemaIssue.InvalidValue(
|
|
1448
|
+
{ expected: "a valid Base64Url string" },
|
|
1449
|
+
input,
|
|
1450
|
+
options
|
|
1451
|
+
)
|
|
1452
|
+
),
|
|
1407
1453
|
onSuccess: Effect.succeed
|
|
1408
1454
|
})
|
|
1409
1455
|
)
|
|
@@ -1433,11 +1479,15 @@ export function decodeBase64UrlString<E extends string>(): Getter<string, E> {
|
|
|
1433
1479
|
* @since 4.0.0
|
|
1434
1480
|
*/
|
|
1435
1481
|
export function decodeHex<E extends string>(): Getter<Uint8Array, E> {
|
|
1436
|
-
return transformOrFail((input) =>
|
|
1482
|
+
return transformOrFail((input, options) =>
|
|
1437
1483
|
Result.match(Encoding.decodeHex(input), {
|
|
1438
1484
|
onFailure: () =>
|
|
1439
1485
|
Effect.fail(
|
|
1440
|
-
new SchemaIssue.InvalidValue(
|
|
1486
|
+
new SchemaIssue.InvalidValue(
|
|
1487
|
+
{ expected: "a valid hexadecimal string" },
|
|
1488
|
+
input,
|
|
1489
|
+
options
|
|
1490
|
+
)
|
|
1441
1491
|
),
|
|
1442
1492
|
onSuccess: Effect.succeed
|
|
1443
1493
|
})
|
|
@@ -1467,11 +1517,15 @@ export function decodeHex<E extends string>(): Getter<Uint8Array, E> {
|
|
|
1467
1517
|
* @since 4.0.0
|
|
1468
1518
|
*/
|
|
1469
1519
|
export function decodeHexString<E extends string>(): Getter<string, E> {
|
|
1470
|
-
return transformOrFail((input) =>
|
|
1520
|
+
return transformOrFail((input, options) =>
|
|
1471
1521
|
Result.match(Encoding.decodeHexString(input), {
|
|
1472
1522
|
onFailure: () =>
|
|
1473
1523
|
Effect.fail(
|
|
1474
|
-
new SchemaIssue.InvalidValue(
|
|
1524
|
+
new SchemaIssue.InvalidValue(
|
|
1525
|
+
{ expected: "a valid hexadecimal string" },
|
|
1526
|
+
input,
|
|
1527
|
+
options
|
|
1528
|
+
)
|
|
1475
1529
|
),
|
|
1476
1530
|
onSuccess: Effect.succeed
|
|
1477
1531
|
})
|
|
@@ -1527,14 +1581,16 @@ export function encodeUriComponent<E extends string>(): Getter<string, E> {
|
|
|
1527
1581
|
* @since 4.0.0
|
|
1528
1582
|
*/
|
|
1529
1583
|
export function decodeUriComponent<E extends string>(): Getter<string, E> {
|
|
1530
|
-
return transformOrFail((input) => {
|
|
1584
|
+
return transformOrFail((input, options) => {
|
|
1531
1585
|
try {
|
|
1532
1586
|
return Effect.succeed(globalThis.decodeURIComponent(input))
|
|
1533
1587
|
} catch {
|
|
1534
1588
|
return Effect.fail(
|
|
1535
|
-
new SchemaIssue.InvalidValue(
|
|
1536
|
-
|
|
1537
|
-
|
|
1589
|
+
new SchemaIssue.InvalidValue(
|
|
1590
|
+
{ expected: "a valid URI component" },
|
|
1591
|
+
input,
|
|
1592
|
+
options
|
|
1593
|
+
)
|
|
1538
1594
|
)
|
|
1539
1595
|
}
|
|
1540
1596
|
})
|
|
@@ -1573,9 +1629,12 @@ export function decodeUriComponent<E extends string>(): Getter<string, E> {
|
|
|
1573
1629
|
* @since 4.0.0
|
|
1574
1630
|
*/
|
|
1575
1631
|
export function dateTimeUtcFromInput<E extends DateTime.DateTime.Input>(): Getter<DateTime.Utc, E> {
|
|
1576
|
-
return transformOrFail((input) => {
|
|
1632
|
+
return transformOrFail((input, options) => {
|
|
1577
1633
|
return Option.match(DateTime.make(input), {
|
|
1578
|
-
onNone: () =>
|
|
1634
|
+
onNone: () =>
|
|
1635
|
+
Effect.fail(
|
|
1636
|
+
new SchemaIssue.InvalidValue({ message: "Invalid DateTime input" }, input, options)
|
|
1637
|
+
),
|
|
1579
1638
|
onSome: (dt) => Effect.succeed(DateTime.toUtc(dt))
|
|
1580
1639
|
})
|
|
1581
1640
|
})
|