@geekmidas/schema 9.0.2 → 10.0.0-alpha.1
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/README.md +6 -6
- package/package.json +4 -1
- package/CHANGELOG.md +0 -63
- package/src/__benchmarks__/conversion.bench.ts +0 -88
- package/src/__tests__/conversion.spec.ts +0 -502
- package/src/__tests__/openapi.spec.ts +0 -396
- package/src/__tests__/parser.spec.ts +0 -236
- package/src/conversion.ts +0 -220
- package/src/index.ts +0 -15
- package/src/openapi.ts +0 -75
- package/src/parser.ts +0 -30
- package/src/types.ts +0 -37
- package/tsconfig.json +0 -9
- package/tsdown.config.ts +0 -5
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ import { z } from 'zod';
|
|
|
73
73
|
// Define a schema
|
|
74
74
|
const userSchema = z.object({
|
|
75
75
|
id: z.string(),
|
|
76
|
-
email: z.
|
|
76
|
+
email: z.email(),
|
|
77
77
|
age: z.number().min(18),
|
|
78
78
|
role: z.enum(['admin', 'user'])
|
|
79
79
|
});
|
|
@@ -130,7 +130,7 @@ import { z } from 'zod';
|
|
|
130
130
|
const schemas = {
|
|
131
131
|
user: z.object({
|
|
132
132
|
id: z.string(),
|
|
133
|
-
email: z.
|
|
133
|
+
email: z.email()
|
|
134
134
|
}),
|
|
135
135
|
post: z.object({
|
|
136
136
|
id: z.string(),
|
|
@@ -237,7 +237,7 @@ import { z } from 'zod';
|
|
|
237
237
|
const createUserEndpoint = {
|
|
238
238
|
body: z.object({
|
|
239
239
|
name: z.string().min(1),
|
|
240
|
-
email: z.
|
|
240
|
+
email: z.email(),
|
|
241
241
|
age: z.number().int().min(18)
|
|
242
242
|
}),
|
|
243
243
|
response: z.object({
|
|
@@ -272,7 +272,7 @@ import { z } from 'zod';
|
|
|
272
272
|
|
|
273
273
|
const userSchema = z.object({
|
|
274
274
|
id: z.string(),
|
|
275
|
-
email: z.
|
|
275
|
+
email: z.email()
|
|
276
276
|
});
|
|
277
277
|
|
|
278
278
|
type User = InferStandardSchema<typeof userSchema>;
|
|
@@ -296,11 +296,11 @@ if (isUser(data)) {
|
|
|
296
296
|
This package is used internally by `@geekmidas/constructs` for type-safe endpoint validation:
|
|
297
297
|
|
|
298
298
|
```typescript
|
|
299
|
-
import {
|
|
299
|
+
import { api } from '../constructs/api';
|
|
300
300
|
import { z } from 'zod';
|
|
301
301
|
|
|
302
302
|
// The constructs package uses InferStandardSchema internally
|
|
303
|
-
const endpoint =
|
|
303
|
+
const endpoint = api
|
|
304
304
|
.post('/users')
|
|
305
305
|
.body(z.object({ name: z.string() }))
|
|
306
306
|
.output(z.object({ id: z.string() }))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/schema",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -44,6 +44,9 @@
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
47
50
|
"repository": {
|
|
48
51
|
"type": "git",
|
|
49
52
|
"url": "https://github.com/geekmidas/toolbox"
|
package/CHANGELOG.md
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# @geekmidas/schema
|
|
2
|
-
|
|
3
|
-
## 9.0.2
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- [#12](https://github.com/geekmidas/toolbox/pull/12) [`d53863a`](https://github.com/geekmidas/toolbox/commit/d53863a84db2e4ab5420e08f79128b637043fc42) Thanks [@geekmidas](https://github.com/geekmidas)! - Align every published package on a single version and keep them in step.
|
|
8
|
-
|
|
9
|
-
All packages now share one version, enforced by a changesets `fixed` group. The
|
|
10
|
-
baseline is 9.0.1 — @geekmidas/client's published version — so nothing moves
|
|
11
|
-
backwards; this release takes the whole set to 9.0.2 together.
|
|
12
|
-
|
|
13
|
-
Independent versions made "which version of the docs applies to me"
|
|
14
|
-
unanswerable: a reader on constructs@7 and cli@2 was on no version at all. One
|
|
15
|
-
number per release makes versioned documentation possible, and lets 9 freeze as
|
|
16
|
-
the current paradigm while the constructs rework is developed against it.
|
|
17
|
-
|
|
18
|
-
Every release now publishes every package, and a major anywhere is a major
|
|
19
|
-
everywhere. Peer ranges get simpler in return.
|
|
20
|
-
|
|
21
|
-
## 1.0.4
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
24
|
-
|
|
25
|
-
- 🐛 [#11](https://github.com/geekmidas/toolbox/pull/11) [`40f4dc0`](https://github.com/geekmidas/toolbox/commit/40f4dc095911b2223a255029d8f776caf7781309) Thanks [@geekmidas](https://github.com/geekmidas)! - Patch release across all packages to realign published versions with the
|
|
26
|
-
registry. The previous release only published the four packages that had
|
|
27
|
-
version bumps; the remaining packages failed with "cannot publish over the
|
|
28
|
-
previously published versions" because their versions were unchanged.
|
|
29
|
-
|
|
30
|
-
## 1.0.3
|
|
31
|
-
|
|
32
|
-
### Patch Changes
|
|
33
|
-
|
|
34
|
-
- [#7](https://github.com/geekmidas/toolbox/pull/7) [`e0d06b3`](https://github.com/geekmidas/toolbox/commit/e0d06b38dfd275758f7955f5754900ab78779302) Thanks [@geekmidas](https://github.com/geekmidas)! - feat(constructs): allow endpoint handlers to return the output schema's input type
|
|
35
|
-
|
|
36
|
-
Endpoint handlers previously had to return the output schema's _parsed_ type
|
|
37
|
-
(`InferStandardSchema`). When an output schema coerces its value (e.g. a `Date`
|
|
38
|
-
serialized to an ISO `string`, or an applied default), that forced handlers to
|
|
39
|
-
pre-coerce values themselves even though the schema would do it on the way out.
|
|
40
|
-
|
|
41
|
-
A new `InferStandardSchemaInput` type is added to `@geekmidas/schema`, exposing a
|
|
42
|
-
Standard Schema's _input_ type (`StandardSchemaV1.InferInput`). `Endpoint`'s
|
|
43
|
-
handler return type now uses it, so handlers may return the looser pre-coercion
|
|
44
|
-
input while consumers (`EndpointOutput` and the generated client) still see the
|
|
45
|
-
narrower parsed output type.
|
|
46
|
-
|
|
47
|
-
## 1.0.2
|
|
48
|
-
|
|
49
|
-
### Patch Changes
|
|
50
|
-
|
|
51
|
-
- 🐛 [`d70c6c0`](https://github.com/geekmidas/toolbox/commit/d70c6c0aeb8a79da2473ac77dbd8255a4a2f5651) Thanks [@geekmidas](https://github.com/geekmidas)! - Fix `package.json` exports so TypeScript declarations resolve correctly under NodeNext/Bundler module resolution. Each subpath export now nests `types` inside its `import`/`require` condition, pointing at the `.d.mts` and `.d.cts` files that `tsdown` actually emits (previously the exports referenced non-existent `.d.ts` files, causing type-resolution failures for consumers). Both ESM (`.mjs`) and CJS (`.cjs`) runtime entry points are preserved. Additionally, `@geekmidas/ui` had `import` paths pointing at `.js` files that were never emitted — those are corrected to `.mjs`.
|
|
52
|
-
|
|
53
|
-
## 1.0.1
|
|
54
|
-
|
|
55
|
-
### Patch Changes
|
|
56
|
-
|
|
57
|
-
- 🐛 [`aeba918`](https://github.com/geekmidas/toolbox/commit/aeba918fc258f6ccdb96b8273b2bc01bd2190553) Thanks [@geekmidas](https://github.com/geekmidas)! - Fix schema, openapi generation and events testkit
|
|
58
|
-
|
|
59
|
-
## 1.0.0
|
|
60
|
-
|
|
61
|
-
### Major Changes
|
|
62
|
-
|
|
63
|
-
- [`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8) Thanks [@geekmidas](https://github.com/geekmidas)! - Version 1 Stable release
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { bench, describe } from 'vitest';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { convertStandardSchemaToJsonSchema } from '../conversion';
|
|
4
|
-
|
|
5
|
-
describe('Schema Conversion - Simple', () => {
|
|
6
|
-
const simpleSchema = z.object({
|
|
7
|
-
id: z.string(),
|
|
8
|
-
name: z.string(),
|
|
9
|
-
email: z.string().email(),
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
bench('simple object schema', async () => {
|
|
13
|
-
await convertStandardSchemaToJsonSchema(simpleSchema);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const primitiveSchema = z.string();
|
|
17
|
-
bench('primitive string schema', async () => {
|
|
18
|
-
await convertStandardSchemaToJsonSchema(primitiveSchema);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const arraySchema = z.array(z.string());
|
|
22
|
-
bench('array of strings schema', async () => {
|
|
23
|
-
await convertStandardSchemaToJsonSchema(arraySchema);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('Schema Conversion - Complex', () => {
|
|
28
|
-
const nestedSchema = z.object({
|
|
29
|
-
user: z.object({
|
|
30
|
-
profile: z.object({
|
|
31
|
-
name: z.string(),
|
|
32
|
-
bio: z.string().optional(),
|
|
33
|
-
settings: z.record(z.string(), z.unknown()),
|
|
34
|
-
}),
|
|
35
|
-
contacts: z.array(
|
|
36
|
-
z.object({
|
|
37
|
-
type: z.enum(['email', 'phone']),
|
|
38
|
-
value: z.string(),
|
|
39
|
-
}),
|
|
40
|
-
),
|
|
41
|
-
}),
|
|
42
|
-
metadata: z.object({
|
|
43
|
-
createdAt: z.string(),
|
|
44
|
-
updatedAt: z.string(),
|
|
45
|
-
}),
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
bench('deeply nested schema', async () => {
|
|
49
|
-
await convertStandardSchemaToJsonSchema(nestedSchema);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const unionSchema = z.discriminatedUnion('type', [
|
|
53
|
-
z.object({ type: z.literal('text'), content: z.string() }),
|
|
54
|
-
z.object({ type: z.literal('image'), url: z.string() }),
|
|
55
|
-
z.object({
|
|
56
|
-
type: z.literal('video'),
|
|
57
|
-
url: z.string(),
|
|
58
|
-
duration: z.number(),
|
|
59
|
-
}),
|
|
60
|
-
]);
|
|
61
|
-
|
|
62
|
-
bench('discriminated union schema', async () => {
|
|
63
|
-
await convertStandardSchemaToJsonSchema(unionSchema);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const largeSchema = z.object(
|
|
67
|
-
Object.fromEntries(
|
|
68
|
-
Array.from({ length: 50 }, (_, i) => [`field${i}`, z.string()]),
|
|
69
|
-
),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
bench('large object (50 fields)', async () => {
|
|
73
|
-
await convertStandardSchemaToJsonSchema(largeSchema);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe('Schema Conversion - With Refinements', () => {
|
|
78
|
-
const refinedSchema = z.object({
|
|
79
|
-
age: z.number().min(0).max(150),
|
|
80
|
-
email: z.string().email(),
|
|
81
|
-
url: z.string().url(),
|
|
82
|
-
uuid: z.string().uuid(),
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
bench('schema with refinements', async () => {
|
|
86
|
-
await convertStandardSchemaToJsonSchema(refinedSchema);
|
|
87
|
-
});
|
|
88
|
-
});
|