@azure-tools/typespec-ts 0.56.0-dev.12 → 0.56.0-dev.14
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/README.md +23 -6
- package/dist/src/lib.d.ts +15 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +22 -5
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/build-classical-client.d.ts.map +1 -1
- package/dist/src/modular/build-classical-client.js +2 -2
- package/dist/src/modular/build-classical-client.js.map +1 -1
- package/dist/src/modular/helpers/client-helpers.d.ts +6 -1
- package/dist/src/modular/helpers/client-helpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/client-helpers.js +15 -11
- package/dist/src/modular/helpers/client-helpers.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/lib.ts +40 -7
- package/src/modular/build-classical-client.ts +2 -6
- package/src/modular/helpers/client-helpers.ts +16 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-ts",
|
|
3
|
-
"version": "0.56.0-dev.
|
|
3
|
+
"version": "0.56.0-dev.14",
|
|
4
4
|
"description": "A TypeSpec emitter for TypeScript",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@azure-tools/azure-http-specs": "^0.1.0-alpha.42 || >=0.1.0-alpha.43-dev <0.1.0-alpha.43",
|
|
26
26
|
"@azure-tools/typespec-autorest": "^0.69.1 || >=0.70.0-dev <0.70.0",
|
|
27
27
|
"@azure-tools/typespec-azure-core": "^0.69.0 || >=0.70.0-dev <0.70.0",
|
|
28
|
-
"@azure-tools/typespec-azure-resource-manager": "^0.69.
|
|
29
|
-
"@azure-tools/typespec-client-generator-core": "^0.69.
|
|
28
|
+
"@azure-tools/typespec-azure-resource-manager": "^0.69.2 || >=0.70.0-dev <0.70.0",
|
|
29
|
+
"@azure-tools/typespec-client-generator-core": "^0.69.2 || >=0.70.0-dev <0.70.0",
|
|
30
30
|
"@azure/abort-controller": "^2.1.2",
|
|
31
31
|
"@azure/core-auth": "^1.6.0",
|
|
32
32
|
"@azure/core-lro": "^3.1.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@azure-tools/typespec-azure-core": "^0.69.0 || >=0.70.0-dev <0.70.0",
|
|
54
|
-
"@azure-tools/typespec-client-generator-core": "^0.69.
|
|
54
|
+
"@azure-tools/typespec-client-generator-core": "^0.69.2 || >=0.70.0-dev <0.70.0",
|
|
55
55
|
"@typespec/compiler": "^1.13.0",
|
|
56
56
|
"@typespec/http": "^1.13.0",
|
|
57
57
|
"@typespec/rest": "^0.83.0 || >=0.84.0-dev <0.84.0",
|
package/src/lib.ts
CHANGED
|
@@ -6,6 +6,21 @@ import { Options } from "prettier";
|
|
|
6
6
|
import { PackageDetails } from "./interfaces.js";
|
|
7
7
|
|
|
8
8
|
export interface EmitterOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Use this flag if you would like to generate the sdk only for a specific version.
|
|
11
|
+
* Also accepts values `latest` and `all`, or a map from service namespace full name to version for multi-service packages.
|
|
12
|
+
*/
|
|
13
|
+
"api-version"?: string | Record<string, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Specifies the directory where the emitter will look for example files.
|
|
16
|
+
* Defaults to an `examples` directory located at the project root.
|
|
17
|
+
*/
|
|
18
|
+
"examples-dir"?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Specifies the namespace you want to override for namespaces set in the spec.
|
|
21
|
+
* With this config, all namespace for the spec types will default to it.
|
|
22
|
+
*/
|
|
23
|
+
namespace?: string;
|
|
9
24
|
/**
|
|
10
25
|
* Indicates whether to include response headers in the generated response type for modular operations.
|
|
11
26
|
* When set to true, modular operation responses with model or void bodies will have their headers
|
|
@@ -50,8 +65,6 @@ export interface EmitterOptions {
|
|
|
50
65
|
"ignore-property-name-normalize"?: boolean;
|
|
51
66
|
"typespec-title-map"?: Record<string, string>;
|
|
52
67
|
"ignore-enum-member-name-normalize"?: boolean;
|
|
53
|
-
//TODO should remove this after finish the release tool test
|
|
54
|
-
"should-use-pnpm-dep"?: boolean;
|
|
55
68
|
"ignore-nullable-on-optional"?: boolean;
|
|
56
69
|
/**
|
|
57
70
|
* When set to true (default for Azure services), non-model return types (arrays, scalars, enums,
|
|
@@ -84,6 +97,31 @@ export const EmitterOptionsSchema: JSONSchemaType<EmitterOptions> = {
|
|
|
84
97
|
type: "object",
|
|
85
98
|
additionalProperties: true,
|
|
86
99
|
properties: {
|
|
100
|
+
"api-version": {
|
|
101
|
+
oneOf: [
|
|
102
|
+
{ type: "string", nullable: true },
|
|
103
|
+
{
|
|
104
|
+
type: "object",
|
|
105
|
+
additionalProperties: { type: "string" },
|
|
106
|
+
required: [],
|
|
107
|
+
nullable: true,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
description:
|
|
111
|
+
"Use this flag if you would like to generate the sdk only for a specific version. Default value is the latest version. Also accepts values `latest` and `all`. For multi-service packages, provide a map from each service namespace's full name to its desired version; services not listed default to their latest version.",
|
|
112
|
+
} as any,
|
|
113
|
+
"examples-dir": {
|
|
114
|
+
type: "string",
|
|
115
|
+
nullable: true,
|
|
116
|
+
description:
|
|
117
|
+
"Specifies the directory where the emitter will look for example files. If the flag isn't set, the emitter defaults to using an `examples` directory located at the project root.",
|
|
118
|
+
},
|
|
119
|
+
namespace: {
|
|
120
|
+
type: "string",
|
|
121
|
+
nullable: true,
|
|
122
|
+
description:
|
|
123
|
+
"Specifies the namespace you want to override for namespaces set in the spec. With this config, all namespace for the spec types will default to it.",
|
|
124
|
+
},
|
|
87
125
|
"include-headers-in-response": {
|
|
88
126
|
type: "boolean",
|
|
89
127
|
nullable: true,
|
|
@@ -245,11 +283,6 @@ export const EmitterOptionsSchema: JSONSchemaType<EmitterOptions> = {
|
|
|
245
283
|
"```",
|
|
246
284
|
].join("\n"),
|
|
247
285
|
},
|
|
248
|
-
"should-use-pnpm-dep": {
|
|
249
|
-
type: "boolean",
|
|
250
|
-
nullable: true,
|
|
251
|
-
description: "Internal option for test.",
|
|
252
|
-
},
|
|
253
286
|
"ignore-nullable-on-optional": {
|
|
254
287
|
type: "boolean",
|
|
255
288
|
nullable: true,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
SourceFile,
|
|
6
6
|
StructureKind,
|
|
7
7
|
} from "ts-morph";
|
|
8
|
-
import {
|
|
8
|
+
import { getClientParametersDeclaration } from "./helpers/client-helpers.js";
|
|
9
9
|
import { getClassicalClientName, getClientName } from "./helpers/naming-helpers.js";
|
|
10
10
|
import { ModularEmitterOptions } from "./interfaces.js";
|
|
11
11
|
|
|
@@ -127,11 +127,7 @@ export function buildClassicalClient(
|
|
|
127
127
|
.map((p) => p.name)
|
|
128
128
|
.map((x) => {
|
|
129
129
|
if (x === "options") {
|
|
130
|
-
return `
|
|
131
|
-
constructor,
|
|
132
|
-
emitterOptions,
|
|
133
|
-
"azsdk-js-client",
|
|
134
|
-
)}}`;
|
|
130
|
+
return `options`;
|
|
135
131
|
} else if (x.toLowerCase() === "subscriptionid" && shouldSubscriptionIdOptional) {
|
|
136
132
|
return `subscriptionId ?? ""`;
|
|
137
133
|
} else {
|
|
@@ -241,7 +241,7 @@ export function buildGetClientOptionsParam(
|
|
|
241
241
|
endpointParam: string,
|
|
242
242
|
apiVersionParamName?: string,
|
|
243
243
|
): string {
|
|
244
|
-
const userAgentOptions = buildUserAgentOptions(context, emitterOptions
|
|
244
|
+
const userAgentOptions = buildUserAgentOptions(context, emitterOptions);
|
|
245
245
|
const loggingOptions = buildLoggingOptions();
|
|
246
246
|
const credentials = buildCredentials(emitterOptions, endpointParam);
|
|
247
247
|
|
|
@@ -313,10 +313,14 @@ function buildLoggingOptions(): string | undefined {
|
|
|
313
313
|
return `{ logger: options.loggingOptions?.logger ?? logger.info }`;
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
/**
|
|
317
|
+
* Builds the `userAgentOptions` for the generated client, producing a telemetry
|
|
318
|
+
* prefix of the form `[<application_id> ]azsdk-js-<package>/<version>` per the Azure
|
|
319
|
+
* Core telemetry policy: https://azure.github.io/azure-sdk/general_azurecore.html#telemetry-policy
|
|
320
|
+
*/
|
|
316
321
|
export function buildUserAgentOptions(
|
|
317
322
|
context: StatementedNode,
|
|
318
323
|
emitterOptions: ModularEmitterOptions,
|
|
319
|
-
sdkUserAgentPrefix: string,
|
|
320
324
|
): string {
|
|
321
325
|
const userAgentStatements = [];
|
|
322
326
|
const prefixFromOptions = "const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix;";
|
|
@@ -329,21 +333,20 @@ export function buildUserAgentOptions(
|
|
|
329
333
|
const packageVersion = emitterOptions.options.packageDetails?.version ?? "";
|
|
330
334
|
|
|
331
335
|
const userAgentInfoStatement =
|
|
332
|
-
packageVersion && clientPackageName
|
|
336
|
+
packageVersion && clientPackageName
|
|
333
337
|
? "const userAgentInfo = `azsdk-js-" + clientPackageName + "/" + packageVersion + "`;"
|
|
334
338
|
: "";
|
|
335
339
|
|
|
336
|
-
if (userAgentInfoStatement) {
|
|
337
|
-
|
|
340
|
+
if (!userAgentInfoStatement) {
|
|
341
|
+
// Without package name/version we cannot build a meaningful telemetry token,
|
|
342
|
+
// so we leave the user agent untouched (the caller's userAgentOptions still flow
|
|
343
|
+
// through `...options`) and let core-rest-pipeline defaults apply.
|
|
344
|
+
return "";
|
|
338
345
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
"` : `" +
|
|
344
|
-
`${sdkUserAgentPrefix}` +
|
|
345
|
-
`${userAgentInfoStatement ? " ${userAgentInfo}`" : "`"}`
|
|
346
|
-
};`;
|
|
346
|
+
|
|
347
|
+
userAgentStatements.push(userAgentInfoStatement);
|
|
348
|
+
const userAgentPrefix =
|
|
349
|
+
"const userAgentPrefix = prefixFromOptions ? `${prefixFromOptions} ${userAgentInfo}` : `${userAgentInfo}`;";
|
|
347
350
|
userAgentStatements.push(userAgentPrefix);
|
|
348
351
|
|
|
349
352
|
context.addStatements(userAgentStatements.join("\n"));
|