@shko.online/dataverse-odata 0.1.0 → 0.1.2

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 (100) hide show
  1. package/.babelrc.js +160 -160
  2. package/.releaserc.yaml +23 -0
  3. package/CHANGELOG.md +13 -0
  4. package/README.md +3 -0
  5. package/lib/cjs/getExpandFromParser.js +16 -16
  6. package/lib/cjs/getFetchXmlFromParser.js +14 -7
  7. package/lib/cjs/getOrderByFromParser.js +44 -0
  8. package/lib/cjs/getSelectFromParser.js +4 -4
  9. package/lib/cjs/getTopFromParser.js +10 -6
  10. package/lib/cjs/getXQueryFromParser.js +35 -0
  11. package/lib/cjs/index.js +42 -0
  12. package/lib/cjs/parseOData.js +16 -4
  13. package/lib/cjs/validateNotEmpty.js +17 -0
  14. package/lib/esm/getExpandFromParser.js +16 -16
  15. package/lib/esm/getFetchXmlFromParser.js +14 -7
  16. package/lib/esm/getOrderByFromParser.js +37 -0
  17. package/lib/esm/getSelectFromParser.js +4 -4
  18. package/lib/esm/getTopFromParser.js +11 -6
  19. package/lib/esm/getXQueryFromParser.js +28 -0
  20. package/lib/esm/index.js +6 -0
  21. package/lib/esm/parseOData.js +17 -4
  22. package/lib/esm/validateNotEmpty.js +10 -0
  23. package/lib/modern/getExpandFromParser.js +16 -16
  24. package/lib/modern/getFetchXmlFromParser.js +14 -7
  25. package/lib/modern/getOrderByFromParser.js +38 -0
  26. package/lib/modern/getSelectFromParser.js +4 -4
  27. package/lib/modern/getTopFromParser.js +11 -6
  28. package/lib/modern/getXQueryFromParser.js +28 -0
  29. package/lib/modern/index.js +6 -0
  30. package/lib/modern/parseOData.js +17 -4
  31. package/lib/modern/validateNotEmpty.js +10 -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/parseOData.d.ts +5 -0
  40. package/lib/ts3.4/validateNotEmpty.d.ts +3 -0
  41. package/lib/ts3.9/getExpandFromParser.d.ts +6 -6
  42. package/lib/ts3.9/getExpandFromParser.d.ts.map +1 -1
  43. package/lib/ts3.9/getFetchXmlFromParser.d.ts +6 -6
  44. package/lib/ts3.9/getFetchXmlFromParser.d.ts.map +1 -1
  45. package/lib/ts3.9/getOrderByFromParser.d.ts +7 -0
  46. package/lib/ts3.9/getOrderByFromParser.d.ts.map +1 -0
  47. package/lib/ts3.9/getSelectFromParser.d.ts +6 -6
  48. package/lib/ts3.9/getSelectFromParser.d.ts.map +1 -1
  49. package/lib/ts3.9/getTopFromParser.d.ts +6 -6
  50. package/lib/ts3.9/getTopFromParser.d.ts.map +1 -1
  51. package/lib/ts3.9/getXQueryFromParser.d.ts +8 -0
  52. package/lib/ts3.9/getXQueryFromParser.d.ts.map +1 -0
  53. package/lib/ts3.9/index.d.ts +10 -4
  54. package/lib/ts3.9/index.d.ts.map +1 -1
  55. package/lib/ts3.9/parseOData.d.ts +7 -2
  56. package/lib/ts3.9/parseOData.d.ts.map +1 -1
  57. package/lib/ts3.9/validateNotEmpty.d.ts +3 -0
  58. package/lib/ts3.9/validateNotEmpty.d.ts.map +1 -0
  59. package/package.json +13 -8
  60. package/src/OData.types.d.ts +136 -61
  61. package/src/getExpandFromParser.ts +106 -105
  62. package/src/getFetchXmlFromParser.ts +56 -48
  63. package/src/getOrderByFromParser.ts +42 -0
  64. package/src/getSelectFromParser.ts +13 -13
  65. package/src/getTopFromParser.ts +31 -27
  66. package/src/getXQueryFromParser.ts +34 -0
  67. package/src/index.ts +24 -16
  68. package/src/parseOData.ts +36 -23
  69. package/src/validateNotEmpty.ts +12 -0
  70. package/tsconfig.build.json +8 -8
  71. package/tsconfig.json +35 -35
  72. package/jest.config.ts +0 -12
  73. package/lib/getExpandFromParser.d.ts +0 -7
  74. package/lib/getExpandFromParser.d.ts.map +0 -1
  75. package/lib/getExpandFromParser.js +0 -97
  76. package/lib/getExpandFromParser.js.map +0 -1
  77. package/lib/getFetchXmlFromParser.d.ts +0 -7
  78. package/lib/getFetchXmlFromParser.d.ts.map +0 -1
  79. package/lib/getFetchXmlFromParser.js +0 -41
  80. package/lib/getFetchXmlFromParser.js.map +0 -1
  81. package/lib/getSelectFromParser.d.ts +0 -7
  82. package/lib/getSelectFromParser.d.ts.map +0 -1
  83. package/lib/getSelectFromParser.js +0 -12
  84. package/lib/getSelectFromParser.js.map +0 -1
  85. package/lib/getTopFromParser.d.ts +0 -7
  86. package/lib/getTopFromParser.d.ts.map +0 -1
  87. package/lib/getTopFromParser.js +0 -27
  88. package/lib/getTopFromParser.js.map +0 -1
  89. package/lib/index.d.ts +0 -5
  90. package/lib/index.d.ts.map +0 -1
  91. package/lib/index.js +0 -4
  92. package/lib/index.js.map +0 -1
  93. package/lib/parseOData.d.ts +0 -3
  94. package/lib/parseOData.d.ts.map +0 -1
  95. package/lib/parseOData.js +0 -22
  96. package/lib/parseOData.js.map +0 -1
  97. package/tests/OData-Parser.$expand.test.ts +0 -39
  98. package/tests/OData-Parser.$top.test.ts +0 -36
  99. package/tests/OData-Parser.fetchXml.test.ts +0 -62
  100. package/tests/OData-Parser.test.ts +0 -17
