@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.
Files changed (119) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +155 -0
  3. package/dist/context.jsonld +24 -0
  4. package/dist/defs.jsonld +949 -0
  5. package/dist/schema.jsonld +621 -0
  6. package/dist/validate.js +1 -0
  7. package/lib/index.d.ts +145 -0
  8. package/lib/index.d.ts.map +1 -0
  9. package/lib/index.js +13 -0
  10. package/lib/index.js.map +1 -0
  11. package/lib/schema/config.d.ts +4 -0
  12. package/lib/schema/config.d.ts.map +1 -0
  13. package/lib/schema/config.js +4 -0
  14. package/lib/schema/config.js.map +1 -0
  15. package/lib/schema/context.d.ts +25 -0
  16. package/lib/schema/context.d.ts.map +1 -0
  17. package/lib/schema/context.js +25 -0
  18. package/lib/schema/context.js.map +1 -0
  19. package/lib/schema/definitions/agent.d.ts +36 -0
  20. package/lib/schema/definitions/agent.d.ts.map +1 -0
  21. package/lib/schema/definitions/agent.js +82 -0
  22. package/lib/schema/definitions/agent.js.map +1 -0
  23. package/lib/schema/definitions/body/citation.d.ts +27 -0
  24. package/lib/schema/definitions/body/citation.d.ts.map +1 -0
  25. package/lib/schema/definitions/body/citation.js +53 -0
  26. package/lib/schema/definitions/body/citation.js.map +1 -0
  27. package/lib/schema/definitions/body/common.d.ts +17 -0
  28. package/lib/schema/definitions/body/common.d.ts.map +1 -0
  29. package/lib/schema/definitions/body/common.js +46 -0
  30. package/lib/schema/definitions/body/common.js.map +1 -0
  31. package/lib/schema/definitions/body/conceptualObject.d.ts +27 -0
  32. package/lib/schema/definitions/body/conceptualObject.d.ts.map +1 -0
  33. package/lib/schema/definitions/body/conceptualObject.js +61 -0
  34. package/lib/schema/definitions/body/conceptualObject.js.map +1 -0
  35. package/lib/schema/definitions/body/correction.d.ts +24 -0
  36. package/lib/schema/definitions/body/correction.d.ts.map +1 -0
  37. package/lib/schema/definitions/body/correction.js +54 -0
  38. package/lib/schema/definitions/body/correction.js.map +1 -0
  39. package/lib/schema/definitions/body/date.d.ts +30 -0
  40. package/lib/schema/definitions/body/date.d.ts.map +1 -0
  41. package/lib/schema/definitions/body/date.js +61 -0
  42. package/lib/schema/definitions/body/date.js.map +1 -0
  43. package/lib/schema/definitions/body/index.d.ts +37 -0
  44. package/lib/schema/definitions/body/index.d.ts.map +1 -0
  45. package/lib/schema/definitions/body/index.js +220 -0
  46. package/lib/schema/definitions/body/index.js.map +1 -0
  47. package/lib/schema/definitions/body/keyword.d.ts +48 -0
  48. package/lib/schema/definitions/body/keyword.d.ts.map +1 -0
  49. package/lib/schema/definitions/body/keyword.js +100 -0
  50. package/lib/schema/definitions/body/keyword.js.map +1 -0
  51. package/lib/schema/definitions/body/link.d.ts +21 -0
  52. package/lib/schema/definitions/body/link.d.ts.map +1 -0
  53. package/lib/schema/definitions/body/link.js +37 -0
  54. package/lib/schema/definitions/body/link.js.map +1 -0
  55. package/lib/schema/definitions/body/note.d.ts +27 -0
  56. package/lib/schema/definitions/body/note.d.ts.map +1 -0
  57. package/lib/schema/definitions/body/note.js +54 -0
  58. package/lib/schema/definitions/body/note.js.map +1 -0
  59. package/lib/schema/definitions/body/organization.d.ts +27 -0
  60. package/lib/schema/definitions/body/organization.d.ts.map +1 -0
  61. package/lib/schema/definitions/body/organization.js +65 -0
  62. package/lib/schema/definitions/body/organization.js.map +1 -0
  63. package/lib/schema/definitions/body/person.d.ts +27 -0
  64. package/lib/schema/definitions/body/person.d.ts.map +1 -0
  65. package/lib/schema/definitions/body/person.js +61 -0
  66. package/lib/schema/definitions/body/person.js.map +1 -0
  67. package/lib/schema/definitions/body/physicalThing.d.ts +27 -0
  68. package/lib/schema/definitions/body/physicalThing.d.ts.map +1 -0
  69. package/lib/schema/definitions/body/physicalThing.js +61 -0
  70. package/lib/schema/definitions/body/physicalThing.js.map +1 -0
  71. package/lib/schema/definitions/body/place.d.ts +30 -0
  72. package/lib/schema/definitions/body/place.d.ts.map +1 -0
  73. package/lib/schema/definitions/body/place.js +64 -0
  74. package/lib/schema/definitions/body/place.js.map +1 -0
  75. package/lib/schema/definitions/body/work.d.ts +27 -0
  76. package/lib/schema/definitions/body/work.d.ts.map +1 -0
  77. package/lib/schema/definitions/body/work.js +61 -0
  78. package/lib/schema/definitions/body/work.js.map +1 -0
  79. package/lib/schema/definitions/index.d.ts +22 -0
  80. package/lib/schema/definitions/index.d.ts.map +1 -0
  81. package/lib/schema/definitions/index.js +24 -0
  82. package/lib/schema/definitions/index.js.map +1 -0
  83. package/lib/schema/definitions/target/index.d.ts +710 -0
  84. package/lib/schema/definitions/target/index.d.ts.map +1 -0
  85. package/lib/schema/definitions/target/index.js +231 -0
  86. package/lib/schema/definitions/target/index.js.map +1 -0
  87. package/lib/schema/definitions/target/selector/index.d.ts +5 -0
  88. package/lib/schema/definitions/target/selector/index.d.ts.map +1 -0
  89. package/lib/schema/definitions/target/selector/index.js +5 -0
  90. package/lib/schema/definitions/target/selector/index.js.map +1 -0
  91. package/lib/schema/definitions/target/selector/range.d.ts +141 -0
  92. package/lib/schema/definitions/target/selector/range.d.ts.map +1 -0
  93. package/lib/schema/definitions/target/selector/range.js +44 -0
  94. package/lib/schema/definitions/target/selector/range.js.map +1 -0
  95. package/lib/schema/definitions/target/selector/textPosition.d.ts +21 -0
  96. package/lib/schema/definitions/target/selector/textPosition.d.ts.map +1 -0
  97. package/lib/schema/definitions/target/selector/textPosition.js +57 -0
  98. package/lib/schema/definitions/target/selector/textPosition.js.map +1 -0
  99. package/lib/schema/definitions/target/selector/textQuote.d.ts +297 -0
  100. package/lib/schema/definitions/target/selector/textQuote.d.ts.map +1 -0
  101. package/lib/schema/definitions/target/selector/textQuote.js +78 -0
  102. package/lib/schema/definitions/target/selector/textQuote.js.map +1 -0
  103. package/lib/schema/definitions/target/selector/xpath.d.ts +46 -0
  104. package/lib/schema/definitions/target/selector/xpath.d.ts.map +1 -0
  105. package/lib/schema/definitions/target/selector/xpath.js +51 -0
  106. package/lib/schema/definitions/target/selector/xpath.js.map +1 -0
  107. package/lib/schema/index.d.ts +5 -0
  108. package/lib/schema/index.d.ts.map +1 -0
  109. package/lib/schema/index.js +5 -0
  110. package/lib/schema/index.js.map +1 -0
  111. package/lib/schema/root.d.ts +1076 -0
  112. package/lib/schema/root.d.ts.map +1 -0
  113. package/lib/schema/root.js +408 -0
  114. package/lib/schema/root.js.map +1 -0
  115. package/lib/validation.d.ts +25 -0
  116. package/lib/validation.d.ts.map +1 -0
  117. package/lib/validation.js +35 -0
  118. package/lib/validation.js.map +1 -0
  119. package/package.json +68 -0
package/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # LINCS Web Annotation Schema
2
+
3
+ ![NPM](https://img.shields.io/npm/l/@cwrc/leafwriter-validator)
4
+ ![npm type definitions](https://img.shields.io/npm/types/@cwrc/leafwriter-validator)
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
+ }