typia 15.0.0 → 15.0.1
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/http.d.ts +49 -24
- package/lib/http.js.map +1 -1
- package/lib/http.mjs.map +1 -1
- package/lib/internal/_httpFormDataReadBigint.js +7 -5
- package/lib/internal/_httpFormDataReadBigint.js.map +1 -1
- package/lib/internal/_httpFormDataReadBigint.mjs +1 -1
- package/lib/internal/_httpFormDataReadBigint.mjs.map +1 -1
- package/lib/internal/_httpFormDataReadBoolean.js +12 -10
- package/lib/internal/_httpFormDataReadBoolean.js.map +1 -1
- package/lib/internal/_httpFormDataReadBoolean.mjs +1 -1
- package/lib/internal/_httpFormDataReadBoolean.mjs.map +1 -1
- package/lib/internal/_httpFormDataReadNumber.js +7 -5
- package/lib/internal/_httpFormDataReadNumber.js.map +1 -1
- package/lib/internal/_httpFormDataReadNumber.mjs +1 -1
- package/lib/internal/_httpFormDataReadNumber.mjs.map +1 -1
- package/lib/internal/_httpFormDataReadString.d.ts +9 -1
- package/lib/internal/_httpFormDataReadString.js +10 -2
- package/lib/internal/_httpFormDataReadString.js.map +1 -1
- package/lib/internal/_httpFormDataReadString.mjs +9 -1
- package/lib/internal/_httpFormDataReadString.mjs.map +1 -1
- package/lib/internal/_httpHeaderReadBigint.js +5 -1
- package/lib/internal/_httpHeaderReadBigint.js.map +1 -1
- package/lib/internal/_httpHeaderReadBigint.mjs +2 -1
- package/lib/internal/_httpHeaderReadBigint.mjs.map +1 -1
- package/lib/internal/_httpHeaderReadNumber.js +5 -1
- package/lib/internal/_httpHeaderReadNumber.js.map +1 -1
- package/lib/internal/_httpHeaderReadNumber.mjs +2 -1
- package/lib/internal/_httpHeaderReadNumber.mjs.map +1 -1
- package/lib/internal/_httpParameterReadBigint.js +4 -0
- package/lib/internal/_httpParameterReadBigint.js.map +1 -1
- package/lib/internal/_httpParameterReadBigint.mjs +1 -0
- package/lib/internal/_httpParameterReadBigint.mjs.map +1 -1
- package/lib/internal/_httpParameterReadNumber.js +4 -0
- package/lib/internal/_httpParameterReadNumber.js.map +1 -1
- package/lib/internal/_httpParameterReadNumber.mjs +1 -0
- package/lib/internal/_httpParameterReadNumber.mjs.map +1 -1
- package/lib/internal/_httpParameterReadString.d.ts +9 -1
- package/lib/internal/_httpParameterReadString.js +9 -1
- package/lib/internal/_httpParameterReadString.js.map +1 -1
- package/lib/internal/_httpParameterReadString.mjs +9 -1
- package/lib/internal/_httpParameterReadString.mjs.map +1 -1
- package/lib/internal/_httpQueryReadBigint.js +8 -1
- package/lib/internal/_httpQueryReadBigint.js.map +1 -1
- package/lib/internal/_httpQueryReadBigint.mjs +1 -1
- package/lib/internal/_httpQueryReadBigint.mjs.map +1 -1
- package/lib/internal/_httpQueryReadBoolean.js +4 -1
- package/lib/internal/_httpQueryReadBoolean.js.map +1 -1
- package/lib/internal/_httpQueryReadBoolean.mjs +1 -1
- package/lib/internal/_httpQueryReadBoolean.mjs.map +1 -1
- package/lib/internal/_httpQueryReadNumber.js +8 -1
- package/lib/internal/_httpQueryReadNumber.js.map +1 -1
- package/lib/internal/_httpQueryReadNumber.mjs +1 -1
- package/lib/internal/_httpQueryReadNumber.mjs.map +1 -1
- package/lib/internal/_httpQueryReadString.d.ts +9 -1
- package/lib/internal/_httpQueryReadString.js +9 -1
- package/lib/internal/_httpQueryReadString.js.map +1 -1
- package/lib/internal/_httpQueryReadString.mjs +9 -1
- package/lib/internal/_httpQueryReadString.mjs.map +1 -1
- package/lib/internal/_randomBigint.d.ts +12 -1
- package/lib/internal/_randomBigint.js +90 -2
- package/lib/internal/_randomBigint.js.map +1 -1
- package/lib/internal/_randomBigint.mjs +70 -2
- package/lib/internal/_randomBigint.mjs.map +1 -1
- package/lib/internal/_randomInteger.js +21 -12
- package/lib/internal/_randomInteger.js.map +1 -1
- package/lib/internal/_randomInteger.mjs +21 -16
- package/lib/internal/_randomInteger.mjs.map +1 -1
- package/lib/internal/_randomNumber.js +19 -10
- package/lib/internal/_randomNumber.js.map +1 -1
- package/lib/internal/_randomNumber.mjs +19 -14
- package/lib/internal/_randomNumber.mjs.map +1 -1
- package/native/cmd/ttsc-typia/llm_evaluation_rejects_invalid_probability_test.go +9 -0
- package/native/cmd/ttsc-typia/random_recursive_min_items_diagnostic_test.go +18 -1
- package/native/core/factories/ExpressionFactory.go +16 -1
- package/native/core/factories/MetadataCommentTagFactory.go +177 -29
- package/native/core/factories/expression_factory_number_spells_non_finite_values_test.go +69 -0
- package/native/core/factories/metadata_comment_tag_factory_holds_bigint_tags_exact_test.go +168 -0
- package/native/core/factories/metadata_comment_tag_factory_reads_javascript_numbers_test.go +158 -0
- package/native/core/programmers/functional/FunctionalAssertParametersProgrammer.go +1 -3
- package/native/core/programmers/functional/FunctionalIsParametersProgrammer.go +107 -9
- package/native/core/programmers/functional/FunctionalValidateParametersProgrammer.go +1 -3
- package/native/core/programmers/http/HttpFormDataProgrammer.go +41 -2
- package/native/core/programmers/http/HttpHeadersProgrammer.go +56 -4
- package/native/core/programmers/http/HttpParameterProgrammer.go +1 -3
- package/native/core/programmers/http/HttpQueryProgrammer.go +26 -43
- package/native/core/programmers/iterate/json_schema_jsDocTags.go +10 -3
- package/native/core/programmers/iterate/json_schema_jsdoc_tags_cast_reads_javascript_numbers_test.go +64 -0
- package/native/core/programmers/llm/LlmEvaluationProgrammer.go +6 -2
- package/native/core/programmers/llm/LlmSchemaProgrammer.go +34 -4
- package/native/core/utils/NumberUtil.go +195 -0
- package/native/core/utils/number_util_rational_keeps_written_value_test.go +62 -0
- package/native/core/utils/number_util_reads_javascript_number_grammar_test.go +147 -0
- package/package.json +3 -3
- package/src/http.ts +61 -34
- package/src/internal/_httpFormDataReadBigint.ts +3 -1
- package/src/internal/_httpFormDataReadBoolean.ts +3 -1
- package/src/internal/_httpFormDataReadNumber.ts +3 -1
- package/src/internal/_httpFormDataReadString.ts +10 -1
- package/src/internal/_httpHeaderReadBigint.ts +6 -1
- package/src/internal/_httpHeaderReadNumber.ts +6 -1
- package/src/internal/_httpParameterReadBigint.ts +3 -0
- package/src/internal/_httpParameterReadNumber.ts +3 -0
- package/src/internal/_httpParameterReadString.ts +12 -2
- package/src/internal/_httpQueryReadBigint.ts +7 -1
- package/src/internal/_httpQueryReadBoolean.ts +3 -1
- package/src/internal/_httpQueryReadNumber.ts +7 -1
- package/src/internal/_httpQueryReadString.ts +10 -1
- package/src/internal/_randomBigint.ts +111 -3
- package/src/internal/_randomInteger.ts +31 -16
- package/src/internal/_randomNumber.ts +23 -12
|
@@ -30,12 +30,8 @@ const scalar = (props) => {
|
|
|
30
30
|
return Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
|
|
31
31
|
};
|
|
32
32
|
const getLowerBoundary = (schema) => {
|
|
33
|
-
const inclusive = schema.minimum
|
|
34
|
-
|
|
35
|
-
: { value: schema.minimum, exclusive: false };
|
|
36
|
-
const exclusive = schema.exclusiveMinimum === undefined
|
|
37
|
-
? null
|
|
38
|
-
: { value: schema.exclusiveMinimum, exclusive: true };
|
|
33
|
+
const inclusive = boundary(schema.minimum, false, "lower");
|
|
34
|
+
const exclusive = boundary(schema.exclusiveMinimum, true, "lower");
|
|
39
35
|
const selected = selectBoundary(inclusive, exclusive, Math.max);
|
|
40
36
|
if (selected === null)
|
|
41
37
|
return null;
|
|
@@ -47,12 +43,8 @@ const getLowerBoundary = (schema) => {
|
|
|
47
43
|
};
|
|
48
44
|
};
|
|
49
45
|
const getUpperBoundary = (schema) => {
|
|
50
|
-
const inclusive = schema.maximum
|
|
51
|
-
|
|
52
|
-
: { value: schema.maximum, exclusive: false };
|
|
53
|
-
const exclusive = schema.exclusiveMaximum === undefined
|
|
54
|
-
? null
|
|
55
|
-
: { value: schema.exclusiveMaximum, exclusive: true };
|
|
46
|
+
const inclusive = boundary(schema.maximum, false, "upper");
|
|
47
|
+
const exclusive = boundary(schema.exclusiveMaximum, true, "upper");
|
|
56
48
|
const selected = selectBoundary(inclusive, exclusive, Math.min);
|
|
57
49
|
if (selected === null)
|
|
58
50
|
return null;
|
|
@@ -63,6 +55,23 @@ const getUpperBoundary = (schema) => {
|
|
|
63
55
|
exclusive: false,
|
|
64
56
|
};
|
|
65
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Reads one bound, which may be infinite.
|
|
60
|
+
*
|
|
61
|
+
* A type tag built from an overflowing literal (`Maximum<1e400>`) carries an
|
|
62
|
+
* infinite bound (#2452). `-Infinity` below or `Infinity` above excludes no
|
|
63
|
+
* finite number, so it is no bound at all; `Infinity` below or `-Infinity`
|
|
64
|
+
* above excludes every finite number, so no value can be generated.
|
|
65
|
+
*/
|
|
66
|
+
const boundary = (value, exclusive, side) => {
|
|
67
|
+
if (value === undefined)
|
|
68
|
+
return null;
|
|
69
|
+
if (Number.isFinite(value))
|
|
70
|
+
return { value, exclusive };
|
|
71
|
+
if (value === (side === "lower" ? -Infinity : Infinity))
|
|
72
|
+
return null;
|
|
73
|
+
throw new Error("Numeric range has no finite value.");
|
|
74
|
+
};
|
|
66
75
|
const selectBoundary = (x, y, compare) => {
|
|
67
76
|
if (x === null)
|
|
68
77
|
return y;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomInteger.js","sourceRoot":"","sources":["../../src/internal/_randomInteger.ts"],"names":[],"mappings":";;;AAEA,uDAAoD;AAE7C,MAAM,cAAc,GAAG,CAC5B,MAAoC,EAC5B,EAAE;;IACV,MAAM,KAAK,GAAqB,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzD,MAAM,KAAK,GAAqB,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzD,MAAM,OAAO,SACX,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,mCAAI,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;IAC3D,MAAM,OAAO,SACX,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,m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AC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC"}
|
|
@@ -25,14 +25,8 @@ const scalar = (props) => {
|
|
|
25
25
|
return Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
|
|
26
26
|
};
|
|
27
27
|
const getLowerBoundary = (schema) => {
|
|
28
|
-
const inclusive = schema.minimum
|
|
29
|
-
|
|
30
|
-
exclusive: false
|
|
31
|
-
};
|
|
32
|
-
const exclusive = schema.exclusiveMinimum === void 0 ? null : {
|
|
33
|
-
value: schema.exclusiveMinimum,
|
|
34
|
-
exclusive: true
|
|
35
|
-
};
|
|
28
|
+
const inclusive = boundary(schema.minimum, false, "lower");
|
|
29
|
+
const exclusive = boundary(schema.exclusiveMinimum, true, "lower");
|
|
36
30
|
const selected = selectBoundary(inclusive, exclusive, Math.max);
|
|
37
31
|
if (selected === null) return null;
|
|
38
32
|
return {
|
|
@@ -41,14 +35,8 @@ const getLowerBoundary = (schema) => {
|
|
|
41
35
|
};
|
|
42
36
|
};
|
|
43
37
|
const getUpperBoundary = (schema) => {
|
|
44
|
-
const inclusive = schema.maximum
|
|
45
|
-
|
|
46
|
-
exclusive: false
|
|
47
|
-
};
|
|
48
|
-
const exclusive = schema.exclusiveMaximum === void 0 ? null : {
|
|
49
|
-
value: schema.exclusiveMaximum,
|
|
50
|
-
exclusive: true
|
|
51
|
-
};
|
|
38
|
+
const inclusive = boundary(schema.maximum, false, "upper");
|
|
39
|
+
const exclusive = boundary(schema.exclusiveMaximum, true, "upper");
|
|
52
40
|
const selected = selectBoundary(inclusive, exclusive, Math.min);
|
|
53
41
|
if (selected === null) return null;
|
|
54
42
|
return {
|
|
@@ -56,6 +44,23 @@ const getUpperBoundary = (schema) => {
|
|
|
56
44
|
exclusive: false
|
|
57
45
|
};
|
|
58
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* Reads one bound, which may be infinite.
|
|
49
|
+
*
|
|
50
|
+
* A type tag built from an overflowing literal (`Maximum<1e400>`) carries an
|
|
51
|
+
* infinite bound (#2452). `-Infinity` below or `Infinity` above excludes no
|
|
52
|
+
* finite number, so it is no bound at all; `Infinity` below or `-Infinity`
|
|
53
|
+
* above excludes every finite number, so no value can be generated.
|
|
54
|
+
*/
|
|
55
|
+
const boundary = (value, exclusive, side) => {
|
|
56
|
+
if (value === void 0) return null;
|
|
57
|
+
if (Number.isFinite(value)) return {
|
|
58
|
+
value,
|
|
59
|
+
exclusive
|
|
60
|
+
};
|
|
61
|
+
if (value === (side === "lower" ? -Infinity : Infinity)) return null;
|
|
62
|
+
throw new Error("Numeric range has no finite value.");
|
|
63
|
+
};
|
|
59
64
|
const selectBoundary = (x, y, compare) => {
|
|
60
65
|
if (x === null) return y;
|
|
61
66
|
if (y === null) return x;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomInteger.mjs","names":[],"sources":["../../src/internal/_randomInteger.ts"],"sourcesContent":["import { OpenApi } from \"@typia/interface\";\n\nimport { _randomMultiple } from \"./_randomMultiple\";\n\nexport const _randomInteger = (\n schema: OpenApi.IJsonSchema.IInteger,\n): number => {\n const lower: IBoundary | null = getLowerBoundary(schema);\n const upper: IBoundary | null = getUpperBoundary(schema);\n const minimum: number =\n lower?.value ?? (upper === null ? 0 : upper.value - 100);\n const maximum: number =\n upper?.value ?? (lower === null ? 100 : lower.value + 100);\n if (minimum > maximum)\n throw new Error(\"Minimum value is greater than maximum value.\");\n return schema.multipleOf === undefined\n ? scalar({ minimum, maximum })\n : _randomMultiple({\n minimum,\n maximum,\n multipleOf: schema.multipleOf,\n exclusiveMinimum: lower?.exclusive ?? false,\n exclusiveMaximum: upper?.exclusive ?? false,\n integer: true,\n });\n};\n\nconst scalar = (props: { minimum: number; maximum: number }): number => {\n const minimum: number = Math.ceil(props.minimum);\n const maximum: number = Math.floor(props.maximum);\n if (minimum > maximum) throw new Error(\"The integer range is empty.\");\n return Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;\n};\n\nconst getLowerBoundary = (\n schema: OpenApi.IJsonSchema.IInteger,\n): IBoundary | null => {\n const inclusive: IBoundary | null
|
|
1
|
+
{"version":3,"file":"_randomInteger.mjs","names":[],"sources":["../../src/internal/_randomInteger.ts"],"sourcesContent":["import { OpenApi } from \"@typia/interface\";\n\nimport { _randomMultiple } from \"./_randomMultiple\";\n\nexport const _randomInteger = (\n schema: OpenApi.IJsonSchema.IInteger,\n): number => {\n const lower: IBoundary | null = getLowerBoundary(schema);\n const upper: IBoundary | null = getUpperBoundary(schema);\n const minimum: number =\n lower?.value ?? (upper === null ? 0 : upper.value - 100);\n const maximum: number =\n upper?.value ?? (lower === null ? 100 : lower.value + 100);\n if (minimum > maximum)\n throw new Error(\"Minimum value is greater than maximum value.\");\n return schema.multipleOf === undefined\n ? scalar({ minimum, maximum })\n : _randomMultiple({\n minimum,\n maximum,\n multipleOf: schema.multipleOf,\n exclusiveMinimum: lower?.exclusive ?? false,\n exclusiveMaximum: upper?.exclusive ?? false,\n integer: true,\n });\n};\n\nconst scalar = (props: { minimum: number; maximum: number }): number => {\n const minimum: number = Math.ceil(props.minimum);\n const maximum: number = Math.floor(props.maximum);\n if (minimum > maximum) throw new Error(\"The integer range is empty.\");\n return Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;\n};\n\nconst getLowerBoundary = (\n schema: OpenApi.IJsonSchema.IInteger,\n): IBoundary | null => {\n const inclusive: IBoundary | null = boundary(schema.minimum, false, \"lower\");\n const exclusive: IBoundary | null = boundary(\n schema.exclusiveMinimum,\n true,\n \"lower\",\n );\n const selected: IBoundary | null = selectBoundary(\n inclusive,\n exclusive,\n Math.max,\n );\n if (selected === null) return null;\n return {\n value: selected.exclusive\n ? Math.floor(selected.value) + 1\n : Math.ceil(selected.value),\n exclusive: false,\n };\n};\n\nconst getUpperBoundary = (\n schema: OpenApi.IJsonSchema.IInteger,\n): IBoundary | null => {\n const inclusive: IBoundary | null = boundary(schema.maximum, false, \"upper\");\n const exclusive: IBoundary | null = boundary(\n schema.exclusiveMaximum,\n true,\n \"upper\",\n );\n const selected: IBoundary | null = selectBoundary(\n inclusive,\n exclusive,\n Math.min,\n );\n if (selected === null) return null;\n return {\n value: selected.exclusive\n ? Math.ceil(selected.value) - 1\n : Math.floor(selected.value),\n exclusive: false,\n };\n};\n\n/**\n * Reads one bound, which may be infinite.\n *\n * A type tag built from an overflowing literal (`Maximum<1e400>`) carries an\n * infinite bound (#2452). `-Infinity` below or `Infinity` above excludes no\n * finite number, so it is no bound at all; `Infinity` below or `-Infinity`\n * above excludes every finite number, so no value can be generated.\n */\nconst boundary = (\n value: number | undefined,\n exclusive: boolean,\n side: \"lower\" | \"upper\",\n): IBoundary | null => {\n if (value === undefined) return null;\n if (Number.isFinite(value)) return { value, exclusive };\n if (value === (side === \"lower\" ? -Infinity : Infinity)) return null;\n throw new Error(\"Numeric range has no finite value.\");\n};\n\nconst selectBoundary = (\n x: IBoundary | null,\n y: IBoundary | null,\n compare: (x: number, y: number) => number,\n): IBoundary | null => {\n if (x === null) return y;\n if (y === null) return x;\n if (x.value === y.value)\n return { value: x.value, exclusive: x.exclusive || y.exclusive };\n return compare(x.value, y.value) === x.value ? x : y;\n};\n\ninterface IBoundary {\n value: number;\n exclusive: boolean;\n}\n"],"mappings":";;AAIA,MAAa,kBACX,WACW;CACX,MAAM,QAA0B,iBAAiB,MAAM;CACvD,MAAM,QAA0B,iBAAiB,MAAM;CACvD,MAAM,UACJ,OAAO,UAAU,UAAU,OAAO,IAAI,MAAM,QAAQ;CACtD,MAAM,UACJ,OAAO,UAAU,UAAU,OAAO,MAAM,MAAM,QAAQ;CACxD,IAAI,UAAU,SACZ,MAAM,IAAI,MAAM,8CAA8C;CAChE,OAAO,OAAO,eAAe,KAAA,IACzB,OAAO;EAAE;EAAS;CAAQ,CAAC,IAC3B,gBAAgB;EACd;EACA;EACA,YAAY,OAAO;EACnB,kBAAkB,OAAO,aAAa;EACtC,kBAAkB,OAAO,aAAa;EACt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,UAAU,EAAE,OAChB,OAAO;EAAE,OAAO,EAAE;EAAO,WAAW,EAAE,aAAa,EAAE;CAAU;CACjE,OAAO,QAAQ,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,QAAQ,IAAI;AACrD"}
|
|
@@ -41,16 +41,25 @@ const scalar = (props) => {
|
|
|
41
41
|
}
|
|
42
42
|
return value;
|
|
43
43
|
};
|
|
44
|
-
const getLowerBoundary = (schema) => selectBoundary(schema.minimum
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
const getLowerBoundary = (schema) => selectBoundary(boundary(schema.minimum, false, "lower"), boundary(schema.exclusiveMinimum, true, "lower"), Math.max);
|
|
45
|
+
const getUpperBoundary = (schema) => selectBoundary(boundary(schema.maximum, false, "upper"), boundary(schema.exclusiveMaximum, true, "upper"), Math.min);
|
|
46
|
+
/**
|
|
47
|
+
* Reads one bound, which may be infinite.
|
|
48
|
+
*
|
|
49
|
+
* A type tag built from an overflowing literal (`Maximum<1e400>`) carries an
|
|
50
|
+
* infinite bound (#2452). `-Infinity` below or `Infinity` above excludes no
|
|
51
|
+
* finite number, so it is no bound at all; `Infinity` below or `-Infinity`
|
|
52
|
+
* above excludes every finite number, so no value can be generated.
|
|
53
|
+
*/
|
|
54
|
+
const boundary = (value, exclusive, side) => {
|
|
55
|
+
if (value === undefined)
|
|
56
|
+
return null;
|
|
57
|
+
if (Number.isFinite(value))
|
|
58
|
+
return { value, exclusive };
|
|
59
|
+
if (value === (side === "lower" ? -Infinity : Infinity))
|
|
60
|
+
return null;
|
|
61
|
+
throw new Error("Numeric range has no finite value.");
|
|
62
|
+
};
|
|
54
63
|
const selectBoundary = (x, y, compare) => {
|
|
55
64
|
if (x === null)
|
|
56
65
|
return y;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomNumber.js","sourceRoot":"","sources":["../../src/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ClB,IAAuB,EACL,EAAE;IACpB,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACrC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IACxD,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACrE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;AACxD,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CACrB,CAAmB,EACnB,CAAmB,EACnB,OAAyC,EACvB,EAAE;IACpB,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC;IACzB,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC;IACzB,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK;QACrB,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;IACnE,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC"}
|
|
@@ -30,20 +30,25 @@ const scalar = (props) => {
|
|
|
30
30
|
}
|
|
31
31
|
return value;
|
|
32
32
|
};
|
|
33
|
-
const getLowerBoundary = (schema) => selectBoundary(schema.minimum
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
value
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
const getLowerBoundary = (schema) => selectBoundary(boundary(schema.minimum, false, "lower"), boundary(schema.exclusiveMinimum, true, "lower"), Math.max);
|
|
34
|
+
const getUpperBoundary = (schema) => selectBoundary(boundary(schema.maximum, false, "upper"), boundary(schema.exclusiveMaximum, true, "upper"), Math.min);
|
|
35
|
+
/**
|
|
36
|
+
* Reads one bound, which may be infinite.
|
|
37
|
+
*
|
|
38
|
+
* A type tag built from an overflowing literal (`Maximum<1e400>`) carries an
|
|
39
|
+
* infinite bound (#2452). `-Infinity` below or `Infinity` above excludes no
|
|
40
|
+
* finite number, so it is no bound at all; `Infinity` below or `-Infinity`
|
|
41
|
+
* above excludes every finite number, so no value can be generated.
|
|
42
|
+
*/
|
|
43
|
+
const boundary = (value, exclusive, side) => {
|
|
44
|
+
if (value === void 0) return null;
|
|
45
|
+
if (Number.isFinite(value)) return {
|
|
46
|
+
value,
|
|
47
|
+
exclusive
|
|
48
|
+
};
|
|
49
|
+
if (value === (side === "lower" ? -Infinity : Infinity)) return null;
|
|
50
|
+
throw new Error("Numeric range has no finite value.");
|
|
51
|
+
};
|
|
47
52
|
const selectBoundary = (x, y, compare) => {
|
|
48
53
|
if (x === null) return y;
|
|
49
54
|
if (y === null) return x;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomNumber.mjs","names":[],"sources":["../../src/internal/_randomNumber.ts"],"sourcesContent":["import { OpenApi } from \"@typia/interface\";\n\nimport { _randomMultiple } from \"./_randomMultiple\";\n\nexport const _randomNumber = (schema: OpenApi.IJsonSchema.INumber): number => {\n const lower: IBoundary | null = getLowerBoundary(schema);\n const upper: IBoundary | null = getUpperBoundary(schema);\n const minimum: number =\n lower?.value ?? (upper === null ? 0 : upper.value - 100);\n const maximum: number =\n upper?.value ?? (lower === null ? 100 : lower.value + 100);\n if (minimum > maximum)\n throw new Error(\"Minimum value is greater than maximum value.\");\n return schema.multipleOf === undefined\n ? scalar({\n minimum,\n maximum,\n exclusiveMinimum: lower?.exclusive ?? false,\n exclusiveMaximum: upper?.exclusive ?? false,\n })\n : _randomMultiple({\n minimum,\n maximum,\n multipleOf: schema.multipleOf,\n exclusiveMinimum: lower?.exclusive ?? false,\n exclusiveMaximum: upper?.exclusive ?? false,\n integer: false,\n });\n};\n\nconst scalar = (props: {\n minimum: number;\n maximum: number;\n exclusiveMinimum: boolean;\n exclusiveMaximum: boolean;\n}): number => {\n if (\n props.minimum === props.maximum &&\n (props.exclusiveMinimum || props.exclusiveMaximum)\n )\n throw new Error(\"Exclusive numeric range is empty.\");\n const value: number =\n Math.random() * (props.maximum - props.minimum) + props.minimum;\n if (\n (props.exclusiveMinimum && value === props.minimum) ||\n (props.exclusiveMaximum && value === props.maximum)\n ) {\n const middle: number = props.minimum + (props.maximum - props.minimum) / 2;\n if (middle <= props.minimum || middle >= props.maximum)\n throw new Error(\"Exclusive numeric range has no representable value.\");\n return middle;\n }\n return value;\n};\n\nconst getLowerBoundary = (\n schema: OpenApi.IJsonSchema.INumber,\n): IBoundary | null =>\n selectBoundary(\n schema.minimum
|
|
1
|
+
{"version":3,"file":"_randomNumber.mjs","names":[],"sources":["../../src/internal/_randomNumber.ts"],"sourcesContent":["import { OpenApi } from \"@typia/interface\";\n\nimport { _randomMultiple } from \"./_randomMultiple\";\n\nexport const _randomNumber = (schema: OpenApi.IJsonSchema.INumber): number => {\n const lower: IBoundary | null = getLowerBoundary(schema);\n const upper: IBoundary | null = getUpperBoundary(schema);\n const minimum: number =\n lower?.value ?? (upper === null ? 0 : upper.value - 100);\n const maximum: number =\n upper?.value ?? (lower === null ? 100 : lower.value + 100);\n if (minimum > maximum)\n throw new Error(\"Minimum value is greater than maximum value.\");\n return schema.multipleOf === undefined\n ? scalar({\n minimum,\n maximum,\n exclusiveMinimum: lower?.exclusive ?? false,\n exclusiveMaximum: upper?.exclusive ?? false,\n })\n : _randomMultiple({\n minimum,\n maximum,\n multipleOf: schema.multipleOf,\n exclusiveMinimum: lower?.exclusive ?? false,\n exclusiveMaximum: upper?.exclusive ?? false,\n integer: false,\n });\n};\n\nconst scalar = (props: {\n minimum: number;\n maximum: number;\n exclusiveMinimum: boolean;\n exclusiveMaximum: boolean;\n}): number => {\n if (\n props.minimum === props.maximum &&\n (props.exclusiveMinimum || props.exclusiveMaximum)\n )\n throw new Error(\"Exclusive numeric range is empty.\");\n const value: number =\n Math.random() * (props.maximum - props.minimum) + props.minimum;\n if (\n (props.exclusiveMinimum && value === props.minimum) ||\n (props.exclusiveMaximum && value === props.maximum)\n ) {\n const middle: number = props.minimum + (props.maximum - props.minimum) / 2;\n if (middle <= props.minimum || middle >= props.maximum)\n throw new Error(\"Exclusive numeric range has no representable value.\");\n return middle;\n }\n return value;\n};\n\nconst getLowerBoundary = (\n schema: OpenApi.IJsonSchema.INumber,\n): IBoundary | null =>\n selectBoundary(\n boundary(schema.minimum, false, \"lower\"),\n boundary(schema.exclusiveMinimum, true, \"lower\"),\n Math.max,\n );\n\nconst getUpperBoundary = (\n schema: OpenApi.IJsonSchema.INumber,\n): IBoundary | null =>\n selectBoundary(\n boundary(schema.maximum, false, \"upper\"),\n boundary(schema.exclusiveMaximum, true, \"upper\"),\n Math.min,\n );\n\n/**\n * Reads one bound, which may be infinite.\n *\n * A type tag built from an overflowing literal (`Maximum<1e400>`) carries an\n * infinite bound (#2452). `-Infinity` below or `Infinity` above excludes no\n * finite number, so it is no bound at all; `Infinity` below or `-Infinity`\n * above excludes every finite number, so no value can be generated.\n */\nconst boundary = (\n value: number | undefined,\n exclusive: boolean,\n side: \"lower\" | \"upper\",\n): IBoundary | null => {\n if (value === undefined) return null;\n if (Number.isFinite(value)) return { value, exclusive };\n if (value === (side === \"lower\" ? -Infinity : Infinity)) return null;\n throw new Error(\"Numeric range has no finite value.\");\n};\n\nconst selectBoundary = (\n x: IBoundary | null,\n y: IBoundary | null,\n compare: (x: number, y: number) => number,\n): IBoundary | null => {\n if (x === null) return y;\n if (y === null) return x;\n if (x.value === y.value)\n return { value: x.value, exclusive: x.exclusive || y.exclusive };\n return compare(x.value, y.value) === x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;;;;AAUF,MAAM,YACJ,OACA,WACA,SACqB;CACrB,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,IAAI,OAAO,SAAS,KAAK,GAAG,OAAO;EAAE;EAAO;CAAU;CACtD,IAAI,WAAW,SAAS,UAAU,YAAY,WAAW,OAAO;CAChE,MAAM,IAAI,MAAM,oCAAoC;AACtD;AAEA,MAAM,kBACJ,GACA,GACA,YACqB;CACrB,IAAI,MAAM,MAAM,OAAO;CACvB,IAAI,MAAM,MAAM,OAAO;CACvB,IAAI,EAAE,UAAU,EAAE,OAChB,OAAO;EAAE,OAAO,EAAE;EAAO,WAAW,EAAE,aAAa,EAAE;CAAU;CACjE,OAAO,QAAQ,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,QAAQ,IAAI;AACrD"}
|
|
@@ -29,6 +29,9 @@ func TestLlmEvaluationRejectsInvalidProbability(t *testing.T) {
|
|
|
29
29
|
"- $input.tagUnder\n - LLM evaluation tags.Probability must be in [0, 1], but got -0.1.",
|
|
30
30
|
"- $input.commentText\n - LLM evaluation @probability must be a number in [0, 1], but got \"high\".",
|
|
31
31
|
"- $input.commentEmpty\n - LLM evaluation @probability must be a number in [0, 1], but got \"\".",
|
|
32
|
+
// Go's float syntax reads `0x1p-1` as 0.5, JavaScript's `Number()` does not
|
|
33
|
+
// (samchon/typia#2442).
|
|
34
|
+
"- $input.commentGoFloat\n - LLM evaluation @probability must be a number in [0, 1], but got \"0x1p-1\".",
|
|
32
35
|
"- $input.commentOver\n - LLM evaluation @probability must be in [0, 1], but got 2.",
|
|
33
36
|
"- $input.commentTwice\n - LLM evaluation @probability is declared more than once; keep only one.",
|
|
34
37
|
"- $input.both\n - LLM evaluation boolean has both tags.Probability and @probability; keep only one.",
|
|
@@ -150,6 +153,12 @@ typia.llm.evaluation<{
|
|
|
150
153
|
* @probability
|
|
151
154
|
*/
|
|
152
155
|
commentEmpty: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Go float?
|
|
158
|
+
*
|
|
159
|
+
* @probability 0x1p-1
|
|
160
|
+
*/
|
|
161
|
+
commentGoFloat: boolean;
|
|
153
162
|
/**
|
|
154
163
|
* Over?
|
|
155
164
|
*
|
|
@@ -13,7 +13,8 @@ import (
|
|
|
13
13
|
// with a positive `MinItems` constraint is unsatisfiable. The build command must
|
|
14
14
|
// report a real transform diagnostic across direct aliases, type aliases, graph
|
|
15
15
|
// cycles, map-key and map-value graph cycles, nested direct aliases, and
|
|
16
|
-
// tuple-union nesting for both immediate and factory random entrypoints
|
|
16
|
+
// tuple-union nesting for both immediate and factory random entrypoints, and
|
|
17
|
+
// for the `@minItems` comment-tag spelling.
|
|
17
18
|
//
|
|
18
19
|
// 1. Build a recursive object whose child array has `MinItems<1>`.
|
|
19
20
|
// 2. Build a direct recursive array alias with `MinItems<1>`.
|
|
@@ -25,6 +26,7 @@ func TestRandomRecursiveMinItemsDiagnostic(t *testing.T) {
|
|
|
25
26
|
source string
|
|
26
27
|
}{
|
|
27
28
|
{"object-child", randomRecursiveMinItemsObjectSource},
|
|
29
|
+
{"comment-tag", randomRecursiveMinItemsCommentTagSource},
|
|
28
30
|
{"property-alias", randomRecursiveMinItemsPropertyAliasSource},
|
|
29
31
|
{"mutual-graph", randomRecursiveMinItemsGraphSource},
|
|
30
32
|
{"map-key-graph", randomRecursiveMinItemsMapKeyGraphSource},
|
|
@@ -121,6 +123,21 @@ typia.random<INode>();
|
|
|
121
123
|
typia.createRandom<INode>();
|
|
122
124
|
`
|
|
123
125
|
|
|
126
|
+
// The JSDoc spelling of the same constraint must fail the same way. Its count
|
|
127
|
+
// used to be stored as a pointer the positivity check could not read, so the
|
|
128
|
+
// comment tag silently let the unsatisfiable type through.
|
|
129
|
+
const randomRecursiveMinItemsCommentTagSource = `import typia from "typia";
|
|
130
|
+
|
|
131
|
+
interface INode {
|
|
132
|
+
value: string;
|
|
133
|
+
/** @minItems 1 */
|
|
134
|
+
children: INode[];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
typia.random<INode>();
|
|
138
|
+
typia.createRandom<INode>();
|
|
139
|
+
`
|
|
140
|
+
|
|
124
141
|
const randomRecursiveMinItemsPropertyAliasSource = `import typia, { tags } from "typia";
|
|
125
142
|
|
|
126
143
|
type Children = INode[] & tags.MinItems<1>;
|
|
@@ -57,7 +57,22 @@ var expressionFactory_factory = shimast.NewNodeFactory(shimast.NodeFactoryHooks{
|
|
|
57
57
|
func (expressionFactoryNamespace) Number(value any, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
58
58
|
f := nativecontext.EmitFactoryOf(expressionFactory_factory, emit...)
|
|
59
59
|
text, numeric := expressionFactory_number_text(value)
|
|
60
|
-
|
|
60
|
+
// Go spells the non-finite floats `NaN`, `+Inf`, and `-Inf`. Only the first
|
|
61
|
+
// happens to be JavaScript; `+Inf` evaluates an undeclared `Inf` and throws a
|
|
62
|
+
// ReferenceError when the emitted function first runs (samchon/typia#2452).
|
|
63
|
+
// Spell them as the globals, as TypeScript's own factory does.
|
|
64
|
+
if math.IsNaN(numeric) {
|
|
65
|
+
return f.NewIdentifier("NaN")
|
|
66
|
+
}
|
|
67
|
+
if math.IsInf(numeric, 0) {
|
|
68
|
+
if numeric < 0 {
|
|
69
|
+
return f.NewPrefixUnaryExpression(shimast.KindMinusToken, f.NewIdentifier("Infinity"))
|
|
70
|
+
}
|
|
71
|
+
return f.NewIdentifier("Infinity")
|
|
72
|
+
}
|
|
73
|
+
// Negative zero takes the same negation as every negative value; its text
|
|
74
|
+
// `-0` is not a numeric literal on its own.
|
|
75
|
+
if numeric < 0 || (numeric == 0 && math.Signbit(numeric)) {
|
|
61
76
|
return f.NewPrefixUnaryExpression(
|
|
62
77
|
shimast.KindMinusToken,
|
|
63
78
|
f.NewNumericLiteral(expressionFactory_number_abs_text(numeric), shimast.TokenFlagsNone),
|