package/.babelrc.js CHANGED
@@ -1,161 +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
- ],
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
161
  };
@@ -0,0 +1,23 @@
1
+ plugins:
2
+ - '@semantic-release/commit-analyzer'
3
+ - '@semantic-release/release-notes-generator'
4
+ - '@semantic-release/changelog'
5
+ - '@semantic-release/npm'
6
+ - '@semantic-release/exec'
7
+ - - '@semantic-release/git'
8
+ - assets:
9
+ - package.json
10
+ - CHANGELOG.md
11
+ message: |-
12
+ chore(release): ${nextRelease.version} [skip ci]
13
+
14
+ ${nextRelease.notes}
15
+ branches:
16
+ - '+([0-9])?(.{+([0-9]),x}).x'
17
+ - main
18
+ - next
19
+ - next-major
20
+ - name: beta
21
+ prerelease: true
22
+ - name: alpha
23
+ prerelease: true
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ## [0.1.2](https://github.com/shko-online/dataverse-odata/compare/v0.1.1...v0.1.2) (2023-02-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Improved documentation ([720fb93](https://github.com/shko-online/dataverse-odata/commit/720fb93a6d330ea51ba262019543519a6255af02))
7
+
8
+ ## [0.1.1](https://github.com/shko-online/dataverse-odata/compare/v0.1.0...v0.1.1) (2023-02-11)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * improved documentation and type exports ([26c0b2f](https://github.com/shko-online/dataverse-odata/commit/26c0b2f8f6146007ed4f51a03ae64adbd3cf6ca5))
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @shko.online/dataverse-odata
2
+ This package will help parse OData strings (only the Microsoft Dataverse subset). It can be used as a validator, or you can build a javascript library which consumes the output of this library. We are using this to mock the `WebAPI` on the `@shko.online/componentframework-mock` package.
3
+
@@ -5,19 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getExpandFromParser = void 0;
7
7
  var _getSelectFromParser = require("./getSelectFromParser");
