effect 4.0.0-beta.105 → 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.
Files changed (134) hide show
  1. package/dist/Config.js +3 -3
  2. package/dist/Config.js.map +1 -1
  3. package/dist/ConfigProvider.d.ts +35 -3
  4. package/dist/ConfigProvider.d.ts.map +1 -1
  5. package/dist/ConfigProvider.js +41 -8
  6. package/dist/ConfigProvider.js.map +1 -1
  7. package/dist/Fiber.d.ts +1 -1
  8. package/dist/Fiber.d.ts.map +1 -1
  9. package/dist/Function.d.ts +26 -0
  10. package/dist/Function.d.ts.map +1 -1
  11. package/dist/Function.js +36 -0
  12. package/dist/Function.js.map +1 -1
  13. package/dist/JsonSchema.d.ts.map +1 -1
  14. package/dist/JsonSchema.js +34 -17
  15. package/dist/JsonSchema.js.map +1 -1
  16. package/dist/Schema.d.ts +32 -84
  17. package/dist/Schema.d.ts.map +1 -1
  18. package/dist/Schema.js +58 -54
  19. package/dist/Schema.js.map +1 -1
  20. package/dist/SchemaAST.d.ts +2 -17
  21. package/dist/SchemaAST.d.ts.map +1 -1
  22. package/dist/SchemaAST.js +39 -28
  23. package/dist/SchemaAST.js.map +1 -1
  24. package/dist/SchemaRepresentation.d.ts +15 -3
  25. package/dist/SchemaRepresentation.d.ts.map +1 -1
  26. package/dist/SchemaRepresentation.js +8 -2
  27. package/dist/SchemaRepresentation.js.map +1 -1
  28. package/dist/ScopedRef.d.ts.map +1 -1
  29. package/dist/ScopedRef.js +1 -1
  30. package/dist/ScopedRef.js.map +1 -1
  31. package/dist/TxQueue.js +1 -1
  32. package/dist/TxQueue.js.map +1 -1
  33. package/dist/internal/effect.js +2 -4
  34. package/dist/internal/effect.js.map +1 -1
  35. package/dist/internal/executionPlan.js +3 -2
  36. package/dist/internal/executionPlan.js.map +1 -1
  37. package/dist/internal/rcRef.js +18 -13
  38. package/dist/internal/rcRef.js.map +1 -1
  39. package/dist/internal/schema/fromJsonSchemaDocument.js +10 -6
  40. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  41. package/dist/internal/schema/toArbitrary.d.ts +1 -4
  42. package/dist/internal/schema/toArbitrary.d.ts.map +1 -1
  43. package/dist/internal/schema/toArbitrary.js +0 -74
  44. package/dist/internal/schema/toArbitrary.js.map +1 -1
  45. package/dist/internal/schema/toJsonSchemaDocument.js +18 -4
  46. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  47. package/dist/internal/schema/toRepresentation.js +45 -43
  48. package/dist/internal/schema/toRepresentation.js.map +1 -1
  49. package/dist/testing/TestSchema.js +2 -2
  50. package/dist/testing/TestSchema.js.map +1 -1
  51. package/dist/unstable/ai/McpSchema.d.ts +110 -110
  52. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  53. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  54. package/dist/unstable/ai/McpServer.js +23 -11
  55. package/dist/unstable/ai/McpServer.js.map +1 -1
  56. package/dist/unstable/ai/Prompt.d.ts +4 -3
  57. package/dist/unstable/ai/Prompt.d.ts.map +1 -1
  58. package/dist/unstable/ai/Prompt.js +38 -13
  59. package/dist/unstable/ai/Prompt.js.map +1 -1
  60. package/dist/unstable/cluster/Entity.d.ts +2 -2
  61. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  62. package/dist/unstable/cluster/Entity.js.map +1 -1
  63. package/dist/unstable/cluster/EntityProxy.d.ts +3 -3
  64. package/dist/unstable/cluster/EntityProxy.d.ts.map +1 -1
  65. package/dist/unstable/cluster/EntityProxy.js +4 -3
  66. package/dist/unstable/cluster/EntityProxy.js.map +1 -1
  67. package/dist/unstable/cluster/Sharding.d.ts +2 -2
  68. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  69. package/dist/unstable/cluster/Sharding.js +14 -5
  70. package/dist/unstable/cluster/Sharding.js.map +1 -1
  71. package/dist/unstable/eventlog/EventLogEncryption.d.ts +6 -5
  72. package/dist/unstable/eventlog/EventLogEncryption.d.ts.map +1 -1
  73. package/dist/unstable/eventlog/EventLogEncryption.js +14 -12
  74. package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
  75. package/dist/unstable/eventlog/EventLogMessage.d.ts +3 -3
  76. package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
  77. package/dist/unstable/eventlog/EventLogMessage.js +2 -3
  78. package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
  79. package/dist/unstable/eventlog/EventLogRemote.js +4 -4
  80. package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
  81. package/dist/unstable/eventlog/EventLogServerEncrypted.js +3 -2
  82. package/dist/unstable/eventlog/EventLogServerEncrypted.js.map +1 -1
  83. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  84. package/dist/unstable/http/HttpServerRequest.js +7 -1
  85. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  86. package/dist/unstable/http/MultipartParser/internal/multipart.d.ts.map +1 -1
  87. package/dist/unstable/http/MultipartParser/internal/multipart.js +18 -6
  88. package/dist/unstable/http/MultipartParser/internal/multipart.js.map +1 -1
  89. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  90. package/dist/unstable/httpapi/OpenApi.js +1 -1
  91. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  92. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  93. package/dist/unstable/rpc/RpcClient.js +5 -0
  94. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  95. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  96. package/dist/unstable/sql/SqlResolver.js +20 -16
  97. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  98. package/dist/unstable/workers/Worker.d.ts.map +1 -1
  99. package/dist/unstable/workers/Worker.js +11 -12
  100. package/dist/unstable/workers/Worker.js.map +1 -1
  101. package/package.json +1 -1
  102. package/src/Config.ts +3 -3
  103. package/src/ConfigProvider.ts +43 -8
  104. package/src/Fiber.ts +1 -1
  105. package/src/Function.ts +37 -0
  106. package/src/JsonSchema.ts +43 -42
  107. package/src/Schema.ts +68 -146
  108. package/src/SchemaAST.ts +50 -30
  109. package/src/SchemaRepresentation.ts +15 -3
  110. package/src/ScopedRef.ts +3 -1
  111. package/src/TxQueue.ts +1 -1
  112. package/src/internal/effect.ts +3 -6
  113. package/src/internal/executionPlan.ts +3 -2
  114. package/src/internal/rcRef.ts +24 -16
  115. package/src/internal/schema/fromJsonSchemaDocument.ts +19 -14
  116. package/src/internal/schema/toArbitrary.ts +0 -72
  117. package/src/internal/schema/toJsonSchemaDocument.ts +24 -4
  118. package/src/internal/schema/toRepresentation.ts +66 -48
  119. package/src/testing/TestSchema.ts +2 -2
  120. package/src/unstable/ai/McpServer.ts +23 -11
  121. package/src/unstable/ai/Prompt.ts +37 -15
  122. package/src/unstable/cluster/Entity.ts +7 -2
  123. package/src/unstable/cluster/EntityProxy.ts +12 -5
  124. package/src/unstable/cluster/Sharding.ts +29 -17
  125. package/src/unstable/eventlog/EventLogEncryption.ts +15 -16
  126. package/src/unstable/eventlog/EventLogMessage.ts +2 -3
  127. package/src/unstable/eventlog/EventLogRemote.ts +4 -4
  128. package/src/unstable/eventlog/EventLogServerEncrypted.ts +2 -2
  129. package/src/unstable/http/HttpServerRequest.ts +8 -3
  130. package/src/unstable/http/MultipartParser/internal/multipart.ts +19 -6
  131. package/src/unstable/httpapi/OpenApi.ts +4 -1
  132. package/src/unstable/rpc/RpcClient.ts +5 -0
  133. package/src/unstable/sql/SqlResolver.ts +28 -20
  134. package/src/unstable/workers/Worker.ts +13 -14
