jsgui3-server 0.0.138 → 0.0.140

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 (57) hide show
  1. package/AGENTS.md +87 -0
  2. package/README.md +12 -0
  3. package/docs/GUIDE_TO_AGENTIC_WORKFLOWS_BY_GROK.md +19 -0
  4. package/docs/advanced-usage-examples.md +1360 -0
  5. package/docs/agent-development-guide.md +386 -0
  6. package/docs/api-reference.md +916 -0
  7. package/docs/broken-functionality-tracker.md +285 -0
  8. package/docs/bundling-system-deep-dive.md +525 -0
  9. package/docs/cli-reference.md +393 -0
  10. package/docs/comprehensive-documentation.md +1403 -0
  11. package/docs/configuration-reference.md +808 -0
  12. package/docs/controls-development.md +859 -0
  13. package/docs/documentation-review/CURRENT_REVIEW.md +95 -0
  14. package/docs/function-publishers-json-apis.md +847 -0
  15. package/docs/getting-started-with-json.md +518 -0
  16. package/docs/minification-compression-sourcemaps-status.md +482 -0
  17. package/docs/minification-compression-sourcemaps-test-results.md +205 -0
  18. package/docs/publishers-guide.md +313 -0
  19. package/docs/resources-guide.md +615 -0
  20. package/docs/serve-helpers.md +406 -0
  21. package/docs/simple-server-api-design.md +13 -0
  22. package/docs/system-architecture.md +275 -0
  23. package/docs/troubleshooting.md +698 -0
  24. package/examples/json/README.md +115 -0
  25. package/examples/json/basic-api/README.md +345 -0
  26. package/examples/json/basic-api/server.js +199 -0
  27. package/examples/json/simple-api/README.md +125 -0
  28. package/examples/json/simple-api/diagnostic-report.json +73 -0
  29. package/examples/json/simple-api/diagnostic-test.js +433 -0
  30. package/examples/json/simple-api/server-debug.md +58 -0
  31. package/examples/json/simple-api/server.js +91 -0
  32. package/examples/json/simple-api/test.js +215 -0
  33. package/http/responders/static/Static_Route_HTTP_Responder.js +1 -2
  34. package/package.json +19 -8
  35. package/publishers/helpers/assigners/static-compressed-response-buffers/Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner.js +65 -12
  36. package/publishers/helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer.js +6 -1
  37. package/publishers/http-function-publisher.js +59 -38
  38. package/publishers/http-webpage-publisher.js +48 -1
  39. package/resources/processors/bundlers/js/esbuild/Advanced_JS_Bundler_Using_ESBuild.js +38 -146
  40. package/resources/processors/bundlers/js/esbuild/Core_JS_Non_Minifying_Bundler_Using_ESBuild.js +54 -5
  41. package/resources/processors/bundlers/js/esbuild/Core_JS_Single_File_Minifying_Bundler_Using_ESBuild.js +36 -4
  42. package/serve-factory.js +36 -9
  43. package/server.js +10 -4
  44. package/test-report.json +0 -0
  45. package/tests/README.md +250 -0
  46. package/tests/assigners.test.js +316 -0
  47. package/tests/bundlers.test.js +329 -0
  48. package/tests/configuration-validation.test.js +530 -0
  49. package/tests/content-analysis.test.js +641 -0
  50. package/tests/end-to-end.test.js +496 -0
  51. package/tests/error-handling.test.js +746 -0
  52. package/tests/performance.test.js +653 -0
  53. package/tests/publishers.test.js +395 -0
  54. package/tests/temp_invalid.js +7 -0
  55. package/tests/temp_invalid_utf8.js +1 -0
  56. package/tests/temp_malformed.js +10 -0
  57. package/tests/test-runner.js +261 -0
