Skip to content

benwest/kql-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kql-ts

Early implementation of TypeScript types for Kirby KQL queries.

Supports Tobias Moritz' extended KQL with a models property for union types, but also works without it.

Example

import { createClient } from "./kql/client";
import { KQLQueryData } from "./kql/query";

const query = {
  query: "site",
  select: {
    title: true,
    logo: {
      query: "site.logo.toFile",
      select: {
        srcset: true,
        width: true,
        height: true,
        placeholder: "file.resize(5).url",
      },
    },
    pages: {
      query: "site.children",
      select: {
        title: true,
        tags: `page.tags.split(',')`,
      },
    },
  },
} as const; // <- important

type Content = KQLQueryData<typeof query>;
/*   ^^^^^^^
{
  readonly title: string;
  readonly logo: {
      readonly srcset: string;
      readonly width: number;
      readonly height: number;
      readonly placeholder: string;
  } | null;
  readonly pages: {
      readonly title: string;
      readonly tags: string[];
  }[];
} */

const kql = createClient({
  user: KQL_USER,
  password: KQL_PASSWORD,
  url: KQL_URL,
});

const response = await kql(query);
if (response.status === "ok") {
  const data = response.result; // strongly typed!
}

todo

  • test! lots of things may be wrong!
  • Finish models.ts to annotate all built in Kirby stuff

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages