backendium 0.0.4 → 0.0.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/dist/router.d.ts CHANGED
@@ -52,7 +52,7 @@ export declare class BackendiumRouter<GlobalAuthType = undefined> {
52
52
  unlock<BodyType = Buffer, ParamsType = {}, QueryType = {}, AuthType = GlobalAuthType, HeadersType = {}>(...args: BackendiumMethodArgsType<BodyType, ParamsType, QueryType, AuthType, HeadersType, GlobalAuthType>): void;
53
53
  link<BodyType = Buffer, ParamsType = {}, QueryType = {}, AuthType = GlobalAuthType, HeadersType = {}>(...args: BackendiumMethodArgsType<BodyType, ParamsType, QueryType, AuthType, HeadersType, GlobalAuthType>): void;
54
54
  unlink<BodyType = Buffer, ParamsType = {}, QueryType = {}, AuthType = GlobalAuthType, HeadersType = {}>(...args: BackendiumMethodArgsType<BodyType, ParamsType, QueryType, AuthType, HeadersType, GlobalAuthType>): void;
55
- ws<InitDataType>(route: string, constructor: WebSocketRouteConstructor<InitDataType>): void;
55
+ ws<InitDataType>(route: string): WebSocketRouteConstructor<InitDataType>;
56
56
  protected static addPrefix([method, route, handler]: [MethodType, string | undefined, Array<(app: Backendium) => RequestHandler>], prefix: string): [MethodType, string, Array<(app: Backendium) => RequestHandler>];
57
57
  protected static addPrefix([method, route, handler]: ["ws", string, Array<(app: Backendium) => WSRequestHandler>], prefix: string): ["ws", string, Array<(app: Backendium) => WSRequestHandler>];
58
58
  router<AuthType>(router: BackendiumRouter<AuthType>, routePrefix?: string): void;
package/dist/router.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import backendiumHandler from "./handler.js";
2
+ import { WebSocketRouteConstructor } from "./ws.js";
2
3
  export class BackendiumRouter {
3
4
  constructor() {
4
5
  this._handlers = [];
@@ -114,10 +115,12 @@ export class BackendiumRouter {
114
115
  unlink(...args) {
115
116
  this.addHandler("unlink", ...args);
116
117
  }
117
- ws(route, constructor) {
118
+ ws(route) {
119
+ let constructor = new WebSocketRouteConstructor;
118
120
  this._handlers.push(["ws", route, [(app) => (request, response, next) => {
119
121
  constructor._handle(request, response, next, app);
120
122
  }]]);
123
+ return constructor;
121
124
  }
122
125
  static addPrefix([method, route, handler], prefix) {
123
126
  return [method, route || !(route === null || route === void 0 ? void 0 : route.startsWith("/")) ? prefix + (route !== null && route !== void 0 ? route : "") : prefix + (route !== null && route !== void 0 ? route : ""), handler];
package/dist/ws.d.ts CHANGED
@@ -98,5 +98,4 @@ export declare class WebSocketRouteConstructor<InitDataType> {
98
98
  off<E extends EventKey<BackendiumWebSocketEvents<InitDataType>>>(event: E, subscriber: (...args: BackendiumWebSocketEvents<InitDataType>[E]) => void): WebSocketRouteConstructor<InitDataType>;
99
99
  requireInit<Type>(callback: (connection: WebSocket & WebSocketExtension, data: Type, app: Backendium) => null | InitDataType | Promise<null | InitDataType>, validator: Validator<Type>): WebSocketRouteConstructor<InitDataType>;
100
100
  }
101
- export declare function websocketConstructor<InitDataType = undefined>(): WebSocketRouteConstructor<InitDataType>;
102
101
  export {};
package/dist/ws.js CHANGED
@@ -336,7 +336,4 @@ export class WebSocketRouteConstructor {
336
336
  return this;
337
337
  }
338
338
  }
339
- export function websocketConstructor() {
340
- return new WebSocketRouteConstructor;
341
- }
342
339
  // @TODO error handling +termination logging
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backendium",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Express-based javascript backend framework with websocket support and type-safe checkeasy validators",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/readme.md CHANGED
@@ -4,6 +4,10 @@
4
4
  > 1. [Installation](#installation)
5
5
  > 2. [Basics](#basics)
6
6
  > 3. [Routing](#routing)
7
+ > 4. [Request validation](#request-validation-checkeasy)
8
+ > 5. [Authorization](#authorization)
9
+ > 6. [Dynamic routing](#dynamic-routing)
10
+ > 7. [Websocket](#websocket)
7
11
  # Installation
8
12
  ```bash
9
13
  npm i backendium checkeasy
@@ -43,7 +47,7 @@ app.start();
43
47
  ```
44
48
  ```typescript
45
49
  // handlers.ts
46
- import {BackendiumRouter} from "backendium/dist/router";
50
+ import {BackendiumRouter} from "backendium";
47
51
 
48
52
  const router = new BackendiumRouter;
49
53
 
@@ -214,7 +218,7 @@ websocketRequest()
214
218
  ```
215
219
  ## Init
216
220
  ```typescript
217
- router.ws<string>("/ws/init")
221
+ router.ws<string>("/ws-init")
218
222
  .event("test", (data, socket) => {
219
223
  socket.send(socket.initData);
220
224
  })
@@ -228,7 +232,7 @@ websocketRequest<number>()
228
232
  .on("message", data => {
229
233
  console.log(data.toString());
230
234
  })
231
- .send("ws://localhost:8080/ws/init", 54)
235
+ .send("ws://localhost:8080/ws-init", 54)
232
236
  .then(socket => {
233
237
  socket.emit("test");
234
238
  });
package/src/router.ts CHANGED
@@ -200,10 +200,12 @@ export class BackendiumRouter<GlobalAuthType = undefined> {
200
200
  this.addHandler("unlink", ...args);
201
201
  }
202
202
 
203
- ws<InitDataType>(route: string, constructor: WebSocketRouteConstructor<InitDataType>) {
203
+ ws<InitDataType>(route: string) {
204
+ let constructor = new WebSocketRouteConstructor<InitDataType>;
204
205
  this._handlers.push(["ws", route, [(app: Backendium) => (request: Request, response: WSResponse, next: NextFunction) => {
205
206
  constructor._handle(request, response, next, app);
206
207
  }]]);
208
+ return constructor;
207
209
  }
208
210
 
209
211
  protected static addPrefix([method, route, handler]: [MethodType, string | undefined, Array<(app: Backendium) => RequestHandler>], prefix: string): [MethodType, string, Array<(app: Backendium) => RequestHandler>];
package/src/ws.ts CHANGED
@@ -369,8 +369,4 @@ export class WebSocketRouteConstructor<InitDataType> {
369
369
  }
370
370
  }
371
371
 
372
- export function websocketConstructor<InitDataType = undefined>() {
373
- return new WebSocketRouteConstructor<InitDataType>;
374
- }
375
-
376
372
  // @TODO error handling +termination logging