From 68b3b826a73026f76a1e59ef41b1ca459890f301 Mon Sep 17 00:00:00 2001 From: Huy-DNA Date: Fri, 30 Jan 2026 13:33:04 +0700 Subject: [PATCH 1/4] fix: validate column reference in ref --- .../analyzer/validator/elementValidators/ref.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/dbml-parse/src/core/analyzer/validator/elementValidators/ref.ts b/packages/dbml-parse/src/core/analyzer/validator/elementValidators/ref.ts index e4bee26e5..cb2a999ad 100644 --- a/packages/dbml-parse/src/core/analyzer/validator/elementValidators/ref.ts +++ b/packages/dbml-parse/src/core/analyzer/validator/elementValidators/ref.ts @@ -11,7 +11,7 @@ import { } from '@/core/parser/utils'; import { ElementValidator } from '@/core/analyzer/validator/types'; import { isSimpleName, isValidColor, pickValidator, aggregateSettingList } from '@/core/analyzer/validator/utils'; -import { isBinaryRelationship, isEqualTupleOperands } from '@/core/analyzer/utils'; +import { destructureComplexVariable, destructureComplexVariableTuple, isBinaryRelationship, isEqualTupleOperands } from '@/core/analyzer/utils'; import SymbolTable from '@/core/analyzer/symbol/symbolTable'; export default class RefValidator implements ElementValidator { @@ -97,6 +97,19 @@ export default class RefValidator implements ElementValidator { errors.push(new CompileError(CompileErrorCode.INVALID_REF_FIELD, 'A Ref field must be a binary relationship', field.callee)); } + if (field.callee && isBinaryRelationship(field.callee)) { + const leftFragment = destructureComplexVariableTuple(field.callee.leftExpression).unwrap_or({ variables: [], tupleElements: [] }); + const leftFragmentCount = leftFragment.variables.length + Math.min(leftFragment.tupleElements.length, 1); + const rightFragment = destructureComplexVariableTuple(field.callee.rightExpression).unwrap_or({ variables: [], tupleElements: [] }); + const rightFragmentCount = rightFragment.variables.length + Math.min(rightFragment.tupleElements.length, 1); + if (leftFragmentCount < 2) { + errors.push(new CompileError(CompileErrorCode.INVALID_REF_FIELD, 'Invalid column reference', field.callee.leftExpression || field.callee)); + } + if (rightFragmentCount < 2) { + errors.push(new CompileError(CompileErrorCode.INVALID_REF_FIELD, 'Invalid column reference', field.callee.rightExpression || field.callee)); + } + } + if (field.callee && !isEqualTupleOperands(field.callee)) { errors.push(new CompileError(CompileErrorCode.UNEQUAL_FIELDS_BINARY_REF, 'Unequal fields in ref endpoints', field.callee)); } From b0ec1c39f89d5e3d037b6d764c0c39beb2b5894a Mon Sep 17 00:00:00 2001 From: Huy-DNA Date: Fri, 30 Jan 2026 14:10:22 +0700 Subject: [PATCH 2/4] test: update tests --- .../validator/output/ref_in_table.out.json | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) diff --git a/packages/dbml-parse/__tests__/snapshots/validator/output/ref_in_table.out.json b/packages/dbml-parse/__tests__/snapshots/validator/output/ref_in_table.out.json index db4a7a21d..a92c953c2 100644 --- a/packages/dbml-parse/__tests__/snapshots/validator/output/ref_in_table.out.json +++ b/packages/dbml-parse/__tests__/snapshots/validator/output/ref_in_table.out.json @@ -3961,6 +3961,92 @@ "end": 147, "name": "CompileError" }, + { + "code": 3039, + "diagnostic": "Invalid column reference", + "nodeOrToken": { + "id": 41, + "kind": "", + "startPos": { + "offset": 138, + "line": 13, + "column": 9 + }, + "fullStart": 138, + "endPos": { + "offset": 140, + "line": 13, + "column": 11 + }, + "fullEnd": 141, + "start": 138, + "end": 140, + "expression": { + "id": 40, + "kind": "", + "startPos": { + "offset": 138, + "line": 13, + "column": 9 + }, + "fullStart": 138, + "endPos": { + "offset": 140, + "line": 13, + "column": 11 + }, + "fullEnd": 141, + "start": 138, + "end": 140, + "variable": { + "kind": "", + "startPos": { + "offset": 138, + "line": 13, + "column": 9 + }, + "endPos": { + "offset": 140, + "line": 13, + "column": 11 + }, + "value": "id", + "leadingTrivia": [], + "trailingTrivia": [ + { + "kind": "", + "startPos": { + "offset": 140, + "line": 13, + "column": 11 + }, + "endPos": { + "offset": 141, + "line": 13, + "column": 12 + }, + "value": " ", + "leadingTrivia": [], + "trailingTrivia": [], + "leadingInvalid": [], + "trailingInvalid": [], + "isInvalid": false, + "start": 140, + "end": 141 + } + ], + "leadingInvalid": [], + "trailingInvalid": [], + "isInvalid": false, + "start": 138, + "end": 140 + } + } + }, + "start": 138, + "end": 140, + "name": "CompileError" + }, { "code": 3034, "diagnostic": "A Ref must appear top-level", @@ -4469,6 +4555,92 @@ "start": 152, "end": 170, "name": "CompileError" + }, + { + "code": 3039, + "diagnostic": "Invalid column reference", + "nodeOrToken": { + "id": 51, + "kind": "", + "startPos": { + "offset": 157, + "line": 14, + "column": 9 + }, + "fullStart": 157, + "endPos": { + "offset": 161, + "line": 14, + "column": 13 + }, + "fullEnd": 162, + "start": 157, + "end": 161, + "expression": { + "id": 50, + "kind": "", + "startPos": { + "offset": 157, + "line": 14, + "column": 9 + }, + "fullStart": 157, + "endPos": { + "offset": 161, + "line": 14, + "column": 13 + }, + "fullEnd": 162, + "start": 157, + "end": 161, + "variable": { + "kind": "", + "startPos": { + "offset": 157, + "line": 14, + "column": 9 + }, + "endPos": { + "offset": 161, + "line": 14, + "column": 13 + }, + "value": "code", + "leadingTrivia": [], + "trailingTrivia": [ + { + "kind": "", + "startPos": { + "offset": 161, + "line": 14, + "column": 13 + }, + "endPos": { + "offset": 162, + "line": 14, + "column": 14 + }, + "value": " ", + "leadingTrivia": [], + "trailingTrivia": [], + "leadingInvalid": [], + "trailingInvalid": [], + "isInvalid": false, + "start": 161, + "end": 162 + } + ], + "leadingInvalid": [], + "trailingInvalid": [], + "isInvalid": false, + "start": 157, + "end": 161 + } + } + }, + "start": 157, + "end": 161, + "name": "CompileError" } ] } \ No newline at end of file From 355cbecd2d809b9750aea2854fbc85bf469db257 Mon Sep 17 00:00:00 2001 From: Huy-DNA Date: Fri, 30 Jan 2026 14:27:32 +0700 Subject: [PATCH 3/4] v5.5.1-alpha.0 --- dbml-playground/package.json | 4 ++-- lerna.json | 2 +- packages/dbml-cli/package.json | 6 +++--- packages/dbml-connector/package.json | 2 +- packages/dbml-core/package.json | 4 ++-- packages/dbml-parse/package.json | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dbml-playground/package.json b/dbml-playground/package.json index 34f5e298c..7767c89ba 100644 --- a/dbml-playground/package.json +++ b/dbml-playground/package.json @@ -1,6 +1,6 @@ { "name": "@dbml/playground", - "version": "5.5.0", + "version": "5.5.1-alpha.0", "description": "Interactive playground for debugging and visualizing the DBML parser pipeline", "author": "Holistics ", "license": "Apache-2.0", @@ -25,7 +25,7 @@ "format": "prettier --write src/" }, "dependencies": { - "@dbml/parse": "^5.5.0", + "@dbml/parse": "^5.5.1-alpha.0", "lodash": "^4.17.21", "monaco-editor": "^0.52.2", "monaco-vim": "^0.4.2", diff --git a/lerna.json b/lerna.json index cf1fa2f22..69b3d6901 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "5.5.0", + "version": "5.5.1-alpha.0", "npmClient": "yarn", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/packages/dbml-cli/package.json b/packages/dbml-cli/package.json index 43efbdb7e..a3c7ec76d 100644 --- a/packages/dbml-cli/package.json +++ b/packages/dbml-cli/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@dbml/cli", - "version": "5.5.0", + "version": "5.5.1-alpha.0", "description": "", "main": "lib/index.js", "license": "Apache-2.0", @@ -30,8 +30,8 @@ ], "dependencies": { "@babel/cli": "^7.21.0", - "@dbml/connector": "^5.5.0", - "@dbml/core": "^5.5.0", + "@dbml/connector": "^5.5.1-alpha.0", + "@dbml/core": "^5.5.1-alpha.0", "bluebird": "^3.5.5", "chalk": "^2.4.2", "commander": "^2.20.0", diff --git a/packages/dbml-connector/package.json b/packages/dbml-connector/package.json index deee3ea2b..6ce1e9de7 100644 --- a/packages/dbml-connector/package.json +++ b/packages/dbml-connector/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@dbml/connector", - "version": "5.5.0", + "version": "5.5.1-alpha.0", "description": "This package was created to fetch the schema JSON from many kind of databases.", "author": "huy.phung.sw@gmail.com", "license": "MIT", diff --git a/packages/dbml-core/package.json b/packages/dbml-core/package.json index 4a8897bf7..505692f4b 100644 --- a/packages/dbml-core/package.json +++ b/packages/dbml-core/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@dbml/core", - "version": "5.5.0", + "version": "5.5.1-alpha.0", "description": "> TODO: description", "author": "Holistics ", "license": "Apache-2.0", @@ -36,7 +36,7 @@ "lint:fix": "eslint --fix ." }, "dependencies": { - "@dbml/parse": "^5.5.0", + "@dbml/parse": "^5.5.1-alpha.0", "antlr4": "^4.13.1", "lodash": "^4.17.15", "parsimmon": "^1.13.0", diff --git a/packages/dbml-parse/package.json b/packages/dbml-parse/package.json index a7beceb56..1d4c41373 100644 --- a/packages/dbml-parse/package.json +++ b/packages/dbml-parse/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@dbml/parse", - "version": "5.5.0", + "version": "5.5.1-alpha.0", "description": "DBML parser v2", "author": "Holistics ", "license": "Apache-2.0", From f5453ea5dadb9c43ec613ac8004ac085ce465728 Mon Sep 17 00:00:00 2001 From: Huy-DNA Date: Fri, 30 Jan 2026 15:36:28 +0700 Subject: [PATCH 4/4] Revert "v5.5.1-alpha.0" This reverts commit 355cbecd2d809b9750aea2854fbc85bf469db257. --- dbml-playground/package.json | 4 ++-- lerna.json | 2 +- packages/dbml-cli/package.json | 6 +++--- packages/dbml-connector/package.json | 2 +- packages/dbml-core/package.json | 4 ++-- packages/dbml-parse/package.json | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dbml-playground/package.json b/dbml-playground/package.json index 7767c89ba..34f5e298c 100644 --- a/dbml-playground/package.json +++ b/dbml-playground/package.json @@ -1,6 +1,6 @@ { "name": "@dbml/playground", - "version": "5.5.1-alpha.0", + "version": "5.5.0", "description": "Interactive playground for debugging and visualizing the DBML parser pipeline", "author": "Holistics ", "license": "Apache-2.0", @@ -25,7 +25,7 @@ "format": "prettier --write src/" }, "dependencies": { - "@dbml/parse": "^5.5.1-alpha.0", + "@dbml/parse": "^5.5.0", "lodash": "^4.17.21", "monaco-editor": "^0.52.2", "monaco-vim": "^0.4.2", diff --git a/lerna.json b/lerna.json index 69b3d6901..cf1fa2f22 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "5.5.1-alpha.0", + "version": "5.5.0", "npmClient": "yarn", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/packages/dbml-cli/package.json b/packages/dbml-cli/package.json index a3c7ec76d..43efbdb7e 100644 --- a/packages/dbml-cli/package.json +++ b/packages/dbml-cli/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@dbml/cli", - "version": "5.5.1-alpha.0", + "version": "5.5.0", "description": "", "main": "lib/index.js", "license": "Apache-2.0", @@ -30,8 +30,8 @@ ], "dependencies": { "@babel/cli": "^7.21.0", - "@dbml/connector": "^5.5.1-alpha.0", - "@dbml/core": "^5.5.1-alpha.0", + "@dbml/connector": "^5.5.0", + "@dbml/core": "^5.5.0", "bluebird": "^3.5.5", "chalk": "^2.4.2", "commander": "^2.20.0", diff --git a/packages/dbml-connector/package.json b/packages/dbml-connector/package.json index 6ce1e9de7..deee3ea2b 100644 --- a/packages/dbml-connector/package.json +++ b/packages/dbml-connector/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@dbml/connector", - "version": "5.5.1-alpha.0", + "version": "5.5.0", "description": "This package was created to fetch the schema JSON from many kind of databases.", "author": "huy.phung.sw@gmail.com", "license": "MIT", diff --git a/packages/dbml-core/package.json b/packages/dbml-core/package.json index 505692f4b..4a8897bf7 100644 --- a/packages/dbml-core/package.json +++ b/packages/dbml-core/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@dbml/core", - "version": "5.5.1-alpha.0", + "version": "5.5.0", "description": "> TODO: description", "author": "Holistics ", "license": "Apache-2.0", @@ -36,7 +36,7 @@ "lint:fix": "eslint --fix ." }, "dependencies": { - "@dbml/parse": "^5.5.1-alpha.0", + "@dbml/parse": "^5.5.0", "antlr4": "^4.13.1", "lodash": "^4.17.15", "parsimmon": "^1.13.0", diff --git a/packages/dbml-parse/package.json b/packages/dbml-parse/package.json index 1d4c41373..a7beceb56 100644 --- a/packages/dbml-parse/package.json +++ b/packages/dbml-parse/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@dbml/parse", - "version": "5.5.1-alpha.0", + "version": "5.5.0", "description": "DBML parser v2", "author": "Holistics ", "license": "Apache-2.0",