@yudao-cli/shared 1.2.1

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,34 @@
1
+ /** `--json` 模式的统一输出包裹结构(DESIGN.md §5.2) */
2
+ export interface Envelope<T = unknown> {
3
+ ok: boolean;
4
+ command: string;
5
+ data: T | null;
6
+ warnings: Warning[];
7
+ error: StructuredError | null;
8
+ meta: Meta;
9
+ /** 仅 NDJSON 批量模式:回显该行输入 */
10
+ input?: unknown;
11
+ }
12
+ export interface Warning {
13
+ code: string;
14
+ message: string;
15
+ }
16
+ export interface StructuredError {
17
+ code: string;
18
+ severity: 'fatal' | 'degraded' | 'notice';
19
+ message: string;
20
+ hint: string;
21
+ retryable: boolean;
22
+ }
23
+ export interface Meta {
24
+ version: string;
25
+ profile: string;
26
+ baseUrl?: string;
27
+ elapsedMs: number;
28
+ }
29
+ export declare function successEnvelope<T>(command: string, data: T, meta: Omit<Meta, 'elapsedMs'> & {
30
+ elapsedMs?: number;
31
+ }, warnings?: Warning[]): Envelope<T>;
32
+ export declare function failureEnvelope(command: string, error: StructuredError, meta: Omit<Meta, 'elapsedMs'> & {
33
+ elapsedMs?: number;
34
+ }, warnings?: Warning[]): Envelope<null>;
@@ -0,0 +1,7 @@
1
+ export function successEnvelope(command, data, meta, warnings = []) {
2
+ return { ok: true, command, data, warnings, error: null, meta: { elapsedMs: 0, ...meta } };
3
+ }
4
+ export function failureEnvelope(command, error, meta, warnings = []) {
5
+ return { ok: false, command, data: null, warnings, error, meta: { elapsedMs: 0, ...meta } };
6
+ }
7
+ //# sourceMappingURL=envelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAgCA,MAAM,UAAU,eAAe,CAC7B,OAAe,EACf,IAAO,EACP,IAAsD,EACtD,WAAsB,EAAE;IAExB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,CAAA;AAC5F,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,OAAe,EACf,KAAsB,EACtB,IAAsD,EACtD,WAAsB,EAAE;IAExB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,CAAA;AAC7F,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './envelope.js';
2
+ export * from './ndjson.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './envelope.js';
2
+ export * from './ndjson.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,9 @@
1
+ /** 逐行解析 NDJSON;返回解析结果或带行号的错误(DESIGN.md §5.4 / §6.4 TRANSFORM_INVALID_INPUT) */
2
+ export declare function parseNdjson(text: string): {
3
+ ok: true;
4
+ records: unknown[];
5
+ } | {
6
+ ok: false;
7
+ line: number;
8
+ snippet: string;
9
+ };
package/dist/ndjson.js ADDED
@@ -0,0 +1,18 @@
1
+ /** 逐行解析 NDJSON;返回解析结果或带行号的错误(DESIGN.md §5.4 / §6.4 TRANSFORM_INVALID_INPUT) */
2
+ export function parseNdjson(text) {
3
+ const records = [];
4
+ const lines = text.split('\n');
5
+ for (let i = 0; i < lines.length; i++) {
6
+ const raw = lines[i].trim();
7
+ if (raw === '')
8
+ continue;
9
+ try {
10
+ records.push(JSON.parse(raw));
11
+ }
12
+ catch {
13
+ return { ok: false, line: i + 1, snippet: raw.slice(0, 80) };
14
+ }
15
+ }
16
+ return { ok: true, records };
17
+ }
18
+ //# sourceMappingURL=ndjson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ndjson.js","sourceRoot":"","sources":["../src/ndjson.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,OAAO,GAAc,EAAE,CAAA;IAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QAC3B,IAAI,GAAG,KAAK,EAAE;YAAE,SAAQ;QACxB,IAAI,CAAC;YACH,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAA;QAC9D,CAAC;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAC9B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@yudao-cli/shared",
3
+ "version": "1.2.1",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/DaYePython/yudao-system-cli.git"
11
+ },
12
+ "homepage": "https://github.com/DaYePython/yudao-system-cli#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/DaYePython/yudao-system-cli/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public",
18
+ "registry": "https://registry.npmjs.org"
19
+ },
20
+ "main": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ }
27
+ },
28
+ "devDependencies": {
29
+ "typescript": "^5.6.0"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc -p tsconfig.json",
33
+ "test": "echo 'shared: no tests' && exit 0"
34
+ }
35
+ }