effect 4.0.0-beta.46 → 4.0.0-beta.48

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 (58) hide show
  1. package/dist/Schema.d.ts +223 -140
  2. package/dist/Schema.d.ts.map +1 -1
  3. package/dist/Schema.js +110 -32
  4. package/dist/Schema.js.map +1 -1
  5. package/dist/Types.d.ts +9 -0
  6. package/dist/Types.d.ts.map +1 -1
  7. package/dist/unstable/ai/McpSchema.d.ts +1 -1
  8. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  9. package/dist/unstable/eventlog/EventLog.d.ts +4 -1
  10. package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
  11. package/dist/unstable/eventlog/EventLog.js +1 -1
  12. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  13. package/dist/unstable/eventlog/EventLogRemote.d.ts.map +1 -1
  14. package/dist/unstable/eventlog/EventLogRemote.js +1 -0
  15. package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
  16. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +1 -1
  17. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  18. package/dist/unstable/httpapi/HttpApiBuilder.js +3 -2
  19. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  20. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  21. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  22. package/dist/unstable/httpapi/HttpApiMiddleware.js +1 -0
  23. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  24. package/dist/unstable/httpapi/HttpApiSchema.d.ts +7 -7
  25. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  26. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  27. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  28. package/dist/unstable/observability/OtlpExporter.js +1 -1
  29. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  30. package/dist/unstable/reactivity/Atom.d.ts +1 -1
  31. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  32. package/dist/unstable/reactivity/Atom.js.map +1 -1
  33. package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
  34. package/dist/unstable/rpc/RpcSchema.d.ts +1 -1
  35. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  36. package/dist/unstable/socket/Socket.js.map +1 -1
  37. package/dist/unstable/workers/Transferable.d.ts +1 -1
  38. package/dist/unstable/workers/Transferable.d.ts.map +1 -1
  39. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  40. package/dist/unstable/workflow/Workflow.js +1 -1
  41. package/dist/unstable/workflow/Workflow.js.map +1 -1
  42. package/package.json +10 -10
  43. package/src/Schema.ts +260 -167
  44. package/src/Types.ts +8 -0
  45. package/src/unstable/ai/McpSchema.ts +1 -1
  46. package/src/unstable/eventlog/EventLog.ts +7 -2
  47. package/src/unstable/eventlog/EventLogRemote.ts +1 -0
  48. package/src/unstable/httpapi/HttpApiBuilder.ts +11 -3
  49. package/src/unstable/httpapi/HttpApiClient.ts +2 -2
  50. package/src/unstable/httpapi/HttpApiMiddleware.ts +1 -0
  51. package/src/unstable/httpapi/HttpApiSchema.ts +4 -6
  52. package/src/unstable/observability/OtlpExporter.ts +1 -0
  53. package/src/unstable/reactivity/Atom.ts +1 -1
  54. package/src/unstable/reactivity/AtomRpc.ts +4 -4
  55. package/src/unstable/rpc/RpcSchema.ts +1 -1
  56. package/src/unstable/socket/Socket.ts +1 -1
  57. package/src/unstable/workers/Transferable.ts +2 -2
  58. package/src/unstable/workflow/Workflow.ts +5 -2
