Skip to content

Commit 7e8d7d3

Browse files
abstraktorslisson
authored andcommitted
fix(ts-model-api): INodeJS argument types are more restrictive now
BREAKING CHANGE: methods of INodeJS don't allow strings for roles anymore
1 parent 652b277 commit 7e8d7d3

File tree

14 files changed

+208
-247
lines changed

14 files changed

+208
-247
lines changed

model-api-gen-gradle-test/typescript-generation/package-lock.json

Lines changed: 18 additions & 118 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useFakeNode } from "./test-helpers";
2+
import { toRoleJS } from "@modelix/ts-model-api";
23

34
test("typed nodes can be removed", () => {
45
const { typedNode, rootNode } = useFakeNode();
5-
expect(rootNode.getChildren("children1")).toHaveLength(1);
6+
expect(rootNode.getChildren(toRoleJS("children1"))).toHaveLength(1);
67

78
typedNode.remove();
8-
expect(rootNode.getChildren("children1")).toHaveLength(0);
9+
expect(rootNode.getChildren(toRoleJS("children1"))).toHaveLength(0);
910
});

model-api-gen-gradle-test/typescript-generation/src/test-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { org } from "@modelix/model-client";
2-
import type { ITypedNode} from "@modelix/ts-model-api";
2+
import { type ITypedNode, toRoleJS } from "@modelix/ts-model-api";
33
import { LanguageRegistry } from "@modelix/ts-model-api";
44
import { registerLanguages } from "../build/typescript_src";
55

@@ -27,7 +27,7 @@ export function useFakeRootNode(nodeData: object = DEFAULT_NODE_DATA) {
2727
);
2828

2929
function getUntypedNode(role: string = "children1") {
30-
return rootNode.getChildren(role)[0];
30+
return rootNode.getChildren(toRoleJS(role))[0];
3131
}
3232

3333
function getTypedNode<T extends ITypedNode>(role?: string) {

model-api-gen-gradle-test/vue-integration/src/intergration.test.ts renamed to model-api-gen-gradle-test/vue-integration/src/integration.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useModelsFromJson } from "@modelix/vue-model-api";
2+
import { toRoleJS } from "@modelix/ts-model-api";
23
import { computed } from "vue";
34
import { registerLanguages } from "typescript-generation";
45
import type { BaseConcept } from "typescript-generation/dist/L_jetbrains_mps_lang_core";
@@ -36,7 +37,9 @@ test("change to property is reactivly updated", () => {
3637
},
3738
};
3839

39-
const untypedNode = useRootNode(nodeData).getChildren("children1")[0];
40+
const untypedNode = useRootNode(nodeData).getChildren(
41+
toRoleJS("children1"),
42+
)[0];
4043
const typedNode = LanguageRegistry.INSTANCE.wrapNode(untypedNode);
4144
if (!isOfConcept_INamedConcept(typedNode)) {
4245
fail(`${typedNode} should be a ${C_INamedConcept}`);
@@ -78,7 +81,9 @@ test("change to children is reactivly updated", () => {
7881
],
7982
},
8083
};
81-
const untypedNode = useRootNode(nodeData).getChildren("children1")[0];
84+
const untypedNode = useRootNode(nodeData).getChildren(
85+
toRoleJS("children1"),
86+
)[0];
8287
const baseConcept = LanguageRegistry.INSTANCE.wrapNode(
8388
untypedNode,
8489
) as BaseConcept;
@@ -119,10 +124,10 @@ test("change to reference is reactivly updated", () => {
119124
};
120125
const rootNode = useRootNode(nodeData);
121126
const staticFieldReference = LanguageRegistry.INSTANCE.wrapNode(
122-
rootNode.getChildren("staticFieldReferences")[0],
127+
rootNode.getChildren(toRoleJS("staticFieldReferences"))[0],
123128
) as StaticFieldReference;
124129
const classifier = LanguageRegistry.INSTANCE.wrapNode(
125-
rootNode.getChildren("classifiers")[0],
130+
rootNode.getChildren(toRoleJS("classifiers"))[0],
126131
) as Classifier;
127132

128133
const computedClassifierName = computed(

model-api-gen/src/main/kotlin/org/modelix/metamodel/generator/TypescriptMMGenerator.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class TypescriptMMGenerator(val outputDir: Path, val nameConfig: NameConfig = Na
9393
GeneratedLanguage,
9494
IConceptJS,
9595
INodeJS,
96+
toRoleJS,
9697
ITypedNode,
9798
SingleChildAccessor,
9899
TypedNode,
@@ -132,10 +133,10 @@ class TypescriptMMGenerator(val outputDir: Path, val nameConfig: NameConfig = Na
132133
IPropertyReference.fromIdAndName(feature.uid, feature.originalName).stringForLegacyApi()
133134
val rawPropertyText = """
134135
public set $rawValueName(value: string | undefined) {
135-
this._node.setPropertyValue("$stringForLegacyApi", value)
136+
this._node.setPropertyValue(toRoleJS("$stringForLegacyApi"), value)
136137
}
137138
public get $rawValueName(): string | undefined {
138-
return this._node.getPropertyValue("$stringForLegacyApi")
139+
return this._node.getPropertyValue(toRoleJS("$stringForLegacyApi"))
139140
}
140141
"""
141142
val typedPropertyText = if (feature.type is PrimitivePropertyType) {
@@ -190,10 +191,10 @@ class TypescriptMMGenerator(val outputDir: Path, val nameConfig: NameConfig = Na
190191
IReferenceLinkReference.fromIdAndName(feature.uid, feature.originalName).stringForLegacyApi()
191192
"""
192193
public set ${feature.generatedName}(value: $entityType | undefined) {
193-
this._node.setReferenceTargetNode("$stringForLegacyApi", value?.unwrap());
194+
this._node.setReferenceTargetNode(toRoleJS("$stringForLegacyApi"), value?.unwrap());
194195
}
195196
public get ${feature.generatedName}(): $entityType | undefined {
196-
let target = this._node.getReferenceTargetNode("$stringForLegacyApi");
197+
let target = this._node.getReferenceTargetNode(toRoleJS("$stringForLegacyApi"));
197198
return target ? LanguageRegistry.INSTANCE.wrapNode(target) as $entityType : undefined;
198199
}
199200
"""
@@ -205,7 +206,7 @@ class TypescriptMMGenerator(val outputDir: Path, val nameConfig: NameConfig = Na
205206
val stringForLegacyApi =
206207
IChildLinkReference.fromIdAndName(feature.uid, feature.originalName).stringForLegacyApi()
207208
"""
208-
public ${feature.generatedName}: $accessorClassName<$languagePrefix${typeRef.nodeWrapperInterfaceName()}> = new $accessorClassName(this._node, "$stringForLegacyApi")
209+
public ${feature.generatedName}: $accessorClassName<$languagePrefix${typeRef.nodeWrapperInterfaceName()}> = new $accessorClassName(this._node, toRoleJS("$stringForLegacyApi"))
209210
"""
210211
}
211212
else -> ""

0 commit comments

Comments
 (0)