@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.cjs
CHANGED
|
@@ -30,15 +30,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
CubeValidator: () => CubeValidator,
|
|
33
34
|
Schema: () => Schema,
|
|
35
|
+
UIUtils: () => UIUtils,
|
|
34
36
|
default: () => index_default
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(index_exports);
|
|
37
39
|
|
|
38
40
|
// src/lib/Schema.ts
|
|
39
|
-
var
|
|
41
|
+
var import_fs3 = __toESM(require("fs"));
|
|
40
42
|
var import_core = require("@dbcube/core");
|
|
41
|
-
var
|
|
43
|
+
var import_path2 = __toESM(require("path"));
|
|
42
44
|
|
|
43
45
|
// src/lib/FileUtils.ts
|
|
44
46
|
var fs = __toESM(require("fs"));
|
|
@@ -285,6 +287,313 @@ ${import_chalk.default.red("\u{1F6AB}")} ${import_chalk.default.bold.red("ERRORS
|
|
|
285
287
|
}
|
|
286
288
|
};
|
|
287
289
|
|
|
290
|
+
// src/lib/CubeValidator.ts
|
|
291
|
+
var import_fs2 = __toESM(require("fs"));
|
|
292
|
+
var import_path = __toESM(require("path"));
|
|
293
|
+
var CubeValidator = class {
|
|
294
|
+
validTypes = ["varchar", "int", "string", "text", "boolean", "date", "datetime", "timestamp", "decimal", "float", "double", "enum", "json"];
|
|
295
|
+
validOptions = ["not null", "primary", "autoincrement", "unique", "zerofill", "index", "required", "unsigned"];
|
|
296
|
+
validProperties = ["type", "length", "options", "value", "defaultValue", "foreign", "enumValues", "description"];
|
|
297
|
+
knownAnnotations = ["database", "table", "meta", "columns", "fields", "dataset", "beforeAdd", "afterAdd", "beforeUpdate", "afterUpdate", "beforeDelete", "afterDelete", "compute", "column"];
|
|
298
|
+
/**
|
|
299
|
+
* Validates a cube file comprehensively
|
|
300
|
+
*/
|
|
301
|
+
validateCubeFile(filePath) {
|
|
302
|
+
const errors = [];
|
|
303
|
+
try {
|
|
304
|
+
const content = import_fs2.default.readFileSync(filePath, "utf8");
|
|
305
|
+
const lines = content.split("\n");
|
|
306
|
+
const fileName = import_path.default.basename(filePath, import_path.default.extname(filePath));
|
|
307
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
308
|
+
const line = lines[lineIndex];
|
|
309
|
+
if (line.trim() === "" || line.trim().startsWith("//")) {
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
this.validateAnnotations(line, lineIndex + 1, filePath, fileName, errors);
|
|
313
|
+
this.validateDataTypes(line, lineIndex + 1, filePath, fileName, errors, content);
|
|
314
|
+
this.validateColumnOptions(line, lineIndex + 1, filePath, fileName, errors, lines);
|
|
315
|
+
this.validateColumnProperties(line, lineIndex + 1, filePath, fileName, errors, content);
|
|
316
|
+
this.validateRequiredColumnProperties(lines, lineIndex + 1, filePath, fileName, errors);
|
|
317
|
+
this.validateGeneralSyntax(line, lineIndex + 1, filePath, fileName, errors);
|
|
318
|
+
}
|
|
319
|
+
this.validateOverallStructure(content, filePath, fileName, errors);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
errors.push({
|
|
322
|
+
itemName: import_path.default.basename(filePath, import_path.default.extname(filePath)),
|
|
323
|
+
error: `Failed to read cube file: ${error.message}`,
|
|
324
|
+
filePath,
|
|
325
|
+
lineNumber: 1
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
isValid: errors.length === 0,
|
|
330
|
+
errors
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
validateAnnotations(line, lineNumber, filePath, fileName, errors) {
|
|
334
|
+
const annotationRegex = /@(\w+)/g;
|
|
335
|
+
let match;
|
|
336
|
+
while ((match = annotationRegex.exec(line)) !== null) {
|
|
337
|
+
const annotation = match[1];
|
|
338
|
+
if (!this.knownAnnotations.includes(annotation)) {
|
|
339
|
+
errors.push({
|
|
340
|
+
itemName: fileName,
|
|
341
|
+
error: `Unknown annotation '@${annotation}'. Valid annotations: ${this.knownAnnotations.join(", ")}`,
|
|
342
|
+
filePath,
|
|
343
|
+
lineNumber
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
validateDataTypes(line, lineNumber, filePath, fileName, errors, content) {
|
|
349
|
+
const typeRegex = /type:\s*["'](\w+)["']/g;
|
|
350
|
+
let match;
|
|
351
|
+
while ((match = typeRegex.exec(line)) !== null) {
|
|
352
|
+
const type = match[1];
|
|
353
|
+
if (!this.validTypes.includes(type)) {
|
|
354
|
+
errors.push({
|
|
355
|
+
itemName: fileName,
|
|
356
|
+
error: `Invalid data type '${type}'. Valid types: ${this.validTypes.join(", ")}`,
|
|
357
|
+
filePath,
|
|
358
|
+
lineNumber
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (line.includes('type: "varchar"')) {
|
|
363
|
+
const lines = content.split("\n");
|
|
364
|
+
const hasLengthNearby = lines.slice(Math.max(0, lineNumber - 1), Math.min(lineNumber + 4, lines.length)).some((nextLine) => nextLine.includes("length:"));
|
|
365
|
+
if (!hasLengthNearby) {
|
|
366
|
+
errors.push({
|
|
367
|
+
itemName: fileName,
|
|
368
|
+
error: "VARCHAR type requires a length specification",
|
|
369
|
+
filePath,
|
|
370
|
+
lineNumber
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
validateColumnOptions(line, lineNumber, filePath, fileName, errors, lines) {
|
|
376
|
+
const optionsMatch = line.match(/^\s*options\s*:\s*\[(.*)\]\s*;?\s*$/);
|
|
377
|
+
if (!optionsMatch) return;
|
|
378
|
+
const optionsContent = optionsMatch[1].trim();
|
|
379
|
+
const invalidSyntaxMatch = optionsContent.match(/[^",\s]+(?![^"]*")/);
|
|
380
|
+
if (invalidSyntaxMatch) {
|
|
381
|
+
errors.push({
|
|
382
|
+
itemName: fileName,
|
|
383
|
+
error: `Invalid syntax '${invalidSyntaxMatch[0]}' in options array. All values must be quoted strings`,
|
|
384
|
+
filePath,
|
|
385
|
+
lineNumber
|
|
386
|
+
});
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const optionMatches = optionsContent.match(/"([^"]*)"/g);
|
|
390
|
+
if (optionMatches) {
|
|
391
|
+
const columnType = this.getColumnTypeForOptions(lines, lineNumber - 1);
|
|
392
|
+
optionMatches.forEach((optionMatch) => {
|
|
393
|
+
const option = optionMatch.replace(/"/g, "");
|
|
394
|
+
if (option.trim() === "") {
|
|
395
|
+
errors.push({
|
|
396
|
+
itemName: fileName,
|
|
397
|
+
error: "Empty option found in options array. All options must have a value",
|
|
398
|
+
filePath,
|
|
399
|
+
lineNumber
|
|
400
|
+
});
|
|
401
|
+
} else if (!this.validOptions.includes(option)) {
|
|
402
|
+
errors.push({
|
|
403
|
+
itemName: fileName,
|
|
404
|
+
error: `Invalid option '${option}'. Valid options: ${this.validOptions.join(", ")}`,
|
|
405
|
+
filePath,
|
|
406
|
+
lineNumber
|
|
407
|
+
});
|
|
408
|
+
} else if (!this.isOptionCompatibleWithType(option, columnType)) {
|
|
409
|
+
errors.push({
|
|
410
|
+
itemName: fileName,
|
|
411
|
+
error: `Option '${option}' is not compatible with type '${columnType}'`,
|
|
412
|
+
filePath,
|
|
413
|
+
lineNumber
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
validateColumnProperties(line, lineNumber, filePath, fileName, errors, content) {
|
|
420
|
+
const propertyKeyRegex = /^\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/;
|
|
421
|
+
const propMatch = propertyKeyRegex.exec(line);
|
|
422
|
+
if (!propMatch) return;
|
|
423
|
+
const propertyName = propMatch[1];
|
|
424
|
+
if (/^\s*[a-zA-Z_][a-zA-Z0-9_]*\s*:\s*\{/.test(line)) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
if (this.isInsideColumnsBlock(content, lineNumber - 1)) {
|
|
428
|
+
if (!this.validProperties.includes(propertyName)) {
|
|
429
|
+
errors.push({
|
|
430
|
+
itemName: fileName,
|
|
431
|
+
error: `Invalid property '${propertyName}'. Valid properties: ${this.validProperties.join(", ")}`,
|
|
432
|
+
filePath,
|
|
433
|
+
lineNumber
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (/^\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*$/.test(line)) {
|
|
438
|
+
errors.push({
|
|
439
|
+
itemName: fileName,
|
|
440
|
+
error: `Property '${propertyName}' is missing a value`,
|
|
441
|
+
filePath,
|
|
442
|
+
lineNumber
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
validateRequiredColumnProperties(lines, lineNumber, filePath, fileName, errors) {
|
|
447
|
+
const line = lines[lineNumber - 1];
|
|
448
|
+
if (!/^\s*\}\s*;?\s*$/.test(line)) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
let columnStartLine = -1;
|
|
452
|
+
let columnName = "";
|
|
453
|
+
for (let i = lineNumber - 2; i >= 0; i--) {
|
|
454
|
+
const currentLine = lines[i];
|
|
455
|
+
const columnDefMatch = currentLine.match(/^\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*\{/);
|
|
456
|
+
if (columnDefMatch) {
|
|
457
|
+
let openBraces = 0;
|
|
458
|
+
let closeBraces = 0;
|
|
459
|
+
for (let j = i; j < lineNumber; j++) {
|
|
460
|
+
openBraces += (lines[j].match(/\{/g) || []).length;
|
|
461
|
+
closeBraces += (lines[j].match(/\}/g) || []).length;
|
|
462
|
+
}
|
|
463
|
+
if (openBraces === closeBraces) {
|
|
464
|
+
columnStartLine = i;
|
|
465
|
+
columnName = columnDefMatch[1];
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
if (columnStartLine === -1 || !columnName) return;
|
|
471
|
+
let hasType = false;
|
|
472
|
+
for (let i = columnStartLine + 1; i < lineNumber - 1; i++) {
|
|
473
|
+
if (lines[i].match(/^\s*type\s*:/)) {
|
|
474
|
+
hasType = true;
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
if (!hasType && columnName !== "foreign" && columnName !== "defaultValue") {
|
|
479
|
+
errors.push({
|
|
480
|
+
itemName: fileName,
|
|
481
|
+
error: `Column '${columnName}' is missing required 'type' property`,
|
|
482
|
+
filePath,
|
|
483
|
+
lineNumber: columnStartLine + 1
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
validateGeneralSyntax(line, lineNumber, filePath, fileName, errors) {
|
|
488
|
+
const quotes = line.match(/["']/g);
|
|
489
|
+
if (quotes && quotes.length % 2 !== 0) {
|
|
490
|
+
errors.push({
|
|
491
|
+
itemName: fileName,
|
|
492
|
+
error: "Mismatched quotes detected",
|
|
493
|
+
filePath,
|
|
494
|
+
lineNumber
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
if (line.includes("@database") || line.includes("@table")) {
|
|
498
|
+
const stringAnnotationRegex = /@(database|table)\s*\(\s*"([^"]*)"\s*\)/;
|
|
499
|
+
if (!stringAnnotationRegex.test(line)) {
|
|
500
|
+
errors.push({
|
|
501
|
+
itemName: fileName,
|
|
502
|
+
error: 'Invalid annotation syntax. Expected format: @annotation("value")',
|
|
503
|
+
filePath,
|
|
504
|
+
lineNumber
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (line.includes("@meta")) {
|
|
509
|
+
const metaObjectRegex = /@meta\s*\(\s*\{/;
|
|
510
|
+
if (!metaObjectRegex.test(line)) {
|
|
511
|
+
errors.push({
|
|
512
|
+
itemName: fileName,
|
|
513
|
+
error: "Invalid @meta syntax. Expected format: @meta({ ... })",
|
|
514
|
+
filePath,
|
|
515
|
+
lineNumber
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
validateOverallStructure(content, filePath, fileName, errors) {
|
|
521
|
+
const lines = content.split("\n");
|
|
522
|
+
const hasDatabase = lines.some((line) => line.includes("@database"));
|
|
523
|
+
if (!hasDatabase) {
|
|
524
|
+
errors.push({
|
|
525
|
+
itemName: fileName,
|
|
526
|
+
error: "Missing required @database annotation",
|
|
527
|
+
filePath,
|
|
528
|
+
lineNumber: 1
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
if (filePath.includes(".table.cube")) {
|
|
532
|
+
const hasColumns = lines.some((line) => line.includes("@columns"));
|
|
533
|
+
if (!hasColumns) {
|
|
534
|
+
errors.push({
|
|
535
|
+
itemName: fileName,
|
|
536
|
+
error: "Table cube files require @columns annotation",
|
|
537
|
+
filePath,
|
|
538
|
+
lineNumber: 1
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
getColumnTypeForOptions(lines, optionsLineIndex) {
|
|
544
|
+
for (let i = optionsLineIndex - 1; i >= 0; i--) {
|
|
545
|
+
const line = lines[i];
|
|
546
|
+
const typeMatch = line.match(/^\s*type\s*:\s*"([^"]+)"/);
|
|
547
|
+
if (typeMatch) {
|
|
548
|
+
return typeMatch[1];
|
|
549
|
+
}
|
|
550
|
+
if (/^\s*[a-zA-Z_][a-zA-Z0-9_]*\s*:\s*\{/.test(line)) {
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return "unknown";
|
|
555
|
+
}
|
|
556
|
+
isOptionCompatibleWithType(option, type) {
|
|
557
|
+
const compatibilityRules = {
|
|
558
|
+
"zerofill": ["int", "decimal", "float", "double"],
|
|
559
|
+
"unsigned": ["int", "decimal", "float", "double"],
|
|
560
|
+
"autoincrement": ["int"],
|
|
561
|
+
"primary": ["int", "varchar", "string"],
|
|
562
|
+
"not null": ["int", "varchar", "string", "text", "boolean", "date", "datetime", "timestamp", "decimal", "float", "double"],
|
|
563
|
+
"unique": ["int", "varchar", "string", "text"],
|
|
564
|
+
"index": ["int", "varchar", "string", "text", "date", "datetime", "timestamp"],
|
|
565
|
+
"required": ["int", "varchar", "string", "text", "boolean", "date", "datetime", "timestamp", "decimal", "float", "double"]
|
|
566
|
+
};
|
|
567
|
+
const compatibleTypes = compatibilityRules[option];
|
|
568
|
+
if (!compatibleTypes) {
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
571
|
+
return compatibleTypes.includes(type);
|
|
572
|
+
}
|
|
573
|
+
isInsideColumnsBlock(content, lineIndex) {
|
|
574
|
+
const lines = content.split("\n");
|
|
575
|
+
let columnsStartLine = -1;
|
|
576
|
+
let columnsEndLine = -1;
|
|
577
|
+
for (let i = 0; i < lines.length; i++) {
|
|
578
|
+
if (lines[i].includes("@columns")) {
|
|
579
|
+
columnsStartLine = i;
|
|
580
|
+
let braceCount = 0;
|
|
581
|
+
for (let j = i; j < lines.length; j++) {
|
|
582
|
+
const currentLine = lines[j];
|
|
583
|
+
braceCount += (currentLine.match(/\{/g) || []).length;
|
|
584
|
+
braceCount -= (currentLine.match(/\}/g) || []).length;
|
|
585
|
+
if (braceCount === 0 && j > i) {
|
|
586
|
+
columnsEndLine = j;
|
|
587
|
+
break;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return columnsStartLine !== -1 && columnsEndLine !== -1 && lineIndex > columnsStartLine && lineIndex < columnsEndLine;
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
|
|
288
597
|
// src/lib/Schema.ts
|
|
289
598
|
var Schema = class {
|
|
290
599
|
name;
|
|
@@ -294,18 +603,27 @@ var Schema = class {
|
|
|
294
603
|
this.engine = new import_core.Engine(name);
|
|
295
604
|
}
|
|
296
605
|
/**
|
|
297
|
-
* Validates
|
|
606
|
+
* Validates cube file comprehensively including syntax, database configuration, and structure
|
|
298
607
|
* @param filePath - Path to the cube file
|
|
299
|
-
* @returns
|
|
608
|
+
* @returns validation result with any errors found
|
|
300
609
|
*/
|
|
301
610
|
validateDatabaseConfiguration(filePath) {
|
|
302
611
|
try {
|
|
612
|
+
const cubeValidator = new CubeValidator();
|
|
613
|
+
const cubeValidation = cubeValidator.validateCubeFile(filePath);
|
|
614
|
+
if (!cubeValidation.isValid && cubeValidation.errors.length > 0) {
|
|
615
|
+
return {
|
|
616
|
+
isValid: false,
|
|
617
|
+
error: cubeValidation.errors[0]
|
|
618
|
+
// Return the first error found
|
|
619
|
+
};
|
|
620
|
+
}
|
|
303
621
|
const dbResult = FileUtils_default.extractDatabaseNameFromCube(filePath);
|
|
304
622
|
if (dbResult.status !== 200) {
|
|
305
623
|
return {
|
|
306
624
|
isValid: false,
|
|
307
625
|
error: {
|
|
308
|
-
itemName:
|
|
626
|
+
itemName: import_path2.default.basename(filePath, import_path2.default.extname(filePath)),
|
|
309
627
|
error: `Error reading database directive: ${dbResult.message}`,
|
|
310
628
|
filePath,
|
|
311
629
|
lineNumber: this.findDatabaseLineNumber(filePath)
|
|
@@ -314,7 +632,7 @@ var Schema = class {
|
|
|
314
632
|
}
|
|
315
633
|
const cubeDbName = dbResult.message;
|
|
316
634
|
const configInstance = new import_core.Config();
|
|
317
|
-
const configFilePath =
|
|
635
|
+
const configFilePath = import_path2.default.resolve(process.cwd(), "dbcube.config.js");
|
|
318
636
|
const configFn = require(configFilePath);
|
|
319
637
|
if (typeof configFn === "function") {
|
|
320
638
|
configFn(configInstance);
|
|
@@ -341,7 +659,7 @@ var Schema = class {
|
|
|
341
659
|
return {
|
|
342
660
|
isValid: false,
|
|
343
661
|
error: {
|
|
344
|
-
itemName:
|
|
662
|
+
itemName: import_path2.default.basename(filePath, import_path2.default.extname(filePath)),
|
|
345
663
|
error: `Database configuration '${cubeDbName}' not found in dbcube.config.js. Available: ${availableText}`,
|
|
346
664
|
filePath,
|
|
347
665
|
lineNumber: this.findDatabaseLineNumber(filePath)
|
|
@@ -353,7 +671,7 @@ var Schema = class {
|
|
|
353
671
|
return {
|
|
354
672
|
isValid: false,
|
|
355
673
|
error: {
|
|
356
|
-
itemName:
|
|
674
|
+
itemName: import_path2.default.basename(filePath, import_path2.default.extname(filePath)),
|
|
357
675
|
error: `Database configuration validation failed: ${error.message}`,
|
|
358
676
|
filePath,
|
|
359
677
|
lineNumber: this.findDatabaseLineNumber(filePath)
|
|
@@ -366,7 +684,7 @@ var Schema = class {
|
|
|
366
684
|
*/
|
|
367
685
|
findDatabaseLineNumber(filePath) {
|
|
368
686
|
try {
|
|
369
|
-
const content =
|
|
687
|
+
const content = import_fs3.default.readFileSync(filePath, "utf8");
|
|
370
688
|
const lines = content.split("\n");
|
|
371
689
|
for (let i = 0; i < lines.length; i++) {
|
|
372
690
|
if (lines[i].includes("@database")) {
|
|
@@ -380,7 +698,7 @@ var Schema = class {
|
|
|
380
698
|
}
|
|
381
699
|
async createDatabase() {
|
|
382
700
|
const startTime = Date.now();
|
|
383
|
-
const rootPath =
|
|
701
|
+
const rootPath = import_path2.default.resolve(process.cwd());
|
|
384
702
|
UIUtils.showOperationHeader(" CREATING DATABASE", this.name, "\u{1F5C4}\uFE0F");
|
|
385
703
|
await UIUtils.showItemProgress("Preparando e instalando base de datos", 1, 1);
|
|
386
704
|
try {
|
|
@@ -424,8 +742,8 @@ var Schema = class {
|
|
|
424
742
|
}
|
|
425
743
|
async refreshTables() {
|
|
426
744
|
const startTime = Date.now();
|
|
427
|
-
const cubesDir =
|
|
428
|
-
if (!
|
|
745
|
+
const cubesDir = import_path2.default.join(process.cwd(), "dbcube", "cubes");
|
|
746
|
+
if (!import_fs3.default.existsSync(cubesDir)) {
|
|
429
747
|
throw new Error("\u274C The cubes folder does not exist");
|
|
430
748
|
}
|
|
431
749
|
const cubeFiles = FileUtils_default.getCubeFilesRecursively("dbcube", "table.cube");
|
|
@@ -440,11 +758,11 @@ var Schema = class {
|
|
|
440
758
|
const errors = [];
|
|
441
759
|
for (let index = 0; index < cubeFiles.length; index++) {
|
|
442
760
|
const file = cubeFiles[index];
|
|
443
|
-
const filePath =
|
|
444
|
-
const stats =
|
|
761
|
+
const filePath = import_path2.default.isAbsolute(file) ? file : import_path2.default.join(cubesDir, file);
|
|
762
|
+
const stats = import_fs3.default.statSync(filePath);
|
|
445
763
|
if (stats.isFile()) {
|
|
446
764
|
const getTableName = FileUtils_default.extracTableNameFromCube(filePath);
|
|
447
|
-
const tableName = getTableName.status === 200 ? getTableName.message :
|
|
765
|
+
const tableName = getTableName.status === 200 ? getTableName.message : import_path2.default.basename(file, ".table.cube");
|
|
448
766
|
await UIUtils.showItemProgress(tableName, index + 1, cubeFiles.length);
|
|
449
767
|
try {
|
|
450
768
|
const validation = this.validateDatabaseConfiguration(filePath);
|
|
@@ -526,8 +844,8 @@ var Schema = class {
|
|
|
526
844
|
}
|
|
527
845
|
async freshTables() {
|
|
528
846
|
const startTime = Date.now();
|
|
529
|
-
const cubesDir =
|
|
530
|
-
if (!
|
|
847
|
+
const cubesDir = import_path2.default.join(process.cwd(), "dbcube", "cubes");
|
|
848
|
+
if (!import_fs3.default.existsSync(cubesDir)) {
|
|
531
849
|
throw new Error("\u274C The cubes folder does not exist");
|
|
532
850
|
}
|
|
533
851
|
const cubeFiles = FileUtils_default.getCubeFilesRecursively("dbcube", "table.cube");
|
|
@@ -542,11 +860,11 @@ var Schema = class {
|
|
|
542
860
|
const errors = [];
|
|
543
861
|
for (let index = 0; index < cubeFiles.length; index++) {
|
|
544
862
|
const file = cubeFiles[index];
|
|
545
|
-
const filePath =
|
|
546
|
-
const stats =
|
|
863
|
+
const filePath = import_path2.default.isAbsolute(file) ? file : import_path2.default.join(cubesDir, file);
|
|
864
|
+
const stats = import_fs3.default.statSync(filePath);
|
|
547
865
|
if (stats.isFile()) {
|
|
548
866
|
const getTableName = FileUtils_default.extracTableNameFromCube(filePath);
|
|
549
|
-
const tableName = getTableName.status === 200 ? getTableName.message :
|
|
867
|
+
const tableName = getTableName.status === 200 ? getTableName.message : import_path2.default.basename(file, ".table.cube");
|
|
550
868
|
await UIUtils.showItemProgress(tableName, index + 1, cubeFiles.length);
|
|
551
869
|
try {
|
|
552
870
|
const validation = this.validateDatabaseConfiguration(filePath);
|
|
@@ -626,8 +944,8 @@ var Schema = class {
|
|
|
626
944
|
}
|
|
627
945
|
async executeSeeders() {
|
|
628
946
|
const startTime = Date.now();
|
|
629
|
-
const cubesDir =
|
|
630
|
-
if (!
|
|
947
|
+
const cubesDir = import_path2.default.join(process.cwd(), "dbcube", "cubes");
|
|
948
|
+
if (!import_fs3.default.existsSync(cubesDir)) {
|
|
631
949
|
throw new Error("\u274C The cubes folder does not exist");
|
|
632
950
|
}
|
|
633
951
|
const cubeFiles = FileUtils_default.getCubeFilesRecursively("dbcube", "seeder.cube");
|
|
@@ -642,11 +960,11 @@ var Schema = class {
|
|
|
642
960
|
const errors = [];
|
|
643
961
|
for (let index = 0; index < cubeFiles.length; index++) {
|
|
644
962
|
const file = cubeFiles[index];
|
|
645
|
-
const filePath =
|
|
646
|
-
const stats =
|
|
963
|
+
const filePath = import_path2.default.isAbsolute(file) ? file : import_path2.default.join(cubesDir, file);
|
|
964
|
+
const stats = import_fs3.default.statSync(filePath);
|
|
647
965
|
if (stats.isFile()) {
|
|
648
966
|
const getSeederName = FileUtils_default.extracTableNameFromCube(filePath);
|
|
649
|
-
const seederName = getSeederName.status === 200 ? getSeederName.message :
|
|
967
|
+
const seederName = getSeederName.status === 200 ? getSeederName.message : import_path2.default.basename(file, ".seeder.cube");
|
|
650
968
|
await UIUtils.showItemProgress(seederName, index + 1, cubeFiles.length);
|
|
651
969
|
try {
|
|
652
970
|
const validation = this.validateDatabaseConfiguration(filePath);
|
|
@@ -697,9 +1015,9 @@ var Schema = class {
|
|
|
697
1015
|
}
|
|
698
1016
|
async executeTriggers() {
|
|
699
1017
|
const startTime = Date.now();
|
|
700
|
-
const cubesDir =
|
|
701
|
-
const triggersDirExit =
|
|
702
|
-
if (!
|
|
1018
|
+
const cubesDir = import_path2.default.join(process.cwd(), "dbcube", "cubes");
|
|
1019
|
+
const triggersDirExit = import_path2.default.join(process.cwd(), "dbcube", "triggers");
|
|
1020
|
+
if (!import_fs3.default.existsSync(cubesDir)) {
|
|
703
1021
|
throw new Error("\u274C The cubes folder does not exist");
|
|
704
1022
|
}
|
|
705
1023
|
const cubeFiles = FileUtils_default.getCubeFilesRecursively("dbcube", "trigger.cube");
|
|
@@ -714,11 +1032,11 @@ var Schema = class {
|
|
|
714
1032
|
const errors = [];
|
|
715
1033
|
for (let index = 0; index < cubeFiles.length; index++) {
|
|
716
1034
|
const file = cubeFiles[index];
|
|
717
|
-
const filePath =
|
|
718
|
-
const stats =
|
|
1035
|
+
const filePath = import_path2.default.isAbsolute(file) ? file : import_path2.default.join(cubesDir, file);
|
|
1036
|
+
const stats = import_fs3.default.statSync(filePath);
|
|
719
1037
|
if (stats.isFile()) {
|
|
720
1038
|
const getTriggerName = FileUtils_default.extracTableNameFromCube(filePath);
|
|
721
|
-
const triggerName = getTriggerName.status === 200 ? getTriggerName.message :
|
|
1039
|
+
const triggerName = getTriggerName.status === 200 ? getTriggerName.message : import_path2.default.basename(file, ".trigger.cube");
|
|
722
1040
|
await UIUtils.showItemProgress(triggerName, index + 1, cubeFiles.length);
|
|
723
1041
|
try {
|
|
724
1042
|
const validation = this.validateDatabaseConfiguration(filePath);
|
|
@@ -789,7 +1107,7 @@ ${import_chalk2.default.red("\u{1F6AB}")} ${import_chalk2.default.bold.red("ERRO
|
|
|
789
1107
|
const errorLocation = `${filePath}:${lineStr}:${columnStr}`;
|
|
790
1108
|
console.log(`${import_chalk2.default.cyan("[code]")} ${import_chalk2.default.yellow(errorLocation)}`);
|
|
791
1109
|
try {
|
|
792
|
-
const codeLines =
|
|
1110
|
+
const codeLines = import_fs3.default.readFileSync(filePath, "utf-8").split("\n");
|
|
793
1111
|
const start = Math.max(0, lineNum - 3);
|
|
794
1112
|
const end = Math.min(codeLines.length, lineNum + 2);
|
|
795
1113
|
for (let i = start; i < end; i++) {
|
|
@@ -803,6 +1121,7 @@ ${import_chalk2.default.red("\u{1F6AB}")} ${import_chalk2.default.bold.red("ERRO
|
|
|
803
1121
|
}
|
|
804
1122
|
}
|
|
805
1123
|
}
|
|
1124
|
+
console.log("");
|
|
806
1125
|
process.exit(1);
|
|
807
1126
|
}
|
|
808
1127
|
|
|
@@ -810,6 +1129,8 @@ ${import_chalk2.default.red("\u{1F6AB}")} ${import_chalk2.default.bold.red("ERRO
|
|
|
810
1129
|
var index_default = Schema;
|
|
811
1130
|
// Annotate the CommonJS export names for ESM import in node:
|
|
812
1131
|
0 && (module.exports = {
|
|
813
|
-
|
|
1132
|
+
CubeValidator,
|
|
1133
|
+
Schema,
|
|
1134
|
+
UIUtils
|
|
814
1135
|
});
|
|
815
1136
|
//# sourceMappingURL=index.cjs.map
|