@stndrds/schema 0.1.0-alpha.67 → 1.0.0-alpha.102
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-D7yQuTJK.d.mts +665 -0
- package/dist/attributes-DcbQC-4b.d.ts +665 -0
- package/dist/chunk-3JINFUN3.js +81 -0
- package/dist/chunk-4KRLCWJM.mjs +8 -0
- package/dist/chunk-4TC27SMF.mjs +18 -0
- package/dist/chunk-56QI6UTK.js +32 -0
- package/dist/chunk-5JVVPJJW.mjs +208 -0
- package/dist/chunk-5XL3JP73.mjs +83 -0
- package/dist/chunk-7HFZ7MVR.mjs +28 -0
- package/dist/chunk-ACQ3TUFK.js +10 -0
- package/dist/chunk-AYCSVKI2.mjs +14 -0
- package/dist/chunk-BLXQGQLK.mjs +10 -0
- package/dist/chunk-D7WFIGXW.js +14 -0
- package/dist/chunk-FRCDMQER.js +47 -0
- package/dist/chunk-GCRHSPZN.js +16 -0
- package/dist/chunk-IRTRJH37.mjs +8 -0
- package/dist/chunk-ITTQ4FGR.mjs +14 -0
- package/dist/chunk-J5HRK3WD.js +10 -0
- package/dist/chunk-KNYZH2WD.mjs +18 -0
- package/dist/chunk-KWVCGQ7N.mjs +78 -0
- package/dist/chunk-MAKSIK3P.js +10 -0
- package/dist/chunk-N7T66JVY.js +86 -0
- package/dist/chunk-OAQWRMTP.js +10 -0
- package/dist/chunk-OLJLCVNY.mjs +8 -0
- package/dist/chunk-P2BE2A2G.js +64 -0
- package/dist/chunk-PGERPYDR.js +2 -0
- package/dist/chunk-QWZHR2OO.js +12 -0
- package/dist/chunk-QY6QFRRV.mjs +41 -0
- package/dist/chunk-QYNPB37W.js +221 -0
- package/dist/chunk-R4CJHCC4.mjs +60 -0
- package/dist/chunk-RJ4LOX7P.js +22 -0
- package/dist/chunk-ROAZLZA2.js +20 -0
- package/dist/chunk-RUYUFXNW.mjs +12 -0
- package/dist/chunk-SP3PNHYF.mjs +1 -0
- package/dist/chunk-SS2NR6DH.mjs +176 -0
- package/dist/chunk-T225DB55.js +33 -0
- package/dist/chunk-TKN73433.js +20 -0
- package/dist/chunk-TMYBEXBT.mjs +8 -0
- package/dist/chunk-UQVW4KPP.mjs +30 -0
- package/dist/chunk-V6DE3MXC.js +180 -0
- package/dist/chunk-VXOTYFEW.js +16 -0
- package/dist/chunk-WV4V64D5.mjs +20 -0
- package/dist/helpers-DD6JzYfI.d.mts +860 -0
- package/dist/helpers-kMS5R7KX.d.ts +860 -0
- package/dist/index.d.mts +3597 -1768
- package/dist/index.d.ts +3597 -1768
- package/dist/index.js +4957 -1955
- package/dist/index.mjs +3920 -1116
- package/dist/types-BAPgWlpX.d.mts +39 -0
- package/dist/types-mZPUEZl0.d.ts +39 -0
- package/dist/utils.d.mts +20 -55
- package/dist/utils.d.ts +20 -55
- package/dist/utils.js +26 -19
- package/dist/utils.mjs +1 -19
- package/dist/validation/all.d.mts +8 -0
- package/dist/validation/all.d.ts +8 -0
- package/dist/validation/all.js +56 -0
- package/dist/validation/all.mjs +19 -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 +11 -0
- package/dist/validation/complex/currency.mjs +2 -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 +11 -0
- package/dist/validation/complex/file.mjs +2 -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 +11 -0
- package/dist/validation/complex/location.mjs +2 -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 +11 -0
- package/dist/validation/complex/phone.mjs +2 -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 +19 -0
- package/dist/validation/complex/relation.mjs +2 -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 +11 -0
- package/dist/validation/complex/richtext.mjs +2 -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 +19 -0
- package/dist/validation/complex/select.mjs +2 -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 +11 -0
- package/dist/validation/complex/user.mjs +2 -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 +11 -0
- package/dist/validation/computed/formula.mjs +2 -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 +11 -0
- package/dist/validation/computed/rollup.mjs +2 -0
- package/dist/validation/config/index.d.mts +20 -0
- package/dist/validation/config/index.d.ts +20 -0
- package/dist/validation/config/index.js +18 -0
- package/dist/validation/config/index.mjs +1 -0
- package/dist/validation/core/index.d.mts +19 -0
- package/dist/validation/core/index.d.ts +19 -0
- package/dist/validation/core/index.js +14 -0
- package/dist/validation/core/index.mjs +1 -0
- package/dist/validation/object/index.d.mts +31 -0
- package/dist/validation/object/index.d.ts +31 -0
- package/dist/validation/object/index.js +70 -0
- package/dist/validation/object/index.mjs +17 -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 +11 -0
- package/dist/validation/primitives/checkbox.mjs +2 -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 +11 -0
- package/dist/validation/primitives/date.mjs +2 -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 +11 -0
- package/dist/validation/primitives/number.mjs +2 -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 +11 -0
- package/dist/validation/primitives/rating.mjs +2 -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 +15 -0
- package/dist/validation/primitives/text.mjs +2 -0
- package/package.json +108 -13
- package/dist/chunk-36UBIXJN.js +0 -82
- package/dist/chunk-3RG5ZIWI.js +0 -10
- package/dist/chunk-A6T4UUZ2.mjs +0 -18669
- package/dist/chunk-NEVERCM3.js +0 -41
- package/dist/chunk-SV4BCGQU.mjs +0 -617
- package/dist/chunk-TOTUS3YS.js +0 -18669
- package/dist/chunk-U4AB53AM.js +0 -617
- package/dist/chunk-V2RPPE2Y.mjs +0 -41
- package/dist/chunk-V5QXU2OK.mjs +0 -82
- package/dist/chunk-Y6FXYEAI.mjs +0 -10
- package/dist/default-roles-42X3TJI5.mjs +0 -21
- package/dist/default-roles-C3FYDYMN.js +0 -21
- package/dist/runtime-BgtwoMx5.d.ts +0 -12759
- package/dist/runtime-DQlTgVZJ.d.mts +0 -12759
- package/dist/runtime.d.mts +0 -6
- package/dist/runtime.d.ts +0 -6
- package/dist/runtime.js +0 -323
- package/dist/runtime.mjs +0 -323
- package/dist/validation/validators.d.mts +0 -4
- package/dist/validation/validators.d.ts +0 -4
- package/dist/validation/validators.js +0 -121
- package/dist/validation/validators.mjs +0 -121
- package/dist/validators-BROsLGn4.d.mts +0 -1556
- package/dist/validators-CEzdvxEq.d.ts +0 -1556
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-UQVW4KPP.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
// src/lib/lru-cache.ts
|
|
5
|
+
var LRUCache = class {
|
|
6
|
+
constructor(capacity) {
|
|
7
|
+
if (capacity <= 0) {
|
|
8
|
+
throw new Error("LRU cache capacity must be greater than 0");
|
|
9
|
+
}
|
|
10
|
+
this.capacity = capacity;
|
|
11
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
12
|
+
}
|
|
13
|
+
get(key) {
|
|
14
|
+
const value = this.cache.get(key);
|
|
15
|
+
if (value !== void 0) {
|
|
16
|
+
this.cache.delete(key);
|
|
17
|
+
this.cache.set(key, value);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
set(key, value) {
|
|
22
|
+
if (this.cache.has(key)) {
|
|
23
|
+
this.cache.delete(key);
|
|
24
|
+
} else if (this.cache.size >= this.capacity) {
|
|
25
|
+
const firstKey = this.cache.keys().next().value;
|
|
26
|
+
if (firstKey !== void 0) {
|
|
27
|
+
this.cache.delete(firstKey);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
this.cache.set(key, value);
|
|
31
|
+
}
|
|
32
|
+
has(key) {
|
|
33
|
+
return this.cache.has(key);
|
|
34
|
+
}
|
|
35
|
+
clear() {
|
|
36
|
+
this.cache.clear();
|
|
37
|
+
}
|
|
38
|
+
get size() {
|
|
39
|
+
return this.cache.size;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/validation/core/regex-cache.ts
|
|
44
|
+
function createRegexCache(capacity = 100) {
|
|
45
|
+
return new LRUCache(capacity);
|
|
46
|
+
}
|
|
47
|
+
function getCachedRegex(cache, pattern) {
|
|
48
|
+
let cached = cache.get(pattern);
|
|
49
|
+
if (!cached) {
|
|
50
|
+
cached = new RegExp(pattern);
|
|
51
|
+
cache.set(pattern, cached);
|
|
52
|
+
}
|
|
53
|
+
return cached;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/validation/primitives/text.ts
|
|
57
|
+
var textRegexCache = createRegexCache();
|
|
58
|
+
function createTextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
59
|
+
let schema = z.string();
|
|
60
|
+
if (attr.minLength !== void 0) {
|
|
61
|
+
schema = schema.min(attr.minLength, messages.minLength(attr, attr.minLength));
|
|
62
|
+
}
|
|
63
|
+
if (attr.maxLength !== void 0) {
|
|
64
|
+
schema = schema.max(attr.maxLength, messages.maxLength(attr, attr.maxLength));
|
|
65
|
+
}
|
|
66
|
+
if (attr.pattern) {
|
|
67
|
+
schema = schema.regex(
|
|
68
|
+
getCachedRegex(textRegexCache, attr.pattern),
|
|
69
|
+
messages.invalidPattern(attr)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return schema;
|
|
73
|
+
}
|
|
74
|
+
function createTextAreaValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
75
|
+
return z.string();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { createTextAreaValidator, createTextValidator };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkT225DB55_js = require('./chunk-T225DB55.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createCheckboxValidator(_attr, _messages = chunkT225DB55_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.boolean();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.createCheckboxValidator = createCheckboxValidator;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkT225DB55_js = require('./chunk-T225DB55.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 getIso2(iso3) {
|
|
12
|
+
const country = constants.getCountryByIso3(iso3);
|
|
13
|
+
return country?.iso2;
|
|
14
|
+
}
|
|
15
|
+
function normalizePhoneNumber(phoneNumber, countryIso3) {
|
|
16
|
+
if (!phoneNumber) return "";
|
|
17
|
+
const iso2 = getIso2(countryIso3);
|
|
18
|
+
if (!iso2) {
|
|
19
|
+
return digitsOnly(phoneNumber);
|
|
20
|
+
}
|
|
21
|
+
const parsed = libphonenumberJs.parsePhoneNumberFromString(phoneNumber, iso2);
|
|
22
|
+
if (parsed) {
|
|
23
|
+
return parsed.nationalNumber;
|
|
24
|
+
}
|
|
25
|
+
const country = constants.getCountryByIso3(countryIso3);
|
|
26
|
+
const digits = digitsOnly(phoneNumber);
|
|
27
|
+
if (country) {
|
|
28
|
+
const callingCode = country.phoneCode.replace("+", "");
|
|
29
|
+
const withoutCC = digits.startsWith(callingCode) ? digits.slice(callingCode.length) : digits;
|
|
30
|
+
return constants.stripTrunkPrefix(withoutCC, country.phoneTrunkPrefix ?? "");
|
|
31
|
+
}
|
|
32
|
+
return digits;
|
|
33
|
+
}
|
|
34
|
+
function validatePhoneNumber(phoneNumber, countryIso3) {
|
|
35
|
+
if (!phoneNumber) return false;
|
|
36
|
+
const iso2 = getIso2(countryIso3);
|
|
37
|
+
if (!iso2) return false;
|
|
38
|
+
const country = constants.getCountryByIso3(countryIso3);
|
|
39
|
+
if (!country) return false;
|
|
40
|
+
const trunkPrefix = country.phoneTrunkPrefix ?? "";
|
|
41
|
+
const digits = digitsOnly(phoneNumber);
|
|
42
|
+
const withTrunk = trunkPrefix + digits;
|
|
43
|
+
const parsed = libphonenumberJs.parsePhoneNumberFromString(withTrunk, iso2);
|
|
44
|
+
if (parsed?.isValid()) return true;
|
|
45
|
+
const parsedDirect = libphonenumberJs.parsePhoneNumberFromString(phoneNumber, iso2);
|
|
46
|
+
if (parsedDirect?.isValid()) return true;
|
|
47
|
+
const maxDigits = country.phoneMaxDigits ?? 15;
|
|
48
|
+
const expectedWithoutTrunk = maxDigits - trunkPrefix.length;
|
|
49
|
+
return digits.length === expectedWithoutTrunk || digits.length === maxDigits;
|
|
50
|
+
}
|
|
51
|
+
function formatPhoneForDisplay(phone) {
|
|
52
|
+
if (!phone.phoneNumber) return "";
|
|
53
|
+
const iso2 = getIso2(phone.countryCode);
|
|
54
|
+
const country = constants.getCountryByIso3(phone.countryCode);
|
|
55
|
+
const dial = country?.phoneCode ?? "";
|
|
56
|
+
if (!iso2) {
|
|
57
|
+
return `${dial} ${phone.phoneNumber}`.trim();
|
|
58
|
+
}
|
|
59
|
+
const e164 = `${dial}${digitsOnly(phone.phoneNumber)}`;
|
|
60
|
+
const parsed = libphonenumberJs.parsePhoneNumberFromString(e164);
|
|
61
|
+
if (parsed) {
|
|
62
|
+
return parsed.formatInternational();
|
|
63
|
+
}
|
|
64
|
+
return `${dial} ${phone.phoneNumber}`.trim();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/validation/complex/phone.ts
|
|
68
|
+
function createPhoneValidator(attr, messages = chunkT225DB55_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
69
|
+
return zod.z.object(
|
|
70
|
+
{
|
|
71
|
+
countryCode: zod.z.string().length(3),
|
|
72
|
+
phoneNumber: zod.z.string().min(1)
|
|
73
|
+
},
|
|
74
|
+
{ message: messages.invalidPhone(attr) }
|
|
75
|
+
).refine((val) => constants.isValidIso3(val.countryCode), {
|
|
76
|
+
message: "Invalid country code"
|
|
77
|
+
}).transform((val) => ({
|
|
78
|
+
countryCode: val.countryCode,
|
|
79
|
+
phoneNumber: normalizePhoneNumber(val.phoneNumber, val.countryCode)
|
|
80
|
+
})).refine((val) => validatePhoneNumber(val.phoneNumber, val.countryCode), {
|
|
81
|
+
message: messages.invalidPhone(attr)
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.createPhoneValidator = createPhoneValidator;
|
|
86
|
+
exports.formatPhoneForDisplay = formatPhoneForDisplay;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkT225DB55_js = require('./chunk-T225DB55.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createFormulaValidator(_attr, _messages = chunkT225DB55_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.unknown();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.createFormulaValidator = createFormulaValidator;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkT225DB55_js = require('./chunk-T225DB55.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function extractRelationId(item) {
|
|
7
|
+
if (typeof item === "object" && item !== null && "id" in item) {
|
|
8
|
+
return item.id;
|
|
9
|
+
}
|
|
10
|
+
return item;
|
|
11
|
+
}
|
|
12
|
+
function createSingleRelationValidator(attr, messages = chunkT225DB55_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
13
|
+
const uuidSchema = zod.z.uuid({
|
|
14
|
+
message: messages.invalidId(attr)
|
|
15
|
+
});
|
|
16
|
+
const nullableUuidSchema = zod.z.union([uuidSchema, zod.z.null()]);
|
|
17
|
+
return zod.z.union([
|
|
18
|
+
nullableUuidSchema,
|
|
19
|
+
zod.z.object({
|
|
20
|
+
id: uuidSchema,
|
|
21
|
+
props: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
|
|
22
|
+
}).passthrough()
|
|
23
|
+
// Allow additional properties (bilateral relations may have extra metadata)
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
function createMultiRelationValidator(attr, messages = chunkT225DB55_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
27
|
+
const uuidSchema = zod.z.uuid({
|
|
28
|
+
message: messages.invalidId(attr)
|
|
29
|
+
});
|
|
30
|
+
const itemSchema = zod.z.union([
|
|
31
|
+
uuidSchema,
|
|
32
|
+
zod.z.object({
|
|
33
|
+
id: uuidSchema,
|
|
34
|
+
props: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
|
|
35
|
+
}).passthrough()
|
|
36
|
+
// Allow additional properties
|
|
37
|
+
]);
|
|
38
|
+
let arraySchema = zod.z.array(itemSchema);
|
|
39
|
+
if (attr.minItems !== void 0) {
|
|
40
|
+
arraySchema = arraySchema.min(attr.minItems, messages.minItems(attr, attr.minItems));
|
|
41
|
+
}
|
|
42
|
+
if (attr.maxItems !== void 0) {
|
|
43
|
+
arraySchema = arraySchema.max(attr.maxItems, messages.maxItems(attr, attr.maxItems));
|
|
44
|
+
}
|
|
45
|
+
return arraySchema.refine(
|
|
46
|
+
(items) => {
|
|
47
|
+
return items.every((item) => {
|
|
48
|
+
const id = extractRelationId(item);
|
|
49
|
+
return typeof id === "string" && uuidSchema.safeParse(id).success;
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
{ message: messages.invalidId(attr) }
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function createRelationValidator(attr, messages = chunkT225DB55_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
56
|
+
if (attr.cardinality === "many") {
|
|
57
|
+
return createMultiRelationValidator(attr, messages);
|
|
58
|
+
}
|
|
59
|
+
return createSingleRelationValidator(attr, messages);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
exports.createMultiRelationValidator = createMultiRelationValidator;
|
|
63
|
+
exports.createRelationValidator = createRelationValidator;
|
|
64
|
+
exports.createSingleRelationValidator = createSingleRelationValidator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkT225DB55_js = require('./chunk-T225DB55.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createRichtextValidator(attr, messages = chunkT225DB55_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.string({
|
|
8
|
+
message: messages.invalidRichtext(attr)
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.createRichtextValidator = createRichtextValidator;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
function asTenantId(id) {
|
|
3
|
+
return id;
|
|
4
|
+
}
|
|
5
|
+
function asUserId(id) {
|
|
6
|
+
return id;
|
|
7
|
+
}
|
|
8
|
+
function generateId() {
|
|
9
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
10
|
+
return crypto.randomUUID();
|
|
11
|
+
}
|
|
12
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
13
|
+
const r = Math.random() * 16 | 0;
|
|
14
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
15
|
+
return v.toString(16);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function indexBy(items, keyFn) {
|
|
19
|
+
return new Map(items.map((item) => [keyFn(item), item]));
|
|
20
|
+
}
|
|
21
|
+
function deepEqual(a, b) {
|
|
22
|
+
if (a === b) return true;
|
|
23
|
+
if (a == null || b == null) return false;
|
|
24
|
+
if (typeof a !== typeof b) return false;
|
|
25
|
+
if (Array.isArray(a)) {
|
|
26
|
+
if (!Array.isArray(b)) return false;
|
|
27
|
+
if (a.length !== b.length) return false;
|
|
28
|
+
return a.every((item, index) => deepEqual(item, b[index]));
|
|
29
|
+
}
|
|
30
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
31
|
+
const aObj = a;
|
|
32
|
+
const bObj = b;
|
|
33
|
+
const aKeys = Object.keys(aObj);
|
|
34
|
+
const bKeys = Object.keys(bObj);
|
|
35
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
36
|
+
return aKeys.every((key) => key in bObj && deepEqual(aObj[key], bObj[key]));
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { asTenantId, asUserId, deepEqual, generateId, indexBy };
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkMAKSIK3P_js = require('./chunk-MAKSIK3P.js');
|
|
4
|
+
var chunkJ5HRK3WD_js = require('./chunk-J5HRK3WD.js');
|
|
5
|
+
var chunkTKN73433_js = require('./chunk-TKN73433.js');
|
|
6
|
+
var chunkD7WFIGXW_js = require('./chunk-D7WFIGXW.js');
|
|
7
|
+
var chunk3JINFUN3_js = require('./chunk-3JINFUN3.js');
|
|
8
|
+
var chunkQWZHR2OO_js = require('./chunk-QWZHR2OO.js');
|
|
9
|
+
var chunk56QI6UTK_js = require('./chunk-56QI6UTK.js');
|
|
10
|
+
var chunkVXOTYFEW_js = require('./chunk-VXOTYFEW.js');
|
|
11
|
+
var chunkOAQWRMTP_js = require('./chunk-OAQWRMTP.js');
|
|
12
|
+
var chunkACQ3TUFK_js = require('./chunk-ACQ3TUFK.js');
|
|
13
|
+
var chunkGCRHSPZN_js = require('./chunk-GCRHSPZN.js');
|
|
14
|
+
var chunkROAZLZA2_js = require('./chunk-ROAZLZA2.js');
|
|
15
|
+
var chunkRJ4LOX7P_js = require('./chunk-RJ4LOX7P.js');
|
|
16
|
+
var chunkN7T66JVY_js = require('./chunk-N7T66JVY.js');
|
|
17
|
+
var chunkP2BE2A2G_js = require('./chunk-P2BE2A2G.js');
|
|
18
|
+
var chunkT225DB55_js = require('./chunk-T225DB55.js');
|
|
19
|
+
var zod = require('zod');
|
|
20
|
+
|
|
21
|
+
function isEmptyValue(value) {
|
|
22
|
+
if (value === null || value === void 0) return true;
|
|
23
|
+
if (typeof value === "string" && value.trim() === "") return true;
|
|
24
|
+
if (value instanceof Date) return false;
|
|
25
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
26
|
+
return Object.values(value).every(
|
|
27
|
+
(v) => v === null || v === void 0 || typeof v === "string" && v.trim() === ""
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
function withEmptyToNull(validator) {
|
|
33
|
+
return zod.z.preprocess((val) => isEmptyValue(val) ? null : val, validator.nullish());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/validation/object/attribute-factory.ts
|
|
37
|
+
function createAttributeValidator(attr, messages = chunkT225DB55_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
38
|
+
switch (attr.type) {
|
|
39
|
+
case "text":
|
|
40
|
+
return chunk3JINFUN3_js.createTextValidator(attr, messages);
|
|
41
|
+
case "textarea":
|
|
42
|
+
return chunk3JINFUN3_js.createTextAreaValidator(attr, messages);
|
|
43
|
+
case "richtext":
|
|
44
|
+
return chunkQWZHR2OO_js.createRichtextValidator(attr, messages);
|
|
45
|
+
case "number":
|
|
46
|
+
return chunkTKN73433_js.createNumberValidator(attr, messages);
|
|
47
|
+
case "checkbox":
|
|
48
|
+
return chunkMAKSIK3P_js.createCheckboxValidator(attr, messages);
|
|
49
|
+
case "date":
|
|
50
|
+
return chunkJ5HRK3WD_js.createDateValidator(attr, messages);
|
|
51
|
+
case "phone":
|
|
52
|
+
return chunkN7T66JVY_js.createPhoneValidator(attr, messages);
|
|
53
|
+
case "currency":
|
|
54
|
+
return chunkGCRHSPZN_js.createCurrencyValidator(attr, messages);
|
|
55
|
+
case "status":
|
|
56
|
+
return chunk56QI6UTK_js.createStatusValidator(attr, messages);
|
|
57
|
+
case "location":
|
|
58
|
+
return chunkRJ4LOX7P_js.createLocationValidator(attr, messages);
|
|
59
|
+
case "select":
|
|
60
|
+
return chunk56QI6UTK_js.createSelectValidator(attr, messages);
|
|
61
|
+
case "multiselect":
|
|
62
|
+
return chunk56QI6UTK_js.createMultiselectValidator(attr, messages);
|
|
63
|
+
case "file":
|
|
64
|
+
return chunkROAZLZA2_js.createFileValidator(attr, messages);
|
|
65
|
+
case "user":
|
|
66
|
+
return chunkVXOTYFEW_js.createUserValidator(attr, messages);
|
|
67
|
+
case "relation":
|
|
68
|
+
return chunkP2BE2A2G_js.createRelationValidator(attr, messages);
|
|
69
|
+
case "rating":
|
|
70
|
+
return chunkD7WFIGXW_js.createRatingValidator(attr, messages);
|
|
71
|
+
case "formula":
|
|
72
|
+
return chunkOAQWRMTP_js.createFormulaValidator(attr, messages);
|
|
73
|
+
case "rollup":
|
|
74
|
+
return chunkACQ3TUFK_js.createRollupValidator(attr, messages);
|
|
75
|
+
default:
|
|
76
|
+
return zod.z.unknown();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function createFormAttributeValidator(attr, messages = chunkT225DB55_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
80
|
+
const validator = createAttributeValidator(attr, messages);
|
|
81
|
+
if (!attr.required) {
|
|
82
|
+
return withEmptyToNull(validator);
|
|
83
|
+
}
|
|
84
|
+
return validator;
|
|
85
|
+
}
|
|
86
|
+
var objectValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
87
|
+
var draftValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
88
|
+
function createObjectValidator(objectDef) {
|
|
89
|
+
const cached = objectValidatorCache.get(objectDef);
|
|
90
|
+
if (cached) return cached;
|
|
91
|
+
const shape = {};
|
|
92
|
+
for (const attr of objectDef.attributes) {
|
|
93
|
+
const validator = createAttributeValidator(attr);
|
|
94
|
+
shape[attr.name] = attr.required ? validator : withEmptyToNull(validator);
|
|
95
|
+
}
|
|
96
|
+
const schema = zod.z.object(shape).passthrough();
|
|
97
|
+
objectValidatorCache.set(objectDef, schema);
|
|
98
|
+
return schema;
|
|
99
|
+
}
|
|
100
|
+
function createDraftValidator(objectDef) {
|
|
101
|
+
const cached = draftValidatorCache.get(objectDef);
|
|
102
|
+
if (cached) return cached;
|
|
103
|
+
const shape = {};
|
|
104
|
+
for (const attr of objectDef.attributes) {
|
|
105
|
+
const validator = createAttributeValidator(attr);
|
|
106
|
+
shape[attr.name] = withEmptyToNull(validator);
|
|
107
|
+
}
|
|
108
|
+
const schema = zod.z.object(shape).passthrough();
|
|
109
|
+
draftValidatorCache.set(objectDef, schema);
|
|
110
|
+
return schema;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/validation/object/helpers.ts
|
|
114
|
+
function validateAttribute(attr, value) {
|
|
115
|
+
const validator = createAttributeValidator(attr);
|
|
116
|
+
if (!attr.required && (value === void 0 || value === null)) {
|
|
117
|
+
return { success: true, data: { [attr.name]: value } };
|
|
118
|
+
}
|
|
119
|
+
const result = validator.safeParse(value);
|
|
120
|
+
if (result.success) {
|
|
121
|
+
return {
|
|
122
|
+
success: true,
|
|
123
|
+
data: { [attr.name]: result.data }
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
success: false,
|
|
128
|
+
errors: chunkT225DB55_js.formatZodErrors(result.error).map((err) => ({
|
|
129
|
+
path: [attr.name, ...err.path],
|
|
130
|
+
message: err.message
|
|
131
|
+
}))
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function validateObject(objectDef, data) {
|
|
135
|
+
const validator = createObjectValidator(objectDef);
|
|
136
|
+
const result = validator.safeParse(data);
|
|
137
|
+
if (result.success) {
|
|
138
|
+
return {
|
|
139
|
+
success: true,
|
|
140
|
+
data: result.data
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
success: false,
|
|
145
|
+
errors: chunkT225DB55_js.formatZodErrors(result.error)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function validateObjectOrThrow(objectDef, data) {
|
|
149
|
+
const result = validateObject(objectDef, data);
|
|
150
|
+
if (!result.success) {
|
|
151
|
+
const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
152
|
+
throw new Error(`Validation failed for ${objectDef.label}:
|
|
153
|
+
${errorMessages}`);
|
|
154
|
+
}
|
|
155
|
+
return result.data;
|
|
156
|
+
}
|
|
157
|
+
function validateDraft(objectDef, data) {
|
|
158
|
+
const validator = createDraftValidator(objectDef);
|
|
159
|
+
const result = validator.safeParse(data);
|
|
160
|
+
if (result.success) {
|
|
161
|
+
return {
|
|
162
|
+
success: true,
|
|
163
|
+
data: result.data
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
success: false,
|
|
168
|
+
errors: chunkT225DB55_js.formatZodErrors(result.error)
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function validateDraftOrThrow(objectDef, data) {
|
|
172
|
+
const result = validateDraft(objectDef, data);
|
|
173
|
+
if (!result.success) {
|
|
174
|
+
const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
175
|
+
throw new Error(`Draft validation failed for ${objectDef.label}:
|
|
176
|
+
${errorMessages}`);
|
|
177
|
+
}
|
|
178
|
+
return result.data;
|
|
179
|
+
}
|
|
180
|
+
function isValuePresent(value) {
|
|
181
|
+
if (value === void 0 || value === null) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
function getMissingRequiredAttributes(objectDef, data) {
|
|
190
|
+
const missing = [];
|
|
191
|
+
for (const attr of objectDef.attributes) {
|
|
192
|
+
if (attr.required && !isValuePresent(data[attr.name])) {
|
|
193
|
+
missing.push(attr);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return missing;
|
|
197
|
+
}
|
|
198
|
+
function isRecordComplete(objectDef, data) {
|
|
199
|
+
const missing = getMissingRequiredAttributes(objectDef, data);
|
|
200
|
+
if (missing.length > 0) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
const validation = validateObject(objectDef, data);
|
|
204
|
+
return validation.success;
|
|
205
|
+
}
|
|
206
|
+
function computeRecordStatus(objectDef, data) {
|
|
207
|
+
return isRecordComplete(objectDef, data) ? "complete" : "draft";
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
exports.computeRecordStatus = computeRecordStatus;
|
|
211
|
+
exports.createAttributeValidator = createAttributeValidator;
|
|
212
|
+
exports.createDraftValidator = createDraftValidator;
|
|
213
|
+
exports.createFormAttributeValidator = createFormAttributeValidator;
|
|
214
|
+
exports.createObjectValidator = createObjectValidator;
|
|
215
|
+
exports.getMissingRequiredAttributes = getMissingRequiredAttributes;
|
|
216
|
+
exports.isRecordComplete = isRecordComplete;
|
|
217
|
+
exports.validateAttribute = validateAttribute;
|
|
218
|
+
exports.validateDraft = validateDraft;
|
|
219
|
+
exports.validateDraftOrThrow = validateDraftOrThrow;
|
|
220
|
+
exports.validateObject = validateObject;
|
|
221
|
+
exports.validateObjectOrThrow = validateObjectOrThrow;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-UQVW4KPP.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function extractRelationId(item) {
|
|
5
|
+
if (typeof item === "object" && item !== null && "id" in item) {
|
|
6
|
+
return item.id;
|
|
7
|
+
}
|
|
8
|
+
return item;
|
|
9
|
+
}
|
|
10
|
+
function createSingleRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
11
|
+
const uuidSchema = z.uuid({
|
|
12
|
+
message: messages.invalidId(attr)
|
|
13
|
+
});
|
|
14
|
+
const nullableUuidSchema = z.union([uuidSchema, z.null()]);
|
|
15
|
+
return z.union([
|
|
16
|
+
nullableUuidSchema,
|
|
17
|
+
z.object({
|
|
18
|
+
id: uuidSchema,
|
|
19
|
+
props: z.record(z.string(), z.unknown()).optional()
|
|
20
|
+
}).passthrough()
|
|
21
|
+
// Allow additional properties (bilateral relations may have extra metadata)
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
function createMultiRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
25
|
+
const uuidSchema = z.uuid({
|
|
26
|
+
message: messages.invalidId(attr)
|
|
27
|
+
});
|
|
28
|
+
const itemSchema = z.union([
|
|
29
|
+
uuidSchema,
|
|
30
|
+
z.object({
|
|
31
|
+
id: uuidSchema,
|
|
32
|
+
props: z.record(z.string(), z.unknown()).optional()
|
|
33
|
+
}).passthrough()
|
|
34
|
+
// Allow additional properties
|
|
35
|
+
]);
|
|
36
|
+
let arraySchema = z.array(itemSchema);
|
|
37
|
+
if (attr.minItems !== void 0) {
|
|
38
|
+
arraySchema = arraySchema.min(attr.minItems, messages.minItems(attr, attr.minItems));
|
|
39
|
+
}
|
|
40
|
+
if (attr.maxItems !== void 0) {
|
|
41
|
+
arraySchema = arraySchema.max(attr.maxItems, messages.maxItems(attr, attr.maxItems));
|
|
42
|
+
}
|
|
43
|
+
return arraySchema.refine(
|
|
44
|
+
(items) => {
|
|
45
|
+
return items.every((item) => {
|
|
46
|
+
const id = extractRelationId(item);
|
|
47
|
+
return typeof id === "string" && uuidSchema.safeParse(id).success;
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
{ message: messages.invalidId(attr) }
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
function createRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
54
|
+
if (attr.cardinality === "many") {
|
|
55
|
+
return createMultiRelationValidator(attr, messages);
|
|
56
|
+
}
|
|
57
|
+
return createSingleRelationValidator(attr, messages);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { createMultiRelationValidator, createRelationValidator, createSingleRelationValidator };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkT225DB55_js = require('./chunk-T225DB55.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createLocationValidator(attr, messages = chunkT225DB55_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.object(
|
|
8
|
+
{
|
|
9
|
+
address: zod.z.string().optional(),
|
|
10
|
+
address2: zod.z.string().optional(),
|
|
11
|
+
city: zod.z.string().optional(),
|
|
12
|
+
state: zod.z.string().optional(),
|
|
13
|
+
postalCode: zod.z.string().optional(),
|
|
14
|
+
country: zod.z.string().length(3).optional(),
|
|
15
|
+
latitude: zod.z.number().optional(),
|
|
16
|
+
longitude: zod.z.number().optional()
|
|
17
|
+
},
|
|
18
|
+
{ message: messages.invalidLocation(attr) }
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.createLocationValidator = createLocationValidator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkT225DB55_js = require('./chunk-T225DB55.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createFileValidator(attr, messages = chunkT225DB55_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
const uuidSchema = zod.z.uuid({
|
|
8
|
+
message: messages.invalidId(attr)
|
|
9
|
+
});
|
|
10
|
+
if (attr.multiple) {
|
|
11
|
+
let arraySchema = zod.z.array(uuidSchema);
|
|
12
|
+
if (attr.maxFiles) {
|
|
13
|
+
arraySchema = arraySchema.max(attr.maxFiles, messages.maxItems(attr, attr.maxFiles));
|
|
14
|
+
}
|
|
15
|
+
return arraySchema;
|
|
16
|
+
}
|
|
17
|
+
return uuidSchema;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.createFileValidator = createFileValidator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-UQVW4KPP.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createRatingValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
let schema = z.number().min(0);
|
|
6
|
+
if (attr.max !== void 0) {
|
|
7
|
+
schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
|
|
8
|
+
}
|
|
9
|
+
return schema;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { createRatingValidator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|