@azure-tools/rlc-common 0.12.0 → 0.13.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 (77) hide show
  1. package/.rush/temp/operation/build/all.log +1 -0
  2. package/.rush/temp/operation/build/state.json +3 -0
  3. package/.rush/temp/package-deps_build.json +17 -16
  4. package/.rush/temp/shrinkwrap-deps.json +146 -145
  5. package/CHANGELOG.md +7 -0
  6. package/dist/buildClient.js +15 -4
  7. package/dist/buildClient.js.map +1 -1
  8. package/dist/buildIsUnexpectedHelper.js +14 -6
  9. package/dist/buildIsUnexpectedHelper.js.map +1 -1
  10. package/dist/buildLogger.js +27 -0
  11. package/dist/buildLogger.js.map +1 -0
  12. package/dist/buildPaginateHelper.js +1 -1
  13. package/dist/buildPaginateHelper.js.map +1 -1
  14. package/dist/buildPollingHelper.js +39 -1
  15. package/dist/buildPollingHelper.js.map +1 -1
  16. package/dist/buildResponseTypes.js +3 -3
  17. package/dist/buildResponseTypes.js.map +1 -1
  18. package/dist/buildTopLevelIndexFile.js +1 -1
  19. package/dist/buildTopLevelIndexFile.js.map +1 -1
  20. package/dist/helpers/nameConstructors.js +5 -1
  21. package/dist/helpers/nameConstructors.js.map +1 -1
  22. package/dist/helpers/operationHelpers.js +6 -6
  23. package/dist/helpers/operationHelpers.js.map +1 -1
  24. package/dist/index.js +1 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/interfaces.js +2 -1
  27. package/dist/interfaces.js.map +1 -1
  28. package/dist/metadata/buildPackageFile.js +2 -2
  29. package/dist/package.json +1 -1
  30. package/dist/static/pollingContent.js +18 -0
  31. package/dist/static/pollingContent.js.map +1 -1
  32. package/dist-esm/buildClient.js +15 -4
  33. package/dist-esm/buildClient.js.map +1 -1
  34. package/dist-esm/buildIsUnexpectedHelper.js +15 -4
  35. package/dist-esm/buildIsUnexpectedHelper.js.map +1 -1
  36. package/dist-esm/buildLogger.js +23 -0
  37. package/dist-esm/buildLogger.js.map +1 -0
  38. package/dist-esm/buildPaginateHelper.js +1 -1
  39. package/dist-esm/buildPaginateHelper.js.map +1 -1
  40. package/dist-esm/buildPollingHelper.js +38 -1
  41. package/dist-esm/buildPollingHelper.js.map +1 -1
  42. package/dist-esm/buildResponseTypes.js +1 -1
  43. package/dist-esm/buildResponseTypes.js.map +1 -1
  44. package/dist-esm/buildTopLevelIndexFile.js +1 -1
  45. package/dist-esm/buildTopLevelIndexFile.js.map +1 -1
  46. package/dist-esm/helpers/nameConstructors.js +3 -0
  47. package/dist-esm/helpers/nameConstructors.js.map +1 -1
  48. package/dist-esm/helpers/operationHelpers.js +6 -6
  49. package/dist-esm/helpers/operationHelpers.js.map +1 -1
  50. package/dist-esm/index.js +1 -0
  51. package/dist-esm/index.js.map +1 -1
  52. package/dist-esm/interfaces.js +1 -0
  53. package/dist-esm/interfaces.js.map +1 -1
  54. package/dist-esm/metadata/buildPackageFile.js +2 -2
  55. package/dist-esm/package.json +1 -1
  56. package/dist-esm/static/pollingContent.js +18 -0
  57. package/dist-esm/static/pollingContent.js.map +1 -1
  58. package/package.json +14 -14
  59. package/rlc-common.build.log +0 -1
  60. package/src/buildClient.ts +19 -4
  61. package/src/buildIsUnexpectedHelper.ts +23 -4
  62. package/src/buildLogger.ts +30 -0
  63. package/src/buildPaginateHelper.ts +1 -1
  64. package/src/buildPollingHelper.ts +58 -2
  65. package/src/buildResponseTypes.ts +2 -1
  66. package/src/buildTopLevelIndexFile.ts +1 -1
  67. package/src/helpers/nameConstructors.ts +10 -0
  68. package/src/helpers/operationHelpers.ts +7 -6
  69. package/src/index.ts +1 -0
  70. package/src/interfaces.ts +19 -5
  71. package/src/metadata/buildPackageFile.ts +2 -2
  72. package/src/static/pollingContent.ts +18 -0
  73. package/types/buildLogger.d.ts +5 -0
  74. package/types/helpers/nameConstructors.d.ts +1 -0
  75. package/types/index.d.ts +1 -0
  76. package/types/interfaces.d.ts +17 -5
  77. package/types/static/pollingContent.d.ts +1 -1
