Refactored CMS packages to remove a circular dependency (#62)
This commit is contained in:
committed by
GitHub
parent
51a40b6d40
commit
d18f810c6e
3
packages/cms/types/README.md
Normal file
3
packages/cms/types/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# CMS - @kit/cms
|
||||
|
||||
CMS abstraction layer for the Makerkit framework.
|
||||
34
packages/cms/types/package.json
Normal file
34
packages/cms/types/package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@kit/cms-types",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"clean": "git clean -xdf .turbo node_modules",
|
||||
"format": "prettier --check \"**/*.{ts,tsx}\"",
|
||||
"lint": "eslint .",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"prettier": "@kit/prettier-config",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kit/eslint-config": "workspace:*",
|
||||
"@kit/prettier-config": "workspace:*",
|
||||
"@kit/tsconfig": "workspace:*"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
"extends": [
|
||||
"@kit/eslint-config/base",
|
||||
"@kit/eslint-config/react"
|
||||
]
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
113
packages/cms/types/src/cms-client.ts
Normal file
113
packages/cms/types/src/cms-client.ts
Normal file
@@ -0,0 +1,113 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
export namespace Cms {
|
||||
export interface ContentItem {
|
||||
id: string;
|
||||
title: string;
|
||||
url: string;
|
||||
description: string | undefined;
|
||||
content: unknown;
|
||||
publishedAt: string;
|
||||
image: string | undefined;
|
||||
status: ContentItemStatus;
|
||||
slug: string;
|
||||
categories: Category[];
|
||||
tags: Tag[];
|
||||
order: number;
|
||||
children: ContentItem[];
|
||||
parentId: string | undefined;
|
||||
}
|
||||
|
||||
export type ContentItemStatus = 'draft' | 'published' | 'review' | 'pending';
|
||||
|
||||
export interface Category {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
}
|
||||
|
||||
export interface Tag {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
}
|
||||
|
||||
export interface GetContentItemsOptions {
|
||||
collection: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
categories?: string[];
|
||||
tags?: string[];
|
||||
parentIds?: string[];
|
||||
language?: string | undefined;
|
||||
sortDirection?: 'asc' | 'desc';
|
||||
sortBy?: 'publishedAt' | 'order' | 'title';
|
||||
status?: ContentItemStatus;
|
||||
}
|
||||
|
||||
export interface GetCategoriesOptions {
|
||||
slugs?: string[];
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}
|
||||
|
||||
export interface GetTagsOptions {
|
||||
slugs?: string[];
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract class representing a CMS client.
|
||||
*/
|
||||
export abstract class CmsClient {
|
||||
/**
|
||||
* Retrieves content items based on the provided options.
|
||||
* @param options - Options for filtering and pagination.
|
||||
* @returns A promise that resolves to an array of content items.
|
||||
*/
|
||||
abstract getContentItems(options?: Cms.GetContentItemsOptions): Promise<{
|
||||
total: number;
|
||||
items: Cms.ContentItem[];
|
||||
}>;
|
||||
|
||||
/**
|
||||
* Retrieves a content item by its ID and type.
|
||||
* @returns A promise that resolves to the content item, or undefined if not found.
|
||||
*/
|
||||
abstract getContentItemBySlug(params: {
|
||||
slug: string;
|
||||
collection: string;
|
||||
status?: Cms.ContentItemStatus;
|
||||
}): Promise<Cms.ContentItem | undefined>;
|
||||
|
||||
/**
|
||||
* Retrieves categories based on the provided options.
|
||||
* @param options - Options for filtering and pagination.
|
||||
* @returns A promise that resolves to an array of categories.
|
||||
*/
|
||||
abstract getCategories(
|
||||
options?: Cms.GetCategoriesOptions,
|
||||
): Promise<Cms.Category[]>;
|
||||
|
||||
/**
|
||||
* Retrieves a category by its slug.
|
||||
* @param slug - The slug of the category.
|
||||
* @returns A promise that resolves to the category, or undefined if not found.
|
||||
*/
|
||||
abstract getCategoryBySlug(slug: string): Promise<Cms.Category | undefined>;
|
||||
|
||||
/**
|
||||
* Retrieves tags based on the provided options.
|
||||
* @param options - Options for filtering and pagination.
|
||||
* @returns A promise that resolves to an array of tags.
|
||||
*/
|
||||
abstract getTags(options?: Cms.GetTagsOptions): Promise<Cms.Tag[]>;
|
||||
|
||||
/**
|
||||
* Retrieves a tag by its slug.
|
||||
* @param slug - The slug of the tag.
|
||||
* @returns A promise that resolves to the tag, or undefined if not found.
|
||||
*/
|
||||
abstract getTagBySlug(slug: string): Promise<Cms.Tag | undefined>;
|
||||
}
|
||||
3
packages/cms/types/src/cms.type.ts
Normal file
3
packages/cms/types/src/cms.type.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
// we can add more types here if we have more CMSs
|
||||
// ex. export type CmsType = 'contentlayer' | 'other-cms';
|
||||
export type CmsType = 'wordpress' | 'keystatic';
|
||||
2
packages/cms/types/src/index.ts
Normal file
2
packages/cms/types/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './cms-client';
|
||||
export * from './cms.type';
|
||||
8
packages/cms/types/tsconfig.json
Normal file
8
packages/cms/types/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@kit/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user