Skip to content

Commit

Permalink
feat: KirbyQuerySchema for typed nested query requests
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Sep 22, 2022
1 parent 30bc218 commit eadbd40
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -44,6 +44,7 @@ Click the type names for complete docs.

### KQL

- [`KirbyQuerySchema`](./src/kql.d.ts) - Matches a [KQL query schema](https://github.com/getkirby/kql).
- [`KirbyQueryRequest`](./src/kql.d.ts) - Matches any [KQL request](https://github.com/getkirby/kql).
- [`KirbyQueryResponse`](./src/kql.d.ts) - Matches any [KQL response](https://github.com/getkirby/kql).

Expand Down
27 changes: 26 additions & 1 deletion index.test-d.ts
Expand Up @@ -43,12 +43,37 @@ expectAssignable<KirbyQueryRequest>({
query: "site",
select: {
title: true,
},
});
expectAssignable<KirbyQueryRequest>({
query: "site",
select: {
children: {
query: "site.children",
select: ["id", "title", "isListed"],
},
},
});
expectAssignable<KirbyQueryRequest>({
query: "site",
select: {
children: {
query: "site.children",
select: {
id: true,
title: true,
isListed: true,
isListed: "page.isListed",
},
},
},
});
expectNotAssignable<KirbyQueryRequest>({
query: "site",
select: {
children: {
query: "site.children",
select: {
id: null,
},
},
},
Expand Down
9 changes: 7 additions & 2 deletions src/kql.d.ts
@@ -1,8 +1,13 @@
import type { KirbyQuery } from "./query";

export interface KirbyQueryRequest {
export interface KirbyQuerySchema {
query: KirbyQuery;
select?: Record<string, any> | string[];
select?:
| string[]
| Record<string, string | number | boolean | KirbyQuerySchema>;
}

export interface KirbyQueryRequest extends KirbyQuerySchema {
pagination?: {
/** @default 100 */
limit?: number;
Expand Down

0 comments on commit eadbd40

Please sign in to comment.