@tsplc/compiler 0.2.16 → 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
|
@@ -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
|
-
|
|
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
|
-
|
|
8
|
+
return left > right ? left : right;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export function clamp<T extends number | bigint>(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
}
|
package/stdlib/telemetry.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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(): {
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
80
|
-
|
|
85
|
+
path: string,
|
|
86
|
+
request: Request,
|
|
81
87
|
): Promise<Response>;
|
package/types/data-types.d.ts
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
}
|
package/types/globals.d.ts
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
const defaultValue: typeof import("./index").defaultValue;
|
|
47
|
+
const copy: typeof import("./index").copy;
|
|
48
|
+
const entries: typeof import("./index").entries;
|
|
46
49
|
}
|