@lark-apaas/db-schema-sync 0.1.0-alpha.4 → 0.1.0-alpha.5

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 CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  __toESM,
7
7
  generateSchema,
8
8
  resolveEnvOptions
9
- } from "./chunk-JZGFS3J2.js";
9
+ } from "./chunk-OF4XHR3O.js";
10
10
 
11
11
  // node_modules/dotenv/package.json
12
12
  var require_package = __commonJS({
@@ -428,8 +428,11 @@ async function main() {
428
428
  try {
429
429
  const options = resolveEnvOptions();
430
430
  console.log("[db-schema-sync] Starting...");
431
- console.log(`[db-schema-sync] app_id=${options.appId}, suda_workspace_id=${options.workspace}, dbBranch=${options.dbBranch}`);
431
+ console.log(`[db-schema-sync] app_id=${options.appId}, dbBranch=${options.dbBranch}`);
432
432
  const schema = await generateSchema(options);
433
+ if (!schema.includes("pgTable") && !schema.includes("pgView")) {
434
+ console.warn("[db-schema-sync] \u26A0 Warning: No tables or views found in database. The generated schema will be empty.");
435
+ }
433
436
  const outputPath = resolve(process.cwd(), output);
434
437
  mkdirSync(dirname(outputPath), { recursive: true });
435
438
  writeFileSync(outputPath, schema, "utf8");
@@ -929,22 +929,17 @@ function getHttpClient() {
929
929
  }
930
930
  function resolveEnvOptions(env = process.env) {
931
931
  const appId = env.app_id;
932
- const workspace = env.suda_workspace_id;
933
932
  if (!appId) {
934
933
  throw new Error("[db-schema-sync] Error: app_id environment variable is required. Set it in your .env file or shell environment.");
935
934
  }
936
- if (!workspace) {
937
- throw new Error("[db-schema-sync] Error: suda_workspace_id environment variable is required. Set it in your .env file or shell environment.");
938
- }
939
935
  return {
940
936
  appId,
941
- workspace,
942
937
  dbBranch: env.FORCE_DB_BRANCH || "main",
943
938
  timeoutMs: env.SCHEMA_API_TIMEOUT_MS ? Number(env.SCHEMA_API_TIMEOUT_MS) : 3e4
944
939
  };
945
940
  }
946
941
  async function fetchListTableView(options) {
947
- const { appId, workspace, dbBranch = "main", timeoutMs = 3e4 } = options;
942
+ const { appId, dbBranch = "main", timeoutMs = 3e4 } = options;
948
943
  const client = getHttpClient();
949
944
  const controller = new AbortController();
950
945
  const timer = setTimeout(() => controller.abort(), timeoutMs);
@@ -956,7 +951,7 @@ async function fetchListTableView(options) {
956
951
  };
957
952
  if (ttEnv) headers["x-tt-env"] = ttEnv;
958
953
  if (webUser) headers["X-Larkgw-Suda-Webuser"] = webUser;
959
- console.log(`[db-schema-sync] GET /v1/app/${appId}/dataloom/schema?dbBranch=${dbBranch}&workspace=${workspace}`);
954
+ console.log(`[db-schema-sync] GET /v1/app/${appId}/dataloom/schema?dbBranch=${dbBranch}`);
960
955
  if (ttEnv) console.log(`[db-schema-sync] x-tt-env: ${ttEnv}`);
961
956
  const response = await client.get(
962
957
  `/v1/app/${appId}/dataloom/schema`,
@@ -1830,8 +1825,7 @@ var TYPE_RULES = [
1830
1825
  {
1831
1826
  usageName: "customTimestamptz",
1832
1827
  definitionCheck: "const customTimestamptz = customType<",
1833
- definition: CUSTOM_TIMESTAMPTZ_DEFINITION,
1834
- alwaysExport: true
1828
+ definition: CUSTOM_TIMESTAMPTZ_DEFINITION
1835
1829
  },
1836
1830
  {
1837
1831
  usageName: "userProfile",
@@ -1893,7 +1887,7 @@ var inlineTypesEnhancer = {
1893
1887
  for (const rule of TYPE_RULES) {
1894
1888
  if (usedTypes.has(rule.usageName) && !text.includes(rule.definitionCheck)) {
1895
1889
  let def = rule.definition;
1896
- if (rule.alwaysExport || exportCustomTypes) {
1890
+ if (exportCustomTypes) {
1897
1891
  def = def.replace(/^(const |function |type )/gm, "export $1");
1898
1892
  }
1899
1893
  definitions.push(def);
package/dist/index.d.ts CHANGED
@@ -157,7 +157,6 @@ interface ApiTableViewResponse {
157
157
 
158
158
  interface FetchOptions {
159
159
  appId: string;
160
- workspace: string;
161
160
  dbBranch?: string;
162
161
  timeoutMs?: number;
163
162
  }
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  generateSchemaFromData,
6
6
  normalizeApiResponse,
7
7
  resolveEnvOptions
8
- } from "./chunk-JZGFS3J2.js";
8
+ } from "./chunk-OF4XHR3O.js";
9
9
  export {
10
10
  generateSchema,
11
11
  generateSchemaCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/db-schema-sync",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",