@stndrds/schema 1.0.0-alpha.294 → 1.0.0-alpha.296
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/LICENSE +111 -0
- package/README.md +7 -0
- package/dist/{all-Cru_CaSY.d.mts → all-BekDmUP1.d.mts} +32 -32
- package/dist/{all-CDJSpI46.d.ts → all-Bl3DlCEn.d.ts} +32 -32
- package/dist/{attributes-CWPLbp7c.d.mts → attributes-CtS5Gf_i.d.mts} +1 -1
- package/dist/{attributes-CNYwg_Nr.d.ts → attributes-SIbTof03.d.ts} +1 -1
- package/dist/capabilities.js +2 -77
- package/dist/capabilities.mjs +2 -70
- package/dist/chunk-23KPS33D.js +2 -0
- package/dist/chunk-47EGJRW7.js +4 -0
- package/dist/chunk-47KVYDKG.js +2 -0
- package/dist/chunk-4OTKOCGB.mjs +2 -0
- package/dist/chunk-4VCADZK4.mjs +2 -0
- package/dist/chunk-5QAE5NPN.js +6 -0
- package/dist/chunk-72TQRSNX.js +12 -0
- package/dist/chunk-DPD6ZWL2.js +2 -0
- package/dist/chunk-GKXTXH4Y.mjs +2 -0
- package/dist/chunk-GWAHL4A2.mjs +2 -0
- package/dist/chunk-GXSNLYRR.js +2 -0
- package/dist/chunk-JCPAOH76.mjs +2 -0
- package/dist/chunk-JFSQ24XR.js +2 -0
- package/dist/chunk-JOS2XMXY.js +2 -0
- package/dist/chunk-JVLH3DVZ.js +2 -0
- package/dist/chunk-KG2ADZG6.mjs +2 -0
- package/dist/chunk-KLR22JMC.js +2 -0
- package/dist/chunk-KSPJP74K.mjs +2 -0
- package/dist/chunk-KYPEBOPW.mjs +2 -0
- package/dist/chunk-LB4TNMZU.mjs +2 -0
- package/dist/chunk-LQYUPOWB.js +2 -0
- package/dist/chunk-LSCBR4VS.js +2 -0
- package/dist/chunk-LWSOKXPF.js +2 -0
- package/dist/chunk-O34B5KOW.mjs +2 -0
- package/dist/chunk-PFO7NWQW.mjs +2 -0
- package/dist/chunk-PT25FZ62.mjs +12 -0
- package/dist/chunk-Q7TQCRSD.mjs +2 -0
- package/dist/chunk-RFKNNT2Q.mjs +4 -0
- package/dist/chunk-SDOYGWU4.js +2 -0
- package/dist/chunk-SLYRQ72J.js +2 -0
- package/dist/chunk-UXISKZ5Y.js +2 -0
- package/dist/chunk-V43RXKN2.mjs +6 -0
- package/dist/chunk-VKFLXFPP.mjs +2 -0
- package/dist/chunk-WMQRTFOP.mjs +2 -0
- package/dist/chunk-XHEBV2HE.js +2 -0
- package/dist/chunk-XMQV2WFY.mjs +2 -0
- package/dist/chunk-XRDP2Y4J.mjs +2 -0
- package/dist/chunk-XUAP7KWK.js +2 -0
- package/dist/chunk-XXTKNIBK.js +2 -0
- package/dist/chunk-YIXNAWH6.mjs +2 -0
- package/dist/exceptions.d.mts +8 -2
- package/dist/exceptions.d.ts +8 -2
- package/dist/exceptions.js +1 -158
- package/dist/exceptions.mjs +1 -1
- package/dist/{helpers-Dul_r9rJ.d.mts → helpers-BUsoR80N.d.mts} +3 -3
- package/dist/{helpers-CXkVwpsl.d.ts → helpers-DZFOorZt.d.ts} +3 -3
- package/dist/{index-CFhPHQaI.d.ts → index-DaY37pqb.d.ts} +2 -2
- package/dist/{index-BdVnHL3F.d.mts → index-EHhbbH-p.d.mts} +2 -2
- package/dist/index.d.mts +500 -146
- package/dist/index.d.ts +500 -146
- package/dist/index.js +30 -10514
- package/dist/index.mjs +30 -9626
- package/dist/{migrations-fRvadl6i.d.mts → migrations-DRBic-QO.d.mts} +1 -1
- package/dist/{migrations-DaFneOfx.d.ts → migrations-DhQ05TqN.d.ts} +1 -1
- package/dist/{objects-DJv6WrDE.d.ts → objects-DMOfJNYg.d.ts} +2 -2
- package/dist/{objects-CDwMSnqv.d.mts → objects-KU7alqZq.d.mts} +2 -2
- package/dist/{types-NGEww_ln.d.ts → types-BNaHEz_n.d.ts} +1 -1
- package/dist/{types-CVYiFc69.d.mts → types-ldo4nJxP.d.mts} +1 -1
- package/dist/utils.js +1 -31
- package/dist/utils.mjs +1 -2
- package/dist/validation/all.d.mts +7 -7
- package/dist/validation/all.d.ts +7 -7
- package/dist/validation/all.js +1 -131
- package/dist/validation/all.mjs +1 -18
- package/dist/validation/complex/currency.d.mts +2 -2
- package/dist/validation/complex/currency.d.ts +2 -2
- package/dist/validation/complex/currency.js +1 -11
- package/dist/validation/complex/currency.mjs +1 -2
- package/dist/validation/complex/location.d.mts +2 -2
- package/dist/validation/complex/location.d.ts +2 -2
- package/dist/validation/complex/location.js +1 -11
- package/dist/validation/complex/location.mjs +1 -2
- package/dist/validation/complex/phone.d.mts +2 -2
- package/dist/validation/complex/phone.d.ts +2 -2
- package/dist/validation/complex/phone.js +1 -11
- package/dist/validation/complex/phone.mjs +1 -2
- package/dist/validation/complex/relation.d.mts +2 -2
- package/dist/validation/complex/relation.d.ts +2 -2
- package/dist/validation/complex/relation.js +1 -19
- package/dist/validation/complex/relation.mjs +1 -2
- package/dist/validation/complex/richtext.d.mts +2 -2
- package/dist/validation/complex/richtext.d.ts +2 -2
- package/dist/validation/complex/richtext.js +1 -11
- package/dist/validation/complex/richtext.mjs +1 -2
- package/dist/validation/complex/select.d.mts +2 -2
- package/dist/validation/complex/select.d.ts +2 -2
- package/dist/validation/complex/select.js +1 -19
- package/dist/validation/complex/select.mjs +1 -2
- package/dist/validation/complex/user.d.mts +2 -2
- package/dist/validation/complex/user.d.ts +2 -2
- package/dist/validation/complex/user.js +1 -11
- package/dist/validation/complex/user.mjs +1 -2
- package/dist/validation/computed/formula.d.mts +2 -2
- package/dist/validation/computed/formula.d.ts +2 -2
- package/dist/validation/computed/formula.js +1 -11
- package/dist/validation/computed/formula.mjs +1 -2
- package/dist/validation/computed/rollup.d.mts +2 -2
- package/dist/validation/computed/rollup.d.ts +2 -2
- package/dist/validation/computed/rollup.js +1 -11
- package/dist/validation/computed/rollup.mjs +1 -2
- package/dist/validation/config/index.d.mts +4 -4
- package/dist/validation/config/index.d.ts +4 -4
- package/dist/validation/config/index.js +1 -52
- package/dist/validation/config/index.mjs +1 -7
- package/dist/validation/core/index.d.mts +3 -3
- package/dist/validation/core/index.d.ts +3 -3
- package/dist/validation/core/index.js +1 -14
- package/dist/validation/core/index.mjs +1 -1
- package/dist/validation/object/index.d.mts +5 -5
- package/dist/validation/object/index.d.ts +5 -5
- package/dist/validation/object/index.js +1 -69
- package/dist/validation/object/index.mjs +1 -16
- package/dist/validation/primitives/checkbox.d.mts +2 -2
- package/dist/validation/primitives/checkbox.d.ts +2 -2
- package/dist/validation/primitives/checkbox.js +1 -11
- package/dist/validation/primitives/checkbox.mjs +1 -2
- package/dist/validation/primitives/date.d.mts +2 -2
- package/dist/validation/primitives/date.d.ts +2 -2
- package/dist/validation/primitives/date.js +1 -11
- package/dist/validation/primitives/date.mjs +1 -2
- package/dist/validation/primitives/number.d.mts +2 -2
- package/dist/validation/primitives/number.d.ts +2 -2
- package/dist/validation/primitives/number.js +1 -11
- package/dist/validation/primitives/number.mjs +1 -2
- package/dist/validation/primitives/text.d.mts +2 -2
- package/dist/validation/primitives/text.d.ts +2 -2
- package/dist/validation/primitives/text.js +1 -11
- package/dist/validation/primitives/text.mjs +1 -2
- package/package.json +7 -5
- package/dist/chunk-2WWGHULM.mjs +0 -226
- package/dist/chunk-4KMUATDG.js +0 -609
- package/dist/chunk-5WATIVCA.js +0 -10
- package/dist/chunk-ACKMC6FL.js +0 -17
- package/dist/chunk-AYVHMVKQ.mjs +0 -15
- package/dist/chunk-CLZORRMS.mjs +0 -570
- package/dist/chunk-DVXGSTWJ.js +0 -81
- package/dist/chunk-E6JUYGJX.js +0 -22
- package/dist/chunk-EEH4XQ7W.js +0 -61
- package/dist/chunk-EW5XR2X3.js +0 -12
- package/dist/chunk-GO6LQADH.mjs +0 -57
- package/dist/chunk-HRQEZUAA.mjs +0 -29
- package/dist/chunk-HTSTPTNZ.js +0 -10
- package/dist/chunk-HURC6CW3.js +0 -241
- package/dist/chunk-JZNR4HKQ.mjs +0 -1432
- package/dist/chunk-KAWYU7TE.js +0 -657
- package/dist/chunk-KNGWHQLR.js +0 -16
- package/dist/chunk-LV3FEUKU.mjs +0 -14
- package/dist/chunk-NS63SPNN.mjs +0 -8
- package/dist/chunk-O73ROMWQ.mjs +0 -85
- package/dist/chunk-OSSGN43B.mjs +0 -8
- package/dist/chunk-Q44QKLN4.mjs +0 -43
- package/dist/chunk-Q4SZAMJT.js +0 -72
- package/dist/chunk-QT35SI3K.mjs +0 -641
- package/dist/chunk-QVLQPW3O.mjs +0 -10
- package/dist/chunk-QWKLQRBX.js +0 -35
- package/dist/chunk-R2DAEDRF.mjs +0 -74
- package/dist/chunk-R5LAJCBU.mjs +0 -67
- package/dist/chunk-SI34M4IC.js +0 -45
- package/dist/chunk-T5PM73EF.js +0 -1504
- package/dist/chunk-UANQJ2GH.mjs +0 -25
- package/dist/chunk-UXAHLSWC.mjs +0 -8
- package/dist/chunk-V2UA2D4E.js +0 -10
- package/dist/chunk-YIP5FJ5H.js +0 -27
- package/dist/chunk-YKWSHBT5.js +0 -32
- package/dist/chunk-YUFTHPOE.mjs +0 -20
- package/dist/chunk-ZDQ5AP26.mjs +0 -31
- package/dist/chunk-ZPFOKBIN.js +0 -89
package/dist/chunk-O73ROMWQ.mjs
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-HRQEZUAA.mjs';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
// src/lib/text-format.ts
|
|
5
|
-
var TEXT_FORMAT_PATTERNS = {
|
|
6
|
-
email: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
|
|
7
|
-
url: "^https?:\\/\\/[\\w\\-]+(\\.[\\w\\-]+)+[/#?]?.*$",
|
|
8
|
-
slug: "^[a-z0-9]+(?:-[a-z0-9]+)*$"
|
|
9
|
-
};
|
|
10
|
-
function resolveTextPattern(attr) {
|
|
11
|
-
if (attr.pattern) return attr.pattern;
|
|
12
|
-
return attr.format ? TEXT_FORMAT_PATTERNS[attr.format] : void 0;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/lib/lru-cache.ts
|
|
16
|
-
var LRUCache = class {
|
|
17
|
-
constructor(capacity) {
|
|
18
|
-
if (!Number.isInteger(capacity) || capacity <= 0) {
|
|
19
|
-
throw new Error("LRU cache capacity must be greater than 0");
|
|
20
|
-
}
|
|
21
|
-
this.capacity = capacity;
|
|
22
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
23
|
-
}
|
|
24
|
-
get(key) {
|
|
25
|
-
if (!this.cache.has(key)) {
|
|
26
|
-
return void 0;
|
|
27
|
-
}
|
|
28
|
-
const value = this.cache.get(key);
|
|
29
|
-
this.cache.delete(key);
|
|
30
|
-
this.cache.set(key, value);
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
set(key, value) {
|
|
34
|
-
if (this.cache.has(key)) {
|
|
35
|
-
this.cache.delete(key);
|
|
36
|
-
} else if (this.cache.size >= this.capacity) {
|
|
37
|
-
const first = this.cache.keys().next();
|
|
38
|
-
if (!first.done) {
|
|
39
|
-
this.cache.delete(first.value);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
this.cache.set(key, value);
|
|
43
|
-
}
|
|
44
|
-
has(key) {
|
|
45
|
-
return this.cache.has(key);
|
|
46
|
-
}
|
|
47
|
-
clear() {
|
|
48
|
-
this.cache.clear();
|
|
49
|
-
}
|
|
50
|
-
get size() {
|
|
51
|
-
return this.cache.size;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// src/validation/core/regex-cache.ts
|
|
56
|
-
function createRegexCache(capacity = 100) {
|
|
57
|
-
return new LRUCache(capacity);
|
|
58
|
-
}
|
|
59
|
-
function getCachedRegex(cache, pattern) {
|
|
60
|
-
let cached = cache.get(pattern);
|
|
61
|
-
if (!cached) {
|
|
62
|
-
cached = new RegExp(pattern);
|
|
63
|
-
cache.set(pattern, cached);
|
|
64
|
-
}
|
|
65
|
-
return cached;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// src/validation/primitives/text.ts
|
|
69
|
-
var textRegexCache = createRegexCache();
|
|
70
|
-
function createTextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
71
|
-
let schema = z.string();
|
|
72
|
-
if (attr.minLength !== void 0) {
|
|
73
|
-
schema = schema.min(attr.minLength, messages.minLength(attr, attr.minLength));
|
|
74
|
-
}
|
|
75
|
-
if (attr.maxLength !== void 0) {
|
|
76
|
-
schema = schema.max(attr.maxLength, messages.maxLength(attr, attr.maxLength));
|
|
77
|
-
}
|
|
78
|
-
const pattern = resolveTextPattern(attr);
|
|
79
|
-
if (pattern) {
|
|
80
|
-
schema = schema.regex(getCachedRegex(textRegexCache, pattern), messages.invalidPattern(attr));
|
|
81
|
-
}
|
|
82
|
-
return schema;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export { TEXT_FORMAT_PATTERNS, createTextValidator, resolveTextPattern };
|
package/dist/chunk-OSSGN43B.mjs
DELETED
package/dist/chunk-Q44QKLN4.mjs
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-HRQEZUAA.mjs';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
function resolveBound(bound) {
|
|
5
|
-
if (!bound) return null;
|
|
6
|
-
const raw = bound === "today" ? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10) : bound;
|
|
7
|
-
const parsed = new Date(raw);
|
|
8
|
-
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
|
9
|
-
}
|
|
10
|
-
function createDateValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
11
|
-
const message = messages.invalidDate(attr);
|
|
12
|
-
const min = resolveBound(attr.minDate);
|
|
13
|
-
const max = resolveBound(attr.maxDate);
|
|
14
|
-
const bound = z.any().superRefine((raw, ctx) => {
|
|
15
|
-
const coerced = new Date(raw);
|
|
16
|
-
if (Number.isNaN(coerced.getTime())) {
|
|
17
|
-
ctx.addIssue({ code: "custom", message });
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (min && coerced < min) {
|
|
21
|
-
ctx.addIssue({ code: "custom", message });
|
|
22
|
-
}
|
|
23
|
-
if (max && coerced > max) {
|
|
24
|
-
ctx.addIssue({ code: "custom", message });
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
if (!attr.endDate) return bound;
|
|
28
|
-
const range = z.object({ start: bound, end: bound.nullable() }).superRefine((value, ctx) => {
|
|
29
|
-
if (value.end === null) return;
|
|
30
|
-
const start = new Date(value.start);
|
|
31
|
-
const end = new Date(value.end);
|
|
32
|
-
const bothValid = !(Number.isNaN(start.getTime()) || Number.isNaN(end.getTime()));
|
|
33
|
-
if (bothValid && end < start) {
|
|
34
|
-
ctx.addIssue({ code: "custom", message, path: ["end"] });
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
return z.preprocess(
|
|
38
|
-
(value) => typeof value === "string" ? { start: value, end: null } : value,
|
|
39
|
-
range
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { createDateValidator };
|
package/dist/chunk-Q4SZAMJT.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkYKWSHBT5_js = require('./chunk-YKWSHBT5.js');
|
|
4
|
-
var constants = require('@stndrds/constants');
|
|
5
|
-
var zod = require('zod');
|
|
6
|
-
var libphonenumberJs = require('libphonenumber-js');
|
|
7
|
-
|
|
8
|
-
function digitsOnly(input) {
|
|
9
|
-
return input.replace(/\D/g, "");
|
|
10
|
-
}
|
|
11
|
-
function normalizeCountrylessPhoneNumber(phoneNumber) {
|
|
12
|
-
return digitsOnly(phoneNumber);
|
|
13
|
-
}
|
|
14
|
-
function getIso2(iso3) {
|
|
15
|
-
const country = constants.getCountryByIso3(iso3);
|
|
16
|
-
return country?.iso2;
|
|
17
|
-
}
|
|
18
|
-
function normalizePhoneNumber(phoneNumber, countryIso3) {
|
|
19
|
-
if (!phoneNumber) return "";
|
|
20
|
-
const iso2 = getIso2(countryIso3);
|
|
21
|
-
if (!iso2) {
|
|
22
|
-
return digitsOnly(phoneNumber);
|
|
23
|
-
}
|
|
24
|
-
const parsed = libphonenumberJs.parsePhoneNumberFromString(phoneNumber, iso2);
|
|
25
|
-
if (parsed) {
|
|
26
|
-
return parsed.nationalNumber;
|
|
27
|
-
}
|
|
28
|
-
const country = constants.getCountryByIso3(countryIso3);
|
|
29
|
-
const digits = digitsOnly(phoneNumber);
|
|
30
|
-
if (country) {
|
|
31
|
-
const callingCode = country.phoneCode.replace("+", "");
|
|
32
|
-
const withoutCC = digits.startsWith(callingCode) ? digits.slice(callingCode.length) : digits;
|
|
33
|
-
return constants.stripTrunkPrefix(withoutCC, country.phoneTrunkPrefix ?? "");
|
|
34
|
-
}
|
|
35
|
-
return digits;
|
|
36
|
-
}
|
|
37
|
-
function formatPhoneForDisplay(phone) {
|
|
38
|
-
if (!phone.phoneNumber) return "";
|
|
39
|
-
const iso2 = getIso2(phone.countryCode);
|
|
40
|
-
const country = constants.getCountryByIso3(phone.countryCode);
|
|
41
|
-
const dial = country?.phoneCode ?? "";
|
|
42
|
-
if (!iso2) {
|
|
43
|
-
return `${dial} ${phone.phoneNumber}`.trim();
|
|
44
|
-
}
|
|
45
|
-
const e164 = `${dial}${digitsOnly(phone.phoneNumber)}`;
|
|
46
|
-
const parsed = libphonenumberJs.parsePhoneNumberFromString(e164);
|
|
47
|
-
if (parsed) {
|
|
48
|
-
return parsed.formatInternational();
|
|
49
|
-
}
|
|
50
|
-
return `${dial} ${phone.phoneNumber}`.trim();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// src/validation/complex/phone.ts
|
|
54
|
-
function createPhoneValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
55
|
-
return zod.z.object(
|
|
56
|
-
{
|
|
57
|
-
countryCode: zod.z.string().length(3),
|
|
58
|
-
phoneNumber: zod.z.string().min(1)
|
|
59
|
-
},
|
|
60
|
-
{ message: messages.invalidPhone(attr) }
|
|
61
|
-
).refine((val) => constants.isValidIso3(val.countryCode), {
|
|
62
|
-
message: "Invalid country code"
|
|
63
|
-
}).transform((val) => ({
|
|
64
|
-
countryCode: val.countryCode,
|
|
65
|
-
phoneNumber: normalizePhoneNumber(val.phoneNumber, val.countryCode)
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
exports.createPhoneValidator = createPhoneValidator;
|
|
70
|
-
exports.formatPhoneForDisplay = formatPhoneForDisplay;
|
|
71
|
-
exports.normalizeCountrylessPhoneNumber = normalizeCountrylessPhoneNumber;
|
|
72
|
-
exports.normalizePhoneNumber = normalizePhoneNumber;
|