unischema 1.0.1 → 1.2.0

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.
Files changed (70) hide show
  1. package/README.md +780 -228
  2. package/dist/adapters/backend/index.d.mts +2 -1
  3. package/dist/adapters/backend/index.d.ts +2 -1
  4. package/dist/adapters/backend/index.js +17 -441
  5. package/dist/adapters/backend/index.mjs +9 -433
  6. package/dist/adapters/frontend/index.d.mts +2 -1
  7. package/dist/adapters/frontend/index.d.ts +2 -1
  8. package/dist/adapters/frontend/index.js +10 -421
  9. package/dist/adapters/frontend/index.mjs +8 -419
  10. package/dist/chunk-5A4ITJVD.mjs +124 -0
  11. package/dist/chunk-66RFUBVU.js +131 -0
  12. package/dist/chunk-75YSYC4K.mjs +85 -0
  13. package/dist/chunk-76BBWQDH.js +90 -0
  14. package/dist/chunk-7XES4A3M.mjs +237 -0
  15. package/dist/chunk-BVRXGZLS.js +17 -0
  16. package/dist/chunk-COMVAVFU.mjs +335 -0
  17. package/dist/chunk-DT2TQZU7.js +796 -0
  18. package/dist/chunk-FPCCH55A.js +103 -0
  19. package/dist/chunk-IUXRLMET.js +206 -0
  20. package/dist/chunk-JEW6U6CB.js +353 -0
  21. package/dist/chunk-KZCV5IW4.mjs +97 -0
  22. package/dist/chunk-KZZ7NVU3.mjs +41 -0
  23. package/dist/chunk-MFEBMQAU.mjs +779 -0
  24. package/dist/chunk-OIYG5D2I.js +50 -0
  25. package/dist/chunk-RW6HDA5H.mjs +194 -0
  26. package/dist/chunk-TTK77YBI.mjs +15 -0
  27. package/dist/chunk-TXT36BCE.js +248 -0
  28. package/dist/index-C17xs-fU.d.mts +140 -0
  29. package/dist/index-C17xs-fU.d.ts +140 -0
  30. package/dist/index.d.mts +26 -7
  31. package/dist/index.d.ts +26 -7
  32. package/dist/index.js +769 -499
  33. package/dist/index.mjs +695 -487
  34. package/dist/{schema-D9DGC9E_.d.ts → schema-DYE8Wz8X.d.mts} +264 -79
  35. package/dist/{schema-D9DGC9E_.d.mts → schema-Dtp-joeT.d.ts} +264 -79
  36. package/dist/validators/array.d.mts +15 -0
  37. package/dist/validators/array.d.ts +15 -0
  38. package/dist/validators/array.js +31 -0
  39. package/dist/validators/array.mjs +2 -0
  40. package/dist/validators/common.d.mts +13 -0
  41. package/dist/validators/common.d.ts +13 -0
  42. package/dist/validators/common.js +27 -0
  43. package/dist/validators/common.mjs +2 -0
  44. package/dist/validators/date.d.mts +23 -0
  45. package/dist/validators/date.d.ts +23 -0
  46. package/dist/validators/date.js +47 -0
  47. package/dist/validators/date.mjs +2 -0
  48. package/dist/validators/index.d.mts +46 -0
  49. package/dist/validators/index.d.ts +46 -0
  50. package/dist/validators/index.js +256 -0
  51. package/dist/validators/index.mjs +7 -0
  52. package/dist/validators/number.d.mts +25 -0
  53. package/dist/validators/number.d.ts +25 -0
  54. package/dist/validators/number.js +51 -0
  55. package/dist/validators/number.mjs +2 -0
  56. package/dist/validators/object.d.mts +11 -0
  57. package/dist/validators/object.d.ts +11 -0
  58. package/dist/validators/object.js +23 -0
  59. package/dist/validators/object.mjs +2 -0
  60. package/dist/validators/string.d.mts +37 -0
  61. package/dist/validators/string.d.ts +37 -0
  62. package/dist/validators/string.js +75 -0
  63. package/dist/validators/string.mjs +2 -0
  64. package/package.json +82 -5
  65. package/dist/adapters/backend/index.js.map +0 -1
  66. package/dist/adapters/backend/index.mjs.map +0 -1
  67. package/dist/adapters/frontend/index.js.map +0 -1
  68. package/dist/adapters/frontend/index.mjs.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,97 @@
