@tsplc/compiler 0.2.17 → 0.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/README.md +2 -2
  2. package/dist/cli.js +920 -943
  3. package/dist/cli.js.map +13 -10
  4. package/dist/codesys.js +3893 -3352
  5. package/dist/codesys.js.map +29 -20
  6. package/dist/elaborate-capture.js +33 -17
  7. package/dist/elaborate-capture.js.map +3 -3
  8. package/dist/index.js +8787 -6855
  9. package/dist/index.js.map +40 -20
  10. package/dist/ir.js +1575 -1072
  11. package/dist/ir.js.map +21 -17
  12. package/dist/math.js.map +2 -2
  13. package/dist/project.js +154 -60
  14. package/dist/project.js.map +5 -5
  15. package/dist/telemetry.js +27 -9
  16. package/dist/telemetry.js.map +5 -5
  17. package/package.json +112 -112
  18. package/src/codesys/config.ts +50 -0
  19. package/src/codesys/debug.ts +670 -0
  20. package/src/codesys/emit.ts +142 -0
  21. package/src/codesys/engineering.ts +109 -0
  22. package/src/codesys/expressions.ts +92 -0
  23. package/src/codesys/global-lists.ts +250 -0
  24. package/src/codesys/global-names.ts +68 -0
  25. package/src/codesys/http.ts +890 -0
  26. package/src/codesys/index.ts +30 -0
  27. package/src/codesys/instrumentation.ts +430 -0
  28. package/src/codesys/io-paths.ts +140 -0
  29. package/src/codesys/manifest.ts +643 -0
  30. package/src/codesys/names.ts +81 -0
  31. package/src/codesys/numeric.ts +409 -0
  32. package/src/codesys/operands.ts +62 -0
  33. package/src/codesys/plan.ts +605 -0
  34. package/src/codesys/programs.ts +53 -0
  35. package/src/codesys/publication.ts +171 -0
  36. package/src/codesys/routines.ts +603 -0
  37. package/src/codesys/sources.ts +71 -0
  38. package/src/codesys/st-files.ts +115 -0
  39. package/src/codesys/storage.ts +97 -0
  40. package/src/codesys/symbols.ts +220 -0
  41. package/src/codesys/task-access.ts +320 -0
  42. package/src/codesys/telemetry.ts +732 -0
  43. package/src/codesys/types.ts +250 -0
  44. package/src/codesys/vendor.ts +150 -0
  45. package/src/frontend/analyzer.ts +794 -0
  46. package/src/frontend/async.ts +317 -1137
  47. package/src/frontend/blocks.ts +537 -403
  48. package/src/frontend/configuration.ts +176 -144
  49. package/src/frontend/const-functions.ts +183 -148
  50. package/src/frontend/cooperative.ts +73 -43
  51. package/src/frontend/coroutines.ts +1032 -0
  52. package/src/frontend/elaborate/calls.ts +535 -0
  53. package/src/frontend/elaborate/capture.ts +157 -101
  54. package/src/frontend/elaborate/dialect.ts +257 -0
  55. package/src/frontend/elaborate/expressions.ts +992 -0
  56. package/src/frontend/elaborate/frame.ts +53 -0
  57. package/src/frontend/elaborate/graph.ts +116 -71
  58. package/src/frontend/elaborate/imports.ts +70 -0
  59. package/src/frontend/elaborate/index.ts +435 -331
  60. package/src/frontend/elaborate/initializers.ts +198 -0
  61. package/src/frontend/elaborate/layouts.ts +591 -384
  62. package/src/frontend/elaborate/model.ts +264 -169
  63. package/src/frontend/elaborate/specialize.ts +343 -2586
  64. package/src/frontend/elaborate/statements.ts +606 -0
  65. package/src/frontend/elaborate/storage.ts +546 -0
  66. package/src/frontend/elaborate/values.ts +58 -0
  67. package/src/frontend/elaborate/writes.ts +100 -0
  68. package/src/frontend/exposure.ts +172 -140
  69. package/src/frontend/expressions.ts +1383 -0
  70. package/src/frontend/intrinsics.ts +337 -0
  71. package/src/frontend/module-graph.ts +89 -59
  72. package/src/frontend/positions.ts +271 -200
  73. package/src/frontend/promise-chains.ts +897 -0
  74. package/src/frontend/promises.ts +390 -747
  75. package/src/frontend/routines.ts +181 -0
  76. package/src/frontend/sdk.ts +82 -0
  77. package/src/frontend/services.ts +506 -372
  78. package/src/frontend/statements.ts +855 -0
  79. package/src/frontend/tasks.ts +471 -0
  80. package/src/frontend/telemetry.ts +174 -0
  81. package/src/frontend/types.ts +845 -551
  82. package/src/frontend/typescript.ts +323 -2543
  83. package/src/index.ts +5 -5
  84. package/src/ir/aggregates.ts +275 -0
  85. package/src/ir/allocation.ts +84 -0
  86. package/src/ir/core-model.ts +146 -0
  87. package/src/ir/declarations.ts +295 -0
  88. package/src/ir/diagnostics.ts +61 -0
  89. package/src/ir/domains.ts +152 -0
  90. package/src/ir/fold.ts +342 -0
  91. package/src/ir/index.ts +90 -0
  92. package/{ir/errors.ts → src/ir/job-errors.ts} +12 -10
  93. package/src/ir/layouts.ts +181 -0
  94. package/src/ir/link.ts +354 -0
  95. package/src/ir/model.ts +386 -0
  96. package/{ir → src/ir}/normalization-error.ts +4 -4
  97. package/src/ir/normalize.ts +70 -0
  98. package/src/ir/numeric.ts +171 -0
  99. package/src/ir/ranges.ts +256 -0
  100. package/src/ir/routine.ts +1163 -0
  101. package/src/ir/scalars.ts +321 -0
  102. package/src/ir/types.ts +127 -0
  103. package/src/project/artifacts.ts +342 -0
  104. package/src/project/cli.ts +177 -0
  105. package/src/project/debugger.ts +82 -0
  106. package/src/project/index.ts +6 -0
  107. package/src/project/plant.ts +467 -0
  108. package/src/project/project-commands.ts +372 -0
  109. package/src/project/project.ts +457 -0
  110. package/src/project/release.ts +153 -0
  111. package/src/project/server.ts +150 -0
  112. package/src/project/terminal.ts +32 -0
  113. package/stdlib/math.ts +14 -10
  114. package/stdlib/telemetry.ts +71 -47
  115. package/types/async.d.ts +46 -40
  116. package/types/data-types.d.ts +26 -26
  117. package/types/globals.d.ts +41 -38
  118. package/types/index.d.ts +96 -51
  119. package/types/plc.d.ts +3 -4
  120. package/types/telemetry.d.ts +14 -14
  121. package/backends/codesys/config.ts +0 -54
  122. package/backends/codesys/debug.ts +0 -509
  123. package/backends/codesys/emit.ts +0 -1738
  124. package/backends/codesys/engineering.ts +0 -88
  125. package/backends/codesys/global-names.ts +0 -49
  126. package/backends/codesys/http.ts +0 -675
  127. package/backends/codesys/index.ts +0 -13
  128. package/backends/codesys/io-paths.ts +0 -105
  129. package/backends/codesys/manifest.ts +0 -312
  130. package/backends/codesys/names.ts +0 -76
  131. package/backends/codesys/numeric.ts +0 -356
  132. package/backends/codesys/plan.ts +0 -457
  133. package/backends/codesys/publication.ts +0 -59
  134. package/backends/codesys/storage.ts +0 -70
  135. package/backends/codesys/task-access.ts +0 -293
  136. package/backends/codesys/telemetry.ts +0 -593
  137. package/backends/codesys/types.ts +0 -179
  138. package/backends/codesys/vendor.ts +0 -108
  139. package/ir/aggregates.ts +0 -333
  140. package/ir/allocation.ts +0 -74
  141. package/ir/core-model.ts +0 -129
  142. package/ir/core.ts +0 -64
  143. package/ir/declarations.ts +0 -208
  144. package/ir/diagnostics.ts +0 -43
  145. package/ir/domains.ts +0 -96
  146. package/ir/index.ts +0 -8
  147. package/ir/link.ts +0 -185
  148. package/ir/model.ts +0 -346
  149. package/ir/routine.ts +0 -859
  150. package/ir/scalars.ts +0 -675
  151. package/ir/types.ts +0 -76
  152. package/project/artifacts.ts +0 -277
  153. package/project/cli.ts +0 -395
  154. package/project/index.ts +0 -1
  155. package/project/plant.ts +0 -509
  156. package/project/project.ts +0 -358
  157. package/project/server.ts +0 -113
