ts-fortress 3.2.0 → 4.0.0

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 (49) hide show
  1. package/dist/entry-point.mjs +1 -0
  2. package/dist/entry-point.mjs.map +1 -1
  3. package/dist/index.mjs +2 -0
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/record/keyof.d.mts +4 -3
  6. package/dist/record/keyof.d.mts.map +1 -1
  7. package/dist/record/keyof.mjs +5 -1
  8. package/dist/record/keyof.mjs.map +1 -1
  9. package/dist/record/omit.d.mts +5 -4
  10. package/dist/record/omit.d.mts.map +1 -1
  11. package/dist/record/omit.mjs +8 -39
  12. package/dist/record/omit.mjs.map +1 -1
  13. package/dist/record/partial.d.mts +13 -4
  14. package/dist/record/partial.d.mts.map +1 -1
  15. package/dist/record/partial.mjs +11 -118
  16. package/dist/record/partial.mjs.map +1 -1
  17. package/dist/record/pick.d.mts +5 -4
  18. package/dist/record/pick.d.mts.map +1 -1
  19. package/dist/record/pick.mjs +8 -39
  20. package/dist/record/pick.mjs.map +1 -1
  21. package/dist/record/record.d.mts +4 -24
  22. package/dist/record/record.d.mts.map +1 -1
  23. package/dist/record/record.mjs +9 -7
  24. package/dist/record/record.mjs.map +1 -1
  25. package/dist/type.d.mts +25 -1
  26. package/dist/type.d.mts.map +1 -1
  27. package/dist/type.mjs +1 -1
  28. package/dist/utils/index.d.mts +1 -0
  29. package/dist/utils/index.d.mts.map +1 -1
  30. package/dist/utils/index.mjs +1 -0
  31. package/dist/utils/index.mjs.map +1 -1
  32. package/dist/utils/to-union-string.d.mts +2 -0
  33. package/dist/utils/to-union-string.d.mts.map +1 -0
  34. package/dist/utils/to-union-string.mjs +4 -0
  35. package/dist/utils/to-union-string.mjs.map +1 -0
  36. package/package.json +1 -1
  37. package/src/record/keyof.mts +34 -12
  38. package/src/record/omit.mts +37 -70
  39. package/src/record/omit.test.mts +8 -1
  40. package/src/record/partial.mts +165 -156
  41. package/src/record/partial.test.mts +44 -4
  42. package/src/record/pick.mts +37 -73
  43. package/src/record/pick.test.mts +8 -1
  44. package/src/record/record-strict-composition.test.mts +16 -16
  45. package/src/record/record.mts +17 -48
  46. package/src/record/record.test.mts +9 -1
  47. package/src/type.mts +54 -2
  48. package/src/utils/index.mts +1 -0
  49. package/src/utils/to-union-string.mts +2 -0
@@ -57,5 +57,6 @@ export { createCastFn } from './utils/create-cast-fn.mjs';
57
57
  export { createIsFn } from './utils/create-is-fn.mjs';
58
58
  export { createPrimitiveType } from './utils/create-primitive-type.mjs';
59
59
  export { createType } from './utils/create-type.mjs';
60
+ export { toUnionString } from './utils/to-union-string.mjs';
60
61
  export { createPrimitiveValidationError, prependIndexToValidationErrors, prependPathToValidationErrors, validationErrorToMessage, validationErrorsToMessages } from './utils/validation-error.mjs';
61
62
  //# sourceMappingURL=entry-point.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"entry-point.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"entry-point.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -51,10 +51,12 @@ export { isOptionalProperty, optional } from './record/optional.mjs';
51
51
  export { partial } from './record/partial.mjs';
52
52
  export { pick } from './record/pick.mjs';
53
53
  export { record, strictRecord } from './record/record.mjs';
54
+ import 'ts-data-forge';
54
55
  export { createAssertFn } from './utils/create-assert-fn.mjs';
55
56
  export { createCastFn } from './utils/create-cast-fn.mjs';
56
57
  export { createIsFn } from './utils/create-is-fn.mjs';
57
58
  export { createPrimitiveType } from './utils/create-primitive-type.mjs';
58
59
  export { createType } from './utils/create-type.mjs';
60
+ export { toUnionString } from './utils/to-union-string.mjs';
59
61
  export { createPrimitiveValidationError, prependIndexToValidationErrors, prependPathToValidationErrors, validationErrorToMessage, validationErrorsToMessages } from './utils/validation-error.mjs';