package/dist/Schema.js CHANGED
@@ -233,7 +233,7 @@ export function declare(is, annotations) {
233
233
  * const bottom = Schema.revealBottom(schema)
234
234
  *
235
235
  * // `bottom` now exposes Type, Encoded, DecodingServices, EncodingServices,
236
- * // ast, ~rebuild.out, ~type.make.in, Iso, ~type.parameters, etc.
236
+ * // ast, Rebuild, ~type.make.in, Iso, ~type.parameters, etc.
237
237
  * type T = typeof bottom["Type"] // string
238
238
  * type E = typeof bottom["Encoded"] // string
239
239
  * ```
@@ -264,13 +264,44 @@ export function revealBottom(bottom) {
264
264
  * )
265
265
  * ```
266
266
  *
267
+ * @see {@link annotateEncoded} to annotate the encoded side instead.
268
+ *
267
269
  * @category Annotations
268
270
  * @since 4.0.0
269
271
  */
270
272
  export function annotate(annotations) {
271
- return self => {
272
- return self.annotate(annotations);
273
- };
273
+ return self => self.annotate(annotations);
274
+ }
275
+ /**
276
+ * Adds metadata annotations to the **encoded** side of a schema without
277
+ * changing its runtime behavior. This is the encoded-side counterpart of
278
+ * `annotate`, which targets the decoded (Type) side.
279
+ *
280
+ * Internally the schema is flipped so that `Encoded` becomes `Type`,
281
+ * annotated, and then flipped back.
282
+ *
283
+ * **Example** (Adding a title to the encoded representation)
284
+ *
285
+ * ```ts
286
+ * import { Schema } from "effect"
287
+ *
288
+ * const schema = Schema.NumberFromString.pipe(
289
+ * Schema.annotateEncoded({
290
+ * title: "my title"
291
+ * })
292
+ * )
293
+ *
294
+ * console.log(Schema.toEncoded(schema).ast.annotations?.title)
295
+ * // "my title"
296
+ * ```
297
+ *
298
+ * @see {@link annotate} to annotate the type side instead.
299
+ *
300
+ * @category Annotations
301
+ * @since 4.0.0
302
+ */
303
+ export function annotateEncoded(annotations) {
304
+ return self => flip(flip(self).annotate(annotations));
274
305
  }
275
306
  /**
276
307
  * Adds key-level annotations to a schema field. This is the pipeable
@@ -2017,18 +2048,18 @@ defaultValue) {
2017
2048
  });
2018
2049
  }
2019
2050
  /**
2020
- * **Options**
2051
+ * Makes a struct key optional on the `Encoded` side and provides a default
2052
+ * `Encoded` value when the key is missing during decoding.
2021
2053
  *
2022
- * - `encodingStrategy`: The strategy to use when encoding.
2023
- * - `passthrough`: (default) Pass the default value through to the output.
2024
- * - `omit`: Omit the value from the output.
2054
+ * The key uses `optionalKey` on the encoded side, so it may be absent from the
2055
+ * input object but **not** `undefined`. The default value is specified in terms
2056
+ * of the `Encoded` type (before any decoding transformations).
2025
2057
  *
2026
- * Provides a default value for a missing key during decoding.
2058
+ * **Options**
2027
2059
  *
2028
- * When the key is absent from the input, `defaultValue()` is called to supply a value.
2029
- * During encoding, the behavior is controlled by `options.encodingStrategy`:
2030
- * - `"passthrough"` (default): include the value in the output
2031
- * - `"omit"`: omit the key from the output
2060
+ * - `encodingStrategy`:
2061
+ * - `"passthrough"` (default): include the value in the encoded output.
2062
+ * - `"omit"`: omit the key from the encoded output.
2032
2063
  *
2033
2064
  * **Example** (Default for a missing struct key)
2034
2065
  *
@@ -2043,7 +2074,8 @@ defaultValue) {
2043
2074
  * // result: { name: "anonymous" }
2044
2075
  * ```
2045
2076
  *
2046
- * @see {@link withDecodingDefault} for the `optional` (value-level) variant
2077
+ * @see {@link withDecodingDefault} for the value-level variant (key absent **or** `undefined`)
2078
+ * @see {@link withDecodingDefaultTypeKey} for the variant where the default is a `Type` value
2047
2079
  * @since 4.0.0
2048
2080
  */
2049
2081
  export function withDecodingDefaultKey(defaultValue, options) {
@@ -2056,21 +2088,42 @@ export function withDecodingDefaultKey(defaultValue, options) {
2056
2088
  };
2057
2089
  }
2058
2090
  /**
2091
+ * Makes a struct key optional on the `Encoded` side (`optionalKey`, so the
2092
+ * key may be absent but **not** `undefined`) and provides a default `Type`
2093
+ * value when the key is missing during decoding.
2094
+ *
2095
+ * Unlike {@link withDecodingDefaultKey}, the default value is specified in
2096
+ * terms of the `Type` (decoded) representation, so it does not need to go
2097
+ * through the decoding transformation.
2098
+ *
2059
2099
  * **Options**
2060
2100
  *
2061
- * - `encodingStrategy`: The strategy to use when encoding.
2062
- * - `passthrough`: (default) Pass the default value through to the output.
2063
- * - `omit`: Omit the value from the output.
2101
+ * - `encodingStrategy`:
2102
+ * - `"passthrough"` (default): include the value in the encoded output.
2103
+ * - `"omit"`: omit the key from the encoded output.
2064
2104
  *
2065
- * Provides a default value for an `optional` field during decoding.
2105
+ * @see {@link withDecodingDefaultKey} for the variant where the default is an `Encoded` value
2106
+ * @see {@link withDecodingDefaultType} for the value-level variant
2107
+ * @since 4.0.0
2108
+ */
2109
+ export function withDecodingDefaultTypeKey(defaultValue, options) {
2110
+ return self => {
2111
+ return toType(self).pipe(withDecodingDefaultKey(defaultValue, options), encodeTo(optionalKey(self)));
2112
+ };
2113
+ }
2114
+ /**
2115
+ * Wraps the `Encoded` side with `optional` (key absent **or** `undefined`)
2116
+ * and provides a default `Encoded` value when the field is missing or
2117
+ * `undefined` during decoding.
2066
2118
  *
2067
- * Similar to {@link withDecodingDefaultKey} but works on `optional` (value-level optional)
2068
- * rather than `optionalKey` (key-level optional).
2119
+ * The default value is specified in terms of the `Encoded` type (before any
2120
+ * decoding transformations).
2069
2121
  *
2070
- * When the value is `undefined` or absent, `defaultValue()` is called to supply a value.
2071
- * During encoding, the behavior is controlled by `options.encodingStrategy`:
2072
- * - `"passthrough"` (default): include the value in the output
2073
- * - `"omit"`: omit the value from the output
2122
+ * **Options**
2123
+ *
2124
+ * - `encodingStrategy`:
2125
+ * - `"passthrough"` (default): include the value in the encoded output.
2126
+ * - `"omit"`: omit the key from the encoded output.
2074
2127
  *
2075
2128
  * **Example** (Default for an optional field value)
2076
2129
  *
@@ -2085,7 +2138,8 @@ export function withDecodingDefaultKey(defaultValue, options) {
2085
2138
  * // result: { name: "anonymous" }
2086
2139
  * ```
2087
2140
  *
2088
- * @see {@link withDecodingDefaultKey} for the key-level variant
2141
+ * @see {@link withDecodingDefaultKey} for the key-level variant (key absent only, not `undefined`)
2142
+ * @see {@link withDecodingDefaultType} for the variant where the default is a `Type` value
2089
2143
  * @since 4.0.0
2090
2144
  */
2091
2145
  export function withDecodingDefault(defaultValue, options) {
@@ -2097,6 +2151,30 @@ export function withDecodingDefault(defaultValue, options) {
2097
2151
  }));
