@grafctory/blue 0.0.0-stage → 0.16.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 (139) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +524 -2
  3. package/dist/boolean/assembler.d.ts +53 -0
  4. package/dist/boolean/assembler.d.ts.map +1 -0
  5. package/dist/boolean/assembler.js +78 -0
  6. package/dist/boolean/assembler.js.map +1 -0
  7. package/dist/boolean/index.d.ts +86 -0
  8. package/dist/boolean/index.d.ts.map +1 -0
  9. package/dist/boolean/index.js +99 -0
  10. package/dist/boolean/index.js.map +1 -0
  11. package/dist/boolean/validator.d.ts +30 -0
  12. package/dist/boolean/validator.d.ts.map +1 -0
  13. package/dist/boolean/validator.js +68 -0
  14. package/dist/boolean/validator.js.map +1 -0
  15. package/dist/dictionary/assembler.d.ts +70 -0
  16. package/dist/dictionary/assembler.d.ts.map +1 -0
  17. package/dist/dictionary/assembler.js +178 -0
  18. package/dist/dictionary/assembler.js.map +1 -0
  19. package/dist/dictionary/index.d.ts +237 -0
  20. package/dist/dictionary/index.d.ts.map +1 -0
  21. package/dist/dictionary/index.js +43 -0
  22. package/dist/dictionary/index.js.map +1 -0
  23. package/dist/dictionary/inference.d.ts +42 -0
  24. package/dist/dictionary/inference.d.ts.map +1 -0
  25. package/dist/dictionary/inference.js +17 -0
  26. package/dist/dictionary/inference.js.map +1 -0
  27. package/dist/dictionary/validator.d.ts +37 -0
  28. package/dist/dictionary/validator.d.ts.map +1 -0
  29. package/dist/dictionary/validator.js +106 -0
  30. package/dist/dictionary/validator.js.map +1 -0
  31. package/dist/index.core.d.ts +33 -0
  32. package/dist/index.core.d.ts.map +1 -0
  33. package/dist/index.core.js +149 -0
  34. package/dist/index.core.js.map +1 -0
  35. package/dist/index.d.ts +333 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +378 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/number/assembler.d.ts +70 -0
  40. package/dist/number/assembler.d.ts.map +1 -0
  41. package/dist/number/assembler.js +188 -0
  42. package/dist/number/assembler.js.map +1 -0
  43. package/dist/number/index.d.ts +329 -0
  44. package/dist/number/index.d.ts.map +1 -0
  45. package/dist/number/index.js +312 -0
  46. package/dist/number/index.js.map +1 -0
  47. package/dist/number/validator.d.ts +31 -0
  48. package/dist/number/validator.d.ts.map +1 -0
  49. package/dist/number/validator.js +57 -0
  50. package/dist/number/validator.js.map +1 -0
  51. package/dist/reference/accessors.d.ts +29 -0
  52. package/dist/reference/accessors.d.ts.map +1 -0
  53. package/dist/reference/accessors.js +38 -0
  54. package/dist/reference/accessors.js.map +1 -0
  55. package/dist/reference/assembler.d.ts +63 -0
  56. package/dist/reference/assembler.d.ts.map +1 -0
  57. package/dist/reference/assembler.js +127 -0
  58. package/dist/reference/assembler.js.map +1 -0
  59. package/dist/reference/index.d.ts +108 -0
  60. package/dist/reference/index.d.ts.map +1 -0
  61. package/dist/reference/index.js +40 -0
  62. package/dist/reference/index.js.map +1 -0
  63. package/dist/reference/validator.d.ts +33 -0
  64. package/dist/reference/validator.d.ts.map +1 -0
  65. package/dist/reference/validator.js +56 -0
  66. package/dist/reference/validator.js.map +1 -0
  67. package/dist/resource/accessors.d.ts +140 -0
  68. package/dist/resource/accessors.d.ts.map +1 -0
  69. package/dist/resource/accessors.js +173 -0
  70. package/dist/resource/accessors.js.map +1 -0
  71. package/dist/resource/assembler.d.ts +265 -0
  72. package/dist/resource/assembler.d.ts.map +1 -0
  73. package/dist/resource/assembler.js +816 -0
  74. package/dist/resource/assembler.js.map +1 -0
  75. package/dist/resource/index.d.ts +903 -0
  76. package/dist/resource/index.d.ts.map +1 -0
  77. package/dist/resource/index.js +160 -0
  78. package/dist/resource/index.js.map +1 -0
  79. package/dist/resource/inference.d.ts +310 -0
  80. package/dist/resource/inference.d.ts.map +1 -0
  81. package/dist/resource/inference.js +17 -0
  82. package/dist/resource/inference.js.map +1 -0
  83. package/dist/resource/validator.d.ts +158 -0
  84. package/dist/resource/validator.d.ts.map +1 -0
  85. package/dist/resource/validator.js +1013 -0
  86. package/dist/resource/validator.js.map +1 -0
  87. package/dist/string/assembler.d.ts +69 -0
  88. package/dist/string/assembler.d.ts.map +1 -0
  89. package/dist/string/assembler.js +143 -0
  90. package/dist/string/assembler.js.map +1 -0
  91. package/dist/string/index.d.ts +431 -0
  92. package/dist/string/index.d.ts.map +1 -0
  93. package/dist/string/index.js +528 -0
  94. package/dist/string/index.js.map +1 -0
  95. package/dist/string/validator.d.ts +30 -0
  96. package/dist/string/validator.d.ts.map +1 -0
  97. package/dist/string/validator.js +69 -0
  98. package/dist/string/validator.js.map +1 -0
  99. package/dist/union/accessors.d.ts +137 -0
  100. package/dist/union/accessors.d.ts.map +1 -0
  101. package/dist/union/accessors.js +253 -0
  102. package/dist/union/accessors.js.map +1 -0
  103. package/dist/union/assembler.d.ts +56 -0
  104. package/dist/union/assembler.d.ts.map +1 -0
  105. package/dist/union/assembler.js +140 -0
  106. package/dist/union/assembler.js.map +1 -0
  107. package/dist/union/index.d.ts +172 -0
  108. package/dist/union/index.d.ts.map +1 -0
  109. package/dist/union/index.js +45 -0
  110. package/dist/union/index.js.map +1 -0
  111. package/dist/union/inference.d.ts +30 -0
  112. package/dist/union/inference.d.ts.map +1 -0
  113. package/dist/union/inference.js +17 -0
  114. package/dist/union/inference.js.map +1 -0
  115. package/dist/union/validator.d.ts +94 -0
  116. package/dist/union/validator.d.ts.map +1 -0
  117. package/dist/union/validator.js +171 -0
  118. package/dist/union/validator.js.map +1 -0
  119. package/dist/value/accessors.d.ts +151 -0
  120. package/dist/value/accessors.d.ts.map +1 -0
  121. package/dist/value/accessors.js +468 -0
  122. package/dist/value/accessors.js.map +1 -0
  123. package/dist/value/assembler.d.ts +129 -0
  124. package/dist/value/assembler.d.ts.map +1 -0
  125. package/dist/value/assembler.js +248 -0
  126. package/dist/value/assembler.js.map +1 -0
  127. package/dist/value/index.d.ts +309 -0
  128. package/dist/value/index.d.ts.map +1 -0
  129. package/dist/value/index.js +26 -0
  130. package/dist/value/index.js.map +1 -0
  131. package/dist/value/inference.d.ts +292 -0
  132. package/dist/value/inference.d.ts.map +1 -0
  133. package/dist/value/inference.js +17 -0
  134. package/dist/value/inference.js.map +1 -0
  135. package/dist/value/validator.d.ts +76 -0
  136. package/dist/value/validator.d.ts.map +1 -0
  137. package/dist/value/validator.js +111 -0
  138. package/dist/value/validator.js.map +1 -0
  139. package/package.json +95 -4
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Shape accessors.
3
+ *
4
+ * Reads what a shape or a retrieved resource reaches, so that callers don't have to walk it themselves. A shape
5
+ * deferred to break a definition cycle resolves to the shape it states, with inherited members merged in. A path and
6
+ * transform pipe resolve to the range of the values they reach, which types a projection binding or a constraint
7
+ * operand. A slice resolves to the collection property it names and to the shape of the drafts posted to it, and a
8
+ * resource retrieved with a slice gives access to the items of its collection, typed by the slice.
9
+ *
10
+ * @module
11
+ */
12
+ import { type Eager, type Lazy } from "@grafctory/core";
13
+ import { type Issue } from "@grafctory/core/trace";
14
+ import { type Probe } from "@grafctory/qest/model";
15
+ import type { Property, ResourceShape } from "../resource/index.js";
16
+ import { type Items, type Match, type Range, type Shape, type Slice } from "./index.js";
17
+ /**
18
+ * Resolves a possibly deferred shape or range.
19
+ *
20
+ * Yields the shape or range a definition states, resolving a deferred one on first reach and handing back the same
21
+ * value on every later reach, so that a definition stated once compares equal wherever it is reached from. A resource
22
+ * shape comes back merged, so a caller reading its members needs not merge the inheritance chain itself; a range comes
23
+ * back as stated, the shape it carries still possibly deferred.
24
+ *
25
+ * A deferred definition may reach itself only through a link. An embedded resource is carried inline, so a definition
26
+ * that embeds itself, directly or through other embedded resources or unions, admits no finite value and is rejected.
27
+ * A cycle running through several definitions is reported only once all of them have been resolved, in whatever
28
+ * order: resolving the earlier ones succeeds, and the error surfaces on the definition resolved last.
29
+ *
30
+ * @typeParam S The stated shape or range, possibly deferred to break definition cycles
31
+ *
32
+ * @param shape The shape or range to resolve
33
+ *
34
+ * @returns The shape or range `shape` states, merged where it describes a resource
35
+ *
36
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself, leaving the
37
+ * shape it states undefined, where it embeds itself with no link to break the cycle, or where it states a target
38
+ * that doesn't narrow the inherited target overridden by the link it is reached through
39
+ */
40
+ export declare function eager<S extends Lazy<Shape | Range>>(shape: S): Eager<S>;
41
+ /**
42
+ * Resolves the values a probe reaches.
43
+ *
44
+ * Yields the range a {@link Probe | probe} resolves to against a shape: the shapes its values may be drawn from and
45
+ * how many of them it reaches, so that a caller may type a projection binding or a constraint operand without walking
46
+ * the shape itself. A path stepping through several alternatives reaches each in turn, and the range it yields
47
+ * envelopes them all; discrimination to the single branch a value belongs to is settled separately, against the value.
48
+ *
49
+ * **What a path reaches**
50
+ *
51
+ * A path steps across the members of the resources it reaches, crossing a link to the resource it points at and
52
+ * entering each alternative of a union in turn; an alternative lacking the next member is dropped, and the path fails
53
+ * only where none carries it. The members naming and typing a resource are reached as a scalar IRI, so a path may end
54
+ * on one but never step past it. A localised member is likewise terminal.
55
+ *
56
+ * A path taking no step reaches the shape it starts from, as it stands: a link stays a link, reached as the identifier
57
+ * naming its target unless a template expands it, and is crossed only by a step that actually names a member.
58
+ *
59
+ * **What a pipe yields**
60
+ *
61
+ * A pipe applies its transforms to whatever the path reached, dropping an alternative the transforms cannot act on:
62
+ * within a union this keeps the compatible alternatives alone, so a pipe stands as long as one survives. A localised
63
+ * value is read through the content language negotiation settles on, as ordinary text. A transform stating it yields
64
+ * the same type reproduces the input shape verbatim where it keeps values within the domain they were drawn from, and
65
+ * widens to the bare numeric type where it combines them and leaves that domain behind.
66
+ *
67
+ * **How many values it reaches**
68
+ *
69
+ * Bounds accumulate multiplicatively along a path and envelope across alternatives: the lowest lower bound and the
70
+ * highest upper bound win, and an unstated bound absorbs, leaving that end unbounded.
71
+ *
72
+ * A transform applied value by value keeps the bounds as they stand. An aggregate caps the count at one, and it returns
73
+ * a value whenever the path reaches one, so a lower bound of one or more drops to one. An aggregate that always returns
74
+ * a value, such as `count` or `sum`, fixes the count at exactly one, whatever the path reaches.
75
+ *
76
+ * Some pipes may return no value for a resource even though the path reaches one: a pipe dropping an alternative it
77
+ * cannot act on, one reading a localised value through negotiation, and one extracting a temporal component the value
78
+ * doesn't state, as `hours` does from a date. Their lower bound stays unstated unless the pipe always returns a value.
79
+ *
80
+ * @param shape The shape to resolve the probe against or a range already resolved to probe further, either possibly
81
+ * deferred to break definition cycles
82
+ * @param probe The path and transform pipe to resolve
83
+ *
84
+ * @returns The range the probe reaches, or an {@link Issue} stating why it reaches nothing: `"unknown property path"`
85
+ * where the path names a member no alternative carries or steps past one that cannot be stepped past,
86
+ * `"multiple aggregate transforms"` where the pipe combines values more than once, or
87
+ * `"incompatible transform input"` where no alternative survives the transforms
88
+ *
89
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself, leaving the
90
+ * shape it states undefined, where it embeds itself with no link to break the cycle, where it states a target
91
+ * that doesn't narrow the inherited target overridden by the link it is reached through, or where a union
92
+ * the path crosses declares a shared member name inconsistently across its branches
93
+ * @throws {@link !TypeError TypeError} Where `probe` is not a well-formed probe
94
+ *
95
+ * @see {@link https://grafctory.github.io/qest/documents/model.Model_Design.html Model Design}
96
+ */
97
+ export declare function effective(shape: Lazy<Shape | Range>, probe: Probe): Range | Issue;
98
+ /**
99
+ * Resolves the collection property a {@link Slice | slice} names.
100
+ *
101
+ * Gives access to the declaration of the collection, such as its cardinality bounds, without looking up the property
102
+ * on the shape by name.
103
+ *
104
+ * @typeParam S The shape of the resource holding the collection, possibly deferred to break definition cycles
105
+ * @typeParam T The slice naming the collection property
106
+ *
107
+ * @param shape The shape of the resource holding the collection
108
+ * @param model The slice naming the collection property
109
+ *
110
+ * @returns The property the slice names, whether declared by the shape or inherited
111
+ *
112
+ * @throws {@link @grafctory/core!TraceError | TraceError} If the shape carries no property by the name the slice states
113
+ */
114
+ export declare function collection<S extends Lazy<ResourceShape>, T extends Slice<S, T>>(shape: S, model: T): Property;
115
+ /**
116
+ * Resolves the shape of the drafts posted to a collection property.
117
+ *
118
+ * Every new item of the collection named by a {@link Slice | slice} must satisfy this shape. Callers use it to
119
+ * validate a {@link Draft | draft} before storing it.
120
+ *
121
+ * @typeParam S The shape of the resource holding the collection, possibly deferred to break definition cycles
122
+ * @typeParam T The slice naming the collection property
123
+ *
124
+ * @param shape The shape of the resource holding the collection
125
+ * @param model The slice naming the collection property
126
+ *
127
+ * @returns The shape of the resources the collection embeds, or of the ones its references point to, with inherited
128
+ * members merged in as by {@link eager}
129
+ *
130
+ * @throws {@link @grafctory/core!TraceError | TraceError} If the shape carries no property by the name the slice
131
+ * states, or if the property collects anything other than resources
132
+ */
133
+ export declare function blueprint<S extends Lazy<ResourceShape>, T extends Slice<S, T>>(shape: S, model: T): ResourceShape;
134
+ /**
135
+ * Resolves the items of a collection property from a retrieved resource.
136
+ *
137
+ * Reads the result of a retrieval made with a {@link Slice | slice}. The items, or the rows a projection computes over
138
+ * them, are returned as {@link Items | items}, typed by the slice, without looking up the collection property on the
139
+ * {@link Match | match} by name. A resource holding no items returns an empty array.
140
+ *
141
+ * @typeParam S The shape of the resource holding the collection, possibly deferred to break definition cycles
142
+ * @typeParam T The slice: the collection property and the members to retrieve from each item, or the projection to
143
+ * compute over the items, possibly with criteria
144
+ *
145
+ * @param match The resource retrieved with `slice`
146
+ * @param slice The slice used to retrieve `match`
147
+ *
148
+ * @returns The items in the collection, or an empty array if there are none
149
+ */
150
+ export declare function items<S extends Lazy<ResourceShape>, T extends Slice<S, T>>(match: Match<S, T>, slice: T): Items<S, T>;
151
+ //# sourceMappingURL=accessors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessors.d.ts","sourceRoot":"","sources":["../../src/value/accessors.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;GAUG;AAEH,OAAO,EAEN,KAAK,KAAK,EAKV,KAAK,IAAI,EAGT,MAAM,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AAE,CAAC,SAAS,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAMrH"}
@@ -0,0 +1,468 @@
1
+ /*
2
+ * Copyright © 2025-2026 Metreeca srl
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Shape accessors.
18
+ *
19
+ * Reads what a shape or a retrieved resource reaches, so that callers don't have to walk it themselves. A shape
20
+ * deferred to break a definition cycle resolves to the shape it states, with inherited members merged in. A path and
21
+ * transform pipe resolve to the range of the values they reach, which types a projection binding or a constraint
22
+ * operand. A slice resolves to the collection property it names and to the shape of the drafts posted to it, and a
23
+ * resource retrieved with a slice gives access to the items of its collection, typed by the slice.
24
+ *
25
+ * @module
26
+ */
27
+ import { assert, error, isFunction, isString, opt as fold } from "@grafctory/core";
28
+ import { unique } from "@grafctory/core/arrays";
29
+ import { xsd } from "@grafctory/core/datatype";
30
+ import { all, TraceError } from "@grafctory/core/trace";
31
+ import { equals, immutable } from "@grafctory/core/values";
32
+ import { isProbe, Transforms } from "@grafctory/qest/model";
33
+ import { decimal, integer } from "../number/index.js";
34
+ import { getShapeTarget } from "../reference/index.js";
35
+ import { flatten } from "../resource/assembler.js";
36
+ import { string } from "../string/index.js";
37
+ import { getShapeBranches, union } from "../union/index.js";
38
+ import { reject } from "./assembler.js";
39
+ import { sh } from "./index.js";
40
+ /**
41
+ * The datatypes a transform may read as a point in time.
42
+ *
43
+ * Names the temporal datatypes the processing space orders and computes on, so that a transform reaching for a date
44
+ * is told apart from one reaching for plain text. The opaque temporal datatypes, `xsd:gYear` and `xsd:duration` among
45
+ * them, are left out: they carry no position on a timeline and are handled as ordinary strings.
46
+ *
47
+ * Each datatype is mapped to the temporal transforms extracting a component its values always state. Any other
48
+ * temporal transform returns no value for it, as a date states no hours and a time of day states no year.
49
+ */
50
+ const Temporal = new Map([
51
+ [xsd.date, new Set(["year", "month", "day"])],
52
+ [xsd.time, new Set(["hours", "minutes", "seconds"])],
53
+ [xsd.dateTime, new Set(["year", "month", "day", "hours", "minutes", "seconds"])]
54
+ ]);
55
+ /**
56
+ * The range a resource identifier is reached through.
57
+ *
58
+ * A member naming or typing a resource carries a single absolute IRI rather than a typed literal, marked as such so
59
+ * that a caller storing the value maps it to an identifier. Every such member is reached through the same range, so it
60
+ * is stated once.
61
+ */
62
+ const IRIRange = immutable({
63
+ minCount: undefined,
64
+ maxCount: 1,
65
+ shape: IRIShape // deferred, so that nothing is read from a module still being initialised
66
+ });
67
+ /**
68
+ * The shape an identifier is stated by.
69
+ *
70
+ * Stated as a single thunk, so that {@link eager} resolves it once and every range reaching it compares equal.
71
+ */
72
+ function IRIShape() {
73
+ return string({ datatype: sh.IRI, pattern: /^[a-zA-Z][a-zA-Z0-9+.-]*:\S+$/ });
74
+ }
75
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76
+ /**
77
+ * The shapes and ranges already resolved from a deferred definition.
78
+ *
79
+ * Keyed by the thunk that deferred them, so that a definition reached along several paths is resolved once and compared
80
+ * by identity; a thunk under resolution is held as `null`, which is how a definition reaching itself is caught.
81
+ */
82
+ const shapes = new WeakMap();
83
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84
+ /**
85
+ * Resolves a possibly deferred shape or range.
86
+ *
87
+ * Yields the shape or range a definition states, resolving a deferred one on first reach and handing back the same
88
+ * value on every later reach, so that a definition stated once compares equal wherever it is reached from. A resource
89
+ * shape comes back merged, so a caller reading its members needs not merge the inheritance chain itself; a range comes
90
+ * back as stated, the shape it carries still possibly deferred.
91
+ *
92
+ * A deferred definition may reach itself only through a link. An embedded resource is carried inline, so a definition
93
+ * that embeds itself, directly or through other embedded resources or unions, admits no finite value and is rejected.
94
+ * A cycle running through several definitions is reported only once all of them have been resolved, in whatever
95
+ * order: resolving the earlier ones succeeds, and the error surfaces on the definition resolved last.
96
+ *
97
+ * @typeParam S The stated shape or range, possibly deferred to break definition cycles
98
+ *
99
+ * @param shape The shape or range to resolve
100
+ *
101
+ * @returns The shape or range `shape` states, merged where it describes a resource
102
+ *
103
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself, leaving the
104
+ * shape it states undefined, where it embeds itself with no link to break the cycle, or where it states a target
105
+ * that doesn't narrow the inherited target overridden by the link it is reached through
106
+ */
107
+ export function eager(shape) {
108
+ if (!isFunction(shape)) {
109
+ return resolve(shape); // ;(cast) a stated shape resolves to itself, merged where it is a resource
110
+ }
111
+ const cached = shapes.get(shape);
112
+ if (cached === null) {
113
+ throw new TraceError("circular definition", [{
114
+ [shape.name || "<anonymous>"]: ["reaches itself"]
115
+ }]);
116
+ }
117
+ else if (cached !== undefined) {
118
+ return cached; // ;(cast) the cache erases the thunk's own type, recovered at this boundary
119
+ }
120
+ shapes.set(shape, null);
121
+ try {
122
+ const resolved = resolve(shape());
123
+ // cached before it is checked, so that the walk reaches the definition through its own thunk
124
+ shapes.set(shape, resolved);
125
+ reject("circular definition", embeds(shape, []));
126
+ return resolved; // ;(cast) as above
127
+ }
128
+ catch (cause) {
129
+ shapes.delete(shape);
130
+ throw cause;
131
+ }
132
+ /**
133
+ * Merges a resolved shape where it describes a resource; a range is handed back as stated.
134
+ */
135
+ function resolve(shape) {
136
+ return "shape" in shape ? shape
137
+ : shape.kind === "resource" ? flatten(shape)
138
+ : shape;
139
+ }
140
+ /**
141
+ * Checks whether a range reaches a definition already on the embedding path.
142
+ *
143
+ * Walks the embedded resources and unions a range reaches, stopping at links and at ranges deferred and not yet
144
+ * resolved, which are checked where they resolve in their own right; a definition under resolution up the stack
145
+ * is reached again through its own thunk once it resolves, the thunk being cached before the check runs.
146
+ *
147
+ * @param range The range to walk, possibly deferred
148
+ * @param trail The definitions and shapes the walk crossed to reach `range`
149
+ *
150
+ * @returns A trace keyed by the members leading to the definition reached again, or `undefined` where none is
151
+ */
152
+ function embeds(range, trail) {
153
+ if (trail.includes(range)) {
154
+ return ["{range} circular embedding"];
155
+ }
156
+ else {
157
+ const resolved = isFunction(range) ? shapes.get(range) : range;
158
+ const crossed = [...trail, range];
159
+ return resolved === null || resolved === undefined || "shape" in resolved ? undefined
160
+ : resolved.kind === "resource" ? all(...Object.entries(resolved.members).map(([name, member]) => () => member.kind === "property" ? fold(embeds(member.range.shape, crossed), trace => [{ [name]: trace }])
161
+ : undefined))(undefined)
162
+ : resolved.kind === "union" ? all(...resolved.branches.map(branch => () => embeds(branch, crossed)))(undefined)
163
+ : undefined;
164
+ }
165
+ }
166
+ }
167
+ /**
168
+ * Resolves the values a probe reaches.
169
+ *
170
+ * Yields the range a {@link Probe | probe} resolves to against a shape: the shapes its values may be drawn from and
171
+ * how many of them it reaches, so that a caller may type a projection binding or a constraint operand without walking
172
+ * the shape itself. A path stepping through several alternatives reaches each in turn, and the range it yields
173
+ * envelopes them all; discrimination to the single branch a value belongs to is settled separately, against the value.
174
+ *
175
+ * **What a path reaches**
176
+ *
177
+ * A path steps across the members of the resources it reaches, crossing a link to the resource it points at and
178
+ * entering each alternative of a union in turn; an alternative lacking the next member is dropped, and the path fails
179
+ * only where none carries it. The members naming and typing a resource are reached as a scalar IRI, so a path may end
180
+ * on one but never step past it. A localised member is likewise terminal.
181
+ *
182
+ * A path taking no step reaches the shape it starts from, as it stands: a link stays a link, reached as the identifier
183
+ * naming its target unless a template expands it, and is crossed only by a step that actually names a member.
184
+ *
185
+ * **What a pipe yields**
186
+ *
187
+ * A pipe applies its transforms to whatever the path reached, dropping an alternative the transforms cannot act on:
188
+ * within a union this keeps the compatible alternatives alone, so a pipe stands as long as one survives. A localised
189
+ * value is read through the content language negotiation settles on, as ordinary text. A transform stating it yields
190
+ * the same type reproduces the input shape verbatim where it keeps values within the domain they were drawn from, and
191
+ * widens to the bare numeric type where it combines them and leaves that domain behind.
192
+ *
193
+ * **How many values it reaches**
194
+ *
195
+ * Bounds accumulate multiplicatively along a path and envelope across alternatives: the lowest lower bound and the
196
+ * highest upper bound win, and an unstated bound absorbs, leaving that end unbounded.
197
+ *
198
+ * A transform applied value by value keeps the bounds as they stand. An aggregate caps the count at one, and it returns
199
+ * a value whenever the path reaches one, so a lower bound of one or more drops to one. An aggregate that always returns
200
+ * a value, such as `count` or `sum`, fixes the count at exactly one, whatever the path reaches.
201
+ *
202
+ * Some pipes may return no value for a resource even though the path reaches one: a pipe dropping an alternative it
203
+ * cannot act on, one reading a localised value through negotiation, and one extracting a temporal component the value
204
+ * doesn't state, as `hours` does from a date. Their lower bound stays unstated unless the pipe always returns a value.
205
+ *
206
+ * @param shape The shape to resolve the probe against or a range already resolved to probe further, either possibly
207
+ * deferred to break definition cycles
208
+ * @param probe The path and transform pipe to resolve
209
+ *
210
+ * @returns The range the probe reaches, or an {@link Issue} stating why it reaches nothing: `"unknown property path"`
211
+ * where the path names a member no alternative carries or steps past one that cannot be stepped past,
212
+ * `"multiple aggregate transforms"` where the pipe combines values more than once, or
213
+ * `"incompatible transform input"` where no alternative survives the transforms
214
+ *
215
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where a deferred definition reaches itself, leaving the
216
+ * shape it states undefined, where it embeds itself with no link to break the cycle, where it states a target
217
+ * that doesn't narrow the inherited target overridden by the link it is reached through, or where a union
218
+ * the path crosses declares a shared member name inconsistently across its branches
219
+ * @throws {@link !TypeError TypeError} Where `probe` is not a well-formed probe
220
+ *
221
+ * @see {@link https://grafctory.github.io/qest/documents/model.Model_Design.html Model Design}
222
+ */
223
+ export function effective(shape, probe) {
224
+ // a hand-built probe may name an unknown transform or a malformed path, which would otherwise surface as a
225
+ // crash deep inside the pipe; it is rejected up front
226
+ const { pipe, path } = assert(probe, isProbe, "malformed probe");
227
+ return transform(traverse(expand(shape)));
228
+ /**
229
+ * Seeds one branch per alternative the shape opens with.
230
+ *
231
+ * A union opens one branch per alternative, at unit cardinality; a range already resolved opens one branch per
232
+ * alternative, carrying the bounds it accumulated. A link opens as itself, each step crossing it to the resource
233
+ * it points at as it resolves the member it names, so a path taking no step is left holding the link.
234
+ */
235
+ function expand(shape) {
236
+ const resolved = eager(shape);
237
+ // told by the shape it carries, not by a missing kind: a property is a range carrying a kind
238
+ if ("shape" in resolved) {
239
+ return getShapeBranches(resolved.shape).map(branch => ({
240
+ minCount: resolved.minCount,
241
+ maxCount: resolved.maxCount,
242
+ shape: branch
243
+ }));
244
+ }
245
+ return getShapeBranches(resolved).map(branch => ({ minCount: 1, maxCount: 1, shape: branch }));
246
+ }
247
+ /**
248
+ * Steps the path across the branches, accumulating the bounds each one reaches its values through.
249
+ */
250
+ function traverse(seed) {
251
+ const branches = path.reduce((branches, segment) => branches.flatMap(branch => {
252
+ const reached = step(branch.shape, segment);
253
+ // a branch not carrying the member is dropped
254
+ return reached === undefined ? [] : getShapeBranches(reached.shape).map(shape => ({
255
+ minCount: multiply(branch.minCount, reached.minCount),
256
+ maxCount: multiply(branch.maxCount, reached.maxCount),
257
+ shape
258
+ }));
259
+ }), seed);
260
+ return branches.length === 0 ? "unknown property path" : {
261
+ minCount: branches.map(branch => branch.minCount).reduce(least),
262
+ maxCount: branches.map(branch => branch.maxCount).reduce(most),
263
+ shape: collect(branches.map(branch => branch.shape))
264
+ };
265
+ }
266
+ /**
267
+ * Resolves one step of the path against a branch.
268
+ */
269
+ function step(shape, segment) {
270
+ const members = getShapeTarget(shape)?.members;
271
+ // a branch carrying no member is stepped past; own names alone, as a name carried over from JSON must not
272
+ // reach Object.prototype
273
+ const member = members !== undefined && Object.hasOwn(members, segment) ? members[segment] : undefined;
274
+ return member === undefined ? undefined
275
+ : member.kind === "id" || member.kind === "type" ? IRIRange
276
+ : member.kind === "property" ? member.range
277
+ : undefined;
278
+ }
279
+ /**
280
+ * Applies the pipe to each branch, dropping the ones its transforms cannot act on.
281
+ */
282
+ function transform(reached) {
283
+ if (isString(reached)) {
284
+ return reached;
285
+ }
286
+ const aggregates = pipe.filter(name => Transforms[name].aggregate !== false);
287
+ if (aggregates.length > 1) {
288
+ return "multiple aggregate transforms";
289
+ }
290
+ // a pipe reads a localised value through the content negotiation settles on, as ordinary text
291
+ const staged = getShapeBranches(reached.shape)
292
+ .map(shape => pipe.length > 0 && shape.kind === "dictionary" ? string() : shape);
293
+ const surviving = staged
294
+ .map(shape => pipe.reduceRight(apply, shape))
295
+ .filter(shape => shape !== undefined);
296
+ if (surviving.length === 0) {
297
+ return "incompatible transform input";
298
+ }
299
+ const piped = pipe.length > 0;
300
+ const total = pipe.some(name => Transforms[name].aggregate === "total");
301
+ // a dropped alternative, a localised value read through negotiation or a missing temporal component may leave a
302
+ // resource with no value; only min and max carry a temporal value through, verbatim, so the component a temporal
303
+ // transform extracts is checked against the shape the path reached, never against an intermediate one
304
+ const lossy = surviving.length < staged.length
305
+ || getShapeBranches(reached.shape).some(shape => shape.kind === "dictionary")
306
+ || staged.some(shape => pipe.some(name => misses(shape, name)));
307
+ return {
308
+ minCount: !piped ? reached.minCount
309
+ : total ? 1
310
+ : lossy ? undefined
311
+ : aggregates.length > 0 ? least(reached.minCount, 1)
312
+ : reached.minCount,
313
+ maxCount: aggregates.length > 0 ? 1 : reached.maxCount,
314
+ shape: collect(surviving)
315
+ };
316
+ }
317
+ /**
318
+ * Applies one transform, dropping the branch once it falls outside a transform's domain.
319
+ */
320
+ function apply(shape, name) {
321
+ const transform = Transforms[name];
322
+ return shape !== undefined && accepts(transform.accepts, shape) ? produce(transform, shape) : undefined;
323
+ }
324
+ /**
325
+ * Resolves the shape a transform yields.
326
+ *
327
+ * A transform keeping values within the domain they were drawn from carries the shape through verbatim; one
328
+ * combining them leaves that domain behind, so it widens to the bare numeric type and drops every value-domain
329
+ * constraint as immaterial to the result.
330
+ */
331
+ function produce({ aggregate, returns }, shape) {
332
+ return returns === "same" ? (aggregate === "total" ? widen(shape) : shape)
333
+ : returns === "integer" ? integer()
334
+ : returns === "decimal" ? decimal()
335
+ : string();
336
+ }
337
+ /**
338
+ * Reports whether a shape lies within a transform's domain.
339
+ */
340
+ function accepts(domain, shape) {
341
+ return domain === "any" ? true
342
+ : domain === "literal" ? isLiteral(shape)
343
+ : domain === "numeric" ? isNumeric(shape)
344
+ : domain === "string" ? isTextual(shape)
345
+ : isTemporal(shape);
346
+ }
347
+ /**
348
+ * Widens a combined numeric result to its bare type, dropping the value-domain constraints.
349
+ */
350
+ function widen(shape) {
351
+ return shape.kind === "number" && shape.integral ? integer() : decimal();
352
+ }
353
+ function isLiteral(shape) {
354
+ return shape.kind === "boolean" || shape.kind === "number" || shape.kind === "string";
355
+ }
356
+ function isNumeric(shape) {
357
+ return shape.kind === "number";
358
+ }
359
+ function isTextual(shape) {
360
+ return shape.kind === "string" && !isTemporal(shape);
361
+ }
362
+ /**
363
+ * Checks whether a temporal transform extracts a component the values of a temporal shape don't state.
364
+ */
365
+ function misses(shape, name) {
366
+ return shape.kind === "string" && shape.datatype !== undefined && Transforms[name].accepts === "temporal"
367
+ && Temporal.get(shape.datatype)?.has(name) === false;
368
+ }
369
+ function isTemporal(shape) {
370
+ return shape.kind === "string" && shape.datatype !== undefined && Temporal.has(shape.datatype);
371
+ }
372
+ /**
373
+ * Gathers the shapes reached into the range's own.
374
+ *
375
+ * Yields the shape itself where a path converges on one and a union of them where it reaches several,
376
+ * deduplicated as late as possible, so that a pipe or a path folding alternatives onto the same shape reports it
377
+ * once.
378
+ */
379
+ function collect(branches) {
380
+ const distinct = unique(branches, equals);
381
+ return distinct.length === 1 ? distinct[0] : union(distinct[0], ...distinct.slice(1));
382
+ }
383
+ /**
384
+ * Lowest lower bound; an unstated bound absorbs, as no lower bound wins.
385
+ */
386
+ function least(a, b) {
387
+ return a === undefined || b === undefined ? undefined : Math.min(a, b);
388
+ }
389
+ /**
390
+ * Highest upper bound; an unstated bound absorbs, as an unbounded end wins.
391
+ */
392
+ function most(a, b) {
393
+ return a === undefined || b === undefined ? undefined : Math.max(a, b);
394
+ }
395
+ /**
396
+ * Product of two bounds; an unstated bound propagates, and a zero product stands.
397
+ */
398
+ function multiply(a, b) {
399
+ return a === undefined || b === undefined ? undefined : a * b;
400
+ }
401
+ }
402
+ /**
403
+ * Resolves the collection property a {@link Slice | slice} names.
404
+ *
405
+ * Gives access to the declaration of the collection, such as its cardinality bounds, without looking up the property
406
+ * on the shape by name.
407
+ *
408
+ * @typeParam S The shape of the resource holding the collection, possibly deferred to break definition cycles
409
+ * @typeParam T The slice naming the collection property
410
+ *
411
+ * @param shape The shape of the resource holding the collection
412
+ * @param model The slice naming the collection property
413
+ *
414
+ * @returns The property the slice names, whether declared by the shape or inherited
415
+ *
416
+ * @throws {@link @grafctory/core!TraceError | TraceError} If the shape carries no property by the name the slice states
417
+ */
418
+ export function collection(shape, model) {
419
+ const [field] = Object.keys(model);
420
+ const member = eager(shape).members[field];
421
+ return member?.kind === "property" ? member : error(new TraceError("invalid model", [{ [field]: ["{range} expected a collection property"] }]));
422
+ }
423
+ /**
424
+ * Resolves the shape of the drafts posted to a collection property.
425
+ *
426
+ * Every new item of the collection named by a {@link Slice | slice} must satisfy this shape. Callers use it to
427
+ * validate a {@link Draft | draft} before storing it.
428
+ *
429
+ * @typeParam S The shape of the resource holding the collection, possibly deferred to break definition cycles
430
+ * @typeParam T The slice naming the collection property
431
+ *
432
+ * @param shape The shape of the resource holding the collection
433
+ * @param model The slice naming the collection property
434
+ *
435
+ * @returns The shape of the resources the collection embeds, or of the ones its references point to, with inherited
436
+ * members merged in as by {@link eager}
437
+ *
438
+ * @throws {@link @grafctory/core!TraceError | TraceError} If the shape carries no property by the name the slice
439
+ * states, or if the property collects anything other than resources
440
+ */
441
+ export function blueprint(shape, model) {
442
+ const [field] = Object.keys(model);
443
+ const resolved = eager(collection(shape, model).range.shape);
444
+ return resolved.kind === "reference" ? eager(resolved.target)
445
+ : resolved.kind === "resource" ? resolved
446
+ : error(new TraceError("invalid model", [{ [field]: ["{range} expected a collection property"] }]));
447
+ }
448
+ /**
449
+ * Resolves the items of a collection property from a retrieved resource.
450
+ *
451
+ * Reads the result of a retrieval made with a {@link Slice | slice}. The items, or the rows a projection computes over
452
+ * them, are returned as {@link Items | items}, typed by the slice, without looking up the collection property on the
453
+ * {@link Match | match} by name. A resource holding no items returns an empty array.
454
+ *
455
+ * @typeParam S The shape of the resource holding the collection, possibly deferred to break definition cycles
456
+ * @typeParam T The slice: the collection property and the members to retrieve from each item, or the projection to
457
+ * compute over the items, possibly with criteria
458
+ *
459
+ * @param match The resource retrieved with `slice`
460
+ * @param slice The slice used to retrieve `match`
461
+ *
462
+ * @returns The items in the collection, or an empty array if there are none
463
+ */
464
+ export function items(match, slice) {
465
+ const [collection] = Object.keys(slice); // the slice names a single collection property
466
+ return (Reflect.get(match, collection) ?? []); // ;(cast) Items is not derivable from Match
467
+ }
468
+ //# sourceMappingURL=accessors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessors.js","sourceRoot":"","sources":["../../src/value/accessors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,EACN,MAAM,EAEN,KAAK,EAEL,UAAU,EACV,QAAQ,EAER,GAAG,IAAI,IAAI,EAEX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,GAAG,EAA0B,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAA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