@wxn0brp/falcon-frame 0.6.2 → 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.
- package/dist/body-utils.d.ts +2 -2
- package/dist/body-utils.js +3 -5
- package/dist/body.d.ts +2 -3
- package/dist/body.js +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -6
- package/dist/render.d.ts +1 -1
- package/dist/req.d.ts +1 -1
- package/dist/req.js +1 -0
- package/dist/res.d.ts +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.js +1 -0
- package/package.json +1 -1
package/dist/body-utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
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,
|
|
6
|
+
export declare function getStandardBodyParser(type: string, parser: ParseBodyFunction, opts: StandardBodyParserOptions): RouteHandler;
|
package/dist/body-utils.js
CHANGED
|
@@ -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,
|
|
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,
|
|
57
|
+
req.body = await parser(body, req, res);
|
|
60
58
|
next();
|
|
61
59
|
}
|
|
62
60
|
catch (err) {
|
|
63
|
-
if (
|
|
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(
|
|
4
|
-
export declare function urlencoded(
|
|
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(
|
|
4
|
-
return getStandardBodyParser("application/json", (body) => JSON.parse(body),
|
|
3
|
+
export function json(opts = {}) {
|
|
4
|
+
return getStandardBodyParser("application/json", (body) => JSON.parse(body), opts);
|
|
5
5
|
}
|
|
6
|
-
export function urlencoded(
|
|
7
|
-
return getStandardBodyParser("application/x-www-form-urlencoded", (body) => querystring.parse(body),
|
|
6
|
+
export function urlencoded(opts = {}) {
|
|
7
|
+
return getStandardBodyParser("application/x-www-form-urlencoded", (body) => querystring.parse(body), opts);
|
|
8
8
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { renderHTML } from "./render.js";
|
|
|
4
4
|
import { FFResponse } from "./res.js";
|
|
5
5
|
import { Router } from "./router.js";
|
|
6
6
|
import type { BeforeHandleRequest, CombinedVars, EngineCallback, ErrorHandler, FFOpts, FFRequest, RouteHandler, ValidationErrorFormatter } from "./types.js";
|
|
7
|
-
export declare class FalconFrame<Vars extends Record<string, any> =
|
|
7
|
+
export declare class FalconFrame<Vars extends Record<string, any> = {}> extends Router {
|
|
8
8
|
logger: Logger;
|
|
9
9
|
bodyParsers: RouteHandler[];
|
|
10
10
|
vars: CombinedVars<Vars>;
|
|
@@ -19,9 +19,9 @@ export declare class FalconFrame<Vars extends Record<string, any> = Record<strin
|
|
|
19
19
|
listen(port: number | string, callback?: (() => void) | boolean, beforeHandleRequest?: BeforeHandleRequest): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
20
20
|
getApp(beforeHandleRequest?: BeforeHandleRequest): (req: any, res: any) => Promise<void>;
|
|
21
21
|
engine(ext: string, callback: EngineCallback): this;
|
|
22
|
-
setVar
|
|
23
|
-
set
|
|
24
|
-
getVar
|
|
22
|
+
setVar<K extends keyof CombinedVars<Vars>>(key: K, value: CombinedVars<Vars>[K]): this;
|
|
23
|
+
set<K extends keyof CombinedVars<Vars>>(key: K, value: CombinedVars<Vars>[K]): this;
|
|
24
|
+
getVar<K extends keyof CombinedVars<Vars>>(key: K): CombinedVars<Vars>[K];
|
|
25
25
|
/**
|
|
26
26
|
* Sets the allowed origins for CORS.
|
|
27
27
|
* This method is a shortcut that simplifies CORS configuration
|
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(
|
|
43
|
+
this.addBodyParser(json({ limit: this.opts.bodyLimit }));
|
|
44
44
|
if (!this.opts.disableUrlencodedParser)
|
|
45
|
-
this.addBodyParser(urlencoded(
|
|
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);
|
|
@@ -102,15 +102,13 @@ export class FalconFrame extends Router {
|
|
|
102
102
|
return this;
|
|
103
103
|
}
|
|
104
104
|
setVar(key, value) {
|
|
105
|
-
// @ts-ignore
|
|
106
105
|
this.vars[key] = value;
|
|
106
|
+
return this;
|
|
107
107
|
}
|
|
108
108
|
set(key, value) {
|
|
109
|
-
|
|
110
|
-
this.vars[key] = value;
|
|
109
|
+
return this.setVar(key, value);
|
|
111
110
|
}
|
|
112
111
|
getVar(key) {
|
|
113
|
-
// @ts-ignore
|
|
114
112
|
return this.vars[key];
|
|
115
113
|
}
|
|
116
114
|
/**
|
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
|
|
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
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,
|
|
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