@wxn0brp/falcon-frame 0.6.0 → 0.6.1

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/index.d.ts CHANGED
@@ -1,33 +1,27 @@
1
- import { Logger, LoggerOptions } from "@wxn0brp/lucerna-log";
1
+ import { Logger } from "@wxn0brp/lucerna-log";
2
2
  import http from "http";
3
3
  import { renderHTML } from "./render.js";
4
4
  import { FFResponse } from "./res.js";
5
5
  import { Router } from "./router.js";
6
- import type { BeforeHandleRequest, EngineCallback, ErrorHandler, FFRequest, RouteHandler, ValidationErrorFormatter } from "./types.js";
7
- export interface Opts {
8
- loggerOpts?: LoggerOptions;
9
- bodyLimit?: string;
10
- disableJsonParser?: boolean;
11
- disableUrlencodedParser?: boolean;
12
- }
13
- export declare class FalconFrame<Vars extends Record<string, any> = any> extends Router {
6
+ import type { BeforeHandleRequest, CombinedVars, EngineCallback, ErrorHandler, FFOpts, FFRequest, RouteHandler, ValidationErrorFormatter } from "./types.js";
7
+ export declare class FalconFrame<Vars extends Record<string, any> = Record<string, any>> extends Router {
14
8
  logger: Logger;
15
9
  bodyParsers: RouteHandler[];
16
- vars: Vars;
17
- opts: Opts;
10
+ vars: CombinedVars<Vars>;
11
+ opts: FFOpts;
18
12
  engines: Record<string, EngineCallback>;
19
13
  _400_formatter: ValidationErrorFormatter;
20
14
  _404: RouteHandler;
21
15
  _413: RouteHandler;
22
16
  _500: ErrorHandler;
23
- constructor(opts?: Partial<Opts>);
17
+ constructor(opts?: Partial<FFOpts>);
24
18
  addBodyParser(parser: RouteHandler): this;
25
19
  listen(port: number | string, callback?: (() => void) | boolean, beforeHandleRequest?: BeforeHandleRequest): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
26
20
  getApp(beforeHandleRequest?: BeforeHandleRequest): (req: any, res: any) => Promise<void>;
27
21
  engine(ext: string, callback: EngineCallback): this;
28
- setVar(key: keyof Vars, value: typeof this.vars[keyof Vars]): void;
29
- set(key: keyof Vars, value: typeof this.vars[keyof Vars]): void;
30
- getVar(key: string): typeof this.vars[keyof Vars];
22
+ setVar(key: keyof CombinedVars<Vars>, value: typeof this.vars[keyof CombinedVars<Vars>]): void;
23
+ set(key: keyof CombinedVars<Vars>, value: typeof this.vars[keyof CombinedVars<Vars>]): void;
24
+ getVar(key: keyof CombinedVars<Vars>): typeof this.vars[keyof CombinedVars<Vars>];
31
25
  /**
32
26
  * Sets the allowed origins for CORS.
33
27
  * This method is a shortcut that simplifies CORS configuration
@@ -50,5 +44,6 @@ export declare class FalconFrame<Vars extends Record<string, any> = any> extends
50
44
  }
51
45
  export default FalconFrame;
52
46
  export * as Helpers from "./helpers.js";
47
+ export { FFOpts as Opts } from "./types.js";
53
48
  export { validateBody } from "./valid.js";
54
49
  export { FFRequest, FFResponse, renderHTML, RouteHandler, Router };
package/dist/index.js CHANGED
@@ -92,7 +92,7 @@ export class FalconFrame extends Router {
92
92
  if (result || res._ended)
93
93
  return;
94
94
  }
95
- await handleRequest(req, res, this);
95
+ handleRequest(req, res, this);
96
96
  };
97
97
  }
98
98
  engine(ext, callback) {
package/dist/render.d.ts CHANGED
@@ -1,6 +1,2 @@
1
1
  import FalconFrame from "./index.js";
2
- interface RenderData {
3
- [key: string]: string;
4
- }
5
- export declare function renderHTML(templatePath: string, data: RenderData, renderedPaths?: string[], FF?: FalconFrame): string;
6
- export {};
2
+ export declare function renderHTML(templatePath: string, data?: Record<string, any>, renderedPaths?: string[], FF?: FalconFrame): string;
package/dist/render.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- export function renderHTML(templatePath, data, renderedPaths = [], FF) {
3
+ export function renderHTML(templatePath, data = {}, renderedPaths = [], FF) {
4
4
  try {
5
5
  const realPath = path.resolve(templatePath);
6
6
  if (renderedPaths.includes(realPath))
7
7
  return `<!-- Circular dependency detected: tried to render ${templatePath} again -->`;
8
- if (FF && FF.vars["render data"]) {
8
+ const FFData = FF && FF.getVar("render data");
9
+ if (FFData) {
9
10
  data = {
10
- ...FF.vars["render data"],
11
+ ...FFData,
11
12
  ...data,
12
13
  };
13
14
  }
@@ -33,7 +34,8 @@ export function renderHTML(templatePath, data, renderedPaths = [], FF) {
33
34
  }
34
35
  });
35
36
  // Layout
36
- if (FF && FF.vars["layout"]) {
37
+ const FFLayout = FF && FF.getVar("layout");
38
+ if (FFLayout) {
37
39
  const hasHtmlStructure = /<\s*html|<\s*body/i.test(template);
38
40
  const forceLayout = /<!--\s*force-layout\s*-->/.test(template);
39
41
  const forceNoLayout = /<!--\s*force-no-layout\s*-->/.test(template);
@@ -41,7 +43,7 @@ export function renderHTML(templatePath, data, renderedPaths = [], FF) {
41
43
  return template;
42
44
  if (!hasHtmlStructure && forceNoLayout)
43
45
  return template;
44
- return renderHTML(FF.vars["layout"], { ...data, body: template }, [...renderedPaths, realPath], FF);
46
+ return renderHTML(FFLayout, { ...data, body: template }, [...renderedPaths, realPath], FF);
45
47
  }
46
48
  return template;
47
49
  }
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { LoggerOptions } from "@wxn0brp/lucerna-log";
1
2
  import FalconFrame from "./index.js";
2
3
  import { FFResponse } from "./res.js";
3
4
  import http from "http";
@@ -73,3 +74,16 @@ export interface RenderOptions {
73
74
  notAppendExt?: boolean;
74
75
  notShareFF?: boolean;
75
76
  }
77
+ export interface FFOpts {
78
+ loggerOpts?: LoggerOptions;
79
+ bodyLimit?: string;
80
+ disableJsonParser?: boolean;
81
+ disableUrlencodedParser?: boolean;
82
+ }
83
+ export type FFVars = {
84
+ "render data": Record<string, any>;
85
+ "view engine": string;
86
+ "views": string;
87
+ "layout": string;
88
+ };
89
+ export type CombinedVars<ExtraVars> = ExtraVars & FFVars;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/falcon-frame",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "wxn0brP",