@grafctory/blue 0.0.0-stage → 0.15.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.
Files changed (139) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +509 -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 +154 -0
  18. package/dist/dictionary/assembler.js.map +1 -0
  19. package/dist/dictionary/index.d.ts +211 -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 +34 -0
  28. package/dist/dictionary/validator.d.ts.map +1 -0
  29. package/dist/dictionary/validator.js +91 -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 +898 -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 +1031 -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 @@
1
+ {"version":3,"file":"index.core.js","sourceRoot":"","sources":["../src/index.core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,SAAS,EAA0B,MAAM,kBAAkB,CAAC;AAGrE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc,EAAE,KAAoB,EAAE,EAE7D,KAAK,KAMF,EAAE;IAEL,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,kDAAkD;IAGjG;;OAEG;IACH,SAAS,QAAQ,CAAC,KAAc,EAAE,KAAoB;QAErD,IAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAG,CAAC;YAAC,OAAO,KAAK,CAAC;QAAC,CAAC;QAEzC,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,I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AC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC;gBACxF,CAAC,CAAC,QAAQ;qBACR,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;qBACrC,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC;gBAChE,CAAC,CAAC,KAAK;SACP,CAAC,CAAC,CAAC;IAEL,CAAC;IAED;;;;OAIG;IACH,SAAS,IAAI,CAAC,KAAc,EAAE,MAAa;QAE1C,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;QAEtC,OAAO,MAAM,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;eAC3C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC;IAE3E,CAAC;IAED;;OAEG;IACH,SAAS,IAAI,CAAC,IAAa;QAE1B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,wCAAwC;YACrE,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI;gBACnB,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAE7B,CAAC;AAEF,CAAC"}
@@ -0,0 +1,333 @@
1
+ /**
2
+ * Linked data validation.
3
+ *
4
+ * Provides shape-based validation for the values, retrieval templates and retrieved data crossing a service boundary.
5
+ * The {@link schema} function describes the payloads a shape admits as a JSON Schema, and the {@link validate}
6
+ * function returns either the value, typed as the shape describes it, or a trace of every violation found. A shape
7
+ * states once what a service accepts, so the description and the checks stay in one place instead of being restated
8
+ * across the interfaces and entry points that exchange data with clients.
9
+ *
10
+ * Shapes are stated with the per-kind modules {@link value! | value} gathers:
11
+ *
12
+ * ```typescript
13
+ * import { boolean } from '@grafctory/blue/boolean';
14
+ * import { integer } from '@grafctory/blue/number';
15
+ * import { id, multiple, optional, required, resource } from '@grafctory/blue/resource';
16
+ * import { date, string } from '@grafctory/blue/string';
17
+ *
18
+ * const Product = resource({
19
+ * id: id(),
20
+ * name: required(string({ minLength: 1, maxLength: 100 })),
21
+ * price: required(integer({ minInclusive: 0 })),
22
+ * available: optional(boolean()),
23
+ * tags: multiple(string()),
24
+ * released: optional(date())
25
+ * });
26
+ * ```
27
+ *
28
+ * **Describing a shape as JSON Schema**
29
+ *
30
+ * A shape also declares schema-driven consumers, such as API descriptions, language model tool interfaces and
31
+ * structured output formats, without a hand-written schema restating it. The {@link schema} function describes the
32
+ * payloads a resource shape admits as a JSON Schema (draft 2020-12). Its strict variant keeps to the subset of JSON
33
+ * Schema accepted by structured output generators, which reject the keywords and formats outside it:
34
+ *
35
+ * ```typescript
36
+ * import { schema } from '@grafctory/blue';
37
+ *
38
+ * schema(Product); // the payloads Product admits
39
+ * schema(Product, { strict: true }); // the same, for strict structured output generators
40
+ * ```
41
+ *
42
+ * **Collecting entry shapes and their dependencies**
43
+ *
44
+ * Model-wide encodings, such as vocabularies, schemas and documentation, cover every shape a set of entry shapes
45
+ * depends on rather than only the entry shapes themselves. The {@link model} function collects the entry shapes and
46
+ * the shapes they extend, link to or embed, each once and in a stable order, ready to be encoded as a whole:
47
+ *
48
+ * ```typescript
49
+ * import { model } from '@grafctory/blue';
50
+ * import { id, optional, resource } from '@grafctory/blue/resource';
51
+ * import { reference } from '@grafctory/blue/reference';
52
+ *
53
+ * const Vendor = resource({
54
+ * id: id()
55
+ * });
56
+ *
57
+ * const Offer = resource({
58
+ * id: id(),
59
+ * vendor: optional(reference(Vendor))
60
+ * });
61
+ *
62
+ * model(Offer); // [Offer, Vendor]
63
+ * ```
64
+ *
65
+ * **Matching a value against a shape**
66
+ *
67
+ * The same shape answers three questions; the `model` option settles which is being asked:
68
+ *
69
+ * ```typescript
70
+ * import { validate } from '@grafctory/blue';
71
+ *
72
+ * validate(product, { shape: Product })({ // a resource in its own right
73
+ * value: product => console.log(product.name),
74
+ * trace: trace => console.error(trace)
75
+ * });
76
+ *
77
+ * validate(response, { shape: Product, model: { name: {} } }); // a retrieval, narrowed by what was asked for
78
+ * validate(request, { shape: Product, model: true }); // a retrieval template, before it is issued
79
+ * ```
80
+ *
81
+ * - omitted, or `false`, matches `value` against the shape as a resource in its own right
82
+ * - a template matches `value` against the members that template asked for, and types what comes back accordingly
83
+ * - `true` matches `value` against the shape as a template, asking whether the shape can serve what it requests
84
+ *
85
+ * > [!CAUTION]
86
+ * > A template may draw on the full query language, including aggregate transforms and nested expansion. Hold an
87
+ * > untrusted caller to what the service will serve: `plain` refuses the aggregate transforms, `depth` caps the
88
+ * > nesting, and `limit` caps the page.
89
+ *
90
+ * @module index
91
+ *
92
+ * @see {@link https://json-schema.org/draft/2020-12/json-schema-core JSON Schema Core (draft 2020-12)}
93
+ * @see {@link https://www.w3.org/TR/shacl/ SHACL - Shapes Constraint Language}
94
+ */
95
+ import { type Lazy, type Optional } from "@grafctory/core";
96
+ import { type Some } from "@grafctory/core/arrays";
97
+ import { type Relay } from "@grafctory/core/relay";
98
+ import { type Trace } from "@grafctory/core/trace";
99
+ import type { Template } from "@grafctory/qest/model";
100
+ import type { Reference } from "@grafctory/qest/state";
101
+ import type { JSONSchema } from "json-schema-typed";
102
+ import type { ResourceShape } from "./resource/index.js";
103
+ import { type Match, type State } from "./value/index.js";
104
+ /**
105
+ * Converts a resource shape into a JSON Schema.
106
+ *
107
+ * A resource is described as an object with one property per member. Like the shape, the object is closed and admits
108
+ * no other property. Members requiring at least one value are required, and a member admitting more than one value is
109
+ * described as an array of its range. Identifier and class members are left out, as they name the resource rather than
110
+ * describe it, so a payload stating them is rejected. A {@link reference!reference | reference} is described as the
111
+ * IRI it carries, and an embedded resource as a nested object. A {@link union!union | union} is described as the
112
+ * alternatives it admits, so the schema accepts a value conforming to any one of its branches.
113
+ *
114
+ * Value constraints are carried through: the bounds of a number and whether it is an integer, and the values, length
115
+ * bounds and lexical pattern of a string. A string in a well-known lexical form also carries the matching `format`, a
116
+ * hint for the consumers that recognise it about the kind of value expected and how to present or check it:
117
+ *
118
+ * - {@link string!url | url} as `uri`, {@link string!iri | iri} as `iri-reference`
119
+ * - {@link string!email | email} as `email`
120
+ * - {@link string!date | date} as `date`, {@link string!time | time} as `time`
121
+ * - {@link string!instant | instant} and {@link string!timestamp | timestamp} as `date-time`
122
+ *
123
+ * Values are still held to the pattern alone: a validator asserting formats may reject values the shape admits, such
124
+ * as a time with no zone offset, so formats are best read as annotations rather than as constraints.
125
+ *
126
+ * The name and description of a resource and of each member are carried as `title` and `description`. A member
127
+ * admitting more than one value annotates the array rather than its items. Localised names and descriptions are
128
+ * carried in English, and are left out if they are stated in no English, as a schema has room for one language only.
129
+ *
130
+ * A strict schema keeps to the subset of JSON Schema accepted by strict structured output generators. Every member is
131
+ * required. An optional single-valued member also admits `null` for an absent value, and an absent multi-valued member
132
+ * is stated as an empty array. A payload generated under a strict schema therefore conforms to the shape only once its
133
+ * `null` members are dropped. No string carries the `uri` or `iri-reference` format: IRI strings are held to their
134
+ * pattern, and references only to being strings, as strict generators reject both formats.
135
+ *
136
+ * The returned schema is deeply immutable. Conversions are cached, so converting the same shape again with the same
137
+ * options returns the same schema at no cost, whether the shape is passed as is or deferred. Cached schemas are kept
138
+ * for the lifetime of the module, so shapes are best declared once rather than built anew on each conversion.
139
+ *
140
+ * @param shape The resource shape to convert, possibly deferred
141
+ * @param options The conversion options
142
+ *
143
+ * @returns The JSON Schema describing the values `shape` admits
144
+ *
145
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where `shape` is malformed, as where it embeds itself with no
146
+ * link to break the cycle and so admits no finite payload a schema could describe
147
+ * @throws {@link !RangeError RangeError} If `shape` admits a {@link dictionary!dictionary | localised} value range at
148
+ * any depth, as a JSON Schema has no way to name the language tags keying each localised value it describes
149
+ *
150
+ * @see {@link https://json-schema.org/draft/2020-12/json-schema-validation#section-7.3 JSON Schema § 7.3 Defined Formats}
151
+ */
152
+ export declare function schema(shape: Lazy<ResourceShape>, { strict }?: {
153
+ /**
154
+ * Whether to produce a strict schema for structured output generators.
155
+ *
156
+ * @defaultValue false
157
+ */
158
+ readonly strict?: boolean;
159
+ }): JSONSchema.Interface;
160
+ /**
161
+ * Collects entry shapes and their dependencies.
162
+ *
163
+ * A shape depends on the shapes it extends and on the shapes its properties link to or embed, directly or through
164
+ * other shapes. Dependencies include the targets of {@link resource!PropertyConstraints.foreign | foreign} properties
165
+ * and the resource alternatives of {@link union!union | unions}, so the listing covers the whole connected model.
166
+ *
167
+ * Each shape is listed once, even where shapes link to each other in a cycle. The entry shapes come first, in the
168
+ * order given, followed by their dependencies, nearest first. Shapes at the same distance follow the order of the
169
+ * shapes reaching them, each contributing its parents before its property targets, in declaration order.
170
+ *
171
+ * Shapes are compared by reference, so a merged shape is listed alongside the shapes it merges. A property embedding
172
+ * different shapes along different inheritance paths, or re-pointed at a narrower embedded shape, ranges over a new
173
+ * shape stating the class of the narrowest, and the listing may then hold two shapes of that class. A shape embedded
174
+ * alike along every path is listed once, provided the shared definition is passed as its factory, as in
175
+ * `optional(Image)`, rather than built by separate calls to it, which return distinct shapes.
176
+ *
177
+ * @param shapes The entry shape or shapes, possibly deferred
178
+ *
179
+ * @returns The entry shapes followed by their dependencies; empty if `shapes` is empty
180
+ *
181
+ * @see {@link https://www.w3.org/TR/shacl/#shapes-graph SHACL § 3.1 Shapes Graph}
182
+ */
183
+ export declare function model(shapes: Some<Lazy<ResourceShape>>): readonly ResourceShape[];
184
+ /**
185
+ * Validates a resource against a shape.
186
+ *
187
+ * Reports what a resource states wrongly, so that a caller may refuse it before it reaches the store holding it, and
188
+ * hands back the resource itself where it passes, typed as the shape describes it. Every member the shape declares is
189
+ * held to it and one it doesn't declare is rejected, the shape being closed; a member the shape admits no value for
190
+ * may be left out.
191
+ *
192
+ * > [!CAUTION]
193
+ * > A captive member is expanded to whatever depth it reaches. Where a caller must be held to bare links, state
194
+ * > `depth` as `0` to refuse every expansion, or as the nesting it may ask for.
195
+ *
196
+ * > [!TIP]
197
+ * > Revalidating a value costs nothing where the second call asks for no more than the first: the earlier verdict is
198
+ * > read off the value itself, so a caller may validate defensively wherever it is unsure.
199
+ *
200
+ * @typeParam S The shape the resource is matched against
201
+ *
202
+ * @param value The value to validate as a resource
203
+ * @param opts Validation options
204
+ * @param opts.shape The shape the resource is matched against, possibly deferred to break definition cycles
205
+ * @param opts.model Omitted, or `false`, to validate `value` as a resource in its own right
206
+ * @param opts.entry The identifier the resource is expected to be named by, where it states one at all
207
+ * @param opts.depth The nesting a captive member may be expanded to, counting each resource it descends into; `0`
208
+ * refuses every expansion while still admitting the identifier naming the resource
209
+ *
210
+ * @returns A {@link Relay} carrying the resource where it passes and a trace of the violations where it doesn't
211
+ *
212
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where `shape` is malformed
213
+ */
214
+ export declare function validate<S extends Lazy<ResourceShape>>(value: unknown, opts: {
215
+ readonly shape: S;
216
+ readonly model?: false;
217
+ readonly entry?: Reference;
218
+ readonly depth?: number;
219
+ }): Relay<{
220
+ /**
221
+ * The resource as it stands, typed as the shape describes it; relayed where it passes.
222
+ */
223
+ readonly value: State<S>;
224
+ /**
225
+ * The violations the resource states, keyed by the member at fault; relayed where it doesn't pass.
226
+ */
227
+ readonly trace: Optional<Trace>;
228
+ }>;
229
+ /**
230
+ * Validates a retrieved resource against a shape, narrowed by the template that requested it.
231
+ *
232
+ * Reports what a retrieval brought back wrongly, so that a caller may refuse a malformed response before reading it,
233
+ * and hands back the resource typed as the template asked for it. Only the members the template names are held to the
234
+ * shape, so a partial retrieval passes on its own terms, and a member the template didn't ask for is rejected, the
235
+ * caller having nowhere to put it. Reach for this where the shape fixes what may be asked for and the template varies
236
+ * from one request to the next.
237
+ *
238
+ * > [!IMPORTANT]
239
+ * > The custom {@link ResourceShape.validators | checks} a shape states never run against a retrieved resource, even
240
+ * > one the template asked for whole: they run only where a whole resource is validated in its own right.
241
+ *
242
+ * > [!NOTE]
243
+ * > The template states which values are wanted and no longer what they are, so every type comes from the shape: the
244
+ * > resource comes back as {@link Match} resolves it, keyed down to the members the template named. A polymorphic
245
+ * > member, a projection column and a localised member come back as wide as the shape describes them.
246
+ *
247
+ * > [!TIP]
248
+ * > Revalidating a value against the same shape and template costs nothing, as
249
+ * > {@link validate | validating a resource} explains.
250
+ *
251
+ * @typeParam S The shape the resource is matched against
252
+ * @typeParam M The template the resource was requested by
253
+ *
254
+ * @param value The value to validate as a retrieved resource
255
+ * @param opts Validation options
256
+ * @param opts.shape The shape the resource is matched against, possibly deferred to break definition cycles
257
+ * @param opts.model The template that requested it, narrowing both what is checked and what comes back
258
+ * @param opts.entry The identifier the resource is expected to be named by, where it states one at all
259
+ *
260
+ * @returns A {@link Relay} carrying the resource where it passes and a trace of the violations where it doesn't
261
+ *
262
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where `shape` is malformed
263
+ */
264
+ export declare function validate<S extends Lazy<ResourceShape>, M extends Template>(value: unknown, opts: {
265
+ readonly shape: S;
266
+ readonly model: M;
267
+ readonly entry?: Reference;
268
+ }): Relay<{
269
+ /**
270
+ * The resource as it stands, typed as the template asked for it; relayed where it passes.
271
+ */
272
+ readonly value: Match<S, M>;
273
+ /**
274
+ * The violations the retrieval brought back, keyed by the member at fault; relayed where it doesn't pass.
275
+ */
276
+ readonly trace: Optional<Trace>;
277
+ }>;
278
+ /**
279
+ * Validates a retrieval template against a shape.
280
+ *
281
+ * Reports each slot of a template that asks for something the shape cannot give, so that a caller may refuse a
282
+ * request before issuing it, and hands back the template itself where it passes, held to what the service
283
+ * guarantees. A template describes what to retrieve rather than what is held, so the value-domain constraints are
284
+ * left alone and a slot the template omits is simply not asked for.
285
+ *
286
+ * > [!CAUTION]
287
+ * > A template may draw on the full query language, including aggregate transforms and nested expansion. Hold an
288
+ * > untrusted caller to what the service will serve: `plain` refuses the aggregate transforms, `depth` caps the
289
+ * > nesting, and `limit` caps the page.
290
+ *
291
+ * > [!TIP]
292
+ * > A member reaching a standalone resource may be asked for as the identifier naming it or as a template standing for
293
+ * > the resource behind it; an embedded one, having no identifier of its own, only as a template. Stating `depth` as
294
+ * > `0` thus leaves a link retrievable while refusing the resource behind it.
295
+ *
296
+ * > [!TIP]
297
+ * > Revalidating a value costs nothing where the second call asks for no more than the first, as
298
+ * > {@link validate | validating a resource} explains.
299
+ *
300
+ * @typeParam T The template the shape admits
301
+ *
302
+ * @param value The value to validate as a retrieval template
303
+ * @param opts Validation options
304
+ * @param opts.shape The shape the template is matched against, possibly deferred to break definition cycles
305
+ * @param opts.model Must be `true` to validate `value` as a template rather than as a resource
306
+ * @param opts.plain Whether to refuse the transforms combining several values into one, leaving a template that
307
+ * retrieves rather than computes
308
+ * @param opts.depth The nesting a template may ask for, counting each resource it descends into; `0` refuses every
309
+ * nested template while still admitting the identifier naming the resource
310
+ * @param opts.limit The largest page a template may ask for; a collection asking for none is held to it, and one
311
+ * asking for more is refused. `0`, like omitting it, leaves the page to the caller
312
+ *
313
+ * @returns A {@link Relay} carrying the template where it passes and a trace of the violations where it doesn't
314
+ *
315
+ * @throws {@link @grafctory/core!TraceError | TraceError} Where `shape` is malformed
316
+ */
317
+ export declare function validate<T extends Template>(value: unknown, opts: {
318
+ readonly shape: Lazy<ResourceShape>;
319
+ readonly model: true;
320
+ readonly plain?: boolean;
321
+ readonly depth?: number;
322
+ readonly limit?: number;
323
+ }): Relay<{
324
+ /**
325
+ * The template, held to what the service guarantees; relayed where it passes.
326
+ */
327
+ readonly value: T;
328
+ /**
329
+ * The violations the template states, keyed by the slot at fault; relayed where it doesn't pass.
330
+ */
331
+ readonly trace: Optional<Trace>;
332
+ }>;
333
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"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