@shko.online/dataverse-odata 0.1.4 → 0.1.6
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.
- package/.editorconfig +8 -0
- package/.github/workflows/publish.yml +44 -0
- package/.prettierrc.json +7 -7
- package/.releaserc.yaml +23 -23
- package/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/azure-pipelines.yml +32 -0
- package/lib/cjs/getAliasedProperty.js +36 -0
- package/lib/cjs/getExpandFromParser.js +1 -1
- package/lib/cjs/getFilterFromParser.js +31 -0
- package/lib/cjs/getOrderByFromParser.js +41 -10
- package/lib/cjs/index.js +1 -2
- package/lib/cjs/parseOData.js +2 -1
- package/lib/cjs/validators/atMostOnce.js +6 -6
- package/lib/cjs/validators/differentFromEmptyString.js +5 -5
- package/lib/cjs/validators/hasContent.js +6 -6
- package/lib/cjs/validators/isGuid.js +5 -5
- package/lib/cjs/validators/recognizedGuid.js +5 -5
- package/lib/esm/getAliasedProperty.js +29 -0
- package/lib/esm/getExpandFromParser.js +1 -1
- package/lib/esm/getFilterFromParser.js +24 -0
- package/lib/esm/getOrderByFromParser.js +41 -10
- package/lib/esm/parseOData.js +2 -1
- package/lib/esm/validators/atMostOnce.js +6 -6
- package/lib/esm/validators/differentFromEmptyString.js +5 -5
- package/lib/esm/validators/hasContent.js +6 -6
- package/lib/esm/validators/isGuid.js +5 -5
- package/lib/esm/validators/recognizedGuid.js +5 -5
- package/lib/modern/getAliasedProperty.js +29 -0
- package/lib/modern/getExpandFromParser.js +1 -1
- package/lib/modern/getFilterFromParser.js +24 -0
- package/lib/modern/getOrderByFromParser.js +42 -11
- package/lib/modern/parseOData.js +2 -1
- package/lib/modern/validators/atMostOnce.js +6 -6
- package/lib/modern/validators/differentFromEmptyString.js +5 -5
- package/lib/modern/validators/hasContent.js +6 -6
- package/lib/modern/validators/isGuid.js +5 -5
- package/lib/modern/validators/recognizedGuid.js +5 -5
- package/lib/ts3.4/OData.types.d.ts +29 -6
- package/lib/ts3.4/getAliasedProperty.d.ts +10 -0
- package/lib/ts3.4/getFilterFromParser.d.ts +7 -0
- package/lib/ts3.4/getXQueryFromParser.d.ts +1 -1
- package/lib/ts3.4/validators/atMostOnce.d.ts +1 -1
- package/lib/ts3.9/OData.types.d.ts +141 -154
- package/lib/ts3.9/getAliasedProperty.d.ts +10 -0
- package/lib/ts3.9/getExpandFromParser.d.ts +7 -7
- package/lib/ts3.9/getFetchXmlFromParser.d.ts +7 -7
- package/lib/ts3.9/getFilterFromParser.d.ts +7 -0
- package/lib/ts3.9/getOrderByFromParser.d.ts +7 -7
- package/lib/ts3.9/getSelectFromParser.d.ts +7 -7
- package/lib/ts3.9/getTopFromParser.d.ts +7 -7
- package/lib/ts3.9/getXQueryFromParser.d.ts +8 -8
- package/lib/ts3.9/index.d.ts +11 -11
- package/lib/ts3.9/parseOData.d.ts +8 -8
- package/lib/ts3.9/validators/atMostOnce.d.ts +10 -10
- package/lib/ts3.9/validators/differentFromEmptyString.d.ts +9 -9
- package/lib/ts3.9/validators/hasContent.d.ts +10 -10
- package/lib/ts3.9/validators/isGuid.d.ts +9 -9
- package/lib/ts3.9/validators/recognizedGuid.d.ts +9 -9
- package/lib/ts4.2/OData.types.d.ts +183 -0
- package/lib/ts4.2/getAliasedProperty.d.ts +10 -0
- package/lib/ts4.2/getAliasedProperty.d.ts.map +1 -0
- package/lib/ts4.2/getExpandFromParser.d.ts +7 -0
- package/lib/{ts3.9 → ts4.2}/getExpandFromParser.d.ts.map +1 -1
- package/lib/ts4.2/getFetchXmlFromParser.d.ts +7 -0
- package/lib/{ts3.9 → ts4.2}/getFetchXmlFromParser.d.ts.map +1 -1
- package/lib/ts4.2/getFilterFromParser.d.ts +7 -0
- package/lib/ts4.2/getFilterFromParser.d.ts.map +1 -0
- package/lib/ts4.2/getOrderByFromParser.d.ts +7 -0
- package/lib/ts4.2/getOrderByFromParser.d.ts.map +1 -0
- package/lib/ts4.2/getSelectFromParser.d.ts +7 -0
- package/lib/{ts3.9 → ts4.2}/getSelectFromParser.d.ts.map +1 -1
- package/lib/ts4.2/getTopFromParser.d.ts +7 -0
- package/lib/{ts3.9 → ts4.2}/getTopFromParser.d.ts.map +1 -1
- package/lib/ts4.2/getXQueryFromParser.d.ts +8 -0
- package/lib/{ts3.9 → ts4.2}/getXQueryFromParser.d.ts.map +1 -1
- package/lib/ts4.2/index.d.ts +11 -0
- package/lib/ts4.2/parseOData.d.ts +8 -0
- package/lib/{ts3.9 → ts4.2}/parseOData.d.ts.map +1 -1
- package/lib/ts4.2/validators/atMostOnce.d.ts +10 -0
- package/lib/{ts3.9 → ts4.2}/validators/atMostOnce.d.ts.map +1 -1
- package/lib/ts4.2/validators/differentFromEmptyString.d.ts +9 -0
- package/lib/{ts3.9 → ts4.2}/validators/differentFromEmptyString.d.ts.map +1 -1
- package/lib/ts4.2/validators/hasContent.d.ts +10 -0
- package/lib/{ts3.9 → ts4.2}/validators/hasContent.d.ts.map +1 -1
- package/lib/ts4.2/validators/isGuid.d.ts +9 -0
- package/lib/{ts3.9 → ts4.2}/validators/isGuid.d.ts.map +1 -1
- package/lib/ts4.2/validators/recognizedGuid.d.ts +9 -0
- package/lib/{ts3.9 → ts4.2}/validators/recognizedGuid.d.ts.map +1 -1
- package/package.json +20 -11
- package/src/OData.types.d.ts +35 -6
- package/src/getAliasedProperty.ts +34 -0
- package/src/getExpandFromParser.ts +1 -1
- package/src/getFilterFromParser.ts +23 -0
- package/src/getOrderByFromParser.ts +46 -10
- package/src/parseOData.ts +3 -1
- package/src/validators/atMostOnce.ts +19 -19
- package/src/validators/differentFromEmptyString.ts +18 -18
- package/src/validators/hasContent.ts +19 -19
- package/src/validators/isGuid.ts +20 -20
- package/src/validators/recognizedGuid.ts +18 -18
- package/lib/ts3.9/getOrderByFromParser.d.ts.map +0 -1
- /package/lib/{ts3.9 → ts4.2}/index.d.ts.map +0 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Semantic Release
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [ main, beta, alpha ]
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read # for checkout
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
build:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
permissions:
|
|
17
|
+
contents: write # to be able to publish a GitHub release
|
|
18
|
+
issues: write # to be able to comment on released issues
|
|
19
|
+
pull-requests: write # to be able to comment on released pull requests
|
|
20
|
+
id-token: write # to enable use of OIDC for trusted publishing and npm provenance
|
|
21
|
+
steps:
|
|
22
|
+
- name: Checkout
|
|
23
|
+
uses: actions/checkout@v6
|
|
24
|
+
with:
|
|
25
|
+
fetch-depth: 0 # to be able to get all tags for semantic-release
|
|
26
|
+
|
|
27
|
+
- name: Setup Node.js
|
|
28
|
+
uses: actions/setup-node@v6
|
|
29
|
+
with:
|
|
30
|
+
node-version: "lts/*"
|
|
31
|
+
|
|
32
|
+
- name: Install dependencies
|
|
33
|
+
run: npm ci
|
|
34
|
+
|
|
35
|
+
- name: Build
|
|
36
|
+
run: npm run build
|
|
37
|
+
|
|
38
|
+
- name: Run tests
|
|
39
|
+
run: npm test
|
|
40
|
+
|
|
41
|
+
- name: Release
|
|
42
|
+
env:
|
|
43
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
44
|
+
run: npx semantic-release
|
package/.prettierrc.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
"semi": true,
|
|
3
|
+
"trailingComma": "all",
|
|
4
|
+
"singleQuote": true,
|
|
5
|
+
"printWidth": 120,
|
|
6
|
+
"tabWidth": 4,
|
|
7
|
+
"endOfLine": "auto"
|
|
8
|
+
}
|
package/.releaserc.yaml
CHANGED
|
@@ -1,23 +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
|
|
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
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [0.1.6](https://github.com/Shko-Online/dataverse-odata/compare/v0.1.5...v0.1.6) (2026-03-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* build before publish ([abf325d](https://github.com/Shko-Online/dataverse-odata/commit/abf325da1f8f7ee2d1ba44f35f0b182de9d9cb6a))
|
|
7
|
+
|
|
8
|
+
## [0.1.5](https://github.com/Shko-Online/dataverse-odata/compare/v0.1.4...v0.1.5) (2026-03-15)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* Properly implemented $orderBy ([c693298](https://github.com/Shko-Online/dataverse-odata/commit/c693298bcc4cb2a96ebbc39939c60fb5abdd93d4))
|
|
14
|
+
|
|
1
15
|
## [0.1.4](https://github.com/shko-online/dataverse-odata/compare/v0.1.3...v0.1.4) (2023-02-12)
|
|
2
16
|
|
|
3
17
|
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Betim Beja and Shko Online LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
pool:
|
|
2
|
+
vmImage: ubuntu-latest
|
|
3
|
+
|
|
4
|
+
steps:
|
|
5
|
+
- task: NodeTool@0
|
|
6
|
+
inputs:
|
|
7
|
+
versionSpec: '24.x'
|
|
8
|
+
displayName: 'Install Node.js'
|
|
9
|
+
|
|
10
|
+
- task: Npm@1
|
|
11
|
+
inputs:
|
|
12
|
+
command: 'install'
|
|
13
|
+
displayName: "Install NPM Dependencies"
|
|
14
|
+
|
|
15
|
+
- task: Npm@1
|
|
16
|
+
inputs:
|
|
17
|
+
command: 'custom'
|
|
18
|
+
customCommand: 'test'
|
|
19
|
+
displayName: "Test"
|
|
20
|
+
|
|
21
|
+
- task: Npm@1
|
|
22
|
+
inputs:
|
|
23
|
+
command: 'custom'
|
|
24
|
+
customCommand: 'run build'
|
|
25
|
+
displayName: "Build"
|
|
26
|
+
|
|
27
|
+
- task: PublishCodeCoverageResults@2
|
|
28
|
+
displayName: "Publish code coverage results"
|
|
29
|
+
condition: succeededOrFailed()
|
|
30
|
+
inputs:
|
|
31
|
+
codeCoverageTool: Cobertura
|
|
32
|
+
summaryFileLocation: "coverage/cobertura-coverage.xml"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAliasedProperty = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Recursively gets the value of an aliased property. For example, if the query is `$orderby=@p1` and `@p1=name`, this function will return `name`
|
|
9
|
+
* @param parser The URLSearchParams object containing the query parameters
|
|
10
|
+
* @param result Will contain the error details in case there is any
|
|
11
|
+
* @param property The property to expand
|
|
12
|
+
* @returns The expanded property or null when there is an error
|
|
13
|
+
*/
|
|
14
|
+
const getAliasedProperty = (parser, result, property) => {
|
|
15
|
+
let propertyName = parser.get(property);
|
|
16
|
+
if (!propertyName) {
|
|
17
|
+
result.error = {
|
|
18
|
+
code: '0x80060888',
|
|
19
|
+
message: 'Order By Property must be of type EdmProperty'
|
|
20
|
+
};
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (!/^[@a-zA-Z]\w+/gi.test(propertyName)) {
|
|
24
|
+
const position = propertyName.length;
|
|
25
|
+
result.error = {
|
|
26
|
+
code: '0x80060888',
|
|
27
|
+
message: `Syntax error at position ${position} in '${propertyName}'.`
|
|
28
|
+
};
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (propertyName.startsWith('@')) {
|
|
32
|
+
return getAliasedProperty(parser, result, propertyName);
|
|
33
|
+
}
|
|
34
|
+
return propertyName;
|
|
35
|
+
};
|
|
36
|
+
exports.getAliasedProperty = getAliasedProperty;
|
|
@@ -77,7 +77,7 @@ const extractExpand = (value, $expand) => {
|
|
|
77
77
|
$expand.$expand[match[1]] = innerExpand;
|
|
78
78
|
}
|
|
79
79
|
matchLength = matchLength + index;
|
|
80
|
-
const secondMatch =
|
|
80
|
+
const secondMatch = new RegExp(/\s*(,?)\s*d/).exec(value.substring(matchLength + 1));
|
|
81
81
|
if (secondMatch !== null) {
|
|
82
82
|
matchLength = matchLength + secondMatch[0].length;
|
|
83
83
|
if (secondMatch[1] !== null) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFilterFromParser = void 0;
|
|
7
|
+
var _atMostOnce = require("./validators/atMostOnce");
|
|
8
|
+
const option = '$filter';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parses the {@link ODataFilter.$filter $filter} query
|
|
12
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
13
|
+
*/
|
|
14
|
+
const getFilterFromParser = (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.$filter = {
|
|
24
|
+
operator: 'eq',
|
|
25
|
+
left: '',
|
|
26
|
+
right: ''
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
};
|
|
31
|
+
exports.getFilterFromParser = getFilterFromParser;
|
|
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getOrderByFromParser = void 0;
|
|
7
|
+
var _getAliasedProperty = require("./getAliasedProperty");
|
|
7
8
|
var _atMostOnce = require("./validators/atMostOnce");
|
|
8
9
|
var _hasContent = require("./validators/hasContent");
|
|
9
10
|
const option = '$orderby';
|
|
10
|
-
const edmProperty = /\w{1-255}/gi;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Parses the {@link ODataOrderBy.$orderby $orderby} query
|
|
@@ -22,25 +22,56 @@ const getOrderByFromParser = (parser, result) => {
|
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
24
|
let $orderby = value[0].trimEnd();
|
|
25
|
+
let $orderbyParts = $orderby.split(',');
|
|
25
26
|
const orderByArray = [];
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
let position = 0;
|
|
28
|
+
for (const element of $orderbyParts) {
|
|
29
|
+
const parts = Array.from(element.matchAll(/\s*(\S+)/gi));
|
|
30
|
+
if (parts.length > 2) {
|
|
31
|
+
position = position + parts[0][0].length + parts[1][0].length + parts[2][0].length;
|
|
28
32
|
result.error = {
|
|
29
|
-
code: '
|
|
30
|
-
message: `Syntax error at position ${
|
|
33
|
+
code: '0x80060888',
|
|
34
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`
|
|
31
35
|
};
|
|
32
36
|
return false;
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
if (!/^[@a-zA-Z]\w+/gi.test(parts[0][1])) {
|
|
39
|
+
position = position + parts[0][0].length;
|
|
40
|
+
result.error = {
|
|
41
|
+
code: '0x80060888',
|
|
42
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`
|
|
43
|
+
};
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const orderBy = {
|
|
47
|
+
column: parts[0][1],
|
|
48
|
+
asc: true // default is ascending
|
|
49
|
+
};
|
|
50
|
+
if (parts[0][1].startsWith('@')) {
|
|
51
|
+
orderBy.column = (0, _getAliasedProperty.getAliasedProperty)(parser, result, parts[0][1]);
|
|
52
|
+
if (!orderBy.column) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (parts.length === 1) {
|
|
57
|
+
orderByArray.push(orderBy);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (parts[1][1].toLowerCase() === 'asc') {
|
|
61
|
+
orderBy.asc = true;
|
|
62
|
+
orderByArray.push(orderBy);
|
|
63
|
+
} else if (parts[1][1].toLowerCase() === 'desc') {
|
|
64
|
+
orderBy.asc = false;
|
|
65
|
+
orderByArray.push(orderBy);
|
|
66
|
+
} else {
|
|
67
|
+
position = position + parts[0][0].length + parts[1][0].length;
|
|
37
68
|
result.error = {
|
|
38
69
|
code: '0x80060888',
|
|
39
|
-
message:
|
|
70
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`
|
|
40
71
|
};
|
|
41
72
|
return false;
|
|
42
73
|
}
|
|
43
|
-
}
|
|
74
|
+
}
|
|
44
75
|
result.$orderby = orderByArray;
|
|
45
76
|
return true;
|
|
46
77
|
};
|
package/lib/cjs/index.js
CHANGED
|
@@ -53,5 +53,4 @@ var _getSelectFromParser = require("./getSelectFromParser");
|
|
|
53
53
|
var _getTopFromParser = require("./getTopFromParser");
|
|
54
54
|
var _getXQueryFromParser = require("./getXQueryFromParser");
|
|
55
55
|
var _parseOData = require("./parseOData");
|
|
56
|
-
var _default = _parseOData.parseOData;
|
|
57
|
-
exports.default = _default;
|
|
56
|
+
var _default = exports.default = _parseOData.parseOData;
|
package/lib/cjs/parseOData.js
CHANGED
|
@@ -10,6 +10,7 @@ var _getExpandFromParser = require("./getExpandFromParser");
|
|
|
10
10
|
var _getFetchXmlFromParser = require("./getFetchXmlFromParser");
|
|
11
11
|
var _getXQueryFromParser = require("./getXQueryFromParser");
|
|
12
12
|
var _getOrderByFromParser = require("./getOrderByFromParser");
|
|
13
|
+
var _getFilterFromParser = require("./getFilterFromParser");
|
|
13
14
|
/**
|
|
14
15
|
* parses the OData query and applies some Dataverse validations
|
|
15
16
|
* @param query The OData query
|
|
@@ -18,7 +19,7 @@ var _getOrderByFromParser = require("./getOrderByFromParser");
|
|
|
18
19
|
const parseOData = query => {
|
|
19
20
|
const parser = new URLSearchParams(query);
|
|
20
21
|
const result = {};
|
|
21
|
-
(0, _getExpandFromParser.getExpandFromParser)(parser, result) && (0,
|
|
22
|
+
(0, _getExpandFromParser.getExpandFromParser)(parser, result) && (0, _getFetchXmlFromParser.getFetchXmlFromParser)(parser, result) && (0, _getFilterFromParser.getFilterFromParser)(parser, result) && (0, _getSelectFromParser.getSelectFromParser)(parser, result) && (0, _getTopFromParser.getTopFromParser)(parser, result) && (0, _getXQueryFromParser.getXQueryFromParser)('savedQuery', parser, result) && (0, _getXQueryFromParser.getXQueryFromParser)('userQuery', parser, result) && (0, _getOrderByFromParser.getOrderByFromParser)(parser, result);
|
|
22
23
|
return result;
|
|
23
24
|
};
|
|
24
25
|
exports.parseOData = parseOData;
|
|
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
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
|
|
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.prototype.getAll URLSearchParams.getAll}
|
|
11
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
12
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
13
13
|
*/
|
|
14
14
|
const atMostOnce = (option, value, result) => {
|
|
15
15
|
if (value.length > 1) {
|
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
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
|
|
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
12
|
*/
|
|
13
13
|
const differentFromEmptyString = (value, result) => {
|
|
14
14
|
if (value[0] === '') {
|
|
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
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
|
|
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
13
|
*/
|
|
14
14
|
const hasContent = (query, value, result) => {
|
|
15
15
|
if (!value[0].trim()) {
|
|
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.isGuid = void 0;
|
|
7
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
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
|
|
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
14
|
*/
|
|
15
15
|
const isGuid = (value, result) => {
|
|
16
16
|
if (!value[0].match(guidRegex)) {
|
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
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
|
|
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
12
|
*/
|
|
13
13
|
const recognizedGuid = (value, result) => {
|
|
14
14
|
if (!value[0].trim()) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively gets the value of an aliased property. For example, if the query is `$orderby=@p1` and `@p1=name`, this function will return `name`
|
|
3
|
+
* @param parser The URLSearchParams object containing the query parameters
|
|
4
|
+
* @param result Will contain the error details in case there is any
|
|
5
|
+
* @param property The property to expand
|
|
6
|
+
* @returns The expanded property or null when there is an error
|
|
7
|
+
*/
|
|
8
|
+
export const getAliasedProperty = (parser, result, property) => {
|
|
9
|
+
let propertyName = parser.get(property);
|
|
10
|
+
if (!propertyName) {
|
|
11
|
+
result.error = {
|
|
12
|
+
code: '0x80060888',
|
|
13
|
+
message: 'Order By Property must be of type EdmProperty'
|
|
14
|
+
};
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (!/^[@a-zA-Z]\w+/gi.test(propertyName)) {
|
|
18
|
+
const position = propertyName.length;
|
|
19
|
+
result.error = {
|
|
20
|
+
code: '0x80060888',
|
|
21
|
+
message: `Syntax error at position ${position} in '${propertyName}'.`
|
|
22
|
+
};
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (propertyName.startsWith('@')) {
|
|
26
|
+
return getAliasedProperty(parser, result, propertyName);
|
|
27
|
+
}
|
|
28
|
+
return propertyName;
|
|
29
|
+
};
|
|
@@ -70,7 +70,7 @@ const extractExpand = (value, $expand) => {
|
|
|
70
70
|
$expand.$expand[match[1]] = innerExpand;
|
|
71
71
|
}
|
|
72
72
|
matchLength = matchLength + index;
|
|
73
|
-
const secondMatch =
|
|
73
|
+
const secondMatch = new RegExp(/\s*(,?)\s*d/).exec(value.substring(matchLength + 1));
|
|
74
74
|
if (secondMatch !== null) {
|
|
75
75
|
matchLength = matchLength + secondMatch[0].length;
|
|
76
76
|
if (secondMatch[1] !== null) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { atMostOnce } from './validators/atMostOnce';
|
|
2
|
+
const option = '$filter';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parses the {@link ODataFilter.$filter $filter} query
|
|
6
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
7
|
+
*/
|
|
8
|
+
export const getFilterFromParser = (parser, result) => {
|
|
9
|
+
const value = parser.getAll(option);
|
|
10
|
+
if (value.length === 0) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (!atMostOnce(option, value, result)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (value.length > 0) {
|
|
17
|
+
result.$filter = {
|
|
18
|
+
operator: 'eq',
|
|
19
|
+
left: '',
|
|
20
|
+
right: ''
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { getAliasedProperty } from './getAliasedProperty';
|
|
1
2
|
import { atMostOnce } from './validators/atMostOnce';
|
|
2
3
|
import { hasContent } from './validators/hasContent';
|
|
3
4
|
const option = '$orderby';
|
|
4
|
-
const edmProperty = /\w{1-255}/gi;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Parses the {@link ODataOrderBy.$orderby $orderby} query
|
|
@@ -16,25 +16,56 @@ export const getOrderByFromParser = (parser, result) => {
|
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
18
|
let $orderby = value[0].trimEnd();
|
|
19
|
+
let $orderbyParts = $orderby.split(',');
|
|
19
20
|
const orderByArray = [];
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
let position = 0;
|
|
22
|
+
for (const element of $orderbyParts) {
|
|
23
|
+
const parts = Array.from(element.matchAll(/\s*(\S+)/gi));
|
|
24
|
+
if (parts.length > 2) {
|
|
25
|
+
position = position + parts[0][0].length + parts[1][0].length + parts[2][0].length;
|
|
22
26
|
result.error = {
|
|
23
|
-
code: '
|
|
24
|
-
message: `Syntax error at position ${
|
|
27
|
+
code: '0x80060888',
|
|
28
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`
|
|
25
29
|
};
|
|
26
30
|
return false;
|
|
27
31
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
if (!/^[@a-zA-Z]\w+/gi.test(parts[0][1])) {
|
|
33
|
+
position = position + parts[0][0].length;
|
|
34
|
+
result.error = {
|
|
35
|
+
code: '0x80060888',
|
|
36
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`
|
|
37
|
+
};
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const orderBy = {
|
|
41
|
+
column: parts[0][1],
|
|
42
|
+
asc: true // default is ascending
|
|
43
|
+
};
|
|
44
|
+
if (parts[0][1].startsWith('@')) {
|
|
45
|
+
orderBy.column = getAliasedProperty(parser, result, parts[0][1]);
|
|
46
|
+
if (!orderBy.column) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (parts.length === 1) {
|
|
51
|
+
orderByArray.push(orderBy);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (parts[1][1].toLowerCase() === 'asc') {
|
|
55
|
+
orderBy.asc = true;
|
|
56
|
+
orderByArray.push(orderBy);
|
|
57
|
+
} else if (parts[1][1].toLowerCase() === 'desc') {
|
|
58
|
+
orderBy.asc = false;
|
|
59
|
+
orderByArray.push(orderBy);
|
|
60
|
+
} else {
|
|
61
|
+
position = position + parts[0][0].length + parts[1][0].length;
|
|
31
62
|
result.error = {
|
|
32
63
|
code: '0x80060888',
|
|
33
|
-
message:
|
|
64
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`
|
|
34
65
|
};
|
|
35
66
|
return false;
|
|
36
67
|
}
|
|
37
|
-
}
|
|
68
|
+
}
|
|
38
69
|
result.$orderby = orderByArray;
|
|
39
70
|
return true;
|
|
40
71
|
};
|
package/lib/esm/parseOData.js
CHANGED
|
@@ -4,6 +4,7 @@ import { getExpandFromParser } from './getExpandFromParser';
|
|
|
4
4
|
import { getFetchXmlFromParser } from './getFetchXmlFromParser';
|
|
5
5
|
import { getXQueryFromParser } from './getXQueryFromParser';
|
|
6
6
|
import { getOrderByFromParser } from './getOrderByFromParser';
|
|
7
|
+
import { getFilterFromParser } from './getFilterFromParser';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* parses the OData query and applies some Dataverse validations
|
|
@@ -13,6 +14,6 @@ import { getOrderByFromParser } from './getOrderByFromParser';
|
|
|
13
14
|
export const parseOData = query => {
|
|
14
15
|
const parser = new URLSearchParams(query);
|
|
15
16
|
const result = {};
|
|
16
|
-
getExpandFromParser(parser, result) &&
|
|
17
|
+
getExpandFromParser(parser, result) && getFetchXmlFromParser(parser, result) && getFilterFromParser(parser, result) && getSelectFromParser(parser, result) && getTopFromParser(parser, result) && getXQueryFromParser('savedQuery', parser, result) && getXQueryFromParser('userQuery', parser, result) && getOrderByFromParser(parser, result);
|
|
17
18
|
return result;
|
|
18
19
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Options of this type must be specified at most once.
|
|
3
|
-
* @param option The option being validated (ex. $top)
|
|
4
|
-
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
5
|
-
* @param result The {@link ODataQuery} to append the error to
|
|
6
|
-
* @returns {boolean} Returns `false` when the parse has an error
|
|
1
|
+
/**
|
|
2
|
+
* Options of this type must be specified at most once.
|
|
3
|
+
* @param option The option being validated (ex. $top)
|
|
4
|
+
* @param value The result of {@link URLSearchParams.prototype.getAll URLSearchParams.getAll}
|
|
5
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
6
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
7
7
|
*/
|
|
8
8
|
export const atMostOnce = (option, value, result) => {
|
|
9
9
|
if (value.length > 1) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
4
|
-
* @param result The {@link ODataQuery} to append the error to
|
|
5
|
-
* @returns {boolean} Returns `false` when the parse has an error
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
4
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
5
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
6
6
|
*/
|
|
7
7
|
export const differentFromEmptyString = (value, result) => {
|
|
8
8
|
if (value[0] === '') {
|