effect 4.0.0-beta.50 → 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 (135) hide show
  1. package/dist/BigDecimal.d.ts.map +1 -1
  2. package/dist/BigDecimal.js +18 -14
  3. package/dist/BigDecimal.js.map +1 -1
  4. package/dist/BigInt.d.ts.map +1 -1
  5. package/dist/BigInt.js +4 -4
  6. package/dist/BigInt.js.map +1 -1
  7. package/dist/Brand.d.ts +2 -4
  8. package/dist/Brand.d.ts.map +1 -1
  9. package/dist/Brand.js.map +1 -1
  10. package/dist/Data.js +2 -2
  11. package/dist/Data.js.map +1 -1
  12. package/dist/Duration.js +1 -1
  13. package/dist/Duration.js.map +1 -1
  14. package/dist/Schema.d.ts +77 -10
  15. package/dist/Schema.d.ts.map +1 -1
  16. package/dist/Schema.js +119 -18
  17. package/dist/Schema.js.map +1 -1
  18. package/dist/SchemaAST.d.ts +6 -0
  19. package/dist/SchemaAST.d.ts.map +1 -1
  20. package/dist/SchemaAST.js +216 -229
  21. package/dist/SchemaAST.js.map +1 -1
  22. package/dist/SchemaGetter.d.ts +3 -5
  23. package/dist/SchemaGetter.d.ts.map +1 -1
  24. package/dist/SchemaGetter.js +3 -2
  25. package/dist/SchemaGetter.js.map +1 -1
  26. package/dist/SchemaIssue.d.ts.map +1 -1
  27. package/dist/SchemaIssue.js +29 -11
  28. package/dist/SchemaIssue.js.map +1 -1
  29. package/dist/SchemaParser.js +14 -2
  30. package/dist/SchemaParser.js.map +1 -1
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +3 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/internal/effect.js +142 -65
  36. package/dist/internal/effect.js.map +1 -1
  37. package/dist/internal/schema/representation.js +1 -2
  38. package/dist/internal/schema/representation.js.map +1 -1
  39. package/dist/internal/schema/schema.d.ts.map +1 -1
  40. package/dist/internal/schema/schema.js +37 -0
  41. package/dist/internal/schema/schema.js.map +1 -1
  42. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  43. package/dist/unstable/ai/McpServer.js +7 -0
  44. package/dist/unstable/ai/McpServer.js.map +1 -1
  45. package/dist/unstable/cli/index.d.ts +2 -0
  46. package/dist/unstable/cli/index.d.ts.map +1 -1
  47. package/dist/unstable/cli/index.js +2 -0
  48. package/dist/unstable/cli/index.js.map +1 -1
  49. package/dist/unstable/cluster/Runners.d.ts.map +1 -1
  50. package/dist/unstable/cluster/Runners.js +3 -2
  51. package/dist/unstable/cluster/Runners.js.map +1 -1
  52. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  53. package/dist/unstable/cluster/SqlMessageStorage.js +1 -0
  54. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  55. package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
  56. package/dist/unstable/cluster/SqlRunnerStorage.js +6 -6
  57. package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
  58. package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -1
  59. package/dist/unstable/eventlog/SqlEventJournal.js +9 -8
  60. package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
  61. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -1
  62. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js +6 -5
  63. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
  64. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts.map +1 -1
  65. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +6 -5
  66. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
  67. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  68. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  69. package/dist/unstable/httpapi/HttpApiBuilder.js +11 -6
  70. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  71. package/dist/unstable/httpapi/HttpApiClient.d.ts +5 -6
  72. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  73. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  74. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +17 -18
  75. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  76. package/dist/unstable/httpapi/HttpApiEndpoint.js +1 -2
  77. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  78. package/dist/unstable/httpapi/HttpApiError.d.ts +28 -8
  79. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  80. package/dist/unstable/httpapi/HttpApiError.js +28 -15
  81. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  82. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -3
  83. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  84. package/dist/unstable/httpapi/HttpApiMiddleware.js +2 -2
  85. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  86. package/dist/unstable/httpapi/OpenApi.d.ts +1 -10
  87. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  88. package/dist/unstable/httpapi/OpenApi.js +2 -11
  89. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  90. package/dist/unstable/observability/OtlpMetrics.js +1 -1
  91. package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
  92. package/dist/unstable/observability/internal/protobuf.js +4 -4
  93. package/dist/unstable/observability/internal/protobuf.js.map +1 -1
  94. package/dist/unstable/rpc/RpcSerialization.d.ts +11 -0
  95. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  96. package/dist/unstable/rpc/RpcSerialization.js +14 -9
  97. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  98. package/package.json +1 -1
  99. package/src/BigDecimal.ts +20 -16
  100. package/src/BigInt.ts +4 -4
  101. package/src/Brand.ts +2 -4
  102. package/src/Data.ts +1 -1
  103. package/src/Duration.ts +1 -1
  104. package/src/Schema.ts +183 -23
  105. package/src/SchemaAST.ts +315 -267
  106. package/src/SchemaGetter.ts +4 -6
  107. package/src/SchemaIssue.ts +28 -15
  108. package/src/SchemaParser.ts +8 -2
  109. package/src/index.ts +3 -0
  110. package/src/internal/effect.ts +196 -69
  111. package/src/internal/schema/representation.ts +1 -2
  112. package/src/internal/schema/schema.ts +43 -0
  113. package/src/unstable/ai/McpServer.ts +8 -0
  114. package/src/unstable/cli/index.ts +2 -0
  115. package/src/unstable/cluster/Runners.ts +8 -5
  116. package/src/unstable/cluster/SqlMessageStorage.ts +1 -0
  117. package/src/unstable/cluster/SqlRunnerStorage.ts +12 -6
  118. package/src/unstable/eventlog/SqlEventJournal.ts +10 -2
  119. package/src/unstable/eventlog/SqlEventLogServerEncrypted.ts +8 -3
  120. package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +9 -3
  121. package/src/unstable/httpapi/HttpApi.ts +1 -1
  122. package/src/unstable/httpapi/HttpApiBuilder.ts +13 -6
  123. package/src/unstable/httpapi/HttpApiClient.ts +5 -6
  124. package/src/unstable/httpapi/HttpApiEndpoint.ts +6 -7
  125. package/src/unstable/httpapi/HttpApiError.ts +43 -22
  126. package/src/unstable/httpapi/HttpApiMiddleware.ts +6 -5
  127. package/src/unstable/httpapi/OpenApi.ts +3 -15
  128. package/src/unstable/observability/OtlpMetrics.ts +1 -1
  129. package/src/unstable/observability/internal/protobuf.ts +4 -4
  130. package/src/unstable/rpc/RpcSerialization.ts +41 -36
  131. package/dist/internal/schema/to-codec.d.ts +0 -2
  132. package/dist/internal/schema/to-codec.d.ts.map +0 -1
  133. package/dist/internal/schema/to-codec.js +0 -126
  134. package/dist/internal/schema/to-codec.js.map +0 -1
  135. package/src/internal/schema/to-codec.ts +0 -138
