@wxn0brp/falcon-frame 0.6.3 → 0.7.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.
@@ -1,6 +1,6 @@
1
- import FalconFrame, { FFResponse } from "./index.js";
1
+ import { FFResponse } from "./index.js";
2
2
  import type { FFRequest, ParseBodyFunction, RouteHandler, StandardBodyParserOptions } from "./types.js";
3
3
  export declare function parseLimit(limit: string | number): number;
4
4
  export declare function getContentType(req: FFRequest): string | undefined;
5
5
  export declare function getRawBody(req: FFRequest, res: FFResponse, limit: number): Promise<string>;
6
- export declare function getStandardBodyParser(type: string, parser: ParseBodyFunction, FF: FalconFrame, opts: StandardBodyParserOptions): RouteHandler;
6
+ export declare function getStandardBodyParser(type: string, parser: ParseBodyFunction, opts: StandardBodyParserOptions): RouteHandler;
@@ -35,8 +35,6 @@ export function getRawBody(req, res, limit) {
35
35
  res.status(413);
36
36
  res.FF._413(req, res);
37
37
  req.destroy();
38
- // @ts-ignore
39
- error.cancel = true;
40
38
  return reject(error);
41
39
  }
42
40
  });
@@ -48,7 +46,7 @@ export function getRawBody(req, res, limit) {
48
46
  });
49
47
  });
50
48
  }
51
- export function getStandardBodyParser(type, parser, FF, opts) {
49
+ export function getStandardBodyParser(type, parser, opts) {
52
50
  const limit = parseLimit(opts.limit || "100k");
53
51
  return async (req, res, next) => {
54
52
  if ((typeof req.body == "object" && Object.keys(req.body).length) || getContentType(req) !== type) {
@@ -56,11 +54,11 @@ export function getStandardBodyParser(type, parser, FF, opts) {
56
54
  }
57
55
  try {
58
56
  const body = await getRawBody(req, res, limit);
59
- req.body = await parser(body, req, FF);
57
+ req.body = await parser(body, req, res);
60
58
  next();
61
59
  }
62
60
  catch (err) {
63
- if (err.cancel)
61
+ if (res._ended)
64
62
  return;
65
63
  req.body = {};
66
64
  next();
package/dist/body.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import FalconFrame from "./index.js";
2
1
  import { RouteHandler, StandardBodyParserOptions } from "./types.js";
3
- export declare function json(FF: FalconFrame, opts?: StandardBodyParserOptions): RouteHandler;
4
- export declare function urlencoded(FF: FalconFrame, opts?: StandardBodyParserOptions): RouteHandler;
2
+ export declare function json(opts?: StandardBodyParserOptions): RouteHandler;
3
+ export declare function urlencoded(opts?: StandardBodyParserOptions): RouteHandler;
package/dist/body.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import querystring from "querystring";
2
2
  import { getStandardBodyParser } from "./body-utils.js";
3
- export function json(FF, opts = {}) {
4
- return getStandardBodyParser("application/json", (body) => JSON.parse(body), FF, opts);
3
+ export function json(opts = {}) {
4
+ return getStandardBodyParser("application/json", (body) => JSON.parse(body), opts);
5
5
  }
6
- export function urlencoded(FF, opts = {}) {
7
- return getStandardBodyParser("application/x-www-form-urlencoded", (body) => querystring.parse(body), FF, opts);
6
+ export function urlencoded(opts = {}) {
7
+ return getStandardBodyParser("application/x-www-form-urlencoded", (body) => querystring.parse(body), opts);
8
8
  }
package/dist/index.js CHANGED
@@ -40,9 +40,9 @@ export class FalconFrame extends Router {
40
40
  ...opts,
41
41
  };
42
42
  if (!this.opts.disableJsonParser)
43
- this.addBodyParser(json(this, { limit: this.opts.bodyLimit }));
43
+ this.addBodyParser(json({ limit: this.opts.bodyLimit }));
44
44
  if (!this.opts.disableUrlencodedParser)
45
- this.addBodyParser(urlencoded(this, { limit: this.opts.bodyLimit }));
45
+ this.addBodyParser(urlencoded({ limit: this.opts.bodyLimit }));
46
46
  this.engine(".html", (path, options, callback, FF) => {
47
47
  try {
48
48
  const content = renderHTML(path, options, [], FF);
package/dist/render.d.ts CHANGED
@@ -2,4 +2,4 @@ import FalconFrame from "./index.js";
2
2
  export interface RenderOptions {
3
3
  noLayout?: boolean;
4
4
  }
5
- export declare function renderHTML(templatePath: string, data?: Record<string, any>, renderedPaths?: string[], FF?: FalconFrame, opts?: RenderOptions): string;
5
+ export declare function renderHTML(templatePath: string, data?: Record<string, any>, renderedPaths?: string[], FF?: FalconFrame<any>, opts?: RenderOptions): string;
package/dist/req.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import FalconFrame from "./index.js";
2
2
  import { FFResponse } from "./res.js";
3
3
  import { FFRequest } from "./types.js";
4
- export declare function handleRequest(req: FFRequest, res: FFResponse, FF: FalconFrame): void;
4
+ export declare function handleRequest(req: FFRequest, res: FFResponse, FF: FalconFrame<any>): void;
package/dist/req.js CHANGED
@@ -5,6 +5,7 @@ import { FFResponse } from "./res.js";
5
5
  import { validate } from "./valid.js";
6
6
  export function handleRequest(req, res, FF) {
7
7
  Object.setPrototypeOf(res, FFResponse.prototype);
8
+ req.FF = FF;
8
9
  res.FF = FF;
9
10
  const originalEnd = res.end;
10
11
  res.end = function (...any) {
package/dist/res.d.ts CHANGED
@@ -3,7 +3,7 @@ import FalconFrame from "./index.js";
3
3
  import { CookieOptions, RenderOptions } from "./types.js";
4
4
  export declare class FFResponse extends http.ServerResponse {
5
5
  _ended: boolean;
6
- FF: FalconFrame;
6
+ FF: FalconFrame<any>;
7
7
  /**
8
8
  * bind end for compatibility
9
9
  */
package/dist/types.d.ts CHANGED
@@ -17,11 +17,12 @@ export interface Query {
17
17
  export interface Body {
18
18
  [key: string]: any;
19
19
  }
20
- export type ParseBodyFunction = (body: string, req: FFRequest, FF: FalconFrame) => Promise<Record<string, any>>;
20
+ export type ParseBodyFunction = (body: string, req: FFRequest, res: FFResponse) => Promise<Record<string, any>>;
21
21
  export interface StandardBodyParserOptions {
22
22
  limit?: string | number;
23
23
  }
24
24
  export declare class FFRequest extends http.IncomingMessage {
25
+ FF: FalconFrame<any>;
25
26
  path: string;
26
27
  query: Query;
27
28
  params: Params;
package/dist/types.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import http from "http";
2
2
  export class FFRequest extends http.IncomingMessage {
3
+ FF;
3
4
  path;
4
5
  query;
5
6
  params;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/falcon-frame",
3
- "version": "0.6.3",
3
+ "version": "0.7.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "wxn0brP",