zero-query 1.1.1 → 1.2.2

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 (156) 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 +442 -442
  5. package/cli/commands/build.js +253 -247
  6. package/cli/commands/bundle.js +1226 -1224
  7. package/cli/commands/create.js +178 -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 +441 -0
  73. package/cli/scaffold/webrtc/assets/.gitkeep +0 -0
  74. package/cli/scaffold/webrtc/global.css +250 -0
  75. package/cli/scaffold/webrtc/index.html +21 -0
  76. package/cli/scaffold/webrtc/package.json +16 -0
  77. package/cli/scaffold/webrtc/server/index.js +198 -0
  78. package/cli/utils.js +305 -287
  79. package/dist/API.md +661 -0
  80. package/dist/zquery.dist.zip +0 -0
  81. package/dist/zquery.js +10454 -6614
  82. package/dist/zquery.min.js +8 -631
  83. package/index.d.ts +570 -371
  84. package/index.js +311 -240
  85. package/package.json +77 -70
  86. package/src/component.js +1758 -1691
  87. package/src/core.js +929 -921
  88. package/src/diff.js +497 -497
  89. package/src/errors.js +209 -209
  90. package/src/expression.js +929 -922
  91. package/src/http.js +242 -242
  92. package/src/package.json +1 -1
  93. package/src/reactive.js +271 -255
  94. package/src/router.js +878 -843
  95. package/src/ssr.js +421 -418
  96. package/src/store.js +325 -318
  97. package/src/utils.js +534 -515
  98. package/src/webrtc/e2ee.js +351 -0
  99. package/src/webrtc/errors.js +116 -0
  100. package/src/webrtc/ice.js +301 -0
  101. package/src/webrtc/index.js +131 -0
  102. package/src/webrtc/joinToken.js +119 -0
  103. package/src/webrtc/observe.js +172 -0
  104. package/src/webrtc/peer.js +351 -0
  105. package/src/webrtc/reactive.js +268 -0
  106. package/src/webrtc/room.js +625 -0
  107. package/src/webrtc/sdp.js +302 -0
  108. package/src/webrtc/sfu/index.js +43 -0
  109. package/src/webrtc/sfu/livekit.js +131 -0
  110. package/src/webrtc/sfu/mediasoup.js +150 -0
  111. package/src/webrtc/signaling.js +373 -0
  112. package/src/webrtc/turn.js +237 -0
  113. package/tests/_helpers/webrtcFakes.js +289 -0
  114. package/tests/audit.test.js +4158 -4158
  115. package/tests/bench/render.bench.js +77 -0
  116. package/tests/cli.test.js +1136 -1103
  117. package/tests/compare.test.js +497 -486
  118. package/tests/component.test.js +4076 -3938
  119. package/tests/core.test.js +1926 -1910
  120. package/tests/dev-server.test.js +489 -489
  121. package/tests/diff.test.js +1416 -1416
  122. package/tests/docs.test.js +1664 -1650
  123. package/tests/electron-features.test.js +864 -864
  124. package/tests/errors.test.js +619 -619
  125. package/tests/expression.test.js +1087 -1056
  126. package/tests/http.test.js +693 -648
  127. package/tests/reactive.test.js +844 -819
  128. package/tests/router.test.js +2423 -2327
  129. package/tests/ssr.test.js +916 -870
  130. package/tests/store.test.js +840 -830
  131. package/tests/test-minifier.js +153 -153
  132. package/tests/test-ssr.js +27 -27
  133. package/tests/utils.test.js +1411 -1377
  134. package/tests/webrtc/e2ee.test.js +283 -0
  135. package/tests/webrtc/ice.test.js +202 -0
  136. package/tests/webrtc/joinToken.test.js +89 -0
  137. package/tests/webrtc/observe.test.js +111 -0
  138. package/tests/webrtc/peer.test.js +373 -0
  139. package/tests/webrtc/reactive.test.js +235 -0
  140. package/tests/webrtc/room.test.js +406 -0
  141. package/tests/webrtc/sdp.test.js +151 -0
  142. package/tests/webrtc/sfu-livekit.test.js +119 -0
  143. package/tests/webrtc/sfu.test.js +160 -0
  144. package/tests/webrtc/signaling.test.js +251 -0
  145. package/tests/webrtc/turn.test.js +256 -0
  146. package/types/collection.d.ts +383 -383
  147. package/types/component.d.ts +186 -186
  148. package/types/errors.d.ts +135 -135
  149. package/types/http.d.ts +92 -92
  150. package/types/misc.d.ts +201 -201
  151. package/types/reactive.d.ts +98 -98
  152. package/types/router.d.ts +190 -190
  153. package/types/ssr.d.ts +102 -102
  154. package/types/store.d.ts +146 -146
  155. package/types/utils.d.ts +245 -245
  156. package/types/webrtc.d.ts +653 -0
