-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.ts
71 lines (69 loc) · 1.61 KB
/
schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { JSONSchemaType } from 'ajv/dist/2020.js'
export const notification: JSONSchemaType<{
type: 'Create' | 'Update' | 'Delete'
id: string
'@context': 'https://www.w3.org/ns/activitystreams'
actor: { type: 'Person'; id: string }
object: {
type: 'Document' | 'Place'
id: string
}
}> = {
type: 'object',
properties: {
'@context': {
type: 'string',
const: 'https://www.w3.org/ns/activitystreams',
},
id: { type: 'string' },
type: { type: 'string', enum: ['Create', 'Update', 'Delete'] },
actor: {
type: 'object',
properties: {
type: { type: 'string', const: 'Person' },
id: { type: 'string', format: 'uri' },
},
required: ['type', 'id'],
},
object: {
type: 'object',
properties: {
type: { type: 'string', enum: ['Document', 'Place'] },
id: { type: 'string', format: 'uri' },
},
required: ['type', 'id'],
},
},
required: ['@context', 'type', 'actor', 'object'],
additionalProperties: false,
}
export const rawThingSchema = (
thingTypes: string[],
): JSONSchemaType<{
types: string[]
latitudes: number[]
longitudes: number[]
}> => ({
type: 'object',
properties: {
types: {
type: 'array',
minItems: 1,
items: { type: 'string' },
contains: { enum: thingTypes },
},
latitudes: {
type: 'array',
minItems: 1,
maxItems: 1,
items: { type: 'number' },
},
longitudes: {
type: 'array',
minItems: 1,
maxItems: 1,
items: { type: 'number' },
},
},
required: ['types', 'latitudes', 'longitudes'],
})