Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/typecheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Typecheck
permissions:
contents: read
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- uses: pnpm/action-setup@v4
- name: Install dependencies
run: pnpm install

- name: Run TypeScript Type Check
run: npx nx run-many --target=typecheck --all --skip-nx-cache

3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"editor.formatOnSave": true
"editor.formatOnSave": true,
"files.insertFinalNewline": true
}
3 changes: 3 additions & 0 deletions apps/cli/eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export default config([
ignoredFiles: [
'{projectRoot}/eslint.config.{js,cjs,mjs,ts,cts,mts}',
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
'{projectRoot}/vitest.config.{js,ts,mjs,mts}',
'{projectRoot}/webpack.config.{js,ts}',
'{projectRoot}/e2e/**/*',
],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔What's the problem that makes us have to exclude them from ESLint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files and directories are excluded from ESLint dependency checks because they contain special syntax or test resources that can easily cause false positives or meaningless dependency check errors.

},
],
Expand Down
25 changes: 23 additions & 2 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,31 @@
"@api7/adc-sdk": "workspace:*",
"@types/express": "^5.0.3",
"@types/supertest": "^6.0.3",
"supertest": "^7.1.4"
"supertest": "^7.1.4",
"vitest": "^3.0.0",
"@nx/webpack": "21.6.4",
"webpack": "5.101.3",
"terser-webpack-plugin": "^5.3.14"
},
"dependencies": {
"express": "^5.1.0",
"winston": "^3.17.0"
"winston": "^3.17.0",
"axios": "^1.13.1",
"rxjs": "^7.8.1",
"pluralize": "^8.0.0",
"listr2": "^8.2.1",
"commander": "^13.1.0",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"chalk": "^4.1.2",
"parse-duration": "^1.1.0",
"qs": "^6.12.1",
"dotenv": "^16.4.5",
"zod": "^4.0.10",
"source-map-support": "^0.5.21",
"agentkeepalive": "^4.6.0",
"glob": "^11.0.3",
"signale": "^1.4.0",
"@api7/adc-sdk": "workspace:*"
Comment on lines +20 to +37
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only @api7/adc-sdk

}
}
2 changes: 1 addition & 1 deletion apps/cli/src/command/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import parseDuration from 'parse-duration';
import qs from 'qs';

export interface BaseOptions {
verbose: boolean;
verbose: number;
}
export class BaseCommand<
OPTS extends BaseOptions = BaseOptions,
Expand Down
6 changes: 1 addition & 5 deletions apps/cli/src/command/lint.command.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import * as ADCSDK from '@api7/adc-sdk';
import { Listr, ListrTask } from 'listr2';
import pluralize from 'pluralize';
import { ZodError } from 'zod';
import { Listr } from 'listr2';

