sibyl-ts 0.3.1 → 0.5.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 (43) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +75 -0
  3. package/dist/cjs/validators/index.d.ts +4 -0
  4. package/dist/cjs/validators/index.d.ts.map +1 -1
  5. package/dist/cjs/validators/index.js +4 -0
  6. package/dist/cjs/validators/index.js.map +1 -1
  7. package/dist/cjs/validators/intersection.d.ts +7 -0
  8. package/dist/cjs/validators/intersection.d.ts.map +1 -0
  9. package/dist/cjs/validators/intersection.js +58 -0
  10. package/dist/cjs/validators/intersection.js.map +1 -0
  11. package/dist/cjs/validators/nil.d.ts +3 -0
  12. package/dist/cjs/validators/nil.d.ts.map +1 -0
  13. package/dist/cjs/validators/nil.js +24 -0
  14. package/dist/cjs/validators/nil.js.map +1 -0
  15. package/dist/cjs/validators/undef.d.ts +3 -0
  16. package/dist/cjs/validators/undef.d.ts.map +1 -0
  17. package/dist/cjs/validators/undef.js +24 -0
  18. package/dist/cjs/validators/undef.js.map +1 -0
  19. package/dist/cjs/validators/unknown.d.ts +3 -0
  20. package/dist/cjs/validators/unknown.d.ts.map +1 -0
  21. package/dist/cjs/validators/unknown.js +13 -0
  22. package/dist/cjs/validators/unknown.js.map +1 -0
  23. package/dist/esm/validators/index.d.ts +4 -0
  24. package/dist/esm/validators/index.d.ts.map +1 -1
  25. package/dist/esm/validators/index.js +4 -0
  26. package/dist/esm/validators/index.js.map +1 -1
  27. package/dist/esm/validators/intersection.d.ts +7 -0
  28. package/dist/esm/validators/intersection.d.ts.map +1 -0
  29. package/dist/esm/validators/intersection.js +54 -0
  30. package/dist/esm/validators/intersection.js.map +1 -0
  31. package/dist/esm/validators/nil.d.ts +3 -0
  32. package/dist/esm/validators/nil.d.ts.map +1 -0
  33. package/dist/esm/validators/nil.js +20 -0
  34. package/dist/esm/validators/nil.js.map +1 -0
  35. package/dist/esm/validators/undef.d.ts +3 -0
  36. package/dist/esm/validators/undef.d.ts.map +1 -0
  37. package/dist/esm/validators/undef.js +20 -0
  38. package/dist/esm/validators/undef.js.map +1 -0
  39. package/dist/esm/validators/unknown.d.ts +3 -0
  40. package/dist/esm/validators/unknown.d.ts.map +1 -0
  41. package/dist/esm/validators/unknown.js +9 -0
  42. package/dist/esm/validators/unknown.js.map +1 -0
  43. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,34 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.5.0] - 2026-01-16
9
+
10
+ ### Added
11
+
12
+ - `intersection()` validator for combining multiple schemas (AND logic)
13
+ - `unknown()` validator for validating any type of value
14
+
15
+ ## [0.4.1] - 2026-01-16
16
+
17
+ ### Changed
18
+
19
+ - Updated README with documentation for `undef()` and `nil()` validators
20
+
21
+ ### Fixed
22
+
23
+ - Code formatting issues
24
+
25
+ ## [0.4.0] - 2026-01-16
26
+
27
+ ### Added
28
+
29
+ - `undef()` validator for explicit undefined checks
30
+ - `nil()` validator for explicit null checks
31
+
32
+ ### Changed
33
+
34
+ - Refactored all validator tests to use regex assertions for error messages, improving test resilience
35
+
8
36
  ## [0.3.1] - 2026-01-14
9
37
 
10
38
  ### Changed
package/README.md CHANGED
@@ -287,6 +287,22 @@ recentDateValidator.judge(new Date('2100-01-01')); // ✗ Before min
287
287
 
288
288
  ---
289
289
 
