This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
odata.js
73 lines (67 loc) · 2.12 KB
/
odata.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
/**
* MOST Web Framework
* A JavaScript Web Framework
* http://themost.io
*
* Copyright (c) 2014, Kyriakos Barbounakis k.barbounakis@gmail.com, Anthi Oikonomou anthioikonomou@gmail.com
*
* Released under the BSD3-Clause license
* Date: 2014-11-10
*/
var util = require('util');
var Q = require('q');
var _ = require('lodash');
var HttpResult = require('./http-mvc').HttpResult;
var ODataModelConventionBuilder = require('most-data/odata').ODataConventionModelBuilder;
var ODataModelBuilder = require('most-data/odata').ODataModelBuilder;
var DataConfiguration = require('most-data/data-configuration').DataConfiguration;
/**
* @class
* @constructor
* @param {*=} data
* @augments {HttpResult}
* @extends {HttpResult}
* @property {EntitySetConfiguration} entitySet
*/
function ODataJsonResult(data) {
ODataJsonResult.super_.bind(this)();
this.data = data;
this.contentType = 'application/json;charset=utf-8';
this.contentEncoding = 'utf8';
}
util.inherits(ODataJsonResult,HttpResult);
ODataJsonResult.prototype.execute = function(context, callback) {
var res = context.response;
if (_.isNil(this.data)) {
res.writeHead(204);
return callback();
}
};
function ODataModelBuilderConfiguration() {
//
}
/**
*
* @param {HttpApplication} app
* @returns Promise<ODataModelBuilder>
*/
ODataModelBuilderConfiguration.config = function(app) {
if (typeof app === 'undefined' || app === null) {
return Q.reject(new TypeError('Application may not be null'))
}
//create by default a new model convention builder
var builder = new ODataModelConventionBuilder(new DataConfiguration(app.getConfigurationPath()));
//initialize builder
return builder.initialize().then(function() {
//register service
app.service(ODataModelBuilder, function() {
return builder;
});
//return newly created builder for further processing
return Q.resolve(builder);
});
};
if (typeof module !== 'undefined') {
module.exports.ODataModelBuilderConfiguration = ODataModelBuilderConfiguration;
module.exports.ODataJsonResult = ODataJsonResult;
}