typia 4.1.0 → 4.1.1-dev.20230621
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/factories/internal/metadata/iterate_metadata_array.js +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_array.js.map +1 -1
- package/lib/module.d.ts +2 -2
- package/package.json +3 -2
- package/src/factories/CommentFactory.ts +64 -64
- package/src/factories/IdentifierFactory.ts +59 -59
- package/src/factories/MetadataFactory.ts +30 -30
- package/src/factories/internal/metadata/iterate_metadata_array.ts +1 -2
- package/src/metadata/MetadataObject.ts +118 -118
- package/src/module.ts +2038 -2038
- package/src/programmers/ApplicationProgrammer.ts +47 -47
- package/src/programmers/AssertCloneProgrammer.ts +71 -71
- package/src/programmers/AssertParseProgrammer.ts +66 -66
- package/src/programmers/AssertProgrammer.ts +279 -279
- package/src/programmers/AssertPruneProgrammer.ts +68 -68
- package/src/programmers/AssertStringifyProgrammer.ts +66 -66
- package/src/programmers/CloneProgrammer.ts +587 -587
- package/src/programmers/IsCloneProgrammer.ts +78 -78
- package/src/programmers/IsParseProgrammer.ts +72 -72
- package/src/programmers/IsProgrammer.ts +239 -239
- package/src/programmers/IsPruneProgrammer.ts +73 -73
- package/src/programmers/IsStringifyProgrammer.ts +76 -76
- package/src/programmers/LiteralsProgrammer.ts +60 -60
- package/src/programmers/PruneProgrammer.ts +542 -542
- package/src/programmers/RandomProgrammer.ts +581 -581
- package/src/programmers/StringifyProgrammer.ts +978 -978
- package/src/programmers/ValidateCloneProgrammer.ts +85 -85
- package/src/programmers/ValidateParseProgrammer.ts +70 -70
- package/src/programmers/ValidateProgrammer.ts +305 -305
- package/src/programmers/ValidatePruneProgrammer.ts +78 -78
- package/src/programmers/ValidateStringifyProgrammer.ts +84 -84
- package/src/programmers/internal/application_tuple.ts +57 -57
- package/src/programmers/internal/feature_object_entries.ts +63 -63
- package/src/schemas/IJsonSchema.ts +133 -133
|
@@ -7,7 +7,7 @@ var iterate_metadata_array = function (checker) {
|
|
|
7
7
|
return function (options) {
|
|
8
8
|
return function (collection) {
|
|
9
9
|
return function (meta, type) {
|
|
10
|
-
if (!checker.isArrayType(type)
|
|
10
|
+
if (!checker.isArrayType(type))
|
|
11
11
|
return false;
|
|
12
12
|
var array = (0, emplace_metadata_array_1.emplace_metadata_array)(checker)(options)(collection)(type, meta.nullable);
|
|
13
13
|
ArrayUtil_1.ArrayUtil.add(meta.arrays, array, function (elem) { return elem.name === array.name; });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterate_metadata_array.js","sourceRoot":"","sources":["../../../../src/factories/internal/metadata/iterate_metadata_array.ts"],"names":[],"mappings":";;;AAKA,sDAAqD;AAIrD,mEAAkE;AAE3D,IAAM,sBAAsB,GAC/B,UAAC,OAAuB;IACxB,OAAA,UAAC,OAAiC;QAClC,OAAA,UAAC,UAA8B;YAC/B,OAAA,UAAC,IAAc,EAAE,IAAa;gBAC1B,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC
|
|
1
|
+
{"version":3,"file":"iterate_metadata_array.js","sourceRoot":"","sources":["../../../../src/factories/internal/metadata/iterate_metadata_array.ts"],"names":[],"mappings":";;;AAKA,sDAAqD;AAIrD,mEAAkE;AAE3D,IAAM,sBAAsB,GAC/B,UAAC,OAAuB;IACxB,OAAA,UAAC,OAAiC;QAClC,OAAA,UAAC,UAA8B;YAC/B,OAAA,UAAC,IAAc,EAAE,IAAa;gBAC1B,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC;oBAAE,OAAO,KAAK,CAAC;gBAE7C,IAAM,KAAK,GAAkB,IAAA,+CAAsB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CACjE,UAAU,CACb,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACvB,qBAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EAAxB,CAAwB,CAAC,CAAC;gBACtE,OAAO,IAAI,CAAC;YAChB,CAAC;QARD,CAQC;IATD,CASC;AAVD,CAUC,CAAC;AAZO,QAAA,sBAAsB,0BAY7B"}
|
package/lib/module.d.ts
CHANGED
|
@@ -723,7 +723,7 @@ export declare function random<T>(generator?: Partial<IRandomGenerator>): Primit
|
|
|
723
723
|
* Converts a union literal type to an array of its members.
|
|
724
724
|
*
|
|
725
725
|
* ```typescript
|
|
726
|
-
* literals<"A" | "B" | 1>; // [
|
|
726
|
+
* literals<"A" | "B" | 1>; // ["A", "B", 1]
|
|
727
727
|
* ```
|
|
728
728
|
*
|
|
729
729
|
* @template T Union literal type
|
|
@@ -738,7 +738,7 @@ export declare function literals(): never;
|
|
|
738
738
|
* Converts a union literal type to an array of its members.
|
|
739
739
|
*
|
|
740
740
|
* ```typescript
|
|
741
|
-
* literals<"A" | "B" | 1>; // [
|
|
741
|
+
* literals<"A" | "B" | 1>; // ["A", "B", 1]
|
|
742
742
|
* ```
|
|
743
743
|
*
|
|
744
744
|
* @template T Union literal type
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typia",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1-dev.20230621",
|
|
4
4
|
"description": "Superfast runtime validators with only one line",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -74,7 +74,8 @@
|
|
|
74
74
|
"commander": "^10.0.0",
|
|
75
75
|
"comment-json": "^4.2.3",
|
|
76
76
|
"inquirer": "^8.2.5",
|
|
77
|
-
"randexp": "^0.5.3"
|
|
77
|
+
"randexp": "^0.5.3",
|
|
78
|
+
"raw-loader": "^4.0.2"
|
|
78
79
|
},
|
|
79
80
|
"peerDependencies": {
|
|
80
81
|
"typescript": ">= 4.7.4"
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace CommentFactory {
|
|
4
|
-
export const description = (symbol: ts.Symbol): string | undefined => {
|
|
5
|
-
const node = symbol.declarations?.[0];
|
|
6
|
-
if (!node) return undefined;
|
|
7
|
-
|
|
8
|
-
const range = ts.getCommentRange(node);
|
|
9
|
-
const text: string = node
|
|
10
|
-
.getSourceFile()
|
|
11
|
-
.text.substring(range.pos, range.end);
|
|
12
|
-
const output: string = transform(text).join("\n");
|
|
13
|
-
return output.length ? output : undefined;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const merge = (comments: ts.SymbolDisplayPart[]): string =>
|
|
17
|
-
comments
|
|
18
|
-
.map((part) => part.text)
|
|
19
|
-
.map((str) => str.split("\r\n").join("\n"))
|
|
20
|
-
.join("");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const transform = (text: string): string[] => {
|
|
24
|
-
const elements: string[] = text.split("\r\n").join("\n").split("\n");
|
|
25
|
-
const first: number = lastIndexOf(elements)((elem) =>
|
|
26
|
-
elem.trim().startsWith("/**"),
|
|
27
|
-
);
|
|
28
|
-
const last: number = lastIndexOf(elements)((elem) =>
|
|
29
|
-
elem.trim().endsWith("*/"),
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const cut: string[] = elements.slice(first, last + 1);
|
|
33
|
-
return cut
|
|
34
|
-
.map((elem, i) => {
|
|
35
|
-
if (i === 0) elem = elem.substring(elem.lastIndexOf("/**") + 3);
|
|
36
|
-
if (i === cut.length - 1)
|
|
37
|
-
elem = elem.substring(0, elem.lastIndexOf("*/"));
|
|
38
|
-
return trim(elem);
|
|
39
|
-
})
|
|
40
|
-
.filter(
|
|
41
|
-
(str, i, array) =>
|
|
42
|
-
(i !== 0 && i !== array.length - 1) || !!str.length,
|
|
43
|
-
);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const lastIndexOf =
|
|
47
|
-
<T>(array: T[]) =>
|
|
48
|
-
(pred: (elem: T) => boolean) => {
|
|
49
|
-
for (let i = array.length - 1; i >= 0; i--)
|
|
50
|
-
if (pred(array[i]!)) return i;
|
|
51
|
-
return -1;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const trim = (str: string): string => {
|
|
55
|
-
const vulnerable = (ch: string) =>
|
|
56
|
-
ch === " " || ch === "\n" || ch === "\t" || ch === "*";
|
|
57
|
-
let start: number;
|
|
58
|
-
let end: number;
|
|
59
|
-
for (start = 0; start < str.length; ++start)
|
|
60
|
-
if (!vulnerable(str.charAt(start))) break;
|
|
61
|
-
for (end = str.length - 1; end >= 0; --end)
|
|
62
|
-
if (!vulnerable(str.charAt(end))) break;
|
|
63
|
-
return start > end ? "" : str.substring(start, end + 1).trim();
|
|
64
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace CommentFactory {
|
|
4
|
+
export const description = (symbol: ts.Symbol): string | undefined => {
|
|
5
|
+
const node = symbol.declarations?.[0];
|
|
6
|
+
if (!node) return undefined;
|
|
7
|
+
|
|
8
|
+
const range = ts.getCommentRange(node);
|
|
9
|
+
const text: string = node
|
|
10
|
+
.getSourceFile()
|
|
11
|
+
.text.substring(range.pos, range.end);
|
|
12
|
+
const output: string = transform(text).join("\n");
|
|
13
|
+
return output.length ? output : undefined;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const merge = (comments: ts.SymbolDisplayPart[]): string =>
|
|
17
|
+
comments
|
|
18
|
+
.map((part) => part.text)
|
|
19
|
+
.map((str) => str.split("\r\n").join("\n"))
|
|
20
|
+
.join("");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const transform = (text: string): string[] => {
|
|
24
|
+
const elements: string[] = text.split("\r\n").join("\n").split("\n");
|
|
25
|
+
const first: number = lastIndexOf(elements)((elem) =>
|
|
26
|
+
elem.trim().startsWith("/**"),
|
|
27
|
+
);
|
|
28
|
+
const last: number = lastIndexOf(elements)((elem) =>
|
|
29
|
+
elem.trim().endsWith("*/"),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const cut: string[] = elements.slice(first, last + 1);
|
|
33
|
+
return cut
|
|
34
|
+
.map((elem, i) => {
|
|
35
|
+
if (i === 0) elem = elem.substring(elem.lastIndexOf("/**") + 3);
|
|
36
|
+
if (i === cut.length - 1)
|
|
37
|
+
elem = elem.substring(0, elem.lastIndexOf("*/"));
|
|
38
|
+
return trim(elem);
|
|
39
|
+
})
|
|
40
|
+
.filter(
|
|
41
|
+
(str, i, array) =>
|
|
42
|
+
(i !== 0 && i !== array.length - 1) || !!str.length,
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const lastIndexOf =
|
|
47
|
+
<T>(array: T[]) =>
|
|
48
|
+
(pred: (elem: T) => boolean) => {
|
|
49
|
+
for (let i = array.length - 1; i >= 0; i--)
|
|
50
|
+
if (pred(array[i]!)) return i;
|
|
51
|
+
return -1;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const trim = (str: string): string => {
|
|
55
|
+
const vulnerable = (ch: string) =>
|
|
56
|
+
ch === " " || ch === "\n" || ch === "\t" || ch === "*";
|
|
57
|
+
let start: number;
|
|
58
|
+
let end: number;
|
|
59
|
+
for (start = 0; start < str.length; ++start)
|
|
60
|
+
if (!vulnerable(str.charAt(start))) break;
|
|
61
|
+
for (end = str.length - 1; end >= 0; --end)
|
|
62
|
+
if (!vulnerable(str.charAt(end))) break;
|
|
63
|
+
return start > end ? "" : str.substring(start, end + 1).trim();
|
|
64
|
+
};
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Escaper } from "../utils/Escaper";
|
|
4
|
-
|
|
5
|
-
import { TypeFactory } from "./TypeFactory";
|
|
6
|
-
|
|
7
|
-
export namespace IdentifierFactory {
|
|
8
|
-
export const identifier = (name: string) =>
|
|
9
|
-
Escaper.variable(name)
|
|
10
|
-
? ts.factory.createIdentifier(name)
|
|
11
|
-
: ts.factory.createStringLiteral(name);
|
|
12
|
-
|
|
13
|
-
export const access = (target: ts.Expression) => (property: string) => {
|
|
14
|
-
const postfix = identifier(property);
|
|
15
|
-
return ts.isStringLiteral(postfix)
|
|
16
|
-
? ts.factory.createElementAccessExpression(target, postfix)
|
|
17
|
-
: ts.factory.createPropertyAccessExpression(target, postfix);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const postfix = (str: string): string =>
|
|
21
|
-
Escaper.variable(str)
|
|
22
|
-
? `".${str}"`
|
|
23
|
-
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
24
|
-
|
|
25
|
-
export const parameter = (
|
|
26
|
-
name: string | ts.BindingName,
|
|
27
|
-
type?: ts.TypeNode,
|
|
28
|
-
init?: ts.Expression | ts.PunctuationToken<ts.SyntaxKind.QuestionToken>,
|
|
29
|
-
) => {
|
|
30
|
-
// instead of ts.version >= "4.8"
|
|
31
|
-
if (ts.getDecorators !== undefined)
|
|
32
|
-
return ts.factory.createParameterDeclaration(
|
|
33
|
-
undefined,
|
|
34
|
-
undefined,
|
|
35
|
-
name,
|
|
36
|
-
init?.kind === ts.SyntaxKind.QuestionToken
|
|
37
|
-
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
38
|
-
: undefined,
|
|
39
|
-
type ?? TypeFactory.keyword("any"),
|
|
40
|
-
init && init.kind !== ts.SyntaxKind.QuestionToken
|
|
41
|
-
? init
|
|
42
|
-
: undefined,
|
|
43
|
-
);
|
|
44
|
-
// eslint-disable-next-line
|
|
45
|
-
return (ts.factory.createParameterDeclaration as any)(
|
|
46
|
-
undefined,
|
|
47
|
-
undefined,
|
|
48
|
-
undefined,
|
|
49
|
-
name,
|
|
50
|
-
init?.kind === ts.SyntaxKind.QuestionToken
|
|
51
|
-
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
52
|
-
: undefined,
|
|
53
|
-
type,
|
|
54
|
-
init && init.kind !== ts.SyntaxKind.QuestionToken
|
|
55
|
-
? init
|
|
56
|
-
: undefined,
|
|
57
|
-
);
|
|
58
|
-
};
|
|
59
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Escaper } from "../utils/Escaper";
|
|
4
|
+
|
|
5
|
+
import { TypeFactory } from "./TypeFactory";
|
|
6
|
+
|
|
7
|
+
export namespace IdentifierFactory {
|
|
8
|
+
export const identifier = (name: string) =>
|
|
9
|
+
Escaper.variable(name)
|
|
10
|
+
? ts.factory.createIdentifier(name)
|
|
11
|
+
: ts.factory.createStringLiteral(name);
|
|
12
|
+
|
|
13
|
+
export const access = (target: ts.Expression) => (property: string) => {
|
|
14
|
+
const postfix = identifier(property);
|
|
15
|
+
return ts.isStringLiteral(postfix)
|
|
16
|
+
? ts.factory.createElementAccessExpression(target, postfix)
|
|
17
|
+
: ts.factory.createPropertyAccessExpression(target, postfix);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const postfix = (str: string): string =>
|
|
21
|
+
Escaper.variable(str)
|
|
22
|
+
? `".${str}"`
|
|
23
|
+
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
24
|
+
|
|
25
|
+
export const parameter = (
|
|
26
|
+
name: string | ts.BindingName,
|
|
27
|
+
type?: ts.TypeNode,
|
|
28
|
+
init?: ts.Expression | ts.PunctuationToken<ts.SyntaxKind.QuestionToken>,
|
|
29
|
+
) => {
|
|
30
|
+
// instead of ts.version >= "4.8"
|
|
31
|
+
if (ts.getDecorators !== undefined)
|
|
32
|
+
return ts.factory.createParameterDeclaration(
|
|
33
|
+
undefined,
|
|
34
|
+
undefined,
|
|
35
|
+
name,
|
|
36
|
+
init?.kind === ts.SyntaxKind.QuestionToken
|
|
37
|
+
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
38
|
+
: undefined,
|
|
39
|
+
type ?? TypeFactory.keyword("any"),
|
|
40
|
+
init && init.kind !== ts.SyntaxKind.QuestionToken
|
|
41
|
+
? init
|
|
42
|
+
: undefined,
|
|
43
|
+
);
|
|
44
|
+
// eslint-disable-next-line
|
|
45
|
+
return (ts.factory.createParameterDeclaration as any)(
|
|
46
|
+
undefined,
|
|
47
|
+
undefined,
|
|
48
|
+
undefined,
|
|
49
|
+
name,
|
|
50
|
+
init?.kind === ts.SyntaxKind.QuestionToken
|
|
51
|
+
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
52
|
+
: undefined,
|
|
53
|
+
type,
|
|
54
|
+
init && init.kind !== ts.SyntaxKind.QuestionToken
|
|
55
|
+
? init
|
|
56
|
+
: undefined,
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../metadata/Metadata";
|
|
4
|
-
import { explore_metadata } from "./internal/metadata/explore_metadata";
|
|
5
|
-
import { iterate_metadata_collection } from "./internal/metadata/iterate_metadata_collection";
|
|
6
|
-
import { iterate_metadata_sort } from "./internal/metadata/iterate_metadata_sort";
|
|
7
|
-
|
|
8
|
-
import { MetadataCollection } from "./MetadataCollection";
|
|
9
|
-
|
|
10
|
-
export namespace MetadataFactory {
|
|
11
|
-
export interface IOptions {
|
|
12
|
-
resolve: boolean;
|
|
13
|
-
constant: boolean;
|
|
14
|
-
absorb: boolean;
|
|
15
|
-
validate?: (meta: Metadata) => void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const analyze =
|
|
19
|
-
(checker: ts.TypeChecker) =>
|
|
20
|
-
(options: IOptions) =>
|
|
21
|
-
(collection: MetadataCollection) =>
|
|
22
|
-
(type: ts.Type | null): Metadata => {
|
|
23
|
-
const meta: Metadata = explore_metadata(checker)(options)(
|
|
24
|
-
collection,
|
|
25
|
-
)(type, false);
|
|
26
|
-
iterate_metadata_collection(collection);
|
|
27
|
-
iterate_metadata_sort(collection)(meta);
|
|
28
|
-
return meta;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../metadata/Metadata";
|
|
4
|
+
import { explore_metadata } from "./internal/metadata/explore_metadata";
|
|
5
|
+
import { iterate_metadata_collection } from "./internal/metadata/iterate_metadata_collection";
|
|
6
|
+
import { iterate_metadata_sort } from "./internal/metadata/iterate_metadata_sort";
|
|
7
|
+
|
|
8
|
+
import { MetadataCollection } from "./MetadataCollection";
|
|
9
|
+
|
|
10
|
+
export namespace MetadataFactory {
|
|
11
|
+
export interface IOptions {
|
|
12
|
+
resolve: boolean;
|
|
13
|
+
constant: boolean;
|
|
14
|
+
absorb: boolean;
|
|
15
|
+
validate?: (meta: Metadata) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const analyze =
|
|
19
|
+
(checker: ts.TypeChecker) =>
|
|
20
|
+
(options: IOptions) =>
|
|
21
|
+
(collection: MetadataCollection) =>
|
|
22
|
+
(type: ts.Type | null): Metadata => {
|
|
23
|
+
const meta: Metadata = explore_metadata(checker)(options)(
|
|
24
|
+
collection,
|
|
25
|
+
)(type, false);
|
|
26
|
+
iterate_metadata_collection(collection);
|
|
27
|
+
iterate_metadata_sort(collection)(meta);
|
|
28
|
+
return meta;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -14,8 +14,7 @@ export const iterate_metadata_array =
|
|
|
14
14
|
(options: MetadataFactory.IOptions) =>
|
|
15
15
|
(collection: MetadataCollection) =>
|
|
16
16
|
(meta: Metadata, type: ts.Type): boolean => {
|
|
17
|
-
if (!checker.isArrayType(type)
|
|
18
|
-
return false;
|
|
17
|
+
if (!checker.isArrayType(type)) return false;
|
|
19
18
|
|
|
20
19
|
const array: MetadataArray = emplace_metadata_array(checker)(options)(
|
|
21
20
|
collection,
|
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
import { ClassProperties } from "../typings/ClassProperties";
|
|
2
|
-
|
|
3
|
-
import { IJsDocTagInfo } from "./IJsDocTagInfo";
|
|
4
|
-
import { IMetadataObject } from "./IMetadataObject";
|
|
5
|
-
import { MetadataProperty } from "./MetadataProperty";
|
|
6
|
-
|
|
7
|
-
export class MetadataObject {
|
|
8
|
-
public readonly name: string;
|
|
9
|
-
public readonly properties: Array<MetadataProperty>;
|
|
10
|
-
public readonly description: string | undefined;
|
|
11
|
-
public readonly jsDocTags: IJsDocTagInfo[];
|
|
12
|
-
|
|
13
|
-
public readonly index: number;
|
|
14
|
-
public validated: boolean;
|
|
15
|
-
public recursive: boolean;
|
|
16
|
-
public nullables: boolean[] = [];
|
|
17
|
-
|
|
18
|
-
/* -----------------------------------------------------------
|
|
19
|
-
CONSTRUCTORS
|
|
20
|
-
----------------------------------------------------------- */
|
|
21
|
-
/**
|
|
22
|
-
* @hidden
|
|
23
|
-
*/
|
|
24
|
-
private constructor(props: ClassProperties<MetadataObject>) {
|
|
25
|
-
this.name = props.name;
|
|
26
|
-
this.properties = props.properties;
|
|
27
|
-
this.description = props.description;
|
|
28
|
-
this.jsDocTags = props.jsDocTags;
|
|
29
|
-
|
|
30
|
-
this.index = props.index;
|
|
31
|
-
this.validated = props.validated;
|
|
32
|
-
this.recursive = props.recursive;
|
|
33
|
-
this.nullables = [];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
public static create(props: ClassProperties<MetadataObject>) {
|
|
40
|
-
return new MetadataObject(props);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
public static _From_without_properties(
|
|
47
|
-
obj: IMetadataObject,
|
|
48
|
-
): MetadataObject {
|
|
49
|
-
return this.create({
|
|
50
|
-
name: obj.name,
|
|
51
|
-
properties: [],
|
|
52
|
-
description: obj.description,
|
|
53
|
-
jsDocTags: obj.jsDocTags,
|
|
54
|
-
|
|
55
|
-
index: obj.index,
|
|
56
|
-
validated: obj.validated,
|
|
57
|
-
recursive: obj.recursive,
|
|
58
|
-
nullables: obj.nullables.slice(),
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @internal
|
|
64
|
-
*/
|
|
65
|
-
public _Is_simple(level: number = 0): boolean {
|
|
66
|
-
return (
|
|
67
|
-
this.recursive === false &&
|
|
68
|
-
this.properties.length < 10 &&
|
|
69
|
-
this.properties.every(
|
|
70
|
-
(property) =>
|
|
71
|
-
property.key.isSoleLiteral() &&
|
|
72
|
-
property.value.size() === 1 &&
|
|
73
|
-
property.value.required === true &&
|
|
74
|
-
property.value.nullable === false &&
|
|
75
|
-
(property.value.atomics.length === 1 ||
|
|
76
|
-
(level < 1 &&
|
|
77
|
-
property.value.objects.length === 1 &&
|
|
78
|
-
property.value.objects[0]!._Is_simple(level + 1))),
|
|
79
|
-
)
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public toJSON(): IMetadataObject {
|
|
84
|
-
return {
|
|
85
|
-
name: this.name,
|
|
86
|
-
properties: this.properties.map((property) => property.toJSON()),
|
|
87
|
-
description: this.description,
|
|
88
|
-
jsDocTags: this.jsDocTags,
|
|
89
|
-
|
|
90
|
-
index: this.index,
|
|
91
|
-
validated: this.validated,
|
|
92
|
-
recursive: this.recursive,
|
|
93
|
-
nullables: this.nullables.slice(),
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @internal
|
|
100
|
-
*/
|
|
101
|
-
export namespace MetadataObject {
|
|
102
|
-
export const intersects = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
103
|
-
x.properties.some(
|
|
104
|
-
(prop) =>
|
|
105
|
-
y.properties.find(
|
|
106
|
-
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
107
|
-
) !== undefined,
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
export const covers = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
111
|
-
x.properties.length >= y.properties.length &&
|
|
112
|
-
x.properties.every(
|
|
113
|
-
(prop) =>
|
|
114
|
-
y.properties.find(
|
|
115
|
-
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
116
|
-
) !== undefined,
|
|
117
|
-
);
|
|
118
|
-
}
|
|
1
|
+
import { ClassProperties } from "../typings/ClassProperties";
|
|
2
|
+
|
|
3
|
+
import { IJsDocTagInfo } from "./IJsDocTagInfo";
|
|
4
|
+
import { IMetadataObject } from "./IMetadataObject";
|
|
5
|
+
import { MetadataProperty } from "./MetadataProperty";
|
|
6
|
+
|
|
7
|
+
export class MetadataObject {
|
|
8
|
+
public readonly name: string;
|
|
9
|
+
public readonly properties: Array<MetadataProperty>;
|
|
10
|
+
public readonly description: string | undefined;
|
|
11
|
+
public readonly jsDocTags: IJsDocTagInfo[];
|
|
12
|
+
|
|
13
|
+
public readonly index: number;
|
|
14
|
+
public validated: boolean;
|
|
15
|
+
public recursive: boolean;
|
|
16
|
+
public nullables: boolean[] = [];
|
|
17
|
+
|
|
18
|
+
/* -----------------------------------------------------------
|
|
19
|
+
CONSTRUCTORS
|
|
20
|
+
----------------------------------------------------------- */
|
|
21
|
+
/**
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
private constructor(props: ClassProperties<MetadataObject>) {
|
|
25
|
+
this.name = props.name;
|
|
26
|
+
this.properties = props.properties;
|
|
27
|
+
this.description = props.description;
|
|
28
|
+
this.jsDocTags = props.jsDocTags;
|
|
29
|
+
|
|
30
|
+
this.index = props.index;
|
|
31
|
+
this.validated = props.validated;
|
|
32
|
+
this.recursive = props.recursive;
|
|
33
|
+
this.nullables = [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
public static create(props: ClassProperties<MetadataObject>) {
|
|
40
|
+
return new MetadataObject(props);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
public static _From_without_properties(
|
|
47
|
+
obj: IMetadataObject,
|
|
48
|
+
): MetadataObject {
|
|
49
|
+
return this.create({
|
|
50
|
+
name: obj.name,
|
|
51
|
+
properties: [],
|
|
52
|
+
description: obj.description,
|
|
53
|
+
jsDocTags: obj.jsDocTags,
|
|
54
|
+
|
|
55
|
+
index: obj.index,
|
|
56
|
+
validated: obj.validated,
|
|
57
|
+
recursive: obj.recursive,
|
|
58
|
+
nullables: obj.nullables.slice(),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
public _Is_simple(level: number = 0): boolean {
|
|
66
|
+
return (
|
|
67
|
+
this.recursive === false &&
|
|
68
|
+
this.properties.length < 10 &&
|
|
69
|
+
this.properties.every(
|
|
70
|
+
(property) =>
|
|
71
|
+
property.key.isSoleLiteral() &&
|
|
72
|
+
property.value.size() === 1 &&
|
|
73
|
+
property.value.required === true &&
|
|
74
|
+
property.value.nullable === false &&
|
|
75
|
+
(property.value.atomics.length === 1 ||
|
|
76
|
+
(level < 1 &&
|
|
77
|
+
property.value.objects.length === 1 &&
|
|
78
|
+
property.value.objects[0]!._Is_simple(level + 1))),
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public toJSON(): IMetadataObject {
|
|
84
|
+
return {
|
|
85
|
+
name: this.name,
|
|
86
|
+
properties: this.properties.map((property) => property.toJSON()),
|
|
87
|
+
description: this.description,
|
|
88
|
+
jsDocTags: this.jsDocTags,
|
|
89
|
+
|
|
90
|
+
index: this.index,
|
|
91
|
+
validated: this.validated,
|
|
92
|
+
recursive: this.recursive,
|
|
93
|
+
nullables: this.nullables.slice(),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
export namespace MetadataObject {
|
|
102
|
+
export const intersects = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
103
|
+
x.properties.some(
|
|
104
|
+
(prop) =>
|
|
105
|
+
y.properties.find(
|
|
106
|
+
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
107
|
+
) !== undefined,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
export const covers = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
111
|
+
x.properties.length >= y.properties.length &&
|
|
112
|
+
x.properties.every(
|
|
113
|
+
(prop) =>
|
|
114
|
+
y.properties.find(
|
|
115
|
+
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
116
|
+
) !== undefined,
|
|
117
|
+
);
|
|
118
|
+
}
|