jsgui3-server 0.0.121 → 0.0.123

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 (282) hide show
  1. package/.vscode/settings.json +6 -0
  2. package/README.md +10 -10
  3. package/controls/Active_HTML_Document.js +116 -116
  4. package/controls/README.md +7 -7
  5. package/controls/page/admin.js +74 -74
  6. package/controls/panel/admin.js +11 -11
  7. package/examples/_css/basic.css +913 -913
  8. package/examples/_css/database-control.css +51 -51
  9. package/examples/_css/jsgui.css +66 -66
  10. package/examples/_css/multi-layout.css +23 -23
  11. package/examples/_css/style.css +1669 -1669
  12. package/examples/_css/top-and-bottom-bars.css +54 -54
  13. package/examples/box/1) square box/client.js +188 -188
  14. package/examples/box/1) square box/server.js +112 -112
  15. package/examples/box/2) twenty square boxes/css flex wrap/client.js +112 -248
  16. package/examples/box/2) twenty square boxes/css flex wrap/server.js +39 -112
  17. package/examples/box/3) twenty selectable square boxes/css flex wrap/client.js +129 -0
  18. package/examples/{controls/15) window, text field → box/3) twenty selectable square boxes/css flex wrap}/server.js +38 -38
  19. package/examples/boxes/square_boxes.js +45 -48
  20. package/examples/boxes/square_boxes_client.js +132 -136
  21. package/examples/client-side-popup-menu-button.html +93 -93
  22. package/examples/color_palette.js +51 -51
  23. package/examples/color_palette_client.js +95 -95
  24. package/examples/controls/1) window/client.js +186 -186
  25. package/examples/controls/1) window/server.js +117 -117
  26. package/examples/controls/10) window, mirrored text inputs/client.js +118 -320
  27. package/examples/controls/10) window, mirrored text inputs/server.js +37 -117
  28. package/examples/controls/11) window, mirrored text fields/client.js +493 -251
  29. package/examples/controls/11) window, mirrored text fields/server.js +117 -117
  30. package/examples/controls/11b) window, shared Data_Object model mirrored text fields/client.js +613 -331
  31. package/examples/controls/11b) window, shared Data_Object model mirrored text fields/server.js +117 -117
  32. package/examples/controls/11c) window, shared Data_Value model mirrored text fields/client.js +617 -617
  33. package/examples/controls/11c) window, shared Data_Value model mirrored text fields/server.js +117 -117
  34. package/examples/controls/11d) window, shared model mirrored integer text fields/client.js +611 -280
  35. package/examples/controls/11d) window, shared model mirrored integer text fields/server.js +134 -22
  36. package/examples/controls/12) window, Select_Options control/client.js +66 -452
  37. package/examples/controls/12) window, Select_Options control/server.js +19 -117
  38. package/examples/controls/13) window, Dropdown_Menu control/client.js +66 -0
  39. package/examples/controls/13) window, Dropdown_Menu control/server.js +20 -0
  40. package/examples/controls/2) two windows/client.js +193 -193
  41. package/examples/controls/2) two windows/server.js +113 -113
  42. package/examples/controls/3) five windows/client.js +217 -217
  43. package/examples/controls/3) five windows/server.js +116 -115
  44. package/examples/controls/4) window, tabbed panel/client.js +54 -225
  45. package/examples/controls/4) window, tabbed panel/server.js +17 -117
  46. package/examples/controls/5) window, grid/client.js +204 -484
  47. package/examples/controls/5) window, grid/server.js +117 -119
  48. package/examples/controls/6) window, color_palette/client.js +68 -204
  49. package/examples/controls/6) window, color_palette/server.js +117 -117
  50. package/examples/controls/7) window, month_view/client.js +40 -231
  51. package/examples/controls/7) window, month_view/server.js +117 -117
  52. package/examples/controls/8) window, checkbox/client.js +33 -209
  53. package/examples/controls/8) window, checkbox/server.js +117 -117
  54. package/examples/controls/9) window, date picker/client.js +76 -303
  55. package/examples/controls/9) window, date picker/server.js +117 -117
  56. package/examples/controls/9b) window, shared data.model mirrored date pickers/README.md +51 -0
  57. package/examples/controls/9b) window, shared data.model mirrored date pickers/client.js +83 -398
  58. package/examples/controls/9b) window, shared data.model mirrored date pickers/server.js +117 -117
  59. package/examples/controls/__old/_html-server-color-palette.js +114 -114
  60. package/examples/controls/__old/html-server-combo-box.js +104 -104
  61. package/examples/controls/__old/html-server-list.js +98 -98
  62. package/examples/controls/__old/html-server-popup-menu-button.js +114 -114
  63. package/examples/controls/__old/html-server-start-stop-toggle-button.js +146 -146
  64. package/examples/controls/__old/scs-arrow-button.js +36 -36
  65. package/examples/controls/__old/scs-date-picker.js +157 -157
  66. package/examples/controls/__old/scs-file-browser.js +82 -82
  67. package/examples/controls/__old/scs-item.js +159 -159
  68. package/examples/controls/__old/scs-month-arrow-selector.js +126 -126
  69. package/examples/controls/__old/scs-month-view.js +94 -94
  70. package/examples/controls/__old/scs-start-stop-toggle-button.js +40 -40
  71. package/examples/controls/__old/scs-tree.js +49 -49
  72. package/examples/controls/__old/scs-year-arrow-selector.js +127 -127
  73. package/examples/demos/date-picker.js +119 -119
  74. package/examples/demos/explain-encapsulation.js +9 -9
  75. package/examples/demos/resizing.js +35 -35
  76. package/examples/demos/server_time.js +6 -6
  77. package/examples/grids/grid_1.js +45 -45
  78. package/examples/grids/grid_1_client.js +329 -329
  79. package/examples/html-rendering.js +20 -20
  80. package/examples/html-server.js +105 -105
  81. package/examples/introducing jsgui3/server.js +110 -110
  82. package/examples/mx_display/mx_display_1.js +45 -45
  83. package/examples/mx_display/mx_display_1_client.js +444 -444
  84. package/fs2.js +1836 -1836
  85. package/http/responders/HTTP_Responder.js +15 -15
  86. package/http/responders/static/Static_Route_HTTP_Responder.js +105 -105
  87. package/module.js +34 -34
  88. package/old/_single-control-server.js +418 -418
  89. package/old/single-control-server.js +368 -368
  90. package/old/single-page-app.js +131 -131
  91. package/package.json +42 -42
  92. package/page-context.js +92 -92
  93. package/publishers/helpers/assigners/Assigner.js +10 -10
  94. package/publishers/helpers/assigners/static-compressed-response-buffers/Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner.js +150 -150
  95. package/publishers/helpers/assigners/static-headers/Single_Control_Webpage_Server_Static_Headers_Assigner.js +109 -109
  96. package/publishers/helpers/assigners/static-routes/Single_Control_Webpage_Server_Static_Routes_Assigner.js +91 -91
  97. package/publishers/helpers/assigners/static-uncompressed-response-buffers/Single_Control_Webpage_Server_Static_Uncompressed_Response_Buffers_Assigner.js +104 -104
  98. package/publishers/helpers/preparers/static/bundle/Ready_To_Serve_Preparer.js +18 -18
  99. package/publishers/helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer.js +44 -44
  100. package/publishers/http-function-publisher.js +212 -212
  101. package/publishers/http-html-page-publisher.js +5 -5
  102. package/publishers/http-html-publisher.js +24 -24
  103. package/publishers/http-js-publisher.js +135 -135
  104. package/publishers/http-observable-publisher.js +124 -124
  105. package/publishers/http-publisher.js +53 -53
  106. package/publishers/http-resource-publisher.js +325 -325
  107. package/publishers/http-webpage-publisher.js +659 -658
  108. package/publishers/http-webpageorsite-publisher.js +343 -343
  109. package/publishers/http-website-publisher.js +640 -640
  110. package/publishers/notes.md +9 -9
  111. package/resources/README.md +16 -16
  112. package/resources/_old_website-javascript-resource.js +994 -994
  113. package/resources/_old_website-resource.js +507 -507
  114. package/resources/compile/server-resource-compilation.js +43 -43
  115. package/resources/data-resource.js +118 -118
  116. package/resources/fs-resource.js +146 -146
  117. package/resources/jsbuilder/Abstract_Single_Declaration.js +105 -105
  118. package/resources/jsbuilder/Abstract_Single_Declaration_Sequence.js +42 -42
  119. package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node.js +61 -61
  120. package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node_Group.js +41 -41
  121. package/resources/jsbuilder/JS_AST/JS_AST_Group_Shared.js +61 -61
  122. package/resources/jsbuilder/JS_AST/JS_AST_Node.js +93 -93
  123. package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +253 -253
  124. package/resources/jsbuilder/JS_AST/JS_AST_Node_1-Babel.js +337 -337
  125. package/resources/jsbuilder/JS_AST/JS_AST_Node_10-Changing.js +39 -39
  126. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.1-Child.js +96 -96
  127. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.2-Parent.js +37 -37
  128. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.3-Ancestor.js +61 -61
  129. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.2-Inner.js +43 -43
  130. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.3-All.js +72 -72
  131. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.4-Sibling.js +92 -92
  132. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.5-Available_In_Scope.js +29 -29
  133. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.9-Signature.js +116 -116
  134. package/resources/jsbuilder/JS_AST/JS_AST_Node_3-Basics.js +159 -159
  135. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.0-Basics_First.js +178 -178
  136. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.1-Basics_Second.js +87 -87
  137. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.99-Basics_Last.js +91 -91
  138. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1-Basics_Each.js +136 -136
  139. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1.5-Basics_Count.js +73 -73
  140. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.2-Basics_Filter.js +39 -39
  141. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.3-Basics_Collect.js +85 -85
  142. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.4-Basics_Select.js +42 -42
  143. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.5-Basics_Find.js +40 -40
  144. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.6-Basics_Callmap.js +54 -54
  145. package/resources/jsbuilder/JS_AST/JS_AST_Node_4.0-Index_Indexes.js +45 -45
  146. package/resources/jsbuilder/JS_AST/JS_AST_Node_4.1-Index.js +343 -343
  147. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.0-Category.js +38 -38
  148. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.1-Category_Identifier.js +30 -30
  149. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.2-Category_Literal.js +28 -28
  150. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.3-Category_Expression.js +26 -26
  151. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.4-Category_Pattern.js +8 -8
  152. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.5-Category_Declaration.js +43 -43
  153. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.6-Category_Statement.js +21 -21
  154. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.0-Type.js +89 -89
  155. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.1-Type_Class_Declaration.js +8 -8
  156. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.2-Type_Variable_Declaration.js +27 -27
  157. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.3-Type_Variable_Declarator.js +28 -28
  158. package/resources/jsbuilder/JS_AST/JS_AST_Node_7-Query.js +736 -736
  159. package/resources/jsbuilder/JS_AST/JS_AST_Node_8-Features.js +64 -64
  160. package/resources/jsbuilder/JS_AST/JS_AST_Node_9-Planning.js +31 -31
  161. package/resources/jsbuilder/JS_AST/JS_AST_Node_Arrangement.js +15 -15
  162. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Declared_Object.js +305 -305
  163. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature.js +77 -77
  164. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declaration.js +248 -248
  165. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declarator.js +138 -138
  166. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature.js +10 -10
  167. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exported.js +100 -100
  168. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exports.js +60 -60
  169. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Interpreted.js +179 -179
  170. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/_JSGUI_Root_Node_Interpreted.js +43 -43
  171. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/special_case_objectassign_to_object.js +12 -12
  172. package/resources/jsbuilder/JS_AST/JS_AST_Node_Group.js +35 -35
  173. package/resources/jsbuilder/JS_AST/JS_AST_Operation.js +11 -11
  174. package/resources/jsbuilder/JS_AST/JS_AST_Operation_On_Relationship.js +31 -31
  175. package/resources/jsbuilder/JS_AST/JS_AST_Ordered_Relationship_Node_To_Group.js +37 -37
  176. package/resources/jsbuilder/JS_AST/JS_AST_Ordinal.js +39 -39
  177. package/resources/jsbuilder/JS_AST/JS_AST_Ordinal_Relationship.js +25 -25
  178. package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_To_Group.js +200 -200
  179. package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_Within_Group_To_Node.js +43 -43
  180. package/resources/jsbuilder/JS_AST/_JS_AST_Node_3.8-Query_Features.js +76 -76
  181. package/resources/jsbuilder/JS_AST/query/enable_array_as_queryable.js +227 -227
  182. package/resources/jsbuilder/JS_AST/query/find_object_keys.js +404 -404
  183. package/resources/jsbuilder/JS_AST/query/node_queries.js +8 -8
  184. package/resources/jsbuilder/JS_AST/query/root_query_identidy.js +11 -11
  185. package/resources/jsbuilder/JS_AST_Node_Extended/JSGUI_Singular_Declaration.js +85 -85
  186. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Declaration.js +123 -123
  187. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended.js +87 -87
  188. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended_0-Core.js +10 -10
  189. package/resources/jsbuilder/JS_Builder.js +10 -10
  190. package/resources/jsbuilder/JS_File/Feature/JS_File_Declared_Object.js +31 -31
  191. package/resources/jsbuilder/JS_File/Feature/JS_File_Exported_Object_Info.js +25 -25
  192. package/resources/jsbuilder/JS_File/Feature/JS_File_Exports.js +78 -78
  193. package/resources/jsbuilder/JS_File/Feature/JS_File_Feature.js +17 -17
  194. package/resources/jsbuilder/JS_File/Feature/JS_File_Imported_Object_Info.js +25 -25
  195. package/resources/jsbuilder/JS_File/Feature/JS_File_Imports.js +8 -8
  196. package/resources/jsbuilder/JS_File/JS_File.js +12 -12
  197. package/resources/jsbuilder/JS_File/JS_File_0-Core.js +202 -202
  198. package/resources/jsbuilder/JS_File/JS_File_1-Early_Parse.js +175 -175
  199. package/resources/jsbuilder/JS_File/JS_File_2-Babel.js +81 -81
  200. package/resources/jsbuilder/JS_File/JS_File_3-JS_AST_Node.js +86 -86
  201. package/resources/jsbuilder/JS_File/JS_File_4-Query.js +413 -413
  202. package/resources/jsbuilder/JS_File/JS_File_4.1-Query_Features.js +414 -414
  203. package/resources/jsbuilder/JS_File/JS_File_5-Planning.js +59 -59
  204. package/resources/jsbuilder/JS_File/JS_File_6-Changing.js +24 -24
  205. package/resources/jsbuilder/JS_File/JS_File_Export_Reference.js +12 -12
  206. package/resources/jsbuilder/JS_File/JS_File_Import_Reference.js +23 -23
  207. package/resources/jsbuilder/JS_File/JS_File_Import_References.js +31 -31
  208. package/resources/jsbuilder/JS_File/JS_File_Processor.js +16 -16
  209. package/resources/jsbuilder/JS_File/JS_Files.js +15 -15
  210. package/resources/jsbuilder/Module.js +14 -14
  211. package/resources/jsbuilder/Platform.js +13 -13
  212. package/resources/jsbuilder/Platforms.js +69 -69
  213. package/resources/jsbuilder/Project.js +109 -109
  214. package/resources/jsbuilder/Reference.js +1 -1
  215. package/resources/jsbuilder/Reference_Sequence.js +16 -16
  216. package/resources/jsbuilder/Scope.js +29 -29
  217. package/resources/jsbuilder/Variable_Name_Provider.js +42 -42
  218. package/resources/jsbuilder/_JS_File.js +225 -225
  219. package/resources/jsbuilder/ast_query.js +20 -20
  220. package/resources/jsbuilder/babel/babel_consts.js +162 -162
  221. package/resources/jsbuilder/babel/babel_node_tools.js +541 -541
  222. package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +923 -904
  223. package/resources/jsbuilder/build.js +16 -16
  224. package/resources/jsbuilder/platform_notes.md +66 -66
  225. package/resources/jsbuilder/test/test_ast_node.js +381 -381
  226. package/resources/jsbuilder/test/test_js_file.js +303 -303
  227. package/resources/jsbuilder/test/test_project.js +157 -157
  228. package/resources/local-server-info-resource.js +96 -96
  229. package/resources/notes.txt +10 -10
  230. package/resources/old/website-image-resource.js +1185 -1185
  231. package/resources/process-js.js +498 -498
  232. package/resources/processors/bundlers/bundle.js +29 -29
  233. package/resources/processors/bundlers/bundler.js +23 -23
  234. package/resources/processors/bundlers/css-bundler.js +234 -234
  235. package/resources/processors/bundlers/js/JS_Bundler.js +51 -51
  236. package/resources/processors/bundlers/js/esbuild/Advanced_JS_Bundler_Using_ESBuild.js +388 -391
  237. package/resources/processors/bundlers/js/esbuild/Bundler_Using_ESBuild.js +8 -8
  238. package/resources/processors/bundlers/js/esbuild/Core_JS_Non_Minifying_Bundler_Using_ESBuild.js +188 -188
  239. package/resources/processors/bundlers/js/esbuild/Core_JS_Single_File_Minifying_Bundler_Using_ESBuild.js +191 -192
  240. package/resources/processors/bundlers/js/esbuild/_Old_CSS_Extractor.js +239 -239
  241. package/resources/processors/bundlers/js-bundler.js +263 -263
  242. package/resources/processors/bundlers/test_ast.js +73 -73
  243. package/resources/processors/bundlers/webpage-bundler.js +404 -404
  244. package/resources/processors/bundlers/website-bundler.js +22 -22
  245. package/resources/processors/extractors/Extractor.js +9 -11
  246. package/resources/processors/extractors/js/css_and_js/AST_Node/CSS_And_JS_From_JS_String_Using_AST_Node_Extractor.js +239 -254
  247. package/resources/processors/extractors/js/css_and_js/CSS_And_JS_From_JS_String_Extractor.js +3 -3
  248. package/resources/processors/extractors/string/Pos_Span_String_Extractor.js +93 -93
  249. package/resources/server-installed-tools.js +28 -28
  250. package/resources/server-resource-pool.js +41 -41
  251. package/resources/website-audio-resource.js +735 -735
  252. package/resources/website-css-resource.js +411 -411
  253. package/resources/website-image-resource.js +412 -412
  254. package/resources/website-javascript-resource-processor.js +908 -908
  255. package/resources/website-javascript-resource.js +874 -874
  256. package/resources/website-resource-processor.js +10 -10
  257. package/resources/website-resource.js +164 -164
  258. package/resources/website-static-html-resource.js +199 -199
  259. package/resources/website-template-html-resource.js +231 -231
  260. package/roadmap.md +75 -75
  261. package/server.js +609 -573
  262. package/static-page-context.js +13 -13
  263. package/website/webpage.js +81 -81
  264. package/website/website-group.js +15 -15
  265. package/website/website.js +260 -260
  266. package/examples/controls/11d) window, shared model mirrored integer text fields/both.js +0 -17
  267. package/examples/controls/13) window, shared model mirrored lat_long/client.js +0 -933
  268. package/examples/controls/13) window, shared model mirrored lat_long/server.js +0 -50
  269. package/examples/controls/14) window, control compositional model/client.js +0 -328
  270. package/examples/controls/14) window, control compositional model/server.js +0 -118
  271. package/examples/controls/14a) window, control spec has compositional model/client.js +0 -440
  272. package/examples/controls/14a) window, control spec has compositional model/server.js +0 -118
  273. package/examples/controls/15) window, text field/client.js +0 -256
  274. package/examples/controls/16) Window([Text_Input])/client.js +0 -266
  275. package/examples/controls/16) Window([Text_Input])/server.js +0 -109
  276. package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/client.js +0 -494
  277. package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/isomorphic.js +0 -24
  278. package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/server.js +0 -73
  279. package/examples/controls/2b) two window, context menus/client.js +0 -193
  280. package/examples/controls/2b) two window, context menus/server.js +0 -114
  281. package/examples/controls/4a) window, tabbed panel with various controls inside/client.js +0 -233
  282. package/examples/controls/4a) window, tabbed panel with various controls inside/server.js +0 -118
