@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
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The main Hypen engine interface for JavaScript/WASM runtimes.
|
|
6
|
-
*
|
|
7
|
-
* `WasmEngine` manages the full lifecycle of a Hypen UI: parsing DSL source,
|
|
8
|
-
* maintaining the virtual tree, tracking reactive dependencies, and emitting
|
|
9
|
-
* minimal patches when state changes. It runs in a single-threaded WASM
|
|
10
|
-
* environment (browsers, Node.js, Bun, Deno).
|
|
11
|
-
*
|
|
12
|
-
* # Quick Start
|
|
13
|
-
*
|
|
14
|
-
* ```js
|
|
15
|
-
* import { WasmEngine } from "@hypen-space/core";
|
|
16
|
-
*
|
|
17
|
-
* const engine = new WasmEngine();
|
|
18
|
-
*
|
|
19
|
-
* // 1. Register primitives so the engine doesn't try to resolve them as components
|
|
20
|
-
* engine.registerPrimitive("Text");
|
|
21
|
-
* engine.registerPrimitive("Column");
|
|
22
|
-
*
|
|
23
|
-
* // 2. Receive patches via callback
|
|
24
|
-
* engine.setRenderCallback((patches) => {
|
|
25
|
-
* for (const patch of patches) {
|
|
26
|
-
* applyPatch(patch); // Create, SetProp, Insert, Remove, etc.
|
|
27
|
-
* }
|
|
28
|
-
* });
|
|
29
|
-
*
|
|
30
|
-
* // 3. Optionally set up a module for stateful UI
|
|
31
|
-
* engine.setModule("Counter", ["increment"], ["count"], { count: 0 });
|
|
32
|
-
*
|
|
33
|
-
* // 4. Render DSL source — patches are emitted via the callback
|
|
34
|
-
* engine.renderSource('Column { Text("Count: ${state.count}") }');
|
|
35
|
-
*
|
|
36
|
-
* // 5. Update state — only affected nodes are re-rendered
|
|
37
|
-
* engine.updateState({ count: 1 });
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* # Patch Protocol
|
|
41
|
-
*
|
|
42
|
-
* All UI mutations are expressed as [`Patch`] values emitted through the render
|
|
43
|
-
* callback. Patches use camelCase field names for direct JavaScript consumption.
|
|
44
|
-
* See [`Patch`] for the full variant list and field documentation.
|
|
45
|
-
*
|
|
46
|
-
* # Component Resolution
|
|
47
|
-
*
|
|
48
|
-
* Custom components (anything not registered as a primitive) are resolved lazily
|
|
49
|
-
* via the component resolver callback set with [`set_component_resolver`]. The
|
|
50
|
-
* resolver receives `(componentName, contextPath)` and should return
|
|
51
|
-
* `{ source: string, path: string }` or `null`.
|
|
52
|
-
*
|
|
53
|
-
* # Revision Tracking
|
|
54
|
-
*
|
|
55
|
-
* Every render cycle (initial render or state update that produces patches)
|
|
56
|
-
* increments the revision counter. Use [`get_revision`] to detect stale state
|
|
57
|
-
* in async workflows.
|
|
58
|
-
*/
|
|
59
|
-
export class WasmEngine {
|
|
60
|
-
free(): void;
|
|
61
|
-
[Symbol.dispose](): void;
|
|
62
|
-
/**
|
|
63
|
-
* Remove all nodes from the instance tree without emitting Remove patches.
|
|
64
|
-
*
|
|
65
|
-
* Use this when tearing down the UI entirely (e.g. navigating away or
|
|
66
|
-
* switching samples). The renderer is responsible for clearing its own
|
|
67
|
-
* DOM/canvas state separately.
|
|
68
|
-
*/
|
|
69
|
-
clearTree(): void;
|
|
70
|
-
/**
|
|
71
|
-
* Return a JSON snapshot of the active module's current state.
|
|
72
|
-
*
|
|
73
|
-
* Returns `null` (as a `JsValue`) if no module is set.
|
|
74
|
-
* Useful for debugging and DevTools integration.
|
|
75
|
-
*/
|
|
76
|
-
currentState(): any;
|
|
77
|
-
/**
|
|
78
|
-
* Parse a component and return a human-readable debug string.
|
|
79
|
-
*
|
|
80
|
-
* Intended for development tooling only — the output format is not stable.
|
|
81
|
-
*/
|
|
82
|
-
debugParseComponent(source: string): string;
|
|
83
|
-
/**
|
|
84
|
-
* Dispatch a named action, invoking the registered handler (if any).
|
|
85
|
-
*
|
|
86
|
-
* Actions are the primary way UI events flow from the renderer back to
|
|
87
|
-
* application logic. In Hypen DSL, buttons reference actions like
|
|
88
|
-
* `Button("@actions.submit")` — the renderer maps clicks to
|
|
89
|
-
* `engine.dispatchAction("submit", payload)`.
|
|
90
|
-
*
|
|
91
|
-
* # Arguments
|
|
92
|
-
* * `name` — Action name (e.g. `"submit"`, `"increment"`)
|
|
93
|
-
* * `payload` — Optional JS value passed to the handler. `null`/`undefined` are treated as no payload.
|
|
94
|
-
*
|
|
95
|
-
* # Errors
|
|
96
|
-
*
|
|
97
|
-
* Returns an error if the payload cannot be deserialized. Does **not** error
|
|
98
|
-
* if no handler is registered (the action is silently dropped).
|
|
99
|
-
*/
|
|
100
|
-
dispatchAction(name: string, payload: any): void;
|
|
101
|
-
/**
|
|
102
|
-
* Get the current revision number.
|
|
103
|
-
*
|
|
104
|
-
* Starts at 0 and increments by 1 for each render cycle that produces
|
|
105
|
-
* patches. Useful for cache invalidation and detecting stale async results.
|
|
106
|
-
*/
|
|
107
|
-
getRevision(): bigint;
|
|
108
|
-
/**
|
|
109
|
-
* Create a new engine instance with an empty tree and no module.
|
|
110
|
-
*
|
|
111
|
-
* After construction, you typically:
|
|
112
|
-
* 1. Register primitives with [`register_primitive`]
|
|
113
|
-
* 2. Set a render callback with [`set_render_callback`]
|
|
114
|
-
* 3. Optionally set a component resolver with [`set_component_resolver`]
|
|
115
|
-
* 4. Optionally initialize a module with [`set_module`]
|
|
116
|
-
* 5. Render source with [`render_source`]
|
|
117
|
-
*/
|
|
118
|
-
constructor();
|
|
119
|
-
/**
|
|
120
|
-
* Register a JavaScript function as the handler for a named action.
|
|
121
|
-
*
|
|
122
|
-
* When [`dispatch_action`] is called with a matching name, the handler
|
|
123
|
-
* receives a serialized [`Action`] object with `{ name, payload }`.
|
|
124
|
-
*
|
|
125
|
-
* Registering a handler for the same name replaces the previous one.
|
|
126
|
-
*/
|
|
127
|
-
onAction(action_name: string, handler: Function): void;
|
|
128
|
-
/**
|
|
129
|
-
* Register a handler for data source actions.
|
|
130
|
-
*
|
|
131
|
-
* When [`dispatch_action`] is called with a name like `"spacetime.sendMessage"`
|
|
132
|
-
* and no explicit action handler is registered for that name, the engine checks
|
|
133
|
-
* if the prefix (`"spacetime"`) is a registered data source. If so, it calls
|
|
134
|
-
* this handler with `{ provider, method, payload }`.
|
|
135
|
-
*
|
|
136
|
-
* This enables `@actions.spacetime.sendMessage` in DSL to automatically route
|
|
137
|
-
* to the appropriate data source plugin without manual handler registration.
|
|
138
|
-
*/
|
|
139
|
-
onDataSourceAction(handler: Function): void;
|
|
140
|
-
/**
|
|
141
|
-
* Register a primitive element (like Text, Button, etc.) to skip component resolution
|
|
142
|
-
* This prevents unnecessary resolver calls for built-in DOM elements
|
|
143
|
-
*/
|
|
144
|
-
registerPrimitive(name: string): void;
|
|
145
|
-
/**
|
|
146
|
-
* Remove a data source context entirely.
|
|
147
|
-
*
|
|
148
|
-
* Drops the provider's state and re-renders bound nodes (they resolve to `null`).
|
|
149
|
-
*/
|
|
150
|
-
removeContext(name: string): void;
|
|
151
|
-
/**
|
|
152
|
-
* Render a component into a specific parent node (subtree rendering)
|
|
153
|
-
* This is used for lazy routing where components are rendered on-demand into route containers
|
|
154
|
-
*
|
|
155
|
-
* # Arguments
|
|
156
|
-
* * `source` - The Hypen DSL source to parse and render
|
|
157
|
-
* * `parent_node_id_str` - The serialized node ID string of the parent element
|
|
158
|
-
* * `state_js` - The state to use for rendering (as JsValue)
|
|
159
|
-
*/
|
|
160
|
-
renderInto(source: string, parent_node_id_str: string, state_js: any): void;
|
|
161
|
-
/**
|
|
162
|
-
* Render a component source on-demand (for lazy-loaded routes).
|
|
163
|
-
*
|
|
164
|
-
* Equivalent to calling [`render_source`] — the source is parsed as a full
|
|
165
|
-
* document and replaces the current tree.
|
|
166
|
-
*/
|
|
167
|
-
renderLazyComponent(source: string): void;
|
|
168
|
-
/**
|
|
169
|
-
* Parse and render Hypen DSL source code, emitting patches via the render callback.
|
|
170
|
-
*
|
|
171
|
-
* Supports full document syntax including `import` statements. Imports are
|
|
172
|
-
* resolved synchronously through the component resolver callback (if set).
|
|
173
|
-
*
|
|
174
|
-
* This performs a **full reconciliation** — the existing tree is diffed against
|
|
175
|
-
* the new IR and minimal patches are emitted. Calling this multiple times with
|
|
176
|
-
* different source replaces the previous UI.
|
|
177
|
-
*
|
|
178
|
-
* # Errors
|
|
179
|
-
*
|
|
180
|
-
* Returns a `JsValue` string error if the source fails to parse.
|
|
181
|
-
*/
|
|
182
|
-
renderSource(source: string): void;
|
|
183
|
-
/**
|
|
184
|
-
* Fully reset the engine to its initial empty state.
|
|
185
|
-
*
|
|
186
|
-
* Clears the tree, module, dependencies, scheduler, action handlers,
|
|
187
|
-
* component registry, and resets the revision to 0. The render callback
|
|
188
|
-
* and component resolver are preserved.
|
|
189
|
-
*/
|
|
190
|
-
reset(): void;
|
|
191
|
-
/**
|
|
192
|
-
* Set the component resolver callback
|
|
193
|
-
* The resolver receives (componentName, contextPath) and should return
|
|
194
|
-
* { source: string, path: string } or null
|
|
195
|
-
*
|
|
196
|
-
* contextPath is the path of the component that's referencing this component
|
|
197
|
-
* The returned path should be the resolved absolute path to the component file
|
|
198
|
-
*/
|
|
199
|
-
setComponentResolver(resolver: Function): void;
|
|
200
|
-
/**
|
|
201
|
-
* Set (or replace) a named data source context.
|
|
202
|
-
*
|
|
203
|
-
* Registers the provider in the dependency graph (if not already known),
|
|
204
|
-
* stores the data, and re-renders every node bound to `$name.*`.
|
|
205
|
-
* Sparse merging (if needed) should happen at the SDK layer before
|
|
206
|
-
* calling this method with the merged object.
|
|
207
|
-
*
|
|
208
|
-
* # Example (JS)
|
|
209
|
-
* ```js
|
|
210
|
-
* engine.setContext("spacetime", {
|
|
211
|
-
* message: [{ id: 1, text: "Hello" }, { id: 2, text: "World" }],
|
|
212
|
-
* user: [{ id: 1, name: "Alice", online: true }]
|
|
213
|
-
* });
|
|
214
|
-
* ```
|
|
215
|
-
*/
|
|
216
|
-
setContext(name: string, data_js: any): void;
|
|
217
|
-
/**
|
|
218
|
-
* Initialize (or replace) the active module with the given configuration.
|
|
219
|
-
*
|
|
220
|
-
* A module provides stateful context for `${state.xxx}` bindings in the DSL.
|
|
221
|
-
* Only one module is active at a time — calling this again replaces it.
|
|
222
|
-
*
|
|
223
|
-
* # Arguments
|
|
224
|
-
* * `name` — Module identifier (e.g. `"Counter"`, `"ProfilePage"`)
|
|
225
|
-
* * `actions` — List of action names this module handles
|
|
226
|
-
* * `state_keys` — List of top-level state keys (used for validation)
|
|
227
|
-
* * `initial_state` — The starting state as a JS object
|
|
228
|
-
*
|
|
229
|
-
* # Errors
|
|
230
|
-
*
|
|
231
|
-
* Returns an error if `initial_state` cannot be deserialized as JSON.
|
|
232
|
-
*/
|
|
233
|
-
setModule(name: string, actions: string[], state_keys: string[], initial_state: any): void;
|
|
234
|
-
/**
|
|
235
|
-
* Set the callback that receives UI patches after each render cycle.
|
|
236
|
-
*
|
|
237
|
-
* The callback is invoked with a single argument: a JavaScript array of
|
|
238
|
-
* [`Patch`] objects. Each patch describes one atomic DOM operation (Create,
|
|
239
|
-
* SetProp, SetText, Insert, Move, Remove, RemoveProp).
|
|
240
|
-
*
|
|
241
|
-
* The callback is called synchronously during `renderSource()`, `updateState()`,
|
|
242
|
-
* `updateStateSparse()`, and `renderInto()`.
|
|
243
|
-
*
|
|
244
|
-
* # Example (JS)
|
|
245
|
-
* ```js
|
|
246
|
-
* engine.setRenderCallback((patches) => {
|
|
247
|
-
* for (const p of patches) {
|
|
248
|
-
* switch (p.type) {
|
|
249
|
-
* case "create": createElement(p.id, p.elementType, p.props); break;
|
|
250
|
-
* case "setProp": setProperty(p.id, p.name, p.value); break;
|
|
251
|
-
* case "insert": insertChild(p.parentId, p.id, p.beforeId); break;
|
|
252
|
-
* // ...
|
|
253
|
-
* }
|
|
254
|
-
* }
|
|
255
|
-
* });
|
|
256
|
-
* ```
|
|
257
|
-
*/
|
|
258
|
-
setRenderCallback(callback: Function): void;
|
|
259
|
-
/**
|
|
260
|
-
* Return the total number of nodes currently in the instance tree.
|
|
261
|
-
*
|
|
262
|
-
* Useful for debugging, performance monitoring, and DevTools.
|
|
263
|
-
*/
|
|
264
|
-
treeSize(): number;
|
|
265
|
-
/**
|
|
266
|
-
* Apply a state patch and re-render affected nodes.
|
|
267
|
-
*
|
|
268
|
-
* The `state_patch` is a JavaScript object whose keys are merged into the
|
|
269
|
-
* current module state (deep merge). Only nodes whose bindings reference
|
|
270
|
-
* changed paths are re-rendered, producing minimal patches.
|
|
271
|
-
*
|
|
272
|
-
* # Example (JS)
|
|
273
|
-
* ```js
|
|
274
|
-
* // Updates state.user.name and state.count, re-renders bound nodes
|
|
275
|
-
* engine.updateState({ user: { name: "Bob" }, count: 42 });
|
|
276
|
-
* ```
|
|
277
|
-
*
|
|
278
|
-
* # Errors
|
|
279
|
-
*
|
|
280
|
-
* Returns an error if `state_patch` cannot be deserialized as JSON.
|
|
281
|
-
*/
|
|
282
|
-
updateState(state_patch: any): void;
|
|
283
|
-
/**
|
|
284
|
-
* Apply a sparse state update using explicit path-value pairs.
|
|
285
|
-
*
|
|
286
|
-
* More efficient than [`update_state`] for large state objects when only a
|
|
287
|
-
* few deeply-nested paths changed, because it avoids a full deep-merge.
|
|
288
|
-
*
|
|
289
|
-
* # Arguments
|
|
290
|
-
* * `paths_js` — JS array of dot-separated paths that changed (e.g. `["user.name", "count"]`)
|
|
291
|
-
* * `values_js` — JS object mapping each path to its new value (e.g. `{ "user.name": "Bob", "count": 42 }`)
|
|
292
|
-
*
|
|
293
|
-
* # Errors
|
|
294
|
-
*
|
|
295
|
-
* Returns an error if either argument cannot be deserialized.
|
|
296
|
-
*/
|
|
297
|
-
updateStateSparse(paths_js: any, values_js: any): void;
|
|
298
|
-
/**
|
|
299
|
-
* Validate that the engine is in a consistent state.
|
|
300
|
-
*
|
|
301
|
-
* Checks that:
|
|
302
|
-
* - All child references point to existing nodes
|
|
303
|
-
* - All parent back-references are correct
|
|
304
|
-
* - The root node (if any) exists in the tree
|
|
305
|
-
*
|
|
306
|
-
* Returns `null` if valid, or a string describing the first inconsistency found.
|
|
307
|
-
* Intended for testing and debugging only — not for production hot paths.
|
|
308
|
-
*/
|
|
309
|
-
validate(): any;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export function main(): void;
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Parse Hypen DSL source and return the AST as a pretty-printed JSON string.
|
|
316
|
-
*
|
|
317
|
-
* Useful for tooling, syntax highlighting, and debugging the parser output.
|
|
318
|
-
*/
|
|
319
|
-
export function parseToJson(source: string): string;
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Serialize a patches array to a pretty-printed JSON string.
|
|
323
|
-
*
|
|
324
|
-
* Intended for debugging and logging — not for production use.
|
|
325
|
-
* Accepts a JS array of patch objects and returns formatted JSON.
|
|
326
|
-
*/
|
|
327
|
-
export function patchesToJson(patches: any): string;
|