-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypes.js
465 lines (434 loc) · 12.5 KB
/
types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
/**
* @license
* MOST Web Framework 2.0 Codename Blueshift
* Copyright (c) 2017, THEMOST LP All rights reserved
*
* Use of this source code is governed by an BSD-3-Clause license that can be
* found in the LICENSE file at https://themost.io/license
*/
///
var Args = require('@themost/common').Args;
var LangUtils = require('@themost/common').LangUtils;
var SequentialEventEmitter = require('@themost/common').SequentialEventEmitter;
var AbstractMethodError = require('@themost/common').AbstractMethodError;
var AbstractClassError = require('@themost/common').AbstractClassError;
var Symbol = require('symbol');
var applicationProperty = Symbol('application');
var IApplicationService = require('@themost/common').IApplicationService;
/**
* @abstract
* @class
* @constructor
* @param {HttpApplication} app
* @augments IApplicationService
*/
function HttpApplicationService(app) {
if (this.constructor === HttpApplicationService.prototype.constructor) {
throw new AbstractClassError();
}
Args.notNull(app, 'HTTP Application');
this[applicationProperty] = app;
}
LangUtils.inherits(HttpApplicationService,IApplicationService);
/**
* @returns {HttpApplication}
*/
HttpApplicationService.prototype.getApplication = function() {
return this[applicationProperty];
};
/**
* Abstract view engine class
* @class HttpViewEngine
* @param {HttpContext} context
* @constructor
* @augments {SequentialEventEmitter}
*/
function HttpViewEngine(context) {
if (this.constructor === HttpViewEngine.prototype.constructor) {
throw new AbstractClassError();
}
/**
* @name HttpViewEngine#context
* @type HttpContext
* @description Gets or sets an instance of HttpContext that represents the current HTTP context.
*/
/**
* @type {HttpContext}
*/
var ctx = context;
Object.defineProperty(this,'context', {
get: function() {
return ctx;
},
set: function(value) {
ctx = value;
},
configurable:false,
enumerable:false
});
}
LangUtils.inherits(HttpViewEngine, SequentialEventEmitter);
/**
* @returns {HttpContext}
*/
HttpViewEngine.prototype.getContext = function() {
return this.context;
};
/**
* @abstract
* @description Renders the specified view with the options provided
* @param {string} _file
* @param {*} _data
* @param {Function} _callback
*/
// eslint-disable-next-line no-unused-vars
HttpViewEngine.prototype.render = function(_file, _data, _callback) {
throw new AbstractMethodError();
};
/**
* @class
* @abstract
*/
// eslint-disable-next-line no-unused-vars
function BeginRequestHandler() {
if (this.constructor === BeginRequestHandler.prototype.constructor) {
throw new AbstractClassError();
}
}
/**
* Occurs as the first event in the HTTP execution
* @param {HttpContext} context
* @param {Function} callback
*/
BeginRequestHandler.prototype.beginRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* @class
* @abstract
*/
// eslint-disable-next-line no-unused-vars
function ValidateRequestHandler() {
if (this.constructor === ValidateRequestHandler.prototype.constructor) {
throw new AbstractClassError();
}
}
/**
* Occurs when a handler is going to validate current HTTP request.
* @param {HttpContext} context
* @param {Function} callback
*/
ValidateRequestHandler.prototype.validateRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* @class
* @abstract
*/
// eslint-disable-next-line no-unused-vars
function AuthenticateRequestHandler() {
if (this.constructor === AuthenticateRequestHandler.prototype.constructor) {
throw new AbstractClassError();
}
}
/**
* Occurs when a handler is going to set current user identity.
* @param {HttpContext} context
* @param {Function} callback
*/
AuthenticateRequestHandler.prototype.authenticateRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* @class
* @abstract
*/
// eslint-disable-next-line no-unused-vars
function AuthorizeRequestHandler() {
if (this.constructor === AuthorizeRequestHandler.prototype.constructor) {
throw new AbstractClassError();
}
}
/**
* Occurs when a handler has verified user authorization.
* @param {HttpContext} context
* @param {Function} callback
*/
AuthorizeRequestHandler.prototype.authorizeRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* @class
* @abstract
*/
// eslint-disable-next-line no-unused-vars
function MapRequestHandler() {
if (this.constructor === MapRequestHandler.prototype.constructor) {
throw new AbstractClassError();
}
}
/**
* Occurs when the handler is selected to respond to the request.
* @param {HttpContext} context
* @param {Function} callback
*/
MapRequestHandler.prototype.mapRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* @class
* @abstract
*/
// eslint-disable-next-line no-unused-vars
function PostMapRequestHandler() {
if (this.constructor === PostMapRequestHandler.prototype.constructor) {
throw new AbstractClassError();
}
}
/**
* Occurs when application has mapped the current request to the appropriate handler.
* @param {HttpContext} context
* @param {Function} callback
*/
PostMapRequestHandler.prototype.postMapRequest = function(context, callback) {
callback = callback || function () { };
return callback();
};
/**
* @class
* @abstract
*/
// eslint-disable-next-line no-unused-vars
function ProcessRequestHandler() {
if (this.constructor === ProcessRequestHandler.prototype.constructor) {
throw new AbstractClassError();
}
}
/**
* Occurs when application starts processing current HTTP request.
* @param {HttpContext} context
* @param {Function} callback
*/
ProcessRequestHandler.prototype.processRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* @class
* @abstract
*/
// eslint-disable-next-line no-unused-vars
function PreExecuteResultHandler() {
if (this.constructor === PreExecuteResultHandler.prototype.constructor) {
throw new AbstractClassError();
}
}
/**
* Occurs when application starts executing an HTTP Result.
* @param {HttpContext} context
* @param {Function} callback
*/
PreExecuteResultHandler.prototype.preExecuteResult = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* @class
* @abstract
*/
// eslint-disable-next-line no-unused-vars
function PostExecuteResultHandler() {
if (this.constructor === PostExecuteResultHandler.prototype.constructor) {
throw new AbstractClassError();
}
}
/**
* Occurs when application was successfully executes an HTTP Result.
* @param {HttpContext} context
* @param {Function} callback
*/
PostExecuteResultHandler.prototype.postExecuteResult = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* @class
* @abstract
*/
// eslint-disable-next-line no-unused-vars
function EndRequestHandler() {
if (this.constructor === EndRequestHandler.prototype.constructor) {
throw new AbstractClassError();
}
}
/**
* Occurs as the first event in the HTTP execution
* @param {HttpContext} context
* @param {Function} callback
*/
EndRequestHandler.prototype.beginRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* @class An abstract class that represents an HTTP Handler
* @abstract
* @constructor
*/
function HttpHandler() {
if (this.constructor === HttpHandler.prototype.constructor) {
throw new AbstractClassError();
}
}
/**
* Gets an array of strings which represent the collection of events of an HttpHandler instance
* @type {Array.<string>}
*/
HttpHandler.Events = [
'beginRequest',
'validateRequest',
'authenticateRequest',
'authorizeRequest',
'mapRequest',
'postMapRequest',
'preExecuteResult',
'postExecuteResult',
'endRequest'
];
/**
* Occurs as the first event in the HTTP execution
* @param {HttpContext} context
* @param {Function} callback
*/
HttpHandler.prototype.beginRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* Occurs when a handler is going to validate current HTTP request.
* @param {HttpContext} context
* @param {Function} callback
*/
HttpHandler.prototype.validateRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* Occurs when a handler is going to set current user identity.
* @param {HttpContext} context
* @param {Function} callback
*/
HttpHandler.prototype.authenticateRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* Occurs when a handler has established the identity of the current user.
* @param {HttpContext} context
* @param {Function} callback
*/
/*HttpHandler.prototype.postAuthenticateRequest = function(context, callback) {
callback = callback || function() {};
callback.call(context);
};*/
/**
* Occurs when a handler has verified user authorization.
* @param {HttpContext} context
* @param {Function} callback
*/
HttpHandler.prototype.authorizeRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* Occurs when the handler is selected to respond to the request.
* @param {HttpContext} context
* @param {Function} callback
*/
HttpHandler.prototype.mapRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* Occurs when application has mapped the current request to the appropriate handler.
* @param {HttpContext} context
* @param {Function} callback
*/
HttpHandler.prototype.postMapRequest = function(context, callback) {
callback = callback || function () { };
return callback();
};
/**
* Occurs just before application starts executing a handler.
* @param {HttpContext} context
* @param {Function} callback
*/
/*HttpHandler.prototype.preRequestHandlerExecute = function(context, callback) {
callback = callback || function() {};
callback.call(context);
};*/
/**
* Occurs when application starts processing current HTTP request.
* @param {HttpContext} context
* @param {Function} callback
*/
HttpHandler.prototype.processRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* Occurs when application starts executing an HTTP Result.
* @param {HttpContext} context
* @param {Function} callback
*/
HttpHandler.prototype.preExecuteResult = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* Occurs when application was successfully executes an HTTP Result.
* @param {HttpContext} context
* @param {Function} callback
*/
HttpHandler.prototype.postExecuteResult = function (context, callback) {
callback = callback || function () { };
return callback();
};
/**
* Occurs when the handler finishes execution.
* @param {HttpContext} context
* @param {Function} callback
*/
/*HttpHandler.prototype.postRequestHandlerExecute = function(context, callback) {
callback = callback || function() {};
callback.call(context);
};*/
/**
* Occurs as the last event in the HTTP execution
* @param {HttpContext} context
* @param {Function} callback
*/
HttpHandler.prototype.endRequest = function (context, callback) {
callback = callback || function () { };
return callback();
};
if (typeof exports !== 'undefined')
{
module.exports.HttpApplicationService = HttpApplicationService;
module.exports.HttpViewEngine = HttpViewEngine;
module.exports.BeginRequestHandler = BeginRequestHandler;
module.exports.AuthenticateRequestHandler = AuthenticateRequestHandler;
module.exports.AuthorizeRequestHandler = AuthorizeRequestHandler;
module.exports.MapRequestHandler = MapRequestHandler;
module.exports.PostMapRequestHandler = PostMapRequestHandler;
module.exports.ProcessRequestHandler = ProcessRequestHandler;
module.exports.PreExecuteResultHandler = PreExecuteResultHandler;
module.exports.PostExecuteResultHandler = PostExecuteResultHandler;
module.exports.EndRequestHandler = EndRequestHandler;
module.exports.HttpHandler = HttpHandler;
}