@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.
- package/.dist/cjs/BigintFormats.cjs +14 -0
- package/.dist/cjs/BigintFormats.cjs.map +1 -0
- package/.dist/cjs/BigintFormats.d.ts +2 -0
- package/.dist/cjs/NumberFormats.cjs +20 -0
- package/.dist/cjs/NumberFormats.cjs.map +1 -0
- package/.dist/cjs/NumberFormats.d.ts +2 -0
- package/.dist/cjs/StringFormats.cjs +120 -0
- package/.dist/cjs/StringFormats.cjs.map +1 -0
- package/.dist/cjs/StringFormats.d.ts +11 -0
- package/.dist/cjs/constants.d.ts +1 -0
- package/.dist/cjs/package.json +1 -0
- package/.dist/cjs/src/bigint/bigIntFormat.runtype.cjs +152 -0
- package/.dist/cjs/src/bigint/bigIntFormat.runtype.cjs.map +1 -0
- package/.dist/cjs/src/bigint/bigIntFormat.runtype.d.ts +21 -0
- package/.dist/cjs/src/bigint/defaultBigNumberFormats.cjs +16 -0
- package/.dist/cjs/src/bigint/defaultBigNumberFormats.cjs.map +1 -0
- package/.dist/cjs/src/bigint/defaultBigNumberFormats.d.ts +29 -0
- package/.dist/cjs/src/constants.cjs +34 -0
- package/.dist/cjs/src/constants.cjs.map +1 -0
- package/.dist/cjs/src/constants.d.ts +15 -0
- package/.dist/cjs/src/constants.mock.cjs +111 -0
- package/.dist/cjs/src/constants.mock.cjs.map +1 -0
- package/.dist/cjs/src/constants.mock.d.ts +335 -0
- package/.dist/cjs/src/number/defaultNumberFormats.cjs +28 -0
- package/.dist/cjs/src/number/defaultNumberFormats.cjs.map +1 -0
- package/.dist/cjs/src/number/defaultNumberFormats.d.ts +63 -0
- package/.dist/cjs/src/number/numberFormat.runtype.cjs +214 -0
- package/.dist/cjs/src/number/numberFormat.runtype.cjs.map +1 -0
- package/.dist/cjs/src/number/numberFormat.runtype.d.ts +21 -0
- package/.dist/cjs/src/string/date.runtype.cjs +88 -0
- package/.dist/cjs/src/string/date.runtype.cjs.map +1 -0
- package/.dist/cjs/src/string/date.runtype.d.ts +19 -0
- package/.dist/cjs/src/string/dateTime.runtype.cjs +83 -0
- package/.dist/cjs/src/string/dateTime.runtype.cjs.map +1 -0
- package/.dist/cjs/src/string/dateTime.runtype.d.ts +26 -0
- package/.dist/cjs/src/string/defaultStringFormats.runtype.cjs +25 -0
- package/.dist/cjs/src/string/defaultStringFormats.runtype.cjs.map +1 -0
- package/.dist/cjs/src/string/defaultStringFormats.runtype.d.ts +45 -0
- package/.dist/cjs/src/string/domain.runtype.cjs +248 -0
- package/.dist/cjs/src/string/domain.runtype.cjs.map +1 -0
- package/.dist/cjs/src/string/domain.runtype.d.ts +72 -0
- package/.dist/cjs/src/string/email.runtype.cjs +159 -0
- package/.dist/cjs/src/string/email.runtype.cjs.map +1 -0
- package/.dist/cjs/src/string/email.runtype.d.ts +57 -0
- package/.dist/cjs/src/string/ip.runtype.cjs +72 -0
- package/.dist/cjs/src/string/ip.runtype.cjs.map +1 -0
- package/.dist/cjs/src/string/ip.runtype.d.ts +50 -0
- package/.dist/cjs/src/string/stringFormat.runtype.cjs +270 -0
- package/.dist/cjs/src/string/stringFormat.runtype.cjs.map +1 -0
- package/.dist/cjs/src/string/stringFormat.runtype.d.ts +21 -0
- package/.dist/cjs/src/string/time.runtype.cjs +100 -0
- package/.dist/cjs/src/string/time.runtype.cjs.map +1 -0
- package/.dist/cjs/src/string/time.runtype.d.ts +21 -0
- package/.dist/cjs/src/string/url.runtype.cjs +160 -0
- package/.dist/cjs/src/string/url.runtype.cjs.map +1 -0
- package/.dist/cjs/src/string/url.runtype.d.ts +81 -0
- package/.dist/cjs/src/string/uuid.runtype.cjs +44 -0
- package/.dist/cjs/src/string/uuid.runtype.cjs.map +1 -0
- package/.dist/cjs/src/string/uuid.runtype.d.ts +22 -0
- package/.dist/cjs/src/type-formats-pure-fns.cjs +390 -0
- package/.dist/cjs/src/type-formats-pure-fns.cjs.map +1 -0
- package/.dist/cjs/src/type-formats-pure-fns.d.ts +27 -0
- package/.dist/cjs/src/utils.cjs +14 -0
- package/.dist/cjs/src/utils.cjs.map +1 -0
- package/.dist/cjs/src/utils.d.ts +3 -0
- package/.dist/cjs/vitest.config.d.ts +2 -0
- package/.dist/esm/BigintFormats.d.ts +2 -0
- package/.dist/esm/BigintFormats.js +14 -0
- package/.dist/esm/BigintFormats.js.map +1 -0
- package/.dist/esm/NumberFormats.d.ts +2 -0
- package/.dist/esm/NumberFormats.js +20 -0
- package/.dist/esm/NumberFormats.js.map +1 -0
- package/.dist/esm/StringFormats.d.ts +11 -0
- package/.dist/esm/StringFormats.js +120 -0
- package/.dist/esm/StringFormats.js.map +1 -0
- package/.dist/esm/constants.d.ts +1 -0
- package/.dist/esm/src/bigint/bigIntFormat.runtype.d.ts +21 -0
- package/.dist/esm/src/bigint/bigIntFormat.runtype.js +152 -0
- package/.dist/esm/src/bigint/bigIntFormat.runtype.js.map +1 -0
- package/.dist/esm/src/bigint/defaultBigNumberFormats.d.ts +29 -0
- package/.dist/esm/src/bigint/defaultBigNumberFormats.js +16 -0
- package/.dist/esm/src/bigint/defaultBigNumberFormats.js.map +1 -0
- package/.dist/esm/src/constants.d.ts +15 -0
- package/.dist/esm/src/constants.js +34 -0
- package/.dist/esm/src/constants.js.map +1 -0
- package/.dist/esm/src/constants.mock.d.ts +335 -0
- package/.dist/esm/src/constants.mock.js +111 -0
- package/.dist/esm/src/constants.mock.js.map +1 -0
- package/.dist/esm/src/number/defaultNumberFormats.d.ts +63 -0
- package/.dist/esm/src/number/defaultNumberFormats.js +28 -0
- package/.dist/esm/src/number/defaultNumberFormats.js.map +1 -0
- package/.dist/esm/src/number/numberFormat.runtype.d.ts +21 -0
- package/.dist/esm/src/number/numberFormat.runtype.js +214 -0
- package/.dist/esm/src/number/numberFormat.runtype.js.map +1 -0
- package/.dist/esm/src/string/date.runtype.d.ts +19 -0
- package/.dist/esm/src/string/date.runtype.js +88 -0
- package/.dist/esm/src/string/date.runtype.js.map +1 -0
- package/.dist/esm/src/string/dateTime.runtype.d.ts +26 -0
- package/.dist/esm/src/string/dateTime.runtype.js +83 -0
- package/.dist/esm/src/string/dateTime.runtype.js.map +1 -0
- package/.dist/esm/src/string/defaultStringFormats.runtype.d.ts +45 -0
- package/.dist/esm/src/string/defaultStringFormats.runtype.js +25 -0
- package/.dist/esm/src/string/defaultStringFormats.runtype.js.map +1 -0
- package/.dist/esm/src/string/domain.runtype.d.ts +72 -0
- package/.dist/esm/src/string/domain.runtype.js +248 -0
- package/.dist/esm/src/string/domain.runtype.js.map +1 -0
- package/.dist/esm/src/string/email.runtype.d.ts +57 -0
- package/.dist/esm/src/string/email.runtype.js +159 -0
- package/.dist/esm/src/string/email.runtype.js.map +1 -0
- package/.dist/esm/src/string/ip.runtype.d.ts +50 -0
- package/.dist/esm/src/string/ip.runtype.js +72 -0
- package/.dist/esm/src/string/ip.runtype.js.map +1 -0
- package/.dist/esm/src/string/stringFormat.runtype.d.ts +21 -0
- package/.dist/esm/src/string/stringFormat.runtype.js +270 -0
- package/.dist/esm/src/string/stringFormat.runtype.js.map +1 -0
- package/.dist/esm/src/string/time.runtype.d.ts +21 -0
- package/.dist/esm/src/string/time.runtype.js +100 -0
- package/.dist/esm/src/string/time.runtype.js.map +1 -0
- package/.dist/esm/src/string/url.runtype.d.ts +81 -0
- package/.dist/esm/src/string/url.runtype.js +160 -0
- package/.dist/esm/src/string/url.runtype.js.map +1 -0
- package/.dist/esm/src/string/uuid.runtype.d.ts +22 -0
- package/.dist/esm/src/string/uuid.runtype.js +44 -0
- package/.dist/esm/src/string/uuid.runtype.js.map +1 -0
- package/.dist/esm/src/type-formats-pure-fns.d.ts +27 -0
- package/.dist/esm/src/type-formats-pure-fns.js +390 -0
- package/.dist/esm/src/type-formats-pure-fns.js.map +1 -0
- package/.dist/esm/src/utils.d.ts +3 -0
- package/.dist/esm/src/utils.js +14 -0
- package/.dist/esm/src/utils.js.map +1 -0
- package/.dist/esm/vitest.config.d.ts +2 -0
- package/LICENSE +21 -0
- package/README.md +123 -0
- package/package.json +80 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const type = require("@deepkit/type");
|
|
4
|
+
const runTypes = require("@mionjs/run-types");
|
|
5
|
+
const src_utils = require("../utils.cjs");
|
|
6
|
+
const src_typeFormatsPureFns = require("../type-formats-pure-fns.cjs");
|
|
7
|
+
class DateStringRunTypeFormat extends runTypes.BaseRunTypeFormat {
|
|
8
|
+
static id = "date";
|
|
9
|
+
kind = type.ReflectionKind.string;
|
|
10
|
+
name = DateStringRunTypeFormat.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 yy = Math.floor(Math.random() * 1e4);
|
|
28
|
+
const mm = Math.floor(Math.random() * 12) + 1;
|
|
29
|
+
const dd = Math.floor(Math.random() * getMaxDaysInMonth(yy, mm)) + 1;
|
|
30
|
+
const year = String(yy).padStart(4, "0");
|
|
31
|
+
const month = String(mm).padStart(2, "0");
|
|
32
|
+
const day = String(dd).padStart(2, "0");
|
|
33
|
+
switch (src_utils.paramVal(params.format)) {
|
|
34
|
+
case "ISO":
|
|
35
|
+
case "YYYY-MM-DD":
|
|
36
|
+
return `${year}-${month}-${day}`;
|
|
37
|
+
case "DD-MM-YYYY":
|
|
38
|
+
return `${day}-${month}-${year}`;
|
|
39
|
+
case "MM-DD-YYYY":
|
|
40
|
+
return `${month}-${day}-${year}`;
|
|
41
|
+
case "YYYY-MM":
|
|
42
|
+
return `${year}-${month}`;
|
|
43
|
+
case "MM-DD":
|
|
44
|
+
return `${month}-${day}`;
|
|
45
|
+
case "DD-MM":
|
|
46
|
+
return `${day}-${month}`;
|
|
47
|
+
default:
|
|
48
|
+
throw new Error(`Invalid date format: ${src_utils.paramVal(params.format)}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
getFormatPureFn(format) {
|
|
52
|
+
switch (format) {
|
|
53
|
+
case "ISO":
|
|
54
|
+
case "YYYY-MM-DD":
|
|
55
|
+
return src_typeFormatsPureFns.cpf_isDateString_YMD;
|
|
56
|
+
case "DD-MM-YYYY":
|
|
57
|
+
return src_typeFormatsPureFns.cpf_isDateString_DMY;
|
|
58
|
+
case "MM-DD-YYYY":
|
|
59
|
+
return src_typeFormatsPureFns.cpf_isDateString_MDY;
|
|
60
|
+
case "YYYY-MM":
|
|
61
|
+
return src_typeFormatsPureFns.cpf_isDateString_YM;
|
|
62
|
+
case "MM-DD":
|
|
63
|
+
return src_typeFormatsPureFns.cpf_isDateString_MD;
|
|
64
|
+
case "DD-MM":
|
|
65
|
+
return src_typeFormatsPureFns.cpf_isDateString_DM;
|
|
66
|
+
default:
|
|
67
|
+
throw new Error(`Invalid date format: ${format}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function getMaxDaysInMonth(year, month) {
|
|
72
|
+
if (month === 2) {
|
|
73
|
+
if (year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0))
|
|
74
|
+
return 29;
|
|
75
|
+
return 28;
|
|
76
|
+
}
|
|
77
|
+
if (month === 4 || month === 6 || month === 9 || month === 11)
|
|
78
|
+
return 30;
|
|
79
|
+
return 31;
|
|
80
|
+
}
|
|
81
|
+
const DATE_RUN_TYPE_FORMATTER = runTypes.registerFormatter(new DateStringRunTypeFormat());
|
|
82
|
+
const __ΩDEFAULT_DATE_PARAMS = ["ISO", "format", "DEFAULT_DATE_PARAMS", 'P.!4"Mw#y'];
|
|
83
|
+
const __ΩFormatStringDate = [() => __ΩDEFAULT_DATE_PARAMS, "P", () => runTypes.__ΩTypeFormat, () => DateStringRunTypeFormat.id, "date", "FormatStringDate", 'n!c"&i$e!!.%o#%w&y'];
|
|
84
|
+
exports.DATE_RUN_TYPE_FORMATTER = DATE_RUN_TYPE_FORMATTER;
|
|
85
|
+
exports.DateStringRunTypeFormat = DateStringRunTypeFormat;
|
|
86
|
+
exports.__ΩDEFAULT_DATE_PARAMS = __ΩDEFAULT_DATE_PARAMS;
|
|
87
|
+
exports.__ΩFormatStringDate = __ΩFormatStringDate;
|
|
88
|
+
//# sourceMappingURL=date.runtype.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.runtype.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ReflectionKind } from '@deepkit/type';
|
|
2
|
+
import { JitFnCompiler, JitErrorsFnCompiler, BaseRunType, RunTypeOptions, JitCode, BaseRunTypeFormat, TypeFormat } from '@mionjs/run-types';
|
|
3
|
+
import { DateFmt, FormatParams_Date } from '@mionjs/core';
|
|
4
|
+
export declare class DateStringRunTypeFormat extends BaseRunTypeFormat<FormatParams_Date> {
|
|
5
|
+
static id: "date";
|
|
6
|
+
kind: ReflectionKind;
|
|
7
|
+
name: "date";
|
|
8
|
+
emitIsType(comp: JitFnCompiler, rt: BaseRunType): JitCode;
|
|
9
|
+
emitIsTypeErrors(comp: JitErrorsFnCompiler, rt: BaseRunType): JitCode;
|
|
10
|
+
_mock(opts: RunTypeOptions, rt: BaseRunType): string;
|
|
11
|
+
getFormatPureFn(format: DateFmt): import('@mionjs/core').CompiledPureFunction;
|
|
12
|
+
}
|
|
13
|
+
export declare const DATE_RUN_TYPE_FORMATTER: DateStringRunTypeFormat;
|
|
14
|
+
export type DEFAULT_DATE_PARAMS = {
|
|
15
|
+
format: 'ISO';
|
|
16
|
+
};
|
|
17
|
+
export type FormatStringDate<P extends Partial<FormatParams_Date> = DEFAULT_DATE_PARAMS> = TypeFormat<string, typeof DateStringRunTypeFormat.id, P, 'date'>;
|
|
18
|
+
export declare type __ΩDEFAULT_DATE_PARAMS = any[];
|
|
19
|
+
export declare type __ΩFormatStringDate = any[];
|
|
@@ -0,0 +1,83 @@
|
|
|
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_date_runtype = require("./date.runtype.cjs");
|
|
6
|
+
const src_string_time_runtype = require("./time.runtype.cjs");
|
|
7
|
+
const src_string_stringFormat_runtype = require("./stringFormat.runtype.cjs");
|
|
8
|
+
const src_utils = require("../utils.cjs");
|
|
9
|
+
class DateTimeRunTypeFormat extends runTypes.BaseRunTypeFormat {
|
|
10
|
+
static id = "dateTime";
|
|
11
|
+
kind = type.ReflectionKind.string;
|
|
12
|
+
name = DateTimeRunTypeFormat.id;
|
|
13
|
+
dateFormatter;
|
|
14
|
+
timeFormatter;
|
|
15
|
+
constructor(parentPath) {
|
|
16
|
+
super(parentPath);
|
|
17
|
+
this.dateFormatter = new src_string_date_runtype.DateStringRunTypeFormat(this.getFormatPath("date"));
|
|
18
|
+
this.timeFormatter = new src_string_time_runtype.TimeStringRunTypeFormat(this.getFormatPath("time"));
|
|
19
|
+
}
|
|
20
|
+
getIgnoredProps() {
|
|
21
|
+
return src_string_stringFormat_runtype.stringIgnoreProps;
|
|
22
|
+
}
|
|
23
|
+
emitIsType(comp, rt) {
|
|
24
|
+
const params = this.getParams(rt);
|
|
25
|
+
const fnID = comp.fnID;
|
|
26
|
+
const fmtName = this.getFormatName();
|
|
27
|
+
const vλl = comp.vλl;
|
|
28
|
+
const splitChar = src_utils.paramVal(params.splitChar);
|
|
29
|
+
const vDatePart = "datePart" + this.getFormatNestLevel();
|
|
30
|
+
const vTimePart = "timePart" + this.getFormatNestLevel();
|
|
31
|
+
const vSplitPos = "splitPos" + this.getFormatNestLevel();
|
|
32
|
+
const dateCode = this.dateFormatter.compileFormat(fnID, comp, rt, params.date, vDatePart, fmtName);
|
|
33
|
+
const timeCode = this.timeFormatter.compileFormat(fnID, comp, rt, params.time, vTimePart, fmtName);
|
|
34
|
+
const returnCode = this.isRootFormat() ? `return true;` : "";
|
|
35
|
+
const code = `
|
|
36
|
+
const ${vSplitPos} = ${vλl}.indexOf('${splitChar}');
|
|
37
|
+
if (${vSplitPos} === -1) return false;
|
|
38
|
+
const ${vDatePart} = ${vλl}.substring(0, ${vSplitPos});
|
|
39
|
+
const ${vTimePart} = ${vλl}.substring(${vSplitPos} + 1);
|
|
40
|
+
if (!(${dateCode.code})) return false;
|
|
41
|
+
if (!(${timeCode.code})) return false;
|
|
42
|
+
${returnCode}
|
|
43
|
+
`;
|
|
44
|
+
return { code, type: "S" };
|
|
45
|
+
}
|
|
46
|
+
emitIsTypeErrors(comp, rt) {
|
|
47
|
+
const params = this.getParams(rt);
|
|
48
|
+
const fnID = comp.fnID;
|
|
49
|
+
const fmtName = this.getFormatName();
|
|
50
|
+
const splitChar = src_utils.paramVal(params.splitChar);
|
|
51
|
+
const errFn = this.getCallJitFormatErr(comp, rt, this, false);
|
|
52
|
+
const vλl = comp.vλl;
|
|
53
|
+
const vDatePart = "datePart";
|
|
54
|
+
const vTimePart = "timePart";
|
|
55
|
+
const vSplitPos = "splitPos";
|
|
56
|
+
const dateCode = this.dateFormatter.compileFormat(fnID, comp, rt, params.date, vDatePart, fmtName);
|
|
57
|
+
const timeCode = this.timeFormatter.compileFormat(fnID, comp, rt, params.time, vTimePart, fmtName);
|
|
58
|
+
const code = `
|
|
59
|
+
const ${vSplitPos} = ${vλl}.indexOf('${splitChar}');
|
|
60
|
+
if (${vSplitPos} === -1) ${errFn("splitChar", splitChar)};
|
|
61
|
+
const ${vDatePart} = ${vλl}.substring(0, ${vSplitPos});
|
|
62
|
+
const ${vTimePart} = ${vλl}.substring(${vSplitPos} + 1);
|
|
63
|
+
${dateCode.code ? `${dateCode.code};` : ""}
|
|
64
|
+
${timeCode.code ? `${timeCode.code};` : ""}
|
|
65
|
+
`;
|
|
66
|
+
return { code, type: "S" };
|
|
67
|
+
}
|
|
68
|
+
_mock(opts, rt) {
|
|
69
|
+
const params = this.getParams(rt);
|
|
70
|
+
const splitChar = src_utils.paramVal(params.splitChar);
|
|
71
|
+
const datePart = this.dateFormatter.mock(opts, rt, params.date);
|
|
72
|
+
const timePart = this.timeFormatter.mock(opts, rt, params.time);
|
|
73
|
+
return `${datePart}${splitChar}${timePart}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const DATE_TIME_RUN_TYPE_FORMATTER = runTypes.registerFormatter(new DateTimeRunTypeFormat());
|
|
77
|
+
const __ΩDEFAULT_DATE_TIME_PARAMS = [() => src_string_date_runtype.__ΩDEFAULT_DATE_PARAMS, "date", () => src_string_time_runtype.__ΩDEFAULT_TIME_FORMAT_PARAMS, "time", "T", "splitChar", "DEFAULT_DATE_TIME_PARAMS", `Pn!4"n#4$.%4&Mw'y`];
|
|
78
|
+
const __ΩFormatStringDateTime = ["P", () => runTypes.__ΩTypeFormat, () => DateTimeRunTypeFormat.id, () => __ΩDEFAULT_DATE_TIME_PARAMS, "dateTime", "FormatStringDateTime", 'PMc!&i#Pn$e"!K.%o"%w&y'];
|
|
79
|
+
exports.DATE_TIME_RUN_TYPE_FORMATTER = DATE_TIME_RUN_TYPE_FORMATTER;
|
|
80
|
+
exports.DateTimeRunTypeFormat = DateTimeRunTypeFormat;
|
|
81
|
+
exports.__ΩDEFAULT_DATE_TIME_PARAMS = __ΩDEFAULT_DATE_TIME_PARAMS;
|
|
82
|
+
exports.__ΩFormatStringDateTime = __ΩFormatStringDateTime;
|
|
83
|
+
//# sourceMappingURL=dateTime.runtype.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateTime.runtype.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseRunType, JitFnCompiler, JitErrorsFnCompiler, JitCode, TypeFormat, RunTypeOptions, BaseRunTypeFormat } from '@mionjs/run-types';
|
|
2
|
+
import { ReflectionKind } from '@deepkit/type';
|
|
3
|
+
import { DEFAULT_DATE_PARAMS, DateStringRunTypeFormat } from './date.runtype.ts';
|
|
4
|
+
import { FormatParams_DateTime } from '@mionjs/core';
|
|
5
|
+
import { DEFAULT_TIME_FORMAT_PARAMS, TimeStringRunTypeFormat } from './time.runtype.ts';
|
|
6
|
+
export declare class DateTimeRunTypeFormat extends BaseRunTypeFormat<FormatParams_DateTime> {
|
|
7
|
+
static id: "dateTime";
|
|
8
|
+
kind: ReflectionKind;
|
|
9
|
+
name: "dateTime";
|
|
10
|
+
dateFormatter: DateStringRunTypeFormat;
|
|
11
|
+
timeFormatter: TimeStringRunTypeFormat;
|
|
12
|
+
constructor(parentPath?: string[]);
|
|
13
|
+
getIgnoredProps(): string[] | undefined;
|
|
14
|
+
emitIsType(comp: JitFnCompiler, rt: BaseRunType): JitCode;
|
|
15
|
+
emitIsTypeErrors(comp: JitErrorsFnCompiler, rt: BaseRunType): JitCode;
|
|
16
|
+
_mock(opts: RunTypeOptions, rt: BaseRunType): string;
|
|
17
|
+
}
|
|
18
|
+
export declare const DATE_TIME_RUN_TYPE_FORMATTER: DateTimeRunTypeFormat;
|
|
19
|
+
export type DEFAULT_DATE_TIME_PARAMS = {
|
|
20
|
+
date: DEFAULT_DATE_PARAMS;
|
|
21
|
+
time: DEFAULT_TIME_FORMAT_PARAMS;
|
|
22
|
+
splitChar: 'T';
|
|
23
|
+
};
|
|
24
|
+
export type FormatStringDateTime<P extends Partial<FormatParams_DateTime> = {}> = TypeFormat<string, typeof DateTimeRunTypeFormat.id, DEFAULT_DATE_TIME_PARAMS & P, 'dateTime'>;
|
|
25
|
+
export declare type __ΩDEFAULT_DATE_TIME_PARAMS = any[];
|
|
26
|
+
export declare type __ΩFormatStringDateTime = any[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const src_string_stringFormat_runtype = require("./stringFormat.runtype.cjs");
|
|
4
|
+
const ALPHANUMERIC_REGEX = /^[\p{L}\p{N}]+$/u;
|
|
5
|
+
const ALPHA_REGEX = /^[\p{L}]+$/u;
|
|
6
|
+
const NUMERIC_REGEX = /^[\p{N}]+$/u;
|
|
7
|
+
const __ΩDEFAULT_ALPHA_NUM_PARAMS = [() => ALPHANUMERIC_REGEX, "val", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "mockSamples", "only alphanumeric values are allowed", "errorMessage", "pattern", "DEFAULT_ALPHA_NUM_PARAMS", `PPi!4".#4$.%4&M4'Mw(y`];
|
|
8
|
+
const __ΩDEFAULT_ALPHA_PARAMS = [() => ALPHA_REGEX, "val", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "mockSamples", "only alphabetic values are allowed", "errorMessage", "pattern", "DEFAULT_ALPHA_PARAMS", `PPi!4".#4$.%4&M4'Mw(y`];
|
|
9
|
+
const __ΩDEFAULT_NUMERIC_PARAMS = [() => NUMERIC_REGEX, "val", "0123456789", "mockSamples", "only numeric values are allowed", "errorMessage", "pattern", "DEFAULT_NUMERIC_PARAMS", `PPi!4".#4$.%4&M4'Mw(y`];
|
|
10
|
+
const __ΩFormatAlphaNumeric = ["P", () => src_string_stringFormat_runtype.__ΩFormatString, () => __ΩDEFAULT_ALPHA_NUM_PARAMS, "FormatAlphaNumeric", 'PMc!Pe"!n#Ko""w$y'];
|
|
11
|
+
const __ΩFormatAlpha = ["P", () => src_string_stringFormat_runtype.__ΩFormatString, () => __ΩDEFAULT_ALPHA_PARAMS, "FormatAlpha", 'PMc!Pe"!n#Ko""w$y'];
|
|
12
|
+
const __ΩFormatNumeric = ["P", () => src_string_stringFormat_runtype.__ΩFormatString, () => __ΩDEFAULT_NUMERIC_PARAMS, "FormatNumeric", 'PMc!Pe"!n#Ko""w$y'];
|
|
13
|
+
const __ΩFormatLowercase = ["P", () => src_string_stringFormat_runtype.__ΩFormatString, true, "lowercase", "FormatLowercase", 'PMc!Pe"!P.#4$MKo""w%y'];
|
|
14
|
+
const __ΩFormatUppercase = ["P", () => src_string_stringFormat_runtype.__ΩFormatString, true, "uppercase", "FormatUppercase", 'PMc!Pe"!P.#4$MKo""w%y'];
|
|
15
|
+
const __ΩFormatCapitalize = ["P", () => src_string_stringFormat_runtype.__ΩFormatString, true, "capitalize", "FormatCapitalize", 'PMc!Pe"!P.#4$MKo""w%y'];
|
|
16
|
+
exports.ALPHANUMERIC_REGEX = ALPHANUMERIC_REGEX;
|
|
17
|
+
exports.ALPHA_REGEX = ALPHA_REGEX;
|
|
18
|
+
exports.NUMERIC_REGEX = NUMERIC_REGEX;
|
|
19
|
+
exports.__ΩFormatAlpha = __ΩFormatAlpha;
|
|
20
|
+
exports.__ΩFormatAlphaNumeric = __ΩFormatAlphaNumeric;
|
|
21
|
+
exports.__ΩFormatCapitalize = __ΩFormatCapitalize;
|
|
22
|
+
exports.__ΩFormatLowercase = __ΩFormatLowercase;
|
|
23
|
+
exports.__ΩFormatNumeric = __ΩFormatNumeric;
|
|
24
|
+
exports.__ΩFormatUppercase = __ΩFormatUppercase;
|
|
25
|
+
//# sourceMappingURL=defaultStringFormats.runtype.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultStringFormats.runtype.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FormatString } from './stringFormat.runtype.ts';
|
|
2
|
+
import { StringParams } from '@mionjs/core';
|
|
3
|
+
export declare const ALPHANUMERIC_REGEX: RegExp;
|
|
4
|
+
export declare const ALPHA_REGEX: RegExp;
|
|
5
|
+
export declare const NUMERIC_REGEX: RegExp;
|
|
6
|
+
type DEFAULT_ALPHA_NUM_PARAMS = {
|
|
7
|
+
pattern: {
|
|
8
|
+
val: typeof ALPHANUMERIC_REGEX;
|
|
9
|
+
mockSamples: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
10
|
+
errorMessage: 'only alphanumeric values are allowed';
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
type DEFAULT_ALPHA_PARAMS = {
|
|
14
|
+
pattern: {
|
|
15
|
+
val: typeof ALPHA_REGEX;
|
|
16
|
+
mockSamples: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
17
|
+
errorMessage: 'only alphabetic values are allowed';
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type DEFAULT_NUMERIC_PARAMS = {
|
|
21
|
+
pattern: {
|
|
22
|
+
val: typeof NUMERIC_REGEX;
|
|
23
|
+
mockSamples: '0123456789';
|
|
24
|
+
errorMessage: 'only numeric values are allowed';
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export type FormatAlphaNumeric<P extends StringParams = {}> = FormatString<P & DEFAULT_ALPHA_NUM_PARAMS>;
|
|
28
|
+
export type FormatAlpha<P extends StringParams = {}> = FormatString<P & DEFAULT_ALPHA_PARAMS>;
|
|
29
|
+
export type FormatNumeric<P extends StringParams = {}> = FormatString<P & DEFAULT_NUMERIC_PARAMS>;
|
|
30
|
+
export type FormatLowercase<P extends StringParams = {}> = FormatString<P & {
|
|
31
|
+
lowercase: true;
|
|
32
|
+
}>;
|
|
33
|
+
export type FormatUppercase<P extends StringParams = {}> = FormatString<P & {
|
|
34
|
+
uppercase: true;
|
|
35
|
+
}>;
|
|
36
|
+
export type FormatCapitalize<P extends StringParams = {}> = FormatString<P & {
|
|
37
|
+
capitalize: true;
|
|
38
|
+
}>;
|
|
39
|
+
export {};
|
|
40
|
+
export declare type __ΩFormatAlphaNumeric = any[];
|
|
41
|
+
export declare type __ΩFormatAlpha = any[];
|
|
42
|
+
export declare type __ΩFormatNumeric = any[];
|
|
43
|
+
export declare type __ΩFormatLowercase = any[];
|
|
44
|
+
export declare type __ΩFormatUppercase = any[];
|
|
45
|
+
export declare type __ΩFormatCapitalize = any[];
|
|
@@ -0,0 +1,248 @@
|
|
|
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_constants_mock = require("../constants.mock.cjs");
|
|
7
|
+
const src_utils = require("../utils.cjs");
|
|
8
|
+
const DOMAIN_PATTERN = /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,63}$/;
|
|
9
|
+
const DOMAIN_PATTERN_UNICODE = /^(?:[\p{L}\p{N}](?:[\p{L}\p{N}-]{0,61}[\p{L}\p{N}])?\.)+[a-zA-Z]{2,63}$/u;
|
|
10
|
+
const DOMAIN_PATTERN_PUNYCODE = /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z0-9-]{2,63}$/;
|
|
11
|
+
const DOMAIN_ALLOWED_CHARS_PATTERN = /^[a-zA-Z0-9-]+$/;
|
|
12
|
+
const TLD_ALLOWED_CHARS_PATTERN = /^[a-zA-Z]+(\.[a-zA-Z]+)?$/;
|
|
13
|
+
const tldAllowedChars = {
|
|
14
|
+
val: src_constants_mock.TLD_CHARS,
|
|
15
|
+
errorMessage: "only alphabetical characters allowed"
|
|
16
|
+
};
|
|
17
|
+
const namesAllowedChars = {
|
|
18
|
+
val: src_constants_mock.NAME_CHARS,
|
|
19
|
+
errorMessage: "only alphabetical characters and hyphens allowed"
|
|
20
|
+
};
|
|
21
|
+
class DomainRunTypeFormat extends runTypes.BaseRunTypeFormat {
|
|
22
|
+
static id = "domain";
|
|
23
|
+
kind = type.ReflectionKind.string;
|
|
24
|
+
name = DomainRunTypeFormat.id;
|
|
25
|
+
// Formatter instances as class variables
|
|
26
|
+
rootFormatter;
|
|
27
|
+
nameFormatter;
|
|
28
|
+
tldFormatter;
|
|
29
|
+
constructor(parentPath) {
|
|
30
|
+
super(parentPath);
|
|
31
|
+
const domainPath = this.getFormatPath();
|
|
32
|
+
const namePath = this.getFormatPath("names");
|
|
33
|
+
const tldPath = this.getFormatPath("tld");
|
|
34
|
+
this.rootFormatter = new src_string_stringFormat_runtype.StringRunTypeFormat(domainPath);
|
|
35
|
+
this.nameFormatter = new src_string_stringFormat_runtype.StringRunTypeFormat(namePath);
|
|
36
|
+
this.tldFormatter = new src_string_stringFormat_runtype.StringRunTypeFormat(tldPath);
|
|
37
|
+
}
|
|
38
|
+
canEmbedFormatterCode(fnID, rt, p) {
|
|
39
|
+
const params = p || this.getParams(rt);
|
|
40
|
+
if (fnID === runTypes.JitFunctions.isType.id || fnID === runTypes.JitFunctions.typeErrors.id)
|
|
41
|
+
return super.canEmbedFormatterCode(fnID, rt) && !!params.pattern;
|
|
42
|
+
return super.canEmbedFormatterCode(fnID, rt);
|
|
43
|
+
}
|
|
44
|
+
getIgnoredProps() {
|
|
45
|
+
return src_string_stringFormat_runtype.stringIgnoreProps;
|
|
46
|
+
}
|
|
47
|
+
emitIsType(comp, rt) {
|
|
48
|
+
const params = this.getParams(rt);
|
|
49
|
+
const fnID = comp.fnID;
|
|
50
|
+
const fmtName = this.getFormatName();
|
|
51
|
+
if (params.pattern)
|
|
52
|
+
return this.rootFormatter.compileFormat(fnID, comp, rt, params, comp.vλl, fmtName);
|
|
53
|
+
const vλl = comp.vλl;
|
|
54
|
+
const vName = "name" + this.getFormatNestLevel();
|
|
55
|
+
const vTld = "tld" + this.getFormatNestLevel();
|
|
56
|
+
const vCount = "count" + this.getFormatNestLevel();
|
|
57
|
+
const vStart = "start" + this.getFormatNestLevel();
|
|
58
|
+
const vPos = "pos" + this.getFormatNestLevel();
|
|
59
|
+
const rootCode = this.rootFormatter.compileFormat(fnID, comp, rt, params, vλl, fmtName);
|
|
60
|
+
const nameCode = this.nameFormatter.compileFormat(fnID, comp, rt, params.names, vName, fmtName);
|
|
61
|
+
const tldCode = this.tldFormatter.compileFormat(fnID, comp, rt, params.tld, vTld, fmtName);
|
|
62
|
+
const maxPartsCode = params.maxParts ? `if (${vCount} > ${params.maxParts}) return false;` : "";
|
|
63
|
+
const minPartsCode = params.minParts ? `if (${vCount} < ${params.minParts}) return false;` : "";
|
|
64
|
+
const rootSafeCode = rootCode.code ? `if (!(${rootCode.code})) return false;` : "";
|
|
65
|
+
const tldSafeCode = tldCode.code ? `const ${vTld} = ${vλl}.substring(${vStart}); if (!(${tldCode.code})) return false;` : "";
|
|
66
|
+
const returnCode = this.isRootFormat() ? `return true;` : "";
|
|
67
|
+
const skipCount = !maxPartsCode && !minPartsCode && !tldCode.code;
|
|
68
|
+
const code = `
|
|
69
|
+
${rootSafeCode}
|
|
70
|
+
let ${vCount} = 1; let ${vStart} = 0; let ${vPos}; let ${vName};
|
|
71
|
+
while ((${vPos} = ${vλl}.indexOf('.', ${vStart})) !== -1) {
|
|
72
|
+
${vName} = ${vλl}.substring(${vStart}, ${vPos});
|
|
73
|
+
${!params.names?.allowedValues ? `if (${vName}.startsWith('-') || ${vName}.endsWith('-')) return false;` : ""}
|
|
74
|
+
if (!(${nameCode.code})) return false;
|
|
75
|
+
${vStart} = ${vPos} + 1;
|
|
76
|
+
${!skipCount ? `${vCount}++;` : ""}
|
|
77
|
+
}
|
|
78
|
+
${maxPartsCode}
|
|
79
|
+
${minPartsCode}
|
|
80
|
+
${tldSafeCode}
|
|
81
|
+
${returnCode}
|
|
82
|
+
`;
|
|
83
|
+
return { code, type: "S" };
|
|
84
|
+
}
|
|
85
|
+
emitIsTypeErrors(comp, rt) {
|
|
86
|
+
const params = this.getParams(rt);
|
|
87
|
+
const fnID = comp.fnID;
|
|
88
|
+
const fmtName = this.getFormatName();
|
|
89
|
+
if (params.pattern)
|
|
90
|
+
return this.rootFormatter.compileFormat(fnID, comp, rt, params, comp.vλl, fmtName);
|
|
91
|
+
const errFn = this.getCallJitFormatErr(comp, rt, this, false);
|
|
92
|
+
const vλl = comp.vλl;
|
|
93
|
+
const vName = "name" + this.getFormatNestLevel();
|
|
94
|
+
const vTld = "tld" + this.getFormatNestLevel();
|
|
95
|
+
const vCount = "count" + this.getFormatNestLevel();
|
|
96
|
+
const vStart = "start" + this.getFormatNestLevel();
|
|
97
|
+
const vPos = "pos" + this.getFormatNestLevel();
|
|
98
|
+
const rootCode = this.rootFormatter.compileFormat(fnID, comp, rt, params, vλl, fmtName);
|
|
99
|
+
const nameCode = this.nameFormatter.compileFormat(fnID, comp, rt, params.names, vName, fmtName, vCount);
|
|
100
|
+
const tldCode = this.tldFormatter.compileFormat(fnID, comp, rt, params.tld, vTld, fmtName);
|
|
101
|
+
const maxPartsCode = params.maxParts ? `if (${vCount} > ${params.maxParts}) ${errFn("maxParts", src_utils.paramVal(params.maxParts))};` : "";
|
|
102
|
+
const minPartsCode = params.minParts ? `if (${vCount} < ${params.minParts}) ${errFn("minParts", src_utils.paramVal(params.minParts))};` : "";
|
|
103
|
+
const tldSafeCode = tldCode.code ? `const ${vTld} = ${vλl}.substring(${vStart}); ${tldCode.code};` : "";
|
|
104
|
+
const skipCount = !maxPartsCode && !minPartsCode && !tldCode.code;
|
|
105
|
+
const code = `
|
|
106
|
+
${rootCode.code};
|
|
107
|
+
let ${vCount} = 0; let ${vStart} = 0; let ${vPos}; let ${vName};
|
|
108
|
+
while ((${vPos} = ${vλl}.indexOf('.', ${vStart})) !== -1) {
|
|
109
|
+
${vName} = ${vλl}.substring(${vStart}, ${vPos});
|
|
110
|
+
${!params.names?.allowedValues ? `if (${vName}.startsWith('-') || ${vName}.endsWith('-')) ${errFn("hyphen", "name")};` : ""}
|
|
111
|
+
${nameCode.code};
|
|
112
|
+
${vStart} = ${vPos} + 1;
|
|
113
|
+
${!skipCount ? `${vCount}++;` : ""}
|
|
114
|
+
}
|
|
115
|
+
${!skipCount ? `${vCount}++;` : ""}
|
|
116
|
+
${maxPartsCode}
|
|
117
|
+
${minPartsCode}
|
|
118
|
+
${tldSafeCode};
|
|
119
|
+
`;
|
|
120
|
+
return { code, type: "S" };
|
|
121
|
+
}
|
|
122
|
+
_mock(opts, rt) {
|
|
123
|
+
const params = this.getParams(rt);
|
|
124
|
+
if (params.pattern)
|
|
125
|
+
return this.rootFormatter.mock(opts, rt, params);
|
|
126
|
+
const maxParts = src_utils.paramVal(params.maxParts || 6);
|
|
127
|
+
const minParts = src_utils.paramVal(params.minParts || 2);
|
|
128
|
+
const maxLength = src_utils.paramVal(params.maxLength || 253);
|
|
129
|
+
const minLength = src_utils.paramVal(params.minLength || 3);
|
|
130
|
+
let tld = this.mockTld(opts, rt, params.tld);
|
|
131
|
+
const tldParts = tld.split(".");
|
|
132
|
+
while (tldParts.length > 1 && tldParts.length >= maxParts)
|
|
133
|
+
tldParts.shift();
|
|
134
|
+
tld = tldParts.join(".");
|
|
135
|
+
const singleNameMax = tldParts.length + 1;
|
|
136
|
+
const noNormalMax = Math.random() < 0.2 ? maxParts : singleNameMax;
|
|
137
|
+
const maxRandom = noNormalMax - tldParts.length;
|
|
138
|
+
const minRandom = minParts - src_utils.paramVal(tldParts.length);
|
|
139
|
+
const maxRandomParts = runTypes.random(minRandom, maxRandom);
|
|
140
|
+
const parts = [];
|
|
141
|
+
parts.push(this.mockName(opts, rt, params.names));
|
|
142
|
+
let name = parts[0];
|
|
143
|
+
let domain = `${name}.${tld}`;
|
|
144
|
+
while (domain.length < maxLength && parts.length < maxRandomParts || domain.length < minLength) {
|
|
145
|
+
parts.push(this.mockName(opts, rt, params.names));
|
|
146
|
+
name = parts.join(".");
|
|
147
|
+
domain = `${name}.${tld}`;
|
|
148
|
+
}
|
|
149
|
+
return domain;
|
|
150
|
+
}
|
|
151
|
+
hasNoConstrains(params) {
|
|
152
|
+
return !params.allowedChars && !params.disallowedChars && !params.pattern && !params.allowedValues;
|
|
153
|
+
}
|
|
154
|
+
mockName(opts, rt, params) {
|
|
155
|
+
const hasParams = !!Object.keys(params).length;
|
|
156
|
+
if (!hasParams)
|
|
157
|
+
return runTypes.randomItem(src_constants_mock.NAME_SAMPLES);
|
|
158
|
+
const defaultParams = {
|
|
159
|
+
...params,
|
|
160
|
+
maxLength: params.maxLength ?? 63,
|
|
161
|
+
minLength: params.minLength ?? 2,
|
|
162
|
+
pattern: params.pattern,
|
|
163
|
+
allowedValues: params.allowedValues,
|
|
164
|
+
disallowedValues: params.disallowedValues,
|
|
165
|
+
allowedChars: this.hasNoConstrains(params) ? namesAllowedChars : void 0
|
|
166
|
+
};
|
|
167
|
+
return this.nameFormatter.mock(opts, rt, defaultParams);
|
|
168
|
+
}
|
|
169
|
+
mockTld(opts, rt, params) {
|
|
170
|
+
const hasParams = !!Object.keys(params).length;
|
|
171
|
+
if (!hasParams)
|
|
172
|
+
return runTypes.randomItem(src_constants_mock.TLD_SAMPLES);
|
|
173
|
+
const defaultParams = {
|
|
174
|
+
...params,
|
|
175
|
+
maxLength: params.maxLength ?? 12,
|
|
176
|
+
minLength: params.minLength ?? 2,
|
|
177
|
+
pattern: params.pattern,
|
|
178
|
+
allowedValues: params.allowedValues,
|
|
179
|
+
disallowedValues: params.disallowedValues,
|
|
180
|
+
allowedChars: this.hasNoConstrains(params) ? tldAllowedChars : void 0
|
|
181
|
+
};
|
|
182
|
+
return this.tldFormatter.mock(opts, rt, defaultParams);
|
|
183
|
+
}
|
|
184
|
+
emitFormat(comp) {
|
|
185
|
+
return { code: `${comp.vλl}.toLowerCase()`, type: "E" };
|
|
186
|
+
}
|
|
187
|
+
_formatMockedValue(opts, _rt, val) {
|
|
188
|
+
return val.toLowerCase();
|
|
189
|
+
}
|
|
190
|
+
validateParams(rt, params) {
|
|
191
|
+
const onlyOne = [params.names, params.pattern].filter(Boolean);
|
|
192
|
+
if (onlyOne.length > 1)
|
|
193
|
+
throw new Error(`Domain can only have one of (names & tld), pattern or allowedValues in type ${this.printPath(rt)}`);
|
|
194
|
+
if (params.maxLength && src_utils.paramVal(params.maxLength) > 253)
|
|
195
|
+
throw new Error(`Domain maxLength cannot be greater than 253 in type ${this.printPath(rt, "maxLength")}`);
|
|
196
|
+
if (params.minLength && src_utils.paramVal(params.minLength) < 3)
|
|
197
|
+
throw new Error(`Domain minLength cannot be less than 3 in type ${this.printPath(rt, "minLength")}`);
|
|
198
|
+
if (params.minParts && src_utils.paramVal(params.minParts) < 2)
|
|
199
|
+
throw new Error(`Domain minParts cannot be less than 2 in type ${this.printPath(rt, "minParts")}`);
|
|
200
|
+
if (params.maxParts && src_utils.paramVal(params.maxParts) < 2)
|
|
201
|
+
throw new Error(`Domain maxParts cannot be less than 2 in type ${this.printPath(rt, "maxParts")}`);
|
|
202
|
+
if (params.names && !params.tld || !params.names && params.tld)
|
|
203
|
+
throw new Error(`Domain names and tld must be used together in type ${this.printPath(rt, "maxParts")}`);
|
|
204
|
+
if (params.tld && params.tld.minLength && src_utils.paramVal(params.tld.minLength) < 2)
|
|
205
|
+
throw new Error(`Domain tld.minLength cannot be less than 2 in type ${this.printPath(rt, "tld.minLength")}`);
|
|
206
|
+
if (params.tld && params.tld.maxLength && src_utils.paramVal(params.tld.maxLength) > 63)
|
|
207
|
+
throw new Error(`Domain tld.maxLength cannot be greater than 63 in type ${this.printPath(rt, "tld.maxLength")}`);
|
|
208
|
+
if (params.names && params.names.maxLength && src_utils.paramVal(params.names.maxLength) > 63)
|
|
209
|
+
throw new Error(`Domain names.maxLength cannot be greater than 63 in type ${this.printPath(rt, "names.maxLength")}`);
|
|
210
|
+
this.rootFormatter.validateParams(rt, params);
|
|
211
|
+
if (params.names?.allowedValues)
|
|
212
|
+
params.names?.allowedValues.val.forEach((val) => {
|
|
213
|
+
if (val.startsWith("-") || val.endsWith("-"))
|
|
214
|
+
throw new Error(`allowedValues[${val}] can not start or end with a hyphen in type ${this.printPath(rt, "names.allowedValues")}`);
|
|
215
|
+
});
|
|
216
|
+
if (params.names) {
|
|
217
|
+
if (Object.values(params.names).length === 0)
|
|
218
|
+
throw new Error(`Domain names must have at least one validator in type ${this.printPath(rt, "names")}`);
|
|
219
|
+
this.nameFormatter.validateParams(rt, params.names);
|
|
220
|
+
}
|
|
221
|
+
if (params.tld) {
|
|
222
|
+
if (Object.values(params.tld).length === 0)
|
|
223
|
+
throw new Error(`Domain tld must have at least one validator in type ${this.printPath(rt, "tld")}`);
|
|
224
|
+
this.tldFormatter.validateParams(rt, params.tld);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const DOMAIN_RUN_TYPE_FORMATTER = runTypes.registerFormatter(new DomainRunTypeFormat());
|
|
229
|
+
const __ΩDEFAULT_DOMAIN_PARAMS = [() => DOMAIN_PATTERN, "P", "ggle.com", "mion.io", "mionkit.io", "yahuu.net", "fbook.com", "wiki.org", "ms.net", "S", 253, "maxLength", 5, "minLength", "val", "mockSamples", "invalid domain", "errorMessage", "pattern", "DEFAULT_DOMAIN_PARAMS", `i!c"P.#.$.%.&.'.(.)Gc*P.+4,.-4.Pe#!4/e#"40.142M43Mw4y`];
|
|
230
|
+
const __ΩDEFAULT_DMM_TLD_PARAMS = [() => TLD_ALLOWED_CHARS_PATTERN, "P", "com", "org", "net", "io", "app", "co", "dev", "tech", "ai", "mion", "co.uk", "com.au", "com.br", "S", 12, "maxLength", 2, "minLength", "val", "mockSamples", "top level domain can only contain letters and dots", "errorMessage", "pattern", "DEFAULT_DMM_TLD_PARAMS", `i!c"P.#.$.%.&.'.(.).*.+.,.-.../Gc0P.142.344Pe#!45e#"46.748M49Mw:y`];
|
|
231
|
+
const __ΩDEFAULT_DOM_NAME_PARAMS = [() => DOMAIN_ALLOWED_CHARS_PATTERN, "P", "domain", "ggle", "fbook", "mion", "prot", "yahuu", "hello", "world", "example", "wiki", "mionkit", "S", 63, "maxLength", 2, "minLength", "val", "mockSamples", "domain names can only contain letters, numbers and hyphens", "errorMessage", "pattern", "DEFAULT_DOM_NAME_PARAMS", `i!c"P.#.$.%.&.'.(.).*.+.,.-Gc.P./40.142Pe#!43e#"44.546M47Mw8y`];
|
|
232
|
+
const __ΩDEFAULT_STRICT_DOMAIN_PARAMS = [6, "maxParts", 2, "minParts", () => __ΩDEFAULT_DOM_NAME_PARAMS, "names", () => __ΩDEFAULT_DMM_TLD_PARAMS, "tld", 253, "maxLength", 5, "minLength", "DEFAULT_STRICT_DOMAIN_PARAMS", `P.!4".#4$n%4&n'4(.)4*.+4,Mw-y`];
|
|
233
|
+
const __ΩFormatDomain = [() => __ΩDEFAULT_DOMAIN_PARAMS, "DP", () => runTypes.__ΩTypeFormat, "domain", "domain", "FormatDomain", 'n!c"&.$e!!.%o#%w&y'];
|
|
234
|
+
const __ΩFormatDomainStrict = ["D", () => __ΩFormatDomain, () => __ΩDEFAULT_STRICT_DOMAIN_PARAMS, "FormatDomainStrict", 'PMc!Pn#e"!Ko""w$y'];
|
|
235
|
+
exports.DOMAIN_ALLOWED_CHARS_PATTERN = DOMAIN_ALLOWED_CHARS_PATTERN;
|
|
236
|
+
exports.DOMAIN_PATTERN = DOMAIN_PATTERN;
|
|
237
|
+
exports.DOMAIN_PATTERN_PUNYCODE = DOMAIN_PATTERN_PUNYCODE;
|
|
238
|
+
exports.DOMAIN_PATTERN_UNICODE = DOMAIN_PATTERN_UNICODE;
|
|
239
|
+
exports.DOMAIN_RUN_TYPE_FORMATTER = DOMAIN_RUN_TYPE_FORMATTER;
|
|
240
|
+
exports.DomainRunTypeFormat = DomainRunTypeFormat;
|
|
241
|
+
exports.TLD_ALLOWED_CHARS_PATTERN = TLD_ALLOWED_CHARS_PATTERN;
|
|
242
|
+
exports.__ΩDEFAULT_DMM_TLD_PARAMS = __ΩDEFAULT_DMM_TLD_PARAMS;
|
|
243
|
+
exports.__ΩDEFAULT_DOMAIN_PARAMS = __ΩDEFAULT_DOMAIN_PARAMS;
|
|
244
|
+
exports.__ΩDEFAULT_DOM_NAME_PARAMS = __ΩDEFAULT_DOM_NAME_PARAMS;
|
|
245
|
+
exports.__ΩDEFAULT_STRICT_DOMAIN_PARAMS = __ΩDEFAULT_STRICT_DOMAIN_PARAMS;
|
|
246
|
+
exports.__ΩFormatDomain = __ΩFormatDomain;
|
|
247
|
+
exports.__ΩFormatDomainStrict = __ΩFormatDomainStrict;
|
|
248
|
+
//# sourceMappingURL=domain.runtype.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.runtype.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { BaseRunType, JitFnCompiler, JitErrorsFnCompiler, JitCode, JitFnID, StrNumber, BaseRunTypeFormat, RunTypeOptions, TypeFormat } from '@mionjs/run-types';
|
|
2
|
+
import { ReflectionKind } from '@deepkit/type';
|
|
3
|
+
import { FormatParams_Domain, Samples } from '@mionjs/core';
|
|
4
|
+
export declare const DOMAIN_PATTERN: RegExp;
|
|
5
|
+
export declare const DOMAIN_PATTERN_UNICODE: RegExp;
|
|
6
|
+
export declare const DOMAIN_PATTERN_PUNYCODE: RegExp;
|
|
7
|
+
export declare const DOMAIN_ALLOWED_CHARS_PATTERN: RegExp;
|
|
8
|
+
export declare const TLD_ALLOWED_CHARS_PATTERN: RegExp;
|
|
9
|
+
export declare class DomainRunTypeFormat extends BaseRunTypeFormat<FormatParams_Domain> {
|
|
10
|
+
static id: "domain";
|
|
11
|
+
kind: ReflectionKind;
|
|
12
|
+
name: "domain";
|
|
13
|
+
private rootFormatter;
|
|
14
|
+
private nameFormatter;
|
|
15
|
+
private tldFormatter;
|
|
16
|
+
constructor(parentPath?: StrNumber[]);
|
|
17
|
+
canEmbedFormatterCode(fnID: JitFnID, rt: BaseRunType, p?: FormatParams_Domain): boolean;
|
|
18
|
+
getIgnoredProps(): string[] | undefined;
|
|
19
|
+
emitIsType(comp: JitFnCompiler, rt: BaseRunType): JitCode;
|
|
20
|
+
emitIsTypeErrors(comp: JitErrorsFnCompiler, rt: BaseRunType): JitCode;
|
|
21
|
+
_mock(opts: RunTypeOptions, rt: BaseRunType): string;
|
|
22
|
+
private hasNoConstrains;
|
|
23
|
+
private mockName;
|
|
24
|
+
private mockTld;
|
|
25
|
+
emitFormat(comp: JitFnCompiler): JitCode;
|
|
26
|
+
_formatMockedValue(opts: RunTypeOptions, _rt: BaseRunType, val: any): string;
|
|
27
|
+
validateParams(rt: BaseRunType, params: FormatParams_Domain): void;
|
|
28
|
+
}
|
|
29
|
+
export declare const DOMAIN_RUN_TYPE_FORMATTER: DomainRunTypeFormat;
|
|
30
|
+
export type DEFAULT_DOMAIN_PARAMS<P extends RegExp = typeof DOMAIN_PATTERN, S extends Samples = ['ggle.com', 'mion.io', 'mionkit.io', 'yahuu.net', 'fbook.com', 'wiki.org', 'ms.net']> = {
|
|
31
|
+
maxLength: 253;
|
|
32
|
+
minLength: 5;
|
|
33
|
+
pattern: {
|
|
34
|
+
val: P;
|
|
35
|
+
mockSamples: S;
|
|
36
|
+
errorMessage: 'invalid domain';
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export type DEFAULT_DMM_TLD_PARAMS<P extends RegExp = typeof TLD_ALLOWED_CHARS_PATTERN, S extends Samples = ['com', 'org', 'net', 'io', 'app', 'co', 'dev', 'tech', 'ai', 'mion', 'co.uk', 'com.au', 'com.br']> = {
|
|
40
|
+
maxLength: 12;
|
|
41
|
+
minLength: 2;
|
|
42
|
+
pattern: {
|
|
43
|
+
val: P;
|
|
44
|
+
mockSamples: S;
|
|
45
|
+
errorMessage: 'top level domain can only contain letters and dots';
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export type DEFAULT_DOM_NAME_PARAMS<P extends RegExp = typeof DOMAIN_ALLOWED_CHARS_PATTERN, S extends Samples = ['domain', 'ggle', 'fbook', 'mion', 'prot', 'yahuu', 'hello', 'world', 'example', 'wiki', 'mionkit']> = {
|
|
49
|
+
maxLength: 63;
|
|
50
|
+
minLength: 2;
|
|
51
|
+
pattern: {
|
|
52
|
+
val: P;
|
|
53
|
+
mockSamples: S;
|
|
54
|
+
errorMessage: 'domain names can only contain letters, numbers and hyphens';
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export type DEFAULT_STRICT_DOMAIN_PARAMS = {
|
|
58
|
+
maxParts: 6;
|
|
59
|
+
minParts: 2;
|
|
60
|
+
names: DEFAULT_DOM_NAME_PARAMS;
|
|
61
|
+
tld: DEFAULT_DMM_TLD_PARAMS;
|
|
62
|
+
maxLength: 253;
|
|
63
|
+
minLength: 5;
|
|
64
|
+
};
|
|
65
|
+
export type FormatDomain<DP extends FormatParams_Domain = DEFAULT_DOMAIN_PARAMS> = TypeFormat<string, 'domain', DP, 'domain'>;
|
|
66
|
+
export type FormatDomainStrict<D extends Partial<FormatParams_Domain> = {}> = FormatDomain<DEFAULT_STRICT_DOMAIN_PARAMS & D>;
|
|
67
|
+
export declare type __ΩDEFAULT_DOMAIN_PARAMS = any[];
|
|
68
|
+
export declare type __ΩDEFAULT_DMM_TLD_PARAMS = any[];
|
|
69
|
+
export declare type __ΩDEFAULT_DOM_NAME_PARAMS = any[];
|
|
70
|
+
export declare type __ΩDEFAULT_STRICT_DOMAIN_PARAMS = any[];
|
|
71
|
+
export declare type __ΩFormatDomain = any[];
|
|
72
|
+
export declare type __ΩFormatDomainStrict = any[];
|