@dbcube/schema-builder 5.1.1 → 5.1.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/dist/index.d.mts CHANGED
@@ -2,139 +2,141 @@
2
2
  * Main class to handle MySQL database connections and queries.
3
3
  * Implements the Singleton pattern to ensure a single instance of the connection pool.
4
4
  */
5
- declare class Schema {
6
- private name;
7
- private engine;
8
- constructor(name: string);
9
- /**
10
- * Validates cube file comprehensively including syntax, database configuration, and structure
11
- * @param filePath - Path to the cube file
12
- * @returns validation result with any errors found
13
- */
14
- private validateDatabaseConfiguration;
15
- /**
16
- * Finds the line number where @database directive is located
17
- */
18
- private findDatabaseLineNumber;
19
- /**
20
- * Extracts foreign key dependencies from a cube file
21
- */
22
- private extractForeignKeyDependencies;
23
- /**
24
- * Finds the line number where a foreign key table reference is located
25
- */
26
- private findForeignKeyLineNumber;
27
- createDatabase(): Promise<any>;
28
- refreshTables(): Promise<any>;
29
- freshTables(): Promise<any>;
30
- executeSeeders(): Promise<any>;
31
- executeAlters(): Promise<any>;
32
- executeTriggers(): Promise<any>;
5
+ export declare class Schema {
6
+ private name;
7
+ private engine;
8
+ constructor(name: string);
9
+ /**
10
+ * Validates cube file comprehensively including syntax, database configuration, and structure
11
+ * @param filePath - Path to the cube file
12
+ * @returns validation result with any errors found
13
+ */
14
+ private validateDatabaseConfiguration;
15
+ /**
16
+ * Finds the line number where @database directive is located
17
+ */
18
+ private findDatabaseLineNumber;
19
+ /**
20
+ * Extracts foreign key dependencies from a cube file
21
+ */
22
+ private extractForeignKeyDependencies;
23
+ /**
24
+ * Finds the line number where a foreign key table reference is located
25
+ */
26
+ private findForeignKeyLineNumber;
27
+ createDatabase(): Promise<any>;
28
+ refreshTables(): Promise<any>;
29
+ freshTables(): Promise<any>;
30
+ executeSeeders(): Promise<any>;
31
+ executeAlters(): Promise<any>;
32
+ executeTriggers(): Promise<any>;
33
33
  }
34
-
35
- interface ProcessError {
36
- itemName: string;
37
- error: string;
38
- filePath?: string;
39
- lineNumber?: number;
34
+ export interface ProcessError {
35
+ itemName: string;
36
+ error: string;
37
+ filePath?: string;
38
+ lineNumber?: number;
40
39
  }
41
- interface ProcessSummary {
42
- startTime: number;
43
- totalProcessed: number;
44
- successCount: number;
45
- errorCount: number;
46
- processedItems: string[];
47
- operationName: string;
48
- databaseName: string;
49
- errors: ProcessError[];
40
+ export interface ProcessSummary {
41
+ startTime: number;
42
+ totalProcessed: number;
43
+ successCount: number;
44
+ errorCount: number;
45
+ processedItems: string[];
46
+ operationName: string;
47
+ databaseName: string;
48
+ errors: ProcessError[];
50
49
  }
51
- declare class UIUtils {
52
- /**
53
- * Shows animated progress for processing items
54
- */
55
- static showItemProgress(itemName: string, current: number, total: number): Promise<void>;
56
- /**
57
- * Shows success for a processed item
58
- */
59
- static showItemSuccess(itemName: string): void;
60
- /**
61
- * Shows error for an item (simplified - only shows X)
62
- */
63
- static showItemError(itemName: string, error: string): void;
64
- /**
65
- * Shows operation header
66
- */
67
- static showOperationHeader(operationName: string, databaseName: string, icon?: string): void;
68
- /**
69
- * Shows comprehensive operation summary
70
- */
71
- static showOperationSummary(summary: ProcessSummary): void;
72
- /**
73
- * Shows code context around an error location
74
- */
75
- static showCodeContext(filePath: string, lineNumber: number, contextLines?: number): void;
50
+ export declare class UIUtils {
51
+ /**
52
+ * Shows animated progress for processing items
53
+ */
54
+ static showItemProgress(itemName: string, current: number, total: number): Promise<void>;
55
+ /**
56
+ * Shows success for a processed item
57
+ */
58
+ static showItemSuccess(itemName: string): void;
59
+ /**
60
+ * Shows error for an item (simplified - only shows X)
61
+ */
62
+ static showItemError(itemName: string, error: string): void;
63
+ /**
64
+ * Shows operation header
65
+ */
66
+ static showOperationHeader(operationName: string, databaseName: string, icon?: string): void;
67
+ /**
68
+ * Shows comprehensive operation summary
69
+ */
70
+ static showOperationSummary(summary: ProcessSummary): void;
71
+ /**
72
+ * Shows code context around an error location
73
+ */
74
+ static showCodeContext(filePath: string, lineNumber: number, contextLines?: number): void;
76
75
  }
77
-
78
- interface ValidationResult {
79
- isValid: boolean;
80
- errors: ProcessError[];
76
+ export interface ValidationResult {
77
+ isValid: boolean;
78
+ errors: ProcessError[];
81
79
  }
82
- declare class CubeValidator {
83
- private validTypes;
84
- private validOptions;
85
- private validProperties;
86
- private knownAnnotations;
87
- /**
88
- * Validates a cube file comprehensively
89
- */
90
- validateCubeFile(filePath: string): ValidationResult;
91
- private validateAnnotations;
92
- private validateDataTypes;
93
- private validateColumnOptions;
94
- private validateColumnProperties;
95
- private validateRequiredColumnProperties;
96
- private validateGeneralSyntax;
97
- private validateOverallStructure;
98
- private getColumnTypeForOptions;
99
- private isOptionCompatibleWithType;
100
- private isInsideColumnsBlock;
101
- private isInsideForeignKeyObject;
80
+ export declare class CubeValidator {
81
+ private validTypes;
82
+ private validOptions;
83
+ private validProperties;
84
+ private knownAnnotations;
85
+ /**
86
+ * Validates a cube file comprehensively
87
+ */
88
+ validateCubeFile(filePath: string): ValidationResult;
89
+ private validateAnnotations;
90
+ private validateDataTypes;
91
+ private validateColumnOptions;
92
+ private validateColumnProperties;
93
+ private isInsideIndexesBlock;
94
+ private validateRequiredColumnProperties;
95
+ private validateGeneralSyntax;
96
+ private validateOverallStructure;
97
+ private getColumnTypeForOptions;
98
+ private isOptionCompatibleWithType;
99
+ private isInsideColumnsBlock;
100
+ private isInsideForeignKeyObject;
102
101
  }
103
-
104
- interface ExecutionOrder {
105
- tables: string[];
106
- seeders: string[];
107
- timestamp: string;
102
+ export interface ExecutionOrder {
103
+ tables: string[];
104
+ seeders: string[];
105
+ timestamp: string;
108
106
  }
109
- declare class DependencyResolver {
110
- /**
111
- * Resolves table dependencies and creates execution order
112
- */
113
- static resolveDependencies(cubeFiles: string[], cubeType?: 'table' | 'seeder'): ExecutionOrder;
114
- /**
115
- * Extracts dependencies from cube files
116
- */
117
- private static extractDependencies;
118
- /**
119
- * Extracts foreign key references from a cube file
120
- */
121
- private static extractForeignKeyReferences;
122
- /**
123
- * Performs topological sort to determine execution order
124
- */
125
- private static topologicalSort;
126
- /**
127
- * Saves the execution order to .dbcube/orderexecute.json
128
- */
129
- private static saveExecutionOrder;
130
- /**
131
- * Loads the execution order from .dbcube/orderexecute.json
132
- */
133
- static loadExecutionOrder(): ExecutionOrder | null;
134
- /**
135
- * Orders cube files based on saved execution order
136
- */
137
- static orderCubeFiles(cubeFiles: string[], cubeType: 'table' | 'seeder'): string[];
107
+ export declare class DependencyResolver {
108
+ /**
109
+ * Resolves table dependencies and creates execution order
110
+ */
111
+ static resolveDependencies(cubeFiles: string[], cubeType?: "table" | "seeder"): ExecutionOrder;
112
+ /**
113
+ * Extracts dependencies from cube files
114
+ */
115
+ private static extractDependencies;
116
+ /**
117
+ * Extracts foreign key references from a cube file
118
+ */
119
+ private static extractForeignKeyReferences;
120
+ /**
121
+ * Performs topological sort to determine execution order
122
+ */
123
+ private static topologicalSort;
124
+ /**
125
+ * Saves the execution order to .dbcube/orderexecute.json
126
+ */
127
+ private static saveExecutionOrder;
128
+ /**
129
+ * Loads the execution order from .dbcube/orderexecute.json
130
+ */
131
+ static loadExecutionOrder(): ExecutionOrder | null;
132
+ /**
133
+ * Orders cube files based on saved execution order
134
+ */
135
+ static orderCubeFiles(cubeFiles: string[], cubeType: "table" | "seeder"): string[];
138
136
  }
139
137
 
140
- export { CubeValidator, DependencyResolver, Schema, UIUtils, Schema as default };
138
+ export {
139
+ Schema as default,
140
+ };
141
+
142
+ export {};
package/dist/index.d.ts CHANGED
@@ -2,139 +2,141 @@
2
2
  * Main class to handle MySQL database connections and queries.
3
3
  * Implements the Singleton pattern to ensure a single instance of the connection pool.
4
4
  */
5
- declare class Schema {
6
- private name;
7
- private engine;
8
- constructor(name: string);
9
- /**
10
- * Validates cube file comprehensively including syntax, database configuration, and structure
11
- * @param filePath - Path to the cube file
12
- * @returns validation result with any errors found
13
- */
14
- private validateDatabaseConfiguration;
15
- /**
16
- * Finds the line number where @database directive is located
17
- */
18
- private findDatabaseLineNumber;
19
- /**
20
- * Extracts foreign key dependencies from a cube file
21
- */
22
- private extractForeignKeyDependencies;
23
- /**
24
- * Finds the line number where a foreign key table reference is located
25
- */
26
- private findForeignKeyLineNumber;
27
- createDatabase(): Promise<any>;
28
- refreshTables(): Promise<any>;
29
- freshTables(): Promise<any>;
30
- executeSeeders(): Promise<any>;
31
- executeAlters(): Promise<any>;
32
- executeTriggers(): Promise<any>;
5
+ export declare class Schema {
6
+ private name;
7
+ private engine;
8
+ constructor(name: string);
9
+ /**
10
+ * Validates cube file comprehensively including syntax, database configuration, and structure
11
+ * @param filePath - Path to the cube file
12
+ * @returns validation result with any errors found
13
+ */
14
+ private validateDatabaseConfiguration;
15
+ /**
16
+ * Finds the line number where @database directive is located
17
+ */
18
+ private findDatabaseLineNumber;
19
+ /**
20
+ * Extracts foreign key dependencies from a cube file
21
+ */
22
+ private extractForeignKeyDependencies;
23
+ /**
24
+ * Finds the line number where a foreign key table reference is located
25
+ */
26
+ private findForeignKeyLineNumber;
27
+ createDatabase(): Promise<any>;
28
+ refreshTables(): Promise<any>;
29
+ freshTables(): Promise<any>;
30
+ executeSeeders(): Promise<any>;
31
+ executeAlters(): Promise<any>;
32
+ executeTriggers(): Promise<any>;
33
33
  }
34
-
35
- interface ProcessError {
36
- itemName: string;
37
- error: string;
38
- filePath?: string;
39
- lineNumber?: number;
34
+ export interface ProcessError {
35
+ itemName: string;
36
+ error: string;
37
+ filePath?: string;
38
+ lineNumber?: number;
40
39
  }
41
- interface ProcessSummary {
42
- startTime: number;
43
- totalProcessed: number;
44
- successCount: number;
45
- errorCount: number;
46
- processedItems: string[];
47
- operationName: string;
48
- databaseName: string;
49
- errors: ProcessError[];
40
+ export interface ProcessSummary {
41
+ startTime: number;
42
+ totalProcessed: number;
43
+ successCount: number;
44
+ errorCount: number;
45
+ processedItems: string[];
46
+ operationName: string;
47
+ databaseName: string;
48
+ errors: ProcessError[];
50
49
  }
51
- declare class UIUtils {
52
- /**
53
- * Shows animated progress for processing items
54
- */
55
- static showItemProgress(itemName: string, current: number, total: number): Promise<void>;
56
- /**
57
- * Shows success for a processed item
58
- */
59
- static showItemSuccess(itemName: string): void;
60
- /**
61
- * Shows error for an item (simplified - only shows X)
62
- */
63
- static showItemError(itemName: string, error: string): void;
64
- /**
65
- * Shows operation header
66
- */
67
- static showOperationHeader(operationName: string, databaseName: string, icon?: string): void;
68
- /**
69
- * Shows comprehensive operation summary
70
- */
71
- static showOperationSummary(summary: ProcessSummary): void;
72
- /**
73
- * Shows code context around an error location
74
- */
75
- static showCodeContext(filePath: string, lineNumber: number, contextLines?: number): void;
50
+ export declare class UIUtils {
51
+ /**
52
+ * Shows animated progress for processing items
53
+ */
54
+ static showItemProgress(itemName: string, current: number, total: number): Promise<void>;
55
+ /**
56
+ * Shows success for a processed item
57
+ */
58
+ static showItemSuccess(itemName: string): void;
59
+ /**
60
+ * Shows error for an item (simplified - only shows X)
61
+ */
62
+ static showItemError(itemName: string, error: string): void;
63
+ /**
64
+ * Shows operation header
65
+ */
66
+ static showOperationHeader(operationName: string, databaseName: string, icon?: string): void;
67
+ /**
68
+ * Shows comprehensive operation summary
69
+ */
70
+ static showOperationSummary(summary: ProcessSummary): void;
71
+ /**
72
+ * Shows code context around an error location
73
+ */
74
+ static showCodeContext(filePath: string, lineNumber: number, contextLines?: number): void;
76
75
  }
77
-
78
- interface ValidationResult {
79
- isValid: boolean;
80
- errors: ProcessError[];
76
+ export interface ValidationResult {
77
+ isValid: boolean;
78
+ errors: ProcessError[];
81
79
  }
82
- declare class CubeValidator {
83
- private validTypes;
84
- private validOptions;
85
- private validProperties;
86
- private knownAnnotations;
87
- /**
88
- * Validates a cube file comprehensively
89
- */
90
- validateCubeFile(filePath: string): ValidationResult;
91
- private validateAnnotations;
92
- private validateDataTypes;
93
- private validateColumnOptions;
94
- private validateColumnProperties;
95
- private validateRequiredColumnProperties;
96
- private validateGeneralSyntax;
97
- private validateOverallStructure;
98
- private getColumnTypeForOptions;
99
- private isOptionCompatibleWithType;
100
- private isInsideColumnsBlock;
101
- private isInsideForeignKeyObject;
80
+ export declare class CubeValidator {
81
+ private validTypes;
82
+ private validOptions;
83
+ private validProperties;
84
+ private knownAnnotations;
85
+ /**
86
+ * Validates a cube file comprehensively
87
+ */
88
+ validateCubeFile(filePath: string): ValidationResult;
89
+ private validateAnnotations;
90
+ private validateDataTypes;
91
+ private validateColumnOptions;
92
+ private validateColumnProperties;
93
+ private isInsideIndexesBlock;
94
+ private validateRequiredColumnProperties;
95
+ private validateGeneralSyntax;
96
+ private validateOverallStructure;
97
+ private getColumnTypeForOptions;
98
+ private isOptionCompatibleWithType;
99
+ private isInsideColumnsBlock;
100
+ private isInsideForeignKeyObject;
102
101
  }
103
-
104
- interface ExecutionOrder {
105
- tables: string[];
106
- seeders: string[];
107
- timestamp: string;
102
+ export interface ExecutionOrder {
103
+ tables: string[];
104
+ seeders: string[];
105
+ timestamp: string;
108
106
  }
109
- declare class DependencyResolver {
110
- /**
111
- * Resolves table dependencies and creates execution order
112
- */
113
- static resolveDependencies(cubeFiles: string[], cubeType?: 'table' | 'seeder'): ExecutionOrder;
114
- /**
115
- * Extracts dependencies from cube files
116
- */
117
- private static extractDependencies;
118
- /**
119
- * Extracts foreign key references from a cube file
120
- */
121
- private static extractForeignKeyReferences;
122
- /**
123
- * Performs topological sort to determine execution order
124
- */
125
- private static topologicalSort;
126
- /**
127
- * Saves the execution order to .dbcube/orderexecute.json
128
- */
129
- private static saveExecutionOrder;
130
- /**
131
- * Loads the execution order from .dbcube/orderexecute.json
132
- */
133
- static loadExecutionOrder(): ExecutionOrder | null;
134
- /**
135
- * Orders cube files based on saved execution order
136
- */
137
- static orderCubeFiles(cubeFiles: string[], cubeType: 'table' | 'seeder'): string[];
107
+ export declare class DependencyResolver {
108
+ /**
109
+ * Resolves table dependencies and creates execution order
110
+ */
111
+ static resolveDependencies(cubeFiles: string[], cubeType?: "table" | "seeder"): ExecutionOrder;
112
+ /**
113
+ * Extracts dependencies from cube files
114
+ */
115
+ private static extractDependencies;
116
+ /**
117
+ * Extracts foreign key references from a cube file
118
+ */
119
+ private static extractForeignKeyReferences;
120
+ /**
121
+ * Performs topological sort to determine execution order
122
+ */
123
+ private static topologicalSort;
124
+ /**
125
+ * Saves the execution order to .dbcube/orderexecute.json
126
+ */
127
+ private static saveExecutionOrder;
128
+ /**
129
+ * Loads the execution order from .dbcube/orderexecute.json
130
+ */
131
+ static loadExecutionOrder(): ExecutionOrder | null;
132
+ /**
133
+ * Orders cube files based on saved execution order
134
+ */
135
+ static orderCubeFiles(cubeFiles: string[], cubeType: "table" | "seeder"): string[];
138
136
  }
139
137
 
140
- export { CubeValidator, DependencyResolver, Schema, UIUtils, Schema as default };
138
+ export {
139
+ Schema as default,
140
+ };
141
+
142
+ export {};
package/dist/index.js CHANGED
@@ -255,7 +255,7 @@ var CubeValidator = class {
255
255
  validTypes = ["varchar", "int", "string", "text", "boolean", "date", "datetime", "timestamp", "decimal", "float", "double", "enum", "json"];
256
256
  validOptions = ["not null", "primary", "autoincrement", "unique", "zerofill", "index", "required", "unsigned"];
257
257
  validProperties = ["type", "length", "options", "value", "defaultValue", "foreign", "enumValues", "description"];
258
- knownAnnotations = ["database", "table", "meta", "columns", "fields", "dataset", "beforeAdd", "afterAdd", "beforeUpdate", "afterUpdate", "beforeDelete", "afterDelete", "compute", "column", "changeName", "addColumn", "deleteColumn", "renameColumn", "changeType", "changeLength", "changeDefault", "changeOptions", "changeEnumValues"];
258
+ knownAnnotations = ["database", "table", "meta", "columns", "indexes", "fields", "dataset", "beforeAdd", "afterAdd", "beforeUpdate", "afterUpdate", "beforeDelete", "afterDelete", "compute", "column", "changeName", "addColumn", "deleteColumn", "renameColumn", "changeType", "changeLength", "changeDefault", "changeOptions", "changeEnumValues"];
259
259
  /**
260
260
  * Validates a cube file comprehensively
261
261
  */
@@ -386,6 +386,18 @@ var CubeValidator = class {
386
386
  if (/^\s*[a-zA-Z_][a-zA-Z0-9_]*\s*:\s*\{/.test(line)) {
387
387
  return;
388
388
  }
389
+ if (this.isInsideIndexesBlock(content, lineNumber - 1)) {
390
+ const validIndexProperties = ["columns", "unique"];
391
+ if (!validIndexProperties.includes(propertyName)) {
392
+ errors.push({
393
+ itemName: fileName,
394
+ error: `Invalid index property '${propertyName}'. Valid index properties: ${validIndexProperties.join(", ")}`,
395
+ filePath,
396
+ lineNumber
397
+ });
398
+ }
399
+ return;
400
+ }
389
401
  if (this.isInsideForeignKeyObject(content, lineNumber - 1)) {
390
402
  const validForeignKeyProperties = ["table", "column"];
391
403
  if (!validForeignKeyProperties.includes(propertyName)) {
@@ -417,6 +429,27 @@ var CubeValidator = class {
417
429
  });
418
430
  }
419
431
  }
432
+ isInsideIndexesBlock(content, lineIndex) {
433
+ const lines = content.split("\n");
434
+ let indexesStartLine = -1;
435
+ let indexesEndLine = -1;
436
+ for (let i = 0; i < lines.length; i++) {
437
+ if (lines[i].includes("@indexes")) {
438
+ indexesStartLine = i;
439
+ let braceCount = 0;
440
+ for (let j = i; j < lines.length; j++) {
441
+ braceCount += (lines[j].match(/\{/g) || []).length;
442
+ braceCount -= (lines[j].match(/\}/g) || []).length;
443
+ if (braceCount === 0 && j > i) {
444
+ indexesEndLine = j;
445
+ break;
446
+ }
447
+ }
448
+ break;
449
+ }
450
+ }
451
+ return indexesStartLine !== -1 && indexesEndLine !== -1 && lineIndex > indexesStartLine && lineIndex < indexesEndLine;
452
+ }
420
453
  validateRequiredColumnProperties(lines, lineNumber, filePath, fileName, errors) {
421
454
  const line = lines[lineNumber - 1];
422
455
  if (!/^\s*\}\s*;?\s*$/.test(line)) {