@steedos/odata-v4-parser 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 +31 -0
- package/lib/expressions.d.ts +94 -0
- package/lib/expressions.js +942 -0
- package/lib/expressions.js.map +1 -0
- package/lib/json.d.ts +24 -0
- package/lib/json.js +391 -0
- package/lib/json.js.map +1 -0
- package/lib/lexer.d.ts +243 -0
- package/lib/lexer.js +595 -0
- package/lib/lexer.js.map +1 -0
- package/lib/nameOrIdentifier.d.ts +56 -0
- package/lib/nameOrIdentifier.js +850 -0
- package/lib/nameOrIdentifier.js.map +1 -0
- package/lib/odataUri.d.ts +6 -0
- package/lib/odataUri.js +34 -0
- package/lib/odataUri.js.map +1 -0
- package/lib/parser.d.ts +16 -0
- package/lib/parser.js +50 -0
- package/lib/parser.js.map +1 -0
- package/lib/primitiveLiteral.d.ts +63 -0
- package/lib/primitiveLiteral.js +793 -0
- package/lib/primitiveLiteral.js.map +1 -0
- package/lib/query.d.ts +42 -0
- package/lib/query.js +903 -0
- package/lib/query.js.map +1 -0
- package/lib/resourcePath.d.ts +31 -0
- package/lib/resourcePath.js +469 -0
- package/lib/resourcePath.js.map +1 -0
- package/lib/utils.d.ts +8 -0
- package/lib/utils.js +37 -0
- package/lib/utils.js.map +1 -0
- package/package.json +24 -0
- package/src/expressions.ts +825 -0
- package/src/json.ts +372 -0
- package/src/lexer.ts +491 -0
- package/src/nameOrIdentifier.ts +749 -0
- package/src/odataUri.ts +37 -0
- package/src/parser.ts +37 -0
- package/src/primitiveLiteral.ts +684 -0
- package/src/query.ts +884 -0
- package/src/resourcePath.ts +461 -0
- package/src/utils.ts +36 -0
- package/tsconfig.json +33 -0
package/src/odataUri.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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:03:14
|
|
6
|
+
* @Description:
|
|
7
|
+
*/
|
|
8
|
+
import Utils from "./utils";
|
|
9
|
+
import Lexer from "./lexer";
|
|
10
|
+
import Query from "./query";
|
|
11
|
+
import ResourcePath from "./resourcePath";
|
|
12
|
+
|
|
13
|
+
export namespace ODataUri {
|
|
14
|
+
export function odataUri(value: Utils.SourceArray, index: number, metadataContext?: any): Lexer.Token {
|
|
15
|
+
let resource = ResourcePath.resourcePath(value, index, metadataContext);
|
|
16
|
+
while (!resource && index < value.length) {
|
|
17
|
+
while (value[++index] !== 0x2f && index < value.length);
|
|
18
|
+
resource = ResourcePath.resourcePath(value, index, metadataContext);
|
|
19
|
+
}
|
|
20
|
+
if (!resource) return;
|
|
21
|
+
let start = index;
|
|
22
|
+
index = resource.next;
|
|
23
|
+
metadataContext = resource.metadata;
|
|
24
|
+
|
|
25
|
+
let query;
|
|
26
|
+
if (value[index] === 0x3f) {
|
|
27
|
+
query = Query.queryOptions(value, index + 1, metadataContext);
|
|
28
|
+
if (!query) return;
|
|
29
|
+
index = query.next;
|
|
30
|
+
delete resource.metadata;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return Lexer.tokenize(value, start, index, { resource, query }, Lexer.TokenType.ODataUri, <any>{ metadata: metadataContext });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default ODataUri;
|
package/src/parser.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Lexer from "./lexer";
|
|
2
|
+
import PrimitiveLiteral from "./primitiveLiteral";
|
|
3
|
+
import Expressions from "./expressions";
|
|
4
|
+
import Query from "./query";
|
|
5
|
+
import ResourcePath from "./resourcePath";
|
|
6
|
+
import ODataUri from "./odataUri";
|
|
7
|
+
|
|
8
|
+
export const parserFactory = function(fn) {
|
|
9
|
+
return function (source, options) {
|
|
10
|
+
options = options || {};
|
|
11
|
+
const raw = new Uint16Array(source.length);
|
|
12
|
+
let pos = 0;
|
|
13
|
+
for (let i = 0; i < source.length; i++) {
|
|
14
|
+
raw[i] = source.charCodeAt(i);
|
|
15
|
+
}
|
|
16
|
+
let result = fn(raw, pos, options.metadata);
|
|
17
|
+
if (!result) throw new Error("Fail at " + pos);
|
|
18
|
+
if (result.next < raw.length) throw new Error("Unexpected character at " + result.next);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class Parser {
|
|
24
|
+
odataUri(source: string, options?: any): Lexer.Token { return parserFactory(ODataUri.odataUri)(source, options); }
|
|
25
|
+
resourcePath(source: string, options?: any): Lexer.Token { return parserFactory(ResourcePath.resourcePath)(source, options); }
|
|
26
|
+
query(source: string, options?: any): Lexer.Token { return parserFactory(Query.queryOptions)(source, options); }
|
|
27
|
+
filter(source: string, options?: any): Lexer.Token { return parserFactory(Expressions.boolCommonExpr)(source, options); }
|
|
28
|
+
keys(source: string, options?: any): Lexer.Token { return parserFactory(Expressions.keyPredicate)(source, options); }
|
|
29
|
+
literal(source: string, options?: any): Lexer.Token { return parserFactory(PrimitiveLiteral.primitiveLiteral)(source, options); }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function odataUri(source: string, options?: any): Lexer.Token { return parserFactory(ODataUri.odataUri)(source, options); }
|
|
33
|
+
export function resourcePath(source: string, options?: any): Lexer.Token { return parserFactory(ResourcePath.resourcePath)(source, options); }
|
|
34
|
+
export function query(source: string, options?: any): Lexer.Token { return parserFactory(Query.queryOptions)(source, options); }
|
|
35
|
+
export function filter(source: string, options?: any): Lexer.Token { return parserFactory(Expressions.boolCommonExpr)(source, options); }
|
|
36
|
+
export function keys(source: string, options?: any): Lexer.Token { return parserFactory(Expressions.keyPredicate)(source, options); }
|
|
37
|
+
export function literal(source: string, options?: any): Lexer.Token { return parserFactory(PrimitiveLiteral.primitiveLiteral)(source, options); }
|