@azure-tools/typespec-ts 0.40.2 → 0.41.0-alpha.20250606.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-tools/typespec-ts",
3
- "version": "0.40.2",
3
+ "version": "0.41.0-alpha.20250606.1",
4
4
  "description": "An experimental TypeSpec emitter for TypeScript RLC",
5
5
  "main": "dist/src/index.js",
6
6
  "type": "module",
@@ -18,13 +18,13 @@
18
18
  "license": "MIT",
19
19
  "devDependencies": {
20
20
  "@azure-rest/core-client": "^2.3.1",
21
- "@typespec/http-specs": "0.1.0-alpha.22-dev.0",
22
- "@typespec/spector": "0.1.0-alpha.14-dev.1",
23
- "@typespec/spec-api": "0.1.0-alpha.7-dev.0",
24
- "@azure-tools/azure-http-specs": "^0.1.0-alpha.17-dev.0",
21
+ "@typespec/http-specs": "0.1.0-alpha.22",
22
+ "@typespec/spector": "0.1.0-alpha.14",
23
+ "@typespec/spec-api": "0.1.0-alpha.6",
24
+ "@azure-tools/azure-http-specs": "^0.1.0-alpha.18",
25
25
  "@azure-tools/typespec-autorest": "^0.56.0",
26
26
  "@azure-tools/typespec-azure-core": "^0.56.0",
27
- "@azure-tools/typespec-azure-resource-manager": "^0.56.1",
27
+ "@azure-tools/typespec-azure-resource-manager": "^0.56.2",
28
28
  "@azure-tools/typespec-client-generator-core": "^0.56.2",
29
29
  "@azure/abort-controller": "^2.1.2",
30
30
  "@azure/core-auth": "^1.6.0",
@@ -76,7 +76,7 @@
76
76
  "@typespec/xml": "^0.70.0"
77
77
  },
78
78
  "dependencies": {
79
- "@azure-tools/rlc-common": "^0.40.2",
79
+ "@azure-tools/rlc-common": "0.41.0-alpha.20250606.1",
80
80
  "fs-extra": "^11.1.0",
81
81
  "lodash": "^4.17.21",
82
82
  "prettier": "^3.3.3",
package/src/index.ts CHANGED
@@ -295,6 +295,10 @@ export async function $onEmit(context: EmitContext) {
295
295
  });
296
296
  console.time("onEmit: emit source files");
297
297
  const clientMap = getClientHierarchyMap(dpgContext);
298
+ if (clientMap.length === 0) {
299
+ // If no clients, we still need to build the root index file
300
+ buildRootIndex(dpgContext, modularEmitterOptions, rootIndexFile);
301
+ }
298
302
  for (const subClient of clientMap) {
299
303
  await renameClientName(subClient[1], modularEmitterOptions);
300
304
  buildApiOptions(dpgContext, subClient, modularEmitterOptions);
@@ -324,9 +328,9 @@ export async function $onEmit(context: EmitContext) {
324
328
  }
325
329
  buildRootIndex(
326
330
  dpgContext,
327
- subClient,
328
331
  modularEmitterOptions,
329
- rootIndexFile
332
+ rootIndexFile,
333
+ subClient
330
334
  );
331
335
  }
332
336
  console.timeEnd("onEmit: emit source files");
@@ -16,10 +16,15 @@ import { useContext } from "../contextManager.js";
16
16
 
