@fuzionx/bridge 0.1.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.
Files changed (3) hide show
  1. package/index.d.ts +70 -0
  2. package/index.js +44 -0
  3. package/package.json +29 -0
package/index.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @fuzionx/bridge — FuzionX Native Bridge N-API bindings
3
+ *
4
+ * High-performance Rust native module for Node.js.
5
+ * libuv Fusion architecture: 167K RPS (×1), 594K RPS (×4 cluster)
6
+ */
7
+
8
+ // ── Boot & Config ──
9
+ export function bootSystem(options: { configPath?: string; port?: number; workers?: number }): void;
10
+ export function reloadConfig(): void;
11
+ export function reloadFusionConfig(): void;
12
+ export function getConfig(): Record<string, any>;
13
+ export function getAppConfig(): string;
14
+ export function getAspConfig(): string;
15
+ export function getWorkerCount(): number;
16
+
17
+ // ── Fusion Server ──
18
+ export function startFusionServer(port: number, handler: (req: any) => any): void;
19
+ export function stopFusionServer(): void;
20
+ export function cleanupIdleConnections(timeoutMs: number): number;
21
+
22
+ // ── Routing ──
23
+ export function registerRoute(method: string, path: string): number;
24
+ export function buildRoutes(): void;
25
+
26
+ // ── WebSocket ──
27
+ export function wsRegisterOnConnect(callback: (namespace: string, sessionId: string) => void): void;
28
+ export function wsRegisterOnMessage(callback: (namespace: string, sessionId: string, data: string) => void): void;
29
+ export function wsRegisterOnDisconnect(callback: (namespace: string, sessionId: string) => void): void;
30
+ export function wsBroadcastAll(data: string): void;
31
+ export function wsBroadcastExcluding(excludeId: string, data: string): void;
32
+ export function wsSendTo(sessionId: string, data: string): boolean;
33
+ export function wsSendToMany(sessionIds: string[], data: string): number;
34
+ export function wsSendToMetadataMatch(key: string, value: string, data: string): number;
35
+ export function wsSetMetadata(sessionId: string, key: string, value: string): void;
36
+ export function wsGetMetadata(sessionId: string, key: string): string | null;
37
+ export function wsRemoveInactive(timeoutMs: number): number;
38
+ export function wsGetAllSessionIds(): string[];
39
+ export function wsGetOnlineCount(): number;
40
+
41
+ // ── Session ──
42
+ export function sessionLoad(sessionId: string): string | null;
43
+ export function sessionGet(sessionId: string): string | null;
44
+ export function sessionSet(sessionId: string, data: string, ttl: number): void;
45
+ export function sessionRenew(sessionId: string): void;
46
+ export function sessionDestroy(sessionId: string): boolean;
47
+ export function sessionCleanup(): number;
48
+ export function sessionGenerateId(): string;
49
+
50
+ // ── Crypto ──
51
+ export function encrypt(plaintext: string, key: string): string;
52
+ export function decrypt(ciphertext: string, key: string): string;
53
+ export function encryptTransport(plaintext: string, rawKey: string): string;
54
+ export function decryptTransport(ciphertext: string, rawKey: string): string;
55
+ export function sha256(input: string): string;
56
+ export function md5(input: string): string;
57
+ export function uuid(): string;
58
+ export function deriveKey(secret: string, domain: string, ua: string, ts: string): string;
59
+ export function getUaSlice(ua: string, ts: string): string;
60
+
61
+ // ── SSR / I18n ──
62
+ export function renderTemplateFile(filePath: string, context: string): string;
63
+ export function renderString(template: string, context: string): string;
64
+ export function translate(key: string, locale: string, params?: string): string;
65
+
66
+ // ── Logging ──
67
+ export function logInfo(msg: string): void;
68
+ export function logWarn(msg: string): void;
69
+ export function logError(msg: string): void;
70
+ export function logDebug(msg: string): void;
package/index.js ADDED
@@ -0,0 +1,44 @@
1
+ /* eslint-disable no-console */
2
+ /**
3
+ * @fuzionx/bridge — 플랫폼별 네이티브 모듈 로더
4
+ *
5
+ * napi-rs 표준 패턴: OS/arch를 감지하여 올바른 플랫폼 패키지의 .node 파일을 로드.
6
+ */
7
+
8
+ const { platform, arch } = process;
9
+
10
+ function getBinding() {
11
+ const platformMap = {
12
+ 'linux-x64': { pkg: '@fuzionx/bridge-linux-x64-gnu', file: 'fuzionx-bridge.linux-x64-gnu.node' },
13
+ 'darwin-arm64': { pkg: '@fuzionx/bridge-darwin-arm64', file: 'fuzionx-bridge.darwin-arm64.node' },
14
+ 'win32-x64': { pkg: '@fuzionx/bridge-win32-x64-msvc', file: 'fuzionx-bridge.win32-x64-msvc.node' },
15
+ };
16
+
17
+ const key = `${platform}-${arch}`;
18
+ const target = platformMap[key];
19
+
20
+ if (!target) {
21
+ throw new Error(
22
+ `@fuzionx/bridge: 지원하지 않는 플랫폼입니다: ${key}\n` +
23
+ `지원 플랫폼: ${Object.keys(platformMap).join(', ')}`
24
+ );
25
+ }
26
+
27
+ try {
28
+ return require(target.pkg);
29
+ } catch (loadError) {
30
+ // fallback: 같은 디렉터리에서 .node 파일 직접 로드 (개발 환경)
31
+ try {
32
+ return require(`./${target.file}`);
33
+ } catch (_) {
34
+ throw new Error(
35
+ `@fuzionx/bridge: 네이티브 모듈을 로드할 수 없습니다.\n` +
36
+ `패키지 '${target.pkg}'가 설치되어 있지 않습니다.\n` +
37
+ `'npm install @fuzionx/bridge'를 다시 실행해 주세요.\n` +
38
+ `원인: ${loadError.message}`
39
+ );
40
+ }
41
+ }
42
+ }
43
+
44
+ module.exports = getBinding();
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@fuzionx/bridge",
3
+ "version": "0.1.0",
4
+ "description": "FuzionX native bridge — high-performance N-API addon for Node.js",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "files": ["index.js", "index.d.ts"],
8
+ "napi": {
9
+ "binaryName": "fuzionx-bridge",
10
+ "targets": [
11
+ "x86_64-unknown-linux-gnu",
12
+ "aarch64-apple-darwin",
13
+ "x86_64-pc-windows-msvc"
14
+ ]
15
+ },
16
+ "optionalDependencies": {
17
+ "@fuzionx/bridge-linux-x64-gnu": "0.1.0",
18
+ "@fuzionx/bridge-darwin-arm64": "0.1.0",
19
+ "@fuzionx/bridge-win32-x64-msvc": "0.1.0"
20
+ },
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/saytohenry/fuzionx"
25
+ },
26
+ "engines": {
27
+ "node": ">=18.0.0"
28
+ }
29
+ }