@ublitzjs/core 0.1.1 → 1.0.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/README.md +17 -14
- package/USAGE.md +16 -5
- package/babel.config.json +8 -0
- package/bun.lock +627 -0
- package/dist/cjs/http-codes.js +99 -0
- package/dist/cjs/http-headers.js +118 -0
- package/dist/cjs/index.js +104 -0
- package/dist/esm/http-codes.js +84 -0
- package/dist/esm/http-headers.js +119 -0
- package/dist/esm/index.js +71 -0
- package/dist/esm/package.json +1 -0
- package/dist/types/http-codes.d.ts +43 -0
- package/dist/types/http-headers.d.ts +1040 -0
- package/dist/types/index.d.ts +249 -0
- package/package.json +27 -7
- package/src/http-codes.ts +94 -0
- package/{types/http-headers.d.ts → src/http-headers.ts} +75 -18
- package/src/index.ts +360 -0
- package/tmp/cjs.cjs +75 -0
- package/tmp/esm.mjs +75 -0
- package/tsconfig.esm.json +9 -0
- package/tsconfig.json +9 -20
- package/tsconfig.types.json +11 -0
- package/cjs/http-codes.cjs +0 -56
- package/cjs/http-headers.cjs +0 -64
- package/cjs/index.cjs +0 -61
- package/mjs/http-codes.mjs +0 -52
- package/mjs/http-headers.mjs +0 -63
- package/mjs/index.mjs +0 -51
- package/types/http-codes.d.ts +0 -54
- package/types/index.d.ts +0 -170
- package/types/uws-types.d.ts +0 -123
package/README.md
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|

|
|
2
2
|
<br/>
|
|
3
3
|
|
|
4
|
-
# μBlitz.js -
|
|
4
|
+
# μBlitz.js - utilitarian-library for uWebSockets.js
|
|
5
5
|
|
|
6
|
-
On NPM you can find such packages:
|
|
6
|
+
On NPM you can find such packages: (with @ublitzjs/ organization)
|
|
7
7
|
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
8
|
+
- core (THIS repo)
|
|
9
|
+
- logger (colorful console)
|
|
10
|
+
- static (send files)
|
|
11
|
+
- payload (handling POST-like requests)
|
|
12
|
+
- router (OpenAPI-like router for simple orientation)
|
|
13
|
+
- openapi
|
|
14
|
+
- preprocess (Code preprocessing + templating framework)
|
|
15
|
+
- asyncapi
|
|
16
|
+
- testing (coming soon)
|
|
17
|
+
- auth (coming soon)
|
|
15
18
|
|
|
16
19
|
# Installation
|
|
17
20
|
|
|
@@ -27,12 +30,12 @@ Supports CJS and ESM in ALL packages
|
|
|
27
30
|
|
|
28
31
|
# <a href="./USAGE.md" target="_blank">Go to usage.md</a>
|
|
29
32
|
|
|
30
|
-
#
|
|
33
|
+
# But why?
|
|
31
34
|
|
|
32
|
-
It is acclaimed
|
|
35
|
+
It is acclaimed that Express.js, Fastify and other frameworks are built to be very extensible and developer-friendly. It is enough to download needed packages, put them as middlewares, which handle everything behind the scenes, and do your own job. <br>
|
|
33
36
|
|
|
34
|
-
But the "speed" of creating your app comes from so-called "abstractions". Their versatility is often considered an "overkill"
|
|
37
|
+
But the "speed" of creating your app comes from so-called "abstractions". Their versatility is often considered to be an "overkill" as they usually overwhelm the RAM and slow down your app. Most people, however, still prefer "rapid typing" over speed of execution, under which I mean uWebSockets.js (which actually handles websockets AND http requests)<br>
|
|
35
38
|
|
|
36
|
-
Though it IS performant, it handles only core features. Now there are solutions like "hyper-express", "ultimate-express", "uwebsockets-express", but they are just
|
|
39
|
+
Though it IS performant, it handles only core features. Now there are solutions like "hyper-express", "ultimate-express", "uwebsockets-express", but they are just additional layers simulating "express" behaviour, while hiding the most important (and difficult) aspects of uWS.<br>
|
|
37
40
|
|
|
38
|
-
This library
|
|
41
|
+
This library provides you with utilities but you still operate on the uWebSockets.js. This way server remains optimizable and rapid typing doesn't vanish.
|
package/USAGE.md
CHANGED
|
@@ -195,7 +195,7 @@ export default (server: Server) => {
|
|
|
195
195
|
};
|
|
196
196
|
```
|
|
197
197
|
|
|
198
|
-
Also there is HeadersMap.default (see
|
|
198
|
+
Also there is HeadersMap.default (see in the code), HeadersMap.baseObj (also in the code), and HeadersMap.remove (you remove unwanted headers)
|
|
199
199
|
|
|
200
200
|
## setCSP
|
|
201
201
|
|
|
@@ -287,9 +287,9 @@ These types add 3 methods to websocket object: sendFirstFragment, sendFragment,
|
|
|
287
287
|
More detailed description <a href="./types/uws-types.d.ts">here</a>
|
|
288
288
|
|
|
289
289
|
```typescript
|
|
290
|
-
import type { DocumentedWSBehavior, lowHeaders } from "@ublitzjs/core";
|
|
290
|
+
import type { extendApp, DocumentedWSBehavior, lowHeaders } from "@ublitzjs/core";
|
|
291
291
|
import uWS from "uWebSockets.js";
|
|
292
|
-
const server = uWS.App()
|
|
292
|
+
const server = extendApp(uWS.App()) // better for ts
|
|
293
293
|
server.ws("/*", {
|
|
294
294
|
upgrade(res, req, context) {
|
|
295
295
|
res.upgrade(
|
|
@@ -307,7 +307,18 @@ server.ws("/*", {
|
|
|
307
307
|
ws.sendFragment("hello2\n");
|
|
308
308
|
ws.sendLastFragment("end hello");
|
|
309
309
|
},
|
|
310
|
-
|
|
310
|
+
close(ws){
|
|
311
|
+
//typed safety flag
|
|
312
|
+
ws.closed = true;
|
|
313
|
+
}
|
|
314
|
+
message(ws){
|
|
315
|
+
setTimeout(()=>{
|
|
316
|
+
//acts like res.aborted
|
|
317
|
+
if(ws.closed) return;
|
|
318
|
+
ws.send("hello")
|
|
319
|
+
}, 100);
|
|
320
|
+
},
|
|
321
|
+
});
|
|
311
322
|
```
|
|
312
323
|
|
|
313
324
|
# Bundling
|
|
@@ -316,4 +327,4 @@ Best efficiency and start time can be achieved if the code is bundled and minifi
|
|
|
316
327
|
For this purpose you can use "esbuild" (at least it was tested and worked for both cjs and esm formats).<br>
|
|
317
328
|
The only thing to remember: when you use it for bundling, don't forget to put "uWebSockets.js" to "external" array.<br>
|
|
318
329
|
<a href="./examples/esbuild.mjs">Example 1</a><br>
|
|
319
|
-
<a href="./tests/esbuild
|
|
330
|
+
<a href="./tests/esbuild.test.ts">Dynamic example 2</a>
|