@shko.online/dataverse-odata 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +8 -0
- package/.github/workflows/publish.yml +44 -0
- package/.prettierrc.json +7 -7
- package/.releaserc.yaml +23 -23
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/azure-pipelines.yml +32 -0
- 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/cjs/OData.types.d.js +0 -1
- package/lib/cjs/getExpandFromParser.js +0 -122
- package/lib/cjs/getFetchXmlFromParser.js +0 -52
- package/lib/cjs/getOrderByFromParser.js +0 -47
- package/lib/cjs/getSelectFromParser.js +0 -27
- package/lib/cjs/getTopFromParser.js +0 -40
- package/lib/cjs/getXQueryFromParser.js +0 -25
- package/lib/cjs/index.js +0 -57
- package/lib/cjs/parseOData.js +0 -24
- package/lib/cjs/validators/atMostOnce.js +0 -24
- package/lib/cjs/validators/differentFromEmptyString.js +0 -23
- package/lib/cjs/validators/hasContent.js +0 -24
- package/lib/cjs/validators/isGuid.js +0 -25
- package/lib/cjs/validators/recognizedGuid.js +0 -23
- package/lib/esm/OData.types.d.js +0 -0
- package/lib/esm/getExpandFromParser.js +0 -115
- package/lib/esm/getFetchXmlFromParser.js +0 -45
- package/lib/esm/getOrderByFromParser.js +0 -40
- package/lib/esm/getSelectFromParser.js +0 -20
- package/lib/esm/getTopFromParser.js +0 -33
- package/lib/esm/getXQueryFromParser.js +0 -19
- package/lib/esm/index.js +0 -9
- package/lib/esm/parseOData.js +0 -18
- package/lib/esm/validators/atMostOnce.js +0 -17
- package/lib/esm/validators/differentFromEmptyString.js +0 -16
- package/lib/esm/validators/hasContent.js +0 -17
- package/lib/esm/validators/isGuid.js +0 -18
- package/lib/esm/validators/recognizedGuid.js +0 -16
- package/lib/modern/OData.types.d.js +0 -0
- package/lib/modern/getExpandFromParser.js +0 -115
- package/lib/modern/getFetchXmlFromParser.js +0 -45
- package/lib/modern/getOrderByFromParser.js +0 -41
- package/lib/modern/getSelectFromParser.js +0 -20
- package/lib/modern/getTopFromParser.js +0 -33
- package/lib/modern/getXQueryFromParser.js +0 -19
- package/lib/modern/index.js +0 -9
- package/lib/modern/parseOData.js +0 -18
- package/lib/modern/validators/atMostOnce.js +0 -17
- package/lib/modern/validators/differentFromEmptyString.js +0 -16
- package/lib/modern/validators/hasContent.js +0 -17
- package/lib/modern/validators/isGuid.js +0 -18
- package/lib/modern/validators/recognizedGuid.js +0 -16
- package/lib/ts3.4/OData.types.d.ts +0 -118
- package/lib/ts3.4/getExpandFromParser.d.ts +0 -7
- package/lib/ts3.4/getFetchXmlFromParser.d.ts +0 -7
- package/lib/ts3.4/getOrderByFromParser.d.ts +0 -7
- package/lib/ts3.4/getSelectFromParser.d.ts +0 -7
- package/lib/ts3.4/getTopFromParser.d.ts +0 -7
- package/lib/ts3.4/getXQueryFromParser.d.ts +0 -8
- package/lib/ts3.4/index.d.ts +0 -11
- package/lib/ts3.4/parseOData.d.ts +0 -8
- package/lib/ts3.4/validators/atMostOnce.d.ts +0 -10
- package/lib/ts3.4/validators/differentFromEmptyString.d.ts +0 -9
- package/lib/ts3.4/validators/hasContent.d.ts +0 -10
- package/lib/ts3.4/validators/isGuid.d.ts +0 -9
- package/lib/ts3.4/validators/recognizedGuid.d.ts +0 -9
- package/lib/ts3.9/OData.types.d.ts +0 -154
- package/lib/ts3.9/getExpandFromParser.d.ts +0 -7
- package/lib/ts3.9/getExpandFromParser.d.ts.map +0 -1
- package/lib/ts3.9/getFetchXmlFromParser.d.ts +0 -7
- package/lib/ts3.9/getFetchXmlFromParser.d.ts.map +0 -1
- package/lib/ts3.9/getOrderByFromParser.d.ts +0 -7
- package/lib/ts3.9/getOrderByFromParser.d.ts.map +0 -1
- package/lib/ts3.9/getSelectFromParser.d.ts +0 -7
- package/lib/ts3.9/getSelectFromParser.d.ts.map +0 -1
- package/lib/ts3.9/getTopFromParser.d.ts +0 -7
- package/lib/ts3.9/getTopFromParser.d.ts.map +0 -1
- package/lib/ts3.9/getXQueryFromParser.d.ts +0 -8
- package/lib/ts3.9/getXQueryFromParser.d.ts.map +0 -1
- package/lib/ts3.9/index.d.ts +0 -11
- package/lib/ts3.9/index.d.ts.map +0 -1
- package/lib/ts3.9/parseOData.d.ts +0 -8
- package/lib/ts3.9/parseOData.d.ts.map +0 -1
- package/lib/ts3.9/validators/atMostOnce.d.ts +0 -10
- package/lib/ts3.9/validators/atMostOnce.d.ts.map +0 -1
- package/lib/ts3.9/validators/differentFromEmptyString.d.ts +0 -9
- package/lib/ts3.9/validators/differentFromEmptyString.d.ts.map +0 -1
- package/lib/ts3.9/validators/hasContent.d.ts +0 -10
- package/lib/ts3.9/validators/hasContent.d.ts.map +0 -1
- package/lib/ts3.9/validators/isGuid.d.ts +0 -9
- package/lib/ts3.9/validators/isGuid.d.ts.map +0 -1
- package/lib/ts3.9/validators/recognizedGuid.d.ts +0 -9
- package/lib/ts3.9/validators/recognizedGuid.d.ts.map +0 -1
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: Update npm
|
|
33
|
+
run: npm install -g npm@latest
|
|
34
|
+
|
|
35
|
+
- name: Install dependencies
|
|
36
|
+
run: npm ci
|
|
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,10 @@
|
|
|
1
|
+
## [0.1.5](https://github.com/Shko-Online/dataverse-odata/compare/v0.1.4...v0.1.5) (2026-03-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Properly implemented $orderBy ([c693298](https://github.com/Shko-Online/dataverse-odata/commit/c693298bcc4cb2a96ebbc39939c60fb5abdd93d4))
|
|
7
|
+
|
|
1
8
|
## [0.1.4](https://github.com/shko-online/dataverse-odata/compare/v0.1.3...v0.1.4) (2023-02-12)
|
|
2
9
|
|
|
3
10
|
|
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"
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shko.online/dataverse-odata",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "This package will help parse OData strings (only the Microsoft Dataverse subset). It can be used as a validator, or you can build some javascript library which consumes the output of this library.",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"build": "npm run lint &&
|
|
6
|
+
"build": "npm run lint && build-npm-package",
|
|
7
7
|
"lint": "eslint",
|
|
8
8
|
"tsc": "tsc --project tsconfig.build.json",
|
|
9
|
-
"test": "jest
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"test:coverage": "jest --coverage",
|
|
10
11
|
"semantic-release": "semantic-release"
|
|
11
12
|
},
|
|
12
13
|
"exports": {
|
|
@@ -26,7 +27,10 @@
|
|
|
26
27
|
]
|
|
27
28
|
}
|
|
28
29
|
},
|
|
29
|
-
"repository":
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/Shko-Online/dataverse-odata"
|
|
33
|
+
},
|
|
30
34
|
"keywords": [
|
|
31
35
|
"odata",
|
|
32
36
|
"dataverse",
|
|
@@ -55,24 +59,29 @@
|
|
|
55
59
|
"@babel/preset-typescript": "^7.18.6",
|
|
56
60
|
"@emotion/babel-plugin": "^11.10.5",
|
|
57
61
|
"@jest/globals": "^29.4.2",
|
|
58
|
-
"@semantic-release/changelog": "^6.0.
|
|
59
|
-
"@semantic-release/commit-analyzer": "^
|
|
60
|
-
"@semantic-release/exec": "^
|
|
62
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
63
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
64
|
+
"@semantic-release/exec": "^7.1.0",
|
|
61
65
|
"@semantic-release/git": "^10.0.1",
|
|
62
|
-
"@semantic-release/
|
|
63
|
-
"@
|
|
66
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
67
|
+
"@shko.online/build-npm-package": "^0.1.0",
|
|
64
68
|
"@storybook/babel-plugin-require-context-hook": "^1.0.1",
|
|
69
|
+
"@types/node": "^24.12.0",
|
|
65
70
|
"@typescript-eslint/eslint-plugin": "^5.40.1",
|
|
66
71
|
"@typescript-eslint/parser": "^5.40.1",
|
|
67
72
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
68
73
|
"babel-plugin-macros": "^3.1.0",
|
|
69
74
|
"copyfiles": "^2.4.1",
|
|
70
75
|
"eslint": "^8.25.0",
|
|
76
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
77
|
+
"eslint-plugin-react": "^7.37.5",
|
|
71
78
|
"jest": "^29.2.1",
|
|
72
79
|
"jest-environment-jsdom": "^29.2.1",
|
|
73
|
-
"
|
|
80
|
+
"prettier": "^3.8.1",
|
|
81
|
+
"prettier-eslint": "^16.4.2",
|
|
82
|
+
"semantic-release": "^25.0.3",
|
|
74
83
|
"ts-jest": "^29.0.3",
|
|
75
84
|
"ts-node": "^10.9.1",
|
|
76
|
-
"typescript": "^
|
|
85
|
+
"typescript": "^5.9.3"
|
|
77
86
|
}
|
|
78
87
|
}
|
package/src/OData.types.d.ts
CHANGED
|
@@ -30,13 +30,15 @@ type ODataExpandQuery = ODataSelect & ODataExpand;
|
|
|
30
30
|
|
|
31
31
|
interface ODataFilter {
|
|
32
32
|
/**
|
|
33
|
-
* Use the {@link
|
|
33
|
+
* Use the {@link $filter $filter} system query option to set criteria for which rows will be returned.
|
|
34
34
|
*
|
|
35
35
|
* * Microsoft Docs: {@link https://learn.microsoft.com/power-apps/developer/data-platform/webapi/query-data-web-api?WT.mc_id=DX-MVP-5004767#filter-results Filter results }
|
|
36
36
|
*/
|
|
37
|
-
$filter?:
|
|
37
|
+
$filter?: FilterOperator;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
type FilterOperator = StandardOperator | ColumnOperator | UnaryOperator | BinaryOperator | QueryFunctionOperator;
|
|
41
|
+
|
|
40
42
|
interface ODataFetch {
|
|
41
43
|
/**
|
|
42
44
|
* You can compose a FetchXML query for a specific table.
|
|
@@ -100,7 +102,20 @@ interface ODataUserQuery {
|
|
|
100
102
|
userQuery?: string;
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
type
|
|
105
|
+
type StandardEqualityOperators = 'eq' | 'ne';
|
|
106
|
+
|
|
107
|
+
type StandardOperators = StandardEqualityOperators | 'gt' | 'ge' | 'lt' | 'le';
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* * Microsoft Docs: {@link https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/query/filter-rows#column-comparison Column comparison }
|
|
112
|
+
*/
|
|
113
|
+
interface ColumnOperator {
|
|
114
|
+
column: string;
|
|
115
|
+
operator: StandardOperators;
|
|
116
|
+
otherColumn: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
104
119
|
|
|
105
120
|
interface StandardOperator {
|
|
106
121
|
operator: StandardOperators;
|
|
@@ -114,15 +129,29 @@ interface StandardOperator {
|
|
|
114
129
|
right: string | number;
|
|
115
130
|
}
|
|
116
131
|
|
|
132
|
+
type QueryFunctionOperators = 'contains' | 'endswith' | 'startswith';
|
|
133
|
+
|
|
134
|
+
interface QueryFunctionOperator {
|
|
135
|
+
operator: QueryFunctionOperators;
|
|
136
|
+
/**
|
|
137
|
+
* The left side of the 'X' operator must be a property of the entity.
|
|
138
|
+
*/
|
|
139
|
+
left: string;
|
|
140
|
+
/**
|
|
141
|
+
* The right side of the 'X' operator must be a constant value.
|
|
142
|
+
*/
|
|
143
|
+
right: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
117
146
|
interface UnaryOperator {
|
|
118
147
|
operator: 'not';
|
|
119
|
-
right:
|
|
148
|
+
right: FilterOperator;
|
|
120
149
|
}
|
|
121
150
|
|
|
122
151
|
interface BinaryOperator {
|
|
123
152
|
operator: 'and' | 'or';
|
|
124
|
-
left:
|
|
125
|
-
right:
|
|
153
|
+
left: FilterOperator;
|
|
154
|
+
right: FilterOperator;
|
|
126
155
|
}
|
|
127
156
|
|
|
128
157
|
type ODataQuery = ODataError &
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ODataQuery } from "./OData.types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Recursively gets the value of an aliased property. For example, if the query is `$orderby=@p1` and `@p1=name`, this function will return `name`
|
|
5
|
+
* @param parser The URLSearchParams object containing the query parameters
|
|
6
|
+
* @param result Will contain the error details in case there is any
|
|
7
|
+
* @param property The property to expand
|
|
8
|
+
* @returns The expanded property or null when there is an error
|
|
9
|
+
*/
|
|
10
|
+
export const getAliasedProperty = (parser: URLSearchParams, result: ODataQuery, property: string): string => {
|
|
11
|
+
let propertyName = parser.get(property);
|
|
12
|
+
if (!propertyName) {
|
|
13
|
+
result.error = {
|
|
14
|
+
code: '0x80060888',
|
|
15
|
+
message: 'Order By Property must be of type EdmProperty',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!/^[@a-zA-Z]\w+/gi.test(propertyName)) {
|
|
22
|
+
const position = propertyName.length;
|
|
23
|
+
result.error = {
|
|
24
|
+
code: '0x80060888',
|
|
25
|
+
message: `Syntax error at position ${position} in '${propertyName}'.`,
|
|
26
|
+
};
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (propertyName.startsWith('@')) {
|
|
31
|
+
return getAliasedProperty(parser, result, propertyName);
|
|
32
|
+
}
|
|
33
|
+
return propertyName;
|
|
34
|
+
};
|
|
@@ -77,7 +77,7 @@ const extractExpand = (value: string, $expand: ODataExpand & ODataError) => {
|
|
|
77
77
|
}
|
|
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,23 @@
|
|
|
1
|
+
import type { ODataQuery, ODataFilter } from './OData.types';
|
|
2
|
+
import { atMostOnce } from './validators/atMostOnce';
|
|
3
|
+
|
|
4
|
+
const option = '$filter';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Parses the {@link ODataFilter.$filter $filter} query
|
|
8
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
9
|
+
*/
|
|
10
|
+
export const getFilterFromParser = (parser: URLSearchParams, result: ODataQuery): boolean => {
|
|
11
|
+
const value = parser.getAll(option);
|
|
12
|
+
if (value.length === 0) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (!atMostOnce(option, value, result)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (value.length > 0) {
|
|
19
|
+
|
|
20
|
+
result.$filter = {operator: 'eq', left: '', right: ''};
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { getAliasedProperty } from './getAliasedProperty';
|
|
1
2
|
import type { ODataQuery, ODataOrderBy } from './OData.types';
|
|
2
3
|
import { atMostOnce } from './validators/atMostOnce';
|
|
3
4
|
import { hasContent } from './validators/hasContent';
|
|
4
5
|
|
|
5
6
|
const option = '$orderby';
|
|
6
|
-
const edmProperty = /\w{1-255}/gi;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Parses the {@link ODataOrderBy.$orderby $orderby} query
|
|
@@ -18,27 +18,63 @@ export const getOrderByFromParser = (parser: URLSearchParams, result: ODataQuery
|
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
let $orderby = value[0].trimEnd();
|
|
21
|
+
let $orderbyParts = $orderby.split(',');
|
|
21
22
|
const orderByArray: ODataOrderBy['$orderby'] = [];
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
let position = 0;
|
|
24
|
+
for (const element of $orderbyParts) {
|
|
25
|
+
const parts = Array.from(element.matchAll(/\s*(\S+)/gi));
|
|
26
|
+
|
|
27
|
+
if (parts.length > 2) {
|
|
28
|
+
position = position + parts[0][0].length + parts[1][0].length + parts[2][0].length;
|
|
24
29
|
result.error = {
|
|
25
|
-
code: '
|
|
26
|
-
message: `Syntax error at position ${
|
|
30
|
+
code: '0x80060888',
|
|
31
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`,
|
|
27
32
|
};
|
|
28
33
|
|
|
29
34
|
return false;
|
|
30
35
|
}
|
|
31
|
-
}
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
if (!/^[@a-zA-Z]\w+/gi.test(parts[0][1])) {
|
|
38
|
+
position = position + parts[0][0].length;
|
|
35
39
|
result.error = {
|
|
36
40
|
code: '0x80060888',
|
|
37
|
-
message:
|
|
41
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`,
|
|
38
42
|
};
|
|
39
43
|
return false;
|
|
40
44
|
}
|
|
41
|
-
|
|
45
|
+
|
|
46
|
+
const orderBy: ODataOrderBy['$orderby'][0] = {
|
|
47
|
+
column: parts[0][1],
|
|
48
|
+
asc: true, // default is ascending
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
if (parts[0][1].startsWith('@')) {
|
|
52
|
+
orderBy.column = getAliasedProperty(parser, result, parts[0][1]);
|
|
53
|
+
if (!orderBy.column) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (parts.length === 1) {
|
|
59
|
+
orderByArray.push(orderBy);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (parts[1][1].toLowerCase() === 'asc') {
|
|
64
|
+
orderBy.asc = true;
|
|
65
|
+
orderByArray.push(orderBy);
|
|
66
|
+
} else if (parts[1][1].toLowerCase() === 'desc') {
|
|
67
|
+
orderBy.asc = false;
|
|
68
|
+
orderByArray.push(orderBy);
|
|
69
|
+
} else {
|
|
70
|
+
position = position + parts[0][0].length + parts[1][0].length;
|
|
71
|
+
result.error = {
|
|
72
|
+
code: '0x80060888',
|
|
73
|
+
message: `Syntax error at position ${position} in '${$orderby}'.`,
|
|
74
|
+
};
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
42
78
|
|
|
43
79
|
result.$orderby = orderByArray;
|
|
44
80
|
|
package/src/parseOData.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { getExpandFromParser } from './getExpandFromParser';
|
|
|
6
6
|
import { getFetchXmlFromParser } from './getFetchXmlFromParser';
|
|
7
7
|
import { getXQueryFromParser } from './getXQueryFromParser';
|
|
8
8
|
import { getOrderByFromParser } from './getOrderByFromParser';
|
|
9
|
+
import { getFilterFromParser } from './getFilterFromParser';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* parses the OData query and applies some Dataverse validations
|
|
@@ -17,9 +18,10 @@ export const parseOData = (query: string) => {
|
|
|
17
18
|
const result = {} as ODataQuery;
|
|
18
19
|
|
|
19
20
|
getExpandFromParser(parser, result) &&
|
|
21
|
+
getFetchXmlFromParser(parser, result) &&
|
|
22
|
+
getFilterFromParser(parser, result) &&
|
|
20
23
|
getSelectFromParser(parser, result) &&
|
|
21
24
|
getTopFromParser(parser, result) &&
|
|
22
|
-
getFetchXmlFromParser(parser, result) &&
|
|
23
25
|
getXQueryFromParser('savedQuery', parser, result) &&
|
|
24
26
|
getXQueryFromParser('userQuery', parser, result) &&
|
|
25
27
|
getOrderByFromParser(parser, result);
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { ODataQuery } from '../OData.types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Options of this type must be specified at most once.
|
|
5
|
-
* @param option The option being validated (ex. $top)
|
|
6
|
-
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
7
|
-
* @param result The {@link ODataQuery} to append the error to
|
|
8
|
-
* @returns {boolean} Returns `false` when the parse has an error
|
|
9
|
-
*/
|
|
10
|
-
export const atMostOnce = (option: string, value: string[], result: ODataQuery) => {
|
|
11
|
-
if (value.length > 1) {
|
|
12
|
-
result.error = {
|
|
13
|
-
code: '0x0',
|
|
14
|
-
message: `Query option '${option}' was specified more than once, but it must be specified at most once.`,
|
|
15
|
-
};
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
};
|
|
1
|
+
import type { ODataQuery } from '../OData.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options of this type must be specified at most once.
|
|
5
|
+
* @param option The option being validated (ex. $top)
|
|
6
|
+
* @param value The result of {@link URLSearchParams.prototype.getAll URLSearchParams.getAll}
|
|
7
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
8
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
9
|
+
*/
|
|
10
|
+
export const atMostOnce = (option: string, value: string[], result: ODataQuery) => {
|
|
11
|
+
if (value.length > 1) {
|
|
12
|
+
result.error = {
|
|
13
|
+
code: '0x0',
|
|
14
|
+
message: `Query option '${option}' was specified more than once, but it must be specified at most once.`,
|
|
15
|
+
};
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { ODataQuery } from '../OData.types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
6
|
-
* @param result The {@link ODataQuery} to append the error to
|
|
7
|
-
* @returns {boolean} Returns `false` when the parse has an error
|
|
8
|
-
*/
|
|
9
|
-
export const differentFromEmptyString = (value: string[], result: ODataQuery) => {
|
|
10
|
-
if (value[0] === '') {
|
|
11
|
-
result.error = {
|
|
12
|
-
code: '0x80040203',
|
|
13
|
-
message: 'Expected non-empty string.',
|
|
14
|
-
};
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
18
|
-
};
|
|
1
|
+
import type { ODataQuery } from '../OData.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
6
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
7
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
8
|
+
*/
|
|
9
|
+
export const differentFromEmptyString = (value: string[], result: ODataQuery) => {
|
|
10
|
+
if (value[0] === '') {
|
|
11
|
+
result.error = {
|
|
12
|
+
code: '0x80040203',
|
|
13
|
+
message: 'Expected non-empty string.',
|
|
14
|
+
};
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { ODataQuery } from '../OData.types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Options of this type must be specified at most once.
|
|
5
|
-
* @param option The option being validated (ex. $top)
|
|
6
|
-
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
7
|
-
* @param result The {@link ODataQuery} to append the error to
|
|
8
|
-
* @returns {boolean} Returns `false` when the parse has an error
|
|
9
|
-
*/
|
|
10
|
-
export const hasContent = (query: string, value: string[], result: ODataQuery) => {
|
|
11
|
-
if (!value[0].trim()) {
|
|
12
|
-
result.error = {
|
|
13
|
-
code: '0x0',
|
|
14
|
-
message: `The value for OData query '${query}' cannot be empty.`,
|
|
15
|
-
};
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
};
|
|
1
|
+
import type { ODataQuery } from '../OData.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options of this type must be specified at most once.
|
|
5
|
+
* @param option The option being validated (ex. $top)
|
|
6
|
+
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
7
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
8
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
9
|
+
*/
|
|
10
|
+
export const hasContent = (query: string, value: string[], result: ODataQuery) => {
|
|
11
|
+
if (!value[0].trim()) {
|
|
12
|
+
result.error = {
|
|
13
|
+
code: '0x0',
|
|
14
|
+
message: `The value for OData query '${query}' cannot be empty.`,
|
|
15
|
+
};
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
};
|
package/src/validators/isGuid.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type { ODataQuery } 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
|
-
*
|
|
7
|
-
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
8
|
-
* @param result The {@link ODataQuery} to append the error to
|
|
9
|
-
* @returns {boolean} Returns `false` when the parse has an error
|
|
10
|
-
*/
|
|
11
|
-
export const isGuid = (value: string[], result: ODataQuery) => {
|
|
12
|
-
if (!value[0].match(guidRegex)) {
|
|
13
|
-
result.error = {
|
|
14
|
-
code: '0x0',
|
|
15
|
-
message: 'Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).',
|
|
16
|
-
};
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
};
|
|
1
|
+
import type { ODataQuery } 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
|
+
*
|
|
7
|
+
* @param value The result of {@link URLSearchParams.getAll getAll}
|
|
8
|
+
* @param result The {@link ODataQuery} to append the error to
|
|
9
|
+
* @returns {boolean} Returns `false` when the parse has an error
|
|
10
|
+
*/
|
|
11
|
+
export const isGuid = (value: string[], result: ODataQuery) => {
|
|
12
|
+
if (!value[0].match(guidRegex)) {
|
|
13
|
+
result.error = {
|
|
14
|
+
code: '0x0',
|
|
15
|
+
message: 'Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).',
|
|
16
|
+
};
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
};
|