@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
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-DnX9mNsh.cjs';
2
- export { A as AccessFunction, a as AdminConfig, B as Block, b as DatabaseAdapter, c as DyrectedContext, F as Field, d as FieldHook, e as FieldType, f as FileData, H as HookFunction, I as ImageService, P as PaginatedResult, S as StorageAdapter, U as UploadConfig, g as createDyrectedApp } from './app-DnX9mNsh.cjs';
1
+ import { D as DyrectedConfig, F as Field, C as CollectionConfig, P as Prettify, I as InferDocShape, S as SystemDocFields, A as AuthDocFields, U as UploadDocFields, G as GlobalConfig } from './app-BElen1tP.cjs';
2
+ export { a as AccessFunction, b as AdminConfig, c as AuthenticatedUser, B as BaseDocument, d as Block, e as CollectionAfterChangeHook, f as CollectionAfterDeleteHook, g as CollectionAfterReadHook, h as CollectionBeforeChangeHook, i as CollectionBeforeDeleteHook, j as CollectionBeforeReadHook, k as DatabaseAdapter, l as DynamicOptionItem, m as DynamicOptionsConfig, n as DynamicOptionsResolver, o as DynamicOptionsResolverArgs, p as DyrectedContext, q as FieldAfterReadHook, r as FieldBeforeChangeHook, s as FieldHook, t as FieldType, u as FileData, v as GlobalAfterChangeHook, w as GlobalAfterReadHook, x as GlobalBeforeChangeHook, y as GlobalBeforeReadHook, H as HookFunction, z as HookRequestContext, E as ImageService, J as PaginatedResult, K as StorageAdapter, L as UploadConfig, M as createDyrectedApp } from './app-BElen1tP.cjs';
3
3
  import 'hono/types';
4
4
  import 'hono';
5
5
 
