jsgui3-server 0.0.81 → 0.0.84

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 (58) hide show
  1. package/README.md +8 -1
  2. package/bundler/bundle.js +11 -0
  3. package/bundler/bundler.js +9 -0
  4. package/bundler/css-bundler.js +48 -0
  5. package/bundler/js-bundler.js +205 -0
  6. package/bundler/test_ast.js +74 -0
  7. package/bundler/webpage-bundler.js +284 -0
  8. package/bundler/website-bundler.js +23 -0
  9. package/controls/README.md +8 -0
  10. package/controls/page/admin.js +75 -0
  11. package/controls/panel/admin.js +11 -0
  12. package/examples/controls/html-server-combo-box.js +5 -5
  13. package/examples/html-server.js +3 -0
  14. package/examples/square_box.js +35 -0
  15. package/examples/square_box_client.js +91 -0
  16. package/module.js +8 -0
  17. package/{single-control-server.js → old/_single-control-server.js} +157 -96
  18. package/old/single-control-server.js +108 -158
  19. package/{single-page-app.js → old/single-page-app.js} +2 -0
  20. package/{examples/demos → old}/square_box.js +1 -1
  21. package/package.json +9 -9
  22. package/page-context.js +1 -1
  23. package/publishing/http-css-publisher.js +0 -0
  24. package/publishing/{function-publisher.js → http-function-publisher.js} +12 -2
  25. package/publishing/http-html-page-publisher.js +5 -0
  26. package/publishing/http-html-publisher.js +25 -0
  27. package/publishing/http-jpeg-publisher.js +0 -0
  28. package/publishing/http-js-publisher.js +25 -0
  29. package/publishing/{observable-publisher.js → http-observable-publisher.js} +12 -6
  30. package/publishing/http-png-publisher.js +0 -0
  31. package/publishing/http-publisher.js +52 -0
  32. package/publishing/{resource-publisher.js → http-resource-publisher.js} +20 -1
  33. package/publishing/http-svg-publisher.js +0 -0
  34. package/publishing/http-webpage-publisher.js +112 -0
  35. package/publishing/http-website-publisher.js +254 -0
  36. package/publishing/notes.md +1 -0
  37. package/resources/README.md +16 -0
  38. package/resources/_old_website-resource.js +507 -0
  39. package/resources/compile/server-resource-compilation.js +41 -0
  40. package/resources/data-resource.js +14 -0
  41. package/resources/fs-resource.js +2 -4
  42. package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +3 -0
  43. package/resources/jsbuilder/test/test_ast_node.js +1 -1
  44. package/resources/jsbuilder/test/test_js_file.js +2 -2
  45. package/resources/jsbuilder/test/test_project.js +1 -0
  46. package/resources/notes.txt +11 -0
  47. package/resources/server-installed-tools.js +29 -0
  48. package/resources/server-resource-pool.js +1 -44
  49. package/resources/website-css-resource.js +1 -1
  50. package/resources/website-javascript-resource.js +165 -34
  51. package/resources/website-resource.js +62 -294
  52. package/resources/website-static-html-resource.js +8 -16
  53. package/resources/website-template-html-resource.js +231 -0
  54. package/roadmap.md +64 -0
  55. package/server.js +721 -18
  56. package/website/webpage.js +169 -0
  57. package/website/website-group.js +16 -0
  58. package/website/website.js +227 -0
@@ -2,6 +2,21 @@
2
2
  * Created by James on 29/07/2014.
3
3
  */
4
4
 
5
+ // 2022 - Seems a little uncertain about what it is for, and what it does has grown over time.
6
+
7
+
8
+
9
+ // A Website abstraction and a Website_Publisher seem like a good way forward.
10
+
11
+
12
+ // Want to make a near future release have a web publishing system that is easier to use as well as more
13
+ // powerful.
14
+
15
+ // Publishing static sites, rendering and compiling.
16
+
17
+ // Represents (and is?) a website itself, and its representation available through the Resource system.
18
+
19
+
5
20
  // Want to get the core resources working and tested.
6
21
  // Want to run a clock website / service to start with.
