node-opcua-client-dynamic-extension-object 2.178.0 → 2.180.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/dist/convert_data_type_definition_to_structuretype_schema.d.ts +8 -11
- package/dist/convert_data_type_definition_to_structuretype_schema.js +81 -48
- package/dist/convert_data_type_definition_to_structuretype_schema.js.map +1 -1
- package/dist/convert_structuretype_schema_to_structure_definition.d.ts +1 -1
- package/dist/convert_structuretype_schema_to_structure_definition.js +5 -3
- package/dist/convert_structuretype_schema_to_structure_definition.js.map +1 -1
- package/dist/extra_data_type_manager.d.ts +4 -5
- package/dist/extra_data_type_manager.js +15 -16
- package/dist/extra_data_type_manager.js.map +1 -1
- package/dist/get_extension_object_constructor.d.ts +3 -3
- package/dist/get_extension_object_constructor.js +3 -0
- package/dist/get_extension_object_constructor.js.map +1 -1
- package/dist/get_extra_data_type_manager.d.ts +2 -2
- package/dist/get_extra_data_type_manager.js +8 -8
- package/dist/get_extra_data_type_manager.js.map +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.js +20 -21
- package/dist/index.js.map +1 -1
- package/dist/populate_data_type_manager.d.ts +2 -2
- package/dist/populate_data_type_manager.js +10 -10
- package/dist/populate_data_type_manager.js.map +1 -1
- package/dist/private/find_encodings.d.ts +2 -2
- package/dist/private/find_encodings.js.map +1 -1
- package/dist/private/populate_data_type_manager_103.d.ts +4 -4
- package/dist/private/populate_data_type_manager_103.js +97 -53
- package/dist/private/populate_data_type_manager_103.js.map +1 -1
- package/dist/private/populate_data_type_manager_104.d.ts +18 -4
- package/dist/private/populate_data_type_manager_104.js +48 -17
- package/dist/private/populate_data_type_manager_104.js.map +1 -1
- package/dist/promote_opaque_structure.d.ts +2 -2
- package/dist/promote_opaque_structure.js.map +1 -1
- package/dist/promote_opaque_structure_in_notification_data.d.ts +2 -2
- package/dist/promote_opaque_structure_in_notification_data.js +0 -2
- package/dist/promote_opaque_structure_in_notification_data.js.map +1 -1
- package/dist/resolve_dynamic_extension_object.d.ts +4 -4
- package/dist/resolve_dynamic_extension_object.js +15 -12
- package/dist/resolve_dynamic_extension_object.js.map +1 -1
- package/package.json +18 -18
- package/source/convert_data_type_definition_to_structuretype_schema.ts +146 -123
- package/source/convert_structuretype_schema_to_structure_definition.ts +9 -9
- package/source/extra_data_type_manager.ts +24 -22
- package/source/get_extension_object_constructor.ts +12 -7
- package/source/get_extra_data_type_manager.ts +21 -24
- package/source/index.ts +8 -8
- package/source/populate_data_type_manager.ts +17 -25
- package/source/private/find_encodings.ts +2 -2
- package/source/private/populate_data_type_manager_103.ts +166 -105
- package/source/private/populate_data_type_manager_104.ts +102 -45
- package/source/promote_opaque_structure.ts +3 -3
- package/source/promote_opaque_structure_in_notification_data.ts +3 -5
- package/source/resolve_dynamic_extension_object.ts +28 -29
|
@@ -1,41 +1,63 @@
|
|
|
1
1
|
import { AttributeIds, BrowseDirection } from "node-opcua-data-model";
|
|
2
2
|
import { checkDebugFlag, make_debugLog, make_errorLog, make_warningLog } from "node-opcua-debug";
|
|
3
3
|
import { DataTypeFactory, getStandardDataTypeFactory } from "node-opcua-factory";
|
|
4
|
-
import { NodeId,
|
|
5
|
-
import {
|
|
4
|
+
import { NodeId, type NodeIdLike, resolveNodeId } from "node-opcua-nodeid";
|
|
5
|
+
import {
|
|
6
|
+
browseAll,
|
|
7
|
+
type IBasicSessionAsync2,
|
|
8
|
+
type IBasicSessionBrowseAsync,
|
|
9
|
+
type IBasicSessionBrowseNext,
|
|
10
|
+
type IBasicSessionReadAsync,
|
|
11
|
+
type IBasicSessionTranslateBrowsePathAsync
|
|
12
|
+
} from "node-opcua-pseudo-session";
|
|
6
13
|
import { createDynamicObjectConstructor as createDynamicObjectConstructorAndRegister } from "node-opcua-schemas";
|
|
14
|
+
import { StatusCodes } from "node-opcua-status-code";
|
|
7
15
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
type BrowseDescriptionOptions,
|
|
17
|
+
type DataTypeDefinition,
|
|
18
|
+
type ReferenceDescription,
|
|
19
|
+
StructureDefinition
|
|
12
20
|
} from "node-opcua-types";
|
|
13
|
-
//
|
|
14
|
-
import { ExtraDataTypeManager } from "../extra_data_type_manager";
|
|
15
21
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
convertDataTypeDefinitionToStructureTypeSchema,
|
|
23
|
+
type ICache
|
|
18
24
|
} from "../convert_data_type_definition_to_structuretype_schema";
|
|
25
|
+
//
|
|
26
|
+
import type { ExtraDataTypeManager } from "../extra_data_type_manager";
|
|
19
27
|
import { hasBoostedSession } from "../get_extra_data_type_manager";
|
|
20
|
-
import { StatusCodes } from "node-opcua-status-code";
|
|
21
28
|
|
|
22
29
|
const errorLog = make_errorLog("populateDataTypeManager");
|
|
23
30
|
const debugLog = make_debugLog("populateDataTypeManager");
|
|
24
31
|
const warningLog = make_warningLog("populateDataTypeManager");
|
|
25
32
|
const doDebug = checkDebugFlag("populateDataTypeManager");
|
|
26
33
|
|
|
27
|
-
type DependentNamespaces = Set<number
|
|
34
|
+
type DependentNamespaces = Set<number>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A dataType that could not be turned into a constructor.
|
|
38
|
+
*
|
|
39
|
+
* These are collected rather than only logged. A failure here means the class is never
|
|
40
|
+
* registered, so decoding that extension object fails later with nothing pointing back
|
|
41
|
+
* to this load - and the 1.03 loader had exactly that fault for five standard types
|
|
42
|
+
* while every test passed. One line naming the count and the types makes the state
|
|
43
|
+
* visible without anyone having to read scrollback.
|
|
44
|
+
*/
|
|
45
|
+
export interface IDataTypeLoadFailure {
|
|
46
|
+
dataTypeNodeId: string;
|
|
47
|
+
name: string;
|
|
48
|
+
message: string;
|
|
49
|
+
}
|
|
28
50
|
|
|
29
51
|
export async function readDataTypeDefinitionAndBuildType(
|
|
30
52
|
session: IBasicSessionAsync2,
|
|
31
53
|
dataTypeNodeId: NodeId,
|
|
32
54
|
name: string | undefined,
|
|
33
55
|
dataTypeManager: ExtraDataTypeManager,
|
|
34
|
-
cache: ICache
|
|
56
|
+
cache: ICache,
|
|
57
|
+
failures?: IDataTypeLoadFailure[]
|
|
35
58
|
): Promise<DependentNamespaces> {
|
|
36
59
|
const dependentNamespaces: DependentNamespaces = new Set();
|
|
37
60
|
try {
|
|
38
|
-
|
|
39
61
|
if (dataTypeManager.getStructureInfoForDataType(dataTypeNodeId)) {
|
|
40
62
|
return dependentNamespaces;
|
|
41
63
|
}
|
|
@@ -53,9 +75,10 @@ export async function readDataTypeDefinitionAndBuildType(
|
|
|
53
75
|
nodeId: dataTypeNodeId
|
|
54
76
|
}
|
|
55
77
|
]);
|
|
56
|
-
if (isAbstractDataValue.statusCode
|
|
78
|
+
if (isAbstractDataValue.statusCode === StatusCodes.BadNodeIdUnknown) {
|
|
57
79
|
// may be model is incomplete and dataTypeNodeId is missing
|
|
58
|
-
|
|
80
|
+
// c8 ignore next
|
|
81
|
+
doDebug && debugLog("Cannot find dataTypeNodeId = ", dataTypeNodeId.toString());
|
|
59
82
|
return dependentNamespaces;
|
|
60
83
|
}
|
|
61
84
|
|
|
@@ -64,7 +87,9 @@ export async function readDataTypeDefinitionAndBuildType(
|
|
|
64
87
|
/* c8 ignore next */
|
|
65
88
|
if (isAbstractDataValue.statusCode.isNotGood()) {
|
|
66
89
|
errorLog("browseName", browseNameDataValue.value.toString());
|
|
67
|
-
throw new Error(
|
|
90
|
+
throw new Error(
|
|
91
|
+
` Cannot find dataType isAbstract ! with nodeId =${dataTypeNodeId.toString()} ${isAbstractDataValue.statusCode.toString()}`
|
|
92
|
+
);
|
|
68
93
|
}
|
|
69
94
|
const isAbstract = isAbstractDataValue.value.value as boolean;
|
|
70
95
|
|
|
@@ -79,7 +104,11 @@ export async function readDataTypeDefinitionAndBuildType(
|
|
|
79
104
|
{ nodeId: dataTypeNodeId, attributeId: AttributeIds.IsAbstract },
|
|
80
105
|
{ nodeId: dataTypeNodeId, attributeId: AttributeIds.BrowseName }
|
|
81
106
|
]);
|
|
82
|
-
warningLog(
|
|
107
|
+
warningLog(
|
|
108
|
+
` Cannot find dataType Definition ! with nodeId =${dataTypeNodeId.toString()}`,
|
|
109
|
+
browseNameDV.value?.value?.toString(),
|
|
110
|
+
isAbstract2.value?.value
|
|
111
|
+
);
|
|
83
112
|
return dependentNamespaces;
|
|
84
113
|
}
|
|
85
114
|
// it is OK to not have dataTypeDefinition for Abstract type!
|
|
@@ -89,10 +118,10 @@ export async function readDataTypeDefinitionAndBuildType(
|
|
|
89
118
|
// get dependencies of struct
|
|
90
119
|
if (dataTypeDefinition instanceof StructureDefinition && dataTypeDefinition.fields) {
|
|
91
120
|
for (const field of dataTypeDefinition.fields) {
|
|
92
|
-
const dataTypeNamespace = field.dataType.namespace
|
|
121
|
+
const dataTypeNamespace = field.dataType.namespace;
|
|
93
122
|
if (dataTypeNamespace === dataTypeDefinition.defaultEncodingId.namespace) {
|
|
94
123
|
continue; // not dependent on own namespace
|
|
95
|
-
}
|
|
124
|
+
}
|
|
96
125
|
dependentNamespaces.add(dataTypeNamespace);
|
|
97
126
|
}
|
|
98
127
|
}
|
|
@@ -113,10 +142,17 @@ export async function readDataTypeDefinitionAndBuildType(
|
|
|
113
142
|
// cannot construct an abstract structure
|
|
114
143
|
dataTypeFactory.registerAbstractStructure(dataTypeNodeId, resolvedName, schema);
|
|
115
144
|
} else {
|
|
116
|
-
|
|
145
|
+
createDynamicObjectConstructorAndRegister(schema, dataTypeFactory);
|
|
117
146
|
}
|
|
118
147
|
} catch (err) {
|
|
119
|
-
|
|
148
|
+
const message = (err as Error).message;
|
|
149
|
+
if (failures) {
|
|
150
|
+
// the caller reports these together; logging here as well would only
|
|
151
|
+
// reproduce the scattered lines this is meant to replace
|
|
152
|
+
failures.push({ dataTypeNodeId: dataTypeNodeId.toString(), name: name || "?", message });
|
|
153
|
+
} else {
|
|
154
|
+
errorLog("Error", message, " while processing dataTypeNodeId =", dataTypeNodeId.toString());
|
|
155
|
+
}
|
|
120
156
|
}
|
|
121
157
|
return dependentNamespaces;
|
|
122
158
|
}
|
|
@@ -125,10 +161,10 @@ export async function populateDataTypeManager104(
|
|
|
125
161
|
session: IBasicSessionAsync2,
|
|
126
162
|
dataTypeManager: ExtraDataTypeManager
|
|
127
163
|
): Promise<void> {
|
|
128
|
-
|
|
129
164
|
const dataFactoriesDependencies = new Map<number, DependentNamespaces>();
|
|
130
165
|
|
|
131
166
|
const cache: ICache = {};
|
|
167
|
+
const failures: IDataTypeLoadFailure[] = [];
|
|
132
168
|
|
|
133
169
|
async function withDataType(r: ReferenceDescription): Promise<void> {
|
|
134
170
|
const dataTypeNodeId = r.nodeId;
|
|
@@ -155,13 +191,18 @@ export async function populateDataTypeManager104(
|
|
|
155
191
|
}
|
|
156
192
|
|
|
157
193
|
// extract it formally
|
|
158
|
-
doDebug &&
|
|
194
|
+
doDebug &&
|
|
195
|
+
debugLog("populateDataTypeManager104: processing dataType = ", r.browseName.toString(), dataTypeNodeId.toString());
|
|
196
|
+
if (!r.browseName.name) {
|
|
197
|
+
throw new Error(`Unexpected: BrowseName has no name for nodeId ${dataTypeNodeId.toString()}`);
|
|
198
|
+
}
|
|
159
199
|
const dependentNamespaces = await readDataTypeDefinitionAndBuildType(
|
|
160
200
|
session,
|
|
161
201
|
dataTypeNodeId,
|
|
162
|
-
r.browseName.name
|
|
202
|
+
r.browseName.name,
|
|
163
203
|
dataTypeManager,
|
|
164
|
-
cache
|
|
204
|
+
cache,
|
|
205
|
+
failures
|
|
165
206
|
);
|
|
166
207
|
|
|
167
208
|
// add dependent namespaces to dataFactoriesDependencies
|
|
@@ -171,10 +212,16 @@ export async function populateDataTypeManager104(
|
|
|
171
212
|
dataFactoryDependencies = new Set([0]); // always dependent on UA node set
|
|
172
213
|
dataFactoriesDependencies.set(dataTypeNodeId.namespace, dataFactoryDependencies);
|
|
173
214
|
}
|
|
174
|
-
|
|
175
|
-
|
|
215
|
+
for (const ns of dependentNamespaces) {
|
|
216
|
+
dataFactoryDependencies.add(ns);
|
|
217
|
+
}
|
|
176
218
|
} catch (err) {
|
|
177
|
-
|
|
219
|
+
// named, so the summary below can say which type failed rather than "err="
|
|
220
|
+
failures.push({
|
|
221
|
+
dataTypeNodeId: dataTypeNodeId.toString(),
|
|
222
|
+
name: r.browseName.name || "?",
|
|
223
|
+
message: (err as Error).message
|
|
224
|
+
});
|
|
178
225
|
}
|
|
179
226
|
}
|
|
180
227
|
|
|
@@ -188,9 +235,21 @@ export async function populateDataTypeManager104(
|
|
|
188
235
|
};
|
|
189
236
|
await applyOnReferenceRecursively(session, resolveNodeId("Structure"), nodeToBrowse, withDataType);
|
|
190
237
|
|
|
238
|
+
// One line for the whole load. A dataType that fails here is simply absent from the
|
|
239
|
+
// factory, and every later decode of it fails somewhere unrelated, so the count
|
|
240
|
+
// belongs where it can be seen rather than spread across the run.
|
|
241
|
+
if (failures.length > 0) {
|
|
242
|
+
warningLog(
|
|
243
|
+
`populateDataTypeManager104: ${failures.length} dataType(s) could not be registered;` +
|
|
244
|
+
" decoding those extension objects will fail:"
|
|
245
|
+
);
|
|
246
|
+
for (const f of failures) {
|
|
247
|
+
warningLog(` ${f.name} (${f.dataTypeNodeId}): ${f.message}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
191
251
|
// set factory dependencies
|
|
192
252
|
for (const [namespace, dependentNamespaces] of dataFactoriesDependencies) {
|
|
193
|
-
|
|
194
253
|
const namespaceDataTypeFactory = dataTypeManager.getDataTypeFactoryForNamespace(namespace);
|
|
195
254
|
const dependentTypeFactories = new Set<DataTypeFactory>([getStandardDataTypeFactory()]);
|
|
196
255
|
|
|
@@ -210,15 +269,13 @@ async function applyOnReferenceRecursively(
|
|
|
210
269
|
browseDescriptionTemplate: BrowseDescriptionOptions,
|
|
211
270
|
action: (ref: ReferenceDescription) => Promise<void>
|
|
212
271
|
): Promise<void> {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const hasBoosted = hasBoostedSession(session as any);
|
|
272
|
+
const hasBoosted = hasBoostedSession(session as unknown as IBasicSessionAsync2);
|
|
216
273
|
const useHeavyParallelization = hasBoosted;
|
|
217
274
|
|
|
218
|
-
|
|
275
|
+
// c8 ignore next
|
|
276
|
+
doDebug && debugLog("applyOnReferenceRecursively = useHeavyParallelization", useHeavyParallelization);
|
|
219
277
|
|
|
220
278
|
const oneLevel = async (nodeId: NodeIdLike, level: number) => {
|
|
221
|
-
|
|
222
279
|
doDebug && debugLog("applyOnReferenceRecursively = level", level, "nodeId", nodeId.toString());
|
|
223
280
|
const nodeToBrowse: BrowseDescriptionOptions = {
|
|
224
281
|
...browseDescriptionTemplate,
|
|
@@ -227,27 +284,27 @@ async function applyOnReferenceRecursively(
|
|
|
227
284
|
|
|
228
285
|
const browseResult = await browseAll(session, nodeToBrowse);
|
|
229
286
|
if (useHeavyParallelization) {
|
|
230
|
-
// @sterfive/optimized-client (PRO module) we can
|
|
231
|
-
// parallelize and minimize the number of calls to the server to
|
|
287
|
+
// @sterfive/optimized-client (PRO module) we can
|
|
288
|
+
// parallelize and minimize the number of calls to the server to
|
|
232
289
|
// drastically improve performance
|
|
233
290
|
const promises: Promise<void>[] = [];
|
|
234
291
|
for (const ref of browseResult.references || []) {
|
|
235
|
-
promises.push(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
292
|
+
promises.push(
|
|
293
|
+
(async () => {
|
|
294
|
+
await action(ref);
|
|
295
|
+
await oneLevel(ref.nodeId, level + 1);
|
|
296
|
+
})()
|
|
297
|
+
);
|
|
239
298
|
}
|
|
240
299
|
await Promise.all(promises);
|
|
241
|
-
|
|
242
300
|
} else {
|
|
243
301
|
// important: we dont parallelize the action on browse reference
|
|
244
|
-
// to avoid overloading browseContinuationToken on client side
|
|
302
|
+
// to avoid overloading browseContinuationToken on client side
|
|
245
303
|
for (const ref of browseResult.references || []) {
|
|
246
304
|
await action(ref);
|
|
247
305
|
await oneLevel(ref.nodeId, level + 1);
|
|
248
306
|
}
|
|
249
|
-
|
|
250
307
|
}
|
|
251
308
|
};
|
|
252
309
|
await oneLevel(nodeId, 0);
|
|
253
|
-
}
|
|
310
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpaqueStructure } from "node-opcua-extension-object";
|
|
2
|
-
import { IBasicSessionAsync2 } from "node-opcua-pseudo-session";
|
|
3
|
-
import { DataType,
|
|
2
|
+
import type { IBasicSessionAsync2 } from "node-opcua-pseudo-session";
|
|
3
|
+
import { DataType, type Variant, VariantArrayType } from "node-opcua-variant";
|
|
4
4
|
//
|
|
5
5
|
import { getExtraDataTypeManager } from "./get_extra_data_type_manager";
|
|
6
6
|
import { resolveDynamicExtensionObject } from "./resolve_dynamic_extension_object";
|
|
@@ -24,7 +24,7 @@ export function extractDataValueToPromote(dataValues: PseudoDataValue[]): Pseudo
|
|
|
24
24
|
return dataValuesToFix;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
*
|
|
28
28
|
* @private
|
|
29
29
|
*/
|
|
30
30
|
export async function promoteOpaqueStructure(session: IBasicSessionAsync2, dataValues: PseudoDataValue[]) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { IBasicSessionAsync2 } from "node-opcua-pseudo-session";
|
|
2
|
+
import { DataChangeNotification, EventNotificationList, type NotificationData } from "node-opcua-types";
|
|
3
|
+
import { DataType, type Variant } from "node-opcua-variant";
|
|
4
4
|
import { promoteOpaqueStructure } from "./promote_opaque_structure";
|
|
5
5
|
|
|
6
6
|
export async function promoteOpaqueStructureInNotificationData(
|
|
@@ -24,9 +24,7 @@ export async function promoteOpaqueStructureInNotificationData(
|
|
|
24
24
|
if (notification.events) {
|
|
25
25
|
for (const events of notification.events) {
|
|
26
26
|
if (events.eventFields) {
|
|
27
|
-
// eslint-disable-next-line max-depth
|
|
28
27
|
for (const eventField of events.eventFields) {
|
|
29
|
-
// eslint-disable-next-line max-depth
|
|
30
28
|
if (eventField.dataType === DataType.ExtensionObject) {
|
|
31
29
|
dataValuesToPromote.push({ value: eventField });
|
|
32
30
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BinaryStream } from "node-opcua-binary-stream";
|
|
2
|
+
import { make_warningLog } from "node-opcua-debug";
|
|
2
3
|
import { ExtensionObject, OpaqueStructure } from "node-opcua-extension-object";
|
|
4
|
+
import type { IBaseUAObject, StructuredTypeField } from "node-opcua-factory";
|
|
5
|
+
import type { IBasicSessionAsync2 } from "node-opcua-pseudo-session";
|
|
3
6
|
import { DataType, Variant, VariantArrayType } from "node-opcua-variant";
|
|
4
|
-
import { make_warningLog } from "node-opcua-debug";
|
|
5
|
-
import { IBasicSessionAsync2 } from "node-opcua-pseudo-session";
|
|
6
|
-
import { StructuredTypeField } from "node-opcua-factory";
|
|
7
7
|
//
|
|
8
|
-
import { ExtraDataTypeManager } from "./extra_data_type_manager";
|
|
8
|
+
import type { ExtraDataTypeManager } from "./extra_data_type_manager";
|
|
9
9
|
|
|
10
10
|
const warningLog = make_warningLog(__filename);
|
|
11
11
|
|
|
@@ -13,10 +13,9 @@ export async function resolveOpaqueStructureInExtensionObject(
|
|
|
13
13
|
session: IBasicSessionAsync2,
|
|
14
14
|
dataTypeManager: ExtraDataTypeManager,
|
|
15
15
|
object: ExtensionObject,
|
|
16
|
-
|
|
16
|
+
visitedParam?: Set<unknown>
|
|
17
17
|
): Promise<void> {
|
|
18
|
-
|
|
19
|
-
visited = visited || new Set();
|
|
18
|
+
const visited = visitedParam || new Set<unknown>();
|
|
20
19
|
if (visited.has(object)) {
|
|
21
20
|
return;
|
|
22
21
|
}
|
|
@@ -25,48 +24,48 @@ export async function resolveOpaqueStructureInExtensionObject(
|
|
|
25
24
|
interface D {
|
|
26
25
|
dataTypeManager: ExtraDataTypeManager;
|
|
27
26
|
promises: Promise<void>[];
|
|
28
|
-
visited: Set<
|
|
27
|
+
visited: Set<unknown>;
|
|
29
28
|
}
|
|
30
29
|
async function fixOpaqueStructureOnElement(
|
|
31
|
-
element:
|
|
32
|
-
|
|
30
|
+
element: unknown,
|
|
31
|
+
_field: StructuredTypeField,
|
|
33
32
|
data: D,
|
|
34
|
-
|
|
33
|
+
_args?: unknown
|
|
35
34
|
): Promise<unknown> {
|
|
36
|
-
|
|
37
|
-
|
|
38
35
|
if (!element) {
|
|
39
36
|
return element;
|
|
40
37
|
}
|
|
38
|
+
const elementAsRecord = element as { constructor?: { name?: string; schema?: { name?: string } } };
|
|
41
39
|
|
|
42
|
-
if (element instanceof Variant ||
|
|
43
|
-
await resolveDynamicExtensionObject(session, element, dataTypeManager, data.visited);
|
|
40
|
+
if (element instanceof Variant || elementAsRecord.constructor?.name === "Variant") {
|
|
41
|
+
await resolveDynamicExtensionObject(session, element as Variant, dataTypeManager, data.visited);
|
|
44
42
|
return element;
|
|
45
43
|
}
|
|
46
|
-
if (element instanceof ExtensionObject ||
|
|
44
|
+
if (element instanceof ExtensionObject || elementAsRecord.constructor?.schema?.name === "ExtensionObject") {
|
|
47
45
|
if (element instanceof OpaqueStructure) {
|
|
48
46
|
const variant = new Variant({ dataType: DataType.ExtensionObject, value: element });
|
|
49
47
|
await resolveDynamicExtensionObject(session, variant, dataTypeManager, data.visited);
|
|
50
48
|
return variant.value as unknown;
|
|
51
49
|
} else {
|
|
52
|
-
await resolveOpaqueStructureInExtensionObject(session, dataTypeManager, element, data.visited);
|
|
50
|
+
await resolveOpaqueStructureInExtensionObject(session, dataTypeManager, element as ExtensionObject, data.visited);
|
|
53
51
|
return element;
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
return element;
|
|
57
55
|
}
|
|
58
|
-
function fixOpaqueStructure(
|
|
59
|
-
|
|
56
|
+
function fixOpaqueStructure(objectArg: IBaseUAObject, field: StructuredTypeField, data: D, args?: unknown) {
|
|
57
|
+
const object = objectArg as unknown as Record<string, unknown>;
|
|
60
58
|
const a = object[field.name];
|
|
61
59
|
if (!a) {
|
|
62
60
|
return;
|
|
63
61
|
}
|
|
64
62
|
if (field.isArray) {
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
const arr = a as unknown[];
|
|
64
|
+
for (let i = 0; i < arr.length; i++) {
|
|
65
|
+
const x = arr[i];
|
|
67
66
|
data.promises.push(
|
|
68
67
|
(async () => {
|
|
69
|
-
|
|
68
|
+
arr[i] = await fixOpaqueStructureOnElement(x, field, data, args);
|
|
70
69
|
})()
|
|
71
70
|
);
|
|
72
71
|
}
|
|
@@ -87,11 +86,11 @@ export async function resolveDynamicExtensionObject(
|
|
|
87
86
|
session: IBasicSessionAsync2,
|
|
88
87
|
variant: Variant,
|
|
89
88
|
dataTypeManager: ExtraDataTypeManager,
|
|
90
|
-
|
|
89
|
+
visitedParam?: Set<unknown>
|
|
91
90
|
): Promise<void> {
|
|
92
|
-
visited =
|
|
91
|
+
const visited = visitedParam || new Set<unknown>();
|
|
93
92
|
|
|
94
|
-
const handleValue = async (value:
|
|
93
|
+
const handleValue = async (value: unknown): Promise<unknown> => {
|
|
95
94
|
if (!value) {
|
|
96
95
|
return value;
|
|
97
96
|
}
|
|
@@ -102,7 +101,7 @@ export async function resolveDynamicExtensionObject(
|
|
|
102
101
|
const stream = new BinaryStream(value.buffer);
|
|
103
102
|
try {
|
|
104
103
|
object.decode(stream);
|
|
105
|
-
await resolveOpaqueStructureInExtensionObject(session, dataTypeManager, object, visited
|
|
104
|
+
await resolveOpaqueStructureInExtensionObject(session, dataTypeManager, object, visited);
|
|
106
105
|
return object;
|
|
107
106
|
} catch (err) {
|
|
108
107
|
warningLog("resolveDynamicExtensionObjectV: error decoding or resolving inner structures");
|
|
@@ -120,15 +119,15 @@ export async function resolveDynamicExtensionObject(
|
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
121
|
if (value instanceof ExtensionObject) {
|
|
123
|
-
await resolveOpaqueStructureInExtensionObject(session, dataTypeManager, value, visited
|
|
122
|
+
await resolveOpaqueStructureInExtensionObject(session, dataTypeManager, value, visited);
|
|
124
123
|
return value;
|
|
125
124
|
}
|
|
126
125
|
if (value instanceof Variant) {
|
|
127
|
-
await resolveDynamicExtensionObject(session, value, dataTypeManager, visited
|
|
126
|
+
await resolveDynamicExtensionObject(session, value, dataTypeManager, visited);
|
|
128
127
|
return value;
|
|
129
128
|
}
|
|
130
129
|
return value;
|
|
131
|
-
}
|
|
130
|
+
};
|
|
132
131
|
|
|
133
132
|
if (variant.arrayType !== VariantArrayType.Scalar) {
|
|
134
133
|
if (Array.isArray(variant.value)) {
|