@typespec/emitter-framework 0.7.0-dev.1 → 0.7.0-dev.3

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.
@@ -1,6 +1,6 @@
1
1
  import { ComponentContext } from "@alloy-js/core";
2
2
  import { Program } from "@typespec/compiler";
3
- import { Typekit } from "@typespec/compiler/experimental/typekit";
3
+ import { type Typekit } from "@typespec/compiler/typekit";
4
4
  export type TspContext = {
5
5
  program: Program;
6
6
  $: Typekit;
@@ -1 +1 @@
1
- {"version":3,"file":"tsp-context.d.ts","sourceRoot":"","sources":["../../../../src/core/context/tsp-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkC,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AAElE,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,CAAC,EAAE,OAAO,CAAC;CACZ,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,gBAAgB,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,CAAC,CAAC,EAAE,OAAO,CAAA;CAAE,CAG3D,CAAC;AAEjB,wBAAgB,MAAM,IAaF,UAAU,CAC7B"}
1
+ {"version":3,"file":"tsp-context.d.ts","sourceRoot":"","sources":["../../../../src/core/context/tsp-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkC,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAK,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,CAAC,EAAE,OAAO,CAAC;CACZ,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,gBAAgB,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,CAAC,CAAC,EAAE,OAAO,CAAA;CAAE,CAG3D,CAAC;AAEjB,wBAAgB,MAAM,IAaF,UAAU,CAC7B"}
@@ -1,5 +1,5 @@
1
1
  import { createNamedContext, useContext } from "@alloy-js/core";
2
- import { unsafe_$ } from "@typespec/compiler/experimental";
2
+ import { $ } from "@typespec/compiler/typekit";
3
3
  export const TspContext = createNamedContext("TspContext");
4
4
  export function useTsp() {
5
5
  const context = useContext(TspContext);
@@ -7,7 +7,7 @@ export function useTsp() {
7
7
  throw new Error("TspContext is not set. Make sure the component is wrapped in TspContext.Provider or the emitter framework Output component.");
8
8
  }
9
9
  if (!context.$) {
10
- context.$ = unsafe_$(context.program);
10
+ context.$ = $(context.program);
11
11
  }
12
12
  return context;
13
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"type-transform.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-transform.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,EAAU,MAAM,gBAAgB,CAAC;AAE9E,OAAO,EAEL,KAAK,EAIL,IAAI,EACJ,KAAK,EACN,MAAM,oBAAoB,CAAC;AAa5B,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,CAAC;IACZ,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;CACrC;AAwDD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,kBAAkB,YAqEjE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,GAAG,WAAW,UAEvF;AAED,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,YAwE5E;AAyDD,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,QAAQ,CAuEzE"}
1
+ {"version":3,"file":"type-transform.d.ts","sourceRoot":"","sources":["../../../../src/typescript/components/type-transform.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,EAAU,MAAM,gBAAgB,CAAC;AAE9E,OAAO,EAEL,KAAK,EAIL,IAAI,EACJ,KAAK,EACN,MAAM,oBAAoB,CAAC;AAa5B,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,CAAC;IACZ,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;CACrC;AA+DD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,kBAAkB,YAqEjE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,GAAG,WAAW,UAEvF;AAED,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,YAwE5E;AAyDD,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,aAAa,GAAG,WAAW,CAAC;IACpC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,QAAQ,CAuEzE"}
@@ -10,8 +10,11 @@ function UnionTransformExpression(props) {
10
10
  const {
11
11
  $
12
12
  } = useTsp();
13
- const discriminator = $.type.getDiscriminator(props.type);
14
- if (!discriminator) {
13
+ const discriminator = $.union.getDiscriminatedUnion(props.type);
14
+ const discriminatorProperty = discriminator?.options.discriminatorPropertyName && {
15
+ propertyName: discriminator.options.discriminatorPropertyName
16
+ };
17
+ if (!discriminatorProperty) {
15
18
  // TODO: Handle non-discriminated unions
16
19
  reportTypescriptDiagnostic($.program, {
17
20
  code: "typescript-unsupported-nondiscriminated-union",
@@ -23,7 +26,7 @@ function UnionTransformExpression(props) {
23
26
  get type() {
24
27
  return props.type;
25
28
  },
26
- discriminator: discriminator,
29
+ discriminator: discriminatorProperty,
27
30
  get target() {
28
31
  return props.target;
29
32
  }
@@ -97,7 +100,7 @@ export function TypeTransformDeclaration(props) {
97
100
  });
98
101
  let transformExpression;
99
102
  if ($.model.is(props.type)) {
100
- const discriminator = $.type.getDiscriminator(props.type);
103
+ const discriminator = $.model.getDiscriminatedUnion(props.type);
101
104
  transformExpression = discriminator ? _$createComponent(DiscriminateExpression, {
102
105
  get type() {
103
106
  return props.type;
@@ -3,7 +3,7 @@ import { Output, render } from "@alloy-js/core";
3
3
  import { dedent } from "@alloy-js/core/testing";
4
4
  import { SourceFile } from "@alloy-js/typescript";
5
5
  import { Numeric } from "@typespec/compiler";
6
- import { $ } from "@typespec/compiler/experimental/typekit";
6
+ import { $ } from "@typespec/compiler/typekit";
7
7
  import { assert, beforeAll, describe, expect, it } from "vitest";
8
8
  import { ValueExpression } from "../../../src/typescript/components/value-expression.js";
9
9
  import { getProgram } from "../test-host.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/emitter-framework",
3
- "version": "0.7.0-dev.1",
3
+ "version": "0.7.0-dev.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -19,17 +19,17 @@
19
19
  "license": "MIT",
20
20
  "description": "",
21
21
  "peerDependencies": {
22
- "@alloy-js/core": "^0.11.0",
23
- "@alloy-js/typescript": "^0.11.0",
22
+ "@alloy-js/core": "^0.13.0",
23
+ "@alloy-js/typescript": "^0.13.0",
24
24
  "@typespec/compiler": "^1.0.0-rc.1",
25
25
  "@typespec/http": "^1.0.0-rc.1",
26
26
  "@typespec/rest": "^0.69.0 || >=0.70.0-dev <0.70.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@alloy-js/cli": "^0.11.0",
29
+ "@alloy-js/cli": "^0.13.0",
30
30
  "@alloy-js/rollup-plugin": "^0.1.0",
31
- "@alloy-js/core": "^0.11.0",
32
- "@alloy-js/typescript": "^0.11.0",
31
+ "@alloy-js/core": "^0.13.0",
32
+ "@alloy-js/typescript": "^0.13.0",
33
33
  "@types/minimist": "^1.2.5",
34
34
  "@typespec/compiler": "^1.0.0-rc.1",
35
35
  "@typespec/http": "^1.0.0-rc.1",
@@ -1,7 +1,6 @@
1
1
  import { ComponentContext, createNamedContext, useContext } from "@alloy-js/core";
2
2
  import { Program } from "@typespec/compiler";
3
- import { unsafe_$ } from "@typespec/compiler/experimental";
4
- import { Typekit } from "@typespec/compiler/experimental/typekit";
3
+ import { $, type Typekit } from "@typespec/compiler/typekit";
5
4
 
6
5
  export type TspContext = {
7
6
  program: Program;
@@ -23,7 +22,7 @@ export function useTsp() {
23
22
  }
24
23
 
25
24
  if (!context.$) {
26
- context.$ = unsafe_$(context.program);
25
+ context.$ = $(context.program);
27
26
  }
28
27
 
29
28
  return context as TspContext;
@@ -9,7 +9,7 @@ import {
9
9
  Operation,
10
10
  RekeyableMap,
11
11
  } from "@typespec/compiler";
12
- import { Typekit } from "@typespec/compiler/experimental/typekit";
12
+ import { Typekit } from "@typespec/compiler/typekit";
13
13
  import { createRekeyableMap } from "@typespec/compiler/utils";
14
14
  import { useTsp } from "../../core/context/tsp-context.js";
15
15
  import { reportDiagnostic } from "../../lib.js";
@@ -1,7 +1,7 @@
1
1
  import { For, refkey } from "@alloy-js/core";
2
2
  import { Reference, ValueExpression } from "@alloy-js/typescript";
3
3
  import { IntrinsicType, Model, Scalar, Type } from "@typespec/compiler";
4
- import { Typekit } from "@typespec/compiler/experimental/typekit";
4
+ import { Typekit } from "@typespec/compiler/typekit";
5
5
  import "@typespec/http/experimental/typekit";
6
6
  import { useTsp } from "../../core/context/tsp-context.js";
7
7
  import { reportTypescriptDiagnostic } from "../../typescript/lib.js";
@@ -9,7 +9,7 @@ import {
9
9
  Type,
10
10
  Union,
11
11
  } from "@typespec/compiler";
12
- import { Typekit } from "@typespec/compiler/experimental/typekit";
12
+ import { Typekit } from "@typespec/compiler/typekit";
13
13
  import { createRekeyableMap } from "@typespec/compiler/utils";
14
14
  import { useTsp } from "../../core/context/tsp-context.js";
15
15
  import { reportDiagnostic } from "../../lib.js";
@@ -35,9 +35,12 @@ export interface UnionTransformProps {
35
35
  }
36
36
  function UnionTransformExpression(props: UnionTransformProps) {
37
37
  const { $ } = useTsp();
38
- const discriminator = $.type.getDiscriminator(props.type);
38
+ const discriminator = $.union.getDiscriminatedUnion(props.type);
39
+ const discriminatorProperty = discriminator?.options.discriminatorPropertyName && {
40
+ propertyName: discriminator.options.discriminatorPropertyName,
41
+ };
39
42
 
40
- if (!discriminator) {
43
+ if (!discriminatorProperty) {
41
44
  // TODO: Handle non-discriminated unions
42
45
  reportTypescriptDiagnostic($.program, {
43
46
  code: "typescript-unsupported-nondiscriminated-union",
@@ -47,7 +50,11 @@ function UnionTransformExpression(props: UnionTransformProps) {
47
50
  }
48
51
 
49
52
  return (
50
- <DiscriminateExpression type={props.type} discriminator={discriminator} target={props.target} />
53
+ <DiscriminateExpression
54
+ type={props.type}
55
+ discriminator={discriminatorProperty}
56
+ target={props.target}
57
+ />
51
58
  );
52
59
  }
53
60
 
@@ -122,7 +129,7 @@ export function TypeTransformDeclaration(props: TypeTransformProps) {
122
129
 
123
130
  let transformExpression: Children;
124
131
  if ($.model.is(props.type)) {
125
- const discriminator = $.type.getDiscriminator(props.type);
132
+ const discriminator = $.model.getDiscriminatedUnion(props.type);
126
133
 
127
134
  transformExpression = discriminator ? (
128
135
  <DiscriminateExpression
@@ -10,7 +10,7 @@ import {
10
10
  Program,
11
11
  Value,
12
12
  } from "@typespec/compiler";
13
- import { $ } from "@typespec/compiler/experimental/typekit";
13
+ import { $ } from "@typespec/compiler/typekit";
14
14
  import { assert, beforeAll, describe, expect, it } from "vitest";
15
15
  import { ValueExpression } from "../../../src/typescript/components/value-expression.js";
16
16
  import { getProgram } from "../test-host.js";