@precisa-saude/fhir 0.4.0 → 0.5.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.
@@ -0,0 +1,58 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/cli-utils.ts
2
+ async function readStdin() {
3
+ if (process.stdin.isTTY) return "";
4
+ const chunks = [];
5
+ for await (const chunk of process.stdin) {
6
+ chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
7
+ }
8
+ return Buffer.concat(chunks).toString("utf-8");
9
+ }
10
+ async function getInput(fileArg) {
11
+ if (fileArg) {
12
+ const { readFile } = await Promise.resolve().then(() => _interopRequireWildcard(require("fs/promises")));
13
+ return readFile(fileArg, "utf-8");
14
+ }
15
+ const stdin = await readStdin();
16
+ if (!stdin.trim()) {
17
+ exitWithError("Forne\xE7a um arquivo ou envie dados via stdin.");
18
+ }
19
+ return stdin;
20
+ }
21
+ function parseJson(raw, errorMessage) {
22
+ try {
23
+ return JSON.parse(raw);
24
+ } catch (e) {
25
+ exitWithError(errorMessage);
26
+ }
27
+ }
28
+ function formatTable(headers, rows) {
29
+ const widths = headers.map(
30
+ (h, i) => rows.reduce((max, r) => Math.max(max, (_nullishCoalesce(r[i], () => ( ""))).length), h.length)
31
+ );
32
+ const fmt = (row) => row.map((c, i) => (_nullishCoalesce(c, () => ( ""))).padEnd(widths[i])).join(" ");
33
+ const sep = widths.map((w) => "-".repeat(w)).join(" ");
34
+ return [fmt(headers), sep, ...rows.map(fmt)].join("\n");
35
+ }
36
+ function outputJson(data) {
37
+ process.stdout.write(`${JSON.stringify(data, null, 2)}
38
+ `);
39
+ }
40
+ function outputText(text) {
41
+ process.stdout.write(`${text}
42
+ `);
43
+ }
44
+ function exitWithError(message, code = 1) {
45
+ process.stderr.write(`Erro: ${message}
46
+ `);
47
+ process.exit(code);
48
+ }
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+ exports.exitWithError = exitWithError; exports.formatTable = formatTable; exports.getInput = getInput; exports.outputJson = outputJson; exports.outputText = outputText; exports.parseJson = parseJson; exports.readStdin = readStdin;
58
+ //# sourceMappingURL=cli-utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/cli-utils.cjs","../src/cli-utils.ts"],"names":[],"mappings":"AAAA;ACOA,MAAA,SAAsB,SAAA,CAAA,EAA6B;AACjD,EAAA,GAAA,CAAI,OAAA,CAAQ,KAAA,CAAM,KAAA,EAAO,OAAO,EAAA;AAChC,EAAA,MAAM,OAAA,EAAmB,CAAC,CAAA;AAC1B,EAAA,IAAA,MAAA,CAAA,MAAiB,MAAA,GAAS,OAAA,CAAQ,KAAA,EAAO;AACvC,IAAA,MAAA,CAAO,IAAA,CAAK,OAAO,MAAA,IAAU,SAAA,EAAW,MAAA,CAAO,IAAA,CAAK,KAAK,EAAA,EAAI,KAAK,CAAA;AAAA,EACpE;AACA,EAAA,OAAO,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA,CAAE,QAAA,CAAS,OAAO,CAAA;AAC/C;AAEA,MAAA,SAAsB,QAAA,CAAS,OAAA,EAAmC;AAChE,EAAA,GAAA,CAAI,OAAA,EAAS;AACX,IAAA,MAAM,EAAE,SAAS,EAAA,EAAI,MAAM,4DAAA,CAAO,aAAkB,GAAA;AACpD,IAAA,OAAO,QAAA,CAAS,OAAA,EAAS,OAAO,CAAA;AAAA,EAClC;AACA,EAAA,MAAM,MAAA,EAAQ,MAAM,SAAA,CAAU,CAAA;AAC9B,EAAA,GAAA,CAAI,CAAC,KAAA,CAAM,IAAA,CAAK,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CAAQ,MAAA,CAAO,KAAA,CAAM,CAAA,EAAA;AAAoC;AAC3D;AAE2B;AACJ,EAAA;AAAW;AAClC;AAE8B;AACP,EAAA;AAAoB;AACxB,EAAA;AACnB;ADRwB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/cli-utils.cjs","sourcesContent":[null,"/**\n * CLI Utilities — shared helpers for fhir-brasil CLI tools\n *\n * Uses only Node.js built-in modules (zero dependencies).\n * Exported as `@precisa-saude/fhir/cli-utils` sub-path.\n */\n\nexport async function readStdin(): Promise<string> {\n if (process.stdin.isTTY) return '';\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) {\n chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);\n }\n return Buffer.concat(chunks).toString('utf-8');\n}\n\nexport async function getInput(fileArg?: string): Promise<string> {\n if (fileArg) {\n const { readFile } = await import('node:fs/promises');\n return readFile(fileArg, 'utf-8');\n }\n const stdin = await readStdin();\n if (!stdin.trim()) {\n exitWithError('Forneça um arquivo ou envie dados via stdin.');\n }\n return stdin;\n}\n\nexport function parseJson<T>(raw: string, errorMessage: string): T {\n try {\n return JSON.parse(raw) as T;\n } catch {\n exitWithError(errorMessage);\n }\n}\n\nexport function formatTable(headers: string[], rows: string[][]): string {\n const widths = headers.map((h, i) =>\n rows.reduce((max, r) => Math.max(max, (r[i] ?? '').length), h.length),\n );\n const fmt = (row: string[]) => row.map((c, i) => (c ?? '').padEnd(widths[i]!)).join(' ');\n const sep = widths.map((w) => '-'.repeat(w)).join(' ');\n return [fmt(headers), sep, ...rows.map(fmt)].join('\\n');\n}\n\nexport function outputJson(data: unknown): void {\n process.stdout.write(`${JSON.stringify(data, null, 2)}\\n`);\n}\n\nexport function outputText(text: string): void {\n process.stdout.write(`${text}\\n`);\n}\n\nexport function exitWithError(message: string, code = 1): never {\n process.stderr.write(`Erro: ${message}\\n`);\n process.exit(code);\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * CLI Utilities — shared helpers for fhir-brasil CLI tools
3
+ *
4
+ * Uses only Node.js built-in modules (zero dependencies).
5
+ * Exported as `@precisa-saude/fhir/cli-utils` sub-path.
6
+ */
7
+ declare function readStdin(): Promise<string>;
8
+ declare function getInput(fileArg?: string): Promise<string>;
9
+ declare function parseJson<T>(raw: string, errorMessage: string): T;
10
+ declare function formatTable(headers: string[], rows: string[][]): string;
11
+ declare function outputJson(data: unknown): void;
12
+ declare function outputText(text: string): void;
13
+ declare function exitWithError(message: string, code?: number): never;
14
+
15
+ export { exitWithError, formatTable, getInput, outputJson, outputText, parseJson, readStdin };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * CLI Utilities — shared helpers for fhir-brasil CLI tools
3
+ *
4
+ * Uses only Node.js built-in modules (zero dependencies).
5
+ * Exported as `@precisa-saude/fhir/cli-utils` sub-path.
6
+ */
7
+ declare function readStdin(): Promise<string>;
8
+ declare function getInput(fileArg?: string): Promise<string>;
9
+ declare function parseJson<T>(raw: string, errorMessage: string): T;
10
+ declare function formatTable(headers: string[], rows: string[][]): string;
11
+ declare function outputJson(data: unknown): void;
12
+ declare function outputText(text: string): void;
13
+ declare function exitWithError(message: string, code?: number): never;
14
+
15
+ export { exitWithError, formatTable, getInput, outputJson, outputText, parseJson, readStdin };
@@ -0,0 +1,58 @@
1
+ // src/cli-utils.ts
2
+ async function readStdin() {
3
+ if (process.stdin.isTTY) return "";
4
+ const chunks = [];
5
+ for await (const chunk of process.stdin) {
6
+ chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
7
+ }
8
+ return Buffer.concat(chunks).toString("utf-8");
9
+ }
10
+ async function getInput(fileArg) {
11
+ if (fileArg) {
12
+ const { readFile } = await import("fs/promises");
13
+ return readFile(fileArg, "utf-8");
14
+ }
15
+ const stdin = await readStdin();
16
+ if (!stdin.trim()) {
17
+ exitWithError("Forne\xE7a um arquivo ou envie dados via stdin.");
18
+ }
19
+ return stdin;
20
+ }
21
+ function parseJson(raw, errorMessage) {
22
+ try {
23
+ return JSON.parse(raw);
24
+ } catch {
25
+ exitWithError(errorMessage);
26
+ }
27
+ }
28
+ function formatTable(headers, rows) {
29
+ const widths = headers.map(
30
+ (h, i) => rows.reduce((max, r) => Math.max(max, (r[i] ?? "").length), h.length)
31
+ );
32
+ const fmt = (row) => row.map((c, i) => (c ?? "").padEnd(widths[i])).join(" ");
33
+ const sep = widths.map((w) => "-".repeat(w)).join(" ");
34
+ return [fmt(headers), sep, ...rows.map(fmt)].join("\n");
35
+ }
36
+ function outputJson(data) {
37
+ process.stdout.write(`${JSON.stringify(data, null, 2)}
38
+ `);
39
+ }
40
+ function outputText(text) {
41
+ process.stdout.write(`${text}
42
+ `);
43
+ }
44
+ function exitWithError(message, code = 1) {
45
+ process.stderr.write(`Erro: ${message}
46
+ `);
47
+ process.exit(code);
48
+ }
49
+ export {
50
+ exitWithError,
51
+ formatTable,
52
+ getInput,
53
+ outputJson,
54
+ outputText,
55
+ parseJson,
56
+ readStdin
57
+ };
58
+ //# sourceMappingURL=cli-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli-utils.ts"],"sourcesContent":["/**\n * CLI Utilities — shared helpers for fhir-brasil CLI tools\n *\n * Uses only Node.js built-in modules (zero dependencies).\n * Exported as `@precisa-saude/fhir/cli-utils` sub-path.\n */\n\nexport async function readStdin(): Promise<string> {\n if (process.stdin.isTTY) return '';\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) {\n chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);\n }\n return Buffer.concat(chunks).toString('utf-8');\n}\n\nexport async function getInput(fileArg?: string): Promise<string> {\n if (fileArg) {\n const { readFile } = await import('node:fs/promises');\n return readFile(fileArg, 'utf-8');\n }\n const stdin = await readStdin();\n if (!stdin.trim()) {\n exitWithError('Forneça um arquivo ou envie dados via stdin.');\n }\n return stdin;\n}\n\nexport function parseJson<T>(raw: string, errorMessage: string): T {\n try {\n return JSON.parse(raw) as T;\n } catch {\n exitWithError(errorMessage);\n }\n}\n\nexport function formatTable(headers: string[], rows: string[][]): string {\n const widths = headers.map((h, i) =>\n rows.reduce((max, r) => Math.max(max, (r[i] ?? '').length), h.length),\n );\n const fmt = (row: string[]) => row.map((c, i) => (c ?? '').padEnd(widths[i]!)).join(' ');\n const sep = widths.map((w) => '-'.repeat(w)).join(' ');\n return [fmt(headers), sep, ...rows.map(fmt)].join('\\n');\n}\n\nexport function outputJson(data: unknown): void {\n process.stdout.write(`${JSON.stringify(data, null, 2)}\\n`);\n}\n\nexport function outputText(text: string): void {\n process.stdout.write(`${text}\\n`);\n}\n\nexport function exitWithError(message: string, code = 1): never {\n process.stderr.write(`Erro: ${message}\\n`);\n process.exit(code);\n}\n"],"mappings":";AAOA,eAAsB,YAA6B;AACjD,MAAI,QAAQ,MAAM,MAAO,QAAO;AAChC,QAAM,SAAmB,CAAC;AAC1B,mBAAiB,SAAS,QAAQ,OAAO;AACvC,WAAO,KAAK,OAAO,UAAU,WAAW,OAAO,KAAK,KAAK,IAAI,KAAK;AAAA,EACpE;AACA,SAAO,OAAO,OAAO,MAAM,EAAE,SAAS,OAAO;AAC/C;AAEA,eAAsB,SAAS,SAAmC;AAChE,MAAI,SAAS;AACX,UAAM,EAAE,SAAS,IAAI,MAAM,OAAO,aAAkB;AACpD,WAAO,SAAS,SAAS,OAAO;AAAA,EAClC;AACA,QAAM,QAAQ,MAAM,UAAU;AAC9B,MAAI,CAAC,MAAM,KAAK,GAAG;AACjB,kBAAc,iDAA8C;AAAA,EAC9D;AACA,SAAO;AACT;AAEO,SAAS,UAAa,KAAa,cAAyB;AACjE,MAAI;AACF,WAAO,KAAK,MAAM,GAAG;AAAA,EACvB,QAAQ;AACN,kBAAc,YAAY;AAAA,EAC5B;AACF;AAEO,SAAS,YAAY,SAAmB,MAA0B;AACvE,QAAM,SAAS,QAAQ;AAAA,IAAI,CAAC,GAAG,MAC7B,KAAK,OAAO,CAAC,KAAK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