effect 4.0.0-beta.15 → 4.0.0-beta.17

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/Schema.js CHANGED
@@ -785,11 +785,12 @@ export function encodeKeys(mapping) {
785
785
  const fields = {};
786
786
  const reverseMapping = {};
787
787
  for (const k in self.fields) {
788
+ const encoded = toEncoded(self.fields[k]);
788
789
  if (Object.hasOwn(mapping, k)) {
789
- fields[mapping[k]] = toEncoded(self.fields[k]);
790
+ fields[mapping[k]] = encoded;
790
791
  reverseMapping[mapping[k]] = k;
791
792
  } else {
792
- fields[k] = self.fields[k];
793
+ fields[k] = encoded;
793
794
  }
794
795
  }
795
796
  return Struct(fields).pipe(decodeTo(self, Transformation.transform({
@@ -3096,6 +3097,40 @@ export function Option(value) {
3096
3097
  export function OptionFromNullOr(schema) {
3097
3098
  return NullOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromNullOr()));
3098
3099
  }
3100
+ /**
3101
+ * Decodes an undefined-or value `T` to a required `Option<T>` value.
3102
+ *
3103
+ * Decoding:
3104
+ * - `undefined` is decoded as `None`
3105
+ * - other values are decoded as `Some`
3106
+ *
3107
+ * Encoding:
3108
+ * - `None` is encoded as `undefined`
3109
+ * - `Some` is encoded as the value
3110
+ *
3111
+ * @category Option
3112
+ * @since 4.0.0
3113
+ */
3114
+ export function OptionFromUndefinedOr(schema) {
3115
+ return UndefinedOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromUndefinedOr()));
3116
+ }
3117
+ /**
3118
+ * Decodes a nullish value `T` to a required `Option<T>` value.
3119
+ *
3120
+ * Decoding:
3121
+ * - `null` and `undefined` are decoded as `None`
3122
+ * - other values are decoded as `Some`
3123
+ *
3124
+ * Encoding:
3125
+ * - `None` is encoded as `null` or `undefined` depending on the provided `options.onNoneEncoding` (defaults to `undefined`)
3126
+ * - `Some` is encoded as the value
3127
+ *
3128
+ * @category Option
3129
+ * @since 4.0.0
3130
+ */
3131
+ export function OptionFromNullishOr(schema, options) {
3132
+ return NullishOr(schema).pipe(decodeTo(Option(toType(schema)), Transformation.optionFromNullishOr(options)));
3133
+ }
3099
3134
  /**
3100
3135
  * Decodes an optional value `A` to a required `Option<A>` value.
3101
3136
  *
@@ -4811,6 +4846,9 @@ function makeClass(Inherited, identifier, struct, annotations) {
4811
4846
  static makeUnsafe(input, options) {
4812
4847
  return new this(input, options);
4813
4848
  }
4849
+ static makeOption(input, options) {
4850
+ return Parser.makeOption(getClassSchema(this))(input, options);
4851
+ }
4814
4852
  static annotate(annotations) {
4815
4853
  return this.rebuild(AST.annotate(this.ast, annotations));
4816
4854
  }