typia 14.0.6 → 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/README.md +3 -0
- package/lib/http.d.ts +49 -24
- package/lib/http.js.map +1 -1
- package/lib/http.mjs.map +1 -1
- package/lib/internal/_createLlmEvaluation.d.ts +1 -0
- package/lib/internal/_createLlmEvaluation.js +486 -0
- package/lib/internal/_createLlmEvaluation.js.map +1 -0
- package/lib/internal/_createLlmEvaluation.mjs +382 -0
- package/lib/internal/_createLlmEvaluation.mjs.map +1 -0
- 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/lib/internal/_stringLengthGte.d.ts +1 -0
- package/lib/internal/_stringLengthGte.js +14 -0
- package/lib/internal/_stringLengthGte.js.map +1 -0
- package/lib/internal/_stringLengthGte.mjs +11 -0
- package/lib/internal/_stringLengthGte.mjs.map +1 -0
- package/lib/internal/_stringLengthLte.d.ts +1 -0
- package/lib/internal/_stringLengthLte.js +14 -0
- package/lib/internal/_stringLengthLte.js.map +1 -0
- package/lib/internal/_stringLengthLte.mjs +11 -0
- package/lib/internal/_stringLengthLte.mjs.map +1 -0
- package/lib/llm.d.ts +54 -1
- package/lib/llm.js +5 -0
- package/lib/llm.js.map +1 -1
- package/lib/llm.mjs +6 -1
- package/lib/llm.mjs.map +1 -1
- package/lib/re-exports.d.ts +1 -1
- package/lib/re-exports.js.map +1 -1
- package/native/cmd/ttsc-typia/build.go +2 -0
- package/native/cmd/ttsc-typia/dynamic_key_tags_transform_test.go +1 -1
- package/native/cmd/ttsc-typia/llm_evaluation_accepts_property_probability_test.go +27 -0
- package/native/cmd/ttsc-typia/llm_evaluation_accepts_unselected_source_probability_test.go +26 -0
- package/native/cmd/ttsc-typia/llm_evaluation_complete_object_shape_test.go +96 -0
- package/native/cmd/ttsc-typia/llm_evaluation_ignores_declaration_probability_without_call_test.go +18 -0
- package/native/cmd/ttsc-typia/llm_evaluation_plan_emission_transform_test.go +90 -0
- package/native/cmd/ttsc-typia/llm_evaluation_program_scan_dependencies_test.go +69 -0
- package/native/cmd/ttsc-typia/llm_evaluation_rejects_alias_comment_test.go +44 -0
- package/native/cmd/ttsc-typia/llm_evaluation_rejects_alias_refinement_test.go +45 -0
- package/native/cmd/ttsc-typia/llm_evaluation_rejects_computed_method_probability_test.go +30 -0
- package/native/cmd/ttsc-typia/llm_evaluation_rejects_imported_declaration_probability_test.go +48 -0
- package/native/cmd/ttsc-typia/llm_evaluation_rejects_invalid_probability_test.go +208 -0
- package/native/cmd/ttsc-typia/llm_evaluation_rejects_refinements_test.go +94 -0
- package/native/cmd/ttsc-typia/llm_evaluation_rejects_undecidable_types_test.go +232 -0
- package/native/cmd/ttsc-typia/metadata_type_tag_sole_malformed_diagnostic_test.go +94 -0
- package/native/cmd/ttsc-typia/random_recursive_min_items_diagnostic_test.go +18 -1
- package/native/cmd/ttsc-typia/template_literal_type_tags_transform_test.go +3 -2
- package/native/cmd/ttsc-typia/transform.go +2 -0
- package/native/cmd/ttsc-typia/transform_helpers_test.go +17 -3
- package/native/core/context/ITypiaContext.go +4 -0
- package/native/core/factories/ExpressionFactory.go +16 -1
- package/native/core/factories/IdentifierFactory.go +10 -0
- package/native/core/factories/LiteralFactory.go +16 -0
- package/native/core/factories/MetadataCommentTagFactory.go +185 -35
- package/native/core/factories/MetadataTypeTagFactory.go +97 -24
- package/native/core/factories/MetadataTypeTagSchemaFactory.go +5 -0
- package/native/core/factories/expression_factory_number_spells_non_finite_values_test.go +69 -0
- package/native/core/factories/internal/metadata/IMetadataIteratorProps.go +6 -2
- package/native/core/factories/internal/metadata/emplace_metadata_object.go +49 -15
- package/native/core/factories/literal_factory_null_survives_objects_test.go +43 -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/factories/metadata_comment_tag_factory_string_length_helpers_test.go +55 -0
- package/native/core/factories/metadata_type_tag_factory_reports_all_invalid_candidates_test.go +73 -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/LlmApplicationProgrammer.go +1 -0
- package/native/core/programmers/llm/LlmEvaluationProgrammer.go +559 -0
- package/native/core/programmers/llm/LlmParametersProgrammer.go +6 -5
- package/native/core/programmers/llm/LlmReferenceDescription.go +113 -0
- package/native/core/programmers/llm/LlmSchemaProgrammer.go +34 -4
- package/native/core/programmers/llm/llm_reference_description_test.go +134 -0
- package/native/core/schemas/metadata/MetadataDependency.go +9 -0
- 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/native/transform/CallExpressionTransformer.go +1 -0
- package/native/transform/FileTransformer.go +5 -0
- package/native/transform/features/llm/LlmEvaluationProbabilityDeclarations.go +94 -0
- package/native/transform/features/llm/LlmEvaluationProbabilityDeclarations_test.go +50 -0
- package/native/transform/features/llm/LlmEvaluationTransformer.go +59 -0
- package/native/transform/features/llm/LlmSchemaTransformer.go +14 -11
- package/native/transform/features/llm/llm_transformer_entry_coverage_test.go +29 -27
- package/package.json +3 -3
- package/src/http.ts +61 -34
- package/src/internal/_createLlmEvaluation.ts +678 -0
- 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
- package/src/internal/_stringLengthGte.ts +6 -0
- package/src/internal/_stringLengthLte.ts +6 -0
- package/src/llm.ts +64 -0
- package/src/re-exports.ts +1 -0
|
@@ -30,6 +30,14 @@ type HttpQueryProgrammer_DecomposeProps struct {
|
|
|
30
30
|
AllowOptional bool
|
|
31
31
|
Type *shimchecker.Type
|
|
32
32
|
Name *string
|
|
33
|
+
|
|
34
|
+
// Missing makes the decoder throw `Error("missing <key>")` for an absent
|
|
35
|
+
// required non-array property. Only `http.query`, which validates nothing
|
|
36
|
+
// else, asks for it. The `is`, `assert`, and `validate` variants decode
|
|
37
|
+
// through this same function and must report the absence through their own
|
|
38
|
+
// contract instead (`null`, an `IValidation` failure, `TypeGuardError`), so
|
|
39
|
+
// they leave it off (samchon/typia#2444).
|
|
40
|
+
Missing bool
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
var httpQueryProgrammer_factory = shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
|
|
@@ -78,9 +86,11 @@ func (httpQueryProgrammerNamespace) Decompose(props HttpQueryProgrammer_Decompos
|
|
|
78
86
|
statements := httpQueryProgrammer_decode_object(struct {
|
|
79
87
|
Context nativecontext.ITypiaContext
|
|
80
88
|
Object *schemametadata.MetadataObjectType
|
|
89
|
+
Missing bool
|
|
81
90
|
}{
|
|
82
91
|
Context: props.Context,
|
|
83
92
|
Object: object,
|
|
93
|
+
Missing: props.Missing,
|
|
84
94
|
})
|
|
85
95
|
return nativeinternal.FeatureProgrammer_IDecomposed{
|
|
86
96
|
Functions: map[string]*shimast.Node{},
|
|
@@ -124,6 +134,7 @@ func (httpQueryProgrammerNamespace) Write(props HttpQueryProgrammer_IProps) *shi
|
|
|
124
134
|
AllowOptional: props.AllowOptional,
|
|
125
135
|
Type: props.Type,
|
|
126
136
|
Name: props.Name,
|
|
137
|
+
Missing: true,
|
|
127
138
|
})
|
|
128
139
|
return nativeinternal.FeatureProgrammer.WriteDecomposed(nativeinternal.FeatureProgrammer_WriteDecomposedProps{
|
|
129
140
|
Modulo: props.Modulo,
|
|
@@ -203,6 +214,7 @@ func (httpQueryProgrammerNamespace) Validate(props struct {
|
|
|
203
214
|
func httpQueryProgrammer_decode_object(props struct {
|
|
204
215
|
Context nativecontext.ITypiaContext
|
|
205
216
|
Object *schemametadata.MetadataObjectType
|
|
217
|
+
Missing bool
|
|
206
218
|
}) []*shimast.Node {
|
|
207
219
|
f := nativecontext.EmitFactoryOf(httpQueryProgrammer_factory, props.Context.Emit)
|
|
208
220
|
input := f.NewIdentifier("input")
|
|
@@ -212,9 +224,11 @@ func httpQueryProgrammer_decode_object(props struct {
|
|
|
212
224
|
properties = append(properties, httpQueryProgrammer_decode_regular_property(struct {
|
|
213
225
|
Context nativecontext.ITypiaContext
|
|
214
226
|
Property *schemametadata.MetadataProperty
|
|
227
|
+
Missing bool
|
|
215
228
|
}{
|
|
216
229
|
Context: props.Context,
|
|
217
230
|
Property: p,
|
|
231
|
+
Missing: props.Missing,
|
|
218
232
|
}))
|
|
219
233
|
}
|
|
220
234
|
return []*shimast.Node{
|
|
@@ -253,6 +267,7 @@ func httpQueryProgrammer_decode_object(props struct {
|
|
|
253
267
|
func httpQueryProgrammer_decode_regular_property(props struct {
|
|
254
268
|
Context nativecontext.ITypiaContext
|
|
255
269
|
Property *schemametadata.MetadataProperty
|
|
270
|
+
Missing bool
|
|
256
271
|
}) *shimast.Node {
|
|
257
272
|
f := nativecontext.EmitFactoryOf(httpQueryProgrammer_factory, props.Context.Emit)
|
|
258
273
|
key := httpProgrammer_property_key(props.Property)
|
|
@@ -277,9 +292,9 @@ func httpQueryProgrammer_decode_regular_property(props struct {
|
|
|
277
292
|
}),
|
|
278
293
|
shimast.NodeFlagsNone,
|
|
279
294
|
)
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
295
|
+
// An absent key reads as an empty list. A query string has no other
|
|
296
|
+
// spelling for `[]`, so a required array decodes it as `[]` rather than as
|
|
297
|
+
// a missing property, and a nullable one as `null` (samchon/typia#2444).
|
|
283
298
|
input = f.NewCallExpression(
|
|
284
299
|
nativefactories.IdentifierFactory.Access(
|
|
285
300
|
props.Context.Emit,
|
|
@@ -301,11 +316,13 @@ func httpQueryProgrammer_decode_regular_property(props struct {
|
|
|
301
316
|
httpQueryProgrammer_decode_value(struct {
|
|
302
317
|
Context nativecontext.ITypiaContext
|
|
303
318
|
Type string
|
|
319
|
+
Nullable bool
|
|
304
320
|
Coalesce bool
|
|
305
321
|
Input *shimast.Node
|
|
306
322
|
}{
|
|
307
323
|
Context: props.Context,
|
|
308
324
|
Type: typ,
|
|
325
|
+
Nullable: httpProgrammer_decode_nullable(value),
|
|
309
326
|
Coalesce: false,
|
|
310
327
|
Input: f.NewIdentifier("elem"),
|
|
311
328
|
}),
|
|
@@ -323,18 +340,20 @@ func httpQueryProgrammer_decode_regular_property(props struct {
|
|
|
323
340
|
Input: input,
|
|
324
341
|
})
|
|
325
342
|
} else {
|
|
326
|
-
if value.IsRequired() {
|
|
343
|
+
if value.IsRequired() && props.Missing {
|
|
327
344
|
input = httpQueryProgrammer_assert_required_value(key, input, props.Context.Emit)
|
|
328
345
|
}
|
|
329
346
|
input = httpQueryProgrammer_decode_value(struct {
|
|
330
347
|
Context nativecontext.ITypiaContext
|
|
331
348
|
Type string
|
|
349
|
+
Nullable bool
|
|
332
350
|
Coalesce bool
|
|
333
351
|
Input *shimast.Node
|
|
334
352
|
}{
|
|
335
353
|
Context: props.Context,
|
|
336
354
|
Type: typ,
|
|
337
|
-
|
|
355
|
+
Nullable: httpProgrammer_decode_nullable(value),
|
|
356
|
+
Coalesce: value.Nullable == false && value.Any == false && value.IsRequired() == false,
|
|
338
357
|
Input: input,
|
|
339
358
|
})
|
|
340
359
|
}
|
|
@@ -350,6 +369,7 @@ func httpQueryProgrammer_decode_regular_property(props struct {
|
|
|
350
369
|
func httpQueryProgrammer_decode_value(props struct {
|
|
351
370
|
Context nativecontext.ITypiaContext
|
|
352
371
|
Type string
|
|
372
|
+
Nullable bool
|
|
353
373
|
Coalesce bool
|
|
354
374
|
Input *shimast.Node
|
|
355
375
|
}) *shimast.Node {
|
|
@@ -358,7 +378,7 @@ func httpQueryProgrammer_decode_value(props struct {
|
|
|
358
378
|
httpParameterProgrammer_internal(props.Context, "httpQueryRead"+httpParameterProgrammer_capitalize(props.Type)),
|
|
359
379
|
nil,
|
|
360
380
|
nil,
|
|
361
|
-
f.NewNodeList(
|
|
381
|
+
f.NewNodeList(httpProgrammer_read_arguments(props.Type, props.Nullable, props.Input, props.Context.Emit)),
|
|
362
382
|
shimast.NodeFlagsNone,
|
|
363
383
|
)
|
|
364
384
|
if props.Coalesce == false {
|
|
@@ -410,43 +430,6 @@ func httpQueryProgrammer_assert_required_value(key string, input *shimast.Node,
|
|
|
410
430
|
)
|
|
411
431
|
}
|
|
412
432
|
|
|
413
|
-
func httpQueryProgrammer_assert_required_array(key string, input *shimast.Node, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
414
|
-
f := nativecontext.EmitFactoryOf(httpQueryProgrammer_factory, emit...)
|
|
415
|
-
value := f.NewIdentifier("value")
|
|
416
|
-
return f.NewCallExpression(
|
|
417
|
-
f.NewArrowFunction(
|
|
418
|
-
nil,
|
|
419
|
-
nil,
|
|
420
|
-
f.NewNodeList(nil),
|
|
421
|
-
nil,
|
|
422
|
-
nil,
|
|
423
|
-
f.NewToken(shimast.KindEqualsGreaterThanToken),
|
|
424
|
-
f.NewBlock(f.NewNodeList([]*shimast.Node{
|
|
425
|
-
nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
|
|
426
|
-
Name: "value",
|
|
427
|
-
Value: input,
|
|
428
|
-
}, emit...),
|
|
429
|
-
f.NewIfStatement(
|
|
430
|
-
f.NewBinaryExpression(
|
|
431
|
-
nil,
|
|
432
|
-
nativefactories.ExpressionFactory.Number(0, emit...),
|
|
433
|
-
nil,
|
|
434
|
-
f.NewToken(shimast.KindEqualsEqualsEqualsToken),
|
|
435
|
-
nativefactories.IdentifierFactory.Access(nil, value, "length"),
|
|
436
|
-
),
|
|
437
|
-
f.NewThrowStatement(httpQueryProgrammer_missing_error(key, emit...)),
|
|
438
|
-
nil,
|
|
439
|
-
),
|
|
440
|
-
f.NewReturnStatement(value),
|
|
441
|
-
}), true),
|
|
442
|
-
),
|
|
443
|
-
nil,
|
|
444
|
-
nil,
|
|
445
|
-
nil,
|
|
446
|
-
shimast.NodeFlagsNone,
|
|
447
|
-
)
|
|
448
|
-
}
|
|
449
|
-
|
|
450
433
|
func httpQueryProgrammer_missing_error(key string, emit ...*shimprinter.EmitContext) *shimast.Node {
|
|
451
434
|
f := nativecontext.EmitFactoryOf(httpQueryProgrammer_factory, emit...)
|
|
452
435
|
return f.NewNewExpression(
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
package iterate
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
"strconv"
|
|
5
4
|
"strings"
|
|
6
5
|
|
|
7
6
|
nativemetadata "github.com/samchon/typia/packages/typia/native/core/schemas/metadata"
|
|
7
|
+
nativeutils "github.com/samchon/typia/packages/typia/native/core/utils"
|
|
8
8
|
)
|
|
9
9
|
|
|
10
10
|
func json_schema_jsDocTags(schema JsonSchema, jsDocTags []nativemetadata.IJsDocTagInfo) JsonSchema {
|
|
@@ -31,6 +31,13 @@ func json_schema_jsDocTags_value(tag nativemetadata.IJsDocTagInfo) (string, bool
|
|
|
31
31
|
return "", false
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
// json_schema_jsDocTags_cast reads an `@x-*` tag's text as a JSON value.
|
|
35
|
+
//
|
|
36
|
+
// Numbers use JavaScript's `Number()` grammar, the grammar of the v12 cast this
|
|
37
|
+
// ports (samchon/typia#2442), so `0x10` is 16 while Go-only spellings such as
|
|
38
|
+
// `0x1p4`, `1_000`, and `inf` stay text. Only finite numbers become numbers: the
|
|
39
|
+
// schema is JSON, which has no NaN or infinity, so `NaN`, `Infinity`, and an
|
|
40
|
+
// overflowing `1e400` keep their text instead of degrading to `null`.
|
|
34
41
|
func json_schema_jsDocTags_cast(value string) any {
|
|
35
42
|
if value == "true" {
|
|
36
43
|
return true
|
|
@@ -38,8 +45,8 @@ func json_schema_jsDocTags_cast(value string) any {
|
|
|
38
45
|
if value == "false" {
|
|
39
46
|
return false
|
|
40
47
|
}
|
|
41
|
-
if
|
|
42
|
-
return
|
|
48
|
+
if reading := nativeutils.NumberUtil.Read(value); reading.Numeric && reading.Finite {
|
|
49
|
+
return reading.Value
|
|
43
50
|
}
|
|
44
51
|
if value == "null" {
|
|
45
52
|
return nil
|
package/native/core/programmers/iterate/json_schema_jsdoc_tags_cast_reads_javascript_numbers_test.go
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
package iterate
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"encoding/json"
|
|
5
|
+
"math"
|
|
6
|
+
"reflect"
|
|
7
|
+
"testing"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
// TestJsonSchemaJsDocTagsCastReadsJavaScriptNumbers verifies the `@x-*`
|
|
11
|
+
// extension cast.
|
|
12
|
+
//
|
|
13
|
+
// The Go port swapped the v12 cast's JavaScript `Number()` grammar for Go's
|
|
14
|
+
// float syntax (samchon/typia#2442). `NaN` and every `Inf` spelling then became
|
|
15
|
+
// floats that `encoding/json` refuses and JavaScript prints as `null`, while
|
|
16
|
+
// `0x10` stopped being a number and `0x1p4` / `1_000` started being one. The
|
|
17
|
+
// expectations restore v12's numbers where they are finite and keep the text
|
|
18
|
+
// where JSON has no number: a non-finite spelling stays a string instead of
|
|
19
|
+
// degrading to `null`, and empty text stays `""` instead of v12's `0`.
|
|
20
|
+
//
|
|
21
|
+
// 1. Cast every row of the issue's table.
|
|
22
|
+
// 2. Assert no result is NaN or an infinity, and every result marshals.
|
|
23
|
+
func TestJsonSchemaJsDocTagsCastReadsJavaScriptNumbers(t *testing.T) {
|
|
24
|
+
for _, item := range []struct {
|
|
25
|
+
text string
|
|
26
|
+
expected any
|
|
27
|
+
}{
|
|
28
|
+
{"NaN", "NaN"},
|
|
29
|
+
{"nan", "nan"},
|
|
30
|
+
{"Infinity", "Infinity"},
|
|
31
|
+
{"-Infinity", "-Infinity"},
|
|
32
|
+
{"infinity", "infinity"},
|
|
33
|
+
{"inf", "inf"},
|
|
34
|
+
{"Inf", "Inf"},
|
|
35
|
+
{"1e400", "1e400"},
|
|
36
|
+
{"0x10", float64(16)},
|
|
37
|
+
{"0b101", float64(5)},
|
|
38
|
+
{"0o7", float64(7)},
|
|
39
|
+
{"0x1p4", "0x1p4"},
|
|
40
|
+
{"1_000", "1_000"},
|
|
41
|
+
{"", ""},
|
|
42
|
+
{"-0", float64(0)},
|
|
43
|
+
{"+5", float64(5)},
|
|
44
|
+
{".5", 0.5},
|
|
45
|
+
{"1e3", float64(1000)},
|
|
46
|
+
{"true", true},
|
|
47
|
+
{"false", false},
|
|
48
|
+
{"null", nil},
|
|
49
|
+
{"text", "text"},
|
|
50
|
+
} {
|
|
51
|
+
actual := json_schema_jsDocTags_cast(item.text)
|
|
52
|
+
if reflect.DeepEqual(actual, item.expected) == false {
|
|
53
|
+
t.Fatalf("cast(%q) = %#v, expected %#v", item.text, actual, item.expected)
|
|
54
|
+
}
|
|
55
|
+
if number, ok := actual.(float64); ok {
|
|
56
|
+
if math.IsNaN(number) || math.IsInf(number, 0) || math.Signbit(number) && number == 0 {
|
|
57
|
+
t.Fatalf("cast(%q) = %v is not a JSON number", item.text, number)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if _, err := json.Marshal(actual); err != nil {
|
|
61
|
+
t.Fatalf("cast(%q) does not marshal: %v", item.text, err)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -401,6 +401,7 @@ func llmApplicationProgrammer_convertParameters(
|
|
|
401
401
|
output := llmSchemaProgrammer_convert_schema_config(target, components, defs, config)
|
|
402
402
|
output["additionalProperties"] = false
|
|
403
403
|
output["$defs"] = defs
|
|
404
|
+
llmReferenceDescription_assign(output, schema, components)
|
|
404
405
|
return output
|
|
405
406
|
}
|
|
406
407
|
|