@lark-apaas/db-schema-sync 0.1.13 → 0.1.14-alpha.20260818084433
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/bin.js +1 -1
- package/dist/{chunk-IHCFEUCL.js → chunk-AUBN2ZMK.js} +78 -16
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1188,11 +1188,75 @@ function sanitizeIdentifier(name) {
|
|
|
1188
1188
|
if (!/^[A-Za-z_]/.test(sanitized)) sanitized = `_${sanitized}`;
|
|
1189
1189
|
return sanitized;
|
|
1190
1190
|
}
|
|
1191
|
+
var TS_BINDING_RESERVED_WORDS = /* @__PURE__ */ new Set([
|
|
1192
|
+
"arguments",
|
|
1193
|
+
"await",
|
|
1194
|
+
"break",
|
|
1195
|
+
"case",
|
|
1196
|
+
"catch",
|
|
1197
|
+
"class",
|
|
1198
|
+
"const",
|
|
1199
|
+
"continue",
|
|
1200
|
+
"debugger",
|
|
1201
|
+
"default",
|
|
1202
|
+
"delete",
|
|
1203
|
+
"do",
|
|
1204
|
+
"else",
|
|
1205
|
+
"enum",
|
|
1206
|
+
"eval",
|
|
1207
|
+
"export",
|
|
1208
|
+
"extends",
|
|
1209
|
+
"false",
|
|
1210
|
+
"finally",
|
|
1211
|
+
"for",
|
|
1212
|
+
"function",
|
|
1213
|
+
"if",
|
|
1214
|
+
"implements",
|
|
1215
|
+
"import",
|
|
1216
|
+
"in",
|
|
1217
|
+
"instanceof",
|
|
1218
|
+
"interface",
|
|
1219
|
+
"let",
|
|
1220
|
+
"new",
|
|
1221
|
+
"null",
|
|
1222
|
+
"package",
|
|
1223
|
+
"private",
|
|
1224
|
+
"protected",
|
|
1225
|
+
"public",
|
|
1226
|
+
"return",
|
|
1227
|
+
"static",
|
|
1228
|
+
"super",
|
|
1229
|
+
"switch",
|
|
1230
|
+
"this",
|
|
1231
|
+
"throw",
|
|
1232
|
+
"true",
|
|
1233
|
+
"try",
|
|
1234
|
+
"typeof",
|
|
1235
|
+
"var",
|
|
1236
|
+
"void",
|
|
1237
|
+
"while",
|
|
1238
|
+
"with",
|
|
1239
|
+
"yield"
|
|
1240
|
+
]);
|
|
1241
|
+
var BINDING_KIND_SUFFIX = {
|
|
1242
|
+
table: "Table",
|
|
1243
|
+
view: "View",
|
|
1244
|
+
materializedView: "MaterializedView",
|
|
1245
|
+
enum: "Enum",
|
|
1246
|
+
sequence: "Sequence"
|
|
1247
|
+
};
|
|
1248
|
+
function sanitizeBindingIdentifier(name, kind = "table") {
|
|
1249
|
+
const base = sanitizeIdentifier(name);
|
|
1250
|
+
if (!TS_BINDING_RESERVED_WORDS.has(base)) {
|
|
1251
|
+
return base;
|
|
1252
|
+
}
|
|
1253
|
+
return `${base}${BINDING_KIND_SUFFIX[kind]}`;
|
|
1254
|
+
}
|
|
1191
1255
|
function sanitizePropertyName(name) {
|
|
1192
1256
|
return sanitizeIdentifier(name);
|
|
1193
1257
|
}
|
|
1194
|
-
function getUniqueIdentifier(name, usedIdentifiers) {
|
|
1195
|
-
const base =
|
|
1258
|
+
function getUniqueIdentifier(name, usedIdentifiers, kind = "table") {
|
|
1259
|
+
const base = sanitizeBindingIdentifier(name, kind);
|
|
1196
1260
|
if (!usedIdentifiers.has(base)) {
|
|
1197
1261
|
usedIdentifiers.add(base);
|
|
1198
1262
|
return base;
|
|
@@ -1262,7 +1326,7 @@ function resolveSystemFieldConflicts(fields) {
|
|
|
1262
1326
|
return toRemove;
|
|
1263
1327
|
}
|
|
1264
1328
|
function normalizeTable(table, usedIdentifiers) {
|
|
1265
|
-
const identifier = getUniqueIdentifier(table.tableName, usedIdentifiers);
|
|
1329
|
+
const identifier = getUniqueIdentifier(table.tableName, usedIdentifiers, "table");
|
|
1266
1330
|
const systemFieldsToRemove = resolveSystemFieldConflicts(table.fields ?? []);
|
|
1267
1331
|
const fields = [];
|
|
1268
1332
|
for (const field of table.fields ?? []) {
|
|
@@ -1282,8 +1346,8 @@ function normalizeTable(table, usedIdentifiers) {
|
|
|
1282
1346
|
indexes
|
|
1283
1347
|
};
|
|
1284
1348
|
}
|
|
1285
|
-
function normalizeView(view, usedIdentifiers) {
|
|
1286
|
-
const identifier = getUniqueIdentifier(view.tableName, usedIdentifiers);
|
|
1349
|
+
function normalizeView(view, usedIdentifiers, kind) {
|
|
1350
|
+
const identifier = getUniqueIdentifier(view.tableName, usedIdentifiers, kind);
|
|
1287
1351
|
const systemFieldsToRemove = resolveSystemFieldConflicts(view.fields ?? []);
|
|
1288
1352
|
const fields = [];
|
|
1289
1353
|
for (const field of view.fields ?? []) {
|
|
@@ -1313,17 +1377,15 @@ function normalizeApiResponse(response) {
|
|
|
1313
1377
|
if (!response) {
|
|
1314
1378
|
return { tables: [], views: [], materializedViews: [], enums: [], sequences: [], syncedTableMap: /* @__PURE__ */ new Map() };
|
|
1315
1379
|
}
|
|
1316
|
-
const
|
|
1317
|
-
const usedViewIdentifiers = /* @__PURE__ */ new Set();
|
|
1318
|
-
const usedMViewIdentifiers = /* @__PURE__ */ new Set();
|
|
1319
|
-
const usedEnumIdentifiers = /* @__PURE__ */ new Set();
|
|
1320
|
-
const usedSeqIdentifiers = /* @__PURE__ */ new Set();
|
|
1380
|
+
const usedIdentifiers = /* @__PURE__ */ new Set();
|
|
1321
1381
|
const tableItems = response.tables?.data ?? response.table?.data ?? [];
|
|
1322
1382
|
const viewItems = response.views?.data ?? response.view?.data ?? [];
|
|
1323
1383
|
const mViewItems = response.materializedViews?.data ?? response.materializedView?.data ?? [];
|
|
1324
|
-
const tables = tableItems.map((t) => normalizeTable(t,
|
|
1325
|
-
const views = viewItems.map((v) => normalizeView(v,
|
|
1326
|
-
const materializedViews = mViewItems.map(
|
|
1384
|
+
const tables = tableItems.map((t) => normalizeTable(t, usedIdentifiers));
|
|
1385
|
+
const views = viewItems.map((v) => normalizeView(v, usedIdentifiers, "view"));
|
|
1386
|
+
const materializedViews = mViewItems.map(
|
|
1387
|
+
(v) => normalizeView(v, usedIdentifiers, "materializedView")
|
|
1388
|
+
);
|
|
1327
1389
|
const enums = (response.enums ?? []).map((e) => {
|
|
1328
1390
|
let values;
|
|
1329
1391
|
if (e.enumValues?.length) {
|
|
@@ -1335,13 +1397,13 @@ function normalizeApiResponse(response) {
|
|
|
1335
1397
|
}
|
|
1336
1398
|
return {
|
|
1337
1399
|
enumName: e.enumName,
|
|
1338
|
-
identifier: getUniqueIdentifier(e.enumName,
|
|
1400
|
+
identifier: getUniqueIdentifier(e.enumName, usedIdentifiers, "enum"),
|
|
1339
1401
|
values
|
|
1340
1402
|
};
|
|
1341
1403
|
});
|
|
1342
1404
|
const sequences = (response.sequences ?? []).map((s) => ({
|
|
1343
1405
|
sequenceName: s.sequenceName,
|
|
1344
|
-
identifier: getUniqueIdentifier(s.sequenceName,
|
|
1406
|
+
identifier: getUniqueIdentifier(s.sequenceName, usedIdentifiers, "sequence")
|
|
1345
1407
|
}));
|
|
1346
1408
|
const allRawTables = [...tableItems, ...viewItems, ...mViewItems];
|
|
1347
1409
|
const syncedTableMap = extractSyncedTableMap(allRawTables);
|
|
@@ -1743,7 +1805,7 @@ function generateIndexCode(idx, tableIdentifier) {
|
|
|
1743
1805
|
// src/generator/structures/foreign-key.ts
|
|
1744
1806
|
function generateForeignKeyCode(rel, tableIdentifier, tableIdentifierMap) {
|
|
1745
1807
|
const columns = rel.fieldNames.map((f) => `table.${sanitizePropertyName(f)}`).join(", ");
|
|
1746
|
-
const targetIdentifier = tableIdentifierMap?.get(rel.targetTableName) ??
|
|
1808
|
+
const targetIdentifier = tableIdentifierMap?.get(rel.targetTableName) ?? sanitizeBindingIdentifier(rel.targetTableName, "table");
|
|
1747
1809
|
const foreignColumns = rel.targetFieldNames.map((f) => `${targetIdentifier}.${sanitizePropertyName(f)}`).join(", ");
|
|
1748
1810
|
const namePart = rel.constraintName ? `
|
|
1749
1811
|
name: "${escapeDoubleQuote(rel.constraintName)}",` : "";
|
package/dist/index.js
CHANGED