@shko.online/dataverse-odata 0.1.2 → 0.1.4

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.
Files changed (88) hide show
  1. package/.eslintrc.json +59 -0
  2. package/.prettierrc.json +8 -0
  3. package/CHANGELOG.md +14 -0
  4. package/lib/cjs/getExpandFromParser.js +19 -12
  5. package/lib/cjs/getFetchXmlFromParser.js +37 -35
  6. package/lib/cjs/getOrderByFromParser.js +28 -25
  7. package/lib/cjs/getSelectFromParser.js +13 -4
  8. package/lib/cjs/getTopFromParser.js +25 -21
  9. package/lib/cjs/getXQueryFromParser.js +9 -19
  10. package/lib/cjs/parseOData.js +2 -18
  11. package/lib/cjs/validators/atMostOnce.js +24 -0
  12. package/lib/cjs/validators/differentFromEmptyString.js +23 -0
  13. package/lib/cjs/validators/hasContent.js +24 -0
  14. package/lib/cjs/validators/isGuid.js +25 -0
  15. package/lib/cjs/validators/recognizedGuid.js +23 -0
  16. package/lib/esm/getExpandFromParser.js +18 -12
  17. package/lib/esm/getFetchXmlFromParser.js +37 -35
  18. package/lib/esm/getOrderByFromParser.js +28 -25
  19. package/lib/esm/getSelectFromParser.js +13 -4
  20. package/lib/esm/getTopFromParser.js +24 -21
  21. package/lib/esm/getXQueryFromParser.js +9 -18
  22. package/lib/esm/parseOData.js +2 -18
  23. package/lib/esm/validators/atMostOnce.js +17 -0
  24. package/lib/esm/validators/differentFromEmptyString.js +16 -0
  25. package/lib/esm/validators/hasContent.js +17 -0
  26. package/lib/esm/validators/isGuid.js +18 -0
  27. package/lib/esm/validators/recognizedGuid.js +16 -0
  28. package/lib/modern/getExpandFromParser.js +18 -12
  29. package/lib/modern/getFetchXmlFromParser.js +37 -35
  30. package/lib/modern/getOrderByFromParser.js +29 -26
  31. package/lib/modern/getSelectFromParser.js +13 -4
  32. package/lib/modern/getTopFromParser.js +24 -21
  33. package/lib/modern/getXQueryFromParser.js +9 -18
  34. package/lib/modern/parseOData.js +2 -18
  35. package/lib/modern/validators/atMostOnce.js +17 -0
  36. package/lib/modern/validators/differentFromEmptyString.js +16 -0
  37. package/lib/modern/validators/hasContent.js +17 -0
  38. package/lib/modern/validators/isGuid.js +18 -0
  39. package/lib/modern/validators/recognizedGuid.js +16 -0
  40. package/lib/ts3.4/OData.types.d.ts +118 -0
  41. package/lib/ts3.4/getSelectFromParser.d.ts +1 -1
  42. package/lib/ts3.4/validators/atMostOnce.d.ts +10 -0
  43. package/lib/ts3.4/validators/differentFromEmptyString.d.ts +9 -0
  44. package/lib/ts3.4/validators/hasContent.d.ts +10 -0
  45. package/lib/ts3.4/validators/isGuid.d.ts +9 -0
  46. package/lib/ts3.4/validators/recognizedGuid.d.ts +9 -0
  47. package/lib/ts3.9/OData.types.d.ts +154 -0
  48. package/lib/ts3.9/getExpandFromParser.d.ts.map +1 -1
  49. package/lib/ts3.9/getFetchXmlFromParser.d.ts.map +1 -1
  50. package/lib/ts3.9/getOrderByFromParser.d.ts.map +1 -1
  51. package/lib/ts3.9/getSelectFromParser.d.ts +1 -1
  52. package/lib/ts3.9/getSelectFromParser.d.ts.map +1 -1
  53. package/lib/ts3.9/getTopFromParser.d.ts.map +1 -1
  54. package/lib/ts3.9/getXQueryFromParser.d.ts.map +1 -1
  55. package/lib/ts3.9/parseOData.d.ts.map +1 -1
  56. package/lib/ts3.9/validators/atMostOnce.d.ts +10 -0
  57. package/lib/ts3.9/validators/atMostOnce.d.ts.map +1 -0
  58. package/lib/ts3.9/validators/differentFromEmptyString.d.ts +9 -0
  59. package/lib/ts3.9/validators/differentFromEmptyString.d.ts.map +1 -0
  60. package/lib/ts3.9/validators/hasContent.d.ts +10 -0
  61. package/lib/ts3.9/validators/hasContent.d.ts.map +1 -0
  62. package/lib/ts3.9/validators/isGuid.d.ts +9 -0
  63. package/lib/ts3.9/validators/isGuid.d.ts.map +1 -0
  64. package/lib/ts3.9/validators/recognizedGuid.d.ts +9 -0
  65. package/lib/ts3.9/validators/recognizedGuid.d.ts.map +1 -0
  66. package/package.json +1 -1
  67. package/src/OData.types.d.ts +33 -15
  68. package/src/getExpandFromParser.ts +23 -12
  69. package/src/getFetchXmlFromParser.ts +48 -45
  70. package/src/getOrderByFromParser.ts +30 -26
  71. package/src/getSelectFromParser.ts +13 -4
  72. package/src/getTopFromParser.ts +25 -21
  73. package/src/getXQueryFromParser.ts +10 -19
  74. package/src/parseOData.ts +10 -18
  75. package/src/validators/atMostOnce.ts +19 -0
  76. package/src/validators/differentFromEmptyString.ts +18 -0
  77. package/src/validators/hasContent.ts +19 -0
  78. package/src/validators/isGuid.ts +20 -0
  79. package/src/validators/recognizedGuid.ts +18 -0
  80. package/tsconfig.build.json +3 -0
  81. package/tsconfig.json +2 -5
  82. package/lib/cjs/validateNotEmpty.js +0 -17
  83. package/lib/esm/validateNotEmpty.js +0 -10
  84. package/lib/modern/validateNotEmpty.js +0 -10
  85. package/lib/ts3.4/validateNotEmpty.d.ts +0 -3
  86. package/lib/ts3.9/validateNotEmpty.d.ts +0 -3
  87. package/lib/ts3.9/validateNotEmpty.d.ts.map +0 -1
  88. package/src/validateNotEmpty.ts +0 -12
