@strictly/define 0.0.31 → 0.0.33
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/.out/transformers/copies/copyTo.js +1 -2
- package/.out/transformers/copies/mobxCopy.js +2 -2
- package/.out/transformers/copies/specs/copyTo.tests.js +1 -1
- package/.out/transformers/flatteners/flattenValueTo.d.ts +1 -1
- package/.out/transformers/flatteners/specs/flattenJsonValueToTypePathsOf.tests.js +1 -0
- package/.out/transformers/flatteners/specs/flattenTypeTo.tests.js +3 -1
- package/.out/transformers/flatteners/specs/flattenValueTo.tests.js +1 -0
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/types/builders.js +24 -2
- package/.out/types/flattened.d.ts +1 -1
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/dist/index.cjs +34 -11
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +37 -12
- package/package.json +6 -6
- package/transformers/copies/copyTo.ts +1 -9
- package/transformers/copies/mobxCopy.ts +1 -2
- package/transformers/copies/specs/copyTo.tests.ts +1 -1
- package/transformers/flatteners/flattenValueTo.ts +1 -1
- package/transformers/flatteners/specs/flattenJsonValueToTypePathsOf.tests.ts +1 -0
- package/transformers/flatteners/specs/flattenTypeTo.tests.ts +3 -1
- package/transformers/flatteners/specs/flattenValueTo.tests.ts +1 -0
- package/types/builders.ts +39 -1
- package/types/flattened.ts +1 -1
|
@@ -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
|
-
|
|
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 {
|
|
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
|
|
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;
|
|
@@ -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
|
|
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;
|
|
@@ -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(
|
|
110
|
+
expect(toTypeDefType).toHaveBeenCalledTimes(5);
|
|
109
111
|
});
|
|
110
112
|
});
|
|
111
113
|
});
|