basyx-typescript-sdk 0.1.11 → 0.2.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 +14 -1
- package/bundle/index.js +287 -235
- package/bundle/index.js.map +1 -1
- package/dist/clients/AasRepositoryClient.d.ts +198 -129
- package/dist/clients/AasRepositoryClient.js +245 -234
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/base64Url.d.ts +32 -0
- package/dist/lib/base64Url.js +62 -0
- package/dist/models/AssetId.d.ts +11 -0
- package/dist/models/AssetId.js +1 -0
- package/dist/models/aas-repository.d.ts +58 -3
- package/dist/models/api.d.ts +12 -0
- package/dist/models/api.js +1 -0
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.js +3 -0
- package/package.json +3 -2
|
@@ -1,400 +1,411 @@
|
|
|
1
1
|
import * as AasRepository from '../generated';
|
|
2
|
+
import { base64Encode } from '../lib/base64Url';
|
|
2
3
|
import { convertApiAasToCoreAas, convertApiAssetInformationToCoreAssetInformation, convertApiReferenceToCoreReference, convertCoreAasToApiAas, convertCoreAssetInformationToApiAssetInformation, convertCoreReferenceToApiReference, } from '../lib/convertAasTypes';
|
|
3
4
|
import { createCustomClient } from '../lib/createAasRepoClient';
|
|
4
5
|
export class AasRepositoryClient {
|
|
5
6
|
/**
|
|
6
|
-
* Returns all Asset Administration Shells
|
|
7
|
+
* Returns all Asset Administration Shells.
|
|
7
8
|
*
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @returns {
|
|
9
|
+
* @param options Object containing:
|
|
10
|
+
* - baseUrl: The API base URL
|
|
11
|
+
* - headers?: Optional Request headers
|
|
12
|
+
* - assetIds?: A list of asset identifiers
|
|
13
|
+
* - idShort?: The AAS's idShort
|
|
14
|
+
* - limit?: Max number of elements to return
|
|
15
|
+
* - cursor?: A paging cursor from previous responses
|
|
16
|
+
*
|
|
17
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
17
18
|
*/
|
|
18
|
-
async getAllAssetAdministrationShells(
|
|
19
|
+
async getAllAssetAdministrationShells(options) {
|
|
20
|
+
const { baseUrl, headers, assetIds, idShort, limit, cursor } = options;
|
|
19
21
|
try {
|
|
20
|
-
const client = createCustomClient(
|
|
22
|
+
const client = createCustomClient(baseUrl, headers);
|
|
23
|
+
const encodedAssetIds = assetIds?.map((id) => base64Encode(JSON.stringify(id)));
|
|
21
24
|
const { data, error } = await AasRepository.getAllAssetAdministrationShells({
|
|
22
25
|
client,
|
|
23
|
-
query: {
|
|
24
|
-
assetIds,
|
|
25
|
-
idShort,
|
|
26
|
-
limit,
|
|
27
|
-
cursor,
|
|
28
|
-
},
|
|
26
|
+
query: { assetIds: encodedAssetIds, idShort, limit, cursor },
|
|
29
27
|
});
|
|
30
28
|
if (error) {
|
|
31
|
-
|
|
32
|
-
throw new Error(JSON.stringify(error.messages));
|
|
29
|
+
return { success: false, error };
|
|
33
30
|
}
|
|
34
31
|
const shells = (data.result ?? []).map(convertApiAasToCoreAas);
|
|
35
32
|
return {
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
success: true,
|
|
34
|
+
data: {
|
|
35
|
+
pagedResult: data.paging_metadata,
|
|
36
|
+
result: shells,
|
|
37
|
+
},
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
catch (
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
catch (err) {
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
44
|
+
};
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
|
-
* Creates a new Asset Administration Shell
|
|
48
|
+
* Creates a new Asset Administration Shell.
|
|
49
|
+
*
|
|
50
|
+
* @param options Object containing:
|
|
51
|
+
* - baseUrl: The API base URL
|
|
52
|
+
* - assetAdministrationShell: The AAS to create
|
|
53
|
+
* - headers?: Optional request headers
|
|
47
54
|
*
|
|
48
|
-
* @
|
|
49
|
-
* @function postAssetAdministrationShell
|
|
50
|
-
* @param baseURL The API base URL
|
|
51
|
-
* @param assetAdministrationShell Asset Administration Shell object
|
|
52
|
-
* @param headers Request headers
|
|
53
|
-
* @returns {Promise<AssetAdministrationShell>} Asset Administration Shell created successfully
|
|
55
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
54
56
|
*/
|
|
55
|
-
async postAssetAdministrationShell(
|
|
57
|
+
async postAssetAdministrationShell(options) {
|
|
58
|
+
const { baseUrl, assetAdministrationShell, headers } = options;
|
|
56
59
|
try {
|
|
57
|
-
const client = createCustomClient(
|
|
60
|
+
const client = createCustomClient(baseUrl, headers);
|
|
58
61
|
const { data, error } = await AasRepository.postAssetAdministrationShell({
|
|
59
62
|
client,
|
|
60
63
|
body: convertCoreAasToApiAas(assetAdministrationShell),
|
|
61
64
|
});
|
|
62
65
|
if (error) {
|
|
63
|
-
|
|
64
|
-
throw new Error(JSON.stringify(error.messages));
|
|
66
|
+
return { success: false, error };
|
|
65
67
|
}
|
|
66
|
-
return convertApiAasToCoreAas(data);
|
|
68
|
+
return { success: true, data: convertApiAasToCoreAas(data) };
|
|
67
69
|
}
|
|
68
|
-
catch (
|
|
69
|
-
|
|
70
|
-
throw error;
|
|
70
|
+
catch (err) {
|
|
71
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
/**
|
|
74
|
-
* Deletes an Asset Administration Shell
|
|
75
|
+
* Deletes an Asset Administration Shell by its unique identifier.
|
|
75
76
|
*
|
|
76
|
-
* @
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* @returns {
|
|
77
|
+
* @param options Object containing:
|
|
78
|
+
* - baseUrl: The API base URL
|
|
79
|
+
* - aasIdentifier: The unique ID for the AAS
|
|
80
|
+
* - headers?: Optional request headers
|
|
81
|
+
*
|
|
82
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
82
83
|
*/
|
|
83
|
-
async deleteAssetAdministrationShellById(
|
|
84
|
+
async deleteAssetAdministrationShellById(options) {
|
|
85
|
+
const { baseUrl, aasIdentifier, headers } = options;
|
|
84
86
|
try {
|
|
85
|
-
const client = createCustomClient(
|
|
86
|
-
const
|
|
87
|
+
const client = createCustomClient(baseUrl, headers);
|
|
88
|
+
const encodedAasIdentifier = base64Encode(aasIdentifier);
|
|
89
|
+
const { data, error } = await AasRepository.deleteAssetAdministrationShellById({
|
|
87
90
|
client,
|
|
88
|
-
path: { aasIdentifier },
|
|
91
|
+
path: { aasIdentifier: encodedAasIdentifier },
|
|
89
92
|
});
|
|
90
93
|
if (error) {
|
|
91
|
-
|
|
92
|
-
throw new Error(JSON.stringify(error.messages));
|
|
94
|
+
return { success: false, error };
|
|
93
95
|
}
|
|
94
|
-
return;
|
|
96
|
+
return { success: true, data };
|
|
95
97
|
}
|
|
96
|
-
catch (
|
|
97
|
-
|
|
98
|
-
throw error;
|
|
98
|
+
catch (err) {
|
|
99
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
/**
|
|
102
|
-
* Returns a specific Asset Administration Shell
|
|
103
|
+
* Returns a specific Asset Administration Shell by its unique identifier.
|
|
104
|
+
*
|
|
105
|
+
* @param options Object containing:
|
|
106
|
+
* - baseUrl: The API base URL
|
|
107
|
+
* - aasIdentifier: The unique ID
|
|
108
|
+
* - headers?: Optional request headers
|
|
103
109
|
*
|
|
104
|
-
* @
|
|
105
|
-
* @function getAssetAdministrationShellById
|
|
106
|
-
* @param baseURL The API base URL
|
|
107
|
-
* @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
|
|
108
|
-
* @param headers Request headers
|
|
109
|
-
* @returns {Promise<AssetAdministrationShell>} Requested Asset Administration Shell
|
|
110
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
110
111
|
*/
|
|
111
|
-
async getAssetAdministrationShellById(
|
|
112
|
+
async getAssetAdministrationShellById(options) {
|
|
113
|
+
const { baseUrl, aasIdentifier, headers } = options;
|
|
112
114
|
try {
|
|
113
|
-
const client = createCustomClient(
|
|
115
|
+
const client = createCustomClient(baseUrl, headers);
|
|
116
|
+
const encodedAasIdentifier = base64Encode(aasIdentifier);
|
|
114
117
|
const { data, error } = await AasRepository.getAssetAdministrationShellById({
|
|
115
118
|
client,
|
|
116
|
-
path: { aasIdentifier },
|
|
119
|
+
path: { aasIdentifier: encodedAasIdentifier },
|
|
117
120
|
});
|
|
118
121
|
if (error) {
|
|
119
|
-
|
|
120
|
-
throw new Error(JSON.stringify(error.messages));
|
|
122
|
+
return { success: false, error };
|
|
121
123
|
}
|
|
122
|
-
return convertApiAasToCoreAas(data);
|
|
124
|
+
return { success: true, data: convertApiAasToCoreAas(data) };
|
|
123
125
|
}
|
|
124
|
-
catch (
|
|
125
|
-
|
|
126
|
-
throw error;
|
|
126
|
+
catch (err) {
|
|
127
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
/**
|
|
130
|
-
* Updates an existing Asset Administration Shell
|
|
131
|
+
* Updates an existing Asset Administration Shell by ID (PUT).
|
|
132
|
+
*
|
|
133
|
+
* @param options Object containing:
|
|
134
|
+
* - baseUrl: The API base URL
|
|
135
|
+
* - aasIdentifier: The unique ID
|
|
136
|
+
* - assetAdministrationShell: The updated AAS object
|
|
137
|
+
* - headers?: Optional request headers
|
|
131
138
|
*
|
|
132
|
-
* @
|
|
133
|
-
* @function putAssetAdministrationShellById
|
|
134
|
-
* @param baseURL The API base URL
|
|
135
|
-
* @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
|
|
136
|
-
* @param assetAdministrationShell Asset Administration Shell object
|
|
137
|
-
* @param headers Request headers
|
|
138
|
-
* @returns {Promise<void>} Asset Administration Shell updated successfully
|
|
139
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
139
140
|
*/
|
|
140
|
-
async putAssetAdministrationShellById(
|
|
141
|
+
async putAssetAdministrationShellById(options) {
|
|
142
|
+
const { baseUrl, aasIdentifier, assetAdministrationShell, headers } = options;
|
|
141
143
|
try {
|
|
142
|
-
const client = createCustomClient(
|
|
143
|
-
const
|
|
144
|
+
const client = createCustomClient(baseUrl, headers);
|
|
145
|
+
const encodedAasIdentifier = base64Encode(aasIdentifier);
|
|
146
|
+
const { data, error } = await AasRepository.putAssetAdministrationShellById({
|
|
144
147
|
client,
|
|
145
|
-
path: { aasIdentifier },
|
|
148
|
+
path: { aasIdentifier: encodedAasIdentifier },
|
|
146
149
|
body: convertCoreAasToApiAas(assetAdministrationShell),
|
|
147
150
|
});
|
|
148
151
|
if (error) {
|
|
149
|
-
|
|
150
|
-
throw new Error(JSON.stringify(error.messages));
|
|
152
|
+
return { success: false, error };
|
|
151
153
|
}
|
|
152
|
-
return;
|
|
154
|
+
return { success: true, data };
|
|
153
155
|
}
|
|
154
|
-
catch (
|
|
155
|
-
|
|
156
|
-
throw error;
|
|
156
|
+
catch (err) {
|
|
157
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
/**
|
|
160
|
-
* Returns the
|
|
161
|
+
* Returns the AssetInformation for the given AAS.
|
|
161
162
|
*
|
|
162
|
-
* @
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* @returns {
|
|
163
|
+
* @param options Object containing:
|
|
164
|
+
* - baseUrl: The API base URL
|
|
165
|
+
* - aasIdentifier: The unique ID
|
|
166
|
+
* - headers?: Optional request headers
|
|
167
|
+
*
|
|
168
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
168
169
|
*/
|
|
169
|
-
async getAssetInformation(
|
|
170
|
+
async getAssetInformation(options) {
|
|
171
|
+
const { baseUrl, aasIdentifier, headers } = options;
|
|
170
172
|
try {
|
|
171
|
-
const client = createCustomClient(
|
|
173
|
+
const client = createCustomClient(baseUrl, headers);
|
|
174
|
+
const encodedAasIdentifier = base64Encode(aasIdentifier);
|
|
172
175
|
const { data, error } = await AasRepository.getAssetInformationAasRepository({
|
|
173
176
|
client,
|
|
174
|
-
path: { aasIdentifier },
|
|
177
|
+
path: { aasIdentifier: encodedAasIdentifier },
|
|
175
178
|
});
|
|
176
179
|
if (error) {
|
|
177
|
-
|
|
178
|
-
throw new Error(JSON.stringify(error.messages));
|
|
180
|
+
return { success: false, error };
|
|
179
181
|
}
|
|
180
|
-
return
|
|
182
|
+
return {
|
|
183
|
+
success: true,
|
|
184
|
+
data: convertApiAssetInformationToCoreAssetInformation(data),
|
|
185
|
+
};
|
|
181
186
|
}
|
|
182
|
-
catch (
|
|
183
|
-
|
|
184
|
-
throw error;
|
|
187
|
+
catch (err) {
|
|
188
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
185
189
|
}
|
|
186
190
|
}
|
|
187
191
|
/**
|
|
188
|
-
* Updates the
|
|
192
|
+
* Updates the AssetInformation for the given AAS.
|
|
189
193
|
*
|
|
190
|
-
* @
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* @returns {
|
|
194
|
+
* @param options Object containing:
|
|
195
|
+
* - baseUrl: The API base URL
|
|
196
|
+
* - aasIdentifier: The unique ID
|
|
197
|
+
* - assetInformation: The updated AssetInformation object
|
|
198
|
+
* - headers?: Optional request headers
|
|
199
|
+
*
|
|
200
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
197
201
|
*/
|
|
198
|
-
async putAssetInformation(
|
|
202
|
+
async putAssetInformation(options) {
|
|
203
|
+
const { baseUrl, aasIdentifier, assetInformation, headers } = options;
|
|
199
204
|
try {
|
|
200
|
-
const client = createCustomClient(
|
|
201
|
-
const
|
|
205
|
+
const client = createCustomClient(baseUrl, headers);
|
|
206
|
+
const encodedAasIdentifier = base64Encode(aasIdentifier);
|
|
207
|
+
const { data, error } = await AasRepository.putAssetInformationAasRepository({
|
|
202
208
|
client,
|
|
203
|
-
path: { aasIdentifier },
|
|
209
|
+
path: { aasIdentifier: encodedAasIdentifier },
|
|
204
210
|
body: convertCoreAssetInformationToApiAssetInformation(assetInformation),
|
|
205
211
|
});
|
|
206
212
|
if (error) {
|
|
207
|
-
|
|
208
|
-
throw new Error(JSON.stringify(error.messages));
|
|
213
|
+
return { success: false, error };
|
|
209
214
|
}
|
|
210
|
-
return;
|
|
215
|
+
return { success: true, data };
|
|
211
216
|
}
|
|
212
|
-
catch (
|
|
213
|
-
|
|
214
|
-
throw error;
|
|
217
|
+
catch (err) {
|
|
218
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
221
|
/**
|
|
218
|
-
* Deletes the Thumbnail
|
|
222
|
+
* Deletes the Thumbnail associated with the given AAS.
|
|
223
|
+
*
|
|
224
|
+
* @param options Object containing:
|
|
225
|
+
* - baseUrl: The API base URL
|
|
226
|
+
* - aasIdentifier: The unique ID
|
|
227
|
+
* - headers?: Optional request headers
|
|
219
228
|
*
|
|
220
|
-
* @
|
|
221
|
-
* @function deleteThumbnail
|
|
222
|
-
* @param baseURL The API base URL
|
|
223
|
-
* @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
|
|
224
|
-
* @param headers Request headers
|
|
225
|
-
* @returns {Promise<void>} Thumbnail deletion successful
|
|
229
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
226
230
|
*/
|
|
227
|
-
async deleteThumbnail(
|
|
231
|
+
async deleteThumbnail(options) {
|
|
232
|
+
const { baseUrl, aasIdentifier, headers } = options;
|
|
228
233
|
try {
|
|
229
|
-
const client = createCustomClient(
|
|
230
|
-
const
|
|
234
|
+
const client = createCustomClient(baseUrl, headers);
|
|
235
|
+
const encodedAasIdentifier = base64Encode(aasIdentifier);
|
|
236
|
+
const { data, error } = await AasRepository.deleteThumbnailAasRepository({
|
|
231
237
|
client,
|
|
232
|
-
path: { aasIdentifier },
|
|
238
|
+
path: { aasIdentifier: encodedAasIdentifier },
|
|
233
239
|
});
|
|
234
240
|
if (error) {
|
|
235
|
-
|
|
236
|
-
throw new Error(JSON.stringify(error.messages));
|
|
241
|
+
return { success: false, error };
|
|
237
242
|
}
|
|
238
|
-
return
|
|
243
|
+
return {
|
|
244
|
+
success: true,
|
|
245
|
+
data: data,
|
|
246
|
+
};
|
|
239
247
|
}
|
|
240
|
-
catch (
|
|
241
|
-
|
|
242
|
-
throw error;
|
|
248
|
+
catch (err) {
|
|
249
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
243
250
|
}
|
|
244
251
|
}
|
|
245
252
|
/**
|
|
246
|
-
* Returns the Thumbnail
|
|
253
|
+
* Returns the Thumbnail associated with an AAS, if any.
|
|
254
|
+
*
|
|
255
|
+
* @param options Object containing:
|
|
256
|
+
* - baseUrl: The API base URL
|
|
257
|
+
* - aasIdentifier: The unique ID
|
|
258
|
+
* - headers?: Optional request headers
|
|
247
259
|
*
|
|
248
|
-
* @
|
|
249
|
-
* @function getThumbnail
|
|
250
|
-
* @param baseURL The API base URL
|
|
251
|
-
* @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
|
|
252
|
-
* @param headers Request headers
|
|
253
|
-
* @returns {Promise<Blob | File>} The thumbnail of the Asset Information.
|
|
260
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
254
261
|
*/
|
|
255
|
-
async getThumbnail(
|
|
262
|
+
async getThumbnail(options) {
|
|
263
|
+
const { baseUrl, aasIdentifier, headers } = options;
|
|
256
264
|
try {
|
|
257
|
-
const client = createCustomClient(
|
|
265
|
+
const client = createCustomClient(baseUrl, headers);
|
|
266
|
+
const encodedAasIdentifier = base64Encode(aasIdentifier);
|
|
258
267
|
const { data, error } = await AasRepository.getThumbnailAasRepository({
|
|
259
268
|
client,
|
|
260
|
-
path: { aasIdentifier },
|
|
269
|
+
path: { aasIdentifier: encodedAasIdentifier },
|
|
261
270
|
});
|
|
262
271
|
if (error) {
|
|
263
|
-
|
|
264
|
-
throw new Error(JSON.stringify(error.messages));
|
|
272
|
+
return { success: false, error };
|
|
265
273
|
}
|
|
266
|
-
return data;
|
|
274
|
+
return { success: true, data };
|
|
267
275
|
}
|
|
268
|
-
catch (
|
|
269
|
-
|
|
270
|
-
throw error;
|
|
276
|
+
catch (err) {
|
|
277
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
271
278
|
}
|
|
272
279
|
}
|
|
273
280
|
/**
|
|
274
|
-
* Updates the Thumbnail
|
|
281
|
+
* Updates (or creates) the Thumbnail for the given AAS.
|
|
282
|
+
*
|
|
283
|
+
* @param options Object containing:
|
|
284
|
+
* - baseUrl: The API base URL
|
|
285
|
+
* - aasIdentifier: The unique ID
|
|
286
|
+
* - thumbnail: The thumbnail data to upload
|
|
287
|
+
* - headers?: Optional request headers
|
|
275
288
|
*
|
|
276
|
-
* @
|
|
277
|
-
* @function putThumbnail
|
|
278
|
-
* @param baseURL The API base URL
|
|
279
|
-
* @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
|
|
280
|
-
* @param thumbnail Thumbnail to upload
|
|
281
|
-
* @param headers Request headers
|
|
282
|
-
* @returns {Promise<void>} Thumbnail updated successfully
|
|
289
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
283
290
|
*/
|
|
284
|
-
async putThumbnail(
|
|
291
|
+
async putThumbnail(options) {
|
|
292
|
+
const { baseUrl, aasIdentifier, thumbnail, headers } = options;
|
|
285
293
|
try {
|
|
286
|
-
const client = createCustomClient(
|
|
287
|
-
const
|
|
294
|
+
const client = createCustomClient(baseUrl, headers);
|
|
295
|
+
const encodedAasIdentifier = base64Encode(aasIdentifier);
|
|
296
|
+
const { data, error } = await AasRepository.putThumbnailAasRepository({
|
|
288
297
|
client,
|
|
289
|
-
path: { aasIdentifier },
|
|
298
|
+
path: { aasIdentifier: encodedAasIdentifier },
|
|
290
299
|
body: thumbnail,
|
|
291
300
|
});
|
|
292
301
|
if (error) {
|
|
293
|
-
|
|
294
|
-
throw new Error(JSON.stringify(error.messages));
|
|
302
|
+
return { success: false, error };
|
|
295
303
|
}
|
|
296
|
-
return;
|
|
304
|
+
return { success: true, data };
|
|
297
305
|
}
|
|
298
|
-
catch (
|
|
299
|
-
|
|
300
|
-
throw error;
|
|
306
|
+
catch (err) {
|
|
307
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
301
308
|
}
|
|
302
309
|
}
|
|
303
310
|
/**
|
|
304
|
-
* Returns all submodel references
|
|
311
|
+
* Returns all submodel references for the given AAS.
|
|
305
312
|
*
|
|
306
|
-
* @
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
* @returns {
|
|
313
|
+
* @param options Object containing:
|
|
314
|
+
* - baseUrl: The API base URL
|
|
315
|
+
* - aasIdentifier: The unique ID
|
|
316
|
+
* - headers?: Optional request headers
|
|
317
|
+
* - limit?: Max number of elements
|
|
318
|
+
* - cursor?: Paging cursor
|
|
319
|
+
*
|
|
320
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
314
321
|
*/
|
|
315
|
-
async getAllSubmodelReferences(
|
|
322
|
+
async getAllSubmodelReferences(options) {
|
|
323
|
+
const { baseUrl, aasIdentifier, headers, limit, cursor } = options;
|
|
316
324
|
try {
|
|
317
|
-
const client = createCustomClient(
|
|
325
|
+
const client = createCustomClient(baseUrl, headers);
|
|
326
|
+
const encodedAasIdentifier = base64Encode(aasIdentifier);
|
|
318
327
|
const { data, error } = await AasRepository.getAllSubmodelReferencesAasRepository({
|
|
319
328
|
client,
|
|
320
|
-
path: { aasIdentifier },
|
|
321
|
-
query: {
|
|
322
|
-
limit,
|
|
323
|
-
cursor,
|
|
324
|
-
},
|
|
329
|
+
path: { aasIdentifier: encodedAasIdentifier },
|
|
330
|
+
query: { limit, cursor },
|
|
325
331
|
});
|
|
326
332
|
if (error) {
|
|
327
|
-
|
|
328
|
-
throw new Error(JSON.stringify(error.messages));
|
|
333
|
+
return { success: false, error };
|
|
329
334
|
}
|
|
330
335
|
const submodelReferences = (data.result ?? []).map(convertApiReferenceToCoreReference);
|
|
331
336
|
return {
|
|
332
|
-
|
|
333
|
-
|
|
337
|
+
success: true,
|
|
338
|
+
data: {
|
|
339
|
+
pagedResult: data.paging_metadata,
|
|
340
|
+
result: submodelReferences,
|
|
341
|
+
},
|
|
334
342
|
};
|
|
335
343
|
}
|
|
336
|
-
catch (
|
|
337
|
-
|
|
338
|
-
throw error;
|
|
344
|
+
catch (err) {
|
|
345
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
339
346
|
}
|
|
340
347
|
}
|
|
341
348
|
/**
|
|
342
|
-
* Creates a submodel reference at the
|
|
349
|
+
* Creates a submodel reference at the given AAS.
|
|
343
350
|
*
|
|
344
|
-
* @
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
* @returns {
|
|
351
|
+
* @param options Object containing:
|
|
352
|
+
* - baseUrl: The API base URL
|
|
353
|
+
* - aasIdentifier: The unique ID of the AAS
|
|
354
|
+
* - submodelReference: The Reference to the submodel
|
|
355
|
+
* - headers?: Optional request headers
|
|
356
|
+
*
|
|
357
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
351
358
|
*/
|
|
352
|
-
async postSubmodelReference(
|
|
359
|
+
async postSubmodelReference(options) {
|
|
360
|
+
const { baseUrl, aasIdentifier, submodelReference, headers } = options;
|
|
353
361
|
try {
|
|
354
|
-
const client = createCustomClient(
|
|
362
|
+
const client = createCustomClient(baseUrl, headers);
|
|
363
|
+
const encodedAasIdentifier = base64Encode(aasIdentifier);
|
|
355
364
|
const { data, error } = await AasRepository.postSubmodelReferenceAasRepository({
|
|
356
365
|
client,
|
|
357
|
-
path: { aasIdentifier },
|
|
366
|
+
path: { aasIdentifier: encodedAasIdentifier },
|
|
358
367
|
body: convertCoreReferenceToApiReference(submodelReference),
|
|
359
368
|
});
|
|
360
369
|
if (error) {
|
|
361
|
-
|
|
362
|
-
throw new Error(JSON.stringify(error.messages));
|
|
370
|
+
return { success: false, error };
|
|
363
371
|
}
|
|
364
|
-
return convertApiReferenceToCoreReference(data);
|
|
372
|
+
return { success: true, data: convertApiReferenceToCoreReference(data) };
|
|
365
373
|
}
|
|
366
|
-
catch (
|
|
367
|
-
|
|
368
|
-
throw error;
|
|
374
|
+
catch (err) {
|
|
375
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
369
376
|
}
|
|
370
377
|
}
|
|
371
378
|
/**
|
|
372
|
-
* Deletes
|
|
379
|
+
* Deletes a submodel reference from the given AAS (does not delete the submodel itself).
|
|
380
|
+
*
|
|
381
|
+
* @param options Object containing:
|
|
382
|
+
* - baseUrl: The API base URL
|
|
383
|
+
* - aasIdentifier: Unique ID of the AAS
|
|
384
|
+
* - submodelIdentifier: The submodel's unique ID
|
|
385
|
+
* - headers?: Optional request headers
|
|
373
386
|
*
|
|
374
|
-
* @
|
|
375
|
-
* @function deleteSubmodelReferenceById
|
|
376
|
-
* @param baseURL The API base URL
|
|
377
|
-
* @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
|
|
378
|
-
* @param submodelIdentifier The Submodel’s unique id (UTF8-BASE64-URL-encoded)
|
|
379
|
-
* @param headers Request headers
|
|
380
|
-
* @returns {Promise<void>} Submodel reference deleted successfully
|
|
387
|
+
* @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
|
|
381
388
|
*/
|
|
382
|
-
async deleteSubmodelReferenceById(
|
|
389
|
+
async deleteSubmodelReferenceById(options) {
|
|
390
|
+
const { baseUrl, aasIdentifier, submodelIdentifier, headers } = options;
|
|
383
391
|
try {
|
|
384
|
-
const client = createCustomClient(
|
|
385
|
-
const
|
|
392
|
+
const client = createCustomClient(baseUrl, headers);
|
|
393
|
+
const encodedAasIdentifier = base64Encode(aasIdentifier);
|
|
394
|
+
const encodedSubmodelIdentifier = base64Encode(submodelIdentifier);
|
|
395
|
+
const { data, error } = await AasRepository.deleteSubmodelReferenceByIdAasRepository({
|
|
386
396
|
client,
|
|
387
|
-
path: {
|
|
397
|
+
path: {
|
|
398
|
+
aasIdentifier: encodedAasIdentifier,
|
|
399
|
+
submodelIdentifier: encodedSubmodelIdentifier,
|
|
400
|
+
},
|
|
388
401
|
});
|
|
389
402
|
if (error) {
|
|
390
|
-
|
|
391
|
-
throw new Error(JSON.stringify(error.messages));
|
|
403
|
+
return { success: false, error };
|
|
392
404
|
}
|
|
393
|
-
return;
|
|
405
|
+
return { success: true, data };
|
|
394
406
|
}
|
|
395
|
-
catch (
|
|
396
|
-
|
|
397
|
-
throw error;
|
|
407
|
+
catch (err) {
|
|
408
|
+
return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
|
|
398
409
|
}
|
|
399
410
|
}
|
|
400
411
|
}
|
package/dist/index.d.ts
CHANGED