@nowline/cli 0.6.0 → 0.8.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/dist/commands/mcp.d.ts
CHANGED
|
@@ -2,9 +2,14 @@ import type { ParsedArgs } from '../cli/args.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* `nowline --mcp` handler.
|
|
4
4
|
*
|
|
5
|
-
* Starts a Model Context Protocol
|
|
6
|
-
* server factory as `npx @nowline/mcp`.
|
|
7
|
-
*
|
|
5
|
+
* Starts a Model Context Protocol server sharing the same @nowline/mcp
|
|
6
|
+
* server factory as `npx @nowline/mcp`.
|
|
7
|
+
*
|
|
8
|
+
* Transport selection:
|
|
9
|
+
* stdio (default) — when --port is absent.
|
|
10
|
+
* Streamable HTTP — when --port <N> is supplied; listens on localhost:<N>.
|
|
11
|
+
*
|
|
12
|
+
* Runs until the process receives SIGINT/SIGTERM or the client closes stdin.
|
|
8
13
|
*/
|
|
9
14
|
export declare function mcpHandler({ args }: {
|
|
10
15
|
args: ParsedArgs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;;;;;;;;;;GAWG;AACH,wBAAsB,UAAU,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuC9E"}
|
package/dist/commands/mcp.js
CHANGED
|
@@ -1,20 +1,50 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
1
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
2
4
|
import { createMcpServer } from '@nowline/mcp/server';
|
|
3
5
|
/**
|
|
4
6
|
* `nowline --mcp` handler.
|
|
5
7
|
*
|
|
6
|
-
* Starts a Model Context Protocol
|
|
7
|
-
* server factory as `npx @nowline/mcp`.
|
|
8
|
-
*
|
|
8
|
+
* Starts a Model Context Protocol server sharing the same @nowline/mcp
|
|
9
|
+
* server factory as `npx @nowline/mcp`.
|
|
10
|
+
*
|
|
11
|
+
* Transport selection:
|
|
12
|
+
* stdio (default) — when --port is absent.
|
|
13
|
+
* Streamable HTTP — when --port <N> is supplied; listens on localhost:<N>.
|
|
14
|
+
*
|
|
15
|
+
* Runs until the process receives SIGINT/SIGTERM or the client closes stdin.
|
|
9
16
|
*/
|
|
10
17
|
export async function mcpHandler({ args }) {
|
|
11
18
|
const root = args.root ?? process.cwd();
|
|
12
19
|
const server = createMcpServer({ allowedRoot: root });
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
const portStr = args.port;
|
|
21
|
+
if (portStr !== undefined) {
|
|
22
|
+
const port = parseInt(portStr, 10);
|
|
23
|
+
if (!Number.isFinite(port) || port < 1 || port > 65535) {
|
|
24
|
+
throw new Error(`nowline: --port must be a number between 1 and 65535 (got ${portStr}).`);
|
|
25
|
+
}
|
|
26
|
+
const transport = new StreamableHTTPServerTransport({
|
|
27
|
+
sessionIdGenerator: undefined,
|
|
28
|
+
});
|
|
29
|
+
await server.connect(transport);
|
|
30
|
+
const httpServer = createServer(async (req, res) => {
|
|
31
|
+
await transport.handleRequest(req, res);
|
|
32
|
+
});
|
|
33
|
+
await new Promise((resolve) => {
|
|
34
|
+
httpServer.listen(port, '127.0.0.1', () => {
|
|
35
|
+
process.stderr.write(`nowline: MCP Streamable HTTP listening on http://127.0.0.1:${port}\n`);
|
|
36
|
+
});
|
|
37
|
+
httpServer.on('close', resolve);
|
|
38
|
+
process.on('SIGINT', () => httpServer.close());
|
|
39
|
+
process.on('SIGTERM', () => httpServer.close());
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const transport = new StdioServerTransport();
|
|
44
|
+
await server.connect(transport);
|
|
45
|
+
await new Promise((resolve) => {
|
|
46
|
+
transport.onclose = resolve;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
19
49
|
}
|
|
20
50
|
//# sourceMappingURL=mcp.js.map
|
package/dist/commands/mcp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,Y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AM,CAAC,KAAK,CAChB,8DAA8D,IAAI,IAAI,CACzE,CAAC;YACN,CAAC,CAAC,CAAC;YACH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAChC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;YAC/C,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACP,CAAC;SAAM,CAAC;QACJ,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAChC,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAChC,SAAS,CAAC,OAAO,GAAG,OAAO,CAAC;QAChC,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC"}
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export interface ParseJsonResult {
|
|
3
|
-
document: NowlineDocument;
|
|
4
|
-
ast: JsonAstNode;
|
|
5
|
-
}
|
|
6
|
-
export declare function parseNowlineJson(text: string, filePath: string): ParseJsonResult;
|
|
1
|
+
export { type ParseJsonResult, parseNowlineJson } from '@nowline/core';
|
|
7
2
|
//# sourceMappingURL=parse-json.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-json.d.ts","sourceRoot":"","sources":["../../src/convert/parse-json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"parse-json.d.ts","sourceRoot":"","sources":["../../src/convert/parse-json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export function parseNowlineJson(text, filePath) {
|
|
4
|
-
let parsed;
|
|
5
|
-
try {
|
|
6
|
-
parsed = JSON.parse(text);
|
|
7
|
-
}
|
|
8
|
-
catch (err) {
|
|
9
|
-
throw new CliError(ExitCode.ValidationError, `${filePath}: invalid JSON — ${err instanceof Error ? err.message : String(err)}`);
|
|
10
|
-
}
|
|
11
|
-
const doc = parsed;
|
|
12
|
-
if (!isRecord(doc)) {
|
|
13
|
-
throw new CliError(ExitCode.ValidationError, `${filePath}: JSON root must be an object with $nowlineSchema and ast.`);
|
|
14
|
-
}
|
|
15
|
-
const schema = doc.$nowlineSchema;
|
|
16
|
-
if (typeof schema !== 'string') {
|
|
17
|
-
throw new CliError(ExitCode.ValidationError, `${filePath}: missing "$nowlineSchema" at document root.`);
|
|
18
|
-
}
|
|
19
|
-
if (schema !== NOWLINE_SCHEMA_VERSION) {
|
|
20
|
-
throw new CliError(ExitCode.ValidationError, `${filePath}: unsupported $nowlineSchema "${schema}" (this CLI supports "${NOWLINE_SCHEMA_VERSION}").`);
|
|
21
|
-
}
|
|
22
|
-
const ast = doc.ast;
|
|
23
|
-
if (!isRecord(ast) || typeof ast.$type !== 'string') {
|
|
24
|
-
throw new CliError(ExitCode.ValidationError, `${filePath}: document.ast must be an object with a "$type" field.`);
|
|
25
|
-
}
|
|
26
|
-
if (ast.$type !== 'NowlineFile') {
|
|
27
|
-
throw new CliError(ExitCode.ValidationError, `${filePath}: document.ast.$type must be "NowlineFile" (got "${String(ast.$type)}").`);
|
|
28
|
-
}
|
|
29
|
-
return { document: doc, ast: ast };
|
|
30
|
-
}
|
|
31
|
-
function isRecord(value) {
|
|
32
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
33
|
-
}
|
|
1
|
+
// Re-exported from @nowline/core. Kept here for backwards compatibility.
|
|
2
|
+
export { parseNowlineJson } from '@nowline/core';
|
|
34
3
|
//# sourceMappingURL=parse-json.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-json.js","sourceRoot":"","sources":["../../src/convert/parse-json.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"parse-json.js","sourceRoot":"","sources":["../../src/convert/parse-json.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,OAAO,EAAwB,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export interface PrintOptions {
|
|
3
|
-
indent?: string;
|
|
4
|
-
}
|
|
5
|
-
export declare function printNowlineFile(ast: JsonAstNode, options?: PrintOptions): string;
|
|
1
|
+
export { type PrintOptions, printNowlineFile } from '@nowline/core';
|
|
6
2
|
//# sourceMappingURL=printer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../../src/convert/printer.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../../src/convert/printer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/convert/printer.js
CHANGED
|
@@ -1,334 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const KEY_ORDER = [
|
|
4
|
-
'date',
|
|
5
|
-
'effort',
|
|
6
|
-
'on',
|
|
7
|
-
'size',
|
|
8
|
-
'duration',
|
|
9
|
-
'status',
|
|
10
|
-
'owner',
|
|
11
|
-
'after',
|
|
12
|
-
'before',
|
|
13
|
-
'remaining',
|
|
14
|
-
'labels',
|
|
15
|
-
'style',
|
|
16
|
-
'link',
|
|
17
|
-
'author',
|
|
18
|
-
'start',
|
|
19
|
-
'scale',
|
|
20
|
-
'calendar',
|
|
21
|
-
'header-position',
|
|
22
|
-
'timeline-position',
|
|
23
|
-
'minor-grid',
|
|
24
|
-
];
|
|
25
|
-
const INDENT = ' ';
|
|
26
|
-
export function printNowlineFile(ast, options = {}) {
|
|
27
|
-
const printer = new Printer(options.indent ?? INDENT);
|
|
28
|
-
printer.file(ast);
|
|
29
|
-
return printer.toString();
|
|
30
|
-
}
|
|
31
|
-
class Printer {
|
|
32
|
-
indent;
|
|
33
|
-
lines = [];
|
|
34
|
-
constructor(indent) {
|
|
35
|
-
this.indent = indent;
|
|
36
|
-
}
|
|
37
|
-
toString() {
|
|
38
|
-
const text = this.lines.join('\n');
|
|
39
|
-
return text.endsWith('\n') ? text : `${text}\n`;
|
|
40
|
-
}
|
|
41
|
-
file(file) {
|
|
42
|
-
assertType(file, 'NowlineFile');
|
|
43
|
-
const directive = file.directive;
|
|
44
|
-
if (directive) {
|
|
45
|
-
const props = asArray(directive.properties);
|
|
46
|
-
const tail = props.length > 0 ? ` ${props.map(renderProperty).join(' ')}` : '';
|
|
47
|
-
this.line(0, `nowline ${getString(directive, 'version')}${tail}`);
|
|
48
|
-
this.blank();
|
|
49
|
-
}
|
|
50
|
-
for (const inc of asArray(file.includes)) {
|
|
51
|
-
this.include(inc);
|
|
52
|
-
}
|
|
53
|
-
if (asArray(file.includes).length > 0)
|
|
54
|
-
this.blank();
|
|
55
|
-
if (file.hasConfig) {
|
|
56
|
-
this.line(0, 'config');
|
|
57
|
-
this.blank();
|
|
58
|
-
for (const entry of asArray(file.configEntries)) {
|
|
59
|
-
this.configEntry(entry);
|
|
60
|
-
this.blank();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (file.roadmapDecl) {
|
|
64
|
-
this.roadmap(file.roadmapDecl);
|
|
65
|
-
this.blank();
|
|
66
|
-
}
|
|
67
|
-
for (const entry of asArray(file.roadmapEntries)) {
|
|
68
|
-
this.roadmapEntry(entry, 0);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
include(inc) {
|
|
72
|
-
assertType(inc, 'IncludeDeclaration');
|
|
73
|
-
const path = getString(inc, 'path');
|
|
74
|
-
const options = asArray(inc.options)
|
|
75
|
-
.map((o) => `${getString(o, 'key')}:${getString(o, 'value')}`)
|
|
76
|
-
.join(' ');
|
|
77
|
-
const tail = options ? ` ${options}` : '';
|
|
78
|
-
this.line(0, `include ${JSON.stringify(path)}${tail}`);
|
|
79
|
-
}
|
|
80
|
-
configEntry(entry) {
|
|
81
|
-
switch (entry.$type) {
|
|
82
|
-
case 'ScaleBlock':
|
|
83
|
-
return this.blockDecl('scale', asArray(entry.properties));
|
|
84
|
-
case 'CalendarBlock':
|
|
85
|
-
return this.blockDecl('calendar', asArray(entry.properties));
|
|
86
|
-
case 'StyleDeclaration':
|
|
87
|
-
return this.styleDecl(entry);
|
|
88
|
-
case 'DefaultDeclaration':
|
|
89
|
-
return this.defaultDecl(entry);
|
|
90
|
-
default:
|
|
91
|
-
throw new CliError(ExitCode.ValidationError, `Unknown config entry type: ${String(entry.$type)}`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
blockDecl(keyword, properties) {
|
|
95
|
-
this.line(0, keyword);
|
|
96
|
-
for (const p of properties) {
|
|
97
|
-
this.line(1, renderBlockProperty(p));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
styleDecl(entry) {
|
|
101
|
-
assertType(entry, 'StyleDeclaration');
|
|
102
|
-
const header = declarationHeader('style', entry, []);
|
|
103
|
-
this.line(0, header);
|
|
104
|
-
for (const p of asArray(entry.properties)) {
|
|
105
|
-
this.line(1, renderBlockProperty(p));
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
defaultDecl(entry) {
|
|
109
|
-
assertType(entry, 'DefaultDeclaration');
|
|
110
|
-
const entityType = getString(entry, 'entityType');
|
|
111
|
-
const props = renderProperties(asArray(entry.properties));
|
|
112
|
-
const tail = props ? ` ${props}` : '';
|
|
113
|
-
this.line(0, `default ${entityType}${tail}`);
|
|
114
|
-
}
|
|
115
|
-
roadmap(decl) {
|
|
116
|
-
assertType(decl, 'RoadmapDeclaration');
|
|
117
|
-
this.line(0, declarationHeader('roadmap', decl, asArray(decl.properties)));
|
|
118
|
-
}
|
|
119
|
-
roadmapEntry(entry, depth) {
|
|
120
|
-
switch (entry.$type) {
|
|
121
|
-
case 'PersonDeclaration':
|
|
122
|
-
return this.simpleEntity('person', entry, depth);
|
|
123
|
-
case 'TeamDeclaration':
|
|
124
|
-
return this.team(entry, depth);
|
|
125
|
-
case 'AnchorDeclaration':
|
|
126
|
-
return this.simpleEntity('anchor', entry, depth);
|
|
127
|
-
case 'SizeDeclaration':
|
|
128
|
-
return this.simpleEntity('size', entry, depth);
|
|
129
|
-
case 'StatusDeclaration':
|
|
130
|
-
return this.simpleEntity('status', entry, depth);
|
|
131
|
-
case 'LabelDeclaration':
|
|
132
|
-
return this.simpleEntity('label', entry, depth);
|
|
133
|
-
case 'MilestoneDeclaration':
|
|
134
|
-
return this.simpleEntity('milestone', entry, depth);
|
|
135
|
-
case 'FootnoteDeclaration':
|
|
136
|
-
return this.simpleEntity('footnote', entry, depth);
|
|
137
|
-
case 'SwimlaneDeclaration':
|
|
138
|
-
return this.swimlane(entry, depth);
|
|
139
|
-
default:
|
|
140
|
-
throw new CliError(ExitCode.ValidationError, `Unknown roadmap entry type: ${String(entry.$type)}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
simpleEntity(keyword, entry, depth) {
|
|
144
|
-
this.line(depth, declarationHeader(keyword, entry, asArray(entry.properties)));
|
|
145
|
-
this.maybeDescription(entry, depth + 1);
|
|
146
|
-
}
|
|
147
|
-
team(entry, depth) {
|
|
148
|
-
this.line(depth, declarationHeader('team', entry, asArray(entry.properties)));
|
|
149
|
-
for (const child of asArray(entry.content)) {
|
|
150
|
-
this.teamContent(child, depth + 1);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
teamContent(node, depth) {
|
|
154
|
-
if (node.$type === 'PersonMemberRef') {
|
|
155
|
-
this.line(depth, `person ${getString(node, 'ref')}`);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if (node.$type === 'TeamDeclaration') {
|
|
159
|
-
return this.team(node, depth);
|
|
160
|
-
}
|
|
161
|
-
if (node.$type === 'PersonDeclaration') {
|
|
162
|
-
return this.simpleEntity('person', node, depth);
|
|
163
|
-
}
|
|
164
|
-
if (node.$type === 'DescriptionDirective') {
|
|
165
|
-
return this.descriptionDirective(node, depth);
|
|
166
|
-
}
|
|
167
|
-
throw new CliError(ExitCode.ValidationError, `Unknown team content type: ${String(node.$type)}`);
|
|
168
|
-
}
|
|
169
|
-
swimlane(entry, depth) {
|
|
170
|
-
this.line(depth, declarationHeader('swimlane', entry, asArray(entry.properties)));
|
|
171
|
-
for (const child of asArray(entry.content)) {
|
|
172
|
-
this.swimlaneContent(child, depth + 1);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
swimlaneContent(node, depth) {
|
|
176
|
-
switch (node.$type) {
|
|
177
|
-
case 'ItemDeclaration':
|
|
178
|
-
this.simpleEntity('item', node, depth);
|
|
179
|
-
return;
|
|
180
|
-
case 'ParallelBlock':
|
|
181
|
-
this.parallelBlock(node, depth);
|
|
182
|
-
return;
|
|
183
|
-
case 'GroupBlock':
|
|
184
|
-
this.groupBlock(node, depth);
|
|
185
|
-
return;
|
|
186
|
-
case 'DescriptionDirective':
|
|
187
|
-
this.descriptionDirective(node, depth);
|
|
188
|
-
return;
|
|
189
|
-
default:
|
|
190
|
-
throw new CliError(ExitCode.ValidationError, `Unknown swimlane content type: ${String(node.$type)}`);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
parallelBlock(entry, depth) {
|
|
194
|
-
this.line(depth, declarationHeader('parallel', entry, asArray(entry.properties)));
|
|
195
|
-
for (const child of asArray(entry.content)) {
|
|
196
|
-
this.swimlaneContent(child, depth + 1);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
groupBlock(entry, depth) {
|
|
200
|
-
this.line(depth, declarationHeader('group', entry, asArray(entry.properties)));
|
|
201
|
-
for (const child of asArray(entry.content)) {
|
|
202
|
-
this.swimlaneContent(child, depth + 1);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
descriptionDirective(node, depth) {
|
|
206
|
-
assertType(node, 'DescriptionDirective');
|
|
207
|
-
this.line(depth, `description ${JSON.stringify(getString(node, 'text'))}`);
|
|
208
|
-
}
|
|
209
|
-
maybeDescription(entry, depth) {
|
|
210
|
-
const desc = entry.description;
|
|
211
|
-
if (desc)
|
|
212
|
-
this.descriptionDirective(desc, depth);
|
|
213
|
-
}
|
|
214
|
-
line(depth, text) {
|
|
215
|
-
this.lines.push(this.indent.repeat(depth) + text);
|
|
216
|
-
}
|
|
217
|
-
blank() {
|
|
218
|
-
if (this.lines.length === 0)
|
|
219
|
-
return;
|
|
220
|
-
if (this.lines[this.lines.length - 1] === '')
|
|
221
|
-
return;
|
|
222
|
-
this.lines.push('');
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
function declarationHeader(keyword, entry, properties) {
|
|
226
|
-
const id = entry.name;
|
|
227
|
-
const title = entry.title;
|
|
228
|
-
const parts = [keyword];
|
|
229
|
-
if (id)
|
|
230
|
-
parts.push(id);
|
|
231
|
-
if (title)
|
|
232
|
-
parts.push(JSON.stringify(title));
|
|
233
|
-
const props = renderProperties(properties);
|
|
234
|
-
if (props)
|
|
235
|
-
parts.push(props);
|
|
236
|
-
return parts.join(' ');
|
|
237
|
-
}
|
|
238
|
-
function renderProperties(properties) {
|
|
239
|
-
return orderProperties(properties).map(renderProperty).join(' ');
|
|
240
|
-
}
|
|
241
|
-
function orderProperties(properties) {
|
|
242
|
-
const indexOf = new Map(KEY_ORDER.map((k, i) => [k, i]));
|
|
243
|
-
return [...properties].sort((a, b) => {
|
|
244
|
-
const ak = normalizeKey(getString(a, 'key'));
|
|
245
|
-
const bk = normalizeKey(getString(b, 'key'));
|
|
246
|
-
const ai = indexOf.get(ak);
|
|
247
|
-
const bi = indexOf.get(bk);
|
|
248
|
-
if (ai !== undefined && bi !== undefined)
|
|
249
|
-
return ai - bi;
|
|
250
|
-
if (ai !== undefined)
|
|
251
|
-
return -1;
|
|
252
|
-
if (bi !== undefined)
|
|
253
|
-
return 1;
|
|
254
|
-
return ak.localeCompare(bk);
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
function renderProperty(prop) {
|
|
258
|
-
const key = normalizeKey(getString(prop, 'key'));
|
|
259
|
-
const values = asStringArray(prop.values);
|
|
260
|
-
const value = prop.value;
|
|
261
|
-
if (values.length >= 2) {
|
|
262
|
-
return `${key}:[${values.map(formatAtom).join(', ')}]`;
|
|
263
|
-
}
|
|
264
|
-
if (values.length === 1) {
|
|
265
|
-
return `${key}:${formatAtom(values[0])}`;
|
|
266
|
-
}
|
|
267
|
-
if (value !== undefined && value !== '') {
|
|
268
|
-
return `${key}:${formatAtom(value)}`;
|
|
269
|
-
}
|
|
270
|
-
return `${key}:`;
|
|
271
|
-
}
|
|
272
|
-
// Block-style property (one per line, rendered as `key: value`). Used inside
|
|
273
|
-
// indented blocks like `scale`, `calendar`, and `style`. Uses formatAtom so
|
|
274
|
-
// that quoted / template strings such as `label: "W{n}"` survive a round-trip.
|
|
275
|
-
function renderBlockProperty(prop) {
|
|
276
|
-
const key = normalizeKey(getString(prop, 'key'));
|
|
277
|
-
const values = asStringArray(prop.values);
|
|
278
|
-
const value = prop.value;
|
|
279
|
-
if (values.length >= 2) {
|
|
280
|
-
return `${key}: [${values.map(formatAtom).join(', ')}]`;
|
|
281
|
-
}
|
|
282
|
-
if (values.length === 1) {
|
|
283
|
-
return `${key}: ${formatAtom(values[0])}`;
|
|
284
|
-
}
|
|
285
|
-
if (value !== undefined && value !== '') {
|
|
286
|
-
return `${key}: ${formatAtom(value)}`;
|
|
287
|
-
}
|
|
288
|
-
return `${key}:`;
|
|
289
|
-
}
|
|
290
|
-
function normalizeKey(key) {
|
|
291
|
-
return key.endsWith(':') ? key.slice(0, -1) : key;
|
|
292
|
-
}
|
|
293
|
-
const URL_RE = /^https?:\/\//;
|
|
294
|
-
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
295
|
-
const DURATION_RE = /^\d+(?:\.\d+)?[dwmqy]$/;
|
|
296
|
-
const PERCENTAGE_RE = /^\d+%$/;
|
|
297
|
-
const HEX_COLOR_RE = /^#[0-9a-fA-F]{3,8}$/;
|
|
298
|
-
const INTEGER_RE = /^\d+$/;
|
|
299
|
-
const ID_RE = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
|
|
300
|
-
function formatAtom(atom) {
|
|
301
|
-
if (URL_RE.test(atom) ||
|
|
302
|
-
DATE_RE.test(atom) ||
|
|
303
|
-
DURATION_RE.test(atom) ||
|
|
304
|
-
PERCENTAGE_RE.test(atom) ||
|
|
305
|
-
HEX_COLOR_RE.test(atom) ||
|
|
306
|
-
INTEGER_RE.test(atom) ||
|
|
307
|
-
ID_RE.test(atom)) {
|
|
308
|
-
return atom;
|
|
309
|
-
}
|
|
310
|
-
// Already-quoted string survives a round trip through JSON.stringify by re-quoting once.
|
|
311
|
-
if (atom.startsWith('"') && atom.endsWith('"'))
|
|
312
|
-
return atom;
|
|
313
|
-
return JSON.stringify(atom);
|
|
314
|
-
}
|
|
315
|
-
function asArray(value) {
|
|
316
|
-
if (Array.isArray(value))
|
|
317
|
-
return value;
|
|
318
|
-
return [];
|
|
319
|
-
}
|
|
320
|
-
function asStringArray(value) {
|
|
321
|
-
if (!Array.isArray(value))
|
|
322
|
-
return [];
|
|
323
|
-
return value.filter((v) => typeof v === 'string');
|
|
324
|
-
}
|
|
325
|
-
function getString(node, key) {
|
|
326
|
-
const value = node[key];
|
|
327
|
-
return typeof value === 'string' ? value : '';
|
|
328
|
-
}
|
|
329
|
-
function assertType(node, expected) {
|
|
330
|
-
if (node.$type !== expected) {
|
|
331
|
-
throw new CliError(ExitCode.ValidationError, `Expected $type "${expected}", got "${String(node.$type)}"`);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
1
|
+
// Re-exported from @nowline/core. Kept here for backwards compatibility.
|
|
2
|
+
export { printNowlineFile } from '@nowline/core';
|
|
334
3
|
//# sourceMappingURL=printer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"printer.js","sourceRoot":"","sources":["../../src/convert/printer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGzD,mFAAmF;AACnF,MAAM,SAAS,GAAG;IACd,MAAM;IACN,QAAQ;IACR,IAAI;IACJ,MAAM;IACN,UAAU;IACV,QAAQ;IACR,OAAO;IACP,OAAO;IACP,QAAQ;IACR,WAAW;IACX,QAAQ;IACR,OAAO;IACP,MAAM;IACN,QAAQ;IACR,OAAO;IACP,OAAO;IACP,UAAU;IACV,iBAAiB;IACjB,mBAAmB;IACnB,YAAY;CACf,CAAC;AAEF,MAAM,MAAM,GAAG,IAAI,CAAC;AAMpB,MAAM,UAAU,gBAAgB,CAAC,GAAgB,EAAE,UAAwB,EAAE;IACzE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC;IACtD,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClB,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC;AAED,MAAM,OAAO;IAGoB;IAFZ,KAAK,GAAa,EAAE,CAAC;IAEtC,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,QAAQ;QACJ,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC;IACpD,CAAC;IAED,IAAI,CAAC,IAAiB;QAClB,UAAU,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAChC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAoC,CAAC;Q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U,CAAC,IAAiB,EAAE,QAAgB;IACnD,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC1B,MAAM,IAAI,QAAQ,CACd,QAAQ,CAAC,eAAe,EACxB,mBAAmB,QAAQ,WAAW,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAC9D,CAAC;IACN,CAAC;AACL,CAAC"}
|
|
1
|
+
{"version":3,"file":"printer.js","sourceRoot":"","sources":["../../src/convert/printer.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,OAAO,EAAqB,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/convert/schema.d.ts
CHANGED
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { LangiumDocument } from 'langium';
|
|
3
|
-
export declare const NOWLINE_SCHEMA_VERSION = "1";
|
|
4
|
-
export interface NowlineDocument {
|
|
5
|
-
$nowlineSchema: string;
|
|
6
|
-
file: {
|
|
7
|
-
uri: string;
|
|
8
|
-
source: string;
|
|
9
|
-
};
|
|
10
|
-
ast: JsonAstNode;
|
|
11
|
-
}
|
|
12
|
-
export interface Position {
|
|
13
|
-
start: {
|
|
14
|
-
line: number;
|
|
15
|
-
column: number;
|
|
16
|
-
offset: number;
|
|
17
|
-
};
|
|
18
|
-
end: {
|
|
19
|
-
line: number;
|
|
20
|
-
column: number;
|
|
21
|
-
offset: number;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export interface JsonAstNode {
|
|
25
|
-
$type: string;
|
|
26
|
-
$position?: Position;
|
|
27
|
-
[key: string]: unknown;
|
|
28
|
-
}
|
|
29
|
-
export interface SerializeOptions {
|
|
30
|
-
includePositions?: boolean;
|
|
31
|
-
}
|
|
32
|
-
export declare function serializeToJson(document: LangiumDocument<NowlineFile>, source: string, options?: SerializeOptions): NowlineDocument;
|
|
1
|
+
export { type JsonAstNode, NOWLINE_SCHEMA_VERSION, type NowlineDocument, type Position, type SerializeOptions, serializeToJson, } from '@nowline/core';
|
|
33
2
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/convert/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/convert/schema.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,WAAW,EAChB,sBAAsB,EACtB,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,eAAe,GAClB,MAAM,eAAe,CAAC"}
|
package/dist/convert/schema.js
CHANGED
|
@@ -1,77 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const CONTAINER_KEYS = new Set(['$container', '$containerProperty', '$containerIndex']);
|
|
4
|
-
// $cstNode / $document are runtime-only. $type and $position are emitted.
|
|
5
|
-
const RUNTIME_KEYS = new Set(['$cstNode', '$document']);
|
|
6
|
-
export function serializeToJson(document, source, options = {}) {
|
|
7
|
-
const includePositions = options.includePositions ?? true;
|
|
8
|
-
return {
|
|
9
|
-
$nowlineSchema: NOWLINE_SCHEMA_VERSION,
|
|
10
|
-
file: {
|
|
11
|
-
uri: document.uri.toString(),
|
|
12
|
-
source,
|
|
13
|
-
},
|
|
14
|
-
ast: serializeNode(document.parseResult.value, includePositions),
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function serializeNode(node, includePositions) {
|
|
18
|
-
const out = { $type: node.$type };
|
|
19
|
-
if (includePositions) {
|
|
20
|
-
const pos = cstPosition(node.$cstNode);
|
|
21
|
-
if (pos)
|
|
22
|
-
out.$position = pos;
|
|
23
|
-
}
|
|
24
|
-
for (const [key, value] of Object.entries(node)) {
|
|
25
|
-
if (key.startsWith('$'))
|
|
26
|
-
continue;
|
|
27
|
-
if (CONTAINER_KEYS.has(key) || RUNTIME_KEYS.has(key))
|
|
28
|
-
continue;
|
|
29
|
-
out[key] = serializeValue(value, includePositions);
|
|
30
|
-
}
|
|
31
|
-
return out;
|
|
32
|
-
}
|
|
33
|
-
function serializeValue(value, includePositions) {
|
|
34
|
-
if (value === null || value === undefined)
|
|
35
|
-
return value;
|
|
36
|
-
if (Array.isArray(value)) {
|
|
37
|
-
return value.map((v) => serializeValue(v, includePositions));
|
|
38
|
-
}
|
|
39
|
-
if (isAstNode(value)) {
|
|
40
|
-
return serializeNode(value, includePositions);
|
|
41
|
-
}
|
|
42
|
-
if (typeof value === 'object') {
|
|
43
|
-
const record = value;
|
|
44
|
-
const out = {};
|
|
45
|
-
for (const [k, v] of Object.entries(record)) {
|
|
46
|
-
if (k.startsWith('$'))
|
|
47
|
-
continue;
|
|
48
|
-
if (CONTAINER_KEYS.has(k) || RUNTIME_KEYS.has(k))
|
|
49
|
-
continue;
|
|
50
|
-
out[k] = serializeValue(v, includePositions);
|
|
51
|
-
}
|
|
52
|
-
return out;
|
|
53
|
-
}
|
|
54
|
-
return value;
|
|
55
|
-
}
|
|
56
|
-
function isAstNode(value) {
|
|
57
|
-
return (value !== null &&
|
|
58
|
-
typeof value === 'object' &&
|
|
59
|
-
typeof value.$type === 'string');
|
|
60
|
-
}
|
|
61
|
-
function cstPosition(cst) {
|
|
62
|
-
if (!cst)
|
|
63
|
-
return undefined;
|
|
64
|
-
return {
|
|
65
|
-
start: {
|
|
66
|
-
line: cst.range.start.line + 1,
|
|
67
|
-
column: cst.range.start.character + 1,
|
|
68
|
-
offset: cst.offset,
|
|
69
|
-
},
|
|
70
|
-
end: {
|
|
71
|
-
line: cst.range.end.line + 1,
|
|
72
|
-
column: cst.range.end.character + 1,
|
|
73
|
-
offset: cst.end,
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
}
|
|
1
|
+
// Re-exported from @nowline/core. Kept here for backwards compatibility.
|
|
2
|
+
export { NOWLINE_SCHEMA_VERSION, serializeToJson, } from '@nowline/core';
|
|
77
3
|
//# sourceMappingURL=schema.js.map
|