ts-fortress 2.5.0 → 2.6.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/README.md +9 -12
- package/dist/entry-point.d.mts +3 -0
- package/dist/entry-point.d.mts.map +1 -0
- package/dist/entry-point.mjs +56 -0
- package/dist/entry-point.mjs.map +1 -0
- package/dist/types.d.mts +1 -1
- package/package.json +4 -4
- package/src/entry-point.mts +89 -0
package/README.md
CHANGED
|
@@ -71,11 +71,9 @@ if (User.is(userData)) {
|
|
|
71
71
|
console.log(`User: ${userData.name}, Age: ${userData.age}`);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
import { Result } from 'ts-data-forge';
|
|
75
|
-
|
|
76
74
|
// Get validation result with error details
|
|
77
75
|
const result = User.validate(userData);
|
|
78
|
-
if (Result.isOk(result)) {
|
|
76
|
+
if (t.Result.isOk(result)) {
|
|
79
77
|
const user = result.value; // typed as User
|
|
80
78
|
} else {
|
|
81
79
|
console.error('Validation errors:', result.value); // readonly ValidationError[] showing error information
|
|
@@ -132,7 +130,7 @@ const completeUser: UserProfile = UserProfile.fill(anyPartialData);
|
|
|
132
130
|
// The is() and validate() functions can still detect missing keys
|
|
133
131
|
console.log(UserProfile.is(partialData)); // false - missing required keys
|
|
134
132
|
const result = UserProfile.validate(partialData);
|
|
135
|
-
if (Result.isErr(result)) {
|
|
133
|
+
if (t.Result.isErr(result)) {
|
|
136
134
|
console.log(result.value); // ValidationError[] showing missing keys
|
|
137
135
|
}
|
|
138
136
|
```
|
|
@@ -413,7 +411,7 @@ const C = t.partial(
|
|
|
413
411
|
const UnionBA = t.union([B, A]);
|
|
414
412
|
const result = UnionBA.validate({ A: 1 });
|
|
415
413
|
|
|
416
|
-
if (Result.isOk(result)) {
|
|
414
|
+
if (t.Result.isOk(result)) {
|
|
417
415
|
console.log(result.value); // { A: 1 } <- ✅ Correct! No unexpected fields
|
|
418
416
|
console.log(A.is(result.value)); // true <- ✅ Correct
|
|
419
417
|
console.log(B.is(result.value)); // false <- ✅ Correct! B requires field B
|
|
@@ -425,7 +423,7 @@ const C = t.partial(
|
|
|
425
423
|
const UnionCA = t.union([C, A]);
|
|
426
424
|
const result = UnionCA.validate({ A: 1 });
|
|
427
425
|
|
|
428
|
-
if (Result.isOk(result)) {
|
|
426
|
+
if (t.Result.isOk(result)) {
|
|
429
427
|
console.log(result.value); // { A: 1 } <- ✅ Correct and consistent
|
|
430
428
|
console.log(A.is(result.value)); // true <- ✅ Correct
|
|
431
429
|
console.log(C.is(result.value)); // true <- ✅ Consistent! ts-fortress partial types allow extra fields
|
|
@@ -496,7 +494,6 @@ The `validate` method performs comprehensive validation and returns a `Result` t
|
|
|
496
494
|
|
|
497
495
|
```typescript
|
|
498
496
|
import * as t from 'ts-fortress';
|
|
499
|
-
import { Result } from 'ts-data-forge';
|
|
500
497
|
|
|
501
498
|
const User = t.record({
|
|
502
499
|
name: t.string(''),
|
|
@@ -507,7 +504,7 @@ const User = t.record({
|
|
|
507
504
|
const validData = { name: 'Alice', age: 30 };
|
|
508
505
|
const result = User.validate(validData);
|
|
509
506
|
|
|
510
|
-
if (Result.isOk(result)) {
|
|
507
|
+
if (t.Result.isOk(result)) {
|
|
511
508
|
console.log(result.value === validData); // true - same reference!
|
|
512
509
|
console.log(result.value); // { name: 'Alice', age: 30 }
|
|
513
510
|
}
|
|
@@ -516,7 +513,7 @@ if (Result.isOk(result)) {
|
|
|
516
513
|
const invalidData = { name: 'Bob', age: 'thirty' };
|
|
517
514
|
const errorResult = User.validate(invalidData);
|
|
518
515
|
|
|
519
|
-
if (Result.isErr(errorResult)) {
|
|
516
|
+
if (t.Result.isErr(errorResult)) {
|
|
520
517
|
console.log(errorResult.value);
|
|
521
518
|
// [
|
|
522
519
|
// {
|
|
@@ -749,7 +746,7 @@ const UInt16 = t.uint16(0);
|
|
|
749
746
|
|
|
750
747
|
// Usage
|
|
751
748
|
const userIdResult = UserId.validate('user_123');
|
|
752
|
-
if (Result.isOk(userIdResult)) {
|
|
749
|
+
if (t.Result.isOk(userIdResult)) {
|
|
753
750
|
const id: UserId = userIdResult.value;
|
|
754
751
|
}
|
|
755
752
|
```
|
|
@@ -815,7 +812,7 @@ const UserType = t.record({
|
|
|
815
812
|
const invalidData = { name: 123, age: 'not a number' };
|
|
816
813
|
|
|
817
814
|
const result = UserType.validate(invalidData);
|
|
818
|
-
if (Result.isErr(result)) {
|
|
815
|
+
if (t.Result.isErr(result)) {
|
|
819
816
|
// result.value is an array of ValidationError objects
|
|
820
817
|
for (const error of result.value) {
|
|
821
818
|
console.log('Path:', error.path); // ['name'] or ['age']
|
|
@@ -851,7 +848,7 @@ const StrictType = t.record(
|
|
|
851
848
|
const dataWithExcess = { name: 'John', age: 30, extra: 'not allowed' };
|
|
852
849
|
const strictResult = StrictType.validate(dataWithExcess);
|
|
853
850
|
|
|
854
|
-
if (Result.isErr(strictResult)) {
|
|
851
|
+
if (t.Result.isErr(strictResult)) {
|
|
855
852
|
console.log(strictResult.value);
|
|
856
853
|
// [{
|
|
857
854
|
// path: ['extra'],
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { FiniteNumber, Int, Int16, Int32, Int8, NonNegativeFiniteNumber, NonNegativeInt16, NonNegativeInt32, NonZeroFiniteNumber, NonZeroInt, NonZeroInt16, NonZeroInt32, NonZeroSafeInt, NonZeroUint16, NonZeroUint32, PositiveFiniteNumber, PositiveInt, PositiveInt16, PositiveInt32, PositiveSafeInt, PositiveUint16, PositiveUint32, Result, SafeInt, SafeUint, Uint, Uint16, Uint32, Uint8, asFiniteNumber, asInt, asInt16, asInt32, asInt8, asNonNegativeFiniteNumber, asNonNegativeInt16, asNonNegativeInt32, asNonZeroFiniteNumber, asNonZeroInt, asNonZeroInt16, asNonZeroInt32, asNonZeroSafeInt, asNonZeroUint16, asNonZeroUint32, asPositiveFiniteNumber, asPositiveInt, asPositiveInt16, asPositiveInt32, asPositiveSafeInt, asPositiveUint16, asPositiveUint32, asSafeInt, asSafeUint, asUint, asUint16, asUint32, asUint8, isBigint, isFiniteNumber, isInt, isInt16, isInt32, isInt8, isNonNegativeFiniteNumber, isNonNegativeInt16, isNonNegativeInt32, isNonZeroFiniteNumber, isNonZeroInt, isNonZeroInt16, isNonZeroInt32, isNonZeroSafeInt, isNonZeroUint16, isNonZeroUint32, isPositiveFiniteNumber, isPositiveInt, isPositiveInt16, isPositiveInt32, isPositiveSafeInt, isPositiveUint16, isPositiveUint32, isSafeInt, isSafeUint, isUint, isUint16, isUint32, isUint8, } from 'ts-data-forge';
|
|
2
|
+
export * from './index.mjs';
|
|
3
|
+
//# sourceMappingURL=entry-point.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-point.d.mts","sourceRoot":"","sources":["../src/entry-point.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,GAAG,EACH,KAAK,EACL,KAAK,EACL,IAAI,EACJ,uBAAuB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,MAAM,EACN,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,MAAM,EACN,KAAK,EACL,cAAc,EACd,KAAK,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,yBAAyB,EACzB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,cAAc,EACd,KAAK,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,yBAAyB,EACzB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,OAAO,GACR,MAAM,eAAe,CAAC;AACvB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export { FiniteNumber, Int, Int16, Int32, Int8, NonNegativeFiniteNumber, NonNegativeInt16, NonNegativeInt32, NonZeroFiniteNumber, NonZeroInt, NonZeroInt16, NonZeroInt32, NonZeroSafeInt, NonZeroUint16, NonZeroUint32, PositiveFiniteNumber, PositiveInt, PositiveInt16, PositiveInt32, PositiveSafeInt, PositiveUint16, PositiveUint32, Result, SafeInt, SafeUint, Uint, Uint16, Uint32, Uint8, asFiniteNumber, asInt, asInt16, asInt32, asInt8, asNonNegativeFiniteNumber, asNonNegativeInt16, asNonNegativeInt32, asNonZeroFiniteNumber, asNonZeroInt, asNonZeroInt16, asNonZeroInt32, asNonZeroSafeInt, asNonZeroUint16, asNonZeroUint32, asPositiveFiniteNumber, asPositiveInt, asPositiveInt16, asPositiveInt32, asPositiveSafeInt, asPositiveUint16, asPositiveUint32, asSafeInt, asSafeUint, asUint, asUint16, asUint32, asUint8, isBigint, isFiniteNumber, isInt, isInt16, isInt32, isInt8, isNonNegativeFiniteNumber, isNonNegativeInt16, isNonNegativeInt32, isNonZeroFiniteNumber, isNonZeroInt, isNonZeroInt16, isNonZeroInt32, isNonZeroSafeInt, isNonZeroUint16, isNonZeroUint32, isPositiveFiniteNumber, isPositiveInt, isPositiveInt16, isPositiveInt32, isPositiveSafeInt, isPositiveUint16, isPositiveUint32, isSafeInt, isSafeUint, isUint, isUint16, isUint32, isUint8 } from 'ts-data-forge';
|
|
2
|
+
export { arrayOfLength } from './array/array-of-length.mjs';
|
|
3
|
+
export { array } from './array/array.mjs';
|
|
4
|
+
export { nonEmptyArray } from './array/non-empty-array.mjs';
|
|
5
|
+
export { tuple } from './array/tuple.mjs';
|
|
6
|
+
export { brand } from './branded/brand.mjs';
|
|
7
|
+
export { finiteNumber } from './branded/number/finite-number.mjs';
|
|
8
|
+
export { int } from './branded/number/int.mjs';
|
|
9
|
+
export { int16 } from './branded/number/int16.mjs';
|
|
10
|
+
export { int32 } from './branded/number/int32.mjs';
|
|
11
|
+
export { nonNegativeFiniteNumber } from './branded/number/non-negative-finite-number.mjs';
|
|
12
|
+
export { nonZeroFiniteNumber } from './branded/number/non-zero-finite-number.mjs';
|
|
13
|
+
export { nonZeroInt } from './branded/number/non-zero-int.mjs';
|
|
14
|
+
export { nonZeroSafeInt } from './branded/number/non-zero-safe-int.mjs';
|
|
15
|
+
export { positiveFiniteNumber } from './branded/number/positive-finite-number.mjs';
|
|
16
|
+
export { positiveInt } from './branded/number/positive-int.mjs';
|
|
17
|
+
export { positiveSafeInt } from './branded/number/positive-safe-int.mjs';
|
|
18
|
+
export { safeInt } from './branded/number/safe-int.mjs';
|
|
19
|
+
export { safeUint } from './branded/number/safe-uint.mjs';
|
|
20
|
+
export { uint } from './branded/number/uint.mjs';
|
|
21
|
+
export { uint16 } from './branded/number/uint16.mjs';
|
|
22
|
+
export { uint32 } from './branded/number/uint32.mjs';
|
|
23
|
+
export { simpleBrandedNumber } from './branded/simple-branded-number.mjs';
|
|
24
|
+
export { simpleBrandedString } from './branded/simple-branded-string.mjs';
|
|
25
|
+
export { intersection } from './compose/intersection.mjs';
|
|
26
|
+
export { mergeRecords } from './compose/merge-records.mjs';
|
|
27
|
+
export { recursion } from './compose/recursion.mjs';
|
|
28
|
+
export { union } from './compose/union.mjs';
|
|
29
|
+
export { enumType } from './enum/enum.mjs';
|
|
30
|
+
export { intRange } from './enum/int-range.mjs';
|
|
31
|
+
export { uintRange } from './enum/uint-range.mjs';
|
|
32
|
+
export { int8 } from './predefined/int8.mjs';
|
|
33
|
+
export { JsonObject, JsonPrimitive, JsonValue } from './predefined/json.mjs';
|
|
34
|
+
export { uint8 } from './predefined/uint8.mjs';
|
|
35
|
+
export { bigint, bigintLiteral } from './primitives/bigint.mjs';
|
|
36
|
+
export { boolean, booleanLiteral } from './primitives/boolean.mjs';
|
|
37
|
+
export { nullType } from './primitives/null.mjs';
|
|
38
|
+
export { number, numberLiteral } from './primitives/number.mjs';
|
|
39
|
+
export { string, stringLiteral } from './primitives/string.mjs';
|
|
40
|
+
export { symbol } from './primitives/symbol.mjs';
|
|
41
|
+
export { undefinedType } from './primitives/undefined.mjs';
|
|
42
|
+
export { keyValueRecord } from './record/key-value-record.mjs';
|
|
43
|
+
export { keyof } from './record/keyof.mjs';
|
|
44
|
+
export { omit } from './record/omit.mjs';
|
|
45
|
+
export { isOptionalProperty, optional } from './record/optional.mjs';
|
|
46
|
+
export { partial } from './record/partial.mjs';
|
|
47
|
+
export { pick } from './record/pick.mjs';
|
|
48
|
+
export { record, strictRecord } from './record/record.mjs';
|
|
49
|
+
export { unknown } from './unknown.mjs';
|
|
50
|
+
export { createAssertFn } from './utils/create-assert-fn.mjs';
|
|
51
|
+
export { createCastFn } from './utils/create-cast-fn.mjs';
|
|
52
|
+
export { createIsFn } from './utils/create-is-fn.mjs';
|
|
53
|
+
export { createPrimitiveType } from './utils/create-primitive-type.mjs';
|
|
54
|
+
export { createType } from './utils/create-type.mjs';
|
|
55
|
+
export { createPrimitiveValidationError, prependIndexToValidationErrors, prependPathToValidationErrors, validationErrorToMessage, validationErrorsToMessages } from './utils/validation-error.mjs';
|
|
56
|
+
//# sourceMappingURL=entry-point.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-point.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import './globals.d.mts';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './entry-point.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-fortress",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript"
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
".": {
|
|
18
18
|
"import": {
|
|
19
19
|
"types": "./dist/types.d.mts",
|
|
20
|
-
"default": "./dist/
|
|
20
|
+
"default": "./dist/entry-point.mjs"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
"module": "./dist/
|
|
24
|
+
"module": "./dist/entry-point.mjs",
|
|
25
25
|
"types": "./dist/types.d.mts",
|
|
26
26
|
"files": [
|
|
27
27
|
"src",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"doc": "tsx ./scripts/cmd/gen-docs.mjs",
|
|
38
38
|
"fmt": "format-diff-from origin/main",
|
|
39
39
|
"fmt:full": "prettier --write .",
|
|
40
|
-
"gi": "gen-index-ts ./src --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --fmt 'npm run fmt'",
|
|
40
|
+
"gi": "gen-index-ts ./src --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --exclude entry-point.mts --fmt 'npm run fmt'",
|
|
41
41
|
"lint": "eslint .",
|
|
42
42
|
"lint:fix": "eslint . --fix",
|
|
43
43
|
"md": "markdownlint-cli2",
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export {
|
|
2
|
+
FiniteNumber,
|
|
3
|
+
Int,
|
|
4
|
+
Int16,
|
|
5
|
+
Int32,
|
|
6
|
+
Int8,
|
|
7
|
+
NonNegativeFiniteNumber,
|
|
8
|
+
NonNegativeInt16,
|
|
9
|
+
NonNegativeInt32,
|
|
10
|
+
NonZeroFiniteNumber,
|
|
11
|
+
NonZeroInt,
|
|
12
|
+
NonZeroInt16,
|
|
13
|
+
NonZeroInt32,
|
|
14
|
+
NonZeroSafeInt,
|
|
15
|
+
NonZeroUint16,
|
|
16
|
+
NonZeroUint32,
|
|
17
|
+
PositiveFiniteNumber,
|
|
18
|
+
PositiveInt,
|
|
19
|
+
PositiveInt16,
|
|
20
|
+
PositiveInt32,
|
|
21
|
+
PositiveSafeInt,
|
|
22
|
+
PositiveUint16,
|
|
23
|
+
PositiveUint32,
|
|
24
|
+
Result,
|
|
25
|
+
SafeInt,
|
|
26
|
+
SafeUint,
|
|
27
|
+
Uint,
|
|
28
|
+
Uint16,
|
|
29
|
+
Uint32,
|
|
30
|
+
Uint8,
|
|
31
|
+
asFiniteNumber,
|
|
32
|
+
asInt,
|
|
33
|
+
asInt16,
|
|
34
|
+
asInt32,
|
|
35
|
+
asInt8,
|
|
36
|
+
asNonNegativeFiniteNumber,
|
|
37
|
+
asNonNegativeInt16,
|
|
38
|
+
asNonNegativeInt32,
|
|
39
|
+
asNonZeroFiniteNumber,
|
|
40
|
+
asNonZeroInt,
|
|
41
|
+
asNonZeroInt16,
|
|
42
|
+
asNonZeroInt32,
|
|
43
|
+
asNonZeroSafeInt,
|
|
44
|
+
asNonZeroUint16,
|
|
45
|
+
asNonZeroUint32,
|
|
46
|
+
asPositiveFiniteNumber,
|
|
47
|
+
asPositiveInt,
|
|
48
|
+
asPositiveInt16,
|
|
49
|
+
asPositiveInt32,
|
|
50
|
+
asPositiveSafeInt,
|
|
51
|
+
asPositiveUint16,
|
|
52
|
+
asPositiveUint32,
|
|
53
|
+
asSafeInt,
|
|
54
|
+
asSafeUint,
|
|
55
|
+
asUint,
|
|
56
|
+
asUint16,
|
|
57
|
+
asUint32,
|
|
58
|
+
asUint8,
|
|
59
|
+
isBigint,
|
|
60
|
+
isFiniteNumber,
|
|
61
|
+
isInt,
|
|
62
|
+
isInt16,
|
|
63
|
+
isInt32,
|
|
64
|
+
isInt8,
|
|
65
|
+
isNonNegativeFiniteNumber,
|
|
66
|
+
isNonNegativeInt16,
|
|
67
|
+
isNonNegativeInt32,
|
|
68
|
+
isNonZeroFiniteNumber,
|
|
69
|
+
isNonZeroInt,
|
|
70
|
+
isNonZeroInt16,
|
|
71
|
+
isNonZeroInt32,
|
|
72
|
+
isNonZeroSafeInt,
|
|
73
|
+
isNonZeroUint16,
|
|
74
|
+
isNonZeroUint32,
|
|
75
|
+
isPositiveFiniteNumber,
|
|
76
|
+
isPositiveInt,
|
|
77
|
+
isPositiveInt16,
|
|
78
|
+
isPositiveInt32,
|
|
79
|
+
isPositiveSafeInt,
|
|
80
|
+
isPositiveUint16,
|
|
81
|
+
isPositiveUint32,
|
|
82
|
+
isSafeInt,
|
|
83
|
+
isSafeUint,
|
|
84
|
+
isUint,
|
|
85
|
+
isUint16,
|
|
86
|
+
isUint32,
|
|
87
|
+
isUint8,
|
|
88
|
+
} from 'ts-data-forge';
|
|
89
|
+
export * from './index.mjs';
|