@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
@@ -45,46 +45,58 @@ plugin({
45
45
  });
46
46
  globalThis.__tsplcService = service;
47
47
  var modules = new Map;
48
- for (const file of [request.entry, ...request.files.filter((file) => file !== request.entry)]) {
48
+ for (const file of [
49
+ request.entry,
50
+ ...request.files.filter((file) => file !== request.entry)
51
+ ]) {
49
52
  const loaded = await import(realpathSync(file));
50
53
  modules.set(file, loaded[exportName]);
51
54
  }
52
55
  var classes = new Map;
53
56
  var functions = new Map;
54
57
  for (const [file, registry] of modules) {
55
- for (const [name, value] of Object.entries(registry.classes))
58
+ for (const [name, value] of Object.entries(registry.classes)) {
56
59
  classes.set(value, { file, name });
57
- for (const [name, value] of Object.entries(registry.functions))
60
+ }
61
+ for (const [name, value] of Object.entries(registry.functions)) {
58
62
  functions.set(value, { file, name });
63
+ }
59
64
  }
60
65
  var nodes = [];
61
66
  var ids = new Map;
62
67
  var capture = (value, where) => {
63
- if (value === undefined)
68
+ if (value === undefined) {
64
69
  return { kind: "undefined" };
65
- if (value === null)
70
+ }
71
+ if (value === null) {
66
72
  throw new Error(`${where}: null has no PLC value; use undefined.`);
67
- if (typeof value === "number" || typeof value === "boolean" || typeof value === "string")
73
+ }
74
+ if (typeof value === "number" || typeof value === "boolean" || typeof value === "string") {
68
75
  return { kind: typeof value, value };
69
- if (typeof value === "bigint")
76
+ }
77
+ if (typeof value === "bigint") {
70
78
  return { kind: "bigint", value: String(value) };
71
- if (typeof value !== "object" && typeof value !== "function")
79
+ }
80
+ if (typeof value !== "object" && typeof value !== "function") {
72
81
  throw new Error(`${where}: a ${typeof value} has no PLC value.`);
82
+ }
73
83
  const known = ids.get(value);
74
- if (known !== undefined)
84
+ if (known !== undefined) {
75
85
  return { kind: "node", id: known };
86
+ }
76
87
  const id = nodes.length;
77
88
  ids.set(value, id);
78
89
  nodes.push({ kind: "object", fields: {} });
79
90
  if (typeof value === "function") {
80
91
  const path = value[servicePath];
81
92
  const named = functions.get(value) ?? classes.get(value);
82
- if (path !== undefined)
93
+ if (path !== undefined) {
83
94
  nodes[id] = { kind: "service", path };
84
- else if (named)
95
+ } else if (named) {
85
96
  nodes[id] = { kind: "function", ...named };
86
- else
97
+ } else {
87
98
  throw new Error(`${where}: setup stored a function that is not a module-level function, so the PLC can't call it.`);
99
+ }
88
100
  return { kind: "node", id };
89
101
  }
90
102
  if (Array.isArray(value)) {
@@ -97,16 +109,18 @@ var capture = (value, where) => {
97
109
  const prototype = Object.getPrototypeOf(value);
98
110
  const owner = prototype === Object.prototype || prototype === null ? undefined : prototype.constructor;
99
111
  const registered = owner && classes.get(owner);
100
- if (owner && !registered)
112
+ if (owner && !registered) {
101
113
  throw new Error(`${where}: a ${owner.name} has no PLC layout; use a class from the program.`);
114
+ }
102
115
  const fields = {};
103
- for (const [key, field] of Object.entries(value))
116
+ for (const [key, field] of Object.entries(value)) {
104
117
  fields[key] = capture(field, `${where}.${key}`);
118
+ }
105
119
  nodes[id] = registered ? { kind: "instance", ...registered, fields } : { kind: "object", fields };
106
120
  return { kind: "node", id };
107
121
  };
108
122
  var graph = { nodes, bindings: [] };
109
- for (const [file, registry] of modules)
123
+ for (const [file, registry] of modules) {
110
124
  for (const [name, read] of Object.entries(registry.values)) {
111
125
  let value;
112
126
  try {
@@ -114,11 +128,13 @@ for (const [file, registry] of modules)
114
128
  } catch {
115
129
  continue;
116
130
  }
117
- if (typeof value === "function" && (functions.has(value) || classes.has(value)))
131
+ if (typeof value === "function" && (functions.has(value) || classes.has(value))) {
118
132
  continue;
133
+ }
119
134
  graph.bindings.push({ file, name, value: capture(value, name) });
120
135
  }
136
+ }
121
137
  process.stdout.write(JSON.stringify(graph));
122
138
 
123
- //# debugId=B296E8EE33D393D564756E2164756E21
139
+ //# debugId=3CF60731C59A118B64756E2164756E21
124
140
  //# sourceMappingURL=elaborate-capture.js.map
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/frontend/elaborate/capture.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Runs a program's setup code in Bun and prints the object graph it builds: every module binding,\n * and every object, array, class instance and function reachable from them. The compiler runs\n * this in a subprocess (graph.ts), so setup code never shares the compiler's process.\n *\n * Usage: bun capture.ts <request.json>\n */\nimport { plugin } from \"bun\";\nimport { readFileSync, realpathSync } from \"node:fs\";\nimport type { CaptureRequest, CapturedGraph, CapturedValue, CapturedNode } from \"./graph.ts\";\n\nconst request: CaptureRequest = JSON.parse(readFileSync(process.argv[2]!, \"utf8\"));\n// Bun loads modules by their real path; the compiler may name them through a symlink.\nconst real = new Map(request.files.map((file) => [realpathSync(file), file]));\nconst runtime = new Set(real.keys());\nconst exportName = \"__tsplcCapture\";\n\n/** Top-level bindings a module declares, so captured state can be traced back to its source. */\nconst bindings = (source: string, names: CaptureRequest[\"bindings\"][string]) =>\n `${source}\\n;export const ${exportName} = { values: { ${names.values\n .map((name) => `${JSON.stringify(name)}: () => ${name}`)\n .join(\", \")} }, classes: { ${names.classes\n .map((name) => `${JSON.stringify(name)}: ${name}`)\n .join(\", \")} }, functions: { ${names.functions\n .map((name) => `${JSON.stringify(name)}: ${name}`)\n .join(\", \")} } };\\n`;\n\nconst servicePath = Symbol(\"tsplc service path\");\n/** A service client: any property is a deeper procedure path, and its identity names that path. */\nconst service = (path: readonly string[]): unknown =>\n new Proxy(function serviceProcedure() {}, {\n get: (_, key) => (key === servicePath ? path.join(\".\") : service([...path, String(key)])),\n apply: () => {\n throw new Error(`Setup code called the PLC service ${path.join(\".\")}.`);\n },\n });\n\nplugin({\n name: \"tsplc-capture\",\n setup(build) {\n build.onLoad(\n {\n filter: new RegExp(\n `^(${[...runtime].map((file) => file.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")).join(\"|\")})$`,\n ),\n },\n ({ path }) => ({\n contents: bindings(readFileSync(path, \"utf8\"), request.bindings[real.get(path)!]!),\n loader: \"ts\",\n }),\n );\n // Setup runs before the first scan, so the clock reads 0 there.\n build.module(\"@tsplc/compiler/clock\", () => ({\n contents: \"export const now = () => 0;\",\n loader: \"js\",\n }));\n // Records describe scans, so setup has none to make.\n build.module(\"@tsplc/compiler/telemetry\", () => ({\n contents: `const unsupported = (name) => () => { throw new Error(\"telemetry.\" + name + \" cannot run during PLC setup.\"); };\n export const telemetry = Object.fromEntries([\"capture\", \"info\", \"warn\", \"error\", \"captureException\", \"text\"].map((name) => [name, unsupported(name)]));\n export const onTelemetry = () => () => {};`,\n loader: \"js\",\n }));\n build.module(\"@tsplc/compiler/async\", () => ({\n contents: `export const createServiceClient = () => globalThis.__tsplcService([]);\n const unsupported = (name) => () => { throw new Error(name + \" cannot run during PLC setup.\"); };\n export const sleep = unsupported(\"sleep\"), fetch = unsupported(\"fetch\"), cancelAsync = unsupported(\"cancelAsync\");`,\n loader: \"js\",\n }));\n },\n});\n(globalThis as { __tsplcService?: unknown }).__tsplcService = service;\n\nconst modules = new Map<string, Record<string, Record<string, unknown>>>();\nfor (const file of [request.entry, ...request.files.filter((file) => file !== request.entry)]) {\n const loaded = (await import(realpathSync(file))) as Record<string, unknown>;\n modules.set(file, loaded[exportName] as Record<string, Record<string, unknown>>);\n}\n\nconst classes = new Map<unknown, { file: string; name: string }>();\nconst functions = new Map<unknown, { file: string; name: string }>();\nfor (const [file, registry] of modules) {\n for (const [name, value] of Object.entries(registry.classes!)) classes.set(value, { file, name });\n for (const [name, value] of Object.entries(registry.functions!))\n functions.set(value, { file, name });\n}\n\nconst nodes: CapturedNode[] = [];\nconst ids = new Map<object, number>();\nconst capture = (value: unknown, where: string): CapturedValue => {\n if (value === undefined) return { kind: \"undefined\" };\n if (value === null) throw new Error(`${where}: null has no PLC value; use undefined.`);\n if (typeof value === \"number\" || typeof value === \"boolean\" || typeof value === \"string\")\n return { kind: typeof value, value } as CapturedValue;\n if (typeof value === \"bigint\") return { kind: \"bigint\", value: String(value) };\n if (typeof value !== \"object\" && typeof value !== \"function\")\n throw new Error(`${where}: a ${typeof value} has no PLC value.`);\n const known = ids.get(value);\n if (known !== undefined) return { kind: \"node\", id: known };\n const id = nodes.length;\n ids.set(value, id);\n nodes.push({ kind: \"object\", fields: {} });\n if (typeof value === \"function\") {\n const path = (value as { [servicePath]?: string })[servicePath];\n const named = functions.get(value) ?? classes.get(value);\n if (path !== undefined) nodes[id] = { kind: \"service\", path };\n else if (named) nodes[id] = { kind: \"function\", ...named };\n else\n throw new Error(\n `${where}: setup stored a function that is not a module-level function, so the PLC can't call it.`,\n );\n return { kind: \"node\", id };\n }\n if (Array.isArray(value)) {\n nodes[id] = {\n kind: \"array\",\n items: value.map((item, index) => capture(item, `${where}[${index}]`)),\n };\n return { kind: \"node\", id };\n }\n const prototype = Object.getPrototypeOf(value);\n const owner =\n prototype === Object.prototype || prototype === null ? undefined : prototype.constructor;\n const registered = owner && classes.get(owner);\n if (owner && !registered)\n throw new Error(`${where}: a ${owner.name} has no PLC layout; use a class from the program.`);\n const fields: Record<string, CapturedValue> = {};\n for (const [key, field] of Object.entries(value)) fields[key] = capture(field, `${where}.${key}`);\n nodes[id] = registered ? { kind: \"instance\", ...registered, fields } : { kind: \"object\", fields };\n return { kind: \"node\", id };\n};\n\nconst graph: CapturedGraph = { nodes, bindings: [] };\nfor (const [file, registry] of modules)\n for (const [name, read] of Object.entries(registry.values!)) {\n let value: unknown;\n try {\n value = (read as () => unknown)();\n } catch {\n continue; // A binding the module never initialized.\n }\n if (typeof value === \"function\" && (functions.has(value) || classes.has(value))) continue;\n graph.bindings.push({ file, name, value: capture(value, name) });\n }\nprocess.stdout.write(JSON.stringify(graph));\n"
5
+ "/**\n * Runs a program's setup code in Bun and prints the object graph it builds: every module binding,\n * and every object, array, class instance and function reachable from them. The compiler runs\n * this in a subprocess (graph.ts), so setup code never shares the compiler's process.\n *\n * Usage: bun capture.ts <request.json>\n */\nimport { plugin } from \"bun\";\nimport { readFileSync, realpathSync } from \"node:fs\";\nimport type {\n\tCaptureRequest,\n\tCapturedGraph,\n\tCapturedValue,\n\tCapturedNode,\n} from \"./graph.ts\";\n\nconst request: CaptureRequest = JSON.parse(\n\treadFileSync(process.argv[2]!, \"utf8\"),\n);\n// Bun loads modules by their real path; the compiler may name them through a symlink.\nconst real = new Map(request.files.map((file) => [realpathSync(file), file]));\nconst runtime = new Set(real.keys());\nconst exportName = \"__tsplcCapture\";\n\n/** Top-level bindings a module declares, so captured state can be traced back to its source. */\nconst bindings = (source: string, names: CaptureRequest[\"bindings\"][string]) =>\n\t`${source}\\n;export const ${exportName} = { values: { ${names.values\n\t\t.map((name) => `${JSON.stringify(name)}: () => ${name}`)\n\t\t.join(\", \")} }, classes: { ${names.classes\n\t\t.map((name) => `${JSON.stringify(name)}: ${name}`)\n\t\t.join(\", \")} }, functions: { ${names.functions\n\t\t.map((name) => `${JSON.stringify(name)}: ${name}`)\n\t\t.join(\", \")} } };\\n`;\n\nconst servicePath = Symbol(\"tsplc service path\");\n/** A service client: any property is a deeper procedure path, and its identity names that path. */\nconst service = (path: readonly string[]): unknown =>\n\tnew Proxy(function serviceProcedure() {}, {\n\t\tget: (_, key) =>\n\t\t\tkey === servicePath ? path.join(\".\") : service([...path, String(key)]),\n\t\tapply: () => {\n\t\t\tthrow new Error(`Setup code called the PLC service ${path.join(\".\")}.`);\n\t\t},\n\t});\n\nplugin({\n\tname: \"tsplc-capture\",\n\tsetup(build) {\n\t\tbuild.onLoad(\n\t\t\t{\n\t\t\t\tfilter: new RegExp(\n\t\t\t\t\t`^(${[...runtime].map((file) => file.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")).join(\"|\")})$`,\n\t\t\t\t),\n\t\t\t},\n\t\t\t({ path }) => ({\n\t\t\t\tcontents: bindings(\n\t\t\t\t\treadFileSync(path, \"utf8\"),\n\t\t\t\t\trequest.bindings[real.get(path)!]!,\n\t\t\t\t),\n\t\t\t\tloader: \"ts\",\n\t\t\t}),\n\t\t);\n\t\t// Setup runs before the first scan, so the clock reads 0 there.\n\t\tbuild.module(\"@tsplc/compiler/clock\", () => ({\n\t\t\tcontents: \"export const now = () => 0;\",\n\t\t\tloader: \"js\",\n\t\t}));\n\t\t// Records describe scans, so setup has none to make.\n\t\tbuild.module(\"@tsplc/compiler/telemetry\", () => ({\n\t\t\tcontents: `const unsupported = (name) => () => { throw new Error(\"telemetry.\" + name + \" cannot run during PLC setup.\"); };\n export const telemetry = Object.fromEntries([\"capture\", \"info\", \"warn\", \"error\", \"captureException\", \"text\"].map((name) => [name, unsupported(name)]));\n export const onTelemetry = () => () => {};`,\n\t\t\tloader: \"js\",\n\t\t}));\n\t\tbuild.module(\"@tsplc/compiler/async\", () => ({\n\t\t\tcontents: `export const createServiceClient = () => globalThis.__tsplcService([]);\n const unsupported = (name) => () => { throw new Error(name + \" cannot run during PLC setup.\"); };\n export const sleep = unsupported(\"sleep\"), fetch = unsupported(\"fetch\"), cancelAsync = unsupported(\"cancelAsync\");`,\n\t\t\tloader: \"js\",\n\t\t}));\n\t},\n});\n(globalThis as { __tsplcService?: unknown }).__tsplcService = service;\n\n/** The bindings each runtime module exports for capture, as `bindings` above adds them. */\ninterface Registry {\n\tvalues: Record<string, () => unknown>;\n\tclasses: Record<string, unknown>;\n\tfunctions: Record<string, unknown>;\n}\n\nconst modules = new Map<string, Registry>();\nfor (const file of [\n\trequest.entry,\n\t...request.files.filter((file) => file !== request.entry),\n]) {\n\tconst loaded = (await import(realpathSync(file))) as Record<string, unknown>;\n\tmodules.set(file, loaded[exportName] as Registry);\n}\n\nconst classes = new Map<unknown, { file: string; name: string }>();\nconst functions = new Map<unknown, { file: string; name: string }>();\nfor (const [file, registry] of modules) {\n\tfor (const [name, value] of Object.entries(registry.classes)) {\n\t\tclasses.set(value, { file, name });\n\t}\n\tfor (const [name, value] of Object.entries(registry.functions)) {\n\t\tfunctions.set(value, { file, name });\n\t}\n}\n\nconst nodes: CapturedNode[] = [];\nconst ids = new Map<object, number>();\nconst capture = (value: unknown, where: string): CapturedValue => {\n\tif (value === undefined) {\n\t\treturn { kind: \"undefined\" };\n\t}\n\tif (value === null) {\n\t\tthrow new Error(`${where}: null has no PLC value; use undefined.`);\n\t}\n\tif (\n\t\ttypeof value === \"number\" ||\n\t\ttypeof value === \"boolean\" ||\n\t\ttypeof value === \"string\"\n\t) {\n\t\treturn { kind: typeof value, value } as CapturedValue;\n\t}\n\tif (typeof value === \"bigint\") {\n\t\treturn { kind: \"bigint\", value: String(value) };\n\t}\n\tif (typeof value !== \"object\" && typeof value !== \"function\") {\n\t\tthrow new Error(`${where}: a ${typeof value} has no PLC value.`);\n\t}\n\tconst known = ids.get(value);\n\tif (known !== undefined) {\n\t\treturn { kind: \"node\", id: known };\n\t}\n\tconst id = nodes.length;\n\tids.set(value, id);\n\tnodes.push({ kind: \"object\", fields: {} });\n\tif (typeof value === \"function\") {\n\t\tconst path = (value as { [servicePath]?: string })[servicePath];\n\t\tconst named = functions.get(value) ?? classes.get(value);\n\t\tif (path !== undefined) {\n\t\t\tnodes[id] = { kind: \"service\", path };\n\t\t} else if (named) {\n\t\t\tnodes[id] = { kind: \"function\", ...named };\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`${where}: setup stored a function that is not a module-level function, so the PLC can't call it.`,\n\t\t\t);\n\t\t}\n\t\treturn { kind: \"node\", id };\n\t}\n\tif (Array.isArray(value)) {\n\t\tnodes[id] = {\n\t\t\tkind: \"array\",\n\t\t\titems: value.map((item, index) => capture(item, `${where}[${index}]`)),\n\t\t};\n\t\treturn { kind: \"node\", id };\n\t}\n\tconst prototype = Object.getPrototypeOf(value);\n\tconst owner =\n\t\tprototype === Object.prototype || prototype === null\n\t\t\t? undefined\n\t\t\t: prototype.constructor;\n\tconst registered = owner && classes.get(owner);\n\tif (owner && !registered) {\n\t\tthrow new Error(\n\t\t\t`${where}: a ${owner.name} has no PLC layout; use a class from the program.`,\n\t\t);\n\t}\n\tconst fields: Record<string, CapturedValue> = {};\n\tfor (const [key, field] of Object.entries(value)) {\n\t\tfields[key] = capture(field, `${where}.${key}`);\n\t}\n\tnodes[id] = registered\n\t\t? { kind: \"instance\", ...registered, fields }\n\t\t: { kind: \"object\", fields };\n\treturn { kind: \"node\", id };\n};\n\nconst graph: CapturedGraph = { nodes, bindings: [] };\nfor (const [file, registry] of modules) {\n\tfor (const [name, read] of Object.entries(registry.values)) {\n\t\tlet value: unknown;\n\t\ttry {\n\t\t\tvalue = read();\n\t\t} catch {\n\t\t\tcontinue; // A binding the module never initialized.\n\t\t}\n\t\tif (\n\t\t\ttypeof value === \"function\" &&\n\t\t\t(functions.has(value) || classes.has(value))\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tgraph.bindings.push({ file, name, value: capture(value, name) });\n\t}\n}\nprocess.stdout.write(JSON.stringify(graph));\n"
6
6
  ],
7
- "mappings": ";;AAOA;AACA;AAGA,IAAM,UAA0B,KAAK,MAAM,aAAa,QAAQ,KAAK,IAAK,MAAM,CAAC;AAEjF,IAAM,OAAO,IAAI,IAAI,QAAQ,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,IAAI,GAAG,IAAI,CAAC,CAAC;AAC5E,IAAM,UAAU,IAAI,IAAI,KA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