@geekmidas/schema 0.0.3 → 1.0.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 (47) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/{conversion-Civd6bIU.mjs → conversion-BJGLAqtd.mjs} +2 -3
  3. package/dist/conversion-BJGLAqtd.mjs.map +1 -0
  4. package/dist/{conversion-CrSNoSRa.cjs → conversion-CFlFrSru.cjs} +2 -3
  5. package/dist/conversion-CFlFrSru.cjs.map +1 -0
  6. package/dist/conversion-CH_EmflL.d.cts.map +1 -0
  7. package/dist/conversion-DUyZYTWO.d.mts.map +1 -0
  8. package/dist/conversion.cjs +1 -1
  9. package/dist/conversion.mjs +1 -1
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.d.cts +2 -2
  12. package/dist/index.d.mts +2 -2
  13. package/dist/index.mjs +1 -1
  14. package/dist/{openapi-DR4_PG-e.d.cts → openapi-Aeb_1e9T.d.cts} +3 -1
  15. package/dist/openapi-Aeb_1e9T.d.cts.map +1 -0
  16. package/dist/openapi-DH5yCqKh.mjs.map +1 -1
  17. package/dist/openapi-DVvLYx-8.cjs.map +1 -1
  18. package/dist/{openapi-j01kFjpI.d.mts → openapi-Dxc4FuMP.d.mts} +3 -1
  19. package/dist/openapi-Dxc4FuMP.d.mts.map +1 -0
  20. package/dist/openapi.d.cts +1 -1
  21. package/dist/openapi.d.mts +1 -1
  22. package/dist/parser.cjs.map +1 -1
  23. package/dist/parser.d.cts +3 -1
  24. package/dist/parser.d.cts.map +1 -0
  25. package/dist/parser.d.mts +3 -1
  26. package/dist/parser.d.mts.map +1 -0
  27. package/dist/parser.mjs.map +1 -1
  28. package/dist/{types-ByLHeRGs.d.mts → types-D7ZRea_7.d.cts} +3 -1
  29. package/dist/types-D7ZRea_7.d.cts.map +1 -0
  30. package/dist/{types-DfcgE7cO.d.cts → types-o4dOkvCd.d.mts} +3 -1
  31. package/dist/types-o4dOkvCd.d.mts.map +1 -0
  32. package/dist/types.d.cts +1 -1
  33. package/dist/types.d.mts +1 -1
  34. package/package.json +1 -1
  35. package/src/__benchmarks__/conversion.bench.ts +88 -0
  36. package/src/__tests__/conversion.spec.ts +440 -257
  37. package/src/__tests__/openapi.spec.ts +390 -390
  38. package/src/__tests__/parser.spec.ts +202 -202
  39. package/src/conversion.ts +154 -158
  40. package/src/index.ts +8 -9
  41. package/src/openapi.ts +49 -49
  42. package/src/parser.ts +11 -11
  43. package/src/types.ts +16 -16
  44. package/tsconfig.json +9 -0
  45. package/tsdown.config.ts +1 -1
  46. package/dist/conversion-Civd6bIU.mjs.map +0 -1
  47. package/dist/conversion-CrSNoSRa.cjs.map +0 -1
@@ -3,234 +3,234 @@ import { z } from 'zod/v4';
3
3
  import { parseSchema, validate } from '../parser';
4
4
 
