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,916 @@
1
+ # API Reference
2
+
3
+ ## When to Read
4
+
5
+ This document provides comprehensive API reference for JSGUI3 Server classes, methods, and utilities. Read this when:
6
+ - You need detailed method signatures and parameters
7
+ - You're implementing custom controls or publishers
8
+ - You want to understand internal APIs for extension
9
+ - You're debugging and need to know available methods
10
+ - You need to integrate with server internals
11
+
12
+ **Note:** This is a technical reference. For usage examples, see [README.md](../README.md) and [docs/comprehensive-documentation.md](docs/comprehensive-documentation.md).
13
+
14
+ ## Server API
15
+
16
+ ### Server.serve(options)
17
+
18
+ Main entry point for starting the server.
19
+
20
+ **Signature:**
21
+ ```javascript
22
+ Server.serve(options?: ServerOptions): Promise<Server>
23
+ ```
24
+
25
+ **Parameters:**
26
+ - `options` (ServerOptions, optional): Server configuration object
27
+
28
+ **Returns:** Promise that resolves to the Server instance
29
+
30
+ **Throws:**
31
+ - `ConfigurationError`: Invalid configuration options
32
+ - `DiscoveryError`: Cannot find client files or controls
33
+ - `BindingError`: Cannot bind to specified host/port
34
+
35
+ **Example:**
36
+ ```javascript
37
+ const server = await Server.serve({
38
+ port: 3000,
39
+ ctrl: MyControl
40
+ });
41
+ ```
42
+
43
+ ### Server Constructor
44
+
45
+ Legacy server constructor (still supported).
46
+
47
+ **Signature:**
48
+ ```javascript
49
+ new Server(options?: ServerOptions)
50
+ ```
51
+
52
+ **Parameters:**
53
+ - `options` (ServerOptions, optional): Server configuration object
54
+
55
+ **Returns:** Server instance
56
+
57
+ **Events:**
58
+ - `'ready'`: Emitted when bundling is complete
59
+ - `'started'`: Emitted when HTTP server is listening
60
+ - `'error'`: Emitted on server errors
61
+
62
+ ## Server Instance Methods
63
+
64
+ ### server.start(port, callback)
65
+
66
+ Starts the HTTP server (legacy API).
67
+
68
+ **Signature:**
69
+ ```javascript
70
+ server.start(port?: number, callback?: (err?: Error) => void): void
71
+ ```
72
+
73
+ **Parameters:**
74
+ - `port` (number, optional): Port to listen on (default: 8080)
75
+ - `callback` (function, optional): Called when server starts or fails
76
+
77
+ ### server.publish(route, handler)
78
+
79
+ Adds an API endpoint (legacy API).
80
+
81
+ **Signature:**
82
+ ```javascript
83
+ server.publish(route: string, handler: Function): void
84
+ ```
85
+
86
+ **Parameters:**
87
+ - `route` (string): Route path (automatically prefixed with `/api/`)
88
+ - `handler` (Function): Request handler function
89
+
90
+ ### server.use(middleware)
91
+
92
+ Adds middleware to the server.
93
+
94
+ **Signature:**
95
+ ```javascript
96
+ server.use(middleware: Function): void
97
+ ```
98
+
99
+ **Parameters:**
100
+ - `middleware` (Function): Express-style middleware function
101
+
102
+ ## Control Classes
103
+
104
+ ### Active_HTML_Document
105
+
106
+ Base class for all UI controls that render HTML documents.
107
+
108
+ **Extends:** Blank_HTML_Document (from jsgui3-html)
109
+
110
+ **Constructor:**
111
+ ```javascript
112
+ new Active_HTML_Document(spec?: ControlSpec)
113
+ ```
114
+
115
+ **Properties:**
116
+ - `context` (Context): Runtime context object
117
+ - `body` (HTMLElement): Document body element
118
+ - `head` (HTMLElement): Document head element
119
+ - `__active` (boolean): Activation state flag
120
+
121
+ **Methods:**
122
+
123
+ #### activate()
124
+
125
+ Activates the control and sets up event handlers.
126
+
127
+ **Signature:**
128
+ ```javascript
129
+ activate(): void
130
+ ```
131
+
132
+ **Throws:** None
133
+
134
+ **Notes:** Must call `super.activate()` first in subclasses
135
+
136
+ #### include_js(url)
137
+
138
+ Adds a JavaScript script tag to the document body.
139
+
140
+ **Signature:**
141
+ ```javascript
142
+ include_js(url: string): void
143
+ ```
144
+
145
+ **Parameters:**
146
+ - `url` (string): JavaScript file URL
147
+
148
+ #### include_css(url)
149
+
150
+ Adds a CSS link tag to the document head.
151
+
152
+ **Signature:**
153
+ ```javascript
154
+ include_css(url: string): void
155
+ ```
156
+
157
+ **Parameters:**
158
+ - `url` (string): CSS file URL
159
+
160
+ #### include_jsgui_client(js_file_require_data_main)
161
+
162
+ Adds RequireJS script tag for JSGUI3 client loading.
163
+
164
+ **Signature:**
165
+ ```javascript
166
+ include_jsgui_client(js_file_require_data_main?: string): void
167
+ ```
168
+
169
+ **Parameters:**
170
+ - `js_file_require_data_main` (string, optional): Main JS file path
171
+
172
+ #### include_client_css()
173
+
174
+ Adds basic client CSS link.
175
+
176
+ **Signature:**
177
+ ```javascript
178
+ include_client_css(): void
179
+ ```
180
+
181
+ ### Control (Base)
182
+
183
+ Fundamental UI component base class.
184
+
185
+ **Extends:** Evented_Class (from lang-tools)
186
+
187
+ **Constructor:**
188
+ ```javascript
189
+ new Control(spec?: ControlSpec)
190
+ ```
191
+
192
+ **Properties:**
193
+ - `context` (Context): Runtime context
194
+ - `dom` (DOM_Object): DOM representation
195
+ - `spec` (ControlSpec): Original specification object
196
+
197
+ **Methods:**
198
+
199
+ #### add(child)
200
+
201
+ Adds a child control.
202
+
203
+ **Signature:**
204
+ ```javascript
205
+ add(child: Control): void
206
+ ```
207
+
208
+ #### remove(child)
209
+
210
+ Removes a child control.
211
+
212
+ **Signature:**
213
+ ```javascript
214
+ remove(child: Control): void
215
+ ```
216
+
217
+ #### add_class(className)
218
+
219
+ Adds CSS class to the control.
220
+
221
+ **Signature:**
222
+ ```javascript
223
+ add_class(className: string): void
224
+ ```
225
+
226
+ #### remove_class(className)
227
+
228
+ Removes CSS class from the control.
229
+
230
+ **Signature:**
231
+ ```javascript
232
+ remove_class(className: string): void
233
+ ```
234
+
235
+ #### has_class(className)
236
+
237
+ Checks if control has CSS class.
238
+
239
+ **Signature:**
240
+ ```javascript
241
+ has_class(className: string): boolean
242
+ ```
243
+
244
+ #### get(attr)
245
+
246
+ Gets attribute value.
247
+
248
+ **Signature:**
249
+ ```javascript
250
+ get(attr: string): any
251
+ ```
252
+
253
+ #### set(attr, value)
254
+
255
+ Sets attribute value.
256
+
257
+ **Signature:**
258
+ ```javascript
259
+ set(attr: string | object, value?: any): void
260
+ ```
261
+
262
+ ## Publisher Classes
263
+
264
+ ### HTTP_Webpage_Publisher
265
+
266
+ Serves HTML pages with embedded controls.
267
+
268
+ **Extends:** Publisher
269
+
270
+ **Constructor:**
271
+ ```javascript
272
+ new HTTP_Webpage_Publisher(spec?: PublisherSpec)
273
+ ```
274
+
275
+ **Methods:**
276
+
277
+ #### serve(request, response)
278
+
279
+ Handles HTTP requests for web pages.
280
+
281
+ **Signature:**
282
+ ```javascript
283
+ serve(request: IncomingMessage, response: ServerResponse): Promise<void>
284
+ ```
285
+
286
+ ### HTTP_JS_Publisher
287
+
288
+ Serves JavaScript bundles.
289
+
290
+ **Extends:** Publisher
291
+
292
+ **Constructor:**
293
+ ```javascript
294
+ new HTTP_JS_Publisher(spec?: PublisherSpec)
295
+ ```
296
+
297
+ **Methods:**
298
+
299
+ #### serve(request, response)
300
+
301
+ Serves JavaScript files.
302
+
303
+ **Signature:**
304
+ ```javascript
305
+ serve(request: IncomingMessage, response: ServerResponse): Promise<void>
306
+ ```
307
+
308
+ ### HTTP_CSS_Publisher
309
+
310
+ Serves CSS stylesheets.
311
+
312
+ **Extends:** Publisher
313
+
314
+ **Constructor:**
315
+ ```javascript
316
+ new HTTP_CSS_Publisher(spec?: PublisherSpec)
317
+ ```
318
+
319
+ **Methods:**
320
+
321
+ #### serve(request, response)
322
+
323
+ Serves CSS files.
324
+
325
+ **Signature:**
326
+ ```javascript
327
+ serve(request: IncomingMessage, response: ServerResponse): Promise<void>
328
+ ```
329
+
330
+ ### HTTP_API_Publisher
331
+
332
+ Handles API endpoints.
333
+
334
+ **Extends:** Publisher
335
+
336
+ **Constructor:**
337
+ ```javascript
338
+ new HTTP_API_Publisher(spec?: PublisherSpec)
339
+ ```
340
+
341
+ **Methods:**
342
+
343
+ #### serve(request, response)
344
+
345
+ Handles API requests.
346
+
347
+ **Signature:**
348
+ ```javascript
349
+ serve(request: IncomingMessage, response: ServerResponse): Promise<void>
350
+ ```
351
+
352
+ ## Resource Classes
353
+
354
+ ### File_System_Resource
355
+
356
+ Provides access to local file system.
357
+
358
+ **Extends:** Resource
359
+
360
+ **Constructor:**
361
+ ```javascript
362
+ new File_System_Resource(spec?: ResourceSpec)
363
+ ```
364
+
365
+ **Methods:**
366
+
367
+ #### get(path)
368
+
369
+ Gets file content.
370
+
371
+ **Signature:**
372
+ ```javascript
373
+ get(path: string): Promise<Buffer>
374
+ ```
375
+
376
+ #### put(path, content)
377
+
378
+ Writes file content.
379
+
380
+ **Signature:**
381
+ ```javascript
382
+ put(path: string, content: Buffer | string): Promise<void>
383
+ ```
384
+
385
+ #### delete(path)
386
+
387
+ Deletes a file.
388
+
389
+ **Signature:**
390
+ ```javascript
391
+ delete(path: string): Promise<void>
392
+ ```
393
+
394
+ #### list(dir)
395
+
396
+ Lists directory contents.
397
+
398
+ **Signature:**
399
+ ```javascript
400
+ list(dir: string): Promise<string[]>
401
+ ```
402
+
403
+ ### Database_Resource
404
+
405
+ Provides database connectivity.
406
+
407
+ **Extends:** Resource
408
+
409
+ **Constructor:**
410
+ ```javascript
411
+ new Database_Resource(spec?: DatabaseResourceSpec)
412
+ ```
413
+
414
+ **Properties:**
415
+ - `connectionString` (string): Database connection string
416
+ - `pool` (Pool): Connection pool instance
417
+
418
+ **Methods:**
419
+
420
+ #### query(sql, params)
421
+
422
+ Executes SQL query.
423
+
424
+ **Signature:**
425
+ ```javascript
426
+ query(sql: string, params?: any[]): Promise<QueryResult>
427
+ ```
428
+
429
+ #### connect()
430
+
431
+ Gets database connection.
432
+
433
+ **Signature:**
434
+ ```javascript
435
+ connect(): Promise<Connection>
436
+ ```
437
+
438
+ ## Bundler Classes
439
+
440
+ ### JS_Bundler
441
+
442
+ Base JavaScript bundler class.
443
+
444
+ **Extends:** Evented_Class
445
+
446
+ **Constructor:**
447
+ ```javascript
448
+ new JS_Bundler(spec?: BundlerSpec)
449
+ ```
450
+
451
+ **Methods:**
452
+
453
+ #### bundle(js_file_path)
454
+
455
+ Bundles JavaScript file.
456
+
457
+ **Signature:**
458
+ ```javascript
459
+ bundle(js_file_path: string): Promise<Bundle>
460
+ ```
461
+
462
+ ### Advanced_JS_Bundler_Using_ESBuild
463
+
464
+ ESBuild-based bundler with CSS extraction.
465
+
466
+ **Extends:** Bundler_Using_ESBuild
467
+
468
+ **Constructor:**
469
+ ```javascript
470
+ new Advanced_JS_Bundler_Using_ESBuild(spec?: BundlerSpec)
471
+ ```
472
+
473
+ **Properties:**
474
+ - `debug` (boolean): Debug mode flag
475
+ - `non_minifying_bundler` (Core_JS_Non_Minifying_Bundler_Using_ESBuild)
476
+ - `minifying_js_single_file_bundler` (Core_JS_Single_File_Minifying_Bundler_Using_ESBuild)
477
+ - `css_and_js_from_js_string_extractor` (CSS_And_JS_From_JS_String_Extractor)
478
+
479
+ **Methods:**
480
+
481
+ #### bundle(js_file_path)
482
+
483
+ Bundles JS file with CSS extraction and optional minification.
484
+
485
+ **Signature:**
486
+ ```javascript
487
+ bundle(js_file_path: string): Promise<Bundle>
488
+ ```
489
+
490
+ **Process:**
491
+ 1. Non-minifying bundle of input file
492
+ 2. Extract CSS and JS from bundle
493
+ 3. Re-bundle JS without CSS
494
+ 4. Minify JS (if not in debug mode)
495
+ 5. Return bundle with separate JS and CSS
496
+
497
+ ## Utility Functions
498
+
499
+ ### Serve Helpers
500
+
501
+ Located in `serve-helpers.js`.
502
+
503
+ #### truthy(value)
504
+
505
+ Converts values to boolean with flexible rules.
506
+
507
+ **Signature:**
508
+ ```javascript
509
+ truthy(value: any): boolean
510
+ ```
511
+
512
+ **Rules:**
513
+ - `boolean`: Returns as-is
514
+ - `number`: `true` if not zero
515
+ - `string`: `true` if not empty and not `'false'` or `'0'`
516
+ - `other`: Uses Boolean() conversion
517
+
518
+ #### guess_caller_file()
519
+
520
+ Determines the file that called the current function.
521
+
522
+ **Signature:**
523
+ ```javascript
524
+ guess_caller_file(): string | null
525
+ ```
526
+
527
+ **Returns:** Absolute path to caller file, or null if not found
528
+
529
+ #### resolve_from_base(base_dir, relative_path)
530
+
531
+ Resolves paths relative to base directory.
532
+
533
+ **Signature:**
534
+ ```javascript
535
+ resolve_from_base(base_dir: string, relative_path: string): string
536
+ ```
537
+
538
+ **Returns:** Absolute path
539
+
540
+ #### find_default_client_path(preferred, caller_dir)
541
+
542
+ Discovers client.js files automatically.
543
+
544
+ **Signature:**
545
+ ```javascript
546
+ find_default_client_path(preferred?: string, caller_dir: string): string | null
547
+ ```
548
+
549
+ **Search Order:**
550
+ 1. `preferred` path (if provided)
551
+ 2. `caller_dir/client.js`
552
+ 3. `caller_dir/src/client.js`
553
+ 4. `caller_dir/app/client.js`
554
+ 5. `process.cwd()` variants
555
+
556
+ #### load_default_control_from_client(client_path)
557
+
558
+ Loads control constructor from client file.
559
+
560
+ **Signature:**
561
+ ```javascript
562
+ load_default_control_from_client(client_path: string): Function | null
563
+ ```
564
+
565
+ **Loading Strategy:**
566
+ 1. Direct function export
567
+ 2. `module.exports.default`
568
+ 3. `module.exports.controls[controlName]`
569
+ 4. `module.exports.control`
570
+ 5. `module.exports.Ctrl`
571
+
572
+ #### ensure_route_leading_slash(route)
573
+
574
+ Ensures route starts with `/`.
575
+
576
+ **Signature:**
577
+ ```javascript
578
+ ensure_route_leading_slash(route: string): string
579
+ ```
580
+
581
+ ## Type Definitions
582
+
583
+ ### ServerOptions
584
+
585
+ ```typescript
586
+ interface ServerOptions {
587
+ ctrl?: Function;
588
+ Ctrl?: Function;
589
+ src_path_client_js?: string;
590
+ port?: number;
591
+ host?: string;
592
+ debug?: boolean;
593
+ name?: string;
594
+ root?: string;
595
+ config?: string;
596
+
597
+ page?: PageConfig;
598
+ pages?: Record<string, PageConfig>;
599
+ api?: Record<string, Function>;
600
+ static?: Record<string, string>;
601
+
602
+ // Advanced options
603
+ cors?: CorsConfig;
604
+ https?: HttpsConfig;
605
+ middleware?: Function[];
606
+ publishers?: Record<string, Publisher>;
607
+ resources?: Record<string, Resource>;
608
+ bundler?: BundlerConfig;
609
+ }
610
+ ```
611
+
612
+ ### PageConfig
613
+
614
+ ```typescript
615
+ interface PageConfig {
616
+ content: Function; // Control constructor
617
+ title?: string;
618
+ description?: string;
619
+ path?: string;
620
+ favicon?: string;
621
+ }
622
+ ```
623
+
624
+ ### ControlSpec
625
+
626
+ ```typescript
627
+ interface ControlSpec {
628
+ __type_name?: string;
629
+ context?: Context;
630
+ size?: [number, number]; // [width, height]
631
+ pos?: [number, number]; // [x, y]
632
+ title?: string;
633
+ background?: {
634
+ color?: string;
635
+ image?: string;
636
+ };
637
+ data?: {
638
+ model?: Data_Object;
639
+ field_name?: string;
640
+ };
641
+ [key: string]: any;
642
+ }
643
+ ```
644
+
645
+ ### PublisherSpec
646
+
647
+ ```typescript
648
+ interface PublisherSpec {
649
+ context?: Context;
650
+ resource_pool?: ResourcePool;
651
+ bundler?: Bundler;
652
+ [key: string]: any;
653
+ }
654
+ ```
655
+
656
+ ### ResourceSpec
657
+
658
+ ```typescript
659
+ interface ResourceSpec {
660
+ context?: Context;
661
+ config?: Record<string, any>;
662
+ [key: string]: any;
663
+ }
664
+ ```
665
+
666
+ ### BundlerSpec
667
+
668
+ ```typescript
669
+ interface BundlerSpec {
670
+ debug?: boolean;
671
+ minify?: boolean;
672
+ sourcemap?: boolean;
673
+ target?: string;
674
+ external?: string[];
675
+ [key: string]: any;
676
+ }
677
+ ```
678
+
679
+ ### Bundle
680
+
681
+ Represents a collection of bundled assets.
682
+
683
+ ```typescript
684
+ interface BundleItem {
685
+ type: 'JavaScript' | 'CSS' | 'HTML';
686
+ extension: string;
687
+ text: string;
688
+ map?: string; // Source map
689
+ }
690
+
691
+ interface Bundle extends Array<BundleItem> {
692
+ // Array of bundle items
693
+ }
694
+ ```
695
+
696
+ ## Error Classes
697
+
698
+ ### ConfigurationError
699
+
700
+ Thrown when configuration is invalid.
701
+
702
+ **Properties:**
703
+ - `message` (string): Error description
704
+ - `option` (string): Invalid option name
705
+ - `value` (any): Invalid value provided
706
+
707
+ ### DiscoveryError
708
+
709
+ Thrown when client files or controls cannot be found.
710
+
711
+ **Properties:**
712
+ - `message` (string): Error description
713
+ - `searchedPaths` (string[]): Paths that were searched
714
+ - `callerFile` (string): File that initiated discovery
715
+
716
+ ### BindingError
717
+
718
+ Thrown when server cannot bind to host/port.
719
+
720
+ **Properties:**
721
+ - `message` (string): Error description
722
+ - `host` (string): Host that failed
723
+ - `port` (number): Port that failed
724
+ - `cause` (Error): Underlying system error
725
+
726
+ ## Constants
727
+
728
+ ### HTTP Status Codes
729
+
730
+ ```javascript
731
+ const HTTP_OK = 200;
732
+ const HTTP_NOT_FOUND = 404;
733
+ const HTTP_INTERNAL_ERROR = 500;
734
+ // ... etc
735
+ ```
736
+
737
+ ### MIME Types
738
+
739
+ ```javascript
740
+ const MIME_HTML = 'text/html';
741
+ const MIME_JSON = 'application/json';
742
+ const MIME_CSS = 'text/css';
743
+ const MIME_JS = 'application/javascript';
744
+ // ... etc
745
+ ```
746
+
747
+ ### Default Values
748
+
749
+ ```javascript
750
+ const DEFAULT_PORT = 8080;
751
+ const DEFAULT_HOST = null; // All interfaces
752
+ const DEFAULT_DEBUG = false;
753
+ const DEFAULT_CLIENT_FILES = ['client.js', 'src/client.js', 'app/client.js'];
754
+ ```
755
+
756
+ ## Events
757
+
758
+ ### Server Events
759
+
760
+ - `'ready'`: Bundling completed, server ready to start
761
+ - `'started'`: HTTP server listening on port
762
+ - `'error'`: Server error occurred
763
+ - `'request'`: HTTP request received
764
+ - `'response'`: HTTP response sent
765
+
766
+ ### Control Events
767
+
768
+ - `'activate'`: Control activated
769
+ - `'deactivate'`: Control deactivated
770
+ - `'render'`: Control rendered to DOM
771
+ - `'destroy'`: Control destroyed
772
+
773
+ ### Context Events
774
+
775
+ - `'window-resize'`: Browser window resized
776
+ - `'data-change'`: Data model changed
777
+ - `'control-added'`: Control added to context
778
+ - `'control-removed'`: Control removed from context
779
+
780
+ ## Extension Points
781
+
782
+ ### Custom Publishers
783
+
784
+ ```javascript
785
+ class CustomPublisher extends Publisher {
786
+ constructor(spec) {
787
+ super(spec);
788
+ }
789
+
790
+ async serve(request, response) {
791
+ // Custom serving logic
792
+ const data = await this.getData(request.url);
793
+ response.writeHead(200, { 'Content-Type': 'application/json' });
794
+ response.end(JSON.stringify(data));
795
+ }
796
+ }
797
+ ```
798
+
799
+ ### Custom Resources
800
+
801
+ ```javascript
802
+ class CustomResource extends Resource {
803
+ constructor(spec) {
804
+ super(spec);
805
+ this.apiKey = spec.apiKey;
806
+ }
807
+
808
+ async get(path) {
809
+ const response = await fetch(`${this.baseUrl}${path}`, {
810
+ headers: { 'Authorization': `Bearer ${this.apiKey}` }
811
+ });
812
+ return response.buffer();
813
+ }
814
+ }
815
+ ```
816
+
817
+ ### Custom Bundlers
818
+
819
+ ```javascript
820
+ class CustomBundler extends JS_Bundler {
821
+ constructor(spec) {
822
+ super(spec);
823
+ }
824
+
825
+ async bundle(js_file_path) {
826
+ // Custom bundling logic
827
+ const code = fs.readFileSync(js_file_path, 'utf8');
828
+ const transformed = await this.transform(code);
829
+ return new Bundle([{
830
+ type: 'JavaScript',
831
+ extension: 'js',
832
+ text: transformed
833
+ }]);
834
+ }
835
+ }
836
+ ```
837
+
838
+ ## Performance Characteristics
839
+
840
+ ### Server Startup Time
841
+
842
+ - **Cold start**: 2-5 seconds (bundling + initialization)
843
+ - **Warm start**: < 1 second (cached bundles)
844
+ - **Debug mode**: 1.5x slower (source maps, no minification)
845
+
846
+ ### Memory Usage
847
+
848
+ - **Base server**: ~50MB
849
+ - **Per control**: ~2-5MB
850
+ - **Bundling**: Additional 100-500MB during build
851
+
852
+ ### Request Latency
853
+
854
+ - **Static files**: < 10ms
855
+ - **API endpoints**: 10-100ms
856
+ - **Control rendering**: 50-200ms (first request)
857
+ - **Cached responses**: < 5ms
858
+
859
+ ## Thread Safety
860
+
861
+ ### Server Instance
862
+
863
+ Server instances are not thread-safe. Create one instance per process.
864
+
865
+ ### Control Instances
866
+
867
+ Controls are not thread-safe. Each request should get its own control instances.
868
+
869
+ ### Resources
870
+
871
+ Resource instances should be thread-safe or use appropriate locking.
872
+
873
+ ## Deprecation Notices
874
+
875
+ ### Legacy APIs
876
+
877
+ - `new Server()` constructor: Use `Server.serve()` instead
878
+ - `server.start()`: Handled automatically by `Server.serve()`
879
+ - `server.publish()`: Use `api` configuration option instead
880
+
881
+ ### Deprecated Options
882
+
883
+ - `Ctrl`: Use `ctrl` instead (lowercase)
884
+ - `src_path_client_js`: Auto-discovered, specify only if needed
885
+
886
+ ## Version Compatibility
887
+
888
+ ### Breaking Changes
889
+
890
+ - **v0.0.138**: `Server.serve()` API introduced
891
+ - **v0.0.137**: Enhanced publisher system
892
+ - **v0.0.136**: API endpoint improvements
893
+
894
+ ### Migration Guide
895
+
896
+ ```javascript
897
+ // Before (v0.0.135 and earlier)
898
+ const server = new Server({
899
+ Ctrl: MyControl,
900
+ src_path_client_js: require.resolve('./client.js')
901
+ });
902
+
903
+ server.on('ready', () => {
904
+ server.start(8080);
905
+ });
906
+
907
+ // After (v0.0.138+)
908
+ const server = await Server.serve({
909
+ ctrl: MyControl,
910
+ port: 8080
911
+ });
912
+ ```
913
+
914
+ ---
915
+
916
+ This API reference provides comprehensive technical documentation for JSGUI3 Server internals. For practical usage examples and tutorials, refer to the user-facing documentation.