-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinks.ts
More file actions
70 lines (67 loc) · 2.05 KB
/
links.ts
File metadata and controls
70 lines (67 loc) · 2.05 KB
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
import { contenttypes, type Link, Links as Links_ } from "./utils/index.ts";
import type { ExegesisContext } from "exegesis-express";
export class Links extends Links_ {
constructor(ctx: ExegesisContext) {
super(ctx);
}
public instances(collectionId: string): this {
const channel = `/collections/${collectionId}/instances`;
let url = new URL(this.server + channel);
this.links.push({
title: "Discover instances within this dataset",
href: url.toString(),
rel: "data",
type: contenttypes.JSON,
});
return this;
}
ws(channel: string,type=contenttypes.JSON): this {
this.links.push({
title: "Subscribe to realtime updates for this resource",
href: this.server,
rel: "hub",
channel,
type
});
return this;
}
instance(collectionId: string, instanceId: string): this {
let title = "View metadata about instance";
const channel = `/collections/${collectionId}/instances/${instanceId}`;
let url = new URL(this.server + channel);
this.links.push({
title,
href: url.toJSON(),
rel: "collection",
type: contenttypes.JSON,
});
return this;
}
queryType(
query_type: string,
default_output_format: keyof typeof contenttypes
): Link {
const { collectionId, instanceId } = this.ctx.params.path;
let str = `/collections/${collectionId}`;
if (instanceId) str += `/instances/${instanceId}`;
str += `/${query_type}`;
return {
title: `Query this dataset using ${query_type}`,
href: new URL(this.server + str).toString(),
type: contenttypes[default_output_format],
rel:
query_type === "items" || query_type === "locations" ? "items" : "data",
templated: false,
};
}
location(
collectionId: string,
locationId: string,
options: { instanceId?: string }
) {
let str = `/collections/${collectionId}`;
if (options.instanceId) str += `/instances/${options.instanceId}`;
str += `/locations/${locationId}`;
return new URL(`${this.server}${str}`).toJSON();
}
}