zero-query 1.0.9 → 1.2.0

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 (154) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -0
  3. package/cli/args.js +33 -33
  4. package/cli/commands/build-api.js +443 -0
  5. package/cli/commands/build.js +254 -216
  6. package/cli/commands/bundle.js +1228 -1183
  7. package/cli/commands/create.js +137 -121
  8. package/cli/commands/dev/devtools/index.js +56 -56
  9. package/cli/commands/dev/devtools/js/components.js +49 -49
  10. package/cli/commands/dev/devtools/js/core.js +423 -423
  11. package/cli/commands/dev/devtools/js/elements.js +421 -421
  12. package/cli/commands/dev/devtools/js/network.js +166 -166
  13. package/cli/commands/dev/devtools/js/performance.js +73 -73
  14. package/cli/commands/dev/devtools/js/router.js +105 -105
  15. package/cli/commands/dev/devtools/js/source.js +132 -132
  16. package/cli/commands/dev/devtools/js/stats.js +35 -35
  17. package/cli/commands/dev/devtools/js/tabs.js +79 -79
  18. package/cli/commands/dev/devtools/panel.html +95 -95
  19. package/cli/commands/dev/devtools/styles.css +244 -244
  20. package/cli/commands/dev/index.js +107 -107
  21. package/cli/commands/dev/logger.js +75 -75
  22. package/cli/commands/dev/overlay.js +858 -858
  23. package/cli/commands/dev/server.js +220 -167
  24. package/cli/commands/dev/validator.js +94 -94
  25. package/cli/commands/dev/watcher.js +172 -172
  26. package/cli/help.js +114 -112
  27. package/cli/index.js +52 -52
  28. package/cli/scaffold/default/LICENSE +21 -21
  29. package/cli/scaffold/default/app/app.js +207 -207
  30. package/cli/scaffold/default/app/components/about.js +201 -201
  31. package/cli/scaffold/default/app/components/api-demo.js +143 -143
  32. package/cli/scaffold/default/app/components/contact-card.js +231 -231
  33. package/cli/scaffold/default/app/components/contacts/contacts.css +706 -706
  34. package/cli/scaffold/default/app/components/contacts/contacts.html +200 -200
  35. package/cli/scaffold/default/app/components/contacts/contacts.js +196 -196
  36. package/cli/scaffold/default/app/components/counter.js +127 -127
  37. package/cli/scaffold/default/app/components/home.js +249 -249
  38. package/cli/scaffold/default/app/components/not-found.js +16 -16
  39. package/cli/scaffold/default/app/components/playground/playground.css +115 -115
  40. package/cli/scaffold/default/app/components/playground/playground.html +161 -161
  41. package/cli/scaffold/default/app/components/playground/playground.js +116 -116
  42. package/cli/scaffold/default/app/components/todos.js +225 -225
  43. package/cli/scaffold/default/app/components/toolkit/toolkit.css +97 -97
  44. package/cli/scaffold/default/app/components/toolkit/toolkit.html +146 -146
  45. package/cli/scaffold/default/app/components/toolkit/toolkit.js +280 -280
  46. package/cli/scaffold/default/app/routes.js +15 -15
  47. package/cli/scaffold/default/app/store.js +101 -101
  48. package/cli/scaffold/default/global.css +552 -552
  49. package/cli/scaffold/default/index.html +99 -99
  50. package/cli/scaffold/minimal/app/app.js +85 -85
  51. package/cli/scaffold/minimal/app/components/about.js +68 -68
  52. package/cli/scaffold/minimal/app/components/counter.js +122 -122
  53. package/cli/scaffold/minimal/app/components/home.js +68 -68
  54. package/cli/scaffold/minimal/app/components/not-found.js +16 -16
  55. package/cli/scaffold/minimal/app/routes.js +9 -9
  56. package/cli/scaffold/minimal/app/store.js +36 -36
  57. package/cli/scaffold/minimal/global.css +300 -300
  58. package/cli/scaffold/minimal/index.html +44 -44
  59. package/cli/scaffold/ssr/app/app.js +41 -41
  60. package/cli/scaffold/ssr/app/components/about.js +55 -55
  61. package/cli/scaffold/ssr/app/components/blog/index.js +65 -65
  62. package/cli/scaffold/ssr/app/components/blog/post.js +86 -86
  63. package/cli/scaffold/ssr/app/components/home.js +37 -37
  64. package/cli/scaffold/ssr/app/components/not-found.js +15 -15
  65. package/cli/scaffold/ssr/app/routes.js +8 -8
  66. package/cli/scaffold/ssr/global.css +228 -228
  67. package/cli/scaffold/ssr/index.html +37 -37
  68. package/cli/scaffold/ssr/package.json +8 -8
  69. package/cli/scaffold/ssr/server/data/posts.js +144 -144
  70. package/cli/scaffold/ssr/server/index.js +213 -213
  71. package/cli/scaffold/webrtc/app/app.js +11 -0
  72. package/cli/scaffold/webrtc/app/components/video-room.js +295 -0
  73. package/cli/scaffold/webrtc/app/lib/room.js +252 -0
  74. package/cli/scaffold/webrtc/assets/.gitkeep +0 -0
  75. package/cli/scaffold/webrtc/global.css +250 -0
  76. package/cli/scaffold/webrtc/index.html +21 -0
  77. package/cli/utils.js +305 -287
  78. package/dist/API.md +7264 -0
  79. package/dist/zquery.dist.zip +0 -0
  80. package/dist/zquery.js +10313 -6252
  81. package/dist/zquery.min.js +8 -601
  82. package/index.d.ts +570 -365
  83. package/index.js +311 -232
  84. package/package.json +76 -69
  85. package/src/component.js +1709 -1454
  86. package/src/core.js +921 -921
  87. package/src/diff.js +497 -497
  88. package/src/errors.js +209 -209
  89. package/src/expression.js +922 -922
  90. package/src/http.js +242 -242
  91. package/src/package.json +1 -1
  92. package/src/reactive.js +255 -254
  93. package/src/router.js +843 -773
  94. package/src/ssr.js +418 -418
  95. package/src/store.js +318 -272
  96. package/src/utils.js +515 -515
  97. package/src/webrtc/e2ee.js +351 -0
  98. package/src/webrtc/errors.js +116 -0
  99. package/src/webrtc/ice.js +301 -0
  100. package/src/webrtc/index.js +131 -0
  101. package/src/webrtc/joinToken.js +119 -0
  102. package/src/webrtc/observe.js +172 -0
  103. package/src/webrtc/peer.js +351 -0
  104. package/src/webrtc/reactive.js +268 -0
  105. package/src/webrtc/room.js +625 -0
  106. package/src/webrtc/sdp.js +302 -0
  107. package/src/webrtc/sfu/index.js +43 -0
  108. package/src/webrtc/sfu/livekit.js +131 -0
  109. package/src/webrtc/sfu/mediasoup.js +150 -0
  110. package/src/webrtc/signaling.js +373 -0
  111. package/src/webrtc/turn.js +237 -0
  112. package/tests/_helpers/webrtcFakes.js +289 -0
  113. package/tests/audit.test.js +4158 -4158
  114. package/tests/cli.test.js +1136 -1023
  115. package/tests/compare.test.js +497 -0
  116. package/tests/component.test.js +3969 -3938
  117. package/tests/core.test.js +1910 -1910
  118. package/tests/dev-server.test.js +489 -0
  119. package/tests/diff.test.js +1416 -1416
  120. package/tests/docs.test.js +1664 -0
  121. package/tests/electron-features.test.js +864 -0
  122. package/tests/errors.test.js +619 -619
  123. package/tests/expression.test.js +1056 -1056
  124. package/tests/http.test.js +648 -648
  125. package/tests/reactive.test.js +819 -819
  126. package/tests/router.test.js +2327 -2327
  127. package/tests/ssr.test.js +870 -870
  128. package/tests/store.test.js +830 -830
  129. package/tests/test-minifier.js +153 -153
  130. package/tests/test-ssr.js +27 -27
  131. package/tests/utils.test.js +1377 -1377
  132. package/tests/webrtc/e2ee.test.js +283 -0
  133. package/tests/webrtc/ice.test.js +202 -0
  134. package/tests/webrtc/joinToken.test.js +89 -0
  135. package/tests/webrtc/observe.test.js +111 -0
  136. package/tests/webrtc/peer.test.js +373 -0
  137. package/tests/webrtc/reactive.test.js +235 -0
  138. package/tests/webrtc/room.test.js +406 -0
  139. package/tests/webrtc/sdp.test.js +151 -0
  140. package/tests/webrtc/sfu-livekit.test.js +119 -0
  141. package/tests/webrtc/sfu.test.js +160 -0
  142. package/tests/webrtc/signaling.test.js +251 -0
  143. package/tests/webrtc/turn.test.js +256 -0
  144. package/types/collection.d.ts +383 -383
  145. package/types/component.d.ts +186 -186
  146. package/types/errors.d.ts +135 -135
  147. package/types/http.d.ts +92 -92
  148. package/types/misc.d.ts +201 -201
  149. package/types/reactive.d.ts +98 -98
  150. package/types/router.d.ts +190 -190
  151. package/types/ssr.d.ts +102 -102
  152. package/types/store.d.ts +146 -145
  153. package/types/utils.d.ts +245 -245
  154. package/types/webrtc.d.ts +653 -0
