@palmares/schemas 0.1.20 → 0.1.22

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 (111) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/src/adapter/index.js +2 -0
  3. package/dist/cjs/src/conf.js +3 -4
  4. package/dist/cjs/src/model.js +34 -38
  5. package/dist/cjs/src/schema/array.js +1 -0
  6. package/dist/cjs/src/schema/object.js +2 -8
  7. package/dist/cjs/src/schema/schema.js +1 -0
  8. package/dist/cjs/src/utils.js +12 -14
  9. package/dist/cjs/src/validators/utils.js +1 -0
  10. package/dist/cjs/tsconfig.types.tsbuildinfo +1 -1
  11. package/dist/cjs/types/adapter/index.d.ts +2 -0
  12. package/dist/cjs/types/adapter/index.d.ts.map +1 -1
  13. package/dist/cjs/types/conf.d.ts +3 -0
  14. package/dist/cjs/types/conf.d.ts.map +1 -1
  15. package/dist/cjs/types/domain.d.ts +3 -0
  16. package/dist/cjs/types/domain.d.ts.map +1 -1
  17. package/dist/cjs/types/model.d.ts +2 -2
  18. package/dist/cjs/types/model.d.ts.map +1 -1
  19. package/dist/cjs/types/schema/array.d.ts +1 -0
  20. package/dist/cjs/types/schema/array.d.ts.map +1 -1
  21. package/dist/cjs/types/schema/object.d.ts.map +1 -1
  22. package/dist/cjs/types/schema/schema.d.ts +1 -0
  23. package/dist/cjs/types/schema/schema.d.ts.map +1 -1
  24. package/dist/cjs/types/utils.d.ts +2 -1
  25. package/dist/cjs/types/utils.d.ts.map +1 -1
  26. package/dist/cjs/types/validators/utils.d.ts +1 -0
  27. package/dist/cjs/types/validators/utils.d.ts.map +1 -1
  28. package/dist/esm/src/adapter/index.js +2 -0
  29. package/dist/esm/src/conf.js +3 -4
  30. package/dist/esm/src/model.js +32 -30
  31. package/dist/esm/src/schema/array.js +1 -0
  32. package/dist/esm/src/schema/object.js +2 -1
  33. package/dist/esm/src/schema/schema.js +1 -0
  34. package/dist/esm/src/utils.js +9 -6
  35. package/dist/esm/src/validators/utils.js +1 -0
  36. package/package.json +11 -5
  37. package/.turbo/turbo-build$colon$watch.log +0 -24
  38. package/.turbo/turbo-build.log +0 -4
  39. package/.turbo/turbo-build:watch.log +0 -26
  40. package/__tests__/.drizzle/migrations/0000_skinny_harrier.sql +0 -22
  41. package/__tests__/.drizzle/migrations/meta/0000_snapshot.json +0 -156
  42. package/__tests__/.drizzle/migrations/meta/_journal.json +0 -13
  43. package/__tests__/.drizzle/schema.ts +0 -35
  44. package/__tests__/drizzle.config.ts +0 -11
  45. package/__tests__/eslint.config.js +0 -10
  46. package/__tests__/manage.ts +0 -5
  47. package/__tests__/node_modules/.bin/drizzle-kit +0 -17
  48. package/__tests__/node_modules/.bin/tsc +0 -17
  49. package/__tests__/node_modules/.bin/tsserver +0 -17
  50. package/__tests__/node_modules/.bin/tsx +0 -17
  51. package/__tests__/package.json +0 -34
  52. package/__tests__/sqlite.db +0 -0
  53. package/__tests__/src/core/array.test.ts +0 -131
  54. package/__tests__/src/core/boolean.test.ts +0 -66
  55. package/__tests__/src/core/datetime.test.ts +0 -102
  56. package/__tests__/src/core/index.ts +0 -35
  57. package/__tests__/src/core/model.test.ts +0 -260
  58. package/__tests__/src/core/models.ts +0 -50
  59. package/__tests__/src/core/numbers.test.ts +0 -177
  60. package/__tests__/src/core/object.test.ts +0 -218
  61. package/__tests__/src/core/string.test.ts +0 -222
  62. package/__tests__/src/core/test.test.ts +0 -59
  63. package/__tests__/src/core/types.test.ts +0 -97
  64. package/__tests__/src/core/union.test.ts +0 -99
  65. package/__tests__/src/settings.ts +0 -69
  66. package/__tests__/tsconfig.json +0 -11
  67. package/src/adapter/fields/array.ts +0 -31
  68. package/src/adapter/fields/boolean.ts +0 -43
  69. package/src/adapter/fields/datetime.ts +0 -43
  70. package/src/adapter/fields/index.ts +0 -72
  71. package/src/adapter/fields/number.ts +0 -43
  72. package/src/adapter/fields/object.ts +0 -52
  73. package/src/adapter/fields/string.ts +0 -43
  74. package/src/adapter/fields/union.ts +0 -43
  75. package/src/adapter/index.ts +0 -35
  76. package/src/adapter/types.ts +0 -276
  77. package/src/compile.ts +0 -14
  78. package/src/conf.ts +0 -27
  79. package/src/constants.ts +0 -7
  80. package/src/domain.ts +0 -15
  81. package/src/exceptions.ts +0 -17
  82. package/src/index.ts +0 -318
  83. package/src/middleware.ts +0 -52
  84. package/src/model.ts +0 -507
  85. package/src/parsers/convert-from-number.ts +0 -13
  86. package/src/parsers/convert-from-string.ts +0 -19
  87. package/src/parsers/index.ts +0 -2
  88. package/src/schema/array.ts +0 -824
  89. package/src/schema/boolean.ts +0 -792
  90. package/src/schema/datetime.ts +0 -704
  91. package/src/schema/index.ts +0 -5
  92. package/src/schema/number.ts +0 -929
  93. package/src/schema/object.ts +0 -798
  94. package/src/schema/schema.ts +0 -1178
  95. package/src/schema/string.ts +0 -941
  96. package/src/schema/types.ts +0 -154
  97. package/src/schema/union.ts +0 -724
  98. package/src/types.ts +0 -66
  99. package/src/utils.ts +0 -383
  100. package/src/validators/array.ts +0 -183
  101. package/src/validators/boolean.ts +0 -52
  102. package/src/validators/datetime.ts +0 -121
  103. package/src/validators/number.ts +0 -178
  104. package/src/validators/object.ts +0 -56
  105. package/src/validators/schema.ts +0 -142
  106. package/src/validators/string.ts +0 -278
  107. package/src/validators/types.ts +0 -1
  108. package/src/validators/union.ts +0 -52
  109. package/src/validators/utils.ts +0 -225
  110. package/tsconfig.json +0 -9
  111. package/tsconfig.types.json +0 -10
