@dyrected/core 2.5.14 → 2.5.17

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.
Files changed (52) hide show
  1. package/dist/app-B2tg7Djj.d.cts +1575 -0
  2. package/dist/app-B2tg7Djj.d.ts +1575 -0
  3. package/dist/app-BElen1tP.d.cts +1690 -0
  4. package/dist/app-BElen1tP.d.ts +1690 -0
  5. package/dist/app-Bh4_Opv0.d.cts +1522 -0
  6. package/dist/app-Bh4_Opv0.d.ts +1522 -0
  7. package/dist/app-Bv9gaDAN.d.cts +561 -0
  8. package/dist/app-Bv9gaDAN.d.ts +561 -0
  9. package/dist/app-BvG3bRc8.d.cts +419 -0
  10. package/dist/app-BvG3bRc8.d.ts +419 -0
  11. package/dist/app-C3B9N1KR.d.cts +1522 -0
  12. package/dist/app-C3B9N1KR.d.ts +1522 -0
  13. package/dist/app-DDJJa0ep.d.cts +1621 -0
  14. package/dist/app-DDJJa0ep.d.ts +1621 -0
  15. package/dist/app-DO1s9YW1.d.cts +1621 -0
  16. package/dist/app-DO1s9YW1.d.ts +1621 -0
  17. package/dist/app-DTP3-9PJ.d.cts +561 -0
  18. package/dist/app-DTP3-9PJ.d.ts +561 -0
  19. package/dist/app-DbKDGYTI.d.cts +566 -0
  20. package/dist/app-DbKDGYTI.d.ts +566 -0
  21. package/dist/app-DqRO-CMi.d.cts +1457 -0
  22. package/dist/app-DqRO-CMi.d.ts +1457 -0
  23. package/dist/app-DvaFpOtj.d.cts +398 -0
  24. package/dist/app-DvaFpOtj.d.ts +398 -0
  25. package/dist/app-FGzip4XM.d.cts +1563 -0
  26. package/dist/app-FGzip4XM.d.ts +1563 -0
  27. package/dist/app-T0alZAE0.d.cts +383 -0
  28. package/dist/app-T0alZAE0.d.ts +383 -0
  29. package/dist/app-oQt5-9MU.d.cts +1560 -0
  30. package/dist/app-oQt5-9MU.d.ts +1560 -0
  31. package/dist/app-rZj1VFer.d.cts +1621 -0
  32. package/dist/app-rZj1VFer.d.ts +1621 -0
  33. package/dist/app-wo82JRHl.d.cts +445 -0
  34. package/dist/app-wo82JRHl.d.ts +445 -0
  35. package/dist/chunk-23URSKPI.js +2371 -0
  36. package/dist/chunk-2JMA3M5S.js +2475 -0
  37. package/dist/chunk-3FZEUK36.js +2470 -0
  38. package/dist/chunk-DOJHZ7XN.js +2394 -0
  39. package/dist/chunk-EXXOPW3I.js +2483 -0
  40. package/dist/chunk-PKNFV7KE.js +2469 -0
  41. package/dist/chunk-UBTRANFX.js +2476 -0
  42. package/dist/chunk-W6KURRMW.js +2471 -0
  43. package/dist/chunk-YNJ3YC4N.js +2483 -0
  44. package/dist/index.cjs +465 -48
  45. package/dist/index.d.cts +124 -8
  46. package/dist/index.d.ts +124 -8
  47. package/dist/index.js +9 -3
  48. package/dist/server.cjs +457 -46
  49. package/dist/server.d.cts +57 -15
  50. package/dist/server.d.ts +57 -15
  51. package/dist/server.js +1 -1
  52. package/package.json +1 -1