package/dist/Schema.js CHANGED
@@ -55,7 +55,6 @@ import * as SchemaIssue from "./SchemaIssue.js";
55
55
  import * as SchemaParser from "./SchemaParser.js";
56
56
  import * as SchemaTransformation from "./SchemaTransformation.js";
57
57
  import * as Struct_ from "./Struct.js";
58
- import * as FastCheck from "./testing/FastCheck.js";
59
58
  const TypeId = InternalSchema.TypeId;
60
59
  /**
61
60
  * Creates a schema for a **parametric** type (a generic container such as
@@ -1475,7 +1474,12 @@ export const requiredKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
1475
1474
  * @category combinators
1476
1475
  * @since 3.10.0
1477
1476
  */
1478
- export const optional = /*#__PURE__*/Struct_.lambda(self => optionalKey(UndefinedOr(self)));
1477
+ export const optional = /*#__PURE__*/Struct_.lambda(self => {
1478
+ const schema = UndefinedOr(self);
1479
+ return make(SchemaAST.optional(self.ast), {
1480
+ schema
1481
+ });
1482
+ });
1479
1483
  /**
1480
1484
  * Reverses `optional` and returns the inner schema.
1481
1485
  *
@@ -2665,7 +2669,7 @@ export function decodeTo(to, transformation) {
2665
2669
  * ```
2666
2670
  *
2667
2671
  * @category transforming
2668
- * @since 3.10.0
2672
+ * @since 4.0.0
2669
2673
  */
