@shko.online/dataverse-odata 0.1.4 → 0.1.5

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 (102) hide show
  1. package/.editorconfig +8 -0
  2. package/.github/workflows/publish.yml +44 -0
  3. package/.prettierrc.json +7 -7
  4. package/.releaserc.yaml +23 -23
  5. package/CHANGELOG.md +7 -0
  6. package/LICENSE +21 -0
  7. package/azure-pipelines.yml +32 -0
  8. package/package.json +20 -11
  9. package/src/OData.types.d.ts +35 -6
  10. package/src/getAliasedProperty.ts +34 -0
  11. package/src/getExpandFromParser.ts +1 -1
  12. package/src/getFilterFromParser.ts +23 -0
  13. package/src/getOrderByFromParser.ts +46 -10
  14. package/src/parseOData.ts +3 -1
  15. package/src/validators/atMostOnce.ts +19 -19
  16. package/src/validators/differentFromEmptyString.ts +18 -18
  17. package/src/validators/hasContent.ts +19 -19
  18. package/src/validators/isGuid.ts +20 -20
  19. package/src/validators/recognizedGuid.ts +18 -18
  20. package/lib/cjs/OData.types.d.js +0 -1
  21. package/lib/cjs/getExpandFromParser.js +0 -122
  22. package/lib/cjs/getFetchXmlFromParser.js +0 -52
  23. package/lib/cjs/getOrderByFromParser.js +0 -47
  24. package/lib/cjs/getSelectFromParser.js +0 -27
  25. package/lib/cjs/getTopFromParser.js +0 -40
  26. package/lib/cjs/getXQueryFromParser.js +0 -25
  27. package/lib/cjs/index.js +0 -57
  28. package/lib/cjs/parseOData.js +0 -24
  29. package/lib/cjs/validators/atMostOnce.js +0 -24
  30. package/lib/cjs/validators/differentFromEmptyString.js +0 -23
  31. package/lib/cjs/validators/hasContent.js +0 -24
  32. package/lib/cjs/validators/isGuid.js +0 -25
  33. package/lib/cjs/validators/recognizedGuid.js +0 -23
  34. package/lib/esm/OData.types.d.js +0 -0
  35. package/lib/esm/getExpandFromParser.js +0 -115
  36. package/lib/esm/getFetchXmlFromParser.js +0 -45
  37. package/lib/esm/getOrderByFromParser.js +0 -40
  38. package/lib/esm/getSelectFromParser.js +0 -20
  39. package/lib/esm/getTopFromParser.js +0 -33
  40. package/lib/esm/getXQueryFromParser.js +0 -19
  41. package/lib/esm/index.js +0 -9
  42. package/lib/esm/parseOData.js +0 -18
  43. package/lib/esm/validators/atMostOnce.js +0 -17
  44. package/lib/esm/validators/differentFromEmptyString.js +0 -16
  45. package/lib/esm/validators/hasContent.js +0 -17
  46. package/lib/esm/validators/isGuid.js +0 -18
  47. package/lib/esm/validators/recognizedGuid.js +0 -16
  48. package/lib/modern/OData.types.d.js +0 -0
  49. package/lib/modern/getExpandFromParser.js +0 -115
  50. package/lib/modern/getFetchXmlFromParser.js +0 -45
  51. package/lib/modern/getOrderByFromParser.js +0 -41
  52. package/lib/modern/getSelectFromParser.js +0 -20
  53. package/lib/modern/getTopFromParser.js +0 -33
  54. package/lib/modern/getXQueryFromParser.js +0 -19
  55. package/lib/modern/index.js +0 -9
  56. package/lib/modern/parseOData.js +0 -18
  57. package/lib/modern/validators/atMostOnce.js +0 -17
  58. package/lib/modern/validators/differentFromEmptyString.js +0 -16
  59. package/lib/modern/validators/hasContent.js +0 -17
  60. package/lib/modern/validators/isGuid.js +0 -18
  61. package/lib/modern/validators/recognizedGuid.js +0 -16
  62. package/lib/ts3.4/OData.types.d.ts +0 -118
  63. package/lib/ts3.4/getExpandFromParser.d.ts +0 -7
  64. package/lib/ts3.4/getFetchXmlFromParser.d.ts +0 -7
  65. package/lib/ts3.4/getOrderByFromParser.d.ts +0 -7
  66. package/lib/ts3.4/getSelectFromParser.d.ts +0 -7
  67. package/lib/ts3.4/getTopFromParser.d.ts +0 -7
  68. package/lib/ts3.4/getXQueryFromParser.d.ts +0 -8
  69. package/lib/ts3.4/index.d.ts +0 -11
  70. package/lib/ts3.4/parseOData.d.ts +0 -8
  71. package/lib/ts3.4/validators/atMostOnce.d.ts +0 -10
  72. package/lib/ts3.4/validators/differentFromEmptyString.d.ts +0 -9
  73. package/lib/ts3.4/validators/hasContent.d.ts +0 -10
  74. package/lib/ts3.4/validators/isGuid.d.ts +0 -9
  75. package/lib/ts3.4/validators/recognizedGuid.d.ts +0 -9
  76. package/lib/ts3.9/OData.types.d.ts +0 -154
  77. package/lib/ts3.9/getExpandFromParser.d.ts +0 -7
  78. package/lib/ts3.9/getExpandFromParser.d.ts.map +0 -1
  79. package/lib/ts3.9/getFetchXmlFromParser.d.ts +0 -7
  80. package/lib/ts3.9/getFetchXmlFromParser.d.ts.map +0 -1
  81. package/lib/ts3.9/getOrderByFromParser.d.ts +0 -7
  82. package/lib/ts3.9/getOrderByFromParser.d.ts.map +0 -1
  83. package/lib/ts3.9/getSelectFromParser.d.ts +0 -7
  84. package/lib/ts3.9/getSelectFromParser.d.ts.map +0 -1
  85. package/lib/ts3.9/getTopFromParser.d.ts +0 -7
  86. package/lib/ts3.9/getTopFromParser.d.ts.map +0 -1
  87. package/lib/ts3.9/getXQueryFromParser.d.ts +0 -8
  88. package/lib/ts3.9/getXQueryFromParser.d.ts.map +0 -1
  89. package/lib/ts3.9/index.d.ts +0 -11
  90. package/lib/ts3.9/index.d.ts.map +0 -1
  91. package/lib/ts3.9/parseOData.d.ts +0 -8
  92. package/lib/ts3.9/parseOData.d.ts.map +0 -1
  93. package/lib/ts3.9/validators/atMostOnce.d.ts +0 -10
  94. package/lib/ts3.9/validators/atMostOnce.d.ts.map +0 -1
  95. package/lib/ts3.9/validators/differentFromEmptyString.d.ts +0 -9
  96. package/lib/ts3.9/validators/differentFromEmptyString.d.ts.map +0 -1
  97. package/lib/ts3.9/validators/hasContent.d.ts +0 -10
  98. package/lib/ts3.9/validators/hasContent.d.ts.map +0 -1
  99. package/lib/ts3.9/validators/isGuid.d.ts +0 -9
  100. package/lib/ts3.9/validators/isGuid.d.ts.map +0 -1
  101. package/lib/ts3.9/validators/recognizedGuid.d.ts +0 -9
  102. package/lib/ts3.9/validators/recognizedGuid.d.ts.map +0 -1
