@lark-apaas/fullstack-cli 1.1.16-alpha.7 → 1.1.16-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.
Files changed (2) hide show
  1. package/dist/index.js +94 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5446,6 +5446,90 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
5446
5446
 
5447
5447
  // src/commands/read-logs/index.ts
5448
5448
  var LOG_TYPES = ["server", "trace", "server-std", "client-std", "browser"];
5449
+ function normalizeObjectKey(key) {
5450
+ return key.toLowerCase().replace(/_/g, "");
5451
+ }
5452
+ function formatIsoWithLocalOffset(date, includeMilliseconds) {
5453
+ const pad2 = (n) => String(n).padStart(2, "0");
5454
+ const pad3 = (n) => String(n).padStart(3, "0");
5455
+ const year = date.getFullYear();
5456
+ const month = pad2(date.getMonth() + 1);
5457
+ const day = pad2(date.getDate());
5458
+ const hour = pad2(date.getHours());
5459
+ const minute = pad2(date.getMinutes());
5460
+ const second = pad2(date.getSeconds());
5461
+ const ms = pad3(date.getMilliseconds());
5462
+ const tzOffsetMinutes = -date.getTimezoneOffset();
5463
+ const sign = tzOffsetMinutes >= 0 ? "+" : "-";
5464
+ const abs = Math.abs(tzOffsetMinutes);
5465
+ const offsetHH = pad2(Math.floor(abs / 60));
5466
+ const offsetMM = pad2(abs % 60);
5467
+ const msPart = includeMilliseconds ? `.${ms}` : "";
5468
+ return `${year}-${month}-${day}T${hour}:${minute}:${second}${msPart}${sign}${offsetHH}:${offsetMM}`;
5469
+ }
5470
+ function formatLocalDateTimeStringWithOffset(input) {
5471
+ const match = input.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
5472
+ if (!match) return input;
5473
+ const year = Number(match[1]);
5474
+ const month = Number(match[2]);
5475
+ const day = Number(match[3]);
5476
+ const hour = Number(match[4]);
5477
+ const minute = Number(match[5]);
5478
+ const second = Number(match[6]);
5479
+ const date = new Date(year, month - 1, day, hour, minute, second, 0);
5480
+ if (Number.isNaN(date.getTime())) return input;
5481
+ return formatIsoWithLocalOffset(date, false);
5482
+ }
5483
+ function formatIsoNoTzStringWithOffset(input) {
5484
+ const match = input.match(
5485
+ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,3}))?$/
5486
+ );
5487
+ if (!match) return input;
5488
+ const year = Number(match[1]);
5489
+ const month = Number(match[2]);
5490
+ const day = Number(match[3]);
5491
+ const hour = Number(match[4]);
5492
+ const minute = Number(match[5]);
5493
+ const second = Number(match[6]);
5494
+ const msRaw = match[7];
5495
+ const ms = typeof msRaw === "string" ? Number(msRaw.padEnd(3, "0")) : 0;
5496
+ const date = new Date(year, month - 1, day, hour, minute, second, ms);
5497
+ if (Number.isNaN(date.getTime())) return input;
5498
+ return formatIsoWithLocalOffset(date, typeof msRaw === "string");
5499
+ }
5500
+ function normalizeTimeString(input) {
5501
+ const localDateTime = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
5502
+ if (localDateTime.test(input)) {
5503
+ return formatLocalDateTimeStringWithOffset(input);
5504
+ }
5505
+ const isoWithTz = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})$/i;
5506
+ if (isoWithTz.test(input)) {
5507
+ const date = new Date(input);
5508
+ if (Number.isNaN(date.getTime())) return input;
5509
+ const includeMs = /\.\d{1,3}/.test(input);
5510
+ return formatIsoWithLocalOffset(date, includeMs);
5511
+ }
5512
+ const isoNoTz = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?$/;
5513
+ if (isoNoTz.test(input)) {
5514
+ return formatIsoNoTzStringWithOffset(input);
5515
+ }
5516
+ return input;
5517
+ }
5518
+ function normalizeTimezonesInValue(value, keyNormalized) {
5519
+ if (typeof value === "string" && (keyNormalized === "time" || keyNormalized === "servertime")) {
5520
+ return normalizeTimeString(value);
5521
+ }
5522
+ if (!value || typeof value !== "object") return value;
5523
+ if (Array.isArray(value)) {
5524
+ return value.map((item) => normalizeTimezonesInValue(item));
5525
+ }
5526
+ const obj = value;
5527
+ const result = {};
5528
+ for (const [key, child] of Object.entries(obj)) {
5529
+ result[key] = normalizeTimezonesInValue(child, normalizeObjectKey(key));
5530
+ }
5531
+ return result;
5532
+ }
5449
5533
  function sanitizeStructuredLog(value) {
5450
5534
  if (!value || typeof value !== "object") return value;
5451
5535
  if (Array.isArray(value)) return value;
@@ -5550,16 +5634,17 @@ async function readLogsJsonResult(options) {
5550
5634
  const logs = [];
5551
5635
  let hasError = false;
5552
5636
  for (const line of lines) {
5553
- if (!hasError && hasErrorInStdLines([line])) {
5554
- hasError = true;
5555
- }
5556
5637
  try {
5557
5638
  const parsed = JSON.parse(line);
5558
- logs.push(sanitizeStructuredLog(parsed));
5639
+ const normalized = normalizeTimezonesInValue(parsed);
5640
+ logs.push(sanitizeStructuredLog(normalized));
5559
5641
  if (!hasError && hasErrorInLogObject(parsed)) {
5560
5642
  hasError = true;
5561
5643
  }
5562
5644
  } catch {
5645
+ if (!hasError && hasErrorInStdLines([line])) {
5646
+ hasError = true;
5647
+ }
5563
5648
  continue;
5564
5649
  }
5565
5650
  }
@@ -5589,15 +5674,8 @@ function resolveLogFilePath(logDir, type) {
5589
5674
  throw new Error(`Unsupported log type: ${type}`);
5590
5675
  }
5591
5676
  async function run4(options) {
5592
- try {
5593
- const result = await readLogsJsonResult(options);
5594
- process.stdout.write(JSON.stringify(result) + "\n");
5595
- } catch (error) {
5596
- const message = error instanceof Error ? error.message : String(error);
5597
- const result = { hasError: true, totalLinesCount: 0, logs: [message] };
5598
- process.stdout.write(JSON.stringify(result) + "\n");
5599
- process.exitCode = 1;
5600
- }
5677
+ const result = await readLogsJsonResult(options);
5678
+ process.stdout.write(JSON.stringify(result) + "\n");
5601
5679
  }
5602
5680
  function parseLogType(input) {
5603
5681
  const value = typeof input === "string" ? input.trim() : "";
@@ -5629,9 +5707,9 @@ var readLogsCommand = {
5629
5707
  name: "read-logs",
5630
5708
  description: "Read latest logs from log files",
5631
5709
  register(program) {
5632
- program.command(this.name).description(this.description).option("--dir <path>", "Logs directory", "logs").option("--type <type>", `Log type: ${LOG_TYPES.join("|")}`, "server-std").option("--max-lines <lines>", "Max lines to return", "30").option("--offset <lines>", "Skip latest N lines for pagination", "0").option("--trace-id <id>", "Filter structured logs by trace id").option("--level <levels>", "Filter structured logs by level (comma-separated)").action(async (rawOptions) => {
5710
+ program.command(this.name).description(this.description).option("--dir <path>", "Logs directory", "/tmp").option("--type <type>", `Log type: ${LOG_TYPES.join("|")}`, "server-std").option("--max-lines <lines>", "Max lines to return", "30").option("--offset <lines>", "Skip latest N lines for pagination", "0").option("--trace-id <id>", "Filter structured logs by trace id").option("--level <levels>", "Filter structured logs by level (comma-separated)").action(async (rawOptions) => {
5633
5711
  try {
5634
- const logDir = typeof rawOptions.dir === "string" ? rawOptions.dir : "logs";
5712
+ const logDir = typeof rawOptions.dir === "string" ? rawOptions.dir : "/tmp";
5635
5713
  const type = parseLogType(rawOptions.type);
5636
5714
  const maxLines = parsePositiveInt(rawOptions.maxLines, "--max-lines");
5637
5715
  const offset = parseNonNegativeInt(rawOptions.offset, "--offset");
@@ -5640,8 +5718,7 @@ var readLogsCommand = {
5640
5718
  await run4({ logDir, type, maxLines, offset, traceId, levels });
5641
5719
  } catch (error) {
5642
5720
  const message = error instanceof Error ? error.message : String(error);
5643
- const result = { hasError: true, totalLinesCount: 0, logs: [message] };
5644
- process.stdout.write(JSON.stringify(result) + "\n");
5721
+ process.stderr.write(message + "\n");
5645
5722
  process.exitCode = 1;
5646
5723
  }
5647
5724
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-cli",
3
- "version": "1.1.16-alpha.7",
3
+ "version": "1.1.16-beta.0",
4
4
  "description": "CLI tool for fullstack template management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",