7
22
  // The server could have a clock, while clients could connect to it and share the information.
@@ -46,6 +61,17 @@
46
61
  // It would be much more secure to bring up an NTP provision service automatically than a file system one. Don't want to take that risk now.
47
62
  //
48
63
 
64
+ // Possibly WebPack could be considered such a resource? Or find a different type for that type of resource?
65
+
66
+ // Compilation_Resource and Compiler_Resource...
67
+
68
+
69
+ // Maybe should do more to represent a website on a server.
70
+ // Maybe it needs more docs, being rather critical.
71
+
72
+
73
+
74
+
49
75
  var Site_Images = require("./website-image-resource");
50
76
 
51
77
  //console.log('1) Site_Images', Site_Images);
@@ -58,293 +84,66 @@ const Resource = jsgui.Resource;
58
84
  const Router = jsgui.Router;
59
85
  //const Evented_Class = jsgui.Evented_Class;
60
86
 
61
- var Resource_Pool = require("./server-resource-pool");
87
+ const Resource_Pool = require("./server-resource-pool");
62
88
  //var Resource_Web_Admin = require('../web-admin');
63
89
 
64
- var Site_JavaScript = require("./website-javascript-resource");
90
+ const Site_JavaScript = require("./website-javascript-resource");
65
91
  //console.log('1) Site_JavaScript', Site_JavaScript);
66
- var Site_CSS = require("./website-css-resource");
67
- var Site_Static_HTML = require("./website-static-html-resource");
92
+ const Site_CSS = require("./website-css-resource");
93
+ const Site_Static_HTML = require("./website-static-html-resource");
68
94
  //var DB_Web_Resource = require('../../web/db-resource-postgres');
69
95
  //var database_resource_factory = require('../../db/resource/factory');
70
96
 
71
- const Resource_Publisher = require("../publishing/resource-publisher");
72
- const Observable_Publisher = require("../publishing/observable-publisher");
73
- const Function_Publisher = require("../publishing/function-publisher");
97
+ const Resource_Publisher = require("../publishing/http-resource-publisher");
98
+ const Observable_Publisher = require("../publishing/http-observable-publisher");
99
+ const Function_Publisher = require("../publishing/http-function-publisher");
74
100
  //const Data_Resource = require("./data-resource");
75
101
 
