@shko.online/dataverse-odata 0.1.1 → 0.1.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.
Files changed (98) 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 +15 -15
  5. package/lib/cjs/getFetchXmlFromParser.js +13 -6
  6. package/lib/cjs/getOrderByFromParser.js +44 -0
  7. package/lib/cjs/getSelectFromParser.js +3 -3
  8. package/lib/cjs/getTopFromParser.js +9 -5
  9. package/lib/cjs/getXQueryFromParser.js +35 -0
  10. package/lib/cjs/index.js +42 -0
  11. package/lib/cjs/parseOData.js +11 -4
  12. package/lib/cjs/validateNotEmpty.js +17 -0
  13. package/lib/esm/getExpandFromParser.js +15 -15
  14. package/lib/esm/getFetchXmlFromParser.js +13 -6
  15. package/lib/esm/getOrderByFromParser.js +37 -0
  16. package/lib/esm/getSelectFromParser.js +3 -3
  17. package/lib/esm/getTopFromParser.js +10 -5
  18. package/lib/esm/getXQueryFromParser.js +28 -0
  19. package/lib/esm/index.js +6 -0
  20. package/lib/esm/parseOData.js +11 -4
  21. package/lib/esm/validateNotEmpty.js +10 -0
  22. package/lib/modern/getExpandFromParser.js +15 -15
  23. package/lib/modern/getFetchXmlFromParser.js +13 -6
  24. package/lib/modern/getOrderByFromParser.js +38 -0
  25. package/lib/modern/getSelectFromParser.js +3 -3
  26. package/lib/modern/getTopFromParser.js +10 -5
  27. package/lib/modern/getXQueryFromParser.js +28 -0
  28. package/lib/modern/index.js +6 -0
  29. package/lib/modern/parseOData.js +11 -4
  30. package/lib/modern/validateNotEmpty.js +10 -0
  31. package/lib/ts3.4/OData.types.d.ts +118 -0
  32. package/lib/ts3.4/getExpandFromParser.d.ts +2 -2
  33. package/lib/ts3.4/getFetchXmlFromParser.d.ts +2 -2
  34. package/lib/ts3.4/getOrderByFromParser.d.ts +7 -0
  35. package/lib/ts3.4/getSelectFromParser.d.ts +2 -2
  36. package/lib/ts3.4/getTopFromParser.d.ts +2 -2
  37. package/lib/ts3.4/getXQueryFromParser.d.ts +8 -0
  38. package/lib/ts3.4/index.d.ts +6 -0
  39. package/lib/ts3.4/validateNotEmpty.d.ts +3 -0
  40. package/lib/ts3.9/OData.types.d.ts +154 -0
  41. package/lib/ts3.9/getExpandFromParser.d.ts +2 -2
  42. package/lib/ts3.9/getFetchXmlFromParser.d.ts +2 -2
  43. package/lib/ts3.9/getFetchXmlFromParser.d.ts.map +1 -1
  44. package/lib/ts3.9/getOrderByFromParser.d.ts +7 -0
  45. package/lib/ts3.9/getOrderByFromParser.d.ts.map +1 -0
  46. package/lib/ts3.9/getSelectFromParser.d.ts +2 -2
  47. package/lib/ts3.9/getSelectFromParser.d.ts.map +1 -1
  48. package/lib/ts3.9/getTopFromParser.d.ts +2 -2
  49. package/lib/ts3.9/getTopFromParser.d.ts.map +1 -1
  50. package/lib/ts3.9/getXQueryFromParser.d.ts +8 -0
  51. package/lib/ts3.9/getXQueryFromParser.d.ts.map +1 -0
  52. package/lib/ts3.9/index.d.ts +6 -0
  53. package/lib/ts3.9/index.d.ts.map +1 -1
  54. package/lib/ts3.9/parseOData.d.ts.map +1 -1
  55. package/lib/ts3.9/validateNotEmpty.d.ts +3 -0
  56. package/lib/ts3.9/validateNotEmpty.d.ts.map +1 -0
  57. package/package.json +1 -1
  58. package/src/OData.types.d.ts +107 -14
  59. package/src/getExpandFromParser.ts +15 -15
  60. package/src/getFetchXmlFromParser.ts +15 -7
  61. package/src/getOrderByFromParser.ts +42 -0
  62. package/src/getSelectFromParser.ts +4 -4
  63. package/src/getTopFromParser.ts +11 -7
  64. package/src/getXQueryFromParser.ts +34 -0
  65. package/src/index.ts +7 -0
  66. package/src/parseOData.ts +11 -4
  67. package/src/validateNotEmpty.ts +12 -0
  68. package/tsconfig.build.json +3 -0
  69. package/tsconfig.json +2 -5
  70. package/jest.config.ts +0 -12
  71. package/lib/getExpandFromParser.d.ts +0 -7
  72. package/lib/getExpandFromParser.d.ts.map +0 -1
  73. package/lib/getExpandFromParser.js +0 -97
  74. package/lib/getExpandFromParser.js.map +0 -1
  75. package/lib/getFetchXmlFromParser.d.ts +0 -7
  76. package/lib/getFetchXmlFromParser.d.ts.map +0 -1
  77. package/lib/getFetchXmlFromParser.js +0 -41
  78. package/lib/getFetchXmlFromParser.js.map +0 -1
  79. package/lib/getSelectFromParser.d.ts +0 -7
  80. package/lib/getSelectFromParser.d.ts.map +0 -1
  81. package/lib/getSelectFromParser.js +0 -12
  82. package/lib/getSelectFromParser.js.map +0 -1
  83. package/lib/getTopFromParser.d.ts +0 -7
  84. package/lib/getTopFromParser.d.ts.map +0 -1
  85. package/lib/getTopFromParser.js +0 -27
  86. package/lib/getTopFromParser.js.map +0 -1
  87. package/lib/index.d.ts +0 -5
  88. package/lib/index.d.ts.map +0 -1
  89. package/lib/index.js +0 -4
  90. package/lib/index.js.map +0 -1
  91. package/lib/parseOData.d.ts +0 -3
  92. package/lib/parseOData.d.ts.map +0 -1
  93. package/lib/parseOData.js +0 -22
  94. package/lib/parseOData.js.map +0 -1
  95. package/tests/OData-Parser.$expand.test.ts +0 -39
  96. package/tests/OData-Parser.$top.test.ts +0 -36
  97. package/tests/OData-Parser.fetchXml.test.ts +0 -62
  98. package/tests/OData-Parser.test.ts +0 -17
