typia 13.2.0 → 14.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.
- package/lib/http.d.ts +3 -3
- package/lib/http.js.map +1 -1
- package/lib/http.mjs.map +1 -1
- package/lib/internal/_assertGuard.js +13 -3
- package/lib/internal/_assertGuard.js.map +1 -1
- package/lib/internal/_assertGuard.mjs +4 -2
- package/lib/internal/_assertGuard.mjs.map +1 -1
- package/lib/internal/_isFormatIdnHostname.js +5 -1
- package/lib/internal/_isFormatIdnHostname.js.map +1 -1
- package/lib/internal/_isFormatIdnHostname.mjs +1 -1
- package/lib/internal/_isFormatIdnHostname.mjs.map +1 -1
- package/lib/internal/_isFormatTime.js +19 -2
- package/lib/internal/_isFormatTime.js.map +1 -1
- package/lib/internal/_isFormatTime.mjs +9 -2
- package/lib/internal/_isFormatTime.mjs.map +1 -1
- package/lib/internal/_randomArray.js +37 -4
- package/lib/internal/_randomArray.js.map +1 -1
- package/lib/internal/_randomArray.mjs +16 -3
- package/lib/internal/_randomArray.mjs.map +1 -1
- package/lib/internal/_randomFormatByte.js +15 -12
- package/lib/internal/_randomFormatByte.js.map +1 -1
- package/lib/internal/_randomFormatByte.mjs +11 -10
- package/lib/internal/_randomFormatByte.mjs.map +1 -1
- package/lib/internal/_randomFormatDatetime.mjs +1 -1
- package/lib/internal/_randomFormatHostname.d.ts +2 -2
- package/lib/internal/_randomFormatHostname.js +2 -2
- package/lib/internal/_randomFormatHostname.mjs +2 -2
- package/lib/internal/_randomFormatHostname.mjs.map +1 -1
- package/lib/internal/_randomFormatIdnHostname.js +9 -10
- package/lib/internal/_randomFormatIdnHostname.js.map +1 -1
- package/lib/internal/_randomFormatIdnHostname.mjs +3 -4
- package/lib/internal/_randomFormatIdnHostname.mjs.map +1 -1
- package/lib/internal/_randomFormatRegex.js +4 -4
- package/lib/internal/_randomFormatRegex.js.map +1 -1
- package/lib/internal/_randomFormatRegex.mjs +1 -2
- package/lib/internal/_randomFormatRegex.mjs.map +1 -1
- package/lib/internal/_randomFormatTime.js +15 -10
- package/lib/internal/_randomFormatTime.js.map +1 -1
- package/lib/internal/_randomFormatTime.mjs +6 -3
- package/lib/internal/_randomFormatTime.mjs.map +1 -1
- package/lib/internal/_randomPattern.js +20 -3
- package/lib/internal/_randomPattern.js.map +1 -1
- package/lib/internal/_randomPattern.mjs +5 -1
- package/lib/internal/_randomPattern.mjs.map +1 -1
- package/lib/internal/_randomStringLength.js +9 -2
- package/lib/internal/_randomStringLength.js.map +1 -1
- package/lib/internal/_randomStringLength.mjs +3 -1
- package/lib/internal/_randomStringLength.mjs.map +1 -1
- package/lib/internal/private/__randomComposition.d.ts +8 -0
- package/lib/internal/private/__randomComposition.js +21 -1
- package/lib/internal/private/__randomComposition.js.map +1 -1
- package/lib/internal/private/__randomComposition.mjs +18 -1
- package/lib/internal/private/__randomComposition.mjs.map +1 -1
- package/lib/json.d.ts +2 -2
- package/lib/json.js.map +1 -1
- package/lib/json.mjs.map +1 -1
- package/lib/module.d.ts +28 -13
- package/lib/module.js.map +1 -1
- package/lib/module.mjs.map +1 -1
- package/lib/notations.d.ts +4 -4
- package/lib/notations.js.map +1 -1
- package/lib/notations.mjs.map +1 -1
- package/lib/plain.d.ts +3 -3
- package/lib/plain.js.map +1 -1
- package/lib/plain.mjs.map +1 -1
- package/lib/protobuf.d.ts +2 -2
- package/lib/protobuf.js.map +1 -1
- package/lib/protobuf.mjs.map +1 -1
- package/lib/transform.mjs +1 -1
- package/native/cmd/ttsc-typia/assert_guard_factory_contract_test.go +17 -4
- package/native/cmd/ttsc-typia/create_assert_error_factory_arity_test.go +309 -0
- package/native/cmd/ttsc-typia/dynamic_key_tags_transform_test.go +206 -0
- package/native/cmd/ttsc-typia/local_function_named_like_typia_operation_transform_test.go +185 -0
- package/native/cmd/ttsc-typia/notation_kebab_case_transform_test.go +2 -2
- package/native/cmd/ttsc-typia/project_catalog_transform_coverage_test.go +84 -85
- package/native/cmd/ttsc-typia/recursive_conditional_alias_name_transform_test.go +307 -0
- package/native/cmd/ttsc-typia/shadowed_typia_module_declaration_diagnostic_test.go +152 -0
- package/native/cmd/ttsc-typia/transform.go +2 -2
- package/native/cmd/ttsc-typia/transform_helpers_test.go +96 -18
- package/native/core/factories/FormatCheatSheet.go +2 -2
- package/native/core/factories/MetadataCommentTagFactory.go +91 -7
- package/native/core/factories/factory_utility_coverage_test.go +896 -907
- package/native/core/factories/internal/metadata/MetadataHelper.go +5 -28
- package/native/core/factories/metadata_comment_tag_factory_rejects_out_of_range_integer_test.go +124 -0
- package/native/core/programmers/AssertProgrammer.go +20 -6
- package/native/core/programmers/RandomProgrammer.go +78 -3
- package/native/core/programmers/ValidateProgrammer.go +21 -6
- package/native/core/programmers/helpers/RandomJoiner.go +8 -1
- package/native/core/programmers/iterate/check_dynamic_properties.go +177 -3
- package/native/core/programmers/iterate/check_object.go +12 -1
- package/native/core/schemas/metadata/MetadataCollection.go +47 -5
- package/native/transform/CallExpressionTransformer.go +167 -0
- package/package.json +3 -12
- package/src/http.ts +18 -4
- package/src/internal/_assertGuard.ts +13 -2
- package/src/internal/_isFormatIdnHostname.ts +5 -1
- package/src/internal/_isFormatTime.ts +19 -2
- package/src/internal/_randomArray.ts +42 -6
- package/src/internal/_randomFormatByte.ts +17 -12
- package/src/internal/_randomFormatHostname.ts +2 -2
- package/src/internal/_randomFormatIdnHostname.ts +8 -9
- package/src/internal/_randomFormatRegex.ts +4 -6
- package/src/internal/_randomFormatTime.ts +15 -10
- package/src/internal/_randomPattern.ts +18 -3
- package/src/internal/_randomStringLength.ts +9 -2
- package/src/internal/private/__randomComposition.ts +24 -0
- package/src/json.ts +16 -4
- package/src/module.ts +56 -22
- package/src/notations.ts +16 -4
- package/src/plain.ts +12 -3
- package/src/protobuf.ts +16 -4
- package/lib/executable/FileSystemIdentity.d.ts +0 -44
- package/lib/executable/FileSystemIdentity.js +0 -213
- package/lib/executable/FileSystemIdentity.js.map +0 -1
- package/lib/executable/FileSystemIdentity.mjs +0 -133
- package/lib/executable/FileSystemIdentity.mjs.map +0 -1
- package/lib/executable/TypiaGenerateWizard.d.ts +0 -9
- package/lib/executable/TypiaGenerateWizard.js +0 -852
- package/lib/executable/TypiaGenerateWizard.js.map +0 -1
- package/lib/executable/TypiaGenerateWizard.mjs +0 -618
- package/lib/executable/TypiaGenerateWizard.mjs.map +0 -1
- package/lib/executable/generate/ttsc.d.ts +0 -1
- package/lib/executable/generate/ttsc.js +0 -53
- package/lib/executable/generate/ttsc.js.map +0 -1
- package/lib/executable/generate/ttsc.mjs +0 -37
- package/lib/executable/generate/ttsc.mjs.map +0 -1
- package/lib/executable/typia.d.ts +0 -2
- package/lib/executable/typia.js +0 -84
- package/lib/executable/typia.js.map +0 -1
- package/lib/executable/typia.mjs +0 -60
- package/lib/executable/typia.mjs.map +0 -1
- package/src/executable/FileSystemIdentity.ts +0 -222
- package/src/executable/TypiaGenerateWizard.ts +0 -1133
- package/src/executable/generate/ttsc.ts +0 -70
- package/src/executable/typia.ts +0 -80
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import RandExp from "randexp";
|
|
2
2
|
|
|
3
3
|
import { _ILengthProps } from "./_randomStringLength";
|
|
4
|
+
import { _stringLength } from "./_stringLength";
|
|
4
5
|
|
|
5
6
|
export const _randomPattern = (
|
|
6
7
|
regex: RegExp,
|
|
@@ -16,14 +17,28 @@ export const _randomPattern = (
|
|
|
16
17
|
if (max !== undefined) r.max = max;
|
|
17
18
|
else if (min !== undefined && min * 2 > r.max) r.max = min * 2;
|
|
18
19
|
|
|
20
|
+
// The verification counts characters, not UTF-16 code units, because that is
|
|
21
|
+
// what `MinLength` and `MaxLength` compare against. `Pattern` compiles to a
|
|
22
|
+
// flagless `RegExp`, so a quantifier binds one code unit wherever its atom is
|
|
23
|
+
// a bare astral character: under `^😀+$` the `+` repeats the trailing low
|
|
24
|
+
// surrogate alone, and RandExp draws `\ud83d` + k * `\ude00` -- k characters
|
|
25
|
+
// in k + 1 code units. Measuring in code units accepted a two-character draw
|
|
26
|
+
// for `MinLength<3>` and handed back a value the generated validator rejects.
|
|
27
|
+
// Group the atom (`^(?:😀)+$`) and the arithmetic changes to 2k units for k
|
|
28
|
+
// characters; the two counts still differ, which is the point.
|
|
29
|
+
//
|
|
30
|
+
// The count is taken only after the pattern matches, and only when a bound
|
|
31
|
+
// exists, so an unbounded draw still walks nothing.
|
|
19
32
|
const bounded: boolean = min !== undefined || max !== undefined;
|
|
20
33
|
const limit: number = bounded ? 1024 : 10;
|
|
21
34
|
for (let i: number = 0; i < limit; ++i) {
|
|
22
35
|
const str: string = r.gen();
|
|
36
|
+
if (regex.test(str) === false) continue;
|
|
37
|
+
if (bounded === false) return str;
|
|
38
|
+
const length: number = _stringLength(str);
|
|
23
39
|
if (
|
|
24
|
-
|
|
25
|
-
(
|
|
26
|
-
(max === undefined || str.length <= max)
|
|
40
|
+
(min === undefined || length >= min) &&
|
|
41
|
+
(max === undefined || length <= max)
|
|
27
42
|
)
|
|
28
43
|
return str;
|
|
29
44
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { _randomInteger } from "./_randomInteger";
|
|
2
2
|
import { _randomString } from "./_randomString";
|
|
3
|
+
import { _stringLength } from "./_stringLength";
|
|
3
4
|
|
|
4
5
|
export const _RANDOM_LENGTH_ERROR =
|
|
5
6
|
"unable to generate a random string satisfying both the format and the length constraints.";
|
|
@@ -106,9 +107,15 @@ export const _randomFormatLength = (
|
|
|
106
107
|
return generate();
|
|
107
108
|
for (let i: number = 0; i < 256; ++i) {
|
|
108
109
|
const value: string = generate();
|
|
110
|
+
// Characters, not UTF-16 code units: `minLength` and `maxLength` are the
|
|
111
|
+
// bounds the generated validator compares in characters. `uuid` and `date`,
|
|
112
|
+
// the only two shapes routed through here, are ASCII, so the two counts
|
|
113
|
+
// agree for them today -- this keeps one measure so a later non-ASCII
|
|
114
|
+
// format cannot reintroduce the divergence unnoticed.
|
|
115
|
+
const length: number = _stringLength(value);
|
|
109
116
|
if (
|
|
110
|
-
(props.minLength === undefined ||
|
|
111
|
-
(props.maxLength === undefined ||
|
|
117
|
+
(props.minLength === undefined || length >= props.minLength) &&
|
|
118
|
+
(props.maxLength === undefined || length <= props.maxLength)
|
|
112
119
|
)
|
|
113
120
|
return value;
|
|
114
121
|
}
|
|
@@ -34,6 +34,30 @@ export const __randomComposition = (props: {
|
|
|
34
34
|
return parts;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Draws `length` characters of the base64 alphabet.
|
|
39
|
+
*
|
|
40
|
+
* The caller passes a multiple of four, which `format: "byte"` accepts without
|
|
41
|
+
* padding; every character below is in the alphabet its validator spells out,
|
|
42
|
+
* so the result needs no encoding step.
|
|
43
|
+
*/
|
|
44
|
+
export const __randomBase64 = (length: number): string => {
|
|
45
|
+
let text: string = "";
|
|
46
|
+
for (let i: number = 0; i < length; ++i)
|
|
47
|
+
text +=
|
|
48
|
+
BASE64[
|
|
49
|
+
_randomInteger({
|
|
50
|
+
type: "integer",
|
|
51
|
+
minimum: 0,
|
|
52
|
+
maximum: BASE64.length - 1,
|
|
53
|
+
})
|
|
54
|
+
];
|
|
55
|
+
return text;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const BASE64 =
|
|
59
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
60
|
+
|
|
37
61
|
/** Draws `length` decimal digits, leading zeros included. */
|
|
38
62
|
export const __randomDigits = (length: number): string => {
|
|
39
63
|
let text: string = "";
|
package/src/json.ts
CHANGED
|
@@ -431,10 +431,16 @@ export function createAssertParse(
|
|
|
431
431
|
*/
|
|
432
432
|
export function createAssertParse<T>(
|
|
433
433
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
434
|
-
): (
|
|
434
|
+
): (
|
|
435
|
+
input: string,
|
|
436
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
437
|
+
) => Primitive<T>;
|
|
435
438
|
|
|
436
439
|
/** @internal */
|
|
437
|
-
export function createAssertParse<T>(): (
|
|
440
|
+
export function createAssertParse<T>(): (
|
|
441
|
+
input: string,
|
|
442
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
443
|
+
) => Primitive<T> {
|
|
438
444
|
NoTransformConfigurationError("json.createAssertParse");
|
|
439
445
|
}
|
|
440
446
|
|
|
@@ -501,10 +507,16 @@ export function createAssertStringify(
|
|
|
501
507
|
*/
|
|
502
508
|
export function createAssertStringify<T>(
|
|
503
509
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
504
|
-
): (
|
|
510
|
+
): (
|
|
511
|
+
input: unknown,
|
|
512
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
513
|
+
) => string;
|
|
505
514
|
|
|
506
515
|
/** @internal */
|
|
507
|
-
export function createAssertStringify(): (
|
|
516
|
+
export function createAssertStringify(): (
|
|
517
|
+
input: unknown,
|
|
518
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
519
|
+
) => string {
|
|
508
520
|
NoTransformConfigurationError("json.createAssertStringify");
|
|
509
521
|
}
|
|
510
522
|
|
package/src/module.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
-
import {
|
|
3
|
-
AssertionGuard,
|
|
4
|
-
IRandomGenerator,
|
|
5
|
-
IValidation,
|
|
6
|
-
Resolved,
|
|
7
|
-
} from "@typia/interface";
|
|
2
|
+
import { IRandomGenerator, IValidation, Resolved } from "@typia/interface";
|
|
8
3
|
|
|
9
4
|
import { TypeGuardError } from "./TypeGuardError";
|
|
10
5
|
import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
|
|
@@ -577,7 +572,7 @@ export function random(): never {
|
|
|
577
572
|
* @template T Target type to validate against
|
|
578
573
|
* @param errorFactory Custom error factory receiving
|
|
579
574
|
* {@link TypeGuardError.IProps}
|
|
580
|
-
* @returns Reusable assert function `(input: unknown) => T`
|
|
575
|
+
* @returns Reusable assert function `(input: unknown, errorFactory?) => T`
|
|
581
576
|
* @danger You must configure the generic argument `T`
|
|
582
577
|
*/
|
|
583
578
|
export function createAssert(
|
|
@@ -593,14 +588,21 @@ export function createAssert(
|
|
|
593
588
|
* @template T Target type to validate against
|
|
594
589
|
* @param errorFactory Custom error factory receiving
|
|
595
590
|
* {@link TypeGuardError.IProps}
|
|
596
|
-
* @returns Reusable assert function `(input: unknown) => T
|
|
591
|
+
* @returns Reusable assert function `(input: unknown, errorFactory?) => T`,
|
|
592
|
+
* whose own `errorFactory` overrides this one for that single call
|
|
597
593
|
*/
|
|
598
594
|
export function createAssert<T>(
|
|
599
595
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
600
|
-
): (
|
|
596
|
+
): (
|
|
597
|
+
input: unknown,
|
|
598
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
599
|
+
) => T;
|
|
601
600
|
|
|
602
601
|
/** @internal */
|
|
603
|
-
export function createAssert<T>(): (
|
|
602
|
+
export function createAssert<T>(): (
|
|
603
|
+
input: unknown,
|
|
604
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
605
|
+
) => T {
|
|
604
606
|
NoTransformConfigurationError("createAssert");
|
|
605
607
|
}
|
|
606
608
|
|
|
@@ -611,6 +613,9 @@ export function createAssert<T>(): (input: unknown) => T {
|
|
|
611
613
|
*
|
|
612
614
|
* TypeScript requirement: You must declare the variable type explicitly. `const
|
|
613
615
|
* fn: AssertionGuard<T> = createAssertGuard<T>()` — otherwise compile error.
|
|
616
|
+
* That annotation is one parameter wide, so it also hides the call-time
|
|
617
|
+
* `errorFactory`; annotate with `(input: unknown, errorFactory?: (props:
|
|
618
|
+
* TypeGuardError.IProps) => Error) => asserts input is T` when you need it.
|
|
614
619
|
*
|
|
615
620
|
* @template T Target type to validate against
|
|
616
621
|
* @param errorFactory Custom error factory receiving
|
|
@@ -629,18 +634,28 @@ export function createAssertGuard(
|
|
|
629
634
|
*
|
|
630
635
|
* TypeScript requirement: You must declare the variable type explicitly. `const
|
|
631
636
|
* fn: AssertionGuard<T> = createAssertGuard<T>()` — otherwise compile error.
|
|
637
|
+
* That annotation is one parameter wide, so it also hides the call-time
|
|
638
|
+
* `errorFactory`; annotate with `(input: unknown, errorFactory?: (props:
|
|
639
|
+
* TypeGuardError.IProps) => Error) => asserts input is T` when you need it.
|
|
632
640
|
*
|
|
633
641
|
* @template T Target type to validate against
|
|
634
642
|
* @param errorFactory Custom error factory receiving
|
|
635
643
|
* {@link TypeGuardError.IProps}
|
|
636
|
-
* @returns Reusable assertion guard function
|
|
644
|
+
* @returns Reusable assertion guard function, whose own `errorFactory`
|
|
645
|
+
* overrides this one for that single call
|
|
637
646
|
*/
|
|
638
647
|
export function createAssertGuard<T>(
|
|
639
648
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
640
|
-
):
|
|
649
|
+
): (
|
|
650
|
+
input: unknown,
|
|
651
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
652
|
+
) => asserts input is T;
|
|
641
653
|
|
|
642
654
|
/** @internal */
|
|
643
|
-
export function createAssertGuard<T>():
|
|
655
|
+
export function createAssertGuard<T>(): (
|
|
656
|
+
input: unknown,
|
|
657
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
658
|
+
) => asserts input is T {
|
|
644
659
|
NoTransformConfigurationError("createAssertGuard");
|
|
645
660
|
}
|
|
646
661
|
|
|
@@ -747,7 +762,8 @@ export function createValidate(): ((input: unknown) => IValidation) &
|
|
|
747
762
|
* @template T Target type for exact match
|
|
748
763
|
* @param errorFactory Custom error factory receiving
|
|
749
764
|
* {@link TypeGuardError.IProps}
|
|
750
|
-
* @returns Reusable assertEquals function `(input: unknown) =>
|
|
765
|
+
* @returns Reusable assertEquals function `(input: unknown, errorFactory?) =>
|
|
766
|
+
* T`
|
|
751
767
|
* @danger You must configure the generic argument `T`
|
|
752
768
|
*/
|
|
753
769
|
export function createAssertEquals(
|
|
@@ -763,14 +779,21 @@ export function createAssertEquals(
|
|
|
763
779
|
* @template T Target type for exact match
|
|
764
780
|
* @param errorFactory Custom error factory receiving
|
|
765
781
|
* {@link TypeGuardError.IProps}
|
|
766
|
-
* @returns Reusable assertEquals function `(input: unknown) =>
|
|
782
|
+
* @returns Reusable assertEquals function `(input: unknown, errorFactory?) =>
|
|
783
|
+
* T`, whose own `errorFactory` overrides this one for that single call
|
|
767
784
|
*/
|
|
768
785
|
export function createAssertEquals<T>(
|
|
769
786
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
770
|
-
): (
|
|
787
|
+
): (
|
|
788
|
+
input: unknown,
|
|
789
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
790
|
+
) => T;
|
|
771
791
|
|
|
772
792
|
/** @internal */
|
|
773
|
-
export function createAssertEquals<T>(): (
|
|
793
|
+
export function createAssertEquals<T>(): (
|
|
794
|
+
input: unknown,
|
|
795
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
796
|
+
) => T {
|
|
774
797
|
NoTransformConfigurationError("createAssertEquals");
|
|
775
798
|
}
|
|
776
799
|
|
|
@@ -781,7 +804,9 @@ export function createAssertEquals<T>(): (input: unknown) => T {
|
|
|
781
804
|
*
|
|
782
805
|
* TypeScript requirement: You must declare the variable type explicitly. `const
|
|
783
806
|
* fn: AssertionGuard<T> = createAssertGuardEquals<T>()` — otherwise compile
|
|
784
|
-
* error.
|
|
807
|
+
* error. That annotation is one parameter wide, so it also hides the call-time
|
|
808
|
+
* `errorFactory`; annotate with `(input: unknown, errorFactory?: (props:
|
|
809
|
+
* TypeGuardError.IProps) => Error) => asserts input is T` when you need it.
|
|
785
810
|
*
|
|
786
811
|
* @template T Target type for exact match
|
|
787
812
|
* @param errorFactory Custom error factory receiving
|
|
@@ -800,19 +825,28 @@ export function createAssertGuardEquals(
|
|
|
800
825
|
*
|
|
801
826
|
* TypeScript requirement: You must declare the variable type explicitly. `const
|
|
802
827
|
* fn: AssertionGuard<T> = createAssertGuardEquals<T>()` — otherwise compile
|
|
803
|
-
* error.
|
|
828
|
+
* error. That annotation is one parameter wide, so it also hides the call-time
|
|
829
|
+
* `errorFactory`; annotate with `(input: unknown, errorFactory?: (props:
|
|
830
|
+
* TypeGuardError.IProps) => Error) => asserts input is T` when you need it.
|
|
804
831
|
*
|
|
805
832
|
* @template T Target type for exact match
|
|
806
833
|
* @param errorFactory Custom error factory receiving
|
|
807
834
|
* {@link TypeGuardError.IProps}
|
|
808
|
-
* @returns Reusable assertion guard function
|
|
835
|
+
* @returns Reusable assertion guard function, whose own `errorFactory`
|
|
836
|
+
* overrides this one for that single call
|
|
809
837
|
*/
|
|
810
838
|
export function createAssertGuardEquals<T>(
|
|
811
839
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
812
|
-
):
|
|
840
|
+
): (
|
|
841
|
+
input: unknown,
|
|
842
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
843
|
+
) => asserts input is T;
|
|
813
844
|
|
|
814
845
|
/** @internal */
|
|
815
|
-
export function createAssertGuardEquals<T>():
|
|
846
|
+
export function createAssertGuardEquals<T>(): (
|
|
847
|
+
input: unknown,
|
|
848
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
849
|
+
) => asserts input is T {
|
|
816
850
|
NoTransformConfigurationError("createAssertGuardEquals");
|
|
817
851
|
}
|
|
818
852
|
|
package/src/notations.ts
CHANGED
|
@@ -530,7 +530,10 @@ export function createAssertCamel(
|
|
|
530
530
|
*/
|
|
531
531
|
export function createAssertCamel<T>(
|
|
532
532
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
533
|
-
): (
|
|
533
|
+
): (
|
|
534
|
+
input: T,
|
|
535
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
536
|
+
) => CamelCase<T>;
|
|
534
537
|
|
|
535
538
|
/** @internal */
|
|
536
539
|
export function createAssertCamel(): never {
|
|
@@ -618,7 +621,10 @@ export function createAssertPascal(
|
|
|
618
621
|
*/
|
|
619
622
|
export function createAssertPascal<T>(
|
|
620
623
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
621
|
-
): (
|
|
624
|
+
): (
|
|
625
|
+
input: T,
|
|
626
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
627
|
+
) => PascalCase<T>;
|
|
622
628
|
|
|
623
629
|
/** @internal */
|
|
624
630
|
export function createAssertPascal(): never {
|
|
@@ -706,7 +712,10 @@ export function createAssertSnake(
|
|
|
706
712
|
*/
|
|
707
713
|
export function createAssertSnake<T>(
|
|
708
714
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
709
|
-
): (
|
|
715
|
+
): (
|
|
716
|
+
input: T,
|
|
717
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
718
|
+
) => SnakeCase<T>;
|
|
710
719
|
|
|
711
720
|
/** @internal */
|
|
712
721
|
export function createAssertSnake(): never {
|
|
@@ -794,7 +803,10 @@ export function createAssertKebab(
|
|
|
794
803
|
*/
|
|
795
804
|
export function createAssertKebab<T>(
|
|
796
805
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
797
|
-
): (
|
|
806
|
+
): (
|
|
807
|
+
input: T,
|
|
808
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
809
|
+
) => KebabCase<T>;
|
|
798
810
|
|
|
799
811
|
/** @internal */
|
|
800
812
|
export function createAssertKebab(): never {
|
package/src/plain.ts
CHANGED
|
@@ -383,7 +383,10 @@ export function createAssertClone(
|
|
|
383
383
|
*/
|
|
384
384
|
export function createAssertClone<T>(
|
|
385
385
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
386
|
-
): (
|
|
386
|
+
): (
|
|
387
|
+
input: unknown,
|
|
388
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
389
|
+
) => Resolved<T>;
|
|
387
390
|
|
|
388
391
|
/** @internal */
|
|
389
392
|
export function createAssertClone(): never {
|
|
@@ -471,7 +474,10 @@ export function createAssertPrune(
|
|
|
471
474
|
*/
|
|
472
475
|
export function createAssertPrune<T extends object>(
|
|
473
476
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
474
|
-
): (
|
|
477
|
+
): (
|
|
478
|
+
input: unknown,
|
|
479
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
480
|
+
) => T;
|
|
475
481
|
|
|
476
482
|
/** @internal */
|
|
477
483
|
export function createAssertPrune(): never {
|
|
@@ -563,7 +569,10 @@ export function createAssertClassify(
|
|
|
563
569
|
*/
|
|
564
570
|
export function createAssertClassify<T>(
|
|
565
571
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
566
|
-
): (
|
|
572
|
+
): (
|
|
573
|
+
input: unknown,
|
|
574
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
575
|
+
) => ClassifyResult<T>;
|
|
567
576
|
|
|
568
577
|
/** @internal */
|
|
569
578
|
export function createAssertClassify(): never {
|
package/src/protobuf.ts
CHANGED
|
@@ -377,10 +377,16 @@ export function createAssertDecode(
|
|
|
377
377
|
*/
|
|
378
378
|
export function createAssertDecode<T>(
|
|
379
379
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
380
|
-
): (
|
|
380
|
+
): (
|
|
381
|
+
input: Uint8Array,
|
|
382
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
383
|
+
) => Resolved<T>;
|
|
381
384
|
|
|
382
385
|
/** @internal */
|
|
383
|
-
export function createAssertDecode<T>(): (
|
|
386
|
+
export function createAssertDecode<T>(): (
|
|
387
|
+
input: Uint8Array,
|
|
388
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
389
|
+
) => Resolved<T> {
|
|
384
390
|
NoTransformConfigurationError("protobuf.createAssertDecode");
|
|
385
391
|
}
|
|
386
392
|
|
|
@@ -467,10 +473,16 @@ export function createAssertEncode(
|
|
|
467
473
|
*/
|
|
468
474
|
export function createAssertEncode<T>(
|
|
469
475
|
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
470
|
-
): (
|
|
476
|
+
): (
|
|
477
|
+
input: T,
|
|
478
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
479
|
+
) => Uint8Array;
|
|
471
480
|
|
|
472
481
|
/** @internal */
|
|
473
|
-
export function createAssertEncode<T>(): (
|
|
482
|
+
export function createAssertEncode<T>(): (
|
|
483
|
+
input: T,
|
|
484
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
485
|
+
) => Uint8Array {
|
|
474
486
|
NoTransformConfigurationError("protobuf.createAssertEncode");
|
|
475
487
|
}
|
|
476
488
|
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
export declare namespace FileSystemIdentity {
|
|
4
|
-
interface IIdentity {
|
|
5
|
-
readonly caseSensitive: boolean;
|
|
6
|
-
contains(file: string, directory: string): boolean;
|
|
7
|
-
filesystemKey(file: string): string;
|
|
8
|
-
isDeclarationFile(file: string): boolean;
|
|
9
|
-
isSamePath(x: string, y: string): boolean;
|
|
10
|
-
isSupportedExtension(file: string): boolean;
|
|
11
|
-
projectFileKey(file: string): string;
|
|
12
|
-
}
|
|
13
|
-
function create(caseSensitive: boolean, pathApi?: typeof path.posix): IIdentity;
|
|
14
|
-
class Policy {
|
|
15
|
-
private caseSensitive_;
|
|
16
|
-
private location_;
|
|
17
|
-
observe(caseSensitive: boolean | undefined, location: string): void;
|
|
18
|
-
get(): IIdentity;
|
|
19
|
-
}
|
|
20
|
-
function inspectDirectory(directory: string): Promise<boolean | undefined>;
|
|
21
|
-
function probeDirectory(directory: string): Promise<boolean>;
|
|
22
|
-
/**
|
|
23
|
-
* Builds the key that decides whether two paths are the same filesystem
|
|
24
|
-
* object.
|
|
25
|
-
*
|
|
26
|
-
* The identity is read from `fs.BigIntStats` rather than `fs.Stats`, because
|
|
27
|
-
* `fs.Stats.ino` is a JavaScript number. An NTFS file ID is `(sequenceNumber
|
|
28
|
-
* << 48) | mftRecordIndex` and routinely exceeds `Number.MAX_SAFE_INTEGER` —
|
|
29
|
-
* in a 4000-directory probe, 1879 of them did — where the spacing between
|
|
30
|
-
* representable doubles is 8 or more. Two entries sharing a sequence number
|
|
31
|
-
* with MFT record indices within that spacing round to one double. The
|
|
32
|
-
* traversal callers would then treat a distinct directory or file as already
|
|
33
|
-
* visited and skip it with no diagnostic, and the overwrite guard would
|
|
34
|
-
* refuse a legitimate output (samchon/typia#2269).
|
|
35
|
-
*
|
|
36
|
-
* A filesystem that reports no inode at all keeps the canonical path
|
|
37
|
-
* fallback, which is the only identity available there.
|
|
38
|
-
*
|
|
39
|
-
* @param stat Stats read with `{ bigint: true }`.
|
|
40
|
-
* @param realpath Canonical path of the same object.
|
|
41
|
-
* @returns Key that is equal for two paths only when they are one object.
|
|
42
|
-
*/
|
|
43
|
-
function identityKey(stat: Pick<fs.BigIntStats, "dev" | "ino">, realpath: string): string;
|
|
44
|
-
}
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.FileSystemIdentity = void 0;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
var FileSystemIdentity;
|
|
19
|
-
(function (FileSystemIdentity) {
|
|
20
|
-
function create(caseSensitive, pathApi = path_1.default) {
|
|
21
|
-
const fold = (value) => caseSensitive ? value : value.toLowerCase();
|
|
22
|
-
const filesystemKey = (file) => fold(pathApi.normalize(file));
|
|
23
|
-
return {
|
|
24
|
-
caseSensitive,
|
|
25
|
-
contains: (file, directory) => {
|
|
26
|
-
const fileKey = filesystemKey(pathApi.resolve(file));
|
|
27
|
-
const directoryKey = filesystemKey(pathApi.resolve(directory));
|
|
28
|
-
const prefix = directoryKey.endsWith(pathApi.sep)
|
|
29
|
-
? directoryKey
|
|
30
|
-
: `${directoryKey}${pathApi.sep}`;
|
|
31
|
-
return fileKey === directoryKey || fileKey.startsWith(prefix);
|
|
32
|
-
},
|
|
33
|
-
filesystemKey,
|
|
34
|
-
isDeclarationFile: (file) => DTS_PATTERN.test(fold(pathApi.basename(file))),
|
|
35
|
-
isSamePath: (x, y) => filesystemKey(x) === filesystemKey(y),
|
|
36
|
-
isSupportedExtension: (file) => {
|
|
37
|
-
const filename = fold(pathApi.basename(file));
|
|
38
|
-
return (TS_PATTERN.test(filename) && DTS_PATTERN.test(filename) === false);
|
|
39
|
-
},
|
|
40
|
-
projectFileKey: fold,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
FileSystemIdentity.create = create;
|
|
44
|
-
class Policy {
|
|
45
|
-
observe(caseSensitive, location) {
|
|
46
|
-
if (caseSensitive === undefined)
|
|
47
|
-
return;
|
|
48
|
-
if (this.caseSensitive_ === undefined) {
|
|
49
|
-
this.caseSensitive_ = caseSensitive;
|
|
50
|
-
this.location_ = location;
|
|
51
|
-
}
|
|
52
|
-
else if (this.caseSensitive_ !== caseSensitive) {
|
|
53
|
-
throw new URIError(`Error on TypiaGenerateWizard.generate(): inconsistent filesystem case behavior between ${this.location_} and ${location}.`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
get() {
|
|
57
|
-
if (this.caseSensitive_ === undefined) {
|
|
58
|
-
throw new URIError("Error on TypiaGenerateWizard.generate(): unable to determine filesystem case behavior for this run.");
|
|
59
|
-
}
|
|
60
|
-
return create(this.caseSensitive_);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
FileSystemIdentity.Policy = Policy;
|
|
64
|
-
function inspectDirectory(directory) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const names = yield fs_1.default.promises.readdir(directory);
|
|
67
|
-
const entries = new Set(names);
|
|
68
|
-
for (const name of names) {
|
|
69
|
-
const alternate = alternateCase(name);
|
|
70
|
-
if (alternate === undefined)
|
|
71
|
-
continue;
|
|
72
|
-
if (entries.has(alternate))
|
|
73
|
-
return true;
|
|
74
|
-
try {
|
|
75
|
-
yield fs_1.default.promises.lstat(path_1.default.join(directory, alternate));
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
if (isMissingFileError(error))
|
|
80
|
-
return true;
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return undefined;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
FileSystemIdentity.inspectDirectory = inspectDirectory;
|
|
88
|
-
function probeDirectory(directory) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
const inspected = yield inspectDirectory(directory);
|
|
91
|
-
if (inspected !== undefined)
|
|
92
|
-
return inspected;
|
|
93
|
-
for (let attempt = 0; attempt < 10; ++attempt) {
|
|
94
|
-
const name = `.typia-case-probe-${process.pid}-${Date.now()}-${Math.random()
|
|
95
|
-
.toString(36)
|
|
96
|
-
.slice(2)}`.toLowerCase();
|
|
97
|
-
const original = path_1.default.join(directory, name);
|
|
98
|
-
const alternate = path_1.default.join(directory, name.toUpperCase());
|
|
99
|
-
let handle;
|
|
100
|
-
try {
|
|
101
|
-
handle = yield fs_1.default.promises.open(original, "wx");
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
if (isAlreadyExistsError(error))
|
|
105
|
-
continue;
|
|
106
|
-
throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to probe filesystem case behavior at ${directory}: ${formatUnknownError(error)}`);
|
|
107
|
-
}
|
|
108
|
-
let closed = false;
|
|
109
|
-
try {
|
|
110
|
-
yield handle.close();
|
|
111
|
-
closed = true;
|
|
112
|
-
try {
|
|
113
|
-
yield fs_1.default.promises.lstat(alternate);
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
if (isMissingFileError(error))
|
|
118
|
-
return true;
|
|
119
|
-
throw error;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
finally {
|
|
123
|
-
let cleanupError;
|
|
124
|
-
if (closed === false) {
|
|
125
|
-
try {
|
|
126
|
-
yield handle.close();
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
cleanupError = error;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
yield fs_1.default.promises.unlink(original);
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
if (isMissingFileError(error) === false)
|
|
137
|
-
cleanupError !== null && cleanupError !== void 0 ? cleanupError : (cleanupError = error);
|
|
138
|
-
}
|
|
139
|
-
if (cleanupError !== undefined) {
|
|
140
|
-
throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to clean filesystem case probe ${original}: ${formatUnknownError(cleanupError)}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
throw new URIError(`Error on TypiaGenerateWizard.generate(): unable to reserve a filesystem case probe at ${directory}.`);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
FileSystemIdentity.probeDirectory = probeDirectory;
|
|
148
|
-
/**
|
|
149
|
-
* Builds the key that decides whether two paths are the same filesystem
|
|
150
|
-
* object.
|
|
151
|
-
*
|
|
152
|
-
* The identity is read from `fs.BigIntStats` rather than `fs.Stats`, because
|
|
153
|
-
* `fs.Stats.ino` is a JavaScript number. An NTFS file ID is `(sequenceNumber
|
|
154
|
-
* << 48) | mftRecordIndex` and routinely exceeds `Number.MAX_SAFE_INTEGER` —
|
|
155
|
-
* in a 4000-directory probe, 1879 of them did — where the spacing between
|
|
156
|
-
* representable doubles is 8 or more. Two entries sharing a sequence number
|
|
157
|
-
* with MFT record indices within that spacing round to one double. The
|
|
158
|
-
* traversal callers would then treat a distinct directory or file as already
|
|
159
|
-
* visited and skip it with no diagnostic, and the overwrite guard would
|
|
160
|
-
* refuse a legitimate output (samchon/typia#2269).
|
|
161
|
-
*
|
|
162
|
-
* A filesystem that reports no inode at all keeps the canonical path
|
|
163
|
-
* fallback, which is the only identity available there.
|
|
164
|
-
*
|
|
165
|
-
* @param stat Stats read with `{ bigint: true }`.
|
|
166
|
-
* @param realpath Canonical path of the same object.
|
|
167
|
-
* @returns Key that is equal for two paths only when they are one object.
|
|
168
|
-
*/
|
|
169
|
-
function identityKey(stat, realpath) {
|
|
170
|
-
// `BigInt(0)` rather than `0n`: this package compiles at ES2016, where a
|
|
171
|
-
// BigInt literal is a syntax error, while the constructor and the `bigint`
|
|
172
|
-
// type are fine.
|
|
173
|
-
return stat.ino === BigInt(0)
|
|
174
|
-
? `path:${path_1.default.normalize(realpath)}`
|
|
175
|
-
: `inode:${stat.dev}:${stat.ino}`;
|
|
176
|
-
}
|
|
177
|
-
FileSystemIdentity.identityKey = identityKey;
|
|
178
|
-
function alternateCase(name) {
|
|
179
|
-
let changed = false;
|
|
180
|
-
let output = "";
|
|
181
|
-
for (const character of name) {
|
|
182
|
-
if (character >= "a" && character <= "z") {
|
|
183
|
-
output += character.toUpperCase();
|
|
184
|
-
changed = true;
|
|
185
|
-
}
|
|
186
|
-
else if (character >= "A" && character <= "Z") {
|
|
187
|
-
output += character.toLowerCase();
|
|
188
|
-
changed = true;
|
|
189
|
-
}
|
|
190
|
-
else
|
|
191
|
-
output += character;
|
|
192
|
-
}
|
|
193
|
-
return changed ? output : undefined;
|
|
194
|
-
}
|
|
195
|
-
function isAlreadyExistsError(error) {
|
|
196
|
-
return (typeof error === "object" &&
|
|
197
|
-
error !== null &&
|
|
198
|
-
"code" in error &&
|
|
199
|
-
error.code === "EEXIST");
|
|
200
|
-
}
|
|
201
|
-
function isMissingFileError(error) {
|
|
202
|
-
return (typeof error === "object" &&
|
|
203
|
-
error !== null &&
|
|
204
|
-
"code" in error &&
|
|
205
|
-
error.code === "ENOENT");
|
|
206
|
-
}
|
|
207
|
-
function formatUnknownError(error) {
|
|
208
|
-
return error instanceof Error ? error.message : String(error);
|
|
209
|
-
}
|
|
210
|
-
})(FileSystemIdentity || (exports.FileSystemIdentity = FileSystemIdentity = {}));
|
|
211
|
-
const TS_PATTERN = /\.[cm]?tsx?$/;
|
|
212
|
-
const DTS_PATTERN = /\.d\.[cm]?tsx?$/;
|
|
213
|
-
//# sourceMappingURL=FileSystemIdentity.js.map
|