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