@hedystia/validations 1.2.7 → 1.2.9

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 (3) hide show
  1. package/dist/index.d.ts +72 -0
  2. package/package.json +1 -1
  3. package/readme.md +167 -167
package/dist/index.d.ts CHANGED
@@ -126,21 +126,93 @@ declare class ObjectSchemaType<T extends Record<string, unknown>> extends BaseSc
126
126
  }
127
127
  type AnySchema = SchemaPrimitive | BaseSchema<any, any> | SchemaDefinition;
128
128
  declare function toStandard<T>(schema: AnySchema): Schema<unknown, T>;
129
+ /**
130
+ * Create standard schema types
131
+ * @returns {typeof h} Standard schema types
132
+ */
129
133
  declare const h: {
134
+ /**
135
+ * Create string schema type
136
+ * @returns {StringSchemaType} String schema type
137
+ */
130
138
  string: () => StringSchemaType;
139
+ /**
140
+ * Create number schema type
141
+ * @returns {NumberSchemaType} Number schema type
142
+ */
131
143
  number: () => NumberSchemaType;
144
+ /**
145
+ * Create boolean schema type
146
+ * @returns {BooleanSchemaType} Boolean schema type
147
+ */
132
148
  boolean: () => BooleanSchemaType;
149
+ /**
150
+ * Create null schema type
151
+ * @returns {NullSchemaType} Null schema type
152
+ */
133
153
  null: () => NullSchemaType;
154
+ /**
155
+ * Create any schema type
156
+ * @returns {AnySchemaType} Any schema type
157
+ */
134
158
  any: () => AnySchemaType;
159
+ /**
160
+ * Create literal schema type
161
+ * @param {T} value - Literal value
162
+ * @returns {LiteralSchema<T>} Literal schema type
163
+ */
135
164
  literal: <T extends string | number | boolean>(value: T) => LiteralSchema<T>;
165
+ /**
166
+ * Create object schema type
167
+ * @param {S} [schemaDef] - Schema definition
168
+ * @returns {ObjectSchemaType<InferObject<S>>} Object schema type
169
+ */
136
170
  object: <S extends SchemaDefinition>(schemaDef?: S) => ObjectSchemaType<InferObject<S>>;
171
+ /**
172
+ * Create array schema type
173
+ * @param {S} schema - Schema
174
+ * @returns {ArraySchema<unknown, InferSchema<S>[]>} Array schema type
175
+ */
137
176
  array: <S extends AnySchema>(schema: S) => ArraySchema<unknown, InferSchema<S>[]>;
177
+ /**
178
+ * Create enum schema type
179
+ * @param {T} values - Enum values
180
+ * @returns {EnumSchema<unknown, T[number]>} Enum schema type
181
+ */
138
182
  enum: <T extends readonly [any, ...any[]]>(values: T) => EnumSchema<unknown, T[number]>;
183
+ /**
184
+ * Create optional schema type
185
+ * @param {S} schema - Schema
186
+ * @returns {OptionalSchema<unknown, InferSchema<S> | undefined>} Optional schema type
187
+ */
139
188
  optional: <S extends AnySchema>(schema: S) => OptionalSchema<unknown, InferSchema<S> | undefined>;
189
+ /**
190
+ * Create options schema type
191
+ * @param {S} schemas - Schemas
192
+ * @returns {UnionSchema<unknown, InferSchema<S[number]>>} Options schema type
193
+ */
140
194
  options: <S extends AnySchema[]>(...schemas: S) => UnionSchema<unknown, InferSchema<S[number]>>;
195
+ /**
196
+ * Create instance of schema type
197
+ * @param {C} constructor - Constructor function
198
+ * @returns {InstanceOfSchema<unknown, InstanceType<C>>} Instance of schema type
199
+ */
141
200
  instanceOf: <C extends new (...args: any[]) => any>(constructor: C) => InstanceOfSchema<unknown, InstanceType<C>>;
201
+ /**
202
+ * Create email schema type
203
+ * @returns {StringSchemaType} Email schema type
204
+ */
142
205
  email: () => StringSchemaType;
206
+ /**
207
+ * Create phone schema type
208
+ * @returns {StringSchemaType} Phone schema type
209
+ */
143
210
  phone: () => StringSchemaType;
211
+ /**
212
+ * Convert schema to standard schema
213
+ * @param {AnySchema} schema - Schema
214
+ * @returns {Schema<unknown, any>} Standard schema
215
+ */
144
216
  toStandard: typeof toStandard;
145
217
  };