2670
2674
  export function decode(transformation) {
2671
2675
  return self => {
@@ -2701,7 +2705,7 @@ export function encodeTo(to, transformation) {
2701
2705
  * ```
2702
2706
  *
2703
2707
  * @category transforming
2704
- * @since 3.10.0
2708
+ * @since 4.0.0
2705
2709
  */
2706
2710
  export function encode(transformation) {
2707
2711
  return self => {
@@ -9212,35 +9216,41 @@ export const TaggedError = identifier => {
9212
9216
  };
9213
9217
  };
9214
9218
  /**
9215
- * Derives a {@link LazyArbitrary} from a schema. The result is memoized so
9216
- * repeated calls with the same schema are cheap.
9219
+ * Returns an {@link Arbitrary} factory derived from a schema. The generated
9220
+ * values satisfy the schema and use its decoded `Type`.
9221
+ *
9222
+ * **When to use**
9223
+ *
9224
+ * Use when you need a fast-check generator for values accepted by a schema.
9217
9225
  *
9218
9226
  * **Details**
9219
9227
  *
9220
- * Prefer {@link toArbitrary} when you need the arbitrary directly, or when you
9221
- * want derivation diagnostics via `{ report: true }`. Unsupported schema
9222
- * nodes, impossible constraints, invalid candidates, and recursive schemas
9223
- * without a finite terminal path fail immediately.
9228
+ * Constraints refine base generators; candidates add weighted sources while
9229
+ * filters still validate every value. Recursive schemas use terminal branches
9230
+ * and fail when no finite terminal path exists. The result is memoized so
9231
+ * repeated calls with the same schema are cheap.
9232
+ *
9233
+ * **Example** (Generating arbitrary values)
9234
+ *
9235
+ * ```ts import.meta.vitest
9236
+ * import { Schema } from "effect"
9237
+ * import * as FastCheck from "fast-check"
9238
+ *
9239
+ * const makePersonArbitrary = Schema.toArbitrary(
9240
+ * Schema.Struct({ name: Schema.String, age: Schema.Number })
9241
+ * )
9242
+ *
9243
+ * const PersonArbitrary = makePersonArbitrary(FastCheck)
9244
+ * FastCheck.sample(PersonArbitrary, 1)
9245
+ * ```
9224
9246
  *
9225
9247
  * @category generators
9226
9248
  * @since 4.0.0
9227
9249
  */
9228
- export function toArbitraryLazy(schema) {
9250
+ export function toArbitrary(schema) {
9229
9251
  const lawc = InternalArbitrary.memoized(schema.ast);
9230
9252
  return fc => lawc(fc, {});
9231
9253
  }
9232
- export function toArbitrary(schema, options) {
9233
- if (options?.report === true) {
9234
- const lawc = InternalArbitrary.memoized(schema.ast);
9235
- const report = InternalArbitrary.makeReport();
9236
- InternalArbitrary.collectReport(schema.ast, report);
9237
- return {
9238
- value: lawc(FastCheck, {}),
9239
- report: InternalArbitrary.toReport(report)
9240
- };
9241
- }
9242
- return toArbitraryLazy(schema)(FastCheck);
9243
- }
9244
9254
  // -----------------------------------------------------------------------------
9245
9255
  // Formatter
9246
9256
  // -----------------------------------------------------------------------------
@@ -9488,7 +9498,7 @@ export function toRepresentation(schema) {
9488
9498
  * @since 4.0.0
9489
9499
  */
9490
9500
  export function toJsonSchemaDocument(schema, options) {
9491
- const document = InternalToRepresentation.toRepresentation(toCodecJsonAST(schema.ast));
9501
+ const document = InternalToRepresentation.toRepresentation(toCodecJsonAST(schema.ast), InternalToJsonSchemaDocument.toRepresentationOptions);
9492
9502
  return InternalToJsonSchemaDocument.toJsonSchemaDocument(document, options);
9493
9503
  }
9494
9504
  /**
@@ -9511,14 +9521,13 @@ export function toCodecJson(schema) {
9511
9521
  schema
9512
9522
  });
9513
9523
  }
9514
- const toCodecJsonASTBase = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
9515
- const out = toCodecJsonBase(ast, toCodecJsonAST);
9524
+ /** @internal */
9525
+ export const toCodecJsonAST = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodingIdempotent(ast => {
9526
+ const out = toCodecJsonASTStep(ast, toCodecJsonAST);
9516
9527
  const context = ast.context;
9517
9528
  if (out === ast || context === undefined) return out;
9518
9529
  return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(context));
9519
9530
  });
9520
- /** @internal */
9521
- export const toCodecJsonAST = /*#__PURE__*/memoize(toCodecJsonASTBase);
9522
9531
  function withoutConstructorDefault(context) {
9523
9532
  return context.constructorDefault === undefined ? context : new SchemaAST.Context(context.isOptional, context.isMutable, undefined, context.annotations);
9524
9533
  }
@@ -9562,7 +9571,7 @@ const toCodecJsonReorder = /*#__PURE__*/makeReorder(ast => {
9562
9571
  return 1;
9563
9572
  }
9564
9573
  });
9565
- function toCodecJsonBase(ast, recur) {
9574
+ function toCodecJsonASTStep(ast, recur) {
9566
9575
  switch (ast._tag) {
9567
9576
  case "Declaration":
9568
9577
  {
@@ -9615,13 +9624,13 @@ function toCodecJsonBase(ast, recur) {
9615
9624
  * @since 4.0.0
9616
9625
  */
9617
9626
  export function toCodecIso(schema) {
9618
- return make(toCodecIsoTop(SchemaAST.toType(schema.ast)));
9627
+ return make(toCodecIsoAST(SchemaAST.toType(schema.ast)));
9619
9628
  }
9620
- const toCodecIsoTop = /*#__PURE__*/memoize(ast => {
9621
- const out = toCodecIsoBase(ast, toCodecIsoTop);
9629
+ const toCodecIsoAST = /*#__PURE__*/memoize(ast => {
9630
+ const out = toCodecIsoASTStep(ast, toCodecIsoAST);
9622
9631
  return out !== ast && ast.context !== undefined ? SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context)) : out;
9623
9632
  });
9624
- function toCodecIsoBase(ast, recur) {
9633
+ function toCodecIsoASTStep(ast, recur) {
9625
9634
  switch (ast._tag) {
9626
9635
  case "Declaration":
9627
9636
  {
@@ -9654,7 +9663,7 @@ function toCodecIsoBase(ast, recur) {
9654
9663
  * @since 4.0.0
9655
9664
  */
9656
9665
  export function toCodecStringTree(schema) {
9657
- return make(serializerStringTree(schema.ast), {
9666
+ return make(toCodecStringTreeAST(schema.ast), {
9658
9667
  schema
9659
9668
  });
9660
9669
  }
@@ -9677,7 +9686,7 @@ export function toCodecStringTree(schema) {
9677
9686
  * @since 4.0.0
9678
9687
  */
9679
9688
  export function toCodecArrayFromSingle(schema) {
9680
- return make(toCodecArrayFromSingleTop(schema.ast));
9689
+ return make(toCodecArrayFromSingleAST(schema.ast));
9681
9690
  }
9682
9691
  /**
9683
9692
  * Derives an XML encoder from a codec.
@@ -9801,7 +9810,7 @@ const toStringTreeReorder = /*#__PURE__*/makeReorder(ast => {
9801
9810
  return 1;
9802
9811
  }
9803
9812
  });
9804
- function serializerTree(ast, recur, onMissingAnnotation) {
9813
+ function toCodecStringTreeASTStep(ast, recur, onMissingAnnotation) {
9805
9814
  switch (ast._tag) {
9806
9815
  case "Declaration":
9807
9816
  {
@@ -9854,13 +9863,10 @@ function serializerTree(ast, recur, onMissingAnnotation) {
9854
9863
  }
9855
9864
  const nullToString = /*#__PURE__*/new SchemaAST.Link(/*#__PURE__*/new SchemaAST.Literal("null"), /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(() => null), /*#__PURE__*/SchemaGetter.transform(() => "null")));
9856
9865
  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()));
9857
- const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY";
9858
- const isSerializerArrayFromSingle = ast => SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY] === true;
9859
- const serializerStringTree = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
9860
- if (isSerializerArrayFromSingle(ast)) {
9861
- return ast;
9862
- }
9863
- const out = serializerTree(ast, serializerStringTree, ast => {
9866
+ const arrayFromSingleTransformation = /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(input => typeof input === "string" ? [input] : input), /*#__PURE__*/SchemaGetter.passthrough());
9867
+ const isCodecArrayFromSingleLink = link => link.transformation === arrayFromSingleTransformation;
9868
+ const toCodecStringTreeAST = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodingIdempotent(ast => {
9869
+ const out = toCodecStringTreeASTStep(ast, toCodecStringTreeAST, ast => {
9864
9870
  throw new globalThis.Error("Missing structural codec for StringTree", {
9865
9871
  cause: ast
9866
9872
  });
@@ -9869,24 +9875,22 @@ const serializerStringTree = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodin
9869
9875
  return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context));
9870
9876
  }
9871
9877
  return out;
9878
+ }, {
9879
+ stopAt: isCodecArrayFromSingleLink
9872
9880
  });
9873
9881
  const toArrayFromSingleInputElement = ast => SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(SchemaAST.unknown) : SchemaAST.unknown;
9874
- const arrayFromSingleTransformation = /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(input => typeof input === "string" ? [input] : input), /*#__PURE__*/SchemaGetter.passthrough());
9875
- const toCodecArrayFromSingleTop = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
9876
- if (isSerializerArrayFromSingle(ast)) {
9877
- return ast;
9878
- }
9879
- const out = onSerializerArrayFromSingle(ast);
9882
+ const toCodecArrayFromSingleAST = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodingIdempotent(ast => {
9883
+ const out = toCodecArrayFromSingleASTStep(ast);
9880
9884
  if (SchemaAST.isArrays(out)) {
9881
- const ensure = SchemaAST.decodeTo(new SchemaAST.Union([new SchemaAST.Arrays(out.isMutable, out.elements.map(toArrayFromSingleInputElement), out.rest.map(toArrayFromSingleInputElement)), SchemaAST.string], "anyOf", {
9882
- [SERIALIZER_ENSURE_ARRAY]: true
9883
- }), out, arrayFromSingleTransformation);
9885
+ const ensure = SchemaAST.decodeTo(new SchemaAST.Union([new SchemaAST.Arrays(out.isMutable, out.elements.map(toArrayFromSingleInputElement), out.rest.map(toArrayFromSingleInputElement)), SchemaAST.string], "anyOf"), out, arrayFromSingleTransformation);
9884
9886
  return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure;
9885
9887
  }
9886
9888
  return out;
9889
+ }, {
9890
+ stopAt: isCodecArrayFromSingleLink
9887
9891
  });
9888
- function onSerializerArrayFromSingle(ast) {
9889
- return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" || ast._tag === "Suspend" ? ast.recur(toCodecArrayFromSingleTop) : ast;
9892
+ function toCodecArrayFromSingleASTStep(ast) {
9893
+ return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" || ast._tag === "Suspend" ? ast.recur(toCodecArrayFromSingleAST) : ast;
9890
9894
  }
9891
9895
  /**
9892
9896
  * Reviver for persisted `isGreaterThanDate` checks.