fluxion-ts 0.0.9 → 0.0.11

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
@@ -166,9 +166,17 @@ Main `fluxion({...})` options:
166
166
  - `dir`: dynamic directory (handler root)
167
167
  - `host`: listen host
168
168
  - `port`: listen port
169
+ - `metaPort`: primary meta API port (defaults to `port + 1`)
169
170
  - `maxRequestBytes`: max request body size (returns 413 when exceeded)
170
171
  - `logger`: `one-line` / `json-line` / custom function
171
172
 
173
+ ## Meta APIs
174
+
175
+ Meta APIs are served by the primary process on `metaPort`:
176
+
177
+ - `GET /_fluxion/healthz`
178
+ - `GET /_fluxion/workers` (worker status + cpu/memory stats)
179
+
172
180
  ## Important
173
181
 
174
182
  Legacy handler-level `db` declarations are removed:
package/dist/index.d.ts CHANGED
@@ -1,126 +1,118 @@
1
- import http from 'node:http';
2
-
3
- type LogLevel = 'INFO' | 'WARN' | 'ERROR' | 'SUCC';
4
- interface LogEntry {
5
- timestamp: string;
6
- level: LogLevel;
7
- event: string;
8
- message?: string;
9
- [key: string]: unknown;
1
+ interface InjectionConfig {
2
+ /**
3
+ * Name that you can use to refer to this injected dependency in your handlers.
4
+ */
5
+ name: string;
6
+
7
+ /**
8
+ * The `.mjs` path that exports the factory function to create the dependency instance.
9
+ */
10
+ modulePath: string;
10
11
  }
11
- type LoggerMode = 'one-line' | 'json-line';
12
- type LoggerSink = (entry: LogEntry) => void;
13
- type LoggerOption = LoggerMode | LoggerSink;
12
+
13
+ type LoggerOption = 'one-line' | 'json-line' | InjectionConfig;
14
14
 
15
15
  /**
16
16
  * Worker runtime tuning options.
17
17
  */
18
- interface ExecutorOptions {
19
- /**
20
- * Request timeout in milliseconds.
21
- */
22
- requestTimeoutMs: number;
23
- /**
24
- * Maximum concurrent requests allowed in the pool.
25
- */
26
- maxInflight: number;
27
- /**
28
- * Soft heap threshold in MB. Idle worker may restart after crossing it.
29
- */
30
- memorySoftLimitMb: number;
31
- /**
32
- * ! Hard heap threshold in MB. Worker is restarted once reached.
33
- */
34
- memoryHardLimitMb: number;
35
- /**
36
- * Memory telemetry interval in milliseconds.
37
- */
38
- memorySampleIntervalMs: number;
39
- /**
40
- * ! V8 old-generation limit per worker in MB.
41
- */
42
- maxOldGenerationSizeMb: number;
43
- /**
44
- * ! V8 young-generation limit per worker in MB.
45
- */
46
- maxYoungGenerationSizeMb: number;
47
- /**
48
- * Worker stack size in MB.
49
- */
50
- stackSizeMb: number;
51
- /**
52
- * ! Maximum response payload bytes allowed from worker to main thread.
53
- */
54
- maxResponseBytes: number;
55
- }
56
- /**
57
- * Custom worker item used by `workerStrategy`.
58
- */
59
- interface WorkerStrategyCustomItem extends Partial<ExecutorOptions> {
60
- /**
61
- * Stable worker id.
62
- */
63
- id: string;
64
- /**
65
- * Database names this worker can access.
66
- */
67
- db: string[];
68
- }
69
- /**
70
- * Worker strategy selector.
71
- */
72
- type WorkerStrategy = 'all' | WorkerStrategyCustomItem[];
18
+ interface WorkerOptions {
19
+ maxWorkerCount: number;
73
20
 
74
- /**
75
- * Database config item accepted by server options.
76
- */
77
- interface FluxionDatabaseConfig {
78
- /**
79
- * Stable database name.
80
- */
81
- name: string;
21
+ /**
22
+ * Request timeout in milliseconds.
23
+ */
24
+ requestTimeoutMs: number;
25
+
26
+ /**
27
+ * Maximum concurrent requests allowed in the pool.
28
+ */
29
+ maxInflight: number;
30
+
31
+ /**
32
+ * Soft heap threshold in MB. Idle worker may restart after crossing it.
33
+ */
34
+ memorySoftLimitMb: number;
35
+
36
+ /**
37
+ * ! Hard heap threshold in MB. Worker is restarted once reached.
38
+ */
39
+ memoryHardLimitMb: number;
40
+
41
+ /**
42
+ * Memory telemetry interval in milliseconds.
43
+ */
44
+ memorySampleIntervalMs: number;
45
+
46
+ /**
47
+ * ! V8 old-generation limit per worker in MB.
48
+ */
49
+ maxOldGenerationSizeMb: number;
50
+
51
+ /**
52
+ * ! V8 young-generation limit per worker in MB.
53
+ */
54
+ maxYoungGenerationSizeMb: number;
55
+
56
+ /**
57
+ * Worker stack size in MB.
58
+ */
59
+ stackSizeMb: number;
60
+
61
+ /**
62
+ * ! Maximum response payload bytes allowed from worker to main thread.
63
+ */
64
+ maxResponseBytes: number;
82
65
  }
83
- /**
84
- * User-provided database config input.
85
- */
86
- type FluxionDatabaseInput = string | FluxionDatabaseConfig;
66
+
87
67
  interface FluxionOptions {
88
- /**
89
- * The directory where dynamic files (e.g. uploaded files) will be stored. It will be created if it doesn't exist.
90
- * It is recommended to use an empty directory that is not used for any other purpose, to avoid potential conflicts or security issues.
91
- */
92
- dir: string;
93
- host: string;
94
- port: number;
95
- /**
96
- * Declared database names used by worker strategy routing.
97
- */
98
- databases?: FluxionDatabaseInput[];
99
- /**
100
- * Optional path to private db config file.
101
- * Defaults to `./.fluxion-private/db.config.cjs`.
102
- */
103
- dbConfigPath?: string;
104
- /**
105
- * Worker routing strategy.
106
- */
107
- workerStrategy?: WorkerStrategy;
108
- /**
109
- * Base worker runtime option overrides.
110
- */
111
- workerOptions?: Partial<ExecutorOptions>;
112
- /**
113
- * Maximum request body bytes accepted by dynamic handlers.
114
- * Requests larger than this limit will return 413.
115
- */
116
- maxRequestBytes?: number;
117
- /**
118
- * Logger output mode or custom logger sink.
119
- * Defaults to `one-line`.
120
- */
121
- logger?: LoggerOption;
68
+ /**
69
+ * The directory where dynamic files (e.g. uploaded files) will be stored. It will be created if it doesn't exist.
70
+ * It is recommended to use an empty directory that is not used for any other purpose, to avoid potential conflicts or security issues.
71
+ */
72
+ dir: string;
73
+
74
+ host: string;
75
+
76
+ port: number;
77
+
78
+ /**
79
+ * Port listened by primary process for meta APIs.
80
+ * Defaults to `port + 1`.
81
+ */
82
+ metaPort?: number;
83
+
84
+ /**
85
+ * Injections will be injected into `globalThis[Symbol.for('fluxion-injections')]`;
86
+ * - **name**: Name that you can use to refer to this injected dependency in your handlers.
87
+ * - **modulePath**: The `.mjs` path that exports the factory function to create the dependency instance.
88
+ */
89
+ injections?: InjectionConfig[];
90
+
91
+ /**
92
+ * Inject Path that will be used like `path.join(moduleDir,modulepath)`
93
+ * - default is `process.cwd()`
94
+ */
95
+ moduleDir?: string;
96
+
97
+ /**
98
+ * Base worker runtime option overrides.
99
+ */
100
+ workerOptions?: Partial<WorkerOptions>;
101
+
102
+ /**
103
+ * Maximum request body bytes accepted by dynamic handlers.
104
+ * Requests larger than this limit will return 413.
105
+ */
106
+ maxRequestBytes?: number;
107
+
108
+ /**
109
+ * Logger output mode or custom logger sink.
110
+ * Defaults to `one-line`.
111
+ */
112
+ logger?: LoggerOption;
122
113
  }
123
- declare function fluxion(options: FluxionOptions): http.Server;
114
+
115
+ declare function fluxion(options: FluxionOptions): Promise<void>;
124
116
 
125
117
  export { fluxion };
126
118
  export type { FluxionOptions };