effect 4.0.0-beta.51 → 4.0.0-beta.52
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/Data.js +2 -2
- package/dist/Data.js.map +1 -1
- package/dist/Schema.d.ts +0 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +82 -11
- package/dist/Schema.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/schema/representation.js +1 -2
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +37 -0
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +7 -0
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +2 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +2 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +11 -6
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +5 -6
- 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 +17 -18
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +1 -2
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +28 -8
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +28 -15
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -3
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +2 -2
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/package.json +1 -1
- package/src/Data.ts +1 -1
- package/src/Schema.ts +96 -12
- package/src/index.ts +3 -0
- package/src/internal/schema/representation.ts +1 -2
- package/src/internal/schema/schema.ts +43 -0
- package/src/unstable/ai/McpServer.ts +8 -0
- package/src/unstable/cli/index.ts +2 -0
- package/src/unstable/httpapi/HttpApi.ts +1 -1
- package/src/unstable/httpapi/HttpApiBuilder.ts +13 -6
- package/src/unstable/httpapi/HttpApiClient.ts +5 -6
- package/src/unstable/httpapi/HttpApiEndpoint.ts +6 -7
- package/src/unstable/httpapi/HttpApiError.ts +43 -22
- package/src/unstable/httpapi/HttpApiMiddleware.ts +6 -5
- package/src/unstable/httpapi/OpenApi.ts +1 -1
- package/dist/internal/schema/to-codec.d.ts +0 -2
- package/dist/internal/schema/to-codec.d.ts.map +0 -1
- package/dist/internal/schema/to-codec.js +0 -126
- package/dist/internal/schema/to-codec.js.map +0 -1
- package/src/internal/schema/to-codec.ts +0 -138
package/dist/Schema.js
CHANGED
|
@@ -96,7 +96,7 @@ import * as Equal from "./Equal.js";
|
|
|
96
96
|
import * as Equivalence from "./Equivalence.js";
|
|
97
97
|
import * as Exit_ from "./Exit.js";
|
|
98
98
|
import { format, formatPropertyKey } from "./Formatter.js";
|
|
99
|
-
import { identity } from "./Function.js";
|
|
99
|
+
import { identity, memoize } from "./Function.js";
|
|
100
100
|
import * as HashMap_ from "./HashMap.js";
|
|
101
101
|
import * as HashSet_ from "./HashSet.js";
|
|
102
102
|
import * as core from "./internal/core.js";
|
|
@@ -106,7 +106,6 @@ import * as InternalEquivalence from "./internal/schema/equivalence.js";
|
|
|
106
106
|
import * as InternalStandard from "./internal/schema/representation.js";
|
|
107
107
|
import * as InternalSchema from "./internal/schema/schema.js";
|
|
108
108
|
import { SchemaError } from "./internal/schema/schema.js";
|
|
109
|
-
import * as InternalToCodec from "./internal/schema/to-codec.js";
|
|
110
109
|
import * as JsonPatch from "./JsonPatch.js";
|
|
111
110
|
import * as JsonSchema from "./JsonSchema.js";
|
|
112
111
|
import { remainder } from "./Number.js";
|
|
@@ -2441,7 +2440,6 @@ export function instanceOf(constructor, annotations) {
|
|
|
2441
2440
|
* Used when building low-level AST transformations that bridge two schema types.
|
|
2442
2441
|
*
|
|
2443
2442
|
* @since 4.0.0
|
|
2444
|
-
* @experimental
|
|
2445
2443
|
*/
|
|
2446
2444
|
export function link() {
|
|
2447
2445
|
return (encodeTo, transformation) => {
|
|
@@ -6812,7 +6810,60 @@ export function toJsonSchemaDocument(schema, options) {
|
|
|
6812
6810
|
* @since 4.0.0
|
|
6813
6811
|
*/
|
|
6814
6812
|
export function toCodecJson(schema) {
|
|
6815
|
-
return make(
|
|
6813
|
+
return make(toCodecJsonTop(schema.ast));
|
|
6814
|
+
}
|
|
6815
|
+
const toCodecJsonTop = /*#__PURE__*/AST.toCodec(ast => {
|
|
6816
|
+
const out = toCodecJsonBase(ast, toCodecJsonTop);
|
|
6817
|
+
return out !== ast && AST.isOptional(ast) ? AST.optionalKeyLastLink(out) : out;
|
|
6818
|
+
});
|
|
6819
|
+
function toCodecJsonBase(ast, recur) {
|
|
6820
|
+
switch (ast._tag) {
|
|
6821
|
+
case "Declaration":
|
|
6822
|
+
{
|
|
6823
|
+
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec;
|
|
6824
|
+
if (Predicate.isFunction(getLink)) {
|
|
6825
|
+
const tps = AST.isDeclaration(ast) ? ast.typeParameters.map(tp => InternalSchema.make(AST.toEncoded(tp))) : [];
|
|
6826
|
+
const link = getLink(tps);
|
|
6827
|
+
const to = recur(link.to);
|
|
6828
|
+
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)]);
|
|
6829
|
+
}
|
|
6830
|
+
return AST.replaceEncoding(ast, [AST.unknownToNull]);
|
|
6831
|
+
}
|
|
6832
|
+
case "Unknown":
|
|
6833
|
+
case "ObjectKeyword":
|
|
6834
|
+
return AST.replaceEncoding(ast, [AST.unknownToJson]);
|
|
6835
|
+
case "Undefined":
|
|
6836
|
+
case "Void":
|
|
6837
|
+
case "Literal":
|
|
6838
|
+
case "Number":
|
|
6839
|
+
return ast.toCodecJson();
|
|
6840
|
+
case "UniqueSymbol":
|
|
6841
|
+
case "Symbol":
|
|
6842
|
+
case "BigInt":
|
|
6843
|
+
return ast.toCodecStringTree();
|
|
6844
|
+
case "Objects":
|
|
6845
|
+
{
|
|
6846
|
+
if (ast.propertySignatures.some(ps => typeof ps.name !== "string")) {
|
|
6847
|
+
throw new globalThis.Error("Objects property names must be strings", {
|
|
6848
|
+
cause: ast
|
|
6849
|
+
});
|
|
6850
|
+
}
|
|
6851
|
+
return ast.recur(recur);
|
|
6852
|
+
}
|
|
6853
|
+
case "Union":
|
|
6854
|
+
{
|
|
6855
|
+
const sortedTypes = InternalSchema.jsonReorder(ast.types);
|
|
6856
|
+
if (sortedTypes !== ast.types) {
|
|
6857
|
+
return new AST.Union(sortedTypes, ast.mode, ast.annotations, ast.checks, ast.encoding, ast.context).recur(recur);
|
|
6858
|
+
}
|
|
6859
|
+
return ast.recur(recur);
|
|
6860
|
+
}
|
|
6861
|
+
case "Arrays":
|
|
6862
|
+
case "Suspend":
|
|
6863
|
+
return ast.recur(recur);
|
|
6864
|
+
}
|
|
6865
|
+
// `Schema.Any` is used as an escape hatch
|
|
6866
|
+
return ast;
|
|
6816
6867
|
}
|
|
6817
6868
|
/**
|
|
6818
6869
|
* Derives an isomorphism codec from a schema. The encoded form is the
|
|
@@ -6822,14 +6873,34 @@ export function toCodecJson(schema) {
|
|
|
6822
6873
|
* @since 4.0.0
|
|
6823
6874
|
*/
|
|
6824
6875
|
export function toCodecIso(schema) {
|
|
6825
|
-
return make(
|
|
6876
|
+
return make(toCodecIsoTop(AST.toType(schema.ast)));
|
|
6826
6877
|
}
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6878
|
+
const toCodecIsoTop = /*#__PURE__*/memoize(ast => {
|
|
6879
|
+
const out = toCodecIsoBase(ast, toCodecIsoTop);
|
|
6880
|
+
return out !== ast && AST.isOptional(ast) ? AST.optionalKeyLastLink(out) : out;
|
|
6881
|
+
});
|
|
6882
|
+
function toCodecIsoBase(ast, recur) {
|
|
6883
|
+
switch (ast._tag) {
|
|
6884
|
+
case "Declaration":
|
|
6885
|
+
{
|
|
6886
|
+
const getLink = ast.annotations?.toCodecIso ?? ast.annotations?.toCodec;
|
|
6887
|
+
if (Predicate.isFunction(getLink)) {
|
|
6888
|
+
const link = getLink(ast.typeParameters.map(tp => InternalSchema.make(tp)));
|
|
6889
|
+
const to = recur(link.to);
|
|
6890
|
+
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)]);
|
|
6891
|
+
}
|
|
6892
|
+
return ast;
|
|
6893
|
+
}
|
|
6894
|
+
case "Arrays":
|
|
6895
|
+
case "Objects":
|
|
6896
|
+
case "Union":
|
|
6897
|
+
case "Suspend":
|
|
6898
|
+
return ast.recur(recur);
|
|
6832
6899
|
}
|
|
6900
|
+
return ast;
|
|
6901
|
+
}
|
|
6902
|
+
export function toCodecStringTree(schema, options) {
|
|
6903
|
+
return make(toCodecEnsureArray(options?.keepDeclarations === true ? serializerStringTreeKeepDeclarations(schema.ast) : serializerStringTree(schema.ast)));
|
|
6833
6904
|
}
|
|
6834
6905
|
/**
|
|
6835
6906
|
* Derives an XML encoder from a codec. Encodes a value to an XML string by
|
|
@@ -6949,7 +7020,7 @@ function getStringTreePriority(ast) {
|
|
|
6949
7020
|
return 1;
|
|
6950
7021
|
}
|
|
6951
7022
|
}
|
|
6952
|
-
const treeReorder = /*#__PURE__*/
|
|
7023
|
+
const treeReorder = /*#__PURE__*/InternalSchema.makeReorder(getStringTreePriority);
|
|
6953
7024
|
function serializerTree(ast, recur, onMissingAnnotation) {
|
|
6954
7025
|
switch (ast._tag) {
|
|
6955
7026
|
case "Declaration":
|