@hypen-space/core 0.3.9 → 0.3.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/dist/{src/app.js → app.js} +15 -2
- package/dist/{src/app.js.map → app.js.map} +3 -3
- package/dist/{src/components → components}/builtin.js +22 -7
- package/dist/{src/components → components}/builtin.js.map +4 -4
- package/dist/context.js +387 -0
- package/dist/context.js.map +12 -0
- package/dist/{src/discovery.js → discovery.js} +18 -4
- package/dist/{src/discovery.js.map → discovery.js.map} +4 -4
- package/dist/disposable.js +377 -0
- package/dist/disposable.js.map +11 -0
- package/dist/engine.browser.js +347 -0
- package/dist/engine.browser.js.map +11 -0
- package/dist/engine.js +320 -0
- package/dist/engine.js.map +11 -0
- package/dist/events.js +282 -0
- package/dist/events.js.map +11 -0
- package/dist/{src/index.browser.js → index.browser.js} +278 -229
- package/dist/index.browser.js.map +22 -0
- package/dist/{src/index.js → index.js} +1377 -1330
- package/dist/index.js.map +31 -0
- package/dist/loader.js +286 -0
- package/dist/loader.js.map +11 -0
- package/dist/plugin.js +334 -0
- package/dist/plugin.js.map +11 -0
- package/dist/{src/remote → remote}/client.js +215 -11
- package/dist/remote/client.js.map +14 -0
- package/dist/{src/remote → remote}/index.js +234 -210
- package/dist/remote/index.js.map +19 -0
- package/dist/remote/server.js +1442 -0
- package/dist/remote/server.js.map +16 -0
- package/dist/renderer.js +264 -0
- package/dist/renderer.js.map +11 -0
- package/dist/{src/router.js → router.js} +209 -8
- package/dist/router.js.map +12 -0
- package/package.json +69 -69
- package/src/components/builtin.ts +9 -6
- package/src/context.ts +10 -7
- package/src/discovery.ts +3 -2
- package/src/disposable.ts +6 -2
- package/src/engine.browser.ts +30 -11
- package/src/engine.ts +6 -3
- package/src/events.ts +5 -1
- package/src/index.browser.ts +20 -0
- package/src/index.ts +2 -0
- package/src/loader.ts +8 -8
- package/src/logger.ts +28 -0
- package/src/plugin.ts +2 -1
- package/src/remote/client.ts +8 -9
- package/src/remote/server.ts +6 -3
- package/src/renderer.ts +4 -5
- package/src/router.ts +10 -7
- package/wasm-browser/hypen_engine_bg.wasm +0 -0
- package/wasm-browser/package.json +1 -1
- package/wasm-node/hypen_engine_bg.wasm +0 -0
- package/wasm-node/package.json +5 -3
- package/dist/src/context.js +0 -182
- package/dist/src/context.js.map +0 -11
- package/dist/src/engine.browser.js +0 -137
- package/dist/src/engine.browser.js.map +0 -10
- package/dist/src/engine.js +0 -119
- package/dist/src/engine.js.map +0 -10
- package/dist/src/events.js +0 -80
- package/dist/src/events.js.map +0 -10
- package/dist/src/index.browser.js.map +0 -22
- package/dist/src/index.js.map +0 -31
- package/dist/src/loader.js +0 -85
- package/dist/src/loader.js.map +0 -10
- package/dist/src/plugin.js +0 -134
- package/dist/src/plugin.js.map +0 -10
- package/dist/src/remote/client.js.map +0 -13
- package/dist/src/remote/index.js.map +0 -19
- package/dist/src/renderer.js +0 -66
- package/dist/src/renderer.js.map +0 -10
- package/dist/src/router.js.map +0 -11
- /package/dist/{src/remote → remote}/types.js +0 -0
- /package/dist/{src/remote → remote}/types.js.map +0 -0
- /package/dist/{src/resolver.js → resolver.js} +0 -0
- /package/dist/{src/resolver.js.map → resolver.js.map} +0 -0
- /package/dist/{src/state.js → state.js} +0 -0
- /package/dist/{src/state.js.map → state.js.map} +0 -0
package/src/context.ts
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
import type { HypenModuleInstance } from "./app.js";
|
|
6
6
|
import { getStateSnapshot } from "./state.js";
|
|
7
7
|
import { TypedEventEmitter, type HypenFrameworkEvents } from "./events.js";
|
|
8
|
+
import { frameworkLoggers } from "./logger.js";
|
|
9
|
+
|
|
10
|
+
const log = frameworkLoggers.context;
|
|
8
11
|
|
|
9
12
|
export type ModuleReference<T = unknown> = {
|
|
10
13
|
state: T; // Live proxy state
|
|
@@ -47,10 +50,10 @@ export class HypenGlobalContext<TEvents extends Record<string, unknown> = HypenF
|
|
|
47
50
|
*/
|
|
48
51
|
registerModule(id: string, instance: HypenModuleInstance) {
|
|
49
52
|
if (this.modules.has(id)) {
|
|
50
|
-
|
|
53
|
+
log.warn(`Module "${id}" is already registered. Overwriting.`);
|
|
51
54
|
}
|
|
52
55
|
this.modules.set(id, instance);
|
|
53
|
-
|
|
56
|
+
log.debug(`Registered module: ${id}`);
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
/**
|
|
@@ -58,7 +61,7 @@ export class HypenGlobalContext<TEvents extends Record<string, unknown> = HypenF
|
|
|
58
61
|
*/
|
|
59
62
|
unregisterModule(id: string) {
|
|
60
63
|
this.modules.delete(id);
|
|
61
|
-
|
|
64
|
+
log.debug(`Unregistered module: ${id}`);
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
/**
|
|
@@ -111,14 +114,14 @@ export class HypenGlobalContext<TEvents extends Record<string, unknown> = HypenF
|
|
|
111
114
|
emit(event: string, payload?: unknown): void {
|
|
112
115
|
const handlers = this.legacyEventBus.get(event);
|
|
113
116
|
if (!handlers || handlers.size === 0) {
|
|
114
|
-
|
|
117
|
+
log.debug(`Event "${event}" emitted but no listeners`);
|
|
115
118
|
} else {
|
|
116
|
-
|
|
119
|
+
log.debug(`Emitting event: ${event}`, payload);
|
|
117
120
|
handlers.forEach((handler) => {
|
|
118
121
|
try {
|
|
119
122
|
handler(payload);
|
|
120
123
|
} catch (error) {
|
|
121
|
-
|
|
124
|
+
log.error(`Error in event handler for "${event}":`, error);
|
|
122
125
|
}
|
|
123
126
|
});
|
|
124
127
|
}
|
|
@@ -141,7 +144,7 @@ export class HypenGlobalContext<TEvents extends Record<string, unknown> = HypenF
|
|
|
141
144
|
const handlers = this.legacyEventBus.get(event)!;
|
|
142
145
|
handlers.add(handler);
|
|
143
146
|
|
|
144
|
-
|
|
147
|
+
log.debug(`Listening to event: ${event}`);
|
|
145
148
|
|
|
146
149
|
// Return unsubscribe function
|
|
147
150
|
return () => {
|
package/src/discovery.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { existsSync, readdirSync, readFileSync, watch } from "fs";
|
|
14
14
|
import { join, basename, resolve } from "path";
|
|
15
15
|
import type { HypenModuleDefinition } from "./app.js";
|
|
16
|
+
import { frameworkLoggers } from "./logger.js";
|
|
16
17
|
|
|
17
18
|
export interface DiscoveredComponent {
|
|
18
19
|
name: string;
|
|
@@ -99,7 +100,7 @@ export async function discoverComponents(
|
|
|
99
100
|
} = options;
|
|
100
101
|
|
|
101
102
|
const log = debug
|
|
102
|
-
? (...args: unknown[]) =>
|
|
103
|
+
? (...args: unknown[]) => frameworkLoggers.discovery.debug(...args)
|
|
103
104
|
: () => {};
|
|
104
105
|
|
|
105
106
|
const resolvedDir = resolve(baseDir);
|
|
@@ -379,7 +380,7 @@ export function watchComponents(
|
|
|
379
380
|
} = options;
|
|
380
381
|
|
|
381
382
|
const log = debug
|
|
382
|
-
? (...args: unknown[]) =>
|
|
383
|
+
? (...args: unknown[]) => frameworkLoggers.discovery.debug("[watch]", ...args)
|
|
383
384
|
: () => {};
|
|
384
385
|
|
|
385
386
|
let currentComponents = new Map<string, DiscoveredComponent>();
|
package/src/disposable.ts
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
* event listeners, timers, WebSocket connections, etc.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { frameworkLoggers } from "./logger.js";
|
|
9
|
+
|
|
10
|
+
const log = frameworkLoggers.lifecycle;
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* Interface for objects that can be disposed
|
|
10
14
|
*/
|
|
@@ -72,7 +76,7 @@ export class DisposableStack implements Disposable {
|
|
|
72
76
|
item.dispose();
|
|
73
77
|
} catch (error) {
|
|
74
78
|
// Log but continue disposing other items
|
|
75
|
-
|
|
79
|
+
log.error('Error during dispose:', error);
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
}
|
|
@@ -242,7 +246,7 @@ export function compositeDisposable(...disposables: Disposable[]): Disposable {
|
|
|
242
246
|
try {
|
|
243
247
|
d.dispose();
|
|
244
248
|
} catch (error) {
|
|
245
|
-
|
|
249
|
+
log.error('Error during dispose:', error);
|
|
246
250
|
}
|
|
247
251
|
}
|
|
248
252
|
},
|
package/src/engine.browser.ts
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* Uses web target for browser environments
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { frameworkLoggers } from "./logger.js";
|
|
7
|
+
|
|
8
|
+
const log = frameworkLoggers.engine;
|
|
9
|
+
|
|
6
10
|
// Dynamic import path - will be configured at build time
|
|
7
11
|
// For browser, the WASM needs to be served and initialized explicitly
|
|
8
12
|
let wasmInit: ((path?: string) => Promise<void>) | null = null;
|
|
@@ -11,14 +15,14 @@ let WasmEngineClass: any = null;
|
|
|
11
15
|
export type Patch = {
|
|
12
16
|
type: "create" | "setProp" | "setText" | "insert" | "move" | "remove" | "attachEvent" | "detachEvent";
|
|
13
17
|
id?: string;
|
|
14
|
-
|
|
15
|
-
props?: Record<string, any
|
|
18
|
+
elementType?: string;
|
|
19
|
+
props?: Record<string, any>;
|
|
16
20
|
name?: string;
|
|
17
21
|
value?: any;
|
|
18
22
|
text?: string;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
parentId?: string;
|
|
24
|
+
beforeId?: string;
|
|
25
|
+
eventName?: string;
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
export type Action = {
|
|
@@ -111,7 +115,7 @@ export class Engine {
|
|
|
111
115
|
this.wasmEngine = new WasmEngineClass();
|
|
112
116
|
this.initialized = true;
|
|
113
117
|
} catch (error) {
|
|
114
|
-
|
|
118
|
+
log.error("Failed to initialize WASM engine:", error);
|
|
115
119
|
throw error;
|
|
116
120
|
}
|
|
117
121
|
}
|
|
@@ -173,16 +177,31 @@ export class Engine {
|
|
|
173
177
|
}
|
|
174
178
|
|
|
175
179
|
/**
|
|
176
|
-
* Notify the engine of state changes
|
|
180
|
+
* Notify the engine of state changes using sparse updates
|
|
177
181
|
*/
|
|
178
|
-
notifyStateChange(paths: string[],
|
|
182
|
+
notifyStateChange(paths: string[], values: Record<string, any>): void {
|
|
179
183
|
const engine = this.ensureInitialized();
|
|
180
184
|
|
|
185
|
+
if (paths.length === 0) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const plainValues = JSON.parse(JSON.stringify(values));
|
|
190
|
+
engine.updateStateSparse(paths, plainValues);
|
|
191
|
+
log.debug("State changed (sparse):", paths);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Notify the engine of state changes using full state replacement
|
|
196
|
+
* @deprecated Use notifyStateChange with sparse values instead
|
|
197
|
+
*/
|
|
198
|
+
notifyStateChangeFull(paths: string[], currentState: Record<string, any>): void {
|
|
199
|
+
const engine = this.ensureInitialized();
|
|
181
200
|
const plainObject = JSON.parse(JSON.stringify(currentState));
|
|
182
201
|
engine.updateState(plainObject);
|
|
183
202
|
|
|
184
203
|
if (paths.length > 0) {
|
|
185
|
-
|
|
204
|
+
log.debug("State changed (full):", paths);
|
|
186
205
|
}
|
|
187
206
|
}
|
|
188
207
|
|
|
@@ -201,7 +220,7 @@ export class Engine {
|
|
|
201
220
|
*/
|
|
202
221
|
dispatchAction(name: string, payload?: any): void {
|
|
203
222
|
const engine = this.ensureInitialized();
|
|
204
|
-
|
|
223
|
+
log.debug(`Action dispatched: ${name}`);
|
|
205
224
|
engine.dispatchAction(name, payload ?? null);
|
|
206
225
|
}
|
|
207
226
|
|
|
@@ -215,7 +234,7 @@ export class Engine {
|
|
|
215
234
|
...action,
|
|
216
235
|
payload: action.payload ? mapToObject(action.payload) : action.payload,
|
|
217
236
|
};
|
|
218
|
-
Promise.resolve(handler(normalizedAction)).catch(
|
|
237
|
+
Promise.resolve(handler(normalizedAction)).catch((err) => log.error("Action handler error:", err));
|
|
219
238
|
});
|
|
220
239
|
}
|
|
221
240
|
|
package/src/engine.ts
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
// WASM module types
|
|
7
7
|
import { WasmEngine } from "../wasm-node/hypen_engine.js";
|
|
8
|
+
import { frameworkLoggers } from "./logger.js";
|
|
9
|
+
|
|
10
|
+
const log = frameworkLoggers.engine;
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Unwrap proxy objects to plain values for WASM serialization.
|
|
@@ -147,7 +150,7 @@ export class Engine {
|
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
engine.updateStateSparse(paths, unwrapForWasm(values));
|
|
150
|
-
|
|
153
|
+
log.debug("State changed (sparse):", paths);
|
|
151
154
|
}
|
|
152
155
|
|
|
153
156
|
/**
|
|
@@ -159,7 +162,7 @@ export class Engine {
|
|
|
159
162
|
engine.updateState(unwrapForWasm(currentState));
|
|
160
163
|
|
|
161
164
|
if (paths.length > 0) {
|
|
162
|
-
|
|
165
|
+
log.debug("State changed (full):", paths);
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
168
|
|
|
@@ -186,7 +189,7 @@ export class Engine {
|
|
|
186
189
|
onAction(actionName: string, handler: ActionHandler): void {
|
|
187
190
|
const engine = this.ensureInitialized();
|
|
188
191
|
engine.onAction(actionName, (action: Action) => {
|
|
189
|
-
Promise.resolve(handler(action)).catch(
|
|
192
|
+
Promise.resolve(handler(action)).catch((err) => log.error("Action handler error:", err));
|
|
190
193
|
});
|
|
191
194
|
}
|
|
192
195
|
|
package/src/events.ts
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
* Provides strongly-typed event emission and subscription with autocomplete support.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { frameworkLoggers } from "./logger.js";
|
|
8
|
+
|
|
9
|
+
const log = frameworkLoggers.events;
|
|
10
|
+
|
|
7
11
|
export type EventHandler<T = unknown> = (payload: T) => void;
|
|
8
12
|
|
|
9
13
|
/**
|
|
@@ -25,7 +29,7 @@ export class TypedEventEmitter<TEvents extends Record<string, unknown> = Record<
|
|
|
25
29
|
try {
|
|
26
30
|
handler(payload);
|
|
27
31
|
} catch (error) {
|
|
28
|
-
|
|
32
|
+
log.error(`Error in event handler for "${String(event)}":`, error);
|
|
29
33
|
}
|
|
30
34
|
});
|
|
31
35
|
}
|
package/src/index.browser.ts
CHANGED
|
@@ -118,3 +118,23 @@ export {
|
|
|
118
118
|
disposableSubscription,
|
|
119
119
|
} from "./disposable.js";
|
|
120
120
|
export type { Disposable } from "./disposable.js";
|
|
121
|
+
|
|
122
|
+
// ============================================================================
|
|
123
|
+
// LOGGER
|
|
124
|
+
// ============================================================================
|
|
125
|
+
|
|
126
|
+
export {
|
|
127
|
+
Logger,
|
|
128
|
+
createLogger,
|
|
129
|
+
logger,
|
|
130
|
+
log,
|
|
131
|
+
frameworkLoggers,
|
|
132
|
+
setLogLevel,
|
|
133
|
+
getLogLevel,
|
|
134
|
+
configureLogger,
|
|
135
|
+
enableLogging,
|
|
136
|
+
disableLogging,
|
|
137
|
+
setDebugMode,
|
|
138
|
+
isDebugMode,
|
|
139
|
+
} from "./logger.js";
|
|
140
|
+
export type { LogLevel, LoggerConfig, LogHandler } from "./logger.js";
|
package/src/index.ts
CHANGED
package/src/loader.ts
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
9
9
|
import { join } from "path";
|
|
10
10
|
import type { HypenModuleDefinition } from "./app.js";
|
|
11
|
+
import { frameworkLoggers } from "./logger.js";
|
|
12
|
+
|
|
13
|
+
const log = frameworkLoggers.loader;
|
|
11
14
|
|
|
12
15
|
export interface ComponentDefinition {
|
|
13
16
|
name: string;
|
|
@@ -89,12 +92,9 @@ export class ComponentLoader {
|
|
|
89
92
|
// Register the component
|
|
90
93
|
this.register(name, module, template, dirPath);
|
|
91
94
|
|
|
92
|
-
|
|
95
|
+
log.debug(`Loaded component: ${name} from ${dirPath}`);
|
|
93
96
|
} catch (error) {
|
|
94
|
-
|
|
95
|
-
`✗ Failed to load component ${name} from ${dirPath}:`,
|
|
96
|
-
error
|
|
97
|
-
);
|
|
97
|
+
log.error(`Failed to load component ${name} from ${dirPath}:`, error);
|
|
98
98
|
throw error;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -106,7 +106,7 @@ export class ComponentLoader {
|
|
|
106
106
|
async loadFromComponentsDir(baseDir: string): Promise<void> {
|
|
107
107
|
try {
|
|
108
108
|
if (!existsSync(baseDir)) {
|
|
109
|
-
|
|
109
|
+
log.warn(`Components directory not found: ${baseDir}`);
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -124,9 +124,9 @@ export class ComponentLoader {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
log.debug(`Loaded ${this.components.size} components from ${baseDir}`);
|
|
128
128
|
} catch (error) {
|
|
129
|
-
|
|
129
|
+
log.error(`Failed to load components from ${baseDir}:`, error);
|
|
130
130
|
throw error;
|
|
131
131
|
}
|
|
132
132
|
}
|
package/src/logger.ts
CHANGED
|
@@ -112,6 +112,27 @@ export function disableLogging(): void {
|
|
|
112
112
|
config.level = "none";
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Enable debug mode - alias for enableLogging()
|
|
117
|
+
* Call this at app startup to see all debug logs
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { setDebugMode } from "@hypen-space/core";
|
|
122
|
+
* setDebugMode(true);
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export function setDebugMode(enabled: boolean): void {
|
|
126
|
+
config.level = enabled ? "debug" : "error";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Check if debug mode is enabled
|
|
131
|
+
*/
|
|
132
|
+
export function isDebugMode(): boolean {
|
|
133
|
+
return config.level === "debug";
|
|
134
|
+
}
|
|
135
|
+
|
|
115
136
|
// ============================================================================
|
|
116
137
|
// Utility Functions
|
|
117
138
|
// ============================================================================
|
|
@@ -327,6 +348,7 @@ export const log = {
|
|
|
327
348
|
// ============================================================================
|
|
328
349
|
|
|
329
350
|
export const frameworkLoggers = {
|
|
351
|
+
hypen: createLogger("Hypen"),
|
|
330
352
|
engine: createLogger("Engine"),
|
|
331
353
|
router: createLogger("Router"),
|
|
332
354
|
state: createLogger("State"),
|
|
@@ -335,4 +357,10 @@ export const frameworkLoggers = {
|
|
|
335
357
|
renderer: createLogger("Renderer"),
|
|
336
358
|
module: createLogger("Module"),
|
|
337
359
|
lifecycle: createLogger("Lifecycle"),
|
|
360
|
+
loader: createLogger("Loader"),
|
|
361
|
+
context: createLogger("Context"),
|
|
362
|
+
discovery: createLogger("Discovery"),
|
|
363
|
+
plugin: createLogger("Plugin"),
|
|
364
|
+
canvas: createLogger("Canvas"),
|
|
365
|
+
debug: createLogger("Debug"),
|
|
338
366
|
};
|
package/src/plugin.ts
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import type { BunPlugin } from "bun";
|
|
17
17
|
import { readFileSync, existsSync } from "fs";
|
|
18
18
|
import { dirname, basename, join, resolve } from "path";
|
|
19
|
+
import { frameworkLoggers } from "./logger.js";
|
|
19
20
|
|
|
20
21
|
export interface HypenPluginOptions {
|
|
21
22
|
/**
|
|
@@ -141,7 +142,7 @@ export function hypenPlugin(options: HypenPluginOptions = {}): BunPlugin {
|
|
|
141
142
|
options;
|
|
142
143
|
|
|
143
144
|
const log = debug
|
|
144
|
-
? (...args: unknown[]) =>
|
|
145
|
+
? (...args: unknown[]) => frameworkLoggers.plugin.debug(...args)
|
|
145
146
|
: () => {};
|
|
146
147
|
|
|
147
148
|
return {
|
package/src/remote/client.ts
CHANGED
|
@@ -51,6 +51,9 @@ import {
|
|
|
51
51
|
disposableListener,
|
|
52
52
|
} from "../disposable.js";
|
|
53
53
|
import { retry, type RetryOptions } from "../retry.js";
|
|
54
|
+
import { frameworkLoggers } from "../logger.js";
|
|
55
|
+
|
|
56
|
+
const log = frameworkLoggers.remote;
|
|
54
57
|
|
|
55
58
|
export type RemoteConnectionState =
|
|
56
59
|
| "disconnected"
|
|
@@ -261,7 +264,7 @@ export class RemoteEngine implements Disposable {
|
|
|
261
264
|
*/
|
|
262
265
|
dispatchAction(action: string, payload?: unknown): void {
|
|
263
266
|
if (this.state !== "connected" || !this.ws) {
|
|
264
|
-
|
|
267
|
+
log.warn("Cannot dispatch action: not connected");
|
|
265
268
|
return;
|
|
266
269
|
}
|
|
267
270
|
|
|
@@ -388,7 +391,7 @@ export class RemoteEngine implements Disposable {
|
|
|
388
391
|
break;
|
|
389
392
|
}
|
|
390
393
|
} catch (e) {
|
|
391
|
-
|
|
394
|
+
log.error("Error handling remote message:", e);
|
|
392
395
|
const error = e instanceof Error ? e : new Error(String(e));
|
|
393
396
|
this.errorCallbacks.forEach((cb) => cb(error));
|
|
394
397
|
}
|
|
@@ -428,9 +431,7 @@ export class RemoteEngine implements Disposable {
|
|
|
428
431
|
private handlePatch(message: PatchMessage): void {
|
|
429
432
|
// Check revision ordering
|
|
430
433
|
if (message.revision <= this.currentRevision) {
|
|
431
|
-
|
|
432
|
-
`Out of order patch: expected > ${this.currentRevision}, got ${message.revision}`
|
|
433
|
-
);
|
|
434
|
+
log.warn(`Out of order patch: expected > ${this.currentRevision}, got ${message.revision}`);
|
|
434
435
|
return;
|
|
435
436
|
}
|
|
436
437
|
|
|
@@ -465,13 +466,11 @@ export class RemoteEngine implements Disposable {
|
|
|
465
466
|
maxDelayMs: 30000,
|
|
466
467
|
jitter: 0.1,
|
|
467
468
|
onRetry: (attempt, error) => {
|
|
468
|
-
|
|
469
|
-
`Reconnection attempt ${attempt}/${this.options.maxReconnectAttempts} failed: ${error.message}`
|
|
470
|
-
);
|
|
469
|
+
log.debug(`Reconnection attempt ${attempt}/${this.options.maxReconnectAttempts} failed: ${error.message}`);
|
|
471
470
|
},
|
|
472
471
|
}
|
|
473
472
|
).catch((error) => {
|
|
474
|
-
|
|
473
|
+
log.error("Max reconnection attempts reached:", error.message);
|
|
475
474
|
this.errorCallbacks.forEach((cb) =>
|
|
476
475
|
cb(new ConnectionError(this.url, error, this.options.maxReconnectAttempts))
|
|
477
476
|
);
|
package/src/remote/server.ts
CHANGED
|
@@ -47,6 +47,9 @@ import type {
|
|
|
47
47
|
import type { Patch } from "../engine.js";
|
|
48
48
|
import type { ServerWebSocket } from "bun";
|
|
49
49
|
import { SessionManager } from "./session.js";
|
|
50
|
+
import { frameworkLoggers } from "../logger.js";
|
|
51
|
+
|
|
52
|
+
const log = frameworkLoggers.remote;
|
|
50
53
|
|
|
51
54
|
interface ClientData {
|
|
52
55
|
id: string;
|
|
@@ -182,7 +185,7 @@ export class RemoteServer {
|
|
|
182
185
|
},
|
|
183
186
|
});
|
|
184
187
|
|
|
185
|
-
|
|
188
|
+
log.info(`Hypen app streaming on ws://${hostname}:${finalPort}`);
|
|
186
189
|
|
|
187
190
|
return this;
|
|
188
191
|
}
|
|
@@ -249,7 +252,7 @@ export class RemoteServer {
|
|
|
249
252
|
}, 1000); // 1 second grace period
|
|
250
253
|
|
|
251
254
|
} catch (error) {
|
|
252
|
-
|
|
255
|
+
log.error("Error handling WebSocket open:", error);
|
|
253
256
|
ws.close(1011, "Internal server error");
|
|
254
257
|
}
|
|
255
258
|
}
|
|
@@ -514,7 +517,7 @@ export class RemoteServer {
|
|
|
514
517
|
break;
|
|
515
518
|
}
|
|
516
519
|
} catch (error) {
|
|
517
|
-
|
|
520
|
+
log.error("Error handling WebSocket message:", error);
|
|
518
521
|
}
|
|
519
522
|
}
|
|
520
523
|
|
package/src/renderer.ts
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { Patch } from "./engine.js";
|
|
9
|
+
import { frameworkLoggers } from "./logger.js";
|
|
10
|
+
|
|
11
|
+
const log = frameworkLoggers.renderer;
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* Renderer interface that all platform renderers must implement
|
|
@@ -93,10 +96,6 @@ export abstract class BaseRenderer implements Renderer {
|
|
|
93
96
|
*/
|
|
94
97
|
export class ConsoleRenderer implements Renderer {
|
|
95
98
|
applyPatches(patches: Patch[]): void {
|
|
96
|
-
|
|
97
|
-
for (const patch of patches) {
|
|
98
|
-
console.log(patch);
|
|
99
|
-
}
|
|
100
|
-
console.groupEnd();
|
|
99
|
+
log.debug("Patches:", patches);
|
|
101
100
|
}
|
|
102
101
|
}
|
package/src/router.ts
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { createObservableState, getStateSnapshot } from "./state.js";
|
|
7
|
+
import { frameworkLoggers } from "./logger.js";
|
|
8
|
+
|
|
9
|
+
const log = frameworkLoggers.router;
|
|
7
10
|
|
|
8
11
|
export type RouteMatch = {
|
|
9
12
|
params: Record<string, string>;
|
|
@@ -76,7 +79,7 @@ export class HypenRouter {
|
|
|
76
79
|
});
|
|
77
80
|
|
|
78
81
|
this.isInitialized = true;
|
|
79
|
-
|
|
82
|
+
log.debug("Router initialized at:", initialPath);
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
/**
|
|
@@ -113,7 +116,7 @@ export class HypenRouter {
|
|
|
113
116
|
* Navigate to a new path
|
|
114
117
|
*/
|
|
115
118
|
push(path: string) {
|
|
116
|
-
|
|
119
|
+
log.debug("push:", path);
|
|
117
120
|
this.updatePath(path, true);
|
|
118
121
|
}
|
|
119
122
|
|
|
@@ -121,7 +124,7 @@ export class HypenRouter {
|
|
|
121
124
|
* Replace current path without adding to history
|
|
122
125
|
*/
|
|
123
126
|
replace(path: string) {
|
|
124
|
-
|
|
127
|
+
log.debug("replace:", path);
|
|
125
128
|
this.updatePath(path, true, true);
|
|
126
129
|
}
|
|
127
130
|
|
|
@@ -129,7 +132,7 @@ export class HypenRouter {
|
|
|
129
132
|
* Go back in history
|
|
130
133
|
*/
|
|
131
134
|
back() {
|
|
132
|
-
|
|
135
|
+
log.debug("back");
|
|
133
136
|
if (typeof window !== "undefined") {
|
|
134
137
|
window.history.back();
|
|
135
138
|
}
|
|
@@ -139,7 +142,7 @@ export class HypenRouter {
|
|
|
139
142
|
* Go forward in history
|
|
140
143
|
*/
|
|
141
144
|
forward() {
|
|
142
|
-
|
|
145
|
+
log.debug("forward");
|
|
143
146
|
if (typeof window !== "undefined") {
|
|
144
147
|
window.history.forward();
|
|
145
148
|
}
|
|
@@ -289,7 +292,7 @@ export class HypenRouter {
|
|
|
289
292
|
try {
|
|
290
293
|
callback(this.getState());
|
|
291
294
|
} catch (error) {
|
|
292
|
-
|
|
295
|
+
log.error("Error in route subscriber:", error);
|
|
293
296
|
}
|
|
294
297
|
|
|
295
298
|
// Return unsubscribe function
|
|
@@ -307,7 +310,7 @@ export class HypenRouter {
|
|
|
307
310
|
try {
|
|
308
311
|
callback(routeState);
|
|
309
312
|
} catch (error) {
|
|
310
|
-
|
|
313
|
+
log.error("Error in route subscriber:", error);
|
|
311
314
|
}
|
|
312
315
|
});
|
|
313
316
|
}
|
|
Binary file
|
|
Binary file
|
package/wasm-node/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"Hypen Contributors"
|
|
5
5
|
],
|
|
6
6
|
"description": "A Rust implementation of the Hypen engine",
|
|
7
|
-
"version": "0.3.
|
|
7
|
+
"version": "0.3.3",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -16,5 +16,7 @@
|
|
|
16
16
|
"hypen_engine.d.ts"
|
|
17
17
|
],
|
|
18
18
|
"main": "hypen_engine.js",
|
|
19
|
-
"types": "hypen_engine.d.ts"
|
|
20
|
-
|
|
19
|
+
"types": "hypen_engine.d.ts",
|
|
20
|
+
"type": "commonjs",
|
|
21
|
+
"sideEffects": false
|
|
22
|
+
}
|