@stndrds/schema 1.0.0-alpha.95 → 1.0.0-alpha.97
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/attributes-C-bhC0k5.d.ts +673 -0
- package/dist/attributes-DB76JqXm.d.mts +673 -0
- package/dist/chunk-2TEWGEUI.js +212 -0
- package/dist/chunk-4RGFTMQR.mjs +8 -0
- package/dist/chunk-5TLM4QXO.mjs +8 -0
- package/dist/chunk-67PQMHQA.mjs +199 -0
- package/dist/chunk-6HHSX6LP.js +64 -0
- package/dist/chunk-AHPXNPJC.js +105 -0
- package/dist/chunk-BEN6TE7Y.js +11 -0
- package/dist/chunk-BH3RPSC5.js +22 -0
- package/dist/chunk-BIQ35DLC.mjs +78 -0
- package/dist/chunk-CKZHFJQT.js +16 -0
- package/dist/chunk-E6XO2STS.js +11 -11
- package/dist/chunk-EIWGW2ML.mjs +99 -0
- package/dist/chunk-EKG35CSO.mjs +1 -0
- package/dist/chunk-IMEPIVTR.js +217 -0
- package/dist/chunk-J4ORNCAH.js +10 -0
- package/dist/chunk-KC4F3HB7.js +32 -0
- package/dist/chunk-LHXE7LLD.js +28 -0
- package/dist/chunk-MD6XGXTU.mjs +18 -0
- package/dist/chunk-N47XKY4R.js +14 -0
- package/dist/chunk-NXXSNUDI.mjs +8 -0
- package/dist/chunk-PKG3E5MW.mjs +18 -0
- package/dist/chunk-PZT3CIHD.mjs +192 -0
- package/dist/chunk-QL3UGPUG.mjs +60 -0
- package/dist/chunk-QY65ZSBL.js +16 -0
- package/dist/chunk-R6JFUC32.js +2 -0
- package/dist/chunk-RDXQ4CYT.mjs +9 -0
- package/dist/chunk-S5VJ2FZE.js +12 -0
- package/dist/chunk-SVII65W7.mjs +14 -0
- package/dist/chunk-U7VN3RUE.mjs +25 -0
- package/dist/chunk-VCPYYLCS.js +83 -0
- package/dist/chunk-VD3P2A6Q.js +10 -0
- package/dist/chunk-VPEV3W34.mjs +10 -0
- package/dist/chunk-WGFQMQMV.mjs +14 -0
- package/dist/chunk-X6VDDXG7.mjs +12 -0
- package/dist/chunk-XAORXFAX.mjs +1 -10
- package/dist/chunk-XEOG24K6.mjs +8 -0
- package/dist/chunk-XK6XC3V4.js +10 -0
- package/dist/chunk-XZ5B5MTG.js +20 -0
- package/dist/chunk-YKHC2AW6.js +10 -0
- package/dist/chunk-Z2T7ONKU.js +20 -0
- package/dist/chunk-ZFL7DXAE.mjs +28 -0
- package/dist/chunk-ZM7W2ZCF.mjs +20 -0
- package/dist/{validators-5XMwJOlV.d.ts → index-Bt-0XNSh.d.ts} +14 -1499
- package/dist/{validators-BCw4Sn01.d.mts → index-C9tOwUbK.d.mts} +14 -1499
- package/dist/index.d.mts +1267 -976
- package/dist/index.d.ts +1267 -976
- package/dist/index.js +1293 -1001
- package/dist/index.mjs +529 -785
- package/dist/types-B7nS2D1A.d.ts +39 -0
- package/dist/types-CjXbGsy8.d.mts +39 -0
- package/dist/utils.js +38 -20
- package/dist/utils.mjs +1 -20
- package/dist/validation/all.d.mts +23 -0
- package/dist/validation/all.d.ts +23 -0
- package/dist/validation/all.js +265 -0
- package/dist/validation/all.mjs +20 -0
- package/dist/validation/complex/currency.d.mts +15 -0
- package/dist/validation/complex/currency.d.ts +15 -0
- package/dist/validation/complex/currency.js +12 -0
- package/dist/validation/complex/currency.mjs +3 -0
- package/dist/validation/complex/file.d.mts +13 -0
- package/dist/validation/complex/file.d.ts +13 -0
- package/dist/validation/complex/file.js +12 -0
- package/dist/validation/complex/file.mjs +3 -0
- package/dist/validation/complex/location.d.mts +22 -0
- package/dist/validation/complex/location.d.ts +22 -0
- package/dist/validation/complex/location.js +12 -0
- package/dist/validation/complex/location.mjs +3 -0
- package/dist/validation/complex/phone.d.mts +22 -0
- package/dist/validation/complex/phone.d.ts +22 -0
- package/dist/validation/complex/phone.js +12 -0
- package/dist/validation/complex/phone.mjs +3 -0
- package/dist/validation/complex/relation.d.mts +25 -0
- package/dist/validation/complex/relation.d.ts +25 -0
- package/dist/validation/complex/relation.js +20 -0
- package/dist/validation/complex/relation.mjs +3 -0
- package/dist/validation/complex/richtext.d.mts +13 -0
- package/dist/validation/complex/richtext.d.ts +13 -0
- package/dist/validation/complex/richtext.js +12 -0
- package/dist/validation/complex/richtext.mjs +3 -0
- package/dist/validation/complex/select.d.mts +20 -0
- package/dist/validation/complex/select.d.ts +20 -0
- package/dist/validation/complex/select.js +20 -0
- package/dist/validation/complex/select.mjs +3 -0
- package/dist/validation/complex/user.d.mts +13 -0
- package/dist/validation/complex/user.d.ts +13 -0
- package/dist/validation/complex/user.js +12 -0
- package/dist/validation/complex/user.mjs +3 -0
- package/dist/validation/computed/formula.d.mts +14 -0
- package/dist/validation/computed/formula.d.ts +14 -0
- package/dist/validation/computed/formula.js +12 -0
- package/dist/validation/computed/formula.mjs +3 -0
- package/dist/validation/computed/rollup.d.mts +14 -0
- package/dist/validation/computed/rollup.d.ts +14 -0
- package/dist/validation/computed/rollup.js +12 -0
- package/dist/validation/computed/rollup.mjs +3 -0
- package/dist/validation/config/index.d.mts +421 -0
- package/dist/validation/config/index.d.ts +421 -0
- package/dist/validation/config/index.js +103 -0
- package/dist/validation/config/index.mjs +2 -0
- package/dist/validation/core/index.d.mts +85 -0
- package/dist/validation/core/index.d.ts +85 -0
- package/dist/validation/core/index.js +27 -0
- package/dist/validation/core/index.mjs +2 -0
- package/dist/validation/object/index.d.mts +6 -0
- package/dist/validation/object/index.d.ts +6 -0
- package/dist/validation/object/index.js +71 -0
- package/dist/validation/object/index.mjs +18 -0
- package/dist/validation/primitives/checkbox.d.mts +12 -0
- package/dist/validation/primitives/checkbox.d.ts +12 -0
- package/dist/validation/primitives/checkbox.js +12 -0
- package/dist/validation/primitives/checkbox.mjs +3 -0
- package/dist/validation/primitives/date.d.mts +12 -0
- package/dist/validation/primitives/date.d.ts +12 -0
- package/dist/validation/primitives/date.js +12 -0
- package/dist/validation/primitives/date.mjs +3 -0
- package/dist/validation/primitives/number.d.mts +12 -0
- package/dist/validation/primitives/number.d.ts +12 -0
- package/dist/validation/primitives/number.js +12 -0
- package/dist/validation/primitives/number.mjs +3 -0
- package/dist/validation/primitives/rating.d.mts +12 -0
- package/dist/validation/primitives/rating.d.ts +12 -0
- package/dist/validation/primitives/rating.js +12 -0
- package/dist/validation/primitives/rating.mjs +3 -0
- package/dist/validation/primitives/text.d.mts +17 -0
- package/dist/validation/primitives/text.d.ts +17 -0
- package/dist/validation/primitives/text.js +16 -0
- package/dist/validation/primitives/text.mjs +3 -0
- package/dist/validation/validators.d.mts +21 -2
- package/dist/validation/validators.d.ts +21 -2
- package/dist/validation/validators.js +265 -120
- package/dist/validation/validators.mjs +20 -120
- package/package.json +108 -5
- package/dist/chunk-4362R5F2.mjs +0 -780
- package/dist/chunk-7QUI6TSO.js +0 -780
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/validation/core/messages.ts
|
|
2
|
+
var DEFAULT_VALIDATION_MESSAGES = {
|
|
3
|
+
required: (attr) => `${attr.label} is required`,
|
|
4
|
+
invalidType: (attr, expected) => `${attr.label} must be a ${expected}`,
|
|
5
|
+
minLength: (attr, min) => `${attr.label} must be at least ${min} characters`,
|
|
6
|
+
maxLength: (attr, max) => `${attr.label} must be at most ${max} characters`,
|
|
7
|
+
invalidPattern: (attr) => `${attr.label} format is invalid`,
|
|
8
|
+
minValue: (attr, min) => `${attr.label} must be at least ${min}`,
|
|
9
|
+
maxValue: (attr, max) => `${attr.label} must be at most ${max}`,
|
|
10
|
+
mustBeInteger: (attr) => `${attr.label} must be an integer`,
|
|
11
|
+
invalidDate: (attr) => `${attr.label} must be a valid date`,
|
|
12
|
+
invalidOption: (attr, options) => `${attr.label} must be one of: ${options.join(", ")}`,
|
|
13
|
+
invalidId: (attr) => `${attr.label} must be a valid ID`,
|
|
14
|
+
minItems: (attr, min) => `${attr.label} must have at least ${min} item${min > 1 ? "s" : ""}`,
|
|
15
|
+
maxItems: (attr, max) => `${attr.label} must have at most ${max} item${max > 1 ? "s" : ""}`,
|
|
16
|
+
invalidRichtext: (attr) => `${attr.label} must be valid rich text content`,
|
|
17
|
+
invalidPhone: (attr) => `${attr.label} must be a valid phone number`,
|
|
18
|
+
invalidCurrency: (attr) => `${attr.label} must be a valid currency value`,
|
|
19
|
+
invalidLocation: (attr) => `${attr.label} must be a valid location`
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/lib/lru-cache.ts
|
|
23
|
+
var LRUCache = class {
|
|
24
|
+
constructor(capacity) {
|
|
25
|
+
if (capacity <= 0) {
|
|
26
|
+
throw new Error("LRU cache capacity must be greater than 0");
|
|
27
|
+
}
|
|
28
|
+
this.capacity = capacity;
|
|
29
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
30
|
+
}
|
|
31
|
+
get(key) {
|
|
32
|
+
const value = this.cache.get(key);
|
|
33
|
+
if (value !== void 0) {
|
|
34
|
+
this.cache.delete(key);
|
|
35
|
+
this.cache.set(key, value);
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
set(key, value) {
|
|
40
|
+
if (this.cache.has(key)) {
|
|
41
|
+
this.cache.delete(key);
|
|
42
|
+
} else if (this.cache.size >= this.capacity) {
|
|
43
|
+
const firstKey = this.cache.keys().next().value;
|
|
44
|
+
if (firstKey !== void 0) {
|
|
45
|
+
this.cache.delete(firstKey);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
this.cache.set(key, value);
|
|
49
|
+
}
|
|
50
|
+
has(key) {
|
|
51
|
+
return this.cache.has(key);
|
|
52
|
+
}
|
|
53
|
+
clear() {
|
|
54
|
+
this.cache.clear();
|
|
55
|
+
}
|
|
56
|
+
get size() {
|
|
57
|
+
return this.cache.size;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/validation/core/regex-cache.ts
|
|
62
|
+
function createRegexCache(capacity = 100) {
|
|
63
|
+
return new LRUCache(capacity);
|
|
64
|
+
}
|
|
65
|
+
function getCachedRegex(cache, pattern) {
|
|
66
|
+
let cached = cache.get(pattern);
|
|
67
|
+
if (!cached) {
|
|
68
|
+
cached = new RegExp(pattern);
|
|
69
|
+
cache.set(pattern, cached);
|
|
70
|
+
}
|
|
71
|
+
return cached;
|
|
72
|
+
}
|
|
73
|
+
var defaultRegexCache = createRegexCache();
|
|
74
|
+
function getRegex(pattern) {
|
|
75
|
+
return getCachedRegex(defaultRegexCache, pattern);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { DEFAULT_VALIDATION_MESSAGES, createRegexCache, getCachedRegex, getRegex };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createUserValidator(attr, messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
const uuidSchema = zod.z.uuid({
|
|
8
|
+
message: messages.invalidId(attr)
|
|
9
|
+
});
|
|
10
|
+
if (attr.multiple) {
|
|
11
|
+
return zod.z.array(uuidSchema);
|
|
12
|
+
}
|
|
13
|
+
return uuidSchema;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.createUserValidator = createUserValidator;
|
package/dist/chunk-E6XO2STS.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils.ts
|
|
2
4
|
function asTenantId(id) {
|
|
3
5
|
return id;
|
|
4
6
|
}
|
|
@@ -49,13 +51,11 @@ function deepEqual(a, b) {
|
|
|
49
51
|
return false;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
exports.asTenantId = asTenantId; exports.asUserId = asUserId; exports.generateId = generateId; exports.generatePrefixedId = generatePrefixedId; exports.slugify = slugify; exports.generateTemplateName = generateTemplateName; exports.indexBy = indexBy; exports.deepEqual = deepEqual;
|
|
54
|
+
exports.asTenantId = asTenantId;
|
|
55
|
+
exports.asUserId = asUserId;
|
|
56
|
+
exports.deepEqual = deepEqual;
|
|
57
|
+
exports.generateId = generateId;
|
|
58
|
+
exports.generatePrefixedId = generatePrefixedId;
|
|
59
|
+
exports.generateTemplateName = generateTemplateName;
|
|
60
|
+
exports.indexBy = indexBy;
|
|
61
|
+
exports.slugify = slugify;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-BIQ35DLC.mjs';
|
|
2
|
+
import { getCountryByIso3, stripTrunkPrefix, isValidIso3 } from '@stndrds/constants';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { parsePhoneNumberFromString } from 'libphonenumber-js';
|
|
5
|
+
|
|
6
|
+
function digitsOnly(input) {
|
|
7
|
+
return input.replace(/\D/g, "");
|
|
8
|
+
}
|
|
9
|
+
function getIso2(iso3) {
|
|
10
|
+
const country = getCountryByIso3(iso3);
|
|
11
|
+
return country?.iso2;
|
|
12
|
+
}
|
|
13
|
+
function normalizePhoneNumber(phoneNumber, countryIso3) {
|
|
14
|
+
if (!phoneNumber) return "";
|
|
15
|
+
const iso2 = getIso2(countryIso3);
|
|
16
|
+
if (!iso2) {
|
|
17
|
+
return digitsOnly(phoneNumber);
|
|
18
|
+
}
|
|
19
|
+
const parsed = parsePhoneNumberFromString(phoneNumber, iso2);
|
|
20
|
+
if (parsed) {
|
|
21
|
+
return parsed.nationalNumber;
|
|
22
|
+
}
|
|
23
|
+
const country = getCountryByIso3(countryIso3);
|
|
24
|
+
const digits = digitsOnly(phoneNumber);
|
|
25
|
+
if (country) {
|
|
26
|
+
const callingCode = country.phoneCode.replace("+", "");
|
|
27
|
+
const withoutCC = digits.startsWith(callingCode) ? digits.slice(callingCode.length) : digits;
|
|
28
|
+
return stripTrunkPrefix(withoutCC, country.phoneTrunkPrefix ?? "");
|
|
29
|
+
}
|
|
30
|
+
return digits;
|
|
31
|
+
}
|
|
32
|
+
function validatePhoneNumber(phoneNumber, countryIso3) {
|
|
33
|
+
if (!phoneNumber) return false;
|
|
34
|
+
const iso2 = getIso2(countryIso3);
|
|
35
|
+
if (!iso2) return false;
|
|
36
|
+
const country = getCountryByIso3(countryIso3);
|
|
37
|
+
if (!country) return false;
|
|
38
|
+
const trunkPrefix = country.phoneTrunkPrefix ?? "";
|
|
39
|
+
const digits = digitsOnly(phoneNumber);
|
|
40
|
+
const withTrunk = trunkPrefix + digits;
|
|
41
|
+
const parsed = parsePhoneNumberFromString(withTrunk, iso2);
|
|
42
|
+
if (parsed?.isValid()) return true;
|
|
43
|
+
const parsedDirect = parsePhoneNumberFromString(phoneNumber, iso2);
|
|
44
|
+
if (parsedDirect?.isValid()) return true;
|
|
45
|
+
const maxDigits = country.phoneMaxDigits ?? 15;
|
|
46
|
+
const expectedWithoutTrunk = maxDigits - trunkPrefix.length;
|
|
47
|
+
return digits.length === expectedWithoutTrunk || digits.length === maxDigits;
|
|
48
|
+
}
|
|
49
|
+
function formatPhoneForDisplay(phone) {
|
|
50
|
+
if (!phone.phoneNumber) return "";
|
|
51
|
+
const iso2 = getIso2(phone.countryCode);
|
|
52
|
+
const country = getCountryByIso3(phone.countryCode);
|
|
53
|
+
const dial = country?.phoneCode ?? "";
|
|
54
|
+
if (!iso2) {
|
|
55
|
+
return `${dial} ${phone.phoneNumber}`.trim();
|
|
56
|
+
}
|
|
57
|
+
const e164 = `${dial}${digitsOnly(phone.phoneNumber)}`;
|
|
58
|
+
const parsed = parsePhoneNumberFromString(e164);
|
|
59
|
+
if (parsed) {
|
|
60
|
+
return parsed.formatInternational();
|
|
61
|
+
}
|
|
62
|
+
return `${dial} ${phone.phoneNumber}`.trim();
|
|
63
|
+
}
|
|
64
|
+
function parseRawPhoneInput(rawInput, countryIso3) {
|
|
65
|
+
if (!rawInput || rawInput.trim() === "") {
|
|
66
|
+
return { success: false, error: "Phone number is empty" };
|
|
67
|
+
}
|
|
68
|
+
const normalized = normalizePhoneNumber(rawInput, countryIso3);
|
|
69
|
+
if (!normalized) {
|
|
70
|
+
return { success: false, error: "Could not extract digits from input" };
|
|
71
|
+
}
|
|
72
|
+
if (!validatePhoneNumber(normalized, countryIso3)) {
|
|
73
|
+
return { success: false, error: "Invalid phone number for country" };
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
success: true,
|
|
77
|
+
phone: { countryCode: countryIso3, phoneNumber: normalized }
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/validation/complex/phone.ts
|
|
82
|
+
function createPhoneValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
83
|
+
return z.object(
|
|
84
|
+
{
|
|
85
|
+
countryCode: z.string().length(3),
|
|
86
|
+
phoneNumber: z.string().min(1)
|
|
87
|
+
},
|
|
88
|
+
{ message: messages.invalidPhone(attr) }
|
|
89
|
+
).refine((val) => isValidIso3(val.countryCode), {
|
|
90
|
+
message: "Invalid country code"
|
|
91
|
+
}).transform((val) => ({
|
|
92
|
+
countryCode: val.countryCode,
|
|
93
|
+
phoneNumber: normalizePhoneNumber(val.phoneNumber, val.countryCode)
|
|
94
|
+
})).refine((val) => validatePhoneNumber(val.phoneNumber, val.countryCode), {
|
|
95
|
+
message: messages.invalidPhone(attr)
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { createPhoneValidator, formatPhoneForDisplay, normalizePhoneNumber, parseRawPhoneInput, validatePhoneNumber };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkBEN6TE7Y_js = require('./chunk-BEN6TE7Y.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
var baseConfigSchema = zod.z.object({
|
|
7
|
+
disabled: zod.z.boolean().optional(),
|
|
8
|
+
placeholder: zod.z.string().optional(),
|
|
9
|
+
description: zod.z.string().optional(),
|
|
10
|
+
defaultValue: zod.z.unknown().optional(),
|
|
11
|
+
icon: zod.z.string().optional(),
|
|
12
|
+
order: zod.z.number().int().optional(),
|
|
13
|
+
hidden: zod.z.boolean().optional(),
|
|
14
|
+
archived: zod.z.boolean().optional(),
|
|
15
|
+
deprecated: zod.z.boolean().optional(),
|
|
16
|
+
metadata: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
|
|
17
|
+
});
|
|
18
|
+
var optionSchema = zod.z.object({
|
|
19
|
+
id: zod.z.string().min(1),
|
|
20
|
+
label: zod.z.string().min(1),
|
|
21
|
+
value: zod.z.string().min(1),
|
|
22
|
+
color: zod.z.string().optional(),
|
|
23
|
+
icon: zod.z.string().optional(),
|
|
24
|
+
description: zod.z.string().optional(),
|
|
25
|
+
group: zod.z.enum(["idle", "in_progress", "finished"]).optional(),
|
|
26
|
+
inverse: zod.z.string().optional()
|
|
27
|
+
});
|
|
28
|
+
var optionsArraySchema = zod.z.array(optionSchema).min(1).refine(
|
|
29
|
+
(options) => {
|
|
30
|
+
const values = options.map((o) => o.value);
|
|
31
|
+
return new Set(values).size === values.length;
|
|
32
|
+
},
|
|
33
|
+
{ message: "Duplicate option values are not allowed" }
|
|
34
|
+
);
|
|
35
|
+
var relationTargetSchema = zod.z.object({
|
|
36
|
+
object: zod.z.string().min(1),
|
|
37
|
+
displayTemplate: zod.z.string().optional(),
|
|
38
|
+
filter: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
|
|
39
|
+
});
|
|
40
|
+
var textConfigSchema = baseConfigSchema.extend({
|
|
41
|
+
minLength: zod.z.number().int().min(0).optional(),
|
|
42
|
+
maxLength: zod.z.number().int().min(1).optional(),
|
|
43
|
+
pattern: zod.z.string().optional()
|
|
44
|
+
});
|
|
45
|
+
var textareaConfigSchema = baseConfigSchema;
|
|
46
|
+
var richtextConfigSchema = baseConfigSchema.extend({
|
|
47
|
+
features: zod.z.array(
|
|
48
|
+
zod.z.enum(["headings", "bold", "italic", "lists", "links", "images", "codeBlocks", "tables"])
|
|
49
|
+
).optional()
|
|
50
|
+
});
|
|
51
|
+
var numberConfigSchema = baseConfigSchema.extend({
|
|
52
|
+
min: zod.z.number().optional(),
|
|
53
|
+
max: zod.z.number().optional(),
|
|
54
|
+
unit: zod.z.enum(["integer", "decimal", "percentage"]).optional(),
|
|
55
|
+
decimals: zod.z.number().int().min(0).optional()
|
|
56
|
+
});
|
|
57
|
+
var checkboxConfigSchema = baseConfigSchema;
|
|
58
|
+
var dateConfigSchema = baseConfigSchema.extend({
|
|
59
|
+
dateFormat: zod.z.enum(["short", "long", "full", "relative"]).optional(),
|
|
60
|
+
minDate: zod.z.string().optional(),
|
|
61
|
+
maxDate: zod.z.string().optional()
|
|
62
|
+
});
|
|
63
|
+
var phoneConfigSchema = baseConfigSchema.extend({
|
|
64
|
+
defaultCountryCode: zod.z.string().length(3).optional()
|
|
65
|
+
});
|
|
66
|
+
var currencyConfigSchema = baseConfigSchema.extend({
|
|
67
|
+
defaultCurrency: zod.z.string().length(3).optional(),
|
|
68
|
+
allowedCurrencies: zod.z.array(zod.z.string().length(3)).optional()
|
|
69
|
+
});
|
|
70
|
+
var statusConfigSchema = baseConfigSchema.extend({
|
|
71
|
+
options: optionsArraySchema
|
|
72
|
+
});
|
|
73
|
+
var locationConfigSchema = baseConfigSchema.extend({
|
|
74
|
+
granularity: zod.z.enum(["full", "address", "city", "state", "country", "coordinates"]),
|
|
75
|
+
enableAutocomplete: zod.z.boolean().optional(),
|
|
76
|
+
enableMap: zod.z.boolean().optional(),
|
|
77
|
+
defaultCountry: zod.z.string().length(3).optional(),
|
|
78
|
+
allowedCountries: zod.z.array(zod.z.string().length(3)).optional(),
|
|
79
|
+
displayFormat: zod.z.enum(["single_line", "multi_line", "compact"]).optional()
|
|
80
|
+
});
|
|
81
|
+
var selectConfigSchema = baseConfigSchema.extend({
|
|
82
|
+
options: optionsArraySchema
|
|
83
|
+
});
|
|
84
|
+
var multiselectConfigSchema = baseConfigSchema.extend({
|
|
85
|
+
options: optionsArraySchema
|
|
86
|
+
});
|
|
87
|
+
var fileConfigSchema = baseConfigSchema.extend({
|
|
88
|
+
maxFiles: zod.z.number().int().min(1).optional(),
|
|
89
|
+
maxSize: zod.z.number().int().min(1).optional(),
|
|
90
|
+
allowedTypes: zod.z.array(zod.z.string()).optional(),
|
|
91
|
+
multiple: zod.z.boolean().optional()
|
|
92
|
+
});
|
|
93
|
+
var userConfigSchema = baseConfigSchema.extend({
|
|
94
|
+
allowedRoles: zod.z.array(zod.z.string()).optional(),
|
|
95
|
+
multiple: zod.z.boolean().optional()
|
|
96
|
+
});
|
|
97
|
+
var relationConfigSchema = baseConfigSchema.extend({
|
|
98
|
+
targets: zod.z.array(relationTargetSchema).min(1),
|
|
99
|
+
cardinality: zod.z.enum(["one", "many"]),
|
|
100
|
+
minItems: zod.z.number().int().min(0).optional(),
|
|
101
|
+
maxItems: zod.z.number().int().min(1).optional()
|
|
102
|
+
});
|
|
103
|
+
var ratingConfigSchema = baseConfigSchema.extend({
|
|
104
|
+
max: zod.z.number().int().min(1).optional(),
|
|
105
|
+
iconType: zod.z.enum(["star", "heart", "thumbs", "number"]).optional()
|
|
106
|
+
});
|
|
107
|
+
var formulaConfigSchema = baseConfigSchema.extend({
|
|
108
|
+
expression: zod.z.string().min(1),
|
|
109
|
+
returnType: zod.z.enum(["text", "number", "boolean", "date"]),
|
|
110
|
+
decimals: zod.z.number().int().min(0).max(10).optional(),
|
|
111
|
+
allowRelations: zod.z.boolean().optional()
|
|
112
|
+
});
|
|
113
|
+
var rollupConfigSchema = baseConfigSchema.extend({
|
|
114
|
+
relationAttribute: zod.z.string().min(1).optional(),
|
|
115
|
+
relationPath: zod.z.string().optional(),
|
|
116
|
+
targetAttribute: zod.z.string().min(1),
|
|
117
|
+
function: zod.z.enum([
|
|
118
|
+
"sum",
|
|
119
|
+
"avg",
|
|
120
|
+
"earliest",
|
|
121
|
+
"latest",
|
|
122
|
+
"count",
|
|
123
|
+
"countValues",
|
|
124
|
+
"countUniqueValues",
|
|
125
|
+
"countEmpty",
|
|
126
|
+
"percentEmpty",
|
|
127
|
+
"percentNotEmpty",
|
|
128
|
+
"original"
|
|
129
|
+
]),
|
|
130
|
+
decimals: zod.z.number().int().min(0).max(10).optional(),
|
|
131
|
+
targetAttributeType: zod.z.string().optional(),
|
|
132
|
+
targetAttributeOptions: zod.z.array(
|
|
133
|
+
zod.z.object({
|
|
134
|
+
id: zod.z.string(),
|
|
135
|
+
label: zod.z.string(),
|
|
136
|
+
value: zod.z.string(),
|
|
137
|
+
color: zod.z.string().optional(),
|
|
138
|
+
icon: zod.z.string().optional(),
|
|
139
|
+
description: zod.z.string().optional(),
|
|
140
|
+
group: zod.z.enum(["idle", "in_progress", "finished"]).optional()
|
|
141
|
+
})
|
|
142
|
+
).optional()
|
|
143
|
+
});
|
|
144
|
+
var documentConfigSchema = baseConfigSchema.extend({
|
|
145
|
+
multiple: zod.z.boolean().optional(),
|
|
146
|
+
maxDocuments: zod.z.number().int().min(1).optional(),
|
|
147
|
+
autoProcess: zod.z.boolean().optional()
|
|
148
|
+
});
|
|
149
|
+
var attributeConfigSchemas = {
|
|
150
|
+
text: textConfigSchema,
|
|
151
|
+
textarea: textareaConfigSchema,
|
|
152
|
+
richtext: richtextConfigSchema,
|
|
153
|
+
number: numberConfigSchema,
|
|
154
|
+
checkbox: checkboxConfigSchema,
|
|
155
|
+
date: dateConfigSchema,
|
|
156
|
+
phone: phoneConfigSchema,
|
|
157
|
+
currency: currencyConfigSchema,
|
|
158
|
+
status: statusConfigSchema,
|
|
159
|
+
location: locationConfigSchema,
|
|
160
|
+
select: selectConfigSchema,
|
|
161
|
+
multiselect: multiselectConfigSchema,
|
|
162
|
+
file: fileConfigSchema,
|
|
163
|
+
user: userConfigSchema,
|
|
164
|
+
relation: relationConfigSchema,
|
|
165
|
+
rating: ratingConfigSchema,
|
|
166
|
+
formula: formulaConfigSchema,
|
|
167
|
+
rollup: rollupConfigSchema,
|
|
168
|
+
document: documentConfigSchema
|
|
169
|
+
};
|
|
170
|
+
function getAttributeConfigSchema(type) {
|
|
171
|
+
return attributeConfigSchemas[type];
|
|
172
|
+
}
|
|
173
|
+
function validateAttributeConfig(type, config) {
|
|
174
|
+
const schema = getAttributeConfigSchema(type);
|
|
175
|
+
const result = schema.safeParse(config);
|
|
176
|
+
if (result.success) {
|
|
177
|
+
return { success: true, data: result.data };
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
success: false,
|
|
181
|
+
errors: chunkBEN6TE7Y_js.formatZodErrors(result.error).map((err) => `${err.path.join(".")}: ${err.message}`)
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function parseAttributeConfig(type, config) {
|
|
185
|
+
const schema = getAttributeConfigSchema(type);
|
|
186
|
+
return schema.strip().parse(config);
|
|
187
|
+
}
|
|
188
|
+
function safeParseAttributeConfig(type, config) {
|
|
189
|
+
const schema = getAttributeConfigSchema(type);
|
|
190
|
+
const result = schema.strip().safeParse(config);
|
|
191
|
+
return result.success ? result.data : void 0;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
exports.attributeConfigSchemas = attributeConfigSchemas;
|
|
195
|
+
exports.checkboxConfigSchema = checkboxConfigSchema;
|
|
196
|
+
exports.currencyConfigSchema = currencyConfigSchema;
|
|
197
|
+
exports.dateConfigSchema = dateConfigSchema;
|
|
198
|
+
exports.documentConfigSchema = documentConfigSchema;
|
|
199
|
+
exports.fileConfigSchema = fileConfigSchema;
|
|
200
|
+
exports.formulaConfigSchema = formulaConfigSchema;
|
|
201
|
+
exports.getAttributeConfigSchema = getAttributeConfigSchema;
|
|
202
|
+
exports.locationConfigSchema = locationConfigSchema;
|
|
203
|
+
exports.multiselectConfigSchema = multiselectConfigSchema;
|
|
204
|
+
exports.numberConfigSchema = numberConfigSchema;
|
|
205
|
+
exports.parseAttributeConfig = parseAttributeConfig;
|
|
206
|
+
exports.phoneConfigSchema = phoneConfigSchema;
|
|
207
|
+
exports.ratingConfigSchema = ratingConfigSchema;
|
|
208
|
+
exports.relationConfigSchema = relationConfigSchema;
|
|
209
|
+
exports.richtextConfigSchema = richtextConfigSchema;
|
|
210
|
+
exports.rollupConfigSchema = rollupConfigSchema;
|
|
211
|
+
exports.safeParseAttributeConfig = safeParseAttributeConfig;
|
|
212
|
+
exports.selectConfigSchema = selectConfigSchema;
|
|
213
|
+
exports.statusConfigSchema = statusConfigSchema;
|
|
214
|
+
exports.textConfigSchema = textConfigSchema;
|
|
215
|
+
exports.textareaConfigSchema = textareaConfigSchema;
|
|
216
|
+
exports.userConfigSchema = userConfigSchema;
|
|
217
|
+
exports.validateAttributeConfig = validateAttributeConfig;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createFormulaValidator(_attr, _messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.unknown();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.createFormulaValidator = createFormulaValidator;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createSelectValidator(attr, messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
const validValues = attr.options.map((opt) => opt.value);
|
|
8
|
+
const validLabels = attr.options.map((opt) => opt.label);
|
|
9
|
+
return zod.z.enum(validValues, {
|
|
10
|
+
message: messages.invalidOption(attr, validLabels)
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function createMultiselectValidator(attr, messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
14
|
+
const validValues = attr.options.map((opt) => opt.value);
|
|
15
|
+
const validLabels = attr.options.map((opt) => opt.label);
|
|
16
|
+
return zod.z.array(
|
|
17
|
+
zod.z.enum(validValues, {
|
|
18
|
+
message: messages.invalidOption(attr, validLabels)
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
function createStatusValidator(attr, messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
23
|
+
const validValues = attr.options.map((opt) => opt.value);
|
|
24
|
+
const validLabels = attr.options.map((opt) => opt.label);
|
|
25
|
+
return zod.z.enum(validValues, {
|
|
26
|
+
message: messages.invalidOption(attr, validLabels)
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.createMultiselectValidator = createMultiselectValidator;
|
|
31
|
+
exports.createSelectValidator = createSelectValidator;
|
|
32
|
+
exports.createStatusValidator = createStatusValidator;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
var textRegexCache = chunkVCPYYLCS_js.createRegexCache();
|
|
7
|
+
function createTextValidator(attr, messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
8
|
+
let schema = zod.z.string();
|
|
9
|
+
if (attr.minLength !== void 0) {
|
|
10
|
+
schema = schema.min(attr.minLength, messages.minLength(attr, attr.minLength));
|
|
11
|
+
}
|
|
12
|
+
if (attr.maxLength !== void 0) {
|
|
13
|
+
schema = schema.max(attr.maxLength, messages.maxLength(attr, attr.maxLength));
|
|
14
|
+
}
|
|
15
|
+
if (attr.pattern) {
|
|
16
|
+
schema = schema.regex(
|
|
17
|
+
chunkVCPYYLCS_js.getCachedRegex(textRegexCache, attr.pattern),
|
|
18
|
+
messages.invalidPattern(attr)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return schema;
|
|
22
|
+
}
|
|
23
|
+
function createTextAreaValidator(_attr, _messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
24
|
+
return zod.z.string();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.createTextAreaValidator = createTextAreaValidator;
|
|
28
|
+
exports.createTextValidator = createTextValidator;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-BIQ35DLC.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createFileValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
const uuidSchema = z.uuid({
|
|
6
|
+
message: messages.invalidId(attr)
|
|
7
|
+
});
|
|
8
|
+
if (attr.multiple) {
|
|
9
|
+
let arraySchema = z.array(uuidSchema);
|
|
10
|
+
if (attr.maxFiles) {
|
|
11
|
+
arraySchema = arraySchema.max(attr.maxFiles, messages.maxItems(attr, attr.maxFiles));
|
|
12
|
+
}
|
|
13
|
+
return arraySchema;
|
|
14
|
+
}
|
|
15
|
+
return uuidSchema;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { createFileValidator };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVCPYYLCS_js = require('./chunk-VCPYYLCS.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createRatingValidator(attr, messages = chunkVCPYYLCS_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
let schema = zod.z.number().min(0);
|
|
8
|
+
if (attr.max !== void 0) {
|
|
9
|
+
schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
|
|
10
|
+
}
|
|
11
|
+
return schema;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.createRatingValidator = createRatingValidator;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-BIQ35DLC.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createNumberValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
let schema = z.number();
|
|
6
|
+
if (attr.min !== void 0) {
|
|
7
|
+
schema = schema.min(attr.min, messages.minValue(attr, attr.min));
|
|
8
|
+
}
|
|
9
|
+
if (attr.max !== void 0) {
|
|
10
|
+
schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
|
|
11
|
+
}
|
|
12
|
+
if (attr.unit === "integer") {
|
|
13
|
+
schema = schema.int(messages.mustBeInteger(attr));
|
|
14
|
+
}
|
|
15
|
+
return schema;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { createNumberValidator };
|