basyx-typescript-sdk 1.0.2 → 1.1.0
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 +430 -13
- package/bundle/index.cjs +2421 -238
- package/bundle/index.cjs.map +1 -1
- package/bundle/index.mjs +2344 -225
- package/bundle/index.mjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +28 -1
- package/dist/lib/aas-dataformat-xml/index.d.ts +1 -0
- package/dist/lib/aas-dataformat-xml/index.js +1 -0
- package/dist/lib/aas-dataformat-xml/xmlization.d.ts +3 -0
- package/dist/lib/aas-dataformat-xml/xmlization.js +1332 -0
- package/dist/lib/base64Url.js +11 -2
- package/dist/lib/descriptorJsonization.js +20 -1
- package/dist/lib/index.d.ts +9 -0
- package/dist/lib/index.js +12 -0
- package/dist/models/BaSyxEnvironment.d.ts +3 -0
- package/dist/models/BaSyxEnvironment.js +3 -0
- package/dist/services/AasService.d.ts +240 -0
- package/dist/services/AasService.js +726 -0
- package/dist/services/SubmodelService.d.ts +192 -0
- package/dist/services/SubmodelService.js +574 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +2 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.js +14 -0
- package/package.json +12 -3
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
import { ModelType } from '@aas-core-works/aas-core3.0-typescript/types';
|
|
2
|
+
import { ConceptDescriptionRepositoryClient } from '../clients/ConceptDescriptionRepositoryClient';
|
|
3
|
+
import { SubmodelRegistryClient } from '../clients/SubmodelRegistryClient';
|
|
4
|
+
import { SubmodelRepositoryClient } from '../clients/SubmodelRepositoryClient';
|
|
5
|
+
import { Configuration } from '../generated/runtime';
|
|
6
|
+
import { base64Decode, base64Encode } from '../lib/base64Url';
|
|
7
|
+
import { SubmodelDescriptor } from '../models/Descriptors';
|
|
8
|
+
/**
|
|
9
|
+
* SubmodelService combines Submodel Registry, Submodel Repository, and Concept Description Repository clients
|
|
10
|
+
* to provide higher-level functionality for working with Submodels.
|
|
11
|
+
*
|
|
12
|
+
* This service demonstrates the multi-client pattern by orchestrating
|
|
13
|
+
* operations across different BaSyx components, including the Submodel Registry,
|
|
14
|
+
* Submodel Repository, and Concept Description Repository.
|
|
15
|
+
*/
|
|
16
|
+
export class SubmodelService {
|
|
17
|
+
registryClient;
|
|
18
|
+
repositoryClient;
|
|
19
|
+
conceptDescriptionClient;
|
|
20
|
+
registryConfig;
|
|
21
|
+
repositoryConfig;
|
|
22
|
+
conceptDescriptionRepositoryConfig;
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.registryClient = new SubmodelRegistryClient();
|
|
25
|
+
this.repositoryClient = new SubmodelRepositoryClient();
|
|
26
|
+
this.conceptDescriptionClient = new ConceptDescriptionRepositoryClient();
|
|
27
|
+
this.registryConfig = config.registryConfig;
|
|
28
|
+
this.repositoryConfig = config.repositoryConfig;
|
|
29
|
+
this.conceptDescriptionRepositoryConfig = config.conceptDescriptionRepositoryConfig;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves a list of all Submodels.
|
|
33
|
+
*
|
|
34
|
+
* This method first attempts to fetch Submodel Descriptors from the Registry,
|
|
35
|
+
* then uses the descriptor endpoints to fetch the actual submodels.
|
|
36
|
+
* If a registry is not configured or fails, it falls back to fetching
|
|
37
|
+
* Submodels directly from the Repository.
|
|
38
|
+
*
|
|
39
|
+
* @param options Object containing:
|
|
40
|
+
* - preferRegistry?: Whether to prefer registry over repository (default: true)
|
|
41
|
+
* - limit?: Maximum number of elements to retrieve
|
|
42
|
+
* - cursor?: Pagination cursor
|
|
43
|
+
* - includeConceptDescriptions?: Whether to fetch concept descriptions (default: false)
|
|
44
|
+
*
|
|
45
|
+
* @returns Either `{ success: true; data: { submodels, source, conceptDescriptions? } }` or `{ success: false; error: ... }`.
|
|
46
|
+
*/
|
|
47
|
+
async getSubmodelList(options) {
|
|
48
|
+
const preferRegistry = options?.preferRegistry ?? true;
|
|
49
|
+
const includeConceptDescriptions = options?.includeConceptDescriptions ?? false;
|
|
50
|
+
// Try registry first if configured and preferred
|
|
51
|
+
if (preferRegistry && this.registryConfig) {
|
|
52
|
+
const registryResult = await this.registryClient.getAllSubmodelDescriptors({
|
|
53
|
+
configuration: this.registryConfig,
|
|
54
|
+
limit: options?.limit,
|
|
55
|
+
cursor: options?.cursor,
|
|
56
|
+
});
|
|
57
|
+
if (registryResult.success) {
|
|
58
|
+
const descriptors = registryResult.data.result;
|
|
59
|
+
// Fetch submodels from their endpoints
|
|
60
|
+
const submodelPromises = descriptors.map(async (descriptor) => {
|
|
61
|
+
const endpoint = descriptor.endpoints?.[0]?.protocolInformation?.href;
|
|
62
|
+
if (!endpoint) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const submodelResult = await this.getSubmodelByEndpoint({ endpoint });
|
|
66
|
+
return submodelResult.success ? submodelResult.data.submodel : null;
|
|
67
|
+
});
|
|
68
|
+
const submodels = (await Promise.all(submodelPromises)).filter((sm) => sm !== null);
|
|
69
|
+
// Fetch concept descriptions if requested
|
|
70
|
+
let conceptDescriptions;
|
|
71
|
+
if (includeConceptDescriptions) {
|
|
72
|
+
conceptDescriptions = await this.fetchConceptDescriptionsForSubmodels(submodels);
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
success: true,
|
|
76
|
+
data: {
|
|
77
|
+
submodels,
|
|
78
|
+
source: 'registry',
|
|
79
|
+
...(conceptDescriptions && { conceptDescriptions }),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Fall back to repository if registry failed or not configured
|
|
85
|
+
if (this.repositoryConfig) {
|
|
86
|
+
const repositoryResult = await this.repositoryClient.getAllSubmodels({
|
|
87
|
+
configuration: this.repositoryConfig,
|
|
88
|
+
limit: options?.limit,
|
|
89
|
+
cursor: options?.cursor,
|
|
90
|
+
});
|
|
91
|
+
if (repositoryResult.success) {
|
|
92
|
+
const submodels = repositoryResult.data.result;
|
|
93
|
+
// Fetch concept descriptions if requested
|
|
94
|
+
let conceptDescriptions;
|
|
95
|
+
if (includeConceptDescriptions) {
|
|
96
|
+
conceptDescriptions = await this.fetchConceptDescriptionsForSubmodels(submodels);
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
success: true,
|
|
100
|
+
data: {
|
|
101
|
+
submodels,
|
|
102
|
+
source: 'repository',
|
|
103
|
+
...(conceptDescriptions && { conceptDescriptions }),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return { success: false, error: repositoryResult.error };
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
error: {
|
|
112
|
+
errorType: 'ConfigurationError',
|
|
113
|
+
message: 'Neither registry nor repository configuration provided',
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Retrieves a Submodel by ID.
|
|
119
|
+
*
|
|
120
|
+
* This method first attempts to fetch the descriptor from the registry
|
|
121
|
+
* and use its endpoint to fetch the submodel. If that fails, it falls back
|
|
122
|
+
* to fetching directly from the repository.
|
|
123
|
+
*
|
|
124
|
+
* @param options Object containing:
|
|
125
|
+
* - submodelIdentifier: The Submodel identifier
|
|
126
|
+
* - useRegistryEndpoint?: Whether to try registry endpoint first (default: true)
|
|
127
|
+
* - includeConceptDescriptions?: Whether to fetch concept descriptions (default: false)
|
|
128
|
+
*
|
|
129
|
+
* @returns Either `{ success: true; data: { submodel, descriptor?, conceptDescriptions? } }` or `{ success: false; error: ... }`.
|
|
130
|
+
*/
|
|
131
|
+
async getSubmodelById(options) {
|
|
132
|
+
const { submodelIdentifier, useRegistryEndpoint = true, includeConceptDescriptions = false } = options;
|
|
133
|
+
// Try registry-based flow first
|
|
134
|
+
if (useRegistryEndpoint && this.registryConfig) {
|
|
135
|
+
const descriptorResult = await this.registryClient.getSubmodelDescriptorById({
|
|
136
|
+
configuration: this.registryConfig,
|
|
137
|
+
submodelIdentifier,
|
|
138
|
+
});
|
|
139
|
+
if (descriptorResult.success) {
|
|
140
|
+
const descriptor = descriptorResult.data;
|
|
141
|
+
const endpoint = descriptor.endpoints?.[0]?.protocolInformation?.href;
|
|
142
|
+
if (endpoint) {
|
|
143
|
+
const submodelResult = await this.getSubmodelByEndpoint({
|
|
144
|
+
endpoint,
|
|
145
|
+
includeConceptDescriptions,
|
|
146
|
+
});
|
|
147
|
+
if (submodelResult.success) {
|
|
148
|
+
return {
|
|
149
|
+
success: true,
|
|
150
|
+
data: {
|
|
151
|
+
submodel: submodelResult.data.submodel,
|
|
152
|
+
descriptor,
|
|
153
|
+
...(submodelResult.data.conceptDescriptions && {
|
|
154
|
+
conceptDescriptions: submodelResult.data.conceptDescriptions,
|
|
155
|
+
}),
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// If endpoint fetch failed, fall through to repository
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Fall back to repository
|
|
164
|
+
if (!this.repositoryConfig) {
|
|
165
|
+
return {
|
|
166
|
+
success: false,
|
|
167
|
+
error: {
|
|
168
|
+
errorType: 'ConfigurationError',
|
|
169
|
+
message: 'No repository configuration available',
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const submodelResult = await this.repositoryClient.getSubmodelById({
|
|
174
|
+
configuration: this.repositoryConfig,
|
|
175
|
+
submodelIdentifier,
|
|
176
|
+
});
|
|
177
|
+
if (submodelResult.success) {
|
|
178
|
+
const submodel = submodelResult.data;
|
|
179
|
+
// Fetch concept descriptions if requested
|
|
180
|
+
let conceptDescriptions;
|
|
181
|
+
if (includeConceptDescriptions) {
|
|
182
|
+
conceptDescriptions = await this.fetchConceptDescriptionsForSubmodels([submodel]);
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
success: true,
|
|
186
|
+
data: {
|
|
187
|
+
submodel,
|
|
188
|
+
descriptor: undefined,
|
|
189
|
+
...(conceptDescriptions && { conceptDescriptions }),
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
return { success: false, error: submodelResult.error };
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Gets the endpoint URL for a Submodel by its identifier.
|
|
197
|
+
*
|
|
198
|
+
* If registry is configured and useRegistry is true, retrieves the endpoint
|
|
199
|
+
* from the descriptor's endpoint object. Otherwise, constructs the endpoint
|
|
200
|
+
* from the repository base path and the encoded Submodel identifier.
|
|
201
|
+
*
|
|
202
|
+
* @param options Object containing:
|
|
203
|
+
* - submodelIdentifier: The Submodel identifier
|
|
204
|
+
* - useRegistry?: Whether to try getting endpoint from registry (default: true)
|
|
205
|
+
*
|
|
206
|
+
* @returns Either `{ success: true; data: endpointUrl }` or `{ success: false; error: ... }`.
|
|
207
|
+
*/
|
|
208
|
+
async getSubmodelEndpointById(options) {
|
|
209
|
+
const { submodelIdentifier, useRegistry = true } = options;
|
|
210
|
+
// Try registry first if configured and requested
|
|
211
|
+
if (useRegistry && this.registryConfig) {
|
|
212
|
+
const descriptorResult = await this.registryClient.getSubmodelDescriptorById({
|
|
213
|
+
configuration: this.registryConfig,
|
|
214
|
+
submodelIdentifier,
|
|
215
|
+
});
|
|
216
|
+
if (descriptorResult.success) {
|
|
217
|
+
const endpoint = descriptorResult.data.endpoints?.[0]?.protocolInformation?.href;
|
|
218
|
+
if (endpoint) {
|
|
219
|
+
return { success: true, data: endpoint };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Fall back to constructing from repository base
|
|
224
|
+
if (!this.repositoryConfig) {
|
|
225
|
+
return {
|
|
226
|
+
success: false,
|
|
227
|
+
error: {
|
|
228
|
+
errorType: 'ConfigurationError',
|
|
229
|
+
message: 'Repository configuration required',
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
const repositoryBasePath = this.repositoryConfig.basePath || 'http://localhost:8082';
|
|
234
|
+
const encodedId = base64Encode(submodelIdentifier);
|
|
235
|
+
const endpoint = `${repositoryBasePath}/submodels/${encodedId}`;
|
|
236
|
+
return { success: true, data: endpoint };
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Retrieves a Submodel by its endpoint URL.
|
|
240
|
+
*
|
|
241
|
+
* Extracts the base URL and base64url-encoded Submodel identifier from the endpoint,
|
|
242
|
+
* decodes the identifier, and fetches the submodel from the repository.
|
|
243
|
+
*
|
|
244
|
+
* @param options Object containing:
|
|
245
|
+
* - endpoint: The endpoint URL (format: http://host/submodels/{base64EncodedId})
|
|
246
|
+
* - includeConceptDescriptions?: Whether to fetch concept descriptions (default: false)
|
|
247
|
+
*
|
|
248
|
+
* @returns Either `{ success: true; data: { submodel, conceptDescriptions? } }` or `{ success: false; error: ... }`.
|
|
249
|
+
*/
|
|
250
|
+
async getSubmodelByEndpoint(options) {
|
|
251
|
+
const { endpoint, includeConceptDescriptions = false } = options;
|
|
252
|
+
// Extract base URL and encoded ID from endpoint
|
|
253
|
+
// Expected format: http://localhost:8082/submodels/base64EncodedId
|
|
254
|
+
const match = endpoint.match(/^(https?:\/\/[^/]+(?::\d+)?)\/submodels\/([^/]+)$/);
|
|
255
|
+
if (!match) {
|
|
256
|
+
return {
|
|
257
|
+
success: false,
|
|
258
|
+
error: {
|
|
259
|
+
errorType: 'InvalidEndpoint',
|
|
260
|
+
message: 'Invalid endpoint format. Expected format: http://host/submodels/{base64EncodedId}',
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
const [, baseUrl, encodedId] = match;
|
|
265
|
+
// Decode the ID
|
|
266
|
+
const submodelIdentifier = base64Decode(encodedId);
|
|
267
|
+
// Create configuration for the endpoint
|
|
268
|
+
const config = new Configuration({ basePath: baseUrl });
|
|
269
|
+
// Fetch the submodel
|
|
270
|
+
const submodelResult = await this.repositoryClient.getSubmodelById({
|
|
271
|
+
configuration: config,
|
|
272
|
+
submodelIdentifier,
|
|
273
|
+
});
|
|
274
|
+
if (!submodelResult.success) {
|
|
275
|
+
return { success: false, error: submodelResult.error };
|
|
276
|
+
}
|
|
277
|
+
const submodel = submodelResult.data;
|
|
278
|
+
// Fetch concept descriptions if requested
|
|
279
|
+
let conceptDescriptions;
|
|
280
|
+
if (includeConceptDescriptions) {
|
|
281
|
+
conceptDescriptions = await this.fetchConceptDescriptionsForSubmodels([submodel]);
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
success: true,
|
|
285
|
+
data: {
|
|
286
|
+
submodel,
|
|
287
|
+
...(conceptDescriptions && { conceptDescriptions }),
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Creates a Submodel and optionally registers it in the registry.
|
|
293
|
+
*
|
|
294
|
+
* This method creates the Submodel in the repository first. If registry is configured
|
|
295
|
+
* and registerInRegistry is true, it automatically creates a descriptor from the submodel
|
|
296
|
+
* and registers it in the registry with the repository endpoint.
|
|
297
|
+
*
|
|
298
|
+
* @param options Object containing:
|
|
299
|
+
* - submodel: The Submodel to create
|
|
300
|
+
* - registerInRegistry?: Whether to register the descriptor in the registry (default: true)
|
|
301
|
+
*
|
|
302
|
+
* @returns Either `{ success: true; data: { submodel, descriptor? } }` or `{ success: false; error: ... }`.
|
|
303
|
+
*/
|
|
304
|
+
async createSubmodel(options) {
|
|
305
|
+
const { submodel, registerInRegistry = true } = options;
|
|
306
|
+
if (!this.repositoryConfig) {
|
|
307
|
+
return {
|
|
308
|
+
success: false,
|
|
309
|
+
error: {
|
|
310
|
+
errorType: 'ConfigurationError',
|
|
311
|
+
message: 'Repository configuration required',
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
// Create Submodel in repository
|
|
316
|
+
const submodelResult = await this.repositoryClient.postSubmodel({
|
|
317
|
+
configuration: this.repositoryConfig,
|
|
318
|
+
submodel: submodel,
|
|
319
|
+
});
|
|
320
|
+
if (!submodelResult.success) {
|
|
321
|
+
return { success: false, error: submodelResult.error };
|
|
322
|
+
}
|
|
323
|
+
// Register descriptor in registry if configured and requested
|
|
324
|
+
if (registerInRegistry && this.registryConfig) {
|
|
325
|
+
const descriptor = this.createDescriptorFromSubmodel(submodel);
|
|
326
|
+
const descriptorResult = await this.registryClient.postSubmodelDescriptor({
|
|
327
|
+
configuration: this.registryConfig,
|
|
328
|
+
submodelDescriptor: descriptor,
|
|
329
|
+
});
|
|
330
|
+
if (!descriptorResult.success) {
|
|
331
|
+
// Submodel was created but registration failed - return error
|
|
332
|
+
return { success: false, error: descriptorResult.error };
|
|
333
|
+
}
|
|
334
|
+
return {
|
|
335
|
+
success: true,
|
|
336
|
+
data: {
|
|
337
|
+
submodel: submodelResult.data,
|
|
338
|
+
descriptor: descriptorResult.data,
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
// Registry not configured or registration not requested
|
|
343
|
+
return {
|
|
344
|
+
success: true,
|
|
345
|
+
data: {
|
|
346
|
+
submodel: submodelResult.data,
|
|
347
|
+
descriptor: undefined,
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Updates a Submodel and optionally updates its descriptor in the registry.
|
|
353
|
+
*
|
|
354
|
+
* This method updates the Submodel in the repository. If registry is configured
|
|
355
|
+
* and updateInRegistry is true, it automatically creates/updates the descriptor
|
|
356
|
+
* in the registry with the updated submodel data.
|
|
357
|
+
*
|
|
358
|
+
* @param options Object containing:
|
|
359
|
+
* - submodel: The updated Submodel
|
|
360
|
+
* - updateInRegistry?: Whether to update the descriptor in the registry (default: true)
|
|
361
|
+
*
|
|
362
|
+
* @returns Either `{ success: true; data: { submodel, descriptor? } }` or `{ success: false; error: ... }`.
|
|
363
|
+
*/
|
|
364
|
+
async updateSubmodel(options) {
|
|
365
|
+
const { submodel, updateInRegistry = true } = options;
|
|
366
|
+
if (!this.repositoryConfig) {
|
|
367
|
+
return {
|
|
368
|
+
success: false,
|
|
369
|
+
error: {
|
|
370
|
+
errorType: 'ConfigurationError',
|
|
371
|
+
message: 'Repository configuration required',
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
// Update Submodel in repository
|
|
376
|
+
const submodelResult = await this.repositoryClient.putSubmodelById({
|
|
377
|
+
configuration: this.repositoryConfig,
|
|
378
|
+
submodelIdentifier: submodel.id,
|
|
379
|
+
submodel: submodel,
|
|
380
|
+
});
|
|
381
|
+
if (!submodelResult.success) {
|
|
382
|
+
return { success: false, error: submodelResult.error };
|
|
383
|
+
}
|
|
384
|
+
// Use the returned submodel if available, otherwise use the input submodel
|
|
385
|
+
const updatedSubmodel = submodelResult.data || submodel;
|
|
386
|
+
// Update descriptor in registry if configured and requested
|
|
387
|
+
if (updateInRegistry && this.registryConfig) {
|
|
388
|
+
const descriptor = this.createDescriptorFromSubmodel(submodel);
|
|
389
|
+
const descriptorResult = await this.registryClient.putSubmodelDescriptorById({
|
|
390
|
+
configuration: this.registryConfig,
|
|
391
|
+
submodelIdentifier: submodel.id,
|
|
392
|
+
submodelDescriptor: descriptor,
|
|
393
|
+
});
|
|
394
|
+
if (!descriptorResult.success) {
|
|
395
|
+
// Submodel was updated but registry update failed - return error
|
|
396
|
+
return { success: false, error: descriptorResult.error };
|
|
397
|
+
}
|
|
398
|
+
return {
|
|
399
|
+
success: true,
|
|
400
|
+
data: {
|
|
401
|
+
submodel: updatedSubmodel,
|
|
402
|
+
descriptor: descriptorResult.data || undefined,
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
// Registry not configured or update not requested
|
|
407
|
+
return {
|
|
408
|
+
success: true,
|
|
409
|
+
data: {
|
|
410
|
+
submodel: updatedSubmodel,
|
|
411
|
+
descriptor: undefined,
|
|
412
|
+
},
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Deletes a Submodel and optionally removes it from the registry.
|
|
417
|
+
*
|
|
418
|
+
* This method removes the descriptor from the registry first (if requested),
|
|
419
|
+
* then deletes the Submodel from the repository.
|
|
420
|
+
*
|
|
421
|
+
* @param options Object containing:
|
|
422
|
+
* - submodelIdentifier: The Submodel identifier to remove
|
|
423
|
+
* - deleteFromRegistry?: Whether to delete from registry (default: true)
|
|
424
|
+
*
|
|
425
|
+
* @returns Either `{ success: true; data: void }` or `{ success: false; error: ... }`.
|
|
426
|
+
*/
|
|
427
|
+
async deleteSubmodel(options) {
|
|
428
|
+
const { submodelIdentifier, deleteFromRegistry = true } = options;
|
|
429
|
+
// Remove from registry first if configured and requested
|
|
430
|
+
if (deleteFromRegistry && this.registryConfig) {
|
|
431
|
+
const registryResult = await this.registryClient.deleteSubmodelDescriptorById({
|
|
432
|
+
configuration: this.registryConfig,
|
|
433
|
+
submodelIdentifier,
|
|
434
|
+
});
|
|
435
|
+
if (!registryResult.success) {
|
|
436
|
+
return { success: false, error: registryResult.error };
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
// Remove from repository
|
|
440
|
+
if (this.repositoryConfig) {
|
|
441
|
+
const repositoryResult = await this.repositoryClient.deleteSubmodelById({
|
|
442
|
+
configuration: this.repositoryConfig,
|
|
443
|
+
submodelIdentifier,
|
|
444
|
+
});
|
|
445
|
+
if (!repositoryResult.success) {
|
|
446
|
+
return { success: false, error: repositoryResult.error };
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return { success: true, data: undefined };
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Helper method to create a Submodel descriptor from a Submodel.
|
|
453
|
+
* Populates descriptor fields from the submodel including metadata and endpoint configuration.
|
|
454
|
+
*
|
|
455
|
+
* @param submodel The Submodel to create descriptor from
|
|
456
|
+
* @returns SubmodelDescriptor with all populated fields
|
|
457
|
+
*/
|
|
458
|
+
createDescriptorFromSubmodel(submodel) {
|
|
459
|
+
// Set endpoint using repository base path
|
|
460
|
+
const repositoryBasePath = this.repositoryConfig.basePath || 'http://localhost:8082';
|
|
461
|
+
const encodedId = base64Encode(submodel.id);
|
|
462
|
+
const endpoints = [
|
|
463
|
+
{
|
|
464
|
+
_interface: 'SUBMODEL-3.0',
|
|
465
|
+
protocolInformation: {
|
|
466
|
+
href: `${repositoryBasePath}/submodels/${encodedId}`,
|
|
467
|
+
endpointProtocol: null,
|
|
468
|
+
endpointProtocolVersion: null,
|
|
469
|
+
subprotocol: null,
|
|
470
|
+
subprotocolBody: null,
|
|
471
|
+
subprotocolBodyEncoding: null,
|
|
472
|
+
securityAttributes: null,
|
|
473
|
+
},
|
|
474
|
+
},
|
|
475
|
+
];
|
|
476
|
+
const descriptor = new SubmodelDescriptor(submodel.id, endpoints, submodel.administration ?? null, submodel.idShort ?? null, submodel.semanticId ?? null, submodel.supplementalSemanticIds ?? null, submodel.displayName ?? null, submodel.description ?? null, submodel.extensions ?? null);
|
|
477
|
+
return descriptor;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Extracts all unique semantic IDs from a submodel and its elements recursively.
|
|
481
|
+
* Uses a stack-based approach to traverse the submodel element tree.
|
|
482
|
+
*
|
|
483
|
+
* @param submodel The submodel to extract semantic IDs from
|
|
484
|
+
* @returns Array of unique semantic ID strings
|
|
485
|
+
*/
|
|
486
|
+
extractSemanticIds(submodel) {
|
|
487
|
+
const semanticIds = new Set();
|
|
488
|
+
// Add submodel's own semantic ID if present
|
|
489
|
+
if (submodel.semanticId?.keys && submodel.semanticId.keys.length > 0) {
|
|
490
|
+
const semanticIdValue = submodel.semanticId.keys[0].value;
|
|
491
|
+
if (semanticIdValue) {
|
|
492
|
+
semanticIds.add(semanticIdValue);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
// Stack-based traversal of submodel elements
|
|
496
|
+
const stack = [...(submodel.submodelElements || [])];
|
|
497
|
+
while (stack.length > 0) {
|
|
498
|
+
const element = stack.pop();
|
|
499
|
+
// Add element's semantic ID if present
|
|
500
|
+
if (element.semanticId?.keys && element.semanticId.keys.length > 0) {
|
|
501
|
+
const semanticIdValue = element.semanticId.keys[0].value;
|
|
502
|
+
if (semanticIdValue) {
|
|
503
|
+
semanticIds.add(semanticIdValue);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
// Add children to stack based on element type
|
|
507
|
+
const modelType = typeof element.modelType === 'function' ? element.modelType() : element.modelType;
|
|
508
|
+
if (modelType === ModelType.SubmodelElementCollection) {
|
|
509
|
+
const collection = element;
|
|
510
|
+
if (collection.value && Array.isArray(collection.value)) {
|
|
511
|
+
stack.push(...collection.value);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
else if (modelType === ModelType.SubmodelElementList) {
|
|
515
|
+
const list = element;
|
|
516
|
+
if (list.value && Array.isArray(list.value)) {
|
|
517
|
+
stack.push(...list.value);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
else if (modelType === ModelType.Entity) {
|
|
521
|
+
const entity = element;
|
|
522
|
+
if (entity.statements && Array.isArray(entity.statements)) {
|
|
523
|
+
stack.push(...entity.statements);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
else if (modelType === ModelType.AnnotatedRelationshipElement) {
|
|
527
|
+
const annotatedRel = element;
|
|
528
|
+
if (annotatedRel.annotations && Array.isArray(annotatedRel.annotations)) {
|
|
529
|
+
stack.push(...annotatedRel.annotations);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return Array.from(semanticIds);
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Fetches concept descriptions for multiple submodels.
|
|
537
|
+
* Deduplicates semantic IDs across all submodels and fetches each concept description once.
|
|
538
|
+
* Skips concept descriptions that cannot be resolved.
|
|
539
|
+
*
|
|
540
|
+
* @param submodels Array of submodels to fetch concept descriptions for
|
|
541
|
+
* @returns Array of unique concept descriptions
|
|
542
|
+
*/
|
|
543
|
+
async fetchConceptDescriptionsForSubmodels(submodels) {
|
|
544
|
+
if (!this.conceptDescriptionRepositoryConfig) {
|
|
545
|
+
return [];
|
|
546
|
+
}
|
|
547
|
+
// Extract all semantic IDs from all submodels
|
|
548
|
+
const allSemanticIds = new Set();
|
|
549
|
+
for (const submodel of submodels) {
|
|
550
|
+
const semanticIds = this.extractSemanticIds(submodel);
|
|
551
|
+
semanticIds.forEach((id) => allSemanticIds.add(id));
|
|
552
|
+
}
|
|
553
|
+
// Fetch concept descriptions for all unique semantic IDs
|
|
554
|
+
const conceptDescriptions = [];
|
|
555
|
+
const fetchPromises = Array.from(allSemanticIds).map(async (semanticId) => {
|
|
556
|
+
try {
|
|
557
|
+
const result = await this.conceptDescriptionClient.getConceptDescriptionById({
|
|
558
|
+
configuration: this.conceptDescriptionRepositoryConfig,
|
|
559
|
+
cdIdentifier: semanticId,
|
|
560
|
+
});
|
|
561
|
+
if (result.success) {
|
|
562
|
+
return result.data;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
catch {
|
|
566
|
+
// Skip concept descriptions that cannot be resolved
|
|
567
|
+
}
|
|
568
|
+
return null;
|
|
569
|
+
});
|
|
570
|
+
const results = await Promise.all(fetchPromises);
|
|
571
|
+
conceptDescriptions.push(...results.filter((cd) => cd !== null));
|
|
572
|
+
return conceptDescriptions;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './DescriptorUtils';
|
|
2
|
+
export * from './KeyTypesUtil';
|
|
3
|
+
export * from './MultiLanguagePropertyUtils';
|
|
4
|
+
export * from './ReferableUtils';
|
|
5
|
+
export * from './ReferenceUtil';
|
|
6
|
+
export * from './SemanticIdUtils';
|
|
7
|
+
export * as DescriptorUtils from './DescriptorUtils';
|
|
8
|
+
export * as KeyTypesUtil from './KeyTypesUtil';
|
|
9
|
+
export * as MultiLanguagePropertyUtils from './MultiLanguagePropertyUtils';
|
|
10
|
+
export * as ReferableUtils from './ReferableUtils';
|
|
11
|
+
export * as ReferenceUtil from './ReferenceUtil';
|
|
12
|
+
export * as SemanticIdUtils from './SemanticIdUtils';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Re-export all utilities as named exports for direct usage
|
|
2
|
+
export * from './DescriptorUtils';
|
|
3
|
+
export * from './KeyTypesUtil';
|
|
4
|
+
export * from './MultiLanguagePropertyUtils';
|
|
5
|
+
export * from './ReferableUtils';
|
|
6
|
+
export * from './ReferenceUtil';
|
|
7
|
+
export * from './SemanticIdUtils';
|
|
8
|
+
// Also export as namespaces for organized imports
|
|
9
|
+
export * as DescriptorUtils from './DescriptorUtils';
|
|
10
|
+
export * as KeyTypesUtil from './KeyTypesUtil';
|
|
11
|
+
export * as MultiLanguagePropertyUtils from './MultiLanguagePropertyUtils';
|
|
12
|
+
export * as ReferableUtils from './ReferableUtils';
|
|
13
|
+
export * as ReferenceUtil from './ReferenceUtil';
|
|
14
|
+
export * as SemanticIdUtils from './SemanticIdUtils';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "basyx-typescript-sdk",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "BaSyx TypeScript SDK for developing applications and components for the Asset Administration Shell (AAS)",
|
|
5
5
|
"main": "bundle/index.cjs",
|
|
6
6
|
"module": "bundle/index.mjs",
|
|
@@ -15,7 +15,12 @@
|
|
|
15
15
|
"repository": "https://github.com/eclipse-basyx/basyx-typescript-sdk.git",
|
|
16
16
|
"author": "Aaron Zielstorff <aaron.zielstorff@iese.fraunhofer.de>",
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"files": [
|
|
18
|
+
"files": [
|
|
19
|
+
"bundle",
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
19
24
|
"scripts": {
|
|
20
25
|
"build": "tsc",
|
|
21
26
|
"bundle": "rollup -c",
|
|
@@ -39,7 +44,7 @@
|
|
|
39
44
|
"@openapitools/openapi-generator-cli": "^2.18.4",
|
|
40
45
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
41
46
|
"@types/jest": "^30.0.0",
|
|
42
|
-
"@types/node": "^
|
|
47
|
+
"@types/node": "^25.0.0",
|
|
43
48
|
"@typescript-eslint/eslint-plugin": "^8.21.0",
|
|
44
49
|
"@typescript-eslint/parser": "^8.20.0",
|
|
45
50
|
"eslint": "^9.18.0",
|
|
@@ -50,11 +55,15 @@
|
|
|
50
55
|
"jiti": "^2.4.2",
|
|
51
56
|
"prettier": "^3.4.2",
|
|
52
57
|
"rollup": "^4.34.6",
|
|
58
|
+
"rollup-plugin-string": "^3.0.0",
|
|
53
59
|
"ts-jest": "^29.2.5",
|
|
54
60
|
"ts-node": "^10.9.2",
|
|
55
61
|
"tsconfig-paths": "^4.2.0",
|
|
56
62
|
"typedoc": "^0.28.1",
|
|
57
63
|
"typescript": "^5.7.3",
|
|
58
64
|
"typescript-eslint": "^8.21.0"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"fast-xml-parser": "^5.3.3"
|
|
59
68
|
}
|
|
60
69
|
}
|