@codexsploitx/schemaapi 1.0.3 → 1.0.4
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/bin/schemaapi +27 -0
- package/package.json +1 -1
- package/readme.md +115 -0
package/bin/schemaapi
CHANGED
|
@@ -249,6 +249,33 @@ function handleInit(adapterArg) {
|
|
|
249
249
|
fs.writeFileSync(indexPath, 'export * from "./usersContract";\n');
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
if (adapter === "next") {
|
|
253
|
+
const appApiUsersDir = path.join(cwd, "app", "api", "users");
|
|
254
|
+
if (!fs.existsSync(appApiUsersDir)) {
|
|
255
|
+
fs.mkdirSync(appApiUsersDir, { recursive: true });
|
|
256
|
+
}
|
|
257
|
+
const routePath = path.join(appApiUsersDir, "route.ts");
|
|
258
|
+
if (!fs.existsSync(routePath)) {
|
|
259
|
+
const nextRouteContent = [
|
|
260
|
+
'import { adapters } from "schemaapi";',
|
|
261
|
+
'import { usersContract } from "../../../contracts";',
|
|
262
|
+
"",
|
|
263
|
+
"const handlers = adapters.next.handleContract(usersContract, {",
|
|
264
|
+
' "GET /users/:id": async ({ params }) => {',
|
|
265
|
+
" return {",
|
|
266
|
+
" id: String(params && params.id),",
|
|
267
|
+
' name: "John Doe",',
|
|
268
|
+
" };",
|
|
269
|
+
" },",
|
|
270
|
+
"});",
|
|
271
|
+
"",
|
|
272
|
+
"export const GET = handlers.GET;",
|
|
273
|
+
"",
|
|
274
|
+
].join("\n");
|
|
275
|
+
fs.writeFileSync(routePath, nextRouteContent);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
252
279
|
const configPath = path.join(cwd, "schemaapi.config.json");
|
|
253
280
|
let existingConfig = null;
|
|
254
281
|
if (fs.existsSync(configPath)) {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -45,6 +45,8 @@
|
|
|
45
45
|
|
|
46
46
|
## 📦 Installation
|
|
47
47
|
|
|
48
|
+
### Core package
|
|
49
|
+
|
|
48
50
|
```bash
|
|
49
51
|
# npm
|
|
50
52
|
npm install schemaapi zod
|
|
@@ -56,6 +58,119 @@ pnpm add schemaapi zod
|
|
|
56
58
|
yarn add schemaapi zod
|
|
57
59
|
```
|
|
58
60
|
|
|
61
|
+
### Per-adapter setup
|
|
62
|
+
|
|
63
|
+
Below are the recommended commands for **new projects** and for **existing projects**.
|
|
64
|
+
|
|
65
|
+
#### Express
|
|
66
|
+
|
|
67
|
+
- 🆕 **New project**
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
mkdir my-express-api && cd my-express-api
|
|
71
|
+
npm init -y
|
|
72
|
+
npm install express schemaapi zod
|
|
73
|
+
npx schemaapi init express
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- ♻️ **Existing Express project**
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm install schemaapi zod
|
|
80
|
+
npx schemaapi init express
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### Next.js
|
|
84
|
+
|
|
85
|
+
- 🆕 **New project**
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npx create-next-app@latest my-next-api --ts
|
|
89
|
+
cd my-next-api
|
|
90
|
+
npm install schemaapi zod
|
|
91
|
+
npx schemaapi init next
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- ♻️ **Existing Next.js project**
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm install schemaapi zod
|
|
98
|
+
npx schemaapi init next
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
El comando `schemaapi init next` creará automáticamente:
|
|
102
|
+
|
|
103
|
+
- Carpeta `contracts/` con un contrato de ejemplo `usersContract.ts`.
|
|
104
|
+
- `contracts/index.ts` exportando los contratos.
|
|
105
|
+
- `schemaapi.config.json` apuntando a `contracts/`.
|
|
106
|
+
- Un handler de ejemplo compatible con **App Router** en `app/api/users/route.ts`.
|
|
107
|
+
|
|
108
|
+
#### Fastify
|
|
109
|
+
|
|
110
|
+
- 🆕 **New project**
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
mkdir my-fastify-api && cd my-fastify-api
|
|
114
|
+
npm init -y
|
|
115
|
+
npm install fastify schemaapi zod
|
|
116
|
+
npx schemaapi init fastify
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- ♻️ **Existing Fastify project**
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm install schemaapi zod
|
|
123
|
+
npx schemaapi init fastify
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Remix
|
|
127
|
+
|
|
128
|
+
- 🆕 **New project**
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npx create-remix@latest
|
|
132
|
+
npm install schemaapi zod
|
|
133
|
+
npx schemaapi init remix
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
- ♻️ **Existing Remix project**
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npm install schemaapi zod
|
|
140
|
+
npx schemaapi init remix
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### NestJS
|
|
144
|
+
|
|
145
|
+
- 🆕 **New project**
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
npm i -g @nestjs/cli
|
|
149
|
+
nest new my-nest-api
|
|
150
|
+
cd my-nest-api
|
|
151
|
+
npm install schemaapi zod
|
|
152
|
+
npx schemaapi init nest
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
- ♻️ **Existing NestJS project**
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npm install schemaapi zod
|
|
159
|
+
npx schemaapi init nest
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Deno
|
|
163
|
+
|
|
164
|
+
- 🆕 / ♻️ **Deno projects**
|
|
165
|
+
|
|
166
|
+
En Deno no se usa npm para el runtime, pero puedes usar SchemaApi en tu
|
|
167
|
+
tooling o en proyectos que usen `deno2node`. Para Node+Deno híbrido:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
npm install schemaapi zod
|
|
171
|
+
npx schemaapi init deno
|
|
172
|
+
```
|
|
173
|
+
|
|
59
174
|
---
|
|
60
175
|
|
|
61
176
|
## 🛠 Usage
|