@@ -0,0 +1,150 @@
1
+ import { existsSync } from "node:fs";
2
+ import { mkdtemp, mkdir, rm, rename } from "node:fs/promises";
3
+ import { dirname, resolve, join } from "node:path";
4
+ import { createRequire } from "node:module";
5
+ import ts from "typescript";
6
+ import type { ResolvedTsplcConfig } from "@tsplc/config";
7
+ import { typeCheckOnly } from "@tsplc/compiler";
8
+
9
+ const resolveServerModule = (root: string, name: string) =>
10
+ name.startsWith(".") ||
11
+ name.startsWith("/") ||
12
+ existsSync(resolve(root, name))
13
+ ? resolve(root, name)
14
+ : createRequire(join(root, "package.json")).resolve(name);
15
+
16
+ const kebabCase = (name: string) =>
17
+ name
18
+ .replace(/([a-z0-9])([A-Z])|([A-Z])([A-Z][a-z])/g, "$1$3-$2$4")
19
+ .replace(/[^A-Za-z0-9]+/g, "-")
20
+ .replace(/^-|-$/g, "")
21
+ .toLowerCase();
22
+
23
+ /** `build/server/<name>-services<extension>`, where the server's script or executable goes. */
24
+ const serverOutput = (
25
+ config: ResolvedTsplcConfig,
26
+ root: string,
27
+ extension: string,
28
+ ) =>
29
+ resolve(
30
+ root,
31
+ "build/server",
32
+ `${kebabCase(config.name)}-services${extension}`,
33
+ );
34
+
35
+ /** The host entry, type-checked as it will be built. */
36
+ const checkedServerEntry = (config: ResolvedTsplcConfig, root: string) => {
37
+ const runtime = config.server?.runtime;
38
+ if (!runtime) {
39
+ throw new Error("Configure server.runtime to build the server.");
40
+ }
41
+ const entry = resolveServerModule(root, runtime.entry);
42
+ const tsconfig = ts.findConfigFile(dirname(entry), ts.sys.fileExists);
43
+ if (!tsconfig) {
44
+ throw new Error("Server entry requires a tsconfig.json.");
45
+ }
46
+ const read = ts.readConfigFile(tsconfig, ts.sys.readFile);
47
+ if (read.error) {
48
+ throw new Error(
49
+ ts.flattenDiagnosticMessageText(read.error.messageText, "\n"),
50
+ );
51
+ }
52
+ const parsed = ts.parseJsonConfigFileContent(
53
+ read.config,
54
+ ts.sys,
55
+ dirname(tsconfig),
56
+ );
57
+ const program = ts.createProgram({
58
+ rootNames: [
59
+ entry,
60
+ ...parsed.fileNames.filter((file) => /\.d\.[cm]?ts$/.test(file)),
61
+ ],
62
+ options: { ...parsed.options, ...typeCheckOnly },
63
+ projectReferences: parsed.projectReferences,
64
+ });
65
+ const diagnostics = [...parsed.errors, ...ts.getPreEmitDiagnostics(program)];
66
+ if (diagnostics.length) {
67
+ throw new Error(
68
+ ts.formatDiagnosticsWithColorAndContext(diagnostics, {
69
+ getCanonicalFileName: (path) => path,
70
+ getCurrentDirectory: () => root,
71
+ getNewLine: () => "\n",
72
+ }),
73
+ );
74
+ }
75
+ return { entry, runtime };
76
+ };
77
+
78
+ /**
79
+ * Bundles the host entry, which starts its own listener, into one minified script,
80
+ * `build/server/<name>-services.js`, which the plant agent runs on its own Bun. It is a few MB
81
+ * where an executable, which embeds Bun, is over 100, and deployments upload it.
82
+ */
83
+ export const bundleServer = async (
84
+ config: ResolvedTsplcConfig,
85
+ root: string,
86
+ ) => {
87
+ const { entry } = checkedServerEntry(config, root);
88
+ const outFile = serverOutput(config, root, ".js");
89
+ const result = await Bun.build({
90
+ entrypoints: [entry],
91
+ target: "bun",
92
+ minify: true,
93
+ env: "disable",
94
+ });
95
+ if (!result.success) {
96
+ throw new AggregateError(result.logs, "Server bundle build failed.");
97
+ }
98
+ const [script, ...assets] = result.outputs;
99
+ if (!script || assets.length) {
100
+ throw new Error(
101
+ `The server bundle needs files beside its script (${assets.map(({ path }) => path).join(", ")}), which deployments don't carry.`,
102
+ );
103
+ }
104
+ await mkdir(dirname(outFile), { recursive: true });
105
+ await Bun.write(outFile, script);
106
+ return outFile;
107
+ };
108
+
109
+ /** Compiles the host entry, which starts its own listener, into `build/server/<name>-services`. */
110
+ export const buildServer = async (
111
+ config: ResolvedTsplcConfig,
112
+ root: string,
113
+ ) => {
114
+ const { entry, runtime } = checkedServerEntry(config, root);
115
+ const windows = runtime.target
116
+ ? runtime.target.includes("windows")
117
+ : process.platform === "win32";
118
+ const outFile = serverOutput(config, root, windows ? ".exe" : "");
119
+ await mkdir(dirname(outFile), { recursive: true });
120
+ // Compile beside the output so dependency resolution starts from the owning project.
121
+ const staging = await mkdtemp(join(dirname(outFile), ".tsplc-server-"));
122
+ try {
123
+ const binary = join(staging, "server");
124
+ const result = await Bun.build({
125
+ entrypoints: [entry],
126
+ env: "disable",
127
+ compile: {
128
+ outfile: binary,
129
+ ...(runtime.target ? { target: runtime.target } : {}),
130
+ autoloadDotenv: false,
131
+ autoloadBunfig: false,
132
+ autoloadTsconfig: false,
133
+ autoloadPackageJson: false,
134
+ },
135
+ });
136
+ if (!result.success) {
137
+ throw new AggregateError(result.logs, "Server executable build failed.");
138
+ }
139
+ // Bun names a Windows executable itself.
140
+ await rename(windows ? `${binary}.exe` : binary, outFile);
141
+ return {
142
+ server: {
143
+ executable: outFile,
144
+ target: runtime.target ?? `bun-${process.platform}-${process.arch}`,
145
+ },
146
+ };
147
+ } finally {
148
+ await rm(staging, { recursive: true, force: true });
149
+ }
150
+ };
@@ -0,0 +1,32 @@
1
+ import { ask } from "@tsplc/agent";
2
+
3
+ export const choose = async <T>(
4
+ question: string,
5
+ items: readonly T[],
6
+ label: (item: T) => string,
7
+ ) => {
8
+ items.forEach((item, index) => console.log(` ${index + 1}. ${label(item)}`));
9
+ while (true) {
10
+ const item =
11
+ items[Number(await ask(`${question} [1-${items.length}]: `)) - 1];
12
+ if (item !== undefined) {
13
+ return item;
14
+ }
15
+ }
16
+ };
17
+
18
+ export const confirm = async (question: string, flags: { yes?: boolean }) =>
19
+ flags.yes || /^y(es)?$/i.test(await ask(`${question} [y/N]: `));
20
+
21
+ export const progress = (message: string) => console.log(` ${message}`);
22
+
23
+ /** Prints progress with the minutes and seconds since it was made, so the slow steps show. */
24
+ export const timedProgress = () => {
25
+ const start = Date.now();
26
+ return (message: string) => {
27
+ const seconds = Math.round((Date.now() - start) / 1000);
28
+ progress(
29
+ `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")} ${message}`,
30
+ );
31
+ };
32
+ };
package/stdlib/math.ts CHANGED
@@ -1,19 +1,23 @@
1
1
  // PLC implementation source: the frontend specializes these helpers for each
