@dbcube/schema-builder 1.0.16 → 1.0.17
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.cjs +354 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +71 -3
- package/dist/index.d.ts +71 -3
- package/dist/index.js +351 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,9 +6,9 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/lib/Schema.ts
|
|
9
|
-
import
|
|
9
|
+
import fs4 from "fs";
|
|
10
10
|
import { Engine, TableProcessor, Config as ConfigClass } from "@dbcube/core";
|
|
11
|
-
import
|
|
11
|
+
import path3 from "path";
|
|
12
12
|
|
|
13
13
|
// src/lib/FileUtils.ts
|
|
14
14
|
import * as fs from "fs";
|
|
@@ -255,6 +255,313 @@ ${chalk.red("\u{1F6AB}")} ${chalk.bold.red("ERRORS FOUND")}`);
|
|
|
255
255
|
}
|
|
256
256
|
};
|
|
257
257
|
|
|
258
|
+
// src/lib/CubeValidator.ts
|
|
259
|
+
import fs3 from "fs";
|
|
260
|
+
import path2 from "path";
|
|
261
|
+
var CubeValidator = class {
|
|
262
|
+
validTypes = ["varchar", "int", "string", "text", "boolean", "date", "datetime", "timestamp", "decimal", "float", "double", "enum", "json"];
|
|
263
|
+
validOptions = ["not null", "primary", "autoincrement", "unique", "zerofill", "index", "required", "unsigned"];
|
|
264
|
+
validProperties = ["type", "length", "options", "value", "defaultValue", "foreign", "enumValues", "description"];
|
|
265
|
+
knownAnnotations = ["database", "table", "meta", "columns", "fields", "dataset", "beforeAdd", "afterAdd", "beforeUpdate", "afterUpdate", "beforeDelete", "afterDelete", "compute", "column"];
|
|
266
|
+
/**
|
|
267
|
+
* Validates a cube file comprehensively
|
|
268
|
+
*/
|
|
269
|
+
validateCubeFile(filePath) {
|
|
270
|
+
const errors = [];
|
|
271
|
+
try {
|
|
272
|
+
const content = fs3.readFileSync(filePath, "utf8");
|
|
273
|
+
const lines = content.split("\n");
|
|
274
|
+
const fileName = path2.basename(filePath, path2.extname(filePath));
|
|
275
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
276
|
+
const line = lines[lineIndex];
|
|
277
|
+
if (line.trim() === "" || line.trim().startsWith("//")) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
this.validateAnnotations(line, lineIndex + 1, filePath, fileName, errors);
|
|
281
|
+
this.validateDataTypes(line, lineIndex + 1, filePath, fileName, errors, content);
|
|
282
|
+
this.validateColumnOptions(line, lineIndex + 1, filePath, fileName, errors, lines);
|
|
283
|
+
this.validateColumnProperties(line, lineIndex + 1, filePath, fileName, errors, content);
|
|
284
|
+
this.validateRequiredColumnProperties(lines, lineIndex + 1, filePath, fileName, errors);
|
|
285
|
+
this.validateGeneralSyntax(line, lineIndex + 1, filePath, fileName, errors);
|
|
286
|
+
}
|
|
287
|
+
this.validateOverallStructure(content, filePath, fileName, errors);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
errors.push({
|
|
290
|
+
itemName: path2.basename(filePath, path2.extname(filePath)),
|
|
291
|
+
error: `Failed to read cube file: ${error.message}`,
|
|
292
|
+
filePath,
|
|
293
|
+
lineNumber: 1
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
isValid: errors.length === 0,
|
|
298
|
+
errors
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
validateAnnotations(line, lineNumber, filePath, fileName, errors) {
|
|
302
|
+
const annotationRegex = /@(\w+)/g;
|
|
303
|
+
let match;
|
|
304
|
+
while ((match = annotationRegex.exec(line)) !== null) {
|
|
305
|
+
const annotation = match[1];
|
|
306
|
+
if (!this.knownAnnotations.includes(annotation)) {
|
|
307
|
+
errors.push({
|
|
308
|
+
itemName: fileName,
|
|
309
|
+
error: `Unknown annotation '@${annotation}'. Valid annotations: ${this.knownAnnotations.join(", ")}`,
|
|
310
|
+
filePath,
|
|
311
|
+
lineNumber
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
validateDataTypes(line, lineNumber, filePath, fileName, errors, content) {
|
|
317
|
+
const typeRegex = /type:\s*["'](\w+)["']/g;
|
|
318
|
+
let match;
|
|
319
|
+
while ((match = typeRegex.exec(line)) !== null) {
|
|
320
|
+
const type = match[1];
|
|
321
|
+
if (!this.validTypes.includes(type)) {
|
|
322
|
+
errors.push({
|
|
323
|
+
itemName: fileName,
|
|
324
|
+
error: `Invalid data type '${type}'. Valid types: ${this.validTypes.join(", ")}`,
|
|
325
|
+
filePath,
|
|
326
|
+
lineNumber
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (line.includes('type: "varchar"')) {
|
|
331
|
+
const lines = content.split("\n");
|
|
332
|
+
const hasLengthNearby = lines.slice(Math.max(0, lineNumber - 1), Math.min(lineNumber + 4, lines.length)).some((nextLine) => nextLine.includes("length:"));
|
|
333
|
+
if (!hasLengthNearby) {
|
|
334
|
+
errors.push({
|
|
335
|
+
itemName: fileName,
|
|
336
|
+
error: "VARCHAR type requires a length specification",
|
|
337
|
+
filePath,
|
|
338
|
+
lineNumber
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
validateColumnOptions(line, lineNumber, filePath, fileName, errors, lines) {
|
|
344
|
+
const optionsMatch = line.match(/^\s*options\s*:\s*\[(.*)\]\s*;?\s*$/);
|
|
345
|
+
if (!optionsMatch) return;
|
|
346
|
+
const optionsContent = optionsMatch[1].trim();
|
|
347
|
+
const invalidSyntaxMatch = optionsContent.match(/[^",\s]+(?![^"]*")/);
|
|
348
|
+
if (invalidSyntaxMatch) {
|
|
349
|
+
errors.push({
|
|
350
|
+
itemName: fileName,
|
|
351
|
+
error: `Invalid syntax '${invalidSyntaxMatch[0]}' in options array. All values must be quoted strings`,
|
|
352
|
+
filePath,
|
|
353
|
+
lineNumber
|
|
354
|
+
});
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const optionMatches = optionsContent.match(/"([^"]*)"/g);
|
|
358
|
+
if (optionMatches) {
|
|
359
|
+
const columnType = this.getColumnTypeForOptions(lines, lineNumber - 1);
|
|
360
|
+
optionMatches.forEach((optionMatch) => {
|
|
361
|
+
const option = optionMatch.replace(/"/g, "");
|
|
362
|
+
if (option.trim() === "") {
|
|
363
|
+
errors.push({
|
|
364
|
+
itemName: fileName,
|
|
365
|
+
error: "Empty option found in options array. All options must have a value",
|
|
366
|
+
filePath,
|
|
367
|
+
lineNumber
|
|
368
|
+
});
|
|
369
|
+
} else if (!this.validOptions.includes(option)) {
|
|
370
|
+
errors.push({
|
|
371
|
+
itemName: fileName,
|
|
372
|
+
error: `Invalid option '${option}'. Valid options: ${this.validOptions.join(", ")}`,
|
|
373
|
+
filePath,
|
|
374
|
+
lineNumber
|
|
375
|
+
});
|
|
376
|
+
} else if (!this.isOptionCompatibleWithType(option, columnType)) {
|
|
377
|
+
errors.push({
|
|
378
|
+
itemName: fileName,
|
|
379
|
+
error: `Option '${option}' is not compatible with type '${columnType}'`,
|
|
380
|
+
filePath,
|
|
381
|
+
lineNumber
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
validateColumnProperties(line, lineNumber, filePath, fileName, errors, content) {
|
|
388
|
+
const propertyKeyRegex = /^\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/;
|
|
389
|
+
const propMatch = propertyKeyRegex.exec(line);
|
|
390
|
+
if (!propMatch) return;
|
|
391
|
+
const propertyName = propMatch[1];
|
|
392
|
+
if (/^\s*[a-zA-Z_][a-zA-Z0-9_]*\s*:\s*\{/.test(line)) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (this.isInsideColumnsBlock(content, lineNumber - 1)) {
|
|
396
|
+
if (!this.validProperties.includes(propertyName)) {
|
|
397
|
+
errors.push({
|
|
398
|
+
itemName: fileName,
|
|
399
|
+
error: `Invalid property '${propertyName}'. Valid properties: ${this.validProperties.join(", ")}`,
|
|
400
|
+
filePath,
|
|
401
|
+
lineNumber
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (/^\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*$/.test(line)) {
|
|
406
|
+
errors.push({
|
|
407
|
+
itemName: fileName,
|
|
408
|
+
error: `Property '${propertyName}' is missing a value`,
|
|
409
|
+
filePath,
|
|
410
|
+
lineNumber
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
validateRequiredColumnProperties(lines, lineNumber, filePath, fileName, errors) {
|
|
415
|
+
const line = lines[lineNumber - 1];
|
|
416
|
+
if (!/^\s*\}\s*;?\s*$/.test(line)) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
let columnStartLine = -1;
|
|
420
|
+
let columnName = "";
|
|
421
|
+
for (let i = lineNumber - 2; i >= 0; i--) {
|
|
422
|
+
const currentLine = lines[i];
|
|
423
|
+
const columnDefMatch = currentLine.match(/^\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*\{/);
|
|
424
|
+
if (columnDefMatch) {
|
|
425
|
+
let openBraces = 0;
|
|
426
|
+
let closeBraces = 0;
|
|
427
|
+
for (let j = i; j < lineNumber; j++) {
|
|
428
|
+
openBraces += (lines[j].match(/\{/g) || []).length;
|
|
429
|
+
closeBraces += (lines[j].match(/\}/g) || []).length;
|
|
430
|
+
}
|
|
431
|
+
if (openBraces === closeBraces) {
|
|
432
|
+
columnStartLine = i;
|
|
433
|
+
columnName = columnDefMatch[1];
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (columnStartLine === -1 || !columnName) return;
|
|
439
|
+
let hasType = false;
|
|
440
|
+
for (let i = columnStartLine + 1; i < lineNumber - 1; i++) {
|
|
441
|
+
if (lines[i].match(/^\s*type\s*:/)) {
|
|
442
|
+
hasType = true;
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (!hasType && columnName !== "foreign" && columnName !== "defaultValue") {
|
|
447
|
+
errors.push({
|
|
448
|
+
itemName: fileName,
|
|
449
|
+
error: `Column '${columnName}' is missing required 'type' property`,
|
|
450
|
+
filePath,
|
|
451
|
+
lineNumber: columnStartLine + 1
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
validateGeneralSyntax(line, lineNumber, filePath, fileName, errors) {
|
|
456
|
+
const quotes = line.match(/["']/g);
|
|
457
|
+
if (quotes && quotes.length % 2 !== 0) {
|
|
458
|
+
errors.push({
|
|
459
|
+
itemName: fileName,
|
|
460
|
+
error: "Mismatched quotes detected",
|
|
461
|
+
filePath,
|
|
462
|
+
lineNumber
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
if (line.includes("@database") || line.includes("@table")) {
|
|
466
|
+
const stringAnnotationRegex = /@(database|table)\s*\(\s*"([^"]*)"\s*\)/;
|
|
467
|
+
if (!stringAnnotationRegex.test(line)) {
|
|
468
|
+
errors.push({
|
|
469
|
+
itemName: fileName,
|
|
470
|
+
error: 'Invalid annotation syntax. Expected format: @annotation("value")',
|
|
471
|
+
filePath,
|
|
472
|
+
lineNumber
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (line.includes("@meta")) {
|
|
477
|
+
const metaObjectRegex = /@meta\s*\(\s*\{/;
|
|
478
|
+
if (!metaObjectRegex.test(line)) {
|
|
479
|
+
errors.push({
|
|
480
|
+
itemName: fileName,
|
|
481
|
+
error: "Invalid @meta syntax. Expected format: @meta({ ... })",
|
|
482
|
+
filePath,
|
|
483
|
+
lineNumber
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
validateOverallStructure(content, filePath, fileName, errors) {
|
|
489
|
+
const lines = content.split("\n");
|
|
490
|
+
const hasDatabase = lines.some((line) => line.includes("@database"));
|
|
491
|
+
if (!hasDatabase) {
|
|
492
|
+
errors.push({
|
|
493
|
+
itemName: fileName,
|
|
494
|
+
error: "Missing required @database annotation",
|
|
495
|
+
filePath,
|
|
496
|
+
lineNumber: 1
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
if (filePath.includes(".table.cube")) {
|
|
500
|
+
const hasColumns = lines.some((line) => line.includes("@columns"));
|
|
501
|
+
if (!hasColumns) {
|
|
502
|
+
errors.push({
|
|
503
|
+
itemName: fileName,
|
|
504
|
+
error: "Table cube files require @columns annotation",
|
|
505
|
+
filePath,
|
|
506
|
+
lineNumber: 1
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
getColumnTypeForOptions(lines, optionsLineIndex) {
|
|
512
|
+
for (let i = optionsLineIndex - 1; i >= 0; i--) {
|
|
513
|
+
const line = lines[i];
|
|
514
|
+
const typeMatch = line.match(/^\s*type\s*:\s*"([^"]+)"/);
|
|
515
|
+
if (typeMatch) {
|
|
516
|
+
return typeMatch[1];
|
|
517
|
+
}
|
|
518
|
+
if (/^\s*[a-zA-Z_][a-zA-Z0-9_]*\s*:\s*\{/.test(line)) {
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return "unknown";
|
|
523
|
+
}
|
|
524
|
+
isOptionCompatibleWithType(option, type) {
|
|
525
|
+
const compatibilityRules = {
|
|
526
|
+
"zerofill": ["int", "decimal", "float", "double"],
|
|
527
|
+
"unsigned": ["int", "decimal", "float", "double"],
|
|
528
|
+
"autoincrement": ["int"],
|
|
529
|
+
"primary": ["int", "varchar", "string"],
|
|
530
|
+
"not null": ["int", "varchar", "string", "text", "boolean", "date", "datetime", "timestamp", "decimal", "float", "double"],
|
|
531
|
+
"unique": ["int", "varchar", "string", "text"],
|
|
532
|
+
"index": ["int", "varchar", "string", "text", "date", "datetime", "timestamp"],
|
|
533
|
+
"required": ["int", "varchar", "string", "text", "boolean", "date", "datetime", "timestamp", "decimal", "float", "double"]
|
|
534
|
+
};
|
|
535
|
+
const compatibleTypes = compatibilityRules[option];
|
|
536
|
+
if (!compatibleTypes) {
|
|
537
|
+
return true;
|
|
538
|
+
}
|
|
539
|
+
return compatibleTypes.includes(type);
|
|
540
|
+
}
|
|
541
|
+
isInsideColumnsBlock(content, lineIndex) {
|
|
542
|
+
const lines = content.split("\n");
|
|
543
|
+
let columnsStartLine = -1;
|
|
544
|
+
let columnsEndLine = -1;
|
|
545
|
+
for (let i = 0; i < lines.length; i++) {
|
|
546
|
+
if (lines[i].includes("@columns")) {
|
|
547
|
+
columnsStartLine = i;
|
|
548
|
+
let braceCount = 0;
|
|
549
|
+
for (let j = i; j < lines.length; j++) {
|
|
550
|
+
const currentLine = lines[j];
|
|
551
|
+
braceCount += (currentLine.match(/\{/g) || []).length;
|
|
552
|
+
braceCount -= (currentLine.match(/\}/g) || []).length;
|
|
553
|
+
if (braceCount === 0 && j > i) {
|
|
554
|
+
columnsEndLine = j;
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return columnsStartLine !== -1 && columnsEndLine !== -1 && lineIndex > columnsStartLine && lineIndex < columnsEndLine;
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
|
|
258
565
|
// src/lib/Schema.ts
|
|
259
566
|
var Schema = class {
|
|
260
567
|
name;
|
|
@@ -264,18 +571,27 @@ var Schema = class {
|
|
|
264
571
|
this.engine = new Engine(name);
|
|
265
572
|
}
|
|
266
573
|
/**
|
|
267
|
-
* Validates
|
|
574
|
+
* Validates cube file comprehensively including syntax, database configuration, and structure
|
|
268
575
|
* @param filePath - Path to the cube file
|
|
269
|
-
* @returns
|
|
576
|
+
* @returns validation result with any errors found
|
|
270
577
|
*/
|
|
271
578
|
validateDatabaseConfiguration(filePath) {
|
|
272
579
|
try {
|
|
580
|
+
const cubeValidator = new CubeValidator();
|
|
581
|
+
const cubeValidation = cubeValidator.validateCubeFile(filePath);
|
|
582
|
+
if (!cubeValidation.isValid && cubeValidation.errors.length > 0) {
|
|
583
|
+
return {
|
|
584
|
+
isValid: false,
|
|
585
|
+
error: cubeValidation.errors[0]
|
|
586
|
+
// Return the first error found
|
|
587
|
+
};
|
|
588
|
+
}
|
|
273
589
|
const dbResult = FileUtils_default.extractDatabaseNameFromCube(filePath);
|
|
274
590
|
if (dbResult.status !== 200) {
|
|
275
591
|
return {
|
|
276
592
|
isValid: false,
|
|
277
593
|
error: {
|
|
278
|
-
itemName:
|
|
594
|
+
itemName: path3.basename(filePath, path3.extname(filePath)),
|
|
279
595
|
error: `Error reading database directive: ${dbResult.message}`,
|
|
280
596
|
filePath,
|
|
281
597
|
lineNumber: this.findDatabaseLineNumber(filePath)
|
|
@@ -284,7 +600,7 @@ var Schema = class {
|
|
|
284
600
|
}
|
|
285
601
|
const cubeDbName = dbResult.message;
|
|
286
602
|
const configInstance = new ConfigClass();
|
|
287
|
-
const configFilePath =
|
|
603
|
+
const configFilePath = path3.resolve(process.cwd(), "dbcube.config.js");
|
|
288
604
|
const configFn = __require(configFilePath);
|
|
289
605
|
if (typeof configFn === "function") {
|
|
290
606
|
configFn(configInstance);
|
|
@@ -311,7 +627,7 @@ var Schema = class {
|
|
|
311
627
|
return {
|
|
312
628
|
isValid: false,
|
|
313
629
|
error: {
|
|
314
|
-
itemName:
|
|
630
|
+
itemName: path3.basename(filePath, path3.extname(filePath)),
|
|
315
631
|
error: `Database configuration '${cubeDbName}' not found in dbcube.config.js. Available: ${availableText}`,
|
|
316
632
|
filePath,
|
|
317
633
|
lineNumber: this.findDatabaseLineNumber(filePath)
|
|
@@ -323,7 +639,7 @@ var Schema = class {
|
|
|
323
639
|
return {
|
|
324
640
|
isValid: false,
|
|
325
641
|
error: {
|
|
326
|
-
itemName:
|
|
642
|
+
itemName: path3.basename(filePath, path3.extname(filePath)),
|
|
327
643
|
error: `Database configuration validation failed: ${error.message}`,
|
|
328
644
|
filePath,
|
|
329
645
|
lineNumber: this.findDatabaseLineNumber(filePath)
|
|
@@ -336,7 +652,7 @@ var Schema = class {
|
|
|
336
652
|
*/
|
|
337
653
|
findDatabaseLineNumber(filePath) {
|
|
338
654
|
try {
|
|
339
|
-
const content =
|
|
655
|
+
const content = fs4.readFileSync(filePath, "utf8");
|
|
340
656
|
const lines = content.split("\n");
|
|
341
657
|
for (let i = 0; i < lines.length; i++) {
|
|
342
658
|
if (lines[i].includes("@database")) {
|
|
@@ -350,7 +666,7 @@ var Schema = class {
|
|
|
350
666
|
}
|
|
351
667
|
async createDatabase() {
|
|
352
668
|
const startTime = Date.now();
|
|
353
|
-
const rootPath =
|
|
669
|
+
const rootPath = path3.resolve(process.cwd());
|
|
354
670
|
UIUtils.showOperationHeader(" CREATING DATABASE", this.name, "\u{1F5C4}\uFE0F");
|
|
355
671
|
await UIUtils.showItemProgress("Preparando e instalando base de datos", 1, 1);
|
|
356
672
|
try {
|
|
@@ -394,8 +710,8 @@ var Schema = class {
|
|
|
394
710
|
}
|
|
395
711
|
async refreshTables() {
|
|
396
712
|
const startTime = Date.now();
|
|
397
|
-
const cubesDir =
|
|
398
|
-
if (!
|
|
713
|
+
const cubesDir = path3.join(process.cwd(), "dbcube", "cubes");
|
|
714
|
+
if (!fs4.existsSync(cubesDir)) {
|
|
399
715
|
throw new Error("\u274C The cubes folder does not exist");
|
|
400
716
|
}
|
|
401
717
|
const cubeFiles = FileUtils_default.getCubeFilesRecursively("dbcube", "table.cube");
|
|
@@ -410,11 +726,11 @@ var Schema = class {
|
|
|
410
726
|
const errors = [];
|
|
411
727
|
for (let index = 0; index < cubeFiles.length; index++) {
|
|
412
728
|
const file = cubeFiles[index];
|
|
413
|
-
const filePath =
|
|
414
|
-
const stats =
|
|
729
|
+
const filePath = path3.isAbsolute(file) ? file : path3.join(cubesDir, file);
|
|
730
|
+
const stats = fs4.statSync(filePath);
|
|
415
731
|
if (stats.isFile()) {
|
|
416
732
|
const getTableName = FileUtils_default.extracTableNameFromCube(filePath);
|
|
417
|
-
const tableName = getTableName.status === 200 ? getTableName.message :
|
|
733
|
+
const tableName = getTableName.status === 200 ? getTableName.message : path3.basename(file, ".table.cube");
|
|
418
734
|
await UIUtils.showItemProgress(tableName, index + 1, cubeFiles.length);
|
|
419
735
|
try {
|
|
420
736
|
const validation = this.validateDatabaseConfiguration(filePath);
|
|
@@ -496,8 +812,8 @@ var Schema = class {
|
|
|
496
812
|
}
|
|
497
813
|
async freshTables() {
|
|
498
814
|
const startTime = Date.now();
|
|
499
|
-
const cubesDir =
|
|
500
|
-
if (!
|
|
815
|
+
const cubesDir = path3.join(process.cwd(), "dbcube", "cubes");
|
|
816
|
+
if (!fs4.existsSync(cubesDir)) {
|
|
501
817
|
throw new Error("\u274C The cubes folder does not exist");
|
|
502
818
|
}
|
|
503
819
|
const cubeFiles = FileUtils_default.getCubeFilesRecursively("dbcube", "table.cube");
|
|
@@ -512,11 +828,11 @@ var Schema = class {
|
|
|
512
828
|
const errors = [];
|
|
513
829
|
for (let index = 0; index < cubeFiles.length; index++) {
|
|
514
830
|
const file = cubeFiles[index];
|
|
515
|
-
const filePath =
|
|
516
|
-
const stats =
|
|
831
|
+
const filePath = path3.isAbsolute(file) ? file : path3.join(cubesDir, file);
|
|
832
|
+
const stats = fs4.statSync(filePath);
|
|
517
833
|
if (stats.isFile()) {
|
|
518
834
|
const getTableName = FileUtils_default.extracTableNameFromCube(filePath);
|
|
519
|
-
const tableName = getTableName.status === 200 ? getTableName.message :
|
|
835
|
+
const tableName = getTableName.status === 200 ? getTableName.message : path3.basename(file, ".table.cube");
|
|
520
836
|
await UIUtils.showItemProgress(tableName, index + 1, cubeFiles.length);
|
|
521
837
|
try {
|
|
522
838
|
const validation = this.validateDatabaseConfiguration(filePath);
|
|
@@ -596,8 +912,8 @@ var Schema = class {
|
|
|
596
912
|
}
|
|
597
913
|
async executeSeeders() {
|
|
598
914
|
const startTime = Date.now();
|
|
599
|
-
const cubesDir =
|
|
600
|
-
if (!
|
|
915
|
+
const cubesDir = path3.join(process.cwd(), "dbcube", "cubes");
|
|
916
|
+
if (!fs4.existsSync(cubesDir)) {
|
|
601
917
|
throw new Error("\u274C The cubes folder does not exist");
|
|
602
918
|
}
|
|
603
919
|
const cubeFiles = FileUtils_default.getCubeFilesRecursively("dbcube", "seeder.cube");
|
|
@@ -612,11 +928,11 @@ var Schema = class {
|
|
|
612
928
|
const errors = [];
|
|
613
929
|
for (let index = 0; index < cubeFiles.length; index++) {
|
|
614
930
|
const file = cubeFiles[index];
|
|
615
|
-
const filePath =
|
|
616
|
-
const stats =
|
|
931
|
+
const filePath = path3.isAbsolute(file) ? file : path3.join(cubesDir, file);
|
|
932
|
+
const stats = fs4.statSync(filePath);
|
|
617
933
|
if (stats.isFile()) {
|
|
618
934
|
const getSeederName = FileUtils_default.extracTableNameFromCube(filePath);
|
|
619
|
-
const seederName = getSeederName.status === 200 ? getSeederName.message :
|
|
935
|
+
const seederName = getSeederName.status === 200 ? getSeederName.message : path3.basename(file, ".seeder.cube");
|
|
620
936
|
await UIUtils.showItemProgress(seederName, index + 1, cubeFiles.length);
|
|
621
937
|
try {
|
|
622
938
|
const validation = this.validateDatabaseConfiguration(filePath);
|
|
@@ -667,9 +983,9 @@ var Schema = class {
|
|
|
667
983
|
}
|
|
668
984
|
async executeTriggers() {
|
|
669
985
|
const startTime = Date.now();
|
|
670
|
-
const cubesDir =
|
|
671
|
-
const triggersDirExit =
|
|
672
|
-
if (!
|
|
986
|
+
const cubesDir = path3.join(process.cwd(), "dbcube", "cubes");
|
|
987
|
+
const triggersDirExit = path3.join(process.cwd(), "dbcube", "triggers");
|
|
988
|
+
if (!fs4.existsSync(cubesDir)) {
|
|
673
989
|
throw new Error("\u274C The cubes folder does not exist");
|
|
674
990
|
}
|
|
675
991
|
const cubeFiles = FileUtils_default.getCubeFilesRecursively("dbcube", "trigger.cube");
|
|
@@ -684,11 +1000,11 @@ var Schema = class {
|
|
|
684
1000
|
const errors = [];
|
|
685
1001
|
for (let index = 0; index < cubeFiles.length; index++) {
|
|
686
1002
|
const file = cubeFiles[index];
|
|
687
|
-
const filePath =
|
|
688
|
-
const stats =
|
|
1003
|
+
const filePath = path3.isAbsolute(file) ? file : path3.join(cubesDir, file);
|
|
1004
|
+
const stats = fs4.statSync(filePath);
|
|
689
1005
|
if (stats.isFile()) {
|
|
690
1006
|
const getTriggerName = FileUtils_default.extracTableNameFromCube(filePath);
|
|
691
|
-
const triggerName = getTriggerName.status === 200 ? getTriggerName.message :
|
|
1007
|
+
const triggerName = getTriggerName.status === 200 ? getTriggerName.message : path3.basename(file, ".trigger.cube");
|
|
692
1008
|
await UIUtils.showItemProgress(triggerName, index + 1, cubeFiles.length);
|
|
693
1009
|
try {
|
|
694
1010
|
const validation = this.validateDatabaseConfiguration(filePath);
|
|
@@ -759,7 +1075,7 @@ ${chalk2.red("\u{1F6AB}")} ${chalk2.bold.red("ERRORS FOUND")}`);
|
|
|
759
1075
|
const errorLocation = `${filePath}:${lineStr}:${columnStr}`;
|
|
760
1076
|
console.log(`${chalk2.cyan("[code]")} ${chalk2.yellow(errorLocation)}`);
|
|
761
1077
|
try {
|
|
762
|
-
const codeLines =
|
|
1078
|
+
const codeLines = fs4.readFileSync(filePath, "utf-8").split("\n");
|
|
763
1079
|
const start = Math.max(0, lineNum - 3);
|
|
764
1080
|
const end = Math.min(codeLines.length, lineNum + 2);
|
|
765
1081
|
for (let i = start; i < end; i++) {
|
|
@@ -773,13 +1089,16 @@ ${chalk2.red("\u{1F6AB}")} ${chalk2.bold.red("ERRORS FOUND")}`);
|
|
|
773
1089
|
}
|
|
774
1090
|
}
|
|
775
1091
|
}
|
|
1092
|
+
console.log("");
|
|
776
1093
|
process.exit(1);
|
|
777
1094
|
}
|
|
778
1095
|
|
|
779
1096
|
// src/index.ts
|
|
780
1097
|
var index_default = Schema;
|
|
781
1098
|
export {
|
|
1099
|
+
CubeValidator,
|
|
782
1100
|
Schema,
|
|
1101
|
+
UIUtils,
|
|
783
1102
|
index_default as default
|
|
784
1103
|
};
|
|
785
1104
|
//# sourceMappingURL=index.js.map
|