ts-fortress 7.0.0 → 7.0.1
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/compose/intersection.d.mts.map +1 -1
- package/dist/compose/intersection.mjs +20 -2
- package/dist/compose/intersection.mjs.map +1 -1
- package/dist/compose/union.d.mts.map +1 -1
- package/dist/compose/union.mjs +21 -2
- package/dist/compose/union.mjs.map +1 -1
- package/dist/other-types/recursion.d.mts.map +1 -1
- package/dist/other-types/recursion.mjs +47 -2
- package/dist/other-types/recursion.mjs.map +1 -1
- package/dist/record/keyof.mjs +1 -1
- package/dist/record/merge-records.mjs +1 -1
- package/dist/record/valueof.mjs +1 -1
- package/package.json +1 -1
- package/src/compose/intersection.mts +41 -4
- package/src/compose/union.mts +43 -4
- package/src/other-types/recursion.mts +60 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intersection.d.mts","sourceRoot":"","sources":["../../src/compose/intersection.mts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"intersection.d.mts","sourceRoot":"","sources":["../../src/compose/intersection.mts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,IAAI,EACT,KAAK,MAAM,EAEZ,MAAM,aAAa,CAAC;AASrB,eAAO,MAAM,YAAY,GAAI,KAAK,CAAC,KAAK,SAAS,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAC3E,OAAO,KAAK,EACZ,aAAa,gBAAgB,CAAC,KAAK,CAAC,EACpC,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CACH,KACA,gBAAgB,CAAC,KAAK,CAgFxB,CAAC;AAEF,KAAK,gBAAgB,CAAC,KAAK,SAAS,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,IAAI,CACtE,qBAAqB,CAAC,KAAK,CAAC,CAC7B,CAAC;AAEF,KAAK,qBAAqB,CAAC,KAAK,SAAS,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IACnE,kBAAkB,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC;AAEtD,kBAAU,kBAAkB,CAAC;IAC3B,MAAM,MAAM,yBAAyB,CACnC,KAAK,SAAS,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IACxC,YAAY,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE/C,KAAK,KAAK,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,GAClE,CAAC,GACD,KAAK,CAAC;;CACX;AA4BD,KAAK,cAAc,CAAC,KAAK,SAAS,SAAS,IAAI,CAAC,OAAO,CAAC,EAAE,IACxD,kBAAkB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;AAE3C,kBAAU,kBAAkB,CAAC;IAC3B,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,SAAS,OAAO,EAAE,IACzD,KAAK,SAAS,SAAS,EAAE,GACrB,SAAS,EAAE,GACX,KAAK,SAAS,SAAS,CAAC,MAAM,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,GAChD,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,GACvD,KAAK,CAAC;IAGd,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;;CACzD"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Arr, Result } from 'ts-data-forge';
|
|
1
|
+
import { Arr, Obj, Result } from 'ts-data-forge';
|
|
2
|
+
import { hasRecordInternals } from '../type.mjs';
|
|
2
3
|
import { createAssertFn } from '../utils/create-assert-fn.mjs';
|
|
3
4
|
import { createCastFn } from '../utils/create-cast-fn.mjs';
|
|
4
5
|
import { createIsFn } from '../utils/create-is-fn.mjs';
|
|
@@ -34,7 +35,7 @@ const intersection = (types, defaultType, options) => {
|
|
|
34
35
|
};
|
|
35
36
|
const is = createIsFn(validate);
|
|
36
37
|
const fill = (a) => (is(a) ? a : defaultType.fill(a));
|
|
37
|
-
|
|
38
|
+
const baseType = {
|
|
38
39
|
typeName: typeNameFilled,
|
|
39
40
|
defaultValue: defaultType.defaultValue,
|
|
40
41
|
fill,
|
|
@@ -43,6 +44,23 @@ const intersection = (types, defaultType, options) => {
|
|
|
43
44
|
assertIs: createAssertFn(validate),
|
|
44
45
|
cast: createCastFn(validate),
|
|
45
46
|
};
|
|
47
|
+
// If all types are records, add RecordTypeInternals
|
|
48
|
+
if (types.every(hasRecordInternals)) {
|
|
49
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
50
|
+
const recordTypes = types;
|
|
51
|
+
const shapes = Arr.map(recordTypes, (t) => t.shape);
|
|
52
|
+
const mergedShape = Obj.merge(...shapes);
|
|
53
|
+
const excessProperty = recordTypes.some((t) => t.excessProperty === 'reject')
|
|
54
|
+
? 'reject'
|
|
55
|
+
: 'allow';
|
|
56
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
57
|
+
return {
|
|
58
|
+
...baseType,
|
|
59
|
+
shape: mergedShape,
|
|
60
|
+
excessProperty,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return baseType;
|
|
46
64
|
};
|
|
47
65
|
|
|
48
66
|
export { intersection };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intersection.mjs","sources":["../../src/compose/intersection.mts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"intersection.mjs","sources":["../../src/compose/intersection.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAiBO,MAAM,YAAY,GAAG,CAC1B,KAAY,EACZ,WAAoC,EACpC,OAIC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,MAAM,QAAQ,GAAY;AACxB,QAAA,QAAQ,EAAE,cAAc;QACxB,YAAY,EAAE,WAAW,CAAC,YAAY;QACtC,IAAI;QACJ,QAAQ;QACR,EAAE;AACF,QAAA,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;AAClC,QAAA,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC;KACpB;;AAGV,IAAA,IAAI,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE;;QAEnC,MAAM,WAAW,GAAG,KAEnB;AAED,QAAA,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CACpB,WAAW,EACX,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CACmB;QAEnC,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,MAAM,CAAiB;AAExD,QAAA,MAAM,cAAc,GAAyB,WAAW,CAAC,IAAI,CAC3D,CAAC,CAAC,KAAK,CAAC,CAAC,cAAc,KAAK,QAAQ;AAEpC,cAAE;cACA,OAAO;;QAGX,OAAO;AACL,YAAA,GAAG,QAAQ;AACX,YAAA,KAAK,EAAE,WAAW;YAClB,cAAc;SACY;;AAG9B,IAAA,OAAO,QAAmC;AAC5C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union.d.mts","sourceRoot":"","sources":["../../src/compose/union.mts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"union.d.mts","sourceRoot":"","sources":["../../src/compose/union.mts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,IAAI,EACT,KAAK,MAAM,EAEZ,MAAM,aAAa,CAAC;AASrB,eAAO,MAAM,KAAK,GAAI,KAAK,CAAC,KAAK,SAAS,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EACpE,OAAO,KAAK,EACZ,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;CAC/B,CAAC,CACH,KACA,SAAS,CAAC,KAAK,CA4EjB,CAAC;AAEF,KAAK,SAAS,CAAC,KAAK,SAAS,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,IAAI,CAC/D,cAAc,CAAC,KAAK,CAAC,CACtB,CAAC;AAEF,KAAK,cAAc,CAAC,KAAK,SAAS,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAC5D,kBAAkB,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAE/C,kBAAU,kBAAkB,CAAC;IAC3B,MAAM,MAAM,kBAAkB,CAAC,KAAK,SAAS,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IACvE,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IAEnC,KAAK,WAAW,CAAC,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;;CAC7E"}
|
package/dist/compose/union.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { memoizeFunction, Result } from 'ts-data-forge';
|
|
1
|
+
import { memoizeFunction, Arr, Obj, Result } from 'ts-data-forge';
|
|
2
|
+
import { hasRecordInternals } from '../type.mjs';
|
|
2
3
|
import { createAssertFn } from '../utils/create-assert-fn.mjs';
|
|
3
4
|
import { createCastFn } from '../utils/create-cast-fn.mjs';
|
|
4
5
|
import { createIsFn } from '../utils/create-is-fn.mjs';
|
|
@@ -26,7 +27,7 @@ const union = (types, options) => {
|
|
|
26
27
|
]);
|
|
27
28
|
const is = createIsFn(validate);
|
|
28
29
|
const fill = (a) => (is(a) ? a : getDefaultType().fill(a));
|
|
29
|
-
|
|
30
|
+
const baseType = {
|
|
30
31
|
typeName: typeNameFilled,
|
|
31
32
|
get defaultValue() {
|
|
32
33
|
return getDefaultType().defaultValue;
|
|
@@ -37,6 +38,24 @@ const union = (types, options) => {
|
|
|
37
38
|
assertIs: createAssertFn(validate),
|
|
38
39
|
cast: createCastFn(validate),
|
|
39
40
|
};
|
|
41
|
+
// If all types are records, add RecordTypeInternals
|
|
42
|
+
if (types.every(hasRecordInternals)) {
|
|
43
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
44
|
+
const recordTypes = types;
|
|
45
|
+
const shapes = Arr.map(recordTypes, (t) => t.shape);
|
|
46
|
+
// For union, merge all shapes to get all possible keys
|
|
47
|
+
const mergedShape = Obj.merge(...shapes);
|
|
48
|
+
const excessProperty = recordTypes.some((t) => t.excessProperty === 'reject')
|
|
49
|
+
? 'reject'
|
|
50
|
+
: 'allow';
|
|
51
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
52
|
+
return {
|
|
53
|
+
...baseType,
|
|
54
|
+
shape: mergedShape,
|
|
55
|
+
excessProperty,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return baseType;
|
|
40
59
|
};
|
|
41
60
|
|
|
42
61
|
export { union };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union.mjs","sources":["../../src/compose/union.mts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"union.mjs","sources":["../../src/compose/union.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;MAiBa,KAAK,GAAG,CACnB,KAAY,EACZ,OAKC,KACmB;AAGpB,IAAA,MAAM,cAAc,GAAG,eAAe,CACpC;;IAEE,OAAO,EAAE,WAAW,IAAK,KAAK,CAAC,CAAC,CAAsB,CACzD;IAED,MAAM,cAAc,GAClB,OAAO,EAAE,QAAQ,IAAI,CAAA,CAAA,EAAI,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAA,CAAA,CAAG;IAEzE,MAAM,QAAQ,GAAwB,CAAC,CAAC,KACtC,KAAK,CAAC,IAAI,CAAC,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B,WAAW,CAAC,IAAI,CAC3D,CAAC,CAAC,KAAK,CAAC,CAAC,cAAc,KAAK,QAAQ;AAEpC,cAAE;cACA,OAAO;;QAGX,OAAO;AACL,YAAA,GAAG,QAAQ;AACX,YAAA,KAAK,EAAE,WAAW;YAClB,cAAc;SACK;;AAGvB,IAAA,OAAO,QAA4B;AACrC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursion.d.mts","sourceRoot":"","sources":["../../src/other-types/recursion.mts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"recursion.d.mts","sourceRoot":"","sources":["../../src/other-types/recursion.mts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAG5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+IG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,EACzB,UAAU,MAAM,EAChB,YAAY,MAAM,IAAI,CAAC,CAAC,CAAC,EACzB,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,YAAY,EAAE,CAAC,CAAC;CACjB,CAAC,CACH,KACA,IAAI,CAAC,CAAC,CAgFR,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { memoizeFunction } from 'ts-data-forge';
|
|
1
|
+
import { memoizeFunction, isRecord, hasKey } from 'ts-data-forge';
|
|
2
|
+
import { hasRecordInternals } from '../type.mjs';
|
|
2
3
|
import { createAssertFn } from '../utils/create-assert-fn.mjs';
|
|
3
4
|
import { createCastFn } from '../utils/create-cast-fn.mjs';
|
|
4
5
|
import { createIsFn } from '../utils/create-is-fn.mjs';
|
|
@@ -153,7 +154,7 @@ const recursion = (typeName, definition, options) => {
|
|
|
153
154
|
const validate = (a) => getInnerType().validate(a);
|
|
154
155
|
const is = createIsFn(validate);
|
|
155
156
|
const fill = (a) => getInnerType().fill(a);
|
|
156
|
-
|
|
157
|
+
const baseType = {
|
|
157
158
|
typeName,
|
|
158
159
|
get defaultValue() {
|
|
159
160
|
return getDefaultValue();
|
|
@@ -164,6 +165,50 @@ const recursion = (typeName, definition, options) => {
|
|
|
164
165
|
assertIs: createAssertFn(validate),
|
|
165
166
|
cast: createCastFn(validate),
|
|
166
167
|
};
|
|
168
|
+
// Proxy to propagate RecordTypeInternals if the inner type has them
|
|
169
|
+
return new Proxy(baseType, {
|
|
170
|
+
get: (target, prop) => {
|
|
171
|
+
if (prop === 'shape' || prop === 'excessProperty') {
|
|
172
|
+
const inner = getInnerType();
|
|
173
|
+
if (hasRecordInternals(inner)) {
|
|
174
|
+
return inner[prop];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (typeof prop === 'string' &&
|
|
178
|
+
isRecord(target) &&
|
|
179
|
+
hasKey(target, prop)) {
|
|
180
|
+
return target[prop];
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
183
|
+
},
|
|
184
|
+
has: (target, prop) => {
|
|
185
|
+
if (prop === 'shape' || prop === 'excessProperty') {
|
|
186
|
+
const inner = getInnerType();
|
|
187
|
+
return hasRecordInternals(inner);
|
|
188
|
+
}
|
|
189
|
+
return isRecord(target) && hasKey(target, prop);
|
|
190
|
+
},
|
|
191
|
+
ownKeys: (target) => {
|
|
192
|
+
const inner = getInnerType();
|
|
193
|
+
if (hasRecordInternals(inner)) {
|
|
194
|
+
return [...Object.keys(target), 'shape', 'excessProperty'];
|
|
195
|
+
}
|
|
196
|
+
return Object.keys(target);
|
|
197
|
+
},
|
|
198
|
+
getOwnPropertyDescriptor: (target, prop) => {
|
|
199
|
+
if (prop === 'shape' || prop === 'excessProperty') {
|
|
200
|
+
const inner = getInnerType();
|
|
201
|
+
if (hasRecordInternals(inner)) {
|
|
202
|
+
return {
|
|
203
|
+
enumerable: true,
|
|
204
|
+
configurable: true,
|
|
205
|
+
value: inner[prop],
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
210
|
+
},
|
|
211
|
+
});
|
|
167
212
|
};
|
|
168
213
|
|
|
169
214
|
export { recursion };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursion.mjs","sources":["../../src/other-types/recursion.mts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"recursion.mjs","sources":["../../src/other-types/recursion.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+IG;AACI,MAAM,SAAS,GAAG,CACvB,QAAgB,EAChB,UAAyB,EACzB,OAIC,KACU;AACX,IAAA,MAAM,eAAe,GAAG,eAAe,CACrC,MAAS,OAAO,EAAE,YAAY,IAAI,YAAY,EAAE,CAAC,YAAY,CAC9D;AAED,IAAA,MAAM,YAAY,GAAkB,eAAe,CAAC,UAAU,CAAC;AAE/D,IAAA,MAAM,QAAQ,GAAwB,CAAC,CAAC,KAAK,YAAY,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEvE,IAAA,MAAM,EAAE,GAAG,UAAU,CAAI,QAAQ,CAAC;AAElC,IAAA,MAAM,IAAI,GAAoB,CAAC,CAAC,KAAK,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AAE3D,IAAA,MAAM,QAAQ,GAAY;QACxB,QAAQ;AACR,QAAA,IAAI,YAAY,GAAA;YACd,OAAO,eAAe,EAAE;QAC1B,CAAC;QACD,IAAI;QACJ,QAAQ;QACR,EAAE;AACF,QAAA,QAAQ,EAAE,cAAc,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AAwB,EAAE,CAAC,MAAM,EAAE,IAAI,KAAI;YACzC,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,gBAAgB,EAAE;AACjD,gBAAA,MAAM,KAAK,GAAG,YAAY,EAAE;AAE5B,gBAAA,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE;oBAC7B,OAAO;AACL,wBAAA,UAAU,EAAE,IAAI;AAChB,wBAAA,YAAY,EAAE,IAAI;AAClB,wBAAA,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC;qBACnB;gBACH;YACF;YAEA,OAAO,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,CAAC;QACtD,CAAC;AACF,KAAA,CAAC;AACJ;;;;"}
|
package/dist/record/keyof.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { pipe, Arr } from 'ts-data-forge';
|
|
2
2
|
import { enumType } from '../enum/enum.mjs';
|
|
3
3
|
import '@sindresorhus/is';
|
|
4
|
+
import { hasRecordInternals } from '../type.mjs';
|
|
4
5
|
import '../other-types/unknown.mjs';
|
|
5
6
|
import { undefinedType } from '../primitives/undefined.mjs';
|
|
6
|
-
import { hasRecordInternals } from '../type.mjs';
|
|
7
7
|
|
|
8
8
|
const keyof = (recordType, options) => {
|
|
9
9
|
if (!hasRecordInternals(recordType)) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Arr, Obj } from 'ts-data-forge';
|
|
2
2
|
import { toIntersectionString } from '../utils/to-union-string.mjs';
|
|
3
3
|
import '@sindresorhus/is';
|
|
4
|
-
import '../other-types/unknown.mjs';
|
|
5
4
|
import { hasRecordInternals } from '../type.mjs';
|
|
5
|
+
import '../other-types/unknown.mjs';
|
|
6
6
|
import { record } from './record.mjs';
|
|
7
7
|
|
|
8
8
|
const mergeRecords = (recordTypes, options) => {
|
package/dist/record/valueof.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Arr } from 'ts-data-forge';
|
|
2
|
+
import { hasRecordInternals } from '../type.mjs';
|
|
2
3
|
import { union } from '../compose/union.mjs';
|
|
3
4
|
import '@sindresorhus/is';
|
|
4
5
|
import '../other-types/unknown.mjs';
|
|
5
6
|
import { undefinedType } from '../primitives/undefined.mjs';
|
|
6
|
-
import { hasRecordInternals } from '../type.mjs';
|
|
7
7
|
|
|
8
8
|
const valueof = (recordType, options) => {
|
|
9
9
|
if (!hasRecordInternals(recordType)) {
|
package/package.json
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { Arr, expectType, Result } from 'ts-data-forge';
|
|
2
|
-
import {
|
|
1
|
+
import { Arr, expectType, Obj, Result } from 'ts-data-forge';
|
|
2
|
+
import {
|
|
3
|
+
type ExcessPropertyOption,
|
|
4
|
+
hasRecordInternals,
|
|
5
|
+
type RecordTypeInternals,
|
|
6
|
+
type Type,
|
|
7
|
+
type TypeOf,
|
|
8
|
+
type UnknownShape,
|
|
9
|
+
} from '../type.mjs';
|
|
3
10
|
import {
|
|
4
11
|
createAssertFn,
|
|
5
12
|
createCastFn,
|
|
@@ -57,7 +64,7 @@ export const intersection = <const Types extends NonEmptyArray<Type<unknown>>>(
|
|
|
57
64
|
|
|
58
65
|
const fill: Type<T>['fill'] = (a) => (is(a) ? a : defaultType.fill(a));
|
|
59
66
|
|
|
60
|
-
|
|
67
|
+
const baseType: Type<T> = {
|
|
61
68
|
typeName: typeNameFilled,
|
|
62
69
|
defaultValue: defaultType.defaultValue,
|
|
63
70
|
fill,
|
|
@@ -65,7 +72,37 @@ export const intersection = <const Types extends NonEmptyArray<Type<unknown>>>(
|
|
|
65
72
|
is,
|
|
66
73
|
assertIs: createAssertFn(validate),
|
|
67
74
|
cast: createCastFn(validate),
|
|
68
|
-
};
|
|
75
|
+
} as const;
|
|
76
|
+
|
|
77
|
+
// If all types are records, add RecordTypeInternals
|
|
78
|
+
if (types.every(hasRecordInternals)) {
|
|
79
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
80
|
+
const recordTypes = types as unknown as NonEmptyArray<
|
|
81
|
+
Type<unknown> & RecordTypeInternals
|
|
82
|
+
>;
|
|
83
|
+
|
|
84
|
+
const shapes = Arr.map(
|
|
85
|
+
recordTypes,
|
|
86
|
+
(t) => t.shape,
|
|
87
|
+
) satisfies readonly UnknownShape[];
|
|
88
|
+
|
|
89
|
+
const mergedShape = Obj.merge(...shapes) as UnknownShape;
|
|
90
|
+
|
|
91
|
+
const excessProperty: ExcessPropertyOption = recordTypes.some(
|
|
92
|
+
(t) => t.excessProperty === 'reject',
|
|
93
|
+
)
|
|
94
|
+
? 'reject'
|
|
95
|
+
: 'allow';
|
|
96
|
+
|
|
97
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
98
|
+
return {
|
|
99
|
+
...baseType,
|
|
100
|
+
shape: mergedShape,
|
|
101
|
+
excessProperty,
|
|
102
|
+
} as IntersectionType<Types>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return baseType as IntersectionType<Types>;
|
|
69
106
|
};
|
|
70
107
|
|
|
71
108
|
type IntersectionType<Types extends NonEmptyArray<Type<unknown>>> = Type<
|
package/src/compose/union.mts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { Result, expectType, memoizeFunction } from 'ts-data-forge';
|
|
2
|
-
import {
|
|
1
|
+
import { Arr, Obj, Result, expectType, memoizeFunction } from 'ts-data-forge';
|
|
2
|
+
import {
|
|
3
|
+
hasRecordInternals,
|
|
4
|
+
type ExcessPropertyOption,
|
|
5
|
+
type RecordTypeInternals,
|
|
6
|
+
type Type,
|
|
7
|
+
type TypeOf,
|
|
8
|
+
type UnknownShape,
|
|
9
|
+
} from '../type.mjs';
|
|
3
10
|
import {
|
|
4
11
|
createAssertFn,
|
|
5
12
|
createCastFn,
|
|
@@ -49,7 +56,7 @@ export const union = <const Types extends NonEmptyArray<Type<unknown>>>(
|
|
|
49
56
|
|
|
50
57
|
const fill: Type<T>['fill'] = (a) => (is(a) ? a : getDefaultType().fill(a));
|
|
51
58
|
|
|
52
|
-
|
|
59
|
+
const baseType: Type<T> = {
|
|
53
60
|
typeName: typeNameFilled,
|
|
54
61
|
get defaultValue() {
|
|
55
62
|
return getDefaultType().defaultValue;
|
|
@@ -59,7 +66,39 @@ export const union = <const Types extends NonEmptyArray<Type<unknown>>>(
|
|
|
59
66
|
is,
|
|
60
67
|
assertIs: createAssertFn(validate),
|
|
61
68
|
cast: createCastFn(validate),
|
|
62
|
-
};
|
|
69
|
+
} as const;
|
|
70
|
+
|
|
71
|
+
// If all types are records, add RecordTypeInternals
|
|
72
|
+
if (types.every(hasRecordInternals)) {
|
|
73
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
74
|
+
const recordTypes = types as unknown as NonEmptyArray<
|
|
75
|
+
Type<unknown> & RecordTypeInternals
|
|
76
|
+
>;
|
|
77
|
+
|
|
78
|
+
const shapes = Arr.map(
|
|
79
|
+
recordTypes,
|
|
80
|
+
(t) => t.shape,
|
|
81
|
+
) satisfies readonly UnknownShape[];
|
|
82
|
+
|
|
83
|
+
// For union, merge all shapes to get all possible keys
|
|
84
|
+
|
|
85
|
+
const mergedShape = Obj.merge(...shapes) as UnknownShape;
|
|
86
|
+
|
|
87
|
+
const excessProperty: ExcessPropertyOption = recordTypes.some(
|
|
88
|
+
(t) => t.excessProperty === 'reject',
|
|
89
|
+
)
|
|
90
|
+
? 'reject'
|
|
91
|
+
: 'allow';
|
|
92
|
+
|
|
93
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
94
|
+
return {
|
|
95
|
+
...baseType,
|
|
96
|
+
shape: mergedShape,
|
|
97
|
+
excessProperty,
|
|
98
|
+
} as UnionType<Types>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return baseType as UnionType<Types>;
|
|
63
102
|
};
|
|
64
103
|
|
|
65
104
|
type UnionType<Types extends NonEmptyArray<Type<unknown>>> = Type<
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { memoizeFunction } from 'ts-data-forge';
|
|
2
|
-
import { type Type } from '../type.mjs';
|
|
1
|
+
import { hasKey, isRecord, memoizeFunction } from 'ts-data-forge';
|
|
2
|
+
import { hasRecordInternals, type Type } from '../type.mjs';
|
|
3
3
|
import { createAssertFn, createCastFn, createIsFn } from '../utils/index.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -167,7 +167,7 @@ export const recursion = <A,>(
|
|
|
167
167
|
|
|
168
168
|
const fill: Type<A>['fill'] = (a) => getInnerType().fill(a);
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
const baseType: Type<A> = {
|
|
171
171
|
typeName,
|
|
172
172
|
get defaultValue(): A {
|
|
173
173
|
return getDefaultValue();
|
|
@@ -177,5 +177,61 @@ export const recursion = <A,>(
|
|
|
177
177
|
is,
|
|
178
178
|
assertIs: createAssertFn(validate),
|
|
179
179
|
cast: createCastFn(validate),
|
|
180
|
-
};
|
|
180
|
+
} as const;
|
|
181
|
+
|
|
182
|
+
// Proxy to propagate RecordTypeInternals if the inner type has them
|
|
183
|
+
return new Proxy(baseType, {
|
|
184
|
+
get: (target, prop) => {
|
|
185
|
+
if (prop === 'shape' || prop === 'excessProperty') {
|
|
186
|
+
const inner = getInnerType();
|
|
187
|
+
|
|
188
|
+
if (hasRecordInternals(inner)) {
|
|
189
|
+
return inner[prop];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (
|
|
194
|
+
typeof prop === 'string' &&
|
|
195
|
+
isRecord(target) &&
|
|
196
|
+
hasKey(target, prop)
|
|
197
|
+
) {
|
|
198
|
+
return target[prop as keyof typeof target];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return undefined;
|
|
202
|
+
},
|
|
203
|
+
has: (target, prop) => {
|
|
204
|
+
if (prop === 'shape' || prop === 'excessProperty') {
|
|
205
|
+
const inner = getInnerType();
|
|
206
|
+
|
|
207
|
+
return hasRecordInternals(inner);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return isRecord(target) && hasKey(target, prop);
|
|
211
|
+
},
|
|
212
|
+
ownKeys: (target) => {
|
|
213
|
+
const inner = getInnerType();
|
|
214
|
+
|
|
215
|
+
if (hasRecordInternals(inner)) {
|
|
216
|
+
return [...Object.keys(target), 'shape', 'excessProperty'];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return Object.keys(target);
|
|
220
|
+
},
|
|
221
|
+
getOwnPropertyDescriptor: (target, prop) => {
|
|
222
|
+
if (prop === 'shape' || prop === 'excessProperty') {
|
|
223
|
+
const inner = getInnerType();
|
|
224
|
+
|
|
225
|
+
if (hasRecordInternals(inner)) {
|
|
226
|
+
return {
|
|
227
|
+
enumerable: true,
|
|
228
|
+
configurable: true,
|
|
229
|
+
value: inner[prop],
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
235
|
+
},
|
|
236
|
+
});
|
|
181
237
|
};
|