2098
2152
  };
2099
2153
  }
2154
+ /**
2155
+ * Wraps the `Encoded` side with `optional` (key absent **or** `undefined`)
2156
+ * and provides a default `Type` value when the field is missing or
2157
+ * `undefined` during decoding.
2158
+ *
2159
+ * Unlike {@link withDecodingDefault}, the default value is specified in terms
2160
+ * of the `Type` (decoded) representation, so it does not need to go through
2161
+ * the decoding transformation.
2162
+ *
2163
+ * **Options**
2164
+ *
2165
+ * - `encodingStrategy`:
2166
+ * - `"passthrough"` (default): include the value in the encoded output.
2167
+ * - `"omit"`: omit the key from the encoded output.
2168
+ *
2169
+ * @see {@link withDecodingDefault} for the variant where the default is an `Encoded` value
2170
+ * @see {@link withDecodingDefaultTypeKey} for the key-level variant
2171
+ * @since 4.0.0
2172
+ */
2173
+ export function withDecodingDefaultType(defaultValue, options) {
2174
+ return self => {
2175
+ return toType(self).pipe(withDecodingDefault(defaultValue, options), encodeTo(optional(self)));
2176
+ };
2177
+ }
2100
2178
  /**
2101
2179
  * Combines a {@link Literal} schema with {@link withConstructorDefault}, making it ideal
2102
2180
  * for discriminator fields in tagged unions. When constructing via `make`, the
@@ -6180,10 +6258,10 @@ function makeClass(Inherited, identifier, struct, annotations, proto) {
6180
6258
  const ClassTypeId = getClassTypeId(identifier); // HMR support
6181
6259
  const out = class extends Inherited {
6182
6260
  constructor(...[input, options]) {
6183
- const props = input ?? {};
6184
- const validated = struct.make(props, options);
6261
+ input = input ?? {};
6262
+ const validated = struct.make(input, options);
6185
6263
  super({
6186
- ...props,
6264
+ ...input,
6187
6265
  ...validated
6188
6266
  }, {
6189
6267
  ...options,
@@ -6209,11 +6287,11 @@ function makeClass(Inherited, identifier, struct, annotations, proto) {
6209
6287
  static make(input, options) {
6210
6288
  return new this(input, options);
6211
6289
  }
6212
- static makeEffect(input, options) {
6213
- return Effect.mapErrorEager(Parser.makeEffect(getClassSchema(this))(input, options), issue => new SchemaError(issue));
6214
- }
6215
6290
  static makeOption(input, options) {
6216
- return Parser.makeOption(getClassSchema(this))(input, options);
6291
+ return Parser.makeOption(getClassSchema(this))(input ?? {}, options);
6292
+ }
6293
+ static makeEffect(input, options) {
6294
+ return Effect.mapErrorEager(Parser.makeEffect(getClassSchema(this))(input ?? {}, options), issue => new SchemaError(issue));
6217
6295
  }
6218
6296
  static annotate(annotations) {
6219
6297
  return this.rebuild(AST.annotate(this.ast, annotations));