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
|
@@ -6,6 +6,15 @@ const _randomInteger_1 = require("./_randomInteger");
|
|
|
6
6
|
const DEFAULT_MIN_ITEMS = 1;
|
|
7
7
|
const DEFAULT_RANGE = 5;
|
|
8
8
|
const DEFAULT_RECURSIVE_RANGE = 2;
|
|
9
|
+
/**
|
|
10
|
+
* Consecutive duplicates that end a unique draw once its floor is satisfied.
|
|
11
|
+
*
|
|
12
|
+
* The worst case a domain can still hide is one value left among a handful:
|
|
13
|
+
* with one of four remaining, sixty-four misses in a row is a `0.75 ** 64`
|
|
14
|
+
* event, about one in a hundred million. Below the floor this limit does not
|
|
15
|
+
* apply at all, so it can never fail a request the domain could satisfy.
|
|
16
|
+
*/
|
|
17
|
+
const STALE_LIMIT = 64;
|
|
9
18
|
const _randomArray = (props) => {
|
|
10
19
|
var _a, _b, _c;
|
|
11
20
|
const defaultMinimum = props.recursive === true ? 0 : DEFAULT_MIN_ITEMS;
|
|
@@ -18,15 +27,39 @@ const _randomArray = (props) => {
|
|
|
18
27
|
});
|
|
19
28
|
if (props.uniqueItems !== true)
|
|
20
29
|
return new Array(count).fill(null).map((_, i) => props.element(i, count));
|
|
30
|
+
// How many distinct values the element can take is not knowable from here --
|
|
31
|
+
// `element` is a closure over whatever the transform emitted, from `boolean`
|
|
32
|
+
// to a recursive object -- so the count above is a preference, not a
|
|
33
|
+
// contract. Draw until the budget says the domain has nothing new left, then
|
|
34
|
+
// keep what was reached.
|
|
35
|
+
//
|
|
36
|
+
// Failing on that budget instead is what made `Array<boolean> &
|
|
37
|
+
// UniqueItems` throw on two draws in three: `[true, false]` satisfies the
|
|
38
|
+
// declaration at every count, and a count of five is unreachable for a
|
|
39
|
+
// domain of two however many times it is redrawn. Only a result below the
|
|
40
|
+
// floor is a real failure, which is still the honest outcome for a window
|
|
41
|
+
// like `MinItems<3>` over a domain of two.
|
|
42
|
+
//
|
|
43
|
+
// Below the floor the whole budget is spent, because stopping early there
|
|
44
|
+
// would fail a request the domain can still satisfy. Above it every further
|
|
45
|
+
// attempt is only buying length, so a run of `STALE_LIMIT` duplicates is
|
|
46
|
+
// taken as the domain saying it has nothing left. Without that, each nesting
|
|
47
|
+
// level of a small-domain unique array multiplies the full budget into the
|
|
48
|
+
// level above it.
|
|
21
49
|
const elements = [];
|
|
22
50
|
const maximumAttempts = count * 100 + 1000;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
throw new Error("Unable to generate enough unique items; the element domain may be too small.");
|
|
51
|
+
let stale = 0;
|
|
52
|
+
for (let attempts = 0; elements.length !== count && attempts !== maximumAttempts; attempts++) {
|
|
26
53
|
const candidate = props.element(elements.length, count);
|
|
27
|
-
if (elements.every((element) => (0, _isUniqueItems_1._isUniqueItems)([element, candidate])))
|
|
54
|
+
if (elements.every((element) => (0, _isUniqueItems_1._isUniqueItems)([element, candidate]))) {
|
|
28
55
|
elements.push(candidate);
|
|
56
|
+
stale = 0;
|
|
57
|
+
}
|
|
58
|
+
else if (elements.length >= minimum && ++stale === STALE_LIMIT)
|
|
59
|
+
break;
|
|
29
60
|
}
|
|
61
|
+
if (elements.length < minimum)
|
|
62
|
+
throw new Error("Unable to generate enough unique items; the element domain may be too small.");
|
|
30
63
|
return elements;
|
|
31
64
|
};
|
|
32
65
|
exports._randomArray = _randomArray;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomArray.js","sourceRoot":"","sources":["../../src/internal/_randomArray.ts"],"names":[],"mappings":";;;AAEA,qDAAkD;AAClD,qDAAkD;AAElD,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,uBAAuB,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"_randomArray.js","sourceRoot":"","sources":["../../src/internal/_randomArray.ts"],"names":[],"mappings":";;;AAEA,qDAAkD;AAClD,qDAAkD;AAElD,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,WAAW,GAAG,EAAE,CAAC;AAEhB,MAAM,YAAY,GAAG,CAC1B,KAGC,EACD,EAAE;;IACF,MAAM,cAAc,GAClB,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC;IACnD,MAAM,OAAO,SACX,KAAK,CAAC,QAAQ,mCACd,IAAI,CAAC,GAAG,OAAC,KAAK,CAAC,QAAQ,mCAAI,cAAc,EAAE,cAAc,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAW,IAAA,+BAAc,EAAC;QACnC,IAAI,EAAE,SAAS;QACf,OAAO;QACP,OAAO,QACL,KAAK,CAAC,QAAQ,mCACd,OAAO;YACL,CAAC,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,aAAa,CAAC;KACzE,CAAC,CAAC;IACH,IAAI,KAAK,CAAC,WAAW,KAAK,IAAI;QAC5B,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IAC5E,6EAA6E;IAC7E,6EAA6E;IAC7E,qEAAqE;IACrE,6EAA6E;IAC7E,yBAAyB;IACzB,EAAE;IACF,gEAAgE;IAChE,0EAA0E;IAC1E,uEAAuE;IACvE,0EAA0E;IAC1E,0EAA0E;IAC1E,2CAA2C;IAC3C,EAAE;IACF,0EAA0E;IAC1E,4EAA4E;IAC5E,yEAAyE;IACzE,6EAA6E;IAC7E,2EAA2E;IAC3E,kBAAkB;IAClB,MAAM,QAAQ,GAAQ,EAAE,CAAC;IACzB,MAAM,eAAe,GAAW,KAAK,GAAG,GAAG,GAAG,IAAI,CAAC;IACnD,IAAI,KAAK,GAAW,CAAC,CAAC;IACtB,KACE,IAAI,QAAQ,GAAG,CAAC,EAChB,QAAQ,CAAC,MAAM,KAAK,KAAK,IAAI,QAAQ,KAAK,eAAe,EACzD,QAAQ,EAAE,EACV,CAAC;QACD,MAAM,SAAS,GAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC3D,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,+BAAc,EAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;YACtE,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACzB,KAAK,GAAG,CAAC,CAAC;QACZ,CAAC;aAAM,IAAI,QAAQ,CAAC,MAAM,IAAI,OAAO,IAAI,EAAE,KAAK,KAAK,WAAW;YAAE,MAAM;IAC1E,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,GAAG,OAAO;QAC3B,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAC;IACJ,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AA3DW,QAAA,YAAY,GAAZ,YAAY,CA2DvB"}
|
|
@@ -4,6 +4,15 @@ import { _randomInteger } from "./_randomInteger.mjs";
|
|
|
4
4
|
const DEFAULT_MIN_ITEMS = 1;
|
|
5
5
|
const DEFAULT_RANGE = 5;
|
|
6
6
|
const DEFAULT_RECURSIVE_RANGE = 2;
|
|
7
|
+
/**
|
|
8
|
+
* Consecutive duplicates that end a unique draw once its floor is satisfied.
|
|
9
|
+
*
|
|
10
|
+
* The worst case a domain can still hide is one value left among a handful:
|
|
11
|
+
* with one of four remaining, sixty-four misses in a row is a `0.75 ** 64`
|
|
12
|
+
* event, about one in a hundred million. Below the floor this limit does not
|
|
13
|
+
* apply at all, so it can never fail a request the domain could satisfy.
|
|
14
|
+
*/
|
|
15
|
+
const STALE_LIMIT = 64;
|
|
7
16
|
const _randomArray = (props) => {
|
|
8
17
|
const defaultMinimum = props.recursive === true ? 0 : DEFAULT_MIN_ITEMS;
|
|
9
18
|
const minimum = props.minItems ?? Math.min(props.maxItems ?? defaultMinimum, defaultMinimum);
|
|
@@ -15,11 +24,15 @@ const _randomArray = (props) => {
|
|
|
15
24
|
if (props.uniqueItems !== true) return new Array(count).fill(null).map((_, i) => props.element(i, count));
|
|
16
25
|
const elements = [];
|
|
17
26
|
const maximumAttempts = count * 100 + 1e3;
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
let stale = 0;
|
|
28
|
+
for (let attempts = 0; elements.length !== count && attempts !== maximumAttempts; attempts++) {
|
|
20
29
|
const candidate = props.element(elements.length, count);
|
|
21
|
-
if (elements.every((element) => _isUniqueItems([element, candidate])))
|
|
30
|
+
if (elements.every((element) => _isUniqueItems([element, candidate]))) {
|
|
31
|
+
elements.push(candidate);
|
|
32
|
+
stale = 0;
|
|
33
|
+
} else if (elements.length >= minimum && ++stale === STALE_LIMIT) break;
|
|
22
34
|
}
|
|
35
|
+
if (elements.length < minimum) throw new Error("Unable to generate enough unique items; the element domain may be too small.");
|
|
23
36
|
return elements;
|
|
24
37
|
};
|
|
25
38
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomArray.mjs","names":[],"sources":["../../src/internal/_randomArray.ts"],"sourcesContent":["import type { OpenApi } from \"@typia/interface\";\n\nimport { _isUniqueItems } from \"./_isUniqueItems\";\nimport { _randomInteger } from \"./_randomInteger\";\n\nconst DEFAULT_MIN_ITEMS = 1;\nconst DEFAULT_RANGE = 5;\nconst DEFAULT_RECURSIVE_RANGE = 2;\n\nexport const _randomArray = <T>(\n props: Omit<OpenApi.IJsonSchema.IArray, \"items\"> & {\n element: (index: number, count: number) => T;\n recursive?: boolean;\n },\n) => {\n const defaultMinimum: number =\n props.recursive === true ? 0 : DEFAULT_MIN_ITEMS;\n const minimum: number =\n props.minItems ??\n Math.min(props.maxItems ?? defaultMinimum, defaultMinimum);\n const count: number = _randomInteger({\n type: \"integer\",\n minimum,\n maximum:\n props.maxItems ??\n minimum +\n (props.recursive === true ? DEFAULT_RECURSIVE_RANGE : DEFAULT_RANGE),\n });\n if (props.uniqueItems !== true)\n return new Array(count).fill(null).map((_, i) => props.element(i, count));\n const elements: T[] = [];\n const maximumAttempts: number = count * 100 + 1000;\n for (let attempts = 0
|
|
1
|
+
{"version":3,"file":"_randomArray.mjs","names":[],"sources":["../../src/internal/_randomArray.ts"],"sourcesContent":["import type { OpenApi } from \"@typia/interface\";\n\nimport { _isUniqueItems } from \"./_isUniqueItems\";\nimport { _randomInteger } from \"./_randomInteger\";\n\nconst DEFAULT_MIN_ITEMS = 1;\nconst DEFAULT_RANGE = 5;\nconst DEFAULT_RECURSIVE_RANGE = 2;\n\n/**\n * Consecutive duplicates that end a unique draw once its floor is satisfied.\n *\n * The worst case a domain can still hide is one value left among a handful:\n * with one of four remaining, sixty-four misses in a row is a `0.75 ** 64`\n * event, about one in a hundred million. Below the floor this limit does not\n * apply at all, so it can never fail a request the domain could satisfy.\n */\nconst STALE_LIMIT = 64;\n\nexport const _randomArray = <T>(\n props: Omit<OpenApi.IJsonSchema.IArray, \"items\"> & {\n element: (index: number, count: number) => T;\n recursive?: boolean;\n },\n) => {\n const defaultMinimum: number =\n props.recursive === true ? 0 : DEFAULT_MIN_ITEMS;\n const minimum: number =\n props.minItems ??\n Math.min(props.maxItems ?? defaultMinimum, defaultMinimum);\n const count: number = _randomInteger({\n type: \"integer\",\n minimum,\n maximum:\n props.maxItems ??\n minimum +\n (props.recursive === true ? DEFAULT_RECURSIVE_RANGE : DEFAULT_RANGE),\n });\n if (props.uniqueItems !== true)\n return new Array(count).fill(null).map((_, i) => props.element(i, count));\n // How many distinct values the element can take is not knowable from here --\n // `element` is a closure over whatever the transform emitted, from `boolean`\n // to a recursive object -- so the count above is a preference, not a\n // contract. Draw until the budget says the domain has nothing new left, then\n // keep what was reached.\n //\n // Failing on that budget instead is what made `Array<boolean> &\n // UniqueItems` throw on two draws in three: `[true, false]` satisfies the\n // declaration at every count, and a count of five is unreachable for a\n // domain of two however many times it is redrawn. Only a result below the\n // floor is a real failure, which is still the honest outcome for a window\n // like `MinItems<3>` over a domain of two.\n //\n // Below the floor the whole budget is spent, because stopping early there\n // would fail a request the domain can still satisfy. Above it every further\n // attempt is only buying length, so a run of `STALE_LIMIT` duplicates is\n // taken as the domain saying it has nothing left. Without that, each nesting\n // level of a small-domain unique array multiplies the full budget into the\n // level above it.\n const elements: T[] = [];\n const maximumAttempts: number = count * 100 + 1000;\n let stale: number = 0;\n for (\n let attempts = 0;\n elements.length !== count && attempts !== maximumAttempts;\n attempts++\n ) {\n const candidate: T = props.element(elements.length, count);\n if (elements.every((element) => _isUniqueItems([element, candidate]))) {\n elements.push(candidate);\n stale = 0;\n } else if (elements.length >= minimum && ++stale === STALE_LIMIT) break;\n }\n if (elements.length < minimum)\n throw new Error(\n \"Unable to generate enough unique items; the element domain may be too small.\",\n );\n return elements;\n};\n"],"mappings":";;;AAKA,MAAM,oBAAoB;AAC1B,MAAM,gBAAgB;AACtB,MAAM,0BAA0B;;;;;;;;;AAUhC,MAAM,cAAc;AAEpB,MAAa,gBACX,UAIG;CACH,MAAM,iBACJ,MAAM,cAAc,OAAO,IAAI;CACjC,MAAM,UACJ,MAAM,YACN,KAAK,IAAI,MAAM,YAAY,gBAAgB,cAAc;CAC3D,MAAM,QAAgB,eAAe;EACnC,MAAM;EACN;EACA,SACE,MAAM,YACN,WACG,MAAM,cAAc,OAAO,0BAA0B;CAC5D,CAAC;CACD,IAAI,MAAM,gBAAgB,MACxB,OAAO,IAAI,MAAM,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,GAAG,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC;CAoB1E,MAAM,WAAgB,CAAC;CACvB,MAAM,kBAA0B,QAAQ,MAAM;CAC9C,IAAI,QAAgB;CACpB,KACE,IAAI,WAAW,GACf,SAAS,WAAW,SAAS,aAAa,iBAC1C,YACA;EACA,MAAM,YAAe,MAAM,QAAQ,SAAS,QAAQ,KAAK;EACzD,IAAI,SAAS,OAAO,YAAY,eAAe,CAAC,SAAS,SAAS,CAAC,CAAC,GAAG;GACrE,SAAS,KAAK,SAAS;GACvB,QAAQ;EACV,OAAO,IAAI,SAAS,UAAU,WAAW,EAAE,UAAU,aAAa;CACpE;CACA,IAAI,SAAS,SAAS,SACpB,MAAM,IAAI,MACR,8EACF;CACF,OAAO;AACT"}
|
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._randomFormatByte = void 0;
|
|
4
|
+
const _randomInteger_1 = require("./_randomInteger");
|
|
4
5
|
const _randomStringLength_1 = require("./_randomStringLength");
|
|
5
|
-
const
|
|
6
|
+
const __randomComposition_1 = require("./private/__randomComposition");
|
|
7
|
+
const _randomFormatByte = (props) => {
|
|
8
|
+
// Base64 encodes three bytes as four characters, so a valid length is always
|
|
9
|
+
// a multiple of four; an unconstrained draw spends between four and twelve
|
|
10
|
+
// groups, and a constrained one raises the window to the first multiple it
|
|
11
|
+
// contains and steps by four from there.
|
|
12
|
+
if ((props === null || props === void 0 ? void 0 : props.minLength) === undefined && (props === null || props === void 0 ? void 0 : props.maxLength) === undefined)
|
|
13
|
+
return (0, __randomComposition_1.__randomBase64)(4 *
|
|
14
|
+
(0, _randomInteger_1._randomInteger)({
|
|
15
|
+
type: "integer",
|
|
16
|
+
minimum: DEFAULT_GROUP_MIN,
|
|
17
|
+
maximum: DEFAULT_GROUP_MAX,
|
|
18
|
+
}));
|
|
19
|
+
const window = (0, _randomStringLength_1._randomLengthWindow)(props, { minimum: 0, spread: 16 });
|
|
20
|
+
const low = Math.ceil(window.low / 4) * 4;
|
|
21
|
+
if (low > window.high)
|
|
22
|
+
throw new Error(_randomStringLength_1._RANDOM_LENGTH_ERROR);
|
|
23
|
+
const length = low +
|
|
24
|
+
4 *
|
|
25
|
+
(0, _randomStringLength_1._randomLengthPick)({
|
|
26
|
+
low: 0,
|
|
27
|
+
high: Math.floor((window.high - low) / 4),
|
|
28
|
+
});
|
|
29
|
+
return (0, __randomComposition_1.__randomBase64)(length);
|
|
30
|
+
};
|
|
6
31
|
exports._randomFormatByte = _randomFormatByte;
|
|
7
|
-
const
|
|
32
|
+
const DEFAULT_GROUP_MIN = 4;
|
|
33
|
+
const DEFAULT_GROUP_MAX = 12;
|
|
8
34
|
//# sourceMappingURL=_randomFormatByte.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatByte.js","sourceRoot":"","sources":["../../src/internal/_randomFormatByte.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"_randomFormatByte.js","sourceRoot":"","sources":["../../src/internal/_randomFormatByte.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAClD,+DAK+B;AAC/B,uEAA+D;AAExD,MAAM,iBAAiB,GAAG,CAAC,KAAqB,EAAU,EAAE;IACjE,6EAA6E;IAC7E,2EAA2E;IAC3E,2EAA2E;IAC3E,yCAAyC;IACzC,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS;QAClE,OAAO,IAAA,oCAAc,EACnB,CAAC;YACC,IAAA,+BAAc,EAAC;gBACb,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,iBAAiB;gBAC1B,OAAO,EAAE,iBAAiB;aAC3B,CAAC,CACL,CAAC;IACJ,MAAM,MAAM,GAAG,IAAA,yCAAmB,EAAC,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IACtE,MAAM,GAAG,GAAW,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAClD,IAAI,GAAG,GAAG,MAAM,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,0CAAoB,CAAC,CAAC;IAC7D,MAAM,MAAM,GACV,GAAG;QACH,CAAC;YACC,IAAA,uCAAiB,EAAC;gBAChB,GAAG,EAAE,CAAC;gBACN,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;aAC1C,CAAC,CAAC;IACP,OAAO,IAAA,oCAAc,EAAC,MAAM,CAAC,CAAC;AAChC,CAAC,CAAC;AAzBW,QAAA,iBAAiB,GAAjB,iBAAiB,CAyB5B;AAEF,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,iBAAiB,GAAG,EAAE,CAAC"}
|
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _randomInteger } from "./_randomInteger.mjs";
|
|
2
|
+
import { _RANDOM_LENGTH_ERROR, _randomLengthPick, _randomLengthWindow } from "./_randomStringLength.mjs";
|
|
3
|
+
import { __randomBase64 } from "./private/__randomComposition.mjs";
|
|
2
4
|
//#region src/internal/_randomFormatByte.ts
|
|
3
|
-
const _randomFormatByte = (props) =>
|
|
4
|
-
|
|
5
|
+
const _randomFormatByte = (props) => {
|
|
6
|
+
if (props?.minLength === void 0 && props?.maxLength === void 0) return __randomBase64(4 * _randomInteger({
|
|
7
|
+
type: "integer",
|
|
8
|
+
minimum: DEFAULT_GROUP_MIN,
|
|
9
|
+
maximum: DEFAULT_GROUP_MAX
|
|
10
|
+
}));
|
|
11
|
+
const window = _randomLengthWindow(props, {
|
|
12
|
+
minimum: 0,
|
|
13
|
+
spread: 16
|
|
14
|
+
});
|
|
15
|
+
const low = Math.ceil(window.low / 4) * 4;
|
|
16
|
+
if (low > window.high) throw new Error(_RANDOM_LENGTH_ERROR);
|
|
17
|
+
return __randomBase64(low + 4 * _randomLengthPick({
|
|
18
|
+
low: 0,
|
|
19
|
+
high: Math.floor((window.high - low) / 4)
|
|
20
|
+
}));
|
|
21
|
+
};
|
|
22
|
+
const DEFAULT_GROUP_MIN = 4;
|
|
23
|
+
const DEFAULT_GROUP_MAX = 12;
|
|
5
24
|
//#endregion
|
|
6
25
|
export { _randomFormatByte };
|
|
7
26
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatByte.mjs","names":[],"sources":["../../src/internal/_randomFormatByte.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"_randomFormatByte.mjs","names":[],"sources":["../../src/internal/_randomFormatByte.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport {\n _ILengthProps,\n _RANDOM_LENGTH_ERROR,\n _randomLengthPick,\n _randomLengthWindow,\n} from \"./_randomStringLength\";\nimport { __randomBase64 } from \"./private/__randomComposition\";\n\nexport const _randomFormatByte = (props?: _ILengthProps): string => {\n // Base64 encodes three bytes as four characters, so a valid length is always\n // a multiple of four; an unconstrained draw spends between four and twelve\n // groups, and a constrained one raises the window to the first multiple it\n // contains and steps by four from there.\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return __randomBase64(\n 4 *\n _randomInteger({\n type: \"integer\",\n minimum: DEFAULT_GROUP_MIN,\n maximum: DEFAULT_GROUP_MAX,\n }),\n );\n const window = _randomLengthWindow(props, { minimum: 0, spread: 16 });\n const low: number = Math.ceil(window.low / 4) * 4;\n if (low > window.high) throw new Error(_RANDOM_LENGTH_ERROR);\n const length: number =\n low +\n 4 *\n _randomLengthPick({\n low: 0,\n high: Math.floor((window.high - low) / 4),\n });\n return __randomBase64(length);\n};\n\nconst DEFAULT_GROUP_MIN = 4;\nconst DEFAULT_GROUP_MAX = 12;\n"],"mappings":";;;;AASA,MAAa,qBAAqB,UAAkC;CAKlE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,eACL,IACE,eAAe;EACb,MAAM;EACN,SAAS;EACT,SAAS;CACX,CAAC,CACL;CACF,MAAM,SAAS,oBAAoB,OAAO;EAAE,SAAS;EAAG,QAAQ;CAAG,CAAC;CACpE,MAAM,MAAc,KAAK,KAAK,OAAO,MAAM,CAAC,IAAI;CAChD,IAAI,MAAM,OAAO,MAAM,MAAM,IAAI,MAAM,oBAAoB;CAQ3D,OAAO,eANL,MACA,IACE,kBAAkB;EAChB,KAAK;EACL,MAAM,KAAK,OAAO,OAAO,OAAO,OAAO,CAAC;CAC1C,CAAC,CACuB;AAC9B;AAEA,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
minLength?: number;
|
|
5
|
-
maxLength?: number;
|
|
6
|
-
}) => string;
|
|
1
|
+
import { _ILengthProps } from "./_randomStringLength";
|
|
2
|
+
import { __IEpochProps } from "./private/__randomEpoch";
|
|
3
|
+
export declare const _randomFormatDate: (props?: __IEpochProps & _ILengthProps) => string;
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._randomFormatDate = void 0;
|
|
4
|
-
const _randomInteger_1 = require("./_randomInteger");
|
|
5
4
|
const _randomStringLength_1 = require("./_randomStringLength");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
minimum: (_a = props === null || props === void 0 ? void 0 : props.minimum) !== null && _a !== void 0 ? _a : 0,
|
|
9
|
-
maximum: ((_b = props === null || props === void 0 ? void 0 : props.maximum) !== null && _b !== void 0 ? _b : (props === null || props === void 0 ? void 0 : props.minimum) === undefined)
|
|
10
|
-
? Date.now()
|
|
11
|
-
: props.minimum + 365 * 24 * 60 * 60 * 1000,
|
|
12
|
-
}))
|
|
13
|
-
.toISOString()
|
|
14
|
-
.substring(0, 10); });
|
|
5
|
+
const __randomEpoch_1 = require("./private/__randomEpoch");
|
|
6
|
+
const _randomFormatDate = (props) => (0, _randomStringLength_1._randomFormatLength)(props, () => new Date((0, __randomEpoch_1.__randomEpoch)(props)).toISOString().substring(0, 10));
|
|
15
7
|
exports._randomFormatDate = _randomFormatDate;
|
|
16
8
|
//# sourceMappingURL=_randomFormatDate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatDate.js","sourceRoot":"","sources":["../../src/internal/_randomFormatDate.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"_randomFormatDate.js","sourceRoot":"","sources":["../../src/internal/_randomFormatDate.ts"],"names":[],"mappings":";;;AAAA,+DAA2E;AAC3E,2DAAuE;AAEhE,MAAM,iBAAiB,GAAG,CAAC,KAAqC,EAAE,EAAE,CACzE,IAAA,yCAAmB,EAAC,KAAK,EAAE,GAAG,EAAE,CAC9B,IAAI,IAAI,CAAC,IAAA,6BAAa,EAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAC9D,CAAC;AAHS,QAAA,iBAAiB,GAAjB,iBAAiB,CAG1B"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { _randomInteger } from "./_randomInteger.mjs";
|
|
2
1
|
import { _randomFormatLength } from "./_randomStringLength.mjs";
|
|
2
|
+
import { __randomEpoch } from "./private/__randomEpoch.mjs";
|
|
3
3
|
//#region src/internal/_randomFormatDate.ts
|
|
4
|
-
const _randomFormatDate = (props) => _randomFormatLength(props, () => new Date(
|
|
5
|
-
type: "integer",
|
|
6
|
-
minimum: props?.minimum ?? 0,
|
|
7
|
-
maximum: props?.maximum ?? props?.minimum === void 0 ? Date.now() : props.minimum + 365 * 24 * 60 * 60 * 1e3
|
|
8
|
-
})).toISOString().substring(0, 10));
|
|
4
|
+
const _randomFormatDate = (props) => _randomFormatLength(props, () => new Date(__randomEpoch(props)).toISOString().substring(0, 10));
|
|
9
5
|
//#endregion
|
|
10
6
|
export { _randomFormatDate };
|
|
11
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatDate.mjs","names":[],"sources":["../../src/internal/_randomFormatDate.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"_randomFormatDate.mjs","names":[],"sources":["../../src/internal/_randomFormatDate.ts"],"sourcesContent":["import { _ILengthProps, _randomFormatLength } from \"./_randomStringLength\";\nimport { __IEpochProps, __randomEpoch } from \"./private/__randomEpoch\";\n\nexport const _randomFormatDate = (props?: __IEpochProps & _ILengthProps) =>\n _randomFormatLength(props, () =>\n new Date(__randomEpoch(props)).toISOString().substring(0, 10),\n );\n"],"mappings":";;;AAGA,MAAa,qBAAqB,UAChC,oBAAoB,aAClB,IAAI,KAAK,cAAc,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,UAAU,GAAG,EAAE,CAC9D"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
minLength?: number;
|
|
5
|
-
maxLength?: number;
|
|
6
|
-
}) => string;
|
|
1
|
+
import { _ILengthProps } from "./_randomStringLength";
|
|
2
|
+
import { __IEpochProps } from "./private/__randomEpoch";
|
|
3
|
+
export declare const _randomFormatDatetime: (props?: __IEpochProps & _ILengthProps) => string;
|
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._randomFormatDatetime = void 0;
|
|
4
|
-
const _randomInteger_1 = require("./_randomInteger");
|
|
5
4
|
const _randomStringLength_1 = require("./_randomStringLength");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const __randomComposition_1 = require("./private/__randomComposition");
|
|
6
|
+
const __randomEpoch_1 = require("./private/__randomEpoch");
|
|
7
|
+
const _randomFormatDatetime = (props) => {
|
|
8
|
+
const instant = () => new Date((0, __randomEpoch_1.__randomEpoch)(props)).toISOString();
|
|
9
|
+
if ((props === null || props === void 0 ? void 0 : props.minLength) === undefined && (props === null || props === void 0 ? void 0 : props.maxLength) === undefined)
|
|
10
|
+
return instant();
|
|
11
|
+
// `YYYY-MM-DDTHH:MM:SS` plus `Z` is the shortest instant, and a fractional
|
|
12
|
+
// second grows it one digit at a time. Because that fraction needs both a dot
|
|
13
|
+
// and at least one digit, 21 is the single length between the two forms that
|
|
14
|
+
// no instant can have.
|
|
15
|
+
const window = (0, _randomStringLength_1._randomLengthWindow)(props, {
|
|
16
|
+
minimum: SECONDS + 1,
|
|
17
|
+
spread: 8,
|
|
18
|
+
});
|
|
19
|
+
let length = (0, _randomStringLength_1._randomLengthPick)(window);
|
|
20
|
+
if (length === SECONDS + 2)
|
|
21
|
+
length = window.high >= SECONDS + 3 ? SECONDS + 3 : SECONDS + 1;
|
|
22
|
+
if (length < window.low || length > window.high)
|
|
23
|
+
throw new Error(_randomStringLength_1._RANDOM_LENGTH_ERROR);
|
|
24
|
+
const base = instant().substring(0, SECONDS);
|
|
25
|
+
return length === SECONDS + 1
|
|
26
|
+
? `${base}Z`
|
|
27
|
+
: `${base}.${(0, __randomComposition_1.__randomDigits)(length - SECONDS - 2)}Z`;
|
|
28
|
+
};
|
|
13
29
|
exports._randomFormatDatetime = _randomFormatDatetime;
|
|
30
|
+
const SECONDS = "0000-00-00T00:00:00".length;
|
|
14
31
|
//# sourceMappingURL=_randomFormatDatetime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatDatetime.js","sourceRoot":"","sources":["../../src/internal/_randomFormatDatetime.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"_randomFormatDatetime.js","sourceRoot":"","sources":["../../src/internal/_randomFormatDatetime.ts"],"names":[],"mappings":";;;AAAA,+DAK+B;AAC/B,uEAA+D;AAC/D,2DAAuE;AAEhE,MAAM,qBAAqB,GAAG,CACnC,KAAqC,EACrC,EAAE;IACF,MAAM,OAAO,GAAG,GAAW,EAAE,CAAC,IAAI,IAAI,CAAC,IAAA,6BAAa,EAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAC3E,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS;QAClE,OAAO,OAAO,EAAE,CAAC;IACnB,2EAA2E;IAC3E,8EAA8E;IAC9E,6EAA6E;IAC7E,uBAAuB;IACvB,MAAM,MAAM,GAAG,IAAA,yCAAmB,EAAC,KAAK,EAAE;QACxC,OAAO,EAAE,OAAO,GAAG,CAAC;QACpB,MAAM,EAAE,CAAC;KACV,CAAC,CAAC;IACH,IAAI,MAAM,GAAW,IAAA,uCAAiB,EAAC,MAAM,CAAC,CAAC;IAC/C,IAAI,MAAM,KAAK,OAAO,GAAG,CAAC;QACxB,MAAM,GAAG,MAAM,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC;IAClE,IAAI,MAAM,GAAG,MAAM,CAAC,GAAG,IAAI,MAAM,GAAG,MAAM,CAAC,IAAI;QAC7C,MAAM,IAAI,KAAK,CAAC,0CAAoB,CAAC,CAAC;IACxC,MAAM,IAAI,GAAW,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACrD,OAAO,MAAM,KAAK,OAAO,GAAG,CAAC;QAC3B,CAAC,CAAC,GAAG,IAAI,GAAG;QACZ,CAAC,CAAC,GAAG,IAAI,IAAI,IAAA,oCAAc,EAAC,MAAM,GAAG,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC;AACzD,CAAC,CAAC;AAvBW,QAAA,qBAAqB,GAArB,qBAAqB,CAuBhC;AAEF,MAAM,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC"}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { _RANDOM_LENGTH_ERROR, _randomLengthPick, _randomLengthWindow } from "./_randomStringLength.mjs";
|
|
2
|
+
import { __randomDigits } from "./private/__randomComposition.mjs";
|
|
3
|
+
import { __randomEpoch } from "./private/__randomEpoch.mjs";
|
|
3
4
|
//#region src/internal/_randomFormatDatetime.ts
|
|
4
|
-
const _randomFormatDatetime = (props) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const _randomFormatDatetime = (props) => {
|
|
6
|
+
const instant = () => new Date(__randomEpoch(props)).toISOString();
|
|
7
|
+
if (props?.minLength === void 0 && props?.maxLength === void 0) return instant();
|
|
8
|
+
const window = _randomLengthWindow(props, {
|
|
9
|
+
minimum: SECONDS + 1,
|
|
10
|
+
spread: 8
|
|
11
|
+
});
|
|
12
|
+
let length = _randomLengthPick(window);
|
|
13
|
+
if (length === SECONDS + 2) length = window.high >= SECONDS + 3 ? SECONDS + 3 : SECONDS + 1;
|
|
14
|
+
if (length < window.low || length > window.high) throw new Error(_RANDOM_LENGTH_ERROR);
|
|
15
|
+
const base = instant().substring(0, SECONDS);
|
|
16
|
+
return length === SECONDS + 1 ? `${base}Z` : `${base}.${__randomDigits(length - SECONDS - 2)}Z`;
|
|
17
|
+
};
|
|
18
|
+
const SECONDS = 19;
|
|
9
19
|
//#endregion
|
|
10
20
|
export { _randomFormatDatetime };
|
|
11
21
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatDatetime.mjs","names":[],"sources":["../../src/internal/_randomFormatDatetime.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"_randomFormatDatetime.mjs","names":[],"sources":["../../src/internal/_randomFormatDatetime.ts"],"sourcesContent":["import {\n _ILengthProps,\n _RANDOM_LENGTH_ERROR,\n _randomLengthPick,\n _randomLengthWindow,\n} from \"./_randomStringLength\";\nimport { __randomDigits } from \"./private/__randomComposition\";\nimport { __IEpochProps, __randomEpoch } from \"./private/__randomEpoch\";\n\nexport const _randomFormatDatetime = (\n props?: __IEpochProps & _ILengthProps,\n) => {\n const instant = (): string => new Date(__randomEpoch(props)).toISOString();\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return instant();\n // `YYYY-MM-DDTHH:MM:SS` plus `Z` is the shortest instant, and a fractional\n // second grows it one digit at a time. Because that fraction needs both a dot\n // and at least one digit, 21 is the single length between the two forms that\n // no instant can have.\n const window = _randomLengthWindow(props, {\n minimum: SECONDS + 1,\n spread: 8,\n });\n let length: number = _randomLengthPick(window);\n if (length === SECONDS + 2)\n length = window.high >= SECONDS + 3 ? SECONDS + 3 : SECONDS + 1;\n if (length < window.low || length > window.high)\n throw new Error(_RANDOM_LENGTH_ERROR);\n const base: string = instant().substring(0, SECONDS);\n return length === SECONDS + 1\n ? `${base}Z`\n : `${base}.${__randomDigits(length - SECONDS - 2)}Z`;\n};\n\nconst SECONDS = \"0000-00-00T00:00:00\".length;\n"],"mappings":";;;;AASA,MAAa,yBACX,UACG;CACH,MAAM,gBAAwB,IAAI,KAAK,cAAc,KAAK,CAAC,CAAC,CAAC,YAAY;CACzE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,QAAQ;CAKjB,MAAM,SAAS,oBAAoB,OAAO;EACxC,SAAS,UAAU;EACnB,QAAQ;CACV,CAAC;CACD,IAAI,SAAiB,kBAAkB,MAAM;CAC7C,IAAI,WAAW,UAAU,GACvB,SAAS,OAAO,QAAQ,UAAU,IAAI,UAAU,IAAI,UAAU;CAChE,IAAI,SAAS,OAAO,OAAO,SAAS,OAAO,MACzC,MAAM,IAAI,MAAM,oBAAoB;CACtC,MAAM,OAAe,QAAQ,CAAC,CAAC,UAAU,GAAG,OAAO;CACnD,OAAO,WAAW,UAAU,IACxB,GAAG,KAAK,KACR,GAAG,KAAK,GAAG,eAAe,SAAS,UAAU,CAAC,EAAE;AACtD;AAEA,MAAM,UAAU"}
|
|
@@ -3,22 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports._randomFormatDuration = void 0;
|
|
4
4
|
const _randomInteger_1 = require("./_randomInteger");
|
|
5
5
|
const _randomStringLength_1 = require("./_randomStringLength");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
const __randomComposition_1 = require("./private/__randomComposition");
|
|
7
|
+
const _randomFormatDuration = (props) => {
|
|
8
|
+
if ((props === null || props === void 0 ? void 0 : props.minLength) === undefined && (props === null || props === void 0 ? void 0 : props.maxLength) === undefined) {
|
|
9
|
+
const period = durate([
|
|
10
|
+
["Y", random(0, 100)],
|
|
11
|
+
["M", random(0, 12)],
|
|
12
|
+
["D", random(0, 31)],
|
|
13
|
+
]);
|
|
14
|
+
const time = durate([
|
|
15
|
+
["H", random(0, 24)],
|
|
16
|
+
["M", random(0, 60)],
|
|
17
|
+
["S", random(0, 60)],
|
|
18
|
+
]);
|
|
19
|
+
if (period.length + time.length === 0)
|
|
20
|
+
return "PT0S";
|
|
21
|
+
return `P${period}${time.length ? "T" : ""}${time}`;
|
|
22
|
+
}
|
|
23
|
+
// A single designator carries an unbounded digit count, so `P<n>Y` expresses
|
|
24
|
+
// every length from three upward and `P1Y` is the shortest duration there is.
|
|
25
|
+
const length = (0, _randomStringLength_1._randomLengthPick)((0, _randomStringLength_1._randomLengthWindow)(props, { minimum: MINIMUM, spread: 6 }));
|
|
26
|
+
return `P${(0, __randomComposition_1.__randomNumeric)(length - MINIMUM + 1)}Y`;
|
|
27
|
+
};
|
|
21
28
|
exports._randomFormatDuration = _randomFormatDuration;
|
|
29
|
+
const MINIMUM = "P1Y".length;
|
|
22
30
|
const durate = (elements) => elements
|
|
23
31
|
.filter(([_unit, value]) => value !== 0)
|
|
24
32
|
.map(([unit, value]) => `${value}${unit}`)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatDuration.js","sourceRoot":"","sources":["../../src/internal/_randomFormatDuration.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAClD,+
|
|
1
|
+
{"version":3,"file":"_randomFormatDuration.js","sourceRoot":"","sources":["../../src/internal/_randomFormatDuration.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAClD,+DAI+B;AAC/B,uEAAgE;AAEzD,MAAM,qBAAqB,GAAG,CAAC,KAAqB,EAAU,EAAE;IACrE,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,EAAE,CAAC;QACrE,MAAM,MAAM,GAAW,MAAM,CAAC;YAC5B,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YACrB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACpB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;SACrB,CAAC,CAAC;QACH,MAAM,IAAI,GAAW,MAAM,CAAC;YAC1B,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACpB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACpB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;SACrB,CAAC,CAAC;QACH,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,MAAM,CAAC;QACrD,OAAO,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC;IACtD,CAAC;IACD,6EAA6E;IAC7E,8EAA8E;IAC9E,MAAM,MAAM,GAAW,IAAA,uCAAiB,EACtC,IAAA,yCAAmB,EAAC,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAC5D,CAAC;IACF,OAAO,IAAI,IAAA,qCAAe,EAAC,MAAM,GAAG,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC;AACtD,CAAC,CAAC;AArBW,QAAA,qBAAqB,GAArB,qBAAqB,CAqBhC;AAEF,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;AAE7B,MAAM,MAAM,GAAG,CAAC,QAA4B,EAAE,EAAE,CAC9C,QAAQ;KACL,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC;KACvC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG,IAAI,EAAE,CAAC;KACzC,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,MAAM,MAAM,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE,CAClD,IAAA,+BAAc,EAAC;IACb,IAAI,EAAE,SAAS;IACf,OAAO;IACP,OAAO;CACR,CAAC,CAAC"}
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { _randomInteger } from "./_randomInteger.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { _randomLengthPick, _randomLengthWindow } from "./_randomStringLength.mjs";
|
|
3
|
+
import { __randomNumeric } from "./private/__randomComposition.mjs";
|
|
3
4
|
//#region src/internal/_randomFormatDuration.ts
|
|
4
|
-
const _randomFormatDuration = (props) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
5
|
+
const _randomFormatDuration = (props) => {
|
|
6
|
+
if (props?.minLength === void 0 && props?.maxLength === void 0) {
|
|
7
|
+
const period = durate([
|
|
8
|
+
["Y", random(0, 100)],
|
|
9
|
+
["M", random(0, 12)],
|
|
10
|
+
["D", random(0, 31)]
|
|
11
|
+
]);
|
|
12
|
+
const time = durate([
|
|
13
|
+
["H", random(0, 24)],
|
|
14
|
+
["M", random(0, 60)],
|
|
15
|
+
["S", random(0, 60)]
|
|
16
|
+
]);
|
|
17
|
+
if (period.length + time.length === 0) return "PT0S";
|
|
18
|
+
return `P${period}${time.length ? "T" : ""}${time}`;
|
|
19
|
+
}
|
|
20
|
+
return `P${__randomNumeric(_randomLengthPick(_randomLengthWindow(props, {
|
|
21
|
+
minimum: MINIMUM,
|
|
22
|
+
spread: 6
|
|
23
|
+
})) - MINIMUM + 1)}Y`;
|
|
24
|
+
};
|
|
25
|
+
const MINIMUM = 3;
|
|
18
26
|
const durate = (elements) => elements.filter(([_unit, value]) => value !== 0).map(([unit, value]) => `${value}${unit}`).join("");
|
|
19
27
|
const random = (minimum, maximum) => _randomInteger({
|
|
20
28
|
type: "integer",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatDuration.mjs","names":[],"sources":["../../src/internal/_randomFormatDuration.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport {
|
|
1
|
+
{"version":3,"file":"_randomFormatDuration.mjs","names":[],"sources":["../../src/internal/_randomFormatDuration.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport {\n _ILengthProps,\n _randomLengthPick,\n _randomLengthWindow,\n} from \"./_randomStringLength\";\nimport { __randomNumeric } from \"./private/__randomComposition\";\n\nexport const _randomFormatDuration = (props?: _ILengthProps): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined) {\n const period: string = durate([\n [\"Y\", random(0, 100)],\n [\"M\", random(0, 12)],\n [\"D\", random(0, 31)],\n ]);\n const time: string = durate([\n [\"H\", random(0, 24)],\n [\"M\", random(0, 60)],\n [\"S\", random(0, 60)],\n ]);\n if (period.length + time.length === 0) return \"PT0S\";\n return `P${period}${time.length ? \"T\" : \"\"}${time}`;\n }\n // A single designator carries an unbounded digit count, so `P<n>Y` expresses\n // every length from three upward and `P1Y` is the shortest duration there is.\n const length: number = _randomLengthPick(\n _randomLengthWindow(props, { minimum: MINIMUM, spread: 6 }),\n );\n return `P${__randomNumeric(length - MINIMUM + 1)}Y`;\n};\n\nconst MINIMUM = \"P1Y\".length;\n\nconst durate = (elements: [string, number][]) =>\n elements\n .filter(([_unit, value]) => value !== 0)\n .map(([unit, value]) => `${value}${unit}`)\n .join(\"\");\nconst random = (minimum: number, maximum: number) =>\n _randomInteger({\n type: \"integer\",\n minimum,\n maximum,\n });\n"],"mappings":";;;;AAQA,MAAa,yBAAyB,UAAkC;CACtE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GAAW;EACpE,MAAM,SAAiB,OAAO;GAC5B,CAAC,KAAK,OAAO,GAAG,GAAG,CAAC;GACpB,CAAC,KAAK,OAAO,GAAG,EAAE,CAAC;GACnB,CAAC,KAAK,OAAO,GAAG,EAAE,CAAC;EACrB,CAAC;EACD,MAAM,OAAe,OAAO;GAC1B,CAAC,KAAK,OAAO,GAAG,EAAE,CAAC;GACnB,CAAC,KAAK,OAAO,GAAG,EAAE,CAAC;GACnB,CAAC,KAAK,OAAO,GAAG,EAAE,CAAC;EACrB,CAAC;EACD,IAAI,OAAO,SAAS,KAAK,WAAW,GAAG,OAAO;EAC9C,OAAO,IAAI,SAAS,KAAK,SAAS,MAAM,KAAK;CAC/C;CAMA,OAAO,IAAI,gBAHY,kBACrB,oBAAoB,OAAO;EAAE,SAAS;EAAS,QAAQ;CAAE,CAAC,CAE5B,IAAI,UAAU,CAAC,EAAE;AACnD;AAEA,MAAM,UAAU;AAEhB,MAAM,UAAU,aACd,SACG,QAAQ,CAAC,OAAO,WAAW,UAAU,CAAC,CAAC,CACvC,KAAK,CAAC,MAAM,WAAW,GAAG,QAAQ,MAAM,CAAC,CACzC,KAAK,EAAE;AACZ,MAAM,UAAU,SAAiB,YAC/B,eAAe;CACb,MAAM;CACN;CACA;AACF,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { _ILengthProps } from "./_randomStringLength";
|
|
|
2
2
|
export declare const _randomFormatHostname: (props?: _ILengthProps) => string;
|
|
3
3
|
/**
|
|
4
4
|
* Builds dot-joined hostname labels totaling exactly `length` characters, each
|
|
5
|
-
* label within 63 chars. Shared with the idn-hostname generator, which
|
|
6
|
-
*
|
|
5
|
+
* label within 63 chars. Shared with the idn-hostname generator, which realizes
|
|
6
|
+
* its length the same way since #2317 gave the two formats one structure.
|
|
7
7
|
*/
|
|
8
8
|
export declare const _randomHostnameLabels: (length: number) => string;
|
|
@@ -26,8 +26,8 @@ const pickLength = (props) => {
|
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
28
|
* Builds dot-joined hostname labels totaling exactly `length` characters, each
|
|
29
|
-
* label within 63 chars. Shared with the idn-hostname generator, which
|
|
30
|
-
*
|
|
29
|
+
* label within 63 chars. Shared with the idn-hostname generator, which realizes
|
|
30
|
+
* its length the same way since #2317 gave the two formats one structure.
|
|
31
31
|
*/
|
|
32
32
|
const _randomHostnameLabels = (length) => {
|
|
33
33
|
const parts = [];
|
|
@@ -20,8 +20,8 @@ const pickLength = (props) => {
|
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
22
|
* Builds dot-joined hostname labels totaling exactly `length` characters, each
|
|
23
|
-
* label within 63 chars. Shared with the idn-hostname generator, which
|
|
24
|
-
*
|
|
23
|
+
* label within 63 chars. Shared with the idn-hostname generator, which realizes
|
|
24
|
+
* its length the same way since #2317 gave the two formats one structure.
|
|
25
25
|
*/
|
|
26
26
|
const _randomHostnameLabels = (length) => {
|
|
27
27
|
const parts = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatHostname.mjs","names":[],"sources":["../../src/internal/_randomFormatHostname.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\nimport { _ILengthProps } from \"./_randomStringLength\";\n\nexport const _randomFormatHostname = (props?: _ILengthProps): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return `${random(10)}.${random(3)}`;\n // A hostname is dot-joined labels of 1..63 chars whose total is capped at 253,\n // so the requested length is realized by splitting it across enough labels.\n return _randomHostnameLabels(pickLength(props));\n};\n\nconst MAX_TOTAL = 253;\nconst MAX_LABEL = 63;\n\nconst pickLength = (props: _ILengthProps): number => {\n let low: number = props.minLength === undefined ? 1 : props.minLength;\n if (low < 1) low = 1;\n const high: number =\n props.maxLength === undefined\n ? Math.min(MAX_TOTAL, low + 14)\n : Math.min(MAX_TOTAL, props.maxLength);\n if (high < low)\n throw new Error(\n \"unable to generate a random hostname satisfying both the format and the length constraints.\",\n );\n return _randomInteger({ type: \"integer\", minimum: low, maximum: high });\n};\n\n/**\n * Builds dot-joined hostname labels totaling exactly `length` characters, each\n * label within 63 chars. Shared with the idn-hostname generator, which
|
|
1
|
+
{"version":3,"file":"_randomFormatHostname.mjs","names":[],"sources":["../../src/internal/_randomFormatHostname.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\nimport { _ILengthProps } from \"./_randomStringLength\";\n\nexport const _randomFormatHostname = (props?: _ILengthProps): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return `${random(10)}.${random(3)}`;\n // A hostname is dot-joined labels of 1..63 chars whose total is capped at 253,\n // so the requested length is realized by splitting it across enough labels.\n return _randomHostnameLabels(pickLength(props));\n};\n\nconst MAX_TOTAL = 253;\nconst MAX_LABEL = 63;\n\nconst pickLength = (props: _ILengthProps): number => {\n let low: number = props.minLength === undefined ? 1 : props.minLength;\n if (low < 1) low = 1;\n const high: number =\n props.maxLength === undefined\n ? Math.min(MAX_TOTAL, low + 14)\n : Math.min(MAX_TOTAL, props.maxLength);\n if (high < low)\n throw new Error(\n \"unable to generate a random hostname satisfying both the format and the length constraints.\",\n );\n return _randomInteger({ type: \"integer\", minimum: low, maximum: high });\n};\n\n/**\n * Builds dot-joined hostname labels totaling exactly `length` characters, each\n * label within 63 chars. Shared with the idn-hostname generator, which realizes\n * its length the same way since #2317 gave the two formats one structure.\n */\nexport const _randomHostnameLabels = (length: number): string => {\n const parts: string[] = [];\n let remaining: number = length;\n while (remaining > MAX_LABEL + 1) {\n // one full label plus its joining dot\n parts.push(random(MAX_LABEL));\n remaining -= MAX_LABEL + 1;\n }\n if (remaining <= MAX_LABEL) parts.push(random(remaining));\n else {\n // remaining === MAX_LABEL + 1: two labels keep every label within 63 chars\n parts.push(random(MAX_LABEL - 1));\n parts.push(random(1));\n }\n return parts.join(\".\");\n};\n\nconst random = (length: number) =>\n _randomString({ type: \"string\", minLength: length, maxLength: length });\n"],"mappings":";;;AAIA,MAAa,yBAAyB,UAAkC;CACtE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,GAAG,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC;CAGlC,OAAO,sBAAsB,WAAW,KAAK,CAAC;AAChD;AAEA,MAAM,YAAY;AAClB,MAAM,YAAY;AAElB,MAAM,cAAc,UAAiC;CACnD,IAAI,MAAc,MAAM,cAAc,KAAA,IAAY,IAAI,MAAM;CAC5D,IAAI,MAAM,GAAG,MAAM;CACnB,MAAM,OACJ,MAAM,cAAc,KAAA,IAChB,KAAK,IAAI,WAAW,MAAM,EAAE,IAC5B,KAAK,IAAI,WAAW,MAAM,SAAS;CACzC,IAAI,OAAO,KACT,MAAM,IAAI,MACR,6FACF;CACF,OAAO,eAAe;EAAE,MAAM;EAAW,SAAS;EAAK,SAAS;CAAK,CAAC;AACxE;;;;;;AAOA,MAAa,yBAAyB,WAA2B;CAC/D,MAAM,QAAkB,CAAC;CACzB,IAAI,YAAoB;CACxB,OAAO,YAAY,IAAe;EAEhC,MAAM,KAAK,OAAO,SAAS,CAAC;EAC5B,aAAa;CACf;CACA,IAAI,aAAa,WAAW,MAAM,KAAK,OAAO,SAAS,CAAC;MACnD;EAEH,MAAM,KAAK,OAAO,YAAY,CAAC,CAAC;EAChC,MAAM,KAAK,OAAO,CAAC,CAAC;CACtB;CACA,OAAO,MAAM,KAAK,GAAG;AACvB;AAEA,MAAM,UAAU,WACd,cAAc;CAAE,MAAM;CAAU,WAAW;CAAQ,WAAW;AAAO,CAAC"}
|
|
@@ -7,20 +7,19 @@ const _randomString_1 = require("./_randomString");
|
|
|
7
7
|
const _randomFormatIdnHostname = (props) => {
|
|
8
8
|
if ((props === null || props === void 0 ? void 0 : props.minLength) === undefined && (props === null || props === void 0 ? void 0 : props.maxLength) === undefined)
|
|
9
9
|
return `${random(10)}.${random(3)}`;
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
return
|
|
10
|
+
// idn-hostname shares hostname's structure (a single label of 1..63 chars is
|
|
11
|
+
// valid, no dot or trailing label required), so the requested length is
|
|
12
|
+
// realized the same way: split it across dot-joined labels. #2317 dropped the
|
|
13
|
+
// mandatory dot and two-character trailing label this generator used to
|
|
14
|
+
// reserve, which is why it now realizes a length below four.
|
|
15
|
+
return (0, _randomFormatHostname_1._randomHostnameLabels)(pickLength(props));
|
|
16
16
|
};
|
|
17
17
|
exports._randomFormatIdnHostname = _randomFormatIdnHostname;
|
|
18
18
|
const MAX_TOTAL = 253;
|
|
19
|
-
const MIN_TOTAL = 4; // the shortest idn hostname, `x.yy`: label(1) + `.` + tld(2)
|
|
20
19
|
const pickLength = (props) => {
|
|
21
|
-
let low = props.minLength === undefined ?
|
|
22
|
-
if (low <
|
|
23
|
-
low =
|
|
20
|
+
let low = props.minLength === undefined ? 1 : props.minLength;
|
|
21
|
+
if (low < 1)
|
|
22
|
+
low = 1;
|
|
24
23
|
const high = props.maxLength === undefined
|
|
25
24
|
? Math.min(MAX_TOTAL, low + 14)
|
|
26
25
|
: Math.min(MAX_TOTAL, props.maxLength);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_randomFormatIdnHostname.js","sourceRoot":"","sources":["../../src/internal/_randomFormatIdnHostname.ts"],"names":[],"mappings":";;;AAAA,mEAAgE;AAChE,qDAAkD;AAClD,mDAAgD;AAGzC,MAAM,wBAAwB,GAAG,CAAC,KAAqB,EAAU,EAAE;IACxE,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS;QAClE,OAAO,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACtC,
|
|
1
|
+
{"version":3,"file":"_randomFormatIdnHostname.js","sourceRoot":"","sources":["../../src/internal/_randomFormatIdnHostname.ts"],"names":[],"mappings":";;;AAAA,mEAAgE;AAChE,qDAAkD;AAClD,mDAAgD;AAGzC,MAAM,wBAAwB,GAAG,CAAC,KAAqB,EAAU,EAAE;IACxE,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,MAAK,SAAS;QAClE,OAAO,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACtC,6EAA6E;IAC7E,wEAAwE;IACxE,8EAA8E;IAC9E,wEAAwE;IACxE,6DAA6D;IAC7D,OAAO,IAAA,6CAAqB,EAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC;AATW,QAAA,wBAAwB,GAAxB,wBAAwB,CASnC;AAEF,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,MAAM,UAAU,GAAG,CAAC,KAAoB,EAAU,EAAE;IAClD,IAAI,GAAG,GAAW,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;IACtE,IAAI,GAAG,GAAG,CAAC;QAAE,GAAG,GAAG,CAAC,CAAC;IACrB,MAAM,IAAI,GACR,KAAK,CAAC,SAAS,KAAK,SAAS;QAC3B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,GAAG,EAAE,CAAC;QAC/B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC3C,IAAI,IAAI,GAAG,GAAG;QACZ,MAAM,IAAI,KAAK,CACb,iGAAiG,CAClG,CAAC;IACJ,OAAO,IAAA,+BAAc,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1E,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE,CAChC,IAAA,6BAAa,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC"}
|