@tscircuit/circuit-json-util 0.0.114 → 0.0.115
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 +3 -3
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,14 +116,14 @@ const source_traces = su(circuitJson).source_trace.list({
|
|
|
116
116
|
For large circuit json, the library provides an optimized version with indexing for faster lookups:
|
|
117
117
|
|
|
118
118
|
```ts
|
|
119
|
-
import {
|
|
119
|
+
import { cjuIndexed } from "@tscircuit/circuit-json-util"
|
|
120
120
|
|
|
121
121
|
const circuitJson = [
|
|
122
122
|
/* large soup with many elements */
|
|
123
123
|
]
|
|
124
124
|
|
|
125
125
|
// Configure the indexes you want to use
|
|
126
|
-
const indexedSu =
|
|
126
|
+
const indexedSu = cjuIndexed(circuitJson, {
|
|
127
127
|
indexConfig: {
|
|
128
128
|
byId: true, // Index by element ID for fast .get() operations
|
|
129
129
|
byType: true, // Index by element type for fast .list() operations
|
|
@@ -142,7 +142,7 @@ const subcircuitElements = indexedSu.source_component.list({
|
|
|
142
142
|
})
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
The indexed version
|
|
145
|
+
The indexed version supports root-level `insert`, `insertAll`, and `subtree` as well as table operations. Root inserts assign IDs, including when an input supplies an ID, just like `cju`. Subtrees preserve the indexing and validation options and have their own collection; existing element objects are shared with the parent. `list()` returns a new array, so sorting or splicing it cannot modify the store's type index. The elements in that array remain live objects.
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
## Categorize DRC Errors and Warnings
|
package/dist/index.js
CHANGED
|
@@ -401,6 +401,20 @@ var cjuIndexed = ((soup, options = {}) => {
|
|
|
401
401
|
if (prop === "editCount") {
|
|
402
402
|
return internalStore.editCount;
|
|
403
403
|
}
|
|
404
|
+
if (prop === "insert") {
|
|
405
|
+
return (elm) => {
|
|
406
|
+
const { type, ...props } = elm;
|
|
407
|
+
if (!type) throw new Error("insert requires an element with a type");
|
|
408
|
+
delete props[`${type}_id`];
|
|
409
|
+
return suIndexed[type].insert(props);
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
if (prop === "insertAll") {
|
|
413
|
+
return (elms) => elms.map((elm) => suIndexed.insert(elm));
|
|
414
|
+
}
|
|
415
|
+
if (prop === "subtree") {
|
|
416
|
+
return (opts) => cjuIndexed(buildSubtree(soup, opts), options);
|
|
417
|
+
}
|
|
404
418
|
const component_type = prop;
|
|
405
419
|
return {
|
|
406
420
|
get: (id) => {
|
|
@@ -496,7 +510,7 @@ var cjuIndexed = ((soup, options = {}) => {
|
|
|
496
510
|
const indexConfig = options.indexConfig || {};
|
|
497
511
|
const keys = !where ? [] : Object.keys(where);
|
|
498
512
|
if (keys.length === 0 && indexConfig.byType && internalStore.indexes.byType) {
|
|
499
|
-
return internalStore.indexes.byType.get(component_type) || [];
|
|
513
|
+
return (internalStore.indexes.byType.get(component_type) || []).slice();
|
|
500
514
|
}
|
|
501
515
|
if (keys.length === 1 && keys[0] === "subcircuit_id" && indexConfig.bySubcircuit && internalStore.indexes.bySubcircuit) {
|
|
502
516
|
const subcircuitId = where.subcircuit_id;
|
|
@@ -516,7 +530,7 @@ var cjuIndexed = ((soup, options = {}) => {
|
|
|
516
530
|
(e) => keys.every((key) => e[key] === where[key])
|
|
517
531
|
);
|
|
518
532
|
}
|
|
519
|
-
return elementsToFilter;
|
|
533
|
+
return elementsToFilter.slice();
|
|
520
534
|
},
|
|
521
535
|
insert: (elm) => {
|
|
522
536
|
internalStore.counts[component_type] ??= -1;
|