@drfed/models 0.2.0-dev.651 → 0.2.0-dev.685
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +308 -0
- package/dist/document.d.mts +200 -0
- package/dist/document.d.mts.map +1 -0
- package/dist/document.mjs +1264 -0
- package/dist/document.mjs.map +1 -0
- package/package.json +13 -6
package/README.md
CHANGED
|
@@ -7,6 +7,314 @@ both PGlite (embedded) and PostgreSQL.
|
|
|
7
7
|
[DrFed]: https://drfed.org/
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
Document validation
|
|
11
|
+
-------------------
|
|
12
|
+
|
|
13
|
+
`@drfed/models/document` exports synchronous
|
|
14
|
+
`validateDocument(document: unknown)` and `prepareDocument(document, options)`,
|
|
15
|
+
plus the `diagnosticReasons` registry. Public types are
|
|
16
|
+
`DocumentValidationResult`, `Diagnostic`, `DiagnosticReason`,
|
|
17
|
+
`DiagnosticCategory`, `DiagnosticSeverity`, `FieldPath`, `JsonValue`,
|
|
18
|
+
`NormalizationChange`, `DocumentAuthority`, `ServerOwnedField`, and
|
|
19
|
+
`DocumentPreparationOptions`. Pass parsed JSON, not JSON text. Validation
|
|
20
|
+
performs no network access, database writes, permission checks, or delivery,
|
|
21
|
+
and never mutates input.
|
|
22
|
+
|
|
23
|
+
### Consumer contract
|
|
24
|
+
|
|
25
|
+
The structured builder (#140) supplies its document; the raw editor (#141)
|
|
26
|
+
parses JSON first and owns syntax errors and text locations. Both call the same
|
|
27
|
+
validator. Paths identify original property names and zero-based list indexes,
|
|
28
|
+
including aliases; `[]` identifies the root. Map these paths to controls or
|
|
29
|
+
source locations without comparing human-readable messages.
|
|
30
|
+
|
|
31
|
+
~~~~ ts
|
|
32
|
+
import { validateDocument } from "@drfed/models/document";
|
|
33
|
+
|
|
34
|
+
const result = validateDocument({
|
|
35
|
+
"@context": "https://www.w3.org/ns/activitystreams",
|
|
36
|
+
type: "Accept",
|
|
37
|
+
object: [{ type: "Follow", actor: false }],
|
|
38
|
+
});
|
|
39
|
+
// invalid_value_shape at ["object", 0, "actor"]
|
|
40
|
+
const structurallyAccepted =
|
|
41
|
+
result.complete &&
|
|
42
|
+
!result.diagnostics.some(({ severity }) => severity === "error");
|
|
43
|
+
~~~~
|
|
44
|
+
|
|
45
|
+
| Result field | Caller interpretation |
|
|
46
|
+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
47
|
+
| complete | Checks finished. A definite malformed-input result can be complete; this is not a validity or permission flag. |
|
|
48
|
+
| diagnostics | Each finding has a stable reason, category, severity, original-input path, and display message. Use reason for machine decisions; messages may change. |
|
|
49
|
+
| changes | Proposed changes with operation, reason, path, message, and before/after values as applicable. Empty when no preview is available. |
|
|
50
|
+
| normalizedDocument | Independent preview, present only when changes are proposed, checking is complete, and no errors occur. Input remains unchanged. |
|
|
51
|
+
|
|
52
|
+
Vocabulary errors describe malformed supported input. Support errors describe
|
|
53
|
+
unimplemented types, properties, or representations and make `complete` false.
|
|
54
|
+
Compatibility warnings do not automatically reject the document. An omitted
|
|
55
|
+
context uses the standard ActivityStreams context with a warning. The exported
|
|
56
|
+
authority category is used by prepareDocument for caller-reported denials and
|
|
57
|
+
server-owned-field conflicts. validateDocument itself emits no authority
|
|
58
|
+
findings.
|
|
59
|
+
|
|
60
|
+
Document-only normalization proposes omission of empty arrays on supported,
|
|
61
|
+
applicable properties. For example, a Note with `to: []` receives the
|
|
62
|
+
`empty_property_list` warning and a removal change with reason
|
|
63
|
+
`omit_empty_property_list`; its preview omits `to`. Present changes for an
|
|
64
|
+
explicit caller decision. Validation does not apply them or save the preview.
|
|
65
|
+
Identifiers set to null or a nonempty array containing only null receive an
|
|
66
|
+
`absent_identifier` warning and a removal change with reason
|
|
67
|
+
`omit_absent_identifier`. This also applies to `@id` and supported aliases.
|
|
68
|
+
The preview omits these absent identifiers so Fedify can parse it; the submitted
|
|
69
|
+
document is preserved. Arrays containing any non-null identifier remain errors.
|
|
70
|
+
It does not assign IDs or timestamps, replace actor/attribution identities,
|
|
71
|
+
deduplicate recipients, or convert references to embedded values.
|
|
72
|
+
|
|
73
|
+
### Preparing server-owned creation fields
|
|
74
|
+
|
|
75
|
+
`prepareDocument(document, options)` returns the same DocumentValidationResult
|
|
76
|
+
shape. It combines structural validation with explicit authority outcomes and
|
|
77
|
+
server-owned values supplied by trusted server code. The exported
|
|
78
|
+
DocumentPreparationOptions, DocumentAuthority, and ServerOwnedField types define
|
|
79
|
+
these inputs. Never populate options directly from editor/client JSON.
|
|
80
|
+
|
|
81
|
+
~~~~ ts
|
|
82
|
+
import { prepareDocument } from "@drfed/models/document";
|
|
83
|
+
|
|
84
|
+
// Server code has already checked permission and allocated these values.
|
|
85
|
+
const result = prepareDocument(submittedDocument, {
|
|
86
|
+
authority: [{ allowed: true, path: [] }],
|
|
87
|
+
serverOwnedFields: [
|
|
88
|
+
{ path: ["id"], value: allocatedObjectIri },
|
|
89
|
+
{ path: ["attributedTo"], value: authorizedActorIri },
|
|
90
|
+
{ path: ["published"], value: allocatedPublicationTimestamp },
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
~~~~
|
|
94
|
+
|
|
95
|
+
At least one explicit authority outcome is required. A denied outcome produces
|
|
96
|
+
unauthorized\_local\_identity (authority/error) at the supplied original path;
|
|
97
|
+
use `[]` for an operation-level denial. The function only reports this outcome:
|
|
98
|
+
`allowed: true` is not an authorization check or a reusable permission token.
|
|
99
|
+
Nested creations need the caller's separate permission outcomes. Embedded
|
|
100
|
+
values alone never request creation or modification of resources.
|
|
101
|
+
Authority paths are caller-supplied diagnostic locations; they are not checked
|
|
102
|
+
against writable document targets. This differs from server-owned field paths.
|
|
103
|
+
|
|
104
|
+
Owned-field paths must name id, actor, attributedTo, published, or updated on
|
|
105
|
+
existing supported root/nested documents. Supported aliases resolve to the same
|
|
106
|
+
field; diagnostics and changes retain original source spellings and indexes.
|
|
107
|
+
Conflicts in arrays point to the non-null entries. When filling an absent value,
|
|
108
|
+
preparation prefers the requested key if it exists, then an existing alias,
|
|
109
|
+
and otherwise adds the requested key.
|
|
110
|
+
References and opaque extension data cannot be targets. The caller lists only
|
|
111
|
+
the fields it owns for that explicit creation operation; no default fields are
|
|
112
|
+
invented, and no values are generated from the clock or random IDs here.
|
|
113
|
+
|
|
114
|
+
| Submitted value | Preparation behavior |
|
|
115
|
+
| ----------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
116
|
+
| Missing | Propose an add change with reason assign\_server\_owned\_field. |
|
|
117
|
+
| Null or a supported array containing only null | Propose a replace change retaining the original value in before. |
|
|
118
|
+
| Exactly one non-null string matching the server value | Preserve the submitted representation; non-null id arrays remain invalid. |
|
|
119
|
+
| Different value, embedded identity, or additional non-null values | Report server\_owned\_field\_conflict (authority/error); never silently replace it. |
|
|
120
|
+
| Structurally malformed or unsupported input | Return its vocabulary/support diagnostics; do not prepare a successful preview. |
|
|
121
|
+
|
|
122
|
+
Matching uses exact string equality, not URL canonicalization, timestamp
|
|
123
|
+
rewriting, or remote lookup. Structural multiplicity errors remain vocabulary
|
|
124
|
+
errors. Both identity strings and timestamps supplied by the server are checked
|
|
125
|
+
for supported syntax. Invalid trusted configuration, duplicate semantic field
|
|
126
|
+
declarations, or paths outside existing supported documents throw TypeError
|
|
127
|
+
before document errors or denied authority stop preparation; these are caller
|
|
128
|
+
programming errors. Missing parent paths are checked without evaluating
|
|
129
|
+
accessors. If malformed documents, unsupported types/contexts, or truncated
|
|
130
|
+
checking prevent target or alias resolution, preparation retains document
|
|
131
|
+
diagnostics instead of treating that uncertainty as a caller path error.
|
|
132
|
+
Resolvable standard property names and trusted values are still checked.
|
|
133
|
+
|
|
134
|
+
The preview combines server-field additions with existing empty-property
|
|
135
|
+
omissions, preserves custom properties, and is structurally revalidated. It
|
|
136
|
+
is returned only when checking completes without errors and changes exist.
|
|
137
|
+
When a server-owned replacement targets a proposed omission at the same source
|
|
138
|
+
path, preparation returns only the replacement and updates the warning to
|
|
139
|
+
describe it. The final preview contains the supplied value; unrelated omission
|
|
140
|
+
proposals remain unchanged.
|
|
141
|
+
Denied authority, conflicts, unsupported input, and truncated diagnostics
|
|
142
|
+
withhold both preview and changes. The input and trusted options are unchanged.
|
|
143
|
+
|
|
144
|
+
#152 owns actual permission checks, value allocation, preview-to-commit
|
|
145
|
+
coordination, persistence, and permission rechecks at write time. It must keep
|
|
146
|
+
the committed values consistent with the accepted preview. This module neither
|
|
147
|
+
saves anything nor adapts createObject. Both editors can display the shared
|
|
148
|
+
results; saving, publication, and sending remain separate operations.
|
|
149
|
+
|
|
150
|
+
### Supported types and properties
|
|
151
|
+
|
|
152
|
+
The checker admits both activity base types and all 28 named activity subtypes,
|
|
153
|
+
plus Object, Note, Article, Application, Group, Organization, Person, Service,
|
|
154
|
+
Collection, OrderedCollection, CollectionPage, OrderedCollectionPage, Link,
|
|
155
|
+
and Mention. Optional properties stay optional. Each document needs one
|
|
156
|
+
supported type string; all type arrays, including singleton arrays, are
|
|
157
|
+
unsupported. Unknown types are retained without being converted to Note.
|
|
158
|
+
|
|
159
|
+
Type detection uses Fedify's public registry and inheritance, with an explicit
|
|
160
|
+
implemented-type set. Link and Mention use their exported classes because the
|
|
161
|
+
installed registry excludes them. Models and federation share the catalog
|
|
162
|
+
version of `@fedify/vocab` (currently 2.4.3); context data comes from the
|
|
163
|
+
matching `@fedify/vocab-runtime`. Recognition by Fedify alone does not
|
|
164
|
+
establish checker coverage. No vocabulary parser or full JSON-LD expansion runs
|
|
165
|
+
here.
|
|
166
|
+
|
|
167
|
+
In the table, Object includes its admitted subtypes, including activities,
|
|
168
|
+
actors, and collections. References are absolute IRIs or supported embedded
|
|
169
|
+
Object/Link values. Reference lists retain order, duplicates, and source
|
|
170
|
+
indexes.
|
|
171
|
+
|
|
172
|
+
| Applies to | Properties and rules |
|
|
173
|
+
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
174
|
+
| Object and Link | id: one IRI; mediaType: one MIME type; preview: references/lists; name/nameMap: text without HTML. |
|
|
175
|
+
| Object | summary/content and summaryMap/contentMap: text, including HTML and empty strings; location and attributedTo: references/lists. |
|
|
176
|
+
| Object | published, updated, startTime, endTime: one date-time each; to, cc, bto, bcc, audience: references/lists, with empty-array omission previews. |
|
|
177
|
+
| Activity | actor, object, target, origin, result, instrument: references/lists. IntransitiveActivity, Arrive, Travel, and Question reject non-null object values. |
|
|
178
|
+
| Actor types | preferredUsername: text; inbox/outbox: one IRI or embedded OrderedCollection or OrderedCollectionPage; following/followers/liked: one IRI or embedded Collection subtype. |
|
|
179
|
+
| Collection and subtypes | items/orderedItems: references/lists; totalItems: non-negative integer; current/first/last: one IRI or CollectionPage subtype. Counts need not match visible members. |
|
|
180
|
+
| CollectionPage subtypes | partOf: one IRI or Collection subtype; next/prev: one IRI or CollectionPage subtype. |
|
|
181
|
+
| OrderedCollectionPage | startIndex: non-negative integer. |
|
|
182
|
+
| Link and Mention | href: one IRI; hreflang: one language tag; rel: relation tokens/IRIs or lists; height/width: non-negative integers. Object-only fields, such as content and location, receive property\_not\_applicable. |
|
|
183
|
+
|
|
184
|
+
Except for id, single-value properties accept a scalar or array containing at
|
|
185
|
+
most one non-null value; multiple values receive `invalid_multiplicity`. Null
|
|
186
|
+
means absence, including null list entries. Empty arrays on supported
|
|
187
|
+
properties receive `empty_property_list` and an inspectable omission preview;
|
|
188
|
+
nested lists remain unsupported. Type and context arrays do not use this
|
|
189
|
+
omission rule. Unknown custom arrays are preserved as opaque data, while empty
|
|
190
|
+
arrays on unsupported or inapplicable fields retain their existing errors.
|
|
191
|
+
Identifiers require an IRI string when present. Null, empty arrays, and
|
|
192
|
+
null-only arrays receive omission previews; arrays containing non-null values
|
|
193
|
+
receive `invalid_value_shape`, even when they contain only one identifier.
|
|
194
|
+
Embedded activity actors and Object `attributedTo` values must use Application,
|
|
195
|
+
Group, Organization, Person, or Service for Fedify compatibility. Other
|
|
196
|
+
ActivityStreams-permitted embedded types receive `unsupported_value_form`; IRI
|
|
197
|
+
references remain supported without remote type checks. Object-only fields such
|
|
198
|
+
as `attributedTo` on Link receive `property_not_applicable`. Link `preview` and
|
|
199
|
+
`nameMap` remain supported by the vocabulary and Fedify's decoder. Collection
|
|
200
|
+
navigation accepts embedded CollectionPage values for current, first, last,
|
|
201
|
+
next, and prev, and Collection values for partOf, including subtypes. Embedded
|
|
202
|
+
Links in these fields receive `unsupported_value_form` because Fedify rejects
|
|
203
|
+
them. Diagnostics retain the original field/list paths.
|
|
204
|
+
|
|
205
|
+
Text accepts strings, flat lists, and supported `@value`/`@language` objects.
|
|
206
|
+
Language maps contain strings or null. Complex text attributes are unsupported.
|
|
207
|
+
Dates require a timezone and uppercase T/Z. Calendar checks use Temporal;
|
|
208
|
+
invalid dates receive `invalid_datetime`. ActivityStreams permits omitted
|
|
209
|
+
seconds, but representations Fedify cannot consume without failure or precision
|
|
210
|
+
loss receive `unsupported_value_form`: omitted seconds, fractions without
|
|
211
|
+
seconds, and fractions exceeding nine digits. Leap-second timestamps remain
|
|
212
|
+
unsupported. Validation preserves these values without adding seconds or
|
|
213
|
+
truncating precision. Timestamp validation does not establish server ownership
|
|
214
|
+
or ordering between fields.
|
|
215
|
+
|
|
216
|
+
Question is supported standalone and inside Create/Update using shared rules.
|
|
217
|
+
Its `oneOf`, `anyOf`, and `closed` fields remain unsupported pending #155's
|
|
218
|
+
poll rules. Open-ended Question needs no choices. Other types without
|
|
219
|
+
implemented rules, such as Place, receive support findings.
|
|
220
|
+
|
|
221
|
+
For 0.2.0, Object property rules for `tag`, `inReplyTo`, `url`, `attachment`,
|
|
222
|
+
`replies`, `icon`, `image`, `context`, `source`, `duration`, and `generator`
|
|
223
|
+
remain unimplemented. Null values are treated as absent and preserved without
|
|
224
|
+
diagnostics or normalization. On Object documents, non-null values produce
|
|
225
|
+
`unsupported_property` errors and set `complete: false`, preventing successful
|
|
226
|
+
validation even when their values are valid ActivityStreams. This limits which
|
|
227
|
+
documents pasted from fediverse servers can pass validation. Unknown custom
|
|
228
|
+
properties instead receive `extension_property_unchecked` warnings and can
|
|
229
|
+
survive successful validation without their semantics being checked. Full
|
|
230
|
+
coverage for the listed properties is deferred beyond 0.2.0 and tracked in
|
|
231
|
+
[#168].
|
|
232
|
+
|
|
233
|
+
[#168]: https://github.com/fedify-dev/drfed/issues/168
|
|
234
|
+
|
|
235
|
+
### Context and preservation limits
|
|
236
|
+
|
|
237
|
+
The context allowlist includes the standard ActivityStreams context (HTTPS and
|
|
238
|
+
its accepted HTTP spelling) and `https://w3id.org/security/v1`. Flat context
|
|
239
|
+
arrays and simple inline term/prefix definitions are supported. Effective
|
|
240
|
+
contexts must include the standard ActivityStreams vocabulary; standard terms
|
|
241
|
+
cannot be overridden. Embedded values inherit context; local alias overrides
|
|
242
|
+
are isolated from siblings.
|
|
243
|
+
|
|
244
|
+
Bundled context tables initialize on first use, not module import; an
|
|
245
|
+
unsupported bundled definition can throw during validation, and failed
|
|
246
|
+
initialization is retried rather than cached.
|
|
247
|
+
|
|
248
|
+
Aliases must have compatible coercion and containers. For example, an object
|
|
249
|
+
alias needs `@type: "@id"`; matching a property IRI alone is insufficient.
|
|
250
|
+
Functional aliases are counted together without merging source values.
|
|
251
|
+
Malformed context definitions receive `invalid_context`; unavailable contexts
|
|
252
|
+
receive `context_unavailable_offline`, not an empty replacement. There are no
|
|
253
|
+
remote lookups or remote lookup failures to interpret in this API.
|
|
254
|
+
Inline terms must be nonempty, and resolved mapping IRIs must not contain
|
|
255
|
+
unescaped whitespace, control characters, or forbidden IRI punctuation.
|
|
256
|
+
|
|
257
|
+
Scoped contexts, custom base/vocabulary/default-language directives, context
|
|
258
|
+
resets, JSON literals, and other complex forms remain unsupported. Relative
|
|
259
|
+
IRIs remain unsupported until a trusted base policy exists. Custom properties,
|
|
260
|
+
mapped or unmapped, are preserved as opaque JSON and receive the compatibility
|
|
261
|
+
warning `extension_property_unchecked`. Their semantics are not validated.
|
|
262
|
+
Otherwise supported documents can finish with `complete: true` and no errors;
|
|
263
|
+
normalization previews preserve the custom fields and their nested values.
|
|
264
|
+
Opaque values are checked for JSON safety, including cycles and accessors,
|
|
265
|
+
without interpreting nested type or context keys as ActivityStreams.
|
|
266
|
+
Language-tagged value objects also require a string or null `@value` and a
|
|
267
|
+
string or null `@language`; malformed values receive `invalid_value_shape`
|
|
268
|
+
at the original keyword path. A null language tag leaves the value untagged.
|
|
269
|
+
Explicit `@id` values inside extensions must be strings. Explicit `@type`
|
|
270
|
+
values must be strings or arrays of strings; malformed entries receive
|
|
271
|
+
`invalid_value_shape` at the original keyword or list-entry path. These shape
|
|
272
|
+
checks do not require custom type strings to appear in the implemented-type
|
|
273
|
+
set. An `@json` value's payload remains ordinary JSON, including keys spelled
|
|
274
|
+
`@id` or `@type`, and is checked only for JSON safety. These bounded checks do
|
|
275
|
+
not establish full JSON-LD validity or interpret nested contexts and keyword
|
|
276
|
+
aliases.
|
|
277
|
+
|
|
278
|
+
This warning policy does not admit unknown types, unsupported contexts,
|
|
279
|
+
JSON-LD keywords, or known vocabulary properties without implemented rules.
|
|
280
|
+
Known unimplemented properties set to null are treated as absent; otherwise,
|
|
281
|
+
those forms still block validation. Passing validation does not guarantee custom
|
|
282
|
+
fields survive Fedify serialization or sending. This supersedes the earlier
|
|
283
|
+
policy that rejected all custom properties.
|
|
284
|
+
|
|
285
|
+
Diagnostics are capped at 100. Exactly 100 findings are retained without a
|
|
286
|
+
truncation marker. If a further finding occurs, the last slot becomes a
|
|
287
|
+
`diagnostic_limit_reached` error; checking remains incomplete and no preview
|
|
288
|
+
is returned. This limits diagnostic output, not the amount of processing.
|
|
289
|
+
Traversal is iterative. Embedded document and opaque-extension traversal paths
|
|
290
|
+
may contain at most 64 segments, counting property names and list indexes;
|
|
291
|
+
the root has depth zero. At depth 65, checking reports
|
|
292
|
+
`processing_limit_exceeded` (support/error) at the original path without
|
|
293
|
+
descending further. The result is incomplete and has no preview or changes;
|
|
294
|
+
other branches can still be checked. Preparation treats targets beyond this
|
|
295
|
+
boundary as unavailable rather than as caller path errors. This is an
|
|
296
|
+
operational support limit, not an ActivityStreams validity rule.
|
|
297
|
+
There is no total value-count or work budget; the depth limit does not bound
|
|
298
|
+
wide arrays or overall document size.
|
|
299
|
+
Cycles in traversed values receive `non_json_value`; shared sibling objects
|
|
300
|
+
are allowed.
|
|
301
|
+
|
|
302
|
+
### Executable examples
|
|
303
|
+
|
|
304
|
+
All 138 cases in [the fixture file] are exercised by [the document tests]
|
|
305
|
+
through the built package export. Cases include `undo-nested-number`,
|
|
306
|
+
`accept-follow-list-actor`, `addressing-empty`, `context-alias-number`, and
|
|
307
|
+
`extension-mixed-type`. Fixture expectations contain reasons and paths;
|
|
308
|
+
category and severity are checked against the registry. Input preservation and
|
|
309
|
+
preview contents are asserted. Additional tests exercise network avoidance,
|
|
310
|
+
contexts, representation limits, and nested traversal. Preparation tests
|
|
311
|
+
exercise supplied authority outcomes and generated-field previews. Database
|
|
312
|
+
permission enforcement and transaction integration remain #152 responsibilities.
|
|
313
|
+
|
|
314
|
+
[the fixture file]: ../../fixtures/document-validation/initial.json
|
|
315
|
+
[the document tests]: src/document.test.ts
|
|
316
|
+
|
|
317
|
+
|
|
10
318
|
Schema
|
|
11
319
|
------
|
|
12
320
|
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
//#region src/document.d.ts
|
|
2
|
+
/** The source property names and zero-based indexes leading to a finding. */
|
|
3
|
+
type FieldPath = readonly (string | number)[];
|
|
4
|
+
type DiagnosticCategory = "vocabulary" | "authority" | "support" | "compatibility";
|
|
5
|
+
type DiagnosticSeverity = "error" | "warning";
|
|
6
|
+
/** Stable classifications; human-readable diagnostic messages may change. */
|
|
7
|
+
declare const diagnosticReasons: {
|
|
8
|
+
readonly invalid_document_root: {
|
|
9
|
+
readonly category: "vocabulary";
|
|
10
|
+
readonly severity: "error";
|
|
11
|
+
};
|
|
12
|
+
readonly non_json_value: {
|
|
13
|
+
readonly category: "vocabulary";
|
|
14
|
+
readonly severity: "error";
|
|
15
|
+
};
|
|
16
|
+
readonly invalid_value_shape: {
|
|
17
|
+
readonly category: "vocabulary";
|
|
18
|
+
readonly severity: "error";
|
|
19
|
+
};
|
|
20
|
+
readonly invalid_iri: {
|
|
21
|
+
readonly category: "vocabulary";
|
|
22
|
+
readonly severity: "error";
|
|
23
|
+
};
|
|
24
|
+
readonly invalid_datetime: {
|
|
25
|
+
readonly category: "vocabulary";
|
|
26
|
+
readonly severity: "error";
|
|
27
|
+
};
|
|
28
|
+
readonly invalid_multiplicity: {
|
|
29
|
+
readonly category: "vocabulary";
|
|
30
|
+
readonly severity: "error";
|
|
31
|
+
};
|
|
32
|
+
readonly property_not_applicable: {
|
|
33
|
+
readonly category: "vocabulary";
|
|
34
|
+
readonly severity: "error";
|
|
35
|
+
};
|
|
36
|
+
readonly invalid_context: {
|
|
37
|
+
readonly category: "vocabulary";
|
|
38
|
+
readonly severity: "error";
|
|
39
|
+
};
|
|
40
|
+
readonly unauthorized_local_identity: {
|
|
41
|
+
readonly category: "authority";
|
|
42
|
+
readonly severity: "error";
|
|
43
|
+
};
|
|
44
|
+
readonly server_owned_field_conflict: {
|
|
45
|
+
readonly category: "authority";
|
|
46
|
+
readonly severity: "error";
|
|
47
|
+
};
|
|
48
|
+
readonly context_unavailable_offline: {
|
|
49
|
+
readonly category: "support";
|
|
50
|
+
readonly severity: "error";
|
|
51
|
+
};
|
|
52
|
+
readonly unsupported_context_form: {
|
|
53
|
+
readonly category: "support";
|
|
54
|
+
readonly severity: "error";
|
|
55
|
+
};
|
|
56
|
+
readonly unsupported_type: {
|
|
57
|
+
readonly category: "support";
|
|
58
|
+
readonly severity: "error";
|
|
59
|
+
};
|
|
60
|
+
readonly unsupported_property: {
|
|
61
|
+
readonly category: "support";
|
|
62
|
+
readonly severity: "error";
|
|
63
|
+
};
|
|
64
|
+
readonly unsupported_value_form: {
|
|
65
|
+
readonly category: "support";
|
|
66
|
+
readonly severity: "error";
|
|
67
|
+
};
|
|
68
|
+
readonly processing_limit_exceeded: {
|
|
69
|
+
readonly category: "support";
|
|
70
|
+
readonly severity: "error";
|
|
71
|
+
};
|
|
72
|
+
readonly diagnostic_limit_reached: {
|
|
73
|
+
readonly category: "support";
|
|
74
|
+
readonly severity: "error";
|
|
75
|
+
};
|
|
76
|
+
readonly implicit_activitystreams_context: {
|
|
77
|
+
readonly category: "compatibility";
|
|
78
|
+
readonly severity: "warning";
|
|
79
|
+
};
|
|
80
|
+
readonly extension_property_unchecked: {
|
|
81
|
+
readonly category: "compatibility";
|
|
82
|
+
readonly severity: "warning";
|
|
83
|
+
};
|
|
84
|
+
readonly empty_property_list: {
|
|
85
|
+
readonly category: "compatibility";
|
|
86
|
+
readonly severity: "warning";
|
|
87
|
+
};
|
|
88
|
+
readonly absent_identifier: {
|
|
89
|
+
readonly category: "compatibility";
|
|
90
|
+
readonly severity: "warning";
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
type DiagnosticReason = keyof typeof diagnosticReasons;
|
|
94
|
+
interface Diagnostic {
|
|
95
|
+
readonly reason: DiagnosticReason;
|
|
96
|
+
readonly category: DiagnosticCategory;
|
|
97
|
+
readonly severity: DiagnosticSeverity;
|
|
98
|
+
readonly path: FieldPath;
|
|
99
|
+
readonly message: string;
|
|
100
|
+
}
|
|
101
|
+
type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
102
|
+
readonly [key: string]: JsonValue;
|
|
103
|
+
};
|
|
104
|
+
/** A proposed transformation; validation never applies it to the input. */
|
|
105
|
+
type NormalizationChange = {
|
|
106
|
+
readonly operation: "add";
|
|
107
|
+
readonly reason: string;
|
|
108
|
+
readonly path: FieldPath;
|
|
109
|
+
readonly after: JsonValue;
|
|
110
|
+
readonly message: string;
|
|
111
|
+
} | {
|
|
112
|
+
readonly operation: "replace";
|
|
113
|
+
readonly reason: string;
|
|
114
|
+
readonly path: FieldPath;
|
|
115
|
+
readonly before: JsonValue;
|
|
116
|
+
readonly after: JsonValue;
|
|
117
|
+
readonly message: string;
|
|
118
|
+
} | {
|
|
119
|
+
readonly operation: "remove";
|
|
120
|
+
readonly reason: string;
|
|
121
|
+
readonly path: FieldPath;
|
|
122
|
+
readonly before: JsonValue;
|
|
123
|
+
readonly message: string;
|
|
124
|
+
};
|
|
125
|
+
interface DocumentValidationResult {
|
|
126
|
+
/** Whether checks finished, including a definite invalid-input conclusion. */
|
|
127
|
+
readonly complete: boolean;
|
|
128
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
129
|
+
readonly normalizedDocument?: {
|
|
130
|
+
readonly [key: string]: JsonValue;
|
|
131
|
+
};
|
|
132
|
+
readonly changes: readonly NormalizationChange[];
|
|
133
|
+
}
|
|
134
|
+
/** A permission outcome established by server code, not by document content. */
|
|
135
|
+
interface DocumentAuthority {
|
|
136
|
+
readonly allowed: boolean;
|
|
137
|
+
/** Original document location; use [] for an operation-level denial. */
|
|
138
|
+
readonly path: FieldPath;
|
|
139
|
+
}
|
|
140
|
+
/** An authoritative creation value allocated by the caller, never the editor. */
|
|
141
|
+
interface ServerOwnedField {
|
|
142
|
+
/** Source path to id, actor, attributedTo, published, or updated. */
|
|
143
|
+
readonly path: FieldPath;
|
|
144
|
+
readonly value: string;
|
|
145
|
+
}
|
|
146
|
+
/** Trusted server inputs; these options must not be accepted from a client. */
|
|
147
|
+
interface DocumentPreparationOptions {
|
|
148
|
+
/** At least one explicit outcome is required; omission never means allowed. */
|
|
149
|
+
readonly authority: readonly [DocumentAuthority, ...DocumentAuthority[]];
|
|
150
|
+
readonly serverOwnedFields: readonly ServerOwnedField[];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Checks the implemented Activity Vocabulary types, including nested
|
|
154
|
+
* activity objects, without network access or writes. Embedded objects inherit
|
|
155
|
+
* the parent's context. Collections add member, count, and navigation checks.
|
|
156
|
+
* Question uses shared intransitive rules; poll-specific
|
|
157
|
+
* fields remain unsupported pending #155.
|
|
158
|
+
*
|
|
159
|
+
* Supports allowlisted bundled contexts and simple inline aliases/prefixes,
|
|
160
|
+
* single types, id, string content,
|
|
161
|
+
* attribution/location and activity actor, object, target, origin, result,
|
|
162
|
+
* and instrument values. These can be IRI references or supported
|
|
163
|
+
* embedded types, singly or in flat lists. Empty supported property arrays
|
|
164
|
+
* receive omission previews. Intransitive activities
|
|
165
|
+
* reject a non-null object property. Other forms produce
|
|
166
|
+
* support diagnostics and `complete: false`. This is not a permission check,
|
|
167
|
+
* a Fedify parsability check, or full ActivityStreams validation.
|
|
168
|
+
* The input must be plain JSON data, not a Proxy.
|
|
169
|
+
* Context interpretation is bounded and synchronous. Unknown
|
|
170
|
+
* custom properties are preserved as opaque JSON with warnings. Complex
|
|
171
|
+
* contexts remain unsupported; input is never expanded.
|
|
172
|
+
* Null list entries mean absence. Functional properties accept at most one
|
|
173
|
+
* non-null value, preserving array-index paths. Common text/language maps,
|
|
174
|
+
* timestamps, actor preferredUsername, and addressing are checked.
|
|
175
|
+
* @returns Findings at original-input paths, with an explicit omission preview
|
|
176
|
+
* for empty supported property arrays and absent identifiers only when validation
|
|
177
|
+
* completes without errors.
|
|
178
|
+
*/
|
|
179
|
+
declare function validateDocument(document: unknown): DocumentValidationResult;
|
|
180
|
+
/**
|
|
181
|
+
* Prepares a creation preview against trusted server values and permission
|
|
182
|
+
* outcomes. Does not determine authorization, allocate values, or persist.
|
|
183
|
+
*
|
|
184
|
+
* Integration boundary: https://github.com/fedify-dev/drfed/issues/152
|
|
185
|
+
* The write operation constructs options from trusted server state, not client
|
|
186
|
+
* JSON. It must check every local write, including nested creations, and recheck
|
|
187
|
+
* permissions at commit. This preview is not an authorization token. The caller
|
|
188
|
+
* also owns keeping committed IDs/timestamps consistent with the shown preview.
|
|
189
|
+
* Merely referencing or embedding an actor/resource does not request a write.
|
|
190
|
+
*
|
|
191
|
+
* Paths identify original source locations; owned-field aliases are resolved
|
|
192
|
+
* within the supported context profile. Matching singleton values are retained;
|
|
193
|
+
* absent/null values receive explicit additions/replacements. Conflicts block
|
|
194
|
+
* the preview. Throws TypeError for invalid trusted options/target paths.
|
|
195
|
+
* @returns Original-input diagnostics and any explicit creation preview changes.
|
|
196
|
+
*/
|
|
197
|
+
declare function prepareDocument(document: unknown, options: DocumentPreparationOptions): DocumentValidationResult;
|
|
198
|
+
//#endregion
|
|
199
|
+
export { Diagnostic, DiagnosticCategory, DiagnosticReason, DiagnosticSeverity, DocumentAuthority, DocumentPreparationOptions, DocumentValidationResult, FieldPath, JsonValue, NormalizationChange, ServerOwnedField, diagnosticReasons, prepareDocument, validateDocument };
|
|
200
|
+
//# sourceMappingURL=document.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.mts","names":[],"sources":["../src/document.ts"],"mappings":";;KAqEY;KAEA;KAMA;;cAGC;;aACc;aAAwB;;;aAC/B;aAAwB;;;aACnB;aAAwB;;;aAChC;aAAwB;;;aACnB;aAAwB;;;aACpB;aAAwB;;;aACrB;aAAwB;;;aAChC;aAAwB;;;aACZ;aAAuB;;;aACvB;aAAuB;;;aACvB;aAAqB;;;aACxB;aAAqB;;;aAC7B;aAAqB;;;aACjB;aAAqB;;;aACnB;aAAqB;;;aAClB;aAAqB;;;aACtB;aAAqB;;;aAE/C;aACA;;;aAGA;aACA;;;aAEqB;aAA2B;;;aAC7B;aAA2B;;;KAStC,gCAAgC;UAE3B;WACN,QAAQ;WACR,UAAU;WACV,UAAU;WACV,MAAM;WACN;;KAGC,wDAKC;YACG,cAAc;;;KAGlB;WAEG;WACA;WACA,MAAM;WACN,OAAO;WACP;;WAGA;WACA;WACA,MAAM;WACN,QAAQ;WACR,OAAO;WACP;;WAGA;WACA;WACA,MAAM;WACN,QAAQ;WACR;;UAGE;;WAEN;WACA,sBAAsB;WACtB;cAAiC,cAAc;;WAC/C,kBAAkB;;;UAIZ;WACN;;WAEA,MAAM;;;UAIA;;WAEN,MAAM;WACN;;;UAIM;;WAEN,qBAAqB,sBAAsB;WAC3C,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8yDvB,iBAAiB,oBAAoB;;;;;;;;;;;;;;;;;;iBA0QrC,gBACd,mBACA,SAAS,6BACR"}
|