-
Notifications
You must be signed in to change notification settings - Fork 121
/
Vocabularies.ts
161 lines (134 loc) · 4.83 KB
/
Vocabularies.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* eslint-disable function-paren-newline */
import { namedNode } from '@rdfjs/data-model';
import type { NamedNode } from 'rdf-js';
type RecordOf<TKey extends any[], TValue> = Record<TKey[number], TValue>;
export type Namespace<TKey extends any[], TValue> =
{ namespace: TValue } & RecordOf<TKey, TValue>;
/**
* Creates a function that expands local names from the given base URI,
* and exports the given local names as properties on the returned object.
*/
export function createNamespace<TKey extends string, TValue>(
baseUri: string,
toValue: (expanded: string) => TValue,
...localNames: TKey[]):
Namespace<typeof localNames, TValue> {
const expanded: Namespace<typeof localNames, TValue> = {} as any;
// Expose the main namespace
expanded.namespace = toValue(baseUri);
// Expose the listed local names as properties
for (const localName of localNames) {
(expanded as RecordOf<TKey[], TValue>)[localName] = toValue(`${baseUri}${localName}`);
}
return expanded;
}
/**
* Creates a function that expands local names from the given base URI into strings,
* and exports the given local names as properties on the returned object.
*/
export function createUriNamespace<T extends string>(baseUri: string, ...localNames: T[]):
Namespace<typeof localNames, string> {
return createNamespace(baseUri, (expanded): string => expanded, ...localNames);
}
/**
* Creates a function that expands local names from the given base URI into named nodes,
* and exports the given local names as properties on the returned object.
*/
export function createTermNamespace<T extends string>(baseUri: string, ...localNames: T[]):
Namespace<typeof localNames, NamedNode> {
return createNamespace(baseUri, namedNode, ...localNames);
}
/**
* Creates a function that expands local names from the given base URI into string,
* and exports the given local names as properties on the returned object.
* Under the `terms` property, it exposes the expanded local names as named nodes.
*/
export function createUriAndTermNamespace<T extends string>(baseUri: string, ...localNames: T[]):
Namespace<typeof localNames, string> & { terms: Namespace<typeof localNames, NamedNode> } {
return Object.assign(createUriNamespace(baseUri, ...localNames),
{ terms: createTermNamespace(baseUri, ...localNames) });
}
export const ACL = createUriAndTermNamespace('http://www.w3.org/ns/auth/acl#',
'accessTo',
'agent',
'agentClass',
'agentGroup',
'AuthenticatedAgent',
'Authorization',
'default',
'mode',
'Write',
'Read',
'Append',
'Control',
);
export const AUTH = createUriAndTermNamespace('urn:solid:auth:',
'userMode',
'publicMode',
);
export const DC = createUriAndTermNamespace('http://purl.org/dc/terms/',
'description',
'modified',
'title',
);
export const FOAF = createUriAndTermNamespace('http://xmlns.com/foaf/0.1/',
'Agent',
);
export const HTTP = createUriAndTermNamespace('http://www.w3.org/2011/http#',
'statusCodeNumber',
);
export const LDP = createUriAndTermNamespace('http://www.w3.org/ns/ldp#',
'contains',
'BasicContainer',
'Container',
'Resource',
);
export const MA = createUriAndTermNamespace('http://www.w3.org/ns/ma-ont#',
'format',
);
export const OIDC = createUriAndTermNamespace('http://www.w3.org/ns/solid/oidc#',
'redirect_uris',
);
export const PIM = createUriAndTermNamespace('http://www.w3.org/ns/pim/space#',
'Storage',
);
export const POSIX = createUriAndTermNamespace('http://www.w3.org/ns/posix/stat#',
'mtime',
'size',
);
export const RDF = createUriAndTermNamespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'type',
);
export const SOLID = createUriAndTermNamespace('http://www.w3.org/ns/solid/terms#',
'oidcIssuer',
'oidcIssuerRegistrationToken',
'oidcRegistration',
);
export const SOLID_ERROR = createUriAndTermNamespace('urn:npm:solid:community-server:error:',
'stack',
);
export const SOLID_HTTP = createUriAndTermNamespace('urn:npm:solid:community-server:http:',
'location',
'slug',
);
export const SOLID_META = createUriAndTermNamespace('urn:npm:solid:community-server:meta:',
// This identifier is used as graph for all metadata that is generated on the fly and should not be stored
'ResponseMetadata',
// This is used to identify templates that can be used for the representation of a resource
'template',
);
export const VANN = createUriAndTermNamespace('http://purl.org/vocab/vann/',
'preferredNamespacePrefix',
);
export const VCARD = createUriAndTermNamespace('http://www.w3.org/2006/vcard/ns#',
'hasMember',
);
export const XSD = createUriAndTermNamespace('http://www.w3.org/2001/XMLSchema#',
'dateTime',
'integer',
);
// Alias for commonly used types
export const CONTENT_TYPE = MA.format;
export const CONTENT_TYPE_TERM = MA.terms.format;
export const PREFERRED_PREFIX = VANN.preferredNamespacePrefix;
export const PREFERRED_PREFIX_TERM = VANN.terms.preferredNamespacePrefix;