Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b2d860f

Browse files
committed
refactor(types): refactor Json-LD interfaces
- Replaced inline object types with dedicated interfaces. - Updated ExpandedOperation and ExpandedRdfProperty to use JsonLdValue and JsonLdId. - Streamlined the structure of ExpandedClass and ExpandedDoc interfaces. Signed-off-by: J3m5 <5523410+J3m5@users.noreply.github.com>
1 parent 8db3d52 commit b2d860f

File tree

1 file changed

+48
-147
lines changed

1 file changed

+48
-147
lines changed

‎src/hydra/types.ts‎

Lines changed: 48 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,32 @@ export interface IriTemplateMapping {
55
required: boolean;
66
}
77

8+
/** Any absolute IRI */
9+
type Iri = string;
10+
11+
/** A primitive value wrapped in @value */
12+
interface JsonLdValue<T = string | number | boolean | null> {
13+
"@value": T;
14+
}
15+
16+
/** A node identifier */
17+
interface JsonLdId {
18+
"@id": Iri;
19+
}
20+
21+
/** Zero‐to‐many rdf:types */
22+
interface JsonLdType {
23+
"@type"?: Iri | Iri[];
24+
}
25+
826
export interface ExpandedOperation {
927
"@type": ["http://www.w3.org/ns/hydra/core#Operation"];
10-
"http://www.w3.org/2000/01/rdf-schema#label": [
11-
{
12-
"@value": string;
13-
},
14-
];
15-
"http://www.w3.org/ns/hydra/core#title": [
16-
{
17-
"@value": string;
18-
},
19-
];
20-
"http://www.w3.org/ns/hydra/core#expects"?: [
21-
{
22-
"@id": string;
23-
},
24-
];
25-
"http://www.w3.org/ns/hydra/core#method": [
26-
{
27-
"@value": string;
28-
},
29-
];
30-
"http://www.w3.org/ns/hydra/core#returns"?: [
31-
{
32-
"@id": string;
33-
},
34-
];
35-
"http://www.w3.org/2002/07/owl#deprecated"?: [
36-
{
37-
"@value": boolean;
38-
},
39-
];
28+
"http://www.w3.org/2000/01/rdf-schema#label": [JsonLdValue<string>];
29+
"http://www.w3.org/ns/hydra/core#title": [JsonLdValue<string>];
30+
"http://www.w3.org/ns/hydra/core#expects"?: [JsonLdId];
31+
"http://www.w3.org/ns/hydra/core#method": [JsonLdValue<string>];
32+
"http://www.w3.org/ns/hydra/core#returns"?: [JsonLdId];
33+
"http://www.w3.org/2002/07/owl#deprecated"?: [JsonLdValue<boolean>];
4034
}
4135

4236
export interface ExpandedRdfProperty {
@@ -45,156 +39,63 @@ export interface ExpandedRdfProperty {
4539
| "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
4640
| "http://www.w3.org/ns/hydra/core#Link",
4741
];
48-
"http://www.w3.org/2000/01/rdf-schema#label": [
49-
{
50-
"@value": string;
51-
},
52-
];
53-
"http://www.w3.org/2000/01/rdf-schema#domain": [
54-
{
55-
"@id": string;
56-
},
57-
];
42+
"http://www.w3.org/2000/01/rdf-schema#label": [JsonLdValue<string>];
43+
"http://www.w3.org/2000/01/rdf-schema#domain": [JsonLdId];
5844
"http://www.w3.org/2000/01/rdf-schema#range":
45+
| [JsonLdId]
5946
| [
60-
{
61-
"@id": string;
62-
},
63-
]
64-
| [
65-
{
66-
"@id": string;
67-
},
47+
JsonLdId,
6848
{
6949
"http://www.w3.org/2002/07/owl#equivalentClass": [
7050
{
71-
"http://www.w3.org/2002/07/owl#allValuesFrom": [
72-
{
73-
"@id": string;
74-
},
75-
];
76-
"http://www.w3.org/2002/07/owl#onProperty": [
77-
{
78-
"@id": string;
79-
},
80-
];
51+
"http://www.w3.org/2002/07/owl#allValuesFrom": [JsonLdId];
52+
"http://www.w3.org/2002/07/owl#onProperty": [JsonLdId];
8153
},
8254
];
8355
},
8456
];
8557
"http://www.w3.org/ns/hydra/core#supportedOperation"?: ExpandedOperation[];
86-
"http://www.w3.org/2002/07/owl#maxCardinality": [
87-
{
88-
"@value": number;
89-
},
90-
];
58+
"http://www.w3.org/2002/07/owl#maxCardinality": [JsonLdValue<number>];
9159
}
9260

