@ts-graphviz/common 3.0.5 → 3.0.6
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/CHANGELOG.md +11 -0
- package/README.md +2 -1
- package/lib/common.js +15 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @ts-graphviz/common
|
|
2
2
|
|
|
3
|
+
## 3.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1797](https://github.com/ts-graphviz/ts-graphviz/pull/1797) [`d527f0d`](https://github.com/ts-graphviz/ts-graphviz/commit/d527f0ded9bd6f0a8fe38a47f6505aea98905989) Thanks [@kamiazya](https://github.com/kamiazya)! - More fields are read only from the objects that own them:
|
|
8
|
+
|
|
9
|
+
- `parse` passes its options to the generated parser in an object without a prototype.
|
|
10
|
+
- Graph and subgraph ids are printed and converted only when the AST node owns them.
|
|
11
|
+
- The model type guards (`isNodeModel`, `isForwardRefNode` and the others) read `$type` and `id` from the object or its classes only.
|
|
12
|
+
- The React components and hooks read their props from own properties.
|
|
13
|
+
|
|
3
14
|
## 3.0.5
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Type information, constants, and utility functions related to the DOT language a
|
|
|
22
22
|
|
|
23
23
|
[](https://github.com/ts-graphviz/ts-graphviz)
|
|
24
24
|
[](https://www.npmjs.com/package/ts-graphviz)
|
|
25
|
-
[](https://ts-graphviz.github.io/
|
|
25
|
+
[](https://ts-graphviz.github.io/api/)
|
|
26
26
|
[](https://deepwiki.com/ts-graphviz/ts-graphviz)
|
|
27
27
|
|
|
28
28
|
[](https://github.com/sponsors/ts-graphviz)
|
|
@@ -210,6 +210,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
210
210
|
<td align="center" valign="top" width="14.28%"><a href="http://www.walterra.dev"><img src="https://avatars.githubusercontent.com/u/230104?v=4?s=100" width="100px;" alt="Walter Rafelsberger"/><br /><sub><b>Walter Rafelsberger</b></sub></a><br /><a href="#question-walterra" title="Answering Questions">💬</a></td>
|
|
211
211
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/grsjst"><img src="https://avatars.githubusercontent.com/u/4739018?v=4?s=100" width="100px;" alt="grsjst"/><br /><sub><b>grsjst</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3Agrsjst" title="Bug reports">🐛</a></td>
|
|
212
212
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/stephenirven"><img src="https://avatars.githubusercontent.com/u/4293560?v=4?s=100" width="100px;" alt="Steve"/><br /><sub><b>Steve</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3Astephenirven" title="Bug reports">🐛</a></td>
|
|
213
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/btomaj"><img src="https://avatars.githubusercontent.com/u/2638986?v=4?s=100" width="100px;" alt="poetry by"/><br /><sub><b>poetry by</b></sub></a><br /><a href="https://github.com/ts-graphviz/ts-graphviz/issues?q=author%3Abtomaj" title="Bug reports">🐛</a></td>
|
|
213
214
|
</tr>
|
|
214
215
|
</tbody>
|
|
215
216
|
</table>
|
package/lib/common.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
function isForwardRefNode(object) {
|
|
2
|
-
return typeof object === "object" && object !== null && typeof object
|
|
2
|
+
return typeof object === "object" && object !== null && typeof ownOrClassField(object, "id") === "string";
|
|
3
|
+
}
|
|
4
|
+
function ownOrClassField(object, key) {
|
|
5
|
+
for (let target = object; target !== null && target !== Object.prototype; target = Object.getPrototypeOf(target)) {
|
|
6
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
7
|
+
if (descriptor) {
|
|
8
|
+
return Object.hasOwn(descriptor, "value") ? descriptor.value : descriptor.get?.call(object);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return void 0;
|
|
3
12
|
}
|
|
4
13
|
function isNodeModel(object) {
|
|
5
|
-
return typeof object === "object" && object !== null && object
|
|
14
|
+
return typeof object === "object" && object !== null && ownOrClassField(object, "$$type") === "Node" && typeof ownOrClassField(object, "id") === "string";
|
|
6
15
|
}
|
|
7
16
|
function isNodeRef(node) {
|
|
8
17
|
return isNodeModel(node) || isForwardRefNode(node);
|
|
@@ -38,16 +47,16 @@ function toNodeRefGroup(targets) {
|
|
|
38
47
|
return targets.map((t) => toNodeRef(t));
|
|
39
48
|
}
|
|
40
49
|
function isEdgeModel(object) {
|
|
41
|
-
return typeof object === "object" && object !== null && object
|
|
50
|
+
return typeof object === "object" && object !== null && ownOrClassField(object, "$$type") === "Edge" && Array.isArray(ownOrClassField(object, "targets"));
|
|
42
51
|
}
|
|
43
52
|
function isSubgraphModel(object) {
|
|
44
|
-
return typeof object === "object" && object !== null && object
|
|
53
|
+
return typeof object === "object" && object !== null && ownOrClassField(object, "$$type") === "Subgraph";
|
|
45
54
|
}
|
|
46
55
|
function isRootGraphModel(object) {
|
|
47
|
-
return typeof object === "object" && object !== null && object
|
|
56
|
+
return typeof object === "object" && object !== null && ownOrClassField(object, "$$type") === "Graph" && typeof ownOrClassField(object, "directed") === "boolean";
|
|
48
57
|
}
|
|
49
58
|
function isAttributeListModel(object) {
|
|
50
|
-
return typeof object === "object" && object !== null && object
|
|
59
|
+
return typeof object === "object" && object !== null && ownOrClassField(object, "$$type") === "AttributeList";
|
|
51
60
|
}
|
|
52
61
|
const RootModelsContext = Object.seal({
|
|
53
62
|
// NOTE: RootModelsContext is also initialized after the model class is declared in the '@ts-graphviz/core/register-default' module.
|