@xpell/core 2.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/LICENSE +21 -0
  3. package/README.md +96 -0
  4. package/dist/XCommand.d.ts +84 -0
  5. package/dist/XConst.d.ts +28 -0
  6. package/dist/XData.d.ts +51 -0
  7. package/dist/XError.d.ts +34 -0
  8. package/dist/XEventManager.d.ts +57 -0
  9. package/dist/XLogger.d.ts +32 -0
  10. package/dist/XModule.d.ts +161 -0
  11. package/dist/XNanoCommands.d.ts +42 -0
  12. package/dist/XObject.d.ts +287 -0
  13. package/dist/XObjectManager.d.ts +96 -0
  14. package/dist/XParams.d.ts +60 -0
  15. package/dist/XParser.d.ts +77 -0
  16. package/dist/XProtocol.d.ts +56 -0
  17. package/dist/XUtils.d.ts +100 -0
  18. package/dist/Xpell.d.ts +142 -0
  19. package/dist/index.d.ts +9 -0
  20. package/dist/xpell-core.cjs.js +3 -0
  21. package/dist/xpell-core.es.js +1428 -0
  22. package/docs/Codex.md +138 -0
  23. package/docs/XData 2.md +209 -0
  24. package/docs/api/.nojekyll +1 -0
  25. package/docs/api/assets/hierarchy.js +1 -0
  26. package/docs/api/assets/highlight.css +71 -0
  27. package/docs/api/assets/icons.js +18 -0
  28. package/docs/api/assets/icons.svg +1 -0
  29. package/docs/api/assets/main.js +60 -0
  30. package/docs/api/assets/navigation.js +1 -0
  31. package/docs/api/assets/search.js +1 -0
  32. package/docs/api/assets/style.css +1611 -0
  33. package/docs/api/classes/XCommand.html +23 -0
  34. package/docs/api/classes/XModule.html +57 -0
  35. package/docs/api/classes/XObject.html +133 -0
  36. package/docs/api/classes/XObjectManager.html +36 -0
  37. package/docs/api/classes/XObjectPack.html +6 -0
  38. package/docs/api/classes/XParams.html +8 -0
  39. package/docs/api/classes/XParser.html +21 -0
  40. package/docs/api/classes/XUtils.html +29 -0
  41. package/docs/api/classes/XpellEngine.html +36 -0
  42. package/docs/api/classes/_XData.html +23 -0
  43. package/docs/api/classes/_XEventManager.html +37 -0
  44. package/docs/api/classes/_XLogger.html +17 -0
  45. package/docs/api/hierarchy.html +1 -0
  46. package/docs/api/index.html +3 -0
  47. package/docs/api/interfaces/IXData.html +1 -0
  48. package/docs/api/interfaces/IXObjectData.html +17 -0
  49. package/docs/api/interfaces/XDataXporterHandler.html +1 -0
  50. package/docs/api/interfaces/XEventListener.html +6 -0
  51. package/docs/api/interfaces/XNanoCommand.html +2 -0
  52. package/docs/api/interfaces/XObjectOnEventIndex.html +1 -0
  53. package/docs/api/types/HTMLEventListenersIndex.html +1 -0
  54. package/docs/api/types/XCommandData.html +1 -0
  55. package/docs/api/types/XDataObject.html +1 -0
  56. package/docs/api/types/XDataVariable.html +1 -0
  57. package/docs/api/types/XDataXporter.html +1 -0
  58. package/docs/api/types/XEvent.html +1 -0
  59. package/docs/api/types/XEventListenerOptions.html +1 -0
  60. package/docs/api/types/XModuleData.html +1 -0
  61. package/docs/api/types/XNanoCommandPack.html +2 -0
  62. package/docs/api/types/XObjectData.html +1 -0
  63. package/docs/api/types/XObjectOnEventHandler.html +1 -0
  64. package/docs/api/variables/XData.html +1 -0
  65. package/docs/api/variables/XEventManager.html +1 -0
  66. package/docs/api/variables/XLogger.html +1 -0
  67. package/docs/api/variables/Xpell.html +3 -0
  68. package/docs/architecture/overview.md +190 -0
  69. package/package.json +66 -0
