@typespec/mutator-framework 0.12.0
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 +21 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mutation/index.d.ts +13 -0
- package/dist/src/mutation/index.d.ts.map +1 -0
- package/dist/src/mutation/index.js +13 -0
- package/dist/src/mutation/index.js.map +1 -0
- package/dist/src/mutation/interface.d.ts +11 -0
- package/dist/src/mutation/interface.d.ts.map +1 -0
- package/dist/src/mutation/interface.js +17 -0
- package/dist/src/mutation/interface.js.map +1 -0
- package/dist/src/mutation/intrinsic.d.ts +9 -0
- package/dist/src/mutation/intrinsic.d.ts.map +1 -0
- package/dist/src/mutation/intrinsic.js +11 -0
- package/dist/src/mutation/intrinsic.js.map +1 -0
- package/dist/src/mutation/literal.d.ts +9 -0
- package/dist/src/mutation/literal.d.ts.map +1 -0
- package/dist/src/mutation/literal.js +11 -0
- package/dist/src/mutation/literal.js.map +1 -0
- package/dist/src/mutation/model-property.d.ts +12 -0
- package/dist/src/mutation/model-property.d.ts.map +1 -0
- package/dist/src/mutation/model-property.js +18 -0
- package/dist/src/mutation/model-property.js.map +1 -0
- package/dist/src/mutation/model.d.ts +18 -0
- package/dist/src/mutation/model.d.ts.map +1 -0
- package/dist/src/mutation/model.js +34 -0
- package/dist/src/mutation/model.js.map +1 -0
- package/dist/src/mutation/mutation-engine.d.ts +80 -0
- package/dist/src/mutation/mutation-engine.d.ts.map +1 -0
- package/dist/src/mutation/mutation-engine.js +165 -0
- package/dist/src/mutation/mutation-engine.js.map +1 -0
- package/dist/src/mutation/mutation-engine.test.d.ts +2 -0
- package/dist/src/mutation/mutation-engine.test.d.ts.map +1 -0
- package/dist/src/mutation/mutation-engine.test.js +145 -0
- package/dist/src/mutation/mutation-engine.test.js.map +1 -0
- package/dist/src/mutation/mutation.d.ts +45 -0
- package/dist/src/mutation/mutation.d.ts.map +1 -0
- package/dist/src/mutation/mutation.js +29 -0
- package/dist/src/mutation/mutation.js.map +1 -0
- package/dist/src/mutation/operation.d.ts +13 -0
- package/dist/src/mutation/operation.d.ts.map +1 -0
- package/dist/src/mutation/operation.js +20 -0
- package/dist/src/mutation/operation.js.map +1 -0
- package/dist/src/mutation/scalar.d.ts +11 -0
- package/dist/src/mutation/scalar.d.ts.map +1 -0
- package/dist/src/mutation/scalar.js +17 -0
- package/dist/src/mutation/scalar.js.map +1 -0
- package/dist/src/mutation/simple-mutation-engine.d.ts +8 -0
- package/dist/src/mutation/simple-mutation-engine.d.ts.map +1 -0
- package/dist/src/mutation/simple-mutation-engine.js +11 -0
- package/dist/src/mutation/simple-mutation-engine.js.map +1 -0
- package/dist/src/mutation/union-variant.d.ts +10 -0
- package/dist/src/mutation/union-variant.d.ts.map +1 -0
- package/dist/src/mutation/union-variant.js +12 -0
- package/dist/src/mutation/union-variant.js.map +1 -0
- package/dist/src/mutation/union.d.ts +11 -0
- package/dist/src/mutation/union.d.ts.map +1 -0
- package/dist/src/mutation/union.js +18 -0
- package/dist/src/mutation/union.js.map +1 -0
- package/dist/src/mutation-node/enum-member.d.ts +7 -0
- package/dist/src/mutation-node/enum-member.d.ts.map +1 -0
- package/dist/src/mutation-node/enum-member.js +6 -0
- package/dist/src/mutation-node/enum-member.js.map +1 -0
- package/dist/src/mutation-node/enum-member.test.d.ts +2 -0
- package/dist/src/mutation-node/enum-member.test.d.ts.map +1 -0
- package/dist/src/mutation-node/enum-member.test.js +25 -0
- package/dist/src/mutation-node/enum-member.test.js.map +1 -0
- package/dist/src/mutation-node/enum.d.ts +8 -0
- package/dist/src/mutation-node/enum.d.ts.map +1 -0
- package/dist/src/mutation-node/enum.js +30 -0
- package/dist/src/mutation-node/enum.js.map +1 -0
- package/dist/src/mutation-node/enum.test.d.ts +2 -0
- package/dist/src/mutation-node/enum.test.d.ts.map +1 -0
- package/dist/src/mutation-node/enum.test.js +25 -0
- package/dist/src/mutation-node/enum.test.js.map +1 -0
- package/dist/src/mutation-node/factory.d.ts +17 -0
- package/dist/src/mutation-node/factory.d.ts.map +1 -0
- package/dist/src/mutation-node/factory.js +45 -0
- package/dist/src/mutation-node/factory.js.map +1 -0
- package/dist/src/mutation-node/index.d.ts +15 -0
- package/dist/src/mutation-node/index.d.ts.map +1 -0
- package/dist/src/mutation-node/index.js +16 -0
- package/dist/src/mutation-node/index.js.map +1 -0
- package/dist/src/mutation-node/interface.d.ts +8 -0
- package/dist/src/mutation-node/interface.d.ts.map +1 -0
- package/dist/src/mutation-node/interface.js +30 -0
- package/dist/src/mutation-node/interface.js.map +1 -0
- package/dist/src/mutation-node/intrinsic.d.ts +7 -0
- package/dist/src/mutation-node/intrinsic.d.ts.map +1 -0
- package/dist/src/mutation-node/intrinsic.js +6 -0
- package/dist/src/mutation-node/intrinsic.js.map +1 -0
- package/dist/src/mutation-node/literal.d.ts +7 -0
- package/dist/src/mutation-node/literal.d.ts.map +1 -0
- package/dist/src/mutation-node/literal.js +6 -0
- package/dist/src/mutation-node/literal.js.map +1 -0
- package/dist/src/mutation-node/model-property.d.ts +10 -0
- package/dist/src/mutation-node/model-property.d.ts.map +1 -0
- package/dist/src/mutation-node/model-property.js +48 -0
- package/dist/src/mutation-node/model-property.js.map +1 -0
- package/dist/src/mutation-node/model-property.test.d.ts +2 -0
- package/dist/src/mutation-node/model-property.test.d.ts.map +1 -0
- package/dist/src/mutation-node/model-property.test.js +108 -0
- package/dist/src/mutation-node/model-property.test.js.map +1 -0
- package/dist/src/mutation-node/model.d.ts +10 -0
- package/dist/src/mutation-node/model.d.ts.map +1 -0
- package/dist/src/mutation-node/model.js +82 -0
- package/dist/src/mutation-node/model.js.map +1 -0
- package/dist/src/mutation-node/model.test.d.ts +2 -0
- package/dist/src/mutation-node/model.test.d.ts.map +1 -0
- package/dist/src/mutation-node/model.test.js +133 -0
- package/dist/src/mutation-node/model.test.js.map +1 -0
- package/dist/src/mutation-node/mutation-edge.d.ts +18 -0
- package/dist/src/mutation-node/mutation-edge.d.ts.map +1 -0
- package/dist/src/mutation-node/mutation-edge.js +31 -0
- package/dist/src/mutation-node/mutation-edge.js.map +1 -0
- package/dist/src/mutation-node/mutation-node.d.ts +29 -0
- package/dist/src/mutation-node/mutation-node.d.ts.map +1 -0
- package/dist/src/mutation-node/mutation-node.js +82 -0
- package/dist/src/mutation-node/mutation-node.js.map +1 -0
- package/dist/src/mutation-node/mutation-node.test.d.ts +2 -0
- package/dist/src/mutation-node/mutation-node.test.d.ts.map +1 -0
- package/dist/src/mutation-node/mutation-node.test.js +88 -0
- package/dist/src/mutation-node/mutation-node.test.js.map +1 -0
- package/dist/src/mutation-node/mutation-subgraph.d.ts +17 -0
- package/dist/src/mutation-node/mutation-subgraph.d.ts.map +1 -0
- package/dist/src/mutation-node/mutation-subgraph.js +45 -0
- package/dist/src/mutation-node/mutation-subgraph.js.map +1 -0
- package/dist/src/mutation-node/operation.d.ts +9 -0
- package/dist/src/mutation-node/operation.d.ts.map +1 -0
- package/dist/src/mutation-node/operation.js +44 -0
- package/dist/src/mutation-node/operation.js.map +1 -0
- package/dist/src/mutation-node/scalar.d.ts +8 -0
- package/dist/src/mutation-node/scalar.d.ts.map +1 -0
- package/dist/src/mutation-node/scalar.js +28 -0
- package/dist/src/mutation-node/scalar.js.map +1 -0
- package/dist/src/mutation-node/scalar.test.d.ts +2 -0
- package/dist/src/mutation-node/scalar.test.d.ts.map +1 -0
- package/dist/src/mutation-node/scalar.test.js +40 -0
- package/dist/src/mutation-node/scalar.test.js.map +1 -0
- package/dist/src/mutation-node/tuple.d.ts +9 -0
- package/dist/src/mutation-node/tuple.d.ts.map +1 -0
- package/dist/src/mutation-node/tuple.js +32 -0
- package/dist/src/mutation-node/tuple.js.map +1 -0
- package/dist/src/mutation-node/tuple.test.d.ts +2 -0
- package/dist/src/mutation-node/tuple.test.d.ts.map +1 -0
- package/dist/src/mutation-node/tuple.test.js +29 -0
- package/dist/src/mutation-node/tuple.test.js.map +1 -0
- package/dist/src/mutation-node/union-variant.d.ts +8 -0
- package/dist/src/mutation-node/union-variant.d.ts.map +1 -0
- package/dist/src/mutation-node/union-variant.js +23 -0
- package/dist/src/mutation-node/union-variant.js.map +1 -0
- package/dist/src/mutation-node/union-variant.test.d.ts +2 -0
- package/dist/src/mutation-node/union-variant.test.d.ts.map +1 -0
- package/dist/src/mutation-node/union-variant.test.js +27 -0
- package/dist/src/mutation-node/union-variant.test.js.map +1 -0
- package/dist/src/mutation-node/union.d.ts +8 -0
- package/dist/src/mutation-node/union.d.ts.map +1 -0
- package/dist/src/mutation-node/union.js +30 -0
- package/dist/src/mutation-node/union.js.map +1 -0
- package/dist/src/mutation-node/union.test.d.ts +2 -0
- package/dist/src/mutation-node/union.test.d.ts.map +1 -0
- package/dist/src/mutation-node/union.test.js +25 -0
- package/dist/src/mutation-node/union.test.js.map +1 -0
- package/dist/test/test-host.d.ts +2 -0
- package/dist/test/test-host.d.ts.map +1 -0
- package/dist/test/test-host.js +6 -0
- package/dist/test/test-host.js.map +1 -0
- package/dist/test/utils.d.ts +4 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/utils.js +8 -0
- package/dist/test/utils.js.map +1 -0
- package/package.json +40 -0
- package/package.json.bak +42 -0
- package/readme.md +339 -0
- package/src/index.ts +4 -0
- package/src/mutation/index.ts +12 -0
- package/src/mutation/interface.ts +38 -0
- package/src/mutation/intrinsic.ts +23 -0
- package/src/mutation/literal.ts +29 -0
- package/src/mutation/model-property.ts +35 -0
- package/src/mutation/model.ts +58 -0
- package/src/mutation/mutation-engine.test.ts +202 -0
- package/src/mutation/mutation-engine.ts +288 -0
- package/src/mutation/mutation.ts +90 -0
- package/src/mutation/operation.ts +40 -0
- package/src/mutation/scalar.ts +36 -0
- package/src/mutation/simple-mutation-engine.ts +21 -0
- package/src/mutation/union-variant.ts +30 -0
- package/src/mutation/union.ts +39 -0
- package/src/mutation-node/enum-member.test.ts +26 -0
- package/src/mutation-node/enum-member.ts +8 -0
- package/src/mutation-node/enum.test.ts +26 -0
- package/src/mutation-node/enum.ts +33 -0
- package/src/mutation-node/factory.ts +95 -0
- package/src/mutation-node/index.ts +16 -0
- package/src/mutation-node/interface.ts +33 -0
- package/src/mutation-node/intrinsic.ts +8 -0
- package/src/mutation-node/literal.ts +10 -0
- package/src/mutation-node/model-property.test.ts +136 -0
- package/src/mutation-node/model-property.ts +53 -0
- package/src/mutation-node/model.test.ts +151 -0
- package/src/mutation-node/model.ts +89 -0
- package/src/mutation-node/mutation-edge.ts +43 -0
- package/src/mutation-node/mutation-node.test.ts +94 -0
- package/src/mutation-node/mutation-node.ts +110 -0
- package/src/mutation-node/mutation-subgraph.ts +59 -0
- package/src/mutation-node/operation.ts +49 -0
- package/src/mutation-node/scalar.test.ts +44 -0
- package/src/mutation-node/scalar.ts +32 -0
- package/src/mutation-node/tuple.test.ts +30 -0
- package/src/mutation-node/tuple.ts +35 -0
- package/src/mutation-node/union-variant.test.ts +28 -0
- package/src/mutation-node/union-variant.ts +26 -0
- package/src/mutation-node/union.test.ts +26 -0
- package/src/mutation-node/union.ts +33 -0
- package/test/test-host.ts +6 -0
- package/test/utils.ts +9 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +4 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EnumMemberMutationNode } from "./enum-member.js";
|
|
2
|
+
import { EnumMutationNode } from "./enum.js";
|
|
3
|
+
import { InterfaceMutationNode } from "./interface.js";
|
|
4
|
+
import { IntrinsicMutationNode } from "./intrinsic.js";
|
|
5
|
+
import { LiteralMutationNode } from "./literal.js";
|
|
6
|
+
import { ModelPropertyMutationNode } from "./model-property.js";
|
|
7
|
+
import { ModelMutationNode } from "./model.js";
|
|
8
|
+
import { OperationMutationNode } from "./operation.js";
|
|
9
|
+
import { ScalarMutationNode } from "./scalar.js";
|
|
10
|
+
import { TupleMutationNode } from "./tuple.js";
|
|
11
|
+
import { UnionVariantMutationNode } from "./union-variant.js";
|
|
12
|
+
import { UnionMutationNode } from "./union.js";
|
|
13
|
+
export function mutationNodeFor(subgraph, sourceType) {
|
|
14
|
+
switch (sourceType.kind) {
|
|
15
|
+
case "Operation":
|
|
16
|
+
return new OperationMutationNode(subgraph, sourceType);
|
|
17
|
+
case "Interface":
|
|
18
|
+
return new InterfaceMutationNode(subgraph, sourceType);
|
|
19
|
+
case "Model":
|
|
20
|
+
return new ModelMutationNode(subgraph, sourceType);
|
|
21
|
+
case "ModelProperty":
|
|
22
|
+
return new ModelPropertyMutationNode(subgraph, sourceType);
|
|
23
|
+
case "Scalar":
|
|
24
|
+
return new ScalarMutationNode(subgraph, sourceType);
|
|
25
|
+
case "Tuple":
|
|
26
|
+
return new TupleMutationNode(subgraph, sourceType);
|
|
27
|
+
case "Union":
|
|
28
|
+
return new UnionMutationNode(subgraph, sourceType);
|
|
29
|
+
case "UnionVariant":
|
|
30
|
+
return new UnionVariantMutationNode(subgraph, sourceType);
|
|
31
|
+
case "Enum":
|
|
32
|
+
return new EnumMutationNode(subgraph, sourceType);
|
|
33
|
+
case "EnumMember":
|
|
34
|
+
return new EnumMemberMutationNode(subgraph, sourceType);
|
|
35
|
+
case "String":
|
|
36
|
+
case "Number":
|
|
37
|
+
case "Boolean":
|
|
38
|
+
return new LiteralMutationNode(subgraph, sourceType);
|
|
39
|
+
case "Intrinsic":
|
|
40
|
+
return new IntrinsicMutationNode(subgraph, sourceType);
|
|
41
|
+
default:
|
|
42
|
+
throw new Error("Unsupported type kind: " + sourceType.kind);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/mutation-node/factory.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,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,IAAI,wBAAwB,CAAC,QAAQ,EAAE,UAAU,CAA2B,CAAC;QACtF,KAAK,MAAM;YACT,OAAO,IAAI,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAA2B,CAAC;QAC9E,KAAK,YAAY;YACf,OAAO,IAAI,sBAAsB,CAAC,QAAQ,EAAE,UAAU,CAA2B,CAAC;QACpF,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACZ,OAAO,IAAI,mBAAmB,CAC5B,QAAQ,EACR,UAA6D,CACpC,CAAC;QAC9B,KAAK,WAAW;YACd,OAAO,IAAI,qBAAqB,CAAC,QAAQ,EAAE,UAAU,CAA2B,CAAC;QACnF;YACE,MAAM,IAAI,KAAK,CAAC,yBAAyB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./mutation-node.js";
|
|
2
|
+
export * from "./enum.js";
|
|
3
|
+
export * from "./interface.js";
|
|
4
|
+
export * from "./intrinsic.js";
|
|
5
|
+
export * from "./literal.js";
|
|
6
|
+
export * from "./model-property.js";
|
|
7
|
+
export * from "./model.js";
|
|
8
|
+
export * from "./mutation-edge.js";
|
|
9
|
+
export * from "./mutation-subgraph.js";
|
|
10
|
+
export * from "./operation.js";
|
|
11
|
+
export * from "./scalar.js";
|
|
12
|
+
export * from "./tuple.js";
|
|
13
|
+
export * from "./union-variant.js";
|
|
14
|
+
export * from "./union.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AAEnC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./mutation-node.js";
|
|
2
|
+
export * from "./enum.js";
|
|
3
|
+
export * from "./interface.js";
|
|
4
|
+
export * from "./intrinsic.js";
|
|
5
|
+
export * from "./literal.js";
|
|
6
|
+
export * from "./model-property.js";
|
|
7
|
+
export * from "./model.js";
|
|
8
|
+
export * from "./mutation-edge.js";
|
|
9
|
+
export * from "./mutation-subgraph.js";
|
|
10
|
+
export * from "./operation.js";
|
|
11
|
+
export * from "./scalar.js";
|
|
12
|
+
export * from "./tuple.js";
|
|
13
|
+
export * from "./union-variant.js";
|
|
14
|
+
export * from "./union.js";
|
|
15
|
+
//export * from "./enum-member.js";
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mutation-node/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AAEnC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,mCAAmC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Interface, Operation } from "@typespec/compiler";
|
|
2
|
+
import { MutationNode } from "./mutation-node.js";
|
|
3
|
+
export declare class InterfaceMutationNode extends MutationNode<Interface> {
|
|
4
|
+
readonly kind = "Interface";
|
|
5
|
+
traverse(): void;
|
|
6
|
+
connectOperation(opNode: MutationNode<Operation>, opName: string): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAAa,qBAAsB,SAAQ,YAAY,CAAC,SAAS,CAAC;IAChE,QAAQ,CAAC,IAAI,eAAe;IAE5B,QAAQ;IAOR,gBAAgB,CAAC,MAAM,EAAE,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM;CAkBjE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MutationEdge } from "./mutation-edge.js";
|
|
2
|
+
import { MutationNode } from "./mutation-node.js";
|
|
3
|
+
export class InterfaceMutationNode extends MutationNode {
|
|
4
|
+
kind = "Interface";
|
|
5
|
+
traverse() {
|
|
6
|
+
for (const [opName, op] of this.sourceType.operations) {
|
|
7
|
+
const opNode = this.subgraph.getNode(op);
|
|
8
|
+
this.connectOperation(opNode, opName);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
connectOperation(opNode, opName) {
|
|
12
|
+
MutationEdge.create(this, opNode, {
|
|
13
|
+
onTailMutation: () => {
|
|
14
|
+
this.mutatedType.operations.delete(opName);
|
|
15
|
+
this.mutatedType.operations.set(opNode.mutatedType.name, opNode.mutatedType);
|
|
16
|
+
},
|
|
17
|
+
onTailDeletion: () => {
|
|
18
|
+
this.mutatedType.operations.delete(opName);
|
|
19
|
+
},
|
|
20
|
+
onTailReplaced: (newTail) => {
|
|
21
|
+
if (newTail.mutatedType.kind !== "Operation") {
|
|
22
|
+
throw new Error("Cannot replace operation with non-operation type");
|
|
23
|
+
}
|
|
24
|
+
this.mutatedType.operations.delete(opName);
|
|
25
|
+
this.mutatedType.operations.set(newTail.mutatedType.name, newTail.mutatedType);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/mutation-node/interface.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,qBAAsB,SAAQ,YAAuB;IACvD,IAAI,GAAG,WAAW,CAAC;IAE5B,QAAQ;QACN,KAAK,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;YACtD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACzC,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,gBAAgB,CAAC,MAA+B,EAAE,MAAc;QAC9D,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE;YAChC,cAAc,EAAE,GAAG,EAAE;gBACnB,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3C,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;YAC/E,CAAC;YACD,cAAc,EAAE,GAAG,EAAE;gBACnB,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC7C,CAAC;YACD,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE;gBAC1B,IAAI,OAAO,CAAC,WAAW,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;oBAC7C,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;gBACtE,CAAC;gBACD,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3C,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;YACjF,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IntrinsicType } from "@typespec/compiler";
|
|
2
|
+
import { MutationNode } from "./mutation-node.js";
|
|
3
|
+
export declare class IntrinsicMutationNode extends MutationNode<IntrinsicType> {
|
|
4
|
+
readonly kind = "Intrinsic";
|
|
5
|
+
traverse(): void;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=intrinsic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intrinsic.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/intrinsic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAAa,qBAAsB,SAAQ,YAAY,CAAC,aAAa,CAAC;IACpE,QAAQ,CAAC,IAAI,eAAe;IAE5B,QAAQ;CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intrinsic.js","sourceRoot":"","sources":["../../../src/mutation-node/intrinsic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,qBAAsB,SAAQ,YAA2B;IAC3D,IAAI,GAAG,WAAW,CAAC;IAE5B,QAAQ,KAAI,CAAC;CACd"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BooleanLiteral, NumericLiteral, StringLiteral } from "@typespec/compiler";
|
|
2
|
+
import { MutationNode } from "./mutation-node.js";
|
|
3
|
+
export declare class LiteralMutationNode extends MutationNode<StringLiteral | NumericLiteral | BooleanLiteral> {
|
|
4
|
+
readonly kind = "Literal";
|
|
5
|
+
traverse(): void;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=literal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/literal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAAa,mBAAoB,SAAQ,YAAY,CACnD,aAAa,GAAG,cAAc,GAAG,cAAc,CAChD;IACC,QAAQ,CAAC,IAAI,aAAa;IAE1B,QAAQ;CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../../src/mutation-node/literal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,mBAAoB,SAAQ,YAExC;IACU,IAAI,GAAG,SAAS,CAAC;IAE1B,QAAQ,KAAI,CAAC;CACd"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ModelProperty, Type } from "@typespec/compiler";
|
|
2
|
+
import { MutationNode } from "./mutation-node.js";
|
|
3
|
+
export declare class ModelPropertyMutationNode extends MutationNode<ModelProperty> {
|
|
4
|
+
#private;
|
|
5
|
+
readonly kind = "ModelProperty";
|
|
6
|
+
traverse(): void;
|
|
7
|
+
connectReference(referenceNode: MutationNode<Type>): void;
|
|
8
|
+
connectType(typeNode: MutationNode<Type>): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=model-property.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-property.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/model-property.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAAa,yBAA0B,SAAQ,YAAY,CAAC,aAAa,CAAC;;IACxE,QAAQ,CAAC,IAAI,mBAAmB;IAGhC,QAAQ;IAQR,gBAAgB,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC;IAiBlD,WAAW,CAAC,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC;CAmBzC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MutationEdge } from "./mutation-edge.js";
|
|
2
|
+
import { MutationNode } from "./mutation-node.js";
|
|
3
|
+
export class ModelPropertyMutationNode extends MutationNode {
|
|
4
|
+
kind = "ModelProperty";
|
|
5
|
+
#referenceMutated = false;
|
|
6
|
+
traverse() {
|
|
7
|
+
const typeNode = this.subgraph.getNode(this.sourceType.type);
|
|
8
|
+
const referenceNode = this.subgraph.getReferenceNode(this.sourceType);
|
|
9
|
+
this.connectType(typeNode);
|
|
10
|
+
this.connectReference(referenceNode);
|
|
11
|
+
}
|
|
12
|
+
connectReference(referenceNode) {
|
|
13
|
+
MutationEdge.create(this, referenceNode, {
|
|
14
|
+
onTailMutation: () => {
|
|
15
|
+
this.#referenceMutated = true;
|
|
16
|
+
this.mutatedType.type = referenceNode.mutatedType;
|
|
17
|
+
},
|
|
18
|
+
onTailDeletion: () => {
|
|
19
|
+
this.#referenceMutated = true;
|
|
20
|
+
this.mutatedType.type = this.$.intrinsic.any;
|
|
21
|
+
},
|
|
22
|
+
onTailReplaced: (newTail) => {
|
|
23
|
+
this.#referenceMutated = true;
|
|
24
|
+
this.mutatedType.type = newTail.mutatedType;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
connectType(typeNode) {
|
|
29
|
+
MutationEdge.create(this, typeNode, {
|
|
30
|
+
onTailMutation: () => {
|
|
31
|
+
if (this.#referenceMutated) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.mutatedType.type = typeNode.mutatedType;
|
|
35
|
+
},
|
|
36
|
+
onTailDeletion: () => {
|
|
37
|
+
if (this.#referenceMutated) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.mutatedType.type = this.$.intrinsic.any;
|
|
41
|
+
},
|
|
42
|
+
onTailReplaced: (newTail) => {
|
|
43
|
+
this.mutatedType.type = newTail.mutatedType;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=model-property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-property.js","sourceRoot":"","sources":["../../../src/mutation-node/model-property.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,yBAA0B,SAAQ,YAA2B;IAC/D,IAAI,GAAG,eAAe,CAAC;IAChC,iBAAiB,GAAG,KAAK,CAAC;IAE1B,QAAQ;QACN,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC7D,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEtE,IAAI,CAAC,WAAW,CAAC,QAAQ,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AAI,GAAG,OAAO,CAAC,WAAW,CAAC;YAC9C,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-property.test.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/model-property.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { t } from "@typespec/compiler/testing";
|
|
2
|
+
import { $ } from "@typespec/compiler/typekit";
|
|
3
|
+
import { beforeEach, expect, it } from "vitest";
|
|
4
|
+
import { Tester } from "../../test/test-host.js";
|
|
5
|
+
import { getSubgraph } from "../../test/utils.js";
|
|
6
|
+
let runner;
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
runner = await Tester.createInstance();
|
|
9
|
+
});
|
|
10
|
+
it("handles mutation of property types", async () => {
|
|
11
|
+
const { prop, program } = await runner.compile(t.code `
|
|
12
|
+
model Foo {
|
|
13
|
+
${t.modelProperty("prop")}: string;
|
|
14
|
+
}
|
|
15
|
+
`);
|
|
16
|
+
const subgraph = getSubgraph(program);
|
|
17
|
+
const propNode = subgraph.getNode(prop);
|
|
18
|
+
const stringNode = subgraph.getNode($(program).builtin.string);
|
|
19
|
+
stringNode.mutate();
|
|
20
|
+
expect(propNode.isMutated).toBe(true);
|
|
21
|
+
expect(propNode.mutatedType.type === stringNode.mutatedType).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
it("handles mutating a reference", async () => {
|
|
24
|
+
const { Foo, Bar, prop, program } = await runner.compile(t.code `
|
|
25
|
+
model ${t.model("Foo")} {
|
|
26
|
+
${t.modelProperty("prop")}: Bar;
|
|
27
|
+
};
|
|
28
|
+
model ${t.model("Bar")} {}
|
|
29
|
+
`);
|
|
30
|
+
const subgraph = getSubgraph(program);
|
|
31
|
+
const fooNode = subgraph.getNode(Foo);
|
|
32
|
+
const propNode = subgraph.getNode(prop);
|
|
33
|
+
const barPrime = subgraph.getReferenceNode(prop);
|
|
34
|
+
// initially the source type is just Bar.
|
|
35
|
+
expect(barPrime.sourceType === Bar).toBe(true);
|
|
36
|
+
barPrime.mutate();
|
|
37
|
+
expect(fooNode.isMutated).toBe(true);
|
|
38
|
+
expect(propNode.isMutated).toBe(true);
|
|
39
|
+
expect(barPrime.isMutated).toBe(true);
|
|
40
|
+
expect(fooNode.mutatedType.properties.get("prop").type === barPrime.mutatedType).toBeTruthy();
|
|
41
|
+
const barNode = subgraph.getNode(Bar);
|
|
42
|
+
barNode.mutate();
|
|
43
|
+
expect(barNode.isMutated).toBe(true);
|
|
44
|
+
expect(barPrime.isMutated).toBe(true);
|
|
45
|
+
// the mutated type doesn't change here.
|
|
46
|
+
expect(fooNode.mutatedType.properties.get("prop").type === barPrime.mutatedType).toBeTruthy();
|
|
47
|
+
});
|
|
48
|
+
it("handles replacing the model reference", async () => {
|
|
49
|
+
const { Foo, Bar, prop, program } = await runner.compile(t.code `
|
|
50
|
+
model ${t.model("Foo")} {
|
|
51
|
+
${t.modelProperty("prop")}: Bar;
|
|
52
|
+
};
|
|
53
|
+
model ${t.model("Bar")} {}
|
|
54
|
+
`);
|
|
55
|
+
const tk = $(program);
|
|
56
|
+
const subgraph = getSubgraph(program);
|
|
57
|
+
const fooNode = subgraph.getNode(Foo);
|
|
58
|
+
const propNode = subgraph.getNode(prop);
|
|
59
|
+
const barPrime = subgraph.getReferenceNode(prop);
|
|
60
|
+
const unionType = tk.union.create({
|
|
61
|
+
variants: [
|
|
62
|
+
tk.unionVariant.create({ type: tk.builtin.string }),
|
|
63
|
+
tk.unionVariant.create({ type: Bar }),
|
|
64
|
+
],
|
|
65
|
+
});
|
|
66
|
+
const replacedBarPrime = barPrime.replace(unionType);
|
|
67
|
+
// the subgraph now returns the new reference node
|
|
68
|
+
expect(subgraph.getReferenceNode(prop) === replacedBarPrime).toBe(true);
|
|
69
|
+
// foo and prop are marked mutated, barPrime is replaced
|
|
70
|
+
expect(fooNode.isMutated).toBe(true);
|
|
71
|
+
expect(propNode.isMutated).toBe(true);
|
|
72
|
+
expect(barPrime.isReplaced).toBe(true);
|
|
73
|
+
// prop's type is the replaced type
|
|
74
|
+
expect(tk.union.is(propNode.mutatedType.type)).toBe(true);
|
|
75
|
+
expect(fooNode.mutatedType.properties.get("prop").type === replacedBarPrime.mutatedType).toBeTruthy();
|
|
76
|
+
});
|
|
77
|
+
it("handles mutating a reference to a reference", async () => {
|
|
78
|
+
const { myString, Foo, fprop, Bar, program } = await runner.compile(t.code `
|
|
79
|
+
scalar ${t.scalar("myString")} extends string;
|
|
80
|
+
model ${t.model("Foo")} {
|
|
81
|
+
${t.modelProperty("fprop")}: myString;
|
|
82
|
+
};
|
|
83
|
+
model ${t.model("Bar")} {
|
|
84
|
+
bprop: Foo.fprop;
|
|
85
|
+
}
|
|
86
|
+
`);
|
|
87
|
+
const subgraph = getSubgraph(program);
|
|
88
|
+
const fooNode = subgraph.getNode(Foo);
|
|
89
|
+
const barNode = subgraph.getNode(Bar);
|
|
90
|
+
const myStringNode = subgraph.getNode(myString);
|
|
91
|
+
myStringNode.mutate();
|
|
92
|
+
expect(myStringNode.isMutated).toBe(true);
|
|
93
|
+
expect(fooNode.isMutated).toBe(true);
|
|
94
|
+
expect(barNode.isMutated).toBe(true);
|
|
95
|
+
// Foo.prop's type is the mutated myString
|
|
96
|
+
expect(fooNode.mutatedType.properties.get("fprop").type === myStringNode.mutatedType).toBeTruthy();
|
|
97
|
+
// Bar.prop's type is the mutated Foo.prop
|
|
98
|
+
expect(barNode.mutatedType.properties.get("bprop").type ===
|
|
99
|
+
fooNode.mutatedType.properties.get("fprop")).toBeTruthy();
|
|
100
|
+
const fpropRefNode = subgraph.getReferenceNode(fprop);
|
|
101
|
+
fpropRefNode.mutate();
|
|
102
|
+
expect(fpropRefNode.isMutated).toBe(true);
|
|
103
|
+
expect(fooNode.mutatedType.properties.get("fprop").type === fpropRefNode.mutatedType).toBeTruthy();
|
|
104
|
+
// Bar.bprop references the mutated type (though is the same reference since fprop was already mutated)
|
|
105
|
+
expect(barNode.mutatedType.properties.get("bprop").type ===
|
|
106
|
+
fooNode.mutatedType.properties.get("fprop")).toBeTruthy();
|
|
107
|
+
});
|
|
108
|
+
//# sourceMappingURL=model-property.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-property.test.js","sourceRoot":"","sources":["../../../src/mutation-node/model-property.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAuB,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,4BAA4B,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,IAAI,MAAsB,CAAC;AAC3B,UAAU,CAAC,KAAK,IAAI,EAAE;IACpB,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,EAAE,CAAC;AACzC,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;IAClD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA;;UAE7C,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC;;KAE5B,CAAC,CAAC;IACL,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,UAAU,CAAC,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC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,OAAO,CAAE,CAAC,IAAI,KAAK,YAAY,CAAC,WAAW,CAC/E,CAAC,UAAU,EAAE,CAAC;IAEf,uGAAuG;IACvG,MAAM,CACJ,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC,IAAI;QAC/C,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAE,CAC/C,CAAC,UAAU,EAAE,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Model, ModelProperty, Type } from "@typespec/compiler";
|
|
2
|
+
import { MutationNode } from "./mutation-node.js";
|
|
3
|
+
export declare class ModelMutationNode extends MutationNode<Model> {
|
|
4
|
+
readonly kind = "Model";
|
|
5
|
+
traverse(): void;
|
|
6
|
+
connectToBase(baseNode: MutationNode<Model>): void;
|
|
7
|
+
connectProperty(propNode: MutationNode<ModelProperty>, sourcePropName: string): void;
|
|
8
|
+
connectIndexerValue(indexerNode: MutationNode<Type>): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAAa,iBAAkB,SAAQ,YAAY,CAAC,KAAK,CAAC;IACxD,QAAQ,CAAC,IAAI,WAAW;IAExB,QAAQ;IAiBR,aAAa,CAAC,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC;IAiB3C,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC,aAAa,CAAC,EAAE,cAAc,EAAE,MAAM;IAmB7E,mBAAmB,CAAC,WAAW,EAAE,YAAY,CAAC,IAAI,CAAC;CA4BpD"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { MutationEdge } from "./mutation-edge.js";
|
|
2
|
+
import { MutationNode } from "./mutation-node.js";
|
|
3
|
+
export class ModelMutationNode extends MutationNode {
|
|
4
|
+
kind = "Model";
|
|
5
|
+
traverse() {
|
|
6
|
+
if (this.sourceType.baseModel) {
|
|
7
|
+
const baseNode = this.subgraph.getNode(this.sourceType.baseModel);
|
|
8
|
+
this.connectToBase(baseNode);
|
|
9
|
+
}
|
|
10
|
+
for (const [propName, prop] of this.sourceType.properties) {
|
|
11
|
+
const propNode = this.subgraph.getNode(prop);
|
|
12
|
+
this.connectProperty(propNode, propName);
|
|
13
|
+
}
|
|
14
|
+
if (this.sourceType.indexer) {
|
|
15
|
+
const indexerNode = this.subgraph.getNode(this.sourceType.indexer.value);
|
|
16
|
+
this.connectIndexerValue(indexerNode);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
connectToBase(baseNode) {
|
|
20
|
+
MutationEdge.create(this, baseNode, {
|
|
21
|
+
onTailMutation: () => {
|
|
22
|
+
this.mutatedType.baseModel = baseNode.mutatedType;
|
|
23
|
+
},
|
|
24
|
+
onTailDeletion: () => {
|
|
25
|
+
this.mutatedType.baseModel = undefined;
|
|
26
|
+
},
|
|
27
|
+
onTailReplaced: (newTail) => {
|
|
28
|
+
if (newTail.mutatedType.kind !== "Model") {
|
|
29
|
+
throw new Error("Cannot replace base model with non-model type");
|
|
30
|
+
}
|
|
31
|
+
this.mutatedType.baseModel = newTail.mutatedType;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
connectProperty(propNode, sourcePropName) {
|
|
36
|
+
MutationEdge.create(this, propNode, {
|
|
37
|
+
onTailMutation: () => {
|
|
38
|
+
this.mutatedType.properties.delete(sourcePropName);
|
|
39
|
+
this.mutatedType.properties.set(propNode.mutatedType.name, propNode.mutatedType);
|
|
40
|
+
},
|
|
41
|
+
onTailDeletion: () => {
|
|
42
|
+
this.mutatedType.properties.delete(sourcePropName);
|
|
43
|
+
},
|
|
44
|
+
onTailReplaced: (newTail) => {
|
|
45
|
+
if (newTail.mutatedType.kind !== "ModelProperty") {
|
|
46
|
+
throw new Error("Cannot replace model property with non-model property type");
|
|
47
|
+
}
|
|
48
|
+
this.mutatedType.properties.delete(sourcePropName);
|
|
49
|
+
this.mutatedType.properties.set(newTail.mutatedType.name, newTail.mutatedType);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
connectIndexerValue(indexerNode) {
|
|
54
|
+
MutationEdge.create(this, indexerNode, {
|
|
55
|
+
onTailMutation: () => {
|
|
56
|
+
if (this.mutatedType.indexer) {
|
|
57
|
+
this.mutatedType.indexer = {
|
|
58
|
+
key: this.mutatedType.indexer.key,
|
|
59
|
+
value: indexerNode.mutatedType,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
onTailDeletion: () => {
|
|
64
|
+
if (this.mutatedType.indexer) {
|
|
65
|
+
this.mutatedType.indexer = {
|
|
66
|
+
key: this.mutatedType.indexer.key,
|
|
67
|
+
value: this.$.intrinsic.any,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
onTailReplaced: (newTail) => {
|
|
72
|
+
if (this.mutatedType.indexer) {
|
|
73
|
+
this.mutatedType.indexer = {
|
|
74
|
+
key: this.mutatedType.indexer.key,
|
|
75
|
+
value: newTail.mutatedType,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/mutation-node/model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CA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I,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG;wBACjC,KAAK,EAAE,WAAW,CAAC,WAAW;qBAC/B,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,cAAc,EAAE,GAAG,EAAE;gBACnB,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;oBAC7B,IAAI,CAAC,WAAW,CAAC,OAAO,GAAG;wBACzB,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG;wBACjC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG;qBAC5B,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE;gBAC1B,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;oBAC7B,IAAI,CAAC,WAAW,CAAC,OAAO,GAAG;wBACzB,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG;wBACjC,KAAK,EAAE,OAAO,CAAC,WAAW;qBAC3B,CAAC;gBACJ,CAAC;YACH,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.test.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/model.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { t } from "@typespec/compiler/testing";
|
|
2
|
+
import { beforeEach, expect, it } from "vitest";
|
|
3
|
+
import { Tester } from "../../test/test-host.js";
|
|
4
|
+
import { getSubgraph } from "../../test/utils.js";
|
|
5
|
+
let runner;
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
runner = await Tester.createInstance();
|
|
8
|
+
});
|
|
9
|
+
it("handles mutation of properties", async () => {
|
|
10
|
+
const { Foo, program } = await runner.compile(t.code `
|
|
11
|
+
model ${t.model("Foo")} {
|
|
12
|
+
prop: string;
|
|
13
|
+
}
|
|
14
|
+
`);
|
|
15
|
+
const subgraph = getSubgraph(program);
|
|
16
|
+
const fooNode = subgraph.getNode(Foo);
|
|
17
|
+
const propNode = subgraph.getNode(Foo.properties.get("prop"));
|
|
18
|
+
propNode.mutate();
|
|
19
|
+
expect(fooNode.isMutated).toBe(true);
|
|
20
|
+
expect(fooNode.mutatedType.properties.get("prop") === propNode.mutatedType).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
it("handles deletion of properties", async () => {
|
|
23
|
+
const { Foo, program } = await runner.compile(t.code `
|
|
24
|
+
model ${t.model("Foo")} {
|
|
25
|
+
prop: string;
|
|
26
|
+
}
|
|
27
|
+
`);
|
|
28
|
+
const subgraph = getSubgraph(program);
|
|
29
|
+
const fooNode = subgraph.getNode(Foo);
|
|
30
|
+
const propNode = subgraph.getNode(Foo.properties.get("prop"));
|
|
31
|
+
propNode.delete();
|
|
32
|
+
expect(fooNode.isMutated).toBe(true);
|
|
33
|
+
expect(fooNode.mutatedType.properties.get("prop")).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
it("handles mutation of properties with name change", async () => {
|
|
36
|
+
const { Foo, program } = await runner.compile(t.code `
|
|
37
|
+
model ${t.model("Foo")} {
|
|
38
|
+
prop: string;
|
|
39
|
+
}
|
|
40
|
+
`);
|
|
41
|
+
const subgraph = getSubgraph(program);
|
|
42
|
+
const fooNode = subgraph.getNode(Foo);
|
|
43
|
+
const propNode = subgraph.getNode(Foo.properties.get("prop"));
|
|
44
|
+
propNode.mutate((clone) => (clone.name = "propRenamed"));
|
|
45
|
+
expect(fooNode.isMutated).toBe(true);
|
|
46
|
+
expect(fooNode.mutatedType.properties.get("prop") === undefined).toBe(true);
|
|
47
|
+
expect(fooNode.mutatedType.properties.get("propRenamed") === propNode.mutatedType).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
it("handles mutation of base models", async () => {
|
|
50
|
+
const { Foo, Bar, program } = await runner.compile(t.code `
|
|
51
|
+
model ${t.model("Foo")} extends Bar {
|
|
52
|
+
barProp: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
model ${t.model("Bar")} {
|
|
56
|
+
bazProp: string;
|
|
57
|
+
}
|
|
58
|
+
`);
|
|
59
|
+
const subgraph = getSubgraph(program);
|
|
60
|
+
const fooNode = subgraph.getNode(Foo);
|
|
61
|
+
const barNode = subgraph.getNode(Bar);
|
|
62
|
+
barNode.mutate();
|
|
63
|
+
expect(barNode.isMutated).toBe(true);
|
|
64
|
+
expect(fooNode.isMutated).toBe(true);
|
|
65
|
+
expect(fooNode.mutatedType.baseModel === barNode.mutatedType).toBeTruthy();
|
|
66
|
+
});
|
|
67
|
+
it("handles deletion of base models", async () => {
|
|
68
|
+
const { Foo, Bar, program } = await runner.compile(t.code `
|
|
69
|
+
model ${t.model("Foo")} extends Bar {
|
|
70
|
+
barProp: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
model ${t.model("Bar")} {
|
|
74
|
+
bazProp: string;
|
|
75
|
+
}
|
|
76
|
+
`);
|
|
77
|
+
const subgraph = getSubgraph(program);
|
|
78
|
+
const fooNode = subgraph.getNode(Foo);
|
|
79
|
+
const barNode = subgraph.getNode(Bar);
|
|
80
|
+
barNode.delete();
|
|
81
|
+
expect(barNode.isDeleted).toBe(true);
|
|
82
|
+
expect(fooNode.isMutated).toBe(true);
|
|
83
|
+
expect(fooNode.mutatedType.baseModel).toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
it("handles mutation of indexers", async () => {
|
|
86
|
+
const { Foo, Bar, program } = await runner.compile(t.code `
|
|
87
|
+
model ${t.model("Foo")} is Record<Bar> {};
|
|
88
|
+
model ${t.model("Bar")} {
|
|
89
|
+
bazProp: string;
|
|
90
|
+
}
|
|
91
|
+
`);
|
|
92
|
+
const subgraph = getSubgraph(program);
|
|
93
|
+
const fooNode = subgraph.getNode(Foo);
|
|
94
|
+
const barNode = subgraph.getNode(Bar);
|
|
95
|
+
barNode.mutate();
|
|
96
|
+
expect(barNode.isMutated).toBe(true);
|
|
97
|
+
expect(fooNode.isMutated).toBe(true);
|
|
98
|
+
expect(fooNode.mutatedType.indexer?.value === barNode.mutatedType).toBeTruthy();
|
|
99
|
+
});
|
|
100
|
+
it("handles mutation of arrays", async () => {
|
|
101
|
+
const { Foo, Bar, bazProp, program } = await runner.compile(t.code `
|
|
102
|
+
model ${t.model("Foo")} {};
|
|
103
|
+
model ${t.model("Bar")} {
|
|
104
|
+
${t.modelProperty("bazProp")}: Foo[];
|
|
105
|
+
}
|
|
106
|
+
`);
|
|
107
|
+
const subgraph = getSubgraph(program);
|
|
108
|
+
const fooNode = subgraph.getNode(Foo);
|
|
109
|
+
const barNode = subgraph.getNode(Bar);
|
|
110
|
+
const bazPropNode = subgraph.getNode(bazProp);
|
|
111
|
+
fooNode.mutate();
|
|
112
|
+
expect(fooNode.isMutated).toBe(true);
|
|
113
|
+
expect(barNode.isMutated).toBe(true);
|
|
114
|
+
expect(bazPropNode.isMutated).toBe(true);
|
|
115
|
+
expect(bazPropNode.mutatedType.type.indexer.value === fooNode.mutatedType).toBeTruthy();
|
|
116
|
+
});
|
|
117
|
+
it("handles circular models", async () => {
|
|
118
|
+
const { Foo, Bar, program } = await runner.compile(t.code `
|
|
119
|
+
model ${t.model("Foo")} {
|
|
120
|
+
bar: Bar;
|
|
121
|
+
};
|
|
122
|
+
model ${t.model("Bar")} {
|
|
123
|
+
foo: Foo;
|
|
124
|
+
}
|
|
125
|
+
`);
|
|
126
|
+
const subgraph = getSubgraph(program);
|
|
127
|
+
const fooNode = subgraph.getNode(Foo);
|
|
128
|
+
const barNode = subgraph.getNode(Bar);
|
|
129
|
+
fooNode.mutate();
|
|
130
|
+
expect(fooNode.isMutated).toBe(true);
|
|
131
|
+
expect(barNode.isMutated).toBe(true);
|
|
132
|
+
});
|
|
133
|
+
//# sourceMappingURL=model.test.js.map
|