@sentropic/diagram-core 0.1.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.
Files changed (42) hide show
  1. package/README.md +164 -1
  2. package/dist/bindings.js +1 -0
  3. package/dist/chain-profile.d.ts +4 -0
  4. package/dist/chain-profile.js +85 -0
  5. package/dist/chain.d.ts +11 -0
  6. package/dist/chain.js +284 -0
  7. package/dist/commands.js +5 -3
  8. package/dist/diagnostics.d.ts +20 -4
  9. package/dist/erd-validate.d.ts +5 -0
  10. package/dist/erd-validate.js +33 -0
  11. package/dist/erd.d.ts +69 -0
  12. package/dist/erd.js +72 -0
  13. package/dist/flows.d.ts +36 -0
  14. package/dist/flows.js +144 -0
  15. package/dist/fold.d.ts +0 -9
  16. package/dist/fold.js +16 -19
  17. package/dist/index.d.ts +7 -2
  18. package/dist/index.js +7 -2
  19. package/dist/layout-hints.d.ts +158 -0
  20. package/dist/layout-hints.js +459 -0
  21. package/dist/notation.d.ts +121 -0
  22. package/dist/notation.js +225 -0
  23. package/dist/presentation-relations.d.ts +4 -0
  24. package/dist/presentation-relations.js +17 -0
  25. package/dist/profile.d.ts +39 -0
  26. package/dist/profile.js +2 -0
  27. package/dist/profiles/erd.d.ts +6 -0
  28. package/dist/profiles/erd.js +29 -0
  29. package/dist/profiles/index.d.ts +1 -0
  30. package/dist/profiles/index.js +5 -0
  31. package/dist/relation-types.d.ts +6 -0
  32. package/dist/relation-types.js +16 -0
  33. package/dist/validate.d.ts +0 -13
  34. package/dist/validate.js +63 -18
  35. package/dist/view-schema-pin.d.ts +9 -6
  36. package/dist/view-schema-pin.js +17 -7
  37. package/dist/view.d.ts +12 -3
  38. package/package.json +8 -3
  39. package/schemas/diagram-view-schema-3.json +1 -0
  40. package/schemas/diagram-view-schema-3.sha256 +1 -0
  41. package/schemas/ds-layout-hints-1.json +1 -0
  42. package/schemas/ds-layout-hints-1.sha256 +1 -0
