Skip to content

Commit 13fc201

Browse files
committed
feat: allow raw queries for where filter
Add support for tests with and without query language
1 parent 2d0a84c commit 13fc201

File tree

10 files changed

+153
-12
lines changed

10 files changed

+153
-12
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,30 @@ jobs:
8888
name: build
8989
path: dist
9090

91-
- name: Generate SDK for tests
91+
- name: Run generator tests
92+
run: npm run test:generator
93+
94+
- name: Generate SDK for tests with former query syntax
95+
run: |
96+
chmod +x ./bin/cli.js
97+
./bin/cli.js test/openapi_v3.json --target browser
98+
99+
- name: Run type-check (former-queries)
100+
run: npm run type-check:former-queries
101+
102+
- name: Run tests (former-queries)
103+
run: npm run test:former-queries
104+
105+
- name: Generate SDK for tests with query language
92106
run: |
93107
chmod +x ./bin/cli.js
94108
./bin/cli.js test/openapi_v3.json --target browser --use-query-language
95109
96-
- name: Run type-check
97-
run: npm run type-check
110+
- name: Run type-check (query-language)
111+
run: npm run type-check:query-language
98112

99-
- name: Run tests
100-
run: npm run test
113+
- name: Run tests (query-language)
114+
run: npm run test:query-language
101115

