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,313 @@
1
+ # Publishers Guide
2
+
3
+ ## When to Read
4
+
5
+ This document explains the publisher system in JSGUI3 Server. Read this when:
6
+ - You need to understand how different content types are served
7
+ - You're creating custom publishers for new content types
8
+ - You want to extend the server with new HTTP response capabilities
9
+ - You're debugging publishing-related issues
10
+ - You need to understand the relationship between controls, resources, and HTTP responses
11
+
12
+ **Note:** For general server usage, see [README.md](../README.md). For system architecture, see [docs/system-architecture.md](docs/system-architecture.md).
13
+
14
+ ## Overview
15
+
16
+ Publishers are the bridge between JSGUI3's internal data structures and HTTP responses. They handle the conversion of various content types (controls, functions, images, etc.) into appropriate HTTP responses that browsers can consume.
17
+
18
+ ## Publisher Types
19
+
20
+ ### HTTP_Webpage_Publisher
21
+
22
+ **Purpose:** Serves JSGUI3 controls as complete HTML web pages with bundled JavaScript and CSS.
23
+
24
+ **Key Features:**
25
+ - Bundles control JavaScript using ESBuild
26
+ - Extracts and serves CSS from control definitions
27
+ - Creates complete HTML documents with proper structure
28
+ - Handles client-side initialization
29
+
30
+ **Usage:**
31
+ ```javascript
32
+ const webpage = new Webpage({ content: MyControl });
33
+ const publisher = new HTTP_Webpage_Publisher({
34
+ webpage,
35
+ src_path_client_js: './client.js'
36
+ });
37
+ ```
38
+
39
+ **Output:** HTML page at routes like `/`, JavaScript at `/js/js.js`, CSS at `/css/css.css`
40
+
41
+ ### HTTP_Website_Publisher
42
+
43
+ **Purpose:** Manages multi-page websites with routing and shared assets.
44
+
45
+ **Key Features:**
46
+ - Handles multiple pages within a website
47
+ - Shared JavaScript/CSS bundles across pages
48
+ - Automatic routing based on URL paths
49
+ - Website-level configuration and metadata
50
+
51
+ **Usage:**
52
+ ```javascript
53
+ const website = new Website({ name: 'My Site' });
54
+ const publisher = new HTTP_Website_Publisher({ website });
55
+ ```
56
+
57
+ ### HTTP_Function_Publisher
58
+
59
+ **Purpose:** Exposes JavaScript functions as REST API endpoints.
60
+
61
+ **Key Features:**
62
+ - Automatic JSON serialization/deserialization
63
+ - Support for async functions and Promises
64
+ - Content-type negotiation (JSON for objects, text for strings)
65
+ - Error handling and propagation
66
+
67
+ **Usage:**
68
+ ```javascript
69
+ const publisher = new HTTP_Function_Publisher({
70
+ name: 'myApi',
71
+ fn: (params) => ({ result: params.value * 2 })
72
+ });
73
+ // Available at /api/myApi
74
+ ```
75
+
76
+ ### HTTP_CSS_Publisher
77
+
78
+ **Purpose:** Serves CSS stylesheets with proper MIME types and caching headers.
79
+
80
+ **Key Features:**
81
+ - CSS minification and optimization
82
+ - Proper cache headers for performance
83
+ - Support for multiple stylesheets
84
+
85
+ ### HTTP_JS_Publisher
86
+
87
+ **Purpose:** Serves JavaScript files and bundles.
88
+
89
+ **Key Features:**
90
+ - ESBuild integration for bundling
91
+ - Source map support for debugging
92
+ - Minification in production mode
93
+
94
+ ### HTTP_Image_Publisher
95
+
96
+ **Purpose:** Serves image files with appropriate MIME types.
97
+
98
+ **Key Features:**
99
+ - Automatic MIME type detection
100
+ - Support for common image formats (JPEG, PNG, SVG, etc.)
101
+ - Efficient streaming for large files
102
+
103
+ ## Publisher Architecture
104
+
105
+ ### Base Publisher Class
106
+
107
+ All publishers extend a common base class that provides:
108
+ - Event handling capabilities
109
+ - Configuration management
110
+ - Error handling patterns
111
+ - Ready state management
112
+
113
+ ### Event System
114
+
115
+ Publishers use an event-driven architecture:
116
+ - `ready`: Fired when publisher has completed initialization and bundling
117
+ - `error`: Fired when publisher encounters an error
118
+
119
+ ### Configuration Patterns
120
+
121
+ Publishers accept configuration objects with common patterns:
122
+ - `debug`: Enable debug mode with verbose logging
123
+ - `src_path_client_js`: Path to client-side JavaScript
124
+ - `name`: Identifier for the publisher instance
125
+
126
+ ## Creating Custom Publishers
127
+
128
+ ### Basic Publisher Structure
129
+
130
+ ```javascript
131
+ const Publisher = require('./Publisher');
132
+
133
+ class Custom_Publisher extends Publisher {
134
+ constructor(spec = {}) {
135
+ super(spec);
136
+ // Custom initialization
137
+ }
138
+
139
+ handle_http(request, response) {
140
+ // Custom HTTP handling logic
141
+ response.writeHead(200, { 'Content-Type': 'text/plain' });
142
+ response.end('Custom response');
143
+ }
144
+ }
145
+ ```
146
+
147
+ ### Integration with Server
148
+
149
+ ```javascript
150
+ // Register custom publisher with server router
151
+ server.router.set_route('/custom', customPublisher, customPublisher.handle_http);
152
+ ```
153
+
154
+ ## Publisher Lifecycle
155
+
156
+ ### Initialization Phase
157
+ 1. Publisher receives configuration
158
+ 2. Resources are loaded and processed
159
+ 3. Bundling/compilation occurs (if needed)
160
+ 4. Routes are registered with the server router
161
+ 5. `ready` event is emitted
162
+
163
+ ### Request Handling Phase
164
+ 1. HTTP request received by server
165
+ 2. Router matches URL to publisher
166
+ 3. Publisher processes request
167
+ 4. Response is generated and sent
168
+
169
+ ### Cleanup Phase
170
+ 1. Resources are released
171
+ 2. Cache is cleared (if applicable)
172
+ 3. Connections are closed
173
+
174
+ ## Performance Considerations
175
+
176
+ ### Caching Strategies
177
+ - Static assets are cached aggressively
178
+ - Dynamic content uses appropriate cache headers
179
+ - Bundle outputs are cached between requests
180
+
181
+ ### Resource Management
182
+ - Publishers clean up after themselves
183
+ - Large resources are streamed rather than buffered
184
+ - Connection pooling for external resources
185
+
186
+ ### Optimization Features
187
+ - Minification in production mode
188
+ - Compression support (gzip, etc.)
189
+ - Lazy loading for large assets
190
+
191
+ ## Error Handling
192
+
193
+ ### Publisher Errors
194
+ - Configuration validation errors
195
+ - Resource loading failures
196
+ - Bundling/compilation errors
197
+
198
+ ### Request Errors
199
+ - Invalid request parameters
200
+ - Resource not found
201
+ - Processing failures
202
+
203
+ ### Recovery Patterns
204
+ - Graceful degradation when possible
205
+ - Fallback responses for errors
206
+ - Comprehensive error logging
207
+
208
+ ## Testing Publishers
209
+
210
+ ### Unit Testing
211
+ ```javascript
212
+ const publisher = new HTTP_Function_Publisher({
213
+ name: 'test',
214
+ fn: () => 'test result'
215
+ });
216
+
217
+ publisher.handle_http(mockRequest, mockResponse);
218
+ // Assert response content and headers
219
+ ```
220
+
221
+ ### Integration Testing
222
+ - Test with real server instances
223
+ - Verify end-to-end request/response cycles
224
+ - Test error conditions and recovery
225
+
226
+ ## Best Practices
227
+
228
+ ### Publisher Design
229
+ - Keep publishers focused on single responsibilities
230
+ - Use consistent configuration patterns
231
+ - Provide clear error messages
232
+ - Document custom publishers thoroughly
233
+
234
+ ### Performance
235
+ - Minimize synchronous operations
236
+ - Use streaming for large content
237
+ - Implement appropriate caching
238
+ - Monitor resource usage
239
+
240
+ ### Maintainability
241
+ - Follow existing code patterns
242
+ - Add comprehensive tests
243
+ - Document configuration options
244
+ - Provide migration guides for changes
245
+
246
+ ## Common Patterns
247
+
248
+ ### Conditional Publishing
249
+ ```javascript
250
+ if (this.debug) {
251
+ // Debug-specific handling
252
+ } else {
253
+ // Production handling
254
+ }
255
+ ```
256
+
257
+ ### Resource Integration
258
+ ```javascript
259
+ // Access server resources
260
+ const resource = this.server.resource_pool.get_resource('My_Resource');
261
+ ```
262
+
263
+ ### Event-Driven Processing
264
+ ```javascript
265
+ this.on('ready', () => {
266
+ // Publisher is ready for requests
267
+ });
268
+
269
+ this.on('error', (error) => {
270
+ // Handle initialization errors
271
+ });
272
+ ```
273
+
274
+ ## Troubleshooting
275
+
276
+ ### Common Issues
277
+ - Publisher not emitting `ready` event
278
+ - Incorrect MIME types in responses
279
+ - Bundling failures in production
280
+ - Memory leaks in long-running publishers
281
+
282
+ ### Debug Mode
283
+ Enable debug mode for detailed logging:
284
+ ```javascript
285
+ const publisher = new Custom_Publisher({
286
+ debug: true
287
+ });
288
+ ```
289
+
290
+ ### Logging
291
+ Publishers provide comprehensive logging:
292
+ - Initialization progress
293
+ - Request handling details
294
+ - Error conditions and stack traces
295
+ - Performance metrics
296
+
297
+ ## Future Enhancements
298
+
299
+ ### Planned Features
300
+ - WebSocket support for real-time publishers
301
+ - GraphQL integration
302
+ - Advanced caching strategies
303
+ - Publisher composition patterns
304
+
305
+ ### Extension Points
306
+ - Plugin system for custom publishers
307
+ - Middleware support
308
+ - Custom response formatters
309
+ - Advanced routing capabilities
310
+
311
+ ---
312
+
313
+ This guide provides the foundation for understanding and extending the publisher system. For specific publisher implementations, refer to their individual source files in the `publishers/` directory.