@lark-apaas/fullstack-cli 1.1.14 → 1.1.16-alpha.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.
Files changed (2) hide show
  1. package/dist/index.js +122 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -186,7 +186,7 @@ function convertSchemaTableInvocations(source) {
186
186
  // src/commands/db/gen-dbschema/helper/table-rename.ts
187
187
  import { pinyin } from "pinyin-pro";
188
188
  function renamePgTableConstants(source) {
189
- const pgTableRegex = /export const\s+([^\s=]+)\s*=\s*(pgTable|pgView|pgMaterializedView)\(\s*["'`]([^"'`]+)["'`]/gu;
189
+ const pgTableRegex = /export const\s+([^\s=]+)\s*=\s*(pgTable|pgView|pgMaterializedView|pgEnum|pgSequence)\(\s*["'`]([^"'`]+)["'`]/gu;
190
190
  const renames = [];
191
191
  const updated = source.replace(pgTableRegex, (match, currentName, factory, tableName) => {
192
192
  const sanitized = sanitizeIdentifier(tableName);
@@ -209,7 +209,7 @@ function updateTableReferenceIdentifiers(source, renames) {
209
209
  if (!rename.from || rename.from === rename.to) {
210
210
  return acc;
211
211
  }
212
- const pattern = new RegExp(`\\b${escapeRegExp(rename.from)}(\\s*\\.)`, "g");
212
+ const pattern = new RegExp(`\\b${escapeRegExp(rename.from)}(\\s*[.(])`, "g");
213
213
  return acc.replace(pattern, `${rename.to}$1`);
214
214
  }, source);
215
215
  }
@@ -256,16 +256,18 @@ function toAsciiName(name) {
256
256
 
257
257
  // src/commands/db/gen-dbschema/helper/custom-types.ts
258
258
  var CUSTOM_TYPE_PATTERN = /\/\/ TODO: failed to parse database type '(?:\w+\.)?(user_profile|file_attachment)(\[\])?'/;
259
+ var UNKNOWN_TYPE_TODO_PATTERN = /\/\/ TODO: failed to parse database type '([^']+)'/;
259
260
  function replaceUnknownColumns(source) {
260
261
  const lines = source.split("\n");
261
262
  const result = [];
262
263
  let replaced = 0;
264
+ let fallbackToText = 0;
263
265
  const unmatched = [];
264
266
  for (let i = 0; i < lines.length; i += 1) {
265
267
  const line = lines[i];
266
- const match = line.match(CUSTOM_TYPE_PATTERN);
267
- if (match) {
268
- const typeName = match[1];
268
+ const knownMatch = line.match(CUSTOM_TYPE_PATTERN);
269
+ if (knownMatch) {
270
+ const typeName = knownMatch[1];
269
271
  const factory = typeName === "user_profile" ? "userProfile" : "fileAttachment";
270
272
  const replacedLine = replaceFollowingUnknown(lines[i + 1], factory);
271
273
  if (replacedLine) {
@@ -278,6 +280,19 @@ function replaceUnknownColumns(source) {
278
280
  }
279
281
  continue;
280
282
  }
283
+ const unknownMatch = line.match(UNKNOWN_TYPE_TODO_PATTERN);
284
+ if (unknownMatch) {
285
+ const replacedLine = replaceFollowingUnknown(lines[i + 1], "text");
286
+ if (replacedLine) {
287
+ result.push(replacedLine);
288
+ fallbackToText += 1;
289
+ i += 1;
290
+ } else {
291
+ unmatched.push(line.trim());
292
+ result.push(line);
293
+ }
294
+ continue;
295
+ }
281
296
  if (line.includes("unknown(")) {
282
297
  unmatched.push(line.trim());
283
298
  }
@@ -286,6 +301,7 @@ function replaceUnknownColumns(source) {
286
301
  return {
287
302
  text: result.join("\n"),
288
303
  replaced,
304
+ fallbackToText,
289
305
  unmatched
290
306
  };
291
307
  }
@@ -547,6 +563,53 @@ ${aliasLines}
547
563
  `;
548
564
  }
549
565
 
566
+ // src/commands/db/gen-dbschema/helper/system-objects-filter.ts
567
+ var SYSTEM_OBJECTS = [
568
+ // pg_stat_statements 扩展
569
+ "pg_stat_statements",
570
+ "pg_stat_statements_info",
571
+ // pg_partman 扩展
572
+ "part_config",
573
+ "part_config_sub",
574
+ // 系统权限视图
575
+ "table_privs"
576
+ ];
577
+ function removeSystemObjects(source, additionalObjects = []) {
578
+ const objectsToFilter = [...SYSTEM_OBJECTS, ...additionalObjects];
579
+ const removed = [];
580
+ const lines = source.split("\n");
581
+ const result = [];
582
+ let skipUntilNextExport = false;
583
+ let currentSystemObject = null;
584
+ for (let i = 0; i < lines.length; i++) {
585
+ const line = lines[i];
586
+ if (!skipUntilNextExport) {
587
+ const exportMatch = line.match(/^export const (\w+)\s*=/);
588
+ if (exportMatch) {
589
+ const objName = exportMatch[1];
590
+ if (objectsToFilter.includes(objName)) {
591
+ skipUntilNextExport = true;
592
+ currentSystemObject = objName;
593
+ continue;
594
+ }
595
+ }
596
+ }
597
+ if (skipUntilNextExport) {
598
+ if (line.match(/^\}\);/) || line.match(/\.as\([^)]*\);$/)) {
599
+ skipUntilNextExport = false;
600
+ if (currentSystemObject) {
601
+ removed.push(currentSystemObject);
602
+ currentSystemObject = null;
603
+ }
604
+ continue;
605
+ }
606
+ continue;
607
+ }
608
+ result.push(line);
609
+ }
610
+ return { text: result.join("\n"), removed };
611
+ }
612
+
550
613
  // src/commands/db/gen-dbschema/postprocess.ts
551
614
  function postprocessDrizzleSchema(targetPath) {
552
615
  const resolvedPath = path.resolve(targetPath);
@@ -561,6 +624,8 @@ function postprocessDrizzleSchema(targetPath) {
561
624
  text = removePgSchemaDeclarations(text);
562
625
  const tableConversion = convertSchemaTableInvocations(text);
563
626
  text = tableConversion.text;
627
+ const systemObjectsResult = removeSystemObjects(text);
628
+ text = systemObjectsResult.text;
564
629
  const renameResult = renamePgTableConstants(text);
565
630
  text = renameResult.text;
566
631
  text = updateTableReferenceIdentifiers(text, renameResult.renames);
@@ -582,10 +647,13 @@ function postprocessDrizzleSchema(targetPath) {
582
647
  console.info(`[postprocess-drizzle-schema] Patched ${patchResult.fixed} drizzle-kit defects (.default(') -> .default(''))`);
583
648
  }
584
649
  if (replacement.replaced > 0) {
585
- console.info(`[postprocess-drizzle-schema] Replaced ${replacement.replaced} unknown columns`);
650
+ console.info(`[postprocess-drizzle-schema] Replaced ${replacement.replaced} unknown columns with custom types`);
651
+ }
652
+ if (replacement.fallbackToText > 0) {
653
+ console.info(`[postprocess-drizzle-schema] Replaced ${replacement.fallbackToText} unknown columns with text (fallback)`);
586
654
  }
587
655
  if (replacement.unmatched.length > 0) {
588
- console.warn("[postprocess-drizzle-schema] Unmatched custom types:", replacement.unmatched.length);
656
+ console.warn("[postprocess-drizzle-schema] Unmatched unknown columns:", replacement.unmatched.length);
589
657
  replacement.unmatched.forEach((line) => console.warn(` ${line}`));
590
658
  }
591
659
  if (tableConversion.converted > 0) {
@@ -597,12 +665,17 @@ function postprocessDrizzleSchema(targetPath) {
597
665
  if (defaultNowReplacement.replaced > 0) {
598
666
  console.info(`[postprocess-drizzle-schema] Replaced ${defaultNowReplacement.replaced} .defaultNow() with .default(sql\`CURRENT_TIMESTAMP\`)`);
599
667
  }
668
+ if (systemObjectsResult.removed.length > 0) {
669
+ console.info(`[postprocess-drizzle-schema] Removed ${systemObjectsResult.removed.length} system objects: ${systemObjectsResult.removed.join(", ")}`);
670
+ }
600
671
  return {
601
672
  replacedUnknown: replacement.replaced,
673
+ fallbackToText: replacement.fallbackToText,
602
674
  unmatchedUnknown: replacement.unmatched,
603
675
  patchedDefects: patchResult.fixed,
604
676
  replacedTimestamps: timestampReplacement.replaced,
605
- replacedDefaultNow: defaultNowReplacement.replaced
677
+ replacedDefaultNow: defaultNowReplacement.replaced,
678
+ removedSystemObjects: systemObjectsResult.removed
606
679
  };
607
680
  }
608
681
 
@@ -1832,10 +1905,13 @@ function getHttpClient() {
1832
1905
  enabled: true
1833
1906
  }
1834
1907
  });
1835
- clientInstance.interceptors.request.use((req) => {
1836
- req.headers["x-tt-env"] = "boe_miaoda_plugin";
1837
- return req;
1838
- });
1908
+ const canaryEnv = process.env.FORCE_FRAMEWORK_CLI_CANARY_ENV;
1909
+ if (canaryEnv) {
1910
+ clientInstance.interceptors.request.use((req) => {
1911
+ req.headers["x-tt-env"] = canaryEnv;
1912
+ return req;
1913
+ });
1914
+ }
1839
1915
  }
1840
1916
  return clientInstance;
1841
1917
  }
@@ -2280,7 +2356,6 @@ var actionPluginCommandGroup = {
2280
2356
 
2281
2357
  // src/commands/capability/utils.ts
2282
2358
  import fs8 from "fs";
2283
- import { createRequire as createRequire2 } from "module";
2284
2359
  import path7 from "path";
2285
2360
  var CAPABILITIES_DIR = "server/capabilities";
2286
2361
  function getProjectRoot2() {
@@ -2304,7 +2379,7 @@ function listCapabilityIds() {
2304
2379
  return [];
2305
2380
  }
2306
2381
  const files = fs8.readdirSync(dir);
2307
- return files.filter((f) => f.endsWith(".json")).map((f) => f.replace(/\.json$/, ""));
2382
+ return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
2308
2383
  }
2309
2384
  function readCapability(id) {
2310
2385
  const filePath = getCapabilityPath(id);
@@ -2323,7 +2398,19 @@ function readCapability(id) {
2323
2398
  }
2324
2399
  function readAllCapabilities() {
2325
2400
  const ids = listCapabilityIds();
2326
- return ids.map((id) => readCapability(id));
2401
+ const capabilities = [];
2402
+ for (const id of ids) {
2403
+ try {
2404
+ const capability = readCapability(id);
2405
+ if (!capability.pluginKey) {
2406
+ continue;
2407
+ }
2408
+ capabilities.push(capability);
2409
+ } catch {
2410
+ continue;
2411
+ }
2412
+ }
2413
+ return capabilities;
2327
2414
  }
2328
2415
  function readPluginManifest(pluginKey) {
2329
2416
  const manifestPath = getPluginManifestPath(pluginKey);
@@ -2348,10 +2435,7 @@ function hasValidParamsSchema(paramsSchema) {
2348
2435
  }
2349
2436
  async function loadPlugin(pluginKey) {
2350
2437
  try {
2351
- const userRequire = createRequire2(path7.join(getProjectRoot2(), "package.json"));
2352
- const resolvedPath = userRequire.resolve(pluginKey);
2353
- const pluginModule = await import(resolvedPath);
2354
- const pluginPackage = pluginModule.default ?? pluginModule;
2438
+ const pluginPackage = (await import(pluginKey)).default;
2355
2439
  if (!pluginPackage || typeof pluginPackage.create !== "function") {
2356
2440
  throw new Error(`Plugin ${pluginKey} does not export a valid create function`);
2357
2441
  }
@@ -2561,10 +2645,21 @@ function detectJsonMigration() {
2561
2645
  try {
2562
2646
  const content = fs11.readFileSync(oldFilePath, "utf-8");
2563
2647
  const parsed = JSON.parse(content);
2564
- const capabilities = Array.isArray(parsed) ? parsed : [];
2648
+ if (!Array.isArray(parsed)) {
2649
+ return {
2650
+ needsMigration: false,
2651
+ reason: "capabilities.json is not a valid array"
2652
+ };
2653
+ }
2654
+ if (parsed.length === 0) {
2655
+ return {
2656
+ needsMigration: false,
2657
+ reason: "capabilities.json is an empty array"
2658
+ };
2659
+ }
2565
2660
  return {
2566
2661
  needsMigration: true,
2567
- oldCapabilities: capabilities,
2662
+ oldCapabilities: parsed,
2568
2663
  oldFilePath
2569
2664
  };
2570
2665
  } catch (error) {
@@ -3165,13 +3260,15 @@ function analyzeClass(sourceFile) {
3165
3260
  if (!name) continue;
3166
3261
  const isInjectable = hasDecorator(classDecl, "Injectable");
3167
3262
  const isController = hasDecorator(classDecl, "Controller");
3168
- if (classInfo && classInfo.isInjectable && !isInjectable && !isController) {
3263
+ const isAutomation = hasDecorator(classDecl, "Automation");
3264
+ if (classInfo && classInfo.isInjectable && !isInjectable && !isController && !isAutomation) {
3169
3265
  continue;
3170
3266
  }
3171
3267
  const info = {
3172
3268
  name,
3173
3269
  isInjectable,
3174
3270
  isController,
3271
+ isAutomation,
3175
3272
  constructorParamCount: 0
3176
3273
  };
3177
3274
  const classBody = classDecl.getChildSyntaxListOrThrow();
@@ -3190,7 +3287,7 @@ function analyzeClass(sourceFile) {
3190
3287
  info.constructorParamsEnd = ctor.getStart();
3191
3288
  }
3192
3289
  }
3193
- if (isInjectable || isController || !classInfo) {
3290
+ if (isInjectable || isController || isAutomation || !classInfo) {
3194
3291
  classInfo = info;
3195
3292
  }
3196
3293
  }
@@ -3203,10 +3300,10 @@ function canAutoMigrate(classInfo) {
3203
3300
  reason: "No class found in file"
3204
3301
  };
3205
3302
  }
3206
- if (!classInfo.isInjectable && !classInfo.isController) {
3303
+ if (!classInfo.isInjectable && !classInfo.isController && !classInfo.isAutomation) {
3207
3304
  return {
3208
3305
  canMigrate: false,
3209
- reason: `Class "${classInfo.name}" is not @Injectable or @Controller`
3306
+ reason: `Class "${classInfo.name}" is not @Injectable, @Controller or @Automation`
3210
3307
  };
3211
3308
  }
3212
3309
  return { canMigrate: true };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-cli",
3
- "version": "1.1.14",
3
+ "version": "1.1.16-alpha.0",
4
4
  "description": "CLI tool for fullstack template management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",