@bpmnkit/core 0.2.0 → 0.3.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/bpmn/bpmn-serializer.js +70 -0
- package/dist/bpmn/diagram-diff.d.ts +71 -0
- package/dist/bpmn/diagram-diff.js +124 -0
- package/dist/bpmn/lint.d.ts +97 -0
- package/dist/bpmn/lint.js +135 -0
- package/dist/bpmn/preserving-writer.d.ts +64 -0
- package/dist/bpmn/preserving-writer.js +70 -0
- package/dist/dmn/dmn-serializer.js +7 -2
- package/dist/dmn/preserving-writer.d.ts +31 -0
- package/dist/dmn/preserving-writer.js +36 -0
- package/dist/form/preserving-writer.d.ts +47 -0
- package/dist/form/preserving-writer.js +50 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.js +7 -1
- package/dist/json/index.d.ts +5 -0
- package/dist/json/index.js +3 -0
- package/dist/json/json-patch.d.ts +65 -0
- package/dist/json/json-patch.js +416 -0
- package/dist/json/json-spans.d.ts +48 -0
- package/dist/json/json-spans.js +153 -0
- package/dist/xml/index.d.ts +5 -1
- package/dist/xml/index.js +2 -0
- package/dist/xml/xml-parser.d.ts +39 -0
- package/dist/xml/xml-parser.js +43 -2
- package/dist/xml/xml-patch.d.ts +109 -0
- package/dist/xml/xml-patch.js +459 -0
- package/dist/xml/xml-spans.d.ts +45 -0
- package/dist/xml/xml-spans.js +74 -0
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The BPMN preserving writer's counterpart for decision documents.
|
|
3
|
+
*
|
|
4
|
+
* Same problem, same shape, one difference worth naming: **DMN rule order is
|
|
5
|
+
* meaning**, not layout. A table with hit policy `FIRST` returns the first rule
|
|
6
|
+
* that matches, so moving a rule up changes what the decision decides. The
|
|
7
|
+
* strategy that keeps the file's own sibling order would quietly undo exactly
|
|
8
|
+
* that edit — which is why every strategy is checked against a plain write
|
|
9
|
+
* before it is used, and why this is a wrapper over the same verified ladder
|
|
10
|
+
* rather than a second implementation of it.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
import { type VerifiedPreserve } from "../xml/xml-patch.js";
|
|
15
|
+
import type { DmnDefinitions } from "./dmn-model.js";
|
|
16
|
+
/**
|
|
17
|
+
* Rewrites a decision document to say what a freshly serialized one says,
|
|
18
|
+
* keeping the original's formatting wherever a DMN reader cannot tell.
|
|
19
|
+
*
|
|
20
|
+
* @param original - The file's current contents.
|
|
21
|
+
* @param updated - The document as the serializer would write it now.
|
|
22
|
+
*/
|
|
23
|
+
export declare function preserveDmnFormatting(original: string, updated: string): VerifiedPreserve;
|
|
24
|
+
/**
|
|
25
|
+
* Serializes a decision model over the document it came from.
|
|
26
|
+
*
|
|
27
|
+
* @param original - The file's current contents.
|
|
28
|
+
* @param definitions - The model to write.
|
|
29
|
+
*/
|
|
30
|
+
export declare function exportDmnPreserving(original: string, definitions: DmnDefinitions): string;
|
|
31
|
+
//# sourceMappingURL=preserving-writer.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The BPMN preserving writer's counterpart for decision documents.
|
|
3
|
+
*
|
|
4
|
+
* Same problem, same shape, one difference worth naming: **DMN rule order is
|
|
5
|
+
* meaning**, not layout. A table with hit policy `FIRST` returns the first rule
|
|
6
|
+
* that matches, so moving a rule up changes what the decision decides. The
|
|
7
|
+
* strategy that keeps the file's own sibling order would quietly undo exactly
|
|
8
|
+
* that edit — which is why every strategy is checked against a plain write
|
|
9
|
+
* before it is used, and why this is a wrapper over the same verified ladder
|
|
10
|
+
* rather than a second implementation of it.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
import { preserveFormattingVerified } from "../xml/xml-patch.js";
|
|
15
|
+
import { parseDmn } from "./dmn-parser.js";
|
|
16
|
+
import { serializeDmn } from "./dmn-serializer.js";
|
|
17
|
+
/**
|
|
18
|
+
* Rewrites a decision document to say what a freshly serialized one says,
|
|
19
|
+
* keeping the original's formatting wherever a DMN reader cannot tell.
|
|
20
|
+
*
|
|
21
|
+
* @param original - The file's current contents.
|
|
22
|
+
* @param updated - The document as the serializer would write it now.
|
|
23
|
+
*/
|
|
24
|
+
export function preserveDmnFormatting(original, updated) {
|
|
25
|
+
return preserveFormattingVerified(original, updated, parseDmn);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Serializes a decision model over the document it came from.
|
|
29
|
+
*
|
|
30
|
+
* @param original - The file's current contents.
|
|
31
|
+
* @param definitions - The model to write.
|
|
32
|
+
*/
|
|
33
|
+
export function exportDmnPreserving(original, definitions) {
|
|
34
|
+
return preserveDmnFormatting(original, serializeDmn(definitions)).xml;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=preserving-writer.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writing a form back over the file it came from, changing as little as
|
|
3
|
+
* possible.
|
|
4
|
+
*
|
|
5
|
+
* The BPMN and DMN writers' counterpart, and the simpler of the two because a
|
|
6
|
+
* form is JSON. There is no schema question to get wrong: object key order is
|
|
7
|
+
* not information and array order always is, both by RFC 8259, so
|
|
8
|
+
* {@link preserveJsonFormatting} checks itself and this needs to supply
|
|
9
|
+
* nothing.
|
|
10
|
+
*
|
|
11
|
+
* What it buys is larger than it sounds. `exportForm` writes
|
|
12
|
+
* `JSON.stringify(…, null, 2)` in its own key order, so a form indented with
|
|
13
|
+
* tabs — or with four spaces, or minified — came back with **every line
|
|
14
|
+
* rewritten** the first time anyone touched it. Now it comes back with the line
|
|
15
|
+
* they touched.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import { type PreservedJson } from "../json/json-patch.js";
|
|
20
|
+
import type { FormDefinition } from "./form-model.js";
|
|
21
|
+
export type { PreservedJson };
|
|
22
|
+
/**
|
|
23
|
+
* Rewrites a form document to say what a freshly serialized one says, keeping
|
|
24
|
+
* the original's formatting wherever JSON cannot tell the difference.
|
|
25
|
+
*
|
|
26
|
+
* Takes both sides as text, for a caller holding a serialized document rather
|
|
27
|
+
* than a model — an editor's schema, say.
|
|
28
|
+
*
|
|
29
|
+
* @param original - The file's current contents.
|
|
30
|
+
* @param updated - The form as the serializer would write it now.
|
|
31
|
+
*/
|
|
32
|
+
export declare function preserveFormFormatting(original: string, updated: string): PreservedJson;
|
|
33
|
+
/**
|
|
34
|
+
* Serializes a form over the document it came from.
|
|
35
|
+
*
|
|
36
|
+
* @param original - The file's current contents.
|
|
37
|
+
* @param form - The form to write.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const onDisk = await readFile("approval.form", "utf8");
|
|
42
|
+
* await writeFile("approval.form", exportFormPreserving(onDisk, edited));
|
|
43
|
+
* // Renaming one label changes one line, whatever indentation the file uses.
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function exportFormPreserving(original: string, form: FormDefinition): string;
|
|
47
|
+
//# sourceMappingURL=preserving-writer.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writing a form back over the file it came from, changing as little as
|
|
3
|
+
* possible.
|
|
4
|
+
*
|
|
5
|
+
* The BPMN and DMN writers' counterpart, and the simpler of the two because a
|
|
6
|
+
* form is JSON. There is no schema question to get wrong: object key order is
|
|
7
|
+
* not information and array order always is, both by RFC 8259, so
|
|
8
|
+
* {@link preserveJsonFormatting} checks itself and this needs to supply
|
|
9
|
+
* nothing.
|
|
10
|
+
*
|
|
11
|
+
* What it buys is larger than it sounds. `exportForm` writes
|
|
12
|
+
* `JSON.stringify(…, null, 2)` in its own key order, so a form indented with
|
|
13
|
+
* tabs — or with four spaces, or minified — came back with **every line
|
|
14
|
+
* rewritten** the first time anyone touched it. Now it comes back with the line
|
|
15
|
+
* they touched.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import { preserveJsonFormatting } from "../json/json-patch.js";
|
|
20
|
+
import { exportForm } from "./form-serializer.js";
|
|
21
|
+
/**
|
|
22
|
+
* Rewrites a form document to say what a freshly serialized one says, keeping
|
|
23
|
+
* the original's formatting wherever JSON cannot tell the difference.
|
|
24
|
+
*
|
|
25
|
+
* Takes both sides as text, for a caller holding a serialized document rather
|
|
26
|
+
* than a model — an editor's schema, say.
|
|
27
|
+
*
|
|
28
|
+
* @param original - The file's current contents.
|
|
29
|
+
* @param updated - The form as the serializer would write it now.
|
|
30
|
+
*/
|
|
31
|
+
export function preserveFormFormatting(original, updated) {
|
|
32
|
+
return preserveJsonFormatting(original, updated);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Serializes a form over the document it came from.
|
|
36
|
+
*
|
|
37
|
+
* @param original - The file's current contents.
|
|
38
|
+
* @param form - The form to write.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const onDisk = await readFile("approval.form", "utf8");
|
|
43
|
+
* await writeFile("approval.form", exportFormPreserving(onDisk, edited));
|
|
44
|
+
* // Renaming one label changes one line, whatever indentation the file uses.
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function exportFormPreserving(original, form) {
|
|
48
|
+
return preserveFormFormatting(original, exportForm(form)).json;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=preserving-writer.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,13 @@ export { Bpmn, SAMPLE_BPMN_XML } from "./bpmn/index.js";
|
|
|
6
6
|
export { applyAutoLayout } from "./bpmn/auto-layout.js";
|
|
7
7
|
export { diffSemantics, projectSemantics, semanticHash } from "./bpmn/semantic-hash.js";
|
|
8
8
|
export type { JsonValue, SemanticDiff, SemanticProjection } from "./bpmn/semantic-hash.js";
|
|
9
|
+
export { detectExecutionPlatform, lintCategories, lintDiagram } from "./bpmn/lint.js";
|
|
10
|
+
export type { DetectedPlatform, ExecutionPlatform, LintDiagnostic, LintOptions, LintReport, } from "./bpmn/lint.js";
|
|
11
|
+
export { diffDiagram } from "./bpmn/diagram-diff.js";
|
|
12
|
+
export { exportPreserving, exportPreservingResult, preserveBpmnFormatting, } from "./bpmn/preserving-writer.js";
|
|
13
|
+
export type { PreservingWriteResult } from "./bpmn/preserving-writer.js";
|
|
14
|
+
export { exportDmnPreserving, preserveDmnFormatting } from "./dmn/preserving-writer.js";
|
|
15
|
+
export type { BpmnDiffCategory, BpmnDiffPlaneSummary, BpmnDiffResult, } from "./bpmn/diagram-diff.js";
|
|
9
16
|
export { sha256Hex } from "./bpmn/sha256.js";
|
|
10
17
|
export { checkDiCompleteness } from "./bpmn/di-check.js";
|
|
11
18
|
export type { DiCompleteness } from "./bpmn/di-check.js";
|
|
@@ -30,7 +37,11 @@ export type { DecisionTableBuilder, InputOptions, OutputOptions, RuleOptions, }
|
|
|
30
37
|
export type { DmnDefinitions, DmnDecision, DmnDecisionTable, DmnInput, DmnOutput, DmnRule, DmnInputEntry, DmnOutputEntry, DmnDiagram, DmnDiagramShape, DmnDiagramEdge, DmnWaypoint, DmnTypeRef, DmnAggregation, HitPolicy, DmnInformationRequirement, DmnKnowledgeRequirement, DmnAuthorityRequirement, DmnInputData, DmnKnowledgeSource, DmnBusinessKnowledgeModel, DmnTextAnnotation, DmnAssociation, } from "./dmn/dmn-model.js";
|
|
31
38
|
export type { XmlElement } from "./types/xml-element.js";
|
|
32
39
|
export { generateId, resetIdCounter } from "./types/id-generator.js";
|
|
33
|
-
export { parseXml, serializeXml } from "./xml/index.js";
|
|
40
|
+
export { parseXml, parseXmlSpans, preserveFormatting, preserveFormattingVerified, serializeXml, } from "./xml/index.js";
|
|
41
|
+
export type { PreserveOptions, SiblingOrder, SpannedAttribute, SpannedElement, VerifiedPreserve, } from "./xml/index.js";
|
|
42
|
+
export { parseJsonSpans, preserveJsonFormatting } from "./json/index.js";
|
|
43
|
+
export { exportFormPreserving, preserveFormFormatting } from "./form/preserving-writer.js";
|
|
44
|
+
export type { JsonKind, JsonMember, JsonNode, PreservedJson } from "./json/index.js";
|
|
34
45
|
export { readDiColor, writeDiColor, BIOC_NS, COLOR_NS } from "./bpmn/di-color.js";
|
|
35
46
|
export type { DiColor } from "./bpmn/di-color.js";
|
|
36
47
|
export { optimize } from "./bpmn/optimize/index.js";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,10 @@ export { findElement, findElementInProcess, findProcess, findSequenceFlow, getAl
|
|
|
4
4
|
export { Bpmn, SAMPLE_BPMN_XML } from "./bpmn/index.js";
|
|
5
5
|
export { applyAutoLayout } from "./bpmn/auto-layout.js";
|
|
6
6
|
export { diffSemantics, projectSemantics, semanticHash } from "./bpmn/semantic-hash.js";
|
|
7
|
+
export { detectExecutionPlatform, lintCategories, lintDiagram } from "./bpmn/lint.js";
|
|
8
|
+
export { diffDiagram } from "./bpmn/diagram-diff.js";
|
|
9
|
+
export { exportPreserving, exportPreservingResult, preserveBpmnFormatting, } from "./bpmn/preserving-writer.js";
|
|
10
|
+
export { exportDmnPreserving, preserveDmnFormatting } from "./dmn/preserving-writer.js";
|
|
7
11
|
export { sha256Hex } from "./bpmn/sha256.js";
|
|
8
12
|
export { checkDiCompleteness } from "./bpmn/di-check.js";
|
|
9
13
|
export { planeForElement, listPlaneElementIds } from "./bpmn/di-planes.js";
|
|
@@ -15,7 +19,9 @@ export { Dmn, layoutDmn, benchmarkDmnLayout, compactifyDmn, expandDmn } from "./
|
|
|
15
19
|
export { Form, compactifyForm, expandForm } from "./form/index.js";
|
|
16
20
|
export { FormBuilder, GroupBuilder } from "./form/form-builder.js";
|
|
17
21
|
export { generateId, resetIdCounter } from "./types/id-generator.js";
|
|
18
|
-
export { parseXml, serializeXml } from "./xml/index.js";
|
|
22
|
+
export { parseXml, parseXmlSpans, preserveFormatting, preserveFormattingVerified, serializeXml, } from "./xml/index.js";
|
|
23
|
+
export { parseJsonSpans, preserveJsonFormatting } from "./json/index.js";
|
|
24
|
+
export { exportFormPreserving, preserveFormFormatting } from "./form/preserving-writer.js";
|
|
19
25
|
export { readDiColor, writeDiColor, BIOC_NS, COLOR_NS } from "./bpmn/di-color.js";
|
|
20
26
|
export { optimize } from "./bpmn/optimize/index.js";
|
|
21
27
|
export { renderStoryHtml } from "./bpmn/story.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { parseJsonSpans } from "./json-spans.js";
|
|
2
|
+
export type { JsonKind, JsonMember, JsonNode } from "./json-spans.js";
|
|
3
|
+
export { preserveJsonFormatting } from "./json-patch.js";
|
|
4
|
+
export type { PreservedJson } from "./json-patch.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewriting a JSON document in place, so an edit reads as an edit.
|
|
3
|
+
*
|
|
4
|
+
* The same problem [`xml-patch.ts`](../xml/xml-patch.ts) solves for XML, and
|
|
5
|
+
* mostly the same answer: take the file as it stands and the file as the
|
|
6
|
+
* serializer would write it, and return the second's content carried by the
|
|
7
|
+
* first's bytes. A form saved from a visual editor otherwise comes back with
|
|
8
|
+
* this toolkit's indentation and this toolkit's key order, and one changed
|
|
9
|
+
* label reads as a rewritten file.
|
|
10
|
+
*
|
|
11
|
+
* ## Why this one checks itself
|
|
12
|
+
*
|
|
13
|
+
* The XML version cannot know whether sibling order carries meaning in a
|
|
14
|
+
* particular document, so it offers strategies and makes the caller verify.
|
|
15
|
+
* JSON needs none of that, because JSON has no schema-dependent semantics to
|
|
16
|
+
* be wrong about:
|
|
17
|
+
*
|
|
18
|
+
* - **An object is an unordered collection of members** (RFC 8259 §4), so
|
|
19
|
+
* keeping the file's own key order is not a guess about a schema; it is what
|
|
20
|
+
* the format says. Key order is never information.
|
|
21
|
+
* - **An array is an ordered sequence** (§5), so item order always follows the
|
|
22
|
+
* update. A form's components are its components in order.
|
|
23
|
+
*
|
|
24
|
+
* That makes deep equality — insensitive to key order, sensitive to item order
|
|
25
|
+
* — an exact statement of "this says what the update says", and the patch
|
|
26
|
+
* checks itself against it before returning. No reader has to be supplied and
|
|
27
|
+
* no strategy has to be chosen.
|
|
28
|
+
*
|
|
29
|
+
* @packageDocumentation
|
|
30
|
+
*/
|
|
31
|
+
/** How a preserving write turned out. */
|
|
32
|
+
export interface PreservedJson {
|
|
33
|
+
/** The document to write. */
|
|
34
|
+
readonly json: string;
|
|
35
|
+
/**
|
|
36
|
+
* `preserved` when the file's own formatting was kept; `rewritten` when the
|
|
37
|
+
* update was used as it stands, because nothing better could be checked.
|
|
38
|
+
*/
|
|
39
|
+
readonly outcome: "preserved" | "rewritten";
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Rewrites `original` to say what `updated` says, changing as little as it can.
|
|
43
|
+
*
|
|
44
|
+
* The result is `updated`'s document written with `original`'s formatting: its
|
|
45
|
+
* indentation, its key order, its number and string spellings. A member nobody
|
|
46
|
+
* touched comes back byte for byte.
|
|
47
|
+
*
|
|
48
|
+
* The patch is checked against `updated` before it is returned — object members
|
|
49
|
+
* compared without regard to order, array items with — so a result that would
|
|
50
|
+
* say anything else is discarded in favour of `updated` itself. That is also
|
|
51
|
+
* what happens when either document will not parse. Calling this is never worse
|
|
52
|
+
* than not.
|
|
53
|
+
*
|
|
54
|
+
* @param original - The document as it stands.
|
|
55
|
+
* @param updated - The same document as the serializer would write it now.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const onDisk = await readFile("approval.form", "utf8");
|
|
60
|
+
* const { json } = preserveJsonFormatting(onDisk, Form.export(edited));
|
|
61
|
+
* // Renaming one label changes one line, whatever indentation the file uses.
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function preserveJsonFormatting(original: string, updated: string): PreservedJson;
|
|
65
|
+
//# sourceMappingURL=json-patch.d.ts.map
|