@dyrected/core 2.5.14 → 2.5.16

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 (48) hide show
  1. package/dist/app-B2tg7Djj.d.cts +1575 -0
  2. package/dist/app-B2tg7Djj.d.ts +1575 -0
  3. package/dist/app-Bh4_Opv0.d.cts +1522 -0
  4. package/dist/app-Bh4_Opv0.d.ts +1522 -0
  5. package/dist/app-Bv9gaDAN.d.cts +561 -0
  6. package/dist/app-Bv9gaDAN.d.ts +561 -0
  7. package/dist/app-BvG3bRc8.d.cts +419 -0
  8. package/dist/app-BvG3bRc8.d.ts +419 -0
  9. package/dist/app-C3B9N1KR.d.cts +1522 -0
  10. package/dist/app-C3B9N1KR.d.ts +1522 -0
  11. package/dist/app-DDJJa0ep.d.cts +1621 -0
  12. package/dist/app-DDJJa0ep.d.ts +1621 -0
  13. package/dist/app-DO1s9YW1.d.cts +1621 -0
  14. package/dist/app-DO1s9YW1.d.ts +1621 -0
  15. package/dist/app-DTP3-9PJ.d.cts +561 -0
  16. package/dist/app-DTP3-9PJ.d.ts +561 -0
  17. package/dist/app-DbKDGYTI.d.cts +566 -0
  18. package/dist/app-DbKDGYTI.d.ts +566 -0
  19. package/dist/app-DqRO-CMi.d.cts +1457 -0
  20. package/dist/app-DqRO-CMi.d.ts +1457 -0
  21. package/dist/app-DvaFpOtj.d.cts +398 -0
  22. package/dist/app-DvaFpOtj.d.ts +398 -0
  23. package/dist/app-FGzip4XM.d.cts +1563 -0
  24. package/dist/app-FGzip4XM.d.ts +1563 -0
  25. package/dist/app-T0alZAE0.d.cts +383 -0
  26. package/dist/app-T0alZAE0.d.ts +383 -0
  27. package/dist/app-oQt5-9MU.d.cts +1560 -0
  28. package/dist/app-oQt5-9MU.d.ts +1560 -0
  29. package/dist/app-rZj1VFer.d.cts +1621 -0
  30. package/dist/app-rZj1VFer.d.ts +1621 -0
  31. package/dist/app-wo82JRHl.d.cts +445 -0
  32. package/dist/app-wo82JRHl.d.ts +445 -0
  33. package/dist/chunk-23URSKPI.js +2371 -0
  34. package/dist/chunk-2JMA3M5S.js +2475 -0
  35. package/dist/chunk-3FZEUK36.js +2470 -0
  36. package/dist/chunk-DOJHZ7XN.js +2394 -0
  37. package/dist/chunk-PKNFV7KE.js +2469 -0
  38. package/dist/chunk-UBTRANFX.js +2476 -0
  39. package/dist/chunk-W6KURRMW.js +2471 -0
  40. package/dist/index.cjs +457 -48
  41. package/dist/index.d.cts +117 -8
  42. package/dist/index.d.ts +117 -8
  43. package/dist/index.js +9 -3
  44. package/dist/server.cjs +449 -46
  45. package/dist/server.d.cts +57 -15
  46. package/dist/server.d.ts +57 -15
  47. package/dist/server.js +1 -1
  48. 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-DO1s9YW1.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-DO1s9YW1.cjs';
3
3
  import 'hono/types';
4
4
  import 'hono';
5
5
 
@@ -84,17 +84,126 @@ 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.
89
94
  */
90
- declare function defineCollection(config: CollectionConfig): CollectionConfig;
95
+ declare function runCollectionHooks(hooks: AnyHookFn[] | undefined, args: {
96
+ data?: unknown;
97
+ doc?: unknown;
98
+ user?: unknown;
99
+ req?: unknown;
100
+ operation?: "create" | "update" | "delete";
101
+ [key: string]: unknown;
102
+ }): Promise<any>;
91
103
  /**
92
- * Define a global configuration with full type safety.
104
+ * Execute field-level `beforeChange` hooks recursively on a data payload.
105
+ *
106
+ * Traverses `array`, `object`, and `blocks` fields depth-first so that nested
107
+ * field hooks fire on every item automatically.
93
108
  */
94
- declare function defineGlobal(config: GlobalConfig): GlobalConfig;
109
+ declare function executeFieldBeforeChange(fields: Field[], data: Record<string, unknown>, originalDoc: Record<string, unknown> | null, user: unknown): Promise<Record<string, unknown>>;
95
110
  /**
96
- * Define the main Dyrected configuration.
111
+ * Execute field-level `afterRead` hooks recursively on a document.
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 executeFieldAfterRead(fields: Field[], doc: Record<string, unknown>, user: unknown): Promise<Record<string, unknown>>;
117
+
118
+ /**
119
+ * Define a collection. When called without an explicit type argument, TypeScript
120
+ * automatically infers the document shape from the `fields` array you provide —
121
+ * no manual interface required:
122
+ *
123
+ * ```ts
124
+ * export const Posts = defineCollection({
125
+ * slug: 'posts',
126
+ * fields: [
127
+ * { name: 'title', type: 'text', required: true },
128
+ * { name: 'status', type: 'select', options: ['draft', 'published'], required: true },
129
+ * ],
130
+ * hooks: {
131
+ * beforeChange: [({ data }) => {
132
+ * // data is { title: string; status: 'draft' | 'published' } — fully inferred
133
+ * }],
134
+ * },
135
+ * })
136
+ * ```
137
+ *
138
+ * When you need a richer interface (e.g. with methods, JSDoc, or types that
139
+ * can't be derived from fields), pass it explicitly:
140
+ *
141
+ * ```ts
142
+ * interface Post { id: string; title: string; status: 'draft' | 'published' }
143
+ *
144
+ * export const Posts = defineCollection<Post>({ ... })
145
+ * ```
146
+ */
147
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
148
+ id: string;
149
+ } & InferDocShape<TFields> & SystemDocFields & AuthDocFields>>, 'fields' | 'auth'> & {
150
+ fields: TFields;
151
+ auth: true;
152
+ }): CollectionConfig<Prettify<{
153
+ id: string;
154
+ } & InferDocShape<TFields> & SystemDocFields & AuthDocFields>>;
155
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
156
+ id: string;
157
+ } & InferDocShape<TFields> & SystemDocFields & UploadDocFields>>, 'fields' | 'upload'> & {
158
+ fields: TFields;
159
+ upload: true;
160
+ }): CollectionConfig<Prettify<{
161
+ id: string;
162
+ } & InferDocShape<TFields> & SystemDocFields & UploadDocFields>>;
163
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
164
+ id: string;
165
+ } & InferDocShape<TFields> & SystemDocFields>>, 'fields'> & {
166
+ fields: TFields;
167
+ }): CollectionConfig<Prettify<{
168
+ id: string;
169
+ } & InferDocShape<TFields> & SystemDocFields>>;
170
+ declare function defineCollection<TDoc extends object>(config: CollectionConfig<TDoc>): CollectionConfig<TDoc>;
171
+ /**
172
+ * Define a global (singleton document). TypeScript automatically infers the
173
+ * document shape from the `fields` array, or you can pass an explicit type:
174
+ *
175
+ * ```ts
176
+ * // Inferred — no interface needed
177
+ * export const Settings = defineGlobal({
178
+ * slug: 'site-settings',
179
+ * fields: [
180
+ * { name: 'siteName', type: 'text', required: true },
181
+ * { name: 'maintenanceMode', type: 'boolean' },
182
+ * ],
183
+ * hooks: {
184
+ * afterChange: [({ doc }) => {
185
+ * // doc.siteName is string, doc.maintenanceMode is boolean | undefined
186
+ * if (doc.maintenanceMode) alertOnCall()
187
+ * }],
188
+ * },
189
+ * })
190
+ *
191
+ * // Explicit type
192
+ * interface SiteSettings { siteName: string; maintenanceMode?: boolean }
193
+ * export const Settings = defineGlobal<SiteSettings>({ ... })
194
+ * ```
195
+ */
196
+ declare function defineGlobal<const TFields extends Field[]>(config: Omit<GlobalConfig<Prettify<InferDocShape<TFields>>>, 'fields'> & {
197
+ fields: TFields;
198
+ }): GlobalConfig<Prettify<InferDocShape<TFields>>>;
199
+ declare function defineGlobal<TDoc extends object>(config: GlobalConfig<TDoc>): GlobalConfig<TDoc>;
200
+ /**
201
+ * Define the root Dyrected configuration.
202
+ *
203
+ * This is the single object passed to `createDyrectedApp`. It wires together
204
+ * the database adapter, collections, globals, storage, email, and all other
205
+ * server-level configuration.
97
206
  */