2
2
  // concrete scalar domain. The release includes this source for that analysis.
3
3
  export function min<T extends number | bigint>(left: T, right: T): T {
4
- return left < right ? left : right;
4
+ return left < right ? left : right;
5
5
  }
6
6
 
7
7
  export function max<T extends number | bigint>(left: T, right: T): T {
8
- return left > right ? left : right;
8
+ return left > right ? left : right;
9
9
  }
10
10
 
11
- export function clamp<T extends number | bigint>(value: T, lower: T, upper: T): T {
12
- if (value < lower) {
13
- return lower;
14
- }
15
- if (value > upper) {
16
- return upper;
17
- }
18
- return value;
11
+ export function clamp<T extends number | bigint>(
12
+ value: T,
13
+ lower: T,
14
+ upper: T,
15
+ ): T {
16
+ if (value < lower) {
17
+ return lower;
18
+ }
19
+ if (value > upper) {
20
+ return upper;
21
+ }
22
+ return value;
19
23
  }
@@ -1,11 +1,11 @@
1
1
  import { relative } from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
- import { errorName } from "../ir/errors.ts";
3
+ import { errorName } from "../src/ir/job-errors.ts";
4
4
  import { now } from "./clock.ts";
5
5
 
6
6
  type Reported = Readonly<Record<string, unknown>>;
7
7
  class Text {
8
- constructor(readonly value: string) {}
8
+ constructor(readonly value: string) {}
9
9
  }
10
10
  type Value = boolean | number | bigint | string | Text;
11
11
  type Properties = Readonly<Record<string, Value>>;
@@ -15,58 +15,82 @@ let collector: ((record: Reported) => void) | undefined;
15
15
 
16
16
  /** The program's call: the first stack frame outside this module, relative to the working directory. */
17
17
  const source = () => {
18
- for (const line of new Error().stack?.split("\n") ?? []) {
19
- const frame = /\(?((?:\/|[A-Za-z]:\\)[^():]+):(\d+):\d+\)?$/.exec(line);
20
- if (frame && frame[1] !== module)
21
- return `${relative(process.cwd(), frame[1]!).replaceAll("\\", "/")}:${frame[2]}`;
22
- }
23
- return "";
18
+ for (const line of new Error().stack?.split("\n") ?? []) {
19
+ const [, file, lineNumber] =
20
+ /\(?((?:\/|[A-Za-z]:\\)[^():]+):(\d+):\d+\)?$/.exec(line) ?? [];
21
+ if (file && file !== module) {
22
+ return `${relative(process.cwd(), file).replaceAll("\\", "/")}:${lineNumber}`;
23
+ }
24
+ }
25
+ return "";
26
+ };
27
+
28
+ const reportedValue = (value: Value) => {
29
+ if (value instanceof Text) {
30
+ return value.value;
31
+ }
32
+ if (typeof value === "bigint") {
33
+ return Number(value);
34
+ }
35
+ return value;
36
+ };
37
+
38
+ const exceptionName = (error: unknown) => {
39
+ if (typeof error === "number") {
40
+ return errorName(error);
41
+ }
42
+ return error instanceof Error ? error.message : String(error);
24
43
  };
25
44
 
26
45
  const report = (record: Reported, properties: Properties = {}) =>
27
- collector?.({
28
- ...record,
29
- properties: Object.fromEntries(
30
- Object.entries(properties).map(([name, value]) => [
31
- name,
32
- value instanceof Text ? value.value : typeof value === "bigint" ? Number(value) : value,
33
- ]),
34
- ),
35
- source: source(),
36
- scan: 0,
37
- time: now(),
38
- });
46
+ collector?.({
47
+ ...record,
48
+ properties: Object.fromEntries(
49
+ Object.entries(properties).map(([name, value]) => [
50
+ name,
51
+ reportedValue(value),
52
+ ]),
53
+ ),
54
+ source: source(),
55
+ scan: 0,
56
+ time: now(),
57
+ });
39
58
 
40
59
  /** What a PLC program's `telemetry` calls do under Bun; see `types/telemetry.d.ts`. */
41
60
  export const telemetry = {
42
- capture: (event: string, properties?: Properties) => report({ kind: "event", event }, properties),
43
- info: (message: string, properties?: Properties) =>
44
- report({ kind: "log", level: "info", message }, properties),
45
- warn: (message: string, properties?: Properties) =>
46
- report({ kind: "log", level: "warn", message }, properties),
47
- error: (message: string, properties?: Properties) =>
48
- report({ kind: "log", level: "error", message }, properties),
49
- // Under Bun a failure can be a thrown Error rather than a code; it is sent as code 0 with its message.
50
- captureException: (error: unknown, properties?: Properties) => {
51
- const code = typeof error === "number" ? error : 0;
52
- const name =
53
- typeof error === "number"
54
- ? errorName(error)
55
- : error instanceof Error
56
- ? error.message
57
- : String(error);
58
- report({ kind: "exception", code, ...(name && { name }), handled: true }, properties);
59
- },
60
- text: (bytes: readonly number[], length: number) => {
61
- const sent = bytes.slice(0, Math.max(0, Math.min(length, bytes.length)));
62
- const end = sent.indexOf(0);
63
- return new Text(new TextDecoder().decode(Uint8Array.from(end < 0 ? sent : sent.slice(0, end))));
64
- },
61
+ capture: (event: string, properties?: Properties) =>
62
+ report({ kind: "event", event }, properties),
63
+ info: (message: string, properties?: Properties) =>
64
+ report({ kind: "log", level: "info", message }, properties),
65
+ warn: (message: string, properties?: Properties) =>
66
+ report({ kind: "log", level: "warn", message }, properties),
67
+ error: (message: string, properties?: Properties) =>
68
+ report({ kind: "log", level: "error", message }, properties),
69
+ // Under Bun a failure can be a thrown Error rather than a code; it is sent as code 0 with its message.
70
+ captureException: (error: unknown, properties?: Properties) => {
71
+ const code = typeof error === "number" ? error : 0;
72
+ const name = exceptionName(error);
73
+ report(
74
+ { kind: "exception", code, ...(name && { name }), handled: true },
75
+ properties,
76
+ );
77
+ },
78
+ text: (bytes: readonly number[], length: number) => {
79
+ const sent = bytes.slice(0, Math.max(0, Math.min(length, bytes.length)));
80
+ const end = sent.indexOf(0);
81
+ return new Text(
82
+ new TextDecoder().decode(
83
+ Uint8Array.from(end < 0 ? sent : sent.slice(0, end)),
84
+ ),
85
+ );
86
+ },
65
87
  };
66
88
 
67
89
  export const onTelemetry = (next: (record: Reported) => void) => {
68
- collector = next;
69
- return () => {
70
- if (collector === next) collector = undefined;
71
- };
90
+ collector = next;
91
+ return () => {
92
+ if (collector === next) {
93
+ collector = undefined;
94
+ }
95
+ };
72
96
  };
package/types/async.d.ts CHANGED
@@ -1,81 +1,87 @@
1
1
  import type { BOOL, TIME, UDINT } from "./index.d.ts";
2
2
 
3
3
  export interface BackgroundSnapshot<T> {
4
- valid: BOOL;
5
- busy: BOOL;
6
- done: BOOL;
7
- cancelRequested: BOOL;
8
- error: UDINT;
9
- result: T;
4
+ valid: BOOL;
5
+ busy: BOOL;
6
+ done: BOOL;
7
+ cancelRequested: BOOL;
8
+ error: UDINT;
9
+ result: T;
10
10
  }
11
11
  export interface BackgroundTask<A extends unknown[], R> {
12
- (...arguments_: A): Promise<R>;
13
- start(...arguments_: A): BOOL;
14
- snapshot(): BackgroundSnapshot<R>;
15
- cancel(): BOOL;
16
- reset(): BOOL;
12
+ (...arguments_: A): Promise<R>;
13
+ start(...arguments_: A): BOOL;
14
+ snapshot(): BackgroundSnapshot<R>;
15
+ cancel(): BOOL;
16
+ reset(): BOOL;
17
17
  }
18
18
  export declare const backgroundTasks: {
19
- define<A extends unknown[], R>(
20
- work: (...arguments_: A) => Promise<R>,
21
- options: { interval: TIME; priority: number },
22
- ): BackgroundTask<A, R>;
19
+ define<A extends unknown[], R>(
20
+ work: (...arguments_: A) => Promise<R>,
21
+ options: { interval: TIME; priority: number },
22
+ ): BackgroundTask<A, R>;
23
23
  };
24
24
  export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
25
25
  export interface FetchOptions<Request> {
26
- method?: HttpMethod;
27
- json?: Request;
26
+ method?: HttpMethod;
27
+ json?: Request;
28
28
  }
29
29
  /** Fetch a bounded JSON response. URL and method must be compile-time values. */
30
30
  export declare function fetch<Response, Request = unknown>(
31
- url: string,
32
- options?: FetchOptions<Request>,
31
+ url: string,
32
+ options?: FetchOptions<Request>,
33
33
  ): Promise<Response>;
34
34
  export declare function sleep(duration: TIME): Promise<void>;
35
35
 
36
36
  /** The PLC's view of a tRPC router: each procedure is an async call. */
37
37
  export type ServiceClient<Procedures> = {
38
- [Key in keyof Procedures]: Procedures[Key] extends {
39
- _def: { $types: { input: infer Input; output: infer Output } };
40
- }
41
- ? (input: Input) => Promise<Output>
42
- : ServiceClient<Procedures[Key]>;
38
+ [Key in keyof Procedures]: Procedures[Key] extends {
39
+ _def: { $types: { input: infer Input; output: infer Output } };
40
+ }
41
+ ? (input: Input) => Promise<Output>
42
+ : ServiceClient<Procedures[Key]>;
43
43
  };
44
44
  /**
45
45
  * Calls the server router's `meta({ plc: true })` procedures, like a tRPC client. Import the
46
46
  * router's type with `import type`; tsPLC reads each call's wire layout from it.
47
47
  */
48
48
  export declare function createServiceClient<
49
- Router extends { _def: { record: object } },
49
+ Router extends { _def: { record: object } },
50
50
  >(): ServiceClient<Router["_def"]["record"]>;
51
51
 
52
52
  /** Cancel pending continuations in a controller or the current module. */
53
53
  export declare function cancelAsync(owner?: object): void;
54
- export declare function asyncDiagnostics(): { valid: BOOL; count: UDINT; lastError: UDINT };
54
+ export declare function asyncDiagnostics(): {
55
+ valid: BOOL;
56
+ count: UDINT;
57
+ lastError: UDINT;
58
+ };
55
59
  export declare function errorCode(reason: unknown): UDINT;
56
60
  export interface Task<A extends unknown[], R> {
57
- /** Starts the work. False while the task is busy or holds an unread result. */
58
- start(...arguments_: A): BOOL;
59
- /** The current state. After `cancel` it completes with error 1 and no result. */
60
- snapshot(): BackgroundSnapshot<R>;
61
- /** Discards the work or its unread result. False when the task is idle. */
62
- cancel(): BOOL;
63
- /** Clears a finished task so it can start again. False while it is busy. */
64
- reset(): BOOL;
61
+ /** Starts the work. False while the task is busy or holds an unread result. */
62
+ start(...arguments_: A): BOOL;
63
+ /** The current state. After `cancel` it completes with error 1 and no result. */
64
+ snapshot(): BackgroundSnapshot<R>;
65
+ /** Discards the work or its unread result. False when the task is idle. */
66
+ cancel(): BOOL;
67
+ /** Clears a finished task so it can start again. False while it is busy. */
68
+ reset(): BOOL;
65
69
  }
66
70
  /** One named, cancellable invocation of async work, advanced in the owner's scan task. */
67
71
  export declare const tasks: {
68
- define<A extends unknown[], R>(work: (...arguments_: A) => Promise<R>): Task<A, R>;
72
+ define<A extends unknown[], R>(
73
+ work: (...arguments_: A) => Promise<R>,
74
+ ): Task<A, R>;
69
75
  };
70
76
  /** @internal Compiler-owned, bounded continuation slots. */
71
77
  export declare const cooperativeTasks: {
72
- define<A extends unknown[], R>(
73
- work: (...arguments_: A) => Promise<R>,
74
- ): { start(...arguments_: A): void; cancel(): void };
78
+ define<A extends unknown[], R>(
79
+ work: (...arguments_: A) => Promise<R>,
80
+ ): { start(...arguments_: A): void; cancel(): void };
75
81
  };
76
82
 
77
83
  /** @internal Generated OPC UA service calls use the same async continuation model. */
78
84
  export declare function opcuaCall<Response, Request>(
79
- path: string,
80
- request: Request,
85
+ path: string,
86
+ request: Request,
81
87
  ): Promise<Response>;
@@ -2,30 +2,30 @@ export {};
2
2
 
3
3
  // The IEC data types alone, for host code that reads PLC declarations but must not see names that exist only in PLC programs.
4
4
  declare global {
5
- type BOOL = import("./index").BOOL;
6
- type SINT = import("./index").SINT;
7
- type USINT = import("./index").USINT;
8
- type INT = import("./index").INT;
9
- type UINT = import("./index").UINT;
10
- type DINT = import("./index").DINT;
11
- type UDINT = import("./index").UDINT;
12
- type LINT = import("./index").LINT;
13
- type ULINT = import("./index").ULINT;
14
- type BYTE = import("./index").BYTE;
15
- type WORD = import("./index").WORD;
16
- type DWORD = import("./index").DWORD;
17
- type LWORD = import("./index").LWORD;
18
- type REAL = import("./index").REAL;
19
- type LREAL = import("./index").LREAL;
20
- type TIME = import("./index").TIME;
21
- type DATE = import("./index").DATE;
22
- type TIME_OF_DAY = import("./index").TIME_OF_DAY;
23
- type DATE_AND_TIME = import("./index").DATE_AND_TIME;
24
- type FixedArray<T, N extends number, Lower extends number = 0> = import("./index").FixedArray<
25
- T,
26
- N,
27
- Lower
28
- >;
29
- type STRING<N extends number> = import("./index").STRING<N>;
30
- type WSTRING<N extends number> = import("./index").WSTRING<N>;
5
+ type BOOL = import("./index").BOOL;
6
+ type SINT = import("./index").SINT;
7
+ type USINT = import("./index").USINT;
8
+ type INT = import("./index").INT;
9
+ type UINT = import("./index").UINT;
10
+ type DINT = import("./index").DINT;
11
+ type UDINT = import("./index").UDINT;
12
+ type LINT = import("./index").LINT;
13
+ type ULINT = import("./index").ULINT;
14
+ type BYTE = import("./index").BYTE;
15
+ type WORD = import("./index").WORD;
16
+ type DWORD = import("./index").DWORD;
17
+ type LWORD = import("./index").LWORD;
18
+ type REAL = import("./index").REAL;
19
+ type LREAL = import("./index").LREAL;
20
+ type TIME = import("./index").TIME;
21
+ type DATE = import("./index").DATE;
22
+ type TIME_OF_DAY = import("./index").TIME_OF_DAY;
23
+ type DATE_AND_TIME = import("./index").DATE_AND_TIME;
24
+ type FixedArray<
25
+ T,
26
+ N extends number,
27
+ Lower extends number = 0,
28
+ > = import("./index").FixedArray<T, N, Lower>;
29
+ type STRING<N extends number> = import("./index").STRING<N>;
30
+ type WSTRING<N extends number> = import("./index").WSTRING<N>;
31
31
  }
@@ -3,44 +3,47 @@ import "./data-types";
3
3
  // Ambient spellings point to the canonical SDK types; the frontend checks this
4
4
  // declaration identity rather than trusting a same-named user alias.
5
5
  declare global {
6
- interface VoidFunction {
7
- (): void;
8
- }
9
- type Input<T> = import("./index").Input<T>;
10
- type Output<T> = import("./index").Output<T>;
6
+ interface VoidFunction {
7
+ (): void;
8
+ }
9
+ type Input<T> = import("./index").Input<T>;
10
+ type Output<T> = import("./index").Output<T>;
11
11
 
12
- type InOut<T> = import("./index").InOut<T>;
13
- type FunctionBlock<I, O = Record<never, never>> = import("./index").FunctionBlock<I, O>;
14
- const FunctionBlock: typeof import("./index").FunctionBlock;
15
- type Blinker = import("./index").Blinker;
16
- const Blinker: typeof import("./index").Blinker;
17
- type OnDelayTimer = import("./index").OnDelayTimer;
18
- const OnDelayTimer: typeof import("./index").OnDelayTimer;
19
- type OffDelayTimer = import("./index").OffDelayTimer;
20
- const OffDelayTimer: typeof import("./index").OffDelayTimer;
21
- type PulseTimer = import("./index").PulseTimer;
22
- const PulseTimer: typeof import("./index").PulseTimer;
23
- type RisingEdge = import("./index").RisingEdge;
24
- const RisingEdge: typeof import("./index").RisingEdge;
25
- type FallingEdge = import("./index").FallingEdge;
26
- const FallingEdge: typeof import("./index").FallingEdge;
27
- type UpCounter = import("./index").UpCounter;
28
- const UpCounter: typeof import("./index").UpCounter;
29
- type DownCounter = import("./index").DownCounter;
30
- const DownCounter: typeof import("./index").DownCounter;
31
- type UpDownCounter = import("./index").UpDownCounter;
32
- const UpDownCounter: typeof import("./index").UpDownCounter;
33
- const ref: typeof import("./index").ref;
34
- const retain: typeof import("./index").retain;
35
- const ms: typeof import("./index").ms;
36
- const seconds: typeof import("./index").seconds;
37
- const minutes: typeof import("./index").minutes;
38
- const timeToMilliseconds: typeof import("./index").timeToMilliseconds;
39
- const date: typeof import("./index").date;
40
- const timeOfDay: typeof import("./index").timeOfDay;
41
- const dateAndTime: typeof import("./index").dateAndTime;
12
+ type InOut<T> = import("./index").InOut<T>;
13
+ type FunctionBlock<
14
+ I,
15
+ O = Record<never, never>,
16
+ > = import("./index").FunctionBlock<I, O>;
17
+ const FunctionBlock: typeof import("./index").FunctionBlock;
18
+ type Blinker = import("./index").Blinker;
19
+ const Blinker: typeof import("./index").Blinker;
20
+ type OnDelayTimer = import("./index").OnDelayTimer;
21
+ const OnDelayTimer: typeof import("./index").OnDelayTimer;
22
+ type OffDelayTimer = import("./index").OffDelayTimer;
23
+ const OffDelayTimer: typeof import("./index").OffDelayTimer;
24
+ type PulseTimer = import("./index").PulseTimer;
25
+ const PulseTimer: typeof import("./index").PulseTimer;
26
+ type RisingEdge = import("./index").RisingEdge;
27
+ const RisingEdge: typeof import("./index").RisingEdge;
28
+ type FallingEdge = import("./index").FallingEdge;
29
+ const FallingEdge: typeof import("./index").FallingEdge;
30
+ type UpCounter = import("./index").UpCounter;
31
+ const UpCounter: typeof import("./index").UpCounter;
32
+ type DownCounter = import("./index").DownCounter;
33
+ const DownCounter: typeof import("./index").DownCounter;
34
+ type UpDownCounter = import("./index").UpDownCounter;
35
+ const UpDownCounter: typeof import("./index").UpDownCounter;
36
+ const ref: typeof import("./index").ref;
37
+ const retain: typeof import("./index").retain;
38
+ const ms: typeof import("./index").ms;
39
+ const seconds: typeof import("./index").seconds;
40
+ const minutes: typeof import("./index").minutes;
41
+ const timeToMilliseconds: typeof import("./index").timeToMilliseconds;
42
+ const date: typeof import("./index").date;
43
+ const timeOfDay: typeof import("./index").timeOfDay;
44
+ const dateAndTime: typeof import("./index").dateAndTime;
42
45
 
43
- const defaultValue: typeof import("./index").defaultValue;
44
- const copy: typeof import("./index").copy;
45
- const entries: typeof import("./index").entries;
46
+ const defaultValue: typeof import("./index").defaultValue;
47
+ const copy: typeof import("./index").copy;
48
+ const entries: typeof import("./index").entries;
46
49
  }