-
Notifications
You must be signed in to change notification settings - Fork 11
chore(types): add type check #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 13 commits
72229df
c3fa05e
9011884
7f2a4bb
d580bf1
48d9e99
41c1806
c31dfb9
df7e18e
31550d9
a6ea794
93ab8b2
f8d7361
87e3d4d
e118d92
8157da4
c012364
9c7b359
6a58edd
eb6f7ca
7456b98
674d6b6
5b32cdf
efc79ec
43770bd
84708ed
14fd5a5
508c80e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: Lint | ||
| 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 Lint Check | ||
| run: npx nx run-many --target=lint --all --skip-nx-cache | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,29 @@ | |
| }, | ||
| "dependencies": { | ||
| "express": "^5.1.0", | ||
| "winston": "^3.17.0" | ||
| "winston": "^3.17.0", | ||
| "axios": "^1.13.1", | ||
| "rxjs": "^7.8.1", | ||
| "supertest": "7.1.4", | ||
LiteSun marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "pluralize": "^8.0.0", | ||
| "semver": "^7.6.3", | ||
| "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", | ||
| "vitest": "3.0.0", | ||
| "@nx/webpack": "21.6.4", | ||
| "webpack": "5.101.3", | ||
| "terser-webpack-plugin": "^5.3.14", | ||
| "@api7/adc-sdk": "workspace:*" | ||
| } | ||
| } | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,9 @@ | |
| } | ||
| }, | ||
| "devDependencies": { | ||
| "@api7/adc-differ": "workspace:*", | ||
| "@api7/adc-sdk": "workspace:*", | ||
| "@api7/adc-differ": "workspace:*" | ||
| "@types/jest": "^30.0.0" | ||
|
||
| }, | ||
| "nx": { | ||
| "name": "backend-api7", | ||
|
|
@@ -30,4 +31,4 @@ | |
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,16 +8,17 @@ import semver, { SemVer } from 'semver'; | |
| import { Fetcher } from './fetcher'; | ||
| import { Operator } from './operator'; | ||
| import { ToADC } from './transformer'; | ||
| import * as typing from './typing'; | ||
|
|
||
| export class BackendAPI7 implements ADCSDK.Backend { | ||
| private readonly client: AxiosInstance; | ||
| private readonly gatewayGroupName: string; | ||
| private readonly gatewayGroupName?: string; | ||
|
||
| private static logScope = ['API7']; | ||
| private readonly subject = new Subject<ADCSDK.BackendEvent>(); | ||
|
|
||
| private _version?: SemVer; | ||
| private gatewayGroupId?: string; | ||
| private innerDefaultValue: ADCSDK.DefaultValue; | ||
| private innerDefaultValue?: ADCSDK.DefaultValue; | ||
|
|
||
| constructor(private readonly opts: ADCSDK.BackendOptions) { | ||
| this.client = axios.create({ | ||
|
|
@@ -54,8 +55,8 @@ export class BackendAPI7 implements ADCSDK.Backend { | |
|
|
||
| return (this._version = | ||
| resp?.data?.value === 'dev' | ||
| ? semver.coerce('999.999.999') | ||
| : semver.coerce(resp?.data?.value) || semver.coerce('0.0.0')); | ||
| ? semver.coerce('999.999.999')! | ||
| : semver.coerce(resp?.data?.value) || semver.coerce('0.0.0')!); | ||
|
||
| } | ||
|
|
||
| public async defaultValue() { | ||
|
|
@@ -64,16 +65,19 @@ export class BackendAPI7 implements ADCSDK.Backend { | |
| if (items.length < 2) return items[0]; | ||
| if (!items.some((item) => item.type === 'object')) return {}; | ||
|
|
||
| const first = items.shift(); | ||
| if (!first.properties) first.properties = {}; | ||
| const first = items.shift() || {}; | ||
| if (!first?.properties) first.properties = {}; | ||
LiteSun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return items.reduce((pv, cv) => { | ||
| Object.entries(cv?.properties ?? {}).forEach(([key, val]) => { | ||
| if (!pv.properties) pv.properties = {}; | ||
| pv.properties[key] = val; | ||
| }); | ||
| return pv; | ||
| }, first); | ||
| }; | ||
| const extractObjectDefault = (obj: JSONSchema4) => { | ||
| const extractObjectDefault = ( | ||
| obj: JSONSchema4, | ||
| ): Record<string, any> | null => { | ||
| if (obj.type !== 'object') return null; | ||
| if (!obj.properties) return null; | ||
|
|
||
|
|
@@ -85,7 +89,7 @@ export class BackendAPI7 implements ADCSDK.Backend { | |
|
|
||
| // For array nested object (e.g. service.upstream.nodes) | ||
| if (field.type === 'array' && !Array.isArray(field.items)) { | ||
| if (field.items.type === 'object') | ||
| if (field?.items?.type === 'object') | ||
| return [key, [extractObjectDefault(field.items)]]; | ||
| } | ||
|
|
||
|
|
@@ -117,29 +121,31 @@ export class BackendAPI7 implements ADCSDK.Backend { | |
| const toADC = new ToADC(); | ||
| return (this.innerDefaultValue = { | ||
| core: Object.fromEntries( | ||
| Object.entries(resp.data.value).map( | ||
| ([type, schema]: [ADCSDK.ResourceType, JSONSchema4]) => { | ||
| const data = | ||
| extractObjectDefault( | ||
| schema.allOf ? mergeAllOf(schema.allOf) : schema, | ||
| ) ?? {}; | ||
| switch (type) { | ||
| case ADCSDK.ResourceType.ROUTE: | ||
| return [type, toADC.transformRoute(data)]; | ||
| case ADCSDK.ResourceType.INTERNAL_STREAM_SERVICE: | ||
| case ADCSDK.ResourceType.SERVICE: | ||
| return [type, toADC.transformService(data)]; | ||
| case ADCSDK.ResourceType.SSL: | ||
| return [type, toADC.transformSSL(data)]; | ||
| case ADCSDK.ResourceType.CONSUMER: | ||
| return [type, toADC.transformConsumer(data)]; | ||
| case ADCSDK.ResourceType.UPSTREAM: | ||
| return [type, toADC.transformUpstream(data)]; | ||
| default: | ||
| return [type, data]; | ||
| } | ||
| }, | ||
| ), | ||
| ( | ||
| Object.entries(resp.data.value || {}) as Array< | ||
| [ADCSDK.ResourceType, JSONSchema4] | ||
| > | ||
| ).map(([type, schema]) => { | ||
| const data = | ||
| extractObjectDefault( | ||
| schema.allOf ? mergeAllOf(schema.allOf) : schema, | ||
| ) ?? {}; | ||
| switch (type) { | ||
| case ADCSDK.ResourceType.ROUTE: | ||
| return [type, toADC.transformRoute(data as typing.Route)]; | ||
| case ADCSDK.ResourceType.INTERNAL_STREAM_SERVICE: | ||
| case ADCSDK.ResourceType.SERVICE: | ||
| return [type, toADC.transformService(data as typing.Service)]; | ||
| case ADCSDK.ResourceType.SSL: | ||
| return [type, toADC.transformSSL(data as typing.SSL)]; | ||
| case ADCSDK.ResourceType.CONSUMER: | ||
| return [type, toADC.transformConsumer(data as typing.Consumer)]; | ||
| case ADCSDK.ResourceType.UPSTREAM: | ||
| return [type, toADC.transformUpstream(data as typing.Upstream)]; | ||
| default: | ||
| return [type, data]; | ||
| } | ||
| }), | ||
| ), | ||
| } as ADCSDK.DefaultValue); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.