9361
interface ExpandedSupportedProperty {
9462
"@type": ["http://www.w3.org/ns/hydra/core#SupportedProperty"];
95-
"http://www.w3.org/ns/hydra/core#title": [
96-
{
97-
"@value": string;
98-
},
99-
];
100-
"http://www.w3.org/ns/hydra/core#description": [
101-
{
102-
"@value": string;
103-
},
104-
];
105-
"http://www.w3.org/ns/hydra/core#required"?: [
106-
{
107-
"@value": boolean;
108-
},
109-
];
110-
"http://www.w3.org/ns/hydra/core#readable": [
111-
{
112-
"@value": boolean;
113-
},
114-
];
63+
"http://www.w3.org/ns/hydra/core#title": [JsonLdValue<string>];
64+
"http://www.w3.org/ns/hydra/core#description": [JsonLdValue<string>];
65+
"http://www.w3.org/ns/hydra/core#required"?: [JsonLdValue<boolean>];
66+
"http://www.w3.org/ns/hydra/core#readable": [JsonLdValue<boolean>];
11567
/**
11668
* @deprecated
11769
*/
118-
"http://www.w3.org/ns/hydra/core#writeable": [
119-
{
120-
"@value": boolean;
121-
},
122-
];
123-
"http://www.w3.org/ns/hydra/core#writable": [
124-
{
125-
"@value": boolean;
126-
},
127-
];
70+
"http://www.w3.org/ns/hydra/core#writeable": [JsonLdValue<boolean>];
71+
"http://www.w3.org/ns/hydra/core#writable": [JsonLdValue<boolean>];
12872
"http://www.w3.org/ns/hydra/core#property": [ExpandedRdfProperty];
129-
"http://www.w3.org/2002/07/owl#deprecated"?: [
130-
{
131-
"@value": boolean;
132-
},
133-
];
73+
"http://www.w3.org/2002/07/owl#deprecated"?: [JsonLdValue<boolean>];
13474
}
13575

136-
export interface ExpandedClass {
76+
export interface ExpandedClass extendsJsonLdNode{
13777
"@id": string;
13878
"@type": ["http://www.w3.org/ns/hydra/core#Class"];
139-
"http://www.w3.org/2000/01/rdf-schema#label"?: [
140-
{
141-
"@value": string;
142-
},
143-
];
144-
"http://www.w3.org/2000/01/rdf-schema#subClassOf"?: [
145-
{
146-
"@id": string;
147-
},
148-
];
149-
"http://www.w3.org/ns/hydra/core#title": [
150-
{
151-
"@value": string;
152-
},
153-
];
154-
"http://www.w3.org/ns/hydra/core#description"?: [
155-
{
156-
"@value": string;
157-
},
158-
];
79+
"http://www.w3.org/2000/01/rdf-schema#label"?: [JsonLdValue<string>];
80+
"http://www.w3.org/2000/01/rdf-schema#subClassOf"?: [JsonLdId];
81+
"http://www.w3.org/ns/hydra/core#title": [JsonLdValue<string>];
82+
"http://www.w3.org/ns/hydra/core#description"?: [JsonLdValue<string>];
15983
"http://www.w3.org/ns/hydra/core#supportedProperty": ExpandedSupportedProperty[];
16084
"http://www.w3.org/ns/hydra/core#supportedOperation"?: ExpandedOperation[];
161-
"http://www.w3.org/2002/07/owl#deprecated"?: [
162-
{
163-
"@value": boolean;
164-
},
165-
];
85+
"http://www.w3.org/2002/07/owl#deprecated"?: [JsonLdValue<boolean>];
16686
}
16787

16888
export interface ExpandedDoc {
16989
"@id": string;
17090
"@type": ["http://www.w3.org/ns/hydra/core#ApiDocumentation"];
171-
"http://www.w3.org/ns/hydra/core#title": [
172-
{
173-
"@value": string;
174-
},
175-
];
176-
"http://www.w3.org/ns/hydra/core#description": [
177-
{
178-
"@value": string;
179-
},
180-
];
181-
"http://www.w3.org/ns/hydra/core#entrypoint": [
182-
{
183-
"@value": string;
184-
},
185-
];
91+
"http://www.w3.org/ns/hydra/core#title": [JsonLdValue<string>];
92+
"http://www.w3.org/ns/hydra/core#description": [JsonLdValue<string>];
93+
"http://www.w3.org/ns/hydra/core#entrypoint": [JsonLdValue<string>];
18694
"http://www.w3.org/ns/hydra/core#supportedClass": ExpandedClass[];
18795
}
18896

18997
export interface Entrypoint {
19098
"@id": string;
19199
"@type": [string];
192-
[key: string]:
193-
| [
194-
{
195-
"@id": string;
196-
},
197-
]
198-
| string
199-
| [string];
100+
[key: string]: [JsonLdId] | string | [string];
200101
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /