@elliots/typical 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/config.d.ts +11 -0
- package/dist/src/config.js +42 -0
- package/dist/src/config.js.map +1 -1
- package/dist/src/transformer.d.ts +51 -9
- package/dist/src/transformer.js +726 -226
- package/dist/src/transformer.js.map +1 -1
- package/package.json +3 -2
- package/src/config.ts +49 -0
- package/src/transformer.ts +888 -289
package/dist/src/config.d.ts
CHANGED
|
@@ -14,6 +14,17 @@ export interface TypicalConfig {
|
|
|
14
14
|
* Example: ["React.*", "Express.Request", "*.Event"]
|
|
15
15
|
*/
|
|
16
16
|
ignoreTypes?: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Skip validation for DOM types (Document, Element, Node, etc.) and their subclasses.
|
|
19
|
+
* These types have complex Window intersections that typia cannot process.
|
|
20
|
+
* Default: true
|
|
21
|
+
*/
|
|
22
|
+
ignoreDOMTypes?: boolean;
|
|
17
23
|
}
|
|
18
24
|
export declare const defaultConfig: TypicalConfig;
|
|
25
|
+
/**
|
|
26
|
+
* DOM types that typia cannot process due to Window global intersections.
|
|
27
|
+
* These are the base DOM types - classes extending them are checked separately.
|
|
28
|
+
*/
|
|
29
|
+
export declare const DOM_TYPES_TO_IGNORE: string[];
|
|
19
30
|
export declare function loadConfig(configPath?: string): TypicalConfig;
|
package/dist/src/config.js
CHANGED
|
@@ -4,10 +4,52 @@ export const defaultConfig = {
|
|
|
4
4
|
reusableValidators: true,
|
|
5
5
|
validateCasts: false,
|
|
6
6
|
hoistRegex: true,
|
|
7
|
+
ignoreDOMTypes: true,
|
|
7
8
|
debug: {
|
|
8
9
|
writeIntermediateFiles: false,
|
|
9
10
|
},
|
|
10
11
|
};
|
|
12
|
+
// FIXME: find a better way to work out which types to ignore
|
|
13
|
+
/**
|
|
14
|
+
* DOM types that typia cannot process due to Window global intersections.
|
|
15
|
+
* These are the base DOM types - classes extending them are checked separately.
|
|
16
|
+
*/
|
|
17
|
+
export const DOM_TYPES_TO_IGNORE = [
|
|
18
|
+
// Core DOM types
|
|
19
|
+
"Document",
|
|
20
|
+
"DocumentFragment",
|
|
21
|
+
"Element",
|
|
22
|
+
"Node",
|
|
23
|
+
"ShadowRoot",
|
|
24
|
+
"Window",
|
|
25
|
+
"EventTarget",
|
|
26
|
+
// HTML Elements
|
|
27
|
+
"HTML*Element",
|
|
28
|
+
"HTMLElement",
|
|
29
|
+
"HTMLCollection",
|
|
30
|
+
// SVG Elements
|
|
31
|
+
"SVG*Element",
|
|
32
|
+
"SVGElement",
|
|
33
|
+
// Events
|
|
34
|
+
"*Event",
|
|
35
|
+
// Other common DOM types
|
|
36
|
+
"NodeList",
|
|
37
|
+
"DOMTokenList",
|
|
38
|
+
"NamedNodeMap",
|
|
39
|
+
"CSSStyleDeclaration",
|
|
40
|
+
"Selection",
|
|
41
|
+
"Range",
|
|
42
|
+
"Text",
|
|
43
|
+
"Comment",
|
|
44
|
+
"CDATASection",
|
|
45
|
+
"ProcessingInstruction",
|
|
46
|
+
"DocumentType",
|
|
47
|
+
"Attr",
|
|
48
|
+
"Table",
|
|
49
|
+
"TableRow",
|
|
50
|
+
"TableCell",
|
|
51
|
+
"StyleSheet",
|
|
52
|
+
];
|
|
11
53
|
import fs from 'fs';
|
|
12
54
|
import path from 'path';
|
|
13
55
|
export function loadConfig(configPath) {
|
package/dist/src/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAyBA,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,OAAO,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC;IAChC,OAAO,EAAE,CAAC,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,CAAC;IAChE,kBAAkB,E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AAC,CAAC;YAClE,OAAO,aAAa,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -14,33 +14,64 @@ export declare class TypicalTransformer {
|
|
|
14
14
|
private typeParsers;
|
|
15
15
|
constructor(config?: TypicalConfig, program?: ts.Program, tsInstance?: typeof ts);
|
|
16
16
|
createSourceFile(fileName: string, content: string): ts.SourceFile;
|
|
17
|
-
transform(sourceFile: ts.SourceFile | string, mode: "basic" | "typia" | "js"): string;
|
|
18
|
-
|
|
17
|
+
transform(sourceFile: ts.SourceFile | string, mode: "basic" | "typia" | "js", skippedTypes?: Set<string>): string;
|
|
18
|
+
/**
|
|
19
|
+
* Apply typia transformation in a separate ts.transform() context.
|
|
20
|
+
* This avoids mixing program contexts and eliminates the need for import recreation.
|
|
21
|
+
* Returns either the transformed code string, or a retry signal with the failed type.
|
|
22
|
+
*/
|
|
23
|
+
private applyTypiaTransform;
|
|
19
24
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* and eliding the import as "unused".
|
|
25
|
+
* Get a transformer that only applies typical's transformations (no typia).
|
|
26
|
+
* @param skippedTypes Set of type strings to skip validation for (used for retry after typia errors)
|
|
23
27
|
*/
|
|
24
|
-
private
|
|
28
|
+
private getTypicalOnlyTransformer;
|
|
29
|
+
/**
|
|
30
|
+
* Get a combined transformer for use with ts-patch/ttsc.
|
|
31
|
+
* This is used by the TSC plugin where we need a single transformer factory.
|
|
32
|
+
*
|
|
33
|
+
* Note: Even for ts-patch, we need to create a new program with the transformed
|
|
34
|
+
* source so typia can resolve the types from our generated typia.createAssert<T>() calls.
|
|
35
|
+
*/
|
|
36
|
+
getTransformer(withTypia: boolean): ts.TransformerFactory<ts.SourceFile>;
|
|
25
37
|
/**
|
|
26
38
|
* Transform a single source file with TypeScript AST
|
|
27
39
|
*/
|
|
28
40
|
private transformSourceFile;
|
|
29
41
|
shouldTransformFile(fileName: string): boolean;
|
|
30
42
|
/**
|
|
31
|
-
* Check if a TypeNode represents
|
|
32
|
-
*
|
|
43
|
+
* Check if a TypeNode represents a type that shouldn't be validated.
|
|
44
|
+
* This includes:
|
|
45
|
+
* - any/unknown (intentional escape hatches)
|
|
46
|
+
* - Type parameters (generics like T)
|
|
47
|
+
* - Constructor types (new (...args: any[]) => T)
|
|
48
|
+
* - Function types ((...args) => T)
|
|
33
49
|
*/
|
|
34
50
|
private isAnyOrUnknownType;
|
|
35
51
|
/**
|
|
36
|
-
* Check if a
|
|
52
|
+
* Check if a type contains any unvalidatable parts (type parameters, constructor types, etc.)
|
|
53
|
+
* This recursively checks intersection and union types.
|
|
54
|
+
*/
|
|
55
|
+
private containsUnvalidatableType;
|
|
56
|
+
/**
|
|
57
|
+
* Check if a Type has any or unknown flags, or is a type parameter or function/constructor.
|
|
37
58
|
*/
|
|
38
59
|
private isAnyOrUnknownTypeFlags;
|
|
39
60
|
/**
|
|
40
61
|
* Check if a type name matches any of the ignoreTypes patterns.
|
|
41
62
|
* Supports wildcards: "React.*" matches "React.FormEvent", "React.ChangeEvent", etc.
|
|
63
|
+
* Also handles union types: "Document | Element" is ignored if "Document" or "Element" is in ignoreTypes.
|
|
42
64
|
*/
|
|
43
65
|
private isIgnoredType;
|
|
66
|
+
/**
|
|
67
|
+
* Check if a single type (not a union) should be ignored.
|
|
68
|
+
* Checks both the type name and its base classes.
|
|
69
|
+
*/
|
|
70
|
+
private isIgnoredSingleType;
|
|
71
|
+
/**
|
|
72
|
+
* Check if a single type name matches any ignore pattern.
|
|
73
|
+
*/
|
|
74
|
+
private matchesIgnorePattern;
|
|
44
75
|
/**
|
|
45
76
|
* Find untransformed typia calls in the output code.
|
|
46
77
|
* These indicate types that typia could not process.
|
|
@@ -73,6 +104,17 @@ export declare class TypicalTransformer {
|
|
|
73
104
|
* getTypeFromTypeNode doesn't work correctly on them
|
|
74
105
|
*/
|
|
75
106
|
private getTypeKey;
|
|
107
|
+
/**
|
|
108
|
+
* Simple string hash for creating unique identifiers from type strings.
|
|
109
|
+
*/
|
|
110
|
+
private hashString;
|
|
111
|
+
/**
|
|
112
|
+
* Format typia's error message into a cleaner list format.
|
|
113
|
+
* Typia outputs verbose messages like:
|
|
114
|
+
* "unsupported type detected\n\n- Window.ondevicemotion: unknown\n - nonsensible intersection\n\n- Window.ondeviceorientation..."
|
|
115
|
+
* We want to extract just the problematic types and their issues.
|
|
116
|
+
*/
|
|
117
|
+
private formatTypiaError;
|
|
76
118
|
/**
|
|
77
119
|
* Creates a readable name suffix from a type string.
|
|
78
120
|
* For simple identifiers like "User" or "string", returns the name directly.
|