@ublitzjs/core 0.1.0 → 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 CHANGED
@@ -1,17 +1,20 @@
1
1
  ![μBlitz.js](./logo.png)
2
2
  <br/>
3
3
 
4
- # μBlitz.js - utility-library for uWebSockets.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
- - @ublitzjs/core (THIS repo)
9
- - @ublitzjs/logger (colorful console)
10
- - @ublitzjs/static (send files)
11
- - @ublitzjs/payload (handling POST-like requests)
12
- - @ublitzjs/router (OpenAPI-like router for simple orientation)
13
- - @ublitzjs/openapi
14
- - @ublitzjs/dev-comments (Tool for removing CODE BETWEEN /\*\_START_DEV\_\*/ and /\*\_END_DEV\_\*/ comments)
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
- # Comparison with others
33
+ # But why?
31
34
 
32
- 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>
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" and 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 uWebSocket.js (which actually handles websockets AND http requests)<br>
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 abstractions, created to be somehow faster then express, but hide the most important (and difficult) aspects of uWS.<br>
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 is different. It doesn't take care of everything, but rather helps you do it yourself, using utilities.
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 it in the code itself), HeadersMap.baseObj (also in the code), and HeadersMap.remove (you remove unwanted headers)
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
- } as DocumentedWSBehavior<{}> as any);
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/build.mjs">Dynamic example 2</a>
330
+ <a href="./tests/esbuild.test.ts">Dynamic example 2</a>
@@ -0,0 +1,8 @@
1
+ {
2
+ "plugins": [
3
+ [
4
+ "@babel/plugin-transform-modules-commonjs",
5
+ { "importInterop": "node" }
6
+ ]
7
+ ]
8
+ }