effect 4.0.0-beta.104 → 4.0.0-beta.105
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 +2 -1
- package/dist/Config.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/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 +73 -25
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +83 -50
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +30 -0
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +40 -32
- 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/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/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/internal/schema/schema.js +1 -9
- package/dist/internal/schema/schema.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 +8 -7
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Prompt.js +4 -4
- package/dist/unstable/ai/Prompt.js.map +1 -1
- package/dist/unstable/cluster/Reply.js +4 -4
- package/dist/unstable/cluster/Reply.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/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/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/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 +3 -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/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 +3 -1
- package/src/Context.ts +1 -23
- package/src/Cron.ts +65 -2
- package/src/Optic.ts +59 -58
- package/src/Schema.ts +145 -71
- package/src/SchemaAST.ts +85 -48
- 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/SchemaTransformation.ts +66 -18
- package/src/Stdio.ts +23 -4
- package/src/internal/schema/schema.ts +1 -17
- package/src/testing/TestSchema.ts +8 -8
- package/src/unstable/ai/Prompt.ts +14 -4
- package/src/unstable/cluster/Reply.ts +4 -4
- package/src/unstable/encoding/Msgpack.ts +12 -8
- package/src/unstable/http/HttpClient.ts +132 -23
- package/src/unstable/httpapi/HttpApiBuilder.ts +32 -13
- package/src/unstable/httpapi/HttpApiClient.ts +26 -8
- package/src/unstable/reactivity/AsyncResult.ts +11 -6
- package/src/unstable/reactivity/Atom.ts +44 -25
- package/src/unstable/rpc/RpcClient.ts +4 -1
- package/src/unstable/rpc/RpcServer.ts +4 -2
- package/src/unstable/workflow/Workflow.ts +2 -5
package/src/SchemaAST.ts
CHANGED
|
@@ -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
|
}
|
|
@@ -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
|
)
|
|
@@ -3688,13 +3727,10 @@ function fromConst<const T>(
|
|
|
3688
3727
|
value: T
|
|
3689
3728
|
): SchemaParser.Parser {
|
|
3690
3729
|
const succeed = InternalParser.succeed(value)
|
|
3691
|
-
return (input) => {
|
|
3730
|
+
return (input, options) => {
|
|
3692
3731
|
if (input === InternalParser.missing) return InternalParser.missingExit
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
: Effect.fail(
|
|
3696
|
-
new SchemaIssue.InvalidType(ast)
|
|
3697
|
-
)
|
|
3732
|
+
if (input === value) return succeed
|
|
3733
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
3698
3734
|
}
|
|
3699
3735
|
}
|
|
3700
3736
|
|
|
@@ -3702,13 +3738,10 @@ function fromRefinement<T>(
|
|
|
3702
3738
|
ast: AST,
|
|
3703
3739
|
refinement: (input: unknown) => input is T
|
|
3704
3740
|
): SchemaParser.Parser {
|
|
3705
|
-
return (input) => {
|
|
3741
|
+
return (input, options) => {
|
|
3706
3742
|
if (input === InternalParser.missing) return InternalParser.missingExit
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
: Effect.fail(
|
|
3710
|
-
new SchemaIssue.InvalidType(ast)
|
|
3711
|
-
)
|
|
3743
|
+
if (refinement(input)) return InternalParser.sameExit
|
|
3744
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
3712
3745
|
}
|
|
3713
3746
|
}
|
|
3714
3747
|
|
|
@@ -3896,13 +3929,17 @@ const symbolToString = new Link(
|
|
|
3896
3929
|
symbolString,
|
|
3897
3930
|
new SchemaTransformation.Transformation(
|
|
3898
3931
|
SchemaGetter.transform((description) => globalThis.Symbol.for(isStringSymbolRegExp.exec(description)![1])),
|
|
3899
|
-
SchemaGetter.transformOrFail((sym: symbol) => {
|
|
3932
|
+
SchemaGetter.transformOrFail((sym: symbol, options) => {
|
|
3900
3933
|
const key = globalThis.Symbol.keyFor(sym)
|
|
3901
3934
|
if (key !== undefined) {
|
|
3902
3935
|
return Effect.succeed(globalThis.String(sym))
|
|
3903
3936
|
}
|
|
3904
3937
|
return Effect.fail(
|
|
3905
|
-
new SchemaIssue.Forbidden(
|
|
3938
|
+
new SchemaIssue.Forbidden(
|
|
3939
|
+
{ message: "cannot serialize to string, Symbol is not registered" },
|
|
3940
|
+
sym,
|
|
3941
|
+
options
|
|
3942
|
+
)
|
|
3906
3943
|
)
|
|
3907
3944
|
})
|
|
3908
3945
|
)
|
|
@@ -3945,7 +3982,7 @@ export function collectIssues<T>(
|
|
|
3945
3982
|
} else {
|
|
3946
3983
|
const issue = check.run(value, ast, options)
|
|
3947
3984
|
if (issue) {
|
|
3948
|
-
const filter = new SchemaIssue.Filter(check, issue)
|
|
3985
|
+
const filter = new SchemaIssue.Filter(check, issue, value, options)
|
|
3949
3986
|
if (issues) issues.push(filter)
|
|
3950
3987
|
else issues = [filter]
|
|
3951
3988
|
if (options.errors !== "all" || check.aborted) {
|
|
@@ -4154,10 +4191,10 @@ export function isJson(u: unknown): u is Schema.Json {
|
|
|
4154
4191
|
/** @internal */
|
|
4155
4192
|
export const Json = new Declaration(
|
|
4156
4193
|
[],
|
|
4157
|
-
() => (input, ast) =>
|
|
4194
|
+
() => (input, ast, options) =>
|
|
4158
4195
|
isJson(input) ?
|
|
4159
4196
|
InternalParser.sameExit :
|
|
4160
|
-
Effect.fail(new SchemaIssue.InvalidType(ast)),
|
|
4197
|
+
Effect.fail(new SchemaIssue.InvalidType(ast, input, options)),
|
|
4161
4198
|
{
|
|
4162
4199
|
representation: {
|
|
4163
4200
|
id: "effect/schema/Json",
|
|
@@ -4206,10 +4243,10 @@ export function isStringTree(u: unknown): u is Schema.StringTree {
|
|
|
4206
4243
|
|
|
4207
4244
|
const StringTree = new Declaration(
|
|
4208
4245
|
[],
|
|
4209
|
-
() => (input, ast) =>
|
|
4246
|
+
() => (input, ast, options) =>
|
|
4210
4247
|
isStringTree(input) ?
|
|
4211
4248
|
InternalParser.sameExit :
|
|
4212
|
-
Effect.fail(new SchemaIssue.InvalidType(ast)),
|
|
4249
|
+
Effect.fail(new SchemaIssue.InvalidType(ast, input, options)),
|
|
4213
4250
|
{ expected: "StringTree", toCodecStringTree: () => undefined }
|
|
4214
4251
|
)
|
|
4215
4252
|
|
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})`
|
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
|
})
|