fusion-framework 1.3.0 → 2.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
@@ -16,6 +16,8 @@ From this repo:
16
16
  cd crates/fusion-node && npm install && npm run build:debug
17
17
  ```
18
18
 
19
+ **Important:** `napi build` must use `--js false` so it does not overwrite `index.js` (the FusionApp / middleware layer). The npm scripts already pass this flag.
20
+
19
21
  Scaffold with [Fusion Tool](https://github.com/cipherunits/fusion-tool):
20
22
 
21
23
  ```bash
@@ -35,7 +37,7 @@ export const ItemModule = route('/api/[module]/{id}')(
35
37
  },
36
38
  )
37
39
 
38
- const MIDDLEWARE = [] // register with app.use() — see securityHeaders, cors, requestId, …
40
+ const MIDDLEWARE = [] // add middleware explicitly, e.g. frameworkHeaders()
39
41
 
40
42
  settings.ensureLoaded()
41
43
  const app = new FusionApp(getSettings())
Binary file
Binary file
Binary file
Binary file
package/index.d.ts CHANGED
@@ -1,148 +1,87 @@
1
- export class App {
2
- constructor()
3
- route(method: string, path: string, handler: (req: FusionRequest) => FusionResponse | string): void
4
- listen(host: string, port: number): Promise<void>
5
- }
6
-
7
- export class Settings {
8
- constructor()
9
- loadJson(path?: string | null, env?: string | null, extraRoots?: string[]): void
10
- ensureLoaded(extraRoots?: string[]): void
11
- merge(values: Record<string, unknown>): void
12
- get(key: string, defaultValue?: unknown): unknown
13
- readonly host: string
14
- readonly port: number
15
- readonly debug: boolean
16
- readonly env: string
17
- }
18
-
19
- export class FusionBaseApi {
20
- request: FusionRequest
21
- constructor(request: FusionRequest)
22
- readonly method: string
23
- readonly path: string
24
- readonly body: string
25
- readonly headers: Record<string, string>
26
- readonly params: Record<string, string>
27
- readonly query: Record<string, string>
28
- readonly state: Record<string, unknown>
29
- response(body?: unknown, status?: number, headers?: Record<string, string>): FusionResponse
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ export declare function getHttpMethods(): Array<string>
7
+ export declare function apiResourceNameJs(className: string): string
8
+ export declare function resolveRoutePathJs(template: string, className: string): string
9
+ export declare function coerceParamJs(raw: string, kind?: string | undefined | null): unknown
10
+ export interface HttpStatusCode {
11
+ name: string
12
+ code: number
30
13
  }
31
-
32
- export class HTTPException extends Error {
33
- status: number
34
- detail: unknown
35
- headers: Record<string, string>
36
- constructor(status: number, detail?: unknown, headers?: Record<string, string>)
37
- toResponse(): FusionResponse
38
- }
39
-
40
- export class FusionApp {
41
- constructor(settings?: Partial<FusionSettings>)
42
- use(middleware: FusionMiddleware): void
43
- mount(): void
44
- listen(host?: string, port?: number): Promise<void>
14
+ export declare function getHttpStatusCodes(): Array<HttpStatusCode>
15
+ export interface HttpHeaderConstant {
16
+ name: string
17
+ value: string
45
18
  }
46
-
47
- export type RouteOptions = {
48
- tags?: string[]
49
- desc?: string
50
- title?: string
51
- version?: string
52
- deprecated?: boolean
53
- middleware?: FusionMiddleware[]
54
- roles?: string[]
55
- roleClaim?: string
56
- roleStateKey?: string
19
+ export declare function getHttpHeaderConstants(): Array<HttpHeaderConstant>
20
+ export declare function headerAttachment(filename: string): Record<string, string>
21
+ export declare function headerInline(filename?: string | undefined | null): Record<string, string>
22
+ export declare function headerContentType(mediaType: string, charset?: string | undefined | null): Record<string, string>
23
+ export declare function headerLocation(url: string): Record<string, string>
24
+ export declare function headerCacheControl(value: string): Record<string, string>
25
+ export declare function headerDownload(filename: string, mediaType?: string | undefined | null): Record<string, string>
26
+ export declare function getFingerprintHeaders(): Record<string, string>
27
+ /** True when the client prefers JSON (`Accept` or `?format=json`). */
28
+ export declare function prefersJsonJs(accept?: string | undefined | null, formatQuery?: string | undefined | null): boolean
29
+ /** Render a Tera template file relative to `templates_root` (default `"templates"`). */
30
+ export declare function renderTemplateJs(templateName: string, context: JsJson, templatesRoot?: string | undefined | null): string
31
+ export interface PaginationParams {
32
+ page: number
33
+ pageSize: number
34
+ offset: number
57
35
  }
58
-
59
- export function router(path: string, options?: RouteOptions): <T>(ApiClass: T) => T
60
- /** Alias of `router`. */
61
- export function route(path: string, options?: RouteOptions): <T>(ApiClass: T) => T
62
-
63
- export function bearerJwt(options?: {
64
- stateKey?: string
65
- header?: string
66
- verify?: (token: string) => Record<string, unknown> | null
67
- }): FusionMiddleware
68
-
69
- export function requireRoles(...roles: string[]): FusionMiddleware
70
- export function requireRoles(options: {
71
- roles: string[]
72
- claim?: string
73
- stateKey?: string
74
- }): FusionMiddleware
75
-
76
- export function runMiddlewareChain(
77
- request: FusionRequest,
78
- middlewares: FusionMiddleware[],
79
- handler: (request: FusionRequest) => unknown | Promise<unknown>,
80
- ): Promise<unknown>
81
-
82
- export function apiResourceName(cls: { name: string } | string): string
83
- export function resolveRoutePath(path: string, cls: { name: string }): string
84
- export function configure(settings: Record<string, unknown>): FusionSettings
85
- export function getSettings(): FusionSettings
86
- export function run(
87
- options?: string | { settingsModule?: string; middleware?: FusionMiddleware[] },
88
- ): Promise<FusionApp>
89
- export function coerceParam(raw: string, kind?: string): unknown
90
- export function getHttpMethods(): string[]
91
- export function apiResourceNameJs(className: string): string
92
- export function resolveRoutePathJs(template: string, className: string): string
93
- export function coerceParamJs(raw: string, kind?: string): unknown
94
-
95
- export const settings: Settings
96
- export const status: Record<string, number>
97
- export const header: HeaderModule
98
- export const HTTP_METHODS: string[]
99
-
100
- export interface HeaderModule {
101
- [name: string]: string | ((...args: any[]) => Record<string, string>)
102
- CONTENT_TYPE: string
103
- CONTENT_DISPOSITION: string
104
- LOCATION: string
105
- AUTHORIZATION: string
106
- APPLICATION_JSON: string
107
- APPLICATION_OCTET_STREAM: string
108
- APPLICATION_PDF: string
109
- attachment(filename: string): Record<string, string>
110
- inline(filename?: string | null): Record<string, string>
111
- contentType(mediaType: string, charset?: string | null): Record<string, string>
112
- location(url: string): Record<string, string>
113
- cacheControl(value: string): Record<string, string>
114
- download(filename: string, mediaType?: string | null): Record<string, string>
115
- fingerprint(): Record<string, string>
116
- }
117
-
118
- export interface FusionSettings {
119
- host: string
120
- port: number
121
- debug: boolean
122
- env?: string
36
+ export declare function parsePagination(query: object, defaultPageSize?: number | undefined | null, maxPageSize?: number | undefined | null): PaginationParams
37
+ export declare function paginatedBody(items: unknown, total: number, params: PaginationParams): unknown
38
+ /** Apply `cache.*` from a Settings instance to the process-wide cache. */
39
+ export declare function cacheConfigure(settings: Settings): void
40
+ /** Install a driver explicitly (default moka). */
41
+ export declare function cacheConfigureDriver(driver?: string | undefined | null, maxCapacity?: number | undefined | null, defaultTtl?: number | undefined | null): void
42
+ export declare function cacheSet(key: string, value: JsJson, ttl?: number | undefined | null): void
43
+ export declare function cacheGet(key: string): unknown
44
+ export declare function cacheDelete(key: string): boolean
45
+ export declare function cacheExists(key: string): boolean
46
+ export declare function cacheGetOrSet(key: string, default: JsJson, ttl?: number | undefined | null): unknown
47
+ export declare function cacheDeleteOrSet(key: string, value: JsJson, ttl?: number | undefined | null): unknown
48
+ export declare function cacheExistsOrSet(key: string, value: JsJson, ttl?: number | undefined | null): boolean
49
+ export declare function cacheDriver(): string
50
+ export declare function cacheClear(): void
51
+ export declare function cacheReset(): void
52
+ export declare function cacheSnapshot(): unknown
53
+ export declare function cachePanelContext(): unknown
54
+ /**
55
+ * Spawn a JS function on the Tokio background runtime. Returns task id.
56
+ *
57
+ * Uses `call_async` so status becomes `done` only after the JS callback runs
58
+ * (sync `Blocking` can return before the Node event loop drains the TSFN).
59
+ */
60
+ export declare function taskSpawn(callback: (...args: any[]) => any): string
61
+ /** Spawn a JS function after `delay_ms` milliseconds. */
62
+ export declare function taskSpawnAfter(delayMs: number, callback: (...args: any[]) => any): string
63
+ /** Cancel a background task by id. */
64
+ export declare function taskCancel(id: string): boolean
65
+ /** Status string for a task id, or null if unknown. */
66
+ export declare function taskStatus(id: string): string | null
67
+ /** Reset the task registry (tests). */
68
+ export declare function taskReset(): void
69
+ /** JSON snapshot of tracked background tasks. */
70
+ export declare function taskSnapshot(): unknown
71
+ export declare class Settings {
72
+ constructor()
73
+ loadJson(path?: string | undefined | null, envName?: string | undefined | null, extraRoots?: Array<string> | undefined | null): void
74
+ ensureLoaded(extraRoots?: Array<string> | undefined | null): void
75
+ merge(values: unknown): void
76
+ get(key: string, default?: unknown | undefined | null): unknown
77
+ get host(): string
78
+ get port(): number
79
+ get debug(): boolean
80
+ get reload(): boolean
81
+ get env(): string
123
82
  }
124
-
125
- export interface FusionRequest {
126
- method: string
127
- path: string
128
- body: string
129
- headers: Record<string, string>
130
- params: Record<string, string>
131
- query: Record<string, string>
132
- state?: Record<string, unknown>
83
+ export declare class App {
84
+ constructor()
85
+ route(method: string, path: string, handler: (...args: any[]) => any): void
86
+ listen(host: string, port: number): Promise<void>
133
87
  }
134
-
135
- export type FusionMiddleware = (
136
- request: FusionRequest,
137
- callNext: (request: FusionRequest) => unknown | Promise<unknown>,
138
- ) => unknown | Promise<unknown>
139
-
140
- export function frameworkHeaders(): FusionMiddleware
141
-
142
- export type FusionResponse =
143
- | string
144
- | {
145
- status?: number
146
- body?: unknown
147
- headers?: Record<string, string>
148
- }