@lark-apaas/db-schema-sync 0.1.4-alpha.2 → 0.1.4-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/bin.js +4 -13
- package/dist/{chunk-FYE77WXG.js → chunk-PCRM6U2W.js} +13 -11
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
__toESM,
|
|
7
7
|
generateSchema,
|
|
8
8
|
resolveEnvOptions
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-PCRM6U2W.js";
|
|
10
10
|
|
|
11
11
|
// node_modules/dotenv/package.json
|
|
12
12
|
var require_package = __commonJS({
|
|
@@ -407,22 +407,16 @@ var require_main = __commonJS({
|
|
|
407
407
|
var import_dotenv = __toESM(require_main(), 1);
|
|
408
408
|
import { resolve, dirname } from "path";
|
|
409
409
|
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
410
|
-
|
|
411
|
-
// src/cli-args.ts
|
|
412
410
|
function parseArgs(argv) {
|
|
413
411
|
const args = argv.slice(2);
|
|
414
412
|
const getArg = (name) => {
|
|
415
413
|
const idx = args.indexOf(name);
|
|
416
414
|
return idx !== -1 && args[idx + 1] ? args[idx + 1] : void 0;
|
|
417
415
|
};
|
|
418
|
-
const hasFlag = (name) => args.includes(name);
|
|
419
416
|
return {
|
|
420
|
-
output: getArg("--output")
|
|
421
|
-
exportCustomTypes: hasFlag("--export-custom-types")
|
|
417
|
+
output: getArg("--output")
|
|
422
418
|
};
|
|
423
419
|
}
|
|
424
|
-
|
|
425
|
-
// src/bin.ts
|
|
426
420
|
async function main() {
|
|
427
421
|
const envPath = resolve(process.cwd(), ".env");
|
|
428
422
|
if (existsSync(envPath)) {
|
|
@@ -434,11 +428,8 @@ async function main() {
|
|
|
434
428
|
try {
|
|
435
429
|
const options = resolveEnvOptions();
|
|
436
430
|
console.log("[db-schema-sync] Starting...");
|
|
437
|
-
console.log(`[db-schema-sync] app_id=${options.appId}, dbBranch=${options.dbBranch}
|
|
438
|
-
const schema = await generateSchema(
|
|
439
|
-
...options,
|
|
440
|
-
exportCustomTypes: cliArgs.exportCustomTypes
|
|
441
|
-
});
|
|
431
|
+
console.log(`[db-schema-sync] app_id=${options.appId}, dbBranch=${options.dbBranch}`);
|
|
432
|
+
const schema = await generateSchema(options);
|
|
442
433
|
if (!schema.includes("pgTable") && !schema.includes("pgView")) {
|
|
443
434
|
console.warn("[db-schema-sync] \u26A0 Warning: No tables or views found in database. The generated schema will be empty.");
|
|
444
435
|
}
|
|
@@ -1276,11 +1276,17 @@ var primitiveMappers = [
|
|
|
1276
1276
|
generate: (f) => `uuid("${escapeDoubleQuote(f.fieldName)}")`,
|
|
1277
1277
|
imports: () => [{ name: "uuid", from: PG_CORE }]
|
|
1278
1278
|
},
|
|
1279
|
-
// varchar
|
|
1279
|
+
// varchar (honors extraInfo.max_length from listTableView API)
|
|
1280
1280
|
{
|
|
1281
1281
|
name: "varchar",
|
|
1282
1282
|
match: (f) => f.type === "varchar",
|
|
1283
|
-
generate: (f) =>
|
|
1283
|
+
generate: (f) => {
|
|
1284
|
+
const maxLength = f.extraInfo?.max_length;
|
|
1285
|
+
if (typeof maxLength === "number" && Number.isInteger(maxLength) && maxLength > 0) {
|
|
1286
|
+
return `varchar("${escapeDoubleQuote(f.fieldName)}", { length: ${maxLength} })`;
|
|
1287
|
+
}
|
|
1288
|
+
return `varchar("${escapeDoubleQuote(f.fieldName)}")`;
|
|
1289
|
+
},
|
|
1284
1290
|
imports: () => [{ name: "varchar", from: PG_CORE }]
|
|
1285
1291
|
},
|
|
1286
1292
|
// text
|
|
@@ -1908,15 +1914,11 @@ var inlineTypesEnhancer = {
|
|
|
1908
1914
|
let text = source;
|
|
1909
1915
|
text = text.replace(/import \{[^}]*\} from ["']\.\/types["'];?\n*/g, "");
|
|
1910
1916
|
const usedTypes = /* @__PURE__ */ new Set();
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
usedTypes.add(rule.usageName);
|
|
1917
|
-
if (rule.deps) {
|
|
1918
|
-
for (const dep of rule.deps) usedTypes.add(dep);
|
|
1919
|
-
}
|
|
1917
|
+
for (const rule of TYPE_RULES) {
|
|
1918
|
+
if (text.includes(rule.usageName + "(") && !text.includes(rule.definitionCheck)) {
|
|
1919
|
+
usedTypes.add(rule.usageName);
|
|
1920
|
+
if (rule.deps) {
|
|
1921
|
+
for (const dep of rule.deps) usedTypes.add(dep);
|
|
1920
1922
|
}
|
|
1921
1923
|
}
|
|
1922
1924
|
}
|
package/dist/index.js
CHANGED