60
62
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,7 +1,8 @@
1
- import { type Type, type TypeOf } from '../type.mjs';
2
- export declare const keyof: <const R extends Type<UnknownRecord>>(recordType: R, options?: Partial<Readonly<{
1
+ import { type RecordType, type Type } from '../type.mjs';
2
+ export declare const keyof: <const R extends ReadonlyRecord<string, Type<unknown>>>(recordType: RecordType<R>, options?: Partial<Readonly<{
3
3
  typeName: string;
4
4
  }>>) => KeyofType<R>;
5
- type KeyofType<R extends Type<UnknownRecord>> = Type<ToString<keyof TypeOf<R>>>;
5
+ type KeyofTypeSub<R extends ReadonlyRecord<string, Type<unknown>>> = Type<ToString<keyof R>>;
6
+ type KeyofType<R extends ReadonlyRecord<string, Type<unknown>>> = IsNever<keyof R> extends true ? Type<undefined> : KeyofTypeSub<R>;
6
7
  export {};
7
8
  //# sourceMappingURL=keyof.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keyof.d.mts","sourceRoot":"","sources":["../../src/record/keyof.mts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAErD,eAAO,MAAM,KAAK,GAAI,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,EACvD,YAAY,CAAC,EACb,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CACH,KACA,SAAS,CAAC,CAAC,CAQW,CAAC;AAE1B,KAAK,SAAS,CAAC,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"keyof.d.mts","sourceRoot":"","sources":["../../src/record/keyof.mts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAEzD,eAAO,MAAM,KAAK,GAAI,KAAK,CAAC,CAAC,SAAS,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,EACzE,YAAY,UAAU,CAAC,CAAC,CAAC,EACzB,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CACH,KACA,SAAS,CAAC,CAAC,CAQW,CAAC;AAQ1B,KAAK,YAAY,CAAC,CAAC,SAAS,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,IAAI,CACvE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAClB,CAAC;AAEF,KAAK,SAAS,CAAC,CAAC,SAAS,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,IAC5D,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC"}
@@ -4,11 +4,15 @@ import { undefinedType } from '../primitives/undefined.mjs';
4
4
 
5
5
  const keyof = (recordType, options) =>
6
6
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
7
- pipe(Object.keys(recordType.defaultValue)).map((keys) => Arr.isNonEmpty(keys)
7
+ pipe(getKeys(recordType)).map((keys) => Arr.isNonEmpty(keys)
8
8
  ? enumType(keys, {
9
9
  typeName: options?.typeName ?? `keyof ${recordType.typeName}`,
10
10
  })
11
11
  : undefinedType).value;
12
+ const getKeys = (recordType) =>
13
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
14
+ Object.keys(recordType.shape);
15
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
12
16
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
13
17
 
14
18
  export { keyof };
@@ -1 +1 @@
1
- {"version":3,"file":"keyof.mjs","sources":["../../src/record/keyof.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;MAKa,KAAK,GAAG,CACnB,UAAa,EACb,OAIC;AAED;AACA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,KAClD,GAAG,CAAC,UAAU,CAAC,IAAI;AACjB,MAAE,QAAQ,CAAC,IAAI,EAAE;QACb,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,CAAA,MAAA,EAAS,UAAU,CAAC,QAAQ,CAAA,CAAE;KAC9D;AACH,MAAE,aAAa,CAClB,CAAC;AAIJ;;;;"}
1
+ {"version":3,"file":"keyof.mjs","sources":["../../src/record/keyof.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;MAKa,KAAK,GAAG,CACnB,UAAyB,EACzB,OAIC;AAED;AACA,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,KACjC,GAAG,CAAC,UAAU,CAAC,IAAI;AACjB,MAAG,QAAQ,CAAC,IAAI,EAAE;QACd,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,CAAA,MAAA,EAAS,UAAU,CAAC,QAAQ,CAAA,CAAE;KAC9D;AACH,MAAG,aAAwC,CAC9C,CAAC;AAEJ,MAAM,OAAO,GAAG,CACd,UAAyB;AAEzB;AACA,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAA2C;AASzE;AAIA;;;;"}
@@ -1,8 +1,9 @@
1
- import { type Type, type TypeOf } from '../type.mjs';
1
+ import { type RecordType, type Type } from '../type.mjs';
2
2
  /** Creates a record type with keys omitted. */
3
- export declare const omit: <const R extends Type<UnknownRecord>, const KeysToOmit extends readonly (keyof TypeOf<R> & string)[]>(recordType: R, keysToOmit: KeysToOmit, options?: Partial<Readonly<{
3
+ export declare const omit: <const R extends ReadonlyRecord<string, Type<unknown>>, const KeysToOmit extends readonly (keyof R & string)[]>(recordType: RecordType<R>, keysToOmit: KeysToOmit, options?: Partial<Readonly<{
4
4
  typeName: string;
5
+ /** @default true */
6
+ allowExcessProperties: boolean;
5
7
  }>>) => OmittedType<R, KeysToOmit>;
6
- type OmittedType<R extends Type<UnknownRecord>, KeysToOmit extends readonly (keyof TypeOf<R>)[]> = Type<Omit<TypeOf<R>, ArrayElement<KeysToOmit>>>;
7
- export {};
8
+ export type OmittedType<R extends ReadonlyRecord<string, Type<unknown>>, KeysToOmit extends readonly (keyof R)[]> = RecordType<Omit<R, ArrayElement<KeysToOmit>>>;
8
9
  //# sourceMappingURL=omit.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"omit.d.mts","sourceRoot":"","sources":["../../src/record/omit.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAQrD,+CAA+C;AAC/C,eAAO,MAAM,IAAI,GACf,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,EACnC,KAAK,CAAC,UAAU,SAAS,SAAS,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE,EAE9D,YAAY,CAAC,EACb,YAAY,UAAU,EACtB,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CACH,KACA,WAAW,CAAC,CAAC,EAAE,UAAU,CA2C3B,CAAC;AAEF,KAAK,WAAW,CACd,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,EAC7B,UAAU,SAAS,SAAS,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,IAC7C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"omit.d.mts","sourceRoot":"","sources":["../../src/record/omit.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAIzD,+CAA+C;AAC/C,eAAO,MAAM,IAAI,GACf,KAAK,CAAC,CAAC,SAAS,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,EACrD,KAAK,CAAC,UAAU,SAAS,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,EAEtD,YAAY,UAAU,CAAC,CAAC,CAAC,EACzB,YAAY,UAAU,EACtB,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IAEjB,oBAAoB;IACpB,qBAAqB,EAAE,OAAO,CAAC;CAChC,CAAC,CACH,KACA,WAAW,CAAC,CAAC,EAAE,UAAU,CAOxB,CAAC;AAEL,MAAM,MAAM,WAAW,CACrB,CAAC,SAAS,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,EAC/C,UAAU,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,IACrC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC"}
@@ -1,44 +1,13 @@
1
- import { Obj, isRecord, Result } from 'ts-data-forge';
2
- import { createAssertFn } from '../utils/create-assert-fn.mjs';
3
- import { createCastFn } from '../utils/create-cast-fn.mjs';
4
- import { createIsFn } from '../utils/create-is-fn.mjs';
5
- import { createPrimitiveValidationError } from '../utils/validation-error.mjs';
1
+ import { Obj } from 'ts-data-forge';
2
+ import { toUnionString } from '../utils/to-union-string.mjs';
3
+ import { record } from './record.mjs';
6
4
 
7
5
  /** Creates a record type with keys omitted. */
8
- const omit = (recordType, keysToOmit, options) => {
9
- const typeNameFilled = options?.typeName ??
10
- `Omit<${recordType.typeName}, ${keysToOmit.join('|')}>`;
11
- const defaultValue = Obj.omit(recordType.defaultValue, keysToOmit);
12
- const validate = (a) => {
13
- if (!isRecord(a)) {
14
- return Result.err([
15
- createPrimitiveValidationError({
16
- actualValue: a,
17
- expectedType: 'record',
18
- typeName: typeNameFilled,
19
- }),
20
- ]);
21
- }
22
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
23
- const objectFilled = {
24
- ...Obj.pick(recordType.fill(a), keysToOmit),
25
- ...a,
26
- };
27
- const baseValidationResult = recordType.validate(objectFilled);
28
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
29
- return Result.map(baseValidationResult, () => a);
30
- };
31
- const fill = (a) => Obj.omit(recordType.fill(a), keysToOmit);
32
- return {
33
- typeName: typeNameFilled,
34
- defaultValue,
35
- fill,
36
- validate,
37
- is: createIsFn(validate),
38
- assertIs: createAssertFn(validate),
39
- cast: createCastFn(validate),
40
- };
41
- };
6
+ const omit = (recordType, keysToOmit, options) => record(Obj.omit(recordType.shape, keysToOmit), {
7
+ typeName: options?.typeName ??
8
+ `Omit<${recordType.typeName}, ${toUnionString(keysToOmit)}>`,
9
+ allowExcessProperties: options?.allowExcessProperties ?? recordType.allowExcessProperties,
10
+ });
42
11
 
43
12
  export { omit };
44
13
  //# sourceMappingURL=omit.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"omit.mjs","sources":["../../src/record/omit.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AASA;AACO,MAAM,IAAI,GAAG,CAIlB,UAAa,EACb,UAAsB,EACtB,OAIC,KAC6B;AAG9B,IAAA,MAAM,cAAc,GAClB,OAAO,EAAE,QAAQ;QACjB,CAAA,KAAA,EAAQ,UAAU,CAAC,QAAQ,CAAA,EAAA,EAA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CAIlB,UAAyB,EACzB,UAAsB,EACtB,OAOC,KAED,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE;IAC7C,QAAQ,EACN,OAAO,EAAE,QAAQ;QACjB,CAAA,KAAA,EAAQ,UAAU,CAAC,QAAQ,CAAA,EAAA,EAAK,aAAa,CAAC,UAAU,CAAC,CAAA,CAAA,CAAG;AAC9D,IAAA,qBAAqB,EACnB,OAAO,EAAE,qBAAqB,IAAI,UAAU,CAAC,qBAAqB;AACrE,CAAA;;;;"}
@@ -1,13 +1,22 @@
1
- import { type Type, type TypeOf } from '../type.mjs';
1
+ import { type RecordType, type Type } from '../type.mjs';
2
+ import { type OptionalPropertyType } from './optional.mjs';
2
3
  /**
3
4
  * Creates a Partial type. If keysToBeOptional is set, only those keys are
4
5
  * optional, otherwise, all properties are optional.
5
6
  */
6
- export declare const partial: <const R extends Type<UnknownRecord>, const KeysToBeOptional extends NonEmptyArray<keyof TypeOf<R> & string>>(recordType: R, options?: Partial<Readonly<{
7
+ export declare const partial: <const R extends ReadonlyRecord<string, Type<unknown>>, const KeysToBeOptional extends NonEmptyArray<keyof R & string>>(recordType: RecordType<R>, options?: Partial<Readonly<{
7
8
  keysToBeOptional: KeysToBeOptional;
8
9
  typeName: string;
10
+ /** @default true */
11
+ allowExcessProperties: boolean;
9
12
  }>>) => PartialType<R, KeysToBeOptional>;
10
- type PartialTypeValue<R extends Type<UnknownRecord>, KeysToBeOptional extends NonEmptyArray<keyof TypeOf<R> & string> | undefined> = TypeEq<KeysToBeOptional, undefined> extends true ? Partial<TypeOf<R>> : PartiallyPartial<TypeOf<R>, ArrayElement<KeysToBeOptional>>;
11
- type PartialType<R extends Type<UnknownRecord>, KeysToBeOptional extends NonEmptyArray<keyof TypeOf<R> & string> | undefined> = Type<PartialTypeValue<R, KeysToBeOptional>>;
13
+ type PartialTypeShape<R extends ReadonlyRecord<string, Type<unknown>>, KeysToBeOptional extends NonEmptyArray<keyof R & string> | undefined> = TypeEq<KeysToBeOptional, undefined> extends true ? FullyOptionalType<R> : PartiallyOptionalType<R, ArrayElement<KeysToBeOptional>>;
14
+ type FullyOptionalType<R extends ReadonlyRecord<string, Type<unknown>>> = {
15
+ readonly [P in keyof R]: OptionalPropertyType<R[P]>;
16
+ };
17
+ type PartiallyOptionalType<R extends ReadonlyRecord<string, Type<unknown>>, K extends keyof R> = {
18
+ readonly [P in keyof R]: P extends K ? OptionalPropertyType<R[P]> : R[P];
19
+ };
20
+ export type PartialType<R extends ReadonlyRecord<string, Type<unknown>>, KeysToBeOptional extends NonEmptyArray<keyof R & string> | undefined> = RecordType<PartialTypeShape<R, KeysToBeOptional>>;
12
21
  export {};
13
22
  //# sourceMappingURL=partial.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"partial.d.mts","sourceRoot":"","sources":["../../src/record/partial.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAQrD;;;GAGG;AACH,eAAO,MAAM,OAAO,GAClB,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,EACnC,KAAK,CAAC,gBAAgB,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,EAEtE,YAAY,CAAC,EACb,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CACH,KACA,WAAW,CAAC,CAAC,EAAE,gBAAgB,CAwEjC,CAAC;AAEF,KAAK,gBAAgB,CACnB,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,EAC7B,gBAAgB,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,SAAS,IAE5E,MAAM,CAAC,gBAAgB,EAAE,SAAS,CAAC,SAAS,IAAI,GAC5C,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,IAAI,GAC5C,iBAAiB,CAAC,CAAC,CAAC,GACpB,qBAAqB,CAAC,CAAC,EAAE,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAE/D,KAAK,iBAAiB,CAAC,CAAC,SAAS,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI;IACxE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACpD,CAAC;AAEF,KAAK,qBAAqB,CACxB,CAAC,SAAS,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,EAC/C,CAAC,SAAS,MAAM,CAAC,IACf;IACF,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACzE,CAAC;AAEF,MAAM,MAAM,WAAW,CACrB,CAAC,SAAS,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,EAC/C,gBAAgB,SAAS,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,SAAS,IAClE,UAAU,CAAC,gBAAgB,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC"}
@@ -1,8 +1,7 @@
1
- import { Obj, isRecord, Result, ISet } from 'ts-data-forge';
2
- import { createAssertFn } from '../utils/create-assert-fn.mjs';
3
- import { createCastFn } from '../utils/create-cast-fn.mjs';
4
- import { createIsFn } from '../utils/create-is-fn.mjs';
5
- import { createPrimitiveValidationError } from '../utils/validation-error.mjs';
1
+ import 'ts-data-forge';
2
+ import { toUnionString } from '../utils/to-union-string.mjs';
3
+ import { optional } from './optional.mjs';
4
+ import { record } from './record.mjs';
6
5
 
7
6
  /**
8
7
  * Creates a Partial type. If keysToBeOptional is set, only those keys are
@@ -12,122 +11,16 @@ const partial = (recordType, options) => {
12
11
  const typeNameFilled = options?.typeName ??
13
12
  (options?.keysToBeOptional === undefined
14
13
  ? `Partial<${recordType.typeName}>`
15
- : `PartiallyPartial<${recordType.typeName}, ${options.keysToBeOptional.join('|')}>`);
16
- const keysToBeOptional = options?.keysToBeOptional ?? Object.keys(recordType.defaultValue);
14
+ : `PartiallyPartial<${recordType.typeName}, ${toUnionString(options.keysToBeOptional)}>`);
15
+ const keysToBeOptional = new Set(options?.keysToBeOptional ?? Object.keys(recordType.shape));
16
+ const partialShape =
17
17
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
18
- const defaultValue = Obj.omit(recordType.defaultValue, keysToBeOptional);
19
- const validate = (a) => {
20
- if (!isRecord(a)) {
21
- return Result.err([
22
- createPrimitiveValidationError({
23
- actualValue: a,
24
- expectedType: 'record',
25
- typeName: typeNameFilled,
26
- }),
27
- ]);
28
- }
29
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
30
- const objectFilled = {
31
- // fill optional properties to skip check by recordType.validate
32
- ...Obj.pick(recordType.defaultValue, keysToBeOptional),
33
- // overwrite with `a`
34
- ...a,
35
- };
36
- const validationResult = recordType.validate(objectFilled);
37
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
38
- return Result.map(validationResult, () => a);
39
- };
40
- const fill = (a) => {
41
- if (!isRecord(a)) {
42
- return defaultValue;
43
- }
44
- const inputKeys = ISet.create(Object.keys(a));
45
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
46
- return Obj.omit(
47
- // First, create a recursively filled object with all properties required.
48
- recordType.fill(a),
49
- // Then, Omit optional properties not present in `a`.
50
- keysToBeOptional.filter((k) =>
51
- // avoid removing properties from `a`
52
- !inputKeys.has(k)));
53
- };
54
- return {
18
+ Object.fromEntries(Object.entries(recordType.shape).map(([k, v]) => [k, keysToBeOptional.has(k) ? optional(v) : v]));
19
+ return record(partialShape, {
55
20
  typeName: typeNameFilled,
56
- defaultValue,
57
- fill,
58
- validate,
59
- is: createIsFn(validate),
60
- assertIs: createAssertFn(validate),
61
- cast: createCastFn(validate),
62
- };
21
+ allowExcessProperties: options?.allowExcessProperties ?? recordType.allowExcessProperties,
22
+ });
63
23
  };
64
- // expectType<TsFortressInternal.SetOptional<Type<0>>, OptionalType<0>>('=');
65
- // expectType<
66
- // TsFortressInternal.SetOptionalForAllKey<{
67
- // a: Type<0>;
68
- // }>,
69
- // Readonly<{
70
- // a: OptionalType<0>;
71
- // }>
72
- // >('=');
73
- // expectType<
74
- // TsFortressInternal.SetOptionalForAllKey<{
75
- // a: Type<0>;
76
- // b: OptionalType<0>;
77
- // }>,
78
- // Readonly<{
79
- // a: OptionalType<0>;
80
- // b: OptionalType<0>;
81
- // }>
82
- // >('=');
83
- // expectType<
84
- // TsFortressInternal.SetOptionalForAllKey<
85
- // RecordType<{
86
- // a: OptionalType<0>;
87
- // b: OptionalType<0>;
88
- // c: Type<0>;
89
- // }>['source']
90
- // >,
91
- // Readonly<{
92
- // a: OptionalType<0>;
93
- // b: OptionalType<0>;
94
- // c: OptionalType<0>;
95
- // }>
96
- // >('=');
97
- // expectType<
98
- // PartialType<
99
- // RecordType<{
100
- // a: OptionalType<0>;
101
- // b: OptionalType<0>;
102
- // c: Type<0>;
103
- // }>,
104
- // undefined
105
- // >,
106
- // RecordType<
107
- // Readonly<{
108
- // a: OptionalType<0>;
109
- // b: OptionalType<0>;
110
- // c: OptionalType<0>;
111
- // }>
112
- // >
113
- // >('=');
114
- // expectType<
115
- // PartialType<
116
- // Type<{
117
- // a: OptionalType<0>;
118
- // b: Type<0>;
119
- // c: Type<0>;
120
- // }>,
121
- // ['b']
122
- // >,
123
- // RecordType<
124
- // Readonly<{
125
- // a: OptionalType<0>;
126
- // b: OptionalType<0>;
127
- // c: Type<0>;
128
- // }>
129
- // >
130
- // >('=');
131
24
 
132
25
  export { partial };
133
26
  //# sourceMappingURL=partial.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"partial.mjs","sources":["../../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I;AAClC,QAAA,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;AAChB,YAAA,OAAO,YAAY;;AAGrB,QAAA,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;QAG7C,OAAO,GAAG,CAAC,IAAI;;AAEb,QAAA,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;;AAElB,QAAA,gBAAgB,CAAC,MAAM,CACrB,CAAC,CAAC;;QAEA,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CACpB,CACc;AACnB,IAAA,CAAC;IAED,OAAO;AACL,QAAA,QAAQ,EAAE,cAAc;QACxB,YAAY;QACZ,IAAI;QACJ,QAAQ;AACR,QAAA,EAAE,EAAE,UAAU,CAAC,QAAQ,CAAC;AACxB,QAAA,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;AAClC,QAAA,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC;KAC7B;AACH;AAeA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}
1
+ {"version":3,"file":"partial.mjs","sources":["../../src/record/partial.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAMA;;;AAGG;MACU,OAAO,GAAG,CAIrB,UAAyB,EACzB,OAQC,KACmC;AACpC,IAAA,MAAM,cAAc,GAClB,OAAO,EAAE,QAAQ;AACjB,SAAC,OAAO,EAAE,gBAAgB,KAAK;AAC7B,cAAE,CAAA,QAAA,EAAW,UAAU,CAAC,QAAQ,CAAA,CAAA;AAChC,cAAE,CAAA,iBAAA,EAAoB,UAAU,CAAC,QAAQ,CAAA,EAAA,EAAK,aAAa,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA,CAAA,CAAG,CAAC;AAE7F,IAAA,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CACnD,OAAO,EAAE,gBAAgB,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAC3D;AAED,IAAA,MAAM,YAAY;;IAEhB,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,CAClC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAU,CACpE,CAIF;IAEH,OAAO,MAAM,CAAC,YAAY,EAAE;AAC1B,QAAA,QAAQ,EAAE,cAAc;AACxB,QAAA,qBAAqB,EACnB,OAAO,EAAE,qBAAqB,IAAI,UAAU,CAAC,qBAAqB;AACrE,KAAA,CAAC;AACJ;;;;"}
@@ -1,8 +1,9 @@
1
- import { type Type, type TypeOf } from '../type.mjs';
1
+ import { type RecordType, type Type } from '../type.mjs';
2
2
  /** Creates a record type with keys picked. */
3
- export declare const pick: <const R extends Type<UnknownRecord>, const KeysToPick extends readonly (keyof TypeOf<R> & string)[]>(recordType: R, keysToPick: KeysToPick, options?: Partial<Readonly<{
3
+ export declare const pick: <const R extends ReadonlyRecord<string, Type<unknown>>, const KeysToPick extends readonly (keyof R & string)[]>(recordType: RecordType<R>, keysToPick: KeysToPick, options?: Partial<Readonly<{
4
4
  typeName: string;
5
+ /** @default true */
6
+ allowExcessProperties: boolean;
5
7
  }>>) => PickedType<R, KeysToPick>;
6
- type PickedType<R extends Type<UnknownRecord>, KeysToPick extends readonly (keyof TypeOf<R>)[]> = Type<Pick<TypeOf<R>, ArrayElement<KeysToPick>>>;
7
- export {};
8
+ export type PickedType<R extends ReadonlyRecord<string, Type<unknown>>, KeysToPick extends readonly (keyof R)[]> = RecordType<Pick<R, ArrayElement<KeysToPick>>>;
8
9
  //# sourceMappingURL=pick.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pick.d.mts","sourceRoot":"","sources":["../../src/record/pick.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAQrD,8CAA8C;AAC9C,eAAO,MAAM,IAAI,GACf,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,EACnC,KAAK,CAAC,UAAU,SAAS,SAAS,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE,EAE9D,YAAY,CAAC,EACb,YAAY,UAAU,EACtB,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CACH,KACA,UAAU,CAAC,CAAC,EAAE,UAAU,CA4C1B,CAAC;AAEF,KAAK,UAAU,CACb,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,EAC7B,UAAU,SAAS,SAAS,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,IAC7C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"pick.d.mts","sourceRoot":"","sources":["../../src/record/pick.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAIzD,8CAA8C;AAC9C,eAAO,MAAM,IAAI,GACf,KAAK,CAAC,CAAC,SAAS,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,EACrD,KAAK,CAAC,UAAU,SAAS,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,EAEtD,YAAY,UAAU,CAAC,CAAC,CAAC,EACzB,YAAY,UAAU,EACtB,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;IAEjB,oBAAoB;IACpB,qBAAqB,EAAE,OAAO,CAAC;CAChC,CAAC,CACH,KACA,UAAU,CAAC,CAAC,EAAE,UAAU,CAOvB,CAAC;AAEL,MAAM,MAAM,UAAU,CACpB,CAAC,SAAS,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,EAC/C,UAAU,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,IACrC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC"}
@@ -1,44 +1,13 @@
1
- import { Obj, isRecord, Result } from 'ts-data-forge';
2
- import { createAssertFn } from '../utils/create-assert-fn.mjs';
3
- import { createCastFn } from '../utils/create-cast-fn.mjs';
4
- import { createIsFn } from '../utils/create-is-fn.mjs';
5
- import { createPrimitiveValidationError } from '../utils/validation-error.mjs';
1
+ import { Obj } from 'ts-data-forge';
2
+ import { toUnionString } from '../utils/to-union-string.mjs';
3
+ import { record } from './record.mjs';
6
4
 
7
5
  /** Creates a record type with keys picked. */
8
- const pick = (recordType, keysToPick, options) => {
9
- const typeNameFilled = options?.typeName ??
10
- `Pick<${recordType.typeName}, ${keysToPick.join('|')}>`;
11
- const defaultValue = Obj.pick(recordType.defaultValue, keysToPick);
12
- const validate = (a) => {
13
- if (!isRecord(a)) {
14
- return Result.err([
15
- createPrimitiveValidationError({
16
- actualValue: a,
17
- expectedType: 'record',
18
- typeName: typeNameFilled,
19
- }),
20
- ]);
21
- }
22
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
23
- const objectFilled = {
24
- ...Obj.omit(recordType.fill(a), keysToPick),
25
- ...a,
26
- };
27
- const baseValidationResult = recordType.validate(objectFilled);
28
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
29
- return Result.map(baseValidationResult, () => a);
30
- };
31
- const fill = (a) => Obj.pick(recordType.fill(a), keysToPick);
32
- return {
33
- typeName: typeNameFilled,
34
- defaultValue,
35
- fill,
36
- validate,
37
- is: createIsFn(validate),
38
- assertIs: createAssertFn(validate),
39
- cast: createCastFn(validate),
40
- };
41
- };
6
+ const pick = (recordType, keysToPick, options) => record(Obj.pick(recordType.shape, keysToPick), {
7
+ typeName: options?.typeName ??
8
+ `Pick<${recordType.typeName}, ${toUnionString(keysToPick)}>`,
9
+ allowExcessProperties: options?.allowExcessProperties ?? recordType.allowExcessProperties,
10
+ });
42
11
 
43
12
  export { pick };
44
13
  //# sourceMappingURL=pick.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"pick.mjs","sources":["../../src/record/pick.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AASA;AACO,MAAM,IAAI,GAAG,CAIlB,UAAa,EACb,UAAsB,EACtB,OAIC,KAC4B;AAG7B,IAAA,MAAM,cAAc,GAClB,OAAO,EAAE,QAAQ;QACjB,CAAA,KAAA,EAAQ,UAAU,CAAC,QAAQ,CAAA,EAAA,EAAK,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA,CAAA,CAAG;AAEzD,IAAA,MAAM,YAAY,GAAM,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,UAAU,CAAM;AAE1E,IAAA,MAAM,QAAQ,GAAwB,CAAC,CAAC,KAAI;AAC1C,QAAA,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;YAChB,OAAO,MAAM,CAAC,GAAG,CAAC;AAChB,gBAAA,8BAA8B,CAAC;AAC7B,oBAAA,WAAW,EAAE,CAAC;AACd,oBAAA,YAAY,EAAE,QAAQ;AACtB,oBAAA,QAAQ,EAAE,cAAc;iBACzB,CAAC;AACH,aAAA,CAAC;;;AAIJ,QAAA,MAAM,YAAY,GAAG;AACnB,YAAA,GAAG,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;AAC3C,YAAA,GAAG,CAAC;SACQ;QAEd,MAAM,oBAAoB,GAAG,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC;;QAG9D,OAAO,MAAM,CAAC,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAM,CAAC;AACvD,IAAA,CAAC;IAED,MAAM,IAAI,GAAoB,CAAC,CAAC,KAC9B,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,UAAU,CAAM;IAE/C,OAAO;AACL,QAAA,QAAQ,EAAE,cAAc;QACxB,YAAY;QACZ,IAAI;QACJ,QAAQ;AACR,QAAA,EAAE,EAAE,UAAU,CAAC,QAAQ,CAAC;AACxB,QAAA,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;AAClC,QAAA,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC;KAC7B;AACH;;;;"}
1
+ {"version":3,"file":"pick.mjs","sources":["../../src/record/pick.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKA;AACO,MAAM,IAAI,GAAG,CAIlB,UAAyB,EACzB,UAAsB,EACtB,OAOC,KAED,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE;IAC7C,QAAQ,EACN,OAAO,EAAE,QAAQ;QACjB,CAAA,KAAA,EAAQ,UAAU,CAAC,QAAQ,CAAA,EAAA,EAAK,aAAa,CAAC,UAAU,CAAC,CAAA,CAAA,CAAG;AAC9D,IAAA,qBAAqB,EACnB,OAAO,EAAE,qBAAqB,IAAI,UAAU,CAAC,qBAAqB;AACrE,CAAA;;;;"}
@@ -1,28 +1,9 @@
1
- import { type Type, type TypeOf } from '../type.mjs';
2
- export declare const record: <const R extends ReadonlyRecord<string, Type<unknown>>>(source: R, options?: Partial<Readonly<{
1
+ import { type RecordType, type TsFortressInternal, type Type } from '../type.mjs';
2
+ export declare const record: <const R extends ReadonlyRecord<string, Type<unknown>>>(shape: R, options?: Partial<Readonly<{
3
3
  typeName: string;
4
4
  /** @default true */
5
5
  allowExcessProperties: boolean;
6
- }>>) => Type<RecordTypeValue<R>>;
7
- type RecordTypeValue<R extends ReadonlyRecord<string, Type<unknown>>> = TsFortressInternal.RecordTypeValueImpl<R>;
8
- declare namespace TsFortressInternal {
9
- export type RecordTypeValueImpl<R extends ReadonlyRecord<string, Type<unknown>>> = RecordTypeValueImplSub<R, OptionalTypeKeys<R>>;
10
- type RecordTypeValueImplSub<A extends ReadonlyRecord<string, Type<unknown>>, OptionalKeys extends keyof A> = TypeEq<OptionalKeys, never> extends true ? Readonly<{
11
- [key in Exclude<keyof A, OptionalKeys>]: TypeOf<A[key]>;
12
- }> : TypeEq<keyof A, OptionalKeys> extends true ? Readonly<MergeIntersection<{
13
- [key in OptionalKeys]?: TypeOf<A[key]>;
14
- }>> : Readonly<MergeIntersection<{
15
- [key in OptionalKeys]?: TypeOf<A[key]>;
16
- } & {
17
- [key in Exclude<keyof A, OptionalKeys>]: TypeOf<A[key]>;
18
- }>>;
19
- type OptionalTypeKeys<A extends ReadonlyRecord<string, Type<unknown>>> = {
20
- [K in keyof A]: A[K] extends {
21
- optional: true;
22
- } ? K : never;
23
- }[keyof A];
24
- export {};
25
- }
6
+ }>>) => RecordType<R>;
26
7
  /**
27
8
  * Creates a strict record type that does not allow excess properties.
28
9
  * This is an alias for `record(source, { allowExcessProperties: false })`.
@@ -46,6 +27,5 @@ declare namespace TsFortressInternal {
46
27
  */
47
28
  export declare const strictRecord: <const R extends ReadonlyRecord<string, Type<unknown>>>(source: R, options?: Partial<Readonly<{
48
29
  typeName: string;
49
- }>>) => Type<RecordTypeValue<R>>;
50
- export {};
30
+ }>>) => Type<TsFortressInternal.RecordTypeValue<R>>;
51
31
  //# sourceMappingURL=record.d.mts.map
@@ -1 +1 @@
1
- {"version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AAM,CAAC;IAEjB,oBAAoB;IACpB,qBAAqB,EAAE,OAAO,CAAC;CAChC,CAAC,CACH,KACA,UAAU,CAAC,CAAC,CAyGd,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,YAAY,GACvB,KAAK,CAAC,CAAC,SAAS,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,EAErD,QAAQ,CAAC,EACT,UAAU,OAAO,CACf,QAAQ,CAAC;IACP,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CACH,KACA,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC,CAAC,CACiB,CAAC"}
@@ -4,16 +4,16 @@ import { createCastFn } from '../utils/create-cast-fn.mjs';
4
4
  import { createIsFn } from '../utils/create-is-fn.mjs';
5
5
  import { createPrimitiveValidationError, prependPathToValidationErrors } from '../utils/validation-error.mjs';
6
6
 
7
- const record = (source, options) => {
8
- const sourceKeys = new Set(Object.keys(source));
7
+ const record = (shape, options) => {
8
+ const sourceKeys = new Set(Object.keys(shape));
9
9
  const typeNameFilled = options?.typeName ??
10
- `{ ${Object.entries(source)
10
+ `{ ${Object.entries(shape)
11
11
  .map(([k, v]) => `${k}: ${v.typeName}`)
12
12
  .join(', ')} }`;
13
13
  const allowExcessProperties = options?.allowExcessProperties ?? true;
14
14
  const defaultValue =
15
15
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
16
- Object.fromEntries(Object.entries(source).map(([key, value]) => tp(key, value.defaultValue)));
16
+ Object.fromEntries(Object.entries(shape).map(([key, value]) => tp(key, value.defaultValue)));
17
17
  const validate = (a) => {
18
18
  if (!isRecord(a)) {
19
19
  return Result.err([
@@ -25,9 +25,9 @@ const record = (source, options) => {
25
25
  ]);
26
26
  }
27
27
  const defaultErrors = Arr.generate(function* () {
28
- for (const [k, valueType] of Object.entries(source)) {
28
+ for (const [k, valueType] of Object.entries(shape)) {
29
29
  if (!Object.hasOwn(a, k)) {
30
- if (source[k]?.optional !== true) {
30
+ if (shape[k]?.optional !== true) {
31
31
  yield {
32
32
  path: [k],
33
33
  actualValue: a,
@@ -69,7 +69,7 @@ const record = (source, options) => {
69
69
  };
70
70
  const fill = (a) => isRecord(a)
71
71
  ? // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
72
- Object.fromEntries(Object.entries(source).map(([k, v]) => tp(k, Object.hasOwn(a, k) ? v.fill(a[k]) : v.defaultValue)))
72
+ Object.fromEntries(Object.entries(shape).map(([k, v]) => tp(k, Object.hasOwn(a, k) ? v.fill(a[k]) : v.defaultValue)))
73
73
  : defaultValue;
74
74
  return {
75
75
  typeName: typeNameFilled,
@@ -79,6 +79,8 @@ const record = (source, options) => {
79
79
  is: createIsFn(validate),
80
80
  assertIs: createAssertFn(validate),
81
81
  cast: createCastFn(validate),
82
+ shape,
83
+ allowExcessProperties,
82
84
  };
83
85
  };
84
86
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"record.mjs","sources":["../../src/record/record.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;MAYa,MAAM,GAAG,CACpB,MAAS,EACT,OAOC,KAC2B;AAG5B,IAAA,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE/C,IAAA,MAAM,cAAc,GAClB,OAAO,EAAE,QAAQ;AACjB,QAAA,CAAA,EAAA,EAAK,MAAM,CAAC,OAAO,CAAC,MAAM;AACvB,aAAA,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAA,EAAA,EAAK,CAAC,CAAC,QAAQ,EAAE;AACrC,aAAA,IAAI,CAAC,IAAI,CAAC,CAAA,EAAA,CAAI;AAEnB,IAAA,MAAM,qBAAqB,GAAG,OAAO,EAAE,qBAAqB,IAAI,IAAI;AAEpE,IAAA,MAAM,YAAY;;AAEhB,IAAA,MAAM,CAAC,WAAW,CAChB,MAAM,CA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,QAAA,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;AAClC,QAAA,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC;QAC5B,KAAK;QACL,qBAAqB;KACtB;AACH;AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AACI,MAAM,YAAY,GAAG,CAG1B,MAAS,EACT,OAIC,KAED,MAAM,CAAC,MAAM,EAAE,EAAE,GAAG,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE;;;;"}
package/dist/type.d.mts CHANGED
@@ -18,11 +18,35 @@ export type Type<A> = Readonly<{
18
18
  cast: (a: unknown) => A;
19
19
  fill: (a: unknown) => A;
20
20
  validate: (a: unknown) => Result<A, readonly ValidationError[]>;
21
- /** Used in record type */
21
+ /** @internal Used to mark properties as optional in record type validation */
22
22
  optional?: true;
23
23
  }>;
24
24
  export type TypeOf<A extends Type<unknown>> = A['defaultValue'];
25
+ /** @deprecated */
25
26
  export type OptionalType<A> = MergeIntersection<Type<A> & Readonly<{
26
27
  optional: true;
27
28
  }>>;
29
+ export type RecordType<R extends ReadonlyRecord<string, Type<unknown>>> = Type<TsFortressInternal.RecordTypeValue<R>> & Readonly<{
30
+ shape: R;
31
+ allowExcessProperties: boolean;
32
+ }>;
33
+ export declare namespace TsFortressInternal {
34
+ export type RecordTypeValue<R extends ReadonlyRecord<string, Type<unknown>>> = RecordTypeValueImpl<R>;
35
+ export type RecordTypeValueImpl<R extends ReadonlyRecord<string, Type<unknown>>> = RecordTypeValueImplSub<R, OptionalTypeKeys<R>>;
36
+ type RecordTypeValueImplSub<A extends ReadonlyRecord<string, Type<unknown>>, OptionalKeys extends keyof A> = TypeEq<OptionalKeys, never> extends true ? Readonly<{
37
+ [key in Exclude<keyof A, OptionalKeys>]: TypeOf<A[key]>;
38
+ }> : TypeEq<keyof A, OptionalKeys> extends true ? Readonly<MergeIntersection<{
39
+ [key in OptionalKeys]?: TypeOf<A[key]>;
40
+ }>> : Readonly<MergeIntersection<{
41
+ [key in OptionalKeys]?: TypeOf<A[key]>;
42
+ } & {
43
+ [key in Exclude<keyof A, OptionalKeys>]: TypeOf<A[key]>;
44
+ }>>;
45
+ type OptionalTypeKeys<A extends ReadonlyRecord<string, Type<unknown>>> = {
46
+ [K in keyof A]: A[K] extends {
47
+ optional: true;
48
+ } ? K : never;
49
+ }[keyof A];
50
+ export {};
51
+ }
28
52
  //# sourceMappingURL=type.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.mts","sourceRoot":"","sources":["../src/type.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;;;;;;;GASG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,QAAQ,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,CAAC,CAAC;IAChB,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,QAAQ,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC;IACxB,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC;IACxB,QAAQ,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC,CAAC;IAEhE,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,IAAI,CAAC;CACjB,CAAC,CAAC;AAEH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC;AAEhE,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,iBAAiB,CAC7C,IAAI,CAAC,CAAC,CAAC,GAAG,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