@@ -1,121 +0,0 @@
1
- import type { DatetimeSchema } from '../schema/datetime';
2
- import type { Schema } from '../schema/schema';
3
- import type { ValidationFallbackReturnType } from '../schema/types';
4
-
5
- export function datetimeValidation(): ValidationFallbackReturnType {
6
- return {
7
- name: 'datetime',
8
- type: 'medium',
9
- // eslint-disable-next-line ts/require-await
10
- callback: async (
11
- value: any,
12
- path: (string | number)[],
13
- _options: Parameters<Schema['__transformToAdapter']>[0]
14
- ) => {
15
- const isValid = value instanceof Date && !isNaN(value.getTime());
16
-
17
- return {
18
- parsed: value,
19
- errors: isValid
20
- ? []
21
- : [
22
- {
23
- isValid: false,
24
- code: 'datetime',
25
- // eslint-disable-next-line ts/no-unnecessary-condition
26
- path: path || [],
27
- message: 'Value is not a date'
28
- }
29
- ],
30
- preventChildValidation: true
31
- };
32
- }
33
- };
34
- }
35
-
36
- export function allowStringParser(): ValidationFallbackReturnType {
37
- return {
38
- name: 'allowString',
39
- type: 'high',
40
- // eslint-disable-next-line ts/require-await
41
- callback: async (
42
- value: any,
43
- _path: (string | number)[],
44
- _options: Parameters<Schema['__transformToAdapter']>[0]
45
- ) => {
46
- if (typeof value === 'string') {
47
- const parsed = new Date(value);
48
- if (parsed instanceof Date && !isNaN(parsed.getTime())) {
49
- return {
50
- parsed: parsed,
51
- errors: []
52
- };
53
- }
54
- }
55
- return {
56
- parsed: value,
57
- errors: []
58
- };
59
- }
60
- };
61
- }
62
-
63
- export function below(args: DatetimeSchema['__below']): ValidationFallbackReturnType {
64
- return {
65
- name: 'below',
66
- type: 'low',
67
- // eslint-disable-next-line ts/require-await
68
- callback: async (
69
- value: any,
70
- path: (string | number)[],
71
- _options: Parameters<Schema['__transformToAdapter']>[0]
72
- ) => {
73
- const isValid = args.inclusive ? value <= args.value : value < args.value;
74
-
75
- return {
76
- parsed: value,
77
- errors: isValid
78
- ? []
79
- : [
80
- {
81
- isValid: false,
82
- code: 'below',
83
- // eslint-disable-next-line ts/no-unnecessary-condition
84
- path: path || [],
85
- message: args.message
86
- }
87
- ]
88
- };
89
- }
90
- };
91
- }
92
-
93
- export function above(args: DatetimeSchema['__above']): ValidationFallbackReturnType {
94
- return {
95
- name: 'above',
96
- type: 'low',
97
- // eslint-disable-next-line ts/require-await
98
- callback: async (
99
- value: any,
100
- path: (string | number)[],
101
- _options: Parameters<Schema['__transformToAdapter']>[0]
102
- ) => {
103
- const isValid = args.inclusive ? value <= args.value : value < args.value;
104
-
105
- return {
106
- parsed: value,
107
- errors: isValid
108
- ? []
109
- : [
110
- {
111
- isValid: false,
112
- code: 'above',
113
- // eslint-disable-next-line ts/no-unnecessary-condition
114
- path: path || [],
115
- message: args.message
116
- }
117
- ]
118
- };
119
- }
120
- };
121
- }
@@ -1,178 +0,0 @@
1
- import type { NumberSchema } from '../schema/number';
2
- import type { Schema } from '../schema/schema';
3
- import type { ValidationFallbackReturnType } from '../schema/types';
4
-
5
- export function numberValidation(): ValidationFallbackReturnType {
6
- return {
7
- name: 'number',
8
- type: 'medium',
9
- // eslint-disable-next-line ts/require-await
10
- callback: async (
11
- value: any,
12
- path: (string | number)[],
13
- _options: Parameters<Schema['__transformToAdapter']>[0]
14
- ) => {
15
- return {
16
- parsed: value,
17
- errors: [
18
- {
19
- isValid: typeof value === 'number',
20
- code: 'number',
21
- // eslint-disable-next-line ts/no-unnecessary-condition
22
- path: path || [],
23
- message: 'The value must be a number. Received: ' + typeof value
24
- }
25
- ]
26
- };
27
- }
28
- };
29
- }
30
-
31
- export function max(args: NonNullable<NumberSchema['__max']>): ValidationFallbackReturnType {
32
- return {
33
- name: 'max',
34
- type: 'low',
35
- // eslint-disable-next-line ts/require-await
36
- callback: async (
37
- value: any,
38
- path: (string | number)[],
39
- _options: Parameters<Schema['__transformToAdapter']>[0]
40
- ) => {
41
- if (args.inclusive)
42
- return {
43
- parsed: value,
44
- errors: [
45
- {
46
- isValid: value <= args.value,
47
- code: 'max',
48
- // eslint-disable-next-line ts/no-unnecessary-condition
49
- path: path || [],
50
- message: args.message
51
- }
52
- ]
53
- };
54
-
55
- return {
56
- parsed: value,
57
- errors: [
58
- {
59
- isValid: value < args.value,
60
- code: 'max',
61
- // eslint-disable-next-line ts/no-unnecessary-condition
62
- path: path || [],
63
- message: args.message
64
- }
65
- ]
66
- };
67
- }
68
- };
69
- }
70
-
71
- export function min(args: NonNullable<NumberSchema['__min']>): ValidationFallbackReturnType {
72
- return {
73
- name: 'min',
74
- type: 'low',
75
- // eslint-disable-next-line ts/require-await
76
- callback: async (value: any, path?: (string | number)[]) => {
77
- if (args.inclusive)
78
- return {
79
- parsed: value,
80
- errors: [
81
- {
82
- isValid: value >= args.value,
83
- message: args.message,
84
- code: 'min',
85
- path: path || []
86
- }
87
- ]
88
- };
89
-
90
- return {
91
- parsed: value,
92
- errors: [
93
- {
94
- isValid: value > args.value,
95
- message: args.message,
96
- code: 'min',
97
- path: path || []
98
- }
99
- ]
100
- };
101
- }
102
- };
103
- }
104
-
105
- export function integer(args: NonNullable<NumberSchema['__integer']>): ValidationFallbackReturnType {
106
- return {
107
- name: 'integer',
108
- type: 'low',
109
- // eslint-disable-next-line ts/require-await
110
- callback: async (value: any, path?: (string | number)[]) => {
111
- const isValid = Number.isInteger(value);
112
-
113
- return {
114
- parsed: value,
115
- errors: isValid
116
- ? []
117
- : [
118
- {
119
- isValid: isValid,
120
- message: args.message,
121
- code: 'integer',
122
- path: path || []
123
- }
124
- ]
125
- };
126
- }
127
- };
128
- }
129
-
130
- export function maxDigits(args: NonNullable<NumberSchema['__maxDigits']>): ValidationFallbackReturnType {
131
- return {
132
- name: 'maxDigits',
133
- type: 'low',
134
- // eslint-disable-next-line ts/require-await
135
- callback: async (value: any, path?: (string | number)[]) => {
136
- const isValid = value.toString().replace('.', '').length <= args.value;
137
-
138
- return {
139
- parsed: value,
140
- errors: isValid
141
- ? []
142
- : [
143
- {
144
- isValid: isValid,
145
- message: args.message,
146
- code: 'maxDigits',
147
- path: path || []
148
- }
149
- ]
150
- };
151
- }
152
- };
153
- }
154
-
155
- export function decimalPlaces(args: NonNullable<NumberSchema['__decimalPlaces']>): ValidationFallbackReturnType {
156
- return {
157
- name: 'decimalPlaces',
158
- type: 'low',
159
- // eslint-disable-next-line ts/require-await
160
- callback: async (value: any, path?: (string | number)[]) => {
161
- const isValid = value.toString().split('.')[1]?.length <= args.value;
162
-
163
- return {
164
- parsed: value,
165
- errors: isValid
166
- ? []
167
- : [
168
- {
169
- isValid: isValid,
170
- message: args.message,
171
- code: 'decimalPlaces',
172
- path: path || []
173
- }
174
- ]
175
- };
176
- }
177
- };
178
- }
@@ -1,56 +0,0 @@
1
- import type { Schema } from '../schema/schema';
2
- import type { ValidationFallbackCallbackReturnType, ValidationFallbackReturnType } from '../schema/types';
3
-
4
- export function objectValidation(keysToFallback: { [key: string]: Schema }): ValidationFallbackReturnType {
5
- return {
6
- name: 'object',
7
- type: 'low',
8
- callback: async (value: any, path: (string | number)[], options: Parameters<Schema['__transformToAdapter']>[0]) => {
9
- const isNotAnObject = typeof value !== 'object' && Array.isArray(value) === false && value !== null;
10
-
11
- if (isNotAnObject)
12
- return {
13
- parsed: value,
14
- preventChildValidation: true,
15
- errors: [
16
- {
17
- isValid: false,
18
- code: 'object',
19
- // eslint-disable-next-line ts/no-unnecessary-condition
20
- path: path || [],
21
- message: 'The value must be an object. Received: ' + typeof value
22
- }
23
- ]
24
- };
25
-
26
- const errors: { [key: string]: ValidationFallbackCallbackReturnType['errors'] } = {};
27
- const toValidateEntries = Object.entries(keysToFallback);
28
-
29
- await Promise.all(
30
- toValidateEntries.map(async ([key, schema]) => {
31
- const schemaWithProtected = schema as Schema & {
32
- __parse: Schema['__parse'];
33
- __toInternal: Schema['__toInternal'];
34
- };
35
- const { parsed, errors: parseErrors } = await schemaWithProtected.__parse(
36
- value[key],
37
- [...path, key],
38
- options
39
- );
40
- if (Array.isArray(parseErrors) && parseErrors.length > 0) errors[key] = parseErrors;
41
- else value[key] = parsed;
42
-
43
- // We append the toInternalToBubbleUp to the parent toInternalToBubbleUp
44
-
45
- if (schemaWithProtected.__toInternal && options.toInternalToBubbleUp)
46
- options.toInternalToBubbleUp.push(async () => (value[key] = await (schema as any).__toInternal(parsed)));
47
- })
48
- );
49
-
50
- return {
51
- parsed: value,
52
- errors: Object.values(errors).flat()
53
- };
54
- }
55
- };
56
- }
@@ -1,142 +0,0 @@
1
- import type { ErrorCodes } from '../adapter/types';
2
- import type { BooleanSchema } from '../schema/boolean';
3
- import type { NumberSchema } from '../schema/number';
4
- import type { Schema } from '../schema/schema';
5
- import type { StringSchema } from '../schema/string';
6
- import type { ValidationFallbackReturnType } from '../schema/types';
7
-
8
- export function optional(args: Schema['__optional']): ValidationFallbackReturnType {
9
- return {
10
- name: 'optional',
11
- type: 'high',
12
- // eslint-disable-next-line ts/require-await
13
- callback: async (value: any, path: (string | number)[]) => {
14
- if (value === undefined) {
15
- if (args.allow === true)
16
- return {
17
- parsed: value,
18
- errors: [],
19
- preventChildValidation: true
20
- };
21
- return {
22
- parsed: value,
23
- errors: [
24
- {
25
- isValid: false,
26
- message: args.message,
27
- code: 'required' as ErrorCodes,
28
- // eslint-disable-next-line ts/no-unnecessary-condition
29
- path: path || []
30
- }
31
- ],
32
- preventChildValidation: true
33
- };
34
- }
35
-
36
- return {
37
- parsed: value,
38
- errors: [],
39
- preventChildValidation: false
40
- };
41
- }
42
- };
43
- }
44
-
45
- export function nullable(args: Schema['__nullable']): ValidationFallbackReturnType {
46
- return {
47
- name: 'nullable',
48
- type: 'high',
49
- // eslint-disable-next-line ts/require-await
50
- callback: async (value: any, path: (string | number)[]) => {
51
- if (value === null) {
52
- if (args.allow === true)
53
- return {
54
- parsed: value,
55
- errors: [],
56
- preventChildValidation: true
57
- };
58
- return {
59
- parsed: value,
60
- errors: [
61
- {
62
- isValid: false,
63
- message: args.message,
64
- code: 'null',
65
- // eslint-disable-next-line ts/no-unnecessary-condition
66
- path: path || []
67
- }
68
- ],
69
- preventChildValidation: true
70
- };
71
- }
72
-
73
- return {
74
- parsed: value,
75
- errors: [],
76
- preventChildValidation: false
77
- };
78
- }
79
- };
80
- }
81
-
82
- export function checkType(args: NonNullable<Schema['__type']>): ValidationFallbackReturnType {
83
- return {
84
- name: 'checkType',
85
- type: 'medium',
86
- // eslint-disable-next-line ts/require-await
87
- callback: async (value: any, path: (string | number)[]) => {
88
- if (args.check(value))
89
- return {
90
- parsed: value,
91
- errors: [],
92
- preventChildValidation: false
93
- };
94
-
95
- return {
96
- parsed: value,
97
- errors: [
98
- {
99
- isValid: false,
100
- message: args.message,
101
- code: 'invalid_type' as ErrorCodes,
102
- // eslint-disable-next-line ts/no-unnecessary-condition
103
- path: path || []
104
- }
105
- ],
106
- preventChildValidation: true
107
- };
108
- }
109
- };
110
- }
111
-
112
- export function is(
113
- args: NonNullable<BooleanSchema['__is']> | NonNullable<NumberSchema['__is']> | NonNullable<StringSchema['__is']>
114
- ): ValidationFallbackReturnType {
115
- return {
116
- name: 'is',
117
- type: 'medium',
118
- // eslint-disable-next-line ts/require-await
119
- callback: async (
120
- value: any,
121
- path: (string | number)[],
122
- _options: Parameters<Schema['__transformToAdapter']>[0]
123
- ) => {
124
- const isValid = Array.isArray(args.value) ? args.value.includes(value as never) : value === args.value;
125
- return {
126
- parsed: value,
127
- errors: isValid
128
- ? []
129
- : [
130
- {
131
- isValid: false,
132
- code: 'is',
133
- // eslint-disable-next-line ts/no-unnecessary-condition
134
- path: path || [],
135
- message: 'Value is not a boolean'
136
- }
137
- ],
138
- preventChildValidation: true
139
- };
140
- }
141
- };
142
- }