@@ -0,0 +1,121 @@
1
+ /**
2
+ * `diagram-notation@1` — the closed notation vocabulary and its pin.
3
+ *
4
+ * A profile maps its types onto this vocabulary (which role draws an entity
5
+ * type, which encoding draws a relation type). The vocabulary is DS-owned;
6
+ * the mapping is profile data and holds no place here.
7
+ *
8
+ * Two layers, both data, both pinned:
9
+ * - `DIAGRAM_NOTATION_SCHEMA` JSON Schema 2020-12, structural only: closed
10
+ * objects, enums, string bounds, required `role`, `nature`, `encoding`,
11
+ * slot shape.
12
+ * - `DIAGRAM_NOTATION_RULES` every conditional the schema does not state:
13
+ * the role table, the variants of each nature, the property list of each
14
+ * encoding, slot ownership.
15
+ *
16
+ * `DIAGRAM_NOTATION_PIN.contentDigest` is the SHA-256 of the RFC 8785 bytes of
17
+ * `{ schema, rules }`. Any change to either is `diagram-notation@2`.
18
+ *
19
+ * NOT here: `validateNotation`, `validateViewNotation` and `resolveNotation`.
20
+ * This module freezes the vocabulary a consumer pins; the executor that reads
21
+ * it is a later lot, and until it ships nothing in this package enforces the
22
+ * rules below.
23
+ */
24
+ import type { PresentationPin } from "./presentation.js";
25
+ export declare const DIAGRAM_NOTATION_VOCABULARY: "diagram-notation@1";
26
+ export declare const DIAGRAM_NOTATION_MODES: readonly ["strict", "metadata"];
27
+ export declare const DIAGRAM_NOTATION_ROLES: readonly ["card", "container", "lane", "entity-table", "flow-node"];
28
+ export declare const DIAGRAM_NOTATION_NATURES: readonly ["component", "responsibility", "data", "activity"];
29
+ export declare const DIAGRAM_NOTATION_VARIANTS: readonly ["task", "start", "end", "decision", "subprocess", "data", "document", "participant"];
30
+ export declare const DIAGRAM_NOTATION_ENCODINGS: readonly ["arrow", "containment", "detail", "footer"];
31
+ export declare const DIAGRAM_NOTATION_ENDS: readonly ["none", "arrow", "cardinality"];
32
+ export type NotationMode = (typeof DIAGRAM_NOTATION_MODES)[number];
33
+ export type NotationRole = (typeof DIAGRAM_NOTATION_ROLES)[number];
34
+ export type NotationNature = (typeof DIAGRAM_NOTATION_NATURES)[number];
35
+ export type NotationVariant = (typeof DIAGRAM_NOTATION_VARIANTS)[number];
36
+ export type NotationEncoding = (typeof DIAGRAM_NOTATION_ENCODINGS)[number];
37
+ export type NotationEnds = (typeof DIAGRAM_NOTATION_ENDS)[number];
38
+ /** A slot is a literal text, or a lookup on an attribute of the instance. */
39
+ export type NotationSlot = string | {
40
+ readonly attribute: string;
41
+ readonly values: Readonly<Record<string, string>>;
42
+ readonly default: string;
43
+ };
44
+ export interface NotationTypeRef {
45
+ readonly profile: string;
46
+ readonly type: string;
47
+ }
48
+ export interface NotationNode {
49
+ readonly role: NotationRole;
50
+ readonly nature: NotationNature;
51
+ readonly variant?: NotationSlot;
52
+ readonly icon?: NotationSlot;
53
+ readonly kicker?: NotationSlot;
54
+ /** Roles of DIRECT containment children. */
55
+ readonly holds?: readonly NotationRole[];
56
+ }
57
+ export interface NotationRelation {
58
+ readonly encoding: NotationEncoding;
59
+ readonly ends?: NotationEnds;
60
+ readonly provisional?: {
61
+ readonly attribute: string;
62
+ readonly equals: string;
63
+ };
64
+ readonly lift?: {
65
+ readonly via: NotationTypeRef;
66
+ readonly ancestors: readonly NotationTypeRef[];
67
+ };
68
+ readonly fallback?: {
69
+ readonly encoding: "detail" | "footer";
70
+ readonly on: string;
71
+ readonly label: string;
72
+ };
73
+ readonly on?: string;
74
+ readonly label?: string;
75
+ }
76
+ export interface NotationBlock {
77
+ readonly vocabulary: typeof DIAGRAM_NOTATION_VOCABULARY;
78
+ readonly mode?: NotationMode;
79
+ readonly entityTypes: Readonly<Record<string, NotationNode>>;
80
+ readonly relationTypes: Readonly<Record<string, NotationRelation>>;
81
+ }
82
+ /** How a role treats one slot. `participant-only`: admitted when the effective variant is `participant`. */
83
+ export type NotationSlotRule = "required" | "optional" | "refused" | "participant-only";
84
+ export interface NotationRoleRule {
85
+ readonly natures: readonly NotationNature[];
86
+ readonly icon: NotationSlotRule;
87
+ readonly kicker: NotationSlotRule;
88
+ /** `by-nature`: the variant is one of `variants[nature]`. */
89
+ readonly variant: "refused" | "by-nature";
90
+ /** Roles a type of this role may list in `holds`. */
91
+ readonly holds: readonly NotationRole[];
92
+ /** When set, `holds` counts only for this effective variant. */
93
+ readonly holdsEffectiveFor?: NotationVariant;
94
+ }
95
+ export interface DiagramNotationRules {
96
+ readonly vocabulary: typeof DIAGRAM_NOTATION_VOCABULARY;
97
+ readonly defaultMode: NotationMode;
98
+ readonly roles: Readonly<Record<NotationRole, NotationRoleRule>>;
99
+ readonly variants: Readonly<Record<NotationNature, readonly NotationVariant[]>>;
100
+ readonly iconPattern: string;
101
+ readonly encodings: Readonly<Record<NotationEncoding, {
102
+ readonly properties: readonly string[];
103
+ readonly required: readonly string[];
104
+ }>>;
105
+ readonly endsDefault: {
106
+ readonly directed: NotationEnds;
107
+ readonly undirected: NotationEnds;
108
+ };
109
+ readonly slotOwners: Readonly<Record<"detail" | "footer", readonly NotationRole[]>>;
110
+ readonly liftAncestorRoles: readonly NotationRole[];
111
+ readonly containmentHierarchyShape: "tree";
112
+ }
113
+ /** The structural JSON Schema of a `diagram-notation@1` block, deeply frozen. */
114
+ export declare const DIAGRAM_NOTATION_SCHEMA: Readonly<Record<string, unknown>>;
115
+ /** The semantic rules of `diagram-notation@1`, as data, deeply frozen. */
116
+ export declare const DIAGRAM_NOTATION_RULES: DiagramNotationRules;
117
+ /** SHA-256 (64 lowercase hex) of the RFC 8785 bytes of `{ schema, rules }`. */
118
+ export declare const DIAGRAM_NOTATION_DIGEST: string;
119
+ /** The pin of the notation vocabulary. Equality is equality of the three fields. */
120
+ export declare const DIAGRAM_NOTATION_PIN: PresentationPin;
121
+ //# sourceMappingURL=notation.d.ts.map
@@ -0,0 +1,225 @@
1
+ /**
2
+ * `diagram-notation@1` — the closed notation vocabulary and its pin.
3
+ *
4
+ * A profile maps its types onto this vocabulary (which role draws an entity
5
+ * type, which encoding draws a relation type). The vocabulary is DS-owned;
6
+ * the mapping is profile data and holds no place here.
7
+ *
8
+ * Two layers, both data, both pinned:
9
+ * - `DIAGRAM_NOTATION_SCHEMA` JSON Schema 2020-12, structural only: closed
10
+ * objects, enums, string bounds, required `role`, `nature`, `encoding`,
11
+ * slot shape.
12
+ * - `DIAGRAM_NOTATION_RULES` every conditional the schema does not state:
13
+ * the role table, the variants of each nature, the property list of each
14
+ * encoding, slot ownership.
15
+ *
16
+ * `DIAGRAM_NOTATION_PIN.contentDigest` is the SHA-256 of the RFC 8785 bytes of
17
+ * `{ schema, rules }`. Any change to either is `diagram-notation@2`.
18
+ *
19
+ * NOT here: `validateNotation`, `validateViewNotation` and `resolveNotation`.
20
+ * This module freezes the vocabulary a consumer pins; the executor that reads
21
+ * it is a later lot, and until it ships nothing in this package enforces the
22
+ * rules below.
23
+ */
24
+ import { canonicalBytes, sha256Hex } from "./sha256.js";
25
+ export const DIAGRAM_NOTATION_VOCABULARY = "diagram-notation@1";
26
+ export const DIAGRAM_NOTATION_MODES = ["strict", "metadata"];
27
+ export const DIAGRAM_NOTATION_ROLES = ["card", "container", "lane", "entity-table", "flow-node"];
28
+ export const DIAGRAM_NOTATION_NATURES = ["component", "responsibility", "data", "activity"];
29
+ export const DIAGRAM_NOTATION_VARIANTS = ["task", "start", "end", "decision", "subprocess", "data", "document", "participant"];
30
+ export const DIAGRAM_NOTATION_ENCODINGS = ["arrow", "containment", "detail", "footer"];
31
+ export const DIAGRAM_NOTATION_ENDS = ["none", "arrow", "cardinality"];
32
+ const TEXT = { type: "string", minLength: 1, maxLength: 40 };
33
+ const NAME = { type: "string", minLength: 1, maxLength: 80 };
34
+ const PRIVATE_SCHEMA = {
35
+ $schema: "https://json-schema.org/draft/2020-12/schema",
36
+ $id: "engram:diagram-notation-schema/1",
37
+ title: "diagram-notation@1 block",
38
+ type: "object",
39
+ properties: {
40
+ vocabulary: { const: DIAGRAM_NOTATION_VOCABULARY },
41
+ mode: { enum: [...DIAGRAM_NOTATION_MODES] },
42
+ entityTypes: { type: "object", additionalProperties: { $ref: "#/$defs/node" } },
43
+ relationTypes: { type: "object", additionalProperties: { $ref: "#/$defs/relation" } },
44
+ },
45
+ required: ["vocabulary", "entityTypes", "relationTypes"],
46
+ additionalProperties: false,
47
+ $defs: {
48
+ text: TEXT,
49
+ name: NAME,
50
+ role: { enum: [...DIAGRAM_NOTATION_ROLES] },
51
+ nature: { enum: [...DIAGRAM_NOTATION_NATURES] },
52
+ slot: {
53
+ anyOf: [
54
+ { $ref: "#/$defs/text" },
55
+ {
56
+ type: "object",
57
+ properties: {
58
+ attribute: { $ref: "#/$defs/name" },
59
+ values: { type: "object", maxProperties: 32, additionalProperties: { $ref: "#/$defs/text" } },
60
+ default: { $ref: "#/$defs/text" },
61
+ },
62
+ required: ["attribute", "values", "default"],
63
+ additionalProperties: false,
64
+ },
65
+ ],
66
+ },
67
+ typeRef: {
68
+ type: "object",
69
+ properties: { profile: { $ref: "#/$defs/name" }, type: { $ref: "#/$defs/name" } },
70
+ required: ["profile", "type"],
71
+ additionalProperties: false,
72
+ },
73
+ node: {
74
+ type: "object",
75
+ properties: {
76
+ role: { $ref: "#/$defs/role" },
77
+ nature: { $ref: "#/$defs/nature" },
78
+ variant: { $ref: "#/$defs/slot" },
79
+ icon: { $ref: "#/$defs/slot" },
80
+ kicker: { $ref: "#/$defs/slot" },
81
+ holds: { type: "array", items: { $ref: "#/$defs/role" }, uniqueItems: true },
82
+ },
83
+ required: ["role", "nature"],
84
+ additionalProperties: false,
85
+ },
86
+ relation: {
87
+ type: "object",
88
+ properties: {
89
+ encoding: { enum: [...DIAGRAM_NOTATION_ENCODINGS] },
90
+ ends: { enum: [...DIAGRAM_NOTATION_ENDS] },
91
+ provisional: {
92
+ type: "object",
93
+ properties: { attribute: { $ref: "#/$defs/name" }, equals: { $ref: "#/$defs/text" } },
94
+ required: ["attribute", "equals"],
95
+ additionalProperties: false,
96
+ },
97
+ lift: {
98
+ type: "object",
99
+ properties: {
100
+ via: { $ref: "#/$defs/typeRef" },
101
+ ancestors: { type: "array", minItems: 1, items: { $ref: "#/$defs/typeRef" } },
102
+ },
103
+ required: ["via", "ancestors"],
104
+ additionalProperties: false,
105
+ },
106
+ fallback: {
107
+ type: "object",
108
+ properties: {
109
+ encoding: { enum: ["detail", "footer"] },
110
+ on: { $ref: "#/$defs/name" },
111
+ label: { $ref: "#/$defs/text" },
112
+ },
113
+ required: ["encoding", "on", "label"],
114
+ additionalProperties: false,
115
+ },
116
+ on: { $ref: "#/$defs/name" },
117
+ label: { $ref: "#/$defs/text" },
118
+ },
119
+ required: ["encoding"],
120
+ additionalProperties: false,
121
+ },
122
+ },
123
+ };
124
+ const PRIVATE_RULES = {
125
+ vocabulary: DIAGRAM_NOTATION_VOCABULARY,
126
+ defaultMode: "strict",
127
+ roles: {
128
+ card: {
129
+ natures: ["component"],
130
+ icon: "required",
131
+ kicker: "optional",
132
+ variant: "refused",
133
+ holds: ["card", "entity-table", "flow-node"],
134
+ },
135
+ container: {
136
+ natures: ["component"],
137
+ icon: "required",
138
+ kicker: "optional",
139
+ variant: "refused",
140
+ holds: ["card", "container", "entity-table", "lane", "flow-node"],
141
+ },
142
+ lane: {
143
+ natures: ["responsibility"],
144
+ icon: "refused",
145
+ kicker: "refused",
146
+ variant: "refused",
147
+ holds: ["flow-node", "lane"],
148
+ },
149
+ "entity-table": {
150
+ natures: ["data"],
151
+ icon: "optional",
152
+ kicker: "refused",
153
+ variant: "refused",
154
+ holds: [],
155
+ },
156
+ "flow-node": {
157
+ natures: ["activity", "data", "responsibility"],
158
+ icon: "participant-only",
159
+ kicker: "refused",
160
+ variant: "by-nature",
161
+ holds: ["flow-node"],
162
+ holdsEffectiveFor: "subprocess",
163
+ },
164
+ },
165
+ /** Variants of each nature; the first is the default. `component` has none. */
166
+ variants: {
167
+ activity: ["task", "start", "end", "decision", "subprocess"],
168
+ data: ["data", "document"],
169
+ responsibility: ["participant"],
170
+ component: [],
171
+ },
172
+ /** Glyph id grammar of an `icon` text. The glyph inventory is not part of the pin. */
173
+ iconPattern: "^[a-z][a-z0-9-]{0,39}$",
174
+ /** The properties each encoding admits, `encoding` included; `required` among them. */
175
+ encodings: {
176
+ arrow: { properties: ["encoding", "ends", "provisional"], required: ["encoding"] },
177
+ containment: { properties: ["encoding", "lift", "fallback"], required: ["encoding"] },
178
+ detail: { properties: ["encoding", "on", "label"], required: ["encoding", "on", "label"] },
179
+ footer: { properties: ["encoding", "on", "label"], required: ["encoding", "on", "label"] },
180
+ },
181
+ /** `ends` when absent: `arrow` on a directed relation type, else `none`. */
182
+ endsDefault: { directed: "arrow", undirected: "none" },
183
+ /** Roles that own each text slot: every type allowed on the `on` endpoint must have one of them. */
184
+ slotOwners: {
185
+ detail: ["card", "container", "entity-table"],
186
+ footer: ["card", "container"],
187
+ },
188
+ /** Roles a `lift.ancestors` type must have. */
189
+ liftAncestorRoles: ["card", "container"],
190
+ /** `containment` needs a relation type whose hierarchy has this shape. */
191
+ containmentHierarchyShape: "tree",
192
+ };
193
+ function deepClone(value) {
194
+ if (value === null || typeof value !== "object")
195
+ return value;
196
+ if (Array.isArray(value))
197
+ return value.map((item) => deepClone(item));
198
+ const out = {};
199
+ for (const key of Object.keys(value)) {
200
+ out[key] = deepClone(value[key]);
201
+ }
202
+ return out;
203
+ }
204
+ function deepFreeze(value) {
205
+ if (value === null || typeof value !== "object" || Object.isFrozen(value))
206
+ return value;
207
+ for (const child of Object.values(value))
208
+ deepFreeze(child);
209
+ return Object.freeze(value);
210
+ }
211
+ deepFreeze(PRIVATE_SCHEMA);
212
+ deepFreeze(PRIVATE_RULES);
213
+ /** The structural JSON Schema of a `diagram-notation@1` block, deeply frozen. */
214
+ export const DIAGRAM_NOTATION_SCHEMA = deepFreeze(deepClone(PRIVATE_SCHEMA));
215
+ /** The semantic rules of `diagram-notation@1`, as data, deeply frozen. */
216
+ export const DIAGRAM_NOTATION_RULES = deepFreeze(deepClone(PRIVATE_RULES));
217
+ /** SHA-256 (64 lowercase hex) of the RFC 8785 bytes of `{ schema, rules }`. */
218
+ export const DIAGRAM_NOTATION_DIGEST = sha256Hex(canonicalBytes({ schema: PRIVATE_SCHEMA, rules: PRIVATE_RULES }));
219
+ /** The pin of the notation vocabulary. Equality is equality of the three fields. */
220
+ export const DIAGRAM_NOTATION_PIN = deepFreeze({
221
+ id: "diagram-notation",
222
+ version: "1",
223
+ contentDigest: DIAGRAM_NOTATION_DIGEST,
224
+ });
225
+ //# sourceMappingURL=notation.js.map
@@ -0,0 +1,4 @@
1
+ /** Resolve document relation refinements at the boundary of the frozen presentation adapter. */
2
+ import { validateDiagramPresentation as validatePinnedPresentation } from "./presentation-validate.js";
3
+ export declare function validateDiagramPresentation(...args: Parameters<typeof validatePinnedPresentation>): ReturnType<typeof validatePinnedPresentation>;
4
+ //# sourceMappingURL=presentation-relations.d.ts.map
@@ -0,0 +1,17 @@
1
+ /** Resolve document relation refinements at the boundary of the frozen presentation adapter. */
2
+ import { validateDiagramPresentation as validatePinnedPresentation } from "./presentation-validate.js";
3
+ import { relationBaseType } from "./relation-types.js";
4
+ export function validateDiagramPresentation(...args) {
5
+ const [document, view, options] = args;
6
+ let changed = false;
7
+ const relations = Object.fromEntries(Object.entries(document.relations).map(([id, relation]) => {
8
+ const profile = options.registry.get(relation.profile);
9
+ const type = profile === undefined ? relation.type : relationBaseType(document, profile, relation);
10
+ if (type === relation.type)
11
+ return [id, relation];
12
+ changed = true;
13
+ return [id, { ...relation, type }];
14
+ }));
15
+ return validatePinnedPresentation(changed ? { ...document, relations } : document, view, options);
16
+ }
17
+ //# sourceMappingURL=presentation-relations.js.map
package/dist/profile.d.ts CHANGED
@@ -32,6 +32,7 @@ export interface EntityTypeDeclaration {
32
32
  * or token field is added here: those live in the view/presentation contract.
33
33
  */
34
34
  readonly container?: boolean;
35
+ readonly foldable?: boolean;
35
36
  /** K1 base types, in declaration order (depth-first, left-to-right). */
36
37
  readonly supertypes?: readonly string[];
37
38
  }
