typia 13.1.19 → 13.3.0
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/executable/FileSystemIdentity.d.ts +23 -0
- package/lib/executable/FileSystemIdentity.js +30 -0
- package/lib/executable/FileSystemIdentity.js.map +1 -1
- package/lib/executable/FileSystemIdentity.mjs +4 -0
- package/lib/executable/FileSystemIdentity.mjs.map +1 -1
- package/lib/executable/TypiaGenerateWizard.js +15 -9
- package/lib/executable/TypiaGenerateWizard.js.map +1 -1
- package/lib/executable/TypiaGenerateWizard.mjs +11 -7
- package/lib/executable/TypiaGenerateWizard.mjs.map +1 -1
- package/lib/http.d.ts +3 -3
- package/lib/http.js.map +1 -1
- package/lib/http.mjs.map +1 -1
- package/lib/internal/_ProtobufReader.d.ts +18 -3
- package/lib/internal/_ProtobufReader.js +39 -11
- package/lib/internal/_ProtobufReader.js.map +1 -1
- package/lib/internal/_ProtobufReader.mjs +37 -10
- package/lib/internal/_ProtobufReader.mjs.map +1 -1
- package/lib/internal/_assertGuard.js +13 -3
- package/lib/internal/_assertGuard.js.map +1 -1
- package/lib/internal/_assertGuard.mjs +4 -2
- package/lib/internal/_assertGuard.mjs.map +1 -1
- package/lib/internal/_isFormatIdnHostname.js +5 -1
- package/lib/internal/_isFormatIdnHostname.js.map +1 -1
- package/lib/internal/_isFormatIdnHostname.mjs +1 -1
- package/lib/internal/_isFormatIdnHostname.mjs.map +1 -1
- package/lib/internal/_isFormatTime.js +19 -2
- package/lib/internal/_isFormatTime.js.map +1 -1
- package/lib/internal/_isFormatTime.mjs +9 -2
- package/lib/internal/_isFormatTime.mjs.map +1 -1
- package/lib/internal/_jsonStringifyArray.d.ts +1 -0
- package/lib/internal/_jsonStringifyArray.js +48 -0
- package/lib/internal/_jsonStringifyArray.js.map +1 -0
- package/lib/internal/_jsonStringifyArray.mjs +40 -0
- package/lib/internal/_jsonStringifyArray.mjs.map +1 -0
- package/lib/internal/_jsonStringifyElement.d.ts +1 -0
- package/lib/internal/_jsonStringifyElement.js +23 -0
- package/lib/internal/_jsonStringifyElement.js.map +1 -0
- package/lib/internal/_jsonStringifyElement.mjs +23 -0
- package/lib/internal/_jsonStringifyElement.mjs.map +1 -0
- package/lib/internal/_jsonStringifyProperty.d.ts +1 -0
- package/lib/internal/_jsonStringifyProperty.js +31 -0
- package/lib/internal/_jsonStringifyProperty.js.map +1 -0
- package/lib/internal/_jsonStringifyProperty.mjs +31 -0
- package/lib/internal/_jsonStringifyProperty.mjs.map +1 -0
- package/lib/internal/_llmApplicationFinalize.js +1 -1
- package/lib/internal/_llmApplicationFinalize.js.map +1 -1
- package/lib/internal/_llmApplicationFinalize.mjs +1 -1
- package/lib/internal/_llmApplicationFinalize.mjs.map +1 -1
- package/lib/internal/_randomArray.js +37 -4
- package/lib/internal/_randomArray.js.map +1 -1
- package/lib/internal/_randomArray.mjs +16 -3
- package/lib/internal/_randomArray.mjs.map +1 -1
- package/lib/internal/_randomFormatByte.js +28 -2
- package/lib/internal/_randomFormatByte.js.map +1 -1
- package/lib/internal/_randomFormatByte.mjs +22 -3
- package/lib/internal/_randomFormatByte.mjs.map +1 -1
- package/lib/internal/_randomFormatDate.d.ts +3 -6
- package/lib/internal/_randomFormatDate.js +2 -10
- package/lib/internal/_randomFormatDate.js.map +1 -1
- package/lib/internal/_randomFormatDate.mjs +2 -6
- package/lib/internal/_randomFormatDate.mjs.map +1 -1
- package/lib/internal/_randomFormatDatetime.d.ts +3 -6
- package/lib/internal/_randomFormatDatetime.js +25 -8
- package/lib/internal/_randomFormatDatetime.js.map +1 -1
- package/lib/internal/_randomFormatDatetime.mjs +17 -7
- package/lib/internal/_randomFormatDatetime.mjs.map +1 -1
- package/lib/internal/_randomFormatDuration.js +23 -15
- package/lib/internal/_randomFormatDuration.js.map +1 -1
- package/lib/internal/_randomFormatDuration.mjs +23 -15
- package/lib/internal/_randomFormatDuration.mjs.map +1 -1
- package/lib/internal/_randomFormatHostname.d.ts +2 -2
- package/lib/internal/_randomFormatHostname.js +2 -2
- package/lib/internal/_randomFormatHostname.mjs +2 -2
- package/lib/internal/_randomFormatHostname.mjs.map +1 -1
- package/lib/internal/_randomFormatIdnHostname.js +9 -10
- package/lib/internal/_randomFormatIdnHostname.js.map +1 -1
- package/lib/internal/_randomFormatIdnHostname.mjs +3 -4
- package/lib/internal/_randomFormatIdnHostname.mjs.map +1 -1
- package/lib/internal/_randomFormatIpv4.js +31 -1
- package/lib/internal/_randomFormatIpv4.js.map +1 -1
- package/lib/internal/_randomFormatIpv4.mjs +23 -2
- package/lib/internal/_randomFormatIpv4.mjs.map +1 -1
- package/lib/internal/_randomFormatIpv6.js +57 -1
- package/lib/internal/_randomFormatIpv6.js.map +1 -1
- package/lib/internal/_randomFormatIpv6.mjs +45 -2
- package/lib/internal/_randomFormatIpv6.mjs.map +1 -1
- package/lib/internal/_randomFormatJsonPointer.js +14 -2
- package/lib/internal/_randomFormatJsonPointer.js.map +1 -1
- package/lib/internal/_randomFormatJsonPointer.mjs +13 -3
- package/lib/internal/_randomFormatJsonPointer.mjs.map +1 -1
- package/lib/internal/_randomFormatRegex.js +15 -2
- package/lib/internal/_randomFormatRegex.js.map +1 -1
- package/lib/internal/_randomFormatRegex.mjs +14 -3
- package/lib/internal/_randomFormatRegex.mjs.map +1 -1
- package/lib/internal/_randomFormatRelativeJsonPointer.js +19 -5
- package/lib/internal/_randomFormatRelativeJsonPointer.js.map +1 -1
- package/lib/internal/_randomFormatRelativeJsonPointer.mjs +21 -6
- package/lib/internal/_randomFormatRelativeJsonPointer.mjs.map +1 -1
- package/lib/internal/_randomFormatTime.js +38 -7
- package/lib/internal/_randomFormatTime.js.map +1 -1
- package/lib/internal/_randomFormatTime.mjs +40 -5
- package/lib/internal/_randomFormatTime.mjs.map +1 -1
- package/lib/internal/_randomPattern.js.map +1 -1
- package/lib/internal/_randomPattern.mjs.map +1 -1
- package/lib/internal/_randomStringLength.d.ts +41 -10
- package/lib/internal/_randomStringLength.js +49 -13
- package/lib/internal/_randomStringLength.js.map +1 -1
- package/lib/internal/_randomStringLength.mjs +48 -13
- package/lib/internal/_randomStringLength.mjs.map +1 -1
- package/lib/internal/private/__notationRename.js.map +1 -1
- package/lib/internal/private/__notationRename.mjs.map +1 -1
- package/lib/internal/private/__randomComposition.d.ts +31 -0
- package/lib/internal/private/__randomComposition.js +68 -0
- package/lib/internal/private/__randomComposition.js.map +1 -0
- package/lib/internal/private/__randomComposition.mjs +71 -0
- package/lib/internal/private/__randomComposition.mjs.map +1 -0
- package/lib/internal/private/__randomEpoch.d.ts +19 -0
- package/lib/internal/private/__randomEpoch.js +31 -0
- package/lib/internal/private/__randomEpoch.js.map +1 -0
- package/lib/internal/private/__randomEpoch.mjs +28 -0
- package/lib/internal/private/__randomEpoch.mjs.map +1 -0
- package/lib/json.d.ts +2 -2
- package/lib/json.js.map +1 -1
- package/lib/json.mjs.map +1 -1
- package/lib/module.d.ts +28 -13
- package/lib/module.js.map +1 -1
- package/lib/module.mjs.map +1 -1
- package/lib/notations.d.ts +4 -4
- package/lib/notations.js.map +1 -1
- package/lib/notations.mjs.map +1 -1
- package/lib/plain.d.ts +3 -3
- package/lib/plain.js.map +1 -1
- package/lib/plain.mjs.map +1 -1
- package/lib/protobuf.d.ts +2 -2
- package/lib/protobuf.js.map +1 -1
- package/lib/protobuf.mjs.map +1 -1
- package/native/cmd/ttsc-typia/assert_guard_factory_contract_test.go +17 -4
- package/native/cmd/ttsc-typia/build.go +3 -0
- package/native/cmd/ttsc-typia/callable_interface_function_semantics_transform_test.go +331 -0
- package/native/cmd/ttsc-typia/callable_type_literal_boundaries_transform_test.go +1184 -0
- package/native/cmd/ttsc-typia/compare_functional_union_membership_transform_test.go +434 -0
- package/native/cmd/ttsc-typia/compare_template_literal_union_transform_test.go +241 -0
- package/native/cmd/ttsc-typia/create_assert_error_factory_arity_test.go +309 -0
- package/native/cmd/ttsc-typia/default_library_spoof_native_identity_transform_test.go +216 -0
- package/native/cmd/ttsc-typia/json_schema_dynamic_key_determinism_transform_test.go +246 -0
- package/native/cmd/ttsc-typia/json_stringify_contextual_undefined_transform_test.go +556 -0
- package/native/cmd/ttsc-typia/lib_replacement_native_identity_transform_test.go +277 -0
- package/native/cmd/ttsc-typia/local_function_named_like_typia_operation_transform_test.go +185 -0
- package/native/cmd/ttsc-typia/native_named_intersection_union_transform_test.go +390 -0
- package/native/cmd/ttsc-typia/node_buffer_native_exports_is_transform_test.go +526 -0
- package/native/cmd/ttsc-typia/package_declaration_native_identity_is_transform_test.go +293 -0
- package/native/cmd/ttsc-typia/protobuf_diagnostic_code_transform_test.go +167 -0
- package/native/cmd/ttsc-typia/recursive_conditional_alias_name_transform_test.go +307 -0
- package/native/cmd/ttsc-typia/shadowed_typia_module_declaration_diagnostic_test.go +152 -0
- package/native/cmd/ttsc-typia/symbol_index_domain_transform_test.go +316 -0
- package/native/cmd/ttsc-typia/template_literal_type_tags_transform_test.go +1 -3
- package/native/cmd/ttsc-typia/transform.go +23 -0
- package/native/cmd/ttsc-typia/transform_helpers_test.go +166 -25
- package/native/cmd/ttsc-typia/user_global_native_identity_transform_test.go +484 -0
- package/native/core/factories/FormatCheatSheet.go +2 -2
- package/native/core/factories/MetadataCommentTagFactory.go +26 -11
- package/native/core/factories/ProtobufFactory.go +6 -1
- package/native/core/factories/factory_utility_coverage_test.go +896 -907
- package/native/core/factories/internal/metadata/MetadataHelper.go +190 -58
- package/native/core/factories/internal/metadata/emplace_metadata_object.go +25 -0
- package/native/core/factories/internal/metadata/iterate_metadata_function.go +1 -1
- package/native/core/factories/internal/metadata/iterate_metadata_intersection.go +103 -23
- package/native/core/factories/internal/metadata/iterate_metadata_map.go +3 -7
- package/native/core/factories/internal/metadata/iterate_metadata_native.go +32 -14
- package/native/core/factories/internal/metadata/iterate_metadata_set.go +3 -7
- package/native/core/factories/metadata_comment_tag_factory_coverage_test.go +2 -2
- package/native/core/programmers/RandomProgrammer.go +5 -2
- package/native/core/programmers/compare/CompareEqualProgrammer.go +27 -13
- package/native/core/programmers/helpers/FunctionProgrammer.go +6 -13
- package/native/core/programmers/helpers/StringifyJoinder.go +129 -50
- package/native/core/programmers/helpers/joiner_branch_coverage_test.go +116 -120
- package/native/core/programmers/iterate/iterate_check_coverage_test.go +76 -158
- package/native/core/programmers/iterate/iterate_utility_coverage_test.go +231 -270
- package/native/core/programmers/iterate/json_schema_object.go +49 -7
- package/native/core/programmers/iterate/json_schema_pattern_property_order_test.go +44 -0
- package/native/core/programmers/iterate/openapi_v3_downgrader.go +34 -1
- package/native/core/programmers/iterate/template_runtime_pattern.go +11 -0
- package/native/core/programmers/json/JsonStringifyProgrammer.go +47 -6
- package/native/core/programmers/llm/LlmApplicationProgrammer.go +9 -1
- package/native/core/programmers/protobuf/ProtobufMessageProgrammer.go +1 -1
- package/native/core/schemas/metadata/MetadataCollection.go +47 -14
- package/native/core/schemas/metadata/MetadataDefaultLibrary.go +81 -0
- package/native/core/schemas/metadata/MetadataObjectType.go +7 -18
- package/native/go.mod +4 -4
- package/native/transform/CallExpressionTransformer.go +167 -0
- package/native/transform/features/protobuf/ProtobufMessageTransformer.go +1 -1
- package/package.json +3 -7
- package/src/executable/FileSystemIdentity.ts +33 -0
- package/src/executable/TypiaGenerateWizard.ts +18 -12
- package/src/http.ts +18 -4
- package/src/internal/_ProtobufReader.ts +40 -11
- package/src/internal/_assertGuard.ts +13 -2
- package/src/internal/_isFormatIdnHostname.ts +5 -1
- package/src/internal/_isFormatTime.ts +19 -2
- package/src/internal/_jsonStringifyArray.ts +50 -0
- package/src/internal/_jsonStringifyElement.ts +19 -0
- package/src/internal/_jsonStringifyProperty.ts +30 -0
- package/src/internal/_llmApplicationFinalize.ts +6 -1
- package/src/internal/_randomArray.ts +42 -6
- package/src/internal/_randomFormatByte.ts +36 -4
- package/src/internal/_randomFormatDate.ts +4 -20
- package/src/internal/_randomFormatDatetime.ts +34 -20
- package/src/internal/_randomFormatDuration.ts +19 -4
- package/src/internal/_randomFormatHostname.ts +2 -2
- package/src/internal/_randomFormatIdnHostname.ts +8 -9
- package/src/internal/_randomFormatIpv4.ts +43 -3
- package/src/internal/_randomFormatIpv6.ts +67 -3
- package/src/internal/_randomFormatJsonPointer.ts +23 -3
- package/src/internal/_randomFormatRegex.ts +22 -6
- package/src/internal/_randomFormatRelativeJsonPointer.ts +23 -10
- package/src/internal/_randomFormatTime.ts +50 -12
- package/src/internal/_randomPattern.ts +4 -1
- package/src/internal/_randomStringLength.ts +61 -17
- package/src/internal/private/__notationRename.ts +1 -4
- package/src/internal/private/__randomComposition.ts +74 -0
- package/src/internal/private/__randomEpoch.ts +34 -0
- package/src/json.ts +16 -4
- package/src/module.ts +56 -22
- package/src/notations.ts +16 -4
- package/src/plain.ts +12 -3
- package/src/protobuf.ts +16 -4
- package/native/adapter/visit.go +0 -173
- package/native/adapter/visit_property_chain_edges_test.go +0 -129
- package/native/core/programmers/helpers/disable_function_programmer_declare.go +0 -10
- package/native/core/programmers/iterate/check_union_array_like.go +0 -422
- package/native/core/programmers/iterate/prune_object_properties.go +0 -105
- package/native/core/programmers/iterate/stringify_dynamic_properties.go +0 -219
- package/native/core/programmers/iterate/stringify_native.go +0 -14
- package/native/core/programmers/iterate/stringify_regular_properties.go +0 -112
- package/native/core/schemas/metadata/MetadataApplication.go +0 -41
|
@@ -1,12 +1,47 @@
|
|
|
1
1
|
import { _randomInteger } from "./_randomInteger.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { _RANDOM_LENGTH_ERROR, _randomLengthPick, _randomLengthWindow } from "./_randomStringLength.mjs";
|
|
3
|
+
import { __randomDigits } from "./private/__randomComposition.mjs";
|
|
3
4
|
//#region src/internal/_randomFormatTime.ts
|
|
4
|
-
const _randomFormatTime = (props) =>
|
|
5
|
+
const _randomFormatTime = (props) => {
|
|
6
|
+
const clock = () => new Date(_randomInteger({
|
|
7
|
+
type: "integer",
|
|
8
|
+
minimum: 0,
|
|
9
|
+
maximum: DAY
|
|
10
|
+
})).toISOString();
|
|
11
|
+
if (props?.minLength === void 0 && props?.maxLength === void 0) return clock().substring(11);
|
|
12
|
+
const window = _randomLengthWindow(props, {
|
|
13
|
+
minimum: CLOCK + 1,
|
|
14
|
+
spread: 6
|
|
15
|
+
});
|
|
16
|
+
let length = _randomLengthPick(window);
|
|
17
|
+
if (length === CLOCK + 2) length = window.high >= CLOCK + 3 ? CLOCK + 3 : CLOCK + 1;
|
|
18
|
+
if (length < window.low || length > window.high) throw new Error(_RANDOM_LENGTH_ERROR);
|
|
19
|
+
const base = clock().substring(11, 11 + CLOCK);
|
|
20
|
+
if (length === CLOCK + 1) return `${base}Z`;
|
|
21
|
+
const fraction = length - CLOCK - OFFSET - 1;
|
|
22
|
+
return (fraction === -1 || fraction >= 1) && _randomInteger({
|
|
23
|
+
type: "integer",
|
|
24
|
+
minimum: 0,
|
|
25
|
+
maximum: 1
|
|
26
|
+
}) === 1 ? fraction === -1 ? `${base}${offset()}` : `${base}.${__randomDigits(fraction)}${offset()}` : `${base}.${__randomDigits(length - CLOCK - 2)}Z`;
|
|
27
|
+
};
|
|
28
|
+
const DAY = 864e5;
|
|
29
|
+
const CLOCK = 8;
|
|
30
|
+
const OFFSET = 6;
|
|
31
|
+
const offset = () => `${_randomInteger({
|
|
5
32
|
type: "integer",
|
|
6
33
|
minimum: 0,
|
|
7
|
-
maximum:
|
|
8
|
-
})
|
|
9
|
-
|
|
34
|
+
maximum: 1
|
|
35
|
+
}) === 0 ? "+" : "-"}${pad(_randomInteger({
|
|
36
|
+
type: "integer",
|
|
37
|
+
minimum: 0,
|
|
38
|
+
maximum: 23
|
|
39
|
+
}))}:${pad(_randomInteger({
|
|
40
|
+
type: "integer",
|
|
41
|
+
minimum: 0,
|
|
42
|
+
maximum: 59
|
|
43
|
+
}))}`;
|
|
44
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
10
45
|
//#endregion
|
|
11
46
|
export { _randomFormatTime };
|
|
12
47
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatTime.mjs","names":[],"sources":["../../src/internal/_randomFormatTime.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport {
|
|
1
|
+
{"version":3,"file":"_randomFormatTime.mjs","names":[],"sources":["../../src/internal/_randomFormatTime.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport {\n _ILengthProps,\n _RANDOM_LENGTH_ERROR,\n _randomLengthPick,\n _randomLengthWindow,\n} from \"./_randomStringLength\";\nimport { __randomDigits } from \"./private/__randomComposition\";\n\nexport const _randomFormatTime = (props?: _ILengthProps): string => {\n const clock = (): string =>\n new Date(\n _randomInteger({ type: \"integer\", minimum: 0, maximum: DAY }),\n ).toISOString();\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return clock().substring(11);\n // `HH:MM:SS` carries a mandatory offset — one character as `Z`, six as\n // `+HH:MM` — and an optional fraction between them that RFC 3339 leaves\n // open above. Together they express 9 and every length from 11 upward; 10 is\n // the one gap, because a fraction needs both a dot and a digit.\n const window = _randomLengthWindow(props, {\n minimum: CLOCK + 1,\n spread: 6,\n });\n let length: number = _randomLengthPick(window);\n if (length === CLOCK + 2)\n length = window.high >= CLOCK + 3 ? CLOCK + 3 : CLOCK + 1;\n if (length < window.low || length > window.high)\n throw new Error(_RANDOM_LENGTH_ERROR);\n const base: string = clock().substring(11, 11 + CLOCK);\n if (length === CLOCK + 1) return `${base}Z`;\n // The `Z` form reaches every remaining length by itself, so the numeric\n // offset is a choice rather than a fallback: it spends six characters, which\n // leaves either nothing (14, `HH:MM:SS+HH:MM`) or a whole fraction (16 and\n // up). At 15 only the `Z` form fits, since the offset would demand a dot\n // with no digit after it.\n const fraction: number = length - CLOCK - OFFSET - 1;\n return (fraction === -1 || fraction >= 1) &&\n _randomInteger({ type: \"integer\", minimum: 0, maximum: 1 }) === 1\n ? fraction === -1\n ? `${base}${offset()}`\n : `${base}.${__randomDigits(fraction)}${offset()}`\n : `${base}.${__randomDigits(length - CLOCK - 2)}Z`;\n};\n\nconst DAY = 86_400_000;\nconst CLOCK = \"00:00:00\".length;\nconst OFFSET = \"+00:00\".length;\n\nconst offset = (): string =>\n `${_randomInteger({ type: \"integer\", minimum: 0, maximum: 1 }) === 0 ? \"+\" : \"-\"}${pad(\n _randomInteger({ type: \"integer\", minimum: 0, maximum: 23 }),\n )}:${pad(_randomInteger({ type: \"integer\", minimum: 0, maximum: 59 }))}`;\n\nconst pad = (value: number): string => String(value).padStart(2, \"0\");\n"],"mappings":";;;;AASA,MAAa,qBAAqB,UAAkC;CAClE,MAAM,cACJ,IAAI,KACF,eAAe;EAAE,MAAM;EAAW,SAAS;EAAG,SAAS;CAAI,CAAC,CAC9D,CAAC,CAAC,YAAY;CAChB,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,MAAM,CAAC,CAAC,UAAU,EAAE;CAK7B,MAAM,SAAS,oBAAoB,OAAO;EACxC,SAAS,QAAQ;EACjB,QAAQ;CACV,CAAC;CACD,IAAI,SAAiB,kBAAkB,MAAM;CAC7C,IAAI,WAAW,QAAQ,GACrB,SAAS,OAAO,QAAQ,QAAQ,IAAI,QAAQ,IAAI,QAAQ;CAC1D,IAAI,SAAS,OAAO,OAAO,SAAS,OAAO,MACzC,MAAM,IAAI,MAAM,oBAAoB;CACtC,MAAM,OAAe,MAAM,CAAC,CAAC,UAAU,IAAI,KAAK,KAAK;CACrD,IAAI,WAAW,QAAQ,GAAG,OAAO,GAAG,KAAK;CAMzC,MAAM,WAAmB,SAAS,QAAQ,SAAS;CACnD,QAAQ,aAAa,MAAM,YAAY,MACrC,eAAe;EAAE,MAAM;EAAW,SAAS;EAAG,SAAS;CAAE,CAAC,MAAM,IAC9D,aAAa,KACX,GAAG,OAAO,OAAO,MACjB,GAAG,KAAK,GAAG,eAAe,QAAQ,IAAI,OAAO,MAC/C,GAAG,KAAK,GAAG,eAAe,SAAS,QAAQ,CAAC,EAAE;AACpD;AAEA,MAAM,MAAM;AACZ,MAAM,QAAQ;AACd,MAAM,SAAS;AAEf,MAAM,eACJ,GAAG,eAAe;CAAE,MAAM;CAAW,SAAS;CAAG,SAAS;AAAE,CAAC,MAAM,IAAI,MAAM,MAAM,IACjF,eAAe;CAAE,MAAM;CAAW,SAAS;CAAG,SAAS;AAAG,CAAC,CAC7D,EAAE,GAAG,IAAI,eAAe;CAAE,MAAM;CAAW,SAAS;CAAG,SAAS;AAAG,CAAC,CAAC;AAEvE,MAAM,OAAO,UAA0B,OAAO,KAAK,CAAC,CAAC,SAAS,GAAG,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomPattern.js","sourceRoot":"","sources":["../../src/internal/_randomPattern.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAIvB,MAAM,cAAc,GAAG,
|
|
1
|
+
{"version":3,"file":"_randomPattern.js","sourceRoot":"","sources":["../../src/internal/_randomPattern.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAIvB,MAAM,cAAc,GAAG,CAC5B,KAAa,EACb,KAAqB,EACb,EAAE;IACV,MAAM,CAAC,GAAY,IAAI,iBAAO,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,GAAG,GAAuB,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,CAAC;IACjD,MAAM,GAAG,GAAuB,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,CAAC;IAEjD,6EAA6E;IAC7E,8EAA8E;IAC9E,6EAA6E;IAC7E,IAAI,GAAG,KAAK,SAAS;QAAE,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;SAC9B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG;QAAE,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;IAE/D,MAAM,OAAO,GAAY,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,CAAC;IAChE,MAAM,KAAK,GAAW,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1C,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC;QACvC,MAAM,GAAG,GAAW,CAAC,CAAC,GAAG,EAAE,CAAC;QAC5B,IACE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;YACf,CAAC,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC;YACxC,CAAC,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC;YAExC,OAAO,GAAG,CAAC;IACf,CAAC;IACD,MAAM,IAAI,KAAK,CACb,OAAO;QACL,CAAC,CAAC,kFAAkF;QACpF,CAAC,CAAC,0DAA0D,CAC/D,CAAC;AACJ,CAAC,CAAC;AA9BW,QAAA,cAAc,GAAd,cAAc,CA8BzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomPattern.mjs","names":[],"sources":["../../src/internal/_randomPattern.ts"],"sourcesContent":["import RandExp from \"randexp\";\n\nimport { _ILengthProps } from \"./_randomStringLength\";\n\nexport const _randomPattern = (regex: RegExp
|
|
1
|
+
{"version":3,"file":"_randomPattern.mjs","names":[],"sources":["../../src/internal/_randomPattern.ts"],"sourcesContent":["import RandExp from \"randexp\";\n\nimport { _ILengthProps } from \"./_randomStringLength\";\n\nexport const _randomPattern = (\n regex: RegExp,\n props?: _ILengthProps,\n): string => {\n const r: RandExp = new RandExp(regex);\n const min: number | undefined = props?.minLength;\n const max: number | undefined = props?.maxLength;\n\n // RandExp expands an unbounded quantifier to `randInt(token.min, token.min +\n // r.max)`, so steering `r.max` biases the generated length toward the window.\n // There is no matching floor control, so the length is still verified below.\n if (max !== undefined) r.max = max;\n else if (min !== undefined && min * 2 > r.max) r.max = min * 2;\n\n const bounded: boolean = min !== undefined || max !== undefined;\n const limit: number = bounded ? 1024 : 10;\n for (let i: number = 0; i < limit; ++i) {\n const str: string = r.gen();\n if (\n regex.test(str) &&\n (min === undefined || str.length >= min) &&\n (max === undefined || str.length <= max)\n )\n return str;\n }\n throw new Error(\n bounded\n ? \"unable to generate a random string matching the pattern within the length range.\"\n : \"unable to generate a random string matching the pattern.\",\n );\n};\n"],"mappings":";;AAIA,MAAa,kBACX,OACA,UACW;CACX,MAAM,IAAa,IAAI,QAAQ,KAAK;CACpC,MAAM,MAA0B,OAAO;CACvC,MAAM,MAA0B,OAAO;CAKvC,IAAI,QAAQ,KAAA,GAAW,EAAE,MAAM;MAC1B,IAAI,QAAQ,KAAA,KAAa,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,MAAM;CAE7D,MAAM,UAAmB,QAAQ,KAAA,KAAa,QAAQ,KAAA;CACtD,MAAM,QAAgB,UAAU,OAAO;CACvC,KAAK,IAAI,IAAY,GAAG,IAAI,OAAO,EAAE,GAAG;EACtC,MAAM,MAAc,EAAE,IAAI;EAC1B,IACE,MAAM,KAAK,GAAG,MACb,QAAQ,KAAA,KAAa,IAAI,UAAU,SACnC,QAAQ,KAAA,KAAa,IAAI,UAAU,MAEpC,OAAO;CACX;CACA,MAAM,IAAI,MACR,UACI,qFACA,0DACN;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const _RANDOM_LENGTH_ERROR = "unable to generate a random string satisfying both the format and the length constraints.";
|
|
1
2
|
/**
|
|
2
3
|
* Length bounds forwarded to a string format or pattern generator.
|
|
3
4
|
*
|
|
@@ -15,19 +16,49 @@ export interface _ILengthProps {
|
|
|
15
16
|
* length `fixed + segment.length` lands inside the requested window.
|
|
16
17
|
*
|
|
17
18
|
* `fixed` is the number of characters the format always contributes around the
|
|
18
|
-
* segment, `fallback` is the segment length used when the leaf is
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* segment, `fallback` is the segment length used when the leaf is unconstrained
|
|
20
|
+
* on that side, and `minimum` is the smallest segment the format still
|
|
21
|
+
* validates with. Throws when the window cannot be satisfied by this format's
|
|
22
|
+
* shape (e.g. `Format<"email"> & MaxLength<3>`).
|
|
22
23
|
*/
|
|
23
24
|
export declare const _randomSegmentLength: (props: _ILengthProps | undefined, fixed: number, fallback: number, minimum: number) => string;
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
26
|
+
* Intersects the requested length window with the lengths a format's grammar
|
|
27
|
+
* can express, and draws one of them.
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* `minimum` and `maximum` are the shortest and longest values the format admits
|
|
30
|
+
* — omit `maximum` when the grammar is open above — and `spread` is how far
|
|
31
|
+
* past the floor an unbounded request may reach, so an open side still varies
|
|
32
|
+
* the way `_randomString` does. The caller draws from the returned window and
|
|
33
|
+
* applies whatever step its grammar has (base64 lengths are multiples of four,
|
|
34
|
+
* a fractional second needs at least one digit).
|
|
35
|
+
*
|
|
36
|
+
* Throws only when the window and the grammar do not overlap at all. That is
|
|
37
|
+
* the distinction the retry driver below cannot make: it redraws one shape, so
|
|
38
|
+
* it gives up on every length that shape never emits even when the format
|
|
39
|
+
* itself accepts one (issue #2284).
|
|
40
|
+
*/
|
|
41
|
+
export declare const _randomLengthWindow: (props: _ILengthProps | undefined, format: {
|
|
42
|
+
minimum: number;
|
|
43
|
+
maximum?: number;
|
|
44
|
+
spread?: number;
|
|
45
|
+
}) => {
|
|
46
|
+
low: number;
|
|
47
|
+
high: number;
|
|
48
|
+
};
|
|
49
|
+
/** Draws a length inside a window produced by {@link _randomLengthWindow}. */
|
|
50
|
+
export declare const _randomLengthPick: (window: {
|
|
51
|
+
low: number;
|
|
52
|
+
high: number;
|
|
53
|
+
}) => number;
|
|
54
|
+
/**
|
|
55
|
+
* Wraps a fixed-length format generator (uuid, date) with the requested length
|
|
56
|
+
* window.
|
|
57
|
+
*
|
|
58
|
+
* Use it only where the grammar admits exactly one length, so a window that
|
|
59
|
+
* excludes it is genuinely unsatisfiable. A format that can express more than
|
|
60
|
+
* one length must build its value at a length drawn from
|
|
61
|
+
* {@link _randomLengthWindow} instead; redrawing one shape cannot reach a length
|
|
62
|
+
* that shape never emits.
|
|
32
63
|
*/
|
|
33
64
|
export declare const _randomFormatLength: (props: _ILengthProps | undefined, generate: () => string) => string;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._randomFormatLength = exports._randomSegmentLength = void 0;
|
|
3
|
+
exports._randomFormatLength = exports._randomLengthPick = exports._randomLengthWindow = exports._randomSegmentLength = exports._RANDOM_LENGTH_ERROR = void 0;
|
|
4
|
+
const _randomInteger_1 = require("./_randomInteger");
|
|
4
5
|
const _randomString_1 = require("./_randomString");
|
|
6
|
+
exports._RANDOM_LENGTH_ERROR = "unable to generate a random string satisfying both the format and the length constraints.";
|
|
5
7
|
/**
|
|
6
8
|
* Builds the variable segment of a fixed-shape format string so that the total
|
|
7
9
|
* length `fixed + segment.length` lands inside the requested window.
|
|
8
10
|
*
|
|
9
11
|
* `fixed` is the number of characters the format always contributes around the
|
|
10
|
-
* segment, `fallback` is the segment length used when the leaf is
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* segment, `fallback` is the segment length used when the leaf is unconstrained
|
|
13
|
+
* on that side, and `minimum` is the smallest segment the format still
|
|
14
|
+
* validates with. Throws when the window cannot be satisfied by this format's
|
|
15
|
+
* shape (e.g. `Format<"email"> & MaxLength<3>`).
|
|
14
16
|
*/
|
|
15
17
|
const _randomSegmentLength = (props, fixed, fallback, minimum) => {
|
|
16
18
|
let low = (props === null || props === void 0 ? void 0 : props.minLength) === undefined ? minimum : props.minLength - fixed;
|
|
@@ -20,18 +22,52 @@ const _randomSegmentLength = (props, fixed, fallback, minimum) => {
|
|
|
20
22
|
// characters so the generated length varies, mirroring `_randomString`.
|
|
21
23
|
const high = (props === null || props === void 0 ? void 0 : props.maxLength) === undefined ? low + fallback : props.maxLength - fixed;
|
|
22
24
|
if (high < low || high < minimum)
|
|
23
|
-
throw new Error(
|
|
25
|
+
throw new Error(exports._RANDOM_LENGTH_ERROR);
|
|
24
26
|
return (0, _randomString_1._randomString)({ type: "string", minLength: low, maxLength: high });
|
|
25
27
|
};
|
|
26
28
|
exports._randomSegmentLength = _randomSegmentLength;
|
|
27
29
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
+
* Intersects the requested length window with the lengths a format's grammar
|
|
31
|
+
* can express, and draws one of them.
|
|
30
32
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
33
|
+
* `minimum` and `maximum` are the shortest and longest values the format admits
|
|
34
|
+
* — omit `maximum` when the grammar is open above — and `spread` is how far
|
|
35
|
+
* past the floor an unbounded request may reach, so an open side still varies
|
|
36
|
+
* the way `_randomString` does. The caller draws from the returned window and
|
|
37
|
+
* applies whatever step its grammar has (base64 lengths are multiples of four,
|
|
38
|
+
* a fractional second needs at least one digit).
|
|
39
|
+
*
|
|
40
|
+
* Throws only when the window and the grammar do not overlap at all. That is
|
|
41
|
+
* the distinction the retry driver below cannot make: it redraws one shape, so
|
|
42
|
+
* it gives up on every length that shape never emits even when the format
|
|
43
|
+
* itself accepts one (issue #2284).
|
|
44
|
+
*/
|
|
45
|
+
const _randomLengthWindow = (props, format) => {
|
|
46
|
+
var _a, _b, _c, _d;
|
|
47
|
+
const ceiling = (_a = format.maximum) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER;
|
|
48
|
+
const low = Math.max((_b = props === null || props === void 0 ? void 0 : props.minLength) !== null && _b !== void 0 ? _b : format.minimum, format.minimum);
|
|
49
|
+
const high = Math.min((_c = props === null || props === void 0 ? void 0 : props.maxLength) !== null && _c !== void 0 ? _c : low + ((_d = format.spread) !== null && _d !== void 0 ? _d : 0), ceiling);
|
|
50
|
+
if (low > high)
|
|
51
|
+
throw new Error(exports._RANDOM_LENGTH_ERROR);
|
|
52
|
+
return { low, high };
|
|
53
|
+
};
|
|
54
|
+
exports._randomLengthWindow = _randomLengthWindow;
|
|
55
|
+
/** Draws a length inside a window produced by {@link _randomLengthWindow}. */
|
|
56
|
+
const _randomLengthPick = (window) => (0, _randomInteger_1._randomInteger)({
|
|
57
|
+
type: "integer",
|
|
58
|
+
minimum: window.low,
|
|
59
|
+
maximum: window.high,
|
|
60
|
+
});
|
|
61
|
+
exports._randomLengthPick = _randomLengthPick;
|
|
62
|
+
/**
|
|
63
|
+
* Wraps a fixed-length format generator (uuid, date) with the requested length
|
|
64
|
+
* window.
|
|
65
|
+
*
|
|
66
|
+
* Use it only where the grammar admits exactly one length, so a window that
|
|
67
|
+
* excludes it is genuinely unsatisfiable. A format that can express more than
|
|
68
|
+
* one length must build its value at a length drawn from
|
|
69
|
+
* {@link _randomLengthWindow} instead; redrawing one shape cannot reach a length
|
|
70
|
+
* that shape never emits.
|
|
35
71
|
*/
|
|
36
72
|
const _randomFormatLength = (props, generate) => {
|
|
37
73
|
if ((props === null || props === void 0 ? void 0 : props.minLength) === undefined && (props === null || props === void 0 ? void 0 : props.maxLength) === undefined)
|
|
@@ -42,7 +78,7 @@ const _randomFormatLength = (props, generate) => {
|
|
|
42
78
|
(props.maxLength === undefined || value.length <= props.maxLength))
|
|
43
79
|
return value;
|
|
44
80
|
}
|
|
45
|
-
throw new Error(
|
|
81
|
+
throw new Error(exports._RANDOM_LENGTH_ERROR);
|
|
46
82
|
};
|
|
47
83
|
exports._randomFormatLength = _randomFormatLength;
|
|
48
84
|
//# sourceMappingURL=_randomStringLength.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomStringLength.js","sourceRoot":"","sources":["../../src/internal/_randomStringLength.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;
|
|
1
|
+
{"version":3,"file":"_randomStringLength.js","sourceRoot":"","sources":["../../src/internal/_randomStringLength.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAClD,mDAAgD;AAEnC,QAAA,oBAAoB,GAC/B,2FAA2F,CAAC;AAe9F;;;;;;;;;GASG;AACI,MAAM,oBAAoB,GAAG,CAClC,KAAgC,EAChC,KAAa,EACb,QAAgB,EAChB,OAAe,EACP,EAAE;IACV,IAAI,GAAG,GACL,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC;IACrE,IAAI,GAAG,GAAG,OAAO;QAAE,GAAG,GAAG,OAAO,CAAC;IACjC,sEAAsE;IACtE,wEAAwE;IACxE,MAAM,IAAI,GACR,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC;IAC5E,IAAI,IAAI,GAAG,GAAG,IAAI,IAAI,GAAG,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,QAAA,oBAAoB,CAAC,CAAC;IACxE,OAAO,IAAA,6BAAa,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC5E,CAAC,CAAC;AAfW,QAAA,oBAAoB,GAApB,oBAAoB,CAe/B;AAEF;;;;;;;;;;;;;;;GAeG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAAgC,EAChC,MAA8D,EAC/B,EAAE;;IACjC,MAAM,OAAO,SAAW,MAAM,CAAC,OAAO,mCAAI,MAAM,CAAC,gBAAgB,CAAC;IAClE,MAAM,GAAG,GAAW,IAAI,CAAC,GAAG,OAC1B,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,mCAAI,MAAM,CAAC,OAAO,EAClC,MAAM,CAAC,OAAO,CACf,CAAC;IACF,MAAM,IAAI,GAAW,IAAI,CAAC,GAAG,OAC3B,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,mCAAI,GAAG,GAAG,OAAC,MAAM,CAAC,MAAM,mCAAI,CAAC,CAAC,EAC9C,OAAO,CACR,CAAC;IACF,IAAI,GAAG,GAAG,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,QAAA,oBAAoB,CAAC,CAAC;IACtD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AACvB,CAAC,CAAC;AAfW,QAAA,mBAAmB,GAAnB,mBAAmB,CAe9B;AAEF,8EAA8E;AACvE,MAAM,iBAAiB,GAAG,CAAC,MAGjC,EAAU,EAAE,CACX,IAAA,+BAAc,EAAC;IACb,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,MAAM,CAAC,GAAG;IACnB,OAAO,EAAE,MAAM,CAAC,IAAI;CACrB,CAAC,CAAC;AARQ,QAAA,iBAAiB,GAAjB,iBAAiB,CAQzB;AAEL;;;;;;;;;GASG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAAgC,EAChC,QAAsB,EACd,EAAE;IACV,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS;QAClE,OAAO,QAAQ,EAAE,CAAC;IACpB,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC;QACrC,MAAM,KAAK,GAAW,QAAQ,EAAE,CAAC;QACjC,IACE,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC;YAClE,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC;YAElE,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,QAAA,oBAAoB,CAAC,CAAC;AACxC,CAAC,CAAC;AAfW,QAAA,mBAAmB,GAAnB,mBAAmB,CAe9B"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
import { _randomInteger } from "./_randomInteger.mjs";
|
|
1
2
|
import { _randomString } from "./_randomString.mjs";
|
|
2
3
|
//#region src/internal/_randomStringLength.ts
|
|
4
|
+
const _RANDOM_LENGTH_ERROR = "unable to generate a random string satisfying both the format and the length constraints.";
|
|
3
5
|
/**
|
|
4
6
|
* Builds the variable segment of a fixed-shape format string so that the total
|
|
5
7
|
* length `fixed + segment.length` lands inside the requested window.
|
|
6
8
|
*
|
|
7
9
|
* `fixed` is the number of characters the format always contributes around the
|
|
8
|
-
* segment, `fallback` is the segment length used when the leaf is
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* segment, `fallback` is the segment length used when the leaf is unconstrained
|
|
11
|
+
* on that side, and `minimum` is the smallest segment the format still
|
|
12
|
+
* validates with. Throws when the window cannot be satisfied by this format's
|
|
13
|
+
* shape (e.g. `Format<"email"> & MaxLength<3>`).
|
|
12
14
|
*/
|
|
13
15
|
const _randomSegmentLength = (props, fixed, fallback, minimum) => {
|
|
14
16
|
let low = props?.minLength === void 0 ? minimum : props.minLength - fixed;
|
|
15
17
|
if (low < minimum) low = minimum;
|
|
16
18
|
const high = props?.maxLength === void 0 ? low + fallback : props.maxLength - fixed;
|
|
17
|
-
if (high < low || high < minimum) throw new Error(
|
|
19
|
+
if (high < low || high < minimum) throw new Error(_RANDOM_LENGTH_ERROR);
|
|
18
20
|
return _randomString({
|
|
19
21
|
type: "string",
|
|
20
22
|
minLength: low,
|
|
@@ -22,13 +24,46 @@ const _randomSegmentLength = (props, fixed, fallback, minimum) => {
|
|
|
22
24
|
});
|
|
23
25
|
};
|
|
24
26
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
+
* Intersects the requested length window with the lengths a format's grammar
|
|
28
|
+
* can express, and draws one of them.
|
|
27
29
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* `minimum` and `maximum` are the shortest and longest values the format admits
|
|
31
|
+
* — omit `maximum` when the grammar is open above — and `spread` is how far
|
|
32
|
+
* past the floor an unbounded request may reach, so an open side still varies
|
|
33
|
+
* the way `_randomString` does. The caller draws from the returned window and
|
|
34
|
+
* applies whatever step its grammar has (base64 lengths are multiples of four,
|
|
35
|
+
* a fractional second needs at least one digit).
|
|
36
|
+
*
|
|
37
|
+
* Throws only when the window and the grammar do not overlap at all. That is
|
|
38
|
+
* the distinction the retry driver below cannot make: it redraws one shape, so
|
|
39
|
+
* it gives up on every length that shape never emits even when the format
|
|
40
|
+
* itself accepts one (issue #2284).
|
|
41
|
+
*/
|
|
42
|
+
const _randomLengthWindow = (props, format) => {
|
|
43
|
+
const ceiling = format.maximum ?? Number.MAX_SAFE_INTEGER;
|
|
44
|
+
const low = Math.max(props?.minLength ?? format.minimum, format.minimum);
|
|
45
|
+
const high = Math.min(props?.maxLength ?? low + (format.spread ?? 0), ceiling);
|
|
46
|
+
if (low > high) throw new Error(_RANDOM_LENGTH_ERROR);
|
|
47
|
+
return {
|
|
48
|
+
low,
|
|
49
|
+
high
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/** Draws a length inside a window produced by {@link _randomLengthWindow}. */
|
|
53
|
+
const _randomLengthPick = (window) => _randomInteger({
|
|
54
|
+
type: "integer",
|
|
55
|
+
minimum: window.low,
|
|
56
|
+
maximum: window.high
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Wraps a fixed-length format generator (uuid, date) with the requested length
|
|
60
|
+
* window.
|
|
61
|
+
*
|
|
62
|
+
* Use it only where the grammar admits exactly one length, so a window that
|
|
63
|
+
* excludes it is genuinely unsatisfiable. A format that can express more than
|
|
64
|
+
* one length must build its value at a length drawn from
|
|
65
|
+
* {@link _randomLengthWindow} instead; redrawing one shape cannot reach a length
|
|
66
|
+
* that shape never emits.
|
|
32
67
|
*/
|
|
33
68
|
const _randomFormatLength = (props, generate) => {
|
|
34
69
|
if (props?.minLength === void 0 && props?.maxLength === void 0) return generate();
|
|
@@ -36,9 +71,9 @@ const _randomFormatLength = (props, generate) => {
|
|
|
36
71
|
const value = generate();
|
|
37
72
|
if ((props.minLength === void 0 || value.length >= props.minLength) && (props.maxLength === void 0 || value.length <= props.maxLength)) return value;
|
|
38
73
|
}
|
|
39
|
-
throw new Error(
|
|
74
|
+
throw new Error(_RANDOM_LENGTH_ERROR);
|
|
40
75
|
};
|
|
41
76
|
//#endregion
|
|
42
|
-
export { _randomFormatLength, _randomSegmentLength };
|
|
77
|
+
export { _RANDOM_LENGTH_ERROR, _randomFormatLength, _randomLengthPick, _randomLengthWindow, _randomSegmentLength };
|
|
43
78
|
|
|
44
79
|
//# sourceMappingURL=_randomStringLength.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomStringLength.mjs","names":[],"sources":["../../src/internal/_randomStringLength.ts"],"sourcesContent":["import { _randomString } from \"./_randomString\";\n\n/**\n * Length bounds forwarded to a string format or pattern generator.\n *\n * `typia.random<T>()` passes this object to the `_randomFormat*` and\n * `_randomPattern` helpers whenever the string leaf also carries a `MinLength`\n * or `MaxLength` tag, so a constrained format or pattern is generated at a\n * length its own validator accepts (issue #2189).\n */\nexport interface _ILengthProps {\n minLength?: number;\n maxLength?: number;\n}\n\n/**\n * Builds the variable segment of a fixed-shape format string so that the total\n * length `fixed + segment.length` lands inside the requested window.\n *\n * `fixed` is the number of characters the format always contributes around the\n * segment, `fallback` is the segment length used when the leaf is\n *
|
|
1
|
+
{"version":3,"file":"_randomStringLength.mjs","names":[],"sources":["../../src/internal/_randomStringLength.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\n\nexport const _RANDOM_LENGTH_ERROR =\n \"unable to generate a random string satisfying both the format and the length constraints.\";\n\n/**\n * Length bounds forwarded to a string format or pattern generator.\n *\n * `typia.random<T>()` passes this object to the `_randomFormat*` and\n * `_randomPattern` helpers whenever the string leaf also carries a `MinLength`\n * or `MaxLength` tag, so a constrained format or pattern is generated at a\n * length its own validator accepts (issue #2189).\n */\nexport interface _ILengthProps {\n minLength?: number;\n maxLength?: number;\n}\n\n/**\n * Builds the variable segment of a fixed-shape format string so that the total\n * length `fixed + segment.length` lands inside the requested window.\n *\n * `fixed` is the number of characters the format always contributes around the\n * segment, `fallback` is the segment length used when the leaf is unconstrained\n * on that side, and `minimum` is the smallest segment the format still\n * validates with. Throws when the window cannot be satisfied by this format's\n * shape (e.g. `Format<\"email\"> & MaxLength<3>`).\n */\nexport const _randomSegmentLength = (\n props: _ILengthProps | undefined,\n fixed: number,\n fallback: number,\n minimum: number,\n): string => {\n let low: number =\n props?.minLength === undefined ? minimum : props.minLength - fixed;\n if (low < minimum) low = minimum;\n // With only a lower bound, spread the segment across `fallback` extra\n // characters so the generated length varies, mirroring `_randomString`.\n const high: number =\n props?.maxLength === undefined ? low + fallback : props.maxLength - fixed;\n if (high < low || high < minimum) throw new Error(_RANDOM_LENGTH_ERROR);\n return _randomString({ type: \"string\", minLength: low, maxLength: high });\n};\n\n/**\n * Intersects the requested length window with the lengths a format's grammar\n * can express, and draws one of them.\n *\n * `minimum` and `maximum` are the shortest and longest values the format admits\n * — omit `maximum` when the grammar is open above — and `spread` is how far\n * past the floor an unbounded request may reach, so an open side still varies\n * the way `_randomString` does. The caller draws from the returned window and\n * applies whatever step its grammar has (base64 lengths are multiples of four,\n * a fractional second needs at least one digit).\n *\n * Throws only when the window and the grammar do not overlap at all. That is\n * the distinction the retry driver below cannot make: it redraws one shape, so\n * it gives up on every length that shape never emits even when the format\n * itself accepts one (issue #2284).\n */\nexport const _randomLengthWindow = (\n props: _ILengthProps | undefined,\n format: { minimum: number; maximum?: number; spread?: number },\n): { low: number; high: number } => {\n const ceiling: number = format.maximum ?? Number.MAX_SAFE_INTEGER;\n const low: number = Math.max(\n props?.minLength ?? format.minimum,\n format.minimum,\n );\n const high: number = Math.min(\n props?.maxLength ?? low + (format.spread ?? 0),\n ceiling,\n );\n if (low > high) throw new Error(_RANDOM_LENGTH_ERROR);\n return { low, high };\n};\n\n/** Draws a length inside a window produced by {@link _randomLengthWindow}. */\nexport const _randomLengthPick = (window: {\n low: number;\n high: number;\n}): number =>\n _randomInteger({\n type: \"integer\",\n minimum: window.low,\n maximum: window.high,\n });\n\n/**\n * Wraps a fixed-length format generator (uuid, date) with the requested length\n * window.\n *\n * Use it only where the grammar admits exactly one length, so a window that\n * excludes it is genuinely unsatisfiable. A format that can express more than\n * one length must build its value at a length drawn from\n * {@link _randomLengthWindow} instead; redrawing one shape cannot reach a length\n * that shape never emits.\n */\nexport const _randomFormatLength = (\n props: _ILengthProps | undefined,\n generate: () => string,\n): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return generate();\n for (let i: number = 0; i < 256; ++i) {\n const value: string = generate();\n if (\n (props.minLength === undefined || value.length >= props.minLength) &&\n (props.maxLength === undefined || value.length <= props.maxLength)\n )\n return value;\n }\n throw new Error(_RANDOM_LENGTH_ERROR);\n};\n"],"mappings":";;;AAGA,MAAa,uBACX;;;;;;;;;;;AAyBF,MAAa,wBACX,OACA,OACA,UACA,YACW;CACX,IAAI,MACF,OAAO,cAAc,KAAA,IAAY,UAAU,MAAM,YAAY;CAC/D,IAAI,MAAM,SAAS,MAAM;CAGzB,MAAM,OACJ,OAAO,cAAc,KAAA,IAAY,MAAM,WAAW,MAAM,YAAY;CACtE,IAAI,OAAO,OAAO,OAAO,SAAS,MAAM,IAAI,MAAM,oBAAoB;CACtE,OAAO,cAAc;EAAE,MAAM;EAAU,WAAW;EAAK,WAAW;CAAK,CAAC;AAC1E;;;;;;;;;;;;;;;;;AAkBA,MAAa,uBACX,OACA,WACkC;CAClC,MAAM,UAAkB,OAAO,WAAW,OAAO;CACjD,MAAM,MAAc,KAAK,IACvB,OAAO,aAAa,OAAO,SAC3B,OAAO,OACT;CACA,MAAM,OAAe,KAAK,IACxB,OAAO,aAAa,OAAO,OAAO,UAAU,IAC5C,OACF;CACA,IAAI,MAAM,MAAM,MAAM,IAAI,MAAM,oBAAoB;CACpD,OAAO;EAAE;EAAK;CAAK;AACrB;;AAGA,MAAa,qBAAqB,WAIhC,eAAe;CACb,MAAM;CACN,SAAS,OAAO;CAChB,SAAS,OAAO;AAClB,CAAC;;;;;;;;;;;AAYH,MAAa,uBACX,OACA,aACW;CACX,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,SAAS;CAClB,KAAK,IAAI,IAAY,GAAG,IAAI,KAAK,EAAE,GAAG;EACpC,MAAM,QAAgB,SAAS;EAC/B,KACG,MAAM,cAAc,KAAA,KAAa,MAAM,UAAU,MAAM,eACvD,MAAM,cAAc,KAAA,KAAa,MAAM,UAAU,MAAM,YAExD,OAAO;CACX;CACA,MAAM,IAAI,MAAM,oBAAoB;AACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__notationRename.js","sourceRoot":"","sources":["../../../src/internal/private/__notationRename.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACI,MAAM,gBAAgB,GAC3B,CAAC,
|
|
1
|
+
{"version":3,"file":"__notationRename.js","sourceRoot":"","sources":["../../../src/internal/private/__notationRename.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACI,MAAM,gBAAgB,GAC3B,CAAC,KAAyE,EAAE,EAAE,CAC9E,CAAC,GAAW,EAAU,EAAE;IACtB,IAAI,MAAM,GAAW,EAAE,CAAC;IACxB,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,CAAC;QACd,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC;IACpC,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;AAC/E,CAAC,CAAC;AAVS,QAAA,gBAAgB,GAAhB,gBAAgB,CAUzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__notationRename.mjs","names":[],"sources":["../../../src/internal/private/__notationRename.ts"],"sourcesContent":["/**\n * Shared outer walk for the `camel`/`pascal` notations.\n *\n * Mirrors the `CamelCase<T>` / `PascalCase<T>` typings: leading underscores are\n * preserved verbatim, an all-underscore key stays untouched, and the presence\n * of any remaining underscore — not the number of non-empty segments — selects\n * the `snake` conversion. Routing on underscore presence keeps a trailing or\n * doubled underscore (`fooBar_`) on the same path the type takes, instead of\n * collapsing it to the underscore-free `plain` path.\n */\nexport const __notationRename =\n (props: {
|
|
1
|
+
{"version":3,"file":"__notationRename.mjs","names":[],"sources":["../../../src/internal/private/__notationRename.ts"],"sourcesContent":["/**\n * Shared outer walk for the `camel`/`pascal` notations.\n *\n * Mirrors the `CamelCase<T>` / `PascalCase<T>` typings: leading underscores are\n * preserved verbatim, an all-underscore key stays untouched, and the presence\n * of any remaining underscore — not the number of non-empty segments — selects\n * the `snake` conversion. Routing on underscore presence keeps a trailing or\n * doubled underscore (`fooBar_`) on the same path the type takes, instead of\n * collapsing it to the underscore-free `plain` path.\n */\nexport const __notationRename =\n (props: { plain: (str: string) => string; snake: (str: string) => string }) =>\n (str: string): string => {\n let prefix: string = \"\";\n while (str.startsWith(\"_\")) {\n prefix += \"_\";\n str = str.substring(1);\n }\n if (str.length === 0) return prefix;\n return `${prefix}${str.includes(\"_\") ? props.snake(str) : props.plain(str)}`;\n };\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,oBACV,WACA,QAAwB;CACvB,IAAI,SAAiB;CACrB,OAAO,IAAI,WAAW,GAAG,GAAG;EAC1B,UAAU;EACV,MAAM,IAAI,UAAU,CAAC;CACvB;CACA,IAAI,IAAI,WAAW,GAAG,OAAO;CAC7B,OAAO,GAAG,SAAS,IAAI,SAAS,GAAG,IAAI,MAAM,MAAM,GAAG,IAAI,MAAM,MAAM,GAAG;AAC3E"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits `total` into `count` parts, each inside `[minimum, maximum]`.
|
|
3
|
+
*
|
|
4
|
+
* Used where a format's length is the sum of its segments — an IPv4 octet spans
|
|
5
|
+
* one to three digits, an IPv6 group one to four — so a requested total length
|
|
6
|
+
* is realized by choosing how many characters each segment contributes instead
|
|
7
|
+
* of redrawing whole addresses and hoping one lands in the window (issue
|
|
8
|
+
* #2284).
|
|
9
|
+
*
|
|
10
|
+
* The caller guarantees `count * minimum <= total <= count * maximum`; each
|
|
11
|
+
* part is drawn from the range that still leaves the remaining parts
|
|
12
|
+
* satisfiable.
|
|
13
|
+
*/
|
|
14
|
+
export declare const __randomComposition: (props: {
|
|
15
|
+
total: number;
|
|
16
|
+
count: number;
|
|
17
|
+
minimum: number;
|
|
18
|
+
maximum: number;
|
|
19
|
+
}) => number[];
|
|
20
|
+
/**
|
|
21
|
+
* Draws `length` characters of the base64 alphabet.
|
|
22
|
+
*
|
|
23
|
+
* The caller passes a multiple of four, which `format: "byte"` accepts without
|
|
24
|
+
* padding; every character below is in the alphabet its validator spells out,
|
|
25
|
+
* so the result needs no encoding step.
|
|
26
|
+
*/
|
|
27
|
+
export declare const __randomBase64: (length: number) => string;
|
|
28
|
+
/** Draws `length` decimal digits, leading zeros included. */
|
|
29
|
+
export declare const __randomDigits: (length: number) => string;
|
|
30
|
+
/** Draws a decimal number of exactly `length` digits without a leading zero. */
|
|
31
|
+
export declare const __randomNumeric: (length: number) => string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__randomNumeric = exports.__randomDigits = exports.__randomBase64 = exports.__randomComposition = void 0;
|
|
4
|
+
const _randomInteger_1 = require("../_randomInteger");
|
|
5
|
+
/**
|
|
6
|
+
* Splits `total` into `count` parts, each inside `[minimum, maximum]`.
|
|
7
|
+
*
|
|
8
|
+
* Used where a format's length is the sum of its segments — an IPv4 octet spans
|
|
9
|
+
* one to three digits, an IPv6 group one to four — so a requested total length
|
|
10
|
+
* is realized by choosing how many characters each segment contributes instead
|
|
11
|
+
* of redrawing whole addresses and hoping one lands in the window (issue
|
|
12
|
+
* #2284).
|
|
13
|
+
*
|
|
14
|
+
* The caller guarantees `count * minimum <= total <= count * maximum`; each
|
|
15
|
+
* part is drawn from the range that still leaves the remaining parts
|
|
16
|
+
* satisfiable.
|
|
17
|
+
*/
|
|
18
|
+
const __randomComposition = (props) => {
|
|
19
|
+
const parts = [];
|
|
20
|
+
let remaining = props.total;
|
|
21
|
+
for (let i = 0; i < props.count; ++i) {
|
|
22
|
+
const rest = props.count - i - 1;
|
|
23
|
+
const value = (0, _randomInteger_1._randomInteger)({
|
|
24
|
+
type: "integer",
|
|
25
|
+
minimum: Math.max(props.minimum, remaining - rest * props.maximum),
|
|
26
|
+
maximum: Math.min(props.maximum, remaining - rest * props.minimum),
|
|
27
|
+
});
|
|
28
|
+
parts.push(value);
|
|
29
|
+
remaining -= value;
|
|
30
|
+
}
|
|
31
|
+
return parts;
|
|
32
|
+
};
|
|
33
|
+
exports.__randomComposition = __randomComposition;
|
|
34
|
+
/**
|
|
35
|
+
* Draws `length` characters of the base64 alphabet.
|
|
36
|
+
*
|
|
37
|
+
* The caller passes a multiple of four, which `format: "byte"` accepts without
|
|
38
|
+
* padding; every character below is in the alphabet its validator spells out,
|
|
39
|
+
* so the result needs no encoding step.
|
|
40
|
+
*/
|
|
41
|
+
const __randomBase64 = (length) => {
|
|
42
|
+
let text = "";
|
|
43
|
+
for (let i = 0; i < length; ++i)
|
|
44
|
+
text +=
|
|
45
|
+
BASE64[(0, _randomInteger_1._randomInteger)({
|
|
46
|
+
type: "integer",
|
|
47
|
+
minimum: 0,
|
|
48
|
+
maximum: BASE64.length - 1,
|
|
49
|
+
})];
|
|
50
|
+
return text;
|
|
51
|
+
};
|
|
52
|
+
exports.__randomBase64 = __randomBase64;
|
|
53
|
+
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
54
|
+
/** Draws `length` decimal digits, leading zeros included. */
|
|
55
|
+
const __randomDigits = (length) => {
|
|
56
|
+
let text = "";
|
|
57
|
+
for (let i = 0; i < length; ++i)
|
|
58
|
+
text += String((0, _randomInteger_1._randomInteger)({ type: "integer", minimum: 0, maximum: 9 }));
|
|
59
|
+
return text;
|
|
60
|
+
};
|
|
61
|
+
exports.__randomDigits = __randomDigits;
|
|
62
|
+
/** Draws a decimal number of exactly `length` digits without a leading zero. */
|
|
63
|
+
const __randomNumeric = (length) => length <= 1
|
|
64
|
+
? String((0, _randomInteger_1._randomInteger)({ type: "integer", minimum: 0, maximum: 9 }))
|
|
65
|
+
: String((0, _randomInteger_1._randomInteger)({ type: "integer", minimum: 1, maximum: 9 })) +
|
|
66
|
+
(0, exports.__randomDigits)(length - 1);
|
|
67
|
+
exports.__randomNumeric = __randomNumeric;
|
|
68
|
+
//# sourceMappingURL=__randomComposition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__randomComposition.js","sourceRoot":"","sources":["../../../src/internal/private/__randomComposition.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD;;;;;;;;;;;;GAYG;AACI,MAAM,mBAAmB,GAAG,CAAC,KAKnC,EAAY,EAAE;IACb,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,SAAS,GAAW,KAAK,CAAC,KAAK,CAAC;IACpC,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAW,KAAK,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;QACzC,MAAM,KAAK,GAAW,IAAA,+BAAc,EAAC;YACnC,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;YAClE,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;SACnE,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,SAAS,IAAI,KAAK,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAnBW,QAAA,mBAAmB,GAAnB,mBAAmB,CAmB9B;AAEF;;;;;;GAMG;AACI,MAAM,cAAc,GAAG,CAAC,MAAc,EAAU,EAAE;IACvD,IAAI,IAAI,GAAW,EAAE,CAAC;IACtB,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC;QACrC,IAAI;YACF,MAAM,CACJ,IAAA,+BAAc,EAAC;gBACb,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC;aAC3B,CAAC,CACH,CAAC;IACN,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAZW,QAAA,cAAc,GAAd,cAAc,CAYzB;AAEF,MAAM,MAAM,GACV,kEAAkE,CAAC;AAErE,6DAA6D;AACtD,MAAM,cAAc,GAAG,CAAC,MAAc,EAAU,EAAE;IACvD,IAAI,IAAI,GAAW,EAAE,CAAC;IACtB,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC;QACrC,IAAI,IAAI,MAAM,CAAC,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9E,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,cAAc,GAAd,cAAc,CAKzB;AAEF,gFAAgF;AACzE,MAAM,eAAe,GAAG,CAAC,MAAc,EAAU,EAAE,CACxD,MAAM,IAAI,CAAC;IACT,CAAC,CAAC,MAAM,CAAC,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IACrE,CAAC,CAAC,MAAM,CAAC,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;QACnE,IAAA,QAAA,cAAc,EAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAJpB,QAAA,eAAe,GAAf,eAAe,CAIK"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { _randomInteger } from "../_randomInteger.mjs";
|
|
2
|
+
//#region src/internal/private/__randomComposition.ts
|
|
3
|
+
/**
|
|
4
|
+
* Splits `total` into `count` parts, each inside `[minimum, maximum]`.
|
|
5
|
+
*
|
|
6
|
+
* Used where a format's length is the sum of its segments — an IPv4 octet spans
|
|
7
|
+
* one to three digits, an IPv6 group one to four — so a requested total length
|
|
8
|
+
* is realized by choosing how many characters each segment contributes instead
|
|
9
|
+
* of redrawing whole addresses and hoping one lands in the window (issue
|
|
10
|
+
* #2284).
|
|
11
|
+
*
|
|
12
|
+
* The caller guarantees `count * minimum <= total <= count * maximum`; each
|
|
13
|
+
* part is drawn from the range that still leaves the remaining parts
|
|
14
|
+
* satisfiable.
|
|
15
|
+
*/
|
|
16
|
+
const __randomComposition = (props) => {
|
|
17
|
+
const parts = [];
|
|
18
|
+
let remaining = props.total;
|
|
19
|
+
for (let i = 0; i < props.count; ++i) {
|
|
20
|
+
const rest = props.count - i - 1;
|
|
21
|
+
const value = _randomInteger({
|
|
22
|
+
type: "integer",
|
|
23
|
+
minimum: Math.max(props.minimum, remaining - rest * props.maximum),
|
|
24
|
+
maximum: Math.min(props.maximum, remaining - rest * props.minimum)
|
|
25
|
+
});
|
|
26
|
+
parts.push(value);
|
|
27
|
+
remaining -= value;
|
|
28
|
+
}
|
|
29
|
+
return parts;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Draws `length` characters of the base64 alphabet.
|
|
33
|
+
*
|
|
34
|
+
* The caller passes a multiple of four, which `format: "byte"` accepts without
|
|
35
|
+
* padding; every character below is in the alphabet its validator spells out,
|
|
36
|
+
* so the result needs no encoding step.
|
|
37
|
+
*/
|
|
38
|
+
const __randomBase64 = (length) => {
|
|
39
|
+
let text = "";
|
|
40
|
+
for (let i = 0; i < length; ++i) text += BASE64[_randomInteger({
|
|
41
|
+
type: "integer",
|
|
42
|
+
minimum: 0,
|
|
43
|
+
maximum: BASE64.length - 1
|
|
44
|
+
})];
|
|
45
|
+
return text;
|
|
46
|
+
};
|
|
47
|
+
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
48
|
+
/** Draws `length` decimal digits, leading zeros included. */
|
|
49
|
+
const __randomDigits = (length) => {
|
|
50
|
+
let text = "";
|
|
51
|
+
for (let i = 0; i < length; ++i) text += String(_randomInteger({
|
|
52
|
+
type: "integer",
|
|
53
|
+
minimum: 0,
|
|
54
|
+
maximum: 9
|
|
55
|
+
}));
|
|
56
|
+
return text;
|
|
57
|
+
};
|
|
58
|
+
/** Draws a decimal number of exactly `length` digits without a leading zero. */
|
|
59
|
+
const __randomNumeric = (length) => length <= 1 ? String(_randomInteger({
|
|
60
|
+
type: "integer",
|
|
61
|
+
minimum: 0,
|
|
62
|
+
maximum: 9
|
|
63
|
+
})) : String(_randomInteger({
|
|
64
|
+
type: "integer",
|
|
65
|
+
minimum: 1,
|
|
66
|
+
maximum: 9
|
|
67
|
+
})) + __randomDigits(length - 1);
|
|
68
|
+
//#endregion
|
|
69
|
+
export { __randomBase64, __randomComposition, __randomDigits, __randomNumeric };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=__randomComposition.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__randomComposition.mjs","names":[],"sources":["../../../src/internal/private/__randomComposition.ts"],"sourcesContent":["import { _randomInteger } from \"../_randomInteger\";\n\n/**\n * Splits `total` into `count` parts, each inside `[minimum, maximum]`.\n *\n * Used where a format's length is the sum of its segments — an IPv4 octet spans\n * one to three digits, an IPv6 group one to four — so a requested total length\n * is realized by choosing how many characters each segment contributes instead\n * of redrawing whole addresses and hoping one lands in the window (issue\n * #2284).\n *\n * The caller guarantees `count * minimum <= total <= count * maximum`; each\n * part is drawn from the range that still leaves the remaining parts\n * satisfiable.\n */\nexport const __randomComposition = (props: {\n total: number;\n count: number;\n minimum: number;\n maximum: number;\n}): number[] => {\n const parts: number[] = [];\n let remaining: number = props.total;\n for (let i: number = 0; i < props.count; ++i) {\n const rest: number = props.count - i - 1;\n const value: number = _randomInteger({\n type: \"integer\",\n minimum: Math.max(props.minimum, remaining - rest * props.maximum),\n maximum: Math.min(props.maximum, remaining - rest * props.minimum),\n });\n parts.push(value);\n remaining -= value;\n }\n return parts;\n};\n\n/**\n * Draws `length` characters of the base64 alphabet.\n *\n * The caller passes a multiple of four, which `format: \"byte\"` accepts without\n * padding; every character below is in the alphabet its validator spells out,\n * so the result needs no encoding step.\n */\nexport const __randomBase64 = (length: number): string => {\n let text: string = \"\";\n for (let i: number = 0; i < length; ++i)\n text +=\n BASE64[\n _randomInteger({\n type: \"integer\",\n minimum: 0,\n maximum: BASE64.length - 1,\n })\n ];\n return text;\n};\n\nconst BASE64 =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\n/** Draws `length` decimal digits, leading zeros included. */\nexport const __randomDigits = (length: number): string => {\n let text: string = \"\";\n for (let i: number = 0; i < length; ++i)\n text += String(_randomInteger({ type: \"integer\", minimum: 0, maximum: 9 }));\n return text;\n};\n\n/** Draws a decimal number of exactly `length` digits without a leading zero. */\nexport const __randomNumeric = (length: number): string =>\n length <= 1\n ? String(_randomInteger({ type: \"integer\", minimum: 0, maximum: 9 }))\n : String(_randomInteger({ type: \"integer\", minimum: 1, maximum: 9 })) +\n __randomDigits(length - 1);\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,uBAAuB,UAKpB;CACd,MAAM,QAAkB,CAAC;CACzB,IAAI,YAAoB,MAAM;CAC9B,KAAK,IAAI,IAAY,GAAG,IAAI,MAAM,OAAO,EAAE,GAAG;EAC5C,MAAM,OAAe,MAAM,QAAQ,IAAI;EACvC,MAAM,QAAgB,eAAe;GACnC,MAAM;GACN,SAAS,KAAK,IAAI,MAAM,SAAS,YAAY,OAAO,MAAM,OAAO;GACjE,SAAS,KAAK,IAAI,MAAM,SAAS,YAAY,OAAO,MAAM,OAAO;EACnE,CAAC;EACD,MAAM,KAAK,KAAK;EAChB,aAAa;CACf;CACA,OAAO;AACT;;;;;;;;AASA,MAAa,kBAAkB,WAA2B;CACxD,IAAI,OAAe;CACnB,KAAK,IAAI,IAAY,GAAG,IAAI,QAAQ,EAAE,GACpC,QACE,OACE,eAAe;EACb,MAAM;EACN,SAAS;EACT,SAAS,OAAO,SAAS;CAC3B,CAAC;CAEP,OAAO;AACT;AAEA,MAAM,SACJ;;AAGF,MAAa,kBAAkB,WAA2B;CACxD,IAAI,OAAe;CACnB,KAAK,IAAI,IAAY,GAAG,IAAI,QAAQ,EAAE,GACpC,QAAQ,OAAO,eAAe;EAAE,MAAM;EAAW,SAAS;EAAG,SAAS;CAAE,CAAC,CAAC;CAC5E,OAAO;AACT;;AAGA,MAAa,mBAAmB,WAC9B,UAAU,IACN,OAAO,eAAe;CAAE,MAAM;CAAW,SAAS;CAAG,SAAS;AAAE,CAAC,CAAC,IAClE,OAAO,eAAe;CAAE,MAAM;CAAW,SAAS;CAAG,SAAS;AAAE,CAAC,CAAC,IAClE,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface __IEpochProps {
|
|
2
|
+
minimum?: number;
|
|
3
|
+
maximum?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Draws an epoch millisecond inside the requested bounds.
|
|
7
|
+
*
|
|
8
|
+
* Shared by the `date` and `date-time` generators, which had the same bound
|
|
9
|
+
* expression written twice: `props?.maximum ?? props?.minimum === undefined`
|
|
10
|
+
* parses as `props?.maximum ?? (props?.minimum === undefined)` because `??`
|
|
11
|
+
* binds looser than `===`, so any supplied `maximum` made the condition truthy
|
|
12
|
+
* and was replaced by `Date.now()`, while `maximum: 0` fell through to
|
|
13
|
+
* `undefined + one year` and produced `NaN` (issue #2287). Keeping the
|
|
14
|
+
* resolution in one place is what stops the two copies from drifting again.
|
|
15
|
+
*
|
|
16
|
+
* With no bound at all the window ends at the present instant; with only a
|
|
17
|
+
* lower bound it spans one year from there.
|
|
18
|
+
*/
|
|
19
|
+
export declare const __randomEpoch: (props?: __IEpochProps) => number;
|