typia 6.10.0-dev.20240823 → 6.10.0-dev.20240908
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/_external/node_modules_@samchon_openapi_lib_utils/LlmSchemaSeparator.mjs +142 -0
- package/lib/_external/node_modules_@samchon_openapi_lib_utils/LlmSchemaSeparator.mjs.map +1 -0
- package/lib/_external/node_modules_@samchon_openapi_lib_utils/LlmTypeChecker.mjs +171 -0
- package/lib/_external/node_modules_@samchon_openapi_lib_utils/LlmTypeChecker.mjs.map +1 -0
- package/lib/_virtual/LlmSchemaSeparator.mjs +4 -0
- package/lib/_virtual/LlmSchemaSeparator.mjs.map +1 -0
- package/lib/_virtual/LlmTypeChecker.mjs +4 -0
- package/lib/_virtual/LlmTypeChecker.mjs.map +1 -0
- package/lib/_virtual/_commonjsHelpers.mjs +3 -1
- package/lib/_virtual/_commonjsHelpers.mjs.map +1 -1
- package/lib/factories/MetadataFactory.d.ts +1 -0
- package/lib/factories/MetadataFactory.js.map +1 -1
- package/lib/factories/MetadataTypeTagSchemaFactory.js +1 -1
- package/lib/factories/MetadataTypeTagSchemaFactory.js.map +1 -1
- package/lib/factories/ProtobufFactory.js +1 -1
- package/lib/factories/ProtobufFactory.js.map +1 -1
- package/lib/factories/TypeFactory.d.ts +1 -0
- package/lib/factories/TypeFactory.js +2 -2
- package/lib/factories/TypeFactory.js.map +1 -1
- package/lib/factories/internal/metadata/emplace_metadata_object.js +12 -7
- package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata.js +2 -0
- package/lib/factories/internal/metadata/iterate_metadata.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_coalesce.js +0 -5
- package/lib/factories/internal/metadata/iterate_metadata_coalesce.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_function.d.ts +5 -0
- package/lib/factories/internal/metadata/iterate_metadata_function.js +89 -0
- package/lib/factories/internal/metadata/iterate_metadata_function.js.map +1 -0
- package/lib/functional/Namespace/index.d.ts +1 -0
- package/lib/functional/Namespace/index.js +2 -1
- package/lib/functional/Namespace/index.js.map +1 -1
- package/lib/functional/Namespace/index.mjs +1 -0
- package/lib/functional/Namespace/index.mjs.map +1 -1
- package/lib/functional/Namespace/llm.d.ts +4 -0
- package/lib/functional/Namespace/llm.js +44 -0
- package/lib/functional/Namespace/llm.js.map +1 -0
- package/lib/functional/Namespace/llm.mjs +19 -0
- package/lib/functional/Namespace/llm.mjs.map +1 -0
- package/lib/index.mjs +2 -0
- package/lib/index.mjs.map +1 -1
- package/lib/llm.d.ts +151 -0
- package/lib/llm.js +50 -0
- package/lib/llm.js.map +1 -0
- package/lib/llm.mjs +26 -0
- package/lib/llm.mjs.map +1 -0
- package/lib/module.d.ts +1 -0
- package/lib/module.js +2 -1
- package/lib/module.js.map +1 -1
- package/lib/module.mjs +2 -0
- package/lib/module.mjs.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +1 -1
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +1 -1
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/functional/internal/FunctionalGeneralProgrammer.d.ts +1 -1
- package/lib/programmers/functional/internal/FunctionalGeneralProgrammer.js.map +1 -1
- package/lib/programmers/internal/application_escaped.js +4 -6
- package/lib/programmers/internal/application_escaped.js.map +1 -1
- package/lib/programmers/internal/application_v30_object.js +1 -1
- package/lib/programmers/internal/application_v30_object.js.map +1 -1
- package/lib/programmers/internal/application_v31_object.js +1 -1
- package/lib/programmers/internal/application_v31_object.js.map +1 -1
- package/lib/programmers/internal/llm_schema_array.d.ts +1 -0
- package/lib/programmers/internal/llm_schema_array.js +20 -0
- package/lib/programmers/internal/llm_schema_array.js.map +1 -0
- package/lib/programmers/internal/llm_schema_escaped.d.ts +1 -0
- package/lib/programmers/internal/llm_schema_escaped.js +56 -0
- package/lib/programmers/internal/llm_schema_escaped.js.map +1 -0
- package/lib/programmers/internal/llm_schema_native.d.ts +1 -0
- package/lib/programmers/internal/llm_schema_native.js +19 -0
- package/lib/programmers/internal/llm_schema_native.js.map +1 -0
- package/lib/programmers/internal/llm_schema_object.d.ts +1 -0
- package/lib/programmers/internal/llm_schema_object.js +134 -0
- package/lib/programmers/internal/llm_schema_object.js.map +1 -0
- package/lib/programmers/internal/llm_schema_station.d.ts +1 -0
- package/lib/programmers/internal/llm_schema_station.js +238 -0
- package/lib/programmers/internal/llm_schema_station.js.map +1 -0
- package/lib/programmers/internal/llm_schema_tuple.d.ts +1 -0
- package/lib/programmers/internal/llm_schema_tuple.js +33 -0
- package/lib/programmers/internal/llm_schema_tuple.js.map +1 -0
- package/lib/programmers/internal/stringify_regular_properties.js +4 -4
- package/lib/programmers/internal/stringify_regular_properties.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +2 -2
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.d.ts +7 -0
- package/lib/programmers/llm/LlmApplicationProgrammer.js +211 -0
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -0
- package/lib/programmers/llm/LlmSchemaProgrammer.d.ts +6 -0
- package/lib/programmers/llm/LlmSchemaProgrammer.js +66 -0
- package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -0
- package/lib/programmers/misc/MiscCloneProgrammer.js +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/schemas/metadata/IMetadata.d.ts +2 -1
- package/lib/schemas/metadata/IMetadataFunction.d.ts +7 -0
- package/lib/schemas/metadata/IMetadataFunction.js +3 -0
- package/lib/schemas/metadata/IMetadataFunction.js.map +1 -0
- package/lib/schemas/metadata/IMetadataParameter.d.ts +8 -0
- package/lib/schemas/metadata/IMetadataParameter.js +3 -0
- package/lib/schemas/metadata/IMetadataParameter.js.map +1 -0
- package/lib/schemas/metadata/Metadata.d.ts +2 -1
- package/lib/schemas/metadata/Metadata.js +12 -11
- package/lib/schemas/metadata/Metadata.js.map +1 -1
- package/lib/schemas/metadata/MetadataFunction.d.ts +15 -0
- package/lib/schemas/metadata/MetadataFunction.js +38 -0
- package/lib/schemas/metadata/MetadataFunction.js.map +1 -0
- package/lib/schemas/metadata/MetadataParameter.d.ts +13 -0
- package/lib/schemas/metadata/MetadataParameter.js +37 -0
- package/lib/schemas/metadata/MetadataParameter.js.map +1 -0
- package/lib/transformers/CallExpressionTransformer.js +11 -1
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/llm/LlmApplicationTransformer.d.ts +5 -0
- package/lib/transformers/features/llm/LlmApplicationTransformer.js +86 -0
- package/lib/transformers/features/llm/LlmApplicationTransformer.js.map +1 -0
- package/lib/transformers/features/llm/LlmSchemaTransformer.d.ts +5 -0
- package/lib/transformers/features/llm/LlmSchemaTransformer.js +46 -0
- package/lib/transformers/features/llm/LlmSchemaTransformer.js.map +1 -0
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js +1 -0
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js.map +1 -1
- package/lib/utils/Escaper.js +4 -0
- package/lib/utils/Escaper.js.map +1 -1
- package/package.json +3 -3
- package/src/factories/MetadataFactory.ts +1 -0
- package/src/factories/MetadataTypeTagSchemaFactory.ts +59 -59
- package/src/factories/ProtobufFactory.ts +1 -1
- package/src/factories/TypeFactory.ts +1 -1
- package/src/factories/internal/metadata/emplace_metadata_object.ts +12 -8
- package/src/factories/internal/metadata/explore_metadata.ts +28 -28
- package/src/factories/internal/metadata/iterate_metadata.ts +6 -0
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +0 -5
- package/src/factories/internal/metadata/iterate_metadata_function.ts +85 -0
- package/src/functional/Namespace/index.ts +1 -0
- package/src/functional/Namespace/llm.ts +20 -0
- package/src/llm.ts +186 -0
- package/src/module.ts +1 -0
- package/src/programmers/CheckerProgrammer.ts +1 -1
- package/src/programmers/RandomProgrammer.ts +1 -1
- package/src/programmers/functional/internal/FunctionalGeneralProgrammer.ts +3 -1
- package/src/programmers/internal/application_escaped.ts +74 -76
- package/src/programmers/internal/application_v30_object.ts +1 -1
- package/src/programmers/internal/application_v31_object.ts +1 -1
- package/src/programmers/internal/llm_schema_array.ts +22 -0
- package/src/programmers/internal/llm_schema_escaped.ts +61 -0
- package/src/programmers/internal/llm_schema_native.ts +17 -0
- package/src/programmers/internal/llm_schema_object.ts +129 -0
- package/src/programmers/internal/llm_schema_station.ts +185 -0
- package/src/programmers/internal/llm_schema_tuple.ts +31 -0
- package/src/programmers/internal/stringify_regular_properties.ts +4 -4
- package/src/programmers/json/JsonApplicationProgrammer.ts +1 -1
- package/src/programmers/json/JsonStringifyProgrammer.ts +2 -2
- package/src/programmers/llm/LlmApplicationProgrammer.ts +211 -0
- package/src/programmers/llm/LlmSchemaProgrammer.ts +49 -0
- package/src/programmers/misc/MiscCloneProgrammer.ts +1 -1
- package/src/programmers/notations/NotationGeneralProgrammer.ts +1 -1
- package/src/schemas/metadata/IMetadata.ts +2 -1
- package/src/schemas/metadata/IMetadataFunction.ts +8 -0
- package/src/schemas/metadata/IMetadataParameter.ts +9 -0
- package/src/schemas/metadata/Metadata.ts +13 -12
- package/src/schemas/metadata/MetadataFunction.ts +49 -0
- package/src/schemas/metadata/MetadataParameter.ts +50 -0
- package/src/transformers/CallExpressionTransformer.ts +508 -500
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +87 -0
- package/src/transformers/features/llm/LlmSchemaTransformer.ts +53 -0
- package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +1 -0
- package/src/utils/Escaper.ts +4 -0
|
@@ -276,7 +276,7 @@ export namespace RandomProgrammer {
|
|
|
276
276
|
expressions.push(ts.factory.createStringLiteral("any type used..."));
|
|
277
277
|
|
|
278
278
|
// NULL COALESCING
|
|
279
|
-
if (meta.isRequired() === false || meta.
|
|
279
|
+
if (meta.isRequired() === false || meta.functions.length)
|
|
280
280
|
expressions.push(ts.factory.createIdentifier("undefined"));
|
|
281
281
|
if (meta.nullable === true) expressions.push(ts.factory.createNull());
|
|
282
282
|
|
|
@@ -9,7 +9,9 @@ export namespace FunctionalGeneralProgrammer {
|
|
|
9
9
|
}
|
|
10
10
|
export const getReturnType =
|
|
11
11
|
(checker: ts.TypeChecker) =>
|
|
12
|
-
(
|
|
12
|
+
(
|
|
13
|
+
declaration: ts.FunctionDeclaration | ts.SignatureDeclaration,
|
|
14
|
+
): IOutput => {
|
|
13
15
|
const signature: ts.Signature | undefined =
|
|
14
16
|
checker.getSignatureFromDeclaration(declaration);
|
|
15
17
|
const type: ts.Type =
|
|
@@ -1,76 +1,74 @@
|
|
|
1
|
-
import { OpenApi, OpenApiV3 } from "@samchon/openapi";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
-
import { MetadataEscaped } from "../../schemas/metadata/MetadataEscaped";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export const application_escaped =
|
|
10
|
-
<Version extends "3.0" | "3.1">(
|
|
11
|
-
generator: (meta: Metadata) => Schema<Version>,
|
|
12
|
-
) =>
|
|
13
|
-
(
|
|
14
|
-
const output: Schema<Version> | null = generator(
|
|
15
|
-
if (output === null) return [];
|
|
16
|
-
|
|
17
|
-
if (is_date(new Set())(
|
|
18
|
-
const string: StringSchema<Version> | undefined = is_string(output)
|
|
19
|
-
? output
|
|
20
|
-
: is_one_of(output)
|
|
21
|
-
? (output.oneOf.find(is_string) as StringSchema<Version>)
|
|
22
|
-
: undefined;
|
|
23
|
-
if (
|
|
24
|
-
string !== undefined &&
|
|
25
|
-
string.format !== "date" &&
|
|
26
|
-
string.format !== "date-time"
|
|
27
|
-
)
|
|
28
|
-
string.format = "date-time";
|
|
29
|
-
}
|
|
30
|
-
return is_one_of(output)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
elem
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
elem
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
meta.
|
|
62
|
-
meta.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
? OpenApiV3.IJsonSchema.IOneOf
|
|
76
|
-
: OpenApi.IJsonSchema.IOneOf;
|
|
1
|
+
import { OpenApi, OpenApiV3 } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
+
import { MetadataEscaped } from "../../schemas/metadata/MetadataEscaped";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const application_escaped =
|
|
10
|
+
<Version extends "3.0" | "3.1">(
|
|
11
|
+
generator: (meta: Metadata) => Schema<Version>,
|
|
12
|
+
) =>
|
|
13
|
+
(escaped: MetadataEscaped): Schema<Version>[] => {
|
|
14
|
+
const output: Schema<Version> | null = generator(escaped.returns);
|
|
15
|
+
if (output === null) return [];
|
|
16
|
+
|
|
17
|
+
if (is_date(new Set())(escaped.original)) {
|
|
18
|
+
const string: StringSchema<Version> | undefined = is_string(output)
|
|
19
|
+
? output
|
|
20
|
+
: is_one_of(output)
|
|
21
|
+
? (output.oneOf.find(is_string) as StringSchema<Version>)
|
|
22
|
+
: undefined;
|
|
23
|
+
if (
|
|
24
|
+
string !== undefined &&
|
|
25
|
+
string.format !== "date" &&
|
|
26
|
+
string.format !== "date-time"
|
|
27
|
+
)
|
|
28
|
+
string.format = "date-time";
|
|
29
|
+
}
|
|
30
|
+
return is_one_of(output) ? (output.oneOf as Schema<Version>[]) : [output];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
const is_string = <Version extends "3.0" | "3.1">(
|
|
37
|
+
elem: Schema<Version>,
|
|
38
|
+
): elem is StringSchema<Version> =>
|
|
39
|
+
(elem as StringSchema<Version>).type === "string";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
const is_one_of = <Version extends "3.0" | "3.1">(
|
|
45
|
+
elem: Schema<Version>,
|
|
46
|
+
): elem is OneOfSchema<Version> =>
|
|
47
|
+
Array.isArray((elem as OneOfSchema<Version>).oneOf);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
const is_date =
|
|
53
|
+
(visited: Set<Metadata>) =>
|
|
54
|
+
(meta: Metadata): boolean => {
|
|
55
|
+
if (visited.has(meta)) return false;
|
|
56
|
+
visited.add(meta);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
meta.natives.some((name) => name === "Date") ||
|
|
60
|
+
meta.arrays.some((array) => is_date(visited)(array.type.value)) ||
|
|
61
|
+
meta.tuples.some((tuple) => tuple.type.elements.some(is_date(visited))) ||
|
|
62
|
+
meta.aliases.some((alias) => is_date(visited)(alias.value))
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
type Schema<Version extends "3.0" | "3.1"> = Version extends "3.0"
|
|
67
|
+
? OpenApiV3.IJsonSchema
|
|
68
|
+
: OpenApi.IJsonSchema;
|
|
69
|
+
type StringSchema<Version extends "3.0" | "3.1"> = Version extends "3.0"
|
|
70
|
+
? OpenApiV3.IJsonSchema.IString
|
|
71
|
+
: OpenApi.IJsonSchema.IString;
|
|
72
|
+
type OneOfSchema<Version extends "3.0" | "3.1"> = Version extends "3.0"
|
|
73
|
+
? OpenApiV3.IJsonSchema.IOneOf
|
|
74
|
+
: OpenApi.IJsonSchema.IOneOf;
|
|
@@ -53,7 +53,7 @@ const create_object_schema =
|
|
|
53
53
|
for (const property of obj.properties) {
|
|
54
54
|
if (
|
|
55
55
|
// FUNCTIONAL TYPE
|
|
56
|
-
property.value.
|
|
56
|
+
property.value.functions.length &&
|
|
57
57
|
property.value.nullable === false &&
|
|
58
58
|
property.value.isRequired() === true &&
|
|
59
59
|
property.value.size() === 0
|
|
@@ -51,7 +51,7 @@ const create_object_schema =
|
|
|
51
51
|
for (const property of obj.properties) {
|
|
52
52
|
if (
|
|
53
53
|
// FUNCTIONAL TYPE
|
|
54
|
-
property.value.
|
|
54
|
+
property.value.functions.length &&
|
|
55
55
|
property.value.nullable === false &&
|
|
56
56
|
property.value.isRequired() === true &&
|
|
57
57
|
property.value.size() === 0
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { MetadataArray } from "../../schemas/metadata/MetadataArray";
|
|
4
|
+
|
|
5
|
+
import { application_plugin } from "./application_plugin";
|
|
6
|
+
import { llm_schema_station } from "./llm_schema_station";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const llm_schema_array = (array: MetadataArray): ILlmSchema.IArray[] =>
|
|
12
|
+
application_plugin(
|
|
13
|
+
{
|
|
14
|
+
type: "array",
|
|
15
|
+
items: llm_schema_station({
|
|
16
|
+
metadata: array.type.value,
|
|
17
|
+
blockNever: false,
|
|
18
|
+
attribute: {},
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
array.tags,
|
|
22
|
+
);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
+
import { MetadataEscaped } from "../../schemas/metadata/MetadataEscaped";
|
|
5
|
+
|
|
6
|
+
import { llm_schema_station } from "./llm_schema_station";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const llm_schema_escaped = (escaped: MetadataEscaped): ILlmSchema[] => {
|
|
12
|
+
const output: ILlmSchema | null = llm_schema_station({
|
|
13
|
+
metadata: escaped.returns,
|
|
14
|
+
blockNever: false,
|
|
15
|
+
attribute: {},
|
|
16
|
+
});
|
|
17
|
+
if (output === null) return [];
|
|
18
|
+
else if (is_date(new Set())(escaped.original)) {
|
|
19
|
+
const string: ILlmSchema.IString | undefined = is_string(output)
|
|
20
|
+
? output
|
|
21
|
+
: is_one_of(output)
|
|
22
|
+
? (output.oneOf.find(is_string) as ILlmSchema.IString)
|
|
23
|
+
: undefined;
|
|
24
|
+
if (
|
|
25
|
+
string !== undefined &&
|
|
26
|
+
string.format !== "date" &&
|
|
27
|
+
string.format !== "date-time"
|
|
28
|
+
)
|
|
29
|
+
string.format = "date-time";
|
|
30
|
+
}
|
|
31
|
+
return is_one_of(output) ? (output.oneOf as ILlmSchema[]) : [output];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
const is_string = (elem: ILlmSchema): elem is ILlmSchema.IString =>
|
|
38
|
+
(elem as ILlmSchema.IString).type === "string";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
const is_one_of = (elem: ILlmSchema): elem is ILlmSchema.IOneOf =>
|
|
44
|
+
Array.isArray((elem as ILlmSchema.IOneOf).oneOf);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
const is_date =
|
|
50
|
+
(visited: Set<Metadata>) =>
|
|
51
|
+
(meta: Metadata): boolean => {
|
|
52
|
+
if (visited.has(meta)) return false;
|
|
53
|
+
visited.add(meta);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
meta.natives.some((name) => name === "Date") ||
|
|
57
|
+
meta.arrays.some((array) => is_date(visited)(array.type.value)) ||
|
|
58
|
+
meta.tuples.some((tuple) => tuple.type.elements.some(is_date(visited))) ||
|
|
59
|
+
meta.aliases.some((alias) => is_date(visited)(alias.value))
|
|
60
|
+
);
|
|
61
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export const llm_schema_native = (
|
|
7
|
+
name: string,
|
|
8
|
+
): ILlmSchema.IString | ILlmSchema.IObject =>
|
|
9
|
+
name === "Blob" || name === "File"
|
|
10
|
+
? {
|
|
11
|
+
type: "string",
|
|
12
|
+
format: "binary",
|
|
13
|
+
}
|
|
14
|
+
: {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {},
|
|
17
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { CommentFactory } from "../../factories/CommentFactory";
|
|
4
|
+
|
|
5
|
+
import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
|
|
6
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
7
|
+
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
8
|
+
|
|
9
|
+
import { PatternUtil } from "../../utils/PatternUtil";
|
|
10
|
+
|
|
11
|
+
import { application_description } from "./application_description";
|
|
12
|
+
import { llm_schema_station } from "./llm_schema_station";
|
|
13
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export const llm_schema_object = (props: {
|
|
19
|
+
object: MetadataObject;
|
|
20
|
+
nullable: boolean;
|
|
21
|
+
}): ILlmSchema.IObject => {
|
|
22
|
+
// ITERATE PROPERTIES
|
|
23
|
+
const properties: Record<string, any> = {};
|
|
24
|
+
const extraMeta: ISuperfluous = {
|
|
25
|
+
patternProperties: {},
|
|
26
|
+
additionalProperties: undefined,
|
|
27
|
+
};
|
|
28
|
+
const required: string[] = [];
|
|
29
|
+
|
|
30
|
+
for (const property of props.object.properties) {
|
|
31
|
+
if (
|
|
32
|
+
// FUNCTIONAL TYPE
|
|
33
|
+
property.value.functions.length &&
|
|
34
|
+
property.value.nullable === false &&
|
|
35
|
+
property.value.isRequired() === true &&
|
|
36
|
+
property.value.size() === 0
|
|
37
|
+
)
|
|
38
|
+
continue;
|
|
39
|
+
else if (property.jsDocTags.find((tag) => tag.name === "hidden")) continue; // THE HIDDEN TAG
|
|
40
|
+
|
|
41
|
+
const key: string | null = property.key.getSoleLiteral();
|
|
42
|
+
const schema: ILlmSchema | null = llm_schema_station({
|
|
43
|
+
blockNever: true,
|
|
44
|
+
attribute: {
|
|
45
|
+
deprecated:
|
|
46
|
+
property.jsDocTags.some((tag) => tag.name === "deprecated") ||
|
|
47
|
+
undefined,
|
|
48
|
+
title: (() => {
|
|
49
|
+
const info: IJsDocTagInfo | undefined = property.jsDocTags.find(
|
|
50
|
+
(tag) => tag.name === "title",
|
|
51
|
+
);
|
|
52
|
+
if (info?.text?.length) return CommentFactory.merge(info.text);
|
|
53
|
+
else if (!property.description?.length) return undefined;
|
|
54
|
+
|
|
55
|
+
const index: number = property.description.indexOf("\n");
|
|
56
|
+
const top: string = (
|
|
57
|
+
index === -1
|
|
58
|
+
? property.description
|
|
59
|
+
: property.description.substring(0, index)
|
|
60
|
+
).trim();
|
|
61
|
+
return top.endsWith(".")
|
|
62
|
+
? top.substring(0, top.length - 1)
|
|
63
|
+
: undefined;
|
|
64
|
+
})(),
|
|
65
|
+
description: application_description(property),
|
|
66
|
+
},
|
|
67
|
+
metadata: property.value,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (schema === null) continue;
|
|
71
|
+
if (key !== null) {
|
|
72
|
+
properties[key] = schema;
|
|
73
|
+
if (property.value.isRequired() === true) required.push(key);
|
|
74
|
+
} else {
|
|
75
|
+
const pattern: string = metadata_to_pattern(true)(property.key);
|
|
76
|
+
if (pattern === PatternUtil.STRING)
|
|
77
|
+
extraMeta.additionalProperties = [property.value, schema];
|
|
78
|
+
else extraMeta.patternProperties[pattern] = [property.value, schema];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
type: "object",
|
|
84
|
+
properties,
|
|
85
|
+
nullable: props.nullable,
|
|
86
|
+
required: required.length ? required : undefined,
|
|
87
|
+
title: (() => {
|
|
88
|
+
const info: IJsDocTagInfo | undefined = props.object.jsDocTags.find(
|
|
89
|
+
(tag) => tag.name === "title",
|
|
90
|
+
);
|
|
91
|
+
return info?.text?.length ? CommentFactory.merge(info.text) : undefined;
|
|
92
|
+
})(),
|
|
93
|
+
description: application_description(props.object),
|
|
94
|
+
additionalProperties: join(extraMeta),
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
const join = (extra: ISuperfluous): ILlmSchema | undefined => {
|
|
102
|
+
// LIST UP METADATA
|
|
103
|
+
const elements: [Metadata, ILlmSchema][] = Object.values(
|
|
104
|
+
extra.patternProperties || {},
|
|
105
|
+
);
|
|
106
|
+
if (extra.additionalProperties) elements.push(extra.additionalProperties);
|
|
107
|
+
|
|
108
|
+
// SHORT RETURN
|
|
109
|
+
if (elements.length === 0) return undefined;
|
|
110
|
+
else if (elements.length === 1) return elements[0]![1]!;
|
|
111
|
+
|
|
112
|
+
// MERGE METADATA AND GENERATE VULNERABLE SCHEMA
|
|
113
|
+
const meta: Metadata = elements
|
|
114
|
+
.map((tuple) => tuple[0])
|
|
115
|
+
.reduce((x, y) => Metadata.merge(x, y));
|
|
116
|
+
return llm_schema_station({
|
|
117
|
+
blockNever: true,
|
|
118
|
+
attribute: {},
|
|
119
|
+
metadata: meta,
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
interface ISuperfluous {
|
|
127
|
+
additionalProperties?: undefined | [Metadata, ILlmSchema];
|
|
128
|
+
patternProperties: Record<string, [Metadata, ILlmSchema]>;
|
|
129
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
+
import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
|
|
5
|
+
|
|
6
|
+
import { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
7
|
+
import { application_bigint } from "./application_bigint";
|
|
8
|
+
import { application_boolean } from "./application_boolean";
|
|
9
|
+
import { application_number } from "./application_number";
|
|
10
|
+
import { application_string } from "./application_string";
|
|
11
|
+
import { application_templates } from "./application_templates";
|
|
12
|
+
import { application_v30_constant } from "./application_v30_constant";
|
|
13
|
+
import { llm_schema_array } from "./llm_schema_array";
|
|
14
|
+
import { llm_schema_escaped } from "./llm_schema_escaped";
|
|
15
|
+
import { llm_schema_native } from "./llm_schema_native";
|
|
16
|
+
import { llm_schema_object } from "./llm_schema_object";
|
|
17
|
+
import { llm_schema_tuple } from "./llm_schema_tuple";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export const llm_schema_station = (props: {
|
|
23
|
+
metadata: Metadata;
|
|
24
|
+
blockNever: boolean;
|
|
25
|
+
attribute: ILlmSchema.__IAttribute;
|
|
26
|
+
}): ILlmSchema => {
|
|
27
|
+
// VULNERABLE CASE
|
|
28
|
+
if (props.metadata.any === true)
|
|
29
|
+
return {
|
|
30
|
+
...props.attribute,
|
|
31
|
+
type: undefined,
|
|
32
|
+
};
|
|
33
|
+
else if (props.metadata.nullable === true && props.metadata.empty() === true)
|
|
34
|
+
return {
|
|
35
|
+
...props.attribute,
|
|
36
|
+
type: "null",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//----
|
|
40
|
+
// GATHER UNION SCHEMAS
|
|
41
|
+
//----
|
|
42
|
+
const union: ILlmSchema[] = [];
|
|
43
|
+
const insert = props.metadata.nullable
|
|
44
|
+
? (schema: ILlmSchema) =>
|
|
45
|
+
union.push({
|
|
46
|
+
...schema,
|
|
47
|
+
nullable: (schema as ILlmSchema.__ISignificant<any>).type
|
|
48
|
+
? true
|
|
49
|
+
: undefined,
|
|
50
|
+
} as ILlmSchema)
|
|
51
|
+
: (schema: ILlmSchema) => union.push(schema);
|
|
52
|
+
|
|
53
|
+
// toJSON() METHOD
|
|
54
|
+
if (props.metadata.escaped !== null)
|
|
55
|
+
llm_schema_escaped(props.metadata.escaped).forEach(insert);
|
|
56
|
+
|
|
57
|
+
// ATOMIC TYPES
|
|
58
|
+
if (
|
|
59
|
+
props.metadata.templates.length &&
|
|
60
|
+
AtomicPredicator.template(props.metadata)
|
|
61
|
+
)
|
|
62
|
+
application_templates<"3.0">(props.metadata).map(insert);
|
|
63
|
+
for (const constant of props.metadata.constants)
|
|
64
|
+
if (AtomicPredicator.constant(props.metadata)(constant.type) === false)
|
|
65
|
+
continue;
|
|
66
|
+
else insert(application_v30_constant(constant));
|
|
67
|
+
for (const a of props.metadata.atomics)
|
|
68
|
+
if (a.type === "boolean") application_boolean<"3.0">(a).forEach(insert);
|
|
69
|
+
else if (a.type === "bigint") application_bigint<"3.0">(a).forEach(insert);
|
|
70
|
+
else if (a.type === "number") application_number<"3.0">(a).forEach(insert);
|
|
71
|
+
else if (a.type === "string") application_string<"3.0">(a).forEach(insert);
|
|
72
|
+
|
|
73
|
+
// ARRAY
|
|
74
|
+
for (const array of props.metadata.arrays)
|
|
75
|
+
if (array.type.recursive)
|
|
76
|
+
throw new Error(
|
|
77
|
+
"Error on LlmSchemaProgrammer.write(): LLM schema does not allow recursive array type.",
|
|
78
|
+
);
|
|
79
|
+
else llm_schema_array(array).forEach(insert);
|
|
80
|
+
|
|
81
|
+
// TUPLE
|
|
82
|
+
for (const tuple of props.metadata.tuples)
|
|
83
|
+
if (tuple.type.recursive)
|
|
84
|
+
throw new Error(
|
|
85
|
+
"Error on LlmSchemaProgrammer.write(): LLM schema does not allow recursive tuple type.",
|
|
86
|
+
);
|
|
87
|
+
else
|
|
88
|
+
insert(
|
|
89
|
+
llm_schema_tuple({
|
|
90
|
+
tuple,
|
|
91
|
+
attribute: props.attribute,
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// NATIVES
|
|
96
|
+
for (const native of props.metadata.natives)
|
|
97
|
+
if (AtomicPredicator.native(native)) {
|
|
98
|
+
const type: string = native.toLowerCase();
|
|
99
|
+
if (props.metadata.atomics.some((a) => a.type === type)) continue;
|
|
100
|
+
else if (type === "boolean")
|
|
101
|
+
insert(
|
|
102
|
+
application_boolean<"3.0">(
|
|
103
|
+
MetadataAtomic.create({
|
|
104
|
+
type: "boolean",
|
|
105
|
+
tags: [],
|
|
106
|
+
}),
|
|
107
|
+
)[0]!,
|
|
108
|
+
);
|
|
109
|
+
else if (type === "bigint")
|
|
110
|
+
insert(
|
|
111
|
+
application_bigint(
|
|
112
|
+
MetadataAtomic.create({
|
|
113
|
+
type: "bigint",
|
|
114
|
+
tags: [],
|
|
115
|
+
}),
|
|
116
|
+
)[0]!,
|
|
117
|
+
);
|
|
118
|
+
else if (type === "number")
|
|
119
|
+
insert(
|
|
120
|
+
application_number(
|
|
121
|
+
MetadataAtomic.create({
|
|
122
|
+
type: "number",
|
|
123
|
+
tags: [],
|
|
124
|
+
}),
|
|
125
|
+
)[0]!,
|
|
126
|
+
);
|
|
127
|
+
else if (type === "string")
|
|
128
|
+
insert(
|
|
129
|
+
application_string(
|
|
130
|
+
MetadataAtomic.create({
|
|
131
|
+
type: "string",
|
|
132
|
+
tags: [],
|
|
133
|
+
}),
|
|
134
|
+
)[0]!,
|
|
135
|
+
);
|
|
136
|
+
} else insert(llm_schema_native(native));
|
|
137
|
+
if (props.metadata.sets.length) insert(llm_schema_native("Set"));
|
|
138
|
+
if (props.metadata.maps.length) insert(llm_schema_native("Map"));
|
|
139
|
+
|
|
140
|
+
// OBJECT
|
|
141
|
+
for (const object of props.metadata.objects)
|
|
142
|
+
if (object.recursive)
|
|
143
|
+
throw new Error(
|
|
144
|
+
"Error on LlmSchemaProgrammer.write(): LLM schema does not allow recursive object type.",
|
|
145
|
+
);
|
|
146
|
+
else
|
|
147
|
+
insert(
|
|
148
|
+
llm_schema_object({
|
|
149
|
+
object,
|
|
150
|
+
nullable: props.metadata.nullable,
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
// ALIASES
|
|
155
|
+
for (const alias of props.metadata.aliases)
|
|
156
|
+
if (alias.recursive)
|
|
157
|
+
throw new Error(
|
|
158
|
+
"Error on LlmSchemaProgrammer.write(): LLM schema does not allow recursive alias type.",
|
|
159
|
+
);
|
|
160
|
+
else
|
|
161
|
+
insert(
|
|
162
|
+
llm_schema_station({
|
|
163
|
+
...props,
|
|
164
|
+
metadata: alias.value,
|
|
165
|
+
}),
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
//----
|
|
169
|
+
// RETURNS
|
|
170
|
+
//----
|
|
171
|
+
if (union.length === 0 && props.blockNever === true) return null!;
|
|
172
|
+
const schema: ILlmSchema =
|
|
173
|
+
union.length === 0
|
|
174
|
+
? { type: undefined }
|
|
175
|
+
: union.length === 1
|
|
176
|
+
? union[0]!
|
|
177
|
+
: { oneOf: union };
|
|
178
|
+
return {
|
|
179
|
+
...schema,
|
|
180
|
+
...props.attribute,
|
|
181
|
+
title: props.attribute.title ?? schema.title,
|
|
182
|
+
description: props.attribute.description ?? schema.description,
|
|
183
|
+
deprecated: props.attribute.deprecated ?? schema.deprecated,
|
|
184
|
+
};
|
|
185
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
+
import { MetadataTuple } from "../../schemas/metadata/MetadataTuple";
|
|
5
|
+
|
|
6
|
+
import { llm_schema_station } from "./llm_schema_station";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const llm_schema_tuple = (props: {
|
|
12
|
+
tuple: MetadataTuple;
|
|
13
|
+
attribute: ILlmSchema.__IAttribute;
|
|
14
|
+
}): ILlmSchema.IArray => ({
|
|
15
|
+
...props.attribute,
|
|
16
|
+
type: "array",
|
|
17
|
+
items: llm_schema_station({
|
|
18
|
+
blockNever: false,
|
|
19
|
+
attribute: props.attribute,
|
|
20
|
+
metadata: props.tuple.type.elements.reduce(
|
|
21
|
+
(x, y) => Metadata.merge(x.rest ?? x, y.rest ?? y),
|
|
22
|
+
Metadata.initialize(),
|
|
23
|
+
),
|
|
24
|
+
}),
|
|
25
|
+
minItems: !!props.tuple.type.elements.at(-1)?.rest
|
|
26
|
+
? props.tuple.type.elements.length - 1
|
|
27
|
+
: props.tuple.type.elements.filter((x) => !x.optional).length,
|
|
28
|
+
maxItems: !!props.tuple.type.elements.at(-1)?.rest
|
|
29
|
+
? undefined!
|
|
30
|
+
: props.tuple.type.elements.length,
|
|
31
|
+
});
|
|
@@ -31,14 +31,14 @@ export const stringify_regular_properties = (
|
|
|
31
31
|
(entry.meta.isRequired() === false &&
|
|
32
32
|
entry.meta.nullable === false &&
|
|
33
33
|
entry.meta.size() === 0) ||
|
|
34
|
-
(entry.meta.
|
|
34
|
+
(!!entry.meta.functions.length &&
|
|
35
35
|
entry.meta.nullable === false &&
|
|
36
36
|
entry.meta.size() === 1);
|
|
37
37
|
|
|
38
38
|
if (empty === true) return;
|
|
39
39
|
else if (
|
|
40
40
|
entry.meta.isRequired() === false ||
|
|
41
|
-
entry.meta.
|
|
41
|
+
entry.meta.functions.length ||
|
|
42
42
|
entry.meta.any === true
|
|
43
43
|
)
|
|
44
44
|
output.push(
|
|
@@ -52,7 +52,7 @@ export const stringify_regular_properties = (
|
|
|
52
52
|
entry.input,
|
|
53
53
|
),
|
|
54
54
|
);
|
|
55
|
-
if (entry.meta.
|
|
55
|
+
if (entry.meta.functions.length || entry.meta.any)
|
|
56
56
|
conditions.push(
|
|
57
57
|
ts.factory.createStrictEquality(
|
|
58
58
|
ts.factory.createStringLiteral("function"),
|
|
@@ -78,4 +78,4 @@ export const stringify_regular_properties = (
|
|
|
78
78
|
* @internal
|
|
79
79
|
*/
|
|
80
80
|
const sequence = (meta: Metadata): number =>
|
|
81
|
-
meta.any || !meta.isRequired() || meta.
|
|
81
|
+
meta.any || !meta.isRequired() || meta.functions.length ? 0 : 1;
|