@objectql/types 1.8.1 → 1.8.3
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.
- package/README.md +133 -0
- package/dist/api.d.ts +427 -0
- package/dist/api.js +45 -0
- package/dist/api.js.map +1 -0
- package/dist/app.d.ts +1 -0
- package/dist/driver.d.ts +58 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/migration.d.ts +327 -0
- package/dist/migration.js +3 -0
- package/dist/migration.js.map +1 -0
- package/package.json +14 -1
package/README.md
CHANGED
|
@@ -66,6 +66,17 @@ npm install @objectql/types
|
|
|
66
66
|
- `Driver` - Database driver interface
|
|
67
67
|
- `DriverConfig` - Driver configuration
|
|
68
68
|
|
|
69
|
+
### Migration & Schema Evolution Types
|
|
70
|
+
- `SchemaChangeType` - Types of schema change operations
|
|
71
|
+
- `SchemaChangeInstruction` - Union of all schema change instructions
|
|
72
|
+
- `FieldUpdateInstruction` - Instruction to update/modify a field
|
|
73
|
+
- `FieldDeleteInstruction` - Instruction to delete/remove a field
|
|
74
|
+
- `ObjectUpdateInstruction` - Instruction to update/modify an object
|
|
75
|
+
- `ObjectDeleteInstruction` - Instruction to delete/remove an object
|
|
76
|
+
- `MigrationConfig` - Complete migration configuration
|
|
77
|
+
- `MigrationStep` - Single step in a migration
|
|
78
|
+
- `MigrationStatus` - Execution status of a migration
|
|
79
|
+
|
|
69
80
|
## Usage Examples
|
|
70
81
|
|
|
71
82
|
### Object Definition with Validation
|
|
@@ -253,6 +264,128 @@ interface FieldValidation {
|
|
|
253
264
|
}
|
|
254
265
|
```
|
|
255
266
|
|
|
267
|
+
### Migration & Schema Evolution
|
|
268
|
+
|
|
269
|
+
Define schema changes declaratively for object and field updates/deletions:
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import {
|
|
273
|
+
MigrationConfig,
|
|
274
|
+
FieldUpdateInstruction,
|
|
275
|
+
FieldDeleteInstruction,
|
|
276
|
+
ObjectUpdateInstruction,
|
|
277
|
+
ObjectDeleteInstruction
|
|
278
|
+
} from '@objectql/types';
|
|
279
|
+
|
|
280
|
+
// Define a migration with multiple schema changes
|
|
281
|
+
const migration: MigrationConfig = {
|
|
282
|
+
id: 'v1.2_refactor_user_fields',
|
|
283
|
+
version: '1.2.0',
|
|
284
|
+
name: 'Refactor User Fields',
|
|
285
|
+
description: 'Update user object schema and remove deprecated fields',
|
|
286
|
+
author: 'dev-team',
|
|
287
|
+
created_at: '2026-01-14T00:00:00Z',
|
|
288
|
+
steps: [
|
|
289
|
+
{
|
|
290
|
+
id: 'rename_username_field',
|
|
291
|
+
name: 'Rename username to user_name',
|
|
292
|
+
instruction: {
|
|
293
|
+
type: 'field_update',
|
|
294
|
+
object_name: 'users',
|
|
295
|
+
field_name: 'username',
|
|
296
|
+
new_field_name: 'user_name',
|
|
297
|
+
changes: {
|
|
298
|
+
label: 'User Name',
|
|
299
|
+
description: 'Updated field name for consistency'
|
|
300
|
+
},
|
|
301
|
+
data_migration_strategy: 'auto'
|
|
302
|
+
} as FieldUpdateInstruction,
|
|
303
|
+
reversible: true
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
id: 'update_email_field',
|
|
307
|
+
name: 'Make email field required',
|
|
308
|
+
instruction: {
|
|
309
|
+
type: 'field_update',
|
|
310
|
+
object_name: 'users',
|
|
311
|
+
field_name: 'email',
|
|
312
|
+
changes: {
|
|
313
|
+
required: true,
|
|
314
|
+
unique: true
|
|
315
|
+
},
|
|
316
|
+
data_migration_strategy: 'auto'
|
|
317
|
+
} as FieldUpdateInstruction,
|
|
318
|
+
reversible: true
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
id: 'delete_legacy_field',
|
|
322
|
+
name: 'Remove deprecated legacy_id field',
|
|
323
|
+
instruction: {
|
|
324
|
+
type: 'field_delete',
|
|
325
|
+
object_name: 'users',
|
|
326
|
+
field_name: 'legacy_id',
|
|
327
|
+
deletion_strategy: 'archive',
|
|
328
|
+
archive_location: 'backup/users_legacy_id'
|
|
329
|
+
} as FieldDeleteInstruction,
|
|
330
|
+
reversible: true
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
id: 'update_object_label',
|
|
334
|
+
name: 'Update Users object label',
|
|
335
|
+
instruction: {
|
|
336
|
+
type: 'object_update',
|
|
337
|
+
object_name: 'users',
|
|
338
|
+
changes: {
|
|
339
|
+
label: 'System Users',
|
|
340
|
+
description: 'Updated to reflect new naming convention'
|
|
341
|
+
}
|
|
342
|
+
} as ObjectUpdateInstruction,
|
|
343
|
+
reversible: true
|
|
344
|
+
}
|
|
345
|
+
],
|
|
346
|
+
reversible: true,
|
|
347
|
+
tags: ['schema', 'refactor']
|
|
348
|
+
};
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
**Field Update Example (Type Change):**
|
|
352
|
+
|
|
353
|
+
```typescript
|
|
354
|
+
const changeFieldType: FieldUpdateInstruction = {
|
|
355
|
+
type: 'field_update',
|
|
356
|
+
object_name: 'products',
|
|
357
|
+
field_name: 'price',
|
|
358
|
+
changes: {
|
|
359
|
+
type: 'currency', // Changed from 'number' to 'currency'
|
|
360
|
+
defaultValue: 0
|
|
361
|
+
},
|
|
362
|
+
data_migration_strategy: 'manual',
|
|
363
|
+
transform_script: `
|
|
364
|
+
// Custom transformation for price field
|
|
365
|
+
return {
|
|
366
|
+
amount: oldValue,
|
|
367
|
+
currency: 'USD'
|
|
368
|
+
};
|
|
369
|
+
`,
|
|
370
|
+
description: 'Convert price from number to currency type',
|
|
371
|
+
reason: 'Support multi-currency pricing'
|
|
372
|
+
};
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
**Object Deletion Example:**
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
const deleteObject: ObjectDeleteInstruction = {
|
|
379
|
+
type: 'object_delete',
|
|
380
|
+
object_name: 'temp_imports',
|
|
381
|
+
deletion_strategy: 'archive',
|
|
382
|
+
archive_location: 'backups/temp_imports_archive',
|
|
383
|
+
cascade_strategy: 'nullify',
|
|
384
|
+
description: 'Remove temporary import table',
|
|
385
|
+
reason: 'No longer needed after migration to new import system'
|
|
386
|
+
};
|
|
387
|
+
```
|
|
388
|
+
|
|
256
389
|
## See Also
|
|
257
390
|
|
|
258
391
|
- [@objectql/core](../core) - Core engine with Validator class
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Type Definitions for ObjectQL
|
|
3
|
+
*
|
|
4
|
+
* This file contains TypeScript interfaces for Data API and Metadata API endpoints.
|
|
5
|
+
* These types enable frontend applications to make type-safe API calls.
|
|
6
|
+
*/
|
|
7
|
+
import { UnifiedQuery, FilterExpression } from './query';
|
|
8
|
+
import { ObjectConfig } from './object';
|
|
9
|
+
import { FieldConfig } from './field';
|
|
10
|
+
import { ActionConfig } from './action';
|
|
11
|
+
/**
|
|
12
|
+
* Standardized error codes for ObjectQL API responses
|
|
13
|
+
*/
|
|
14
|
+
export declare enum ApiErrorCode {
|
|
15
|
+
INVALID_REQUEST = "INVALID_REQUEST",
|
|
16
|
+
VALIDATION_ERROR = "VALIDATION_ERROR",
|
|
17
|
+
UNAUTHORIZED = "UNAUTHORIZED",
|
|
18
|
+
FORBIDDEN = "FORBIDDEN",
|
|
19
|
+
NOT_FOUND = "NOT_FOUND",
|
|
20
|
+
CONFLICT = "CONFLICT",
|
|
21
|
+
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
22
|
+
DATABASE_ERROR = "DATABASE_ERROR",
|
|
23
|
+
RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED"
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error details structure with optional field-specific information
|
|
27
|
+
*/
|
|
28
|
+
export interface ApiErrorDetails {
|
|
29
|
+
field?: string;
|
|
30
|
+
reason?: string;
|
|
31
|
+
fields?: Record<string, string>;
|
|
32
|
+
required_permission?: string;
|
|
33
|
+
user_roles?: string[];
|
|
34
|
+
retry_after?: number;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Standard error response structure
|
|
39
|
+
*/
|
|
40
|
+
export interface ApiError {
|
|
41
|
+
code: ApiErrorCode | string;
|
|
42
|
+
message: string;
|
|
43
|
+
details?: ApiErrorDetails;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* ObjectQL Error class for throwing structured errors
|
|
47
|
+
*/
|
|
48
|
+
export declare class ObjectQLError extends Error {
|
|
49
|
+
code: ApiErrorCode | string;
|
|
50
|
+
details?: ApiErrorDetails;
|
|
51
|
+
constructor(error: {
|
|
52
|
+
code: ApiErrorCode | string;
|
|
53
|
+
message: string;
|
|
54
|
+
details?: ApiErrorDetails;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Pagination metadata for list responses
|
|
59
|
+
*/
|
|
60
|
+
export interface PaginationMeta {
|
|
61
|
+
/** Total number of records */
|
|
62
|
+
total: number;
|
|
63
|
+
/** Current page number (1-indexed) */
|
|
64
|
+
page?: number;
|
|
65
|
+
/** Number of items per page */
|
|
66
|
+
size?: number;
|
|
67
|
+
/** Total number of pages */
|
|
68
|
+
pages?: number;
|
|
69
|
+
/** Whether there is a next page */
|
|
70
|
+
has_next?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Base response structure for Data API operations
|
|
74
|
+
*/
|
|
75
|
+
export interface DataApiResponse<T = unknown> {
|
|
76
|
+
/** Error information if the operation failed */
|
|
77
|
+
error?: ApiError;
|
|
78
|
+
/** Additional response fields for successful operations */
|
|
79
|
+
[key: string]: unknown;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Response for list operations (find)
|
|
83
|
+
*/
|
|
84
|
+
export interface DataApiListResponse<T = unknown> extends DataApiResponse<T> {
|
|
85
|
+
/** Array of retrieved items */
|
|
86
|
+
items?: T[];
|
|
87
|
+
/** Pagination metadata */
|
|
88
|
+
meta?: PaginationMeta;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Response for single item operations (findOne, create, update)
|
|
92
|
+
*/
|
|
93
|
+
export interface DataApiItemResponse<T = unknown> extends DataApiResponse<T> {
|
|
94
|
+
/** The item ID */
|
|
95
|
+
_id?: string | number;
|
|
96
|
+
/** Object type identifier */
|
|
97
|
+
'@type'?: string;
|
|
98
|
+
/** Timestamp when created */
|
|
99
|
+
created_at?: string | Date;
|
|
100
|
+
/** Timestamp when last updated */
|
|
101
|
+
updated_at?: string | Date;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Query parameters for GET /api/data/:object (list records)
|
|
105
|
+
*/
|
|
106
|
+
export interface DataApiListParams {
|
|
107
|
+
/** Filter expression (can be FilterExpression array or JSON string) */
|
|
108
|
+
filter?: FilterExpression | string;
|
|
109
|
+
/** Fields to return (array or comma-separated string) */
|
|
110
|
+
fields?: string[] | string;
|
|
111
|
+
/** Sort criteria - array of [field, direction] tuples */
|
|
112
|
+
sort?: [string, 'asc' | 'desc'][] | string;
|
|
113
|
+
/** Maximum number of records to return */
|
|
114
|
+
limit?: number;
|
|
115
|
+
/** Number of records to skip (for pagination) */
|
|
116
|
+
skip?: number;
|
|
117
|
+
/** Offset alias for skip */
|
|
118
|
+
offset?: number;
|
|
119
|
+
/** OData-style top parameter (alias for limit) */
|
|
120
|
+
top?: number;
|
|
121
|
+
/** Expand related records */
|
|
122
|
+
expand?: Record<string, UnifiedQuery>;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Request body for POST /api/data/:object (create single record)
|
|
126
|
+
*/
|
|
127
|
+
export interface DataApiCreateRequest {
|
|
128
|
+
[key: string]: unknown;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Request body for POST /api/data/:object (create multiple records)
|
|
132
|
+
*/
|
|
133
|
+
export type DataApiCreateManyRequest = Array<Record<string, unknown>>;
|
|
134
|
+
/**
|
|
135
|
+
* Request body for PUT /api/data/:object/:id (update record)
|
|
136
|
+
*/
|
|
137
|
+
export interface DataApiUpdateRequest {
|
|
138
|
+
[key: string]: unknown;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Request body for POST /api/data/:object/bulk-update (update many records)
|
|
142
|
+
*/
|
|
143
|
+
export interface DataApiBulkUpdateRequest {
|
|
144
|
+
/** Filter criteria to select records to update */
|
|
145
|
+
filters: FilterExpression;
|
|
146
|
+
/** Data to update */
|
|
147
|
+
data: Record<string, unknown>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Request body for POST /api/data/:object/bulk-delete (delete many records)
|
|
151
|
+
*/
|
|
152
|
+
export interface DataApiBulkDeleteRequest {
|
|
153
|
+
/** Filter criteria to select records to delete */
|
|
154
|
+
filters: FilterExpression;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Response for count operations
|
|
158
|
+
*/
|
|
159
|
+
export interface DataApiCountResponse extends DataApiResponse {
|
|
160
|
+
/** Number of records matching the criteria */
|
|
161
|
+
count?: number;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Response for delete operations
|
|
165
|
+
*/
|
|
166
|
+
export interface DataApiDeleteResponse extends DataApiResponse {
|
|
167
|
+
/** Whether the operation was successful */
|
|
168
|
+
success?: boolean;
|
|
169
|
+
/** Number of deleted records (for bulk operations) */
|
|
170
|
+
deleted_count?: number;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Base response structure for Metadata API operations
|
|
174
|
+
*/
|
|
175
|
+
export interface MetadataApiResponse<T = unknown> {
|
|
176
|
+
/** Error information if the operation failed */
|
|
177
|
+
error?: ApiError;
|
|
178
|
+
/** Additional response fields */
|
|
179
|
+
[key: string]: unknown;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Response for list metadata operations
|
|
183
|
+
*/
|
|
184
|
+
export interface MetadataApiListResponse<T = unknown> extends MetadataApiResponse<T> {
|
|
185
|
+
/** Array of metadata items */
|
|
186
|
+
items: T[];
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Simplified object metadata for list views
|
|
190
|
+
*/
|
|
191
|
+
export interface ObjectMetadataSummary {
|
|
192
|
+
/** Object name (internal identifier) */
|
|
193
|
+
name: string;
|
|
194
|
+
/** Display label */
|
|
195
|
+
label?: string;
|
|
196
|
+
/** Icon identifier */
|
|
197
|
+
icon?: string;
|
|
198
|
+
/** Object description */
|
|
199
|
+
description?: string;
|
|
200
|
+
/** Field definitions (simplified) */
|
|
201
|
+
fields?: Record<string, FieldConfig>;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Detailed object metadata for single object view
|
|
205
|
+
*/
|
|
206
|
+
export interface ObjectMetadataDetail extends ObjectConfig {
|
|
207
|
+
/** Formatted fields with name property populated */
|
|
208
|
+
fields: Record<string, FieldConfig & {
|
|
209
|
+
name: string;
|
|
210
|
+
}>;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Response for GET /api/metadata/objects (list all objects)
|
|
214
|
+
*/
|
|
215
|
+
export interface MetadataApiObjectListResponse extends MetadataApiListResponse<ObjectMetadataSummary> {
|
|
216
|
+
items: ObjectMetadataSummary[];
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Response for GET /api/metadata/object/:name (get single object)
|
|
220
|
+
*/
|
|
221
|
+
export interface MetadataApiObjectDetailResponse extends MetadataApiResponse<ObjectMetadataDetail> {
|
|
222
|
+
/** Object name */
|
|
223
|
+
name: string;
|
|
224
|
+
/** Display label */
|
|
225
|
+
label?: string;
|
|
226
|
+
/** Icon identifier */
|
|
227
|
+
icon?: string;
|
|
228
|
+
/** Description */
|
|
229
|
+
description?: string;
|
|
230
|
+
/** Field definitions with populated names */
|
|
231
|
+
fields: Record<string, FieldConfig & {
|
|
232
|
+
name: string;
|
|
233
|
+
}>;
|
|
234
|
+
/** Available actions */
|
|
235
|
+
actions?: Record<string, ActionConfig>;
|
|
236
|
+
/** Validation rules */
|
|
237
|
+
validation?: ObjectConfig['validation'];
|
|
238
|
+
/** AI configuration */
|
|
239
|
+
ai?: ObjectConfig['ai'];
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Field metadata response
|
|
243
|
+
*/
|
|
244
|
+
export interface FieldMetadataResponse extends MetadataApiResponse<FieldConfig> {
|
|
245
|
+
/** Field name */
|
|
246
|
+
name: string;
|
|
247
|
+
/** Field type */
|
|
248
|
+
type: string;
|
|
249
|
+
/** Display label */
|
|
250
|
+
label?: string;
|
|
251
|
+
/** Whether field is required */
|
|
252
|
+
required?: boolean;
|
|
253
|
+
/** Whether field must be unique */
|
|
254
|
+
unique?: boolean;
|
|
255
|
+
/** Default value */
|
|
256
|
+
defaultValue?: unknown;
|
|
257
|
+
/** Options for select/radio fields */
|
|
258
|
+
options?: unknown[];
|
|
259
|
+
/** Minimum value (for number fields) */
|
|
260
|
+
min?: number;
|
|
261
|
+
/** Maximum value (for number fields) */
|
|
262
|
+
max?: number;
|
|
263
|
+
/** Minimum length (for text fields) */
|
|
264
|
+
min_length?: number;
|
|
265
|
+
/** Maximum length (for text fields) */
|
|
266
|
+
max_length?: number;
|
|
267
|
+
/** Regular expression pattern */
|
|
268
|
+
regex?: string;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Action metadata summary
|
|
272
|
+
*/
|
|
273
|
+
export interface ActionMetadataSummary {
|
|
274
|
+
/** Action name (internal identifier) */
|
|
275
|
+
name: string;
|
|
276
|
+
/** Action type (record or global) */
|
|
277
|
+
type: 'record' | 'global';
|
|
278
|
+
/** Display label */
|
|
279
|
+
label?: string;
|
|
280
|
+
/** Action parameters */
|
|
281
|
+
params?: Record<string, unknown>;
|
|
282
|
+
/** Action description */
|
|
283
|
+
description?: string;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Response for GET /api/metadata/object/:name/actions (list object actions)
|
|
287
|
+
*/
|
|
288
|
+
export interface MetadataApiActionsResponse extends MetadataApiListResponse<ActionMetadataSummary> {
|
|
289
|
+
items: ActionMetadataSummary[];
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Generic metadata entry
|
|
293
|
+
*/
|
|
294
|
+
export interface MetadataEntry {
|
|
295
|
+
/** Metadata type (e.g., 'object', 'view', 'form', 'page') */
|
|
296
|
+
type: string;
|
|
297
|
+
/** Unique identifier */
|
|
298
|
+
id: string;
|
|
299
|
+
/** File path (if loaded from file) */
|
|
300
|
+
path?: string;
|
|
301
|
+
/** Package name (if from a plugin) */
|
|
302
|
+
package?: string;
|
|
303
|
+
/** Actual metadata content */
|
|
304
|
+
content: unknown;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Configuration for Data API client
|
|
308
|
+
*/
|
|
309
|
+
export interface DataApiClientConfig {
|
|
310
|
+
/** Base URL of the ObjectQL server */
|
|
311
|
+
baseUrl: string;
|
|
312
|
+
/** Optional authentication token */
|
|
313
|
+
token?: string;
|
|
314
|
+
/** Custom headers */
|
|
315
|
+
headers?: Record<string, string>;
|
|
316
|
+
/** Request timeout in milliseconds */
|
|
317
|
+
timeout?: number;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Configuration for Metadata API client
|
|
321
|
+
*/
|
|
322
|
+
export interface MetadataApiClientConfig {
|
|
323
|
+
/** Base URL of the ObjectQL server */
|
|
324
|
+
baseUrl: string;
|
|
325
|
+
/** Optional authentication token */
|
|
326
|
+
token?: string;
|
|
327
|
+
/** Custom headers */
|
|
328
|
+
headers?: Record<string, string>;
|
|
329
|
+
/** Request timeout in milliseconds */
|
|
330
|
+
timeout?: number;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Interface for Data API client operations
|
|
334
|
+
*/
|
|
335
|
+
export interface IDataApiClient {
|
|
336
|
+
/**
|
|
337
|
+
* List records from an object
|
|
338
|
+
* @param objectName - Name of the object
|
|
339
|
+
* @param params - Query parameters
|
|
340
|
+
*/
|
|
341
|
+
list<T = unknown>(objectName: string, params?: DataApiListParams): Promise<DataApiListResponse<T>>;
|
|
342
|
+
/**
|
|
343
|
+
* Get a single record by ID
|
|
344
|
+
* @param objectName - Name of the object
|
|
345
|
+
* @param id - Record ID
|
|
346
|
+
*/
|
|
347
|
+
get<T = unknown>(objectName: string, id: string | number): Promise<DataApiItemResponse<T>>;
|
|
348
|
+
/**
|
|
349
|
+
* Create a new record
|
|
350
|
+
* @param objectName - Name of the object
|
|
351
|
+
* @param data - Record data
|
|
352
|
+
*/
|
|
353
|
+
create<T = unknown>(objectName: string, data: DataApiCreateRequest): Promise<DataApiItemResponse<T>>;
|
|
354
|
+
/**
|
|
355
|
+
* Create multiple records
|
|
356
|
+
* @param objectName - Name of the object
|
|
357
|
+
* @param data - Array of record data
|
|
358
|
+
*/
|
|
359
|
+
createMany<T = unknown>(objectName: string, data: DataApiCreateManyRequest): Promise<DataApiListResponse<T>>;
|
|
360
|
+
/**
|
|
361
|
+
* Update a record
|
|
362
|
+
* @param objectName - Name of the object
|
|
363
|
+
* @param id - Record ID
|
|
364
|
+
* @param data - Updated data
|
|
365
|
+
*/
|
|
366
|
+
update<T = unknown>(objectName: string, id: string | number, data: DataApiUpdateRequest): Promise<DataApiItemResponse<T>>;
|
|
367
|
+
/**
|
|
368
|
+
* Update multiple records
|
|
369
|
+
* @param objectName - Name of the object
|
|
370
|
+
* @param request - Bulk update request
|
|
371
|
+
*/
|
|
372
|
+
updateMany(objectName: string, request: DataApiBulkUpdateRequest): Promise<DataApiResponse>;
|
|
373
|
+
/**
|
|
374
|
+
* Delete a record
|
|
375
|
+
* @param objectName - Name of the object
|
|
376
|
+
* @param id - Record ID
|
|
377
|
+
*/
|
|
378
|
+
delete(objectName: string, id: string | number): Promise<DataApiDeleteResponse>;
|
|
379
|
+
/**
|
|
380
|
+
* Delete multiple records
|
|
381
|
+
* @param objectName - Name of the object
|
|
382
|
+
* @param request - Bulk delete request
|
|
383
|
+
*/
|
|
384
|
+
deleteMany(objectName: string, request: DataApiBulkDeleteRequest): Promise<DataApiDeleteResponse>;
|
|
385
|
+
/**
|
|
386
|
+
* Count records
|
|
387
|
+
* @param objectName - Name of the object
|
|
388
|
+
* @param filters - Filter criteria
|
|
389
|
+
*/
|
|
390
|
+
count(objectName: string, filters?: FilterExpression): Promise<DataApiCountResponse>;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Interface for Metadata API client operations
|
|
394
|
+
*/
|
|
395
|
+
export interface IMetadataApiClient {
|
|
396
|
+
/**
|
|
397
|
+
* List all objects
|
|
398
|
+
*/
|
|
399
|
+
listObjects(): Promise<MetadataApiObjectListResponse>;
|
|
400
|
+
/**
|
|
401
|
+
* Get detailed metadata for a specific object
|
|
402
|
+
* @param objectName - Name of the object
|
|
403
|
+
*/
|
|
404
|
+
getObject(objectName: string): Promise<MetadataApiObjectDetailResponse>;
|
|
405
|
+
/**
|
|
406
|
+
* Get field metadata for a specific object field
|
|
407
|
+
* @param objectName - Name of the object
|
|
408
|
+
* @param fieldName - Name of the field
|
|
409
|
+
*/
|
|
410
|
+
getField(objectName: string, fieldName: string): Promise<FieldMetadataResponse>;
|
|
411
|
+
/**
|
|
412
|
+
* List actions for a specific object
|
|
413
|
+
* @param objectName - Name of the object
|
|
414
|
+
*/
|
|
415
|
+
listActions(objectName: string): Promise<MetadataApiActionsResponse>;
|
|
416
|
+
/**
|
|
417
|
+
* List metadata entries by type
|
|
418
|
+
* @param metadataType - Type of metadata (e.g., 'view', 'form', 'page')
|
|
419
|
+
*/
|
|
420
|
+
listByType<T = unknown>(metadataType: string): Promise<MetadataApiListResponse<T>>;
|
|
421
|
+
/**
|
|
422
|
+
* Get a specific metadata entry
|
|
423
|
+
* @param metadataType - Type of metadata
|
|
424
|
+
* @param id - Unique identifier
|
|
425
|
+
*/
|
|
426
|
+
getMetadata<T = unknown>(metadataType: string, id: string): Promise<MetadataApiResponse<T>>;
|
|
427
|
+
}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* API Type Definitions for ObjectQL
|
|
4
|
+
*
|
|
5
|
+
* This file contains TypeScript interfaces for Data API and Metadata API endpoints.
|
|
6
|
+
* These types enable frontend applications to make type-safe API calls.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ObjectQLError = exports.ApiErrorCode = void 0;
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Error Handling Types
|
|
12
|
+
// ============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Standardized error codes for ObjectQL API responses
|
|
15
|
+
*/
|
|
16
|
+
var ApiErrorCode;
|
|
17
|
+
(function (ApiErrorCode) {
|
|
18
|
+
ApiErrorCode["INVALID_REQUEST"] = "INVALID_REQUEST";
|
|
19
|
+
ApiErrorCode["VALIDATION_ERROR"] = "VALIDATION_ERROR";
|
|
20
|
+
ApiErrorCode["UNAUTHORIZED"] = "UNAUTHORIZED";
|
|
21
|
+
ApiErrorCode["FORBIDDEN"] = "FORBIDDEN";
|
|
22
|
+
ApiErrorCode["NOT_FOUND"] = "NOT_FOUND";
|
|
23
|
+
ApiErrorCode["CONFLICT"] = "CONFLICT";
|
|
24
|
+
ApiErrorCode["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
|
25
|
+
ApiErrorCode["DATABASE_ERROR"] = "DATABASE_ERROR";
|
|
26
|
+
ApiErrorCode["RATE_LIMIT_EXCEEDED"] = "RATE_LIMIT_EXCEEDED";
|
|
27
|
+
})(ApiErrorCode || (exports.ApiErrorCode = ApiErrorCode = {}));
|
|
28
|
+
/**
|
|
29
|
+
* ObjectQL Error class for throwing structured errors
|
|
30
|
+
*/
|
|
31
|
+
class ObjectQLError extends Error {
|
|
32
|
+
constructor(error) {
|
|
33
|
+
super(error.message);
|
|
34
|
+
this.name = 'ObjectQLError';
|
|
35
|
+
this.code = error.code;
|
|
36
|
+
this.details = error.details;
|
|
37
|
+
// Preserve proper stack traces in Node.js environments
|
|
38
|
+
const ErrorConstructor = Error;
|
|
39
|
+
if (typeof ErrorConstructor.captureStackTrace === 'function') {
|
|
40
|
+
ErrorConstructor.captureStackTrace(this, ObjectQLError);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ObjectQLError = ObjectQLError;
|
|
45
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAOH,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;GAEG;AACH,IAAY,YAUX;AAVD,WAAY,YAAY;IACpB,mDAAmC,CAAA;IACnC,qDAAqC,CAAA;IACrC,6CAA6B,CAAA;IAC7B,uCAAuB,CAAA;IACvB,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,iDAAiC,CAAA;IACjC,iDAAiC,CAAA;IACjC,2DAA2C,CAAA;AAC/C,CAAC,EAVW,YAAY,4BAAZ,YAAY,QAUvB;AAwBD;;GAEG;AACH,MAAa,aAAc,SAAQ,KAAK;IAIpC,YAAY,KAAkF;QAC1F,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAE7B,uDAAuD;QACvD,MAAM,gBAAgB,GAAG,KAA2F,CAAC;QACrH,IAAI,OAAO,gBAAgB,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;YAC3D,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAC5D,CAAC;IACL,CAAC;CACJ;AAhBD,sCAgBC"}
|
package/dist/app.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface IObjectQL {
|
|
|
8
8
|
getConfigs(): Record<string, ObjectConfig>;
|
|
9
9
|
datasource(name: string): Driver;
|
|
10
10
|
init(): Promise<void>;
|
|
11
|
+
close?(): Promise<void>;
|
|
11
12
|
removePackage(name: string): void;
|
|
12
13
|
metadata: MetadataRegistry;
|
|
13
14
|
registerObject(object: ObjectConfig): void;
|
package/dist/driver.d.ts
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column metadata from database introspection.
|
|
3
|
+
*/
|
|
4
|
+
export interface IntrospectedColumn {
|
|
5
|
+
/** Column name */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Native database type (e.g., 'varchar', 'integer', 'timestamp') */
|
|
8
|
+
type: string;
|
|
9
|
+
/** Whether the column is nullable */
|
|
10
|
+
nullable: boolean;
|
|
11
|
+
/** Default value if any */
|
|
12
|
+
defaultValue?: any;
|
|
13
|
+
/** Whether this is a primary key */
|
|
14
|
+
isPrimary?: boolean;
|
|
15
|
+
/** Whether this column has a unique constraint */
|
|
16
|
+
isUnique?: boolean;
|
|
17
|
+
/** Maximum length for string types */
|
|
18
|
+
maxLength?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Foreign key relationship metadata.
|
|
22
|
+
*/
|
|
23
|
+
export interface IntrospectedForeignKey {
|
|
24
|
+
/** Column name in the source table */
|
|
25
|
+
columnName: string;
|
|
26
|
+
/** Referenced table name */
|
|
27
|
+
referencedTable: string;
|
|
28
|
+
/** Referenced column name */
|
|
29
|
+
referencedColumn: string;
|
|
30
|
+
/** Constraint name */
|
|
31
|
+
constraintName?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Table metadata from database introspection.
|
|
35
|
+
*/
|
|
36
|
+
export interface IntrospectedTable {
|
|
37
|
+
/** Table name */
|
|
38
|
+
name: string;
|
|
39
|
+
/** List of columns */
|
|
40
|
+
columns: IntrospectedColumn[];
|
|
41
|
+
/** List of foreign key relationships */
|
|
42
|
+
foreignKeys: IntrospectedForeignKey[];
|
|
43
|
+
/** Primary key columns */
|
|
44
|
+
primaryKeys: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Complete database schema introspection result.
|
|
48
|
+
*/
|
|
49
|
+
export interface IntrospectedSchema {
|
|
50
|
+
/** Map of table name to table metadata */
|
|
51
|
+
tables: Record<string, IntrospectedTable>;
|
|
52
|
+
}
|
|
1
53
|
export interface Driver {
|
|
2
54
|
find(objectName: string, query: any, options?: any): Promise<any[]>;
|
|
3
55
|
findOne(objectName: string, id: string | number, query?: any, options?: any): Promise<any>;
|
|
@@ -6,6 +58,12 @@ export interface Driver {
|
|
|
6
58
|
delete(objectName: string, id: string | number, options?: any): Promise<any>;
|
|
7
59
|
count(objectName: string, filters: any, options?: any): Promise<number>;
|
|
8
60
|
init?(objects: any[]): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Introspect the database schema to discover existing tables, columns, and relationships.
|
|
63
|
+
* This allows connecting to an existing database without defining metadata.
|
|
64
|
+
* @returns Complete schema information including tables, columns, and foreign keys
|
|
65
|
+
*/
|
|
66
|
+
introspectSchema?(): Promise<IntrospectedSchema>;
|
|
9
67
|
aggregate?(objectName: string, query: any, options?: any): Promise<any>;
|
|
10
68
|
distinct?(objectName: string, field: string, filters?: any, options?: any): Promise<any[]>;
|
|
11
69
|
createMany?(objectName: string, data: any[], options?: any): Promise<any>;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -32,4 +32,6 @@ __exportStar(require("./page"), exports);
|
|
|
32
32
|
__exportStar(require("./loader"), exports);
|
|
33
33
|
__exportStar(require("./application"), exports);
|
|
34
34
|
__exportStar(require("./menu"), exports);
|
|
35
|
+
__exportStar(require("./migration"), exports);
|
|
36
|
+
__exportStar(require("./api"), exports);
|
|
35
37
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,yCAAuB;AACvB,2CAAyB;AACzB,+CAA6B;AAC7B,wCAAsB;AACtB,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B;AAC7B,+CAA6B;AAC7B,yCAAuB;AACvB,2CAAyB;AACzB,gDAA8B;AAC9B,yCAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,yCAAuB;AACvB,2CAAyB;AACzB,+CAA6B;AAC7B,wCAAsB;AACtB,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B;AAC7B,+CAA6B;AAC7B,yCAAuB;AACvB,2CAAyB;AACzB,gDAA8B;AAC9B,yCAAuB;AACvB,8CAA4B;AAC5B,wCAAsB"}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"migration.js","sourceRoot":"","sources":["../src/migration.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@objectql/types",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.3",
|
|
4
|
+
"description": "Pure TypeScript type definitions and interfaces for the ObjectQL protocol - The Contract",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"objectql",
|
|
7
|
+
"types",
|
|
8
|
+
"typescript",
|
|
9
|
+
"interfaces",
|
|
10
|
+
"protocol",
|
|
11
|
+
"schema",
|
|
12
|
+
"metadata",
|
|
13
|
+
"ai-native",
|
|
14
|
+
"orm",
|
|
15
|
+
"database"
|
|
16
|
+
],
|
|
4
17
|
"license": "MIT",
|
|
5
18
|
"main": "dist/index.js",
|
|
6
19
|
"types": "dist/index.d.ts",
|