@nowline/cli 0.6.0 → 0.7.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.
- package/dist/commands/mcp.d.ts +8 -3
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +39 -9
- package/dist/commands/mcp.js.map +1 -1
- package/dist/convert/parse-json.d.ts +1 -6
- package/dist/convert/parse-json.d.ts.map +1 -1
- package/dist/convert/parse-json.js +2 -33
- package/dist/convert/parse-json.js.map +1 -1
- package/dist/convert/printer.d.ts +1 -5
- package/dist/convert/printer.d.ts.map +1 -1
- package/dist/convert/printer.js +2 -333
- package/dist/convert/printer.js.map +1 -1
- package/dist/convert/schema.d.ts +1 -32
- package/dist/convert/schema.d.ts.map +1 -1
- package/dist/convert/schema.js +2 -76
- package/dist/convert/schema.js.map +1 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +2 -2
- package/package.json +15 -15
- package/src/commands/mcp.ts +46 -9
- package/src/convert/parse-json.ts +2 -57
- package/src/convert/printer.ts +2 -376
- package/src/convert/schema.ts +9 -105
- package/src/generated/version.ts +2 -2
package/src/convert/schema.ts
CHANGED
|
@@ -1,105 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface Position {
|
|
13
|
-
start: { line: number; column: number; offset: number };
|
|
14
|
-
end: { line: number; column: number; offset: number };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface JsonAstNode {
|
|
18
|
-
$type: string;
|
|
19
|
-
$position?: Position;
|
|
20
|
-
[key: string]: unknown;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface SerializeOptions {
|
|
24
|
-
includePositions?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Keys that Langium adds to AST nodes that we don't want in the JSON form.
|
|
28
|
-
const CONTAINER_KEYS = new Set(['$container', '$containerProperty', '$containerIndex']);
|
|
29
|
-
// $cstNode / $document are runtime-only. $type and $position are emitted.
|
|
30
|
-
const RUNTIME_KEYS = new Set(['$cstNode', '$document']);
|
|
31
|
-
|
|
32
|
-
export function serializeToJson(
|
|
33
|
-
document: LangiumDocument<NowlineFile>,
|
|
34
|
-
source: string,
|
|
35
|
-
options: SerializeOptions = {},
|
|
36
|
-
): NowlineDocument {
|
|
37
|
-
const includePositions = options.includePositions ?? true;
|
|
38
|
-
return {
|
|
39
|
-
$nowlineSchema: NOWLINE_SCHEMA_VERSION,
|
|
40
|
-
file: {
|
|
41
|
-
uri: document.uri.toString(),
|
|
42
|
-
source,
|
|
43
|
-
},
|
|
44
|
-
ast: serializeNode(document.parseResult.value, includePositions),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function serializeNode(node: AstNode, includePositions: boolean): JsonAstNode {
|
|
49
|
-
const out: JsonAstNode = { $type: node.$type };
|
|
50
|
-
if (includePositions) {
|
|
51
|
-
const pos = cstPosition(node.$cstNode);
|
|
52
|
-
if (pos) out.$position = pos;
|
|
53
|
-
}
|
|
54
|
-
for (const [key, value] of Object.entries(node)) {
|
|
55
|
-
if (key.startsWith('$')) continue;
|
|
56
|
-
if (CONTAINER_KEYS.has(key) || RUNTIME_KEYS.has(key)) continue;
|
|
57
|
-
out[key] = serializeValue(value, includePositions);
|
|
58
|
-
}
|
|
59
|
-
return out;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function serializeValue(value: unknown, includePositions: boolean): unknown {
|
|
63
|
-
if (value === null || value === undefined) return value;
|
|
64
|
-
if (Array.isArray(value)) {
|
|
65
|
-
return value.map((v) => serializeValue(v, includePositions));
|
|
66
|
-
}
|
|
67
|
-
if (isAstNode(value)) {
|
|
68
|
-
return serializeNode(value, includePositions);
|
|
69
|
-
}
|
|
70
|
-
if (typeof value === 'object') {
|
|
71
|
-
const record = value as Record<string, unknown>;
|
|
72
|
-
const out: Record<string, unknown> = {};
|
|
73
|
-
for (const [k, v] of Object.entries(record)) {
|
|
74
|
-
if (k.startsWith('$')) continue;
|
|
75
|
-
if (CONTAINER_KEYS.has(k) || RUNTIME_KEYS.has(k)) continue;
|
|
76
|
-
out[k] = serializeValue(v, includePositions);
|
|
77
|
-
}
|
|
78
|
-
return out;
|
|
79
|
-
}
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function isAstNode(value: unknown): value is AstNode {
|
|
84
|
-
return (
|
|
85
|
-
value !== null &&
|
|
86
|
-
typeof value === 'object' &&
|
|
87
|
-
typeof (value as { $type?: unknown }).$type === 'string'
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function cstPosition(cst: CstNode | undefined): Position | undefined {
|
|
92
|
-
if (!cst) return undefined;
|
|
93
|
-
return {
|
|
94
|
-
start: {
|
|
95
|
-
line: cst.range.start.line + 1,
|
|
96
|
-
column: cst.range.start.character + 1,
|
|
97
|
-
offset: cst.offset,
|
|
98
|
-
},
|
|
99
|
-
end: {
|
|
100
|
-
line: cst.range.end.line + 1,
|
|
101
|
-
column: cst.range.end.character + 1,
|
|
102
|
-
offset: cst.end,
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
1
|
+
// Re-exported from @nowline/core. Kept here for backwards compatibility.
|
|
2
|
+
export {
|
|
3
|
+
type JsonAstNode,
|
|
4
|
+
NOWLINE_SCHEMA_VERSION,
|
|
5
|
+
type NowlineDocument,
|
|
6
|
+
type Position,
|
|
7
|
+
type SerializeOptions,
|
|
8
|
+
serializeToJson,
|
|
9
|
+
} from '@nowline/core';
|
package/src/generated/version.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Auto-generated by scripts/bundle-templates.mjs. Do not edit by hand.
|
|
2
2
|
|
|
3
|
-
export const CLI_VERSION = "0.
|
|
3
|
+
export const CLI_VERSION = "0.7.0";
|
|
4
4
|
|
|
5
5
|
export interface CliBuild {
|
|
6
6
|
/** Short git SHA at build time, or empty when not in a git checkout. */
|
|
@@ -12,7 +12,7 @@ export interface CliBuild {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export const CLI_BUILD: CliBuild = {
|
|
15
|
-
"sha": "
|
|
15
|
+
"sha": "0f07e00",
|
|
16
16
|
"isRelease": true,
|
|
17
17
|
"isDirty": false
|
|
18
18
|
};
|