@azure-tools/rlc-common 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rush/temp/operation/build/state.json +1 -1
- package/.rush/temp/package-deps_build.json +16 -14
- package/CHANGELOG.md +8 -0
- package/dist/buildClient.js +24 -16
- package/dist/buildClient.js.map +1 -1
- package/dist/buildClientDefinitions.js +2 -1
- package/dist/buildClientDefinitions.js.map +1 -1
- package/dist/buildIsUnexpectedHelper.js +7 -3
- package/dist/buildIsUnexpectedHelper.js.map +1 -1
- package/dist/buildLogger.js +4 -0
- package/dist/buildLogger.js.map +1 -1
- package/dist/buildParameterTypes.js +6 -8
- package/dist/buildParameterTypes.js.map +1 -1
- package/dist/buildResponseTypes.js +6 -6
- package/dist/buildResponseTypes.js.map +1 -1
- package/dist/buildSchemaType.js +2 -1
- package/dist/buildSchemaType.js.map +1 -1
- package/dist/helpers/importsUtil.js +94 -0
- package/dist/helpers/importsUtil.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.js +1 -6
- package/dist/interfaces.js.map +1 -1
- package/dist/metadata/buildESLintConfig.js +6 -1
- package/dist/metadata/buildESLintConfig.js.map +1 -1
- package/dist/metadata/buildReadmeFile.js +40 -2
- package/dist/metadata/buildReadmeFile.js.map +1 -1
- package/dist/metadata/buildRollupConfig.js +3 -2
- package/dist/metadata/buildRollupConfig.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist-esm/buildClient.js +24 -16
- package/dist-esm/buildClient.js.map +1 -1
- package/dist-esm/buildClientDefinitions.js +2 -1
- package/dist-esm/buildClientDefinitions.js.map +1 -1
- package/dist-esm/buildIsUnexpectedHelper.js +5 -3
- package/dist-esm/buildIsUnexpectedHelper.js.map +1 -1
- package/dist-esm/buildLogger.js +4 -0
- package/dist-esm/buildLogger.js.map +1 -1
- package/dist-esm/buildParameterTypes.js +5 -7
- package/dist-esm/buildParameterTypes.js.map +1 -1
- package/dist-esm/buildResponseTypes.js +5 -5
- package/dist-esm/buildResponseTypes.js.map +1 -1
- package/dist-esm/buildSchemaType.js +2 -1
- package/dist-esm/buildSchemaType.js.map +1 -1
- package/dist-esm/helpers/importsUtil.js +89 -0
- package/dist-esm/helpers/importsUtil.js.map +1 -0
- package/dist-esm/index.js +1 -0
- package/dist-esm/index.js.map +1 -1
- package/dist-esm/interfaces.js +0 -5
- package/dist-esm/interfaces.js.map +1 -1
- package/dist-esm/metadata/buildESLintConfig.js +5 -1
- package/dist-esm/metadata/buildESLintConfig.js.map +1 -1
- package/dist-esm/metadata/buildReadmeFile.js +39 -1
- package/dist-esm/metadata/buildReadmeFile.js.map +1 -1
- package/dist-esm/metadata/buildRollupConfig.js +2 -1
- package/dist-esm/metadata/buildRollupConfig.js.map +1 -1
- package/dist-esm/package.json +1 -1
- package/package.json +1 -1
- package/src/buildClient.ts +35 -18
- package/src/buildClientDefinitions.ts +5 -1
- package/src/buildIsUnexpectedHelper.ts +8 -3
- package/src/buildLogger.ts +4 -0
- package/src/buildParameterTypes.ts +15 -7
- package/src/buildResponseTypes.ts +11 -5
- package/src/buildSchemaType.ts +5 -1
- package/src/helpers/importsUtil.ts +97 -0
- package/src/index.ts +1 -0
- package/src/interfaces.ts +39 -5
- package/src/metadata/buildESLintConfig.ts +6 -1
- package/src/metadata/buildReadmeFile.ts +43 -1
- package/src/metadata/buildRollupConfig.ts +2 -1
- package/test/helpers/importsUtil.spec.ts +68 -0
- package/types/helpers/importsUtil.d.ts +13 -0
- package/types/index.d.ts +1 -0
- package/types/interfaces.d.ts +22 -5
- package/types/metadata/buildESLintConfig.d.ts +3 -2
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the common imports for generated SDK
|
|
3
|
+
* @param branded whether to use azure-branded imports, the default value is true for azure branded
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export function buildRuntimeImports(branded = true) {
|
|
7
|
+
if (!branded) {
|
|
8
|
+
// In non-azure branded scope we only have one dependency that is ts-http-runtime
|
|
9
|
+
return {
|
|
10
|
+
commonFallback: {
|
|
11
|
+
type: "commonFallback",
|
|
12
|
+
specifier: "@typespec/ts-http-runtime",
|
|
13
|
+
version: "1.0.0-alpha.20231103.1"
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return {
|
|
19
|
+
restClient: {
|
|
20
|
+
type: "restClient",
|
|
21
|
+
specifier: "@azure-rest/core-client",
|
|
22
|
+
version: "^1.1.4"
|
|
23
|
+
},
|
|
24
|
+
coreAuth: {
|
|
25
|
+
type: "coreAuth",
|
|
26
|
+
specifier: "@azure/core-auth",
|
|
27
|
+
version: "^1.3.0"
|
|
28
|
+
},
|
|
29
|
+
restPipeline: {
|
|
30
|
+
type: "restPipeline",
|
|
31
|
+
specifier: "@azure/core-rest-pipeline",
|
|
32
|
+
version: "^1.12.0"
|
|
33
|
+
},
|
|
34
|
+
coreUtil: {
|
|
35
|
+
type: "coreUtil",
|
|
36
|
+
specifier: "@azure/core-util",
|
|
37
|
+
version: "^1.4.0"
|
|
38
|
+
},
|
|
39
|
+
coreLogger: {
|
|
40
|
+
type: "coreLogger",
|
|
41
|
+
specifier: "@azure/logger",
|
|
42
|
+
version: "^1.0.0"
|
|
43
|
+
},
|
|
44
|
+
azureEslintPlugin: {
|
|
45
|
+
type: "azureEslintPlugin",
|
|
46
|
+
specifier: "@azure/eslint-plugin-azure-sdk",
|
|
47
|
+
version: "^1.0.0"
|
|
48
|
+
},
|
|
49
|
+
azureTestRecorder: {
|
|
50
|
+
type: "azureTestRecorder",
|
|
51
|
+
specifier: "@azure-tools/test-recorder",
|
|
52
|
+
version: "^3.0.0"
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Initialize the inner imports for parameter and response, the import set would be used for referred models
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
export function initInternalImports() {
|
|
62
|
+
return {
|
|
63
|
+
parameter: {
|
|
64
|
+
type: "parameter",
|
|
65
|
+
importsSet: new Set()
|
|
66
|
+
},
|
|
67
|
+
response: {
|
|
68
|
+
type: "response",
|
|
69
|
+
importsSet: new Set()
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function getImportSpecifier(importType, imports, includeFallback = true) {
|
|
74
|
+
imports = imports ?? {};
|
|
75
|
+
const defaultPackageMap = {
|
|
76
|
+
restClient: "@azure-rest/core-client",
|
|
77
|
+
coreAuth: "@azure/core-auth",
|
|
78
|
+
restPipeline: "@azure/core-rest-pipeline",
|
|
79
|
+
coreUtil: "@azure/core-util",
|
|
80
|
+
coreLogger: "@azure/logger"
|
|
81
|
+
};
|
|
82
|
+
if (!includeFallback) {
|
|
83
|
+
return imports[importType]?.specifier ?? "";
|
|
84
|
+
}
|
|
85
|
+
return ((imports[importType] ?? imports.commonFallback)?.specifier ??
|
|
86
|
+
defaultPackageMap[importType] ??
|
|
87
|
+
"");
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=importsUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importsUtil.js","sourceRoot":"","sources":["../../src/helpers/importsUtil.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAO,GAAG,IAAI;IAChD,IAAI,CAAC,OAAO,EAAE;QACZ,iFAAiF;QACjF,OAAO;YACL,cAAc,EAAE;gBACd,IAAI,EAAE,gBAAgB;gBACtB,SAAS,EAAE,2BAA2B;gBACtC,OAAO,EAAE,wBAAwB;aAClC;SACS,CAAC;KACd;SAAM;QACL,OAAO;YACL,UAAU,EAAE;gBACV,IAAI,EAAE,YAAY;gBAClB,SAAS,EAAE,yBAAyB;gBACpC,OAAO,EAAE,QAAQ;aAClB;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,UA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,CAAC;KAC7C;IACD,OAAO,CACL,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,cAAc,CAAC,EAAE,SAAS;QAC1D,iBAAiB,CAAC,UAAU,CAAC;QAC7B,EAAE,CACH,CAAC;AACJ,CAAC"}
|
package/dist-esm/index.js
CHANGED
package/dist-esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC"}
|
package/dist-esm/interfaces.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
export const OPERATION_LRO_HIGH_PRIORITY = 0, OPERATION_LRO_LOW_PRIORITY = 1;
|
|
2
|
-
export var ImportKind;
|
|
3
|
-
(function (ImportKind) {
|
|
4
|
-
ImportKind[ImportKind["ResponseOutput"] = 0] = "ResponseOutput";
|
|
5
|
-
ImportKind[ImportKind["ParameterInput"] = 1] = "ParameterInput";
|
|
6
|
-
})(ImportKind || (ImportKind = {}));
|
|
7
2
|
export var SchemaContext;
|
|
8
3
|
(function (SchemaContext) {
|
|
9
4
|
/** Schema is used as an input to an operation. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAyKA,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,EAC1C,0BAA0B,GAAG,CAAC,CAAC;AAwEjC,MAAM,CAAN,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,kDAAkD;IAClD,gCAAe,CAAA;IACf,qDAAqD;IACrD,kCAAiB,CAAA;IACjB,wDAAwD;IACxD,wCAAuB,CAAA;AACzB,CAAC,EAPW,aAAa,KAAb,aAAa,QAOxB"}
|
|
@@ -10,7 +10,11 @@ const esLintConfig = {
|
|
|
10
10
|
"tsdoc/syntax": "warn"
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
export function buildEsLintConfig() {
|
|
13
|
+
export function buildEsLintConfig(model) {
|
|
14
|
+
const branded = model.options?.branded ?? true;
|
|
15
|
+
if (branded === false) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
14
18
|
const project = new Project();
|
|
15
19
|
const filePath = ".eslintrc.json";
|
|
16
20
|
const configFile = project.createSourceFile(".eslintrc.json", JSON.stringify(esLintConfig), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildESLintConfig.js","sourceRoot":"","sources":["../../src/metadata/buildESLintConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"buildESLintConfig.js","sourceRoot":"","sources":["../../src/metadata/buildESLintConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,MAAM,YAAY,GAAG;IACnB,OAAO,EAAE,CAAC,kBAAkB,CAAC;IAC7B,OAAO,EAAE,CAAC,wCAAwC,CAAC;IACnD,KAAK,EAAE;QACL,wCAAwC,EAAE,MAAM;QAChD,6CAA6C,EAAE,MAAM;QACrD,wCAAwC,EAAE,MAAM;QAChD,oDAAoD,EAAE,MAAM;QAC5D,cAAc,EAAE,MAAM;KACvB;CACF,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAAC,KAAe;IAC/C,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC;IAC/C,IAAI,OAAO,KAAK,KAAK,EAAE;QACrB,OAAO;KACR;IACD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,MAAM,QAAQ,GAAG,gBAAgB,CAAC;IAClC,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CACzC,gBAAgB,EAChB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAC5B;QACE,SAAS,EAAE,IAAI;KAChB,CACF,CAAC;IACF,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,UAAU,CAAC,WAAW,EAAE;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -78,9 +78,47 @@ setLogLevel("info");
|
|
|
78
78
|
|
|
79
79
|
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).
|
|
80
80
|
`;
|
|
81
|
+
const nonBrandedReadmeTemplate = `# {{ clientDescriptiveName }} library for JavaScript
|
|
82
|
+
|
|
83
|
+
{{ description }}
|
|
84
|
+
|
|
85
|
+
Key links:
|
|
86
|
+
|
|
87
|
+
{{#if packageSourceURL}}
|
|
88
|
+
- [Source code]({{ packageSourceURL }})
|
|
89
|
+
{{/if}}
|
|
90
|
+
{{#if packageNPMURL}}
|
|
91
|
+
- [Package (NPM)]({{ packageNPMURL }})
|
|
92
|
+
{{/if}}
|
|
93
|
+
{{#if apiRefURL}}
|
|
94
|
+
- [API reference documentation]({{ apiRefURL }})
|
|
95
|
+
{{/if}}
|
|
96
|
+
{{#if serviceDocURL}}
|
|
97
|
+
- [Product documentation]({{ serviceDocURL }})
|
|
98
|
+
{{/if}}
|
|
99
|
+
{{#if samplesURL}}
|
|
100
|
+
- [Samples]({{ samplesURL }})
|
|
101
|
+
{{/if}}
|
|
102
|
+
|
|
103
|
+
## Getting started
|
|
104
|
+
|
|
105
|
+
### Currently supported environments
|
|
106
|
+
|
|
107
|
+
- LTS versions of Node.js
|
|
108
|
+
|
|
109
|
+
### Install the \`{{ clientPackageName }}\` package
|
|
110
|
+
|
|
111
|
+
Install the {{ clientDescriptiveName }} REST client library for JavaScript with \`npm\`:
|
|
112
|
+
|
|
113
|
+
\`\`\`bash
|
|
114
|
+
npm install {{ clientPackageName }}
|
|
115
|
+
\`\`\`
|
|
116
|
+
`;
|
|
81
117
|
export function buildReadmeFile(model) {
|
|
82
118
|
const metadata = createMetadata(model) ?? {};
|
|
83
|
-
const readmeFileContents = hbs.compile(
|
|
119
|
+
const readmeFileContents = hbs.compile(model.options?.branded === false
|
|
120
|
+
? nonBrandedReadmeTemplate
|
|
121
|
+
: readmeTemplate, { noEscape: true });
|
|
84
122
|
return {
|
|
85
123
|
path: "README.md",
|
|
86
124
|
content: readmeFileContents(metadata)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildReadmeFile.js","sourceRoot":"","sources":["../../src/metadata/buildReadmeFile.ts"],"names":[],"mappings":"AACA,6DAA6D;AAC7D,0CAA0C;AAC1C,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAElE,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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C,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"}
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
import { Project } from "ts-morph";
|
|
4
4
|
export function buildRollupConfig(model) {
|
|
5
5
|
const azureSdkForJs = Boolean(model.options?.azureSdkForJs);
|
|
6
|
+
const isBranded = model.options?.branded ?? true;
|
|
6
7
|
// Only generate the file when it is not in sdk repo
|
|
7
|
-
if (azureSdkForJs === true || azureSdkForJs === undefined) {
|
|
8
|
+
if (isBranded && (azureSdkForJs === true || azureSdkForJs === undefined)) {
|
|
8
9
|
return;
|
|
9
10
|
}
|
|
10
11
|
const project = new Project();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildRollupConfig.js","sourceRoot":"","sources":["../../src/metadata/buildRollupConfig.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,MAAM,UAAU,iBAAiB,CAAC,KAAe;IAC/C,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC5D,oDAAoD;IACpD,IAAI,aAAa,KAAK,IAAI,IAAI,aAAa,KAAK,SAAS,EAAE;
|
|
1
|
+
{"version":3,"file":"buildRollupConfig.js","sourceRoot":"","sources":["../../src/metadata/buildRollupConfig.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,MAAM,UAAU,iBAAiB,CAAC,KAAe;IAC/C,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC5D,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC;IACjD,oDAAoD;IACpD,IAAI,SAAS,IAAI,CAAC,aAAa,KAAK,IAAI,IAAI,aAAa,KAAK,SAAS,CAAC,EAAE;QACxE,OAAO;KACR;IAED,MAAM,OAAO,GAAG,IAAI,OAAO,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"}
|
package/dist-esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@azure-tools/rlc-common","version":"0.
|
|
1
|
+
{"name":"@azure-tools/rlc-common","version":"0.19.0","description":"","type":"module","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":{"lint":"eslint src --ext .ts --max-warnings=0","lint:fix":"eslint src --fix --ext .ts","format":"npm run -s prettier -- --write","check-format":"npm run prettier -- --check","prettier":"prettier --config ./.prettierrc src/**/*.ts","build":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node publishPackage.js","build:cjs":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig-cjs.json && node publishPackage.js","build:esm":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && node publishPackage.js","test":"npm run unit-test","unit-test":"cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --loader=ts-node/esm --experimental-specifier-resolution=node test/**/*.spec.ts"},"keywords":[],"author":"","license":"ISC","dependencies":{"ts-morph":"^15.1.0","lodash":"^4.17.21","handlebars":"^4.7.7"},"devDependencies":{"@types/node":"^18.0.0","eslint":"^8.9.0","prettier":"~2.7.1","typescript":"~5.2.0","rimraf":"^5.0.0","@types/lodash":"^4.14.182","fs-extra":"^10.0.0","@types/fs-extra":"^8.1.0","ts-node":"^10.7.0","mocha":"^10.2.0","chai":"^4.3.7","@types/chai":"^4.3.4","@types/mocha":"^10.0.1","@typescript-eslint/eslint-plugin":"^6.8.0","@typescript-eslint/parser":"^6.8.0","eslint-plugin-require-extensions":"0.1.3","cross-env":"7.0.3"},"bugs":{"url":"https://github.com/Azure/autorest.typescript/issues"},"homepage":"https://github.com/Azure/autorest.typescript/tree/main/packages/rlc-common/"}
|
package/package.json
CHANGED
package/src/buildClient.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
getClientName,
|
|
20
20
|
getImportModuleName
|
|
21
21
|
} from "./helpers/nameConstructors.js";
|
|
22
|
+
import { getImportSpecifier } from "./helpers/importsUtil.js";
|
|
22
23
|
|
|
23
24
|
function getClientOptionsInterface(
|
|
24
25
|
clientName: string,
|
|
@@ -84,7 +85,8 @@ export function buildClient(model: RLCModel): File | undefined {
|
|
|
84
85
|
addCredentials,
|
|
85
86
|
credentialScopes,
|
|
86
87
|
credentialKeyHeaderName,
|
|
87
|
-
customHttpAuthHeaderName
|
|
88
|
+
customHttpAuthHeaderName,
|
|
89
|
+
branded
|
|
88
90
|
} = model.options;
|
|
89
91
|
const credentialTypes = credentialScopes ? ["TokenCredential"] : [];
|
|
90
92
|
|
|
@@ -160,19 +162,26 @@ export function buildClient(model: RLCModel): File | undefined {
|
|
|
160
162
|
clientFile.addImportDeclarations([
|
|
161
163
|
{
|
|
162
164
|
namedImports: ["getClient", "ClientOptions"],
|
|
163
|
-
moduleSpecifier:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
namedImports: ["logger"],
|
|
167
|
-
moduleSpecifier: getImportModuleName(
|
|
168
|
-
{
|
|
169
|
-
cjsName: loggerPath,
|
|
170
|
-
esModulesName: `${loggerPath}.js`
|
|
171
|
-
},
|
|
172
|
-
model
|
|
165
|
+
moduleSpecifier: getImportSpecifier(
|
|
166
|
+
"restClient",
|
|
167
|
+
model.importInfo.runtimeImports
|
|
173
168
|
)
|
|
174
169
|
}
|
|
175
170
|
]);
|
|
171
|
+
if (branded !== false) {
|
|
172
|
+
clientFile.addImportDeclarations([
|
|
173
|
+
{
|
|
174
|
+
namedImports: ["logger"],
|
|
175
|
+
moduleSpecifier: getImportModuleName(
|
|
176
|
+
{
|
|
177
|
+
cjsName: loggerPath,
|
|
178
|
+
esModulesName: `${loggerPath}.js`
|
|
179
|
+
},
|
|
180
|
+
model
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
]);
|
|
184
|
+
}
|
|
176
185
|
|
|
177
186
|
if (
|
|
178
187
|
addCredentials &&
|
|
@@ -185,7 +194,10 @@ export function buildClient(model: RLCModel): File | undefined {
|
|
|
185
194
|
clientFile.addImportDeclarations([
|
|
186
195
|
{
|
|
187
196
|
namedImports: credentialTypes,
|
|
188
|
-
moduleSpecifier:
|
|
197
|
+
moduleSpecifier: getImportSpecifier(
|
|
198
|
+
"coreAuth",
|
|
199
|
+
model.importInfo.runtimeImports
|
|
200
|
+
)
|
|
189
201
|
}
|
|
190
202
|
]);
|
|
191
203
|
}
|
|
@@ -221,7 +233,8 @@ export function getClientFactoryBody(
|
|
|
221
233
|
if (!model.options || !model.options.packageDetails || !model.urlInfo) {
|
|
222
234
|
return "";
|
|
223
235
|
}
|
|
224
|
-
const { includeShortcuts, packageDetails } =
|
|
236
|
+
const { includeShortcuts, packageDetails, branded, addCredentials } =
|
|
237
|
+
model.options;
|
|
225
238
|
let clientPackageName =
|
|
226
239
|
packageDetails!.nameWithoutScope ?? packageDetails?.name ?? "";
|
|
227
240
|
const packageVersion = packageDetails.version;
|
|
@@ -308,9 +321,16 @@ export function getClientFactoryBody(
|
|
|
308
321
|
const apiKeyHeaderName = credentialKeyHeaderName
|
|
309
322
|
? `apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "${credentialKeyHeaderName}",`
|
|
310
323
|
: "";
|
|
324
|
+
const loggerOptions =
|
|
325
|
+
branded !== false
|
|
326
|
+
? `,
|
|
327
|
+
loggingOptions: {
|
|
328
|
+
logger: options.loggingOptions?.logger ?? logger.info
|
|
329
|
+
}`
|
|
330
|
+
: "";
|
|
311
331
|
|
|
312
332
|
const credentialsOptions =
|
|
313
|
-
scopes || apiKeyHeaderName
|
|
333
|
+
(scopes || apiKeyHeaderName) && addCredentials
|
|
314
334
|
? `,
|
|
315
335
|
credentials: {
|
|
316
336
|
${scopes}
|
|
@@ -321,10 +341,7 @@ export function getClientFactoryBody(
|
|
|
321
341
|
...options,
|
|
322
342
|
userAgentOptions: {
|
|
323
343
|
userAgentPrefix
|
|
324
|
-
}
|
|
325
|
-
loggingOptions: {
|
|
326
|
-
logger: options.loggingOptions?.logger ?? logger.info
|
|
327
|
-
}${customHeaderOptions}${credentialsOptions}
|
|
344
|
+
}${loggerOptions}${customHeaderOptions}${credentialsOptions}
|
|
328
345
|
}`;
|
|
329
346
|
|
|
330
347
|
const getClient = `const client = getClient(
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
getClientName,
|
|
30
30
|
getImportModuleName
|
|
31
31
|
} from "./helpers/nameConstructors.js";
|
|
32
|
+
import { getImportSpecifier } from "./helpers/importsUtil.js";
|
|
32
33
|
|
|
33
34
|
export function buildClientDefinitions(model: RLCModel) {
|
|
34
35
|
const options = {
|
|
@@ -115,7 +116,10 @@ export function buildClientDefinitions(model: RLCModel) {
|
|
|
115
116
|
clientDefinitionsFile.addImportDeclarations([
|
|
116
117
|
{
|
|
117
118
|
namedImports: [...options.clientImports],
|
|
118
|
-
moduleSpecifier:
|
|
119
|
+
moduleSpecifier: getImportSpecifier(
|
|
120
|
+
"restClient",
|
|
121
|
+
model.importInfo.runtimeImports
|
|
122
|
+
)
|
|
119
123
|
}
|
|
120
124
|
]);
|
|
121
125
|
|
|
@@ -57,7 +57,9 @@ export function buildIsUnexpectedHelper(model: RLCModel) {
|
|
|
57
57
|
map = { ...map, ...{ [operation]: Array.from(successSet) } };
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
const successTypes = [
|
|
60
|
+
const successTypes = [
|
|
61
|
+
...methodDetails.flatMap((md) => md.responseTypes.success)
|
|
62
|
+
];
|
|
61
63
|
const errorTypes = methodDetails[0].responseTypes.error;
|
|
62
64
|
|
|
63
65
|
if (
|
|
@@ -66,8 +68,11 @@ export function buildIsUnexpectedHelper(model: RLCModel) {
|
|
|
66
68
|
?.success
|
|
67
69
|
) {
|
|
68
70
|
successTypes.push(
|
|
69
|
-
...methodDetails
|
|
70
|
-
|
|
71
|
+
...methodDetails.flatMap(
|
|
72
|
+
(md) =>
|
|
73
|
+
md.operationHelperDetail?.lroDetails?.logicalResponseTypes
|
|
74
|
+
?.success ?? ""
|
|
75
|
+
)
|
|
71
76
|
);
|
|
72
77
|
}
|
|
73
78
|
|
package/src/buildLogger.ts
CHANGED
|
@@ -9,6 +9,10 @@ export function buildLogger(model: RLCModel) {
|
|
|
9
9
|
if (!model.options) {
|
|
10
10
|
return undefined;
|
|
11
11
|
}
|
|
12
|
+
// Disable logger for non-branded packages
|
|
13
|
+
if (model.options.branded === false) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
12
16
|
const project = new Project();
|
|
13
17
|
const { srcPath } = model;
|
|
14
18
|
const { packageDetails } = model.options;
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
} from "ts-morph";
|
|
11
11
|
import * as path from "path";
|
|
12
12
|
import {
|
|
13
|
-
ImportKind,
|
|
14
13
|
ObjectSchema,
|
|
15
14
|
ParameterMetadata,
|
|
16
15
|
ParameterMetadatas,
|
|
@@ -22,6 +21,7 @@ import {
|
|
|
22
21
|
getParameterBaseName,
|
|
23
22
|
getParameterTypeName
|
|
24
23
|
} from "./helpers/nameConstructors.js";
|
|
24
|
+
import { getImportSpecifier } from "./helpers/importsUtil.js";
|
|
25
25
|
|
|
26
26
|
export function buildParameterTypes(model: RLCModel) {
|
|
27
27
|
const project = new Project();
|
|
@@ -139,22 +139,30 @@ export function buildParameterTypes(model: RLCModel) {
|
|
|
139
139
|
parametersFile.addImportDeclarations([
|
|
140
140
|
{
|
|
141
141
|
namedImports: ["RawHttpHeadersInput"],
|
|
142
|
-
moduleSpecifier:
|
|
142
|
+
moduleSpecifier: getImportSpecifier(
|
|
143
|
+
"restPipeline",
|
|
144
|
+
model.importInfo.runtimeImports
|
|
145
|
+
)
|
|
143
146
|
}
|
|
144
147
|
]);
|
|
145
148
|
}
|
|
146
149
|
parametersFile.addImportDeclarations([
|
|
147
150
|
{
|
|
148
151
|
namedImports: ["RequestParameters"],
|
|
149
|
-
moduleSpecifier:
|
|
152
|
+
moduleSpecifier: getImportSpecifier(
|
|
153
|
+
"restClient",
|
|
154
|
+
model.importInfo.runtimeImports
|
|
155
|
+
)
|
|
150
156
|
}
|
|
151
157
|
]);
|
|
152
|
-
if (
|
|
158
|
+
if (
|
|
159
|
+
(model.importInfo.internalImports?.parameter?.importsSet?.size ?? 0) > 0
|
|
160
|
+
) {
|
|
153
161
|
parametersFile.addImportDeclarations([
|
|
154
162
|
{
|
|
155
|
-
namedImports:
|
|
156
|
-
|
|
157
|
-
|
|
163
|
+
namedImports: Array.from(
|
|
164
|
+
model.importInfo.internalImports.parameter.importsSet!
|
|
165
|
+
),
|
|
158
166
|
moduleSpecifier: getImportModuleName(
|
|
159
167
|
{
|
|
160
168
|
cjsName: `./models`,
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
StructureKind
|
|
10
10
|
} from "ts-morph";
|
|
11
11
|
import {
|
|
12
|
-
ImportKind,
|
|
13
12
|
ResponseHeaderSchema,
|
|
14
13
|
ResponseMetadata,
|
|
15
14
|
RLCModel
|
|
@@ -20,6 +19,7 @@ import {
|
|
|
20
19
|
getResponseBaseName,
|
|
21
20
|
getResponseTypeName
|
|
22
21
|
} from "./helpers/nameConstructors.js";
|
|
22
|
+
import { getImportSpecifier } from "./helpers/importsUtil.js";
|
|
23
23
|
|
|
24
24
|
let hasErrorResponse = false;
|
|
25
25
|
export function buildResponseTypes(model: RLCModel) {
|
|
@@ -86,7 +86,10 @@ export function buildResponseTypes(model: RLCModel) {
|
|
|
86
86
|
responsesFile.addImportDeclarations([
|
|
87
87
|
{
|
|
88
88
|
namedImports: ["RawHttpHeaders"],
|
|
89
|
-
moduleSpecifier:
|
|
89
|
+
moduleSpecifier: getImportSpecifier(
|
|
90
|
+
"restPipeline",
|
|
91
|
+
model.importInfo.runtimeImports
|
|
92
|
+
)
|
|
90
93
|
}
|
|
91
94
|
]);
|
|
92
95
|
}
|
|
@@ -97,13 +100,16 @@ export function buildResponseTypes(model: RLCModel) {
|
|
|
97
100
|
responsesFile.addImportDeclarations([
|
|
98
101
|
{
|
|
99
102
|
namedImports,
|
|
100
|
-
moduleSpecifier:
|
|
103
|
+
moduleSpecifier: getImportSpecifier(
|
|
104
|
+
"restClient",
|
|
105
|
+
model.importInfo.runtimeImports
|
|
106
|
+
)
|
|
101
107
|
}
|
|
102
108
|
]);
|
|
103
109
|
|
|
104
|
-
if (model.
|
|
110
|
+
if ((model.importInfo.internalImports.response?.importsSet?.size ?? 0) > 0) {
|
|
105
111
|
const modelNamedImports = Array.from(
|
|
106
|
-
model.
|
|
112
|
+
model.importInfo.internalImports.response!.importsSet!
|
|
107
113
|
).filter((modelName) => {
|
|
108
114
|
return !(modelName === "ErrorResponseOutput" && hasErrorResponse);
|
|
109
115
|
});
|
package/src/buildSchemaType.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
buildPolymorphicAliases
|
|
10
10
|
} from "./buildObjectTypes.js";
|
|
11
11
|
import { RLCModel, SchemaContext } from "./interfaces.js";
|
|
12
|
+
import { getImportSpecifier } from "./helpers/importsUtil.js";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Generates types to represent schema definitions in the swagger
|
|
@@ -74,7 +75,10 @@ export function generateModelFiles(
|
|
|
74
75
|
modelsFile.addImportDeclarations([
|
|
75
76
|
{
|
|
76
77
|
namedImports: [...Array.from(importedModels || [])],
|
|
77
|
-
moduleSpecifier:
|
|
78
|
+
moduleSpecifier: getImportSpecifier(
|
|
79
|
+
"restClient",
|
|
80
|
+
model.importInfo.runtimeImports
|
|
81
|
+
)
|
|
78
82
|
}
|
|
79
83
|
]);
|
|
80
84
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ImportType, Imports } from "../interfaces.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Build the common imports for generated SDK
|
|
5
|
+
* @param branded whether to use azure-branded imports, the default value is true for azure branded
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export function buildRuntimeImports(branded = true): Imports {
|
|
9
|
+
if (!branded) {
|
|
10
|
+
// In non-azure branded scope we only have one dependency that is ts-http-runtime
|
|
11
|
+
return {
|
|
12
|
+
commonFallback: {
|
|
13
|
+
type: "commonFallback",
|
|
14
|
+
specifier: "@typespec/ts-http-runtime",
|
|
15
|
+
version: "1.0.0-alpha.20231103.1"
|
|
16
|
+
}
|
|
17
|
+
} as Imports;
|
|
18
|
+
} else {
|
|
19
|
+
return {
|
|
20
|
+
restClient: {
|
|
21
|
+
type: "restClient",
|
|
22
|
+
specifier: "@azure-rest/core-client",
|
|
23
|
+
version: "^1.1.4"
|
|
24
|
+
},
|
|
25
|
+
coreAuth: {
|
|
26
|
+
type: "coreAuth",
|
|
27
|
+
specifier: "@azure/core-auth",
|
|
28
|
+
version: "^1.3.0"
|
|
29
|
+
},
|
|
30
|
+
restPipeline: {
|
|
31
|
+
type: "restPipeline",
|
|
32
|
+
specifier: "@azure/core-rest-pipeline",
|
|
33
|
+
version: "^1.12.0"
|
|
34
|
+
},
|
|
35
|
+
coreUtil: {
|
|
36
|
+
type: "coreUtil",
|
|
37
|
+
specifier: "@azure/core-util",
|
|
38
|
+
version: "^1.4.0"
|
|
39
|
+
},
|
|
40
|
+
coreLogger: {
|
|
41
|
+
type: "coreLogger",
|
|
42
|
+
specifier: "@azure/logger",
|
|
43
|
+
version: "^1.0.0"
|
|
44
|
+
},
|
|
45
|
+
azureEslintPlugin: {
|
|
46
|
+
type: "azureEslintPlugin",
|
|
47
|
+
specifier: "@azure/eslint-plugin-azure-sdk",
|
|
48
|
+
version: "^1.0.0"
|
|
49
|
+
},
|
|
50
|
+
azureTestRecorder: {
|
|
51
|
+
type: "azureTestRecorder",
|
|
52
|
+
specifier: "@azure-tools/test-recorder",
|
|
53
|
+
version: "^3.0.0"
|
|
54
|
+
}
|
|
55
|
+
} as Imports;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Initialize the inner imports for parameter and response, the import set would be used for referred models
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
export function initInternalImports(): Imports {
|
|
64
|
+
return {
|
|
65
|
+
parameter: {
|
|
66
|
+
type: "parameter",
|
|
67
|
+
importsSet: new Set<string>()
|
|
68
|
+
},
|
|
69
|
+
response: {
|
|
70
|
+
type: "response",
|
|
71
|
+
importsSet: new Set<string>()
|
|
72
|
+
}
|
|
73
|
+
} as Imports;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function getImportSpecifier(
|
|
77
|
+
importType: ImportType,
|
|
78
|
+
imports?: Imports,
|
|
79
|
+
includeFallback = true
|
|
80
|
+
): string {
|
|
81
|
+
imports = imports ?? ({} as Imports);
|
|
82
|
+
const defaultPackageMap: Record<ImportType, string> = {
|
|
83
|
+
restClient: "@azure-rest/core-client",
|
|
84
|
+
coreAuth: "@azure/core-auth",
|
|
85
|
+
restPipeline: "@azure/core-rest-pipeline",
|
|
86
|
+
coreUtil: "@azure/core-util",
|
|
87
|
+
coreLogger: "@azure/logger"
|
|
88
|
+
} as any;
|
|
89
|
+
if (!includeFallback) {
|
|
90
|
+
return imports[importType]?.specifier ?? "";
|
|
91
|
+
}
|
|
92
|
+
return (
|
|
93
|
+
(imports[importType] ?? imports.commonFallback)?.specifier ??
|
|
94
|
+
defaultPackageMap[importType] ??
|
|
95
|
+
""
|
|
96
|
+
);
|
|
97
|
+
}
|
package/src/index.ts
CHANGED