@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,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildReadmeFile = void 0;
|
|
4
|
+
// @ts-ignore: to fix the handlebars issue
|
|
5
|
+
const handlebars_1 = require("handlebars");
|
|
6
|
+
const nameUtils_js_1 = require("../helpers/nameUtils.js");
|
|
7
|
+
const readmeTemplate = `# {{ clientDescriptiveName }} library for JavaScript
|
|
8
|
+
|
|
9
|
+
{{ description }}
|
|
10
|
+
|
|
11
|
+
{{#if azureArm}}
|
|
12
|
+
**If you are not familiar with our REST client, please spend 5 minutes to take a look at {{#if serviceDocURL}}[the service's documentation]({{ serviceDocURL }}) and {{/if}}our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library, the REST client provides a light-weighted & developer friendly way to call azure rest api
|
|
13
|
+
{{else}}
|
|
14
|
+
**Please rely heavily on {{#if serviceDocURL}}[the service's documentation]({{ serviceDocURL }}) and {{/if}}our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**
|
|
15
|
+
{{/if}}
|
|
16
|
+
|
|
17
|
+
Key links:
|
|
18
|
+
|
|
19
|
+
{{#if packageSourceURL}}
|
|
20
|
+
- [Source code]({{ packageSourceURL }})
|
|
21
|
+
{{/if}}
|
|
22
|
+
{{#if packageNPMURL}}
|
|
23
|
+
- [Package (NPM)]({{ packageNPMURL }})
|
|
24
|
+
{{/if}}
|
|
25
|
+
{{#if apiRefURL}}
|
|
26
|
+
- [API reference documentation]({{ apiRefURL }})
|
|
27
|
+
{{/if}}
|
|
28
|
+
{{#if serviceDocURL}}
|
|
29
|
+
- [Product documentation]({{ serviceDocURL }})
|
|
30
|
+
{{/if}}
|
|
31
|
+
{{#if samplesURL}}
|
|
32
|
+
- [Samples]({{ samplesURL }})
|
|
33
|
+
{{/if}}
|
|
34
|
+
|
|
35
|
+
## Getting started
|
|
36
|
+
|
|
37
|
+
### Currently supported environments
|
|
38
|
+
|
|
39
|
+
- Node.js version 14.x.x or higher
|
|
40
|
+
|
|
41
|
+
### Prerequisites
|
|
42
|
+
|
|
43
|
+
- You must have an [Azure subscription](https://azure.microsoft.com/free/){{#if dependencyLink}} and follow [these]({{ dependencyLink }}) instructions{{/if}} to use this package.
|
|
44
|
+
|
|
45
|
+
### Install the \`{{ clientPackageName }}\` package
|
|
46
|
+
|
|
47
|
+
Install the {{ clientDescriptiveName }} REST client library for JavaScript with \`npm\`:
|
|
48
|
+
|
|
49
|
+
\`\`\`bash
|
|
50
|
+
npm install {{ clientPackageName }}
|
|
51
|
+
\`\`\`
|
|
52
|
+
|
|
53
|
+
### Create and authenticate a \`{{ clientClassName }}\`
|
|
54
|
+
|
|
55
|
+
To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
|
|
56
|
+
provide an instance of the desired credential type obtained from the
|
|
57
|
+
[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.
|
|
58
|
+
|
|
59
|
+
To authenticate with AAD, you must first \`npm\` install [\`@azure/identity\`](https://www.npmjs.com/package/@azure/identity) {{#if dependencyLink}}and
|
|
60
|
+
[{{dependencyDescription }}]({{ dependencyLink }}){{/if}}
|
|
61
|
+
|
|
62
|
+
After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from \`@azure/identity\` to use.
|
|
63
|
+
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
|
|
64
|
+
can be used to authenticate the client.
|
|
65
|
+
|
|
66
|
+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
|
|
67
|
+
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
|
|
68
|
+
|
|
69
|
+
## Troubleshooting
|
|
70
|
+
|
|
71
|
+
### Logging
|
|
72
|
+
|
|
73
|
+
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the \`AZURE_LOG_LEVEL\` environment variable to \`info\`. Alternatively, logging can be enabled at runtime by calling \`setLogLevel\` in the \`@azure/logger\`:
|
|
74
|
+
|
|
75
|
+
\`\`\`javascript
|
|
76
|
+
import { setLogLevel } from "@azure/logger";
|
|
77
|
+
|
|
78
|
+
setLogLevel("info");
|
|
79
|
+
\`\`\`
|
|
80
|
+
|
|
81
|
+
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
|
|
82
|
+
`;
|
|
83
|
+
function buildReadmeFile(model) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
const generateMetadata = Boolean((_a = model.options) === null || _a === void 0 ? void 0 : _a.generateMetadata);
|
|
86
|
+
if (!generateMetadata) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const metadata = (_b = createMetadata(model)) !== null && _b !== void 0 ? _b : {};
|
|
90
|
+
const readmeFileContents = handlebars_1.default.compile(readmeTemplate, { noEscape: true });
|
|
91
|
+
return {
|
|
92
|
+
path: "README.md",
|
|
93
|
+
content: readmeFileContents(metadata)
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
exports.buildReadmeFile = buildReadmeFile;
|
|
97
|
+
/**
|
|
98
|
+
* Returns meta data information about the service, the package, and the client.
|
|
99
|
+
* @param codeModel - include the client details
|
|
100
|
+
* @returns inferred metadata about the service, the package, and the client
|
|
101
|
+
*/
|
|
102
|
+
function createMetadata(model) {
|
|
103
|
+
var _a;
|
|
104
|
+
if (!model.options || !model.options.packageDetails) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// const packageDetails = model.options.packageDetails;
|
|
108
|
+
const { packageDetails, azureOutputDirectory, productDocLink, dependencyInfo, multiClient, batch, serviceInfo } = model.options;
|
|
109
|
+
const azureHuh = (packageDetails === null || packageDetails === void 0 ? void 0 : packageDetails.scopeName) === "azure" ||
|
|
110
|
+
(packageDetails === null || packageDetails === void 0 ? void 0 : packageDetails.scopeName) === "azure-rest";
|
|
111
|
+
const repoURL = "https://github.com/Azure/azure-sdk-for-js";
|
|
112
|
+
const relativePackageSourcePath = azureOutputDirectory;
|
|
113
|
+
const packageSourceURL = relativePackageSourcePath &&
|
|
114
|
+
repoURL &&
|
|
115
|
+
`${repoURL}/tree/main/${relativePackageSourcePath}`;
|
|
116
|
+
const clientPackageName = packageDetails === null || packageDetails === void 0 ? void 0 : packageDetails.name;
|
|
117
|
+
const clientClassName = getClientName(model);
|
|
118
|
+
const serviceName = getServiceName(model);
|
|
119
|
+
var apiRefUrlQueryParameter = "";
|
|
120
|
+
if (packageDetails === null || packageDetails === void 0 ? void 0 : packageDetails.version.includes("beta")) {
|
|
121
|
+
apiRefUrlQueryParameter = "?view=azure-node-preview";
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
serviceName,
|
|
125
|
+
clientClassName,
|
|
126
|
+
clientPackageName: clientPackageName,
|
|
127
|
+
clientDescriptiveName: `${serviceName} REST client`,
|
|
128
|
+
description: (_a = serviceInfo === null || serviceInfo === void 0 ? void 0 : serviceInfo.description) !== null && _a !== void 0 ? _a : packageDetails.description,
|
|
129
|
+
serviceDocURL: productDocLink,
|
|
130
|
+
packageSourceURL: packageSourceURL,
|
|
131
|
+
packageNPMURL: `https://www.npmjs.com/package/${clientPackageName}`,
|
|
132
|
+
samplesURL: packageSourceURL && `${packageSourceURL}/samples`,
|
|
133
|
+
apiRefURL: azureHuh
|
|
134
|
+
? `https://docs.microsoft.com/javascript/api/${clientPackageName}${apiRefUrlQueryParameter}`
|
|
135
|
+
: undefined,
|
|
136
|
+
dependencyDescription: dependencyInfo === null || dependencyInfo === void 0 ? void 0 : dependencyInfo.description,
|
|
137
|
+
dependencyLink: dependencyInfo === null || dependencyInfo === void 0 ? void 0 : dependencyInfo.link,
|
|
138
|
+
hasMultiClients: multiClient && batch && batch.length > 1,
|
|
139
|
+
azureArm: Boolean(model.options.azureArm)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function getServiceName(model) {
|
|
143
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
144
|
+
const azureHuh = ((_b = (_a = model === null || model === void 0 ? void 0 : model.options) === null || _a === void 0 ? void 0 : _a.packageDetails) === null || _b === void 0 ? void 0 : _b.scopeName) === "azure" ||
|
|
145
|
+
((_d = (_c = model === null || model === void 0 ? void 0 : model.options) === null || _c === void 0 ? void 0 : _c.packageDetails) === null || _d === void 0 ? void 0 : _d.scopeName) === "azure-rest";
|
|
146
|
+
const libraryName = model.libraryName;
|
|
147
|
+
const serviceTitle = (_g = (_f = (_e = model.options) === null || _e === void 0 ? void 0 : _e.serviceInfo) === null || _f === void 0 ? void 0 : _f.title) !== null && _g !== void 0 ? _g : model.libraryName;
|
|
148
|
+
const batch = (_h = model === null || model === void 0 ? void 0 : model.options) === null || _h === void 0 ? void 0 : _h.batch, packageDetails = (_j = model === null || model === void 0 ? void 0 : model.options) === null || _j === void 0 ? void 0 : _j.packageDetails;
|
|
149
|
+
let simpleServiceName = batch && batch.length > 1
|
|
150
|
+
? (0, nameUtils_js_1.normalizeName)(packageDetails.nameWithoutScope || "", nameUtils_js_1.NameType.Class)
|
|
151
|
+
: (0, nameUtils_js_1.normalizeName)(serviceTitle, nameUtils_js_1.NameType.Class);
|
|
152
|
+
simpleServiceName =
|
|
153
|
+
/**
|
|
154
|
+
* It is a required convention in Azure swaggers for their titles to end with
|
|
155
|
+
* "Client".
|
|
156
|
+
*/
|
|
157
|
+
(_s = (_q = (_o = (_l = (_k = serviceTitle.match(/(.*) Client/)) === null || _k === void 0 ? void 0 : _k[1]) !== null && _l !== void 0 ? _l : (_m = serviceTitle.match(/(.*)Client/)) === null || _m === void 0 ? void 0 : _m[1]) !== null && _o !== void 0 ? _o : (_p = libraryName.match(/(.*)Client/)) === null || _p === void 0 ? void 0 : _p[1]) !== null && _q !== void 0 ? _q : (_r = serviceTitle.match(/(.*) Service/)) === null || _r === void 0 ? void 0 : _r[1]) !== null && _s !== void 0 ? _s : simpleServiceName;
|
|
158
|
+
return azureHuh
|
|
159
|
+
? simpleServiceName.startsWith("Azure")
|
|
160
|
+
? simpleServiceName
|
|
161
|
+
: `Azure ${simpleServiceName}`
|
|
162
|
+
: simpleServiceName;
|
|
163
|
+
}
|
|
164
|
+
function getClientName(model) {
|
|
165
|
+
const clientName = model.libraryName;
|
|
166
|
+
return clientName.endsWith("Client")
|
|
167
|
+
? `${clientName}`
|
|
168
|
+
: `${clientName}Client`;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=buildReadmeFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildReadmeFile.js","sourceRoot":"","sources":["../../src/metadata/buildReadmeFile.ts"],"names":[],"mappings":";;;AACA,0CAA0C;AAC1C,2CAA6B;AAC7B,0DAAkE;AAElE,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2EtB,CAAC;AA2CF,SAAgB,eAAe,CAAC,KAAe;;IAC7C,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAA,KAAK,CAAC,OAAO,0CAAE,gBAAgB,CAAC,CAAC;IAClE,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO;KACR;IAED,MAAM,QAAQ,GAAG,MAAA,cAAc,CAAC,KAAK,CAAC,mCAAI,EAAE,CAAC;IAC7C,MAAM,kB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GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,0CAAE,cAAe,CAAC;IACnD,IAAI,iBAAiB,GACnB,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QACvB,CAAC,CAAC,IAAA,4BAAa,EAAC,cAAc,CAAC,gBAAgB,IAAI,EAAE,EAAE,uBAAQ,CAAC,KAAK,CAAC;QACtE,CAAC,CAAC,IAAA,4BAAa,EAAC,YAAY,EAAE,uBAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,iBAAiB;QACf;;;WAGG;QACH,MAAA,MAAA,MAAA,MAAA,MAAA,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,0CAAG,CAAC,CAAC,mCACtC,MAAA,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,0CAAG,CAAC,CAAC,mCACrC,MAAA,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,0CAAG,CAAC,CAAC,mCACpC,MAAA,YAAY,CAAC,KAAK,CAAC,cAAc,CAAC,0CAAG,CAAC,CAAC,mCACvC,iBAAiB,CAAC;IAEpB,OAAO,QAAQ;QACb,CAAC,CAAC,iBAAiB,CAAC,UAAU,CAAC,OAAO,CAAC;YACrC,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,SAAS,iBAAiB,EAAE;QAChC,CAAC,CAAC,iBAAiB,CAAC;AACxB,CAAC;AAED,SAAS,aAAa,CAAC,KAAe;IACpC,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC;IACrC,OAAO,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAClC,CAAC,CAAC,GAAG,UAAU,EAAE;QACjB,CAAC,CAAC,GAAG,UAAU,QAAQ,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.buildRollupConfig = void 0;
|
|
6
|
+
const ts_morph_1 = require("ts-morph");
|
|
7
|
+
function buildRollupConfig(model) {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const generateMetadata = Boolean((_a = model.options) === null || _a === void 0 ? void 0 : _a.generateMetadata), azureSdkForJs = Boolean((_b = model.options) === null || _b === void 0 ? void 0 : _b.azureSdkForJs);
|
|
10
|
+
// when it's generating rlc codes, only generate rollup config in codegen test
|
|
11
|
+
if (!generateMetadata || azureSdkForJs) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const project = new ts_morph_1.Project();
|
|
15
|
+
const filePath = "rollup.config.js";
|
|
16
|
+
const rollupFile = project.createSourceFile(filePath, undefined, {
|
|
17
|
+
overwrite: true
|
|
18
|
+
});
|
|
19
|
+
rollupFile.addStatements(`import nodeResolve from "@rollup/plugin-node-resolve";
|
|
20
|
+
import cjs from "@rollup/plugin-commonjs";
|
|
21
|
+
import sourcemaps from "rollup-plugin-sourcemaps";
|
|
22
|
+
import multiEntry from "@rollup/plugin-multi-entry";
|
|
23
|
+
import json from "@rollup/plugin-json";
|
|
24
|
+
|
|
25
|
+
import nodeBuiltins from "builtin-modules";
|
|
26
|
+
|
|
27
|
+
// #region Warning Handler
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A function that can determine whether a rollup warning should be ignored. If
|
|
31
|
+
* the function returns \`true\`, then the warning will not be displayed.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
function ignoreNiseSinonEval(warning) {
|
|
35
|
+
return (
|
|
36
|
+
warning.code === "EVAL" &&
|
|
37
|
+
(warning.id && ((warning.id.includes("node_modules/nise")) ||
|
|
38
|
+
warning.id.includes("node_modules/sinon")) === true)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function ignoreChaiCircularDependency(warning) {
|
|
43
|
+
return (
|
|
44
|
+
warning.code === "CIRCULAR_DEPENDENCY" &&
|
|
45
|
+
(warning.importer && warning.importer.includes("node_modules/chai") === true)
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const warningInhibitors = [
|
|
50
|
+
ignoreChaiCircularDependency,
|
|
51
|
+
ignoreNiseSinonEval
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Construct a warning handler for the shared rollup configuration
|
|
56
|
+
* that ignores certain warnings that are not relevant to testing.
|
|
57
|
+
*/
|
|
58
|
+
function makeOnWarnForTesting() {
|
|
59
|
+
return (warning, warn) => {
|
|
60
|
+
// If every inhibitor returns false (i.e. no inhibitors), then show the warning
|
|
61
|
+
if (warningInhibitors.every(inhib => !inhib(warning))) {
|
|
62
|
+
warn(warning);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// #endregion
|
|
68
|
+
|
|
69
|
+
function makeBrowserTestConfig() {
|
|
70
|
+
const config = {
|
|
71
|
+
input: {
|
|
72
|
+
include: ["dist-esm/test/**/*.spec.js"],
|
|
73
|
+
exclude: ["dist-esm/test/**/node/**"]
|
|
74
|
+
},
|
|
75
|
+
output: {
|
|
76
|
+
file: \`dist-test/index.browser.js\`,
|
|
77
|
+
format: "umd",
|
|
78
|
+
sourcemap: true
|
|
79
|
+
},
|
|
80
|
+
preserveSymlinks: false,
|
|
81
|
+
plugins: [
|
|
82
|
+
multiEntry({ exports: false }),
|
|
83
|
+
nodeResolve({
|
|
84
|
+
mainFields: ["module", "browser"]
|
|
85
|
+
}),
|
|
86
|
+
cjs(),
|
|
87
|
+
json(),
|
|
88
|
+
sourcemaps()
|
|
89
|
+
//viz({ filename: "dist-test/browser-stats.html", sourcemap: true })
|
|
90
|
+
],
|
|
91
|
+
onwarn: makeOnWarnForTesting(),
|
|
92
|
+
// Disable tree-shaking of test code. In rollup-plugin-node-resolve@5.0.0,
|
|
93
|
+
// rollup started respecting the "sideEffects" field in package.json. Since
|
|
94
|
+
// our package.json sets "sideEffects=false", this also applies to test
|
|
95
|
+
// code, which causes all tests to be removed by tree-shaking.
|
|
96
|
+
treeshake: false
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return config;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const defaultConfigurationOptions = {
|
|
103
|
+
disableBrowserBundle: false
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export function makeConfig(
|
|
107
|
+
pkg,
|
|
108
|
+
options
|
|
109
|
+
) {
|
|
110
|
+
options = {
|
|
111
|
+
...defaultConfigurationOptions,
|
|
112
|
+
...(options || {})
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const baseConfig = {
|
|
116
|
+
// Use the package's module field if it has one
|
|
117
|
+
input: pkg["module"] || "dist-esm/src/index.js",
|
|
118
|
+
external: [
|
|
119
|
+
...nodeBuiltins,
|
|
120
|
+
...Object.keys(pkg.dependencies),
|
|
121
|
+
...Object.keys(pkg.devDependencies)
|
|
122
|
+
],
|
|
123
|
+
output: { file: "dist/index.js", format: "cjs", sourcemap: true },
|
|
124
|
+
preserveSymlinks: false,
|
|
125
|
+
plugins: [sourcemaps(), nodeResolve()]
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const config = [baseConfig];
|
|
129
|
+
|
|
130
|
+
if (!options.disableBrowserBundle) {
|
|
131
|
+
config.push(makeBrowserTestConfig());
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return config;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export default makeConfig(require("./package.json"));`);
|
|
138
|
+
return {
|
|
139
|
+
path: filePath,
|
|
140
|
+
content: rollupFile.getFullText()
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
exports.buildRollupConfig = buildRollupConfig;
|
|
144
|
+
//# sourceMappingURL=buildRollupConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildRollupConfig.js","sourceRoot":"","sources":["../../src/metadata/buildRollupConfig.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,uCAAmC;AAGnC,SAAgB,iBAAiB,CAAC,KAAe;;IAC/C,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAA,KAAK,CAAC,OAAO,0CAAE,gBAAgB,CAAC,EAC/D,aAAa,GAAG,OAAO,CAAC,MAAA,KAAK,CAAC,OAAO,0CAAE,aAAa,CAAC,CAAC;IACxD,8EAA8E;IAC9E,IAAI,CAAC,gBAAgB,IAAI,aAAa,EAAE;QACtC,OAAO;KACR;IAED,MAAM,OAAO,GAAG,IAAI,kBAAO,EAAE,CAAC;IAC9B,MAAM,QAAQ,GAAG,kBAAkB,CAAC;IACpC,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE;QAC/D,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;IAEH,UAAU,CAAC,aAAa,CACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0DAsHsD,CACvD,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,UAAU,CAAC,WAAW,EAAE;KAClC,CAAC;AACJ,CAAC;AA5ID,8CA4IC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.buildTsConfig = void 0;
|
|
6
|
+
const ts_morph_1 = require("ts-morph");
|
|
7
|
+
const restLevelTsConfigInAzureSdkForJs = {
|
|
8
|
+
extends: "../../../tsconfig.package",
|
|
9
|
+
compilerOptions: {
|
|
10
|
+
outDir: "./dist-esm",
|
|
11
|
+
declarationDir: "./types"
|
|
12
|
+
},
|
|
13
|
+
include: ["src/**/*.ts"]
|
|
14
|
+
};
|
|
15
|
+
const restLevelTsConfigNotInAzureSdkForJs = {
|
|
16
|
+
compilerOptions: {
|
|
17
|
+
target: "ES2017",
|
|
18
|
+
module: "es6",
|
|
19
|
+
lib: [],
|
|
20
|
+
declaration: true,
|
|
21
|
+
declarationMap: true,
|
|
22
|
+
inlineSources: true,
|
|
23
|
+
sourceMap: true,
|
|
24
|
+
importHelpers: true,
|
|
25
|
+
strict: true,
|
|
26
|
+
alwaysStrict: true,
|
|
27
|
+
noUnusedLocals: true,
|
|
28
|
+
noUnusedParameters: true,
|
|
29
|
+
noImplicitReturns: true,
|
|
30
|
+
noFallthroughCasesInSwitch: true,
|
|
31
|
+
forceConsistentCasingInFileNames: true,
|
|
32
|
+
moduleResolution: "node",
|
|
33
|
+
allowSyntheticDefaultImports: true,
|
|
34
|
+
esModuleInterop: true,
|
|
35
|
+
outDir: "./dist-esm",
|
|
36
|
+
declarationDir: "./types"
|
|
37
|
+
},
|
|
38
|
+
include: ["./src/**/*.ts"]
|
|
39
|
+
};
|
|
40
|
+
function buildTsConfig(model, hasSamplesGenerated = false) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const generateMetadata = Boolean((_a = model.options) === null || _a === void 0 ? void 0 : _a.generateMetadata);
|
|
43
|
+
if (!generateMetadata) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const { generateTest, packageDetails, generateSample, azureSdkForJs } = model.options || {};
|
|
47
|
+
const clientPackageName = (_b = packageDetails === null || packageDetails === void 0 ? void 0 : packageDetails.name) !== null && _b !== void 0 ? _b : "";
|
|
48
|
+
const project = new ts_morph_1.Project();
|
|
49
|
+
const restLevelTsConfig = azureSdkForJs
|
|
50
|
+
? restLevelTsConfigInAzureSdkForJs
|
|
51
|
+
: restLevelTsConfigNotInAzureSdkForJs;
|
|
52
|
+
if (generateTest) {
|
|
53
|
+
restLevelTsConfig.include.push("./test/**/*.ts");
|
|
54
|
+
}
|
|
55
|
+
if (generateSample && hasSamplesGenerated) {
|
|
56
|
+
restLevelTsConfig.include.push("samples-dev/**/*.ts");
|
|
57
|
+
restLevelTsConfig.compilerOptions["paths"] = {};
|
|
58
|
+
restLevelTsConfig.compilerOptions["paths"][clientPackageName] = [
|
|
59
|
+
"./src/index"
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
const filePath = "tsconfig.json";
|
|
63
|
+
const configFile = project.createSourceFile(filePath, JSON.stringify(restLevelTsConfig), {
|
|
64
|
+
overwrite: true
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
path: filePath,
|
|
68
|
+
content: configFile.getFullText()
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
exports.buildTsConfig = buildTsConfig;
|
|
72
|
+
//# sourceMappingURL=buildTsConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildTsConfig.js","sourceRoot":"","sources":["../../src/metadata/buildTsConfig.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,uCAAmC;AAGnC,MAAM,gCAAgC,GAAwB;IAC5D,OAAO,EAAE,2BAA2B;IACpC,eAAe,EAAE;QACf,MAAM,EAAE,YAAY;QACpB,cAAc,EAAE,SAAS;KAC1B;IACD,OAAO,EAAE,CAAC,aAAa,CAAC;CACzB,CAAC;AAEF,MAAM,mCAAmC,GAAwB;IAC/D,eAAe,EAAE;QACf,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,EAAE;QACP,WAAW,EAAE,IAAI;QACjB,cAAc,EAAE,IAAI;QACpB,aAAa,EAAE,IAAI;QACnB,SAAS,EAAE,IAAI;QACf,aAAa,EAAE,IAAI;QACnB,MAAM,EAAE,IAAI;QACZ,YAAY,EAAE,IAAI;QAClB,cAAc,EAAE,IAAI;QACpB,kBAAkB,EAAE,IAAI;QACxB,iBAAiB,EAAE,IAAI;QACvB,0BAA0B,EAAE,IAAI;QAChC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iB,CAAC,EACjC;QACE,SAAS,EAAE,IAAI;KAChB,CACF,CAAC;IACF,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,UAAU,CAAC,WAAW,EAAE;KAClC,CAAC;AACJ,CAAC;AArCD,sCAqCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"@azure-tools/rlc-common","version":"1.0.0-beta.1","description":"","type":"commonjs","main":"dist/index.js","module":"dist-esm/index.js","exports":{".":{"types":"./types/index.d.ts","require":"./dist/index.js","import":"./dist-esm/index.js"}},"types":"./types/index.d.ts","scripts":{"build":"rimraf dist/* dist-esm/* types/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node publishPackage.js","build:cjs":"rimraf dist/* dist-esm/* types/* && tsc -p tsconfig-cjs.json && node publishPackage.js","build:esm":"rimraf dist/* dist-esm/* types/* && tsc -p tsconfig.json && node publishPackage.js","test":"echo \"Error: no test specified\" && exit 1"},"keywords":[],"author":"","license":"ISC","dependencies":{"ts-morph":"^15.1.0","lodash":"^4.17.21","handlebars":"^4.7.7"},"devDependencies":{"@types/node":"^18.0.0","prettier":"~2.7.1","typescript":"^4.6.3","rimraf":"^3.0.2","@types/lodash":"^4.14.182","fs-extra":"^10.0.0","@types/fs-extra":"^8.1.0","ts-node":"^10.7.0"}}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paginateContent = void 0;
|
|
4
|
+
exports.paginateContent = `
|
|
5
|
+
import {
|
|
6
|
+
getPagedAsyncIterator,
|
|
7
|
+
PagedAsyncIterableIterator,
|
|
8
|
+
PagedResult
|
|
9
|
+
} from "@azure/core-paging";
|
|
10
|
+
import {
|
|
11
|
+
Client,
|
|
12
|
+
createRestError,
|
|
13
|
+
PathUncheckedResponse
|
|
14
|
+
} from "@azure-rest/core-client";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Helper type to extract the type of an array
|
|
18
|
+
*/
|
|
19
|
+
export type GetArrayType<T> = T extends Array<infer TData> ? TData : never;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The type of a custom function that defines how to get a page and a link to the next one if any.
|
|
23
|
+
*/
|
|
24
|
+
export type GetPage<TPage> = (
|
|
25
|
+
pageLink: string,
|
|
26
|
+
maxPageSize?: number
|
|
27
|
+
) => Promise<{
|
|
28
|
+
page: TPage;
|
|
29
|
+
nextPageLink?: string;
|
|
30
|
+
}>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Options for the paging helper
|
|
34
|
+
*/
|
|
35
|
+
export interface PagingOptions<TResponse> {
|
|
36
|
+
/**
|
|
37
|
+
* Custom function to extract pagination details for crating the PagedAsyncIterableIterator
|
|
38
|
+
*/
|
|
39
|
+
customGetPage?: GetPage<PaginateReturn<TResponse>[]>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Helper type to infer the Type of the paged elements from the response type
|
|
44
|
+
* This type is generated based on the swagger information for x-ms-pageable
|
|
45
|
+
* specifically on the itemName property which indicates the property of the response
|
|
46
|
+
* where the page items are found. The default value is \`value\`.
|
|
47
|
+
* This type will allow us to provide strongly typed Iterator based on the response we get as second parameter
|
|
48
|
+
*/
|
|
49
|
+
export type PaginateReturn<TResult> = TResult extends {{#each itemNames}}
|
|
50
|
+
{
|
|
51
|
+
|
|
52
|
+
body: { {{this}}?: infer TPage }
|
|
53
|
+
|
|
54
|
+
} {{#if @last }}{{else}} | {{/if}}
|
|
55
|
+
{{/each}}
|
|
56
|
+
? GetArrayType<TPage>
|
|
57
|
+
: Array<unknown>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Helper to paginate results from an initial response that follows the specification of Autorest \`x-ms-pageable\` extension
|
|
61
|
+
* @param client - Client to use for sending the next page requests
|
|
62
|
+
* @param initialResponse - Initial response containing the nextLink and current page of elements
|
|
63
|
+
* @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results
|
|
64
|
+
* @returns - PagedAsyncIterableIterator to iterate the elements
|
|
65
|
+
*/
|
|
66
|
+
export function paginate<TResponse extends PathUncheckedResponse>(
|
|
67
|
+
client: Client,
|
|
68
|
+
initialResponse: TResponse,
|
|
69
|
+
options: PagingOptions<TResponse> = {}
|
|
70
|
+
): PagedAsyncIterableIterator<PaginateReturn<TResponse>> {
|
|
71
|
+
// Extract element type from initial response
|
|
72
|
+
type TElement = PaginateReturn<TResponse>;
|
|
73
|
+
let firstRun = true;
|
|
74
|
+
{{#if isComplexPaging}}
|
|
75
|
+
// We need to check the response for success before trying to inspect it looking for
|
|
76
|
+
// the properties to use for nextLink and itemName
|
|
77
|
+
checkPagingRequest(initialResponse);
|
|
78
|
+
const { itemName, nextLinkName } = getPaginationProperties(initialResponse);
|
|
79
|
+
{{else}}
|
|
80
|
+
const itemName = {{ quoteWrap itemNames }};
|
|
81
|
+
const nextLinkName = {{quoteWrap nextLinkNames}};
|
|
82
|
+
{{/if}}
|
|
83
|
+
const { customGetPage } = options;
|
|
84
|
+
const pagedResult: PagedResult<TElement[]> = {
|
|
85
|
+
firstPageLink: "",
|
|
86
|
+
getPage:
|
|
87
|
+
typeof customGetPage === "function"
|
|
88
|
+
? customGetPage
|
|
89
|
+
: async (pageLink: string) => {
|
|
90
|
+
const result = firstRun
|
|
91
|
+
? initialResponse
|
|
92
|
+
: await client.pathUnchecked(pageLink).get();
|
|
93
|
+
firstRun = false;
|
|
94
|
+
checkPagingRequest(result);
|
|
95
|
+
const nextLink = getNextLink(result.body, nextLinkName);
|
|
96
|
+
const values = getElements<TElement>(result.body, itemName);
|
|
97
|
+
return {
|
|
98
|
+
page: values,
|
|
99
|
+
nextPageLink: nextLink
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return getPagedAsyncIterator(pagedResult);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Gets for the value of nextLink in the body
|
|
109
|
+
*/
|
|
110
|
+
function getNextLink(body: unknown, nextLinkName?: string): string | undefined {
|
|
111
|
+
if (!nextLinkName) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const nextLink = (body as Record<string, unknown>)[nextLinkName];
|
|
116
|
+
|
|
117
|
+
if (typeof nextLink !== "string" && typeof nextLink !== "undefined") {
|
|
118
|
+
throw new Error(
|
|
119
|
+
\`Body Property \${nextLinkName} should be a string or undefined\`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return nextLink;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Gets the elements of the current request in the body.
|
|
128
|
+
*/
|
|
129
|
+
function getElements<T = unknown>(body: unknown, itemName: string): T[] {
|
|
130
|
+
const value = (body as Record<string, unknown>)[itemName] as T[];
|
|
131
|
+
|
|
132
|
+
// value has to be an array according to the x-ms-pageable extension.
|
|
133
|
+
// The fact that this must be an array is used above to calculate the
|
|
134
|
+
// type of elements in the page in PaginateReturn
|
|
135
|
+
if (!Array.isArray(value)) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
\`Couldn't paginate response\\n Body doesn't contain an array property with name: \${itemName}\`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return value ?? [];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Checks if a request failed
|
|
146
|
+
*/
|
|
147
|
+
function checkPagingRequest(response: PathUncheckedResponse): void {
|
|
148
|
+
const Http2xxStatusCodes = [
|
|
149
|
+
"200",
|
|
150
|
+
"201",
|
|
151
|
+
"202",
|
|
152
|
+
"203",
|
|
153
|
+
"204",
|
|
154
|
+
"205",
|
|
155
|
+
"206",
|
|
156
|
+
"207",
|
|
157
|
+
"208",
|
|
158
|
+
"226"
|
|
159
|
+
];
|
|
160
|
+
if (!Http2xxStatusCodes.includes(response.status)) {
|
|
161
|
+
throw createRestError(
|
|
162
|
+
\`Pagination failed with unexpected statusCode \${response.status\}\`,
|
|
163
|
+
response
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
{{#if isComplexPaging}}
|
|
169
|
+
/**
|
|
170
|
+
* Extracts the itemName and nextLinkName from the initial response to use them for pagination
|
|
171
|
+
*/
|
|
172
|
+
function getPaginationProperties(initialResponse: PathUncheckedResponse) {
|
|
173
|
+
// Build a set with the passed custom nextLinkNames
|
|
174
|
+
const nextLinkNames = new Set([{{ quoteWrap nextLinkNames }}]);
|
|
175
|
+
|
|
176
|
+
// Build a set with the passed custom set of itemNames
|
|
177
|
+
const itemNames = new Set([{{ quoteWrap itemNames }}]);
|
|
178
|
+
|
|
179
|
+
let nextLinkName: string | undefined;
|
|
180
|
+
let itemName: string | undefined;
|
|
181
|
+
|
|
182
|
+
for (const name of nextLinkNames) {
|
|
183
|
+
const nextLink = (initialResponse.body as Record<string, unknown>)[
|
|
184
|
+
name
|
|
185
|
+
] as string;
|
|
186
|
+
if (nextLink) {
|
|
187
|
+
nextLinkName = name;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
for (const name of itemNames) {
|
|
193
|
+
const item = (initialResponse.body as Record<string, unknown>)[
|
|
194
|
+
name
|
|
195
|
+
] as string;
|
|
196
|
+
if (item) {
|
|
197
|
+
itemName = name;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (!itemName) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
\`Couldn't paginate response\\n Body doesn't contain an array property with name: \${[
|
|
205
|
+
...itemNames
|
|
206
|
+
].join(" OR ")}\`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return { itemName, nextLinkName };
|
|
211
|
+
}
|
|
212
|
+
{{/if}}
|
|
213
|
+
`;
|
|
214
|
+
//# sourceMappingURL=paginateContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginateContent.js","sourceRoot":"","sources":["../../src/static/paginateContent.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiN9B,CAAC"}
|