@@ -84,17 +84,133 @@ declare function parseSqlWhere(where: WhereClause, getJsonField: (field: string)
84
84
  */
85
85
  declare function parseMongoWhere(where: WhereClause): Record<string, any>;
86
86
 
87
+ type AnyHookFn = (args: any) => any;
87
88
  /**
88
- * Define a collection configuration with full type safety.
89
+ * Run a list of hook functions sequentially.
90
+ *
91
+ * Each hook receives the output of the previous hook merged back into the
92
+ * original `args`. When a hook returns a non-undefined value it becomes the
93
+ * `data` / `doc` for the next hook in the chain.
94
+ *
95
+ * Pass `{ isolated: true }` for hooks that run **after** a DB write has already
96
+ * been committed (`afterChange`, `afterDelete`). In isolated mode each hook is
97
+ * wrapped in a try/catch so a failing side-effect (email, webhook, etc.) never
98
+ * surfaces as an HTTP 500 to the caller — the write already succeeded.
99
+ */
100
+ declare function runCollectionHooks(hooks: AnyHookFn[] | undefined, args: {
101
+ data?: unknown;
102
+ doc?: unknown;
103
+ user?: unknown;
104
+ req?: unknown;
105
+ operation?: "create" | "update" | "delete";
106
+ [key: string]: unknown;
107
+ }, options?: {
108
+ isolated?: boolean;
109
+ }): Promise<any>;
110
+ /**
111
+ * Execute field-level `beforeChange` hooks recursively on a data payload.
112
+ *
113
+ * Traverses `array`, `object`, and `blocks` fields depth-first so that nested
114
+ * field hooks fire on every item automatically.
115
+ */
116
+ declare function executeFieldBeforeChange(fields: Field[], data: Record<string, unknown>, originalDoc: Record<string, unknown> | null, user: unknown): Promise<Record<string, unknown>>;
117
+ /**
118
+ * Execute field-level `afterRead` hooks recursively on a document.
119
+ *
120
+ * Traverses `array`, `object`, and `blocks` fields depth-first so that nested
121
+ * field hooks fire on every item automatically.
122
+ */
123
+ declare function executeFieldAfterRead(fields: Field[], doc: Record<string, unknown>, user: unknown): Promise<Record<string, unknown>>;
124
+
125
+ /**
126
+ * Define a collection. When called without an explicit type argument, TypeScript
127
+ * automatically infers the document shape from the `fields` array you provide —
128
+ * no manual interface required:
129
+ *
130
+ * ```ts
131
+ * export const Posts = defineCollection({
132
+ * slug: 'posts',
133
+ * fields: [
134
+ * { name: 'title', type: 'text', required: true },
135
+ * { name: 'status', type: 'select', options: ['draft', 'published'], required: true },
136
+ * ],
137
+ * hooks: {
138
+ * beforeChange: [({ data }) => {
139
+ * // data is { title: string; status: 'draft' | 'published' } — fully inferred
140
+ * }],
141
+ * },
142
+ * })
143
+ * ```
144
+ *
145
+ * When you need a richer interface (e.g. with methods, JSDoc, or types that
146
+ * can't be derived from fields), pass it explicitly:
147
+ *
148
+ * ```ts
149
+ * interface Post { id: string; title: string; status: 'draft' | 'published' }
150
+ *
151
+ * export const Posts = defineCollection<Post>({ ... })
152
+ * ```
89
153
  */
90
- declare function defineCollection(config: CollectionConfig): CollectionConfig;
154
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
155
+ id: string;
156
+ } & InferDocShape<TFields> & SystemDocFields & AuthDocFields>>, 'fields' | 'auth'> & {
157
+ fields: TFields;
158
+ auth: true;
159
+ }): CollectionConfig<Prettify<{
160
+ id: string;
161
+ } & InferDocShape<TFields> & SystemDocFields & AuthDocFields>>;
162
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
163
+ id: string;
164
+ } & InferDocShape<TFields> & SystemDocFields & UploadDocFields>>, 'fields' | 'upload'> & {
165
+ fields: TFields;
166
+ upload: true;
167
+ }): CollectionConfig<Prettify<{
168
+ id: string;
169
+ } & InferDocShape<TFields> & SystemDocFields & UploadDocFields>>;
170
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
171
+ id: string;
172
+ } & InferDocShape<TFields> & SystemDocFields>>, 'fields'> & {
173
+ fields: TFields;
174
+ }): CollectionConfig<Prettify<{
175
+ id: string;
176
+ } & InferDocShape<TFields> & SystemDocFields>>;
177
+ declare function defineCollection<TDoc extends object>(config: CollectionConfig<TDoc>): CollectionConfig<TDoc>;
91
178
  /**
92
- * Define a global configuration with full type safety.
179
+ * Define a global (singleton document). TypeScript automatically infers the
180
+ * document shape from the `fields` array, or you can pass an explicit type:
181
+ *
182
+ * ```ts
183
+ * // Inferred — no interface needed
184
+ * export const Settings = defineGlobal({
185
+ * slug: 'site-settings',
186
+ * fields: [
187
+ * { name: 'siteName', type: 'text', required: true },
188
+ * { name: 'maintenanceMode', type: 'boolean' },
189
+ * ],
190
+ * hooks: {
191
+ * afterChange: [({ doc }) => {
192
+ * // doc.siteName is string, doc.maintenanceMode is boolean | undefined
193
+ * if (doc.maintenanceMode) alertOnCall()
194
+ * }],
195
+ * },
196
+ * })
197
+ *
198
+ * // Explicit type
199
+ * interface SiteSettings { siteName: string; maintenanceMode?: boolean }
200
+ * export const Settings = defineGlobal<SiteSettings>({ ... })
201
+ * ```
93
202
  */