@@ -1,186 +1,186 @@
1
- /**
2
- * Component system - define, mount, and manage reactive components.
3
- *
4
- * @module component
5
- */
6
-
7
- import type { ReactiveProxy } from './reactive';
8
- import type { NavigationContext } from './router';
9
-
10
- /** The object passed to `$.component()` to define a component. */
11
- export interface ComponentDefinition {
12
- /**
13
- * Initial reactive state.
14
- * A function form is recommended so each instance gets its own copy.
15
- */
16
- state?: Record<string, any> | (() => Record<string, any>);
17
-
18
- /**
19
- * Returns an HTML string. Called on every state change.
20
- * `this` is the component instance.
21
- */
22
- render?(this: ComponentInstance): string;
23
-
24
- /** CSS string - scoped to the component root on first render. */
25
- styles?: string;
26
-
27
- /**
28
- * URL (or array / object map of URLs) to external HTML template file(s).
29
- * If `render()` is also defined, `render()` takes priority.
30
- */
31
- templateUrl?: string | string[] | Record<string, string>;
32
-
33
- /**
34
- * URL (or array of URLs) to external CSS file(s).
35
- * Fetched and auto-scoped on first mount; merged with `styles` if both present.
36
- */
37
- styleUrl?: string | string[];
38
-
39
- /**
40
- * Override the base path for resolving relative `templateUrl` and `styleUrl`
41
- * paths. Normally auto-detected from the calling file.
42
- */
43
- base?: string;
44
-
45
- /** Called before first render (during construction). */
46
- init?(this: ComponentInstance): void;
47
-
48
- /** Called once after first render and DOM insertion. */
49
- mounted?(this: ComponentInstance): void;
50
-
51
- /** Called after every subsequent re-render. */
52
- updated?(this: ComponentInstance): void;
53
-
54
- /** Called when the component is destroyed. Clean up subscriptions here. */
55
- destroyed?(this: ComponentInstance): void;
56
-
57
- /**
58
- * Computed properties - lazy getters derived from state.
59
- * Each function receives the raw state as its argument.
60
- * Access via `this.computed.name` in methods and templates.
61
- */
62
- computed?: Record<string, (state: Record<string, any>) => any>;
63
-
64
- /**
65
- * Watch state keys for changes.
66
- * Keys support dot-path notation (e.g. `'user.name'`).
67
- * Handler receives `(newValue, oldValue)`.
68
- */
69
- watch?: Record<
70
- string,
71
- | ((this: ComponentInstance, newVal: any, oldVal: any) => void)
72
- | { handler: (this: ComponentInstance, newVal: any, oldVal: any) => void }
73
- >;
74
-
75
- /** Additional keys become instance methods (bound to the instance). */
76
- [method: string]: any;
77
- }
78
-
79
- /** The runtime instance of a mounted component. */
80
- export interface ComponentInstance {
81
- /** Reactive state proxy. Mutating triggers re-render. */
82
- state: Record<string, any> & ReactiveProxy;
83
-
84
- /**
85
- * Frozen props passed from parent / router.
86
- * When mounted by the router, includes `$route`, `$query`, and `$params`.
87
- */
88
- readonly props: Readonly<
89
- Record<string, any> & {
90
- $route?: NavigationContext;
91
- $query?: Record<string, string>;
92
- $params?: Record<string, string>;
93
- }
94
- >;
95
-
96
- /** Map of `z-ref` name → DOM element. Populated after each render. */
97
- refs: Record<string, Element>;
98
-
99
- /** Keyed template map (when using multi-`templateUrl`). */
100
- templates: Record<string, string>;
101
-
102
- /**
103
- * Computed properties - lazy getters derived from state.
104
- * Defined via `computed` in the component definition.
105
- */
106
- readonly computed: Record<string, any>;
107
-
108
- /** Merge partial state (triggers re-render). */
109
- setState(partial: Record<string, any>): void;
110
-
111
- /** Dispatch a bubbling `CustomEvent` from the component root. */
112
- emit(name: string, detail?: any): void;
113
-
114
- /** Teardown: removes listeners, scoped styles, clears DOM. */
115
- destroy(): void;
116
-
117
- /**
118
- * Manually queue a re-render (microtask-batched).
119
- * Safe to call from anywhere - state mutations during render are coalesced.
120
- */
121
- _scheduleUpdate(): void;
122
-
123
- /** Any user-defined methods from the component definition. */
124
- [method: string]: any;
125
- }
126
-
127
- /**
128
- * Register a new component.
129
- * @param name Must contain a hyphen (Web Component convention).
130
- * @param definition Component definition object.
131
- */
132
- export function component(name: string, definition: ComponentDefinition): void;
133
-
134
- /**
135
- * Mount a registered component into a target element.
136
- * @returns The component instance.
137
- */
138
- export function mount(
139
- target: string | Element,
140
- componentName: string,
141
- props?: Record<string, any>,
142
- ): ComponentInstance;
143
-
144
- /**
145
- * Scan `root` for elements whose tag matches a registered component and mount them.
146
- * @param root Defaults to `document.body`.
147
- */
148
- export function mountAll(root?: Element): void;
149
-
150
- /** Get the component instance mounted on `target`. */
151
- export function getInstance(target: string | Element): ComponentInstance | null;
152
-
153
- /** Destroy the component at the given target. */
154
- export function destroy(target: string | Element): void;
155
-
156
- /** Returns an object of all registered component definitions (for debugging). */
157
- export function getRegistry(): Record<string, ComponentDefinition>;
158
-
159
- /**
160
- * Pre-load external templates and styles for a registered component.
161
- * Useful for warming the cache before navigation to avoid blank flashes.
162
- * @param name Registered component name.
163
- */
164
- export function prefetch(name: string): Promise<void>;
165
-
166
- /** Handle returned by `$.style()`. */
167
- export interface StyleHandle {
168
- /** Remove all injected `<link>` elements. */
169
- remove(): void;
170
- /** Resolves when all stylesheets have loaded. */
171
- ready: Promise<void>;
172
- }
173
-
174
- /** Options for `$.style()`. */
175
- export interface StyleOptions {
176
- /** Hide page until loaded to prevent FOUC (default `true`). */
177
- critical?: boolean;
178
- /** Background color while hidden during critical load (default `'#0d1117'`). */
179
- bg?: string;
180
- }
181
-
182
- /**
183
- * Dynamically load global (unscoped) stylesheet file(s) into `<head>`.
184
- * Relative paths resolve relative to the calling file.
185
- */
186
- export function style(urls: string | string[], opts?: StyleOptions): StyleHandle;
1
+ /**
2
+ * Component system - define, mount, and manage reactive components.
3
+ *
4
+ * @module component
5
+ */
6
+
7
+ import type { ReactiveProxy } from './reactive';
8
+ import type { NavigationContext } from './router';
9
+
10
+ /** The object passed to `$.component()` to define a component. */
11
+ export interface ComponentDefinition {
12
+ /**
13
+ * Initial reactive state.
14
+ * A function form is recommended so each instance gets its own copy.
15
+ */
16
+ state?: Record<string, any> | (() => Record<string, any>);
17
+
18
+ /**
19
+ * Returns an HTML string. Called on every state change.
20
+ * `this` is the component instance.
21
+ */
22
+ render?(this: ComponentInstance): string;
23
+
24
+ /** CSS string - scoped to the component root on first render. */
25
+ styles?: string;
26
+
27
+ /**
28
+ * URL (or array / object map of URLs) to external HTML template file(s).
29
+ * If `render()` is also defined, `render()` takes priority.
30
+ */
31
+ templateUrl?: string | string[] | Record<string, string>;
32
+
33
+ /**
34
+ * URL (or array of URLs) to external CSS file(s).
35
+ * Fetched and auto-scoped on first mount; merged with `styles` if both present.
36
+ */
37
+ styleUrl?: string | string[];
38
+
39
+ /**
40
+ * Override the base path for resolving relative `templateUrl` and `styleUrl`
41
+ * paths. Normally auto-detected from the calling file.
42
+ */
43
+ base?: string;
44
+
45
+ /** Called before first render (during construction). */
46
+ init?(this: ComponentInstance): void;
47
+
48
+ /** Called once after first render and DOM insertion. */
49
+ mounted?(this: ComponentInstance): void;
50
+
51
+ /** Called after every subsequent re-render. */
52
+ updated?(this: ComponentInstance): void;
53
+
54
+ /** Called when the component is destroyed. Clean up subscriptions here. */
55
+ destroyed?(this: ComponentInstance): void;
56
+
57
+ /**
58
+ * Computed properties - lazy getters derived from state.
59
+ * Each function receives the raw state as its argument.
60
+ * Access via `this.computed.name` in methods and templates.
61
+ */
62
+ computed?: Record<string, (state: Record<string, any>) => any>;
63
+
64
+ /**
65
+ * Watch state keys for changes.
66
+ * Keys support dot-path notation (e.g. `'user.name'`).
67
+ * Handler receives `(newValue, oldValue)`.
68
+ */
69
+ watch?: Record<
70
+ string,
71
+ | ((this: ComponentInstance, newVal: any, oldVal: any) => void)
72
+ | { handler: (this: ComponentInstance, newVal: any, oldVal: any) => void }
73
+ >;
74
+
75
+ /** Additional keys become instance methods (bound to the instance). */
76
+ [method: string]: any;
77
+ }
78
+
79
+ /** The runtime instance of a mounted component. */
80
+ export interface ComponentInstance {
81
+ /** Reactive state proxy. Mutating triggers re-render. */
82
+ state: Record<string, any> & ReactiveProxy;
83
+
84
+ /**
85
+ * Frozen props passed from parent / router.
86
+ * When mounted by the router, includes `$route`, `$query`, and `$params`.
87
+ */
88
+ readonly props: Readonly<
89
+ Record<string, any> & {
90
+ $route?: NavigationContext;
91
+ $query?: Record<string, string>;
92
+ $params?: Record<string, string>;
93
+ }
94
+ >;
95
+
96
+ /** Map of `z-ref` name → DOM element. Populated after each render. */
97
+ refs: Record<string, Element>;
98
+
99
+ /** Keyed template map (when using multi-`templateUrl`). */
100
+ templates: Record<string, string>;
101
+
102
+ /**
103
+ * Computed properties - lazy getters derived from state.
104
+ * Defined via `computed` in the component definition.
105
+ */
106
+ readonly computed: Record<string, any>;
107
+
108
+ /** Merge partial state (triggers re-render). */
109
+ setState(partial: Record<string, any>): void;
110
+
111
+ /** Dispatch a bubbling `CustomEvent` from the component root. */
112
+ emit(name: string, detail?: any): void;
113
+
114
+ /** Teardown: removes listeners, scoped styles, clears DOM. */
115
+ destroy(): void;
116
+
117
+ /**
118
+ * Manually queue a re-render (microtask-batched).
119
+ * Safe to call from anywhere - state mutations during render are coalesced.
120
+ */
121
+ _scheduleUpdate(): void;
122
+
123
+ /** Any user-defined methods from the component definition. */
124
+ [method: string]: any;
125
+ }
126
+
127
+ /**
128
+ * Register a new component.
129
+ * @param name Must contain a hyphen (Web Component convention).
130
+ * @param definition Component definition object.
131
+ */
132
+ export function component(name: string, definition: ComponentDefinition): void;
133
+
134
+ /**
135
+ * Mount a registered component into a target element.
136
+ * @returns The component instance.
137
+ */
138
+ export function mount(
139
+ target: string | Element,
140
+ componentName: string,
141
+ props?: Record<string, any>,
142
+ ): ComponentInstance;
143
+
144
+ /**
145
+ * Scan `root` for elements whose tag matches a registered component and mount them.
146
+ * @param root Defaults to `document.body`.
147
+ */
148
+ export function mountAll(root?: Element): void;
149
+
150
+ /** Get the component instance mounted on `target`. */
151
+ export function getInstance(target: string | Element): ComponentInstance | null;
152
+
153
+ /** Destroy the component at the given target. */
154
+ export function destroy(target: string | Element): void;
155
+
156
+ /** Returns an object of all registered component definitions (for debugging). */
157
+ export function getRegistry(): Record<string, ComponentDefinition>;
158
+
159
+ /**
160
+ * Pre-load external templates and styles for a registered component.
161
+ * Useful for warming the cache before navigation to avoid blank flashes.
162
+ * @param name Registered component name.
163
+ */
164
+ export function prefetch(name: string): Promise<void>;
165
+
166
+ /** Handle returned by `$.style()`. */
167
+ export interface StyleHandle {
168
+ /** Remove all injected `<link>` elements. */
169
+ remove(): void;
170
+ /** Resolves when all stylesheets have loaded. */
171
+ ready: Promise<void>;
172
+ }
173
+
174
+ /** Options for `$.style()`. */
175
+ export interface StyleOptions {
176
+ /** Hide page until loaded to prevent FOUC (default `true`). */
177
+ critical?: boolean;
178
+ /** Background color while hidden during critical load (default `'#0d1117'`). */
179
+ bg?: string;
180
+ }
181
+
182
+ /**
183
+ * Dynamically load global (unscoped) stylesheet file(s) into `<head>`.
184
+ * Relative paths resolve relative to the calling file.
185
+ */
186
+ export function style(urls: string | string[], opts?: StyleOptions): StyleHandle;
package/types/errors.d.ts CHANGED
@@ -1,135 +1,135 @@
1
- /**
2
- * Structured error handling - error codes, error class, and global handler.
3
- *
4
- * @module errors
5
- */
6
-
7
- /** All structured error codes used by zQuery. */
8
- export declare const ErrorCode: {
9
- // Reactive
10
- readonly REACTIVE_CALLBACK: 'ZQ_REACTIVE_CALLBACK';
11
- readonly SIGNAL_CALLBACK: 'ZQ_SIGNAL_CALLBACK';
12
- readonly EFFECT_EXEC: 'ZQ_EFFECT_EXEC';
13
-
14
- // Expression parser
15
- readonly EXPR_PARSE: 'ZQ_EXPR_PARSE';
16
- readonly EXPR_EVAL: 'ZQ_EXPR_EVAL';
17
- readonly EXPR_UNSAFE_ACCESS: 'ZQ_EXPR_UNSAFE_ACCESS';
18
-
19
- // Component
20
- readonly COMP_INVALID_NAME: 'ZQ_COMP_INVALID_NAME';
21
- readonly COMP_NOT_FOUND: 'ZQ_COMP_NOT_FOUND';
22
- readonly COMP_MOUNT_TARGET: 'ZQ_COMP_MOUNT_TARGET';
23
- readonly COMP_RENDER: 'ZQ_COMP_RENDER';
24
- readonly COMP_LIFECYCLE: 'ZQ_COMP_LIFECYCLE';
25
- readonly COMP_RESOURCE: 'ZQ_COMP_RESOURCE';
26
- readonly COMP_DIRECTIVE: 'ZQ_COMP_DIRECTIVE';
27
-
28
- // Router
29
- readonly ROUTER_LOAD: 'ZQ_ROUTER_LOAD';
30
- readonly ROUTER_GUARD: 'ZQ_ROUTER_GUARD';
31
- readonly ROUTER_RESOLVE: 'ZQ_ROUTER_RESOLVE';
32
-
33
- // Store
34
- readonly STORE_ACTION: 'ZQ_STORE_ACTION';
35
- readonly STORE_MIDDLEWARE: 'ZQ_STORE_MIDDLEWARE';
36
- readonly STORE_SUBSCRIBE: 'ZQ_STORE_SUBSCRIBE';
37
-
38
- // HTTP
39
- readonly HTTP_REQUEST: 'ZQ_HTTP_REQUEST';
40
- readonly HTTP_TIMEOUT: 'ZQ_HTTP_TIMEOUT';
41
- readonly HTTP_INTERCEPTOR: 'ZQ_HTTP_INTERCEPTOR';
42
- readonly HTTP_PARSE: 'ZQ_HTTP_PARSE';
43
-
44
- // SSR
45
- readonly SSR_RENDER: 'ZQ_SSR_RENDER';
46
- readonly SSR_COMPONENT: 'ZQ_SSR_COMPONENT';
47
- readonly SSR_HYDRATION: 'ZQ_SSR_HYDRATION';
48
- readonly SSR_PAGE: 'ZQ_SSR_PAGE';
49
-
50
- // General
51
- readonly INVALID_ARGUMENT: 'ZQ_INVALID_ARGUMENT';
52
- };
53
-
54
- /** Union of all error code string values. */
55
- export type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
56
-
57
- /** Structured error class used throughout zQuery. */
58
- export class ZQueryError extends Error {
59
- readonly name: 'ZQueryError';
60
- /** Machine-readable error code (e.g. `'ZQ_COMP_RENDER'`). */
61
- readonly code: ErrorCodeValue;
62
- /** Extra contextual data (component name, expression string, etc.). */
63
- readonly context: Record<string, any>;
64
- /** Original error that caused this one, if any. */
65
- readonly cause?: Error;
66
-
67
- constructor(
68
- code: ErrorCodeValue,
69
- message: string,
70
- context?: Record<string, any>,
71
- cause?: Error,
72
- );
73
- }
74
-
75
- /** Error handler callback type. */
76
- export type ZQueryErrorHandler = (error: ZQueryError) => void;
77
-
78
- /**
79
- * Register a global error handler. Called whenever zQuery catches an
80
- * error internally. Multiple handlers are supported. Pass `null` to clear all.
81
- * @returns Unsubscribe function to remove this handler.
82
- */
83
- export function onError(handler: ZQueryErrorHandler | null): () => void;
84
-
85
- /**
86
- * Report an error through the global handler and console.
87
- * Non-throwing - used for recoverable errors in callbacks, lifecycle hooks, etc.
88
- */
89
- export function reportError(
90
- code: ErrorCodeValue,
91
- message: string,
92
- context?: Record<string, any>,
93
- cause?: Error,
94
- ): void;
95
-
96
- /**
97
- * Wrap a callback so that thrown errors are caught, reported via `reportError`,
98
- * and don't crash the current execution context.
99
- */
100
- export function guardCallback<T extends (...args: any[]) => any>(
101
- fn: T,
102
- code: ErrorCodeValue,
103
- context?: Record<string, any>,
104
- ): (...args: Parameters<T>) => ReturnType<T> | undefined;
105
-
106
- /**
107
- * Validate a required value is defined and of the expected type.
108
- * Throws `ZQueryError` with `INVALID_ARGUMENT` on failure.
109
- */
110
- export function validate(value: any, name: string, expectedType?: string): void;
111
-
112
- /** Formatted error structure for overlays and logging. */
113
- export interface FormattedError {
114
- code: string;
115
- type: string;
116
- message: string;
117
- context: Record<string, any>;
118
- stack: string;
119
- cause: FormattedError | null;
120
- }
121
-
122
- /**
123
- * Format a ZQueryError into a structured object suitable for overlays/logging.
124
- */
125
- export function formatError(err: ZQueryError | Error): FormattedError;
126
-
127
- /**
128
- * Async version of guardCallback - wraps an async function so that
129
- * rejections are caught, reported, and don't crash execution.
130
- */
131
- export function guardAsync<T extends (...args: any[]) => Promise<any>>(
132
- fn: T,
133
- code: ErrorCodeValue,
134
- context?: Record<string, any>,
135
- ): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>> | undefined>;
1
+ /**
2
+ * Structured error handling - error codes, error class, and global handler.
3
+ *
4
+ * @module errors
5
+ */
6
+
7
+ /** All structured error codes used by zQuery. */
8
+ export declare const ErrorCode: {
9
+ // Reactive
10
+ readonly REACTIVE_CALLBACK: 'ZQ_REACTIVE_CALLBACK';
11
+ readonly SIGNAL_CALLBACK: 'ZQ_SIGNAL_CALLBACK';
12
+ readonly EFFECT_EXEC: 'ZQ_EFFECT_EXEC';
13
+
14
+ // Expression parser
15
+ readonly EXPR_PARSE: 'ZQ_EXPR_PARSE';
16
+ readonly EXPR_EVAL: 'ZQ_EXPR_EVAL';
17
+ readonly EXPR_UNSAFE_ACCESS: 'ZQ_EXPR_UNSAFE_ACCESS';
18
+
19
+ // Component
20
+ readonly COMP_INVALID_NAME: 'ZQ_COMP_INVALID_NAME';
21
+ readonly COMP_NOT_FOUND: 'ZQ_COMP_NOT_FOUND';
22
+ readonly COMP_MOUNT_TARGET: 'ZQ_COMP_MOUNT_TARGET';
23
+ readonly COMP_RENDER: 'ZQ_COMP_RENDER';
24
+ readonly COMP_LIFECYCLE: 'ZQ_COMP_LIFECYCLE';
25
+ readonly COMP_RESOURCE: 'ZQ_COMP_RESOURCE';
26
+ readonly COMP_DIRECTIVE: 'ZQ_COMP_DIRECTIVE';
27
+
28
+ // Router
29
+ readonly ROUTER_LOAD: 'ZQ_ROUTER_LOAD';
30
+ readonly ROUTER_GUARD: 'ZQ_ROUTER_GUARD';
31
+ readonly ROUTER_RESOLVE: 'ZQ_ROUTER_RESOLVE';
32
+
33
+ // Store
34
+ readonly STORE_ACTION: 'ZQ_STORE_ACTION';
35
+ readonly STORE_MIDDLEWARE: 'ZQ_STORE_MIDDLEWARE';
36
+ readonly STORE_SUBSCRIBE: 'ZQ_STORE_SUBSCRIBE';
37
+
38
+ // HTTP
39
+ readonly HTTP_REQUEST: 'ZQ_HTTP_REQUEST';
40
+ readonly HTTP_TIMEOUT: 'ZQ_HTTP_TIMEOUT';
41
+ readonly HTTP_INTERCEPTOR: 'ZQ_HTTP_INTERCEPTOR';
42
+ readonly HTTP_PARSE: 'ZQ_HTTP_PARSE';
43
+
44
+ // SSR
45
+ readonly SSR_RENDER: 'ZQ_SSR_RENDER';
46
+ readonly SSR_COMPONENT: 'ZQ_SSR_COMPONENT';
47
+ readonly SSR_HYDRATION: 'ZQ_SSR_HYDRATION';
48
+ readonly SSR_PAGE: 'ZQ_SSR_PAGE';
49
+
50
+ // General
51
+ readonly INVALID_ARGUMENT: 'ZQ_INVALID_ARGUMENT';
52
+ };
53
+
54
+ /** Union of all error code string values. */
55
+ export type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
56
+
57
+ /** Structured error class used throughout zQuery. */
58
+ export class ZQueryError extends Error {
59
+ readonly name: 'ZQueryError';
60
+ /** Machine-readable error code (e.g. `'ZQ_COMP_RENDER'`). */
61
+ readonly code: ErrorCodeValue;
62
+ /** Extra contextual data (component name, expression string, etc.). */
63
+ readonly context: Record<string, any>;
64
+ /** Original error that caused this one, if any. */
65
+ readonly cause?: Error;
66
+
67
+ constructor(
68
+ code: ErrorCodeValue,
69
+ message: string,
70
+ context?: Record<string, any>,
71
+ cause?: Error,
72
+ );
73
+ }
74
+
75
+ /** Error handler callback type. */
76
+ export type ZQueryErrorHandler = (error: ZQueryError) => void;
77
+
78
+ /**
79
+ * Register a global error handler. Called whenever zQuery catches an
80
+ * error internally. Multiple handlers are supported. Pass `null` to clear all.
81
+ * @returns Unsubscribe function to remove this handler.
82
+ */
83
+ export function onError(handler: ZQueryErrorHandler | null): () => void;
84
+
85
+ /**
86
+ * Report an error through the global handler and console.
87
+ * Non-throwing - used for recoverable errors in callbacks, lifecycle hooks, etc.
88
+ */
89
+ export function reportError(
90
+ code: ErrorCodeValue,
91
+ message: string,
92
+ context?: Record<string, any>,
93
+ cause?: Error,
94
+ ): void;
95
+
96
+ /**
97
+ * Wrap a callback so that thrown errors are caught, reported via `reportError`,
98
+ * and don't crash the current execution context.
99
+ */
100
+ export function guardCallback<T extends (...args: any[]) => any>(
101
+ fn: T,
102
+ code: ErrorCodeValue,
103
+ context?: Record<string, any>,
104
+ ): (...args: Parameters<T>) => ReturnType<T> | undefined;
105
+
106
+ /**
107
+ * Validate a required value is defined and of the expected type.
108
+ * Throws `ZQueryError` with `INVALID_ARGUMENT` on failure.
109
+ */
110
+ export function validate(value: any, name: string, expectedType?: string): void;
111
+
112
+ /** Formatted error structure for overlays and logging. */
113
+ export interface FormattedError {
114
+ code: string;
115
+ type: string;
116
+ message: string;
117
+ context: Record<string, any>;
118
+ stack: string;
119
+ cause: FormattedError | null;
120
+ }
121
+
122
+ /**
123
+ * Format a ZQueryError into a structured object suitable for overlays/logging.
124
+ */
125
+ export function formatError(err: ZQueryError | Error): FormattedError;
126
+
127
+ /**
128
+ * Async version of guardCallback - wraps an async function so that
129
+ * rejections are caught, reported, and don't crash execution.
130
+ */
131
+ export function guardAsync<T extends (...args: any[]) => Promise<any>>(
132
+ fn: T,
133
+ code: ErrorCodeValue,
134
+ context?: Record<string, any>,
135
+ ): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>> | undefined>;