17
17
  export function buildRootIndex(
18
18
  context: SdkContext,
19
- clientMap: [string[], SdkClientType<SdkServiceOperation>],
20
19
  emitterOptions: ModularEmitterOptions,
21
- rootIndexFile: SourceFile
20
+ rootIndexFile: SourceFile,
21
+ clientMap?: [string[], SdkClientType<SdkServiceOperation>]
22
22
  ) {
23
+ if (!clientMap) {
24
+ // we still need to export the models if no client is provided
25
+ exportModels(emitterOptions, rootIndexFile);
26
+ return;
27
+ }
23
28
  const project = useContext("outputProject");
24
29
  const [_, client] = clientMap;
25
30
  const srcPath = emitterOptions.modularOptions.sourceRoot;
@@ -50,17 +55,7 @@ export function buildRootIndex(
50
55
  subfolder,
51
56
  true
52
57
  );
53
- const modelsExportsIndex = rootIndexFile
54
- .getExportDeclarations()
55
- ?.find((i) => {
56
- return i.getModuleSpecifierValue()?.startsWith(`./models/`);
57
- });
58
- if (!modelsExportsIndex) {
59
- exportModules(rootIndexFile, project, srcPath, clientName, "models", {
60
- isTopLevel: true,
61
- recursive: true
62
- });
63
- }
58
+ exportModels(emitterOptions, rootIndexFile, clientName);
64
59
  exportModules(rootIndexFile, project, srcPath, clientName, "api", {
65
60
  subfolder,
66
61
  interfaceOnly: true,
@@ -75,6 +70,27 @@ export function buildRootIndex(
75
70
  exportFileContentsType(context, rootIndexFile);
76
71
  }
77
72
 
73
+ function exportModels(
74
+ emitterOptions: ModularEmitterOptions,
75
+ rootIndexFile: SourceFile,
76
+ clientName: string = ""
77
+ ) {
78
+ // export models index file if not exists
79
+ const project = useContext("outputProject");
80
+ const srcPath = emitterOptions.modularOptions.sourceRoot;
81
+ const modelsExportsIndex = rootIndexFile
82
+ .getExportDeclarations()
83
+ ?.find((i) => {
84
+ return i.getModuleSpecifierValue()?.startsWith(`./models/`);
85
+ });
86
+ if (!modelsExportsIndex) {
87
+ exportModules(rootIndexFile, project, srcPath, clientName, "models", {
88
+ isTopLevel: true,
89
+ recursive: true
90
+ });
91
+ }
92
+ }
93
+
78
94
  /**
79
95
  * This is a temporary solution for adding paging exports. Eventually we will have the binder generate the exports automatically.
80
96
  */
@@ -314,26 +314,9 @@ function addSerializationFunctions(
314
314
  type,
315
315
  skipDiscriminatedUnion
316
316
  );
317
- let typeName = undefined;
318
- switch (type.kind) {
319
- case "array":
320
- typeName = "array";
321
- break;
322
- case "dict":
323
- typeName = "record";
324
- break;
325
- default:
326
- break;
327
- }
328
317
 
329
- const serializerRefkey =
330
- type.kind === "array" || type.kind === "dict"
331
- ? refkey(type.valueType, typeName, "serializer")
332
- : refkey(type, "serializer");
333
- const deserailizerRefKey =
334
- type.kind === "array" || type.kind === "dict"
335
- ? refkey(type.valueType, typeName, "deserializer")
336
- : refkey(type, "deserializer");
318
+ const serializerRefkey = refkey(type, "serializer");
319
+ const deserailizerRefKey = refkey(type, "deserializer");
337
320
  if (
338
321
  serializationFunction &&
339
322
  typeof serializationFunction !== "string" &&
@@ -424,7 +424,7 @@ function buildDictTypeDeserializer(
424
424
 
425
425
  const deserializerFunctionName = `${normalizeModelName(context, type, NameType.Operation, false, true)}Deserializer`;
426
426
  if (nameOnly) {
427
- return resolveReference(refkey(type.valueType, "record", "deserializer"));
427
+ return resolveReference(refkey(type, "deserializer"));
428
428
  }
429
429
  const deserializerFunction: FunctionDeclarationStructure = {
430
430
  kind: StructureKind.Function,
@@ -482,7 +482,7 @@ function buildArrayTypeDeserializer(
482
482
  }
483
483
  const deserializerFunctionName = `${normalizeModelName(context, type, NameType.Operation, false, true)}Deserializer`;
484
484
  if (nameOnly) {
485
- return resolveReference(refkey(type.valueType, "array", "deserializer"));
485
+ return resolveReference(refkey(type, "deserializer"));
486
486
  }
487
487
  const serializerFunction: FunctionDeclarationStructure = {
488
488
  kind: StructureKind.Function,
@@ -488,7 +488,7 @@ function buildDictTypeSerializer(
488
488
  }
489
489
  const serializerFunctionName = `${normalizeModelName(context, type, NameType.Operation, false, true)}Serializer`;
490
490
  if (nameOnly) {
491
- return resolveReference(refkey(type.valueType, "record", "serializer"));
491
+ return resolveReference(refkey(type, "serializer"));
492
492
  }
493
493
  const serializerFunction: FunctionDeclarationStructure = {
494
494
  kind: StructureKind.Function,
@@ -546,7 +546,7 @@ function buildArrayTypeSerializer(
546
546
  }
547
547
  const serializerFunctionName = `${normalizeModelName(context, type, NameType.Operation, false, true)}Serializer`;
548
548
  if (nameOnly) {
549
- return resolveReference(refkey(type.valueType, "array", "serializer"));
549
+ return resolveReference(refkey(type, "serializer"));
550
550
  }
551
551
  const serializerFunction: FunctionDeclarationStructure = {
552
552
  kind: StructureKind.Function,