1
+ import { isEmpty, createError, isNumber } from './chunk-KZZ7NVU3.mjs';
2
+
3
+ // src/validators/common/notMatches.ts
4
+ var notMatchesValidator = (value, params, context) => {
5
+ if (isEmpty(value)) return null;
6
+ const fieldName = params?.field;
7
+ const soft = params?.soft;
8
+ const message = params?.message;
9
+ if (!fieldName) return null;
10
+ const root = context.root;
11
+ const otherValue = root?.[fieldName];
12
+ if (value === otherValue) {
13
+ return createError(
14
+ context,
15
+ "INVALID_NOT_MATCHES",
16
+ message || `Must not match ${fieldName}`,
17
+ soft
18
+ );
19
+ }
20
+ return null;
21
+ };
22
+
23
+ // src/validators/common/greaterThan.ts
24
+ var greaterThanValidator = (value, params, context) => {
25
+ if (isEmpty(value)) return null;
26
+ const fieldName = params?.field;
27
+ const soft = params?.soft;
28
+ const message = params?.message;
29
+ if (!isNumber(value) || !fieldName) return null;
30
+ const root = context.root;
31
+ const otherValue = root?.[fieldName];
32
+ if (isNumber(otherValue) && value <= otherValue) {
33
+ return createError(
34
+ context,
35
+ "INVALID_GREATER_THAN",
36
+ message || `Must be greater than ${fieldName}`,
37
+ soft
38
+ );
39
+ }
40
+ return null;
41
+ };
42
+
43
+ // src/validators/common/lessThan.ts
44
+ var lessThanValidator = (value, params, context) => {
45
+ if (isEmpty(value)) return null;
46
+ const fieldName = params?.field;
47
+ const soft = params?.soft;
48
+ const message = params?.message;
49
+ if (!isNumber(value) || !fieldName) return null;
50
+ const root = context.root;
51
+ const otherValue = root?.[fieldName];
52
+ if (isNumber(otherValue) && value >= otherValue) {
53
+ return createError(
54
+ context,
55
+ "INVALID_LESS_THAN",
56
+ message || `Must be less than ${fieldName}`,
57
+ soft
58
+ );
59
+ }
60
+ return null;
61
+ };
62
+
63
+ // src/validators/common/when.ts
64
+ var whenValidator = (value, params, context) => {
65
+ const fieldName = params?.field;
66
+ const is = params?.is;
67
+ const then = params?.then;
68
+ if (!fieldName || !then) return null;
69
+ const root = context.root;
70
+ const otherValue = root?.[fieldName];
71
+ if (otherValue === is) {
72
+ return then(value, params, context);
73
+ }
74
+ return null;
75
+ };
76
+
77
+ // src/validators/common/dependsOn.ts
78
+ var dependsOnValidator = (value, params, context) => {
79
+ if (isEmpty(value)) return null;
80
+ const fieldName = params?.field;
81
+ const soft = params?.soft;
82
+ const message = params?.message;
83
+ if (!fieldName) return null;
84
+ const root = context.root;
85
+ const otherValue = root?.[fieldName];
86
+ if (isEmpty(otherValue)) {
87
+ return createError(
88
+ context,
89
+ "INVALID_DEPENDS_ON",
90
+ message || `This field requires ${fieldName} to be set`,
91
+ soft
92
+ );
93
+ }
94
+ return null;
95
+ };
96
+
97
+ export { dependsOnValidator, greaterThanValidator, lessThanValidator, notMatchesValidator, whenValidator };
@@ -0,0 +1,41 @@
1
+ // src/validators/utils.ts
2
+ function createError(context, code, message, soft = false, received, expected) {
3
+ return {
4
+ field: context.path,
5
+ code,
6
+ message,
7
+ severity: soft ? "soft" : "hard",
8
+ received,
9
+ expected
10
+ };
11
+ }
12
+ function isEmpty(value) {
13
+ return value === void 0 || value === null || value === "";
14
+ }
15
+ function isString(value) {
16
+ return typeof value === "string";
17
+ }
18
+ function isNumber(value) {
19
+ return typeof value === "number" && !isNaN(value);
20
+ }
21
+ function isDate(value) {
22
+ return value instanceof Date && !isNaN(value.getTime());
23
+ }
24
+ function parseDate(value) {
25
+ if (value instanceof Date) {
26
+ return isNaN(value.getTime()) ? null : value;
27
+ }
28
+ if (typeof value === "string") {
29
+ const parsed = new Date(value);
30
+ return isNaN(parsed.getTime()) ? null : parsed;
31
+ }
32
+ return null;
33
+ }
34
+ function isArray(value) {
35
+ return Array.isArray(value);
36
+ }
37
+ function isObject(value) {
38
+ return typeof value === "object" && value !== null && !Array.isArray(value);
39
+ }
40
+
41
+ export { createError, isArray, isDate, isEmpty, isNumber, isObject, isString, parseDate };