94
- declare function defineGlobal(config: GlobalConfig): GlobalConfig;
203
+ declare function defineGlobal<const TFields extends Field[]>(config: Omit<GlobalConfig<Prettify<InferDocShape<TFields>>>, 'fields'> & {
204
+ fields: TFields;
205
+ }): GlobalConfig<Prettify<InferDocShape<TFields>>>;
206
+ declare function defineGlobal<TDoc extends object>(config: GlobalConfig<TDoc>): GlobalConfig<TDoc>;
95
207
  /**
96
- * Define the main Dyrected configuration.
208
+ * Define the root Dyrected configuration.
209
+ *
210
+ * This is the single object passed to `createDyrectedApp`. It wires together
211
+ * the database adapter, collections, globals, storage, email, and all other
212
+ * server-level configuration.
97
213
  */
98
214
  declare function defineConfig(config: DyrectedConfig): DyrectedConfig;
99
215
 
100
- export { CollectionConfig, DyrectedConfig, GlobalConfig, type SetupPromptConfig, type SqlWhereResult, type WhereClause, type WhereOperator, type WhereOperatorName, defineCollection, defineConfig, defineGlobal, generateAIPrompt, generateFreshSetupPrompt, normalizeConfig, parseMongoWhere, parseSqlWhere };
216
+ export { AuthDocFields, CollectionConfig, DyrectedConfig, Field, GlobalConfig, InferDocShape, Prettify, type SetupPromptConfig, type SqlWhereResult, SystemDocFields, UploadDocFields, type WhereClause, type WhereOperator, type WhereOperatorName, defineCollection, defineConfig, defineGlobal, executeFieldAfterRead, executeFieldBeforeChange, generateAIPrompt, generateFreshSetupPrompt, normalizeConfig, parseMongoWhere, parseSqlWhere, runCollectionHooks };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-DnX9mNsh.js';
2
- export { A as AccessFunction, a as AdminConfig, B as Block, b as DatabaseAdapter, c as DyrectedContext, F as Field, d as FieldHook, e as FieldType, f as FileData, H as HookFunction, I as ImageService, P as PaginatedResult, S as StorageAdapter, U as UploadConfig, g as createDyrectedApp } from './app-DnX9mNsh.js';
1
+ import { D as DyrectedConfig, F as Field, C as CollectionConfig, P as Prettify, I as InferDocShape, S as SystemDocFields, A as AuthDocFields, U as UploadDocFields, G as GlobalConfig } from './app-BElen1tP.js';
2
+ export { a as AccessFunction, b as AdminConfig, c as AuthenticatedUser, B as BaseDocument, d as Block, e as CollectionAfterChangeHook, f as CollectionAfterDeleteHook, g as CollectionAfterReadHook, h as CollectionBeforeChangeHook, i as CollectionBeforeDeleteHook, j as CollectionBeforeReadHook, k as DatabaseAdapter, l as DynamicOptionItem, m as DynamicOptionsConfig, n as DynamicOptionsResolver, o as DynamicOptionsResolverArgs, p as DyrectedContext, q as FieldAfterReadHook, r as FieldBeforeChangeHook, s as FieldHook, t as FieldType, u as FileData, v as GlobalAfterChangeHook, w as GlobalAfterReadHook, x as GlobalBeforeChangeHook, y as GlobalBeforeReadHook, H as HookFunction, z as HookRequestContext, E as ImageService, J as PaginatedResult, K as StorageAdapter, L as UploadConfig, M as createDyrectedApp } from './app-BElen1tP.js';
3
3
  import 'hono/types';
4
4
  import 'hono';
5
5
 