146
218
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hedystia/validations",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "devDependencies": {
5
5
  "@standard-schema/spec": "^1.0.0",
6
6
  "@types/bun": "latest",
package/readme.md CHANGED
@@ -1,167 +1,167 @@
1
- <div align="center">
2
- <p>
3
- <strong>🚀 Hedystia Framework</strong>
4
- </p>
5
-
6
- <p>
7
- <strong>Next-gen TypeScript framework for building type-safe APIs at lightspeed! ⚡</strong>
8
- </p>
9
-
10
- <p>
11
- <a href="https://www.npmjs.com/package/hedystia"><img src="https://img.shields.io/npm/v/hedystia.svg?style=flat-square" alt="npm version"></a>
12
- <a href="https://www.npmjs.com/package/hedystia"><img src="https://img.shields.io/npm/dm/hedystia.svg?style=flat-square" alt="npm downloads"></a>
13
- <a href="LICENSE"><img src="https://img.shields.io/github/license/Hedystia/Framework.svg?style=flat-square" alt="license"></a>
14
- <img src="https://img.shields.io/badge/Bun-powered-FFD43B?style=flat-square&logo=bun" alt="Bun powered">
15
- </p>
16
- </div>
17
-
18
- ## 🚨 Early Access Notice
19
- > **Warning**
20
- > Framework is in active development. Core features are stable but some advanced functionality still being implemented.
21
-
22
- ## 🌟 Superpowers
23
-
24
- - 🌐 **Multi-runtime support** - Bun (default), Deno, Node.js, Vercel, Cloudflare Workers, Fastly Compute, Lambda, etc.
25
- - 🔒 **End-to-end type safety** - From params to response, full TypeScript integration
26
- - ⚡ **Bun-native performance** - Built for Bun runtime with native validation
27
- - 🧩 **Client integration** - Auto-generated type-safe HTTP client
28
- - 🛡️ **Validation built-in** - Zod integration for runtime safety
29
- - 🔌 **Extensible architecture** - Middleware, hooks and macros system
30
- - 📝 **Standard Schema** - Compatibility with the standard schema so you can use it with Zod, Arktype, etc.
31
-
32
- ## 🚀 Launch in 30 Seconds
33
-
34
- 1. Install with Bun:
35
- ```bash
36
- bun add hedystia
37
- ```
38
-
39
- 2. Create your first API:
40
- ```typescript
41
- import { Hedystia, h } from "hedystia";
42
-
43
- const app = new Hedystia()
44
- .get("/hello/:name", (ctx) => `Hello ${ctx.params.name}!`, {
45
- params: h.object({ name: h.string() }),
46
- response: h.string()
47
- })
48
- .listen(3000);
49
- ```
50
-
51
- 3. Generate client and consume API:
52
- ```typescript
53
- import { createClient } from "@hedystia/client";
54
-
55
- const client = createClient<typeof app>("http://localhost:3000");
56
-
57
- // Fully typed request!
58
- const { data } = await client.hello.name("World").get();
59
- console.log(data); // "Hello World!"
60
- ```
61
-
62
- ## 💡 Why Developers Love Hedystia
63
-
64
- ### 🔄 Full-stack Type Safety
65
- ```typescript
66
- // Server-side validation
67
- .post("/users", (ctx) => {...}, {
68
- body: h.object({
69
- email: h.email(),
70
- age: h.number()
71
- })
72
- })
73
-
74
- // Client-side types
75
- await client.users.post({
76
- email: "user@example.com", // Autocompletes!
77
- age: 25 // Type-checked
78
- });
79
- ```
80
-
81
- ### 📖 Swagger Integration
82
-
83
- ```typescript
84
- import { swagger } from "@hedystia/swagger";
85
-
86
- const swaggerPlugin = swagger({
87
- title: "My API",
88
- description: "An example API with Swagger",
89
- version: "1.0.0",
90
- tags: [
91
- { name: "users", description: "User operations" },
92
- ],
93
- });
94
-
95
- swaggerPlugin.captureRoutes(app);
96
-
97
- app.use("/swagger", swaggerPlugin.plugin).listen(3000);
98
- ```
99
-
100
- ### ⚡ Performance First
101
- - Bun runtime optimized
102
- - Faster by default
103
- - Own type validation system
104
- - Faster than Express
105
- - Built-in response compression
106
-
107
- ### 🧩 Modern Feature Set
108
- ```typescript
109
- // File uploads
110
- .post("/upload", async (ctx) => {
111
- const formData = await ctx.body; // FormData type
112
- })
113
-
114
- // Binary responses
115
- .get("/pdf", () => new Blob([...]), {
116
- response: h.instanceof(Blob)
117
- })
118
-
119
- // Nested routing
120
- .group("/api/v1", (v1) => v1
121
- .group("/users", (users) => users
122
- .get("/:id", ...)
123
- )
124
- )
125
- ```
126
-
127
- ## 🛠️ Development Roadmap
128
-
129
- ### Core Features
130
- - ✅ HTTP Methods: GET, POST, PUT, PATCH, DELETE
131
- - ✅ Response Types: JSON, Text, FormData, Blob, ArrayBuffer
132
- - ✅ Router Groups & Middleware
133
- - ✅ Type-safe Client Generation
134
- - ✅ WebSocket Support
135
- - ✅ Adapter System to work with other frameworks
136
-
137
- ### Advanced Capabilities
138
- - ✅ Standard Schema Compatibility
139
- - ✅ Hooks System (onRequest, onError, etc)
140
- - ✅ Macro System for Auth/Rate Limiting
141
- - ✅ OpenAPI - Swagger Integration
142
-
143
- ## 💼 Production Ready
144
- ```typescript
145
- // Error handling
146
- .onError((err) => {
147
- return Response.json({
148
- error: err.message
149
- }, { status: 500 })
150
- })
151
-
152
- // Rate limiting macro
153
- .macro({
154
- rateLimit: () => ({
155
- resolve: async (ctx) => {
156
- // Implement your logic
157
- }
158
- })
159
- })
160
- ```
161
-
162
- ## 📜 License
163
- MIT License © 2025 Hedystia
164
-
165
- ## 🗣️ Community
166
- - [GitHub Issues](https://github.com/Hedystia/Framework/issues)
167
- - [Discord Server](https://hedystia.com/support)
1
+ <div align="center">
2
+ <p>
3
+ <strong>🚀 Hedystia Framework</strong>
4
+ </p>
5
+
6
+ <p>
7
+ <strong>Next-gen TypeScript framework for building type-safe APIs at lightspeed! ⚡</strong>
8
+ </p>
9
+
10
+ <p>
11
+ <a href="https://www.npmjs.com/package/hedystia"><img src="https://img.shields.io/npm/v/hedystia.svg?style=flat-square" alt="npm version"></a>
12
+ <a href="https://www.npmjs.com/package/hedystia"><img src="https://img.shields.io/npm/dm/hedystia.svg?style=flat-square" alt="npm downloads"></a>
13
+ <a href="LICENSE"><img src="https://img.shields.io/github/license/Hedystia/Framework.svg?style=flat-square" alt="license"></a>
14
+ <img src="https://img.shields.io/badge/Bun-powered-FFD43B?style=flat-square&logo=bun" alt="Bun powered">
15
+ </p>
16
+ </div>
17
+
18
+ ## 🚨 Early Access Notice
19
+ > **Warning**
20
+ > Framework is in active development. Core features are stable but some advanced functionality still being implemented.
21
+
22
+ ## 🌟 Superpowers
23
+
24
+ - 🌐 **Multi-runtime support** - Bun (default), Deno, Node.js, Vercel, Cloudflare Workers, Fastly Compute, Lambda, etc.
25
+ - 🔒 **End-to-end type safety** - From params to response, full TypeScript integration
26
+ - ⚡ **Bun-native performance** - Built for Bun runtime with native validation
27
+ - 🧩 **Client integration** - Auto-generated type-safe HTTP client
28
+ - 🛡️ **Validation built-in** - Zod integration for runtime safety
29
+ - 🔌 **Extensible architecture** - Middleware, hooks and macros system
30
+ - 📝 **Standard Schema** - Compatibility with the standard schema so you can use it with Zod, Arktype, etc.
31
+
32
+ ## 🚀 Launch in 30 Seconds
33
+
34
+ 1. Install with Bun:
35
+ ```bash
36
+ bun add hedystia
37
+ ```
38
+
39
+ 2. Create your first API:
40
+ ```typescript
41
+ import { Hedystia, h } from "hedystia";
42
+
43
+ const app = new Hedystia()
44
+ .get("/hello/:name", (ctx) => `Hello ${ctx.params.name}!`, {
45
+ params: h.object({ name: h.string() }),
46
+ response: h.string()
47
+ })
48
+ .listen(3000);
49
+ ```
50
+
51
+ 3. Generate client and consume API:
52
+ ```typescript
53
+ import { createClient } from "@hedystia/client";
54
+
55
+ const client = createClient<typeof app>("http://localhost:3000");
56
+
57
+ // Fully typed request!
58
+ const { data } = await client.hello.name("World").get();
59
+ console.log(data); // "Hello World!"
60
+ ```
61
+
62
+ ## 💡 Why Developers Love Hedystia
63
+
64
+ ### 🔄 Full-stack Type Safety
65
+ ```typescript
66
+ // Server-side validation
67
+ .post("/users", (ctx) => {...}, {
68
+ body: h.object({
69
+ email: h.email(),
70
+ age: h.number()
71
+ })
72
+ })
73
+
74
+ // Client-side types
75
+ await client.users.post({
76
+ email: "user@example.com", // Autocompletes!
77
+ age: 25 // Type-checked
78
+ });
79
+ ```
80
+
81
+ ### 📖 Swagger Integration
82
+
83
+ ```typescript
84
+ import { swagger } from "@hedystia/swagger";
85
+
86
+ const swaggerPlugin = swagger({
87
+ title: "My API",
88
+ description: "An example API with Swagger",
89
+ version: "1.0.0",
90
+ tags: [
91
+ { name: "users", description: "User operations" },
92
+ ],
93
+ });
94
+
95
+ swaggerPlugin.captureRoutes(app);
96
+
97
+ app.use("/swagger", swaggerPlugin.plugin).listen(3000);
98
+ ```
99
+
100
+ ### ⚡ Performance First
101
+ - Bun runtime optimized
102
+ - Faster by default
103
+ - Own type validation system
104
+ - Faster than Express
105
+ - Built-in response compression
106
+
107
+ ### 🧩 Modern Feature Set
108
+ ```typescript
109
+ // File uploads
110
+ .post("/upload", async (ctx) => {
111
+ const formData = await ctx.body; // FormData type
112
+ })
113
+
114
+ // Binary responses
115
+ .get("/pdf", () => new Blob([...]), {
116
+ response: h.instanceof(Blob)
117
+ })
118
+
119
+ // Nested routing
120
+ .group("/api/v1", (v1) => v1
121
+ .group("/users", (users) => users
122
+ .get("/:id", ...)
123
+ )
124
+ )
125
+ ```
126
+
127
+ ## 🛠️ Development Roadmap
128
+
129
+ ### Core Features
130
+ - ✅ HTTP Methods: GET, POST, PUT, PATCH, DELETE
131
+ - ✅ Response Types: JSON, Text, FormData, Blob, ArrayBuffer
132
+ - ✅ Router Groups & Middleware
133
+ - ✅ Type-safe Client Generation
134
+ - ✅ WebSocket Support
135
+ - ✅ Adapter System to work with other frameworks
136
+
137
+ ### Advanced Capabilities
138
+ - ✅ Standard Schema Compatibility
139
+ - ✅ Hooks System (onRequest, onError, etc)
140
+ - ✅ Macro System for Auth/Rate Limiting
141
+ - ✅ OpenAPI - Swagger Integration
142
+
143
+ ## 💼 Production Ready
144
+ ```typescript
145
+ // Error handling
146
+ .onError((err) => {
147
+ return Response.json({
148
+ error: err.message
149
+ }, { status: 500 })
150
+ })
151
+
152
+ // Rate limiting macro
153
+ .macro({
154
+ rateLimit: () => ({
155
+ resolve: async (ctx) => {
156
+ // Implement your logic
157
+ }
158
+ })
159
+ })
160
+ ```
161
+
162
+ ## 📜 License
163
+ MIT License © 2025 Hedystia
164
+
165
+ ## 🗣️ Community
166
+ - [GitHub Issues](https://github.com/Hedystia/Framework/issues)
167
+ - [Discord Server](https://hedystia.com/support)