@hypen-space/core 0.4.37 → 0.4.38
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 +13 -14
- package/dist/app.js +289 -227
- package/dist/app.js.map +5 -5
- package/dist/components/builtin.js +289 -227
- package/dist/components/builtin.js.map +5 -5
- package/dist/context.js +60 -64
- package/dist/context.js.map +2 -2
- package/dist/datasource.js +80 -0
- package/dist/datasource.js.map +10 -0
- package/dist/disposable.js +60 -63
- package/dist/disposable.js.map +2 -2
- package/dist/events.js +60 -63
- package/dist/events.js.map +2 -2
- package/dist/hypen.js +78 -0
- package/dist/hypen.js.map +10 -0
- package/dist/index.browser.d.ts +2 -1
- package/dist/index.browser.js +303 -244
- package/dist/index.browser.js.map +6 -7
- package/dist/index.d.ts +0 -3
- package/dist/index.js +492 -180
- package/dist/index.js.map +6 -6
- package/dist/logger.js +60 -64
- package/dist/logger.js.map +2 -2
- package/dist/remote/client.js +243 -158
- package/dist/remote/client.js.map +6 -6
- package/dist/remote/index.d.ts +6 -5
- package/dist/remote/index.js +241 -1986
- package/dist/remote/index.js.map +6 -13
- package/dist/remote/session.js +151 -0
- package/dist/remote/session.js.map +10 -0
- package/dist/renderer.js +60 -63
- package/dist/renderer.js.map +2 -2
- package/dist/result.js +220 -0
- package/dist/result.js.map +10 -0
- package/dist/retry.js +329 -0
- package/dist/retry.js.map +11 -0
- package/dist/router.js +62 -70
- package/dist/router.js.map +2 -2
- package/dist/state.js +3 -8
- package/dist/state.js.map +2 -2
- package/package.json +11 -56
- package/src/index.browser.ts +5 -4
- package/src/index.ts +10 -23
- package/src/remote/index.ts +9 -5
- package/dist/discovery.d.ts +0 -90
- package/dist/discovery.js +0 -1334
- package/dist/discovery.js.map +0 -15
- package/dist/engine.browser.d.ts +0 -116
- package/dist/engine.browser.js +0 -479
- package/dist/engine.browser.js.map +0 -12
- package/dist/engine.d.ts +0 -107
- package/dist/engine.js +0 -543
- package/dist/engine.js.map +0 -12
- package/dist/loader.d.ts +0 -51
- package/dist/loader.js +0 -292
- package/dist/loader.js.map +0 -11
- package/dist/plugin.d.ts +0 -39
- package/dist/plugin.js +0 -685
- package/dist/plugin.js.map +0 -12
- package/dist/remote/server.d.ts +0 -188
- package/dist/remote/server.js +0 -2270
- package/dist/remote/server.js.map +0 -19
- package/src/discovery.ts +0 -527
- package/src/engine.browser.ts +0 -302
- package/src/engine.ts +0 -282
- package/src/loader.ts +0 -136
- package/src/plugin.ts +0 -220
- package/src/remote/server.ts +0 -879
- package/wasm-browser/README.md +0 -594
- package/wasm-browser/hypen_engine.d.ts +0 -389
- package/wasm-browser/hypen_engine.js +0 -1070
- package/wasm-browser/hypen_engine_bg.wasm +0 -0
- package/wasm-browser/hypen_engine_bg.wasm.d.ts +0 -37
- package/wasm-browser/package.json +0 -24
- package/wasm-node/README.md +0 -594
- package/wasm-node/hypen_engine.d.ts +0 -327
- package/wasm-node/hypen_engine.js +0 -979
- package/wasm-node/hypen_engine_bg.wasm +0 -0
- package/wasm-node/hypen_engine_bg.wasm.d.ts +0 -37
- package/wasm-node/package.json +0 -22
package/README.md
CHANGED
|
@@ -77,7 +77,8 @@ Your renderer applies these patches to the actual platform.
|
|
|
77
77
|
## Quick Start
|
|
78
78
|
|
|
79
79
|
```typescript
|
|
80
|
-
import {
|
|
80
|
+
import { app } from "@hypen-space/core";
|
|
81
|
+
import { Engine } from "@hypen-space/web-engine";
|
|
81
82
|
|
|
82
83
|
// 1. Define your module's state and actions
|
|
83
84
|
const counter = app
|
|
@@ -244,7 +245,7 @@ Link(to: "/products/42") { Text("View Product") }
|
|
|
244
245
|
For larger apps, organize components as files and auto-discover them:
|
|
245
246
|
|
|
246
247
|
```typescript
|
|
247
|
-
import { discoverComponents, loadDiscoveredComponents } from "@hypen-space/
|
|
248
|
+
import { discoverComponents, loadDiscoveredComponents } from "@hypen-space/server";
|
|
248
249
|
|
|
249
250
|
const components = await discoverComponents("./src/components");
|
|
250
251
|
const loaded = await loadDiscoveredComponents(components);
|
|
@@ -268,7 +269,7 @@ Counter/
|
|
|
268
269
|
Watch for changes (hot reload):
|
|
269
270
|
|
|
270
271
|
```typescript
|
|
271
|
-
import { watchComponents } from "@hypen-space/
|
|
272
|
+
import { watchComponents } from "@hypen-space/server";
|
|
272
273
|
|
|
273
274
|
const watcher = watchComponents("./src/components", {
|
|
274
275
|
onUpdate: (c) => console.log("Updated:", c.name),
|
|
@@ -280,7 +281,7 @@ const watcher = watchComponents("./src/components", {
|
|
|
280
281
|
Register components programmatically:
|
|
281
282
|
|
|
282
283
|
```typescript
|
|
283
|
-
import { componentLoader, ComponentLoader } from "@hypen-space/
|
|
284
|
+
import { componentLoader, ComponentLoader } from "@hypen-space/server";
|
|
284
285
|
|
|
285
286
|
// Global loader
|
|
286
287
|
componentLoader.register("Counter", counterModule, counterTemplate);
|
|
@@ -336,13 +337,13 @@ context.emit("userLoggedIn", { id: "1", name: "Ian" });
|
|
|
336
337
|
|
|
337
338
|
```typescript
|
|
338
339
|
// Node.js / Bundler - WASM loads automatically
|
|
339
|
-
import { Engine } from "@hypen-space/
|
|
340
|
+
import { Engine } from "@hypen-space/server";
|
|
340
341
|
const engine = new Engine();
|
|
341
342
|
await engine.init();
|
|
342
343
|
|
|
343
344
|
// Browser - specify WASM path
|
|
344
|
-
import {
|
|
345
|
-
const engine = new
|
|
345
|
+
import { Engine } from "@hypen-space/web-engine";
|
|
346
|
+
const engine = new Engine();
|
|
346
347
|
await engine.init({ wasmPath: "/hypen_engine_bg.wasm" });
|
|
347
348
|
```
|
|
348
349
|
|
|
@@ -515,24 +516,22 @@ events.emit("userLogin", { userId: "123" });
|
|
|
515
516
|
|
|
516
517
|
| Export | Description |
|
|
517
518
|
|--------|-------------|
|
|
518
|
-
| `@hypen-space/core` | Main entry point |
|
|
519
|
-
| `@hypen-space/core/engine` | Low-level WASM engine |
|
|
520
|
-
| `@hypen-space/core/engine/browser` | Browser-optimized engine |
|
|
519
|
+
| `@hypen-space/core` | Main entry point (app, state, router, types) |
|
|
521
520
|
| `@hypen-space/core/app` | Module builder |
|
|
522
521
|
| `@hypen-space/core/state` | Observable state utilities |
|
|
523
522
|
| `@hypen-space/core/renderer` | Abstract renderer |
|
|
524
523
|
| `@hypen-space/core/router` | Routing system |
|
|
525
524
|
| `@hypen-space/core/context` | Global context |
|
|
526
|
-
| `@hypen-space/core/remote` | Remote UI
|
|
527
|
-
| `@hypen-space/core/loader` | Component loader |
|
|
528
|
-
| `@hypen-space/core/discovery` | Component discovery |
|
|
525
|
+
| `@hypen-space/core/remote/client` | Remote UI client (RemoteEngine) |
|
|
529
526
|
| `@hypen-space/core/components` | Built-in Router, Route, Link |
|
|
530
527
|
| `@hypen-space/core/result` | Result type for error handling |
|
|
531
528
|
| `@hypen-space/core/disposable` | Disposable pattern utilities |
|
|
532
529
|
| `@hypen-space/core/retry` | Retry with backoff |
|
|
533
530
|
| `@hypen-space/core/logger` | Structured logging |
|
|
534
531
|
| `@hypen-space/core/events` | Typed event emitter |
|
|
535
|
-
| `@hypen-space/
|
|
532
|
+
| `@hypen-space/server` | Node.js WASM engine, loader, discovery, RemoteServer |
|
|
533
|
+
| `@hypen-space/web-engine` | Browser WASM engine, Hypen orchestrator |
|
|
534
|
+
| `@hypen-space/web` | DOM & Canvas renderers |
|
|
536
535
|
|
|
537
536
|
## Requirements
|
|
538
537
|
|
package/dist/app.js
CHANGED
|
@@ -21,7 +21,235 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
21
21
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
// src/result.ts
|
|
25
|
+
function Ok(value) {
|
|
26
|
+
return { ok: true, value };
|
|
27
|
+
}
|
|
28
|
+
function Err(error) {
|
|
29
|
+
return { ok: false, error };
|
|
30
|
+
}
|
|
31
|
+
function isOk(result) {
|
|
32
|
+
return result.ok;
|
|
33
|
+
}
|
|
34
|
+
function isErr(result) {
|
|
35
|
+
return !result.ok;
|
|
36
|
+
}
|
|
37
|
+
async function fromPromise(promise, mapError) {
|
|
38
|
+
try {
|
|
39
|
+
const value = await promise;
|
|
40
|
+
return Ok(value);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
if (mapError) {
|
|
43
|
+
return Err(mapError(e));
|
|
44
|
+
}
|
|
45
|
+
return Err(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function fromTry(fn, mapError) {
|
|
49
|
+
try {
|
|
50
|
+
return Ok(fn());
|
|
51
|
+
} catch (e) {
|
|
52
|
+
if (mapError) {
|
|
53
|
+
return Err(mapError(e));
|
|
54
|
+
}
|
|
55
|
+
return Err(e);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function map(result, fn) {
|
|
59
|
+
if (result.ok) {
|
|
60
|
+
return Ok(fn(result.value));
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
function mapErr(result, fn) {
|
|
65
|
+
if (!result.ok) {
|
|
66
|
+
return Err(fn(result.error));
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
function flatMap(result, fn) {
|
|
71
|
+
if (result.ok) {
|
|
72
|
+
return fn(result.value);
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
function unwrap(result) {
|
|
77
|
+
if (result.ok) {
|
|
78
|
+
return result.value;
|
|
79
|
+
}
|
|
80
|
+
throw result.error;
|
|
81
|
+
}
|
|
82
|
+
function unwrapOr(result, defaultValue) {
|
|
83
|
+
if (result.ok) {
|
|
84
|
+
return result.value;
|
|
85
|
+
}
|
|
86
|
+
return defaultValue;
|
|
87
|
+
}
|
|
88
|
+
function unwrapOrElse(result, fn) {
|
|
89
|
+
if (result.ok) {
|
|
90
|
+
return result.value;
|
|
91
|
+
}
|
|
92
|
+
return fn(result.error);
|
|
93
|
+
}
|
|
94
|
+
function match(result, handlers) {
|
|
95
|
+
if (result.ok) {
|
|
96
|
+
return handlers.ok(result.value);
|
|
97
|
+
}
|
|
98
|
+
return handlers.err(result.error);
|
|
99
|
+
}
|
|
100
|
+
function all(results) {
|
|
101
|
+
const values = [];
|
|
102
|
+
for (const result of results) {
|
|
103
|
+
if (!result.ok) {
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
values.push(result.value);
|
|
107
|
+
}
|
|
108
|
+
return Ok(values);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
class HypenError extends Error {
|
|
112
|
+
code;
|
|
113
|
+
context;
|
|
114
|
+
cause;
|
|
115
|
+
constructor(code, message, options) {
|
|
116
|
+
super(message);
|
|
117
|
+
this.name = "HypenError";
|
|
118
|
+
this.code = code;
|
|
119
|
+
this.context = options?.context;
|
|
120
|
+
this.cause = options?.cause;
|
|
121
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
class ActionError extends HypenError {
|
|
126
|
+
actionName;
|
|
127
|
+
constructor(actionName, cause) {
|
|
128
|
+
super("ACTION_ERROR", `Action handler "${actionName}" failed: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
129
|
+
context: { actionName },
|
|
130
|
+
cause: cause instanceof Error ? cause : undefined
|
|
131
|
+
});
|
|
132
|
+
this.name = "ActionError";
|
|
133
|
+
this.actionName = actionName;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
class ConnectionError extends HypenError {
|
|
138
|
+
url;
|
|
139
|
+
attempt;
|
|
140
|
+
constructor(url, cause, attempt) {
|
|
141
|
+
super("CONNECTION_ERROR", `Connection to "${url}" failed${attempt ? ` (attempt ${attempt})` : ""}: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
142
|
+
context: { url, attempt },
|
|
143
|
+
cause: cause instanceof Error ? cause : undefined
|
|
144
|
+
});
|
|
145
|
+
this.name = "ConnectionError";
|
|
146
|
+
this.url = url;
|
|
147
|
+
this.attempt = attempt;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
class StateError extends HypenError {
|
|
152
|
+
path;
|
|
153
|
+
constructor(message, path, cause) {
|
|
154
|
+
super("STATE_ERROR", message, {
|
|
155
|
+
context: { path },
|
|
156
|
+
cause: cause instanceof Error ? cause : undefined
|
|
157
|
+
});
|
|
158
|
+
this.name = "StateError";
|
|
159
|
+
this.path = path;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
class ParseError extends HypenError {
|
|
164
|
+
source;
|
|
165
|
+
constructor(message, source, cause) {
|
|
166
|
+
super("PARSE_ERROR", message, {
|
|
167
|
+
context: { source },
|
|
168
|
+
cause: cause instanceof Error ? cause : undefined
|
|
169
|
+
});
|
|
170
|
+
this.name = "ParseError";
|
|
171
|
+
this.source = source;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
class RenderError extends HypenError {
|
|
176
|
+
constructor(message, cause) {
|
|
177
|
+
super("RENDER_ERROR", message, {
|
|
178
|
+
cause: cause instanceof Error ? cause : undefined
|
|
179
|
+
});
|
|
180
|
+
this.name = "RenderError";
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function classifyEngineError(err) {
|
|
184
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
185
|
+
if (message.startsWith("Parse error:")) {
|
|
186
|
+
return new ParseError(message);
|
|
187
|
+
}
|
|
188
|
+
if (message.startsWith("Invalid state:") || message.startsWith("Invalid state patch:")) {
|
|
189
|
+
return new StateError(message);
|
|
190
|
+
}
|
|
191
|
+
if (message.startsWith("Parent node not found:")) {
|
|
192
|
+
return new RenderError(message);
|
|
193
|
+
}
|
|
194
|
+
return new RenderError(message);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// src/datasource.ts
|
|
198
|
+
class DataSourceManager {
|
|
199
|
+
plugins = new Map;
|
|
200
|
+
configs = new Map;
|
|
201
|
+
state = new Map;
|
|
202
|
+
engine;
|
|
203
|
+
constructor(engine) {
|
|
204
|
+
this.engine = engine;
|
|
205
|
+
}
|
|
206
|
+
async use(plugin, config) {
|
|
207
|
+
const { name } = plugin;
|
|
208
|
+
this.state.set(name, {});
|
|
209
|
+
this.plugins.set(name, plugin);
|
|
210
|
+
this.configs.set(name, config);
|
|
211
|
+
await plugin.connect(config, (change) => {
|
|
212
|
+
const current = this.state.get(name) ?? {};
|
|
213
|
+
for (const path of change.paths) {
|
|
214
|
+
if (path in change.values) {
|
|
215
|
+
current[path] = change.values[path];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
this.state.set(name, current);
|
|
219
|
+
this.engine.setContext(name, current);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
get(name) {
|
|
223
|
+
return this.plugins.get(name);
|
|
224
|
+
}
|
|
225
|
+
has(name) {
|
|
226
|
+
return this.plugins.has(name);
|
|
227
|
+
}
|
|
228
|
+
getNames() {
|
|
229
|
+
return Array.from(this.plugins.keys());
|
|
230
|
+
}
|
|
231
|
+
getStatus(name) {
|
|
232
|
+
return this.plugins.get(name)?.status;
|
|
233
|
+
}
|
|
234
|
+
async remove(name) {
|
|
235
|
+
const plugin = this.plugins.get(name);
|
|
236
|
+
if (plugin) {
|
|
237
|
+
await plugin.disconnect();
|
|
238
|
+
this.plugins.delete(name);
|
|
239
|
+
this.configs.delete(name);
|
|
240
|
+
this.state.delete(name);
|
|
241
|
+
this.engine.removeContext(name);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
async disconnectAll() {
|
|
245
|
+
const names = Array.from(this.plugins.keys());
|
|
246
|
+
await Promise.all(names.map((name) => this.remove(name)));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
24
250
|
// src/state.ts
|
|
251
|
+
var IS_PROXY = Symbol.for("hypen.isProxy");
|
|
252
|
+
var RAW_TARGET = Symbol.for("hypen.rawTarget");
|
|
25
253
|
function deepClone(obj) {
|
|
26
254
|
if (obj === null || typeof obj !== "object") {
|
|
27
255
|
return obj;
|
|
@@ -266,19 +494,33 @@ function unwrapProxy(value) {
|
|
|
266
494
|
}
|
|
267
495
|
return value;
|
|
268
496
|
}
|
|
269
|
-
var IS_PROXY, RAW_TARGET;
|
|
270
|
-
var init_state = __esm(() => {
|
|
271
|
-
IS_PROXY = Symbol.for("hypen.isProxy");
|
|
272
|
-
RAW_TARGET = Symbol.for("hypen.rawTarget");
|
|
273
|
-
});
|
|
274
497
|
|
|
275
498
|
// src/logger.ts
|
|
499
|
+
var LOG_LEVEL_ORDER = {
|
|
500
|
+
debug: 0,
|
|
501
|
+
info: 1,
|
|
502
|
+
warn: 2,
|
|
503
|
+
error: 3,
|
|
504
|
+
none: 4
|
|
505
|
+
};
|
|
506
|
+
var LOG_LEVEL_COLORS = {
|
|
507
|
+
debug: "\x1B[36m",
|
|
508
|
+
info: "\x1B[32m",
|
|
509
|
+
warn: "\x1B[33m",
|
|
510
|
+
error: "\x1B[31m"
|
|
511
|
+
};
|
|
512
|
+
var RESET_COLOR = "\x1B[0m";
|
|
276
513
|
function isProduction() {
|
|
277
514
|
if (typeof process !== "undefined" && process.env) {
|
|
278
515
|
return false;
|
|
279
516
|
}
|
|
280
517
|
return false;
|
|
281
518
|
}
|
|
519
|
+
var config = {
|
|
520
|
+
level: isProduction() ? "error" : "info",
|
|
521
|
+
colors: true,
|
|
522
|
+
timestamps: false
|
|
523
|
+
};
|
|
282
524
|
function setLogLevel(level) {
|
|
283
525
|
config.level = level;
|
|
284
526
|
}
|
|
@@ -409,220 +651,49 @@ class Logger {
|
|
|
409
651
|
function createLogger(tag) {
|
|
410
652
|
return new Logger(tag);
|
|
411
653
|
}
|
|
412
|
-
var
|
|
413
|
-
var
|
|
414
|
-
|
|
415
|
-
debug
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
log = {
|
|
434
|
-
debug: (tag, ...args) => {
|
|
435
|
-
if (!shouldLog("debug"))
|
|
436
|
-
return;
|
|
437
|
-
console.log(formatTag(tag, "debug"), ...args);
|
|
438
|
-
},
|
|
439
|
-
info: (tag, ...args) => {
|
|
440
|
-
if (!shouldLog("info"))
|
|
441
|
-
return;
|
|
442
|
-
console.info(formatTag(tag, "info"), ...args);
|
|
443
|
-
},
|
|
444
|
-
warn: (tag, ...args) => {
|
|
445
|
-
if (!shouldLog("warn"))
|
|
446
|
-
return;
|
|
447
|
-
console.warn(formatTag(tag, "warn"), ...args);
|
|
448
|
-
},
|
|
449
|
-
error: (tag, ...args) => {
|
|
450
|
-
if (!shouldLog("error"))
|
|
451
|
-
return;
|
|
452
|
-
console.error(formatTag(tag, "error"), ...args);
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
frameworkLoggers = {
|
|
456
|
-
hypen: createLogger("Hypen"),
|
|
457
|
-
engine: createLogger("Engine"),
|
|
458
|
-
router: createLogger("Router"),
|
|
459
|
-
state: createLogger("State"),
|
|
460
|
-
events: createLogger("Events"),
|
|
461
|
-
remote: createLogger("Remote"),
|
|
462
|
-
renderer: createLogger("Renderer"),
|
|
463
|
-
module: createLogger("Module"),
|
|
464
|
-
lifecycle: createLogger("Lifecycle"),
|
|
465
|
-
loader: createLogger("Loader"),
|
|
466
|
-
context: createLogger("Context"),
|
|
467
|
-
discovery: createLogger("Discovery"),
|
|
468
|
-
plugin: createLogger("Plugin"),
|
|
469
|
-
canvas: createLogger("Canvas"),
|
|
470
|
-
debug: createLogger("Debug")
|
|
471
|
-
};
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
// src/result.ts
|
|
475
|
-
function Ok(value) {
|
|
476
|
-
return { ok: true, value };
|
|
477
|
-
}
|
|
478
|
-
function Err(error) {
|
|
479
|
-
return { ok: false, error };
|
|
480
|
-
}
|
|
481
|
-
function classifyEngineError(err) {
|
|
482
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
483
|
-
if (message.startsWith("Parse error:")) {
|
|
484
|
-
return new ParseError(message);
|
|
485
|
-
}
|
|
486
|
-
if (message.startsWith("Invalid state:") || message.startsWith("Invalid state patch:")) {
|
|
487
|
-
return new StateError(message);
|
|
488
|
-
}
|
|
489
|
-
if (message.startsWith("Parent node not found:")) {
|
|
490
|
-
return new RenderError(message);
|
|
491
|
-
}
|
|
492
|
-
return new RenderError(message);
|
|
493
|
-
}
|
|
494
|
-
var HypenError, ActionError, ConnectionError, StateError, ParseError, RenderError;
|
|
495
|
-
var init_result = __esm(() => {
|
|
496
|
-
HypenError = class HypenError extends Error {
|
|
497
|
-
code;
|
|
498
|
-
context;
|
|
499
|
-
cause;
|
|
500
|
-
constructor(code, message, options) {
|
|
501
|
-
super(message);
|
|
502
|
-
this.name = "HypenError";
|
|
503
|
-
this.code = code;
|
|
504
|
-
this.context = options?.context;
|
|
505
|
-
this.cause = options?.cause;
|
|
506
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
ActionError = class ActionError extends HypenError {
|
|
510
|
-
actionName;
|
|
511
|
-
constructor(actionName, cause) {
|
|
512
|
-
super("ACTION_ERROR", `Action handler "${actionName}" failed: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
513
|
-
context: { actionName },
|
|
514
|
-
cause: cause instanceof Error ? cause : undefined
|
|
515
|
-
});
|
|
516
|
-
this.name = "ActionError";
|
|
517
|
-
this.actionName = actionName;
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
ConnectionError = class ConnectionError extends HypenError {
|
|
521
|
-
url;
|
|
522
|
-
attempt;
|
|
523
|
-
constructor(url, cause, attempt) {
|
|
524
|
-
super("CONNECTION_ERROR", `Connection to "${url}" failed${attempt ? ` (attempt ${attempt})` : ""}: ${cause instanceof Error ? cause.message : String(cause)}`, {
|
|
525
|
-
context: { url, attempt },
|
|
526
|
-
cause: cause instanceof Error ? cause : undefined
|
|
527
|
-
});
|
|
528
|
-
this.name = "ConnectionError";
|
|
529
|
-
this.url = url;
|
|
530
|
-
this.attempt = attempt;
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
StateError = class StateError extends HypenError {
|
|
534
|
-
path;
|
|
535
|
-
constructor(message, path, cause) {
|
|
536
|
-
super("STATE_ERROR", message, {
|
|
537
|
-
context: { path },
|
|
538
|
-
cause: cause instanceof Error ? cause : undefined
|
|
539
|
-
});
|
|
540
|
-
this.name = "StateError";
|
|
541
|
-
this.path = path;
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
ParseError = class ParseError extends HypenError {
|
|
545
|
-
source;
|
|
546
|
-
constructor(message, source, cause) {
|
|
547
|
-
super("PARSE_ERROR", message, {
|
|
548
|
-
context: { source },
|
|
549
|
-
cause: cause instanceof Error ? cause : undefined
|
|
550
|
-
});
|
|
551
|
-
this.name = "ParseError";
|
|
552
|
-
this.source = source;
|
|
553
|
-
}
|
|
554
|
-
};
|
|
555
|
-
RenderError = class RenderError extends HypenError {
|
|
556
|
-
constructor(message, cause) {
|
|
557
|
-
super("RENDER_ERROR", message, {
|
|
558
|
-
cause: cause instanceof Error ? cause : undefined
|
|
559
|
-
});
|
|
560
|
-
this.name = "RenderError";
|
|
561
|
-
}
|
|
562
|
-
};
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
// src/datasource.ts
|
|
566
|
-
class DataSourceManager {
|
|
567
|
-
plugins = new Map;
|
|
568
|
-
configs = new Map;
|
|
569
|
-
state = new Map;
|
|
570
|
-
engine;
|
|
571
|
-
constructor(engine) {
|
|
572
|
-
this.engine = engine;
|
|
573
|
-
}
|
|
574
|
-
async use(plugin, config2) {
|
|
575
|
-
const { name } = plugin;
|
|
576
|
-
this.state.set(name, {});
|
|
577
|
-
this.plugins.set(name, plugin);
|
|
578
|
-
this.configs.set(name, config2);
|
|
579
|
-
await plugin.connect(config2, (change) => {
|
|
580
|
-
const current = this.state.get(name) ?? {};
|
|
581
|
-
for (const path of change.paths) {
|
|
582
|
-
if (path in change.values) {
|
|
583
|
-
current[path] = change.values[path];
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
this.state.set(name, current);
|
|
587
|
-
this.engine.setContext(name, current);
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
get(name) {
|
|
591
|
-
return this.plugins.get(name);
|
|
592
|
-
}
|
|
593
|
-
has(name) {
|
|
594
|
-
return this.plugins.has(name);
|
|
595
|
-
}
|
|
596
|
-
getNames() {
|
|
597
|
-
return Array.from(this.plugins.keys());
|
|
598
|
-
}
|
|
599
|
-
getStatus(name) {
|
|
600
|
-
return this.plugins.get(name)?.status;
|
|
601
|
-
}
|
|
602
|
-
async remove(name) {
|
|
603
|
-
const plugin = this.plugins.get(name);
|
|
604
|
-
if (plugin) {
|
|
605
|
-
await plugin.disconnect();
|
|
606
|
-
this.plugins.delete(name);
|
|
607
|
-
this.configs.delete(name);
|
|
608
|
-
this.state.delete(name);
|
|
609
|
-
this.engine.removeContext(name);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
async disconnectAll() {
|
|
613
|
-
const names = Array.from(this.plugins.keys());
|
|
614
|
-
await Promise.all(names.map((name) => this.remove(name)));
|
|
654
|
+
var logger = createLogger("Hypen");
|
|
655
|
+
var log = {
|
|
656
|
+
debug: (tag, ...args) => {
|
|
657
|
+
if (!shouldLog("debug"))
|
|
658
|
+
return;
|
|
659
|
+
console.log(formatTag(tag, "debug"), ...args);
|
|
660
|
+
},
|
|
661
|
+
info: (tag, ...args) => {
|
|
662
|
+
if (!shouldLog("info"))
|
|
663
|
+
return;
|
|
664
|
+
console.info(formatTag(tag, "info"), ...args);
|
|
665
|
+
},
|
|
666
|
+
warn: (tag, ...args) => {
|
|
667
|
+
if (!shouldLog("warn"))
|
|
668
|
+
return;
|
|
669
|
+
console.warn(formatTag(tag, "warn"), ...args);
|
|
670
|
+
},
|
|
671
|
+
error: (tag, ...args) => {
|
|
672
|
+
if (!shouldLog("error"))
|
|
673
|
+
return;
|
|
674
|
+
console.error(formatTag(tag, "error"), ...args);
|
|
615
675
|
}
|
|
616
|
-
}
|
|
676
|
+
};
|
|
677
|
+
var frameworkLoggers = {
|
|
678
|
+
hypen: createLogger("Hypen"),
|
|
679
|
+
engine: createLogger("Engine"),
|
|
680
|
+
router: createLogger("Router"),
|
|
681
|
+
state: createLogger("State"),
|
|
682
|
+
events: createLogger("Events"),
|
|
683
|
+
remote: createLogger("Remote"),
|
|
684
|
+
renderer: createLogger("Renderer"),
|
|
685
|
+
module: createLogger("Module"),
|
|
686
|
+
lifecycle: createLogger("Lifecycle"),
|
|
687
|
+
loader: createLogger("Loader"),
|
|
688
|
+
context: createLogger("Context"),
|
|
689
|
+
discovery: createLogger("Discovery"),
|
|
690
|
+
plugin: createLogger("Plugin"),
|
|
691
|
+
canvas: createLogger("Canvas"),
|
|
692
|
+
debug: createLogger("Debug")
|
|
693
|
+
};
|
|
617
694
|
|
|
618
695
|
// src/app.ts
|
|
619
|
-
var
|
|
620
|
-
__export(exports_app, {
|
|
621
|
-
app: () => app,
|
|
622
|
-
HypenModuleInstance: () => HypenModuleInstance,
|
|
623
|
-
HypenAppBuilder: () => HypenAppBuilder,
|
|
624
|
-
HypenApp: () => HypenApp
|
|
625
|
-
});
|
|
696
|
+
var log2 = createLogger("ModuleInstance");
|
|
626
697
|
|
|
627
698
|
class HypenAppBuilder {
|
|
628
699
|
initialState;
|
|
@@ -746,6 +817,7 @@ class HypenApp {
|
|
|
746
817
|
this._registry.clear();
|
|
747
818
|
}
|
|
748
819
|
}
|
|
820
|
+
var app = new HypenApp;
|
|
749
821
|
|
|
750
822
|
class HypenModuleInstance {
|
|
751
823
|
engine;
|
|
@@ -949,16 +1021,6 @@ class HypenModuleInstance {
|
|
|
949
1021
|
Object.assign(this.state, patch);
|
|
950
1022
|
}
|
|
951
1023
|
}
|
|
952
|
-
var log2, app;
|
|
953
|
-
var init_app = __esm(() => {
|
|
954
|
-
init_result();
|
|
955
|
-
init_state();
|
|
956
|
-
init_logger();
|
|
957
|
-
log2 = createLogger("ModuleInstance");
|
|
958
|
-
app = new HypenApp;
|
|
959
|
-
});
|
|
960
|
-
init_app();
|
|
961
|
-
|
|
962
1024
|
export {
|
|
963
1025
|
app,
|
|
964
1026
|
HypenModuleInstance,
|
|
@@ -966,4 +1028,4 @@ export {
|
|
|
966
1028
|
HypenApp
|
|
967
1029
|
};
|
|
968
1030
|
|
|
969
|
-
//# debugId=
|
|
1031
|
+
//# debugId=24B072C0F00911D864756E2164756E21
|