package/src/interfaces.ts CHANGED
@@ -10,7 +10,7 @@ export interface RLCModel {
10
10
  parameters?: OperationParameter[];
11
11
  responses?: OperationResponse[];
12
12
  importSet?: Map<ImportKind, Set<string>>;
13
- annotations?: AnnotationDetails;
13
+ helperDetails?: HelperFunctionDetails;
14
14
  urlInfo?: UrlInfo;
15
15
  }
16
16
 
@@ -31,9 +31,10 @@ export interface ApiVersionInfo {
31
31
  }
32
32
 
33
33
  export type ApiVersionPosition = "path" | "query" | "both" | "none";
34
- export interface AnnotationDetails {
34
+ export interface HelperFunctionDetails {
35
35
  hasPaging?: boolean;
36
36
  hasLongRunning?: boolean;
37
+ clientLroOverload?: boolean;
37
38
  pageDetails?: PagingDetails;
38
39
  hasMultiCollection?: boolean;
39
40
  hasPipeCollection?: boolean;
@@ -64,7 +65,7 @@ export interface OperationMethod {
64
65
  successStatus: string[];
65
66
  responseTypes: ResponseTypes;
66
67
  operationName: string;
67
- annotations?: OperationAnnotations;
68
+ operationHelperDetail?: OperationHelperDetail;
68
69
  }
69
70
  export interface PathMetadata {
70
71
  name: string;
@@ -83,11 +84,23 @@ export type PathParameter = {
83
84
  value?: string | number | boolean;
84
85
  };
85
86
 
86
- export interface OperationAnnotations {
87
- isLongRunning?: boolean;
87
+ export interface OperationHelperDetail {
88
+ lroDetails?: OperationLroDetail;
88
89
  isPageable?: boolean;
89
90
  }
90
91
 
92
+ export const OPERATION_LRO_HIGH_PRIORITY = 0,
93
+ OPERATION_LRO_LOW_PRIORITY = 1;
94
+ export interface OperationLroDetail {
95
+ isLongRunning?: boolean;
96
+ logicalResponseTypes?: ResponseTypes;
97
+ operationLroOverload?: boolean;
98
+ /**
99
+ * This is used to sort the overload order, sorted in descending order
100
+ */
101
+ precedence?: number;
102
+ }
103
+
91
104
  export interface RLCOptions {
92
105
  includeShortcuts?: boolean;
93
106
  multiClient?: boolean;
@@ -224,6 +237,7 @@ export interface ResponseMetadata {
224
237
  description?: string;
225
238
  headers?: ResponseHeaderSchema[];
226
239
  body?: ResponseBodySchema;
240
+ predefinedName?: string;
227
241
  }
228
242
 
229
243
  export type ResponseHeaderSchema = Schema;
@@ -153,7 +153,7 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
153
153
  autoPublish: false,
154
154
  dependencies: {
155
155
  "@azure/core-auth": "^1.3.0",
156
- "@azure-rest/core-client": "^1.1.2",
156
+ "@azure-rest/core-client": "^1.1.3",
157
157
  "@azure/core-rest-pipeline": "^1.8.0",
158
158
  "@azure/logger": "^1.0.0",
159
159
  tslib: "^2.2.0",
@@ -161,7 +161,7 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
161
161
  "@azure/core-paging": "^1.5.0"
162
162
  }),
163
163
  ...(hasLRO && {
164
- "@azure/core-lro": "^2.5.0",
164
+ "@azure/core-lro": "^2.5.3",
165
165
  "@azure/abort-controller": "^1.0.0"
166
166
  })
167
167
  },
@@ -18,6 +18,13 @@ import {
18
18
  SimplePollerLike,
19
19
  createHttpPoller
20
20
  } from "@azure/core-lro";
21
+ {{#if clientOverload}}
22
+ import {
23
+ {{#each importedResponses}}
24
+ {{this}},
25
+ {{/each}}
26
+ } from "./responses";
27
+ {{/if}}
21
28
  {{/if}}
22
29
  /**
23
30
  * Helper function that builds a Poller object to help polling a long running operation.
@@ -26,6 +33,17 @@ import {
26
33
  * @param options - Options to set a resume state or custom polling interval.
27
34
  * @returns - A poller object to poll for operation state updates and eventually get the final response.
28
35
  */
36
+ {{#if clientOverload}}
37
+ {{#each overloadMap}}
38
+ export async function getLongRunningPoller<
39
+ TResult extends {{ this.finalResponses }}
40
+ >(
41
+ client: Client,
42
+ initialResponse: {{ this.initalResponses }},
43
+ options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>
44
+ ): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
45
+ {{/each}}
46
+ {{/if}}
29
47
  export {{#unless useLegacyLro}}async {{/unless}}function getLongRunningPoller<TResult extends HttpResponse>(
30
48
  client: Client,
31
49
  initialResponse: TResult,
@@ -0,0 +1,5 @@
1
+ import { RLCModel } from "./interfaces.js";
2
+ export declare function buildLogger(model: RLCModel): {
3
+ path: string;
4
+ content: string;
5
+ } | undefined;
@@ -5,6 +5,7 @@ import { RLCModel } from "../interfaces.js";
5
5
  */
6
6
  export declare function getResponseTypeName(baseResponseName: string): string;
7
7
  export declare function getResponseTypeName(operationGroup: string, operationName: string, statusCode: string): string;
8
+ export declare function getLroLogicalResponseName(operationGroup: string, operationName: string): string;
8
9
  /**
9
10
  * The prefix of all response types
10
11
  * @param operationGroup operation group name e.g string_PutEmpty
package/types/index.d.ts CHANGED
@@ -25,3 +25,4 @@ export * from "./metadata/buildESLintConfig.js";
25
25
  export * from "./metadata/buildLicenseFile.js";
26
26
  export * from "./buildSerializeHelper.js";
27
27
  export * from "./helpers/apiVersionUtil.js";
28
+ export * from "./buildLogger.js";
@@ -8,7 +8,7 @@ export interface RLCModel {
8
8
  parameters?: OperationParameter[];
9
9
  responses?: OperationResponse[];
10
10
  importSet?: Map<ImportKind, Set<string>>;
11
- annotations?: AnnotationDetails;
11
+ helperDetails?: HelperFunctionDetails;
12
12
  urlInfo?: UrlInfo;
13
13
  }
14
14
  export interface PathTemplateApiVersion {
@@ -25,9 +25,10 @@ export interface ApiVersionInfo {
25
25
  isCrossedVersion?: boolean;
26
26
  }
27
27
  export type ApiVersionPosition = "path" | "query" | "both" | "none";
28
- export interface AnnotationDetails {
28
+ export interface HelperFunctionDetails {
29
29
  hasPaging?: boolean;
30
30
  hasLongRunning?: boolean;
31
+ clientLroOverload?: boolean;
31
32
  pageDetails?: PagingDetails;
32
33
  hasMultiCollection?: boolean;
33
34
  hasPipeCollection?: boolean;
@@ -54,7 +55,7 @@ export interface OperationMethod {
54
55
  successStatus: string[];
55
56
  responseTypes: ResponseTypes;
56
57
  operationName: string;
57
- annotations?: OperationAnnotations;
58
+ operationHelperDetail?: OperationHelperDetail;
58
59
  }
59
60
  export interface PathMetadata {
60
61
  name: string;
@@ -70,10 +71,20 @@ export type PathParameter = {
70
71
  description?: string;
71
72
  value?: string | number | boolean;
72
73
  };
73
- export interface OperationAnnotations {
74
- isLongRunning?: boolean;
74
+ export interface OperationHelperDetail {
75
+ lroDetails?: OperationLroDetail;
75
76
  isPageable?: boolean;
76
77
  }
78
+ export declare const OPERATION_LRO_HIGH_PRIORITY = 0, OPERATION_LRO_LOW_PRIORITY = 1;
79
+ export interface OperationLroDetail {
80
+ isLongRunning?: boolean;
81
+ logicalResponseTypes?: ResponseTypes;
82
+ operationLroOverload?: boolean;
83
+ /**
84
+ * This is used to sort the overload order, sorted in descending order
85
+ */
86
+ precedence?: number;
87
+ }
77
88
  export interface RLCOptions {
78
89
  includeShortcuts?: boolean;
79
90
  multiClient?: boolean;
@@ -197,6 +208,7 @@ export interface ResponseMetadata {
197
208
  description?: string;
198
209
  headers?: ResponseHeaderSchema[];
199
210
  body?: ResponseBodySchema;
211
+ predefinedName?: string;
200
212
  }
201
213
  export type ResponseHeaderSchema = Schema;
202
214
  export type ResponseBodySchema = Schema;
@@ -1 +1 @@
1
- export declare const pollingContent = "\nimport { Client, HttpResponse } from \"@azure-rest/core-client\";\n{{#if useLegacyLro}}\nimport {\n LongRunningOperation,\n LroEngine,\n LroEngineOptions,\n LroResponse,\n PollerLike,\n PollOperationState\n} from \"@azure/core-lro\";\n{{else}}\nimport {\n CreateHttpPollerOptions,\n LongRunningOperation,\n LroResponse,\n OperationState,\n SimplePollerLike,\n createHttpPoller\n} from \"@azure/core-lro\";\n{{/if}}\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport {{#unless useLegacyLro}}async {{/unless}}function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n {{#if useLegacyLro}}\n options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}\n ): PollerLike<PollOperationState<TResult>, TResult> {\n {{else}}\n options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {}\n ): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {\n {{/if}} \n const poller: LongRunningOperation<TResult> = {\n requestMethod: initialResponse.request.method,\n requestPath: initialResponse.request.url,\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async path => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n const response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get();\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] =\n initialResponse.request.url;\n return lroResponse;\n }\n };\n\n {{#if useLegacyLro}}\n return new LroEngine(poller, options);\n {{else}}\n options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;\n return await createHttpPoller(poller, options);\n {{/if}}\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO implementation understands\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO implementation understands\n */\nfunction getLroResponse<TResult extends HttpResponse>(\n response: TResult\n): LroResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(\n `Status code of the response is not a number. Value: ${response.status}`\n );\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body\n }\n };\n}\n";
1
+ export declare const pollingContent = "\nimport { Client, HttpResponse } from \"@azure-rest/core-client\";\n{{#if useLegacyLro}}\nimport {\n LongRunningOperation,\n LroEngine,\n LroEngineOptions,\n LroResponse,\n PollerLike,\n PollOperationState\n} from \"@azure/core-lro\";\n{{else}}\nimport {\n CreateHttpPollerOptions,\n LongRunningOperation,\n LroResponse,\n OperationState,\n SimplePollerLike,\n createHttpPoller\n} from \"@azure/core-lro\";\n{{#if clientOverload}}\nimport {\n {{#each importedResponses}}\n {{this}},\n {{/each}}\n} from \"./responses\";\n{{/if}}\n{{/if}}\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\n{{#if clientOverload}}\n{{#each overloadMap}}\nexport async function getLongRunningPoller<\n TResult extends {{ this.finalResponses }}\n>(\n client: Client,\n initialResponse: {{ this.initalResponses }},\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\n{{/each}}\n{{/if}}\nexport {{#unless useLegacyLro}}async {{/unless}}function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n {{#if useLegacyLro}}\n options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}\n ): PollerLike<PollOperationState<TResult>, TResult> {\n {{else}}\n options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {}\n ): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {\n {{/if}} \n const poller: LongRunningOperation<TResult> = {\n requestMethod: initialResponse.request.method,\n requestPath: initialResponse.request.url,\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async path => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n const response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get();\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] =\n initialResponse.request.url;\n return lroResponse;\n }\n };\n\n {{#if useLegacyLro}}\n return new LroEngine(poller, options);\n {{else}}\n options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;\n return await createHttpPoller(poller, options);\n {{/if}}\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO implementation understands\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO implementation understands\n */\nfunction getLroResponse<TResult extends HttpResponse>(\n response: TResult\n): LroResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(\n `Status code of the response is not a number. Value: ${response.status}`\n );\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body\n }\n };\n}\n";