@stndrds/schema 0.1.0-alpha.66 → 1.0.0-alpha.100
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-CH89Z_J-.d.mts +675 -0
- package/dist/attributes-dw-jLtYS.d.ts +675 -0
- package/dist/chunk-2LUHLHLE.mjs +8 -0
- package/dist/chunk-3RFFA4EV.mjs +14 -0
- package/dist/chunk-4DMDOSFN.js +10 -0
- package/dist/chunk-4IVCBFJA.mjs +12 -0
- package/dist/chunk-5CBTJS7J.js +22 -0
- package/dist/chunk-5SQEKHPW.js +78 -0
- package/dist/chunk-6IFD5732.js +10 -0
- package/dist/chunk-6MXQAQBB.mjs +18 -0
- package/dist/chunk-7FSIBNRH.mjs +25 -0
- package/dist/chunk-ALV6GETG.mjs +10 -0
- package/dist/chunk-ANP6HGMJ.js +64 -0
- package/dist/chunk-ATA4XHB4.js +20 -0
- package/dist/chunk-BEN6TE7Y.js +11 -0
- package/dist/chunk-BZTLI773.mjs +8 -0
- package/dist/chunk-C7KW4NAD.js +20 -0
- package/dist/chunk-CE25ADK5.js +212 -0
- package/dist/chunk-E6XO2STS.js +61 -0
- package/dist/chunk-EKG35CSO.mjs +1 -0
- package/dist/chunk-ERG77ADK.mjs +18 -0
- package/dist/chunk-FKETRWAF.js +10 -0
- package/dist/chunk-FKPYFM6G.mjs +14 -0
- package/dist/chunk-H3VBSMVW.js +105 -0
- package/dist/chunk-HJNLL34O.js +12 -0
- package/dist/chunk-IMEPIVTR.js +217 -0
- package/dist/chunk-JEDANRCG.mjs +74 -0
- package/dist/chunk-KC2FFNL4.js +16 -0
- package/dist/chunk-OO2LJ6GP.js +32 -0
- package/dist/chunk-P4NGPF5L.mjs +99 -0
- package/dist/chunk-PGHTIMRD.mjs +199 -0
- package/dist/chunk-PZT3CIHD.mjs +192 -0
- package/dist/chunk-QPDXDX7A.js +16 -0
- package/dist/chunk-R6JFUC32.js +2 -0
- package/dist/chunk-RDGBQM3N.mjs +20 -0
- package/dist/chunk-RDXQ4CYT.mjs +9 -0
- package/dist/chunk-STKN6A5M.js +14 -0
- package/dist/chunk-TV4G2KMD.mjs +8 -0
- package/dist/chunk-UPEQEX2D.js +10 -0
- package/dist/chunk-VC4E3OSZ.mjs +8 -0
- package/dist/{chunk-V2RPPE2Y.mjs → chunk-XAORXFAX.mjs} +20 -9
- package/dist/chunk-XPFWKISJ.mjs +60 -0
- package/dist/chunk-ZJNX6UXB.mjs +28 -0
- package/dist/chunk-ZWMMEQI7.js +28 -0
- package/dist/index-CftmKoRP.d.mts +2053 -0
- package/dist/index-Dh_XiNFt.d.ts +2053 -0
- package/dist/index.d.mts +4406 -490
- package/dist/index.d.ts +4406 -490
- package/dist/index.js +6598 -1729
- package/dist/index.mjs +5260 -938
- package/dist/types-D-0QbsA9.d.ts +39 -0
- package/dist/types-Ms3HtAmo.d.mts +39 -0
- package/dist/utils.d.mts +20 -1
- package/dist/utils.d.ts +20 -1
- package/dist/utils.js +38 -19
- package/dist/utils.mjs +1 -19
- 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 +68 -0
- package/dist/validation/core/index.d.ts +68 -0
- package/dist/validation/core/index.js +23 -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 -121
- package/dist/validation/validators.mjs +20 -121
- package/package.json +109 -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-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/validators-BROsLGn4.d.mts +0 -1556
- package/dist/validators-CEzdvxEq.d.ts +0 -1556
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createCheckboxValidator(_attr, _messages = chunk5SQEKHPW_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.boolean();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.createCheckboxValidator = createCheckboxValidator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-JEDANRCG.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,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createLocationValidator(attr, messages = chunk5SQEKHPW_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,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/validation/core/messages.ts
|
|
4
|
+
var DEFAULT_VALIDATION_MESSAGES = {
|
|
5
|
+
required: (attr) => `${attr.label} is required`,
|
|
6
|
+
invalidType: (attr, expected) => `${attr.label} must be a ${expected}`,
|
|
7
|
+
minLength: (attr, min) => `${attr.label} must be at least ${min} characters`,
|
|
8
|
+
maxLength: (attr, max) => `${attr.label} must be at most ${max} characters`,
|
|
9
|
+
invalidPattern: (attr) => `${attr.label} format is invalid`,
|
|
10
|
+
minValue: (attr, min) => `${attr.label} must be at least ${min}`,
|
|
11
|
+
maxValue: (attr, max) => `${attr.label} must be at most ${max}`,
|
|
12
|
+
mustBeInteger: (attr) => `${attr.label} must be an integer`,
|
|
13
|
+
invalidDate: (attr) => `${attr.label} must be a valid date`,
|
|
14
|
+
invalidOption: (attr, options) => `${attr.label} must be one of: ${options.join(", ")}`,
|
|
15
|
+
invalidId: (attr) => `${attr.label} must be a valid ID`,
|
|
16
|
+
minItems: (attr, min) => `${attr.label} must have at least ${min} item${min > 1 ? "s" : ""}`,
|
|
17
|
+
maxItems: (attr, max) => `${attr.label} must have at most ${max} item${max > 1 ? "s" : ""}`,
|
|
18
|
+
invalidRichtext: (attr) => `${attr.label} must be valid rich text content`,
|
|
19
|
+
invalidPhone: (attr) => `${attr.label} must be a valid phone number`,
|
|
20
|
+
invalidCurrency: (attr) => `${attr.label} must be a valid currency value`,
|
|
21
|
+
invalidLocation: (attr) => `${attr.label} must be a valid location`
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/lib/lru-cache.ts
|
|
25
|
+
var LRUCache = class {
|
|
26
|
+
constructor(capacity) {
|
|
27
|
+
if (capacity <= 0) {
|
|
28
|
+
throw new Error("LRU cache capacity must be greater than 0");
|
|
29
|
+
}
|
|
30
|
+
this.capacity = capacity;
|
|
31
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
32
|
+
}
|
|
33
|
+
get(key) {
|
|
34
|
+
const value = this.cache.get(key);
|
|
35
|
+
if (value !== void 0) {
|
|
36
|
+
this.cache.delete(key);
|
|
37
|
+
this.cache.set(key, value);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
set(key, value) {
|
|
42
|
+
if (this.cache.has(key)) {
|
|
43
|
+
this.cache.delete(key);
|
|
44
|
+
} else if (this.cache.size >= this.capacity) {
|
|
45
|
+
const firstKey = this.cache.keys().next().value;
|
|
46
|
+
if (firstKey !== void 0) {
|
|
47
|
+
this.cache.delete(firstKey);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
this.cache.set(key, value);
|
|
51
|
+
}
|
|
52
|
+
has(key) {
|
|
53
|
+
return this.cache.has(key);
|
|
54
|
+
}
|
|
55
|
+
clear() {
|
|
56
|
+
this.cache.clear();
|
|
57
|
+
}
|
|
58
|
+
get size() {
|
|
59
|
+
return this.cache.size;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/validation/core/regex-cache.ts
|
|
64
|
+
function createRegexCache(capacity = 100) {
|
|
65
|
+
return new LRUCache(capacity);
|
|
66
|
+
}
|
|
67
|
+
function getCachedRegex(cache, pattern) {
|
|
68
|
+
let cached = cache.get(pattern);
|
|
69
|
+
if (!cached) {
|
|
70
|
+
cached = new RegExp(pattern);
|
|
71
|
+
cache.set(pattern, cached);
|
|
72
|
+
}
|
|
73
|
+
return cached;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
exports.DEFAULT_VALIDATION_MESSAGES = DEFAULT_VALIDATION_MESSAGES;
|
|
77
|
+
exports.createRegexCache = createRegexCache;
|
|
78
|
+
exports.getCachedRegex = getCachedRegex;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createRollupValidator(_attr, _messages = chunk5SQEKHPW_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.unknown();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.createRollupValidator = createRollupValidator;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-JEDANRCG.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 };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createRegexCache, DEFAULT_VALIDATION_MESSAGES, getCachedRegex } from './chunk-JEDANRCG.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
var textRegexCache = createRegexCache();
|
|
5
|
+
function createTextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
6
|
+
let schema = z.string();
|
|
7
|
+
if (attr.minLength !== void 0) {
|
|
8
|
+
schema = schema.min(attr.minLength, messages.minLength(attr, attr.minLength));
|
|
9
|
+
}
|
|
10
|
+
if (attr.maxLength !== void 0) {
|
|
11
|
+
schema = schema.max(attr.maxLength, messages.maxLength(attr, attr.maxLength));
|
|
12
|
+
}
|
|
13
|
+
if (attr.pattern) {
|
|
14
|
+
schema = schema.regex(
|
|
15
|
+
getCachedRegex(textRegexCache, attr.pattern),
|
|
16
|
+
messages.invalidPattern(attr)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return schema;
|
|
20
|
+
}
|
|
21
|
+
function createTextAreaValidator(_attr, _messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
22
|
+
return z.string();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { createTextAreaValidator, createTextValidator };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-JEDANRCG.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createRichtextValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
return z.string({
|
|
6
|
+
message: messages.invalidRichtext(attr)
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { createRichtextValidator };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.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 = chunk5SQEKHPW_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 = chunk5SQEKHPW_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 = chunk5SQEKHPW_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,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createNumberValidator(attr, messages = chunk5SQEKHPW_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
let schema = zod.z.number();
|
|
8
|
+
if (attr.min !== void 0) {
|
|
9
|
+
schema = schema.min(attr.min, messages.minValue(attr, attr.min));
|
|
10
|
+
}
|
|
11
|
+
if (attr.max !== void 0) {
|
|
12
|
+
schema = schema.max(attr.max, messages.maxValue(attr, attr.max));
|
|
13
|
+
}
|
|
14
|
+
if (attr.unit === "integer") {
|
|
15
|
+
schema = schema.int(messages.mustBeInteger(attr));
|
|
16
|
+
}
|
|
17
|
+
return schema;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.createNumberValidator = createNumberValidator;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-JEDANRCG.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createDateValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
return z.coerce.date({ message: messages.invalidDate(attr) });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { createDateValidator };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createFileValidator(attr, messages = chunk5SQEKHPW_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,212 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk4DMDOSFN_js = require('./chunk-4DMDOSFN.js');
|
|
4
|
+
var chunkFKETRWAF_js = require('./chunk-FKETRWAF.js');
|
|
5
|
+
var chunkATA4XHB4_js = require('./chunk-ATA4XHB4.js');
|
|
6
|
+
var chunkSTKN6A5M_js = require('./chunk-STKN6A5M.js');
|
|
7
|
+
var chunkZWMMEQI7_js = require('./chunk-ZWMMEQI7.js');
|
|
8
|
+
var chunkANP6HGMJ_js = require('./chunk-ANP6HGMJ.js');
|
|
9
|
+
var chunkHJNLL34O_js = require('./chunk-HJNLL34O.js');
|
|
10
|
+
var chunkOO2LJ6GP_js = require('./chunk-OO2LJ6GP.js');
|
|
11
|
+
var chunkKC2FFNL4_js = require('./chunk-KC2FFNL4.js');
|
|
12
|
+
var chunkUPEQEX2D_js = require('./chunk-UPEQEX2D.js');
|
|
13
|
+
var chunk6IFD5732_js = require('./chunk-6IFD5732.js');
|
|
14
|
+
var chunkQPDXDX7A_js = require('./chunk-QPDXDX7A.js');
|
|
15
|
+
var chunkC7KW4NAD_js = require('./chunk-C7KW4NAD.js');
|
|
16
|
+
var chunk5CBTJS7J_js = require('./chunk-5CBTJS7J.js');
|
|
17
|
+
var chunkH3VBSMVW_js = require('./chunk-H3VBSMVW.js');
|
|
18
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.js');
|
|
19
|
+
var chunkBEN6TE7Y_js = require('./chunk-BEN6TE7Y.js');
|
|
20
|
+
var zod = require('zod');
|
|
21
|
+
|
|
22
|
+
function isEmptyValue(value) {
|
|
23
|
+
if (value === null || value === void 0) return true;
|
|
24
|
+
if (typeof value === "string" && value.trim() === "") return true;
|
|
25
|
+
if (value instanceof Date) return false;
|
|
26
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
27
|
+
return Object.values(value).every(
|
|
28
|
+
(v) => v === null || v === void 0 || typeof v === "string" && v.trim() === ""
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
function withEmptyToNull(validator) {
|
|
34
|
+
return zod.z.preprocess((val) => isEmptyValue(val) ? null : val, validator.nullish());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/validation/object/attribute-factory.ts
|
|
38
|
+
function createAttributeValidator(attr, messages = chunk5SQEKHPW_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
39
|
+
switch (attr.type) {
|
|
40
|
+
case "text":
|
|
41
|
+
return chunkZWMMEQI7_js.createTextValidator(attr, messages);
|
|
42
|
+
case "textarea":
|
|
43
|
+
return chunkZWMMEQI7_js.createTextAreaValidator(attr, messages);
|
|
44
|
+
case "richtext":
|
|
45
|
+
return chunkHJNLL34O_js.createRichtextValidator(attr, messages);
|
|
46
|
+
case "number":
|
|
47
|
+
return chunkATA4XHB4_js.createNumberValidator(attr, messages);
|
|
48
|
+
case "checkbox":
|
|
49
|
+
return chunk4DMDOSFN_js.createCheckboxValidator(attr, messages);
|
|
50
|
+
case "date":
|
|
51
|
+
return chunkFKETRWAF_js.createDateValidator(attr, messages);
|
|
52
|
+
case "phone":
|
|
53
|
+
return chunkH3VBSMVW_js.createPhoneValidator(attr, messages);
|
|
54
|
+
case "currency":
|
|
55
|
+
return chunkQPDXDX7A_js.createCurrencyValidator(attr, messages);
|
|
56
|
+
case "status":
|
|
57
|
+
return chunkOO2LJ6GP_js.createStatusValidator(attr, messages);
|
|
58
|
+
case "location":
|
|
59
|
+
return chunk5CBTJS7J_js.createLocationValidator(attr, messages);
|
|
60
|
+
case "select":
|
|
61
|
+
return chunkOO2LJ6GP_js.createSelectValidator(attr, messages);
|
|
62
|
+
case "multiselect":
|
|
63
|
+
return chunkOO2LJ6GP_js.createMultiselectValidator(attr, messages);
|
|
64
|
+
case "file":
|
|
65
|
+
return chunkC7KW4NAD_js.createFileValidator(attr, messages);
|
|
66
|
+
case "user":
|
|
67
|
+
return chunkKC2FFNL4_js.createUserValidator(attr, messages);
|
|
68
|
+
case "relation":
|
|
69
|
+
return chunkANP6HGMJ_js.createRelationValidator(attr, messages);
|
|
70
|
+
case "rating":
|
|
71
|
+
return chunkSTKN6A5M_js.createRatingValidator(attr, messages);
|
|
72
|
+
case "formula":
|
|
73
|
+
return chunkUPEQEX2D_js.createFormulaValidator(attr, messages);
|
|
74
|
+
case "rollup":
|
|
75
|
+
return chunk6IFD5732_js.createRollupValidator(attr, messages);
|
|
76
|
+
default:
|
|
77
|
+
return zod.z.unknown();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function createFormAttributeValidator(attr, messages = chunk5SQEKHPW_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
81
|
+
const validator = createAttributeValidator(attr, messages);
|
|
82
|
+
if (!attr.required) {
|
|
83
|
+
return withEmptyToNull(validator);
|
|
84
|
+
}
|
|
85
|
+
return validator;
|
|
86
|
+
}
|
|
87
|
+
function createObjectValidator(objectDef) {
|
|
88
|
+
const shape = {};
|
|
89
|
+
for (const attr of objectDef.attributes) {
|
|
90
|
+
const validator = createAttributeValidator(attr);
|
|
91
|
+
shape[attr.name] = attr.required ? validator : withEmptyToNull(validator);
|
|
92
|
+
}
|
|
93
|
+
return zod.z.object(shape).passthrough();
|
|
94
|
+
}
|
|
95
|
+
function createDraftValidator(objectDef) {
|
|
96
|
+
const shape = {};
|
|
97
|
+
for (const attr of objectDef.attributes) {
|
|
98
|
+
const validator = createAttributeValidator(attr);
|
|
99
|
+
shape[attr.name] = withEmptyToNull(validator);
|
|
100
|
+
}
|
|
101
|
+
return zod.z.object(shape).passthrough();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/validation/object/helpers.ts
|
|
105
|
+
function validateAttribute(attr, value) {
|
|
106
|
+
const validator = createAttributeValidator(attr);
|
|
107
|
+
if (!attr.required && (value === void 0 || value === null)) {
|
|
108
|
+
return { success: true, data: { [attr.name]: value } };
|
|
109
|
+
}
|
|
110
|
+
const result = validator.safeParse(value);
|
|
111
|
+
if (result.success) {
|
|
112
|
+
return {
|
|
113
|
+
success: true,
|
|
114
|
+
data: { [attr.name]: result.data }
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
success: false,
|
|
119
|
+
errors: chunkBEN6TE7Y_js.formatZodErrors(result.error).map((err) => ({
|
|
120
|
+
path: [attr.name, ...err.path],
|
|
121
|
+
message: err.message
|
|
122
|
+
}))
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function validateObject(objectDef, data) {
|
|
126
|
+
const validator = createObjectValidator(objectDef);
|
|
127
|
+
const result = validator.safeParse(data);
|
|
128
|
+
if (result.success) {
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
data: result.data
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
success: false,
|
|
136
|
+
errors: chunkBEN6TE7Y_js.formatZodErrors(result.error)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function validateObjectOrThrow(objectDef, data) {
|
|
140
|
+
const result = validateObject(objectDef, data);
|
|
141
|
+
if (!result.success) {
|
|
142
|
+
const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
143
|
+
throw new Error(`Validation failed for ${objectDef.label}:
|
|
144
|
+
${errorMessages}`);
|
|
145
|
+
}
|
|
146
|
+
return result.data;
|
|
147
|
+
}
|
|
148
|
+
function validateDraft(objectDef, data) {
|
|
149
|
+
const validator = createDraftValidator(objectDef);
|
|
150
|
+
const result = validator.safeParse(data);
|
|
151
|
+
if (result.success) {
|
|
152
|
+
return {
|
|
153
|
+
success: true,
|
|
154
|
+
data: result.data
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
success: false,
|
|
159
|
+
errors: chunkBEN6TE7Y_js.formatZodErrors(result.error)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function validateDraftOrThrow(objectDef, data) {
|
|
163
|
+
const result = validateDraft(objectDef, data);
|
|
164
|
+
if (!result.success) {
|
|
165
|
+
const errorMessages = result.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
166
|
+
throw new Error(`Draft validation failed for ${objectDef.label}:
|
|
167
|
+
${errorMessages}`);
|
|
168
|
+
}
|
|
169
|
+
return result.data;
|
|
170
|
+
}
|
|
171
|
+
function isValuePresent(value) {
|
|
172
|
+
if (value === void 0 || value === null) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
function getMissingRequiredAttributes(objectDef, data) {
|
|
181
|
+
const missing = [];
|
|
182
|
+
for (const attr of objectDef.attributes) {
|
|
183
|
+
if (attr.required && !isValuePresent(data[attr.name])) {
|
|
184
|
+
missing.push(attr);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return missing;
|
|
188
|
+
}
|
|
189
|
+
function isRecordComplete(objectDef, data) {
|
|
190
|
+
const missing = getMissingRequiredAttributes(objectDef, data);
|
|
191
|
+
if (missing.length > 0) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
const validation = validateObject(objectDef, data);
|
|
195
|
+
return validation.success;
|
|
196
|
+
}
|
|
197
|
+
function computeRecordStatus(objectDef, data) {
|
|
198
|
+
return isRecordComplete(objectDef, data) ? "complete" : "draft";
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
exports.computeRecordStatus = computeRecordStatus;
|
|
202
|
+
exports.createAttributeValidator = createAttributeValidator;
|
|
203
|
+
exports.createDraftValidator = createDraftValidator;
|
|
204
|
+
exports.createFormAttributeValidator = createFormAttributeValidator;
|
|
205
|
+
exports.createObjectValidator = createObjectValidator;
|
|
206
|
+
exports.getMissingRequiredAttributes = getMissingRequiredAttributes;
|
|
207
|
+
exports.isRecordComplete = isRecordComplete;
|
|
208
|
+
exports.validateAttribute = validateAttribute;
|
|
209
|
+
exports.validateDraft = validateDraft;
|
|
210
|
+
exports.validateDraftOrThrow = validateDraftOrThrow;
|
|
211
|
+
exports.validateObject = validateObject;
|
|
212
|
+
exports.validateObjectOrThrow = validateObjectOrThrow;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils.ts
|
|
4
|
+
function asTenantId(id) {
|
|
5
|
+
return id;
|
|
6
|
+
}
|
|
7
|
+
function asUserId(id) {
|
|
8
|
+
return id;
|
|
9
|
+
}
|
|
10
|
+
function generateId() {
|
|
11
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
12
|
+
return crypto.randomUUID();
|
|
13
|
+
}
|
|
14
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
15
|
+
const r = Math.random() * 16 | 0;
|
|
16
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
17
|
+
return v.toString(16);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function generatePrefixedId(prefix) {
|
|
21
|
+
return `${prefix}_${generateId()}`;
|
|
22
|
+
}
|
|
23
|
+
function slugify(input) {
|
|
24
|
+
return input.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/[^a-z0-9\s_-]/g, "").trim().replace(/\s+/g, "-").replace(/-+/g, "-");
|
|
25
|
+
}
|
|
26
|
+
function generateTemplateName(label) {
|
|
27
|
+
const slug = slugify(label) || "template";
|
|
28
|
+
const suffix = generateId().slice(0, 8);
|
|
29
|
+
return `${slug}-${suffix}`;
|
|
30
|
+
}
|
|
31
|
+
function indexBy(items, keyFn) {
|
|
32
|
+
return new Map(items.map((item) => [keyFn(item), item]));
|
|
33
|
+
}
|
|
34
|
+
function deepEqual(a, b) {
|
|
35
|
+
if (a === b) return true;
|
|
36
|
+
if (a == null || b == null) return false;
|
|
37
|
+
if (typeof a !== typeof b) return false;
|
|
38
|
+
if (Array.isArray(a)) {
|
|
39
|
+
if (!Array.isArray(b)) return false;
|
|
40
|
+
if (a.length !== b.length) return false;
|
|
41
|
+
return a.every((item, index) => deepEqual(item, b[index]));
|
|
42
|
+
}
|
|
43
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
44
|
+
const aObj = a;
|
|
45
|
+
const bObj = b;
|
|
46
|
+
const aKeys = Object.keys(aObj);
|
|
47
|
+
const bKeys = Object.keys(bObj);
|
|
48
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
49
|
+
return aKeys.every((key) => key in bObj && deepEqual(aObj[key], bObj[key]));
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
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 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-JEDANRCG.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,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5SQEKHPW_js = require('./chunk-5SQEKHPW.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function createDateValidator(attr, messages = chunk5SQEKHPW_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
+
return zod.z.coerce.date({ message: messages.invalidDate(attr) });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.createDateValidator = createDateValidator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-JEDANRCG.mjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
function createCurrencyValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
5
|
+
return z.object(
|
|
6
|
+
{
|
|
7
|
+
code: z.string().length(3),
|
|
8
|
+
value: z.number().min(0)
|
|
9
|
+
},
|
|
10
|
+
{ message: messages.invalidCurrency(attr) }
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { createCurrencyValidator };
|