@azure-tools/typespec-ts 0.14.0 → 0.15.0-alpha.20230822.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 (141) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/src/index.d.ts +1 -5
  3. package/dist/src/index.d.ts.map +1 -1
  4. package/dist/src/index.js +148 -78
  5. package/dist/src/index.js.map +1 -1
  6. package/dist/src/lib.d.ts.map +1 -1
  7. package/dist/src/lib.js +4 -2
  8. package/dist/src/lib.js.map +1 -1
  9. package/dist/src/modular/buildClassicalClient.d.ts +1 -1
  10. package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
  11. package/dist/src/modular/buildClassicalClient.js +27 -15
  12. package/dist/src/modular/buildClassicalClient.js.map +1 -1
  13. package/dist/src/modular/buildClientContext.d.ts +1 -1
  14. package/dist/src/modular/buildClientContext.d.ts.map +1 -1
  15. package/dist/src/modular/buildClientContext.js +16 -7
  16. package/dist/src/modular/buildClientContext.js.map +1 -1
  17. package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
  18. package/dist/src/modular/buildCodeModel.js +59 -12
  19. package/dist/src/modular/buildCodeModel.js.map +1 -1
  20. package/dist/src/modular/buildOperations.d.ts +2 -1
  21. package/dist/src/modular/buildOperations.d.ts.map +1 -1
  22. package/dist/src/modular/buildOperations.js +25 -29
  23. package/dist/src/modular/buildOperations.js.map +1 -1
  24. package/dist/src/modular/buildProjectFiles.d.ts +2 -2
  25. package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
  26. package/dist/src/modular/buildProjectFiles.js +284 -145
  27. package/dist/src/modular/buildProjectFiles.js.map +1 -1
  28. package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
  29. package/dist/src/modular/buildRootIndex.js +5 -5
  30. package/dist/src/modular/buildRootIndex.js.map +1 -1
  31. package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
  32. package/dist/src/modular/buildSubpathIndex.js +9 -2
  33. package/dist/src/modular/buildSubpathIndex.js.map +1 -1
  34. package/dist/src/modular/emitModels.d.ts +3 -2
  35. package/dist/src/modular/emitModels.d.ts.map +1 -1
  36. package/dist/src/modular/emitModels.js +40 -7
  37. package/dist/src/modular/emitModels.js.map +1 -1
  38. package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
  39. package/dist/src/modular/helpers/clientHelpers.js +5 -3
  40. package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
  41. package/dist/src/modular/helpers/docsHelpers.d.ts +3 -0
  42. package/dist/src/modular/helpers/docsHelpers.d.ts.map +1 -0
  43. package/dist/src/modular/helpers/docsHelpers.js +10 -0
  44. package/dist/src/modular/helpers/docsHelpers.js.map +1 -0
  45. package/dist/src/modular/helpers/operationHelpers.d.ts +11 -4
  46. package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
  47. package/dist/src/modular/helpers/operationHelpers.js +197 -56
  48. package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
  49. package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
  50. package/dist/src/modular/helpers/typeHelpers.js +6 -0
  51. package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
  52. package/dist/src/modular/modularCodeModel.d.ts +2 -0
  53. package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
  54. package/dist/src/transform/transform.d.ts +5 -8
  55. package/dist/src/transform/transform.d.ts.map +1 -1
  56. package/dist/src/transform/transform.js +23 -13
  57. package/dist/src/transform/transform.js.map +1 -1
  58. package/dist/src/transform/transformApiVersionInfo.d.ts +2 -1
  59. package/dist/src/transform/transformApiVersionInfo.d.ts.map +1 -1
  60. package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
  61. package/dist/src/transform/transformHelperFunctionDetails.d.ts +2 -1
  62. package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -1
  63. package/dist/src/transform/transformHelperFunctionDetails.js +4 -10
  64. package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
  65. package/dist/src/transform/transformParameters.d.ts +2 -12
  66. package/dist/src/transform/transformParameters.d.ts.map +1 -1
  67. package/dist/src/transform/transformParameters.js +6 -47
  68. package/dist/src/transform/transformParameters.js.map +1 -1
  69. package/dist/src/transform/transformPaths.d.ts +2 -2
  70. package/dist/src/transform/transformPaths.d.ts.map +1 -1
  71. package/dist/src/transform/transformPaths.js.map +1 -1
  72. package/dist/src/transform/transformResponses.d.ts +2 -2
  73. package/dist/src/transform/transformResponses.d.ts.map +1 -1
  74. package/dist/src/transform/transformResponses.js +5 -1
  75. package/dist/src/transform/transformResponses.js.map +1 -1
  76. package/dist/src/transform/transformSchemas.d.ts +2 -2
  77. package/dist/src/transform/transformSchemas.d.ts.map +1 -1
  78. package/dist/src/transform/transformSchemas.js.map +1 -1
  79. package/dist/src/transform/transformTelemetryInfo.d.ts +4 -0
  80. package/dist/src/transform/transformTelemetryInfo.d.ts.map +1 -0
  81. package/dist/src/transform/transformTelemetryInfo.js +42 -0
  82. package/dist/src/transform/transformTelemetryInfo.js.map +1 -0
  83. package/dist/src/transform/transfromRLCOptions.d.ts +4 -2
  84. package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
  85. package/dist/src/transform/transfromRLCOptions.js +72 -19
  86. package/dist/src/transform/transfromRLCOptions.js.map +1 -1
  87. package/dist/src/utils/clientUtils.d.ts +2 -1
  88. package/dist/src/utils/clientUtils.d.ts.map +1 -1
  89. package/dist/src/utils/clientUtils.js.map +1 -1
  90. package/dist/src/utils/interfaces.d.ts +13 -0
  91. package/dist/src/utils/interfaces.d.ts.map +1 -0
  92. package/dist/src/utils/interfaces.js +2 -0
  93. package/dist/src/utils/interfaces.js.map +1 -0
  94. package/dist/src/utils/modelUtils.d.ts +1 -1
  95. package/dist/src/utils/modelUtils.d.ts.map +1 -1
  96. package/dist/src/utils/modelUtils.js +25 -20
  97. package/dist/src/utils/modelUtils.js.map +1 -1
  98. package/dist/src/utils/operationUtil.d.ts +15 -4
  99. package/dist/src/utils/operationUtil.d.ts.map +1 -1
  100. package/dist/src/utils/operationUtil.js +65 -1
  101. package/dist/src/utils/operationUtil.js.map +1 -1
  102. package/dist/tsconfig.tsbuildinfo +1 -1
  103. package/package.json +28 -18
  104. package/src/index.ts +231 -129
  105. package/src/lib.ts +4 -2
  106. package/src/modular/buildClassicalClient.ts +33 -16
  107. package/src/modular/buildClientContext.ts +18 -8
  108. package/src/modular/buildCodeModel.ts +71 -13
  109. package/src/modular/buildOperations.ts +31 -36
  110. package/src/modular/buildProjectFiles.ts +329 -162
  111. package/src/modular/buildRootIndex.ts +5 -7
  112. package/src/modular/buildSubpathIndex.ts +9 -2
  113. package/src/modular/emitModels.ts +55 -9
  114. package/src/modular/helpers/clientHelpers.ts +5 -3
  115. package/src/modular/helpers/docsHelpers.ts +10 -0
  116. package/src/modular/helpers/operationHelpers.ts +328 -75
  117. package/src/modular/helpers/typeHelpers.ts +6 -0
  118. package/src/modular/modularCodeModel.ts +2 -0
  119. package/src/transform/transform.ts +24 -31
  120. package/src/transform/transformApiVersionInfo.ts +1 -1
  121. package/src/transform/transformHelperFunctionDetails.ts +12 -11
  122. package/src/transform/transformParameters.ts +20 -63
  123. package/src/transform/transformPaths.ts +5 -5
  124. package/src/transform/transformResponses.ts +10 -6
  125. package/src/transform/transformSchemas.ts +2 -2
  126. package/src/transform/transformTelemetryInfo.ts +72 -0
  127. package/src/transform/transfromRLCOptions.ts +100 -23
  128. package/src/utils/clientUtils.ts +2 -4
  129. package/src/utils/interfaces.ts +14 -0
  130. package/src/utils/modelUtils.ts +18 -11
  131. package/src/utils/operationUtil.ts +92 -6
  132. package/dist/src/modular/helpers/fixmeHelpers.d.ts +0 -2
  133. package/dist/src/modular/helpers/fixmeHelpers.d.ts.map +0 -1
  134. package/dist/src/modular/helpers/fixmeHelpers.js +0 -4
  135. package/dist/src/modular/helpers/fixmeHelpers.js.map +0 -1
  136. package/dist/src/modular/helpers/parameterHelpers.d.ts +0 -3
  137. package/dist/src/modular/helpers/parameterHelpers.d.ts.map +0 -1
  138. package/dist/src/modular/helpers/parameterHelpers.js +0 -16
  139. package/dist/src/modular/helpers/parameterHelpers.js.map +0 -1
  140. package/src/modular/helpers/fixmeHelpers.ts +0 -3
  141. package/src/modular/helpers/parameterHelpers.ts +0 -17
