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.
@@ -0,0 +1,192 @@
1
+ import type { ConceptDescription, Submodel } from '@aas-core-works/aas-core3.0-typescript/types';
2
+ import type { ApiResult } from '../models/api';
3
+ import { Configuration } from '../generated/runtime';
4
+ import { SubmodelDescriptor } from '../models/Descriptors';
5
+ export interface SubmodelServiceConfig {
6
+ registryConfig?: Configuration;
7
+ repositoryConfig?: Configuration;
8
+ conceptDescriptionRepositoryConfig?: Configuration;
9
+ }
10
+ /**
11
+ * SubmodelService combines Submodel Registry, Submodel Repository, and Concept Description Repository clients
12
+ * to provide higher-level functionality for working with Submodels.
13
+ *
14
+ * This service demonstrates the multi-client pattern by orchestrating
15
+ * operations across different BaSyx components, including the Submodel Registry,
16
+ * Submodel Repository, and Concept Description Repository.
17
+ */
18
+ export declare class SubmodelService {
19
+ private registryClient;
20
+ private repositoryClient;
21
+ private conceptDescriptionClient;
22
+ private registryConfig?;
23
+ private repositoryConfig?;
24
+ private conceptDescriptionRepositoryConfig?;
25
+ constructor(config: SubmodelServiceConfig);
26
+ /**
27
+ * Retrieves a list of all Submodels.
28
+ *
29
+ * This method first attempts to fetch Submodel Descriptors from the Registry,
30
+ * then uses the descriptor endpoints to fetch the actual submodels.
31
+ * If a registry is not configured or fails, it falls back to fetching
32
+ * Submodels directly from the Repository.
33
+ *
34
+ * @param options Object containing:
35
+ * - preferRegistry?: Whether to prefer registry over repository (default: true)
36
+ * - limit?: Maximum number of elements to retrieve
37
+ * - cursor?: Pagination cursor
38
+ * - includeConceptDescriptions?: Whether to fetch concept descriptions (default: false)
39
+ *
40
+ * @returns Either `{ success: true; data: { submodels, source, conceptDescriptions? } }` or `{ success: false; error: ... }`.
41
+ */
42
+ getSubmodelList(options?: {
43
+ preferRegistry?: boolean;
44
+ limit?: number;
45
+ cursor?: string;
46
+ includeConceptDescriptions?: boolean;
47
+ }): Promise<ApiResult<{
48
+ submodels: Submodel[];
49
+ source: 'registry' | 'repository';
50
+ conceptDescriptions?: ConceptDescription[];
51
+ }, any>>;
52
+ /**
53
+ * Retrieves a Submodel by ID.
54
+ *
55
+ * This method first attempts to fetch the descriptor from the registry
56
+ * and use its endpoint to fetch the submodel. If that fails, it falls back
57
+ * to fetching directly from the repository.
58
+ *
59
+ * @param options Object containing:
60
+ * - submodelIdentifier: The Submodel identifier
61
+ * - useRegistryEndpoint?: Whether to try registry endpoint first (default: true)
62
+ * - includeConceptDescriptions?: Whether to fetch concept descriptions (default: false)
63
+ *
64
+ * @returns Either `{ success: true; data: { submodel, descriptor?, conceptDescriptions? } }` or `{ success: false; error: ... }`.
65
+ */
66
+ getSubmodelById(options: {
67
+ submodelIdentifier: string;
68
+ useRegistryEndpoint?: boolean;
69
+ includeConceptDescriptions?: boolean;
70
+ }): Promise<ApiResult<{
71
+ submodel: Submodel;
72
+ descriptor?: SubmodelDescriptor;
73
+ conceptDescriptions?: ConceptDescription[];
74
+ }, any>>;
75
+ /**
76
+ * Gets the endpoint URL for a Submodel by its identifier.
77
+ *
78
+ * If registry is configured and useRegistry is true, retrieves the endpoint
79
+ * from the descriptor's endpoint object. Otherwise, constructs the endpoint
80
+ * from the repository base path and the encoded Submodel identifier.
81
+ *
82
+ * @param options Object containing:
83
+ * - submodelIdentifier: The Submodel identifier
84
+ * - useRegistry?: Whether to try getting endpoint from registry (default: true)
85
+ *
86
+ * @returns Either `{ success: true; data: endpointUrl }` or `{ success: false; error: ... }`.
87
+ */
88
+ getSubmodelEndpointById(options: {
89
+ submodelIdentifier: string;
90
+ useRegistry?: boolean;
91
+ }): Promise<ApiResult<string, any>>;
92
+ /**
93
+ * Retrieves a Submodel by its endpoint URL.
94
+ *
95
+ * Extracts the base URL and base64url-encoded Submodel identifier from the endpoint,
96
+ * decodes the identifier, and fetches the submodel from the repository.
97
+ *
98
+ * @param options Object containing:
99
+ * - endpoint: The endpoint URL (format: http://host/submodels/{base64EncodedId})
100
+ * - includeConceptDescriptions?: Whether to fetch concept descriptions (default: false)
101
+ *
102
+ * @returns Either `{ success: true; data: { submodel, conceptDescriptions? } }` or `{ success: false; error: ... }`.
103
+ */
104
+ getSubmodelByEndpoint(options: {
105
+ endpoint: string;
106
+ includeConceptDescriptions?: boolean;
107
+ }): Promise<ApiResult<{
108
+ submodel: Submodel;
109
+ conceptDescriptions?: ConceptDescription[];
110
+ }, any>>;
111
+ /**
112
+ * Creates a Submodel and optionally registers it in the registry.
113
+ *
114
+ * This method creates the Submodel in the repository first. If registry is configured
115
+ * and registerInRegistry is true, it automatically creates a descriptor from the submodel
116
+ * and registers it in the registry with the repository endpoint.
117
+ *
118
+ * @param options Object containing:
119
+ * - submodel: The Submodel to create
120
+ * - registerInRegistry?: Whether to register the descriptor in the registry (default: true)
121
+ *
122
+ * @returns Either `{ success: true; data: { submodel, descriptor? } }` or `{ success: false; error: ... }`.
123
+ */
124
+ createSubmodel(options: {
125
+ submodel: Submodel;
126
+ registerInRegistry?: boolean;
127
+ }): Promise<ApiResult<{
128
+ submodel: Submodel;
129
+ descriptor?: SubmodelDescriptor;
130
+ }, any>>;
131
+ /**
132
+ * Updates a Submodel and optionally updates its descriptor in the registry.
133
+ *
134
+ * This method updates the Submodel in the repository. If registry is configured
135
+ * and updateInRegistry is true, it automatically creates/updates the descriptor
136
+ * in the registry with the updated submodel data.
137
+ *
138
+ * @param options Object containing:
139
+ * - submodel: The updated Submodel
140
+ * - updateInRegistry?: Whether to update the descriptor in the registry (default: true)
141
+ *
142
+ * @returns Either `{ success: true; data: { submodel, descriptor? } }` or `{ success: false; error: ... }`.
143
+ */
144
+ updateSubmodel(options: {
145
+ submodel: Submodel;
146
+ updateInRegistry?: boolean;
147
+ }): Promise<ApiResult<{
148
+ submodel: Submodel;
149
+ descriptor?: SubmodelDescriptor;
150
+ }, any>>;
151
+ /**
152
+ * Deletes a Submodel and optionally removes it from the registry.
153
+ *
154
+ * This method removes the descriptor from the registry first (if requested),
155
+ * then deletes the Submodel from the repository.
156
+ *
157
+ * @param options Object containing:
158
+ * - submodelIdentifier: The Submodel identifier to remove
159
+ * - deleteFromRegistry?: Whether to delete from registry (default: true)
160
+ *
161
+ * @returns Either `{ success: true; data: void }` or `{ success: false; error: ... }`.
162
+ */
163
+ deleteSubmodel(options: {
164
+ submodelIdentifier: string;
165
+ deleteFromRegistry?: boolean;
166
+ }): Promise<ApiResult<void, any>>;
167
+ /**
168
+ * Helper method to create a Submodel descriptor from a Submodel.
169
+ * Populates descriptor fields from the submodel including metadata and endpoint configuration.
170
+ *
171
+ * @param submodel The Submodel to create descriptor from
172
+ * @returns SubmodelDescriptor with all populated fields
173
+ */
174
+ private createDescriptorFromSubmodel;
175
+ /**
176
+ * Extracts all unique semantic IDs from a submodel and its elements recursively.
177
+ * Uses a stack-based approach to traverse the submodel element tree.
178
+ *
179
+ * @param submodel The submodel to extract semantic IDs from
180
+ * @returns Array of unique semantic ID strings
181
+ */
182
+ private extractSemanticIds;
183
+ /**
184
+ * Fetches concept descriptions for multiple submodels.
185
+ * Deduplicates semantic IDs across all submodels and fetches each concept description once.
186
+ * Skips concept descriptions that cannot be resolved.
187
+ *
188
+ * @param submodels Array of submodels to fetch concept descriptions for
189
+ * @returns Array of unique concept descriptions
190
+ */
191
+ private fetchConceptDescriptionsForSubmodels;
192
+ }