@tsplc/typegen 0.5.3 → 0.5.4

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/dist/index.js CHANGED
@@ -1205,56 +1205,12 @@ async function deviceTree(config, catalog) {
1205
1205
  }
1206
1206
  return { ethernet: settings.ethernet ?? {}, devices: [first, ...rest] };
1207
1207
  }
1208
- // packages/typegen/src/hardware/mapping-types.ts
1209
- import { ioScalarBits } from "@tsplc/iec";
1210
- var directBinding = (layout) => {
1211
- const scalar = layout.replace(/^\d+x/, "");
1212
- const integer = /^INT(\d+)$/.exec(scalar);
1213
- const bits = integer ? Number(integer[1]) : ioScalarBits(scalar);
1214
- const size = bits === undefined ? undefined : addressSize(bits);
1215
- if (!size) {
1216
- return;
1217
- }
1218
- return size === "X" ? '{ address: `%${"I" | "Q"}X${number}.${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7}`; type?: string }' : `{ address: \`%\${"I" | "Q"}${size}\${number}\`; type?: string }`;
1219
- };
1220
- function generateHardwareTypes(catalog, targets, publication, ioTypes = true) {
1221
- const selectors = publication?.map((selector) => JSON.stringify(selector)).join(" | ") ?? "string";
1222
- const publicationTypes = `// Generated by tsPLC. Run tsplc typegen after changing EDS files, device selections or PLC storage.
1223
- export type PublicationSelector = ${selectors || "never"};
1224
- export type PlcPublication = { readonly production: readonly PublicationSelector[]; readonly development: readonly PublicationSelector[] };
1225
- `;
1226
- if (!ioTypes) {
1227
- return publicationTypes;
1228
- }
1229
- const channel = (device, id, options) => `{ device: ${JSON.stringify(device)}; channel: ${JSON.stringify(id)}${options} }`;
1230
- const channels = catalog.devices.flatMap((device) => device.channels.filter((item) => item.address).map((item) => ({
1231
- binding: channel(device.id, item.id, item.direction === "input" && item.type === "BOOL" ? "; inverted?: boolean; shared?: boolean" : ""),
1232
- layout: ioLayout(item.type)
1233
- })));
1234
- const direct = '{ address: `%${"I" | "Q"}${"B" | "W" | "D"}${number}` | `%${"I" | "Q"}X${number}.${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7}`; type?: string }';
1235
- const anyBinding = [...channels.map((item) => item.binding), direct].join(`
1236
- | `);
1237
- const mapping = targets ? [...new Set(targets.map((target) => target.layout))].sort().map((layout) => {
1238
- const keys = targets.filter((target) => target.layout === layout).map((target) => `\`${target.key}\``);
1239
- const bindings = [
1240
- ...channels.filter((item) => item.layout === layout).map((item) => item.binding),
1241
- directBinding(layout)
1242
- ].filter(Boolean);
1243
- return `{
1244
- readonly [K in ${keys.join(" | ")}]?: ${bindings.join(" | ") || "never"};
1245
- }`;
1246
- }).join(" & ") || "Readonly<Record<string, never>>" : "Readonly<Record<string, HardwareIoBinding>>";
1247
- return `${publicationTypes}export type HardwareIoBinding = ${anyBinding};
1248
- export type HardwareIoMapping = ${mapping};
1249
- export const hardware = ${JSON.stringify(catalog, null, 2)} as const;
1250
- `;
1251
- }
1252
1208
  // packages/typegen/src/hardware.ts
1253
1209
  import { readdir as readdir2, readFile as readFile3 } from "node:fs/promises";
1254
1210
  import { resolve } from "node:path";
1255
1211
 
1256
1212
  // packages/typegen/src/hardware/channels.ts