8
- /**
9
- * Parses the $expand query
10
- * @returns Returns true when the parse has an error
8
+ /**
9
+ * Parses the {@link ODataExpand.$expand $expand} query
10
+ * @returns Returns `false` when the parse has an error
11
11
  */
12
12
  const getExpandFromParser = (parser, result) => {
13
13
  const $expand = parser.get('$expand');
14
14
  if ($expand !== null) {
15
15
  result.$expand = {};
16
- if (extractExpand($expand, result)) {
17
- return true;
16
+ if (!extractExpand($expand, result)) {
17
+ return false;
18
18
  }
19
19
  }
20
- return false;
20
+ return true;
21
21
  };
22
22
  exports.getExpandFromParser = getExpandFromParser;
23
23
  const extractExpand = (value, $expand) => {
@@ -27,7 +27,7 @@ const extractExpand = (value, $expand) => {
27
27
  code: '0x0',
28
28
  message: 'invalid expand expression'
29
29
  };
30
- return true;
30
+ return false;
31
31
  }
32
32
  let matchSeparator = match[3];
33
33
  let matchLength = match[0].length;
@@ -47,25 +47,25 @@ const extractExpand = (value, $expand) => {
47
47
  code: '0x0',
48
48
  message: error
49
49
  };
50
- return true;
50
+ return false;
51
51
  }
