@azure-tools/typespec-java 0.20.1 → 0.21.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/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +89 -47
- package/dist/src/code-model-builder.js.map +1 -1
- package/dist/src/common/client.d.ts +1 -1
- package/dist/src/common/client.d.ts.map +1 -1
- package/dist/src/common/client.js +1 -0
- package/dist/src/common/client.js.map +1 -1
- package/dist/src/common/code-model.d.ts +1 -1
- package/dist/src/common/code-model.d.ts.map +1 -1
- package/dist/src/common/code-model.js +2 -1
- package/dist/src/common/code-model.js.map +1 -1
- package/dist/src/common/operation.d.ts +2 -2
- package/dist/src/common/operation.d.ts.map +1 -1
- package/dist/src/common/operation.js +2 -1
- package/dist/src/common/operation.js.map +1 -1
- package/dist/src/common/schemas/choice.d.ts.map +1 -1
- package/dist/src/common/schemas/choice.js +2 -1
- package/dist/src/common/schemas/choice.js.map +1 -1
- package/dist/src/common/schemas/constant.d.ts +1 -1
- package/dist/src/common/schemas/constant.d.ts.map +1 -1
- package/dist/src/common/schemas/constant.js +1 -0
- package/dist/src/common/schemas/constant.js.map +1 -1
- package/dist/src/common/schemas/relationship.d.ts +2 -3
- package/dist/src/common/schemas/relationship.d.ts.map +1 -1
- package/dist/src/common/schemas/relationship.js +2 -2
- package/dist/src/common/schemas/relationship.js.map +1 -1
- package/dist/src/common/schemas/time.d.ts +1 -1
- package/dist/src/common/schemas/time.d.ts.map +1 -1
- package/dist/src/common/schemas/time.js +1 -0
- package/dist/src/common/schemas/time.js.map +1 -1
- package/dist/src/emitter.d.ts +5 -6
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +12 -14
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/external-schemas.d.ts.map +1 -1
- package/dist/src/external-schemas.js +3 -2
- package/dist/src/external-schemas.js.map +1 -1
- package/dist/src/models.d.ts +1 -3
- package/dist/src/models.d.ts.map +1 -1
- package/dist/src/models.js +2 -29
- package/dist/src/models.js.map +1 -1
- package/dist/src/operation-utils.d.ts +3 -3
- package/dist/src/operation-utils.d.ts.map +1 -1
- package/dist/src/operation-utils.js +2 -2
- package/dist/src/operation-utils.js.map +1 -1
- package/dist/src/type-utils.d.ts +5 -5
- package/dist/src/type-utils.d.ts.map +1 -1
- package/dist/src/type-utils.js +51 -14
- package/dist/src/type-utils.js.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +10 -4
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/{target → generator/http-client-generator/target}/emitter.jar +0 -0
- package/package.json +28 -28
- package/readme.md +2 -2
- package/dist/src/prenamer/formatter.d.ts +0 -11
- package/dist/src/prenamer/formatter.d.ts.map +0 -1
- package/dist/src/prenamer/formatter.js +0 -124
- package/dist/src/prenamer/formatter.js.map +0 -1
- package/dist/src/prenamer/naming-utils.d.ts +0 -67
- package/dist/src/prenamer/naming-utils.d.ts.map +0 -1
- package/dist/src/prenamer/naming-utils.js +0 -147
- package/dist/src/prenamer/naming-utils.js.map +0 -1
- package/dist/src/prenamer/prenamer.d.ts +0 -36
- package/dist/src/prenamer/prenamer.d.ts.map +0 -1
- package/dist/src/prenamer/prenamer.js +0 -333
- package/dist/src/prenamer/prenamer.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-java",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"TypeSpec"
|
|
@@ -42,20 +42,20 @@
|
|
|
42
42
|
"lib/*.tsp",
|
|
43
43
|
"dist/**",
|
|
44
44
|
"!dist/test/**",
|
|
45
|
-
"target/emitter.jar"
|
|
45
|
+
"generator/http-client-generator/target/emitter.jar"
|
|
46
46
|
],
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@azure-tools/typespec-azure-core": ">=0.
|
|
49
|
-
"@azure-tools/typespec-azure-resource-manager": ">=0.
|
|
50
|
-
"@azure-tools/typespec-autorest": ">=0.
|
|
51
|
-
"@azure-tools/typespec-azure-rulesets": ">=0.
|
|
52
|
-
"@azure-tools/typespec-client-generator-core": ">=0.
|
|
53
|
-
"@typespec/compiler": ">=0.
|
|
54
|
-
"@typespec/http": ">=0.
|
|
55
|
-
"@typespec/openapi": ">=0.
|
|
56
|
-
"@typespec/rest": ">=0.
|
|
57
|
-
"@typespec/versioning": ">=0.
|
|
58
|
-
"@typespec/xml": ">=0.
|
|
48
|
+
"@azure-tools/typespec-azure-core": ">=0.46.0 <1.0.0",
|
|
49
|
+
"@azure-tools/typespec-azure-resource-manager": ">=0.46.0 <1.0.0",
|
|
50
|
+
"@azure-tools/typespec-autorest": ">=0.46.0 <1.0.0",
|
|
51
|
+
"@azure-tools/typespec-azure-rulesets": ">=0.46.0 <1.0.0",
|
|
52
|
+
"@azure-tools/typespec-client-generator-core": ">=0.46.0 <1.0.0",
|
|
53
|
+
"@typespec/compiler": ">=0.60.0 <1.0.0",
|
|
54
|
+
"@typespec/http": ">=0.60.0 <1.0.0",
|
|
55
|
+
"@typespec/openapi": ">=0.60.0 <1.0.0",
|
|
56
|
+
"@typespec/rest": ">=0.60.0 <1.0.0",
|
|
57
|
+
"@typespec/versioning": ">=0.60.0 <1.0.0",
|
|
58
|
+
"@typespec/xml": ">=0.60.0 <1.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@autorest/codemodel": "~4.20.0",
|
|
@@ -63,29 +63,29 @@
|
|
|
63
63
|
"lodash": "~4.17.21"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@azure-tools/typespec-azure-core": "0.
|
|
67
|
-
"@azure-tools/typespec-azure-resource-manager": "0.
|
|
68
|
-
"@azure-tools/typespec-autorest": "0.
|
|
69
|
-
"@azure-tools/typespec-azure-rulesets": "0.
|
|
70
|
-
"@azure-tools/typespec-client-generator-core": "0.
|
|
66
|
+
"@azure-tools/typespec-azure-core": "0.46.0",
|
|
67
|
+
"@azure-tools/typespec-azure-resource-manager": "0.46.0",
|
|
68
|
+
"@azure-tools/typespec-autorest": "0.46.0",
|
|
69
|
+
"@azure-tools/typespec-azure-rulesets": "0.46.0",
|
|
70
|
+
"@azure-tools/typespec-client-generator-core": "0.46.0",
|
|
71
71
|
"@types/js-yaml": "~4.0.9",
|
|
72
72
|
"@types/lodash": "~4.17.7",
|
|
73
73
|
"@types/mocha": "~10.0.7",
|
|
74
|
-
"@types/node": "~22.5.
|
|
75
|
-
"@typescript-eslint/eslint-plugin": "~8.
|
|
76
|
-
"@typescript-eslint/parser": "~8.
|
|
77
|
-
"@typespec/compiler": "0.
|
|
78
|
-
"@typespec/http": "0.
|
|
79
|
-
"@typespec/openapi": "0.
|
|
80
|
-
"@typespec/rest": "0.
|
|
81
|
-
"@typespec/versioning": "0.
|
|
82
|
-
"@typespec/xml": "0.
|
|
74
|
+
"@types/node": "~22.5.4",
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "~8.5.0",
|
|
76
|
+
"@typescript-eslint/parser": "~8.5.0",
|
|
77
|
+
"@typespec/compiler": "0.60.0",
|
|
78
|
+
"@typespec/http": "0.60.0",
|
|
79
|
+
"@typespec/openapi": "0.60.0",
|
|
80
|
+
"@typespec/rest": "0.60.0",
|
|
81
|
+
"@typespec/versioning": "0.60.1",
|
|
82
|
+
"@typespec/xml": "0.60.0",
|
|
83
83
|
"c8": "~10.1.2",
|
|
84
84
|
"eslint": "~8.57.0",
|
|
85
85
|
"eslint-plugin-deprecation": "~3.0.0",
|
|
86
86
|
"mocha": "~10.7.3",
|
|
87
87
|
"prettier": "~3.3.3",
|
|
88
88
|
"rimraf": "~6.0.1",
|
|
89
|
-
"typescript": "~5.
|
|
89
|
+
"typescript": "~5.6.2"
|
|
90
90
|
}
|
|
91
91
|
}
|
package/readme.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Prerequisite
|
|
2
2
|
|
|
3
|
-
Install [Node.js](https://nodejs.org/en/download/)
|
|
3
|
+
Install [Node.js](https://nodejs.org/en/download/) 20 or above. (Verify by `node --version`)
|
|
4
4
|
|
|
5
5
|
Install [Java](https://docs.microsoft.com/java/openjdk/download) 11 or above. (Verify by `java --version`)
|
|
6
6
|
|
|
7
|
-
Install [TypeSpec](https://github.com/microsoft/typespec/) 0.
|
|
7
|
+
Install [TypeSpec](https://github.com/microsoft/typespec/) 0.60.
|
|
8
8
|
|
|
9
9
|
# Initialize TypeSpec Project
|
|
10
10
|
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type Styler = (identifier: string | Array<string>, removeDuplicates: boolean | undefined, overrides: Record<string, string> | undefined) => string;
|
|
2
|
-
export declare class Style {
|
|
3
|
-
static select(style: any, fallback: Styler, maxUppercasePreserve: number): Styler;
|
|
4
|
-
static kebab(identifier: string | Array<string>, removeDuplicates?: boolean, overrides?: Record<string, string>, maxUppercasePreserve?: number): string;
|
|
5
|
-
static space(identifier: string | Array<string>, removeDuplicates?: boolean, overrides?: Record<string, string>, maxUppercasePreserve?: number): string;
|
|
6
|
-
static snake(identifier: string | Array<string>, removeDuplicates?: boolean, overrides?: Record<string, string>, maxUppercasePreserve?: number): string;
|
|
7
|
-
static upper(identifier: string | Array<string>, removeDuplicates?: boolean, overrides?: Record<string, string>, maxUppercasePreserve?: number): string;
|
|
8
|
-
static pascal(identifier: string | Array<string>, removeDuplicates?: boolean, overrides?: Record<string, string>, maxUppercasePreserve?: number): string;
|
|
9
|
-
static camel(identifier: string | Array<string>, removeDuplicates?: boolean, overrides?: Record<string, string>, maxUppercasePreserve?: number): string;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.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,EACvB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACtC,oBAAoB,SAAI,GACvB,MAAM;IAST,MAAM,CAAC,KAAK,CACV,UAAU,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,EAClC,gBAAgB,UAAO,EACvB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACtC,oBAAoB,SAAI,GACvB,MAAM;CAYV"}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { fixLeadingNumber, removeSequentialDuplicates } from "@azure-tools/codegen";
|
|
2
|
-
function capitalize(s) {
|
|
3
|
-
return s ? `${s.charAt(0).toUpperCase()}${s.slice(1)}` : s;
|
|
4
|
-
}
|
|
5
|
-
function uncapitalize(s) {
|
|
6
|
-
return s ? `${s.charAt(0).toLowerCase()}${s.slice(1)}` : s;
|
|
7
|
-
}
|
|
8
|
-
function IsFullyUpperCase(identifier, maxUppercasePreserve) {
|
|
9
|
-
const len = identifier.length;
|
|
10
|
-
if (len > 1) {
|
|
11
|
-
if (len <= maxUppercasePreserve && identifier === identifier.toUpperCase()) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
if (len <= maxUppercasePreserve + 1 && identifier.endsWith("s")) {
|
|
15
|
-
const i = identifier.substring(0, len - 1);
|
|
16
|
-
if (i.toUpperCase() === i) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
function deconstruct(identifier, maxUppercasePreserve) {
|
|
24
|
-
if (Array.isArray(identifier)) {
|
|
25
|
-
return [...identifier.flatMap((each) => deconstruct(each, maxUppercasePreserve))];
|
|
26
|
-
}
|
|
27
|
-
return `${identifier}`
|
|
28
|
-
.replace(/([a-z]+)([A-Z])/g, "$1 $2") // Add a space in between camelCase words(e.g. fooBar => foo Bar)
|
|
29
|
-
.replace(/(\d+)/g, " $1 ") // Adds a space after numbers(e.g. foo123 => foo123 bar)
|
|
30
|
-
.replace(/\b([A-Z]+)([A-Z])s([^a-z])(.*)/g, "$1$2« $3$4") // Add a space after a plural uppper cased word(e.g. MBsFoo => MBs Foo)
|
|
31
|
-
.replace(/\b([A-Z]+)([A-Z])([a-z]+)/g, "$1 $2$3") // Add a space between an upper case word(2 char+) and the last captial case.(e.g. SQLConnection -> SQL Connection)
|
|
32
|
-
.replace(/«/g, "s")
|
|
33
|
-
.trim()
|
|
34
|
-
.split(/[\W|_]+/)
|
|
35
|
-
.map((each) => (IsFullyUpperCase(each, maxUppercasePreserve) ? each : each.toLowerCase()));
|
|
36
|
-
}
|
|
37
|
-
function wrap(prefix, postfix, style, maxUppercasePreserve) {
|
|
38
|
-
if (postfix || prefix) {
|
|
39
|
-
return (i, r, o) => typeof i === "string" && typeof o === "object"
|
|
40
|
-
? o[i.toLowerCase()] || `${prefix}${style(i, r, o, maxUppercasePreserve)}${postfix}`
|
|
41
|
-
: `${prefix}${style(i, r, o, maxUppercasePreserve)}${postfix}`;
|
|
42
|
-
}
|
|
43
|
-
return (i, r, o) => style(i, r, o, maxUppercasePreserve);
|
|
44
|
-
}
|
|
45
|
-
function applyFormat(normalizedContent, overrides = {}, separator = "", formatter = (s, i) => s) {
|
|
46
|
-
return normalizedContent
|
|
47
|
-
.map((each, index) => {
|
|
48
|
-
if (Object.keys(overrides).includes(each.toLowerCase())) {
|
|
49
|
-
const override = overrides[each.toLowerCase()];
|
|
50
|
-
if (override) {
|
|
51
|
-
return override;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return formatter(each, index);
|
|
55
|
-
})
|
|
56
|
-
.join(separator);
|
|
57
|
-
}
|
|
58
|
-
function normalize(identifier, removeDuplicates = true, overrides = {}, maxUppercasePreserve = 0) {
|
|
59
|
-
if (!identifier || identifier.length === 0) {
|
|
60
|
-
return [""];
|
|
61
|
-
}
|
|
62
|
-
return typeof identifier === "string"
|
|
63
|
-
? normalize(fixLeadingNumber(deconstruct(identifier, maxUppercasePreserve)), removeDuplicates, overrides, maxUppercasePreserve)
|
|
64
|
-
: removeDuplicates
|
|
65
|
-
? removeSequentialDuplicates(identifier)
|
|
66
|
-
: identifier;
|
|
67
|
-
}
|
|
68
|
-
export class Style {
|
|
69
|
-
static select(style, fallback, maxUppercasePreserve) {
|
|
70
|
-
if (style) {
|
|
71
|
-
const styles = /^([a-zA-Z0-9_]*?\+?)([a-zA-Z]+)(\+?[a-zA-Z0-9_]*)$/g.exec(style.replace(/\s*/g, ""));
|
|
72
|
-
if (styles) {
|
|
73
|
-
const prefix = styles[1] ? styles[1].substring(0, styles[1].length - 1) : "";
|
|
74
|
-
const postfix = styles[3] ? styles[3].substring(1) : "";
|
|
75
|
-
switch (styles[2]) {
|
|
76
|
-
case "camelcase":
|
|
77
|
-
case "camel":
|
|
78
|
-
return wrap(prefix, postfix, Style.camel, maxUppercasePreserve);
|
|
79
|
-
case "pascalcase":
|
|
80
|
-
case "pascal":
|
|
81
|
-
return wrap(prefix, postfix, Style.pascal, maxUppercasePreserve);
|
|
82
|
-
case "snakecase":
|
|
83
|
-
case "snake":
|
|
84
|
-
return wrap(prefix, postfix, Style.snake, maxUppercasePreserve);
|
|
85
|
-
case "uppercase":
|
|
86
|
-
case "upper":
|
|
87
|
-
return wrap(prefix, postfix, Style.upper, maxUppercasePreserve);
|
|
88
|
-
case "kebabcase":
|
|
89
|
-
case "kebab":
|
|
90
|
-
return wrap(prefix, postfix, Style.kebab, maxUppercasePreserve);
|
|
91
|
-
case "spacecase":
|
|
92
|
-
case "space":
|
|
93
|
-
return wrap(prefix, postfix, Style.space, maxUppercasePreserve);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return wrap("", "", fallback, maxUppercasePreserve);
|
|
98
|
-
}
|
|
99
|
-
static kebab(identifier, removeDuplicates = true, overrides = {}, maxUppercasePreserve = 0) {
|
|
100
|
-
return ((Object.keys(overrides).includes(identifier) && overrides[identifier]) ||
|
|
101
|
-
applyFormat(normalize(identifier, removeDuplicates, overrides, maxUppercasePreserve), overrides, "-").replace(/([^\d])-(\d+)/g, "$1$2"));
|
|
102
|
-
}
|
|
103
|
-
static space(identifier, removeDuplicates = true, overrides = {}, maxUppercasePreserve = 0) {
|
|
104
|
-
return ((Object.keys(overrides).includes(identifier) && overrides[identifier]) ||
|
|
105
|
-
applyFormat(normalize(identifier, removeDuplicates, overrides, maxUppercasePreserve), overrides, " ").replace(/([^\d]) (\d+)/g, "$1$2"));
|
|
106
|
-
}
|
|
107
|
-
static snake(identifier, removeDuplicates = true, overrides = {}, maxUppercasePreserve = 0) {
|
|
108
|
-
return ((Object.keys(overrides).includes(identifier) && overrides[identifier]) ||
|
|
109
|
-
applyFormat(normalize(identifier, removeDuplicates, overrides, maxUppercasePreserve), overrides, "_").replace(/([^\d])_(\d+)/g, "$1$2"));
|
|
110
|
-
}
|
|
111
|
-
static upper(identifier, removeDuplicates = true, overrides = {}, maxUppercasePreserve = 0) {
|
|
112
|
-
return ((Object.keys(overrides).includes(identifier) && overrides[identifier]) ||
|
|
113
|
-
applyFormat(normalize(identifier, removeDuplicates, overrides, maxUppercasePreserve), overrides, "_", (each) => each.toUpperCase()).replace(/([^\d])_(\d+)/g, "$1$2"));
|
|
114
|
-
}
|
|
115
|
-
static pascal(identifier, removeDuplicates = true, overrides = {}, maxUppercasePreserve = 0) {
|
|
116
|
-
return ((Object.keys(overrides).includes(identifier) && overrides[identifier]) ||
|
|
117
|
-
applyFormat(normalize(identifier, removeDuplicates, overrides, maxUppercasePreserve), overrides, "", (each) => capitalize(each)));
|
|
118
|
-
}
|
|
119
|
-
static camel(identifier, removeDuplicates = true, overrides = {}, maxUppercasePreserve = 0) {
|
|
120
|
-
return ((Object.keys(overrides).includes(identifier) && overrides[identifier]) ||
|
|
121
|
-
applyFormat(normalize(identifier, removeDuplicates, overrides, maxUppercasePreserve), overrides, "", (each, index) => index ? capitalize(each) : IsFullyUpperCase(each, maxUppercasePreserve) ? each : uncapitalize(each)));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
//# sourceMappingURL=formatter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../src/prenamer/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAcpF,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,YAAY,CAAC,CAAS;IAC7B,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,gBAAgB,CAAC,UAAkB,EAAE,oBAA4B;IACxE,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC;IAC9B,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACZ,IAAI,GAAG,IAAI,oBAAoB,IAAI,UAAU,KAAK,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC;YAC3E,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,GAAG,IAAI,oBAAoB,GAAG,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAChE,MAAM,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;YAC3C,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC;gBAC1B,OAAO,IAAI,CAAC;YACd,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CAAC,IAAI,SAAS,CAAS,UAAU,CAAC,CAAC;YACtF,WAAW,CAAC,SAAS,CAAC,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,oBAAoB,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAC5G,UAAU,CAAC,IAAI,CAAC,CACjB,CACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK,CACV,UAAkC,EAClC,gBAAgB,GAAG,IAAI,EACvB,YAAoC,EAAE,EACtC,oBAAoB,GAAG,CAAC;QAExB,OAAO,CACL,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAS,UAAU,CAAC,IAAI,SAAS,CAAS,UAAU,CAAC,CAAC;YACtF,WAAW,CACT,SAAS,CAAC,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,oBAAoB,CAAC,EACxE,SAAS,EACT,EAAE,EACF,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACd,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CACtG,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Languages } from "@autorest/codemodel";
|
|
2
|
-
import { Styler } from "./formatter.js";
|
|
3
|
-
export declare function getNameOptions(typeName: string, components: Array<string>): string[];
|
|
4
|
-
interface SetNameOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Remove consecutive duplicate words in the name.
|
|
7
|
-
* @example "FooBarBarSomething" -> "FooBarSomething"
|
|
8
|
-
*/
|
|
9
|
-
removeDuplicates?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Error message if a name is empty.
|
|
12
|
-
*/
|
|
13
|
-
nameEmptyErrorMessage?: string;
|
|
14
|
-
}
|
|
15
|
-
export interface Nameable {
|
|
16
|
-
language: Languages;
|
|
17
|
-
}
|
|
18
|
-
export declare class NamingService {
|
|
19
|
-
constructor();
|
|
20
|
-
setName(thing: Nameable, styler: Styler, defaultValue: string, overrides: Record<string, string>, options?: SetNameOptions): void;
|
|
21
|
-
setNameAllowEmpty(thing: Nameable, styler: Styler, defaultValue: string, overrides: Record<string, string>, options?: SetNameOptions): void;
|
|
22
|
-
}
|
|
23
|
-
export declare function isUnassigned(value: string): boolean;
|
|
24
|
-
export interface ScopeNamerOptions {
|
|
25
|
-
deduplicateNames?: boolean;
|
|
26
|
-
overrides?: Record<string, string>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Class that will style and resolve unique names for entities in the same scope.
|
|
30
|
-
*/
|
|
31
|
-
export declare class ScopeNamer {
|
|
32
|
-
private options;
|
|
33
|
-
private names;
|
|
34
|
-
constructor(options: ScopeNamerOptions);
|
|
35
|
-
/**
|
|
36
|
-
* Add a nameable entity to be styled and named.
|
|
37
|
-
* @param entity Nameable entity.
|
|
38
|
-
* @param styler Styler to use to render name.
|
|
39
|
-
* @param defaultName Default name in case entity doesn't have any specified.
|
|
40
|
-
*/
|
|
41
|
-
add(entity: Nameable, styler: Styler, defaultName?: string): void;
|
|
42
|
-
/**
|
|
43
|
-
* Returns true if the name is already used in this scope.
|
|
44
|
-
* @param name Name to check
|
|
45
|
-
* @returns Boolean
|
|
46
|
-
*/
|
|
47
|
-
isUsed(name: string): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Trigger the renaming process.
|
|
50
|
-
* Will go over all the entity and find best possible names.
|
|
51
|
-
*/
|
|
52
|
-
process(): void;
|
|
53
|
-
/**
|
|
54
|
-
* 1st pass of the name resolving where it tries to simplify names with duplicate consecutive words.
|
|
55
|
-
*/
|
|
56
|
-
private processSimplifyNames;
|
|
57
|
-
/**
|
|
58
|
-
* 2nd pass of the name resolving where it will deduplicate names used twice.
|
|
59
|
-
*/
|
|
60
|
-
private deduplicateNames;
|
|
61
|
-
/**
|
|
62
|
-
* Tries to find a new compatible name for the given schema.
|
|
63
|
-
*/
|
|
64
|
-
private deduplicateSchemaName;
|
|
65
|
-
}
|
|
66
|
-
export {};
|
|
67
|
-
//# sourceMappingURL=naming-utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"naming-utils.d.ts","sourceRoot":"","sources":["../../../src/prenamer/naming-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAS,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAI/C,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,YAiBzE;AAED,UAAU,cAAc;IACtB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAMD,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,qBAAa,aAAa;;IAGjB,OAAO,CACZ,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,OAAO,CAAC,EAAE,cAAc;IAQnB,iBAAiB,CACtB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,OAAO,CAAC,EAAE,cAAc;CAS3B;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,WAEzC;AAED,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAQD;;GAEG;AACH,qBAAa,UAAU;IAGF,OAAO,CAAC,OAAO;IAFlC,OAAO,CAAC,KAAK,CAAmC;gBAErB,OAAO,EAAE,iBAAiB;IAErD;;;;;OAKG;IACI,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;IAcjE;;;;OAIG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIpC;;;OAGG;IACI,OAAO;IAOd;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAwB5B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAWxB;;OAEG;IACH,OAAO,CAAC,qBAAqB;CAwB9B"}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { removeSequentialDuplicates, fixLeadingNumber, deconstruct } from "@azure-tools/codegen";
|
|
2
|
-
import { Style } from "./formatter.js";
|
|
3
|
-
import pkg from "lodash";
|
|
4
|
-
const { last } = pkg;
|
|
5
|
-
export function getNameOptions(typeName, components) {
|
|
6
|
-
const result = new Set();
|
|
7
|
-
// add a variant for each incrementally inclusive parent naming scheme.
|
|
8
|
-
for (let i = 0; i < components.length; i++) {
|
|
9
|
-
const subset = Style.pascal([...removeSequentialDuplicates(components.slice(-1 * i, components.length))]);
|
|
10
|
-
result.add(subset);
|
|
11
|
-
}
|
|
12
|
-
// add a second-to-last-ditch option as <typename>.<name>
|
|
13
|
-
result.add(Style.pascal([
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
15
|
-
...removeSequentialDuplicates([...fixLeadingNumber(deconstruct(typeName)), ...deconstruct(last(components))]),
|
|
16
|
-
]));
|
|
17
|
-
return [...result.values()];
|
|
18
|
-
}
|
|
19
|
-
const setNameDefaultOptions = Object.freeze({
|
|
20
|
-
removeDuplicates: true,
|
|
21
|
-
});
|
|
22
|
-
export class NamingService {
|
|
23
|
-
constructor() { }
|
|
24
|
-
setName(thing, styler, defaultValue, overrides, options) {
|
|
25
|
-
this.setNameAllowEmpty(thing, styler, defaultValue, overrides, options);
|
|
26
|
-
// if (!thing.language.default.name) {
|
|
27
|
-
// this.session.error(options?.nameEmptyErrorMessage ?? getNameEmptyError(thing), ["Prenamer", "NameEmpty"], thing);
|
|
28
|
-
// }
|
|
29
|
-
}
|
|
30
|
-
setNameAllowEmpty(thing, styler, defaultValue, overrides, options) {
|
|
31
|
-
options = { ...setNameDefaultOptions, ...options };
|
|
32
|
-
thing.language.default.name = styler(defaultValue && isUnassigned(thing.language.default.name) ? defaultValue : thing.language.default.name, options.removeDuplicates, overrides);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export function isUnassigned(value) {
|
|
36
|
-
return !value || value.indexOf("·") > -1;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Class that will style and resolve unique names for entities in the same scope.
|
|
40
|
-
*/
|
|
41
|
-
export class ScopeNamer {
|
|
42
|
-
constructor(options) {
|
|
43
|
-
this.options = options;
|
|
44
|
-
this.names = new Map();
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Add a nameable entity to be styled and named.
|
|
48
|
-
* @param entity Nameable entity.
|
|
49
|
-
* @param styler Styler to use to render name.
|
|
50
|
-
* @param defaultName Default name in case entity doesn't have any specified.
|
|
51
|
-
*/
|
|
52
|
-
add(entity, styler, defaultName) {
|
|
53
|
-
const initialName = defaultName && isUnassigned(entity.language.default.name) ? defaultName : entity.language.default.name;
|
|
54
|
-
const name = styler(initialName, false, this.options.overrides);
|
|
55
|
-
const list = this.names.get(name);
|
|
56
|
-
const entry = { entity, styler, initialName };
|
|
57
|
-
if (list) {
|
|
58
|
-
list.push(entry);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
this.names.set(name, [entry]);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Returns true if the name is already used in this scope.
|
|
66
|
-
* @param name Name to check
|
|
67
|
-
* @returns Boolean
|
|
68
|
-
*/
|
|
69
|
-
isUsed(name) {
|
|
70
|
-
return this.names.has(name);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Trigger the renaming process.
|
|
74
|
-
* Will go over all the entity and find best possible names.
|
|
75
|
-
*/
|
|
76
|
-
process() {
|
|
77
|
-
const state = this.processSimplifyNames();
|
|
78
|
-
if (this.options.deduplicateNames) {
|
|
79
|
-
this.deduplicateNames(state);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* 1st pass of the name resolving where it tries to simplify names with duplicate consecutive words.
|
|
84
|
-
*/
|
|
85
|
-
processSimplifyNames() {
|
|
86
|
-
const processedNames = new Map();
|
|
87
|
-
for (const [name, entities] of this.names.entries()) {
|
|
88
|
-
for (const { entity, styler, initialName } of entities) {
|
|
89
|
-
let selectedName = name;
|
|
90
|
-
const noDupName = styler(initialName, true, this.options.overrides);
|
|
91
|
-
if (noDupName !== name) {
|
|
92
|
-
if (!this.names.has(noDupName) && !processedNames.has(noDupName)) {
|
|
93
|
-
selectedName = noDupName;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
entity.language.default.name = selectedName;
|
|
97
|
-
const entries = processedNames.get(selectedName);
|
|
98
|
-
if (entries) {
|
|
99
|
-
entries.push(entity);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
processedNames.set(selectedName, [entity]);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return processedNames;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* 2nd pass of the name resolving where it will deduplicate names used twice.
|
|
110
|
-
*/
|
|
111
|
-
deduplicateNames(names) {
|
|
112
|
-
const entityNames = new Set(names.keys());
|
|
113
|
-
for (const [_, entries] of names.entries()) {
|
|
114
|
-
if (entries.length > 1) {
|
|
115
|
-
for (const entity of entries.slice(1)) {
|
|
116
|
-
this.deduplicateSchemaName(entity, entityNames);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Tries to find a new compatible name for the given schema.
|
|
123
|
-
*/
|
|
124
|
-
deduplicateSchemaName(schema, entityNames) {
|
|
125
|
-
const schemaName = schema.language.default.name;
|
|
126
|
-
const maxDedupes = 1000;
|
|
127
|
-
if (entityNames.has(schemaName)) {
|
|
128
|
-
for (let i = 1; i <= maxDedupes; i++) {
|
|
129
|
-
const newName = `${schemaName}AutoGenerated${i === 1 ? "" : i}`;
|
|
130
|
-
if (!entityNames.has(newName)) {
|
|
131
|
-
schema.language.default.name = newName;
|
|
132
|
-
entityNames.add(newName);
|
|
133
|
-
// this.session.warning(`Deduplicating schema name: '${schemaName}' -> '${newName}'`, [
|
|
134
|
-
// "PreNamer/DeduplicateName",
|
|
135
|
-
// ]);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
// this.session.error(
|
|
140
|
-
// `Attempted to deduplicate schema name '${schema.language.default.name}' more than ${maxDedupes} times and failed.`,
|
|
141
|
-
// ["PreNamer/DeduplicateName"],
|
|
142
|
-
// );
|
|
143
|
-
}
|
|
144
|
-
entityNames.add(schemaName);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
//# sourceMappingURL=naming-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"naming-utils.js","sourceRoot":"","sources":["../../../src/prenamer/naming-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACjG,OAAO,EAAE,KAAK,EAAU,MAAM,gBAAgB,CAAC;AAC/C,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;AAErB,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,UAAyB;IACxE,MAAM,MAAM,GAAG,IAAI,GAAG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oBACzB,uFAAuF;oBACvF,gCAAgC;oBAChC,MAAM;oBACN,OAAO;gBACT,CAAC;YACH,CAAC;YAED,sBAAsB;YACtB,wHAAwH;YACxH,kCAAkC;YAClC,KAAK;QACP,CAAC;QAED,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ObjectSchema } from "@autorest/codemodel";
|
|
2
|
-
import { CodeModel } from "../common/code-model.js";
|
|
3
|
-
import { Style } from "./formatter.js";
|
|
4
|
-
export declare class PreNamer {
|
|
5
|
-
codeModel: CodeModel;
|
|
6
|
-
options: any;
|
|
7
|
-
format: {
|
|
8
|
-
parameter: typeof Style.camel;
|
|
9
|
-
property: typeof Style.camel;
|
|
10
|
-
operation: typeof Style.camel;
|
|
11
|
-
operationGroup: typeof Style.pascal;
|
|
12
|
-
responseHeader: typeof Style.camel;
|
|
13
|
-
choice: typeof Style.pascal;
|
|
14
|
-
choiceValue: typeof Style.upper;
|
|
15
|
-
constant: typeof Style.pascal;
|
|
16
|
-
constantParameter: typeof Style.camel;
|
|
17
|
-
type: typeof Style.pascal;
|
|
18
|
-
client: typeof Style.pascal;
|
|
19
|
-
local: typeof Style.camel;
|
|
20
|
-
global: typeof Style.pascal;
|
|
21
|
-
override: Record<string, string>;
|
|
22
|
-
};
|
|
23
|
-
enum: number;
|
|
24
|
-
constant: number;
|
|
25
|
-
private namingService;
|
|
26
|
-
constructor(codeModel: CodeModel);
|
|
27
|
-
init(): this;
|
|
28
|
-
process(): CodeModel;
|
|
29
|
-
private processChoiceNames;
|
|
30
|
-
private setParameterNames;
|
|
31
|
-
private setResponseHeaderNames;
|
|
32
|
-
fixParameterCollisions(): void;
|
|
33
|
-
fixCollisions(schema: ObjectSchema): void;
|
|
34
|
-
fixPropertyCollisions(): void;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=prenamer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prenamer.d.ts","sourceRoot":"","sources":["../../../src/prenamer/prenamer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAOb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAKpD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAIvC,qBAAa,QAAQ;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,GAAG,CAAM;IAClB,MAAM;;;;;;;;;;;;;;kBAcO,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;MACjC;IAEF,IAAI,SAAK;IACT,QAAQ,SAAK;IAEb,OAAO,CAAC,aAAa,CAAgB;gBAEzB,SAAS,EAAE,SAAS;IAKhC,IAAI;IAyCJ,OAAO;IAoNP,OAAO,CAAC,kBAAkB;IAa1B,OAAO,CAAC,iBAAiB;IAuBzB,OAAO,CAAC,sBAAsB;IAa9B,sBAAsB;IAkCtB,aAAa,CAAC,MAAM,EAAE,YAAY;IAgClC,qBAAqB;CAKtB"}
|