@objectql/types 1.8.2 → 1.8.4

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,327 @@
1
+ import { FieldConfig } from './field';
2
+ /**
3
+ * Represents the type of schema change operation.
4
+ */
5
+ export type SchemaChangeType = 'field_update' | 'field_delete' | 'object_update' | 'object_delete';
6
+ /**
7
+ * Base interface for all schema change instructions.
8
+ */
9
+ export interface BaseSchemaChangeInstruction {
10
+ /** Type of schema change operation */
11
+ type: SchemaChangeType;
12
+ /** Human-readable description of the change */
13
+ description?: string;
14
+ /** Reason for the change (for audit trail) */
15
+ reason?: string;
16
+ /** Timestamp when the change was defined (ISO 8601) */
17
+ timestamp?: string;
18
+ /** Author of the change (username or ID) */
19
+ author?: string;
20
+ }
21
+ /**
22
+ * Database impact assessment for a field change.
23
+ * Describes how the change affects the underlying database schema.
24
+ */
25
+ export interface DatabaseImpact {
26
+ /**
27
+ * Type of database operation required.
28
+ * - 'alter_column': Modify column properties (type, constraints, default)
29
+ * - 'rename_column': Rename a column
30
+ * - 'drop_column': Remove a column
31
+ * - 'add_column': Add a new column
32
+ * - 'rebuild_table': Requires full table rebuild (complex changes)
33
+ * - 'no_change': Schema-level only, no database changes
34
+ */
35
+ operation: 'alter_column' | 'rename_column' | 'drop_column' | 'add_column' | 'rebuild_table' | 'no_change';
36
+ /**
37
+ * Whether this change requires data migration.
38
+ * If true, existing records must be updated.
39
+ */
40
+ requires_data_migration: boolean;
41
+ /**
42
+ * Whether this change may cause data loss.
43
+ * Examples: type narrowing, dropping columns, shortening text length
44
+ */
45
+ may_cause_data_loss: boolean;
46
+ /**
47
+ * Estimated risk level for this change.
48
+ * - 'low': Safe, reversible change (e.g., adding nullable field)
49
+ * - 'medium': May affect queries or require downtime (e.g., adding index)
50
+ * - 'high': Requires careful planning (e.g., type change with data migration)
51
+ * - 'critical': May cause data loss or extended downtime (e.g., dropping column)
52
+ */
53
+ risk_level?: 'low' | 'medium' | 'high' | 'critical';
54
+ /**
55
+ * Expected downtime for this change.
56
+ * Format: ISO 8601 duration (e.g., 'PT5M' for 5 minutes, 'PT2H' for 2 hours)
57
+ */
58
+ estimated_downtime?: string;
59
+ /**
60
+ * Notes about the database impact for human review.
61
+ */
62
+ notes?: string;
63
+ }
64
+ /**
65
+ * Database upgrade script information.
66
+ * Contains the generated DDL/DML statements for applying the migration.
67
+ */
68
+ export interface UpgradeScript {
69
+ /**
70
+ * Target database dialect.
71
+ * Examples: 'postgresql', 'mysql', 'sqlite', 'mongodb', 'mssql'
72
+ */
73
+ dialect: string;
74
+ /**
75
+ * SQL or database-specific statements to apply the change (forward migration).
76
+ * For SQL: DDL statements (ALTER TABLE, CREATE INDEX, etc.)
77
+ * For MongoDB: Update operations
78
+ */
79
+ up_statements: string[];
80
+ /**
81
+ * SQL or database-specific statements to rollback the change (reverse migration).
82
+ * Only present if the change is reversible.
83
+ */
84
+ down_statements?: string[];
85
+ /**
86
+ * Pre-migration checks or validations to run before applying changes.
87
+ * Examples: Check for data integrity, verify no duplicate values before adding UNIQUE constraint
88
+ */
89
+ pre_checks?: string[];
90
+ /**
91
+ * Post-migration validations to ensure the change was successful.
92
+ * Examples: Verify column exists, check data was migrated correctly
93
+ */
94
+ post_checks?: string[];
95
+ /**
96
+ * Estimated execution time for this script.
97
+ * Format: ISO 8601 duration
98
+ */
99
+ estimated_execution_time?: string;
100
+ }
101
+ /**
102
+ * Instruction to update (modify) a field in an object.
103
+ * Can rename, change type, or update properties of an existing field.
104
+ */
105
+ export interface FieldUpdateInstruction extends BaseSchemaChangeInstruction {
106
+ type: 'field_update';
107
+ /** Name of the object containing the field */
108
+ object_name: string;
109
+ /** Current name of the field to update */
110
+ field_name: string;
111
+ /** New name for the field (if renaming) */
112
+ new_field_name?: string;
113
+ /** Updated field configuration (partial) */
114
+ changes: Partial<FieldConfig>;
115
+ /**
116
+ * Strategy for handling existing data during type changes.
117
+ * - 'auto': Attempt automatic conversion
118
+ * - 'manual': Requires custom data migration script
119
+ * - 'preserve': Keep data as-is (may cause validation errors)
120
+ * - 'clear': Set field to null/default for all existing records
121
+ */
122
+ data_migration_strategy?: 'auto' | 'manual' | 'preserve' | 'clear';
123
+ /**
124
+ * Custom data transformation function (for manual strategy).
125
+ * Should be a valid JavaScript expression or function body.
126
+ */
127
+ transform_script?: string;
128
+ /**
129
+ * Database impact assessment for this field change.
130
+ * Describes the effect on the underlying database schema.
131
+ */
132
+ database_impact?: DatabaseImpact;
133
+ /**
134
+ * Generated upgrade scripts for different database dialects.
135
+ * Maps dialect name to upgrade script.
136
+ * Example: { postgresql: {...}, mysql: {...} }
137
+ */
138
+ upgrade_scripts?: Record<string, UpgradeScript>;
139
+ }
140
+ /**
141
+ * Instruction to delete (remove) a field from an object.
142
+ */
143
+ export interface FieldDeleteInstruction extends BaseSchemaChangeInstruction {
144
+ type: 'field_delete';
145
+ /** Name of the object containing the field */
146
+ object_name: string;
147
+ /** Name of the field to delete */
148
+ field_name: string;
149
+ /**
150
+ * Strategy for handling existing data in the field.
151
+ * - 'drop': Remove the field and its data (irreversible)
152
+ * - 'archive': Move data to an archive/backup location
153
+ * - 'soft': Mark as deleted but keep data (for rollback)
154
+ */
155
+ deletion_strategy?: 'drop' | 'archive' | 'soft';
156
+ /** Backup location if using 'archive' strategy */
157
+ archive_location?: string;
158
+ /**
159
+ * Database impact assessment for this field deletion.
160
+ * Describes the effect on the underlying database schema.
161
+ */
162
+ database_impact?: DatabaseImpact;
163
+ /**
164
+ * Generated upgrade scripts for different database dialects.
165
+ * Maps dialect name to upgrade script.
166
+ * Example: { postgresql: {...}, mysql: {...} }
167
+ */
168
+ upgrade_scripts?: Record<string, UpgradeScript>;
169
+ }
170
+ /**
171
+ * Configuration changes that can be applied to an object.
172
+ * Used by ObjectUpdateInstruction to modify object metadata.
173
+ */
174
+ export interface ObjectUpdateChanges {
175
+ /** Updated human-readable label */
176
+ label?: string;
177
+ /** Updated icon string */
178
+ icon?: string;
179
+ /** Updated description */
180
+ description?: string;
181
+ /** Updated datasource name */
182
+ datasource?: string;
183
+ }
184
+ /**
185
+ * Instruction to update (modify) an object definition.
186
+ * Can rename or change properties of an existing object.
187
+ */
188
+ export interface ObjectUpdateInstruction extends BaseSchemaChangeInstruction {
189
+ type: 'object_update';
190
+ /** Current name of the object to update */
191
+ object_name: string;
192
+ /** New name for the object (if renaming) */
193
+ new_object_name?: string;
194
+ /** Updated properties (label, description, icon, etc.) */
195
+ changes: ObjectUpdateChanges;
196
+ /**
197
+ * Database impact assessment for this object change.
198
+ * Describes the effect on the underlying database schema.
199
+ */
200
+ database_impact?: DatabaseImpact;
201
+ /**
202
+ * Generated upgrade scripts for different database dialects.
203
+ * Maps dialect name to upgrade script.
204
+ * Example: { postgresql: {...}, mysql: {...} }
205
+ */
206
+ upgrade_scripts?: Record<string, UpgradeScript>;
207
+ }
208
+ /**
209
+ * Instruction to delete (remove) an entire object.
210
+ */
211
+ export interface ObjectDeleteInstruction extends BaseSchemaChangeInstruction {
212
+ type: 'object_delete';
213
+ /** Name of the object to delete */
214
+ object_name: string;
215
+ /**
216
+ * Strategy for handling existing data in the object.
217
+ * - 'drop': Remove the object and all its data (irreversible)
218
+ * - 'archive': Move all data to an archive/backup location
219
+ * - 'soft': Mark as deleted but keep data (for rollback)
220
+ */
221
+ deletion_strategy?: 'drop' | 'archive' | 'soft';
222
+ /** Backup location if using 'archive' strategy */
223
+ archive_location?: string;
224
+ /**
225
+ * Handle dependent objects/relationships.
226
+ * - 'cascade': Also delete related records in other objects
227
+ * - 'fail': Fail if there are dependent records
228
+ * - 'nullify': Set foreign key references to null
229
+ */
230
+ cascade_strategy?: 'cascade' | 'fail' | 'nullify';
231
+ /**
232
+ * Database impact assessment for this object deletion.
233
+ * Describes the effect on the underlying database schema.
234
+ */
235
+ database_impact?: DatabaseImpact;
236
+ /**
237
+ * Generated upgrade scripts for different database dialects.
238
+ * Maps dialect name to upgrade script.
239
+ * Example: { postgresql: {...}, mysql: {...} }
240
+ */
241
+ upgrade_scripts?: Record<string, UpgradeScript>;
242
+ }
243
+ /**
244
+ * Union type for all schema change instructions.
245
+ */
246
+ export type SchemaChangeInstruction = FieldUpdateInstruction | FieldDeleteInstruction | ObjectUpdateInstruction | ObjectDeleteInstruction;
247
+ /**
248
+ * Represents a single migration step in a migration sequence.
249
+ */
250
+ export interface MigrationStep {
251
+ /** Unique identifier for this step */
252
+ id: string;
253
+ /** Human-readable name for this step */
254
+ name: string;
255
+ /** Description of what this step does */
256
+ description?: string;
257
+ /** Schema change instruction to execute */
258
+ instruction: SchemaChangeInstruction;
259
+ /**
260
+ * Whether this step can be automatically rolled back.
261
+ * Default: true
262
+ */
263
+ reversible?: boolean;
264
+ /**
265
+ * Optional rollback instruction (if different from automatic inverse).
266
+ */
267
+ rollback_instruction?: SchemaChangeInstruction;
268
+ /**
269
+ * Dependencies on other migration steps (by step ID).
270
+ * This step will only execute after dependencies are complete.
271
+ */
272
+ depends_on?: string[];
273
+ }
274
+ /**
275
+ * Configuration for a complete migration.
276
+ * Groups multiple schema changes into a versioned migration.
277
+ */
278
+ export interface MigrationConfig {
279
+ /** Unique identifier for this migration (e.g., 'v1.0_add_user_fields') */
280
+ id: string;
281
+ /** Semantic version number (e.g., '1.2.0') */
282
+ version: string;
283
+ /** Human-readable name for this migration */
284
+ name: string;
285
+ /** Detailed description of the migration purpose */
286
+ description?: string;
287
+ /** Author of the migration */
288
+ author?: string;
289
+ /** Timestamp when the migration was created (ISO 8601) */
290
+ created_at?: string;
291
+ /** Ordered list of migration steps to execute */
292
+ steps: MigrationStep[];
293
+ /**
294
+ * Whether this migration can be automatically rolled back.
295
+ * Default: true if all steps are reversible
296
+ */
297
+ reversible?: boolean;
298
+ /**
299
+ * Dependencies on other migrations (by migration ID).
300
+ * This migration will only run after dependencies are applied.
301
+ */
302
+ depends_on?: string[];
303
+ /**
304
+ * Tags for categorization and filtering.
305
+ * Examples: ['schema', 'data', 'hotfix', 'feature']
306
+ */
307
+ tags?: string[];
308
+ }
309
+ /**
310
+ * Represents the execution status of a migration.
311
+ */
312
+ export interface MigrationStatus {
313
+ /** Migration ID */
314
+ migration_id: string;
315
+ /** Execution status */
316
+ status: 'pending' | 'running' | 'completed' | 'failed' | 'rolled_back';
317
+ /** Timestamp when execution started */
318
+ started_at?: string;
319
+ /** Timestamp when execution completed */
320
+ completed_at?: string;
321
+ /** Error message if failed */
322
+ error?: string;
323
+ /** Number of steps completed */
324
+ steps_completed?: number;
325
+ /** Total number of steps */
326
+ steps_total?: number;
327
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.js","sourceRoot":"","sources":["../src/migration.ts"],"names":[],"mappings":""}
@@ -0,0 +1,276 @@
1
+ /**
2
+ * Report Metadata Definition
3
+ *
4
+ * Defines the structure for reports, data summaries, and analytics in ObjectQL.
5
+ * Reports aggregate and visualize data from objects with grouping, filtering, and calculations.
6
+ *
7
+ * Based on patterns from Salesforce Reports, Tableau, and similar BI platforms.
8
+ */
9
+ import { ViewFilter, ViewFilterGroup, ViewColumn } from './view';
10
+ /**
11
+ * Types of reports supported by ObjectQL
12
+ */
13
+ export type ReportType = 'tabular' | 'summary' | 'matrix' | 'chart' | 'dashboard' | 'custom';
14
+ /**
15
+ * Chart types for visualization
16
+ */
17
+ export type ChartType = 'bar' | 'column' | 'line' | 'area' | 'pie' | 'donut' | 'scatter' | 'bubble' | 'funnel' | 'gauge' | 'radar' | 'heatmap' | 'treemap' | 'waterfall' | 'custom';
18
+ /**
19
+ * Aggregation functions for report calculations
20
+ */
21
+ export type AggregationFunction = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'median' | 'mode' | 'stddev' | 'variance' | 'distinct_count' | 'first' | 'last' | 'custom';
22
+ /**
23
+ * Grouping configuration for reports
24
+ */
25
+ export interface ReportGrouping {
26
+ /** Field to group by */
27
+ field: string;
28
+ /** Display label */
29
+ label?: string;
30
+ /** Sort order for groups */
31
+ sort?: 'asc' | 'desc';
32
+ /** Group by date interval (for date fields) */
33
+ date_interval?: 'day' | 'week' | 'month' | 'quarter' | 'year';
34
+ /** Group by numeric range (for numeric fields) */
35
+ numeric_range?: {
36
+ /** Range size */
37
+ size: number;
38
+ /** Starting value */
39
+ start?: number;
40
+ };
41
+ /** Show subtotals for this grouping */
42
+ show_subtotals?: boolean;
43
+ /** Limit number of groups */
44
+ limit?: number;
45
+ }
46
+ /**
47
+ * Aggregation/calculation configuration
48
+ */
49
+ export interface ReportAggregation {
50
+ /** Field to aggregate */
51
+ field: string;
52
+ /** Aggregation function */
53
+ function: AggregationFunction;
54
+ /** Display label */
55
+ label?: string;
56
+ /** Display format */
57
+ format?: string;
58
+ /** Custom aggregation expression */
59
+ expression?: string;
60
+ /** Show in totals row */
61
+ show_in_total?: boolean;
62
+ }
63
+ /**
64
+ * Formula field for calculated columns
65
+ */
66
+ export interface ReportFormula {
67
+ /** Formula name */
68
+ name: string;
69
+ /** Display label */
70
+ label?: string;
71
+ /** Formula expression */
72
+ expression: string;
73
+ /** Data type of result */
74
+ type?: 'number' | 'text' | 'date' | 'boolean';
75
+ /** Display format */
76
+ format?: string;
77
+ /** Description of what this formula calculates */
78
+ description?: string;
79
+ }
80
+ /**
81
+ * Chart configuration for report visualization
82
+ */
83
+ export interface ReportChartConfig {
84
+ /** Chart type */
85
+ type: ChartType;
86
+ /** Chart title */
87
+ title?: string;
88
+ /** Field for X-axis */
89
+ x_axis?: string;
90
+ /** Field(s) for Y-axis */
91
+ y_axis?: string | string[];
92
+ /** Field for chart series/legend */
93
+ series_field?: string;
94
+ /** Chart colors */
95
+ colors?: string[];
96
+ /** Show legend */
97
+ show_legend?: boolean;
98
+ /** Legend position */
99
+ legend_position?: 'top' | 'bottom' | 'left' | 'right';
100
+ /** Show data labels */
101
+ show_data_labels?: boolean;
102
+ /** Chart height in pixels */
103
+ height?: number;
104
+ /** Chart width in pixels */
105
+ width?: number;
106
+ /** Enable drill-down */
107
+ enable_drill_down?: boolean;
108
+ /** Custom chart configuration */
109
+ custom_config?: Record<string, any>;
110
+ }
111
+ /**
112
+ * Matrix report dimension configuration
113
+ */
114
+ export interface MatrixDimension {
115
+ /** Field for this dimension */
116
+ field: string;
117
+ /** Display label */
118
+ label?: string;
119
+ /** Sort order */
120
+ sort?: 'asc' | 'desc';
121
+ /** Show totals */
122
+ show_totals?: boolean;
123
+ }
124
+ /**
125
+ * Export configuration for reports
126
+ */
127
+ export interface ReportExportConfig {
128
+ /** Enabled export formats */
129
+ formats?: ('pdf' | 'xlsx' | 'csv' | 'json' | 'html')[];
130
+ /** Include charts in export */
131
+ include_charts?: boolean;
132
+ /** Export filename template */
133
+ filename_template?: string;
134
+ /** Page orientation for PDF */
135
+ page_orientation?: 'portrait' | 'landscape';
136
+ /** Paper size for PDF */
137
+ paper_size?: 'A4' | 'Letter' | 'Legal';
138
+ }
139
+ /**
140
+ * Scheduling configuration for automated reports
141
+ */
142
+ export interface ReportScheduleConfig {
143
+ /** Enable scheduled execution */
144
+ enabled: boolean;
145
+ /** Cron expression for schedule */
146
+ cron?: string;
147
+ /** Timezone for schedule */
148
+ timezone?: string;
149
+ /** Email recipients for scheduled reports */
150
+ recipients?: string[];
151
+ /** Email subject template */
152
+ email_subject?: string;
153
+ /** Email body template */
154
+ email_body?: string;
155
+ /** Export format for scheduled report */
156
+ format?: 'pdf' | 'xlsx' | 'csv';
157
+ }
158
+ /**
159
+ * Complete report configuration
160
+ */
161
+ export interface ReportConfig {
162
+ /** Unique report identifier */
163
+ name: string;
164
+ /** Display label */
165
+ label: string;
166
+ /** Report type */
167
+ type: ReportType;
168
+ /** Primary object for the report */
169
+ object: string;
170
+ /** Report description */
171
+ description?: string;
172
+ /** Icon for the report */
173
+ icon?: string;
174
+ /** Columns to display */
175
+ columns?: ViewColumn[];
176
+ /** Filters to apply */
177
+ filters?: (ViewFilter | ViewFilterGroup)[];
178
+ /** Grouping configuration */
179
+ groupings?: ReportGrouping[];
180
+ /** Aggregations/calculations */
181
+ aggregations?: ReportAggregation[];
182
+ /** Formula fields */
183
+ formulas?: ReportFormula[];
184
+ /** Chart configuration */
185
+ chart?: ReportChartConfig;
186
+ /** Matrix report row dimension */
187
+ row_dimension?: MatrixDimension;
188
+ /** Matrix report column dimension */
189
+ column_dimension?: MatrixDimension;
190
+ /** Limit number of rows */
191
+ limit?: number;
192
+ /** Enable drill-down to records */
193
+ enable_drill_down?: boolean;
194
+ /** Show record count */
195
+ show_record_count?: boolean;
196
+ /** Show grand totals */
197
+ show_grand_total?: boolean;
198
+ /** Export configuration */
199
+ export?: ReportExportConfig;
200
+ /** Scheduling configuration */
201
+ schedule?: ReportScheduleConfig;
202
+ /** Cache configuration */
203
+ cache?: {
204
+ /** Enable caching */
205
+ enabled?: boolean;
206
+ /** Cache duration in seconds */
207
+ duration?: number;
208
+ };
209
+ /** Access control */
210
+ permissions?: {
211
+ /** Roles that can view this report */
212
+ view?: string[];
213
+ /** Roles that can edit report configuration */
214
+ edit?: string[];
215
+ /** Roles that can export */
216
+ export?: string[];
217
+ };
218
+ /** Whether this report is shared with all users */
219
+ is_public?: boolean;
220
+ /** Owner of the report (for personal reports) */
221
+ owner?: string;
222
+ /** Folder/category for organization */
223
+ folder?: string;
224
+ /** Custom report configuration */
225
+ config?: Record<string, any>;
226
+ /** AI context for report generation */
227
+ ai_context?: {
228
+ /** Business question this report answers */
229
+ intent?: string;
230
+ /** Target audience */
231
+ audience?: string;
232
+ /** Key insights to highlight */
233
+ insights?: string[];
234
+ /** Recommended visualizations */
235
+ visualizations?: string[];
236
+ };
237
+ }
238
+ /**
239
+ * Report execution result
240
+ */
241
+ export interface ReportResult {
242
+ /** Report name */
243
+ report_name: string;
244
+ /** Execution timestamp */
245
+ executed_at: string;
246
+ /** Data rows */
247
+ rows: any[];
248
+ /** Total record count */
249
+ total_count: number;
250
+ /** Aggregation results */
251
+ aggregations?: Record<string, any>;
252
+ /** Grand totals */
253
+ grand_total?: Record<string, any>;
254
+ /** Chart data */
255
+ chart_data?: any;
256
+ /** Execution time in milliseconds */
257
+ execution_time?: number;
258
+ /** Whether result was from cache */
259
+ from_cache?: boolean;
260
+ }
261
+ /**
262
+ * Lightweight report reference
263
+ * Used in navigation, dropdowns, and report selectors
264
+ */
265
+ export interface ReportReference {
266
+ /** Report name/identifier */
267
+ name: string;
268
+ /** Display label */
269
+ label?: string;
270
+ /** Icon */
271
+ icon?: string;
272
+ /** Report type */
273
+ type?: ReportType;
274
+ /** Folder/category */
275
+ folder?: string;
276
+ }
package/dist/report.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ /**
3
+ * Report Metadata Definition
4
+ *
5
+ * Defines the structure for reports, data summaries, and analytics in ObjectQL.
6
+ * Reports aggregate and visualize data from objects with grouping, filtering, and calculations.
7
+ *
8
+ * Based on patterns from Salesforce Reports, Tableau, and similar BI platforms.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ //# sourceMappingURL=report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.js","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG"}