@ozanarslan/corpus 0.1.4 → 0.1.6

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Corpus
2
2
 
3
- A very simple typescript backend framework package to use for personal projects or simple crud applications.
3
+ A simple typescript backend framework package to use for personal projects or simple crud applications.
4
4
  This package is by no means a replacement for full fledged backend frameworks commonly used in production.
5
5
 
6
6
  ## Quick Start
@@ -30,7 +30,7 @@ new C.Route("/health", () => "ok");
30
30
  server.listen(3000);
31
31
  ```
32
32
 
33
- That's it. Your bare bones backend is running.
33
+ That's it. Your barebones backend is running.
34
34
 
35
35
  ## What does this library do?
36
36
 
@@ -41,24 +41,26 @@ That's it. Your bare bones backend is running.
41
41
  - Request handling using `RouteContext` (the `(c) => {}` callback pattern)
42
42
  - Loading env variables using `Config`
43
43
  - Other utilities such as setting cors, global prefix, error handling etc.
44
+ - The package exports two modules: `C` (default) for the core API, and `X` - also importable as `Extra` - for additional utilities like Cors, Repository, router adapters etc.
44
45
 
45
46
  ## How does the routing work?
46
47
 
47
48
  - Routes, route models and middlewares are lazily registered to their respective registries on class initialization. Router uses the registries and is created with the Server object. The Server should be created before any route, controller or middleware.
48
49
  - Router is RegExp based and supports route parameters.
49
- - The router isn't very advanced since this is my very first time working on such a project, I appreciate all feedback.
50
+ - Router supports drop-in replacements with the provided adapters as the default router is quite simple.
50
51
 
51
52
  ## Runtime?
52
53
 
53
- Originally I wanted to support Node and Bun runtimes but to be honest, I didn't test with node at all because I almost always prefer Bun in my personal projects and this library is meant to be used for small personal projects. Maybe I'll get back to the idea later on.
54
+ Bun only for now, Node support planned. This is due to lack of testing, if you can get it working with node using the existing internal classes like ServerUsingBun etc. you are free to!
54
55
 
55
- ## What is the pattern I had in mind?
56
+ ## Recommended Pattern
56
57
 
57
58
  ```typescript
58
- // You can also use something else
59
+ // Any schema library that supports standard schema works
59
60
  import { type } from "arktype";
60
- // You can also import everything by name
61
- import C from "@ozanarslan/corpus";
61
+ // You can import The main module C by name or as a default,
62
+ // X is the Extra module and can also be imported as "Extra"
63
+ import C, { X } from "@ozanarslan/corpus";
62
64
 
63
65
  // You can use schemas however you want, I just really like this.
64
66
  export class ItemModel {
@@ -73,12 +75,12 @@ export class ItemModel {
73
75
  }
74
76
 
75
77
  // This helper type could also work for similar prototypes
76
- export type ItemType = C.InferModel<typeof ItemModel>;
78
+ export type ItemType = X.InferModel<typeof ItemModel>;
77
79
 
78
80
  // This is also a personal helper, all repositories get
79
81
  // the DatabaseClientInterface in constructor args.
80
82
  // This interface can be extended.
81
- export class ItemRepository extends C.Repository {
83
+ export class ItemRepository extends X.Repository {
82
84
  // ...
83
85
  }
84
86
 
@@ -105,21 +107,23 @@ export class ItemController extends C.Controller {
105
107
  );
106
108
 
107
109
  // Static routes can also be in the controller instead of new StaticRoute()
108
- page = this
109
- .staticRoute
110
- // ...
111
- ();
110
+ page = this.staticRoute(...)
112
111
  }
113
112
 
114
113
  // Server must be created first for the router
115
- const server = new C.Server();
114
+ const server = new C.Server({
115
+ // There are some supported adapters for the router,
116
+ // The default router with no dependencies is very simple
117
+ // so I wanted to make it drop-in replaceable.
118
+ adapter: new X.SomeSupportedRouterAdapter()
119
+ });
116
120
  // This DOES NOT apply to static routes
117
121
  server.setGlobalPrefix("/api");
118
122
 
119
123
  // Cors headers are applied globally if you set them this way also
120
124
  // any request with Access-Control-Request-Method header and OPTIONS
121
125
  // method is handled as a preflight request.
122
- server.setCors({});
126
+ new X.Cors({})
123
127
 
124
128
  const db = new DatabaseClient();
125
129
  server.setOnBeforeListen(() => db.connect());
@@ -156,19 +160,14 @@ declare module "@ozanarslan/corpus" {
156
160
 
157
161
  # Closing thoughts
158
162
 
159
- As I mentioned multiple times, this is not for production. It's also my first ever personal project at this scale. I am very open to suggestions (maybe even pull requests). Thank you for being here.
163
+ As I mentioned multiple times, this is not for production. It's also my first ever personal project at this scale. I am open to suggestions (maybe even pull requests). Thank you for being here.
160
164
 
161
165
  Very much inspired from the core ideas behind [Elysia](https://github.com/elysiajs/elysia)
162
166
 
163
167
  # Roadmap
164
168
 
165
- - [ ] Better and more memory efficient router
166
- - [ ] Reduce dist size
167
- - [ ] Support ArrayBuffer in custom Response wrapper object
168
- - [ ] Support Blob in custom Response wrapper object
169
- - [ ] Support FormData in custom Response wrapper object
170
- - [ ] Support URLSearchParams in custom Response wrapper object
171
- - [ ] Support ReadableStream in custom Response wrapper object
169
+ - [x] Better and more memory efficient router
170
+ - [x] Reduce dist size
171
+ - [x] Support additional response body types (ArrayBuffer, Blob, FormData, etc.) in the custom Response object.
172
172
  - [ ] Support WebSocket
173
173
  - [ ] Compress static files in StaticRoute for caching and stuff maybe?
174
- - [ ] Better everything