Skip to content

Commit

Permalink
feat: custom Kirby query models
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Sep 16, 2022
1 parent c5a08b8 commit a1ca702
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
7 changes: 5 additions & 2 deletions index.test-d.ts
Expand Up @@ -11,12 +11,15 @@ interface KirbySite {
}

// Query
expectAssignable<KirbyQuery>("site");
expectAssignable<KirbyQuery>('kirby.page("about")');
expectAssignable<KirbyQuery>('collection("notes")');
expectAssignable<KirbyQuery<"custom">>("custom");
expectAssignable<KirbyQuery<"custom">>("custom.cover");
expectNotAssignable<KirbyQuery>("kirby(");
expectNotAssignable<KirbyQuery>('kirby("about');

// Query Request
// KQL Query Request
expectAssignable<KirbyQueryRequest>({
query: "site",
select: {
Expand All @@ -32,7 +35,7 @@ expectAssignable<KirbyQueryRequest>({
},
});

// Query Response
// KQL Query Response
expectAssignable<KirbyQueryResponse<KirbySite>>({
code: 200,
status: "OK",
Expand Down
13 changes: 7 additions & 6 deletions src/query.d.ts
@@ -1,13 +1,14 @@
// https://github.com/getkirby/kql/blob/66abd20093e5656b0f7e6f51ee04f630ab38f2a3/src/Kql/Kql.php#L73
export type KirbyQueryModel =
export type KirbyQueryModel<T extends string = never> =
| "collection"
| "file"
| "kirby"
| "page"
| "site"
| "user";
| "user"
| T;

export type KirbyQuery =
| KirbyQueryModel
| `${KirbyQueryModel}.${string}`
| `${KirbyQueryModel}(${string})`;
export type KirbyQuery<T extends string = never> =
| KirbyQueryModel<T>
| `${KirbyQueryModel<T>}.${string}`
| `${KirbyQueryModel<T>}(${string})`;

0 comments on commit a1ca702

Please sign in to comment.