sparkzen 1.0.2 → 1.1.0
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/dist/cli/index.js +2 -4
- package/package.json +1 -1
- package/README.md +0 -294
package/dist/cli/index.js
CHANGED
|
@@ -139,13 +139,11 @@ var dev_default = dev;
|
|
|
139
139
|
import { execSync as execSync3 } from "child_process";
|
|
140
140
|
import { Command as Command3 } from "commander";
|
|
141
141
|
import { bgGreenBright, bold as bold3 } from "logfy-x";
|
|
142
|
-
import path3 from "path";
|
|
143
142
|
var build = new Command3().name("build").description("Build the project").action(() => {
|
|
144
143
|
const projectPath = process.cwd();
|
|
145
144
|
console.log(`${bgGreenBright(bold3(" \u{1F4E6} BUILD "))} Building the project...
|
|
146
145
|
`);
|
|
147
|
-
|
|
148
|
-
execSync3(`${tsupPath} src/index.ts --format esm --out-dir dist`, {
|
|
146
|
+
execSync3(`npx tsc`, {
|
|
149
147
|
cwd: projectPath,
|
|
150
148
|
stdio: "inherit",
|
|
151
149
|
shell: process.platform === "win32" ? "cmd.exe" : "/bin/sh"
|
|
@@ -165,7 +163,7 @@ function registerCommands(program2) {
|
|
|
165
163
|
|
|
166
164
|
// package.json
|
|
167
165
|
var name = "sparkzen";
|
|
168
|
-
var version = "1.0
|
|
166
|
+
var version = "1.1.0";
|
|
169
167
|
|
|
170
168
|
// src/cli/index.ts
|
|
171
169
|
var program = new Command4();
|
package/package.json
CHANGED
package/README.md
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
# SparkZen — Official Documentation
|
|
2
|
-
|
|
3
|
-
**SparkZen** is a high‑performance TypeScript framework focused on extreme simplicity, aggressively smooth DX, and stylish logs that make any developer smile. Designed for builders who want fast, scalable APIs with an organized architecture — *without corporate bureaucracy*.
|
|
4
|
-
|
|
5
|
-
Minimal on the outside, powerful on the inside.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# 🚀 1. Overview
|
|
10
|
-
|
|
11
|
-
SparkZen follows three core principles:
|
|
12
|
-
|
|
13
|
-
* **Zero initial configuration** – import → use → run.
|
|
14
|
-
* **Folder‑driven architecture** – routes are auto‑registered.
|
|
15
|
-
* **DX first** – schemas, middlewares, and handlers fully typed.
|
|
16
|
-
|
|
17
|
-
Perfect for modern REST APIs, microservices, and backends that demand clarity.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
# 📦 2. Creating a New SparkZen Project
|
|
22
|
-
|
|
23
|
-
Kickstart a new SparkZen application using the official CLI:
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
npx sparkzen init
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
The CLI will walk you through scaffolding, project structure, and essentials.
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
Installation
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
npm install sparkzen
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
or:
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
yarn add sparkzen
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
# 🏗️ 3. API Initialization
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
import sparkzen from "sparkzen";
|
|
51
|
-
|
|
52
|
-
async function spark() {
|
|
53
|
-
try {
|
|
54
|
-
const app = await sparkzen();
|
|
55
|
-
await app.listen({ port: 3000 });
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error(error);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
spark();
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
When you run this, SparkZen automatically:
|
|
66
|
-
|
|
67
|
-
* initializes the server
|
|
68
|
-
* loads all routes inside `src/routes`
|
|
69
|
-
* applies default middlewares
|
|
70
|
-
* prints clean, structured logs
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
# 📂 4. Folder Structure
|
|
75
|
-
|
|
76
|
-
SparkZen uses a modern, intuitive pattern:
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
src/
|
|
80
|
-
└── routes/
|
|
81
|
-
├── users/
|
|
82
|
-
│ ├── get.ts → GET /users
|
|
83
|
-
│ └── [id]/
|
|
84
|
-
│ └── post.ts → POST /users/:id
|
|
85
|
-
└── auth/
|
|
86
|
-
└── login/post.ts → POST /auth/login
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
📌 **Golden Rule:**
|
|
90
|
-
|
|
91
|
-
* File name → HTTP method
|
|
92
|
-
* Folder name → endpoint path
|
|
93
|
-
* `[id]` → dynamic param
|
|
94
|
-
|
|
95
|
-
Simple. Beautiful. Powerful.
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
# 🧩 5. Handlers
|
|
100
|
-
|
|
101
|
-
Handlers are the core of each route.
|
|
102
|
-
|
|
103
|
-
### Basic Example
|
|
104
|
-
|
|
105
|
-
```ts
|
|
106
|
-
import type { Handler } from "sparkzen";
|
|
107
|
-
|
|
108
|
-
const handler: Handler = async (request, reply) => {
|
|
109
|
-
return reply.status(200).send({ message: "Hello, SparkZen!" });
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export default handler;
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### What you get inside a handler?
|
|
116
|
-
|
|
117
|
-
* `request.params`
|
|
118
|
-
* `request.body`
|
|
119
|
-
* `request.query`
|
|
120
|
-
* `request.headers`
|
|
121
|
-
|
|
122
|
-
All fully typed.
|
|
123
|
-
|
|
124
|
-
---
|
|
125
|
-
|
|
126
|
-
# 🛡️ 6. Schemas (TypeBox Powered)
|
|
127
|
-
|
|
128
|
-
SparkZen uses **TypeBox** for strong validation + auto‑generated TypeScript types.
|
|
129
|
-
|
|
130
|
-
### Example Schema
|
|
131
|
-
|
|
132
|
-
```ts
|
|
133
|
-
export const schema = {
|
|
134
|
-
params: T.Object({
|
|
135
|
-
id: T.Number({ description: "User ID", examples: [1] }),
|
|
136
|
-
}),
|
|
137
|
-
|
|
138
|
-
body: T.Object({
|
|
139
|
-
name: T.String({ minLength: 2 }),
|
|
140
|
-
nick: T.Optional(T.String()),
|
|
141
|
-
}),
|
|
142
|
-
|
|
143
|
-
response: {
|
|
144
|
-
200: T.Object({
|
|
145
|
-
ok: T.Boolean(),
|
|
146
|
-
message: T.String(),
|
|
147
|
-
received: T.Object({
|
|
148
|
-
id: T.Number(),
|
|
149
|
-
name: T.String(),
|
|
150
|
-
nick: T.Optional(T.String()),
|
|
151
|
-
}),
|
|
152
|
-
}),
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
Define once → SparkZen types everything.
|
|
158
|
-
|
|
159
|
-
---
|
|
160
|
-
|
|
161
|
-
# ⚙️ 7. Middlewares
|
|
162
|
-
|
|
163
|
-
Clean, lightweight, powerful.
|
|
164
|
-
|
|
165
|
-
### Example
|
|
166
|
-
|
|
167
|
-
```ts
|
|
168
|
-
export const middlewares: Middleware<typeof schema> = [
|
|
169
|
-
(request, _reply, done) => {
|
|
170
|
-
console.log("[SparkZen] Incoming request:", {
|
|
171
|
-
params: request.params,
|
|
172
|
-
body: request.body,
|
|
173
|
-
});
|
|
174
|
-
done();
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
(_request, _reply, done) => {
|
|
178
|
-
console.log("[SparkZen] Second middleware executed");
|
|
179
|
-
done();
|
|
180
|
-
},
|
|
181
|
-
];
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
Each middleware receives:
|
|
185
|
-
|
|
186
|
-
* `request`
|
|
187
|
-
* `reply`
|
|
188
|
-
* `done()`
|
|
189
|
-
|
|
190
|
-
Similar to Fastify — but tighter and more TS‑integrated.
|
|
191
|
-
|
|
192
|
-
---
|
|
193
|
-
|
|
194
|
-
# 🔥 8. Full Route (Schema + Middleware + Handler)
|
|
195
|
-
|
|
196
|
-
```ts
|
|
197
|
-
import { Middleware, T, type Handler } from "sparkzen";
|
|
198
|
-
|
|
199
|
-
export const schema = {
|
|
200
|
-
params: T.Object({
|
|
201
|
-
id: T.Number({ description: "User ID", examples: [1] }),
|
|
202
|
-
}),
|
|
203
|
-
body: T.Object({
|
|
204
|
-
name: T.String({ minLength: 2 }),
|
|
205
|
-
nick: T.Optional(T.String()),
|
|
206
|
-
}),
|
|
207
|
-
response: {
|
|
208
|
-
200: T.Object({
|
|
209
|
-
ok: T.Boolean(),
|
|
210
|
-
message: T.String(),
|
|
211
|
-
received: T.Object({
|
|
212
|
-
id: T.Number(),
|
|
213
|
-
name: T.String(),
|
|
214
|
-
nick: T.Optional(T.String()),
|
|
215
|
-
}),
|
|
216
|
-
}),
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
export const middlewares: Middleware<typeof schema> = [
|
|
221
|
-
(request, _reply, done) => {
|
|
222
|
-
console.log("[SparkZen] Incoming request:", {
|
|
223
|
-
params: request.params,
|
|
224
|
-
body: request.body,
|
|
225
|
-
});
|
|
226
|
-
done();
|
|
227
|
-
},
|
|
228
|
-
() => {
|
|
229
|
-
console.log("[SparkZen] Second middleware executed");
|
|
230
|
-
},
|
|
231
|
-
];
|
|
232
|
-
|
|
233
|
-
const handler: Handler<typeof schema> = async (request, reply) => {
|
|
234
|
-
const { id } = request.params;
|
|
235
|
-
const { name, nick } = request.body;
|
|
236
|
-
|
|
237
|
-
return reply.status(200).send({
|
|
238
|
-
ok: true,
|
|
239
|
-
message: "User processed successfully",
|
|
240
|
-
received: { id, name, nick },
|
|
241
|
-
});
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
export default handler;
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
---
|
|
248
|
-
|
|
249
|
-
# 📡 9. Boot Logs
|
|
250
|
-
|
|
251
|
-
On startup, SparkZen prints something like:
|
|
252
|
-
|
|
253
|
-
```
|
|
254
|
-
SPARKZEN INITIALIZING API SPARKZEN
|
|
255
|
-
|
|
256
|
-
SPARKZEN LOADING ROUTES SPARKZEN
|
|
257
|
-
|
|
258
|
-
ROUTE GET /api/users .../src/routes/users/get.ts
|
|
259
|
-
ROUTE POST /api/users/:id .../src/routes/users/[id]/post.ts
|
|
260
|
-
|
|
261
|
-
SPARKZEN STARTING SERVER SPARKZEN
|
|
262
|
-
|
|
263
|
-
SERVER Running at: http://localhost:3000
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
Logs are designed for:
|
|
267
|
-
|
|
268
|
-
* maximum clarity
|
|
269
|
-
* fast debugging
|
|
270
|
-
* clean aesthetics
|
|
271
|
-
|
|
272
|
-
---
|
|
273
|
-
|
|
274
|
-
# 🧠 10. Best Practices
|
|
275
|
-
|
|
276
|
-
* Always use **schemas** for strong typing
|
|
277
|
-
* Keep **handlers minimal**
|
|
278
|
-
* Group middlewares by responsibility
|
|
279
|
-
* Keep route folders small and focused
|
|
280
|
-
* Name files after HTTP methods (SparkZen standard ❤️)
|
|
281
|
-
|
|
282
|
-
---
|
|
283
|
-
|
|
284
|
-
# 🔮 11. SparkZen Roadmap
|
|
285
|
-
|
|
286
|
-
Planned features:
|
|
287
|
-
|
|
288
|
-
* Advanced CLI
|
|
289
|
-
* Official plugins
|
|
290
|
-
* Simplified authentication utilities
|
|
291
|
-
* Auto‑generated documentation
|
|
292
|
-
* Edge‑runtime adapters
|
|
293
|
-
|
|
294
|
-
SparkZen was built to scale — and you scale with it.
|