Skip to content

Commit 62646d3

Browse files
authored
chore(types): fix types and add type check (#374)
1 parent e242f8b commit 62646d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+749
-470
lines changed

.github/workflows/typecheck.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Typecheck
2+
permissions:
3+
contents: read
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: 'lts/*'
19+
- uses: pnpm/action-setup@v4
20+
- name: Install dependencies
21+
run: pnpm install
22+
23+
- name: Run TypeScript Type Check
24+
run: npx nx run-many --target=typecheck --all --skip-nx-cache
25+

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"editor.formatOnSave": true
2+
"editor.formatOnSave": true,
3+
"files.insertFinalNewline": true
34
}

apps/cli/eslint.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export default config([
1313
ignoredFiles: [
1414
'{projectRoot}/eslint.config.{js,cjs,mjs,ts,cts,mts}',
1515
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
16+
'{projectRoot}/vitest.config.{js,ts,mjs,mts}',
17+
'{projectRoot}/webpack.config.{js,ts}',
18+
'{projectRoot}/e2e/**/*',
1619
],
1720
},
1821
],

apps/cli/package.json

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,33 @@
66
"@api7/adc-backend-apisix-standalone": "workspace:*",
77
"@api7/adc-converter-openapi": "workspace:*",
88
"@api7/adc-differ": "workspace:*",
9-
"@api7/adc-sdk": "workspace:*",
109
"@types/express": "^5.0.3",
1110
"@types/supertest": "^6.0.3",
12-
"supertest": "^7.1.4"
11+
"supertest": "^7.1.4",
12+
"vitest": "^3.0.0",
13+
"@nx/webpack": "21.6.4",
14+
"webpack": "5.101.3",
15+
"terser-webpack-plugin": "^5.3.14"
1316
},
1417
"dependencies": {
1518
"express": "^5.1.0",
16-
"winston": "^3.17.0"
19+
"winston": "^3.17.0",
20+
"axios": "^1.13.1",
21+
"rxjs": "^7.8.1",
22+
"pluralize": "^8.0.0",
23+
"listr2": "^8.2.1",
24+
"commander": "^13.1.0",
25+
"js-yaml": "^4.1.0",
26+
"lodash": "^4.17.21",
27+
"chalk": "^4.1.2",
28+
"parse-duration": "^1.1.0",
29+
"qs": "^6.12.1",
30+
"dotenv": "^16.4.5",
31+
"zod": "^4.0.10",
32+
"source-map-support": "^0.5.21",
33+
"agentkeepalive": "^4.6.0",
34+
"glob": "^11.0.3",
35+
"signale": "^1.4.0",
36+
"@api7/adc-sdk": "workspace:*"
1737
}
1838
}

apps/cli/src/command/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import parseDuration from 'parse-duration';
88
import qs from 'qs';
99

1010
export interface BaseOptions {
11-
verbose: boolean;
11+
verbose: number;
1212
}
1313
export class BaseCommand<
1414
OPTS extends BaseOptions = BaseOptions,

apps/cli/src/command/lint.command.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import * as ADCSDK from '@api7/adc-sdk';
2-
import { Listr, ListrTask } from 'listr2';
3-
import pluralize from 'pluralize';
4-
import { ZodError } from 'zod';
1+
import { Listr } from 'listr2';
52

6-
import { check } from '../linter';
73
import { LintTask, LoadLocalConfigurationTask } from '../tasks';
84
import { SignaleRenderer } from '../utils/listr';
95
import { BaseCommand } from './helper';

