@codexsploitx/schemaapi 1.0.3 → 1.0.5

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/bin/schemaapi +36 -1
  2. package/package.json +1 -1
  3. package/readme.md +132 -7
package/bin/schemaapi CHANGED
@@ -23,6 +23,14 @@ function showHelp() {
23
23
  console.log(" schemaapi generate tests");
24
24
  console.log(" schemaapi audit");
25
25
  console.log(" schemaapi init <adapter>");
26
+ console.log("");
27
+ console.log("Adapters:");
28
+ console.log(" express");
29
+ console.log(" next");
30
+ console.log(" fastify");
31
+ console.log(" remix");
32
+ console.log(" nest");
33
+ console.log(" deno");
26
34
  }
27
35
 
28
36
  function loadConfig() {
@@ -228,7 +236,7 @@ function handleInit(adapterArg) {
228
236
  const usersContractPath = path.join(contractsDir, "usersContract.ts");
229
237
  if (!fs.existsSync(usersContractPath)) {
230
238
  const usersContractContent = [
231
- 'import { createContract } from "schemaapi";',
239
+ 'import { createContract } from "@codexsploitx/schemaapi";',
232
240
  'import { z } from "zod";',
233
241
  "",
234
242
  "export const usersContract = createContract({",
@@ -249,6 +257,33 @@ function handleInit(adapterArg) {
249
257
  fs.writeFileSync(indexPath, 'export * from "./usersContract";\n');
250
258
  }
251
259
 
260
+ if (adapter === "next") {
261
+ const appApiUsersDir = path.join(cwd, "app", "api", "users");
262
+ if (!fs.existsSync(appApiUsersDir)) {
263
+ fs.mkdirSync(appApiUsersDir, { recursive: true });
264
+ }
265
+ const routePath = path.join(appApiUsersDir, "route.ts");
266
+ if (!fs.existsSync(routePath)) {
267
+ const nextRouteContent = [
268
+ 'import { adapters } from "@codexsploitx/schemaapi";',
269
+ 'import { usersContract } from "../../../contracts";',
270
+ "",
271
+ "const handlers = adapters.next.handleContract(usersContract, {",
272
+ ' "GET /users/:id": async ({ params }) => {',
273
+ " return {",
274
+ " id: String(params && params.id),",
275
+ ' name: "John Doe",',
276
+ " };",
277
+ " },",
278
+ "});",
279
+ "",
280
+ "export const GET = handlers.GET;",
281
+ "",
282
+ ].join("\n");
283
+ fs.writeFileSync(routePath, nextRouteContent);
284
+ }
285
+ }
286
+
252
287
  const configPath = path.join(cwd, "schemaapi.config.json");
253
288
  let existingConfig = null;
254
289
  if (fs.existsSync(configPath)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codexsploitx/schemaapi",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
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
@@ -5,8 +5,8 @@
5
5
  **The Zod of APIs**
6
6
  *Type-safe contracts. Runtime validation. Auto-generated docs.*
7
7
 
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)
8
+ [![npm version](https://img.shields.io/npm/v/%40codexsploitx%2Fschemaapi?style=flat-square&color=blue)](https://www.npmjs.com/package/@codexsploitx/schemaapi)
9
+ [![License](https://img.shields.io/npm/l/%40codexsploitx%2Fschemaapi?style=flat-square&color=green)](LICENSE)
10
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
11
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
12
12
 
@@ -45,15 +45,140 @@
45
45
 
46
46
  ## 📦 Installation
47
47
 
48
+ ### Core package
49
+
48
50
  ```bash
49
51
  # npm
50
- npm install schemaapi zod
52
+ npm install @codexsploitx/schemaapi zod
51
53
 
52
54
  # pnpm
53
- pnpm add schemaapi zod
55
+ pnpm add @codexsploitx/schemaapi zod
54
56
 
55
57
  # yarn
56
- yarn add schemaapi zod
58
+ yarn add @codexsploitx/schemaapi zod
59
+ ```
60
+
61
+ ### Per-adapter setup
62
+
63
+ Below are the recommended commands for **new projects** and for **existing projects**.
64
+
65
+ #### CLI quick reference
66
+
67
+ | Adapter | Init command |
68
+ |---------|----------------------------------------------------|
69
+ | Express | `npx @codexsploitx/schemaapi init express` |
70
+ | Next.js | `npx @codexsploitx/schemaapi init next` |
71
+ | Fastify | `npx @codexsploitx/schemaapi init fastify` |
72
+ | Remix | `npx @codexsploitx/schemaapi init remix` |
73
+ | NestJS | `npx @codexsploitx/schemaapi init nest` |
74
+ | Deno | `npx @codexsploitx/schemaapi init deno` |
75
+
76
+ #### Express
77
+
78
+ - 🆕 **New project**
79
+
80
+ ```bash
81
+ mkdir my-express-api && cd my-express-api
82
+ npm init -y
83
+ npm install express @codexsploitx/schemaapi zod
84
+ npx @codexsploitx/schemaapi init express
85
+ ```
86
+
87
+ - ♻️ **Existing Express project**
88
+
89
+ ```bash
90
+ npm install @codexsploitx/schemaapi zod
91
+ npx @codexsploitx/schemaapi init express
92
+ ```
93
+
94
+ #### Next.js
95
+
96
+ - 🆕 **New project**
97
+
98
+ ```bash
99
+ npx create-next-app@latest my-next-api --ts
100
+ cd my-next-api
101
+ npm install @codexsploitx/schemaapi zod
102
+ npx @codexsploitx/schemaapi init next
103
+ ```
104
+
105
+ - ♻️ **Existing Next.js project**
106
+
107
+ ```bash
108
+ npm install @codexsploitx/schemaapi zod
109
+ npx @codexsploitx/schemaapi init next
110
+ ```
111
+
112
+ El comando `schemaapi init next` creará automáticamente:
113
+
114
+ - Carpeta `contracts/` con un contrato de ejemplo `usersContract.ts`.
115
+ - `contracts/index.ts` exportando los contratos.
116
+ - `schemaapi.config.json` apuntando a `contracts/`.
117
+ - Un handler de ejemplo compatible con **App Router** en `app/api/users/route.ts`.
118
+
119
+ #### Fastify
120
+
121
+ - 🆕 **New project**
122
+
123
+ ```bash
124
+ mkdir my-fastify-api && cd my-fastify-api
125
+ npm init -y
126
+ npm install fastify @codexsploitx/schemaapi zod
127
+ npx @codexsploitx/schemaapi init fastify
128
+ ```
129
+
130
+ - ♻️ **Existing Fastify project**
131
+
132
+ ```bash
133
+ npm install @codexsploitx/schemaapi zod
134
+ npx @codexsploitx/schemaapi init fastify
135
+ ```
136
+
137
+ #### Remix
138
+
139
+ - 🆕 **New project**
140
+
141
+ ```bash
142
+ npx create-remix@latest
143
+ npm install @codexsploitx/schemaapi zod
144
+ npx @codexsploitx/schemaapi init remix
145
+ ```
146
+
147
+ - ♻️ **Existing Remix project**
148
+
149
+ ```bash
150
+ npm install @codexsploitx/schemaapi zod
151
+ npx @codexsploitx/schemaapi init remix
152
+
153
+ #### NestJS
154
+
155
+ - 🆕 **New project**
156
+
157
+ ```bash
158
+ npm i -g @nestjs/cli
159
+ nest new my-nest-api
160
+ cd my-nest-api
161
+ npm install @codexsploitx/schemaapi zod
162
+ npx @codexsploitx/schemaapi init nest
163
+ ```
164
+
165
+ - ♻️ **Existing NestJS project**
166
+
167
+ ```bash
168
+ npm install @codexsploitx/schemaapi zod
169
+ npx @codexsploitx/schemaapi init nest
170
+ ```
171
+
172
+ #### Deno
173
+
174
+ - 🆕 / ♻️ **Deno projects**
175
+
176
+ En Deno no se usa npm para el runtime, pero puedes usar SchemaApi en tu
177
+ tooling o en proyectos que usen `deno2node`. Para Node+Deno híbrido:
178
+
179
+ ```bash
180
+ npm install @codexsploitx/schemaapi zod
181
+ npx @codexsploitx/schemaapi init deno
57
182
  ```
58
183
 
59
184
  ---
@@ -65,7 +190,7 @@ yarn add schemaapi zod
65
190
  Create a shared file (e.g., `contract.ts`). This is your API's law.
66
191
 
67
192
  ```typescript
68
- import { createContract } from "schemaapi";
193
+ import { createContract } from "@codexsploitx/schemaapi";
69
194
  import { z } from "zod";
70
195
 
71
196
  export const contract = createContract({
@@ -116,7 +241,7 @@ app.get(
116
241
  No more manual fetch calls. No more `any`.
117
242
 
118
243
  ```typescript
119
- import { createClient } from "schemaapi";
244
+ import { createClient } from "@codexsploitx/schemaapi";
120
245
  import { contract } from "./shared/contract";
121
246
 
122
247
  const client = createClient(contract, {