Skip to content

Commit 592ea1a

Browse files
committed
removes embedded json-ld context
1 parent 3c7535a commit 592ea1a

8 files changed

Lines changed: 71 additions & 68 deletions

File tree

src/Constants.ts

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -47,59 +47,8 @@ export type HydraTerm = 'apiDocumentation' |
4747
'object';
4848

4949
export namespace Core {
50-
export const Context = {
51-
hydra: 'http://www.w3.org/ns/hydra/core#',
52-
apiDocumentation: 'hydra:apiDocumentation',
53-
ApiDocumentation: 'hydra:ApiDocumentation',
54-
title: 'hydra:title',
55-
description: 'hydra:description',
56-
entrypoint: {'@id': 'hydra:entrypoint', '@type': '@id'},
57-
supportedClass: {'@id': 'hydra:supportedClass', '@type': '@vocab'},
58-
Class: 'hydra:Class',
59-
supportedProperty: {'@id': 'hydra:supportedProperty', '@type': '@id'},
60-
SupportedProperty: 'hydra:SupportedProperty',
61-
property: {'@id': 'hydra:property', '@type': '@vocab'},
62-
required: 'hydra:required',
63-
readonly: 'hydra:readonly',
64-
writeonly: 'hydra:writeonly',
65-
supportedOperation: {'@id': 'hydra:supportedOperation', '@type': '@id'},
66-
Operation: 'hydra:SupportedOperation',
67-
CreateResourceOperation: 'hydra:CreateResourceOperation',
68-
ReplaceResourceOperation: 'hydra:ReplaceResourceOperation',
69-
DeleteResourceOperation: 'hydra:DeleteResourceOperation',
70-
method: 'hydra:method',
71-
expects: {'@id': 'hydra:expects', '@type': '@vocab'},
72-
returns: {'@id': 'hydra:returns', '@type': '@vocab'},
73-
statusCodes: {'@id': 'hydra:statusCodes', '@type': '@id'},
74-
StatusCodeDescription: 'hydra:StatusCodeDescription',
75-
statusCode: 'hydra:statusCode',
76-
Error: 'hydra:Error',
77-
Resource: 'hydra:Resource',
78-
operation: 'hydra:operation',
79-
Collection: 'hydra:Collection',
80-
member: {'@id': 'hydra:member', '@type': '@id'},
81-
search: 'hydra:search',
82-
freetextQuery: 'hydra:freetextQuery',
83-
PagedCollection: 'hydra:PagedCollection',
84-
totalItems: 'hydra:totalItems',
85-
itemsPerPage: 'hydra:itemsPerPage',
86-
firstPage: {'@id': 'hydra:firstPage', '@type': '@id'},
87-
lastPage: {'@id': 'hydra:lastPage', '@type': '@id'},
88-
nextPage: {'@id': 'hydra:nextPage', '@type': '@id'},
89-
previousPage: {'@id': 'hydra:previousPage', '@type': '@id'},
90-
Link: 'hydra:Link',
91-
TemplatedLink: 'hydra:TemplatedLink',
92-
IriTemplate: 'hydra:IriTemplate',
93-
template: 'hydra:template',
94-
mapping: 'hydra:mapping',
95-
IriTemplateMapping: 'hydra:IriTemplateMapping',
96-
variable: 'hydra:variable',
97-
collection: 'hydra:collection',
98-
manages: 'hydra:manages',
99-
};
100-
10150
export function Vocab(term: HydraTerm) {
102-
return Core.Context.hydra + term;
51+
return 'http://www.w3.org/ns/hydra/core#' + term;
10352
}
10453
}
10554

src/Resources/Resource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export default class implements IResource {
3636
isProcessed.set(this, val);
3737
}
3838

