-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
ActorQuerySourceIdentifyHypermedia.ts
101 lines (92 loc) 路 3.17 KB
/
ActorQuerySourceIdentifyHypermedia.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
import type { IAction, IActorArgs, IActorOutput, IActorTest, Mediate } from '@comunica/core';
import { Actor } from '@comunica/core';
import type { IQuerySource } from '@comunica/types';
import type * as RDF from '@rdfjs/types';
/**
* A comunica actor for query-source-identify-hypermedia events.
*
* Actor types:
* * Input: IActionQuerySourceIdentifyHypermedia: The metadata in the document and a query operation.
* * Test: <none>
* * Output: IActorQuerySourceIdentifyHypermediaOutput: A query source.
*
* @see IActionQuerySourceIdentifyHypermedia
* @see IActorQuerySourceIdentifyHypermediaOutput
*/
export abstract class ActorQuerySourceIdentifyHypermedia
extends Actor<
IActionQuerySourceIdentifyHypermedia,
IActorQuerySourceIdentifyHypermediaTest,
IActorQuerySourceIdentifyHypermediaOutput
> {
protected readonly sourceType: string;
/**
* @param args - @defaultNested {<default_bus> a <cc:components/Bus.jsonld#Bus>} bus
* @param sourceType The source type.
*/
public constructor(args: IActorQuerySourceIdentifyHypermediaArgs, sourceType: string) {
super(args);
this.sourceType = sourceType;
}
public async test(action: IActionQuerySourceIdentifyHypermedia): Promise<IActorQuerySourceIdentifyHypermediaTest> {
if (action.forceSourceType && this.sourceType !== action.forceSourceType) {
throw new Error(`Actor ${this.name} is not able to handle source type ${action.forceSourceType}.`);
}
return this.testMetadata(action);
}
public abstract testMetadata(
action: IActionQuerySourceIdentifyHypermedia,
): Promise<IActorQuerySourceIdentifyHypermediaTest>;
}
export interface IActionQuerySourceIdentifyHypermedia extends IAction {
/**
* The URL of the source that was fetched.
*/
url: string;
/**
* A metadata key-value mapping.
*/
metadata: Record<string, any>;
/**
* A stream of data quads.
*/
quads: RDF.Stream;
/**
* A hash of all datasets that have been handled.
*/
handledDatasets?: Record<string, boolean>;
/**
* The explicitly requested source type.
* If set, the source type of the actor MUST explicitly match the given forced type.
*/
forceSourceType?: string;
}
export interface IActorQuerySourceIdentifyHypermediaTest extends IActorTest {
/**
* A value from 0 to 1 indicating to what respect a source type is
* able to pre-filter the source based on the pattern.
* 1 indicates that the source can apply the whole pattern,
* and 0 indicates that the source can not apply the pattern at all (and local filtering must happen).
*/
filterFactor: number;
}
export interface IActorQuerySourceIdentifyHypermediaOutput extends IActorOutput {
/**
* The new source of quads contained in the document.
*/
source: IQuerySource;
/**
* The dataset that was handled.
*/
dataset?: string;
}
export type IActorQuerySourceIdentifyHypermediaArgs = IActorArgs<
IActionQuerySourceIdentifyHypermedia,
IActorQuerySourceIdentifyHypermediaTest,
IActorQuerySourceIdentifyHypermediaOutput
>;
export type MediatorQuerySourceIdentifyHypermedia = Mediate<
IActionQuerySourceIdentifyHypermedia,
IActorQuerySourceIdentifyHypermediaOutput,
IActorQuerySourceIdentifyHypermediaTest
>;