@steedos/odata-v4-mongodb 2.2.53-beta.3
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/LICENSE.txt +22 -0
- package/README.md +85 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +25 -0
- package/lib/index.js.map +1 -0
- package/lib/visitor.d.ts +47 -0
- package/lib/visitor.js +265 -0
- package/lib/visitor.js.map +1 -0
- package/package.json +37 -0
- package/src/index.ts +41 -0
- package/src/visitor.ts +301 -0
- package/tsconfig.json +33 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Steedos Licensing
|
|
2
|
+
|
|
3
|
+
SOFTWARE LICENSING
|
|
4
|
+
|
|
5
|
+
To determine under which license you may use a file from the Steedos source code,
|
|
6
|
+
please resort to the header of that file.
|
|
7
|
+
|
|
8
|
+
If the file has no header, the following rules apply
|
|
9
|
+
1. enterprise features are licensed under Steedos Enterprise Terms, see License.enterprise.txt
|
|
10
|
+
2. source code that is neither (1) is licensed under MIT, see https://opensource.org/licenses/MIT
|
|
11
|
+
|
|
12
|
+
On request, licenses under different terms are available.
|
|
13
|
+
|
|
14
|
+
Source code of enterprise features are files that
|
|
15
|
+
* are in folders named "ee" or start with "ee_", or in subfolders of such folders.
|
|
16
|
+
* contain the strings "ee_" in its filename name.
|
|
17
|
+
The files can be found by running the command `find . -iname ee -or -iname "*_ee*" -or -iname "*ee_*"`
|
|
18
|
+
|
|
19
|
+
STEEDOS TRADEMARK GUIDELINES
|
|
20
|
+
|
|
21
|
+
Your use of the mark Steedos is subject to Steedos, Inc's prior written approval. For trademark approval or any questions
|
|
22
|
+
you have about using these trademarks, please email zhuangjianguo@steedos.com
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
* @Author: baozhoutao@steedos.com
|
|
3
|
+
* @Date: 2022-07-10 15:44:34
|
|
4
|
+
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
+
* @LastEditTime: 2022-07-10 15:57:25
|
|
6
|
+
* @Description:
|
|
7
|
+
-->
|
|
8
|
+
# OData V4 Service modules - MongoDB Connector
|
|
9
|
+
|
|
10
|
+
Service OData v4 requests from a MongoDB data store.
|
|
11
|
+
|
|
12
|
+
## Synopsis
|
|
13
|
+
The OData V4 MongoDB Connector provides functionality to convert the various types of OData segments
|
|
14
|
+
into MongoDB query objects, that you can execute over a MongoDB database.
|
|
15
|
+
|
|
16
|
+
## Potential usage scenarios
|
|
17
|
+
|
|
18
|
+
- Create high speed, standard compliant data sharing APIs
|
|
19
|
+
|
|
20
|
+
## Usage as server - TypeScript
|
|
21
|
+
```javascript
|
|
22
|
+
import { createFilter } from '@steedos/odata-v4-mongodb'
|
|
23
|
+
|
|
24
|
+
//example request: GET /api/products?$filter=category/id eq 5 or color eq 'Red'
|
|
25
|
+
app.get("/api/products", (req: Request, res: Response) => {
|
|
26
|
+
const filter = createFilter(req.query.$filter);
|
|
27
|
+
// collection instance from MongoDB Node.JS Driver
|
|
28
|
+
collection.find(filter, function(err, data){
|
|
29
|
+
res.json({
|
|
30
|
+
'@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#products',
|
|
31
|
+
value: data
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage ES5
|
|
38
|
+
```javascript
|
|
39
|
+
var createFilter = require('@steedos/odata-v4-mongodb').createFilter;
|
|
40
|
+
|
|
41
|
+
app.get("/api/products", function(req, res) {
|
|
42
|
+
var filter = createFilter(req.query.$filter);
|
|
43
|
+
// collection instance from MongoDB Node.JS Driver
|
|
44
|
+
collection.find(filter, function(err, data){
|
|
45
|
+
res.json({
|
|
46
|
+
'@odata.context': req.protocol + '://' + req.get('host') + '/api/$metadata#products',
|
|
47
|
+
value: data
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Supported OData segments
|
|
54
|
+
|
|
55
|
+
For now **$filter**, **$select**, **$skip** and **$top**
|
|
56
|
+
|
|
57
|
+
Support for **$expand** is next.
|
|
58
|
+
|
|
59
|
+
### Supported $filter expressions
|
|
60
|
+
|
|
61
|
+
The [OData v4 Parser](https://www.npmjs.com/package/odata-v4-parser) layer supports 100% of the specification.
|
|
62
|
+
The Connector is supporting basic MongoDB queries.
|
|
63
|
+
|
|
64
|
+
*We are into creating a comprehensive feature availability chart for V1 release*
|
|
65
|
+
|
|
66
|
+
√ expression 5.1.1.6.1: NullValue eq null
|
|
67
|
+
√ expression 5.1.1.6.1: TrueValue eq true
|
|
68
|
+
√ expression 5.1.1.6.1: FalseValue eq false
|
|
69
|
+
√ expression 5.1.1.6.1: IntegerValue lt -128
|
|
70
|
+
√ expression 5.1.1.6.1: DecimalValue eq 34.95
|
|
71
|
+
√ expression 5.1.1.6.1: StringValue eq 'Say Hello,then go'
|
|
72
|
+
√ expression 5.1.1.6.1: DurationValue eq duration'P12DT23H59M59.999999999999S'
|
|
73
|
+
√ expression 5.1.1.6.1: DateValue eq 2012-12-03
|
|
74
|
+
√ expression 5.1.1.6.1: DateTimeOffsetValue eq 2012-12-03T07:16:23Z
|
|
75
|
+
√ expression 5.1.1.6.1: GuidValue eq 01234567-89ab-cdef-0123-456789abcdef
|
|
76
|
+
√ expression 5.1.1.6.1: Int64Value eq 0
|
|
77
|
+
√ expression 5.1.1.6.1: A eq INF
|
|
78
|
+
√ expression 5.1.1.6.1: A eq 0.31415926535897931e1
|
|
79
|
+
√ expression 5.1.1.1.2: A ne 1
|
|
80
|
+
√ expression 5.1.1.1.3: A gt 2
|
|
81
|
+
√ expression 5.1.1.1.4: A ge 3
|
|
82
|
+
√ expression 5.1.1.1.5: A lt 2
|
|
83
|
+
√ expression 5.1.1.1.6: A le 2
|
|
84
|
+
√ expression: A/b eq 1
|
|
85
|
+
√ expression 5.1.1.3: (A/b eq 2) or (B/c lt 4) and ((E gt 5) or (E lt -1))
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates MongoDB collection, query, projection, sort, skip and limit from an OData URI string
|
|
3
|
+
* @param {string} queryString - An OData query string
|
|
4
|
+
* @return {Visitor} Visitor instance object with collection, query, projection, sort, skip and limit
|
|
5
|
+
* @example
|
|
6
|
+
* const query = createQuery("$filter=Size eq 4&$orderby=Orders&$skip=10&$top=5");
|
|
7
|
+
* collections[query.collection].find(query.query).project(query.projection).sort(query.sort).skip(query.skip).limit(query.limit).toArray(function(err, data){ ... });
|
|
8
|
+
*/
|
|
9
|
+
export declare function createQuery(odataQuery: string): any;
|
|
10
|
+
export declare function createQuery(odataQuery: any): any;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a MongoDB query object from an OData filter expression string
|
|
13
|
+
* @param {string} odataFilter - A filter expression in OData $filter format
|
|
14
|
+
* @return {Object} MongoDB query object
|
|
15
|
+
* @example
|
|
16
|
+
* const filter = createFilter("Size eq 4 and Age gt 18");
|
|
17
|
+
* collection.find(filter, function(err, data){ ... });
|
|
18
|
+
*/
|
|
19
|
+
export declare function createFilter(odataFilter: string): any;
|
|
20
|
+
export declare function createFilter(odataFilter: any): any;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFilter = exports.createQuery = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* @Author: baozhoutao@steedos.com
|
|
6
|
+
* @Date: 2022-07-10 15:44:34
|
|
7
|
+
* @LastEditors: baozhoutao@steedos.com
|
|
8
|
+
* @LastEditTime: 2022-07-10 17:09:22
|
|
9
|
+
* @Description:
|
|
10
|
+
*/
|
|
11
|
+
var visitor_1 = require("./visitor");
|
|
12
|
+
var odata_v4_parser_1 = require("@steedos/odata-v4-parser");
|
|
13
|
+
function createQuery(odataQuery) {
|
|
14
|
+
var ast = (typeof odataQuery == "string" ? (0, odata_v4_parser_1.query)(odataQuery) : odataQuery);
|
|
15
|
+
return new visitor_1.Visitor().Visit(ast);
|
|
16
|
+
}
|
|
17
|
+
exports.createQuery = createQuery;
|
|
18
|
+
function createFilter(odataFilter) {
|
|
19
|
+
var context = { query: {} };
|
|
20
|
+
var ast = (typeof odataFilter == "string" ? (0, odata_v4_parser_1.filter)(odataFilter) : odataFilter);
|
|
21
|
+
new visitor_1.Visitor().Visit(ast, context);
|
|
22
|
+
return context.query;
|
|
23
|
+
}
|
|
24
|
+
exports.createFilter = createFilter;
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,qCAAmC;AACnC,4DAAwD;AAYxD,SAAgB,WAAW,CAAC,UAAuB;IAC/C,IAAI,GAAG,GAAY,CAAC,OAAO,UAAU,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAA,uBAAK,EAAS,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAC5F,OAAO,IAAI,iBAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC;AAHD,kCAGC;AAYD,SAAgB,YAAY,CAAC,WAAwB;IACjD,IAAI,OAAO,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IAC5B,IAAI,GAAG,GAAY,CAAC,OAAO,WAAW,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAA,wBAAM,EAAS,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAChG,IAAI,iBAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,OAAO,CAAC,KAAK,CAAC;AACzB,CAAC;AALD,oCAKC"}
|
package/lib/visitor.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare class Visitor {
|
|
2
|
+
query: any;
|
|
3
|
+
sort: any;
|
|
4
|
+
skip: number;
|
|
5
|
+
limit: number;
|
|
6
|
+
projection: any;
|
|
7
|
+
collection: string;
|
|
8
|
+
navigationProperty: string;
|
|
9
|
+
includes: Visitor[];
|
|
10
|
+
inlinecount: boolean;
|
|
11
|
+
ast: any;
|
|
12
|
+
constructor();
|
|
13
|
+
Visit(node: any, context?: any): this;
|
|
14
|
+
protected VisitODataUri(node: any, context: any): void;
|
|
15
|
+
protected VisitEntitySetName(node: any, context: any): void;
|
|
16
|
+
protected VisitExpand(node: any, context: any): void;
|
|
17
|
+
protected VisitExpandItem(node: any, context: any): void;
|
|
18
|
+
protected VisitExpandPath(node: any, context: any): void;
|
|
19
|
+
protected VisitQueryOptions(node: any, context: any): void;
|
|
20
|
+
protected VisitInlineCount(node: any, context: any): void;
|
|
21
|
+
protected VisitFilter(node: any, context: any): void;
|
|
22
|
+
protected VisitOrderBy(node: any, context: any): void;
|
|
23
|
+
protected VisitSkip(node: any, context: any): void;
|
|
24
|
+
protected VisitTop(node: any, context: any): void;
|
|
25
|
+
protected VisitOrderByItem(node: any, context: any): void;
|
|
26
|
+
protected VisitSelect(node: any, context: any): void;
|
|
27
|
+
protected VisitSelectItem(node: any, context: any): void;
|
|
28
|
+
protected VisitAndExpression(node: any, context: any): void;
|
|
29
|
+
protected VisitOrExpression(node: any, context: any): void;
|
|
30
|
+
protected VisitBoolParenExpression(node: any, context: any): void;
|
|
31
|
+
protected VisitCommonExpression(node: any, context: any): void;
|
|
32
|
+
protected VisitFirstMemberExpression(node: any, context: any): void;
|
|
33
|
+
protected VisitMemberExpression(node: any, context: any): void;
|
|
34
|
+
protected VisitPropertyPathExpression(node: any, context: any): void;
|
|
35
|
+
protected VisitSingleNavigationExpression(node: any, context: any): void;
|
|
36
|
+
protected VisitODataIdentifier(node: any, context: any): void;
|
|
37
|
+
protected VisitNotExpression(node: any, context: any): void;
|
|
38
|
+
protected VisitEqualsExpression(node: any, context: any): void;
|
|
39
|
+
protected VisitNotEqualsExpression(node: any, context: any): void;
|
|
40
|
+
protected VisitInExpression(node: any, context: any): void;
|
|
41
|
+
protected VisitLesserThanExpression(node: any, context: any): void;
|
|
42
|
+
protected VisitLesserOrEqualsExpression(node: any, context: any): void;
|
|
43
|
+
protected VisitGreaterThanExpression(node: any, context: any): void;
|
|
44
|
+
protected VisitGreaterOrEqualsExpression(node: any, context: any): void;
|
|
45
|
+
protected VisitLiteral(node: any, context: any): void;
|
|
46
|
+
protected VisitMethodCallExpression(node: any, context: any): void;
|
|
47
|
+
}
|
package/lib/visitor.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Visitor = void 0;
|
|
4
|
+
var odata_v4_literal_1 = require("odata-v4-literal");
|
|
5
|
+
var Visitor = /** @class */ (function () {
|
|
6
|
+
function Visitor() {
|
|
7
|
+
this.query = {};
|
|
8
|
+
this.sort = {};
|
|
9
|
+
this.projection = {};
|
|
10
|
+
this.includes = [];
|
|
11
|
+
var _ast;
|
|
12
|
+
Object.defineProperty(this, "ast", {
|
|
13
|
+
get: function () { return _ast; },
|
|
14
|
+
set: function (v) { _ast = v; },
|
|
15
|
+
enumerable: false
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
Visitor.prototype.Visit = function (node, context) {
|
|
19
|
+
this.ast = this.ast || node;
|
|
20
|
+
context = context || {};
|
|
21
|
+
if (node) {
|
|
22
|
+
var visitor = this["Visit".concat(node.type)];
|
|
23
|
+
if (visitor)
|
|
24
|
+
visitor.call(this, node, context);
|
|
25
|
+
}
|
|
26
|
+
return this;
|
|
27
|
+
};
|
|
28
|
+
Visitor.prototype.VisitODataUri = function (node, context) {
|
|
29
|
+
this.Visit(node.value.resource, context);
|
|
30
|
+
this.Visit(node.value.query, context);
|
|
31
|
+
};
|
|
32
|
+
Visitor.prototype.VisitEntitySetName = function (node, context) {
|
|
33
|
+
this.collection = node.value.name;
|
|
34
|
+
};
|
|
35
|
+
Visitor.prototype.VisitExpand = function (node, context) {
|
|
36
|
+
var _this = this;
|
|
37
|
+
var innerContexts = {};
|
|
38
|
+
node.value.items.forEach(function (item) {
|
|
39
|
+
var expandPath = item.value.path.raw;
|
|
40
|
+
var innerVisitor = _this.includes.filter(function (v) { return v.navigationProperty === expandPath; })[0];
|
|
41
|
+
if (!innerVisitor) {
|
|
42
|
+
innerVisitor = new Visitor();
|
|
43
|
+
innerContexts[expandPath] = {
|
|
44
|
+
query: {},
|
|
45
|
+
sort: {},
|
|
46
|
+
projection: {},
|
|
47
|
+
options: {}
|
|
48
|
+
};
|
|
49
|
+
_this.includes.push(innerVisitor);
|
|
50
|
+
}
|
|
51
|
+
var innerContext = innerContexts[expandPath] || {};
|
|
52
|
+
innerVisitor.Visit(item, innerContext);
|
|
53
|
+
innerVisitor.query = innerContext.query || innerVisitor.query || {};
|
|
54
|
+
innerVisitor.sort = innerContext.sort || innerVisitor.sort;
|
|
55
|
+
innerVisitor.projection = innerContext.projection || innerVisitor.projection;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
Visitor.prototype.VisitExpandItem = function (node, context) {
|
|
59
|
+
var _this = this;
|
|
60
|
+
this.Visit(node.value.path, context);
|
|
61
|
+
node.value.options && node.value.options.forEach(function (item) { return _this.Visit(item, context); });
|
|
62
|
+
};
|
|
63
|
+
Visitor.prototype.VisitExpandPath = function (node, context) {
|
|
64
|
+
this.navigationProperty = node.raw;
|
|
65
|
+
};
|
|
66
|
+
Visitor.prototype.VisitQueryOptions = function (node, context) {
|
|
67
|
+
var _this = this;
|
|
68
|
+
context.options = {};
|
|
69
|
+
node.value.options.forEach(function (option) { return _this.Visit(option, context); });
|
|
70
|
+
this.query = context.query || {};
|
|
71
|
+
delete context.query;
|
|
72
|
+
this.sort = context.sort;
|
|
73
|
+
delete context.sort;
|
|
74
|
+
};
|
|
75
|
+
Visitor.prototype.VisitInlineCount = function (node, context) {
|
|
76
|
+
this.inlinecount = odata_v4_literal_1.Literal.convert(node.value.value, node.value.raw);
|
|
77
|
+
};
|
|
78
|
+
Visitor.prototype.VisitFilter = function (node, context) {
|
|
79
|
+
context.query = {};
|
|
80
|
+
this.Visit(node.value, context);
|
|
81
|
+
delete context.identifier;
|
|
82
|
+
delete context.literal;
|
|
83
|
+
};
|
|
84
|
+
Visitor.prototype.VisitOrderBy = function (node, context) {
|
|
85
|
+
var _this = this;
|
|
86
|
+
context.sort = {};
|
|
87
|
+
node.value.items.forEach(function (item) { return _this.Visit(item, context); });
|
|
88
|
+
};
|
|
89
|
+
Visitor.prototype.VisitSkip = function (node, context) {
|
|
90
|
+
this.skip = +node.value.raw;
|
|
91
|
+
};
|
|
92
|
+
Visitor.prototype.VisitTop = function (node, context) {
|
|
93
|
+
this.limit = +node.value.raw;
|
|
94
|
+
};
|
|
95
|
+
Visitor.prototype.VisitOrderByItem = function (node, context) {
|
|
96
|
+
this.Visit(node.value.expr, context);
|
|
97
|
+
if (context.identifier)
|
|
98
|
+
context.sort[context.identifier] = node.value.direction;
|
|
99
|
+
delete context.identifier;
|
|
100
|
+
delete context.literal;
|
|
101
|
+
};
|
|
102
|
+
Visitor.prototype.VisitSelect = function (node, context) {
|
|
103
|
+
var _this = this;
|
|
104
|
+
context.projection = {};
|
|
105
|
+
node.value.items.forEach(function (item) { return _this.Visit(item, context); });
|
|
106
|
+
this.projection = context.projection;
|
|
107
|
+
delete context.projection;
|
|
108
|
+
};
|
|
109
|
+
Visitor.prototype.VisitSelectItem = function (node, context) {
|
|
110
|
+
context.projection[node.raw.replace(/\//g, '.')] = 1;
|
|
111
|
+
};
|
|
112
|
+
Visitor.prototype.VisitAndExpression = function (node, context) {
|
|
113
|
+
var query = context.query;
|
|
114
|
+
var leftQuery = {};
|
|
115
|
+
context.query = leftQuery;
|
|
116
|
+
this.Visit(node.value.left, context);
|
|
117
|
+
var rightQuery = {};
|
|
118
|
+
context.query = rightQuery;
|
|
119
|
+
this.Visit(node.value.right, context);
|
|
120
|
+
if (Object.keys(leftQuery).length > 0 && Object.keys(rightQuery).length > 0) {
|
|
121
|
+
query.$and = [leftQuery, rightQuery];
|
|
122
|
+
}
|
|
123
|
+
context.query = query;
|
|
124
|
+
};
|
|
125
|
+
Visitor.prototype.VisitOrExpression = function (node, context) {
|
|
126
|
+
var query = context.query;
|
|
127
|
+
var leftQuery = {};
|
|
128
|
+
context.query = leftQuery;
|
|
129
|
+
this.Visit(node.value.left, context);
|
|
130
|
+
var rightQuery = {};
|
|
131
|
+
context.query = rightQuery;
|
|
132
|
+
this.Visit(node.value.right, context);
|
|
133
|
+
if (Object.keys(leftQuery).length > 0 && Object.keys(rightQuery).length > 0) {
|
|
134
|
+
query.$or = [leftQuery, rightQuery];
|
|
135
|
+
}
|
|
136
|
+
context.query = query;
|
|
137
|
+
};
|
|
138
|
+
Visitor.prototype.VisitBoolParenExpression = function (node, context) {
|
|
139
|
+
this.Visit(node.value, context);
|
|
140
|
+
};
|
|
141
|
+
Visitor.prototype.VisitCommonExpression = function (node, context) {
|
|
142
|
+
this.Visit(node.value, context);
|
|
143
|
+
};
|
|
144
|
+
Visitor.prototype.VisitFirstMemberExpression = function (node, context) {
|
|
145
|
+
this.Visit(node.value, context);
|
|
146
|
+
};
|
|
147
|
+
Visitor.prototype.VisitMemberExpression = function (node, context) {
|
|
148
|
+
this.Visit(node.value, context);
|
|
149
|
+
};
|
|
150
|
+
Visitor.prototype.VisitPropertyPathExpression = function (node, context) {
|
|
151
|
+
if (node.value.current && node.value.next) {
|
|
152
|
+
this.Visit(node.value.current, context);
|
|
153
|
+
if (context.identifier)
|
|
154
|
+
context.identifier += ".";
|
|
155
|
+
this.Visit(node.value.next, context);
|
|
156
|
+
}
|
|
157
|
+
else
|
|
158
|
+
this.Visit(node.value, context);
|
|
159
|
+
};
|
|
160
|
+
Visitor.prototype.VisitSingleNavigationExpression = function (node, context) {
|
|
161
|
+
if (node.value.current && node.value.next) {
|
|
162
|
+
this.Visit(node.value.current, context);
|
|
163
|
+
this.Visit(node.value.next, context);
|
|
164
|
+
}
|
|
165
|
+
else
|
|
166
|
+
this.Visit(node.value, context);
|
|
167
|
+
};
|
|
168
|
+
Visitor.prototype.VisitODataIdentifier = function (node, context) {
|
|
169
|
+
context.identifier = (context.identifier || "") + node.value.name;
|
|
170
|
+
};
|
|
171
|
+
Visitor.prototype.VisitNotExpression = function (node, context) {
|
|
172
|
+
this.Visit(node.value, context);
|
|
173
|
+
if (context.query) {
|
|
174
|
+
for (var prop in context.query) {
|
|
175
|
+
context.query[prop] = { $not: context.query[prop] };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
Visitor.prototype.VisitEqualsExpression = function (node, context) {
|
|
180
|
+
this.Visit(node.value.left, context);
|
|
181
|
+
this.Visit(node.value.right, context);
|
|
182
|
+
if (context.identifier)
|
|
183
|
+
context.query[context.identifier] = context.literal;
|
|
184
|
+
delete context.identifier;
|
|
185
|
+
delete context.literal;
|
|
186
|
+
};
|
|
187
|
+
Visitor.prototype.VisitNotEqualsExpression = function (node, context) {
|
|
188
|
+
this.Visit(node.value.left, context);
|
|
189
|
+
this.Visit(node.value.right, context);
|
|
190
|
+
if (context.identifier)
|
|
191
|
+
context.query[context.identifier] = { $ne: context.literal };
|
|
192
|
+
delete context.identifier;
|
|
193
|
+
delete context.literal;
|
|
194
|
+
};
|
|
195
|
+
Visitor.prototype.VisitInExpression = function (node, context) {
|
|
196
|
+
this.Visit(node.value.left, context);
|
|
197
|
+
this.Visit(node.value.right, context);
|
|
198
|
+
if (context.identifier)
|
|
199
|
+
context.query[context.identifier] = {
|
|
200
|
+
$in: JSON.parse("[".concat(node.value.right.raw.replace(/\'/g, "\"").slice(1).slice(0, -1), "]"))
|
|
201
|
+
};
|
|
202
|
+
delete context.identifier;
|
|
203
|
+
delete context.literal;
|
|
204
|
+
};
|
|
205
|
+
;
|
|
206
|
+
Visitor.prototype.VisitLesserThanExpression = function (node, context) {
|
|
207
|
+
this.Visit(node.value.left, context);
|
|
208
|
+
this.Visit(node.value.right, context);
|
|
209
|
+
if (context.identifier)
|
|
210
|
+
context.query[context.identifier] = { $lt: context.literal };
|
|
211
|
+
delete context.identifier;
|
|
212
|
+
delete context.literal;
|
|
213
|
+
};
|
|
214
|
+
Visitor.prototype.VisitLesserOrEqualsExpression = function (node, context) {
|
|
215
|
+
this.Visit(node.value.left, context);
|
|
216
|
+
this.Visit(node.value.right, context);
|
|
217
|
+
if (context.identifier)
|
|
218
|
+
context.query[context.identifier] = { $lte: context.literal };
|
|
219
|
+
delete context.identifier;
|
|
220
|
+
delete context.literal;
|
|
221
|
+
};
|
|
222
|
+
Visitor.prototype.VisitGreaterThanExpression = function (node, context) {
|
|
223
|
+
this.Visit(node.value.left, context);
|
|
224
|
+
this.Visit(node.value.right, context);
|
|
225
|
+
if (context.identifier)
|
|
226
|
+
context.query[context.identifier] = { $gt: context.literal };
|
|
227
|
+
delete context.identifier;
|
|
228
|
+
delete context.literal;
|
|
229
|
+
};
|
|
230
|
+
Visitor.prototype.VisitGreaterOrEqualsExpression = function (node, context) {
|
|
231
|
+
this.Visit(node.value.left, context);
|
|
232
|
+
this.Visit(node.value.right, context);
|
|
233
|
+
if (context.identifier)
|
|
234
|
+
context.query[context.identifier] = { $gte: context.literal };
|
|
235
|
+
delete context.identifier;
|
|
236
|
+
delete context.literal;
|
|
237
|
+
};
|
|
238
|
+
Visitor.prototype.VisitLiteral = function (node, context) {
|
|
239
|
+
context.literal = odata_v4_literal_1.Literal.convert(node.value, node.raw);
|
|
240
|
+
};
|
|
241
|
+
Visitor.prototype.VisitMethodCallExpression = function (node, context) {
|
|
242
|
+
var _this = this;
|
|
243
|
+
var method = node.value.method;
|
|
244
|
+
(node.value.parameters || []).forEach(function (p) { return _this.Visit(p, context); });
|
|
245
|
+
if (context.identifier) {
|
|
246
|
+
switch (method) {
|
|
247
|
+
case "contains":
|
|
248
|
+
context.query[context.identifier] = new RegExp(context.literal, "gi");
|
|
249
|
+
break;
|
|
250
|
+
case "endswith":
|
|
251
|
+
context.query[context.identifier] = new RegExp(context.literal + "$", "gi");
|
|
252
|
+
break;
|
|
253
|
+
case "startswith":
|
|
254
|
+
context.query[context.identifier] = new RegExp("^" + context.literal, "gi");
|
|
255
|
+
break;
|
|
256
|
+
default:
|
|
257
|
+
throw new Error("Method call not implemented.");
|
|
258
|
+
}
|
|
259
|
+
delete context.identifier;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
return Visitor;
|
|
263
|
+
}());
|
|
264
|
+
exports.Visitor = Visitor;
|
|
265
|
+
//# sourceMappingURL=visitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitor.js","sourceRoot":"","sources":["../src/visitor.ts"],"names":[],"mappings":";;;AAAA,qDAA2C;AAE3C;IAYC;QACC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QAEnB,IAAI,IAAI,CAAC;QACT,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE;YAClC,GAAG,EAAE,cAAQ,OAAO,IAAI,CAAC,CAAC,CAAC;YAC3B,GAAG,EAAE,UAAC,CAAC,IAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;YACzB,UAAU,EAAE,KAAK;SACjB,CAAC,CAAC;IACJ,CAAC;IAED,uBAAK,GAAL,UAAM,IAAQ,EAAE,OAAY;QAC3B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC;QAC5B,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QAExB,IAAI,IAAI,EAAC;YACR,IAAI,OAAO,GAAG,IAAI,CAAC,eAAQ,IAAI,C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,CAAC;IAES,2CAAyB,GAAnC,UAAoC,IAAS,EAAE,OAAY;QAA3D,iBAmBC;QAlBA,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAC/B,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,KAAI,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,EAAtB,CAAsB,CAAC,CAAC;QACnE,IAAI,OAAO,CAAC,UAAU,EAAE;YACvB,QAAQ,MAAM,EAAE;gBACf,KAAK,UAAU;oBACd,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;oBACtE,MAAM;gBACP,KAAK,UAAU;oBACd,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC;oBAC5E,MAAM;gBACP,KAAK,YAAY;oBAChB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;oBAC5E,MAAM;gBACP;oBACC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;aAChD;YACD,OAAO,OAAO,CAAC,UAAU,CAAC;SAC1B;IACF,CAAC;IAEF,cAAC;AAAD,CAAC,AA1SD,IA0SC;AA1SY,0BAAO"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@steedos/odata-v4-mongodb",
|
|
3
|
+
"version": "2.2.53-beta.3",
|
|
4
|
+
"description": "Service OData requests from a MongoDB data store",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"directories": {
|
|
7
|
+
"test": "test"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/jaystack/odata-v4-mongodb.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"OData",
|
|
18
|
+
"server",
|
|
19
|
+
"V4",
|
|
20
|
+
"parser"
|
|
21
|
+
],
|
|
22
|
+
"author": "",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/jaystack/odata-v4-mongodb/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/jaystack/odata-v4-mongodb#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@steedos/odata-v4-parser": "2.2.53-beta.3",
|
|
30
|
+
"odata-v4-literal": "^0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"private": false,
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "5782f1171133c05cce158adef71e527d970ef50e"
|
|
37
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: baozhoutao@steedos.com
|
|
3
|
+
* @Date: 2022-07-10 15:44:34
|
|
4
|
+
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
+
* @LastEditTime: 2022-07-10 17:09:22
|
|
6
|
+
* @Description:
|
|
7
|
+
*/
|
|
8
|
+
import { Visitor } from "./visitor"
|
|
9
|
+
import { filter, query } from "@steedos/odata-v4-parser"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates MongoDB collection, query, projection, sort, skip and limit from an OData URI string
|
|
13
|
+
* @param {string} queryString - An OData query string
|
|
14
|
+
* @return {Visitor} Visitor instance object with collection, query, projection, sort, skip and limit
|
|
15
|
+
* @example
|
|
16
|
+
* const query = createQuery("$filter=Size eq 4&$orderby=Orders&$skip=10&$top=5");
|
|
17
|
+
* collections[query.collection].find(query.query).project(query.projection).sort(query.sort).skip(query.skip).limit(query.limit).toArray(function(err, data){ ... });
|
|
18
|
+
*/
|
|
19
|
+
export function createQuery(odataQuery:string);
|
|
20
|
+
export function createQuery(odataQuery:any);
|
|
21
|
+
export function createQuery(odataQuery:string | any){
|
|
22
|
+
let ast:any = <any>(typeof odataQuery == "string" ? query(<string>odataQuery) : odataQuery);
|
|
23
|
+
return new Visitor().Visit(ast);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a MongoDB query object from an OData filter expression string
|
|
28
|
+
* @param {string} odataFilter - A filter expression in OData $filter format
|
|
29
|
+
* @return {Object} MongoDB query object
|
|
30
|
+
* @example
|
|
31
|
+
* const filter = createFilter("Size eq 4 and Age gt 18");
|
|
32
|
+
* collection.find(filter, function(err, data){ ... });
|
|
33
|
+
*/
|
|
34
|
+
export function createFilter(odataFilter:string);
|
|
35
|
+
export function createFilter(odataFilter:any);
|
|
36
|
+
export function createFilter(odataFilter:string | any):Object{
|
|
37
|
+
let context = { query: {} };
|
|
38
|
+
let ast:any = <any>(typeof odataFilter == "string" ? filter(<string>odataFilter) : odataFilter);
|
|
39
|
+
new Visitor().Visit(ast, context);
|
|
40
|
+
return context.query;
|
|
41
|
+
}
|
package/src/visitor.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { Literal } from "odata-v4-literal";
|
|
2
|
+
|
|
3
|
+
export class Visitor{
|
|
4
|
+
query: any
|
|
5
|
+
sort: any
|
|
6
|
+
skip: number
|
|
7
|
+
limit: number
|
|
8
|
+
projection: any
|
|
9
|
+
collection: string
|
|
10
|
+
navigationProperty: string
|
|
11
|
+
includes:Visitor[]
|
|
12
|
+
inlinecount: boolean
|
|
13
|
+
ast:any
|
|
14
|
+
|
|
15
|
+
constructor(){
|
|
16
|
+
this.query = {};
|
|
17
|
+
this.sort = {};
|
|
18
|
+
this.projection = {};
|
|
19
|
+
this.includes = [];
|
|
20
|
+
|
|
21
|
+
let _ast;
|
|
22
|
+
Object.defineProperty(this, "ast", {
|
|
23
|
+
get: () => { return _ast; },
|
|
24
|
+
set: (v) => { _ast = v; },
|
|
25
|
+
enumerable: false
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Visit(node:any, context?:any){
|
|
30
|
+
this.ast = this.ast || node;
|
|
31
|
+
context = context || {};
|
|
32
|
+
|
|
33
|
+
if (node){
|
|
34
|
+
var visitor = this[`Visit${node.type}`];
|
|
35
|
+
if (visitor) visitor.call(this, node, context);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected VisitODataUri(node:any, context:any){
|
|
42
|
+
this.Visit(node.value.resource, context);
|
|
43
|
+
this.Visit(node.value.query, context);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected VisitEntitySetName(node:any, context:any){
|
|
47
|
+
this.collection = node.value.name;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected VisitExpand(node: any, context: any) {
|
|
51
|
+
var innerContexts:any = {};
|
|
52
|
+
node.value.items.forEach((item) => {
|
|
53
|
+
var expandPath = item.value.path.raw;
|
|
54
|
+
var innerVisitor = this.includes.filter(v => v.navigationProperty === expandPath)[0];
|
|
55
|
+
if (!innerVisitor){
|
|
56
|
+
innerVisitor = new Visitor();
|
|
57
|
+
|
|
58
|
+
innerContexts[expandPath] = {
|
|
59
|
+
query: {},
|
|
60
|
+
sort: {},
|
|
61
|
+
projection: {},
|
|
62
|
+
options: {}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
this.includes.push(innerVisitor);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let innerContext:any = innerContexts[expandPath] || {};
|
|
69
|
+
innerVisitor.Visit(item, innerContext);
|
|
70
|
+
|
|
71
|
+
innerVisitor.query = innerContext.query || innerVisitor.query || {};
|
|
72
|
+
innerVisitor.sort = innerContext.sort || innerVisitor.sort;
|
|
73
|
+
innerVisitor.projection = innerContext.projection || innerVisitor.projection;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
protected VisitExpandItem(node: any, context: any) {
|
|
78
|
+
this.Visit(node.value.path, context);
|
|
79
|
+
node.value.options && node.value.options.forEach((item) => this.Visit(item, context));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected VisitExpandPath(node: any, context: any) {
|
|
83
|
+
this.navigationProperty = node.raw;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
protected VisitQueryOptions(node:any, context:any){
|
|
87
|
+
context.options = {};
|
|
88
|
+
node.value.options.forEach((option) => this.Visit(option, context));
|
|
89
|
+
|
|
90
|
+
this.query = context.query || {};
|
|
91
|
+
delete context.query;
|
|
92
|
+
|
|
93
|
+
this.sort = context.sort;
|
|
94
|
+
delete context.sort;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
protected VisitInlineCount(node:any, context:any){
|
|
98
|
+
this.inlinecount = Literal.convert(node.value.value, node.value.raw);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
protected VisitFilter(node:any, context:any){
|
|
102
|
+
context.query = {};
|
|
103
|
+
this.Visit(node.value, context);
|
|
104
|
+
delete context.identifier;
|
|
105
|
+
delete context.literal;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
protected VisitOrderBy(node:any, context:any){
|
|
109
|
+
context.sort = {};
|
|
110
|
+
node.value.items.forEach((item) => this.Visit(item, context));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
protected VisitSkip(node:any, context:any){
|
|
114
|
+
this.skip = +node.value.raw;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
protected VisitTop(node:any, context:any){
|
|
118
|
+
this.limit = +node.value.raw;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
protected VisitOrderByItem(node:any, context:any){
|
|
122
|
+
this.Visit(node.value.expr, context);
|
|
123
|
+
if (context.identifier) context.sort[context.identifier] = node.value.direction;
|
|
124
|
+
delete context.identifier;
|
|
125
|
+
delete context.literal;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
protected VisitSelect(node:any, context:any){
|
|
129
|
+
context.projection = {};
|
|
130
|
+
node.value.items.forEach((item) => this.Visit(item, context));
|
|
131
|
+
|
|
132
|
+
this.projection = context.projection;
|
|
133
|
+
delete context.projection;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
protected VisitSelectItem(node:any, context:any){
|
|
137
|
+
context.projection[node.raw.replace(/\//g, '.')] = 1;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
protected VisitAndExpression(node:any, context:any){
|
|
141
|
+
var query = context.query;
|
|
142
|
+
var leftQuery = {};
|
|
143
|
+
context.query = leftQuery;
|
|
144
|
+
this.Visit(node.value.left, context);
|
|
145
|
+
|
|
146
|
+
var rightQuery = {};
|
|
147
|
+
context.query = rightQuery;
|
|
148
|
+
this.Visit(node.value.right, context);
|
|
149
|
+
|
|
150
|
+
if (Object.keys(leftQuery).length > 0 && Object.keys(rightQuery).length > 0){
|
|
151
|
+
query.$and = [leftQuery, rightQuery];
|
|
152
|
+
}
|
|
153
|
+
context.query = query;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
protected VisitOrExpression(node:any, context:any){
|
|
157
|
+
var query = context.query;
|
|
158
|
+
var leftQuery = {};
|
|
159
|
+
context.query = leftQuery;
|
|
160
|
+
this.Visit(node.value.left, context);
|
|
161
|
+
|
|
162
|
+
var rightQuery = {};
|
|
163
|
+
context.query = rightQuery;
|
|
164
|
+
this.Visit(node.value.right, context);
|
|
165
|
+
|
|
166
|
+
if (Object.keys(leftQuery).length > 0 && Object.keys(rightQuery).length > 0){
|
|
167
|
+
query.$or = [leftQuery, rightQuery];
|
|
168
|
+
}
|
|
169
|
+
context.query = query;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
protected VisitBoolParenExpression(node:any, context:any){
|
|
173
|
+
this.Visit(node.value, context);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
protected VisitCommonExpression(node:any, context:any){
|
|
177
|
+
this.Visit(node.value, context);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
protected VisitFirstMemberExpression(node:any, context:any){
|
|
181
|
+
this.Visit(node.value, context);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
protected VisitMemberExpression(node:any, context:any){
|
|
185
|
+
this.Visit(node.value, context);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
protected VisitPropertyPathExpression(node:any, context:any){
|
|
189
|
+
if (node.value.current && node.value.next){
|
|
190
|
+
this.Visit(node.value.current, context);
|
|
191
|
+
if (context.identifier) context.identifier += ".";
|
|
192
|
+
this.Visit(node.value.next, context);
|
|
193
|
+
}else this.Visit(node.value, context);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
protected VisitSingleNavigationExpression(node:any, context:any){
|
|
197
|
+
if (node.value.current && node.value.next){
|
|
198
|
+
this.Visit(node.value.current, context);
|
|
199
|
+
this.Visit(node.value.next, context);
|
|
200
|
+
}else this.Visit(node.value, context);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
protected VisitODataIdentifier(node:any, context:any){
|
|
204
|
+
context.identifier = (context.identifier || "") + node.value.name;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
protected VisitNotExpression(node:any, context:any){
|
|
208
|
+
this.Visit(node.value, context);
|
|
209
|
+
if (context.query){
|
|
210
|
+
for (var prop in context.query){
|
|
211
|
+
context.query[prop] = { $not: context.query[prop] };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
protected VisitEqualsExpression(node:any, context:any){
|
|
217
|
+
this.Visit(node.value.left, context);
|
|
218
|
+
this.Visit(node.value.right, context);
|
|
219
|
+
|
|
220
|
+
if (context.identifier) context.query[context.identifier] = context.literal;
|
|
221
|
+
delete context.identifier;
|
|
222
|
+
delete context.literal;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
protected VisitNotEqualsExpression(node:any, context:any){
|
|
226
|
+
this.Visit(node.value.left, context);
|
|
227
|
+
this.Visit(node.value.right, context);
|
|
228
|
+
if (context.identifier) context.query[context.identifier] = { $ne: context.literal };
|
|
229
|
+
delete context.identifier;
|
|
230
|
+
delete context.literal;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
protected VisitInExpression(node:any, context:any){
|
|
234
|
+
this.Visit(node.value.left, context);
|
|
235
|
+
this.Visit(node.value.right, context);
|
|
236
|
+
if (context.identifier)
|
|
237
|
+
context.query[context.identifier] = {
|
|
238
|
+
$in: JSON.parse(`[${node.value.right.raw.replace(/\'/g, "\"").slice(1).slice(0, -1)}]`)
|
|
239
|
+
};
|
|
240
|
+
delete context.identifier;
|
|
241
|
+
delete context.literal;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
protected VisitLesserThanExpression(node:any, context:any){
|
|
245
|
+
this.Visit(node.value.left, context);
|
|
246
|
+
this.Visit(node.value.right, context);
|
|
247
|
+
if (context.identifier) context.query[context.identifier] = { $lt: context.literal };
|
|
248
|
+
delete context.identifier;
|
|
249
|
+
delete context.literal;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
protected VisitLesserOrEqualsExpression(node:any, context:any){
|
|
253
|
+
this.Visit(node.value.left, context);
|
|
254
|
+
this.Visit(node.value.right, context);
|
|
255
|
+
if (context.identifier) context.query[context.identifier] = { $lte: context.literal };
|
|
256
|
+
delete context.identifier;
|
|
257
|
+
delete context.literal;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
protected VisitGreaterThanExpression(node:any, context:any){
|
|
261
|
+
this.Visit(node.value.left, context);
|
|
262
|
+
this.Visit(node.value.right, context);
|
|
263
|
+
if (context.identifier) context.query[context.identifier] = { $gt: context.literal };
|
|
264
|
+
delete context.identifier;
|
|
265
|
+
delete context.literal;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
protected VisitGreaterOrEqualsExpression(node:any, context:any){
|
|
269
|
+
this.Visit(node.value.left, context);
|
|
270
|
+
this.Visit(node.value.right, context);
|
|
271
|
+
if (context.identifier) context.query[context.identifier] = { $gte: context.literal };
|
|
272
|
+
delete context.identifier;
|
|
273
|
+
delete context.literal;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
protected VisitLiteral(node:any, context:any){
|
|
277
|
+
context.literal = Literal.convert(node.value, node.raw);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
protected VisitMethodCallExpression(node: any, context: any) {
|
|
281
|
+
var method = node.value.method;
|
|
282
|
+
(node.value.parameters || []).forEach(p => this.Visit(p, context));
|
|
283
|
+
if (context.identifier) {
|
|
284
|
+
switch (method) {
|
|
285
|
+
case "contains":
|
|
286
|
+
context.query[context.identifier] = new RegExp(context.literal, "gi");
|
|
287
|
+
break;
|
|
288
|
+
case "endswith":
|
|
289
|
+
context.query[context.identifier] = new RegExp(context.literal + "$", "gi");
|
|
290
|
+
break;
|
|
291
|
+
case "startswith":
|
|
292
|
+
context.query[context.identifier] = new RegExp("^" + context.literal, "gi");
|
|
293
|
+
break;
|
|
294
|
+
default:
|
|
295
|
+
throw new Error("Method call not implemented.")
|
|
296
|
+
}
|
|
297
|
+
delete context.identifier;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "./lib",
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"importHelpers": true,
|
|
8
|
+
"emitDecoratorMetadata": true,
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"noImplicitAny": false,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"noFallthroughCasesInSwitch": true,
|
|
14
|
+
//"noImplicitReturns": true,
|
|
15
|
+
"stripInternal": true,
|
|
16
|
+
"pretty": true,
|
|
17
|
+
"strictNullChecks": false,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"downlevelIteration": true,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"lib": [
|
|
22
|
+
"es5",
|
|
23
|
+
"es6",
|
|
24
|
+
"es2015",
|
|
25
|
+
"es2016",
|
|
26
|
+
"es2017",
|
|
27
|
+
"esnext"
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
"include": [
|
|
31
|
+
"./src/**/*"
|
|
32
|
+
]
|
|
33
|
+
}
|