package/dist/Schema.d.ts CHANGED
@@ -3629,7 +3629,6 @@ export declare function instanceOf<C extends abstract new (...args: any) => any,
3629
3629
  * Used when building low-level AST transformations that bridge two schema types.
3630
3630
  *
3631
3631
  * @since 4.0.0
3632
- * @experimental
3633
3632
  */
3634
3633
  export declare function link<T>(): <To extends Top>(encodeTo: To, transformation: {
3635
3634
  readonly decode: Getter.Getter<T, NoInfer<To["Type"]>>;
@@ -3638,27 +3637,95 @@ export declare function link<T>(): <To extends Top>(encodeTo: To, transformation
3638
3637
  /**
3639
3638
  * Creates a custom filter check from a predicate function. The predicate
3640
3639
  * receives the input value, the schema's AST, and parse options, and returns
3641
- * `true`/`undefined` on success or a failure description on error.
3640
+ * a value of type {@link FilterOutput}.
3641
+ *
3642
+ * **Example** (Failure at a nested path)
3642
3643
  *
3643
- * **Example** (Custom filter check)
3644
3644
  * ```ts
3645
3645
  * import { Schema } from "effect"
3646
3646
  *
3647
- * // Check that a number is even
3648
- * const isEven = Schema.makeFilter(
3649
- * (n: number) => n % 2 === 0 || "expected an even number"
3647
+ * const schema = Schema.Struct({ password: Schema.String, confirmPassword: Schema.String }).check(
3648
+ * Schema.makeFilter((o) =>
3649
+ * o.password === o.confirmPassword
3650
+ * ? undefined
3651
+ * : { path: ["password"], issue: "password and confirmPassword must match" }
3652
+ * )
3653
+ * )
3654
+ *
3655
+ * console.log(String(Schema.decodeUnknownExit(schema)({ password: "123456", confirmPassword: "1234567" })))
3656
+ * // Failure(Cause([Fail(SchemaError: password and confirmPassword must match
3657
+ * // at ["password"])]))
3658
+ * ```
3659
+ *
3660
+ * **Example** (Reporting multiple failures at once)
3661
+ *
3662
+ * ```ts
3663
+ * import { Schema } from "effect"
3664
+ *
3665
+ * const schema = Schema.Struct({ a: Schema.Finite, b: Schema.Finite, c: Schema.Finite }).check(
3666
+ * Schema.makeFilter((o) => {
3667
+ * const issues: Array<Schema.FilterIssue> = []
3668
+ * if (o.a > 0) {
3669
+ * if (o.b <= 0) issues.push({ path: ["b"], issue: "b must be greater than 0" })
3670
+ * if (o.c <= 0) issues.push({ path: ["c"], issue: "c must be greater than 0" })
3671
+ * }
3672
+ * return issues
3673
+ * })
3650
3674
  * )
3651
3675
  *
3652
- * const EvenNumber = Schema.Number.check(isEven)
3676
+ * console.log(String(Schema.decodeUnknownExit(schema)({ a: 1, b: 0, c: 0 })))
3677
+ * // Failure(Cause([Fail(SchemaError: b must be greater than 0
3678
+ * // at ["b"]
3679
+ * // c must be greater than 0
3680
+ * // at ["c"])]))
3653
3681
  * ```
3654
3682
  *
3655
3683
  * @category Checks Constructors
3656
3684
  * @since 4.0.0
3657
3685
  */
3658
- export declare const makeFilter: <T>(filter: (input: T, ast: AST.AST, options: AST.ParseOptions) => undefined | boolean | string | Issue.Issue | {
3686
+ export declare const makeFilter: <T>(filter: (input: T, ast: AST.AST, options: AST.ParseOptions) => FilterOutput, annotations?: Annotations.Filter | undefined, abort?: boolean) => AST.Filter<T>;
3687
+ /**
3688
+ * A single failure reported by a filter predicate. Used as the element type
3689
+ * of the array arm of {@link FilterOutput}, and also accepted on its own.
3690
+ *
3691
+ * - `string`: failure with that string as the message. Produces an
3692
+ * {@link Issue.InvalidValue} wrapping the input, with the string used as
3693
+ * the issue's `message` annotation.
3694
+ * - {@link Issue.Issue}: a fully-formed issue, returned as-is.
3695
+ * - `{ path, issue }`: failure attached to a nested path. `issue` is either
3696
+ * a `string` (wrapped in an {@link Issue.InvalidValue}) or a full
3697
+ * {@link Issue.Issue}; the result is wrapped in an {@link Issue.Pointer}
3698
+ * at the given `path`.
3699
+ *
3700
+ * @category model
3701
+ * @since 4.0.0
3702
+ */
3703
+ export type FilterIssue = string | Issue.Issue | {
3659
3704
  readonly path: ReadonlyArray<PropertyKey>;
3660
- readonly message: string;
3661
- }, annotations?: Annotations.Filter | undefined, abort?: boolean) => AST.Filter<T>;
3705
+ readonly issue: string | Issue.Issue;
3706
+ };
3707
+ /**
3708
+ * The value a filter predicate (see {@link makeFilter}) may return.
3709
+ *
3710
+ * Each shape is normalized into an {@link Issue.Issue} (or `undefined` for
3711
+ * success) before being attached to the parse result:
3712
+ *
3713
+ * - `undefined`: success. The input satisfies the filter.
3714
+ * - `true`: success. Equivalent to `undefined`, useful when the predicate is
3715
+ * a plain boolean expression.
3716
+ * - `false`: generic failure. Produces an {@link Issue.InvalidValue} wrapping
3717
+ * the input, with no custom message.
3718
+ * - {@link FilterIssue}: a single failure. See {@link FilterIssue} for the
3719
+ * shapes (`string`, {@link Issue.Issue}, or `{ path, issue }`).
3720
+ * - `ReadonlyArray<FilterIssue>`: several failures reported together. An
3721
+ * empty array is treated as success; a single-element array is equivalent
3722
+ * to returning that element directly; otherwise the entries are grouped
3723
+ * into an {@link Issue.Composite}.
3724
+ *
3725
+ * @category model
3726
+ * @since 4.0.0
3727
+ */
3728
+ export type FilterOutput = undefined | boolean | FilterIssue | ReadonlyArray<FilterIssue>;
3662
3729
  /**
3663
3730
  * Groups multiple checks into a single {@link AST.FilterGroup}, applying
3664
3731
  * optional shared annotations to the group as a whole.