typia 4.1.3 → 4.1.4-dev.20230707
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/metadata/Metadata.d.ts +1 -0
- package/lib/metadata/Metadata.js +5 -2
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/metadata/MetadataObject.js +1 -1
- package/lib/metadata/MetadataObject.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +3 -3
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.js +1 -1
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +1 -1
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/StringifyProgrammer.js +5 -5
- package/lib/programmers/StringifyProgrammer.js.map +1 -1
- package/lib/programmers/helpers/StringifyJoinder.js +1 -1
- package/lib/programmers/helpers/StringifyJoinder.js.map +1 -1
- package/lib/programmers/helpers/StringifyPredicator.js +3 -2
- package/lib/programmers/helpers/StringifyPredicator.js.map +1 -1
- package/lib/programmers/helpers/UnionPredicator.js +1 -1
- package/lib/programmers/helpers/UnionPredicator.js.map +1 -1
- package/lib/programmers/internal/application_object.js +2 -2
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js +5 -4
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/stringify_regular_properties.js +4 -4
- package/lib/programmers/internal/stringify_regular_properties.js.map +1 -1
- package/package.json +1 -1
- package/src/factories/internal/metadata/emplace_metadata_object.ts +137 -137
- package/src/factories/internal/metadata/iterate_metadata_collection.ts +133 -133
- package/src/factories/internal/metadata/iterate_metadata_tag.ts +31 -31
- package/src/metadata/Metadata.ts +6 -2
- package/src/metadata/MetadataObject.ts +129 -129
- package/src/programmers/CheckerProgrammer.ts +4 -4
- package/src/programmers/IsProgrammer.ts +1 -1
- package/src/programmers/RandomProgrammer.ts +1 -1
- package/src/programmers/StringifyProgrammer.ts +5 -5
- package/src/programmers/helpers/StringifyJoinder.ts +1 -1
- package/src/programmers/helpers/StringifyPredicator.ts +3 -2
- package/src/programmers/helpers/UnionPredicator.ts +1 -1
- package/src/programmers/internal/application_object.ts +2 -2
- package/src/programmers/internal/check_dynamic_properties.ts +5 -4
- package/src/programmers/internal/stringify_regular_properties.ts +4 -4
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
-
import { MetadataArray } from "../../../metadata/MetadataArray";
|
|
3
|
-
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
4
|
-
import { MetadataTuple } from "../../../metadata/MetadataTuple";
|
|
5
|
-
|
|
6
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
7
|
-
import { iterate_metadata_tag } from "./iterate_metadata_tag";
|
|
8
|
-
|
|
9
|
-
export const iterate_metadata_collection = (
|
|
10
|
-
collection: MetadataCollection,
|
|
11
|
-
): void => {
|
|
12
|
-
for (const array of collection.arrays())
|
|
13
|
-
if (array.recursive === null)
|
|
14
|
-
collection.setArrayRecursive(
|
|
15
|
-
array,
|
|
16
|
-
isArrayRecursive(new Set())(array)(array.value),
|
|
17
|
-
);
|
|
18
|
-
for (const tuple of collection.tuples())
|
|
19
|
-
if (tuple.recursive === null) {
|
|
20
|
-
const visited: Set<Metadata> = new Set();
|
|
21
|
-
collection.setTupleRecursive(
|
|
22
|
-
tuple,
|
|
23
|
-
tuple.elements.some(isTupleRecursive(visited)(tuple)),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
for (const obj of collection.objects()) {
|
|
27
|
-
iterate_metadata_tag(obj);
|
|
28
|
-
if (obj.recursive === null) {
|
|
29
|
-
const visited: Set<Metadata> = new Set();
|
|
30
|
-
collection.setObjectRecursive(
|
|
31
|
-
obj,
|
|
32
|
-
obj.properties.some((p) =>
|
|
33
|
-
isObjectRecursive(visited)(obj)(p.value),
|
|
34
|
-
),
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const isArrayRecursive =
|
|
41
|
-
(visited: Set<Metadata>) =>
|
|
42
|
-
(array: MetadataArray) =>
|
|
43
|
-
(meta: Metadata): boolean => {
|
|
44
|
-
if (visited.has(meta)) return false;
|
|
45
|
-
visited.add(meta);
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
meta.arrays.some(
|
|
49
|
-
(a) => a === array || isArrayRecursive(visited)(array)(a.value),
|
|
50
|
-
) ||
|
|
51
|
-
meta.aliases.some((d) =>
|
|
52
|
-
isArrayRecursive(visited)(array)(d.value),
|
|
53
|
-
) ||
|
|
54
|
-
meta.tuples.some(
|
|
55
|
-
(t) =>
|
|
56
|
-
!t.recursive &&
|
|
57
|
-
t.elements.some((e) => isArrayRecursive(visited)(array)(e)),
|
|
58
|
-
) ||
|
|
59
|
-
meta.maps.some((m) => isArrayRecursive(visited)(array)(m.value)) ||
|
|
60
|
-
meta.sets.some((s) => isArrayRecursive(visited)(array)(s)) ||
|
|
61
|
-
(meta.resolved !== null &&
|
|
62
|
-
isArrayRecursive(visited)(array)(meta.resolved.returns)) ||
|
|
63
|
-
(meta.rest !== null && isArrayRecursive(visited)(array)(meta.rest))
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const isTupleRecursive =
|
|
68
|
-
(visited: Set<Metadata>) =>
|
|
69
|
-
(tuple: MetadataTuple) =>
|
|
70
|
-
(meta: Metadata): boolean => {
|
|
71
|
-
if (visited.has(meta)) return false;
|
|
72
|
-
visited.add(meta);
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
meta.tuples.some(
|
|
76
|
-
(t) =>
|
|
77
|
-
t === tuple ||
|
|
78
|
-
t.elements.some((e) => isTupleRecursive(visited)(tuple)(e)),
|
|
79
|
-
) ||
|
|
80
|
-
meta.arrays.some(
|
|
81
|
-
(a) =>
|
|
82
|
-
!a.recursive && isTupleRecursive(visited)(tuple)(a.value),
|
|
83
|
-
) ||
|
|
84
|
-
meta.maps.some((m) => isTupleRecursive(visited)(tuple)(m.value)) ||
|
|
85
|
-
meta.sets.some((s) => isTupleRecursive(visited)(tuple)(s)) ||
|
|
86
|
-
meta.aliases.some((d) =>
|
|
87
|
-
isTupleRecursive(visited)(tuple)(d.value),
|
|
88
|
-
) ||
|
|
89
|
-
(meta.resolved !== null &&
|
|
90
|
-
isTupleRecursive(visited)(tuple)(meta.resolved.returns)) ||
|
|
91
|
-
(meta.rest !== null && isTupleRecursive(visited)(tuple)(meta.rest))
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const isObjectRecursive =
|
|
96
|
-
(visited: Set<Metadata>) =>
|
|
97
|
-
(obj: MetadataObject) =>
|
|
98
|
-
(meta: Metadata): boolean => {
|
|
99
|
-
if (visited.has(meta)) return false;
|
|
100
|
-
|
|
101
|
-
visited.add(meta);
|
|
102
|
-
return (
|
|
103
|
-
meta.objects.some(
|
|
104
|
-
(o) =>
|
|
105
|
-
obj === o ||
|
|
106
|
-
o.properties.some((prop) =>
|
|
107
|
-
isObjectRecursive(visited)(obj)(prop.value),
|
|
108
|
-
),
|
|
109
|
-
) ||
|
|
110
|
-
meta.aliases.some((alias) =>
|
|
111
|
-
isObjectRecursive(visited)(obj)(alias.value),
|
|
112
|
-
) ||
|
|
113
|
-
meta.arrays.some(
|
|
114
|
-
(array) =>
|
|
115
|
-
!array.recursive &&
|
|
116
|
-
isObjectRecursive(visited)(obj)(array.value),
|
|
117
|
-
) ||
|
|
118
|
-
meta.tuples.some(
|
|
119
|
-
(tuple) =>
|
|
120
|
-
!tuple.recursive &&
|
|
121
|
-
tuple.elements.some((elem) =>
|
|
122
|
-
isObjectRecursive(visited)(obj)(elem),
|
|
123
|
-
),
|
|
124
|
-
) ||
|
|
125
|
-
meta.maps.some((map) =>
|
|
126
|
-
isObjectRecursive(visited)(obj)(map.value),
|
|
127
|
-
) ||
|
|
128
|
-
meta.sets.some((value) => isObjectRecursive(visited)(obj)(value)) ||
|
|
129
|
-
(meta.resolved !== null &&
|
|
130
|
-
isObjectRecursive(visited)(obj)(meta.resolved.returns)) ||
|
|
131
|
-
(meta.rest !== null && isObjectRecursive(visited)(obj)(meta.rest))
|
|
132
|
-
);
|
|
133
|
-
};
|
|
1
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
+
import { MetadataArray } from "../../../metadata/MetadataArray";
|
|
3
|
+
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
4
|
+
import { MetadataTuple } from "../../../metadata/MetadataTuple";
|
|
5
|
+
|
|
6
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
7
|
+
import { iterate_metadata_tag } from "./iterate_metadata_tag";
|
|
8
|
+
|
|
9
|
+
export const iterate_metadata_collection = (
|
|
10
|
+
collection: MetadataCollection,
|
|
11
|
+
): void => {
|
|
12
|
+
for (const array of collection.arrays())
|
|
13
|
+
if (array.recursive === null)
|
|
14
|
+
collection.setArrayRecursive(
|
|
15
|
+
array,
|
|
16
|
+
isArrayRecursive(new Set())(array)(array.value),
|
|
17
|
+
);
|
|
18
|
+
for (const tuple of collection.tuples())
|
|
19
|
+
if (tuple.recursive === null) {
|
|
20
|
+
const visited: Set<Metadata> = new Set();
|
|
21
|
+
collection.setTupleRecursive(
|
|
22
|
+
tuple,
|
|
23
|
+
tuple.elements.some(isTupleRecursive(visited)(tuple)),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
for (const obj of collection.objects()) {
|
|
27
|
+
iterate_metadata_tag(obj);
|
|
28
|
+
if (obj.recursive === null) {
|
|
29
|
+
const visited: Set<Metadata> = new Set();
|
|
30
|
+
collection.setObjectRecursive(
|
|
31
|
+
obj,
|
|
32
|
+
obj.properties.some((p) =>
|
|
33
|
+
isObjectRecursive(visited)(obj)(p.value),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const isArrayRecursive =
|
|
41
|
+
(visited: Set<Metadata>) =>
|
|
42
|
+
(array: MetadataArray) =>
|
|
43
|
+
(meta: Metadata): boolean => {
|
|
44
|
+
if (visited.has(meta)) return false;
|
|
45
|
+
visited.add(meta);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
meta.arrays.some(
|
|
49
|
+
(a) => a === array || isArrayRecursive(visited)(array)(a.value),
|
|
50
|
+
) ||
|
|
51
|
+
meta.aliases.some((d) =>
|
|
52
|
+
isArrayRecursive(visited)(array)(d.value),
|
|
53
|
+
) ||
|
|
54
|
+
meta.tuples.some(
|
|
55
|
+
(t) =>
|
|
56
|
+
!t.recursive &&
|
|
57
|
+
t.elements.some((e) => isArrayRecursive(visited)(array)(e)),
|
|
58
|
+
) ||
|
|
59
|
+
meta.maps.some((m) => isArrayRecursive(visited)(array)(m.value)) ||
|
|
60
|
+
meta.sets.some((s) => isArrayRecursive(visited)(array)(s)) ||
|
|
61
|
+
(meta.resolved !== null &&
|
|
62
|
+
isArrayRecursive(visited)(array)(meta.resolved.returns)) ||
|
|
63
|
+
(meta.rest !== null && isArrayRecursive(visited)(array)(meta.rest))
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const isTupleRecursive =
|
|
68
|
+
(visited: Set<Metadata>) =>
|
|
69
|
+
(tuple: MetadataTuple) =>
|
|
70
|
+
(meta: Metadata): boolean => {
|
|
71
|
+
if (visited.has(meta)) return false;
|
|
72
|
+
visited.add(meta);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
meta.tuples.some(
|
|
76
|
+
(t) =>
|
|
77
|
+
t === tuple ||
|
|
78
|
+
t.elements.some((e) => isTupleRecursive(visited)(tuple)(e)),
|
|
79
|
+
) ||
|
|
80
|
+
meta.arrays.some(
|
|
81
|
+
(a) =>
|
|
82
|
+
!a.recursive && isTupleRecursive(visited)(tuple)(a.value),
|
|
83
|
+
) ||
|
|
84
|
+
meta.maps.some((m) => isTupleRecursive(visited)(tuple)(m.value)) ||
|
|
85
|
+
meta.sets.some((s) => isTupleRecursive(visited)(tuple)(s)) ||
|
|
86
|
+
meta.aliases.some((d) =>
|
|
87
|
+
isTupleRecursive(visited)(tuple)(d.value),
|
|
88
|
+
) ||
|
|
89
|
+
(meta.resolved !== null &&
|
|
90
|
+
isTupleRecursive(visited)(tuple)(meta.resolved.returns)) ||
|
|
91
|
+
(meta.rest !== null && isTupleRecursive(visited)(tuple)(meta.rest))
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const isObjectRecursive =
|
|
96
|
+
(visited: Set<Metadata>) =>
|
|
97
|
+
(obj: MetadataObject) =>
|
|
98
|
+
(meta: Metadata): boolean => {
|
|
99
|
+
if (visited.has(meta)) return false;
|
|
100
|
+
|
|
101
|
+
visited.add(meta);
|
|
102
|
+
return (
|
|
103
|
+
meta.objects.some(
|
|
104
|
+
(o) =>
|
|
105
|
+
obj === o ||
|
|
106
|
+
o.properties.some((prop) =>
|
|
107
|
+
isObjectRecursive(visited)(obj)(prop.value),
|
|
108
|
+
),
|
|
109
|
+
) ||
|
|
110
|
+
meta.aliases.some((alias) =>
|
|
111
|
+
isObjectRecursive(visited)(obj)(alias.value),
|
|
112
|
+
) ||
|
|
113
|
+
meta.arrays.some(
|
|
114
|
+
(array) =>
|
|
115
|
+
!array.recursive &&
|
|
116
|
+
isObjectRecursive(visited)(obj)(array.value),
|
|
117
|
+
) ||
|
|
118
|
+
meta.tuples.some(
|
|
119
|
+
(tuple) =>
|
|
120
|
+
!tuple.recursive &&
|
|
121
|
+
tuple.elements.some((elem) =>
|
|
122
|
+
isObjectRecursive(visited)(obj)(elem),
|
|
123
|
+
),
|
|
124
|
+
) ||
|
|
125
|
+
meta.maps.some((map) =>
|
|
126
|
+
isObjectRecursive(visited)(obj)(map.value),
|
|
127
|
+
) ||
|
|
128
|
+
meta.sets.some((value) => isObjectRecursive(visited)(obj)(value)) ||
|
|
129
|
+
(meta.resolved !== null &&
|
|
130
|
+
isObjectRecursive(visited)(obj)(meta.resolved.returns)) ||
|
|
131
|
+
(meta.rest !== null && isObjectRecursive(visited)(obj)(meta.rest))
|
|
132
|
+
);
|
|
133
|
+
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
2
|
-
|
|
3
|
-
import { Writable } from "../../../typings/Writable";
|
|
4
|
-
|
|
5
|
-
import { Escaper } from "../../../utils/Escaper";
|
|
6
|
-
|
|
7
|
-
import { MetadataTagFactory } from "../../MetadataTagFactory";
|
|
8
|
-
|
|
9
|
-
export const iterate_metadata_tag = (obj: MetadataObject) => {
|
|
10
|
-
if (obj.tagged_ === true) return;
|
|
11
|
-
obj.tagged_ = true;
|
|
12
|
-
|
|
13
|
-
for (const prop of obj.properties) {
|
|
14
|
-
const key: string = prop.key.getName();
|
|
15
|
-
const variable: string | null =
|
|
16
|
-
key.length >= 3 &&
|
|
17
|
-
key[0] === '"' &&
|
|
18
|
-
key[key.length - 1] === '"' &&
|
|
19
|
-
Escaper.variable(key.slice(1, -1))
|
|
20
|
-
? key.slice(1, -1)
|
|
21
|
-
: null;
|
|
22
|
-
|
|
23
|
-
Writable(prop).tags = MetadataTagFactory.generate(prop.value)(
|
|
24
|
-
prop.jsDocTags,
|
|
25
|
-
)(
|
|
26
|
-
variable !== null
|
|
27
|
-
? () => `${obj.name}.${variable}`
|
|
28
|
-
: () => `${obj.name}[${key}]`,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
1
|
+
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
2
|
+
|
|
3
|
+
import { Writable } from "../../../typings/Writable";
|
|
4
|
+
|
|
5
|
+
import { Escaper } from "../../../utils/Escaper";
|
|
6
|
+
|
|
7
|
+
import { MetadataTagFactory } from "../../MetadataTagFactory";
|
|
8
|
+
|
|
9
|
+
export const iterate_metadata_tag = (obj: MetadataObject) => {
|
|
10
|
+
if (obj.tagged_ === true) return;
|
|
11
|
+
obj.tagged_ = true;
|
|
12
|
+
|
|
13
|
+
for (const prop of obj.properties) {
|
|
14
|
+
const key: string = prop.key.getName();
|
|
15
|
+
const variable: string | null =
|
|
16
|
+
key.length >= 3 &&
|
|
17
|
+
key[0] === '"' &&
|
|
18
|
+
key[key.length - 1] === '"' &&
|
|
19
|
+
Escaper.variable(key.slice(1, -1))
|
|
20
|
+
? key.slice(1, -1)
|
|
21
|
+
: null;
|
|
22
|
+
|
|
23
|
+
Writable(prop).tags = MetadataTagFactory.generate(prop.value)(
|
|
24
|
+
prop.jsDocTags,
|
|
25
|
+
)(
|
|
26
|
+
variable !== null
|
|
27
|
+
? () => `${obj.name}.${variable}`
|
|
28
|
+
: () => `${obj.name}[${key}]`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
};
|
package/src/metadata/Metadata.ts
CHANGED
|
@@ -306,6 +306,10 @@ export class Metadata {
|
|
|
306
306
|
return this.bucket() === (this.constants.length ? 1 : 0);
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
+
public isRequired(): boolean {
|
|
310
|
+
return this.required && this.optional === false;
|
|
311
|
+
}
|
|
312
|
+
|
|
309
313
|
/**
|
|
310
314
|
* @internal
|
|
311
315
|
*/
|
|
@@ -347,7 +351,7 @@ export namespace Metadata {
|
|
|
347
351
|
export const intersects = (x: Metadata, y: Metadata): boolean => {
|
|
348
352
|
// CHECK ANY & OPTIONAL
|
|
349
353
|
if (x.any || y.any) return true;
|
|
350
|
-
if (x.
|
|
354
|
+
if (x.isRequired() === false && false === y.isRequired()) return true;
|
|
351
355
|
if (x.nullable === true && true === y.nullable) return true;
|
|
352
356
|
if (x.functional === true && y.functional === true) return true;
|
|
353
357
|
|
|
@@ -546,7 +550,7 @@ const getName = (metadata: Metadata): string => {
|
|
|
546
550
|
|
|
547
551
|
// OPTIONAL
|
|
548
552
|
if (metadata.nullable === true) elements.push("null");
|
|
549
|
-
if (metadata.
|
|
553
|
+
if (metadata.isRequired() === false) elements.push("undefined");
|
|
550
554
|
|
|
551
555
|
// ATOMIC
|
|
552
556
|
for (const type of metadata.atomics) {
|
|
@@ -1,129 +1,129 @@
|
|
|
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
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
public tagged_: boolean = false;
|
|
22
|
-
|
|
23
|
-
/* -----------------------------------------------------------
|
|
24
|
-
CONSTRUCTORS
|
|
25
|
-
----------------------------------------------------------- */
|
|
26
|
-
/**
|
|
27
|
-
* @hidden
|
|
28
|
-
*/
|
|
29
|
-
private constructor(
|
|
30
|
-
props: Omit<ClassProperties<MetadataObject>, "tagged_">,
|
|
31
|
-
) {
|
|
32
|
-
this.name = props.name;
|
|
33
|
-
this.properties = props.properties;
|
|
34
|
-
this.description = props.description;
|
|
35
|
-
this.jsDocTags = props.jsDocTags;
|
|
36
|
-
|
|
37
|
-
this.index = props.index;
|
|
38
|
-
this.validated = props.validated;
|
|
39
|
-
this.recursive = props.recursive;
|
|
40
|
-
this.nullables = [];
|
|
41
|
-
|
|
42
|
-
this.tagged_ = false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
48
|
-
public static create(
|
|
49
|
-
props: Omit<ClassProperties<MetadataObject>, "tagged_">,
|
|
50
|
-
) {
|
|
51
|
-
return new MetadataObject(props);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
public static _From_without_properties(
|
|
58
|
-
obj: IMetadataObject,
|
|
59
|
-
): MetadataObject {
|
|
60
|
-
return this.create({
|
|
61
|
-
name: obj.name,
|
|
62
|
-
properties: [],
|
|
63
|
-
description: obj.description,
|
|
64
|
-
jsDocTags: obj.jsDocTags,
|
|
65
|
-
|
|
66
|
-
index: obj.index,
|
|
67
|
-
validated: obj.validated,
|
|
68
|
-
recursive: obj.recursive,
|
|
69
|
-
nullables: obj.nullables.slice(),
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @internal
|
|
75
|
-
*/
|
|
76
|
-
public _Is_simple(level: number = 0): boolean {
|
|
77
|
-
return (
|
|
78
|
-
this.recursive === false &&
|
|
79
|
-
this.properties.length < 10 &&
|
|
80
|
-
this.properties.every(
|
|
81
|
-
(property) =>
|
|
82
|
-
property.key.isSoleLiteral() &&
|
|
83
|
-
property.value.size() === 1 &&
|
|
84
|
-
property.value.
|
|
85
|
-
property.value.nullable === false &&
|
|
86
|
-
(property.value.atomics.length === 1 ||
|
|
87
|
-
(level < 1 &&
|
|
88
|
-
property.value.objects.length === 1 &&
|
|
89
|
-
property.value.objects[0]!._Is_simple(level + 1))),
|
|
90
|
-
)
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public toJSON(): IMetadataObject {
|
|
95
|
-
return {
|
|
96
|
-
name: this.name,
|
|
97
|
-
properties: this.properties.map((property) => property.toJSON()),
|
|
98
|
-
description: this.description,
|
|
99
|
-
jsDocTags: this.jsDocTags,
|
|
100
|
-
|
|
101
|
-
index: this.index,
|
|
102
|
-
validated: this.validated,
|
|
103
|
-
recursive: this.recursive,
|
|
104
|
-
nullables: this.nullables.slice(),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @internal
|
|
111
|
-
*/
|
|
112
|
-
export namespace MetadataObject {
|
|
113
|
-
export const intersects = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
114
|
-
x.properties.some(
|
|
115
|
-
(prop) =>
|
|
116
|
-
y.properties.find(
|
|
117
|
-
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
118
|
-
) !== undefined,
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
export const covers = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
122
|
-
x.properties.length >= y.properties.length &&
|
|
123
|
-
x.properties.every(
|
|
124
|
-
(prop) =>
|
|
125
|
-
y.properties.find(
|
|
126
|
-
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
127
|
-
) !== undefined,
|
|
128
|
-
);
|
|
129
|
-
}
|
|
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
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
public tagged_: boolean = false;
|
|
22
|
+
|
|
23
|
+
/* -----------------------------------------------------------
|
|
24
|
+
CONSTRUCTORS
|
|
25
|
+
----------------------------------------------------------- */
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
*/
|
|
29
|
+
private constructor(
|
|
30
|
+
props: Omit<ClassProperties<MetadataObject>, "tagged_">,
|
|
31
|
+
) {
|
|
32
|
+
this.name = props.name;
|
|
33
|
+
this.properties = props.properties;
|
|
34
|
+
this.description = props.description;
|
|
35
|
+
this.jsDocTags = props.jsDocTags;
|
|
36
|
+
|
|
37
|
+
this.index = props.index;
|
|
38
|
+
this.validated = props.validated;
|
|
39
|
+
this.recursive = props.recursive;
|
|
40
|
+
this.nullables = [];
|
|
41
|
+
|
|
42
|
+
this.tagged_ = false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
public static create(
|
|
49
|
+
props: Omit<ClassProperties<MetadataObject>, "tagged_">,
|
|
50
|
+
) {
|
|
51
|
+
return new MetadataObject(props);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
public static _From_without_properties(
|
|
58
|
+
obj: IMetadataObject,
|
|
59
|
+
): MetadataObject {
|
|
60
|
+
return this.create({
|
|
61
|
+
name: obj.name,
|
|
62
|
+
properties: [],
|
|
63
|
+
description: obj.description,
|
|
64
|
+
jsDocTags: obj.jsDocTags,
|
|
65
|
+
|
|
66
|
+
index: obj.index,
|
|
67
|
+
validated: obj.validated,
|
|
68
|
+
recursive: obj.recursive,
|
|
69
|
+
nullables: obj.nullables.slice(),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
public _Is_simple(level: number = 0): boolean {
|
|
77
|
+
return (
|
|
78
|
+
this.recursive === false &&
|
|
79
|
+
this.properties.length < 10 &&
|
|
80
|
+
this.properties.every(
|
|
81
|
+
(property) =>
|
|
82
|
+
property.key.isSoleLiteral() &&
|
|
83
|
+
property.value.size() === 1 &&
|
|
84
|
+
property.value.isRequired() === true &&
|
|
85
|
+
property.value.nullable === false &&
|
|
86
|
+
(property.value.atomics.length === 1 ||
|
|
87
|
+
(level < 1 &&
|
|
88
|
+
property.value.objects.length === 1 &&
|
|
89
|
+
property.value.objects[0]!._Is_simple(level + 1))),
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public toJSON(): IMetadataObject {
|
|
95
|
+
return {
|
|
96
|
+
name: this.name,
|
|
97
|
+
properties: this.properties.map((property) => property.toJSON()),
|
|
98
|
+
description: this.description,
|
|
99
|
+
jsDocTags: this.jsDocTags,
|
|
100
|
+
|
|
101
|
+
index: this.index,
|
|
102
|
+
validated: this.validated,
|
|
103
|
+
recursive: this.recursive,
|
|
104
|
+
nullables: this.nullables.slice(),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
export namespace MetadataObject {
|
|
113
|
+
export const intersects = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
114
|
+
x.properties.some(
|
|
115
|
+
(prop) =>
|
|
116
|
+
y.properties.find(
|
|
117
|
+
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
118
|
+
) !== undefined,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
export const covers = (x: MetadataObject, y: MetadataObject): boolean =>
|
|
122
|
+
x.properties.length >= y.properties.length &&
|
|
123
|
+
x.properties.every(
|
|
124
|
+
(prop) =>
|
|
125
|
+
y.properties.find(
|
|
126
|
+
(oppo) => prop.key.getName() === oppo.key.getName(),
|
|
127
|
+
) !== undefined,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
@@ -330,9 +330,9 @@ export namespace CheckerProgrammer {
|
|
|
330
330
|
);
|
|
331
331
|
|
|
332
332
|
// UNDEFINDABLE
|
|
333
|
-
if (checkOptional || !meta.
|
|
334
|
-
(meta.
|
|
335
|
-
!meta.
|
|
333
|
+
if (checkOptional || !meta.isRequired())
|
|
334
|
+
(meta.isRequired() ? create_add(top)(input) : add)(
|
|
335
|
+
!meta.isRequired(),
|
|
336
336
|
ValueFactory.UNDEFINED(),
|
|
337
337
|
);
|
|
338
338
|
|
|
@@ -572,7 +572,7 @@ export namespace CheckerProgrammer {
|
|
|
572
572
|
obj.properties.every(
|
|
573
573
|
(prop) =>
|
|
574
574
|
!prop.key.isSoleLiteral() ||
|
|
575
|
-
!prop.value.
|
|
575
|
+
!prop.value.isRequired(),
|
|
576
576
|
),
|
|
577
577
|
),
|
|
578
578
|
})(input),
|
|
@@ -122,7 +122,7 @@ export namespace IsProgrammer {
|
|
|
122
122
|
if (
|
|
123
123
|
target.size() === 1 &&
|
|
124
124
|
target.objects.length === 1 &&
|
|
125
|
-
target.
|
|
125
|
+
target.isRequired() === true &&
|
|
126
126
|
target.nullable === false
|
|
127
127
|
) {
|
|
128
128
|
// ONLY WHEN OBJECT WITH SOME ATOMIC PROPERTIES
|
|
@@ -225,7 +225,7 @@ export namespace RandomProgrammer {
|
|
|
225
225
|
);
|
|
226
226
|
|
|
227
227
|
// NULL COALESCING
|
|
228
|
-
if (meta.
|
|
228
|
+
if (meta.isRequired() === false)
|
|
229
229
|
expressions.push(ts.factory.createIdentifier("undefined"));
|
|
230
230
|
if (meta.nullable === true)
|
|
231
231
|
expressions.push(ts.factory.createNull());
|