@@ -156,6 +157,9 @@ export type AddedConstraint = {
156
157
  readonly attribute: string;
157
158
  };
158
159
  export type ProfileConstraint = {
160
+ readonly kind: "erd-keys";
161
+ readonly maxFields: number;
162
+ } | {
159
163
  readonly kind: "acyclic-hierarchy";
160
164
  readonly hierarchyId: string;
161
165
  } | {
@@ -174,6 +178,40 @@ export interface ProfileLimits {
174
178
  readonly maxRelations?: number;
175
179
  readonly maxEndpointsPerRelation?: number;
176
180
  }
181
+ /** Pure DATA consumed by the document-only endpoint provenance evaluator. */
182
+ export interface ChainConstraint {
183
+ readonly attribute: string;
184
+ readonly equals: string | boolean;
185
+ }
186
+ export interface ChainStep {
187
+ readonly relationTypes: readonly string[];
188
+ readonly direction: "forward" | "inverse";
189
+ readonly repeat: "one" | "zeroOrMore" | "oneOrMore";
190
+ }
191
+ export interface ChainPath {
192
+ readonly steps: readonly ChainStep[];
193
+ readonly endTypes: readonly string[];
194
+ readonly endConstraints?: readonly ChainConstraint[];
195
+ }
196
+ export interface ChainAggregation {
197
+ readonly memberRelationTypes: readonly string[];
198
+ readonly memberTargetChain: ChainPath;
199
+ readonly memberSourceChain: ChainPath;
200
+ /** Fixed UTF-16 tuple order; never a locale-dependent comparator. */
201
+ readonly sort?: "sourceId,targetId,relationId";
202
+ }
203
+ export interface ChainPredicate {
204
+ readonly id: string;
205
+ readonly appliesTo: {
206
+ readonly relationTypes: readonly string[];
207
+ readonly roles: readonly string[];
208
+ readonly startTypes: readonly string[];
209
+ };
210
+ readonly startConstraints?: readonly ChainConstraint[];
211
+ readonly alternatives: readonly ChainPath[];
212
+ readonly selection: "unique" | "ordered" | "first-drawn" | "aggregate";
213
+ readonly aggregation?: ChainAggregation;
214
+ }
177
215
  export interface Profile {
178
216
  readonly id: ProfileId;
179
217
  readonly name: string;
@@ -184,6 +222,7 @@ export interface Profile {
184
222
  readonly relationTypes: readonly RelationTypeDeclaration[];
185
223
  readonly constraints: readonly ProfileConstraint[];
186
224
  readonly limits: ProfileLimits;
225
+ readonly chainPredicates?: readonly ChainPredicate[];
187
226
  /** Declared limits, in prose, for a human reading a skeleton profile. */
188
227
  readonly notes: readonly string[];
189
228
  }
package/dist/profile.js CHANGED
@@ -16,6 +16,7 @@
16
16
  */
17
17
  import { stableStringify } from "./bindings.js";
18
18
  import { diagnostic } from "./diagnostics.js";
19
+ import { validateChainPredicates } from "./chain-profile.js";
19
20
  export function createProfileRegistry(profiles) {
20
21
  const byId = new Map();
21
22
  for (const profile of profiles) {
@@ -119,6 +120,7 @@ export function validateProfile(profile, adapter = "legacy-constraints@1") {
119
120
  // checks below; the retained native run ignores them exactly as before.
120
121
  }
121
122
  diagnostics.push(...validateM3Declarations(profile, seenEntityTypes, adapter));
123
+ diagnostics.push(...validateChainPredicates(profile));
122
124
  return diagnostics;
123
125
  }
124
126
  /**
@@ -0,0 +1,6 @@
1
+ import type { Profile } from '../profile.js';
2
+ export declare const ERD_PROFILE_ID: "erd@1";
3
+ export declare const ERD_CARDINALITIES: readonly ["1", "0..1", "1..n", "0..n"];
4
+ export type ErdCardinality = typeof ERD_CARDINALITIES[number];
5
+ export declare const erdProfile: Profile;
6
+ //# sourceMappingURL=erd.d.ts.map
@@ -0,0 +1,29 @@
1
+ export const ERD_PROFILE_ID = 'erd@1';
2
+ export const ERD_CARDINALITIES = ['1', '0..1', '1..n', '0..n'];
3
+ export const erdProfile = {
4
+ id: ERD_PROFILE_ID, name: 'ERD', version: 1, completeness: 'complete',
5
+ entityTypes: [{ id: 'entity', label: 'Entity', foldable: true, attributes: [
6
+ { name: 'name', kind: 'text', required: true }, { name: 'schema', kind: 'text' },
7
+ ] }],
8
+ portTypes: [{ id: 'field', label: 'Attribute row', directions: ['inout'], attributes: [
9
+ { name: 'dataType', kind: 'text', required: true },
10
+ { name: 'pk', kind: 'boolean', required: true },
11
+ { name: 'fk', kind: 'reference', refKind: 'port' },
12
+ { name: 'nullable', kind: 'boolean', required: true },
13
+ { name: 'ordinal', kind: 'quantity', units: ['index'], integer: true, min: 0, required: true },
14
+ ] }],
15
+ relationTypes: [{ id: 'relationship', label: 'Relationship', direction: 'undirected',
16
+ roles: ['from', 'to'].map(role => ({ role, cardinality: { min: 1, max: 1 }, targets: ['entity', 'port'] })),
17
+ attributes: [
18
+ { name: 'name', kind: 'text', required: true }, { name: 'label', kind: 'text' },
19
+ ...['from', 'to'].flatMap(end => [
20
+ { name: end + 'Cardinality', kind: 'enum', values: ERD_CARDINALITIES, required: true },
21
+ { name: end + 'Role', kind: 'text', required: true },
22
+ ]),
23
+ ],
24
+ }],
25
+ constraints: [{ kind: 'erd-keys', maxFields: 17 }],
26
+ limits: { maxEntities: 1000, maxRelations: 10000, maxEndpointsPerRelation: 2 },
27
+ notes: ['Exactly one primary key per entity; no composite keys. Many-to-many remains one relationship.'],
28
+ };
29
+ //# sourceMappingURL=erd.js.map
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import { type ExecutorProfileBindings } from "../bindings.js";
10
10
  import { type Profile, type ProfileRegistry } from "../profile.js";
11
+ export * from "./erd.js";
11
12
  export * from "./generic.js";
12
13
  export * from "./generic2.js";
13
14
  export * from "./skeletons.js";
@@ -8,11 +8,13 @@
8
8
  */
9
9
  import { embeddedExecutorBindings } from "../bindings.js";
10
10
  import { createProfileRegistry } from "../profile.js";
11
+ import { erdProfile } from "./erd.js";
11
12
  import { genericProfile } from "./generic.js";
12
13
  import { generic2Profile } from "./generic2.js";
13
14
  import { archimateSkeletonProfile, bpmnSkeletonProfile, umlSkeletonProfile } from "./skeletons.js";
14
15
  import { archimate2Profile } from "./archimate2.js";
15
16
  import { uml2Profile } from "./uml2.js";
17
+ export * from "./erd.js";
16
18
  export * from "./generic.js";
17
19
  export * from "./generic2.js";
18
20
  export * from "./skeletons.js";
@@ -37,6 +39,7 @@ export const m3ProfileRegistry = createProfileRegistry([
37
39
  generic2Profile,
38
40
  archimate2Profile,
39
41
  uml2Profile,
42
+ erdProfile,
40
43
  ]);
41
44
  /** All six @1/@2 ids for coexistence and reload witnesses (§3.13.2). */
42
45
  export const allProfilesRegistry = createProfileRegistry([
@@ -45,6 +48,7 @@ export const allProfilesRegistry = createProfileRegistry([
45
48
  generic2Profile,
46
49
  archimate2Profile,
47
50
  uml2Profile,
51
+ erdProfile,
48
52
  ]);
49
53
  /**
50
54
  * The shipped `executor-profile-bindings@1` table (M3 §5.3.1): one verifying
@@ -72,6 +76,7 @@ export const shippedExecutorBindings = lazyBindings([
72
76
  generic2Profile,
73
77
  archimate2Profile,
74
78
  uml2Profile,
79
+ erdProfile,
75
80
  ]);
76
81
  /**
77
82
  * The packaged verified default rows for exactly the four retained @1
@@ -0,0 +1,6 @@
1
+ /** Document-local relation refinements inherit the complete relation declaration. */
2
+ import type { Relation, SemanticDocument } from "./document.js";
3
+ import { type Profile, type RelationTypeDeclaration } from "./profile.js";
4
+ export declare function relationBaseType(document: SemanticDocument, profile: Profile, relation: Relation): string;
5
+ export declare function relationSchema(document: SemanticDocument, profile: Profile, relation: Relation): RelationTypeDeclaration | undefined;
6
+ //# sourceMappingURL=relation-types.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { relationTypeOf } from "./profile.js";
2
+ export function relationBaseType(document, profile, relation) {
3
+ if (relationTypeOf(profile, relation.type) !== undefined)
4
+ return relation.type;
5
+ const definition = document.typeDefinitions[relation.type];
6
+ return definition?.profile === profile.id ? definition.baseType : relation.type;
7
+ }
8
+ export function relationSchema(document, profile, relation) {
9
+ const base = relationTypeOf(profile, relationBaseType(document, profile, relation));
10
+ if (base === undefined)
11
+ return undefined;
12
+ const definition = document.typeDefinitions[relation.type];
13
+ return relation.type === base.id || definition?.profile !== profile.id
14
+ ? base : { ...base, attributes: [...(base.attributes ?? []), ...definition.attributes] };
15
+ }
16
+ //# sourceMappingURL=relation-types.js.map
@@ -1,16 +1,3 @@
1
- /**
2
- * Validation: the only place that decides whether a document or a view is
3
- * writable, and the only producer of the nine named rejected cases.
4
- *
5
- * Three rules it follows without exception:
6
- * 1. It never repairs. A document is refused with diagnostics, never
7
- * "cleaned up" - a silently dropped dangling edge is what study invariant 1
8
- * forbids at the semantic level.
9
- * 2. It reads nothing ambient. Types, roles, cardinalities, constraints and
10
- * limits come from the profile registry handed to it.
11
- * 3. It collects. A caller gets every diagnostic of a run, not the first, so a
12
- * refused transaction can be explained in one pass.
13
- */
14
1
  import { type AttributeSchema } from "./attributes.js";
15
2
  import { type ExecutorProfileBindings } from "./bindings.js";
16
3
  import { type Diagnostic } from "./diagnostics.js";