@@ -0,0 +1,287 @@
1
+ /**
2
+ * XObject — Core Runtime Object Model
3
+ *
4
+ * The foundational primitive of the Xpell runtime.
5
+ *
6
+ * `XObject` is the base class for objects managed by Xpell modules and provides:
7
+ * - Identity (`_id`) and typing (`_type`)
8
+ * - Tree composition (`_children` / `_parent`)
9
+ * - Lifecycle hooks (`onCreate`, `onMount`, `onFrame`, `onData`)
10
+ * - Event binding via `XEventManager` (`_on` / `_once`)
11
+ * - Nano-command execution (`run` / `execute`) powered by `XParser` + `XCommand`
12
+ * - Data-source integration (`_data_source`) and XData export (`toXData`)
13
+ *
14
+ * XObject is module-agnostic: UI (XUI), navigation (XVM), data (XDB), and transport
15
+ * layers build on top of it without changing its core contract.
16
+ *
17
+ * One-liner: XObject is the universal runtime node for Xpell.
18
+ *
19
+ * @packageDocumentation
20
+ * @since 2022-07-22
21
+ * @author Tamir Fridman
22
+ * @license MIT
23
+ * @copyright
24
+ * © 2022–present Aime Technologies. All rights reserved.
25
+ */
26
+ import XCommand, { XCommandData } from "./XCommand";
27
+ import { XEventListenerOptions } from "./XEventManager";
28
+ import { XNanoCommandPack, XNanoCommand } from "./XNanoCommands";
29
+ export type wordsList = {
30
+ [k: string]: string;
31
+ };
32
+ export type XValue = string | number | boolean | null | undefined | Function | XValue[] | {
33
+ [k: string]: XValue;
34
+ };
35
+ export interface IXData {
36
+ [k: string]: XValue;
37
+ }
38
+ export interface XDataXporterHandler {
39
+ (inst: any): any;
40
+ }
41
+ export type XDataInstanceXporter = {
42
+ cls: any;
43
+ handler: XDataXporterHandler;
44
+ };
45
+ export type XDataXporter = {
46
+ _ignore_fields: string[];
47
+ _instance_xporters: {
48
+ [id: string]: XDataInstanceXporter;
49
+ };
50
+ };
51
+ export type XObjectOnEventHandler = (xObject: XObject, data?: any) => void;
52
+ export interface XObjectOnEventIndex {
53
+ [eventName: string]: XObjectOnEventHandler;
54
+ }
55
+ export type XObjectData = {
56
+ [k: string]: XValue;
57
+ _id?: string;
58
+ _type?: string;
59
+ _children?: Array<XObject | XObjectData>;
60
+ _name?: string;
61
+ _data_source?: string;
62
+ _on?: XObjectOnEventIndex;
63
+ _once?: XObjectOnEventIndex;
64
+ _on_create?: string | Function;
65
+ _on_mount?: string | Function;
66
+ _on_frame?: string | Function;
67
+ _on_data?: string | Function;
68
+ _process_frame?: boolean;
69
+ _process_data?: boolean;
70
+ _nano_commands?: XNanoCommandPack;
71
+ _debug?: boolean;
72
+ };
73
+ /**
74
+ * XObject class
75
+ * @class XObject
76
+ */
77
+ export declare class XObject {
78
+ [k: string]: string | null | [] | undefined | Function | boolean | number | {} | null;
79
+ _id: string;
80
+ _type: string;
81
+ _children: Array<XObject | XObjectData>;
82
+ _parent: XObject | null;
83
+ _name?: string;
84
+ _data_source?: string;
85
+ _debug?: boolean;
86
+ _on: XObjectOnEventIndex;
87
+ _once: XObjectOnEventIndex;
88
+ _on_create?: string | Function | undefined;
89
+ _on_mount?: string | Function | undefined;
90
+ _on_frame?: string | Function | undefined;
91
+ _on_data?: string | Function | undefined;
92
+ _on_event?: string | Function | undefined;
93
+ _process_frame: boolean;
94
+ _process_data: boolean;
95
+ protected _xem_options: XEventListenerOptions;
96
+ protected _nano_commands: {
97
+ [k: string]: XNanoCommand;
98
+ };
99
+ protected _cache_cmd_txt?: string;
100
+ protected _cache_jcmd?: any;
101
+ protected _event_listeners_ids: {
102
+ [eventName: string]: string[];
103
+ };
104
+ protected _event_parsed: boolean;
105
+ protected _mounted: boolean;
106
+ protected _xporter: XDataXporter;
107
+ private _xd_unsub?;
108
+ private _xd_bound_key?;
109
+ /**
110
+ * XObject constructor is creating the object and adding all the data keys to the XObject instance
111
+ * @param data constructor input data (object)
112
+ * @param defaults - defaults to merge with data
113
+ * @param skipParse - skip data parsing
114
+ * if override this method make sure to call super.init(data,skipParse) and to set skipParse to true
115
+ */
116
+ constructor(data: XObjectData, defaults?: any, skipParse?: boolean);
117
+ log(message?: any, ...optionalParams: any[]): void;
118
+ /**
119
+ * Initialize the XObject
120
+ * @param data - data to parse (XObjectData)
121
+ * @param skipParse - skip data parsing
122
+ * @deprecated - use parse method instead
123
+ */
124
+ init(data?: any, skipParse?: boolean): void;
125
+ parseEvents(options?: XEventListenerOptions): void;
126
+ addEventListener(eventName: string, handler: XObjectOnEventHandler | string, options?: XEventListenerOptions): void;
127
+ removeEventListener(eventName: string): void;
128
+ removeAllEventListeners(): void;
129
+ /**
130
+ * Append a child XObject to this XObject
131
+ * @param xobject
132
+ */
133
+ append(xobject: XObject): void;
134
+ /**
135
+ * Add single nano command to the object
136
+ * @param commandName - the nano command name
137
+ * @param nanoCommandFunction
138
+ */
139
+ addNanoCommand(commandName: string, nanoCommandFunction: XNanoCommand): void;
140
+ addNanoCommandPack(ncPack: XNanoCommandPack): void;
141
+ /**
142
+ * List of fields to ignore when exporting the xobject to XData or string format
143
+ * @param <string[]> ignoreFields - an array with all the fields to ignore
144
+ */
145
+ addXporterDataIgnoreFields(ignoreFields: string[]): void;
146
+ /**
147
+ * Add XData Xporter instance handler
148
+ * @param <XDataInstanceXporter> ie - the instance exporter object
149
+ */
150
+ addXporterInstanceXporter(classOfInstance: any, handler: XDataXporterHandler): void;
151
+ /**
152
+ * Parse data to the XObject
153
+ * @param data data to parse
154
+ * @param ignore - lis of words to ignore in the parse process
155
+ */
156
+ parse(data: XObjectData, ignore?: any): void;
157
+ /**
158
+ * Parse data to the XObject
159
+ * @param data data to parse
160
+ * @param {object} fields- object with fields and default values (IXData format)
161
+ *
162
+ * fields example = {
163
+ * _name : "default-name",
164
+ * ...
165
+ * }
166
+ */
167
+ parseFieldsFromXDataObject(data: XObjectData, fields: {
168
+ [name: string]: any;
169
+ }): void;
170
+ /**
171
+ * Parse list of fields from IXObjectData to the class
172
+ * @param {IXObjectData} data - the data
173
+ * @param {Array<string>} fields - array of field names (string)
174
+ * @param checkNonXParams - also check non Xpell fields (fields that not starting with "_" sign)
175
+ */
176
+ parseFields(data: XObjectData, fields: Array<string>, checkNonXParams?: boolean): void;
177
+ /**
178
+ * this method triggered after the HTML DOM object has been created and added to the parent element
179
+ * support external _on_create anonymous function in the , example:
180
+ * _on_create: async (xObject) => {
181
+ * // xObject -> The XObject parent of the _on_create function, use instead of this keyword
182
+ * // write code that will be executed each frame.
183
+ * // make sure to write async anonymous function.
184
+ * }
185
+ *
186
+ */
187
+ onCreate(): Promise<void>;
188
+ protected checkAndRunInternalFunction(func: any, ...params: any): Promise<void>;
189
+ /**
190
+ * Triggers when the object is being mounted to other element
191
+ * support external _on_create anonymous function in the , example:
192
+ * _on_mount: async (xObject) => {
193
+ * // xObject -> The XObject parent of the _on_mount function, use instead of this keyword
194
+ * // write code that will be executed each frame.
195
+ * // make sure to write async anonymous function.
196
+ * }
197
+ */
198
+ onMount(): Promise<void>;
199
+ emptyDataSource(): void;
200
+ /**
201
+ * Triggers when new data is being received from the data source
202
+ * @param data - the data
203
+ * if override this method make sure to call super.onData(data) to run the _on_data attribute
204
+ */
205
+ onData(data: any): Promise<void>;
206
+ /**
207
+ * Triggers from Xpell frame every frame
208
+ * Support _on_frame atrribute that can be XCommand string or function
209
+ * @param {number} frameNumber
210
+ *
211
+ * XObject supports
212
+ * 1. External _on_frame anonymous function in the , example:
213
+ * _on_frame: async (xObject,frameNumber) => {
214
+ * // xObject -> The XObject parent of the _on_frame function, use instead of this keyword
215
+ * // frameNumber = Xpell current frame number
216
+ * // write code that will be executed each frame.
217
+ * // make sure to write async anonymous function.
218
+ * // be wise with the function execution and try to keep it in the 15ms running time to support 60 FPS
219
+ * }
220
+ *
221
+ * 2. String execution of nano commands
222
+ *
223
+ * _on_frame: "nano command text"
224
+ *
225
+ */
226
+ onFrame(frameNumber: number): Promise<void>;
227
+ /**
228
+ * Runs object nano commands
229
+ * @param nanoCommand - object nano command (string)
230
+ * @param cache - cache last command to prevent multiple parsing on the same command
231
+ */
232
+ run(nanoCommand: string, cache?: boolean): Promise<void>;
233
+ /**
234
+ * Execute XCommand within the XObject Nano Commands
235
+ * @param xCommand XCommand to execute
236
+ *
237
+ * Nano command example:
238
+ *
239
+ * "set-text" : (xCommand,xObject) => {
240
+ * xObject.setText(xCommands.params.text)
241
+ * }
242
+ *
243
+ */
244
+ execute(xCommand: XCommand | XCommandData): Promise<void>;
245
+ /**
246
+ * Return an IXObjectData JSON representation of the XObject
247
+ * @returns IXObjectData
248
+ */
249
+ toXData(): IXData;
250
+ /**
251
+ * Return a string representation of the XObject
252
+ * @returns string
253
+ */
254
+ toString(): string;
255
+ clearAttributes(attributes: Array<string>): void;
256
+ bindDataSource(key?: string, opts?: {
257
+ initial?: boolean;
258
+ }): void;
259
+ unbindDataSource(): void;
260
+ /**
261
+ * Dispose the XObject and all its children
262
+ */
263
+ dispose(): Promise<void>;
264
+ /**
265
+ * Remove a child from the XObject )
266
+ * @param child - the child to
267
+ * @returns void
268
+ */
269
+ removeChild(child: XObject, dispose?: boolean): void;
270
+ /**
271
+ * @param child - the child to add
272
+ * @deprecated use append method instead
273
+ */
274
+ addChild(child: XObject): void;
275
+ }
276
+ /**
277
+ * ObjectPack class for multi object registration
278
+ */
279
+ export declare class XObjectPack {
280
+ [k: string]: any;
281
+ /**
282
+ * Get all registered object in this ObjectPack
283
+ * @returns XObject dictionary
284
+ */
285
+ static getObjects(): object;
286
+ }
287
+ export default XObject;
@@ -0,0 +1,96 @@
1
+ /**
2
+ * XObjectManager — Module Object Registry
3
+ *
4
+ * Central manager for module-owned XObject instances.
5
+ *
6
+ * XObjectManager tracks and manages root XObjects created by Xpell modules.
7
+ * Child XObjects are considered part of their parent hierarchy and are
8
+ * not managed independently by the manager.
9
+ *
10
+ * XModules use XObjectManager to:
11
+ * - Register and resolve XObject classes by `_type`
12
+ * - Create new XObject instances from schemas or commands
13
+ * - Maintain deterministic ownership of module-level objects
14
+ *
15
+ * One-liner: XObjectManager governs the lifetime of module root objects.
16
+ *
17
+ * @packageDocumentation
18
+ * @since 2022-07-22
19
+ * @author Tamir Fridman
20
+ * @license MIT
21
+ * @copyright
22
+ * © 2022–present Aime Technologies. All rights reserved.
23
+ */
24
+ import XObject, { XObjectPack } from "./XObject";
25
+ export type XObjectManagerIndex = {
26
+ [name: string]: any;
27
+ };
28
+ export declare class XObjectManager {
29
+ #private;
30
+ constructor();
31
+ get _objects(): XObjectManagerIndex;
32
+ /**
33
+ * Checks if an object is found in the object manager
34
+ * @param xObjectId
35
+ * @returns
36
+ */
37
+ hasObject(xObjectId: string): boolean;
38
+ /**
39
+ * Register multiple classes dictionary into the object manager
40
+ * @param xObjects - key value list -> \{"view":XView,...\}
41
+ */
42
+ registerObjects(xObjects: XObjectPack): void;
43
+ /**
44
+ * Registers single XObject
45
+ * @param name - name of the object
46
+ * @param xObjects The object class
47
+ */
48
+ registerObject(name: string, xObjects: XObject): void;
49
+ /**
50
+ * Checks if a class (name) is found in the object manager classes dictionary
51
+ * @param name - class name
52
+ * @returns {boolean}
53
+ */
54
+ hasObjectClass(name: string): boolean;
55
+ /**
56
+ * Retrieves XObject class instance
57
+ * @param name class name
58
+ * @returns {XObject}
59
+ */
60
+ getObjectClass(name: string): any;
61
+ /**
62
+ * Retrieves all the classes dictionary
63
+ * @returns XObjectManagerIndex
64
+ */
65
+ getAllClasses(): XObjectManagerIndex;
66
+ get _classes(): XObjectManagerIndex;
67
+ /**
68
+ * Add XObject instance to the manager
69
+ * @param xObject XObject to maintain
70
+ */
71
+ addObject(xObject: XObject): void;
72
+ /**
73
+ * Remove XObject from the manager
74
+ * @param xObjectId object id to remove
75
+ */
76
+ removeObject(xObjectId: string): void;
77
+ /**
78
+ * Retrieves XObject instance
79
+ * @param xObjectId XObject id
80
+ * @returns {XObject}
81
+ */
82
+ getObject(xObjectId: string): XObject;
83
+ /**
84
+ * alias to getObject
85
+ * @param id
86
+ * @returns
87
+ */
88
+ go(id: string): XObject;
89
+ /**
90
+ * Retrieves XObject instance
91
+ * @param objectName XObject name
92
+ * @returns {XObject}
93
+ */
94
+ getObjectByName(objectName: string): XObject | null;
95
+ }
96
+ export default XObjectManager;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * XParams — Command Parameter Accessors
3
+ *
4
+ * Typed parameter helper for Xpell commands.
5
+ *
6
+ * XParams provides a safe, normalized way to read parameters
7
+ * from Xpell command-like objects (`XCmdLike`) using positional
8
+ * or named keys, with optional type coercion and defaults.
9
+ *
10
+ * It is designed to be used by:
11
+ * - Nano commands
12
+ * - XVM internal commands
13
+ * - Runtime command dispatchers
14
+ * - AI- or text-generated command inputs
15
+ *
16
+ * ---
17
+ *
18
+ * ## Responsibilities
19
+ *
20
+ * - Read parameters from `_params` safely
21
+ * - Provide typed accessors (`bool`, `int`, `json`, `str`)
22
+ * - Apply sane defaults and coercion rules
23
+ * - Support both positional and named parameters
24
+ *
25
+ * ---
26
+ *
27
+ * ## Design Notes
28
+ *
29
+ * - Parameter access is defensive and non-throwing
30
+ * - String inputs are normalized when possible
31
+ * - JSON parsing is best-effort and fail-safe
32
+ * - XParams does not mutate command objects
33
+ *
34
+ * ---
35
+ *
36
+ * XParams is a low-level utility and contains no
37
+ * domain-specific logic or side effects.
38
+ * XParams turns loose input into safe intent.
39
+ *
40
+ * @packageDocumentation
41
+ * @since 2022-07-22
42
+ * @author Tamir Fridman
43
+ * @license MIT
44
+ * @copyright
45
+ * © 2022–present Aime Technologies. All rights reserved.
46
+ */
47
+ export type XCmdLike = {
48
+ _params?: Record<string, any>;
49
+ } | {
50
+ getParam?: (pos: number, name: string, def: any) => any;
51
+ _params?: Record<string, any>;
52
+ };
53
+ export declare class XParams {
54
+ static get(cmd: any, key: string | number, def?: any): any;
55
+ static has(cmd: any, key: string | number): any;
56
+ static str(cmd: any, ...keys: (string | number)[]): string | undefined;
57
+ static bool(cmd: any, key: string | number, def?: boolean): boolean;
58
+ static int(cmd: any, key: string | number, def?: number): number;
59
+ static json<T = any>(cmd: any, key: string | number, def?: T): T | undefined;
60
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Xpell Parser
3
+ *
4
+ * Input parsing layer for the Xpell runtime.
5
+ *
6
+ * Responsible for converting external representations
7
+ * (XML, HTML, raw text, and JSON) into normalized
8
+ * Xpell commands and runtime instructions.
9
+ *
10
+ * ---
11
+ *
12
+ * ## Responsibilities
13
+ *
14
+ * - Parse XML, HTML, raw text, and JSON inputs
15
+ * - Normalize input into Xpell command structures
16
+ * - Validate and sanitize external input formats
17
+ * - Provide a unified entry point for declarative and textual inputs
18
+ *
19
+ * ---
20
+ *
21
+ * ## Architectural Role
22
+ *
23
+ * The parser is format-aware but runtime-agnostic.
24
+ * It does not execute commands or mutate state directly.
25
+ *
26
+ * Parsed output is consumed by:
27
+ * - XUI (UI creation)
28
+ * - XVM (navigation and flow)
29
+ * - XDB (data and entities)
30
+ *
31
+ * ---
32
+ *
33
+ * The parser defines the boundary between
34
+ * untrusted input and the Xpell runtime.
35
+ *
36
+ * @packageDocumentation
37
+ * @since 2022-07-22
38
+ * @author Tamir Fridman
39
+ * @license MIT
40
+ * @copyright © 2022–present Aime Technologies. All rights reserved.
41
+ */
42
+ import XCommand from "./XCommand";
43
+ export declare class XParser {
44
+ private static html2XMap;
45
+ /**
46
+ * Adds HTML-Xpell Mapping item
47
+ * @param htmlElement HTML element to change from
48
+ * @param xpellElement Xpell element to change to
49
+ */
50
+ static addHtml2XpellMapItem(htmlElement: string, xpellElement: string): void;
51
+ /**
52
+ * convert text command to Xpell json command
53
+ * @param {string} txt
54
+ */
55
+ static parse(txt: string, module?: string): XCommand;
56
+ static replaceSpacesInQuotes(inputString: string, replaceWith?: string): string;
57
+ static parseObjectCommand(command: string, module?: string): {
58
+ _module: string;
59
+ _object: string | undefined;
60
+ _op: string;
61
+ _params: any;
62
+ };
63
+ /**
64
+ * Converts XML/HTML string to XCommand
65
+ * @param xmlString XML string
66
+ * @returns
67
+ */
68
+ static xmlString2Xpell(xmlString: string): {};
69
+ /**
70
+ * Converts XML/HTML Document to Xpell JSON
71
+ * @param xmlNode XML Document Node
72
+ * @param forceXhtml force Xpell XHTML for every unknown object
73
+ * @returns {} Xpell JSON
74
+ */
75
+ static xml2Xpell(xmlNode: any, forceXhtml?: boolean): {};
76
+ }
77
+ export default XParser;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * XProtocol — Core Response Envelope (Pre-Wormholes v1)
3
+ *
4
+ * Defines the canonical, transport-agnostic response format used by Xpell
5
+ * runtimes and clients **before** Wormholes / streaming / routing layers.
6
+ *
7
+ * This protocol is:
8
+ * - Platform-neutral (no Node, DOM, or transport dependencies)
9
+ * - JSON-safe and serializable across process, thread, and network boundaries
10
+ * - Shared between server and client as a strict wire contract
11
+ *
12
+ * Design rules:
13
+ * - XResponseData is the FINAL response shape for v1
14
+ * - Errors are represented via XError.toXData() inside `_result`
15
+ * - Timing fields (`_ts`, `_pt`) are measured on the responder side
16
+ * - Clients must treat this object as immutable protocol data
17
+ *
18
+ * IMPORTANT:
19
+ * - Do NOT add transport concerns here (request IDs, peers, streams, auth)
20
+ * - Do NOT mutate XResponseData once sent
21
+ * - Wormholes and future protocols MUST wrap this envelope, not modify it
22
+ *
23
+ * @package xpell-core
24
+ * @version 2.0.0-alpha
25
+ * @author Tamir Fridman <DrXoom>
26
+ */
27
+ export type XResponseData = {
28
+ _ok: boolean;
29
+ _ts: number;
30
+ _pt: number;
31
+ _result: any;
32
+ };
33
+ export declare class XResponse {
34
+ _ok: boolean;
35
+ _ts: number;
36
+ _pt: number;
37
+ _result: any;
38
+ constructor(data?: Partial<XResponseData>);
39
+ static create(data?: Partial<XResponseData>): XResponse;
40
+ static ok(result: any): XResponse;
41
+ static error(error: any): XResponse;
42
+ stopProcessTimeCounter(): void;
43
+ /**
44
+ * Convert to wire-safe object.
45
+ * NOTE: serialize == finalize timing
46
+ */
47
+ toXData(): XResponseData;
48
+ toString(): string;
49
+ setXData(data: Partial<XResponseData>): void;
50
+ }
51
+ export declare class XResponseError extends XResponse {
52
+ constructor(error: any);
53
+ }
54
+ export declare class XResponseOK extends XResponse {
55
+ constructor(result: any);
56
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * XUtils — Xpell Utility Package
3
+ *
4
+ * Shared utility functions used across the Xpell runtime.
5
+ *
6
+ * Provides small, focused helpers that support core modules
7
+ * (XUI, XVM, XDB, Wormholes) without introducing cross-module
8
+ * dependencies or architectural coupling.
9
+ *
10
+ * ---
11
+ *
12
+ * ## Design Principles
13
+ *
14
+ * - Stateless and side-effect minimal
15
+ * - No runtime ownership or lifecycle management
16
+ * - Safe to use across client, server, and tooling
17
+ * - Free of UI, navigation, and data-layer assumptions
18
+ *
19
+ * ---
20
+ *
21
+ * XUtils exists to reduce duplication while keeping the core
22
+ * architecture clean and modular.
23
+ *
24
+ * @packageDocumentation
25
+ * @since 2022-07-22
26
+ * @author Tamir Fridman
27
+ * @copyright © 2022–present Aime Technologies. All rights reserved.
28
+ * @license MIT
29
+ */
30
+ export type XFrameScheduler = (cb: () => void) => void;
31
+ export declare const TWO_PI: number;
32
+ export declare class _XUtils {
33
+ /**
34
+ * Create ignore list for parser to ignore spell words
35
+ * @param list - comma-separated list of words
36
+ * @param reservedWords - base reserved words map (mutated)
37
+ */
38
+ createIgnoreList(list: string, reservedWords: Record<string, any>): Record<string, any>;
39
+ /**
40
+ * GUID / UUID v4 (cross-platform)
41
+ *
42
+ * Preference order:
43
+ * 1) globalThis.crypto.randomUUID()
44
+ * 2) globalThis.crypto.getRandomValues() (RFC4122 v4)
45
+ * 3) Math.random() fallback (NOT crypto-secure, legacy fallback only)
46
+ */
47
+ guid(): string;
48
+ /**
49
+ * Merge defaults into data object (mutates data)
50
+ * @param data - target data
51
+ * @param defaults - defaults object
52
+ * @param force - overwrite existing values
53
+ */
54
+ mergeDefaultsWithData(data: any, defaults: any, force?: boolean): any;
55
+ /**
56
+ * Encode string to Base64 (UTF-8 safe, cross-platform)
57
+ */
58
+ encode(str: string): string;
59
+ /**
60
+ * Decode Base64 string to UTF-8 (cross-platform)
61
+ */
62
+ decode(str: string): string;
63
+ /**
64
+ * Returns a random integer between min and max (inclusive)
65
+ * NOTE: Not cryptographically secure (OK for UI, NOT for IDs)
66
+ */
67
+ getRandomInt(min: number, max: number): number;
68
+ /**
69
+ * Extract parameter from XCommand
70
+ */
71
+ getParam(xcmd: any, paramName: string, defaultValue?: any): any;
72
+ /**
73
+ * Default frame scheduler (cross-platform)
74
+ * - Browser: requestAnimationFrame
75
+ * - Node / non-DOM: setImmediate (fast) or setTimeout (paced by target fps)
76
+ */
77
+ createDefaultScheduler(_target_fps?: number): XFrameScheduler;
78
+ }
79
+ declare const XUtils: _XUtils;
80
+ declare const _xu: _XUtils;
81
+ export { XUtils, _xu };
82
+ export default XUtils;
83
+ /**
84
+ * FPS Calculator (cross-platform + stable)
85
+ *
86
+ * - Works in browser + node (performance.now() else Date.now()).
87
+ * - Smooths frame time via EMA (ms/frame).
88
+ * - Deadband prevents 119↔120 flicker.
89
+ *
90
+ * Notes:
91
+ * - If your engine runs at 1 FPS on node, this will naturally converge to ~1.
92
+ * - This is O(1) work per frame (a few ops) and will not affect frame rate.
93
+ */
94
+ export declare class FPSCalc {
95
+ #private;
96
+ constructor(alpha?: number, deadband?: number);
97
+ private now;
98
+ calc(): number;
99
+ reset(): void;
100
+ }