circuit-json-to-connectivity-map 0.0.1 → 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 tscircuit Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,4 +1,13 @@
1
- # circuit-json-to-connectivity-map
1
+ # Circuit JSON to Connectivity Map
2
+
3
+ This project provides utilities to generate connectivity maps from circuit JSON data. It's designed to work with the `@tscircuit/soup` library and offers functionality to find connected networks and create source port connectivity maps.
4
+
5
+ ## Features
6
+
7
+ - Find connected networks from a list of connections
8
+ - Generate source port connectivity maps from circuit JSON data
9
+
10
+ ## Installation
2
11
 
3
12
  To install dependencies:
4
13
 
@@ -6,10 +15,60 @@ To install dependencies:
6
15
  bun install
7
16
  ```
8
17
 
9
- To run:
18
+ ## Usage
19
+
20
+ ### Finding Connected Networks
21
+
22
+ ```typescript
23
+ import { findConnectedNetworks } from "circuit-json-to-connectivity-map"
24
+
25
+ const connections = [
26
+ ["A", "B"],
27
+ ["B", "C"],
28
+ ["D", "E"],
29
+ ]
30
+
31
+ const result = findConnectedNetworks(connections)
32
+ console.log(result)
33
+ ```
34
+
35
+ ### Generating Source Port Connectivity Map
36
+
37
+ ```typescript
38
+ import { getSoupPortConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map"
39
+ import type { AnySoupElement } from "@tscircuit/soup"
40
+
41
+ const circuitJson: AnySoupElement[] = [
42
+ // Your circuit JSON data here
43
+ ]
44
+
45
+ const connectivityMap = getSoupPortConnectivityMapFromCircuitJson(circuitJson)
46
+ console.log(connectivityMap)
47
+ ```
48
+
49
+ ## Running Tests
50
+
51
+ To run the tests:
10
52
 
11
53
  ```bash
12
- bun run index.ts
54
+ bun test
13
55
  ```
14
56
 
15
- This project was created using `bun init` in bun v1.1.21. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
57
+ ## Development
58
+
59
+ This project uses [Bun](https://bun.sh) as its JavaScript runtime. Bun is a fast all-in-one JavaScript runtime.
60
+
61
+ To start development:
62
+
63
+ 1. Clone the repository
64
+ 2. Run `bun install` to install dependencies
65
+ 3. Make your changes
66
+ 4. Run `bun test` to ensure all tests pass
67
+
68
+ ## Contributing
69
+
70
+ Contributions are welcome! Please feel free to submit a Pull Request.
71
+
72
+ ## License
73
+
74
+ [MIT License](LICENSE)
package/dist/index.d.ts CHANGED
@@ -6,6 +6,6 @@ declare function findConnectedNetworks(connections: Array<NodeId[]>): Array<{
6
6
  connectedNodeIds: string[];
7
7
  }>;
8
8
 
9
- declare const getSoupPortConnectivityMapFromCircuitJson: (circuitJson: AnySoupElement[]) => Map<string, string[]>;
9
+ declare const getSourcePortConnectivityMapFromCircuitJson: (circuitJson: AnySoupElement[]) => Map<string, string[]>;
10
10
 
11
- export { findConnectedNetworks, getSoupPortConnectivityMapFromCircuitJson };
11
+ export { findConnectedNetworks, getSourcePortConnectivityMapFromCircuitJson };
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ function findConnectedNetworks(connections) {
9
9
  }
10
10
  }
11
11
  const newNetwork = /* @__PURE__ */ new Set();
12
- networks.set(`net_${netCounter++}`, newNetwork);
12
+ networks.set(`connectivity_net${netCounter++}`, newNetwork);
13
13
  return newNetwork;
14
14
  }
15
15
  for (const connection of connections) {
@@ -40,12 +40,15 @@ function findConnectedNetworks(connections) {
40
40
  }
41
41
 
42
42
  // src/getSourcePortConnectivityMapFromCircuitJson.ts
43
- var getSoupPortConnectivityMapFromCircuitJson = (circuitJson) => {
43
+ var getSourcePortConnectivityMapFromCircuitJson = (circuitJson) => {
44
44
  const connectivityMap = /* @__PURE__ */ new Map();
45
45
  const connections = [];
46
46
  for (const element of circuitJson) {
47
47
  if (element.type === "source_trace") {
48
- connections.push(element.connected_source_port_ids);
48
+ connections.push([
49
+ ...element.connected_source_port_ids,
50
+ ...element.connected_source_net_ids
51
+ ]);
49
52
  }
50
53
  }
51
54
  const connectedNetworks = findConnectedNetworks(connections);
@@ -56,6 +59,6 @@ var getSoupPortConnectivityMapFromCircuitJson = (circuitJson) => {
56
59
  };
57
60
  export {
58
61
  findConnectedNetworks,
59
- getSoupPortConnectivityMapFromCircuitJson
62
+ getSourcePortConnectivityMapFromCircuitJson
60
63
  };
61
64
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findConnectedNetworks.ts","../src/getSourcePortConnectivityMapFromCircuitJson.ts"],"sourcesContent":["type NodeId = string\n\nexport function findConnectedNetworks(\n connections: Array<NodeId[]>,\n): Array<{ netId: string; connectedNodeIds: string[] }> {\n const networks: Map<string, Set<string>> = new Map()\n let netCounter = 0\n\n function getOrCreateNetwork(nodeId: string): Set<string> {\n for (const [, network] of networks) {\n if (network.has(nodeId)) {\n return network\n }\n }\n const newNetwork = new Set<string>()\n networks.set(`net_${netCounter++}`, newNetwork)\n return newNetwork\n }\n\n for (const connection of connections) {\n let network: Set<string> | null = null\n\n for (const nodeId of connection) {\n if (!network) {\n network = getOrCreateNetwork(nodeId)\n } else if (!network.has(nodeId)) {\n const existingNetwork = getOrCreateNetwork(nodeId)\n if (existingNetwork !== network) {\n // Merge networks\n for (const node of existingNetwork) {\n network.add(node)\n }\n networks.delete(\n Array.from(networks.entries()).find(\n ([, net]) => net === existingNetwork,\n )![0],\n )\n }\n }\n network.add(nodeId)\n }\n }\n\n return Array.from(networks.entries()).map(([netId, connectedNodes]) => ({\n netId,\n connectedNodeIds: Array.from(connectedNodes),\n }))\n}\n","import type { AnySoupElement } from \"@tscircuit/soup\"\nimport { findConnectedNetworks } from \"./findConnectedNetworks\"\n\nexport const getSoupPortConnectivityMapFromCircuitJson = (\n circuitJson: AnySoupElement[],\n) => {\n const connectivityMap = new Map<string, string[]>()\n\n const connections: string[][] = []\n\n for (const element of circuitJson) {\n if (element.type === \"source_trace\") {\n connections.push(element.connected_source_port_ids)\n }\n }\n\n const connectedNetworks = findConnectedNetworks(connections)\n\n for (const network of connectedNetworks) {\n connectivityMap.set(network.netId, network.connectedNodeIds)\n }\n\n return connectivityMap\n}\n"],"mappings":";AAEO,SAAS,sBACd,aACsD;AACtD,QAAM,WAAqC,oBAAI,IAAI;AACnD,MAAI,aAAa;AAEjB,WAAS,mBAAmB,QAA6B;AACvD,eAAW,CAAC,EAAE,OAAO,KAAK,UAAU;AAClC,UAAI,QAAQ,IAAI,MAAM,GAAG;AACvB,eAAO;AAAA,MACT;AAAA,IACF;AACA,UAAM,aAAa,oBAAI,IAAY;AACnC,aAAS,IAAI,OAAO,YAAY,IAAI,UAAU;AAC9C,WAAO;AAAA,EACT;AAEA,aAAW,cAAc,aAAa;AACpC,QAAI,UAA8B;AAElC,eAAW,UAAU,YAAY;AAC/B,UAAI,CAAC,SAAS;AACZ,kBAAU,mBAAmB,MAAM;AAAA,MACrC,WAAW,CAAC,QAAQ,IAAI,MAAM,GAAG;AAC/B,cAAM,kBAAkB,mBAAmB,MAAM;AACjD,YAAI,oBAAoB,SAAS;AAE/B,qBAAW,QAAQ,iBAAiB;AAClC,oBAAQ,IAAI,IAAI;AAAA,UAClB;AACA,mBAAS;AAAA,YACP,MAAM,KAAK,SAAS,QAAQ,CAAC,EAAE;AAAA,cAC7B,CAAC,CAAC,EAAE,GAAG,MAAM,QAAQ;AAAA,YACvB,EAAG,CAAC;AAAA,UACN;AAAA,QACF;AAAA,MACF;AACA,cAAQ,IAAI,MAAM;AAAA,IACpB;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,SAAS,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,OAAO,cAAc,OAAO;AAAA,IACtE;AAAA,IACA,kBAAkB,MAAM,KAAK,cAAc;AAAA,EAC7C,EAAE;AACJ;;;AC5CO,IAAM,4CAA4C,CACvD,gBACG;AACH,QAAM,kBAAkB,oBAAI,IAAsB;AAElD,QAAM,cAA0B,CAAC;AAEjC,aAAW,WAAW,aAAa;AACjC,QAAI,QAAQ,SAAS,gBAAgB;AACnC,kBAAY,KAAK,QAAQ,yBAAyB;AAAA,IACpD;AAAA,EACF;AAEA,QAAM,oBAAoB,sBAAsB,WAAW;AAE3D,aAAW,WAAW,mBAAmB;AACvC,oBAAgB,IAAI,QAAQ,OAAO,QAAQ,gBAAgB;AAAA,EAC7D;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/findConnectedNetworks.ts","../src/getSourcePortConnectivityMapFromCircuitJson.ts"],"sourcesContent":["type NodeId = string\n\nexport function findConnectedNetworks(\n connections: Array<NodeId[]>,\n): Array<{ netId: string; connectedNodeIds: string[] }> {\n const networks: Map<string, Set<string>> = new Map()\n let netCounter = 0\n\n function getOrCreateNetwork(nodeId: string): Set<string> {\n for (const [, network] of networks) {\n if (network.has(nodeId)) {\n return network\n }\n }\n const newNetwork = new Set<string>()\n networks.set(`connectivity_net${netCounter++}`, newNetwork)\n return newNetwork\n }\n\n for (const connection of connections) {\n let network: Set<string> | null = null\n\n for (const nodeId of connection) {\n if (!network) {\n network = getOrCreateNetwork(nodeId)\n } else if (!network.has(nodeId)) {\n const existingNetwork = getOrCreateNetwork(nodeId)\n if (existingNetwork !== network) {\n // Merge networks\n for (const node of existingNetwork) {\n network.add(node)\n }\n networks.delete(\n Array.from(networks.entries()).find(\n ([, net]) => net === existingNetwork,\n )![0],\n )\n }\n }\n network.add(nodeId)\n }\n }\n\n return Array.from(networks.entries()).map(([netId, connectedNodes]) => ({\n netId,\n connectedNodeIds: Array.from(connectedNodes),\n }))\n}\n","import type { AnySoupElement } from \"@tscircuit/soup\"\nimport { findConnectedNetworks } from \"./findConnectedNetworks\"\n\nexport const getSourcePortConnectivityMapFromCircuitJson = (\n circuitJson: AnySoupElement[],\n) => {\n const connectivityMap = new Map<string, string[]>()\n\n const connections: string[][] = []\n\n for (const element of circuitJson) {\n if (element.type === \"source_trace\") {\n connections.push([\n ...element.connected_source_port_ids,\n ...element.connected_source_net_ids,\n ])\n }\n }\n\n const connectedNetworks = findConnectedNetworks(connections)\n\n for (const network of connectedNetworks) {\n connectivityMap.set(network.netId, network.connectedNodeIds)\n }\n\n return connectivityMap\n}\n"],"mappings":";AAEO,SAAS,sBACd,aACsD;AACtD,QAAM,WAAqC,oBAAI,IAAI;AACnD,MAAI,aAAa;AAEjB,WAAS,mBAAmB,QAA6B;AACvD,eAAW,CAAC,EAAE,OAAO,KAAK,UAAU;AAClC,UAAI,QAAQ,IAAI,MAAM,GAAG;AACvB,eAAO;AAAA,MACT;AAAA,IACF;AACA,UAAM,aAAa,oBAAI,IAAY;AACnC,aAAS,IAAI,mBAAmB,YAAY,IAAI,UAAU;AAC1D,WAAO;AAAA,EACT;AAEA,aAAW,cAAc,aAAa;AACpC,QAAI,UAA8B;AAElC,eAAW,UAAU,YAAY;AAC/B,UAAI,CAAC,SAAS;AACZ,kBAAU,mBAAmB,MAAM;AAAA,MACrC,WAAW,CAAC,QAAQ,IAAI,MAAM,GAAG;AAC/B,cAAM,kBAAkB,mBAAmB,MAAM;AACjD,YAAI,oBAAoB,SAAS;AAE/B,qBAAW,QAAQ,iBAAiB;AAClC,oBAAQ,IAAI,IAAI;AAAA,UAClB;AACA,mBAAS;AAAA,YACP,MAAM,KAAK,SAAS,QAAQ,CAAC,EAAE;AAAA,cAC7B,CAAC,CAAC,EAAE,GAAG,MAAM,QAAQ;AAAA,YACvB,EAAG,CAAC;AAAA,UACN;AAAA,QACF;AAAA,MACF;AACA,cAAQ,IAAI,MAAM;AAAA,IACpB;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,SAAS,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,OAAO,cAAc,OAAO;AAAA,IACtE;AAAA,IACA,kBAAkB,MAAM,KAAK,cAAc;AAAA,EAC7C,EAAE;AACJ;;;AC5CO,IAAM,8CAA8C,CACzD,gBACG;AACH,QAAM,kBAAkB,oBAAI,IAAsB;AAElD,QAAM,cAA0B,CAAC;AAEjC,aAAW,WAAW,aAAa;AACjC,QAAI,QAAQ,SAAS,gBAAgB;AACnC,kBAAY,KAAK;AAAA,QACf,GAAG,QAAQ;AAAA,QACX,GAAG,QAAQ;AAAA,MACb,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,oBAAoB,sBAAsB,WAAW;AAE3D,aAAW,WAAW,mBAAmB;AACvC,oBAAgB,IAAI,QAAQ,OAAO,QAAQ,gBAAgB;AAAA,EAC7D;AAEA,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "circuit-json-to-connectivity-map",
3
3
  "module": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.1",
5
+ "version": "0.0.3",
6
6
  "files": [
7
7
  "dist"
8
8
  ],