1257
- import { ioScalarBits as ioScalarBits2 } from "@tsplc/iec";
1213
+ import { ioScalarBits } from "@tsplc/iec";
1258
1214
  function assemblyChannels({
1259
1215
  device,
1260
1216
  direction,
@@ -1317,7 +1273,7 @@ function assemblyChannels({
1317
1273
  const count = counts.get(name) ?? 0;
1318
1274
  counts.set(name, count + 1);
1319
1275
  const key = `${prefix}.${name}${repeated.has(name) ? `[${count}]` : ""}`;
1320
- const scalarBits = ioScalarBits2(member.type);
1276
+ const scalarBits = ioScalarBits(member.type);
1321
1277
  const channel = {
1322
1278
  device,
1323
1279
  id: key,
@@ -1462,6 +1418,53 @@ function selectAssemblies(id, settings, descriptor, connection) {
1462
1418
 
1463
1419
  // packages/typegen/src/hardware.ts
1464
1420
  import { ioScalarBits as ioScalarBits3 } from "@tsplc/iec";
1421
+
1422
+ // packages/typegen/src/hardware/mapping-types.ts
1423
+ import { ioScalarBits as ioScalarBits2 } from "@tsplc/iec";
1424
+ var directBinding = (layout) => {
1425
+ const scalar = layout.replace(/^\d+x/, "");
1426
+ const integer = /^INT(\d+)$/.exec(scalar);
1427
+ const bits = integer ? Number(integer[1]) : ioScalarBits2(scalar);
1428
+ const size = bits === undefined ? undefined : addressSize(bits);
1429
+ if (!size) {
1430
+ return;
1431
+ }
1432
+ return size === "X" ? '{ address: `%${"I" | "Q"}X${number}.${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7}`; type?: string }' : `{ address: \`%\${"I" | "Q"}${size}\${number}\`; type?: string }`;
1433
+ };
1434
+ function generateHardwareTypes(catalog, targets, publication, ioTypes = true) {
1435
+ const selectors = publication?.map((selector) => JSON.stringify(selector)).join(" | ") ?? "string";
1436
+ const publicationTypes = `// Generated by tsPLC. Run tsplc typegen after changing EDS files, device selections or PLC storage.
1437
+ export type PublicationSelector = ${selectors || "never"};
1438
+ export type PlcPublication = { readonly production: readonly PublicationSelector[]; readonly development: readonly PublicationSelector[] };
1439
+ `;
1440
+ if (!ioTypes) {
1441
+ return publicationTypes;
1442
+ }
1443
+ const channel = (device, id, options) => `{ device: ${JSON.stringify(device)}; channel: ${JSON.stringify(id)}${options} }`;
1444
+ const channels = catalog.devices.flatMap((device) => device.channels.filter((item) => item.address).map((item) => ({
1445
+ binding: channel(device.id, item.id, item.direction === "input" && item.type === "BOOL" ? "; inverted?: boolean; shared?: boolean" : ""),
1446
+ layout: ioLayout(item.type)
1447
+ })));
1448
+ const direct = '{ address: `%${"I" | "Q"}${"B" | "W" | "D"}${number}` | `%${"I" | "Q"}X${number}.${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7}`; type?: string }';
1449
+ const anyBinding = [...channels.map((item) => item.binding), direct].join(`
1450
+ | `);
1451
+ const mapping = targets ? [...new Set(targets.map((target) => target.layout))].sort().map((layout) => {
1452
+ const keys = targets.filter((target) => target.layout === layout).map((target) => `\`${target.key}\``);
1453
+ const bindings = [
1454
+ ...channels.filter((item) => item.layout === layout).map((item) => item.binding),
1455
+ directBinding(layout)
1456
+ ].filter(Boolean);
1457
+ return `{
1458
+ readonly [K in ${keys.join(" | ")}]?: ${bindings.join(" | ") || "never"};
1459
+ }`;
1460
+ }).join(" & ") || "Readonly<Record<string, never>>" : "Readonly<Record<string, HardwareIoBinding>>";
1461
+ return `${publicationTypes}export type HardwareIoBinding = ${anyBinding};
1462
+ export type HardwareIoMapping = ${mapping};
1463
+ export const hardware = ${JSON.stringify(catalog, null, 2)} as const;
1464
+ `;
1465
+ }
1466
+
1467
+ // packages/typegen/src/hardware.ts
1465
1468
  async function edsFiles(directory) {
1466
1469
  const entries = await readdir2(directory, { withFileTypes: true }).catch((cause) => {
1467
1470
  if (cause && typeof cause === "object" && "code" in cause && cause.code === "ENOENT") {
@@ -1772,5 +1775,5 @@ export {
1772
1775
  resolveIo
1773
1776
  };
1774
1777
 
1775
- //# debugId=6D922A9E33BA4A4164756E2164756E21
1778
+ //# debugId=B34A72964855D25464756E2164756E21
1776
1779
  //# sourceMappingURL=index.js.map