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