@nestia/migrate 14.0.0 → 14.0.2

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 (182) hide show
  1. package/README.md +1 -1
  2. package/lib/NestiaMigrateApplication.d.ts +111 -0
  3. package/lib/NestiaMigrateApplication.js +148 -9
  4. package/lib/NestiaMigrateApplication.js.map +1 -1
  5. package/lib/NestiaMigrateApplication.mjs +147 -5
  6. package/lib/analyzers/NestiaMigrateControllerAnalyzer.d.ts +58 -0
  7. package/lib/analyzers/NestiaMigrateControllerAnalyzer.js +88 -2
  8. package/lib/analyzers/NestiaMigrateControllerAnalyzer.js.map +1 -1
  9. package/lib/analyzers/NestiaMigrateControllerAnalyzer.mjs +20 -2
  10. package/lib/archivers/NestiaMigrateFileArchiver.d.ts +34 -0
  11. package/lib/archivers/NestiaMigrateFileArchiver.js +34 -0
  12. package/lib/archivers/NestiaMigrateFileArchiver.js.map +1 -1
  13. package/lib/bundles/NEST_TEMPLATE.js +1 -1
  14. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  15. package/lib/bundles/NEST_TEMPLATE.mjs +1 -1
  16. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  17. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  18. package/lib/bundles/SDK_TEMPLATE.mjs +1 -1
  19. package/lib/executable/NestiaMigrateCommander.d.ts +36 -0
  20. package/lib/executable/NestiaMigrateCommander.js +43 -1
  21. package/lib/executable/NestiaMigrateCommander.js.map +1 -1
  22. package/lib/executable/NestiaMigrateCommander.mjs +4 -2
  23. package/lib/executable/NestiaMigrateInquirer.d.ts +29 -0
  24. package/lib/executable/NestiaMigrateInquirer.js +27 -25
  25. package/lib/executable/NestiaMigrateInquirer.js.map +1 -1
  26. package/lib/executable/NestiaMigrateInquirer.mjs +5 -7
  27. package/lib/factories/ExpressionFactory.d.ts +14 -0
  28. package/lib/factories/ExpressionFactory.js +14 -0
  29. package/lib/factories/ExpressionFactory.js.map +1 -1
  30. package/lib/factories/IdentifierFactory.d.ts +20 -0
  31. package/lib/factories/IdentifierFactory.js +20 -0
  32. package/lib/factories/IdentifierFactory.js.map +1 -1
  33. package/lib/factories/LiteralFactory.d.ts +18 -2
  34. package/lib/factories/LiteralFactory.js +18 -2
  35. package/lib/factories/LiteralFactory.js.map +1 -1
  36. package/lib/factories/StatementFactory.d.ts +26 -1
  37. package/lib/factories/StatementFactory.js +26 -1
  38. package/lib/factories/StatementFactory.js.map +1 -1
  39. package/lib/factories/SupportedStringFormats.d.ts +6 -0
  40. package/lib/factories/SupportedStringFormats.js +33 -0
  41. package/lib/factories/SupportedStringFormats.js.map +1 -0
  42. package/lib/factories/SupportedStringFormats.mjs +34 -0
  43. package/lib/factories/SupportedStringFormats.mjs.map +1 -0
  44. package/lib/factories/TypeFactory.d.ts +21 -0
  45. package/lib/factories/TypeFactory.js +13 -0
  46. package/lib/factories/TypeFactory.js.map +1 -1
  47. package/lib/factories/TypeLiteralFactory.d.ts +18 -0
  48. package/lib/factories/TypeLiteralFactory.js +18 -0
  49. package/lib/factories/TypeLiteralFactory.js.map +1 -1
  50. package/lib/internal/ts.d.ts +153 -0
  51. package/lib/internal/ts.js.map +1 -1
  52. package/lib/programmers/NestiaMigrateApiFileProgrammer.d.ts +31 -0
  53. package/lib/programmers/NestiaMigrateApiFileProgrammer.js +17 -0
  54. package/lib/programmers/NestiaMigrateApiFileProgrammer.js.map +1 -1
  55. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.d.ts +40 -0
  56. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +34 -5
  57. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +1 -1
  58. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.mjs +4 -2
  59. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.d.ts +39 -0
  60. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js +57 -13
  61. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js.map +1 -1
  62. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.mjs +17 -8
  63. package/lib/programmers/NestiaMigrateApiProgrammer.d.ts +18 -0
  64. package/lib/programmers/NestiaMigrateApiProgrammer.js +18 -0
  65. package/lib/programmers/NestiaMigrateApiProgrammer.js.map +1 -1
  66. package/lib/programmers/NestiaMigrateApiProgrammer.mjs +1 -1
  67. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.d.ts +40 -0
  68. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js +51 -22
  69. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js.map +1 -1
  70. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.mjs +13 -20
  71. package/lib/programmers/NestiaMigrateApiStartProgrammer.d.ts +17 -0
  72. package/lib/programmers/NestiaMigrateApiStartProgrammer.js +19 -8
  73. package/lib/programmers/NestiaMigrateApiStartProgrammer.js.map +1 -1
  74. package/lib/programmers/NestiaMigrateApiStartProgrammer.mjs +1 -6
  75. package/lib/programmers/NestiaMigrateDtoProgrammer.d.ts +30 -0
  76. package/lib/programmers/NestiaMigrateDtoProgrammer.js +17 -0
  77. package/lib/programmers/NestiaMigrateDtoProgrammer.js.map +1 -1
  78. package/lib/programmers/NestiaMigrateE2eFileProgrammer.d.ts +39 -0
  79. package/lib/programmers/NestiaMigrateE2eFileProgrammer.js +46 -5
  80. package/lib/programmers/NestiaMigrateE2eFileProgrammer.js.map +1 -1
  81. package/lib/programmers/NestiaMigrateE2eFileProgrammer.mjs +6 -2
  82. package/lib/programmers/NestiaMigrateE2eProgrammer.d.ts +16 -0
  83. package/lib/programmers/NestiaMigrateE2eProgrammer.js +16 -0
  84. package/lib/programmers/NestiaMigrateE2eProgrammer.js.map +1 -1
  85. package/lib/programmers/NestiaMigrateImportProgrammer.d.ts +75 -0
  86. package/lib/programmers/NestiaMigrateImportProgrammer.js +58 -3
  87. package/lib/programmers/NestiaMigrateImportProgrammer.js.map +1 -1
  88. package/lib/programmers/NestiaMigrateImportProgrammer.mjs +58 -3
  89. package/lib/programmers/NestiaMigrateNestControllerProgrammer.d.ts +28 -0
  90. package/lib/programmers/NestiaMigrateNestControllerProgrammer.js +16 -0
  91. package/lib/programmers/NestiaMigrateNestControllerProgrammer.js.map +1 -1
  92. package/lib/programmers/NestiaMigrateNestMethodProgrammer.d.ts +30 -0
  93. package/lib/programmers/NestiaMigrateNestMethodProgrammer.js +85 -13
  94. package/lib/programmers/NestiaMigrateNestMethodProgrammer.js.map +1 -1
  95. package/lib/programmers/NestiaMigrateNestMethodProgrammer.mjs +46 -9
  96. package/lib/programmers/NestiaMigrateNestModuleProgrammer.d.ts +16 -0
  97. package/lib/programmers/NestiaMigrateNestModuleProgrammer.js +16 -0
  98. package/lib/programmers/NestiaMigrateNestModuleProgrammer.js.map +1 -1
  99. package/lib/programmers/NestiaMigrateNestProgrammer.d.ts +17 -0
  100. package/lib/programmers/NestiaMigrateNestProgrammer.js +17 -0
  101. package/lib/programmers/NestiaMigrateNestProgrammer.js.map +1 -1
  102. package/lib/programmers/NestiaMigrateSchemaProgrammer.d.ts +16 -0
  103. package/lib/programmers/NestiaMigrateSchemaProgrammer.js +45 -9
  104. package/lib/programmers/NestiaMigrateSchemaProgrammer.js.map +1 -1
  105. package/lib/programmers/NestiaMigrateSchemaProgrammer.mjs +19 -8
  106. package/lib/structures/INestiaMigrateConfig.d.ts +21 -0
  107. package/lib/structures/INestiaMigrateContext.d.ts +15 -0
  108. package/lib/structures/INestiaMigrateController.d.ts +13 -0
  109. package/lib/structures/INestiaMigrateFile.d.ts +11 -0
  110. package/lib/utils/FilePrinter.d.ts +33 -0
  111. package/lib/utils/FilePrinter.js +33 -0
  112. package/lib/utils/FilePrinter.js.map +1 -1
  113. package/lib/utils/MapUtil.d.ts +17 -0
  114. package/lib/utils/MapUtil.js +19 -3
  115. package/lib/utils/MapUtil.js.map +1 -1
  116. package/lib/utils/MapUtil.mjs +1 -2
  117. package/lib/utils/PathTemplate.d.ts +41 -0
  118. package/lib/utils/PathTemplate.js +56 -0
  119. package/lib/utils/PathTemplate.js.map +1 -0
  120. package/lib/utils/PathTemplate.mjs +34 -0
  121. package/lib/utils/PathTemplate.mjs.map +1 -0
  122. package/lib/utils/RequestBody.d.ts +22 -0
  123. package/lib/utils/RequestBody.js +29 -0
  124. package/lib/utils/RequestBody.js.map +1 -0
  125. package/lib/utils/RequestBody.mjs +9 -0
  126. package/lib/utils/RequestBody.mjs.map +1 -0
  127. package/lib/utils/StringUtil.d.ts +55 -0
  128. package/lib/utils/StringUtil.js +93 -8
  129. package/lib/utils/StringUtil.js.map +1 -1
  130. package/lib/utils/StringUtil.mjs +30 -8
  131. package/lib/utils/SuccessStatus.d.ts +34 -0
  132. package/lib/utils/SuccessStatus.js +48 -0
  133. package/lib/utils/SuccessStatus.js.map +1 -0
  134. package/lib/utils/SuccessStatus.mjs +14 -0
  135. package/lib/utils/SuccessStatus.mjs.map +1 -0
  136. package/package.json +5 -4
  137. package/src/NestiaMigrateApplication.ts +151 -13
  138. package/src/analyzers/NestiaMigrateControllerAnalyzer.ts +94 -2
  139. package/src/archivers/NestiaMigrateFileArchiver.ts +34 -0
  140. package/src/bundles/NEST_TEMPLATE.ts +1 -1
  141. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  142. package/src/executable/NestiaMigrateCommander.ts +47 -1
  143. package/src/executable/NestiaMigrateInquirer.ts +41 -26
  144. package/src/factories/ExpressionFactory.ts +14 -0
  145. package/src/factories/IdentifierFactory.ts +20 -0
  146. package/src/factories/LiteralFactory.ts +18 -2
  147. package/src/factories/StatementFactory.ts +26 -1
  148. package/src/factories/SupportedStringFormats.ts +29 -0
  149. package/src/factories/TypeFactory.ts +21 -0
  150. package/src/factories/TypeLiteralFactory.ts +18 -0
  151. package/src/internal/ts.ts +153 -0
  152. package/src/programmers/NestiaMigrateApiFileProgrammer.ts +35 -0
  153. package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +53 -4
  154. package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +83 -20
  155. package/src/programmers/NestiaMigrateApiProgrammer.ts +18 -0
  156. package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +66 -73
  157. package/src/programmers/NestiaMigrateApiStartProgrammer.ts +19 -10
  158. package/src/programmers/NestiaMigrateDtoProgrammer.ts +33 -0
  159. package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +83 -8
  160. package/src/programmers/NestiaMigrateE2eProgrammer.ts +16 -0
  161. package/src/programmers/NestiaMigrateImportProgrammer.ts +86 -5
  162. package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +30 -0
  163. package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +122 -29
  164. package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +16 -0
  165. package/src/programmers/NestiaMigrateNestProgrammer.ts +17 -0
  166. package/src/programmers/NestiaMigrateSchemaProgrammer.ts +53 -18
  167. package/src/structures/INestiaMigrateConfig.ts +26 -0
  168. package/src/structures/INestiaMigrateContext.ts +17 -0
  169. package/src/structures/INestiaMigrateController.ts +16 -0
  170. package/src/structures/INestiaMigrateFile.ts +13 -0
  171. package/src/utils/FilePrinter.ts +33 -0
  172. package/src/utils/MapUtil.ts +18 -2
  173. package/src/utils/PathTemplate.ts +61 -0
  174. package/src/utils/RequestBody.ts +27 -0
  175. package/src/utils/StringUtil.ts +101 -9
  176. package/src/utils/SuccessStatus.ts +49 -0
  177. package/lib/factories/FormatCheatSheet.d.ts +0 -25
  178. package/lib/factories/FormatCheatSheet.js +0 -34
  179. package/lib/factories/FormatCheatSheet.js.map +0 -1
  180. package/lib/factories/FormatCheatSheet.mjs +0 -31
  181. package/lib/factories/FormatCheatSheet.mjs.map +0 -1
  182. package/src/factories/FormatCheatSheet.ts +0 -71
