@tsplc/tmp-debug 0.0.0-stage → 0.6.3

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 (78) hide show
  1. package/README.md +38 -2
  2. package/dist/api.js +744 -0
  3. package/dist/api.js.map +12 -0
  4. package/dist/constant.js +33 -0
  5. package/dist/constant.js.map +10 -0
  6. package/dist/explain-file.js +468 -0
  7. package/dist/explain-file.js.map +11 -0
  8. package/dist/explain.js +1310 -0
  9. package/dist/explain.js.map +19 -0
  10. package/dist/format.js +214 -0
  11. package/dist/format.js.map +12 -0
  12. package/dist/index.js +4066 -0
  13. package/dist/index.js.map +44 -0
  14. package/dist/manifest.js +240 -0
  15. package/dist/manifest.js.map +10 -0
  16. package/dist/paths.js +242 -0
  17. package/dist/paths.js.map +10 -0
  18. package/package.json +72 -4
  19. package/src/adapter.ts +77 -0
  20. package/src/api.ts +446 -0
  21. package/src/app-server.ts +151 -0
  22. package/src/build-files.ts +46 -0
  23. package/src/constant.ts +41 -0
  24. package/src/debugger.ts +237 -0
  25. package/src/errors.ts +13 -0
  26. package/src/explain-expressions.ts +484 -0
  27. package/src/explain-file.ts +325 -0
  28. package/src/explain-frames.ts +155 -0
  29. package/src/explain-loops.ts +151 -0
  30. package/src/explain-operations.ts +232 -0
  31. package/src/explain-tables.ts +345 -0
  32. package/src/explain-value.ts +203 -0
  33. package/src/explain-verdicts.ts +548 -0
  34. package/src/explain.ts +82 -0
  35. package/src/hardware.ts +159 -0
  36. package/src/http.ts +218 -0
  37. package/src/index.ts +44 -0
  38. package/src/jobs.ts +139 -0
  39. package/src/login-value.ts +165 -0
  40. package/src/login.ts +315 -0
  41. package/src/manifest.ts +328 -0
  42. package/src/opcua.ts +80 -0
  43. package/src/paths.ts +363 -0
  44. package/src/requests.ts +99 -0
  45. package/src/server-cursor.ts +22 -0
  46. package/src/shown.ts +229 -0
  47. package/src/telemetry.ts +125 -0
  48. package/src/timeline.ts +148 -0
  49. package/src/trace.ts +62 -0
  50. package/src/ui/bits.ts +48 -0
  51. package/src/ui/client.ts +87 -0
  52. package/src/ui/dom.ts +61 -0
  53. package/src/ui/explain-read.ts +105 -0
  54. package/src/ui/format.ts +261 -0
  55. package/src/ui/hardware.ts +425 -0
  56. package/src/ui/header.ts +207 -0
  57. package/src/ui/health.ts +64 -0
  58. package/src/ui/index.ts +27 -0
  59. package/src/ui/jobs.ts +263 -0
  60. package/src/ui/links.ts +59 -0
  61. package/src/ui/live-value.ts +85 -0
  62. package/src/ui/main.ts +76 -0
  63. package/src/ui/overview.ts +178 -0
  64. package/src/ui/page.ts +286 -0
  65. package/src/ui/pages.ts +64 -0
  66. package/src/ui/recent-window.ts +49 -0
  67. package/src/ui/recent.ts +355 -0
  68. package/src/ui/request-trace.ts +38 -0
  69. package/src/ui/requests.ts +80 -0
  70. package/src/ui/routes.ts +98 -0
  71. package/src/ui/store.ts +295 -0
  72. package/src/ui/success-cache.ts +11 -0
  73. package/src/ui/tree.ts +162 -0
  74. package/src/ui/variables.ts +597 -0
  75. package/src/ui/why-watch.ts +11 -0
  76. package/src/ui/why.ts +694 -0
  77. package/src/values.ts +170 -0
  78. package/src/watch.ts +32 -0
