jsgui3-server 0.0.75 → 0.0.77

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 (158) hide show
  1. package/examples/client-side-popup-menu-button.html +93 -93
  2. package/examples/controls/_html-server-color-palette.js +114 -114
  3. package/examples/controls/html-server-combo-box.js +104 -104
  4. package/examples/controls/html-server-list.js +98 -98
  5. package/examples/controls/html-server-popup-menu-button.js +114 -114
  6. package/examples/controls/html-server-start-stop-toggle-button.js +146 -146
  7. package/examples/controls/scs-arrow-button.js +36 -36
  8. package/examples/controls/scs-date-picker.js +157 -157
  9. package/examples/controls/scs-file-browser.js +82 -82
  10. package/examples/controls/scs-item.js +159 -159
  11. package/examples/controls/scs-month-arrow-selector.js +126 -126
  12. package/examples/controls/scs-month-view.js +95 -95
  13. package/examples/controls/scs-start-stop-toggle-button.js +40 -40
  14. package/examples/controls/scs-tree.js +49 -49
  15. package/examples/controls/scs-year-arrow-selector.js +127 -127
  16. package/examples/demos/date-picker.js +119 -119
  17. package/examples/demos/explain-encapsulation.js +9 -9
  18. package/examples/demos/resizing.js +35 -35
  19. package/examples/demos/server_time.js +6 -6
  20. package/examples/demos/square_box.js +324 -324
  21. package/examples/html-rendering.js +20 -20
  22. package/examples/html-server.js +100 -100
  23. package/fs2.js +1836 -1836
  24. package/module.js +21 -21
  25. package/old/single-control-server.js +418 -418
  26. package/package.json +44 -42
  27. package/publishing/function-publisher.js +202 -202
  28. package/publishing/notes.md +5 -5
  29. package/publishing/observable-publisher.js +118 -118
  30. package/publishing/resource-publisher.js +306 -306
  31. package/resources/data-resource.js +104 -104
  32. package/resources/fs-resource.js +148 -148
  33. package/resources/jsbuilder/Abstract_Single_Declaration.js +105 -0
  34. package/resources/jsbuilder/Abstract_Single_Declaration_Sequence.js +43 -0
  35. package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node.js +62 -0
  36. package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node_Group.js +42 -0
  37. package/resources/jsbuilder/JS_AST/JS_AST_Group_Shared.js +62 -0
  38. package/resources/jsbuilder/JS_AST/JS_AST_Node.js +94 -0
  39. package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +228 -0
  40. package/resources/jsbuilder/JS_AST/JS_AST_Node_1-Babel.js +338 -0
  41. package/resources/jsbuilder/JS_AST/JS_AST_Node_10-Changing.js +40 -0
  42. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.1-Child.js +97 -0
  43. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.2-Parent.js +38 -0
  44. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.3-Ancestor.js +62 -0
  45. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.2-Inner.js +44 -0
  46. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.3-All.js +73 -0
  47. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.4-Sibling.js +93 -0
  48. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.5-Available_In_Scope.js +29 -0
  49. package/resources/jsbuilder/JS_AST/JS_AST_Node_2.9-Signature.js +116 -0
  50. package/resources/jsbuilder/JS_AST/JS_AST_Node_3-Basics.js +160 -0
  51. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.0-Basics_First.js +179 -0
  52. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.1-Basics_Second.js +88 -0
  53. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.99-Basics_Last.js +92 -0
  54. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1-Basics_Each.js +137 -0
  55. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1.5-Basics_Count.js +74 -0
  56. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.2-Basics_Filter.js +40 -0
  57. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.3-Basics_Collect.js +86 -0
  58. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.4-Basics_Select.js +43 -0
  59. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.5-Basics_Find.js +41 -0
  60. package/resources/jsbuilder/JS_AST/JS_AST_Node_3.6-Basics_Callmap.js +55 -0
  61. package/resources/jsbuilder/JS_AST/JS_AST_Node_4.0-Index_Indexes.js +46 -0
  62. package/resources/jsbuilder/JS_AST/JS_AST_Node_4.1-Index.js +344 -0
  63. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.0-Category.js +39 -0
  64. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.1-Category_Identifier.js +31 -0
  65. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.2-Category_Literal.js +29 -0
  66. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.3-Category_Expression.js +27 -0
  67. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.4-Category_Pattern.js +9 -0
  68. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.5-Category_Declaration.js +44 -0
  69. package/resources/jsbuilder/JS_AST/JS_AST_Node_5.6-Category_Statement.js +22 -0
  70. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.0-Type.js +87 -0
  71. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.1-Type_Class_Declaration.js +9 -0
  72. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.2-Type_Variable_Declaration.js +28 -0
  73. package/resources/jsbuilder/JS_AST/JS_AST_Node_6.3-Type_Variable_Declarator.js +29 -0
  74. package/resources/jsbuilder/JS_AST/JS_AST_Node_7-Query.js +737 -0
  75. package/resources/jsbuilder/JS_AST/JS_AST_Node_8-Features.js +65 -0
  76. package/resources/jsbuilder/JS_AST/JS_AST_Node_9-Planning.js +32 -0
  77. package/resources/jsbuilder/JS_AST/JS_AST_Node_Arrangement.js +15 -0
  78. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Declared_Object.js +306 -0
  79. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature.js +78 -0
  80. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declaration.js +249 -0
  81. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declarator.js +139 -0
  82. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature.js +10 -0
  83. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exported.js +101 -0
  84. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exports.js +61 -0
  85. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Interpreted.js +180 -0
  86. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/_JSGUI_Root_Node_Interpreted.js +43 -0
  87. package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/special_case_objectassign_to_object.js +12 -0
  88. package/resources/jsbuilder/JS_AST/JS_AST_Node_Group.js +35 -0
  89. package/resources/jsbuilder/JS_AST/JS_AST_Operation.js +11 -0
  90. package/resources/jsbuilder/JS_AST/JS_AST_Operation_On_Relationship.js +32 -0
  91. package/resources/jsbuilder/JS_AST/JS_AST_Ordered_Relationship_Node_To_Group.js +38 -0
  92. package/resources/jsbuilder/JS_AST/JS_AST_Ordinal.js +40 -0
  93. package/resources/jsbuilder/JS_AST/JS_AST_Ordinal_Relationship.js +25 -0
  94. package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_To_Group.js +201 -0
  95. package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_Within_Group_To_Node.js +44 -0
  96. package/resources/jsbuilder/JS_AST/_JS_AST_Node_3.8-Query_Features.js +77 -0
  97. package/resources/jsbuilder/JS_AST/query/all.js +0 -0
  98. package/resources/jsbuilder/JS_AST/query/enable_array_as_queryable.js +228 -0
  99. package/resources/jsbuilder/JS_AST/query/find_object_keys.js +405 -0
  100. package/resources/jsbuilder/JS_AST/query/node_queries.js +9 -0
  101. package/resources/jsbuilder/JS_AST/query/root_queries.js +0 -0
  102. package/resources/jsbuilder/JS_AST/query/root_query_identidy.js +12 -0
  103. package/resources/jsbuilder/JS_AST_Node_Extended/JSGUI_Singular_Declaration.js +86 -0
  104. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Declaration.js +124 -0
  105. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended.js +88 -0
  106. package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended_0-Core.js +11 -0
  107. package/resources/jsbuilder/JS_Builder.js +10 -36
  108. package/resources/jsbuilder/JS_File/Feature/JS_File_Declared_Object.js +32 -0
  109. package/resources/jsbuilder/JS_File/Feature/JS_File_Exported_Object_Info.js +26 -0
  110. package/resources/jsbuilder/JS_File/Feature/JS_File_Exports.js +79 -0
  111. package/resources/jsbuilder/JS_File/Feature/JS_File_Feature.js +18 -0
  112. package/resources/jsbuilder/JS_File/Feature/JS_File_Imported_Object_Info.js +26 -0
  113. package/resources/jsbuilder/JS_File/Feature/JS_File_Imports.js +9 -0
  114. package/resources/jsbuilder/JS_File/JS_File.js +12 -0
  115. package/resources/jsbuilder/JS_File/JS_File_0-Core.js +202 -0
  116. package/resources/jsbuilder/JS_File/JS_File_1-Early_Parse.js +175 -0
  117. package/resources/jsbuilder/JS_File/JS_File_2-Babel.js +81 -0
  118. package/resources/jsbuilder/JS_File/JS_File_3-JS_AST_Node.js +86 -0
  119. package/resources/jsbuilder/JS_File/JS_File_4-Query.js +414 -0
  120. package/resources/jsbuilder/JS_File/JS_File_4.1-Query_Features.js +415 -0
  121. package/resources/jsbuilder/JS_File/JS_File_5-Planning.js +59 -0
  122. package/resources/jsbuilder/JS_File/JS_File_6-Changing.js +24 -0
  123. package/resources/jsbuilder/JS_File/JS_File_Export_Reference.js +12 -0
  124. package/resources/jsbuilder/JS_File/JS_File_Import_Reference.js +24 -0
  125. package/resources/jsbuilder/JS_File/JS_File_Import_References.js +32 -0
  126. package/resources/jsbuilder/JS_File/JS_File_Processor.js +16 -0
  127. package/resources/jsbuilder/JS_File/JS_Files.js +16 -0
  128. package/resources/jsbuilder/Module.js +14 -0
  129. package/resources/jsbuilder/Platform.js +13 -53
  130. package/resources/jsbuilder/Platforms.js +69 -15
  131. package/resources/jsbuilder/Project.js +109 -0
  132. package/resources/jsbuilder/Reference.js +1 -1
  133. package/resources/jsbuilder/Reference_Sequence.js +16 -7
  134. package/resources/jsbuilder/Scope.js +30 -0
  135. package/resources/jsbuilder/Variable_Name_Provider.js +43 -0
  136. package/resources/jsbuilder/_JS_File.js +226 -0
  137. package/resources/jsbuilder/ast_query.js +21 -0
  138. package/resources/jsbuilder/babel/babel_consts.js +150 -0
  139. package/resources/jsbuilder/babel/babel_node_tools.js +542 -0
  140. package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +604 -0
  141. package/resources/jsbuilder/build.js +16 -0
  142. package/resources/jsbuilder/platform_notes.md +66 -0
  143. package/resources/jsbuilder/test/test_ast_node.js +451 -0
  144. package/resources/jsbuilder/test/test_js_file.js +303 -11
  145. package/resources/jsbuilder/test/test_project.js +157 -0
  146. package/resources/local-server-info-resource.js +78 -78
  147. package/resources/process-js.js +537 -537
  148. package/resources/server-resource-pool.js +84 -84
  149. package/resources/website-css-resource.js +411 -411
  150. package/resources/website-javascript-resource.js +761 -751
  151. package/resources/website-resource.js +390 -390
  152. package/resources/website-static-html-resource.js +196 -196
  153. package/server.js +170 -170
  154. package/single-control-server.js +398 -398
  155. package/single-page-app.js +129 -129
  156. package/resources/jsbuilder/Declaration.js +0 -15
  157. package/resources/jsbuilder/Declaration_Sequence.js +0 -15
  158. package/resources/jsbuilder/JS_File.js +0 -77
