@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.
Files changed (221) hide show
  1. package/LICENSE +21 -0
  2. package/dist/src/index.d.ts +3 -0
  3. package/dist/src/index.d.ts.map +1 -0
  4. package/dist/src/index.js +4 -0
  5. package/dist/src/index.js.map +1 -0
  6. package/dist/src/mutation/index.d.ts +13 -0
  7. package/dist/src/mutation/index.d.ts.map +1 -0
  8. package/dist/src/mutation/index.js +13 -0
  9. package/dist/src/mutation/index.js.map +1 -0
  10. package/dist/src/mutation/interface.d.ts +11 -0
  11. package/dist/src/mutation/interface.d.ts.map +1 -0
  12. package/dist/src/mutation/interface.js +17 -0
  13. package/dist/src/mutation/interface.js.map +1 -0
  14. package/dist/src/mutation/intrinsic.d.ts +9 -0
  15. package/dist/src/mutation/intrinsic.d.ts.map +1 -0
  16. package/dist/src/mutation/intrinsic.js +11 -0
  17. package/dist/src/mutation/intrinsic.js.map +1 -0
  18. package/dist/src/mutation/literal.d.ts +9 -0
  19. package/dist/src/mutation/literal.d.ts.map +1 -0
  20. package/dist/src/mutation/literal.js +11 -0
  21. package/dist/src/mutation/literal.js.map +1 -0
  22. package/dist/src/mutation/model-property.d.ts +12 -0
  23. package/dist/src/mutation/model-property.d.ts.map +1 -0
  24. package/dist/src/mutation/model-property.js +18 -0
  25. package/dist/src/mutation/model-property.js.map +1 -0
  26. package/dist/src/mutation/model.d.ts +18 -0
  27. package/dist/src/mutation/model.d.ts.map +1 -0
  28. package/dist/src/mutation/model.js +34 -0
  29. package/dist/src/mutation/model.js.map +1 -0
  30. package/dist/src/mutation/mutation-engine.d.ts +80 -0
  31. package/dist/src/mutation/mutation-engine.d.ts.map +1 -0
  32. package/dist/src/mutation/mutation-engine.js +165 -0
  33. package/dist/src/mutation/mutation-engine.js.map +1 -0
  34. package/dist/src/mutation/mutation-engine.test.d.ts +2 -0
  35. package/dist/src/mutation/mutation-engine.test.d.ts.map +1 -0
  36. package/dist/src/mutation/mutation-engine.test.js +145 -0
  37. package/dist/src/mutation/mutation-engine.test.js.map +1 -0
  38. package/dist/src/mutation/mutation.d.ts +45 -0
  39. package/dist/src/mutation/mutation.d.ts.map +1 -0
  40. package/dist/src/mutation/mutation.js +29 -0
  41. package/dist/src/mutation/mutation.js.map +1 -0
  42. package/dist/src/mutation/operation.d.ts +13 -0
  43. package/dist/src/mutation/operation.d.ts.map +1 -0
  44. package/dist/src/mutation/operation.js +20 -0
  45. package/dist/src/mutation/operation.js.map +1 -0
  46. package/dist/src/mutation/scalar.d.ts +11 -0
  47. package/dist/src/mutation/scalar.d.ts.map +1 -0
  48. package/dist/src/mutation/scalar.js +17 -0
  49. package/dist/src/mutation/scalar.js.map +1 -0
  50. package/dist/src/mutation/simple-mutation-engine.d.ts +8 -0
  51. package/dist/src/mutation/simple-mutation-engine.d.ts.map +1 -0
  52. package/dist/src/mutation/simple-mutation-engine.js +11 -0
  53. package/dist/src/mutation/simple-mutation-engine.js.map +1 -0
  54. package/dist/src/mutation/union-variant.d.ts +10 -0
  55. package/dist/src/mutation/union-variant.d.ts.map +1 -0
  56. package/dist/src/mutation/union-variant.js +12 -0
  57. package/dist/src/mutation/union-variant.js.map +1 -0
  58. package/dist/src/mutation/union.d.ts +11 -0
  59. package/dist/src/mutation/union.d.ts.map +1 -0
  60. package/dist/src/mutation/union.js +18 -0
  61. package/dist/src/mutation/union.js.map +1 -0
  62. package/dist/src/mutation-node/enum-member.d.ts +7 -0
  63. package/dist/src/mutation-node/enum-member.d.ts.map +1 -0
  64. package/dist/src/mutation-node/enum-member.js +6 -0
  65. package/dist/src/mutation-node/enum-member.js.map +1 -0
  66. package/dist/src/mutation-node/enum-member.test.d.ts +2 -0
  67. package/dist/src/mutation-node/enum-member.test.d.ts.map +1 -0
  68. package/dist/src/mutation-node/enum-member.test.js +25 -0
  69. package/dist/src/mutation-node/enum-member.test.js.map +1 -0
  70. package/dist/src/mutation-node/enum.d.ts +8 -0
  71. package/dist/src/mutation-node/enum.d.ts.map +1 -0
  72. package/dist/src/mutation-node/enum.js +30 -0
  73. package/dist/src/mutation-node/enum.js.map +1 -0
  74. package/dist/src/mutation-node/enum.test.d.ts +2 -0
  75. package/dist/src/mutation-node/enum.test.d.ts.map +1 -0
  76. package/dist/src/mutation-node/enum.test.js +25 -0
  77. package/dist/src/mutation-node/enum.test.js.map +1 -0
  78. package/dist/src/mutation-node/factory.d.ts +17 -0
  79. package/dist/src/mutation-node/factory.d.ts.map +1 -0
  80. package/dist/src/mutation-node/factory.js +45 -0
  81. package/dist/src/mutation-node/factory.js.map +1 -0
  82. package/dist/src/mutation-node/index.d.ts +15 -0
  83. package/dist/src/mutation-node/index.d.ts.map +1 -0
  84. package/dist/src/mutation-node/index.js +16 -0
  85. package/dist/src/mutation-node/index.js.map +1 -0
  86. package/dist/src/mutation-node/interface.d.ts +8 -0
  87. package/dist/src/mutation-node/interface.d.ts.map +1 -0
  88. package/dist/src/mutation-node/interface.js +30 -0
  89. package/dist/src/mutation-node/interface.js.map +1 -0
  90. package/dist/src/mutation-node/intrinsic.d.ts +7 -0
  91. package/dist/src/mutation-node/intrinsic.d.ts.map +1 -0
  92. package/dist/src/mutation-node/intrinsic.js +6 -0
  93. package/dist/src/mutation-node/intrinsic.js.map +1 -0
  94. package/dist/src/mutation-node/literal.d.ts +7 -0
  95. package/dist/src/mutation-node/literal.d.ts.map +1 -0
  96. package/dist/src/mutation-node/literal.js +6 -0
  97. package/dist/src/mutation-node/literal.js.map +1 -0
  98. package/dist/src/mutation-node/model-property.d.ts +10 -0
  99. package/dist/src/mutation-node/model-property.d.ts.map +1 -0
  100. package/dist/src/mutation-node/model-property.js +48 -0
  101. package/dist/src/mutation-node/model-property.js.map +1 -0
  102. package/dist/src/mutation-node/model-property.test.d.ts +2 -0
  103. package/dist/src/mutation-node/model-property.test.d.ts.map +1 -0
  104. package/dist/src/mutation-node/model-property.test.js +108 -0
  105. package/dist/src/mutation-node/model-property.test.js.map +1 -0
  106. package/dist/src/mutation-node/model.d.ts +10 -0
  107. package/dist/src/mutation-node/model.d.ts.map +1 -0
  108. package/dist/src/mutation-node/model.js +82 -0
  109. package/dist/src/mutation-node/model.js.map +1 -0
  110. package/dist/src/mutation-node/model.test.d.ts +2 -0
  111. package/dist/src/mutation-node/model.test.d.ts.map +1 -0
  112. package/dist/src/mutation-node/model.test.js +133 -0
  113. package/dist/src/mutation-node/model.test.js.map +1 -0
  114. package/dist/src/mutation-node/mutation-edge.d.ts +18 -0
  115. package/dist/src/mutation-node/mutation-edge.d.ts.map +1 -0
  116. package/dist/src/mutation-node/mutation-edge.js +31 -0
  117. package/dist/src/mutation-node/mutation-edge.js.map +1 -0
  118. package/dist/src/mutation-node/mutation-node.d.ts +29 -0
  119. package/dist/src/mutation-node/mutation-node.d.ts.map +1 -0
  120. package/dist/src/mutation-node/mutation-node.js +82 -0
  121. package/dist/src/mutation-node/mutation-node.js.map +1 -0
  122. package/dist/src/mutation-node/mutation-node.test.d.ts +2 -0
  123. package/dist/src/mutation-node/mutation-node.test.d.ts.map +1 -0
  124. package/dist/src/mutation-node/mutation-node.test.js +88 -0
  125. package/dist/src/mutation-node/mutation-node.test.js.map +1 -0
  126. package/dist/src/mutation-node/mutation-subgraph.d.ts +17 -0
  127. package/dist/src/mutation-node/mutation-subgraph.d.ts.map +1 -0
  128. package/dist/src/mutation-node/mutation-subgraph.js +45 -0
  129. package/dist/src/mutation-node/mutation-subgraph.js.map +1 -0
  130. package/dist/src/mutation-node/operation.d.ts +9 -0
  131. package/dist/src/mutation-node/operation.d.ts.map +1 -0
  132. package/dist/src/mutation-node/operation.js +44 -0
  133. package/dist/src/mutation-node/operation.js.map +1 -0
  134. package/dist/src/mutation-node/scalar.d.ts +8 -0
  135. package/dist/src/mutation-node/scalar.d.ts.map +1 -0
  136. package/dist/src/mutation-node/scalar.js +28 -0
  137. package/dist/src/mutation-node/scalar.js.map +1 -0
  138. package/dist/src/mutation-node/scalar.test.d.ts +2 -0
  139. package/dist/src/mutation-node/scalar.test.d.ts.map +1 -0
  140. package/dist/src/mutation-node/scalar.test.js +40 -0
  141. package/dist/src/mutation-node/scalar.test.js.map +1 -0
  142. package/dist/src/mutation-node/tuple.d.ts +9 -0
  143. package/dist/src/mutation-node/tuple.d.ts.map +1 -0
  144. package/dist/src/mutation-node/tuple.js +32 -0
  145. package/dist/src/mutation-node/tuple.js.map +1 -0
  146. package/dist/src/mutation-node/tuple.test.d.ts +2 -0
  147. package/dist/src/mutation-node/tuple.test.d.ts.map +1 -0
  148. package/dist/src/mutation-node/tuple.test.js +29 -0
  149. package/dist/src/mutation-node/tuple.test.js.map +1 -0
  150. package/dist/src/mutation-node/union-variant.d.ts +8 -0
  151. package/dist/src/mutation-node/union-variant.d.ts.map +1 -0
  152. package/dist/src/mutation-node/union-variant.js +23 -0
  153. package/dist/src/mutation-node/union-variant.js.map +1 -0
  154. package/dist/src/mutation-node/union-variant.test.d.ts +2 -0
  155. package/dist/src/mutation-node/union-variant.test.d.ts.map +1 -0
  156. package/dist/src/mutation-node/union-variant.test.js +27 -0
  157. package/dist/src/mutation-node/union-variant.test.js.map +1 -0
  158. package/dist/src/mutation-node/union.d.ts +8 -0
  159. package/dist/src/mutation-node/union.d.ts.map +1 -0
  160. package/dist/src/mutation-node/union.js +30 -0
  161. package/dist/src/mutation-node/union.js.map +1 -0
  162. package/dist/src/mutation-node/union.test.d.ts +2 -0
  163. package/dist/src/mutation-node/union.test.d.ts.map +1 -0
  164. package/dist/src/mutation-node/union.test.js +25 -0
  165. package/dist/src/mutation-node/union.test.js.map +1 -0
  166. package/dist/test/test-host.d.ts +2 -0
  167. package/dist/test/test-host.d.ts.map +1 -0
  168. package/dist/test/test-host.js +6 -0
  169. package/dist/test/test-host.js.map +1 -0
  170. package/dist/test/utils.d.ts +4 -0
  171. package/dist/test/utils.d.ts.map +1 -0
  172. package/dist/test/utils.js +8 -0
  173. package/dist/test/utils.js.map +1 -0
  174. package/package.json +40 -0
  175. package/package.json.bak +42 -0
  176. package/readme.md +339 -0
  177. package/src/index.ts +4 -0
  178. package/src/mutation/index.ts +12 -0
  179. package/src/mutation/interface.ts +38 -0
  180. package/src/mutation/intrinsic.ts +23 -0
  181. package/src/mutation/literal.ts +29 -0
  182. package/src/mutation/model-property.ts +35 -0
  183. package/src/mutation/model.ts +58 -0
  184. package/src/mutation/mutation-engine.test.ts +202 -0
  185. package/src/mutation/mutation-engine.ts +288 -0
  186. package/src/mutation/mutation.ts +90 -0
  187. package/src/mutation/operation.ts +40 -0
  188. package/src/mutation/scalar.ts +36 -0
  189. package/src/mutation/simple-mutation-engine.ts +21 -0
  190. package/src/mutation/union-variant.ts +30 -0
  191. package/src/mutation/union.ts +39 -0
  192. package/src/mutation-node/enum-member.test.ts +26 -0
  193. package/src/mutation-node/enum-member.ts +8 -0
  194. package/src/mutation-node/enum.test.ts +26 -0
  195. package/src/mutation-node/enum.ts +33 -0
  196. package/src/mutation-node/factory.ts +95 -0
  197. package/src/mutation-node/index.ts +16 -0
  198. package/src/mutation-node/interface.ts +33 -0
  199. package/src/mutation-node/intrinsic.ts +8 -0
  200. package/src/mutation-node/literal.ts +10 -0
  201. package/src/mutation-node/model-property.test.ts +136 -0
  202. package/src/mutation-node/model-property.ts +53 -0
  203. package/src/mutation-node/model.test.ts +151 -0
  204. package/src/mutation-node/model.ts +89 -0
  205. package/src/mutation-node/mutation-edge.ts +43 -0
  206. package/src/mutation-node/mutation-node.test.ts +94 -0
  207. package/src/mutation-node/mutation-node.ts +110 -0
  208. package/src/mutation-node/mutation-subgraph.ts +59 -0
  209. package/src/mutation-node/operation.ts +49 -0
  210. package/src/mutation-node/scalar.test.ts +44 -0
  211. package/src/mutation-node/scalar.ts +32 -0
  212. package/src/mutation-node/tuple.test.ts +30 -0
  213. package/src/mutation-node/tuple.ts +35 -0
  214. package/src/mutation-node/union-variant.test.ts +28 -0
  215. package/src/mutation-node/union-variant.ts +26 -0
  216. package/src/mutation-node/union.test.ts +26 -0
  217. package/src/mutation-node/union.ts +33 -0
  218. package/test/test-host.ts +6 -0
  219. package/test/utils.ts +9 -0
  220. package/tsconfig.json +19 -0
  221. package/vitest.config.ts +4 -0