package/.eslintrc.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true
5
+ },
6
+ "extends": [
7
+ "eslint:recommended",
8
+ "plugin:react/recommended",
9
+ "plugin:@typescript-eslint/recommended",
10
+ "plugin:prettier/recommended",
11
+ "prettier",
12
+ "plugin:sonarjs/recommended"
13
+ ],
14
+ "parser": "@typescript-eslint/parser",
15
+ "parserOptions": {
16
+ "ecmaFeatures": {
17
+ "jsx": true
18
+ },
19
+ "ecmaVersion": 12,
20
+ "sourceType": "module"
21
+ },
22
+ "plugins": [
23
+ "react",
24
+ "react-hooks",
25
+ "@typescript-eslint",
26
+ "prettier",
27
+ "sonarjs"
28
+ ],
29
+ "settings": {
30
+ "react": {
31
+ "pragma": "React",
32
+ "version": "detect"
33
+ }
34
+ },
35
+ "ignorePatterns": ["**/generated/*.ts"],
36
+ "rules": {
37
+ "eqeqeq": [2, "smart"],
38
+ "react-hooks/exhaustive-deps": "warn",
39
+ "prettier/prettier": "error",
40
+ "arrow-body-style": "off",
41
+ "prefer-arrow-callback": "off",
42
+ "linebreak-style": [
43
+ "error",
44
+ "windows"
45
+ ],
46
+ "quotes": [
47
+ "error",
48
+ "single",
49
+ {
50
+ "avoidEscape": true,
51
+ "allowTemplateLiterals": true
52
+ }
53
+ ],
54
+ "semi": [
55
+ "error",
56
+ "always"
57
+ ]
58
+ }
59
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "all",
4
+ "singleQuote": true,
5
+ "printWidth": 120,
6
+ "tabWidth": 4,
7
+ "endOfLine":"auto"
8
+ }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [0.1.4](https://github.com/shko-online/dataverse-odata/compare/v0.1.3...v0.1.4) (2023-02-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * added orderby support ([ea3748a](https://github.com/shko-online/dataverse-odata/commit/ea3748a5569d6ce2a086ff14ceb4a99421ecd069))
7
+
8
+ ## [0.1.3](https://github.com/shko-online/dataverse-odata/compare/v0.1.2...v0.1.3) (2023-02-11)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Fixed bundled types ([abbd95b](https://github.com/shko-online/dataverse-odata/commit/abbd95bbc0d118e9c2c20cbeb224025e84e33a9e))
14
+
1
15
  ## [0.1.2](https://github.com/shko-online/dataverse-odata/compare/v0.1.1...v0.1.2) (2023-02-11)
2
16
 
3
17
 
@@ -5,27 +5,34 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getExpandFromParser = void 0;
7
7
  var _getSelectFromParser = require("./getSelectFromParser");
8
+ var _atMostOnce = require("./validators/atMostOnce");
9
+ const option = '$expand';
10
+
8
11
  /**
9
12
  * Parses the {@link ODataExpand.$expand $expand} query
10
13
  * @returns Returns `false` when the parse has an error
11
14
  */
12
15
  const getExpandFromParser = (parser, result) => {
13
- const $expand = parser.get('$expand');
14
- if ($expand !== null) {
15
- result.$expand = {};
16
- if (!extractExpand($expand, result)) {
17
- return false;
18
- }
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;
19
26
  }
20
27
  return true;
21
28
  };
22
29
  exports.getExpandFromParser = getExpandFromParser;
23
30
  const extractExpand = (value, $expand) => {
24
- const match = value.match(/^\s*(\w(\w|\d|_)*)\s*(,|\()?\s*/);
31
+ const match = value.match(/^\s*(\w(\w|\d|_)*)\s*(,|\(|\))?\s*/);
25
32
  if (match === null || match[0].length < value.length && match[3] === null || match[0].length === value.length && match[3] !== undefined) {
26
33
  $expand.error = {
27
34
  code: '0x0',
28
- message: 'invalid expand expression'
35
+ message: `Term '${value}' is not valid in a $select or $expand expression.`
29
36
  };
30
37
  return false;
31
38
  }
@@ -63,7 +70,7 @@ const extractExpand = (value, $expand) => {
63
70
  if (innerExpand.$expand === undefined && innerExpand.$select === undefined) {
64
71
  $expand.error = {
65
72
  code: '0x0',
66
- message: 'Empty expand'
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.`
67
74
  };
68
75
  return false;
69
76
  }
@@ -92,7 +99,7 @@ const getClosingBracket = value => {
92
99
  const match = value.substring(startAt).match(/\(|\)/);
93
100
  if (match === null) {
94
101
  return {
95
- error: 'no closing bracket found',
102
+ error: 'Found an unbalanced bracket expression.',
96
103
  index: -1
97
104
  };
98
105
  }
@@ -106,10 +113,10 @@ const getClosingBracket = value => {
106
113
  } else {
107
114
  depth += 1;
108
115
  }
109
- startAt = (match.index || 0) + 1;
116
+ startAt += (match.index || 0) + 1;
110
117
  }
111
118
  return {
112
- error: 'no closing bracket found',
119
+ error: 'Found an unbalanced bracket expression.',
113
120
  index: -1
114
121
  };
115
122
  };
@@ -4,47 +4,49 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getFetchXmlFromParser = void 0;
7
+ var _atMostOnce = require("./validators/atMostOnce");
8
+ var _differentFromEmptyString = require("./validators/differentFromEmptyString");
9
+ const option = 'fetchXml';
10
+
7
11
  /**
8
12
  * Parses the {@link ODataFetch.fetchXml fetchXml} query
9
13
  * @returns Returns `false` when the parse has an error
10
14
  */
11
15
  const getFetchXmlFromParser = (parser, result) => {
12
- const fetchXml = parser.get('fetchXml');
13
- if (fetchXml !== null) {
14
- if (fetchXml === '') {
15
- result.error = {
16
- code: '0x80040203',
17
- message: 'Expected non-empty string.'
18
- };
19
- return false;
20
- }
21
- const serializer = new DOMParser();
22
- const fetchXmlDocument = serializer.parseFromString(fetchXml, 'text/xml');
23
- if (fetchXmlDocument.documentElement.tagName === 'parsererror') {
24
- result.error = {
25
- code: '0x80040201',
26
- message: 'Invalid XML.'
27
- };
28
- return false;
29
- }
30
- const entity = fetchXmlDocument.evaluate('fetch/entity', fetchXmlDocument, null, XPathResult.ANY_TYPE, null).iterateNext();
31
- if (fetchXmlDocument.documentElement.children.length != 1 || !entity || !entity.getAttribute('name')) {
32
- result.error = {
33
- code: '0x80041102',
34
- message: 'Entity Name was not specified in FetchXml String.'
35
- };
36
- return false;
37
- }
38
- 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();
39
- if (invalidAttribute) {
40
- result.error = {
41
- code: '0x8004111c',
42
- message: `Invalid Child Node, valid nodes are filter, order, link-entity, attribute, all-attributes, no-attrs. NodeName = ${invalidAttribute.tagName} NodeXml = ${invalidAttribute.outerHTML}`
43
- };
44
- return false;
45
- }
46
- result.fetchXml = fetchXmlDocument;
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;
47
48
  }
49
+ result.fetchXml = fetchXmlDocument;
48
50
  return true;
49
51
  };
50
52
  exports.getFetchXmlFromParser = getFetchXmlFromParser;
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getOrderByFromParser = void 0;
7
- var _validateNotEmpty = require("./validateNotEmpty");
7
+ var _atMostOnce = require("./validators/atMostOnce");
8
+ var _hasContent = require("./validators/hasContent");
9
+ const option = '$orderby';
8
10
  const edmProperty = /\w{1-255}/gi;
9
11
 
10
12
  /**
@@ -12,33 +14,34 @@ const edmProperty = /\w{1-255}/gi;
12
14
  * @returns Returns `false` when the parse has an error
13
15
  */
14
16
  const getOrderByFromParser = (parser, result) => {
15
- let $orderby = parser.get('$orderby');
16
- if ($orderby !== null) {
17
- if (!(0, _validateNotEmpty.validateNotEmpty)('$orderby', $orderby, 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
+ const orderByArray = [];
26
+ for (let i = 0; i < $orderby.length; i++) {
27
+ if (false /* syntax error */) {
28
+ result.error = {
29
+ code: '0x0',
30
+ message: `Syntax error at position ${i} in '${$orderby}'.`
31
+ };
18
32
  return false;
19
33
  }
20
- $orderby = $orderby.trimEnd();
21
- const orderByArray = [];
22
- for (let i = 0; i < $orderby.length; i++) {
23
- if (false /* syntax error */) {
24
- result.error = {
25
- code: '0x0',
26
- message: `Syntax error at position ${i} in '${$orderby}'.`
27
- };
28
- return false;
29
- }
30
- }
31
- orderByArray.forEach(orderBy => {
32
- if (!orderBy.column?.match(edmProperty)) {
33
- result.error = {
34
- code: '0x80060888',
35
- message: 'Order By Property must be of type EdmProperty'
36
- };
37
- return false;
38
- }
39
- });
40
- result.$orderby = orderByArray;
41
34
  }
35
+ orderByArray.forEach(orderBy => {
36
+ if (!orderBy.column?.match(edmProperty)) {
37
+ result.error = {
38
+ code: '0x80060888',
39
+ message: 'Order By Property must be of type EdmProperty'
40
+ };
41
+ return false;
42
+ }
43
+ });
44
+ result.$orderby = orderByArray;
42
45
  return true;
43
46
  };
44
47
  exports.getOrderByFromParser = getOrderByFromParser;
@@ -4,14 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getSelectFromParser = void 0;
7
+ var _atMostOnce = require("./validators/atMostOnce");
8
+ const option = '$select';
9
+
7
10
  /**
8
11
  * Parses the {@link ODataSelect.$select $select} query
9
- * @returns Returns `false` when the parse has an error
12
+ * @returns {boolean} Returns `false` when the parse has an error
10
13
  */
11
14
  const getSelectFromParser = (parser, result) => {
12
- const $select = parser.get('$select');
13
- if ($select !== null) {
14
- result.$select = $select.split(',');
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(',');
15
24
  }
16
25
  return true;
17
26
  };
@@ -4,33 +4,37 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getTopFromParser = void 0;
7
- var _validateNotEmpty = require("./validateNotEmpty");
7
+ var _atMostOnce = require("./validators/atMostOnce");
8
+ var _hasContent = require("./validators/hasContent");
9
+ const option = '$top';
10
+
8
11
  /**
9
12
  * Parses the {@link ODataTop.$top $top} query
10
13
  * @returns Returns `false` when the parse has an error
11
14
  */
12
15
  const getTopFromParser = (parser, result) => {
13
- const $topValue = parser.get('$top');
14
- if ($topValue !== null) {
15
- if (!(0, _validateNotEmpty.validateNotEmpty)('$orderby', $topValue, result)) {
16
- return false;
17
- }
18
- let $top;
19
- if (!$topValue.match(/^\d+$/) || ($top = parseInt($topValue)) < 0) {
20
- result.error = {
21
- code: '0x0',
22
- message: `Invalid value '${$topValue}' for $top query option found. The $top query option requires a non-negative integer value.`
23
- };
24
- return false;
25
- } else if ($top === 0) {
26
- result.error = {
27
- code: '0x0',
28
- message: `Invalid value for $top query option.`
29
- };
30
- return false;
31
- }
32
- result.$top = $top;
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;
33
36
  }
37
+ result.$top = $top;
34
38
  return true;
35
39
  };
36
40
  exports.getTopFromParser = getTopFromParser;
@@ -4,32 +4,22 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getXQueryFromParser = 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
-
7
+ var _isGuid = require("./validators/isGuid");
8
+ var _recognizedGuid = require("./validators/recognizedGuid");
9
9
  /**
10
10
  * Parses the {@link ODataSavedQuery.savedQuery savedQuery} or
11
11
  * {@link ODataUserQuery.userQuery userQuery} query
12
12
  * @returns Returns `false` when the parse has an error
13
13
  */
14
14
  const getXQueryFromParser = (X, parser, result) => {
15
- const xQuery = parser.get(X);
16
- if (xQuery !== null) {
17
- if (!xQuery.trim()) {
18
- result.error = {
19
- code: '0x0',
20
- message: 'Unrecognized Guid format.'
21
- };
22
- return false;
23
- }
24
- if (!xQuery.match(guidRegex)) {
25
- result.error = {
26
- code: '0x0',
27
- message: 'Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).'
28
- };
29
- return false;
30
- }
31
- result[X] = xQuery;
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;
32
21
  }
22
+ result[X] = value[0];
33
23
  return true;
34
24
  };
35
25
  exports.getXQueryFromParser = getXQueryFromParser;
@@ -9,6 +9,7 @@ var _getSelectFromParser = require("./getSelectFromParser");
9
9
  var _getExpandFromParser = require("./getExpandFromParser");
10
10
  var _getFetchXmlFromParser = require("./getFetchXmlFromParser");
11
11
  var _getXQueryFromParser = require("./getXQueryFromParser");
12
+ var _getOrderByFromParser = require("./getOrderByFromParser");
12
13
  /**
13
14
  * parses the OData query and applies some Dataverse validations
14
15
  * @param query The OData query
@@ -17,24 +18,7 @@ var _getXQueryFromParser = require("./getXQueryFromParser");
17
18
  const parseOData = query => {
18
19
  const parser = new URLSearchParams(query);
19
20
  const result = {};
20
- if (!(0, _getExpandFromParser.getExpandFromParser)(parser, result)) {
21
- return result;
22
- }
23
- if (!(0, _getSelectFromParser.getSelectFromParser)(parser, result)) {
24
- return result;
25
- }
26
- if (!(0, _getTopFromParser.getTopFromParser)(parser, result)) {
27
- return result;
28
- }
29
- if (!(0, _getFetchXmlFromParser.getFetchXmlFromParser)(parser, result)) {
30
- return result;
31
- }
32
- if (!(0, _getXQueryFromParser.getXQueryFromParser)('savedQuery', parser, result)) {
33
- return result;
34
- }
35
- if (!(0, _getXQueryFromParser.getXQueryFromParser)('userQuery', parser, result)) {
36
- return result;
37
- }
21
+ (0, _getExpandFromParser.getExpandFromParser)(parser, result) && (0, _getSelectFromParser.getSelectFromParser)(parser, result) && (0, _getTopFromParser.getTopFromParser)(parser, result) && (0, _getFetchXmlFromParser.getFetchXmlFromParser)(parser, result) && (0, _getXQueryFromParser.getXQueryFromParser)('savedQuery', parser, result) && (0, _getXQueryFromParser.getXQueryFromParser)('userQuery', parser, result) && (0, _getOrderByFromParser.getOrderByFromParser)(parser, result);
38
22
  return result;
39
23
  };
40
24
  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.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 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;