@azure-tools/typespec-ts 0.48.1 → 0.49.0-alpha.20260203.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/src/index.d.ts.map +1 -1
  3. package/dist/src/index.js +2 -1
  4. package/dist/src/index.js.map +1 -1
  5. package/dist/src/modular/buildClientContext.d.ts.map +1 -1
  6. package/dist/src/modular/buildClientContext.js +6 -25
  7. package/dist/src/modular/buildClientContext.js.map +1 -1
  8. package/dist/src/modular/buildOperations.d.ts.map +1 -1
  9. package/dist/src/modular/buildOperations.js +1 -1
  10. package/dist/src/modular/buildOperations.js.map +1 -1
  11. package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
  12. package/dist/src/modular/buildProjectFiles.js +13 -10
  13. package/dist/src/modular/buildProjectFiles.js.map +1 -1
  14. package/dist/src/modular/buildRestorePoller.d.ts.map +1 -1
  15. package/dist/src/modular/buildRestorePoller.js +9 -2
  16. package/dist/src/modular/buildRestorePoller.js.map +1 -1
  17. package/dist/src/modular/emitModels.d.ts.map +1 -1
  18. package/dist/src/modular/emitModels.js +18 -4
  19. package/dist/src/modular/emitModels.js.map +1 -1
  20. package/dist/src/modular/emitSamples.d.ts.map +1 -1
  21. package/dist/src/modular/emitSamples.js +19 -1
  22. package/dist/src/modular/emitSamples.js.map +1 -1
  23. package/dist/src/modular/helpers/clientHelpers.d.ts +1 -0
  24. package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
  25. package/dist/src/modular/helpers/clientHelpers.js +28 -8
  26. package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
  27. package/dist/src/modular/helpers/operationHelpers.d.ts +2 -2
  28. package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
  29. package/dist/src/modular/helpers/operationHelpers.js +53 -9
  30. package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
  31. package/dist/src/modular/helpers/typeHelpers.js +1 -1
  32. package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
  33. package/dist/src/modular/serialization/buildDeserializerFunction.js +5 -1
  34. package/dist/src/modular/serialization/buildDeserializerFunction.js.map +1 -1
  35. package/dist/src/modular/serialization/buildSerializerFunction.js +5 -1
  36. package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
  37. package/dist/src/modular/serialization/serializeUtils.d.ts.map +1 -1
  38. package/dist/src/modular/serialization/serializeUtils.js +1 -0
  39. package/dist/src/modular/serialization/serializeUtils.js.map +1 -1
  40. package/dist/src/modular/type-expressions/get-type-expression.js +1 -1
  41. package/dist/src/modular/type-expressions/get-type-expression.js.map +1 -1
  42. package/dist/src/transform/transform.d.ts.map +1 -1
  43. package/dist/src/transform/transform.js +10 -10
  44. package/dist/src/transform/transform.js.map +1 -1
  45. package/dist/src/transform/transformPaths.js +1 -1
  46. package/dist/src/transform/transformPaths.js.map +1 -1
  47. package/dist/src/transform/transformSchemas.d.ts.map +1 -1
  48. package/dist/src/transform/transformSchemas.js +4 -4
  49. package/dist/src/transform/transformSchemas.js.map +1 -1
  50. package/dist/src/transform/transfromRLCOptions.d.ts +1 -1
  51. package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
  52. package/dist/src/transform/transfromRLCOptions.js +25 -24
  53. package/dist/src/transform/transfromRLCOptions.js.map +1 -1
  54. package/dist/src/utils/clientUtils.d.ts +1 -1
  55. package/dist/src/utils/clientUtils.d.ts.map +1 -1
  56. package/dist/src/utils/clientUtils.js +47 -15
  57. package/dist/src/utils/clientUtils.js.map +1 -1
  58. package/dist/src/utils/crossLanguageDef.d.ts.map +1 -1
  59. package/dist/src/utils/crossLanguageDef.js +9 -3
  60. package/dist/src/utils/crossLanguageDef.js.map +1 -1
  61. package/dist/src/utils/interfaces.d.ts +2 -1
  62. package/dist/src/utils/interfaces.d.ts.map +1 -1
  63. package/dist/src/utils/modelUtils.d.ts +1 -1
  64. package/dist/src/utils/modelUtils.d.ts.map +1 -1
  65. package/dist/src/utils/modelUtils.js +14 -9
  66. package/dist/src/utils/modelUtils.js.map +1 -1
  67. package/dist/src/utils/operationUtil.d.ts +1 -1
  68. package/dist/src/utils/operationUtil.d.ts.map +1 -1
  69. package/dist/src/utils/operationUtil.js +7 -4
  70. package/dist/src/utils/operationUtil.js.map +1 -1
  71. package/dist/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +7 -7
  73. package/src/index.ts +2 -0
  74. package/src/modular/buildClientContext.ts +6 -26
  75. package/src/modular/buildOperations.ts +0 -1
  76. package/src/modular/buildProjectFiles.ts +19 -16
  77. package/src/modular/buildRestorePoller.ts +9 -2
  78. package/src/modular/emitModels.ts +16 -3
  79. package/src/modular/emitSamples.ts +29 -1
  80. package/src/modular/helpers/clientHelpers.ts +33 -11
  81. package/src/modular/helpers/operationHelpers.ts +60 -16
  82. package/src/modular/helpers/typeHelpers.ts +1 -1
  83. package/src/modular/serialization/buildDeserializerFunction.ts +5 -1
  84. package/src/modular/serialization/buildSerializerFunction.ts +5 -1
  85. package/src/modular/serialization/serializeUtils.ts +1 -0
  86. package/src/modular/type-expressions/get-type-expression.ts +1 -1
  87. package/src/transform/transform.ts +5 -2
  88. package/src/transform/transformPaths.ts +1 -1
  89. package/src/transform/transformSchemas.ts +4 -1
  90. package/src/transform/transfromRLCOptions.ts +45 -24
  91. package/src/utils/clientUtils.ts +55 -14
  92. package/src/utils/crossLanguageDef.ts +8 -0
  93. package/src/utils/interfaces.ts +2 -1
  94. package/src/utils/modelUtils.ts +20 -6
  95. package/src/utils/operationUtil.ts +11 -3
  96. package/static/static-helpers/pagingHelpers.ts +32 -6
  97. package/static/static-helpers/pollingHelpers.ts +27 -2
