@gzl10/nexus-sdk 0.12.7 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,506 @@
1
+ import { L as LocalizedString, i as FieldDefinition } from '../field-CngHXora.js';
2
+ import { u as RolePermission, b as CollectionEntityDefinition, f as DagEntityDefinition, c as EventEntityDefinition, d as ConfigEntityDefinition } from '../entity-kPgsCMdR.js';
3
+ import 'knex';
4
+ import 'express';
5
+ import 'pino';
6
+
7
+ /**
8
+ * Collection Entity Configuration Types
9
+ *
10
+ * Types for configuring pre-defined entities from the collection.
11
+ */
12
+
13
+ /**
14
+ * Configuration options for collection entity factories.
15
+ *
16
+ * Allows basic customization without modifying entity structure:
17
+ * - Table naming (prefix or full override)
18
+ * - Labels for UI
19
+ * - CASL subject for authorization
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // With prefix
24
+ * createCommentsEntity({ tablePrefix: 'blog_' })
25
+ * // Result: table = 'blog_comments'
26
+ *
27
+ * // Full override
28
+ * createCommentsEntity({
29
+ * table: 'feedback',
30
+ * label: { en: 'Feedback', es: 'Retroalimentación' }
31
+ * })
32
+ * ```
33
+ */
34
+ interface CollectionEntityConfig {
35
+ /**
36
+ * Prefix to prepend to the default table name.
37
+ * Example: 'blog_' + 'comments' = 'blog_comments'
38
+ */
39
+ tablePrefix?: string;
40
+ /**
41
+ * Full table name override (ignores tablePrefix if set).
42
+ */
43
+ table?: string;
44
+ /**
45
+ * Override singular label for UI.
46
+ */
47
+ label?: LocalizedString;
48
+ /**
49
+ * Override plural label for UI.
50
+ */
51
+ labelPlural?: LocalizedString;
52
+ /**
53
+ * Override CASL subject for authorization.
54
+ * Default is auto-generated from entity name (e.g., 'NxComment').
55
+ */
56
+ caslSubject?: string;
57
+ /**
58
+ * Override route prefix for API endpoints.
59
+ * Default is auto-generated from table name.
60
+ */
61
+ routePrefix?: string;
62
+ }
63
+ /**
64
+ * Factory function type for creating configurable entities.
65
+ */
66
+ type EntityFactory<T> = (config?: CollectionEntityConfig) => T;
67
+
68
+ /**
69
+ * Default CASL permissions for polymorphic entities.
70
+ * - All users can read
71
+ * - Authenticated users can create (own)
72
+ * - Users can update/delete their own records
73
+ * - Admins can manage all
74
+ */
75
+ declare const polymorphicCaslPermissions: Record<string, RolePermission>;
76
+ /**
77
+ * Default CASL permissions for system entities.
78
+ * - Users can read their own
79
+ * - Admins can manage all
80
+ */
81
+ declare const systemCaslPermissions: Record<string, RolePermission>;
82
+ /**
83
+ * Default CASL permissions for workflow entities.
84
+ * - Users can read their own assignments/approvals
85
+ * - Users can update assigned to them
86
+ * - Admins can manage all
87
+ */
88
+ declare const workflowCaslPermissions: Record<string, RolePermission>;
89
+ /**
90
+ * Standard polymorphic fields for relating to any entity.
91
+ * Include these in entities that can be attached to multiple entity types.
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * fields: {
96
+ * id: idField,
97
+ * ...polymorphicFields,
98
+ * // entity-specific fields...
99
+ * }
100
+ * ```
101
+ */
102
+ declare const polymorphicFields: {
103
+ entity_type: FieldDefinition;
104
+ entity_id: FieldDefinition;
105
+ };
106
+ /** Supported entity definition types */
107
+ type ConfigurableEntity = CollectionEntityDefinition | DagEntityDefinition | EventEntityDefinition | ConfigEntityDefinition;
108
+ /**
109
+ * Applies configuration overrides to an entity definition.
110
+ *
111
+ * @param base - The base entity definition
112
+ * @param defaultTable - Default table name (used with tablePrefix)
113
+ * @param defaultSubject - Default CASL subject
114
+ * @param config - Optional configuration overrides
115
+ * @returns Modified entity definition
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * const base = { type: 'collection', table: 'nx_comments', ... }
120
+ * const configured = applyEntityConfig(base, 'comments', 'NxComment', {
121
+ * tablePrefix: 'blog_'
122
+ * })
123
+ * // Result: { table: 'blog_comments', casl: { subject: 'BlogComment' }, ... }
124
+ * ```
125
+ */
126
+ declare function applyEntityConfig<T extends ConfigurableEntity>(base: T, defaultTable: string, defaultSubject: string, config?: CollectionEntityConfig): T;
127
+ /**
128
+ * Creates a factory function for an entity definition.
129
+ *
130
+ * @param baseEntity - The base entity definition
131
+ * @param defaultTable - Default table name
132
+ * @param defaultSubject - Default CASL subject
133
+ * @returns Factory function that accepts optional config
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const baseComments = { type: 'collection', table: 'nx_comments', ... }
138
+ * export const createCommentsEntity = createEntityFactory(
139
+ * baseComments,
140
+ * 'comments',
141
+ * 'NxComment'
142
+ * )
143
+ *
144
+ * // Usage
145
+ * const entity = createCommentsEntity({ tablePrefix: 'blog_' })
146
+ * ```
147
+ */
148
+ declare function createEntityFactory<T extends ConfigurableEntity>(baseEntity: T, defaultTable: string, defaultSubject: string): (config?: CollectionEntityConfig) => T;
149
+
150
+ /**
151
+ * Comments Entity
152
+ *
153
+ * Polymorphic comments that can be attached to any entity.
154
+ * Supports threading via parent_id for nested replies.
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * // Use as-is
159
+ * import { commentsEntity } from '@gzl10/nexus-sdk/collection'
160
+ *
161
+ * // Or with custom table prefix
162
+ * import { createCommentsEntity } from '@gzl10/nexus-sdk/collection'
163
+ * const blogComments = createCommentsEntity({ tablePrefix: 'blog_' })
164
+ * ```
165
+ */
166
+
167
+ /**
168
+ * Pre-configured comments entity ready to use.
169
+ * Table: nx_comments
170
+ */
171
+ declare const commentsEntity: CollectionEntityDefinition;
172
+ /**
173
+ * Factory to create a comments entity with custom configuration.
174
+ *
175
+ * @param config - Optional configuration overrides
176
+ * @returns Configured comments entity definition
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * const blogComments = createCommentsEntity({ tablePrefix: 'blog_' })
181
+ * // Table: blog_comments, Subject: BlogComment
182
+ * ```
183
+ */
184
+ declare const createCommentsEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
185
+
186
+ /**
187
+ * Pre-configured attachments entity ready to use.
188
+ * Table: nx_attachments
189
+ */
190
+ declare const attachmentsEntity: CollectionEntityDefinition;
191
+ /**
192
+ * Factory to create an attachments entity with custom configuration.
193
+ */
194
+ declare const createAttachmentsEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
195
+
196
+ /**
197
+ * Tag-Entity pivot table for polymorphic associations.
198
+ * This entity links tags to any other entity.
199
+ */
200
+ declare const tagEntitiesEntity: CollectionEntityDefinition;
201
+ /**
202
+ * Pre-configured tags entity ready to use.
203
+ * Table: nx_tags (DAG with nx_tags_parents)
204
+ */
205
+ declare const tagsEntity: DagEntityDefinition;
206
+ /**
207
+ * Factory to create a tags entity with custom configuration.
208
+ */
209
+ declare const createTagsEntity: (config?: CollectionEntityConfig) => DagEntityDefinition;
210
+
211
+ /**
212
+ * Pre-configured notes entity ready to use.
213
+ * Table: nx_notes
214
+ */
215
+ declare const notesEntity: CollectionEntityDefinition;
216
+ /**
217
+ * Factory to create a notes entity with custom configuration.
218
+ */
219
+ declare const createNotesEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
220
+
221
+ /**
222
+ * Pre-configured favorites entity ready to use.
223
+ * Table: nx_favorites
224
+ */
225
+ declare const favoritesEntity: CollectionEntityDefinition;
226
+ /**
227
+ * Factory to create a favorites entity with custom configuration.
228
+ */
229
+ declare const createFavoritesEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
230
+
231
+ /**
232
+ * Pre-configured ratings entity ready to use.
233
+ * Table: nx_ratings
234
+ */
235
+ declare const ratingsEntity: CollectionEntityDefinition;
236
+ /**
237
+ * Factory to create a ratings entity with custom configuration.
238
+ */
239
+ declare const createRatingsEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
240
+
241
+ /**
242
+ * Standard reaction types.
243
+ */
244
+ declare const REACTION_TYPES: {
245
+ readonly LIKE: "like";
246
+ readonly LOVE: "love";
247
+ readonly HAHA: "haha";
248
+ readonly WOW: "wow";
249
+ readonly SAD: "sad";
250
+ readonly ANGRY: "angry";
251
+ readonly THUMBS_UP: "thumbs_up";
252
+ readonly THUMBS_DOWN: "thumbs_down";
253
+ readonly CELEBRATE: "celebrate";
254
+ readonly SUPPORT: "support";
255
+ };
256
+ /**
257
+ * Pre-configured reactions entity ready to use.
258
+ * Table: nx_reactions
259
+ */
260
+ declare const reactionsEntity: CollectionEntityDefinition;
261
+ /**
262
+ * Factory to create a reactions entity with custom configuration.
263
+ */
264
+ declare const createReactionsEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
265
+
266
+ /**
267
+ * Pre-configured mentions entity ready to use.
268
+ * Table: nx_mentions
269
+ */
270
+ declare const mentionsEntity: CollectionEntityDefinition;
271
+ /**
272
+ * Factory to create a mentions entity with custom configuration.
273
+ */
274
+ declare const createMentionsEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
275
+
276
+ /**
277
+ * Common option groups for quick reference.
278
+ */
279
+ declare const OPTION_GROUPS: {
280
+ readonly STATUS: "status";
281
+ readonly PRIORITY: "priority";
282
+ readonly CATEGORY: "category";
283
+ readonly TYPE: "type";
284
+ readonly LEVEL: "level";
285
+ readonly SIZE: "size";
286
+ readonly COLOR: "color";
287
+ };
288
+ /**
289
+ * Default seed data for common options.
290
+ * Use this to seed the options table manually if needed.
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * // In module seed function
295
+ * await ctx.db('nx_options').insert(DEFAULT_OPTIONS_SEED)
296
+ * ```
297
+ */
298
+ declare const DEFAULT_OPTIONS_SEED: {
299
+ id: string;
300
+ option_group: string;
301
+ value: string;
302
+ label: string;
303
+ color: string;
304
+ icon: string;
305
+ order: number;
306
+ is_default: boolean;
307
+ is_active: boolean;
308
+ }[];
309
+ /**
310
+ * Pre-configured options entity ready to use.
311
+ * Table: nx_options
312
+ *
313
+ * Includes seed data for common statuses and priorities.
314
+ */
315
+ declare const optionsEntity: CollectionEntityDefinition;
316
+ /**
317
+ * Factory to create an options entity with custom configuration.
318
+ *
319
+ * @example
320
+ * ```typescript
321
+ * // For a CRM module
322
+ * const crmOptions = createOptionsEntity({ tablePrefix: 'crm_' })
323
+ * // Table: crm_options
324
+ * ```
325
+ */
326
+ declare const createOptionsEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
327
+ /**
328
+ * Helper to create field options that reference this entity.
329
+ *
330
+ * @param group - The option_group to filter by
331
+ * @param module - Module name (default: 'collection')
332
+ * @param entity - Entity route (default: 'nx-options')
333
+ *
334
+ * @example
335
+ * ```typescript
336
+ * status: {
337
+ * input: 'select',
338
+ * options: dynamicOptions('status')
339
+ * }
340
+ * ```
341
+ */
342
+ declare function dynamicOptions(group: string, module?: string, entity?: string): {
343
+ endpoint: string;
344
+ filter: {
345
+ option_group: string;
346
+ is_active: boolean;
347
+ };
348
+ valueField: string;
349
+ labelField: string;
350
+ sortField: string;
351
+ };
352
+
353
+ /**
354
+ * Common activity types.
355
+ */
356
+ declare const ACTIVITY_TYPES: {
357
+ readonly LOGIN: "auth.login";
358
+ readonly LOGOUT: "auth.logout";
359
+ readonly PASSWORD_CHANGE: "auth.password_change";
360
+ readonly CREATE: "data.create";
361
+ readonly UPDATE: "data.update";
362
+ readonly DELETE: "data.delete";
363
+ readonly EXPORT: "system.export";
364
+ readonly IMPORT: "system.import";
365
+ readonly CONFIG_CHANGE: "system.config_change";
366
+ readonly CUSTOM: "custom";
367
+ };
368
+ /**
369
+ * Pre-configured activity log entity ready to use.
370
+ * Table: nx_activity_log
371
+ */
372
+ declare const activityLogEntity: EventEntityDefinition;
373
+ /**
374
+ * Factory to create an activity log entity with custom configuration.
375
+ */
376
+ declare const createActivityLogEntity: (config?: CollectionEntityConfig) => EventEntityDefinition;
377
+
378
+ /**
379
+ * Common notification types.
380
+ */
381
+ declare const NOTIFICATION_TYPES: {
382
+ readonly INFO: "info";
383
+ readonly SUCCESS: "success";
384
+ readonly WARNING: "warning";
385
+ readonly ERROR: "error";
386
+ readonly MENTION: "mention";
387
+ readonly ASSIGNMENT: "assignment";
388
+ readonly REMINDER: "reminder";
389
+ readonly SYSTEM: "system";
390
+ };
391
+ /**
392
+ * Pre-configured notifications entity ready to use.
393
+ * Table: nx_notifications
394
+ */
395
+ declare const notificationsEntity: CollectionEntityDefinition;
396
+ /**
397
+ * Factory to create a notifications entity with custom configuration.
398
+ */
399
+ declare const createNotificationsEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
400
+
401
+ /**
402
+ * Common preference keys.
403
+ */
404
+ declare const PREFERENCE_KEYS: {
405
+ readonly THEME: "theme";
406
+ readonly LANGUAGE: "language";
407
+ readonly TIMEZONE: "timezone";
408
+ readonly SIDEBAR_COLLAPSED: "sidebar_collapsed";
409
+ readonly NOTIFICATIONS_ENABLED: "notifications_enabled";
410
+ readonly EMAIL_DIGEST: "email_digest";
411
+ };
412
+ /**
413
+ * Pre-configured preferences entity ready to use.
414
+ * Table: nx_preferences
415
+ */
416
+ declare const preferencesEntity: CollectionEntityDefinition;
417
+ /**
418
+ * Factory to create a preferences entity with custom configuration.
419
+ */
420
+ declare const createPreferencesEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
421
+
422
+ /**
423
+ * Common schedule frequencies.
424
+ */
425
+ declare const SCHEDULE_FREQUENCIES: {
426
+ readonly EVERY_MINUTE: "* * * * *";
427
+ readonly EVERY_5_MINUTES: "*/5 * * * *";
428
+ readonly EVERY_15_MINUTES: "*/15 * * * *";
429
+ readonly EVERY_HOUR: "0 * * * *";
430
+ readonly EVERY_DAY_MIDNIGHT: "0 0 * * *";
431
+ readonly EVERY_DAY_6AM: "0 6 * * *";
432
+ readonly EVERY_MONDAY: "0 0 * * 1";
433
+ readonly EVERY_MONTH_1ST: "0 0 1 * *";
434
+ };
435
+ /**
436
+ * Pre-configured schedules entity ready to use.
437
+ * Table: nx_schedules
438
+ */
439
+ declare const schedulesEntity: CollectionEntityDefinition;
440
+ /**
441
+ * Factory to create a schedules entity with custom configuration.
442
+ */
443
+ declare const createSchedulesEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
444
+
445
+ /**
446
+ * Common webhook events.
447
+ */
448
+ declare const WEBHOOK_EVENTS: {
449
+ readonly CREATED: "created";
450
+ readonly UPDATED: "updated";
451
+ readonly DELETED: "deleted";
452
+ readonly PUBLISHED: "published";
453
+ readonly ARCHIVED: "archived";
454
+ readonly STATUS_CHANGED: "status_changed";
455
+ };
456
+ /**
457
+ * Pre-configured webhooks entity ready to use.
458
+ * Table: nx_webhooks
459
+ */
460
+ declare const webhooksEntity: CollectionEntityDefinition;
461
+ /**
462
+ * Factory to create a webhooks entity with custom configuration.
463
+ */
464
+ declare const createWebhooksEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
465
+
466
+ /**
467
+ * Approval status values.
468
+ */
469
+ declare const APPROVAL_STATUS: {
470
+ readonly PENDING: "pending";
471
+ readonly APPROVED: "approved";
472
+ readonly REJECTED: "rejected";
473
+ readonly CANCELLED: "cancelled";
474
+ readonly EXPIRED: "expired";
475
+ };
476
+ /**
477
+ * Pre-configured approvals entity ready to use.
478
+ * Table: nx_approvals
479
+ */
480
+ declare const approvalsEntity: CollectionEntityDefinition;
481
+ /**
482
+ * Factory to create an approvals entity with custom configuration.
483
+ */
484
+ declare const createApprovalsEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
485
+
486
+ /**
487
+ * Assignment role types.
488
+ */
489
+ declare const ASSIGNMENT_ROLES: {
490
+ readonly OWNER: "owner";
491
+ readonly ASSIGNEE: "assignee";
492
+ readonly REVIEWER: "reviewer";
493
+ readonly COLLABORATOR: "collaborator";
494
+ readonly WATCHER: "watcher";
495
+ };
496
+ /**
497
+ * Pre-configured assignments entity ready to use.
498
+ * Table: nx_assignments
499
+ */
500
+ declare const assignmentsEntity: CollectionEntityDefinition;
501
+ /**
502
+ * Factory to create an assignments entity with custom configuration.
503
+ */
504
+ declare const createAssignmentsEntity: (config?: CollectionEntityConfig) => CollectionEntityDefinition;
505
+
506
+ export { ACTIVITY_TYPES, APPROVAL_STATUS, ASSIGNMENT_ROLES, type CollectionEntityConfig, DEFAULT_OPTIONS_SEED, type EntityFactory, NOTIFICATION_TYPES, OPTION_GROUPS, PREFERENCE_KEYS, REACTION_TYPES, SCHEDULE_FREQUENCIES, WEBHOOK_EVENTS, activityLogEntity, applyEntityConfig, approvalsEntity, assignmentsEntity, attachmentsEntity, commentsEntity, createActivityLogEntity, createApprovalsEntity, createAssignmentsEntity, createAttachmentsEntity, createCommentsEntity, createEntityFactory, createFavoritesEntity, createMentionsEntity, createNotesEntity, createNotificationsEntity, createOptionsEntity, createPreferencesEntity, createRatingsEntity, createReactionsEntity, createSchedulesEntity, createTagsEntity, createWebhooksEntity, dynamicOptions, favoritesEntity, mentionsEntity, notesEntity, notificationsEntity, optionsEntity, polymorphicCaslPermissions, polymorphicFields, preferencesEntity, ratingsEntity, reactionsEntity, schedulesEntity, systemCaslPermissions, tagEntitiesEntity, tagsEntity, webhooksEntity, workflowCaslPermissions };