@@ -1,14 +1,20 @@
1
1
  import { getType } from "./helpers/typeHelpers.js";
2
2
  import * as path from "path";
3
+ import { getDocsFromDescription } from "./helpers/docsHelpers.js";
4
+ import { buildOperationOptions } from "./buildOperations.js";
3
5
  /**
4
6
  * This function creates the file containing all the models defined in TypeSpec
5
7
  */
6
8
  export function buildModels(codeModel, project, srcPath = "src", subfolder = "") {
7
- var _a, _b, _c, _d, _e, _f;
8
- const modelsFile = project.createSourceFile(path.join(`${srcPath}/src/`, subfolder, `models/models.ts`));
9
+ var _a, _b, _c, _d;
9
10
  // We are generating both models and enums here
10
11
  const coreClientTypes = new Set();
11
12
  const models = codeModel.types.filter((t) => (t.type === "model" || t.type === "enum") && !isAzureCoreError(t));
13
+ // Skip to generate models.ts if there is no any models
14
+ if (models.length === 0) {
15
+ return;
16
+ }
17
+ const modelsFile = project.createSourceFile(path.join(`${srcPath}/`, subfolder, `models/models.ts`));
12
18
  for (const model of codeModel.types) {
13
19
  if (model.type === "combined" && model.nullable) {
14
20
  for (const unionModel of (_a = model.types) !== null && _a !== void 0 ? _a : []) {
@@ -34,17 +40,17 @@ export function buildModels(codeModel, project, srcPath = "src", subfolder = "")
34
40
  name: model.name,
35
41
  isExported: true,
36
42
  docs: [
37
- (_c = model.description) !== null && _c !== void 0 ? _c : "",
43
+ ...getDocsFromDescription(model.description),
38
44
  // If it is a fixed enum we don't need to list the known values in the docs as the
39
45
  // output will be a literal union which is self documenting
40
46
  model.isFixed
41
47
  ? ""
42
48
  : // When we generate an "extensible" enum, the type will be "string" so we list the known values
43
49
  // in the docs for user reference.
44
- ((_d = model.values) !== null && _d !== void 0 ? _d : []).map((v) => `"${v.value}"`).join(", ")
50
+ ((_c = model.values) !== null && _c !== void 0 ? _c : []).map((v) => `"${v.value}"`).join(", ")
45
51
  ],
46
52
  type: model.isFixed
47
- ? ((_e = model.values) !== null && _e !== void 0 ? _e : []).map((v) => `"${v.value}"`).join(" | ")
53
+ ? ((_d = model.values) !== null && _d !== void 0 ? _d : []).map((v) => `"${v.value}"`).join(" | ")
48
54
  : "string"
49
55
  });
50
56
  }
@@ -55,7 +61,7 @@ export function buildModels(codeModel, project, srcPath = "src", subfolder = "")
55
61
  modelsFile.addInterface({
56
62
  name: model.name,
57
63
  isExported: true,
58
- docs: [(_f = model.description) !== null && _f !== void 0 ? _f : ""],
64
+ docs: getDocsFromDescription(model.description),
59
65
  properties: properties.map((p) => {
60
66
  const propertyMetadata = getType(p.type);
61
67
  let propertyTypeName = propertyMetadata.name;
@@ -69,7 +75,7 @@ export function buildModels(codeModel, project, srcPath = "src", subfolder = "")
69
75
  }
70
76
  return {
71
77
  name: `"${p.clientName}"`,
72
- docs: [p.description],
78
+ docs: getDocsFromDescription(p.description),
73
79
  hasQuestionToken: p.optional,
74
80
  isReadonly: p.readonly,
75
81
  type: propertyTypeName
@@ -98,4 +104,31 @@ function isAzureCoreError(t) {
98
104
  ["Error", "InnerError"].includes(t.name) &&
99
105
  t.isCoreErrorType === true);
100
106
  }
107
+ export function buildModelsOptions(client, project, srcPath = "src", subfolder = "") {
108
+ const modelOptionsFile = project.createSourceFile(`${srcPath}/${subfolder}/models/options.ts`, undefined, {
109
+ overwrite: true
110
+ });
111
+ for (const operationGroup of client.operationGroups) {
112
+ operationGroup.operations.forEach((o) => {
113
+ buildOperationOptions(o, modelOptionsFile);
114
+ });
115
+ }
116
+ modelOptionsFile.addImportDeclarations([
117
+ {
118
+ moduleSpecifier: "@azure-rest/core-client",
119
+ namedImports: ["OperationOptions"]
120
+ }
121
+ ]);
122
+ modelOptionsFile.fixMissingImports();
123
+ modelOptionsFile
124
+ .getImportDeclarations()
125
+ .filter((id) => {
126
+ return (id.isModuleSpecifierRelative() &&
127
+ !id.getModuleSpecifierValue().endsWith(".js"));
128
+ })
129
+ .map((id) => {
130
+ id.setModuleSpecifier(id.getModuleSpecifierValue() + ".js");
131
+ return id;
132
+ });
133
+ }
101
134
  //# sourceMappingURL=emitModels.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"emitModels.js","sourceRoot":"","sources":["../../../src/modular/emitModels.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B;;GAEG;AACH,MAAM,UAAU,WAAW,CACzB,SAA2B,EAC3B,OAAgB,EAChB,UAAkB,KAAK,EACvB,YAAoB,EAAE;;IAEtB,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CACzC,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,OAAO,EAAE,SAAS,EAAE,kBAAkB,CAAC,CAC5D,CAAC;IAEF,+CAA+C;IAC/C,MAAM,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IAC1C,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,CACnC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CACzE,CAAC;IAEF,KAAK,MAAM,KAAK,IAAI,SAAS,CAAC,KAAK,EAAE;QACnC,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,KAAK,CAAC,QAAQ,EAAE;YAC/C,KAAK,MAAM,UAAU,IAAI,MAAA,KAAK,CAAC,KAAK,mCAAI,EAAE,EAAE;gBAC1C,IAAI,UAAU,CAAC,IAAI,KAAK,OAAO,EAAE;oBAC/B,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;iBACzB;aACF;SACF;KACF;IAED,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,MAAM,U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CAAC;KACJ;IACD,gBAAgB,CAAC,qBAAqB,CAAC;QACrC;YACE,eAAe,EAAE,yBAAyB;YAC1C,YAAY,EAAE,CAAC,kBAAkB,CAAC;SACnC;KACF,CAAC,CAAC;IAEH,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;IACrC,gBAAgB;SACb,qBAAqB,EAAE;SACvB,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE;QACb,OAAO,CACL,EAAE,CAAC,yBAAyB,EAAE;YAC9B,CAAC,EAAE,CAAC,uBAAuB,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAC9C,CAAC;IACJ,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;QACV,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,uBAAuB,EAAE,GAAG,KAAK,CAAC,CAAC;QAC5D,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"clientHelpers.d.ts","sourceRoot":"","sources":["../../../../src/modular/helpers/clientHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,GACb,YAAY,CAAC,6BAA6B,CAAC,EAAE,CAyB/C"}
1
+ {"version":3,"file":"clientHelpers.d.ts","sourceRoot":"","sources":["../../../../src/modular/helpers/clientHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAIhD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,GACb,YAAY,CAAC,6BAA6B,CAAC,EAAE,CA0B/C"}
@@ -1,6 +1,8 @@
1
- import { getParameterType } from "./parameterHelpers.js";
1
+ import { getType } from "./typeHelpers.js";
2
+ import { getClientName } from "./namingHelpers.js";
2
3
  export function getClientParameters(client) {
3
- const { name, parameters } = client;
4
+ const { parameters } = client;
5
+ const name = getClientName(client);
4
6
  const optionsParam = {
5
7
  name: "options",
6
8
  type: `${name}ClientOptions`,
@@ -13,7 +15,7 @@ export function getClientParameters(client) {
13
15
  .map((p) => {
14
16
  return {
15
17
  name: p.clientName,
16
- type: getParameterType(p)
18
+ type: getType(p.type).name
17
19
  };
18
20
  }),
19
21
  optionsParam
@@ -1 +1 @@
1
- {"version":3,"file":"clientHelpers.js","sourceRoot":"","sources":["../../../../src/modular/helpers/clientHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,UAAU,mBAAmB,CACjC,MAAc;IAEd,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,YAAY,GAAG;QACnB,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,GAAG,IAAI,eAAe;QAC5B,WAAW,EAAE,IAAI;KAClB,CAAC;IAEF,MAAM,MAAM,GAAkD;QAC5D,GAAG,UAAU;aACV,MAAM,CACL,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,UAAU;YAC1B,CAAC,CAAC,CAAC,kBAAkB,KAAK,IAAI,IAAI,CAAC,CAAC,kBAAkB,KAAK,SAAS,CAAC,CACxE;aACA,GAAG,CAA8C,CAAC,CAAC,EAAE,EAAE;YACtD,OAAO;gBACL,IAAI,EAAE,CAAC,CAAC,UAAU;gBAClB,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;aAC1B,CAAC;QACJ,CAAC,CAAC;QACJ,YAAY;KACb,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"clientHelpers.js","sourceRoot":"","sources":["../../../../src/modular/helpers/clientHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,UAAU,mBAAmB,CACjC,MAAc;IAEd,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAC9B,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACnC,MAAM,YAAY,GAAG;QACnB,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,GAAG,IAAI,eAAe;QAC5B,WAAW,EAAE,IAAI;KAClB,CAAC;IAEF,MAAM,MAAM,GAAkD;QAC5D,GAAG,UAAU;aACV,MAAM,CACL,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,UAAU;YAC1B,CAAC,CAAC,CAAC,kBAAkB,KAAK,IAAI,IAAI,CAAC,CAAC,kBAAkB,KAAK,SAAS,CAAC,CACxE;aACA,GAAG,CAA8C,CAAC,CAAC,EAAE,EAAE;YACtD,OAAO;gBACL,IAAI,EAAE,CAAC,CAAC,UAAU;gBAClB,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI;aAC3B,CAAC;QACJ,CAAC,CAAC;QACJ,YAAY;KACb,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function getFixmeForMultilineDocs(fixme: string[]): string[];
2
+ export declare function getDocsFromDescription(description?: string): string[];
3
+ //# sourceMappingURL=docsHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docsHelpers.d.ts","sourceRoot":"","sources":["../../../../src/modular/helpers/docsHelpers.ts"],"names":[],"mappings":"AAAA,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAElE;AAED,wBAAgB,sBAAsB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAKrE"}
@@ -0,0 +1,10 @@
1
+ export function getFixmeForMultilineDocs(fixme) {
2
+ return fixme.map((fixme) => ` @fixme ${fixme}`);
3
+ }
4
+ export function getDocsFromDescription(description) {
5
+ if (!description || description.trim().length === 0) {
6
+ return [];
7
+ }
8
+ return [description];
9
+ }
10
+ //# sourceMappingURL=docsHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docsHelpers.js","sourceRoot":"","sources":["../../../../src/modular/helpers/docsHelpers.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,wBAAwB,CAAC,KAAe;IACtD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,KAAK,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,WAAoB;IACzD,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE;QACnD,OAAO,EAAE,CAAC;KACX;IACD,OAAO,CAAC,WAAW,CAAC,CAAC;AACvB,CAAC"}
@@ -1,10 +1,17 @@
1
1
  import { FunctionDeclarationStructure, OptionalKind } from "ts-morph";
2
- import { Operation } from "../modularCodeModel.js";
3
- export declare function getSendPrivateFunction(operation: Operation, clientType: string): OptionalKind<FunctionDeclarationStructure>;
4
- export declare function getDeserializePrivateFunction(operation: Operation, needSubClient: boolean, needUnexpectedHelper: boolean): OptionalKind<FunctionDeclarationStructure>;
2
+ import { ModularCodeModel, Operation, Property } from "../modularCodeModel.js";
3
+ export declare function getSendPrivateFunction(operation: Operation, clientType: string, importSet: Map<string, Set<string>>): OptionalKind<FunctionDeclarationStructure>;
4
+ export declare function getDeserializePrivateFunction(operation: Operation, needSubClient: boolean, needUnexpectedHelper: boolean, importSet: Map<string, Set<string>>): OptionalKind<FunctionDeclarationStructure>;
5
5
  /**
6
6
  * This operation builds and returns the function declaration for an operation.
7
7
  */
8
8
  export declare function getOperationFunction(operation: Operation, clientType: string): OptionalKind<FunctionDeclarationStructure>;
9
- export declare function getOperationOptionsName(operation: Operation): string;
9
+ export declare function getOperationOptionsName(operation: Operation, includeGroupName?: boolean): string;
10
+ /**
11
+ * This function helps translating an RLC response to an HLC response,
12
+ * extracting properties from body and headers and building the HLC response object
13
+ */
14
+ export declare function getResponseMapping(properties: Property[], propertyPath: string | undefined, importSet: Map<string, Set<string>>): string[];
15
+ export declare function hasLROOperation(codeModel: ModularCodeModel): boolean;
16
+ export declare function hasPagingOperation(codeModel: ModularCodeModel): boolean;
10
17
  //# sourceMappingURL=operationHelpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"operationHelpers.d.ts","sourceRoot":"","sources":["../../../../src/modular/helpers/operationHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,YAAY,EAEb,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,SAAS,EAIV,MAAM,wBAAwB,CAAC;AA6BhC,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,MAAM,GACjB,YAAY,CAAC,4BAA4B,CAAC,CA+B5C;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,OAAO,EACtB,oBAAoB,EAAE,OAAO,GAC5B,YAAY,CAAC,4BAA4B,CAAC,CAgE5C;AA6DD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,MAAM,GACjB,YAAY,CAAC,4BAA4B,CAAC,CAgC5C;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,SAAS,UAI3D"}
1
+ {"version":3,"file":"operationHelpers.d.ts","sourceRoot":"","sources":["../../../../src/modular/helpers/operationHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,YAAY,EAEb,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,gBAAgB,EAChB,SAAS,EAET,QAAQ,EAET,MAAM,wBAAwB,CAAC;AAoChC,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,GAClC,YAAY,CAAC,4BAA4B,CAAC,CA6B5C;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,OAAO,EACtB,oBAAoB,EAAE,OAAO,EAC7B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,GAClC,YAAY,CAAC,4BAA4B,CAAC,CAyE5C;AA6DD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,MAAM,GACjB,YAAY,CAAC,4BAA4B,CAAC,CAmC5C;AAED,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,SAAS,EACpB,gBAAgB,UAAQ,UAQzB;AAsWD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,QAAQ,EAAE,EACtB,YAAY,oBAAwB,EACpC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,YAyEpC;AA8GD,wBAAgB,eAAe,CAAC,SAAS,EAAE,gBAAgB,WAQ1D;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,gBAAgB,WAS7D"}
@@ -2,7 +2,8 @@ import { toPascalCase } from "../../utils/casingUtils.js";
2
2
  import { buildType } from "./typeHelpers.js";
3
3
  import { NameType, getResponseBaseName, getResponseTypeName, normalizeName } from "@azure-tools/rlc-common";
4
4
  import { getOperationName } from "./namingHelpers.js";
5
- import { getFixmeForMultilineDocs } from "./fixmeHelpers.js";
5
+ import { getFixmeForMultilineDocs, getDocsFromDescription } from "./docsHelpers.js";
6
+ import { getCollectionFormatHelper, hasCollectionFormatInfo } from "../../utils/operationUtil.js";
6
7
  function getRLCResponseType(rlcResponse) {
7
8
  if (!(rlcResponse === null || rlcResponse === void 0 ? void 0 : rlcResponse.responses)) {
8
9
  return;
@@ -14,10 +15,7 @@ function getRLCResponseType(rlcResponse) {
14
15
  return (_a = resp.predefinedName) !== null && _a !== void 0 ? _a : getResponseTypeName(baseResponseName);
15
16
  }).join(" | ");
16
17
  }
17
- export function getSendPrivateFunction(operation, clientType) {
18
- if (operation.name === "uploadTestFile") {
19
- operation;
20
- }
18
+ export function getSendPrivateFunction(operation, clientType, importSet) {
21
19
  const parameters = getOperationSignatureParameters(operation, clientType);
22
20
  const { name } = getOperationName(operation);
23
21
  const functionStatement = {
@@ -30,13 +28,13 @@ export function getSendPrivateFunction(operation, clientType) {
30
28
  const operationPath = operation.url;
31
29
  const operationMethod = operation.method.toLowerCase();
32
30
  const statements = [];
33
- statements.push(`return context.path("${operationPath}", ${getPathParameters(operation)}).${operationMethod}({...operationOptionsToRequestParameters(options), ${getRequestParameters(operation)}});`);
31
+ statements.push(`return context.path("${operationPath}", ${getPathParameters(operation)}).${operationMethod}({...operationOptionsToRequestParameters(options), ${getRequestParameters(operation, importSet)}});`);
34
32
  return {
35
33
  ...functionStatement,
36
34
  statements
37
35
  };
38
36
  }
39
- export function getDeserializePrivateFunction(operation, needSubClient, needUnexpectedHelper) {
37
+ export function getDeserializePrivateFunction(operation, needSubClient, needUnexpectedHelper, importSet) {
40
38
  var _a, _b, _c, _d, _e;
41
39
  const { name } = getOperationName(operation);
42
40
  let parameters = [
@@ -77,10 +75,10 @@ export function getDeserializePrivateFunction(operation, needSubClient, needUnex
77
75
  statements.push(`return result.body`);
78
76
  }
79
77
  else if ((_c = response === null || response === void 0 ? void 0 : response.type) === null || _c === void 0 ? void 0 : _c.elementType) {
80
- statements.push(`return ${deserializeResponseValue(response.type, "result.body")}`);
78
+ statements.push(`return ${deserializeResponseValue(response.type, "result.body", importSet, response.type.nullable !== undefined ? !response.type.nullable : false)}`);
81
79
  }
82
80
  else if ((_d = response === null || response === void 0 ? void 0 : response.type) === null || _d === void 0 ? void 0 : _d.properties) {
83
- statements.push(`return {`, getResponseMapping((_e = response.type.properties) !== null && _e !== void 0 ? _e : []).join(","), `}`);
81
+ statements.push(`return {`, getResponseMapping((_e = response.type.properties) !== null && _e !== void 0 ? _e : [], "result.body", importSet).join(","), `}`);
84
82
  }
85
83
  else if (returnType.type === "void") {
86
84
  statements.push(`return;`);
@@ -145,7 +143,10 @@ export function getOperationFunction(operation, clientType) {
145
143
  : { name: "", type: "void" };
146
144
  const { name, fixme = [] } = getOperationName(operation);
147
145
  const functionStatement = {
148
- docs: [operation.description, ...getFixmeForMultilineDocs(fixme)],
146
+ docs: [
147
+ ...getDocsFromDescription(operation.description),
148
+ ...getFixmeForMultilineDocs(fixme)
149
+ ],
149
150
  isAsync: true,
150
151
  isExported: true,
151
152
  name: normalizeName(operation.name, NameType.Operation, true),
@@ -162,15 +163,21 @@ export function getOperationFunction(operation, clientType) {
162
163
  statements
163
164
  };
164
165
  }
165
- export function getOperationOptionsName(operation) {
166
- return `${toPascalCase(operation.groupName)}${toPascalCase(operation.name)}Options`;
166
+ export function getOperationOptionsName(operation, includeGroupName = false) {
167
+ var _a;
168
+ const prefix = includeGroupName ? toPascalCase(operation.groupName) : "";
169
+ const optionName = `${prefix}${toPascalCase(operation.name)}Options`;
170
+ if (((_a = operation.bodyParameter) === null || _a === void 0 ? void 0 : _a.type.name) === optionName) {
171
+ return optionName.replace(/Options$/, "RequestOptions");
172
+ }
173
+ return optionName;
167
174
  }
168
175
  /**
169
176
  * This function build the request parameters that we will provide to the
170
177
  * RLC internally. This will translate High Level parameters into the RLC ones.
171
178
  * Figuring out what goes in headers, body, path and qsp.
172
179
  */
173
- function getRequestParameters(operation) {
180
+ function getRequestParameters(operation, importSet) {
174
181
  if (!operation.parameters) {
175
182
  return "";
176
183
  }
@@ -183,7 +190,7 @@ function getRequestParameters(operation) {
183
190
  };
184
191
  for (const param of operationParameters) {
185
192
  if (param.location === "header" || param.location === "query") {
186
- parametersImplementation[param.location].push(getParameterMap(param));
193
+ parametersImplementation[param.location].push(getParameterMap(param, importSet));
187
194
  }
188
195
  }
189
196
  let paramStr = "";
@@ -191,29 +198,40 @@ function getRequestParameters(operation) {
191
198
  paramStr = `${getContentTypeValue(contentTypeParameter)},`;
192
199
  }
193
200
  if (parametersImplementation.header.length) {
194
- paramStr = `${paramStr}\nheaders: {${parametersImplementation.header.join(",\n") + ","},`;
201
+ paramStr = `${paramStr}\nheaders: {${parametersImplementation.header.join(",\n")}},`;
195
202
  }
196
203
  if (parametersImplementation.query.length) {
197
204
  paramStr = `${paramStr}\nqueryParameters: {${parametersImplementation.query.join(",\n")}},`;
198
205
  }
199
- paramStr = `${paramStr}${buildBodyParameter(operation.bodyParameter)}`;
206
+ paramStr = `${paramStr}${buildBodyParameter(operation.bodyParameter, importSet)}`;
200
207
  return paramStr;
201
208
  }
202
- function buildBodyParameter(bodyParameter) {
203
- var _a, _b;
209
+ function buildBodyParameter(bodyParameter, importSet) {
210
+ var _a, _b, _c;
204
211
  if (!bodyParameter) {
205
212
  return "";
206
213
  }
207
214
  if (bodyParameter.type.type === "model") {
208
215
  const bodyParts = [];
209
216
  for (const param of (_b = (_a = bodyParameter === null || bodyParameter === void 0 ? void 0 : bodyParameter.type.properties) === null || _a === void 0 ? void 0 : _a.filter((p) => !p.readonly)) !== null && _b !== void 0 ? _b : []) {
210
- bodyParts.push(getParameterMap(param));
217
+ if (param.type.type === "model" && isRequired(param)) {
218
+ bodyParts.push(`"${param.restApiName}": {${getRequestModelMapping(param.type, param.clientName, importSet).join(",\n")}}`);
219
+ }
220
+ else {
221
+ bodyParts.push(getParameterMap(param, importSet));
222
+ }
211
223
  }
212
224
  if (bodyParameter && bodyParameter.type.properties) {
213
225
  return `\nbody: {${bodyParts.join(",\n")}},`;
214
226
  }
215
227
  }
216
228
  if (bodyParameter.type.type === "list") {
229
+ if (((_c = bodyParameter.type.elementType) === null || _c === void 0 ? void 0 : _c.type) === "model") {
230
+ const bodyParts = getRequestModelMapping(bodyParameter.type.elementType, "p", importSet);
231
+ return `\nbody: (${bodyParameter.clientName} ?? []).map((p) => { return {
232
+ ${bodyParts.join(", ")}
233
+ };}),`;
234
+ }
217
235
  return `\nbody: ${bodyParameter.clientName},`;
218
236
  }
219
237
  if (bodyParameter.type.type === "byte-array") {
@@ -224,21 +242,35 @@ function buildBodyParameter(bodyParameter) {
224
242
  /**
225
243
  * This function helps with renames, translating client names to rest api names
226
244
  */
227
- function getParameterMap(param) {
245
+ function getParameterMap(param, importSet) {
228
246
  if (isConstant(param)) {
229
247
  return getConstantValue(param);
230
248
  }
231
- if (isOptionalWithouDefault(param)) {
232
- return getOptionalWithoutDefault(param);
249
+ if (hasCollectionFormatInfo(param.location, param.format)) {
250
+ return getCollectionFormat(param);
233
251
  }
234
- if (isOptionalWithDefault(param)) {
235
- return getOptionalWithDefault(param);
252
+ // if the parameter or property is optional, we don't need to handle the default value
253
+ if (isOptional(param)) {
254
+ return getOptional(param, importSet);
236
255
  }
237
256
  if (isRequired(param)) {
238
- return getRequired(param);
257
+ return getRequired(param, importSet);
239
258
  }
240
259
  throw new Error(`Parameter ${param.clientName} is not supported`);
241
260
  }
261
+ function getCollectionFormat(param) {
262
+ var _a, _b;
263
+ const collectionInfo = getCollectionFormatHelper(param.location, (_a = param.format) !== null && _a !== void 0 ? _a : "");
264
+ if (!collectionInfo) {
265
+ throw "Has collection format info but without helper function detected";
266
+ }
267
+ const isMulti = ((_b = param.format) !== null && _b !== void 0 ? _b : "").toLowerCase() === "multi";
268
+ const additionalParam = isMulti ? `, "${param.restApiName}"` : "";
269
+ if (!param.optional) {
270
+ return `"${param.restApiName}": ${collectionInfo}(${param.clientName}${additionalParam})`;
271
+ }
272
+ return `"${param.restApiName}": options?.${param.clientName} !== undefined ? ${collectionInfo}(options?.${param.clientName}${additionalParam}): undefined`;
273
+ }
242
274
  function isContentType(param) {
243
275
  return (param.location === "header" &&
244
276
  param.restApiName.toLowerCase() === "content-type");
@@ -259,7 +291,10 @@ function getContentTypeValue(param) {
259
291
  function isRequired(param) {
260
292
  return !param.optional;
261
293
  }
262
- function getRequired(param) {
294
+ function getRequired(param, importSet) {
295
+ if (param.type.type === "model") {
296
+ return `"${param.restApiName}": ${getRequestModelMapping(param.type, param.clientName, importSet).join(",")}`;
297
+ }
263
298
  return `"${param.restApiName}": ${param.clientName}`;
264
299
  }
265
300
  function getConstantValue(param) {
@@ -273,25 +308,14 @@ function getConstantValue(param) {
273
308
  function isConstant(param) {
274
309
  return (param.type.type === "constant" && param.clientDefaultValue !== undefined);
275
310
  }
276
- function isOptionalWithouDefault(param) {
277
- return Boolean(param.optional && !param.clientDefaultValue);
278
- }
279
- function getOptionalWithoutDefault(param) {
280
- return `"${param.restApiName}": options?.${param.clientName}`;
281
- }
282
- function isOptionalWithDefault(param) {
283
- return Boolean(param.clientDefaultValue);
311
+ function isOptional(param) {
312
+ return Boolean(param.optional);
284
313
  }
285
- function getOptionalWithDefault(param) {
286
- return `"${param.restApiName}": options.${param.clientName} ?? ${getQuotedValue(param)}`;
287
- }
288
- function getQuotedValue(param) {
289
- if (param.type.type === "string") {
290
- return `"${param.clientDefaultValue}"`;
291
- }
292
- else {
293
- return param.clientDefaultValue;
314
+ function getOptional(param, importSet) {
315
+ if (param.type.type === "model") {
316
+ return `"${param.restApiName}": {${getRequestModelMapping(param.type, "options?." + param.clientName + "?", importSet).join(", ")}}`;
294
317
  }
318
+ return `"${param.restApiName}": options?.${param.clientName}`;
295
319
  }
296
320
  /**
297
321
  * Builds the assignment for when a property or parameter has a default value
@@ -332,30 +356,81 @@ function getNullableCheck(name, type) {
332
356
  }
333
357
  return `${name} === null ? null :`;
334
358
  }
359
+ /**
360
+ *
361
+ * This function helps translating an HLC request to RLC request,
362
+ * extracting properties from body and headers and building the RLC response object
363
+ */
364
+ function getRequestModelMapping(modelPropertyType, propertyPath = "body", importSet) {
365
+ if (!modelPropertyType.properties || !modelPropertyType.properties) {
366
+ return [];
367
+ }
368
+ const props = [];
369
+ const properties = modelPropertyType.properties;
370
+ for (const property of properties) {
371
+ if (property.readonly) {
372
+ continue;
373
+ }
374
+ const propertyFullName = `${propertyPath}.${property.restApiName}`;
375
+ if (property.type.type === "model") {
376
+ let definition;
377
+ if (property.type.isCoreErrorType) {
378
+ definition = `"${property.restApiName}": ${getNullableCheck(propertyFullName, property.type)} ${!property.optional ? "" : `!${propertyFullName} ? undefined :`} ${propertyFullName}`;
379
+ }
380
+ else {
381
+ definition = `"${property.restApiName}": ${getNullableCheck(propertyFullName, property.type)} ${!property.optional ? "" : `!${propertyFullName} ? undefined :`} {${getRequestModelMapping(property.type, `${propertyPath}.${property.restApiName}${property.optional ? "?" : ""}`, importSet)}}`;
382
+ }
383
+ props.push(definition);
384
+ }
385
+ else {
386
+ const dot = propertyPath.endsWith("?") ? "." : "";
387
+ const restValue = `${propertyPath ? `${propertyPath}${dot}` : `${dot}`}["${property.clientName}"]`;
388
+ props.push(`"${property.restApiName}": ${serializeRequestValue(property.type, restValue, importSet)}`);
389
+ }
390
+ }
391
+ return props;
392
+ }
335
393
  /**
336
394
  * This function helps translating an RLC response to an HLC response,
337
395
  * extracting properties from body and headers and building the HLC response object
338
396
  */
339
- function getResponseMapping(properties, propertyPath = "result.body") {
340
- var _a;
397
+ export function getResponseMapping(properties, propertyPath = "result.body", importSet) {
398
+ var _a, _b, _c;
341
399
  const props = [];
342
400
  for (const property of properties) {
343
401
  // TODO: Do we need to also add headers in the result type?
344
- const propertyFullName = `${propertyPath}.${property.clientName}`;
402
+ const propertyFullName = `${propertyPath}.${property.restApiName}`;
345
403
  if (property.type.type === "model") {
346
404
  let definition;
347
405
  if (property.type.isCoreErrorType) {
348
- definition = `"${property.restApiName}": ${getNullableCheck(propertyFullName, property.type)} ${!property.optional ? "" : `!${propertyFullName} ? undefined :`} ${propertyFullName}`;
406
+ definition = `"${property.clientName}": ${getNullableCheck(propertyFullName, property.type)} ${!property.optional ? "" : `!${propertyFullName} ? undefined :`} ${propertyFullName}`;
407
+ }
408
+ else if ((property.restApiName === "message" ||
409
+ property.restApiName === "messages") &&
410
+ (property.type.name === "ChatMessage" ||
411
+ ((_a = property.type.elementType) === null || _a === void 0 ? void 0 : _a.name) === "ChatMessage")) {
412
+ definition = `"${property.clientName}": ${!property.optional
413
+ ? `${propertyFullName} as any`
414
+ : `!${propertyFullName} ? undefined : ${propertyFullName} as any`}`;
349
415
  }
350
416
  else {
351
- definition = `"${property.restApiName}": ${getNullableCheck(propertyFullName, property.type)} ${!property.optional ? "" : `!${propertyFullName} ? undefined :`} {${getResponseMapping((_a = property.type.properties) !== null && _a !== void 0 ? _a : [], `${propertyPath}.${property.restApiName}${property.optional ? "?" : ""}`)}}`;
417
+ definition = `"${property.clientName}": ${getNullableCheck(propertyFullName, property.type)} ${!property.optional ? "" : `!${propertyFullName} ? undefined :`} {${getResponseMapping((_b = property.type.properties) !== null && _b !== void 0 ? _b : [], `${propertyPath}.${property.restApiName}${property.optional ? "?" : ""}`, importSet)}}`;
352
418
  }
353
419
  props.push(definition);
354
420
  }
355
421
  else {
356
422
  const dot = propertyPath.endsWith("?") ? "." : "";
357
423
  const restValue = `${propertyPath ? `${propertyPath}${dot}` : `${dot}`}["${property.restApiName}"]`;
358
- props.push(`"${property.clientName}": ${deserializeResponseValue(property.type, restValue)}`);
424
+ if (property.restApiName === "messages" &&
425
+ (property.type.name === "ChatMessage" ||
426
+ ((_c = property.type.elementType) === null || _c === void 0 ? void 0 : _c.name) === "ChatMessage")) {
427
+ props.push(`"${property.clientName}": ${!property.optional
428
+ ? `${propertyFullName} as any`
429
+ : `!${propertyFullName} ? undefined : ${propertyFullName} as any`}`);
430
+ }
431
+ else {
432
+ props.push(`"${property.clientName}": ${deserializeResponseValue(property.type, restValue, importSet, property.optional !== undefined ? !property.optional : false)}`);
433
+ }
359
434
  }
360
435
  }
361
436
  return props;
@@ -365,23 +440,69 @@ function getResponseMapping(properties, propertyPath = "result.body") {
365
440
  * We need to drill down into Array elements to make sure that the element type is
366
441
  * deserialized correctly
367
442
  */
368
- function deserializeResponseValue(type, restValue) {
369
- var _a, _b, _c, _d, _e;
443
+ function deserializeResponseValue(type, restValue, importSet, required) {
444
+ var _a, _b, _c, _d, _e, _f;
445
+ const coreUtilSet = importSet.get("@azure/core-util");
370
446
  switch (type.type) {
371
447
  case "datetime":
372
- return `new Date(${restValue} ?? "")`;
373
- case "byte-array":
374
- return `Buffer.from(${restValue} ?? "")`;
448
+ return required
449
+ ? `new Date(${restValue})`
450
+ : `${restValue} !== undefined? new Date(${restValue}): undefined`;
451
+ case "combined":
452
+ return `${restValue} as any`;
375
453
  case "list":
376
454
  if (((_a = type.elementType) === null || _a === void 0 ? void 0 : _a.type) === "model") {
377
- return `(${restValue} ?? []).map(p => ({${getResponseMapping((_c = (_b = type.elementType) === null || _b === void 0 ? void 0 : _b.properties) !== null && _c !== void 0 ? _c : [], "p")}}))`;
455
+ return `(${restValue} ?? []).map(p => ({${getResponseMapping((_c = (_b = type.elementType) === null || _b === void 0 ? void 0 : _b.properties) !== null && _c !== void 0 ? _c : [], "p", importSet)}}))`;
378
456
  }
379
457
  else if ((_e = (_d = type.elementType) === null || _d === void 0 ? void 0 : _d.properties) === null || _e === void 0 ? void 0 : _e.some((p) => needsDeserialize(p.type))) {
380
- return `(${restValue} ?? []).map(p => ${deserializeResponseValue(type.elementType, "p")})`;
458
+ return `(${restValue} ?? []).map(p => ${deserializeResponseValue(type.elementType, "p", importSet, required)})`;
381
459
  }
382
460
  else {
383
461
  return restValue;
384
462
  }
463
+ case "byte-array":
464
+ if (!coreUtilSet) {
465
+ importSet.set("@azure/core-util", new Set().add("stringToUint8Array"));
466
+ }
467
+ else {
468
+ coreUtilSet.add("stringToUint8Array");
469
+ }
470
+ return `typeof ${restValue} === 'string'
471
+ ? stringToUint8Array(${restValue}, "${(_f = type.format) !== null && _f !== void 0 ? _f : "base64"}")
472
+ : ${restValue}`;
473
+ default:
474
+ return restValue;
475
+ }
476
+ }
477
+ /**
478
+ * This function helps converting strings into JS complex types recursively.
479
+ * We need to drill down into Array elements to make sure that the element type is
480
+ * deserialized correctly
481
+ */
482
+ function serializeRequestValue(type, restValue, importSet) {
483
+ var _a, _b, _c, _d;
484
+ const coreUtilSet = importSet.get("@azure/core-util");
485
+ switch (type.type) {
486
+ case "datetime":
487
+ return `${restValue} !== undefined ? new Date(${restValue}): undefined`;
488
+ case "list":
489
+ if (((_a = type.elementType) === null || _a === void 0 ? void 0 : _a.type) === "model") {
490
+ return `(${restValue} ?? []).map(p => ({${getRequestModelMapping(type.elementType, "p", importSet)}}))`;
491
+ }
492
+ else if ((_c = (_b = type.elementType) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.some((p) => needsDeserialize(p.type))) {
493
+ return `(${restValue} ?? []).map(p => ${serializeRequestValue(type.elementType, "p", importSet)})`;
494
+ }
495
+ else {
496
+ return restValue;
497
+ }
498
+ case "byte-array":
499
+ if (!coreUtilSet) {
500
+ importSet.set("@azure/core-util", new Set().add("uint8ArrayToString"));
501
+ }
502
+ else {
503
+ coreUtilSet.add("uint8ArrayToString");
504
+ }
505
+ return `${restValue} !== undefined ? uint8ArrayToString(${restValue}, "${(_d = type.format) !== null && _d !== void 0 ? _d : "base64"}"): undefined`;
385
506
  default:
386
507
  return restValue;
387
508
  }
@@ -389,4 +510,24 @@ function deserializeResponseValue(type, restValue) {
389
510
  function needsDeserialize(type) {
390
511
  return (type === null || type === void 0 ? void 0 : type.type) === "datetime" || (type === null || type === void 0 ? void 0 : type.type) === "model";
391
512
  }
513
+ export function hasLROOperation(codeModel) {
514
+ var _a;
515
+ return ((_a = codeModel.clients) !== null && _a !== void 0 ? _a : []).some((c) => {
516
+ var _a;
517
+ return ((_a = c.operationGroups) !== null && _a !== void 0 ? _a : []).some((og) => {
518
+ var _a;
519
+ return ((_a = og.operations) !== null && _a !== void 0 ? _a : []).some((op) => op.discriminator === "lro" || op.discriminator === "lropaging");
520
+ });
521
+ });
522
+ }
523
+ export function hasPagingOperation(codeModel) {
524
+ var _a;
525
+ return ((_a = codeModel.clients) !== null && _a !== void 0 ? _a : []).some((c) => {
526
+ var _a;
527
+ return ((_a = c.operationGroups) !== null && _a !== void 0 ? _a : []).some((og) => {
528
+ var _a;
529
+ return ((_a = og.operations) !== null && _a !== void 0 ? _a : []).some((op) => op.discriminator === "paging" || op.discriminator === "lropaging");
530
+ });
531
+ });
532
+ }
392
533
  //# sourceMappingURL=operationHelpers.js.map