zero-query 1.1.1 → 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 -442
  5. package/cli/commands/build.js +254 -247
  6. package/cli/commands/bundle.js +1228 -1224
  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 -220
  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 +661 -0
  79. package/dist/zquery.dist.zip +0 -0
  80. package/dist/zquery.js +10313 -6614
  81. package/dist/zquery.min.js +8 -631
  82. package/index.d.ts +570 -371
  83. package/index.js +311 -240
  84. package/package.json +76 -70
  85. package/src/component.js +1709 -1691
  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 -255
  93. package/src/router.js +843 -843
  94. package/src/ssr.js +418 -418
  95. package/src/store.js +318 -318
  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 -1103
  115. package/tests/compare.test.js +497 -486
  116. package/tests/component.test.js +3969 -3938
  117. package/tests/core.test.js +1910 -1910
  118. package/tests/dev-server.test.js +489 -489
  119. package/tests/diff.test.js +1416 -1416
  120. package/tests/docs.test.js +1664 -1650
  121. package/tests/electron-features.test.js +864 -864
  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 -146
  153. package/types/utils.d.ts +245 -245
  154. package/types/webrtc.d.ts +653 -0
@@ -1,144 +1,144 @@
1
- // server/data/posts.js - Blog post data
2
- //
3
- // Simulates a database or CMS. In a real app you'd fetch from a DB,
4
- // headless CMS, or markdown files. The server imports this data and
5
- // passes it as props to blog components during SSR.
6
-
7
- export const posts = [
8
- {
9
- slug: 'why-ssr-matters',
10
- title: 'Why Server-Side Rendering Matters',
11
- date: '2025-12-15',
12
- tag: 'SSR',
13
- summary:
14
- 'SSR delivers fully rendered HTML to the browser, improving first contentful paint, SEO indexability, and perceived performance on slower connections.',
15
- body: `
16
- <p>Server-Side Rendering (SSR) generates the full HTML for a page on the server
17
- before sending it to the browser. Instead of shipping an empty shell and waiting
18
- for JavaScript to populate it, the user sees content immediately.</p>
19
-
20
- <h4>Key Benefits</h4>
21
- <ul>
22
- <li><strong>Faster First Paint</strong> — HTML arrives ready to display.
23
- No waiting for JS bundles to download and execute.</li>
24
- <li><strong>SEO Friendly</strong> — Search engine crawlers see complete
25
- content without running JavaScript.</li>
26
- <li><strong>Social Sharing</strong> — Open Graph meta tags are present in
27
- the initial response, so link previews work everywhere.</li>
28
- <li><strong>Accessibility</strong> — Content is available even if JS fails
29
- to load or is disabled.</li>
30
- </ul>
31
-
32
- <h4>The Trade-Off</h4>
33
- <p>SSR adds server-side compute cost per request. Strategies like render
34
- caching, edge deployment, and stale-while-revalidate headers help keep
35
- response times low while maintaining the benefits of dynamic rendering.</p>
36
- `,
37
- },
38
- {
39
- slug: 'hydration-explained',
40
- title: 'Hydration: Picking Up Where the Server Left Off',
41
- date: '2025-12-20',
42
- tag: 'Architecture',
43
- summary:
44
- 'After the server sends HTML, the client "hydrates" the page — attaching event listeners and reactive state so the SPA takes over without a full re-render.',
45
- body: `
46
- <p>Hydration is the process where the client-side framework takes ownership
47
- of server-rendered HTML. The DOM is already there — hydration wires up event
48
- handlers, reactive state, and component lifecycles on top of it.</p>
49
-
50
- <h4>How It Works in zQuery</h4>
51
- <ol>
52
- <li>The server renders a component to HTML with <code>app.renderToString()</code>,
53
- adding a <code>data-zq-ssr</code> marker.</li>
54
- <li>The HTML is injected into the page shell and sent to the browser.</li>
55
- <li>The client loads the same component definitions and registers them
56
- with <code>$.component()</code>.</li>
57
- <li>The router detects the SSR marker and hydrates instead of re-rendering,
58
- preserving the existing DOM while activating reactivity.</li>
59
- </ol>
60
-
61
- <h4>Why This Matters</h4>
62
- <p>Without hydration, the client would discard the server HTML and re-render
63
- from scratch — causing a flash of empty content. Hydration gives you the best
64
- of both worlds: fast server-rendered first paint with full client interactivity.</p>
65
- `,
66
- },
67
- {
68
- slug: 'shared-components',
69
- title: 'Shared Components Across Client and Server',
70
- date: '2026-01-05',
71
- tag: 'Components',
72
- summary:
73
- 'Write your component once and use it everywhere. The same definition object that powers client rendering can be imported by the SSR server to produce identical markup.',
74
- body: `
75
- <p>In zQuery, a component is a plain JavaScript object with <code>state</code>,
76
- <code>render()</code>, and optional lifecycle hooks. This simple contract means
77
- the same file works on both sides:</p>
78
-
79
- <pre><code>// components/greeting.js
80
- export const greeting = {
81
- state: () => ({ name: 'World' }),
82
- render() {
83
- return \`&lt;h1&gt;Hello, \${this.state.name}!&lt;/h1&gt;\`;
84
- }
85
- };</code></pre>
86
-
87
- <h4>Client</h4>
88
- <pre><code>import { greeting } from './components/greeting.js';
89
- $.component('greeting', greeting);</code></pre>
90
-
91
- <h4>Server</h4>
92
- <pre><code>import { greeting } from '../app/components/greeting.js';
93
- app.component('greeting', greeting);
94
- const html = await app.renderToString('greeting', { name: 'Tony' });</code></pre>
95
-
96
- <p>No special file conventions, no build-time transforms. Just JavaScript
97
- modules shared between environments.</p>
98
- `,
99
- },
100
- {
101
- slug: 'ssr-caching-strategies',
102
- title: 'Caching Strategies for SSR Pages',
103
- date: '2026-01-18',
104
- tag: 'Performance',
105
- summary:
106
- 'Combine stale-while-revalidate headers, in-memory render caching, and CDN edge caching to serve SSR pages at static-site speed without sacrificing freshness.',
107
- body: `
108
- <p>SSR is powerful but adds per-request compute. Smart caching lets you keep
109
- the dynamic benefits while serving at near-static speed.</p>
110
-
111
- <h4>Layer 1: In-Memory Cache</h4>
112
- <p>Cache rendered HTML in a <code>Map</code> keyed by route. Set a TTL
113
- (e.g. 60 seconds) and serve cached responses until they expire. Simple and
114
- effective for moderate traffic.</p>
115
-
116
- <h4>Layer 2: HTTP Cache Headers</h4>
117
- <pre><code>Cache-Control: public, s-maxage=60, stale-while-revalidate=300</code></pre>
118
- <p>This tells CDNs to serve cached content for 60s, then revalidate in the
119
- background for up to 5 minutes. Users always get a fast response.</p>
120
-
121
- <h4>Layer 3: CDN Edge Caching</h4>
122
- <p>Deploy behind a CDN (Cloudflare, Vercel Edge, Fastly) so cached pages are
123
- served from the nearest edge node. Combine with geographic routing for
124
- sub-100ms global TTFB.</p>
125
-
126
- <h4>When to Skip Caching</h4>
127
- <p>User-specific pages (dashboards, settings) shouldn't be edge-cached.
128
- Use <code>Cache-Control: private</code> and rely on in-memory caching
129
- or skip caching entirely for authenticated routes.</p>
130
- `,
131
- },
132
- ];
133
-
134
- /** Find a single post by slug. Returns undefined if not found. */
135
- export function getPostBySlug(slug) {
136
- return posts.find(p => p.slug === slug);
137
- }
138
-
139
- /** Return all posts (summary only — no body). */
140
- export function getAllPosts() {
141
- return posts.map(({ slug, title, date, tag, summary }) => ({
142
- slug, title, date, tag, summary,
143
- }));
144
- }
1
+ // server/data/posts.js - Blog post data
2
+ //
3
+ // Simulates a database or CMS. In a real app you'd fetch from a DB,
4
+ // headless CMS, or markdown files. The server imports this data and
5
+ // passes it as props to blog components during SSR.
6
+
7
+ export const posts = [
8
+ {
9
+ slug: 'why-ssr-matters',
10
+ title: 'Why Server-Side Rendering Matters',
11
+ date: '2025-12-15',
12
+ tag: 'SSR',
13
+ summary:
14
+ 'SSR delivers fully rendered HTML to the browser, improving first contentful paint, SEO indexability, and perceived performance on slower connections.',
15
+ body: `
16
+ <p>Server-Side Rendering (SSR) generates the full HTML for a page on the server
17
+ before sending it to the browser. Instead of shipping an empty shell and waiting
18
+ for JavaScript to populate it, the user sees content immediately.</p>
19
+
20
+ <h4>Key Benefits</h4>
21
+ <ul>
22
+ <li><strong>Faster First Paint</strong> — HTML arrives ready to display.
23
+ No waiting for JS bundles to download and execute.</li>
24
+ <li><strong>SEO Friendly</strong> — Search engine crawlers see complete
25
+ content without running JavaScript.</li>
26
+ <li><strong>Social Sharing</strong> — Open Graph meta tags are present in
27
+ the initial response, so link previews work everywhere.</li>
28
+ <li><strong>Accessibility</strong> — Content is available even if JS fails
29
+ to load or is disabled.</li>
30
+ </ul>
31
+
32
+ <h4>The Trade-Off</h4>
33
+ <p>SSR adds server-side compute cost per request. Strategies like render
34
+ caching, edge deployment, and stale-while-revalidate headers help keep
35
+ response times low while maintaining the benefits of dynamic rendering.</p>
36
+ `,
37
+ },
38
+ {
39
+ slug: 'hydration-explained',
40
+ title: 'Hydration: Picking Up Where the Server Left Off',
41
+ date: '2025-12-20',
42
+ tag: 'Architecture',
43
+ summary:
44
+ 'After the server sends HTML, the client "hydrates" the page — attaching event listeners and reactive state so the SPA takes over without a full re-render.',
45
+ body: `
46
+ <p>Hydration is the process where the client-side framework takes ownership
47
+ of server-rendered HTML. The DOM is already there — hydration wires up event
48
+ handlers, reactive state, and component lifecycles on top of it.</p>
49
+
50
+ <h4>How It Works in zQuery</h4>
51
+ <ol>
52
+ <li>The server renders a component to HTML with <code>app.renderToString()</code>,
53
+ adding a <code>data-zq-ssr</code> marker.</li>
54
+ <li>The HTML is injected into the page shell and sent to the browser.</li>
55
+ <li>The client loads the same component definitions and registers them
56
+ with <code>$.component()</code>.</li>
57
+ <li>The router detects the SSR marker and hydrates instead of re-rendering,
58
+ preserving the existing DOM while activating reactivity.</li>
59
+ </ol>
60
+
61
+ <h4>Why This Matters</h4>
62
+ <p>Without hydration, the client would discard the server HTML and re-render
63
+ from scratch — causing a flash of empty content. Hydration gives you the best
64
+ of both worlds: fast server-rendered first paint with full client interactivity.</p>
65
+ `,
66
+ },
67
+ {
68
+ slug: 'shared-components',
69
+ title: 'Shared Components Across Client and Server',
70
+ date: '2026-01-05',
71
+ tag: 'Components',
72
+ summary:
73
+ 'Write your component once and use it everywhere. The same definition object that powers client rendering can be imported by the SSR server to produce identical markup.',
74
+ body: `
75
+ <p>In zQuery, a component is a plain JavaScript object with <code>state</code>,
76
+ <code>render()</code>, and optional lifecycle hooks. This simple contract means
77
+ the same file works on both sides:</p>
78
+
79
+ <pre><code>// components/greeting.js
80
+ export const greeting = {
81
+ state: () => ({ name: 'World' }),
82
+ render() {
83
+ return \`&lt;h1&gt;Hello, \${this.state.name}!&lt;/h1&gt;\`;
84
+ }
85
+ };</code></pre>
86
+
87
+ <h4>Client</h4>
88
+ <pre><code>import { greeting } from './components/greeting.js';
89
+ $.component('greeting', greeting);</code></pre>
90
+
91
+ <h4>Server</h4>
92
+ <pre><code>import { greeting } from '../app/components/greeting.js';
93
+ app.component('greeting', greeting);
94
+ const html = await app.renderToString('greeting', { name: 'Tony' });</code></pre>
95
+
96
+ <p>No special file conventions, no build-time transforms. Just JavaScript
97
+ modules shared between environments.</p>
98
+ `,
99
+ },
100
+ {
101
+ slug: 'ssr-caching-strategies',
102
+ title: 'Caching Strategies for SSR Pages',
103
+ date: '2026-01-18',
104
+ tag: 'Performance',
105
+ summary:
106
+ 'Combine stale-while-revalidate headers, in-memory render caching, and CDN edge caching to serve SSR pages at static-site speed without sacrificing freshness.',
107
+ body: `
108
+ <p>SSR is powerful but adds per-request compute. Smart caching lets you keep
109
+ the dynamic benefits while serving at near-static speed.</p>
110
+
111
+ <h4>Layer 1: In-Memory Cache</h4>
112
+ <p>Cache rendered HTML in a <code>Map</code> keyed by route. Set a TTL
113
+ (e.g. 60 seconds) and serve cached responses until they expire. Simple and
114
+ effective for moderate traffic.</p>
115
+
116
+ <h4>Layer 2: HTTP Cache Headers</h4>
117
+ <pre><code>Cache-Control: public, s-maxage=60, stale-while-revalidate=300</code></pre>
118
+ <p>This tells CDNs to serve cached content for 60s, then revalidate in the
119
+ background for up to 5 minutes. Users always get a fast response.</p>
120
+
121
+ <h4>Layer 3: CDN Edge Caching</h4>
122
+ <p>Deploy behind a CDN (Cloudflare, Vercel Edge, Fastly) so cached pages are
123
+ served from the nearest edge node. Combine with geographic routing for
124
+ sub-100ms global TTFB.</p>
125
+
126
+ <h4>When to Skip Caching</h4>
127
+ <p>User-specific pages (dashboards, settings) shouldn't be edge-cached.
128
+ Use <code>Cache-Control: private</code> and rely on in-memory caching
129
+ or skip caching entirely for authenticated routes.</p>
130
+ `,
131
+ },
132
+ ];
133
+
134
+ /** Find a single post by slug. Returns undefined if not found. */
135
+ export function getPostBySlug(slug) {
136
+ return posts.find(p => p.slug === slug);
137
+ }
138
+
139
+ /** Return all posts (summary only — no body). */
140
+ export function getAllPosts() {
141
+ return posts.map(({ slug, title, date, tag, summary }) => ({
142
+ slug, title, date, tag, summary,
143
+ }));
144
+ }