@@ -1,27 +1,31 @@
1
- import type { ODataQuery } from './OData.types';
1
+ import type { ODataQuery, ODataTop } from './OData.types';
2
+ import { validateNotEmpty } from './validateNotEmpty';
2
3
 
3
4
  /**
4
- * Parses the $top query
5
- * @returns Returns true when the parse has an error
5
+ * Parses the {@link ODataTop.$top $top} query
6
+ * @returns Returns `false` when the parse has an error
6
7
  */
7
8
  export const getTopFromParser = (parser: URLSearchParams, result: ODataQuery): boolean => {
8
9
  const $topValue = parser.get('$top');
9
10
  if ($topValue !== null) {
10
- let $top;
11
+ if (!validateNotEmpty('$orderby', $topValue, result)) {
12
+ return false;
13
+ }
14
+ let $top: number;
11
15
  if (!$topValue.match(/^\d+$/) || ($top = parseInt($topValue)) < 0) {
12
16
  result.error = {
13
17
  code: '0x0',
14
18
  message: `Invalid value '${$topValue}' for $top query option found. The $top query option requires a non-negative integer value.`,
15
19
  };
16
- return true;
20
+ return false;
17
21
  } else if ($top === 0) {
18
22
  result.error = {
19
23
  code: '0x0',
20
24
  message: `Invalid value for $top query option.`,
21
25
  };
22
- return true;
26
+ return false;
23
27
  }
24
28
  result.$top = $top;
25
29
  }
26
- return false;
30
+ return true;
27
31
  };
@@ -0,0 +1,34 @@
1
+ import type { ODataQuery, ODataSavedQuery, ODataUserQuery } from './OData.types';
2
+
3
+ const guidRegex = /[0-9A-F]{8}\-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/gi;
4
+
5
+ /**
6
+ * Parses the {@link ODataSavedQuery.savedQuery savedQuery} or
7
+ * {@link ODataUserQuery.userQuery userQuery} query
8
+ * @returns Returns `false` when the parse has an error
9
+ */
10
+ export const getXQueryFromParser = (
11
+ X: 'savedQuery' | 'userQuery',
12
+ parser: URLSearchParams,
13
+ result: ODataQuery,
14
+ ): boolean => {
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;
32
+ }
33
+ return true;
34
+ };
package/src/index.ts CHANGED
@@ -12,6 +12,13 @@ export type {
12
12
  StandardOperators,
13
13
  } from './OData.types';
14
14
 
