@miragon/wardley-dsl 0.5.3 → 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/index.d.cts CHANGED
@@ -1,6 +1,14 @@
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
+ /**
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
+
4
12
  /** Finding produced while parsing — line is 1-based; `text` is that source line, trimmed. */
5
13
  interface ParseDiagnostic {
6
14
  readonly line: number;
@@ -23,12 +31,40 @@ 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
+ * The id each element of `map` carries once `serializeDSL(map)` is read back, keyed by its id in
54
+ * `map`. The OWM DSL writes no ids: the parser derives them from names, texts and the order of the
55
+ * lines, so an element created or renamed in an editor has another id in memory than in the
56
+ * document until the text is read again. Elements the text does not write (none today) are
57
+ * missing from the result.
58
+ */
59
+ declare function readBackIds(map: WardleyMap): Map<string, string>;
60
+
61
+ /**
62
+ * `rawPassthrough` without the uninterpreted statements of one keyword (e.g. an unreadable `size`
63
+ * line once the map writes a valid one). Lines are judged by their code outside comments, so text
64
+ * inside a block comment that merely starts with the keyword stays. A dropped statement keeps its
65
+ * own comment fragments, so an opened block comment still closes where it did.
66
+ */
67
+ declare function withoutRawStatements(rawPassthrough: readonly string[] | undefined, keyword: string): readonly string[] | undefined;
32
68
 
33
69
  /**
34
70
  * Small, line-oriented helpers for the OWM DSL (concept doc §7.4).
@@ -78,4 +114,5 @@ declare function parseLabelOffset(line: string): {
78
114
  declare function keywordOf(line: string): string;
79
115
  declare function slug(label: string): string;
80
116
 
81
- export { type InlineDecorators, type LabelOffsetToken, type ParseDiagnostic, type ParseResult, type ParsedCoords, keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, serializeDSL, slug };
117
+ export { keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, patchDSL, readBackIds, serializeDSL, slug, withoutRawStatements };
118
+ export type { InlineDecorators, LabelOffsetToken, ParseDiagnostic, ParseResult, ParsedCoords, PatchOptions };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,14 @@
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
+ /**
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
+
4
12
  /** Finding produced while parsing — line is 1-based; `text` is that source line, trimmed. */
5
13
  interface ParseDiagnostic {
6
14
  readonly line: number;
@@ -23,12 +31,40 @@ 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
+ * The id each element of `map` carries once `serializeDSL(map)` is read back, keyed by its id in
54
+ * `map`. The OWM DSL writes no ids: the parser derives them from names, texts and the order of the
55
+ * lines, so an element created or renamed in an editor has another id in memory than in the
56
+ * document until the text is read again. Elements the text does not write (none today) are
57
+ * missing from the result.
58
+ */
59
+ declare function readBackIds(map: WardleyMap): Map<string, string>;
60
+
61
+ /**
62
+ * `rawPassthrough` without the uninterpreted statements of one keyword (e.g. an unreadable `size`
63
+ * line once the map writes a valid one). Lines are judged by their code outside comments, so text
64
+ * inside a block comment that merely starts with the keyword stays. A dropped statement keeps its
65
+ * own comment fragments, so an opened block comment still closes where it did.
66
+ */
67
+ declare function withoutRawStatements(rawPassthrough: readonly string[] | undefined, keyword: string): readonly string[] | undefined;
32
68
 
33
69
  /**
34
70
  * Small, line-oriented helpers for the OWM DSL (concept doc §7.4).
@@ -78,4 +114,5 @@ declare function parseLabelOffset(line: string): {
78
114
  declare function keywordOf(line: string): string;
79
115
  declare function slug(label: string): string;
80
116
 
81
- export { type InlineDecorators, type LabelOffsetToken, type ParseDiagnostic, type ParseResult, type ParsedCoords, keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, serializeDSL, slug };
117
+ export { keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, patchDSL, readBackIds, serializeDSL, slug, withoutRawStatements };
118
+ export type { InlineDecorators, LabelOffsetToken, ParseDiagnostic, ParseResult, ParsedCoords, PatchOptions };