@azure-tools/rlc-common 1.0.0-beta.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/.rush/temp/package-deps_build.json +45 -0
- package/.rush/temp/shrinkwrap-deps.json +72 -0
- package/CHANGELOG.md +3 -0
- package/dist/buildClient.js +198 -0
- package/dist/buildClient.js.map +1 -0
- package/dist/buildClientDefinitions.js +160 -0
- package/dist/buildClientDefinitions.js.map +1 -0
- package/dist/buildIndexFile.js +150 -0
- package/dist/buildIndexFile.js.map +1 -0
- package/dist/buildIsUnexpectedHelper.js +219 -0
- package/dist/buildIsUnexpectedHelper.js.map +1 -0
- package/dist/buildMethodShortcuts.js +50 -0
- package/dist/buildMethodShortcuts.js.map +1 -0
- package/dist/buildObjectTypes.js +250 -0
- package/dist/buildObjectTypes.js.map +1 -0
- package/dist/buildPaginateHelper.js +30 -0
- package/dist/buildPaginateHelper.js.map +1 -0
- package/dist/buildParameterTypes.js +287 -0
- package/dist/buildParameterTypes.js.map +1 -0
- package/dist/buildPollingHelper.js +21 -0
- package/dist/buildPollingHelper.js.map +1 -0
- package/dist/buildResponseTypes.js +122 -0
- package/dist/buildResponseTypes.js.map +1 -0
- package/dist/buildSchemaType.js +44 -0
- package/dist/buildSchemaType.js.map +1 -0
- package/dist/buildTopLevelIndexFile.js +45 -0
- package/dist/buildTopLevelIndexFile.js.map +1 -0
- package/dist/helpers/nameConstructors.js +41 -0
- package/dist/helpers/nameConstructors.js.map +1 -0
- package/dist/helpers/nameUtils.js +196 -0
- package/dist/helpers/nameUtils.js.map +1 -0
- package/dist/helpers/operationHelpers.js +83 -0
- package/dist/helpers/operationHelpers.js.map +1 -0
- package/dist/helpers/schemaHelpers.js +27 -0
- package/dist/helpers/schemaHelpers.js.map +1 -0
- package/dist/helpers/shortcutMethods.js +46 -0
- package/dist/helpers/shortcutMethods.js.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.js +18 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/metadata/buildApiExtractorConfig.js +56 -0
- package/dist/metadata/buildApiExtractorConfig.js.map +1 -0
- package/dist/metadata/buildESLintConfig.js +33 -0
- package/dist/metadata/buildESLintConfig.js.map +1 -0
- package/dist/metadata/buildLicenseFile.js +41 -0
- package/dist/metadata/buildLicenseFile.js.map +1 -0
- package/dist/metadata/buildPackageFile.js +232 -0
- package/dist/metadata/buildPackageFile.js.map +1 -0
- package/dist/metadata/buildReadmeFile.js +170 -0
- package/dist/metadata/buildReadmeFile.js.map +1 -0
- package/dist/metadata/buildRollupConfig.js +144 -0
- package/dist/metadata/buildRollupConfig.js.map +1 -0
- package/dist/metadata/buildTsConfig.js +72 -0
- package/dist/metadata/buildTsConfig.js.map +1 -0
- package/dist/package.json +1 -0
- package/dist/static/paginateContent.js +214 -0
- package/dist/static/paginateContent.js.map +1 -0
- package/dist/static/pollingContent.js +78 -0
- package/dist/static/pollingContent.js.map +1 -0
- package/dist/test/buildEnvFile.js +31 -0
- package/dist/test/buildEnvFile.js.map +1 -0
- package/dist/test/buildKarmaConfig.js +19 -0
- package/dist/test/buildKarmaConfig.js.map +1 -0
- package/dist/test/buildRecordedClient.js +22 -0
- package/dist/test/buildRecordedClient.js.map +1 -0
- package/dist/test/buildSampleTest.js +19 -0
- package/dist/test/buildSampleTest.js.map +1 -0
- package/dist/test/template.js +192 -0
- package/dist/test/template.js.map +1 -0
- package/dist-esm/buildClient.js +191 -0
- package/dist-esm/buildClient.js.map +1 -0
- package/dist-esm/buildClientDefinitions.js +155 -0
- package/dist-esm/buildClientDefinitions.js.map +1 -0
- package/dist-esm/buildIndexFile.js +145 -0
- package/dist-esm/buildIndexFile.js.map +1 -0
- package/dist-esm/buildIsUnexpectedHelper.js +215 -0
- package/dist-esm/buildIsUnexpectedHelper.js.map +1 -0
- package/dist-esm/buildMethodShortcuts.js +46 -0
- package/dist-esm/buildMethodShortcuts.js.map +1 -0
- package/dist-esm/buildObjectTypes.js +249 -0
- package/dist-esm/buildObjectTypes.js.map +1 -0
- package/dist-esm/buildPaginateHelper.js +26 -0
- package/dist-esm/buildPaginateHelper.js.map +1 -0
- package/dist-esm/buildParameterTypes.js +288 -0
- package/dist-esm/buildParameterTypes.js.map +1 -0
- package/dist-esm/buildPollingHelper.js +17 -0
- package/dist-esm/buildPollingHelper.js.map +1 -0
- package/dist-esm/buildResponseTypes.js +127 -0
- package/dist-esm/buildResponseTypes.js.map +1 -0
- package/dist-esm/buildSchemaType.js +39 -0
- package/dist-esm/buildSchemaType.js.map +1 -0
- package/dist-esm/buildTopLevelIndexFile.js +41 -0
- package/dist-esm/buildTopLevelIndexFile.js.map +1 -0
- package/dist-esm/helpers/nameConstructors.js +34 -0
- package/dist-esm/helpers/nameConstructors.js.map +1 -0
- package/dist-esm/helpers/nameUtils.js +187 -0
- package/dist-esm/helpers/nameUtils.js.map +1 -0
- package/dist-esm/helpers/operationHelpers.js +72 -0
- package/dist-esm/helpers/operationHelpers.js.map +1 -0
- package/dist-esm/helpers/schemaHelpers.js +21 -0
- package/dist-esm/helpers/schemaHelpers.js.map +1 -0
- package/dist-esm/helpers/shortcutMethods.js +42 -0
- package/dist-esm/helpers/shortcutMethods.js.map +1 -0
- package/dist-esm/index.js +28 -0
- package/dist-esm/index.js.map +1 -0
- package/dist-esm/interfaces.js +15 -0
- package/dist-esm/interfaces.js.map +1 -0
- package/dist-esm/metadata/buildApiExtractorConfig.js +51 -0
- package/dist-esm/metadata/buildApiExtractorConfig.js.map +1 -0
- package/dist-esm/metadata/buildESLintConfig.js +28 -0
- package/dist-esm/metadata/buildESLintConfig.js.map +1 -0
- package/dist-esm/metadata/buildLicenseFile.js +36 -0
- package/dist-esm/metadata/buildLicenseFile.js.map +1 -0
- package/dist-esm/metadata/buildPackageFile.js +234 -0
- package/dist-esm/metadata/buildPackageFile.js.map +1 -0
- package/dist-esm/metadata/buildReadmeFile.js +167 -0
- package/dist-esm/metadata/buildReadmeFile.js.map +1 -0
- package/dist-esm/metadata/buildRollupConfig.js +139 -0
- package/dist-esm/metadata/buildRollupConfig.js.map +1 -0
- package/dist-esm/metadata/buildTsConfig.js +67 -0
- package/dist-esm/metadata/buildTsConfig.js.map +1 -0
- package/dist-esm/package.json +1 -0
- package/dist-esm/static/paginateContent.js +211 -0
- package/dist-esm/static/paginateContent.js.map +1 -0
- package/dist-esm/static/pollingContent.js +75 -0
- package/dist-esm/static/pollingContent.js.map +1 -0
- package/dist-esm/test/buildEnvFile.js +24 -0
- package/dist-esm/test/buildEnvFile.js.map +1 -0
- package/dist-esm/test/buildKarmaConfig.js +14 -0
- package/dist-esm/test/buildKarmaConfig.js.map +1 -0
- package/dist-esm/test/buildRecordedClient.js +17 -0
- package/dist-esm/test/buildRecordedClient.js.map +1 -0
- package/dist-esm/test/buildSampleTest.js +14 -0
- package/dist-esm/test/buildSampleTest.js.map +1 -0
- package/dist-esm/test/template.js +189 -0
- package/dist-esm/test/template.js.map +1 -0
- package/package.json +40 -0
- package/publishPackage.js +11 -0
- package/rlc-common.build.log +2 -0
- package/src/buildClient.ts +251 -0
- package/src/buildClientDefinitions.ts +231 -0
- package/src/buildIndexFile.ts +172 -0
- package/src/buildIsUnexpectedHelper.ts +240 -0
- package/src/buildMethodShortcuts.ts +75 -0
- package/src/buildObjectTypes.ts +393 -0
- package/src/buildPaginateHelper.ts +33 -0
- package/src/buildParameterTypes.ts +435 -0
- package/src/buildPollingHelper.ts +18 -0
- package/src/buildResponseTypes.ts +169 -0
- package/src/buildSchemaType.ts +56 -0
- package/src/buildTopLevelIndexFile.ts +46 -0
- package/src/helpers/nameConstructors.ts +93 -0
- package/src/helpers/nameUtils.ts +227 -0
- package/src/helpers/operationHelpers.ts +103 -0
- package/src/helpers/schemaHelpers.ts +25 -0
- package/src/helpers/shortcutMethods.ts +60 -0
- package/src/index.ts +28 -0
- package/src/interfaces.ts +212 -0
- package/src/metadata/buildApiExtractorConfig.ts +59 -0
- package/src/metadata/buildESLintConfig.ts +34 -0
- package/src/metadata/buildLicenseFile.ts +39 -0
- package/src/metadata/buildPackageFile.ts +271 -0
- package/src/metadata/buildReadmeFile.ts +231 -0
- package/src/metadata/buildRollupConfig.ts +147 -0
- package/src/metadata/buildTsConfig.ts +79 -0
- package/src/static/paginateContent.ts +210 -0
- package/src/static/pollingContent.ts +74 -0
- package/src/test/buildEnvFile.ts +26 -0
- package/src/test/buildKarmaConfig.ts +15 -0
- package/src/test/buildRecordedClient.ts +18 -0
- package/src/test/buildSampleTest.ts +15 -0
- package/src/test/template.ts +192 -0
- package/tsconfig-cjs.json +9 -0
- package/tsconfig-common.json +13 -0
- package/tsconfig.json +13 -0
- package/types/buildClient.d.ts +2 -0
- package/types/buildClientDefinitions.d.ts +5 -0
- package/types/buildIndexFile.d.ts +5 -0
- package/types/buildIsUnexpectedHelper.d.ts +5 -0
- package/types/buildMethodShortcuts.d.ts +4 -0
- package/types/buildObjectTypes.d.ts +14 -0
- package/types/buildPaginateHelper.d.ts +5 -0
- package/types/buildParameterTypes.d.ts +5 -0
- package/types/buildPollingHelper.d.ts +5 -0
- package/types/buildResponseTypes.d.ts +5 -0
- package/types/buildSchemaType.d.ts +19 -0
- package/types/buildTopLevelIndexFile.d.ts +5 -0
- package/types/helpers/nameConstructors.d.ts +28 -0
- package/types/helpers/nameUtils.d.ts +25 -0
- package/types/helpers/operationHelpers.d.ts +9 -0
- package/types/helpers/schemaHelpers.d.ts +4 -0
- package/types/helpers/shortcutMethods.d.ts +3 -0
- package/types/index.d.ts +25 -0
- package/types/interfaces.d.ts +186 -0
- package/types/metadata/buildApiExtractorConfig.d.ts +5 -0
- package/types/metadata/buildESLintConfig.d.ts +5 -0
- package/types/metadata/buildLicenseFile.d.ts +5 -0
- package/types/metadata/buildPackageFile.d.ts +5 -0
- package/types/metadata/buildReadmeFile.d.ts +5 -0
- package/types/metadata/buildRollupConfig.d.ts +5 -0
- package/types/metadata/buildTsConfig.d.ts +5 -0
- package/types/static/paginateContent.d.ts +1 -0
- package/types/static/pollingContent.d.ts +1 -0
- package/types/test/buildEnvFile.d.ts +9 -0
- package/types/test/buildKarmaConfig.d.ts +5 -0
- package/types/test/buildRecordedClient.d.ts +5 -0
- package/types/test/buildSampleTest.d.ts +5 -0
- package/types/test/template.d.ts +5 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
export interface RLCModel {
|
|
2
|
+
libraryName: string;
|
|
3
|
+
srcPath: string;
|
|
4
|
+
paths: Paths;
|
|
5
|
+
options?: RLCOptions;
|
|
6
|
+
schemas: Schema[];
|
|
7
|
+
apiVersionParam?: Parameter;
|
|
8
|
+
parameters?: OperationParameter[];
|
|
9
|
+
responses?: OperationResponse[];
|
|
10
|
+
importSet?: Map<ImportKind, Set<string>>;
|
|
11
|
+
annotations?: AnnotationDetails;
|
|
12
|
+
urlInfo?: UrlInfo;
|
|
13
|
+
}
|
|
14
|
+
export interface UrlInfo {
|
|
15
|
+
endpoint?: string;
|
|
16
|
+
urlParameters?: PathParameter[];
|
|
17
|
+
}
|
|
18
|
+
export interface AnnotationDetails {
|
|
19
|
+
hasPaging?: boolean;
|
|
20
|
+
hasLongRunning?: boolean;
|
|
21
|
+
pageDetails?: PagingDetails;
|
|
22
|
+
}
|
|
23
|
+
export interface PagingDetails {
|
|
24
|
+
itemNames: string[];
|
|
25
|
+
nextLinkNames: string[];
|
|
26
|
+
isComplexPaging: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare type Methods = {
|
|
29
|
+
[key: string]: [OperationMethod];
|
|
30
|
+
};
|
|
31
|
+
export interface ResponseTypes {
|
|
32
|
+
success: string[];
|
|
33
|
+
error: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface OperationMethod {
|
|
36
|
+
optionsName: string;
|
|
37
|
+
description: string;
|
|
38
|
+
hasOptionalOptions: boolean;
|
|
39
|
+
returnType: string;
|
|
40
|
+
successStatus: string[];
|
|
41
|
+
responseTypes: ResponseTypes;
|
|
42
|
+
operationName: string;
|
|
43
|
+
annotations?: OperationAnnotations;
|
|
44
|
+
}
|
|
45
|
+
export interface PathMetadata {
|
|
46
|
+
name: string;
|
|
47
|
+
pathParameters: PathParameter[];
|
|
48
|
+
methods: Methods;
|
|
49
|
+
operationGroupName: string;
|
|
50
|
+
description: string;
|
|
51
|
+
}
|
|
52
|
+
export declare type Paths = Record<string, PathMetadata>;
|
|
53
|
+
export declare type PathParameter = {
|
|
54
|
+
name: string;
|
|
55
|
+
type: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
};
|
|
58
|
+
export interface OperationAnnotations {
|
|
59
|
+
isLongRunning?: boolean;
|
|
60
|
+
isPageable?: boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface RLCOptions {
|
|
63
|
+
includeShortcuts?: boolean;
|
|
64
|
+
multiClient?: boolean;
|
|
65
|
+
batch?: any[];
|
|
66
|
+
packageDetails?: PackageDetails;
|
|
67
|
+
addCredentials?: boolean;
|
|
68
|
+
credentialScopes?: string[];
|
|
69
|
+
credentialKeyHeaderName?: string;
|
|
70
|
+
generateMetadata?: boolean;
|
|
71
|
+
generateTest?: boolean;
|
|
72
|
+
generateSample?: boolean;
|
|
73
|
+
azureSdkForJs?: boolean;
|
|
74
|
+
azureOutputDirectory?: string;
|
|
75
|
+
isCadlTest?: boolean;
|
|
76
|
+
title?: string;
|
|
77
|
+
dependencyInfo?: DependencyInfo;
|
|
78
|
+
productDocLink?: string;
|
|
79
|
+
serviceInfo?: ServiceInfo;
|
|
80
|
+
azureArm?: boolean;
|
|
81
|
+
}
|
|
82
|
+
export interface ServiceInfo {
|
|
83
|
+
title?: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface DependencyInfo {
|
|
87
|
+
link: string;
|
|
88
|
+
description: string;
|
|
89
|
+
}
|
|
90
|
+
export declare enum ImportKind {
|
|
91
|
+
ResponseOutput = 0,
|
|
92
|
+
ParameterInput = 1
|
|
93
|
+
}
|
|
94
|
+
export interface File {
|
|
95
|
+
path: string;
|
|
96
|
+
content: string;
|
|
97
|
+
}
|
|
98
|
+
export declare enum SchemaContext {
|
|
99
|
+
/** Schema is used as an input to an operation. */
|
|
100
|
+
Input = "input",
|
|
101
|
+
/** Schema is used as an output from an operation. */
|
|
102
|
+
Output = "output",
|
|
103
|
+
/** Schema is used as an exception from an operation. */
|
|
104
|
+
Exception = "exception"
|
|
105
|
+
}
|
|
106
|
+
export interface Schema {
|
|
107
|
+
name: string;
|
|
108
|
+
type: string;
|
|
109
|
+
typeName?: string;
|
|
110
|
+
outputTypeName?: string;
|
|
111
|
+
description?: string;
|
|
112
|
+
required?: boolean;
|
|
113
|
+
default?: any;
|
|
114
|
+
readOnly?: boolean;
|
|
115
|
+
usage?: SchemaContext[];
|
|
116
|
+
}
|
|
117
|
+
export interface ObjectSchema extends Schema {
|
|
118
|
+
properties?: Record<string, Schema>;
|
|
119
|
+
discriminatorValue?: string;
|
|
120
|
+
discriminator?: Schema;
|
|
121
|
+
isPolyParent?: boolean;
|
|
122
|
+
children?: {
|
|
123
|
+
all?: ObjectSchema[];
|
|
124
|
+
immediate?: ObjectSchema[];
|
|
125
|
+
};
|
|
126
|
+
parents?: {
|
|
127
|
+
all?: ObjectSchema[];
|
|
128
|
+
immediate?: ObjectSchema[];
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export interface DictionarySchema extends Schema {
|
|
132
|
+
valueTypeName?: string;
|
|
133
|
+
outputValueTypeName?: string;
|
|
134
|
+
}
|
|
135
|
+
export interface Property extends Schema {
|
|
136
|
+
}
|
|
137
|
+
export interface Parameter extends Schema {
|
|
138
|
+
}
|
|
139
|
+
export interface PackageDetails {
|
|
140
|
+
name: string;
|
|
141
|
+
scopeName?: string;
|
|
142
|
+
nameWithoutScope?: string;
|
|
143
|
+
description?: string;
|
|
144
|
+
version: string;
|
|
145
|
+
}
|
|
146
|
+
export interface OperationParameter {
|
|
147
|
+
operationGroup: string;
|
|
148
|
+
operationName: string;
|
|
149
|
+
/**
|
|
150
|
+
* An operation with multiple request parameters means that
|
|
151
|
+
* the operation can get different values for content-type and each value
|
|
152
|
+
* may have a different type associated to it.
|
|
153
|
+
*/
|
|
154
|
+
parameters: ParameterMetadatas[];
|
|
155
|
+
}
|
|
156
|
+
export interface ParameterMetadatas {
|
|
157
|
+
parameters?: ParameterMetadata[];
|
|
158
|
+
body?: ParameterBodyMetadata;
|
|
159
|
+
}
|
|
160
|
+
export interface ParameterBodyMetadata {
|
|
161
|
+
isPartialBody?: boolean;
|
|
162
|
+
body?: ParameterBodySchema[];
|
|
163
|
+
}
|
|
164
|
+
export declare type ParameterBodySchema = Schema;
|
|
165
|
+
export interface ParameterMetadata {
|
|
166
|
+
type: "query" | "path" | "header";
|
|
167
|
+
name: string;
|
|
168
|
+
param: Schema;
|
|
169
|
+
}
|
|
170
|
+
export interface OperationResponse {
|
|
171
|
+
operationGroup: string;
|
|
172
|
+
operationName: string;
|
|
173
|
+
responses: ResponseMetadata[];
|
|
174
|
+
}
|
|
175
|
+
export interface ResponseMetadata {
|
|
176
|
+
statusCode: string;
|
|
177
|
+
description?: string;
|
|
178
|
+
headers?: ResponseHeaderSchema[];
|
|
179
|
+
body?: ResponseBodySchema;
|
|
180
|
+
}
|
|
181
|
+
export declare type ResponseHeaderSchema = Schema;
|
|
182
|
+
export declare type ResponseBodySchema = Schema;
|
|
183
|
+
export declare type ContentBuilder = {
|
|
184
|
+
(model: RLCModel): File | undefined;
|
|
185
|
+
(model: RLCModel, hasSampleGenerated?: boolean): File | undefined;
|
|
186
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const paginateContent = "\nimport {\n getPagedAsyncIterator,\n PagedAsyncIterableIterator,\n PagedResult\n} from \"@azure/core-paging\";\nimport {\n Client,\n createRestError,\n PathUncheckedResponse\n} from \"@azure-rest/core-client\";\n\n/**\n * Helper type to extract the type of an array\n */\nexport type GetArrayType<T> = T extends Array<infer TData> ? TData : never;\n\n/**\n * The type of a custom function that defines how to get a page and a link to the next one if any.\n */\nexport type GetPage<TPage> = (\n pageLink: string,\n maxPageSize?: number\n) => Promise<{\n page: TPage;\n nextPageLink?: string;\n}>;\n\n/**\n * Options for the paging helper\n */\nexport interface PagingOptions<TResponse> {\n /**\n * Custom function to extract pagination details for crating the PagedAsyncIterableIterator\n */\n customGetPage?: GetPage<PaginateReturn<TResponse>[]>\n}\n\n/**\n * Helper type to infer the Type of the paged elements from the response type\n * This type is generated based on the swagger information for x-ms-pageable\n * specifically on the itemName property which indicates the property of the response\n * where the page items are found. The default value is `value`.\n * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter\n */\n export type PaginateReturn<TResult> = TResult extends {{#each itemNames}}\n {\n \n body: { {{this}}?: infer TPage } \n \n} {{#if @last }}{{else}} | {{/if}}\n{{/each}}\n ? GetArrayType<TPage>\n : Array<unknown>;\n \n /**\n * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension\n * @param client - Client to use for sending the next page requests\n * @param initialResponse - Initial response containing the nextLink and current page of elements\n * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results\n * @returns - PagedAsyncIterableIterator to iterate the elements\n */\n export function paginate<TResponse extends PathUncheckedResponse>(\n client: Client,\n initialResponse: TResponse,\n options: PagingOptions<TResponse> = {}\n ): PagedAsyncIterableIterator<PaginateReturn<TResponse>> {\n // Extract element type from initial response\n type TElement = PaginateReturn<TResponse>;\n let firstRun = true;\n {{#if isComplexPaging}}\n // We need to check the response for success before trying to inspect it looking for\n // the properties to use for nextLink and itemName\n checkPagingRequest(initialResponse);\n const { itemName, nextLinkName } = getPaginationProperties(initialResponse);\n {{else}}\n const itemName = {{ quoteWrap itemNames }};\n const nextLinkName = {{quoteWrap nextLinkNames}};\n {{/if}}\n const { customGetPage } = options;\n const pagedResult: PagedResult<TElement[]> = {\n firstPageLink: \"\",\n getPage:\n typeof customGetPage === \"function\"\n ? customGetPage\n : async (pageLink: string) => {\n const result = firstRun\n ? initialResponse\n : await client.pathUnchecked(pageLink).get();\n firstRun = false;\n checkPagingRequest(result);\n const nextLink = getNextLink(result.body, nextLinkName);\n const values = getElements<TElement>(result.body, itemName);\n return {\n page: values,\n nextPageLink: nextLink\n };\n }\n };\n\n return getPagedAsyncIterator(pagedResult);\n}\n\n/**\n * Gets for the value of nextLink in the body\n */\nfunction getNextLink(body: unknown, nextLinkName?: string): string | undefined {\n if (!nextLinkName) {\n return undefined;\n }\n\n const nextLink = (body as Record<string, unknown>)[nextLinkName];\n\n if (typeof nextLink !== \"string\" && typeof nextLink !== \"undefined\") {\n throw new Error(\n `Body Property ${nextLinkName} should be a string or undefined`\n );\n }\n\n return nextLink;\n}\n\n/**\n * Gets the elements of the current request in the body.\n */\nfunction getElements<T = unknown>(body: unknown, itemName: string): T[] {\n const value = (body as Record<string, unknown>)[itemName] as T[];\n\n // value has to be an array according to the x-ms-pageable extension.\n // The fact that this must be an array is used above to calculate the\n // type of elements in the page in PaginateReturn\n if (!Array.isArray(value)) {\n throw new Error(\n `Couldn't paginate response\\n Body doesn't contain an array property with name: ${itemName}`\n );\n }\n\n return value ?? [];\n}\n\n/**\n * Checks if a request failed\n */\nfunction checkPagingRequest(response: PathUncheckedResponse): void {\n const Http2xxStatusCodes = [\n \"200\",\n \"201\",\n \"202\",\n \"203\",\n \"204\",\n \"205\",\n \"206\",\n \"207\",\n \"208\",\n \"226\"\n ];\n if (!Http2xxStatusCodes.includes(response.status)) {\n throw createRestError(\n `Pagination failed with unexpected statusCode ${response.status}`,\n response\n );\n }\n}\n\n{{#if isComplexPaging}}\n/**\n * Extracts the itemName and nextLinkName from the initial response to use them for pagination\n */\nfunction getPaginationProperties(initialResponse: PathUncheckedResponse) {\n // Build a set with the passed custom nextLinkNames\n const nextLinkNames = new Set([{{ quoteWrap nextLinkNames }}]);\n\n // Build a set with the passed custom set of itemNames\n const itemNames = new Set([{{ quoteWrap itemNames }}]);\n\n let nextLinkName: string | undefined;\n let itemName: string | undefined;\n\n for (const name of nextLinkNames) {\n const nextLink = (initialResponse.body as Record<string, unknown>)[\n name\n ] as string;\n if (nextLink) {\n nextLinkName = name;\n break;\n }\n }\n\n for (const name of itemNames) {\n const item = (initialResponse.body as Record<string, unknown>)[\n name\n ] as string;\n if (item) {\n itemName = name;\n break;\n }\n }\n\n if (!itemName) {\n throw new Error(\n `Couldn't paginate response\\n Body doesn't contain an array property with name: ${[\n ...itemNames\n ].join(\" OR \")}`\n );\n }\n\n return { itemName, nextLinkName };\n}\n{{/if}}\n";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const pollingContent = "\nimport { Client, HttpResponse } from \"@azure-rest/core-client\";\nimport {\n LongRunningOperation,\n LroEngine,\n LroEngineOptions,\n LroResponse,\n PollerLike,\n PollOperationState\n} from \"@azure/core-lro\";\n\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 function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}\n): PollerLike<PollOperationState<TResult>, TResult> {\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 return new LroEngine(poller, options);\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO engine knows about\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO engine can work with\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";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RLCModel } from "../interfaces.js";
|
|
2
|
+
export declare function buildEnvFile(model: RLCModel): {
|
|
3
|
+
path: string;
|
|
4
|
+
content: any;
|
|
5
|
+
} | undefined;
|
|
6
|
+
export declare function buildEnvBrowserFile(model: RLCModel): {
|
|
7
|
+
path: string;
|
|
8
|
+
content: any;
|
|
9
|
+
} | undefined;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const envContent = "\nimport * as dotenv from \"dotenv\";\n\ndotenv.config();\n";
|
|
2
|
+
export declare const envBrowserContent = "\nimport * as dotenv from \"dotenv\";\n\ndotenv.config();\n";
|
|
3
|
+
export declare const karmaConfig = "\n// https://github.com/karma-runner/karma-chrome-launcher\nprocess.env.CHROME_BIN = require(\"puppeteer\").executablePath();\nrequire(\"dotenv\").config();\nconst { relativeRecordingsPath } = require(\"@azure-tools/test-recorder\");\nprocess.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();\n\nmodule.exports = function (config) {\n config.set({\n // base path that will be used to resolve all patterns (eg. files, exclude)\n basePath: \"./\",\n\n // frameworks to use\n // available frameworks: https://npmjs.org/browse/keyword/karma-adapter\n frameworks: [\"source-map-support\", \"mocha\"],\n\n plugins: [\n \"karma-mocha\",\n \"karma-mocha-reporter\",\n \"karma-chrome-launcher\",\n \"karma-edge-launcher\",\n \"karma-firefox-launcher\",\n \"karma-ie-launcher\",\n \"karma-env-preprocessor\",\n \"karma-coverage\",\n \"karma-sourcemap-loader\",\n \"karma-junit-reporter\",\n \"karma-source-map-support\",\n ],\n\n // list of files / patterns to load in the browser\n files: [\n \"dist-test/index.browser.js\",\n { pattern: \"dist-test/index.browser.js.map\", type: \"html\", included: false, served: true },\n ],\n\n // list of files / patterns to exclude\n exclude: [],\n\n // preprocess matching files before serving them to the browser\n // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor\n preprocessors: {\n \"**/*.js\": [\"sourcemap\", \"env\"],\n // IMPORTANT: COMMENT following line if you want to debug in your browsers!!\n // Preprocess source file to calculate code coverage, however this will make source file unreadable\n // \"dist-test/index.js\": [\"coverage\"]\n },\n\n envPreprocessor: [\n \"TEST_MODE\",\n \"ENDPOINT\",\n \"AZURE_CLIENT_SECRET\",\n \"AZURE_CLIENT_ID\",\n \"AZURE_TENANT_ID\",\n \"SUBSCRIPTION_ID\",\n ],\n\n // test results reporter to use\n // possible values: 'dots', 'progress'\n // available reporters: https://npmjs.org/browse/keyword/karma-reporter\n reporters: [\"mocha\", \"coverage\", \"junit\"],\n\n coverageReporter: {\n // specify a common output directory\n dir: \"coverage-browser/\",\n reporters: [\n { type: \"json\", subdir: \".\", file: \"coverage.json\" },\n { type: \"lcovonly\", subdir: \".\", file: \"lcov.info\" },\n { type: \"html\", subdir: \"html\" },\n { type: \"cobertura\", subdir: \".\", file: \"cobertura-coverage.xml\" },\n ],\n },\n\n junitReporter: {\n outputDir: \"\", // results will be saved as $outputDir/$browserName.xml\n outputFile: \"test-results.browser.xml\", // if included, results will be saved as $outputDir/$browserName/$outputFile\n suite: \"\", // suite will become the package name attribute in xml testsuite element\n useBrowserName: false, // add browser name to report and classes names\n nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element\n classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element\n properties: {}, // key value pair of properties to add to the <properties> section of the report\n },\n\n // web server port\n port: 9876,\n\n // enable / disable colors in the output (reporters and logs)\n colors: true,\n\n // level of logging\n // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG\n logLevel: config.LOG_INFO,\n\n // enable / disable watching file and executing tests whenever any file changes\n autoWatch: false,\n\n // --no-sandbox allows our tests to run in Linux without having to change the system.\n // --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex.\n browsers: [\"ChromeHeadlessNoSandbox\"],\n customLaunchers: {\n ChromeHeadlessNoSandbox: {\n base: \"ChromeHeadless\",\n flags: [\"--no-sandbox\", \"--disable-web-security\"],\n },\n },\n\n // Continuous Integration mode\n // if true, Karma captures browsers, runs the tests and exits\n singleRun: false,\n\n // Concurrency level\n // how many browser should be started simultaneous\n concurrency: 1,\n\n browserNoActivityTimeout: 60000000,\n browserDisconnectTimeout: 10000,\n browserDisconnectTolerance: 3,\n\n client: {\n mocha: {\n // change Karma's debug.html to the mocha web reporter\n reporter: \"html\",\n timeout: \"600000\",\n },\n },\n });\n};\n";
|
|
4
|
+
export declare const recordedClientContent = "\nimport { Context } from \"mocha\";\nimport { Recorder, RecorderStartOptions } from \"@azure-tools/test-recorder\";\nimport \"./env\";\n\nconst envSetupForPlayback: Record<string, string> = {\n ENDPOINT: \"https://endpoint\",\n AZURE_CLIENT_ID: \"azure_client_id\",\n AZURE_CLIENT_SECRET: \"azure_client_secret\",\n AZURE_TENANT_ID: \"88888888-8888-8888-8888-888888888888\",\n SUBSCRIPTION_ID: \"azure_subscription_id\"\n};\n\nconst recorderEnvSetup: RecorderStartOptions = {\n envSetupForPlayback\n};\n\n/**\n* creates the recorder and reads the environment variables from the `.env` file.\n* Should be called first in the test suite to make sure environment variables are\n* read before they are being used.\n*/\nexport async function createRecorder(context: Context): Promise<Recorder> {\n const recorder = new Recorder(context.currentTest);\n await recorder.start(recorderEnvSetup);\n return recorder;\n}\n";
|
|
5
|
+
export declare const sampleTestContent = "\nimport { Recorder } from \"@azure-tools/test-recorder\";\nimport { assert } from \"chai\";\nimport { createRecorder } from \"./utils/recordedClient\";\nimport { Context } from \"mocha\";\n\ndescribe(\"My test\", () => {\n let recorder: Recorder;\n\n beforeEach(async function(this: Context) {\n recorder = await createRecorder(this);\n });\n\n afterEach(async function() {\n await recorder.stop();\n });\n\n it(\"sample test\", async function() {\n assert.equal(1, 1);\n });\n});\n";
|