98
207
  declare function defineConfig(config: DyrectedConfig): DyrectedConfig;
99
208
 
100
- export { CollectionConfig, DyrectedConfig, GlobalConfig, type SetupPromptConfig, type SqlWhereResult, type WhereClause, type WhereOperator, type WhereOperatorName, defineCollection, defineConfig, defineGlobal, generateAIPrompt, generateFreshSetupPrompt, normalizeConfig, parseMongoWhere, parseSqlWhere };
209
+ 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-DO1s9YW1.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-DO1s9YW1.js';
3
3
  import 'hono/types';
4
4
  import 'hono';
5
5
 
@@ -84,17 +84,126 @@ 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.
89
94
  */
90
- declare function defineCollection(config: CollectionConfig): CollectionConfig;
95
+ declare function runCollectionHooks(hooks: AnyHookFn[] | undefined, args: {
96
+ data?: unknown;
97
+ doc?: unknown;
98
+ user?: unknown;
99
+ req?: unknown;
100
+ operation?: "create" | "update" | "delete";
101
+ [key: string]: unknown;
102
+ }): Promise<any>;
91
103
  /**
92
- * Define a global configuration with full type safety.
104
+ * Execute field-level `beforeChange` hooks recursively on a data payload.
105
+ *
106
+ * Traverses `array`, `object`, and `blocks` fields depth-first so that nested
107
+ * field hooks fire on every item automatically.
93
108
  */