5
5
  describe('Schema Parser', () => {
6
- describe('validate', () => {
7
- it('should validate data against a Zod schema', async () => {
8
- const schema = z.object({
9
- name: z.string(),
10
- age: z.number(),
11
- });
12
-
13
- const result = await validate(schema, { name: 'John', age: 30 });
14
-
15
- expect(result.issues).toBeUndefined();
16
- if ('value' in result) {
17
- expect(result.value).toEqual({ name: 'John', age: 30 });
18
- }
19
- });
20
-
21
- it('should return issues for invalid data', async () => {
22
- const schema = z.object({
23
- name: z.string(),
24
- age: z.number(),
25
- });
26
-
27
- const result = await validate(schema, { name: 'John', age: 'invalid' });
28
-
29
- expect(result.issues).toBeDefined();
30
- });
31
-
32
- it('should validate string schema', async () => {
33
- const schema = z.string();
34
-
35
- const result = await validate(schema, 'test string');
36
-
37
- expect(result.issues).toBeUndefined();
38
- if ('value' in result) {
39
- expect(result.value).toBe('test string');
40
- }
41
- });
42
-
43
- it('should validate array schema', async () => {
44
- const schema = z.array(z.number());
45
-
46
- const result = await validate(schema, [1, 2, 3]);
6
+ describe('validate', () => {
7
+ it('should validate data against a Zod schema', async () => {
8
+ const schema = z.object({
9
+ name: z.string(),
10
+ age: z.number(),
11
+ });
12
+
13
+ const result = await validate(schema, { name: 'John', age: 30 });
14
+
15
+ expect(result.issues).toBeUndefined();
16
+ if ('value' in result) {
17
+ expect(result.value).toEqual({ name: 'John', age: 30 });
18
+ }
19
+ });
20
+
21
+ it('should return issues for invalid data', async () => {
22
+ const schema = z.object({
23
+ name: z.string(),
24
+ age: z.number(),
25
+ });
26
+
27
+ const result = await validate(schema, { name: 'John', age: 'invalid' });
28
+
29
+ expect(result.issues).toBeDefined();
30
+ });
31
+
32
+ it('should validate string schema', async () => {
33
+ const schema = z.string();
34
+
35
+ const result = await validate(schema, 'test string');
36
+
37
+ expect(result.issues).toBeUndefined();
38
+ if ('value' in result) {
39
+ expect(result.value).toBe('test string');
40
+ }
41
+ });
42
+
43
+ it('should validate array schema', async () => {
44
+ const schema = z.array(z.number());
45
+
46
+ const result = await validate(schema, [1, 2, 3]);
47
47
 
48
- expect(result.issues).toBeUndefined();
49
- if ('value' in result) {
50
- expect(result.value).toEqual([1, 2, 3]);
51
- }
52
- });
53
-
54
- it('should return issues for invalid array items', async () => {
55
- const schema = z.array(z.number());
48
+ expect(result.issues).toBeUndefined();
49
+ if ('value' in result) {
50
+ expect(result.value).toEqual([1, 2, 3]);
51
+ }
52
+ });
53
+
54
+ it('should return issues for invalid array items', async () => {
55
+ const schema = z.array(z.number());
56
56
 
57
- const result = await validate(schema, [1, 'invalid', 3]);
57
+ const result = await validate(schema, [1, 'invalid', 3]);
58
58
 
59
- expect(result.issues).toBeDefined();
60
- });
61
-
62
- it('should validate nested objects', async () => {
63
- const schema = z.object({
64
- user: z.object({
65
- name: z.string(),
66
- profile: z.object({
67
- bio: z.string(),
68
- }),
69
- }),
70
- });
59
+ expect(result.issues).toBeDefined();
60
+ });
61
+
62
+ it('should validate nested objects', async () => {
63
+ const schema = z.object({
64
+ user: z.object({
65
+ name: z.string(),
66
+ profile: z.object({
67
+ bio: z.string(),
68
+ }),
69
+ }),
70
+ });
71
71
 
72
- const result = await validate(schema, {
73
- user: {
74
- name: 'John',
75
- profile: { bio: 'Developer' },
76
- },
77
- });
72
+ const result = await validate(schema, {
73
+ user: {
74
+ name: 'John',
75
+ profile: { bio: 'Developer' },
76
+ },
77
+ });
78
78
 
79
- expect(result.issues).toBeUndefined();
80
- if ('value' in result) {
81
- expect(result.value).toEqual({
82
- user: {
83
- name: 'John',
84
- profile: { bio: 'Developer' },
85
- },
86
- });
87
- }
88
- });
89
- });
79
+ expect(result.issues).toBeUndefined();
80
+ if ('value' in result) {
81
+ expect(result.value).toEqual({
82
+ user: {
83
+ name: 'John',
84
+ profile: { bio: 'Developer' },
85
+ },
86
+ });
87
+ }
88
+ });
89
+ });
90
90
 
91
- describe('parseSchema', () => {
92
- it('should parse valid data', async () => {
93
- const schema = z.object({
94
- name: z.string(),
95
- age: z.number(),
96
- });
91
+ describe('parseSchema', () => {
92
+ it('should parse valid data', async () => {
93
+ const schema = z.object({
94
+ name: z.string(),
95
+ age: z.number(),
96
+ });
97
97
 
98
- const result = await parseSchema(schema, { name: 'John', age: 30 });
98
+ const result = await parseSchema(schema, { name: 'John', age: 30 });
99
99
 
100
- expect(result).toEqual({ name: 'John', age: 30 });
101
- });
100
+ expect(result).toEqual({ name: 'John', age: 30 });
101
+ });
102
102
 
103
- it('should throw for invalid data', async () => {
104
- const schema = z.object({
105
- name: z.string(),
106
- age: z.number(),
107
- });
103
+ it('should throw for invalid data', async () => {
104
+ const schema = z.object({
105
+ name: z.string(),
106
+ age: z.number(),
107
+ });
108
108
 
109
- await expect(
110
- parseSchema(schema, { name: 'John', age: 'invalid' }),
111
- ).rejects.toBeDefined();
112
- });
109
+ await expect(
110
+ parseSchema(schema, { name: 'John', age: 'invalid' }),
111
+ ).rejects.toBeDefined();
112
+ });
113
113
 
114
- it('should return undefined for undefined schema', async () => {
115
- const result = await parseSchema(undefined as any, { name: 'John' });
114
+ it('should return undefined for undefined schema', async () => {
115
+ const result = await parseSchema(undefined as any, { name: 'John' });
116
116
 
117
- expect(result).toBeUndefined();
118
- });
117
+ expect(result).toBeUndefined();
118
+ });
119
119
 
120
- it('should parse string schema', async () => {
121
- const schema = z.string().min(3);
120
+ it('should parse string schema', async () => {
121
+ const schema = z.string().min(3);
122
122
 
123
- const result = await parseSchema(schema, 'test');
123
+ const result = await parseSchema(schema, 'test');
124
124
 
125
- expect(result).toBe('test');
126
- });
125
+ expect(result).toBe('test');
126
+ });
127
127
 
128
- it('should throw for string that is too short', async () => {
129
- const schema = z.string().min(5);
128
+ it('should throw for string that is too short', async () => {
129
+ const schema = z.string().min(5);
130
130
 
131
- await expect(parseSchema(schema, 'abc')).rejects.toBeDefined();
132
- });
133
-
134
- it('should parse number schema', async () => {
135
- const schema = z.number().positive();
136
-
137
- const result = await parseSchema(schema, 42);
138
-
139
- expect(result).toBe(42);
140
- });
141
-
142
- it('should throw for negative number when positive required', async () => {
143
- const schema = z.number().positive();
144
-
145
- await expect(parseSchema(schema, -5)).rejects.toBeDefined();
146
- });
147
-
148
- it('should parse optional fields', async () => {
149
- const schema = z.object({
150
- required: z.string(),
151
- optional: z.string().optional(),
152
- });
153
-
154
- const result = await parseSchema(schema, { required: 'value' });
155
-
156
- expect(result).toEqual({ required: 'value' });
157
- });
158
-
159
- it('should parse with defaults', async () => {
160
- const schema = z.object({
161
- name: z.string(),
162
- role: z.string().default('user'),
163
- });
164
-
165
- const result = await parseSchema(schema, { name: 'John' });
166
-
167
- expect(result).toEqual({ name: 'John', role: 'user' });
168
- });
169
-
170
- it('should parse enum values', async () => {
171
- const schema = z.object({
172
- status: z.enum(['active', 'inactive', 'pending']),
173
- });
174
-
175
- const result = await parseSchema(schema, { status: 'active' });
176
-
177
- expect(result).toEqual({ status: 'active' });
178
- });
179
-
180
- it('should throw for invalid enum value', async () => {
181
- const schema = z.object({
182
- status: z.enum(['active', 'inactive']),
183
- });
131
+ await expect(parseSchema(schema, 'abc')).rejects.toBeDefined();
132
+ });
133
+
134
+ it('should parse number schema', async () => {
135
+ const schema = z.number().positive();
136
+
137
+ const result = await parseSchema(schema, 42);
138
+
139
+ expect(result).toBe(42);
140
+ });
141
+
142
+ it('should throw for negative number when positive required', async () => {
143
+ const schema = z.number().positive();
144
+
145
+ await expect(parseSchema(schema, -5)).rejects.toBeDefined();
146
+ });
147
+
148
+ it('should parse optional fields', async () => {
149
+ const schema = z.object({
150
+ required: z.string(),
151
+ optional: z.string().optional(),
152
+ });
153
+
154
+ const result = await parseSchema(schema, { required: 'value' });
155
+
156
+ expect(result).toEqual({ required: 'value' });
157
+ });
158
+
159
+ it('should parse with defaults', async () => {
160
+ const schema = z.object({
161
+ name: z.string(),
162
+ role: z.string().default('user'),
163
+ });
164
+
165
+ const result = await parseSchema(schema, { name: 'John' });
166
+
167
+ expect(result).toEqual({ name: 'John', role: 'user' });
168
+ });
169
+
170
+ it('should parse enum values', async () => {
171
+ const schema = z.object({
172
+ status: z.enum(['active', 'inactive', 'pending']),
173
+ });
174
+
175
+ const result = await parseSchema(schema, { status: 'active' });
176
+
177
+ expect(result).toEqual({ status: 'active' });
178
+ });
179
+
180
+ it('should throw for invalid enum value', async () => {
181
+ const schema = z.object({
182
+ status: z.enum(['active', 'inactive']),
183
+ });
184
184
 
185
- await expect(
186
- parseSchema(schema, { status: 'invalid' }),
187
- ).rejects.toBeDefined();
188
- });
185
+ await expect(
186
+ parseSchema(schema, { status: 'invalid' }),
187
+ ).rejects.toBeDefined();
188
+ });
189
189
 
190
- it('should parse union types', async () => {
191
- const schema = z.union([z.string(), z.number()]);
190
+ it('should parse union types', async () => {
191
+ const schema = z.union([z.string(), z.number()]);
192
192
 
193
- const result1 = await parseSchema(schema, 'text');
194
- const result2 = await parseSchema(schema, 42);
193
+ const result1 = await parseSchema(schema, 'text');
194
+ const result2 = await parseSchema(schema, 42);
195
195
 
196
- expect(result1).toBe('text');
197
- expect(result2).toBe(42);
198
- });
196
+ expect(result1).toBe('text');
197
+ expect(result2).toBe(42);
198
+ });
199
199
 
200
- it('should throw for invalid union value', async () => {
201
- const schema = z.union([z.string(), z.number()]);
200
+ it('should throw for invalid union value', async () => {
201
+ const schema = z.union([z.string(), z.number()]);
202
202
 
203
- await expect(parseSchema(schema, true)).rejects.toBeDefined();
204
- });
203
+ await expect(parseSchema(schema, true)).rejects.toBeDefined();
204
+ });
205
205
 
206
- it('should parse array of objects', async () => {
207
- const schema = z.array(
208
- z.object({
209
- id: z.number(),
210
- name: z.string(),
211
- }),
212
- );
206
+ it('should parse array of objects', async () => {
207
+ const schema = z.array(
208
+ z.object({
209
+ id: z.number(),
210
+ name: z.string(),
211
+ }),
212
+ );
213
213
 
214
- const result = await parseSchema(schema, [
215
- { id: 1, name: 'Alice' },
216
- { id: 2, name: 'Bob' },
217
- ]);
214
+ const result = await parseSchema(schema, [
215
+ { id: 1, name: 'Alice' },
216
+ { id: 2, name: 'Bob' },
217
+ ]);
218
218
 
219
- expect(result).toEqual([
220
- { id: 1, name: 'Alice' },
221
- { id: 2, name: 'Bob' },
222
- ]);
223
- });
219
+ expect(result).toEqual([
220
+ { id: 1, name: 'Alice' },
221
+ { id: 2, name: 'Bob' },
222
+ ]);
223
+ });
224
224
 
225
- it('should validate required fields', async () => {
226
- const schema = z.object({
227
- required: z.string(),
228
- optional: z.string().optional(),
229
- });
225
+ it('should validate required fields', async () => {
226
+ const schema = z.object({
227
+ required: z.string(),
228
+ optional: z.string().optional(),
229
+ });
230
230
 
231
- await expect(
232
- parseSchema(schema, { optional: 'value' }),
233
- ).rejects.toBeDefined();
234
- });
235
- });
231
+ await expect(
232
+ parseSchema(schema, { optional: 'value' }),
233
+ ).rejects.toBeDefined();
234
+ });
235
+ });
236
236
  });