@sentropic/diagram-core 0.3.0 → 0.4.1
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/presentation-relations.d.ts +0 -1
- package/dist/presentation-relations.js +47 -2
- package/dist/presentation.d.ts +23 -0
- package/dist/presentation.js +74 -1
- package/dist/validate.js +26 -10
- package/dist/view.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Resolve document relation refinements at the boundary of the frozen presentation adapter. */
|
|
2
1
|
import { validateDiagramPresentation as validatePinnedPresentation } from "./presentation-validate.js";
|
|
3
2
|
export declare function validateDiagramPresentation(...args: Parameters<typeof validatePinnedPresentation>): ReturnType<typeof validatePinnedPresentation>;
|
|
4
3
|
//# sourceMappingURL=presentation-relations.d.ts.map
|
|
@@ -1,6 +1,51 @@
|
|
|
1
|
-
/** Resolve document relation refinements at the boundary of the frozen presentation adapter. */
|
|
1
|
+
/** Resolve document relation refinements and diagram-presentation@2 at the boundary of the frozen presentation adapter. */
|
|
2
|
+
import { DIAGRAM_PRESENTATION_CONTRACT_PIN, isPresentationContractV2Pin, } from "./presentation.js";
|
|
2
3
|
import { validateDiagramPresentation as validatePinnedPresentation } from "./presentation-validate.js";
|
|
3
4
|
import { relationBaseType } from "./relation-types.js";
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function normalizeV2View(view) {
|
|
9
|
+
const diagram = view.presentation.diagram;
|
|
10
|
+
if (!isRecord(diagram) || !isRecord(diagram["contractPin"]))
|
|
11
|
+
return view;
|
|
12
|
+
if (!isPresentationContractV2Pin(diagram["contractPin"]))
|
|
13
|
+
return view;
|
|
14
|
+
const rawEntities = diagram["entities"];
|
|
15
|
+
if (!isRecord(rawEntities)) {
|
|
16
|
+
return {
|
|
17
|
+
...view,
|
|
18
|
+
presentation: {
|
|
19
|
+
...view.presentation,
|
|
20
|
+
diagram: { ...diagram, contractPin: { ...DIAGRAM_PRESENTATION_CONTRACT_PIN } },
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const entities = {};
|
|
25
|
+
for (const [key, entry] of Object.entries(rawEntities)) {
|
|
26
|
+
if (isRecord(entry) && "align" in entry) {
|
|
27
|
+
const align = entry["align"];
|
|
28
|
+
if (align === undefined || align === "left" || align === "center") {
|
|
29
|
+
const { align: _validAlign, ...rest } = entry;
|
|
30
|
+
void _validAlign;
|
|
31
|
+
entities[key] = rest;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
entities[key] = entry;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
...view,
|
|
39
|
+
presentation: {
|
|
40
|
+
...view.presentation,
|
|
41
|
+
diagram: {
|
|
42
|
+
...diagram,
|
|
43
|
+
contractPin: { ...DIAGRAM_PRESENTATION_CONTRACT_PIN },
|
|
44
|
+
entities,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
4
49
|
export function validateDiagramPresentation(...args) {
|
|
5
50
|
const [document, view, options] = args;
|
|
6
51
|
let changed = false;
|
|
@@ -12,6 +57,6 @@ export function validateDiagramPresentation(...args) {
|
|
|
12
57
|
changed = true;
|
|
13
58
|
return [id, { ...relation, type }];
|
|
14
59
|
}));
|
|
15
|
-
return validatePinnedPresentation(changed ? { ...document, relations } : document, view, options);
|
|
60
|
+
return validatePinnedPresentation(changed ? { ...document, relations } : document, normalizeV2View(view), options);
|
|
16
61
|
}
|
|
17
62
|
//# sourceMappingURL=presentation-relations.js.map
|
package/dist/presentation.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface PresentationPin {
|
|
|
17
17
|
}
|
|
18
18
|
export type StrokeStyle = "solid" | "dashed";
|
|
19
19
|
export type DiagramForm = "card" | "container" | "legend" | "legend-key";
|
|
20
|
+
/** Text/header alignment governed by `diagram-presentation@2` (DE-1). */
|
|
21
|
+
export type PresentationAlign = "left" | "center";
|
|
20
22
|
export interface PresentationText {
|
|
21
23
|
readonly title?: string;
|
|
22
24
|
readonly kicker?: string;
|
|
@@ -30,6 +32,8 @@ export interface EntityPresentation {
|
|
|
30
32
|
readonly text: PresentationText;
|
|
31
33
|
readonly icon?: string;
|
|
32
34
|
readonly categoryRef?: EntityRef;
|
|
35
|
+
/** Optional alignment (`diagram-presentation@2`, DE-1). */
|
|
36
|
+
readonly align?: PresentationAlign;
|
|
33
37
|
}
|
|
34
38
|
export interface LegendPresentation {
|
|
35
39
|
readonly order: readonly EntityRef[];
|
|
@@ -134,9 +138,28 @@ export declare const DIAGRAM_PRESENTATION_PACKAGED_CATALOG: PresentationContract
|
|
|
134
138
|
export declare function parsePinnedAdapterReference(ref: string): PresentationPin | undefined;
|
|
135
139
|
/** The contract ProfileId form, never a valid semantic profileRef. */
|
|
136
140
|
export declare const DIAGRAM_PRESENTATION_PROFILE_ID: "diagram-presentation@1";
|
|
141
|
+
export declare const DIAGRAM_PRESENTATION_V2_SCHEMA: Record<string, unknown>;
|
|
142
|
+
export declare const DIAGRAM_PRESENTATION_V2_SCHEMA_DIGEST: string;
|
|
143
|
+
export declare const DIAGRAM_PRESENTATION_V2_SCHEMA_PIN: PresentationPin;
|
|
144
|
+
export declare const DIAGRAM_PRESENTATION_V2_CONTRACT_ID: "diagram-presentation@2";
|
|
145
|
+
export declare const DIAGRAM_PRESENTATION_V2_PROFILE_ID: "diagram-presentation@2";
|
|
146
|
+
export declare const DIAGRAM_PRESENTATION_V2_CONTRACT_DESCRIPTOR: {
|
|
147
|
+
id: "diagram-presentation@2";
|
|
148
|
+
artifactKind: "contract";
|
|
149
|
+
schemaPin: {
|
|
150
|
+
id: string;
|
|
151
|
+
version: string;
|
|
152
|
+
contentDigest: string;
|
|
153
|
+
};
|
|
154
|
+
compatibilityMatrixVersion: "2";
|
|
155
|
+
};
|
|
156
|
+
export declare const DIAGRAM_PRESENTATION_V2_CONTRACT_CONTENT: string;
|
|
157
|
+
export declare const DIAGRAM_PRESENTATION_V2_CONTRACT_PIN: PresentationPin;
|
|
137
158
|
export declare function isPresentationContractProfileId(id: string): boolean;
|
|
138
159
|
export declare function isPresentationContractPin(pin: PresentationPin): boolean;
|
|
160
|
+
export declare function isPresentationContractV2Pin(pin: PresentationPin): boolean;
|
|
139
161
|
export declare function isPresentationSchemaPin(pin: PresentationPin): boolean;
|
|
162
|
+
export declare function isPresentationSchemaV2Pin(pin: PresentationPin): boolean;
|
|
140
163
|
/** G0 family pin for a DS profile (explicit native/pin mapping, §7.4.2). */
|
|
141
164
|
export declare function familyPinForProfile(profile: Profile): PresentationPin;
|
|
142
165
|
export declare function presentationPinsEqual(left: PresentationPin, right: PresentationPin): boolean;
|
package/dist/presentation.js
CHANGED
|
@@ -234,19 +234,92 @@ export function parsePinnedAdapterReference(ref) {
|
|
|
234
234
|
}
|
|
235
235
|
/** The contract ProfileId form, never a valid semantic profileRef. */
|
|
236
236
|
export const DIAGRAM_PRESENTATION_PROFILE_ID = "diagram-presentation@1";
|
|
237
|
+
/**
|
|
238
|
+
* diagram-presentation@2 (DE-1): additive successor to @1 carrying optional
|
|
239
|
+
* `align: "left" | "center"` on `EntityPresentation`. `@1` bytes, digests and
|
|
240
|
+
* packaged catalog remain untouched.
|
|
241
|
+
*/
|
|
242
|
+
const ENTITY_PRESENTATION_V2_SCHEMA = {
|
|
243
|
+
...ENTITY_PRESENTATION_SCHEMA,
|
|
244
|
+
properties: {
|
|
245
|
+
...ENTITY_PRESENTATION_SCHEMA.properties,
|
|
246
|
+
align: { enum: ["left", "center"] },
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
const DIAGRAM_VALUE_V2_PROPERTIES = {
|
|
250
|
+
...DIAGRAM_VALUE_PROPERTIES,
|
|
251
|
+
contractPin: {
|
|
252
|
+
type: "object",
|
|
253
|
+
properties: {
|
|
254
|
+
id: { const: "diagram-presentation" },
|
|
255
|
+
version: { const: "2" },
|
|
256
|
+
contentDigest: { type: "string", pattern: "^[0-9a-f]{64}$" },
|
|
257
|
+
},
|
|
258
|
+
required: ["id", "version", "contentDigest"],
|
|
259
|
+
additionalProperties: false,
|
|
260
|
+
},
|
|
261
|
+
entities: { type: "object", additionalProperties: ENTITY_PRESENTATION_V2_SCHEMA },
|
|
262
|
+
};
|
|
263
|
+
const PRIVATE_PRESENTATION_V2_SCHEMA = {
|
|
264
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
265
|
+
$id: "engram:diagram-presentation-schema/2",
|
|
266
|
+
title: "diagram-presentation@2 contract",
|
|
267
|
+
type: "object",
|
|
268
|
+
properties: DIAGRAM_VALUE_V2_PROPERTIES,
|
|
269
|
+
required: [...DIAGRAM_VALUE_REQUIRED],
|
|
270
|
+
additionalProperties: false,
|
|
271
|
+
};
|
|
272
|
+
deepFreezeValue(PRIVATE_PRESENTATION_V2_SCHEMA);
|
|
273
|
+
export const DIAGRAM_PRESENTATION_V2_SCHEMA = frozenCopy(PRIVATE_PRESENTATION_V2_SCHEMA);
|
|
274
|
+
export const DIAGRAM_PRESENTATION_V2_SCHEMA_DIGEST = sha256Hex(canonicalBytes(PRIVATE_PRESENTATION_V2_SCHEMA));
|
|
275
|
+
const PRIVATE_PRESENTATION_V2_SCHEMA_PIN = {
|
|
276
|
+
id: "diagram-presentation-schema",
|
|
277
|
+
version: "2",
|
|
278
|
+
contentDigest: DIAGRAM_PRESENTATION_V2_SCHEMA_DIGEST,
|
|
279
|
+
};
|
|
280
|
+
deepFreezeValue(PRIVATE_PRESENTATION_V2_SCHEMA_PIN);
|
|
281
|
+
export const DIAGRAM_PRESENTATION_V2_SCHEMA_PIN = frozenCopy(PRIVATE_PRESENTATION_V2_SCHEMA_PIN);
|
|
282
|
+
export const DIAGRAM_PRESENTATION_V2_CONTRACT_ID = "diagram-presentation@2";
|
|
283
|
+
export const DIAGRAM_PRESENTATION_V2_PROFILE_ID = "diagram-presentation@2";
|
|
284
|
+
const PRIVATE_CONTRACT_V2_DESCRIPTOR = {
|
|
285
|
+
id: DIAGRAM_PRESENTATION_V2_CONTRACT_ID,
|
|
286
|
+
artifactKind: DIAGRAM_PRESENTATION_ARTIFACT_KIND,
|
|
287
|
+
schemaPin: { ...PRIVATE_PRESENTATION_V2_SCHEMA_PIN },
|
|
288
|
+
compatibilityMatrixVersion: "2",
|
|
289
|
+
};
|
|
290
|
+
deepFreezeValue(PRIVATE_CONTRACT_V2_DESCRIPTOR);
|
|
291
|
+
export const DIAGRAM_PRESENTATION_V2_CONTRACT_DESCRIPTOR = frozenCopy(PRIVATE_CONTRACT_V2_DESCRIPTOR);
|
|
292
|
+
export const DIAGRAM_PRESENTATION_V2_CONTRACT_CONTENT = sha256Hex(canonicalBytes(PRIVATE_CONTRACT_V2_DESCRIPTOR));
|
|
293
|
+
const PRIVATE_CONTRACT_V2_PIN = {
|
|
294
|
+
id: "diagram-presentation",
|
|
295
|
+
version: "2",
|
|
296
|
+
contentDigest: DIAGRAM_PRESENTATION_V2_CONTRACT_CONTENT,
|
|
297
|
+
};
|
|
298
|
+
deepFreezeValue(PRIVATE_CONTRACT_V2_PIN);
|
|
299
|
+
export const DIAGRAM_PRESENTATION_V2_CONTRACT_PIN = frozenCopy(PRIVATE_CONTRACT_V2_PIN);
|
|
237
300
|
export function isPresentationContractProfileId(id) {
|
|
238
|
-
return id === DIAGRAM_PRESENTATION_PROFILE_ID;
|
|
301
|
+
return id === DIAGRAM_PRESENTATION_PROFILE_ID || id === DIAGRAM_PRESENTATION_V2_PROFILE_ID;
|
|
239
302
|
}
|
|
240
303
|
export function isPresentationContractPin(pin) {
|
|
241
304
|
return (pin.id === PRIVATE_CONTRACT_PIN.id &&
|
|
242
305
|
pin.version === PRIVATE_CONTRACT_PIN.version &&
|
|
243
306
|
pin.contentDigest === PRIVATE_CONTRACT_PIN.contentDigest);
|
|
244
307
|
}
|
|
308
|
+
export function isPresentationContractV2Pin(pin) {
|
|
309
|
+
return (pin.id === PRIVATE_CONTRACT_V2_PIN.id &&
|
|
310
|
+
pin.version === PRIVATE_CONTRACT_V2_PIN.version &&
|
|
311
|
+
pin.contentDigest === PRIVATE_CONTRACT_V2_PIN.contentDigest);
|
|
312
|
+
}
|
|
245
313
|
export function isPresentationSchemaPin(pin) {
|
|
246
314
|
return (pin.id === PRIVATE_PRESENTATION_SCHEMA_PIN.id &&
|
|
247
315
|
pin.version === PRIVATE_PRESENTATION_SCHEMA_PIN.version &&
|
|
248
316
|
pin.contentDigest === PRIVATE_PRESENTATION_SCHEMA_PIN.contentDigest);
|
|
249
317
|
}
|
|
318
|
+
export function isPresentationSchemaV2Pin(pin) {
|
|
319
|
+
return (pin.id === PRIVATE_PRESENTATION_V2_SCHEMA_PIN.id &&
|
|
320
|
+
pin.version === PRIVATE_PRESENTATION_V2_SCHEMA_PIN.version &&
|
|
321
|
+
pin.contentDigest === PRIVATE_PRESENTATION_V2_SCHEMA_PIN.contentDigest);
|
|
322
|
+
}
|
|
250
323
|
/** G0 family pin for a DS profile (explicit native/pin mapping, §7.4.2). */
|
|
251
324
|
export function familyPinForProfile(profile) {
|
|
252
325
|
const shortId = profile.id.includes("@") ? profile.id.slice(0, profile.id.indexOf("@")) : profile.id;
|
package/dist/validate.js
CHANGED
|
@@ -24,7 +24,7 @@ import { hashContent } from "./hash.js";
|
|
|
24
24
|
import { entityTypeOf, portTypeOf, qualifyAttributeSchema, relationTypeOf, roleOf, selectGroupingHierarchy, validateProfile, } from "./profile.js";
|
|
25
25
|
import { parseRef, refKindOf, } from "./refs.js";
|
|
26
26
|
import { createTypeResolver } from "./resolver.js";
|
|
27
|
-
import {
|
|
27
|
+
import { isPresentationContractProfileId } from "./presentation.js";
|
|
28
28
|
import { validateDiagramPresentation } from "./presentation-relations.js";
|
|
29
29
|
import { analyzeSummaries, classifyInternalRelations, collapsedOf, drawnTargetOf, hiddenByFold, parentOccurrenceOf, portRepresentativeOf, representativeOf, } from "./fold.js";
|
|
30
30
|
/** Base type attributes plus the additive attributes of a document type definition. */
|
|
@@ -1299,27 +1299,32 @@ export function validateDocument(document, options) {
|
|
|
1299
1299
|
if (typeof document !== "object" || document === null) {
|
|
1300
1300
|
return [diagnostic({ code: "document-not-an-object", path: "document", message: "a document is an object" })];
|
|
1301
1301
|
}
|
|
1302
|
-
|
|
1303
|
-
document.profileRefs.
|
|
1302
|
+
const contractProfileRef = Array.isArray(document.profileRefs)
|
|
1303
|
+
? document.profileRefs.find((id) => isPresentationContractProfileId(id))
|
|
1304
|
+
: undefined;
|
|
1305
|
+
if (contractProfileRef !== undefined) {
|
|
1304
1306
|
return [
|
|
1305
1307
|
diagnostic({
|
|
1306
1308
|
code: "unknown-profile",
|
|
1307
1309
|
severity: "error",
|
|
1308
1310
|
path: "profileRefs",
|
|
1309
|
-
message: `profile ${
|
|
1310
|
-
details: { profile:
|
|
1311
|
+
message: `profile ${contractProfileRef} is not a diagram profile; ${contractProfileRef} is a contract artifact, not a semantic profile`,
|
|
1312
|
+
details: { profile: contractProfileRef },
|
|
1311
1313
|
}),
|
|
1312
1314
|
];
|
|
1313
1315
|
}
|
|
1314
|
-
|
|
1315
|
-
options.bindings.rows.
|
|
1316
|
+
const contractBindingRow = options.bindings !== undefined
|
|
1317
|
+
? options.bindings.rows.find((row) => isPresentationContractProfileId(row.profileId))
|
|
1318
|
+
: undefined;
|
|
1319
|
+
if (contractBindingRow !== undefined) {
|
|
1320
|
+
const profileId = contractBindingRow.profileId;
|
|
1316
1321
|
return [
|
|
1317
1322
|
diagnostic({
|
|
1318
1323
|
code: "type-definition-conflict",
|
|
1319
1324
|
severity: "error",
|
|
1320
|
-
path: `bindings.${
|
|
1321
|
-
message: `executor binding for ${
|
|
1322
|
-
details: { profile:
|
|
1325
|
+
path: `bindings.${profileId}`,
|
|
1326
|
+
message: `executor binding for ${profileId} is refused; a contract artifact is never a family layer`,
|
|
1327
|
+
details: { profile: profileId },
|
|
1323
1328
|
}),
|
|
1324
1329
|
];
|
|
1325
1330
|
}
|
|
@@ -2010,6 +2015,17 @@ export function validateView(view, document, options, hidden) {
|
|
|
2010
2015
|
message: `zoom ${view.presentation.camera.zoom} must be strictly positive`,
|
|
2011
2016
|
}));
|
|
2012
2017
|
}
|
|
2018
|
+
if (view.presentation.anatomy !== undefined &&
|
|
2019
|
+
view.presentation.anatomy !== "v1" &&
|
|
2020
|
+
view.presentation.anatomy !== "v2") {
|
|
2021
|
+
diagnostics.push(diagnostic({
|
|
2022
|
+
code: "occurrence-endpoint-mismatch",
|
|
2023
|
+
severity: "error",
|
|
2024
|
+
path: "presentation.anatomy",
|
|
2025
|
+
message: `anatomy ${String(view.presentation.anatomy)} must be "v1" or "v2"`,
|
|
2026
|
+
details: { check: "presentation-shape-invalid" },
|
|
2027
|
+
}));
|
|
2028
|
+
}
|
|
2013
2029
|
if (view.presentation.diagram !== undefined) {
|
|
2014
2030
|
diagnostics.push(...validateDiagramPresentation(document, view, options));
|
|
2015
2031
|
}
|
package/dist/view.d.ts
CHANGED
|
@@ -170,6 +170,8 @@ export type ViewFilter = {
|
|
|
170
170
|
* adapter maps these three numbers to its own camera contract; that adapter is
|
|
171
171
|
* GD-M2-CANVAS work, not this lot's.
|
|
172
172
|
*/
|
|
173
|
+
/** Versioned card/zone anatomy pinned by a view (DE-1). Absent means legacy `"v1"`. */
|
|
174
|
+
export type DiagramAnatomyVersion = "v1" | "v2";
|
|
173
175
|
export interface PresentationState {
|
|
174
176
|
readonly camera: {
|
|
175
177
|
readonly x: number;
|
|
@@ -182,6 +184,8 @@ export interface PresentationState {
|
|
|
182
184
|
};
|
|
183
185
|
/** A theme id the host resolves. No colour, no token value is stored here. */
|
|
184
186
|
readonly theme?: string;
|
|
187
|
+
/** Pinned card/zone anatomy (`diagram-anatomy/v1 | v2`). Absent means legacy `"v1"`; `"v2"` is opt-in. */
|
|
188
|
+
readonly anatomy?: DiagramAnatomyVersion;
|
|
185
189
|
/** Typed presentation fragment (M3 §3.2.2). Absent means no presentation contract. */
|
|
186
190
|
readonly diagram?: DiagramPresentation;
|
|
187
191
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/diagram-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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"
|