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