@tsplc/compiler 0.2.17 → 0.2.18
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 +2 -2
- package/dist/cli.js +920 -943
- package/dist/cli.js.map +13 -10
- package/dist/codesys.js +3893 -3352
- package/dist/codesys.js.map +29 -20
- package/dist/elaborate-capture.js +33 -17
- package/dist/elaborate-capture.js.map +3 -3
- package/dist/index.js +8787 -6855
- package/dist/index.js.map +40 -20
- package/dist/ir.js +1575 -1072
- package/dist/ir.js.map +21 -17
- package/dist/math.js.map +2 -2
- package/dist/project.js +154 -60
- package/dist/project.js.map +5 -5
- package/dist/telemetry.js +27 -9
- package/dist/telemetry.js.map +5 -5
- package/package.json +112 -112
- package/src/codesys/config.ts +50 -0
- package/src/codesys/debug.ts +670 -0
- package/src/codesys/emit.ts +142 -0
- package/src/codesys/engineering.ts +109 -0
- package/src/codesys/expressions.ts +92 -0
- package/src/codesys/global-lists.ts +250 -0
- package/src/codesys/global-names.ts +68 -0
- package/src/codesys/http.ts +890 -0
- package/src/codesys/index.ts +30 -0
- package/src/codesys/instrumentation.ts +430 -0
- package/src/codesys/io-paths.ts +140 -0
- package/src/codesys/manifest.ts +643 -0
- package/src/codesys/names.ts +81 -0
- package/src/codesys/numeric.ts +409 -0
- package/src/codesys/operands.ts +62 -0
- package/src/codesys/plan.ts +605 -0
- package/src/codesys/programs.ts +53 -0
- package/src/codesys/publication.ts +171 -0
- package/src/codesys/routines.ts +603 -0
- package/src/codesys/sources.ts +71 -0
- package/src/codesys/st-files.ts +115 -0
- package/src/codesys/storage.ts +97 -0
- package/src/codesys/symbols.ts +220 -0
- package/src/codesys/task-access.ts +320 -0
- package/src/codesys/telemetry.ts +732 -0
- package/src/codesys/types.ts +250 -0
- package/src/codesys/vendor.ts +150 -0
- package/src/frontend/analyzer.ts +794 -0
- package/src/frontend/async.ts +317 -1137
- package/src/frontend/blocks.ts +537 -403
- package/src/frontend/configuration.ts +176 -144
- package/src/frontend/const-functions.ts +183 -148
- package/src/frontend/cooperative.ts +73 -43
- package/src/frontend/coroutines.ts +1032 -0
- package/src/frontend/elaborate/calls.ts +535 -0
- package/src/frontend/elaborate/capture.ts +157 -101
- package/src/frontend/elaborate/dialect.ts +257 -0
- package/src/frontend/elaborate/expressions.ts +992 -0
- package/src/frontend/elaborate/frame.ts +53 -0
- package/src/frontend/elaborate/graph.ts +116 -71
- package/src/frontend/elaborate/imports.ts +70 -0
- package/src/frontend/elaborate/index.ts +435 -331
- package/src/frontend/elaborate/initializers.ts +198 -0
- package/src/frontend/elaborate/layouts.ts +591 -384
- package/src/frontend/elaborate/model.ts +264 -169
- package/src/frontend/elaborate/specialize.ts +343 -2586
- package/src/frontend/elaborate/statements.ts +606 -0
- package/src/frontend/elaborate/storage.ts +546 -0
- package/src/frontend/elaborate/values.ts +58 -0
- package/src/frontend/elaborate/writes.ts +100 -0
- package/src/frontend/exposure.ts +172 -140
- package/src/frontend/expressions.ts +1383 -0
- package/src/frontend/intrinsics.ts +337 -0
- package/src/frontend/module-graph.ts +89 -59
- package/src/frontend/positions.ts +271 -200
- package/src/frontend/promise-chains.ts +897 -0
- package/src/frontend/promises.ts +390 -747
- package/src/frontend/routines.ts +181 -0
- package/src/frontend/sdk.ts +82 -0
- package/src/frontend/services.ts +506 -372
- package/src/frontend/statements.ts +855 -0
- package/src/frontend/tasks.ts +471 -0
- package/src/frontend/telemetry.ts +174 -0
- package/src/frontend/types.ts +845 -551
- package/src/frontend/typescript.ts +323 -2543
- package/src/index.ts +5 -5
- package/src/ir/aggregates.ts +275 -0
- package/src/ir/allocation.ts +84 -0
- package/src/ir/core-model.ts +146 -0
- package/src/ir/declarations.ts +295 -0
- package/src/ir/diagnostics.ts +61 -0
- package/src/ir/domains.ts +152 -0
- package/src/ir/fold.ts +342 -0
- package/src/ir/index.ts +90 -0
- package/{ir/errors.ts → src/ir/job-errors.ts} +12 -10
- package/src/ir/layouts.ts +181 -0
- package/src/ir/link.ts +354 -0
- package/src/ir/model.ts +386 -0
- package/{ir → src/ir}/normalization-error.ts +4 -4
- package/src/ir/normalize.ts +70 -0
- package/src/ir/numeric.ts +171 -0
- package/src/ir/ranges.ts +256 -0
- package/src/ir/routine.ts +1163 -0
- package/src/ir/scalars.ts +321 -0
- package/src/ir/types.ts +127 -0
- package/src/project/artifacts.ts +342 -0
- package/src/project/cli.ts +177 -0
- package/src/project/debugger.ts +82 -0
- package/src/project/index.ts +6 -0
- package/src/project/plant.ts +467 -0
- package/src/project/project-commands.ts +372 -0
- package/src/project/project.ts +457 -0
- package/src/project/release.ts +153 -0
- package/src/project/server.ts +150 -0
- package/src/project/terminal.ts +32 -0
- package/stdlib/math.ts +14 -10
- package/stdlib/telemetry.ts +71 -47
- package/types/async.d.ts +46 -40
- package/types/data-types.d.ts +26 -26
- package/types/globals.d.ts +41 -38
- package/types/index.d.ts +96 -51
- package/types/plc.d.ts +3 -4
- package/types/telemetry.d.ts +14 -14
- package/backends/codesys/config.ts +0 -54
- package/backends/codesys/debug.ts +0 -509
- package/backends/codesys/emit.ts +0 -1738
- package/backends/codesys/engineering.ts +0 -88
- package/backends/codesys/global-names.ts +0 -49
- package/backends/codesys/http.ts +0 -675
- package/backends/codesys/index.ts +0 -13
- package/backends/codesys/io-paths.ts +0 -105
- package/backends/codesys/manifest.ts +0 -312
- package/backends/codesys/names.ts +0 -76
- package/backends/codesys/numeric.ts +0 -356
- package/backends/codesys/plan.ts +0 -457
- package/backends/codesys/publication.ts +0 -59
- package/backends/codesys/storage.ts +0 -70
- package/backends/codesys/task-access.ts +0 -293
- package/backends/codesys/telemetry.ts +0 -593
- package/backends/codesys/types.ts +0 -179
- package/backends/codesys/vendor.ts +0 -108
- package/ir/aggregates.ts +0 -333
- package/ir/allocation.ts +0 -74
- package/ir/core-model.ts +0 -129
- package/ir/core.ts +0 -64
- package/ir/declarations.ts +0 -208
- package/ir/diagnostics.ts +0 -43
- package/ir/domains.ts +0 -96
- package/ir/index.ts +0 -8
- package/ir/link.ts +0 -185
- package/ir/model.ts +0 -346
- package/ir/routine.ts +0 -859
- package/ir/scalars.ts +0 -675
- package/ir/types.ts +0 -76
- package/project/artifacts.ts +0 -277
- package/project/cli.ts +0 -395
- package/project/index.ts +0 -1
- package/project/plant.ts +0 -509
- package/project/project.ts +0 -358
- package/project/server.ts +0 -113
package/dist/telemetry.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { relative } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
|
-
// packages/compiler/ir/errors.ts
|
|
5
|
+
// packages/compiler/src/ir/job-errors.ts
|
|
6
6
|
var jobErrors = {
|
|
7
7
|
"1": "cancelled",
|
|
8
8
|
"2": "timeout",
|
|
@@ -15,8 +15,9 @@ var jobErrors = {
|
|
|
15
15
|
};
|
|
16
16
|
var httpErrors = { base: 1e4, last: 10999 };
|
|
17
17
|
var errorName = (code) => {
|
|
18
|
-
if (code > httpErrors.base && code <= httpErrors.last)
|
|
18
|
+
if (code > httpErrors.base && code <= httpErrors.last) {
|
|
19
19
|
return `HTTP ${code - httpErrors.base}`;
|
|
20
|
+
}
|
|
20
21
|
return code < httpErrors.base ? jobErrors[code] : undefined;
|
|
21
22
|
};
|
|
22
23
|
|
|
@@ -35,17 +36,33 @@ var collector;
|
|
|
35
36
|
var source = () => {
|
|
36
37
|
for (const line of new Error().stack?.split(`
|
|
37
38
|
`) ?? []) {
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
return `${relative(process.cwd(),
|
|
39
|
+
const [, file, lineNumber] = /\(?((?:\/|[A-Za-z]:\\)[^():]+):(\d+):\d+\)?$/.exec(line) ?? [];
|
|
40
|
+
if (file && file !== module) {
|
|
41
|
+
return `${relative(process.cwd(), file).replaceAll("\\", "/")}:${lineNumber}`;
|
|
42
|
+
}
|
|
41
43
|
}
|
|
42
44
|
return "";
|
|
43
45
|
};
|
|
46
|
+
var reportedValue = (value) => {
|
|
47
|
+
if (value instanceof Text) {
|
|
48
|
+
return value.value;
|
|
49
|
+
}
|
|
50
|
+
if (typeof value === "bigint") {
|
|
51
|
+
return Number(value);
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
};
|
|
55
|
+
var exceptionName = (error) => {
|
|
56
|
+
if (typeof error === "number") {
|
|
57
|
+
return errorName(error);
|
|
58
|
+
}
|
|
59
|
+
return error instanceof Error ? error.message : String(error);
|
|
60
|
+
};
|
|
44
61
|
var report = (record, properties = {}) => collector?.({
|
|
45
62
|
...record,
|
|
46
63
|
properties: Object.fromEntries(Object.entries(properties).map(([name, value]) => [
|
|
47
64
|
name,
|
|
48
|
-
|
|
65
|
+
reportedValue(value)
|
|
49
66
|
])),
|
|
50
67
|
source: source(),
|
|
51
68
|
scan: 0,
|
|
@@ -58,7 +75,7 @@ var telemetry = {
|
|
|
58
75
|
error: (message, properties) => report({ kind: "log", level: "error", message }, properties),
|
|
59
76
|
captureException: (error, properties) => {
|
|
60
77
|
const code = typeof error === "number" ? error : 0;
|
|
61
|
-
const name =
|
|
78
|
+
const name = exceptionName(error);
|
|
62
79
|
report({ kind: "exception", code, ...name && { name }, handled: true }, properties);
|
|
63
80
|
},
|
|
64
81
|
text: (bytes, length) => {
|
|
@@ -70,8 +87,9 @@ var telemetry = {
|
|
|
70
87
|
var onTelemetry = (next) => {
|
|
71
88
|
collector = next;
|
|
72
89
|
return () => {
|
|
73
|
-
if (collector === next)
|
|
90
|
+
if (collector === next) {
|
|
74
91
|
collector = undefined;
|
|
92
|
+
}
|
|
75
93
|
};
|
|
76
94
|
};
|
|
77
95
|
export {
|
|
@@ -79,5 +97,5 @@ export {
|
|
|
79
97
|
telemetry
|
|
80
98
|
};
|
|
81
99
|
|
|
82
|
-
//# debugId=
|
|
100
|
+
//# debugId=80AC1E2249312EFF64756E2164756E21
|
|
83
101
|
//# sourceMappingURL=telemetry.js.map
|
package/dist/telemetry.js.map
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../stdlib/telemetry.ts", "../ir/errors.ts", "../stdlib/clock.ts"],
|
|
3
|
+
"sources": ["../stdlib/telemetry.ts", "../src/ir/job-errors.ts", "../stdlib/clock.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { relative } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { errorName } from \"../ir/errors.ts\";\nimport { now } from \"./clock.ts\";\n\ntype Reported = Readonly<Record<string, unknown>>;\nclass Text {\n
|
|
6
|
-
"/** Job error codes, as every generated async block and service call reports them. */\nexport const jobErrors: Record<string, string> = {\n
|
|
5
|
+
"import { relative } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { errorName } from \"../src/ir/job-errors.ts\";\nimport { now } from \"./clock.ts\";\n\ntype Reported = Readonly<Record<string, unknown>>;\nclass Text {\n\tconstructor(readonly value: string) {}\n}\ntype Value = boolean | number | bigint | string | Text;\ntype Properties = Readonly<Record<string, Value>>;\n\nconst module = fileURLToPath(import.meta.url);\nlet collector: ((record: Reported) => void) | undefined;\n\n/** The program's call: the first stack frame outside this module, relative to the working directory. */\nconst source = () => {\n\tfor (const line of new Error().stack?.split(\"\\n\") ?? []) {\n\t\tconst [, file, lineNumber] =\n\t\t\t/\\(?((?:\\/|[A-Za-z]:\\\\)[^():]+):(\\d+):\\d+\\)?$/.exec(line) ?? [];\n\t\tif (file && file !== module) {\n\t\t\treturn `${relative(process.cwd(), file).replaceAll(\"\\\\\", \"/\")}:${lineNumber}`;\n\t\t}\n\t}\n\treturn \"\";\n};\n\nconst reportedValue = (value: Value) => {\n\tif (value instanceof Text) {\n\t\treturn value.value;\n\t}\n\tif (typeof value === \"bigint\") {\n\t\treturn Number(value);\n\t}\n\treturn value;\n};\n\nconst exceptionName = (error: unknown) => {\n\tif (typeof error === \"number\") {\n\t\treturn errorName(error);\n\t}\n\treturn error instanceof Error ? error.message : String(error);\n};\n\nconst report = (record: Reported, properties: Properties = {}) =>\n\tcollector?.({\n\t\t...record,\n\t\tproperties: Object.fromEntries(\n\t\t\tObject.entries(properties).map(([name, value]) => [\n\t\t\t\tname,\n\t\t\t\treportedValue(value),\n\t\t\t]),\n\t\t),\n\t\tsource: source(),\n\t\tscan: 0,\n\t\ttime: now(),\n\t});\n\n/** What a PLC program's `telemetry` calls do under Bun; see `types/telemetry.d.ts`. */\nexport const telemetry = {\n\tcapture: (event: string, properties?: Properties) =>\n\t\treport({ kind: \"event\", event }, properties),\n\tinfo: (message: string, properties?: Properties) =>\n\t\treport({ kind: \"log\", level: \"info\", message }, properties),\n\twarn: (message: string, properties?: Properties) =>\n\t\treport({ kind: \"log\", level: \"warn\", message }, properties),\n\terror: (message: string, properties?: Properties) =>\n\t\treport({ kind: \"log\", level: \"error\", message }, properties),\n\t// Under Bun a failure can be a thrown Error rather than a code; it is sent as code 0 with its message.\n\tcaptureException: (error: unknown, properties?: Properties) => {\n\t\tconst code = typeof error === \"number\" ? error : 0;\n\t\tconst name = exceptionName(error);\n\t\treport(\n\t\t\t{ kind: \"exception\", code, ...(name && { name }), handled: true },\n\t\t\tproperties,\n\t\t);\n\t},\n\ttext: (bytes: readonly number[], length: number) => {\n\t\tconst sent = bytes.slice(0, Math.max(0, Math.min(length, bytes.length)));\n\t\tconst end = sent.indexOf(0);\n\t\treturn new Text(\n\t\t\tnew TextDecoder().decode(\n\t\t\t\tUint8Array.from(end < 0 ? sent : sent.slice(0, end)),\n\t\t\t),\n\t\t);\n\t},\n};\n\nexport const onTelemetry = (next: (record: Reported) => void) => {\n\tcollector = next;\n\treturn () => {\n\t\tif (collector === next) {\n\t\t\tcollector = undefined;\n\t\t}\n\t};\n};\n",
|
|
6
|
+
"/** Job error codes, as every generated async block and service call reports them. */\nexport const jobErrors: Record<string, string> = {\n\t\"1\": \"cancelled\",\n\t\"2\": \"timeout\",\n\t\"3\": \"request or response too large to encode\",\n\t\"4\": \"malformed response\",\n\t\"5\": \"network error or server restarted\",\n\t\"6\": \"TLS error\",\n\t\"7\": \"no free request slot\",\n\t\"10000\": \"HTTP status: 10000 + status code\",\n};\n\n/** An HTTP response fails a job with `base` + its status, up to `last`. */\nexport const httpErrors = { base: 10000, last: 10999 };\n\n/** What a telemetry exception record calls an error code: its meaning when it is a job error. */\nexport const errorName = (code: number): string | undefined => {\n\tif (code > httpErrors.base && code <= httpErrors.last) {\n\t\treturn `HTTP ${code - httpErrors.base}`;\n\t}\n\treturn code < httpErrors.base ? jobErrors[code] : undefined;\n};\n",
|
|
7
7
|
"/** Milliseconds since the process started, as the PLC's `now()` counts them; used when a program runs under Bun. */\nexport const now = (): number => Math.floor(performance.now());\n"
|
|
8
8
|
],
|
|
9
|
-
"mappings": ";AAAA;AACA;;;ACAO,IAAM,YAAoC;AAAA,
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": ";AAAA;AACA;;;ACAO,IAAM,YAAoC;AAAA,EAChD,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,SAAS;AACV;AAGO,IAAM,aAAa,EAAE,MAAM,KAAO,MAAM,MAAM;AAG9C,IAAM,YAAY,CAAC,SAAqC;AAAA,EAC9D,IAAI,OAAO,WAAW,QAAQ,QAAQ,WAAW,MAAM;AAAA,IACtD,OAAO,QAAQ,OAAO,WAAW;AAAA,EAClC;AAAA,EACA,OAAO,OAAO,WAAW,OAAO,UAAU,QAAQ;AAAA;;;ACnB5C,IAAM,MAAM,MAAc,KAAK,MAAM,YAAY,IAAI,CAAC;;;AFK7D,MAAM,KAAK;AAAA,EACW;AAAA,EAArB,WAAW,CAAU,OAAe;AAAA,IAAf;AAAA;AACtB;AAIA,IAAM,SAAS,cAAc,YAAY,GAAG;AAC5C,IAAI;AAGJ,IAAM,SAAS,MAAM;AAAA,EACpB,WAAW,QAAQ,IAAI,MAAM,EAAE,OAAO,MAAM;AAAA,CA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
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
2
|
+
"name": "@tsplc/compiler",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"description": "Write CODESYS PLC programs in TypeScript and compile them to IEC 61131-3 Structured Text. Provides the tsplc CLI.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"plc",
|
|
7
|
+
"codesys",
|
|
8
|
+
"iec-61131-3",
|
|
9
|
+
"structured-text",
|
|
10
|
+
"typescript",
|
|
11
|
+
"compiler"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/rip-technologies/tsplc#readme",
|
|
14
|
+
"bugs": "https://github.com/rip-technologies/tsplc/issues",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/rip-technologies/tsplc.git",
|
|
18
|
+
"directory": "packages/compiler"
|
|
19
|
+
},
|
|
20
|
+
"version": "0.2.18",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./src/index.ts",
|
|
25
|
+
"bun": "./src/index.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./ir": {
|
|
29
|
+
"types": "./src/ir/index.ts",
|
|
30
|
+
"bun": "./src/ir/index.ts",
|
|
31
|
+
"default": "./dist/ir.js"
|
|
32
|
+
},
|
|
33
|
+
"./codesys": {
|
|
34
|
+
"types": "./src/codesys/index.ts",
|
|
35
|
+
"bun": "./src/codesys/index.ts",
|
|
36
|
+
"default": "./dist/codesys.js"
|
|
37
|
+
},
|
|
38
|
+
"./project": {
|
|
39
|
+
"types": "./src/project/index.ts",
|
|
40
|
+
"bun": "./src/project/index.ts",
|
|
41
|
+
"default": "./dist/project.js"
|
|
42
|
+
},
|
|
43
|
+
"./clock": {
|
|
44
|
+
"types": "./types/clock.d.ts",
|
|
45
|
+
"bun": "./stdlib/clock.ts",
|
|
46
|
+
"default": "./dist/clock.js"
|
|
47
|
+
},
|
|
48
|
+
"./telemetry": {
|
|
49
|
+
"types": "./types/telemetry.d.ts",
|
|
50
|
+
"bun": "./stdlib/telemetry.ts",
|
|
51
|
+
"default": "./dist/telemetry.js"
|
|
52
|
+
},
|
|
53
|
+
"./math": {
|
|
54
|
+
"types": "./stdlib/math.ts",
|
|
55
|
+
"bun": "./stdlib/math.ts",
|
|
56
|
+
"default": "./dist/math.js"
|
|
57
|
+
},
|
|
58
|
+
"./types": {
|
|
59
|
+
"types": "./types/index.d.ts",
|
|
60
|
+
"default": "./types/index.d.ts"
|
|
61
|
+
},
|
|
62
|
+
"./data-types": {
|
|
63
|
+
"types": "./types/data-types.d.ts",
|
|
64
|
+
"default": "./types/data-types.d.ts"
|
|
65
|
+
},
|
|
66
|
+
"./globals": {
|
|
67
|
+
"types": "./types/globals.d.ts",
|
|
68
|
+
"default": "./types/globals.d.ts"
|
|
69
|
+
},
|
|
70
|
+
"./async": {
|
|
71
|
+
"types": "./types/async.d.ts",
|
|
72
|
+
"default": "./types/async.d.ts"
|
|
73
|
+
},
|
|
74
|
+
"./config": {
|
|
75
|
+
"types": "./types/config.d.ts",
|
|
76
|
+
"default": "./types/config.d.ts"
|
|
77
|
+
},
|
|
78
|
+
"./plc": {
|
|
79
|
+
"types": "./types/plc.d.ts",
|
|
80
|
+
"default": "./types/plc.d.ts"
|
|
81
|
+
},
|
|
82
|
+
"./testing/machine": "./testing/machine.fixtures.ts"
|
|
83
|
+
},
|
|
84
|
+
"files": [
|
|
85
|
+
"dist",
|
|
86
|
+
"src",
|
|
87
|
+
"types",
|
|
88
|
+
"stdlib",
|
|
89
|
+
"!**/*.test.ts",
|
|
90
|
+
"!**/*.fixtures.ts"
|
|
91
|
+
],
|
|
92
|
+
"engines": {
|
|
93
|
+
"bun": ">=1.4.3"
|
|
94
|
+
},
|
|
95
|
+
"dependencies": {
|
|
96
|
+
"@tsplc/agent": "0.2.18",
|
|
97
|
+
"@tsplc/build": "0.2.18",
|
|
98
|
+
"@tsplc/config": "0.2.18",
|
|
99
|
+
"@tsplc/debug": "0.2.18",
|
|
100
|
+
"@tsplc/opcua": "0.2.18",
|
|
101
|
+
"@tsplc/typegen": "0.2.18",
|
|
102
|
+
"typescript": "6.0.3",
|
|
103
|
+
"zod": "4.3.6",
|
|
104
|
+
"@types/bun": "1.4.2",
|
|
105
|
+
"@tsplc/server": "0.2.18",
|
|
106
|
+
"@tsplc/iec": "0.2.18"
|
|
107
|
+
},
|
|
108
|
+
"bin": {
|
|
109
|
+
"tsplc": "./dist/cli.js"
|
|
110
|
+
},
|
|
111
|
+
"publishConfig": {
|
|
112
|
+
"access": "public"
|
|
113
|
+
}
|
|
114
114
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
httpOptionsSchema,
|
|
3
|
+
buildTargetSchema,
|
|
4
|
+
publicationSchema,
|
|
5
|
+
type TargetDescriptor,
|
|
6
|
+
} from "@tsplc/config";
|
|
7
|
+
import { directIoBindingSchema } from "@tsplc/config/build";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { engineeringSchema } from "./engineering.ts";
|
|
10
|
+
import { isIecIdentifier } from "./names.ts";
|
|
11
|
+
|
|
12
|
+
const addressSchema = directIoBindingSchema.extend({
|
|
13
|
+
kind: z.literal("direct"),
|
|
14
|
+
// A generated device tree maps this bit or byte channel to its target
|
|
15
|
+
// variable, so the scan needs no AT wire or copy.
|
|
16
|
+
mapped: z.boolean().optional(),
|
|
17
|
+
});
|
|
18
|
+
// Explicit IEC object names keep their exact spelling, so they must already be valid.
|
|
19
|
+
const iecNames = z
|
|
20
|
+
.record(
|
|
21
|
+
z.string().min(1),
|
|
22
|
+
z
|
|
23
|
+
.string()
|
|
24
|
+
.refine(isIecIdentifier, "Use a valid, non-reserved IEC identifier."),
|
|
25
|
+
)
|
|
26
|
+
.optional();
|
|
27
|
+
export const optionsSchema = z
|
|
28
|
+
.object({
|
|
29
|
+
engineering: engineeringSchema,
|
|
30
|
+
http: httpOptionsSchema,
|
|
31
|
+
io: z.record(z.string().min(1), addressSchema),
|
|
32
|
+
publish: publicationSchema.default({ production: [], development: [] }),
|
|
33
|
+
buildTarget: buildTargetSchema.default("production"),
|
|
34
|
+
programNames: iecNames,
|
|
35
|
+
})
|
|
36
|
+
.strict();
|
|
37
|
+
export type CodesysOptions = z.infer<typeof optionsSchema>;
|
|
38
|
+
export function codesys(
|
|
39
|
+
options: z.input<typeof optionsSchema>,
|
|
40
|
+
): TargetDescriptor<z.input<typeof optionsSchema>> {
|
|
41
|
+
return { kind: "codesys", options };
|
|
42
|
+
}
|
|
43
|
+
// tsPLC binds nothing at 64-bit addresses, so `%IL`/`%QL` are not offered.
|
|
44
|
+
export function direct(
|
|
45
|
+
address:
|
|
46
|
+
| `%${"I" | "Q"}X${number}.${number}`
|
|
47
|
+
| `%${"I" | "Q"}${"B" | "W" | "D"}${number}`,
|
|
48
|
+
): z.infer<typeof addressSchema> {
|
|
49
|
+
return { kind: "direct", address };
|
|
50
|
+
}
|