@hypen-space/core 0.4.36 → 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
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/hypen.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Hypen Tagged Template Literal\n *\n * Enables single-file components with inline UI templates.\n *\n * The `hypen` tagged template preserves ${state.x} and ${item.x} bindings\n * instead of interpolating them, allowing you to write:\n *\n * @example\n * ```typescript\n * import { app, hypen, state } from \"@hypen-space/core\";\n *\n * export default app\n * .defineState({ count: 0 })\n * .onAction(\"increment\", ({ state }) => {\n * state.count += 1;\n * })\n * .ui(hypen`\n * Column {\n * Text(\"Count: ${state.count}\")\n * Button { Text(\"+\") }\n * .onClick(\"@actions.increment\")\n * }\n * `);\n * ```\n */\n\n/**\n * Creates a proxy that captures property access as a binding path string.\n *\n * When used in a template literal, the proxy's toString() returns the\n * full binding expression (e.g., \"${state.user.name}\").\n *\n * @example\n * ```typescript\n * const state = createBindingProxy('state');\n * `${state.user.name}` // Returns: \"${state.user.name}\"\n * ```\n */\nfunction createBindingProxy(root: string): any {\n const handler: ProxyHandler<object> = {\n get(_, prop: string | symbol): any {\n // Handle Symbol.toPrimitive, toString, and valueOf for string conversion\n if (\n prop === Symbol.toPrimitive ||\n prop === \"toString\" ||\n prop === \"valueOf\"\n ) {\n return () => `\\${${root}}`;\n }\n\n // Handle other Symbol properties (e.g., Symbol.toStringTag)\n if (typeof prop === \"symbol\") {\n return undefined;\n }\n\n // Handle JSON.stringify\n if (prop === \"toJSON\") {\n return () => `\\${${root}}`;\n }\n\n // Chain to nested property: state.user -> state.user.name\n return createBindingProxy(`${root}.${prop}`);\n },\n\n // Support for `in` operator\n has() {\n return true;\n },\n\n // Support for Object.keys() - return empty to avoid enumeration issues\n ownKeys() {\n return [];\n },\n\n getOwnPropertyDescriptor() {\n return {\n configurable: true,\n enumerable: true,\n };\n },\n };\n\n return new Proxy({} as any, handler);\n}\n\n/**\n * Proxy for state bindings.\n *\n * Use in hypen templates to create reactive state bindings:\n *\n * @example\n * ```typescript\n * hypen`Text(\"Hello, ${state.user.name}\")`\n * // Produces: Text(\"Hello, ${state.user.name}\")\n * ```\n */\nexport const state: any = createBindingProxy(\"state\");\n\n/**\n * Proxy for item bindings in list iteration.\n *\n * Use inside List components to reference the current item:\n *\n * @example\n * ```typescript\n * hypen`\n * List(@state.items) {\n * Text(\"${item.name}: ${item.price}\")\n * }\n * `\n * ```\n */\nexport const item: any = createBindingProxy(\"item\");\n\n/**\n * Proxy for index in list iteration.\n *\n * Use inside List components to reference the current index:\n *\n * @example\n * ```typescript\n * hypen`\n * List(@state.items) {\n * Text(\"Item #${index}: ${item.name}\")\n * }\n * `\n * ```\n */\nexport const index: any = {\n [Symbol.toPrimitive]: () => \"${index}\",\n toString: () => \"${index}\",\n valueOf: () => \"${index}\",\n toJSON: () => \"${index}\",\n};\n\n/**\n * Tagged template literal for Hypen DSL templates.\n *\n * Works with the `state`, `item`, and `index` binding proxies to preserve\n * binding syntax in the output string.\n *\n * @example\n * ```typescript\n * import { hypen, state, item } from \"@hypen-space/core\";\n *\n * // Simple state binding\n * const t1 = hypen`Text(\"Count: ${state.count}\")`;\n * // Result: 'Text(\"Count: ${state.count}\")'\n *\n * // Nested state binding\n * const t2 = hypen`Text(\"Hello, ${state.user.profile.name}\")`;\n * // Result: 'Text(\"Hello, ${state.user.profile.name}\")'\n *\n * // List with item binding\n * const t3 = hypen`\n * List(@state.products) {\n * Text(\"${item.name} - $${item.price}\")\n * }\n * `;\n *\n * // Complex expressions (use regular JS interpolation for static values)\n * const title = \"My App\";\n * const t4 = hypen`Text(\"${title}: ${state.count}\")`;\n * // Result: 'Text(\"My App: ${state.count}\")'\n * ```\n *\n * @param strings - Template literal string parts\n * @param expressions - Interpolated expressions (proxies return binding strings)\n * @returns The template string with bindings preserved\n */\nexport function hypen(\n strings: TemplateStringsArray,\n ...expressions: unknown[]\n): string {\n let result = strings[0];\n\n for (let i = 0; i < expressions.length; i++) {\n const expr = expressions[i];\n\n // Convert expression to string\n // Binding proxies will return \"${state.x}\" via their toString()\n result += String(expr);\n result += strings[i + 1]!;\n }\n\n return result!.trim();\n}\n\n/**\n * Type helper for defining state shape.\n * Use with state proxy for better IDE support in complex scenarios.\n *\n * @example\n * ```typescript\n * type MyState = { user: { name: string; age: number } };\n * const typedState = state as StateProxy<MyState>;\n * ```\n */\nexport type StateProxy<T> = {\n [K in keyof T]: T[K] extends object\n ? StateProxy<T[K]> & { toString(): string }\n : { toString(): string };\n} & { toString(): string };\n\n/**\n * Type helper for item proxy in lists.\n */\nexport type ItemProxy<T> = StateProxy<T>;\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAS,kBAAkB,CAAC,MAAmB;AAAA,EAC7C,MAAM,UAAgC;AAAA,IACpC,GAAG,CAAC,GAAG,MAA4B;AAAA,MAEjC,IACE,SAAS,OAAO,eAChB,SAAS,cACT,SAAS,WACT;AAAA,QACA,OAAO,MAAM,MAAM;AAAA,MACrB;AAAA,MAGA,IAAI,OAAO,SAAS,UAAU;AAAA,QAC5B;AAAA,MACF;AAAA,MAGA,IAAI,SAAS,UAAU;AAAA,QACrB,OAAO,MAAM,MAAM;AAAA,MACrB;AAAA,MAGA,OAAO,mBAAmB,GAAG,QAAQ,MAAM;AAAA;AAAA,IAI7C,GAAG,GAAG;AAAA,MACJ,OAAO;AAAA;AAAA,IAIT,OAAO,GAAG;AAAA,MACR,OAAO,CAAC;AAAA;AAAA,IAGV,wBAAwB,GAAG;AAAA,MACzB,OAAO;AAAA,QACL,cAAc;AAAA,QACd,YAAY;AAAA,MACd;AAAA;AAAA,EAEJ;AAAA,EAEA,OAAO,IAAI,MAAM,CAAC,GAAU,OAAO;AAAA;AAc9B,IAAM,QAAa,mBAAmB,OAAO;AAgB7C,IAAM,OAAY,mBAAmB,MAAM;AAgB3C,IAAM,QAAa;AAAA,GACvB,OAAO,cAAc,MAAM;AAAA,EAC5B,UAAU,MAAM;AAAA,EAChB,SAAS,MAAM;AAAA,EACf,QAAQ,MAAM;AAChB;AAqCO,SAAS,KAAK,CACnB,YACG,aACK;AAAA,EACR,IAAI,SAAS,QAAQ;AAAA,EAErB,SAAS,IAAI,EAAG,IAAI,YAAY,QAAQ,KAAK;AAAA,IAC3C,MAAM,OAAO,YAAY;AAAA,IAIzB,UAAU,OAAO,IAAI;AAAA,IACrB,UAAU,QAAQ,IAAI;AAAA,EACxB;AAAA,EAEA,OAAO,OAAQ,KAAK;AAAA;",
|
|
8
|
+
"debugId": "00831BA93E2ED31164756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @hypen-space/core - Browser Entry Point
|
|
3
3
|
*
|
|
4
|
-
* This entry point
|
|
4
|
+
* This entry point exports platform-agnostic runtime APIs for browser use.
|
|
5
|
+
* Engine has moved to @hypen-space/web-engine (browser) and @hypen-space/server (Node.js).
|
|
5
6
|
*/
|
|
6
7
|
export type { Patch, Action, RenderCallback, ActionHandler as EngineActionHandler, ResolvedComponent, ComponentResolver, } from "./types.js";
|
|
7
8
|
export { app, HypenApp, HypenAppBuilder, HypenModuleInstance } from "./app.js";
|
package/dist/index.browser.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,17 +1021,8 @@ 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
1024
|
|
|
961
1025
|
// src/renderer.ts
|
|
962
|
-
init_logger();
|
|
963
1026
|
var log3 = frameworkLoggers.renderer;
|
|
964
1027
|
|
|
965
1028
|
class BaseRenderer {
|
|
@@ -1011,7 +1074,6 @@ class ConsoleRenderer {
|
|
|
1011
1074
|
}
|
|
1012
1075
|
|
|
1013
1076
|
// src/disposable.ts
|
|
1014
|
-
init_logger();
|
|
1015
1077
|
var log4 = frameworkLoggers.lifecycle;
|
|
1016
1078
|
function isDisposable(obj) {
|
|
1017
1079
|
return obj !== null && typeof obj === "object" && "dispose" in obj && typeof obj.dispose === "function";
|
|
@@ -1159,8 +1221,6 @@ function usingSync(resource, fn) {
|
|
|
1159
1221
|
}
|
|
1160
1222
|
|
|
1161
1223
|
// src/router.ts
|
|
1162
|
-
init_state();
|
|
1163
|
-
init_logger();
|
|
1164
1224
|
var log5 = frameworkLoggers.router;
|
|
1165
1225
|
|
|
1166
1226
|
class HypenRouter {
|
|
@@ -1310,12 +1370,12 @@ class HypenRouter {
|
|
|
1310
1370
|
return "([^/]+)";
|
|
1311
1371
|
}).replace(/\*/g, ".*");
|
|
1312
1372
|
const regex = new RegExp(`^${regexPattern}$`);
|
|
1313
|
-
const
|
|
1314
|
-
if (!
|
|
1373
|
+
const match2 = path.match(regex);
|
|
1374
|
+
if (!match2)
|
|
1315
1375
|
return null;
|
|
1316
1376
|
const params = {};
|
|
1317
1377
|
paramNames.forEach((name, i) => {
|
|
1318
|
-
const value =
|
|
1378
|
+
const value = match2[i + 1];
|
|
1319
1379
|
if (value !== undefined) {
|
|
1320
1380
|
params[name] = decodeURIComponent(value);
|
|
1321
1381
|
}
|
|
@@ -1372,7 +1432,6 @@ class HypenRouter {
|
|
|
1372
1432
|
}
|
|
1373
1433
|
|
|
1374
1434
|
// src/events.ts
|
|
1375
|
-
init_logger();
|
|
1376
1435
|
var log6 = frameworkLoggers.events;
|
|
1377
1436
|
|
|
1378
1437
|
class TypedEventEmitter {
|
|
@@ -1438,7 +1497,6 @@ function createEventEmitter() {
|
|
|
1438
1497
|
}
|
|
1439
1498
|
|
|
1440
1499
|
// src/context.ts
|
|
1441
|
-
init_logger();
|
|
1442
1500
|
var log7 = frameworkLoggers.context;
|
|
1443
1501
|
|
|
1444
1502
|
class HypenGlobalContext {
|
|
@@ -1543,11 +1601,7 @@ class HypenGlobalContext {
|
|
|
1543
1601
|
}
|
|
1544
1602
|
}
|
|
1545
1603
|
|
|
1546
|
-
// src/remote/client.ts
|
|
1547
|
-
init_result();
|
|
1548
|
-
|
|
1549
1604
|
// src/retry.ts
|
|
1550
|
-
init_result();
|
|
1551
1605
|
var DEFAULT_OPTIONS = {
|
|
1552
1606
|
maxAttempts: 3,
|
|
1553
1607
|
delayMs: 1000,
|
|
@@ -1611,6 +1665,17 @@ async function retry(fn, options = {}) {
|
|
|
1611
1665
|
}
|
|
1612
1666
|
throw lastError;
|
|
1613
1667
|
}
|
|
1668
|
+
async function retryResult(fn, options = {}) {
|
|
1669
|
+
try {
|
|
1670
|
+
const value = await retry(fn, options);
|
|
1671
|
+
return Ok(value);
|
|
1672
|
+
} catch (e) {
|
|
1673
|
+
return Err(e instanceof Error ? e : new Error(String(e)));
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
function withRetry(fn, options = {}) {
|
|
1677
|
+
return (...args) => retry(() => fn(...args), options);
|
|
1678
|
+
}
|
|
1614
1679
|
var RetryConditions = {
|
|
1615
1680
|
networkErrors: (error) => {
|
|
1616
1681
|
const message = error.message.toLowerCase();
|
|
@@ -1662,7 +1727,6 @@ var RetryPresets = {
|
|
|
1662
1727
|
};
|
|
1663
1728
|
|
|
1664
1729
|
// src/remote/client.ts
|
|
1665
|
-
init_logger();
|
|
1666
1730
|
var log8 = frameworkLoggers.remote;
|
|
1667
1731
|
|
|
1668
1732
|
class RemoteEngine {
|
|
@@ -1928,11 +1992,6 @@ class RemoteEngine {
|
|
|
1928
1992
|
}, this.options.reconnectInterval);
|
|
1929
1993
|
}
|
|
1930
1994
|
}
|
|
1931
|
-
|
|
1932
|
-
// src/index.browser.ts
|
|
1933
|
-
init_app();
|
|
1934
|
-
init_state();
|
|
1935
|
-
init_logger();
|
|
1936
1995
|
export {
|
|
1937
1996
|
setLogLevel,
|
|
1938
1997
|
setDebugMode,
|
|
@@ -1970,4 +2029,4 @@ export {
|
|
|
1970
2029
|
BaseRenderer
|
|
1971
2030
|
};
|
|
1972
2031
|
|
|
1973
|
-
//# debugId=
|
|
2032
|
+
//# debugId=C6D5A3EDD25535C064756E2164756E21
|