@twin.org/api-models 0.0.1-next.8 → 0.0.1-next.9

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.
@@ -88,71 +88,20 @@ class HttpParameterHelper {
88
88
  return values?.join(",");
89
89
  }
90
90
  /**
91
- * Convert the conditions string to a list of comparators.
92
- * @param conditions The conditions query string.
93
- * @returns The list of comparators.
91
+ * Convert object string to object.
92
+ * @param value The value query string.
93
+ * @returns The object.
94
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
- }
95
+ static objectFromString(value) {
96
+ return core.Coerce.object(value);
123
97
  }
124
98
  /**
125
- * Convert the sort string to a list of sort properties.
126
- * @param sortProperties The sort properties query string.
127
- * @returns The list of sort properties.
99
+ * Convert object to query string.
100
+ * @param value The value to convert to a string.
101
+ * @returns The converted object.
128
102
  */
129
- static sortPropertiesFromString(sortProperties) {
130
- const sortParts = sortProperties?.split(",") ?? [];
131
- const sortPropertyList = [];
132
- for (const conditionPart of sortParts) {
133
- const parts = conditionPart.split("|");
134
- if (parts.length === 2) {
135
- sortPropertyList.push({
136
- property: parts[0],
137
- sortDirection: parts[1]
138
- });
139
- }
140
- }
141
- return sortPropertyList.length === 0 ? undefined : sortPropertyList;
142
- }
143
- /**
144
- * Convert the sort properties to a string parameter.
145
- * @param sortProperties The sort properties to convert.
146
- * @returns The string version of the sort properties.
147
- */
148
- static sortPropertiesToString(sortProperties) {
149
- if (core.Is.arrayValue(sortProperties)) {
150
- const sortPropertyList = [];
151
- for (const conditionPart of sortProperties) {
152
- sortPropertyList.push(`${conditionPart.property}|${conditionPart.sortDirection}`);
153
- }
154
- return sortPropertyList.join(",");
155
- }
103
+ static objectToString(value) {
104
+ return core.Is.object(value) ? JSON.stringify(value) : undefined;
156
105
  }
157
106
  }
158
107
 
@@ -1,4 +1,4 @@
1
- import { BaseError, GuardError, ConflictError, NotFoundError, AlreadyExistsError, UnauthorizedError, NotImplementedError, UnprocessableError, Is } from '@twin.org/core';
1
+ import { BaseError, GuardError, ConflictError, NotFoundError, AlreadyExistsError, UnauthorizedError, NotImplementedError, UnprocessableError, Coerce, Is } from '@twin.org/core';
2
2
  import { HttpStatusCode, HeaderTypes, MimeTypes } from '@twin.org/web';
3
3
 
4
4
  // Copyright 2024 IOTA Stiftung.
@@ -86,71 +86,20 @@ class HttpParameterHelper {
86
86
  return values?.join(",");
87
87
  }
88
88
  /**
89
- * Convert the conditions string to a list of comparators.
90
- * @param conditions The conditions query string.
91
- * @returns The list of comparators.
89
+ * Convert object string to object.
90
+ * @param value The value query string.
91
+ * @returns The object.
92
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
- }
93
+ static objectFromString(value) {
94
+ return Coerce.object(value);
121
95
  }
122
96
  /**
123
- * Convert the sort string to a list of sort properties.
124
- * @param sortProperties The sort properties query string.
125
- * @returns The list of sort properties.
97
+ * Convert object to query string.
98
+ * @param value The value to convert to a string.
99
+ * @returns The converted object.
126
100
  */
127
- static sortPropertiesFromString(sortProperties) {
128
- const sortParts = sortProperties?.split(",") ?? [];
129
- const sortPropertyList = [];
130
- for (const conditionPart of sortParts) {
131
- const parts = conditionPart.split("|");
132
- if (parts.length === 2) {
133
- sortPropertyList.push({
134
- property: parts[0],
135
- sortDirection: parts[1]
136
- });
137
- }
138
- }
139
- return sortPropertyList.length === 0 ? undefined : sortPropertyList;
140
- }
141
- /**
142
- * Convert the sort properties to a string parameter.
143
- * @param sortProperties The sort properties to convert.
144
- * @returns The string version of the sort properties.
145
- */
146
- static sortPropertiesToString(sortProperties) {
147
- if (Is.arrayValue(sortProperties)) {
148
- const sortPropertyList = [];
149
- for (const conditionPart of sortProperties) {
150
- sortPropertyList.push(`${conditionPart.property}|${conditionPart.sortDirection}`);
151
- }
152
- return sortPropertyList.join(",");
153
- }
101
+ static objectToString(value) {
102
+ return Is.object(value) ? JSON.stringify(value) : undefined;
154
103
  }
155
104
  }