@@ -84,17 +84,133 @@ declare function parseSqlWhere(where: WhereClause, getJsonField: (field: string)
84
84
  */
85
85
  declare function parseMongoWhere(where: WhereClause): Record<string, any>;
86
86
 
87
+ type AnyHookFn = (args: any) => any;
87
88
  /**
88
- * Define a collection configuration with full type safety.
89
+ * Run a list of hook functions sequentially.
90
+ *
91
+ * Each hook receives the output of the previous hook merged back into the
92
+ * original `args`. When a hook returns a non-undefined value it becomes the
93
+ * `data` / `doc` for the next hook in the chain.
94
+ *
95
+ * Pass `{ isolated: true }` for hooks that run **after** a DB write has already
96
+ * been committed (`afterChange`, `afterDelete`). In isolated mode each hook is
97
+ * wrapped in a try/catch so a failing side-effect (email, webhook, etc.) never
98
+ * surfaces as an HTTP 500 to the caller — the write already succeeded.
99
+ */
100
+ declare function runCollectionHooks(hooks: AnyHookFn[] | undefined, args: {
101
+ data?: unknown;
102
+ doc?: unknown;
103
+ user?: unknown;
104
+ req?: unknown;
105
+ operation?: "create" | "update" | "delete";
106
+ [key: string]: unknown;
107
+ }, options?: {
108
+ isolated?: boolean;
109
+ }): Promise<any>;
110
+ /**
111
+ * Execute field-level `beforeChange` hooks recursively on a data payload.
112
+ *
113
+ * Traverses `array`, `object`, and `blocks` fields depth-first so that nested
114
+ * field hooks fire on every item automatically.
115
+ */
116
+ declare function executeFieldBeforeChange(fields: Field[], data: Record<string, unknown>, originalDoc: Record<string, unknown> | null, user: unknown): Promise<Record<string, unknown>>;
117
+ /**
118
+ * Execute field-level `afterRead` hooks recursively on a document.
119
+ *
120
+ * Traverses `array`, `object`, and `blocks` fields depth-first so that nested
121
+ * field hooks fire on every item automatically.
122
+ */
123
+ declare function executeFieldAfterRead(fields: Field[], doc: Record<string, unknown>, user: unknown): Promise<Record<string, unknown>>;
124
+
125
+ /**
126
+ * Define a collection. When called without an explicit type argument, TypeScript
127
+ * automatically infers the document shape from the `fields` array you provide —
128
+ * no manual interface required:
129
+ *
130
+ * ```ts
131
+ * export const Posts = defineCollection({
132
+ * slug: 'posts',
133
+ * fields: [
134
+ * { name: 'title', type: 'text', required: true },
135
+ * { name: 'status', type: 'select', options: ['draft', 'published'], required: true },
136
+ * ],
137
+ * hooks: {
138
+ * beforeChange: [({ data }) => {
139
+ * // data is { title: string; status: 'draft' | 'published' } — fully inferred
140
+ * }],
141
+ * },
142
+ * })
143
+ * ```
144
+ *
145
+ * When you need a richer interface (e.g. with methods, JSDoc, or types that
146
+ * can't be derived from fields), pass it explicitly:
147
+ *
148
+ * ```ts
149
+ * interface Post { id: string; title: string; status: 'draft' | 'published' }
150
+ *
151
+ * export const Posts = defineCollection<Post>({ ... })
152
+ * ```
89
153
  */
90
- declare function defineCollection(config: CollectionConfig): CollectionConfig;
154
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
155
+ id: string;
156
+ } & InferDocShape<TFields> & SystemDocFields & AuthDocFields>>, 'fields' | 'auth'> & {
157
+ fields: TFields;
158
+ auth: true;
159
+ }): CollectionConfig<Prettify<{
160
+ id: string;
161
+ } & InferDocShape<TFields> & SystemDocFields & AuthDocFields>>;
162
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
163
+ id: string;
164
+ } & InferDocShape<TFields> & SystemDocFields & UploadDocFields>>, 'fields' | 'upload'> & {
165
+ fields: TFields;
166
+ upload: true;
167
+ }): CollectionConfig<Prettify<{
168
+ id: string;
169
+ } & InferDocShape<TFields> & SystemDocFields & UploadDocFields>>;
170
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
171
+ id: string;
172
+ } & InferDocShape<TFields> & SystemDocFields>>, 'fields'> & {
173
+ fields: TFields;
174
+ }): CollectionConfig<Prettify<{
175
+ id: string;
176
+ } & InferDocShape<TFields> & SystemDocFields>>;
177
+ declare function defineCollection<TDoc extends object>(config: CollectionConfig<TDoc>): CollectionConfig<TDoc>;
91
178
  /**
92
- * Define a global configuration with full type safety.
179
+ * Define a global (singleton document). TypeScript automatically infers the
180
+ * document shape from the `fields` array, or you can pass an explicit type:
181
+ *
182
+ * ```ts
183
+ * // Inferred — no interface needed
184
+ * export const Settings = defineGlobal({
185
+ * slug: 'site-settings',
186
+ * fields: [
187
+ * { name: 'siteName', type: 'text', required: true },
188
+ * { name: 'maintenanceMode', type: 'boolean' },
189
+ * ],
190
+ * hooks: {
191
+ * afterChange: [({ doc }) => {
192
+ * // doc.siteName is string, doc.maintenanceMode is boolean | undefined
193
+ * if (doc.maintenanceMode) alertOnCall()
194
+ * }],
195
+ * },
196
+ * })
197
+ *
198
+ * // Explicit type
199
+ * interface SiteSettings { siteName: string; maintenanceMode?: boolean }
200
+ * export const Settings = defineGlobal<SiteSettings>({ ... })
201
+ * ```
93
202
  */