102116
publish:
103117
name: Publish release version

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import tsEslint from 'typescript-eslint';
33
export default tsEslint.config(
44
{
55
name: 'app/files-to-ignore',
6-
ignores: ['**/*.d.ts', '**/.*', '**/dist', '**/sdk', '**/node_modules']
6+
ignores: ['**/*.d.ts', '**/.*', '**/dist', '**/sdk', '**/node_modules', 'test/**']
77
},
88
{
99
extends: [...tsEslint.configs.recommendedTypeChecked],

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
}
3838
},
3939
"scripts": {
40-
"build": "rollup --config rollup.config.ts --configPlugin typescript={tsconfig:\\'tsconfig.node.json\\'} --configImportAttributesKey with",
40+
"build": "rollup --config rollup.config.ts --configPlugin typescript={tsconfig:'tsconfig.rollup.json'} --configImportAttributesKey with",
4141
"build:watch": "npm run build -- --watch",
4242
"cli:browser:v1": "./bin/cli.js test/openapi.json --target browser",
4343
"cli:browser.rx:v1": "./bin/cli.js test/openapi.json --target browser.rx",
@@ -54,12 +54,16 @@
5454
"cli:node.rx:cache": "./bin/cli.js test/openapi.json --target node.rx --cache",
5555
"prettier": "prettier . --check",
5656
"prettier:fix": "prettier . --write",
57-
"test": "vitest run",
57+
"test:generator": "vitest run src/",
58+
"test:former-queries": "vitest run test/former-queries/",
59+
"test:query-language": "vitest run test/queries/",
5860
"test:coverage": "vitest run --coverage",
59-
"type-check": "tsc -p tsconfig.node.json --noEmit --skipLibCheck",
61+
"type-check:former-queries": "tsc -p tsconfig.typecheck-former-queries.json --noEmit --skipLibCheck",
62+
"type-check:query-language": "tsc -p tsconfig.typecheck-query-language.json --noEmit --skipLibCheck",
6063
"lint": "eslint ./src --cache",
6164
"lint:fix": "npm run lint -- --fix",
62-
"ci": "npm run prettier && npm run lint && npm run build && npm run cli:browser:v1 && npm run cli:browser:v2 && npm run cli:browser:v3 && npm run cli:browser:v3:ql && npm run type-check && npm run test",
65+
"ci:test": "npm run test:generator && npm run cli:browser:v3 && npm run type-check:former-queries && npm run test:former-queries && npm run cli:browser:v3:ql && npm run type-check:query-language && npm run test:query-language",
66+
"ci": "npm run prettier && npm run lint && npm run build && npm run cli:browser:v1 && npm run cli:browser:v2 && npm run cli:browser:v3 && npm run ci:test",
6367
"release": "standard-version"
6468
},
6569
"devDependencies": {

rollup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const txt = (): Plugin => {
2020

2121
export default defineConfig({
2222
input: 'src/index.ts',
23-
plugins: [txt(), ts({ tsconfig: 'tsconfig.node.json' })],
23+
plugins: [txt(), ts({ tsconfig: 'tsconfig.rollup.json' })],
2424
external: [
2525
...Object.keys(pkg.dependencies),
2626
...Object.keys(pkg.peerDependencies),

test/former-queries/filter.spec.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
2+
import { articleService, setGlobalConfig } from '@sdk/dist';
3+
4+
describe('filter', () => {
5+
let capturedRequest: Request;
6+
7+
beforeAll(() => {
8+
setGlobalConfig({
9+
host: 'test.example.com',
10+
secure: true,
11+
key: 'test-key',
12+
interceptors: {
13+
request: (request) => {
14+
capturedRequest = request;
15+
return new Response(
16+
JSON.stringify({
17+
result: [],
18+
referencedEntities: {},
19+
additionalProperties: {}
20+
}),
21+
{
22+
status: 200,
23+
headers: { 'content-type': 'application/json' }
24+
}
25+
);
26+
}
27+
}
28+
});
29+
});
30+
31+
describe('some query', () => {
32+
it('should assemble a typed filter object into individual query params', async () => {
33+
const service = articleService();
34+
35+
await service.some({
36+
filter: {
37+
articleNumber: { EQ: 'ART-001' }
38+
}
39+
});
40+
41+
const url = new URL(capturedRequest.url);
42+
expect(url.searchParams.get('articleNumber-eq')).toBe('ART-001');
43+
});
44+
45+
it('should pass sort as a comma-separated query param', async () => {
46+
const service = articleService();
47+
48+
await service.some({
49+
sort: [{ articleNumber: 'asc' }, { name: 'desc' }]
50+
});
51+
52+
const url = new URL(capturedRequest.url);
53+
expect(url.searchParams.get('sort')).toBe('articleNumber,-name');
54+
});
55+
56+
it('should pass pagination as page and pageSize query params', async () => {
57+
const service = articleService();
58+
59+
await service.some({
60+
pagination: { page: 3, pageSize: 25 }
61+
});
62+
63+
const url = new URL(capturedRequest.url);
64+
expect(url.searchParams.get('page')).toBe('3');
65+
expect(url.searchParams.get('pageSize')).toBe('25');
66+
});
67+
68+
it('should combine filter, sort and pagination into a single request', async () => {
69+
const service = articleService();
70+
71+
await service.some({
72+
filter: {
73+
articleNumber: { EQ: 'ART-001' }
74+
},
75+
sort: [{ articleNumber: 'asc' }],
76+
pagination: { page: 1, pageSize: 10 }
77+
});
78+
79+
const url = new URL(capturedRequest.url);
80+
expect(url.searchParams.get('articleNumber-eq')).toBe('ART-001');
81+
expect(url.searchParams.get('sort')).toBe('articleNumber');
82+
expect(url.searchParams.get('page')).toBe('1');
83+
expect(url.searchParams.get('pageSize')).toBe('10');
84+
});
85+
});
86+
87+
describe('count query', () => {
88+
it('should assemble a typed filter object into individual query params', async () => {
89+
const service = articleService();
90+
91+
await service.count({
92+
filter: {
93+
articleNumber: { EQ: 'ART-001' }
94+
}
95+
});
96+
97+
const url = new URL(capturedRequest.url);
98+
expect(url.searchParams.get('articleNumber-eq')).toBe('ART-001');
99+
});
100+
});
101+
102+
afterAll(() => {
103+
setGlobalConfig(undefined);
104+
});
105+
});

tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
},
77
{
88
"path": "./tsconfig.sdk.json"
9+
},
10+
{
11+
"path": "./tsconfig.typecheck-former-queries.json"
12+
},
13+
{
14+
"path": "./tsconfig.typecheck-query-language.json"
915
}
1016
]
1117
}

tsconfig.node.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
"@sdk/*": ["sdk/*"]
2424
}
2525
},
26-
"include": ["src/**/*.ts", "test/**/*.spec.ts", "rollup.config.ts", "vitest.config.ts"]
26+
"include": ["src/**/*.ts", "rollup.config.ts", "vitest.config.ts"]
2727
}

tsconfig.rollup.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.node.json",
3+
"include": ["src/**/*.ts", "rollup.config.ts"]
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.node.json",
3+
"include": ["test/former-queries/**/*.spec.ts"]
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.node.json",
3+
"include": ["test/queries/**/*.spec.ts"]
4+
}

0 commit comments

Comments
 (0)