156
105
 
@@ -1,4 +1,3 @@
1
- import type { IComparator, SortDirection } from "@twin.org/entity";
2
1
  /**
3
2
  * Class to help with handling http parameters.
4
3
  */
@@ -16,33 +15,15 @@ export declare class HttpParameterHelper {
16
15
  */
17
16
  static arrayToString<T = string>(values?: T[]): string | undefined;
18
17
  /**
19
- * Convert the conditions string to a list of comparators.
20
- * @param conditions The conditions query string.
21
- * @returns The list of comparators.
18
+ * Convert object string to object.
19
+ * @param value The value query string.
20
+ * @returns The object.
22
21
  */
23
- static conditionsFromString(conditions?: string): IComparator[] | undefined;
22
+ static objectFromString<T = unknown>(value?: string): T | undefined;
24
23
  /**
25
- * Convert the conditions to a string parameter.
26
- * @param conditions The conditions to convert.
27
- * @returns The string version of the comparators.
24
+ * Convert object to query string.
25
+ * @param value The value to convert to a string.
26
+ * @returns The converted object.
28
27
  */
29
- static conditionsToString(conditions?: IComparator[]): string | undefined;
30
- /**
31
- * Convert the sort string to a list of sort properties.
32
- * @param sortProperties The sort properties query string.
33
- * @returns The list of sort properties.
34
- */
35
- static sortPropertiesFromString<T = unknown>(sortProperties?: string): {
36
- property: keyof T;
37
- sortDirection: SortDirection;
38
- }[] | undefined;
39
- /**
40
- * Convert the sort properties to a string parameter.
41
- * @param sortProperties The sort properties to convert.
42
- * @returns The string version of the sort properties.
43
- */
44
- static sortPropertiesToString<T = unknown>(sortProperties?: {
45
- property: keyof T;
46
- sortDirection: SortDirection;
47
- }[]): string | undefined;
28
+ static objectToString<T = unknown>(value?: T): string | undefined;
48
29
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/api-models - Changelog
2
2
 
3
- ## v0.0.1-next.8
3
+ ## v0.0.1-next.9
4
4
 
5
5
  - Initial Release
@@ -62,51 +62,11 @@ The combined.
62
62
 
63
63
  ***
64
64
 
65
- ### conditionsFromString()
65
+ ### objectFromString()
66
66
 
67
- > `static` **conditionsFromString**(`conditions`?): `undefined` \| `IComparator`[]
67
+ > `static` **objectFromString**\<`T`\>(`value`?): `undefined` \| `T`
68
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.
102
-
103
- ***
104
-
105
- ### sortPropertiesFromString()
106
-
107
- > `static` **sortPropertiesFromString**\<`T`\>(`sortProperties`?): `undefined` \| `object`[]
108
-
109
- Convert the sort string to a list of sort properties.
69
+ Convert object string to object.
110
70
 
111
71
  #### Type Parameters
112
72
 
@@ -114,23 +74,23 @@ Convert the sort string to a list of sort properties.
114
74
 
115
75
  #### Parameters
116
76
 
117
- • **sortProperties?**: `string`
77
+ • **value?**: `string`
118
78
 
119
- The sort properties query string.
79
+ The value query string.
120
80
 
121
81
  #### Returns
122
82
 
123
- `undefined` \| `object`[]
83
+ `undefined` \| `T`
124
84
 
125
- The list of sort properties.
85
+ The object.
126
86
 
127
87
  ***
128
88
 
129
- ### sortPropertiesToString()
89
+ ### objectToString()
130
90
 
131
- > `static` **sortPropertiesToString**\<`T`\>(`sortProperties`?): `undefined` \| `string`
91
+ > `static` **objectToString**\<`T`\>(`value`?): `undefined` \| `string`
132
92
 
133
- Convert the sort properties to a string parameter.
93
+ Convert object to query string.
134
94
 
135
95
  #### Type Parameters
136
96
 
@@ -138,12 +98,12 @@ Convert the sort properties to a string parameter.
138
98
 
139
99
  #### Parameters
140
100
 
141
- • **sortProperties?**: `object`[]
101
+ • **value?**: `T`
142
102
 
143
- The sort properties to convert.
103
+ The value to convert to a string.
144
104
 
145
105
  #### Returns
146
106
 
147
107
  `undefined` \| `string`
148
108
 
149
- The string version of the sort properties.
109
+ The converted object.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/api-models",
3
- "version": "0.0.1-next.8",
3
+ "version": "0.0.1-next.9",
4
4
  "description": "Contains models and classes for use with APIs",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,6 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
- "@twin.org/entity": "next",
19
18
  "@twin.org/nameof": "next",
20
19
  "@twin.org/web": "next"
21
20
  },