@mionjs/type-formats 0.8.0-alpha.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 (134) hide show
  1. package/.dist/cjs/BigintFormats.cjs +14 -0
  2. package/.dist/cjs/BigintFormats.cjs.map +1 -0
  3. package/.dist/cjs/BigintFormats.d.ts +2 -0
  4. package/.dist/cjs/NumberFormats.cjs +20 -0
  5. package/.dist/cjs/NumberFormats.cjs.map +1 -0
  6. package/.dist/cjs/NumberFormats.d.ts +2 -0
  7. package/.dist/cjs/StringFormats.cjs +120 -0
  8. package/.dist/cjs/StringFormats.cjs.map +1 -0
  9. package/.dist/cjs/StringFormats.d.ts +11 -0
  10. package/.dist/cjs/constants.d.ts +1 -0
  11. package/.dist/cjs/package.json +1 -0
  12. package/.dist/cjs/src/bigint/bigIntFormat.runtype.cjs +152 -0
  13. package/.dist/cjs/src/bigint/bigIntFormat.runtype.cjs.map +1 -0
  14. package/.dist/cjs/src/bigint/bigIntFormat.runtype.d.ts +21 -0
  15. package/.dist/cjs/src/bigint/defaultBigNumberFormats.cjs +16 -0
  16. package/.dist/cjs/src/bigint/defaultBigNumberFormats.cjs.map +1 -0
  17. package/.dist/cjs/src/bigint/defaultBigNumberFormats.d.ts +29 -0
  18. package/.dist/cjs/src/constants.cjs +34 -0
  19. package/.dist/cjs/src/constants.cjs.map +1 -0
  20. package/.dist/cjs/src/constants.d.ts +15 -0
  21. package/.dist/cjs/src/constants.mock.cjs +111 -0
  22. package/.dist/cjs/src/constants.mock.cjs.map +1 -0
  23. package/.dist/cjs/src/constants.mock.d.ts +335 -0
  24. package/.dist/cjs/src/number/defaultNumberFormats.cjs +28 -0
  25. package/.dist/cjs/src/number/defaultNumberFormats.cjs.map +1 -0
  26. package/.dist/cjs/src/number/defaultNumberFormats.d.ts +63 -0
  27. package/.dist/cjs/src/number/numberFormat.runtype.cjs +214 -0
  28. package/.dist/cjs/src/number/numberFormat.runtype.cjs.map +1 -0
  29. package/.dist/cjs/src/number/numberFormat.runtype.d.ts +21 -0
  30. package/.dist/cjs/src/string/date.runtype.cjs +88 -0
  31. package/.dist/cjs/src/string/date.runtype.cjs.map +1 -0
  32. package/.dist/cjs/src/string/date.runtype.d.ts +19 -0
  33. package/.dist/cjs/src/string/dateTime.runtype.cjs +83 -0
  34. package/.dist/cjs/src/string/dateTime.runtype.cjs.map +1 -0
  35. package/.dist/cjs/src/string/dateTime.runtype.d.ts +26 -0
  36. package/.dist/cjs/src/string/defaultStringFormats.runtype.cjs +25 -0
  37. package/.dist/cjs/src/string/defaultStringFormats.runtype.cjs.map +1 -0
  38. package/.dist/cjs/src/string/defaultStringFormats.runtype.d.ts +45 -0
  39. package/.dist/cjs/src/string/domain.runtype.cjs +248 -0
  40. package/.dist/cjs/src/string/domain.runtype.cjs.map +1 -0
  41. package/.dist/cjs/src/string/domain.runtype.d.ts +72 -0
  42. package/.dist/cjs/src/string/email.runtype.cjs +159 -0
  43. package/.dist/cjs/src/string/email.runtype.cjs.map +1 -0
  44. package/.dist/cjs/src/string/email.runtype.d.ts +57 -0
  45. package/.dist/cjs/src/string/ip.runtype.cjs +72 -0
  46. package/.dist/cjs/src/string/ip.runtype.cjs.map +1 -0
  47. package/.dist/cjs/src/string/ip.runtype.d.ts +50 -0
  48. package/.dist/cjs/src/string/stringFormat.runtype.cjs +270 -0
  49. package/.dist/cjs/src/string/stringFormat.runtype.cjs.map +1 -0
  50. package/.dist/cjs/src/string/stringFormat.runtype.d.ts +21 -0
  51. package/.dist/cjs/src/string/time.runtype.cjs +100 -0
  52. package/.dist/cjs/src/string/time.runtype.cjs.map +1 -0
  53. package/.dist/cjs/src/string/time.runtype.d.ts +21 -0
  54. package/.dist/cjs/src/string/url.runtype.cjs +160 -0
  55. package/.dist/cjs/src/string/url.runtype.cjs.map +1 -0
  56. package/.dist/cjs/src/string/url.runtype.d.ts +81 -0
  57. package/.dist/cjs/src/string/uuid.runtype.cjs +44 -0
  58. package/.dist/cjs/src/string/uuid.runtype.cjs.map +1 -0
  59. package/.dist/cjs/src/string/uuid.runtype.d.ts +22 -0
  60. package/.dist/cjs/src/type-formats-pure-fns.cjs +390 -0
  61. package/.dist/cjs/src/type-formats-pure-fns.cjs.map +1 -0
  62. package/.dist/cjs/src/type-formats-pure-fns.d.ts +27 -0
  63. package/.dist/cjs/src/utils.cjs +14 -0
  64. package/.dist/cjs/src/utils.cjs.map +1 -0
  65. package/.dist/cjs/src/utils.d.ts +3 -0
  66. package/.dist/cjs/vitest.config.d.ts +2 -0
  67. package/.dist/esm/BigintFormats.d.ts +2 -0
  68. package/.dist/esm/BigintFormats.js +14 -0
  69. package/.dist/esm/BigintFormats.js.map +1 -0
  70. package/.dist/esm/NumberFormats.d.ts +2 -0
  71. package/.dist/esm/NumberFormats.js +20 -0
  72. package/.dist/esm/NumberFormats.js.map +1 -0
  73. package/.dist/esm/StringFormats.d.ts +11 -0
  74. package/.dist/esm/StringFormats.js +120 -0
  75. package/.dist/esm/StringFormats.js.map +1 -0
  76. package/.dist/esm/constants.d.ts +1 -0
  77. package/.dist/esm/src/bigint/bigIntFormat.runtype.d.ts +21 -0
  78. package/.dist/esm/src/bigint/bigIntFormat.runtype.js +152 -0
  79. package/.dist/esm/src/bigint/bigIntFormat.runtype.js.map +1 -0
  80. package/.dist/esm/src/bigint/defaultBigNumberFormats.d.ts +29 -0
  81. package/.dist/esm/src/bigint/defaultBigNumberFormats.js +16 -0
  82. package/.dist/esm/src/bigint/defaultBigNumberFormats.js.map +1 -0
  83. package/.dist/esm/src/constants.d.ts +15 -0
  84. package/.dist/esm/src/constants.js +34 -0
  85. package/.dist/esm/src/constants.js.map +1 -0
  86. package/.dist/esm/src/constants.mock.d.ts +335 -0
  87. package/.dist/esm/src/constants.mock.js +111 -0
  88. package/.dist/esm/src/constants.mock.js.map +1 -0
  89. package/.dist/esm/src/number/defaultNumberFormats.d.ts +63 -0
  90. package/.dist/esm/src/number/defaultNumberFormats.js +28 -0
  91. package/.dist/esm/src/number/defaultNumberFormats.js.map +1 -0
  92. package/.dist/esm/src/number/numberFormat.runtype.d.ts +21 -0
  93. package/.dist/esm/src/number/numberFormat.runtype.js +214 -0
  94. package/.dist/esm/src/number/numberFormat.runtype.js.map +1 -0
  95. package/.dist/esm/src/string/date.runtype.d.ts +19 -0
  96. package/.dist/esm/src/string/date.runtype.js +88 -0
  97. package/.dist/esm/src/string/date.runtype.js.map +1 -0
  98. package/.dist/esm/src/string/dateTime.runtype.d.ts +26 -0
  99. package/.dist/esm/src/string/dateTime.runtype.js +83 -0
  100. package/.dist/esm/src/string/dateTime.runtype.js.map +1 -0
  101. package/.dist/esm/src/string/defaultStringFormats.runtype.d.ts +45 -0
  102. package/.dist/esm/src/string/defaultStringFormats.runtype.js +25 -0
  103. package/.dist/esm/src/string/defaultStringFormats.runtype.js.map +1 -0
  104. package/.dist/esm/src/string/domain.runtype.d.ts +72 -0
  105. package/.dist/esm/src/string/domain.runtype.js +248 -0
  106. package/.dist/esm/src/string/domain.runtype.js.map +1 -0
  107. package/.dist/esm/src/string/email.runtype.d.ts +57 -0
  108. package/.dist/esm/src/string/email.runtype.js +159 -0
  109. package/.dist/esm/src/string/email.runtype.js.map +1 -0
  110. package/.dist/esm/src/string/ip.runtype.d.ts +50 -0
  111. package/.dist/esm/src/string/ip.runtype.js +72 -0
  112. package/.dist/esm/src/string/ip.runtype.js.map +1 -0
  113. package/.dist/esm/src/string/stringFormat.runtype.d.ts +21 -0
  114. package/.dist/esm/src/string/stringFormat.runtype.js +270 -0
  115. package/.dist/esm/src/string/stringFormat.runtype.js.map +1 -0
  116. package/.dist/esm/src/string/time.runtype.d.ts +21 -0
  117. package/.dist/esm/src/string/time.runtype.js +100 -0
  118. package/.dist/esm/src/string/time.runtype.js.map +1 -0
  119. package/.dist/esm/src/string/url.runtype.d.ts +81 -0
  120. package/.dist/esm/src/string/url.runtype.js +160 -0
  121. package/.dist/esm/src/string/url.runtype.js.map +1 -0
  122. package/.dist/esm/src/string/uuid.runtype.d.ts +22 -0
  123. package/.dist/esm/src/string/uuid.runtype.js +44 -0
  124. package/.dist/esm/src/string/uuid.runtype.js.map +1 -0
  125. package/.dist/esm/src/type-formats-pure-fns.d.ts +27 -0
  126. package/.dist/esm/src/type-formats-pure-fns.js +390 -0
  127. package/.dist/esm/src/type-formats-pure-fns.js.map +1 -0
  128. package/.dist/esm/src/utils.d.ts +3 -0
  129. package/.dist/esm/src/utils.js +14 -0
  130. package/.dist/esm/src/utils.js.map +1 -0
  131. package/.dist/esm/vitest.config.d.ts +2 -0
  132. package/LICENSE +21 -0
  133. package/README.md +123 -0
  134. package/package.json +80 -0
