• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dialoguedb / client-nodejs / 26549428352

28 May 2026 01:41AM UTC coverage: 83.537%. First build
26549428352

Pull #80

github

web-flow
Merge 997333343 into c9508f8b7
Pull Request #80: Draft PR for release version v2.0.0

938 of 1116 branches covered (84.05%)

Branch coverage included in aggregate %.

0 of 216 new or added lines in 6 files covered. (0.0%)

1112 of 1338 relevant lines covered (83.11%)

38.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/cli/shared.ts
NEW
1
import { DialogueDBError } from "../errors";
×
NEW
2
import { getDialogue } from "../methods/getDialogue";
×
3

NEW
4
export function parseJSON(label: string, raw: string): unknown {
×
NEW
5
  try {
×
NEW
6
    return JSON.parse(raw);
×
7
  } catch (e) {
NEW
8
    const message = e instanceof Error ? e.message : String(e);
×
NEW
9
    throw new Error(`--${label} is not valid JSON: ${message}`);
×
10
  }
11
}
12

NEW
13
export function parseCSV(raw: string): string[] {
×
NEW
14
  return raw
×
15
    .split(",")
NEW
16
    .map((s) => s.trim())
×
NEW
17
    .filter((s) => s.length > 0);
×
18
}
19

NEW
20
export function parseIntStrict(label: string, raw: string): number {
×
NEW
21
  const n = Number(raw);
×
NEW
22
  if (!Number.isInteger(n)) {
×
NEW
23
    throw new Error(`--${label} must be an integer, got "${raw}"`);
×
24
  }
NEW
25
  return n;
×
26
}
27

NEW
28
export async function readStdin(): Promise<string> {
×
NEW
29
  if (process.stdin.isTTY) {
×
NEW
30
    throw new Error(
×
31
      "--stdin was passed but stdin is a terminal (no piped input detected)"
32
    );
33
  }
NEW
34
  const chunks: Buffer[] = [];
×
NEW
35
  for await (const chunk of process.stdin) {
×
NEW
36
    chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
×
37
  }
NEW
38
  return Buffer.concat(chunks).toString("utf8");
×
39
}
40

NEW
41
export async function loadDialogueOrExit(id: string, namespace?: string) {
×
NEW
42
  const d = await getDialogue({
×
43
    id,
44
    ...(namespace && { namespace }),
×
45
  });
NEW
46
  if (!d) {
×
NEW
47
    process.stderr.write(`Dialogue ${id} not found\n`);
×
NEW
48
    process.exit(1);
×
49
  }
NEW
50
  return d;
×
51
}
52

NEW
53
export async function resolveContent(opts: {
×
54
  content?: string;
55
  stdin?: boolean;
56
}): Promise<string> {
NEW
57
  if (opts.stdin) return (await readStdin()).trimEnd();
×
NEW
58
  if (opts.content !== undefined) return opts.content;
×
NEW
59
  throw new Error("Provide --content <text> or --stdin");
×
60
}
61

NEW
62
export function output(value: unknown): void {
×
NEW
63
  process.stdout.write(JSON.stringify(value, null, 2) + "\n");
×
64
}
65

NEW
66
export function withErrorHandler<A extends unknown[]>(
×
67
  fn: (...args: A) => Promise<void>
68
) {
NEW
69
  return async (...args: A): Promise<void> => {
×
NEW
70
    try {
×
NEW
71
      await fn(...args);
×
72
    } catch (e) {
NEW
73
      if (e instanceof DialogueDBError) {
×
NEW
74
        process.stderr.write(
×
75
          JSON.stringify(
76
            {
77
              error: e.message,
78
              code: e.code,
79
              type: e.type,
80
              statusCode: e.statusCode,
81
              requestId: e.requestId,
82
              details: e.details,
83
            },
84
            null,
85
            2
86
          ) + "\n"
87
        );
88
      } else {
NEW
89
        process.stderr.write(`${e instanceof Error ? e.message : String(e)}\n`);
×
90
      }
NEW
91
      process.exit(1);
×
92
    }
93
  };
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc