@objectql/types 1.6.0 → 1.7.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.
package/src/validation.ts DELETED
@@ -1,390 +0,0 @@
1
- /**
2
- * Validation system types based on the validation metadata specification.
3
- * These types define the structure for metadata-driven validation rules.
4
- */
5
-
6
- import { ObjectDoc } from './object';
7
-
8
- /**
9
- * Types of validation rules supported by ObjectQL.
10
- */
11
- export type ValidationRuleType =
12
- | 'field' // Built-in field validation
13
- | 'cross_field' // Validate relationships between fields
14
- | 'business_rule' // Declarative business rules
15
- | 'state_machine' // Enforce valid state transitions
16
- | 'unique' // Uniqueness validation
17
- | 'dependency' // Validate related record constraints
18
- | 'custom'; // Custom validation logic
19
-
20
- /**
21
- * Severity levels for validation errors.
22
- */
23
- export type ValidationSeverity = 'error' | 'warning' | 'info';
24
-
25
- /**
26
- * Operations that can trigger validation.
27
- */
28
- export type ValidationTrigger = 'create' | 'update' | 'delete';
29
-
30
- /**
31
- * Comparison operators for validation rules.
32
- */
33
- export type ValidationOperator =
34
- | '=' | '!='
35
- | '>' | '>=' | '<' | '<='
36
- | 'in' | 'not_in'
37
- | 'contains' | 'not_contains'
38
- | 'starts_with' | 'ends_with';
39
-
40
- /**
41
- * AI context for validation rules.
42
- * Provides semantic information for AI tools to understand validation intent.
43
- */
44
- export interface ValidationAiContext {
45
- /** Business intent behind the validation rule */
46
- intent?: string;
47
- /** Business rule description in natural language */
48
- business_rule?: string;
49
- /** Impact level if validation fails */
50
- error_impact?: 'high' | 'medium' | 'low';
51
- /** External dependencies required for validation */
52
- data_dependency?: string;
53
- /** External system dependencies */
54
- external_dependency?: string;
55
- /** Examples of valid/invalid data */
56
- examples?: {
57
- valid?: any[];
58
- invalid?: any[];
59
- };
60
- /** Algorithm description for complex validation */
61
- algorithm?: string;
62
- /** Visualization of the validation logic */
63
- visualization?: string;
64
- /** Rationale for the rule */
65
- rationale?: string;
66
- /** Decision logic in natural language */
67
- decision_logic?: string;
68
- /** Compliance requirements */
69
- compliance?: string;
70
- }
71
-
72
- /**
73
- * Condition for applying validation rules.
74
- */
75
- export interface ValidationCondition {
76
- /** Field to check */
77
- field?: string;
78
- /** Comparison operator */
79
- operator?: ValidationOperator;
80
- /** Value to compare against */
81
- value?: any;
82
- /** Field name to compare against (for cross-field validation) */
83
- compare_to?: string;
84
- /** Expression to evaluate */
85
- expression?: string;
86
- /** Logical AND conditions */
87
- all_of?: ValidationCondition[];
88
- /** Logical OR conditions */
89
- any_of?: ValidationCondition[];
90
- }
91
-
92
- /**
93
- * State transition definition for state machine validation.
94
- */
95
- export interface StateTransition {
96
- /** States that can transition to this state */
97
- allowed_next?: string[];
98
- /** Whether this is a terminal state */
99
- is_terminal?: boolean;
100
- /** AI context for the transition */
101
- ai_context?: ValidationAiContext;
102
- }
103
-
104
- /**
105
- * Relationship lookup for business rule validation.
106
- */
107
- export interface ValidationRelationship {
108
- /** Related object name */
109
- object?: string;
110
- /** Field that links to the related object */
111
- via?: string;
112
- /** Field(s) to fetch from related object */
113
- field?: string;
114
- fields?: string[];
115
- /** Validation to apply on related record */
116
- validate?: ValidationCondition;
117
- }
118
-
119
- /**
120
- * Business rule constraint definition.
121
- */
122
- export interface BusinessRuleConstraint {
123
- /** Expression to evaluate */
124
- expression?: string;
125
- /** Relationships needed for the rule */
126
- relationships?: Record<string, ValidationRelationship>;
127
- /** Logical AND conditions */
128
- all_of?: ValidationCondition[];
129
- /** Logical OR conditions */
130
- any_of?: ValidationCondition[];
131
- /** Required field condition */
132
- then_require?: ValidationCondition[];
133
- }
134
-
135
- /**
136
- * Field validation configuration (built into FieldConfig).
137
- */
138
- export interface FieldValidation {
139
- /** Format validation (email, url, etc.) */
140
- format?: 'email' | 'url' | 'phone' | 'date' | 'datetime';
141
- /** Allowed protocols for URL validation */
142
- protocols?: string[];
143
- /** Minimum value for numbers */
144
- min?: number;
145
- /** Maximum value for numbers */
146
- max?: number;
147
- /** Minimum length for strings */
148
- min_length?: number;
149
- /** Maximum length for strings */
150
- max_length?: number;
151
- /** Regular expression pattern for validation */
152
- pattern?: string;
153
- /** @deprecated Use pattern instead */
154
- regex?: string;
155
- /** Custom validation message */
156
- message?: string;
157
- }
158
-
159
- /**
160
- * Base validation rule definition.
161
- */
162
- export interface ValidationRule {
163
- /** Unique name of the rule */
164
- name: string;
165
- /** Type of validation rule */
166
- type: ValidationRuleType;
167
- /** Human-readable error message */
168
- message: string | Record<string, string>;
169
- /** Error code for programmatic handling */
170
- error_code?: string;
171
- /** Severity level */
172
- severity?: ValidationSeverity;
173
- /** Operations that trigger this rule */
174
- trigger?: ValidationTrigger[];
175
- /** Fields that trigger this rule when changed */
176
- fields?: string[];
177
- /** Contexts where this rule applies */
178
- context?: string[];
179
- /** Skip in bulk operations */
180
- skip_bulk?: boolean;
181
- /** AI context for understanding the rule */
182
- ai_context?: ValidationAiContext;
183
- /** Condition for applying the rule */
184
- apply_when?: ValidationCondition;
185
- /** Whether this is an async validation */
186
- async?: boolean;
187
- /** Timeout for async validation (ms) */
188
- timeout?: number;
189
- }
190
-
191
- /**
192
- * Cross-field validation rule.
193
- */
194
- export interface CrossFieldValidationRule extends ValidationRule {
195
- type: 'cross_field';
196
- /** The validation rule to apply */
197
- rule?: ValidationCondition;
198
- }
199
-
200
- /**
201
- * Business rule validation.
202
- */
203
- export interface BusinessRuleValidationRule extends ValidationRule {
204
- type: 'business_rule';
205
- /** The business rule constraint */
206
- constraint?: BusinessRuleConstraint;
207
- }
208
-
209
- /**
210
- * State machine validation rule.
211
- */
212
- export interface StateMachineValidationRule extends ValidationRule {
213
- type: 'state_machine';
214
- /** Field containing the state */
215
- field: string;
216
- /** Valid state transitions */
217
- transitions?: Record<string, StateTransition | string[]>;
218
- /** Initial states */
219
- initial_states?: string[];
220
- /** Transition conditions */
221
- transition_conditions?: Record<string, any>;
222
- }
223
-
224
- /**
225
- * Uniqueness validation rule.
226
- */
227
- export interface UniquenessValidationRule extends ValidationRule {
228
- type: 'unique';
229
- /** Field to check for uniqueness */
230
- field?: string;
231
- /** Multiple fields for composite uniqueness */
232
- fields?: string[];
233
- /** Case sensitivity for string comparison */
234
- case_sensitive?: boolean;
235
- /** Scope constraint for conditional uniqueness */
236
- scope?: ValidationCondition;
237
- }
238
-
239
- /**
240
- * Dependency validation rule.
241
- */
242
- export interface DependencyValidationRule extends ValidationRule {
243
- type: 'dependency';
244
- /** Validation condition */
245
- condition?: {
246
- /** Lookup validation */
247
- lookup?: ValidationRelationship;
248
- /** Related records check */
249
- has_related?: {
250
- object: string;
251
- relation_field: string;
252
- filter?: ValidationCondition[];
253
- };
254
- };
255
- }
256
-
257
- /**
258
- * Custom validation rule with validator function.
259
- */
260
- export interface CustomValidationRule extends ValidationRule {
261
- type: 'custom';
262
- /** Validator function as string */
263
- validator?: string;
264
- /** Error message template */
265
- error_message_template?: string;
266
- /** Message parameters */
267
- message_params?: Record<string, any>;
268
- }
269
-
270
- /**
271
- * Union type for all validation rules.
272
- */
273
- export type AnyValidationRule =
274
- | ValidationRule
275
- | CrossFieldValidationRule
276
- | BusinessRuleValidationRule
277
- | StateMachineValidationRule
278
- | UniquenessValidationRule
279
- | DependencyValidationRule
280
- | CustomValidationRule;
281
-
282
- /**
283
- * Validation group definition.
284
- */
285
- export interface ValidationGroup {
286
- /** Group name */
287
- name: string;
288
- /** Group description */
289
- description?: string;
290
- /** Rules in this group */
291
- rules: string[];
292
- /** Whether group runs asynchronously */
293
- async?: boolean;
294
- /** Whether this group is required */
295
- required?: boolean;
296
- }
297
-
298
- /**
299
- * Complete validation configuration for an object.
300
- */
301
- export interface ValidationConfig {
302
- /** Name of the validation configuration */
303
- name: string;
304
- /** Object this validation applies to */
305
- object: string;
306
- /** Description */
307
- description?: string;
308
- /** AI context for the overall validation strategy */
309
- ai_context?: ValidationAiContext;
310
- /** Validation rules */
311
- rules: AnyValidationRule[];
312
- /** Validation groups */
313
- validation_groups?: ValidationGroup[];
314
- }
315
-
316
- /**
317
- * Context provided to validation functions.
318
- */
319
- export interface ValidationContext {
320
- /** Current record data */
321
- record: ObjectDoc;
322
- /** Previous record data (for updates) */
323
- previousRecord?: ObjectDoc;
324
- /** Current user */
325
- user?: any;
326
- /** API access for queries */
327
- api?: any;
328
- /** HTTP client for external calls */
329
- http?: any;
330
- /** Operation type */
331
- operation: ValidationTrigger;
332
- /** Additional metadata */
333
- metadata?: {
334
- objectName: string;
335
- ruleName: string;
336
- [key: string]: any;
337
- };
338
- /** Changed fields (for updates) */
339
- changedFields?: string[];
340
- }
341
-
342
- /**
343
- * Result of a single validation rule.
344
- */
345
- export interface ValidationRuleResult {
346
- /** Rule name */
347
- rule: string;
348
- /** Whether validation passed */
349
- valid: boolean;
350
- /** Error message if validation failed */
351
- message?: string;
352
- /** Error code */
353
- error_code?: string;
354
- /** Severity level */
355
- severity?: ValidationSeverity;
356
- /** Field(s) that failed validation */
357
- fields?: string[];
358
- /** Additional context */
359
- context?: any;
360
- }
361
-
362
- /**
363
- * Overall validation result for a record.
364
- */
365
- export interface ValidationResult {
366
- /** Whether all validations passed */
367
- valid: boolean;
368
- /** Individual rule results */
369
- results: ValidationRuleResult[];
370
- /** Errors (severity: error) */
371
- errors: ValidationRuleResult[];
372
- /** Warnings (severity: warning) */
373
- warnings: ValidationRuleResult[];
374
- /** Info messages (severity: info) */
375
- info: ValidationRuleResult[];
376
- }
377
-
378
- /**
379
- * Validation error class.
380
- */
381
- export class ValidationError extends Error {
382
- constructor(
383
- message: string,
384
- public results: ValidationRuleResult[],
385
- public code?: string
386
- ) {
387
- super(message);
388
- this.name = 'ValidationError';
389
- }
390
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./src"
6
- },
7
- "include": ["src/**/*"],
8
- "references": []
9
- }