kirby-types 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-PRESENT Johann Schopplich <https://github.com/johannschopplich>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # kirby-types
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/kirby-types?color=a1b858&label=)](https://www.npmjs.com/package/kirby-types)
4
+
5
+ A collection of TypeScript types to work with Kirby, mainly in the context of the Kirby Query Language.
6
+
7
+ ## Setup
8
+
9
+ ```bash
10
+ # pnpm
11
+ pnpm add -D kirby-types
12
+
13
+ # npm
14
+ npm i -D kirby-types
15
+
16
+ # yarn
17
+ yarn add -D kirby-types
18
+ ```
19
+
20
+ ## Basic Usage
21
+
22
+ ```ts
23
+ import type { KirbyQuery } from "kirby-types";
24
+
25
+ // Strictly typed query for the Kirby Query Language
26
+ const query: KirbyQuery = 'kirby.page("about")';
27
+ ```
28
+
29
+ ## API
30
+
31
+ Click the type names for complete docs.
32
+
33
+ ### Query
34
+
35
+ - [`KirbyQueryModel`](./src/query.d.ts) - Matches any [supported KirbyQL model](https://github.com/getkirby/kql/blob/66abd20093e5656b0f7e6f51ee04f630ab38f2a3/src/Kql/Kql.php#L73).
36
+ - [`KirbyQuery`](./src/query.d.ts) - Matches a KirbyQL [`query`](https://getkirby.com/docs/guide/blueprints/query-language).
37
+
38
+ ### Blocks
39
+
40
+ - [`KirbyBlockType`](./src/blocks.d.ts) - Matches any [Kirby block type](https://getkirby.com/docs/reference/panel/blocks).
41
+ - [`KirbyBlock`](./src/blocks.d.ts) - Matches a [Kirby block](https://getkirby.com/docs/guide/page-builder).
42
+
43
+ ### Layout
44
+
45
+ - [`KirbyLayout`](./src/layout.d.ts) - Matches a [Kirby layout](https://getkirby.com/docs/reference/panel/fields/layout).
46
+ - [`KirbyLayoutColumn`](./src/layout.d.ts) - Matches any [supported layout width](https://getkirby.com/docs/reference/panel/fields/layout#defining-your-own-layouts__available-widths).
47
+
48
+ ### KQL
49
+
50
+ - [`KirbyQuerySchema`](./src/kql.d.ts) - Matches a [KQL query schema](https://github.com/getkirby/kql).
51
+ - [`KirbyQueryRequest`](./src/kql.d.ts) - Matches any [KQL request](https://github.com/getkirby/kql).
52
+ - [`KirbyQueryResponse`](./src/kql.d.ts) - Matches any [KQL response](https://github.com/getkirby/kql).
53
+
54
+ ## License
55
+
56
+ [MIT](./LICENSE) License © 2022-PRESENT [Johann Schopplich](https://github.com/johannschopplich)
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./src/blocks";
2
+ export * from "./src/kql";
3
+ export * from "./src/layout";
4
+ export * from "./src/query";
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "kirby-types",
3
+ "type": "module",
4
+ "version": "0.5.0",
5
+ "packageManager": "pnpm@8.7.0",
6
+ "description": "A collection of TypeScript types for the Kirby CMS",
7
+ "author": "Johann Schopplich <pkg@johannschopplich.com>",
8
+ "license": "MIT",
9
+ "homepage": "https://github.com/johannschopplich/kirby-types#readme",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/johannschopplich/kirby-types.git"
13
+ },
14
+ "bugs": "https://github.com/johannschopplich/kirby-types/issues",
15
+ "keywords": [
16
+ "getkirby",
17
+ "kirby-cms",
18
+ "kirby",
19
+ "kql",
20
+ "query-language",
21
+ "query",
22
+ "typescript"
23
+ ],
24
+ "sideEffects": false,
25
+ "exports": {
26
+ ".": {
27
+ "types": "./index.d.ts"
28
+ }
29
+ },
30
+ "types": "./index.d.ts",
31
+ "files": [
32
+ "src",
33
+ "index.d.ts"
34
+ ],
35
+ "scripts": {
36
+ "lint": "eslint \"**/*.ts\" --ignore-path .gitignore",
37
+ "lint:fix": "npm run lint -- --fix",
38
+ "format": "prettier \"**/*.{css,html,json,md,mjs,ts,vue,yml}\" --write",
39
+ "format:check": "prettier \"**/*.{css,html,json,md,mjs,ts,vue,yml}\" --check",
40
+ "release": "bumpp --commit --push --tag",
41
+ "test": "tsd -f \"test/**/*.test-d.ts\""
42
+ },
43
+ "devDependencies": {
44
+ "@nuxt/eslint-config": "^0.1.1",
45
+ "bumpp": "^9.2.0",
46
+ "eslint": "^8.48.0",
47
+ "eslint-config-prettier": "^9.0.0",
48
+ "prettier": "^3.0.2",
49
+ "tsd": "^0.28.1",
50
+ "typescript": "^5.1.6"
51
+ }
52
+ }
@@ -0,0 +1,51 @@
1
+ export type KirbyBlockType =
2
+ | "code"
3
+ | "gallery"
4
+ | "heading"
5
+ | "image"
6
+ | "line"
7
+ | "list"
8
+ | "markdown"
9
+ | "quote"
10
+ | "table"
11
+ | "text"
12
+ | "video";
13
+
14
+ export interface KirbyBlock<
15
+ T extends string = KirbyBlockType,
16
+ U extends Record<string, any> | undefined = undefined,
17
+ > {
18
+ content: U extends Record<string, any>
19
+ ? U
20
+ : T extends "code"
21
+ ? { code: string; language: string }
22
+ : T extends "gallery"
23
+ ? { images: string[] }
24
+ : T extends "heading"
25
+ ? { level: string; text: string }
26
+ : T extends "image"
27
+ ? {
28
+ location: string;
29
+ image: string[];
30
+ src: string;
31
+ alt: string;
32
+ caption: string;
33
+ link: string;
34
+ ratio: string;
35
+ crop: boolean;
36
+ }
37
+ : T extends "list"
38
+ ? { text: string }
39
+ : T extends "markdown"
40
+ ? { text: string }
41
+ : T extends "quote"
42
+ ? { text: string; citation: string }
43
+ : T extends "text"
44
+ ? { text: string }
45
+ : T extends "video"
46
+ ? { url: string; caption: string }
47
+ : Record<string, never>;
48
+ id: string;
49
+ isHidden: boolean;
50
+ type: T;
51
+ }
package/src/kql.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import type { KirbyQuery } from "./query";
2
+
3
+ export interface KirbyQuerySchema {
4
+ query: KirbyQuery;
5
+ select?:
6
+ | string[]
7
+ | Record<string, string | number | boolean | KirbyQuerySchema>;
8
+ }
9
+
10
+ export interface KirbyQueryRequest extends KirbyQuerySchema {
11
+ pagination?: {
12
+ /** @default 100 */
13
+ limit?: number;
14
+ page?: number;
15
+ };
16
+ }
17
+
18
+ export interface KirbyQueryResponse<
19
+ T = any,
20
+ Pagination extends boolean = false,
21
+ > {
22
+ code: number;
23
+ status: string;
24
+ result?: Pagination extends true
25
+ ? {
26
+ data: T;
27
+ pagination: {
28
+ page: number;
29
+ pages: number;
30
+ offset: number;
31
+ limit: number;
32
+ total: number;
33
+ };
34
+ }
35
+ : T;
36
+ }
@@ -0,0 +1,41 @@
1
+ import type { KirbyBlock } from "./blocks";
2
+
3
+ export interface KirbyLayoutColumn {
4
+ id: string;
5
+ width:
6
+ | "1/1"
7
+ | "1/2"
8
+ | "1/3"
9
+ | "1/4"
10
+ | "1/6"
11
+ | "1/12"
12
+ | "2/2"
13
+ | "2/3"
14
+ | "2/4"
15
+ | "2/6"
16
+ | "2/12"
17
+ | "3/3"
18
+ | "3/4"
19
+ | "3/6"
20
+ | "3/12"
21
+ | "4/4"
22
+ | "4/6"
23
+ | "4/12"
24
+ | "5/6"
25
+ | "5/12"
26
+ | "6/6"
27
+ | "6/12"
28
+ | "7/12"
29
+ | "8/12"
30
+ | "9/12"
31
+ | "10/12"
32
+ | "11/12"
33
+ | "12/12";
34
+ blocks: KirbyBlock[];
35
+ }
36
+
37
+ export interface KirbyLayout {
38
+ id: string;
39
+ attrs: Record<string, any> | string[];
40
+ columns: KirbyLayoutColumn[];
41
+ }
package/src/query.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ // https://github.com/getkirby/kql/blob/4c8cdd88c076cdef5323efcd4f0fda38c0865eed/src/Kql/Kql.php#L73
2
+ export type KirbyQueryModel<CustomModel extends string = never> =
3
+ | "collection"
4
+ | "file"
5
+ | "kirby"
6
+ | "page"
7
+ | "site"
8
+ | "user"
9
+ | "arrayItem"
10
+ | "structureItem"
11
+ | "block"
12
+ | CustomModel;
13
+
14
+ // For simple dot-based queries like `site.title`, `page.images`, etc.
15
+ type DotNotationQuery<M extends string = never> =
16
+ `${KirbyQueryModel<M>}.${string}`;
17
+
18
+ // For function-based queries like `page("id")`, `user("name")`, etc.
19
+ type FunctionNotationQuery<M extends string = never> =
20
+ `${KirbyQueryModel<M>}(${string})${string}`;
21
+
22
+ // Combines the two types above to allow for either dot or function notation
23
+ export type KirbyQueryChain<M extends string = never> =
24
+ | DotNotationQuery<M>
25
+ | FunctionNotationQuery<M>;
26
+
27
+ export type KirbyQuery<CustomModel extends string = never> =
28
+ | KirbyQueryModel<CustomModel>
29
+ // Ensures that it must match the pattern exactly, but not more broadly
30
+ | (string extends KirbyQueryChain<CustomModel>
31
+ ? never
32
+ : KirbyQueryChain<CustomModel>);