@@ -0,0 +1,145 @@
1
+ import { t } from "@typespec/compiler/testing";
2
+ import { $ } from "@typespec/compiler/typekit";
3
+ import { expect, it } from "vitest";
4
+ import { Tester } from "../../test/test-host.js";
5
+ import { ModelPropertyMutation } from "./model-property.js";
6
+ import { ModelMutation } from "./model.js";
7
+ import { MutationEngine, MutationOptions } from "./mutation-engine.js";
8
+ import { SimpleMutationEngine } from "./simple-mutation-engine.js";
9
+ class RenameMutationOptions extends MutationOptions {
10
+ prefix;
11
+ suffix;
12
+ constructor(prefix, suffix) {
13
+ super();
14
+ this.prefix = prefix;
15
+ this.suffix = suffix;
16
+ }
17
+ cacheKey() {
18
+ return `${this.prefix}-${this.suffix}`;
19
+ }
20
+ }
21
+ class RenameMutationEngine extends MutationEngine {
22
+ constructor($) {
23
+ super($, {
24
+ Model: RenameModelMutation,
25
+ });
26
+ this.registerSubgraph("prefix");
27
+ this.registerSubgraph("suffix");
28
+ }
29
+ getPrefixSubgraph(options) {
30
+ return this.getMutationSubgraph(options, "prefix");
31
+ }
32
+ getSuffixSubgraph(options) {
33
+ return this.getMutationSubgraph(options, "suffix");
34
+ }
35
+ }
36
+ class RenameModelMutation extends ModelMutation {
37
+ get #prefixSubgraph() {
38
+ return this.engine.getPrefixSubgraph(this.options);
39
+ }
40
+ get #suffixSubgraph() {
41
+ return this.engine.getSuffixSubgraph(this.options);
42
+ }
43
+ get withPrefix() {
44
+ return this.getMutatedType(this.#prefixSubgraph);
45
+ }
46
+ get withSuffix() {
47
+ return this.getMutatedType(this.#suffixSubgraph);
48
+ }
49
+ mutate() {
50
+ if ("name" in this.sourceType && typeof this.sourceType.name === "string") {
51
+ this.mutateType(this.#prefixSubgraph, (m) => (m.name = `${this.options.prefix}${this.sourceType.name}`));
52
+ this.mutateType(this.#suffixSubgraph, (m) => (m.name = `${this.sourceType.name}${this.options.suffix}`));
53
+ }
54
+ // mutate all connected types passing on the same options
55
+ super.mutate();
56
+ }
57
+ }
58
+ it("creates mutations", async () => {
59
+ const runner = await Tester.createInstance();
60
+ const { Foo, Bar, prop, program } = await runner.compile(t.code `
61
+ model ${t.model("Foo")} {
62
+ ${t.modelProperty("prop")}: Bar;
63
+ }
64
+
65
+ model ${t.model("Bar")} {
66
+ prop: string;
67
+ }
68
+ `);
69
+ const tk = $(program);
70
+ const engine = new RenameMutationEngine(tk);
71
+ const options = new RenameMutationOptions("Pre", "Suf");
72
+ const fooMutation = engine.mutate(Foo, options);
73
+ // can navigate the mutation result to get prefix and suffix names side-by-side
74
+ expect(fooMutation.properties.size).toBe(1);
75
+ const barMutation = fooMutation.properties.get("prop").type;
76
+ expect(barMutation.withPrefix.name).toBe("PreBar");
77
+ // Or you could get barMutation like:
78
+ const barMutation2 = engine.mutate(Bar, options);
79
+ // but these are not the same mutation node because the mutation accessed via
80
+ // the property is a distinct from the one accessed from the scalar.
81
+ expect(barMutation === barMutation2).toBe(false);
82
+ expect(barMutation.referenceTypes.length).toEqual(1);
83
+ expect(barMutation.referenceTypes[0] === prop).toBe(true);
84
+ expect(barMutation2.referenceTypes.length).toEqual(0);
85
+ // The graph is mutated
86
+ const prefixModel = fooMutation.withPrefix;
87
+ const suffixModel = fooMutation.withSuffix;
88
+ expect(prefixModel.name).toBe("PreFoo");
89
+ expect(prefixModel.properties.get("prop").type.name).toBe("PreBar");
90
+ expect(suffixModel.name).toBe("FooSuf");
91
+ expect(suffixModel.properties.get("prop").type.name).toBe("BarSuf");
92
+ });
93
+ class UnionifyModel extends ModelMutation {
94
+ get unionified() {
95
+ return this.getMutatedType();
96
+ }
97
+ }
98
+ class UnionifyProperty extends ModelPropertyMutation {
99
+ get unionified() {
100
+ return this.getMutatedType();
101
+ }
102
+ mutate() {
103
+ if (!this.engine.$.union.is(this.sourceType.type)) {
104
+ // turn it into this union:
105
+ const newUnionType = this.engine.$.union.create({
106
+ variants: [
107
+ this.engine.$.unionVariant.create({ type: this.sourceType.type }),
108
+ this.engine.$.unionVariant.create({
109
+ type: this.engine.$.builtin.string,
110
+ }),
111
+ ],
112
+ });
113
+ this.type = this.replaceReferencedType(this.engine.getDefaultMutationSubgraph(this.options), newUnionType);
114
+ }
115
+ else {
116
+ super.mutate();
117
+ }
118
+ }
119
+ }
120
+ it("mutates model properties into unions", async () => {
121
+ const runner = await Tester.createInstance();
122
+ const { Foo, program } = await runner.compile(t.code `
123
+ model ${t.model("Foo")} {
124
+ ${t.modelProperty("prop")}: Bar;
125
+ }
126
+
127
+ model ${t.model("Bar")} {
128
+ barProp: string;
129
+ }
130
+ `);
131
+ const tk = $(program);
132
+ const engine = new SimpleMutationEngine(tk, {
133
+ ModelProperty: UnionifyProperty,
134
+ Model: UnionifyModel,
135
+ });
136
+ const fooMutation = engine.mutate(Foo);
137
+ const propMutation = fooMutation.properties.get("prop");
138
+ const typeMutation = propMutation.type;
139
+ expect(typeMutation.kind).toBe("Union");
140
+ const propType = propMutation.unionified;
141
+ expect(tk.union.is(propType.type)).toBe(true);
142
+ const mutatedFoo = fooMutation.unionified;
143
+ expect(tk.union.is(mutatedFoo.properties.get("prop").type)).toBe(true);
144
+ });
145
+ //# sourceMappingURL=mutation-engine.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutation-engine.test.js","sourceRoot":"","sources":["../../../src/mutation/mutation-engine.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,4BAA4B,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAgB,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;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,IAAI,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { MemberType, Type } from "@typespec/compiler";
2
+ import type { MutationNodeForType } from "../mutation-node/factory.js";
3
+ import type { MutationSubgraph } from "../mutation-node/mutation-subgraph.js";
4
+ import type { CustomMutationClasses, MutationEngine, MutationOptions } from "./mutation-engine.js";
5
+ export declare abstract class Mutation<TSourceType extends Type, TCustomMutations extends CustomMutationClasses, TOptions extends MutationOptions = MutationOptions, TEngine extends MutationEngine<TCustomMutations> = MutationEngine<TCustomMutations>> {
6
+ abstract readonly kind: string;
7
+ static readonly subgraphNames: string[];
8
+ engine: TEngine;
9
+ sourceType: TSourceType;
10
+ options: TOptions;
11
+ isMutated: boolean;
12
+ referenceTypes: MemberType[];
13
+ constructor(engine: TEngine, sourceType: TSourceType, referenceTypes: MemberType[], options: TOptions);
14
+ abstract mutate(): void;
15
+ /**
16
+ * Retrieve the mutated type for this mutation's default subgraph.
17
+ */
18
+ protected getMutatedType(): TSourceType;
19
+ /**
20
+ * Retrieve the mutated type for the provided subgraph.
21
+ */
22
+ protected getMutatedType(subgraph: MutationSubgraph): TSourceType;
23
+ /**
24
+ * Retrieve the mutation node for this mutation's default subgraph.
25
+ */
26
+ protected getMutationNode(): MutationNodeForType<TSourceType>;
27
+ /**
28
+ * Retrieve the mutation node for the provided subgraph.
29
+ */
30
+ protected getMutationNode(subgraph: MutationSubgraph): MutationNodeForType<TSourceType>;
31
+ /**
32
+ * Retrieve the mutation node for either the default subgraph with the given
33
+ * options or a specific subgraph.
34
+ */
35
+ protected getMutationNode(subgraphOrOptions: MutationSubgraph | MutationOptions): MutationNodeForType<TSourceType>;
36
+ /**
37
+ * Mutate this type in the default subgraph.
38
+ */
39
+ protected mutateType(initializeMutation?: (type: TSourceType) => void): void;
40
+ /**
41
+ * Mutate this type in the given subgraph
42
+ */
43
+ protected mutateType(subgraph: MutationSubgraph, initializeMutation?: (type: TSourceType) => void): void;
44
+ }
45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,CAAC,eAAe,CAAC,QAAQ,EAAE,gBAAgB,GAAG,mBAAmB,CAAC,WAAW,CAAC;IACvF;;;OAGG;IACH,SAAS,CAAC,eAAe,CACvB,iBAAiB,EAAE,gBAAgB,GAAG,eAAe,GACpD,mBAAmB,CAAC,WAAW,CAAC;IAKnC;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,GAAG,IAAI;IAC5E;;OAEG;IACH,SAAS,CAAC,UAAU,CAClB,QAAQ,EAAE,gBAAgB,EAC1B,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,GAC/C,IAAI;CAaR"}
@@ -0,0 +1,29 @@
1
+ export class Mutation {
2
+ static subgraphNames = [];
3
+ engine;
4
+ sourceType;
5
+ options;
6
+ isMutated = false;
7
+ referenceTypes;
8
+ constructor(engine, sourceType, referenceTypes, options) {
9
+ this.engine = engine;
10
+ this.sourceType = sourceType;
11
+ this.options = options;
12
+ this.referenceTypes = referenceTypes;
13
+ }
14
+ getMutatedType(subgraphOrOptions) {
15
+ return this.engine.getMutatedType(subgraphOrOptions ?? this.options, this.sourceType);
16
+ }
17
+ getMutationNode(subgraphOrOptions) {
18
+ return this.engine.getMutationNode(subgraphOrOptions ?? this.options, this.sourceType);
19
+ }
20
+ mutateType(subgraphOrInit, initializeMutation) {
21
+ if (typeof subgraphOrInit === "function") {
22
+ initializeMutation = subgraphOrInit;
23
+ subgraphOrInit = undefined;
24
+ }
25
+ const node = this.getMutationNode(subgraphOrInit ?? this.options);
26
+ node.mutate(initializeMutation);
27
+ }
28
+ }
29
+ //# sourceMappingURL=mutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutation.js","sourceRoot":"","sources":["../../../src/mutation/mutation.ts"],"names":[],"mappings":"AAKA,MAAM,OAAgB,QAAQ;IAQ5B,MAAM,CAAU,aAAa,GAAa,EAAE,CAAC;IAE7C,MAAM,CAAU;IAChB,UAAU,CAAc;IACxB,OAAO,CAAW;IAClB,SAAS,GAAY,KAAK,CAAC;IAC3B,cAAc,CAAe;IAE7B,YACE,MAAe,EACf,UAAuB,EACvB,cAA4B,EAC5B,OAAiB;QAEjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAYS,cAAc,CAAC,iBAAsD;QAC7E,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,iBAAiB,IAAI,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACxF,CAAC;IAiBS,eAAe,CAAC,iBAAsD;QAC9E,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,iBAAiB,IAAI,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzF,CAAC;IAcS,UAAU,CAClB,cAAiE,EACjE,kBAAgD;QAEhD,IAAI,OAAO,cAAc,KAAK,UAAU,EAAE,CAAC;YACzC,kBAAkB,GAAG,cAAc,CAAC;YACpC,cAAc,GAAG,SAAS,CAAC;QAC7B,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;QAClE,IAAI,CAAC,MAAM,CAAC,kBAA0C,CAAC,CAAC;IAC1D,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { MemberType, Operation, Type } from "@typespec/compiler";
2
+ import type { CustomMutationClasses, MutationEngine, MutationFor, MutationOptions } from "./mutation-engine.js";
3
+ import { Mutation } from "./mutation.js";
4
+ export declare class OperationMutation<TOptions extends MutationOptions, TCustomMutations extends CustomMutationClasses, TEngine extends MutationEngine<TCustomMutations> = MutationEngine<TCustomMutations>> extends Mutation<Operation, TCustomMutations, TOptions, TEngine> {
5
+ readonly kind = "Operation";
6
+ parameters: MutationFor<TCustomMutations, "Model">;
7
+ returnType: MutationFor<TCustomMutations, Type["kind"]>;
8
+ constructor(engine: TEngine, sourceType: Operation, referenceTypes: MemberType[] | undefined, options: TOptions);
9
+ protected mutateParameters(): void;
10
+ protected mutateReturnType(): void;
11
+ mutate(): void;
12
+ }
13
+ //# sourceMappingURL=operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/mutation/operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EACd,WAAW,EACX,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,qBAAa,iBAAiB,CAC5B,QAAQ,SAAS,eAAe,EAChC,gBAAgB,SAAS,qBAAqB,EAC9C,OAAO,SAAS,cAAc,CAAC,gBAAgB,CAAC,GAAG,cAAc,CAAC,gBAAgB,CAAC,CACnF,SAAQ,QAAQ,CAAC,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,CAAC;IAChE,QAAQ,CAAC,IAAI,eAAe;IAC5B,UAAU,EAAG,WAAW,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;IACpD,UAAU,EAAG,WAAW,CAAC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;gBAGvD,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,SAAS,EACrB,cAAc,EAAE,UAAU,EAAE,YAAK,EACjC,OAAO,EAAE,QAAQ;IAKnB,SAAS,CAAC,gBAAgB;IAI1B,SAAS,CAAC,gBAAgB;IAI1B,MAAM;CAIP"}
@@ -0,0 +1,20 @@
1
+ import { Mutation } from "./mutation.js";
2
+ export class OperationMutation extends Mutation {
3
+ kind = "Operation";
4
+ parameters;
5
+ returnType;
6
+ constructor(engine, sourceType, referenceTypes = [], options) {
7
+ super(engine, sourceType, referenceTypes, options);
8
+ }
9
+ mutateParameters() {
10
+ this.parameters = this.engine.mutate(this.sourceType.parameters, this.options);
11
+ }
12
+ mutateReturnType() {
13
+ this.returnType = this.engine.mutate(this.sourceType.returnType, this.options);
14
+ }
15
+ mutate() {
16
+ this.mutateParameters();
17
+ this.mutateReturnType();
18
+ }
19
+ }
20
+ //# sourceMappingURL=operation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/mutation/operation.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,iBAIX,SAAQ,QAAwD;IACvD,IAAI,GAAG,WAAW,CAAC;IAC5B,UAAU,CAA0C;IACpD,UAAU,CAA+C;IAEzD,YACE,MAAe,EACf,UAAqB,EACrB,iBAA+B,EAAE,EACjC,OAAiB;QAEjB,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAES,gBAAgB;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACjF,CAAC;IAES,gBAAgB;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACjF,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import type { MemberType, Scalar } from "@typespec/compiler";
2
+ import type { CustomMutationClasses, MutationEngine, MutationFor, MutationOptions } from "./mutation-engine.js";
3
+ import { Mutation } from "./mutation.js";
4
+ export declare class ScalarMutation<TOptions extends MutationOptions, TCustomMutations extends CustomMutationClasses, TEngine extends MutationEngine<TCustomMutations> = MutationEngine<TCustomMutations>> extends Mutation<Scalar, TCustomMutations, TOptions, TEngine> {
5
+ readonly kind = "Scalar";
6
+ baseScalar?: MutationFor<TCustomMutations, "Scalar">;
7
+ constructor(engine: TEngine, sourceType: Scalar, referenceTypes: MemberType[] | undefined, options: TOptions);
8
+ protected mutateBaseScalar(): void;
9
+ mutate(): void;
10
+ }
11
+ //# sourceMappingURL=scalar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../../src/mutation/scalar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EACd,WAAW,EACX,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,qBAAa,cAAc,CACzB,QAAQ,SAAS,eAAe,EAChC,gBAAgB,SAAS,qBAAqB,EAC9C,OAAO,SAAS,cAAc,CAAC,gBAAgB,CAAC,GAAG,cAAc,CAAC,gBAAgB,CAAC,CACnF,SAAQ,QAAQ,CAAC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,CAAC;IAC7D,QAAQ,CAAC,IAAI,YAAY;IACzB,UAAU,CAAC,EAAE,WAAW,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;gBAGnD,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,UAAU,EAAE,YAAK,EACjC,OAAO,EAAE,QAAQ;IAKnB,SAAS,CAAC,gBAAgB;IAM1B,MAAM;CAGP"}
@@ -0,0 +1,17 @@
1
+ import { Mutation } from "./mutation.js";
2
+ export class ScalarMutation extends Mutation {
3
+ kind = "Scalar";
4
+ baseScalar;
5
+ constructor(engine, sourceType, referenceTypes = [], options) {
6
+ super(engine, sourceType, referenceTypes, options);
7
+ }
8
+ mutateBaseScalar() {
9
+ if (this.sourceType.baseScalar) {
10
+ this.baseScalar = this.engine.mutate(this.sourceType.baseScalar, this.options);
11
+ }
12
+ }
13
+ mutate() {
14
+ this.mutateBaseScalar();
15
+ }
16
+ }
17
+ //# sourceMappingURL=scalar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar.js","sourceRoot":"","sources":["../../../src/mutation/scalar.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,cAIX,SAAQ,QAAqD;IACpD,IAAI,GAAG,QAAQ,CAAC;IACzB,UAAU,CAA2C;IAErD,YACE,MAAe,EACf,UAAkB,EAClB,iBAA+B,EAAE,EACjC,OAAiB;QAEjB,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAES,gBAAgB;QACxB,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;YAC/B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACjF,CAAC;IACH,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ import type { Typekit } from "@typespec/compiler/typekit";
2
+ import type { MutationSubgraph } from "../mutation-node/mutation-subgraph.js";
3
+ import { type ConstructorsFor, type CustomMutationClasses, MutationEngine, MutationOptions } from "./mutation-engine.js";
4
+ export declare class SimpleMutationEngine<TCustomMutations extends CustomMutationClasses> extends MutationEngine<TCustomMutations> {
5
+ constructor($: Typekit, mutatorClasses: ConstructorsFor<TCustomMutations>);
6
+ getDefaultMutationSubgraph(options: MutationOptions): MutationSubgraph;
7
+ }
8
+ //# sourceMappingURL=simple-mutation-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-mutation-engine.d.ts","sourceRoot":"","sources":["../../../src/mutation/simple-mutation-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,cAAc,EACd,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAE9B,qBAAa,oBAAoB,CAC/B,gBAAgB,SAAS,qBAAqB,CAC9C,SAAQ,cAAc,CAAC,gBAAgB,CAAC;gBAC5B,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,eAAe,CAAC,gBAAgB,CAAC;IAKzE,0BAA0B,CAAC,OAAO,EAAE,eAAe,GAAG,gBAAgB;CAGvE"}
@@ -0,0 +1,11 @@
1
+ import { MutationEngine, MutationOptions, } from "./mutation-engine.js";
2
+ export class SimpleMutationEngine extends MutationEngine {
3
+ constructor($, mutatorClasses) {
4
+ super($, mutatorClasses);
5
+ this.registerSubgraph("subgraph");
6
+ }
7
+ getDefaultMutationSubgraph(options) {
8
+ return super.getMutationSubgraph(options, "subgraph");
9
+ }
10
+ }
11
+ //# sourceMappingURL=simple-mutation-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-mutation-engine.js","sourceRoot":"","sources":["../../../src/mutation/simple-mutation-engine.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,cAAc,EACd,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,OAAO,oBAEX,SAAQ,cAAgC;IACxC,YAAY,CAAU,EAAE,cAAiD;QACvE,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;QACzB,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IAED,0BAA0B,CAAC,OAAwB;QACjD,OAAO,KAAK,CAAC,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACxD,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import type { MemberType, Type, UnionVariant } from "@typespec/compiler";
2
+ import type { CustomMutationClasses, MutationEngine, MutationFor, MutationOptions } from "./mutation-engine.js";
3
+ import { Mutation } from "./mutation.js";
4
+ export declare class UnionVariantMutation<TOptions extends MutationOptions, TCustomMutations extends CustomMutationClasses, TEngine extends MutationEngine<TCustomMutations> = MutationEngine<TCustomMutations>> extends Mutation<UnionVariant, TCustomMutations, TOptions, TEngine> {
5
+ readonly kind = "UnionVariant";
6
+ type: MutationFor<TCustomMutations, Type["kind"]>;
7
+ constructor(engine: TEngine, sourceType: UnionVariant, referenceTypes: MemberType[] | undefined, options: TOptions);
8
+ mutate(): void;
9
+ }
10
+ //# sourceMappingURL=union-variant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union-variant.d.ts","sourceRoot":"","sources":["../../../src/mutation/union-variant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EACd,WAAW,EACX,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,qBAAa,oBAAoB,CAC/B,QAAQ,SAAS,eAAe,EAChC,gBAAgB,SAAS,qBAAqB,EAC9C,OAAO,SAAS,cAAc,CAAC,gBAAgB,CAAC,GAAG,cAAc,CAAC,gBAAgB,CAAC,CACnF,SAAQ,QAAQ,CAAC,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,CAAC;IACnE,QAAQ,CAAC,IAAI,kBAAkB;IAC/B,IAAI,EAAG,WAAW,CAAC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;gBAGjD,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,YAAY,EACxB,cAAc,EAAE,UAAU,EAAE,YAAK,EACjC,OAAO,EAAE,QAAQ;IAKnB,MAAM,IAAI,IAAI;CAGf"}
@@ -0,0 +1,12 @@
1
+ import { Mutation } from "./mutation.js";
2
+ export class UnionVariantMutation extends Mutation {
3
+ kind = "UnionVariant";
4
+ type;
5
+ constructor(engine, sourceType, referenceTypes = [], options) {
6
+ super(engine, sourceType, referenceTypes, options);
7
+ }
8
+ mutate() {
9
+ this.type = this.engine.mutate(this.sourceType.type, this.options);
10
+ }
11
+ }
12
+ //# sourceMappingURL=union-variant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union-variant.js","sourceRoot":"","sources":["../../../src/mutation/union-variant.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,oBAIX,SAAQ,QAA2D;IAC1D,IAAI,GAAG,cAAc,CAAC;IAC/B,IAAI,CAA+C;IAEnD,YACE,MAAe,EACf,UAAwB,EACxB,iBAA+B,EAAE,EACjC,OAAiB;QAEjB,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACrE,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import type { MemberType, Union } from "@typespec/compiler";
2
+ import type { CustomMutationClasses, MutationEngine, MutationFor, MutationOptions } from "./mutation-engine.js";
3
+ import { Mutation } from "./mutation.js";
4
+ export declare class UnionMutation<TOptions extends MutationOptions, TCustomMutations extends CustomMutationClasses, TEngine extends MutationEngine<TCustomMutations> = MutationEngine<TCustomMutations>> extends Mutation<Union, TCustomMutations, TOptions, TEngine> {
5
+ readonly kind = "Union";
6
+ variants: Map<string | symbol, MutationFor<TCustomMutations, "UnionVariant">>;
7
+ constructor(engine: TEngine, sourceType: Union, referenceTypes: MemberType[] | undefined, options: TOptions);
8
+ protected mutateVariants(): void;
9
+ mutate(): void;
10
+ }
11
+ //# sourceMappingURL=union.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../../src/mutation/union.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EACd,WAAW,EACX,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,qBAAa,aAAa,CACxB,QAAQ,SAAS,eAAe,EAChC,gBAAgB,SAAS,qBAAqB,EAC9C,OAAO,SAAS,cAAc,CAAC,gBAAgB,CAAC,GAAG,cAAc,CAAC,gBAAgB,CAAC,CACnF,SAAQ,QAAQ,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,CAAC;IAC5D,QAAQ,CAAC,IAAI,WAAW;IACxB,QAAQ,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,WAAW,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC,CAAa;gBAGxF,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,KAAK,EACjB,cAAc,EAAE,UAAU,EAAE,YAAK,EACjC,OAAO,EAAE,QAAQ;IAKnB,SAAS,CAAC,cAAc;IASxB,MAAM;CAGP"}
@@ -0,0 +1,18 @@
1
+ import { Mutation } from "./mutation.js";
2
+ export class UnionMutation extends Mutation {
3
+ kind = "Union";
4
+ variants = new Map();
5
+ constructor(engine, sourceType, referenceTypes = [], options) {
6
+ super(engine, sourceType, referenceTypes, options);
7
+ }
8
+ mutateVariants() {
9
+ this.variants = new Map([...this.sourceType.variants].map(([name, variant]) => [
10
+ name,
11
+ this.engine.mutate(variant, this.options),
12
+ ]));
13
+ }
14
+ mutate() {
15
+ this.mutateVariants();
16
+ }
17
+ }
18
+ //# sourceMappingURL=union.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union.js","sourceRoot":"","sources":["../../../src/mutation/union.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,aAIX,SAAQ,QAAoD;IACnD,IAAI,GAAG,OAAO,CAAC;IACxB,QAAQ,GAAwE,IAAI,GAAG,EAAE,CAAC;IAE1F,YACE,MAAe,EACf,UAAiB,EACjB,iBAA+B,EAAE,EACjC,OAAiB;QAEjB,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAES,cAAc;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CACrB,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;YACrD,IAAI;YACJ,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC;SAC1C,CAAC,CACH,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import type { EnumMember } from "@typespec/compiler";
2
+ import { MutationNode } from "./mutation-node.js";
3
+ export declare class EnumMemberMutationNode extends MutationNode<EnumMember> {
4
+ readonly kind = "EnumMember";
5
+ traverse(): void;
6
+ }
7
+ //# sourceMappingURL=enum-member.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-member.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/enum-member.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAAa,sBAAuB,SAAQ,YAAY,CAAC,UAAU,CAAC;IAClE,QAAQ,CAAC,IAAI,gBAAgB;IAE7B,QAAQ;CACT"}
@@ -0,0 +1,6 @@
1
+ import { MutationNode } from "./mutation-node.js";
2
+ export class EnumMemberMutationNode extends MutationNode {
3
+ kind = "EnumMember";
4
+ traverse() { }
5
+ }
6
+ //# sourceMappingURL=enum-member.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-member.js","sourceRoot":"","sources":["../../../src/mutation-node/enum-member.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,sBAAuB,SAAQ,YAAwB;IACzD,IAAI,GAAG,YAAY,CAAC;IAE7B,QAAQ,KAAI,CAAC;CACd"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=enum-member.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-member.test.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/enum-member.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
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 member values", async () => {
10
+ const { program, Foo, a } = await runner.compile(t.code `
11
+ enum ${t.enum("Foo")} {
12
+ ${t.enumMember("a")}: "valueA";
13
+ b: "valueB";
14
+ }
15
+ `);
16
+ const subgraph = getSubgraph(program);
17
+ const fooNode = subgraph.getNode(Foo);
18
+ const aNode = subgraph.getNode(a);
19
+ aNode.mutate((clone) => (clone.value = "valueARenamed"));
20
+ expect(aNode.isMutated).toBe(true);
21
+ expect(fooNode.isMutated).toBe(true);
22
+ expect(fooNode.mutatedType.members.get("a") === aNode.mutatedType).toBe(true);
23
+ expect(aNode.mutatedType.value).toBe("valueARenamed");
24
+ });
25
+ //# sourceMappingURL=enum-member.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-member.test.js","sourceRoot":"","sources":["../../../src/mutation-node/enum-member.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAuB,MAAM,4BAA4B,CAAC;AACpE,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;AAClD,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,mCAAmC,EAAE,KAAK,IAAI,EAAE;IACjD,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA;aAC5C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;UAChB,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;;;KAGtB,CAAC,CAAC;IAEL,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAClC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,GAAG,eAAe,CAAC,CAAC,CAAC;IACzD,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9E,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AACxD,CAAC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Enum, EnumMember } from "@typespec/compiler";
2
+ import { MutationNode } from "./mutation-node.js";
3
+ export declare class EnumMutationNode extends MutationNode<Enum> {
4
+ readonly kind = "Enum";
5
+ traverse(): void;
6
+ connectMember(memberNode: MutationNode<EnumMember>, sourcePropName: string): void;
7
+ }
8
+ //# sourceMappingURL=enum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/enum.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAAa,gBAAiB,SAAQ,YAAY,CAAC,IAAI,CAAC;IACtD,QAAQ,CAAC,IAAI,UAAU;IAEvB,QAAQ;IAOR,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC,UAAU,CAAC,EAAE,cAAc,EAAE,MAAM;CAkB3E"}
@@ -0,0 +1,30 @@
1
+ import { MutationEdge } from "./mutation-edge.js";
2
+ import { MutationNode } from "./mutation-node.js";
3
+ export class EnumMutationNode extends MutationNode {
4
+ kind = "Enum";
5
+ traverse() {
6
+ for (const member of this.sourceType.members.values()) {
7
+ const memberNode = this.subgraph.getNode(member);
8
+ this.connectMember(memberNode, member.name);
9
+ }
10
+ }
11
+ connectMember(memberNode, sourcePropName) {
12
+ MutationEdge.create(this, memberNode, {
13
+ onTailMutation: () => {
14
+ this.mutatedType.members.delete(sourcePropName);
15
+ this.mutatedType.members.set(memberNode.mutatedType.name, memberNode.mutatedType);
16
+ },
17
+ onTailDeletion: () => {
18
+ this.mutatedType.members.delete(sourcePropName);
19
+ },
20
+ onTailReplaced: (newTail) => {
21
+ if (newTail.mutatedType.kind !== "EnumMember") {
22
+ throw new Error("Cannot replace enum member with non-enum member type");
23
+ }
24
+ this.mutatedType.members.delete(sourcePropName);
25
+ this.mutatedType.members.set(newTail.mutatedType.name, newTail.mutatedType);
26
+ },
27
+ });
28
+ }
29
+ }
30
+ //# sourceMappingURL=enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../src/mutation-node/enum.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,OAAO,gBAAiB,SAAQ,YAAkB;IAC7C,IAAI,GAAG,MAAM,CAAC;IAEvB,QAAQ;QACN,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACtD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACjD,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,aAAa,CAAC,UAAoC,EAAE,cAAsB;QACxE,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE;YACpC,cAAc,EAAE,GAAG,EAAE;gBACnB,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;gBAChD,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;YACpF,CAAC;YACD,cAAc,EAAE,GAAG,EAAE;gBACnB,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YAClD,CAAC;YACD,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE;gBAC1B,IAAI,OAAO,CAAC,WAAW,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;oBAC9C,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;gBAC1E,CAAC;gBACD,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;gBAChD,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;YAC9E,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=enum.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.test.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/enum.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
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 members", async () => {
10
+ const { program, Foo, a } = await runner.compile(t.code `
11
+ enum ${t.enum("Foo")} {
12
+ ${t.enumMember("a")};
13
+ b;
14
+ }
15
+ `);
16
+ const subgraph = getSubgraph(program);
17
+ const fooNode = subgraph.getNode(Foo);
18
+ const aNode = subgraph.getNode(a);
19
+ aNode.mutate((clone) => (clone.name = "aRenamed"));
20
+ expect(aNode.isMutated).toBe(true);
21
+ expect(fooNode.isMutated).toBe(true);
22
+ expect(fooNode.mutatedType.members.get("a") === undefined).toBeTruthy();
23
+ expect(fooNode.mutatedType.members.get("aRenamed") === aNode.mutatedType).toBeTruthy();
24
+ });
25
+ //# sourceMappingURL=enum.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.test.js","sourceRoot":"","sources":["../../../src/mutation-node/enum.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAuB,MAAM,4BAA4B,CAAC;AACpE,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;AAClD,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,6BAA6B,EAAE,KAAK,IAAI,EAAE;IAC3C,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA;aAC5C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;UAChB,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;;;KAGtB,CAAC,CAAC;IAEL,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAClC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC;IACnD,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;IACxE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,KAAK,CAAC,WAAW,CAAC,CAAC,UAAU,EAAE,CAAC;AACzF,CAAC,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { BooleanLiteral, Enum, EnumMember, Interface, IntrinsicType, Model, ModelProperty, NumericLiteral, Operation, Scalar, StringLiteral, Tuple, Type, Union, UnionVariant } from "@typespec/compiler";
2
+ import { EnumMemberMutationNode } from "./enum-member.js";
3
+ import { EnumMutationNode } from "./enum.js";
4
+ import { InterfaceMutationNode } from "./interface.js";
5
+ import { IntrinsicMutationNode } from "./intrinsic.js";
6
+ import { LiteralMutationNode } from "./literal.js";
7
+ import { ModelPropertyMutationNode } from "./model-property.js";
8
+ import { ModelMutationNode } from "./model.js";
9
+ import type { MutationSubgraph } from "./mutation-subgraph.js";
10
+ import { OperationMutationNode } from "./operation.js";
11
+ import { ScalarMutationNode } from "./scalar.js";
12
+ import { TupleMutationNode } from "./tuple.js";
13
+ import { UnionVariantMutationNode } from "./union-variant.js";
14
+ import { UnionMutationNode } from "./union.js";
15
+ export declare function mutationNodeFor<T extends Type>(subgraph: MutationSubgraph, sourceType: T): MutationNodeForType<T>;
16
+ export type MutationNodeForType<T extends Type> = T extends Model ? ModelMutationNode : T extends Interface ? InterfaceMutationNode : T extends Operation ? OperationMutationNode : T extends ModelProperty ? ModelPropertyMutationNode : T extends Scalar ? ScalarMutationNode : T extends Tuple ? TupleMutationNode : T extends Union ? UnionMutationNode : T extends UnionVariant ? UnionVariantMutationNode : T extends Enum ? EnumMutationNode : T extends EnumMember ? EnumMemberMutationNode : T extends StringLiteral | NumericLiteral | BooleanLiteral ? LiteralMutationNode : T extends IntrinsicType ? IntrinsicMutationNode : never;
17
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/mutation-node/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,IAAI,EACJ,UAAU,EACV,SAAS,EACT,aAAa,EACb,KAAK,EACL,aAAa,EACb,cAAc,EACd,SAAS,EACT,MAAM,EACN,aAAa,EACb,KAAK,EACL,IAAI,EACJ,KAAK,EACL,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC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