@@ -0,0 +1,203 @@
1
+ import {
2
+ elementaryType,
3
+ isIntegerValued,
4
+ nanosecondsPerMillisecond,
5
+ } from "@tsplc/iec";
6
+ import { type ConstantScalar, decodeConstant } from "./constant";
7
+ import type { DebugManifest } from "./manifest";
8
+ import { typeOf } from "./paths";
9
+
10
+ /** A value as the PLC holds it: durations in nanoseconds, enums by member value. */
11
+ export type PlcValue =
12
+ | { kind: "bool"; value: boolean }
13
+ | { kind: "integer"; value: bigint }
14
+ | { kind: "float"; value: number }
15
+ | { kind: "text"; value: string }
16
+ /** The PLC clock, known to lie between `low` and `high`. */
17
+ | { kind: "interval"; low: bigint; high: bigint }
18
+ | { kind: "record"; fields: Readonly<Record<string, Outcome>> }
19
+ | { kind: "array"; lower: number; items: readonly Outcome[] }
20
+ /** An object reference: the id it holds (−1 for `undefined`) and the object's path, null for `undefined`. */
21
+ | { kind: "instance"; id: bigint; path: string | null };
22
+
23
+ /** A value, or why it isn't known, with the reasons it is only an estimate. */
24
+ export type Outcome =
25
+ | { known: true; value: PlcValue; estimate: readonly string[] }
26
+ | { known: false; reason: string; estimate: readonly string[] };
27
+
28
+ export type UnknownOutcome = Extract<Outcome, { known: false }>;
29
+
30
+ /** Three-valued truth, and `candidate` for a job step that may have run this scan or earlier. */
31
+ export type Truth = "true" | "false" | "unknown" | "candidate";
32
+
33
+ export const unknown = (
34
+ reason: string,
35
+ estimate: readonly string[] = [],
36
+ ): UnknownOutcome => ({
37
+ known: false,
38
+ reason,
39
+ estimate,
40
+ });
41
+ export const known = (
42
+ value: PlcValue,
43
+ estimate: readonly string[] = [],
44
+ ): Outcome => ({
45
+ known: true,
46
+ value,
47
+ estimate,
48
+ });
49
+ export const withEstimate = (
50
+ outcome: Outcome,
51
+ estimate: readonly string[],
52
+ ): Outcome =>
53
+ estimate.length
54
+ ? { ...outcome, estimate: [...new Set([...outcome.estimate, ...estimate])] }
55
+ : outcome;
56
+ export const merge = (...lists: readonly (readonly string[])[]): string[] => [
57
+ ...new Set(lists.flat()),
58
+ ];
59
+
60
+ export const and = (truths: readonly Truth[]): Truth => {
61
+ if (truths.includes("false")) {
62
+ return "false";
63
+ }
64
+ if (truths.includes("unknown")) {
65
+ return "unknown";
66
+ }
67
+ return truths.includes("candidate") ? "candidate" : "true";
68
+ };
69
+
70
+ const fromConstant = (scalar: ConstantScalar): PlcValue => ({
71
+ kind: "integer",
72
+ value: scalar.kind === "integer" ? scalar.value : scalar.nanoseconds,
73
+ });
74
+
75
+ /** A JSON constant of `explain.json`, or a decoded sample, as the PLC value of `type`. */
76
+ export const sampleValue = (
77
+ manifest: DebugManifest,
78
+ type: string,
79
+ decoded: unknown,
80
+ ): PlcValue | undefined => {
81
+ const declared = typeOf(manifest, type);
82
+ if (declared.kind === "enum") {
83
+ const member =
84
+ typeof decoded === "string" ? declared.members[decoded] : undefined;
85
+ if (typeof member === "number") {
86
+ return { kind: "integer", value: BigInt(member) };
87
+ }
88
+ return typeof decoded === "number" || typeof decoded === "bigint"
89
+ ? { kind: "integer", value: BigInt(decoded) }
90
+ : undefined;
91
+ }
92
+ const scalar =
93
+ declared.kind === "scalar" ? elementaryType(declared.iec) : undefined;
94
+ const constant = decodeConstant(decoded);
95
+ if (isIntegerValued(scalar)) {
96
+ if (typeof decoded === "bigint") {
97
+ return { kind: "integer", value: decoded };
98
+ }
99
+ return constant?.kind === "integer" ? fromConstant(constant) : undefined;
100
+ }
101
+ switch (scalar?.family) {
102
+ case "bool":
103
+ if (typeof decoded === "boolean") {
104
+ return { kind: "bool", value: decoded };
105
+ }
106
+ return typeof decoded === "number"
107
+ ? { kind: "bool", value: decoded !== 0 }
108
+ : undefined;
109
+ case "real":
110
+ return typeof decoded === "number"
111
+ ? { kind: "float", value: decoded }
112
+ : undefined;
113
+ case "duration":
114
+ if (typeof decoded === "number") {
115
+ return {
116
+ kind: "integer",
117
+ value: BigInt(
118
+ Math.round(decoded * Number(nanosecondsPerMillisecond)),
119
+ ),
120
+ };
121
+ }
122
+ return typeof decoded === "string" && constant?.kind === "duration"
123
+ ? fromConstant(constant)
124
+ : undefined;
125
+ case "string":
126
+ return typeof decoded === "string"
127
+ ? { kind: "text", value: decoded }
128
+ : undefined;
129
+ default:
130
+ return undefined;
131
+ }
132
+ };
133
+
134
+ /** A constant of `explain.json` whose type doesn't say how to read it, by its JSON shape. */
135
+ export const constantAggregate = (value: unknown): Outcome => {
136
+ if (Array.isArray(value)) {
137
+ return known({
138
+ kind: "array",
139
+ lower: 0,
140
+ items: value.map((item) => constantAggregate(item)),
141
+ });
142
+ }
143
+ if (typeof value === "object" && value !== null) {
144
+ return known({
145
+ kind: "record",
146
+ fields: Object.fromEntries(
147
+ Object.entries(value).map(([name, item]) => [
148
+ name,
149
+ constantAggregate(item),
150
+ ]),
151
+ ),
152
+ });
153
+ }
154
+ if (typeof value === "boolean") {
155
+ return known({ kind: "bool", value });
156
+ }
157
+ if (typeof value !== "number" && typeof value !== "string") {
158
+ return unknown("a constant this debugger can't show");
159
+ }
160
+ const constant = decodeConstant(value);
161
+ if (constant) {
162
+ return known(fromConstant(constant));
163
+ }
164
+ return known(
165
+ typeof value === "number"
166
+ ? { kind: "float", value }
167
+ : { kind: "text", value },
168
+ );
169
+ };
170
+
171
+ export const equalValues = (
172
+ left: PlcValue,
173
+ right: PlcValue,
174
+ ): boolean | undefined => {
175
+ if (left.kind === "float" || right.kind === "float") {
176
+ const leftNumber =
177
+ left.kind === "float" || left.kind === "integer"
178
+ ? Number(left.value)
179
+ : Number.NaN;
180
+ const rightNumber =
181
+ right.kind === "float" || right.kind === "integer"
182
+ ? Number(right.value)
183
+ : Number.NaN;
184
+ // REAL rounding and the login's text precision both blur the last digits.
185
+ return (
186
+ Math.abs(leftNumber - rightNumber) <=
187
+ Math.max(Math.abs(leftNumber), Math.abs(rightNumber)) * 1e-6 + 1e-9
188
+ );
189
+ }
190
+ if (left.kind === "bool" && right.kind === "bool") {
191
+ return left.value === right.value;
192
+ }
193
+ if (left.kind === "integer" && right.kind === "integer") {
194
+ return left.value === right.value;
195
+ }
196
+ if (left.kind === "text" && right.kind === "text") {
197
+ return left.value === right.value;
198
+ }
199
+ if (left.kind === "instance" && right.kind === "instance") {
200
+ return left.path === right.path;
201
+ }
202
+ return undefined;
203
+ };