@codexsploitx/schemaapi 1.0.1 → 1.0.2

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/LICENSE +21 -0
  2. package/package.json +1 -1
  3. package/readme.md +125 -48
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 CodexSploitx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codexsploitx/schemaapi",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Type-safe API contracts (HTTP/WebSocket) with adapters, client and docs generator.",
5
5
  "main": "dist/schemaapi.cjs.js",
6
6
  "module": "dist/schemaapi.esm.js",
package/readme.md CHANGED
@@ -1,61 +1,70 @@
1
+ <div align="center">
2
+
1
3
  # SchemaApi
2
4
 
3
- > El Zod de las APIs
4
- > No reemplaza tu stack. Lo hace confiable.
5
+ **The Zod of APIs**
6
+ *Type-safe contracts. Runtime validation. Auto-generated docs.*
5
7
 
6
- SchemaApi es una librería de **contratos para APIs**.
7
- No sustituye Express, Fastify, Next.js, Axios ni Fetch.
8
- Se coloca **encima** de ellos como una capa de validación, coherencia y arquitectura.
8
+ [![npm version](https://img.shields.io/npm/v/schemaapi?style=flat-square&color=blue)](https://www.npmjs.com/package/schemaapi)
9
+ [![License](https://img.shields.io/npm/l/schemaapi?style=flat-square&color=green)](LICENSE)
10
+ [![Tests](https://img.shields.io/github/actions/workflow/status/CodexSploitx/SchemaApi/test.yml?label=tests&style=flat-square)](https://github.com/CodexSploitx/SchemaApi/actions)
11
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
9
12
 
10
- ---
13
+ [Features](#-features) • [Installation](#-installation) • [Usage](#-usage) • [Adapters](#-adapters) • [Documentation](#-documentation)
11
14
 
12
- ## 🧠 Filosofía
15
+ </div>
13
16
 
14
- > “Tu API no es tu código.
15
- > Tu API es el contrato que prometes al mundo.”
17
+ ---
16
18
 
17
- SchemaApi convierte ese contrato en:
18
- - Código tipado
19
- - Validación runtime
20
- - Seguridad (roles y errores tipados)
21
- - Documentación (vía CLI y contrato)
22
- - SDK de cliente básico
23
- - Tests (unitarios y de contrato)
19
+ ## 🚀 Why SchemaApi?
24
20
 
25
- ---
21
+ **Your API is a contract.** But in most codebases, that contract is broken into pieces:
22
+ - Validation logic in controllers.
23
+ - Types in a `types.ts` file.
24
+ - Documentation in a stale Swagger file.
25
+ - Client SDKs handwritten (and buggy).
26
26
 
27
- ## Lo que hace SchemaApi hoy
27
+ **SchemaApi** unifies everything into a **Single Source of Truth**. Define your contract once, and get everything else for free.
28
28
 
29
- - Valida rutas, métodos HTTP y parámetros
30
- - Valida query, body y headers
31
- - Controla roles y autenticación
32
- - Valida responses y errores (incluye status codes definidos en el contrato)
33
- - Expone un contrato único fuente de verdad para docs/SDK/tests
34
- - Ofrece un cliente JS/TS básico vía `createClient`
35
- - Proporciona una CLI mínima (`schemaapi`) para orquestar generación de docs/SDK/tests
36
- - Versionado de API con detección de breaking changes
29
+ > "It doesn't replace your framework. It makes it invincible."
37
30
 
38
31
  ---
39
32
 
40
- ## Lo que NO hace
33
+ ## Features
41
34
 
42
- - No transporta datos (usa Fetch / Axios)
43
- - No reemplaza tu framework (Express / Next / Fastify)
44
- - No maneja DB ni ORM
45
- - No es un servidor
35
+ | Feature | Description |
36
+ | :--- | :--- |
37
+ | **🛡️ End-to-End Type Safety** | Types flow from your server contract directly to your client SDK. No code generation required. |
38
+ | **⚡ Runtime Validation** | Powered by **[Zod](https://zod.dev)**. Automatically validates params, query, body, and headers. |
39
+ | **🔐 Built-in Security** | Define `roles` and `scopes` directly in your contract. RBAC made simple. |
40
+ | **📚 Auto Documentation** | Generate beautiful, interactive HTML documentation that never drifts from code. |
41
+ | **🔌 Framework Agnostic** | Works with Express, Next.js, Fastify, Remix, NestJS, and more. |
42
+ | **📦 Zero-Config SDK** | Export a fully typed client that handles methods, paths, and errors for you. |
46
43
 
47
44
  ---
48
45
 
49
- ## 🌐 Instalación
46
+ ## 📦 Installation
50
47
 
51
48
  ```bash
52
- npm install schemaapi
53
- # o
54
- yarn add schemaapi
49
+ # npm
50
+ npm install schemaapi zod
51
+
52
+ # pnpm
53
+ pnpm add schemaapi zod
55
54
 
55
+ # yarn
56
+ yarn add schemaapi zod
57
+ ```
56
58
 
57
- 🧩 Ejemplo básico
59
+ ---
60
+
61
+ ## 🛠 Usage
62
+
63
+ ### 1️⃣ Define the Contract
58
64
 
65
+ Create a shared file (e.g., `contract.ts`). This is your API's law.
66
+
67
+ ```typescript
59
68
  import { createContract } from "schemaapi";
60
69
  import { z } from "zod";
61
70
 
@@ -63,27 +72,95 @@ export const contract = createContract({
63
72
  "/users/:id": {
64
73
  GET: {
65
74
  params: z.object({ id: z.string().uuid() }),
66
- headers: z.object({ authorization: z.string() }),
67
- roles: ["user", "admin"],
68
75
  response: z.object({
69
76
  id: z.string(),
70
- username: z.string(),
71
- email: z.string().email()
77
+ name: z.string(),
78
+ email: z.string().email(),
72
79
  }),
73
- errors: { 401: "UNAUTHORIZED", 404: "USER_NOT_FOUND" }
74
- }
75
- }
80
+ errors: {
81
+ 404: "USER_NOT_FOUND",
82
+ },
83
+ },
84
+ },
76
85
  });
86
+ ```
77
87
 
88
+ ### 2️⃣ Implement the Server
78
89
 
90
+ Use the `handle` method to implement the logic. SchemaApi ensures you return exactly what the contract promises.
79
91
 
80
- 🛠 Integración con Express
92
+ ```typescript
93
+ import express from "express";
94
+ import { contract } from "./contract";
95
+
96
+ const app = express();
81
97
 
82
98
  app.get(
83
99
  "/users/:id",
84
- contract.handle("GET /users/:id", async (ctx) => {
85
- const user = await db.findUser(ctx.params.id);
86
- return user; // Validación automática
100
+ contract.handle("GET /users/:id", async ({ params }) => {
101
+ // `params.id` is strictly typed as a UUID string
102
+ const user = await db.users.find(params.id);
103
+
104
+ if (!user) {
105
+ throw { status: 404, message: "User not found" };
106
+ }
107
+
108
+ // TypeScript ensures this return value matches the contract
109
+ return user;
87
110
  })
88
111
  );
89
- # SchemaApi
112
+ ```
113
+
114
+ ### 3️⃣ Consume with Client SDK
115
+
116
+ No more manual fetch calls. No more `any`.
117
+
118
+ ```typescript
119
+ import { createClient } from "schemaapi";
120
+ import { contract } from "./shared/contract";
121
+
122
+ const client = createClient(contract, {
123
+ baseUrl: "https://api.example.com"
124
+ });
125
+
126
+ // Full autocomplete & type checking
127
+ const user = await client.users.get({
128
+ id: "550e8400-e29b-41d4-a716-446655440000"
129
+ });
130
+
131
+ console.log(user.email); // ✅ Typed!
132
+ ```
133
+
134
+ ---
135
+
136
+ ## 🔌 Adapters Ecosystem
137
+
138
+ SchemaApi is designed to drop into any stack.
139
+
140
+ | Adapter | Status | Package Support |
141
+ | :--- | :---: | :--- |
142
+ | <img src="https://raw.githubusercontent.com/expressjs/expressjs.com/gh-pages/images/favicon.png" width="20" /> **Express** | ✅ Stable | Native support |
143
+ | <img src="https://assets.vercel.com/image/upload/v1662130559/nextjs/Icon_dark_background.png" width="20" /> **Next.js** | ✅ Stable | API Routes & App Router |
144
+ | <img src="https://raw.githubusercontent.com/fastify/graphics/master/fastify-icon.png" width="20" /> **Fastify** | ✅ Stable | High performance |
145
+ | <img src="https://github.com/remix-run/branding/raw/main/remix-r.png" width="20" /> **Remix** | ✅ Stable | Loaders & Actions |
146
+ | <img src="https://nestjs.com/img/logo-small.svg" width="20" /> **NestJS** | ✅ Stable | Decorators |
147
+ | <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Deno.svg/1200px-Deno.svg.png" width="20" /> **Deno** | ✅ Stable | Native HTTP |
148
+ | ⚡ **WebSocket** | 🚧 Beta | Real-time contracts |
149
+
150
+ ---
151
+
152
+ ## 📚 Documentation Generator
153
+
154
+ Stop writing Swagger files manually. Generate a stunning static documentation site with one command.
155
+
156
+ ```bash
157
+ npx schemaapi generate docs --out ./docs
158
+ ```
159
+
160
+ It creates a fully responsive, dark-mode ready HTML dashboard showing all your routes, schemas, and types.
161
+
162
+ ---
163
+
164
+ ## 📄 License
165
+
166
+ MIT © [CodexSploitx](https://github.com/CodexSploitx)