@@ -0,0 +1,1690 @@
1
+ import * as hono_types from 'hono/types';
2
+ import { Hono } from 'hono';
3
+
4
+ /**
5
+ * Minimum HTTP request context passed to every server-side hook and resolver.
6
+ *
7
+ * The full Web Standard `Request` is available as `raw` when you need it, but
8
+ * most hooks only need `query` (URL search parameters).
9
+ */
10
+ interface HookRequestContext {
11
+ /** Parsed URL query-string parameters, e.g. `{ page: '2', search: 'hello' }`. */
12
+ query: Record<string, string>;
13
+ /** Incoming HTTP headers, lowercased. */
14
+ headers: Record<string, string>;
15
+ /** The raw Web Standard `Request` object. Useful for streaming or advanced header inspection. */
16
+ raw?: Request;
17
+ }
18
+ /**
19
+ * Base shape of an authenticated user as decoded from the JWT.
20
+ *
21
+ * The actual shape will include every field on your auth collection — this
22
+ * interface only guarantees the properties that Dyrected always stamps on the
23
+ * token. Extend it in your own codebase for stronger typing:
24
+ *
25
+ * @example
26
+ * declare module '@dyrected/core' {
27
+ * interface AuthenticatedUser {
28
+ * role: 'admin' | 'editor'
29
+ * organizationId: string
30
+ * }
31
+ * }
32
+ */
33
+ interface AuthenticatedUser {
34
+ /** The user's document ID in the database. */
35
+ sub: string;
36
+ /** The user's email address. */
37
+ email?: string;
38
+ /** Slug of the collection this user was authenticated against. */
39
+ collection: string;
40
+ /** Array of role strings, if your auth collection has a `roles` field. */
41
+ roles?: string[];
42
+ /** Any additional fields from the auth collection document. */
43
+ [key: string]: unknown;
44
+ }
45
+ /**
46
+ * Every field type supported by Dyrected.
47
+ *
48
+ * - Text group: `text`, `textarea`, `richText`, `email`, `url`, `icon`
49
+ * - Number/Bool: `number`, `boolean`
50
+ * - Date: `date`
51
+ * - Selection: `select`, `multiSelect`, `radio`
52
+ * - Relationship: `relationship`, `join`
53
+ * - Structural: `array`, `object`, `blocks`, `json`
54
+ * - Layout: `row`
55
+ * - Media: `image`
56
+ */
57
+ type FieldType = "text" | "textarea" | "richText" | "number" | "boolean" | "date" | "datetime" | "select" | "multiSelect" | "radio" | "relationship" | "array" | "object" | "json" | "blocks" | "image" | "email" | "url" | "icon" | "join" | "row";
58
+ /**
59
+ * Arguments passed to a server-side dynamic options resolver.
60
+ *
61
+ * All properties are optional so simple resolvers that fetch from an external
62
+ * API without needing any context (`async () => fetch(...)`) still compile
63
+ * without errors.
64
+ */
65
+ interface DynamicOptionsResolverArgs {
66
+ /**
67
+ * The configured database adapter. Use it to query any collection.
68
+ *
69
+ * @example
70
+ * options: async ({ db }) => {
71
+ * const result = await db.find({ collection: 'categories' })
72
+ * return result.docs.map(c => ({ label: c.name, value: c.id }))
73
+ * }
74
+ */
75
+ db?: DatabaseAdapter;
76
+ /**
77
+ * The authenticated user making the request, or `undefined` for
78
+ * unauthenticated requests. Use it to filter options per user.
79
+ *
80
+ * @example
81
+ * options: async ({ user, db }) => {
82
+ * if (!user) return []
83
+ * const teams = await db.find({ collection: 'teams', where: { owner: { equals: user.sub } } })
84
+ * return teams.docs.map(t => ({ label: t.name, value: t.id }))
85
+ * }
86
+ */
87
+ user?: AuthenticatedUser;
88
+ /**
89
+ * HTTP request context. Sibling field values selected in the Admin UI are
90
+ * forwarded as query parameters and accessible via `req.query`.
91
+ *
92
+ * @example
93
+ * // Cascading dropdown: the Admin UI appends ?country=ca
94
+ * options: async ({ req }) => {
95
+ * const country = req.query.country ?? 'us'
96
+ * const regions = await fetch(`/api/regions?country=${country}`)
97
+ * return regions.json()
98
+ * }
99
+ */
100
+ req: HookRequestContext;
101
+ }
102
+ /** A function that returns option items for a `select`, `multiSelect`, or `radio` field. */
103
+ type DynamicOptionsResolver = (args: DynamicOptionsResolverArgs) => Promise<DynamicOptionItem[]> | DynamicOptionItem[];
104
+ /**
105
+ * Config-object form for a dynamic options resolver. Use this when you also
106
+ * want server-side caching via `cacheTTL`.
107
+ *
108
+ * @example
109
+ * options: {
110
+ * resolve: async () => fetchCountriesFromApi(),
111
+ * cacheTTL: 300, // cache for 5 minutes
112
+ * }
113
+ */
114
+ interface DynamicOptionsConfig {
115
+ /** The resolver function. Receives the same args as a bare function resolver. */
116
+ resolve: DynamicOptionsResolver;
117
+ /**
118
+ * Time-to-live in **seconds** for caching the resolver result on the server.
119
+ *
120
+ * Useful for resolvers that call rate-limited external APIs. When set, the
121
+ * result is reused for all identical requests within the TTL window.
122
+ *
123
+ * Not applied when the resolver uses query parameters (`req.query`), since
124
+ * parameterised results are request-specific.
125
+ */
126
+ cacheTTL?: number;
127
+ }
128
+ /** A single option item — either a plain string or a label/value pair. */
129
+ type DynamicOptionItem = string | {
130
+ label: string;
131
+ value: unknown;
132
+ };
133
+ /**
134
+ * A single block type for use inside a `blocks` field.
135
+ *
136
+ * Each block has its own field schema. At runtime, every block item in the
137
+ * array carries a `blockType` property that matches the block's `slug`.
138
+ *
139
+ * @example
140
+ * const HeroBlock: Block = {
141
+ * slug: 'hero',
142
+ * labels: { singular: 'Hero', plural: 'Heroes' },
143
+ * fields: [
144
+ * { name: 'heading', type: 'text', required: true },
145
+ * { name: 'image', type: 'relationship', relationTo: 'media' },
146
+ * ],
147
+ * }
148
+ */
149
+ interface Block {
150
+ /** Unique identifier for this block type. Stored as `blockType` on each item. */
151
+ slug: string;
152
+ /** Human-readable labels shown in the Admin UI block picker. */
153
+ labels?: {
154
+ singular: string;
155
+ plural: string;
156
+ };
157
+ /** Fields that make up this block's data shape. */
158
+ fields: Field[];
159
+ }
160
+ /**
161
+ * A hook that runs **before a field value is saved** to the database.
162
+ *
163
+ * Return the transformed value to persist. Return `undefined` to leave the
164
+ * value unchanged (same as returning the original `value`).
165
+ *
166
+ * Field `beforeChange` hooks run recursively inside `array`, `object`, and
167
+ * `blocks` fields — every nested item is processed automatically.
168
+ *
169
+ * @template TValue The TypeScript type of this field's value.
170
+ * @template TDoc The document shape of the parent collection/global.
171
+ *
172
+ * @example
173
+ * // Normalise email to lowercase
174
+ * const normaliseEmail: FieldBeforeChangeHook<string> = ({ value }) =>
175
+ * value?.toLowerCase().trim()
176
+ *
177
+ * @example
178
+ * // Hash a password with bcrypt
179
+ * const hashPassword: FieldBeforeChangeHook<string> = async ({ value }) =>
180
+ * value ? bcrypt.hash(value, 10) : value
181
+ */
182
+ type FieldBeforeChangeHook<TValue = unknown, TDoc extends object = Record<string, unknown>> = (args: {
183
+ /** The current value of this field (after any previous hooks in the chain). */
184
+ value: TValue;
185
+ /** The full document as it existed before this update. `undefined` on create. */
186
+ originalDoc?: TDoc;
187
+ /** The full incoming data payload being written. */
188
+ data: Partial<TDoc>;
189
+ /** The authenticated user, or `undefined` for unauthenticated requests. */
190
+ user?: AuthenticatedUser;
191
+ }) => TValue | undefined | Promise<TValue | undefined>;
192
+ /**
193
+ * A hook that runs **after a field value is read** from the database, before
194
+ * the response is sent to the client.
195
+ *
196
+ * Return the transformed value to return to the client. Use this for masking,
197
+ * formatting, or adding computed properties.
198
+ *
199
+ * @template TValue The TypeScript type of this field's value.
200
+ * @template TDoc The document shape of the parent collection/global.
201
+ *
202
+ * @example
203
+ * // Mask sensitive value for non-admins
204
+ * const maskForPublic: FieldAfterReadHook<string> = ({ value, user }) =>
205
+ * user?.role === 'admin' ? value : '••••••••'
206
+ */
207
+ type FieldAfterReadHook<TValue = unknown, TDoc extends object = Record<string, unknown>> = (args: {
208
+ /** The raw field value as stored in the database. */
209
+ value: TValue;
210
+ /** The full document being returned (with defaults applied). */
211
+ doc: TDoc;
212
+ /** The authenticated user, or `undefined` for unauthenticated requests. */
213
+ user?: AuthenticatedUser;
214
+ }) => TValue | undefined | Promise<TValue | undefined>;
215
+ /**
216
+ * @deprecated Use {@link FieldBeforeChangeHook} or {@link FieldAfterReadHook} instead.
217
+ * This alias remains for backwards compatibility.
218
+ */
219
+ type FieldHook<TDoc extends object = Record<string, unknown>, TValue = unknown> = FieldBeforeChangeHook<TValue, TDoc>;
220
+ /**
221
+ * Runs before Dyrected queries the database for a list or single-document fetch.
222
+ *
223
+ * Return a new `where` query object to override or extend the current filter.
224
+ * Return `undefined` (or nothing) to leave the query unchanged.
225
+ *
226
+ * @example
227
+ * // Scope all reads to the current user's own documents
228
+ * const scopeToUser: CollectionBeforeReadHook = ({ user, query }) => ({
229
+ * ...query,
230
+ * owner: { equals: user?.sub },
231
+ * })
232
+ */
233
+ type CollectionBeforeReadHook = (args: {
234
+ /** The HTTP request context. */
235
+ req: HookRequestContext;
236
+ /** The current `where` query filter. Modify and return to override. */
237
+ query?: Record<string, unknown>;
238
+ /** The authenticated user, or `undefined` for unauthenticated requests. */
239
+ user?: AuthenticatedUser;
240
+ }) => Record<string, unknown> | void | Promise<Record<string, unknown> | void>;
241
+ /**
242
+ * Runs after a document (or list of documents) is fetched from the database,
243
+ * before the response is sent to the client.
244
+ *
245
+ * Return a modified document to send instead. Useful for adding computed
246
+ * virtual fields or transforming the shape of the response.
247
+ *
248
+ * @template TDoc The shape of the collection's document.
249
+ *
250
+ * @example
251
+ * // Add a computed fullName field
252
+ * const addFullName: CollectionAfterReadHook<User> = ({ doc }) => ({
253
+ * ...doc,
254
+ * fullName: `${doc.firstName} ${doc.lastName}`.trim(),
255
+ * })
256
+ */
257
+ type CollectionAfterReadHook<TDoc extends object = Record<string, unknown>> = (args: {
258
+ /** The document as fetched from the database (with defaults applied). */
259
+ doc: TDoc;
260
+ /** The HTTP request context. */
261
+ req: HookRequestContext;
262
+ /** The authenticated user, or `undefined` for unauthenticated requests. */
263
+ user?: AuthenticatedUser;
264
+ }) => TDoc | Promise<TDoc>;
265
+ /**
266
+ * Runs **before** a document is created or updated in the database.
267
+ *
268
+ * Return a modified data object to write instead of the original. This is the
269
+ * right place for data transformation, normalisation, slug generation, and
270
+ * validation (throw to abort the write).
271
+ *
272
+ * @template TDoc The shape of the collection's document.
273
+ *
274
+ * @example
275
+ * // Auto-generate a slug on create
276
+ * const generateSlug: CollectionBeforeChangeHook<Post> = ({ data, operation }) => {
277
+ * if (operation === 'create' || data.title !== undefined) {
278
+ * return { ...data, slug: slugify(data.title ?? '') }
279
+ * }
280
+ * return data
281
+ * }
282
+ *
283
+ * @example
284
+ * // Abort the write with a validation error
285
+ * const validateStock: CollectionBeforeChangeHook<Product> = ({ data }) => {
286
+ * if ((data.stock ?? 0) < 0) throw new Error('Stock cannot be negative.')
287
+ * return data
288
+ * }
289
+ */
290
+ type CollectionBeforeChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
291
+ /** The incoming data payload being written. */
292
+ data: Partial<TDoc>;
293
+ /**
294
+ * The existing document before this update. Only present on `'update'`
295
+ * operations; `undefined` on `'create'`.
296
+ */
297
+ doc?: TDoc;
298
+ /** The HTTP request context. */
299
+ req: HookRequestContext;
300
+ /** The authenticated user, or `undefined` for unauthenticated requests. */
301
+ user?: AuthenticatedUser;
302
+ /** Whether this is a new document or an update to an existing one. */
303
+ operation: "create" | "update";
304
+ }) => Partial<TDoc> | void | Promise<Partial<TDoc> | void>;
305
+ /**
306
+ * Runs **after** a document is created or updated in the database.
307
+ *
308
+ * **Isolation**: errors thrown inside this hook are caught by the framework,
309
+ * logged to the console, and then discarded. The HTTP response returns the
310
+ * saved document as if nothing went wrong — because from the database's
311
+ * perspective, nothing did. This means a transient email failure or webhook
312
+ * timeout will never turn a successful write into a 500 for the caller.
313
+ *
314
+ * The return value is ignored — this hook is for side-effects only (emails,
315
+ * webhooks, cache revalidation, search index updates, etc.).
316
+ *
317
+ * **Awaiting vs fire-and-forget**: `await`ing inside this hook is fine for
318
+ * fast, reliable calls. For slow or unreliable external services prefer
319
+ * fire-and-forget with your own `.catch()` so the response doesn't block:
320
+ *
321
+ * ```ts
322
+ * // ✓ fast & reliable — safe to await
323
+ * afterChange: [async ({ doc }) => {
324
+ * await revalidatePath(`/posts/${doc.slug}`)
325
+ * }]
326
+ *
327
+ * // ✓ slow or unreliable — fire-and-forget
328
+ * afterChange: [({ doc }) => {
329
+ * sendEmail({ to: doc.email, ... }).catch(console.error)
330
+ * }]
331
+ * ```
332
+ *
333
+ * @template TDoc The shape of the collection's document.
334
+ *
335
+ * @example
336
+ * // Send a webhook after every save
337
+ * const sendWebhook: CollectionAfterChangeHook<Post> = async ({ doc, operation }) => {
338
+ * await fetch('https://hooks.example.com/content', {
339
+ * method: 'POST',
340
+ * body: JSON.stringify({ event: operation, doc }),
341
+ * })
342
+ * }
343
+ *
344
+ * @example
345
+ * // Only act when a specific field changed
346
+ * const onStatusChange: CollectionAfterChangeHook<Post> = async ({ doc, previousDoc, operation }) => {
347
+ * if (operation === 'update' && doc.status !== previousDoc?.status) {
348
+ * await notifySubscribers(doc)
349
+ * }
350
+ * }
351
+ */
352
+ type CollectionAfterChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
353
+ /** The document as it was written to the database. */
354
+ doc: TDoc;
355
+ /**
356
+ * Snapshot of the document before the write. Only present on `'update'`
357
+ * operations; `undefined` on `'create'`.
358
+ */
359
+ previousDoc?: TDoc;
360
+ /** The HTTP request context. */
361
+ req: HookRequestContext;
362
+ /** The authenticated user, or `undefined` for unauthenticated requests. */
363
+ user?: AuthenticatedUser;
364
+ /** Whether this was a new document or an update. */
365
+ operation: "create" | "update";
366
+ }) => void | Promise<void>;
367
+ /**
368
+ * Runs **before** a document is deleted from the database.
369
+ *
370
+ * Throw an error to cancel the deletion — the document will not be removed
371
+ * and the API will return a `500` with your error message.
372
+ *
373
+ * @template TDoc The shape of the collection's document.
374
+ *
375
+ * @example
376
+ * // Prevent deletion when other documents reference this one
377
+ * const guardReferences: CollectionBeforeDeleteHook<Category> = async ({ id, doc }) => {
378
+ * const refs = await db.find({ collection: 'posts', where: { category: { equals: id } } })
379
+ * if (refs.total > 0) throw new Error(`${refs.total} post(s) still reference this category.`)
380
+ * }
381
+ */
382
+ type CollectionBeforeDeleteHook<TDoc extends object = Record<string, unknown>> = (args: {
383
+ /** The ID of the document about to be deleted. */
384
+ id: string;
385
+ /** The full document about to be deleted. */
386
+ doc: TDoc;
387
+ /** The HTTP request context. */
388
+ req: HookRequestContext;
389
+ /** The authenticated user, or `undefined` for unauthenticated requests. */
390
+ user?: AuthenticatedUser;
391
+ }) => void | Promise<void>;
392
+ /**
393
+ * Runs **after** a document has been deleted from the database.
394
+ *
395
+ * **Isolation**: same as {@link CollectionAfterChangeHook} — errors are caught,
396
+ * logged, and discarded. The deletion is already committed; a hook failure will
397
+ * never cause the deleted ID to appear in the `failed` list of a bulk delete or
398
+ * turn a successful single delete into a 500.
399
+ *
400
+ * Use for cleanup side-effects — removing related media, invalidating caches,
401
+ * notifying downstream services, etc.
402
+ *
403
+ * @template TDoc The shape of the collection's document.
404
+ */
405
+ type CollectionAfterDeleteHook<TDoc extends object = Record<string, unknown>> = (args: {
406
+ /** The ID of the deleted document. */
407
+ id: string;
408
+ /** The document as it was just before deletion. */
409
+ doc: TDoc;
410
+ /** The HTTP request context. */
411
+ req: HookRequestContext;
412
+ /** The authenticated user, or `undefined` for unauthenticated requests. */
413
+ user?: AuthenticatedUser;
414
+ }) => void | Promise<void>;
415
+ /** @see {@link CollectionBeforeReadHook} */
416
+ type GlobalBeforeReadHook = CollectionBeforeReadHook;
417
+ /**
418
+ * Runs after the global document is fetched, before the response is sent.
419
+ * @see {@link CollectionAfterReadHook}
420
+ */
421
+ type GlobalAfterReadHook<TDoc extends object = Record<string, unknown>> = (args: {
422
+ doc: TDoc;
423
+ req: HookRequestContext;
424
+ user?: AuthenticatedUser;
425
+ }) => TDoc | Promise<TDoc>;
426
+ /**
427
+ * Runs before the global document is updated.
428
+ * Operation is always `'update'` (globals cannot be created or deleted).
429
+ * @see {@link CollectionBeforeChangeHook}
430
+ */
431
+ type GlobalBeforeChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
432
+ data: Partial<TDoc>;
433
+ doc?: TDoc;
434
+ req: HookRequestContext;
435
+ user?: AuthenticatedUser;
436
+ operation: "update";
437
+ }) => Partial<TDoc> | void | Promise<Partial<TDoc> | void>;
438
+ /**
439
+ * Runs after the global document is updated. Side-effects only.
440
+ *
441
+ * **Isolation**: errors are caught, logged, and discarded — same behaviour as
442
+ * {@link CollectionAfterChangeHook}. The update is already committed.
443
+ *
444
+ * @see {@link CollectionAfterChangeHook}
445
+ */
446
+ type GlobalAfterChangeHook<TDoc extends object = Record<string, unknown>> = (args: {
447
+ doc: TDoc;
448
+ previousDoc?: TDoc;
449
+ req: HookRequestContext;
450
+ user?: AuthenticatedUser;
451
+ operation: "update";
452
+ }) => void | Promise<void>;
453
+ /**
454
+ * @deprecated Use the specific hook types instead:
455
+ * {@link CollectionBeforeChangeHook}, {@link CollectionAfterReadHook}, etc.
456
+ *
457
+ * This broad type remains for backwards compatibility with the internal hook runner.
458
+ */
459
+ type HookFunction<TDoc extends object = Record<string, unknown>> = (args: {
460
+ data?: Partial<TDoc>;
461
+ doc?: TDoc;
462
+ user?: AuthenticatedUser;
463
+ req?: HookRequestContext;
464
+ operation?: "create" | "update" | "delete";
465
+ [key: string]: unknown;
466
+ }) => unknown | Promise<unknown>;
467
+ /**
468
+ * A function that determines whether the current user can perform an operation.
469
+ *
470
+ * Return `true` to allow, `false` to deny.
471
+ * Return a `where`-style object to allow access only to matching documents
472
+ * (useful for multi-tenant setups where users can only see their own data).
473
+ *
474
+ * Can also be expressed as a Jexl expression **string** for simple role checks
475
+ * that need to be serialised (e.g. stored in the database or sent to the Admin UI).
476
+ *
477
+ * @template TDoc The shape of the collection's document.
478
+ *
479
+ * @example
480
+ * // Simple role check
481
+ * access: {
482
+ * delete: ({ user }) => user?.roles?.includes('admin') ?? false,
483
+ * }
484
+ *
485
+ * @example
486
+ * // Row-level: users can only read their own documents
487
+ * access: {
488
+ * read: ({ user }) => ({ owner: { equals: user?.sub } }),
489
+ * }
490
+ *
491
+ * @example
492
+ * // Jexl string — evaluated server-side
493
+ * access: {
494
+ * update: "user.roles contains 'editor'",
495
+ * }
496
+ */
497
+ type AccessFunction<TDoc extends object = Record<string, unknown>> = (args: {
498
+ user: AuthenticatedUser | undefined;
499
+ doc?: TDoc;
500
+ data?: Partial<TDoc>;
501
+ req: HookRequestContext;
502
+ }) => boolean | Record<string, unknown> | Promise<boolean | Record<string, unknown>>;
503
+ /**
504
+ * Shared base properties present on every field type.
505
+ * The exported `Field` union type extends this with a typed `hooks` block.
506
+ */
507
+ interface FieldBase {
508
+ /**
509
+ * The database column / JSON key for this field.
510
+ * Use camelCase. Omit for layout-only fields (`row`, `join`).
511
+ */
512
+ name?: string;
513
+ /**
514
+ * Human-readable label shown next to the field in the Admin UI.
515
+ * Defaults to a title-cased version of `name` if omitted.
516
+ */
517
+ label?: string;
518
+ /**
519
+ * If `true`, the field must have a non-empty value.
520
+ * Enforced on both client (Admin UI) and server (API).
521
+ */
522
+ required?: boolean;
523
+ /**
524
+ * If `true`, the database adapter enforces a unique constraint for this
525
+ * field across the collection.
526
+ */
527
+ unique?: boolean;
528
+ /**
529
+ * The initial value written to new documents when no value is provided.
530
+ * The type should match the field type.
531
+ */
532
+ defaultValue?: unknown;
533
+ /**
534
+ * Available choices for `select`, `multiSelect`, and `radio` fields.
535
+ *
536
+ * Three forms are accepted:
537
+ *
538
+ * **1. Static array** — fixed list known at build time:
539
+ * ```ts
540
+ * options: [{ label: 'Draft', value: 'draft' }, { label: 'Published', value: 'published' }]
541
+ * ```
542
+ *
543
+ * **2. Server-side resolver** — runs on the server (never in the browser).
544
+ * Use for DB queries, secret API keys, or user-filtered lists.
545
+ * The Admin UI fetches results from `GET /api/dyrected/options/:slug/:field`.
546
+ * ```ts
547
+ * options: async ({ db, user }) => {
548
+ * const cats = await db.find({ collection: 'categories' })
549
+ * return cats.docs.map(c => ({ label: c.name, value: c.id }))
550
+ * }
551
+ * ```
552
+ *
553
+ * **3. With caching** (`{ resolve, cacheTTL }`) — same as above but the
554
+ * result is cached on the server for `cacheTTL` seconds:
555
+ * ```ts
556
+ * options: { resolve: async () => fetchFromSlowApi(), cacheTTL: 300 }
557
+ * ```
558
+ *
559
+ * For **instant client-side cascading dropdowns** driven by another field's
560
+ * value, use `admin.hooks.options` instead (no network round-trip).
561
+ */
562
+ options?: string[] | {
563
+ label: string;
564
+ value: unknown;
565
+ }[] | DynamicOptionsResolver | DynamicOptionsConfig;
566
+ /** For `relationship` fields — the slug of the collection to link to. */
567
+ relationTo?: string;
568
+ /**
569
+ * For `relationship` and `image` fields — if `true`, stores an array of
570
+ * IDs instead of a single ID.
571
+ */
572
+ hasMany?: boolean;
573
+ /** Sub-fields for `array` and `object` field types. */
574
+ fields?: Field[];
575
+ /** Block type definitions for `blocks` fields. */
576
+ blocks?: Block[];
577
+ /**
578
+ * For `join` fields — the slug of the target collection to show linked
579
+ * documents from. Paired with `on`.
580
+ */
581
+ collection?: string;
582
+ /**
583
+ * For `join` fields — the name of the `relationship` field on the target
584
+ * collection that points back to this collection.
585
+ */
586
+ on?: string;
587
+ /**
588
+ * Field-level read/update access control.
589
+ *
590
+ * - `read`: if it returns `false`, the field is stripped from API responses.
591
+ * - `update`: if it returns `false`, incoming values for this field are silently ignored.
592
+ */
593
+ access?: {
594
+ read?: AccessFunction | string;
595
+ update?: AccessFunction | string;
596
+ };
597
+ /**
598
+ * Admin UI options for this field. None of these properties affect the API
599
+ * or the database — they are purely presentational.
600
+ */
601
+ admin?: {
602
+ /** Placeholder text shown when the input is empty. */
603
+ placeholder?: string;
604
+ /** Help text rendered below the field in the Admin UI. */
605
+ description?: string;
606
+ /**
607
+ * If `true`, the field is hidden from the Admin form entirely.
608
+ * Its value is preserved in the database and still returned by the API.
609
+ */
610
+ hidden?: boolean;
611
+ /**
612
+ * If `true`, the field is rendered as non-editable in the Admin UI.
613
+ * The value is still included in form submissions.
614
+ */
615
+ readOnly?: boolean;
616
+ /**
617
+ * A function (or Jexl expression string) evaluated reactively as the
618
+ * editor types. Return `true` to show the field, `false` to hide it.
619
+ *
620
+ * Receives the current form values as `data` and sibling-level values
621
+ * as `siblingData`.
622
+ *
623
+ * @example
624
+ * // Only show the discount field when a coupon code is entered
625
+ * condition: (data) => !!data.couponCode
626
+ */
627
+ condition?: ((data: Record<string, unknown>, siblingData: Record<string, unknown>) => boolean) | string;
628
+ /**
629
+ * For `select` fields — render as radio buttons instead of a dropdown.
630
+ * Recommended for 2–5 options.
631
+ */
632
+ layout?: "radio" | "select" | string;
633
+ /**
634
+ * For `select` fields with `layout: 'radio'` — orientation of the radio buttons.
635
+ * @default 'vertical'
636
+ */
637
+ direction?: "horizontal" | "vertical";
638
+ /**
639
+ * Assigns this field to a named tab in the Admin form.
640
+ * When any field in the collection has a `tab`, the form switches to a
641
+ * tabbed layout. Fields without a `tab` are grouped under "General".
642
+ */
643
+ tab?: string;
644
+ /**
645
+ * CSS width of this field when it is a child of a `row` field.
646
+ * Accepts any CSS length value, e.g. `'50%'`, `'200px'`, `'1fr'`.
647
+ */
648
+ width?: string;
649
+ /**
650
+ * Client-side Admin UI hooks for this field.
651
+ *
652
+ * These run **in the browser** every time any sibling field value changes.
653
+ * They are completely separate from the server-side `hooks` property.
654
+ *
655
+ * `onChange` is typed per-field via the discriminated `Field` union —
656
+ * see `FieldAdminHooks<TValue>` below.
657
+ */
658
+ hooks?: {
659
+ /**
660
+ * For `select`, `multiSelect`, and `radio` fields only.
661
+ *
662
+ * Computes the **available choices** for this field based on other
663
+ * field values — instant, zero-latency cascading dropdowns.
664
+ *
665
+ * Runs in the browser every time any sibling field changes. When the
666
+ * returned list changes, the field's current value is automatically
667
+ * cleared if it is no longer a valid choice.
668
+ *
669
+ * Use the top-level `options` resolver (server-side) when:
670
+ * - Your option list requires a DB query or a secret API key
671
+ * - You want server-side caching (`cacheTTL`)
672
+ *
673
+ * @example
674
+ * // Country → State/Province cascading dropdown
675
+ * options: ({ siblingData }) => {
676
+ * if (siblingData.country === 'us') {
677
+ * return [{ label: 'California', value: 'CA' }, { label: 'New York', value: 'NY' }]
678
+ * }
679
+ * return []
680
+ * }
681
+ */
682
+ options?: (args: {
683
+ /** Current values of all fields at the same nesting level. */
684
+ siblingData: Record<string, unknown>;
685
+ /** Current values of the entire form. */
686
+ data: Record<string, unknown>;
687
+ }) => Array<string | {
688
+ label: string;
689
+ value: unknown;
690
+ }> | Promise<Array<string | {
691
+ label: string;
692
+ value: unknown;
693
+ }>>;
694
+ };
695
+ };
696
+ /**
697
+ * For database migrations: if set, data stored under this key in the database
698
+ * will be migrated to the current field `name` on next schema sync.
699
+ */
700
+ renameTo?: string;
701
+ /**
702
+ * For SQL adapters: if `true`, this field is extracted to a real column
703
+ * instead of being stored inside a JSON blob. Improves query performance
704
+ * for frequently-filtered fields.
705
+ */
706
+ promoted?: boolean;
707
+ }
708
+ /**
709
+ * Typed hooks block for a field whose stored value is `TValue`.
710
+ *
711
+ * The return type of the callbacks is kept as `unknown` here so that TypeScript
712
+ * can narrow the contextual type from the discriminated `Field` union without
713
+ * bidirectional inference conflicts. Use the explicit `FieldBeforeChangeHook<T>`
714
+ * and `FieldAfterReadHook<T>` types when you need checked return types.
715
+ */
716
+ type FieldHooks<TValue> = {
717
+ /**
718
+ * Field-level lifecycle hooks.
719
+ *
720
+ * - `beforeChange` — transform or validate the value before it is saved.
721
+ * `value` is typed to the field's own value type (e.g. `string` for
722
+ * `text`, `number` for `number`, `boolean` for `boolean`).
723
+ * - `afterRead` — transform the value after it is read, before the API response.
724
+ *
725
+ * Both hook types run **recursively** inside `array`, `object`, and `blocks` fields.
726
+ *
727
+ * @example
728
+ * hooks: {
729
+ * beforeChange: [({ value }) => value.trim()], // value: string ✓
730
+ * afterRead: [({ value, user }) => user?.role === 'admin' ? value : '****'],
731
+ * }
732
+ */
733
+ hooks?: {
734
+ beforeChange?: Array<(args: {
735
+ value: TValue;
736
+ originalDoc?: Record<string, unknown>;
737
+ data: Record<string, unknown>;
738
+ user?: AuthenticatedUser;
739
+ }) => unknown>;
740
+ afterRead?: Array<(args: {
741
+ value: TValue;
742
+ doc: Record<string, unknown>;
743
+ user?: AuthenticatedUser;
744
+ }) => unknown>;
745
+ };
746
+ };
747
+ /**
748
+ * Typed client-side admin hook block for a field whose value type is `TValue`.
749
+ *
750
+ * Intersected into each discriminated `Field` union member so that
751
+ * `admin.hooks.onChange` receives a `value` typed to the field's own type.
752
+ * The return type is `unknown` for the same reason as `FieldHooks` — to
753
+ * prevent bidirectional inference from conflicting with union discrimination.
754
+ */
755
+ type FieldAdminHooks<TValue> = {
756
+ admin?: {
757
+ hooks?: {
758
+ /**
759
+ * Derives or computes this field's **value** from other field values in
760
+ * real time — without any network request.
761
+ *
762
+ * Return a new value to update this field. Return `undefined` to leave
763
+ * it unchanged.
764
+ *
765
+ * Use `setValue` for imperative updates inside async callbacks.
766
+ *
767
+ * ⚠️ Never return an options array here — use `admin.hooks.options` for that.
768
+ *
769
+ * @example
770
+ * // Auto-generate a URL slug from the title field
771
+ * onChange: ({ value, siblingData }) => {
772
+ * const base = (siblingData.title ?? '').toLowerCase().replace(/[^a-z0-9]+/g, '-');
773
+ * return base.includes(value) ? base : value;
774
+ * }
775
+ */
776
+ onChange?: (args: {
777
+ /** The current value of this field — typed to match the field's `type`. */
778
+ value: TValue;
779
+ /** Current values of all fields at the same nesting level. */
780
+ siblingData: Record<string, unknown>;
781
+ /** Current values of the entire form. */
782
+ data: Record<string, unknown>;
783
+ /** Imperative setter — use inside async callbacks when you can't return a value. */
784
+ setValue: (value: unknown) => void;
785
+ }) => unknown;
786
+ };
787
+ };
788
+ };
789
+ /**
790
+ * Defines a single field on a collection or global.
791
+ *
792
+ * ## Typed `value` in hook callbacks
793
+ *
794
+ * Three hook callbacks automatically receive a `value` typed to the field's
795
+ * own value type — no manual annotations needed:
796
+ *
797
+ * | Hook | When it runs |
798
+ * |------|-------------|
799
+ * | `hooks.beforeChange` | Server — before the value is written to the DB |
800
+ * | `hooks.afterRead` | Server — after the value is read, before the API response |
801
+ * | `admin.hooks.onChange` | Browser — whenever a sibling field changes in the Admin UI |
802
+ *
803
+ * Type mapping by `type` property:
804
+ * - `text / textarea / email / url / icon / date / select / radio` → `string`
805
+ * - `number` → `number`
806
+ * - `boolean` → `boolean`
807
+ * - `multiSelect` → `string[]`
808
+ * - `relationship / image` → `string | string[]`
809
+ * - `richText / json` → `Record<string, unknown>`
810
+ * - `object / array / blocks` → `unknown`
811
+ *
812
+ * ```ts
813
+ * {
814
+ * name: 'slug', type: 'text',
815
+ * hooks: {
816
+ * beforeChange: [({ value }) => value.toLowerCase()], // value: string ✓
817
+ * afterRead: [({ value }) => value.trim()], // value: string ✓
818
+ * },
819
+ * admin: {
820
+ * hooks: {
821
+ * onChange: ({ value, siblingData }) => // value: string ✓
822
+ * (siblingData.title as string ?? '').toLowerCase().replace(/\s+/g, '-'),
823
+ * },
824
+ * },
825
+ * }
826
+ * ```
827
+ *
828
+ * **Important**: write `type` as a plain string literal — do **not** use `as const`.
829
+ * TypeScript's `const` generic inference already preserves literal types, and
830
+ * adding `as const` to the discriminant property prevents the contextual type
831
+ * from flowing into the hook callbacks.
832
+ *
833
+ * ```ts
834
+ * // ✓ correct
835
+ * { name: 'slug', type: 'text', hooks: { beforeChange: [({ value }) => value.toLowerCase()] } }
836
+ *
837
+ * // ✗ breaks value typing
838
+ * { name: 'slug', type: 'text' as const, hooks: { beforeChange: [({ value }) => value.toLowerCase()] } }
839
+ * ```
840
+ */
841
+ type Field = FieldBase & (({
842
+ type: 'text' | 'textarea' | 'email' | 'url' | 'icon' | 'date' | 'datetime' | 'select' | 'radio';
843
+ } & FieldHooks<string> & FieldAdminHooks<string>) | ({
844
+ type: 'number';
845
+ } & FieldHooks<number> & FieldAdminHooks<number>) | ({
846
+ type: 'boolean';
847
+ } & FieldHooks<boolean> & FieldAdminHooks<boolean>) | ({
848
+ type: 'multiSelect';
849
+ } & FieldHooks<string[]> & FieldAdminHooks<string[]>) | ({
850
+ type: 'relationship' | 'image';
851
+ } & FieldHooks<string | string[]> & FieldAdminHooks<string | string[]>) | ({
852
+ type: 'richText' | 'json';
853
+ } & FieldHooks<Record<string, unknown>> & FieldAdminHooks<Record<string, unknown>>) | ({
854
+ type: 'object' | 'array' | 'blocks' | 'join' | 'row';
855
+ } & FieldHooks<unknown> & FieldAdminHooks<unknown>));
856
+ /**
857
+ * Defines a Dyrected collection — a named set of documents with a shared schema.
858
+ *
859
+ * Pass your document's TypeScript type as the generic parameter `TDoc` to get
860
+ * fully typed hooks and access functions:
861
+ *
862
+ * ```ts
863
+ * interface Post {
864
+ * id: string
865
+ * title: string
866
+ * slug: string
867
+ * status: 'draft' | 'published'
868
+ * publishedAt?: string
869
+ * }
870
+ *
871
+ * export const Posts = defineCollection<Post>({
872
+ * slug: 'posts',
873
+ * hooks: {
874
+ * beforeChange: [({ data, operation }) => {
875
+ * // `data` is typed as Partial<Post>
876
+ * if (operation === 'create') return { ...data, status: 'draft' }
877
+ * return data
878
+ * }],
879
+ * afterChange: [({ doc, previousDoc }) => {
880
+ * // `doc` and `previousDoc` are typed as Post
881
+ * if (doc.status !== previousDoc?.status) notifySubscribers(doc)
882
+ * }],
883
+ * },
884
+ * fields: [...],
885
+ * })
886
+ * ```
887
+ *
888
+ * @template TDoc The TypeScript shape of a document in this collection.
889
+ * Defaults to `Record<string, unknown>` for untyped usage.
890
+ */
891
+ interface CollectionConfig<TDoc extends object = Record<string, unknown>> {
892
+ /**
893
+ * Unique identifier for this collection.
894
+ * Used as the URL segment (`/api/collections/:slug`) and the database table/collection name.
895
+ * Use kebab-case, e.g. `'blog-posts'`.
896
+ */
897
+ slug: string;
898
+ /**
899
+ * Restricts this collection to a specific site in a multi-tenant deployment.
900
+ * When set, only requests bearing a matching `X-Site-Id` header can access it.
901
+ */
902
+ siteId?: string;
903
+ /**
904
+ * If `true`, this collection is shared across all sites in a multi-tenant
905
+ * deployment and accessible regardless of the `X-Site-Id` header.
906
+ */
907
+ shared?: boolean;
908
+ /** Human-readable names for documents in this collection, shown in the Admin UI. */
909
+ labels?: {
910
+ singular: string;
911
+ plural: string;
912
+ };
913
+ /**
914
+ * If `true`, this collection is an **auth collection** — it gains
915
+ * `POST /api/collections/:slug/login` and `POST /api/collections/:slug/logout`
916
+ * endpoints, and documents are expected to have a `password` field.
917
+ */
918
+ auth?: boolean;
919
+ /**
920
+ * If `true` (or a config object), this collection supports **file uploads**.
921
+ * Documents gain file-related fields (`url`, `filename`, `mimeType`, etc.)
922
+ * and the create endpoint accepts `multipart/form-data`.
923
+ */
924
+ upload?: boolean | UploadConfig;
925
+ /** Field definitions that make up the document schema for this collection. */
926
+ fields: Field[];
927
+ /**
928
+ * If `true`, Dyrected automatically adds `createdAt` and `updatedAt`
929
+ * timestamp fields to every document. Defaults to `true`.
930
+ */
931
+ timestamps?: boolean;
932
+ /**
933
+ * Initial documents to seed into this collection the first time it is
934
+ * fetched and found to be empty (e.g. for demo data or defaults).
935
+ */
936
+ initialData?: Partial<TDoc>[];
937
+ /**
938
+ * If `true`, every create, update, and delete operation on this collection
939
+ * is logged to the `__audit` collection with before/after snapshots and the
940
+ * acting user's identity.
941
+ */
942
+ audit?: boolean;
943
+ /**
944
+ * Collection-level access control.
945
+ *
946
+ * Each key is an operation; the value is a function (or Jexl string) that
947
+ * returns `true` to allow or `false` to deny. Returning a `where`-style
948
+ * object grants access only to matching documents.
949
+ *
950
+ * @example
951
+ * access: {
952
+ * read: () => true, // public read
953
+ * create: ({ user }) => !!user, // logged-in users only
954
+ * update: ({ user }) => user?.roles?.includes('editor') ?? false,
955
+ * delete: ({ user }) => user?.roles?.includes('admin') ?? false,
956
+ * }
957
+ */
958
+ access?: {
959
+ read?: AccessFunction<TDoc> | string;
960
+ create?: AccessFunction<TDoc> | string;
961
+ update?: AccessFunction<TDoc> | string;
962
+ delete?: AccessFunction<TDoc> | string;
963
+ };
964
+ /**
965
+ * Collection-level lifecycle hooks.
966
+ *
967
+ * Hooks run in the order they appear in the array. The return value of each
968
+ * hook is passed as the input to the next. Throwing inside any hook aborts
969
+ * the operation and returns a `500` error.
970
+ *
971
+ * See the [Hooks reference](/docs/concepts/hooks) for the full lifecycle diagram.
972
+ */
973
+ hooks?: {
974
+ /**
975
+ * Runs before the database is queried. Return a modified `where` object
976
+ * to override the query filter.
977
+ */
978
+ beforeRead?: CollectionBeforeReadHook[];
979
+ /**
980
+ * Runs after documents are fetched. Return a modified doc to change what
981
+ * the client receives. Runs on every document in a list response.
982
+ */
983
+ afterRead?: CollectionAfterReadHook<TDoc>[];
984
+ /**
985
+ * Runs before create or update. Return modified data to change what is
986
+ * written to the database. Throw to abort the write entirely.
987
+ */
988
+ beforeChange?: CollectionBeforeChangeHook<TDoc>[];
989
+ /**
990
+ * Runs after create or update is committed. For side-effects only —
991
+ * webhooks, cache busting, notifications. Return value is ignored.
992
+ *
993
+ * Errors are **isolated**: caught, logged, and discarded so a failing
994
+ * side-effect never turns a successful write into an HTTP 500.
995
+ * See {@link CollectionAfterChangeHook} for the await-vs-fire-and-forget guidance.
996
+ */
997
+ afterChange?: CollectionAfterChangeHook<TDoc>[];
998
+ /**
999
+ * Runs before a document is deleted. Throw to cancel the deletion.
1000
+ */
1001
+ beforeDelete?: CollectionBeforeDeleteHook<TDoc>[];
1002
+ /**
1003
+ * Runs after a document has been deleted. For cleanup side-effects only.
1004
+ *
1005
+ * Errors are **isolated**: caught, logged, and discarded — the deletion is
1006
+ * already committed and will not be undone.
1007
+ */
1008
+ afterDelete?: CollectionAfterDeleteHook<TDoc>[];
1009
+ };
1010
+ /** Admin UI configuration for this collection. */
1011
+ admin?: {
1012
+ /**
1013
+ * The field name used as the document's display title in the Admin list
1014
+ * view and breadcrumbs. Defaults to `'title'` if the field exists.
1015
+ */
1016
+ useAsTitle?: string;
1017
+ /**
1018
+ * Field names to show as columns in the Admin list view.
1019
+ * Defaults to a sensible set of the first few non-structural fields.
1020
+ */
1021
+ defaultColumns?: string[];
1022
+ /**
1023
+ * Groups this collection under a named section in the Admin sidebar.
1024
+ * Collections with the same `group` are visually grouped together.
1025
+ */
1026
+ group?: string;
1027
+ /** If `true`, this collection is not shown in the Admin UI sidebar. */
1028
+ hidden?: boolean;
1029
+ /**
1030
+ * URL to open in the Live Preview pane when editing a document.
1031
+ * Pass a function to derive the URL from the document's fields.
1032
+ *
1033
+ * @example
1034
+ * previewUrl: (doc) => `https://mysite.com/blog/${doc.slug}`
1035
+ */
1036
+ previewUrl?: string | ((doc: TDoc, opts: {
1037
+ locale?: string;
1038
+ }) => string | null);
1039
+ /**
1040
+ * How the Live Preview pane communicates with the frontend.
1041
+ * - `'postMessage'` (default) — sends a `postMessage` with the current doc data.
1042
+ * - `'token'` — passes a short-lived preview token as a query parameter.
1043
+ */
1044
+ previewMode?: "postMessage" | "token";
1045
+ /**
1046
+ * Frontend URL pattern for this collection, used by `url` fields to
1047
+ * resolve internal links. Use `{fieldName}` placeholders.
1048
+ *
1049
+ * @example
1050
+ * urlPattern: '/blog/{slug}' // → /blog/my-post
1051
+ * urlPattern: '/{slug}' // → /about
1052
+ */
1053
+ urlPattern?: string;
1054
+ };
1055
+ }
1056
+ /**
1057
+ * Upload configuration for collections that store files.
1058
+ * Set `upload: true` on the collection to use all defaults, or pass this
1059
+ * object to customise allowed types, size limits, and image processing.
1060
+ */
1061
+ interface UploadConfig {
1062
+ /**
1063
+ * Allowed MIME types. Requests with other MIME types are rejected with `400`.
1064
+ * @example ['image/jpeg', 'image/png', 'image/webp', 'application/pdf']
1065
+ */
1066
+ allowedMimeTypes?: string[];
1067
+ /**
1068
+ * Maximum file size in **bytes**.
1069
+ * @example 10 * 1024 * 1024 // 10 MB
1070
+ */
1071
+ maxFileSize?: number;
1072
+ /**
1073
+ * Local filesystem path where files are stored.
1074
+ * Only used by the `LocalStorage` adapter.
1075
+ */
1076
+ staticDir?: string;
1077
+ /**
1078
+ * Public URL prefix prepended to filenames when generating download URLs.
1079
+ * Only used by the `LocalStorage` adapter.
1080
+ * @example '/uploads'
1081
+ */
1082
+ staticURL?: string;
1083
+ /**
1084
+ * The `imageSizes` entry name to use as the thumbnail in the Admin media grid.
1085
+ * @example 'thumbnail'
1086
+ */
1087
+ adminThumbnail?: string;
1088
+ /**
1089
+ * Additional image sizes to generate when an image is uploaded.
1090
+ * Requires an `ImageService` to be configured (e.g. `@dyrected/image-sharp`).
1091
+ *
1092
+ * @example
1093
+ * imageSizes: [
1094
+ * { name: 'thumbnail', width: 300, height: 300, fit: 'cover' },
1095
+ * { name: 'card', width: 800 },
1096
+ * ]
1097
+ */
1098
+ imageSizes?: {
1099
+ /** Identifier used to access this size, e.g. `doc.sizes.thumbnail`. */
1100
+ name: string;
1101
+ /** Target width in pixels. */
1102
+ width?: number;
1103
+ /** Target height in pixels. */
1104
+ height?: number;
1105
+ /** sharp crop strategy (`'entropy'`, `'attention'`, etc.). */
1106
+ crop?: string;
1107
+ /**
1108
+ * sharp fit strategy.
1109
+ * @see https://sharp.pixelplumbing.com/api-resize#parameters
1110
+ */
1111
+ fit?: string;
1112
+ /**
1113
+ * If `true`, images smaller than the target size are not upscaled.
1114
+ * @default true
1115
+ */
1116
+ withoutEnlargement?: boolean;
1117
+ /** Additional sharp format options forwarded to the output pipeline. */
1118
+ formatOptions?: Record<string, unknown>;
1119
+ }[];
1120
+ }
1121
+ /**
1122
+ * Defines a Dyrected global — a singleton document without pagination or IDs.
1123
+ *
1124
+ * Globals are ideal for site-wide settings, feature flags, or any data where
1125
+ * there is always exactly one record (e.g. `site-settings`, `navigation`, `theme`).
1126
+ *
1127
+ * Pass your document's TypeScript type as the generic parameter `TDoc` to get
1128
+ * fully typed hooks:
1129
+ *
1130
+ * ```ts
1131
+ * interface SiteSettings {
1132
+ * siteName: string
1133
+ * tagline: string
1134
+ * maintenanceMode: boolean
1135
+ * }
1136
+ *
1137
+ * export const Settings = defineGlobal<SiteSettings>({
1138
+ * slug: 'site-settings',
1139
+ * hooks: {
1140
+ * afterChange: [({ doc }) => {
1141
+ * // `doc` is typed as SiteSettings
1142
+ * if (doc.maintenanceMode) alertOnCall()
1143
+ * }],
1144
+ * },
1145
+ * fields: [...],
1146
+ * })
1147
+ * ```
1148
+ *
1149
+ * @template TDoc The TypeScript shape of this global's document.
1150
+ */
1151
+ interface GlobalConfig<TDoc extends object = Record<string, unknown>> {
1152
+ /**
1153
+ * Unique identifier for this global.
1154
+ * Used as the URL segment (`/api/globals/:slug`) and the storage key.
1155
+ */
1156
+ slug: string;
1157
+ /** Restricts this global to a specific site in a multi-tenant deployment. */
1158
+ siteId?: string;
1159
+ /**
1160
+ * If `true`, this global is shared across all sites in a multi-tenant
1161
+ * deployment.
1162
+ */
1163
+ shared?: boolean;
1164
+ /** Human-readable label shown in the Admin UI sidebar. */
1165
+ label?: string;
1166
+ /** Field definitions for this global's document schema. */
1167
+ fields: Field[];
1168
+ /** Access control for reading and updating this global. */
1169
+ access?: {
1170
+ read?: AccessFunction<TDoc>;
1171
+ update?: AccessFunction<TDoc>;
1172
+ };
1173
+ /**
1174
+ * Global-level lifecycle hooks.
1175
+ * Globals support `beforeRead`, `afterRead`, `beforeChange`, and `afterChange`.
1176
+ * There are no delete hooks since globals cannot be deleted.
1177
+ */
1178
+ hooks?: {
1179
+ beforeRead?: GlobalBeforeReadHook[];
1180
+ afterRead?: GlobalAfterReadHook<TDoc>[];
1181
+ beforeChange?: GlobalBeforeChangeHook<TDoc>[];
1182
+ afterChange?: GlobalAfterChangeHook<TDoc>[];
1183
+ };
1184
+ /** Admin UI configuration for this global. */
1185
+ admin?: {
1186
+ /** Groups this global under a named section in the Admin sidebar. */
1187
+ group?: string;
1188
+ /** If `true`, this global is not shown in the Admin UI sidebar. */
1189
+ hidden?: boolean;
1190
+ };
1191
+ /**
1192
+ * Initial data to seed this global with the first time it is fetched and
1193
+ * found to be empty.
1194
+ */
1195
+ initialData?: Partial<TDoc>;
1196
+ }
1197
+ /**
1198
+ * The minimum shape of every document returned by the database layer.
1199
+ *
1200
+ * All documents have an `id` field assigned by the adapter. Additional fields
1201
+ * are stored as `unknown` until you narrow them with your own interface.
1202
+ *
1203
+ * Use this as the base when declaring your collection document types:
1204
+ * ```ts
1205
+ * interface Post extends BaseDocument {
1206
+ * title: string
1207
+ * slug: string
1208
+ * }
1209
+ * ```
1210
+ */
1211
+ interface BaseDocument {
1212
+ /** The document's unique identifier, assigned by the database adapter. */
1213
+ id: string;
1214
+ [key: string]: unknown;
1215
+ }
1216
+ /**
1217
+ * The envelope returned by collection list endpoints (`GET /api/collections/:slug`).
1218
+ *
1219
+ * @template T The document type.
1220
+ */
1221
+ interface PaginatedResult<T = Record<string, unknown>> {
1222
+ /** The documents on the current page. */
1223
+ docs: T[];
1224
+ /** Total number of documents matching the query (across all pages). */
1225
+ total: number;
1226
+ /** Maximum number of documents per page as requested. */
1227
+ limit: number;
1228
+ /** The current page number (1-indexed). */
1229
+ page: number;
1230
+ /** Total number of pages given the current `limit`. */
1231
+ totalPages: number;
1232
+ /** Whether a next page exists. */
1233
+ hasNextPage: boolean;
1234
+ /** Whether a previous page exists. */
1235
+ hasPrevPage: boolean;
1236
+ }
1237
+ /**
1238
+ * The interface every database adapter must implement.
1239
+ *
1240
+ * Dyrected ships adapters for PostgreSQL, MySQL, SQLite, and MongoDB.
1241
+ * Implement this interface to connect any other database.
1242
+ */
1243
+ interface DatabaseAdapter {
1244
+ /** Find a paginated list of documents in a collection. */
1245
+ find(args: {
1246
+ collection: string;
1247
+ where?: Record<string, unknown>;
1248
+ limit?: number;
1249
+ page?: number;
1250
+ sort?: string;
1251
+ }): Promise<PaginatedResult>;
1252
+ /** Find a single document by its ID. Returns `null` if not found. */
1253
+ findOne(args: {
1254
+ collection: string;
1255
+ id: string;
1256
+ }): Promise<BaseDocument | null>;
1257
+ /** Insert a new document and return it with its generated `id`. */
1258
+ create(args: {
1259
+ collection: string;
1260
+ data: Record<string, unknown>;
1261
+ }): Promise<BaseDocument>;
1262
+ /** Update a document by ID and return the updated document. */
1263
+ update(args: {
1264
+ collection: string;
1265
+ id: string;
1266
+ data: Record<string, unknown>;
1267
+ }): Promise<BaseDocument>;
1268
+ /** Delete a document by ID. Return value is intentionally untyped — callers do not use it. */
1269
+ delete(args: {
1270
+ collection: string;
1271
+ id: string;
1272
+ }): Promise<unknown>;
1273
+ /** Fetch the singleton document for a global. Returns `null` if not yet initialised. */
1274
+ getGlobal(args: {
1275
+ slug: string;
1276
+ }): Promise<Record<string, unknown> | null>;
1277
+ /** Create or replace the singleton document for a global. */
1278
+ updateGlobal(args: {
1279
+ slug: string;
1280
+ data: Record<string, unknown>;
1281
+ }): Promise<Record<string, unknown>>;
1282
+ /**
1283
+ * Sync the database schema with the current collection and global configs.
1284
+ * Called on startup to create tables/collections that don't exist yet.
1285
+ * Not all adapters implement this (e.g. MongoDB is schema-less).
1286
+ */
1287
+ sync?(collections: CollectionConfig[], globals: GlobalConfig[]): Promise<void>;
1288
+ /**
1289
+ * Execute a raw SQL query or database command.
1290
+ * Optional — not all adapters support raw access.
1291
+ */
1292
+ execute?(query: string, params?: unknown[]): Promise<unknown>;
1293
+ }
1294
+ /**
1295
+ * Metadata returned after a file is uploaded and stored.
1296
+ * Stored on the document in upload collections.
1297
+ */
1298
+ interface FileData {
1299
+ filename: string;
1300
+ filesize?: number;
1301
+ mimeType: string;
1302
+ /** Public URL of the stored file. */
1303
+ url: string;
1304
+ width?: number;
1305
+ height?: number;
1306
+ focalPoint?: {
1307
+ x: number;
1308
+ y: number;
1309
+ };
1310
+ /** Base64-encoded BlurHash string for progressive image loading. */
1311
+ blurhash?: string;
1312
+ /** `'upload'` for server-stored files; `'external'` for provider-managed files. */
1313
+ type?: "upload" | "external";
1314
+ provider?: string;
1315
+ provider_metadata?: unknown;
1316
+ [key: string]: unknown;
1317
+ }
1318
+ /**
1319
+ * The interface every storage adapter must implement.
1320
+ *
1321
+ * Dyrected ships adapters for local disk, S3, Cloudflare R2, Cloudinary, and
1322
+ * Backblaze B2. Implement this interface to use any other storage provider.
1323
+ */
1324
+ interface StorageAdapter {
1325
+ /**
1326
+ * Upload a file and return its metadata (URL, dimensions, etc.).
1327
+ * The `prefix` is a path prefix used for multi-tenant setups.
1328
+ */
1329
+ upload(args: {
1330
+ filename: string;
1331
+ buffer: Uint8Array;
1332
+ mimeType: string;
1333
+ prefix?: string;
1334
+ }): Promise<FileData>;
1335
+ /** Delete a file by its stored filename. */
1336
+ delete(args: {
1337
+ filename: string;
1338
+ }): Promise<void>;
1339
+ /** Return the public URL for a stored file. */
1340
+ getURL(args: {
1341
+ filename: string;
1342
+ }): string;
1343
+ /**
1344
+ * Retrieve the file's raw bytes and MIME type for serving via the API.
1345
+ * Only needed by adapters that serve files through the Dyrected API
1346
+ * (e.g. `LocalStorage`). Cloud adapters return `null` here and rely on
1347
+ * direct CDN URLs instead.
1348
+ */
1349
+ resolve?(args: {
1350
+ filename: string;
1351
+ }): Promise<{
1352
+ buffer: Uint8Array;
1353
+ mimeType: string;
1354
+ } | null>;
1355
+ }
1356
+ /**
1357
+ * Processes uploaded images — generates metadata (dimensions, BlurHash) and
1358
+ * produces resized variants defined in `UploadConfig.imageSizes`.
1359
+ *
1360
+ * @example
1361
+ * import { SharpImageService } from '@dyrected/image-sharp'
1362
+ * defineConfig({ image: new SharpImageService(), ... })
1363
+ */
1364
+ interface ImageService {
1365
+ process(args: {
1366
+ buffer: Uint8Array;
1367
+ mimeType: string;
1368
+ config?: CollectionConfig["upload"];
1369
+ focalPoint?: {
1370
+ x: number;
1371
+ y: number;
1372
+ };
1373
+ }): Promise<{
1374
+ metadata: {
1375
+ width?: number;
1376
+ height?: number;
1377
+ /** Base64-encoded BlurHash for progressive loading. */
1378
+ blurhash?: string;
1379
+ };
1380
+ /** Generated image sizes keyed by their `name`. */
1381
+ sizes?: Record<string, {
1382
+ buffer: Uint8Array;
1383
+ width: number;
1384
+ height: number;
1385
+ filename: string;
1386
+ }>;
1387
+ }>;
1388
+ }
1389
+ /**
1390
+ * Branding and metadata options for the Dyrected Admin UI.
1391
+ *
1392
+ * @example
1393
+ * admin: {
1394
+ * branding: {
1395
+ * logo: '/logo.svg',
1396
+ * primaryColor: '#6366f1',
1397
+ * },
1398
+ * meta: {
1399
+ * titleSuffix: '- My App',
1400
+ * },
1401
+ * }
1402
+ */
1403
+ interface AdminConfig {
1404
+ branding?: {
1405
+ /** Full logo image shown in the expanded sidebar. URL or imported image asset. */
1406
+ logo?: string;
1407
+ /** Compact logo mark used in the collapsed sidebar state. */
1408
+ logoMark?: string;
1409
+ /**
1410
+ * Primary accent colour as any CSS colour value.
1411
+ * @example '#6366f1'
1412
+ * @example 'hsl(240 50% 60%)'
1413
+ */
1414
+ primaryColor?: string;
1415
+ /** Browser tab favicon URL. */
1416
+ favicon?: string;
1417
+ /** Font family for body and UI text. Must be loaded separately. */
1418
+ fontSans?: string;
1419
+ /** Font family for headings. Must be loaded separately. */
1420
+ fontSerif?: string;
1421
+ };
1422
+ meta?: {
1423
+ /**
1424
+ * String appended to every Admin page's `<title>`.
1425
+ * @default '- Dyrected'
1426
+ */
1427
+ titleSuffix?: string;
1428
+ };
1429
+ }
1430
+ /**
1431
+ * Collapses intersection types into a flat object type for readable IDE tooltips.
1432
+ *
1433
+ * @example
1434
+ * type T = Prettify<{ a: string } & { b: number }>
1435
+ * // → { a: string; b: number }
1436
+ */
1437
+ type Prettify<T> = {
1438
+ [K in keyof T]: T[K];
1439
+ };
1440
+ /** Maps a field's runtime type tag to its TypeScript value type. @internal */
1441
+ type FieldValueType<F extends Field> = F['type'] extends 'text' | 'textarea' | 'email' | 'url' | 'icon' | 'date' | 'select' | 'radio' ? string : F['type'] extends 'number' ? number : F['type'] extends 'boolean' ? boolean : F['type'] extends 'multiSelect' ? string[] : F['type'] extends 'relationship' ? F extends {
1442
+ hasMany: true;
1443
+ } ? string[] : string : F['type'] extends 'image' ? string : F['type'] extends 'richText' | 'json' ? Record<string, unknown> : F['type'] extends 'object' ? F extends {
1444
+ fields: infer SF extends readonly Field[];
1445
+ } ? Prettify<InferDocShape<SF>> : Record<string, unknown> : F['type'] extends 'array' ? F extends {
1446
+ fields: infer SF extends readonly Field[];
1447
+ } ? Array<Prettify<InferDocShape<SF>>> : unknown[] : F['type'] extends 'blocks' ? F extends {
1448
+ blocks: infer B extends readonly Block[];
1449
+ } ? Array<InferBlocksUnion<B>> : Array<{
1450
+ blockType: string;
1451
+ } & Record<string, unknown>> : unknown;
1452
+ /** Build a discriminated-union type covering all possible block shapes. @internal */
1453
+ type InferBlocksUnion<Blocks extends readonly Block[]> = Blocks extends readonly [infer B extends Block, ...infer Rest extends readonly Block[]] ? B['fields'] extends readonly Field[] ? ({
1454
+ blockType: B['slug'];
1455
+ } & Prettify<InferDocShape<B['fields']>>) | InferBlocksUnion<Rest> : ({
1456
+ blockType: B['slug'];
1457
+ } & Record<string, unknown>) | InferBlocksUnion<Rest> : never;
1458
+ /** Converts one field definition to its corresponding document key/value pair. @internal */
1459
+ type InferFieldEntry<F extends Field> = F extends {
1460
+ type: 'row';
1461
+ fields: infer SF extends readonly Field[];
1462
+ } ? InferDocShape<SF> : F extends {
1463
+ type: 'join';
1464
+ } ? Record<never, never> : F extends {
1465
+ name: infer N extends string;
1466
+ required: true;
1467
+ } ? {
1468
+ [K in N]: FieldValueType<F>;
1469
+ } : F extends {
1470
+ name: infer N extends string;
1471
+ } ? {
1472
+ [K in N]?: FieldValueType<F>;
1473
+ } : Record<never, never>;
1474
+ /**
1475
+ * Infer a document shape from a literal fields tuple.
1476
+ *
1477
+ * This is used automatically by {@link defineCollection} and {@link defineGlobal}
1478
+ * when no explicit `TDoc` type argument is provided — TypeScript derives the
1479
+ * document type straight from the `fields` array you write inline.
1480
+ *
1481
+ * For collections, the inferred type is wrapped with `{ id: string }` (the
1482
+ * database adapter always stamps an `id` on created documents). Globals don't
1483
+ * get an `id`.
1484
+ *
1485
+ * @example
1486
+ * const fields = [
1487
+ * { name: 'title', type: 'text', required: true },
1488
+ * { name: 'published', type: 'boolean' },
1489
+ * ] as const satisfies Field[];
1490
+ *
1491
+ * type Doc = InferDocShape<typeof fields>;
1492
+ * // → { title: string; published?: boolean }
1493
+ */
1494
+ type InferDocShape<Fields extends readonly Field[]> = Fields extends readonly [] ? Record<never, never> : Fields extends readonly [infer Head extends Field, ...infer Tail extends readonly Field[]] ? InferFieldEntry<Head> & InferDocShape<Tail> : Record<string, unknown>;
1495
+ /**
1496
+ * Audit fields automatically injected into every collection document at runtime.
1497
+ * They are always present in API responses but hidden in the Admin UI by default.
1498
+ */
1499
+ type SystemDocFields = {
1500
+ createdAt?: string;
1501
+ updatedAt?: string;
1502
+ /** ID of the user who created the document. */
1503
+ createdBy?: string;
1504
+ /** ID of the user who last updated the document. */
1505
+ updatedBy?: string;
1506
+ };
1507
+ /**
1508
+ * Fields automatically injected into collections with `auth: true`.
1509
+ * `password` is part of the schema but is stripped from API read responses.
1510
+ */
1511
+ type AuthDocFields = {
1512
+ email: string;
1513
+ password?: string;
1514
+ roles?: string;
1515
+ };
1516
+ /**
1517
+ * Fields automatically added to upload/media collection documents.
1518
+ * These mirror the `FileData` interface returned by storage adapters.
1519
+ */
1520
+ type UploadDocFields = {
1521
+ filename: string;
1522
+ filesize?: number;
1523
+ mimeType: string;
1524
+ /** Public URL of the stored file. */
1525
+ url: string;
1526
+ width?: number;
1527
+ height?: number;
1528
+ focalPoint?: {
1529
+ x: number;
1530
+ y: number;
1531
+ };
1532
+ /** Base64 BlurHash for progressive image loading. */
1533
+ blurhash?: string;
1534
+ sizes?: Record<string, {
1535
+ filename?: string;
1536
+ url?: string;
1537
+ width?: number;
1538
+ height?: number;
1539
+ }>;
1540
+ };
1541
+ /**
1542
+ * The root configuration object passed to `createDyrectedApp`.
1543
+ *
1544
+ * This is the single source of truth for your entire Dyrected instance —
1545
+ * collections, globals, database adapter, storage, email, and more.
1546
+ *
1547
+ * @example
1548
+ * import { defineConfig } from '@dyrected/core'
1549
+ * import { SQLiteAdapter } from '@dyrected/db-sqlite'
1550
+ *
1551
+ * export default defineConfig({
1552
+ * db: new SQLiteAdapter({ filename: './db.sqlite' }),
1553
+ * collections: [Posts, Users],
1554
+ * globals: [SiteSettings],
1555
+ * })
1556
+ */
1557
+ interface DyrectedConfig {
1558
+ /** Collection definitions. Each collection maps to a database table/collection. */
1559
+ collections: CollectionConfig<any>[];
1560
+ /** Global (singleton) definitions. Each global maps to a single document. */
1561
+ globals: GlobalConfig<any>[];
1562
+ /**
1563
+ * The database adapter. Required for all data operations.
1564
+ * @see {@link DatabaseAdapter}
1565
+ */
1566
+ db?: DatabaseAdapter;
1567
+ /**
1568
+ * The storage adapter for file uploads.
1569
+ * Required when any collection has `upload: true`.
1570
+ * @see {@link StorageAdapter}
1571
+ */
1572
+ storage?: StorageAdapter;
1573
+ /**
1574
+ * The image processing service. Required when any upload collection
1575
+ * defines `imageSizes`.
1576
+ * @see {@link ImageService}
1577
+ */
1578
+ image?: ImageService;
1579
+ /** Admin UI branding and metadata. */
1580
+ admin?: AdminConfig;
1581
+ /**
1582
+ * Email transport configuration. Required for welcome emails, password
1583
+ * resets, and invite links.
1584
+ *
1585
+ * @example
1586
+ * email: {
1587
+ * from: 'no-reply@myapp.com',
1588
+ * send: async ({ to, subject, html }) => {
1589
+ * await resend.emails.send({ from, to, subject, html })
1590
+ * },
1591
+ * }
1592
+ */
1593
+ email?: {
1594
+ /** The `From` address for all outbound emails. */
1595
+ from: string;
1596
+ /** The send function. Wire in any email provider (Resend, SendGrid, SES, etc.). */
1597
+ send: (args: {
1598
+ to: string;
1599
+ subject: string;
1600
+ html: string;
1601
+ }) => Promise<void>;
1602
+ /** Override the default email templates. */
1603
+ templates?: {
1604
+ welcome?: (args: {
1605
+ email: string;
1606
+ }) => {
1607
+ subject?: string;
1608
+ html: string;
1609
+ };
1610
+ invite?: (args: {
1611
+ token: string;
1612
+ invitedByEmail?: string;
1613
+ }) => {
1614
+ subject?: string;
1615
+ html: string;
1616
+ };
1617
+ resetPassword?: (args: {
1618
+ token: string;
1619
+ }) => {
1620
+ subject?: string;
1621
+ html: string;
1622
+ };
1623
+ passwordChanged?: (args: {
1624
+ email: string;
1625
+ }) => {
1626
+ subject?: string;
1627
+ html: string;
1628
+ };
1629
+ };
1630
+ };
1631
+ /**
1632
+ * Redis connection URL. Required for distributed caching of dynamic option
1633
+ * resolvers and other server-side caches in multi-instance deployments.
1634
+ *
1635
+ * @example
1636
+ * redis: { url: process.env.REDIS_URL }
1637
+ */
1638
+ redis?: {
1639
+ url: string;
1640
+ };
1641
+ /**
1642
+ * Cross-Origin Resource Sharing (CORS) configuration.
1643
+ * List all origins that are allowed to call the Dyrected API.
1644
+ *
1645
+ * @example
1646
+ * cors: { origins: ['https://myapp.com', 'https://www.myapp.com'] }
1647
+ */
1648
+ cors?: {
1649
+ origins: string[];
1650
+ };
1651
+ /**
1652
+ * Callback to dynamically fetch additional collections and globals for a
1653
+ * given site ID at request time. Used in multi-tenant deployments where each
1654
+ * site has its own schema stored in the database.
1655
+ *
1656
+ * @param siteId The `X-Site-Id` header value from the incoming request.
1657
+ * @returns Extra collections and globals to merge into the config for this request.
1658
+ *
1659
+ * @example
1660
+ * onSchemaFetch: async (siteId) => {
1661
+ * const site = await db.findOne({ collection: 'sites', id: siteId })
1662
+ * return buildSchemaFromSiteConfig(site)
1663
+ * }
1664
+ */
1665
+ onSchemaFetch?: (siteId: string) => Promise<{
1666
+ collections?: CollectionConfig<any>[];
1667
+ globals?: GlobalConfig<any>[];
1668
+ }>;
1669
+ }
1670
+
1671
+ interface DyrectedContext {
1672
+ Variables: {
1673
+ config: DyrectedConfig;
1674
+ siteId?: string;
1675
+ workspaceId?: string;
1676
+ /** Decoded JWT payload set by requireAuth() or optionalAuth() middleware. */
1677
+ user?: {
1678
+ sub: string;
1679
+ email: string;
1680
+ collection: string;
1681
+ [key: string]: any;
1682
+ };
1683
+ };
1684
+ }
1685
+ /**
1686
+ * Create the main Dyrected Hono application.
1687
+ */
1688
+ declare function createDyrectedApp(rawConfig: DyrectedConfig): Promise<Hono<DyrectedContext, hono_types.BlankSchema, "/">>;
1689
+
1690
+ export { type AuthDocFields as A, type BaseDocument as B, type CollectionConfig as C, type DyrectedConfig as D, type ImageService as E, type Field as F, type GlobalConfig as G, type HookFunction as H, type InferDocShape as I, type PaginatedResult as J, type StorageAdapter as K, type UploadConfig as L, createDyrectedApp as M, type Prettify as P, type SystemDocFields as S, type UploadDocFields as U, type AccessFunction as a, type AdminConfig as b, type AuthenticatedUser as c, type Block as d, type CollectionAfterChangeHook as e, type CollectionAfterDeleteHook as f, type CollectionAfterReadHook as g, type CollectionBeforeChangeHook as h, type CollectionBeforeDeleteHook as i, type CollectionBeforeReadHook as j, type DatabaseAdapter as k, type DynamicOptionItem as l, type DynamicOptionsConfig as m, type DynamicOptionsResolver as n, type DynamicOptionsResolverArgs as o, type DyrectedContext as p, type FieldAfterReadHook as q, type FieldBeforeChangeHook as r, type FieldHook as s, type FieldType as t, type FileData as u, type GlobalAfterChangeHook as v, type GlobalAfterReadHook as w, type GlobalBeforeChangeHook as x, type GlobalBeforeReadHook as y, type HookRequestContext as z };