@azure-tools/typespec-ts 0.27.0 → 0.28.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/CHANGELOG.md +11 -0
- package/README.md +0 -8
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +14 -88
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +0 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +0 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +1 -1
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts +1 -1
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +1 -1
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +12 -7
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +1 -1
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +1 -1
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildPagingFiles.d.ts +2 -2
- package/dist/src/modular/buildPagingFiles.d.ts.map +1 -1
- package/dist/src/modular/buildPagingFiles.js +2 -2
- package/dist/src/modular/buildPagingFiles.js.map +1 -1
- package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
- package/dist/src/modular/buildProjectFiles.js +4 -3
- package/dist/src/modular/buildProjectFiles.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts +2 -2
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +2 -2
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +1 -1
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts +2 -2
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +2 -2
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +2 -2
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +1 -0
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/transform/transform.js +5 -5
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.d.ts.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.js +1 -2
- package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.js +8 -6
- package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
- package/dist/src/transform/transformParameters.d.ts +1 -1
- package/dist/src/transform/transformParameters.d.ts.map +1 -1
- package/dist/src/transform/transformParameters.js +7 -21
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformPaths.d.ts +2 -3
- package/dist/src/transform/transformPaths.d.ts.map +1 -1
- package/dist/src/transform/transformPaths.js +19 -9
- package/dist/src/transform/transformPaths.js.map +1 -1
- package/dist/src/transform/transformResponses.d.ts +1 -1
- package/dist/src/transform/transformResponses.d.ts.map +1 -1
- package/dist/src/transform/transformResponses.js +1 -1
- package/dist/src/transform/transformResponses.js.map +1 -1
- package/dist/src/transform/transformSchemas.d.ts +1 -2
- package/dist/src/transform/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js +11 -21
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.d.ts +1 -1
- package/dist/src/transform/transformTelemetryInfo.d.ts.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.js +1 -1
- package/dist/src/transform/transformTelemetryInfo.js.map +1 -1
- package/dist/src/utils/mediaTypes.d.ts +1 -1
- package/dist/src/utils/mediaTypes.d.ts.map +1 -1
- package/dist/src/utils/mediaTypes.js +5 -0
- package/dist/src/utils/mediaTypes.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts +2 -1
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +56 -16
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +2 -2
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +12 -8
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -25
- package/src/index.ts +14 -102
- package/src/lib.ts +0 -2
- package/src/modular/buildClassicalClient.ts +2 -2
- package/src/modular/buildClientContext.ts +2 -2
- package/src/modular/buildCodeModel.ts +15 -7
- package/src/modular/buildOperations.ts +1 -1
- package/src/modular/buildPagingFiles.ts +2 -2
- package/src/modular/buildProjectFiles.ts +4 -3
- package/src/modular/buildRootIndex.ts +3 -3
- package/src/modular/buildSubpathIndex.ts +1 -1
- package/src/modular/emitModels.ts +4 -4
- package/src/modular/helpers/classicalOperationHelpers.ts +8 -2
- package/src/modular/helpers/operationHelpers.ts +2 -2
- package/src/modular/modularCodeModel.ts +1 -0
- package/src/transform/transform.ts +6 -6
- package/src/transform/transformApiVersionInfo.ts +1 -2
- package/src/transform/transformHelperFunctionDetails.ts +7 -14
- package/src/transform/transformParameters.ts +9 -27
- package/src/transform/transformPaths.ts +28 -11
- package/src/transform/transformResponses.ts +2 -2
- package/src/transform/transformSchemas.ts +3 -22
- package/src/transform/transformTelemetryInfo.ts +2 -2
- package/src/utils/mediaTypes.ts +11 -1
- package/src/utils/modelUtils.ts +79 -15
- package/src/utils/operationUtil.ts +11 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "An experimental TypeSpec emitter for TypeScript RLC",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@types/chai": "^4.3.1",
|
|
11
|
-
"@types/mocha": "^
|
|
11
|
+
"@types/mocha": "^10.0.6",
|
|
12
12
|
"@types/node": "^18.0.0",
|
|
13
13
|
"@types/fs-extra": "^9.0.13",
|
|
14
14
|
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"chai": "^4.3.6",
|
|
17
17
|
"mkdirp": "^3.0.1",
|
|
18
18
|
"eslint": "^8.9.0",
|
|
19
|
-
"mocha": "^
|
|
19
|
+
"mocha": "^10.4.0",
|
|
20
20
|
"rimraf": "^5.0.0",
|
|
21
21
|
"ts-node": "~10.9.1",
|
|
22
22
|
"typescript": "~5.4.5",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@azure-tools/cadl-ranch-expect": "^0.13.3",
|
|
26
26
|
"@azure-tools/cadl-ranch": "^0.12.7",
|
|
27
27
|
"chalk": "^4.0.0",
|
|
28
|
-
"@azure-rest/core-client": "^
|
|
28
|
+
"@azure-rest/core-client": "^2.0.0",
|
|
29
29
|
"@azure/core-auth": "^1.6.0",
|
|
30
30
|
"cross-env": "^7.0.3",
|
|
31
31
|
"@azure/core-paging": "^1.5.0",
|
|
@@ -36,15 +36,16 @@
|
|
|
36
36
|
"eslint-plugin-require-extensions": "0.1.3",
|
|
37
37
|
"@typespec/ts-http-runtime": "1.0.0-alpha.20240314.2",
|
|
38
38
|
"@azure-tools/typespec-azure-core": ">=0.41.0 <1.0.0",
|
|
39
|
-
"@azure-tools/typespec-client-generator-core": "0.
|
|
39
|
+
"@azure-tools/typespec-client-generator-core": ">=0.41.5 <1.0.0",
|
|
40
40
|
"@typespec/compiler": ">=0.55.0 <1.0.0",
|
|
41
41
|
"@typespec/http": ">=0.55.0 <1.0.0",
|
|
42
42
|
"@typespec/rest": ">=0.55.0 <1.0.0",
|
|
43
|
-
"@typespec/versioning": ">=0.55.0 <1.0.0"
|
|
43
|
+
"@typespec/versioning": ">=0.55.0 <1.0.0",
|
|
44
|
+
"npm-run-all": "~4.1.5"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
47
|
"@azure-tools/typespec-azure-core": ">=0.41.0 <1.0.0",
|
|
47
|
-
"@azure-tools/typespec-client-generator-core": "0.
|
|
48
|
+
"@azure-tools/typespec-client-generator-core": ">=0.41.5 <1.0.0",
|
|
48
49
|
"@typespec/compiler": ">=0.55.0 <1.0.0",
|
|
49
50
|
"@typespec/http": ">=0.55.0 <1.0.0",
|
|
50
51
|
"@typespec/rest": ">=0.55.0 <1.0.0",
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
"dependencies": {
|
|
54
55
|
"prettier": "^3.1.0",
|
|
55
56
|
"tslib": "^2.3.1",
|
|
56
|
-
"@azure-tools/rlc-common": "^0.
|
|
57
|
+
"@azure-tools/rlc-common": "^0.28.0",
|
|
57
58
|
"ts-morph": "^15.1.0",
|
|
58
59
|
"fs-extra": "^11.1.0"
|
|
59
60
|
},
|
|
@@ -82,27 +83,30 @@
|
|
|
82
83
|
"lint:fix": "eslint src --fix --ext .ts",
|
|
83
84
|
"format": "npm run -s prettier -- --write",
|
|
84
85
|
"check-format": "npm run prettier -- --check",
|
|
85
|
-
"prettier": "prettier --config ./.prettierrc src/**/*.ts",
|
|
86
|
+
"prettier": "prettier --config ./.prettierrc \"src/**/*.ts\"",
|
|
86
87
|
"check:tree": "node --loader ts-node/esm ./test/commands/check-clean-tree.ts",
|
|
87
|
-
"integration-test-ci": "npm
|
|
88
|
-
"integration-test-ci:
|
|
89
|
-
"integration-test-ci:
|
|
90
|
-
"integration-test-ci:
|
|
91
|
-
"integration-test-ci:non-branded-
|
|
88
|
+
"integration-test-ci": "npm-run-all copy:typespec integration-test-ci:rlc integration-test-ci:modular integration-test-ci:non-branded-rlc integration-test-ci:non-branded-modular",
|
|
89
|
+
"integration-test-ci:sequential": "npm-run-all --serial copy:typespec integration-test-ci:modular && npm run integration-test-ci:modular",
|
|
90
|
+
"integration-test-ci:rlc": "npm-run-all --silent -p start-test-server:rlc --race generate-and-run:rlc",
|
|
91
|
+
"integration-test-ci:modular": "npm-run-all --silent -p start-test-server:modular --race generate-and-run:modular",
|
|
92
|
+
"integration-test-ci:non-branded-rlc": "npm-run-all --silent -p start-test-server:non-branded-rlc --race generate-and-run:non-branded-rlc",
|
|
93
|
+
"integration-test-ci:non-branded-modular": "npm-run-all --silent -p start-test-server:non-branded-modular --race generate-and-run:non-branded-modular",
|
|
92
94
|
"start-test-server": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./coverage/cadl-ranch-coverage-typescript.json",
|
|
93
|
-
"start-test-server:rlc": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http
|
|
94
|
-
"start-test-server:modular": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./coverage/cadl-ranch-coverage-typescript-modular-azure.json",
|
|
95
|
-
"start-test-server:non-branded-rlc": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./coverage/cadl-ranch-coverage-typescript-rlc-standard.json",
|
|
96
|
-
"start-test-server:non-branded-modular": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./coverage/cadl-ranch-coverage-typescript-modular-standard.json",
|
|
95
|
+
"start-test-server:rlc": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./coverage/cadl-ranch-coverage-typescript-rlc-azure.json",
|
|
96
|
+
"start-test-server:modular": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --port 3002 --coverageFile ./coverage/cadl-ranch-coverage-typescript-modular-azure.json",
|
|
97
|
+
"start-test-server:non-branded-rlc": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --port 3003 --coverageFile ./coverage/cadl-ranch-coverage-typescript-rlc-standard.json",
|
|
98
|
+
"start-test-server:non-branded-modular": "mkdirp -p coverage && npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --port 3004 --coverageFile ./coverage/cadl-ranch-coverage-typescript-modular-standard.json",
|
|
97
99
|
"copy:typespec": "rm -rf temp && mkdirp -p temp && cp -r ./node_modules/@azure-tools/cadl-ranch-specs/* ./temp && cp -r ./test/integration/typespec/* ./temp/http",
|
|
98
|
-
"generate-and-run:rlc": "npm run generate-tsp-only:rlc && npm run integration-test:alone:rlc && npm run stop-test-server",
|
|
99
|
-
"generate-and-run:modular": "npm run generate-tsp-only:modular && npm run integration-test:alone:modular && npm run stop-test-server",
|
|
100
|
+
"generate-and-run:rlc": "npm run generate-tsp-only:rlc && npm run integration-test:alone:rlc && npm run stop-test-server -- -p 3000",
|
|
101
|
+
"generate-and-run:modular": "npm run generate-tsp-only:modular && npm run integration-test:alone:modular && npm run stop-test-server -- -p 3002",
|
|
102
|
+
"generate-and-run:non-branded-rlc": "npm run generate-tsp-only:non-branded-rlc && npm run integration-test:alone:non-branded-rlc && npm run stop-test-server -- -p 3003",
|
|
103
|
+
"generate-and-run:non-branded-modular": "npm run generate-tsp-only:non-branded-modular && npm run integration-test:alone:non-branded-modular && npm run stop-test-server -- -p 3004",
|
|
100
104
|
"generate-tsp-only": "npm run generate-tsp-only:rlc && npm run generate-tsp-only:modular && npm run generate-tsp-only:non-branded-rlc && npm run generate-tsp-only:non-branded-modular",
|
|
101
|
-
"generate-tsp-only:rlc": "node
|
|
102
|
-
"generate-tsp-only:modular": "node
|
|
105
|
+
"generate-tsp-only:rlc": "node ./test/commands/gen-cadl-ranch.js --tag=rlc",
|
|
106
|
+
"generate-tsp-only:modular": "node ./test/commands/gen-cadl-ranch.js --tag=modular",
|
|
103
107
|
"generate-tsp-only:non-branded": "npm run generate-tsp-only:non-branded-rlc && npm run generate-tsp-only:non-branded-modular",
|
|
104
|
-
"generate-tsp-only:non-branded-rlc": "node
|
|
105
|
-
"generate-tsp-only:non-branded-modular": "node
|
|
108
|
+
"generate-tsp-only:non-branded-rlc": "node ./test/commands/gen-cadl-ranch.js --tag=non-branded-rlc",
|
|
109
|
+
"generate-tsp-only:non-branded-modular": "node ./test/commands/gen-cadl-ranch.js --tag=non-branded-modular",
|
|
106
110
|
"regen-test-baselines": "npm run generate-tsp-only && npm run generate-tsp-only:non-branded",
|
|
107
111
|
"integration-test:alone": "npm run integration-test:alone:rlc && npm run integration-test:alone:modular",
|
|
108
112
|
"integration-test:alone:rlc": "cross-env TS_NODE_PROJECT=tsconfig.integration.json mocha -r ts-node/register --experimental-specifier-resolution=node --timeout 36000 ./test/integration/*.spec.ts",
|
|
@@ -110,7 +114,7 @@
|
|
|
110
114
|
"integration-test:alone:non-branded-rlc": "cross-env TS_NODE_PROJECT=tsconfig.integration.json mocha -r ts-node/register --experimental-specifier-resolution=node --timeout 36000 ./test/nonBrandedIntegration/rlc/*.spec.ts",
|
|
111
115
|
"integration-test:alone:non-branded-modular": "cross-env TS_NODE_PROJECT=tsconfig.integration.json mocha -r ts-node/register --experimental-specifier-resolution=node --timeout 36000 ./test/nonBrandedIntegration/modular/*.spec.ts",
|
|
112
116
|
"stop-test-server": "npx cadl-ranch server stop",
|
|
113
|
-
"unit-test": "npm
|
|
117
|
+
"unit-test": "npm-run-all --parallel unit-test:rlc unit-test:modular",
|
|
114
118
|
"unit-test:rlc": "cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --experimental-specifier-resolution=node --experimental-modules=true --timeout 36000 './test/unit/**/*.spec.ts'",
|
|
115
119
|
"unit-test:modular": "cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --experimental-specifier-resolution=node --experimental-modules=true --no-timeout './test/modularUnit/**/*.spec.ts'"
|
|
116
120
|
}
|
package/src/index.ts
CHANGED
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
import { transformRLCModel } from "./transform/transform.js";
|
|
38
38
|
import { emitContentByBuilder, emitModels } from "./utils/emitUtil.js";
|
|
39
39
|
import { createSdkContext } from "@azure-tools/typespec-client-generator-core";
|
|
40
|
-
import { Project
|
|
40
|
+
import { Project } from "ts-morph";
|
|
41
41
|
import { buildClientContext } from "./modular/buildClientContext.js";
|
|
42
42
|
import { emitCodeModel } from "./modular/buildCodeModel.js";
|
|
43
43
|
import {
|
|
@@ -211,48 +211,44 @@ export async function $onEmit(context: EmitContext) {
|
|
|
211
211
|
|
|
212
212
|
const isMultiClients = modularCodeModel.clients.length > 1;
|
|
213
213
|
for (const subClient of modularCodeModel.clients) {
|
|
214
|
-
buildModels(
|
|
215
|
-
buildModelsOptions(
|
|
214
|
+
buildModels(subClient, modularCodeModel);
|
|
215
|
+
buildModelsOptions(subClient, modularCodeModel);
|
|
216
216
|
const hasClientUnexpectedHelper =
|
|
217
217
|
needUnexpectedHelper.get(subClient.rlcClientName) ?? false;
|
|
218
218
|
buildSerializeUtils(modularCodeModel);
|
|
219
|
-
buildPagingTypes(
|
|
219
|
+
buildPagingTypes(subClient, modularCodeModel);
|
|
220
220
|
buildModularPagingHelpers(
|
|
221
|
-
modularCodeModel,
|
|
222
221
|
subClient,
|
|
222
|
+
modularCodeModel,
|
|
223
223
|
hasClientUnexpectedHelper,
|
|
224
224
|
isMultiClients
|
|
225
225
|
);
|
|
226
226
|
buildOperationFiles(
|
|
227
|
+
subClient,
|
|
227
228
|
dpgContext,
|
|
228
229
|
modularCodeModel,
|
|
229
|
-
subClient,
|
|
230
230
|
hasClientUnexpectedHelper
|
|
231
231
|
);
|
|
232
|
-
buildClientContext(dpgContext, modularCodeModel
|
|
233
|
-
buildSubpathIndexFile(
|
|
232
|
+
buildClientContext(subClient, dpgContext, modularCodeModel);
|
|
233
|
+
buildSubpathIndexFile(subClient, modularCodeModel, "models");
|
|
234
234
|
if (dpgContext.rlcOptions?.hierarchyClient) {
|
|
235
|
-
buildSubpathIndexFile(
|
|
235
|
+
buildSubpathIndexFile(subClient, modularCodeModel, "api");
|
|
236
236
|
} else {
|
|
237
|
-
buildSubpathIndexFile(
|
|
237
|
+
buildSubpathIndexFile(subClient, modularCodeModel, "api", {
|
|
238
238
|
exportIndex: true
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
buildClassicalClient(dpgContext, modularCodeModel
|
|
242
|
+
buildClassicalClient(subClient, dpgContext, modularCodeModel);
|
|
243
243
|
buildClassicOperationFiles(modularCodeModel, subClient);
|
|
244
|
-
buildSubpathIndexFile(
|
|
244
|
+
buildSubpathIndexFile(subClient, modularCodeModel, "classic", {
|
|
245
245
|
exportIndex: true,
|
|
246
246
|
interfaceOnly: true
|
|
247
247
|
});
|
|
248
248
|
if (isMultiClients) {
|
|
249
|
-
buildSubClientIndexFile(
|
|
249
|
+
buildSubClientIndexFile(subClient, modularCodeModel);
|
|
250
250
|
}
|
|
251
|
-
buildRootIndex(
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (!emitterOptions.generateOrphanModels) {
|
|
255
|
-
removeUnusedInterfaces(project);
|
|
251
|
+
buildRootIndex(subClient, modularCodeModel, rootIndexFile);
|
|
256
252
|
}
|
|
257
253
|
|
|
258
254
|
for (const file of project.getSourceFiles()) {
|
|
@@ -337,87 +333,3 @@ export async function $onEmit(context: EmitContext) {
|
|
|
337
333
|
}
|
|
338
334
|
}
|
|
339
335
|
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Removing this for now, as it has some problem when we have two models with the same name and only one of them is unused, this function will end up removing the other used models.
|
|
343
|
-
*/
|
|
344
|
-
export function removeUnusedInterfaces(project: Project) {
|
|
345
|
-
const allInterfaces = project.getSourceFiles().flatMap((file) =>
|
|
346
|
-
file.getInterfaces().map((interfaceDeclaration) => {
|
|
347
|
-
return { interfaceDeclaration, filepath: file.getFilePath() };
|
|
348
|
-
})
|
|
349
|
-
);
|
|
350
|
-
|
|
351
|
-
const unusedInterfaces = allInterfaces.filter((interfaceDeclaration) => {
|
|
352
|
-
const references = interfaceDeclaration.interfaceDeclaration
|
|
353
|
-
.findReferencesAsNodes()
|
|
354
|
-
.filter((node) => {
|
|
355
|
-
const kind = node.getParent()?.getKind();
|
|
356
|
-
return (
|
|
357
|
-
kind !== SyntaxKind.ExportSpecifier &&
|
|
358
|
-
kind !== SyntaxKind.InterfaceDeclaration
|
|
359
|
-
);
|
|
360
|
-
});
|
|
361
|
-
return references.length === 0;
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
unusedInterfaces.forEach((interfaceDeclaration) => {
|
|
365
|
-
const references = interfaceDeclaration.interfaceDeclaration
|
|
366
|
-
.findReferencesAsNodes()
|
|
367
|
-
.filter((node) => {
|
|
368
|
-
const kind = node.getParent()?.getKind();
|
|
369
|
-
return kind === SyntaxKind.ExportSpecifier;
|
|
370
|
-
});
|
|
371
|
-
const map = new Map<string, string>();
|
|
372
|
-
references.forEach((node) => {
|
|
373
|
-
const exportPath = node.getSourceFile().getFilePath();
|
|
374
|
-
map.set(exportPath, node.getText());
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
// Get the index.ts file
|
|
378
|
-
const indexFiles = project.getSourceFiles().filter((file) => {
|
|
379
|
-
return file.getFilePath().endsWith("index.ts");
|
|
380
|
-
}); // Adjust the path to your index.ts file
|
|
381
|
-
// to make sure the top level index file is in the last
|
|
382
|
-
const sortedIndexFiles = indexFiles.sort((idx1, idx2) => {
|
|
383
|
-
return (
|
|
384
|
-
idx2.getFilePath().split("/").length -
|
|
385
|
-
idx1.getFilePath().split("/").length
|
|
386
|
-
);
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
const matchAliasNodes: string[] = [];
|
|
390
|
-
for (const indexFile of sortedIndexFiles) {
|
|
391
|
-
const filepath = indexFile.getFilePath();
|
|
392
|
-
if (map.has(filepath)) {
|
|
393
|
-
// Get all export declarations
|
|
394
|
-
const exportDeclarations = indexFile.getExportDeclarations();
|
|
395
|
-
|
|
396
|
-
// Iterate over each export declaration
|
|
397
|
-
exportDeclarations.forEach((exportDeclaration) => {
|
|
398
|
-
// Find named exports that match the unused interface
|
|
399
|
-
const matchingExports = exportDeclaration
|
|
400
|
-
.getNamedExports()
|
|
401
|
-
.filter((ne) => {
|
|
402
|
-
const aliasNode = ne.getAliasNode();
|
|
403
|
-
if (
|
|
404
|
-
aliasNode &&
|
|
405
|
-
aliasNode.getText() !== map.get(filepath) &&
|
|
406
|
-
ne.getName() === map.get(filepath)
|
|
407
|
-
) {
|
|
408
|
-
matchAliasNodes.push(aliasNode.getText());
|
|
409
|
-
}
|
|
410
|
-
return (
|
|
411
|
-
matchAliasNodes.indexOf(ne.getName()) > -1 ||
|
|
412
|
-
ne.getName() === map.get(filepath) ||
|
|
413
|
-
ne.getAliasNode()?.getText() === map.get(filepath)
|
|
414
|
-
);
|
|
415
|
-
});
|
|
416
|
-
// Remove the matching exports
|
|
417
|
-
matchingExports.forEach((me) => me.remove());
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
interfaceDeclaration.interfaceDeclaration.remove();
|
|
422
|
-
});
|
|
423
|
-
}
|
package/src/lib.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { Options } from "prettier";
|
|
|
11
11
|
|
|
12
12
|
export interface EmitterOptions extends RLCOptions {
|
|
13
13
|
branded?: boolean;
|
|
14
|
-
generateOrphanModels?: boolean;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
|
|
@@ -84,7 +83,6 @@ export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
|
|
|
84
83
|
hierarchyClient: { type: "boolean", nullable: true },
|
|
85
84
|
branded: { type: "boolean", nullable: true },
|
|
86
85
|
flavor: { type: "string", nullable: true },
|
|
87
|
-
generateOrphanModels: { type: "boolean", nullable: true },
|
|
88
86
|
moduleKind: {
|
|
89
87
|
type: "string",
|
|
90
88
|
nullable: true,
|
|
@@ -23,9 +23,9 @@ import { getOperationFunction } from "./helpers/operationHelpers.js";
|
|
|
23
23
|
import { getImportSpecifier } from "@azure-tools/rlc-common";
|
|
24
24
|
|
|
25
25
|
export function buildClassicalClient(
|
|
26
|
+
client: Client,
|
|
26
27
|
dpgContext: SdkContext,
|
|
27
|
-
codeModel: ModularCodeModel
|
|
28
|
-
client: Client
|
|
28
|
+
codeModel: ModularCodeModel
|
|
29
29
|
) {
|
|
30
30
|
const { description } = client;
|
|
31
31
|
const modularClientName = getClientName(client);
|
|
@@ -20,9 +20,9 @@ import { getType } from "./helpers/typeHelpers.js";
|
|
|
20
20
|
* This function creates the file containing the modular client context
|
|
21
21
|
*/
|
|
22
22
|
export function buildClientContext(
|
|
23
|
+
client: Client,
|
|
23
24
|
dpgContext: SdkContext,
|
|
24
|
-
codeModel: ModularCodeModel
|
|
25
|
-
client: Client
|
|
25
|
+
codeModel: ModularCodeModel
|
|
26
26
|
): SourceFile {
|
|
27
27
|
const { description, subfolder } = client;
|
|
28
28
|
const name = getClientName(client);
|
|
@@ -314,6 +314,7 @@ function processModelProperties(
|
|
|
314
314
|
// because it's impossible to have a anonymous model as the polymorphic base in typespec
|
|
315
315
|
// the only possibility is the anonymous model is an alias for an union type which has already been taken care of in the combined types.
|
|
316
316
|
if (newValue.name) {
|
|
317
|
+
newValue.name = normalizeName(newValue.name, NameType.Interface);
|
|
317
318
|
discriminatorInfo?.aliases.push(`${newValue.name}`);
|
|
318
319
|
newValue.alias = `${newValue.name}`;
|
|
319
320
|
newValue.name = `${newValue.name}Union`;
|
|
@@ -529,7 +530,7 @@ function emitParameter(
|
|
|
529
530
|
clientDefaultValue = defaultApiVersion.value;
|
|
530
531
|
}
|
|
531
532
|
if (!clientDefaultValue) {
|
|
532
|
-
clientDefaultValue = getDefaultApiVersionString(context
|
|
533
|
+
clientDefaultValue = getDefaultApiVersionString(context);
|
|
533
534
|
}
|
|
534
535
|
if (clientDefaultValue !== undefined) {
|
|
535
536
|
paramMap.optional = true;
|
|
@@ -1108,9 +1109,10 @@ function emitEnum(context: SdkContext, type: Enum): Record<string, any> {
|
|
|
1108
1109
|
|
|
1109
1110
|
return {
|
|
1110
1111
|
type: "enum",
|
|
1111
|
-
name:
|
|
1112
|
-
? getLibraryName(context, type)
|
|
1113
|
-
|
|
1112
|
+
name: normalizeName(
|
|
1113
|
+
getLibraryName(context, type) ? getLibraryName(context, type) : type.name,
|
|
1114
|
+
NameType.Interface
|
|
1115
|
+
),
|
|
1114
1116
|
description: getDocStr(program, type),
|
|
1115
1117
|
valueType: { type: enumMemberType(type.members.values().next().value) },
|
|
1116
1118
|
values: enumValues,
|
|
@@ -1399,10 +1401,13 @@ function emitUnion(
|
|
|
1399
1401
|
}
|
|
1400
1402
|
return valueType;
|
|
1401
1403
|
});
|
|
1404
|
+
const unionTypeName = unionName
|
|
1405
|
+
? normalizeName(unionName, NameType.Interface)
|
|
1406
|
+
: undefined;
|
|
1402
1407
|
return {
|
|
1403
1408
|
nullable: sdkType.nullable,
|
|
1404
|
-
name:
|
|
1405
|
-
description: `Type of ${
|
|
1409
|
+
name: unionTypeName,
|
|
1410
|
+
description: `Type of ${unionTypeName}`,
|
|
1406
1411
|
internal: true,
|
|
1407
1412
|
type: "combined",
|
|
1408
1413
|
types: variantTypes,
|
|
@@ -1417,11 +1422,14 @@ function emitUnion(
|
|
|
1417
1422
|
: variantTypes.map((x) => getTypeName(x).name).join(" | ")
|
|
1418
1423
|
};
|
|
1419
1424
|
} else if (sdkType.kind === "enum") {
|
|
1420
|
-
|
|
1425
|
+
let typeName = getLibraryName(context, type)
|
|
1421
1426
|
? getLibraryName(context, type)
|
|
1422
1427
|
: sdkType.isGeneratedName
|
|
1423
1428
|
? type.name
|
|
1424
1429
|
: sdkType.name;
|
|
1430
|
+
typeName = typeName
|
|
1431
|
+
? normalizeName(typeName, NameType.Interface)
|
|
1432
|
+
: undefined;
|
|
1425
1433
|
return {
|
|
1426
1434
|
name: typeName,
|
|
1427
1435
|
nullable: sdkType.nullable,
|
|
@@ -23,9 +23,9 @@ import {
|
|
|
23
23
|
* file called operations.ts where all operations are generated.
|
|
24
24
|
*/
|
|
25
25
|
export function buildOperationFiles(
|
|
26
|
+
client: Client,
|
|
26
27
|
dpgContext: SdkContext,
|
|
27
28
|
codeModel: ModularCodeModel,
|
|
28
|
-
client: Client,
|
|
29
29
|
needUnexpectedHelper: boolean = true
|
|
30
30
|
) {
|
|
31
31
|
const operationFiles = [];
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
isPagingOperation
|
|
6
6
|
} from "./helpers/operationHelpers.js";
|
|
7
7
|
|
|
8
|
-
export function buildPagingTypes(
|
|
8
|
+
export function buildPagingTypes(client: Client, codeModel: ModularCodeModel) {
|
|
9
9
|
if (!hasPagingOperation(client)) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
@@ -112,8 +112,8 @@ export function buildPagingTypes(codeModel: ModularCodeModel, client: Client) {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
export function buildPagingHelpers(
|
|
115
|
-
codeModel: ModularCodeModel,
|
|
116
115
|
client: Client,
|
|
116
|
+
codeModel: ModularCodeModel,
|
|
117
117
|
needUnexpectedHelper: boolean = true,
|
|
118
118
|
isMultiClients: boolean = false
|
|
119
119
|
) {
|
|
@@ -331,11 +331,12 @@ function emitBrandedPackage(codeModel: ModularCodeModel) {
|
|
|
331
331
|
});
|
|
332
332
|
}
|
|
333
333
|
packageInfo.scripts["build"] =
|
|
334
|
-
"npm run clean && tsc -p . && dev-tool run bundle && mkdirp ./review &&
|
|
334
|
+
"npm run clean && tsc -p . && dev-tool run bundle && mkdirp ./review && dev-tool run extract-api";
|
|
335
335
|
packageInfo.scripts["build:debug"] =
|
|
336
|
-
"tsc -p . && dev-tool run bundle &&
|
|
336
|
+
"tsc -p . && dev-tool run bundle && dev-tool run extract-api";
|
|
337
337
|
packageInfo.scripts["build:browser"] = "tsc -p . && dev-tool run bundle";
|
|
338
338
|
packageInfo.scripts["build:node"] = "tsc -p . && dev-tool run bundle";
|
|
339
|
+
packageInfo.scripts["extract-api"] = "dev-tool run extract-api";
|
|
339
340
|
packageInfo.devDependencies["@azure/dev-tool"] = "^1.0.0";
|
|
340
341
|
packageInfo.devDependencies["@azure/eslint-plugin-azure-sdk"] = "^3.0.0";
|
|
341
342
|
// azsdkjs repo use dev-tool to run vendored prettier
|
|
@@ -380,7 +381,7 @@ function emitBrandedPackage(codeModel: ModularCodeModel) {
|
|
|
380
381
|
packageInfo.devDependencies["karma-source-map-support"] = "~1.4.0";
|
|
381
382
|
packageInfo.devDependencies["karma-sourcemap-loader"] = "^0.4.0";
|
|
382
383
|
packageInfo.devDependencies["karma"] = "^6.2.0";
|
|
383
|
-
packageInfo.devDependencies["
|
|
384
|
+
packageInfo.devDependencies["nyc"] = "^15.1.0";
|
|
384
385
|
packageInfo.devDependencies["source-map-support"] = "^0.5.9";
|
|
385
386
|
packageInfo.devDependencies["ts-node"] = "^10.0.0";
|
|
386
387
|
packageInfo.scripts["test"] =
|
|
@@ -4,8 +4,8 @@ import { Client, ModularCodeModel } from "./modularCodeModel.js";
|
|
|
4
4
|
import { normalizeName, NameType } from "@azure-tools/rlc-common";
|
|
5
5
|
|
|
6
6
|
export function buildRootIndex(
|
|
7
|
-
codeModel: ModularCodeModel,
|
|
8
7
|
client: Client,
|
|
8
|
+
codeModel: ModularCodeModel,
|
|
9
9
|
rootIndexFile: SourceFile
|
|
10
10
|
) {
|
|
11
11
|
const { project } = codeModel;
|
|
@@ -101,8 +101,8 @@ function exportModules(
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
export function buildSubClientIndexFile(
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
client: Client,
|
|
105
|
+
codeModel: ModularCodeModel
|
|
106
106
|
) {
|
|
107
107
|
const subfolder = client.subfolder ?? "";
|
|
108
108
|
const srcPath = codeModel.modularOptions.sourceRoot;
|
|
@@ -137,8 +137,8 @@ export function buildModelInterface(
|
|
|
137
137
|
* This function creates the file containing all the models defined in TypeSpec
|
|
138
138
|
*/
|
|
139
139
|
export function buildModels(
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
subClient: Client,
|
|
141
|
+
codeModel: ModularCodeModel
|
|
142
142
|
): SourceFile | undefined {
|
|
143
143
|
// We are generating both models and enums here
|
|
144
144
|
const coreClientTypes = new Set<string>();
|
|
@@ -201,8 +201,8 @@ export function buildModelTypeAlias(model: Type) {
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
export function buildModelsOptions(
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
client: Client,
|
|
205
|
+
codeModel: ModularCodeModel
|
|
206
206
|
) {
|
|
207
207
|
const modelOptionsFile = codeModel.project.createSourceFile(
|
|
208
208
|
path.join(
|
|
@@ -22,13 +22,19 @@ export function getClassicalOperation(
|
|
|
22
22
|
.filter((i) => {
|
|
23
23
|
return (
|
|
24
24
|
i.getModuleSpecifierValue() ===
|
|
25
|
-
`${"../".repeat(layer + 2)}api/${normalizeName(
|
|
25
|
+
`${"../".repeat(layer + 2)}api/${normalizeName(
|
|
26
|
+
modularClientName,
|
|
27
|
+
NameType.File
|
|
28
|
+
)}.js`
|
|
26
29
|
);
|
|
27
30
|
});
|
|
28
31
|
if (!hasClientContextImport || hasClientContextImport.length === 0) {
|
|
29
32
|
classicFile.addImportDeclaration({
|
|
30
33
|
namedImports: [client.rlcClientName],
|
|
31
|
-
moduleSpecifier: `${"../".repeat(layer + 2)}api/${normalizeName(
|
|
34
|
+
moduleSpecifier: `${"../".repeat(layer + 2)}api/${normalizeName(
|
|
35
|
+
modularClientName,
|
|
36
|
+
NameType.File
|
|
37
|
+
)}.js`
|
|
32
38
|
});
|
|
33
39
|
}
|
|
34
40
|
|
|
@@ -502,12 +502,12 @@ function buildBodyParameter(
|
|
|
502
502
|
return bodyParameter.optional
|
|
503
503
|
? `body: typeof ${bodyParameter.clientName} === 'string'
|
|
504
504
|
? uint8ArrayToString(${bodyParameter.clientName}, "${getEncodingFormat(
|
|
505
|
-
bodyParameter
|
|
505
|
+
bodyParameter
|
|
506
506
|
)}")
|
|
507
507
|
: ${bodyParameter.clientName}`
|
|
508
508
|
: `body: uint8ArrayToString(${
|
|
509
509
|
bodyParameter.clientName
|
|
510
|
-
}, "${getEncodingFormat(bodyParameter
|
|
510
|
+
}, "${getEncodingFormat(bodyParameter)}")`;
|
|
511
511
|
} else if (bodyParameter.isBinaryPayload) {
|
|
512
512
|
return `\nbody: ${bodyParameter.clientName},`;
|
|
513
513
|
}
|
|
@@ -63,17 +63,17 @@ export async function transformRLCModel(
|
|
|
63
63
|
);
|
|
64
64
|
const importSet = initInternalImports();
|
|
65
65
|
const urlInfo = transformUrlInfo(client, dpgContext, importSet);
|
|
66
|
-
const paths: Paths = transformPaths(
|
|
67
|
-
const schemas: Schema[] = transformSchemas(
|
|
66
|
+
const paths: Paths = transformPaths(client, dpgContext, importSet);
|
|
67
|
+
const schemas: Schema[] = transformSchemas(client, dpgContext);
|
|
68
68
|
const responses: OperationResponse[] = transformToResponseTypes(
|
|
69
|
-
importSet,
|
|
70
69
|
client,
|
|
71
|
-
dpgContext
|
|
70
|
+
dpgContext,
|
|
71
|
+
importSet
|
|
72
72
|
);
|
|
73
73
|
const parameters: OperationParameter[] = transformToParameterTypes(
|
|
74
|
-
importSet,
|
|
75
74
|
client,
|
|
76
75
|
dpgContext,
|
|
76
|
+
importSet,
|
|
77
77
|
urlInfo?.apiVersionInfo
|
|
78
78
|
);
|
|
79
79
|
const helperDetails = transformHelperFunctionDetails(
|
|
@@ -84,7 +84,7 @@ export async function transformRLCModel(
|
|
|
84
84
|
// Enrich client-level annotation detail
|
|
85
85
|
helperDetails.clientLroOverload = getClientLroOverload(paths);
|
|
86
86
|
|
|
87
|
-
const telemetryOptions = transformTelemetryInfo(
|
|
87
|
+
const telemetryOptions = transformTelemetryInfo(client, dpgContext);
|
|
88
88
|
const model: RLCModel = {
|
|
89
89
|
srcPath,
|
|
90
90
|
libraryName,
|
|
@@ -26,14 +26,13 @@ export function transformApiVersionInfo(
|
|
|
26
26
|
dpgContext: SdkContext,
|
|
27
27
|
urlInfo?: UrlInfo
|
|
28
28
|
): ApiVersionInfo | undefined {
|
|
29
|
-
const program = dpgContext.program;
|
|
30
29
|
const queryVersionDetail = getOperationApiVersion(client, dpgContext);
|
|
31
30
|
const pathVersionDetail = extractPathApiVersion(urlInfo);
|
|
32
31
|
const isCrossedVersion =
|
|
33
32
|
pathVersionDetail?.isCrossedVersion || queryVersionDetail?.isCrossedVersion;
|
|
34
33
|
const defaultValue =
|
|
35
34
|
(pathVersionDetail || queryVersionDetail) && !isCrossedVersion
|
|
36
|
-
? getDefaultApiVersionString(
|
|
35
|
+
? getDefaultApiVersionString(dpgContext) ??
|
|
37
36
|
pathVersionDetail?.defaultValue ??
|
|
38
37
|
queryVersionDetail?.defaultValue
|
|
39
38
|
: undefined;
|
|
@@ -22,11 +22,7 @@ export function transformHelperFunctionDetails(
|
|
|
22
22
|
flavor?: PackageFlavor
|
|
23
23
|
): HelperFunctionDetails {
|
|
24
24
|
const program = dpgContext.program;
|
|
25
|
-
const serializeInfo = extractSpecialSerializeInfo(
|
|
26
|
-
program,
|
|
27
|
-
client,
|
|
28
|
-
dpgContext
|
|
29
|
-
);
|
|
25
|
+
const serializeInfo = extractSpecialSerializeInfo(client, dpgContext);
|
|
30
26
|
// Disbale paging and long running for non-Azure clients.
|
|
31
27
|
if (flavor !== "azure") {
|
|
32
28
|
return {
|
|
@@ -38,9 +34,9 @@ export function transformHelperFunctionDetails(
|
|
|
38
34
|
|
|
39
35
|
// Extract paged metadata from Azure.Core.Page
|
|
40
36
|
const annotationDetails = {
|
|
41
|
-
hasLongRunning: hasPollingOperations(
|
|
37
|
+
hasLongRunning: hasPollingOperations(client, dpgContext)
|
|
42
38
|
};
|
|
43
|
-
const details = extractPageDetailFromCore(
|
|
39
|
+
const details = extractPageDetailFromCore(client, dpgContext);
|
|
44
40
|
if (details) {
|
|
45
41
|
return {
|
|
46
42
|
...details,
|
|
@@ -110,12 +106,9 @@ export function getPageable(
|
|
|
110
106
|
return program.stateMap(pageableOperationsKey).get(entity);
|
|
111
107
|
}
|
|
112
108
|
|
|
113
|
-
function extractPageDetailFromCore(
|
|
114
|
-
program
|
|
115
|
-
client
|
|
116
|
-
dpgContext: SdkContext
|
|
117
|
-
) {
|
|
118
|
-
if (!hasPagingOperations(program, client, dpgContext)) {
|
|
109
|
+
function extractPageDetailFromCore(client: SdkClient, dpgContext: SdkContext) {
|
|
110
|
+
const program = dpgContext.program;
|
|
111
|
+
if (!hasPagingOperations(client, dpgContext)) {
|
|
119
112
|
return;
|
|
120
113
|
}
|
|
121
114
|
const nextLinks = new Set<string>();
|
|
@@ -179,10 +172,10 @@ function extractPageDetailFromCore(
|
|
|
179
172
|
}
|
|
180
173
|
|
|
181
174
|
function extractSpecialSerializeInfo(
|
|
182
|
-
program: Program,
|
|
183
175
|
client: SdkClient,
|
|
184
176
|
dpgContext: SdkContext
|
|
185
177
|
) {
|
|
178
|
+
const program = dpgContext.program;
|
|
186
179
|
let hasMultiCollection = false;
|
|
187
180
|
let hasPipeCollection = false;
|
|
188
181
|
let hasTsvCollection = false;
|