@nmvuong92/fluxe 0.6.0 → 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/lib/core/engine.d.ts +8 -9
- package/lib/server_factory.d.ts +1 -0
- package/lib/server_factory.js +5 -3
- package/package.json +1 -1
package/lib/core/engine.d.ts
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
import type { ComponentType } from "react";
|
|
2
|
-
import type { Backend } from "../backends/types";
|
|
3
2
|
import type { HeadMeta } from "./seo";
|
|
4
3
|
import type { Session } from "./auth";
|
|
5
4
|
import type { TFn } from "./i18n";
|
|
6
|
-
export interface Ctx<I> {
|
|
5
|
+
export interface Ctx<I, B = any> {
|
|
7
6
|
input: I;
|
|
8
|
-
backend:
|
|
7
|
+
backend: B;
|
|
9
8
|
session?: Session | null;
|
|
10
9
|
locale?: string;
|
|
11
10
|
t?: TFn;
|
|
12
11
|
}
|
|
13
|
-
export type Loader<I, O> = (ctx: Ctx<I>) => Promise<O>;
|
|
14
|
-
export type Action<I, O> = (ctx: Ctx<I>) => Promise<O>;
|
|
12
|
+
export type Loader<I, O, B = any> = (ctx: Ctx<I, B>) => Promise<O>;
|
|
13
|
+
export type Action<I, O, B = any> = (ctx: Ctx<I, B>) => Promise<O>;
|
|
15
14
|
export type Hydration = "static" | "island";
|
|
16
|
-
export interface CellDef<I, O> {
|
|
15
|
+
export interface CellDef<I, O, B = any> {
|
|
17
16
|
id: string;
|
|
18
17
|
route: string;
|
|
19
18
|
hydration?: Hydration;
|
|
20
|
-
loader: Loader<I, O>;
|
|
19
|
+
loader: Loader<I, O, B>;
|
|
21
20
|
view: ComponentType<{
|
|
22
21
|
data: O;
|
|
23
22
|
}>;
|
|
24
|
-
actions?: Record<string, Action<any, any>>;
|
|
23
|
+
actions?: Record<string, Action<any, any, B>>;
|
|
25
24
|
head?: (data: O) => HeadMeta;
|
|
26
25
|
layout?: string;
|
|
27
26
|
requireAuth?: boolean;
|
|
28
27
|
requireRole?: string;
|
|
29
28
|
cache?: boolean;
|
|
30
29
|
}
|
|
31
|
-
export declare function defineCell<I, O>(c: CellDef<I, O>): CellDef<I, O>;
|
|
30
|
+
export declare function defineCell<I, O, B = any>(c: CellDef<I, O, B>): CellDef<I, O, B>;
|
package/lib/server_factory.d.ts
CHANGED
package/lib/server_factory.js
CHANGED
|
@@ -98,9 +98,11 @@ export function makeServer(manifest, cells, layouts = {}, opts = {}) {
|
|
|
98
98
|
// Cells được TIÊM từ app (DI) — engine không import ngược vào app/. Thêm trang = sửa app/app.ts.
|
|
99
99
|
const matchRoute = makeRouter(cells);
|
|
100
100
|
const byId = new Map(cells.map((c) => [c.id, c]));
|
|
101
|
-
// Backend
|
|
102
|
-
|
|
103
|
-
const
|
|
101
|
+
// Backend USER-OWNED (app/backend.ts) inject qua opts.backend → dùng cho mọi cell.
|
|
102
|
+
// Nếu app không truyền → fallback driver built-in giải từ manifest (memory/sqlite) cho quick-start.
|
|
103
|
+
const userBackend = opts.backend;
|
|
104
|
+
const backends = userBackend === undefined ? backendsFromManifest(manifest) : null;
|
|
105
|
+
const backendFor = (id) => userBackend ?? backends.byCell.get(id) ?? backends.default;
|
|
104
106
|
// Resolved Container: service realtime đăng ký LƯỜI — chỉ tạo khi thật sự dùng (SSE/action).
|
|
105
107
|
// App không realtime → broker/presence KHÔNG bao giờ bootstrap. resolved() ở /_fluxe/stats.
|
|
106
108
|
const container = createContainer();
|