apps/cli/src/command/typing.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export type BackendOptions = {
99
server: string;
1010
token: string;
1111
gatewayGroup: string;
12+
cacheKey: string;
13+
httpAgent: httpAgent;
14+
httpsAgent: httpsAgent;
1215

1316
labelSelector?: Record<string, string>;
1417
includeResourceType?: Array<ADCSDK.ResourceType>;

apps/cli/src/command/utils.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('CLI utils', () => {
4949
name: 'Test Stream Route',
5050
},
5151
],
52-
},
52+
} as ADCSDK.Configuration,
5353
{ test1: 'test1', test2: 'test2' },
5454
),
5555
).toEqual({
@@ -147,7 +147,7 @@ describe('CLI utils', () => {
147147
labels: { test: 'test' },
148148
},
149149
],
150-
},
150+
} as ADCSDK.Configuration,
151151
{ test1: 'test1', test2: 'test2' },
152152
),
153153
).toEqual({
@@ -201,7 +201,7 @@ describe('CLI utils', () => {
201201
});
202202

203203
it('should remove metadata from dump result', () => {
204-
const config: ADCSDK.Configuration = {
204+
const config = {
205205
services: [
206206
{
207207
name: 'TestService1',
@@ -232,7 +232,7 @@ describe('CLI utils', () => {
232232
metadata: { id: 'test_ssl' },
233233
},
234234
],
235-
};
235+
} as unknown as ADCSDK.Configuration;
236236
recursiveRemoveMetadataField(config);
237237
expect(config).toEqual({
238238
services: [

apps/cli/src/command/utils.ts

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ export const toKVConfiguration = (
6262
) {
6363
return [
6464
resourceType,
65-
Object.fromEntries(resources.map((item) => [item.name, item])),
65+
Object.fromEntries(
66+
(Array.isArray(resources) ? resources : []).map((item) => [
67+
item.name,
68+
item,
69+
]),
70+
),
6671
];
6772
} else {
6873
throw new Error(
@@ -120,52 +125,6 @@ export const mergeKVConfigurations = (
120125
return baseConfiguration;
121126
};
122127

123-
export const mergeConfigurations = (
124-
...fileContents: Array<ADCSDK.Configuration>
125-
) => {
126-
const result: ADCSDK.Configuration = {
127-
services: [],
128-
ssls: [],
129-
consumers: [],
130-
global_rules: {},
131-
plugin_metadata: {},
132-
133-
routes: [],
134-
stream_routes: [],
135-
/* consumer_groups: [],
136-
plugin_configs: [],
137-
upstreams: [], */
138-
};
139-
140-
fileContents.forEach((config) => {
141-
config.services && result.services.push(...config.services);
142-
config.ssls && result.ssls.push(...config.ssls);
143-
config.consumers && result.consumers.push(...config.consumers);
144-
config.global_rules &&
145-
Object.keys(config.global_rules).forEach((globalRuleName: string) => {
146-
result.global_rules[globalRuleName] =
147-
config.global_rules[globalRuleName];
148-
});
149-
config.plugin_metadata &&
150-
Object.keys(config.plugin_metadata).forEach(
151-
(pluginMetadataName: string) => {
152-
result.plugin_metadata[pluginMetadataName] =
153-
config.plugin_metadata[pluginMetadataName];
154-
},
155-
);
156-
157-
config.routes && result.routes.push(...config.routes);
158-
config.stream_routes && result.stream_routes.push(...config.stream_routes);
159-
/* config.consumer_groups &&
160-
result.consumer_groups.push(...config.consumer_groups);
161-
config.plugin_configs &&
162-
result.plugin_configs.push(...config.plugin_configs);
163-
config.upstreams && result.upstreams.push(...config.upstreams); */
164-
});
165-
166-
return result;
167-
};
168-
169128
export const filterConfiguration = (
170129
configuration: ADCSDK.Configuration,
171130
rules: Record<string, string>,
@@ -332,7 +291,7 @@ export const resortConfiguration = (
332291
];
333292
return [
334293
key,
335-
value.sort((a, b) => {
294+
(Array.isArray(value) ? value : []).sort((a, b) => {
336295
// sort nested resources
337296
if (key === 'services') {
338297
if (a.routes) a.routes.sort((x, y) => x.name.localeCompare(y.name));

apps/cli/src/linter/specs/consumer.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ describe('Consumer Linter', () => {
5252
},
5353
{
5454
name: 'should check consumer credentials (unsupported type)',
55-
//@ts-expect-error for test
5655
input: {
5756
consumers: [
5857
{

0 commit comments

Comments
 (0)