@@ -1,18 +1,18 @@
1
- import type { ODataQuery } from '../OData.types';
2
-
3
- /**
4
- *
5
- * @param value The result of {@link URLSearchParams.getAll getAll}
6
- * @param result The {@link ODataQuery} to append the error to
7
- * @returns {boolean} Returns `false` when the parse has an error
8
- */
9
- export const recognizedGuid = (value: string[], result: ODataQuery) => {
10
- if (!value[0].trim()) {
11
- result.error = {
12
- code: '0x0',
13
- message: 'Unrecognized Guid format.',
14
- };
15
- return false;
16
- }
17
- return true;
18
- };
1
+ import type { ODataQuery } from '../OData.types';
2
+
3
+ /**
4
+ *
5
+ * @param value The result of {@link URLSearchParams.getAll getAll}
6
+ * @param result The {@link ODataQuery} to append the error to
7
+ * @returns {boolean} Returns `false` when the parse has an error
8
+ */
9
+ export const recognizedGuid = (value: string[], result: ODataQuery) => {
10
+ if (!value[0].trim()) {
11
+ result.error = {
12
+ code: '0x0',
13
+ message: 'Unrecognized Guid format.',
14
+ };
15
+ return false;
16
+ }
17
+ return true;
18
+ };
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,122 +0,0 @@
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 = value.substring(matchLength + 1).match(/\s*(,?)\s*d/);
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
- };
@@ -1,52 +0,0 @@
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;
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getOrderByFromParser = void 0;
7
- var _atMostOnce = require("./validators/atMostOnce");
8
- var _hasContent = require("./validators/hasContent");
9
- const option = '$orderby';
10
- const edmProperty = /\w{1-255}/gi;
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
- 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
- };
32
- return false;
33
- }
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;
45
- return true;
46
- };
47
- exports.getOrderByFromParser = getOrderByFromParser;
@@ -1,27 +0,0 @@
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;
@@ -1,40 +0,0 @@
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;
@@ -1,25 +0,0 @@
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 DELETED
@@ -1,57 +0,0 @@
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 = _parseOData.parseOData;
57
- exports.default = _default;
@@ -1,24 +0,0 @@
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
- /**
14
- * parses the OData query and applies some Dataverse validations
15
- * @param query The OData query
16
- * @returns The parsed OData query
17
- */
18
- const parseOData = query => {
19
- const parser = new URLSearchParams(query);
20
- const result = {};
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);
22
- return result;
23
- };
24
- exports.parseOData = parseOData;
@@ -1,24 +0,0 @@
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;
@@ -1,23 +0,0 @@
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;
@@ -1,24 +0,0 @@
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;
@@ -1,25 +0,0 @@
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;
@@ -1,23 +0,0 @@
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
@@ -1,115 +0,0 @@
1
- import { getSelectFromParser } from './getSelectFromParser';
2
- import { atMostOnce } from './validators/atMostOnce';
3
- const option = '$expand';
4
-
5
- /**
6
- * Parses the {@link ODataExpand.$expand $expand} query
7
- * @returns Returns `false` when the parse has an error
8
- */
9
- export const getExpandFromParser = (parser, result) => {
10
- const value = parser.getAll(option);
11
- if (value.length === 0) {
12
- return true;
13
- }
14
- if (!atMostOnce(option, value, result)) {
15
- return false;
16
- }
17
- result.$expand = {};
18
- if (!extractExpand(value[0], result)) {
19
- return false;
20
- }
21
- return true;
22
- };
23
- const extractExpand = (value, $expand) => {
24
- const match = value.match(/^\s*(\w(\w|\d|_)*)\s*(,|\(|\))?\s*/);
25
- if (match === null || match[0].length < value.length && match[3] === null || match[0].length === value.length && match[3] !== undefined) {
26
- $expand.error = {
27
- code: '0x0',
28
- message: `Term '${value}' is not valid in a $select or $expand expression.`
29
- };
30
- return false;
31
- }
32
- let matchSeparator = match[3];
33
- let matchLength = match[0].length;
34
- if (matchSeparator !== '(') {
35
- if ($expand.$expand !== undefined) {
36
- $expand.$expand[match[1]] = {
37
- $select: []
38
- };
39
- }
40
- } else {
41
- const {
42
- index,
43
- error
44
- } = getClosingBracket(value.substring(matchLength));
45
- if (error) {
46
- $expand.error = {
47
- code: '0x0',
48
- message: error
49
- };
50
- return false;
51
- }
52
- if ($expand.$expand !== undefined) {
53
- const innerExpand = {};
54
- const parser = new URLSearchParams('?' + value.substring(matchLength, matchLength + index));
55
- if (!getSelectFromParser(parser, innerExpand)) {
56
- $expand.error = innerExpand.error;
57
- return false;
58
- }
59
- if (!getExpandFromParser(parser, innerExpand)) {
60
- $expand.error = innerExpand.error;
61
- return false;
62
- }
63
- if (innerExpand.$expand === undefined && innerExpand.$select === undefined) {
64
- $expand.error = {
65
- code: '0x0',
66
- 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
- };
68
- return false;
69
- }
70
- $expand.$expand[match[1]] = innerExpand;
71
- }
72
- matchLength = matchLength + index;
73
- const secondMatch = value.substring(matchLength + 1).match(/\s*(,?)\s*d/);
74
- if (secondMatch !== null) {
75
- matchLength = matchLength + secondMatch[0].length;
76
- if (secondMatch[1] !== null) {
77
- matchSeparator = ',';
78
- }
79
- }
80
- }
81
- if (matchSeparator === ',') {
82
- if (!extractExpand(value.substring(matchLength), $expand)) {
83
- return false;
84
- }
85
- }
86
- return true;
87
- };
88
- const getClosingBracket = value => {
89
- let depth = 1;
90
- let startAt = 0;
91
- while (depth > 0) {
92
- const match = value.substring(startAt).match(/\(|\)/);
93
- if (match === null) {
94
- return {
95
- error: 'Found an unbalanced bracket expression.',
96
- index: -1
97
- };
98
- }
99
- if (match[0] === ')') {
100
- depth -= 1;
101
- if (depth === 0) {
102
- return {
103
- index: match.index || 0
104
- };
105
- }
106
- } else {
107
- depth += 1;
108
- }
109
- startAt += (match.index || 0) + 1;
110
- }
111
- return {
112
- error: 'Found an unbalanced bracket expression.',
113
- index: -1
114
- };
115
- };