import { check } from '../linter';
import { LintTask, LoadLocalConfigurationTask } from '../tasks';
import { SignaleRenderer } from '../utils/listr';
import { BaseCommand } from './helper';
Expand Down
3 changes: 3 additions & 0 deletions apps/cli/src/command/typing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export type BackendOptions = {
server: string;
token: string;
gatewayGroup: string;
cacheKey: string;
httpAgent: httpAgent;
httpsAgent: httpsAgent;

labelSelector?: Record<string, string>;
includeResourceType?: Array<ADCSDK.ResourceType>;
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/command/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('CLI utils', () => {
});

it('should remove metadata from dump result', () => {
const config: ADCSDK.Configuration = {
const config = {
services: [
{
name: 'TestService1',
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('CLI utils', () => {
metadata: { id: 'test_ssl' },
},
],
};
} as unknown as ADCSDK.Configuration;
recursiveRemoveMetadataField(config);
expect(config).toEqual({
services: [
Expand Down
45 changes: 33 additions & 12 deletions apps/cli/src/command/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export const toKVConfiguration = (
) {
return [
resourceType,
Object.fromEntries(resources.map((item) => [item.name, item])),
Object.fromEntries(
(Array.isArray(resources) ? resources : []).map((item) => [
item.name,
item,
]),
),
];
} else {
throw new Error(
Expand Down Expand Up @@ -138,29 +143,45 @@ export const mergeConfigurations = (
};

fileContents.forEach((config) => {
config.services && result.services.push(...config.services);
config.ssls && result.ssls.push(...config.ssls);
config.consumers && result.consumers.push(...config.consumers);
config.global_rules &&
if (config.services) {
result.services.push(...config.services);
}
if (config.ssls) {
result.ssls.push(...config.ssls);
}
if (config.consumers) {
result.consumers.push(...config.consumers);
}
if (config.global_rules) {
Object.keys(config.global_rules).forEach((globalRuleName: string) => {
result.global_rules[globalRuleName] =
config.global_rules[globalRuleName];
});
config.plugin_metadata &&
}
if (config.plugin_metadata) {
Object.keys(config.plugin_metadata).forEach(
(pluginMetadataName: string) => {
result.plugin_metadata[pluginMetadataName] =
config.plugin_metadata[pluginMetadataName];
},
);
}

config.routes && result.routes.push(...config.routes);
config.stream_routes && result.stream_routes.push(...config.stream_routes);
/* config.consumer_groups &&
if (config.routes) {
result.routes.push(...config.routes);
}
if (config.stream_routes) {
result.stream_routes.push(...config.stream_routes);
}
/* if (config.consumer_groups) {
result.consumer_groups.push(...config.consumer_groups);
config.plugin_configs &&
}
if (config.plugin_configs) {
result.plugin_configs.push(...config.plugin_configs);
config.upstreams && result.upstreams.push(...config.upstreams); */
}
if (config.upstreams) {
result.upstreams.push(...config.upstreams);
} */
});

return result;
Expand Down Expand Up @@ -332,7 +353,7 @@ export const resortConfiguration = (
];
return [
key,
value.sort((a, b) => {
(Array.isArray(value) ? value : []).sort((a, b) => {
// sort nested resources
if (key === 'services') {
if (a.routes) a.routes.sort((x, y) => x.name.localeCompare(y.name));
Expand Down
1 change: 0 additions & 1 deletion apps/cli/src/linter/specs/consumer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe('Consumer Linter', () => {
},
{
name: 'should check consumer credentials (unsupported type)',
//@ts-expect-error for test
input: {
consumers: [
{
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/linter/specs/upstream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('Upstream Linter', () => {
],
},
],
} as ADCSDK.Configuration,
} as unknown as ADCSDK.Configuration,
expect: false,
errors: [
{
Expand Down
1 change: 0 additions & 1 deletion apps/cli/src/tasks/lint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as ADCSDK from '@api7/adc-sdk';
import { ListrTask } from 'listr2';
import pluralize from 'pluralize';
import { z } from 'zod';

import { check } from '../linter';
Expand Down
16 changes: 10 additions & 6 deletions apps/cli/src/utils/listr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LogEntry, LogEntryOptions, Logger } from '@api7/adc-sdk';
import axios, { AxiosResponse } from 'axios';
import {
ListrRenderer,
ListrTaskEventType,
Expand Down Expand Up @@ -64,8 +63,9 @@ export class SignaleRenderer implements ListrRenderer {
if (err) {
this.getScopedLogger().fatal(err);
} else {
this.options.verbose > 0 &&
if (this.options.verbose > 0) {
this.getScopedLogger().star('All is well, see you next time!');
}
}
}

Expand All @@ -84,22 +84,26 @@ export class SignaleRenderer implements ListrRenderer {
if (!task.hasTitle()) return;

if (state === ListrTaskState.STARTED) {
rendererOptions?.verbose > 0 &&
if (rendererOptions?.verbose > 0) {
this.getScopedLogger(rendererOptions).start(task.title);
}
}
if (state === ListrTaskState.COMPLETED) {
rendererOptions?.verbose > 0 &&
if (rendererOptions?.verbose > 0) {
this.getScopedLogger(rendererOptions).success(task.title);
}
}
if (state === ListrTaskState.SKIPPED) {
rendererOptions?.verbose > 0 &&
if (rendererOptions?.verbose > 0) {
this.getScopedLogger(rendererOptions).info(
`${task.title} is skipped${task.message.skip ? `: ${task.message.skip}` : ''}`,
);
}
}
if (state === ListrTaskState.FAILED) {
rendererOptions?.verbose > 0 &&
if (rendererOptions?.verbose > 0) {
this.getScopedLogger(rendererOptions).error(task.title);
}
}
});

Expand Down
3 changes: 1 addition & 2 deletions apps/cli/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
},
"exclude": [
"vitest.config.ts",
"src/**/*.spec.ts",
"src/**/*.test.ts"
"src/**/*.spec.ts"
],
"include": [
"src/**/*.ts"
Expand Down
4 changes: 2 additions & 2 deletions libs/backend-api7/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
}
},
"devDependencies": {
"@api7/adc-sdk": "workspace:*",
"@api7/adc-differ": "workspace:*"
"@api7/adc-differ": "workspace:*",
"@api7/adc-sdk": "workspace:*"
},
"nx": {
"name": "backend-api7",
Expand Down
14 changes: 9 additions & 5 deletions libs/backend-api7/src/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ export class Fetcher extends ADCSDK.backend.BackendEventSource {
}),
).pipe(
tap((resp) => logger(this.debugLogEvent(resp))),
map((resp) => this.toADC.transformPluginMetadatas(resp?.data?.value)),
map((resp) =>
this.toADC.transformPluginMetadatas(
resp?.data?.value as typing.PluginMetadata,
),
),
tap(() => logger(taskStateEvent('TASK_DONE'))),
);
}
Expand Down Expand Up @@ -278,18 +282,18 @@ export class Fetcher extends ADCSDK.backend.BackendEventSource {
private isSkip(type: ADCSDK.ResourceType): boolean {
const { includeResourceType, excludeResourceType } =
this.opts.backendOpts || {};
if (!isEmpty(includeResourceType) && !includeResourceType.includes(type)) {
if (!isEmpty(includeResourceType) && !includeResourceType?.includes(type)) {
return true;
}
if (!isEmpty(excludeResourceType) && excludeResourceType.includes(type)) {
if (!isEmpty(excludeResourceType) && excludeResourceType?.includes(type)) {
return true;
}
return false;
}

private attachLabelSelector(
params: Record<string, string> = {},
): Record<string, string> {
params: Record<string, string | undefined> = {},
): Record<string, string | undefined> {
const { labelSelector } = this.opts.backendOpts || {};
if (labelSelector)
Object.entries(labelSelector).forEach(([key, value]) => {
Expand Down
Loading
Loading