@sentropic/diagram-core 0.1.0 → 0.2.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/README.md +67 -0
- package/dist/bindings.js +1 -0
- package/dist/chain-profile.d.ts +4 -0
- package/dist/chain-profile.js +85 -0
- package/dist/chain.d.ts +11 -0
- package/dist/chain.js +284 -0
- package/dist/commands.js +5 -3
- package/dist/diagnostics.d.ts +3 -3
- package/dist/erd-validate.d.ts +5 -0
- package/dist/erd-validate.js +33 -0
- package/dist/erd.d.ts +69 -0
- package/dist/erd.js +72 -0
- package/dist/flows.d.ts +36 -0
- package/dist/flows.js +144 -0
- package/dist/fold.d.ts +0 -9
- package/dist/fold.js +16 -19
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/presentation-relations.d.ts +4 -0
- package/dist/presentation-relations.js +17 -0
- package/dist/profile.d.ts +39 -0
- package/dist/profile.js +2 -0
- package/dist/profiles/erd.d.ts +6 -0
- package/dist/profiles/erd.js +29 -0
- package/dist/profiles/index.d.ts +1 -0
- package/dist/profiles/index.js +5 -0
- package/dist/relation-types.d.ts +6 -0
- package/dist/relation-types.js +16 -0
- package/dist/validate.d.ts +0 -13
- package/dist/validate.js +63 -18
- package/dist/view-schema-pin.d.ts +9 -6
- package/dist/view-schema-pin.js +17 -7
- package/dist/view.d.ts +12 -3
- package/package.json +6 -3
- package/schemas/diagram-view-schema-3.json +1 -0
- package/schemas/diagram-view-schema-3.sha256 +1 -0
package/dist/validate.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { relationBaseType, relationSchema } from "./relation-types.js";
|
|
1
2
|
/**
|
|
2
3
|
* Validation: the only place that decides whether a document or a view is
|
|
3
4
|
* writable, and the only producer of the nine named rejected cases.
|
|
@@ -11,10 +12,12 @@
|
|
|
11
12
|
* 3. It collects. A caller gets every diagnostic of a run, not the first, so a
|
|
12
13
|
* refused transaction can be explained in one pass.
|
|
13
14
|
*/
|
|
15
|
+
import { validateErdKeys } from "./erd-validate.js";
|
|
14
16
|
import { referencesOf, validateAttributeValue, } from "./attributes.js";
|
|
15
17
|
import { adapterFor, isRetainedLegacyProfileId, LEGACY_CONSTRAINTS_ADAPTER, verifyExecutorBindings, } from "./bindings.js";
|
|
16
18
|
import { retainedExecutorBindings } from "./profiles/index.js";
|
|
17
19
|
import { tryCanonicalise } from "./canonical.js";
|
|
20
|
+
import { createChainValidator } from "./chain.js";
|
|
18
21
|
import { diagnostic } from "./diagnostics.js";
|
|
19
22
|
import { CURRENT_SCHEMA_VERSION, scopeTargetOf, } from "./document.js";
|
|
20
23
|
import { hashContent } from "./hash.js";
|
|
@@ -22,7 +25,7 @@ import { entityTypeOf, portTypeOf, qualifyAttributeSchema, relationTypeOf, roleO
|
|
|
22
25
|
import { parseRef, refKindOf, } from "./refs.js";
|
|
23
26
|
import { createTypeResolver } from "./resolver.js";
|
|
24
27
|
import { DIAGRAM_PRESENTATION_PROFILE_ID } from "./presentation.js";
|
|
25
|
-
import { validateDiagramPresentation } from "./presentation-
|
|
28
|
+
import { validateDiagramPresentation } from "./presentation-relations.js";
|
|
26
29
|
import { analyzeSummaries, classifyInternalRelations, collapsedOf, drawnTargetOf, hiddenByFold, parentOccurrenceOf, portRepresentativeOf, representativeOf, } from "./fold.js";
|
|
27
30
|
/** Base type attributes plus the additive attributes of a document type definition. */
|
|
28
31
|
export function effectiveEntitySchemas(document, profile, typeId) {
|
|
@@ -326,7 +329,7 @@ function validateRelation(relation, key, document, options, resolver, adapter =
|
|
|
326
329
|
const profile = declaredProfile(document, relation.profile, options, path);
|
|
327
330
|
if ("diagnostic" in profile)
|
|
328
331
|
return [...diagnostics, profile.diagnostic];
|
|
329
|
-
const declared =
|
|
332
|
+
const declared = relationSchema(document, profile.profile, relation);
|
|
330
333
|
if (declared === undefined) {
|
|
331
334
|
diagnostics.push(diagnostic({
|
|
332
335
|
code: "unknown-relation-type",
|
|
@@ -470,7 +473,7 @@ function validateHierarchies(document, relationTypes) {
|
|
|
470
473
|
const childToParents = new Map();
|
|
471
474
|
const children = new Map();
|
|
472
475
|
for (const relation of Object.values(document.relations)) {
|
|
473
|
-
if (relation.profile !== profile || relation.type !== declaration.id)
|
|
476
|
+
if (relation.profile !== profile || (document.typeDefinitions[relation.type]?.baseType ?? relation.type) !== declaration.id)
|
|
474
477
|
continue;
|
|
475
478
|
const parents = relation.endpoints.filter((endpoint) => endpoint.role === hierarchy.parentRole);
|
|
476
479
|
const kids = relation.endpoints.filter((endpoint) => endpoint.role === hierarchy.childRole);
|
|
@@ -534,6 +537,10 @@ function validateConstraints(document, profile, options, resolver, adapter) {
|
|
|
534
537
|
const diagnostics = [];
|
|
535
538
|
const entities = Object.values(document.entities).filter((entity) => entity.profile === profile.id);
|
|
536
539
|
for (const constraint of profile.constraints) {
|
|
540
|
+
if (constraint.kind === "erd-keys") {
|
|
541
|
+
diagnostics.push(...validateErdKeys(document, profile, constraint.maxFields));
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
537
544
|
if (constraint.kind === "acyclic-hierarchy")
|
|
538
545
|
continue; // handled by validateHierarchies
|
|
539
546
|
if (adapter !== LEGACY_CONSTRAINTS_ADAPTER && resolver !== undefined && isAddedConstraint(constraint)) {
|
|
@@ -639,7 +646,7 @@ function indexHierarchy(document, profile, hierarchyId) {
|
|
|
639
646
|
for (const declaration of declarations) {
|
|
640
647
|
const hierarchy = declaration.hierarchy;
|
|
641
648
|
for (const relation of Object.values(document.relations)) {
|
|
642
|
-
if (relation.profile !== profile.id || relation.type !== declaration.id)
|
|
649
|
+
if (relation.profile !== profile.id || (document.typeDefinitions[relation.type]?.baseType ?? relation.type) !== declaration.id)
|
|
643
650
|
continue;
|
|
644
651
|
const parents = relation.endpoints.filter((endpoint) => endpoint.role === hierarchy.parentRole);
|
|
645
652
|
const kids = relation.endpoints.filter((endpoint) => endpoint.role === hierarchy.childRole);
|
|
@@ -693,7 +700,7 @@ function checkParentFamily(document, profile, registry, resolver, constraint) {
|
|
|
693
700
|
continue;
|
|
694
701
|
const hierarchy = declaration.hierarchy;
|
|
695
702
|
const relations = Object.values(document.relations)
|
|
696
|
-
.filter((relation) => relation.profile === profile.id && relation
|
|
703
|
+
.filter((relation) => relation.profile === profile.id && relationBaseType(document, profile, relation) === declaration.id)
|
|
697
704
|
.sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
|
|
698
705
|
for (const relation of relations) {
|
|
699
706
|
relation.endpoints.forEach((endpoint, index) => {
|
|
@@ -726,7 +733,7 @@ function checkChildrenRestricted(document, profile, registry, resolver, constrai
|
|
|
726
733
|
continue;
|
|
727
734
|
const hierarchy = declaration.hierarchy;
|
|
728
735
|
const relations = Object.values(document.relations)
|
|
729
|
-
.filter((relation) => relation.profile === profile.id && relation
|
|
736
|
+
.filter((relation) => relation.profile === profile.id && relationBaseType(document, profile, relation) === declaration.id)
|
|
730
737
|
.sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
|
|
731
738
|
for (const relation of relations) {
|
|
732
739
|
const parents = relation.endpoints.filter((endpoint) => endpoint.role === hierarchy.parentRole);
|
|
@@ -822,7 +829,7 @@ function checkRelationshipMatrix(document, profile, registry, resolver, constrai
|
|
|
822
829
|
// prerequisites take precedence. A relation failing any of them already
|
|
823
830
|
// carries its own refusal from endpoint validation; comparing it against
|
|
824
831
|
// the matrix would add a secondary relationship-matrix-violation.
|
|
825
|
-
const declared =
|
|
832
|
+
const declared = relationSchema(document, profile, relation);
|
|
826
833
|
if (declared === undefined)
|
|
827
834
|
continue;
|
|
828
835
|
const sourceRole = roleOf(declared, constraint.sourceRole);
|
|
@@ -889,7 +896,7 @@ function checkRelationshipMatrix(document, profile, registry, resolver, constrai
|
|
|
889
896
|
else {
|
|
890
897
|
targetType = "@relation";
|
|
891
898
|
}
|
|
892
|
-
if (tuples.has(`${relation
|
|
899
|
+
if (tuples.has(`${relationBaseType(document, profile, relation)}\n${sourceType}\n${targetType}`))
|
|
893
900
|
continue;
|
|
894
901
|
diagnostics.push(diagnostic({
|
|
895
902
|
code: "relationship-matrix-violation",
|
|
@@ -970,7 +977,7 @@ function checkBoundPair(document, profile, registry, resolver, constraint) {
|
|
|
970
977
|
for (const relation of Object.values(document.relations)
|
|
971
978
|
.filter((candidate) => candidate.profile === profile.id)
|
|
972
979
|
.sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0))) {
|
|
973
|
-
if (
|
|
980
|
+
if (relationSchema(document, profile, relation) === undefined)
|
|
974
981
|
continue;
|
|
975
982
|
checkRecord(`relations.${relation.id}`, relation.attributes);
|
|
976
983
|
}
|
|
@@ -1057,13 +1064,13 @@ function checkIncidentTypeUniformity(document, profile, registry, resolver, cons
|
|
|
1057
1064
|
const diagnostics = [];
|
|
1058
1065
|
const ordered = [...entities].sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
|
|
1059
1066
|
const relations = Object.values(document.relations)
|
|
1060
|
-
.filter((relation) => relation.profile === profile.id && constraint.relationTypes.includes(relation
|
|
1067
|
+
.filter((relation) => relation.profile === profile.id && constraint.relationTypes.includes(relationBaseType(document, profile, relation)))
|
|
1061
1068
|
.sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
|
|
1062
1069
|
for (const entity of ordered) {
|
|
1063
1070
|
if (!entityAncestry(registry, resolver, entity).includes(constraint.entityType))
|
|
1064
1071
|
continue;
|
|
1065
1072
|
const incident = relations.filter((relation) => relation.endpoints.some((endpoint) => endpoint.target === entity.id));
|
|
1066
|
-
const distinct = [...new Set(incident.map((relation) => relation
|
|
1073
|
+
const distinct = [...new Set(incident.map((relation) => relationBaseType(document, profile, relation)))].sort();
|
|
1067
1074
|
if (distinct.length <= 1)
|
|
1068
1075
|
continue;
|
|
1069
1076
|
diagnostics.push(diagnostic({
|
|
@@ -1083,7 +1090,7 @@ function checkIncidentTypeUniformity(document, profile, registry, resolver, cons
|
|
|
1083
1090
|
function checkAtMostValue(document, profile, constraint) {
|
|
1084
1091
|
const diagnostics = [];
|
|
1085
1092
|
const relations = Object.values(document.relations)
|
|
1086
|
-
.filter((relation) => relation.profile === profile.id && relation
|
|
1093
|
+
.filter((relation) => relation.profile === profile.id && relationBaseType(document, profile, relation) === constraint.relationType)
|
|
1087
1094
|
.sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
|
|
1088
1095
|
for (const relation of relations) {
|
|
1089
1096
|
const count = constraint.attributes.filter((attribute) => {
|
|
@@ -1438,8 +1445,18 @@ export function validateDocument(document, options) {
|
|
|
1438
1445
|
diagnostics.push(profile.diagnostic);
|
|
1439
1446
|
continue;
|
|
1440
1447
|
}
|
|
1441
|
-
|
|
1442
|
-
|
|
1448
|
+
const entityBase = entityTypeOf(profile.profile, definition.baseType);
|
|
1449
|
+
const relationBase = relationTypeOf(profile.profile, definition.baseType);
|
|
1450
|
+
if (entityTypeOf(profile.profile, key) !== undefined || relationTypeOf(profile.profile, key) !== undefined) {
|
|
1451
|
+
diagnostics.push(diagnostic({ code: "type-definition-reserved", path, message: `definition ${key} shadows a profile type` }));
|
|
1452
|
+
continue;
|
|
1453
|
+
}
|
|
1454
|
+
if (entityBase !== undefined && relationBase !== undefined) {
|
|
1455
|
+
diagnostics.push(diagnostic({ code: "type-definition-ambiguous", path: `${path}.baseType`, message: `base ${definition.baseType} exists in both namespaces` }));
|
|
1456
|
+
continue;
|
|
1457
|
+
}
|
|
1458
|
+
if (adapterOf(definition.profile) === LEGACY_CONSTRAINTS_ADAPTER || relationBase !== undefined) {
|
|
1459
|
+
const base = entityBase ?? relationBase;
|
|
1443
1460
|
if (base === undefined) {
|
|
1444
1461
|
diagnostics.push(diagnostic({
|
|
1445
1462
|
code: "unknown-entity-type",
|
|
@@ -1448,8 +1465,11 @@ export function validateDocument(document, options) {
|
|
|
1448
1465
|
}));
|
|
1449
1466
|
continue;
|
|
1450
1467
|
}
|
|
1451
|
-
const baseNames = new Set(base.attributes.map((attribute) => attribute.name));
|
|
1468
|
+
const baseNames = new Set((base.attributes ?? []).map((attribute) => attribute.name));
|
|
1452
1469
|
for (const attribute of definition.attributes) {
|
|
1470
|
+
diagnostics.push(...qualifyAttributeSchema(attribute, `${path}.attributes.${attribute.name}`));
|
|
1471
|
+
if (relationBase !== undefined && attribute.required === true)
|
|
1472
|
+
diagnostics.push(diagnostic({ code: "type-definition-conflict", path: `${path}.attributes.${attribute.name}`, message: "refinements add optional attributes only" }));
|
|
1453
1473
|
if (baseNames.has(attribute.name)) {
|
|
1454
1474
|
diagnostics.push(diagnostic({
|
|
1455
1475
|
code: "type-definition-conflict",
|
|
@@ -1458,6 +1478,7 @@ export function validateDocument(document, options) {
|
|
|
1458
1478
|
details: { attribute: attribute.name, baseType: definition.baseType },
|
|
1459
1479
|
}));
|
|
1460
1480
|
}
|
|
1481
|
+
baseNames.add(attribute.name);
|
|
1461
1482
|
}
|
|
1462
1483
|
continue;
|
|
1463
1484
|
}
|
|
@@ -1596,7 +1617,7 @@ function projectedEndpointDiagnostic(view, document, options, resolver, scopedTa
|
|
|
1596
1617
|
if (profile === undefined)
|
|
1597
1618
|
return undefined;
|
|
1598
1619
|
const resolution = resolver.resolve(profile, entity.type);
|
|
1599
|
-
return resolution.ok ? resolution.resolved.container : undefined;
|
|
1620
|
+
return resolution.ok ? resolution.resolved.container || entityTypeOf(profile, entity.type)?.foldable === true : undefined;
|
|
1600
1621
|
};
|
|
1601
1622
|
if (refKindOf(semantic) === "relation") {
|
|
1602
1623
|
if (internal.get(sourceId) !== endpoint.occurrence)
|
|
@@ -1643,6 +1664,7 @@ export function validateView(view, document, options, hidden) {
|
|
|
1643
1664
|
const hiddenMask = new Set(hidden?.projectedHiddenRelationOccurrences ?? []);
|
|
1644
1665
|
const resolver = createTypeResolver(document);
|
|
1645
1666
|
const collapsed = collapsedOf(view);
|
|
1667
|
+
let chainDiagnostic;
|
|
1646
1668
|
const internal = classifyInternalRelations(view, document, collapsed);
|
|
1647
1669
|
const admittedBindings = options.bindings !== undefined && verifyExecutorBindings(options.bindings, options.registry).length === 0
|
|
1648
1670
|
? options.bindings
|
|
@@ -1763,9 +1785,32 @@ export function validateView(view, document, options, hidden) {
|
|
|
1763
1785
|
const endpointPath = `${path}.endpoints[${index}]`;
|
|
1764
1786
|
// Provenance-carrying endpoints validate provenance first, even when
|
|
1765
1787
|
// the drawn occurrence is missing (C.4 priority).
|
|
1766
|
-
if (endpoint.semanticTarget !== undefined || endpoint.sourceOccurrence !== undefined) {
|
|
1788
|
+
if (endpoint.semanticTarget !== undefined || endpoint.sourceOccurrence !== undefined || endpoint.chainProvenance !== undefined) {
|
|
1767
1789
|
if (relation === undefined)
|
|
1768
1790
|
return;
|
|
1791
|
+
if (endpoint.chainProvenance !== undefined) {
|
|
1792
|
+
if (endpoint.semanticTarget === undefined || endpoint.sourceOccurrence !== undefined) {
|
|
1793
|
+
diagnostics.push(diagnostic({
|
|
1794
|
+
code: "occurrence-endpoint-mismatch", path: `${endpointPath}.occurrence`,
|
|
1795
|
+
message: `projected endpoint for role ${endpoint.role} fails check provenance-missing`,
|
|
1796
|
+
refs: [occurrence.id, endpoint.occurrence], details: { role: endpoint.role, check: "provenance-missing" },
|
|
1797
|
+
}));
|
|
1798
|
+
}
|
|
1799
|
+
else {
|
|
1800
|
+
if (chainDiagnostic === undefined) {
|
|
1801
|
+
const drawnTargets = new Map([
|
|
1802
|
+
...Object.values(view.entityOccurrences).map((o) => [o.id, o.entity]),
|
|
1803
|
+
...Object.values(view.portOccurrences).map((o) => [o.id, o.port]),
|
|
1804
|
+
...Object.values(view.relationOccurrences).map((o) => [o.id, o.relation]),
|
|
1805
|
+
]);
|
|
1806
|
+
chainDiagnostic = createChainValidator(document, options.registry, resolver, drawnTargets);
|
|
1807
|
+
}
|
|
1808
|
+
const failure = chainDiagnostic(relation, occurrence.id, endpoint, endpointPath, scopedTargets);
|
|
1809
|
+
if (failure !== undefined)
|
|
1810
|
+
diagnostics.push(failure);
|
|
1811
|
+
}
|
|
1812
|
+
return;
|
|
1813
|
+
}
|
|
1769
1814
|
const failure = projectedEndpointDiagnostic(view, document, options, resolver, scopedTargets, collapsed, internal, relation, occurrence.id, endpoint, endpointPath);
|
|
1770
1815
|
if (failure !== undefined)
|
|
1771
1816
|
diagnostics.push(failure);
|
|
@@ -1883,7 +1928,7 @@ export function validateView(view, document, options, hidden) {
|
|
|
1883
1928
|
const resolution = entity === undefined || profile === undefined
|
|
1884
1929
|
? undefined
|
|
1885
1930
|
: resolver.resolve(profile, entity.type);
|
|
1886
|
-
if (resolution !== undefined && resolution.ok && !resolution.resolved.container) {
|
|
1931
|
+
if (resolution !== undefined && resolution.ok && !resolution.resolved.container && entityTypeOf(profile, entity.type)?.foldable !== true) {
|
|
1887
1932
|
diagnostics.push(diagnostic({
|
|
1888
1933
|
code: "occurrence-endpoint-mismatch",
|
|
1889
1934
|
path: `${path}.occurrence`,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* diagram-view-schema@1/@2 private frozen record
|
|
2
|
+
* diagram-view-schema@1/@2/@3 private frozen record.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Schemas are vendored as data: the exact JSON values of the Engram
|
|
5
5
|
* canonical files, each with its Pin
|
|
6
|
-
* `{ id: "diagram-view-schema", version: "1" | "2", contentDigest }`,
|
|
6
|
+
* `{ id: "diagram-view-schema", version: "1" | "2" | "3", contentDigest }`,
|
|
7
7
|
* deeply frozen. The digests are measured through the DS canonical bytes
|
|
8
8
|
* (`sha256Hex(canonicalBytes(schema))`), the same procedure as Engram
|
|
9
|
-
* `govern` (
|
|
9
|
+
* `govern` (engram@46f93dbe `src/ontology-guardian/diagram-schemas.ts`).
|
|
10
10
|
*
|
|
11
|
-
* Resolution is by exact pin only: @2 and @1
|
|
11
|
+
* Resolution is by exact pin only: @3, @2 and @1 all resolve
|
|
12
12
|
* (no "latest", no fallback, no reverse migration). Refusals are typed
|
|
13
13
|
* values, never throws. Transitional and partial references are refused.
|
|
14
14
|
*
|
|
@@ -21,7 +21,7 @@ export interface ViewSchemaPin {
|
|
|
21
21
|
readonly version: string;
|
|
22
22
|
readonly contentDigest: string;
|
|
23
23
|
}
|
|
24
|
-
export type ViewSchemaVersion = "1" | "2";
|
|
24
|
+
export type ViewSchemaVersion = "1" | "2" | "3";
|
|
25
25
|
export declare const DIAGRAM_VIEW_SCHEMA_ID: "diagram-view-schema";
|
|
26
26
|
export declare const DIAGRAM_VIEW_SCHEMA_V1: Record<string, unknown>;
|
|
27
27
|
export declare const DIAGRAM_VIEW_SCHEMA_V1_DIGEST: string;
|
|
@@ -43,6 +43,9 @@ export type ViewSchemaResolution = {
|
|
|
43
43
|
readonly ok: false;
|
|
44
44
|
readonly refusal: ViewSchemaRefusal;
|
|
45
45
|
};
|
|
46
|
+
export declare const DIAGRAM_VIEW_SCHEMA_V3: Record<string, unknown>;
|
|
47
|
+
export declare const DIAGRAM_VIEW_SCHEMA_V3_DIGEST: string;
|
|
48
|
+
export declare const DIAGRAM_VIEW_SCHEMA_V3_PIN: ViewSchemaPin;
|
|
46
49
|
/**
|
|
47
50
|
* Resolve a view schema by exact pin only. Never throws: every failure is a
|
|
48
51
|
* typed refusal. No "latest", no fallback, no reverse migration.
|
package/dist/view-schema-pin.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* diagram-view-schema@1/@2 private frozen record
|
|
2
|
+
* diagram-view-schema@1/@2/@3 private frozen record.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Schemas are vendored as data: the exact JSON values of the Engram
|
|
5
5
|
* canonical files, each with its Pin
|
|
6
|
-
* `{ id: "diagram-view-schema", version: "1" | "2", contentDigest }`,
|
|
6
|
+
* `{ id: "diagram-view-schema", version: "1" | "2" | "3", contentDigest }`,
|
|
7
7
|
* deeply frozen. The digests are measured through the DS canonical bytes
|
|
8
8
|
* (`sha256Hex(canonicalBytes(schema))`), the same procedure as Engram
|
|
9
|
-
* `govern` (
|
|
9
|
+
* `govern` (engram@46f93dbe `src/ontology-guardian/diagram-schemas.ts`).
|
|
10
10
|
*
|
|
11
|
-
* Resolution is by exact pin only: @2 and @1
|
|
11
|
+
* Resolution is by exact pin only: @3, @2 and @1 all resolve
|
|
12
12
|
* (no "latest", no fallback, no reverse migration). Refusals are typed
|
|
13
13
|
* values, never throws. Transitional and partial references are refused.
|
|
14
14
|
*
|
|
@@ -79,6 +79,14 @@ function isPlainRecord(value) {
|
|
|
79
79
|
const proto = Object.getPrototypeOf(value);
|
|
80
80
|
return proto === Object.prototype || proto === null;
|
|
81
81
|
}
|
|
82
|
+
/** Additive successor: endpoint pairing is plain, fold, or chain, exclusively. */
|
|
83
|
+
const PRIVATE_V3_SCHEMA = { "$id": "engram:diagram-view-schema/3", "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": false, "properties": { "entityOccurrences": { "additionalProperties": { "additionalProperties": false, "properties": { "entity": { "type": "string" }, "geometry": { "additionalProperties": false, "properties": { "height": { "type": "number" }, "width": { "type": "number" }, "x": { "type": "number" }, "y": { "type": "number" } }, "required": ["x", "y", "width", "height"], "type": "object" }, "group": { "type": "string" }, "id": { "type": "string" }, "z": { "type": "number" } }, "required": ["id", "entity", "geometry"], "type": "object" }, "type": "object" }, "filters": { "items": { "anyOf": [{ "additionalProperties": false, "properties": { "id": { "type": "string" }, "kind": { "const": "entity-type" }, "mode": { "enum": ["include", "exclude"] }, "types": { "items": { "type": "string" }, "type": "array" } }, "required": ["id", "kind", "types", "mode"], "type": "object" }, { "additionalProperties": false, "properties": { "id": { "type": "string" }, "kind": { "const": "relation-type" }, "mode": { "enum": ["include", "exclude"] }, "types": { "items": { "type": "string" }, "type": "array" } }, "required": ["id", "kind", "types", "mode"], "type": "object" }, { "additionalProperties": false, "properties": { "attribute": { "type": "string" }, "id": { "type": "string" }, "kind": { "const": "attribute-equals" }, "mode": { "enum": ["include", "exclude"] }, "value": { "type": "string" } }, "required": ["id", "kind", "attribute", "value", "mode"], "type": "object" }] }, "type": "array" }, "groups": { "additionalProperties": { "additionalProperties": false, "properties": { "collapsed": { "type": "boolean" }, "id": { "type": "string" }, "label": { "type": "string" }, "occurrence": { "type": "string" } }, "required": ["id"], "type": "object" }, "type": "object" }, "portOccurrences": { "additionalProperties": { "additionalProperties": false, "properties": { "anchor": { "maximum": 1, "minimum": 0, "type": "number" }, "id": { "type": "string" }, "order": { "type": "number" }, "ownerOccurrence": { "type": "string" }, "port": { "type": "string" }, "side": { "enum": ["north", "east", "south", "west"] } }, "required": ["id", "port", "ownerOccurrence", "side", "order", "anchor"], "type": "object" }, "type": "object" }, "presentation": { "additionalProperties": false, "properties": { "camera": { "additionalProperties": false, "properties": { "x": { "type": "number" }, "y": { "type": "number" }, "zoom": { "type": "number" } }, "required": ["x", "y", "zoom"], "type": "object" }, "diagram": { "additionalProperties": false, "properties": { "categoryTokens": { "items": { "additionalProperties": false, "properties": { "category": { "maxLength": 40, "minLength": 1, "pattern": "^[a-z][a-z0-9-]*$", "type": "string" }, "legendRef": { "minLength": 1, "type": "string" }, "token": { "maxLength": 80, "minLength": 1, "pattern": "^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)*$", "type": "string" } }, "required": ["legendRef", "category", "token"], "type": "object" }, "type": "array" }, "contractPin": { "additionalProperties": false, "properties": { "contentDigest": { "pattern": "^[0-9a-f]{64}$", "type": "string" }, "id": { "const": "diagram-presentation" }, "version": { "const": "1" } }, "required": ["id", "version", "contentDigest"], "type": "object" }, "entities": { "additionalProperties": { "additionalProperties": false, "allOf": [{ "if": { "properties": { "form": { "const": "legend-key" } }, "required": ["form"] }, "then": { "properties": { "text": { "properties": { "title": { "maxLength": 120, "type": "string" } }, "type": "object" } } } }], "properties": { "categoryRef": { "minLength": 1, "type": "string" }, "form": { "enum": ["card", "container", "legend", "legend-key"] }, "icon": { "maxLength": 40, "minLength": 1, "pattern": "^[a-z][a-z0-9-]*$", "type": "string" }, "text": { "additionalProperties": false, "properties": { "body": { "maxLength": 400, "type": "string" }, "detail": { "maxLength": 400, "type": "string" }, "footer": { "maxLength": 120, "type": "string" }, "kicker": { "maxLength": 80, "type": "string" }, "subtitle": { "maxLength": 600, "type": "string" }, "title": { "maxLength": 200, "type": "string" } }, "type": "object" } }, "required": ["form", "text"], "type": "object" }, "type": "object" }, "legends": { "additionalProperties": { "additionalProperties": false, "properties": { "order": { "items": { "minLength": 1, "type": "string" }, "type": "array", "uniqueItems": true } }, "required": ["order"], "type": "object" }, "type": "object" } }, "required": ["contractPin", "entities", "legends", "categoryTokens"], "type": "object" }, "grid": { "additionalProperties": false, "properties": { "size": { "type": "number" }, "snap": { "type": "boolean" } }, "required": ["size", "snap"], "type": "object" }, "theme": { "type": "string" } }, "required": ["camera"], "type": "object" }, "relationOccurrences": { "additionalProperties": { "additionalProperties": false, "properties": { "endpoints": { "items": { "additionalProperties": false, "dependentRequired": { "sourceOccurrence": ["semanticTarget"], "chainProvenance": ["semanticTarget"] }, "properties": { "occurrence": { "type": "string" }, "role": { "type": "string" }, "semanticTarget": { "type": "string" }, "sourceOccurrence": { "type": "string" }, "chainProvenance": { "type": "object", "additionalProperties": false, "required": ["predicateId", "hops"], "properties": { "predicateId": { "type": "string", "minLength": 1 }, "hops": { "type": "array", "items": { "type": "string" } }, "members": { "type": "array", "items": { "type": "string" } } } } }, "required": ["role", "occurrence"], "type": "object", "dependentSchemas": { "semanticTarget": { "oneOf": [{ "properties": { "sourceOccurrence": true, "chainProvenance": false }, "required": ["sourceOccurrence"] }, { "properties": { "chainProvenance": true, "sourceOccurrence": false }, "required": ["chainProvenance"] }] } } }, "type": "array" }, "id": { "type": "string" }, "relation": { "type": "string" }, "strokeStyle": { "enum": ["solid", "dashed"] }, "waypoints": { "items": { "additionalProperties": false, "properties": { "x": { "type": "number" }, "y": { "type": "number" } }, "required": ["x", "y"], "type": "object" }, "type": "array" } }, "required": ["id", "relation", "endpoints"], "type": "object" }, "type": "object" }, "revision": { "minimum": 0, "type": "integer" }, "semanticDocumentId": { "type": "string" }, "summaryLabels": { "additionalProperties": { "additionalProperties": false, "properties": { "id": { "type": "string" }, "label": { "type": "string" }, "relationIds": { "items": { "type": "string" }, "minItems": 1, "type": "array" }, "relationOccurrences": { "items": { "type": "string" }, "type": "array" }, "sourceOccurrence": { "type": "string" }, "strokeStyle": { "enum": ["solid", "dashed"] }, "targetOccurrence": { "type": "string" } }, "required": ["id", "sourceOccurrence", "targetOccurrence", "label", "relationIds"], "type": "object" }, "type": "object" }, "viewId": { "type": "string" } }, "required": ["viewId", "semanticDocumentId", "revision", "entityOccurrences", "relationOccurrences", "portOccurrences", "groups", "filters", "presentation"], "type": "object" };
|
|
84
|
+
deepFreezeValue(PRIVATE_V3_SCHEMA);
|
|
85
|
+
export const DIAGRAM_VIEW_SCHEMA_V3 = frozenCopy(PRIVATE_V3_SCHEMA);
|
|
86
|
+
export const DIAGRAM_VIEW_SCHEMA_V3_DIGEST = sha256Hex(canonicalBytes(PRIVATE_V3_SCHEMA));
|
|
87
|
+
export const DIAGRAM_VIEW_SCHEMA_V3_PIN = deepFreezeValue({
|
|
88
|
+
id: DIAGRAM_VIEW_SCHEMA_ID, version: "3", contentDigest: DIAGRAM_VIEW_SCHEMA_V3_DIGEST,
|
|
89
|
+
});
|
|
82
90
|
const ALLOWED_PIN_KEYS = new Set(["id", "version", "contentDigest"]);
|
|
83
91
|
/**
|
|
84
92
|
* Exact-key shape gate, mirroring `isWellFormedPin` in
|
|
@@ -138,9 +146,9 @@ export function resolveViewSchema(pin) {
|
|
|
138
146
|
return { ok: false, refusal: { code: "pin-malformed" } };
|
|
139
147
|
if (id !== DIAGRAM_VIEW_SCHEMA_ID)
|
|
140
148
|
return { ok: false, refusal: { code: "unknown-schema-id" } };
|
|
141
|
-
if (version !== "1" && version !== "2")
|
|
149
|
+
if (version !== "1" && version !== "2" && version !== "3")
|
|
142
150
|
return { ok: false, refusal: { code: "unknown-schema-version" } };
|
|
143
|
-
const expected = version === "1" ? DIAGRAM_VIEW_SCHEMA_V1_DIGEST : DIAGRAM_VIEW_SCHEMA_V2_DIGEST;
|
|
151
|
+
const expected = version === "1" ? DIAGRAM_VIEW_SCHEMA_V1_DIGEST : version === "2" ? DIAGRAM_VIEW_SCHEMA_V2_DIGEST : DIAGRAM_VIEW_SCHEMA_V3_DIGEST;
|
|
144
152
|
if (contentDigest !== expected)
|
|
145
153
|
return { ok: false, refusal: { code: "schema-digest-mismatch" } };
|
|
146
154
|
if (version === "1") {
|
|
@@ -148,6 +156,8 @@ export function resolveViewSchema(pin) {
|
|
|
148
156
|
return { ok: false, refusal: { code: "schema-bytes-unavailable" } };
|
|
149
157
|
return { ok: true, version: "1", pin: frozenCopy(DIAGRAM_VIEW_SCHEMA_V1_PIN), schema: DIAGRAM_VIEW_SCHEMA_V1 };
|
|
150
158
|
}
|
|
159
|
+
if (version === "3")
|
|
160
|
+
return { ok: true, version: "3", pin: frozenCopy(DIAGRAM_VIEW_SCHEMA_V3_PIN), schema: DIAGRAM_VIEW_SCHEMA_V3 };
|
|
151
161
|
if (DIAGRAM_VIEW_SCHEMA_V2 === undefined)
|
|
152
162
|
return { ok: false, refusal: { code: "schema-bytes-unavailable" } };
|
|
153
163
|
return { ok: true, version: "2", pin: frozenCopy(DIAGRAM_VIEW_SCHEMA_V2_PIN), schema: DIAGRAM_VIEW_SCHEMA_V2 };
|
package/dist/view.d.ts
CHANGED
|
@@ -38,6 +38,13 @@ export interface EntityOccurrence {
|
|
|
38
38
|
/** Explicit paint order. A field, never an array position. */
|
|
39
39
|
readonly z?: number;
|
|
40
40
|
}
|
|
41
|
+
export interface ChainProvenance {
|
|
42
|
+
readonly predicateId: string;
|
|
43
|
+
/** Semantic relation refs in walk order from semanticTarget to the drawn entity. */
|
|
44
|
+
readonly hops: readonly RelationRef[];
|
|
45
|
+
/** Aggregate only: complete carrier set in fixed source/target/relation order. */
|
|
46
|
+
readonly members?: readonly RelationRef[];
|
|
47
|
+
}
|
|
41
48
|
export interface RelationOccurrenceEndpoint {
|
|
42
49
|
/** The role of the relation this end draws. Matched against the relation's own endpoints. */
|
|
43
50
|
readonly role: string;
|
|
@@ -49,16 +56,18 @@ export interface RelationOccurrenceEndpoint {
|
|
|
49
56
|
readonly occurrence: OccurrenceRef;
|
|
50
57
|
/**
|
|
51
58
|
* The semantic endpoint target for this role, copied verbatim. Present iff
|
|
52
|
-
* the drawn `occurrence` does not itself draw that target (
|
|
53
|
-
*
|
|
59
|
+
* the drawn `occurrence` does not itself draw that target (fold or chain
|
|
60
|
+
* provenance). A RelationRef is permitted only where the semantic
|
|
54
61
|
* role admits relation targets.
|
|
55
62
|
*/
|
|
56
63
|
readonly semanticTarget?: EntityRef | PortRef | RelationRef;
|
|
57
64
|
/**
|
|
58
65
|
* The original endpoint occurrence in the retained source view. Present iff
|
|
59
|
-
*
|
|
66
|
+
* fold provenance is used; mutually exclusive with `chainProvenance`.
|
|
60
67
|
*/
|
|
61
68
|
readonly sourceOccurrence?: OccurrenceRef;
|
|
69
|
+
/** Document-proven chain: requires semanticTarget and excludes sourceOccurrence. */
|
|
70
|
+
readonly chainProvenance?: ChainProvenance;
|
|
62
71
|
}
|
|
63
72
|
export interface RelationOccurrence {
|
|
64
73
|
readonly id: OccurrenceRef;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/diagram-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Typed semantic core for diagrams: versioned documents and profiles, views with occurrences, transactional commands with logical inverses. No runtime dependency, no DOM, no framework.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"!dist/**/*.map",
|
|
11
|
-
"!dist/.srchash"
|
|
11
|
+
"!dist/.srchash",
|
|
12
|
+
"schemas"
|
|
12
13
|
],
|
|
13
14
|
"type": "module",
|
|
14
15
|
"license": "MIT",
|
|
@@ -21,7 +22,9 @@
|
|
|
21
22
|
".": {
|
|
22
23
|
"types": "./dist/index.d.ts",
|
|
23
24
|
"import": "./dist/index.js"
|
|
24
|
-
}
|
|
25
|
+
},
|
|
26
|
+
"./schemas/diagram-view-schema-3.json": "./schemas/diagram-view-schema-3.json",
|
|
27
|
+
"./schemas/diagram-view-schema-3.sha256": "./schemas/diagram-view-schema-3.sha256"
|
|
25
28
|
},
|
|
26
29
|
"types": "./dist/index.d.ts",
|
|
27
30
|
"main": "./dist/index.js",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$id":"engram:diagram-view-schema/3","$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":false,"properties":{"entityOccurrences":{"additionalProperties":{"additionalProperties":false,"properties":{"entity":{"type":"string"},"geometry":{"additionalProperties":false,"properties":{"height":{"type":"number"},"width":{"type":"number"},"x":{"type":"number"},"y":{"type":"number"}},"required":["x","y","width","height"],"type":"object"},"group":{"type":"string"},"id":{"type":"string"},"z":{"type":"number"}},"required":["id","entity","geometry"],"type":"object"},"type":"object"},"filters":{"items":{"anyOf":[{"additionalProperties":false,"properties":{"id":{"type":"string"},"kind":{"const":"entity-type"},"mode":{"enum":["include","exclude"]},"types":{"items":{"type":"string"},"type":"array"}},"required":["id","kind","types","mode"],"type":"object"},{"additionalProperties":false,"properties":{"id":{"type":"string"},"kind":{"const":"relation-type"},"mode":{"enum":["include","exclude"]},"types":{"items":{"type":"string"},"type":"array"}},"required":["id","kind","types","mode"],"type":"object"},{"additionalProperties":false,"properties":{"attribute":{"type":"string"},"id":{"type":"string"},"kind":{"const":"attribute-equals"},"mode":{"enum":["include","exclude"]},"value":{"type":"string"}},"required":["id","kind","attribute","value","mode"],"type":"object"}]},"type":"array"},"groups":{"additionalProperties":{"additionalProperties":false,"properties":{"collapsed":{"type":"boolean"},"id":{"type":"string"},"label":{"type":"string"},"occurrence":{"type":"string"}},"required":["id"],"type":"object"},"type":"object"},"portOccurrences":{"additionalProperties":{"additionalProperties":false,"properties":{"anchor":{"maximum":1,"minimum":0,"type":"number"},"id":{"type":"string"},"order":{"type":"number"},"ownerOccurrence":{"type":"string"},"port":{"type":"string"},"side":{"enum":["north","east","south","west"]}},"required":["id","port","ownerOccurrence","side","order","anchor"],"type":"object"},"type":"object"},"presentation":{"additionalProperties":false,"properties":{"camera":{"additionalProperties":false,"properties":{"x":{"type":"number"},"y":{"type":"number"},"zoom":{"type":"number"}},"required":["x","y","zoom"],"type":"object"},"diagram":{"additionalProperties":false,"properties":{"categoryTokens":{"items":{"additionalProperties":false,"properties":{"category":{"maxLength":40,"minLength":1,"pattern":"^[a-z][a-z0-9-]*$","type":"string"},"legendRef":{"minLength":1,"type":"string"},"token":{"maxLength":80,"minLength":1,"pattern":"^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)*$","type":"string"}},"required":["legendRef","category","token"],"type":"object"},"type":"array"},"contractPin":{"additionalProperties":false,"properties":{"contentDigest":{"pattern":"^[0-9a-f]{64}$","type":"string"},"id":{"const":"diagram-presentation"},"version":{"const":"1"}},"required":["id","version","contentDigest"],"type":"object"},"entities":{"additionalProperties":{"additionalProperties":false,"allOf":[{"if":{"properties":{"form":{"const":"legend-key"}},"required":["form"]},"then":{"properties":{"text":{"properties":{"title":{"maxLength":120,"type":"string"}},"type":"object"}}}}],"properties":{"categoryRef":{"minLength":1,"type":"string"},"form":{"enum":["card","container","legend","legend-key"]},"icon":{"maxLength":40,"minLength":1,"pattern":"^[a-z][a-z0-9-]*$","type":"string"},"text":{"additionalProperties":false,"properties":{"body":{"maxLength":400,"type":"string"},"detail":{"maxLength":400,"type":"string"},"footer":{"maxLength":120,"type":"string"},"kicker":{"maxLength":80,"type":"string"},"subtitle":{"maxLength":600,"type":"string"},"title":{"maxLength":200,"type":"string"}},"type":"object"}},"required":["form","text"],"type":"object"},"type":"object"},"legends":{"additionalProperties":{"additionalProperties":false,"properties":{"order":{"items":{"minLength":1,"type":"string"},"type":"array","uniqueItems":true}},"required":["order"],"type":"object"},"type":"object"}},"required":["contractPin","entities","legends","categoryTokens"],"type":"object"},"grid":{"additionalProperties":false,"properties":{"size":{"type":"number"},"snap":{"type":"boolean"}},"required":["size","snap"],"type":"object"},"theme":{"type":"string"}},"required":["camera"],"type":"object"},"relationOccurrences":{"additionalProperties":{"additionalProperties":false,"properties":{"endpoints":{"items":{"additionalProperties":false,"dependentRequired":{"chainProvenance":["semanticTarget"],"sourceOccurrence":["semanticTarget"]},"dependentSchemas":{"semanticTarget":{"oneOf":[{"properties":{"chainProvenance":false,"sourceOccurrence":true},"required":["sourceOccurrence"]},{"properties":{"chainProvenance":true,"sourceOccurrence":false},"required":["chainProvenance"]}]}},"properties":{"chainProvenance":{"additionalProperties":false,"properties":{"hops":{"items":{"type":"string"},"type":"array"},"members":{"items":{"type":"string"},"type":"array"},"predicateId":{"minLength":1,"type":"string"}},"required":["predicateId","hops"],"type":"object"},"occurrence":{"type":"string"},"role":{"type":"string"},"semanticTarget":{"type":"string"},"sourceOccurrence":{"type":"string"}},"required":["role","occurrence"],"type":"object"},"type":"array"},"id":{"type":"string"},"relation":{"type":"string"},"strokeStyle":{"enum":["solid","dashed"]},"waypoints":{"items":{"additionalProperties":false,"properties":{"x":{"type":"number"},"y":{"type":"number"}},"required":["x","y"],"type":"object"},"type":"array"}},"required":["id","relation","endpoints"],"type":"object"},"type":"object"},"revision":{"minimum":0,"type":"integer"},"semanticDocumentId":{"type":"string"},"summaryLabels":{"additionalProperties":{"additionalProperties":false,"properties":{"id":{"type":"string"},"label":{"type":"string"},"relationIds":{"items":{"type":"string"},"minItems":1,"type":"array"},"relationOccurrences":{"items":{"type":"string"},"type":"array"},"sourceOccurrence":{"type":"string"},"strokeStyle":{"enum":["solid","dashed"]},"targetOccurrence":{"type":"string"}},"required":["id","sourceOccurrence","targetOccurrence","label","relationIds"],"type":"object"},"type":"object"},"viewId":{"type":"string"}},"required":["viewId","semanticDocumentId","revision","entityOccurrences","relationOccurrences","portOccurrences","groups","filters","presentation"],"type":"object"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
b415c05197692baa5f74ab35e3150ce58079cf9f06201df5e581d222a8d2c0df
|