@@ -0,0 +1,289 @@
1
+ /**
2
+ * tests/_helpers/webrtcFakes.js - shared fakes for WebRTC tests
3
+ *
4
+ * No external deps. Designed to be drop-in compatible with the global
5
+ * `WebSocket` API where it matters for the signaling client:
6
+ * - `onopen`, `onmessage`, `onerror`, `onclose`
7
+ * - `send(data)`
8
+ * - `close(code, reason)`
9
+ *
10
+ * Instances expose helpers for tests to drive the fake's state:
11
+ * `fakeOpen()`, `fakeMessage(payload)`, `fakeClose(code, reason)`, etc.
12
+ * All `send()` calls are buffered into `sendCalls` for assertion.
13
+ */
14
+
15
+
16
+
17
+ /** Active fake-socket instances, in construction order. Cleared per-test by callers. */
18
+ export const fakeSockets = [];
19
+
20
+
21
+ /**
22
+ * Reset the shared fake-socket registry between tests.
23
+ */
24
+ export function resetFakeSockets() {
25
+ fakeSockets.length = 0;
26
+ }
27
+
28
+
29
+ /**
30
+ * Minimal stand-in for the global `WebSocket` API. Pass the class itself
31
+ * (not an instance) to `new SignalingClient(url, { WebSocket: FakeWebSocket })`.
32
+ */
33
+ export class FakeWebSocket {
34
+ /**
35
+ * @param {string} url
36
+ */
37
+ constructor(url) {
38
+ this.url = url;
39
+ this.readyState = 0; // CONNECTING
40
+ this.onopen = null;
41
+ this.onmessage = null;
42
+ this.onerror = null;
43
+ this.onclose = null;
44
+ this.sendCalls = [];
45
+ this.closeCalls = [];
46
+ fakeSockets.push(this);
47
+ }
48
+
49
+ /** Capture an outbound frame. */
50
+ send(data) {
51
+ this.sendCalls.push(data);
52
+ }
53
+
54
+ /** Mimic `WebSocket.close()` and immediately fire `onclose`. */
55
+ close(code = 1000, reason = '') {
56
+ this.closeCalls.push({ code, reason });
57
+ this.readyState = 3; // CLOSED
58
+ if (typeof this.onclose === 'function') {
59
+ this.onclose({ code, reason, wasClean: code === 1000 });
60
+ }
61
+ }
62
+
63
+ // ----- Test-side drivers -----------------------------------------------
64
+
65
+ /** Mark the socket open and fire `onopen`. */
66
+ fakeOpen() {
67
+ this.readyState = 1; // OPEN
68
+ if (typeof this.onopen === 'function') this.onopen({});
69
+ }
70
+
71
+ /**
72
+ * Deliver a message. Accepts an object (auto-JSON-stringified) or a string.
73
+ * @param {*} payload
74
+ */
75
+ fakeMessage(payload) {
76
+ const data = typeof payload === 'string' ? payload : JSON.stringify(payload);
77
+ if (typeof this.onmessage === 'function') this.onmessage({ data });
78
+ }
79
+
80
+ /** Fire `onerror`. */
81
+ fakeError(event = {}) {
82
+ if (typeof this.onerror === 'function') this.onerror(event);
83
+ }
84
+
85
+ /** Fire `onclose` without sending a server close - simulates abrupt disconnect. */
86
+ fakeClose(code = 1006, reason = 'abnormal') {
87
+ this.readyState = 3;
88
+ if (typeof this.onclose === 'function') {
89
+ this.onclose({ code, reason, wasClean: code === 1000 });
90
+ }
91
+ }
92
+
93
+ /** Convenience: return parsed JSON frames sent by the client. */
94
+ get sentFrames() {
95
+ return this.sendCalls.map((d) => {
96
+ try { return JSON.parse(d); }
97
+ catch (_) { return d; }
98
+ });
99
+ }
100
+ }
101
+
102
+
103
+ // ---------------------------------------------------------------------------
104
+ // RTCPeerConnection fake (for tests/webrtc/peer.test.js etc.)
105
+ // ---------------------------------------------------------------------------
106
+
107
+ /**
108
+ * Minimum-valid SDP that satisfies the server's strict validator
109
+ * (UDP/TLS/RTP/SAVPF + ice-ufrag + ice-pwd + sha-256 fingerprint).
110
+ * Verbatim copy of `test/webrtc/bot.test.js` MIN_SDP in zero-http-npm.
111
+ */
112
+ export const MIN_SDP = [
113
+ 'v=0', 'o=- 1 2 IN IP4 127.0.0.1', 's=-', 't=0 0',
114
+ 'm=audio 9 UDP/TLS/RTP/SAVPF 111',
115
+ 'a=ice-ufrag:abcd', 'a=ice-pwd:0123456789abcdef0123456789',
116
+ 'a=fingerprint:sha-256 AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99',
117
+ 'a=setup:actpass', 'a=mid:0', 'a=sendrecv', 'a=rtpmap:111 opus/48000/2',
118
+ ].join('\r\n') + '\r\n';
119
+
120
+
121
+ /** Active fake RTCPeerConnections, in construction order. */
122
+ export const fakePeerConnections = [];
123
+
124
+
125
+ /** Reset the shared fake-PC registry between tests. */
126
+ export function resetFakePeerConnections() {
127
+ fakePeerConnections.length = 0;
128
+ }
129
+
130
+
131
+ /**
132
+ * Scriptable stand-in for the browser `RTCPeerConnection`. Records every
133
+ * operation and exposes `_fire*()` helpers so tests can drive the
134
+ * negotiation state machine deterministically.
135
+ *
136
+ * Pass the class itself to `new Peer(id, signaling, { RTCPeerConnection: FakeRTCPeerConnection })`.
137
+ */
138
+ export class FakeRTCPeerConnection {
139
+ /**
140
+ * @param {RTCConfiguration} [config]
141
+ */
142
+ constructor(config = {}) {
143
+ this.config = config;
144
+ this.signalingState = 'stable';
145
+ this.connectionState = 'new';
146
+ this.iceConnectionState = 'new';
147
+ this.localDescription = null;
148
+ this.remoteDescription = null;
149
+
150
+ this.onnegotiationneeded = null;
151
+ this.onicecandidate = null;
152
+ this.ontrack = null;
153
+ this.ondatachannel = null;
154
+ this.onconnectionstatechange = null;
155
+
156
+ // Spies / counters
157
+ this.addTrackCalls = [];
158
+ this.removeTrackCalls = [];
159
+ this.dataChannelCalls = [];
160
+ this.addIceCandidateCalls = [];
161
+ this.restartIceCount = 0;
162
+ this.setLocalCalls = 0;
163
+ this.setRemoteCalls = [];
164
+ this.closeCalls = 0;
165
+
166
+ // Test hooks
167
+ this.failNextSetLocal = null; // Error|null
168
+ this.failNextSetRemote = null;
169
+ this.failNextAddIce = null;
170
+
171
+ fakePeerConnections.push(this);
172
+ }
173
+
174
+ // --- Spec surface ------------------------------------------------------
175
+
176
+ addTrack(track, ...streams) {
177
+ const sender = { track, streams, replaceTrack: () => {}, getStats: async () => new Map() };
178
+ this.addTrackCalls.push(sender);
179
+ return sender;
180
+ }
181
+
182
+ removeTrack(sender) {
183
+ this.removeTrackCalls.push(sender);
184
+ }
185
+
186
+ createDataChannel(label, init) {
187
+ const dc = { label, init: init || {}, readyState: 'connecting', send: () => {}, close: () => {} };
188
+ this.dataChannelCalls.push(dc);
189
+ return dc;
190
+ }
191
+
192
+ async setLocalDescription(desc) {
193
+ this.setLocalCalls++;
194
+ if (this.failNextSetLocal) {
195
+ const err = this.failNextSetLocal; this.failNextSetLocal = null; throw err;
196
+ }
197
+ // Auto-generate a local description when called without args (modern API).
198
+ const next = desc || {
199
+ type: this.signalingState === 'have-remote-offer' ? 'answer' : 'offer',
200
+ sdp: MIN_SDP,
201
+ };
202
+ this.localDescription = next;
203
+ if (next.type === 'offer') this.signalingState = 'have-local-offer';
204
+ else if (next.type === 'answer') this.signalingState = 'stable';
205
+ }
206
+
207
+ async setRemoteDescription(desc) {
208
+ this.setRemoteCalls.push(desc);
209
+ if (this.failNextSetRemote) {
210
+ const err = this.failNextSetRemote; this.failNextSetRemote = null; throw err;
211
+ }
212
+ this.remoteDescription = desc;
213
+ if (desc.type === 'offer') this.signalingState = 'have-remote-offer';
214
+ else if (desc.type === 'answer') this.signalingState = 'stable';
215
+ }
216
+
217
+ async addIceCandidate(cand) {
218
+ this.addIceCandidateCalls.push(cand);
219
+ if (this.failNextAddIce) {
220
+ const err = this.failNextAddIce; this.failNextAddIce = null; throw err;
221
+ }
222
+ }
223
+
224
+ restartIce() {
225
+ this.restartIceCount++;
226
+ }
227
+
228
+ close() {
229
+ this.closeCalls++;
230
+ this.connectionState = 'closed';
231
+ this.signalingState = 'closed';
232
+ }
233
+
234
+ // --- Test-side drivers -------------------------------------------------
235
+
236
+ /** Fire `onnegotiationneeded`. */
237
+ async fakeNegotiationNeeded() {
238
+ if (typeof this.onnegotiationneeded === 'function') {
239
+ await this.onnegotiationneeded({});
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Fire `onicecandidate` with a synthetic `RTCPeerConnectionIceEvent`.
245
+ * Pass `null` to fire the end-of-candidates marker.
246
+ * @param {string|null} candidate - raw `a=candidate:` line
247
+ */
248
+ fakeIceCandidate(candidate) {
249
+ if (typeof this.onicecandidate === 'function') {
250
+ this.onicecandidate({ candidate: candidate ? { candidate } : null });
251
+ }
252
+ }
253
+
254
+ /**
255
+ * Fire `ontrack` with a synthetic `RTCTrackEvent`.
256
+ * @param {object} [overrides]
257
+ */
258
+ fakeTrack(overrides = {}) {
259
+ if (typeof this.ontrack === 'function') {
260
+ this.ontrack(Object.assign({
261
+ track: { kind: 'audio', id: 'track_fake' },
262
+ streams: [{ id: 'stream_fake' }],
263
+ receiver: {},
264
+ transceiver: {},
265
+ }, overrides));
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Fire `ondatachannel`.
271
+ * @param {object} [dc]
272
+ */
273
+ fakeDataChannel(dc) {
274
+ if (typeof this.ondatachannel === 'function') {
275
+ this.ondatachannel({ channel: dc || { label: 'fake', send: () => {}, close: () => {} } });
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Move connectionState and fire `onconnectionstatechange`.
281
+ * @param {string} state
282
+ */
283
+ fakeConnectionStateChange(state) {
284
+ this.connectionState = state;
285
+ if (typeof this.onconnectionstatechange === 'function') {
286
+ this.onconnectionstatechange({});
287
+ }
288
+ }
289
+ }