290
+ #### `unknown()`
291
+
292
+ Passthrough validator that accepts any value. Useful for data that hasn't been scanned by the Sibyl System yet.
293
+
294
+ ```typescript
295
+ import { unknown } from 'sibyl-ts';
296
+
297
+ const unscannedEvidenceValidator = unknown();
298
+ unscannedEvidenceValidator.judge('mysterious device'); // ✓
299
+ unscannedEvidenceValidator.judge({ threatLevel: 'unknown' }); // ✓
300
+ ```
301
+
302
+ **Type:** `unknown`
303
+
304
+ ---
305
+
290
306
  ### String Validators
291
307
 
292
308
  #### `email()`
@@ -522,6 +538,31 @@ modeValidator.judge('paralyzer'); // ✓
522
538
 
523
539
  ---
524
540
 
541
+ #### `intersection([...validators])`
542
+
543
+ Intersection type validation (AND logic). Combines multiple validators and deeply merges the results of object validators.
544
+
545
+ ```typescript
546
+ import { intersection, obj, str, num } from 'sibyl-ts';
547
+
548
+ // Combine multiple object schemas
549
+ const personValidator = obj({ name: str() });
550
+ const employeeValidator = obj({ role: str(), salary: num() });
551
+
552
+ // Resulting type is flattened: { name: string; role: string; salary: number }
553
+ const employeeProfileValidator = intersection([personValidator, employeeValidator]);
554
+
555
+ employeeProfileValidator.judge({
556
+ name: 'Akane Tsunemori',
557
+ role: 'Inspector',
558
+ salary: 100000,
559
+ }); // ✓
560
+ ```
561
+
562
+ **Expected input:** Value matching **ALL** validators in the array
563
+
564
+ ---
565
+
525
566
  #### `record(keyValidator, valueValidator)`
526
567
 
527
568
  Record/dictionary validation.
@@ -639,6 +680,40 @@ previousCoefficientValidator.judge(undefined); // ✗
639
680
 
640
681
  ---
641
682
 
683
+ #### `undef()`
684
+
685
+ Explicitly validates `undefined`.
686
+
687
+ ```typescript
688
+ import { undef } from 'sibyl-ts';
689
+
690
+ const undefValidator = undef();
691
+ undefValidator.judge(undefined); // ✓
692
+ undefValidator.judge(null); // ✗
693
+ undefValidator.judge(false); // ✗
694
+ ```
695
+
696
+ **Type:** `undefined`
697
+
698
+ ---
699
+
700
+ #### `nil()`
701
+
702
+ Explicitly validates `null`.
703
+
704
+ ```typescript
705
+ import { nil } from 'sibyl-ts';
706
+
707
+ const nilValidator = nil();
708
+ nilValidator.judge(null); // ✓
709
+ nilValidator.judge(undefined); // ✗
710
+ nilValidator.judge(false); // ✗
711
+ ```
712
+
713
+ **Type:** `null`
714
+
715
+ ---
716
+
642
717
  #### `nullish(validator)`
643
718
 
644
719
  Makes a validator nullish (allows `null` AND `undefined`).
@@ -12,4 +12,8 @@ export * from './tuple';
12
12
  export * from './record';
13
13
  export * from './enum';
14
14
  export * from './date';
15
+ export * from './undef';
16
+ export * from './nil';
17
+ export * from './unknown';
18
+ export * from './intersection';
15
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validators/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validators/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
@@ -28,4 +28,8 @@ __exportStar(require("./tuple"), exports);
28
28
  __exportStar(require("./record"), exports);
29
29
  __exportStar(require("./enum"), exports);
30
30
  __exportStar(require("./date"), exports);
