@object-ui/types 0.3.1 → 0.5.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.
Files changed (97) hide show
  1. package/dist/app.d.ts +10 -0
  2. package/dist/app.d.ts.map +1 -1
  3. package/dist/blocks.d.ts +332 -0
  4. package/dist/blocks.d.ts.map +1 -0
  5. package/dist/blocks.js +8 -0
  6. package/dist/crud.d.ts +174 -3
  7. package/dist/crud.d.ts.map +1 -1
  8. package/dist/data-protocol.d.ts +1268 -0
  9. package/dist/data-protocol.d.ts.map +1 -0
  10. package/dist/data-protocol.js +8 -0
  11. package/dist/data.d.ts +6 -1
  12. package/dist/data.d.ts.map +1 -1
  13. package/dist/field-types.d.ts +353 -11
  14. package/dist/field-types.d.ts.map +1 -1
  15. package/dist/index.d.ts +28 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/objectql.d.ts +8 -1
  18. package/dist/objectql.d.ts.map +1 -1
  19. package/dist/plugin-scope.d.ts +194 -0
  20. package/dist/plugin-scope.d.ts.map +1 -0
  21. package/dist/plugin-scope.js +8 -0
  22. package/dist/reports.d.ts +336 -0
  23. package/dist/reports.d.ts.map +1 -0
  24. package/dist/reports.js +8 -0
  25. package/dist/theme.d.ts +289 -0
  26. package/dist/theme.d.ts.map +1 -0
  27. package/dist/theme.js +8 -0
  28. package/dist/ui-action.d.ts +175 -0
  29. package/dist/ui-action.d.ts.map +1 -0
  30. package/dist/ui-action.js +8 -0
  31. package/dist/views.d.ts +417 -0
  32. package/dist/views.d.ts.map +1 -0
  33. package/dist/views.js +8 -0
  34. package/dist/zod/app.zod.d.ts +120 -0
  35. package/dist/zod/app.zod.d.ts.map +1 -0
  36. package/dist/zod/app.zod.js +60 -0
  37. package/dist/zod/blocks.zod.d.ts +834 -0
  38. package/dist/zod/blocks.zod.d.ts.map +1 -0
  39. package/dist/zod/blocks.zod.js +145 -0
  40. package/dist/zod/complex.zod.js +1 -1
  41. package/dist/zod/crud.zod.d.ts +598 -0
  42. package/dist/zod/crud.zod.d.ts.map +1 -0
  43. package/dist/zod/crud.zod.js +230 -0
  44. package/dist/zod/data-display.zod.js +1 -1
  45. package/dist/zod/disclosure.zod.js +1 -1
  46. package/dist/zod/feedback.zod.js +1 -1
  47. package/dist/zod/form.zod.js +1 -1
  48. package/dist/zod/index.zod.d.ts +1829 -18
  49. package/dist/zod/index.zod.d.ts.map +1 -1
  50. package/dist/zod/index.zod.js +96 -19
  51. package/dist/zod/layout.zod.d.ts +2 -2
  52. package/dist/zod/layout.zod.js +1 -1
  53. package/dist/zod/navigation.zod.js +1 -1
  54. package/dist/zod/objectql.zod.d.ts +10 -10
  55. package/dist/zod/objectql.zod.js +1 -1
  56. package/dist/zod/overlay.zod.js +1 -1
  57. package/dist/zod/reports.zod.d.ts +1628 -0
  58. package/dist/zod/reports.zod.d.ts.map +1 -0
  59. package/dist/zod/reports.zod.js +152 -0
  60. package/dist/zod/theme.zod.d.ts +611 -0
  61. package/dist/zod/theme.zod.d.ts.map +1 -0
  62. package/dist/zod/theme.zod.js +130 -0
  63. package/dist/zod/views.zod.d.ts +675 -0
  64. package/dist/zod/views.zod.d.ts.map +1 -0
  65. package/dist/zod/views.zod.js +159 -0
  66. package/package.json +2 -2
  67. package/src/__tests__/namespace-exports.test.ts +80 -0
  68. package/src/__tests__/phase2-schemas.test.ts +639 -0
  69. package/src/app.ts +12 -0
  70. package/src/blocks.ts +405 -0
  71. package/src/crud.ts +177 -3
  72. package/src/data-protocol.ts +1679 -0
  73. package/src/data.ts +3 -1
  74. package/src/field-types.ts +392 -11
  75. package/src/index.ts +214 -0
  76. package/src/objectql.ts +9 -1
  77. package/src/plugin-scope.ts +210 -0
  78. package/src/reports.ts +408 -0
  79. package/src/theme.ts +351 -0
  80. package/src/ui-action.ts +276 -0
  81. package/src/views.ts +429 -0
  82. package/src/zod/app.zod.ts +72 -0
  83. package/src/zod/blocks.zod.ts +170 -0
  84. package/src/zod/complex.zod.ts +1 -1
  85. package/src/zod/crud.zod.ts +259 -0
  86. package/src/zod/data-display.zod.ts +1 -1
  87. package/src/zod/disclosure.zod.ts +1 -1
  88. package/src/zod/feedback.zod.ts +1 -1
  89. package/src/zod/form.zod.ts +1 -1
  90. package/src/zod/index.zod.ts +167 -19
  91. package/src/zod/layout.zod.ts +1 -1
  92. package/src/zod/navigation.zod.ts +1 -1
  93. package/src/zod/objectql.zod.ts +1 -1
  94. package/src/zod/overlay.zod.ts +1 -1
  95. package/src/zod/reports.zod.ts +183 -0
  96. package/src/zod/theme.zod.ts +155 -0
  97. package/src/zod/views.zod.ts +182 -0