@@ -1,8 +1,24 @@
1
1
  import { IHttpMigrateRoute } from "@typia/interface";
2
2
 
3
+ /**
4
+ * A controller to generate: its name, its path, its source location, and its
5
+ * routes.
6
+ *
7
+ * @evidence contracts/common.md#principled-implementation The record is the output of the analyzer and the input of the controller programmer.
8
+ * @evidence contracts/common.md#clear-and-simple-design A four-member record.
9
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
10
+ * @evidence contracts/common.md#meaningful-documentation The comment lists the members.
11
+ */
3
12
  export interface INestiaMigrateController {
13
+ /** Class identifier shared by its declaration, filename and module import. */
4
14
  name: string;
15
+
16
+ /** Shared router path prefix, including router escapes for literal characters. */
5
17
  path: string;
18
+
19
+ /** Slash-separated source directory relative to the backend package. */
6
20
  location: string;
21
+
22
+ /** Operations grouped into this controller, in document order. */
7
23
  routes: IHttpMigrateRoute[];
8
24
  }
@@ -1,5 +1,18 @@
1
+ /**
2
+ * A generated file: its directory, its name, and its content.
3
+ *
4
+ * @evidence contracts/common.md#principled-implementation The record separates the location from the name so the writers can join them per mode.
5
+ * @evidence contracts/common.md#clear-and-simple-design A three-member record.
6
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
7
+ * @evidence contracts/common.md#meaningful-documentation The comment lists the members.
8
+ */
1
9
  export interface INestiaMigrateFile {
10
+ /** Slash-separated output directory relative to the generated project root. */
2
11
  location: string;
12
+
13
+ /** Filename within location. */
3
14
  file: string;
15
+
16
+ /** Complete source text written without another generation step. */
4
17
  content: string;
5
18
  }