31
+ __exportStar(require("./undef"), exports);
32
+ __exportStar(require("./nil"), exports);
33
+ __exportStar(require("./unknown"), exports);
34
+ __exportStar(require("./intersection"), exports);
31
35
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,0CAAwB;AACxB,4CAA0B;AAC1B,6CAA2B;AAC3B,6CAA2B;AAC3B,4CAA0B;AAC1B,0CAAwB;AACxB,2CAAyB;AACzB,yCAAuB;AACvB,yCAAuB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,0CAAwB;AACxB,4CAA0B;AAC1B,6CAA2B;AAC3B,6CAA2B;AAC3B,4CAA0B;AAC1B,0CAAwB;AACxB,2CAAyB;AACzB,yCAAuB;AACvB,yCAAuB;AACvB,0CAAwB;AACxB,wCAAsB;AACtB,4CAA0B;AAC1B,iDAA+B"}
@@ -0,0 +1,7 @@
1
+ import type { Validator, ExtractValidatorType } from '../common';
2
+ export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
3
+ export type SimplifyDeep<T> = T extends Record<string, unknown> ? {
4
+ [K in keyof T]: SimplifyDeep<T[K]>;
5
+ } & {} : T;
6
+ export declare const intersection: <V extends Validator[]>(validators: [...V]) => Validator<SimplifyDeep<UnionToIntersection<ExtractValidatorType<V[number]>>>>;
7
+ //# sourceMappingURL=intersection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intersection.d.ts","sourceRoot":"","sources":["../../../src/validators/intersection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAKjE,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CACxF,CAAC,EAAE,MAAM,CAAC,KACP,IAAI,GACL,CAAC,GACD,KAAK,CAAC;AAmCV,MAAM,MAAM,YAAY,CAAC,CAAC,IAExB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEtF,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,SAAS,EAAE,EAChD,YAAY,CAAC,GAAG,CAAC,CAAC,KACjB,SAAS,CAAC,YAAY,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAkC9E,CAAC"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.intersection = void 0;
4
+ const withTryJudge_1 = require("../withTryJudge");
5
+ const error_1 = require("../error");
6
+ const isObject = (item) => {
7
+ return (typeof item === 'object' && item !== null && !Array.isArray(item) && !(item instanceof Date));
8
+ };
9
+ // Helper for deep merging objects
10
+ const deepMerge = (target, source) => {
11
+ if (!isObject(target) || !isObject(source)) {
12
+ return source;
13
+ }
14
+ return Object.keys(source).reduce((acc, key) => {
15
+ const targetValue = acc[key];
16
+ const sourceValue = source[key];
17
+ if (key in acc) {
18
+ return {
19
+ ...acc,
20
+ [key]: deepMerge(targetValue, sourceValue),
21
+ };
22
+ }
23
+ return {
24
+ ...acc,
25
+ [key]: sourceValue,
26
+ };
27
+ }, { ...target });
28
+ };
29
+ const intersection = (validators) => {
30
+ return (0, withTryJudge_1.withTryJudge)({
31
+ judge(value) {
32
+ const { result, issues } = validators.reduce((acc, validator) => {
33
+ try {
34
+ const validValue = validator.judge(value);
35
+ return {
36
+ result: acc.result === undefined ? validValue : deepMerge(acc.result, validValue),
37
+ issues: acc.issues,
38
+ };
39
+ }
40
+ catch (error) {
41
+ if (error instanceof error_1.JudgmentError) {
42
+ return {
43
+ result: acc.result,
44
+ issues: [...acc.issues, ...error.issues],
45
+ };
46
+ }
47
+ throw error;
48
+ }
49
+ }, { result: undefined, issues: [] });
50
+ if (issues.length > 0) {
51
+ throw new error_1.JudgmentError(issues);
52
+ }
53
+ return result;
54
+ },
55
+ });
56
+ };
57
+ exports.intersection = intersection;
58
+ //# sourceMappingURL=intersection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intersection.js","sourceRoot":"","sources":["../../../src/validators/intersection.ts"],"names":[],"mappings":";;;AACA,kDAA+C;AAC/C,oCAA6D;AAS7D,MAAM,QAAQ,GAAG,CAAC,IAAa,EAAmC,EAAE;IAClE,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC,CAC7F,CAAC;AACJ,CAAC,CAAC;AAEF,kCAAkC;AAClC,MAAM,SAAS,GAAG,CAAC,MAAe,EAAE,MAAe,EAAW,EAAE;IAC9D,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAC/B,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACX,MAAM,WAAW,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAEhC,IAAI,GAAG,I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qBAAa,CAAC,MAAM,CAAC,CAAC;YAClC,CAAC;YAED,OAAO,MAA4E,CAAC;QACtF,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AApCW,QAAA,YAAY,gBAoCvB"}
@@ -0,0 +1,3 @@
1
+ import { Validator } from '../common';
2
+ export declare const nil: () => Validator<null>;
3
+ //# sourceMappingURL=nil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nil.d.ts","sourceRoot":"","sources":["../../../src/validators/nil.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAItC,eAAO,MAAM,GAAG,QAAO,SAAS,CAAC,IAAI,CAgBpC,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nil = void 0;
4
+ const error_1 = require("../error");
5
+ const getValueType_1 = require("../getValueType");
6
+ const withTryJudge_1 = require("../withTryJudge");
7
+ const nil = () => {
8
+ return (0, withTryJudge_1.withTryJudge)({
9
+ judge(value) {
10
+ if (value === null) {
11
+ return null;
12
+ }
13
+ const valueType = (0, getValueType_1.getValueType)(value);
14
+ throw new error_1.JudgmentError([
15
+ {
16
+ message: `Value is ${valueType}, expected null`,
17
+ path: '',
18
+ },
19
+ ]);
20
+ },
21
+ });
22
+ };
23
+ exports.nil = nil;
24
+ //# sourceMappingURL=nil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nil.js","sourceRoot":"","sources":["../../../src/validators/nil.ts"],"names":[],"mappings":";;;AAAA,oCAAyC;AAEzC,kDAA+C;AAC/C,kDAA+C;AAExC,MAAM,GAAG,GAAG,GAAoB,EAAE;IACvC,OAAO,IAAA,2BAAY,EAAC;QAClB,KAAK,CAAC,KAAK;YACT,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,SAAS,GAAG,IAAA,2BAAY,EAAC,KAAK,CAAC,CAAC;YACtC,MAAM,IAAI,qBAAa,CAAC;gBACtB;oBACE,OAAO,EAAE,YAAY,SAAS,iBAAiB;oBAC/C,IAAI,EAAE,EAAE;iBACT;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAhBW,QAAA,GAAG,OAgBd"}
@@ -0,0 +1,3 @@
1
+ import { Validator } from '../common';
2
+ export declare const undef: () => Validator<undefined>;
3
+ //# sourceMappingURL=undef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"undef.d.ts","sourceRoot":"","sources":["../../../src/validators/undef.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAItC,eAAO,MAAM,KAAK,QAAO,SAAS,CAAC,SAAS,CAgB3C,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.undef = void 0;
4
+ const error_1 = require("../error");
5
+ const getValueType_1 = require("../getValueType");
6
+ const withTryJudge_1 = require("../withTryJudge");
7
+ const undef = () => {
8
+ return (0, withTryJudge_1.withTryJudge)({
9
+ judge(value) {
10
+ if (value === undefined) {
11
+ return undefined;
12
+ }
13
+ const valueType = (0, getValueType_1.getValueType)(value);
14
+ throw new error_1.JudgmentError([
15
+ {
16
+ message: `Value is ${valueType}, expected undefined`,
17
+ path: '',
18
+ },
19
+ ]);
20
+ },
21
+ });
22
+ };
23
+ exports.undef = undef;
24
+ //# sourceMappingURL=undef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"undef.js","sourceRoot":"","sources":["../../../src/validators/undef.ts"],"names":[],"mappings":";;;AAAA,oCAAyC;AAEzC,kDAA+C;AAC/C,kDAA+C;AAExC,MAAM,KAAK,GAAG,GAAyB,EAAE;IAC9C,OAAO,IAAA,2BAAY,EAAC;QAClB,KAAK,CAAC,KAAK;YACT,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,MAAM,SAAS,GAAG,IAAA,2BAAY,EAAC,KAAK,CAAC,CAAC;YACtC,MAAM,IAAI,qBAAa,CAAC;gBACtB;oBACE,OAAO,EAAE,YAAY,SAAS,sBAAsB;oBACpD,IAAI,EAAE,EAAE;iBACT;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAhBW,QAAA,KAAK,SAgBhB"}
@@ -0,0 +1,3 @@
1
+ import type { Validator } from '../common';
2
+ export declare const unknown: () => Validator<unknown>;
3
+ //# sourceMappingURL=unknown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknown.d.ts","sourceRoot":"","sources":["../../../src/validators/unknown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,eAAO,MAAM,OAAO,QAAO,SAAS,CAAC,OAAO,CAM3C,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unknown = void 0;
4
+ const withTryJudge_1 = require("../withTryJudge");
5
+ const unknown = () => {
6
+ return (0, withTryJudge_1.withTryJudge)({
7
+ judge(value) {
8
+ return value;
9
+ },
10
+ });
11
+ };
12
+ exports.unknown = unknown;
13
+ //# sourceMappingURL=unknown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../src/validators/unknown.ts"],"names":[],"mappings":";;;AACA,kDAA+C;AAExC,MAAM,OAAO,GAAG,GAAuB,EAAE;IAC9C,OAAO,IAAA,2BAAY,EAAC;QAClB,KAAK,CAAC,KAAK;YACT,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AANW,QAAA,OAAO,WAMlB"}
@@ -12,4 +12,8 @@ export * from './tuple';
12
12
  export * from './record';
