kirby-types
A collection of TypeScript types to work with Kirby CMS, mainly in the context of the Kirby Query Language and headless Kirby usage.
Setup
# pnpm
pnpm add -D kirby-types
# npm
npm i -D kirby-types
# yarn
yarn add -D kirby-types
Basic Usage
import type { KirbyQuery, ParseKirbyQuery } from "kirby-types";
// Strictly typed query
const query: KirbyQuery = 'page.children.filterBy("featured", true)';
// Parse query strings into structured objects
type BasicQuery = ParseKirbyQuery<"site">;
// Result: { model: "site"; chain: [] }
type DotNotationQuery = ParseKirbyQuery<"page.children.listed">;
// Result: {
// model: "page";
// chain: [
// { type: "property"; name: "children" },
// { type: "property"; name: "listed" }
// ]
// }
type MethodQuery = ParseKirbyQuery<'site("home")'>;
// Result: {
// model: "site";
// chain: [{ type: "method"; name: "site"; params: '"home"' }]
// }
type ComplexQuery =
ParseKirbyQuery<'page.children.filterBy("status", "published")'>;
// Result: {
// model: "page";
// chain: [
// { type: "property"; name: "children" },
// { type: "method"; name: "filterBy"; params: '"status", "published"' }
// ]
// }
API
By clicking on a type name, you will be redirected to the corresponding TypeScript definition file.
API
KirbyApiResponse
- Matches the response of a Kirby API request.
Query
KirbyQueryModel
- Matches any supported KirbyQL model.KirbyQuery
- Matches a KirbyQLquery
.ParseKirbyQuery
- Parses a KirbyQL query string into a structured object with model and chain information.
Blocks
KirbyBlock
- Matches a Kirby block.KirbyDefaultBlockType
- Matches any Kirby default block type.KirbyDefaultBlocks
- Maps each of Kirby's default block type to its corresponding block content.
Layout
KirbyLayout
- Matches a Kirby layout.KirbyLayoutColumn
- Matches any supported layout width.
KQL
KirbyQuerySchema
- Matches a KQL query schema.KirbyQueryRequest
- Matches any KQL request.KirbyQueryResponse
- Matches any KQL response.
License
MIT License © 2022-PRESENT Johann Schopplich