@sentropic/diagram-core 0.0.0-stage → 0.1.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 (70) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE.THIRD-PARTY.md +28 -0
  3. package/README.md +212 -2
  4. package/dist/archimate-cases.d.ts +11 -0
  5. package/dist/archimate-cases.js +30 -0
  6. package/dist/attributes.d.ts +133 -0
  7. package/dist/attributes.js +313 -0
  8. package/dist/bindings.d.ts +81 -0
  9. package/dist/bindings.js +224 -0
  10. package/dist/canonical.d.ts +47 -0
  11. package/dist/canonical.js +117 -0
  12. package/dist/commands.d.ts +279 -0
  13. package/dist/commands.js +1192 -0
  14. package/dist/diagnostics.d.ts +63 -0
  15. package/dist/diagnostics.js +30 -0
  16. package/dist/document.d.ts +153 -0
  17. package/dist/document.js +58 -0
  18. package/dist/fold.d.ts +156 -0
  19. package/dist/fold.js +723 -0
  20. package/dist/hash.d.ts +19 -0
  21. package/dist/hash.js +56 -0
  22. package/dist/index.d.ts +32 -0
  23. package/dist/index.js +32 -0
  24. package/dist/migrate.d.ts +69 -0
  25. package/dist/migrate.js +402 -0
  26. package/dist/multiplicity.d.ts +31 -0
  27. package/dist/multiplicity.js +36 -0
  28. package/dist/presentation-apply.d.ts +32 -0
  29. package/dist/presentation-apply.js +257 -0
  30. package/dist/presentation-catalog.d.ts +217 -0
  31. package/dist/presentation-catalog.js +263 -0
  32. package/dist/presentation-pinned-adapter.d.ts +7 -0
  33. package/dist/presentation-pinned-adapter.js +7 -0
  34. package/dist/presentation-validate.d.ts +13 -0
  35. package/dist/presentation-validate.js +798 -0
  36. package/dist/presentation.d.ts +145 -0
  37. package/dist/presentation.js +266 -0
  38. package/dist/profile-migrations.d.ts +83 -0
  39. package/dist/profile-migrations.js +959 -0
  40. package/dist/profile.d.ts +211 -0
  41. package/dist/profile.js +679 -0
  42. package/dist/profiles/archimate-matrix.d.ts +31 -0
  43. package/dist/profiles/archimate-matrix.js +111 -0
  44. package/dist/profiles/archimate2.d.ts +21 -0
  45. package/dist/profiles/archimate2.js +126 -0
  46. package/dist/profiles/generic.d.ts +14 -0
  47. package/dist/profiles/generic.js +111 -0
  48. package/dist/profiles/generic2.d.ts +20 -0
  49. package/dist/profiles/generic2.js +161 -0
  50. package/dist/profiles/index.d.ts +38 -0
  51. package/dist/profiles/index.js +87 -0
  52. package/dist/profiles/skeletons.d.ts +32 -0
  53. package/dist/profiles/skeletons.js +225 -0
  54. package/dist/profiles/uml2.d.ts +11 -0
  55. package/dist/profiles/uml2.js +138 -0
  56. package/dist/refs.d.ts +112 -0
  57. package/dist/refs.js +139 -0
  58. package/dist/resolver.d.ts +50 -0
  59. package/dist/resolver.js +259 -0
  60. package/dist/sha256.d.ts +16 -0
  61. package/dist/sha256.js +190 -0
  62. package/dist/state.d.ts +20 -0
  63. package/dist/state.js +23 -0
  64. package/dist/validate.d.ts +64 -0
  65. package/dist/validate.js +1992 -0
  66. package/dist/view-schema-pin.d.ts +51 -0
  67. package/dist/view-schema-pin.js +159 -0
  68. package/dist/view.d.ts +219 -0
  69. package/dist/view.js +81 -0
  70. package/package.json +32 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rhanka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,28 @@
