Skip to content

Commit 4c3cc1d

Browse files
committed
props over args, adding plugin map, rearranged server generics
1 parent a36d0a9 commit 4c3cc1d

16 files changed

Lines changed: 432 additions & 324 deletions

File tree

ingest/README.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Ingest is a lightweight, flexible server framework that brings the familiar Expr
1717
- **🚀 Serverless-First**: Designed specifically for serverless environments while maintaining compatibility with traditional servers
1818
- **🔄 Event-Driven**: Built on a robust event system that enables reactive programming patterns
1919
- **🛣️ Multi-Routing Interface**: Four different routing approaches in one framework
20-
- **🔌 Plugin System**: Highly extensible with a simple plugin architecture
21-
- **📦 Build Support**: Exposes routing information for bundlers and build tools
20+
- **🔌 Plugin System**: Optional automatic wiring for routes, hooks, and shared services
21+
- **📦 Build Support**: Exposes routing information for build and deployment tooling
2222
- **🌐 Cross-Platform**: Works with Node.js HTTP, WHATWG Fetch, and various serverless platforms
2323

2424
## Installation
@@ -39,11 +39,11 @@ import { server } from '@stackpress/ingest/http';
3939
const app = server();
4040

4141
// Traditional Express-like routing
42-
app.get('/', (req, res) => {
42+
app.get('/', ({ req, res }) => {
4343
res.setHTML('<h1>Hello World!</h1>');
4444
});
4545

46-
app.get('/api/users/:id', (req, res) => {
46+
app.get('/api/users/:id', ({ req, res }) => {
4747
const userId = req.data.get('id');
4848
res.setJSON({ id: userId, name: 'John Doe' });
4949
});
@@ -61,7 +61,7 @@ import { server } from '@stackpress/ingest/whatwg';
6161

6262
const app = server();
6363

64-
app.get('/api/hello', (req, res) => {
64+
app.get('/api/hello', ({ req, res }) => {
6565
res.setJSON({ message: 'Hello from Vercel!' });
6666
});
6767

@@ -78,7 +78,7 @@ Ingest provides four different ways to define routes, giving you flexibility in
7878
Express.js-like inline route handlers:
7979

8080
```typescript
81-
app.action.get('/users', (req, res) => {
81+
app.action.get('/users', ({ req, res }) => {
8282
res.setJSON({ users: [] });
8383
});
8484
```
@@ -91,7 +91,7 @@ app.entry.get('/users', './routes/users.js');
9191
```
9292

9393
### 3. Import Router (Lazy Loading)
94-
Dynamic imports for code splitting:
94+
Dynamic imports for lazy loading and tooling-aware route boundaries:
9595

9696
```typescript
9797
app.import.get('/users', () => import('./routes/users.js'));
@@ -110,7 +110,7 @@ Ingest can automatically determine which router to use based on your input:
110110

111111
```typescript
112112
// Automatically uses action router
113-
app.get('/users', (req, res) => { /* handler */ });
113+
app.get('/users', ({ req, res }) => { /* handler */ });
114114

115115
// Automatically uses import router
116116
app.get('/users', () => import('./routes/users.js'));
@@ -121,14 +121,14 @@ app.get('/users', './views/users.hbs');
121121

122122
## Plugin System
123123

124-
Ingest features a powerful plugin system that allows you to modularize your application:
124+
Ingest includes an optional plugin system that can automate application wiring. You can still wire routes, handlers, and services manually in a main file if you prefer:
125125

126126
### Creating a Plugin
127127

128128
```typescript
129129
// src/plugins/auth.ts
130130
export default function authPlugin(server) {
131-
server.on('request', (req, res) => {
131+
server.on('request', ({ req, res }) => {
132132
// Add authentication logic
133133
if (!req.headers.get('authorization')) {
134134
res.setError('Unauthorized', {}, [], 401);
@@ -171,12 +171,12 @@ Ingest is built on a powerful event system that allows for reactive programming:
171171

172172
```typescript
173173
// Listen to all requests
174-
app.on('request', (req, res) => {
174+
app.on('request', ({ req, res }) => {
175175
console.log(`${req.method} ${req.url.pathname}`);
176176
});
177177

178178
// Listen to specific routes
179-
app.on('GET /api/users', (req, res) => {
179+
app.on('GET /api/users', ({ req, res }) => {
180180
// This runs for GET /api/users
181181
});
182182

@@ -193,7 +193,7 @@ app.on('request', middleware2, 5); // Lower priority
193193
import { server } from '@stackpress/ingest/whatwg';
194194

195195
const app = server();
196-
app.get('/api/hello', (req, res) => {
196+
app.get('/api/hello', ({ req, res }) => {
197197
res.setJSON({ message: 'Hello from Lambda!' });
198198
});
199199

@@ -210,7 +210,7 @@ export const handler = async (event, context) => {
210210
import { server } from '@stackpress/ingest/whatwg';
211211

212212
const app = server();
213-
app.get('/api/users', (req, res) => {
213+
app.get('/api/users', ({ req, res }) => {
214214
res.setJSON({ users: [] });
215215
});
216216

@@ -225,7 +225,7 @@ export default async function handler(req: Request) {
225225
import { server } from '@stackpress/ingest/whatwg';
226226

227227
const app = server();
228-
app.get('/.netlify/functions/api', (req, res) => {
228+
app.get('/.netlify/functions/api', ({ req, res }) => {
229229
res.setJSON({ message: 'Hello from Netlify!' });
230230
});
231231

@@ -238,7 +238,7 @@ export const handler = async (event, context) => {
238238

239239
## Build Support
240240

241-
Ingest exposes routing information that can be used by bundlers and build tools:
241+
Ingest exposes routing information that can be used by build and deployment tooling:
242242

243243
```typescript
244244
const app = server();
@@ -252,17 +252,20 @@ console.log(app.entries); // File entries
252252
console.log(app.views); // View templates
253253
```
254254

255-
This information can be used by bundlers to:
255+
This information can be used by tooling to:
256256
- Pre-bundle route modules
257257
- Generate static route manifests
258-
- Optimize code splitting
258+
- Discover import, entry, and view boundaries
259259
- Create deployment artifacts
260260

261261
## Documentation
262262

263-
- [API Reference](https://github.com/stackpress/ingest/tree/main/docs/api/README.md) - Complete API documentation
264-
- [Examples](https://github.com/stackpress/ingest/tree/main/docs/examples.md) - Comprehensive usage examples
265-
- [Plugin Development](https://github.com/stackpress/ingest/tree/main/docs/plugin-development.md) - Guide to creating plugins
263+
- [Specifications](https://github.com/stackpress/ingest/tree/main/specs/README.md) - Documentation index
264+
- [Overview](https://github.com/stackpress/ingest/tree/main/specs/overview.md) - What Ingest is optimizing for
265+
- [Concepts](https://github.com/stackpress/ingest/tree/main/specs/concepts/README.md) - How the system works
266+
- [Guides](https://github.com/stackpress/ingest/tree/main/specs/guides/README.md) - Task-oriented documentation
267+
- [API Reference](https://github.com/stackpress/ingest/tree/main/specs/api/README.md) - Exact class and method lookup
268+
- [Examples](https://github.com/stackpress/ingest/tree/main/specs/examples.md) - Example workspace guide
266269

267270
## Examples
268271

ingest/src/Route.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,42 @@ import Exception from './Exception.js';
1616
* - properly formats the response
1717
*/
1818
export default class Route<
19-
//configuration map
20-
C extends UnknownNest = UnknownNest,
21-
//request resource
2219
R = unknown,
23-
//response resource
24-
S = unknown
20+
S = unknown,
21+
C extends UnknownNest = UnknownNest,
22+
P extends Record<string, unknown> = Record<string, unknown>
2523
> {
2624
/**
2725
* Hooks in plugins to the request lifecycle
2826
*/
2927
public static async emit<
30-
C extends UnknownNest = UnknownNest,
3128
R = unknown,
32-
S = unknown
29+
S = unknown,
30+
C extends UnknownNest = UnknownNest,
31+
P extends Record<string, unknown> = Record<string, unknown>
3332
>(
34-
event: ServerAction<C, R, S>|string,
33+
event: ServerAction<R, S, C, P>|string,
3534
request: Request<R>,
3635
response: Response<S>,
37-
context: Server<C, R, S>
36+
context: Server<R, S, C, P>
3837
) {
3938
const route = new Route(event, request, response, context);
4039
return route.emit();
4140
}
4241

43-
public readonly event: ServerAction<C, R, S>|string;
42+
public readonly event: ServerAction<R, S, C, P>|string;
4443
public readonly request: Request<R>;
4544
public readonly response: Response<S>;
46-
public readonly context: Server<C, R, S>;
45+
public readonly context: Server<R, S, C, P>;
4746

4847
/**
4948
* Gets everything needed from route.handle()
5049
*/
5150
constructor(
52-
event: ServerAction<C, R, S>|string,
51+
event: ServerAction<R, S, C, P>|string,
5352
request: Request<R>,
5453
response: Response<S>,
55-
context: Server<C, R, S>
54+
context: Server<R, S, C, P>
5655
) {
5756
this.event = event;
5857
this.request = request;
@@ -117,11 +116,7 @@ export default class Route<
117116
this.response
118117
);
119118
} else {
120-
await this.event(
121-
this.request,
122-
this.response,
123-
this.context
124-
);
119+
await this.event(this.context.props(this.request, this.response));
125120
}
126121
} catch(error) {
127122
//allow plugins to handle the error

0 commit comments

Comments
 (0)