94
- declare function defineGlobal(config: GlobalConfig): GlobalConfig;
109
+ declare function executeFieldBeforeChange(fields: Field[], data: Record<string, unknown>, originalDoc: Record<string, unknown> | null, user: unknown): Promise<Record<string, unknown>>;
95
110
  /**
96
- * Define the main Dyrected configuration.
111
+ * Execute field-level `afterRead` hooks recursively on a document.
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 executeFieldAfterRead(fields: Field[], doc: Record<string, unknown>, user: unknown): Promise<Record<string, unknown>>;
117
+
118
+ /**
119
+ * Define a collection. When called without an explicit type argument, TypeScript
120
+ * automatically infers the document shape from the `fields` array you provide —
121
+ * no manual interface required:
122
+ *
123
+ * ```ts
124
+ * export const Posts = defineCollection({
125
+ * slug: 'posts',
126
+ * fields: [
127
+ * { name: 'title', type: 'text', required: true },
128
+ * { name: 'status', type: 'select', options: ['draft', 'published'], required: true },
129
+ * ],
130
+ * hooks: {
131
+ * beforeChange: [({ data }) => {
132
+ * // data is { title: string; status: 'draft' | 'published' } — fully inferred
133
+ * }],
134
+ * },
135
+ * })
136
+ * ```
137
+ *
138
+ * When you need a richer interface (e.g. with methods, JSDoc, or types that
139
+ * can't be derived from fields), pass it explicitly:
140
+ *
141
+ * ```ts
142
+ * interface Post { id: string; title: string; status: 'draft' | 'published' }
143
+ *
144
+ * export const Posts = defineCollection<Post>({ ... })
145
+ * ```
146
+ */
147
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
148
+ id: string;
149
+ } & InferDocShape<TFields> & SystemDocFields & AuthDocFields>>, 'fields' | 'auth'> & {
150
+ fields: TFields;
151
+ auth: true;
152
+ }): CollectionConfig<Prettify<{
153
+ id: string;
154
+ } & InferDocShape<TFields> & SystemDocFields & AuthDocFields>>;
155
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
156
+ id: string;
157
+ } & InferDocShape<TFields> & SystemDocFields & UploadDocFields>>, 'fields' | 'upload'> & {
158
+ fields: TFields;
159
+ upload: true;
160
+ }): CollectionConfig<Prettify<{
161
+ id: string;
162
+ } & InferDocShape<TFields> & SystemDocFields & UploadDocFields>>;
163
+ declare function defineCollection<const TFields extends Field[]>(config: Omit<CollectionConfig<Prettify<{
164
+ id: string;
165
+ } & InferDocShape<TFields> & SystemDocFields>>, 'fields'> & {
166
+ fields: TFields;
167
+ }): CollectionConfig<Prettify<{
168
+ id: string;
169
+ } & InferDocShape<TFields> & SystemDocFields>>;
170
+ declare function defineCollection<TDoc extends object>(config: CollectionConfig<TDoc>): CollectionConfig<TDoc>;
171
+ /**
172
+ * Define a global (singleton document). TypeScript automatically infers the
173
+ * document shape from the `fields` array, or you can pass an explicit type:
174
+ *
175
+ * ```ts
176
+ * // Inferred — no interface needed
177
+ * export const Settings = defineGlobal({
178
+ * slug: 'site-settings',
179
+ * fields: [
180
+ * { name: 'siteName', type: 'text', required: true },
181
+ * { name: 'maintenanceMode', type: 'boolean' },
182
+ * ],
183
+ * hooks: {
184
+ * afterChange: [({ doc }) => {
185
+ * // doc.siteName is string, doc.maintenanceMode is boolean | undefined
186
+ * if (doc.maintenanceMode) alertOnCall()
187
+ * }],
188
+ * },
189
+ * })
190
+ *
191
+ * // Explicit type
192
+ * interface SiteSettings { siteName: string; maintenanceMode?: boolean }
193
+ * export const Settings = defineGlobal<SiteSettings>({ ... })
194
+ * ```
195
+ */
196
+ declare function defineGlobal<const TFields extends Field[]>(config: Omit<GlobalConfig<Prettify<InferDocShape<TFields>>>, 'fields'> & {
197
+ fields: TFields;
198
+ }): GlobalConfig<Prettify<InferDocShape<TFields>>>;
199
+ declare function defineGlobal<TDoc extends object>(config: GlobalConfig<TDoc>): GlobalConfig<TDoc>;
200
+ /**
201
+ * Define the root Dyrected configuration.
202
+ *
203
+ * This is the single object passed to `createDyrectedApp`. It wires together
204
+ * the database adapter, collections, globals, storage, email, and all other
205
+ * server-level configuration.
97
206
  */
98
207
  declare function defineConfig(config: DyrectedConfig): DyrectedConfig;
99
208
 
100
- export { CollectionConfig, DyrectedConfig, GlobalConfig, type SetupPromptConfig, type SqlWhereResult, type WhereClause, type WhereOperator, type WhereOperatorName, defineCollection, defineConfig, defineGlobal, generateAIPrompt, generateFreshSetupPrompt, normalizeConfig, parseMongoWhere, parseSqlWhere };
209
+ 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-2JMA3M5S.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
  };