@dbml/parse 8.0.0-alpha.0 → 8.0.0-alpha.4
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/dbml-parse.js +22 -22
- package/dist/dbml-parse.mjs +164 -76
- package/dist/src/compiler/index.d.ts +1 -1
- package/dist/src/compiler/queries/files/usableMembers.d.ts +5 -3
- package/dist/src/core/global_modules/records/utils/index.d.ts +1 -0
- package/package.json +2 -2
- /package/dist/src/core/global_modules/{program → records}/utils/constraints/fk.d.ts +0 -0
- /package/dist/src/core/global_modules/{program → records}/utils/constraints/helper.d.ts +0 -0
- /package/dist/src/core/global_modules/{program → records}/utils/constraints/index.d.ts +0 -0
- /package/dist/src/core/global_modules/{program → records}/utils/constraints/pk.d.ts +0 -0
- /package/dist/src/core/global_modules/{program → records}/utils/constraints/unique.d.ts +0 -0
package/dist/dbml-parse.mjs
CHANGED
|
@@ -1257,13 +1257,13 @@ var isAbsolute = function(r) {
|
|
|
1257
1257
|
function resolveImportFilepath(r, j) {
|
|
1258
1258
|
if (!Filepath.isRelative(j)) return;
|
|
1259
1259
|
let M = Filepath.resolve(r.dirname, j);
|
|
1260
|
-
return M.absolute.endsWith(".dbml") ? M : Filepath.from(M.absolute +
|
|
1260
|
+
return M.absolute.endsWith(".dbml") ? M : Filepath.from(M.absolute + ".dbml");
|
|
1261
1261
|
}
|
|
1262
1262
|
const KEYWORDS_OF_DEFAULT_SETTING = [
|
|
1263
1263
|
"null",
|
|
1264
1264
|
"true",
|
|
1265
1265
|
"false"
|
|
1266
|
-
],
|
|
1266
|
+
], NUMERIC_LITERAL_PREFIX = ["-", "+"], DEFAULT_SCHEMA_NAME = "public", DEFAULT_ENTRY = Filepath.from("/main.dbml");
|
|
1267
1267
|
let CompileErrorCode = /* @__PURE__ */ function(r) {
|
|
1268
1268
|
return r[r.UNKNOWN_SYMBOL = 1e3] = "UNKNOWN_SYMBOL", r[r.UNEXPECTED_SYMBOL = 1001] = "UNEXPECTED_SYMBOL", r[r.UNEXPECTED_EOF = 1002] = "UNEXPECTED_EOF", r[r.UNEXPECTED_NEWLINE = 1003] = "UNEXPECTED_NEWLINE", r[r.UNKNOWN_TOKEN = 1004] = "UNKNOWN_TOKEN", r[r.UNEXPECTED_TOKEN = 1005] = "UNEXPECTED_TOKEN", r[r.UNEXPECTED_ELEMENT_DECLARATION = 1006] = "UNEXPECTED_ELEMENT_DECLARATION", r[r.MISSING_SPACES = 1007] = "MISSING_SPACES", r[r.UNKNOWN_PREFIX_OP = 1008] = "UNKNOWN_PREFIX_OP", r[r.INVALID_OPERAND = 1009] = "INVALID_OPERAND", r[r.EMPTY_ATTRIBUTE_NAME = 1010] = "EMPTY_ATTRIBUTE_NAME", r[r.INVALID_ESCAPE_SEQUENCE = 1011] = "INVALID_ESCAPE_SEQUENCE", r[r.INVALID_NAME = 3e3] = "INVALID_NAME", r[r.UNEXPECTED_NAME = 3001] = "UNEXPECTED_NAME", r[r.NAME_NOT_FOUND = 3002] = "NAME_NOT_FOUND", r[r.DUPLICATE_NAME = 3003] = "DUPLICATE_NAME", r[r.INVALID_ALIAS = 3004] = "INVALID_ALIAS", r[r.UNEXPECTED_ALIAS = 3005] = "UNEXPECTED_ALIAS", r[r.UNEXPECTED_SETTINGS = 3006] = "UNEXPECTED_SETTINGS", r[r.INVALID_SETTINGS = 3007] = "INVALID_SETTINGS", r[r.UNEXPECTED_SIMPLE_BODY = 3008] = "UNEXPECTED_SIMPLE_BODY", r[r.UNEXPECTED_COMPLEX_BODY = 3009] = "UNEXPECTED_COMPLEX_BODY", r[r.INVALID_TABLE_CONTEXT = 3010] = "INVALID_TABLE_CONTEXT", r[r.UNKNOWN_TABLE_SETTING = 3011] = "UNKNOWN_TABLE_SETTING", r[r.DUPLICATE_TABLE_SETTING = 3012] = "DUPLICATE_TABLE_SETTING", r[r.INVALID_TABLEGROUP_CONTEXT = 3013] = "INVALID_TABLEGROUP_CONTEXT", r[r.INVALID_TABLEGROUP_ELEMENT_NAME = 3014] = "INVALID_TABLEGROUP_ELEMENT_NAME", r[r.DUPLICATE_TABLEGROUP_ELEMENT_NAME = 3015] = "DUPLICATE_TABLEGROUP_ELEMENT_NAME", r[r.DUPLICATE_TABLEGROUP_FIELD_NAME = 3016] = "DUPLICATE_TABLEGROUP_FIELD_NAME", r[r.INVALID_TABLEGROUP_FIELD = 3017] = "INVALID_TABLEGROUP_FIELD", r[r.EMPTY_TABLE = 3018] = "EMPTY_TABLE", r[r.INVALID_COLUMN = 3019] = "INVALID_COLUMN", r[r.INVALID_COLUMN_NAME = 3020] = "INVALID_COLUMN_NAME", r[r.UNKNOWN_COLUMN_SETTING = 3021] = "UNKNOWN_COLUMN_SETTING", r[r.INVALID_COLUMN_TYPE = 3022] = "INVALID_COLUMN_TYPE", r[r.DUPLICATE_COLUMN_NAME = 3023] = "DUPLICATE_COLUMN_NAME", r[r.DUPLICATE_COLUMN_SETTING = 3024] = "DUPLICATE_COLUMN_SETTING", r[r.INVALID_COLUMN_SETTING_VALUE = 3025] = "INVALID_COLUMN_SETTING_VALUE", r[r.INVALID_ENUM_CONTEXT = 3026] = "INVALID_ENUM_CONTEXT", r[r.INVALID_ENUM_ELEMENT_NAME = 3027] = "INVALID_ENUM_ELEMENT_NAME", r[r.INVALID_ENUM_ELEMENT = 3028] = "INVALID_ENUM_ELEMENT", r[r.DUPLICATE_ENUM_ELEMENT_NAME = 3029] = "DUPLICATE_ENUM_ELEMENT_NAME", r[r.UNKNOWN_ENUM_ELEMENT_SETTING = 3030] = "UNKNOWN_ENUM_ELEMENT_SETTING", r[r.DUPLICATE_ENUM_ELEMENT_SETTING = 3031] = "DUPLICATE_ENUM_ELEMENT_SETTING", r[r.INVALID_ENUM_ELEMENT_SETTING = 3032] = "INVALID_ENUM_ELEMENT_SETTING", r[r.EMPTY_ENUM = 3033] = "EMPTY_ENUM", r[r.INVALID_REF_CONTEXT = 3034] = "INVALID_REF_CONTEXT", r[r.UNKNOWN_REF_SETTING = 3035] = "UNKNOWN_REF_SETTING", r[r.DUPLICATE_REF_SETTING = 3036] = "DUPLICATE_REF_SETTING", r[r.INVALID_REF_SETTING_VALUE = 3037] = "INVALID_REF_SETTING_VALUE", r[r.INVALID_REF_RELATIONSHIP = 3038] = "INVALID_REF_RELATIONSHIP", r[r.INVALID_REF_FIELD = 3039] = "INVALID_REF_FIELD", r[r.EMPTY_REF = 3040] = "EMPTY_REF", r[r.REF_REDEFINED = 3041] = "REF_REDEFINED", r[r.INVALID_NOTE_CONTEXT = 3042] = "INVALID_NOTE_CONTEXT", r[r.INVALID_NOTE = 3043] = "INVALID_NOTE", r[r.NOTE_REDEFINED = 3044] = "NOTE_REDEFINED", r[r.NOTE_CONTENT_REDEFINED = 3045] = "NOTE_CONTENT_REDEFINED", r[r.EMPTY_NOTE = 3046] = "EMPTY_NOTE", r[r.INVALID_INDEXES_CONTEXT = 3047] = "INVALID_INDEXES_CONTEXT", r[r.INVALID_INDEXES_FIELD = 3048] = "INVALID_INDEXES_FIELD", r[r.INVALID_INDEX = 3049] = "INVALID_INDEX", r[r.UNKNOWN_INDEX_SETTING = 3050] = "UNKNOWN_INDEX_SETTING", r[r.DUPLICATE_INDEX_SETTING = 3051] = "DUPLICATE_INDEX_SETTING", r[r.UNEXPECTED_INDEX_SETTING_VALUE = 3052] = "UNEXPECTED_INDEX_SETTING_VALUE", r[r.INVALID_INDEX_SETTING_VALUE = 3053] = "INVALID_INDEX_SETTING_VALUE", r[r.INVALID_PROJECT_CONTEXT = 3054] = "INVALID_PROJECT_CONTEXT", r[r.PROJECT_REDEFINED = 3055] = "PROJECT_REDEFINED", r[r.INVALID_PROJECT_FIELD = 3056] = "INVALID_PROJECT_FIELD", r[r.INVALID_CUSTOM_CONTEXT = 3057] = "INVALID_CUSTOM_CONTEXT", r[r.INVALID_CUSTOM_ELEMENT_VALUE = 3058] = "INVALID_CUSTOM_ELEMENT_VALUE", r[r.INVALID_ELEMENT_IN_SIMPLE_BODY = 3059] = "INVALID_ELEMENT_IN_SIMPLE_BODY", r[r.INVALID_TABLE_PARTIAL_CONTEXT = 3060] = "INVALID_TABLE_PARTIAL_CONTEXT", r[r.INVALID_TABLE_PARTIAL_ELEMENT_NAME = 3061] = "INVALID_TABLE_PARTIAL_ELEMENT_NAME", r[r.INVALID_TABLE_PARTIAL_SETTING_VALUE = 3062] = "INVALID_TABLE_PARTIAL_SETTING_VALUE", r[r.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME = 3063] = "DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME", r[r.DUPLICATE_TABLE_PARTIAL_SETTING = 3064] = "DUPLICATE_TABLE_PARTIAL_SETTING", r[r.INVALID_TABLE_PARTIAL_INJECTION = 3065] = "INVALID_TABLE_PARTIAL_INJECTION", r[r.INVALID_TABLE_PARTIAL_INJECTION_OP = 3066] = "INVALID_TABLE_PARTIAL_INJECTION_OP", r[r.INVALID_TABLE_PARTIAL_INJECTION_NAME = 3067] = "INVALID_TABLE_PARTIAL_INJECTION_NAME", r[r.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME = 3068] = "DUPLICATE_TABLE_PARTIAL_INJECTION_NAME", r[r.UNKNOWN_TABLE_PARTIAL_SETTING = 3069] = "UNKNOWN_TABLE_PARTIAL_SETTING", r[r.INVALID_TABLE_SETTING_VALUE = 3070] = "INVALID_TABLE_SETTING_VALUE", r[r.INVALID_CHECKS_CONTEXT = 3071] = "INVALID_CHECKS_CONTEXT", r[r.INVALID_CHECKS_FIELD = 3072] = "INVALID_CHECKS_FIELD", r[r.INVALID_CHECK = 3073] = "INVALID_CHECK", r[r.UNKNOWN_CHECK_SETTING = 3074] = "UNKNOWN_CHECK_SETTING", r[r.DUPLICATE_CHECK_SETTING = 3075] = "DUPLICATE_CHECK_SETTING", r[r.INVALID_CHECK_SETTING_VALUE = 3076] = "INVALID_CHECK_SETTING_VALUE", r[r.INVALID_RECORDS_CONTEXT = 3077] = "INVALID_RECORDS_CONTEXT", r[r.INVALID_RECORDS_NAME = 3078] = "INVALID_RECORDS_NAME", r[r.INVALID_RECORDS_FIELD = 3079] = "INVALID_RECORDS_FIELD", r[r.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS = 3080] = "DUPLICATE_COLUMN_REFERENCES_IN_RECORDS", r[r.DUPLICATE_RECORDS_FOR_TABLE = 3081] = "DUPLICATE_RECORDS_FOR_TABLE", r[r.INVALID_USE_CONTEXT = 3082] = "INVALID_USE_CONTEXT", r[r.INVALID_USE_SPECIFIER_KIND = 3083] = "INVALID_USE_SPECIFIER_KIND", r[r.INVALID_USE_SPECIFIER_NAME = 3084] = "INVALID_USE_SPECIFIER_NAME", r[r.INVALID_DIAGRAMVIEW_CONTEXT = 3085] = "INVALID_DIAGRAMVIEW_CONTEXT", r[r.DUPLICATE_DIAGRAMVIEW_NAME = 3086] = "DUPLICATE_DIAGRAMVIEW_NAME", r[r.INVALID_DIAGRAMVIEW_FIELD = 3087] = "INVALID_DIAGRAMVIEW_FIELD", r[r.DUPLICATE_DIAGRAMVIEW_FIELD = 3088] = "DUPLICATE_DIAGRAMVIEW_FIELD", r[r.BINDING_ERROR = 4e3] = "BINDING_ERROR", r[r.NONEXISTENT_MODULE = 4001] = "NONEXISTENT_MODULE", r[r.UNSUPPORTED = 5e3] = "UNSUPPORTED", r[r.CIRCULAR_REF = 5001] = "CIRCULAR_REF", r[r.SAME_ENDPOINT = 5002] = "SAME_ENDPOINT", r[r.UNEQUAL_FIELDS_BINARY_REF = 5003] = "UNEQUAL_FIELDS_BINARY_REF", r[r.CONFLICTING_SETTING = 5004] = "CONFLICTING_SETTING", r[r.TABLE_REAPPEAR_IN_TABLEGROUP = 5005] = "TABLE_REAPPEAR_IN_TABLEGROUP", r;
|
|
1269
1269
|
}({});
|
|
@@ -1504,7 +1504,7 @@ function destructureIndexNode(r) {
|
|
|
1504
1504
|
};
|
|
1505
1505
|
}
|
|
1506
1506
|
function extractQuotedStringToken(r) {
|
|
1507
|
-
if (isExpressionAQuotedString(r)) return r
|
|
1507
|
+
if (isExpressionAQuotedString(r)) return r.expression instanceof VariableNode ? r?.expression?.variable?.value : r.expression.literal.value;
|
|
1508
1508
|
}
|
|
1509
1509
|
function extractNumericLiteral(r) {
|
|
1510
1510
|
return r instanceof PrimaryExpressionNode && r.expression instanceof LiteralNode && r.expression.literal?.kind === SyntaxTokenKind.NUMERIC_LITERAL ? Number(r.expression.literal.value) : null;
|
|
@@ -7558,24 +7558,16 @@ const programModule$1 = {
|
|
|
7558
7558
|
},
|
|
7559
7559
|
symbolMembers(N, P) {
|
|
7560
7560
|
if (!P.isKind(SymbolKind.Program)) return Report.create(PASS_THROUGH);
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
let I = new Map([[DEFAULT_SCHEMA_NAME, N.symbolFactory.create(SchemaSymbol, { name: DEFAULT_SCHEMA_NAME }, P.filepath)]]);
|
|
7564
|
-
for (let r of F.declarations) {
|
|
7565
|
-
let M = N.nodeFullname(r).getFiltered(UNHANDLED) || [], F = M.length <= 1 ? DEFAULT_SCHEMA_NAME : M[0];
|
|
7566
|
-
I.has(F) || I.set(F, N.symbolFactory.create(SchemaSymbol, { name: F }, P.filepath));
|
|
7567
|
-
}
|
|
7561
|
+
if (!(P.declaration instanceof ProgramNode)) return Report.create([]);
|
|
7562
|
+
let F = /* @__PURE__ */ new Map();
|
|
7568
7563
|
for (let r of N.reachableFiles(P.filepath)) {
|
|
7569
7564
|
let { schemaMembers: j } = N.usableMembers(r).getValue();
|
|
7570
|
-
for (let r of j)
|
|
7571
|
-
let { name: j } = r;
|
|
7572
|
-
I.has(j) || I.set(j, N.symbolFactory.create(SchemaSymbol, { name: j }, P.filepath));
|
|
7573
|
-
}
|
|
7565
|
+
for (let r of j) F.has(r.name) || F.set(r.name, r);
|
|
7574
7566
|
}
|
|
7575
|
-
let
|
|
7576
|
-
if (!
|
|
7577
|
-
let
|
|
7578
|
-
return
|
|
7567
|
+
let I = F.get(DEFAULT_SCHEMA_NAME);
|
|
7568
|
+
if (!I) return Report.create([...F.values()]);
|
|
7569
|
+
let L = N.symbolMembers(I).getFiltered(UNHANDLED)?.filter((r) => !r.isKind(SymbolKind.Schema));
|
|
7570
|
+
return L ? Report.create([...F.values(), ...L]) : Report.create([...F.values()]);
|
|
7579
7571
|
},
|
|
7580
7572
|
bindNode(j, N) {
|
|
7581
7573
|
return isProgramNode(N) ? new Binder(N, j).resolve() : Report.create(PASS_THROUGH);
|
|
@@ -8209,15 +8201,15 @@ const useUtils = { visibleName(r, M) {
|
|
|
8209
8201
|
nodeSymbol(N, P) {
|
|
8210
8202
|
if (!isUseSpecifier(P) || !P.name) return Report.create(PASS_THROUGH);
|
|
8211
8203
|
let F = P.getSymbolKind();
|
|
8212
|
-
if (F === void 0
|
|
8204
|
+
if (F === void 0) return Report.create(PASS_THROUGH);
|
|
8213
8205
|
let I = N.nodeReferee(P.name).getFiltered(UNHANDLED);
|
|
8214
|
-
return I && !I.canBeImported ? Report.create(PASS_THROUGH) : Report.create(N.symbolFactory.create(UseSymbol, {
|
|
8206
|
+
return I && !I.canBeImported && F !== SymbolKind.Schema ? Report.create(PASS_THROUGH) : Report.create(N.symbolFactory.create(UseSymbol, {
|
|
8215
8207
|
useSpecifierDeclaration: P,
|
|
8216
8208
|
declaration: I?.declaration,
|
|
8217
8209
|
usedSymbol: I,
|
|
8218
8210
|
kind: F,
|
|
8219
8211
|
name: useUtils.visibleName(N, P)?.at(-1)
|
|
8220
|
-
}, P.filepath), I === void 0 ? [new CompileError(CompileErrorCode.BINDING_ERROR, `Failed to resolve the import of ${F} '${(
|
|
8212
|
+
}, P.filepath), I === void 0 ? [new CompileError(CompileErrorCode.BINDING_ERROR, `Failed to resolve the import of ${F} '${(destructureComplexVariable(P.name) || []).map(addDoubleQuoteIfNeeded).join(".")}'`, P)] : []);
|
|
8221
8213
|
},
|
|
8222
8214
|
symbolMembers(N, P) {
|
|
8223
8215
|
if (!(P instanceof UseSymbol)) return Report.create(PASS_THROUGH);
|
|
@@ -8298,64 +8290,23 @@ function lookupMemberInFilepath(r, M, N, P, F = /* @__PURE__ */ new Set()) {
|
|
|
8298
8290
|
}
|
|
8299
8291
|
}
|
|
8300
8292
|
function usableMembers(r) {
|
|
8301
|
-
let N = [], P = /* @__PURE__ */ new Map(), F = [], I = [], L = [], R = [], z = r instanceof Filepath ? r : r.filepath, B = this.parseFile(z), { ast: V } = B.getValue();
|
|
8302
|
-
for (let r of V.body) {
|
|
8303
|
-
if (!(r instanceof UseDeclarationNode) || !r.specifiers || !r.importPath) continue;
|
|
8304
|
-
let j = resolveImportFilepath(z, r.importPath.value);
|
|
8305
|
-
j && (r.isReuse ? r.specifiers instanceof WildcardNode ? F.push({
|
|
8306
|
-
importPath: j,
|
|
8307
|
-
node: r.specifiers
|
|
8308
|
-
}) : I.push(...r.specifiers.specifiers) : r.specifiers instanceof WildcardNode ? L.push({
|
|
8309
|
-
importPath: j,
|
|
8310
|
-
node: r.specifiers
|
|
8311
|
-
}) : R.push(...r.specifiers.specifiers));
|
|
8312
|
-
}
|
|
8313
|
-
let H = [];
|
|
8314
8293
|
if (r instanceof Filepath) {
|
|
8315
|
-
let M =
|
|
8316
|
-
|
|
8317
|
-
let P = this.nodeFullname(N).getFiltered(UNHANDLED) || [], F = P.length <= 1 ? DEFAULT_SCHEMA_NAME : P[0];
|
|
8318
|
-
M.has(F) || M.set(F, this.symbolFactory.create(SchemaSymbol, { name: F }, r));
|
|
8319
|
-
}
|
|
8320
|
-
H.push(...M.values());
|
|
8321
|
-
let P = H.find((r) => r.isPublicSchema());
|
|
8322
|
-
if (P) {
|
|
8323
|
-
let r = this.usableMembers(P).getFiltered(UNHANDLED);
|
|
8324
|
-
r && N.push(...r.nonSchemaMembers);
|
|
8325
|
-
}
|
|
8326
|
-
} else {
|
|
8327
|
-
let M = r;
|
|
8328
|
-
for (let r of V.body) {
|
|
8329
|
-
if (!(r instanceof ElementDeclarationNode)) continue;
|
|
8330
|
-
let F = schemaMembership(this, M, r), I = this.nodeAlias(r).getFiltered(UNHANDLED), L = this.nodeSymbol(r).getFiltered(UNHANDLED);
|
|
8331
|
-
if (I !== void 0 && M.isPublicSchema() && L && N.push(this.symbolFactory.create(AliasSymbol, {
|
|
8332
|
-
kind: L.kind,
|
|
8333
|
-
declaration: r,
|
|
8334
|
-
aliasedSymbol: L,
|
|
8335
|
-
name: I
|
|
8336
|
-
}, M.filepath)), F.kind !== "none") if (F.kind === "direct") {
|
|
8337
|
-
let M = this.nodeSymbol(r).getFiltered(UNHANDLED);
|
|
8338
|
-
if (!M) continue;
|
|
8339
|
-
N.push(M);
|
|
8340
|
-
} else P.has(F.schemaName) || P.set(F.schemaName, this.symbolFactory.create(SchemaSymbol, {
|
|
8341
|
-
name: F.schemaName,
|
|
8342
|
-
parent: M
|
|
8343
|
-
}, M.filepath));
|
|
8344
|
-
}
|
|
8345
|
-
H.push(...P.values());
|
|
8294
|
+
let { ast: M } = this.parseFile(r).getValue(), N = this.nodeSymbol(M).getFiltered(UNHANDLED);
|
|
8295
|
+
return this.usableMembers(N);
|
|
8346
8296
|
}
|
|
8297
|
+
let N = r.filepath, P = collectImports(this, N), { nonSchemaMembers: F, schemaMembers: I } = r instanceof ProgramSymbol ? usableMembersForProgram(this, r, P) : usableMembersForSchema(this, r, P);
|
|
8347
8298
|
return new Report({
|
|
8348
|
-
nonSchemaMembers:
|
|
8349
|
-
schemaMembers:
|
|
8299
|
+
nonSchemaMembers: F,
|
|
8300
|
+
schemaMembers: I,
|
|
8350
8301
|
reuses: {
|
|
8351
|
-
selective:
|
|
8352
|
-
wildcard:
|
|
8302
|
+
selective: P.selectiveReuses,
|
|
8303
|
+
wildcard: P.wildcardReuses
|
|
8353
8304
|
},
|
|
8354
8305
|
uses: {
|
|
8355
|
-
selective:
|
|
8356
|
-
wildcard:
|
|
8306
|
+
selective: P.selectiveUses,
|
|
8307
|
+
wildcard: P.wildcardUses
|
|
8357
8308
|
}
|
|
8358
|
-
},
|
|
8309
|
+
}, P.parseResult.getErrors(), P.parseResult.getWarnings());
|
|
8359
8310
|
}
|
|
8360
8311
|
function schemaMembership(r, M, N) {
|
|
8361
8312
|
let P = M.qualifiedName, F;
|
|
@@ -8366,6 +8317,124 @@ function schemaMembership(r, M, N) {
|
|
|
8366
8317
|
schemaName: I[P.length]
|
|
8367
8318
|
};
|
|
8368
8319
|
}
|
|
8320
|
+
function collectImports(r, j) {
|
|
8321
|
+
let M = r.parseFile(j), { ast: N } = M.getValue(), P = [], F = [], I = [], L = [];
|
|
8322
|
+
for (let r of N.body) {
|
|
8323
|
+
if (!(r instanceof UseDeclarationNode) || !r.specifiers || !r.importPath) continue;
|
|
8324
|
+
let M = resolveImportFilepath(j, r.importPath.value);
|
|
8325
|
+
M && (r.isReuse ? r.specifiers instanceof WildcardNode ? P.push({
|
|
8326
|
+
importPath: M,
|
|
8327
|
+
node: r.specifiers
|
|
8328
|
+
}) : F.push(...r.specifiers.specifiers) : r.specifiers instanceof WildcardNode ? I.push({
|
|
8329
|
+
importPath: M,
|
|
8330
|
+
node: r.specifiers
|
|
8331
|
+
}) : L.push(...r.specifiers.specifiers));
|
|
8332
|
+
}
|
|
8333
|
+
return {
|
|
8334
|
+
ast: N,
|
|
8335
|
+
parseResult: M,
|
|
8336
|
+
selectiveReuses: F,
|
|
8337
|
+
wildcardReuses: P,
|
|
8338
|
+
selectiveUses: L,
|
|
8339
|
+
wildcardUses: I
|
|
8340
|
+
};
|
|
8341
|
+
}
|
|
8342
|
+
function usableMembersForProgram(r, M, N) {
|
|
8343
|
+
let { ast: P, selectiveUses: F, selectiveReuses: I } = N, L = M.filepath, R = new Map([[DEFAULT_SCHEMA_NAME, r.symbolFactory.create(SchemaSymbol, { name: DEFAULT_SCHEMA_NAME }, L)]]);
|
|
8344
|
+
for (let M of P.declarations) {
|
|
8345
|
+
let N = r.nodeFullname(M).getFiltered(UNHANDLED) || [], P = N.length <= 1 ? DEFAULT_SCHEMA_NAME : N[0];
|
|
8346
|
+
R.has(P) || R.set(P, r.symbolFactory.create(SchemaSymbol, { name: P }, L));
|
|
8347
|
+
}
|
|
8348
|
+
registerProgramSchemas(r, [...F, ...I], R, L);
|
|
8349
|
+
for (let j of r.reachableFiles(L)) for (let M of collectTopLevelSchemaNames(r, j)) R.has(M) || R.set(M, r.symbolFactory.create(SchemaSymbol, { name: M }, L));
|
|
8350
|
+
let z = [...R.values()], B = [], V = z.find((r) => r.isPublicSchema());
|
|
8351
|
+
if (V) {
|
|
8352
|
+
let M = r.usableMembers(V).getFiltered(UNHANDLED);
|
|
8353
|
+
M && B.push(...M.nonSchemaMembers);
|
|
8354
|
+
}
|
|
8355
|
+
return {
|
|
8356
|
+
nonSchemaMembers: B,
|
|
8357
|
+
schemaMembers: z
|
|
8358
|
+
};
|
|
8359
|
+
}
|
|
8360
|
+
function usableMembersForSchema(r, M, N) {
|
|
8361
|
+
let { ast: P, selectiveUses: F, selectiveReuses: I } = N, L = [], R = /* @__PURE__ */ new Map();
|
|
8362
|
+
for (let N of P.body) {
|
|
8363
|
+
if (!(N instanceof ElementDeclarationNode)) continue;
|
|
8364
|
+
let P = schemaMembership(r, M, N), F = r.nodeAlias(N).getFiltered(UNHANDLED), I = r.nodeSymbol(N).getFiltered(UNHANDLED);
|
|
8365
|
+
if (F !== void 0 && M.isPublicSchema() && I && L.push(r.symbolFactory.create(AliasSymbol, {
|
|
8366
|
+
kind: I.kind,
|
|
8367
|
+
declaration: N,
|
|
8368
|
+
aliasedSymbol: I,
|
|
8369
|
+
name: F
|
|
8370
|
+
}, M.filepath)), P.kind !== "none") if (P.kind === "direct") {
|
|
8371
|
+
let M = r.nodeSymbol(N).getFiltered(UNHANDLED);
|
|
8372
|
+
if (!M) continue;
|
|
8373
|
+
L.push(M);
|
|
8374
|
+
} else R.has(P.schemaName) || R.set(P.schemaName, r.symbolFactory.create(SchemaSymbol, {
|
|
8375
|
+
name: P.schemaName,
|
|
8376
|
+
parent: M
|
|
8377
|
+
}, M.filepath));
|
|
8378
|
+
}
|
|
8379
|
+
registerSchemaChildren(r, [...F, ...I], M, R);
|
|
8380
|
+
let z = M.qualifiedName;
|
|
8381
|
+
for (let j of r.reachableFiles(M.filepath)) for (let N of collectChildSchemaNames(r, j, z)) R.has(N) || R.set(N, r.symbolFactory.create(SchemaSymbol, {
|
|
8382
|
+
name: N,
|
|
8383
|
+
parent: M
|
|
8384
|
+
}, M.filepath));
|
|
8385
|
+
return {
|
|
8386
|
+
nonSchemaMembers: L,
|
|
8387
|
+
schemaMembers: [...R.values()]
|
|
8388
|
+
};
|
|
8389
|
+
}
|
|
8390
|
+
function registerProgramSchemas(r, j, M, N) {
|
|
8391
|
+
for (let P of j) {
|
|
8392
|
+
if (P.getSymbolKind() !== SymbolKind.Schema) continue;
|
|
8393
|
+
let j = useUtils.visibleName(r, P)?.at(0);
|
|
8394
|
+
j !== void 0 && !M.has(j) && M.set(j, r.symbolFactory.create(SchemaSymbol, { name: j }, N));
|
|
8395
|
+
}
|
|
8396
|
+
}
|
|
8397
|
+
function registerSchemaChildren(r, j, M, N) {
|
|
8398
|
+
let P = M.qualifiedName;
|
|
8399
|
+
for (let F of j) {
|
|
8400
|
+
if (F.getSymbolKind() !== SymbolKind.Schema) continue;
|
|
8401
|
+
let j = useUtils.visibleName(r, F);
|
|
8402
|
+
if (!j || j.length <= P.length || !P.every((r, M) => r === j[M])) continue;
|
|
8403
|
+
let I = j[P.length];
|
|
8404
|
+
I && !N.has(I) && N.set(I, r.symbolFactory.create(SchemaSymbol, {
|
|
8405
|
+
name: I,
|
|
8406
|
+
parent: M
|
|
8407
|
+
}, M.filepath));
|
|
8408
|
+
}
|
|
8409
|
+
}
|
|
8410
|
+
function collectTopLevelSchemaNames(r, M) {
|
|
8411
|
+
let { ast: N } = r.parseFile(M).getValue(), P = [];
|
|
8412
|
+
for (let M of N.declarations) {
|
|
8413
|
+
let N = r.nodeFullname(M).getFiltered(UNHANDLED) || [], F = N.length <= 1 ? DEFAULT_SCHEMA_NAME : N[0];
|
|
8414
|
+
P.push(F);
|
|
8415
|
+
}
|
|
8416
|
+
let F = collectImports(r, M);
|
|
8417
|
+
for (let j of [...F.selectiveUses, ...F.selectiveReuses]) {
|
|
8418
|
+
if (j.getSymbolKind() !== SymbolKind.Schema) continue;
|
|
8419
|
+
let M = useUtils.visibleName(r, j)?.at(0);
|
|
8420
|
+
M !== void 0 && P.push(M);
|
|
8421
|
+
}
|
|
8422
|
+
return P;
|
|
8423
|
+
}
|
|
8424
|
+
function collectChildSchemaNames(r, M, N) {
|
|
8425
|
+
let { ast: P } = r.parseFile(M).getValue(), F = [];
|
|
8426
|
+
for (let M of P.declarations) {
|
|
8427
|
+
let P = r.nodeFullname(M).getFiltered(UNHANDLED) || [], I = P.length <= 1 ? [DEFAULT_SCHEMA_NAME] : P.slice(0, -1);
|
|
8428
|
+
I.length > N.length && N.every((r, j) => r === I[j]) && F.push(I[N.length]);
|
|
8429
|
+
}
|
|
8430
|
+
let I = collectImports(r, M);
|
|
8431
|
+
for (let j of [...I.selectiveUses, ...I.selectiveReuses]) {
|
|
8432
|
+
if (j.getSymbolKind() !== SymbolKind.Schema) continue;
|
|
8433
|
+
let M = useUtils.visibleName(r, j);
|
|
8434
|
+
!M || M.length <= N.length || N.every((r, j) => r === M[j]) && F.push(M[N.length]);
|
|
8435
|
+
}
|
|
8436
|
+
return F;
|
|
8437
|
+
}
|
|
8369
8438
|
var TableBinder = class {
|
|
8370
8439
|
constructor(r, j) {
|
|
8371
8440
|
this.compiler = r, this.declarationNode = j;
|
|
@@ -9358,14 +9427,14 @@ const schemaModule = { symbolMembers(N, P) {
|
|
|
9358
9427
|
let M = handleMemberSelectiveUses(N, P, r, R);
|
|
9359
9428
|
z.push(...M.getErrors());
|
|
9360
9429
|
let F = M.getFiltered(UNHANDLED);
|
|
9361
|
-
F && L.push(F);
|
|
9430
|
+
F && L.push(F), L.push(...mergeImportedSchema(N, P, r));
|
|
9362
9431
|
}
|
|
9363
9432
|
for (let { importPath: r, node: j } of I.reuses.wildcard) L.push(...handleMemberWildcardUses(N, P, r, j, R));
|
|
9364
9433
|
for (let r of I.uses.selective) {
|
|
9365
9434
|
let M = handleMemberSelectiveUses(N, P, r, R);
|
|
9366
9435
|
z.push(...M.getErrors());
|
|
9367
9436
|
let F = M.getFiltered(UNHANDLED);
|
|
9368
|
-
F && L.push(F);
|
|
9437
|
+
F && L.push(F), L.push(...mergeImportedSchema(N, P, r));
|
|
9369
9438
|
}
|
|
9370
9439
|
for (let { importPath: r, node: j } of I.uses.wildcard) L.push(...handleMemberWildcardUses(N, P, r, j, R));
|
|
9371
9440
|
L.push(...R.values());
|
|
@@ -9406,6 +9475,25 @@ function handleMemberSelectiveUses(r, N, P, F) {
|
|
|
9406
9475
|
parent: N
|
|
9407
9476
|
}, N.filepath)), Report.create(void 0);
|
|
9408
9477
|
}
|
|
9478
|
+
function mergeImportedSchema(r, M, N, P = /* @__PURE__ */ new Set()) {
|
|
9479
|
+
if (N.getSymbolKind() !== SymbolKind.Schema || !N.name) return [];
|
|
9480
|
+
let F = r.nodeReferee(N.name).getFiltered(UNHANDLED);
|
|
9481
|
+
if (!F || !F.isKind(SymbolKind.Schema) || F.name !== M.name) return [];
|
|
9482
|
+
let I = F.intern();
|
|
9483
|
+
if (P.has(I)) return [];
|
|
9484
|
+
P.add(I);
|
|
9485
|
+
let L = r.usableMembers(F).getFiltered(UNHANDLED);
|
|
9486
|
+
if (!L) return [];
|
|
9487
|
+
let R = L.nonSchemaMembers.filter((r) => r.canBeImported).map((j) => r.symbolFactory.create(UseSymbol, {
|
|
9488
|
+
kind: j.kind,
|
|
9489
|
+
declaration: j.originalSymbol.declaration,
|
|
9490
|
+
usedSymbol: j.originalSymbol,
|
|
9491
|
+
useSpecifierDeclaration: void 0,
|
|
9492
|
+
name: j.name
|
|
9493
|
+
}, M.filepath));
|
|
9494
|
+
for (let j of L.reuses.selective) R.push(...mergeImportedSchema(r, M, j, P));
|
|
9495
|
+
return R;
|
|
9496
|
+
}
|
|
9409
9497
|
function handleMemberWildcardUses(r, M, N, P, F, I = /* @__PURE__ */ new Set()) {
|
|
9410
9498
|
if (I.has(N)) return [];
|
|
9411
9499
|
I.add(N);
|
|
@@ -11023,7 +11111,7 @@ const modules = [
|
|
|
11023
11111
|
nodeFullname(j, N) {
|
|
11024
11112
|
if (!isUseSpecifier(N)) return Report.create(PASS_THROUGH);
|
|
11025
11113
|
let P = destructureComplexVariable(N.name);
|
|
11026
|
-
return !P || P.length === 0 ? Report.create(void 0, [new CompileError(CompileErrorCode.INVALID_NAME, "Use specifiers must have a valid name (simple name or schema-qualified name)", N)]) : N.isKind(ImportKind.TableGroup) && P.length > 1 ? Report.create(P, [new CompileError(CompileErrorCode.INVALID_USE_SPECIFIER_NAME, "A TableGroup name must be a simple name", N)]) : N.isKind(ImportKind.TablePartial) && P.length > 1 ? Report.create(P, [new CompileError(CompileErrorCode.INVALID_USE_SPECIFIER_NAME, "A TablePartial name must be a simple name", N)]) : N.isKind(ImportKind.Note) && P.length > 1 ? Report.create(P, [new CompileError(CompileErrorCode.INVALID_USE_SPECIFIER_NAME, "A Sticky note name must be a simple name", N)]) : (P.length === 1 && P.unshift(DEFAULT_SCHEMA_NAME), new Report(P));
|
|
11114
|
+
return !P || P.length === 0 ? Report.create(void 0, [new CompileError(CompileErrorCode.INVALID_NAME, "Use specifiers must have a valid name (simple name or schema-qualified name)", N)]) : N.isKind(ImportKind.TableGroup) && P.length > 1 ? Report.create(P, [new CompileError(CompileErrorCode.INVALID_USE_SPECIFIER_NAME, "A TableGroup name must be a simple name", N)]) : N.isKind(ImportKind.TablePartial) && P.length > 1 ? Report.create(P, [new CompileError(CompileErrorCode.INVALID_USE_SPECIFIER_NAME, "A TablePartial name must be a simple name", N)]) : N.isKind(ImportKind.Note) && P.length > 1 ? Report.create(P, [new CompileError(CompileErrorCode.INVALID_USE_SPECIFIER_NAME, "A Sticky note name must be a simple name", N)]) : (P.length === 1 && !N.isKind(ImportKind.Schema) && P.unshift(DEFAULT_SCHEMA_NAME), new Report(P));
|
|
11027
11115
|
},
|
|
11028
11116
|
nodeAlias(j, N) {
|
|
11029
11117
|
return isUseSpecifier(N) ? N.alias ? isValidAlias(N.alias) ? new Report(extractVariableFromExpression(N.alias)) : new Report(void 0, [new CompileError(CompileErrorCode.INVALID_ALIAS, "Use aliases can only contain alphanumeric and underscore unless surrounded by double quotes", N.alias)]) : new Report(void 0) : Report.create(PASS_THROUGH);
|
|
@@ -14797,4 +14885,4 @@ var COMPUTING = Symbol("COMPUTING"), Compiler = class {
|
|
|
14797
14885
|
};
|
|
14798
14886
|
}
|
|
14799
14887
|
};
|
|
14800
|
-
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 };
|
|
14888
|
+
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 };
|
|
@@ -47,7 +47,7 @@ export default class Compiler {
|
|
|
47
47
|
symbolUses: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('../core/types/symbol').UseSymbol[]>;
|
|
48
48
|
fileDependencies: (filepath: Filepath) => Filepath[];
|
|
49
49
|
reachableFiles: (entry?: Filepath | undefined) => Filepath[];
|
|
50
|
-
usableMembers: (symbolOrFilepath: Filepath | import('../core/types/symbol').SchemaSymbol) => import('../core/types/report').default<{
|
|
50
|
+
usableMembers: (symbolOrFilepath: Filepath | import('../core/types/symbol').ProgramSymbol | import('../core/types/symbol').SchemaSymbol) => import('../core/types/report').default<{
|
|
51
51
|
nonSchemaMembers: import('../core/types/symbol').NodeSymbol[];
|
|
52
52
|
schemaMembers: import('../core/types/symbol').SchemaSymbol[];
|
|
53
53
|
reuses: {
|
|
@@ -2,8 +2,8 @@ import { default as Compiler } from '../..';
|
|
|
2
2
|
import { Filepath } from '../../../core/types/filepath';
|
|
3
3
|
import { ElementDeclarationNode, UseSpecifierNode, WildcardNode } from '../../../core/types/nodes';
|
|
4
4
|
import { default as Report } from '../../../core/types/report';
|
|
5
|
-
import { NodeSymbol, SchemaSymbol } from '../../../core/types/symbol';
|
|
6
|
-
|
|
5
|
+
import { NodeSymbol, SchemaSymbol, ProgramSymbol } from '../../../core/types/symbol';
|
|
6
|
+
type UsableResult = {
|
|
7
7
|
nonSchemaMembers: NodeSymbol[];
|
|
8
8
|
schemaMembers: SchemaSymbol[];
|
|
9
9
|
reuses: {
|
|
@@ -20,7 +20,8 @@ export declare function usableMembers(this: Compiler, symbolOrFilepath: SchemaSy
|
|
|
20
20
|
node: WildcardNode;
|
|
21
21
|
}[];
|
|
22
22
|
};
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
|
+
export declare function usableMembers(this: Compiler, symbolOrFilepath: SchemaSymbol | ProgramSymbol | Filepath): Report<UsableResult>;
|
|
24
25
|
export type SchemaMembership = {
|
|
25
26
|
kind: 'direct';
|
|
26
27
|
} | {
|
|
@@ -30,3 +31,4 @@ export type SchemaMembership = {
|
|
|
30
31
|
kind: 'none';
|
|
31
32
|
};
|
|
32
33
|
export declare function schemaMembership(compiler: Compiler, schema: SchemaSymbol, element: ElementDeclarationNode | UseSpecifierNode): SchemaMembership;
|
|
34
|
+
export {};
|
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.
|
|
4
|
+
"version": "8.0.0-alpha.4",
|
|
5
5
|
"description": "DBML parser v2",
|
|
6
6
|
"author": "Holistics <dev@holistics.io>",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=18"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "17d4675433b702912a20dcc65a63c03c73c56db5"
|
|
49
49
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|