@miragon/wardley-dsl 0.5.2 → 0.6.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/index.d.cts CHANGED
@@ -1,7 +1,15 @@
1
1
  import { WardleyMap, Method } from '@miragon/wardley-schema-model';
2
2
  export { loadMap, parseMapJSON as mapFromJSON, serializeMap as mapToJSON } from '@miragon/wardley-schema-model';
3
3
 
4
- /** Finding produced while parsing — line is 1-based; `text` is the (comment-stripped) line. */
4
+ /**
5
+ * Serializes a WardleyMap into Online-Wardley-Maps text. Deterministic; writes only
6
+ * syntax the OWM parser reads back. `rawPassthrough` is appended unchanged.
7
+ * Coordinates are keyword-differentiated (component/anchor/note = [visibility, maturity];
8
+ * pipeline = [maturityStart, maturityEnd]).
9
+ */
10
+ declare function serializeDSL(map: WardleyMap): string;
11
+
12
+ /** Finding produced while parsing — line is 1-based; `text` is that source line, trimmed. */
5
13
  interface ParseDiagnostic {
6
14
  readonly line: number;
7
15
  readonly message: string;
@@ -23,12 +31,31 @@ declare function parseDSL(text: string): WardleyMap;
23
31
  declare function parseDSLWithDiagnostics(text: string): ParseResult;
24
32
 
25
33
  /**
26
- * Serializes a WardleyMap into Online-Wardley-Maps text. Deterministic; writes only
27
- * syntax the OWM parser reads back. `rawPassthrough` is appended unchanged.
28
- * Coordinates are keyword-differentiated (component/anchor/note = [visibility, maturity];
29
- * pipeline = [maturityStart, maturityEnd]).
34
+ * Writes `map` back into `originalText`, the text it was read from, and keeps everything the edit
35
+ * did not touch verbatim: comments, blank lines, line order, number formatting, unknown lines and
36
+ * the line breaks. Changed statements are rewritten in place the way `serializeDSL` writes them,
37
+ * removed ones are deleted and new ones are inserted after the last statement of their kind. The
38
+ * result always reads back as the same map as `serializeDSL(map)`; when a patch cannot guarantee
39
+ * that, the result is `serializeDSL(map)` itself, in the line break style of the source. Never
40
+ * throws.
30
41
  */
31
- declare function serializeDSL(map: WardleyMap): string;
42
+ declare function patchDSL(originalText: string, map: WardleyMap, options?: PatchOptions): string;
43
+ interface PatchOptions {
44
+ /**
45
+ * The map `originalText` was last written from, in the caller's ids. An editor that keeps the
46
+ * ids of its first read (instead of re-reading every patched text) passes it, so an element
47
+ * renamed twice is still recognised: the re-read text derives its id from the first new name.
48
+ */
49
+ readonly previous?: WardleyMap;
50
+ }
51
+
52
+ /**
53
+ * `rawPassthrough` without the uninterpreted statements of one keyword (e.g. an unreadable `size`
54
+ * line once the map writes a valid one). Lines are judged by their code outside comments, so text
55
+ * inside a block comment that merely starts with the keyword stays. A dropped statement keeps its
56
+ * own comment fragments, so an opened block comment still closes where it did.
57
+ */
58
+ declare function withoutRawStatements(rawPassthrough: readonly string[] | undefined, keyword: string): readonly string[] | undefined;
32
59
 
33
60
  /**
34
61
  * Small, line-oriented helpers for the OWM DSL (concept doc §7.4).
@@ -52,6 +79,10 @@ interface InlineDecorators {
52
79
  * - parenthesized: `(market)`, `(ecosystem)`, `(build|buy|outsource)`, combined `(market, outsource)`
53
80
  * - trailing keyword: `inertia`
54
81
  * Returns the decorators found and the line stripped of them.
82
+ *
83
+ * @deprecated Kept for API compatibility; the parser no longer uses it. It reads every `( … )` group
84
+ * and `inertia` anywhere on the line and lets the last method win, while `parseDSL` reads decorators
85
+ * only after the coordinates and keeps the first method.
55
86
  */
56
87
  declare function parseDecorators(line: string): {
57
88
  decorators: InlineDecorators;
@@ -61,13 +92,17 @@ interface LabelOffsetToken {
61
92
  readonly dx: number;
62
93
  readonly dy: number;
63
94
  }
64
- /** Reads an optional `label [dx, dy]` (pixel offset) and returns it plus the stripped line. */
95
+ /**
96
+ * Reads an optional `label [dx, dy]` (pixel offset) and returns it plus the stripped line.
97
+ * `unreadable` holds the matched text when a number in it cannot be read.
98
+ */
65
99
  declare function parseLabelOffset(line: string): {
66
100
  labelOffset: LabelOffsetToken | null;
67
101
  rest: string;
102
+ unreadable?: string;
68
103
  };
69
104
  /** First word (keyword) of a line, lowercased. */
70
105
  declare function keywordOf(line: string): string;
71
106
  declare function slug(label: string): string;
72
107
 
73
- export { type InlineDecorators, type LabelOffsetToken, type ParseDiagnostic, type ParseResult, type ParsedCoords, keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, serializeDSL, slug };
108
+ export { type InlineDecorators, type LabelOffsetToken, type ParseDiagnostic, type ParseResult, type ParsedCoords, type PatchOptions, keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, patchDSL, serializeDSL, slug, withoutRawStatements };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,15 @@
1
1
  import { WardleyMap, Method } from '@miragon/wardley-schema-model';
2
2
  export { loadMap, parseMapJSON as mapFromJSON, serializeMap as mapToJSON } from '@miragon/wardley-schema-model';
3
3
 
4
- /** Finding produced while parsing — line is 1-based; `text` is the (comment-stripped) line. */
4
+ /**
5
+ * Serializes a WardleyMap into Online-Wardley-Maps text. Deterministic; writes only
6
+ * syntax the OWM parser reads back. `rawPassthrough` is appended unchanged.
7
+ * Coordinates are keyword-differentiated (component/anchor/note = [visibility, maturity];
8
+ * pipeline = [maturityStart, maturityEnd]).
9
+ */
10
+ declare function serializeDSL(map: WardleyMap): string;
11
+
12
+ /** Finding produced while parsing — line is 1-based; `text` is that source line, trimmed. */
5
13
  interface ParseDiagnostic {
6
14
  readonly line: number;
7
15
  readonly message: string;
@@ -23,12 +31,31 @@ declare function parseDSL(text: string): WardleyMap;
23
31
  declare function parseDSLWithDiagnostics(text: string): ParseResult;
24
32
 
25
33
  /**
26
- * Serializes a WardleyMap into Online-Wardley-Maps text. Deterministic; writes only
27
- * syntax the OWM parser reads back. `rawPassthrough` is appended unchanged.
28
- * Coordinates are keyword-differentiated (component/anchor/note = [visibility, maturity];
29
- * pipeline = [maturityStart, maturityEnd]).
34
+ * Writes `map` back into `originalText`, the text it was read from, and keeps everything the edit
35
+ * did not touch verbatim: comments, blank lines, line order, number formatting, unknown lines and
36
+ * the line breaks. Changed statements are rewritten in place the way `serializeDSL` writes them,
37
+ * removed ones are deleted and new ones are inserted after the last statement of their kind. The
38
+ * result always reads back as the same map as `serializeDSL(map)`; when a patch cannot guarantee
39
+ * that, the result is `serializeDSL(map)` itself, in the line break style of the source. Never
40
+ * throws.
30
41
  */
31
- declare function serializeDSL(map: WardleyMap): string;
42
+ declare function patchDSL(originalText: string, map: WardleyMap, options?: PatchOptions): string;
43
+ interface PatchOptions {
44
+ /**
45
+ * The map `originalText` was last written from, in the caller's ids. An editor that keeps the
46
+ * ids of its first read (instead of re-reading every patched text) passes it, so an element
47
+ * renamed twice is still recognised: the re-read text derives its id from the first new name.
48
+ */
49
+ readonly previous?: WardleyMap;
50
+ }
51
+
52
+ /**
53
+ * `rawPassthrough` without the uninterpreted statements of one keyword (e.g. an unreadable `size`
54
+ * line once the map writes a valid one). Lines are judged by their code outside comments, so text
55
+ * inside a block comment that merely starts with the keyword stays. A dropped statement keeps its
56
+ * own comment fragments, so an opened block comment still closes where it did.
57
+ */
58
+ declare function withoutRawStatements(rawPassthrough: readonly string[] | undefined, keyword: string): readonly string[] | undefined;
32
59
 
33
60
  /**
34
61
  * Small, line-oriented helpers for the OWM DSL (concept doc §7.4).
@@ -52,6 +79,10 @@ interface InlineDecorators {
52
79
  * - parenthesized: `(market)`, `(ecosystem)`, `(build|buy|outsource)`, combined `(market, outsource)`
53
80
  * - trailing keyword: `inertia`
54
81
  * Returns the decorators found and the line stripped of them.
82
+ *
83
+ * @deprecated Kept for API compatibility; the parser no longer uses it. It reads every `( … )` group
84
+ * and `inertia` anywhere on the line and lets the last method win, while `parseDSL` reads decorators
85
+ * only after the coordinates and keeps the first method.
55
86
  */
56
87
  declare function parseDecorators(line: string): {
57
88
  decorators: InlineDecorators;
@@ -61,13 +92,17 @@ interface LabelOffsetToken {
61
92
  readonly dx: number;
62
93
  readonly dy: number;
63
94
  }
64
- /** Reads an optional `label [dx, dy]` (pixel offset) and returns it plus the stripped line. */
95
+ /**
96
+ * Reads an optional `label [dx, dy]` (pixel offset) and returns it plus the stripped line.
97
+ * `unreadable` holds the matched text when a number in it cannot be read.
98
+ */
65
99
  declare function parseLabelOffset(line: string): {
66
100
  labelOffset: LabelOffsetToken | null;
67
101
  rest: string;
102
+ unreadable?: string;
68
103
  };
69
104
  /** First word (keyword) of a line, lowercased. */
70
105
  declare function keywordOf(line: string): string;
71
106
  declare function slug(label: string): string;
72
107
 
73
- export { type InlineDecorators, type LabelOffsetToken, type ParseDiagnostic, type ParseResult, type ParsedCoords, keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, serializeDSL, slug };
108
+ export { type InlineDecorators, type LabelOffsetToken, type ParseDiagnostic, type ParseResult, type ParsedCoords, type PatchOptions, keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, patchDSL, serializeDSL, slug, withoutRawStatements };