@miragon/wardley-dsl 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/index.d.cts CHANGED
@@ -49,6 +49,15 @@ interface PatchOptions {
49
49
  readonly previous?: WardleyMap;
50
50
  }
51
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
+
52
61
  /**
53
62
  * `rawPassthrough` without the uninterpreted statements of one keyword (e.g. an unreadable `size`
54
63
  * line once the map writes a valid one). Lines are judged by their code outside comments, so text
@@ -105,4 +114,5 @@ declare function parseLabelOffset(line: string): {
105
114
  declare function keywordOf(line: string): string;
106
115
  declare function slug(label: string): string;
107
116
 
108
- export { type InlineDecorators, type LabelOffsetToken, type ParseDiagnostic, type ParseResult, type ParsedCoords, type PatchOptions, keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, patchDSL, serializeDSL, slug, withoutRawStatements };
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
@@ -49,6 +49,15 @@ interface PatchOptions {
49
49
  readonly previous?: WardleyMap;
50
50
  }
51
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
+
52
61
  /**
53
62
  * `rawPassthrough` without the uninterpreted statements of one keyword (e.g. an unreadable `size`
54
63
  * line once the map writes a valid one). Lines are judged by their code outside comments, so text
@@ -105,4 +114,5 @@ declare function parseLabelOffset(line: string): {
105
114
  declare function keywordOf(line: string): string;
106
115
  declare function slug(label: string): string;
107
116
 
108
- export { type InlineDecorators, type LabelOffsetToken, type ParseDiagnostic, type ParseResult, type ParsedCoords, type PatchOptions, keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, patchDSL, serializeDSL, slug, withoutRawStatements };
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.js CHANGED
@@ -594,7 +594,7 @@ var MapReader = class {
594
594
  }
595
595
  /** For a line that looks like a known construct but cannot be parsed. */
596
596
  failed(line) {
597
- this.keep(line, "Line could not be interpreted (kept losslessly in rawPassthrough)");
597
+ this.keep(line, "Line not understood \u2014 kept as written");
598
598
  }
599
599
  // A reference binds to the name as written first, so `X 2` stays bound to an explicit "X 2" even
600
600
  // when a duplicate "X" was renamed to "X 2"; the serializer then writes that reference by the
@@ -2484,6 +2484,28 @@ function fingerprint(map) {
2484
2484
  return entries.sort().join("\n");
2485
2485
  }
2486
2486
 
2487
+ // src/read-back-ids.ts
2488
+ var ELEMENT_KEY = /^(?:element|child):(.*)$/s;
2489
+ function elementIdOf(key) {
2490
+ return ELEMENT_KEY.exec(key)?.[1];
2491
+ }
2492
+ function readBackIds(map) {
2493
+ const lines = serializeKeyedLines(map);
2494
+ const { sourceMap } = parseDSLWithSourceMap([...lines.map((line) => line.text), ""].join("\n"));
2495
+ const readIdByLine = /* @__PURE__ */ new Map();
2496
+ for (const [key, line] of sourceMap.primaryLineOf) {
2497
+ const id = elementIdOf(key);
2498
+ if (id !== void 0) readIdByLine.set(line, id);
2499
+ }
2500
+ const ids = /* @__PURE__ */ new Map();
2501
+ lines.forEach((line, index) => {
2502
+ const id = elementIdOf(line.key);
2503
+ const readId = readIdByLine.get(index + 1);
2504
+ if (id !== void 0 && readId !== void 0) ids.set(id, readId);
2505
+ });
2506
+ return ids;
2507
+ }
2508
+
2487
2509
  // src/raw-passthrough.ts
2488
2510
  function withoutRawStatements(rawPassthrough, keyword) {
2489
2511
  if (!rawPassthrough) return rawPassthrough;
@@ -2504,6 +2526,6 @@ function withoutRawStatements(rawPassthrough, keyword) {
2504
2526
  return kept.length ? kept : void 0;
2505
2527
  }
2506
2528
 
2507
- export { keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, patchDSL, serializeDSL, slug, withoutRawStatements };
2529
+ export { keywordOf, parseCoords, parseDSL, parseDSLWithDiagnostics, parseDecorators, parseLabelOffset, patchDSL, readBackIds, serializeDSL, slug, withoutRawStatements };
2508
2530
  //# sourceMappingURL=index.js.map
2509
2531
  //# sourceMappingURL=index.js.map