@effect-opcua/client 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +367 -0
- package/dist/Opcua.d.mts +13 -0
- package/dist/Opcua.d.mts.map +1 -0
- package/dist/Opcua.mjs +23 -0
- package/dist/Opcua.mjs.map +1 -0
- package/dist/OpcuaClient.d.mts +27 -0
- package/dist/OpcuaClient.d.mts.map +1 -0
- package/dist/OpcuaClient.mjs +20 -0
- package/dist/OpcuaClient.mjs.map +1 -0
- package/dist/OpcuaError.d.mts +249 -0
- package/dist/OpcuaError.d.mts.map +1 -0
- package/dist/OpcuaError.mjs +97 -0
- package/dist/OpcuaError.mjs.map +1 -0
- package/dist/OpcuaMethod.d.mts +158 -0
- package/dist/OpcuaMethod.d.mts.map +1 -0
- package/dist/OpcuaMethod.mjs +31 -0
- package/dist/OpcuaMethod.mjs.map +1 -0
- package/dist/OpcuaSession.d.mts +247 -0
- package/dist/OpcuaSession.d.mts.map +1 -0
- package/dist/OpcuaSession.mjs +50 -0
- package/dist/OpcuaSession.mjs.map +1 -0
- package/dist/OpcuaSubscription.d.mts +148 -0
- package/dist/OpcuaSubscription.d.mts.map +1 -0
- package/dist/OpcuaSubscription.mjs +45 -0
- package/dist/OpcuaSubscription.mjs.map +1 -0
- package/dist/OpcuaVariable.d.mts +179 -0
- package/dist/OpcuaVariable.d.mts.map +1 -0
- package/dist/OpcuaVariable.mjs +15 -0
- package/dist/OpcuaVariable.mjs.map +1 -0
- package/dist/_virtual/rolldown_runtime.mjs +18 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +7 -0
- package/dist/internal/batch/chunk.d.mts +11 -0
- package/dist/internal/batch/chunk.d.mts.map +1 -0
- package/dist/internal/batch/chunk.mjs +23 -0
- package/dist/internal/batch/chunk.mjs.map +1 -0
- package/dist/internal/batch/keyed.d.mts +50 -0
- package/dist/internal/batch/keyed.d.mts.map +1 -0
- package/dist/internal/batch/keyed.mjs +112 -0
- package/dist/internal/batch/keyed.mjs.map +1 -0
- package/dist/internal/batch/operations.d.mts +25 -0
- package/dist/internal/batch/operations.d.mts.map +1 -0
- package/dist/internal/batch/operations.mjs +213 -0
- package/dist/internal/batch/operations.mjs.map +1 -0
- package/dist/internal/browse/operations.d.mts +15 -0
- package/dist/internal/browse/operations.d.mts.map +1 -0
- package/dist/internal/browse/operations.mjs +72 -0
- package/dist/internal/browse/operations.mjs.map +1 -0
- package/dist/internal/client/make.d.mts +16 -0
- package/dist/internal/client/make.d.mts.map +1 -0
- package/dist/internal/client/make.mjs +76 -0
- package/dist/internal/client/make.mjs.map +1 -0
- package/dist/internal/common/collections.d.mts +5 -0
- package/dist/internal/common/collections.d.mts.map +1 -0
- package/dist/internal/common/collections.mjs +10 -0
- package/dist/internal/common/collections.mjs.map +1 -0
- package/dist/internal/common/constants.d.mts +18 -0
- package/dist/internal/common/constants.d.mts.map +1 -0
- package/dist/internal/common/constants.mjs +19 -0
- package/dist/internal/common/constants.mjs.map +1 -0
- package/dist/internal/common/node-id.d.mts +2 -0
- package/dist/internal/common/node-id.mjs +1 -0
- package/dist/internal/common/options.d.mts +15 -0
- package/dist/internal/common/options.d.mts.map +1 -0
- package/dist/internal/common/options.mjs +22 -0
- package/dist/internal/common/options.mjs.map +1 -0
- package/dist/internal/common/predicates.d.mts +8 -0
- package/dist/internal/common/predicates.d.mts.map +1 -0
- package/dist/internal/common/predicates.mjs +13 -0
- package/dist/internal/common/predicates.mjs.map +1 -0
- package/dist/internal/data-types/enum.d.mts +2 -0
- package/dist/internal/data-types/enum.mjs +3 -0
- package/dist/internal/data-types/manager.d.mts +2 -0
- package/dist/internal/data-types/manager.mjs +3 -0
- package/dist/internal/data-types/model.d.mts +2 -0
- package/dist/internal/data-types/model.mjs +1 -0
- package/dist/internal/data-types/read.d.mts +14 -0
- package/dist/internal/data-types/read.d.mts.map +1 -0
- package/dist/internal/data-types/read.mjs +291 -0
- package/dist/internal/data-types/read.mjs.map +1 -0
- package/dist/internal/data-types/structure.d.mts +2 -0
- package/dist/internal/data-types/structure.mjs +3 -0
- package/dist/internal/events/model.d.mts +72 -0
- package/dist/internal/events/model.d.mts.map +1 -0
- package/dist/internal/events/model.mjs +1 -0
- package/dist/internal/events/wire.d.mts +37 -0
- package/dist/internal/events/wire.d.mts.map +1 -0
- package/dist/internal/events/wire.mjs +127 -0
- package/dist/internal/events/wire.mjs.map +1 -0
- package/dist/internal/metadata/arguments.d.mts +2 -0
- package/dist/internal/metadata/arguments.mjs +3 -0
- package/dist/internal/metadata/methods.d.mts +2 -0
- package/dist/internal/metadata/methods.mjs +3 -0
- package/dist/internal/metadata/service.d.mts +23 -0
- package/dist/internal/metadata/service.d.mts.map +1 -0
- package/dist/internal/metadata/service.mjs +416 -0
- package/dist/internal/metadata/service.mjs.map +1 -0
- package/dist/internal/metadata/variables.d.mts +3 -0
- package/dist/internal/metadata/variables.mjs +3 -0
- package/dist/internal/method/arguments.d.mts +48 -0
- package/dist/internal/method/arguments.d.mts.map +1 -0
- package/dist/internal/method/arguments.mjs +216 -0
- package/dist/internal/method/arguments.mjs.map +1 -0
- package/dist/internal/method/operations.d.mts +19 -0
- package/dist/internal/method/operations.d.mts.map +1 -0
- package/dist/internal/method/operations.mjs +111 -0
- package/dist/internal/method/operations.mjs.map +1 -0
- package/dist/internal/monitoring/options.d.mts +30 -0
- package/dist/internal/monitoring/options.d.mts.map +1 -0
- package/dist/internal/monitoring/options.mjs +260 -0
- package/dist/internal/monitoring/options.mjs.map +1 -0
- package/dist/internal/monitoring/requests.d.mts +16 -0
- package/dist/internal/monitoring/requests.d.mts.map +1 -0
- package/dist/internal/monitoring/requests.mjs +53 -0
- package/dist/internal/monitoring/requests.mjs.map +1 -0
- package/dist/internal/monitoring/runtime.d.mts +14 -0
- package/dist/internal/monitoring/runtime.d.mts.map +1 -0
- package/dist/internal/monitoring/runtime.mjs +321 -0
- package/dist/internal/monitoring/runtime.mjs.map +1 -0
- package/dist/internal/monitoring/samples.d.mts +23 -0
- package/dist/internal/monitoring/samples.d.mts.map +1 -0
- package/dist/internal/monitoring/samples.mjs +45 -0
- package/dist/internal/monitoring/samples.mjs.map +1 -0
- package/dist/internal/session/make.d.mts +11 -0
- package/dist/internal/session/make.d.mts.map +1 -0
- package/dist/internal/session/make.mjs +36 -0
- package/dist/internal/session/make.mjs.map +1 -0
- package/dist/internal/session/service.d.mts +10 -0
- package/dist/internal/session/service.d.mts.map +1 -0
- package/dist/internal/session/service.mjs +232 -0
- package/dist/internal/session/service.mjs.map +1 -0
- package/dist/internal/structures/adapter.d.mts +11 -0
- package/dist/internal/structures/adapter.d.mts.map +1 -0
- package/dist/internal/structures/adapter.mjs +37 -0
- package/dist/internal/structures/adapter.mjs.map +1 -0
- package/dist/internal/structures/model.d.mts +21 -0
- package/dist/internal/structures/model.d.mts.map +1 -0
- package/dist/internal/structures/model.mjs +7 -0
- package/dist/internal/structures/model.mjs.map +1 -0
- package/dist/internal/structures/runtime.d.mts +28 -0
- package/dist/internal/structures/runtime.d.mts.map +1 -0
- package/dist/internal/structures/runtime.mjs +119 -0
- package/dist/internal/structures/runtime.mjs.map +1 -0
- package/dist/internal/subscription/options.d.mts +17 -0
- package/dist/internal/subscription/options.d.mts.map +1 -0
- package/dist/internal/subscription/options.mjs +51 -0
- package/dist/internal/subscription/options.mjs.map +1 -0
- package/dist/internal/subscription/runtime.d.mts +15 -0
- package/dist/internal/subscription/runtime.d.mts.map +1 -0
- package/dist/internal/subscription/runtime.mjs +43 -0
- package/dist/internal/subscription/runtime.mjs.map +1 -0
- package/dist/internal/values/codec.d.mts +53 -0
- package/dist/internal/values/codec.d.mts.map +1 -0
- package/dist/internal/values/codec.mjs +117 -0
- package/dist/internal/values/codec.mjs.map +1 -0
- package/dist/internal/values/normalize.d.mts +33 -0
- package/dist/internal/values/normalize.d.mts.map +1 -0
- package/dist/internal/values/normalize.mjs +177 -0
- package/dist/internal/values/normalize.mjs.map +1 -0
- package/dist/internal/values/result.d.mts +16 -0
- package/dist/internal/values/result.d.mts.map +1 -0
- package/dist/internal/values/result.mjs +15 -0
- package/dist/internal/values/result.mjs.map +1 -0
- package/dist/internal/variable/operations.d.mts +50 -0
- package/dist/internal/variable/operations.d.mts.map +1 -0
- package/dist/internal/variable/operations.mjs +192 -0
- package/dist/internal/variable/operations.mjs.map +1 -0
- package/dist/node-opcua.d.mts +2 -0
- package/dist/node-opcua.mjs +3 -0
- package/package.json +57 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { isPlainRecord } from "../common/predicates.mjs";
|
|
2
|
+
import { configurationError } from "../../OpcuaError.mjs";
|
|
3
|
+
import { readPreparedVariables, writePreparedVariables } from "../variable/operations.mjs";
|
|
4
|
+
import { methodCallOptionsError } from "../method/arguments.mjs";
|
|
5
|
+
import { callMethods, resolveMethod } from "../method/operations.mjs";
|
|
6
|
+
import { normalizeServiceOptions, runKeyedBatchOperation, validateOptionsShape, validateUniqueTargets } from "./keyed.mjs";
|
|
7
|
+
import { coerceNodeId } from "node-opcua";
|
|
8
|
+
import { Effect } from "effect";
|
|
9
|
+
|
|
10
|
+
//#region src/internal/batch/operations.ts
|
|
11
|
+
const readManyWithState = (state, items, options) => runKeyedBatchOperation(items, options, state.batching?.readLimits, {
|
|
12
|
+
operation: "readMany",
|
|
13
|
+
normalizeOptions: normalizeReadManyOptions,
|
|
14
|
+
normalizeItem: normalizeReadManyItem,
|
|
15
|
+
validateItems: validateUniqueNodeIds("readMany.items"),
|
|
16
|
+
preflight: (entries, normalizedOptions) => Effect.gen(function* () {
|
|
17
|
+
if (normalizedOptions.validation === "strict") yield* Effect.forEach(entries, (entry) => state.metadata.variable(entry.normalized.def), { discard: true });
|
|
18
|
+
return entries;
|
|
19
|
+
}),
|
|
20
|
+
execute: (entries, normalizedOptions) => {
|
|
21
|
+
const prepared = entries.map((entry) => ({
|
|
22
|
+
def: entry.normalized.def,
|
|
23
|
+
rawNodeId: entry.normalized.rawNodeId
|
|
24
|
+
}));
|
|
25
|
+
return readPreparedVariables(state.unsafeRaw, prepared, state.structureRuntime, {
|
|
26
|
+
maxItemsPerRequest: normalizedOptions.maxNodesPerRequest,
|
|
27
|
+
maxConcurrentRequests: normalizedOptions.maxConcurrentRequests
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
toPublicResult: (_entry, raw) => Effect.succeed(raw)
|
|
31
|
+
});
|
|
32
|
+
const writeManyWithState = (state, items, options) => runKeyedBatchOperation(items, options, state.batching?.writeLimits, {
|
|
33
|
+
operation: "writeMany",
|
|
34
|
+
normalizeOptions: normalizeWriteManyOptions,
|
|
35
|
+
normalizeItem: normalizeWriteManyItem,
|
|
36
|
+
validateItems: validateUniqueNodeIds("writeMany.items"),
|
|
37
|
+
preflight: (entries) => Effect.forEach(entries, (entry) => Effect.map(state.metadata.variable(entry.normalized.def), (metadata) => ({
|
|
38
|
+
key: entry.key,
|
|
39
|
+
index: entry.index,
|
|
40
|
+
normalized: {
|
|
41
|
+
def: entry.normalized.def,
|
|
42
|
+
metadata,
|
|
43
|
+
value: entry.normalized.value,
|
|
44
|
+
rawNodeId: entry.normalized.rawNodeId
|
|
45
|
+
}
|
|
46
|
+
}))),
|
|
47
|
+
execute: (entries, normalizedOptions) => writePreparedVariables(state.unsafeRaw, entries.map((entry) => entry.normalized), state.structureRuntime, {
|
|
48
|
+
maxItemsPerRequest: normalizedOptions.maxNodesPerRequest,
|
|
49
|
+
maxConcurrentRequests: normalizedOptions.maxConcurrentRequests
|
|
50
|
+
}),
|
|
51
|
+
toPublicResult: (_entry, raw) => Effect.succeed(raw)
|
|
52
|
+
});
|
|
53
|
+
const callManyWithState = (state, items, options) => runKeyedBatchOperation(items, options, state.batching?.callLimits, {
|
|
54
|
+
operation: "callMany",
|
|
55
|
+
normalizeOptions: normalizeCallManyOptions,
|
|
56
|
+
normalizeItem: normalizeCallManyItem,
|
|
57
|
+
preflight: (entries) => Effect.forEach(entries, (entry) => Effect.gen(function* () {
|
|
58
|
+
const methodMetadata = yield* state.metadata.method(entry.normalized.def);
|
|
59
|
+
const method = yield* resolveMethod(entry.normalized.def, methodMetadata);
|
|
60
|
+
return {
|
|
61
|
+
key: entry.key,
|
|
62
|
+
index: entry.index,
|
|
63
|
+
normalized: {
|
|
64
|
+
method,
|
|
65
|
+
input: entry.normalized.input,
|
|
66
|
+
options: entry.normalized.options
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
})),
|
|
70
|
+
execute: (entries, normalizedOptions) => callMethods(state.unsafeRaw, entries.map((entry) => entry.normalized), state.structureRuntime, {
|
|
71
|
+
maxItemsPerRequest: normalizedOptions.maxNodesPerRequest,
|
|
72
|
+
maxConcurrentRequests: normalizedOptions.maxConcurrentRequests
|
|
73
|
+
}),
|
|
74
|
+
toPublicResult: (_entry, raw) => Effect.succeed(raw)
|
|
75
|
+
});
|
|
76
|
+
const normalizeReadManyItem = (key, value) => Effect.suspend(() => {
|
|
77
|
+
if (!isReadableVariableDef(value)) return Effect.fail(configurationError({
|
|
78
|
+
operation: "readMany.items",
|
|
79
|
+
key,
|
|
80
|
+
cause: "items must be readable variable definitions"
|
|
81
|
+
}));
|
|
82
|
+
const rawNodeId = coerceNodeIdForKey("readMany.items", key, value.nodeId);
|
|
83
|
+
if (rawNodeId instanceof Error) return Effect.fail(rawNodeId);
|
|
84
|
+
return Effect.succeed({
|
|
85
|
+
def: value,
|
|
86
|
+
nodeId: rawNodeId.toString(),
|
|
87
|
+
rawNodeId
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
const normalizeWriteManyItem = (key, tuple) => Effect.suspend(() => {
|
|
91
|
+
if (!Array.isArray(tuple) || tuple.length !== 2) return Effect.fail(configurationError({
|
|
92
|
+
operation: "writeMany.items",
|
|
93
|
+
key,
|
|
94
|
+
cause: "write entries must be [definition, value] tuples"
|
|
95
|
+
}));
|
|
96
|
+
const [def, value] = tuple;
|
|
97
|
+
if (!isWritableVariableDef(def)) return Effect.fail(configurationError({
|
|
98
|
+
operation: "writeMany.items",
|
|
99
|
+
key,
|
|
100
|
+
cause: "write entries must use writable variable definitions"
|
|
101
|
+
}));
|
|
102
|
+
const rawNodeId = coerceNodeIdForKey("writeMany.items", key, def.nodeId);
|
|
103
|
+
if (rawNodeId instanceof Error) return Effect.fail(rawNodeId);
|
|
104
|
+
return Effect.succeed({
|
|
105
|
+
def,
|
|
106
|
+
value,
|
|
107
|
+
nodeId: rawNodeId.toString(),
|
|
108
|
+
rawNodeId
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
const normalizeCallManyItem = (key, tuple) => Effect.suspend(() => {
|
|
112
|
+
if (!Array.isArray(tuple) || tuple.length !== 2 && tuple.length !== 3) return Effect.fail(configurationError({
|
|
113
|
+
operation: "callMany.items",
|
|
114
|
+
key,
|
|
115
|
+
cause: "call entries must be [definition, input] or [definition, input, options] tuples"
|
|
116
|
+
}));
|
|
117
|
+
const [def, input, itemOptions] = tuple;
|
|
118
|
+
if (!isMethodDef(def)) return Effect.fail(configurationError({
|
|
119
|
+
operation: "callMany.items",
|
|
120
|
+
key,
|
|
121
|
+
cause: "call entries must use method definitions"
|
|
122
|
+
}));
|
|
123
|
+
const optionsError = methodCallOptionsError("callMany.items.options", def.objectId, def.methodId, itemOptions);
|
|
124
|
+
if (optionsError) return Effect.fail(optionsError);
|
|
125
|
+
return Effect.succeed({
|
|
126
|
+
def,
|
|
127
|
+
input,
|
|
128
|
+
options: itemOptions
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
const validateUniqueNodeIds = (operation) => (entries) => validateUniqueTargets(entries, {
|
|
132
|
+
operation,
|
|
133
|
+
target: (entry) => entry.normalized.nodeId,
|
|
134
|
+
duplicateCause: (_target, previousKey) => `duplicate NodeId also used by ${previousKey}`,
|
|
135
|
+
errorContext: (_entry, nodeId) => ({ nodeId })
|
|
136
|
+
});
|
|
137
|
+
const validateBatchOptionsShape = (operation, options, keys = []) => validateOptionsShape(operation, options, [
|
|
138
|
+
...keys,
|
|
139
|
+
"service",
|
|
140
|
+
"serviceLimitsOverrides"
|
|
141
|
+
]);
|
|
142
|
+
const serviceOptions = (options) => options?.service ?? options?.serviceLimitsOverrides;
|
|
143
|
+
const normalizeReadManyOptions = (options, defaults) => Effect.gen(function* () {
|
|
144
|
+
yield* validateBatchOptionsShape("readMany.options", options, ["validation"]);
|
|
145
|
+
if (options?.validation !== void 0 && options.validation !== "strict" && options.validation !== "none") return yield* Effect.fail(configurationError({
|
|
146
|
+
operation: "readMany.options.validation",
|
|
147
|
+
cause: "validation must be \"strict\" or \"none\""
|
|
148
|
+
}));
|
|
149
|
+
const service = yield* normalizeServiceOptions({
|
|
150
|
+
serviceLimits: serviceOptions(options),
|
|
151
|
+
defaults,
|
|
152
|
+
serviceOperation: "readMany.options.service",
|
|
153
|
+
defaultsOperation: "OpcuaSession.batching.read",
|
|
154
|
+
allowedKeys: ["maxNodesPerRequest", "maxConcurrentRequests"],
|
|
155
|
+
fallback: {
|
|
156
|
+
maxNodesPerRequest: 250,
|
|
157
|
+
maxConcurrentRequests: 1
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return {
|
|
161
|
+
validation: options?.validation ?? "strict",
|
|
162
|
+
...service
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
const normalizeWriteManyOptions = (options, defaults) => Effect.gen(function* () {
|
|
166
|
+
yield* validateBatchOptionsShape("writeMany.options", options);
|
|
167
|
+
return yield* normalizeServiceOptions({
|
|
168
|
+
serviceLimits: serviceOptions(options),
|
|
169
|
+
defaults,
|
|
170
|
+
serviceOperation: "writeMany.options.service",
|
|
171
|
+
defaultsOperation: "OpcuaSession.batching.write",
|
|
172
|
+
allowedKeys: ["maxNodesPerRequest", "maxConcurrentRequests"],
|
|
173
|
+
fallback: {
|
|
174
|
+
maxNodesPerRequest: 250,
|
|
175
|
+
maxConcurrentRequests: 1
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
const normalizeCallManyOptions = (options, defaults) => Effect.gen(function* () {
|
|
180
|
+
yield* validateBatchOptionsShape("callMany.options", options);
|
|
181
|
+
return yield* normalizeServiceOptions({
|
|
182
|
+
serviceLimits: serviceOptions(options),
|
|
183
|
+
defaults,
|
|
184
|
+
serviceOperation: "callMany.options.service",
|
|
185
|
+
defaultsOperation: "OpcuaSession.batching.call",
|
|
186
|
+
allowedKeys: ["maxNodesPerRequest", "maxConcurrentRequests"],
|
|
187
|
+
fallback: {
|
|
188
|
+
maxNodesPerRequest: 50,
|
|
189
|
+
maxConcurrentRequests: 1
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
const coerceNodeIdForKey = (operation, key, nodeId) => {
|
|
194
|
+
try {
|
|
195
|
+
return coerceNodeId(nodeId);
|
|
196
|
+
} catch (cause) {
|
|
197
|
+
return configurationError({
|
|
198
|
+
operation,
|
|
199
|
+
key,
|
|
200
|
+
nodeId,
|
|
201
|
+
cause
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const isReadableVariableDef = (value) => isVariableDef(value) && (value.access === "read" || value.access === "readWrite");
|
|
206
|
+
const isWritableVariableDef = (value) => isVariableDef(value) && (value.access === "write" || value.access === "readWrite");
|
|
207
|
+
const isVariableDef = (value) => isPlainRecord(value) && value._tag === "VariableDef" && typeof value.nodeId === "string" && isVariableAccess(value.access) && isPlainRecord(value.codec);
|
|
208
|
+
const isMethodDef = (value) => isPlainRecord(value) && value._tag === "MethodDef" && typeof value.objectId === "string" && typeof value.methodId === "string";
|
|
209
|
+
const isVariableAccess = (value) => value === "read" || value === "write" || value === "readWrite";
|
|
210
|
+
|
|
211
|
+
//#endregion
|
|
212
|
+
export { callManyWithState, readManyWithState, writeManyWithState };
|
|
213
|
+
//# sourceMappingURL=operations.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.mjs","names":["prepared: ReadonlyArray<VariableOperations.PreparedReadVariable>","VariableOperations.readPreparedVariables","VariableOperations.writePreparedVariables","MethodOperations.resolveMethod","MethodOperations.callMethods","OpcuaError.configurationError","MethodArguments.methodCallOptionsError"],"sources":["../../../src/internal/batch/operations.ts"],"sourcesContent":["import { coerceNodeId, type ClientSession, type NodeId } from \"node-opcua\";\nimport { Effect } from \"effect\";\n\nimport * as OpcuaError from \"../../OpcuaError.js\";\nimport * as OpcuaMethod from \"../../OpcuaMethod.js\";\nimport * as OpcuaVariable from \"../../OpcuaVariable.js\";\nimport * as MethodArguments from \"../method/arguments.js\";\nimport * as MethodOperations from \"../method/operations.js\";\nimport * as VariableOperations from \"../variable/operations.js\";\nimport {\n normalizeServiceOptions,\n runKeyedBatchOperation,\n validateOptionsShape,\n validateUniqueTargets,\n type KeyedEntry,\n} from \"./keyed.js\";\nimport { isPlainRecord } from \"../common/predicates.js\";\nimport type { makeMetadataService } from \"../metadata/service.js\";\nimport type { makeStructureRuntime } from \"../structures/runtime.js\";\nimport type { NodeIdString } from \"../common/node-id.js\";\nimport type {\n CallManyOptions,\n ReadManyOptions,\n ServiceOptions,\n ServiceLimits,\n SessionBatchingOptions,\n WriteManyOptions,\n} from \"../../OpcuaSession.js\";\nimport type { MethodCallOptions } from \"../../OpcuaMethod.js\";\nexport type {\n CallManyOptions,\n ReadManyOptions,\n ServiceOptions,\n ServiceLimits,\n SessionBatchingOptions,\n WriteManyOptions,\n} from \"../../OpcuaSession.js\";\nexport type { MethodCallOptions } from \"../../OpcuaMethod.js\";\n\nexport type SessionOperationsState = {\n readonly unsafeRaw: ClientSession;\n readonly metadata: ReturnType<typeof makeMetadataService>;\n readonly structureRuntime: ReturnType<typeof makeStructureRuntime>;\n readonly batching?: SessionBatchingOptions;\n};\n\ntype AnyWriteManyRecord = Record<\n string,\n readonly [OpcuaVariable.WritableVariableDef, unknown]\n>;\n\ntype AnyCallManyRecord = Record<\n string,\n | readonly [OpcuaMethod.AnyMethodDef, unknown]\n | readonly [OpcuaMethod.AnyMethodDef, unknown, MethodCallOptions]\n>;\n\ntype NormalizedReadItem = {\n readonly def: OpcuaVariable.ReadableVariableDef;\n readonly nodeId: NodeIdString;\n readonly rawNodeId: NodeId;\n};\n\ntype NormalizedWriteItem = {\n readonly def: OpcuaVariable.WritableVariableDef;\n readonly value: unknown;\n readonly nodeId: NodeIdString;\n readonly rawNodeId: NodeId;\n};\n\ntype NormalizedCallItem = {\n readonly def: OpcuaMethod.AnyMethodDef;\n readonly input: unknown;\n readonly options?: MethodCallOptions;\n};\n\nexport const readManyWithState = <\n const Items extends Record<string, OpcuaVariable.ReadableVariableDef>,\n>(\n state: SessionOperationsState,\n items: Items,\n options?: ReadManyOptions,\n): Effect.Effect<OpcuaVariable.ReadManyResult<Items>, OpcuaError.OpcuaError> =>\n runKeyedBatchOperation(items, options, state.batching?.readLimits, {\n operation: \"readMany\",\n normalizeOptions: normalizeReadManyOptions,\n normalizeItem: normalizeReadManyItem,\n validateItems: validateUniqueNodeIds(\"readMany.items\"),\n preflight: (entries, normalizedOptions) =>\n Effect.gen(function* () {\n if (normalizedOptions.validation === \"strict\") {\n yield* Effect.forEach(\n entries,\n (entry) => state.metadata.variable(entry.normalized.def),\n { discard: true },\n );\n }\n return entries;\n }),\n execute: (entries, normalizedOptions) => {\n const prepared: ReadonlyArray<VariableOperations.PreparedReadVariable> =\n entries.map((entry) => ({\n def: entry.normalized.def,\n rawNodeId: entry.normalized.rawNodeId,\n }));\n return VariableOperations.readPreparedVariables(\n state.unsafeRaw,\n prepared,\n state.structureRuntime,\n {\n maxItemsPerRequest: normalizedOptions.maxNodesPerRequest,\n maxConcurrentRequests: normalizedOptions.maxConcurrentRequests,\n },\n );\n },\n toPublicResult: (_entry, raw) => Effect.succeed(raw),\n }) as Effect.Effect<\n OpcuaVariable.ReadManyResult<Items>,\n OpcuaError.OpcuaError\n >;\n\nexport const writeManyWithState = <const Items extends AnyWriteManyRecord>(\n state: SessionOperationsState,\n items: Items & OpcuaVariable.WriteManyInput<Items>,\n options?: WriteManyOptions,\n): Effect.Effect<OpcuaVariable.WriteManyResult<Items>, OpcuaError.OpcuaError> =>\n runKeyedBatchOperation(items, options, state.batching?.writeLimits, {\n operation: \"writeMany\",\n normalizeOptions: normalizeWriteManyOptions,\n normalizeItem: normalizeWriteManyItem,\n validateItems: validateUniqueNodeIds(\"writeMany.items\"),\n preflight: (entries) =>\n Effect.forEach(entries, (entry) =>\n Effect.map(\n state.metadata.variable(entry.normalized.def),\n (\n metadata,\n ): KeyedEntry<string, VariableOperations.PreparedWriteVariable> => ({\n key: entry.key,\n index: entry.index,\n normalized: {\n def: entry.normalized.def,\n metadata,\n value: entry.normalized.value,\n rawNodeId: entry.normalized.rawNodeId,\n },\n }),\n ),\n ),\n execute: (entries, normalizedOptions) =>\n VariableOperations.writePreparedVariables(\n state.unsafeRaw,\n entries.map((entry) => entry.normalized),\n state.structureRuntime,\n {\n maxItemsPerRequest: normalizedOptions.maxNodesPerRequest,\n maxConcurrentRequests: normalizedOptions.maxConcurrentRequests,\n },\n ),\n toPublicResult: (_entry, raw) => Effect.succeed(raw),\n }) as Effect.Effect<\n OpcuaVariable.WriteManyResult<Items>,\n OpcuaError.OpcuaError\n >;\n\nexport const callManyWithState = <const Items extends AnyCallManyRecord>(\n state: SessionOperationsState,\n items: Items & OpcuaMethod.CallManyInput<Items>,\n options?: CallManyOptions,\n): Effect.Effect<OpcuaMethod.CallManyResult<Items>, OpcuaError.OpcuaError> =>\n runKeyedBatchOperation(items, options, state.batching?.callLimits, {\n operation: \"callMany\",\n normalizeOptions: normalizeCallManyOptions,\n normalizeItem: normalizeCallManyItem,\n preflight: (entries) =>\n Effect.forEach(entries, (entry) =>\n Effect.gen(function* () {\n const methodMetadata = yield* state.metadata.method(\n entry.normalized.def,\n );\n const method = yield* MethodOperations.resolveMethod(\n entry.normalized.def,\n methodMetadata,\n );\n return {\n key: entry.key,\n index: entry.index,\n normalized: {\n method,\n input: entry.normalized.input,\n options: entry.normalized.options,\n } as OpcuaMethod.MethodCallEntry<OpcuaMethod.AnyResolvedMethod>,\n };\n }),\n ),\n execute: (entries, normalizedOptions) =>\n MethodOperations.callMethods(\n state.unsafeRaw,\n entries.map((entry) => entry.normalized),\n state.structureRuntime,\n {\n maxItemsPerRequest: normalizedOptions.maxNodesPerRequest,\n maxConcurrentRequests: normalizedOptions.maxConcurrentRequests,\n },\n ),\n toPublicResult: (_entry, raw) => Effect.succeed(raw),\n }) as Effect.Effect<OpcuaMethod.CallManyResult<Items>, OpcuaError.OpcuaError>;\n\nconst normalizeReadManyItem = (\n key: string,\n value: OpcuaVariable.ReadableVariableDef,\n): Effect.Effect<NormalizedReadItem, OpcuaError.OpcuaError> =>\n Effect.suspend(() => {\n if (!isReadableVariableDef(value)) {\n return Effect.fail(\n OpcuaError.configurationError({\n operation: \"readMany.items\",\n key,\n cause: \"items must be readable variable definitions\",\n }),\n );\n }\n const rawNodeId = coerceNodeIdForKey(\"readMany.items\", key, value.nodeId);\n if (rawNodeId instanceof Error)\n return Effect.fail(rawNodeId as OpcuaError.OpcuaError);\n return Effect.succeed({\n def: value,\n nodeId: rawNodeId.toString(),\n rawNodeId,\n });\n });\n\nconst normalizeWriteManyItem = (\n key: string,\n tuple: readonly [OpcuaVariable.WritableVariableDef, unknown],\n): Effect.Effect<NormalizedWriteItem, OpcuaError.OpcuaError> =>\n Effect.suspend(() => {\n if (!Array.isArray(tuple) || tuple.length !== 2) {\n return Effect.fail(\n OpcuaError.configurationError({\n operation: \"writeMany.items\",\n key,\n cause: \"write entries must be [definition, value] tuples\",\n }),\n );\n }\n const [def, value] = tuple;\n if (!isWritableVariableDef(def)) {\n return Effect.fail(\n OpcuaError.configurationError({\n operation: \"writeMany.items\",\n key,\n cause: \"write entries must use writable variable definitions\",\n }),\n );\n }\n const rawNodeId = coerceNodeIdForKey(\"writeMany.items\", key, def.nodeId);\n if (rawNodeId instanceof Error)\n return Effect.fail(rawNodeId as OpcuaError.OpcuaError);\n return Effect.succeed({\n def,\n value,\n nodeId: rawNodeId.toString(),\n rawNodeId,\n });\n });\n\nconst normalizeCallManyItem = (\n key: string,\n tuple:\n | readonly [OpcuaMethod.AnyMethodDef, unknown]\n | readonly [OpcuaMethod.AnyMethodDef, unknown, MethodCallOptions],\n): Effect.Effect<NormalizedCallItem, OpcuaError.OpcuaError> =>\n Effect.suspend(() => {\n if (!Array.isArray(tuple) || (tuple.length !== 2 && tuple.length !== 3)) {\n return Effect.fail(\n OpcuaError.configurationError({\n operation: \"callMany.items\",\n key,\n cause:\n \"call entries must be [definition, input] or [definition, input, options] tuples\",\n }),\n );\n }\n const [def, input, itemOptions] = tuple;\n if (!isMethodDef(def)) {\n return Effect.fail(\n OpcuaError.configurationError({\n operation: \"callMany.items\",\n key,\n cause: \"call entries must use method definitions\",\n }),\n );\n }\n const optionsError = MethodArguments.methodCallOptionsError(\n \"callMany.items.options\",\n def.objectId,\n def.methodId,\n itemOptions as MethodCallOptions | undefined,\n );\n if (optionsError) return Effect.fail(optionsError);\n return Effect.succeed({\n def,\n input,\n options: itemOptions as MethodCallOptions | undefined,\n });\n });\n\nconst validateUniqueNodeIds =\n (operation: string) =>\n (\n entries: ReadonlyArray<\n KeyedEntry<string, { readonly nodeId: NodeIdString }>\n >,\n ) =>\n validateUniqueTargets(entries, {\n operation,\n target: (entry) => entry.normalized.nodeId,\n duplicateCause: (_target, previousKey) =>\n `duplicate NodeId also used by ${previousKey}`,\n errorContext: (_entry, nodeId) => ({ nodeId }),\n });\n\nconst validateBatchOptionsShape = (\n operation: string,\n options: ServiceOptions | undefined,\n keys: ReadonlyArray<string> = [],\n) =>\n validateOptionsShape(operation, options, [\n ...keys,\n \"service\",\n \"serviceLimitsOverrides\",\n ]);\n\nconst serviceOptions = (options: ServiceOptions | undefined) =>\n options?.service ?? options?.serviceLimitsOverrides;\n\nconst normalizeReadManyOptions = (\n options: ReadManyOptions | undefined,\n defaults: SessionBatchingOptions[\"readLimits\"] | undefined,\n): Effect.Effect<\n ServiceLimits & { readonly validation: \"strict\" | \"none\" },\n OpcuaError.OpcuaError\n> =>\n Effect.gen(function* () {\n yield* validateBatchOptionsShape(\"readMany.options\", options, [\n \"validation\",\n ]);\n if (\n options?.validation !== undefined &&\n options.validation !== \"strict\" &&\n options.validation !== \"none\"\n ) {\n return yield* Effect.fail(\n OpcuaError.configurationError({\n operation: \"readMany.options.validation\",\n cause: 'validation must be \"strict\" or \"none\"',\n }),\n );\n }\n\n const service = yield* normalizeServiceOptions<\n \"maxNodesPerRequest\" | \"maxConcurrentRequests\"\n >({\n serviceLimits: serviceOptions(options),\n defaults,\n serviceOperation: \"readMany.options.service\",\n defaultsOperation: \"OpcuaSession.batching.read\",\n allowedKeys: [\"maxNodesPerRequest\", \"maxConcurrentRequests\"],\n fallback: {\n maxNodesPerRequest: 250,\n maxConcurrentRequests: 1,\n },\n });\n return {\n validation: options?.validation ?? \"strict\",\n ...service,\n };\n });\n\nconst normalizeWriteManyOptions = (\n options: WriteManyOptions | undefined,\n defaults: SessionBatchingOptions[\"writeLimits\"] | undefined,\n): Effect.Effect<ServiceLimits, OpcuaError.OpcuaError> =>\n Effect.gen(function* () {\n yield* validateBatchOptionsShape(\"writeMany.options\", options);\n return yield* normalizeServiceOptions<\n \"maxNodesPerRequest\" | \"maxConcurrentRequests\"\n >({\n serviceLimits: serviceOptions(options),\n defaults,\n serviceOperation: \"writeMany.options.service\",\n defaultsOperation: \"OpcuaSession.batching.write\",\n allowedKeys: [\"maxNodesPerRequest\", \"maxConcurrentRequests\"],\n fallback: {\n maxNodesPerRequest: 250,\n maxConcurrentRequests: 1,\n },\n });\n });\n\nconst normalizeCallManyOptions = (\n options: CallManyOptions | undefined,\n defaults: SessionBatchingOptions[\"callLimits\"] | undefined,\n): Effect.Effect<ServiceLimits, OpcuaError.OpcuaError> =>\n Effect.gen(function* () {\n yield* validateBatchOptionsShape(\"callMany.options\", options);\n return yield* normalizeServiceOptions<\n \"maxNodesPerRequest\" | \"maxConcurrentRequests\"\n >({\n serviceLimits: serviceOptions(options),\n defaults,\n serviceOperation: \"callMany.options.service\",\n defaultsOperation: \"OpcuaSession.batching.call\",\n allowedKeys: [\"maxNodesPerRequest\", \"maxConcurrentRequests\"],\n fallback: {\n maxNodesPerRequest: 50,\n maxConcurrentRequests: 1,\n },\n });\n });\n\nconst coerceNodeIdForKey = (\n operation: string,\n key: string,\n nodeId: NodeIdString,\n) => {\n try {\n return coerceNodeId(nodeId);\n } catch (cause) {\n return OpcuaError.configurationError({ operation, key, nodeId, cause });\n }\n};\n\nconst isReadableVariableDef = (\n value: unknown,\n): value is OpcuaVariable.ReadableVariableDef =>\n isVariableDef(value) &&\n (value.access === \"read\" || value.access === \"readWrite\");\n\nconst isWritableVariableDef = (\n value: unknown,\n): value is OpcuaVariable.WritableVariableDef =>\n isVariableDef(value) &&\n (value.access === \"write\" || value.access === \"readWrite\");\n\nconst isVariableDef = (value: unknown): value is OpcuaVariable.AnyVariableDef =>\n isPlainRecord(value) &&\n value._tag === \"VariableDef\" &&\n typeof value.nodeId === \"string\" &&\n isVariableAccess(value.access) &&\n isPlainRecord(value.codec);\n\nconst isMethodDef = (value: unknown): value is OpcuaMethod.AnyMethodDef =>\n isPlainRecord(value) &&\n value._tag === \"MethodDef\" &&\n typeof value.objectId === \"string\" &&\n typeof value.methodId === \"string\";\n\nconst isVariableAccess = (\n value: unknown,\n): value is OpcuaVariable.VariableAccess =>\n value === \"read\" || value === \"write\" || value === \"readWrite\";\n"],"mappings":";;;;;;;;;;AA4EA,MAAa,qBAGX,OACA,OACA,YAEA,uBAAuB,OAAO,SAAS,MAAM,UAAU,YAAY;CACjE,WAAW;CACX,kBAAkB;CAClB,eAAe;CACf,eAAe,sBAAsB,iBAAiB;CACtD,YAAY,SAAS,sBACnB,OAAO,IAAI,aAAa;AACtB,MAAI,kBAAkB,eAAe,SACnC,QAAO,OAAO,QACZ,UACC,UAAU,MAAM,SAAS,SAAS,MAAM,WAAW,IAAI,EACxD,EAAE,SAAS,MAAM,CAClB;AAEH,SAAO;GACP;CACJ,UAAU,S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,0BAA0B,qBAAqB,QAAQ;AAC9D,QAAO,OAAO,wBAEZ;EACA,eAAe,eAAe,QAAQ;EACtC;EACA,kBAAkB;EAClB,mBAAmB;EACnB,aAAa,CAAC,sBAAsB,wBAAwB;EAC5D,UAAU;GACR,oBAAoB;GACpB,uBAAuB;GACxB;EACF,CAAC;EACF;AAEJ,MAAM,4BACJ,SACA,aAEA,OAAO,IAAI,aAAa;AACtB,QAAO,0BAA0B,oBAAoB,QAAQ;AAC7D,QAAO,OAAO,wBAEZ;EACA,eAAe,eAAe,QAAQ;EACtC;EACA,kBAAkB;EAClB,mBAAmB;EACnB,aAAa,CAAC,sBAAsB,wBAAwB;EAC5D,UAAU;GACR,oBAAoB;GACpB,uBAAuB;GACxB;EACF,CAAC;EACF;AAEJ,MAAM,sBACJ,WACA,KACA,WACG;AACH,KAAI;AACF,SAAO,aAAa,OAAO;UACpB,OAAO;AACd,SAAOA,mBAA8B;GAAE;GAAW;GAAK;GAAQ;GAAO,CAAC;;;AAI3E,MAAM,yBACJ,UAEA,cAAc,MAAM,KACnB,MAAM,WAAW,UAAU,MAAM,WAAW;AAE/C,MAAM,yBACJ,UAEA,cAAc,MAAM,KACnB,MAAM,WAAW,WAAW,MAAM,WAAW;AAEhD,MAAM,iBAAiB,UACrB,cAAc,MAAM,IACpB,MAAM,SAAS,iBACf,OAAO,MAAM,WAAW,YACxB,iBAAiB,MAAM,OAAO,IAC9B,cAAc,MAAM,MAAM;AAE5B,MAAM,eAAe,UACnB,cAAc,MAAM,IACpB,MAAM,SAAS,eACf,OAAO,MAAM,aAAa,YAC1B,OAAO,MAAM,aAAa;AAE5B,MAAM,oBACJ,UAEA,UAAU,UAAU,UAAU,WAAW,UAAU"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NodeIdString } from "../../OpcuaVariable.mjs";
|
|
2
|
+
import "../common/node-id.mjs";
|
|
3
|
+
import { OpcuaConfigurationError } from "../../OpcuaError.mjs";
|
|
4
|
+
import { OpcuaBrowseChildrenOptions, OpcuaBrowseChildrenResult, OpcuaBrowseContinuation, OpcuaBrowseOptions, OpcuaBrowseReference, OpcuaBrowseResult } from "../../OpcuaSession.mjs";
|
|
5
|
+
import { BrowseDescriptionOptions, BrowseResult, ClientSession, ReferenceDescription } from "node-opcua";
|
|
6
|
+
|
|
7
|
+
//#region src/internal/browse/operations.d.ts
|
|
8
|
+
declare const browseOptionsError: (input: OpcuaBrowseOptions) => OpcuaConfigurationError | undefined;
|
|
9
|
+
declare const browseContinuationError: (operation: string, continuation: OpcuaBrowseContinuation) => OpcuaConfigurationError | undefined;
|
|
10
|
+
declare const browseWithMaxReferences: (session: ClientSession, nodeToBrowse: BrowseDescriptionOptions, maxReferencesPerNode: number) => Promise<BrowseResult>;
|
|
11
|
+
declare const normalizeBrowseResult: (nodeId: NodeIdString, result: BrowseResult, includeRaw: boolean) => OpcuaBrowseResult;
|
|
12
|
+
declare const normalizeBrowseReference: (reference: ReferenceDescription, includeRaw: boolean) => OpcuaBrowseReference;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { type OpcuaBrowseChildrenOptions, type OpcuaBrowseChildrenResult, type OpcuaBrowseContinuation, type OpcuaBrowseOptions, type OpcuaBrowseReference, type OpcuaBrowseResult, browseContinuationError, browseOptionsError, browseWithMaxReferences, normalizeBrowseReference, normalizeBrowseResult };
|
|
15
|
+
//# sourceMappingURL=operations.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.d.mts","names":[],"sources":["../../../src/internal/browse/operations.ts"],"sourcesContent":[],"mappings":";;;;;;;cAiCa,4BAA6B,uBAAkB,uBAAA;cAqB/C,2DAEG,4BAAuB,uBAAA;cAmB1B,mCACF,6BACK,2DAEb,QAAQ;AA9CE,cAwDA,qBAxD6B,EAAA,CAAA,MAAA,EAyDhC,YAzDkD,EAAA,MAAA,EA0DlD,YA1DkD,EAAA,UAAA,EAAA,OAAA,EAAA,GA4DzD,iBA5DyD;AAqB/C,cAiEA,wBA/DG,EAAA,CAAA,SAAA,EAgEH,oBAhE0B,EAAA,UAAA,EAAA,OAAA,EAAA,GAkEpC,oBAlEoC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { isGood, normalizeExpandedNodeId, normalizeLocalizedText, normalizeQualifiedName, normalizeStatusCode } from "../values/normalize.mjs";
|
|
2
|
+
import { configurationError } from "../../OpcuaError.mjs";
|
|
3
|
+
import { nonNegativeIntegerOption } from "../common/options.mjs";
|
|
4
|
+
import { NodeClass } from "node-opcua";
|
|
5
|
+
|
|
6
|
+
//#region src/internal/browse/operations.ts
|
|
7
|
+
const browseOptionsError = (input) => {
|
|
8
|
+
if (input.nodeId.trim() === "") return configurationError({
|
|
9
|
+
operation: "browse",
|
|
10
|
+
nodeId: input.nodeId,
|
|
11
|
+
cause: "nodeId must not be empty"
|
|
12
|
+
});
|
|
13
|
+
if (input.maxReferencesPerNode !== void 0 && !nonNegativeIntegerOption(input.maxReferencesPerNode)) return configurationError({
|
|
14
|
+
operation: "browse",
|
|
15
|
+
nodeId: input.nodeId,
|
|
16
|
+
cause: "maxReferencesPerNode must be a non-negative integer"
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const browseContinuationError = (operation, continuation) => {
|
|
20
|
+
if (continuation.nodeId.trim() === "") return configurationError({
|
|
21
|
+
operation,
|
|
22
|
+
nodeId: continuation.nodeId,
|
|
23
|
+
cause: "nodeId must not be empty"
|
|
24
|
+
});
|
|
25
|
+
if (continuation.unsafeRaw.length === 0) return configurationError({
|
|
26
|
+
operation,
|
|
27
|
+
nodeId: continuation.nodeId,
|
|
28
|
+
cause: "continuation raw buffer must not be empty"
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const browseWithMaxReferences = async (session, nodeToBrowse, maxReferencesPerNode) => {
|
|
32
|
+
const previousMaxReferencesPerNode = session.requestedMaxReferencesPerNode;
|
|
33
|
+
session.requestedMaxReferencesPerNode = maxReferencesPerNode;
|
|
34
|
+
try {
|
|
35
|
+
return await session.browse(nodeToBrowse);
|
|
36
|
+
} finally {
|
|
37
|
+
session.requestedMaxReferencesPerNode = previousMaxReferencesPerNode;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const normalizeBrowseResult = (nodeId, result, includeRaw) => {
|
|
41
|
+
if (!isGood(result.statusCode)) return {
|
|
42
|
+
_tag: "NonGoodStatus",
|
|
43
|
+
nodeId,
|
|
44
|
+
status: normalizeStatusCode(result.statusCode),
|
|
45
|
+
unsafeRaw: includeRaw ? result : void 0
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
_tag: "Browsed",
|
|
49
|
+
nodeId,
|
|
50
|
+
status: normalizeStatusCode(result.statusCode),
|
|
51
|
+
references: result.references?.map((reference) => normalizeBrowseReference(reference, includeRaw)) ?? [],
|
|
52
|
+
continuation: result.continuationPoint && result.continuationPoint.length > 0 ? {
|
|
53
|
+
nodeId,
|
|
54
|
+
unsafeRaw: result.continuationPoint
|
|
55
|
+
} : void 0,
|
|
56
|
+
unsafeRaw: includeRaw ? result : void 0
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const normalizeBrowseReference = (reference, includeRaw) => ({
|
|
60
|
+
nodeId: normalizeExpandedNodeId(reference.nodeId),
|
|
61
|
+
referenceTypeId: reference.referenceTypeId?.toString(),
|
|
62
|
+
isForward: reference.isForward,
|
|
63
|
+
nodeClass: typeof reference.nodeClass === "number" ? NodeClass[reference.nodeClass] : void 0,
|
|
64
|
+
browseName: reference.browseName ? normalizeQualifiedName(reference.browseName) : void 0,
|
|
65
|
+
displayName: reference.displayName ? normalizeLocalizedText(reference.displayName) : void 0,
|
|
66
|
+
typeDefinition: reference.typeDefinition ? normalizeExpandedNodeId(reference.typeDefinition) : void 0,
|
|
67
|
+
unsafeRaw: includeRaw ? reference : void 0
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { browseContinuationError, browseOptionsError, browseWithMaxReferences, normalizeBrowseReference, normalizeBrowseResult };
|
|
72
|
+
//# sourceMappingURL=operations.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.mjs","names":[],"sources":["../../../src/internal/browse/operations.ts"],"sourcesContent":["import {\n NodeClass,\n type BrowseDescriptionOptions,\n type BrowseResult,\n type ClientSession,\n type ReferenceDescription,\n} from \"node-opcua\";\n\nimport { configurationError } from \"../../OpcuaError.js\";\nimport type {\n OpcuaBrowseContinuation,\n OpcuaBrowseOptions,\n OpcuaBrowseReference,\n OpcuaBrowseResult,\n} from \"../../OpcuaSession.js\";\nimport {\n isGood,\n normalizeExpandedNodeId,\n normalizeLocalizedText,\n normalizeQualifiedName,\n normalizeStatusCode,\n} from \"../values/normalize.js\";\nimport type { NodeIdString } from \"../common/node-id.js\";\nimport { nonNegativeIntegerOption } from \"../common/options.js\";\nexport type {\n OpcuaBrowseChildrenOptions,\n OpcuaBrowseChildrenResult,\n OpcuaBrowseContinuation,\n OpcuaBrowseOptions,\n OpcuaBrowseReference,\n OpcuaBrowseResult,\n} from \"../../OpcuaSession.js\";\n\nexport const browseOptionsError = (input: OpcuaBrowseOptions) => {\n if (input.nodeId.trim() === \"\") {\n return configurationError({\n operation: \"browse\",\n nodeId: input.nodeId,\n cause: \"nodeId must not be empty\",\n });\n }\n if (\n input.maxReferencesPerNode !== undefined &&\n !nonNegativeIntegerOption(input.maxReferencesPerNode)\n ) {\n return configurationError({\n operation: \"browse\",\n nodeId: input.nodeId,\n cause: \"maxReferencesPerNode must be a non-negative integer\",\n });\n }\n return undefined;\n};\n\nexport const browseContinuationError = (\n operation: string,\n continuation: OpcuaBrowseContinuation,\n) => {\n if (continuation.nodeId.trim() === \"\") {\n return configurationError({\n operation,\n nodeId: continuation.nodeId,\n cause: \"nodeId must not be empty\",\n });\n }\n if (continuation.unsafeRaw.length === 0) {\n return configurationError({\n operation,\n nodeId: continuation.nodeId,\n cause: \"continuation raw buffer must not be empty\",\n });\n }\n return undefined;\n};\n\nexport const browseWithMaxReferences = async (\n session: ClientSession,\n nodeToBrowse: BrowseDescriptionOptions,\n maxReferencesPerNode: number,\n): Promise<BrowseResult> => {\n const previousMaxReferencesPerNode = session.requestedMaxReferencesPerNode;\n session.requestedMaxReferencesPerNode = maxReferencesPerNode;\n try {\n return await session.browse(nodeToBrowse);\n } finally {\n session.requestedMaxReferencesPerNode = previousMaxReferencesPerNode;\n }\n};\n\nexport const normalizeBrowseResult = (\n nodeId: NodeIdString,\n result: BrowseResult,\n includeRaw: boolean,\n): OpcuaBrowseResult => {\n if (!isGood(result.statusCode)) {\n return {\n _tag: \"NonGoodStatus\",\n nodeId,\n status: normalizeStatusCode(result.statusCode),\n unsafeRaw: includeRaw ? result : undefined,\n };\n }\n\n return {\n _tag: \"Browsed\",\n nodeId,\n status: normalizeStatusCode(result.statusCode),\n references:\n result.references?.map((reference) =>\n normalizeBrowseReference(reference, includeRaw),\n ) ?? [],\n continuation:\n result.continuationPoint && result.continuationPoint.length > 0\n ? { nodeId, unsafeRaw: result.continuationPoint }\n : undefined,\n unsafeRaw: includeRaw ? result : undefined,\n };\n};\n\nexport const normalizeBrowseReference = (\n reference: ReferenceDescription,\n includeRaw: boolean,\n): OpcuaBrowseReference => ({\n nodeId: normalizeExpandedNodeId(reference.nodeId),\n referenceTypeId: reference.referenceTypeId?.toString(),\n isForward: reference.isForward,\n nodeClass:\n typeof reference.nodeClass === \"number\"\n ? NodeClass[reference.nodeClass]\n : undefined,\n browseName: reference.browseName\n ? normalizeQualifiedName(reference.browseName)\n : undefined,\n displayName: reference.displayName\n ? normalizeLocalizedText(reference.displayName)\n : undefined,\n typeDefinition: reference.typeDefinition\n ? normalizeExpandedNodeId(reference.typeDefinition)\n : undefined,\n unsafeRaw: includeRaw ? reference : undefined,\n});\n"],"mappings":";;;;;;AAiCA,MAAa,sBAAsB,UAA8B;AAC/D,KAAI,MAAM,OAAO,MAAM,KAAK,GAC1B,QAAO,mBAAmB;EACxB,WAAW;EACX,QAAQ,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nB,uBAAuB,UAAU,YAAY,GAC7C;CACJ,gBAAgB,UAAU,iBACtB,wBAAwB,UAAU,eAAe,GACjD;CACJ,WAAW,aAAa,YAAY;CACrC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OpcuaClientEvent } from "../events/model.mjs";
|
|
2
|
+
import { OpcuaConnectError } from "../../OpcuaError.mjs";
|
|
3
|
+
import { ClientLayerOptions } from "../../OpcuaClient.mjs";
|
|
4
|
+
import * as node_opcua0 from "node-opcua";
|
|
5
|
+
import { OPCUAClient } from "node-opcua";
|
|
6
|
+
import { Effect, Stream } from "effect";
|
|
7
|
+
import * as effect_Scope1 from "effect/Scope";
|
|
8
|
+
|
|
9
|
+
//#region src/internal/client/make.d.ts
|
|
10
|
+
declare const makeClientService: (options: ClientLayerOptions) => Effect.Effect<{
|
|
11
|
+
events: Stream.Stream<OpcuaClientEvent, never, never>;
|
|
12
|
+
unsafeRawClient: OPCUAClient<node_opcua0.OPCUAClientBaseEvents>;
|
|
13
|
+
}, OpcuaConnectError, effect_Scope1.Scope>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { makeClientService };
|
|
16
|
+
//# sourceMappingURL=make.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make.d.mts","names":[],"sources":["../../../src/internal/client/make.ts"],"sourcesContent":[],"mappings":";;;;;;;;;cASa,6BAAiB,uBAAA,MAAA,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { connectError, disconnectError } from "../../OpcuaError.mjs";
|
|
2
|
+
import { EventBus, wireClientEvents } from "../events/wire.mjs";
|
|
3
|
+
import { EVENT_BUFFER_SIZE } from "../common/constants.mjs";
|
|
4
|
+
import { OPCUAClient } from "node-opcua";
|
|
5
|
+
import { Effect, PubSub, Stream } from "effect";
|
|
6
|
+
|
|
7
|
+
//#region src/internal/client/make.ts
|
|
8
|
+
const makeClientService = Effect.fnUntraced(function* (options) {
|
|
9
|
+
const events = yield* PubSub.sliding({
|
|
10
|
+
capacity: EVENT_BUFFER_SIZE,
|
|
11
|
+
replay: 1
|
|
12
|
+
});
|
|
13
|
+
yield* Effect.addFinalizer(() => PubSub.shutdown(events));
|
|
14
|
+
const unsafeRawClient = yield* Effect.try({
|
|
15
|
+
try: () => OPCUAClient.create(options.clientOptions ?? {}),
|
|
16
|
+
catch: (cause) => connectError({
|
|
17
|
+
endpointUrl: options.endpointUrl,
|
|
18
|
+
cause
|
|
19
|
+
})
|
|
20
|
+
});
|
|
21
|
+
yield* wireClientEvents(unsafeRawClient, events);
|
|
22
|
+
yield* Effect.acquireRelease(Effect.tryPromise({
|
|
23
|
+
try: async (signal) => {
|
|
24
|
+
let disconnectAfterAbort;
|
|
25
|
+
const disconnectOnAbort = () => {
|
|
26
|
+
disconnectAfterAbort ??= unsafeRawClient.disconnect().catch(() => void 0);
|
|
27
|
+
};
|
|
28
|
+
signal.addEventListener("abort", disconnectOnAbort, { once: true });
|
|
29
|
+
try {
|
|
30
|
+
await unsafeRawClient.connect(options.endpointUrl);
|
|
31
|
+
if (signal.aborted) {
|
|
32
|
+
disconnectOnAbort();
|
|
33
|
+
await disconnectAfterAbort;
|
|
34
|
+
throw new Error("Connection aborted");
|
|
35
|
+
}
|
|
36
|
+
EventBus.publishUnsafe(events, {
|
|
37
|
+
_tag: "Connected",
|
|
38
|
+
endpointUrl: options.endpointUrl
|
|
39
|
+
});
|
|
40
|
+
return unsafeRawClient;
|
|
41
|
+
} finally {
|
|
42
|
+
signal.removeEventListener("abort", disconnectOnAbort);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
catch: (cause) => connectError({
|
|
46
|
+
endpointUrl: options.endpointUrl,
|
|
47
|
+
cause
|
|
48
|
+
})
|
|
49
|
+
}).pipe(Effect.withSpan("opcua.connect", {
|
|
50
|
+
attributes: { "opcua.endpoint_url": options.endpointUrl },
|
|
51
|
+
kind: "client"
|
|
52
|
+
})), () => Effect.tryPromise({
|
|
53
|
+
try: async () => {
|
|
54
|
+
await unsafeRawClient.disconnect();
|
|
55
|
+
EventBus.publishUnsafe(events, {
|
|
56
|
+
_tag: "Disconnected",
|
|
57
|
+
endpointUrl: options.endpointUrl
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
catch: (cause) => disconnectError({
|
|
61
|
+
endpointUrl: options.endpointUrl,
|
|
62
|
+
cause
|
|
63
|
+
})
|
|
64
|
+
}).pipe(Effect.withSpan("opcua.disconnect", {
|
|
65
|
+
attributes: { "opcua.endpoint_url": options.endpointUrl },
|
|
66
|
+
kind: "client"
|
|
67
|
+
}), Effect.ignore));
|
|
68
|
+
return {
|
|
69
|
+
events: Stream.fromPubSub(events),
|
|
70
|
+
unsafeRawClient
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { makeClientService };
|
|
76
|
+
//# sourceMappingURL=make.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make.mjs","names":["OpcuaError.connectError","disconnectAfterAbort: Promise<void> | undefined","OpcuaError.disconnectError"],"sources":["../../../src/internal/client/make.ts"],"sourcesContent":["import { OPCUAClient } from \"node-opcua\";\nimport { Effect, PubSub, Stream } from \"effect\";\n\nimport * as OpcuaError from \"../../OpcuaError.js\";\nimport type { ClientLayerOptions, ClientService } from \"../../OpcuaClient.js\";\nimport { EVENT_BUFFER_SIZE } from \"../common/constants.js\";\nimport { EventBus, wireClientEvents } from \"../events/wire.js\";\nimport type { OpcuaClientEvent } from \"../events/model.js\";\n\nexport const makeClientService = Effect.fnUntraced(function* (\n options: ClientLayerOptions,\n) {\n const events = yield* PubSub.sliding<OpcuaClientEvent>({\n capacity: EVENT_BUFFER_SIZE,\n replay: 1,\n });\n yield* Effect.addFinalizer(() => PubSub.shutdown(events));\n\n const unsafeRawClient = yield* Effect.try({\n try: () => OPCUAClient.create(options.clientOptions ?? {}),\n catch: (cause) =>\n OpcuaError.connectError({ endpointUrl: options.endpointUrl, cause }),\n });\n yield* wireClientEvents(unsafeRawClient, events);\n yield* Effect.acquireRelease(\n Effect.tryPromise({\n try: async (signal) => {\n let disconnectAfterAbort: Promise<void> | undefined;\n const disconnectOnAbort = () => {\n disconnectAfterAbort ??= unsafeRawClient\n .disconnect()\n .catch(() => undefined);\n };\n\n signal.addEventListener(\"abort\", disconnectOnAbort, { once: true });\n try {\n await unsafeRawClient.connect(options.endpointUrl);\n if (signal.aborted) {\n disconnectOnAbort();\n await disconnectAfterAbort;\n throw new Error(\"Connection aborted\");\n }\n EventBus.publishUnsafe(events, {\n _tag: \"Connected\",\n endpointUrl: options.endpointUrl,\n });\n return unsafeRawClient;\n } finally {\n signal.removeEventListener(\"abort\", disconnectOnAbort);\n }\n },\n catch: (cause) =>\n OpcuaError.connectError({\n endpointUrl: options.endpointUrl,\n cause,\n }),\n }).pipe(\n Effect.withSpan(\"opcua.connect\", {\n attributes: { \"opcua.endpoint_url\": options.endpointUrl },\n kind: \"client\",\n }),\n ),\n () =>\n Effect.tryPromise({\n try: async () => {\n await unsafeRawClient.disconnect();\n EventBus.publishUnsafe(events, {\n _tag: \"Disconnected\",\n endpointUrl: options.endpointUrl,\n });\n },\n catch: (cause) =>\n OpcuaError.disconnectError({\n endpointUrl: options.endpointUrl,\n cause,\n }),\n }).pipe(\n Effect.withSpan(\"opcua.disconnect\", {\n attributes: { \"opcua.endpoint_url\": options.endpointUrl },\n kind: \"client\",\n }),\n Effect.ignore,\n ),\n );\n return {\n events: Stream.fromPubSub(events),\n unsafeRawClient,\n } satisfies ClientService;\n});\n"],"mappings":";;;;;;;AASA,MAAa,oBAAoB,OAAO,WAAW,WACjD,SACA;CACA,MAAM,SAAS,OAAO,OAAO,QAA0B;EACrD,UAAU;EACV,QAAQ;EACT,CAAC;AACF,QAAO,OAAO,mBAAmB,OAAO,SAAS,OAAO,CAAC;CAEzD,MAAM,kBAAkB,OAAO,OAAO,IAAI;EACxC,WAAW,YAAY,OAAO,QAAQ,iBAA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cesContent":[],"mappings":";cAAa,qBACJ,cAAc,qBAEpB,cAAc,cAAc"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/internal/common/collections.ts
|
|
2
|
+
const chunksOf = (items, size) => {
|
|
3
|
+
const chunks = [];
|
|
4
|
+
for (let index = 0; index < items.length; index += size) chunks.push(items.slice(index, index + size));
|
|
5
|
+
return chunks;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { chunksOf };
|
|
10
|
+
//# sourceMappingURL=collections.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.mjs","names":["chunks: Array<ReadonlyArray<A>>"],"sources":["../../../src/internal/common/collections.ts"],"sourcesContent":["export const chunksOf = <A>(\n items: ReadonlyArray<A>,\n size: number,\n): ReadonlyArray<ReadonlyArray<A>> => {\n const chunks: Array<ReadonlyArray<A>> = [];\n for (let index = 0; index < items.length; index += size) {\n chunks.push(items.slice(index, index + size));\n }\n return chunks;\n};\n"],"mappings":";AAAA,MAAa,YACX,OACA,SACoC;CACpC,MAAMA,SAAkC,EAAE;AAC1C,MAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,KACjD,QAAO,KAAK,MAAM,MAAM,OAAO,QAAQ,KAAK,CAAC;AAE/C,QAAO"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as node_opcua1 from "node-opcua";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/common/constants.d.ts
|
|
4
|
+
declare const EVENT_BUFFER_SIZE = 256;
|
|
5
|
+
declare const DEFAULT_LIFETIME_COUNT = 60;
|
|
6
|
+
declare const DEFAULT_MAX_KEEP_ALIVE_COUNT = 10;
|
|
7
|
+
declare const DEFAULT_MAX_NOTIFICATIONS_PER_PUBLISH = 0;
|
|
8
|
+
declare const DEFAULT_PUBLISHING_ENABLED = true;
|
|
9
|
+
declare const DEFAULT_PRIORITY = 0;
|
|
10
|
+
declare const DEFAULT_BROWSE_REFERENCE_TYPE_ID = "HierarchicalReferences";
|
|
11
|
+
declare const DEFAULT_BROWSE_DIRECTION = BrowseDirection.Forward;
|
|
12
|
+
declare const DEFAULT_BROWSE_INCLUDE_SUBTYPES = true;
|
|
13
|
+
declare const DEFAULT_BROWSE_NODE_CLASS_MASK = 0;
|
|
14
|
+
declare const DEFAULT_BROWSE_RESULT_MASK: node_opcua1.ResultMask;
|
|
15
|
+
declare const DEFAULT_BROWSE_MAX_REFERENCES_PER_NODE = 0;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { DEFAULT_BROWSE_DIRECTION, DEFAULT_BROWSE_INCLUDE_SUBTYPES, DEFAULT_BROWSE_MAX_REFERENCES_PER_NODE, DEFAULT_BROWSE_NODE_CLASS_MASK, DEFAULT_BROWSE_REFERENCE_TYPE_ID, DEFAULT_BROWSE_RESULT_MASK, DEFAULT_LIFETIME_COUNT, DEFAULT_MAX_KEEP_ALIVE_COUNT, DEFAULT_MAX_NOTIFICATIONS_PER_PUBLISH, DEFAULT_PRIORITY, DEFAULT_PUBLISHING_ENABLED, EVENT_BUFFER_SIZE };
|
|
18
|
+
//# sourceMappingURL=constants.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.mts","names":[],"sources":["../../../src/internal/common/constants.ts"],"sourcesContent":[],"mappings":";;;cAEa,iBAAA;cACA,sBAAA;AADA,cAEA,4BAAA,GAFiB,EAAA;AACjB,cAEA,qCAAA,GAFsB,CAAA;AACtB,cAEA,0BAAA,GAF4B,IAAA;AAC5B,cAEA,gBAAA,GAFA,CAAA;AACA,cAEA,gCAAA,GAF0B,wBAAA;AAC1B,cAEA,wBAAA,GAFgB,eAAA,CAAA,OAAA;AAChB,cAEA,+BAAA,GAFgC,IAAA;AAChC,cAEA,8BAAA,GAFwB,CAAA;AACxB,cAEA,0BAF+B,EAI3C,WAAA,CAFsC,UAFK;AAC/B,cAIA,sCAAA,GAJ8B,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BrowseDirection, makeResultMask } from "node-opcua";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/common/constants.ts
|
|
4
|
+
const EVENT_BUFFER_SIZE = 256;
|
|
5
|
+
const DEFAULT_LIFETIME_COUNT = 60;
|
|
6
|
+
const DEFAULT_MAX_KEEP_ALIVE_COUNT = 10;
|
|
7
|
+
const DEFAULT_MAX_NOTIFICATIONS_PER_PUBLISH = 0;
|
|
8
|
+
const DEFAULT_PUBLISHING_ENABLED = true;
|
|
9
|
+
const DEFAULT_PRIORITY = 0;
|
|
10
|
+
const DEFAULT_BROWSE_REFERENCE_TYPE_ID = "HierarchicalReferences";
|
|
11
|
+
const DEFAULT_BROWSE_DIRECTION = BrowseDirection.Forward;
|
|
12
|
+
const DEFAULT_BROWSE_INCLUDE_SUBTYPES = true;
|
|
13
|
+
const DEFAULT_BROWSE_NODE_CLASS_MASK = 0;
|
|
14
|
+
const DEFAULT_BROWSE_RESULT_MASK = makeResultMask("ReferenceType | IsForward | NodeClass | BrowseName | DisplayName | TypeDefinition");
|
|
15
|
+
const DEFAULT_BROWSE_MAX_REFERENCES_PER_NODE = 0;
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { DEFAULT_BROWSE_DIRECTION, DEFAULT_BROWSE_INCLUDE_SUBTYPES, DEFAULT_BROWSE_MAX_REFERENCES_PER_NODE, DEFAULT_BROWSE_NODE_CLASS_MASK, DEFAULT_BROWSE_REFERENCE_TYPE_ID, DEFAULT_BROWSE_RESULT_MASK, DEFAULT_LIFETIME_COUNT, DEFAULT_MAX_KEEP_ALIVE_COUNT, DEFAULT_MAX_NOTIFICATIONS_PER_PUBLISH, DEFAULT_PRIORITY, DEFAULT_PUBLISHING_ENABLED, EVENT_BUFFER_SIZE };
|
|
19
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../../src/internal/common/constants.ts"],"sourcesContent":["import { BrowseDirection, makeResultMask } from \"node-opcua\";\n\nexport const EVENT_BUFFER_SIZE = 256;\nexport const DEFAULT_LIFETIME_COUNT = 60;\nexport const DEFAULT_MAX_KEEP_ALIVE_COUNT = 10;\nexport const DEFAULT_MAX_NOTIFICATIONS_PER_PUBLISH = 0;\nexport const DEFAULT_PUBLISHING_ENABLED = true;\nexport const DEFAULT_PRIORITY = 0;\nexport const DEFAULT_BROWSE_REFERENCE_TYPE_ID = \"HierarchicalReferences\";\nexport const DEFAULT_BROWSE_DIRECTION = BrowseDirection.Forward;\nexport const DEFAULT_BROWSE_INCLUDE_SUBTYPES = true;\nexport const DEFAULT_BROWSE_NODE_CLASS_MASK = 0;\nexport const DEFAULT_BROWSE_RESULT_MASK = makeResultMask(\n \"ReferenceType | IsForward | NodeClass | BrowseName | DisplayName | TypeDefinition\",\n);\nexport const DEFAULT_BROWSE_MAX_REFERENCES_PER_NODE = 0;\n"],"mappings":";;;AAEA,MAAa,oBAAoB;AACjC,MAAa,yBAAyB;AACtC,MAAa,+BAA+B;AAC5C,MAAa,wCAAwC;AACrD,MAAa,6BAA6B;AAC1C,MAAa,mBAAmB;AAChC,MAAa,mCAAmC;AAChD,MAAa,2BAA2B,gBAAgB;AACxD,MAAa,kCAAkC;AAC/C,MAAa,iCAAiC;AAC9C,MAAa,6BAA6B,eACxC,oFACD;AACD,MAAa,yCAAyC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Duration } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/common/options.d.ts
|
|
4
|
+
declare const unknownKeys: (value: Record<string, unknown>, allowedKeys: Iterable<string>) => ReadonlyArray<string>;
|
|
5
|
+
declare const positiveIntegerOption: (value: unknown) => value is number;
|
|
6
|
+
declare const nonNegativeIntegerOption: (value: unknown) => value is number;
|
|
7
|
+
declare const positiveIntegerOrDefault: (value: number | undefined, fallback: number) => number;
|
|
8
|
+
declare const durationToMillis: (duration: Duration.Duration, options: {
|
|
9
|
+
readonly notDuration: string;
|
|
10
|
+
readonly invalidDuration: string;
|
|
11
|
+
}) => string | number;
|
|
12
|
+
declare const stringUnionOption: <Value extends string>(value: unknown, allowed: ReadonlyArray<Value>) => value is Value;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { durationToMillis, nonNegativeIntegerOption, positiveIntegerOption, positiveIntegerOrDefault, stringUnionOption, unknownKeys };
|
|
15
|
+
//# sourceMappingURL=options.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.mts","names":[],"sources":["../../../src/internal/common/options.ts"],"sourcesContent":[],"mappings":";;;cAIa,qBACJ,sCACM,qBACZ;cAKU;AARA,cAWA,wBALZ,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,KAAA,IAAA,MAAA;AALQ,cAaI,wBAbJ,EAAA,CAAA,KAAA,EAAA,MAAA,GAAA,SAAA,EAAA,QAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AACM,cAiBF,gBAjBE,EAAA,CAAA,QAAA,EAkBH,QAAA,CAAS,QAlBN,EAAA,OAAA,EAAA;EACZ,SAAA,WAAA,EAAA,MAAA;EAAa,SAAA,eAAA,EAAA,MAAA;AAKhB,CAAA,EAAA,GAAa,MAAA,GAAA,MAAA;AAGA,cAqBA,iBApBc,EAAA,CAAA,cAAA,MAAA,CAAA,CAAA,KAAA,EAAA,OAAA,EAAA,OAAA,EAsBhB,aAtBgB,CAsBF,KAtBE,CAAA,EAAA,GAAA,KAAA,IAuBf,KAvBe"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { nonNegativeInteger, positiveInteger } from "./predicates.mjs";
|
|
2
|
+
import { Duration } from "effect";
|
|
3
|
+
|
|
4
|
+
//#region src/internal/common/options.ts
|
|
5
|
+
const unknownKeys = (value, allowedKeys) => {
|
|
6
|
+
const allowed = new Set(allowedKeys);
|
|
7
|
+
return Object.keys(value).filter((key) => !allowed.has(key));
|
|
8
|
+
};
|
|
9
|
+
const positiveIntegerOption = (value) => positiveInteger(value);
|
|
10
|
+
const nonNegativeIntegerOption = (value) => nonNegativeInteger(value);
|
|
11
|
+
const positiveIntegerOrDefault = (value, fallback) => positiveInteger(value) ? Math.floor(value) : fallback;
|
|
12
|
+
const durationToMillis = (duration, options) => {
|
|
13
|
+
if (!Duration.isDuration(duration)) return options.notDuration;
|
|
14
|
+
const millis = Duration.toMillis(duration);
|
|
15
|
+
if (!Number.isFinite(millis) || millis < 0) return options.invalidDuration;
|
|
16
|
+
return millis;
|
|
17
|
+
};
|
|
18
|
+
const stringUnionOption = (value, allowed) => allowed.includes(value);
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { durationToMillis, nonNegativeIntegerOption, positiveIntegerOption, positiveIntegerOrDefault, stringUnionOption, unknownKeys };
|
|
22
|
+
//# sourceMappingURL=options.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.mjs","names":[],"sources":["../../../src/internal/common/options.ts"],"sourcesContent":["import { Duration } from \"effect\";\n\nimport { nonNegativeInteger, positiveInteger } from \"./predicates.js\";\n\nexport const unknownKeys = (\n value: Record<string, unknown>,\n allowedKeys: Iterable<string>,\n): ReadonlyArray<string> => {\n const allowed = new Set(allowedKeys);\n return Object.keys(value).filter((key) => !allowed.has(key));\n};\n\nexport const positiveIntegerOption = (value: unknown): value is number =>\n positiveInteger(value);\n\nexport const nonNegativeIntegerOption = (value: unknown): value is number =>\n nonNegativeInteger(value);\n\nexport const positiveIntegerOrDefault = (\n value: number | undefined,\n fallback: number,\n) => (positiveInteger(value) ? Math.floor(value) : fallback);\n\nexport const durationToMillis = (\n duration: Duration.Duration,\n options: {\n readonly notDuration: string;\n readonly invalidDuration: string;\n },\n) => {\n if (!Duration.isDuration(duration)) return options.notDuration;\n const millis = Duration.toMillis(duration);\n if (!Number.isFinite(millis) || millis < 0) return options.invalidDuration;\n return millis;\n};\n\nexport const stringUnionOption = <Value extends string>(\n value: unknown,\n allowed: ReadonlyArray<Value>,\n): value is Value => allowed.includes(value as Value);\n"],"mappings":";;;;AAIA,MAAa,eACX,OACA,gBAC0B;CAC1B,MAAM,UAAU,IAAI,IAAI,YAAY;AACpC,QAAO,OAAO,KAAK,MAAM,CAAC,QAAQ,QAAQ,CAAC,QAAQ,IAAI,IAAI,CAAC;;AAG9D,MAAa,yBAAyB,UACpC,gBAAgB,MAAM;AAExB,MAAa,4BAA4B,UACvC,mBAAmB,MAAM;AAE3B,MAAa,4BACX,OACA,aACI,gBAAgB,MAAM,GAAG,KAAK,MAAM,MAAM,GAAG;AAEnD,MAAa,oBACX,UACA,YAIG;AACH,KAAI,CAAC,SAAS,WAAW,SAAS,CAAE,QAAO,QAAQ;CACnD,MAAM,SAAS,SAAS,SAAS,SAAS;AAC1C,KAAI,CAAC,OAAO,SAAS,OAAO,IAAI,SAAS,EAAG,QAAO,QAAQ;AAC3D,QAAO;;AAGT,MAAa,qBACX,OACA,YACmB,QAAQ,SAAS,MAAe"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/internal/common/predicates.d.ts
|
|
2
|
+
declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
3
|
+
declare const isPlainRecord: (value: unknown) => value is Record<string, unknown>;
|
|
4
|
+
declare const positiveInteger: (value: unknown) => value is number;
|
|
5
|
+
declare const nonNegativeInteger: (value: unknown) => value is number;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isPlainRecord, isRecord, nonNegativeInteger, positiveInteger };
|
|
8
|
+
//# sourceMappingURL=predicates.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicates.d.mts","names":[],"sources":["../../../src/internal/common/predicates.ts"],"sourcesContent":[],"mappings":";cAAa,uCAAsC;AAAtC,cAGA,aAHsC,EAAM,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,KAAA,IAK7C,MAL6C,CAAA,MAAA,EAAA,OAAA,CAAA;AAG5C,cAQA,eAND,EAAA,CAAA,KAAM,EAAA,OAAA,EAAA,GAAA,KAAA,IAAA,MAAA;AAML,cAMA,kBAFF,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,KAAA,IAAA,MAAA"}
|