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.
Files changed (62) hide show
  1. package/dist/Data.js +2 -2
  2. package/dist/Data.js.map +1 -1
  3. package/dist/Schema.d.ts +0 -1
  4. package/dist/Schema.d.ts.map +1 -1
  5. package/dist/Schema.js +82 -11
  6. package/dist/Schema.js.map +1 -1
  7. package/dist/index.d.ts +3 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/internal/schema/representation.js +1 -2
  12. package/dist/internal/schema/representation.js.map +1 -1
  13. package/dist/internal/schema/schema.d.ts.map +1 -1
  14. package/dist/internal/schema/schema.js +37 -0
  15. package/dist/internal/schema/schema.js.map +1 -1
  16. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  17. package/dist/unstable/ai/McpServer.js +7 -0
  18. package/dist/unstable/ai/McpServer.js.map +1 -1
  19. package/dist/unstable/cli/index.d.ts +2 -0
  20. package/dist/unstable/cli/index.d.ts.map +1 -1
  21. package/dist/unstable/cli/index.js +2 -0
  22. package/dist/unstable/cli/index.js.map +1 -1
  23. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  24. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  25. package/dist/unstable/httpapi/HttpApiBuilder.js +11 -6
  26. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  27. package/dist/unstable/httpapi/HttpApiClient.d.ts +5 -6
  28. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  29. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  30. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +17 -18
  31. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  32. package/dist/unstable/httpapi/HttpApiEndpoint.js +1 -2
  33. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  34. package/dist/unstable/httpapi/HttpApiError.d.ts +28 -8
  35. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  36. package/dist/unstable/httpapi/HttpApiError.js +28 -15
  37. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  38. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -3
  39. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  40. package/dist/unstable/httpapi/HttpApiMiddleware.js +2 -2
  41. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  42. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  43. package/package.json +1 -1
  44. package/src/Data.ts +1 -1
  45. package/src/Schema.ts +96 -12
  46. package/src/index.ts +3 -0
  47. package/src/internal/schema/representation.ts +1 -2
  48. package/src/internal/schema/schema.ts +43 -0
  49. package/src/unstable/ai/McpServer.ts +8 -0
  50. package/src/unstable/cli/index.ts +2 -0
  51. package/src/unstable/httpapi/HttpApi.ts +1 -1
  52. package/src/unstable/httpapi/HttpApiBuilder.ts +13 -6
  53. package/src/unstable/httpapi/HttpApiClient.ts +5 -6
  54. package/src/unstable/httpapi/HttpApiEndpoint.ts +6 -7
  55. package/src/unstable/httpapi/HttpApiError.ts +43 -22
  56. package/src/unstable/httpapi/HttpApiMiddleware.ts +6 -5
  57. package/src/unstable/httpapi/OpenApi.ts +1 -1
  58. package/dist/internal/schema/to-codec.d.ts +0 -2
  59. package/dist/internal/schema/to-codec.d.ts.map +0 -1
  60. package/dist/internal/schema/to-codec.js +0 -126
  61. package/dist/internal/schema/to-codec.js.map +0 -1
  62. 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(InternalToCodec.toCodecJson(schema.ast));
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(InternalToCodec.toCodecIso(AST.toType(schema.ast)));
6876
+ return make(toCodecIsoTop(AST.toType(schema.ast)));
6826
6877
  }
6827
- export function toCodecStringTree(schema, options) {
6828
- if (options?.keepDeclarations === true) {
6829
- return make(toCodecEnsureArray(serializerStringTreeKeepDeclarations(schema.ast)));
6830
- } else {
6831
- return make(toCodecEnsureArray(serializerStringTree(schema.ast)));
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__*/InternalToCodec.makeReorder(getStringTreePriority);
7023
+ const treeReorder = /*#__PURE__*/InternalSchema.makeReorder(getStringTreePriority);
6953
7024
  function serializerTree(ast, recur, onMissingAnnotation) {
6954
7025
  switch (ast._tag) {
6955
7026
  case "Declaration":