@shko.online/dataverse-odata 0.1.0

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 (79) hide show
  1. package/.babelrc.js +161 -0
  2. package/jest.config.ts +12 -0
  3. package/lib/cjs/OData.types.d.js +1 -0
  4. package/lib/cjs/getExpandFromParser.js +115 -0
  5. package/lib/cjs/getFetchXmlFromParser.js +43 -0
  6. package/lib/cjs/getSelectFromParser.js +18 -0
  7. package/lib/cjs/getTopFromParser.js +32 -0
  8. package/lib/cjs/index.js +15 -0
  9. package/lib/cjs/parseOData.js +28 -0
  10. package/lib/esm/OData.types.d.js +0 -0
  11. package/lib/esm/getExpandFromParser.js +109 -0
  12. package/lib/esm/getFetchXmlFromParser.js +36 -0
  13. package/lib/esm/getSelectFromParser.js +11 -0
  14. package/lib/esm/getTopFromParser.js +25 -0
  15. package/lib/esm/index.js +3 -0
  16. package/lib/esm/parseOData.js +21 -0
  17. package/lib/getExpandFromParser.d.ts +7 -0
  18. package/lib/getExpandFromParser.d.ts.map +1 -0
  19. package/lib/getExpandFromParser.js +97 -0
  20. package/lib/getExpandFromParser.js.map +1 -0
  21. package/lib/getFetchXmlFromParser.d.ts +7 -0
  22. package/lib/getFetchXmlFromParser.d.ts.map +1 -0
  23. package/lib/getFetchXmlFromParser.js +41 -0
  24. package/lib/getFetchXmlFromParser.js.map +1 -0
  25. package/lib/getSelectFromParser.d.ts +7 -0
  26. package/lib/getSelectFromParser.d.ts.map +1 -0
  27. package/lib/getSelectFromParser.js +12 -0
  28. package/lib/getSelectFromParser.js.map +1 -0
  29. package/lib/getTopFromParser.d.ts +7 -0
  30. package/lib/getTopFromParser.d.ts.map +1 -0
  31. package/lib/getTopFromParser.js +27 -0
  32. package/lib/getTopFromParser.js.map +1 -0
  33. package/lib/index.d.ts +5 -0
  34. package/lib/index.d.ts.map +1 -0
  35. package/lib/index.js +4 -0
  36. package/lib/index.js.map +1 -0
  37. package/lib/modern/OData.types.d.js +0 -0
  38. package/lib/modern/getExpandFromParser.js +109 -0
  39. package/lib/modern/getFetchXmlFromParser.js +36 -0
  40. package/lib/modern/getSelectFromParser.js +11 -0
  41. package/lib/modern/getTopFromParser.js +25 -0
  42. package/lib/modern/index.js +3 -0
  43. package/lib/modern/parseOData.js +21 -0
  44. package/lib/parseOData.d.ts +3 -0
  45. package/lib/parseOData.d.ts.map +1 -0
  46. package/lib/parseOData.js +22 -0
  47. package/lib/parseOData.js.map +1 -0
  48. package/lib/ts3.4/getExpandFromParser.d.ts +7 -0
  49. package/lib/ts3.4/getFetchXmlFromParser.d.ts +7 -0
  50. package/lib/ts3.4/getSelectFromParser.d.ts +7 -0
  51. package/lib/ts3.4/getTopFromParser.d.ts +7 -0
  52. package/lib/ts3.4/index.d.ts +5 -0
  53. package/lib/ts3.4/parseOData.d.ts +3 -0
  54. package/lib/ts3.9/getExpandFromParser.d.ts +7 -0
  55. package/lib/ts3.9/getExpandFromParser.d.ts.map +1 -0
  56. package/lib/ts3.9/getFetchXmlFromParser.d.ts +7 -0
  57. package/lib/ts3.9/getFetchXmlFromParser.d.ts.map +1 -0
  58. package/lib/ts3.9/getSelectFromParser.d.ts +7 -0
  59. package/lib/ts3.9/getSelectFromParser.d.ts.map +1 -0
  60. package/lib/ts3.9/getTopFromParser.d.ts +7 -0
  61. package/lib/ts3.9/getTopFromParser.d.ts.map +1 -0
  62. package/lib/ts3.9/index.d.ts +5 -0
  63. package/lib/ts3.9/index.d.ts.map +1 -0
  64. package/lib/ts3.9/parseOData.d.ts +3 -0
  65. package/lib/ts3.9/parseOData.d.ts.map +1 -0
  66. package/package.json +73 -0
  67. package/src/OData.types.d.ts +61 -0
  68. package/src/getExpandFromParser.ts +105 -0
  69. package/src/getFetchXmlFromParser.ts +48 -0
  70. package/src/getSelectFromParser.ts +13 -0
  71. package/src/getTopFromParser.ts +27 -0
  72. package/src/index.ts +16 -0
  73. package/src/parseOData.ts +23 -0
  74. package/tests/OData-Parser.$expand.test.ts +39 -0
  75. package/tests/OData-Parser.$top.test.ts +36 -0
  76. package/tests/OData-Parser.fetchXml.test.ts +62 -0
  77. package/tests/OData-Parser.test.ts +17 -0
  78. package/tsconfig.build.json +9 -0
  79. package/tsconfig.json +36 -0
