@rdfc/js-runner 2.0.0-alpha.5 → 2.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/examples/echo/.idea/echo.iml +9 -0
- package/examples/echo/.idea/misc.xml +6 -0
- package/examples/echo/.idea/modules.xml +8 -0
- package/examples/echo/.idea/vcs.xml +7 -0
- package/examples/echo/.swls/config.json +1 -0
- package/examples/echo/index.ttl +3 -0
- package/examples/echo/minimal.ttl +90 -0
- package/examples/echo/pipeline.ttl +22 -4
- package/examples/echo/processors.ttl +5 -7
- package/examples/echo/shacl.ttl +9 -0
- package/examples/echo/shape.ttl +1339 -0
- package/examples/echo/src/processors.ts +31 -30
- package/examples/echo/test.ttl +9 -12
- package/file:/home/silvius/Projects/mumo-pipeline/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +3 -0
- package/index.ttl +28 -20
- package/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +3 -0
- package/lib/jsonld.js +2 -2
- package/lib/reader.d.ts +2 -1
- package/lib/reader.js +1 -3
- package/lib/runner.d.ts +2 -2
- package/lib/runner.js +3 -5
- package/lib/testUtils.js +4 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/util_processors.js +1 -1
- package/lib/writer.d.ts +2 -1
- package/lib/writer.js +1 -1
- package/minimal.ttl +99 -0
- package/package.json +1 -1
- package/src/jsonld.ts +1 -1
- package/src/reader.ts +130 -131
- package/src/runner.ts +144 -143
- package/src/testUtils.ts +3 -0
- package/src/util_processors.ts +1 -1
- package/src/writer.ts +66 -65
package/src/writer.ts
CHANGED
|
@@ -5,85 +5,86 @@ import { Any } from './reader'
|
|
|
5
5
|
|
|
6
6
|
type Writable = (msg: OrchestratorMessage) => Promise<unknown>
|
|
7
7
|
export interface Writer {
|
|
8
|
-
|
|
8
|
+
readonly uri: string;
|
|
9
|
+
buffer(buffer: Uint8Array): Promise<void>
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
stream(buffer: AsyncIterable<Uint8Array>): Promise<void>
|
|
12
|
+
stream<T>(
|
|
13
|
+
buffer: AsyncIterable<T>,
|
|
14
|
+
tranform: (x: T) => Uint8Array,
|
|
15
|
+
): Promise<void>
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
string(buffer: string): Promise<void>
|
|
18
|
+
any(any: Any): Promise<void>
|
|
19
|
+
close(): Promise<void>
|
|
19
20
|
}
|
|
20
21
|
const encoder = new TextEncoder()
|
|
21
22
|
export class WriterInstance implements Writer {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
readonly uri: string
|
|
24
|
+
private readonly client: RunnerClient
|
|
25
|
+
private readonly write: Writable
|
|
26
|
+
private readonly logger: Logger
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
async any(any: Any): Promise<void> {
|
|
39
|
-
if ('stream' in any) {
|
|
40
|
-
await this.stream(any.stream)
|
|
28
|
+
constructor(
|
|
29
|
+
uri: string,
|
|
30
|
+
client: RunnerClient,
|
|
31
|
+
write: Writable,
|
|
32
|
+
logger: Logger,
|
|
33
|
+
) {
|
|
34
|
+
this.client = client
|
|
35
|
+
this.write = write
|
|
36
|
+
this.uri = uri
|
|
37
|
+
this.logger = logger
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
async any(any: Any): Promise<void> {
|
|
40
|
+
if ('stream' in any) {
|
|
41
|
+
await this.stream(any.stream)
|
|
42
|
+
}
|
|
43
|
+
if ('buffer' in any) {
|
|
44
|
+
await this.buffer(any.buffer)
|
|
45
|
+
}
|
|
46
|
+
if ('string' in any) {
|
|
47
|
+
await this.string(any.string)
|
|
48
|
+
}
|
|
44
49
|
}
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
|
|
51
|
+
async buffer(buffer: Uint8Array): Promise<void> {
|
|
52
|
+
this.logger.debug(`${this.uri} sends buffer ${buffer.length} bytes`)
|
|
53
|
+
await this.write({ msg: { data: buffer, channel: this.uri } })
|
|
47
54
|
}
|
|
48
|
-
}
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
async stream<T = Uint8Array>(
|
|
57
|
+
buffer: AsyncIterable<T>,
|
|
58
|
+
transform?: (x: T) => Uint8Array,
|
|
59
|
+
) {
|
|
60
|
+
const t = transform || ((x: unknown) => <Uint8Array>x)
|
|
61
|
+
const stream = this.client.sendStreamMessage()
|
|
62
|
+
const id: Id = await new Promise((res) => stream.once('data', res))
|
|
63
|
+
this.logger.debug(`${this.uri} streams message with id ${id.id}`)
|
|
64
|
+
await this.write({ streamMsg: { id, channel: this.uri } })
|
|
54
65
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const t = transform || ((x: unknown) => <Uint8Array>x)
|
|
60
|
-
const stream = this.client.sendStreamMessage()
|
|
61
|
-
const id: Id = await new Promise((res) => stream.once('data', res))
|
|
62
|
-
this.logger.debug(`${this.uri} streams message with id ${id.id}`)
|
|
63
|
-
await this.write({ streamMsg: { id, channel: this.uri } })
|
|
66
|
+
const write = promisify(stream.write.bind(stream))
|
|
67
|
+
for await (const msg of buffer) {
|
|
68
|
+
await write({ data: t(msg) })
|
|
69
|
+
}
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
await write({ data: t(msg) })
|
|
71
|
+
this.logger.debug(`${this.uri} is done streaming message with id ${id.id}`)
|
|
72
|
+
stream.end()
|
|
68
73
|
}
|
|
69
74
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
await this.write({
|
|
77
|
-
msg: { data: encoder.encode(msg), channel: this.uri },
|
|
78
|
-
})
|
|
79
|
-
}
|
|
75
|
+
async string(msg: string): Promise<void> {
|
|
76
|
+
this.logger.debug(`${this.uri} sends string ${msg.length} characters`)
|
|
77
|
+
await this.write({
|
|
78
|
+
msg: { data: encoder.encode(msg), channel: this.uri },
|
|
79
|
+
})
|
|
80
|
+
}
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
async close(issued = false): Promise<void> {
|
|
83
|
+
this.logger.debug(`${this.uri} closes stream`)
|
|
84
|
+
if (!issued) {
|
|
85
|
+
await this.write({
|
|
86
|
+
close: { channel: this.uri },
|
|
87
|
+
})
|
|
88
|
+
}
|
|
87
89
|
}
|
|
88
|
-
}
|
|
89
90
|
}
|