@rdfc/js-runner 2.0.0 → 3.0.0
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/.editorconfig +9 -0
- package/.github/renovate.json +3 -0
- package/README.md +127 -3
- package/__tests__/channels.test.ts +131 -74
- package/__tests__/echoProcessor.test.ts +131 -0
- package/__tests__/testProcessor.test.ts +69 -0
- package/eslint.config.mjs +1 -1
- package/examples/echo/.idea/echo.iml +9 -0
- package/examples/echo/.idea/misc.xml +6 -0
- package/{.idea → examples/echo/.idea}/modules.xml +1 -1
- 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/shacl.ttl +9 -0
- package/examples/echo/shape.ttl +1339 -0
- package/examples/echo/test.ttl +11 -0
- package/examples/echo/untitled:/types/MyType.ttl +0 -0
- 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 +3 -31
- package/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +3 -0
- package/lib/client.js +6 -9
- package/lib/logger.d.ts +2 -2
- package/lib/logger.js +3 -3
- package/lib/reader.d.ts +8 -6
- package/lib/reader.js +135 -25
- package/lib/runner.d.ts +10 -5
- package/lib/runner.js +86 -46
- package/lib/testUtils/duplex.d.ts +25 -0
- package/lib/testUtils/duplex.js +70 -0
- package/lib/testUtils/index.d.ts +51 -0
- package/lib/testUtils/index.js +243 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/writer.d.ts +12 -5
- package/lib/writer.js +66 -13
- package/minimal.ttl +99 -0
- package/package.json +3 -3
- package/src/client.ts +8 -11
- package/src/logger.ts +3 -3
- package/src/reader.ts +207 -29
- package/src/runner.ts +128 -65
- package/src/testUtils/duplex.ts +112 -0
- package/src/testUtils/index.ts +430 -0
- package/src/writer.ts +106 -16
- package/.idea/LNKD.tech Editor.xml +0 -194
- package/.idea/codeStyles/Project.xml +0 -52
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/js-runner.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/dist/args.d.ts +0 -4
- package/dist/args.js +0 -58
- package/dist/connectors/file.d.ts +0 -15
- package/dist/connectors/file.js +0 -89
- package/dist/connectors/http.d.ts +0 -14
- package/dist/connectors/http.js +0 -82
- package/dist/connectors/kafka.d.ts +0 -48
- package/dist/connectors/kafka.js +0 -68
- package/dist/connectors/ws.d.ts +0 -10
- package/dist/connectors/ws.js +0 -72
- package/dist/connectors.d.ts +0 -73
- package/dist/connectors.js +0 -168
- package/dist/index.cjs +0 -732
- package/dist/index.d.ts +0 -42
- package/dist/index.js +0 -83
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/util.d.ts +0 -71
- package/dist/util.js +0 -92
- package/src/jsonld.ts +0 -220
- package/src/testUtils.ts +0 -196
package/src/testUtils.ts
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { DataChunk, RunnerClient } from '@rdfc/proto'
|
|
2
|
-
import * as grpc from '@grpc/grpc-js'
|
|
3
|
-
import { ClientReadableStream } from '@grpc/grpc-js'
|
|
4
|
-
import { ClientReadableStreamImpl, OrchestratorMessage } from './reexports'
|
|
5
|
-
import { extractShapes } from 'rdf-lens'
|
|
6
|
-
import { NamedNode, Parser, Writer } from 'n3'
|
|
7
|
-
import { readFile } from 'fs/promises'
|
|
8
|
-
import winston, { createLogger } from 'winston'
|
|
9
|
-
import { WriterInstance } from './writer'
|
|
10
|
-
import { ReaderInstance } from './reader'
|
|
11
|
-
import { Processor } from './processor'
|
|
12
|
-
import { FullProc, Runner } from './runner'
|
|
13
|
-
import { Quad, Term } from '@rdfjs/types'
|
|
14
|
-
import { createTermNamespace } from '@treecg/types'
|
|
15
|
-
import { expect } from 'vitest'
|
|
16
|
-
|
|
17
|
-
export async function getProcessorShape(
|
|
18
|
-
baseIRI = process.cwd() + '/node_modules/@rdfc/js-runner/index.ttl',
|
|
19
|
-
) {
|
|
20
|
-
const configFile = await readFile(baseIRI, { encoding: 'utf8' })
|
|
21
|
-
const configQuads = new Parser().parse(configFile)
|
|
22
|
-
const shapes = extractShapes(configQuads)
|
|
23
|
-
|
|
24
|
-
return shapes
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class TestClient extends RunnerClient {
|
|
28
|
-
next: (stream: ClientReadableStream<DataChunk>) => unknown
|
|
29
|
-
|
|
30
|
-
constructor() {
|
|
31
|
-
super('localhost:5400', grpc.credentials.createInsecure())
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
nextStream(): Promise<ClientReadableStream<DataChunk>> {
|
|
35
|
-
return new Promise((res) => (this.next = res))
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
receiveStreamMessage(): ClientReadableStream<DataChunk> {
|
|
39
|
-
const stream = new ClientReadableStreamImpl<DataChunk>((data: Buffer) => {
|
|
40
|
-
return { data }
|
|
41
|
-
})
|
|
42
|
-
this.next(stream)
|
|
43
|
-
return stream
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export async function one<T>(iter: AsyncIterable<T>): Promise<T | undefined> {
|
|
48
|
-
for await (const item of iter) {
|
|
49
|
-
return item
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const client = new TestClient()
|
|
54
|
-
export const uri = 'someUri'
|
|
55
|
-
export const logger = createLogger({
|
|
56
|
-
transports: new winston.transports.Console({
|
|
57
|
-
level: process.env['DEBUG'] || 'info',
|
|
58
|
-
}),
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
export function createWriter(iri = uri): [WriterInstance, ReaderInstance] {
|
|
62
|
-
const reader = createReader(iri)
|
|
63
|
-
const writeStream = new WriterInstance(
|
|
64
|
-
iri,
|
|
65
|
-
client,
|
|
66
|
-
async (msg) => {
|
|
67
|
-
if (msg.msg) {
|
|
68
|
-
reader.handleMsg(msg.msg)
|
|
69
|
-
}
|
|
70
|
-
if (msg.close) {
|
|
71
|
-
reader.close()
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
logger,
|
|
75
|
-
)
|
|
76
|
-
return [writeStream, reader]
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function createReader(iri = uri): ReaderInstance {
|
|
80
|
-
const reader = new ReaderInstance(iri, client, logger)
|
|
81
|
-
return reader
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const shapeQuads = `
|
|
85
|
-
@prefix rdfc: <https://w3id.org/rdf-connect#>.
|
|
86
|
-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
|
87
|
-
@prefix sh: <http://www.w3.org/ns/shacl#>.
|
|
88
|
-
[ ] a sh:NodeShape;
|
|
89
|
-
sh:targetClass <JsProcessorShape>;
|
|
90
|
-
sh:property [
|
|
91
|
-
sh:path rdfc:entrypoint;
|
|
92
|
-
sh:name "location";
|
|
93
|
-
sh:minCount 1;
|
|
94
|
-
sh:maxCount 1;
|
|
95
|
-
sh:datatype xsd:string;
|
|
96
|
-
], [
|
|
97
|
-
sh:path rdfc:file;
|
|
98
|
-
sh:name "file";
|
|
99
|
-
sh:minCount 1;
|
|
100
|
-
sh:maxCount 1;
|
|
101
|
-
sh:datatype xsd:string;
|
|
102
|
-
], [
|
|
103
|
-
sh:path rdfc:class;
|
|
104
|
-
sh:name "clazz";
|
|
105
|
-
sh:maxCount 1;
|
|
106
|
-
sh:datatype xsd:string;
|
|
107
|
-
].
|
|
108
|
-
`
|
|
109
|
-
const OWL = createTermNamespace('http://www.w3.org/2002/07/owl#', 'imports')
|
|
110
|
-
const processorShapes = extractShapes(new Parser().parse(shapeQuads))
|
|
111
|
-
const base = 'https://w3id.org/rdf-connect#'
|
|
112
|
-
|
|
113
|
-
export async function importFile(file: string): Promise<Quad[]> {
|
|
114
|
-
const done = new Set<string>()
|
|
115
|
-
const todo = [new URL('file://' + file)]
|
|
116
|
-
const quads: Quad[] = []
|
|
117
|
-
|
|
118
|
-
let item = todo.pop()
|
|
119
|
-
while (item !== undefined) {
|
|
120
|
-
if (done.has(item.toString())) {
|
|
121
|
-
item = todo.pop()
|
|
122
|
-
continue
|
|
123
|
-
}
|
|
124
|
-
done.add(item.toString())
|
|
125
|
-
if (item.protocol !== 'file:') {
|
|
126
|
-
throw 'No supported protocol ' + item.protocol
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const txt = await readFile(item.pathname, { encoding: 'utf8' })
|
|
130
|
-
const extras = new Parser({ baseIRI: item.toString() }).parse(txt)
|
|
131
|
-
|
|
132
|
-
for (const o of extras
|
|
133
|
-
.filter(
|
|
134
|
-
(x) =>
|
|
135
|
-
x.subject.value === item?.toString() &&
|
|
136
|
-
x.predicate.equals(OWL.imports),
|
|
137
|
-
)
|
|
138
|
-
.map((x) => x.object.value)) {
|
|
139
|
-
todo.push(new URL(o))
|
|
140
|
-
}
|
|
141
|
-
quads.push(...extras)
|
|
142
|
-
|
|
143
|
-
item = todo.pop()
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return quads
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export async function getProc<T extends Processor<unknown>>(
|
|
150
|
-
config: string,
|
|
151
|
-
ty: string,
|
|
152
|
-
configLocation: string,
|
|
153
|
-
uri = 'http://example.com/ns#processor',
|
|
154
|
-
): Promise<FullProc<T>> {
|
|
155
|
-
const configQuads = await importFile(configLocation)
|
|
156
|
-
const procConfig = processorShapes.lenses['JsProcessorShape'].execute({
|
|
157
|
-
id: new NamedNode(base + ty),
|
|
158
|
-
quads: configQuads,
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
const msgs: OrchestratorMessage[] = []
|
|
162
|
-
const write = async (x: OrchestratorMessage) => {
|
|
163
|
-
msgs.push(x)
|
|
164
|
-
}
|
|
165
|
-
const runner = new Runner(
|
|
166
|
-
new TestClient(),
|
|
167
|
-
write,
|
|
168
|
-
'http://example.com/ns#',
|
|
169
|
-
logger,
|
|
170
|
-
)
|
|
171
|
-
configQuads.push(...new Parser().parse(config))
|
|
172
|
-
await runner.handleOrchMessage({
|
|
173
|
-
pipeline: new Writer().quadsToString(configQuads),
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
const proc = await runner.addProcessor<T>({
|
|
177
|
-
config: JSON.stringify(procConfig),
|
|
178
|
-
arguments: '',
|
|
179
|
-
uri,
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
return proc
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export async function checkProcDefinition(file: string, n: string) {
|
|
186
|
-
const quads = await importFile(file)
|
|
187
|
-
const procConfig = <{ file: Term; location: string; clazz: string }>(
|
|
188
|
-
processorShapes.lenses['JsProcessorShape'].execute({
|
|
189
|
-
id: new NamedNode(base + n),
|
|
190
|
-
quads: quads,
|
|
191
|
-
})
|
|
192
|
-
)
|
|
193
|
-
expect(procConfig.file, n + ' has file').toBeDefined()
|
|
194
|
-
expect(procConfig.location, n + ' has location').toBeDefined()
|
|
195
|
-
expect(procConfig.clazz, n + ' has clazz').toBeDefined()
|
|
196
|
-
}
|