package/.babelrc.js ADDED
@@ -0,0 +1,161 @@
1
+ const withTests = {
2
+ presets: [
3
+ [
4
+ '@babel/preset-env',
5
+ { shippedProposals: true, useBuiltIns: 'usage', corejs: '3', targets: { node: 'current' } },
6
+ ],
7
+ ],
8
+ plugins: [
9
+ '@storybook/babel-plugin-require-context-hook',
10
+ 'babel-plugin-dynamic-import-node',
11
+ '@babel/plugin-transform-runtime',
12
+ ],
13
+ };
14
+
15
+ // type BabelMode = 'cjs' | 'esm' | 'modern';
16
+
17
+ const modules = process.env.BABEL_MODE === 'cjs' ? 'auto' : false;
18
+
19
+ // FIXME: optional chaining introduced in chrome 80, not supported by wepback4
20
+ // https://github.com/webpack/webpack/issues/10227#issuecomment-642734920
21
+ const targets = process.env.BABEL_MODE === 'modern' ? { chrome: '79' } : 'defaults';
22
+
23
+ module.exports = {
24
+ ignore: [
25
+ './lib/codemod/src/transforms/__testfixtures__',
26
+ './lib/postinstall/src/__testfixtures__',
27
+ '**/typings.d.ts',
28
+ ],
29
+ presets: [
30
+ [
31
+ '@babel/preset-env',
32
+ {
33
+ shippedProposals: true,
34
+ useBuiltIns: 'usage',
35
+ corejs: '3',
36
+ targets,
37
+ modules,
38
+ },
39
+ ],
40
+ '@babel/preset-typescript',
41
+ '@babel/preset-react',
42
+ '@babel/preset-flow',
43
+ ],
44
+ plugins: [
45
+ [
46
+ '@babel/plugin-proposal-decorators',
47
+ {
48
+ legacy: true,
49
+ },
50
+ ],
51
+ ['@babel/plugin-proposal-class-properties', { loose: true }],
52
+ ['@babel/plugin-proposal-private-methods', { loose: true }],
53
+ ['@babel/plugin-proposal-private-property-in-object', { loose: true }],
54
+ '@babel/plugin-proposal-export-default-from',
55
+ '@babel/plugin-syntax-dynamic-import',
56
+ ['@babel/plugin-proposal-object-rest-spread', { loose: true, useBuiltIns: true }],
57
+ 'babel-plugin-macros',
58
+ ['@emotion', { sourceMap: true, autoLabel: 'always' }],
59
+ ],
60
+ env: {
61
+ test: withTests,
62
+ },
63
+ overrides: [
64
+ {
65
+ test: './examples/vue-kitchen-sink',
66
+ presets: ['@vue/babel-preset-jsx'],
67
+ env: {
68
+ test: withTests,
69
+ },
70
+ },
71
+ {
72
+ test: './lib',
73
+ presets: [
74
+ [
75
+ '@babel/preset-env',
76
+ {
77
+ shippedProposals: true,
78
+ useBuiltIns: 'usage',
79
+ corejs: '3',
80
+ modules,
81
+ targets,
82
+ },
83
+ ],
84
+ '@babel/preset-react',
85
+ ],
86
+ plugins: [
87
+ ['@babel/plugin-proposal-object-rest-spread', { loose: true, useBuiltIns: true }],
88
+ '@babel/plugin-proposal-export-default-from',
89
+ '@babel/plugin-syntax-dynamic-import',
90
+ ['@babel/plugin-proposal-private-property-in-object', { loose: true }],
91
+ ['@babel/plugin-proposal-class-properties', { loose: true }],
92
+ 'babel-plugin-macros',
93
+ ['@emotion', { sourceMap: true, autoLabel: 'always' }],
94
+ 'babel-plugin-add-react-displayname',
95
+ ],
96
+ env: {
97
+ test: withTests,
98
+ },
99
+ },
100
+ {
101
+ test: [
102
+ './lib/node-logger',
103
+ './lib/core',
104
+ './lib/core-common',
105
+ './lib/core-server',
106
+ './lib/builder-webpack4',
107
+ './lib/builder-webpack5',
108
+ './lib/codemod',
109
+ './addons/storyshots',
110
+ '**/src/server/**',
111
+ '**/src/bin/**',
112
+ ],
113
+ presets: [
114
+ [
115
+ '@babel/preset-env',
116
+ {
117
+ shippedProposals: true,
118
+ useBuiltIns: 'usage',
119
+ targets: {
120
+ node: '10',
121
+ },
122
+ modules,
123
+ corejs: '3',
124
+ },
125
+ ],
126
+ ],
127
+ plugins: [
128
+ '@emotion',
129
+ 'babel-plugin-macros',
130
+ '@babel/plugin-transform-arrow-functions',
131
+ '@babel/plugin-transform-shorthand-properties',
132
+ '@babel/plugin-transform-block-scoping',
133
+ '@babel/plugin-transform-destructuring',
134
+ ['@babel/plugin-proposal-private-property-in-object', { loose: true }],
135
+ ['@babel/plugin-proposal-class-properties', { loose: true }],
136
+ '@babel/plugin-proposal-object-rest-spread',
137
+ '@babel/plugin-proposal-export-default-from',
138
+ ],
139
+ env: {
140
+ test: withTests,
141
+ },
142
+ },
143
+ {
144
+ test: ['**/virtualModuleEntry.template.js'],
145
+ presets: [
146
+ [
147
+ '@babel/preset-env',
148
+ {
149
+ shippedProposals: true,
150
+ useBuiltIns: 'usage',
151
+ targets: {
152
+ node: '10',
153
+ },
154
+ corejs: '3',
155
+ modules: false,
156
+ },
157
+ ],
158
+ ],
159
+ },
160
+ ],
161
+ };
package/jest.config.ts ADDED
@@ -0,0 +1,12 @@
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;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getExpandFromParser = void 0;
7
+ var _getSelectFromParser = require("./getSelectFromParser");
8
+ /**
9
+ * Parses the $expand query
10
+ * @returns Returns true when the parse has an error
11
+ */
12
+ const getExpandFromParser = (parser, result) => {
13
+ const $expand = parser.get('$expand');
14
+ if ($expand !== null) {
15
+ result.$expand = {};
16
+ if (extractExpand($expand, result)) {
17
+ return true;
18
+ }
19
+ }
20
+ return false;
21
+ };
22
+ exports.getExpandFromParser = getExpandFromParser;
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: 'invalid expand expression'
29
+ };
30
+ return true;
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 true;
51
+ }
52
+ if ($expand.$expand !== undefined) {
53
+ const innerExpand = {};
54
+ const parser = new URLSearchParams('?' + value.substring(matchLength, matchLength + index));
55
+ if ((0, _getSelectFromParser.getSelectFromParser)(parser, innerExpand)) {
56
+ $expand.error = innerExpand.error;
57
+ return true;
58
+ }
59
+ if (getExpandFromParser(parser, innerExpand)) {
60
+ $expand.error = innerExpand.error;
61
+ return true;
62
+ }
63
+ if (innerExpand.$expand === undefined && innerExpand.$select === undefined) {
64
+ $expand.error = {
65
+ code: '0x0',
66
+ message: 'Empty expand'
67
+ };
68
+ return true;
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 true;
84
+ }
85
+ }
86
+ return false;
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: 'no closing bracket found',
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: 'no closing bracket found',
113
+ index: -1
114
+ };
115
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getFetchXmlFromParser = void 0;
7
+ /**
8
+ * Parses the $fetchXml query
9
+ * @returns Returns true when the parse has an error
10
+ */
11
+ const getFetchXmlFromParser = (parser, result) => {
12
+ const fetchXml = parser.get('fetchXml');
13
+ if (fetchXml !== null) {
14
+ const serializer = new DOMParser();
15
+ const fetchXmlDocument = serializer.parseFromString(fetchXml, 'text/xml');
16
+ if (fetchXmlDocument.documentElement.tagName === 'parsererror') {
17
+ result.error = {
18
+ code: '0x80040201',
19
+ message: 'Invalid XML.'
20
+ };
21
+ return true;
22
+ }
23
+ const entity = fetchXmlDocument.evaluate('fetch/entity', fetchXmlDocument, null, XPathResult.ANY_TYPE, null).iterateNext();
24
+ if (fetchXmlDocument.documentElement.children.length != 1 || !entity || !entity.getAttribute('name')) {
25
+ result.error = {
26
+ code: '0x80041102',
27
+ message: 'Entity Name was not specified in FetchXml String.'
28
+ };
29
+ return true;
30
+ }
31
+ 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();
32
+ if (invalidAttribute) {
33
+ result.error = {
34
+ code: '0x8004111c',
35
+ message: `Invalid Child Node, valid nodes are filter, order, link-entity, attribute, all-attributes, no-attrs. NodeName = ${invalidAttribute.tagName} NodeXml = ${invalidAttribute.outerHTML}`
36
+ };
37
+ return true;
38
+ }
39
+ result.fetchXml = fetchXmlDocument;
40
+ }
41
+ return false;
42
+ };
43
+ exports.getFetchXmlFromParser = getFetchXmlFromParser;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSelectFromParser = void 0;
7
+ /**
8
+ * Parses the $select query
9
+ * @returns Returns true when the parse has an error
10
+ */
11
+ const getSelectFromParser = (parser, result) => {
12
+ const $select = parser.get('$select');
13
+ if ($select !== null) {
14
+ result.$select = $select.split(',');
15
+ }
16
+ return false;
17
+ };
18
+ exports.getSelectFromParser = getSelectFromParser;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTopFromParser = void 0;
7
+ /**
8
+ * Parses the $top query
9
+ * @returns Returns true when the parse has an error
10
+ */
11
+ const getTopFromParser = (parser, result) => {
12
+ const $topValue = parser.get('$top');
13
+ if ($topValue !== null) {
14
+ let $top;
15
+ if (!$topValue.match(/^\d+$/) || ($top = parseInt($topValue)) < 0) {
16
+ result.error = {
17
+ code: '0x0',
18
+ message: `Invalid value '${$topValue}' for $top query option found. The $top query option requires a non-negative integer value.`
19
+ };
20
+ return true;
21
+ } else if ($top === 0) {
22
+ result.error = {
23
+ code: '0x0',
24
+ message: `Invalid value for $top query option.`
25
+ };
26
+ return true;
27
+ }
28
+ result.$top = $top;
29
+ }
30
+ return false;
31
+ };
32
+ exports.getTopFromParser = getTopFromParser;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ Object.defineProperty(exports, "parseOData", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _parseOData.parseOData;
11
+ }
12
+ });
13
+ var _parseOData = require("./parseOData");
14
+ var _default = _parseOData.parseOData;
15
+ exports.default = _default;
@@ -0,0 +1,28 @@
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
+ const parseOData = query => {
12
+ const parser = new URLSearchParams(query);
13
+ const result = {};
14
+ if ((0, _getExpandFromParser.getExpandFromParser)(parser, result)) {
15
+ return result;
16
+ }
17
+ if ((0, _getSelectFromParser.getSelectFromParser)(parser, result)) {
18
+ return result;
19
+ }
20
+ if ((0, _getTopFromParser.getTopFromParser)(parser, result)) {
21
+ return result;
22
+ }
23
+ if ((0, _getFetchXmlFromParser.getFetchXmlFromParser)(parser, result)) {
24
+ return result;
25
+ }
26
+ return result;
27
+ };
28
+ exports.parseOData = parseOData;
File without changes
@@ -0,0 +1,109 @@
1
+ import { getSelectFromParser } from './getSelectFromParser';
2
+
3
+ /**
4
+ * Parses the $expand query
5
+ * @returns Returns true when the parse has an error
6
+ */
7
+ export const getExpandFromParser = (parser, result) => {
8
+ const $expand = parser.get('$expand');
9
+ if ($expand !== null) {
10
+ result.$expand = {};
11
+ if (extractExpand($expand, result)) {
12
+ return true;
13
+ }
14
+ }
15
+ return false;
16
+ };
17
+ const extractExpand = (value, $expand) => {
18
+ const match = value.match(/^\s*(\w(\w|\d|_)*)\s*(,|\()?\s*/);
19
+ if (match === null || match[0].length < value.length && match[3] === null || match[0].length === value.length && match[3] !== undefined) {
20
+ $expand.error = {
21
+ code: '0x0',
22
+ message: 'invalid expand expression'
23
+ };
24
+ return true;
25
+ }
26
+ let matchSeparator = match[3];
27
+ let matchLength = match[0].length;
28
+ if (matchSeparator !== '(') {
29
+ if ($expand.$expand !== undefined) {
30
+ $expand.$expand[match[1]] = {
31
+ $select: []
32
+ };
33
+ }
34
+ } else {
35
+ const {
36
+ index,
37
+ error
38
+ } = getClosingBracket(value.substring(matchLength));
39
+ if (error) {
40
+ $expand.error = {
41
+ code: '0x0',
42
+ message: error
43
+ };
44
+ return true;
45
+ }
46
+ if ($expand.$expand !== undefined) {
47
+ const innerExpand = {};
48
+ const parser = new URLSearchParams('?' + value.substring(matchLength, matchLength + index));
49
+ if (getSelectFromParser(parser, innerExpand)) {
50
+ $expand.error = innerExpand.error;
51
+ return true;
52
+ }
53
+ if (getExpandFromParser(parser, innerExpand)) {
54
+ $expand.error = innerExpand.error;
55
+ return true;
56
+ }
57
+ if (innerExpand.$expand === undefined && innerExpand.$select === undefined) {
58
+ $expand.error = {
59
+ code: '0x0',
60
+ message: 'Empty expand'
61
+ };
62
+ return true;
63
+ }
64
+ $expand.$expand[match[1]] = innerExpand;
65
+ }
66
+ matchLength = matchLength + index;
67
+ const secondMatch = value.substring(matchLength + 1).match(/\s*(,?)\s*d/);
68
+ if (secondMatch !== null) {
69
+ matchLength = matchLength + secondMatch[0].length;
70
+ if (secondMatch[1] !== null) {
71
+ matchSeparator = ',';
72
+ }
73
+ }
74
+ }
75
+ if (matchSeparator === ',') {
76
+ if (extractExpand(value.substring(matchLength), $expand)) {
77
+ return true;
78
+ }
79
+ }
80
+ return false;
81
+ };
82
+ const getClosingBracket = value => {
83
+ let depth = 1;
84
+ let startAt = 0;
85
+ while (depth > 0) {
86
+ const match = value.substring(startAt).match(/\(|\)/);
87
+ if (match === null) {
88
+ return {
89
+ error: 'no closing bracket found',
90
+ index: -1
91
+ };
92
+ }
93
+ if (match[0] === ')') {
94
+ depth -= 1;
95
+ if (depth === 0) {
96
+ return {
97
+ index: match.index || 0
98
+ };
99
+ }
100
+ } else {
101
+ depth += 1;
102
+ }
103
+ startAt = (match.index || 0) + 1;
104
+ }
105
+ return {
106
+ error: 'no closing bracket found',
107
+ index: -1
108
+ };
109
+ };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Parses the $fetchXml query
3
+ * @returns Returns true when the parse has an error
4
+ */
5
+ export const getFetchXmlFromParser = (parser, result) => {
6
+ const fetchXml = parser.get('fetchXml');
7
+ if (fetchXml !== null) {
8
+ const serializer = new DOMParser();
9
+ const 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
+ const entity = fetchXmlDocument.evaluate('fetch/entity', fetchXmlDocument, null, XPathResult.ANY_TYPE, null).iterateNext();
18
+ if (fetchXmlDocument.documentElement.children.length != 1 || !entity || !entity.getAttribute('name')) {
19
+ result.error = {
20
+ code: '0x80041102',
21
+ message: 'Entity Name was not specified in FetchXml String.'
22
+ };
23
+ return true;
24
+ }
25
+ 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();
26
+ if (invalidAttribute) {
27
+ result.error = {
28
+ code: '0x8004111c',
29
+ message: `Invalid Child Node, valid nodes are filter, order, link-entity, attribute, all-attributes, no-attrs. NodeName = ${invalidAttribute.tagName} NodeXml = ${invalidAttribute.outerHTML}`
30
+ };
31
+ return true;
32
+ }
33
+ result.fetchXml = fetchXmlDocument;
34
+ }
35
+ return false;
36
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Parses the $select query
3
+ * @returns Returns true when the parse has an error
4
+ */
5
+ export const getSelectFromParser = (parser, result) => {
6
+ const $select = parser.get('$select');
7
+ if ($select !== null) {
8
+ result.$select = $select.split(',');
9
+ }
10
+ return false;
11
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Parses the $top query
3
+ * @returns Returns true when the parse has an error
4
+ */
5
+ export const getTopFromParser = (parser, result) => {
6
+ const $topValue = parser.get('$top');
7
+ if ($topValue !== null) {
8
+ let $top;
9
+ if (!$topValue.match(/^\d+$/) || ($top = parseInt($topValue)) < 0) {
10
+ result.error = {
11
+ code: '0x0',
12
+ message: `Invalid value '${$topValue}' for $top query option found. The $top query option requires a non-negative integer value.`
13
+ };
14
+ return true;
15
+ } else if ($top === 0) {
16
+ result.error = {
17
+ code: '0x0',
18
+ message: `Invalid value for $top query option.`
19
+ };
20
+ return true;
21
+ }
22
+ result.$top = $top;
23
+ }
24
+ return false;
25
+ };
@@ -0,0 +1,3 @@
1
+ export { parseOData } from './parseOData';
2
+ import { parseOData } from './parseOData';
3
+ export default parseOData;
@@ -0,0 +1,21 @@
1
+ import { getTopFromParser } from './getTopFromParser';
2
+ import { getSelectFromParser } from './getSelectFromParser';
3
+ import { getExpandFromParser } from './getExpandFromParser';
4
+ import { getFetchXmlFromParser } from './getFetchXmlFromParser';
5
+ export const parseOData = query => {
6
+ const parser = new URLSearchParams(query);
7
+ const 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
+ };
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
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"}