@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,189 @@
|
|
|
1
|
+
export const envContent = `
|
|
2
|
+
import * as dotenv from "dotenv";
|
|
3
|
+
|
|
4
|
+
dotenv.config();
|
|
5
|
+
`;
|
|
6
|
+
export const envBrowserContent = `
|
|
7
|
+
import * as dotenv from "dotenv";
|
|
8
|
+
|
|
9
|
+
dotenv.config();
|
|
10
|
+
`;
|
|
11
|
+
export const karmaConfig = `
|
|
12
|
+
// https://github.com/karma-runner/karma-chrome-launcher
|
|
13
|
+
process.env.CHROME_BIN = require("puppeteer").executablePath();
|
|
14
|
+
require("dotenv").config();
|
|
15
|
+
const { relativeRecordingsPath } = require("@azure-tools/test-recorder");
|
|
16
|
+
process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();
|
|
17
|
+
|
|
18
|
+
module.exports = function (config) {
|
|
19
|
+
config.set({
|
|
20
|
+
// base path that will be used to resolve all patterns (eg. files, exclude)
|
|
21
|
+
basePath: "./",
|
|
22
|
+
|
|
23
|
+
// frameworks to use
|
|
24
|
+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
|
25
|
+
frameworks: ["source-map-support", "mocha"],
|
|
26
|
+
|
|
27
|
+
plugins: [
|
|
28
|
+
"karma-mocha",
|
|
29
|
+
"karma-mocha-reporter",
|
|
30
|
+
"karma-chrome-launcher",
|
|
31
|
+
"karma-edge-launcher",
|
|
32
|
+
"karma-firefox-launcher",
|
|
33
|
+
"karma-ie-launcher",
|
|
34
|
+
"karma-env-preprocessor",
|
|
35
|
+
"karma-coverage",
|
|
36
|
+
"karma-sourcemap-loader",
|
|
37
|
+
"karma-junit-reporter",
|
|
38
|
+
"karma-source-map-support",
|
|
39
|
+
],
|
|
40
|
+
|
|
41
|
+
// list of files / patterns to load in the browser
|
|
42
|
+
files: [
|
|
43
|
+
"dist-test/index.browser.js",
|
|
44
|
+
{ pattern: "dist-test/index.browser.js.map", type: "html", included: false, served: true },
|
|
45
|
+
],
|
|
46
|
+
|
|
47
|
+
// list of files / patterns to exclude
|
|
48
|
+
exclude: [],
|
|
49
|
+
|
|
50
|
+
// preprocess matching files before serving them to the browser
|
|
51
|
+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
|
52
|
+
preprocessors: {
|
|
53
|
+
"**/*.js": ["sourcemap", "env"],
|
|
54
|
+
// IMPORTANT: COMMENT following line if you want to debug in your browsers!!
|
|
55
|
+
// Preprocess source file to calculate code coverage, however this will make source file unreadable
|
|
56
|
+
// "dist-test/index.js": ["coverage"]
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
envPreprocessor: [
|
|
60
|
+
"TEST_MODE",
|
|
61
|
+
"ENDPOINT",
|
|
62
|
+
"AZURE_CLIENT_SECRET",
|
|
63
|
+
"AZURE_CLIENT_ID",
|
|
64
|
+
"AZURE_TENANT_ID",
|
|
65
|
+
"SUBSCRIPTION_ID",
|
|
66
|
+
],
|
|
67
|
+
|
|
68
|
+
// test results reporter to use
|
|
69
|
+
// possible values: 'dots', 'progress'
|
|
70
|
+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
|
71
|
+
reporters: ["mocha", "coverage", "junit"],
|
|
72
|
+
|
|
73
|
+
coverageReporter: {
|
|
74
|
+
// specify a common output directory
|
|
75
|
+
dir: "coverage-browser/",
|
|
76
|
+
reporters: [
|
|
77
|
+
{ type: "json", subdir: ".", file: "coverage.json" },
|
|
78
|
+
{ type: "lcovonly", subdir: ".", file: "lcov.info" },
|
|
79
|
+
{ type: "html", subdir: "html" },
|
|
80
|
+
{ type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
junitReporter: {
|
|
85
|
+
outputDir: "", // results will be saved as $outputDir/$browserName.xml
|
|
86
|
+
outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile
|
|
87
|
+
suite: "", // suite will become the package name attribute in xml testsuite element
|
|
88
|
+
useBrowserName: false, // add browser name to report and classes names
|
|
89
|
+
nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
|
|
90
|
+
classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
|
|
91
|
+
properties: {}, // key value pair of properties to add to the <properties> section of the report
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
// web server port
|
|
95
|
+
port: 9876,
|
|
96
|
+
|
|
97
|
+
// enable / disable colors in the output (reporters and logs)
|
|
98
|
+
colors: true,
|
|
99
|
+
|
|
100
|
+
// level of logging
|
|
101
|
+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
|
102
|
+
logLevel: config.LOG_INFO,
|
|
103
|
+
|
|
104
|
+
// enable / disable watching file and executing tests whenever any file changes
|
|
105
|
+
autoWatch: false,
|
|
106
|
+
|
|
107
|
+
// --no-sandbox allows our tests to run in Linux without having to change the system.
|
|
108
|
+
// --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex.
|
|
109
|
+
browsers: ["ChromeHeadlessNoSandbox"],
|
|
110
|
+
customLaunchers: {
|
|
111
|
+
ChromeHeadlessNoSandbox: {
|
|
112
|
+
base: "ChromeHeadless",
|
|
113
|
+
flags: ["--no-sandbox", "--disable-web-security"],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
// Continuous Integration mode
|
|
118
|
+
// if true, Karma captures browsers, runs the tests and exits
|
|
119
|
+
singleRun: false,
|
|
120
|
+
|
|
121
|
+
// Concurrency level
|
|
122
|
+
// how many browser should be started simultaneous
|
|
123
|
+
concurrency: 1,
|
|
124
|
+
|
|
125
|
+
browserNoActivityTimeout: 60000000,
|
|
126
|
+
browserDisconnectTimeout: 10000,
|
|
127
|
+
browserDisconnectTolerance: 3,
|
|
128
|
+
|
|
129
|
+
client: {
|
|
130
|
+
mocha: {
|
|
131
|
+
// change Karma's debug.html to the mocha web reporter
|
|
132
|
+
reporter: "html",
|
|
133
|
+
timeout: "600000",
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
`;
|
|
139
|
+
export const recordedClientContent = `
|
|
140
|
+
import { Context } from "mocha";
|
|
141
|
+
import { Recorder, RecorderStartOptions } from "@azure-tools/test-recorder";
|
|
142
|
+
import "./env";
|
|
143
|
+
|
|
144
|
+
const envSetupForPlayback: Record<string, string> = {
|
|
145
|
+
ENDPOINT: "https://endpoint",
|
|
146
|
+
AZURE_CLIENT_ID: "azure_client_id",
|
|
147
|
+
AZURE_CLIENT_SECRET: "azure_client_secret",
|
|
148
|
+
AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888",
|
|
149
|
+
SUBSCRIPTION_ID: "azure_subscription_id"
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const recorderEnvSetup: RecorderStartOptions = {
|
|
153
|
+
envSetupForPlayback
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* creates the recorder and reads the environment variables from the \`.env\` file.
|
|
158
|
+
* Should be called first in the test suite to make sure environment variables are
|
|
159
|
+
* read before they are being used.
|
|
160
|
+
*/
|
|
161
|
+
export async function createRecorder(context: Context): Promise<Recorder> {
|
|
162
|
+
const recorder = new Recorder(context.currentTest);
|
|
163
|
+
await recorder.start(recorderEnvSetup);
|
|
164
|
+
return recorder;
|
|
165
|
+
}
|
|
166
|
+
`;
|
|
167
|
+
export const sampleTestContent = `
|
|
168
|
+
import { Recorder } from "@azure-tools/test-recorder";
|
|
169
|
+
import { assert } from "chai";
|
|
170
|
+
import { createRecorder } from "./utils/recordedClient";
|
|
171
|
+
import { Context } from "mocha";
|
|
172
|
+
|
|
173
|
+
describe("My test", () => {
|
|
174
|
+
let recorder: Recorder;
|
|
175
|
+
|
|
176
|
+
beforeEach(async function(this: Context) {
|
|
177
|
+
recorder = await createRecorder(this);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
afterEach(async function() {
|
|
181
|
+
await recorder.stop();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("sample test", async function() {
|
|
185
|
+
assert.equal(1, 1);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
`;
|
|
189
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/test/template.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;;;;CAIzB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;CAIhC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+H1B,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BpC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;CAqBhC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@azure-tools/rlc-common",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist-esm/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./types/index.d.ts",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"import": "./dist-esm/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"types": "./types/index.d.ts",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "rimraf dist/* dist-esm/* types/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node publishPackage.js",
|
|
18
|
+
"build:cjs":"rimraf dist/* dist-esm/* types/* && tsc -p tsconfig-cjs.json && node publishPackage.js",
|
|
19
|
+
"build:esm":"rimraf dist/* dist-esm/* types/* && tsc -p tsconfig.json && node publishPackage.js",
|
|
20
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [],
|
|
23
|
+
"author": "",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"ts-morph": "^15.1.0",
|
|
27
|
+
"lodash": "^4.17.21",
|
|
28
|
+
"handlebars": "^4.7.7"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^18.0.0",
|
|
32
|
+
"prettier": "~2.7.1",
|
|
33
|
+
"typescript": "^4.6.3",
|
|
34
|
+
"rimraf": "^3.0.2",
|
|
35
|
+
"@types/lodash": "^4.14.182",
|
|
36
|
+
"fs-extra": "^10.0.0",
|
|
37
|
+
"@types/fs-extra": "^8.1.0",
|
|
38
|
+
"ts-node": "^10.7.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { writeFileSync } from "fs";
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const p = require("./package.json");
|
|
5
|
+
|
|
6
|
+
const cjsPackage = { ...p, type: "commonjs" };
|
|
7
|
+
writeFileSync("./dist/package.json", JSON.stringify(cjsPackage));
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const esmPackage = { ...p, type: "module" };
|
|
11
|
+
writeFileSync("./dist-esm/package.json", JSON.stringify(esmPackage));
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Project,
|
|
6
|
+
StatementStructures,
|
|
7
|
+
StructureKind,
|
|
8
|
+
VariableDeclarationKind,
|
|
9
|
+
VariableStatementStructure,
|
|
10
|
+
WriterFunction
|
|
11
|
+
} from "ts-morph";
|
|
12
|
+
import * as path from "path";
|
|
13
|
+
import { NameType, normalizeName } from "./helpers/nameUtils.js";
|
|
14
|
+
import { isConstantSchema } from "./helpers/schemaHelpers.js";
|
|
15
|
+
import { buildMethodShortcutImplementation } from "./buildMethodShortcuts.js";
|
|
16
|
+
import { RLCModel, Schema, File } from "./interfaces.js";
|
|
17
|
+
|
|
18
|
+
export function buildClient(model: RLCModel): File | undefined {
|
|
19
|
+
const name = normalizeName(model.libraryName, NameType.File);
|
|
20
|
+
const { srcPath } = model;
|
|
21
|
+
const project = new Project();
|
|
22
|
+
const filePath = path.join(srcPath, `${name}.ts`);
|
|
23
|
+
const clientFile = project.createSourceFile(filePath, undefined, {
|
|
24
|
+
overwrite: true
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Get all paths
|
|
28
|
+
const clientName = model.libraryName;
|
|
29
|
+
const urlParameters = model?.urlInfo?.urlParameters;
|
|
30
|
+
|
|
31
|
+
if (!model.options) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const { multiClient, batch } = model.options;
|
|
35
|
+
const { addCredentials, credentialScopes, credentialKeyHeaderName } =
|
|
36
|
+
model.options;
|
|
37
|
+
const credentialTypes =
|
|
38
|
+
credentialScopes && credentialScopes.length > 0 ? ["TokenCredential"] : [];
|
|
39
|
+
|
|
40
|
+
if (credentialKeyHeaderName) {
|
|
41
|
+
credentialTypes.push("KeyCredential");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const commonClientParams = [
|
|
45
|
+
...(urlParameters ?? []),
|
|
46
|
+
...(addCredentials === false ||
|
|
47
|
+
!isSecurityInfoDefined(credentialScopes, credentialKeyHeaderName)
|
|
48
|
+
? []
|
|
49
|
+
: [{ name: "credentials", type: credentialTypes.join(" | ") }])
|
|
50
|
+
];
|
|
51
|
+
const clientInterfaceName = clientName.endsWith("Client")
|
|
52
|
+
? `${clientName}`
|
|
53
|
+
: `${clientName}Client`;
|
|
54
|
+
|
|
55
|
+
const functionStatement = {
|
|
56
|
+
isExported: true,
|
|
57
|
+
name: `createClient`,
|
|
58
|
+
parameters: [
|
|
59
|
+
...commonClientParams,
|
|
60
|
+
{ name: "options", type: "ClientOptions = {}" }
|
|
61
|
+
],
|
|
62
|
+
docs: [
|
|
63
|
+
{
|
|
64
|
+
description:
|
|
65
|
+
`Initialize a new instance of the class ${clientInterfaceName} class. \n` +
|
|
66
|
+
commonClientParams
|
|
67
|
+
.map((param) => {
|
|
68
|
+
return `@param ${param.name} type: ${param.type} ${param.description ?? ""}`;
|
|
69
|
+
})
|
|
70
|
+
.join("\n")
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
returnType: clientInterfaceName,
|
|
74
|
+
isDefaultExport: false,
|
|
75
|
+
statements: getClientFactoryBody(model, clientInterfaceName)
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (!multiClient || !batch || batch.length === 1) {
|
|
79
|
+
functionStatement.isDefaultExport = true;
|
|
80
|
+
}
|
|
81
|
+
clientFile.addFunction(functionStatement);
|
|
82
|
+
|
|
83
|
+
clientFile.addImportDeclarations([
|
|
84
|
+
{
|
|
85
|
+
namedImports: ["getClient", "ClientOptions"],
|
|
86
|
+
moduleSpecifier: "@azure-rest/core-client"
|
|
87
|
+
}
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
if (
|
|
91
|
+
addCredentials &&
|
|
92
|
+
isSecurityInfoDefined(credentialScopes, credentialKeyHeaderName)
|
|
93
|
+
) {
|
|
94
|
+
clientFile.addImportDeclarations([
|
|
95
|
+
{
|
|
96
|
+
namedImports: credentialTypes,
|
|
97
|
+
moduleSpecifier: "@azure/core-auth"
|
|
98
|
+
}
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
clientFile.addImportDeclarations([
|
|
102
|
+
{
|
|
103
|
+
namedImports: [`${clientInterfaceName}`],
|
|
104
|
+
moduleSpecifier: "./clientDefinitions"
|
|
105
|
+
}
|
|
106
|
+
]);
|
|
107
|
+
return { path: filePath, content: clientFile.getFullText() };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function isSecurityInfoDefined(
|
|
111
|
+
credentialScopes?: string[],
|
|
112
|
+
credentialKeyHeaderName?: string
|
|
113
|
+
) {
|
|
114
|
+
return (
|
|
115
|
+
(credentialScopes && credentialScopes.length > 0) || credentialKeyHeaderName
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function getClientFactoryBody(
|
|
120
|
+
model: RLCModel,
|
|
121
|
+
clientTypeName: string
|
|
122
|
+
): string | WriterFunction | (string | WriterFunction | StatementStructures)[] {
|
|
123
|
+
if (!model.options || !model.options.packageDetails || !model.urlInfo) {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
const { includeShortcuts, packageDetails } = model.options;
|
|
127
|
+
let clientPackageName = packageDetails.nameWithoutScope ?? "";
|
|
128
|
+
const packageVersion = packageDetails.version;
|
|
129
|
+
const { endpoint, urlParameters } = model.urlInfo;
|
|
130
|
+
let baseUrl: string;
|
|
131
|
+
if (urlParameters && endpoint) {
|
|
132
|
+
let parsedEndpoint = endpoint;
|
|
133
|
+
urlParameters.forEach((urlParameter) => {
|
|
134
|
+
parsedEndpoint = parsedEndpoint.replace(
|
|
135
|
+
`{${urlParameter.name}}`,
|
|
136
|
+
`\${${urlParameter.name}}`
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
baseUrl = `options.baseUrl ?? \`${parsedEndpoint}\``;
|
|
141
|
+
} else {
|
|
142
|
+
baseUrl = `options.baseUrl ?? "${endpoint}"`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const apiVersion = getApiVersion(model);
|
|
146
|
+
let apiVersionStatement: string = "";
|
|
147
|
+
if (apiVersion) {
|
|
148
|
+
apiVersionStatement = `options.apiVersion = options.apiVersion ?? "${apiVersion}"`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!clientPackageName.endsWith("-rest")) {
|
|
152
|
+
clientPackageName = clientPackageName + "-rest";
|
|
153
|
+
}
|
|
154
|
+
const userAgentInfoStatement =
|
|
155
|
+
"const userAgentInfo = `azsdk-js-" +
|
|
156
|
+
clientPackageName +
|
|
157
|
+
"/" +
|
|
158
|
+
packageVersion +
|
|
159
|
+
"`;";
|
|
160
|
+
const userAgentPrefix =
|
|
161
|
+
"options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`: `${userAgentInfo}`;";
|
|
162
|
+
const userAgentStatement: VariableStatementStructure = {
|
|
163
|
+
kind: StructureKind.VariableStatement,
|
|
164
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
165
|
+
declarations: [{ name: "userAgentPrefix", initializer: userAgentPrefix }]
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const userAgentOptionsStatement = `options = {
|
|
169
|
+
...options,
|
|
170
|
+
userAgentOptions: {
|
|
171
|
+
userAgentPrefix
|
|
172
|
+
}
|
|
173
|
+
}`;
|
|
174
|
+
|
|
175
|
+
const baseUrlStatement: VariableStatementStructure = {
|
|
176
|
+
kind: StructureKind.VariableStatement,
|
|
177
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
178
|
+
declarations: [{ name: "baseUrl", initializer: baseUrl }]
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const { credentialScopes, credentialKeyHeaderName } = model.options;
|
|
182
|
+
|
|
183
|
+
const scopesString =
|
|
184
|
+
credentialScopes && credentialScopes.length
|
|
185
|
+
? credentialScopes.map((cs) => `"${cs}"`).join(", ")
|
|
186
|
+
: "";
|
|
187
|
+
const scopes = scopesString ? `scopes: [${scopesString}],` : "";
|
|
188
|
+
|
|
189
|
+
const apiKeyHeaderName = credentialKeyHeaderName
|
|
190
|
+
? `apiKeyHeaderName: "${credentialKeyHeaderName}",`
|
|
191
|
+
: "";
|
|
192
|
+
|
|
193
|
+
const credentials =
|
|
194
|
+
scopes || apiKeyHeaderName
|
|
195
|
+
? `options = {
|
|
196
|
+
...options,
|
|
197
|
+
credentials: {
|
|
198
|
+
${scopes}
|
|
199
|
+
${apiKeyHeaderName}
|
|
200
|
+
},
|
|
201
|
+
}`
|
|
202
|
+
: "";
|
|
203
|
+
|
|
204
|
+
const getClient = `const client = getClient(
|
|
205
|
+
baseUrl, ${credentials ? "credentials," : ""} options
|
|
206
|
+
) as ${clientTypeName};
|
|
207
|
+
`;
|
|
208
|
+
|
|
209
|
+
let returnStatement = `return client;`;
|
|
210
|
+
|
|
211
|
+
if (includeShortcuts) {
|
|
212
|
+
const shortcutImplementations = buildMethodShortcutImplementation(
|
|
213
|
+
model.paths
|
|
214
|
+
);
|
|
215
|
+
const shortcutBody = Object.keys(shortcutImplementations).map((key) => {
|
|
216
|
+
// If the operation group has an empty name, it means its operations are client
|
|
217
|
+
// level operations so we need to spread the definitions. Otherwise they are
|
|
218
|
+
// within an operation group so we add them as key: value
|
|
219
|
+
return `${
|
|
220
|
+
key && key !== "client" ? `"${key}":` : "..."
|
|
221
|
+
} {${shortcutImplementations[key].join()}}`;
|
|
222
|
+
});
|
|
223
|
+
returnStatement = `return { ...client, ${shortcutBody.join()} };`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return [
|
|
227
|
+
baseUrlStatement,
|
|
228
|
+
apiVersionStatement,
|
|
229
|
+
credentials,
|
|
230
|
+
userAgentInfoStatement,
|
|
231
|
+
userAgentStatement,
|
|
232
|
+
userAgentOptionsStatement,
|
|
233
|
+
getClient,
|
|
234
|
+
returnStatement
|
|
235
|
+
];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function getApiVersion(model: RLCModel): string | undefined {
|
|
239
|
+
if (!model.apiVersionParam) {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (
|
|
244
|
+
model.apiVersionParam &&
|
|
245
|
+
isConstantSchema(model.apiVersionParam as Schema)
|
|
246
|
+
) {
|
|
247
|
+
return model.apiVersionParam.default;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|