@tsplc/opcua 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # @tsplc/opcua
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Part of [tsPLC](https://github.com/livingforjesus/tsplc).
4
+
5
+ Typed OPC UA access to a running tsPLC program: `createPlc` reads and writes its published globals by path, typed from the program's own declarations, and `createMachineClient` reads machine telemetry. The generated contract (`@tsplc/opcua/contract`) describes what a build published.
6
+
7
+ See the [documentation](https://github.com/livingforjesus/tsplc/tree/main/docs). MIT licensed.
@@ -0,0 +1,32 @@
1
+ // packages/opcua/src/contract.ts
2
+ var contractVariables = (contract, published) => {
3
+ const selected = published && new Set(published);
4
+ return contract.symbols.filter((symbol) => !selected || selected.has(`${symbol.gvl}.${symbol.name}`)).flatMap((symbol) => {
5
+ const fields = contract.typeFields[symbol.type];
6
+ if (!fields && symbol.type.startsWith("ARRAY["))
7
+ return [
8
+ {
9
+ description: "",
10
+ device: symbol.name,
11
+ field: "",
12
+ path: `${symbol.gvl}.${symbol.name}`,
13
+ type: symbol.type
14
+ }
15
+ ];
16
+ if (!fields)
17
+ throw new Error(`Missing generated fields for ${symbol.type}.`);
18
+ return fields.map(({ field, type, description }) => ({
19
+ description,
20
+ device: symbol.name,
21
+ field,
22
+ path: `${symbol.gvl}.${symbol.name}${field.startsWith("[") ? "" : "."}${field}`,
23
+ type
24
+ }));
25
+ });
26
+ };
27
+ export {
28
+ contractVariables
29
+ };
30
+
31
+ //# debugId=080E88B866BC96AE64756E2164756E21
32
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/contract.ts"],
4
+ "sourcesContent": [
5
+ "/** The generated symbol tables from `tsplc typegen` (`symbols` and `typeFields`). */\nexport interface PlcContract {\n symbols: ReadonlyArray<{ name: string; gvl: string; type: string }>;\n typeFields: Readonly<\n Record<string, ReadonlyArray<{ field: string; type: string; description: string }>>\n >;\n}\n\n/** Dotted leaf paths of a record, with `[${number}]` for record arrays. */\nexport type FieldPath<T> = {\n [K in keyof T & string]: T[K] extends ReadonlyArray<infer Item>\n ? Item extends object\n ? `${K}[${number}].${FieldPath<Item>}`\n : K\n : T[K] extends object\n ? `${K}.${FieldPath<T[K]>}`\n : K;\n}[keyof T & string];\n\n/** Every leaf variable of the contract's symbols, optionally only the published symbols. */\nexport const contractVariables = (contract: PlcContract, published?: readonly string[]) => {\n const selected = published && new Set(published);\n return contract.symbols\n .filter((symbol) => !selected || selected.has(`${symbol.gvl}.${symbol.name}`))\n .flatMap((symbol) => {\n const fields = contract.typeFields[symbol.type];\n // An array global, such as a service channel's slots, is read and written whole.\n if (!fields && symbol.type.startsWith(\"ARRAY[\"))\n return [\n {\n description: \"\",\n device: symbol.name,\n field: \"\",\n path: `${symbol.gvl}.${symbol.name}`,\n type: symbol.type,\n },\n ];\n if (!fields) throw new Error(`Missing generated fields for ${symbol.type}.`);\n return fields.map(({ field, type, description }) => ({\n description,\n device: symbol.name,\n field,\n // An array type's fields start at an element, such as `[3].Enabled`.\n path: `${symbol.gvl}.${symbol.name}${field.startsWith(\"[\") ? \"\" : \".\"}${field}`,\n type,\n }));\n });\n};\n"
6
+ ],
7
+ "mappings": ";AAoBO,IAAM,oBAAoB,CAAC,UAAuB,cAAkC;AAAA,EACzF,MAAM,WAAW,aAAa,IAAI,IAAI,SAAS;AAAA,EAC/C,OAAO,SAAS,QACb,OAAO,CAAC,WAAW,CAAC,YAAY,SAAS,IAAI,GAAG,OAAO,OAAO,OAAO,MAAM,CAAC,EAC5E,QAAQ,CAAC,WAAW;AAAA,IACnB,MAAM,SAAS,SAAS,WAAW,OAAO;AAAA,IAE1C,IAAI,CAAC,UAAU,OAAO,KAAK,WAAW,QAAQ;AAAA,MAC5C,OAAO;AAAA,QACL;AAAA,UACE,aAAa;AAAA,UACb,QAAQ,OAAO;AAAA,UACf,OAAO;AAAA,UACP,MAAM,GAAG,OAAO,OAAO,OAAO;AAAA,UAC9B,MAAM,OAAO;AAAA,QACf;AAAA,MACF;AAAA,IACF,IAAI,CAAC;AAAA,MAAQ,MAAM,IAAI,MAAM,gCAAgC,OAAO,OAAO;AAAA,IAC3E,OAAO,OAAO,IAAI,GAAG,OAAO,MAAM,mBAAmB;AAAA,MACnD;AAAA,MACA,QAAQ,OAAO;AAAA,MACf;AAAA,MAEA,MAAM,GAAG,OAAO,OAAO,OAAO,OAAO,MAAM,WAAW,GAAG,IAAI,KAAK,MAAM;AAAA,MACxE;AAAA,IACF,EAAE;AAAA,GACH;AAAA;",
8
+ "debugId": "080E88B866BC96AE64756E2164756E21",
9
+ "names": []
10
+ }