@typespec/http-client-js 0.4.0-dev.7 → 0.4.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 (94) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/src/components/client-context/client-context-factory.d.ts.map +1 -1
  3. package/dist/src/components/client-context/client-context-factory.js +10 -1
  4. package/dist/src/components/client-operation.d.ts.map +1 -1
  5. package/dist/src/components/client-operation.js +4 -1
  6. package/dist/src/components/client.d.ts.map +1 -1
  7. package/dist/src/components/client.js +13 -1
  8. package/dist/src/components/http-response.d.ts.map +1 -1
  9. package/dist/src/components/http-response.js +4 -1
  10. package/dist/src/components/models.d.ts.map +1 -1
  11. package/dist/src/components/models.js +4 -1
  12. package/dist/src/components/operation-handlers/paging/page-item.d.ts.map +1 -1
  13. package/dist/src/components/operation-handlers/paging/page-item.js +4 -1
  14. package/dist/src/components/operation-handlers/paging/paginated-operation-handler.d.ts.map +1 -1
  15. package/dist/src/components/operation-handlers/paging/paginated-operation-handler.js +7 -1
  16. package/dist/src/components/output.d.ts +2 -0
  17. package/dist/src/components/output.d.ts.map +1 -1
  18. package/dist/src/components/output.js +6 -5
  19. package/dist/src/components/serializers.d.ts.map +1 -1
  20. package/dist/src/components/serializers.js +7 -4
  21. package/dist/src/components/transforms/data-transform.d.ts.map +1 -1
  22. package/dist/src/components/transforms/data-transform.js +4 -1
  23. package/dist/src/components/transforms/json/json-array-transform.d.ts.map +1 -1
  24. package/dist/src/components/transforms/json/json-array-transform.js +7 -1
  25. package/dist/src/components/transforms/json/json-model-additional-properties-transform.d.ts.map +1 -1
  26. package/dist/src/components/transforms/json/json-model-additional-properties-transform.js +4 -1
  27. package/dist/src/components/transforms/json/json-model-property-transform.d.ts.map +1 -1
  28. package/dist/src/components/transforms/json/json-model-property-transform.js +4 -1
  29. package/dist/src/components/transforms/json/json-model-transform.d.ts.map +1 -1
  30. package/dist/src/components/transforms/json/json-model-transform.js +7 -1
  31. package/dist/src/components/transforms/json/json-record-transform.d.ts.map +1 -1
  32. package/dist/src/components/transforms/json/json-record-transform.js +7 -1
  33. package/dist/src/components/transforms/json/json-transform-discriminator.d.ts.map +1 -1
  34. package/dist/src/components/transforms/json/json-transform-discriminator.js +7 -1
  35. package/dist/src/components/transforms/json/json-transform.d.ts.map +1 -1
  36. package/dist/src/components/transforms/json/json-transform.js +10 -1
  37. package/dist/src/components/transforms/json/union-transform.d.ts.map +1 -1
  38. package/dist/src/components/transforms/json/union-transform.js +4 -1
  39. package/dist/src/components/transforms/json/utils/transport-namer.d.ts +2 -1
  40. package/dist/src/components/transforms/json/utils/transport-namer.d.ts.map +1 -1
  41. package/dist/src/components/transforms/json/utils/transport-namer.js +1 -2
  42. package/dist/src/components/transforms/multipart/multipart-transform.d.ts.map +1 -1
  43. package/dist/src/components/transforms/multipart/multipart-transform.js +4 -2
  44. package/dist/src/components/transforms/multipart/simple-part-transform.d.ts.map +1 -1
  45. package/dist/src/components/transforms/multipart/simple-part-transform.js +4 -1
  46. package/dist/src/components/transforms/operation-transform-expression.d.ts.map +1 -1
  47. package/dist/src/components/transforms/operation-transform-expression.js +4 -2
  48. package/dist/src/components/transforms/scalar-transform.js +95 -78
  49. package/dist/src/components/transforms/transform-name-policy.d.ts.map +1 -1
  50. package/dist/src/components/transforms/transform-name-policy.js +6 -1
  51. package/dist/src/components/utils/unpack-model-property.d.ts.map +1 -1
  52. package/dist/src/components/utils/unpack-model-property.js +4 -1
  53. package/dist/src/context/encoding/encoding-context.d.ts.map +1 -1
  54. package/dist/src/context/encoding/encoding-context.js +4 -1
  55. package/dist/src/emitter.js +4 -1
  56. package/dist/src/utils/multipart.d.ts.map +1 -1
  57. package/dist/src/utils/multipart.js +4 -1
  58. package/dist/src/utils/operations.d.ts +3 -2
  59. package/dist/src/utils/operations.d.ts.map +1 -1
  60. package/dist/src/utils/operations.js +12 -13
  61. package/dist/src/utils/parameters.d.ts.map +1 -1
  62. package/dist/src/utils/parameters.js +7 -1
  63. package/dist/tsconfig.tsbuildinfo +1 -1
  64. package/package.json +13 -13
  65. package/src/components/client-context/client-context-factory.tsx +4 -1
  66. package/src/components/client-operation.tsx +2 -1
  67. package/src/components/client.tsx +5 -1
  68. package/src/components/http-response.tsx +2 -1
  69. package/src/components/models.tsx +2 -1
  70. package/src/components/operation-handlers/paging/page-item.tsx +2 -1
  71. package/src/components/operation-handlers/paging/paginated-operation-handler.tsx +3 -1
  72. package/src/components/output.tsx +10 -5
  73. package/src/components/serializers.tsx +6 -4
  74. package/src/components/transforms/data-transform.tsx +2 -1
  75. package/src/components/transforms/json/json-array-transform.tsx +3 -1
  76. package/src/components/transforms/json/json-model-additional-properties-transform.tsx +2 -1
  77. package/src/components/transforms/json/json-model-property-transform.tsx +2 -1
  78. package/src/components/transforms/json/json-model-transform.tsx +3 -1
  79. package/src/components/transforms/json/json-record-transform.tsx +3 -1
  80. package/src/components/transforms/json/json-transform-discriminator.tsx +3 -1
  81. package/src/components/transforms/json/json-transform.tsx +4 -1
  82. package/src/components/transforms/json/union-transform.tsx +2 -1
  83. package/src/components/transforms/json/utils/transport-namer.ts +2 -2
  84. package/src/components/transforms/multipart/multipart-transform.tsx +2 -2
  85. package/src/components/transforms/multipart/simple-part-transform.tsx +2 -1
  86. package/src/components/transforms/operation-transform-expression.tsx +2 -2
  87. package/src/components/transforms/scalar-transform.tsx +42 -32
  88. package/src/components/transforms/transform-name-policy.ts +2 -1
  89. package/src/components/utils/unpack-model-property.ts +2 -1
  90. package/src/context/encoding/encoding-context.tsx +2 -1
  91. package/src/emitter.tsx +2 -2
  92. package/src/utils/multipart.ts +2 -1
  93. package/src/utils/operations.ts +13 -11
  94. package/src/utils/parameters.tsx +3 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-js",
