kizunacms 0.0.0 → 0.1.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.MD +9 -0
- package/README.md +208 -0
- package/dist/access-4YiqVHXB.d.mts +1251 -0
- package/dist/access-CrrWP0hv.d.cts +1251 -0
- package/dist/db-Cnv0aXba.cjs +1603 -0
- package/dist/db-wUR_ude-.mjs +1274 -0
- package/dist/index.cjs +2716 -0
- package/dist/index.d.cts +545 -0
- package/dist/index.d.mts +545 -0
- package/dist/index.mjs +2701 -0
- package/dist/postgres.cjs +1152 -0
- package/dist/postgres.d.cts +99 -0
- package/dist/postgres.d.mts +99 -0
- package/dist/postgres.mjs +1151 -0
- package/package.json +96 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
import { $ as TextField, A as StorageAdapter, B as DateTimeField, C as StoredDocument, D as Where, E as SortOf, F as GlobalDefinition, G as FieldColumn, H as Field, I as GlobalOf, J as RelationshipField, K as FieldValue, L as BooleanField, M as diskStorage, N as memoryStorage, O as WhereOf, P as Global, Q as SlugSchema, R as BuiltInField, S as ListOptions, T as OperatorsFor, U as FieldAffixes, V as EmailField, W as FieldBase, X as SelectOption, Y as SelectField, Z as SlugField, _ as MetaOptions, a as GlobalAuth, at as SessionRecord, b as DocumentPage, c as CollectionDefinition, d as DocumentMeta, et as UrlField, f as DocumentOf, g as labelsOf, h as documentSchemaOf, i as DocumentRole, it as PasswordReset, j as StorageDefinition, k as Storage, l as ContentOf, m as LoginOptions, n as AuthRule, nt as columnOf, o as RolesOption, ot as hashPassword, p as Labels, q as NumberField, r as CollectionAuth, rt as schemaOf, s as Collection, st as verifyPassword, t as ADMIN_ROLE, tt as WithStoreFields, u as DeclaredCollection, v as MetaTitleOptions, w as memoryAdapter, x as GLOBALS_COLLECTION, y as DatabaseAdapter, z as DateField } from "./access-CrrWP0hv.cjs";
|
|
2
|
+
import * as _$kizunajs from "kizunajs";
|
|
3
|
+
import { GroupOptions, Jobs, Kizuna as Kizuna$1, KizunaConfigInput, KizunaConfigShape, PermissionCatalog, PermissionSet, PluginList, RequestContextSchema, Roles, RouteAuthRule, Routes, SecurityScheme, defineConfig as defineConfig$1 } from "kizunajs";
|
|
4
|
+
import { AnyAdapter } from "kizunajs/adapter";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
//#region src/editors.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* An editor's account, as a document of the collection editors log in from. It never holds the password.
|
|
10
|
+
*/
|
|
11
|
+
type Editor<RoleName extends string = string> = StoredDocument & {
|
|
12
|
+
email: string;
|
|
13
|
+
roles: RoleName[];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A new editor's email, password and roles, with values for the editors collection's own fields.
|
|
17
|
+
*/
|
|
18
|
+
type NewEditor<RoleName extends string = string> = {
|
|
19
|
+
email: string;
|
|
20
|
+
password: string;
|
|
21
|
+
roles: readonly RoleName[];
|
|
22
|
+
} & Record<string, unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Editor accounts your own server code can create and find, without access checks.
|
|
25
|
+
*/
|
|
26
|
+
interface EditorsApi<RoleName extends string = string> {
|
|
27
|
+
/**
|
|
28
|
+
* Creates an editor's account with a password of at least 12 characters. Throws when another editor has the email.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* await kizuna.editors.create({
|
|
32
|
+
* email: 'admin@example.com',
|
|
33
|
+
* name: 'Admin',
|
|
34
|
+
* password: process.env.ADMIN_PASSWORD,
|
|
35
|
+
* roles: ['admin'],
|
|
36
|
+
* });
|
|
37
|
+
*/
|
|
38
|
+
create: (editor: NewEditor<RoleName>) => Promise<Editor<RoleName>>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a page of editors, 20 at a time unless `limit` says otherwise, or the one editor with `email`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const { total } = await kizuna.editors.find({
|
|
44
|
+
* email: 'admin@example.com',
|
|
45
|
+
* });
|
|
46
|
+
*/
|
|
47
|
+
find: (options?: {
|
|
48
|
+
email?: string;
|
|
49
|
+
offset?: number;
|
|
50
|
+
limit?: number;
|
|
51
|
+
}) => Promise<{
|
|
52
|
+
items: Editor<RoleName>[];
|
|
53
|
+
total: number;
|
|
54
|
+
}>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The bearer identity editors log in to the admin as.
|
|
58
|
+
*/
|
|
59
|
+
declare const editorIdentityOf: (db: DatabaseAdapter, roles: RolesOption, collection: Collection) => _$kizunajs.IdentityWithGuard<_$kizunajs.Identity<z.ZodObject<{
|
|
60
|
+
id: z.ZodString;
|
|
61
|
+
session: z.ZodString;
|
|
62
|
+
}, z.core.$strip>, _$kizunajs.Roles<_$kizunajs.PermissionCatalog | undefined, string>, {
|
|
63
|
+
bearer: _$kizunajs.BearerCredential | null;
|
|
64
|
+
}, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | undefined>>;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/slugs.d.ts
|
|
67
|
+
/**
|
|
68
|
+
* How the CMS spells the slugs it fills in.
|
|
69
|
+
*/
|
|
70
|
+
interface SlugOptions {
|
|
71
|
+
/**
|
|
72
|
+
* The language letters are spelled in. `'nb'` spells å and ø as `aa` and `oe` instead of `a` and `o`.
|
|
73
|
+
*/
|
|
74
|
+
locale?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Text to swap before the slug is spelled, as pairs of what to find and what to write instead.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* replacements: [['&', 'og']],
|
|
80
|
+
*/
|
|
81
|
+
replacements?: readonly (readonly [string, string])[];
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/define-config.d.ts
|
|
85
|
+
/**
|
|
86
|
+
* The options `defineConfig` takes for the CMS. It takes every Kizuna.js option beside them.
|
|
87
|
+
*/
|
|
88
|
+
interface CmsOptions<Collections extends readonly Collection[] = readonly Collection[], RoleName extends string = string, Globals extends readonly Global[] = readonly Global[]> {
|
|
89
|
+
/**
|
|
90
|
+
* The name the admin shows for this CMS.
|
|
91
|
+
*/
|
|
92
|
+
name: string;
|
|
93
|
+
/**
|
|
94
|
+
* Where documents, accounts and sessions are kept, like `postgresAdapter()` from `kizunacms/postgres`.
|
|
95
|
+
* `memoryAdapter()` keeps them in memory, for tests.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* db: postgresAdapter(drizzle(process.env.DATABASE_URL)),
|
|
99
|
+
*/
|
|
100
|
+
db: DatabaseAdapter;
|
|
101
|
+
/**
|
|
102
|
+
* The collections this CMS holds, each declared with `k.collection`.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* collections: [Articles, Authors],
|
|
106
|
+
*/
|
|
107
|
+
collections: Collections;
|
|
108
|
+
/**
|
|
109
|
+
* The globals this CMS holds, each declared with `k.global`.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* globals: [Settings, Footer],
|
|
113
|
+
*/
|
|
114
|
+
globals?: Globals;
|
|
115
|
+
/**
|
|
116
|
+
* The text every search title ends with.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* meta: {
|
|
120
|
+
* suffix: 'Example',
|
|
121
|
+
* separator: '|',
|
|
122
|
+
* },
|
|
123
|
+
*/
|
|
124
|
+
meta?: MetaTitleOptions;
|
|
125
|
+
/**
|
|
126
|
+
* How the CMS spells the slugs it fills in from a title.
|
|
127
|
+
*
|
|
128
|
+
* @default å becomes `a`
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* slugs: {
|
|
132
|
+
* locale: 'nb',
|
|
133
|
+
* replacements: [['&', 'og']],
|
|
134
|
+
* },
|
|
135
|
+
*/
|
|
136
|
+
slugs?: SlugOptions;
|
|
137
|
+
/**
|
|
138
|
+
* The login collection users log in to the admin from. It needs `login: true`, and the CMS adds a `roles` field to
|
|
139
|
+
* it. Your own routes let its users in with `auth: 'editor'`.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* users: Users,
|
|
143
|
+
*/
|
|
144
|
+
users: Collection;
|
|
145
|
+
/**
|
|
146
|
+
* Every role a user can hold beside `admin`. Admins pass every collection's, global's and store's `auth`, and may
|
|
147
|
+
* set other users' roles. Pass `Kizuna.roles(permissions, { ... })` instead of names to let a collection's `auth`
|
|
148
|
+
* ask for permissions with `requires`, and `admin` holds every permission.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* roles: ['editor', 'author'],
|
|
152
|
+
*/
|
|
153
|
+
roles: RolesOption<RoleName>;
|
|
154
|
+
/**
|
|
155
|
+
* Roles a user holds only on the documents that name them in a field. A collection's `auth.update` and
|
|
156
|
+
* `auth.delete` may list them beside the roles in `roles`. Only admins and the roles an operation lists may change
|
|
157
|
+
* the field that names the holder.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* documentRoles: {
|
|
161
|
+
* author: {
|
|
162
|
+
* field: 'author',
|
|
163
|
+
* },
|
|
164
|
+
* },
|
|
165
|
+
*/
|
|
166
|
+
documentRoles?: Readonly<Record<string, DocumentRole>>;
|
|
167
|
+
/**
|
|
168
|
+
* The stores image and file fields upload to, each declared with `k.storage`.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* storage: [Images, Documents],
|
|
172
|
+
*/
|
|
173
|
+
storage?: readonly Storage[];
|
|
174
|
+
/**
|
|
175
|
+
* The path every CMS route is served under. `'/cms'` serves the `articles` collection at `/cms/articles`.
|
|
176
|
+
*
|
|
177
|
+
* @default '', which serves `articles` at `/articles`
|
|
178
|
+
*/
|
|
179
|
+
basePath?: string;
|
|
180
|
+
/**
|
|
181
|
+
* The URL the CMS's routes are reached at, like `https://cms.example.com`, with no trailing slash.
|
|
182
|
+
*/
|
|
183
|
+
baseUrl?: string;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The CMS's collections, globals, stores and settings, as the admin reads them from `kizuna.cms`.
|
|
187
|
+
*/
|
|
188
|
+
interface CmsDefinition<Collections extends readonly Collection[] = readonly Collection[], Globals extends readonly Global[] = readonly Global[]> {
|
|
189
|
+
name: string;
|
|
190
|
+
/**
|
|
191
|
+
* The path every CMS route is served under, or `''` for the root.
|
|
192
|
+
*/
|
|
193
|
+
basePath: string;
|
|
194
|
+
db: DatabaseAdapter;
|
|
195
|
+
collections: Collections;
|
|
196
|
+
globals: Globals;
|
|
197
|
+
slugs: SlugOptions | undefined;
|
|
198
|
+
meta: MetaTitleOptions | undefined;
|
|
199
|
+
/**
|
|
200
|
+
* The groups that hold collections, with their titles, in the order the app declares them.
|
|
201
|
+
*/
|
|
202
|
+
groups: readonly {
|
|
203
|
+
name: string;
|
|
204
|
+
title: string;
|
|
205
|
+
}[];
|
|
206
|
+
/**
|
|
207
|
+
* The collection users log in to the admin from, with its `email` and `roles` fields.
|
|
208
|
+
*/
|
|
209
|
+
users: Collection;
|
|
210
|
+
/**
|
|
211
|
+
* Every role a user can hold, `admin` first.
|
|
212
|
+
*/
|
|
213
|
+
roles: RolesOption;
|
|
214
|
+
documentRoles: Readonly<Record<string, DocumentRole>> | undefined;
|
|
215
|
+
storage: readonly Storage[];
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Creates a CMS from its collections, globals, stores and users. It takes every Kizuna.js `defineConfig` option too,
|
|
219
|
+
* and serves each collection's routes beside the app's own.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* export default defineConfig({
|
|
223
|
+
* name: 'Example',
|
|
224
|
+
* db: postgresAdapter(drizzle(process.env.DATABASE_URL)),
|
|
225
|
+
* collections: [Articles, Users],
|
|
226
|
+
* users: Users,
|
|
227
|
+
* roles: ['editor'],
|
|
228
|
+
* });
|
|
229
|
+
*/
|
|
230
|
+
declare const defineConfig: <const R extends readonly Routes[] = readonly [], const J extends Jobs = Record<string, never>, const P extends PluginList = readonly [], const Groups extends Record<string, GroupOptions | string> = {}, const Codes extends string = never, const Identities extends Record<string, SecurityScheme> = Record<string, never>, const RequestContext extends Record<string, RequestContextSchema> = Record<string, never>, GuardSchema extends z.ZodType | undefined = undefined, const AdapterValue extends AnyAdapter | undefined = undefined, const Collections extends readonly Collection[] = readonly Collection[], const RoleName extends string = never, const Globals extends readonly Global[] = readonly []>(options: KizunaConfigInput<R, J, P, Groups, Codes, Identities, RequestContext, GuardSchema, AdapterValue> & CmsOptions<Collections, RoleName, Globals>) => ReturnType<typeof defineConfig$1<R, J, P, Groups, Codes, Identities, RequestContext, GuardSchema, AdapterValue>> & {
|
|
231
|
+
cms: CmsDefinition<Collections, Globals>;
|
|
232
|
+
/**
|
|
233
|
+
* Editor accounts your own server code can create and find, without access checks.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* await kizuna.editors.create({
|
|
237
|
+
* email: 'admin@example.com',
|
|
238
|
+
* name: 'Admin',
|
|
239
|
+
* password: process.env.ADMIN_PASSWORD,
|
|
240
|
+
* roles: ['admin'],
|
|
241
|
+
* });
|
|
242
|
+
*/
|
|
243
|
+
editors: EditorsApi<typeof ADMIN_ROLE | RoleName>;
|
|
244
|
+
};
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/kizuna.d.ts
|
|
247
|
+
/**
|
|
248
|
+
* The names a CMS declares, as `kizuna generate` writes them into the app's `Config` under `cms`.
|
|
249
|
+
*/
|
|
250
|
+
interface CmsNames {
|
|
251
|
+
collections?: string;
|
|
252
|
+
globals?: string;
|
|
253
|
+
roles?: string;
|
|
254
|
+
documentRoles?: string;
|
|
255
|
+
permissions?: object;
|
|
256
|
+
storage?: object;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The `Config` a CMS's `k` takes: Kizuna.js's own keys, plus the CMS's names under `cms`.
|
|
260
|
+
*/
|
|
261
|
+
interface CmsConfigShape extends KizunaConfigShape {
|
|
262
|
+
cms?: CmsNames;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* The collection names `kizuna generate` wrote into `Config`, or any name before it runs.
|
|
266
|
+
*/
|
|
267
|
+
type CollectionNamesOf<Config> = Config extends {
|
|
268
|
+
cms: {
|
|
269
|
+
collections: infer Names extends string;
|
|
270
|
+
};
|
|
271
|
+
} ? Names : string;
|
|
272
|
+
/**
|
|
273
|
+
* The store names `kizuna generate` wrote into `Config`, or any name before it runs.
|
|
274
|
+
*/
|
|
275
|
+
type StorageNamesOf<Config> = Config extends {
|
|
276
|
+
cms: {
|
|
277
|
+
storage: infer Stores extends object;
|
|
278
|
+
};
|
|
279
|
+
} ? keyof Stores & string : string;
|
|
280
|
+
type StoreEntryField<Name extends string, Entry> = Entry extends {
|
|
281
|
+
type: 'select';
|
|
282
|
+
options: infer Option extends string;
|
|
283
|
+
} ? {
|
|
284
|
+
name: Name;
|
|
285
|
+
type: 'select';
|
|
286
|
+
options: readonly Option[];
|
|
287
|
+
required: Entry extends {
|
|
288
|
+
required: 'true';
|
|
289
|
+
} ? true : false;
|
|
290
|
+
many: Entry extends {
|
|
291
|
+
many: 'true';
|
|
292
|
+
} ? true : false;
|
|
293
|
+
} : Entry extends {
|
|
294
|
+
type: infer Type extends 'text' | 'number' | 'boolean' | 'url' | 'email' | 'slug' | 'date' | 'dateTime';
|
|
295
|
+
} ? {
|
|
296
|
+
name: Name;
|
|
297
|
+
type: Type;
|
|
298
|
+
required: Entry extends {
|
|
299
|
+
required: 'true';
|
|
300
|
+
} ? true : false;
|
|
301
|
+
} : never;
|
|
302
|
+
/**
|
|
303
|
+
* A store's own fields, rebuilt from what `kizuna generate` wrote into `Config`.
|
|
304
|
+
*/
|
|
305
|
+
type StoreFieldsOf<Config, StoreName> = Config extends {
|
|
306
|
+
cms: {
|
|
307
|
+
storage: infer Stores;
|
|
308
|
+
};
|
|
309
|
+
} ? StoreName extends keyof Stores ? readonly { [Name in keyof Stores[StoreName] & string]: StoreEntryField<Name, Stores[StoreName][Name]> }[keyof Stores[StoreName] & string][] : readonly [] : readonly [];
|
|
310
|
+
/**
|
|
311
|
+
* The fields, with each image and file field carrying its store's own fields.
|
|
312
|
+
*/
|
|
313
|
+
type WithStores<Fields extends readonly Field[], Config> = { readonly [Index in keyof Fields]: Fields[Index] extends {
|
|
314
|
+
type: 'image' | 'file';
|
|
315
|
+
storage: infer StoreName;
|
|
316
|
+
} ? Fields[Index] & WithStoreFields<StoreFieldsOf<Config, StoreName>> : Fields[Index] };
|
|
317
|
+
/**
|
|
318
|
+
* The groups `k.groups` declares, or any name before `kizuna generate` runs.
|
|
319
|
+
*/
|
|
320
|
+
type GroupNamesOf<Config> = Config extends {
|
|
321
|
+
groups: {
|
|
322
|
+
declared: infer Declared;
|
|
323
|
+
};
|
|
324
|
+
} ? keyof Declared & string : string;
|
|
325
|
+
type TextFieldNamesOf<Fields extends readonly Field[]> = Extract<Fields[number], {
|
|
326
|
+
type: 'text';
|
|
327
|
+
}>['name'];
|
|
328
|
+
type ImageFieldNamesOf<Fields extends readonly Field[]> = Extract<Fields[number], {
|
|
329
|
+
type: 'image';
|
|
330
|
+
}>['name'];
|
|
331
|
+
/**
|
|
332
|
+
* The fields, with each slug's `generateFrom` checked against the text fields beside it.
|
|
333
|
+
*/
|
|
334
|
+
type WithCheckedSlugs<Fields extends readonly Field[]> = { readonly [Index in keyof Fields]: Fields[Index] extends {
|
|
335
|
+
type: 'slug';
|
|
336
|
+
generateFrom: infer From extends string;
|
|
337
|
+
} ? From extends TextFieldNamesOf<Fields> ? Fields[Index] : Omit<Fields[Index], 'generateFrom'> & {
|
|
338
|
+
generateFrom: TextFieldNamesOf<Fields>;
|
|
339
|
+
} : Fields[Index] };
|
|
340
|
+
/**
|
|
341
|
+
* What `meta` may point at: the collection's text fields and its image fields.
|
|
342
|
+
*/
|
|
343
|
+
type MetaOptionsOf<Fields extends readonly Field[], Config> = true | {
|
|
344
|
+
title?: {
|
|
345
|
+
generateFrom?: TextFieldNamesOf<Fields>;
|
|
346
|
+
};
|
|
347
|
+
description?: {
|
|
348
|
+
generateFrom?: TextFieldNamesOf<Fields>;
|
|
349
|
+
};
|
|
350
|
+
image?: {
|
|
351
|
+
generateFrom?: ImageFieldNamesOf<Fields>;
|
|
352
|
+
storage?: StorageNamesOf<Config>;
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
type EditorIdentity = ReturnType<typeof editorIdentityOf>;
|
|
356
|
+
/**
|
|
357
|
+
* The names `kizuna generate` wrote under `cms`, or none before it runs.
|
|
358
|
+
*/
|
|
359
|
+
type CmsOf<Config> = Config extends {
|
|
360
|
+
cms: infer Cms extends object;
|
|
361
|
+
} ? [Cms] extends [never] ? {} : Cms : {};
|
|
362
|
+
type CmsRoleNamesOf<Config> = CmsOf<Config> extends {
|
|
363
|
+
roles: infer Names extends string;
|
|
364
|
+
} ? Names : string;
|
|
365
|
+
type DocumentRoleNamesOf<Config> = CmsOf<Config> extends {
|
|
366
|
+
documentRoles: infer Names extends string;
|
|
367
|
+
} ? Names : CmsOf<Config> extends {
|
|
368
|
+
roles: string;
|
|
369
|
+
} ? never : string;
|
|
370
|
+
type EditorCatalogOf<Config> = CmsOf<Config> extends {
|
|
371
|
+
permissions: infer Catalog extends object;
|
|
372
|
+
} ? { [Resource in keyof Catalog & string]: readonly (Catalog[Resource] & string)[] } : never;
|
|
373
|
+
/**
|
|
374
|
+
* A rule for the `editor` identity, naming roles or permissions from the config's `roles`.
|
|
375
|
+
*/
|
|
376
|
+
type EditorRuleOf<Config> = {
|
|
377
|
+
identity: 'editor';
|
|
378
|
+
roles?: CmsRoleNamesOf<Config> | readonly CmsRoleNamesOf<Config>[];
|
|
379
|
+
requires?: EditorCatalogOf<Config> extends infer Catalog extends PermissionCatalog ? PermissionSet<Catalog> : never;
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* A rule for one of the app's own identities, or any rule before `kizuna generate` runs.
|
|
383
|
+
*/
|
|
384
|
+
type AppRuleOf<Config> = CmsOf<Config> extends {
|
|
385
|
+
roles: string;
|
|
386
|
+
} ? [keyof IdentitiesOf<Config> & string] extends [never] ? never : RouteAuthRule<keyof IdentitiesOf<Config> & string, IdentitiesOf<Config>> : AuthRule;
|
|
387
|
+
/**
|
|
388
|
+
* What a collection's `auth` may name: editor roles, document roles, or a rule for the `editor` identity or one of the
|
|
389
|
+
* app's own.
|
|
390
|
+
*/
|
|
391
|
+
type CollectionAuthOf<Config> = CollectionAuth<CmsRoleNamesOf<Config> | DocumentRoleNamesOf<Config>, EditorRuleOf<Config> | AppRuleOf<Config>>;
|
|
392
|
+
/**
|
|
393
|
+
* What a global's `auth` may name: editor roles, or a rule for the `editor` identity or one of the app's own.
|
|
394
|
+
*/
|
|
395
|
+
type GlobalAuthOf<Config> = GlobalAuth<CmsRoleNamesOf<Config>, EditorRuleOf<Config> | AppRuleOf<Config>>;
|
|
396
|
+
type IdentitiesOf<Config> = Config extends {
|
|
397
|
+
auth: {
|
|
398
|
+
identities: infer Identities extends object;
|
|
399
|
+
};
|
|
400
|
+
} ? [Identities] extends [never] ? {} : Identities : {};
|
|
401
|
+
/**
|
|
402
|
+
* The `editor` identity, with the roles `kizuna generate` wrote into `Config`, or any role before it runs.
|
|
403
|
+
*/
|
|
404
|
+
type EditorIdentityOf<Config> = CmsOf<Config> extends {
|
|
405
|
+
roles: infer Names extends string;
|
|
406
|
+
} ? Omit<EditorIdentity, 'roles'> & {
|
|
407
|
+
readonly roles: Roles<[EditorCatalogOf<Config>] extends [never] ? undefined : EditorCatalogOf<Config> extends infer Catalog extends PermissionCatalog ? Catalog : undefined, Names>;
|
|
408
|
+
} : EditorIdentity;
|
|
409
|
+
/**
|
|
410
|
+
* The app's `Config` with the CMS's `editor` identity added, so the app's own routes can say `auth: 'editor'`.
|
|
411
|
+
*/
|
|
412
|
+
type WithEditor<Config extends KizunaConfigShape> = Omit<Config, 'auth'> & {
|
|
413
|
+
auth: Omit<NonNullable<Config['auth']>, 'identities'> & {
|
|
414
|
+
identities: IdentitiesOf<Config> & {
|
|
415
|
+
editor: EditorIdentityOf<Config>;
|
|
416
|
+
};
|
|
417
|
+
};
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* Declares the collections, globals, file stores and routes of a CMS.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* import { Kizuna } from 'kizunacms';
|
|
424
|
+
* import type { Config } from './kizuna.types';
|
|
425
|
+
*
|
|
426
|
+
* export const k = new Kizuna<Config>();
|
|
427
|
+
*
|
|
428
|
+
* export const Articles = k.collection({
|
|
429
|
+
* name: 'articles',
|
|
430
|
+
* auth: {
|
|
431
|
+
* read: ['public'],
|
|
432
|
+
* create: ['editor'],
|
|
433
|
+
* update: ['editor'],
|
|
434
|
+
* delete: ['editor'],
|
|
435
|
+
* },
|
|
436
|
+
* fields: [
|
|
437
|
+
* {
|
|
438
|
+
* name: 'title',
|
|
439
|
+
* type: 'text',
|
|
440
|
+
* required: true,
|
|
441
|
+
* },
|
|
442
|
+
* ],
|
|
443
|
+
* });
|
|
444
|
+
*/
|
|
445
|
+
declare class Kizuna<Config extends CmsConfigShape = Record<string, never>> extends Kizuna$1<WithEditor<Config>> {
|
|
446
|
+
/**
|
|
447
|
+
* Declares a collection of documents that share the same fields.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* export const Articles = k.collection({
|
|
451
|
+
* name: 'articles',
|
|
452
|
+
* auth: {
|
|
453
|
+
* read: ['public'],
|
|
454
|
+
* create: ['editor'],
|
|
455
|
+
* update: ['editor'],
|
|
456
|
+
* delete: ['editor'],
|
|
457
|
+
* },
|
|
458
|
+
* fields: [
|
|
459
|
+
* {
|
|
460
|
+
* name: 'title',
|
|
461
|
+
* type: 'text',
|
|
462
|
+
* required: true,
|
|
463
|
+
* },
|
|
464
|
+
* {
|
|
465
|
+
* name: 'author',
|
|
466
|
+
* type: 'relationship',
|
|
467
|
+
* to: 'authors',
|
|
468
|
+
* },
|
|
469
|
+
* ],
|
|
470
|
+
* });
|
|
471
|
+
*/
|
|
472
|
+
collection<const Name extends string, const Fields extends readonly Field<CollectionNamesOf<Config>, StorageNamesOf<Config>>[]>(definition: CollectionDefinition<Name, Fields> & {
|
|
473
|
+
group?: GroupNamesOf<Config>;
|
|
474
|
+
auth: CollectionAuthOf<Config>;
|
|
475
|
+
titleField?: TextFieldNamesOf<NoInfer<Fields>>;
|
|
476
|
+
meta?: MetaOptionsOf<NoInfer<Fields>, Config>;
|
|
477
|
+
fields: NoInfer<WithCheckedSlugs<Fields>>;
|
|
478
|
+
}): DeclaredCollection<Name, WithStores<Fields, Config>>;
|
|
479
|
+
/**
|
|
480
|
+
* Declares a global: a single document with no list.
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* export const Settings = k.global({
|
|
484
|
+
* name: 'settings',
|
|
485
|
+
* auth: {
|
|
486
|
+
* read: ['public'],
|
|
487
|
+
* update: ['editor'],
|
|
488
|
+
* },
|
|
489
|
+
* label: 'Settings',
|
|
490
|
+
* fields: [
|
|
491
|
+
* {
|
|
492
|
+
* name: 'siteName',
|
|
493
|
+
* type: 'text',
|
|
494
|
+
* },
|
|
495
|
+
* ],
|
|
496
|
+
* });
|
|
497
|
+
*/
|
|
498
|
+
global<const Name extends string, const Fields extends readonly Field<CollectionNamesOf<Config>, StorageNamesOf<Config>>[]>(definition: GlobalDefinition<Name, Fields> & {
|
|
499
|
+
auth: GlobalAuthOf<Config>;
|
|
500
|
+
}): Global<Name, WithStores<Fields, Config>>;
|
|
501
|
+
/**
|
|
502
|
+
* Declares a store that image and file fields upload to.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* export const Images = k.storage({
|
|
506
|
+
* name: 'images',
|
|
507
|
+
* auth: {
|
|
508
|
+
* read: ['public'],
|
|
509
|
+
* create: ['editor'],
|
|
510
|
+
* update: ['editor'],
|
|
511
|
+
* delete: ['editor'],
|
|
512
|
+
* },
|
|
513
|
+
* adapter: s3Storage({
|
|
514
|
+
* bucket: 'example-images',
|
|
515
|
+
* }),
|
|
516
|
+
* });
|
|
517
|
+
*
|
|
518
|
+
* // an image field names it
|
|
519
|
+
* {
|
|
520
|
+
* name: 'cover',
|
|
521
|
+
* type: 'image',
|
|
522
|
+
* storage: 'images',
|
|
523
|
+
* }
|
|
524
|
+
*/
|
|
525
|
+
storage<const Name extends string, const Fields extends readonly Field<CollectionNamesOf<Config>>[] = readonly []>(definition: StorageDefinition<Name, Fields> & {
|
|
526
|
+
auth: CollectionAuthOf<Config>;
|
|
527
|
+
}): Storage<Name, Fields>;
|
|
528
|
+
}
|
|
529
|
+
//#endregion
|
|
530
|
+
//#region src/image-size.d.ts
|
|
531
|
+
/**
|
|
532
|
+
* An image's type and size, read from its first bytes.
|
|
533
|
+
*/
|
|
534
|
+
interface ImageSize {
|
|
535
|
+
contentType: 'image/png' | 'image/gif' | 'image/jpeg' | 'image/webp' | 'image/avif' | 'image/heic';
|
|
536
|
+
width: number;
|
|
537
|
+
height: number;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Returns an image's type, and its width and height as shown, or `undefined` when the bytes are not a PNG, GIF, JPEG,
|
|
541
|
+
* WebP, AVIF or HEIC image, or its header can't be read.
|
|
542
|
+
*/
|
|
543
|
+
declare const imageSizeOf: (bytes: Uint8Array) => ImageSize | undefined;
|
|
544
|
+
//#endregion
|
|
545
|
+
export { type BooleanField, type BuiltInField, type CmsConfigShape, type CmsDefinition, type CmsNames, type CmsOptions, type Collection, type CollectionAuth, type CollectionDefinition, type CollectionNamesOf, type ContentOf, type DatabaseAdapter, type DateField, type DateTimeField, type DeclaredCollection, type DocumentMeta, type DocumentOf, type DocumentPage, type DocumentRole, type Editor, type EditorsApi, type EmailField, type Field, type FieldAffixes, type FieldBase, type FieldColumn, type FieldValue, GLOBALS_COLLECTION, type Global, type GlobalAuth, type GlobalDefinition, type GlobalOf, type ImageSize, Kizuna, type Labels, type ListOptions, type LoginOptions, type MetaOptions, type MetaTitleOptions, type NewEditor, type NumberField, type OperatorsFor, type PasswordReset, type RelationshipField, type RolesOption, type SelectField, type SelectOption, type SessionRecord, type SlugField, type SlugOptions, SlugSchema, type SortOf, type Storage, type StorageAdapter, type StorageDefinition, type StoredDocument, type TextField, type UrlField, type Where, type WhereOf, type WithEditor, columnOf, defineConfig, diskStorage, documentSchemaOf, hashPassword, imageSizeOf, labelsOf, memoryAdapter, memoryStorage, schemaOf, verifyPassword };
|