15
+ export { getExpandFromParser } from './getExpandFromParser';
16
+ export { getFetchXmlFromParser } from './getFetchXmlFromParser';
17
+ export { getOrderByFromParser } from './getOrderByFromParser';
18
+ export { getSelectFromParser } from './getSelectFromParser';
19
+ export { getTopFromParser } from './getTopFromParser';
20
+ export { getXQueryFromParser } from './getXQueryFromParser';
21
+
15
22
  export { parseOData } from './parseOData';
16
23
  import { parseOData } from './parseOData';
17
24
  export default parseOData;
package/src/parseOData.ts CHANGED
@@ -4,6 +4,7 @@ import { getTopFromParser } from './getTopFromParser';
4
4
  import { getSelectFromParser } from './getSelectFromParser';
5
5
  import { getExpandFromParser } from './getExpandFromParser';
6
6
  import { getFetchXmlFromParser } from './getFetchXmlFromParser';
7
+ import { getXQueryFromParser } from './getXQueryFromParser';
7
8
 
8
9
  /**
9
10
  * parses the OData query and applies some Dataverse validations
@@ -13,16 +14,22 @@ import { getFetchXmlFromParser } from './getFetchXmlFromParser';
13
14
  export const parseOData = (query: string) => {
14
15
  const parser = new URLSearchParams(query);
15
16
  const result = {} as ODataQuery;
16
- if (getExpandFromParser(parser, result)) {
17
+ if (!getExpandFromParser(parser, result)) {
17
18
  return result;
18
19
  }
19
- if (getSelectFromParser(parser, result)) {
20
+ if (!getSelectFromParser(parser, result)) {
20
21
  return result;
21
22
  }
22
- if (getTopFromParser(parser, result)) {
23
+ if (!getTopFromParser(parser, result)) {
23
24
  return result;
24
25
  }
25
- if (getFetchXmlFromParser(parser, result)) {
26
+ if (!getFetchXmlFromParser(parser, result)) {
27
+ return result;
28
+ }
29
+ if (!getXQueryFromParser('savedQuery', parser, result)) {
30
+ return result;
31
+ }
32
+ if (!getXQueryFromParser('userQuery', parser, result)) {
26
33
  return result;
27
34
  }
28
35
  return result;
@@ -0,0 +1,12 @@
1
+ import type { ODataQuery } from './OData.types';
2
+
3
+ export const validateNotEmpty = (query: string, value: string, result: ODataQuery) => {
4
+ if (!value.trim()) {
5
+ result.error = {
6
+ code: '0x0',
7
+ message: `The value for OData query '${query}' cannot be empty.`,
8
+ };
9
+ return false;
10
+ }
11
+ return true;
12
+ };
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
+ "include": [
4
+ "src"
5
+ ],
3
6
  "exclude": [
4
7
  "tests",
5
8
  "lib",
package/tsconfig.json CHANGED
@@ -16,11 +16,8 @@
16
16
  "resolveJsonModule": true,
17
17
  "declaration": true,
18
18
  "declarationMap": true,
19
- "sourceMap": true,
20
- "baseUrl": ".",
21
- "typeRoots": [
22
- "./node_modules/@types"
23
- ]
19
+ "sourceMap": true,
20
+ "baseUrl": "."
24
21
  },
25
22
  "exclude": [
26
23
  "node_modules",
package/jest.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import { JestConfigWithTsJest } from 'ts-jest';
2
-
3
- export default {
4
- testMatch: [' **/tests/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'],
5
- clearMocks: true,
6
- collectCoverage: true,
7
- coverageDirectory: 'coverage',
8
- coverageProvider: 'v8',
9
- preset: 'ts-jest',
10
- testEnvironment: 'jsdom',
11
- coverageReporters: ['cobertura', 'text', 'html']
12
- } as JestConfigWithTsJest;
@@ -1,7 +0,0 @@
1
- import type { ODataQuery } from './OData.types';
2
- /**
3
- * Parses the $expand query
4
- * @returns Returns true when the parse has an error
5
- */
6
- export declare const getExpandFromParser: (parser: URLSearchParams, result: ODataQuery) => boolean;
7
- //# sourceMappingURL=getExpandFromParser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getExpandFromParser.d.ts","sourceRoot":"","sources":["../src/getExpandFromParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA6C,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3F;;;GAGG;AACH,eAAO,MAAM,mBAAmB,WAAY,eAAe,UAAU,UAAU,KAAG,OAUjF,CAAC"}
@@ -1,97 +0,0 @@
1
- import { getSelectFromParser } from './getSelectFromParser';
2
- /**
3
- * Parses the $expand query
4
- * @returns Returns true when the parse has an error
5
- */
6
- export var getExpandFromParser = function (parser, result) {
7
- var $expand = parser.get('$expand');
8
- if ($expand !== null) {
9
- result.$expand = {};
10
- if (extractExpand($expand, result)) {
11
- return true;
12
- }
13
- }
14
- return false;
15
- };
16
- var extractExpand = function (value, $expand) {
17
- var match = value.match(/^\s*(\w(\w|\d|_)*)\s*(,|\()?\s*/);
18
- if (match === null ||
19
- (match[0].length < value.length && match[3] === null) ||
20
- (match[0].length === value.length && match[3] !== undefined)) {
21
- $expand.error = {
22
- code: '0x0',
23
- message: 'invalid expand expression',
24
- };
25
- return true;
26
- }
27
- var matchSeparator = match[3];
28
- var matchLength = match[0].length;
29
- if (matchSeparator !== '(') {
30
- if ($expand.$expand !== undefined) {
31
- $expand.$expand[match[1]] = { $select: [] };
32
- }
33
- }
34
- else {
35
- var _a = getClosingBracket(value.substring(matchLength)), index = _a.index, error = _a.error;
36
- if (error) {
37
- $expand.error = {
38
- code: '0x0',
39
- message: error,
40
- };
41
- return true;
42
- }
43
- if ($expand.$expand !== undefined) {
44
- var innerExpand = {};
45
- var parser = new URLSearchParams('?' + value.substring(matchLength, matchLength + index));
46
- if (getSelectFromParser(parser, innerExpand)) {
47
- $expand.error = innerExpand.error;
48
- return true;
49
- }
50
- if (getExpandFromParser(parser, innerExpand)) {
51
- $expand.error = innerExpand.error;
52
- return true;
53
- }
54
- if (innerExpand.$expand === undefined && innerExpand.$select === undefined) {
55
- $expand.error = { code: '0x0', message: 'Empty expand' };
56
- return true;
57
- }
58
- $expand.$expand[match[1]] = innerExpand;
59
- }
60
- matchLength = matchLength + index;
61
- var secondMatch = value.substring(matchLength + 1).match(/\s*(,?)\s*d/);
62
- if (secondMatch !== null) {
63
- matchLength = matchLength + secondMatch[0].length;
64
- if (secondMatch[1] !== null) {
65
- matchSeparator = ',';
66
- }
67
- }
68
- }
69
- if (matchSeparator === ',') {
70
- if (extractExpand(value.substring(matchLength), $expand)) {
71
- return true;
72
- }
73
- }
74
- return false;
75
- };
76
- var getClosingBracket = function (value) {
77
- var depth = 1;
78
- var startAt = 0;
79
- while (depth > 0) {
80
- var match = value.substring(startAt).match(/\(|\)/);
81
- if (match === null) {
82
- return { error: 'no closing bracket found', index: -1 };
83
- }
84
- if (match[0] === ')') {
85
- depth -= 1;
86
- if (depth === 0) {
87
- return { index: match.index || 0 };
88
- }
89
- }
90
- else {
91
- depth += 1;
92
- }
93
- startAt = (match.index || 0) + 1;
94
- }
95
- return { error: 'no closing bracket found', index: -1 };
96
- };
97
- //# sourceMappingURL=getExpandFromParser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getExpandFromParser.js","sourceRoot":"","sources":["../src/getExpandFromParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;GAGG;AACH,MAAM,CAAC,IAAM,mBAAmB,GAAG,UAAC,MAAuB,EAAE,MAAkB;IAC3E,IAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACtC,IAAI,OAAO,KAAK,IAAI,EAAE;QAClB,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;QAEpB,IAAI,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;YAChC,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,IAAM,aAAa,GAAG,UAAC,KAAa,EAAE,OAAiC;IACnE,IAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAC7D,IACI,KAAK,KAAK,IAAI;QACd,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;QACrD,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,EAC9D;QACE,OAAO,CAAC,KAAK,GAAG;YACZ,IAAI,EAAE,KAAK;YACX,OAAO,EAAE,2BAA2B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AO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC;aACtC;SACJ;aAAM;YACH,KAAK,IAAI,CAAC,CAAC;SACd;QACD,OAAO,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;KACpC;IACD,OAAO,EAAE,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;AAC5D,CAAC,CAAC"}
@@ -1,7 +0,0 @@
1
- import type { ODataQuery } from './OData.types';
2
- /**
3
- * Parses the $fetchXml query
4
- * @returns Returns true when the parse has an error
5
- */
6
- export declare const getFetchXmlFromParser: (parser: URLSearchParams, result: ODataQuery) => boolean;
7
- //# sourceMappingURL=getFetchXmlFromParser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getFetchXmlFromParser.d.ts","sourceRoot":"","sources":["../src/getFetchXmlFromParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,WAAY,eAAe,UAAU,UAAU,KAAG,OAyCnF,CAAC"}
@@ -1,41 +0,0 @@
1
- /**
2
- * Parses the $fetchXml query
3
- * @returns Returns true when the parse has an error
4
- */
5
- export var getFetchXmlFromParser = function (parser, result) {
6
- var fetchXml = parser.get('fetchXml');
7
- if (fetchXml !== null) {
8
- var serializer = new DOMParser();
9
- var fetchXmlDocument = serializer.parseFromString(fetchXml, 'text/xml');
10
- if (fetchXmlDocument.documentElement.tagName === 'parsererror') {
11
- result.error = {
12
- code: '0x80040201',
13
- message: 'Invalid XML.',
14
- };
15
- return true;
16
- }
17
- var entity = fetchXmlDocument
18
- .evaluate('fetch/entity', fetchXmlDocument, null, XPathResult.ANY_TYPE, null)
19
- .iterateNext();
20
- if (fetchXmlDocument.documentElement.children.length != 1 || !entity || !entity.getAttribute('name')) {
21
- result.error = {
22
- code: '0x80041102',
23
- message: 'Entity Name was not specified in FetchXml String.',
24
- };
25
- return true;
26
- }
27
- var invalidAttribute = fetchXmlDocument
28
- .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)
29
- .iterateNext();
30
- if (invalidAttribute) {
31
- result.error = {
32
- code: '0x8004111c',
33
- message: "Invalid Child Node, valid nodes are filter, order, link-entity, attribute, all-attributes, no-attrs. NodeName = ".concat(invalidAttribute.tagName, " NodeXml = ").concat(invalidAttribute.outerHTML),
34
- };
35
- return true;
36
- }
37
- result.fetchXml = fetchXmlDocument;
38
- }
39
- return false;
40
- };
41
- //# sourceMappingURL=getFetchXmlFromParser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getFetchXmlFromParser.js","sourceRoot":"","sources":["../src/getFetchXmlFromParser.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,IAAM,qBAAqB,GAAG,UAAC,MAAuB,EAAE,MAAkB;IAC7E,IAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxC,IAAI,QAAQ,KAAK,IAAI,EAAE;QACnB,IAAM,UAAU,GAAG,IAAI,SAAS,EAAE,CAAC;QACnC,IAAM,gBAAgB,GAAG,UAAU,CAAC,eAAe,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC1E,IAAI,gBAAgB,CAAC,eAAe,CAAC,OAAO,KAAK,aAAa,EAAE;YAC5D,MAAM,CAAC,KAAK,GAAG;gBACX,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,cAAc;aAC1B,CAAC;YACF,OAAO,IAAI,CAAC;SACf;QACD,IAAM,MAAM,GAAG,gBAAgB;aAC1B,QAAQ,CAAC,cAAc,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC;aAC5E,WAAW,EAAa,CAAC;QAC9B,IAAI,gBAAgB,CAAC,eAAe,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;YAClG,MAAM,CAAC,KAAK,GAAG;gBACX,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,mDAAmD;aAC/D,CAAC;YACF,OAAO,IAAI,CAAC;SACf;QACD,IAAM,gBAAgB,GAAG,gBAAgB;aACpC,QAAQ,CACL,oIAAoI,EACpI,gBAAgB,EAChB,IAAI,EACJ,WAAW,CAAC,QAAQ,EACpB,IAAI,CACP;aACA,WAAW,EAAa,CAAC;QAC9B,IAAI,gBAAgB,EAAE;YAClB,MAAM,CAAC,KAAK,GAAG;gBACX,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,0HAAmH,gBAAgB,CAAC,OAAO,wBAAc,gBAAgB,CAAC,SAAS,CAAE;aACjM,CAAC;YACF,OAAO,IAAI,CAAC;SACf;QACD,MAAM,CAAC,QAAQ,GAAG,gBAAgB,CAAC;KACtC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC"}
@@ -1,7 +0,0 @@
1
- import type { ODataQuery } from './OData.types';
2
- /**
3
- * Parses the $select query
4
- * @returns Returns true when the parse has an error
5
- */
6
- export declare const getSelectFromParser: (parser: URLSearchParams, result: ODataQuery) => boolean;
7
- //# sourceMappingURL=getSelectFromParser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getSelectFromParser.d.ts","sourceRoot":"","sources":["../src/getSelectFromParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,WAAY,eAAe,UAAU,UAAU,KAAG,OAMjF,CAAC"}
@@ -1,12 +0,0 @@
1
- /**
2
- * Parses the $select query
3
- * @returns Returns true when the parse has an error
4
- */
5
- export var getSelectFromParser = function (parser, result) {
6
- var $select = parser.get('$select');
7
- if ($select !== null) {
8
- result.$select = $select.split(',');
9
- }
10
- return false;
11
- };
12
- //# sourceMappingURL=getSelectFromParser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getSelectFromParser.js","sourceRoot":"","sources":["../src/getSelectFromParser.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,IAAM,mBAAmB,GAAG,UAAC,MAAuB,EAAE,MAAkB;IAC3E,IAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACtC,IAAI,OAAO,KAAK,IAAI,EAAE;QAClB,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;KACvC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC"}
@@ -1,7 +0,0 @@
1
- import type { ODataQuery } from './OData.types';
2
- /**
3
- * Parses the $top query
4
- * @returns Returns true when the parse has an error
5
- */
6
- export declare const getTopFromParser: (parser: URLSearchParams, result: ODataQuery) => boolean;
7
- //# sourceMappingURL=getTopFromParser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getTopFromParser.d.ts","sourceRoot":"","sources":["../src/getTopFromParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,WAAY,eAAe,UAAU,UAAU,KAAG,OAoB9E,CAAC"}
@@ -1,27 +0,0 @@
1
- /**
2
- * Parses the $top query
3
- * @returns Returns true when the parse has an error
4
- */
5
- export var getTopFromParser = function (parser, result) {
6
- var $topValue = parser.get('$top');
7
- if ($topValue !== null) {
8
- var $top = void 0;
9
- if (!$topValue.match(/^\d+$/) || ($top = parseInt($topValue)) < 0) {
10
- result.error = {
11
- code: '0x0',
12
- message: "Invalid value '".concat($topValue, "' for $top query option found. The $top query option requires a non-negative integer value."),
13
- };
14
- return true;
15
- }
16
- else if ($top === 0) {
17
- result.error = {
18
- code: '0x0',
19
- message: "Invalid value for $top query option.",
20
- };
21
- return true;
22
- }
23
- result.$top = $top;
24
- }
25
- return false;
26
- };
27
- //# sourceMappingURL=getTopFromParser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getTopFromParser.js","sourceRoot":"","sources":["../src/getTopFromParser.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAAC,MAAuB,EAAE,MAAkB;IACxE,IAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,SAAS,KAAK,IAAI,EAAE;QACpB,IAAI,IAAI,SAAA,CAAC;QACT,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,EAAE;YAC/D,MAAM,CAAC,KAAK,GAAG;gBACX,IAAI,EAAE,KAAK;gBACX,OAAO,EAAE,yBAAkB,SAAS,gGAA6F;aACpI,CAAC;YACF,OAAO,IAAI,CAAC;SACf;aAAM,IAAI,IAAI,KAAK,CAAC,EAAE;YACnB,MAAM,CAAC,KAAK,GAAG;gBACX,IAAI,EAAE,KAAK;gBACX,OAAO,EAAE,sCAAsC;aAClD,CAAC;YACF,OAAO,IAAI,CAAC;SACf;QACD,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;KACtB;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC"}
package/lib/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export type { BinaryOperator, ODataError, ODataExpand, ODataExpandQuery, ODataFetch, ODataFilter, ODataQuery, ODataSelect, ODataTop, StandardOperator, StandardOperators, } from './OData.types';
2
- export { parseOData } from './parseOData';
3
- import { parseOData } from './parseOData';
4
- export default parseOData;
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,cAAc,EACd,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,eAAe,UAAU,CAAC"}
package/lib/index.js DELETED
@@ -1,4 +0,0 @@
1
- export { parseOData } from './parseOData';
2
- import { parseOData } from './parseOData';
3
- export default parseOData;
4
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,eAAe,UAAU,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { ODataQuery } from './OData.types';
2
- export declare const parseOData: (query: string) => ODataQuery;
3
- //# sourceMappingURL=parseOData.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseOData.d.ts","sourceRoot":"","sources":["../src/parseOData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAMhD,eAAO,MAAM,UAAU,UAAW,MAAM,eAgBvC,CAAC"}
package/lib/parseOData.js DELETED
@@ -1,22 +0,0 @@
1
- import { getTopFromParser } from './getTopFromParser';
2
- import { getSelectFromParser } from './getSelectFromParser';
3
- import { getExpandFromParser } from './getExpandFromParser';
4
- import { getFetchXmlFromParser } from './getFetchXmlFromParser';
5
- export var parseOData = function (query) {
6
- var parser = new URLSearchParams(query);
7
- var result = {};
8
- if (getExpandFromParser(parser, result)) {
9
- return result;
10
- }
11
- if (getSelectFromParser(parser, result)) {
12
- return result;
13
- }
14
- if (getTopFromParser(parser, result)) {
15
- return result;
16
- }
17
- if (getFetchXmlFromParser(parser, result)) {
18
- return result;
19
- }
20
- return result;
21
- };
22
- //# sourceMappingURL=parseOData.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseOData.js","sourceRoot":"","sources":["../src/parseOData.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,MAAM,CAAC,IAAM,UAAU,GAAG,UAAC,KAAa;IACpC,IAAM,MAAM,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;IAC1C,IAAM,MAAM,GAAG,EAAgB,CAAC;IAChC,IAAI,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;QACrC,OAAO,MAAM,CAAC;KACjB;IACD,IAAI,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;QACrC,OAAO,MAAM,CAAC;KACjB;IACD,IAAI,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;QAClC,OAAO,MAAM,CAAC;KACjB;IACD,IAAI,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;QACvC,OAAO,MAAM,CAAC;KACjB;IACD,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC"}
@@ -1,39 +0,0 @@
1
- import { describe, expect, test } from '@jest/globals';
2
- import { parseOData } from '../src';
3
-
4
- describe('parseOData $expand', () => {
5
- test('parse $expand Account_Leads', () => {
6
- const result = parseOData('?$expand=Account_Leads');
7
- expect(result.error).toBeUndefined();
8
- expect(result.$expand).not.toBeNull();
9
- expect(result.$expand).not.toBeUndefined();
10
- expect(result.$expand?.Account_Leads.$select).toEqual([]);
11
- });
12
-
13
- test('parse $expand Account_Leads and business_unit_accounts', () => {
14
- const result = parseOData('?$expand=Account_Leads,business_unit_accounts');
15
- expect(result.error).toBeUndefined();
16
- expect(result.$expand).not.toBeNull();
17
- expect(result.$expand).not.toBeUndefined();
18
- expect(result.$expand?.Account_Leads.$select).toEqual([]);
19
- expect(result.$expand?.business_unit_accounts.$select).toEqual([]);
20
- });
21
-
22
- test('parse $expand throws on Account_Leads without details', () => {
23
- const result = parseOData('?$expand=Account_Leads()');
24
- expect(result.error).not.toBeUndefined();
25
- expect(result.error?.message).toEqual('Empty expand');
26
- });
27
-
28
- test('parse $expand Account_Leads with $select', () => {
29
- const result = parseOData('?$expand=Account_Leads($select=name)');
30
- expect(result.error).toBeUndefined();
31
- expect(result.$expand).not.toBeNull();
32
- expect(result.$expand).not.toBeUndefined();
33
- expect(result.$expand?.Account_Leads).not.toBeNull();
34
- expect(result.$expand?.Account_Leads).not.toBeUndefined();
35
- expect(result.$expand?.Account_Leads.$select).not.toBeNull();
36
- expect(result.$expand?.Account_Leads.$select).not.toBeUndefined();
37
- expect(result.$expand?.Account_Leads.$select).toContain('name');
38
- });
39
- });
@@ -1,36 +0,0 @@
1
- import { describe, expect, test } from '@jest/globals';
2
- import { parseOData } from '../src';
3
-
4
- describe('parseOData $top', () => {
5
- test('parse $top 5', () => {
6
- const result = parseOData('?$top=5');
7
- console.log(result);
8
- expect(result.$top).toEqual(5);
9
- });
10
-
11
- test('parse $top errors for 1,0', () => {
12
- const result = parseOData('?$select=name,numberofemployees&$top=1,0');
13
- expect(result.error).not.toBeNull();
14
- console.log(result.error);
15
- expect(result.error?.code).toEqual('0x0');
16
- expect(result.error?.message).toEqual(
17
- `Invalid value '1,0' for $top query option found. The $top query option requires a non-negative integer value.`,
18
- );
19
- });
20
-
21
- test('parse $top errors for negative value', () => {
22
- const result = parseOData('?$select=name,numberofemployees&$top=-2');
23
- expect(result.error).not.toBeNull();
24
- expect(result.error?.code).toEqual('0x0');
25
- expect(result.error?.message).toEqual(
26
- `Invalid value '-2' for $top query option found. The $top query option requires a non-negative integer value.`,
27
- );
28
- });
29
-
30
- test('parse $top errors for 0', () => {
31
- const result = parseOData('?$select=name,numberofemployees&$top=0');
32
- expect(result.error).not.toBeNull();
33
- expect(result.error?.code).toEqual('0x0');
34
- expect(result.error?.message).toEqual(`Invalid value for $top query option.`);
35
- });
36
- });
@@ -1,62 +0,0 @@
1
- import { describe, expect, test } from '@jest/globals';
2
- import { parseOData } from '../src';
3
-
4
- describe('parseOData fetchXml', () => {
5
- test('parse fetchXml account', () => {
6
- const result = parseOData(
7
- '?fetchXml=%3Cfetch%20mapping%3D%27logical%27%3E%3Centity%20name%3D%27account%27%3E%3Cattribute%20name%3D%27accountid%27%2F%3E%3Cattribute%20name%3D%27name%27%2F%3E%3Cattribute%20name%3D%27accountnumber%27%2F%3E%3C%2Fentity%3E%3C%2Ffetch%3E',
8
- );
9
- console.log(result);
10
- expect(result.fetchXml?.documentElement.outerHTML).toEqual(
11
- `<fetch mapping="logical"><entity name="account"><attribute name="accountid"/><attribute name="name"/><attribute name="accountnumber"/></entity></fetch>`,
12
- );
13
- });
14
-
15
- test('parse fetchXml fails if invalid XML', () => {
16
- const result = parseOData('?fetchXml=invalid');
17
- expect(result.error).not.toBeNull();
18
- console.log(result.error);
19
- expect(result.error?.code).toEqual('0x80040201');
20
- expect(result.error?.message).toEqual('Invalid XML.');
21
- });
22
-
23
- test('parse fetchXml fails if EntityName not specified', () => {
24
- const result = parseOData('?fetchXml=<fetch><entity name=""></entity></fetch>');
25
- expect(result.error).not.toBeNull();
26
- console.log(result.error);
27
- expect(result.error?.code).toEqual('0x80041102');
28
- expect(result.error?.message).toEqual('Entity Name was not specified in FetchXml String.');
29
- });
30
-
31
- test('parse fetchXml fails if EntityName not specified', () => {
32
- const result = parseOData('?fetchXml=<fetch><entity></entity></fetch>');
33
- expect(result.error).not.toBeNull();
34
- console.log(result.error);
35
- expect(result.error?.code).toEqual('0x80041102');
36
- expect(result.error?.message).toEqual('Entity Name was not specified in FetchXml String.');
37
- });
38
-
39
- test('parse fetchXml fails if EntityName not specified', () => {
40
- const result = parseOData('?fetchXml=<entity></entity>');
41
- expect(result.error).not.toBeNull();
42
- console.log(result.error);
43
- expect(result.error?.code).toEqual('0x80041102');
44
- expect(result.error?.message).toEqual('Entity Name was not specified in FetchXml String.');
45
- });
46
-
47
- test('parse fetchXml fails if EntityName not specified', () => {
48
- const result = parseOData('?fetchXml=<fetch></fetch>');
49
- expect(result.error).not.toBeNull();
50
- console.log(result.error);
51
- expect(result.error?.code).toEqual('0x80041102');
52
- expect(result.error?.message).toEqual('Entity Name was not specified in FetchXml String.');
53
- });
54
-
55
- test('parse fetchXml fails if invalid attribute specified', () => {
56
- const result = parseOData('?fetchXml=<fetch><entity%20name="systemuser"><n%20/></entity></fetch>');
57
- expect(result.error).not.toBeUndefined();
58
- console.log(result.error);
59
- expect(result.error?.code).toEqual('0x8004111c');
60
- expect(result.error?.message).toEqual('Invalid Child Node, valid nodes are filter, order, link-entity, attribute, all-attributes, no-attrs. NodeName = n NodeXml = <n/>');
61
- });
62
- });
@@ -1,17 +0,0 @@
1
- import { describe, expect, test } from '@jest/globals';
2
- import { parseOData } from '../src';
3
-
4
- describe('parse odata', () => {
5
- test('parse $select', () => {
6
- const result = parseOData('?$select=name,numberofemployees$top=5');
7
- expect(result.$select).not.toBeNull();
8
- expect(result.$select).toContain('name');
9
- });
10
-
11
- test('$select and $expand', () => {
12
- const result = parseOData('?$select2=name,numberofemployees&$expand=Account_Leads($select=name)');
13
- expect(result.$select).not.toBeNull();
14
- expect(result.$expand).not.toBeNull();
15
- expect(result.$expand?.Account_Leads).not.toBeNull();
16
- });
17
- });