@twin.org/api-models 0.0.1-next.3 → 0.0.1-next.4
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/dist/cjs/index.cjs +59 -0
- package/dist/esm/index.mjs +60 -2
- package/dist/types/helpers/httpParameterHelper.d.ts +30 -0
- package/dist/types/index.d.ts +1 -0
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/HttpParameterHelper.md +101 -0
- package/docs/reference/index.md +1 -0
- package/package.json +2 -28
package/dist/cjs/index.cjs
CHANGED
|
@@ -65,6 +65,64 @@ class HttpErrorHelper {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
// Copyright 2024 IOTA Stiftung.
|
|
69
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
70
|
+
/**
|
|
71
|
+
* Class to help with handling http parameters.
|
|
72
|
+
*/
|
|
73
|
+
class HttpParameterHelper {
|
|
74
|
+
/**
|
|
75
|
+
* Convert list query to array.
|
|
76
|
+
* @param values The values query string.
|
|
77
|
+
* @returns The array of values.
|
|
78
|
+
*/
|
|
79
|
+
static arrayFromString(values) {
|
|
80
|
+
return values?.split(",");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Convert array of values to query string.
|
|
84
|
+
* @param values The values to combine string.
|
|
85
|
+
* @returns The combined.
|
|
86
|
+
*/
|
|
87
|
+
static arrayToString(values) {
|
|
88
|
+
return values?.join(",");
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Convert the conditions string to a list of comparators.
|
|
92
|
+
* @param conditions The conditions query string.
|
|
93
|
+
* @returns The list of comparators.
|
|
94
|
+
*/
|
|
95
|
+
static conditionsFromString(conditions) {
|
|
96
|
+
const conditionParts = conditions?.split(",") ?? [];
|
|
97
|
+
const conditionsList = [];
|
|
98
|
+
for (const conditionPart of conditionParts) {
|
|
99
|
+
const parts = conditionPart.split("|");
|
|
100
|
+
if (parts.length === 3) {
|
|
101
|
+
conditionsList.push({
|
|
102
|
+
property: parts[0],
|
|
103
|
+
comparison: parts[1],
|
|
104
|
+
value: parts[2]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return conditionsList.length === 0 ? undefined : conditionsList;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Convert the conditions to a string parameter.
|
|
112
|
+
* @param conditions The conditions to convert.
|
|
113
|
+
* @returns The string version of the comparators.
|
|
114
|
+
*/
|
|
115
|
+
static conditionsToString(conditions) {
|
|
116
|
+
if (core.Is.arrayValue(conditions)) {
|
|
117
|
+
const conditionsList = [];
|
|
118
|
+
for (const conditionPart of conditions) {
|
|
119
|
+
conditionsList.push(`${conditionPart.property}|${conditionPart.comparison}|${conditionPart.value}`);
|
|
120
|
+
}
|
|
121
|
+
return conditionsList.join(",");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
68
126
|
// Copyright 2024 IOTA Stiftung.
|
|
69
127
|
// SPDX-License-Identifier: Apache-2.0.
|
|
70
128
|
/**
|
|
@@ -88,3 +146,4 @@ const HealthStatus = {
|
|
|
88
146
|
|
|
89
147
|
exports.HealthStatus = HealthStatus;
|
|
90
148
|
exports.HttpErrorHelper = HttpErrorHelper;
|
|
149
|
+
exports.HttpParameterHelper = HttpParameterHelper;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseError, GuardError, ConflictError, NotFoundError, AlreadyExistsError, UnauthorizedError, NotImplementedError, UnprocessableError } from '@twin.org/core';
|
|
1
|
+
import { BaseError, GuardError, ConflictError, NotFoundError, AlreadyExistsError, UnauthorizedError, NotImplementedError, UnprocessableError, Is } from '@twin.org/core';
|
|
2
2
|
import { HttpStatusCode, HeaderTypes, MimeTypes } from '@twin.org/web';
|
|
3
3
|
|
|
4
4
|
// Copyright 2024 IOTA Stiftung.
|
|
@@ -63,6 +63,64 @@ class HttpErrorHelper {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
// Copyright 2024 IOTA Stiftung.
|
|
67
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
68
|
+
/**
|
|
69
|
+
* Class to help with handling http parameters.
|
|
70
|
+
*/
|
|
71
|
+
class HttpParameterHelper {
|
|
72
|
+
/**
|
|
73
|
+
* Convert list query to array.
|
|
74
|
+
* @param values The values query string.
|
|
75
|
+
* @returns The array of values.
|
|
76
|
+
*/
|
|
77
|
+
static arrayFromString(values) {
|
|
78
|
+
return values?.split(",");
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Convert array of values to query string.
|
|
82
|
+
* @param values The values to combine string.
|
|
83
|
+
* @returns The combined.
|
|
84
|
+
*/
|
|
85
|
+
static arrayToString(values) {
|
|
86
|
+
return values?.join(",");
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Convert the conditions string to a list of comparators.
|
|
90
|
+
* @param conditions The conditions query string.
|
|
91
|
+
* @returns The list of comparators.
|
|
92
|
+
*/
|
|
93
|
+
static conditionsFromString(conditions) {
|
|
94
|
+
const conditionParts = conditions?.split(",") ?? [];
|
|
95
|
+
const conditionsList = [];
|
|
96
|
+
for (const conditionPart of conditionParts) {
|
|
97
|
+
const parts = conditionPart.split("|");
|
|
98
|
+
if (parts.length === 3) {
|
|
99
|
+
conditionsList.push({
|
|
100
|
+
property: parts[0],
|
|
101
|
+
comparison: parts[1],
|
|
102
|
+
value: parts[2]
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return conditionsList.length === 0 ? undefined : conditionsList;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Convert the conditions to a string parameter.
|
|
110
|
+
* @param conditions The conditions to convert.
|
|
111
|
+
* @returns The string version of the comparators.
|
|
112
|
+
*/
|
|
113
|
+
static conditionsToString(conditions) {
|
|
114
|
+
if (Is.arrayValue(conditions)) {
|
|
115
|
+
const conditionsList = [];
|
|
116
|
+
for (const conditionPart of conditions) {
|
|
117
|
+
conditionsList.push(`${conditionPart.property}|${conditionPart.comparison}|${conditionPart.value}`);
|
|
118
|
+
}
|
|
119
|
+
return conditionsList.join(",");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
66
124
|
// Copyright 2024 IOTA Stiftung.
|
|
67
125
|
// SPDX-License-Identifier: Apache-2.0.
|
|
68
126
|
/**
|
|
@@ -84,4 +142,4 @@ const HealthStatus = {
|
|
|
84
142
|
Error: "error"
|
|
85
143
|
};
|
|
86
144
|
|
|
87
|
-
export { HealthStatus, HttpErrorHelper };
|
|
145
|
+
export { HealthStatus, HttpErrorHelper, HttpParameterHelper };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { IComparator } from "@twin.org/entity";
|
|
2
|
+
/**
|
|
3
|
+
* Class to help with handling http parameters.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpParameterHelper {
|
|
6
|
+
/**
|
|
7
|
+
* Convert list query to array.
|
|
8
|
+
* @param values The values query string.
|
|
9
|
+
* @returns The array of values.
|
|
10
|
+
*/
|
|
11
|
+
static arrayFromString<T = string>(values?: string): T[] | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Convert array of values to query string.
|
|
14
|
+
* @param values The values to combine string.
|
|
15
|
+
* @returns The combined.
|
|
16
|
+
*/
|
|
17
|
+
static arrayToString<T = string>(values?: T[]): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Convert the conditions string to a list of comparators.
|
|
20
|
+
* @param conditions The conditions query string.
|
|
21
|
+
* @returns The list of comparators.
|
|
22
|
+
*/
|
|
23
|
+
static conditionsFromString(conditions?: string): IComparator[] | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Convert the conditions to a string parameter.
|
|
26
|
+
* @param conditions The conditions to convert.
|
|
27
|
+
* @returns The string version of the comparators.
|
|
28
|
+
*/
|
|
29
|
+
static conditionsToString(conditions?: IComparator[]): string | undefined;
|
|
30
|
+
}
|
package/dist/types/index.d.ts
CHANGED
package/docs/changelog.md
CHANGED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Class: HttpParameterHelper
|
|
2
|
+
|
|
3
|
+
Class to help with handling http parameters.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### new HttpParameterHelper()
|
|
8
|
+
|
|
9
|
+
> **new HttpParameterHelper**(): [`HttpParameterHelper`](HttpParameterHelper.md)
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
[`HttpParameterHelper`](HttpParameterHelper.md)
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### arrayFromString()
|
|
18
|
+
|
|
19
|
+
> `static` **arrayFromString**\<`T`\>(`values`?): `undefined` \| `T`[]
|
|
20
|
+
|
|
21
|
+
Convert list query to array.
|
|
22
|
+
|
|
23
|
+
#### Type Parameters
|
|
24
|
+
|
|
25
|
+
• **T** = `string`
|
|
26
|
+
|
|
27
|
+
#### Parameters
|
|
28
|
+
|
|
29
|
+
• **values?**: `string`
|
|
30
|
+
|
|
31
|
+
The values query string.
|
|
32
|
+
|
|
33
|
+
#### Returns
|
|
34
|
+
|
|
35
|
+
`undefined` \| `T`[]
|
|
36
|
+
|
|
37
|
+
The array of values.
|
|
38
|
+
|
|
39
|
+
***
|
|
40
|
+
|
|
41
|
+
### arrayToString()
|
|
42
|
+
|
|
43
|
+
> `static` **arrayToString**\<`T`\>(`values`?): `undefined` \| `string`
|
|
44
|
+
|
|
45
|
+
Convert array of values to query string.
|
|
46
|
+
|
|
47
|
+
#### Type Parameters
|
|
48
|
+
|
|
49
|
+
• **T** = `string`
|
|
50
|
+
|
|
51
|
+
#### Parameters
|
|
52
|
+
|
|
53
|
+
• **values?**: `T`[]
|
|
54
|
+
|
|
55
|
+
The values to combine string.
|
|
56
|
+
|
|
57
|
+
#### Returns
|
|
58
|
+
|
|
59
|
+
`undefined` \| `string`
|
|
60
|
+
|
|
61
|
+
The combined.
|
|
62
|
+
|
|
63
|
+
***
|
|
64
|
+
|
|
65
|
+
### conditionsFromString()
|
|
66
|
+
|
|
67
|
+
> `static` **conditionsFromString**(`conditions`?): `undefined` \| `IComparator`[]
|
|
68
|
+
|
|
69
|
+
Convert the conditions string to a list of comparators.
|
|
70
|
+
|
|
71
|
+
#### Parameters
|
|
72
|
+
|
|
73
|
+
• **conditions?**: `string`
|
|
74
|
+
|
|
75
|
+
The conditions query string.
|
|
76
|
+
|
|
77
|
+
#### Returns
|
|
78
|
+
|
|
79
|
+
`undefined` \| `IComparator`[]
|
|
80
|
+
|
|
81
|
+
The list of comparators.
|
|
82
|
+
|
|
83
|
+
***
|
|
84
|
+
|
|
85
|
+
### conditionsToString()
|
|
86
|
+
|
|
87
|
+
> `static` **conditionsToString**(`conditions`?): `undefined` \| `string`
|
|
88
|
+
|
|
89
|
+
Convert the conditions to a string parameter.
|
|
90
|
+
|
|
91
|
+
#### Parameters
|
|
92
|
+
|
|
93
|
+
• **conditions?**: `IComparator`[]
|
|
94
|
+
|
|
95
|
+
The conditions to convert.
|
|
96
|
+
|
|
97
|
+
#### Returns
|
|
98
|
+
|
|
99
|
+
`undefined` \| `string`
|
|
100
|
+
|
|
101
|
+
The string version of the comparators.
|
package/docs/reference/index.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-models",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.4",
|
|
4
4
|
"description": "Contains models and classes for use with APIs",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,38 +13,12 @@
|
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"clean": "rimraf dist coverage",
|
|
18
|
-
"build": "tspc",
|
|
19
|
-
"test": "vitest --run --config ./vitest.config.ts --no-cache",
|
|
20
|
-
"coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
|
|
21
|
-
"bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
|
|
22
|
-
"bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
|
|
23
|
-
"bundle": "npm run bundle:esm && npm run bundle:cjs",
|
|
24
|
-
"docs:clean": "rimraf docs/reference",
|
|
25
|
-
"docs:generate": "typedoc",
|
|
26
|
-
"docs": "npm run docs:clean && npm run docs:generate",
|
|
27
|
-
"dist": "npm run clean && npm run build && npm run test && npm run bundle && npm run docs"
|
|
28
|
-
},
|
|
29
16
|
"dependencies": {
|
|
30
17
|
"@twin.org/core": "next",
|
|
18
|
+
"@twin.org/entity": "next",
|
|
31
19
|
"@twin.org/nameof": "next",
|
|
32
20
|
"@twin.org/web": "next"
|
|
33
21
|
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@twin.org/nameof-transformer": "next",
|
|
36
|
-
"@vitest/coverage-v8": "2.1.1",
|
|
37
|
-
"@types/node": "22.5.5",
|
|
38
|
-
"copyfiles": "2.4.1",
|
|
39
|
-
"rimraf": "6.0.1",
|
|
40
|
-
"rollup": "4.21.3",
|
|
41
|
-
"rollup-plugin-typescript2": "0.36.0",
|
|
42
|
-
"ts-patch": "3.2.1",
|
|
43
|
-
"typedoc": "0.26.7",
|
|
44
|
-
"typedoc-plugin-markdown": "4.2.7",
|
|
45
|
-
"typescript": "5.6.2",
|
|
46
|
-
"vitest": "2.1.1"
|
|
47
|
-
},
|
|
48
22
|
"main": "./dist/cjs/index.cjs",
|
|
49
23
|
"module": "./dist/esm/index.mjs",
|
|
50
24
|
"types": "./dist/types/index.d.ts",
|