@deltares/fews-web-oc-utils 2.0.2 → 2.1.1
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/README.md
CHANGED
|
@@ -1,36 +1,51 @@
|
|
|
1
1
|
# fews-web-oc-utils
|
|
2
2
|
|
|
3
3
|
## Project setup
|
|
4
|
+
|
|
4
5
|
```
|
|
5
6
|
npm install
|
|
6
7
|
```
|
|
8
|
+
|
|
7
9
|
### Compiles and minifies for production
|
|
10
|
+
|
|
8
11
|
```
|
|
9
12
|
npm run build
|
|
10
13
|
```
|
|
14
|
+
|
|
11
15
|
Build only esm bundle
|
|
16
|
+
|
|
12
17
|
```
|
|
13
18
|
npm run build:esm
|
|
14
19
|
```
|
|
20
|
+
|
|
15
21
|
Build only cjs bundle
|
|
22
|
+
|
|
16
23
|
```
|
|
17
24
|
npm run build:cjs
|
|
18
25
|
```
|
|
26
|
+
|
|
19
27
|
### Lints and fixes files
|
|
28
|
+
|
|
20
29
|
```
|
|
21
30
|
npm run lint
|
|
22
31
|
```
|
|
23
32
|
|
|
24
33
|
### Run tests
|
|
34
|
+
|
|
25
35
|
Get the coverage report
|
|
36
|
+
|
|
26
37
|
```
|
|
27
38
|
npm run test
|
|
28
39
|
```
|
|
40
|
+
|
|
29
41
|
Run only unit tests
|
|
42
|
+
|
|
30
43
|
```
|
|
31
44
|
npm run test:unit
|
|
32
45
|
```
|
|
46
|
+
|
|
33
47
|
Run only e2e tests
|
|
48
|
+
|
|
34
49
|
```
|
|
35
50
|
npm run test:e2e
|
|
36
51
|
```
|
|
@@ -1,79 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
class
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
async parse(e) {
|
|
71
|
-
return await e.text();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
export {
|
|
75
|
-
l as DefaultParser,
|
|
76
|
-
w as PiRestService,
|
|
77
|
-
q as PlainTextParser,
|
|
78
|
-
u as RequestOptions
|
|
1
|
+
//#region src/restservice/requestOptions.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
_mode = "cors";
|
|
4
|
+
_relativeUrl = !0;
|
|
5
|
+
get relativeUrl() {
|
|
6
|
+
return this._relativeUrl;
|
|
7
|
+
}
|
|
8
|
+
set relativeUrl(e) {
|
|
9
|
+
this._relativeUrl = e;
|
|
10
|
+
}
|
|
11
|
+
get mode() {
|
|
12
|
+
return this._mode;
|
|
13
|
+
}
|
|
14
|
+
set mode(e) {
|
|
15
|
+
this._mode = e;
|
|
16
|
+
}
|
|
17
|
+
}, t = class {
|
|
18
|
+
async parse(e) {
|
|
19
|
+
return await e.json();
|
|
20
|
+
}
|
|
21
|
+
}, n = class {
|
|
22
|
+
webserviceUrl;
|
|
23
|
+
transformRequest;
|
|
24
|
+
constructor(e, t) {
|
|
25
|
+
if (this.webserviceUrl = e, t === void 0) {
|
|
26
|
+
async function e(e) {
|
|
27
|
+
return e;
|
|
28
|
+
}
|
|
29
|
+
this.transformRequest = e;
|
|
30
|
+
} else this.transformRequest = t;
|
|
31
|
+
}
|
|
32
|
+
async getDataWithParser(e, t, n) {
|
|
33
|
+
let r = t.relativeUrl ? this.webserviceUrl + e : e, i = {}, a = {};
|
|
34
|
+
a.method = "GET";
|
|
35
|
+
let o = new Request(r, a), s = await fetch(await this.transformRequest(o));
|
|
36
|
+
if (!s.ok) throw Error("Fetch Error", { cause: s });
|
|
37
|
+
return await this.processResponse(i, s, r, n);
|
|
38
|
+
}
|
|
39
|
+
async postDataWithParser(e, t, n, r, i) {
|
|
40
|
+
let a = t.relativeUrl ? this.webserviceUrl + e : e, o = {}, s = {};
|
|
41
|
+
s.method = "POST", s.body = r, s.headers = i;
|
|
42
|
+
let c = new Request(a, s), l = await fetch(await this.transformRequest(c));
|
|
43
|
+
if (!l.ok) throw Error("Fetch Error", { cause: l });
|
|
44
|
+
return await this.processResponse(o, l, a, n);
|
|
45
|
+
}
|
|
46
|
+
async getData(n) {
|
|
47
|
+
let r = new e();
|
|
48
|
+
return r.relativeUrl = !n.startsWith("http"), this.getDataWithParser(n, r, new t());
|
|
49
|
+
}
|
|
50
|
+
async postData(n, r, i) {
|
|
51
|
+
let a = new e();
|
|
52
|
+
return a.relativeUrl = !n.startsWith("http"), this.postDataWithParser(n, a, new t(), r, {
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
...i
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async processResponse(e, t, n, r) {
|
|
58
|
+
e.responseCode = t.status, e.contentType = t.headers.get("content-type");
|
|
59
|
+
try {
|
|
60
|
+
e.data = await r.parse(t);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
throw Error(`Parse Error for response ${n}.`, { cause: e });
|
|
63
|
+
}
|
|
64
|
+
return e;
|
|
65
|
+
}
|
|
66
|
+
}, r = class {
|
|
67
|
+
async parse(e) {
|
|
68
|
+
return await e.text();
|
|
69
|
+
}
|
|
79
70
|
};
|
|
71
|
+
//#endregion
|
|
72
|
+
export { t as DefaultParser, n as PiRestService, r as PlainTextParser, e as RequestOptions };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import DataRequestResult from
|
|
2
|
-
import { RequestOptions } from
|
|
3
|
-
import { ResponseParser } from
|
|
4
|
-
export
|
|
5
|
-
(request: Request): Promise<Request>;
|
|
6
|
-
}
|
|
1
|
+
import type { DataRequestResult } from './dataRequestResult.js';
|
|
2
|
+
import { RequestOptions } from './requestOptions.js';
|
|
3
|
+
import { ResponseParser } from '../parser/responseParser.js';
|
|
4
|
+
export type TransformRequestFunction = (request: Request) => Promise<Request>;
|
|
7
5
|
export declare class PiRestService {
|
|
8
6
|
private readonly webserviceUrl;
|
|
9
|
-
private transformRequest;
|
|
7
|
+
private readonly transformRequest;
|
|
10
8
|
constructor(webserviceUrl: string, transformRequestFn?: TransformRequestFunction);
|
|
11
9
|
getDataWithParser<T>(url: string, requestOption: RequestOptions, parser: ResponseParser<T>): Promise<DataRequestResult<T>>;
|
|
12
10
|
postDataWithParser<T>(url: string, requestOption: RequestOptions, parser: ResponseParser<T>, body: BodyInit, headers: HeadersInit): Promise<DataRequestResult<T>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deltares/fews-web-oc-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Util Library for common Web OC functionality",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Werner Kramer",
|
|
@@ -23,29 +23,30 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"build": "
|
|
26
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
27
27
|
"doc": "typedoc --out doc src",
|
|
28
|
-
"lint": "
|
|
29
|
-
"
|
|
28
|
+
"lint": "npm run prettier",
|
|
29
|
+
"prettier": "prettier . --check",
|
|
30
|
+
"format": "prettier . --write",
|
|
30
31
|
"test:unit": "vitest run test/unit",
|
|
31
32
|
"test:e2e": "vitest run test/e2e",
|
|
32
|
-
"test": "vitest"
|
|
33
|
-
"sonar": "sonar-scanner -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN -Dsonar.projectKey=$SONAR_KEY -Dsonar.projectName='Delft-FEWS Web OC Utils'"
|
|
33
|
+
"test": "vitest"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@types/node": "^
|
|
38
|
-
"eslint": "^
|
|
36
|
+
"@eslint/js": "^10.0.1",
|
|
37
|
+
"@types/node": "^24.12.2",
|
|
38
|
+
"eslint": "^10.4.0",
|
|
39
39
|
"eslint-config-prettier": "^10.1.8",
|
|
40
40
|
"fetch-mock": "^12.6.0",
|
|
41
|
+
"globals": "^17.6.0",
|
|
41
42
|
"json-schema-to-typescript": "^15.0.4",
|
|
42
|
-
"
|
|
43
|
+
"prettier": "^3.8.3",
|
|
43
44
|
"tslib": "^2.8.1",
|
|
44
|
-
"typedoc": "^0.28.
|
|
45
|
-
"typescript": "^
|
|
46
|
-
"typescript-eslint": "^8.
|
|
47
|
-
"vite": "^
|
|
48
|
-
"vitest": "^4.
|
|
45
|
+
"typedoc": "^0.28.19",
|
|
46
|
+
"typescript": "^6.0.3",
|
|
47
|
+
"typescript-eslint": "^8.59.3",
|
|
48
|
+
"vite": "^8.0.13",
|
|
49
|
+
"vitest": "^4.1.6"
|
|
49
50
|
},
|
|
50
51
|
"engines": {
|
|
51
52
|
"node": ">=22.0.0"
|
|
@@ -63,5 +64,8 @@
|
|
|
63
64
|
"publishConfig": {
|
|
64
65
|
"access": "public",
|
|
65
66
|
"registry": "https://registry.npmjs.org"
|
|
67
|
+
},
|
|
68
|
+
"volta": {
|
|
69
|
+
"node": "24.14.1"
|
|
66
70
|
}
|
|
67
71
|
}
|