@@ -0,0 +1,100 @@
1
+ import { registerFormatter, BaseRunTypeFormat, __ΩTypeFormat as ___TypeFormat } from "@mionjs/run-types";
2
+ import { ReflectionKind } from "@deepkit/type";
3
+ import { paramVal } from "../utils.js";
4
+ import { cpf_isSeconds, cpf_isMinutes, cpf_isHours, cpf_isTimeString_mmss, cpf_isTimeString_HHmm, cpf_isTimeString_HHmmss, cpf_isTimeString_ISO, cpf_isTimeString_ISO_TZ } from "../type-formats-pure-fns.js";
5
+ class TimeStringRunTypeFormat extends BaseRunTypeFormat {
6
+ static id = "time";
7
+ kind = ReflectionKind.string;
8
+ name = TimeStringRunTypeFormat.id;
9
+ emitIsType(comp, rt) {
10
+ const params = this.getParams(rt);
11
+ const formatFn = this.getFormatPureFn(paramVal(params.format));
12
+ return { code: this.compilePureFunctionCall(comp, rt, formatFn).callCode, type: "E" };
13
+ }
14
+ emitIsTypeErrors(comp, rt) {
15
+ const isTypeCodeObj = this.emitIsType(comp, rt);
16
+ const isTypeCode = isTypeCodeObj.code;
17
+ if (!isTypeCode)
18
+ return { code: "", type: "S" };
19
+ const params = this.getParams(rt);
20
+ const errFn = this.getCallJitFormatErr(comp, rt, this);
21
+ return { code: `if (!(${isTypeCode})) ${errFn("format", paramVal(params.format))}`, type: "S" };
22
+ }
23
+ _mock(opts, rt) {
24
+ const params = this.getParams(rt);
25
+ const hours = String(Math.floor(Math.random() * 24)).padStart(2, "0");
26
+ const minutes = String(Math.floor(Math.random() * 60)).padStart(2, "0");
27
+ const seconds = String(Math.floor(Math.random() * 60)).padStart(2, "0");
28
+ switch (paramVal(params.format)) {
29
+ case "ISO":
30
+ // ISO
31
+ case "HH:mm:ss[.mmm]TZ":
32
+ return `${hours}:${minutes}:${seconds}${mockMilliseconds()}${mockTimeZone()}`;
33
+ case "HH:mm:ss[.mmm]":
34
+ return `${hours}:${minutes}:${seconds}${mockMilliseconds()}`;
35
+ case "HH:mm:ss":
36
+ return `${hours}:${minutes}:${seconds}`;
37
+ case "HH:mm":
38
+ return `${hours}:${minutes}`;
39
+ case "mm:ss":
40
+ return `${minutes}:${seconds}`;
41
+ case "HH":
42
+ return hours;
43
+ case "mm":
44
+ return minutes;
45
+ case "ss":
46
+ return seconds;
47
+ default:
48
+ throw new Error(`Invalid time format: ${paramVal(params.format)}`);
49
+ }
50
+ }
51
+ getFormatPureFn(format) {
52
+ switch (format) {
53
+ case "ISO":
54
+ case "HH:mm:ss[.mmm]TZ":
55
+ return cpf_isTimeString_ISO_TZ;
56
+ case "HH:mm:ss[.mmm]":
57
+ return cpf_isTimeString_ISO;
58
+ case "HH:mm:ss":
59
+ return cpf_isTimeString_HHmmss;
60
+ case "HH:mm":
61
+ return cpf_isTimeString_HHmm;
62
+ case "mm:ss":
63
+ return cpf_isTimeString_mmss;
64
+ case "HH":
65
+ return cpf_isHours;
66
+ case "mm":
67
+ return cpf_isMinutes;
68
+ case "ss":
69
+ return cpf_isSeconds;
70
+ default:
71
+ throw new Error(`Invalid time format: ${format}`);
72
+ }
73
+ }
74
+ }
75
+ function mockMilliseconds() {
76
+ const showMilliseconds = Math.random() > 0.5;
77
+ if (!showMilliseconds)
78
+ return "";
79
+ return `.${String(Math.floor(Math.random() * 1e3)).padStart(3, "0")}`;
80
+ }
81
+ function mockTimeZone() {
82
+ const isZ = Math.random() > 0.5;
83
+ if (isZ)
84
+ return "Z";
85
+ const hours = String(Math.floor(Math.random() * 24)).padStart(2, "0");
86
+ const minutes = String(Math.floor(Math.random() * 60)).padStart(2, "0");
87
+ return `${Math.random() > 0.5 ? "+" : "-"}${hours}:${minutes}`;
88
+ }
89
+ const TIME_RUN_TYPE_FORMATTER = registerFormatter(new TimeStringRunTypeFormat());
90
+ const __ΩDEFAULT_TIME_FORMAT_PARAMS = ["ISO", "format", "DEFAULT_TIME_FORMAT_PARAMS", 'P.!4"Mw#y'];
91
+ const __ΩFormatStringTime = [() => __ΩDEFAULT_TIME_FORMAT_PARAMS, "P", () => ___TypeFormat, () => TimeStringRunTypeFormat.id, "time", "FormatStringTime", 'n!c"&i$e!!.%o#%w&y'];
92
+ export {
93
+ TIME_RUN_TYPE_FORMATTER,
94
+ TimeStringRunTypeFormat,
95
+ __ΩDEFAULT_TIME_FORMAT_PARAMS,
96
+ __ΩFormatStringTime,
97
+ mockMilliseconds,
98
+ mockTimeZone
99
+ };
100
+ //# sourceMappingURL=time.runtype.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.runtype.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,81 @@
1
+ import { BaseRunType, JitFnCompiler, JitErrorsFnCompiler, JitCode, StrNumber, BaseRunTypeFormat, TypeFormat, RunTypeOptions } from '@mionjs/run-types';
2
+ import { ReflectionKind } from '@deepkit/type';
3
+ import { FormatParams_Url } from '@mionjs/core';
4
+ import { FILE_URL_SAMPLES, HTTP_URL_SAMPLES, SOCIAL_MEDIA_URL_SAMPLES, URL_SAMPLES, SOCIAL_MEDIA_DOMAINS_SAMPLES } from '../constants.mock.ts';
5
+ export declare const URL_REGEXP: RegExp;
6
+ export declare const URL_FILE_REGEXP: RegExp;
7
+ export declare const URL_HTTP_REGEXP: RegExp;
8
+ export declare class URLRunTypeFormat extends BaseRunTypeFormat<FormatParams_Url> {
9
+ static readonly id = "url";
10
+ readonly kind = ReflectionKind.string;
11
+ readonly name = "url";
12
+ private urlFormatter;
13
+ private domainFormatter;
14
+ private ipFormatter;
15
+ constructor(parentPath?: StrNumber[]);
16
+ getIgnoredProps(): string[] | undefined;
17
+ emitIsType(comp: JitFnCompiler, rt: BaseRunType): JitCode;
18
+ emitIsTypeErrors(comp: JitErrorsFnCompiler, rt: BaseRunType): JitCode;
19
+ _mock(opts: RunTypeOptions, rt: BaseRunType): string;
20
+ validateParams(rt: BaseRunType, params: FormatParams_Url): void;
21
+ emitFormat(comp: JitFnCompiler, rt: BaseRunType): JitCode;
22
+ }
23
+ export declare const URL_RUN_TYPE_FORMATTER: URLRunTypeFormat;
24
+ export type DEFAULT_URL_PARAMS = {
25
+ maxLength: 2048;
26
+ pattern: {
27
+ val: typeof URL_REGEXP;
28
+ errorMessage: 'invalid URL format';
29
+ mockSamples: URL_SAMPLES;
30
+ };
31
+ };
32
+ export type DEFAULT_URL_FILE_PARAMS = {
33
+ maxLength: 2048;
34
+ pattern: {
35
+ val: typeof URL_FILE_REGEXP;
36
+ errorMessage: 'invalid file URL format';
37
+ mockSamples: FILE_URL_SAMPLES;
38
+ };
39
+ };
40
+ export type DEFAULT_URL_HTTP_PARAMS = {
41
+ maxLength: 2048;
42
+ pattern: {
43
+ val: typeof URL_HTTP_REGEXP;
44
+ errorMessage: 'invalid Http URL format';
45
+ mockSamples: HTTP_URL_SAMPLES;
46
+ };
47
+ };
48
+ export type DEFAULT_URL_SOCIAL_MEDIA_PARAMS<DomainLIst extends readonly string[] = SOCIAL_MEDIA_DOMAINS_SAMPLES> = {
49
+ maxLength: 2048;
50
+ pattern: {
51
+ val: typeof URL_HTTP_REGEXP;
52
+ errorMessage: 'invalid social media URL format';
53
+ mockSamples: SOCIAL_MEDIA_URL_SAMPLES;
54
+ };
55
+ domain: {
56
+ names: {
57
+ allowedValues: {
58
+ val: DomainLIst;
59
+ errorMessage: 'Only social media domains are allowed';
60
+ };
61
+ };
62
+ tld: {
63
+ allowedValues: {
64
+ val: ['com'];
65
+ errorMessage: 'Only com TLDs are allowed';
66
+ };
67
+ };
68
+ };
69
+ };
70
+ export type FormatUrl<P extends FormatParams_Url = {}> = TypeFormat<string, 'url', DEFAULT_URL_PARAMS & P, 'url'>;
71
+ export type FormatUrlFile<P extends FormatParams_Url = {}> = TypeFormat<string, 'url', DEFAULT_URL_FILE_PARAMS & P, 'url'>;
72
+ export type FormatUrlHttp<P extends FormatParams_Url = {}> = TypeFormat<string, 'url', DEFAULT_URL_HTTP_PARAMS & P, 'url'>;
73
+ export type FormatUrlSocialMedia<DomainLIst extends readonly string[] = SOCIAL_MEDIA_DOMAINS_SAMPLES> = FormatUrl<DEFAULT_URL_SOCIAL_MEDIA_PARAMS<DomainLIst>>;
74
+ export declare type __ΩDEFAULT_URL_PARAMS = any[];
75
+ export declare type __ΩDEFAULT_URL_FILE_PARAMS = any[];
76
+ export declare type __ΩDEFAULT_URL_HTTP_PARAMS = any[];
77
+ export declare type __ΩDEFAULT_URL_SOCIAL_MEDIA_PARAMS = any[];
78
+ export declare type __ΩFormatUrl = any[];
79
+ export declare type __ΩFormatUrlFile = any[];
80
+ export declare type __ΩFormatUrlHttp = any[];
81
+ export declare type __ΩFormatUrlSocialMedia = any[];
@@ -0,0 +1,160 @@
1
+ import { registerFormatter, BaseRunTypeFormat, randomItem, JitFunctions, __ΩTypeFormat as ___TypeFormat } from "@mionjs/run-types";
2
+ import { ReflectionKind } from "@deepkit/type";
3
+ import { StringRunTypeFormat, stringIgnoreProps } from "./stringFormat.runtype.js";
4
+ import { DomainRunTypeFormat } from "./domain.runtype.js";
5
+ import { IPRunTypeFormat } from "./ip.runtype.js";
6
+ import { INTERNET_PROTOCOLS, __ΩFILE_URL_SAMPLES as ___FILE_URL_SAMPLES, __ΩHTTP_URL_SAMPLES as ___HTTP_URL_SAMPLES, __ΩURL_SAMPLES as ___URL_SAMPLES, __ΩSOCIAL_MEDIA_DOMAINS_SAMPLES as ___SOCIAL_MEDIA_DOMAINS_SAMPLES, __ΩSOCIAL_MEDIA_URL_SAMPLES as ___SOCIAL_MEDIA_URL_SAMPLES } from "../constants.mock.js";
7
+ import { paramVal } from "../utils.js";
8
+ const URL_REGEXP = /^(?:https?|ftps?|wss?):\/\/[^\s/$.?#-][^\s]*$/i;
9
+ const URL_FILE_REGEXP = /^file:\/\/\/?(?:[a-zA-Z]:)?[^\s/$.?#-][^\s]*$/i;
10
+ const URL_HTTP_REGEXP = /^https?:\/\/[^\s/$.?#-][^\s]*$/i;
11
+ class URLRunTypeFormat extends BaseRunTypeFormat {
12
+ static id = "url";
13
+ kind = ReflectionKind.string;
14
+ name = URLRunTypeFormat.id;
15
+ // Formatter instances as class variables
16
+ urlFormatter;
17
+ domainFormatter;
18
+ ipFormatter;
19
+ constructor(parentPath) {
20
+ super(parentPath);
21
+ const urlPath = this.getFormatPath();
22
+ const domainPath = this.getFormatPath("domain");
23
+ const ipPath = this.getFormatPath("ip");
24
+ this.urlFormatter = new StringRunTypeFormat(urlPath);
25
+ this.domainFormatter = new DomainRunTypeFormat(domainPath);
26
+ this.ipFormatter = new IPRunTypeFormat(ipPath);
27
+ }
28
+ getIgnoredProps() {
29
+ return stringIgnoreProps;
30
+ }
31
+ emitIsType(comp, rt) {
32
+ const params = this.getParams(rt);
33
+ const fnID = comp.fnID;
34
+ const fmtName = this.getFormatName();
35
+ const urlCode = this.urlFormatter.compileFormat(fnID, comp, rt, params, comp.vλl, fmtName);
36
+ if (!params.domain && !params.ip)
37
+ return urlCode;
38
+ const vDomain = "domain";
39
+ const dmnCode = params?.domain ? this.domainFormatter.compileFormat(fnID, comp, rt, params.domain, vDomain, fmtName) : null;
40
+ const ipCodeObj = params.ip ? this.ipFormatter.compileFormat(fnID, comp, rt, params.ip, vDomain, fmtName) : null;
41
+ const safeUrlCode = urlCode.code ? `if(!(${urlCode.code})) return false;` : "";
42
+ const dIsExpression = dmnCode?.type === "E";
43
+ const ipExpression = ipCodeObj?.type === "E";
44
+ const domainSafeCode = dIsExpression && dmnCode?.code ? `if(!(${dmnCode.code})) return false;` : dmnCode?.code;
45
+ const ipSafeCode = ipExpression && ipCodeObj?.code ? `if(${ipCodeObj.code}) return false;` : ipCodeObj?.code;
46
+ const returnCode = this.isRootFormat() ? `return true;` : "";
47
+ const code = `
48
+ ${safeUrlCode}
49
+ const start = ${comp.vλl}.indexOf('://') + 3;
50
+ const end = ${comp.vλl}.indexOf('/', start);
51
+ const endIdx = end === -1 ? ${comp.vλl}.length : end;
52
+ const domain = ${comp.vλl}.substring(start, endIdx);
53
+ ${domainSafeCode}
54
+ ${ipSafeCode}
55
+ ${returnCode}
56
+ `;
57
+ return { code, type: "S" };
58
+ }
59
+ emitIsTypeErrors(comp, rt) {
60
+ const params = this.getParams(rt);
61
+ const fnID = comp.fnID;
62
+ const fmtName = this.getFormatName();
63
+ const urlCode = this.urlFormatter.compileFormat(fnID, comp, rt, params, comp.vλl, fmtName);
64
+ if (!params.domain && !params.ip)
65
+ return urlCode;
66
+ const vDomain = "domain" + this.getFormatNestLevel();
67
+ const dmnCode = params?.domain ? this.domainFormatter.compileFormat(fnID, comp, rt, params.domain, vDomain, fmtName) : null;
68
+ const iPCode = params.ip ? this.ipFormatter.compileFormat(fnID, comp, rt, params.ip, vDomain, fmtName) : null;
69
+ const checks = [urlCode.code, dmnCode?.code, iPCode?.code].filter(Boolean);
70
+ const vStart = "start" + this.getFormatNestLevel();
71
+ const vEnd = "end" + this.getFormatNestLevel();
72
+ const vEndIdx = "endIdx" + this.getFormatNestLevel();
73
+ const code = `
74
+ const ${vStart} = ${comp.vλl}.indexOf('://') + 3;
75
+ const ${vEnd} = ${comp.vλl}.indexOf('/', ${vStart});
76
+ const ${vEndIdx} = ${vEnd} === -1 ? ${comp.vλl}.length : ${vEnd};
77
+ const ${vDomain} = ${comp.vλl}.substring(${vStart}, ${vEndIdx});
78
+ ${checks.join(";")};
79
+ `;
80
+ return { code, type: "S" };
81
+ }
82
+ _mock(opts, rt) {
83
+ const params = this.getParams(rt);
84
+ let url = this.urlFormatter.mock(opts, rt, params);
85
+ const hasProtocol = url.indexOf("://") !== -1;
86
+ if (!hasProtocol)
87
+ url = randomItem(INTERNET_PROTOCOLS) + url;
88
+ if (params.domain) {
89
+ const domain = this.domainFormatter.mock(opts, rt, params.domain);
90
+ return replaceDomain(url, domain);
91
+ }
92
+ if (params.ip)
93
+ return replaceDomain(url, this.ipFormatter.mock(opts, rt, params.ip));
94
+ return url;
95
+ }
96
+ validateParams(rt, params) {
97
+ if (params.maxLength && paramVal(params.maxLength) > 2048)
98
+ throw new Error("URL maxLength cannot be greater than 2048");
99
+ if (params.minLength && paramVal(params.minLength) < 5)
100
+ throw new Error("URL minLength cannot be less than 5");
101
+ this.urlFormatter.validateParams(rt, params);
102
+ const { ip, domain } = params;
103
+ if (ip && domain)
104
+ throw new Error("URL validator cannot have both IP and domain validators");
105
+ if (domain) {
106
+ this.domainFormatter.validateParams(rt, domain);
107
+ }
108
+ }
109
+ emitFormat(comp, rt) {
110
+ const params = this.getParams(rt);
111
+ if (!params.domain)
112
+ return { code: void 0, type: "S" };
113
+ const vDomain = "domain" + this.getFormatNestLevel();
114
+ const fnID = JitFunctions.format.id;
115
+ const fmtName = this.getFormatName();
116
+ const domainCode = this.domainFormatter.compileFormat(fnID, comp, rt, params.domain, vDomain, fmtName);
117
+ const vStart = "start" + this.getFormatNestLevel();
118
+ const vEnd = "end" + this.getFormatNestLevel();
119
+ const vEndIdx = "endIdx" + this.getFormatNestLevel();
120
+ const code = `
121
+ const ${vStart} = ${comp.vλl}.indexOf('://') + 3;
122
+ const ${vEnd} = ${comp.vλl}.indexOf('/', ${vStart});
123
+ const ${vEndIdx} = ${vEnd} === -1 ? ${comp.vλl}.length : ${vEnd};
124
+ const ${vDomain} = ${comp.vλl}.substring(${vStart}, ${vEndIdx});
125
+ return ${domainCode.code};
126
+ `;
127
+ return { code, type: "RB" };
128
+ }
129
+ }
130
+ function replaceDomain(url, domain) {
131
+ const start = url.indexOf("://") + 3;
132
+ const end = url.indexOf("/", start);
133
+ const endIdx = end === -1 ? url.length : end;
134
+ return url.substring(0, start) + domain + url.substring(endIdx);
135
+ }
136
+ const URL_RUN_TYPE_FORMATTER = registerFormatter(new URLRunTypeFormat());
137
+ const __ΩDEFAULT_URL_PARAMS = [2048, "maxLength", () => URL_REGEXP, "val", "invalid URL format", "errorMessage", () => ___URL_SAMPLES, "mockSamples", "pattern", "DEFAULT_URL_PARAMS", `P.!4"Pi#4$.%4&n'4(M4)Mw*y`];
138
+ const __ΩDEFAULT_URL_FILE_PARAMS = [2048, "maxLength", () => URL_FILE_REGEXP, "val", "invalid file URL format", "errorMessage", () => ___FILE_URL_SAMPLES, "mockSamples", "pattern", "DEFAULT_URL_FILE_PARAMS", `P.!4"Pi#4$.%4&n'4(M4)Mw*y`];
139
+ const __ΩDEFAULT_URL_HTTP_PARAMS = [2048, "maxLength", () => URL_HTTP_REGEXP, "val", "invalid Http URL format", "errorMessage", () => ___HTTP_URL_SAMPLES, "mockSamples", "pattern", "DEFAULT_URL_HTTP_PARAMS", `P.!4"Pi#4$.%4&n'4(M4)Mw*y`];
140
+ const __ΩDEFAULT_URL_SOCIAL_MEDIA_PARAMS = [() => ___SOCIAL_MEDIA_DOMAINS_SAMPLES, "DomainLIst", 2048, "maxLength", () => URL_HTTP_REGEXP, "val", "invalid social media URL format", "errorMessage", () => ___SOCIAL_MEDIA_URL_SAMPLES, "mockSamples", "pattern", "Only social media domains are allowed", "allowedValues", "names", "com", "Only com TLDs are allowed", "tld", "domain", "DEFAULT_URL_SOCIAL_MEDIA_PARAMS", `n!c"P.#4$Pi%4&.'4(n)4*M4+PPPe%!4&.,4(M4-M4.PPP./G4&.04(M4-M41M42Mw3y`];
141
+ const __ΩFormatUrl = ["P", () => ___TypeFormat, "url", () => __ΩDEFAULT_URL_PARAMS, "url", "FormatUrl", 'PMc!&.#Pn$e"!K.%o"%w&y'];
142
+ const __ΩFormatUrlFile = ["P", () => ___TypeFormat, "url", () => __ΩDEFAULT_URL_FILE_PARAMS, "url", "FormatUrlFile", 'PMc!&.#Pn$e"!K.%o"%w&y'];
143
+ const __ΩFormatUrlHttp = ["P", () => ___TypeFormat, "url", () => __ΩDEFAULT_URL_HTTP_PARAMS, "url", "FormatUrlHttp", 'PMc!&.#Pn$e"!K.%o"%w&y'];
144
+ const __ΩFormatUrlSocialMedia = [() => ___SOCIAL_MEDIA_DOMAINS_SAMPLES, "DomainLIst", () => __ΩFormatUrl, () => __ΩDEFAULT_URL_SOCIAL_MEDIA_PARAMS, "FormatUrlSocialMedia", 'n!c"e!!o$"o#"w%y'];
145
+ export {
146
+ URLRunTypeFormat,
147
+ URL_FILE_REGEXP,
148
+ URL_HTTP_REGEXP,
149
+ URL_REGEXP,
150
+ URL_RUN_TYPE_FORMATTER,
151
+ __ΩDEFAULT_URL_FILE_PARAMS,
152
+ __ΩDEFAULT_URL_HTTP_PARAMS,
153
+ __ΩDEFAULT_URL_PARAMS,
154
+ __ΩDEFAULT_URL_SOCIAL_MEDIA_PARAMS,
155
+ __ΩFormatUrl,
156
+ __ΩFormatUrlFile,
157
+ __ΩFormatUrlHttp,
158
+ __ΩFormatUrlSocialMedia
159
+ };
160
+ //# sourceMappingURL=url.runtype.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.runtype.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,22 @@
1
+ import { BaseRunType, JitFnCompiler, JitErrorsFnCompiler, JitCode, BaseRunTypeFormat, RunTypeOptions, TypeFormat } from '@mionjs/run-types';
2
+ import { ReflectionKind } from '@deepkit/type';
3
+ import { FormatParams_UUID } from '@mionjs/core';
4
+ export declare class UUIDRunTypeFormat extends BaseRunTypeFormat<FormatParams_UUID> {
5
+ static readonly id: "uuid";
6
+ readonly kind = ReflectionKind.string;
7
+ readonly name: "uuid";
8
+ emitIsType(comp: JitFnCompiler, rt: BaseRunType): JitCode;
9
+ emitIsTypeErrors(comp: JitErrorsFnCompiler, rt: BaseRunType): JitCode;
10
+ _mock(opts: RunTypeOptions, rt: BaseRunType): string;
11
+ validateParams(_rt: BaseRunType, params: FormatParams_UUID): void;
12
+ emitFormat?: any;
13
+ }
14
+ export declare const UUID_RUN_TYPE_FORMATTER: UUIDRunTypeFormat;
15
+ export type FormatUUIDv4 = TypeFormat<string, typeof UUIDRunTypeFormat.id, {
16
+ version: '4';
17
+ }, 'uuid'>;
18
+ export type FormatUUIDv7 = TypeFormat<string, typeof UUIDRunTypeFormat.id, {
19
+ version: '7';
20
+ }, 'uuid'>;
21
+ export declare type __ΩFormatUUIDv4 = any[];
22
+ export declare type __ΩFormatUUIDv7 = any[];
@@ -0,0 +1,44 @@
1
+ import { registerFormatter, BaseRunTypeFormat, __ΩTypeFormat as ___TypeFormat } from "@mionjs/run-types";
2
+ import { ReflectionKind } from "@deepkit/type";
3
+ import { randomUUID_V7 } from "@mionjs/core";
4
+ import { paramVal } from "../utils.js";
5
+ import { cpf_isUUID } from "../type-formats-pure-fns.js";
6
+ class UUIDRunTypeFormat extends BaseRunTypeFormat {
7
+ static id = "uuid";
8
+ kind = ReflectionKind.string;
9
+ name = UUIDRunTypeFormat.id;
10
+ emitIsType(comp, rt) {
11
+ const params = this.getParams(rt);
12
+ return { code: this.compilePureFunctionCall(comp, rt, cpf_isUUID, params).callCode, type: "E" };
13
+ }
14
+ emitIsTypeErrors(comp, rt) {
15
+ const params = this.getParams(rt);
16
+ const isTypeCodeObj = this.emitIsType(comp, rt);
17
+ const isTypeCode = isTypeCodeObj.code;
18
+ if (!isTypeCode)
19
+ return { code: "", type: "S" };
20
+ const errFn = this.getCallJitFormatErr(comp, rt, this);
21
+ return { code: `if (!(${isTypeCode})) ${errFn("version", paramVal(params.version))}`, type: "S" };
22
+ }
23
+ _mock(opts, rt) {
24
+ const params = this.getParams(rt);
25
+ return params.version === "4" ? crypto.randomUUID() : randomUUID_V7();
26
+ }
27
+ validateParams(_rt, params) {
28
+ if (params.version !== "4" && params.version !== "7") {
29
+ throw new Error(`Invalid UUID version: ${params.version}, must be either 4 or 7`);
30
+ }
31
+ }
32
+ emitFormat;
33
+ // no format needed
34
+ }
35
+ const UUID_RUN_TYPE_FORMATTER = registerFormatter(new UUIDRunTypeFormat());
36
+ const __ΩFormatUUIDv4 = [() => ___TypeFormat, () => UUIDRunTypeFormat.id, "4", "version", "uuid", "FormatUUIDv4", '&i"P.#4$M.%o!%w&y'];
37
+ const __ΩFormatUUIDv7 = [() => ___TypeFormat, () => UUIDRunTypeFormat.id, "7", "version", "uuid", "FormatUUIDv7", '&i"P.#4$M.%o!%w&y'];
38
+ export {
39
+ UUIDRunTypeFormat,
40
+ UUID_RUN_TYPE_FORMATTER,
41
+ __ΩFormatUUIDv4,
42
+ __ΩFormatUUIDv7
43
+ };
44
+ //# sourceMappingURL=uuid.runtype.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.runtype.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,27 @@
1
+ export declare const cpf_isDateString: import('@mionjs/core').CompiledPureFunction;
2
+ export declare const cpf_isDateString_YMD: import('@mionjs/core').CompiledPureFunction;
3
+ export declare const cpf_isDateString_DMY: import('@mionjs/core').CompiledPureFunction;
4
+ export declare const cpf_isDateString_MDY: import('@mionjs/core').CompiledPureFunction;
5
+ export declare const cpf_isDateString_YM: import('@mionjs/core').CompiledPureFunction;
6
+ export declare const cpf_isDateString_MD: import('@mionjs/core').CompiledPureFunction;
7
+ export declare const cpf_isDateString_DM: import('@mionjs/core').CompiledPureFunction;
8
+ export declare const dateFunctions: import('@mionjs/core').CompiledPureFunction[];
9
+ export declare const cpf_isTimeZone: import('@mionjs/core').CompiledPureFunction;
10
+ export declare const cpf_isHours: import('@mionjs/core').CompiledPureFunction;
11
+ export declare const cpf_isMinutes: import('@mionjs/core').CompiledPureFunction;
12
+ export declare const cpf_isSeconds: import('@mionjs/core').CompiledPureFunction;
13
+ export declare const cpf_isSecondsWithMs: import('@mionjs/core').CompiledPureFunction;
14
+ export declare const cpf_isTimeString_ISO_TZ: import('@mionjs/core').CompiledPureFunction;
15
+ export declare const cpf_isTimeString_ISO: import('@mionjs/core').CompiledPureFunction;
16
+ export declare const cpf_isTimeString_HHmmss: import('@mionjs/core').CompiledPureFunction;
17
+ export declare const cpf_isTimeString_HHmm: import('@mionjs/core').CompiledPureFunction;
18
+ export declare const cpf_isTimeString_mmss: import('@mionjs/core').CompiledPureFunction;
19
+ export declare const pureTimeFns: import('@mionjs/core').CompiledPureFunction[];
20
+ export declare const timeFunctions: import('@mionjs/core').CompiledPureFunction[];
21
+ export declare const cpf_isUUID: import('@mionjs/core').CompiledPureFunction;
22
+ export declare const cpf_isLocalHost: import('@mionjs/core').CompiledPureFunction;
23
+ export declare const cpf_isIPV4: import('@mionjs/core').CompiledPureFunction;
24
+ export declare const cpf_isIPV6: import('@mionjs/core').CompiledPureFunction;
25
+ export declare const cpf_mionGetIPErrors: import('@mionjs/core').CompiledPureFunction;
26
+ export declare const ipFunctions: import('@mionjs/core').CompiledPureFunction[];
27
+ export declare const mionFormatsPureFunctions: import('@mionjs/core').CompiledPureFunction[];