13
13
  export * from './enum';
14
14
  export * from './date';
15
+ export * from './undef';
16
+ export * from './nil';
17
+ export * from './unknown';
18
+ export * from './intersection';
15
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validators/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validators/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
@@ -12,4 +12,8 @@ export * from './tuple';
12
12
  export * from './record';
13
13
  export * from './enum';
14
14
  export * from './date';
15
+ export * from './undef';
16
+ export * from './nil';
17
+ export * from './unknown';
18
+ export * from './intersection';
15
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validators/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validators/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Validator, ExtractValidatorType } from '../common';
2
+ export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
3
+ export type SimplifyDeep<T> = T extends Record<string, unknown> ? {
4
+ [K in keyof T]: SimplifyDeep<T[K]>;
5
+ } & {} : T;
6
+ export declare const intersection: <V extends Validator[]>(validators: [...V]) => Validator<SimplifyDeep<UnionToIntersection<ExtractValidatorType<V[number]>>>>;
7
+ //# sourceMappingURL=intersection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intersection.d.ts","sourceRoot":"","sources":["../../../src/validators/intersection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAKjE,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CACxF,CAAC,EAAE,MAAM,CAAC,KACP,IAAI,GACL,CAAC,GACD,KAAK,CAAC;AAmCV,MAAM,MAAM,YAAY,CAAC,CAAC,IAExB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEtF,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,SAAS,EAAE,EAChD,YAAY,CAAC,GAAG,CAAC,CAAC,KACjB,SAAS,CAAC,YAAY,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAkC9E,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { withTryJudge } from '../withTryJudge';
2
+ import { JudgmentError } from '../error';
3
+ const isObject = (item) => {
4
+ return (typeof item === 'object' && item !== null && !Array.isArray(item) && !(item instanceof Date));
5
+ };
6
+ // Helper for deep merging objects
7
+ const deepMerge = (target, source) => {
8
+ if (!isObject(target) || !isObject(source)) {
9
+ return source;
10
+ }
11
+ return Object.keys(source).reduce((acc, key) => {
12
+ const targetValue = acc[key];
13
+ const sourceValue = source[key];
14
+ if (key in acc) {
15
+ return {
16
+ ...acc,
17
+ [key]: deepMerge(targetValue, sourceValue),
18
+ };
19
+ }
20
+ return {
21
+ ...acc,
22
+ [key]: sourceValue,
23
+ };
24
+ }, { ...target });
25
+ };
26
+ export const intersection = (validators) => {
27
+ return withTryJudge({
28
+ judge(value) {
29
+ const { result, issues } = validators.reduce((acc, validator) => {
30
+ try {
31
+ const validValue = validator.judge(value);
32
+ return {
33
+ result: acc.result === undefined ? validValue : deepMerge(acc.result, validValue),
34
+ issues: acc.issues,
35
+ };
36
+ }
37
+ catch (error) {
38
+ if (error instanceof JudgmentError) {
39
+ return {
40
+ result: acc.result,
41
+ issues: [...acc.issues, ...error.issues],
42
+ };
43
+ }
44
+ throw error;
45
+ }
46
+ }, { result: undefined, issues: [] });
47
+ if (issues.length > 0) {
48
+ throw new JudgmentError(issues);
49
+ }
50
+ return result;
51
+ },
52
+ });
53
+ };
54
+ //# sourceMappingURL=intersection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intersection.js","sourceRoot":"","sources":["../../../src/validators/intersection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAsB,MAAM,UAAU,CAAC;AAS7D,MAAM,QAAQ,GAAG,CAAC,IAAa,EAAmC,EAAE;IAClE,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC,CAC7F,CAAC;AACJ,CAAC,CAAC;AAEF,kCAAkC;AAClC,MAAM,SAAS,GAAG,CAAC,MAAe,EAAE,MAAe,EAAW,EAAE;IAC9D,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAC/B,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACX,MAAM,WAAW,GAAG,GAAG,CAAC,GAAG,CAAC,CA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ClC,CAAC;YAEF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACtB,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;YAClC,CAAC;YAED,OAAO,MAA4E,CAAC;QACtF,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Validator } from '../common';
2
+ export declare const nil: () => Validator<null>;
3
+ //# sourceMappingURL=nil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nil.d.ts","sourceRoot":"","sources":["../../../src/validators/nil.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAItC,eAAO,MAAM,GAAG,QAAO,SAAS,CAAC,IAAI,CAgBpC,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { JudgmentError } from '../error';
2
+ import { getValueType } from '../getValueType';
3
+ import { withTryJudge } from '../withTryJudge';
4
+ export const nil = () => {
5
+ return withTryJudge({
6
+ judge(value) {
7
+ if (value === null) {
8
+ return null;
9
+ }
10
+ const valueType = getValueType(value);
11
+ throw new JudgmentError([
12
+ {
13
+ message: `Value is ${valueType}, expected null`,
14
+ path: '',
15
+ },
16
+ ]);
17
+ },
18
+ });
19
+ };
20
+ //# sourceMappingURL=nil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nil.js","sourceRoot":"","sources":["../../../src/validators/nil.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,CAAC,MAAM,GAAG,GAAG,GAAoB,EAAE;IACvC,OAAO,YAAY,CAAC;QAClB,KAAK,CAAC,KAAK;YACT,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YACtC,MAAM,IAAI,aAAa,CAAC;gBACtB;oBACE,OAAO,EAAE,YAAY,SAAS,iBAAiB;oBAC/C,IAAI,EAAE,EAAE;iBACT;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Validator } from '../common';
2
+ export declare const undef: () => Validator<undefined>;
3
+ //# sourceMappingURL=undef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"undef.d.ts","sourceRoot":"","sources":["../../../src/validators/undef.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAItC,eAAO,MAAM,KAAK,QAAO,SAAS,CAAC,SAAS,CAgB3C,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { JudgmentError } from '../error';
2
+ import { getValueType } from '../getValueType';
3
+ import { withTryJudge } from '../withTryJudge';
4
+ export const undef = () => {
5
+ return withTryJudge({
6
+ judge(value) {
7
+ if (value === undefined) {
8
+ return undefined;
9
+ }
10
+ const valueType = getValueType(value);
11
+ throw new JudgmentError([
12
+ {
13
+ message: `Value is ${valueType}, expected undefined`,
14
+ path: '',
15
+ },
16
+ ]);
17
+ },
18
+ });
19
+ };
20
+ //# sourceMappingURL=undef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"undef.js","sourceRoot":"","sources":["../../../src/validators/undef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,CAAC,MAAM,KAAK,GAAG,GAAyB,EAAE;IAC9C,OAAO,YAAY,CAAC;QAClB,KAAK,CAAC,KAAK;YACT,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YACtC,MAAM,IAAI,aAAa,CAAC;gBACtB;oBACE,OAAO,EAAE,YAAY,SAAS,sBAAsB;oBACpD,IAAI,EAAE,EAAE;iBACT;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Validator } from '../common';
2
+ export declare const unknown: () => Validator<unknown>;
3
+ //# sourceMappingURL=unknown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknown.d.ts","sourceRoot":"","sources":["../../../src/validators/unknown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,eAAO,MAAM,OAAO,QAAO,SAAS,CAAC,OAAO,CAM3C,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { withTryJudge } from '../withTryJudge';
2
+ export const unknown = () => {
3
+ return withTryJudge({
4
+ judge(value) {
5
+ return value;
6
+ },
7
+ });
8
+ };
9
+ //# sourceMappingURL=unknown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../src/validators/unknown.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,GAAuB,EAAE;IAC9C,OAAO,YAAY,CAAC;QAClB,KAAK,CAAC,KAAK;YACT,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sibyl-ts",
3
- "version": "0.3.1",
3
+ "version": "0.5.0",
4
4
  "description": "TypeScript validation library with type-safe validators",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",