@lincs.project/webannotation-schema 1.0.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/LICENSE +661 -0
- package/README.md +155 -0
- package/dist/context.jsonld +24 -0
- package/dist/defs.jsonld +949 -0
- package/dist/schema.jsonld +621 -0
- package/dist/validate.js +1 -0
- package/lib/index.d.ts +145 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +13 -0
- package/lib/index.js.map +1 -0
- package/lib/schema/config.d.ts +4 -0
- package/lib/schema/config.d.ts.map +1 -0
- package/lib/schema/config.js +4 -0
- package/lib/schema/config.js.map +1 -0
- package/lib/schema/context.d.ts +25 -0
- package/lib/schema/context.d.ts.map +1 -0
- package/lib/schema/context.js +25 -0
- package/lib/schema/context.js.map +1 -0
- package/lib/schema/definitions/agent.d.ts +36 -0
- package/lib/schema/definitions/agent.d.ts.map +1 -0
- package/lib/schema/definitions/agent.js +82 -0
- package/lib/schema/definitions/agent.js.map +1 -0
- package/lib/schema/definitions/body/citation.d.ts +27 -0
- package/lib/schema/definitions/body/citation.d.ts.map +1 -0
- package/lib/schema/definitions/body/citation.js +53 -0
- package/lib/schema/definitions/body/citation.js.map +1 -0
- package/lib/schema/definitions/body/common.d.ts +17 -0
- package/lib/schema/definitions/body/common.d.ts.map +1 -0
- package/lib/schema/definitions/body/common.js +46 -0
- package/lib/schema/definitions/body/common.js.map +1 -0
- package/lib/schema/definitions/body/conceptualObject.d.ts +27 -0
- package/lib/schema/definitions/body/conceptualObject.d.ts.map +1 -0
- package/lib/schema/definitions/body/conceptualObject.js +61 -0
- package/lib/schema/definitions/body/conceptualObject.js.map +1 -0
- package/lib/schema/definitions/body/correction.d.ts +24 -0
- package/lib/schema/definitions/body/correction.d.ts.map +1 -0
- package/lib/schema/definitions/body/correction.js +54 -0
- package/lib/schema/definitions/body/correction.js.map +1 -0
- package/lib/schema/definitions/body/date.d.ts +30 -0
- package/lib/schema/definitions/body/date.d.ts.map +1 -0
- package/lib/schema/definitions/body/date.js +61 -0
- package/lib/schema/definitions/body/date.js.map +1 -0
- package/lib/schema/definitions/body/index.d.ts +37 -0
- package/lib/schema/definitions/body/index.d.ts.map +1 -0
- package/lib/schema/definitions/body/index.js +220 -0
- package/lib/schema/definitions/body/index.js.map +1 -0
- package/lib/schema/definitions/body/keyword.d.ts +48 -0
- package/lib/schema/definitions/body/keyword.d.ts.map +1 -0
- package/lib/schema/definitions/body/keyword.js +100 -0
- package/lib/schema/definitions/body/keyword.js.map +1 -0
- package/lib/schema/definitions/body/link.d.ts +21 -0
- package/lib/schema/definitions/body/link.d.ts.map +1 -0
- package/lib/schema/definitions/body/link.js +37 -0
- package/lib/schema/definitions/body/link.js.map +1 -0
- package/lib/schema/definitions/body/note.d.ts +27 -0
- package/lib/schema/definitions/body/note.d.ts.map +1 -0
- package/lib/schema/definitions/body/note.js +54 -0
- package/lib/schema/definitions/body/note.js.map +1 -0
- package/lib/schema/definitions/body/organization.d.ts +27 -0
- package/lib/schema/definitions/body/organization.d.ts.map +1 -0
- package/lib/schema/definitions/body/organization.js +65 -0
- package/lib/schema/definitions/body/organization.js.map +1 -0
- package/lib/schema/definitions/body/person.d.ts +27 -0
- package/lib/schema/definitions/body/person.d.ts.map +1 -0
- package/lib/schema/definitions/body/person.js +61 -0
- package/lib/schema/definitions/body/person.js.map +1 -0
- package/lib/schema/definitions/body/physicalThing.d.ts +27 -0
- package/lib/schema/definitions/body/physicalThing.d.ts.map +1 -0
- package/lib/schema/definitions/body/physicalThing.js +61 -0
- package/lib/schema/definitions/body/physicalThing.js.map +1 -0
- package/lib/schema/definitions/body/place.d.ts +30 -0
- package/lib/schema/definitions/body/place.d.ts.map +1 -0
- package/lib/schema/definitions/body/place.js +64 -0
- package/lib/schema/definitions/body/place.js.map +1 -0
- package/lib/schema/definitions/body/work.d.ts +27 -0
- package/lib/schema/definitions/body/work.d.ts.map +1 -0
- package/lib/schema/definitions/body/work.js +61 -0
- package/lib/schema/definitions/body/work.js.map +1 -0
- package/lib/schema/definitions/index.d.ts +22 -0
- package/lib/schema/definitions/index.d.ts.map +1 -0
- package/lib/schema/definitions/index.js +24 -0
- package/lib/schema/definitions/index.js.map +1 -0
- package/lib/schema/definitions/target/index.d.ts +710 -0
- package/lib/schema/definitions/target/index.d.ts.map +1 -0
- package/lib/schema/definitions/target/index.js +231 -0
- package/lib/schema/definitions/target/index.js.map +1 -0
- package/lib/schema/definitions/target/selector/index.d.ts +5 -0
- package/lib/schema/definitions/target/selector/index.d.ts.map +1 -0
- package/lib/schema/definitions/target/selector/index.js +5 -0
- package/lib/schema/definitions/target/selector/index.js.map +1 -0
- package/lib/schema/definitions/target/selector/range.d.ts +141 -0
- package/lib/schema/definitions/target/selector/range.d.ts.map +1 -0
- package/lib/schema/definitions/target/selector/range.js +44 -0
- package/lib/schema/definitions/target/selector/range.js.map +1 -0
- package/lib/schema/definitions/target/selector/textPosition.d.ts +21 -0
- package/lib/schema/definitions/target/selector/textPosition.d.ts.map +1 -0
- package/lib/schema/definitions/target/selector/textPosition.js +57 -0
- package/lib/schema/definitions/target/selector/textPosition.js.map +1 -0
- package/lib/schema/definitions/target/selector/textQuote.d.ts +297 -0
- package/lib/schema/definitions/target/selector/textQuote.d.ts.map +1 -0
- package/lib/schema/definitions/target/selector/textQuote.js +78 -0
- package/lib/schema/definitions/target/selector/textQuote.js.map +1 -0
- package/lib/schema/definitions/target/selector/xpath.d.ts +46 -0
- package/lib/schema/definitions/target/selector/xpath.d.ts.map +1 -0
- package/lib/schema/definitions/target/selector/xpath.js +51 -0
- package/lib/schema/definitions/target/selector/xpath.js.map +1 -0
- package/lib/schema/index.d.ts +5 -0
- package/lib/schema/index.d.ts.map +1 -0
- package/lib/schema/index.js +5 -0
- package/lib/schema/index.js.map +1 -0
- package/lib/schema/root.d.ts +1076 -0
- package/lib/schema/root.d.ts.map +1 -0
- package/lib/schema/root.js +408 -0
- package/lib/schema/root.js.map +1 -0
- package/lib/validation.d.ts +25 -0
- package/lib/validation.d.ts.map +1 -0
- package/lib/validation.js +35 -0
- package/lib/validation.js.map +1 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# LINCS Web Annotation Schema
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
LINCS Web Annotation Schema is a Typescript JSON Schema generator and validator for the browser and NodeJS. It extends the [Web Annotation Model](https://www.w3.org/TR/annotation-model/) and provides the means to validate Web Annotations that follow this schema. The schema is defined by a JSON-LD object constructed using a combination of Typescript objects based on [Zod](https://zod.dev/) and [Ajv](https://ajv.js.org/).
|
|
7
|
+
|
|
8
|
+
The first version of the schema follows the discussion in this [document](https://docs.google.com/document/d/1SkrZTbHMDxupDmsmBsjTTdu7Inlny-eecg369zVaJNM/edit#heading=h.4pfo79y7up7t). Subsequent versions may introduce changes and improve upon this document.
|
|
9
|
+
|
|
10
|
+
You can check the modules and type definitions [Type Docs](https://gitlab.com/calincs/conversion/lincs-webannotation/-/tree/main/packages/schema/docs). Check also the [examples](https://gitlab.com/calincs/conversion/lincs-webannotation/-/tree/main/packages/schema/examples) folder to see how to produce valid LINCS Web Annotations.
|
|
11
|
+
|
|
12
|
+
- [LINCS Web Annotation Schema](#lincs-web-annotation-schema)
|
|
13
|
+
- [Install](#install)
|
|
14
|
+
- [Use](#use)
|
|
15
|
+
- [Types](#types)
|
|
16
|
+
- [Parameters](#parameters)
|
|
17
|
+
- [ValidateResult](#validateresult)
|
|
18
|
+
- [ValidationError](#validationerror)
|
|
19
|
+
- [Assets](#assets)
|
|
20
|
+
- [Ajv Schema Object](#ajv-schema-object)
|
|
21
|
+
- [Typings](#typings)
|
|
22
|
+
- [import types](#import-types)
|
|
23
|
+
- [Development](#development)
|
|
24
|
+
- [Testing](#testing)
|
|
25
|
+
- [Versioning](#versioning)
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
To install it as a dependency, simply type
|
|
30
|
+
`npm install @lincs.project/webannotation-schema`
|
|
31
|
+
|
|
32
|
+
## Use
|
|
33
|
+
|
|
34
|
+
Import the `validate` function from the module and pass the `annotation object`. It returns the [ValidateResult](#validateresult) object with one or two properties: `valid` is a boolean and `errors` lists where the errors occurred if the annotation is not valid.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { validate } from '@lincs.project/webannotation-validator';
|
|
38
|
+
|
|
39
|
+
const validAnnotation = {...};
|
|
40
|
+
const resultValid = validate(validAnnotation);
|
|
41
|
+
console.log(resultValid);
|
|
42
|
+
/*
|
|
43
|
+
{
|
|
44
|
+
valid: true
|
|
45
|
+
}
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
const invalidAnnotation = {...};
|
|
49
|
+
const resultInvalid = validate(invalidAnnotation);
|
|
50
|
+
console.log(resultInvalid);
|
|
51
|
+
/*
|
|
52
|
+
{
|
|
53
|
+
valid: true,
|
|
54
|
+
error: [
|
|
55
|
+
{
|
|
56
|
+
"message": "property 'type' must not have fewer than 2 items",
|
|
57
|
+
"path": "{annotation}.generator.type",
|
|
58
|
+
"context": {
|
|
59
|
+
"errorType": "minItems"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"message": "'0' property must be equal to the allowed value",
|
|
64
|
+
"path": "{annotation}.generator.type.0",
|
|
65
|
+
"context": {
|
|
66
|
+
"errorType": "const",
|
|
67
|
+
"allowedValue": "Software"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
*/
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Types
|
|
76
|
+
|
|
77
|
+
#### Parameters
|
|
78
|
+
|
|
79
|
+
| Name | Type | Description |
|
|
80
|
+
| --------------------- | ------ | ------------------------- |
|
|
81
|
+
| Web Annotation Object | object | The Web Annotation Object |
|
|
82
|
+
|
|
83
|
+
#### ValidateResult
|
|
84
|
+
|
|
85
|
+
| Name | Type | Description |
|
|
86
|
+
| ------ | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
87
|
+
| valid* | boolean | If the Annotation is valid or not |
|
|
88
|
+
| Error | [ValidationError](#validationerror)[] | Collection of error ValidationError from [better-ajv-errors](https://github.com/apideck-libraries/better-ajv-errors) |
|
|
89
|
+
|
|
90
|
+
#### ValidationError
|
|
91
|
+
|
|
92
|
+
| Name | Type | Description |
|
|
93
|
+
| ---------- | ------ | ----------------------------------- |
|
|
94
|
+
| message* | string | Information about the error |
|
|
95
|
+
| path* | string | Error location |
|
|
96
|
+
| context* | object | Specific information about the error |
|
|
97
|
+
| suggestion | string | Suggestion of correction |
|
|
98
|
+
|
|
99
|
+
## Assets
|
|
100
|
+
|
|
101
|
+
Beyond the `validate` function, this module export multiple assets that can be used to build a custom validator ([Ajv Schema Object](#ajv-schema-object)) or assist the developer in building Web Annotations using Typescript ([Typings](#typings)).
|
|
102
|
+
|
|
103
|
+
### Ajv Schema Object
|
|
104
|
+
|
|
105
|
+
It can be used to combine a custom validator.
|
|
106
|
+
|
|
107
|
+
- JSONSchemaType
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import {definitionSchema, webAnnotationSchema } from '@lincs.project/webannotation-schema';
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- Schema Ids (string)
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { defsId, schemaId } from '@lincs.project/webannotation-schema';
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- Schema Context (JSON)
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import {schemaContext} from '@lincs.project/webannotation-schema';
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Typings
|
|
126
|
+
|
|
127
|
+
This module exports types. Check the available types in the documentation [here](?).
|
|
128
|
+
|
|
129
|
+
### import types
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import type { Body, Creator, Motivation, Software, Status, Target, User, WebAnnotation } from '@lincs.project/webannotation-schema';
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
It is also possible to import Zod Schema.
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { Body, Creator, Motivation, Software, Status, Target, User, WebAnnotation } from '@lincs.project/webannotation-schema';
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Development
|
|
142
|
+
|
|
143
|
+
Generate a new version of the schema with valid examples.
|
|
144
|
+
|
|
145
|
+
`npm run generate`
|
|
146
|
+
|
|
147
|
+
### Testing
|
|
148
|
+
|
|
149
|
+
We use jest for testing.
|
|
150
|
+
|
|
151
|
+
`npm test`
|
|
152
|
+
|
|
153
|
+
### Versioning
|
|
154
|
+
|
|
155
|
+
We follow Semantic Versioning. But it is important to note that the context and the schema are made public available on the web. They are also used in our web service for validation [link](link). Thus, when introducing changes, especially if there are **breaking changes**, it is important to update the schema IDs and introduce the new version in the web service.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bf": "http://www.openlinksw.com/schemas/bif#",
|
|
3
|
+
"cito": "https://sparontologies.github.io/cito/current/cito.html#",
|
|
4
|
+
"cwrc": "http://id.lincsproject.ca/cwrc#",
|
|
5
|
+
"edit": "http://id.lincsproject.ca/edit/#",
|
|
6
|
+
"fabio": "https://purl.org/spar/fabio#",
|
|
7
|
+
"frbroo": "https://www.iflastandards.info/fr/frbr/frbroo#",
|
|
8
|
+
"wikidata": "https://www.wikidata.org/wiki/",
|
|
9
|
+
"crm": "http://www.cidoc-crm.org/cidoc-crm/",
|
|
10
|
+
"crmdig": "http://www.ics.forth.gr/isl/CRMdig/",
|
|
11
|
+
"certainty": "crm:P2_has_type",
|
|
12
|
+
"contributor": "dcterms:contributor",
|
|
13
|
+
"description": "rdfs:comment",
|
|
14
|
+
"precision": "crm:P2_has_type",
|
|
15
|
+
"softwareVersion": "schema:softwareVersion",
|
|
16
|
+
"status": "crm:P2_has_type",
|
|
17
|
+
"entityType": "crm:P2_has_type",
|
|
18
|
+
"addicionalType": "crm:P2_has_type",
|
|
19
|
+
"approved": "edit:statusApproved",
|
|
20
|
+
"citing": "edit:citing",
|
|
21
|
+
"correcting": "edit:correcting",
|
|
22
|
+
"draft": "edit:statusDraft",
|
|
23
|
+
"published": "edit:statusPublished"
|
|
24
|
+
}
|