@@ -1,659 +1,660 @@
1
- // Want to get it (back) working as a server easily serving simple controls and pages and sites.
2
- // Need to tame some of the more complex layers inside it to get it to easily serve the app.
3
- // Then should work on making / improving some of the specific controls.
4
- // Make the code idiomatic and DRY. The more complex lower and middle level abstractions will help with that.
5
- // Use polymorphism and run-time checks to allow for some more flexibility.
6
-
7
-
8
-
9
- // Later on will probably make some new very specific classes to encapsulate things the HTTP_Webpage_Publisher does.
10
-
11
- // Maybe have the publisher use Preparer or other (slightly) more specific classes.
12
-
13
-
14
-
15
-
16
- // The publisher will need to do a few things / have some things done, but make it rely on the helpers
17
- // and bundlers and extractors.
18
-
19
- // The helpers maybe could call the bundlers and extractors.
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
- // A publisher handles HTTP requests.
29
-
30
- // This is going to take over some of the responsibilities of the old website resource, which was unfocused code that was
31
- // doing some of the main / most important parts of serving the website.
32
- const jsgui_client = require('jsgui3-client');
33
-
34
- const HTTP_Publisher = require('./http-publisher');
35
- const Server_Static_Page_Context = require('../static-page-context');
36
-
37
- const HTTP_Webpageorsite_Publisher = require('./http-webpageorsite-publisher');
38
- const {obs} = require('fnl');
39
-
40
- // May want / need to more carefully and specifically define APIs.
41
- // It's nice to have classes for specific things like this, but need to make them do what is needed.
42
- // Maybe get a 'Website' object or control ready to be served.
43
- //
44
- const Static_Routes_Responses_Webpage_Bundle_Preparer = require('./helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer');
45
-
46
-
47
-
48
- // Named observables?
49
- /*
50
-
51
- obs((next, complete, error) => {
52
-
53
- */
54
-
55
-
56
- // HTTP_Webpage_Publisher could be interesting.
57
- // The Website Publisher could make use of some of its functionality.
58
-
59
- // Handling HTTP / bundling for a specific page could be cool.
60
-
61
- // A Webpage Publisher may be simpler and better to work on in the short term.
62
- // Maybe would not need to be (as) concerned with routing.
63
- // Could be useful for publishing a SPA of course, kind of a website but as a single page.
64
-
65
- // Should have more concerning bundling / compilation.
66
-
67
-
68
- // There could be 'bundle' functionality for the webpage.
69
-
70
- // The webpage itself could know what client js it needs to use.
71
-
72
- // Seems like bundling a specified webpage earlier on in the process makes sense.
73
-
74
- // And a Bundler as well?
75
- // Perhaps HTTP_Webpage_Bundler would be an important class to have here.
76
- // Considering how it could be interchangable from the publisher if it's a different class.
77
-
78
- // Possibly a Publisher should be called to provide something over HTTP.
79
- // So the call is routed to a Webpage object, through the Publisher.
80
- // Publisher could maintain a cache.
81
- // Maybe the publisher should read the bundle?
82
- // Maybe the publisher should do the bundling?
83
- // Perhaps there should be a bit more coordination of the bundling process, possibly accessed once needed.
84
- //
85
-
86
-
87
- // Should include or use various other publishers, such as html or js?
88
-
89
-
90
- // HTTP_Static_Webpage_Publisher perhaps....
91
-
92
-
93
- // Also have various Authorisers ...
94
- // Have Authenticators ...
95
-
96
-
97
-
98
-
99
-
100
-
101
- class HTTP_Webpage_Publisher extends HTTP_Webpageorsite_Publisher {
102
-
103
- // Website generally serves JS from a single address.
104
- // Webpage could have its specific JS.
105
- // This component may need to handle the JS building.
106
- // webpage-bundler within the 'bundler' directory.
107
-
108
- // But not sure if babel or esbuild is better here.
109
- // Babel has obviously improved since I had to switch to esbuild years ago.
110
- // Being able to use either would help.
111
-
112
-
113
-
114
-
115
-
116
- constructor(spec = {}) {
117
- super(spec)
118
-
119
- // A website property.
120
-
121
- let webpage;
122
- if (spec.webpage) webpage = spec.webpage;
123
- Object.defineProperty(this, 'webpage', {
124
- get() {
125
- return webpage;
126
- }
127
- });
128
-
129
-
130
-
131
-
132
- // But like the website publisher, this would need to bundle the page (JS, CSS, maybe more).
133
- // Consider that an SPA may reference images. May not exactly be one page in some ways.
134
-
135
-
136
-
137
-
138
-
139
- // Probably best to come up with a bundle here, or at an early stage.
140
-
141
- // .prepare_bundle?
142
-
143
- // .prepare_bundle would be a good function to have here.
144
-
145
-
146
-
147
- // .bundle?
148
- // seems clearest that we will be getting / preparing multiple files.
149
-
150
- // Bundling and compiling web content seems like a better thing to get working before serving (or attempting to serve) it.
151
- // .build?
152
-
153
- /*
154
- setTimeout(() => {
155
-
156
-
157
- this.raise('ready');
158
- }, 0);
159
-
160
- */
161
-
162
- this.static_routes_responses_webpage_bundle_preparer = new Static_Routes_Responses_Webpage_Bundle_Preparer();
163
-
164
- (async() => {
165
-
166
- const res_get_ready = await this.get_ready();
167
-
168
-
169
- // Is the HTML to be static or regenerated on page calls?
170
- // Want an easy way to specify it.
171
-
172
-
173
-
174
- // Then set things (a single static route???) up for the webpage.
175
- // Be very explicit with classes to do specific things like this so they will be easier to find and change.
176
-
177
- // Should render the webpage (once)
178
- // Maybe use a class on a higher level to choose this important rendering / caching setting.
179
-
180
- // Maybe the server could render multiple times over a few minutes before deciding it's not going to change.
181
-
182
- // Though telling the server it's static would help in some / many cases.
183
- // Have it as a sensible default depending on the situation.
184
-
185
- // Could even look at the controls to see if anything is non-static.
186
- // Or mark things somehow.
187
-
188
- // At least want to make this setting very clear in the future.
189
-
190
-
191
- this.raise('ready', res_get_ready);
192
-
193
- })();
194
-
195
- }
196
-
197
- async get_ready() {
198
- //await super.get_ready();
199
-
200
- const {static_routes_responses_webpage_bundle_preparer} = this;
201
-
202
-
203
- // Its a bundle....
204
- const webpage_or_website_res_get_ready = await super.get_ready();
205
-
206
- //console.log('webpage_or_website_res_get_ready', webpage_or_website_res_get_ready);
207
-
208
-
209
-
210
-
211
- const render_webpage = async () => {
212
-
213
- // Activate it or not.... As in serve active JSGUI control content. HTML ready to be activated on the client.
214
-
215
- // .active();
216
- // Generally would want that as standard.
217
-
218
- // Need to be very clear about generating active content on the server side.
219
- // Ready to be activated on the client-side.
220
- // Though could possibly activate using CSS classes.
221
-
222
-
223
-
224
-
225
- // Probably best to make a Server_Page_Context here.
226
- // Server_Static_Page_Context perhaps.
227
-
228
-
229
-
230
- // Maybe a class to render the single page into the bundle?
231
- // Maybe only worth doing when there become (many) more options and divisions seem clearer.
232
-
233
- const {webpage} = this;
234
- const Ctrl = webpage.content;
235
-
236
- // In business activating it with the page context.
237
-
238
- const static_page_context = new Server_Static_Page_Context();
239
-
240
- // Think the control needs to be some kind of HTML document control.
241
-
242
-
243
-
244
- const ctrl = new Ctrl({
245
- context: static_page_context
246
- });
247
-
248
- // Webpage_CSS_JS_HTML_Bundle_Ready_To_Serve_Preparer
249
-
250
- if (ctrl.head && ctrl.body) {
251
-
252
-
253
- // Create the CSS link control
254
-
255
- //console.log('jsgui_client.controls', jsgui_client.controls);
256
-
257
- //console.log('jsgui_client.controls', Object.keys(jsgui_client.controls));
258
-
259
- const ctrl_css_link = new jsgui_client.controls.link({
260
- context: static_page_context
261
- });
262
- ctrl_css_link.dom.attributes.rel = 'stylesheet';
263
- ctrl_css_link.dom.attributes.href = '/css/css.css';
264
-
265
- ctrl.head.add(ctrl_css_link);
266
-
267
-
268
- // Then add the JS Script ref (with href) to the (end of the) body.
269
-
270
- // Content_Incorporator perhaps???
271
- // Bundle_Content_Incorporator?
272
-
273
- // Will be worth making classes to do this when there is more variety of settings and operations.
274
-
275
- const ctrl_js_script_link = new jsgui_client.controls.script({
276
- context: static_page_context
277
- });
278
-
279
- ctrl_js_script_link.dom.attributes.src = '/js/js.js';
280
-
281
- ctrl.body.add(ctrl_js_script_link);
282
-
283
- // <script src="myscripts.js"></script>
284
-
285
-
286
- //console.log('!!ctrl.head', !!ctrl.head);
287
- //console.log('!!ctrl.body', !!ctrl.body);
288
-
289
- // add the css ref to the head, then the script ref to the body.
290
-
291
- // ctrl.body????
292
-
293
- // or add it to the body....
294
- // ctrl.head.add(new jsgui.script(...))
295
-
296
-
297
- // Adding script references...?
298
-
299
- // or .activate with it working on the server...?
300
-
301
-
302
-
303
- // Could have settings which determine which HTML elements get activated into controls, which don't.
304
- ctrl.active();
305
-
306
-
307
-
308
- // .active should do enough I think....
309
-
310
- // Server_Page_Context being the context of a publisher doing a one-time static rendering of a only page's HTML
311
- // Does seem like the Servier_Page_Context will be needed for this to work properly.
312
- // Want to hide some details that won't need changing from the top level API.
313
- // All kinds of things like page contexts will help in the background, they should be there to make
314
- // things easier.
315
-
316
-
317
-
318
-
319
-
320
-
321
- // do we need a Server_Page_Context first?
322
-
323
- const html = await ctrl.all_html_render();
324
-
325
- // Produces the HTML fairly well here....
326
-
327
-
328
- // Want to provide these as static resources to the server / router.
329
- // The publisher itself should not need to handle HTTP requests each time.
330
- // Keep the option for that though, it may help with some systems, more dynamic, not static responses.
331
-
332
- // Focus a lot on ease of use to set up servers with sensible and powerful defaults.
333
- // Also not requiring a specific directory or project structure.
334
- // Serving a simple app with a simple JS file.
335
-
336
-
337
-
338
-
339
-
340
-
341
-
342
-
343
- //console.log('html', html);
344
-
345
- //console.trace();
346
- //throw 'NYI';
347
-
348
- return html;
349
-
350
-
351
-
352
- } else {
353
- console.trace();
354
- throw 'NYI';
355
- }
356
-
357
- }
358
-
359
- // Maybe a Webpage_Rendering_Preparer could do this even?
360
-
361
- // Webpage_Renderer even
362
- // And it could render jsx, (other react?),
363
-
364
-
365
- const webpage_html = await render_webpage();
366
-
367
- const o_webpage_html = {
368
- type: 'HTML',
369
- extension: 'html',
370
- text: webpage_html
371
- }
372
-
373
- webpage_or_website_res_get_ready.push(o_webpage_html);
374
-
375
- //console.log('webpage_or_website_res_get_ready._arr.length', webpage_or_website_res_get_ready._arr.length);
376
-
377
-
378
- await static_routes_responses_webpage_bundle_preparer.prepare(webpage_or_website_res_get_ready);
379
-
380
- // Then publish it to the router...?
381
- // server.serve_prepared_static_routes_bundle ?????
382
- return webpage_or_website_res_get_ready;
383
-
384
-
385
-
386
- // But then the bundle with static routes should be given / provided to the server.
387
- // Would be nice to end the responsibility of the Publisher once the final prepared bundle with static
388
- // routes and static content (compressed in different ways, uncompressed buffer there too) and have the
389
- // Server or Server Router do the rest.
390
-
391
- // Improve handling of prepared to serve (HTTP response) bundles, making it easy to tell the server to use them.
392
-
393
- // Maybe make a more advanced HTTP_Responder baked into the server.
394
- // Or an interchagable class that does it, used within the server.
395
-
396
-
397
-
398
-
399
-
400
-
401
-
402
-
403
-
404
- // Then send it off to the final stage bundler / Final_Stage_Bundle_Preparer_That_Prepares_Static_Routes_Responses
405
-
406
- // Some very long and explicit class names seem appropriate.
407
-
408
- // Final_Stage_Webpage_Bundle_Preparer_Of_Static_Routes_Responses
409
-
410
- // Static_Routes_Responses_Webpage_Bundle_Preparer
411
- // That should be fine doing the very last part.
412
-
413
- // But then another component to assign these static routes to the router?
414
- // Or maybe that's easy enough to do with a function call (or a few).
415
-
416
- // Prepared_Responses_Cache???
417
-
418
- // Don't want to make big changes to the router and server itself right now.
419
- // Though an extra function (or a few) could help within Server_Router.
420
- // Or not the router, but do it here in the handle_http function call.
421
- // With the router just routing those URLs here.
422
-
423
- // Does seem better architecture for the publisher to hand the responsibility off to some (other) server component.
424
-
425
-
426
-
427
-
428
-
429
-
430
-
431
-
432
- // then add that webpage html to the bundle.
433
-
434
-
435
-
436
- // Then add a new static HTML item to the bundle.
437
-
438
-
439
-
440
- //console.log('webpage_html', webpage_html);
441
-
442
-
443
- // Add it to the bundle
444
- // Prepare the bundle to serve with static routes
445
- // Give the prepared bundle to the server (router).
446
-
447
- // Then see it running small and increasingly large apps.
448
-
449
-
450
-
451
-
452
-
453
- // Add the webpage HTML to the bundle.
454
- // Then call the static routes assigner on the array in the bundle (._arr)
455
-
456
- // Then get server_static_route_prepared_responses.
457
-
458
- // Then maybe some other class assigns these prepared responses to the server or server router.
459
-
460
- // When preparing static responses, should prepare them gzipped, brotlied, and uncompressed.
461
- // Though will (always?) use UTF8, will make that explicit and allow for other encoding types.
462
-
463
-
464
-
465
- // Preparer or Bundle_Perparer could be a final / further stage.
466
- // And would itself use other classes internally with very specific functionality
467
-
468
-
469
-
470
-
471
-
472
-
473
- // Then it will be about assembling the routing instructions.
474
-
475
- // So then different conventions / systems could be used to assign static routes.
476
- // And very clear in the code what is going on (through use of very explicit and specific class / classes that do this).
477
-
478
-
479
- // Server_Static_Routes_Assigner perhaps.
480
- // subclass:
481
- // Single_Control_Webpage_Server_Static_Routes_Assigner
482
-
483
- // Assigning the static routes with a class makes sense, could hard-code things here but want better options that can be interchanged
484
- // and modified and improved separately.
485
-
486
-
487
-
488
- // Bundle_To_Serve_Statically_Preparer
489
- // .prepare(bundle)
490
-
491
- // Really simple function calling syntax, really clear responsibilities, and if any wind up not being used then that will be
492
- // fine.
493
-
494
-
495
-
496
-
497
-
498
- // Server_Prepared_Static_Routes_Responses
499
-
500
-
501
- // publishers/publishing-tools perhaps....?
502
-
503
- // Or create a bundle that then includes the HTML document.
504
- // Could add headers and compressed buffers (to write to responses) to the existing bundle items.
505
-
506
-
507
- // The system as a whole here is not massively complex, but moderately.
508
- // Changable minute details will be finite in this implementation but infinite when it comes to extending and
509
- // making subcategories especially in terms of how things are done internally to that system.
510
-
511
-
512
-
513
-
514
-
515
-
516
-
517
-
518
-
519
- //console.trace();
520
- //throw 'NYI';
521
-
522
-
523
-
524
-
525
- // Probably need to call a preparer???
526
- // Need (something to) server the static things, but also if the rendered HTML itself is static, having that pre-rendered
527
- // would be best.
528
-
529
-
530
- // Should make the rendering more abstract (less specific code in Server itself) and be very clear indeed what the classes
531
- // do by naming them well.
532
-
533
- // But the publisher itself does handle the HTTP.
534
- // That possibly should not always be the case.
535
-
536
-
537
- // Website_Static_Responses_Preparer
538
- // Webpage_Static_Responses_Preparer
539
-
540
-
541
-
542
- // HTTP_Response_Preparer could be a useful class and one to subclass from.
543
-
544
- // HTTP_Static_Response_Preparer
545
-
546
-
547
-
548
-
549
-
550
-
551
-
552
-
553
- // Or maybe insert references to the bundled content appropriately into the HTML.
554
-
555
- // At the end of the body may be best for the JS???
556
- // Want nice options for this.
557
-
558
- // Then here we need to create static HTML....
559
-
560
-
561
-
562
- }
563
-
564
- // The publisher should not (always / usually) handle the HTTP calls.
565
- // It may be worth having architecture that allows for it when publishing dynamic content.
566
- // When publishing static content it's better to pass that static content onto the server. (specific static content for specific routes / urls)
567
- // Maybe dict or map lookup is better for those static content URLs.
568
-
569
-
570
-
571
-
572
-
573
-
574
- handle_http(req, res) {
575
-
576
-
577
- // Don't (automatically) connect this function.
578
-
579
- console.log('HTTP_Webpage_Publisher handle_http');
580
- console.log('req.url', req.url);
581
-
582
- // Should not (need to?) handle the HTTP here.
583
-
584
- // Ideally the Webpage Publisher will have already bundled all the static files.
585
-
586
-
587
- // HTTP_Webpage_Request_Handler perhaps?
588
-
589
-
590
-
591
-
592
-
593
- // Is the webpage rendered?
594
- // Does the webpage require rendering?
595
- // Seems like the main question to ask here.
596
-
597
-
598
-
599
-
600
- // returning an observable would make sense.
601
- // so other parts of the server could observe the request being processed.
602
-
603
-
604
-
605
-
606
- // This may be quite concerned with ensuring the bundle before handling any http requests to provide it or parts of it.
607
- // Could even unit test before running deployed code.
608
-
609
- // Could get info on what needs to be bundled from the webpage object itself.
610
- // A Webpage objects could have 'requirements', or 'build requirements'.
611
- // If such things are needed, then make classes for them.
612
-
613
-
614
-
615
-
616
-
617
-
618
-
619
-
620
-
621
-
622
-
623
-
624
- //console.log('HTTP_Webpage_Publisher handle_http');
625
- //console.log('req', req);
626
-
627
- const {webpage} = this;
628
- //console.log('webpage', webpage);
629
- //console.log('webpage.render()', webpage.render());
630
- //console.log('Object.keys (webpage)', Object.keys (webpage));
631
-
632
- //console.log('webpage.content', webpage.content);
633
-
634
- const Ctrl = webpage.content;
635
- const ctrl = new Ctrl();
636
-
637
- //console.log('webpage.content.render()', webpage.content.render());
638
- //console.log('webpage.content[0]', webpage.content[0]);
639
-
640
- //res.statusCode = 200;
641
- //response.setHeader('Content-Type', 'text/html');
642
- res.writeHead(200, {
643
- 'Content-Type': 'text/html'
644
- });
645
-
646
- res.end(ctrl.all_html_render());
647
-
648
-
649
-
650
-
651
- // May have bundle already prepared anyway.
652
- // Possibly the Website or the Website_Resource could do the bundling / building.
653
- // Could even bundle into a ZIP file :)
654
-
655
- //throw 'NYI';
656
- }
657
- }
658
-
1
+ // Want to get it (back) working as a server easily serving simple controls and pages and sites.
2
+ // Need to tame some of the more complex layers inside it to get it to easily serve the app.
3
+ // Then should work on making / improving some of the specific controls.
4
+ // Make the code idiomatic and DRY. The more complex lower and middle level abstractions will help with that.
5
+ // Use polymorphism and run-time checks to allow for some more flexibility.
6
+
7
+
8
+
9
+ // Later on will probably make some new very specific classes to encapsulate things the HTTP_Webpage_Publisher does.
10
+
11
+ // Maybe have the publisher use Preparer or other (slightly) more specific classes.
12
+
13
+
14
+
15
+
16
+ // The publisher will need to do a few things / have some things done, but make it rely on the helpers
17
+ // and bundlers and extractors.
18
+
19
+ // The helpers maybe could call the bundlers and extractors.
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+ // A publisher handles HTTP requests.
29
+
30
+ // This is going to take over some of the responsibilities of the old website resource, which was unfocused code that was
31
+ // doing some of the main / most important parts of serving the website.
32
+ const jsgui_client = require('jsgui3-client');
33
+
34
+ const HTTP_Publisher = require('./http-publisher');
35
+ const Server_Static_Page_Context = require('../static-page-context');
36
+
37
+ const HTTP_Webpageorsite_Publisher = require('./http-webpageorsite-publisher');
38
+ const {obs} = require('fnl');
39
+
40
+ // May want / need to more carefully and specifically define APIs.
41
+ // It's nice to have classes for specific things like this, but need to make them do what is needed.
42
+ // Maybe get a 'Website' object or control ready to be served.
43
+ //
44
+ const Static_Routes_Responses_Webpage_Bundle_Preparer = require('./helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer');
45
+
46
+
47
+
48
+ // Named observables?
49
+ /*
50
+
51
+ obs((next, complete, error) => {
52
+
53
+ */
54
+
55
+
56
+ // HTTP_Webpage_Publisher could be interesting.
57
+ // The Website Publisher could make use of some of its functionality.
58
+
59
+ // Handling HTTP / bundling for a specific page could be cool.
60
+
61
+ // A Webpage Publisher may be simpler and better to work on in the short term.
62
+ // Maybe would not need to be (as) concerned with routing.
63
+ // Could be useful for publishing a SPA of course, kind of a website but as a single page.
64
+
65
+ // Should have more concerning bundling / compilation.
66
+
67
+
68
+ // There could be 'bundle' functionality for the webpage.
69
+
70
+ // The webpage itself could know what client js it needs to use.
71
+
72
+ // Seems like bundling a specified webpage earlier on in the process makes sense.
73
+
74
+ // And a Bundler as well?
75
+ // Perhaps HTTP_Webpage_Bundler would be an important class to have here.
76
+ // Considering how it could be interchangable from the publisher if it's a different class.
77
+
78
+ // Possibly a Publisher should be called to provide something over HTTP.
79
+ // So the call is routed to a Webpage object, through the Publisher.
80
+ // Publisher could maintain a cache.
81
+ // Maybe the publisher should read the bundle?
82
+ // Maybe the publisher should do the bundling?
83
+ // Perhaps there should be a bit more coordination of the bundling process, possibly accessed once needed.
84
+ //
85
+
86
+
87
+ // Should include or use various other publishers, such as html or js?
88
+
89
+
90
+ // HTTP_Static_Webpage_Publisher perhaps....
91
+
92
+
93
+ // Also have various Authorisers ...
94
+ // Have Authenticators ...
95
+
96
+
97
+
98
+
99
+
100
+
101
+ class HTTP_Webpage_Publisher extends HTTP_Webpageorsite_Publisher {
102
+
103
+ // Website generally serves JS from a single address.
104
+ // Webpage could have its specific JS.
105
+ // This component may need to handle the JS building.
106
+ // webpage-bundler within the 'bundler' directory.
107
+
108
+ // But not sure if babel or esbuild is better here.
109
+ // Babel has obviously improved since I had to switch to esbuild years ago.
110
+ // Being able to use either would help.
111
+
112
+
113
+
114
+
115
+
116
+ constructor(spec = {}) {
117
+ super(spec)
118
+
119
+ // A website property.
120
+
121
+ let webpage;
122
+ if (spec.webpage) webpage = spec.webpage;
123
+ Object.defineProperty(this, 'webpage', {
124
+ get() {
125
+ return webpage;
126
+ }
127
+ });
128
+
129
+
130
+
131
+
132
+ // But like the website publisher, this would need to bundle the page (JS, CSS, maybe more).
133
+ // Consider that an SPA may reference images. May not exactly be one page in some ways.
134
+
135
+
136
+
137
+
138
+
139
+ // Probably best to come up with a bundle here, or at an early stage.
140
+
141
+ // .prepare_bundle?
142
+
143
+ // .prepare_bundle would be a good function to have here.
144
+
145
+
146
+
147
+ // .bundle?
148
+ // seems clearest that we will be getting / preparing multiple files.
149
+
150
+ // Bundling and compiling web content seems like a better thing to get working before serving (or attempting to serve) it.
151
+ // .build?
152
+
153
+ /*
154
+ setTimeout(() => {
155
+
156
+
157
+ this.raise('ready');
158
+ }, 0);
159
+
160
+ */
161
+
162
+ this.static_routes_responses_webpage_bundle_preparer = new Static_Routes_Responses_Webpage_Bundle_Preparer();
163
+
164
+ (async() => {
165
+
166
+ const res_get_ready = await this.get_ready();
167
+
168
+
169
+ // Is the HTML to be static or regenerated on page calls?
170
+ // Want an easy way to specify it.
171
+
172
+
173
+
174
+ // Then set things (a single static route???) up for the webpage.
175
+ // Be very explicit with classes to do specific things like this so they will be easier to find and change.
176
+
177
+ // Should render the webpage (once)
178
+ // Maybe use a class on a higher level to choose this important rendering / caching setting.
179
+
180
+ // Maybe the server could render multiple times over a few minutes before deciding it's not going to change.
181
+
182
+ // Though telling the server it's static would help in some / many cases.
183
+ // Have it as a sensible default depending on the situation.
184
+
185
+ // Could even look at the controls to see if anything is non-static.
186
+ // Or mark things somehow.
187
+
188
+ // At least want to make this setting very clear in the future.
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+ this.raise('ready', res_get_ready);
197
+
198
+ })();
199
+
200
+ }
201
+
202
+ async get_ready() {
203
+ //await super.get_ready();
204
+
205
+ const {static_routes_responses_webpage_bundle_preparer} = this;
206
+
207
+
208
+ // Its a bundle....
209
+ const webpage_or_website_res_get_ready = await super.get_ready();
210
+
211
+ //console.log('webpage_or_website_res_get_ready', webpage_or_website_res_get_ready);
212
+
213
+
214
+
215
+
216
+ const render_webpage = async () => {
217
+
218
+ // Activate it or not.... As in serve active JSGUI control content. HTML ready to be activated on the client.
219
+
220
+ // .active();
221
+ // Generally would want that as standard.
222
+
223
+ // Need to be very clear about generating active content on the server side.
224
+ // Ready to be activated on the client-side.
225
+ // Though could possibly activate using CSS classes.
226
+
227
+
228
+
229
+
230
+ // Probably best to make a Server_Page_Context here.
231
+ // Server_Static_Page_Context perhaps.
232
+
233
+
234
+
235
+ // Maybe a class to render the single page into the bundle?
236
+ // Maybe only worth doing when there become (many) more options and divisions seem clearer.
237
+
238
+ const {webpage} = this;
239
+ const Ctrl = webpage.content;
240
+
241
+ // In business activating it with the page context.
242
+
243
+ const static_page_context = new Server_Static_Page_Context();
244
+
245
+ const ctrl = new Ctrl({
246
+ context: static_page_context
247
+ });
248
+
249
+ // Webpage_CSS_JS_HTML_Bundle_Ready_To_Serve_Preparer
250
+
251
+ if (ctrl.head && ctrl.body) {
252
+
253
+
254
+ // Create the CSS link control
255
+
256
+ //console.log('jsgui_client.controls', jsgui_client.controls);
257
+
258
+ //console.log('jsgui_client.controls', Object.keys(jsgui_client.controls));
259
+
260
+ const ctrl_css_link = new jsgui_client.controls.link({
261
+ context: static_page_context
262
+ });
263
+ ctrl_css_link.dom.attributes.rel = 'stylesheet';
264
+ ctrl_css_link.dom.attributes.href = '/css/css.css';
265
+
266
+ ctrl.head.add(ctrl_css_link);
267
+
268
+
269
+ // Then add the JS Script ref (with href) to the (end of the) body.
270
+
271
+ // Content_Incorporator perhaps???
272
+ // Bundle_Content_Incorporator?
273
+
274
+ // Will be worth making classes to do this when there is more variety of settings and operations.
275
+
276
+ const ctrl_js_script_link = new jsgui_client.controls.script({
277
+ context: static_page_context
278
+ });
279
+
280
+ ctrl_js_script_link.dom.attributes.src = '/js/js.js';
281
+
282
+ ctrl.body.add(ctrl_js_script_link);
283
+
284
+ // <script src="myscripts.js"></script>
285
+
286
+
287
+ //console.log('!!ctrl.head', !!ctrl.head);
288
+ //console.log('!!ctrl.body', !!ctrl.body);
289
+
290
+ // add the css ref to the head, then the script ref to the body.
291
+
292
+ // ctrl.body????
293
+
294
+ // or add it to the body....
295
+ // ctrl.head.add(new jsgui.script(...))
296
+
297
+
298
+ // Adding script references...?
299
+
300
+ // or .activate with it working on the server...?
301
+
302
+
303
+
304
+ // Could have settings which determine which HTML elements get activated into controls, which don't.
305
+ ctrl.active();
306
+
307
+
308
+
309
+ // .active should do enough I think....
310
+
311
+ // Server_Page_Context being the context of a publisher doing a one-time static rendering of a only page's HTML
312
+ // Does seem like the Servier_Page_Context will be needed for this to work properly.
313
+ // Want to hide some details that won't need changing from the top level API.
314
+ // All kinds of things like page contexts will help in the background, they should be there to make
315
+ // things easier.
316
+
317
+
318
+
319
+
320
+
321
+
322
+ // do we need a Server_Page_Context first?
323
+
324
+ const html = await ctrl.all_html_render();
325
+
326
+ // Produces the HTML fairly well here....
327
+
328
+
329
+ // Want to provide these as static resources to the server / router.
330
+ // The publisher itself should not need to handle HTTP requests each time.
331
+ // Keep the option for that though, it may help with some systems, more dynamic, not static responses.
332
+
333
+ // Focus a lot on ease of use to set up servers with sensible and powerful defaults.
334
+ // Also not requiring a specific directory or project structure.
335
+ // Serving a simple app with a simple JS file.
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+ //console.log('html', html);
345
+
346
+ //console.trace();
347
+ //throw 'NYI';
348
+
349
+ return html;
350
+
351
+
352
+
353
+ } else {
354
+ console.trace();
355
+ throw 'NYI';
356
+ }
357
+
358
+ }
359
+
360
+ // Maybe a Webpage_Rendering_Preparer could do this even?
361
+
362
+ // Webpage_Renderer even
363
+ // And it could render jsx, (other react?),
364
+
365
+
366
+ const webpage_html = await render_webpage();
367
+
368
+ const o_webpage_html = {
369
+ type: 'HTML',
370
+ extension: 'html',
371
+ text: webpage_html
372
+ }
373
+
374
+ webpage_or_website_res_get_ready.push(o_webpage_html);
375
+
376
+ //console.log('webpage_or_website_res_get_ready._arr.length', webpage_or_website_res_get_ready._arr.length);
377
+
378
+
379
+ await static_routes_responses_webpage_bundle_preparer.prepare(webpage_or_website_res_get_ready);
380
+
381
+ // Then publish it to the router...?
382
+ // server.serve_prepared_static_routes_bundle ?????
383
+ return webpage_or_website_res_get_ready;
384
+
385
+
386
+
387
+ // But then the bundle with static routes should be given / provided to the server.
388
+ // Would be nice to end the responsibility of the Publisher once the final prepared bundle with static
389
+ // routes and static content (compressed in different ways, uncompressed buffer there too) and have the
390
+ // Server or Server Router do the rest.
391
+
392
+ // Improve handling of prepared to serve (HTTP response) bundles, making it easy to tell the server to use them.
393
+
394
+ // Maybe make a more advanced HTTP_Responder baked into the server.
395
+ // Or an interchagable class that does it, used within the server.
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+ // Then send it off to the final stage bundler / Final_Stage_Bundle_Preparer_That_Prepares_Static_Routes_Responses
406
+
407
+ // Some very long and explicit class names seem appropriate.
408
+
409
+ // Final_Stage_Webpage_Bundle_Preparer_Of_Static_Routes_Responses
410
+
411
+ // Static_Routes_Responses_Webpage_Bundle_Preparer
412
+ // That should be fine doing the very last part.
413
+
414
+ // But then another component to assign these static routes to the router?
415
+ // Or maybe that's easy enough to do with a function call (or a few).
416
+
417
+ // Prepared_Responses_Cache???
418
+
419
+ // Don't want to make big changes to the router and server itself right now.
420
+ // Though an extra function (or a few) could help within Server_Router.
421
+ // Or not the router, but do it here in the handle_http function call.
422
+ // With the router just routing those URLs here.
423
+
424
+ // Does seem better architecture for the publisher to hand the responsibility off to some (other) server component.
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+ // then add that webpage html to the bundle.
434
+
435
+
436
+
437
+ // Then add a new static HTML item to the bundle.
438
+
439
+
440
+
441
+ //console.log('webpage_html', webpage_html);
442
+
443
+
444
+ // Add it to the bundle
445
+ // Prepare the bundle to serve with static routes
446
+ // Give the prepared bundle to the server (router).
447
+
448
+ // Then see it running small and increasingly large apps.
449
+
450
+
451
+
452
+
453
+
454
+ // Add the webpage HTML to the bundle.
455
+ // Then call the static routes assigner on the array in the bundle (._arr)
456
+
457
+ // Then get server_static_route_prepared_responses.
458
+
459
+ // Then maybe some other class assigns these prepared responses to the server or server router.
460
+
461
+ // When preparing static responses, should prepare them gzipped, brotlied, and uncompressed.
462
+ // Though will (always?) use UTF8, will make that explicit and allow for other encoding types.
463
+
464
+
465
+
466
+ // Preparer or Bundle_Perparer could be a final / further stage.
467
+ // And would itself use other classes internally with very specific functionality
468
+
469
+
470
+
471
+
472
+
473
+
474
+ // Then it will be about assembling the routing instructions.
475
+
476
+ // So then different conventions / systems could be used to assign static routes.
477
+ // And very clear in the code what is going on (through use of very explicit and specific class / classes that do this).
478
+
479
+
480
+ // Server_Static_Routes_Assigner perhaps.
481
+ // subclass:
482
+ // Single_Control_Webpage_Server_Static_Routes_Assigner
483
+
484
+ // Assigning the static routes with a class makes sense, could hard-code things here but want better options that can be interchanged
485
+ // and modified and improved separately.
486
+
487
+
488
+
489
+ // Bundle_To_Serve_Statically_Preparer
490
+ // .prepare(bundle)
491
+
492
+ // Really simple function calling syntax, really clear responsibilities, and if any wind up not being used then that will be
493
+ // fine.
494
+
495
+
496
+
497
+
498
+
499
+ // Server_Prepared_Static_Routes_Responses
500
+
501
+
502
+ // publishers/publishing-tools perhaps....?
503
+
504
+ // Or create a bundle that then includes the HTML document.
505
+ // Could add headers and compressed buffers (to write to responses) to the existing bundle items.
506
+
507
+
508
+ // The system as a whole here is not massively complex, but moderately.
509
+ // Changable minute details will be finite in this implementation but infinite when it comes to extending and
510
+ // making subcategories especially in terms of how things are done internally to that system.
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+ //console.trace();
521
+ //throw 'NYI';
522
+
523
+
524
+
525
+
526
+ // Probably need to call a preparer???
527
+ // Need (something to) server the static things, but also if the rendered HTML itself is static, having that pre-rendered
528
+ // would be best.
529
+
530
+
531
+ // Should make the rendering more abstract (less specific code in Server itself) and be very clear indeed what the classes
532
+ // do by naming them well.
533
+
534
+ // But the publisher itself does handle the HTTP.
535
+ // That possibly should not always be the case.
536
+
537
+
538
+ // Website_Static_Responses_Preparer
539
+ // Webpage_Static_Responses_Preparer
540
+
541
+
542
+
543
+ // HTTP_Response_Preparer could be a useful class and one to subclass from.
544
+
545
+ // HTTP_Static_Response_Preparer
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
554
+ // Or maybe insert references to the bundled content appropriately into the HTML.
555
+
556
+ // At the end of the body may be best for the JS???
557
+ // Want nice options for this.
558
+
559
+ // Then here we need to create static HTML....
560
+
561
+
562
+
563
+ }
564
+
565
+ // The publisher should not (always / usually) handle the HTTP calls.
566
+ // It may be worth having architecture that allows for it when publishing dynamic content.
567
+ // When publishing static content it's better to pass that static content onto the server. (specific static content for specific routes / urls)
568
+ // Maybe dict or map lookup is better for those static content URLs.
569
+
570
+
571
+
572
+
573
+
574
+
575
+ handle_http(req, res) {
576
+
577
+
578
+ // Don't (automatically) connect this function.
579
+
580
+ console.log('HTTP_Webpage_Publisher handle_http');
581
+ console.log('req.url', req.url);
582
+
583
+ // Should not (need to?) handle the HTTP here.
584
+
585
+ // Ideally the Webpage Publisher will have already bundled all the static files.
586
+
587
+
588
+ // HTTP_Webpage_Request_Handler perhaps?
589
+
590
+
591
+
592
+
593
+
594
+ // Is the webpage rendered?
595
+ // Does the webpage require rendering?
596
+ // Seems like the main question to ask here.
597
+
598
+
599
+
600
+
601
+ // returning an observable would make sense.
602
+ // so other parts of the server could observe the request being processed.
603
+
604
+
605
+
606
+
607
+ // This may be quite concerned with ensuring the bundle before handling any http requests to provide it or parts of it.
608
+ // Could even unit test before running deployed code.
609
+
610
+ // Could get info on what needs to be bundled from the webpage object itself.
611
+ // A Webpage objects could have 'requirements', or 'build requirements'.
612
+ // If such things are needed, then make classes for them.
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+
624
+
625
+ //console.log('HTTP_Webpage_Publisher handle_http');
626
+ //console.log('req', req);
627
+
628
+ const {webpage} = this;
629
+ //console.log('webpage', webpage);
630
+ //console.log('webpage.render()', webpage.render());
631
+ //console.log('Object.keys (webpage)', Object.keys (webpage));
632
+
633
+ //console.log('webpage.content', webpage.content);
634
+
635
+ const Ctrl = webpage.content;
636
+ const ctrl = new Ctrl();
637
+
638
+ //console.log('webpage.content.render()', webpage.content.render());
639
+ //console.log('webpage.content[0]', webpage.content[0]);
640
+
641
+ //res.statusCode = 200;
642
+ //response.setHeader('Content-Type', 'text/html');
643
+ res.writeHead(200, {
644
+ 'Content-Type': 'text/html'
645
+ });
646
+
647
+ res.end(ctrl.all_html_render());
648
+
649
+
650
+
651
+
652
+ // May have bundle already prepared anyway.
653
+ // Possibly the Website or the Website_Resource could do the bundling / building.
654
+ // Could even bundle into a ZIP file :)
655
+
656
+ //throw 'NYI';
657
+ }
658
+ }
659
+
659
660
  module.exports = HTTP_Webpage_Publisher;