effect 4.0.0-beta.85 → 4.0.0-beta.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ChannelSchema.d.ts +8 -8
- package/dist/ChannelSchema.d.ts.map +1 -1
- package/dist/Config.d.ts +2 -2
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +10 -3
- package/dist/Config.js.map +1 -1
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +4 -0
- package/dist/Cron.js.map +1 -1
- package/dist/Schema.d.ts +749 -393
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +95 -65
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +20 -29
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaParser.d.ts +24 -24
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +43 -39
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +300 -300
- package/dist/SchemaTransformation.d.ts +2 -2
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +5 -8
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/internal/effect.js +6 -7
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/matcher.js +0 -2
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/schema/representation.js +1 -5
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +9 -9
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +3 -2
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +2 -2
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +1 -1
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +4 -4
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +13 -6
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +4 -4
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +2 -2
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Response.d.ts +2 -2
- package/dist/unstable/ai/Response.d.ts.map +1 -1
- package/dist/unstable/ai/Response.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +26 -26
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/Argument.d.ts +8 -7
- package/dist/unstable/cli/Argument.d.ts.map +1 -1
- package/dist/unstable/cli/Argument.js.map +1 -1
- package/dist/unstable/cli/Flag.d.ts +8 -7
- package/dist/unstable/cli/Flag.d.ts.map +1 -1
- package/dist/unstable/cli/Flag.js.map +1 -1
- package/dist/unstable/cli/Param.d.ts +1806 -168
- package/dist/unstable/cli/Param.d.ts.map +1 -1
- package/dist/unstable/cli/Param.js +0 -70
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Primitive.d.ts +3 -4
- package/dist/unstable/cli/Primitive.d.ts.map +1 -1
- package/dist/unstable/cli/Primitive.js.map +1 -1
- package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
- package/dist/unstable/cli/internal/ansi.js +0 -22
- package/dist/unstable/cli/internal/ansi.js.map +1 -1
- package/dist/unstable/cli/internal/config.d.ts +48 -0
- package/dist/unstable/cli/internal/config.d.ts.map +1 -1
- package/dist/unstable/cli/internal/config.js +0 -6
- package/dist/unstable/cli/internal/config.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +3 -3
- package/dist/unstable/cluster/Reply.d.ts +2 -2
- package/dist/unstable/cluster/Reply.d.ts.map +1 -1
- package/dist/unstable/cluster/Reply.js.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
- package/dist/unstable/encoding/Msgpack.d.ts +6 -6
- package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
- package/dist/unstable/encoding/Msgpack.js.map +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +8 -8
- package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.d.ts +1 -1
- package/dist/unstable/encoding/Sse.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.d.ts +22 -22
- package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.d.ts +15 -15
- package/dist/unstable/http/HttpBody.d.ts +1 -1
- package/dist/unstable/http/HttpBody.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
- package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +12 -3
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +32 -32
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +13 -6
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js +0 -13
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/internal/otlpProtobuf.js +0 -68
- package/dist/unstable/observability/internal/otlpProtobuf.js.map +1 -1
- package/dist/unstable/observability/internal/protobuf.js +0 -28
- package/dist/unstable/observability/internal/protobuf.js.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.d.ts +2 -2
- package/dist/unstable/persistence/KeyValueStore.d.ts.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
- package/dist/unstable/persistence/Persistable.d.ts +6 -6
- package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.d.ts +3 -3
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Persistence.d.ts +5 -5
- package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.d.ts +2 -2
- package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +1 -1
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +3 -4
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js +1 -1
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +25 -4
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcMessage.d.ts +7 -0
- package/dist/unstable/rpc/RpcMessage.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMessage.js +20 -0
- package/dist/unstable/rpc/RpcMessage.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +2 -2
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.d.ts +10 -3
- package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.js.map +1 -1
- package/dist/unstable/rpc/RpcWorker.d.ts +3 -3
- package/dist/unstable/rpc/RpcWorker.d.ts.map +1 -1
- package/dist/unstable/schema/Model.d.ts +2 -2
- package/dist/unstable/schema/Model.d.ts.map +1 -1
- package/dist/unstable/schema/Model.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +16 -2
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/sql/SqlConnection.d.ts +1 -0
- package/dist/unstable/sql/SqlConnection.d.ts.map +1 -1
- package/dist/unstable/sql/SqlConnection.js.map +1 -1
- package/dist/unstable/sql/SqlModel.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.d.ts +4 -4
- package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/sql/SqlSchema.d.ts +5 -5
- package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.d.ts +1 -0
- package/dist/unstable/sql/Statement.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.js +3 -0
- package/dist/unstable/sql/Statement.js.map +1 -1
- package/dist/unstable/workflow/Activity.d.ts +2 -2
- package/dist/unstable/workflow/Activity.d.ts.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.d.ts +18 -18
- package/dist/unstable/workflow/DurableDeferred.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +3 -3
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +3 -3
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ChannelSchema.ts +9 -9
- package/src/Config.ts +12 -5
- package/src/Cron.ts +4 -0
- package/src/Schema.ts +968 -689
- package/src/SchemaAST.ts +25 -35
- package/src/SchemaParser.ts +85 -77
- package/src/SchemaTransformation.ts +5 -6
- package/src/internal/effect.ts +6 -22
- package/src/internal/matcher.ts +0 -5
- package/src/internal/schema/arbitrary.ts +1 -1
- package/src/internal/schema/representation.ts +1 -5
- package/src/internal/schema/schema.ts +1 -1
- package/src/testing/TestSchema.ts +14 -13
- package/src/unstable/ai/AnthropicStructuredOutput.ts +2 -2
- package/src/unstable/ai/Chat.ts +1 -1
- package/src/unstable/ai/LanguageModel.ts +7 -7
- package/src/unstable/ai/McpSchema.ts +16 -14
- package/src/unstable/ai/McpServer.ts +7 -7
- package/src/unstable/ai/OpenAiStructuredOutput.ts +2 -2
- package/src/unstable/ai/Response.ts +9 -5
- package/src/unstable/ai/Tool.ts +49 -47
- package/src/unstable/cli/Argument.ts +9 -8
- package/src/unstable/cli/Flag.ts +9 -8
- package/src/unstable/cli/Param.ts +6 -146
- package/src/unstable/cli/Primitive.ts +5 -6
- package/src/unstable/cli/internal/ansi.ts +0 -33
- package/src/unstable/cli/internal/config.ts +0 -8
- package/src/unstable/cli/internal/parser.ts +2 -2
- package/src/unstable/cluster/MessageStorage.ts +1 -1
- package/src/unstable/cluster/Reply.ts +6 -2
- package/src/unstable/devtools/DevToolsSchema.ts +1 -1
- package/src/unstable/encoding/Msgpack.ts +9 -7
- package/src/unstable/encoding/Ndjson.ts +10 -10
- package/src/unstable/encoding/Sse.ts +1 -1
- package/src/unstable/eventlog/Event.ts +3 -3
- package/src/unstable/http/HttpBody.ts +1 -1
- package/src/unstable/http/HttpClientRequest.ts +1 -1
- package/src/unstable/http/HttpIncomingMessage.ts +1 -1
- package/src/unstable/http/HttpMiddleware.ts +12 -3
- package/src/unstable/httpapi/HttpApi.ts +1 -1
- package/src/unstable/httpapi/HttpApiBuilder.ts +9 -5
- package/src/unstable/httpapi/HttpApiClient.ts +10 -10
- package/src/unstable/httpapi/HttpApiEndpoint.ts +45 -33
- package/src/unstable/httpapi/HttpApiMiddleware.ts +2 -2
- package/src/unstable/httpapi/HttpApiSchema.ts +16 -43
- package/src/unstable/httpapi/OpenApi.ts +5 -5
- package/src/unstable/observability/internal/otlpProtobuf.ts +0 -75
- package/src/unstable/observability/internal/protobuf.ts +0 -42
- package/src/unstable/persistence/KeyValueStore.ts +2 -2
- package/src/unstable/persistence/Persistable.ts +7 -7
- package/src/unstable/persistence/PersistedQueue.ts +3 -3
- package/src/unstable/persistence/Persistence.ts +5 -5
- package/src/unstable/reactivity/AsyncResult.ts +4 -4
- package/src/unstable/reactivity/Atom.ts +1 -1
- package/src/unstable/reactivity/AtomHttpApi.ts +1 -1
- package/src/unstable/rpc/Rpc.ts +7 -8
- package/src/unstable/rpc/RpcClient.ts +26 -4
- package/src/unstable/rpc/RpcMessage.ts +19 -0
- package/src/unstable/rpc/RpcMiddleware.ts +2 -2
- package/src/unstable/rpc/RpcSchema.ts +12 -9
- package/src/unstable/rpc/RpcWorker.ts +3 -3
- package/src/unstable/schema/Model.ts +2 -2
- package/src/unstable/schema/VariantSchema.ts +19 -17
- package/src/unstable/sql/SqlConnection.ts +5 -0
- package/src/unstable/sql/SqlModel.ts +2 -2
- package/src/unstable/sql/SqlResolver.ts +6 -6
- package/src/unstable/sql/SqlSchema.ts +5 -5
- package/src/unstable/sql/Statement.ts +11 -0
- package/src/unstable/workflow/Activity.ts +6 -6
- package/src/unstable/workflow/DurableDeferred.ts +33 -33
- package/src/unstable/workflow/Workflow.ts +5 -5
- package/src/unstable/workflow/WorkflowEngine.ts +10 -10
- package/dist/internal/concurrency.d.ts +0 -2
- package/dist/internal/concurrency.d.ts.map +0 -1
- package/dist/internal/concurrency.js +0 -29
- package/dist/internal/concurrency.js.map +0 -1
- package/src/internal/concurrency.ts +0 -52
package/dist/Schema.js
CHANGED
|
@@ -87,7 +87,7 @@ const TypeId = InternalSchema.TypeId;
|
|
|
87
87
|
* const isBox = (u: unknown): u is Box<unknown> =>
|
|
88
88
|
* typeof u === "object" && u !== null && "value" in u
|
|
89
89
|
*
|
|
90
|
-
* const Box = <A extends Schema.
|
|
90
|
+
* const Box = <A extends Schema.Constraint>(item: A) =>
|
|
91
91
|
* Schema.declareConstructor<Box<A["Type"]>, Box<A["Encoded"]>>()(
|
|
92
92
|
* [item],
|
|
93
93
|
* ([itemCodec]) =>
|
|
@@ -813,7 +813,7 @@ export const decodeUnknownOption = SchemaParser.decodeUnknownOption;
|
|
|
813
813
|
* @category decoding
|
|
814
814
|
* @since 3.10.0
|
|
815
815
|
*/
|
|
816
|
-
export const decodeOption =
|
|
816
|
+
export const decodeOption = SchemaParser.decodeOption;
|
|
817
817
|
/**
|
|
818
818
|
* Decodes an `unknown` input against a schema, returning a `Result` that
|
|
819
819
|
* succeeds with the decoded value or fails with a {@link SchemaError} for schema
|
|
@@ -1194,7 +1194,7 @@ export const encodeUnknownOption = SchemaParser.encodeUnknownOption;
|
|
|
1194
1194
|
* @category encoding
|
|
1195
1195
|
* @since 3.10.0
|
|
1196
1196
|
*/
|
|
1197
|
-
export const encodeOption =
|
|
1197
|
+
export const encodeOption = SchemaParser.encodeOption;
|
|
1198
1198
|
/**
|
|
1199
1199
|
* Encodes an `unknown` input against a schema, returning a `Result` that
|
|
1200
1200
|
* succeeds with the encoded value or fails with a {@link SchemaError} for schema
|
|
@@ -2064,6 +2064,13 @@ export function Record(key, value, options) {
|
|
|
2064
2064
|
* Extends a struct schema with one or more record (index-signature) schemas,
|
|
2065
2065
|
* producing a schema whose decoded type intersects the struct and all records.
|
|
2066
2066
|
*
|
|
2067
|
+
* **Gotchas**
|
|
2068
|
+
*
|
|
2069
|
+
* TypeScript index signatures also apply to fixed keys. `StructWithRest` does
|
|
2070
|
+
* not reject incompatible fixed fields at the call site; use
|
|
2071
|
+
* `StructWithRest.ValidateRecords` when you want an explicit type-level
|
|
2072
|
+
* compatibility check.
|
|
2073
|
+
*
|
|
2067
2074
|
* **Example** (Defining structs with string-indexed extra keys)
|
|
2068
2075
|
*
|
|
2069
2076
|
* ```ts
|
|
@@ -2568,7 +2575,7 @@ export function catchDecoding(f) {
|
|
|
2568
2575
|
* @since 4.0.0
|
|
2569
2576
|
*/
|
|
2570
2577
|
export function catchDecodingWithContext(f) {
|
|
2571
|
-
return self =>
|
|
2578
|
+
return self => middlewareDecoding(Effect.catchEager(f))(self);
|
|
2572
2579
|
}
|
|
2573
2580
|
/**
|
|
2574
2581
|
* Recovers from an encoding error by providing a fallback value.
|
|
@@ -2606,7 +2613,7 @@ export function catchEncoding(f) {
|
|
|
2606
2613
|
* @since 4.0.0
|
|
2607
2614
|
*/
|
|
2608
2615
|
export function catchEncodingWithContext(f) {
|
|
2609
|
-
return self =>
|
|
2616
|
+
return self => middlewareEncoding(Effect.catchEager(f))(self);
|
|
2610
2617
|
}
|
|
2611
2618
|
export function decodeTo(to, transformation) {
|
|
2612
2619
|
return from => {
|
|
@@ -2661,12 +2668,12 @@ export function decodeTo(to, transformation) {
|
|
|
2661
2668
|
*/
|
|
2662
2669
|
export function decode(transformation) {
|
|
2663
2670
|
return self => {
|
|
2664
|
-
return
|
|
2671
|
+
return decodeTo(toType(self), transformation)(self);
|
|
2665
2672
|
};
|
|
2666
2673
|
}
|
|
2667
2674
|
export function encodeTo(to, transformation) {
|
|
2668
2675
|
return from => {
|
|
2669
|
-
return transformation ?
|
|
2676
|
+
return transformation ? decodeTo(from, transformation)(to) : decodeTo(from)(to);
|
|
2670
2677
|
};
|
|
2671
2678
|
}
|
|
2672
2679
|
/**
|
|
@@ -2696,7 +2703,7 @@ export function encodeTo(to, transformation) {
|
|
|
2696
2703
|
*/
|
|
2697
2704
|
export function encode(transformation) {
|
|
2698
2705
|
return self => {
|
|
2699
|
-
return
|
|
2706
|
+
return decodeTo(self, transformation)(toEncoded(self));
|
|
2700
2707
|
};
|
|
2701
2708
|
}
|
|
2702
2709
|
/**
|
|
@@ -5228,6 +5235,7 @@ export function Result(success, failure) {
|
|
|
5228
5235
|
* into JSON, it will fail with an error. This is useful when the wrapped schema is
|
|
5229
5236
|
* sensitive and should not be exposed in JSON.
|
|
5230
5237
|
*
|
|
5238
|
+
* @see {@link RedactedFromValue} for decoding raw values and wrapping them in `Redacted`.
|
|
5231
5239
|
* @category Redacted
|
|
5232
5240
|
* @since 3.10.0
|
|
5233
5241
|
*/
|
|
@@ -5286,13 +5294,14 @@ export function Redacted(value, options) {
|
|
|
5286
5294
|
* @since 4.0.0
|
|
5287
5295
|
*/
|
|
5288
5296
|
export function redact(schema) {
|
|
5289
|
-
return
|
|
5297
|
+
return middlewareDecoding(Effect.mapErrorEager(SchemaIssue.redact))(schema);
|
|
5290
5298
|
}
|
|
5291
5299
|
/**
|
|
5292
5300
|
* Decodes a value and wraps it in `Redacted<A>`. Unlike {@link Redacted} which
|
|
5293
5301
|
* expects the input to already be a `Redacted` instance, this schema decodes
|
|
5294
5302
|
* the raw value and wraps it.
|
|
5295
5303
|
*
|
|
5304
|
+
* @see {@link Redacted} for schemas whose input is already a `Redacted` value.
|
|
5296
5305
|
* @category Redacted
|
|
5297
5306
|
* @since 4.0.0
|
|
5298
5307
|
*/
|
|
@@ -6654,10 +6663,8 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
|
|
|
6654
6663
|
*
|
|
6655
6664
|
* You can express nested values using bracket notation.
|
|
6656
6665
|
*
|
|
6657
|
-
* If you want to decode
|
|
6658
|
-
* `Schema.toCodecStringTree
|
|
6659
|
-
* This serializer preserves values such as numbers and `Blob` objects when
|
|
6660
|
-
* compatible with the schema.
|
|
6666
|
+
* If you want to decode string fields into non-string primitive values, use
|
|
6667
|
+
* `Schema.toCodecStringTree`.
|
|
6661
6668
|
*
|
|
6662
6669
|
* **Example** (Decoding a flat structure)
|
|
6663
6670
|
*
|
|
@@ -6711,8 +6718,7 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
|
|
|
6711
6718
|
* Schema.toCodecStringTree(
|
|
6712
6719
|
* Schema.Struct({
|
|
6713
6720
|
* a: Schema.Int
|
|
6714
|
-
* })
|
|
6715
|
-
* { keepDeclarations: true }
|
|
6721
|
+
* })
|
|
6716
6722
|
* )
|
|
6717
6723
|
* )
|
|
6718
6724
|
*
|
|
@@ -7530,25 +7536,25 @@ function getClassTypeId(identifier) {
|
|
|
7530
7536
|
function getClassSchemaFactory(from, identifier, annotations) {
|
|
7531
7537
|
let memo;
|
|
7532
7538
|
return self => {
|
|
7533
|
-
if (memo
|
|
7534
|
-
|
|
7535
|
-
const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast) => {
|
|
7536
|
-
return input instanceof self || Predicate.hasProperty(input, getClassTypeId(identifier)) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
7537
|
-
}, {
|
|
7538
|
-
identifier,
|
|
7539
|
-
[SchemaAST.ClassTypeId]: ([from]) => new SchemaAST.Link(from, transformation),
|
|
7540
|
-
toCodec: ([from]) => new SchemaAST.Link(from.ast, transformation),
|
|
7541
|
-
toArbitrary: ([from]) => () => ({
|
|
7542
|
-
arbitrary: from.arbitrary.map(args => new self(args)),
|
|
7543
|
-
terminal: from.terminal?.map(args => new self(args))
|
|
7544
|
-
}),
|
|
7545
|
-
toFormatter: ([from]) => t => `${self.identifier}(${from(t)})`,
|
|
7546
|
-
"~sentinels": SchemaAST.collectSentinels(from.ast),
|
|
7547
|
-
...annotations
|
|
7548
|
-
}));
|
|
7549
|
-
memo = from.pipe(decodeTo(to, transformation));
|
|
7539
|
+
if (memo !== undefined) {
|
|
7540
|
+
return memo;
|
|
7550
7541
|
}
|
|
7551
|
-
|
|
7542
|
+
const transformation = getClassTransformation(self);
|
|
7543
|
+
const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast) => {
|
|
7544
|
+
return input instanceof self || Predicate.hasProperty(input, getClassTypeId(identifier)) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
|
|
7545
|
+
}, {
|
|
7546
|
+
identifier,
|
|
7547
|
+
[SchemaAST.ClassTypeId]: ([from]) => new SchemaAST.Link(from, transformation),
|
|
7548
|
+
toCodec: ([from]) => new SchemaAST.Link(from.ast, transformation),
|
|
7549
|
+
toArbitrary: ([from]) => () => ({
|
|
7550
|
+
arbitrary: from.arbitrary.map(args => new self(args)),
|
|
7551
|
+
terminal: from.terminal?.map(args => new self(args))
|
|
7552
|
+
}),
|
|
7553
|
+
toFormatter: ([from]) => t => `${self.identifier}(${from(t)})`,
|
|
7554
|
+
"~sentinels": SchemaAST.collectSentinels(from.ast),
|
|
7555
|
+
...annotations
|
|
7556
|
+
}));
|
|
7557
|
+
return memo = decodeTo(to, transformation)(from);
|
|
7552
7558
|
};
|
|
7553
7559
|
}
|
|
7554
7560
|
function isStruct(schema) {
|
|
@@ -8011,9 +8017,6 @@ export function toJsonSchemaDocument(schema, options) {
|
|
|
8011
8017
|
definitions: jd.definitions
|
|
8012
8018
|
};
|
|
8013
8019
|
}
|
|
8014
|
-
// -----------------------------------------------------------------------------
|
|
8015
|
-
// Canonical Codecs
|
|
8016
|
-
// -----------------------------------------------------------------------------
|
|
8017
8020
|
/**
|
|
8018
8021
|
* Derives a canonical JSON codec from a schema. The encoded form is `Json`, and
|
|
8019
8022
|
* decoding produces the schema's `Type`.
|
|
@@ -8022,9 +8025,11 @@ export function toJsonSchemaDocument(schema, options) {
|
|
|
8022
8025
|
* @since 4.0.0
|
|
8023
8026
|
*/
|
|
8024
8027
|
export function toCodecJson(schema) {
|
|
8025
|
-
return make(toCodecJsonTop(schema.ast)
|
|
8028
|
+
return make(toCodecJsonTop(schema.ast), {
|
|
8029
|
+
schema
|
|
8030
|
+
});
|
|
8026
8031
|
}
|
|
8027
|
-
const toCodecJsonTop = /*#__PURE__*/SchemaAST.
|
|
8032
|
+
const toCodecJsonTop = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
|
|
8028
8033
|
const out = toCodecJsonBase(ast, toCodecJsonTop);
|
|
8029
8034
|
return out !== ast && SchemaAST.isOptional(ast) ? SchemaAST.optionalKeyLastLink(out) : out;
|
|
8030
8035
|
});
|
|
@@ -8111,8 +8116,43 @@ function toCodecIsoBase(ast, recur) {
|
|
|
8111
8116
|
}
|
|
8112
8117
|
return ast;
|
|
8113
8118
|
}
|
|
8114
|
-
|
|
8115
|
-
|
|
8119
|
+
/**
|
|
8120
|
+
* Converts a schema to the StringTree canonical codec, where every leaf value
|
|
8121
|
+
* becomes a string while preserving the original structure.
|
|
8122
|
+
*
|
|
8123
|
+
* **Details**
|
|
8124
|
+
*
|
|
8125
|
+
* Declarations are converted to `undefined` (unless they have a
|
|
8126
|
+
* `toCodecJson` or `toCodec` annotation).
|
|
8127
|
+
*
|
|
8128
|
+
* @category Canonical Codecs
|
|
8129
|
+
* @since 4.0.0
|
|
8130
|
+
*/
|
|
8131
|
+
export function toCodecStringTree(schema) {
|
|
8132
|
+
return make(serializerStringTree(schema.ast), {
|
|
8133
|
+
schema
|
|
8134
|
+
});
|
|
8135
|
+
}
|
|
8136
|
+
/**
|
|
8137
|
+
* Allows array schemas to decode from either an array input or a single value
|
|
8138
|
+
* input.
|
|
8139
|
+
*
|
|
8140
|
+
* **When to use**
|
|
8141
|
+
*
|
|
8142
|
+
* Use when you need to accept transport formats that may represent a
|
|
8143
|
+
* single-item array as a bare value, such as query-string or form-data adapters.
|
|
8144
|
+
*
|
|
8145
|
+
* **Gotchas**
|
|
8146
|
+
*
|
|
8147
|
+
* This combinator is intentionally not part of `toCodecStringTree`; it adds a
|
|
8148
|
+
* decoding convenience rather than a canonical StringTree representation. It
|
|
8149
|
+
* does not parse comma-separated strings.
|
|
8150
|
+
*
|
|
8151
|
+
* @category Canonical Codecs
|
|
8152
|
+
* @since 4.0.0
|
|
8153
|
+
*/
|
|
8154
|
+
export function toCodecArrayFromSingle(schema) {
|
|
8155
|
+
return make(toCodecArrayFromSingleTop(schema.ast));
|
|
8116
8156
|
}
|
|
8117
8157
|
/**
|
|
8118
8158
|
* Derives an XML encoder from a codec.
|
|
@@ -8290,7 +8330,12 @@ function serializerTree(ast, recur, onMissingAnnotation) {
|
|
|
8290
8330
|
}
|
|
8291
8331
|
const nullToString = /*#__PURE__*/new SchemaAST.Link(/*#__PURE__*/new SchemaAST.Literal("null"), /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(() => null), /*#__PURE__*/SchemaGetter.transform(() => "null")));
|
|
8292
8332
|
const booleanToString = /*#__PURE__*/new SchemaAST.Link(/*#__PURE__*/new SchemaAST.Union([/*#__PURE__*/new SchemaAST.Literal("true"), /*#__PURE__*/new SchemaAST.Literal("false")], "anyOf"), /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(s => s === "true"), /*#__PURE__*/SchemaGetter.String()));
|
|
8293
|
-
const
|
|
8333
|
+
const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY";
|
|
8334
|
+
const isSerializerArrayFromSingle = ast => SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY] === true;
|
|
8335
|
+
const serializerStringTree = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
|
|
8336
|
+
if (isSerializerArrayFromSingle(ast)) {
|
|
8337
|
+
return ast;
|
|
8338
|
+
}
|
|
8294
8339
|
const out = serializerTree(ast, serializerStringTree, ast => SchemaAST.replaceEncoding(ast, [unknownToUndefined]));
|
|
8295
8340
|
if (out !== ast && SchemaAST.isOptional(ast)) {
|
|
8296
8341
|
return SchemaAST.optionalKeyLastLink(out);
|
|
@@ -8298,38 +8343,23 @@ const serializerStringTree = /*#__PURE__*/SchemaAST.toCodec(ast => {
|
|
|
8298
8343
|
return out;
|
|
8299
8344
|
});
|
|
8300
8345
|
const unknownToUndefined = /*#__PURE__*/new SchemaAST.Link(SchemaAST.undefined, /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.passthrough(), /*#__PURE__*/SchemaGetter.transform(() => undefined)));
|
|
8301
|
-
const
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
|
|
8305
|
-
}
|
|
8306
|
-
return out;
|
|
8307
|
-
});
|
|
8308
|
-
const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY";
|
|
8309
|
-
const toCodecEnsureArray = /*#__PURE__*/SchemaAST.toCodec(ast => {
|
|
8310
|
-
if (SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY]) {
|
|
8346
|
+
const toArrayFromSingleInputElement = ast => SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(SchemaAST.unknown) : SchemaAST.unknown;
|
|
8347
|
+
const arrayFromSingleTransformation = /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(input => typeof input === "string" ? [input] : input), /*#__PURE__*/SchemaGetter.passthrough());
|
|
8348
|
+
const toCodecArrayFromSingleTop = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
|
|
8349
|
+
if (isSerializerArrayFromSingle(ast)) {
|
|
8311
8350
|
return ast;
|
|
8312
8351
|
}
|
|
8313
|
-
const out =
|
|
8352
|
+
const out = onSerializerArrayFromSingle(ast);
|
|
8314
8353
|
if (SchemaAST.isArrays(out)) {
|
|
8315
|
-
const ensure = new SchemaAST.Union([
|
|
8354
|
+
const ensure = SchemaAST.decodeTo(new SchemaAST.Union([new SchemaAST.Arrays(out.isMutable, out.elements.map(toArrayFromSingleInputElement), out.rest.map(toArrayFromSingleInputElement)), SchemaAST.string], "anyOf", {
|
|
8316
8355
|
[SERIALIZER_ENSURE_ARRAY]: true
|
|
8317
|
-
});
|
|
8356
|
+
}), out, arrayFromSingleTransformation);
|
|
8318
8357
|
return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure;
|
|
8319
8358
|
}
|
|
8320
8359
|
return out;
|
|
8321
8360
|
});
|
|
8322
|
-
function
|
|
8323
|
-
|
|
8324
|
-
default:
|
|
8325
|
-
return ast;
|
|
8326
|
-
case "Declaration":
|
|
8327
|
-
case "Arrays":
|
|
8328
|
-
case "Objects":
|
|
8329
|
-
case "Union":
|
|
8330
|
-
case "Suspend":
|
|
8331
|
-
return ast.recur(toCodecEnsureArray);
|
|
8332
|
-
}
|
|
8361
|
+
function onSerializerArrayFromSingle(ast) {
|
|
8362
|
+
return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" || ast._tag === "Suspend" ? ast.recur(toCodecArrayFromSingleTop) : ast;
|
|
8333
8363
|
}
|
|
8334
8364
|
// -----------------------------------------------------------------------------
|
|
8335
8365
|
// Optic APIs
|