@strictly/define 0.0.31 → 0.0.32

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.
@@ -68,8 +68,7 @@ function copyUnion(typeDef, value, copier) {
68
68
  // is it a discriminated union with a struct?
69
69
  if (discriminator != null) {
70
70
  const discriminatorValue = value[discriminator];
71
- const discriminatingUnion = Object.assign(Object.assign({}, internalCopyTo(unions[discriminatorValue], value, copier)), { [discriminator]: discriminatorValue });
72
- return copier(discriminatingUnion, typeDef);
71
+ return internalCopyTo(unions[discriminatorValue], value, copier);
73
72
  }
74
73
  // is it a `<constant1> | <constant2> | X`? We can handle that
75
74
  // a good example is when we `| null` something
@@ -1,5 +1,5 @@
1
1
  import { reduce, UnreachableError, } from '@strictly/base';
2
- import { makeObservable, observable, } from 'mobx';
2
+ import { observable, } from 'mobx';
3
3
  import { getUnionTypeDef } from 'transformers/flatteners/flattenValueTo';
4
4
  import { TypeDefType, } from 'types/Type';
5
5
  import { copyTo, } from './copyTo';
@@ -21,7 +21,7 @@ function observeValue(v, def) {
21
21
  });
22
22
  case TypeDefType.Object:
23
23
  // `makeObservable` only observes the specified props
24
- return makeObservable(v, reduce(def.fields, function (acc, k) {
24
+ return observable(v, reduce(def.fields, function (acc, k) {
25
25
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
26
26
  acc[k] = observable;
27
27
  return acc;
@@ -88,7 +88,7 @@ describe('copyTo', function () {
88
88
  x: 1,
89
89
  }, toString);
90
90
  expect(c).toEqual({
91
- d: 'a',
91
+ d: '"a"',
92
92
  x: '1',
93
93
  });
94
94
  });
@@ -5,7 +5,7 @@ import { type ValueOfType } from 'types/ValueOfType';
5
5
  export type AnyValueType = any;
6
6
  export type Setter<V> = (v: V) => void;
7
7
  export type Mapper<R> = (t: StrictTypeDef, v: AnyValueType, setter: Setter<AnyValueType>, typePath: string, valuePath: string) => R;
8
- export declare function flattenValueTo<T extends StrictType, M, R extends Readonly<Record<string, M>>>({ definition }: T, v: ValueOfType<T>, setter: Setter<ValueOfType<T>>, mapper: Mapper<M>, listIndicesToKeys?: Record<string, number[]>): R;
8
+ export declare function flattenValueTo<T extends StrictType, M, R extends Readonly<Record<string, M>>>({ definition }: T, v: ValueOfType<ReadonlyTypeOfType<T>>, setter: Setter<ValueOfType<T>>, mapper: Mapper<M>, listIndicesToKeys?: Record<string, number[]>): R;
9
9
  export declare function getUnionTypeDef<T extends UnionTypeDef>(typeDef: T, v: ValueOfType<ReadonlyTypeOfType<{
10
10
  definition: T;
11
11
  }>>): any;
@@ -87,6 +87,7 @@ describe('flattenJsonValueToTypePathsOf', function () {
87
87
  $: '$',
88
88
  '$:x.a': '$:x.a',
89
89
  '$:x.b': '$:x.b',
90
+ '$:x.d': '$:x.d',
90
91
  });
91
92
  });
92
93
  });
@@ -101,11 +101,13 @@ describe('flattenTypeDefTo', function () {
101
101
  expect(flattened).toEqual({
102
102
  $: TypeDefType.Union,
103
103
  '$:a.a': TypeDefType.Literal,
104
+ '$:a.d': TypeDefType.Literal,
104
105
  '$:b.b': TypeDefType.Literal,
106
+ '$:b.d': TypeDefType.Literal,
105
107
  });
106
108
  });
107
109
  it('calls the mapper function', function () {
108
- expect(toTypeDefType).toHaveBeenCalledTimes(3);
110
+ expect(toTypeDefType).toHaveBeenCalledTimes(5);
109
111
  });
110
112
  });
111
113
  });
@@ -210,6 +210,7 @@ describe('flattenValueTo', function () {
210
210
  expect(flattened).toEqual({
211
211
  $: '{"d":"1","a":2}',
212
212
  ['$:1.a']: '2',
213
+ ['$:1.d']: '"1"',
213
214
  });
214
215
  });
215
216
  });