package/package.json CHANGED
@@ -1,42 +1,44 @@
1
- {
2
- "name": "jsgui3-server",
3
- "main": "module.js",
4
- "license": "MIT",
5
- "dependencies": {
6
- "@babel/core": "^7.11.6",
7
- "babel-plugin-transform-runtime": "^6.23.0",
8
- "babel-preset-minify": "^0.5.1",
9
- "browserify": "14.5.0",
10
- "child-process": "^1.0.2",
11
- "cookies": "^0.7.3",
12
- "fnl": "^0.0.18",
13
- "fnlfs": "^0.0.20",
14
- "jsgui3-client": "^0.0.63",
15
- "jsgui3-html": "0.0.88",
16
- "lang-mini": "^0.0.18",
17
- "multiparty": "^4.2.2",
18
- "ncp": "^2.0.0",
19
- "obext": "0.0.18",
20
- "rimraf": "^2.7.1",
21
- "stream-to-array": "^2.3.0",
22
- "url-parse": "^1.4.7"
23
- },
24
- "commentDeps": {
25
- "babel-plugin-minify-dead-code-elimination": "^0.5.0",
26
- "babel-plugin-remove-comments": "^2.0.0",
27
- "babel-plugin-transform-class": "^0.3.0",
28
- "babel-plugin-transform-es2015-classes": "^6.24.1",
29
- "babel-plugin-transform-es2015-object-super": "^6.24.1",
30
- "iltorb": "^2.4.3"
31
- },
32
- "engines": {
33
- "node": ">=10.0.0"
34
- },
35
- "description": "ES6 JSGUI Server. Delivers the client to the browser.",
36
- "author": "James Vickers <james@metabench.com>",
37
- "repository": {
38
- "type": "git",
39
- "url": "https://github.com/metabench/jsgui3-server.git"
40
- },
41
- "version": "0.0.75"
42
- }
1
+ {
2
+ "name": "jsgui3-server",
3
+ "main": "module.js",
4
+ "license": "MIT",
5
+ "dependencies": {
6
+ "@babel/core": "^7.17.8",
7
+ "@babel/parser": "7.17.8",
8
+ "@babel/generator": "^7.17.7",
9
+ "babel-plugin-transform-runtime": "^6.23.0",
10
+ "babel-preset-minify": "^0.5.1",
11
+ "browserify": "17.0.0",
12
+ "child-process": "^1.0.2",
13
+ "cookies": "^0.8.0",
14
+ "fnl": "^0.0.20",
15
+ "fnlfs": "^0.0.22",
16
+ "jsgui3-client": "^0.0.63",
17
+ "jsgui3-html": "0.0.89",
18
+ "lang-mini": "^0.0.23",
19
+ "multiparty": "^4.2.3",
20
+ "ncp": "^2.0.0",
21
+ "obext": "0.0.19",
22
+ "rimraf": "^3.0.2",
23
+ "stream-to-array": "^2.3.0",
24
+ "url-parse": "^1.5.10"
25
+ },
26
+ "commentDeps": {
27
+ "babel-plugin-minify-dead-code-elimination": "^0.5.0",
28
+ "babel-plugin-remove-comments": "^2.0.0",
29
+ "babel-plugin-transform-class": "^0.3.0",
30
+ "babel-plugin-transform-es2015-classes": "^6.24.1",
31
+ "babel-plugin-transform-es2015-object-super": "^6.24.1",
32
+ "iltorb": "^2.4.3"
33
+ },
34
+ "engines": {
35
+ "node": ">=15.0.0"
36
+ },
37
+ "description": "ES6 JSGUI Server. Delivers the client to the browser.",
38
+ "author": "James Vickers <james@metabench.com>",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/metabench/jsgui3-server.git"
42
+ },
43
+ "version": "0.0.77"
44
+ }
@@ -1,203 +1,203 @@
1
- const jsgui = require('jsgui3-html');
2
- const {
3
- Evented_Class, tf
4
- } = jsgui;
5
-
6
- const {
7
- observable
8
- } = require('fnl');
9
-
10
- // May need a lot more work for flexibility and auth
11
- // Maybe can use middleware.
12
-
13
- // Websocket: the server should have some kind of websocket request amalgamator or router.
14
- // Only one wesocket connection should be open between each client and server.
15
- // May be worth leaving for the moment.
16
-
17
- // Websocket would be below the level of the publishers.
18
- // Need a unified ws api, but data available separately.
19
- // It would be a single comm channel unlike multiple HTTP requests.
20
-
21
- // Use some more general, lower level HTTP?
22
-
23
- class Function_Publisher {
24
- constructor(spec) {
25
- //let fn = this.fn = spec;
26
- // attach a spec to the function?
27
- // including a schema or params list for the fn?
28
- let fn;
29
- if (typeof spec === 'function') {
30
- fn = spec;
31
- } else {
32
- fn = spec.fn;
33
- if (spec.schema) {
34
- this.schema = spec.schema;
35
- } else {
36
- this.schema = {};
37
- }
38
- }
39
- this.type = 'function';
40
- //let fn = spec;
41
- //console.log('Function_Publisher constructor fn', fn);
42
- //console.log('Function_Publisher constructor fn', fn.toString());
43
-
44
- this.handle_http = (req, res) => {
45
- // need to handle observable http request.
46
- // Begin sending to that connection...
47
- // Following SSE would be nice.
48
-
49
- // Should check to see if it supports compression.
50
- // Compression function middleware could work fine here.
51
-
52
- // Will need to call the function with params.
53
- // Read params from content body?
54
-
55
- const {method, headers} = req;
56
-
57
- console.log('Function Publisher handle_http method', method);
58
- console.log('headers', headers);
59
-
60
- // Need to get the incoming parameters.
61
- // Need to use formidable or whatever else...?
62
-
63
- // Need to wait for the whole of the request to complete.
64
- // Don't think it will be multipart forms.
65
-
66
- const content_length = headers['content-length'];
67
- const content_type = headers['content-type'];
68
- // could be the mime type and the charset.
69
-
70
- // then need to wait for the whole thing.
71
- // think the req is a Readable_Stream.
72
-
73
- const chunks = [];
74
-
75
- req.on('data', data => {
76
- chunks.push(data);
77
- });
78
-
79
- req.on('end', () => {
80
- const buf_input = Buffer.concat(chunks);
81
- console.log('buf_input', buf_input);
82
-
83
- // then interpret it according to the content_type
84
- let obj_input;
85
-
86
- if (content_type.startsWith('text/plain')) {
87
- obj_input = buf_input.toString();
88
-
89
- } else {
90
-
91
- if (content_type === 'application/json') {
92
- obj_input = JSON.parse(buf_input.toString());
93
- } else {
94
- console.trace();
95
- throw 'NYI';
96
- }
97
- // decode / parse JSON.
98
- }
99
-
100
-
101
- const output_all = (call_res) => {
102
- // But not a buffer, string???
103
- // res is response.
104
- const tcr = tf(call_res);
105
-
106
- console.log('tcr', tcr);
107
-
108
- res.writeHead(200, {
109
- 'Content-Type': 'application/json'//,
110
- //'Transfer-Encoding': 'chunked',
111
- //'Trailer': 'Content-MD5'
112
- });
113
- res.end(JSON.stringify(call_res));
114
- }
115
-
116
-
117
- // And the function to call may be async.
118
- // Can test to see if we get a promise (or observable) back from it.
119
-
120
- const fn_res = fn(obj_input);
121
- const tfr = tf(fn_res);
122
-
123
- console.log('tfr', tfr);
124
-
125
- if (tfr === 'p') {
126
- // promise
127
- console.log('need to await promise resolution');
128
-
129
- fn_res.then(call_res => {
130
- console.log('fn_res then happened, call_res', call_res);
131
- output_all(call_res);
132
-
133
- }, err => {
134
-
135
- });
136
-
137
-
138
- } else {
139
-
140
- console.trace();
141
- throw 'NYI';
142
- }
143
-
144
-
145
-
146
-
147
-
148
- // turn it to string?
149
- // check its mime type?
150
-
151
- // however, likely we should have been told its application/json if that's the case.
152
- // likely will be the case for function calls.
153
-
154
- // the jsgui http post call....
155
- // should set the mime type where possible to intelligently do so.
156
-
157
-
158
-
159
-
160
- // may get some polymorphism out of the mime types.
161
- // text/plain;charset=UTF-8
162
- // turn it to a string.
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
- });
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
- /*
181
-
182
-
183
-
184
-
185
- */
186
-
187
-
188
-
189
- /*
190
- let obs2_handler = data => {
191
- //console.log('data', data);
192
- let s_data = JSON.stringify(data);
193
- //res.write(s_data + '\n');
194
- res.write('event: message\ndata:' + s_data + '\n\n');
195
- }
196
- obs2.on('next', obs2_handler);
197
- */
198
- }
199
- if (spec.schema) this.schema = spec.schema;
200
- }
201
- }
202
-
1
+ const jsgui = require('jsgui3-html');
2
+ const {
3
+ Evented_Class, tf
4
+ } = jsgui;
5
+
6
+ const {
7
+ observable
8
+ } = require('fnl');
9
+
10
+ // May need a lot more work for flexibility and auth
11
+ // Maybe can use middleware.
12
+
13
+ // Websocket: the server should have some kind of websocket request amalgamator or router.
14
+ // Only one wesocket connection should be open between each client and server.
15
+ // May be worth leaving for the moment.
16
+
17
+ // Websocket would be below the level of the publishers.
18
+ // Need a unified ws api, but data available separately.
19
+ // It would be a single comm channel unlike multiple HTTP requests.
20
+
21
+ // Use some more general, lower level HTTP?
22
+
23
+ class Function_Publisher {
24
+ constructor(spec) {
25
+ //let fn = this.fn = spec;
26
+ // attach a spec to the function?
27
+ // including a schema or params list for the fn?
28
+ let fn;
29
+ if (typeof spec === 'function') {
30
+ fn = spec;
31
+ } else {
32
+ fn = spec.fn;
33
+ if (spec.schema) {
34
+ this.schema = spec.schema;
35
+ } else {
36
+ this.schema = {};
37
+ }
38
+ }
39
+ this.type = 'function';
40
+ //let fn = spec;
41
+ //console.log('Function_Publisher constructor fn', fn);
42
+ //console.log('Function_Publisher constructor fn', fn.toString());
43
+
44
+ this.handle_http = (req, res) => {
45
+ // need to handle observable http request.
46
+ // Begin sending to that connection...
47
+ // Following SSE would be nice.
48
+
49
+ // Should check to see if it supports compression.
50
+ // Compression function middleware could work fine here.
51
+
52
+ // Will need to call the function with params.
53
+ // Read params from content body?
54
+
55
+ const {method, headers} = req;
56
+
57
+ console.log('Function Publisher handle_http method', method);
58
+ console.log('headers', headers);
59
+
60
+ // Need to get the incoming parameters.
61
+ // Need to use formidable or whatever else...?
62
+
63
+ // Need to wait for the whole of the request to complete.
64
+ // Don't think it will be multipart forms.
65
+
66
+ const content_length = headers['content-length'];
67
+ const content_type = headers['content-type'];
68
+ // could be the mime type and the charset.
69
+
70
+ // then need to wait for the whole thing.
71
+ // think the req is a Readable_Stream.
72
+
73
+ const chunks = [];
74
+
75
+ req.on('data', data => {
76
+ chunks.push(data);
77
+ });
78
+
79
+ req.on('end', () => {
80
+ const buf_input = Buffer.concat(chunks);
81
+ console.log('buf_input', buf_input);
82
+
83
+ // then interpret it according to the content_type
84
+ let obj_input;
85
+
86
+ if (content_type.startsWith('text/plain')) {
87
+ obj_input = buf_input.toString();
88
+
89
+ } else {
90
+
91
+ if (content_type === 'application/json') {
92
+ obj_input = JSON.parse(buf_input.toString());
93
+ } else {
94
+ console.trace();
95
+ throw 'NYI';
96
+ }
97
+ // decode / parse JSON.
98
+ }
99
+
100
+
101
+ const output_all = (call_res) => {
102
+ // But not a buffer, string???
103
+ // res is response.
104
+ const tcr = tf(call_res);
105
+
106
+ console.log('tcr', tcr);
107
+
108
+ res.writeHead(200, {
109
+ 'Content-Type': 'application/json'//,
110
+ //'Transfer-Encoding': 'chunked',
111
+ //'Trailer': 'Content-MD5'
112
+ });
113
+ res.end(JSON.stringify(call_res));
114
+ }
115
+
116
+
117
+ // And the function to call may be async.
118
+ // Can test to see if we get a promise (or observable) back from it.
119
+
120
+ const fn_res = fn(obj_input);
121
+ const tfr = tf(fn_res);
122
+
123
+ console.log('tfr', tfr);
124
+
125
+ if (tfr === 'p') {
126
+ // promise
127
+ console.log('need to await promise resolution');
128
+
129
+ fn_res.then(call_res => {
130
+ console.log('fn_res then happened, call_res', call_res);
131
+ output_all(call_res);
132
+
133
+ }, err => {
134
+
135
+ });
136
+
137
+
138
+ } else {
139
+
140
+ console.trace();
141
+ throw 'NYI';
142
+ }
143
+
144
+
145
+
146
+
147
+
148
+ // turn it to string?
149
+ // check its mime type?
150
+
151
+ // however, likely we should have been told its application/json if that's the case.
152
+ // likely will be the case for function calls.
153
+
154
+ // the jsgui http post call....
155
+ // should set the mime type where possible to intelligently do so.
156
+
157
+
158
+
159
+
160
+ // may get some polymorphism out of the mime types.
161
+ // text/plain;charset=UTF-8
162
+ // turn it to a string.
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+ });
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+ /*
181
+
182
+
183
+
184
+
185
+ */
186
+
187
+
188
+
189
+ /*
190
+ let obs2_handler = data => {
191
+ //console.log('data', data);
192
+ let s_data = JSON.stringify(data);
193
+ //res.write(s_data + '\n');
194
+ res.write('event: message\ndata:' + s_data + '\n\n');
195
+ }
196
+ obs2.on('next', obs2_handler);
197
+ */
198
+ }
199
+ if (spec.schema) this.schema = spec.schema;
200
+ }
201
+ }
202
+
203
203
  module.exports = Function_Publisher;
@@ -1,5 +1,5 @@
1
- Function publishing, and some other sorts of publishing, should maybe be contained in another module / set of modules.
2
- May need to work without all the HTML and Control things for some applications.
3
-
4
-
5
-
1
+ Function publishing, and some other sorts of publishing, should maybe be contained in another module / set of modules.
2
+ May need to work without all the HTML and Control things for some applications.
3
+
4
+
5
+