basyx-typescript-sdk 2.2.4 → 2.3.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.
Files changed (62) hide show
  1. package/README.md +169 -0
  2. package/bundle/index.cjs +3484 -2149
  3. package/bundle/index.cjs.map +1 -1
  4. package/bundle/index.mjs +3484 -2149
  5. package/bundle/index.mjs.map +1 -1
  6. package/dist/clients/AasDiscoveryClient.d.ts +12 -5
  7. package/dist/clients/AasDiscoveryClient.js +104 -27
  8. package/dist/clients/AasRegistryClient.d.ts +32 -10
  9. package/dist/clients/AasRegistryClient.js +211 -61
  10. package/dist/clients/AasRepositoryClient.d.ts +231 -60
  11. package/dist/clients/AasRepositoryClient.js +1021 -353
  12. package/dist/clients/AasxFileClient.d.ts +29 -3
  13. package/dist/clients/AasxFileClient.js +122 -31
  14. package/dist/clients/ConceptDescriptionRepositoryClient.d.ts +14 -4
  15. package/dist/clients/ConceptDescriptionRepositoryClient.js +127 -35
  16. package/dist/clients/SubmodelRegistryClient.d.ts +14 -4
  17. package/dist/clients/SubmodelRegistryClient.js +117 -27
  18. package/dist/clients/SubmodelRepositoryClient.d.ts +339 -58
  19. package/dist/clients/SubmodelRepositoryClient.js +913 -269
  20. package/dist/generated/AasDiscoveryService/models/index.d.ts +2 -2
  21. package/dist/generated/AasRegistryService/apis/AssetAdministrationShellRegistryAPIApi.d.ts +1 -1
  22. package/dist/generated/AasRegistryService/apis/AssetAdministrationShellRegistryAPIApi.js +1 -1
  23. package/dist/generated/AasRegistryService/apis/DescriptionAPIApi.d.ts +1 -1
  24. package/dist/generated/AasRegistryService/apis/DescriptionAPIApi.js +1 -1
  25. package/dist/generated/AasRegistryService/index.d.ts +1 -1
  26. package/dist/generated/AasRegistryService/index.js +1 -1
  27. package/dist/generated/AasRegistryService/models/index.d.ts +3 -3
  28. package/dist/generated/AasRepositoryService/apis/AssetAdministrationShellRepositoryAPIApi.d.ts +3 -3
  29. package/dist/generated/AasRepositoryService/apis/AssetAdministrationShellRepositoryAPIApi.js +1 -1
  30. package/dist/generated/AasRepositoryService/apis/DescriptionAPIApi.d.ts +1 -1
  31. package/dist/generated/AasRepositoryService/apis/DescriptionAPIApi.js +1 -1
  32. package/dist/generated/AasRepositoryService/apis/SerializationAPIApi.d.ts +1 -1
  33. package/dist/generated/AasRepositoryService/apis/SerializationAPIApi.js +1 -1
  34. package/dist/generated/AasRepositoryService/index.d.ts +1 -1
  35. package/dist/generated/AasRepositoryService/index.js +1 -1
  36. package/dist/generated/AasRepositoryService/models/index.d.ts +7 -7
  37. package/dist/generated/AasxFileService/apis/AASXFileServerAPIApi.d.ts +5 -3
  38. package/dist/generated/AasxFileService/apis/AASXFileServerAPIApi.js +6 -0
  39. package/dist/generated/AasxFileService/apis/DescriptionAPIApi.d.ts +26 -0
  40. package/dist/generated/AasxFileService/apis/DescriptionAPIApi.js +40 -0
  41. package/dist/generated/AasxFileService/apis/index.d.ts +1 -0
  42. package/dist/generated/AasxFileService/apis/index.js +1 -0
  43. package/dist/generated/AasxFileService/models/index.d.ts +45 -0
  44. package/dist/generated/ConceptDescriptionRepositoryService/models/index.d.ts +2 -2
  45. package/dist/generated/SubmodelRegistryService/models/index.d.ts +2 -2
  46. package/dist/generated/SubmodelRepositoryService/models/index.d.ts +9 -9
  47. package/dist/generated/runtime.js +7 -0
  48. package/dist/lib/apiConfig.d.ts +2 -1
  49. package/dist/lib/apiConfig.js +27 -2
  50. package/dist/lib/conditionalRequests.d.ts +28 -0
  51. package/dist/lib/conditionalRequests.js +55 -0
  52. package/dist/lib/errorHandler.js +13 -2
  53. package/dist/models/api.d.ts +40 -2
  54. package/dist/services/AasService.d.ts +34 -4
  55. package/dist/services/AasService.js +159 -33
  56. package/dist/services/SubmodelService.d.ts +34 -4
  57. package/dist/services/SubmodelService.js +168 -28
  58. package/package.json +14 -3
  59. package/dist/generated/AasRegistryService/runtime.d.ts +0 -181
  60. package/dist/generated/AasRegistryService/runtime.js +0 -326
  61. package/dist/generated/AasRepositoryService/runtime.d.ts +0 -181
  62. package/dist/generated/AasRepositoryService/runtime.js +0 -326
