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.
Files changed (235) hide show
  1. package/lib/executable/FileSystemIdentity.d.ts +23 -0
  2. package/lib/executable/FileSystemIdentity.js +30 -0
  3. package/lib/executable/FileSystemIdentity.js.map +1 -1
  4. package/lib/executable/FileSystemIdentity.mjs +4 -0
  5. package/lib/executable/FileSystemIdentity.mjs.map +1 -1
  6. package/lib/executable/TypiaGenerateWizard.js +15 -9
  7. package/lib/executable/TypiaGenerateWizard.js.map +1 -1
  8. package/lib/executable/TypiaGenerateWizard.mjs +11 -7
  9. package/lib/executable/TypiaGenerateWizard.mjs.map +1 -1
  10. package/lib/http.d.ts +3 -3
  11. package/lib/http.js.map +1 -1
  12. package/lib/http.mjs.map +1 -1
  13. package/lib/internal/_ProtobufReader.d.ts +18 -3
  14. package/lib/internal/_ProtobufReader.js +39 -11
  15. package/lib/internal/_ProtobufReader.js.map +1 -1
  16. package/lib/internal/_ProtobufReader.mjs +37 -10
  17. package/lib/internal/_ProtobufReader.mjs.map +1 -1
  18. package/lib/internal/_assertGuard.js +13 -3
  19. package/lib/internal/_assertGuard.js.map +1 -1
  20. package/lib/internal/_assertGuard.mjs +4 -2
  21. package/lib/internal/_assertGuard.mjs.map +1 -1
  22. package/lib/internal/_isFormatIdnHostname.js +5 -1
  23. package/lib/internal/_isFormatIdnHostname.js.map +1 -1
  24. package/lib/internal/_isFormatIdnHostname.mjs +1 -1
  25. package/lib/internal/_isFormatIdnHostname.mjs.map +1 -1
  26. package/lib/internal/_isFormatTime.js +19 -2
  27. package/lib/internal/_isFormatTime.js.map +1 -1
  28. package/lib/internal/_isFormatTime.mjs +9 -2
  29. package/lib/internal/_isFormatTime.mjs.map +1 -1
  30. package/lib/internal/_jsonStringifyArray.d.ts +1 -0
  31. package/lib/internal/_jsonStringifyArray.js +48 -0
  32. package/lib/internal/_jsonStringifyArray.js.map +1 -0
  33. package/lib/internal/_jsonStringifyArray.mjs +40 -0
  34. package/lib/internal/_jsonStringifyArray.mjs.map +1 -0
  35. package/lib/internal/_jsonStringifyElement.d.ts +1 -0
  36. package/lib/internal/_jsonStringifyElement.js +23 -0
  37. package/lib/internal/_jsonStringifyElement.js.map +1 -0
  38. package/lib/internal/_jsonStringifyElement.mjs +23 -0
  39. package/lib/internal/_jsonStringifyElement.mjs.map +1 -0
  40. package/lib/internal/_jsonStringifyProperty.d.ts +1 -0
  41. package/lib/internal/_jsonStringifyProperty.js +31 -0
  42. package/lib/internal/_jsonStringifyProperty.js.map +1 -0
  43. package/lib/internal/_jsonStringifyProperty.mjs +31 -0
  44. package/lib/internal/_jsonStringifyProperty.mjs.map +1 -0
  45. package/lib/internal/_llmApplicationFinalize.js +1 -1
  46. package/lib/internal/_llmApplicationFinalize.js.map +1 -1
  47. package/lib/internal/_llmApplicationFinalize.mjs +1 -1
  48. package/lib/internal/_llmApplicationFinalize.mjs.map +1 -1
  49. package/lib/internal/_randomArray.js +37 -4
  50. package/lib/internal/_randomArray.js.map +1 -1
  51. package/lib/internal/_randomArray.mjs +16 -3
  52. package/lib/internal/_randomArray.mjs.map +1 -1
  53. package/lib/internal/_randomFormatByte.js +28 -2
  54. package/lib/internal/_randomFormatByte.js.map +1 -1
  55. package/lib/internal/_randomFormatByte.mjs +22 -3
  56. package/lib/internal/_randomFormatByte.mjs.map +1 -1
  57. package/lib/internal/_randomFormatDate.d.ts +3 -6
  58. package/lib/internal/_randomFormatDate.js +2 -10
  59. package/lib/internal/_randomFormatDate.js.map +1 -1
  60. package/lib/internal/_randomFormatDate.mjs +2 -6
  61. package/lib/internal/_randomFormatDate.mjs.map +1 -1
  62. package/lib/internal/_randomFormatDatetime.d.ts +3 -6
  63. package/lib/internal/_randomFormatDatetime.js +25 -8
  64. package/lib/internal/_randomFormatDatetime.js.map +1 -1
  65. package/lib/internal/_randomFormatDatetime.mjs +17 -7
  66. package/lib/internal/_randomFormatDatetime.mjs.map +1 -1
  67. package/lib/internal/_randomFormatDuration.js +23 -15
  68. package/lib/internal/_randomFormatDuration.js.map +1 -1
  69. package/lib/internal/_randomFormatDuration.mjs +23 -15
  70. package/lib/internal/_randomFormatDuration.mjs.map +1 -1
  71. package/lib/internal/_randomFormatHostname.d.ts +2 -2
  72. package/lib/internal/_randomFormatHostname.js +2 -2
  73. package/lib/internal/_randomFormatHostname.mjs +2 -2
  74. package/lib/internal/_randomFormatHostname.mjs.map +1 -1
  75. package/lib/internal/_randomFormatIdnHostname.js +9 -10
  76. package/lib/internal/_randomFormatIdnHostname.js.map +1 -1
  77. package/lib/internal/_randomFormatIdnHostname.mjs +3 -4
  78. package/lib/internal/_randomFormatIdnHostname.mjs.map +1 -1
  79. package/lib/internal/_randomFormatIpv4.js +31 -1
  80. package/lib/internal/_randomFormatIpv4.js.map +1 -1
  81. package/lib/internal/_randomFormatIpv4.mjs +23 -2
  82. package/lib/internal/_randomFormatIpv4.mjs.map +1 -1
  83. package/lib/internal/_randomFormatIpv6.js +57 -1
  84. package/lib/internal/_randomFormatIpv6.js.map +1 -1
  85. package/lib/internal/_randomFormatIpv6.mjs +45 -2
  86. package/lib/internal/_randomFormatIpv6.mjs.map +1 -1
  87. package/lib/internal/_randomFormatJsonPointer.js +14 -2
  88. package/lib/internal/_randomFormatJsonPointer.js.map +1 -1
  89. package/lib/internal/_randomFormatJsonPointer.mjs +13 -3
  90. package/lib/internal/_randomFormatJsonPointer.mjs.map +1 -1
  91. package/lib/internal/_randomFormatRegex.js +15 -2
  92. package/lib/internal/_randomFormatRegex.js.map +1 -1
  93. package/lib/internal/_randomFormatRegex.mjs +14 -3
  94. package/lib/internal/_randomFormatRegex.mjs.map +1 -1
  95. package/lib/internal/_randomFormatRelativeJsonPointer.js +19 -5
  96. package/lib/internal/_randomFormatRelativeJsonPointer.js.map +1 -1
  97. package/lib/internal/_randomFormatRelativeJsonPointer.mjs +21 -6
  98. package/lib/internal/_randomFormatRelativeJsonPointer.mjs.map +1 -1
  99. package/lib/internal/_randomFormatTime.js +38 -7
  100. package/lib/internal/_randomFormatTime.js.map +1 -1
  101. package/lib/internal/_randomFormatTime.mjs +40 -5
  102. package/lib/internal/_randomFormatTime.mjs.map +1 -1
  103. package/lib/internal/_randomPattern.js.map +1 -1
  104. package/lib/internal/_randomPattern.mjs.map +1 -1
  105. package/lib/internal/_randomStringLength.d.ts +41 -10
  106. package/lib/internal/_randomStringLength.js +49 -13
  107. package/lib/internal/_randomStringLength.js.map +1 -1
  108. package/lib/internal/_randomStringLength.mjs +48 -13
  109. package/lib/internal/_randomStringLength.mjs.map +1 -1
  110. package/lib/internal/private/__notationRename.js.map +1 -1
  111. package/lib/internal/private/__notationRename.mjs.map +1 -1
  112. package/lib/internal/private/__randomComposition.d.ts +31 -0
  113. package/lib/internal/private/__randomComposition.js +68 -0
  114. package/lib/internal/private/__randomComposition.js.map +1 -0
  115. package/lib/internal/private/__randomComposition.mjs +71 -0
  116. package/lib/internal/private/__randomComposition.mjs.map +1 -0
  117. package/lib/internal/private/__randomEpoch.d.ts +19 -0
  118. package/lib/internal/private/__randomEpoch.js +31 -0
  119. package/lib/internal/private/__randomEpoch.js.map +1 -0
  120. package/lib/internal/private/__randomEpoch.mjs +28 -0
  121. package/lib/internal/private/__randomEpoch.mjs.map +1 -0
  122. package/lib/json.d.ts +2 -2
  123. package/lib/json.js.map +1 -1
  124. package/lib/json.mjs.map +1 -1
  125. package/lib/module.d.ts +28 -13
  126. package/lib/module.js.map +1 -1
  127. package/lib/module.mjs.map +1 -1
  128. package/lib/notations.d.ts +4 -4
  129. package/lib/notations.js.map +1 -1
  130. package/lib/notations.mjs.map +1 -1
  131. package/lib/plain.d.ts +3 -3
  132. package/lib/plain.js.map +1 -1
  133. package/lib/plain.mjs.map +1 -1
  134. package/lib/protobuf.d.ts +2 -2
  135. package/lib/protobuf.js.map +1 -1
  136. package/lib/protobuf.mjs.map +1 -1
  137. package/native/cmd/ttsc-typia/assert_guard_factory_contract_test.go +17 -4
  138. package/native/cmd/ttsc-typia/build.go +3 -0
  139. package/native/cmd/ttsc-typia/callable_interface_function_semantics_transform_test.go +331 -0
  140. package/native/cmd/ttsc-typia/callable_type_literal_boundaries_transform_test.go +1184 -0
  141. package/native/cmd/ttsc-typia/compare_functional_union_membership_transform_test.go +434 -0
  142. package/native/cmd/ttsc-typia/compare_template_literal_union_transform_test.go +241 -0
  143. package/native/cmd/ttsc-typia/create_assert_error_factory_arity_test.go +309 -0
  144. package/native/cmd/ttsc-typia/default_library_spoof_native_identity_transform_test.go +216 -0
  145. package/native/cmd/ttsc-typia/json_schema_dynamic_key_determinism_transform_test.go +246 -0
  146. package/native/cmd/ttsc-typia/json_stringify_contextual_undefined_transform_test.go +556 -0
  147. package/native/cmd/ttsc-typia/lib_replacement_native_identity_transform_test.go +277 -0
  148. package/native/cmd/ttsc-typia/local_function_named_like_typia_operation_transform_test.go +185 -0
  149. package/native/cmd/ttsc-typia/native_named_intersection_union_transform_test.go +390 -0
  150. package/native/cmd/ttsc-typia/node_buffer_native_exports_is_transform_test.go +526 -0
  151. package/native/cmd/ttsc-typia/package_declaration_native_identity_is_transform_test.go +293 -0
  152. package/native/cmd/ttsc-typia/protobuf_diagnostic_code_transform_test.go +167 -0
  153. package/native/cmd/ttsc-typia/recursive_conditional_alias_name_transform_test.go +307 -0
  154. package/native/cmd/ttsc-typia/shadowed_typia_module_declaration_diagnostic_test.go +152 -0
  155. package/native/cmd/ttsc-typia/symbol_index_domain_transform_test.go +316 -0
  156. package/native/cmd/ttsc-typia/template_literal_type_tags_transform_test.go +1 -3
  157. package/native/cmd/ttsc-typia/transform.go +23 -0
  158. package/native/cmd/ttsc-typia/transform_helpers_test.go +166 -25
  159. package/native/cmd/ttsc-typia/user_global_native_identity_transform_test.go +484 -0
  160. package/native/core/factories/FormatCheatSheet.go +2 -2
  161. package/native/core/factories/MetadataCommentTagFactory.go +26 -11
  162. package/native/core/factories/ProtobufFactory.go +6 -1
  163. package/native/core/factories/factory_utility_coverage_test.go +896 -907
  164. package/native/core/factories/internal/metadata/MetadataHelper.go +190 -58
  165. package/native/core/factories/internal/metadata/emplace_metadata_object.go +25 -0
  166. package/native/core/factories/internal/metadata/iterate_metadata_function.go +1 -1
  167. package/native/core/factories/internal/metadata/iterate_metadata_intersection.go +103 -23
  168. package/native/core/factories/internal/metadata/iterate_metadata_map.go +3 -7
  169. package/native/core/factories/internal/metadata/iterate_metadata_native.go +32 -14
  170. package/native/core/factories/internal/metadata/iterate_metadata_set.go +3 -7
  171. package/native/core/factories/metadata_comment_tag_factory_coverage_test.go +2 -2
  172. package/native/core/programmers/RandomProgrammer.go +5 -2
  173. package/native/core/programmers/compare/CompareEqualProgrammer.go +27 -13
  174. package/native/core/programmers/helpers/FunctionProgrammer.go +6 -13
  175. package/native/core/programmers/helpers/StringifyJoinder.go +129 -50
  176. package/native/core/programmers/helpers/joiner_branch_coverage_test.go +116 -120
  177. package/native/core/programmers/iterate/iterate_check_coverage_test.go +76 -158
  178. package/native/core/programmers/iterate/iterate_utility_coverage_test.go +231 -270
  179. package/native/core/programmers/iterate/json_schema_object.go +49 -7
  180. package/native/core/programmers/iterate/json_schema_pattern_property_order_test.go +44 -0
  181. package/native/core/programmers/iterate/openapi_v3_downgrader.go +34 -1
  182. package/native/core/programmers/iterate/template_runtime_pattern.go +11 -0
  183. package/native/core/programmers/json/JsonStringifyProgrammer.go +47 -6
  184. package/native/core/programmers/llm/LlmApplicationProgrammer.go +9 -1
  185. package/native/core/programmers/protobuf/ProtobufMessageProgrammer.go +1 -1
  186. package/native/core/schemas/metadata/MetadataCollection.go +47 -14
  187. package/native/core/schemas/metadata/MetadataDefaultLibrary.go +81 -0
  188. package/native/core/schemas/metadata/MetadataObjectType.go +7 -18
  189. package/native/go.mod +4 -4
  190. package/native/transform/CallExpressionTransformer.go +167 -0
  191. package/native/transform/features/protobuf/ProtobufMessageTransformer.go +1 -1
  192. package/package.json +3 -7
  193. package/src/executable/FileSystemIdentity.ts +33 -0
  194. package/src/executable/TypiaGenerateWizard.ts +18 -12
  195. package/src/http.ts +18 -4
  196. package/src/internal/_ProtobufReader.ts +40 -11
  197. package/src/internal/_assertGuard.ts +13 -2
  198. package/src/internal/_isFormatIdnHostname.ts +5 -1
  199. package/src/internal/_isFormatTime.ts +19 -2
  200. package/src/internal/_jsonStringifyArray.ts +50 -0
  201. package/src/internal/_jsonStringifyElement.ts +19 -0
  202. package/src/internal/_jsonStringifyProperty.ts +30 -0
  203. package/src/internal/_llmApplicationFinalize.ts +6 -1
  204. package/src/internal/_randomArray.ts +42 -6
  205. package/src/internal/_randomFormatByte.ts +36 -4
  206. package/src/internal/_randomFormatDate.ts +4 -20
  207. package/src/internal/_randomFormatDatetime.ts +34 -20
  208. package/src/internal/_randomFormatDuration.ts +19 -4
  209. package/src/internal/_randomFormatHostname.ts +2 -2
  210. package/src/internal/_randomFormatIdnHostname.ts +8 -9
  211. package/src/internal/_randomFormatIpv4.ts +43 -3
  212. package/src/internal/_randomFormatIpv6.ts +67 -3
  213. package/src/internal/_randomFormatJsonPointer.ts +23 -3
  214. package/src/internal/_randomFormatRegex.ts +22 -6
  215. package/src/internal/_randomFormatRelativeJsonPointer.ts +23 -10
  216. package/src/internal/_randomFormatTime.ts +50 -12
  217. package/src/internal/_randomPattern.ts +4 -1
  218. package/src/internal/_randomStringLength.ts +61 -17
  219. package/src/internal/private/__notationRename.ts +1 -4
  220. package/src/internal/private/__randomComposition.ts +74 -0
  221. package/src/internal/private/__randomEpoch.ts +34 -0
  222. package/src/json.ts +16 -4
  223. package/src/module.ts +56 -22
  224. package/src/notations.ts +16 -4
  225. package/src/plain.ts +12 -3
  226. package/src/protobuf.ts +16 -4
  227. package/native/adapter/visit.go +0 -173
  228. package/native/adapter/visit_property_chain_edges_test.go +0 -129
  229. package/native/core/programmers/helpers/disable_function_programmer_declare.go +0 -10
  230. package/native/core/programmers/iterate/check_union_array_like.go +0 -422
  231. package/native/core/programmers/iterate/prune_object_properties.go +0 -105
  232. package/native/core/programmers/iterate/stringify_dynamic_properties.go +0 -219
  233. package/native/core/programmers/iterate/stringify_native.go +0 -14
  234. package/native/core/programmers/iterate/stringify_regular_properties.go +0 -112
  235. 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