@@ -0,0 +1,1679 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ /**
10
+ * @object-ui/types - Data Protocol Advanced Types
11
+ *
12
+ * Phase 3: Complete implementation of QuerySchema, FilterSchema,
13
+ * ValidationSchema, DriverInterface, and DatasourceSchema.
14
+ *
15
+ * @module data-protocol
16
+ * @packageDocumentation
17
+ */
18
+
19
+ // Import existing base types to avoid duplication
20
+ import type { SortConfig as BaseSortConfig } from './objectql';
21
+ import type { FilterOperator as BaseFilterOperator } from './complex';
22
+
23
+ /**
24
+ * =============================================================================
25
+ * Phase 3.3: QuerySchema AST Implementation
26
+ * =============================================================================
27
+ */
28
+
29
+ /**
30
+ * Query AST Node Types
31
+ */
32
+ export type QueryASTNodeType =
33
+ | 'select'
34
+ | 'from'
35
+ | 'where'
36
+ | 'join'
37
+ | 'group_by'
38
+ | 'order_by'
39
+ | 'limit'
40
+ | 'offset'
41
+ | 'subquery'
42
+ | 'aggregate'
43
+ | 'window'
44
+ | 'field'
45
+ | 'literal'
46
+ | 'operator'
47
+ | 'function';
48
+
49
+ /**
50
+ * Base Query AST Node
51
+ */
52
+ export interface QueryASTNode {
53
+ type: QueryASTNodeType;
54
+ [key: string]: any;
55
+ }
56
+
57
+ /**
58
+ * SELECT clause node
59
+ */
60
+ export interface SelectNode extends QueryASTNode {
61
+ type: 'select';
62
+ fields: (FieldNode | AggregateNode | WindowNode)[];
63
+ distinct?: boolean;
64
+ }
65
+
66
+ /**
67
+ * FROM clause node
68
+ */
69
+ export interface FromNode extends QueryASTNode {
70
+ type: 'from';
71
+ table: string;
72
+ alias?: string;
73
+ }
74
+
75
+ /**
76
+ * WHERE clause node
77
+ */
78
+ export interface WhereNode extends QueryASTNode {
79
+ type: 'where';
80
+ condition: OperatorNode;
81
+ }
82
+
83
+ /**
84
+ * Join execution strategy hint (ObjectStack Spec v0.7.1)
85
+ */
86
+ export type JoinStrategy = 'auto' | 'database' | 'hash' | 'loop';
87
+
88
+ /**
89
+ * JOIN clause node (Phase 3.3.4)
90
+ */
91
+ export interface JoinNode extends QueryASTNode {
92
+ type: 'join';
93
+ join_type: 'inner' | 'left' | 'right' | 'full' | 'cross';
94
+ table: string;
95
+ alias?: string;
96
+ on: OperatorNode;
97
+ strategy?: JoinStrategy; // Execution strategy hint for cross-datasource joins
98
+ }
99
+
100
+ /**
101
+ * GROUP BY clause node
102
+ */
103
+ export interface GroupByNode extends QueryASTNode {
104
+ type: 'group_by';
105
+ fields: FieldNode[];
106
+ having?: OperatorNode;
107
+ }
108
+
109
+ /**
110
+ * ORDER BY clause node
111
+ */
112
+ export interface OrderByNode extends QueryASTNode {
113
+ type: 'order_by';
114
+ fields: Array<{
115
+ field: FieldNode;
116
+ direction: 'asc' | 'desc';
117
+ }>;
118
+ }
119
+
120
+ /**
121
+ * LIMIT clause node
122
+ */
123
+ export interface LimitNode extends QueryASTNode {
124
+ type: 'limit';
125
+ value: number;
126
+ }
127
+
128
+ /**
129
+ * OFFSET clause node
130
+ */
131
+ export interface OffsetNode extends QueryASTNode {
132
+ type: 'offset';
133
+ value: number;
134
+ }
135
+
136
+ /**
137
+ * Subquery node (Phase 3.3.3)
138
+ */
139
+ export interface SubqueryNode extends QueryASTNode {
140
+ type: 'subquery';
141
+ query: QueryAST;
142
+ alias?: string;
143
+ }
144
+
145
+ /**
146
+ * Aggregate function node (Phase 3.3.5)
147
+ */
148
+ export interface AggregateNode extends QueryASTNode {
149
+ type: 'aggregate';
150
+ function: 'count' | 'sum' | 'avg' | 'min' | 'max' | 'first' | 'last' | 'count_distinct' | 'array_agg' | 'string_agg';
151
+ field?: FieldNode;
152
+ alias?: string;
153
+ distinct?: boolean;
154
+ separator?: string; // For string_agg function
155
+ }
156
+
157
+ /**
158
+ * Window function type (ObjectStack Spec v0.7.1)
159
+ */
160
+ export type WindowFunction =
161
+ | 'row_number'
162
+ | 'rank'
163
+ | 'dense_rank'
164
+ | 'percent_rank'
165
+ | 'lag'
166
+ | 'lead'
167
+ | 'first_value'
168
+ | 'last_value'
169
+ | 'sum'
170
+ | 'avg'
171
+ | 'count'
172
+ | 'min'
173
+ | 'max';
174
+
175
+ /**
176
+ * Window frame unit (ObjectStack Spec v0.7.1)
177
+ */
178
+ export type WindowFrameUnit = 'rows' | 'range';
179
+
180
+ /**
181
+ * Window frame boundary (ObjectStack Spec v0.7.1)
182
+ */
183
+ export type WindowFrameBoundary =
184
+ | 'unbounded_preceding'
185
+ | 'unbounded_following'
186
+ | 'current_row'
187
+ | { type: 'preceding'; offset: number }
188
+ | { type: 'following'; offset: number };
189
+
190
+ /**
191
+ * Window frame specification (ObjectStack Spec v0.7.1)
192
+ */
193
+ export interface WindowFrame {
194
+ unit: WindowFrameUnit;
195
+ start: WindowFrameBoundary;
196
+ end?: WindowFrameBoundary; // Defaults to CURRENT ROW if not specified
197
+ }
198
+
199
+ /**
200
+ * Window function node (ObjectStack Spec v0.7.1)
201
+ */
202
+ export interface WindowNode extends QueryASTNode {
203
+ type: 'window';
204
+ function: WindowFunction;
205
+ field?: FieldNode; // For aggregate window functions
206
+ alias: string;
207
+ partitionBy?: FieldNode[];
208
+ orderBy?: Array<{
209
+ field: FieldNode;
210
+ direction: 'asc' | 'desc';
211
+ }>;
212
+ frame?: WindowFrame;
213
+
214
+ // For LAG/LEAD functions
215
+ offset?: number;
216
+ defaultValue?: LiteralNode;
217
+ }
218
+
219
+ /**
220
+ * Field reference node
221
+ */
222
+ export interface FieldNode extends QueryASTNode {
223
+ type: 'field';
224
+ table?: string;
225
+ name: string;
226
+ alias?: string;
227
+ }
228
+
229
+ /**
230
+ * Literal value node
231
+ */
232
+ export interface LiteralNode extends QueryASTNode {
233
+ type: 'literal';
234
+ value: any;
235
+ data_type?: 'string' | 'number' | 'boolean' | 'date' | 'null';
236
+ }
237
+
238
+ /**
239
+ * Operator node
240
+ */
241
+ export interface OperatorNode extends QueryASTNode {
242
+ type: 'operator';
243
+ operator: ComparisonOperator | LogicalOperator;
244
+ operands: (FieldNode | LiteralNode | OperatorNode | FunctionNode)[];
245
+ }
246
+
247
+ /**
248
+ * Function call node
249
+ */
250
+ export interface FunctionNode extends QueryASTNode {
251
+ type: 'function';
252
+ name: string;
253
+ arguments: (FieldNode | LiteralNode | FunctionNode)[];
254
+ alias?: string;
255
+ }
256
+
257
+ /**
258
+ * Comparison operators
259
+ */
260
+ export type ComparisonOperator =
261
+ | '='
262
+ | '!='
263
+ | '<>'
264
+ | '>'
265
+ | '>='
266
+ | '<'
267
+ | '<='
268
+ | 'like'
269
+ | 'ilike'
270
+ | 'in'
271
+ | 'not_in'
272
+ | 'is_null'
273
+ | 'is_not_null'
274
+ | 'between'
275
+ | 'contains'
276
+ | 'starts_with'
277
+ | 'ends_with';
278
+
279
+ /**
280
+ * Logical operators
281
+ */
282
+ export type LogicalOperator = 'and' | 'or' | 'not';
283
+
284
+ /**
285
+ * Complete Query AST (Phase 3.3.1)
286
+ */
287
+ export interface QueryAST {
288
+ select: SelectNode;
289
+ from: FromNode;
290
+ joins?: JoinNode[];
291
+ where?: WhereNode;
292
+ group_by?: GroupByNode;
293
+ order_by?: OrderByNode;
294
+ limit?: LimitNode;
295
+ offset?: OffsetNode;
296
+ }
297
+
298
+ /**
299
+ * Query Schema - High-level query configuration
300
+ */
301
+ export interface QuerySchema {
302
+ /**
303
+ * Target object/table
304
+ */
305
+ object: string;
306
+
307
+ /**
308
+ * Fields to select
309
+ */
310
+ fields?: string[];
311
+
312
+ /**
313
+ * Filter conditions
314
+ */
315
+ filter?: AdvancedFilterSchema;
316
+
317
+ /**
318
+ * Sort configuration
319
+ */
320
+ sort?: QuerySortConfig[];
321
+
322
+ /**
323
+ * Pagination
324
+ */
325
+ limit?: number;
326
+ offset?: number;
327
+
328
+ /**
329
+ * Joins (Phase 3.3.4)
330
+ */
331
+ joins?: JoinConfig[];
332
+
333
+ /**
334
+ * Aggregations (Phase 3.3.5)
335
+ */
336
+ aggregations?: AggregationConfig[];
337
+
338
+ /**
339
+ * Group by fields
340
+ */
341
+ group_by?: string[];
342
+
343
+ /**
344
+ * Window functions (ObjectStack Spec v0.7.1)
345
+ */
346
+ windows?: WindowConfig[];
347
+
348
+ /**
349
+ * Related objects to expand
350
+ */
351
+ expand?: string[];
352
+
353
+ /**
354
+ * Full-text search
355
+ */
356
+ search?: string;
357
+ }
358
+
359
+ /**
360
+ * Sort configuration (extends base SortConfig)
361
+ */
362
+ export interface QuerySortConfig extends BaseSortConfig {
363
+ nulls?: 'first' | 'last';
364
+ }
365
+
366
+ /**
367
+ * Join configuration
368
+ */
369
+ export interface JoinConfig {
370
+ type: 'inner' | 'left' | 'right' | 'full';
371
+ object: string;
372
+ on: {
373
+ local_field: string;
374
+ foreign_field: string;
375
+ };
376
+ alias?: string;
377
+ }
378
+
379
+ /**
380
+ * Aggregation configuration
381
+ */
382
+ export interface AggregationConfig {
383
+ function: 'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct' | 'array_agg' | 'string_agg';
384
+ field?: string;
385
+ alias?: string;
386
+ distinct?: boolean;
387
+ separator?: string; // For string_agg function
388
+ }
389
+
390
+ /**
391
+ * Window function configuration (ObjectStack Spec v0.7.1)
392
+ */
393
+ export interface WindowConfig {
394
+ /** Window function name */
395
+ function: WindowFunction;
396
+
397
+ /** Field to operate on (not required for row_number, rank, etc.) */
398
+ field?: string;
399
+
400
+ /** Result alias */
401
+ alias: string;
402
+
403
+ /** PARTITION BY fields */
404
+ partitionBy?: string[];
405
+
406
+ /** ORDER BY clause */
407
+ orderBy?: Array<{ field: string; direction: 'asc' | 'desc' }>;
408
+
409
+ /** Window frame specification */
410
+ frame?: WindowFrame;
411
+
412
+ /** Offset for lag/lead functions */
413
+ offset?: number;
414
+
415
+ /** Default value for lag/lead when no previous/next row */
416
+ defaultValue?: any;
417
+ }
418
+
419
+ /**
420
+ * =============================================================================
421
+ * Phase 3.4: FilterSchema - Advanced Filtering
422
+ * =============================================================================
423
+ */
424
+
425
+ /**
426
+ * Filter Schema - Complex filtering support (extends base)
427
+ */
428
+ export interface AdvancedFilterSchema {
429
+ /**
430
+ * Logical operator for combining conditions
431
+ */
432
+ operator?: 'and' | 'or' | 'not';
433
+
434
+ /**
435
+ * Filter conditions
436
+ */
437
+ conditions?: AdvancedFilterCondition[];
438
+
439
+ /**
440
+ * Nested filter groups
441
+ */
442
+ groups?: AdvancedFilterSchema[];
443
+ }
444
+
445
+ /**
446
+ * Individual filter condition (extends base)
447
+ */
448
+ export interface AdvancedFilterCondition {
449
+ /**
450
+ * Field to filter on
451
+ */
452
+ field: string;
453
+
454
+ /**
455
+ * Comparison operator (extended)
456
+ */
457
+ operator: AdvancedFilterOperator;
458
+
459
+ /**
460
+ * Value to compare against
461
+ */
462
+ value?: any;
463
+
464
+ /**
465
+ * For BETWEEN and IN operators
466
+ */
467
+ values?: any[];
468
+
469
+ /**
470
+ * Case sensitivity for string comparisons
471
+ */
472
+ case_sensitive?: boolean;
473
+ }
474
+
475
+ /**
476
+ * Filter operators (Phase 3.4.1-3.4.4) - Extended from base
477
+ */
478
+ export type AdvancedFilterOperator =
479
+ | BaseFilterOperator
480
+ // Additional operators
481
+ | 'like'
482
+ | 'ilike'
483
+ | 'is_null'
484
+ | 'is_not_null'
485
+ | 'between'
486
+ | 'not_between'
487
+ // Date-specific (Phase 3.4.2)
488
+ | 'date_equals'
489
+ | 'date_after'
490
+ | 'date_before'
491
+ | 'date_in_range'
492
+ | 'date_today'
493
+ | 'date_yesterday'
494
+ | 'date_tomorrow'
495
+ | 'date_this_week'
496
+ | 'date_last_week'
497
+ | 'date_next_week'
498
+ | 'date_this_month'
499
+ | 'date_last_month'
500
+ | 'date_next_month'
501
+ | 'date_this_year'
502
+ | 'date_last_year'
503
+ | 'date_next_year'
504
+ // Lookup field filters (Phase 3.4.3)
505
+ | 'lookup_equals'
506
+ | 'lookup_contains'
507
+ | 'lookup_starts_with'
508
+ // Full-text search (Phase 3.4.4)
509
+ | 'search'
510
+ | 'search_phrase'
511
+ | 'search_proximity';
512
+
513
+ /**
514
+ * Date range filter (Phase 3.4.2)
515
+ */
516
+ export interface DateRangeFilter {
517
+ start?: Date | string;
518
+ end?: Date | string;
519
+ preset?: DateRangePreset;
520
+ }
521
+
522
+ /**
523
+ * Date range presets
524
+ */
525
+ export type DateRangePreset =
526
+ | 'today'
527
+ | 'yesterday'
528
+ | 'tomorrow'
529
+ | 'this_week'
530
+ | 'last_week'
531
+ | 'next_week'
532
+ | 'this_month'
533
+ | 'last_month'
534
+ | 'next_month'
535
+ | 'this_quarter'
536
+ | 'last_quarter'
537
+ | 'next_quarter'
538
+ | 'this_year'
539
+ | 'last_year'
540
+ | 'next_year'
541
+ | 'last_7_days'
542
+ | 'last_30_days'
543
+ | 'last_90_days'
544
+ | 'next_7_days'
545
+ | 'next_30_days'
546
+ | 'next_90_days';
547
+
548
+ /**
549
+ * Filter builder configuration (Phase 3.4.5)
550
+ */
551
+ export interface FilterBuilderConfig {
552
+ /**
553
+ * Available fields for filtering
554
+ */
555
+ fields: FilterFieldConfig[];
556
+
557
+ /**
558
+ * Default operator
559
+ */
560
+ default_operator?: 'and' | 'or';
561
+
562
+ /**
563
+ * Allow nested groups
564
+ */
565
+ allow_groups?: boolean;
566
+
567
+ /**
568
+ * Maximum nesting depth
569
+ */
570
+ max_depth?: number;
571
+ }
572
+
573
+ /**
574
+ * Filter field configuration
575
+ */
576
+ export interface FilterFieldConfig {
577
+ /**
578
+ * Field name
579
+ */
580
+ name: string;
581
+
582
+ /**
583
+ * Display label
584
+ */
585
+ label: string;
586
+
587
+ /**
588
+ * Field type
589
+ */
590
+ type: string;
591
+
592
+ /**
593
+ * Available operators for this field
594
+ */
595
+ operators?: AdvancedFilterOperator[];
596
+
597
+ /**
598
+ * Options for select fields
599
+ */
600
+ options?: Array<{ label: string; value: any }>;
601
+ }
602
+
603
+ /**
604
+ * =============================================================================
605
+ * Phase 3.5: ValidationSchema - Complete Validation Engine
606
+ * =============================================================================
607
+ */
608
+
609
+ /**
610
+ * Validation Schema (Phase 3.5)
611
+ */
612
+ export interface AdvancedValidationSchema {
613
+ /**
614
+ * Field name to validate
615
+ */
616
+ field?: string;
617
+
618
+ /**
619
+ * Validation rules
620
+ */
621
+ rules: AdvancedValidationRule[];
622
+
623
+ /**
624
+ * Custom error messages
625
+ */
626
+ messages?: Record<string, string>;
627
+
628
+ /**
629
+ * Validation triggers
630
+ */
631
+ on?: ('blur' | 'change' | 'submit')[];
632
+
633
+ /**
634
+ * Whether validation is async
635
+ */
636
+ async?: boolean;
637
+
638
+ /**
639
+ * Debounce time for async validation (ms)
640
+ */
641
+ debounce?: number;
642
+ }
643
+
644
+ /**
645
+ * Validation rule (Phase 3.5.1-3.5.4) - Extended
646
+ */
647
+ export interface AdvancedValidationRule {
648
+ /**
649
+ * Rule type
650
+ */
651
+ type: ValidationRuleType;
652
+
653
+ /**
654
+ * Rule parameters
655
+ */
656
+ params?: any;
657
+
658
+ /**
659
+ * Error message
660
+ */
661
+ message?: string;
662
+
663
+ /**
664
+ * Custom validation function (Phase 3.5.2)
665
+ */
666
+ validator?: ValidationFunction;
667
+
668
+ /**
669
+ * Async validation function (Phase 3.5.3)
670
+ */
671
+ async_validator?: AsyncValidationFunction;
672
+
673
+ /**
674
+ * Cross-field dependencies (Phase 3.5.4)
675
+ */
676
+ depends_on?: string[];
677
+
678
+ /**
679
+ * Validation severity
680
+ */
681
+ severity?: 'error' | 'warning' | 'info';
682
+ }
683
+
684
+ /**
685
+ * Validation rule types
686
+ */
687
+ export type ValidationRuleType =
688
+ // Required
689
+ | 'required'
690
+ // String validations
691
+ | 'min_length'
692
+ | 'max_length'
693
+ | 'pattern'
694
+ | 'email'
695
+ | 'url'
696
+ | 'phone'
697
+ // Number validations
698
+ | 'min'
699
+ | 'max'
700
+ | 'integer'
701
+ | 'positive'
702
+ | 'negative'
703
+ // Date validations
704
+ | 'date_min'
705
+ | 'date_max'
706
+ | 'date_range'
707
+ | 'date_future'
708
+ | 'date_past'
709
+ // Array validations
710
+ | 'min_items'
711
+ | 'max_items'
712
+ | 'unique_items'
713
+ // Object validations
714
+ | 'object_schema'
715
+ // Cross-field validations (Phase 3.5.4)
716
+ | 'field_match'
717
+ | 'field_compare'
718
+ | 'conditional'
719
+ // Custom validations (Phase 3.5.2)
720
+ | 'custom'
721
+ // Async validations (Phase 3.5.3)
722
+ | 'async_custom'
723
+ | 'remote_validation'
724
+ | 'unique_check'
725
+ | 'exists_check';
726
+
727
+ /**
728
+ * Validation function signature used by AdvancedValidationRule in the data protocol.
729
+ *
730
+ * This type is defined in this module and may differ from similarly named
731
+ * validation function types in other packages (e.g., in `field-types`).
732
+ *
733
+ * @param value - The value to validate
734
+ * @param context - Optional validation context with access to other field values
735
+ * @returns true if valid, false or error message string if invalid
736
+ */
737
+ export type ValidationFunction = (value: any, context?: ValidationContext) => boolean | string;
738
+
739
+ /**
740
+ * Async validation function (Phase 3.5.3)
741
+ */
742
+ export type AsyncValidationFunction = (
743
+ value: any,
744
+ context?: ValidationContext
745
+ ) => Promise<boolean | string>;
746
+
747
+ /**
748
+ * Validation context (Phase 3.5.4)
749
+ */
750
+ export interface ValidationContext {
751
+ /**
752
+ * All form values
753
+ */
754
+ values?: Record<string, any>;
755
+
756
+ /**
757
+ * Field metadata
758
+ */
759
+ field?: any;
760
+
761
+ /**
762
+ * Parent object data
763
+ */
764
+ parent?: any;
765
+
766
+ /**
767
+ * Current user context
768
+ */
769
+ user?: any;
770
+ }
771
+
772
+ /**
773
+ * Validation result
774
+ */
775
+ export interface AdvancedValidationResult {
776
+ /**
777
+ * Whether validation passed
778
+ */
779
+ valid: boolean;
780
+
781
+ /**
782
+ * Validation errors
783
+ */
784
+ errors: AdvancedValidationError[];
785
+
786
+ /**
787
+ * Validation warnings
788
+ */
789
+ warnings?: AdvancedValidationError[];
790
+ }
791
+
792
+ /**
793
+ * Validation error (Phase 3.5.5: Improved error messages)
794
+ */
795
+ export interface AdvancedValidationError {
796
+ /**
797
+ * Field path
798
+ */
799
+ field: string;
800
+
801
+ /**
802
+ * Error message
803
+ */
804
+ message: string;
805
+
806
+ /**
807
+ * Error code
808
+ */
809
+ code?: string;
810
+
811
+ /**
812
+ * Rule type that failed
813
+ */
814
+ rule?: ValidationRuleType;
815
+
816
+ /**
817
+ * Error severity
818
+ */
819
+ severity?: 'error' | 'warning' | 'info';
820
+
821
+ /**
822
+ * Additional context
823
+ */
824
+ context?: Record<string, any>;
825
+ }
826
+
827
+ /**
828
+ * =============================================================================
829
+ * ObjectStack Spec v0.7.1: Object-Level Validation Framework
830
+ * =============================================================================
831
+ */
832
+
833
+ /**
834
+ * Base validation interface (ObjectStack Spec v0.7.1)
835
+ */
836
+ export interface BaseValidation {
837
+ /** Unique validation name (snake_case) */
838
+ name: string;
839
+
840
+ /** Display label for the validation */
841
+ label?: string;
842
+
843
+ /** Description of what this validation does */
844
+ description?: string;
845
+
846
+ /** Whether this validation is currently active */
847
+ active: boolean;
848
+
849
+ /** When this validation should run */
850
+ events: Array<'insert' | 'update' | 'delete'>;
851
+
852
+ /** Severity of validation failure */
853
+ severity: 'error' | 'warning' | 'info';
854
+
855
+ /** Error message to display on failure */
856
+ message: string;
857
+
858
+ /** Tags for categorization */
859
+ tags?: string[];
860
+ }
861
+
862
+ /**
863
+ * Script-based validation (ObjectStack Spec v0.7.1)
864
+ * Uses expression language to define conditions
865
+ */
866
+ export interface ScriptValidation extends BaseValidation {
867
+ type: 'script';
868
+
869
+ /** Expression that must evaluate to true */
870
+ condition: string;
871
+ }
872
+
873
+ /**
874
+ * Uniqueness validation (ObjectStack Spec v0.7.1)
875
+ * Ensures field combinations are unique
876
+ */
877
+ export interface UniquenessValidation extends BaseValidation {
878
+ type: 'unique';
879
+
880
+ /** Fields that must be unique together */
881
+ fields: string[];
882
+
883
+ /** Optional scope expression (e.g., "tenant_id = ${current_tenant}") */
884
+ scope?: string;
885
+
886
+ /** Whether comparison is case-sensitive */
887
+ caseSensitive?: boolean;
888
+ }
889
+
890
+ /**
891
+ * State machine validation (ObjectStack Spec v0.7.1)
892
+ * Enforces valid state transitions
893
+ */
894
+ export interface StateMachineValidation extends BaseValidation {
895
+ type: 'state_machine';
896
+
897
+ /** Field containing the state */
898
+ stateField: string;
899
+
900
+ /** Allowed state transitions */
901
+ transitions: Array<{
902
+ /** Source state(s) */
903
+ from: string | string[];
904
+
905
+ /** Target state */
906
+ to: string;
907
+
908
+ /** Optional condition that must be true */
909
+ condition?: string;
910
+ }>;
911
+ }
912
+
913
+ /**
914
+ * Cross-field validation (ObjectStack Spec v0.7.1)
915
+ * Validates relationships between multiple fields
916
+ */
917
+ export interface CrossFieldValidation extends BaseValidation {
918
+ type: 'cross_field';
919
+
920
+ /** Fields involved in the validation */
921
+ fields: string[];
922
+
923
+ /** Condition expression involving multiple fields */
924
+ condition: string;
925
+ }
926
+
927
+ /**
928
+ * Async/remote validation (ObjectStack Spec v0.7.1)
929
+ * Calls external endpoint for validation
930
+ */
931
+ export interface AsyncValidation extends BaseValidation {
932
+ type: 'async';
933
+
934
+ /** API endpoint to call */
935
+ endpoint: string;
936
+
937
+ /** HTTP method */
938
+ method?: 'GET' | 'POST';
939
+
940
+ /** Debounce delay in milliseconds */
941
+ debounce?: number;
942
+
943
+ /** Cache configuration */
944
+ cache?: {
945
+ enabled: boolean;
946
+ ttl?: number; // Time to live in seconds
947
+ };
948
+ }
949
+
950
+ /**
951
+ * Conditional validation (ObjectStack Spec v0.7.1)
952
+ * Applies nested rules only when condition is met
953
+ */
954
+ export interface ConditionalValidation extends BaseValidation {
955
+ type: 'conditional';
956
+
957
+ /** Condition that determines if rules should apply */
958
+ condition: string;
959
+
960
+ /** Nested validation rules to apply when condition is true */
961
+ rules: ObjectValidationRule[];
962
+ }
963
+
964
+ /**
965
+ * Format validation (ObjectStack Spec v0.7.1)
966
+ * Validates field format using regex or predefined patterns
967
+ */
968
+ export interface FormatValidation extends BaseValidation {
969
+ type: 'format';
970
+
971
+ /** Field to validate */
972
+ field: string;
973
+
974
+ /** Regex pattern or predefined format name */
975
+ pattern: string | RegExp;
976
+
977
+ /** Predefined format (email, url, phone, etc.) */
978
+ format?: 'email' | 'url' | 'phone' | 'ipv4' | 'ipv6' | 'uuid' | 'iso_date' | 'credit_card';
979
+
980
+ /** Validation flags for regex (i, g, m, etc.) */
981
+ flags?: string;
982
+ }
983
+
984
+ /**
985
+ * Range validation (ObjectStack Spec v0.7.1)
986
+ * Validates numeric or date ranges
987
+ */
988
+ export interface RangeValidation extends BaseValidation {
989
+ type: 'range';
990
+
991
+ /** Field to validate */
992
+ field: string;
993
+
994
+ /** Minimum value (inclusive) */
995
+ min?: number | string | Date;
996
+
997
+ /** Maximum value (inclusive) */
998
+ max?: number | string | Date;
999
+
1000
+ /** Whether min is exclusive */
1001
+ minExclusive?: boolean;
1002
+
1003
+ /** Whether max is exclusive */
1004
+ maxExclusive?: boolean;
1005
+ }
1006
+
1007
+ /**
1008
+ * Union type for all validation rules (ObjectStack Spec v0.7.1)
1009
+ */
1010
+ export type ObjectValidationRule =
1011
+ | ScriptValidation
1012
+ | UniquenessValidation
1013
+ | StateMachineValidation
1014
+ | CrossFieldValidation
1015
+ | AsyncValidation
1016
+ | ConditionalValidation
1017
+ | FormatValidation
1018
+ | RangeValidation;
1019
+
1020
+ /**
1021
+ * =============================================================================
1022
+ * Phase 3.6: DriverInterface - Database Driver Abstraction
1023
+ * =============================================================================
1024
+ */
1025
+
1026
+ /**
1027
+ * Database Driver Interface (Phase 3.6)
1028
+ */
1029
+ export interface DriverInterface {
1030
+ /**
1031
+ * Driver name
1032
+ */
1033
+ name: string;
1034
+
1035
+ /**
1036
+ * Driver version
1037
+ */
1038
+ version?: string;
1039
+
1040
+ /**
1041
+ * Connect to database
1042
+ */
1043
+ connect(config: ConnectionConfig): Promise<void>;
1044
+
1045
+ /**
1046
+ * Disconnect from database
1047
+ */
1048
+ disconnect(): Promise<void>;
1049
+
1050
+ /**
1051
+ * Execute query
1052
+ */
1053
+ query<T = any>(sql: string, params?: any[]): Promise<DriverQueryResult<T>>;
1054
+
1055
+ /**
1056
+ * Execute query from AST
1057
+ */
1058
+ executeAST<T = any>(ast: QueryAST): Promise<DriverQueryResult<T>>;
1059
+
1060
+ /**
1061
+ * Find records
1062
+ */
1063
+ find<T = any>(table: string, query: QuerySchema): Promise<DriverQueryResult<T>>;
1064
+
1065
+ /**
1066
+ * Find one record
1067
+ */
1068
+ findOne<T = any>(table: string, id: any): Promise<T | null>;
1069
+
1070
+ /**
1071
+ * Insert record
1072
+ */
1073
+ insert<T = any>(table: string, data: Partial<T>): Promise<T>;
1074
+
1075
+ /**
1076
+ * Update record
1077
+ */
1078
+ update<T = any>(table: string, id: any, data: Partial<T>): Promise<T>;
1079
+
1080
+ /**
1081
+ * Delete record
1082
+ */
1083
+ delete(table: string, id: any): Promise<boolean>;
1084
+
1085
+ /**
1086
+ * Batch operations (Phase 3.6.2)
1087
+ */
1088
+ batch<T = any>(operations: BatchOperation[]): Promise<BatchResult<T>>;
1089
+
1090
+ /**
1091
+ * Transaction support (Phase 3.6.1)
1092
+ */
1093
+ transaction<T = any>(
1094
+ callback: (trx: TransactionContext) => Promise<T>
1095
+ ): Promise<T>;
1096
+
1097
+ /**
1098
+ * Get object schema
1099
+ */
1100
+ getSchema(objectName: string): Promise<any>;
1101
+
1102
+ /**
1103
+ * Cache management (Phase 3.6.4)
1104
+ */
1105
+ cache?: CacheManager;
1106
+
1107
+ /**
1108
+ * Connection pool (Phase 3.6.3)
1109
+ */
1110
+ pool?: ConnectionPool;
1111
+ }
1112
+
1113
+ /**
1114
+ * Connection configuration
1115
+ */
1116
+ export interface ConnectionConfig {
1117
+ /**
1118
+ * Database host
1119
+ */
1120
+ host?: string;
1121
+
1122
+ /**
1123
+ * Database port
1124
+ */
1125
+ port?: number;
1126
+
1127
+ /**
1128
+ * Database name
1129
+ */
1130
+ database?: string;
1131
+
1132
+ /**
1133
+ * Username
1134
+ */
1135
+ username?: string;
1136
+
1137
+ /**
1138
+ * Password
1139
+ */
1140
+ password?: string;
1141
+
1142
+ /**
1143
+ * Connection URL
1144
+ */
1145
+ url?: string;
1146
+
1147
+ /**
1148
+ * SSL configuration
1149
+ */
1150
+ ssl?: boolean | object;
1151
+
1152
+ /**
1153
+ * Pool configuration (Phase 3.6.3)
1154
+ */
1155
+ pool?: {
1156
+ min?: number;
1157
+ max?: number;
1158
+ idle_timeout?: number;
1159
+ connection_timeout?: number;
1160
+ };
1161
+
1162
+ /**
1163
+ * Additional driver-specific options
1164
+ */
1165
+ options?: Record<string, any>;
1166
+ }
1167
+
1168
+ /**
1169
+ * Query result with metadata (extends base QueryResult from data.ts)
1170
+ */
1171
+ export interface DriverQueryResult<T = any> {
1172
+ /**
1173
+ * Result data
1174
+ */
1175
+ data: T[];
1176
+
1177
+ /**
1178
+ * Total count
1179
+ */
1180
+ total?: number;
1181
+
1182
+ /**
1183
+ * Current page number (1-indexed)
1184
+ */
1185
+ page?: number;
1186
+
1187
+ /**
1188
+ * Page size
1189
+ */
1190
+ pageSize?: number;
1191
+
1192
+ /**
1193
+ * Whether there are more records
1194
+ */
1195
+ hasMore?: boolean;
1196
+
1197
+ /**
1198
+ * Cursor for cursor-based pagination
1199
+ */
1200
+ cursor?: string;
1201
+
1202
+ /**
1203
+ * Execution metadata
1204
+ */
1205
+ metadata?: {
1206
+ /**
1207
+ * Execution time in ms
1208
+ */
1209
+ execution_time?: number;
1210
+
1211
+ /**
1212
+ * Whether result was cached
1213
+ */
1214
+ from_cache?: boolean;
1215
+
1216
+ /**
1217
+ * Number of rows affected
1218
+ */
1219
+ rows_affected?: number;
1220
+ };
1221
+ }
1222
+
1223
+ /**
1224
+ * Batch operation (Phase 3.6.2)
1225
+ */
1226
+ export interface BatchOperation {
1227
+ /**
1228
+ * Operation type
1229
+ */
1230
+ type: 'insert' | 'update' | 'delete';
1231
+
1232
+ /**
1233
+ * Target table
1234
+ */
1235
+ table: string;
1236
+
1237
+ /**
1238
+ * Operation data
1239
+ */
1240
+ data?: any;
1241
+
1242
+ /**
1243
+ * Record ID (for update/delete)
1244
+ */
1245
+ id?: any;
1246
+ }
1247
+
1248
+ /**
1249
+ * Batch operation result
1250
+ */
1251
+ export interface BatchResult<T = any> {
1252
+ /**
1253
+ * Successful operations
1254
+ */
1255
+ success: T[];
1256
+
1257
+ /**
1258
+ * Failed operations
1259
+ */
1260
+ failed: Array<{
1261
+ operation: BatchOperation;
1262
+ error: Error;
1263
+ }>;
1264
+
1265
+ /**
1266
+ * Total operations
1267
+ */
1268
+ total: number;
1269
+
1270
+ /**
1271
+ * Success count
1272
+ */
1273
+ success_count: number;
1274
+
1275
+ /**
1276
+ * Failure count
1277
+ */
1278
+ failure_count: number;
1279
+ }
1280
+
1281
+ /**
1282
+ * Transaction context (Phase 3.6.1)
1283
+ */
1284
+ export interface TransactionContext {
1285
+ /**
1286
+ * Execute query within transaction
1287
+ */
1288
+ query<T = any>(sql: string, params?: any[]): Promise<DriverQueryResult<T>>;
1289
+
1290
+ /**
1291
+ * Insert within transaction
1292
+ */
1293
+ insert<T = any>(table: string, data: Partial<T>): Promise<T>;
1294
+
1295
+ /**
1296
+ * Update within transaction
1297
+ */
1298
+ update<T = any>(table: string, id: any, data: Partial<T>): Promise<T>;
1299
+
1300
+ /**
1301
+ * Delete within transaction
1302
+ */
1303
+ delete(table: string, id: any): Promise<boolean>;
1304
+
1305
+ /**
1306
+ * Commit transaction
1307
+ */
1308
+ commit(): Promise<void>;
1309
+
1310
+ /**
1311
+ * Rollback transaction
1312
+ */
1313
+ rollback(): Promise<void>;
1314
+ }
1315
+
1316
+ /**
1317
+ * Cache manager (Phase 3.6.4)
1318
+ */
1319
+ export interface CacheManager {
1320
+ /**
1321
+ * Get cached value
1322
+ */
1323
+ get<T = any>(key: string): Promise<T | null>;
1324
+
1325
+ /**
1326
+ * Set cached value
1327
+ */
1328
+ set<T = any>(key: string, value: T, ttl?: number): Promise<void>;
1329
+
1330
+ /**
1331
+ * Delete cached value
1332
+ */
1333
+ delete(key: string): Promise<void>;
1334
+
1335
+ /**
1336
+ * Clear all cache
1337
+ */
1338
+ clear(): Promise<void>;
1339
+
1340
+ /**
1341
+ * Check if key exists
1342
+ */
1343
+ has(key: string): Promise<boolean>;
1344
+ }
1345
+
1346
+ /**
1347
+ * Connection pool (Phase 3.6.3)
1348
+ */
1349
+ export interface ConnectionPool {
1350
+ /**
1351
+ * Get connection from pool
1352
+ */
1353
+ acquire(): Promise<any>;
1354
+
1355
+ /**
1356
+ * Release connection back to pool
1357
+ */
1358
+ release(connection: any): Promise<void>;
1359
+
1360
+ /**
1361
+ * Pool statistics
1362
+ */
1363
+ stats(): {
1364
+ total: number;
1365
+ idle: number;
1366
+ active: number;
1367
+ waiting: number;
1368
+ };
1369
+
1370
+ /**
1371
+ * Close all connections
1372
+ */
1373
+ close(): Promise<void>;
1374
+ }
1375
+
1376
+ /**
1377
+ * =============================================================================
1378
+ * Phase 3.7: DatasourceSchema - Multi-Datasource Management
1379
+ * =============================================================================
1380
+ */
1381
+
1382
+ /**
1383
+ * Datasource Schema (Phase 3.7)
1384
+ */
1385
+ export interface DatasourceSchema {
1386
+ /**
1387
+ * Datasource name
1388
+ */
1389
+ name: string;
1390
+
1391
+ /**
1392
+ * Datasource type
1393
+ */
1394
+ type: DatasourceType;
1395
+
1396
+ /**
1397
+ * Display label
1398
+ */
1399
+ label?: string;
1400
+
1401
+ /**
1402
+ * Connection configuration
1403
+ */
1404
+ connection: ConnectionConfig;
1405
+
1406
+ /**
1407
+ * Driver interface
1408
+ */
1409
+ driver?: DriverInterface;
1410
+
1411
+ /**
1412
+ * Whether datasource is default
1413
+ */
1414
+ is_default?: boolean;
1415
+
1416
+ /**
1417
+ * Health check configuration (Phase 3.7.4)
1418
+ */
1419
+ health_check?: {
1420
+ /**
1421
+ * Enable health checks
1422
+ */
1423
+ enabled?: boolean;
1424
+
1425
+ /**
1426
+ * Check interval in seconds
1427
+ */
1428
+ interval?: number;
1429
+
1430
+ /**
1431
+ * Timeout in milliseconds
1432
+ */
1433
+ timeout?: number;
1434
+
1435
+ /**
1436
+ * Health check query
1437
+ */
1438
+ query?: string;
1439
+ };
1440
+
1441
+ /**
1442
+ * Monitoring configuration (Phase 3.7.5)
1443
+ */
1444
+ monitoring?: {
1445
+ /**
1446
+ * Enable monitoring
1447
+ */
1448
+ enabled?: boolean;
1449
+
1450
+ /**
1451
+ * Metrics to collect
1452
+ */
1453
+ metrics?: DatasourceMetric[];
1454
+
1455
+ /**
1456
+ * Alert thresholds
1457
+ */
1458
+ alerts?: DatasourceAlert[];
1459
+ };
1460
+
1461
+ /**
1462
+ * Retry configuration
1463
+ */
1464
+ retry?: {
1465
+ /**
1466
+ * Max retry attempts
1467
+ */
1468
+ max_attempts?: number;
1469
+
1470
+ /**
1471
+ * Retry delay in milliseconds
1472
+ */
1473
+ delay?: number;
1474
+
1475
+ /**
1476
+ * Exponential backoff
1477
+ */
1478
+ backoff?: boolean;
1479
+ };
1480
+
1481
+ /**
1482
+ * Metadata
1483
+ */
1484
+ metadata?: Record<string, any>;
1485
+ }
1486
+
1487
+ /**
1488
+ * Datasource types
1489
+ */
1490
+ export type DatasourceType =
1491
+ | 'postgres'
1492
+ | 'mysql'
1493
+ | 'mongodb'
1494
+ | 'sqlite'
1495
+ | 'mssql'
1496
+ | 'oracle'
1497
+ | 'rest'
1498
+ | 'graphql'
1499
+ | 'objectql'
1500
+ | 'custom';
1501
+
1502
+ /**
1503
+ * Datasource metric types (Phase 3.7.5)
1504
+ */
1505
+ export type DatasourceMetric =
1506
+ | 'query_count'
1507
+ | 'query_duration'
1508
+ | 'error_rate'
1509
+ | 'connection_count'
1510
+ | 'cache_hit_rate'
1511
+ | 'throughput';
1512
+
1513
+ /**
1514
+ * Datasource alert configuration (Phase 3.7.5)
1515
+ */
1516
+ export interface DatasourceAlert {
1517
+ /**
1518
+ * Alert name
1519
+ */
1520
+ name: string;
1521
+
1522
+ /**
1523
+ * Metric to monitor
1524
+ */
1525
+ metric: DatasourceMetric;
1526
+
1527
+ /**
1528
+ * Threshold value
1529
+ */
1530
+ threshold: number;
1531
+
1532
+ /**
1533
+ * Comparison operator
1534
+ */
1535
+ operator: '>' | '<' | '>=' | '<=' | '=';
1536
+
1537
+ /**
1538
+ * Alert severity
1539
+ */
1540
+ severity: 'info' | 'warning' | 'error' | 'critical';
1541
+
1542
+ /**
1543
+ * Alert actions
1544
+ */
1545
+ actions?: Array<'log' | 'email' | 'slack' | 'webhook'>;
1546
+ }
1547
+
1548
+ /**
1549
+ * Multi-datasource manager (Phase 3.7.2)
1550
+ */
1551
+ export interface DatasourceManager {
1552
+ /**
1553
+ * Register a datasource
1554
+ */
1555
+ register(datasource: DatasourceSchema): void;
1556
+
1557
+ /**
1558
+ * Unregister a datasource
1559
+ */
1560
+ unregister(name: string): void;
1561
+
1562
+ /**
1563
+ * Get datasource by name
1564
+ */
1565
+ get(name: string): DatasourceSchema | undefined;
1566
+
1567
+ /**
1568
+ * Get default datasource
1569
+ */
1570
+ getDefault(): DatasourceSchema | undefined;
1571
+
1572
+ /**
1573
+ * Switch active datasource (Phase 3.7.3)
1574
+ */
1575
+ switch(name: string): void;
1576
+
1577
+ /**
1578
+ * Get active datasource
1579
+ */
1580
+ getActive(): DatasourceSchema | undefined;
1581
+
1582
+ /**
1583
+ * List all datasources
1584
+ */
1585
+ list(): DatasourceSchema[];
1586
+
1587
+ /**
1588
+ * Check datasource health (Phase 3.7.4)
1589
+ */
1590
+ checkHealth(name: string): Promise<HealthCheckResult>;
1591
+
1592
+ /**
1593
+ * Get datasource metrics (Phase 3.7.5)
1594
+ */
1595
+ getMetrics(name: string): Promise<DatasourceMetrics>;
1596
+ }
1597
+
1598
+ /**
1599
+ * Health check result (Phase 3.7.4)
1600
+ */
1601
+ export interface HealthCheckResult {
1602
+ /**
1603
+ * Datasource name
1604
+ */
1605
+ datasource: string;
1606
+
1607
+ /**
1608
+ * Health status
1609
+ */
1610
+ status: 'healthy' | 'degraded' | 'unhealthy';
1611
+
1612
+ /**
1613
+ * Response time in ms
1614
+ */
1615
+ response_time?: number;
1616
+
1617
+ /**
1618
+ * Error message if unhealthy
1619
+ */
1620
+ error?: string;
1621
+
1622
+ /**
1623
+ * Timestamp
1624
+ */
1625
+ timestamp: Date;
1626
+
1627
+ /**
1628
+ * Additional details
1629
+ */
1630
+ details?: Record<string, any>;
1631
+ }
1632
+
1633
+ /**
1634
+ * Datasource metrics (Phase 3.7.5)
1635
+ */
1636
+ export interface DatasourceMetrics {
1637
+ /**
1638
+ * Datasource name
1639
+ */
1640
+ datasource: string;
1641
+
1642
+ /**
1643
+ * Query metrics
1644
+ */
1645
+ queries: {
1646
+ total: number;
1647
+ success: number;
1648
+ failed: number;
1649
+ avg_duration: number;
1650
+ };
1651
+
1652
+ /**
1653
+ * Connection metrics
1654
+ */
1655
+ connections: {
1656
+ active: number;
1657
+ idle: number;
1658
+ total: number;
1659
+ };
1660
+
1661
+ /**
1662
+ * Cache metrics
1663
+ */
1664
+ cache?: {
1665
+ hits: number;
1666
+ misses: number;
1667
+ hit_rate: number;
1668
+ };
1669
+
1670
+ /**
1671
+ * Error rate
1672
+ */
1673
+ error_rate: number;
1674
+
1675
+ /**
1676
+ * Timestamp
1677
+ */
1678
+ timestamp: Date;
1679
+ }