@@ -89,7 +89,10 @@ export function transformSchemas(client: SdkClient, dpgContext: SdkContext) {
89
89
  }
90
90
  }
91
91
  function transformHostParameters() {
92
- const serviceNs = getDefaultService(program)?.type;
92
+ const serviceNs = getDefaultService(
93
+ program,
94
+ dpgContext.rlcOptions?.isModularLibrary
95
+ )?.type;
93
96
  if (serviceNs) {
94
97
  const host = getServers(program, serviceNs);
95
98
  if (host && host?.[0] && host?.[0]?.parameters) {
@@ -33,10 +33,7 @@ export function transformRLCOptions(
33
33
  emitterOptions,
34
34
  dpgContext.generationPathDetail?.rootDir ?? ""
35
35
  );
36
- if (emitterOptions["is-modular-library"] !== false) {
37
- options.isModularLibrary = true;
38
- }
39
- const batch = getRLCClients(dpgContext);
36
+ const batch = getRLCClients(dpgContext, options.isModularLibrary);
40
37
  options.batch = batch;
41
38
  return options;
42
39
  }
@@ -46,20 +43,31 @@ function extractRLCOptions(
46
43
  generationRootDir: string
47
44
  ): RLCOptions {
48
45
  const program = dpgContext.program;
46
+ // Compute isModularLibrary early - defaults to true unless explicitly set to false
47
+ const isModularLibrary = emitterOptions["is-modular-library"] !== false;
49
48
  const includeShortcuts = getIncludeShortcuts(emitterOptions);
50
- const packageDetails = getPackageDetails(program, emitterOptions);
49
+ const packageDetails = getPackageDetails(
50
+ program,
51
+ emitterOptions,
52
+ isModularLibrary
53
+ );
51
54
  const flavor = getFlavor(emitterOptions, packageDetails);
52
55
  const moduleKind = getModuleKind(emitterOptions);
53
- const serviceInfo = getServiceInfo(program);
56
+ const serviceInfo = getServiceInfo(program, isModularLibrary);
54
57
  const azureSdkForJs = getAzureSdkForJs(emitterOptions, flavor);
55
58
  const generateMetadata = getGenerateMetadata(emitterOptions);
56
59
  const generateTest = getGenerateTest(emitterOptions, flavor);
57
60
  const generateSample = getGenerateSample(dpgContext, emitterOptions);
58
- const credentialInfo = getCredentialInfo(program, emitterOptions);
61
+ const credentialInfo = getCredentialInfo(
62
+ program,
63
+ emitterOptions,
64
+ isModularLibrary
65
+ );
59
66
  const azureOutputDirectory = getAzureOutputDirectory(generationRootDir);
60
67
  const enableOperationGroup = getEnableOperationGroup(
61
68
  dpgContext,
62
- emitterOptions
69
+ emitterOptions,
70
+ isModularLibrary
63
71
  );
64
72
  const enableModelNamespace = getEnableModelNamespace(
65
73
  dpgContext,
@@ -72,7 +80,6 @@ function extractRLCOptions(
72
80
  const title = emitterOptions.title;
73
81
  const dependencyInfo = emitterOptions["dependency-info"];
74
82
  const productDocLink = emitterOptions["product-doc-link"];
75
- const isModularLibrary = emitterOptions["is-modular-library"];
76
83
  const compatibilityMode = emitterOptions["compatibility-mode"];
77
84
  const compatibilityLro = emitterOptions["compatibility-lro"];
78
85
  const experimentalExtensibleEnums =
@@ -85,6 +92,7 @@ function extractRLCOptions(
85
92
  emitterOptions["compatibility-query-multi-format"];
86
93
  const typespecTitleMap = emitterOptions["typespec-title-map"];
87
94
  const hasSubscriptionId = getSubscriptionId(dpgContext);
95
+ const isMultiService = (dpgContext.allServiceNamespaces?.length ?? 0) > 1;
88
96
 
89
97
  return {
90
98
  ...credentialInfo,
@@ -117,12 +125,13 @@ function extractRLCOptions(
117
125
  compatibilityQueryMultiFormat,
118
126
  typespecTitleMap,
119
127
  ignoreEnumMemberNameNormalize,
120
- hasSubscriptionId
128
+ hasSubscriptionId,
129
+ isMultiService
121
130
  };
122
131
  }
123
132
 
124
- function processAuth(program: Program) {
125
- const serviceNs = getDefaultService(program)?.type;
133
+ function processAuth(program: Program, isModularLibrary: boolean) {
134
+ const serviceNs = getDefaultService(program, isModularLibrary)?.type;
126
135
  if (!serviceNs) {
127
136
  return undefined;
128
137
  }
@@ -190,7 +199,8 @@ function processAuth(program: Program) {
190
199
 
191
200
  function getEnableOperationGroup(
192
201
  dpgContext: SdkContext,
193
- emitterOptions: EmitterOptions
202
+ emitterOptions: EmitterOptions,
203
+ isModularLibrary: boolean
194
204
  ) {
195
205
  if (
196
206
  emitterOptions["enable-operation-group"] === true ||
@@ -199,7 +209,7 @@ function getEnableOperationGroup(
199
209
  return emitterOptions["enable-operation-group"];
200
210
  }
201
211
  // Only detect if existing name conflicts if customers don't set hierarchyClient to true
202
- return detectIfNameConflicts(dpgContext);
212
+ return detectIfNameConflicts(dpgContext, isModularLibrary);
203
213
  }
204
214
 
205
215
  function getEnableModelNamespace(
@@ -231,8 +241,11 @@ function getClearOutputFolder(emitterOptions: EmitterOptions) {
231
241
  return emitterOptions["clear-output-folder"] ? true : false;
232
242
  }
233
243
 
234
- function detectIfNameConflicts(dpgContext: SdkContext) {
235
- const clients = getRLCClients(dpgContext);
244
+ function detectIfNameConflicts(
245
+ dpgContext: SdkContext,
246
+ isModularLibrary: boolean
247
+ ) {
248
+ const clients = getRLCClients(dpgContext, isModularLibrary);
236
249
  for (const client of clients) {
237
250
  // only consider it's conflict when there are conflicts in the same client
238
251
  const nameSet = new Set<string>();
@@ -290,7 +303,8 @@ function getFlavor(
290
303
  }
291
304
  function buildPackageDetails(
292
305
  program: Program,
293
- emitterOptions: EmitterOptions
306
+ emitterOptions: EmitterOptions,
307
+ isModularLibrary: boolean
294
308
  ): PackageDetails {
295
309
  const defaultDetail = {
296
310
  name: "@msinternal/unamedpackage",
@@ -305,7 +319,9 @@ function buildPackageDetails(
305
319
  name:
306
320
  emitterOptions["package-details"]?.name ??
307
321
  normalizeName(
308
- emitterOptions?.title ?? getDefaultService(program)?.title ?? "",
322
+ emitterOptions?.title ??
323
+ getDefaultService(program, isModularLibrary)?.title ??
324
+ "",
309
325
  NameType.Class
310
326
  ),
311
327
  version: emitterOptions["package-details"]?.version ?? "1.0.0-beta.1",
@@ -323,13 +339,17 @@ function buildPackageDetails(
323
339
 
324
340
  function getPackageDetails(
325
341
  program: Program,
326
- emitterOptions: EmitterOptions
342
+ emitterOptions: EmitterOptions,
343
+ isModularLibrary: boolean
327
344
  ): PackageDetails {
328
- return buildPackageDetails(program, emitterOptions);
345
+ return buildPackageDetails(program, emitterOptions, isModularLibrary);
329
346
  }
330
347
 
331
- function getServiceInfo(program: Program): ServiceInfo {
332
- const defaultService = getDefaultService(program);
348
+ function getServiceInfo(
349
+ program: Program,
350
+ isModularLibrary: boolean
351
+ ): ServiceInfo {
352
+ const defaultService = getDefaultService(program, isModularLibrary);
333
353
  return {
334
354
  title: defaultService?.title,
335
355
  description: defaultService && getDoc(program, defaultService.type)
@@ -397,9 +417,10 @@ function getGenerateSample(
397
417
 
398
418
  export function getCredentialInfo(
399
419
  program: Program,
400
- emitterOptions: EmitterOptions
420
+ emitterOptions: EmitterOptions,
421
+ isModularLibrary: boolean = true
401
422
  ) {
402
- const securityInfo = processAuth(program);
423
+ const securityInfo = processAuth(program, isModularLibrary);
403
424
  const addCredentials =
404
425
  emitterOptions["add-credentials"] === false
405
426
  ? false
@@ -18,23 +18,64 @@ import { SdkContext } from "./interfaces.js";
18
18
  import { ModularClientOptions } from "../modular/interfaces.js";
19
19
  import { NameType, normalizeName } from "@azure-tools/rlc-common";
20
20
 
21
- export function getRLCClients(dpgContext: SdkContext): SdkClient[] {
22
- const services = new Set<Namespace>();
23
- listClients(dpgContext).forEach((c) => {
24
- const clientService = c.service;
25
- if (Array.isArray(clientService)) {
26
- clientService.forEach((ns) => services.add(ns));
27
- } else {
28
- services.add(clientService);
21
+ export function getRLCClients(
22
+ dpgContext: SdkContext,
23
+ isModularLibrary?: boolean
24
+ ): SdkClient[] {
25
+ const modular =
26
+ isModularLibrary ?? dpgContext.rlcOptions?.isModularLibrary ?? false;
27
+ const clients = listClients(dpgContext);
28
+ const rawServiceNamespaces =
29
+ dpgContext.allServiceNamespaces ?? listAllServiceNamespaces(dpgContext);
30
+
31
+ // For one client in Modular: Return the client from listClients with multi-service support
32
+ if (modular && clients.length === 1) {
33
+ return clients.map((client) => {
34
+ const services = Array.isArray(client.service)
35
+ ? client.service
36
+ : [client.service];
37
+ return {
38
+ ...client,
39
+ services: services,
40
+ crossLanguageDefinitionId: `${getNamespaceFullName(
41
+ services[0]!
42
+ )}.${client.name}`
43
+ };
44
+ });
45
+ } else {
46
+ // For RLC and multiple clients in Modular:
47
+ // Flatten all services and return one client per service
48
+ const services = new Set<Namespace>();
49
+ clients.forEach((c) => {
50
+ const clientService = c.service;
51
+ if (Array.isArray(clientService)) {
52
+ clientService.forEach((ns) => services.add(ns));
53
+ } else {
54
+ services.add(clientService);
55
+ }
56
+ });
57
+
58
+ if (services.size > 0) {
59
+ return [...services.values()].map((service) => {
60
+ const clientName = service.name + "Client";
61
+ return {
62
+ kind: "SdkClient",
63
+ name: clientName,
64
+ service: service,
65
+ type: service,
66
+ services: [service],
67
+ arm: Boolean(dpgContext.arm),
68
+ crossLanguageDefinitionId: `${getNamespaceFullName(
69
+ service
70
+ )}.${clientName}`,
71
+ subOperationGroups: []
72
+ };
73
+ });
29
74
  }
30
- });
31
- const rawServiceNamespaces = listAllServiceNamespaces(dpgContext);
32
- if (services.size === 0 && rawServiceNamespaces.length > 0) {
33
- // If no clients are found, fall back to raw service namespaces
34
- [...rawServiceNamespaces.values()].forEach((ns) => services.add(ns));
35
75
  }
36
76
 
37
- return [...services.values()].map((service) => {
77
+ // Fallback to raw service namespaces if no clients found
78
+ return rawServiceNamespaces.map((service) => {
38
79
  const clientName = service.name + "Client";
39
80
  return {
40
81
  kind: "SdkClient",
@@ -5,6 +5,7 @@ import { SdkContext } from "./interfaces.js";
5
5
  import { transformModularEmitterOptions } from "../modular/buildModularOptions.js";
6
6
  import { getMethodHierarchiesMap } from "./operationUtil.js";
7
7
  import { NameType, normalizeName } from "@azure-tools/rlc-common";
8
+ import { UsageFlags } from "@azure-tools/typespec-client-generator-core";
8
9
 
9
10
  export function generateCrossLanguageDefinitionFile(dpgContext: SdkContext): {
10
11
  CrossLanguagePackageId: string;
@@ -28,6 +29,13 @@ export function generateCrossLanguageDefinitionFile(dpgContext: SdkContext): {
28
29
  model.crossLanguageDefinitionId;
29
30
  }
30
31
  for (const enm of dpgContext.sdkPackage.enums) {
32
+ // Skip api version enum for multi-service scenarios since each service may have different versions
33
+ if (
34
+ dpgContext.rlcOptions?.isMultiService &&
35
+ enm.usage === UsageFlags.ApiVersionEnum
36
+ ) {
37
+ continue;
38
+ }
31
39
  CrossLanguageDefinitionId[`${packageName}!Known${enm.name}:enum`] =
32
40
  enm.crossLanguageDefinitionId;
33
41
  }
@@ -1,12 +1,13 @@
1
1
  import { RLCOptions, SchemaContext } from "@azure-tools/rlc-common";
2
2
  import { SdkContext as TCGCSdkContext } from "@azure-tools/typespec-client-generator-core";
3
- import { ModelProperty } from "@typespec/compiler";
3
+ import { ModelProperty, Namespace } from "@typespec/compiler";
4
4
  import { KnownMediaType } from "./mediaTypes.js";
5
5
 
6
6
  export interface SdkContext extends TCGCSdkContext {
7
7
  rlcOptions?: RLCOptions;
8
8
  generationPathDetail?: GenerationDirDetail;
9
9
  hasApiVersionInClient?: boolean;
10
+ allServiceNamespaces?: Namespace[];
10
11
  }
11
12
 
12
13
  export interface GenerationDirDetail {
@@ -1187,7 +1187,7 @@ function getSchemaForArrayModel(
1187
1187
  .join(" | ");
1188
1188
  }
1189
1189
  }
1190
- } else if (schema.items.type.includes("|")) {
1190
+ } else if (schema.items?.type?.includes("|")) {
1191
1191
  schema.typeName = `(${schema.items.type})[]`;
1192
1192
  } else {
1193
1193
  schema.typeName = `${schema.items.type}[]`;
@@ -1326,6 +1326,10 @@ function getSchemaForStdScalar(
1326
1326
  type: "number",
1327
1327
  format: "safeint"
1328
1328
  });
1329
+ case "numeric":
1330
+ return applyIntrinsicDecorators(program, type, {
1331
+ type: "number"
1332
+ });
1329
1333
  case "uint8":
1330
1334
  return applyIntrinsicDecorators(program, type, {
1331
1335
  type: "number",
@@ -1657,7 +1661,10 @@ export function predictDefaultValue(
1657
1661
  }
1658
1662
  return specificDefault;
1659
1663
  }
1660
- const serviceNamespace = getDefaultService(program)?.type;
1664
+ const serviceNamespace = getDefaultService(
1665
+ program,
1666
+ dpgContext.rlcOptions?.isModularLibrary
1667
+ )?.type;
1661
1668
  if (!serviceNamespace) {
1662
1669
  return;
1663
1670
  }
@@ -1668,7 +1675,10 @@ export function predictDefaultValue(
1668
1675
  return;
1669
1676
  }
1670
1677
 
1671
- export function getDefaultService(program: Program): Service | undefined {
1678
+ export function getDefaultService(
1679
+ program: Program,
1680
+ isModularLibrary: boolean = true
1681
+ ): Service | undefined {
1672
1682
  const services = listServices(program);
1673
1683
  if (!services || services.length === 0) {
1674
1684
  reportDiagnostic(program, {
@@ -1676,7 +1686,7 @@ export function getDefaultService(program: Program): Service | undefined {
1676
1686
  target: NoTarget
1677
1687
  });
1678
1688
  }
1679
- if (services.length > 1) {
1689
+ if (services.length > 1 && !isModularLibrary) {
1680
1690
  reportDiagnostic(program, {
1681
1691
  code: "more-than-one-service",
1682
1692
  target: NoTarget
@@ -1691,8 +1701,12 @@ export function getDefaultApiVersionString(
1691
1701
  dpgContext: SdkContext
1692
1702
  ): string | undefined {
1693
1703
  const program = dpgContext.program;
1694
- return getDefaultService(program)
1695
- ? getDefaultApiVersion(dpgContext, getDefaultService(program)!.type)?.value
1704
+ const isModularLibrary = dpgContext.rlcOptions?.isModularLibrary;
1705
+ return getDefaultService(program, isModularLibrary)
1706
+ ? getDefaultApiVersion(
1707
+ dpgContext,
1708
+ getDefaultService(program, isModularLibrary)!.type
1709
+ )?.value
1696
1710
  : undefined;
1697
1711
  }
1698
1712
 
@@ -15,6 +15,7 @@ import {
15
15
  } from "@azure-tools/rlc-common";
16
16
  import { getLroMetadata } from "@azure-tools/typespec-azure-core";
17
17
  import {
18
+ getDisablePageable,
18
19
  getHttpOperationWithCache,
19
20
  getWireName,
20
21
  InitializedByFlags,
@@ -424,7 +425,15 @@ export function extractPageDetails(
424
425
  return undefined;
425
426
  }
426
427
 
427
- export function isPagingOperation(program: Program, operation: HttpOperation) {
428
+ export function isPagingOperation(
429
+ dpgContext: SdkContext,
430
+ operation: HttpOperation
431
+ ) {
432
+ const { program } = dpgContext;
433
+ if (getDisablePageable(dpgContext, operation.operation)) {
434
+ return false;
435
+ }
436
+
428
437
  return extractPageDetails(program, operation) !== undefined;
429
438
  }
430
439
 
@@ -471,14 +480,13 @@ function findRootSourceProperty(property: ModelProperty): ModelProperty {
471
480
  }
472
481
 
473
482
  export function hasPagingOperations(client: SdkClient, dpgContext: SdkContext) {
474
- const program = dpgContext.program;
475
483
  for (const op of listOperationsUnderRLCClient(client)) {
476
484
  const route = getHttpOperationWithCache(dpgContext, op);
477
485
  // ignore overload base operation
478
486
  if (route.overloads && route.overloads?.length > 0) {
479
487
  continue;
480
488
  }
481
- if (isPagingOperation(program, route)) {
489
+ if (isPagingOperation(dpgContext, route)) {
482
490
  return true;
483
491
  }
484
492
  }
@@ -91,6 +91,7 @@ export interface BuildPagedAsyncIteratorOptions {
91
91
  itemName?: string;
92
92
  nextLinkName?: string;
93
93
  nextLinkMethod?: "GET" | "POST";
94
+ apiVersion?: string;
94
95
  }
95
96
 
96
97
  /**
@@ -111,14 +112,21 @@ export function buildPagedAsyncIterator<
111
112
  const itemName = options.itemName ?? "value";
112
113
  const nextLinkName = options.nextLinkName ?? "nextLink";
113
114
  const nextLinkMethod = options.nextLinkMethod ?? "GET";
115
+ const apiVersion = options.apiVersion;
114
116
  const pagedResult: PagedResult<TElement, TPage, TPageSettings> = {
115
117
  getPage: async (pageLink?: string) => {
116
- const result =
117
- pageLink === undefined
118
- ? await getInitialResponse()
119
- : nextLinkMethod === "POST"
120
- ? await client.pathUnchecked(pageLink).post()
121
- : await client.pathUnchecked(pageLink).get();
118
+ let result;
119
+ if (pageLink === undefined) {
120
+ result = await getInitialResponse();
121
+ } else {
122
+ const resolvedPageLink = apiVersion
123
+ ? addApiVersionToUrl(pageLink, apiVersion)
124
+ : pageLink;
125
+ result =
126
+ nextLinkMethod === "POST"
127
+ ? await client.pathUnchecked(resolvedPageLink).post()
128
+ : await client.pathUnchecked(resolvedPageLink).get();
129
+ }
122
130
  checkPagingRequest(result, expectedStatuses);
123
131
  const results = await processResponseBody(result as TResponse);
124
132
  const nextLink = getNextLink(results, nextLinkName);
@@ -273,3 +281,21 @@ function checkPagingRequest(
273
281
  );
274
282
  }
275
283
  }
284
+
285
+ /**
286
+ * Adds the api-version query parameter on a URL if it's not present.
287
+ * @param url - the URL to modify
288
+ * @param apiVersion - the API version to set
289
+ * @returns - the URL with the api-version query parameter set
290
+ */
291
+ function addApiVersionToUrl(url: string, apiVersion: string): string {
292
+ // The base URL is only used for parsing and won't appear in the returned URL
293
+ const urlObj = new URL(url, "https://microsoft.com");
294
+ if (!urlObj.searchParams.get("api-version")) {
295
+ // Append one if there is no apiVersion
296
+ return `${url}${
297
+ Array.from(urlObj.searchParams.keys()).length > 0 ? "&" : "?"
298
+ }api-version=${apiVersion}`;
299
+ }
300
+ return url;
301
+ }
@@ -38,6 +38,10 @@ export interface GetLongRunningPollerOptions<TResponse> {
38
38
  * The function to get the initial response
39
39
  */
40
40
  getInitialResponse?: () => PromiseLike<TResponse>;
41
+ /**
42
+ * The api-version of the LRO
43
+ */
44
+ apiVersion?: string;
41
45
  }
42
46
  export function getLongRunningPoller<
43
47
  TResponse extends PathUncheckedResponse,
@@ -48,7 +52,7 @@ export function getLongRunningPoller<
48
52
  expectedStatuses: string[],
49
53
  options: GetLongRunningPollerOptions<TResponse>
50
54
  ): PollerLike<OperationState<TResult>, TResult> {
51
- const { restoreFrom, getInitialResponse } = options;
55
+ const { restoreFrom, getInitialResponse, apiVersion } = options;
52
56
  if (!restoreFrom && !getInitialResponse) {
53
57
  throw new Error(
54
58
  "Either restoreFrom or getInitialResponse must be specified"
@@ -91,7 +95,10 @@ export function getLongRunningPoller<
91
95
  }
92
96
  let response;
93
97
  try {
94
- response = await client.pathUnchecked(path).get({ abortSignal });
98
+ const pollingPath = apiVersion
99
+ ? addApiVersionToUrl(path, apiVersion)
100
+ : path;
101
+ response = await client.pathUnchecked(pollingPath).get({ abortSignal });
95
102
  } finally {
96
103
  options.abortSignal?.removeEventListener("abort", abortListener);
97
104
  pollOptions?.abortSignal?.removeEventListener("abort", abortListener);
@@ -132,3 +139,21 @@ function getLroResponse<TResponse extends PathUncheckedResponse>(
132
139
  }
133
140
  };
134
141
  }
142
+
143
+ /**
144
+ * Adds the api-version query parameter on a URL if it's not present.
145
+ * @param url - the URL to modify
146
+ * @param apiVersion - the API version to set
147
+ * @returns - the URL with the api-version query parameter set
148
+ */
149
+ function addApiVersionToUrl(url: string, apiVersion: string): string {
150
+ // The base URL is only used for parsing and won't appear in the returned URL
151
+ const urlObj = new URL(url, "https://microsoft.com");
152
+ if (!urlObj.searchParams.get("api-version")) {
153
+ // Append one if there is no apiVersion
154
+ return `${url}${
155
+ Array.from(urlObj.searchParams.keys()).length > 0 ? "&" : "?"
156
+ }api-version=${apiVersion}`;
157
+ }
158
+ return url;
159
+ }