3
- "version": "0.4.0-dev.7",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "homepage": "https://typespec.io",
6
6
  "readme": "https://github.com/microsoft/typespec/blob/main/packages/http-client-js/README.md",
@@ -26,27 +26,22 @@
26
26
  "license": "MIT",
27
27
  "description": "TypeSpec library for emitting Http Client libraries for JavaScript/TypeScript",
28
28
  "peerDependencies": {
29
- "@typespec/compiler": "^1.0.0-rc.0",
30
- "@typespec/http": "^1.0.0-rc.0",
31
- "@typespec/rest": "^0.68.0 || >=0.69.0-dev <0.69.0"
29
+ "@typespec/compiler": "^1.0.0-rc.1",
30
+ "@typespec/http": "^1.0.0-rc.1",
31
+ "@typespec/rest": "^0.69.0"
32
32
  },
33
33
  "dependencies": {
34
34
  "@alloy-js/core": "^0.11.0",
35
35
  "@alloy-js/typescript": "^0.11.0",
36
- "@typespec/emitter-framework": "^0.5.0 || >=0.6.0-dev <0.6.0",
37
- "@typespec/http-client": "^0.4.0 || >=0.5.0-dev <0.5.0",
38
- "prettier": "~3.5.3"
36
+ "prettier": "~3.5.3",
37
+ "@typespec/emitter-framework": "^0.6.0",
38
+ "@typespec/http-client": "^0.5.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@alloy-js/cli": "^0.11.0",
42
42
  "@alloy-js/rollup-plugin": "^0.1.0",
43
43
  "@types/yargs": "~17.0.33",
44
- "@typespec/http": "^1.0.0-rc.0",
45
- "@typespec/http-specs": "^0.1.0-alpha.19 || >=0.1.0-alpha.20-dev <0.1.0-alpha.20",
46
- "@typespec/spector": "^0.1.0-alpha.12 || >=0.1.0-alpha.13-dev <0.1.0-alpha.13",
47
44
  "@typespec/ts-http-runtime": "0.2.1",
48
- "@typespec/tspd": "^0.68.0 || >=0.69.0-dev <0.69.0",
49
- "@typespec/versioning": "^0.68.0 || >=0.69.0-dev <0.69.0",
50
45
  "@vitest/ui": "^3.0.9",
51
46
  "change-case": "~5.4.4",
52
47
  "concurrently": "^9.1.2",
@@ -60,7 +55,12 @@
60
55
  "typescript": "~5.8.2",
61
56
  "uri-template": "^2.0.0",
62
57
  "vitest": "^3.0.9",
63
- "yargs": "~17.7.2"
58
+ "yargs": "~17.7.2",
59
+ "@typespec/http": "^1.0.0-rc.1",
60
+ "@typespec/http-specs": "^0.1.0-alpha.20",
61
+ "@typespec/spector": "^0.1.0-alpha.12",
62
+ "@typespec/tspd": "^0.69.0",
63
+ "@typespec/versioning": "^0.69.0"
64
64
  },
