@dbml/parse 8.0.0-alpha.11 → 8.0.0-alpha.13

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.
@@ -1235,7 +1235,7 @@ var isAbsolute = function(r) {
1235
1235
  }
1236
1236
  relativeTo(r) {
1237
1237
  let j = relative$1(r, this.path);
1238
- return j.startsWith(".") ? j : `./${j}`;
1238
+ return !j.startsWith("./") && !j.startsWith("../") && ![".", ".."].includes(j) ? `./${j}` : j;
1239
1239
  }
1240
1240
  toString() {
1241
1241
  return this.path;
@@ -7638,7 +7638,7 @@ var ProjectBinder = class {
7638
7638
  interpretBody(r) {
7639
7639
  return r.body.flatMap((r) => {
7640
7640
  let j = r;
7641
- switch (j.type?.value.toLowerCase()) {
7641
+ switch (j.getElementKind()) {
7642
7642
  case ElementKind.Table: {
7643
7643
  let r = this.interpretSubElement(j);
7644
7644
  return r.getValue() && this.project.tables?.push(r.getValue()), r.getErrors();
@@ -8591,7 +8591,7 @@ var TableBinder = class {
8591
8591
  }
8592
8592
  interpretSubElements(r) {
8593
8593
  return r.flatMap((r) => {
8594
- switch (r.type?.value.toLowerCase()) {
8594
+ switch (r.getElementKind()) {
8595
8595
  case ElementKind.Note: return this.table.note = {
8596
8596
  value: normalizeNote(extractQuotedStringToken(r.body instanceof BlockExpressionNode ? r.body.body[0].callee : r.body.callee)),
8597
8597
  token: getTokenPosition(r)
@@ -8611,8 +8611,8 @@ var TableBinder = class {
8611
8611
  P.name = extractVariableFromExpression(r.expression) || "";
8612
8612
  let F = r.expression ? this.compiler.nodeReferee(r.expression).getFiltered(UNHANDLED) : void 0, I = this.compiler.parseFile(this.filepath).getValue().ast, L = this.compiler.nodeSymbol(I).getFiltered(UNHANDLED);
8613
8613
  if (F && !L.inNestedSchema(this.compiler, F)) {
8614
- let M = this.compiler.nodeSymbol(this.declarationNode).getFiltered(UNHANDLED), P = M ? (this.compiler.symbolUses(M).getFiltered(UNHANDLED) ?? []).find((r) => r.filepath.equals(this.filepath)) : void 0;
8615
- N.push(new CompileError(CompileErrorCode.UNSUPPORTED, `Import TablePartial from '${F.filepath}' first. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`, P?.useSpecifierDeclaration ?? r));
8614
+ let M = this.compiler.nodeSymbol(this.declarationNode).getFiltered(UNHANDLED), I = M ? (this.compiler.symbolUses(M).getFiltered(UNHANDLED) ?? []).find((r) => r.filepath.equals(this.filepath)) : void 0;
8615
+ N.push(new CompileError(CompileErrorCode.UNSUPPORTED, `TablePartial ${P.name} from '${F.filepath}' should be imported. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`, I?.useSpecifierDeclaration ?? r));
8616
8616
  }
8617
8617
  return this.table.partials.push(P), N;
8618
8618
  }
@@ -9014,8 +9014,8 @@ var TableGroupBinder = class {
9014
9014
  }
9015
9015
  interpretSubElements(r) {
9016
9016
  return r.flatMap((r) => {
9017
- switch (r.type?.value.toLowerCase()) {
9018
- case "note":
9017
+ switch (r.getElementKind()) {
9018
+ case ElementKind.Note:
9019
9019
  this.tableGroup.note = {
9020
9020
  value: normalizeNote(extractQuotedStringToken(r.body instanceof BlockExpressionNode ? r.body.body[0].callee : r.body.callee)),
9021
9021
  token: getTokenPosition(r)
@@ -9236,7 +9236,7 @@ var TablePartialBinder = class {
9236
9236
  }
9237
9237
  interpretSubElements(r) {
9238
9238
  return r.flatMap((r) => {
9239
- switch (r.type?.value.toLowerCase()) {
9239
+ switch (r.getElementKind()) {
9240
9240
  case ElementKind.Note: return this.tablePartial.note = {
9241
9241
  value: normalizeNote(extractQuotedStringToken(r.body instanceof BlockExpressionNode ? r.body.body[0].callee : r.body.callee)),
9242
9242
  token: getTokenPosition(r)
@@ -13179,48 +13179,6 @@ var dbmlMonarchTokensProvider = {
13179
13179
  [/[/*]/, "comment"]
13180
13180
  ]
13181
13181
  }
13182
- }, MemoryProjectLayout = class r {
13183
- constructor(r = {}) {
13184
- this.files = r instanceof Map ? new Map(r) : new Map(Object.entries(r));
13185
- }
13186
- setSource(r, j) {
13187
- this.files.set(r.absolute, j);
13188
- }
13189
- getSource(r) {
13190
- return this.files.get(r.absolute) ?? void 0;
13191
- }
13192
- deleteSource(r) {
13193
- this.files.delete(r.absolute);
13194
- }
13195
- clearSource() {
13196
- this.files.clear();
13197
- }
13198
- exists(r) {
13199
- return this.isFile(r) || this.isDirectory(r);
13200
- }
13201
- isFile(r) {
13202
- return this.files.has(r.absolute);
13203
- }
13204
- isDirectory(r) {
13205
- let j = r.absolute.endsWith("/") ? r.absolute : `${r.absolute}/`;
13206
- for (let r of this.files.keys()) if (r.startsWith(j)) return !0;
13207
- return !1;
13208
- }
13209
- listDirectory(r) {
13210
- let j = r?.absolute ?? "/", M = j.endsWith("/") ? j : j + "/", N = /* @__PURE__ */ new Set();
13211
- for (let r of this.files.keys()) {
13212
- if (!r.startsWith(M)) continue;
13213
- let j = r.slice(M.length), P = j.indexOf("/");
13214
- N.add(M + (P === -1 ? j : j.slice(0, P)));
13215
- }
13216
- return [...N].sort().map(Filepath.from);
13217
- }
13218
- getEntrypoints() {
13219
- return [...this.files.keys()].map(Filepath.from).sort((r, j) => r.absolute.localeCompare(j.absolute));
13220
- }
13221
- clone() {
13222
- return new r(this.files);
13223
- }
13224
13182
  };
13225
13183
  function containerStack(r, j) {
13226
13184
  let M = this.token.flatStream(r), { index: N, token: P } = this.container.token(r, j), F = N === void 0 ? -1 : findLastIndex_default(M, (r) => !r.isInvalid, N);
@@ -13424,7 +13382,7 @@ function bindProject() {
13424
13382
  function interpretFile(r) {
13425
13383
  let N = this.bindFile(r);
13426
13384
  if (N.getErrors().length > 0) return N.map(() => void 0);
13427
- let P = this.parseFile(r).getValue().ast, F = this.nodeSymbol(P).getFiltered(UNHANDLED);
13385
+ let { ast: P } = this.parseFile(r).getValue(), F = this.nodeSymbol(P).getFiltered(UNHANDLED);
13428
13386
  return F ? this.interpretSymbol(F, r).map((r) => r === UNHANDLED || !r ? void 0 : r) : Report.create(void 0);
13429
13387
  }
13430
13388
  function interpretProject() {
@@ -13439,7 +13397,7 @@ function interpretProject() {
13439
13397
  r.push(...F.getErrors()), N.push(...F.getWarnings());
13440
13398
  let L = this.bindFile(P);
13441
13399
  r.push(...L.getErrors()), N.push(...L.getWarnings());
13442
- let R = F.getValue().ast, z = this.nodeSymbol(R).getFiltered(UNHANDLED), B = z ? this.interpretSymbol(z, P) : Report.create(UNHANDLED), V = B.getFiltered(UNHANDLED);
13400
+ let { ast: R } = F.getValue(), z = this.nodeSymbol(R).getFiltered(UNHANDLED), B = z ? this.interpretSymbol(z, P) : Report.create(UNHANDLED), V = B.getFiltered(UNHANDLED);
13443
13401
  V && I.set(P.absolute, V), r.push(...B.getErrors()), N.push(...B.getWarnings());
13444
13402
  }
13445
13403
  let L = {};
@@ -14855,8 +14813,8 @@ function computeDeleteEdit(r, j, M) {
14855
14813
  }];
14856
14814
  }
14857
14815
  var COMPUTING = Symbol("COMPUTING"), Compiler = class {
14858
- constructor(r = new MemoryProjectLayout()) {
14859
- this.nodeIdGenerator = new SyntaxNodeIdGenerator(), this.symbolIdGenerator = new NodeSymbolIdGenerator(), this.symbolFactory = new SymbolFactory(this.symbolIdGenerator), this.sourceSnapshot = /* @__PURE__ */ new Map(), this.globalCache = /* @__PURE__ */ new Map(), this.localCache = /* @__PURE__ */ new Map(), this.parseFile = this.localQuery(parseFile), this.parseProject = this.globalQuery(parseProject), this.validateNode = this.localQuery(validateNode), this.validateFile = this.localQuery(validateFile), this.nodeFullname = this.localQuery(nodeFullname), this.nodeAlias = this.localQuery(nodeAlias), this.nodeSettings = this.localQuery(nodeSettings), this.canonicalName = this.globalQuery(canonicalName), this.bindNode = this.globalQuery(bindNode), this.bindFile = this.globalQuery(bindFile), this.bindProject = this.globalQuery(bindProject), this.interpretSymbol = this.globalQuery(interpretSymbol), this.interpretMetadata = interpretMetadata.bind(this), this.interpretFile = this.globalQuery(interpretFile), this.interpretProject = this.globalQuery(interpretProject), this.nodeSymbol = this.globalQuery(nodeSymbol), this.nodeMetadata = this.globalQuery(nodeMetadata), this.symbolMembers = this.globalQuery(symbolMembers), this.lookupMembers = this.globalQuery(lookupMembers), this.nodeReferee = this.globalQuery(nodeReferee), this.resolutionIndex = this.globalQuery(resolutionIndex), this.symbolReferences = this.globalQuery(symbolReferences), this.symbolParent = this.globalQuery(symbolParent), this.symbolMetadata = this.globalQuery(symbolMetadata), this.symbolAliases = this.globalQuery(symbolAliases), this.symbolUses = this.globalQuery(symbolUses), this.fileDependencies = this.localQuery(fileDependencies), this.reachableFiles = this.globalQuery(reachableFiles), this.usableMembers = this.globalQuery(usableMembers), this.nodeAtPosition = this.localQuery(nodeAtPosition), this.renameTable = renameTable.bind(this), this.syncDiagramView = syncDiagramView.bind(this), this.token = {
14816
+ constructor(r) {
14817
+ this.layout = r, this.nodeIdGenerator = new SyntaxNodeIdGenerator(), this.symbolIdGenerator = new NodeSymbolIdGenerator(), this.symbolFactory = new SymbolFactory(this.symbolIdGenerator), this.sourceSnapshot = /* @__PURE__ */ new Map(), this.globalCache = /* @__PURE__ */ new Map(), this.localCache = /* @__PURE__ */ new Map(), this.parseFile = this.localQuery(parseFile), this.parseProject = this.globalQuery(parseProject), this.validateNode = this.localQuery(validateNode), this.validateFile = this.localQuery(validateFile), this.nodeFullname = this.localQuery(nodeFullname), this.nodeAlias = this.localQuery(nodeAlias), this.nodeSettings = this.localQuery(nodeSettings), this.canonicalName = this.globalQuery(canonicalName), this.bindNode = this.globalQuery(bindNode), this.bindFile = this.globalQuery(bindFile), this.bindProject = this.globalQuery(bindProject), this.interpretSymbol = this.globalQuery(interpretSymbol), this.interpretMetadata = interpretMetadata.bind(this), this.interpretFile = this.globalQuery(interpretFile), this.interpretProject = this.globalQuery(interpretProject), this.nodeSymbol = this.globalQuery(nodeSymbol), this.nodeMetadata = this.globalQuery(nodeMetadata), this.symbolMembers = this.globalQuery(symbolMembers), this.lookupMembers = this.globalQuery(lookupMembers), this.nodeReferee = this.globalQuery(nodeReferee), this.resolutionIndex = this.globalQuery(resolutionIndex), this.symbolReferences = this.globalQuery(symbolReferences), this.symbolParent = this.globalQuery(symbolParent), this.symbolMetadata = this.globalQuery(symbolMetadata), this.symbolAliases = this.globalQuery(symbolAliases), this.symbolUses = this.globalQuery(symbolUses), this.fileDependencies = this.localQuery(fileDependencies), this.reachableFiles = this.globalQuery(reachableFiles), this.usableMembers = this.globalQuery(usableMembers), this.nodeAtPosition = this.localQuery(nodeAtPosition), this.renameTable = renameTable.bind(this), this.syncDiagramView = syncDiagramView.bind(this), this.token = {
14860
14818
  invalidStream: this.localQuery(invalidStream),
14861
14819
  flatStream: this.localQuery(flatStream)
14862
14820
  }, this.parse = {
@@ -14873,7 +14831,7 @@ var COMPUTING = Symbol("COMPUTING"), Compiler = class {
14873
14831
  element: this.localQuery(containerElement),
14874
14832
  scope: this.localQuery(containerScope),
14875
14833
  scopeKind: this.localQuery(containerScopeKind)
14876
- }, this.layout = r;
14834
+ };
14877
14835
  }
14878
14836
  getSource(r) {
14879
14837
  return this.layout.getSource(r);
@@ -14955,5 +14913,47 @@ var COMPUTING = Symbol("COMPUTING"), Compiler = class {
14955
14913
  diagnosticsProvider: new DBMLDiagnosticsProvider(this)
14956
14914
  };
14957
14915
  }
14916
+ }, MemoryProjectLayout = class r {
14917
+ constructor(r = {}) {
14918
+ this.files = r instanceof Map ? new Map(r) : new Map(Object.entries(r));
14919
+ }
14920
+ setSource(r, j) {
14921
+ this.files.set(r.absolute, j);
14922
+ }
14923
+ getSource(r) {
14924
+ return this.files.get(r.absolute) ?? void 0;
14925
+ }
14926
+ deleteSource(r) {
14927
+ this.files.delete(r.absolute);
14928
+ }
14929
+ clearSource() {
14930
+ this.files.clear();
14931
+ }
14932
+ exists(r) {
14933
+ return this.isFile(r) || this.isDirectory(r);
14934
+ }
14935
+ isFile(r) {
14936
+ return this.files.has(r.absolute);
14937
+ }
14938
+ isDirectory(r) {
14939
+ let j = r.absolute.endsWith("/") ? r.absolute : `${r.absolute}/`;
14940
+ for (let r of this.files.keys()) if (r.startsWith(j)) return !0;
14941
+ return !1;
14942
+ }
14943
+ listDirectory(r) {
14944
+ let j = r?.absolute ?? "/", M = j.endsWith("/") ? j : j + "/", N = /* @__PURE__ */ new Set();
14945
+ for (let r of this.files.keys()) {
14946
+ if (!r.startsWith(M)) continue;
14947
+ let j = r.slice(M.length), P = j.indexOf("/");
14948
+ N.add(M + (P === -1 ? j : j.slice(0, P)));
14949
+ }
14950
+ return [...N].sort().map(Filepath.from);
14951
+ }
14952
+ getEntrypoints() {
14953
+ return [...this.files.keys()].map(Filepath.from).sort((r, j) => r.absolute.localeCompare(j.absolute));
14954
+ }
14955
+ clone() {
14956
+ return new r(this.files);
14957
+ }
14958
14958
  };
14959
14959
  export { ArrayNode, AttributeNode, BlockExpressionNode, CallExpressionNode, CommaExpressionNode, CompileError, CompileErrorCode, Compiler, CompletionItemInsertTextRule, CompletionItemKind, DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLDiagnosticsProvider, DBMLReferencesProvider, DEFAULT_ENTRY, ElementDeclarationNode, ElementKind, EmptyNode, FALSY_VALUES, Filepath, FunctionApplicationNode, FunctionExpressionNode, GroupExpressionNode, IdentifierStreamNode, InfixExpressionNode, ListExpressionNode, LiteralNode, MarkerSeverity, MemoryProjectLayout, PostfixExpressionNode, PrefixExpressionNode, PrimaryExpressionNode, ProgramNode, ScopeKind, SymbolKind, SyntaxNode, SyntaxNodeIdGenerator, SyntaxNodeKind, SyntaxToken, SyntaxTokenKind, TRUTHY_VALUES, TupleExpressionNode, UNHANDLED, URI as Uri, UseDeclarationNode, UseSpecifierListNode, UseSpecifierNode, VariableNode, WildcardNode, addDoubleQuoteIfNeeded, dbmlLanguageConfig, dbmlMonarchTokensProvider, escapeString, extractNumericLiteral, extractSignedNumber, formatRecordValue, getRecordValueType, isBinaryType, isBooleanType, isDateTimeType, isEmptyStringLiteral, isFloatType, isFunctionExpression, isIntegerType, isNullish, isNumericType, isOp, isOpToken, isSerialType, isStringType, isTriviaToken, isValidIdentifier, normalizeTypeName, splitQualifiedIdentifier, tryExtractBoolean, tryExtractDateTime, tryExtractEnum, tryExtractInteger, tryExtractNumeric, tryExtractString, unescapeString, validateForeignKeys, validatePrimaryKey, validateUnique };
@@ -9,11 +9,11 @@ export { ScopeKind } from './types';
9
9
  export type { DiagramViewBlock, TableNameInput, TextEdit } from './queries/transform';
10
10
  export { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, splitQualifiedIdentifier, unescapeString, findDiagramViewBlocks, };
11
11
  export default class Compiler {
12
+ layout: DbmlProjectLayout;
12
13
  readonly nodeIdGenerator: SyntaxNodeIdGenerator;
13
14
  readonly symbolIdGenerator: NodeSymbolIdGenerator;
14
15
  readonly symbolFactory: SymbolFactory;
15
- layout: DbmlProjectLayout;
16
- constructor(layout?: DbmlProjectLayout);
16
+ constructor(layout: DbmlProjectLayout);
17
17
  getSource(filepath: Filepath): string | undefined;
18
18
  private sourceSnapshot;
19
19
  private cleanStaleLocalCache;
@@ -8,7 +8,7 @@ export interface DbmlProjectLayout {
8
8
  getEntrypoints(): Filepath[];
9
9
  }
10
10
  export declare class MemoryProjectLayout implements DbmlProjectLayout {
11
- private files;
11
+ private readonly files;
12
12
  constructor(files?: Map<string, string> | Record<string, string>);
13
13
  setSource(filePath: Filepath, content: string): void;
14
14
  getSource(filePath: Filepath): string | undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@dbml/parse",
4
- "version": "8.0.0-alpha.11",
4
+ "version": "8.0.0-alpha.13",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -46,5 +46,5 @@
46
46
  "engines": {
47
47
  "node": ">=18"
48
48
  },
49
- "gitHead": "976e0f27c85468fa8a0fbb2ded04862e86b05b89"
49
+ "gitHead": "632d9ce9317eff1404c5fe35fb16cf732faa3867"
50
50
  }