52
52
  if ($expand.$expand !== undefined) {
53
53
  const innerExpand = {};
54
54
  const parser = new URLSearchParams('?' + value.substring(matchLength, matchLength + index));
55
- if ((0, _getSelectFromParser.getSelectFromParser)(parser, innerExpand)) {
55
+ if (!(0, _getSelectFromParser.getSelectFromParser)(parser, innerExpand)) {
56
56
  $expand.error = innerExpand.error;
57
- return true;
57
+ return false;
58
58
  }
59
- if (getExpandFromParser(parser, innerExpand)) {
59
+ if (!getExpandFromParser(parser, innerExpand)) {
60
60
  $expand.error = innerExpand.error;
61
- return true;
61
+ return false;
62
62
  }
63
63
  if (innerExpand.$expand === undefined && innerExpand.$select === undefined) {
64
64
  $expand.error = {
65
65
  code: '0x0',
66
66
  message: 'Empty expand'
67
67
  };
68
- return true;
68
+ return false;
69
69
  }
70
70
  $expand.$expand[match[1]] = innerExpand;
71
71
  }
@@ -79,11 +79,11 @@ const extractExpand = (value, $expand) => {
79
79
  }
80
80
  }
81
81
  if (matchSeparator === ',') {
82
- if (extractExpand(value.substring(matchLength), $expand)) {
83
- return true;
82
+ if (!extractExpand(value.substring(matchLength), $expand)) {
83
+ return false;
84
84
  }
85
85
  }
86
- return false;
86
+ return true;
87
87
  };
88
88
  const getClosingBracket = value => {
89
89
  let depth = 1;
@@ -4,13 +4,20 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getFetchXmlFromParser = void 0;
7
- /**
8
- * Parses the $fetchXml query
9
- * @returns Returns true when the parse has an error
7
+ /**
8
+ * Parses the {@link ODataFetch.fetchXml fetchXml} query
9
+ * @returns Returns `false` when the parse has an error
10
10
  */
11
11
  const getFetchXmlFromParser = (parser, result) => {
12
12
  const fetchXml = parser.get('fetchXml');
13
13
  if (fetchXml !== null) {
14
+ if (fetchXml === '') {
15
+ result.error = {
16
+ code: '0x80040203',
17
+ message: 'Expected non-empty string.'
18
+ };
19
+ return false;
20
+ }
14
21
  const serializer = new DOMParser();
15
22
  const fetchXmlDocument = serializer.parseFromString(fetchXml, 'text/xml');
16
23
  if (fetchXmlDocument.documentElement.tagName === 'parsererror') {
@@ -18,7 +25,7 @@ const getFetchXmlFromParser = (parser, result) => {
18
25
  code: '0x80040201',
19
26
  message: 'Invalid XML.'
20
27
  };
21
- return true;
28
+ return false;
22
29
  }
23
30
  const entity = fetchXmlDocument.evaluate('fetch/entity', fetchXmlDocument, null, XPathResult.ANY_TYPE, null).iterateNext();
24
31
  if (fetchXmlDocument.documentElement.children.length != 1 || !entity || !entity.getAttribute('name')) {
@@ -26,7 +33,7 @@ const getFetchXmlFromParser = (parser, result) => {
26
33
  code: '0x80041102',
27
34
  message: 'Entity Name was not specified in FetchXml String.'
28
35
  };
29
- return true;
36
+ return false;
30
37
  }
31
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();
32
39
  if (invalidAttribute) {
@@ -34,10 +41,10 @@ const getFetchXmlFromParser = (parser, result) => {
34
41
  code: '0x8004111c',
35
42
  message: `Invalid Child Node, valid nodes are filter, order, link-entity, attribute, all-attributes, no-attrs. NodeName = ${invalidAttribute.tagName} NodeXml = ${invalidAttribute.outerHTML}`
36
43
  };
37
- return true;
44
+ return false;
38
45
  }
39
46
  result.fetchXml = fetchXmlDocument;
40
47
  }
41
- return false;
48
+ return true;
42
49
  };
43
50
  exports.getFetchXmlFromParser = getFetchXmlFromParser;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getOrderByFromParser = void 0;
7
+ var _validateNotEmpty = require("./validateNotEmpty");
8
+ const edmProperty = /\w{1-255}/gi;
9
+
10
+ /**
11
+ * Parses the {@link ODataOrderBy.$orderby $orderby} query
12
+ * @returns Returns `false` when the parse has an error
13
+ */
14
+ const getOrderByFromParser = (parser, result) => {
15
+ let $orderby = parser.get('$orderby');
16
+ if ($orderby !== null) {
17
+ if (!(0, _validateNotEmpty.validateNotEmpty)('$orderby', $orderby, result)) {
18
+ return false;
19
+ }
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
+ }
42
+ return true;
43
+ };
44
+ exports.getOrderByFromParser = getOrderByFromParser;
@@ -4,15 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getSelectFromParser = void 0;
7
- /**
8
- * Parses the $select query
9
- * @returns Returns true when the parse has an error
7
+ /**
8
+ * Parses the {@link ODataSelect.$select $select} query
9
+ * @returns Returns `false` when the parse has an error
10
10
  */
11
11
  const getSelectFromParser = (parser, result) => {
12
12
  const $select = parser.get('$select');
13
13
  if ($select !== null) {
14
14
  result.$select = $select.split(',');
15
15
  }
16
- return false;
16
+ return true;
17
17
  };
18
18
  exports.getSelectFromParser = getSelectFromParser;
@@ -4,29 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getTopFromParser = void 0;
7
- /**
8
- * Parses the $top query
9
- * @returns Returns true when the parse has an error
7
+ var _validateNotEmpty = require("./validateNotEmpty");
8
+ /**
9
+ * Parses the {@link ODataTop.$top $top} query
10
+ * @returns Returns `false` when the parse has an error
10
11
  */
11
12
  const getTopFromParser = (parser, result) => {
12
13
  const $topValue = parser.get('$top');
13
14
  if ($topValue !== null) {
15
+ if (!(0, _validateNotEmpty.validateNotEmpty)('$orderby', $topValue, result)) {
16
+ return false;
17
+ }
14
18
  let $top;
15
19
  if (!$topValue.match(/^\d+$/) || ($top = parseInt($topValue)) < 0) {
16
20
  result.error = {
17
21
  code: '0x0',
18
22
  message: `Invalid value '${$topValue}' for $top query option found. The $top query option requires a non-negative integer value.`
19
23
  };
20
- return true;
24
+ return false;
21
25
  } else if ($top === 0) {
22
26
  result.error = {
23
27
  code: '0x0',
24
28
  message: `Invalid value for $top query option.`
25
29
  };
26
- return true;
30
+ return false;
27
31
  }
28
32
  result.$top = $top;
29
33
  }
30
- return false;
34
+ return true;
31
35
  };
32
36
  exports.getTopFromParser = getTopFromParser;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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
+
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 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
+ };
35
+ exports.getXQueryFromParser = getXQueryFromParser;