65
65
  "scripts": {
66
66
  "build": "alloy build",
@@ -1,6 +1,6 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { $ } from "@typespec/compiler/experimental/typekit";
3
+ import { useTsp } from "@typespec/emitter-framework";
4
4
  import { FunctionDeclaration } from "@typespec/emitter-framework/typescript";
5
5
  import { HttpAuth, type OAuth2Flow } from "@typespec/http";
6
6
  import * as cl from "@typespec/http-client";
@@ -20,6 +20,7 @@ export function getClientContextFactoryRef(client: cl.Client) {
20
20
  }
21
21
 
22
22
  export function ClientContextFactoryDeclaration(props: ClientContextFactoryProps) {
23
+ const { $ } = useTsp();
23
24
  const ref = getClientContextFactoryRef(props.client);
24
25
  const contextDeclarationRef = getClientcontextDeclarationRef(props.client);
25
26
  const namePolicy = ts.useTSNamePolicy();
@@ -99,6 +100,7 @@ interface AuthSchemeProps {
99
100
  }
100
101
 
101
102
  function AuthScheme(props: AuthSchemeProps) {
103
+ const { $ } = useTsp();
102
104
  switch (props.scheme.type) {
103
105
  case "http":
104
106
  return (
@@ -161,6 +163,7 @@ function OAuth2Flow(props: OAuth2FlowProps) {
161
163
  }
162
164
 
163
165
  function AuthSchemeOptions(props: AuthSchemeOptionsProps) {
166
+ const { $ } = useTsp();
164
167
  const clientCredential = $.client.getAuth(props.client);
165
168
 
166
169
  if (clientCredential.schemes.length === 0) {
@@ -1,6 +1,6 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { $ } from "@typespec/compiler/experimental/typekit";
3
+ import { useTsp } from "@typespec/emitter-framework";
4
4
  import { FunctionDeclaration, TypeExpression } from "@typespec/emitter-framework/typescript";
5
5
  import { HttpOperation } from "@typespec/http";
6
6
  import * as cl from "@typespec/http-client";
@@ -47,6 +47,7 @@ export interface ClientOperationProps {
47
47
  }
48
48
 
49
49
  export function ClientOperation(props: ClientOperationProps) {
50
+ const { $ } = useTsp();
50
51
  const clientLibrary = cl.useClientLibrary();
51
52
  const client = clientLibrary.getClientForOperation(props.httpOperation);
52
53
 
@@ -1,6 +1,6 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { $ } from "@typespec/compiler/experimental/typekit";
3
+ import { useTsp } from "@typespec/emitter-framework";
4
4
  import { ClassMethod } from "@typespec/emitter-framework/typescript";
5
5
  import * as cl from "@typespec/http-client";
6
6
  import { useClientLibrary } from "@typespec/http-client";
@@ -13,6 +13,7 @@ import { getOperationParameters } from "./operation-parameters.jsx";
13
13
  export interface ClientProps {}
14
14
 
15
15
  export function Client(props: ClientProps) {
16
+ const { $ } = useTsp();
16
17
  const namePolicy = ts.useTSNamePolicy();
17
18
  const { topLevel } = useClientLibrary();
18
19
 
@@ -45,6 +46,7 @@ function getClientContextFieldRef(client: cl.Client) {
45
46
  return ay.refkey(client.type, "client-context");
46
47
  }
47
48
  export function ClientClass(props: ClientClassProps) {
49
+ const { $ } = useTsp();
48
50
  const namePolicy = ts.useTSNamePolicy();
49
51
  const clientName = namePolicy.getName($.client.getName(props.client), "class");
50
52
  const contextMemberRef = getClientContextFieldRef(props.client);
@@ -103,6 +105,7 @@ function getSubClientClassFieldRef(client: cl.Client) {
103
105
  }
104
106
 
105
107
  function SubClientClassField(props: SubClientClassFieldProps) {
108
+ const { $ } = useTsp();
106
109
  const parent = props.client.parent;
107
110
  // If sub client has different parameters than client, don't add it as a subclass field
108
111
  // Todo: We need to detect the extra parameters and make this field a factory for the subclient
@@ -122,6 +125,7 @@ interface ClientConstructorProps {
122
125
  }
123
126
 
124
127
  function ClientConstructor(props: ClientConstructorProps) {
128
+ const { $ } = useTsp();
125
129
  const subClients = props.client.subClients.filter((sc) =>
126
130
  $.client.haveSameConstructor(sc, props.client),
127
131
  );
@@ -1,6 +1,6 @@
1
1
  import { Children, code, For, List, Refkey } from "@alloy-js/core";
2
2
  import { isVoidType } from "@typespec/compiler";
3
- import { $ } from "@typespec/compiler/experimental/typekit";
3
+ import { useTsp } from "@typespec/emitter-framework";
4
4
  import { HttpOperation } from "@typespec/http";
5
5
  import { getCreateRestErrorRefkey } from "./static-helpers/rest-error.jsx";
6
6
  import { ContentTypeEncodingProvider } from "./transforms/content-type-encoding-provider.jsx";
@@ -26,6 +26,7 @@ export interface HttpResponsesProps {
26
26
  }
27
27
 
28
28
  export function HttpResponses(props: HttpResponsesProps) {
29
+ const { $ } = useTsp();
29
30
  // Handle response by status code and content type
30
31
  const responses = $.httpOperation.flattenResponses(props.httpOperation);
31
32
  return (
@@ -1,6 +1,6 @@
1
1
  import { For, refkey } from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { $ } from "@typespec/compiler/experimental/typekit";
3
+ import { useTsp } from "@typespec/emitter-framework";
4
4
  import * as ef from "@typespec/emitter-framework/typescript";
5
5
  import { useClientLibrary } from "@typespec/http-client";
6
6
  import { getFileTypeReference } from "./static-helpers/multipart-helpers.jsx";
@@ -10,6 +10,7 @@ export interface ModelsProps {
10
10
  }
11
11
 
12
12
  export function Models(props: ModelsProps) {
13
+ const { $ } = useTsp();
13
14
  const clientLibrary = useClientLibrary();
14
15
  const dataTypes = clientLibrary.dataTypes;
15
16
  return (
@@ -1,8 +1,9 @@
1
1
  import { PagingOperation } from "@typespec/compiler";
2
- import { $ } from "@typespec/compiler/experimental/typekit";
2
+ import { useTsp } from "@typespec/emitter-framework";
3
3
  import { TypeExpression } from "@typespec/emitter-framework/typescript";
4
4
 
5
5
  export function getPageItemTypeName(pagingOperation: PagingOperation) {
6
+ const { $ } = useTsp();
6
7
  const type = pagingOperation.output.pageItems.property.type;
7
8
  // only accept array type
8
9
  if (type.kind === "Model" && $.array.is(type)) {
@@ -1,7 +1,7 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import { Children } from "@alloy-js/core";
3
3
  import * as ts from "@alloy-js/typescript";
4
- import { $ } from "@typespec/compiler/experimental/typekit";
4
+ import { useTsp } from "@typespec/emitter-framework";
5
5
  import { FunctionDeclaration } from "@typespec/emitter-framework/typescript";
6
6
  import { HttpOperation } from "@typespec/http";
7
7
  import * as cl from "@typespec/http-client";
@@ -30,10 +30,12 @@ import { OperationHandler } from "../types.js";
30
30
 
31
31
  export const PaginatedOperationHandler: OperationHandler = {
32
32
  canHandle(httpOperation: HttpOperation): boolean {
33
+ const { $ } = useTsp();
33
34
  const pagingMetadata = $.operation.getPagingMetadata(httpOperation.operation);
34
35
  return pagingMetadata !== undefined;
35
36
  },
36
37
  handle(httpOperation: HttpOperation): Children {
38
+ const { $ } = useTsp();
37
39
  const clientLibrary = cl.useClientLibrary();
38
40
  const client = clientLibrary.getClientForOperation(httpOperation);
39
41
 
@@ -1,7 +1,7 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { $ } from "@typespec/compiler/experimental/typekit";
4
- import { TransformNamePolicyContext } from "@typespec/emitter-framework";
3
+ import { Program } from "@typespec/compiler";
4
+ import { Output as EFOutput, TransformNamePolicyContext } from "@typespec/emitter-framework";
5
5
  import { ClientLibrary } from "@typespec/http-client/components";
6
6
  import { EncodingProvider } from "./encoding-provider.jsx";
7
7
  import { httpRuntimeTemplateLib } from "./external-packages/ts-http-runtime.js";
@@ -10,18 +10,23 @@ import { createTransformNamePolicy } from "./transforms/transform-name-policy.js
10
10
 
11
11
  export interface OutputProps {
12
12
  children?: ay.Children;
13
+ program: Program;
13
14
  }
14
15
 
15
16
  export function Output(props: OutputProps) {
16
17
  const tsNamePolicy = ts.createTSNamePolicy();
17
18
  const defaultTransformNamePolicy = createTransformNamePolicy();
18
19
  return (
19
- <ay.Output namePolicy={tsNamePolicy} externals={[uriTemplateLib, httpRuntimeTemplateLib]}>
20
- <ClientLibrary program={$.program}>
20
+ <EFOutput
21
+ namePolicy={tsNamePolicy}
22
+ externals={[uriTemplateLib, httpRuntimeTemplateLib]}
23
+ program={props.program}
24
+ >
25
+ <ClientLibrary program={props.program}>
21
26
  <TransformNamePolicyContext.Provider value={defaultTransformNamePolicy}>
22
27
  <EncodingProvider>{props.children}</EncodingProvider>
23
28
  </TransformNamePolicyContext.Provider>
24
29
  </ClientLibrary>
25
- </ay.Output>
30
+ </EFOutput>
26
31
  );
27
32
  }
@@ -1,6 +1,7 @@
1
1
  import * as ts from "@alloy-js/typescript";
2
2
  import { Type } from "@typespec/compiler";
3
- import { $ } from "@typespec/compiler/experimental/typekit";
3
+ import type { Typekit } from "@typespec/compiler/experimental/typekit";
4
+ import { useTsp } from "@typespec/emitter-framework";
4
5
  import {
5
6
  DateDeserializer,
6
7
  DateRfc3339Serializer,
@@ -20,6 +21,7 @@ export interface ModelSerializersProps {
20
21
  }
21
22
 
22
23
  export function ModelSerializers(props: ModelSerializersProps) {
24
+ const { $ } = useTsp();
23
25
  const clientLibrary = useClientLibrary();
24
26
  const dataTypes = clientLibrary.dataTypes;
25
27
  const flatClients = clientLibrary.topLevel.flatMap((c) => flattenClients(c));
@@ -44,7 +46,7 @@ export function ModelSerializers(props: ModelSerializersProps) {
44
46
  .filter((m) => m.kind === "Model" || m.kind === "Union")
45
47
  .map((type) => {
46
48
  let bytesDefaultEncoding: "base64" | "none" = "base64";
47
- if (isOrExtendsFile(type)) {
49
+ if (isOrExtendsFile($, type)) {
48
50
  bytesDefaultEncoding = "none";
49
51
  }
50
52
 
@@ -59,7 +61,7 @@ export function ModelSerializers(props: ModelSerializersProps) {
59
61
  );
60
62
  }
61
63
 
62
- function isOrExtendsFile(type: Type): boolean {
64
+ function isOrExtendsFile($: Typekit, type: Type): boolean {
63
65
  if (!$.model.is(type)) {
64
66
  return false;
65
67
  }
@@ -68,5 +70,5 @@ function isOrExtendsFile(type: Type): boolean {
68
70
  return true;
69
71
  }
70
72
 
71
- return type.baseModel ? isOrExtendsFile(type.baseModel) : false;
73
+ return type.baseModel ? isOrExtendsFile($, type.baseModel) : false;
72
74
  }
@@ -1,6 +1,6 @@
1
1
  import { Children, Refkey } from "@alloy-js/core";
2
2
  import { EncodeData, ModelProperty, Scalar } from "@typespec/compiler";
3
- import { $ } from "@typespec/compiler/experimental/typekit";
3
+ import { useTsp } from "@typespec/emitter-framework";
4
4
  import { reportDiagnostic } from "../../lib.js";
5
5
  import { unpackProperty } from "../utils/unpack-model-property.js";
6
6
  import { getScalarTransformer } from "./scalar-transform.jsx";
@@ -12,6 +12,7 @@ export interface ScalarDataTransformProps {
12
12
  }
13
13
 
14
14
  export function ScalarDataTransform(props: ScalarDataTransformProps) {
15
+ const { $ } = useTsp();
15
16
  let scalar: Scalar;
16
17
  let encoding: EncodeData | undefined;
17
18
  if ($.modelProperty.is(props.type)) {
@@ -3,7 +3,7 @@ import * as ts from "@alloy-js/typescript";
3
3
  import * as ef from "@typespec/emitter-framework/typescript";
4
4
 
5
5
  import { Model } from "@typespec/compiler";
6
- import { $ } from "@typespec/compiler/experimental/typekit";
6
+ import { useTsp } from "@typespec/emitter-framework";
7
7
  import { JsonTransform } from "./json-transform.jsx";
8
8
 
9
9
  export interface JsonArrayTransformProps {
@@ -13,6 +13,7 @@ export interface JsonArrayTransformProps {
13
13
  }
14
14
 
15
15
  export function JsonArrayTransform(props: JsonArrayTransformProps) {
16
+ const { $ } = useTsp();
16
17
  if (!$.array.is(props.type)) {
17
18
  return null;
18
19
  }
@@ -47,6 +48,7 @@ export interface JsonArrayTransformDeclarationProps {
47
48
  }
48
49
 
49
50
  export function JsonArrayTransformDeclaration(props: JsonArrayTransformDeclarationProps) {
51
+ const { $ } = useTsp();
50
52
  if (!$.array.is(props.type)) {
51
53
  return null;
52
54
  }
@@ -1,7 +1,7 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
3
  import { Model } from "@typespec/compiler";
4
- import { $ } from "@typespec/compiler/experimental/typekit";
4
+ import { useTsp } from "@typespec/emitter-framework";
5
5
  import { getJsonRecordTransformRefkey } from "./json-record-transform.jsx";
6
6
 
7
7
  export interface JsonAdditionalPropertiesTransformProps {
@@ -11,6 +11,7 @@ export interface JsonAdditionalPropertiesTransformProps {
11
11
  }
12
12
 
13
13
  export function JsonAdditionalPropertiesTransform(props: JsonAdditionalPropertiesTransformProps) {
14
+ const { $ } = useTsp();
14
15
  const additionalProperties = $.model.getAdditionalPropertiesRecord(props.type);
15
16
 
16
17
  if (!additionalProperties) {
@@ -1,7 +1,7 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
3
  import { ModelProperty } from "@typespec/compiler";
4
- import { $ } from "@typespec/compiler/experimental/typekit";
4
+ import { useTsp } from "@typespec/emitter-framework";
5
5
  import { unpackProperty } from "../../utils/unpack-model-property.js";
6
6
  import { ScalarDataTransform } from "../data-transform.jsx";
7
7
  import { useTransformNamePolicy } from "../transform-name-policy.js";
@@ -14,6 +14,7 @@ export interface JsonModelPropertyTransformProps {
14
14
  }
15
15
 
16
16
  export function JsonModelPropertyTransform(props: JsonModelPropertyTransformProps) {
17
+ const { $ } = useTsp();
17
18
  const transformNamer = useTransformNamePolicy();
18
19
  const propertyValueType = unpackProperty(props.type);
19
20
 
@@ -2,7 +2,7 @@ import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
3
 
4
4
  import { Model } from "@typespec/compiler";
5
- import { $ } from "@typespec/compiler/experimental/typekit";
5
+ import { useTsp } from "@typespec/emitter-framework";
6
6
  import { JsonAdditionalPropertiesTransform } from "./json-model-additional-properties-transform.jsx";
7
7
  import { JsonModelPropertyTransform } from "./json-model-property-transform.jsx";
8
8
  import { JsonRecordTransformDeclaration } from "./json-record-transform.jsx";
@@ -18,6 +18,7 @@ export interface JsonModelTransformProps {
18
18
  }
19
19
 
20
20
  export function JsonModelTransform(props: JsonModelTransformProps) {
21
+ const { $ } = useTsp();
21
22
  // Need to skip never properties
22
23
  const properties = Array.from(
23
24
  $.model.getProperties(props.type, { includeExtended: true }).values(),
@@ -69,6 +70,7 @@ export interface JsonModelTransformDeclarationProps {
69
70
  export function JsonModelTransformDeclaration(
70
71
  props: JsonModelTransformDeclarationProps,
71
72
  ): ay.Children {
73
+ const { $ } = useTsp();
72
74
  const namePolicy = ts.useTSNamePolicy();
73
75
  const transformName = namePolicy.getName(
74
76
  `json_${props.type.name}_to_${props.target}_transform`,
@@ -2,7 +2,7 @@ import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
3
 
4
4
  import { Model } from "@typespec/compiler";
5
- import { $ } from "@typespec/compiler/experimental/typekit";
5
+ import { useTsp } from "@typespec/emitter-framework";
6
6
  import { JsonTransform } from "./json-transform.jsx";
7
7
 
8
8
  export interface JsonRecordTransformProps {
@@ -12,6 +12,7 @@ export interface JsonRecordTransformProps {
12
12
  }
13
13
 
14
14
  export function JsonRecordTransform(props: JsonRecordTransformProps) {
15
+ const { $ } = useTsp();
15
16
  if (!$.record.is(props.type)) {
16
17
  return null;
17
18
  }
@@ -48,6 +49,7 @@ export interface JsonRecordTransformDeclarationProps {
48
49
  }
49
50
 
50
51
  export function JsonRecordTransformDeclaration(props: JsonRecordTransformDeclarationProps) {
52
+ const { $ } = useTsp();
51
53
  if (!$.record.is(props.type)) {
52
54
  return null;
53
55
  }
@@ -1,7 +1,7 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
3
  import { Discriminator, Model, Union } from "@typespec/compiler";
4
- import { $ } from "@typespec/compiler/experimental/typekit";
4
+ import { useTsp } from "@typespec/emitter-framework";
5
5
  import { JsonTransform } from "./json-transform.jsx";
6
6
 
7
7
  export interface JsonTransformDiscriminatorProps {
@@ -12,6 +12,7 @@ export interface JsonTransformDiscriminatorProps {
12
12
  }
13
13
 
14
14
  export function JsonTransformDiscriminator(props: JsonTransformDiscriminatorProps) {
15
+ const { $ } = useTsp();
15
16
  const discriminatedUnion = $.model.is(props.type)
16
17
  ? $.model.getDiscriminatedUnion(props.type)
17
18
  : $.union.getDiscriminatedUnion(props.type);
@@ -62,6 +63,7 @@ export interface JsonTransformDiscriminatorDeclarationProps {
62
63
  export function JsonTransformDiscriminatorDeclaration(
63
64
  props: JsonTransformDiscriminatorDeclarationProps,
64
65
  ) {
66
+ const { $ } = useTsp();
65
67
  const discriminator = $.type.getDiscriminator(props.type);
66
68
  if (!discriminator) {
67
69
  return null;
@@ -1,6 +1,6 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import { Type } from "@typespec/compiler";
3
- import { $ } from "@typespec/compiler/experimental/typekit";
3
+ import { useTsp } from "@typespec/emitter-framework";
4
4
  import { ScalarDataTransform } from "../data-transform.jsx";
5
5
  import {
6
6
  getJsonArrayTransformRefkey,
@@ -31,6 +31,7 @@ export interface JsonTransformProps {
31
31
  }
32
32
 
33
33
  export function JsonTransform(props: JsonTransformProps) {
34
+ const { $ } = useTsp();
34
35
  const type = $.httpPart.unpack(props.type) ?? props.type;
35
36
  const declaredTransform = getTransformReference(type, props.target);
36
37
 
@@ -71,6 +72,7 @@ export interface JsonTransformDeclarationProps {
71
72
  }
72
73
 
73
74
  export function JsonTransformDeclaration(props: JsonTransformDeclarationProps) {
75
+ const { $ } = useTsp();
74
76
  if (!$.model.is(props.type) && !$.union.is(props.type)) {
75
77
  return null;
76
78
  }
@@ -96,6 +98,7 @@ function getTransformReference(
96
98
  type: Type,
97
99
  target: "transport" | "application",
98
100
  ): ay.Refkey | undefined {
101
+ const { $ } = useTsp();
99
102
  if (type.kind === "Model" && Boolean(type.name)) {
100
103
  if ($.array.is(type)) {
101
104
  return getJsonArrayTransformRefkey(type, target);
@@ -1,7 +1,7 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
3
  import { Union } from "@typespec/compiler";
4
- import { $ } from "@typespec/compiler/experimental/typekit";
4
+ import { useTsp } from "@typespec/emitter-framework";
5
5
  import {
6
6
  getJsonTransformDiscriminatorRefkey,
7
7
  JsonTransformDiscriminatorDeclaration,
@@ -15,6 +15,7 @@ export interface JsonUnionTransformProps {
15
15
  }
16
16
 
17
17
  export function JsonUnionTransform(props: JsonUnionTransformProps) {
18
+ const { $ } = useTsp();
18
19
  const discriminator = $.type.getDiscriminator(props.type);
19
20
  if (discriminator) {
20
21
  // return <JsonTransformDiscriminator {...props} discriminator={discriminator}/>;
@@ -1,8 +1,8 @@
1
1
  import { Type } from "@typespec/compiler";
2
- import { $ } from "@typespec/compiler/experimental/typekit";
2
+ import type { Typekit } from "@typespec/compiler/experimental/typekit";
3
3
  import { reportDiagnostic } from "../../../../lib.js";
4
4
 
5
- export function getJsonTransportName(type: Type) {
5
+ export function getJsonTransportName($: Typekit, type: Type) {
6
6
  if (!("name" in type)) {
7
7
  reportDiagnostic($.program, { code: "no-name-type", target: type });
8
8
  return "";
@@ -1,6 +1,5 @@
1
1
  import * as ay from "@alloy-js/core";
2
- import { $ } from "@typespec/compiler/experimental/typekit";
3
- import { useTransformNamePolicy } from "@typespec/emitter-framework";
2
+ import { useTransformNamePolicy, useTsp } from "@typespec/emitter-framework";
4
3
  import { HttpOperationMultipartBody } from "@typespec/http";
5
4
  import { reportDiagnostic } from "../../../lib.js";
6
5
  import { HttpPartTransform } from "./part-transform.jsx";
@@ -10,6 +9,7 @@ export interface MultipartTransformProps {
10
9
  }
11
10
 
12
11
  export function MultipartTransform(props: MultipartTransformProps) {
12
+ const { $ } = useTsp();
13
13
  const transportNamer = useTransformNamePolicy();
14
14
  const httpParts = props.body.parts;
15
15
 
@@ -1,6 +1,6 @@
1
1
  import * as ay from "@alloy-js/core";
2
2
  import * as ts from "@alloy-js/typescript";
3
- import { $ } from "@typespec/compiler/experimental/typekit";
3
+ import { useTsp } from "@typespec/emitter-framework";
4
4
  import { HttpOperationPart } from "@typespec/http";
5
5
  import { reportDiagnostic } from "../../../lib.js";
6
6
  import { JsonTransform } from "../json/json-transform.jsx";
@@ -11,6 +11,7 @@ export interface SimplePartTransformProps {
11
11
  }
12
12
 
13
13
  export function SimplePartTransform(props: SimplePartTransformProps) {
14
+ const { $ } = useTsp();
14
15
  const namePolicy = ts.useTSNamePolicy();
15
16
  const applicationName = namePolicy.getName(props.part.name!, "variable");
16
17
  const partName = ts.ValueExpression({ jsValue: props.part.name });
@@ -1,7 +1,6 @@
1
1
  import * as ts from "@alloy-js/typescript";
2
2
  import { Type } from "@typespec/compiler";
3
- import { $ } from "@typespec/compiler/experimental/typekit";
4
- import { HasName, TransformNamePolicyContext } from "@typespec/emitter-framework";
3
+ import { HasName, TransformNamePolicyContext, useTsp } from "@typespec/emitter-framework";
5
4
  import { HttpOperation } from "@typespec/http";
6
5
  import { reportDiagnostic } from "../../lib.js";
7
6
  import { ContentTypeEncodingProvider } from "./content-type-encoding-provider.jsx";
@@ -45,6 +44,7 @@ export function OperationTransformExpression(props: OperationTransformToTranspor
45
44
  }
46
45
 
47
46
  function payloadApplicationNameGetter(type: HasName<Type>) {
47
+ const { $ } = useTsp();
48
48
  if (typeof type.name !== "string") {
49
49
  reportDiagnostic($.program, { code: "symbol-name-not-supported", target: type });
50
50
  return "";