1
+ <!-- GÉNÉRÉ par scripts/generate-third-party-notices.mjs — ne pas éditer à la main. -->
2
+ <!-- Régénérer : `npm run notices:generate`. La dérive fait échouer `npm run licensing:check`. -->
3
+
4
+ # Notices de tiers — `@sentropic/diagram-core`
5
+
6
+ Licence de ce paquet : **MIT** — voir `LICENSE`.
7
+ Ce fichier couvre le code **tiers**, et lui seul.
8
+
9
+ Périmètre, littéralement : le code tiers recopié dans ce paquet (§1) et la
10
+ fermeture transitive de ses dépendances d'exécution (§2). Hors périmètre, et
11
+ c'est délibéré : les `peerDependencies`, fournies par le consommateur, et les
12
+ `devDependencies`, qui n'entrent dans aucun tarball.
13
+
14
+ ## 1. Code tiers recopié dans ce paquet
15
+
16
+ **Rien de mesuré.** Ce qui a été cherché, littéralement : les données de
17
+ tracé publiées par `lucide`, comparées octet pour octet aux sources de ce
18
+ paquet. Aucune n'y figure.
19
+
20
+ Ce qui n'a **pas** été cherché : tout amont non déclaré dans
21
+ `scripts/third-party-sources.json`. L'absence ci-dessus est donc l'absence
22
+ de ces données-là, et non un constat d'absence générale de code tiers dans
23
+ ce paquet.
24
+
25
+ ## 2. Dépendances installées avec ce paquet
26
+
27
+ Aucune. Ce paquet ne déclare aucune dépendance tierce : installer ce paquet
28
+ n'installe aucun code tiers de notre fait.
package/README.md CHANGED
@@ -1,3 +1,213 @@
1
- # Temporary Holding Version
1
+ # @sentropic/diagram-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The typed semantic core of the diagram programme: versioned documents and
4
+ profiles, views with occurrences, and transactional commands that return their
5
+ logical inverse. No runtime dependency, no DOM, no framework, no renderer.
6
+
7
+ This package is public as `@sentropic/diagram-core` (0.1.0, first publication).
8
+ Pin the exact version — never a range, never `latest`. Publication is CI-only
9
+ through `.github/workflows/diagram-core-publish.yml` on tags `diagram-core-v<version>`.
10
+
11
+ ## The five objects, and which two live here
12
+
13
+ | Object | Where it lives |
14
+ |---|---|
15
+ | `SemanticDocument` — business truth | **here** |
16
+ | `ViewDocument` — drawings of that truth | **here** |
17
+ | `ProcessingSnapshot` — normalised input of a layout | `@sentropic/graph/processing` |
18
+ | `Scene` / `GeometryFrame` — what a backend draws | GD-M2-CANVAS, not written |
19
+ | `TextSource` — imported text with its AST and spans | GD-M4 codecs, not written |
20
+
21
+ ## The model
22
+
23
+ ### References are nominal, and they say their own namespace
24
+
25
+ Seven reference types, none assignable to another: `EntityRef`, `RelationRef`,
26
+ `OccurrenceRef`, `PortRef`, `ViewRef`, `ResourceRef`, `DocumentRef`. The brand is
27
+ a phantom property keyed by a module-private `unique symbol`, so nothing of it
28
+ survives compilation; at runtime a reference carries its identity namespace as a
29
+ prefix (`entity:alpha`, `occurrence:alpha-1`), which is how a function that
30
+ expects an occurrence refuses an entity that crossed a file or process boundary —
31
+ with a `reference-type-mismatch` diagnostic, not a silent misread.
32
+
33
+ The spec names five. `RelationRef` and `DocumentRef` are declared because a
34
+ relation occurrence points at a relation and a view at a document; typing either
35
+ as `EntityRef` would be exactly the mis-typing the rule exists to prevent.
36
+
37
+ ### A document is a schema, not a bag
38
+
39
+ An entity is discriminated by `profile` **and** `type`, and every attribute is
40
+ read through the schema of that type: `text`, `boolean`, `date` (ISO-8601),
41
+ `quantity` (a magnitude **and** its unit), `enum`, `reference` (with the
42
+ namespace it must carry) or a **bounded** `collection` — `maxItems` is required,
43
+ because an unbounded list is how a schema becomes a bag. An attribute the schema
44
+ does not declare is refused; unmodelled content belongs in an extension.
45
+
46
+ A relation has two or more endpoints, each with a **role** declared by its type,
47
+ a cardinality per role and a declared set of legal targets. A hyperrelation
48
+ (`generic@1`'s `association`, 2..8 members) keeps one business id, which is what
49
+ lets a projection turn it into a junction node without losing it.
50
+
51
+ A semantic port belongs to an entity and has a direction. Its side, order and
52
+ anchor are geometric and live on the **port occurrence** in a view.
53
+
54
+ Collections are records keyed by the element's own reference. Insertion order is
55
+ therefore never content, and every order that matters is an explicit field
56
+ (`PortOccurrence.order`, `EntityOccurrence.z`).
57
+
58
+ ### Profiles are versioned schema modules
59
+
60
+ `generic@1` is the only **complete** profile of this lot. `bpmn@1`,
61
+ `archimate@1` and `uml@1` are declared **skeletons**: they carry
62
+ `completeness: "skeleton"`, their types and relation arity are declared and
63
+ validated by the same machinery, their qualification fixtures are partial, and
64
+ each lists in `notes` what it does **not** declare. **No BPMN, ArchiMate or UML
65
+ conformance is claimed anywhere in this package.** The native profiles are GD-M3.
66
+
67
+ ### A view holds drawings, never facts
68
+
69
+ One entity has N occurrences in a view and occurrences in several views. Removing
70
+ an occurrence removes a drawing. Deleting the **entity** requires an explicit
71
+ policy for its occurrences, its relations and its ports — the field is mandatory
72
+ in the type and a malformed one is `delete-policy-required` at runtime. A visual
73
+ group declares itself and membership lives on the occurrence (`group`), so there
74
+ is one source of truth for it.
75
+
76
+ The persisted presentation state holds a camera (`x`, `y`, `zoom`) and an
77
+ optional grid. It is stored here, and deliberately not imported from a renderer
78
+ package: a migration-versioned persisted schema must not be hostage to another
79
+ package's type evolution.
80
+
81
+ ### Commands are transactions
82
+
83
+ `applyTransaction(state, transaction, { registry })` returns either
84
+ `{ status: "applied", state, effects, inverse }` or
85
+ `{ status: "rejected", diagnostics }`.
86
+
87
+ - **No partial success.** Commands run on a working copy, the final state is
88
+ validated once, and any refusal throws the whole copy away. The caller's state
89
+ is never mutated.
90
+ - **Revision conflicts are explicit.** `baseRevision` must be the state's
91
+ revision; otherwise `revision-conflict`, carrying `expected` and `seen`.
92
+ - **One counter.** A transaction bumps `document.revision` by one and stamps the
93
+ views it touched with that revision, so a view is never ahead of its document.
94
+ - **An inverse, or a reason.** Every one of the 18 commands returns a logical
95
+ inverse built from the pre-image it captured. `non-invertible` is returned when
96
+ a cascade's inverse would exceed the declared `inverseBudget`, with the budget
97
+ in the reason: an unbounded inverse is an unbounded cost on the host's undo
98
+ stack.
99
+ - **Undo is a new transaction**, replayed against the current revision, never a
100
+ rewrite of the journal. After a command and its inverse the content is
101
+ identical and the revision is two ahead — which is why the round-trip tests
102
+ compare `serialiseContent` (revisions normalised) and assert the revision
103
+ arithmetic separately.
104
+
105
+ The 18th command, `remove-preserved-extension`, is an addition to the spec's list
106
+ of seventeen: adding an extension can only be undone by removing one, and no
107
+ command in the list removed one.
108
+
109
+ ### Canonical form
110
+
111
+ `serialiseState` / `serialiseDocument` produce sorted-key JSON with no
112
+ whitespace. A function, a non-finite number, a `BigInt`, a symbol or a cycle is
113
+ **refused** with a diagnostic rather than silently turned into `null`. That
114
+ refusal is also what keeps a function out of a document.
115
+
116
+ `hashContent` is a 64-bit FNV-1a printed as `fnv1a64:<16 hex>`. It is **not
117
+ cryptographic**: it makes drift detectable, it must never gate trust. A real
118
+ digest belongs to the codecs lot, where a hash crosses a trust boundary.
119
+
120
+ ### Migration
121
+
122
+ A stored version is migrated only by a registered, versioned function, which
123
+ returns a report: `from`, `to`, the operations it performed, the items it could
124
+ not carry over **with a reason each**, and the original bytes with their hash.
125
+ This build knows `1.0 -> 1.1`. An unknown **major** is refused for write and
126
+ preserved for inspection and export (`exportPreserved`).
127
+
128
+ A migration is not a repair. It migrates what it can and says what it could not,
129
+ so a migrated document may still be unwritable — for instance when a value that
130
+ failed to convert was a **required** attribute. The report names the element; the
131
+ decision is the host's.
132
+
133
+ ## What this package does not import
134
+
135
+ Nothing. Not one specifier that is not a relative module of its own source, which
136
+ a test asserts by scanning every file. In particular:
137
+
138
+ - **no `@sentropic/graph`.** SPEC 3.1 allows DOM-free graph contracts and offers
139
+ to create a `@sentropic/graph/contracts` subpath for them. This lot needs none:
140
+ its only candidate consumer would be the persisted view schema, and binding a
141
+ migration-versioned persisted schema to another package's evolving types is
142
+ what the migration rule exists to prevent. `@sentropic/graph/processing` already
143
+ exists and is DOM-free, and contains nothing this package consumes. The
144
+ `diagram-core -> graph` edge of `docs/graph-dataviz-architecture-dag.json`
145
+ stays `"status": "proposed"`, which is what that file already says.
146
+ - **no DOM.** Enforced by the compiler first: `tsconfig.json` gives `src`
147
+ `lib: ["ES2022"]` and `types: []`, so `document`, `window` and every node
148
+ builtin are unresolvable names. Then by tests: the barrel is imported in Node
149
+ with no jsdom, with a throwing proxy installed as `document`/`window`, and the
150
+ source is scanned for those identifiers in executable code.
151
+ - **no renderer, no WebGL, no framework, no design system package.**
152
+
153
+ ## What is not covered yet
154
+
155
+ - **Projection** (study invariant 7): this package produces no projection,
156
+ no geometry and no layout. `LayoutOutcome.inverse` in
157
+ `@sentropic/graph/processing` already carries the origin → projected index →
158
+ result correspondence; the scene side is GD-M2-CANVAS.
159
+ - **The world → view → CSS pixel → device pixel transform contract** (second half
160
+ of invariant 8): a rendering contract. This package persists a camera and finite
161
+ geometry and exposes no transform composition, no `devicePixelRatio` and no hit
162
+ testing.
163
+ - **Codecs, source text, AST/CST and conversion reports**: GD-M4. Nothing here
164
+ parses, fetches or executes imported content, a URI or markup.
165
+ - **Native BPMN / ArchiMate / UML profiles**: GD-M3. See the skeletons' `notes`.
166
+ - **A reference disposition in the delete policy.** The policy governs
167
+ occurrences, relations and ports. An entity a typed reference attribute still
168
+ points at cannot be deleted: the transaction refuses itself on the final state
169
+ (`dangling-reference`) rather than clearing someone's attribute. "Clear",
170
+ "refuse" or "reassign" as an explicit choice is a later decision.
171
+ - **Filter evaluation, and commands over groups and filters.** A view's groups and
172
+ filters are declared, validated and persisted here; nothing in this lot decides
173
+ what a filter hides, nor what happens to a relation whose endpoint is hidden,
174
+ and no command of this lot edits a group or a filter. Both are GD-M2-CANVAS.
175
+ - **Selection, geometric port editing and annotations**: GD-M2-CANVAS, by SPEC 3.5.
176
+ - **A cryptographic content hash**: see `hash.ts`.
177
+ - **Concurrency beyond compare-and-swap semantics.** `revision-conflict` is a
178
+ refusal, not a merge. No conflict resolution, no CRDT, no operational transform.
179
+
180
+ ## Layout
181
+
182
+ ```
183
+ src/refs.ts the seven nominal reference types, their guards and diagnostics
184
+ src/diagnostics.ts one code per refusal; nothing returns a boolean validity
185
+ src/attributes.ts typed attribute values and their schemas
186
+ src/profile.ts profile declarations, registry, and profile self-validation
187
+ src/profiles/ generic@1 (complete), bpmn@1 / archimate@1 / uml@1 (skeletons)
188
+ src/document.ts SemanticDocument, entities, relations, ports, resources, extensions
189
+ src/view.ts ViewDocument, the three occurrence kinds, groups, filters, presentation
190
+ src/state.ts { document, views } - the transactional unit
191
+ src/canonical.ts canonical JSON and content serialisation
192
+ src/hash.ts fnv1a64, dependency-free, non-cryptographic
193
+ src/validate.ts every refusal, including the nine named rejected cases
194
+ src/commands.ts 18 commands, transactions, effects, inverses
195
+ src/migrate.ts registered migrations and their reports
196
+ fixtures/ valid documents, a divergent-revision state, a command
197
+ sequence, the nine rejected cases, a 1.0 stored document
198
+ tests/ 10 suites; `refs-nominal.test.ts` is a COMPILER test
199
+ ```
200
+
201
+ ## Gates
202
+
203
+ ```
204
+ npm run --workspace @sentropic/diagram-core build # tsc -> dist
205
+ npm run --workspace @sentropic/diagram-core check # tsc over src AND tests
206
+ npm run --workspace @sentropic/diagram-core test # vitest, node environment
207
+ ```
208
+
209
+ `check` compiles the tests on purpose: `tests/refs-nominal.test.ts` proves the
210
+ reference types are not interchangeable with one `@ts-expect-error` per
211
+ illegitimate assignment (42 ordered pairs). Those assertions only mean something
212
+ if a compiler reads them. Remove the brand from `Ref<K>` and `check` reports 42
213
+ × TS2578 ("Unused '@ts-expect-error' directive") — measured, not assumed.
@@ -0,0 +1,11 @@
1
+ import type { ArchimateTuple } from "./profiles/archimate2.js";
2
+ export interface ArchimatePairCase {
3
+ readonly relationType: string;
4
+ readonly sourceType: string;
5
+ readonly targetType: string;
6
+ readonly expected: "allowed" | "rejected";
7
+ }
8
+ /** @deprecated Use ArchimatePairCase (renamed to keep the no-transform invariant). */
9
+ export type ArchimateMatrixCase = ArchimatePairCase;
10
+ export declare function buildArchimatePairCases(tuples: readonly ArchimateTuple[], relationshipIds: readonly string[]): ArchimatePairCase[];
11
+ //# sourceMappingURL=archimate-cases.d.ts.map
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Deterministic ArchiMate matrix case builder (spec A.4).
3
+ *
4
+ * The finite closed corpus: 62 ordered concept pairs × 11 relation ids =
5
+ * 42,284 cases. Each expanded tuple yields an allowed case; every absent
6
+ * tuple yields a rejection. `@relation` witnesses use real relation
7
+ * targets, never entity stubs.
8
+ */
9
+ import { ARCHIMATE_CONCEPT_NAMES } from "./profiles/archimate-matrix.js";
10
+ const typeIdOf = (name) => name === "Relationship" ? "@relation" : name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
11
+ export function buildArchimatePairCases(tuples, relationshipIds) {
12
+ const allowed = new Set(tuples.map((t) => `${t.relationType}\0${t.sourceType}\0${t.targetType}`));
13
+ const cases = [];
14
+ for (const sourceName of ARCHIMATE_CONCEPT_NAMES) {
15
+ for (const targetName of ARCHIMATE_CONCEPT_NAMES) {
16
+ for (const relationType of relationshipIds) {
17
+ const sourceType = typeIdOf(sourceName);
18
+ const targetType = typeIdOf(targetName);
19
+ cases.push({
20
+ relationType,
21
+ sourceType,
22
+ targetType,
23
+ expected: allowed.has(`${relationType}\0${sourceType}\0${targetType}`) ? "allowed" : "rejected",
24
+ });
25
+ }
26
+ }
27
+ }
28
+ return cases;
29
+ }
30
+ //# sourceMappingURL=archimate-cases.js.map
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Typed attributes. SPEC 3.3: "attributs typés selon le schéma du profil
3
+ * (quantité+unité, énumération, référence, texte, date, booléen, collection
4
+ * bornée) - jamais un dictionnaire libre."
5
+ *
6
+ * Two consequences that shape everything below:
7
+ * - a VALUE carries its kind, so a number is never silently read as a
8
+ * quantity: a quantity without a unit is `quantity-unit-missing`, which is
9
+ * one of the nine named rejected cases;
10
+ * - a SCHEMA is required to read a value. There is no "any attribute"
11
+ * escape. Content a profile does not declare is not an attribute; it is an
12
+ * extension (see extensions in `document.ts`), preserved with its hash and
13
+ * never promoted to a business fact (decision D3-C).
14
+ */
15
+ import { type Diagnostic } from "./diagnostics.js";
16
+ import { type RefKind } from "./refs.js";
17
+ export type ScalarAttributeKind = "text" | "boolean" | "date" | "quantity" | "enum" | "reference";
18
+ export type AttributeKind = ScalarAttributeKind | "collection" | "struct";
19
+ export type ScalarAttributeValue = {
20
+ readonly kind: "text";
21
+ readonly value: string;
22
+ } | {
23
+ readonly kind: "boolean";
24
+ readonly value: boolean;
25
+ }
26
+ /** ISO-8601 calendar date or date-time, as text. No date object: the model stays serialisable. */
27
+ | {
28
+ readonly kind: "date";
29
+ readonly value: string;
30
+ }
31
+ /** A magnitude AND its unit. Neither half is optional. */
32
+ | {
33
+ readonly kind: "quantity";
34
+ readonly value: number;
35
+ readonly unit: string;
36
+ } | {
37
+ readonly kind: "enum";
38
+ readonly value: string;
39
+ }
40
+ /** A raw reference string; the namespace it must carry is declared by the schema. */
41
+ | {
42
+ readonly kind: "reference";
43
+ readonly value: string;
44
+ };
45
+ export type AttributeValue = ScalarAttributeValue | StructAttributeValue | {
46
+ readonly kind: "collection";
47
+ readonly items: readonly ScalarAttributeValue[];
48
+ };
49
+ /**
50
+ * A structured value (K6 carrier). `type` names a profile-declared structured
51
+ * type; `fields` carries the nested attribute values, validated against that
52
+ * type's declared field schemas. It has no entity identity: an entity record
53
+ * can never instantiate an abstract structured type.
54
+ */
55
+ export type StructAttributeValue = {
56
+ readonly kind: "struct";
57
+ readonly type: string;
58
+ readonly fields: Readonly<Record<string, AttributeValue>>;
59
+ };
60
+ export type TextSchema = {
61
+ readonly kind: "text";
62
+ readonly maxLength?: number;
63
+ /** Minimum length. A present value below it is refused (pattern "min-length"). */
64
+ readonly minLength?: number;
65
+ /** Anchored ASCII RegExp source, no flags. `patternName` is required with it. */
66
+ readonly pattern?: string;
67
+ readonly patternName?: string;
68
+ };
69
+ export type QuantitySchema = {
70
+ readonly kind: "quantity";
71
+ readonly units: readonly string[];
72
+ /** When true, only integers validate; a fraction is refused. */
73
+ readonly integer?: boolean;
74
+ readonly min?: number;
75
+ readonly max?: number;
76
+ };
77
+ export type ReferenceSchema = {
78
+ readonly kind: "reference";
79
+ readonly refKind: RefKind;
80
+ /** K2 target types: the referenced entity's resolved chain must contain one. */
81
+ readonly targetTypes?: readonly string[];
82
+ };
83
+ /** A structured-value slot (K6 carrier): only the named types are allowed here. */
84
+ export type StructSchema = {
85
+ readonly kind: "struct";
86
+ readonly targetTypes: readonly string[];
87
+ };
88
+ export type ScalarSchema = TextSchema | {
89
+ readonly kind: "boolean";
90
+ } | {
91
+ readonly kind: "date";
92
+ }
93
+ /** The units a quantity may use. A one-unit list is how a profile pins a unit. */
94
+ | QuantitySchema | {
95
+ readonly kind: "enum";
96
+ readonly values: readonly string[];
97
+ } | ReferenceSchema;
98
+ /**
99
+ * A collection is ALWAYS bounded: `maxItems` is required, because "collection
100
+ * bornée" is the contract and an unbounded list is how a schema becomes a bag.
101
+ */
102
+ export type CollectionSchema = {
103
+ readonly kind: "collection";
104
+ readonly item: ScalarSchema;
105
+ readonly maxItems: number;
106
+ readonly minItems?: number;
107
+ };
108
+ export type AttributeSchema = {
109
+ readonly name: string;
110
+ readonly required?: boolean;
111
+ } & (ScalarSchema | CollectionSchema | StructSchema);
112
+ /**
113
+ * Validate ONE attribute value against its schema. Resolution of reference
114
+ * values against the document is NOT done here (this module knows nothing about
115
+ * documents); `validate.ts` resolves them and reports `dangling-reference`.
116
+ */
117
+ export declare function validateAttributeValue(schema: AttributeSchema, value: AttributeValue, path: string): readonly Diagnostic[];
118
+ /** Every reference a value carries, with the namespace its schema requires. */
119
+ export declare function referencesOf(schema: AttributeSchema, value: AttributeValue): readonly {
120
+ readonly raw: string;
121
+ readonly refKind: RefKind;
122
+ readonly index?: number;
123
+ }[];
124
+ /** Convenience constructors, so fixtures and tests read as data, not as casts. */
125
+ export declare const text: (value: string) => AttributeValue;
126
+ export declare const boolean: (value: boolean) => AttributeValue;
127
+ export declare const date: (value: string) => AttributeValue;
128
+ export declare const quantity: (value: number, unit: string) => AttributeValue;
129
+ export declare const enumeration: (value: string) => AttributeValue;
130
+ export declare const reference: (value: string) => AttributeValue;
131
+ export declare const collection: (items: readonly ScalarAttributeValue[]) => AttributeValue;
132
+ export declare const structValue: (type: string, fields: Readonly<Record<string, AttributeValue>>) => AttributeValue;
133
+ //# sourceMappingURL=attributes.d.ts.map