@@ -7,7 +7,24 @@ import {
7
7
 
8
8
  import ts from "../internal/ts";
9
9
 
10
+ /**
11
+ * Helpers that turn statements and comments into file text.
12
+ *
13
+ * @evidence contracts/common.md#principled-implementation The namespace attaches a JSDoc comment to a node, builds a blank line, and prints a file from statements.
14
+ * @evidence contracts/common.md#clear-and-simple-design Three small functions.
15
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The comment text is escaped so it cannot end the comment early.
16
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
17
+ */
10
18
  export namespace FilePrinter {
19
+ /**
20
+ * Attaches a JSDoc comment made from the text to the node, and leaves the
21
+ * node alone when the text is empty.
22
+ *
23
+ * @evidence contracts/common.md#principled-implementation Line endings are normalized, each line is prefixed, and every comment terminator in the text is replaced by an escaped form, so a description can never end the comment early and inject code.
24
+ * @evidence contracts/common.md#clear-and-simple-design One function with an early return.
25
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The escaping applies to every line.
26
+ * @evidence contracts/common.md#meaningful-documentation The comment states the empty case and the escaping.
27
+ */
11
28
  export const description = <Node extends ts.Node>(
12
29
  node: Node,
13
30
  comment: string,
@@ -33,9 +50,25 @@ export namespace FilePrinter {
33
50
  return node;
34
51
  };
35
52
 
53
+ /**
54
+ * Builds a statement that prints as a blank line.
55
+ *
56
+ * @evidence contracts/common.md#principled-implementation The printer emits the identifier text as it is, so an identifier holding a newline produces an empty line between statements.
57
+ * @evidence contracts/common.md#clear-and-simple-design One expression.
58
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is the way the printer offers to space statements.
59
+ * @evidence contracts/common.md#meaningful-documentation The comment states what the statement prints.
60
+ */
36
61
  export const newLine = () =>
37
62
  factory.createExpressionStatement(factory.createIdentifier("\n"));
38
63
 
64
+ /**
65
+ * Prints the statements as a file, with an optional text at the top.
66
+ *
67
+ * @evidence contracts/common.md#principled-implementation The statements are printed by the factory package's printer, so the output is the source of the syntax tree.
68
+ * @evidence contracts/common.md#clear-and-simple-design One expression.
69
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It prints what it is given.
70
+ * @evidence contracts/common.md#meaningful-documentation The comment states the top text.
71
+ */
39
72
  export const write = (props: {
40
73
  statements: ts.Statement[];
41
74
  top?: string;
@@ -1,10 +1,26 @@
1
+ /**
2
+ * Helpers for maps.
3
+ *
4
+ * @evidence contracts/common.md#principled-implementation The namespace holds the get-or-create helper.
5
+ * @evidence contracts/common.md#clear-and-simple-design One function.
6
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a plain helper.
7
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
8
+ */
1
9
  export namespace MapUtil {
10
+ /**
11
+ * Returns the value of a key, creating and storing it with the generator when
12
+ * the key is absent.
13
+ *
14
+ * @evidence contracts/common.md#principled-implementation Presence is tested with `has`, so a stored falsy value is returned and not created again, and the generator runs once per key.
15
+ * @evidence contracts/common.md#clear-and-simple-design One check, one generator call, and one store.
16
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The stored value is returned as it is.
17
+ * @evidence contracts/common.md#meaningful-documentation The comment states when the generator runs.
18
+ */
2
19
  export const take =
3
20
  <Key, T>(dict: Map<Key, T>) =>
4
21
  (key: Key) =>
5
22
  (generator: () => T): T => {
6
- const oldbie: T | undefined = dict.get(key);
7
- if (oldbie) return oldbie;
23
+ if (dict.has(key)) return dict.get(key) as T;
8
24
 
9
25
  const value: T = generator();
10
26
  dict.set(key, value);
@@ -0,0 +1,61 @@
1
+ import { IHttpMigrateRoute } from "@typia/interface";
2
+
3
+ /**
4
+ * Splits a route path template into literal and parameter segments.
5
+ *
6
+ * @evidence contracts/common.md#principled-implementation The namespace scans the template for `{name}` placeholders and matches each with the route's parameter of that name.
7
+ * @evidence contracts/common.md#clear-and-simple-design One type and one function.
8
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The scan is by the template syntax.
9
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
10
+ */
11
+ export namespace PathTemplate {
12
+ /**
13
+ * A segment of a path: a literal text or a parameter.
14
+ *
15
+ * @evidence contracts/common.md#principled-implementation The union is discriminated by `type`, so a consumer handles each case once.
16
+ * @evidence contracts/common.md#clear-and-simple-design A two-member union.
17
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
18
+ * @evidence contracts/common.md#meaningful-documentation The comment names the two cases.
19
+ */
20
+ export type ISegment =
21
+ | { type: "literal"; value: string }
22
+ | { type: "param"; parameter: IHttpMigrateRoute.IParameter };
23
+
24
+ /**
25
+ * The route's path as literal text and path parameters, in order, read from
26
+ * the document's own template (`/files/{id}.json`), whose braces delimit each
27
+ * parameter name. The emended path (`/files/:id.json`) cannot be split back:
28
+ * its `:id.json` could name `id` or `id.json`, and a name such as `item-id`
29
+ * would read as `item` followed by `-id`. It always starts with `/`, as the
30
+ * emended path does. A placeholder without a matching route parameter remains
31
+ * literal text; adjacent literals are merged.
32
+ *
33
+ * @evidence contracts/common.md#principled-implementation The scan uses a regular expression over the placeholders and joins the text between them, and merging adjacent literals keeps the segment list minimal.
34
+ * @evidence contracts/common.md#clear-and-simple-design One function with one helper for merging.
35
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It never drops text of the template.
36
+ * @evidence contracts/common.md#meaningful-documentation The comment states the merging and the unmatched placeholder rule.
37
+ */
38
+ export const segments = (route: IHttpMigrateRoute): ISegment[] => {
39
+ const path: string = route.path.startsWith("/")
40
+ ? route.path
41
+ : `/${route.path}`;
42
+ const output: ISegment[] = [];
43
+ const literal = (value: string): void => {
44
+ if (value.length === 0) return;
45
+ const last: ISegment | undefined = output[output.length - 1];
46
+ if (last?.type === "literal") last.value += value;
47
+ else output.push({ type: "literal", value });
48
+ };
49
+ let cursor: number = 0;
50
+ for (const match of path.matchAll(/\{([^{}]+)\}/g)) {
51
+ literal(path.slice(cursor, match.index));
52
+ cursor = match.index! + match[0].length;
53
+ const parameter: IHttpMigrateRoute.IParameter | undefined =
54
+ route.parameters.find((p) => p.name === match[1]);
55
+ if (parameter === undefined) literal(match[0]);
56
+ else output.push({ type: "param", parameter });
57
+ }
58
+ literal(path.slice(cursor));
59
+ return output;
60
+ };
61
+ }
@@ -0,0 +1,27 @@
1
+ import { IHttpMigrateRoute } from "@typia/interface";
2
+
3
+ /**
4
+ * Helpers about the request body of a route.
5
+ *
6
+ * @evidence contracts/common.md#principled-implementation The namespace holds the optional-body predicate.
7
+ * @evidence contracts/common.md#clear-and-simple-design One function.
8
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a plain helper.
9
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
10
+ */
11
+ export namespace RequestBody {
12
+ /**
13
+ * Whether the route's body may be omitted: a JSON or text body the document
14
+ * does not require. The SDK's positional and keyword functions and the Nest
15
+ * controller all read this one rule.
16
+ *
17
+ * @evidence contracts/common.md#principled-implementation The requirement flag is read from the operation and only an explicit `false` makes the body optional.
18
+ * @evidence contracts/common.md#clear-and-simple-design One expression.
19
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It reads the document.
20
+ * @evidence contracts/common.md#meaningful-documentation The comment states the condition.
21
+ */
22
+ export const optional = (route: IHttpMigrateRoute): boolean =>
23
+ route.body !== null &&
24
+ (route.body.type === "application/json" ||
25
+ route.body.type === "text/plain") &&
26
+ route.operation().requestBody?.required === false;
27
+ }
@@ -1,24 +1,79 @@
1
+ /**
2
+ * String helpers that turn arbitrary text into valid identifiers and names.
3
+ *
4
+ * Identifier escaping traverses the input with a fixed punctuation table and
5
+ * Unicode-aware per-segment replacements; total work and intermediate storage
6
+ * scale with encoded output length.
7
+ *
8
+ * @evidence contracts/common.md#principled-implementation The namespace holds the capitalization, path segment normalization, and identifier escaping rules used by the generators.
9
+ * @evidence contracts/common.md#clear-and-simple-design Three functions and private tables of reserved words and replacements.
10
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The tables are the language's reserved words and a fixed replacement of punctuation.
11
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
12
+ */
1
13
  export namespace StringUtil {
2
- export const capitalize = (str: string) =>
3
- str[0]!.toUpperCase() + str.slice(1).toLowerCase();
14
+ /**
15
+ * Upper-cases the first character and lower-cases the rest; an empty string
16
+ * stays empty.
17
+ *
18
+ * One leading-character conversion and one remainder conversion cost O(N) in
19
+ * the input length.
20
+ *
21
+ * @evidence contracts/common.md#principled-implementation The first character is transformed alone and the remainder is lower-cased, so the result is a normalized word.
22
+ * @evidence contracts/common.md#clear-and-simple-design One expression.
23
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It applies to every input.
24
+ * @evidence contracts/common.md#meaningful-documentation The comment states the rule and the empty case.
25
+ */
26
+ export const capitalize = (str: string): string =>
27
+ str.length === 0 ? str : str[0]!.toUpperCase() + str.slice(1).toLowerCase();
4
28
 
29
+ /**
30
+ * Splits a path by slashes and normalizes each non-empty segment into a name.
31
+ *
32
+ * The path is split once and each segment normalized with a fixed number of
33
+ * transformations: O(N) total text work and output storage.
34
+ *
35
+ * @evidence contracts/common.md#principled-implementation Each segment loses dots and dashes, a reserved word or a leading digit gets an underscore prefix, and empty segments are dropped.
36
+ * @evidence contracts/common.md#clear-and-simple-design One expression over the private normalizer.
37
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The rules apply to every segment.
38
+ * @evidence contracts/common.md#meaningful-documentation The comment states the normalization.
39
+ */
5
40
  export const splitWithNormalization = (path: string) =>
6
41
  path
7
42
  .split("/")
8
43
  .map((str) => normalize(str.trim()))
9
44
  .filter((str) => !!str.length);
10
45
 
46
+ /**
47
+ * Escapes a string into a valid, possibly qualified, name.
48
+ *
49
+ * A dot separates the segments of a qualified name, so each segment is
50
+ * escaped as one identifier. Punctuation is replaced by a word such as
51
+ * `_at_`, any other character an identifier cannot hold by its code point, a
52
+ * reserved word or a segment that cannot start an identifier gets an
53
+ * underscore prefix, and an empty segment is `_empty_`. The last segment
54
+ * names a type, so it is also prefixed when it is a predefined type name.
55
+ *
56
+ * A fixed punctuation table traverses the text before per-segment Unicode
57
+ * escaping. Work scales linearly with the encoded text length for the fixed
58
+ * table; expanded code-point spellings are retained only in the returned
59
+ * string.
60
+ *
61
+ * @evidence contracts/common.md#principled-implementation Whitespace at the edges is trimmed and the punctuation table is applied in its fixed order over the whole string; the string is then split at the dots, which stay as the namespace separators the DTO tree reads, and every segment is made an identifier by the ECMAScript rule: characters outside `ID_Continue` become their code point, and a reserved word, a predefined type name in the last segment or a segment not starting with `ID_Start`, `_` or `$` is prefixed with an underscore, so each segment is a valid identifier even where the punctuation table does not cover its characters.
62
+ * @evidence contracts/common.md#clear-and-simple-design One function over one segment helper and three private tables of reserved words, predefined type names and replacements.
63
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts No schema name is special-cased; the fixed punctuation table and Unicode identifier rules apply to every segment.
64
+ * @evidence contracts/common.md#meaningful-documentation The comment states the segment rule, the replacements, the prefixes and the empty case.
65
+ */
11
66
  export const escapeNonVariable = (str: string): string => {
12
- str = escape(str);
67
+ str = str.trim();
13
68
  for (const [before, after] of VARIABLE_REPLACERS)
14
69
  str = str.split(before).join(after);
15
- for (let i: number = 0; i <= 9; ++i)
16
- if (str[0] === i.toString()) {
17
- str = "_" + str;
18
- break;
19
- }
20
70
  if (str === "") return "_empty_";
21
- return str;
71
+ const segments: string[] = str.split(".");
72
+ return segments
73
+ .map((segment, index) =>
74
+ escapeSegment(segment, index === segments.length - 1),
75
+ )
76
+ .join(".");
22
77
  };
23
78
  }
24
79
 
@@ -30,10 +85,42 @@ const escape = (str: string): string => {
30
85
  return str;
31
86
  };
32
87
 
88
+ // One identifier. The patterns are built at run time because the property
89
+ // escapes need a newer script target than the one this package compiles to.
90
+ const NON_IDENTIFIER_PART: RegExp = new RegExp("[^\\p{ID_Continue}]", "gu");
91
+ const IDENTIFIER_START: RegExp = new RegExp("^[\\p{ID_Start}_$]", "u");
92
+
93
+ const escapeSegment = (segment: string, type: boolean): string => {
94
+ segment = segment.replace(
95
+ NON_IDENTIFIER_PART,
96
+ (char) => `_u${char.codePointAt(0)!.toString(16)}_`,
97
+ );
98
+ if (segment.length === 0) return "_empty_";
99
+ return RESERVED.has(segment) ||
100
+ (type && TYPE_NAMES.has(segment)) ||
101
+ IDENTIFIER_START.test(segment) === false
102
+ ? `_${segment}`
103
+ : segment;
104
+ };
105
+
33
106
  const normalize = (str: string): string =>
34
107
  escape(str.split(".").join("_").split("-").join("_"));
35
108
 
109
+ const TYPE_NAMES: Set<string> = new Set([
110
+ "any",
111
+ "bigint",
112
+ "boolean",
113
+ "never",
114
+ "number",
115
+ "object",
116
+ "string",
117
+ "symbol",
118
+ "undefined",
119
+ "unknown",
120
+ ]);
121
+
36
122
  const RESERVED: Set<string> = new Set([
123
+ "await",
37
124
  "break",
38
125
  "case",
39
126
  "catch",
@@ -53,9 +140,12 @@ const RESERVED: Set<string> = new Set([
53
140
  "for",
54
141
  "function",
55
142
  "if",
143
+ "implements",
56
144
  "import",
57
145
  "in",
58
146
  "instanceof",
147
+ "interface",
148
+ "let",
59
149
  "module",
60
150
  "new",
61
151
  "null",
@@ -64,6 +154,7 @@ const RESERVED: Set<string> = new Set([
64
154
  "private",
65
155
  "protected",
66
156
  "return",
157
+ "static",
67
158
  "super",
68
159
  "switch",
69
160
  "this",
@@ -75,6 +166,7 @@ const RESERVED: Set<string> = new Set([
75
166
  "void",
76
167
  "while",
77
168
  "with",
169
+ "yield",
78
170
  ]);
79
171
 
80
172
  const VARIABLE_REPLACERS: [string, string][] = [
@@ -0,0 +1,49 @@
1
+ import { IHttpMigrateRoute } from "@typia/interface";
2
+
3
+ /**
4
+ * Helpers about the success status of a route.
5
+ *
6
+ * @evidence contracts/common.md#principled-implementation The namespace holds the status that the SDK should treat as success and the status that the generated NestJS controller answers.
7
+ * @evidence contracts/common.md#clear-and-simple-design Two functions and one private priority.
8
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The rules follow HTTP conventions.
9
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
10
+ */
11
+ export namespace SuccessStatus {
12
+ /**
13
+ * The route's success status code, or null when the document declares only a
14
+ * range (`2XX`) or a `default` response.
15
+ *
16
+ * The success response is the one typia's route composer selects: 200, then
17
+ * 201, then the lowest other 2xx. A bodiless one, such as a 204 No Content,
18
+ * leaves `route.success` null, so its status is read from the responses.
19
+ *
20
+ * @evidence contracts/common.md#principled-implementation The candidates are the 2xx keys of the responses ordered by a fixed priority, and a value that is not a three-digit number is rejected.
21
+ * @evidence contracts/common.md#clear-and-simple-design One function with one priority helper.
22
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The order is the HTTP convention.
23
+ * @evidence contracts/common.md#meaningful-documentation The comment states the selection.
24
+ */
25
+ export const of = (route: IHttpMigrateRoute): number | null => {
26
+ const status: string | undefined =
27
+ route.success?.status ??
28
+ Object.keys(route.operation().responses ?? {})
29
+ .filter((key) => /^2\d\d$/.test(key))
30
+ .sort((x, y) => priority(x) - priority(y))[0];
31
+ return status !== undefined && /^\d{3}$/.test(status)
32
+ ? Number(status)
33
+ : null;
34
+ };
35
+
36
+ /**
37
+ * The status NestJS answers without `@HttpCode()`.
38
+ *
39
+ * @evidence contracts/common.md#principled-implementation NestJS answers 201 for POST and 200 for the other methods when no status is set, so a generated controller matches without an explicit one.
40
+ * @evidence contracts/common.md#clear-and-simple-design One expression.
41
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The rule is NestJS's.
42
+ * @evidence contracts/common.md#meaningful-documentation The comment states the two statuses.
43
+ */
44
+ export const nest = (route: IHttpMigrateRoute): number =>
45
+ route.method === "post" ? 201 : 200;
46
+
47
+ const priority = (status: string): number =>
48
+ status === "200" ? 0 : status === "201" ? 1 : Number(status);
49
+ }
@@ -1,25 +0,0 @@
1
- /** @reference https://github.dev/ajv-validator/ajv-formats/blob/master/src/formats.ts */
2
- export declare const FormatCheatSheet: {
3
- readonly byte: "/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm.test($input)";
4
- readonly password: `true`;
5
- readonly regex: `(() => { try { new RegExp($input); return true; } catch { return false; } })()`;
6
- readonly uuid: "/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test($input)";
7
- readonly email: "/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test($input)";
8
- readonly hostname: "/^(?=.{1,253}\\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\\.?$/i.test($input)";
9
- readonly "idn-email": "/^(([^<>()[\\]\\.,;:\\s@\\\"]+(\\.[^<>()[\\]\\.,;:\\s@\\\"]+)*)|(\\\".+\\\"))@(([^<>()[\\]\\.,;:\\s@\\\"]+\\.)+[^<>()[\\]\\.,;:\\s@\\\"]{2,})$/i.test($input)";
10
- readonly "idn-hostname": "/^([a-z0-9\\u00a1-\\uffff0-9]+(-[a-z0-9\\u00a1-\\uffff0-9]+)*\\.)+[a-z\\u00a1-\\uffff]{2,}$/i.test($input)";
11
- readonly iri: "/^[A-Za-z][\\d+-.A-Za-z]*:[^\\u0000-\\u0020\"<>\\\\^`{|}]*$/u.test($input)";
12
- readonly "iri-reference": "/^[A-Za-z][\\d+-.A-Za-z]*:[^\\u0000-\\u0020\"<>\\\\^`{|}]*$/u.test($input)";
13
- readonly ipv4: "/^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/.test($input)";
14
- readonly ipv6: "/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))$/i.test($input)";
15
- readonly uri: "/\\/|:/.test($input) && /^(?:[a-z][a-z0-9+\\-.]*:)(?:\\/?\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::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[0-4]\\d|[01]?\\d\\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\\.[a-z0-9\\-._~!$&'()*+,;=:]+)\\]|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)|(?:[a-z0-9\\-._~!$&'\"()*+,;=]|%[0-9a-f]{2})*)(?::\\d*)?(?:\\/(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})*)*|\\/(?:(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\\?(?:[a-z0-9\\-._~!$&'\"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'\"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i.test($input)";
17
- readonly "uri-template": "/^(?:(?:[^\\x00-\\x20\"'<>%\\\\^`{|}]|%[0-9a-f]{2})|\\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?)*\\})*$/i.test($input)";
18
- readonly url: "/^(?:https?|ftp):\\/\\/(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)(?:\\.(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)*(?:\\.(?:[a-z\\u{00a1}-\\u{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$/iu.test($input)";
19
- readonly "date-time": "/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i.test($input)";
20
- readonly date: "/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test($input)";
21
- readonly time: "/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i.test($input)";
22
- readonly duration: "/^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?|(\\d+W)?)$/.test($input)";
23
- readonly "json-pointer": "/^(?:\\/(?:[^~/]|~0|~1)*)*$/.test($input)";
24
- readonly "relative-json-pointer": "/^(?:0|[1-9][0-9]*)(?:#|(?:\\/(?:[^~/]|~0|~1)*)*)$/.test($input)";
25
- };
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatCheatSheet = void 0;
4
- const RegexCall = (text) => `${text}.test($input)`;
5
- /** @reference https://github.dev/ajv-validator/ajv-formats/blob/master/src/formats.ts */
6
- exports.FormatCheatSheet = {
7
- // SPECIAL CHARACTERS
8
- byte: RegexCall(`/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm`),
9
- password: `true`,
10
- regex: `(() => { try { new RegExp($input); return true; } catch { return false; } })()`,
11
- uuid: RegexCall(`/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i`),
12
- // ADDRESSES
13
- email: RegexCall(`/^[a-z0-9!#$%&'*+/=?^_\`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i`),
14
- hostname: RegexCall(`/^(?=.{1,253}\\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\\.?$/i`),
15
- "idn-email": RegexCall(`/^(([^<>()[\\]\\.,;:\\s@\\"]+(\\.[^<>()[\\]\\.,;:\\s@\\"]+)*)|(\\".+\\"))@(([^<>()[\\]\\.,;:\\s@\\"]+\\.)+[^<>()[\\]\\.,;:\\s@\\"]{2,})$/i`),
16
- "idn-hostname": RegexCall(`/^([a-z0-9\\u00a1-\\uffff0-9]+(-[a-z0-9\\u00a1-\\uffff0-9]+)*\\.)+[a-z\\u00a1-\\uffff]{2,}$/i`),
17
- iri: RegexCall(`/^[A-Za-z][\\d+-.A-Za-z]*:[^\\u0000-\\u0020"<>\\\\^\`{|}]*$/u`),
18
- "iri-reference": RegexCall(`/^[A-Za-z][\\d+-.A-Za-z]*:[^\\u0000-\\u0020"<>\\\\^\`{|}]*$/u`),
19
- ipv4: RegexCall(`/^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/`),
20
- ipv6: RegexCall(`/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i`),
21
- uri: `${RegexCall(`/\\/|:/`)} && ${RegexCall(`/^(?:[a-z][a-z0-9+\\-.]*:)(?:\\/?\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:]|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/(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\\?(?:[a-z0-9\\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i`),
23
- "uri-template": RegexCall(`/^(?:(?:[^\\x00-\\x20"'<>%\\\\^\`{|}]|%[0-9a-f]{2})|\\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?)*\\})*$/i`),
24
- url: RegexCall(`/^(?:https?|ftp):\\/\\/(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)(?:\\.(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)*(?:\\.(?:[a-z\\u{00a1}-\\u{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$/iu`),
25
- // TIMESTAMPS
26
- "date-time": RegexCall(`/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i`),
27
- date: RegexCall(`/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/`),
28
- time: RegexCall(`/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i`),
29
- duration: RegexCall(`/^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?|(\\d+W)?)$/`),
30
- // POINTERS
31
- "json-pointer": RegexCall(`/^(?:\\/(?:[^~/]|~0|~1)*)*$/`),
32
- "relative-json-pointer": RegexCall(`/^(?:0|[1-9][0-9]*)(?:#|(?:\\/(?:[^~/]|~0|~1)*)*)$/`),
33
- };
34
- //# sourceMappingURL=FormatCheatSheet.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormatCheatSheet.js","sourceRoot":"","sources":["../../src/factories/FormatCheatSheet.ts"],"names":[],"mappings":";;;AAAA,MAAM,SAAS,GAAG,CAAsB,IAAU,EAAE,EAAE,CACpD,GAAG,IAAI,eAAwB,CAAC;AAElC,yFAAyF;AAC5E,QAAA,gBAAgB,GAAG;IAC9B,qBAAqB;IACrB,IAAI,EAAE,SAAS,CACb,sEAAsE,CACvE;IACD,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,gFAAgF;IACvF,IAAI,EAAE,SAAS,CACb,gEAAgE,CACjE;IAED,YAAY;IACZ,KAAK,EAAE,SAAS,CACd,gJAAgJ,CACjJ;IACD,QAAQ,EAAE,SAAS,CACjB,4GAA4G,CAC7G;IACD,WAAW,EAAE,SAAS,CACpB,4IAA4I,CAC7I;IACD,cAAc,EAAE,SAAS,CACvB,+FAA+F,CAChG;IACD,GAAG,EAAE,SAAS,CACZ,+DAA+D,CAChE;IACD,eAAe,EAAE,SAAS,CACxB,+DAA+D,CAChE;IACD,IAAI,EAAE,SAAS,CACb,8FAA8F,CAC/F;IACD,IAAI,EAAE,SAAS,CACb,o/BAAo/B,CACr/B;IACD,GAAG,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,OAAO,SAAS,CAC1C,oqCAAoqC,CACrqC,EAAE;IACH,eAAe,EAAE,SAAS,CACxB,8qCAA8qC,CAC/qC;IACD,cAAc,EAAE,SAAS,CACvB,8LAA8L,CAC/L;IACD,GAAG,EAAE,SAAS,CACZ,+fAA+f,CAChgB;IAED,aAAa;IACb,WAAW,EAAE,SAAS,CACpB,8JAA8J,CAC/J;IACD,IAAI,EAAE,SAAS,CAAC,uDAAuD,CAAC;IACxE,IAAI,EAAE,SAAS,CACb,sGAAsG,CACvG;IACD,QAAQ,EAAE,SAAS,CACjB,kFAAkF,CACnF;IAED,WAAW;IACX,cAAc,EAAE,SAAS,CAAC,8BAA8B,CAAC;IACzD,uBAAuB,EAAE,SAAS,CAChC,qDAAqD,CACtD;CACO,CAAC"}
@@ -1,31 +0,0 @@
1
- //#region src/factories/FormatCheatSheet.ts
2
- const RegexCall = (text) => `${text}.test($input)`;
3
- /** @reference https://github.dev/ajv-validator/ajv-formats/blob/master/src/formats.ts */
4
- const FormatCheatSheet = {
5
- byte: RegexCall(`/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm`),
6
- password: `true`,
7
- regex: `(() => { try { new RegExp($input); return true; } catch { return false; } })()`,
8
- uuid: RegexCall(`/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i`),
9
- email: RegexCall(`/^[a-z0-9!#$%&'*+/=?^_\`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i`),
10
- hostname: RegexCall(`/^(?=.{1,253}\\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\\.?$/i`),
11
- "idn-email": RegexCall(`/^(([^<>()[\\]\\.,;:\\s@\\"]+(\\.[^<>()[\\]\\.,;:\\s@\\"]+)*)|(\\".+\\"))@(([^<>()[\\]\\.,;:\\s@\\"]+\\.)+[^<>()[\\]\\.,;:\\s@\\"]{2,})$/i`),
12
- "idn-hostname": RegexCall(`/^([a-z0-9\\u00a1-\\uffff0-9]+(-[a-z0-9\\u00a1-\\uffff0-9]+)*\\.)+[a-z\\u00a1-\\uffff]{2,}$/i`),
13
- iri: RegexCall(`/^[A-Za-z][\\d+-.A-Za-z]*:[^\\u0000-\\u0020"<>\\\\^\`{|}]*$/u`),
14
- "iri-reference": RegexCall(`/^[A-Za-z][\\d+-.A-Za-z]*:[^\\u0000-\\u0020"<>\\\\^\`{|}]*$/u`),
15
- ipv4: RegexCall(`/^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/`),
16
- ipv6: RegexCall(`/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5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]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\\.[a-z0-9\\-._~!$&'()*+,;=:]+)\\]|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)|(?:[a-z0-9\\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\\d*)?(?:\\/(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\\/(?:(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\\?(?:[a-z0-9\\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i`),
19
- "uri-template": RegexCall(`/^(?:(?:[^\\x00-\\x20"'<>%\\\\^\`{|}]|%[0-9a-f]{2})|\\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?)*\\})*$/i`),
20
- url: RegexCall(`/^(?:https?|ftp):\\/\\/(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)(?:\\.(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)*(?:\\.(?:[a-z\\u{00a1}-\\u{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$/iu`),
21
- "date-time": RegexCall(`/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i`),
22
- date: RegexCall(`/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/`),
23
- time: RegexCall(`/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i`),
24
- duration: RegexCall(`/^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?|(\\d+W)?)$/`),
25
- "json-pointer": RegexCall(`/^(?:\\/(?:[^~/]|~0|~1)*)*$/`),
26
- "relative-json-pointer": RegexCall(`/^(?:0|[1-9][0-9]*)(?:#|(?:\\/(?:[^~/]|~0|~1)*)*)$/`)
27
- };
28
- //#endregion
29
- export { FormatCheatSheet };
30
-
31
- //# sourceMappingURL=FormatCheatSheet.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormatCheatSheet.mjs","names":[],"sources":[],"mappings":""}
@@ -1,71 +0,0 @@
1
- const RegexCall = <Text extends string>(text: Text) =>
2
- `${text}.test($input)` as const;
3
-
4
- /** @reference https://github.dev/ajv-validator/ajv-formats/blob/master/src/formats.ts */
5
- export const FormatCheatSheet = {
6
- // SPECIAL CHARACTERS
7
- byte: RegexCall(
8
- `/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm`,
9
- ),
10
- password: `true`,
11
- regex: `(() => { try { new RegExp($input); return true; } catch { return false; } })()`,
12
- uuid: RegexCall(
13
- `/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i`,
14
- ),
15
-
16
- // ADDRESSES
17
- email: RegexCall(
18
- `/^[a-z0-9!#$%&'*+/=?^_\`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i`,
19
- ),
20
- hostname: RegexCall(
21
- `/^(?=.{1,253}\\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\\.?$/i`,
22
- ),
23
- "idn-email": RegexCall(
24
- `/^(([^<>()[\\]\\.,;:\\s@\\"]+(\\.[^<>()[\\]\\.,;:\\s@\\"]+)*)|(\\".+\\"))@(([^<>()[\\]\\.,;:\\s@\\"]+\\.)+[^<>()[\\]\\.,;:\\s@\\"]{2,})$/i`,
25
- ),
26
- "idn-hostname": RegexCall(
27
- `/^([a-z0-9\\u00a1-\\uffff0-9]+(-[a-z0-9\\u00a1-\\uffff0-9]+)*\\.)+[a-z\\u00a1-\\uffff]{2,}$/i`,
28
- ),
29
- iri: RegexCall(
30
- `/^[A-Za-z][\\d+-.A-Za-z]*:[^\\u0000-\\u0020"<>\\\\^\`{|}]*$/u`,
31
- ),
32
- "iri-reference": RegexCall(
33
- `/^[A-Za-z][\\d+-.A-Za-z]*:[^\\u0000-\\u0020"<>\\\\^\`{|}]*$/u`,
34
- ),
35
- ipv4: RegexCall(
36
- `/^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/`,
37
- ),
38
- ipv6: RegexCall(
39
- `/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[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f]{2})*)(?::\\d*)?(?:\\/(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\\/(?:(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\\?(?:[a-z0-9\\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i`,
46
- ),
47
- "uri-template": RegexCall(
48
- `/^(?:(?:[^\\x00-\\x20"'<>%\\\\^\`{|}]|%[0-9a-f]{2})|\\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?)*\\})*$/i`,
49
- ),
50
- url: RegexCall(
51
- `/^(?:https?|ftp):\\/\\/(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)(?:\\.(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)*(?:\\.(?:[a-z\\u{00a1}-\\u{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$/iu`,
52
- ),
53
-
54
- // TIMESTAMPS
55
- "date-time": RegexCall(
56
- `/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i`,
57
- ),
58
- date: RegexCall(`/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/`),
59
- time: RegexCall(
60
- `/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i`,
61
- ),
62
- duration: RegexCall(
63
- `/^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?|(\\d+W)?)$/`,
64
- ),
65
-
66
- // POINTERS
67
- "json-pointer": RegexCall(`/^(?:\\/(?:[^~/]|~0|~1)*)*$/`),
68
- "relative-json-pointer": RegexCall(
69
- `/^(?:0|[1-9][0-9]*)(?:#|(?:\\/(?:[^~/]|~0|~1)*)*)$/`,
70
- ),
71
- } as const;