- for (let attempts = 0; elements.length !== count; attempts++) {
24
- if (attempts === maximumAttempts)
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;AAE3B,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,SAA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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
- for (let attempts = 0; elements.length !== count; attempts++) {
19
- if (attempts === maximumAttempts) throw new Error("Unable to generate enough unique items; the element domain may be too small.");
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]))) elements.push(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; elements.length !== count; attempts++) {\n if (attempts === maximumAttempts)\n throw new Error(\n \"Unable to generate enough unique items; the element domain may be too small.\",\n );\n const candidate: T = props.element(elements.length, count);\n if (elements.every((element) => _isUniqueItems([element, candidate])))\n elements.push(candidate);\n }\n return elements;\n};\n"],"mappings":";;;AAKA,MAAM,oBAAoB;AAC1B,MAAM,gBAAgB;AACtB,MAAM,0BAA0B;AAEhC,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;CAC1E,MAAM,WAAgB,CAAC;CACvB,MAAM,kBAA0B,QAAQ,MAAM;CAC9C,KAAK,IAAI,WAAW,GAAG,SAAS,WAAW,OAAO,YAAY;EAC5D,IAAI,aAAa,iBACf,MAAM,IAAI,MACR,8EACF;EACF,MAAM,YAAe,MAAM,QAAQ,SAAS,QAAQ,KAAK;EACzD,IAAI,SAAS,OAAO,YAAY,eAAe,CAAC,SAAS,SAAS,CAAC,CAAC,GAClE,SAAS,KAAK,SAAS;CAC3B;CACA,OAAO;AACT"}
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 _randomFormatByte = (props) => (0, _randomStringLength_1._randomFormatLength)(props, () => FIXED);
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 FIXED = "vt7ekz4lIoNTTS9sDQYdWKharxIFAR54+z/umIxSgUM=";
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,+DAA2E;AAEpE,MAAM,iBAAiB,GAAG,CAAC,KAAqB,EAAU,EAAE,CACjE,IAAA,yCAAmB,EAAC,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;AAD7B,QAAA,iBAAiB,GAAjB,iBAAiB,CACY;AAE1C,MAAM,KAAK,GA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GAAG,CAAC,CAAC;AAC5B,MAAM,iBAAiB,GAAG,EAAE,CAAC"}
@@ -1,7 +1,26 @@
1
- import { _randomFormatLength } from "./_randomStringLength.mjs";
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) => _randomFormatLength(props, () => FIXED);
4
- const FIXED = "vt7ekz4lIoNTTS9sDQYdWKharxIFAR54+z/umIxSgUM=";
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 { _ILengthProps, _randomFormatLength } from \"./_randomStringLength\";\n\nexport const _randomFormatByte = (props?: _ILengthProps): string =>\n _randomFormatLength(props, () => FIXED);\n\nconst FIXED = \"vt7ekz4lIoNTTS9sDQYdWKharxIFAR54+z/umIxSgUM=\";\n"],"mappings":";;AAEA,MAAa,qBAAqB,UAChC,oBAAoB,aAAa,KAAK;AAExC,MAAM,QAAQ"}
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
- export declare const _randomFormatDate: (props?: {
2
- minimum?: number;
3
- maximum?: number;
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 _randomFormatDate = (props) => (0, _randomStringLength_1._randomFormatLength)(props, () => { var _a, _b; return new Date((0, _randomInteger_1._randomInteger)({
7
- type: "integer",
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,qDAAkD;AAClD,+DAA4D;AAErD,MAAM,iBAAiB,GAAG,CAAC,KAKjC,EAAE,EAAE,CACH,IAAA,yCAAmB,EAAC,KAAK,EAAE,GAAG,EAAE,sBAC9B,IAAI,IAAI,CACN,IAAA,+BAAc,EAAC;IACb,IAAI,EAAE,SAAS;IACf,OAAO,QAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,mCAAI,CAAC;IAC5B,OAAO,EACL,OAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,mCAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,MAAK,SAAS,CAAC;QAC9C,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QACZ,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAK;CACjD,CAAC,CACH;KACE,WAAW,EAAE;KACb,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,GAAA,CACpB,CAAC;AAnBS,QAAA,iBAAiB,GAAjB,iBAAiB,CAmB1B"}
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(_randomInteger({
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 { _randomInteger } from \"./_randomInteger\";\nimport { _randomFormatLength } from \"./_randomStringLength\";\n\nexport const _randomFormatDate = (props?: {\n minimum?: number;\n maximum?: number;\n minLength?: number;\n maxLength?: number;\n}) =>\n _randomFormatLength(props, () =>\n new Date(\n _randomInteger({\n type: \"integer\",\n minimum: props?.minimum ?? 0,\n maximum:\n (props?.maximum ?? props?.minimum === undefined)\n ? Date.now()\n : props.minimum + 365 * 24 * 60 * 60 * 1_000,\n }),\n )\n .toISOString()\n .substring(0, 10),\n );\n"],"mappings":";;;AAGA,MAAa,qBAAqB,UAMhC,oBAAoB,aAClB,IAAI,KACF,eAAe;CACb,MAAM;CACN,SAAS,OAAO,WAAW;CAC3B,SACG,OAAO,WAAW,OAAO,YAAY,KAAA,IAClC,KAAK,IAAI,IACT,MAAM,UAAU,MAAM,KAAK,KAAK,KAAK;AAC7C,CAAC,CACH,CAAC,CACE,YAAY,CAAC,CACb,UAAU,GAAG,EAAE,CACpB"}
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
- export declare const _randomFormatDatetime: (props?: {
2
- minimum?: number;
3
- maximum?: number;
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 _randomFormatDatetime = (props) => (0, _randomStringLength_1._randomFormatLength)(props, () => { var _a, _b; return new Date((0, _randomInteger_1._randomInteger)({
7
- type: "integer",
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
- })).toISOString(); });
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,qDAAkD;AAClD,+DAA4D;AAErD,MAAM,qBAAqB,GAAG,CAAC,KAKrC,EAAE,EAAE,CACH,IAAA,yCAAmB,EAAC,KAAK,EAAE,GAAG,EAAE,sBAC9B,IAAI,IAAI,CACN,IAAA,+BAAc,EAAC;IACb,IAAI,EAAE,SAAS;IACf,OAAO,QAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,mCAAI,CAAC;IAC5B,OAAO,EACL,OAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,mCAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,MAAK,SAAS,CAAC;QAC9C,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QACZ,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAK;CACjD,CAAC,CACH,CAAC,WAAW,EAAE,GAAA,CAChB,CAAC;AAjBS,QAAA,qBAAqB,GAArB,qBAAqB,CAiB9B"}
1
+ {"version":3,"file":"_randomFormatDatetime.js","sourceRoot":"","sources":["../../src/internal/_randomFormatDatetime.ts"],"names":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CAAC;AACzD,CAAC,CAAC;AAvBW,QAAA,qBAAqB,GAArB,qBAAqB,CAuBhC;AAEF,MAAM,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC"}
@@ -1,11 +1,21 @@
1
- import { _randomInteger } from "./_randomInteger.mjs";
2
- import { _randomFormatLength } from "./_randomStringLength.mjs";
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) => _randomFormatLength(props, () => new Date(_randomInteger({
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());
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 { _randomInteger } from \"./_randomInteger\";\nimport { _randomFormatLength } from \"./_randomStringLength\";\n\nexport const _randomFormatDatetime = (props?: {\n minimum?: number;\n maximum?: number;\n minLength?: number;\n maxLength?: number;\n}) =>\n _randomFormatLength(props, () =>\n new Date(\n _randomInteger({\n type: \"integer\",\n minimum: props?.minimum ?? 0,\n maximum:\n (props?.maximum ?? props?.minimum === undefined)\n ? Date.now()\n : props.minimum + 365 * 24 * 60 * 60 * 1_000,\n }),\n ).toISOString(),\n );\n"],"mappings":";;;AAGA,MAAa,yBAAyB,UAMpC,oBAAoB,aAClB,IAAI,KACF,eAAe;CACb,MAAM;CACN,SAAS,OAAO,WAAW;CAC3B,SACG,OAAO,WAAW,OAAO,YAAY,KAAA,IAClC,KAAK,IAAI,IACT,MAAM,UAAU,MAAM,KAAK,KAAK,KAAK;AAC7C,CAAC,CACH,CAAC,CAAC,YAAY,CAChB"}
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 _randomFormatDuration = (props) => (0, _randomStringLength_1._randomFormatLength)(props, () => {
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)
18
- return "PT0S";
19
- return `P${period}${time.length ? "T" : ""}${time}`;
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,+DAA2E;AAEpE,MAAM,qBAAqB,GAAG,CAAC,KAAqB,EAAU,EAAE,CACrE,IAAA,yCAAmB,EAAC,KAAK,EAAE,GAAG,EAAE;IAC9B,MAAM,MAAM,GAAW,MAAM,CAAC;QAC5B,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACrB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACpB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;KACrB,CAAC,CAAC;IACH,MAAM,IAAI,GAAW,MAAM,CAAC;QAC1B,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACpB,CAAC,GAAG,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,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 { _randomFormatLength } from "./_randomStringLength.mjs";
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) => _randomFormatLength(props, () => {
5
- const period = durate([
6
- ["Y", random(0, 100)],
7
- ["M", random(0, 12)],
8
- ["D", random(0, 31)]
9
- ]);
10
- const time = durate([
11
- ["H", random(0, 24)],
12
- ["M", random(0, 60)],
13
- ["S", random(0, 60)]
14
- ]);
15
- if (period.length + time.length === 0) return "PT0S";
16
- return `P${period}${time.length ? "T" : ""}${time}`;
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 { _ILengthProps, _randomFormatLength } from \"./_randomStringLength\";\n\nexport const _randomFormatDuration = (props?: _ILengthProps): string =>\n _randomFormatLength(props, () => {\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 });\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":";;;AAGA,MAAa,yBAAyB,UACpC,oBAAoB,aAAa;CAC/B,MAAM,SAAiB,OAAO;EAC5B,CAAC,KAAK,OAAO,GAAG,GAAG,CAAC;EACpB,CAAC,KAAK,OAAO,GAAG,EAAE,CAAC;EACnB,CAAC,KAAK,OAAO,GAAG,EAAE,CAAC;CACrB,CAAC;CACD,MAAM,OAAe,OAAO;EAC1B,CAAC,KAAK,OAAO,GAAG,EAAE,CAAC;EACnB,CAAC,KAAK,OAAO,GAAG,EAAE,CAAC;EACnB,CAAC,KAAK,OAAO,GAAG,EAAE,CAAC;CACrB,CAAC;CACD,IAAI,OAAO,SAAS,KAAK,WAAW,GAAG,OAAO;CAC9C,OAAO,IAAI,SAAS,KAAK,SAAS,MAAM,KAAK;AAC/C,CAAC;AACH,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"}
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 reserves
6
- * a fixed `.<tld>` suffix and realizes the rest as these leading labels.
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 reserves
30
- * a fixed `.<tld>` suffix and realizes the rest as these leading labels.
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 reserves
24
- * a fixed `.<tld>` suffix and realizes the rest as these leading labels.
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 reserves\n * a fixed `.<tld>` suffix and realizes the rest as these leading labels.\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"}
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
- // `_isFormatIdnHostname` requires at least one label, a dot, and a >=2-char
11
- // TLD (`(…\.)+[a-z¡-￿]{2,}`), none of which the non-idn hostname generator
12
- // guarantees on its length path (it can emit a single dotless label). Reserve
13
- // a fixed `.<2-char TLD>` and realize the rest as dot-joined leading labels.
14
- const length = pickLength(props);
15
- return `${(0, _randomFormatHostname_1._randomHostnameLabels)(length - 3)}.${random(2)}`;
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 ? MIN_TOTAL : props.minLength;
22
- if (low < MIN_TOTAL)
23
- low = MIN_TOTAL;
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,4EAA4E;IAC5E,2EAA2E;IAC3E,8EAA8E;IAC9E,6EAA6E;IAC7E,MAAM,MAAM,GAAW,UAAU,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,GAAG,IAAA,6CAAqB,EAAC,M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