typia 5.0.0-dev.20230823-2 → 5.0.0-dev.2023084
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/MetadataTagFactory.js +4 -2
- package/lib/factories/MetadataTagFactory.js.map +1 -1
- package/lib/factories/ProtobufFactory.js +2 -1
- package/lib/factories/ProtobufFactory.js.map +1 -1
- package/lib/factories/internal/metadata/emend_metadata_atomics.js +6 -6
- package/lib/factories/internal/metadata/emend_metadata_atomics.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_atomic.js +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_atomic.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +6 -6
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +5 -5
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/helpers/AtomicPredicator.js +2 -2
- package/lib/programmers/helpers/AtomicPredicator.js.map +1 -1
- package/lib/programmers/helpers/ProtobufUtil.js +2 -2
- package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
- package/lib/programmers/internal/application_default_string.js +2 -2
- package/lib/programmers/internal/application_default_string.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +5 -5
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/metadata_to_pattern.js +4 -4
- package/lib/programmers/internal/metadata_to_pattern.js.map +1 -1
- package/lib/programmers/internal/stringify_dynamic_properties.js +2 -1
- package/lib/programmers/internal/stringify_dynamic_properties.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +16 -10
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscLiteralsProgrammer.js +2 -2
- package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/schemas/metadata/IMetadata.d.ts +2 -2
- package/lib/schemas/metadata/IMetadataAtomic.d.ts +12 -0
- package/lib/schemas/metadata/IMetadataAtomic.js +3 -0
- package/lib/schemas/metadata/IMetadataAtomic.js.map +1 -0
- package/lib/schemas/metadata/Metadata.d.ts +2 -2
- package/lib/schemas/metadata/Metadata.js +49 -44
- package/lib/schemas/metadata/Metadata.js.map +1 -1
- package/lib/tags/ExclusiveMaximum.d.ts +8 -0
- package/lib/tags/ExclusiveMaximum.js +3 -0
- package/lib/tags/ExclusiveMaximum.js.map +1 -0
- package/lib/tags/ExclusiveMinimum.d.ts +8 -0
- package/lib/tags/ExclusiveMinimum.js +3 -0
- package/lib/tags/ExclusiveMinimum.js.map +1 -0
- package/lib/tags/Format.d.ts +8 -0
- package/lib/tags/Format.js +3 -0
- package/lib/tags/Format.js.map +1 -0
- package/lib/tags/MaxItems.d.ts +8 -0
- package/lib/tags/MaxItems.js +3 -0
- package/lib/tags/MaxItems.js.map +1 -0
- package/lib/tags/MaxLength.d.ts +8 -0
- package/lib/tags/MaxLength.js +3 -0
- package/lib/tags/MaxLength.js.map +1 -0
- package/lib/tags/Maximum.d.ts +8 -0
- package/lib/tags/Maximum.js +3 -0
- package/lib/tags/Maximum.js.map +1 -0
- package/lib/tags/MinItems.d.ts +8 -0
- package/lib/tags/MinItems.js +3 -0
- package/lib/tags/MinItems.js.map +1 -0
- package/lib/tags/MinLength.d.ts +8 -0
- package/lib/tags/MinLength.js +3 -0
- package/lib/tags/MinLength.js.map +1 -0
- package/lib/tags/Minimum.d.ts +8 -0
- package/lib/tags/Minimum.js +3 -0
- package/lib/tags/Minimum.js.map +1 -0
- package/lib/tags/MultipleOf.d.ts +8 -0
- package/lib/tags/MultipleOf.js +3 -0
- package/lib/tags/MultipleOf.js.map +1 -0
- package/lib/tags/Pattern.d.ts +8 -0
- package/lib/tags/Pattern.js +3 -0
- package/lib/tags/Pattern.js.map +1 -0
- package/lib/tags/TagBase.d.ts +10 -0
- package/lib/tags/TagBase.js +3 -0
- package/lib/tags/TagBase.js.map +1 -0
- package/lib/tags/Type.d.ts +13 -0
- package/lib/tags/Type.js +3 -0
- package/lib/tags/Type.js.map +1 -0
- package/lib/tags/index.d.ts +12 -0
- package/lib/tags/index.js +29 -0
- package/lib/tags/index.js.map +1 -0
- package/lib/transformers/features/json/JsonApplicationTransformer.js +1 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/Primitive.ts +135 -135
- package/src/Resolved.ts +116 -116
- package/src/factories/MetadataFactory.ts +46 -46
- package/src/factories/MetadataTagFactory.ts +366 -364
- package/src/factories/ProtobufFactory.ts +268 -266
- package/src/factories/internal/metadata/emend_metadata_atomics.ts +35 -33
- package/src/factories/internal/metadata/explore_metadata.ts +38 -38
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +63 -59
- package/src/factories/internal/metadata/iterate_metadata_collection.ts +133 -133
- package/src/factories/internal/metadata/iterate_metadata_native.ts +210 -210
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +49 -49
- package/src/factories/internal/metadata/iterate_metadata_sort.ts +69 -69
- package/src/functional/$ProtobufWriter.ts +151 -151
- package/src/json.ts +648 -648
- package/src/misc.ts +651 -651
- package/src/module.ts +709 -709
- package/src/programmers/AssertProgrammer.ts +281 -281
- package/src/programmers/CheckerProgrammer.ts +1174 -1173
- package/src/programmers/IsProgrammer.ts +241 -241
- package/src/programmers/RandomProgrammer.ts +874 -874
- package/src/programmers/ValidateProgrammer.ts +307 -307
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/FunctionImporeter.ts +91 -91
- package/src/programmers/helpers/ProtobufUtil.ts +29 -29
- package/src/programmers/helpers/StringifyPredicator.ts +12 -12
- package/src/programmers/helpers/disable_function_importer_declare.ts +32 -32
- package/src/programmers/internal/application_default_string.ts +37 -33
- package/src/programmers/internal/application_resolved.ts +55 -55
- package/src/programmers/internal/application_schema.ts +157 -157
- package/src/programmers/internal/metadata_to_pattern.ts +34 -34
- package/src/programmers/internal/stringify_dynamic_properties.ts +171 -171
- package/src/programmers/json/JsonStringifyProgrammer.ts +995 -989
- package/src/programmers/misc/MiscAssertCloneProgrammer.ts +71 -71
- package/src/programmers/misc/MiscCloneProgrammer.ts +775 -775
- package/src/programmers/misc/MiscIsCloneProgrammer.ts +78 -78
- package/src/programmers/misc/MiscLiteralsProgrammer.ts +64 -64
- package/src/programmers/misc/MiscPruneProgrammer.ts +544 -544
- package/src/programmers/misc/MiscValidateCloneProgrammer.ts +85 -85
- package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +75 -75
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +673 -673
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +814 -814
- package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +85 -85
- package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +75 -75
- package/src/protobuf.ts +881 -881
- package/src/schemas/metadata/IMetadata.ts +27 -28
- package/src/schemas/metadata/IMetadataAtomic.ts +13 -0
- package/src/schemas/metadata/IMetadataEscaped.ts +6 -6
- package/src/schemas/metadata/Metadata.ts +643 -634
- package/src/schemas/metadata/MetadataEscaped.ts +51 -51
- package/src/tags/ExclusiveMaximum.ts +8 -0
- package/src/tags/ExclusiveMinimum.ts +8 -0
- package/src/tags/Format.ts +29 -0
- package/src/tags/MaxItems.ts +8 -0
- package/src/tags/MaxLength.ts +8 -0
- package/src/tags/Maximum.ts +8 -0
- package/src/tags/MinItems.ts +8 -0
- package/src/tags/MinLength.ts +8 -0
- package/src/tags/Minimum.ts +8 -0
- package/src/tags/MultipleOf.ts +10 -0
- package/src/tags/Pattern.ts +8 -0
- package/src/tags/TagBase.ts +17 -0
- package/src/tags/Type.ts +30 -0
- package/src/tags/index.ts +12 -0
- package/src/transformers/features/json/JsonApplicationTransformer.ts +111 -111
- package/src/transformers/features/misc/MetadataTransformer.ts +53 -53
- package/src/utils/RandomGenerator.ts +83 -83
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
-
|
|
3
|
-
import { Atomic } from "../../typings/Atomic";
|
|
4
|
-
|
|
5
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
6
|
-
|
|
7
|
-
export namespace AtomicPredicator {
|
|
8
|
-
export const constant =
|
|
9
|
-
(meta: Metadata) =>
|
|
10
|
-
(name: Atomic.Literal): boolean =>
|
|
11
|
-
!ArrayUtil.has(meta.atomics, (
|
|
12
|
-
!ArrayUtil.has(
|
|
13
|
-
meta.natives,
|
|
14
|
-
(native) => native.toLowerCase() === name,
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
export const atomic =
|
|
18
|
-
(meta: Metadata) =>
|
|
19
|
-
(name: Atomic.Literal): boolean =>
|
|
20
|
-
!ArrayUtil.has(
|
|
21
|
-
meta.natives,
|
|
22
|
-
(native) => native.toLowerCase() === name,
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
export const native = (name: string) => LIKE.has(name.toLowerCase());
|
|
26
|
-
|
|
27
|
-
export const template = (meta: Metadata): boolean =>
|
|
28
|
-
!ArrayUtil.has(meta.atomics, (
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const LIKE = new Set(["boolean", "number", "string"]);
|
|
1
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
import { Atomic } from "../../typings/Atomic";
|
|
4
|
+
|
|
5
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
6
|
+
|
|
7
|
+
export namespace AtomicPredicator {
|
|
8
|
+
export const constant =
|
|
9
|
+
(meta: Metadata) =>
|
|
10
|
+
(name: Atomic.Literal): boolean =>
|
|
11
|
+
!ArrayUtil.has(meta.atomics, (a) => a.type === name) &&
|
|
12
|
+
!ArrayUtil.has(
|
|
13
|
+
meta.natives,
|
|
14
|
+
(native) => native.toLowerCase() === name,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const atomic =
|
|
18
|
+
(meta: Metadata) =>
|
|
19
|
+
(name: Atomic.Literal): boolean =>
|
|
20
|
+
!ArrayUtil.has(
|
|
21
|
+
meta.natives,
|
|
22
|
+
(native) => native.toLowerCase() === name,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export const native = (name: string) => LIKE.has(name.toLowerCase());
|
|
26
|
+
|
|
27
|
+
export const template = (meta: Metadata): boolean =>
|
|
28
|
+
!ArrayUtil.has(meta.atomics, (a) => a.type === "string");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const LIKE = new Set(["boolean", "number", "string"]);
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
-
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
-
|
|
7
|
-
export class FunctionImporter {
|
|
8
|
-
private readonly used_: Set<string> = new Set();
|
|
9
|
-
private readonly local_: Set<string> = new Set();
|
|
10
|
-
private readonly unions_: Map<string, [string, ts.ArrowFunction]> =
|
|
11
|
-
new Map();
|
|
12
|
-
private sequence_: number = 0;
|
|
13
|
-
|
|
14
|
-
public constructor(public readonly method: string) {}
|
|
15
|
-
|
|
16
|
-
public empty(): boolean {
|
|
17
|
-
return this.used_.size === 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public use(name: string): ts.Identifier {
|
|
21
|
-
this.used_.add(name);
|
|
22
|
-
return ts.factory.createIdentifier("$" + name);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public useLocal(name: string): string {
|
|
26
|
-
this.local_.add(name);
|
|
27
|
-
return name;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public hasLocal(name: string): boolean {
|
|
31
|
-
return this.local_.has(name);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public declare(
|
|
35
|
-
modulo: ts.LeftHandSideExpression,
|
|
36
|
-
includeUnions: boolean = true,
|
|
37
|
-
): ts.Statement[] {
|
|
38
|
-
return [
|
|
39
|
-
...[...this.used_].map((name) =>
|
|
40
|
-
StatementFactory.constant(
|
|
41
|
-
"$" + name,
|
|
42
|
-
IdentifierFactory.access(
|
|
43
|
-
ts.factory.createParenthesizedExpression(
|
|
44
|
-
ts.factory.createAsExpression(
|
|
45
|
-
modulo,
|
|
46
|
-
TypeFactory.keyword("any"),
|
|
47
|
-
),
|
|
48
|
-
),
|
|
49
|
-
)(name),
|
|
50
|
-
),
|
|
51
|
-
),
|
|
52
|
-
...(includeUnions === true
|
|
53
|
-
? [...this.unions_.values()].map(([key, arrow]) =>
|
|
54
|
-
StatementFactory.constant(key, arrow),
|
|
55
|
-
)
|
|
56
|
-
: []),
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public declareUnions(): ts.Statement[] {
|
|
61
|
-
return [...this.unions_.values()].map(([key, arrow]) =>
|
|
62
|
-
StatementFactory.constant(key, arrow),
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public increment(): number {
|
|
67
|
-
return ++this.sequence_;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public emplaceUnion(
|
|
71
|
-
prefix: string,
|
|
72
|
-
name: string,
|
|
73
|
-
factory: () => ts.ArrowFunction,
|
|
74
|
-
): string {
|
|
75
|
-
const oldbie = this.unions_.get(name);
|
|
76
|
-
if (oldbie) return oldbie[0];
|
|
77
|
-
|
|
78
|
-
const index: number = this.unions_.size;
|
|
79
|
-
const accessor: string = `${prefix}p${index}`;
|
|
80
|
-
|
|
81
|
-
const tuple: [string, ReturnType<typeof factory>] = [accessor, null!];
|
|
82
|
-
this.unions_.set(name, tuple);
|
|
83
|
-
tuple[1] = factory();
|
|
84
|
-
return accessor;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public trace(): void {
|
|
88
|
-
console.log(...this.used_);
|
|
89
|
-
console.log(...this.local_);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
+
|
|
7
|
+
export class FunctionImporter {
|
|
8
|
+
private readonly used_: Set<string> = new Set();
|
|
9
|
+
private readonly local_: Set<string> = new Set();
|
|
10
|
+
private readonly unions_: Map<string, [string, ts.ArrowFunction]> =
|
|
11
|
+
new Map();
|
|
12
|
+
private sequence_: number = 0;
|
|
13
|
+
|
|
14
|
+
public constructor(public readonly method: string) {}
|
|
15
|
+
|
|
16
|
+
public empty(): boolean {
|
|
17
|
+
return this.used_.size === 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public use(name: string): ts.Identifier {
|
|
21
|
+
this.used_.add(name);
|
|
22
|
+
return ts.factory.createIdentifier("$" + name);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public useLocal(name: string): string {
|
|
26
|
+
this.local_.add(name);
|
|
27
|
+
return name;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public hasLocal(name: string): boolean {
|
|
31
|
+
return this.local_.has(name);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public declare(
|
|
35
|
+
modulo: ts.LeftHandSideExpression,
|
|
36
|
+
includeUnions: boolean = true,
|
|
37
|
+
): ts.Statement[] {
|
|
38
|
+
return [
|
|
39
|
+
...[...this.used_].map((name) =>
|
|
40
|
+
StatementFactory.constant(
|
|
41
|
+
"$" + name,
|
|
42
|
+
IdentifierFactory.access(
|
|
43
|
+
ts.factory.createParenthesizedExpression(
|
|
44
|
+
ts.factory.createAsExpression(
|
|
45
|
+
modulo,
|
|
46
|
+
TypeFactory.keyword("any"),
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
)(name),
|
|
50
|
+
),
|
|
51
|
+
),
|
|
52
|
+
...(includeUnions === true
|
|
53
|
+
? [...this.unions_.values()].map(([key, arrow]) =>
|
|
54
|
+
StatementFactory.constant(key, arrow),
|
|
55
|
+
)
|
|
56
|
+
: []),
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public declareUnions(): ts.Statement[] {
|
|
61
|
+
return [...this.unions_.values()].map(([key, arrow]) =>
|
|
62
|
+
StatementFactory.constant(key, arrow),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public increment(): number {
|
|
67
|
+
return ++this.sequence_;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public emplaceUnion(
|
|
71
|
+
prefix: string,
|
|
72
|
+
name: string,
|
|
73
|
+
factory: () => ts.ArrowFunction,
|
|
74
|
+
): string {
|
|
75
|
+
const oldbie = this.unions_.get(name);
|
|
76
|
+
if (oldbie) return oldbie[0];
|
|
77
|
+
|
|
78
|
+
const index: number = this.unions_.size;
|
|
79
|
+
const accessor: string = `${prefix}p${index}`;
|
|
80
|
+
|
|
81
|
+
const tuple: [string, ReturnType<typeof factory>] = [accessor, null!];
|
|
82
|
+
this.unions_.set(name, tuple);
|
|
83
|
+
tuple[1] = factory();
|
|
84
|
+
return accessor;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public trace(): void {
|
|
88
|
+
console.log(...this.used_);
|
|
89
|
+
console.log(...this.local_);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
-
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
3
|
-
|
|
4
|
-
import { Atomic } from "../../typings/Atomic";
|
|
5
|
-
|
|
6
|
-
export namespace ProtobufUtil {
|
|
7
|
-
export const getAtomics = (meta: Metadata) => {
|
|
8
|
-
const set: Set<Atomic.Literal> = new Set();
|
|
9
|
-
|
|
10
|
-
for (const
|
|
11
|
-
for (const constant of meta.constants) set.add(constant.type);
|
|
12
|
-
if (meta.templates.length) set.add("string");
|
|
13
|
-
|
|
14
|
-
return [...set].sort(
|
|
15
|
-
(x, y) => ATOMIC_ORDER.get(x)! - ATOMIC_ORDER.get(y)!,
|
|
16
|
-
);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const isStaticObject = (obj: MetadataObject): boolean =>
|
|
20
|
-
obj.properties.length >= 1 &&
|
|
21
|
-
obj.properties.every((p) => p.key.isSoleLiteral());
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const ATOMIC_ORDER = new Map<Atomic.Literal, number>([
|
|
25
|
-
["boolean", 0],
|
|
26
|
-
["bigint", 1],
|
|
27
|
-
["number", 2],
|
|
28
|
-
["string", 3],
|
|
29
|
-
]);
|
|
1
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
+
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
3
|
+
|
|
4
|
+
import { Atomic } from "../../typings/Atomic";
|
|
5
|
+
|
|
6
|
+
export namespace ProtobufUtil {
|
|
7
|
+
export const getAtomics = (meta: Metadata) => {
|
|
8
|
+
const set: Set<Atomic.Literal> = new Set();
|
|
9
|
+
|
|
10
|
+
for (const a of meta.atomics) set.add(a.type);
|
|
11
|
+
for (const constant of meta.constants) set.add(constant.type);
|
|
12
|
+
if (meta.templates.length) set.add("string");
|
|
13
|
+
|
|
14
|
+
return [...set].sort(
|
|
15
|
+
(x, y) => ATOMIC_ORDER.get(x)! - ATOMIC_ORDER.get(y)!,
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const isStaticObject = (obj: MetadataObject): boolean =>
|
|
20
|
+
obj.properties.length >= 1 &&
|
|
21
|
+
obj.properties.every((p) => p.key.isSoleLiteral());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const ATOMIC_ORDER = new Map<Atomic.Literal, number>([
|
|
25
|
+
["boolean", 0],
|
|
26
|
+
["bigint", 1],
|
|
27
|
+
["number", 2],
|
|
28
|
+
["string", 3],
|
|
29
|
+
]);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
-
|
|
3
|
-
export namespace StringifyPredicator {
|
|
4
|
-
export const require_escape = (value: string): boolean =>
|
|
5
|
-
value.split("").some((ch) => ESCAPED.some((escaped) => escaped === ch));
|
|
6
|
-
|
|
7
|
-
export const undefindable = (meta: Metadata): boolean =>
|
|
8
|
-
meta.isRequired() === false ||
|
|
9
|
-
(meta.escaped !== null && meta.escaped.returns.isRequired() === false);
|
|
10
|
-
|
|
11
|
-
const ESCAPED = ['"', "\\", "\b", "\f", "\n", "\n", "\r", "\t"];
|
|
12
|
-
}
|
|
1
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
export namespace StringifyPredicator {
|
|
4
|
+
export const require_escape = (value: string): boolean =>
|
|
5
|
+
value.split("").some((ch) => ESCAPED.some((escaped) => escaped === ch));
|
|
6
|
+
|
|
7
|
+
export const undefindable = (meta: Metadata): boolean =>
|
|
8
|
+
meta.isRequired() === false ||
|
|
9
|
+
(meta.escaped !== null && meta.escaped.returns.isRequired() === false);
|
|
10
|
+
|
|
11
|
+
const ESCAPED = ['"', "\\", "\b", "\f", "\n", "\n", "\r", "\t"];
|
|
12
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { FunctionImporter } from "./FunctionImporeter";
|
|
4
|
-
|
|
5
|
-
export const disable_function_importer_declare = (
|
|
6
|
-
importer: FunctionImporter,
|
|
7
|
-
): FunctionImporter => disable(importer) as FunctionImporter;
|
|
8
|
-
|
|
9
|
-
const disable = (importer: FunctionImporter): MethodOnly<FunctionImporter> => ({
|
|
10
|
-
method: importer.method,
|
|
11
|
-
empty: (): boolean => importer.empty(),
|
|
12
|
-
use: (name: string): ts.Identifier => importer.use(name),
|
|
13
|
-
useLocal: (name: string): string => importer.useLocal(name),
|
|
14
|
-
hasLocal: (name: string): boolean => importer.hasLocal(name),
|
|
15
|
-
declare: (_modulo: ts.LeftHandSideExpression): ts.Statement[] => [],
|
|
16
|
-
declareUnions: (): ts.Statement[] => [],
|
|
17
|
-
increment: (): number => importer.increment(),
|
|
18
|
-
emplaceUnion: (
|
|
19
|
-
prefix: string,
|
|
20
|
-
name: string,
|
|
21
|
-
factory: () => ts.ArrowFunction,
|
|
22
|
-
): string => importer.emplaceUnion(prefix, name, factory),
|
|
23
|
-
trace: (): void => importer.trace(),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
type MethodOnly<T> = {
|
|
27
|
-
[P in keyof T]: T[P] extends Function
|
|
28
|
-
? T[P]
|
|
29
|
-
: P extends "method"
|
|
30
|
-
? T[P]
|
|
31
|
-
: never;
|
|
32
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { FunctionImporter } from "./FunctionImporeter";
|
|
4
|
+
|
|
5
|
+
export const disable_function_importer_declare = (
|
|
6
|
+
importer: FunctionImporter,
|
|
7
|
+
): FunctionImporter => disable(importer) as FunctionImporter;
|
|
8
|
+
|
|
9
|
+
const disable = (importer: FunctionImporter): MethodOnly<FunctionImporter> => ({
|
|
10
|
+
method: importer.method,
|
|
11
|
+
empty: (): boolean => importer.empty(),
|
|
12
|
+
use: (name: string): ts.Identifier => importer.use(name),
|
|
13
|
+
useLocal: (name: string): string => importer.useLocal(name),
|
|
14
|
+
hasLocal: (name: string): boolean => importer.hasLocal(name),
|
|
15
|
+
declare: (_modulo: ts.LeftHandSideExpression): ts.Statement[] => [],
|
|
16
|
+
declareUnions: (): ts.Statement[] => [],
|
|
17
|
+
increment: (): number => importer.increment(),
|
|
18
|
+
emplaceUnion: (
|
|
19
|
+
prefix: string,
|
|
20
|
+
name: string,
|
|
21
|
+
factory: () => ts.ArrowFunction,
|
|
22
|
+
): string => importer.emplaceUnion(prefix, name, factory),
|
|
23
|
+
trace: (): void => importer.trace(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
type MethodOnly<T> = {
|
|
27
|
+
[P in keyof T]: T[P] extends Function
|
|
28
|
+
? T[P]
|
|
29
|
+
: P extends "method"
|
|
30
|
+
? T[P]
|
|
31
|
+
: never;
|
|
32
|
+
};
|
|
@@ -1,33 +1,37 @@
|
|
|
1
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
-
|
|
3
|
-
import { IJsonSchema } from "../../module";
|
|
4
|
-
import { application_default } from "./application_default";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export const application_default_string =
|
|
10
|
-
(meta: Metadata) =>
|
|
11
|
-
(attribute: IJsonSchema.IAttribute) =>
|
|
12
|
-
(schema: IJsonSchema.IString) =>
|
|
13
|
-
application_default(attribute)((str) => {
|
|
14
|
-
const conditions: boolean[] = [];
|
|
15
|
-
|
|
16
|
-
// OTHER ATOMIC TYPES
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (schema.
|
|
31
|
-
conditions.push(
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
import { IJsonSchema } from "../../module";
|
|
4
|
+
import { application_default } from "./application_default";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const application_default_string =
|
|
10
|
+
(meta: Metadata) =>
|
|
11
|
+
(attribute: IJsonSchema.IAttribute) =>
|
|
12
|
+
(schema: IJsonSchema.IString) =>
|
|
13
|
+
application_default(attribute)((str) => {
|
|
14
|
+
const conditions: boolean[] = [];
|
|
15
|
+
|
|
16
|
+
// OTHER ATOMIC TYPES
|
|
17
|
+
if (
|
|
18
|
+
meta.atomics.find(
|
|
19
|
+
(a) => a.type === "number" || a.type === "bigint",
|
|
20
|
+
)
|
|
21
|
+
)
|
|
22
|
+
conditions.push(Number.isNaN(Number(str)));
|
|
23
|
+
if (meta.atomics.find((a) => a.type === "boolean"))
|
|
24
|
+
conditions.push(str !== "true" && str !== "false");
|
|
25
|
+
for (const constant of meta.constants)
|
|
26
|
+
for (const value of constant.values)
|
|
27
|
+
conditions.push(str !== value.toString());
|
|
28
|
+
|
|
29
|
+
// CONSIDER TAGS
|
|
30
|
+
if (schema.minLength !== undefined)
|
|
31
|
+
conditions.push(str.length >= schema.minLength);
|
|
32
|
+
if (schema.maxLength !== undefined)
|
|
33
|
+
conditions.push(str.length <= schema.maxLength);
|
|
34
|
+
if (schema.pattern !== undefined)
|
|
35
|
+
conditions.push(new RegExp(schema.pattern).test(str));
|
|
36
|
+
return conditions.every((c) => c);
|
|
37
|
+
})((str) => str);
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
-
import { MetadataEscaped } from "../../schemas/metadata/MetadataEscaped";
|
|
3
|
-
|
|
4
|
-
import { IJsonComponents, IJsonSchema } from "../../module";
|
|
5
|
-
import { JsonApplicationProgrammer } from "../json/JsonApplicationProgrammer";
|
|
6
|
-
import { application_schema } from "./application_schema";
|
|
7
|
-
|
|
8
|
-
export const application_resolved =
|
|
9
|
-
(options: JsonApplicationProgrammer.IOptions) =>
|
|
10
|
-
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
11
|
-
(components: IJsonComponents) =>
|
|
12
|
-
(resolved: MetadataEscaped) =>
|
|
13
|
-
(attribute: IJsonSchema.IAttribute): IJsonSchema[] => {
|
|
14
|
-
const output = application_schema(options)(blockNever)(components)(
|
|
15
|
-
resolved.returns,
|
|
16
|
-
)(attribute);
|
|
17
|
-
if (output === null) return [];
|
|
18
|
-
|
|
19
|
-
if (is_date(new Set())(resolved.original)) {
|
|
20
|
-
const string: IJsonSchema.IString | undefined = is_string(output)
|
|
21
|
-
? output
|
|
22
|
-
: is_one_of(output)
|
|
23
|
-
? output.oneOf.find(is_string)
|
|
24
|
-
: undefined;
|
|
25
|
-
if (
|
|
26
|
-
string !== undefined &&
|
|
27
|
-
string.format !== "date" &&
|
|
28
|
-
string.format !== "date-time"
|
|
29
|
-
)
|
|
30
|
-
string.format = "date-time";
|
|
31
|
-
}
|
|
32
|
-
return is_one_of(output) ? output.oneOf : [output];
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const is_string = (elem: IJsonSchema): elem is IJsonSchema.IString =>
|
|
36
|
-
(elem as IJsonSchema.IString).type === "string";
|
|
37
|
-
|
|
38
|
-
const is_one_of = (elem: IJsonSchema): elem is IJsonSchema.IOneOf =>
|
|
39
|
-
Array.isArray((elem as IJsonSchema.IOneOf).oneOf);
|
|
40
|
-
|
|
41
|
-
const is_date =
|
|
42
|
-
(visited: Set<Metadata>) =>
|
|
43
|
-
(meta: Metadata): boolean => {
|
|
44
|
-
if (visited.has(meta)) return false;
|
|
45
|
-
visited.add(meta);
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
meta.natives.some((name) => name === "Date") ||
|
|
49
|
-
meta.arrays.some((array) => is_date(visited)(array.value)) ||
|
|
50
|
-
meta.tuples.some((tuple) =>
|
|
51
|
-
tuple.elements.some(is_date(visited)),
|
|
52
|
-
) ||
|
|
53
|
-
meta.aliases.some((alias) => is_date(visited)(alias.value))
|
|
54
|
-
);
|
|
55
|
-
};
|
|
1
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
+
import { MetadataEscaped } from "../../schemas/metadata/MetadataEscaped";
|
|
3
|
+
|
|
4
|
+
import { IJsonComponents, IJsonSchema } from "../../module";
|
|
5
|
+
import { JsonApplicationProgrammer } from "../json/JsonApplicationProgrammer";
|
|
6
|
+
import { application_schema } from "./application_schema";
|
|
7
|
+
|
|
8
|
+
export const application_resolved =
|
|
9
|
+
(options: JsonApplicationProgrammer.IOptions) =>
|
|
10
|
+
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
11
|
+
(components: IJsonComponents) =>
|
|
12
|
+
(resolved: MetadataEscaped) =>
|
|
13
|
+
(attribute: IJsonSchema.IAttribute): IJsonSchema[] => {
|
|
14
|
+
const output = application_schema(options)(blockNever)(components)(
|
|
15
|
+
resolved.returns,
|
|
16
|
+
)(attribute);
|
|
17
|
+
if (output === null) return [];
|
|
18
|
+
|
|
19
|
+
if (is_date(new Set())(resolved.original)) {
|
|
20
|
+
const string: IJsonSchema.IString | undefined = is_string(output)
|
|
21
|
+
? output
|
|
22
|
+
: is_one_of(output)
|
|
23
|
+
? output.oneOf.find(is_string)
|
|
24
|
+
: undefined;
|
|
25
|
+
if (
|
|
26
|
+
string !== undefined &&
|
|
27
|
+
string.format !== "date" &&
|
|
28
|
+
string.format !== "date-time"
|
|
29
|
+
)
|
|
30
|
+
string.format = "date-time";
|
|
31
|
+
}
|
|
32
|
+
return is_one_of(output) ? output.oneOf : [output];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const is_string = (elem: IJsonSchema): elem is IJsonSchema.IString =>
|
|
36
|
+
(elem as IJsonSchema.IString).type === "string";
|
|
37
|
+
|
|
38
|
+
const is_one_of = (elem: IJsonSchema): elem is IJsonSchema.IOneOf =>
|
|
39
|
+
Array.isArray((elem as IJsonSchema.IOneOf).oneOf);
|
|
40
|
+
|
|
41
|
+
const is_date =
|
|
42
|
+
(visited: Set<Metadata>) =>
|
|
43
|
+
(meta: Metadata): boolean => {
|
|
44
|
+
if (visited.has(meta)) return false;
|
|
45
|
+
visited.add(meta);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
meta.natives.some((name) => name === "Date") ||
|
|
49
|
+
meta.arrays.some((array) => is_date(visited)(array.value)) ||
|
|
50
|
+
meta.tuples.some((tuple) =>
|
|
51
|
+
tuple.elements.some(is_date(visited)),
|
|
52
|
+
) ||
|
|
53
|
+
meta.aliases.some((alias) => is_date(visited)(alias.value))
|
|
54
|
+
);
|
|
55
|
+
};
|