@kidecms/core 0.1.11 → 0.14.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 +21 -0
- package/admin/components/AssetsGrid.tsx +366 -173
- package/admin/components/BlockEditor.tsx +260 -679
- package/admin/components/CheckboxField.tsx +2 -2
- package/admin/components/CollaborationReviewBar.tsx +384 -0
- package/admin/components/ColorField.tsx +87 -0
- package/admin/components/CommandPalette.tsx +169 -0
- package/admin/components/ContentEditor.tsx +687 -0
- package/admin/components/DocumentActions.tsx +4 -2
- package/admin/components/DocumentsDataTable.tsx +91 -10
- package/admin/components/FieldControl.astro +151 -26
- package/admin/components/FocalPointSelector.tsx +27 -1
- package/admin/components/InternalLinkPicker.tsx +4 -3
- package/admin/components/LinkField.tsx +126 -0
- package/admin/components/RelationField.tsx +105 -26
- package/admin/components/RepeaterInput.tsx +46 -0
- package/admin/components/RichTextEditor.tsx +44 -9
- package/admin/components/SharedSectionBlockField.tsx +93 -0
- package/admin/components/SidebarUserMenu.tsx +1 -1
- package/admin/components/Toast.astro +1 -1
- package/admin/components/TreeItemsEditor.tsx +20 -19
- package/admin/components/TreeSelect.tsx +2 -2
- package/admin/components/YoutubeField.tsx +48 -0
- package/admin/components/block-fields.tsx +777 -0
- package/admin/components/content-block-spec.ts +114 -0
- package/admin/components/slash-command.tsx +242 -0
- package/admin/components/tree-utils.ts +14 -2
- package/admin/components/ui/badge.tsx +2 -3
- package/admin/components/ui/button.tsx +5 -4
- package/admin/components/ui/checkbox.tsx +1 -1
- package/admin/components/ui/input.tsx +1 -1
- package/admin/components/ui/select.tsx +1 -1
- package/admin/components/ui/table.tsx +1 -1
- package/admin/components/ui/textarea.tsx +1 -1
- package/admin/layouts/AdminLayout.astro +323 -123
- package/admin/lib/access.ts +54 -0
- package/admin/lib/collaboration.ts +178 -0
- package/admin/lib/edit-data.ts +448 -0
- package/admin/views/AccessDeniedView.astro +8 -0
- package/admin/views/EditView.astro +706 -0
- package/admin/views/ListView.astro +202 -0
- package/admin/views/RecentView.astro +76 -0
- package/admin/views/SinglesView.astro +65 -0
- package/admin/views/edit/EditScripts.astro +145 -0
- package/admin/views/edit/ReverseReferencesList.astro +68 -0
- package/core/admin.ts +193 -0
- package/core/ai.ts +87 -0
- package/core/api.ts +1392 -0
- package/core/assets.ts +336 -0
- package/core/audit.ts +86 -0
- package/core/auth-config.ts +44 -0
- package/core/auth.ts +303 -0
- package/core/collaboration.ts +276 -0
- package/core/content.ts +27 -0
- package/core/create-admin.ts +28 -0
- package/core/define.ts +623 -0
- package/core/field-model.ts +172 -0
- package/core/generator.ts +519 -0
- package/core/http.ts +42 -0
- package/core/image.ts +219 -0
- package/core/index.ts +211 -0
- package/core/locks.ts +52 -0
- package/core/log.ts +37 -0
- package/core/migrate.ts +278 -0
- package/core/rate-limit.ts +110 -0
- package/core/request-scope.ts +33 -0
- package/core/richtext.ts +1 -0
- package/core/runtime.ts +63 -0
- package/core/schema.ts +32 -0
- package/core/search.ts +489 -0
- package/core/seed.ts +101 -0
- package/core/shared-sections.ts +96 -0
- package/core/tasks.ts +176 -0
- package/core/values.ts +433 -0
- package/core/webhooks.ts +85 -0
- package/core/youtube.ts +39 -0
- package/internals/cli.mjs +34 -0
- package/internals/context.ts +67 -0
- package/internals/create-admin.ts +40 -0
- package/internals/describe.ts +25 -0
- package/internals/eject.ts +144 -0
- package/internals/generator.ts +11 -0
- package/internals/integration.ts +481 -0
- package/internals/mcp.ts +397 -0
- package/internals/project.ts +31 -0
- package/internals/push.ts +160 -0
- package/internals/reindex.ts +11 -0
- package/internals/restore.ts +257 -0
- package/internals/seed.ts +15 -0
- package/internals/upgrade.ts +785 -0
- package/{virtual.d.ts → internals/virtual.d.ts} +39 -5
- package/middleware/auth.ts +130 -17
- package/middleware/push.ts +121 -0
- package/package.json +55 -67
- package/platform/cloudflare/cf-env.ts +60 -0
- package/platform/cloudflare/database.ts +28 -0
- package/platform/cloudflare/globals.d.ts +5 -0
- package/platform/cloudflare/storage.ts +33 -0
- package/platform/cloudflare/uploads-route.ts +37 -0
- package/platform/node/database.ts +39 -0
- package/platform/node/storage.ts +52 -0
- package/routes/admin/[...path].astro +71 -0
- package/routes/{pages/admin → admin}/assets/[id].astro +25 -19
- package/routes/admin/assets/index.astro +90 -0
- package/routes/{pages/admin/login.astro → admin/forgot-password.astro} +21 -19
- package/routes/{pages/admin → admin}/invite.astro +13 -6
- package/routes/admin/login.astro +103 -0
- package/routes/admin/reset-password.astro +73 -0
- package/routes/{pages/admin → admin}/setup.astro +32 -8
- package/routes/api/{cms/[collection] → [collection]}/[...path].ts +67 -15
- package/routes/api/admin/search.ts +89 -0
- package/routes/api/{cms/assets → assets}/[id].ts +24 -14
- package/routes/api/{cms/assets → assets}/index.ts +4 -2
- package/routes/api/assets/upload.ts +147 -0
- package/routes/api/auth/forgot-password.ts +77 -0
- package/routes/api/{cms/auth → auth}/invite.ts +41 -9
- package/routes/api/auth/login.ts +167 -0
- package/routes/api/{cms/auth → auth}/logout.ts +11 -2
- package/routes/api/auth/reset-password.ts +85 -0
- package/routes/api/auth/setup.ts +110 -0
- package/routes/api/auth/sso/[provider]/start.ts +34 -0
- package/routes/api/collaboration/index.ts +106 -0
- package/routes/api/cron/_authorize.ts +25 -0
- package/routes/api/{cms/cron → cron}/publish.ts +3 -9
- package/routes/api/cron/tasks.ts +34 -0
- package/routes/api/forms/submit/[slug].ts +143 -0
- package/routes/api/img/[...path].ts +65 -0
- package/routes/api/{cms/preview → preview}/render.ts +8 -3
- package/routes/api/{cms/references → references}/[collection]/[id].ts +31 -1
- package/routes/api/webhooks/[provider].ts +54 -0
- package/README.md +0 -28
- package/dist/admin.d.ts +0 -33
- package/dist/admin.js +0 -92
- package/dist/ai.d.ts +0 -15
- package/dist/ai.js +0 -70
- package/dist/api.d.ts +0 -14
- package/dist/api.js +0 -833
- package/dist/assets.d.ts +0 -51
- package/dist/assets.js +0 -163
- package/dist/auth.d.ts +0 -30
- package/dist/auth.js +0 -132
- package/dist/content.d.ts +0 -3
- package/dist/content.js +0 -29
- package/dist/create-admin.d.ts +0 -5
- package/dist/create-admin.js +0 -23
- package/dist/define.d.ts +0 -254
- package/dist/define.js +0 -36
- package/dist/generator.d.ts +0 -9
- package/dist/generator.js +0 -370
- package/dist/image.d.ts +0 -9
- package/dist/image.js +0 -69
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -16
- package/dist/integration.d.ts +0 -14
- package/dist/integration.js +0 -327
- package/dist/locks.d.ts +0 -7
- package/dist/locks.js +0 -37
- package/dist/richtext.d.ts +0 -1
- package/dist/richtext.js +0 -1
- package/dist/runtime.d.ts +0 -24
- package/dist/runtime.js +0 -26
- package/dist/schema.d.ts +0 -17
- package/dist/schema.js +0 -13
- package/dist/seed.d.ts +0 -2
- package/dist/seed.js +0 -84
- package/dist/values.d.ts +0 -8
- package/dist/values.js +0 -102
- package/dist/webhooks.d.ts +0 -2
- package/dist/webhooks.js +0 -73
- package/routes/api/cms/assets/upload.ts +0 -112
- package/routes/api/cms/auth/login.ts +0 -124
- package/routes/api/cms/auth/setup.ts +0 -77
- package/routes/api/cms/img/[...path].ts +0 -24
- package/routes/pages/admin/[...path].astro +0 -1107
- package/routes/pages/admin/assets/index.astro +0 -63
- /package/routes/api/{cms/ai → ai}/alt-text.ts +0 -0
- /package/routes/api/{cms/ai → ai}/seo.ts +0 -0
- /package/routes/api/{cms/ai → ai}/translate.ts +0 -0
- /package/routes/api/{cms/assets → assets}/folders.ts +0 -0
- /package/routes/api/{cms/locks → locks}/[...path].ts +0 -0
package/dist/define.d.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
export type CollectionLabels = {
|
|
2
|
-
singular: string;
|
|
3
|
-
plural: string;
|
|
4
|
-
};
|
|
5
|
-
export type DatabaseConfig = {
|
|
6
|
-
dialect: "sqlite" | "postgres";
|
|
7
|
-
url?: string;
|
|
8
|
-
};
|
|
9
|
-
export type LocaleConfig = {
|
|
10
|
-
default: string;
|
|
11
|
-
supported: string[];
|
|
12
|
-
};
|
|
13
|
-
export type AdminFieldComponent = {
|
|
14
|
-
component?: string;
|
|
15
|
-
placeholder?: string;
|
|
16
|
-
position?: "content" | "sidebar";
|
|
17
|
-
rows?: number;
|
|
18
|
-
help?: string;
|
|
19
|
-
hidden?: boolean;
|
|
20
|
-
};
|
|
21
|
-
export type FieldCondition = {
|
|
22
|
-
field: string;
|
|
23
|
-
value: string | string[] | boolean;
|
|
24
|
-
};
|
|
25
|
-
type BaseFieldConfig<TType extends string, TValue = unknown> = {
|
|
26
|
-
type: TType;
|
|
27
|
-
label?: string;
|
|
28
|
-
description?: string;
|
|
29
|
-
required?: boolean;
|
|
30
|
-
defaultValue?: TValue;
|
|
31
|
-
indexed?: boolean;
|
|
32
|
-
unique?: boolean;
|
|
33
|
-
translatable?: boolean;
|
|
34
|
-
condition?: FieldCondition;
|
|
35
|
-
admin?: AdminFieldComponent;
|
|
36
|
-
access?: {
|
|
37
|
-
read?: (context: {
|
|
38
|
-
user?: {
|
|
39
|
-
id: string;
|
|
40
|
-
role?: string;
|
|
41
|
-
email?: string;
|
|
42
|
-
} | null;
|
|
43
|
-
doc?: Record<string, unknown> | null;
|
|
44
|
-
operation: string;
|
|
45
|
-
collection: string;
|
|
46
|
-
}) => boolean | Promise<boolean>;
|
|
47
|
-
update?: (context: {
|
|
48
|
-
user?: {
|
|
49
|
-
id: string;
|
|
50
|
-
role?: string;
|
|
51
|
-
email?: string;
|
|
52
|
-
} | null;
|
|
53
|
-
doc?: Record<string, unknown> | null;
|
|
54
|
-
operation: string;
|
|
55
|
-
collection: string;
|
|
56
|
-
}) => boolean | Promise<boolean>;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
export type TextFieldConfig = BaseFieldConfig<"text", string> & {
|
|
60
|
-
maxLength?: number;
|
|
61
|
-
};
|
|
62
|
-
export type SlugFieldConfig = BaseFieldConfig<"slug", string> & {
|
|
63
|
-
from?: string;
|
|
64
|
-
};
|
|
65
|
-
export type EmailFieldConfig = BaseFieldConfig<"email", string>;
|
|
66
|
-
export type NumberFieldConfig = BaseFieldConfig<"number", number>;
|
|
67
|
-
export type BooleanFieldConfig = BaseFieldConfig<"boolean", boolean>;
|
|
68
|
-
export type DateFieldConfig = BaseFieldConfig<"date", string>;
|
|
69
|
-
export type SelectFieldConfig = BaseFieldConfig<"select", string> & {
|
|
70
|
-
options: string[];
|
|
71
|
-
};
|
|
72
|
-
export type RichTextNode = {
|
|
73
|
-
type: string;
|
|
74
|
-
value?: string;
|
|
75
|
-
level?: number;
|
|
76
|
-
children?: RichTextNode[];
|
|
77
|
-
[key: string]: unknown;
|
|
78
|
-
};
|
|
79
|
-
export type RichTextDocument = {
|
|
80
|
-
type: "root";
|
|
81
|
-
children: RichTextNode[];
|
|
82
|
-
};
|
|
83
|
-
export type RichTextFieldConfig = BaseFieldConfig<"richText", RichTextDocument>;
|
|
84
|
-
export type ImageFieldConfig = BaseFieldConfig<"image", string>;
|
|
85
|
-
export type RelationFieldConfig = BaseFieldConfig<"relation", string | string[]> & {
|
|
86
|
-
collection: string;
|
|
87
|
-
hasMany?: boolean;
|
|
88
|
-
};
|
|
89
|
-
export type ArrayFieldConfig = BaseFieldConfig<"array", unknown[]> & {
|
|
90
|
-
of: FieldConfig;
|
|
91
|
-
};
|
|
92
|
-
export type JsonFieldConfig = BaseFieldConfig<"json", unknown> & {
|
|
93
|
-
schema?: string;
|
|
94
|
-
};
|
|
95
|
-
export type BlocksFieldConfig = BaseFieldConfig<"blocks", Array<Record<string, unknown>>> & {
|
|
96
|
-
types: Record<string, Record<string, FieldConfig>>;
|
|
97
|
-
};
|
|
98
|
-
export type FieldConfig = TextFieldConfig | SlugFieldConfig | EmailFieldConfig | NumberFieldConfig | BooleanFieldConfig | DateFieldConfig | SelectFieldConfig | RichTextFieldConfig | ImageFieldConfig | RelationFieldConfig | ArrayFieldConfig | JsonFieldConfig | BlocksFieldConfig;
|
|
99
|
-
export type CollectionFieldMap = Record<string, FieldConfig>;
|
|
100
|
-
export type SeedDocument = Record<string, unknown>;
|
|
101
|
-
export type CollectionViewConfig = {
|
|
102
|
-
list?: {
|
|
103
|
-
columns?: string[];
|
|
104
|
-
defaultSort?: {
|
|
105
|
-
field: string;
|
|
106
|
-
direction: "asc" | "desc";
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
export type CollectionConfig = {
|
|
111
|
-
slug: string;
|
|
112
|
-
labels: CollectionLabels;
|
|
113
|
-
labelField?: string;
|
|
114
|
-
pathPrefix?: string;
|
|
115
|
-
preview?: boolean | string;
|
|
116
|
-
timestamps?: boolean;
|
|
117
|
-
drafts?: boolean;
|
|
118
|
-
versions?: {
|
|
119
|
-
max: number;
|
|
120
|
-
};
|
|
121
|
-
auth?: boolean;
|
|
122
|
-
singleton?: boolean;
|
|
123
|
-
access?: CollectionAccess;
|
|
124
|
-
hooks?: CollectionHooks;
|
|
125
|
-
fields: CollectionFieldMap;
|
|
126
|
-
views?: CollectionViewConfig;
|
|
127
|
-
seed?: SeedDocument[];
|
|
128
|
-
};
|
|
129
|
-
export type AdminNavItem = {
|
|
130
|
-
label: string;
|
|
131
|
-
href: string;
|
|
132
|
-
icon?: string;
|
|
133
|
-
/** Sort order — lower values appear first (default: 0) */
|
|
134
|
-
weight?: number;
|
|
135
|
-
};
|
|
136
|
-
export type WebhookEvent = "create" | "update" | "delete" | "publish" | "unpublish";
|
|
137
|
-
export type WebhookContext = {
|
|
138
|
-
user?: {
|
|
139
|
-
id: string;
|
|
140
|
-
role?: string;
|
|
141
|
-
email?: string;
|
|
142
|
-
} | null;
|
|
143
|
-
event: WebhookEvent;
|
|
144
|
-
collection: string;
|
|
145
|
-
timestamp: string;
|
|
146
|
-
};
|
|
147
|
-
export type WebhookConfig = {
|
|
148
|
-
/** Display name (shown in logs) */
|
|
149
|
-
name: string;
|
|
150
|
-
/** URL to POST to */
|
|
151
|
-
url: string;
|
|
152
|
-
/** Events that trigger this webhook */
|
|
153
|
-
events: WebhookEvent[];
|
|
154
|
-
/** Restrict to specific collections (omit for all) */
|
|
155
|
-
collections?: string[];
|
|
156
|
-
/** HTTP method (default: POST) */
|
|
157
|
-
method?: "POST" | "PUT" | "PATCH";
|
|
158
|
-
/** Custom headers */
|
|
159
|
-
headers?: Record<string, string>;
|
|
160
|
-
/** Transform the payload (default: { event, collection, doc, user, timestamp }) */
|
|
161
|
-
payload?: (doc: Record<string, unknown>, context: WebhookContext) => any;
|
|
162
|
-
};
|
|
163
|
-
export type AdminUploadConfig = {
|
|
164
|
-
/** Allowed MIME types (default: images, PDF, video) */
|
|
165
|
-
allowedTypes?: string[];
|
|
166
|
-
/** Max file size in bytes (default: 50 MB) */
|
|
167
|
-
maxFileSize?: number;
|
|
168
|
-
};
|
|
169
|
-
export type AdminRateLimitConfig = {
|
|
170
|
-
/** Max login attempts before blocking (default: 5) */
|
|
171
|
-
maxAttempts?: number;
|
|
172
|
-
/** Time window in milliseconds (default: 15 minutes) */
|
|
173
|
-
windowMs?: number;
|
|
174
|
-
};
|
|
175
|
-
export type AdminConfig = {
|
|
176
|
-
dateFormat?: string;
|
|
177
|
-
nav?: AdminNavItem[];
|
|
178
|
-
uploads?: AdminUploadConfig;
|
|
179
|
-
rateLimit?: AdminRateLimitConfig;
|
|
180
|
-
/** Admin list page size (default: 20) */
|
|
181
|
-
pageSize?: number;
|
|
182
|
-
/** Webhooks fired on content events */
|
|
183
|
-
webhooks?: WebhookConfig[];
|
|
184
|
-
};
|
|
185
|
-
export type CMSConfig = {
|
|
186
|
-
database?: DatabaseConfig;
|
|
187
|
-
locales?: LocaleConfig;
|
|
188
|
-
admin?: AdminConfig;
|
|
189
|
-
collections: CollectionConfig[];
|
|
190
|
-
};
|
|
191
|
-
export type AccessContext = {
|
|
192
|
-
user?: {
|
|
193
|
-
id: string;
|
|
194
|
-
role?: string;
|
|
195
|
-
email?: string;
|
|
196
|
-
} | null;
|
|
197
|
-
doc?: Record<string, unknown> | null;
|
|
198
|
-
operation: string;
|
|
199
|
-
collection: string;
|
|
200
|
-
};
|
|
201
|
-
export type AccessRule = (context: AccessContext) => boolean | Promise<boolean>;
|
|
202
|
-
export type CollectionAccess = Partial<Record<"read" | "create" | "update" | "delete" | "publish" | "schedule", AccessRule>>;
|
|
203
|
-
export declare const hasRole: (...roles: string[]) => AccessRule;
|
|
204
|
-
export type HookContext = {
|
|
205
|
-
user?: AccessContext["user"];
|
|
206
|
-
operation: string;
|
|
207
|
-
collection: string;
|
|
208
|
-
timestamp: string;
|
|
209
|
-
cache?: {
|
|
210
|
-
invalidate: (opts: {
|
|
211
|
-
tags: string[];
|
|
212
|
-
}) => void;
|
|
213
|
-
};
|
|
214
|
-
};
|
|
215
|
-
export type CollectionHooks = {
|
|
216
|
-
beforeCreate?: (data: Record<string, unknown>, context: HookContext) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
217
|
-
afterCreate?: (doc: Record<string, unknown>, context: HookContext) => void | Promise<void>;
|
|
218
|
-
beforeUpdate?: (data: Record<string, unknown>, existing: Record<string, unknown>, context: HookContext) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
219
|
-
afterUpdate?: (doc: Record<string, unknown>, context: HookContext) => void | Promise<void>;
|
|
220
|
-
beforeDelete?: (doc: Record<string, unknown>, context: HookContext) => void | Promise<void>;
|
|
221
|
-
afterDelete?: (doc: Record<string, unknown>, context: HookContext) => void | Promise<void>;
|
|
222
|
-
beforePublish?: (doc: Record<string, unknown>, context: HookContext) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
223
|
-
afterPublish?: (doc: Record<string, unknown>, context: HookContext) => void | Promise<void>;
|
|
224
|
-
beforeUnpublish?: (doc: Record<string, unknown>, context: HookContext) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
225
|
-
afterUnpublish?: (doc: Record<string, unknown>, context: HookContext) => void | Promise<void>;
|
|
226
|
-
beforeSchedule?: (doc: Record<string, unknown>, context: HookContext) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
227
|
-
afterSchedule?: (doc: Record<string, unknown>, context: HookContext) => void | Promise<void>;
|
|
228
|
-
};
|
|
229
|
-
export declare const fields: {
|
|
230
|
-
text: (options?: Omit<TextFieldConfig, "type">) => TextFieldConfig;
|
|
231
|
-
slug: (options?: Omit<SlugFieldConfig, "type">) => SlugFieldConfig;
|
|
232
|
-
email: (options?: Omit<EmailFieldConfig, "type">) => EmailFieldConfig;
|
|
233
|
-
number: (options?: Omit<NumberFieldConfig, "type">) => NumberFieldConfig;
|
|
234
|
-
boolean: (options?: Omit<BooleanFieldConfig, "type">) => BooleanFieldConfig;
|
|
235
|
-
date: (options?: Omit<DateFieldConfig, "type">) => DateFieldConfig;
|
|
236
|
-
select: (options: Omit<SelectFieldConfig, "type">) => SelectFieldConfig;
|
|
237
|
-
richText: (options?: Omit<RichTextFieldConfig, "type">) => RichTextFieldConfig;
|
|
238
|
-
image: (options?: Omit<ImageFieldConfig, "type">) => ImageFieldConfig;
|
|
239
|
-
relation: (options: Omit<RelationFieldConfig, "type">) => RelationFieldConfig;
|
|
240
|
-
array: (options: Omit<ArrayFieldConfig, "type">) => ArrayFieldConfig;
|
|
241
|
-
json: (options?: Omit<JsonFieldConfig, "type">) => JsonFieldConfig;
|
|
242
|
-
blocks: (options: Omit<BlocksFieldConfig, "type">) => BlocksFieldConfig;
|
|
243
|
-
};
|
|
244
|
-
export declare const defineCollection: (collection: CollectionConfig) => CollectionConfig;
|
|
245
|
-
export declare const defineConfig: (config: CMSConfig) => CMSConfig;
|
|
246
|
-
export declare const getCollectionMap: (config: CMSConfig) => {
|
|
247
|
-
[k: string]: CollectionConfig;
|
|
248
|
-
};
|
|
249
|
-
export declare const getDefaultLocale: (config: CMSConfig) => string;
|
|
250
|
-
export declare const getTranslatableFieldNames: (collection: CollectionConfig) => string[];
|
|
251
|
-
export declare const isStructuralField: (field: FieldConfig) => boolean;
|
|
252
|
-
export declare const getCollectionLabel: (collection: CollectionConfig) => string;
|
|
253
|
-
export declare const getLabelField: (collection: CollectionConfig) => string;
|
|
254
|
-
export {};
|
package/dist/define.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export const hasRole = (...roles) => ({ user }) => !!user?.role && roles.includes(user.role);
|
|
2
|
-
const createField = (type, options) => ({ type, ...(options ?? {}) });
|
|
3
|
-
export const fields = {
|
|
4
|
-
text: (options) => createField("text", options),
|
|
5
|
-
slug: (options) => createField("slug", options),
|
|
6
|
-
email: (options) => createField("email", options),
|
|
7
|
-
number: (options) => createField("number", options),
|
|
8
|
-
boolean: (options) => createField("boolean", options),
|
|
9
|
-
date: (options) => createField("date", options),
|
|
10
|
-
select: (options) => createField("select", options),
|
|
11
|
-
richText: (options) => createField("richText", options),
|
|
12
|
-
image: (options) => createField("image", options),
|
|
13
|
-
relation: (options) => createField("relation", options),
|
|
14
|
-
array: (options) => createField("array", options),
|
|
15
|
-
json: (options) => createField("json", options),
|
|
16
|
-
blocks: (options) => createField("blocks", options),
|
|
17
|
-
};
|
|
18
|
-
export const defineCollection = (collection) => collection;
|
|
19
|
-
export const defineConfig = (config) => config;
|
|
20
|
-
export const getCollectionMap = (config) => Object.fromEntries(config.collections.map((collection) => [collection.slug, collection]));
|
|
21
|
-
export const getDefaultLocale = (config) => config.locales?.default ?? null;
|
|
22
|
-
export const getTranslatableFieldNames = (collection) => Object.entries(collection.fields)
|
|
23
|
-
.filter(([, field]) => field.translatable)
|
|
24
|
-
.map(([name]) => name);
|
|
25
|
-
export const isStructuralField = (field) => ["number", "boolean", "relation", "image", "date"].includes(field.type);
|
|
26
|
-
export const getCollectionLabel = (collection) => collection.labels.plural;
|
|
27
|
-
export const getLabelField = (collection) => {
|
|
28
|
-
if (collection.labelField && collection.labelField in collection.fields)
|
|
29
|
-
return collection.labelField;
|
|
30
|
-
if ("title" in collection.fields)
|
|
31
|
-
return "title";
|
|
32
|
-
if ("name" in collection.fields)
|
|
33
|
-
return "name";
|
|
34
|
-
const firstTextField = Object.entries(collection.fields).find(([, field]) => field.type === "text");
|
|
35
|
-
return firstTextField ? firstTextField[0] : Object.keys(collection.fields)[0];
|
|
36
|
-
};
|
package/dist/generator.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { CMSConfig } from "./define";
|
|
2
|
-
type GeneratorOptions = {
|
|
3
|
-
outputDir: string;
|
|
4
|
-
coreImportPath?: string;
|
|
5
|
-
runtimeImportPath?: string;
|
|
6
|
-
configImportPath?: string;
|
|
7
|
-
};
|
|
8
|
-
export declare const generate: (config: CMSConfig, options: GeneratorOptions) => Promise<void>;
|
|
9
|
-
export {};
|
package/dist/generator.js
DELETED
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { getTranslatableFieldNames } from "./define";
|
|
4
|
-
const pascalCase = (value) => value
|
|
5
|
-
.split(/[^a-zA-Z0-9]+/)
|
|
6
|
-
.filter(Boolean)
|
|
7
|
-
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
8
|
-
.join("");
|
|
9
|
-
const snakeCase = (value) => value
|
|
10
|
-
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
11
|
-
.replace(/[^a-zA-Z0-9]+/g, "_")
|
|
12
|
-
.toLowerCase();
|
|
13
|
-
const isJsonField = (field) => field.type === "richText" ||
|
|
14
|
-
field.type === "array" ||
|
|
15
|
-
field.type === "json" ||
|
|
16
|
-
field.type === "blocks" ||
|
|
17
|
-
(field.type === "relation" && field.hasMany);
|
|
18
|
-
const generateColumnDef = (fieldName, field) => {
|
|
19
|
-
const colName = snakeCase(fieldName);
|
|
20
|
-
let col;
|
|
21
|
-
if (field.type === "number") {
|
|
22
|
-
col = `integer("${colName}")`;
|
|
23
|
-
}
|
|
24
|
-
else if (field.type === "boolean") {
|
|
25
|
-
col = `integer("${colName}", { mode: "boolean" })`;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
col = `text("${colName}")`;
|
|
29
|
-
}
|
|
30
|
-
if (field.required && !field.condition)
|
|
31
|
-
col += ".notNull()";
|
|
32
|
-
if (field.unique)
|
|
33
|
-
col += ".unique()";
|
|
34
|
-
if (field.defaultValue !== undefined && !isJsonField(field)) {
|
|
35
|
-
if (field.type === "number" || field.type === "boolean") {
|
|
36
|
-
col += `.default(${field.defaultValue})`;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
col += `.default(${JSON.stringify(field.defaultValue)})`;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return ` ${fieldName}: ${col},`;
|
|
43
|
-
};
|
|
44
|
-
const generateMainTable = (collection) => {
|
|
45
|
-
const tableName = `cms_${snakeCase(collection.slug)}`;
|
|
46
|
-
const varName = `cms${pascalCase(collection.slug)}`;
|
|
47
|
-
const columns = [` _id: text("_id").primaryKey(),`];
|
|
48
|
-
for (const [fieldName, field] of Object.entries(collection.fields)) {
|
|
49
|
-
columns.push(generateColumnDef(fieldName, field));
|
|
50
|
-
}
|
|
51
|
-
if (collection.drafts) {
|
|
52
|
-
columns.push(` _status: text("_status").notNull().default("draft"),`);
|
|
53
|
-
columns.push(` _publishedAt: text("_published_at"),`);
|
|
54
|
-
columns.push(` _publishAt: text("_publish_at"),`);
|
|
55
|
-
columns.push(` _unpublishAt: text("_unpublish_at"),`);
|
|
56
|
-
columns.push(` _published: text("_published"),`);
|
|
57
|
-
}
|
|
58
|
-
if (collection.timestamps !== false) {
|
|
59
|
-
columns.push(` _createdAt: text("_created_at").notNull(),`);
|
|
60
|
-
columns.push(` _updatedAt: text("_updated_at").notNull(),`);
|
|
61
|
-
}
|
|
62
|
-
return `export const ${varName} = sqliteTable("${tableName}", {\n${columns.join("\n")}\n});`;
|
|
63
|
-
};
|
|
64
|
-
const generateTranslationsTable = (config, collection) => {
|
|
65
|
-
if (!config.locales)
|
|
66
|
-
return null;
|
|
67
|
-
const translatableFields = getTranslatableFieldNames(collection);
|
|
68
|
-
if (translatableFields.length === 0)
|
|
69
|
-
return null;
|
|
70
|
-
const tableName = `cms_${snakeCase(collection.slug)}_translations`;
|
|
71
|
-
const varName = `cms${pascalCase(collection.slug)}Translations`;
|
|
72
|
-
const mainVar = `cms${pascalCase(collection.slug)}`;
|
|
73
|
-
const columns = [
|
|
74
|
-
` _id: text("_id").primaryKey(),`,
|
|
75
|
-
` _entityId: text("_entity_id").notNull().references(() => ${mainVar}._id, { onDelete: "cascade" }),`,
|
|
76
|
-
` _languageCode: text("_language_code").notNull(),`,
|
|
77
|
-
];
|
|
78
|
-
for (const fieldName of translatableFields) {
|
|
79
|
-
columns.push(generateColumnDef(fieldName, collection.fields[fieldName]));
|
|
80
|
-
}
|
|
81
|
-
return `export const ${varName} = sqliteTable("${tableName}", {\n${columns.join("\n")}\n}, (table) => ({\n uniqueLocale: unique().on(table._entityId, table._languageCode),\n}));`;
|
|
82
|
-
};
|
|
83
|
-
const generateVersionsTable = (collection) => {
|
|
84
|
-
if (!collection.versions)
|
|
85
|
-
return null;
|
|
86
|
-
const tableName = `cms_${snakeCase(collection.slug)}_versions`;
|
|
87
|
-
const varName = `cms${pascalCase(collection.slug)}Versions`;
|
|
88
|
-
const mainVar = `cms${pascalCase(collection.slug)}`;
|
|
89
|
-
return `export const ${varName} = sqliteTable("${tableName}", {
|
|
90
|
-
_id: text("_id").primaryKey(),
|
|
91
|
-
_docId: text("_doc_id").notNull().references(() => ${mainVar}._id, { onDelete: "cascade" }),
|
|
92
|
-
_version: integer("_version").notNull(),
|
|
93
|
-
_snapshot: text("_snapshot").notNull(),
|
|
94
|
-
_createdAt: text("_created_at").notNull(),
|
|
95
|
-
});`;
|
|
96
|
-
};
|
|
97
|
-
const generateSchemaFile = (config) => {
|
|
98
|
-
const parts = [
|
|
99
|
-
`// auto-generated — do not edit`,
|
|
100
|
-
`import { sqliteTable, text, integer, real, unique } from "drizzle-orm/sqlite-core";`,
|
|
101
|
-
``,
|
|
102
|
-
];
|
|
103
|
-
for (const collection of config.collections) {
|
|
104
|
-
parts.push(generateMainTable(collection));
|
|
105
|
-
const translationsTable = generateTranslationsTable(config, collection);
|
|
106
|
-
if (translationsTable)
|
|
107
|
-
parts.push("", translationsTable);
|
|
108
|
-
const versionsTable = generateVersionsTable(collection);
|
|
109
|
-
if (versionsTable)
|
|
110
|
-
parts.push("", versionsTable);
|
|
111
|
-
parts.push("");
|
|
112
|
-
}
|
|
113
|
-
parts.push(`export const cmsAssets = sqliteTable("cms_assets", {
|
|
114
|
-
_id: text("_id").primaryKey(),
|
|
115
|
-
filename: text("filename").notNull(),
|
|
116
|
-
mimeType: text("mime_type").notNull(),
|
|
117
|
-
size: integer("size").notNull(),
|
|
118
|
-
width: integer("width"),
|
|
119
|
-
height: integer("height"),
|
|
120
|
-
focalX: real("focal_x"),
|
|
121
|
-
focalY: real("focal_y"),
|
|
122
|
-
alt: text("alt"),
|
|
123
|
-
folder: text("folder"),
|
|
124
|
-
storagePath: text("storage_path").notNull(),
|
|
125
|
-
_createdAt: text("_created_at").notNull(),
|
|
126
|
-
});`);
|
|
127
|
-
parts.push("");
|
|
128
|
-
parts.push(`export const cmsAssetFolders = sqliteTable("cms_asset_folders", {
|
|
129
|
-
_id: text("_id").primaryKey(),
|
|
130
|
-
name: text("name").notNull(),
|
|
131
|
-
parent: text("parent"),
|
|
132
|
-
_createdAt: text("_created_at").notNull(),
|
|
133
|
-
});`);
|
|
134
|
-
parts.push("");
|
|
135
|
-
parts.push(`export const cmsSessions = sqliteTable("cms_sessions", {
|
|
136
|
-
_id: text("_id").primaryKey(),
|
|
137
|
-
userId: text("user_id").notNull(),
|
|
138
|
-
expiresAt: text("expires_at").notNull(),
|
|
139
|
-
});`);
|
|
140
|
-
parts.push("");
|
|
141
|
-
parts.push(`export const cmsLocks = sqliteTable("cms_locks", {
|
|
142
|
-
_id: text("_id").primaryKey(),
|
|
143
|
-
collection: text("collection").notNull(),
|
|
144
|
-
documentId: text("document_id").notNull(),
|
|
145
|
-
userId: text("user_id").notNull(),
|
|
146
|
-
userEmail: text("user_email").notNull(),
|
|
147
|
-
lockedAt: text("locked_at").notNull(),
|
|
148
|
-
});`);
|
|
149
|
-
parts.push("");
|
|
150
|
-
parts.push(`export const cmsInvites = sqliteTable("cms_invites", {
|
|
151
|
-
_id: text("_id").primaryKey(),
|
|
152
|
-
userId: text("user_id").notNull(),
|
|
153
|
-
token: text("token").notNull().unique(),
|
|
154
|
-
expiresAt: text("expires_at").notNull(),
|
|
155
|
-
usedAt: text("used_at"),
|
|
156
|
-
});`);
|
|
157
|
-
parts.push("");
|
|
158
|
-
const tableExports = [];
|
|
159
|
-
for (const collection of config.collections) {
|
|
160
|
-
const varName = `cms${pascalCase(collection.slug)}`;
|
|
161
|
-
const safeKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(collection.slug) ? collection.slug : `"${collection.slug}"`;
|
|
162
|
-
tableExports.push(` ${safeKey}: { main: ${varName}`);
|
|
163
|
-
const translatableFields = getTranslatableFieldNames(collection);
|
|
164
|
-
if (translatableFields.length > 0 && config.locales) {
|
|
165
|
-
tableExports[tableExports.length - 1] += `, translations: ${varName}Translations`;
|
|
166
|
-
}
|
|
167
|
-
if (collection.versions) {
|
|
168
|
-
tableExports[tableExports.length - 1] += `, versions: ${varName}Versions`;
|
|
169
|
-
}
|
|
170
|
-
tableExports[tableExports.length - 1] += ` },`;
|
|
171
|
-
}
|
|
172
|
-
parts.push(`export const cmsTables = {\n${tableExports.join("\n")}\n};`);
|
|
173
|
-
return parts.join("\n");
|
|
174
|
-
};
|
|
175
|
-
const zodTypeForField = (field) => {
|
|
176
|
-
if (["text", "slug", "email", "image", "date"].includes(field.type)) {
|
|
177
|
-
let zodType = "z.string()";
|
|
178
|
-
if (field.type === "email")
|
|
179
|
-
zodType = "z.string().email()";
|
|
180
|
-
if (field.type === "text" && field.maxLength)
|
|
181
|
-
zodType = `z.string().max(${field.maxLength})`;
|
|
182
|
-
return zodType;
|
|
183
|
-
}
|
|
184
|
-
if (field.type === "number")
|
|
185
|
-
return "z.number()";
|
|
186
|
-
if (field.type === "boolean")
|
|
187
|
-
return "z.boolean()";
|
|
188
|
-
if (field.type === "select")
|
|
189
|
-
return `z.enum([${field.options.map((option) => JSON.stringify(option)).join(", ")}])`;
|
|
190
|
-
if (field.type === "relation")
|
|
191
|
-
return field.hasMany ? "z.array(z.string())" : "z.string()";
|
|
192
|
-
if (field.type === "array")
|
|
193
|
-
return `z.array(${zodTypeForField(field.of)})`;
|
|
194
|
-
if (field.type === "richText")
|
|
195
|
-
return "z.object({ type: z.literal('root'), children: z.array(z.any()) })";
|
|
196
|
-
if (field.type === "json")
|
|
197
|
-
return "z.record(z.unknown())";
|
|
198
|
-
if (field.type === "blocks") {
|
|
199
|
-
const variants = Object.entries(field.types).map(([blockType, fields]) => {
|
|
200
|
-
const members = Object.entries(fields)
|
|
201
|
-
.map(([fieldName, nestedField]) => `${fieldName}: ${zodTypeForField(nestedField)}${nestedField.required ? "" : ".optional()"}`)
|
|
202
|
-
.join(", ");
|
|
203
|
-
return `z.object({ type: z.literal(${JSON.stringify(blockType)}), ${members} })`;
|
|
204
|
-
});
|
|
205
|
-
if (variants.length === 0)
|
|
206
|
-
return "z.array(z.record(z.unknown()))";
|
|
207
|
-
if (variants.length === 1)
|
|
208
|
-
return `z.array(${variants[0]})`;
|
|
209
|
-
return `z.array(z.discriminatedUnion("type", [\n ${variants.join(",\n ")},\n ]))`;
|
|
210
|
-
}
|
|
211
|
-
return "z.unknown()";
|
|
212
|
-
};
|
|
213
|
-
const generateValidatorsFile = (config) => {
|
|
214
|
-
const parts = [`// auto-generated — do not edit`, `import { z } from "zod";`, ``];
|
|
215
|
-
for (const collection of config.collections) {
|
|
216
|
-
const name = pascalCase(collection.slug);
|
|
217
|
-
const fieldEntries = Object.entries(collection.fields).map(([fieldName, field]) => {
|
|
218
|
-
const zodType = zodTypeForField(field);
|
|
219
|
-
const isOptional = !field.required || !!field.condition;
|
|
220
|
-
return ` ${fieldName}: ${zodType}${isOptional ? ".optional()" : ""},`;
|
|
221
|
-
});
|
|
222
|
-
parts.push(`export const ${name}CreateSchema = z.object({\n${fieldEntries.join("\n")}\n});`);
|
|
223
|
-
parts.push("");
|
|
224
|
-
const partialEntries = Object.entries(collection.fields).map(([fieldName, field]) => {
|
|
225
|
-
const zodType = zodTypeForField(field);
|
|
226
|
-
return ` ${fieldName}: ${zodType}.optional(),`;
|
|
227
|
-
});
|
|
228
|
-
parts.push(`export const ${name}UpdateSchema = z.object({\n${partialEntries.join("\n")}\n});`);
|
|
229
|
-
parts.push("");
|
|
230
|
-
}
|
|
231
|
-
const mapEntries = config.collections.map((collection) => {
|
|
232
|
-
const name = pascalCase(collection.slug);
|
|
233
|
-
return ` ${collection.slug}: { create: ${name}CreateSchema, update: ${name}UpdateSchema },`;
|
|
234
|
-
});
|
|
235
|
-
parts.push(`export const validators = {\n${mapEntries.join("\n")}\n};`);
|
|
236
|
-
return parts.join("\n");
|
|
237
|
-
};
|
|
238
|
-
const typeForField = (field) => {
|
|
239
|
-
if (["text", "slug", "email", "image", "date"].includes(field.type))
|
|
240
|
-
return "string";
|
|
241
|
-
if (field.type === "number")
|
|
242
|
-
return "number";
|
|
243
|
-
if (field.type === "boolean")
|
|
244
|
-
return "boolean";
|
|
245
|
-
if (field.type === "select")
|
|
246
|
-
return field.options.map((option) => JSON.stringify(option)).join(" | ");
|
|
247
|
-
if (field.type === "relation")
|
|
248
|
-
return field.hasMany ? "string[]" : "string";
|
|
249
|
-
if (field.type === "array")
|
|
250
|
-
return `${typeForField(field.of)}[]`;
|
|
251
|
-
if (field.type === "richText")
|
|
252
|
-
return "RichTextDocument";
|
|
253
|
-
if (field.type === "json")
|
|
254
|
-
return "Record<string, unknown>";
|
|
255
|
-
if (field.type === "blocks") {
|
|
256
|
-
const variants = Object.entries(field.types).map(([blockType, fields]) => {
|
|
257
|
-
const members = Object.entries(fields)
|
|
258
|
-
.map(([fieldName, nestedField]) => `${fieldName}${nestedField.required ? "" : "?"}: ${typeForField(nestedField)};`)
|
|
259
|
-
.join(" ");
|
|
260
|
-
return `{ type: ${JSON.stringify(blockType)}; ${members} }`;
|
|
261
|
-
});
|
|
262
|
-
return `Array<${variants.join(" | ")}>`;
|
|
263
|
-
}
|
|
264
|
-
return "unknown";
|
|
265
|
-
};
|
|
266
|
-
const generateTypesFile = (config, coreImportPath) => {
|
|
267
|
-
const parts = [
|
|
268
|
-
`// auto-generated — do not edit`,
|
|
269
|
-
`import type { RichTextDocument } from "${coreImportPath}";`,
|
|
270
|
-
``,
|
|
271
|
-
`export type CMSCollectionSlug = ${config.collections.map((collection) => JSON.stringify(collection.slug)).join(" | ")};`,
|
|
272
|
-
``,
|
|
273
|
-
];
|
|
274
|
-
for (const collection of config.collections) {
|
|
275
|
-
const docName = `${pascalCase(collection.slug)}Document`;
|
|
276
|
-
const inputName = `${pascalCase(collection.slug)}Input`;
|
|
277
|
-
const translationName = `${pascalCase(collection.slug)}TranslationInput`;
|
|
278
|
-
const translatableFields = getTranslatableFieldNames(collection);
|
|
279
|
-
const fieldEntries = Object.entries(collection.fields)
|
|
280
|
-
.map(([fieldName, field]) => {
|
|
281
|
-
const isOptional = !field.required || !!field.condition;
|
|
282
|
-
return ` ${fieldName}${isOptional ? "?" : ""}: ${typeForField(field)};`;
|
|
283
|
-
})
|
|
284
|
-
.join("\n");
|
|
285
|
-
const translationEntries = translatableFields.length
|
|
286
|
-
? translatableFields
|
|
287
|
-
.map((fieldName) => ` ${fieldName}?: ${typeForField(collection.fields[fieldName])};`)
|
|
288
|
-
.join("\n")
|
|
289
|
-
: " [key: string]: never;";
|
|
290
|
-
parts.push(`export type ${inputName} = {\n${fieldEntries}\n};`);
|
|
291
|
-
parts.push("");
|
|
292
|
-
parts.push(`export type ${translationName} = {\n${translationEntries}\n};`);
|
|
293
|
-
parts.push("");
|
|
294
|
-
parts.push(`export type ${docName} = ${inputName} & {
|
|
295
|
-
_id: string;
|
|
296
|
-
_status: "draft" | "published" | "scheduled";
|
|
297
|
-
_publishedAt?: string | null;
|
|
298
|
-
_publishAt?: string | null;
|
|
299
|
-
_unpublishAt?: string | null;
|
|
300
|
-
_createdAt: string;
|
|
301
|
-
_updatedAt: string;
|
|
302
|
-
_locale?: string | null;
|
|
303
|
-
_availableLocales?: string[];
|
|
304
|
-
};`);
|
|
305
|
-
parts.push("");
|
|
306
|
-
}
|
|
307
|
-
parts.push(`export type StoredVersion = {
|
|
308
|
-
version: number;
|
|
309
|
-
createdAt: string;
|
|
310
|
-
snapshot: Record<string, unknown>;
|
|
311
|
-
};`);
|
|
312
|
-
return parts.join("\n");
|
|
313
|
-
};
|
|
314
|
-
const generateApiFile = (config, coreImportPath, runtimeImportPath, configImportPath) => {
|
|
315
|
-
const imports = config.collections
|
|
316
|
-
.map((collection) => {
|
|
317
|
-
const name = pascalCase(collection.slug);
|
|
318
|
-
return [`${name}Document`, `${name}Input`, `${name}TranslationInput`];
|
|
319
|
-
})
|
|
320
|
-
.flat();
|
|
321
|
-
const apiTypes = config.collections
|
|
322
|
-
.map((collection) => {
|
|
323
|
-
const baseName = pascalCase(collection.slug);
|
|
324
|
-
const ctx = `context?: { user?: { id: string; role?: string; email?: string } | null }`;
|
|
325
|
-
const apiKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(collection.slug) ? collection.slug : `"${collection.slug}"`;
|
|
326
|
-
return ` ${apiKey}: {
|
|
327
|
-
find(options?: import("${coreImportPath}").FindOptions, ${ctx}): Promise<${baseName}Document[]>;
|
|
328
|
-
findOne(filter: Record<string, unknown> & { locale?: string; status?: "draft" | "published" | "scheduled" | "any" }, ${ctx}): Promise<${baseName}Document | null>;
|
|
329
|
-
findById(id: string, options?: { locale?: string; status?: "draft" | "published" | "scheduled" | "any" }, ${ctx}): Promise<${baseName}Document | null>;
|
|
330
|
-
create(data: ${baseName}Input, ${ctx}): Promise<${baseName}Document>;
|
|
331
|
-
update(id: string, data: Partial<${baseName}Input>, ${ctx}): Promise<${baseName}Document>;
|
|
332
|
-
delete(id: string, ${ctx}): Promise<void>;
|
|
333
|
-
count(filter?: Omit<import("${coreImportPath}").FindOptions, "limit" | "offset" | "sort">, ${ctx}): Promise<number>;
|
|
334
|
-
versions(id: string): Promise<import("./types").StoredVersion[]>;
|
|
335
|
-
restore(id: string, versionNumber: number, ${ctx}): Promise<${baseName}Document>;
|
|
336
|
-
publish(id: string, ${ctx}): Promise<${baseName}Document>;
|
|
337
|
-
unpublish(id: string, ${ctx}): Promise<${baseName}Document>;
|
|
338
|
-
schedule(id: string, publishAt: string, unpublishAt?: string | null, ${ctx}): Promise<${baseName}Document>;
|
|
339
|
-
getTranslations(id: string): Promise<Record<string, ${baseName}TranslationInput>>;
|
|
340
|
-
upsertTranslation(id: string, locale: string, data: ${baseName}TranslationInput, ${ctx}): Promise<${baseName}Document>;
|
|
341
|
-
};`;
|
|
342
|
-
})
|
|
343
|
-
.join("\n");
|
|
344
|
-
return `// auto-generated — do not edit
|
|
345
|
-
import config from "${configImportPath}";
|
|
346
|
-
import { createCms } from "${runtimeImportPath}";
|
|
347
|
-
import type {
|
|
348
|
-
${imports.map((entry) => `${entry},`).join("\n ")}
|
|
349
|
-
} from "./types";
|
|
350
|
-
|
|
351
|
-
export const cms = createCms(config) as {
|
|
352
|
-
${apiTypes}
|
|
353
|
-
meta: ReturnType<typeof createCms>["meta"];
|
|
354
|
-
scheduled: ReturnType<typeof createCms>["scheduled"];
|
|
355
|
-
};
|
|
356
|
-
`;
|
|
357
|
-
};
|
|
358
|
-
export const generate = async (config, options) => {
|
|
359
|
-
const outputDir = options.outputDir;
|
|
360
|
-
const coreImportPath = options.coreImportPath ?? "@kidecms/core";
|
|
361
|
-
const runtimeImportPath = options.runtimeImportPath ?? "../runtime";
|
|
362
|
-
const configImportPath = options.configImportPath ?? "../cms.config";
|
|
363
|
-
await mkdir(outputDir, { recursive: true });
|
|
364
|
-
await Promise.all([
|
|
365
|
-
writeFile(path.join(outputDir, "schema.ts"), generateSchemaFile(config), "utf-8"),
|
|
366
|
-
writeFile(path.join(outputDir, "types.ts"), generateTypesFile(config, coreImportPath), "utf-8"),
|
|
367
|
-
writeFile(path.join(outputDir, "validators.ts"), generateValidatorsFile(config), "utf-8"),
|
|
368
|
-
writeFile(path.join(outputDir, "api.ts"), generateApiFile(config, coreImportPath, runtimeImportPath, configImportPath), "utf-8"),
|
|
369
|
-
]);
|
|
370
|
-
};
|
package/dist/image.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const ALLOWED_FORMATS: readonly ["webp", "avif", "jpeg", "png"];
|
|
2
|
-
type Format = (typeof ALLOWED_FORMATS)[number];
|
|
3
|
-
export declare function cmsImage(src: string, width?: number, format?: Format): string;
|
|
4
|
-
export declare function cmsSrcset(src: string, widths?: number[], format?: Format): string;
|
|
5
|
-
export declare function transformImage(src: string, width?: number, format?: string, quality?: number): Promise<{
|
|
6
|
-
buffer: Buffer;
|
|
7
|
-
contentType: string;
|
|
8
|
-
} | null>;
|
|
9
|
-
export {};
|