94
- declare function defineGlobal(config: GlobalConfig): GlobalConfig;
203
+ declare function defineGlobal<const TFields extends Field[]>(config: Omit<GlobalConfig<Prettify<InferDocShape<TFields>>>, 'fields'> & {
204
+ fields: TFields;
205
+ }): GlobalConfig<Prettify<InferDocShape<TFields>>>;
206
+ declare function defineGlobal<TDoc extends object>(config: GlobalConfig<TDoc>): GlobalConfig<TDoc>;
95
207
  /**
96
- * Define the main Dyrected configuration.
208
+ * Define the root Dyrected configuration.
209
+ *
210
+ * This is the single object passed to `createDyrectedApp`. It wires together
211
+ * the database adapter, collections, globals, storage, email, and all other
212
+ * server-level configuration.
97
213
  */
98
214
  declare function defineConfig(config: DyrectedConfig): DyrectedConfig;
99
215
 
100
- export { CollectionConfig, DyrectedConfig, GlobalConfig, type SetupPromptConfig, type SqlWhereResult, type WhereClause, type WhereOperator, type WhereOperatorName, defineCollection, defineConfig, defineGlobal, generateAIPrompt, generateFreshSetupPrompt, normalizeConfig, parseMongoWhere, parseSqlWhere };
216
+ export { AuthDocFields, CollectionConfig, DyrectedConfig, Field, GlobalConfig, InferDocShape, Prettify, type SetupPromptConfig, type SqlWhereResult, SystemDocFields, UploadDocFields, type WhereClause, type WhereOperator, type WhereOperatorName, defineCollection, defineConfig, defineGlobal, executeFieldAfterRead, executeFieldBeforeChange, generateAIPrompt, generateFreshSetupPrompt, normalizeConfig, parseMongoWhere, parseSqlWhere, runCollectionHooks };
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import {
2
2
  createDyrectedApp,
3
- normalizeConfig
4
- } from "./chunk-JJN4J5NS.js";
3
+ executeFieldAfterRead,
4
+ executeFieldBeforeChange,
5
+ normalizeConfig,
6
+ runCollectionHooks
7
+ } from "./chunk-YNJ3YC4N.js";
5
8
 
6
9
  // src/utils/setup-prompt.ts
7
10
  function buildEnvironmentSection(frameworkLabel, isSelfHosted, config) {
@@ -996,9 +999,12 @@ export {
996
999
  defineCollection,
997
1000
  defineConfig,
998
1001
  defineGlobal,
1002
+ executeFieldAfterRead,
1003
+ executeFieldBeforeChange,
999
1004
  generateAIPrompt,
1000
1005
  generateFreshSetupPrompt,
1001
1006
  normalizeConfig,
1002
1007
  parseMongoWhere,
1003
- parseSqlWhere
1008
+ parseSqlWhere,
1009
+ runCollectionHooks
1004
1010
  };