jsgui3-server 0.0.73 → 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.
- package/examples/client-side-popup-menu-button.html +93 -93
- package/examples/controls/_html-server-color-palette.js +114 -114
- package/examples/controls/html-server-combo-box.js +104 -104
- package/examples/controls/html-server-list.js +98 -98
- package/examples/controls/html-server-popup-menu-button.js +114 -114
- package/examples/controls/html-server-start-stop-toggle-button.js +146 -146
- package/examples/controls/scs-arrow-button.js +36 -36
- package/examples/controls/scs-date-picker.js +157 -157
- package/examples/controls/scs-file-browser.js +82 -82
- package/examples/controls/scs-item.js +159 -159
- package/examples/controls/scs-month-arrow-selector.js +126 -126
- package/examples/controls/scs-month-view.js +95 -95
- package/examples/controls/scs-start-stop-toggle-button.js +40 -40
- package/examples/controls/scs-tree.js +49 -49
- package/examples/controls/scs-year-arrow-selector.js +127 -127
- package/examples/demos/date-picker.js +119 -119
- package/examples/demos/explain-encapsulation.js +9 -9
- package/examples/demos/resizing.js +35 -35
- package/examples/demos/server_time.js +6 -6
- package/examples/demos/square_box.js +324 -324
- package/examples/html-rendering.js +20 -20
- package/examples/html-server.js +100 -100
- package/fs2.js +1836 -1836
- package/module.js +21 -21
- package/old/single-control-server.js +418 -418
- package/package.json +44 -42
- package/publishing/function-publisher.js +202 -202
- package/publishing/notes.md +5 -5
- package/publishing/observable-publisher.js +118 -118
- package/publishing/resource-publisher.js +306 -306
- package/resources/data-resource.js +104 -104
- package/resources/fs-resource.js +148 -148
- package/resources/jsbuilder/Abstract_Single_Declaration.js +105 -0
- package/resources/jsbuilder/Abstract_Single_Declaration_Sequence.js +43 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node.js +62 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node_Group.js +42 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Group_Shared.js +62 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node.js +94 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +228 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_1-Babel.js +338 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_10-Changing.js +40 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.1-Child.js +97 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.2-Parent.js +38 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.3-Ancestor.js +62 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.2-Inner.js +44 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.3-All.js +73 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.4-Sibling.js +93 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.5-Available_In_Scope.js +29 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.9-Signature.js +116 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3-Basics.js +160 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.0-Basics_First.js +179 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.1-Basics_Second.js +88 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.99-Basics_Last.js +92 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1-Basics_Each.js +137 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1.5-Basics_Count.js +74 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.2-Basics_Filter.js +40 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.3-Basics_Collect.js +86 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.4-Basics_Select.js +43 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.5-Basics_Find.js +41 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.6-Basics_Callmap.js +55 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_4.0-Index_Indexes.js +46 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_4.1-Index.js +344 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.0-Category.js +39 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.1-Category_Identifier.js +31 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.2-Category_Literal.js +29 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.3-Category_Expression.js +27 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.4-Category_Pattern.js +9 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.5-Category_Declaration.js +44 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.6-Category_Statement.js +22 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.0-Type.js +87 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.1-Type_Class_Declaration.js +9 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.2-Type_Variable_Declaration.js +28 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.3-Type_Variable_Declarator.js +29 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_7-Query.js +737 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_8-Features.js +65 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_9-Planning.js +32 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Arrangement.js +15 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Declared_Object.js +306 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature.js +78 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declaration.js +249 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declarator.js +139 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature.js +10 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exported.js +101 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exports.js +61 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Interpreted.js +180 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/_JSGUI_Root_Node_Interpreted.js +43 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/special_case_objectassign_to_object.js +12 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Group.js +35 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Operation.js +11 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Operation_On_Relationship.js +32 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Ordered_Relationship_Node_To_Group.js +38 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Ordinal.js +40 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Ordinal_Relationship.js +25 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_To_Group.js +201 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_Within_Group_To_Node.js +44 -0
- package/resources/jsbuilder/JS_AST/_JS_AST_Node_3.8-Query_Features.js +77 -0
- package/resources/jsbuilder/JS_AST/query/all.js +0 -0
- package/resources/jsbuilder/JS_AST/query/enable_array_as_queryable.js +228 -0
- package/resources/jsbuilder/JS_AST/query/find_object_keys.js +405 -0
- package/resources/jsbuilder/JS_AST/query/node_queries.js +9 -0
- package/resources/jsbuilder/JS_AST/query/root_queries.js +0 -0
- package/resources/jsbuilder/JS_AST/query/root_query_identidy.js +12 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JSGUI_Singular_Declaration.js +86 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Declaration.js +124 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended.js +88 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended_0-Core.js +11 -0
- package/resources/jsbuilder/JS_Builder.js +11 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Declared_Object.js +32 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Exported_Object_Info.js +26 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Exports.js +79 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Feature.js +18 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Imported_Object_Info.js +26 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Imports.js +9 -0
- package/resources/jsbuilder/JS_File/JS_File.js +12 -0
- package/resources/jsbuilder/JS_File/JS_File_0-Core.js +202 -0
- package/resources/jsbuilder/JS_File/JS_File_1-Early_Parse.js +175 -0
- package/resources/jsbuilder/JS_File/JS_File_2-Babel.js +81 -0
- package/resources/jsbuilder/JS_File/JS_File_3-JS_AST_Node.js +86 -0
- package/resources/jsbuilder/JS_File/JS_File_4-Query.js +414 -0
- package/resources/jsbuilder/JS_File/JS_File_4.1-Query_Features.js +415 -0
- package/resources/jsbuilder/JS_File/JS_File_5-Planning.js +59 -0
- package/resources/jsbuilder/JS_File/JS_File_6-Changing.js +24 -0
- package/resources/jsbuilder/JS_File/JS_File_Export_Reference.js +12 -0
- package/resources/jsbuilder/JS_File/JS_File_Import_Reference.js +24 -0
- package/resources/jsbuilder/JS_File/JS_File_Import_References.js +32 -0
- package/resources/jsbuilder/JS_File/JS_File_Processor.js +16 -0
- package/resources/jsbuilder/JS_File/JS_Files.js +16 -0
- package/resources/jsbuilder/Module.js +14 -0
- package/resources/jsbuilder/Platform.js +14 -0
- package/resources/jsbuilder/Platforms.js +70 -0
- package/resources/jsbuilder/Project.js +109 -0
- package/resources/jsbuilder/Reference.js +1 -0
- package/resources/jsbuilder/Reference_Sequence.js +16 -0
- package/resources/jsbuilder/Scope.js +30 -0
- package/resources/jsbuilder/Variable_Name_Provider.js +43 -0
- package/resources/jsbuilder/_JS_File.js +226 -0
- package/resources/jsbuilder/ast_query.js +21 -0
- package/resources/jsbuilder/babel/babel_consts.js +150 -0
- package/resources/jsbuilder/babel/babel_node_tools.js +542 -0
- package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +604 -0
- package/resources/jsbuilder/build.js +16 -0
- package/resources/jsbuilder/platform_notes.md +66 -0
- package/resources/jsbuilder/test/test_ast_node.js +451 -0
- package/resources/jsbuilder/test/test_js_file.js +304 -0
- package/resources/jsbuilder/test/test_project.js +157 -0
- package/resources/local-server-info-resource.js +78 -78
- package/resources/process-js.js +537 -537
- package/resources/server-resource-pool.js +84 -84
- package/resources/website-css-resource.js +411 -411
- package/resources/website-javascript-resource.js +761 -1347
- package/resources/website-resource.js +390 -797
- package/resources/website-static-html-resource.js +196 -196
- package/server.js +170 -170
- package/single-control-server.js +398 -398
- package/single-page-app.js +129 -129
|
@@ -1,797 +1,390 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by James on 29/07/2014.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// Want to get the core resources working and tested.
|
|
6
|
-
// Want to run a clock website / service to start with.
|
|
7
|
-
// The server could have a clock, while clients could connect to it and share the information.
|
|
8
|
-
// Could also experiment with P2P distribution of the data.
|
|
9
|
-
// A clock is also useful because it contains time signals so we can see how long it takes for data to reach various machines.
|
|
10
|
-
|
|
11
|
-
// A web resource in particular?
|
|
12
|
-
// Any need for an HTML resource?
|
|
13
|
-
// Probably not - have web resource handle HTML and websockets.
|
|
14
|
-
|
|
15
|
-
// Resources could also have events which objects can listen to.
|
|
16
|
-
// Programmatic objects can listen.
|
|
17
|
-
// The resources may broadcast to whatever is listening.
|
|
18
|
-
|
|
19
|
-
// Also, maintaining one connection stream, communicating with multiple resources - could connect through a Resource Pool, or maybe there
|
|
20
|
-
// could be a Multi Resource Publisher that publishes a bunch of resources.
|
|
21
|
-
|
|
22
|
-
// The Application router at the moment sending requests to resources.
|
|
23
|
-
// I am thinking that rather than doing that, the requests should be handled by a resource publisher that interacts with the resource and publishes it over HTTP.
|
|
24
|
-
|
|
25
|
-
// Resources in general won't handle HTTP requests, though they will have the capability.
|
|
26
|
-
// More likely that a resource, when it is served online, will be served using a Resource Publisher (which is itself a resource), which handles HTTP implementation details that would otherwise have
|
|
27
|
-
// to be repeated between resources.
|
|
28
|
-
|
|
29
|
-
//define(["./jsgui-lang-util", './abstract-resource'], function(jsgui, AR) {
|
|
30
|
-
|
|
31
|
-
// Do this not with AMD?
|
|
32
|
-
|
|
33
|
-
// May need Website_Data_Resource
|
|
34
|
-
// Would be configured within the node app, client has maximum autoconfig from connecting to the server, and integration with client-side controls.
|
|
35
|
-
// With the DB admin, it's about returining queries (maybe from RAM) about table data.
|
|
36
|
-
// /data/then the api?
|
|
37
|
-
|
|
38
|
-
// Respond to both data HTTP requests and websocket connections.
|
|
39
|
-
|
|
40
|
-
// HTTP data request -> response seems like the most important step now.
|
|
41
|
-
|
|
42
|
-
// An fs Resource would be of use for file system browser.
|
|
43
|
-
// Could have a client-side fs resource that connects to a veriety of services, could have one that connects to the server-side fs resource.
|
|
44
|
-
|
|
45
|
-
// Need to connect a data-providing resource to the UI component in cases where it's not secure to do so automatically.
|
|
46
|
-
// 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
|
-
//
|
|
48
|
-
|
|
49
|
-
var Site_Images = require("./website-image-resource");
|
|
50
|
-
|
|
51
|
-
//console.log('1) Site_Images', Site_Images);
|
|
52
|
-
|
|
53
|
-
var jsgui = require("jsgui3-html");
|
|
54
|
-
const { each, get_a_sig, is_defined, tof } = jsgui;
|
|
55
|
-
|
|
56
|
-
//var Web_Resource = require('./website-resource');
|
|
57
|
-
const Resource = jsgui.Resource;
|
|
58
|
-
const Router = jsgui.Router;
|
|
59
|
-
const Evented_Class = jsgui.Evented_Class;
|
|
60
|
-
|
|
61
|
-
var Resource_Pool = require("./server-resource-pool");
|
|
62
|
-
//var Resource_Web_Admin = require('../web-admin');
|
|
63
|
-
|
|
64
|
-
var Site_JavaScript = require("./website-javascript-resource");
|
|
65
|
-
//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");
|
|
68
|
-
//var DB_Web_Resource = require('../../web/db-resource-postgres');
|
|
69
|
-
//var database_resource_factory = require('../../db/resource/factory');
|
|
70
|
-
|
|
71
|
-
const Resource_Publisher = require("../publishing/resource-publisher");
|
|
72
|
-
const Observable_Publisher = require("../publishing/observable-publisher");
|
|
73
|
-
const Function_Publisher = require("../publishing/function-publisher");
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
var
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
//
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
//
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
// Publishing functions / being able to do so, not under the /resources/ path makes a lot of sense.
|
|
393
|
-
// Intuitively a website arch may not need the /resources/ path.
|
|
394
|
-
// Be able to set a custom path / route.
|
|
395
|
-
|
|
396
|
-
// A publisher could create a request handler function?
|
|
397
|
-
|
|
398
|
-
// resources maybe will not be set under /resources/.
|
|
399
|
-
// worth keeping as a default?
|
|
400
|
-
// does make sense unless a 'path' is specified in the options.
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
// keep this for the moment...
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
router.set_route("resources/:resource_name/*", this, (req, res) => {
|
|
411
|
-
//console.log('website router routing resource request');
|
|
412
|
-
//console.log('route_data.params', req.params);
|
|
413
|
-
//let resource_name = req.params.resource_name;
|
|
414
|
-
//console.log('resource_name', resource_name);
|
|
415
|
-
//console.log('req', req);
|
|
416
|
-
let { url, method } = req;
|
|
417
|
-
let s_url = url.split("/");
|
|
418
|
-
//console.log('s_url', s_url);
|
|
419
|
-
let resource_short_name = s_url[2];
|
|
420
|
-
//console.log('resource_short_name', resource_short_name);
|
|
421
|
-
//console.log('Object.keys(req)', Object.keys(req));
|
|
422
|
-
//console.log('req.params', req.params);
|
|
423
|
-
//console.log('url, method', url, method);
|
|
424
|
-
//console.log('resource_name', resource_name);
|
|
425
|
-
// consult the map of published resources
|
|
426
|
-
// or supposed to be encapsulated
|
|
427
|
-
// That is the server resource pool.
|
|
428
|
-
//console.log('this.pool', this.pool);
|
|
429
|
-
// Route it to a server resource?
|
|
430
|
-
|
|
431
|
-
//console.log('Object.keys(this.map_resource_publishers)', Object.keys(this.map_resource_publishers));
|
|
432
|
-
//console.log('this', this);
|
|
433
|
-
|
|
434
|
-
let resource_publisher = this.map_resource_publishers[resource_short_name];
|
|
435
|
-
//console.log('1) this', this);
|
|
436
|
-
//console.log('1) that', that);
|
|
437
|
-
// that
|
|
438
|
-
//console.log('this.map_resource_publishers', that.map_resource_publishers);
|
|
439
|
-
//console.log('!!resource_publisher', !!resource_publisher);
|
|
440
|
-
//console.trace();
|
|
441
|
-
|
|
442
|
-
if (resource_publisher) {
|
|
443
|
-
resource_publisher.handle_http(req, res);
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
|
-
// The website (admin) resource will make use of the images resource where necessary.
|
|
447
|
-
// The website (admin) resource will be able to get the images resource from the resource pool.
|
|
448
|
-
//router.set_route('admin/*', admin_web_resource, admin_web_resource.process);
|
|
449
|
-
/*
|
|
450
|
-
resource_pool.push(new Site_Images({
|
|
451
|
-
'meta': {
|
|
452
|
-
'name': 'Site Images'
|
|
453
|
-
}
|
|
454
|
-
}));
|
|
455
|
-
*/
|
|
456
|
-
// set up the routes.
|
|
457
|
-
if (!is_defined(spec)) spec = {};
|
|
458
|
-
//console.log('pre super');
|
|
459
|
-
//Web_Resource.prototype.init.call(this, spec);
|
|
460
|
-
//this.router = router;
|
|
461
|
-
this.resource_pool = resource_pool;
|
|
462
|
-
//this.set('router', router);
|
|
463
|
-
//this.set('resource_pool', resource_pool);
|
|
464
|
-
// Super call was not working for some reason.
|
|
465
|
-
//this._super(spec);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
publishing_get_pub(item) {
|
|
469
|
-
// don't need to name it?
|
|
470
|
-
// name could already be included in item.
|
|
471
|
-
|
|
472
|
-
let pub;
|
|
473
|
-
if (item instanceof jsgui.Resource) {
|
|
474
|
-
pub = new Resource_Publisher({
|
|
475
|
-
resource: item
|
|
476
|
-
});
|
|
477
|
-
//this.map_resource_publishers[published_name] = resource_publisher;
|
|
478
|
-
|
|
479
|
-
//item.name = item.name || published_name;
|
|
480
|
-
// add that resource!
|
|
481
|
-
// (to the pool?)
|
|
482
|
-
//console.log('item', item);
|
|
483
|
-
//this.resource_pool.add(item);
|
|
484
|
-
|
|
485
|
-
//console.log('Object.keys(this.map_resource_publishers)', Object.keys(this.map_resource_publishers));
|
|
486
|
-
} else {
|
|
487
|
-
// if its a function
|
|
488
|
-
// return that function call to the response.
|
|
489
|
-
let t_item = typeof item;
|
|
490
|
-
if (t_item === "function") {
|
|
491
|
-
// Function_Call_Publisher
|
|
492
|
-
// could respec this.
|
|
493
|
-
// And the Function_Publisher operates through the Publisher API. Not sure what that is right now though.
|
|
494
|
-
|
|
495
|
-
pub = new Function_Publisher({
|
|
496
|
-
fn: item
|
|
497
|
-
});
|
|
498
|
-
//this.map_resource_publishers[published_name] = pub;
|
|
499
|
-
//
|
|
500
|
-
} else {
|
|
501
|
-
if (item.next && item.complete && item.error) {
|
|
502
|
-
// assuming observable
|
|
503
|
-
// Observable publisher
|
|
504
|
-
// One way sending...
|
|
505
|
-
//console.log('using Observable_Publisher');
|
|
506
|
-
pub = new Observable_Publisher({
|
|
507
|
-
obs: item
|
|
508
|
-
});
|
|
509
|
-
// or not a resource publisher, an observable publisher.
|
|
510
|
-
//this.map_resource_publishers = this.map_resource_publishers || {};
|
|
511
|
-
//this.map_resource_publishers[published_name] = obs_pub;
|
|
512
|
-
|
|
513
|
-
//console.log('2) this', this);
|
|
514
|
-
//console.log('this.map_resource_publishers', this.map_resource_publishers);
|
|
515
|
-
//console.trace();
|
|
516
|
-
} else {
|
|
517
|
-
console.log("item", item);
|
|
518
|
-
throw "Unrecognised item type. Possibly node module versions are wrong / have not been linked fully.";
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
//if (item instanceof Evented_Class) {
|
|
522
|
-
}
|
|
523
|
-
return pub;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
// publish within resources?
|
|
530
|
-
publish(published_name, item, schema) {
|
|
531
|
-
|
|
532
|
-
// more sig matching where we check for a path?
|
|
533
|
-
// use of an options object?
|
|
534
|
-
|
|
535
|
-
// worth parsing the signature, looking for specific things.
|
|
536
|
-
// likely could save some space and make the function clearer.
|
|
537
|
-
|
|
538
|
-
// and automatically publishing the function schema / api, if the function is made with mfp etc?
|
|
539
|
-
// not for the moment...?
|
|
540
|
-
|
|
541
|
-
// or assign its full params.
|
|
542
|
-
|
|
543
|
-
// an options object?
|
|
544
|
-
// path, (name?), item
|
|
545
|
-
|
|
546
|
-
// ofp applying as plural using multiple keys and values from the options object
|
|
547
|
-
// not yet. that would be a way of calling the single function.
|
|
548
|
-
|
|
549
|
-
// allowing it to take an options object would be very useful.
|
|
550
|
-
// specifying the name as well as the path?
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
// Want to be able to (optionally) choose the full path its published under.
|
|
555
|
-
// Not (only) published under /resources/name.
|
|
556
|
-
// More flexibility in creation of the website / service API / structure.
|
|
557
|
-
|
|
558
|
-
// single and multi
|
|
559
|
-
// effectively like arrayify or mapify
|
|
560
|
-
// 1 or multiple args
|
|
561
|
-
// string, whatever
|
|
562
|
-
// Including published info within the HTML document?
|
|
563
|
-
// Could go there as a comment.
|
|
564
|
-
// A hidden control may work well.
|
|
565
|
-
// Just as a jsgui property would be fine.
|
|
566
|
-
// Automatic wiring of the services / publishers so that they are available on the client without requiring further plumbing.
|
|
567
|
-
|
|
568
|
-
let sig = get_a_sig(arguments),
|
|
569
|
-
a = arguments,
|
|
570
|
-
l = a.length;
|
|
571
|
-
|
|
572
|
-
//console.log("a", a);
|
|
573
|
-
//console.log("sig", sig);
|
|
574
|
-
//console.log("l", l);
|
|
575
|
-
//throw 'stop';
|
|
576
|
-
|
|
577
|
-
// could use mfp, ofp etc.
|
|
578
|
-
|
|
579
|
-
const single = (published_name, item) => {
|
|
580
|
-
|
|
581
|
-
// option of
|
|
582
|
-
|
|
583
|
-
//console.log("Website_Resource publish", published_name);
|
|
584
|
-
//console.log('published_name, item', published_name, item);
|
|
585
|
-
//this.map_resource_publishers = this.map_resource_publishers || {};
|
|
586
|
-
// .__resource ?
|
|
587
|
-
// instanceof means same version?
|
|
588
|
-
if (item instanceof jsgui.Resource) {
|
|
589
|
-
let resource_publisher = new Resource_Publisher({
|
|
590
|
-
resource: item,
|
|
591
|
-
name: published_name
|
|
592
|
-
});
|
|
593
|
-
this.map_resource_publishers[published_name] = resource_publisher;
|
|
594
|
-
|
|
595
|
-
item.name = item.name || published_name;
|
|
596
|
-
// add that resource!
|
|
597
|
-
// (to the pool?)
|
|
598
|
-
//console.log('item', item);
|
|
599
|
-
this.resource_pool.add(item);
|
|
600
|
-
|
|
601
|
-
//console.log('Object.keys(this.map_resource_publishers)', Object.keys(this.map_resource_publishers));
|
|
602
|
-
} else {
|
|
603
|
-
// if its a function
|
|
604
|
-
// return that function call to the response.
|
|
605
|
-
let t_item = typeof item;
|
|
606
|
-
if (t_item === "function") {
|
|
607
|
-
// Function_Call_Publisher
|
|
608
|
-
// could respec this.
|
|
609
|
-
|
|
610
|
-
// And the Function_Publisher operates through the Publisher API. Not sure what that is right now though.
|
|
611
|
-
// directly attaching the resource publishers?
|
|
612
|
-
let pub = new Function_Publisher({
|
|
613
|
-
fn: item,
|
|
614
|
-
schema: schema
|
|
615
|
-
});
|
|
616
|
-
this.map_resource_publishers[published_name] = pub;
|
|
617
|
-
//
|
|
618
|
-
|
|
619
|
-
} else {
|
|
620
|
-
if (item.next && item.complete && item.error) {
|
|
621
|
-
// assuming observable
|
|
622
|
-
// Observable publisher
|
|
623
|
-
// One way sending...
|
|
624
|
-
//console.log('using Observable_Publisher');
|
|
625
|
-
let obs_pub = new Observable_Publisher({
|
|
626
|
-
obs: item,
|
|
627
|
-
schema: schema
|
|
628
|
-
});
|
|
629
|
-
// or not a resource publisher, an observable publisher.
|
|
630
|
-
//this.map_resource_publishers = this.map_resource_publishers || {};
|
|
631
|
-
this.map_resource_publishers[published_name] = obs_pub;
|
|
632
|
-
|
|
633
|
-
//console.log('2) this', this);
|
|
634
|
-
//console.log('this.map_resource_publishers', this.map_resource_publishers);
|
|
635
|
-
//console.trace();
|
|
636
|
-
} else {
|
|
637
|
-
console.log("item", item);
|
|
638
|
-
throw "Unrecognised item type. Possibly node module versions are wrong / have not been linked fully.";
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
//if (item instanceof Evented_Class) {
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
// Need to give it a name to publish it as
|
|
645
|
-
|
|
646
|
-
// server needs a Resource_Publisher.
|
|
647
|
-
// Some resources include their own publishing.
|
|
648
|
-
// (existing things like javascript-resource)
|
|
649
|
-
|
|
650
|
-
// needs a name
|
|
651
|
-
|
|
652
|
-
//this.resource_publisher = this.resource_publisher || new Resource_Publisher({
|
|
653
|
-
|
|
654
|
-
//this.resource_pool.map_resource_publishers = resource_publisher;
|
|
655
|
-
|
|
656
|
-
// website resource needs the map of resource publishers.
|
|
657
|
-
|
|
658
|
-
// Should actually publish within a Website_Resource...
|
|
659
|
-
// Server holds this.
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
if (sig === "[o]") {
|
|
663
|
-
each(a[0], (v, i) => {
|
|
664
|
-
single(i, v);
|
|
665
|
-
})
|
|
666
|
-
} else {
|
|
667
|
-
|
|
668
|
-
single(published_name, item);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
get resource_names() {
|
|
673
|
-
//console.log('this.resource_pool', this.resource_pool);
|
|
674
|
-
return this.resource_pool.resource_names;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
get_resource(resource_name) {
|
|
678
|
-
var resource_pool = this.resource_pool;
|
|
679
|
-
//console.log('resource_pool', resource_pool);
|
|
680
|
-
|
|
681
|
-
//console.log('this._.resource_pool', this._.resource_pool);
|
|
682
|
-
|
|
683
|
-
//throw 'stop';
|
|
684
|
-
return resource_pool.get_resource(resource_name);
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
get def_resource_publishers() {
|
|
688
|
-
const res = {};
|
|
689
|
-
each(this.map_resource_publishers, (rp, name) => {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
//console.log('name', name);
|
|
694
|
-
//console.log('rp', rp);
|
|
695
|
-
let def = {
|
|
696
|
-
name: name,
|
|
697
|
-
type: rp.type
|
|
698
|
-
}
|
|
699
|
-
res[name] = def;
|
|
700
|
-
if (rp.type === 'function') {
|
|
701
|
-
if (rp.schema) def.schema = rp.schema;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
/*
|
|
705
|
-
if (rp.type === 'function') {
|
|
706
|
-
|
|
707
|
-
}
|
|
708
|
-
if (rp.type === 'observable') {
|
|
709
|
-
|
|
710
|
-
}
|
|
711
|
-
*/
|
|
712
|
-
|
|
713
|
-
// look up the def of each of the resource publishers.
|
|
714
|
-
// could include a little schema with each of the functions to be published.
|
|
715
|
-
// the observable publisher responds to the observable events.
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
})
|
|
721
|
-
|
|
722
|
-
return res;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
start(callback) {
|
|
726
|
-
// Need to wait until the database has started.
|
|
727
|
-
//console.log('Website Resource start');
|
|
728
|
-
// start the db / web db resources?
|
|
729
|
-
// start the resource pool?
|
|
730
|
-
var resource_pool = this.resource_pool;
|
|
731
|
-
resource_pool.start(callback);
|
|
732
|
-
//callback(null, true);
|
|
733
|
-
|
|
734
|
-
// needs various other resources to have started.
|
|
735
|
-
|
|
736
|
-
// check the requirements
|
|
737
|
-
|
|
738
|
-
// check requirements recursive - checks the requirements of everything required, and if they have the check_requirements function, it uses that.
|
|
739
|
-
// I think using the system of names APIs will help here.
|
|
740
|
-
|
|
741
|
-
// The web db resource needs to have been started.
|
|
742
|
-
|
|
743
|
-
//throw 'no start function defined for web resource (subclass)'
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
meets_requirements() {
|
|
747
|
-
// Likely will be part of Status
|
|
748
|
-
|
|
749
|
-
//return false;
|
|
750
|
-
|
|
751
|
-
return true;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
// Needs to be able to process HTTP requests. A bit like the Router in that way.
|
|
755
|
-
process(req, res) {
|
|
756
|
-
//console.log('website process request req.url', req.url);
|
|
757
|
-
//throw 'stop';
|
|
758
|
-
|
|
759
|
-
var remoteAddress = req.connection.remoteAddress;
|
|
760
|
-
var router = this.router;
|
|
761
|
-
var res_process = router.process(req, res);
|
|
762
|
-
if (res_process === false) {
|
|
763
|
-
// Perhaps it's one of the static HTML files?
|
|
764
|
-
// Could try to process it using static HTML?
|
|
765
|
-
// Or an internal change / proxy from / to /index.html
|
|
766
|
-
|
|
767
|
-
// These will possibly be base level page requests, just looking for the file on disk and serving it.
|
|
768
|
-
|
|
769
|
-
// At this point we hand it off to the static HTML processor.
|
|
770
|
-
// Need some more root directory level handling, but the main processing system is about setting up paths and dealing with parameters.
|
|
771
|
-
//
|
|
772
|
-
// Special case of '/'
|
|
773
|
-
|
|
774
|
-
if (req.url === "/") {
|
|
775
|
-
// Send this to the static HTML processing system.
|
|
776
|
-
|
|
777
|
-
var static_html_resource = this.resource_pool.get_resource(
|
|
778
|
-
"Static HTML"
|
|
779
|
-
);
|
|
780
|
-
//console.log('static_html_resource', static_html_resource);
|
|
781
|
-
// And lets get the static resource to process it
|
|
782
|
-
if (static_html_resource) {
|
|
783
|
-
static_html_resource.process(req, res);
|
|
784
|
-
}
|
|
785
|
-
} else {
|
|
786
|
-
// show a 404
|
|
787
|
-
res.writeHead(404, {
|
|
788
|
-
"Content-Type": "text/plain"
|
|
789
|
-
});
|
|
790
|
-
res.write("404 Not Found\n");
|
|
791
|
-
res.end();
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
module.exports = Website_Resource;
|
|
1
|
+
/**
|
|
2
|
+
* Created by James on 29/07/2014.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Want to get the core resources working and tested.
|
|
6
|
+
// Want to run a clock website / service to start with.
|
|
7
|
+
// The server could have a clock, while clients could connect to it and share the information.
|
|
8
|
+
// Could also experiment with P2P distribution of the data.
|
|
9
|
+
// A clock is also useful because it contains time signals so we can see how long it takes for data to reach various machines.
|
|
10
|
+
|
|
11
|
+
// A web resource in particular?
|
|
12
|
+
// Any need for an HTML resource?
|
|
13
|
+
// Probably not - have web resource handle HTML and websockets.
|
|
14
|
+
|
|
15
|
+
// Resources could also have events which objects can listen to.
|
|
16
|
+
// Programmatic objects can listen.
|
|
17
|
+
// The resources may broadcast to whatever is listening.
|
|
18
|
+
|
|
19
|
+
// Also, maintaining one connection stream, communicating with multiple resources - could connect through a Resource Pool, or maybe there
|
|
20
|
+
// could be a Multi Resource Publisher that publishes a bunch of resources.
|
|
21
|
+
|
|
22
|
+
// The Application router at the moment sending requests to resources.
|
|
23
|
+
// I am thinking that rather than doing that, the requests should be handled by a resource publisher that interacts with the resource and publishes it over HTTP.
|
|
24
|
+
|
|
25
|
+
// Resources in general won't handle HTTP requests, though they will have the capability.
|
|
26
|
+
// More likely that a resource, when it is served online, will be served using a Resource Publisher (which is itself a resource), which handles HTTP implementation details that would otherwise have
|
|
27
|
+
// to be repeated between resources.
|
|
28
|
+
|
|
29
|
+
//define(["./jsgui-lang-util", './abstract-resource'], function(jsgui, AR) {
|
|
30
|
+
|
|
31
|
+
// Do this not with AMD?
|
|
32
|
+
|
|
33
|
+
// May need Website_Data_Resource
|
|
34
|
+
// Would be configured within the node app, client has maximum autoconfig from connecting to the server, and integration with client-side controls.
|
|
35
|
+
// With the DB admin, it's about returining queries (maybe from RAM) about table data.
|
|
36
|
+
// /data/then the api?
|
|
37
|
+
|
|
38
|
+
// Respond to both data HTTP requests and websocket connections.
|
|
39
|
+
|
|
40
|
+
// HTTP data request -> response seems like the most important step now.
|
|
41
|
+
|
|
42
|
+
// An fs Resource would be of use for file system browser.
|
|
43
|
+
// Could have a client-side fs resource that connects to a veriety of services, could have one that connects to the server-side fs resource.
|
|
44
|
+
|
|
45
|
+
// Need to connect a data-providing resource to the UI component in cases where it's not secure to do so automatically.
|
|
46
|
+
// 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
|
+
//
|
|
48
|
+
|
|
49
|
+
var Site_Images = require("./website-image-resource");
|
|
50
|
+
|
|
51
|
+
//console.log('1) Site_Images', Site_Images);
|
|
52
|
+
|
|
53
|
+
var jsgui = require("jsgui3-html");
|
|
54
|
+
const { each, get_a_sig, is_defined, tof } = jsgui;
|
|
55
|
+
|
|
56
|
+
//var Web_Resource = require('./website-resource');
|
|
57
|
+
const Resource = jsgui.Resource;
|
|
58
|
+
const Router = jsgui.Router;
|
|
59
|
+
//const Evented_Class = jsgui.Evented_Class;
|
|
60
|
+
|
|
61
|
+
var Resource_Pool = require("./server-resource-pool");
|
|
62
|
+
//var Resource_Web_Admin = require('../web-admin');
|
|
63
|
+
|
|
64
|
+
var Site_JavaScript = require("./website-javascript-resource");
|
|
65
|
+
//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");
|
|
68
|
+
//var DB_Web_Resource = require('../../web/db-resource-postgres');
|
|
69
|
+
//var database_resource_factory = require('../../db/resource/factory');
|
|
70
|
+
|
|
71
|
+
const Resource_Publisher = require("../publishing/resource-publisher");
|
|
72
|
+
const Observable_Publisher = require("../publishing/observable-publisher");
|
|
73
|
+
const Function_Publisher = require("../publishing/function-publisher");
|
|
74
|
+
//const Data_Resource = require("./data-resource");
|
|
75
|
+
|
|
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
|
+
});
|
|
138
|
+
|
|
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
|
+
|
|
165
|
+
|
|
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.
|
|
170
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
};
|
|
301
|
+
|
|
302
|
+
if (sig === "[o]") {
|
|
303
|
+
each(a[0], (v, i) => {
|
|
304
|
+
single(i, v);
|
|
305
|
+
})
|
|
306
|
+
} else {
|
|
307
|
+
|
|
308
|
+
single(published_name, item);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
get resource_names() {
|
|
313
|
+
//console.log('this.resource_pool', this.resource_pool);
|
|
314
|
+
return this.resource_pool.resource_names;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
get_resource(resource_name) {
|
|
318
|
+
var resource_pool = this.resource_pool;
|
|
319
|
+
//console.log('resource_pool', resource_pool);
|
|
320
|
+
|
|
321
|
+
//console.log('this._.resource_pool', this._.resource_pool);
|
|
322
|
+
|
|
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
|
+
})
|
|
341
|
+
|
|
342
|
+
return res;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
start(callback) {
|
|
346
|
+
var resource_pool = this.resource_pool;
|
|
347
|
+
resource_pool.start(callback);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
meets_requirements() {
|
|
351
|
+
// Likely will be part of Status
|
|
352
|
+
|
|
353
|
+
//return false;
|
|
354
|
+
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
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
|
+
}
|
|
389
|
+
|
|
390
|
+
module.exports = Website_Resource;
|