@baasix/types 1.0.1

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/src/schema.ts ADDED
@@ -0,0 +1,343 @@
1
+ /**
2
+ * Schema & Field Types
3
+ * Shared across core, sdk, cli, and app packages
4
+ */
5
+
6
+ // ============================================================================
7
+ // Field Types
8
+ // ============================================================================
9
+
10
+ /**
11
+ * Supported field types in Baasix
12
+ */
13
+ export type FieldType =
14
+ | "String"
15
+ | "Text"
16
+ | "HTML"
17
+ | "Integer"
18
+ | "BigInt"
19
+ | "Float"
20
+ | "Real"
21
+ | "Double"
22
+ | "Decimal"
23
+ | "Boolean"
24
+ | "Date"
25
+ | "DateTime"
26
+ | "Time"
27
+ | "UUID"
28
+ | "SUID"
29
+ | "JSON"
30
+ | "JSONB"
31
+ | "Array"
32
+ | "Geometry"
33
+ | "Point"
34
+ | "LineString"
35
+ | "Polygon"
36
+ | "Enum";
37
+
38
+ /**
39
+ * Default value types supported by Baasix
40
+ */
41
+ export type DefaultValueType =
42
+ | { type: "UUIDV4" }
43
+ | { type: "SUID" }
44
+ | { type: "NOW" }
45
+ | { type: "AUTOINCREMENT" }
46
+ | { type: "SQL"; value: string }
47
+ | { type: "CURRENT_USER" }
48
+ | { type: "CURRENT_TENANT" };
49
+
50
+ /**
51
+ * Field validation rules
52
+ */
53
+ export interface FieldValidationRules {
54
+ /** Minimum value for numeric fields */
55
+ min?: number;
56
+ /** Maximum value for numeric fields */
57
+ max?: number;
58
+ /** Validate as integer */
59
+ isInt?: boolean;
60
+ /** Validate email format */
61
+ isEmail?: boolean;
62
+ /** Validate URL format */
63
+ isUrl?: boolean;
64
+ /** Validate IP address format */
65
+ isIP?: boolean;
66
+ /** Validate UUID format */
67
+ isUUID?: boolean;
68
+ /** String must not be empty */
69
+ notEmpty?: boolean;
70
+ /** String length range [min, max] */
71
+ len?: [number, number];
72
+ /** Pattern matching with regex */
73
+ is?: string;
74
+ /** Pattern matching with regex (alias for is) */
75
+ matches?: string;
76
+ /** @deprecated Use 'is' or 'matches' instead */
77
+ regex?: string;
78
+ }
79
+
80
+ /**
81
+ * Field values configuration (for type-specific options)
82
+ */
83
+ export interface FieldValues {
84
+ /** String length (varchar) */
85
+ length?: number;
86
+ /** String length (alias for length) */
87
+ stringLength?: number;
88
+ /** Decimal precision */
89
+ precision?: number;
90
+ /** Decimal scale */
91
+ scale?: number;
92
+ /** Array element type */
93
+ type?: string;
94
+ /** Enum values */
95
+ values?: string[];
96
+ /** Spatial reference system identifier (for geometry types) */
97
+ srid?: number;
98
+ }
99
+
100
+ /**
101
+ * Field definition
102
+ * Note: `type` is optional because relation fields use `relType` instead
103
+ */
104
+ export interface FieldDefinition {
105
+ /** Field type (required for data fields, not used for relation fields) */
106
+ type?: FieldType | string;
107
+ primaryKey?: boolean;
108
+ allowNull?: boolean;
109
+ unique?: boolean;
110
+ /**
111
+ * Default value for the field
112
+ * Can be a static value or a dynamic type
113
+ */
114
+ defaultValue?: DefaultValueType | string | number | boolean | null | unknown[] | Record<string, unknown>;
115
+ /** Field values configuration (for type-specific options like length, precision, enum values) */
116
+ values?: FieldValues;
117
+ validate?: FieldValidationRules;
118
+ comment?: string;
119
+ /** Field description for documentation */
120
+ description?: string;
121
+ /** Relation type (if this is a relation field) */
122
+ relType?: RelationshipType | string;
123
+ /** Target collection for relations */
124
+ target?: string;
125
+ /** Alias for relation (used in queries) */
126
+ as?: string;
127
+ /** Display format for relations */
128
+ showAs?: string;
129
+ /** Foreign key field name or boolean indicating it's a foreign key */
130
+ foreignKey?: string | boolean;
131
+ /** Target key for relations */
132
+ targetKey?: string;
133
+ /** Junction table name for M2M (or junction config object) */
134
+ through?: string | Record<string, unknown>;
135
+ /** Other key in junction table */
136
+ otherKey?: string;
137
+ /** Display format string */
138
+ displayFormat?: string;
139
+ /** Display options */
140
+ displayOptions?: Record<string, unknown>;
141
+ /** Calculated field expression */
142
+ calculated?: string;
143
+ /** Hide field from API responses */
144
+ hidden?: boolean;
145
+ /** Mark field as system-generated (not user-editable) */
146
+ SystemGenerated?: string | boolean;
147
+ /** Whether to add constraints */
148
+ constraints?: boolean;
149
+ /** Delete behavior for relations */
150
+ onDelete?: "CASCADE" | "RESTRICT" | "SET NULL" | string;
151
+ /** Update behavior for relations */
152
+ onUpdate?: "CASCADE" | "RESTRICT" | "SET NULL" | string;
153
+ /** Whether this is a polymorphic relation (M2A) */
154
+ polymorphic?: boolean;
155
+ /** Target tables for polymorphic (M2A) relations */
156
+ tables?: string[];
157
+ }
158
+
159
+ /**
160
+ * Flattened field info (used in core services)
161
+ */
162
+ export interface FlattenedField {
163
+ name: string;
164
+ type: FieldType;
165
+ allowNull?: boolean;
166
+ unique?: boolean;
167
+ primaryKey?: boolean;
168
+ defaultValue?: unknown;
169
+ validate?: FieldValidationRules;
170
+ relType?: RelationshipType;
171
+ target?: string;
172
+ }
173
+
174
+ /**
175
+ * Field info with full metadata
176
+ */
177
+ export interface FieldInfo extends FlattenedField {
178
+ path: string;
179
+ isRelation: boolean;
180
+ isNested: boolean;
181
+ }
182
+
183
+ // ============================================================================
184
+ // Schema Types
185
+ // ============================================================================
186
+
187
+ /**
188
+ * Index definition
189
+ */
190
+ export interface IndexDefinition {
191
+ /** Index name (auto-generated if not provided) */
192
+ name?: string;
193
+ fields: string[];
194
+ unique?: boolean;
195
+ /** When true, NULL values are considered equal for unique indexes (PostgreSQL 15+) */
196
+ nullsNotDistinct?: boolean;
197
+ type?: "btree" | "hash" | "gin" | "gist";
198
+ }
199
+
200
+ /**
201
+ * Schema definition
202
+ */
203
+ export interface SchemaDefinition {
204
+ name: string;
205
+ timestamps?: boolean;
206
+ paranoid?: boolean;
207
+ sortEnabled?: boolean;
208
+ /**
209
+ * Track user who created/updated records (adds createdBy_Id, updatedBy_Id)
210
+ */
211
+ usertrack?: boolean;
212
+ /**
213
+ * True for M2M/M2A junction tables (system-generated)
214
+ */
215
+ isJunction?: boolean;
216
+ fields: Record<string, FieldDefinition>;
217
+ indexes?: IndexDefinition[];
218
+ }
219
+
220
+ /**
221
+ * Schema info (full schema with collection name)
222
+ */
223
+ export interface SchemaInfo {
224
+ collectionName: string;
225
+ schema: SchemaDefinition;
226
+ relationships?: RelationshipDefinition[];
227
+ }
228
+
229
+ /**
230
+ * Validation result (generic base)
231
+ */
232
+ export interface ValidationResult {
233
+ valid: boolean;
234
+ errors: string[];
235
+ warnings: string[];
236
+ }
237
+
238
+ /**
239
+ * Field validation result
240
+ */
241
+ export interface FieldValidation extends ValidationResult {
242
+ fieldName: string;
243
+ }
244
+
245
+ /**
246
+ * Schema validation result
247
+ */
248
+ export interface SchemaValidation extends ValidationResult {
249
+ collectionName: string;
250
+ fieldValidations?: FieldValidation[];
251
+ }
252
+
253
+ // ============================================================================
254
+ // Relationship Types
255
+ // ============================================================================
256
+
257
+ /**
258
+ * Relationship types
259
+ * - M2O: Many-to-One (creates foreign key with auto-index)
260
+ * - O2M: One-to-Many (virtual reverse of M2O)
261
+ * - O2O: One-to-One (creates foreign key with unique constraint)
262
+ * - M2M: Many-to-Many (creates junction table)
263
+ * - M2A: Many-to-Any (polymorphic junction table)
264
+ *
265
+ * Legacy aliases (deprecated, use M2O/O2M/M2M/O2O instead):
266
+ * - BelongsTo: alias for M2O
267
+ * - HasMany: alias for O2M
268
+ * - HasOne: alias for O2O
269
+ * - BelongsToMany: alias for M2M
270
+ */
271
+ export type RelationshipType =
272
+ | "M2O"
273
+ | "O2M"
274
+ | "M2M"
275
+ | "M2A"
276
+ | "O2O"
277
+ // Legacy aliases for backward compatibility
278
+ | "BelongsTo"
279
+ | "HasMany"
280
+ | "HasOne"
281
+ | "BelongsToMany";
282
+
283
+ /**
284
+ * Association type (alias for RelationshipType)
285
+ */
286
+ export type AssociationType = RelationshipType;
287
+
288
+ /**
289
+ * Relationship definition
290
+ */
291
+ export interface RelationshipDefinition {
292
+ type: RelationshipType;
293
+ target: string;
294
+ name: string;
295
+ alias?: string;
296
+ /**
297
+ * Custom junction table name for M2M/M2A relationships
298
+ */
299
+ through?: string;
300
+ onDelete?: "CASCADE" | "RESTRICT" | "SET NULL";
301
+ onUpdate?: "CASCADE" | "RESTRICT" | "SET NULL";
302
+ /** Target tables for M2A (polymorphic) relationships */
303
+ tables?: string[];
304
+ }
305
+
306
+ /**
307
+ * Association definition (used internally in core)
308
+ */
309
+ export interface AssociationDefinition {
310
+ type: AssociationType;
311
+ foreignKey?: string;
312
+ sourceKey?: string;
313
+ targetKey?: string;
314
+ through?: string;
315
+ as?: string;
316
+ target: string;
317
+ onDelete?: "CASCADE" | "RESTRICT" | "SET NULL";
318
+ onUpdate?: "CASCADE" | "RESTRICT" | "SET NULL";
319
+ }
320
+
321
+ /**
322
+ * Include configuration for relation fetching
323
+ */
324
+ export interface IncludeConfig {
325
+ model: string;
326
+ as?: string;
327
+ attributes?: string[];
328
+ where?: Record<string, unknown>;
329
+ required?: boolean;
330
+ include?: IncludeConfig[];
331
+ }
332
+
333
+ /**
334
+ * Processed include (after parsing)
335
+ */
336
+ export interface ProcessedInclude {
337
+ association: string;
338
+ as: string;
339
+ attributes?: string[];
340
+ where?: Record<string, unknown>;
341
+ required?: boolean;
342
+ include?: ProcessedInclude[];
343
+ }
package/src/spatial.ts ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Spatial/GeoJSON Types
3
+ * Types for geospatial data (PostGIS compatible)
4
+ */
5
+
6
+ // ============================================================================
7
+ // GeoJSON Types
8
+ // ============================================================================
9
+
10
+ /**
11
+ * GeoJSON Point
12
+ */
13
+ export interface GeoJSONPoint {
14
+ type: "Point";
15
+ coordinates: [number, number]; // [longitude, latitude]
16
+ }
17
+
18
+ /**
19
+ * GeoJSON LineString
20
+ */
21
+ export interface GeoJSONLineString {
22
+ type: "LineString";
23
+ coordinates: [number, number][];
24
+ }
25
+
26
+ /**
27
+ * GeoJSON Polygon
28
+ */
29
+ export interface GeoJSONPolygon {
30
+ type: "Polygon";
31
+ coordinates: [number, number][][];
32
+ }
33
+
34
+ /**
35
+ * GeoJSON Geometry (union type)
36
+ */
37
+ export type GeoJSONGeometry = GeoJSONPoint | GeoJSONLineString | GeoJSONPolygon;
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Workflow Types
3
+ * Shared across core, sdk, and app packages
4
+ */
5
+
6
+ // ============================================================================
7
+ // Workflow Types
8
+ // ============================================================================
9
+
10
+ /**
11
+ * Workflow trigger types
12
+ */
13
+ export type WorkflowTriggerType = "manual" | "webhook" | "schedule" | "hook" | "cron";
14
+
15
+ /**
16
+ * Workflow status
17
+ */
18
+ export type WorkflowStatus = "draft" | "active" | "inactive" | "archived";
19
+
20
+ /**
21
+ * Workflow definition
22
+ */
23
+ export interface Workflow {
24
+ id: string;
25
+ name: string;
26
+ description?: string;
27
+ status: WorkflowStatus;
28
+ /** @deprecated Use status instead. Kept for backward compatibility. */
29
+ isActive?: boolean;
30
+ trigger_type?: WorkflowTriggerType;
31
+ /** Alternative trigger format used by SDK */
32
+ trigger?: WorkflowTrigger;
33
+ trigger_cron?: string;
34
+ trigger_webhook_path?: string;
35
+ trigger_webhook_method?: string;
36
+ trigger_hook_collection?: string;
37
+ trigger_hook_action?: string;
38
+ allowed_roles?: string[];
39
+ flow_data?: WorkflowFlowData;
40
+ /** Alternative format: nodes at top level */
41
+ nodes?: WorkflowNode[];
42
+ /** Alternative format: edges at top level */
43
+ edges?: WorkflowEdge[];
44
+ variables?: Record<string, unknown>;
45
+ options?: Record<string, unknown>;
46
+ createdAt?: string;
47
+ updatedAt?: string;
48
+ }
49
+
50
+ /**
51
+ * Workflow flow data (React Flow format)
52
+ */
53
+ export interface WorkflowFlowData {
54
+ nodes: WorkflowNode[];
55
+ edges: WorkflowEdge[];
56
+ viewport?: { x: number; y: number; zoom: number };
57
+ }
58
+
59
+ /**
60
+ * Workflow trigger configuration
61
+ */
62
+ export interface WorkflowTrigger {
63
+ type: WorkflowTriggerType;
64
+ config?: Record<string, unknown>;
65
+ }
66
+
67
+ /**
68
+ * Workflow node
69
+ */
70
+ export interface WorkflowNode {
71
+ id: string;
72
+ type: string;
73
+ data: WorkflowNodeData;
74
+ position: { x: number; y: number };
75
+ }
76
+
77
+ /**
78
+ * Workflow node data
79
+ */
80
+ export interface WorkflowNodeData {
81
+ label?: string;
82
+ [key: string]: unknown;
83
+ }
84
+
85
+ /**
86
+ * Workflow edge
87
+ */
88
+ export interface WorkflowEdge {
89
+ id: string;
90
+ source: string;
91
+ target: string;
92
+ sourceHandle?: string;
93
+ targetHandle?: string;
94
+ condition?: string;
95
+ label?: string;
96
+ }
97
+
98
+ // ============================================================================
99
+ // Workflow Execution Types
100
+ // ============================================================================
101
+
102
+ /**
103
+ * Workflow execution status
104
+ */
105
+ export type WorkflowExecutionStatus =
106
+ | "queued"
107
+ | "pending"
108
+ | "running"
109
+ | "completed"
110
+ | "failed"
111
+ | "cancelled";
112
+
113
+ /**
114
+ * Workflow execution
115
+ */
116
+ export interface WorkflowExecution {
117
+ id: string;
118
+ workflow_Id: string;
119
+ status: WorkflowExecutionStatus;
120
+ triggeredBy?: string;
121
+ triggerData?: Record<string, unknown>;
122
+ result?: Record<string, unknown>;
123
+ error?: string;
124
+ durationMs?: number;
125
+ startedAt?: string;
126
+ completedAt?: string;
127
+ createdAt: string;
128
+ updatedAt?: string;
129
+ }
130
+
131
+ /**
132
+ * Workflow execution log
133
+ */
134
+ export interface WorkflowExecutionLog {
135
+ id: string;
136
+ execution_Id: string;
137
+ nodeId: string;
138
+ nodeType: string;
139
+ status: "pending" | "running" | "completed" | "failed" | "skipped";
140
+ input?: Record<string, unknown>;
141
+ output?: Record<string, unknown>;
142
+ error?: string;
143
+ durationMs?: number;
144
+ startedAt?: string;
145
+ completedAt?: string;
146
+ }