@palmares/schemas 0.1.21 → 0.1.23

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 (78) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/package.json +10 -4
  3. package/.turbo/turbo-build$colon$watch.log +0 -24
  4. package/.turbo/turbo-build.log +0 -13
  5. package/.turbo/turbo-build:watch.log +0 -26
  6. package/__tests__/.drizzle/migrations/0000_skinny_harrier.sql +0 -22
  7. package/__tests__/.drizzle/migrations/meta/0000_snapshot.json +0 -156
  8. package/__tests__/.drizzle/migrations/meta/_journal.json +0 -13
  9. package/__tests__/.drizzle/schema.ts +0 -35
  10. package/__tests__/drizzle.config.ts +0 -11
  11. package/__tests__/eslint.config.js +0 -10
  12. package/__tests__/manage.ts +0 -5
  13. package/__tests__/node_modules/.bin/drizzle-kit +0 -17
  14. package/__tests__/node_modules/.bin/node-gyp +0 -17
  15. package/__tests__/node_modules/.bin/tsc +0 -17
  16. package/__tests__/node_modules/.bin/tsserver +0 -17
  17. package/__tests__/node_modules/.bin/tsx +0 -17
  18. package/__tests__/package.json +0 -34
  19. package/__tests__/sqlite.db +0 -0
  20. package/__tests__/src/core/array.test.ts +0 -131
  21. package/__tests__/src/core/boolean.test.ts +0 -66
  22. package/__tests__/src/core/datetime.test.ts +0 -102
  23. package/__tests__/src/core/index.ts +0 -35
  24. package/__tests__/src/core/model.test.ts +0 -260
  25. package/__tests__/src/core/models.ts +0 -50
  26. package/__tests__/src/core/numbers.test.ts +0 -177
  27. package/__tests__/src/core/object.test.ts +0 -218
  28. package/__tests__/src/core/string.test.ts +0 -222
  29. package/__tests__/src/core/test.test.ts +0 -59
  30. package/__tests__/src/core/types.test.ts +0 -97
  31. package/__tests__/src/core/union.test.ts +0 -99
  32. package/__tests__/src/settings.ts +0 -69
  33. package/__tests__/tsconfig.json +0 -11
  34. package/src/adapter/fields/array.ts +0 -31
  35. package/src/adapter/fields/boolean.ts +0 -43
  36. package/src/adapter/fields/datetime.ts +0 -43
  37. package/src/adapter/fields/index.ts +0 -72
  38. package/src/adapter/fields/number.ts +0 -43
  39. package/src/adapter/fields/object.ts +0 -52
  40. package/src/adapter/fields/string.ts +0 -43
  41. package/src/adapter/fields/union.ts +0 -43
  42. package/src/adapter/index.ts +0 -37
  43. package/src/adapter/types.ts +0 -276
  44. package/src/compile.ts +0 -14
  45. package/src/conf.ts +0 -30
  46. package/src/constants.ts +0 -7
  47. package/src/domain.ts +0 -15
  48. package/src/exceptions.ts +0 -17
  49. package/src/index.ts +0 -318
  50. package/src/middleware.ts +0 -52
  51. package/src/model.ts +0 -518
  52. package/src/parsers/convert-from-number.ts +0 -13
  53. package/src/parsers/convert-from-string.ts +0 -19
  54. package/src/parsers/index.ts +0 -2
  55. package/src/schema/array.ts +0 -825
  56. package/src/schema/boolean.ts +0 -792
  57. package/src/schema/datetime.ts +0 -704
  58. package/src/schema/index.ts +0 -5
  59. package/src/schema/number.ts +0 -929
  60. package/src/schema/object.ts +0 -799
  61. package/src/schema/schema.ts +0 -1179
  62. package/src/schema/string.ts +0 -941
  63. package/src/schema/types.ts +0 -154
  64. package/src/schema/union.ts +0 -724
  65. package/src/types.ts +0 -66
  66. package/src/utils.ts +0 -389
  67. package/src/validators/array.ts +0 -183
  68. package/src/validators/boolean.ts +0 -52
  69. package/src/validators/datetime.ts +0 -121
  70. package/src/validators/number.ts +0 -178
  71. package/src/validators/object.ts +0 -56
  72. package/src/validators/schema.ts +0 -142
  73. package/src/validators/string.ts +0 -278
  74. package/src/validators/types.ts +0 -1
  75. package/src/validators/union.ts +0 -52
  76. package/src/validators/utils.ts +0 -226
  77. package/tsconfig.json +0 -9
  78. 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
- }