@chronicle.app/schema 0.3.0 → 0.5.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.
- package/README.md +89 -19
- package/chronicle.ttl +1023 -579
- package/dist/datetime.d.ts +10 -0
- package/dist/datetime.js +49 -0
- package/dist/identity.d.ts +59 -0
- package/dist/identity.js +166 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/schema.d.ts +317 -74
- package/dist/schema.js +1227 -419
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@ A deliberately small extraction vocabulary with generated TypeScript interfaces
|
|
|
4
4
|
and Zod validators. The canonical file is [chronicle.ttl](chronicle.ttl); edit it and run
|
|
5
5
|
`npm run schema:generate` from the repository root to regenerate the TypeScript/Zod
|
|
6
6
|
schemas. `npm run schema:check` verifies that the committed output matches the
|
|
7
|
-
ontology without rewriting it.
|
|
7
|
+
ontology without rewriting it. Write each term's `rdfs:comment` by the rules in
|
|
8
|
+
[WRITING.md](WRITING.md).
|
|
8
9
|
|
|
9
10
|
## Documentation site
|
|
10
11
|
|
|
@@ -13,6 +14,40 @@ The schema is documented at https://schema.chronicle.app, built from
|
|
|
13
14
|
site lives in [apps/schema-site](../../apps/schema-site), which also describes
|
|
14
15
|
the examples format.
|
|
15
16
|
|
|
17
|
+
## Other vocabularies
|
|
18
|
+
|
|
19
|
+
Chronicle's vocabulary stands on its own. It borrows schema.org's model and
|
|
20
|
+
names, and `chronicle.ttl` points each term to the closest schema.org term as a
|
|
21
|
+
hint for mapping data between them: `skos:exactMatch` for the same meaning,
|
|
22
|
+
`skos:closeMatch` for a similar one, and `skos:broadMatch` when schema.org's
|
|
23
|
+
term is broader. A reasoner draws nothing from SKOS mappings, so the hints
|
|
24
|
+
don't claim the vocabularies are compatible. They aren't: values, scope, and
|
|
25
|
+
structure differ in places. No `rdfs:subClassOf`, `rdfs:subPropertyOf`,
|
|
26
|
+
`owl:equivalentClass`, or `owl:equivalentProperty` points to another
|
|
27
|
+
vocabulary, and the schema site's build fails on one.
|
|
28
|
+
|
|
29
|
+
[alignments/](alignments) holds one file for each vocabulary that Chronicle's
|
|
30
|
+
terms relate to, `schemaorg.ttl` and `activitystreams.ttl`. Each names the
|
|
31
|
+
release its terms were checked against, and holds:
|
|
32
|
+
|
|
33
|
+
- `doc:note`: how a Chronicle term differs from the term it maps to, written
|
|
34
|
+
by the rules in [WRITING.md](WRITING.md#8-notes-on-other-vocabularies).
|
|
35
|
+
- `doc:unlike`: a term with the same name as a Chronicle term but a different
|
|
36
|
+
meaning, such as schema.org's `Project`.
|
|
37
|
+
- The mappings to any vocabulary other than schema.org. They can change
|
|
38
|
+
without a vocabulary release.
|
|
39
|
+
|
|
40
|
+
`<name>.terms.json` lists the classes and properties of the release. To move to
|
|
41
|
+
a newer one, run `node scripts/snapshot-vocabulary.js schemaorg <release>` (or
|
|
42
|
+
`activitystreams`), update `doc:release`, and fix what the schema site's build
|
|
43
|
+
reports. The site shows each term's relations, has a page for each vocabulary,
|
|
44
|
+
and fails when a mapping names a term the release does not have, or when a
|
|
45
|
+
Chronicle term shares a name with a term it neither maps to nor marks unlike.
|
|
46
|
+
Names are also compared without the endings in `doc:nameEnding`, so
|
|
47
|
+
`LikeAction` is compared with Activity Streams' `Like`. To relate the
|
|
48
|
+
vocabulary to another one, add its alignment, its `.terms.json`, and a
|
|
49
|
+
comparison in [the site's vocabularies/](../../apps/schema-site/vocabularies).
|
|
50
|
+
|
|
16
51
|
## Vocabulary
|
|
17
52
|
|
|
18
53
|
- `Base`: an identity-bearing node; carries `sourceId`.
|
|
@@ -27,9 +62,10 @@ visits, trips, places, and journeys; WhatsApp adds group channels, members, and
|
|
|
27
62
|
quoted replies. Shared properties cover source identity,
|
|
28
63
|
event time, agents, membership, authors, and recipients.
|
|
29
64
|
|
|
30
|
-
`Text`, `URL`, `DateTime`,
|
|
31
|
-
`
|
|
32
|
-
|
|
65
|
+
`Text`, `URL`, `DateTime`, and `Number` are datatypes. A
|
|
66
|
+
`DateTime` is a `Date` or an EDTF string at the source's precision, such as `1987` or
|
|
67
|
+
`XXXX-03-12`; `isDateTime` checks a string. A property takes a list of values
|
|
68
|
+
unless its SHACL shape sets `sh:maxCount 1`. Records carry `@type` and at least one of `@key` (a nonempty list of
|
|
33
69
|
identity fields or computed key entries) or `@id` (an existing identity). A
|
|
34
70
|
record can also carry `@assertedAt`, the instant its source observed it, and
|
|
35
71
|
`@asserts`, the predicates it states completely (`'*'` for all of them).
|
|
@@ -64,12 +100,44 @@ and cardinality. Unknown object fields are stripped by Zod; undeclared record
|
|
|
64
100
|
types are rejected. Import interfaces such as `Entity` and `Action` for static
|
|
65
101
|
typing; use validators at runtime to enforce identity requirements.
|
|
66
102
|
|
|
103
|
+
## Writing the ontology
|
|
104
|
+
|
|
105
|
+
`chronicle.ttl` says what terms mean in OWL, and how records use them in SHACL:
|
|
106
|
+
|
|
107
|
+
- A class is an `owl:Class`. `:Base` is the disjoint union of `:Entity` and
|
|
108
|
+
`:Action`, so nothing is both.
|
|
109
|
+
- A property is an `owl:ObjectProperty` when it links to records and an
|
|
110
|
+
`owl:DatatypeProperty` when it holds values. `:sameAs` takes either, so it is
|
|
111
|
+
an `rdf:Property`.
|
|
112
|
+
- A property's `rdfs:domain` and `rdfs:range` name one term, or several in one
|
|
113
|
+
`owl:unionOf`. Don't add a second `rdfs:domain` or `rdfs:range`: OWL reads two
|
|
114
|
+
as both at once, so the generator rejects it.
|
|
115
|
+
- A datatype is an `rdfs:Datatype` defined over XSD. Each accepts the plain
|
|
116
|
+
strings that Chronicle JSON becomes in JSON-LD as well as typed values, such
|
|
117
|
+
as an `xsd:dateTime` for an instant.
|
|
118
|
+
- A property can name its inverse with `:inverseName`, such as `hasPart` on
|
|
119
|
+
`:isPartOf`. A record can give the relation under either name, so a whole
|
|
120
|
+
can list its parts, and only the forward edge is stored. The generated
|
|
121
|
+
`INVERSE_PROPERTIES` maps each inverse name to its forward property.
|
|
122
|
+
- A number property can say what form its values take with `:metric`. A
|
|
123
|
+
`gauge` is a level or a rate, such as a heart rate, and combines as a mean,
|
|
124
|
+
minimum, or maximum. A `sum` is an amount, such as a number of steps, and
|
|
125
|
+
adds up. A metric's `:unit` is the one unit all its values are in, as a UCUM
|
|
126
|
+
code such as `/min`. The generated `METRIC_PROPERTIES` gives each metric's
|
|
127
|
+
form and unit.
|
|
128
|
+
- A SHACL property shape after a property holds its record rules. `sh:maxCount 1`
|
|
129
|
+
makes it take one value. A shape with `sh:targetClass` and `sh:minCount 1`
|
|
130
|
+
makes it required on that class.
|
|
131
|
+
|
|
67
132
|
## Generation and compatibility
|
|
68
133
|
|
|
69
|
-
The generator turns
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
134
|
+
The generator turns the ontology into TypeScript types and Zod validators. It
|
|
135
|
+
reads terms through `scripts/terms.js`, which the schema site also uses. It
|
|
136
|
+
handles inheritance, including a class with two parents, domains and ranges,
|
|
137
|
+
and SHACL counts, and it fails for cyclic inheritance, undeclared referenced
|
|
138
|
+
classes, a property with two domains or ranges, or a metric that isn't a
|
|
139
|
+
gauge or a sum of numbers in one unit. The package has no
|
|
140
|
+
persistence metadata, derived effects, or runtime filesystem parser.
|
|
73
141
|
Generated runtime code depends only on Zod; the TTL is also included in the package.
|
|
74
142
|
|
|
75
143
|
## Schema versions
|
|
@@ -84,12 +152,13 @@ Release notes map software versions to vocabulary versions.
|
|
|
84
152
|
The package exports `@chronicle.app/schema/chronicle.ttl`; the former
|
|
85
153
|
`@chronicle.app/schema/schema.ttl` export remains an alias for compatibility.
|
|
86
154
|
|
|
87
|
-
Use patch releases for description corrections that preserve meaning
|
|
88
|
-
releases for
|
|
89
|
-
terms,
|
|
90
|
-
|
|
91
|
-
`https://schema.chronicle.app/Task`
|
|
92
|
-
|
|
155
|
+
Use patch releases for description corrections that preserve meaning and minor
|
|
156
|
+
releases for anything else. Until 1.0, a minor release can rename or remove
|
|
157
|
+
terms, change what they mean, or add constraints, so data that validates against
|
|
158
|
+
one minor version may not validate against the next. From 1.0, those changes need
|
|
159
|
+
a major release. Term identifiers such as `https://schema.chronicle.app/Task` are
|
|
160
|
+
unversioned, so don't reuse one for a different concept. Give that concept a new
|
|
161
|
+
term.
|
|
93
162
|
|
|
94
163
|
Snapshot paths use the vocabulary version, not the npm package version.
|
|
95
164
|
The publication convention is
|
|
@@ -98,13 +167,14 @@ documentation under the same release path. Published snapshots must never be
|
|
|
98
167
|
overwritten or removed by later deployments. The unversioned `/chronicle.ttl`
|
|
99
168
|
and term pages serve `main`, so `main` holds only vocabulary that is ready to
|
|
100
169
|
publish: work on new terms in a branch until it is ready. Any change to
|
|
101
|
-
`chronicle.ttl` after a release must raise `owl:versionInfo
|
|
102
|
-
`npm run schema:check`
|
|
170
|
+
`chronicle.ttl` after a release must raise `owl:versionInfo`. While the
|
|
171
|
+
vocabulary is in flux, `npm run schema:check` doesn't check this, so run
|
|
172
|
+
`npm run version:check` before a release to compare against the latest release
|
|
173
|
+
tag. See [Preparing a release](../../RELEASING.md) for the
|
|
103
174
|
release procedure.
|
|
104
175
|
|
|
105
|
-
The vocabulary is intentionally small. Add terms only when a plugin needs them
|
|
106
|
-
|
|
107
|
-
focused tests alongside each addition.
|
|
176
|
+
The vocabulary is intentionally small. Add terms only when a plugin needs them;
|
|
177
|
+
regenerate and add focused tests alongside each addition.
|
|
108
178
|
|
|
109
179
|
Node.js 22.13+. MIT covers the ontology, generator, generated code, and docs;
|
|
110
180
|
see [LICENSE](LICENSE).
|