39-
public compact(context: any = null) {
40-
return jsonld.compact(this, context || Core.Context);
39+
public compact(context: any = 'https://www.w3.org/ns/hydra/core') {
40+
return jsonld.compact(this, context);
4141
}
4242

4343
public _get(property: string) {

tests/Resources/Class-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {promises as jsonld} from 'jsonld';
2-
import {Core} from '../../src/Constants';
32
import {Mixin} from '../../src/Resources/Mixins/Class';
43
import Resource from '../../src/Resources/Resource';
4+
import Context from '../test-objects/Context';
55

66
class Class extends Mixin(Resource) {}
77

88
describe('Class', () => {
99

1010
const hydraClass = {
11-
'@context': Core.Context,
11+
'@context': Context,
1212
'@id': 'http://example.com/vocab#SomeClass',
1313
'supportedOperation': [{}],
1414
'supportedProperty': [{}],

tests/Resources/DocumentedResource-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {promises as jsonld} from 'jsonld';
2-
import {Core} from '../../src/Constants';
32
import {Mixin} from '../../src/Resources/Mixins/DocumentedResource';
43
import Resource from '../../src/Resources/Resource';
4+
import Context from '../test-objects/Context';
55

66
class DocumentedResource extends Mixin(Resource) {}
77

88
describe('DocumentedResource', () => {
99

1010
const hydraDescriptionJsonLd = {
11-
'@context': Core.Context,
11+
'@context': Context,
1212
'description': 'The longer description',
1313
'http://some/custom/property': 'The value',
1414
'title': 'The title',

tests/Resources/RdfProperty-spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Core} from '../../src/Constants';
33
import {Mixin} from '../../src/Resources/Mixins/RdfProperty';
44
import Resource from '../../src/Resources/Resource';
55
import {owl, rdf, rdfs, xsd} from '../../src/Vocabs';
6+
import Context from '../test-objects/Context';
67

78
class RdfProperty extends Mixin(Resource) {}
89

@@ -13,7 +14,7 @@ describe('RdfProperty', () => {
1314
beforeEach(() => {
1415
testProperty = {
1516
'@context': [
16-
Core.Context,
17+
Context,
1718
{
1819
rdfs: rdfs(),
1920
},

tests/Resources/SupportedOperation-spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Core} from '../../src/Constants';
33
import {Mixin} from '../../src/Resources/Mixins/SupportedOperation';
44
import Resource from '../../src/Resources/Resource';
55
import {owl} from '../../src/Vocabs';
6+
import Context from '../test-objects/Context';
67

78
class SupportedOperation extends Mixin(Resource) {}
89

@@ -11,7 +12,7 @@ describe('SupportedOperation', () => {
1112
let operationJsonLd;
1213

1314
beforeEach(() => operationJsonLd = {
14-
'@context': Core.Context,
15+
'@context': Context,
1516
'description': 'The operation description',
1617
'expects': owl.Nothing,
1718
'method': 'TRACE',
@@ -57,7 +58,7 @@ describe('SupportedOperation', () => {
5758
it('should return false for GET operation', async () => {
5859
// given
5960
const operation = {
60-
'@context': Core.Context,
61+
'@context': Context,
6162
'method': 'GET',
6263
};
6364

@@ -73,7 +74,7 @@ describe('SupportedOperation', () => {
7374
it('should return false for DELETE operation', async () => {
7475
// given
7576
const operation = {
76-
'@context': Core.Context,
77+
'@context': Context,
7778
'method': 'DELETE',
7879
};
7980

@@ -89,7 +90,7 @@ describe('SupportedOperation', () => {
8990
it('should return true if operation expects a body', async () => {
9091
// given
9192
const operation = {
92-
'@context': Core.Context,
93+
'@context': Context,
9394
'method': 'POST',
9495
};
9596

@@ -105,7 +106,7 @@ describe('SupportedOperation', () => {
105106
it('should return true if operation expects nothing', async () => {
106107
// given
107108
const operation = {
108-
'@context': Core.Context,
109+
'@context': Context,
109110
'method': 'POST',
110111
};
111112

tests/test-objects/Context.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* tslint:disable:object-literal-sort-keys */
2+
export default {
3+
hydra: 'http://www.w3.org/ns/hydra/core#',
4+
apiDocumentation: 'hydra:apiDocumentation',
5+
ApiDocumentation: 'hydra:ApiDocumentation',
6+
title: 'hydra:title',
7+
description: 'hydra:description',
8+
entrypoint: {'@id': 'hydra:entrypoint', '@type': '@id'},
9+
supportedClass: {'@id': 'hydra:supportedClass', '@type': '@vocab'},
10+
Class: 'hydra:Class',
11+
supportedProperty: {'@id': 'hydra:supportedProperty', '@type': '@id'},
12+
SupportedProperty: 'hydra:SupportedProperty',
13+
property: {'@id': 'hydra:property', '@type': '@vocab'},
14+
required: 'hydra:required',
15+
readonly: 'hydra:readonly',
16+
writeonly: 'hydra:writeonly',
17+
supportedOperation: {'@id': 'hydra:supportedOperation', '@type': '@id'},
18+
Operation: 'hydra:SupportedOperation',
19+
CreateResourceOperation: 'hydra:CreateResourceOperation',
20+
ReplaceResourceOperation: 'hydra:ReplaceResourceOperation',
21+
DeleteResourceOperation: 'hydra:DeleteResourceOperation',
22+
method: 'hydra:method',
23+
expects: {'@id': 'hydra:expects', '@type': '@vocab'},
24+
returns: {'@id': 'hydra:returns', '@type': '@vocab'},
25+
statusCodes: {'@id': 'hydra:statusCodes', '@type': '@id'},
26+
StatusCodeDescription: 'hydra:StatusCodeDescription',
27+
statusCode: 'hydra:statusCode',
28+
Error: 'hydra:Error',
29+
Resource: 'hydra:Resource',
30+
operation: 'hydra:operation',
31+
Collection: 'hydra:Collection',
32+
member: {'@id': 'hydra:member', '@type': '@id'},
33+
search: 'hydra:search',
34+
freetextQuery: 'hydra:freetextQuery',
35+
PagedCollection: 'hydra:PagedCollection',
36+
totalItems: 'hydra:totalItems',
37+
itemsPerPage: 'hydra:itemsPerPage',
38+
firstPage: {'@id': 'hydra:firstPage', '@type': '@id'},
39+
lastPage: {'@id': 'hydra:lastPage', '@type': '@id'},
40+
nextPage: {'@id': 'hydra:nextPage', '@type': '@id'},
41+
previousPage: {'@id': 'hydra:previousPage', '@type': '@id'},
42+
Link: 'hydra:Link',
43+
TemplatedLink: 'hydra:TemplatedLink',
44+
IriTemplate: 'hydra:IriTemplate',
45+
template: 'hydra:template',
46+
mapping: 'hydra:mapping',
47+
IriTemplateMapping: 'hydra:IriTemplateMapping',
48+
variable: 'hydra:variable',
49+
collection: 'hydra:collection',
50+
manages: 'hydra:manages',
51+
};

tests/test-objects/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import {Core} from '../../src/Constants';
44
import {owl, rdf, xsd} from '../../src/Vocabs';
5+
import Context from '../test-objects/Context';
56

67
export namespace Bodies {
78
export let someJsonLd = {
@@ -120,7 +121,7 @@ export namespace Bodies {
120121

121122
export let hydraCollection = {
122123
'@id': 'http://example.com/resource',
123-
'@context': Core.Context,
124+
'@context': Context,
124125
'hydra:member': [
125126
{'@id': 'http://example.com/element/1'},
126127
{'@id': 'http://example.com/element/2'},
@@ -135,7 +136,7 @@ export namespace Bodies {
135136

136137
export let hydraCollectionWithView = {
137138
'@id': 'http://example.com/resource',
138-
'@context': Core.Context,
139+
'@context': Context,
139140
'member': [
140141
{'@id': 'http://example.com/element/1'},
141142
{'@id': 'http://example.com/element/2'},
@@ -162,7 +163,7 @@ export namespace Documentations {
162163
export let classWithOperation = {
163164
'@id': 'http://api.example.com/doc/',
164165
'@type': Core.Vocab('ApiDocumentation'),
165-
'@context': Core.Context,
166+
'@context': Context,
166167
'entrypoint': 'http://example.com/home',
167168
'supportedClass': [
168169
{
@@ -215,7 +216,7 @@ export namespace Documentations {
215216
};
216217

217218
export let untyped = {
218-
'@context': Core.Context,
219+
'@context': Context,
219220
'@id': 'http://api.example.com/doc/',
220221
'entrypoint': 'http://example.com/home',
221222
};

0 commit comments

Comments
 (0)