@shko.online/dataverse-odata 0.1.5 → 0.1.6
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/.github/workflows/publish.yml +3 -3
- package/CHANGELOG.md +7 -0
- package/lib/cjs/OData.types.d.js +1 -0
- package/lib/cjs/getAliasedProperty.js +36 -0
- package/lib/cjs/getExpandFromParser.js +122 -0
- package/lib/cjs/getFetchXmlFromParser.js +52 -0
- package/lib/cjs/getFilterFromParser.js +31 -0
- package/lib/cjs/getOrderByFromParser.js +78 -0
- package/lib/cjs/getSelectFromParser.js +27 -0
- package/lib/cjs/getTopFromParser.js +40 -0
- package/lib/cjs/getXQueryFromParser.js +25 -0
- package/lib/cjs/index.js +56 -0
- package/lib/cjs/parseOData.js +25 -0
- package/lib/cjs/validators/atMostOnce.js +24 -0
- package/lib/cjs/validators/differentFromEmptyString.js +23 -0
- package/lib/cjs/validators/hasContent.js +24 -0
- package/lib/cjs/validators/isGuid.js +25 -0
- package/lib/cjs/validators/recognizedGuid.js +23 -0
- package/lib/esm/OData.types.d.js +0 -0
- package/lib/esm/getAliasedProperty.js +29 -0
- package/lib/esm/getExpandFromParser.js +115 -0
- package/lib/esm/getFetchXmlFromParser.js +45 -0
- package/lib/esm/getFilterFromParser.js +24 -0
- package/lib/esm/getOrderByFromParser.js +71 -0
- package/lib/esm/getSelectFromParser.js +20 -0
- package/lib/esm/getTopFromParser.js +33 -0
- package/lib/esm/getXQueryFromParser.js +19 -0
- package/lib/esm/index.js +9 -0
- package/lib/esm/parseOData.js +19 -0
- package/lib/esm/validators/atMostOnce.js +17 -0
- package/lib/esm/validators/differentFromEmptyString.js +16 -0
- package/lib/esm/validators/hasContent.js +17 -0
- package/lib/esm/validators/isGuid.js +18 -0
- package/lib/esm/validators/recognizedGuid.js +16 -0
- package/lib/modern/OData.types.d.js +0 -0
- package/lib/modern/getAliasedProperty.js +29 -0
- package/lib/modern/getExpandFromParser.js +115 -0
- package/lib/modern/getFetchXmlFromParser.js +45 -0
- package/lib/modern/getFilterFromParser.js +24 -0
- package/lib/modern/getOrderByFromParser.js +72 -0
- package/lib/modern/getSelectFromParser.js +20 -0
- package/lib/modern/getTopFromParser.js +33 -0
- package/lib/modern/getXQueryFromParser.js +19 -0
- package/lib/modern/index.js +9 -0
- package/lib/modern/parseOData.js +19 -0
- package/lib/modern/validators/atMostOnce.js +17 -0
- package/lib/modern/validators/differentFromEmptyString.js +16 -0
- package/lib/modern/validators/hasContent.js +17 -0
- package/lib/modern/validators/isGuid.js +18 -0
- package/lib/modern/validators/recognizedGuid.js +16 -0
- package/lib/ts3.4/OData.types.d.ts +141 -0
- package/lib/ts3.4/getAliasedProperty.d.ts +10 -0
- package/lib/ts3.4/getExpandFromParser.d.ts +7 -0
- package/lib/ts3.4/getFetchXmlFromParser.d.ts +7 -0
- package/lib/ts3.4/getFilterFromParser.d.ts +7 -0
- package/lib/ts3.4/getOrderByFromParser.d.ts +7 -0
- package/lib/ts3.4/getSelectFromParser.d.ts +7 -0
- package/lib/ts3.4/getTopFromParser.d.ts +7 -0
- package/lib/ts3.4/getXQueryFromParser.d.ts +8 -0
- package/lib/ts3.4/index.d.ts +11 -0
- package/lib/ts3.4/parseOData.d.ts +8 -0
- package/lib/ts3.4/validators/atMostOnce.d.ts +10 -0
- package/lib/ts3.4/validators/differentFromEmptyString.d.ts +9 -0
- package/lib/ts3.4/validators/hasContent.d.ts +10 -0
- package/lib/ts3.4/validators/isGuid.d.ts +9 -0
- package/lib/ts3.4/validators/recognizedGuid.d.ts +9 -0
- package/lib/ts3.9/OData.types.d.ts +141 -0
- package/lib/ts3.9/getAliasedProperty.d.ts +10 -0
- package/lib/ts3.9/getExpandFromParser.d.ts +7 -0
- package/lib/ts3.9/getFetchXmlFromParser.d.ts +7 -0
- package/lib/ts3.9/getFilterFromParser.d.ts +7 -0
- package/lib/ts3.9/getOrderByFromParser.d.ts +7 -0
- package/lib/ts3.9/getSelectFromParser.d.ts +7 -0
- package/lib/ts3.9/getTopFromParser.d.ts +7 -0
- package/lib/ts3.9/getXQueryFromParser.d.ts +8 -0
- package/lib/ts3.9/index.d.ts +11 -0
- package/lib/ts3.9/parseOData.d.ts +8 -0
- package/lib/ts3.9/validators/atMostOnce.d.ts +10 -0
- package/lib/ts3.9/validators/differentFromEmptyString.d.ts +9 -0
- package/lib/ts3.9/validators/hasContent.d.ts +10 -0
- package/lib/ts3.9/validators/isGuid.d.ts +9 -0
- package/lib/ts3.9/validators/recognizedGuid.d.ts +9 -0
- package/lib/ts4.2/OData.types.d.ts +183 -0
- package/lib/ts4.2/getAliasedProperty.d.ts +10 -0
- package/lib/ts4.2/getAliasedProperty.d.ts.map +1 -0
- package/lib/ts4.2/getExpandFromParser.d.ts +7 -0
- package/lib/ts4.2/getExpandFromParser.d.ts.map +1 -0
- package/lib/ts4.2/getFetchXmlFromParser.d.ts +7 -0
- package/lib/ts4.2/getFetchXmlFromParser.d.ts.map +1 -0
- package/lib/ts4.2/getFilterFromParser.d.ts +7 -0
- package/lib/ts4.2/getFilterFromParser.d.ts.map +1 -0
- package/lib/ts4.2/getOrderByFromParser.d.ts +7 -0
- package/lib/ts4.2/getOrderByFromParser.d.ts.map +1 -0
- package/lib/ts4.2/getSelectFromParser.d.ts +7 -0
- package/lib/ts4.2/getSelectFromParser.d.ts.map +1 -0
- package/lib/ts4.2/getTopFromParser.d.ts +7 -0
- package/lib/ts4.2/getTopFromParser.d.ts.map +1 -0
- package/lib/ts4.2/getXQueryFromParser.d.ts +8 -0
- package/lib/ts4.2/getXQueryFromParser.d.ts.map +1 -0
- package/lib/ts4.2/index.d.ts +11 -0
- package/lib/ts4.2/index.d.ts.map +1 -0
- package/lib/ts4.2/parseOData.d.ts +8 -0
- package/lib/ts4.2/parseOData.d.ts.map +1 -0
- package/lib/ts4.2/validators/atMostOnce.d.ts +10 -0
- package/lib/ts4.2/validators/atMostOnce.d.ts.map +1 -0
- package/lib/ts4.2/validators/differentFromEmptyString.d.ts +9 -0
- package/lib/ts4.2/validators/differentFromEmptyString.d.ts.map +1 -0
- package/lib/ts4.2/validators/hasContent.d.ts +10 -0
- package/lib/ts4.2/validators/hasContent.d.ts.map +1 -0
- package/lib/ts4.2/validators/isGuid.d.ts +9 -0
- package/lib/ts4.2/validators/isGuid.d.ts.map +1 -0
- package/lib/ts4.2/validators/recognizedGuid.d.ts +9 -0
- package/lib/ts4.2/validators/recognizedGuid.d.ts.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [0.1.6](https://github.com/Shko-Online/dataverse-odata/compare/v0.1.5...v0.1.6) (2026-03-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* build before publish ([abf325d](https://github.com/Shko-Online/dataverse-odata/commit/abf325da1f8f7ee2d1ba44f35f0b182de9d9cb6a))
|
|
7
|
+
|
|
1
8
|
## [0.1.5](https://github.com/Shko-Online/dataverse-odata/compare/v0.1.4...v0.1.5) (2026-03-15)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAliasedProperty = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Recursively gets the value of an aliased property. For example, if the query is `$orderby=@p1` and `@p1=name`, this function will return `name`
|
|
9
|
+
* @param parser The URLSearchParams object containing the query parameters
|
|
10
|
+
* @param result Will contain the error details in case there is any
|
|
11
|
+
* @param property The property to expand
|
|
12
|
+
* @returns The expanded property or null when there is an error
|
|
13
|
+
*/
|
|
14
|
+
const getAliasedProperty = (parser, result, property) => {
|
|
15
|
+
let propertyName = parser.get(property);
|
|
16
|
+
if (!propertyName) {
|
|
17
|
+
result.error = {
|
|
18
|
+
code: '0x80060888',
|
|
19
|
+
message: 'Order By Property must be of type EdmProperty'
|
|
20
|
+
};
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (!/^[@a-zA-Z]\w+/gi.test(propertyName)) {
|
|
24
|
+
const position = propertyName.length;
|
|
25
|
+
result.error = {
|
|
26
|
+
code: '0x80060888',
|
|
27
|
+
message: `Syntax error at position ${position} in '${propertyName}'.`
|
|
28
|
+
};
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (propertyName.startsWith('@')) {
|
|
32
|
+
return getAliasedProperty(parser, result, propertyName);
|
|
33
|
+
}
|
|
34
|
+
return propertyName;
|
|
35
|
+
};
|
|
36
|
+
exports.getAliasedProperty = getAliasedProperty;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getExpandFromParser = void 0;
|
|
7
|
+
var _getSelectFromParser = require("./getSelectFromParser");
|
|
8
|
+
var _atMostOnce = require("./validators/atMostOnce");
|
|
9
|
+
const option = '$expand';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Parses the {@link ODataExpand.$expand $expand} query
|
|
13
|
+
* @returns Returns `false` when the parse has an error
|
|
14
|
+
*/
|
|
15
|
+
const getExpandFromParser = (parser, result) => {
|
|
16
|
+
const value = parser.getAll(option);
|
|
17
|
+
if (value.length === 0) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (!(0, _atMostOnce.atMostOnce)(option, value, result)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
result.$expand = {};
|
|
24
|
+
if (!extractExpand(value[0], result)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
exports.getExpandFromParser = getExpandFromParser;
|
|
30
|
+
const extractExpand = (value, $expand) => {
|
|
31
|
+
const match = value.match(/^\s*(\w(\w|\d|_)*)\s*(,|\(|\))?\s*/);
|
|
32
|
+
if (match === null || match[0].length < value.length && match[3] === null || match[0].length === value.length && match[3] !== undefined) {
|
|
33
|
+
$expand.error = {
|
|
34
|
+
code: '0x0',
|
|
35
|
+
message: `Term '${value}' is not valid in a $select or $expand expression.`
|
|
36
|
+
};
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
let matchSeparator = match[3];
|
|
40
|
+
let matchLength = match[0].length;
|
|
41
|
+
if (matchSeparator !== '(') {
|
|
42
|
+
if ($expand.$expand !== undefined) {
|
|
43
|
+
$expand.$expand[match[1]] = {
|
|
44
|
+
$select: []
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
const {
|
|
49
|
+
index,
|
|
50
|
+
error
|
|
51
|
+
} = getClosingBracket(value.substring(matchLength));
|
|
52
|
+
if (error) {
|
|
53
|
+
$expand.error = {
|
|
54
|
+
code: '0x0',
|
|
55
|
+
message: error
|
|
56
|
+
};
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if ($expand.$expand !== undefined) {
|
|
60
|
+
const innerExpand = {};
|
|
61
|
+
const parser = new URLSearchParams('?' + value.substring(matchLength, matchLength + index));
|
|
62
|
+
if (!(0, _getSelectFromParser.getSelectFromParser)(parser, innerExpand)) {
|
|
63
|
+
$expand.error = innerExpand.error;
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (!getExpandFromParser(parser, innerExpand)) {
|
|
67
|
+
$expand.error = innerExpand.error;
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
if (innerExpand.$expand === undefined && innerExpand.$select === undefined) {
|
|
71
|
+
$expand.error = {
|
|
72
|
+
code: '0x0',
|
|
73
|
+
message: `Missing expand option on navigation property '${match[1]}'. If a parenthesis expression follows an expanded navigation property, then at least one expand option must be provided.`
|
|
74
|
+
};
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
$expand.$expand[match[1]] = innerExpand;
|
|
78
|
+
}
|
|
79
|
+
matchLength = matchLength + index;
|
|
80
|
+
const secondMatch = new RegExp(/\s*(,?)\s*d/).exec(value.substring(matchLength + 1));
|
|
81
|
+
if (secondMatch !== null) {
|
|
82
|
+
matchLength = matchLength + secondMatch[0].length;
|
|
83
|
+
if (secondMatch[1] !== null) {
|
|
84
|
+
matchSeparator = ',';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (matchSeparator === ',') {
|
|
89
|
+
if (!extractExpand(value.substring(matchLength), $expand)) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
};
|
|
95
|
+
const getClosingBracket = value => {
|
|
96
|
+
let depth = 1;
|
|
97
|
+
let startAt = 0;
|
|
98
|
+
while (depth > 0) {
|
|
99
|
+
const match = value.substring(startAt).match(/\(|\)/);
|
|
100
|
+
if (match === null) {
|
|
101
|
+
return {
|
|
102
|
+
error: 'Found an unbalanced bracket expression.',
|
|
103
|
+
index: -1
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
if (match[0] === ')') {
|
|
107
|
+
depth -= 1;
|
|
108
|
+
if (depth === 0) {
|
|
109
|
+
return {
|
|
110
|
+
index: match.index || 0
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
depth += 1;
|
|
115
|
+
}
|
|
116
|
+
startAt += (match.index || 0) + 1;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
error: 'Found an unbalanced bracket expression.',
|
|
120
|
+
index: -1
|
|
121
|
+
};
|
|
122
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFetchXmlFromParser = void 0;
|
|
7
|
+
var _atMostOnce = require("./validators/atMostOnce");
|
|
8
|
+
var _differentFromEmptyString = require("./validators/differentFromEmptyString");
|
|
9
|
+
const option = 'fetchXml';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Parses the {@link ODataFetch.fetchXml fetchXml} query
|
|
13
|
+
* @returns Returns `false` when the parse has an error
|
|
14
|
+
*/
|
|
15
|
+
const getFetchXmlFromParser = (parser, result) => {
|
|
16
|
+
const value = parser.getAll(option);
|
|
17
|
+
if (value.length === 0) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (!(0, _atMostOnce.atMostOnce)(option, value, result) || !(0, _differentFromEmptyString.differentFromEmptyString)(value, result)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const fetchXml = value[0];
|
|
24
|
+
const serializer = new DOMParser();
|
|
25
|
+
const fetchXmlDocument = serializer.parseFromString(fetchXml, 'text/xml');
|
|
26
|
+
if (fetchXmlDocument.documentElement.tagName === 'parsererror') {
|
|
27
|
+
result.error = {
|
|
28
|
+
code: '0x80040201',
|
|
29
|
+
message: 'Invalid XML.'
|
|
30
|
+
};
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const entity = fetchXmlDocument.evaluate('fetch/entity', fetchXmlDocument, null, XPathResult.ANY_TYPE, null).iterateNext();
|
|
34
|
+
if (fetchXmlDocument.documentElement.children.length != 1 || !entity || !entity.getAttribute('name')) {
|
|
35
|
+
result.error = {
|
|
36
|
+
code: '0x80041102',
|
|
37
|
+
message: 'Entity Name was not specified in FetchXml String.'
|
|
38
|
+
};
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const invalidAttribute = fetchXmlDocument.evaluate('fetch/entity/*[not(self::filter or self::order or self::link-entity or self::attribute or self::all-attributes or self::no-attrs)]', fetchXmlDocument, null, XPathResult.ANY_TYPE, null).iterateNext();
|
|
42
|
+
if (invalidAttribute) {
|
|
43
|
+
result.error = {
|
|
44
|
+
code: '0x8004111c',
|
|
45
|
+
message: `Invalid Child Node, valid nodes are filter, order, link-entity, attribute, all-attributes, no-attrs. NodeName = ${invalidAttribute.tagName} NodeXml = ${invalidAttribute.outerHTML}`
|
|
46
|
+
};
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
result.fetchXml = fetchXmlDocument;
|
|
50
|
+
return true;
|
|
51
|
+
};
|
|
52
|
+
exports.getFetchXmlFromParser = getFetchXmlFromParser;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFilterFromParser = void 0;
|
|
7
|
+
var _atMostOnce = require("./validators/atMostOnce");
|
|
8
|
+
const option = '$filter';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parses the {@link ODataFilter.$filter $filter} query
|
|
12
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
13
|
+
*/
|
|
14
|
+
const getFilterFromParser = (parser, result) => {
|
|
15
|
+
const value = parser.getAll(option);
|
|
16
|
+
if (value.length === 0) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (!(0, _atMostOnce.atMostOnce)(option, value, result)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (value.length > 0) {
|
|
23
|
+
result.$filter = {
|
|
24
|
+
operator: 'eq',
|
|
25
|
+
left: '',
|
|
26
|
+
right: ''
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
};
|
|
31
|
+
exports.getFilterFromParser = getFilterFromParser;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getOrderByFromParser = void 0;
|
|
7
|
+
var _getAliasedProperty = require("./getAliasedProperty");
|
|
8
|
+
var _atMostOnce = require("./validators/atMostOnce");
|
|
9
|
+
var _hasContent = require("./validators/hasContent");
|
|
10
|
+
const option = '$orderby';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Parses the {@link ODataOrderBy.$orderby $orderby} query
|
|
14
|
+
* @returns Returns `false` when the parse has an error
|
|
15
|
+
*/
|
|
16
|
+
const getOrderByFromParser = (parser, result) => {
|
|
17
|
+
let value = parser.getAll(option);
|
|
18
|
+
if (value.length === 0) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (!(0, _atMostOnce.atMostOnce)(option, value, result) || !(0, _hasContent.hasContent)(option, value, result)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
let $orderby = value[0].trimEnd();
|
|
25
|
+
let $orderbyParts = $orderby.split(',');
|
|
26
|
+
const orderByArray = [];
|
|
27
|
+
let position = 0;
|
|
28
|
+
for (const element of $orderbyParts) {
|
|
29
|
+
const parts = Array.from(element.matchAll(/\s*(\S+)/gi));
|
|
30
|
+
if (parts.length > 2) {
|
|
31
|
+
position = position + parts[0][0].length + parts[1][0].length + parts[2][0].length;
|
|
32
|
+
result.error = {
|
|
33
|
+
code: '0x80060888',
|
|
34
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`
|
|
35
|
+
};
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (!/^[@a-zA-Z]\w+/gi.test(parts[0][1])) {
|
|
39
|
+
position = position + parts[0][0].length;
|
|
40
|
+
result.error = {
|
|
41
|
+
code: '0x80060888',
|
|
42
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`
|
|
43
|
+
};
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const orderBy = {
|
|
47
|
+
column: parts[0][1],
|
|
48
|
+
asc: true // default is ascending
|
|
49
|
+
};
|
|
50
|
+
if (parts[0][1].startsWith('@')) {
|
|
51
|
+
orderBy.column = (0, _getAliasedProperty.getAliasedProperty)(parser, result, parts[0][1]);
|
|
52
|
+
if (!orderBy.column) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (parts.length === 1) {
|
|
57
|
+
orderByArray.push(orderBy);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (parts[1][1].toLowerCase() === 'asc') {
|
|
61
|
+
orderBy.asc = true;
|
|
62
|
+
orderByArray.push(orderBy);
|
|
63
|
+
} else if (parts[1][1].toLowerCase() === 'desc') {
|
|
64
|
+
orderBy.asc = false;
|
|
65
|
+
orderByArray.push(orderBy);
|
|
66
|
+
} else {
|
|
67
|
+
position = position + parts[0][0].length + parts[1][0].length;
|
|
68
|
+
result.error = {
|
|
69
|
+
code: '0x80060888',
|
|
70
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`
|
|
71
|
+
};
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
result.$orderby = orderByArray;
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
exports.getOrderByFromParser = getOrderByFromParser;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSelectFromParser = void 0;
|
|
7
|
+
var _atMostOnce = require("./validators/atMostOnce");
|
|
8
|
+
const option = '$select';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parses the {@link ODataSelect.$select $select} query
|
|
12
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
13
|
+
*/
|
|
14
|
+
const getSelectFromParser = (parser, result) => {
|
|
15
|
+
const value = parser.getAll(option);
|
|
16
|
+
if (value.length === 0) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (!(0, _atMostOnce.atMostOnce)(option, value, result)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (value.length > 0) {
|
|
23
|
+
result.$select = value[0].split(',');
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
exports.getSelectFromParser = getSelectFromParser;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getTopFromParser = void 0;
|
|
7
|
+
var _atMostOnce = require("./validators/atMostOnce");
|
|
8
|
+
var _hasContent = require("./validators/hasContent");
|
|
9
|
+
const option = '$top';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Parses the {@link ODataTop.$top $top} query
|
|
13
|
+
* @returns Returns `false` when the parse has an error
|
|
14
|
+
*/
|
|
15
|
+
const getTopFromParser = (parser, result) => {
|
|
16
|
+
const value = parser.getAll(option);
|
|
17
|
+
if (value.length === 0) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (!(0, _atMostOnce.atMostOnce)(option, value, result) || !(0, _hasContent.hasContent)(option, value, result)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
let $top;
|
|
24
|
+
if (!value[0].match(/^\d+$/) || ($top = parseInt(value[0])) < 0) {
|
|
25
|
+
result.error = {
|
|
26
|
+
code: '0x0',
|
|
27
|
+
message: `Invalid value '${value}' for $top query option found. The $top query option requires a non-negative integer value.`
|
|
28
|
+
};
|
|
29
|
+
return false;
|
|
30
|
+
} else if ($top === 0) {
|
|
31
|
+
result.error = {
|
|
32
|
+
code: '0x0',
|
|
33
|
+
message: `Invalid value for $top query option.`
|
|
34
|
+
};
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
result.$top = $top;
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
exports.getTopFromParser = getTopFromParser;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getXQueryFromParser = void 0;
|
|
7
|
+
var _isGuid = require("./validators/isGuid");
|
|
8
|
+
var _recognizedGuid = require("./validators/recognizedGuid");
|
|
9
|
+
/**
|
|
10
|
+
* Parses the {@link ODataSavedQuery.savedQuery savedQuery} or
|
|
11
|
+
* {@link ODataUserQuery.userQuery userQuery} query
|
|
12
|
+
* @returns Returns `false` when the parse has an error
|
|
13
|
+
*/
|
|
14
|
+
const getXQueryFromParser = (X, parser, result) => {
|
|
15
|
+
const value = parser.getAll(X);
|
|
16
|
+
if (value.length === 0) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (!(0, _recognizedGuid.recognizedGuid)(value, result) || !(0, _isGuid.isGuid)(value, result)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
result[X] = value[0];
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
25
|
+
exports.getXQueryFromParser = getXQueryFromParser;
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
Object.defineProperty(exports, "getExpandFromParser", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _getExpandFromParser.getExpandFromParser;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "getFetchXmlFromParser", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _getFetchXmlFromParser.getFetchXmlFromParser;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "getOrderByFromParser", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _getOrderByFromParser.getOrderByFromParser;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "getSelectFromParser", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _getSelectFromParser.getSelectFromParser;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "getTopFromParser", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _getTopFromParser.getTopFromParser;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "getXQueryFromParser", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _getXQueryFromParser.getXQueryFromParser;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "parseOData", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _parseOData.parseOData;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
var _getExpandFromParser = require("./getExpandFromParser");
|
|
50
|
+
var _getFetchXmlFromParser = require("./getFetchXmlFromParser");
|
|
51
|
+
var _getOrderByFromParser = require("./getOrderByFromParser");
|
|
52
|
+
var _getSelectFromParser = require("./getSelectFromParser");
|
|
53
|
+
var _getTopFromParser = require("./getTopFromParser");
|
|
54
|
+
var _getXQueryFromParser = require("./getXQueryFromParser");
|
|
55
|
+
var _parseOData = require("./parseOData");
|
|
56
|
+
var _default = exports.default = _parseOData.parseOData;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseOData = void 0;
|
|
7
|
+
var _getTopFromParser = require("./getTopFromParser");
|
|
8
|
+
var _getSelectFromParser = require("./getSelectFromParser");
|
|
9
|
+
var _getExpandFromParser = require("./getExpandFromParser");
|
|
10
|
+
var _getFetchXmlFromParser = require("./getFetchXmlFromParser");
|
|
11
|
+
var _getXQueryFromParser = require("./getXQueryFromParser");
|
|
12
|
+
var _getOrderByFromParser = require("./getOrderByFromParser");
|
|
13
|
+
var _getFilterFromParser = require("./getFilterFromParser");
|
|
14
|
+
/**
|
|
15
|
+
* parses the OData query and applies some Dataverse validations
|
|
16
|
+
* @param query The OData query
|
|
17
|
+
* @returns The parsed OData query
|
|
18
|
+
*/
|
|
19
|
+
const parseOData = query => {
|
|
20
|
+
const parser = new URLSearchParams(query);
|
|
21
|
+
const result = {};
|
|
22
|
+
(0, _getExpandFromParser.getExpandFromParser)(parser, result) && (0, _getFetchXmlFromParser.getFetchXmlFromParser)(parser, result) && (0, _getFilterFromParser.getFilterFromParser)(parser, result) && (0, _getSelectFromParser.getSelectFromParser)(parser, result) && (0, _getTopFromParser.getTopFromParser)(parser, result) && (0, _getXQueryFromParser.getXQueryFromParser)('savedQuery', parser, result) && (0, _getXQueryFromParser.getXQueryFromParser)('userQuery', parser, result) && (0, _getOrderByFromParser.getOrderByFromParser)(parser, result);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
exports.parseOData = parseOData;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.atMostOnce = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Options of this type must be specified at most once.
|
|
9
|
+
* @param option The option being validated (ex. $top)
|
|
10
|
+
* @param value The result of {@link URLSearchParams.prototype.getAll URLSearchParams.getAll}
|
|
11
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
12
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
13
|
+
*/
|
|
14
|
+
const atMostOnce = (option, value, result) => {
|
|
15
|
+
if (value.length > 1) {
|
|
16
|
+
result.error = {
|
|
17
|
+
code: '0x0',
|
|
18
|
+
message: `Query option '${option}' was specified more than once, but it must be specified at most once.`
|
|
19
|
+
};
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
exports.atMostOnce = atMostOnce;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.differentFromEmptyString = void 0;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
10
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
11
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
12
|
+
*/
|
|
13
|
+
const differentFromEmptyString = (value, result) => {
|
|
14
|
+
if (value[0] === '') {
|
|
15
|
+
result.error = {
|
|
16
|
+
code: '0x80040203',
|
|
17
|
+
message: 'Expected non-empty string.'
|
|
18
|
+
};
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
exports.differentFromEmptyString = differentFromEmptyString;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasContent = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Options of this type must be specified at most once.
|
|
9
|
+
* @param option The option being validated (ex. $top)
|
|
10
|
+
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
11
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
12
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
13
|
+
*/
|
|
14
|
+
const hasContent = (query, value, result) => {
|
|
15
|
+
if (!value[0].trim()) {
|
|
16
|
+
result.error = {
|
|
17
|
+
code: '0x0',
|
|
18
|
+
message: `The value for OData query '${query}' cannot be empty.`
|
|
19
|
+
};
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
exports.hasContent = hasContent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isGuid = void 0;
|
|
7
|
+
const guidRegex = /[0-9A-F]{8}\-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/gi;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
12
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
13
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
14
|
+
*/
|
|
15
|
+
const isGuid = (value, result) => {
|
|
16
|
+
if (!value[0].match(guidRegex)) {
|
|
17
|
+
result.error = {
|
|
18
|
+
code: '0x0',
|
|
19
|
+
message: 'Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).'
|
|
20
|
+
};
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
25
|
+
exports.isGuid = isGuid;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.recognizedGuid = void 0;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
10
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
11
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
12
|
+
*/
|
|
13
|
+
const recognizedGuid = (value, result) => {
|
|
14
|
+
if (!value[0].trim()) {
|
|
15
|
+
result.error = {
|
|
16
|
+
code: '0x0',
|
|
17
|
+
message: 'Unrecognized Guid format.'
|
|
18
|
+
};
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
exports.recognizedGuid = recognizedGuid;
|
|
File without changes
|