76
- class Website_Resource extends Resource {
77
- constructor(spec = {}) {
78
- super(spec);
79
- // A bit of a special resource here because it has its own resource_pool.
80
- var resource_pool = new Resource_Pool({
81
- name: "Website Resource Pool"
82
- });
83
- this.resource_pool = resource_pool;
84
- var database_spec = spec.database;
85
- var web_database_resource;
86
-
87
- if (database_spec) {
88
- database_spec.name = database_spec.name || database_spec.database_name;
89
- var database_resource = database_resource_factory(database_spec);
90
- database_resource.start();
91
- // should start automatically when in the pool?
92
- // does the pool need to be told to start?
93
- // Though probably don't want to start the resource on initialization.
94
- resource_pool.add(database_resource);
95
- web_database_resource = new DB_Web_Resource({
96
- database: database_resource,
97
- meta: {
98
- name: "Web DB",
99
- pool: resource_pool
100
- }
101
- });
102
- }
103
-
104
- if (web_database_resource) {
105
- resource_pool.add(web_database_resource);
106
- }
107
-
108
- var router = new Router({
109
- name: "Site Router"
110
- });
111
-
112
- this.router = router;
113
-
114
- var spec_web_admin = {
115
- //'web_database': web_database_resource,
116
- meta: {
117
- name: "Web Admin"
118
- }
119
- };
120
-
121
- if (web_database_resource) {
122
- spec_web_admin.web_database = web_database_resource;
123
- }
124
-
125
- var img_resource = new Site_Images({
126
- //'meta': {
127
- name: "Site Images",
128
- pool: resource_pool
129
- // }
130
- });
131
-
132
- var js_resource = new Site_JavaScript({
133
- //'meta': {
134
- name: "Site JavaScript",
135
- pool: resource_pool
136
- //}
137
- });
102
+ // Proxy_Server_Resource possibly.
103
+ // Note that the client should be able to access a Proxy_Server_Resource if needed.
104
+ // Could just send request onwards and do same for response.
105
+ // Buffering rate-limiting proxies too though?
138
106
 
139
- // Also want a static HTML server.
140
- // Would serve index.html by default I think???
141
- // Probably with the static or simplest settings.
142
-
143
- var static_html_resource;
144
-
145
- if (spec == "static") {
146
- static_html_resource = new Site_Static_HTML({
147
- //'meta': {
148
- name: "Static HTML",
149
- pool: resource_pool
150
- //}
151
- });
152
-
153
- resource_pool.push(static_html_resource);
154
-
155
- // Perhaps set it up with the specific files (automatically)?
156
- // Probably with the index.html
157
- }
158
- var css_resource = new Site_CSS({
159
- //'meta': {
160
- name: "Site CSS",
161
- pool: resource_pool
162
- //}
163
- });
164
107
 
108
+ // May help with FirstPoint_Server.
165
109
 
166
- js_resource.on('extracted-controls-css', str_extracted_css => {
167
- css_resource.serve_str_css('controls.css', str_extracted_css);
168
- // Will serve this as controls.css
169
- // Separate HTTP request, will get more CSS for the moment.
110
+ // Could move the publishing parts to Website_Resource_Publisher perhaps.
170
111
 
171
- });
172
- // javascript and css resources.
173
- resource_pool.push(router);
174
- resource_pool.push(img_resource);
175
- resource_pool.push(js_resource);
176
- resource_pool.push(css_resource);
177
- //resource_pool.push(data_resource);
178
-
179
- // anything ending in .css as well.
180
- // Routing maybe wouldn't work like that.
181
- //router.set_route('*.css', css_resource, css_resource.process);
182
-
183
- router.set_route("css/*", css_resource, css_resource.process);
184
- router.set_route("js/*", js_resource, js_resource.process);
185
- // As well as this, it could get the JavaScript resource to serve the JavaScript from the app's js directory.
186
- js_resource.serve_directory("js");
187
- router.set_route("img/*", img_resource, img_resource.process);
188
- router.set_route("images/*", img_resource, img_resource.process);
189
- this.map_resource_publishers = this.map_resource_publishers || {};
190
- router.set_route("resources/:resource_name/*", this, (req, res) => {
191
- let { url, method } = req;
192
- let s_url = url.split("/");
193
- let resource_short_name = s_url[2];
194
- let resource_publisher = this.map_resource_publishers[resource_short_name];
195
- if (resource_publisher) {
196
- resource_publisher.handle_http(req, res);
197
- }
198
- });
199
- if (!is_defined(spec)) spec = {};
200
- this.resource_pool = resource_pool;
201
- }
202
112
 
203
- publishing_get_pub(item) {
204
- let pub;
205
- if (item instanceof jsgui.Resource) {
206
- pub = new Resource_Publisher({
207
- resource: item
208
- });
209
- } else {
210
- // if its a function
211
- // return that function call to the response.
212
- let t_item = typeof item;
213
- if (t_item === "function") {
214
- // Function_Call_Publisher
215
- // could respec this.
216
- // And the Function_Publisher operates through the Publisher API. Not sure what that is right now though.
217
-
218
- pub = new Function_Publisher({
219
- fn: item
220
- });
221
- //this.map_resource_publishers[published_name] = pub;
222
- //
223
- } else {
224
- if (item.next && item.complete && item.error) {
225
- // assuming observable
226
- // Observable publisher
227
- // One way sending...
228
- //console.log('using Observable_Publisher');
229
- pub = new Observable_Publisher({
230
- obs: item
231
- });
232
- // or not a resource publisher, an observable publisher.
233
- //this.map_resource_publishers = this.map_resource_publishers || {};
234
- //this.map_resource_publishers[published_name] = obs_pub;
235
-
236
- //console.log('2) this', this);
237
- //console.log('this.map_resource_publishers', this.map_resource_publishers);
238
- //console.trace();
239
- } else {
240
- console.log("item", item);
241
- throw "Unrecognised item type. Possibly node module versions are wrong / have not been linked fully.";
242
- }
243
- }
244
- //if (item instanceof Evented_Class) {
245
- }
246
- return pub;
247
- }
248
113
 
249
- // publish within resources?
250
- publish(published_name, item, schema) {
251
- let sig = get_a_sig(arguments),
252
- a = arguments,
253
- l = a.length;
254
- const single = (published_name, item) => {
255
- if (item instanceof jsgui.Resource) {
256
- let resource_publisher = new Resource_Publisher({
257
- resource: item,
258
- name: published_name
259
- });
260
- this.map_resource_publishers[published_name] = resource_publisher;
261
-
262
- item.name = item.name || published_name;
263
- // add that resource!
264
- // (to the pool?)
265
- //console.log('item', item);
266
- this.resource_pool.add(item);
267
-
268
- //console.log('Object.keys(this.map_resource_publishers)', Object.keys(this.map_resource_publishers));
269
- } else {
270
- // if its a function
271
- // return that function call to the response.
272
- let t_item = typeof item;
273
- if (t_item === "function") {
274
- // Function_Call_Publisher
275
- // could respec this.
276
-
277
- // And the Function_Publisher operates through the Publisher API. Not sure what that is right now though.
278
- // directly attaching the resource publishers?
279
- let pub = new Function_Publisher({
280
- fn: item,
281
- schema: schema
282
- });
283
- this.map_resource_publishers[published_name] = pub;
284
- //
285
-
286
- } else {
287
- if (item.next && item.complete && item.error) {
288
- let obs_pub = new Observable_Publisher({
289
- obs: item,
290
- schema: schema
291
- });
292
- this.map_resource_publishers[published_name] = obs_pub;
293
- } else {
294
- console.log("item", item);
295
- throw "Unrecognised item type. Possibly node module versions are wrong / have not been linked fully.";
296
- }
297
- }
298
- //if (item instanceof Evented_Class) {
299
- }
300
- };
114
+ // Maybe worth just having a Website object.
115
+ // Then the Website_Resource can encapsulate that.
301
116
 
302
- if (sig === "[o]") {
303
- each(a[0], (v, i) => {
304
- single(i, v);
305
- })
306
- } else {
117
+ // Better if this wraps the Website object?
307
118
 
308
- single(published_name, item);
309
- }
310
- }
119
+ // A Website has its own Website Resource Pool?
311
120
 
312
- get resource_names() {
313
- //console.log('this.resource_pool', this.resource_pool);
314
- return this.resource_pool.resource_names;
315
- }
121
+ // Make Website_Resource into the wrapper that wraps Website?
122
+ // Or we don't need that, just use HTTP_Website_Publisher.
316
123
 
317
- get_resource(resource_name) {
318
- var resource_pool = this.resource_pool;
319
- //console.log('resource_pool', resource_pool);
124
+ // Maybe this won't be necessary in various cases.
320
125
 
321
- //console.log('this._.resource_pool', this._.resource_pool);
126
+ // For the moment won't make this website resource do all that much.
322
127
 
323
- //throw 'stop';
324
- return resource_pool.get_resource(resource_name);
325
- }
326
-
327
- get def_resource_publishers() {
328
- const res = {};
329
- each(this.map_resource_publishers, (rp, name) => {
330
-
331
- let def = {
332
- name: name,
333
- type: rp.type
334
- }
335
- res[name] = def;
336
- if (rp.type === 'function') {
337
- if (rp.schema) def.schema = rp.schema;
338
- }
339
-
340
- })
128
+ class Website_Resource extends Resource {
129
+ constructor(spec = {}) {
130
+ super(spec);
131
+ // A bit of a special resource here because it has its own resource_pool.
132
+ let website;
133
+ if (spec.website) website = spec.website;
134
+ Object.defineProperty(this, 'website', {
135
+ get() {
136
+ return website;
137
+ }
138
+ });
341
139
 
342
- return res;
343
140
  }
344
141
 
345
142
  start(callback) {
346
- var resource_pool = this.resource_pool;
347
- resource_pool.start(callback);
143
+ //var resource_pool = this.resource_pool;
144
+ //resource_pool.start(callback);
145
+
146
+ callback(null, true);
348
147
  }
349
148
 
350
149
  meets_requirements() {
@@ -354,37 +153,6 @@ class Website_Resource extends Resource {
354
153
 
355
154
  return true;
356
155
  }
357
-
358
- // Needs to be able to process HTTP requests. A bit like the Router in that way.
359
- process(req, res) {
360
- //console.log('website process request req.url', req.url);
361
- //throw 'stop';
362
-
363
- var remoteAddress = req.connection.remoteAddress;
364
- var router = this.router;
365
- var res_process = router.process(req, res);
366
- if (res_process === false) {
367
- if (req.url === "/") {
368
- // Send this to the static HTML processing system.
369
-
370
- var static_html_resource = this.resource_pool.get_resource(
371
- "Static HTML"
372
- );
373
- //console.log('static_html_resource', static_html_resource);
374
- // And lets get the static resource to process it
375
- if (static_html_resource) {
376
- static_html_resource.process(req, res);
377
- }
378
- } else {
379
- // show a 404
380
- res.writeHead(404, {
381
- "Content-Type": "text/plain"
382
- });
383
- res.write("404 Not Found\n");
384
- res.end();
385
- }
386
- }
387
- }
388
156
  }
389
157
 
390
158
  module.exports = Website_Resource;
@@ -38,6 +38,14 @@ var serve_html_file_from_disk = function(filePath, response) {
38
38
 
39
39
  // Transformation Resource could / should appear in jsgui3-client. Makes sense on the client too.
40
40
 
41
+ // Separate loading of transformation resource, data resource, and template (resource)
42
+ // The transformation resource can itself load / be provided with the data resource and template resource.
43
+
44
+ // jsx processing may be the best way (by far)?
45
+
46
+ // or jsui templates?
47
+ // jsx may seem / be easiest at this stage for long term expansion and integration.
48
+
41
49
 
42
50
  class Site_Static_HTML extends Resource {
43
51
 
@@ -83,48 +91,33 @@ class Site_Static_HTML extends Resource {
83
91
  }
84
92
  'process'(req, res) {
85
93
  //console.log('Site_Static_HTML processing');
86
-
87
-
88
-
89
-
90
94
  var remoteAddress = req.connection.remoteAddress;
91
-
92
95
  var custom_paths = this.custom_paths;
93
-
94
96
  var rurl = req.url;
95
-
96
97
  var pool = this.pool;
97
98
  // should have a bunch of resources from the pool.
98
-
99
99
  //var pool_resources = pool.resources();
100
100
  //console.log('pool_resources ' + stringify(pool_resources));
101
101
 
102
-
103
102
  var url_parts = url.parse(req.url, true);
104
103
  //console.log('url_parts ' + stringify(url_parts));
105
104
  var splitPath = url_parts.path.substr(1).split('/');
106
105
  //console.log('resource site css splitPath ' + stringify(splitPath));
107
106
 
108
-
109
107
  if (rurl.substr(0, 1) == '/') rurl = rurl.substr(1);
110
108
  rurl = rurl.replace(/\./g, '☺');
111
109
  //console.log('rurl ' + rurl);
112
110
 
113
111
  if (rurl == '') rurl = '/';
114
-
115
112
  var custom_response_entry = custom_paths.get(rurl);
116
-
117
113
  //console.log('Static HTML Resource process url', req.url);
118
114
 
119
115
 
120
-
121
-
122
116
  //console.log('custom_response_entry ' + stringify(custom_response_entry));
123
117
 
124
118
  if (custom_response_entry) {
125
119
  var tcr = tof(custom_response_entry);
126
120
  //console.log('tcr ' + tcr);
127
-
128
121
  if (tcr == 'data_value') {
129
122
  var val = custom_response_entry.value();
130
123
  //console.log('val ' + val);
@@ -195,7 +188,6 @@ class Site_Static_HTML extends Resource {
195
188
  if (splitPath.length == 3) {
196
189
 
197
190
  }
198
-
199
191
  }
200
192
  }
201
193
  }