@@ -1,31 +1,70 @@
1
1
  import { ConceptDescriptionRepositoryService } from '../generated'; // Updated import
2
+ import { RequiredError } from '../generated/runtime';
2
3
  import { applyDefaults } from '../lib/apiConfig';
3
4
  import { base64Encode } from '../lib/base64Url';
5
+ import { getConditionalErrorFields, getEtag, getNotModifiedResult } from '../lib/conditionalRequests';
4
6
  import { convertApiCDToCoreCD, convertCoreCDToApiCD } from '../lib/convertConceptDescriptionTypes';
5
7
  import { handleApiError } from '../lib/errorHandler';
6
8
  export class ConceptDescriptionRepositoryClient {
9
+ static requireIdentifier(value, field) {
10
+ if (value === null || value === undefined || value.trim() === '') {
11
+ throw new RequiredError(field, `Required parameter "${field}" was null, undefined, or empty.`);
12
+ }
13
+ return value;
14
+ }
15
+ static extractStatusCode(err, parsedError) {
16
+ const responseStatus = err?.response?.status;
17
+ if (typeof responseStatus === 'number') {
18
+ return responseStatus;
19
+ }
20
+ if (err instanceof RequiredError || err?.name === 'RequiredError') {
21
+ return 400;
22
+ }
23
+ const code = parsedError?.messages?.[0]?.code;
24
+ if (!code) {
25
+ return undefined;
26
+ }
27
+ const parsedCode = Number.parseInt(code, 10);
28
+ return Number.isNaN(parsedCode) ? undefined : parsedCode;
29
+ }
7
30
  /**
8
31
  * Returns a specific Concept Description
9
32
  *
10
33
  * @param options Object containing:
11
34
  * - configuration: The http request options
12
35
  * - cdIdentifier: The Concept Description’s unique id
36
+ * - ifNoneMatch?: Sent as `If-None-Match` header; returns `{ success: true; notModified: true }` without data if the representation still has this `etag`
13
37
  *
14
38
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
15
39
  */
16
40
  async getConceptDescriptionById(options) {
17
- const { configuration, cdIdentifier } = options;
41
+ const { configuration, cdIdentifier, ifNoneMatch } = options;
18
42
  try {
19
- const apiInstance = new ConceptDescriptionRepositoryService.ConceptDescriptionRepositoryAPIApi(applyDefaults(configuration));
20
- const encodedCdIdentifier = base64Encode(cdIdentifier);
21
- const result = await apiInstance.getConceptDescriptionById({
43
+ const apiInstance = new ConceptDescriptionRepositoryService.ConceptDescriptionRepositoryAPIApi(applyDefaults(configuration, { ifNoneMatch }));
44
+ const encodedCdIdentifier = base64Encode(ConceptDescriptionRepositoryClient.requireIdentifier(cdIdentifier, 'cdIdentifier'));
45
+ const response = await apiInstance.getConceptDescriptionByIdRaw({
22
46
  cdIdentifier: encodedCdIdentifier,
23
47
  });
24
- return { success: true, data: convertApiCDToCoreCD(result) };
48
+ const result = await response.value();
49
+ return {
50
+ success: true,
51
+ data: convertApiCDToCoreCD(result),
52
+ statusCode: response.raw.status,
53
+ etag: getEtag(response.raw),
54
+ };
25
55
  }
26
56
  catch (err) {
57
+ const notModified = getNotModifiedResult(err, ifNoneMatch);
58
+ if (notModified) {
59
+ return notModified;
60
+ }
27
61
  const customError = await handleApiError(err);
28
- return { success: false, error: customError };
62
+ return {
63
+ success: false,
64
+ error: customError,
65
+ statusCode: ConceptDescriptionRepositoryClient.extractStatusCode(err, customError),
66
+ ...getConditionalErrorFields(err),
67
+ };
29
68
  }
30
69
  }
31
70
  /**
@@ -34,22 +73,29 @@ export class ConceptDescriptionRepositoryClient {
34
73
  * @param options Object containing:
35
74
  * - configuration: The http request options
36
75
  * - cdIdentifier: The Concept Description’s unique id
76
+ * - ifMatch?: Sent as `If-Match` header; the request fails with `preconditionFailed` if the resource has changed since the `etag` was issued
37
77
  *
38
78
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
39
79
  */
40
80
  async deleteConceptDescriptionById(options) {
41
- const { configuration, cdIdentifier } = options;
81
+ const { configuration, cdIdentifier, ifMatch } = options;
42
82
  try {
43
- const apiInstance = new ConceptDescriptionRepositoryService.ConceptDescriptionRepositoryAPIApi(applyDefaults(configuration));
44
- const encodedCdIdentifier = base64Encode(cdIdentifier);
45
- const result = await apiInstance.deleteConceptDescriptionById({
83
+ const apiInstance = new ConceptDescriptionRepositoryService.ConceptDescriptionRepositoryAPIApi(applyDefaults(configuration, { ifMatch }));
84
+ const encodedCdIdentifier = base64Encode(ConceptDescriptionRepositoryClient.requireIdentifier(cdIdentifier, 'cdIdentifier'));
85
+ const response = await apiInstance.deleteConceptDescriptionByIdRaw({
46
86
  cdIdentifier: encodedCdIdentifier,
47
87
  });
48
- return { success: true, data: result };
88
+ const result = await response.value();
89
+ return { success: true, data: result, statusCode: response.raw.status, etag: getEtag(response.raw) };
49
90
  }
50
91
  catch (err) {
51
92
  const customError = await handleApiError(err);
52
- return { success: false, error: customError };
93
+ return {
94
+ success: false,
95
+ error: customError,
96
+ statusCode: ConceptDescriptionRepositoryClient.extractStatusCode(err, customError),
97
+ ...getConditionalErrorFields(err),
98
+ };
53
99
  }
54
100
  }
55
101
  /**
@@ -59,23 +105,39 @@ export class ConceptDescriptionRepositoryClient {
59
105
  * - configuration: The http request options
60
106
  * - cdIdentifier: The Concept Description’s unique id
61
107
  * - conceptDescription: Concept Description object
108
+ * - ifMatch?: Sent as `If-Match` header; the request fails with `preconditionFailed` if the resource has changed since the `etag` was issued
109
+ * - ifNoneMatch?: Sent as `If-None-Match` header; use `*` to only create the resource (fails with `preconditionFailed` if it exists)
62
110
  *
63
111
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
64
112
  */
65
113
  async putConceptDescriptionById(options) {
66
- const { configuration, cdIdentifier, conceptDescription } = options;
114
+ const { configuration, cdIdentifier, conceptDescription, ifMatch, ifNoneMatch } = options;
67
115
  try {
68
- const apiInstance = new ConceptDescriptionRepositoryService.ConceptDescriptionRepositoryAPIApi(applyDefaults(configuration));
69
- const encodedCdIdentifier = base64Encode(cdIdentifier);
70
- const result = await apiInstance.putConceptDescriptionById({
116
+ const apiInstance = new ConceptDescriptionRepositoryService.ConceptDescriptionRepositoryAPIApi(applyDefaults(configuration, { ifMatch, ifNoneMatch }));
117
+ const encodedCdIdentifier = base64Encode(ConceptDescriptionRepositoryClient.requireIdentifier(cdIdentifier, 'cdIdentifier'));
118
+ const response = await apiInstance.putConceptDescriptionByIdRaw({
71
119
  cdIdentifier: encodedCdIdentifier,
72
120
  conceptDescription: convertCoreCDToApiCD(conceptDescription),
73
121
  });
74
- return { success: true, data: result ? convertApiCDToCoreCD(result) : undefined };
122
+ if (response.raw.status === 204) {
123
+ return { success: true, data: undefined, statusCode: response.raw.status, etag: getEtag(response.raw) };
124
+ }
125
+ const result = await response.value();
126
+ return {
127
+ success: true,
128
+ data: result ? convertApiCDToCoreCD(result) : undefined,
129
+ statusCode: response.raw.status,
130
+ etag: getEtag(response.raw),
131
+ };
75
132
  }
76
133
  catch (err) {
77
134
  const customError = await handleApiError(err);
78
- return { success: false, error: customError };
135
+ return {
136
+ success: false,
137
+ error: customError,
138
+ statusCode: ConceptDescriptionRepositoryClient.extractStatusCode(err, customError),
139
+ ...getConditionalErrorFields(err),
140
+ };
79
141
  }
80
142
  }
81
143
  /**
@@ -87,7 +149,7 @@ export class ConceptDescriptionRepositoryClient {
87
149
  * - isCaseOf?: IsCaseOf reference (UTF8-BASE64-URL-encoded)
88
150
  * - dataSpecificationRef?: DataSpecification reference (UTF8-BASE64-URL-encoded)
89
151
  * - limit?: The maximum number of elements in the response array
90
- * - cursor?: A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue
152
+ * - cursor?: A server-generated identifier retrieved from paging_metadata that specifies from which position the result listing should continue
91
153
  *
92
154
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
93
155
  */
@@ -95,26 +157,33 @@ export class ConceptDescriptionRepositoryClient {
95
157
  const { configuration, idShort, isCaseOf, dataSpecificationRef, limit, cursor } = options;
96
158
  try {
97
159
  const apiInstance = new ConceptDescriptionRepositoryService.ConceptDescriptionRepositoryAPIApi(applyDefaults(configuration));
98
- const encodedIsCaseOf = isCaseOf ? base64Encode(JSON.stringify(isCaseOf)) : undefined;
99
- const encodedDataSpecificationRef = dataSpecificationRef
100
- ? base64Encode(JSON.stringify(dataSpecificationRef))
101
- : undefined;
102
- const result = await apiInstance.getAllConceptDescriptions({
160
+ const encodedIsCaseOf = isCaseOf ? base64Encode(isCaseOf) : undefined;
161
+ const encodedDataSpecificationRef = dataSpecificationRef ? base64Encode(dataSpecificationRef) : undefined;
162
+ const response = await apiInstance.getAllConceptDescriptionsRaw({
103
163
  idShort: idShort,
104
164
  isCaseOf: encodedIsCaseOf,
105
165
  dataSpecificationRef: encodedDataSpecificationRef,
106
166
  limit: limit,
107
167
  cursor: cursor,
108
168
  });
169
+ const result = await response.value();
109
170
  const conceptDescriptions = (result.result ?? []).map(convertApiCDToCoreCD);
171
+ const pagedResult = result.paging_metadata;
110
172
  return {
111
173
  success: true,
112
- data: { pagedResult: result.pagingMetadata, result: conceptDescriptions },
174
+ data: { pagedResult, result: conceptDescriptions },
175
+ statusCode: response.raw.status,
176
+ etag: getEtag(response.raw),
113
177
  };
114
178
  }
115
179
  catch (err) {
116
180
  const customError = await handleApiError(err);
117
- return { success: false, error: customError };
181
+ return {
182
+ success: false,
183
+ error: customError,
184
+ statusCode: ConceptDescriptionRepositoryClient.extractStatusCode(err, customError),
185
+ ...getConditionalErrorFields(err),
186
+ };
118
187
  }
119
188
  }
120
189
  /**
@@ -130,14 +199,25 @@ export class ConceptDescriptionRepositoryClient {
130
199
  const { configuration, conceptDescription } = options;
131
200
  try {
132
201
  const apiInstance = new ConceptDescriptionRepositoryService.ConceptDescriptionRepositoryAPIApi(applyDefaults(configuration));
133
- const result = await apiInstance.postConceptDescription({
202
+ const response = await apiInstance.postConceptDescriptionRaw({
134
203
  conceptDescription: convertCoreCDToApiCD(conceptDescription),
135
204
  });
136
- return { success: true, data: convertApiCDToCoreCD(result) };
205
+ const result = await response.value();
206
+ return {
207
+ success: true,
208
+ data: convertApiCDToCoreCD(result),
209
+ statusCode: response.raw.status,
210
+ etag: getEtag(response.raw),
211
+ };
137
212
  }
138
213
  catch (err) {
139
214
  const customError = await handleApiError(err);
140
- return { success: false, error: customError };
215
+ return {
216
+ success: false,
217
+ error: customError,
218
+ statusCode: ConceptDescriptionRepositoryClient.extractStatusCode(err, customError),
219
+ ...getConditionalErrorFields(err),
220
+ };
141
221
  }
142
222
  }
143
223
  /**
@@ -155,16 +235,22 @@ export class ConceptDescriptionRepositoryClient {
155
235
  const { configuration, aasIds, submodelIds, includeConceptDescriptions } = options;
156
236
  try {
157
237
  const apiInstance = new ConceptDescriptionRepositoryService.SerializationAPIApi(applyDefaults(configuration));
158
- const result = await apiInstance.generateSerializationByIds({
238
+ const response = await apiInstance.generateSerializationByIdsRaw({
159
239
  aasIds: aasIds,
160
240
  submodelIds: submodelIds,
161
241
  includeConceptDescriptions: includeConceptDescriptions,
162
242
  });
163
- return { success: true, data: result };
243
+ const result = await response.value();
244
+ return { success: true, data: result, statusCode: response.raw.status, etag: getEtag(response.raw) };
164
245
  }
165
246
  catch (err) {
166
247
  const customError = await handleApiError(err);
167
- return { success: false, error: customError };
248
+ return {
249
+ success: false,
250
+ error: customError,
251
+ statusCode: ConceptDescriptionRepositoryClient.extractStatusCode(err, customError),
252
+ ...getConditionalErrorFields(err),
253
+ };
168
254
  }
169
255
  }
170
256
  /**
@@ -179,12 +265,18 @@ export class ConceptDescriptionRepositoryClient {
179
265
  const { configuration } = options;
180
266
  try {
181
267
  const apiInstance = new ConceptDescriptionRepositoryService.DescriptionAPIApi(applyDefaults(configuration));
182
- const result = await apiInstance.getSelfDescription();
183
- return { success: true, data: result };
268
+ const response = await apiInstance.getSelfDescriptionRaw();
269
+ const result = await response.value();
270
+ return { success: true, data: result, statusCode: response.raw.status, etag: getEtag(response.raw) };
184
271
  }
185
272
  catch (err) {
186
273
  const customError = await handleApiError(err);
187
- return { success: false, error: customError };
274
+ return {
275
+ success: false,
276
+ error: customError,
277
+ statusCode: ConceptDescriptionRepositoryClient.extractStatusCode(err, customError),
278
+ ...getConditionalErrorFields(err),
279
+ };
188
280
  }
189
281
  }
190
282
  }
@@ -1,15 +1,17 @@
1
- import type { ApiResult } from '../models/api';
1
+ import type { ApiResult, ConditionalApiResult } from '../models/api';
2
2
  import { SubmodelRegistryService } from '../generated';
3
3
  import { Configuration } from '../generated/runtime';
4
4
  import { SubmodelDescriptor } from '../models/Descriptors';
5
5
  export declare class SubmodelRegistryClient {
6
+ private static requireIdentifier;
7
+ private static extractStatusCode;
6
8
  /**
7
9
  * Returns all Submodel Descriptors
8
10
  *
9
11
  * @param options Object containing:
10
12
  * - configuration: The http request options
11
13
  * - limit?: The maximum number of elements in the response array
12
- * - cursor?: A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue
14
+ * - cursor?: A server-generated identifier retrieved from paging_metadata that specifies from which position the result listing should continue
13
15
  *
14
16
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
15
17
  */
@@ -40,12 +42,14 @@ export declare class SubmodelRegistryClient {
40
42
  * @param options Object containing:
41
43
  * - configuration: The http request options
42
44
  * - submodelIdentifier: The Submodel’s unique id (UTF8-BASE64-URL-encoded)
45
+ * - ifMatch?: Sent as `If-Match` header; the request fails with `preconditionFailed` if the resource has changed since the `etag` was issued
43
46
  *
44
47
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
45
48
  */
46
49
  deleteSubmodelDescriptorById(options: {
47
50
  configuration: Configuration;
48
51
  submodelIdentifier: string;
52
+ ifMatch?: string;
49
53
  }): Promise<ApiResult<void, SubmodelRegistryService.Result>>;
50
54
  /**
51
55
  * Returns a specific Submodel Descriptor
@@ -53,13 +57,15 @@ export declare class SubmodelRegistryClient {
53
57
  * @param options Object containing:
54
58
  * - configuration: The http request options
55
59
  * - submodelIdentifier: The Submodel’s unique id (UTF8-BASE64-URL-encoded)
60
+ * - ifNoneMatch?: Sent as `If-None-Match` header; returns `{ success: true; notModified: true }` without data if the representation still has this `etag`
56
61
  *
57
62
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
58
63
  */
59
- getSubmodelDescriptorById(options: {
64
+ getSubmodelDescriptorById<IfNoneMatch extends string | undefined = undefined>(options: {
60
65
  configuration: Configuration;
61
66
  submodelIdentifier: string;
62
- }): Promise<ApiResult<SubmodelDescriptor, SubmodelRegistryService.Result>>;
67
+ ifNoneMatch?: IfNoneMatch;
68
+ }): Promise<ConditionalApiResult<SubmodelDescriptor, SubmodelRegistryService.Result, IfNoneMatch>>;
63
69
  /**
64
70
  * Creates or updates an existing Submodel Descriptor
65
71
  *
@@ -67,6 +73,8 @@ export declare class SubmodelRegistryClient {
67
73
  * - configuration: The http request options
68
74
  * - submodelIdentifier: The Submodel’s unique id (UTF8-BASE64-URL-encoded)
69
75
  * - submodelDescriptor: Submodel Descriptor object
76
+ * - ifMatch?: Sent as `If-Match` header; the request fails with `preconditionFailed` if the resource has changed since the `etag` was issued
77
+ * - ifNoneMatch?: Sent as `If-None-Match` header; use `*` to only create the resource (fails with `preconditionFailed` if it exists)
70
78
  *
71
79
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
72
80
  */
@@ -74,6 +82,8 @@ export declare class SubmodelRegistryClient {
74
82
  configuration: Configuration;
75
83
  submodelIdentifier: string;
76
84
  submodelDescriptor: SubmodelDescriptor;
85
+ ifMatch?: string;
86
+ ifNoneMatch?: string;
77
87
  }): Promise<ApiResult<SubmodelDescriptor | void, SubmodelRegistryService.Result>>;
78
88
  /**
79
89
  * Returns the self-describing information of a network resource (ServiceDescription)
@@ -1,16 +1,39 @@
1
1
  import { SubmodelRegistryService } from '../generated';
2
+ import { RequiredError } from '../generated/runtime';
2
3
  import { applyDefaults } from '../lib/apiConfig';
3
4
  import { base64Encode } from '../lib/base64Url';
5
+ import { getConditionalErrorFields, getEtag, getNotModifiedResult } from '../lib/conditionalRequests';
4
6
  import { convertApiSubmodelDescriptorToCoreSubmodelDescriptor, convertCoreSubmodelDescriptorToApiSubmodelDescriptor, } from '../lib/convertAasDescriptorTypes';
5
7
  import { handleApiError } from '../lib/errorHandler';
6
8
  export class SubmodelRegistryClient {
9
+ static requireIdentifier(value, field) {
10
+ if (value === null || value === undefined || value.trim() === '') {
11
+ throw new RequiredError(field, `Required parameter "${field}" was null, undefined, or empty.`);
12
+ }
13
+ return value;
14
+ }
15
+ static extractStatusCode(err, parsedError) {
16
+ const responseStatus = err?.response?.status;
17
+ if (typeof responseStatus === 'number') {
18
+ return responseStatus;
19
+ }
20
+ if (err instanceof RequiredError || err?.name === 'RequiredError') {
21
+ return 400;
22
+ }
23
+ const code = parsedError?.messages?.[0]?.code;
24
+ if (!code) {
25
+ return undefined;
26
+ }
27
+ const parsedCode = Number.parseInt(code, 10);
28
+ return Number.isNaN(parsedCode) ? undefined : parsedCode;
29
+ }
7
30
  /**
8
31
  * Returns all Submodel Descriptors
9
32
  *
10
33
  * @param options Object containing:
11
34
  * - configuration: The http request options
12
35
  * - limit?: The maximum number of elements in the response array
13
- * - cursor?: A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue
36
+ * - cursor?: A server-generated identifier retrieved from paging_metadata that specifies from which position the result listing should continue
14
37
  *
15
38
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
16
39
  */
@@ -18,19 +41,28 @@ export class SubmodelRegistryClient {
18
41
  const { configuration, limit, cursor } = options;
19
42
  try {
20
43
  const apiInstance = new SubmodelRegistryService.SubmodelRegistryAPIApi(applyDefaults(configuration));
21
- const result = await apiInstance.getAllSubmodelDescriptors({
44
+ const response = await apiInstance.getAllSubmodelDescriptorsRaw({
22
45
  limit: limit,
23
46
  cursor: cursor,
24
47
  });
48
+ const result = await response.value();
25
49
  const submodelDescriptors = (result.result ?? []).map(convertApiSubmodelDescriptorToCoreSubmodelDescriptor);
50
+ const pagedResult = result.paging_metadata;
26
51
  return {
27
52
  success: true,
28
- data: { pagedResult: result.pagingMetadata, result: submodelDescriptors },
53
+ data: { pagedResult, result: submodelDescriptors },
54
+ statusCode: response.raw.status,
55
+ etag: getEtag(response.raw),
29
56
  };
30
57
  }
31
58
  catch (err) {
32
59
  const customError = await handleApiError(err);
33
- return { success: false, error: customError };
60
+ return {
61
+ success: false,
62
+ error: customError,
63
+ statusCode: SubmodelRegistryClient.extractStatusCode(err, customError),
64
+ ...getConditionalErrorFields(err),
65
+ };
34
66
  }
35
67
  }
36
68
  /**
@@ -46,14 +78,25 @@ export class SubmodelRegistryClient {
46
78
  const { configuration, submodelDescriptor } = options;
47
79
  try {
48
80
  const apiInstance = new SubmodelRegistryService.SubmodelRegistryAPIApi(applyDefaults(configuration));
49
- const result = await apiInstance.postSubmodelDescriptor({
81
+ const response = await apiInstance.postSubmodelDescriptorRaw({
50
82
  submodelDescriptor: convertCoreSubmodelDescriptorToApiSubmodelDescriptor(submodelDescriptor),
51
83
  });
52
- return { success: true, data: convertApiSubmodelDescriptorToCoreSubmodelDescriptor(result) };
84
+ const result = await response.value();
85
+ return {
86
+ success: true,
87
+ data: convertApiSubmodelDescriptorToCoreSubmodelDescriptor(result),
88
+ statusCode: response.raw.status,
89
+ etag: getEtag(response.raw),
90
+ };
53
91
  }
54
92
  catch (err) {
55
93
  const customError = await handleApiError(err);
56
- return { success: false, error: customError };
94
+ return {
95
+ success: false,
96
+ error: customError,
97
+ statusCode: SubmodelRegistryClient.extractStatusCode(err, customError),
98
+ ...getConditionalErrorFields(err),
99
+ };
57
100
  }
58
101
  }
59
102
  /**
@@ -62,22 +105,29 @@ export class SubmodelRegistryClient {
62
105
  * @param options Object containing:
63
106
  * - configuration: The http request options
64
107
  * - submodelIdentifier: The Submodel’s unique id (UTF8-BASE64-URL-encoded)
108
+ * - ifMatch?: Sent as `If-Match` header; the request fails with `preconditionFailed` if the resource has changed since the `etag` was issued
65
109
  *
66
110
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
67
111
  */
68
112
  async deleteSubmodelDescriptorById(options) {
69
- const { configuration, submodelIdentifier } = options;
113
+ const { configuration, submodelIdentifier, ifMatch } = options;
70
114
  try {
71
- const apiInstance = new SubmodelRegistryService.SubmodelRegistryAPIApi(applyDefaults(configuration));
72
- const encodedSubmodelIdentifier = base64Encode(submodelIdentifier);
73
- const result = await apiInstance.deleteSubmodelDescriptorById({
115
+ const apiInstance = new SubmodelRegistryService.SubmodelRegistryAPIApi(applyDefaults(configuration, { ifMatch }));
116
+ const encodedSubmodelIdentifier = base64Encode(SubmodelRegistryClient.requireIdentifier(submodelIdentifier, 'submodelIdentifier'));
117
+ const response = await apiInstance.deleteSubmodelDescriptorByIdRaw({
74
118
  submodelIdentifier: encodedSubmodelIdentifier,
75
119
  });
76
- return { success: true, data: result };
120
+ const result = await response.value();
121
+ return { success: true, data: result, statusCode: response.raw.status, etag: getEtag(response.raw) };
77
122
  }
78
123
  catch (err) {
79
124
  const customError = await handleApiError(err);
80
- return { success: false, error: customError };
125
+ return {
126
+ success: false,
127
+ error: customError,
128
+ statusCode: SubmodelRegistryClient.extractStatusCode(err, customError),
129
+ ...getConditionalErrorFields(err),
130
+ };
81
131
  }
82
132
  }
83
133
  /**
@@ -86,22 +136,38 @@ export class SubmodelRegistryClient {
86
136
  * @param options Object containing:
87
137
  * - configuration: The http request options
88
138
  * - submodelIdentifier: The Submodel’s unique id (UTF8-BASE64-URL-encoded)
139
+ * - ifNoneMatch?: Sent as `If-None-Match` header; returns `{ success: true; notModified: true }` without data if the representation still has this `etag`
89
140
  *
90
141
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
91
142
  */
92
143
  async getSubmodelDescriptorById(options) {
93
- const { configuration, submodelIdentifier } = options;
144
+ const { configuration, submodelIdentifier, ifNoneMatch } = options;
94
145
  try {
95
- const apiInstance = new SubmodelRegistryService.SubmodelRegistryAPIApi(applyDefaults(configuration));
96
- const encodedSubmodelIdentifier = base64Encode(submodelIdentifier);
97
- const result = await apiInstance.getSubmodelDescriptorById({
146
+ const apiInstance = new SubmodelRegistryService.SubmodelRegistryAPIApi(applyDefaults(configuration, { ifNoneMatch }));
147
+ const encodedSubmodelIdentifier = base64Encode(SubmodelRegistryClient.requireIdentifier(submodelIdentifier, 'submodelIdentifier'));
148
+ const response = await apiInstance.getSubmodelDescriptorByIdRaw({
98
149
  submodelIdentifier: encodedSubmodelIdentifier,
99
150
  });
100
- return { success: true, data: convertApiSubmodelDescriptorToCoreSubmodelDescriptor(result) };
151
+ const result = await response.value();
152
+ return {
153
+ success: true,
154
+ data: convertApiSubmodelDescriptorToCoreSubmodelDescriptor(result),
155
+ statusCode: response.raw.status,
156
+ etag: getEtag(response.raw),
157
+ };
101
158
  }
102
159
  catch (err) {
160
+ const notModified = getNotModifiedResult(err, ifNoneMatch);
161
+ if (notModified) {
162
+ return notModified;
163
+ }
103
164
  const customError = await handleApiError(err);
104
- return { success: false, error: customError };
165
+ return {
166
+ success: false,
167
+ error: customError,
168
+ statusCode: SubmodelRegistryClient.extractStatusCode(err, customError),
169
+ ...getConditionalErrorFields(err),
170
+ };
105
171
  }
106
172
  }
107
173
  /**
@@ -111,26 +177,44 @@ export class SubmodelRegistryClient {
111
177
  * - configuration: The http request options
112
178
  * - submodelIdentifier: The Submodel’s unique id (UTF8-BASE64-URL-encoded)
113
179
  * - submodelDescriptor: Submodel Descriptor object
180
+ * - ifMatch?: Sent as `If-Match` header; the request fails with `preconditionFailed` if the resource has changed since the `etag` was issued
181
+ * - ifNoneMatch?: Sent as `If-None-Match` header; use `*` to only create the resource (fails with `preconditionFailed` if it exists)
114
182
  *
115
183
  * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
116
184
  */
117
185
  async putSubmodelDescriptorById(options) {
118
- const { configuration, submodelIdentifier, submodelDescriptor } = options;
186
+ const { configuration, submodelIdentifier, submodelDescriptor, ifMatch, ifNoneMatch } = options;
119
187
  try {
120
- const apiInstance = new SubmodelRegistryService.SubmodelRegistryAPIApi(applyDefaults(configuration));
121
- const encodedSubmodelIdentifier = base64Encode(submodelIdentifier);
122
- const result = await apiInstance.putSubmodelDescriptorById({
188
+ const apiInstance = new SubmodelRegistryService.SubmodelRegistryAPIApi(applyDefaults(configuration, { ifMatch, ifNoneMatch }));
189
+ const encodedSubmodelIdentifier = base64Encode(SubmodelRegistryClient.requireIdentifier(submodelIdentifier, 'submodelIdentifier'));
190
+ const response = await apiInstance.putSubmodelDescriptorByIdRaw({
123
191
  submodelIdentifier: encodedSubmodelIdentifier,
124
192
  submodelDescriptor: convertCoreSubmodelDescriptorToApiSubmodelDescriptor(submodelDescriptor),
125
193
  });
194
+ if (response.raw.status === 204) {
195
+ return {
196
+ success: true,
197
+ data: undefined,
198
+ statusCode: response.raw.status,
199
+ etag: getEtag(response.raw),
200
+ };
201
+ }
202
+ const result = await response.value();
126
203
  return {
127
204
  success: true,
128
205
  data: result ? convertApiSubmodelDescriptorToCoreSubmodelDescriptor(result) : undefined,
206
+ statusCode: response.raw.status,
207
+ etag: getEtag(response.raw),
129
208
  };
130
209
  }
131
210
  catch (err) {
132
211
  const customError = await handleApiError(err);
133
- return { success: false, error: customError };
212
+ return {
213
+ success: false,
214
+ error: customError,
215
+ statusCode: SubmodelRegistryClient.extractStatusCode(err, customError),
216
+ ...getConditionalErrorFields(err),
217
+ };
134
218
  }
135
219
  }
136
220
  /**
@@ -145,12 +229,18 @@ export class SubmodelRegistryClient {
145
229
  const { configuration } = options;
146
230
  try {
147
231
  const apiInstance = new SubmodelRegistryService.DescriptionAPIApi(applyDefaults(configuration));
148
- const result = await apiInstance.getSelfDescription();
149
- return { success: true, data: result };
232
+ const response = await apiInstance.getSelfDescriptionRaw();
233
+ const result = await response.value();
234
+ return { success: true, data: result, statusCode: response.raw.status, etag: getEtag(response.raw) };
150
235
  }
151
236
  catch (err) {
152
237
  const customError = await handleApiError(err);
153
- return { success: false, error: customError };
238
+ return {
239
+ success: false,
240
+ error: customError,
241
+ statusCode: SubmodelRegistryClient.extractStatusCode(err, customError),
242
+ ...getConditionalErrorFields(err),
243
+ };
154
244
  }
155
245
  }
156
246
  }