@@ -0,0 +1,698 @@
1
+ # Troubleshooting Guide
2
+
3
+ ## When to Read
4
+
5
+ This document provides solutions to common issues encountered when using JSGUI3 Server. Read this when:
6
+ - You're experiencing errors or unexpected behavior
7
+ - Server won't start or controls aren't rendering
8
+ - You need help debugging bundling or API issues
9
+ - You're encountering performance problems
10
+ - You want to understand error messages and their solutions
11
+
12
+ **Note:** For general usage, see [README.md](../README.md). For CLI usage, see [docs/cli-reference.md](docs/cli-reference.md).
13
+
14
+ ## Quick Diagnosis
15
+
16
+ ### Check Server Logs
17
+
18
+ Enable verbose logging to see what's happening:
19
+
20
+ ```bash
21
+ # CLI
22
+ JSGUI_DEBUG=1 node cli.js serve
23
+
24
+ # Programmatic
25
+ Server.serve({
26
+ ctrl: MyControl,
27
+ debug: true
28
+ });
29
+ ```
30
+
31
+ ### Common Log Messages
32
+
33
+ **"waiting for server ready event"**
34
+ - Normal startup message
35
+ - Indicates bundling is in progress
36
+
37
+ **"server ready"**
38
+ - Bundling completed successfully
39
+ - Server is about to start listening
40
+
41
+ **"server started"**
42
+ - HTTP server is listening on specified port
43
+ - Application should be accessible
44
+
45
+ ## Server Startup Issues
46
+
47
+ ### Port Already in Use
48
+
49
+ **Symptoms:**
50
+ ```
51
+ Error: listen EADDRINUSE: address already in use :::8080
52
+ ```
53
+
54
+ **Solutions:**
55
+
56
+ 1. **Find and kill the process:**
57
+ ```bash
58
+ # Linux/macOS
59
+ lsof -i :8080
60
+ kill -9 <PID>
61
+
62
+ # Windows
63
+ netstat -ano | findstr :8080
64
+ taskkill /PID <PID> /F
65
+ ```
66
+
67
+ 2. **Use a different port:**
68
+ ```bash
69
+ node cli.js serve --port 3000
70
+ ```
71
+
72
+ 3. **Use ephemeral port:**
73
+ ```javascript
74
+ Server.serve({ port: 0 }); // Random available port
75
+ ```
76
+
77
+ ### Missing Client File
78
+
79
+ **Symptoms:**
80
+ ```
81
+ Error: No client file found
82
+ Searched in: /app/client.js, /app/src/client.js, /app/app/client.js
83
+ ```
84
+
85
+ **Solutions:**
86
+
87
+ 1. **Create client.js in project root:**
88
+ ```javascript
89
+ const jsgui = require('jsgui3-client');
90
+ const { controls } = jsgui;
91
+ const Active_HTML_Document = require('jsgui3-server/controls/Active_HTML_Document');
92
+
93
+ class MyControl extends Active_HTML_Document {
94
+ // ... control implementation
95
+ }
96
+
97
+ controls.MyControl = MyControl;
98
+ module.exports = jsgui;
99
+ ```
100
+
101
+ 2. **Specify explicit path:**
102
+ ```javascript
103
+ Server.serve({
104
+ ctrl: MyControl,
105
+ src_path_client_js: require.resolve('./path/to/client.js')
106
+ });
107
+ ```
108
+
109
+ 3. **Use different directory structure:**
110
+ - Place client.js in `src/` or `app/` directory
111
+ - Or create symlink: `ln -s src/client.js client.js`
112
+
113
+ ### Control Not Found
114
+
115
+ **Symptoms:**
116
+ ```
117
+ Error: No control found in /path/to/client.js
118
+ ```
119
+
120
+ **Solutions:**
121
+
122
+ 1. **Check exports structure:**
123
+ ```javascript
124
+ // Correct - export jsgui object with controls
125
+ controls.MyControl = MyControl;
126
+ module.exports = jsgui;
127
+
128
+ // Also correct - direct export
129
+ module.exports = MyControl;
130
+
131
+ // Also correct - default export
132
+ module.exports.default = MyControl;
133
+ ```
134
+
135
+ 2. **Verify control class:**
136
+ ```javascript
137
+ class MyControl extends Active_HTML_Document {
138
+ constructor(spec = {}) {
139
+ spec.__type_name = 'my_control'; // Required
140
+ super(spec);
141
+ // ... rest of constructor
142
+ }
143
+ }
144
+ ```
145
+
146
+ ### ESBuild Bundling Errors
147
+
148
+ **Symptoms:**
149
+ ```
150
+ Error: Build failed with 1 error:
151
+ input.js:1:0: ERROR: Expected identifier but found "}"
152
+ ```
153
+
154
+ **Solutions:**
155
+
156
+ 1. **Check syntax errors:**
157
+ ```bash
158
+ node -c client.js # Check syntax
159
+ ```
160
+
161
+ 2. **Verify imports:**
162
+ ```javascript
163
+ // Correct
164
+ const jsgui = require('jsgui3-client');
165
+
166
+ // Incorrect - missing dependency
167
+ // npm install jsgui3-client
168
+ ```
169
+
170
+ 3. **Check file paths:**
171
+ ```javascript
172
+ // Use require.resolve for reliable paths
173
+ src_path_client_js: require.resolve('./client.js')
174
+ ```
175
+
176
+ ## Control Rendering Issues
177
+
178
+ ### Controls Not Appearing
179
+
180
+ **Symptoms:**
181
+ - Page loads but shows blank or default content
182
+ - JavaScript console shows no errors
183
+ - Network tab shows 404 for CSS/JS files
184
+
185
+ **Solutions:**
186
+
187
+ 1. **Check control composition:**
188
+ ```javascript
189
+ const compose = () => {
190
+ // This code must run
191
+ const button = new controls.Button({ context });
192
+ this.body.add(button);
193
+ };
194
+
195
+ if (!spec.el) { compose(); } // Required condition
196
+ ```
197
+
198
+ 2. **Verify CSS definition:**
199
+ ```javascript
200
+ MyControl.css = `
201
+ .my-control {
202
+ padding: 20px;
203
+ background: #f0f0f0;
204
+ }
205
+ `;
206
+ ```
207
+
208
+ 3. **Check activation:**
209
+ ```javascript
210
+ activate() {
211
+ if (!this.__active) {
212
+ super.activate(); // Must call first
213
+ const { context } = this;
214
+ // Event handlers here
215
+ }
216
+ }
217
+ ```
218
+
219
+ ### CSS Not Loading
220
+
221
+ **Symptoms:**
222
+ - Controls render but without styles
223
+ - Network tab shows 404 for `/css/css.css`
224
+
225
+ **Solutions:**
226
+
227
+ 1. **Verify CSS extraction:**
228
+ - CSS must be defined as static property: `MyControl.css = '...';`
229
+ - Not as instance property: `this.css = '...';`
230
+
231
+ 2. **Check bundling completion:**
232
+ - Wait for "server ready" message
233
+ - Ensure no bundling errors in logs
234
+
235
+ 3. **Debug CSS content:**
236
+ ```javascript
237
+ console.log('CSS content:', MyControl.css);
238
+ ```
239
+
240
+ ### JavaScript Errors
241
+
242
+ **Symptoms:**
243
+ - Browser console shows JavaScript errors
244
+ - Controls fail to initialize
245
+
246
+ **Solutions:**
247
+
248
+ 1. **Check browser console:**
249
+ - Open DevTools → Console tab
250
+ - Look for red error messages
251
+
252
+ 2. **Verify control registration:**
253
+ ```javascript
254
+ // Must register control globally
255
+ controls.MyControl = MyControl;
256
+ ```
257
+
258
+ 3. **Check context access:**
259
+ ```javascript
260
+ constructor(spec = {}) {
261
+ super(spec);
262
+ const { context } = this; // Must extract context
263
+ // Use context for creating child controls
264
+ }
265
+ ```
266
+
267
+ ## API Endpoint Issues
268
+
269
+ ### API Routes Not Working
270
+
271
+ **Symptoms:**
272
+ - GET/POST to `/api/endpoint` returns 404
273
+ - API functions not being called
274
+
275
+ **Solutions:**
276
+
277
+ 1. **Check route definition:**
278
+ ```javascript
279
+ Server.serve({
280
+ api: {
281
+ 'endpoint': () => 'response' // Correct
282
+ // 'endpoint/': () => 'response' // Incorrect - no trailing slash
283
+ }
284
+ });
285
+ ```
286
+
287
+ 2. **Verify function signatures:**
288
+ ```javascript
289
+ // Synchronous
290
+ 'sync': () => ({ data: 'value' })
291
+
292
+ // Asynchronous
293
+ 'async': async () => {
294
+ const result = await database.query();
295
+ return result;
296
+ }
297
+
298
+ // With parameters
299
+ 'withParams': ({ id, name }) => {
300
+ return { id, name };
301
+ }
302
+ ```
303
+
304
+ 3. **Check response types:**
305
+ - Objects/arrays → JSON response
306
+ - Strings → text/plain response
307
+ - Promises → automatically awaited
308
+
309
+ ### CORS Issues
310
+
311
+ **Symptoms:**
312
+ ```
313
+ Access to XMLHttpRequest at 'http://localhost:8080/api/data'
314
+ from origin 'http://localhost:3000' has been blocked by CORS policy
315
+ ```
316
+
317
+ **Solutions:**
318
+
319
+ 1. **Add CORS configuration:**
320
+ ```javascript
321
+ Server.serve({
322
+ cors: {
323
+ origin: ['http://localhost:3000'],
324
+ methods: ['GET', 'POST'],
325
+ credentials: true
326
+ }
327
+ });
328
+ ```
329
+
330
+ 2. **Or disable CORS for development:**
331
+ ```javascript
332
+ Server.serve({
333
+ cors: {
334
+ origin: true, // Allow all origins
335
+ credentials: true
336
+ }
337
+ });
338
+ ```
339
+
340
+ ## Data Binding Issues
341
+
342
+ ### Models Not Syncing
343
+
344
+ **Symptoms:**
345
+ - Changes in one control don't update others
346
+ - Data models become desynchronized
347
+
348
+ **Solutions:**
349
+
350
+ 1. **Verify model registration:**
351
+ ```javascript
352
+ this.data = { model: new Data_Object({ context }) };
353
+ field(this.data.model, 'value');
354
+ context.register_control(this.data.model); // Required
355
+ ```
356
+
357
+ 2. **Check control binding:**
358
+ ```javascript
359
+ const input = new controls.Text_Input({
360
+ context,
361
+ data: {
362
+ model: this.data.model, // Correct reference
363
+ field_name: 'value' // Correct field name
364
+ }
365
+ });
366
+ ```
367
+
368
+ 3. **Ensure field names match:**
369
+ ```javascript
370
+ // In model creation
371
+ field(model, 'userName');
372
+
373
+ // In control binding
374
+ data: { model: model, field_name: 'userName' } // Must match exactly
375
+ ```
376
+
377
+ ### Activation Timing Issues
378
+
379
+ **Symptoms:**
380
+ - Controls work sometimes but not always
381
+ - Data binding fails intermittently
382
+
383
+ **Solutions:**
384
+
385
+ 1. **Check activation order:**
386
+ ```javascript
387
+ activate() {
388
+ if (!this.__active) {
389
+ super.activate(); // Must be first
390
+ // Then do control-specific activation
391
+ }
392
+ }
393
+ ```
394
+
395
+ 2. **Verify context availability:**
396
+ ```javascript
397
+ activate() {
398
+ if (!this.__active) {
399
+ super.activate();
400
+ const { context } = this; // Re-extract after super call
401
+ // Use context here
402
+ }
403
+ }
404
+ ```
405
+
406
+ ## Performance Issues
407
+
408
+ ### Slow Startup
409
+
410
+ **Symptoms:**
411
+ - Long delay between "waiting for server ready" and "server ready"
412
+ - Bundling takes excessive time
413
+
414
+ **Solutions:**
415
+
416
+ 1. **Disable debug mode in production:**
417
+ ```javascript
418
+ Server.serve({
419
+ debug: false // Faster bundling, smaller files
420
+ });
421
+ ```
422
+
423
+ 2. **Check for large dependencies:**
424
+ ```bash
425
+ npm ls --depth=0 # See direct dependencies
426
+ ```
427
+
428
+ 3. **Optimize bundling:**
429
+ - Remove unused imports
430
+ - Minimize CSS content
431
+ - Use production builds of dependencies
432
+
433
+ ### Memory Leaks
434
+
435
+ **Symptoms:**
436
+ - Memory usage grows over time
437
+ - Server becomes unresponsive after hours/days
438
+
439
+ **Solutions:**
440
+
441
+ 1. **Clean up event handlers:**
442
+ ```javascript
443
+ deactivate() {
444
+ // Remove event listeners
445
+ // Clear timers/intervals
446
+ // Release resources
447
+ super.deactivate();
448
+ }
449
+ ```
450
+
451
+ 2. **Proper model cleanup:**
452
+ ```javascript
453
+ // Models are automatically cleaned up when context is destroyed
454
+ // But ensure context.register_control() was called
455
+ ```
456
+
457
+ 3. **Monitor memory usage:**
458
+ ```bash
459
+ # Use PM2 or similar process manager
460
+ pm2 monit
461
+ ```
462
+
463
+ ## Development Environment Issues
464
+
465
+ ### Hot Reload Not Working
466
+
467
+ **Symptoms:**
468
+ - Changes to client.js don't appear in browser
469
+ - Need to restart server for every change
470
+
471
+ **Solutions:**
472
+
473
+ 1. **Restart server:**
474
+ ```bash
475
+ # Kill and restart
476
+ pkill -f "node cli.js"
477
+ node cli.js serve
478
+ ```
479
+
480
+ 2. **Check file watching:**
481
+ - JSGUI3 Server doesn't have built-in hot reload yet
482
+ - Use browser refresh (F5) after server restart
483
+ - Consider using nodemon for auto-restart
484
+
485
+ 3. **Clear cache:**
486
+ ```javascript
487
+ // In development, clear require cache
488
+ delete require.cache[require.resolve('./client.js')];
489
+ ```
490
+
491
+ ### Source Maps Not Working
492
+
493
+ **Symptoms:**
494
+ - JavaScript errors show minified code
495
+ - Can't debug original source
496
+
497
+ **Solutions:**
498
+
499
+ 1. **Enable debug mode:**
500
+ ```bash
501
+ JSGUI_DEBUG=1 node cli.js serve
502
+ ```
503
+
504
+ 2. **Check browser dev tools:**
505
+ - Ensure source maps are enabled in DevTools settings
506
+ - Look for `.js.map` files in Network tab
507
+
508
+ ## Production Deployment Issues
509
+
510
+ ### Environment Variables Not Working
511
+
512
+ **Symptoms:**
513
+ - PORT, HOST, JSGUI_DEBUG ignored
514
+
515
+ **Solutions:**
516
+
517
+ 1. **Check variable syntax:**
518
+ ```bash
519
+ # Correct
520
+ PORT=3000 JSGUI_DEBUG=1 node cli.js serve
521
+
522
+ # Incorrect (spaces around =)
523
+ PORT = 3000 node cli.js serve
524
+ ```
525
+
526
+ 2. **Verify precedence:**
527
+ - CLI options override environment variables
528
+ - Environment variables override defaults
529
+
530
+ ### Static Files Not Serving
531
+
532
+ **Symptoms:**
533
+ - 404 errors for images, CSS, or other assets
534
+
535
+ **Solutions:**
536
+
537
+ 1. **Configure static file serving:**
538
+ ```javascript
539
+ Server.serve({
540
+ static: {
541
+ '/images': './public/images',
542
+ '/assets': './public/assets'
543
+ }
544
+ });
545
+ ```
546
+
547
+ 2. **Check file permissions:**
548
+ ```bash
549
+ ls -la ./public/images/
550
+ ```
551
+
552
+ 3. **Verify paths:**
553
+ - Use absolute paths or paths relative to server startup directory
554
+ - Ensure files exist at specified locations
555
+
556
+ ## Advanced Debugging
557
+
558
+ ### Network Analysis
559
+
560
+ Use browser DevTools Network tab to check:
561
+
562
+ 1. **HTTP status codes** - 200 OK, 404 Not Found, 500 Error
563
+ 2. **Response times** - Slow requests indicate performance issues
564
+ 3. **Request headers** - CORS, content-type, etc.
565
+ 4. **Response content** - Verify API responses, HTML structure
566
+
567
+ ### Console Debugging
568
+
569
+ Add temporary logging:
570
+
571
+ ```javascript
572
+ class MyControl extends Active_HTML_Document {
573
+ constructor(spec = {}) {
574
+ super(spec);
575
+ console.log('Control constructor called', spec);
576
+
577
+ const compose = () => {
578
+ console.log('Composing UI');
579
+ // ... composition logic
580
+ };
581
+
582
+ if (!spec.el) {
583
+ console.log('Calling compose');
584
+ compose();
585
+ }
586
+ }
587
+
588
+ activate() {
589
+ console.log('Activating control');
590
+ if (!this.__active) {
591
+ super.activate();
592
+ console.log('Control activated successfully');
593
+ }
594
+ }
595
+ }
596
+ ```
597
+
598
+ ### Stack Trace Analysis
599
+
600
+ When errors occur:
601
+
602
+ 1. **Look at the full stack trace** - shows where error originated
603
+ 2. **Check file paths** - ensure correct files are being loaded
604
+ 3. **Verify function calls** - trace execution flow
605
+ 4. **Check variable values** - log intermediate values
606
+
607
+ ### Process Monitoring
608
+
609
+ ```bash
610
+ # Monitor server process
611
+ ps aux | grep "node cli.js"
612
+
613
+ # Check memory usage
614
+ ps -o pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
615
+
616
+ # Monitor file descriptors
617
+ lsof -p <PID> | wc -l
618
+ ```
619
+
620
+ ## Getting Help
621
+
622
+ ### Community Resources
623
+
624
+ 1. **GitHub Issues:** Check existing issues and create new ones
625
+ 2. **GitHub Discussions:** Ask questions and share solutions
626
+ 3. **Project Wiki:** Additional documentation and examples
627
+
628
+ ### Debug Information to Include
629
+
630
+ When reporting issues, include:
631
+
632
+ 1. **Server version:** `npm list jsgui3-server`
633
+ 2. **Node.js version:** `node --version`
634
+ 3. **Operating system:** `uname -a` or Windows version
635
+ 4. **Full error message and stack trace**
636
+ 5. **Server configuration** (redact sensitive data)
637
+ 6. **Steps to reproduce the issue**
638
+ 7. **Expected vs actual behavior**
639
+
640
+ ### Minimal Reproduction Case
641
+
642
+ Create a minimal example that demonstrates the issue:
643
+
644
+ ```javascript
645
+ // minimal-server.js
646
+ const Server = require('jsgui3-server');
647
+
648
+ Server.serve({
649
+ port: 3000,
650
+ debug: true
651
+ }).catch(console.error);
652
+
653
+ // minimal-client.js
654
+ const jsgui = require('jsgui3-client');
655
+ const { controls } = jsgui;
656
+ const Active_HTML_Document = require('jsgui3-server/controls/Active_HTML_Document');
657
+
658
+ class MinimalControl extends Active_HTML_Document {
659
+ constructor(spec = {}) {
660
+ spec.__type_name = 'minimal_control';
661
+ super(spec);
662
+ const { context } = this;
663
+
664
+ if (typeof this.body.add_class === 'function') {
665
+ this.body.add_class('minimal-control');
666
+ }
667
+
668
+ const compose = () => {
669
+ // Minimal UI
670
+ };
671
+
672
+ if (!spec.el) { compose(); }
673
+ }
674
+
675
+ activate() {
676
+ if (!this.__active) {
677
+ super.activate();
678
+ const { context } = this;
679
+ }
680
+ }
681
+ }
682
+
683
+ MinimalControl.css = `
684
+ .minimal-control {
685
+ padding: 20px;
686
+ background: #f0f0f0;
687
+ }
688
+ `;
689
+
690
+ controls.MinimalControl = MinimalControl;
691
+ module.exports = jsgui;
692
+ ```
693
+
694
+ This minimal setup helps isolate whether the issue is with your specific code or the framework itself.
695
+
696
+ ---
697
+
698
+ Remember: Most issues can be resolved by carefully checking the console output, verifying file paths, and ensuring proper control lifecycle management. Start with the basics and work systematically through the possible causes.