@stndrds/schema 1.0.0-alpha.294 → 1.0.0-alpha.68
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/chunk-36UBIXJN.js +82 -0
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/chunk-IXHWBBIY.mjs +721 -0
- package/dist/chunk-KG75T7MA.mjs +18664 -0
- package/dist/chunk-NEVERCM3.js +41 -0
- package/dist/chunk-V2RPPE2Y.mjs +41 -0
- package/dist/chunk-V32FQLWX.js +721 -0
- package/dist/chunk-V5QXU2OK.mjs +82 -0
- package/dist/chunk-XGFBT4K2.js +18664 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/default-roles-42X3TJI5.mjs +21 -0
- package/dist/default-roles-C3FYDYMN.js +21 -0
- package/dist/index.d.mts +3392 -10868
- package/dist/index.d.ts +3392 -10868
- package/dist/index.js +1705 -10256
- package/dist/index.mjs +1735 -9398
- package/dist/runtime-B0G6eBXO.d.ts +12810 -0
- package/dist/runtime-fj4EKCWH.d.mts +12810 -0
- package/dist/runtime.d.mts +6 -0
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +323 -0
- package/dist/runtime.mjs +323 -0
- package/dist/utils.d.mts +55 -35
- package/dist/utils.d.ts +55 -35
- package/dist/utils.js +19 -31
- package/dist/utils.mjs +19 -2
- package/dist/validation/validators.d.mts +4 -0
- package/dist/validation/validators.d.ts +4 -0
- package/dist/validation/validators.js +121 -0
- package/dist/validation/validators.mjs +121 -0
- package/dist/validators-B6L_hVBw.d.ts +1564 -0
- package/dist/validators-CgiGGhyH.d.mts +1564 -0
- package/package.json +16 -106
- package/dist/all-CDJSpI46.d.ts +0 -978
- package/dist/all-Cru_CaSY.d.mts +0 -978
- package/dist/attributes-CNYwg_Nr.d.ts +0 -584
- package/dist/attributes-CWPLbp7c.d.mts +0 -584
- package/dist/capabilities.d.mts +0 -146
- package/dist/capabilities.d.ts +0 -146
- package/dist/capabilities.js +0 -77
- package/dist/capabilities.mjs +0 -70
- package/dist/chunk-2WWGHULM.mjs +0 -226
- package/dist/chunk-4KMUATDG.js +0 -609
- package/dist/chunk-5WATIVCA.js +0 -10
- package/dist/chunk-ACKMC6FL.js +0 -17
- package/dist/chunk-AYVHMVKQ.mjs +0 -15
- package/dist/chunk-CLZORRMS.mjs +0 -570
- package/dist/chunk-DVXGSTWJ.js +0 -81
- package/dist/chunk-E6JUYGJX.js +0 -22
- package/dist/chunk-EEH4XQ7W.js +0 -61
- package/dist/chunk-EW5XR2X3.js +0 -12
- package/dist/chunk-GO6LQADH.mjs +0 -57
- package/dist/chunk-HRQEZUAA.mjs +0 -29
- package/dist/chunk-HTSTPTNZ.js +0 -10
- package/dist/chunk-HURC6CW3.js +0 -241
- package/dist/chunk-JZNR4HKQ.mjs +0 -1432
- package/dist/chunk-KAWYU7TE.js +0 -657
- package/dist/chunk-KNGWHQLR.js +0 -16
- package/dist/chunk-LV3FEUKU.mjs +0 -14
- package/dist/chunk-NS63SPNN.mjs +0 -8
- package/dist/chunk-O73ROMWQ.mjs +0 -85
- package/dist/chunk-OSSGN43B.mjs +0 -8
- package/dist/chunk-Q44QKLN4.mjs +0 -43
- package/dist/chunk-Q4SZAMJT.js +0 -72
- package/dist/chunk-QT35SI3K.mjs +0 -641
- package/dist/chunk-QVLQPW3O.mjs +0 -10
- package/dist/chunk-QWKLQRBX.js +0 -35
- package/dist/chunk-R2DAEDRF.mjs +0 -74
- package/dist/chunk-R5LAJCBU.mjs +0 -67
- package/dist/chunk-SI34M4IC.js +0 -45
- package/dist/chunk-T5PM73EF.js +0 -1504
- package/dist/chunk-UANQJ2GH.mjs +0 -25
- package/dist/chunk-UXAHLSWC.mjs +0 -8
- package/dist/chunk-V2UA2D4E.js +0 -10
- package/dist/chunk-YIP5FJ5H.js +0 -27
- package/dist/chunk-YKWSHBT5.js +0 -32
- package/dist/chunk-YUFTHPOE.mjs +0 -20
- package/dist/chunk-ZDQ5AP26.mjs +0 -31
- package/dist/chunk-ZPFOKBIN.js +0 -89
- package/dist/exceptions.d.mts +0 -511
- package/dist/exceptions.d.ts +0 -511
- package/dist/exceptions.js +0 -158
- package/dist/exceptions.mjs +0 -1
- package/dist/helpers-CXkVwpsl.d.ts +0 -76
- package/dist/helpers-Dul_r9rJ.d.mts +0 -76
- package/dist/index-BdVnHL3F.d.mts +0 -853
- package/dist/index-CFhPHQaI.d.ts +0 -853
- package/dist/migrations-DaFneOfx.d.ts +0 -39
- package/dist/migrations-fRvadl6i.d.mts +0 -39
- package/dist/objects-CDwMSnqv.d.mts +0 -250
- package/dist/objects-DJv6WrDE.d.ts +0 -250
- package/dist/types-CVYiFc69.d.mts +0 -38
- package/dist/types-NGEww_ln.d.ts +0 -38
- package/dist/validation/all.d.mts +0 -11
- package/dist/validation/all.d.ts +0 -11
- package/dist/validation/all.js +0 -131
- package/dist/validation/all.mjs +0 -18
- package/dist/validation/complex/currency.d.mts +0 -15
- package/dist/validation/complex/currency.d.ts +0 -15
- package/dist/validation/complex/currency.js +0 -11
- package/dist/validation/complex/currency.mjs +0 -2
- package/dist/validation/complex/location.d.mts +0 -22
- package/dist/validation/complex/location.d.ts +0 -22
- package/dist/validation/complex/location.js +0 -11
- package/dist/validation/complex/location.mjs +0 -2
- package/dist/validation/complex/phone.d.mts +0 -22
- package/dist/validation/complex/phone.d.ts +0 -22
- package/dist/validation/complex/phone.js +0 -11
- package/dist/validation/complex/phone.mjs +0 -2
- package/dist/validation/complex/relation.d.mts +0 -25
- package/dist/validation/complex/relation.d.ts +0 -25
- package/dist/validation/complex/relation.js +0 -19
- package/dist/validation/complex/relation.mjs +0 -2
- package/dist/validation/complex/richtext.d.mts +0 -13
- package/dist/validation/complex/richtext.d.ts +0 -13
- package/dist/validation/complex/richtext.js +0 -11
- package/dist/validation/complex/richtext.mjs +0 -2
- package/dist/validation/complex/select.d.mts +0 -20
- package/dist/validation/complex/select.d.ts +0 -20
- package/dist/validation/complex/select.js +0 -19
- package/dist/validation/complex/select.mjs +0 -2
- package/dist/validation/complex/user.d.mts +0 -13
- package/dist/validation/complex/user.d.ts +0 -13
- package/dist/validation/complex/user.js +0 -11
- package/dist/validation/complex/user.mjs +0 -2
- package/dist/validation/computed/formula.d.mts +0 -14
- package/dist/validation/computed/formula.d.ts +0 -14
- package/dist/validation/computed/formula.js +0 -11
- package/dist/validation/computed/formula.mjs +0 -2
- package/dist/validation/computed/rollup.d.mts +0 -14
- package/dist/validation/computed/rollup.d.ts +0 -14
- package/dist/validation/computed/rollup.js +0 -11
- package/dist/validation/computed/rollup.mjs +0 -2
- package/dist/validation/config/index.d.mts +0 -7
- package/dist/validation/config/index.d.ts +0 -7
- package/dist/validation/config/index.js +0 -52
- package/dist/validation/config/index.mjs +0 -7
- package/dist/validation/core/index.d.mts +0 -19
- package/dist/validation/core/index.d.ts +0 -19
- package/dist/validation/core/index.js +0 -14
- package/dist/validation/core/index.mjs +0 -1
- package/dist/validation/object/index.d.mts +0 -32
- package/dist/validation/object/index.d.ts +0 -32
- package/dist/validation/object/index.js +0 -69
- package/dist/validation/object/index.mjs +0 -16
- package/dist/validation/primitives/checkbox.d.mts +0 -12
- package/dist/validation/primitives/checkbox.d.ts +0 -12
- package/dist/validation/primitives/checkbox.js +0 -11
- package/dist/validation/primitives/checkbox.mjs +0 -2
- package/dist/validation/primitives/date.d.mts +0 -25
- package/dist/validation/primitives/date.d.ts +0 -25
- package/dist/validation/primitives/date.js +0 -11
- package/dist/validation/primitives/date.mjs +0 -2
- package/dist/validation/primitives/number.d.mts +0 -12
- package/dist/validation/primitives/number.d.ts +0 -12
- package/dist/validation/primitives/number.js +0 -11
- package/dist/validation/primitives/number.mjs +0 -2
- package/dist/validation/primitives/text.d.mts +0 -12
- package/dist/validation/primitives/text.d.ts +0 -12
- package/dist/validation/primitives/text.js +0 -11
- package/dist/validation/primitives/text.mjs +0 -2
package/dist/chunk-EEH4XQ7W.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkYKWSHBT5_js = require('./chunk-YKWSHBT5.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 = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
13
|
-
const uuidSchema = zod.z.guid({
|
|
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 = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
27
|
-
const uuidSchema = zod.z.guid({
|
|
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.maxItems !== void 0) {
|
|
40
|
-
arraySchema = arraySchema.max(attr.maxItems, messages.maxItems(attr, attr.maxItems));
|
|
41
|
-
}
|
|
42
|
-
return arraySchema.refine(
|
|
43
|
-
(items) => {
|
|
44
|
-
return items.every((item) => {
|
|
45
|
-
const id = extractRelationId(item);
|
|
46
|
-
return typeof id === "string" && uuidSchema.safeParse(id).success;
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
{ message: messages.invalidId(attr) }
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
function createRelationValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
53
|
-
if (attr.cardinality === "many") {
|
|
54
|
-
return createMultiRelationValidator(attr, messages);
|
|
55
|
-
}
|
|
56
|
-
return createSingleRelationValidator(attr, messages);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
exports.createMultiRelationValidator = createMultiRelationValidator;
|
|
60
|
-
exports.createRelationValidator = createRelationValidator;
|
|
61
|
-
exports.createSingleRelationValidator = createSingleRelationValidator;
|
package/dist/chunk-EW5XR2X3.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkYKWSHBT5_js = require('./chunk-YKWSHBT5.js');
|
|
4
|
-
var zod = require('zod');
|
|
5
|
-
|
|
6
|
-
function createRichtextValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
-
return zod.z.string({
|
|
8
|
-
message: messages.invalidRichtext(attr)
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
exports.createRichtextValidator = createRichtextValidator;
|
package/dist/chunk-GO6LQADH.mjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_VALIDATION_MESSAGES } from './chunk-HRQEZUAA.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.guid({
|
|
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.guid({
|
|
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.maxItems !== void 0) {
|
|
38
|
-
arraySchema = arraySchema.max(attr.maxItems, messages.maxItems(attr, attr.maxItems));
|
|
39
|
-
}
|
|
40
|
-
return arraySchema.refine(
|
|
41
|
-
(items) => {
|
|
42
|
-
return items.every((item) => {
|
|
43
|
-
const id = extractRelationId(item);
|
|
44
|
-
return typeof id === "string" && uuidSchema.safeParse(id).success;
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
{ message: messages.invalidId(attr) }
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
function createRelationValidator(attr, messages = DEFAULT_VALIDATION_MESSAGES) {
|
|
51
|
-
if (attr.cardinality === "many") {
|
|
52
|
-
return createMultiRelationValidator(attr, messages);
|
|
53
|
-
}
|
|
54
|
-
return createSingleRelationValidator(attr, messages);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { createMultiRelationValidator, createRelationValidator, createSingleRelationValidator };
|
package/dist/chunk-HRQEZUAA.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
maxItems: (attr, max) => `${attr.label} must have at most ${max} item${max > 1 ? "s" : ""}`,
|
|
15
|
-
invalidRichtext: (attr) => `${attr.label} must be valid rich text content`,
|
|
16
|
-
invalidPhone: (attr) => `${attr.label} must be a valid phone number`,
|
|
17
|
-
invalidCurrency: (attr) => `${attr.label} must be a valid currency value`,
|
|
18
|
-
invalidLocation: (attr) => `${attr.label} must be a valid location`
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// src/validation/core/errors.ts
|
|
22
|
-
function formatZodErrors(error) {
|
|
23
|
-
return error.issues.map((err) => ({
|
|
24
|
-
path: err.path.map(String),
|
|
25
|
-
message: err.message
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { DEFAULT_VALIDATION_MESSAGES, formatZodErrors };
|
package/dist/chunk-HTSTPTNZ.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkYKWSHBT5_js = require('./chunk-YKWSHBT5.js');
|
|
4
|
-
var zod = require('zod');
|
|
5
|
-
|
|
6
|
-
function createFormulaValidator(_attr, _messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
7
|
-
return zod.z.unknown();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
exports.createFormulaValidator = createFormulaValidator;
|
package/dist/chunk-HURC6CW3.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkEEH4XQ7W_js = require('./chunk-EEH4XQ7W.js');
|
|
4
|
-
var chunkEW5XR2X3_js = require('./chunk-EW5XR2X3.js');
|
|
5
|
-
var chunkQWKLQRBX_js = require('./chunk-QWKLQRBX.js');
|
|
6
|
-
var chunkKNGWHQLR_js = require('./chunk-KNGWHQLR.js');
|
|
7
|
-
var chunkHTSTPTNZ_js = require('./chunk-HTSTPTNZ.js');
|
|
8
|
-
var chunkV2UA2D4E_js = require('./chunk-V2UA2D4E.js');
|
|
9
|
-
var chunk5WATIVCA_js = require('./chunk-5WATIVCA.js');
|
|
10
|
-
var chunkSI34M4IC_js = require('./chunk-SI34M4IC.js');
|
|
11
|
-
var chunkYIP5FJ5H_js = require('./chunk-YIP5FJ5H.js');
|
|
12
|
-
var chunkZPFOKBIN_js = require('./chunk-ZPFOKBIN.js');
|
|
13
|
-
var chunk4KMUATDG_js = require('./chunk-4KMUATDG.js');
|
|
14
|
-
var chunkACKMC6FL_js = require('./chunk-ACKMC6FL.js');
|
|
15
|
-
var chunkE6JUYGJX_js = require('./chunk-E6JUYGJX.js');
|
|
16
|
-
var chunkQ4SZAMJT_js = require('./chunk-Q4SZAMJT.js');
|
|
17
|
-
var chunkYKWSHBT5_js = require('./chunk-YKWSHBT5.js');
|
|
18
|
-
var zod = require('zod');
|
|
19
|
-
|
|
20
|
-
function isEmptyValue(value) {
|
|
21
|
-
if (value === null || value === void 0) return true;
|
|
22
|
-
if (typeof value === "string" && value.trim() === "") return true;
|
|
23
|
-
if (value instanceof Date) return false;
|
|
24
|
-
if (typeof value === "object" && !Array.isArray(value)) {
|
|
25
|
-
return Object.values(value).every(
|
|
26
|
-
(v) => v === null || v === void 0 || typeof v === "string" && v.trim() === ""
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
function withEmptyToNull(validator) {
|
|
32
|
-
return zod.z.preprocess((val) => isEmptyValue(val) ? null : val, validator.nullish());
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/validation/object/attribute-factory.ts
|
|
36
|
-
function createAttributeValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
37
|
-
switch (attr.type) {
|
|
38
|
-
case "text":
|
|
39
|
-
return chunkZPFOKBIN_js.createTextValidator(attr, messages);
|
|
40
|
-
case "richtext":
|
|
41
|
-
return chunkEW5XR2X3_js.createRichtextValidator(attr, messages);
|
|
42
|
-
case "number":
|
|
43
|
-
return chunkYIP5FJ5H_js.createNumberValidator(attr, messages);
|
|
44
|
-
case "checkbox":
|
|
45
|
-
return chunk5WATIVCA_js.createCheckboxValidator(attr, messages);
|
|
46
|
-
case "date":
|
|
47
|
-
return chunkSI34M4IC_js.createDateValidator(attr, messages);
|
|
48
|
-
case "phone":
|
|
49
|
-
return chunkQ4SZAMJT_js.createPhoneValidator(attr, messages);
|
|
50
|
-
case "currency":
|
|
51
|
-
return chunkACKMC6FL_js.createCurrencyValidator(attr, messages);
|
|
52
|
-
case "status":
|
|
53
|
-
return chunkQWKLQRBX_js.createStatusValidator(attr, messages);
|
|
54
|
-
case "location":
|
|
55
|
-
return chunkE6JUYGJX_js.createLocationValidator(attr, messages);
|
|
56
|
-
case "select":
|
|
57
|
-
return chunkQWKLQRBX_js.createSelectValidator(attr, messages);
|
|
58
|
-
case "multiselect":
|
|
59
|
-
return chunkQWKLQRBX_js.createMultiselectValidator(attr, messages);
|
|
60
|
-
case "user":
|
|
61
|
-
return chunkKNGWHQLR_js.createUserValidator(attr, messages);
|
|
62
|
-
case "relation":
|
|
63
|
-
return chunkEEH4XQ7W_js.createRelationValidator(attr, messages);
|
|
64
|
-
case "formula":
|
|
65
|
-
return chunkHTSTPTNZ_js.createFormulaValidator(attr, messages);
|
|
66
|
-
case "rollup":
|
|
67
|
-
return chunkV2UA2D4E_js.createRollupValidator(attr, messages);
|
|
68
|
-
default:
|
|
69
|
-
return zod.z.unknown();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function createFormAttributeValidator(attr, messages = chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES) {
|
|
73
|
-
const validator = createAttributeValidator(attr, messages);
|
|
74
|
-
if (!attr.required) {
|
|
75
|
-
return withEmptyToNull(validator);
|
|
76
|
-
}
|
|
77
|
-
return validator;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// src/lib/empty.ts
|
|
81
|
-
function isNullishOrEmptyString(value) {
|
|
82
|
-
return value === null || value === void 0 || value === "";
|
|
83
|
-
}
|
|
84
|
-
function isValuePresent(value) {
|
|
85
|
-
if (value === null || value === void 0) return false;
|
|
86
|
-
if (typeof value === "string") return value.trim() !== "";
|
|
87
|
-
if (Array.isArray(value)) return value.length > 0;
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/validation/object/object-validator.ts
|
|
92
|
-
var objectValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
93
|
-
var draftValidatorCache = /* @__PURE__ */ new WeakMap();
|
|
94
|
-
function createObjectValidator(objectDef) {
|
|
95
|
-
const cached = objectValidatorCache.get(objectDef);
|
|
96
|
-
if (cached) return cached;
|
|
97
|
-
const shape = {};
|
|
98
|
-
for (const attr of objectDef.attributes) {
|
|
99
|
-
const validator = createAttributeValidator(attr);
|
|
100
|
-
if (attr.required) {
|
|
101
|
-
shape[attr.name] = validator.refine(isValuePresent, {
|
|
102
|
-
message: chunkYKWSHBT5_js.DEFAULT_VALIDATION_MESSAGES.required(attr)
|
|
103
|
-
});
|
|
104
|
-
} else {
|
|
105
|
-
shape[attr.name] = withEmptyToNull(validator);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const schema = zod.z.object(shape).passthrough();
|
|
109
|
-
objectValidatorCache.set(objectDef, schema);
|
|
110
|
-
return schema;
|
|
111
|
-
}
|
|
112
|
-
function createDraftValidator(objectDef) {
|
|
113
|
-
const cached = draftValidatorCache.get(objectDef);
|
|
114
|
-
if (cached) return cached;
|
|
115
|
-
const shape = {};
|
|
116
|
-
for (const attr of objectDef.attributes) {
|
|
117
|
-
const validator = createAttributeValidator(attr);
|
|
118
|
-
shape[attr.name] = withEmptyToNull(validator);
|
|
119
|
-
}
|
|
120
|
-
const schema = zod.z.object(shape).passthrough();
|
|
121
|
-
draftValidatorCache.set(objectDef, schema);
|
|
122
|
-
return schema;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// src/validation/object/helpers.ts
|
|
126
|
-
function validateAttribute(attr, value) {
|
|
127
|
-
const validator = createAttributeValidator(attr);
|
|
128
|
-
if (!attr.required && (value === void 0 || value === null)) {
|
|
129
|
-
return { success: true, data: { [attr.name]: value } };
|
|
130
|
-
}
|
|
131
|
-
const result = validator.safeParse(value);
|
|
132
|
-
if (result.success) {
|
|
133
|
-
return {
|
|
134
|
-
success: true,
|
|
135
|
-
data: { [attr.name]: result.data }
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
success: false,
|
|
140
|
-
errors: chunkYKWSHBT5_js.formatZodErrors(result.error).map((err) => ({
|
|
141
|
-
path: [attr.name, ...err.path],
|
|
142
|
-
message: err.message
|
|
143
|
-
}))
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function validateObject(objectDef, data) {
|
|
147
|
-
const validator = createObjectValidator(objectDef);
|
|
148
|
-
const result = validator.safeParse(data);
|
|
149
|
-
if (result.success) {
|
|
150
|
-
return {
|
|
151
|
-
success: true,
|
|
152
|
-
data: result.data
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
success: false,
|
|
157
|
-
errors: chunkYKWSHBT5_js.formatZodErrors(result.error)
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
function validateObjectOrThrow(objectDef, data) {
|
|
161
|
-
const result = validateObject(objectDef, data);
|
|
162
|
-
if (!result.success) {
|
|
163
|
-
const errors = result.errors ?? [];
|
|
164
|
-
const detail = errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
165
|
-
throw new chunk4KMUATDG_js.ValidationError(
|
|
166
|
-
`Validation failed for ${objectDef.label}:
|
|
167
|
-
${detail}`,
|
|
168
|
-
errors.map((err) => ({ path: err.path, message: err.message }))
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
return result.data;
|
|
172
|
-
}
|
|
173
|
-
function validateDraft(objectDef, data) {
|
|
174
|
-
const validator = createDraftValidator(objectDef);
|
|
175
|
-
const result = validator.safeParse(data);
|
|
176
|
-
if (result.success) {
|
|
177
|
-
return {
|
|
178
|
-
success: true,
|
|
179
|
-
data: result.data
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
return {
|
|
183
|
-
success: false,
|
|
184
|
-
errors: chunkYKWSHBT5_js.formatZodErrors(result.error)
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
function validateDraftOrThrow(objectDef, data) {
|
|
188
|
-
const result = validateDraft(objectDef, data);
|
|
189
|
-
if (!result.success) {
|
|
190
|
-
const errors = result.errors ?? [];
|
|
191
|
-
const detail = errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("\n") || "Unknown validation error";
|
|
192
|
-
throw new chunk4KMUATDG_js.ValidationError(
|
|
193
|
-
`Draft validation failed for ${objectDef.label}:
|
|
194
|
-
${detail}`,
|
|
195
|
-
errors.map((err) => ({ path: err.path, message: err.message }))
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
return result.data;
|
|
199
|
-
}
|
|
200
|
-
function rejectUnknownAttributesOrThrow(objectDef, data) {
|
|
201
|
-
const knownNames = new Set(objectDef.attributes.map((a) => a.name));
|
|
202
|
-
const unknownKeys = Object.keys(data).filter((key) => !knownNames.has(key));
|
|
203
|
-
if (unknownKeys.length > 0) {
|
|
204
|
-
throw new chunk4KMUATDG_js.ValidationError(
|
|
205
|
-
`Unknown attribute${unknownKeys.length > 1 ? "s" : ""} for ${objectDef.label}: ${unknownKeys.join(", ")}`,
|
|
206
|
-
unknownKeys.map((key) => ({ path: [key], message: "Unknown attribute" }))
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
function getMissingRequiredAttributes(objectDef, data) {
|
|
211
|
-
const missing = [];
|
|
212
|
-
for (const attr of objectDef.attributes) {
|
|
213
|
-
if (attr.required && !isValuePresent(data[attr.name])) {
|
|
214
|
-
missing.push(attr);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return missing;
|
|
218
|
-
}
|
|
219
|
-
function isRecordComplete(objectDef, data) {
|
|
220
|
-
const missing = getMissingRequiredAttributes(objectDef, data);
|
|
221
|
-
if (missing.length > 0) {
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
const validation = validateObject(objectDef, data);
|
|
225
|
-
return validation.success;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
exports.createAttributeValidator = createAttributeValidator;
|
|
229
|
-
exports.createDraftValidator = createDraftValidator;
|
|
230
|
-
exports.createFormAttributeValidator = createFormAttributeValidator;
|
|
231
|
-
exports.createObjectValidator = createObjectValidator;
|
|
232
|
-
exports.getMissingRequiredAttributes = getMissingRequiredAttributes;
|
|
233
|
-
exports.isNullishOrEmptyString = isNullishOrEmptyString;
|
|
234
|
-
exports.isRecordComplete = isRecordComplete;
|
|
235
|
-
exports.isValuePresent = isValuePresent;
|
|
236
|
-
exports.rejectUnknownAttributesOrThrow = rejectUnknownAttributesOrThrow;
|
|
237
|
-
exports.validateAttribute = validateAttribute;
|
|
238
|
-
exports.validateDraft = validateDraft;
|
|
239
|
-
exports.validateDraftOrThrow = validateDraftOrThrow;
|
|
240
|
-
exports.validateObject = validateObject;
|
|
241
|
-
exports.validateObjectOrThrow = validateObjectOrThrow;
|