@rdfc/js-runner 3.0.0 → 3.0.2
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/.github/workflows/build-test.yml +24 -0
- package/.idea/LNKD.tech Editor.xml +194 -0
- package/.idea/codeStyles/Project.xml +52 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/copilot.data.migration.agent.xml +6 -0
- package/.idea/copilot.data.migration.ask.xml +6 -0
- package/.idea/copilot.data.migration.ask2agent.xml +6 -0
- package/.idea/copilot.data.migration.edit.xml +6 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/js-runner.iml +12 -0
- package/{examples/echo/.idea → .idea}/modules.xml +1 -1
- package/.idea/vcs.xml +6 -0
- package/__tests__/echoProcessor.test.ts +12 -11
- package/dist/args.d.ts +4 -0
- package/dist/args.js +58 -0
- package/dist/connectors/file.d.ts +15 -0
- package/dist/connectors/file.js +89 -0
- package/dist/connectors/http.d.ts +14 -0
- package/dist/connectors/http.js +82 -0
- package/dist/connectors/kafka.d.ts +48 -0
- package/dist/connectors/kafka.js +68 -0
- package/dist/connectors/ws.d.ts +10 -0
- package/dist/connectors/ws.js +72 -0
- package/dist/connectors.d.ts +73 -0
- package/dist/connectors.js +168 -0
- package/dist/index.cjs +732 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +83 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/util.d.ts +71 -0
- package/dist/util.js +92 -0
- package/lib/reader.js +1 -1
- package/lib/runner.d.ts +2 -1
- package/lib/runner.js +8 -4
- package/lib/testUtils/duplex.d.ts +2 -2
- package/lib/testUtils/duplex.js +1 -1
- package/lib/testUtils/index.d.ts +9 -9
- package/lib/testUtils/index.js +10 -11
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -25
- package/src/reader.ts +8 -8
- package/src/runner.ts +13 -5
- package/src/testUtils/duplex.ts +2 -2
- package/src/testUtils/index.ts +21 -27
- package/examples/echo/.idea/echo.iml +0 -9
- package/examples/echo/.idea/misc.xml +0 -6
- package/examples/echo/.idea/vcs.xml +0 -7
- package/examples/echo/.swls/config.json +0 -1
- package/examples/echo/index.ttl +0 -3
- package/examples/echo/minimal.ttl +0 -90
- package/examples/echo/shacl.ttl +0 -9
- package/examples/echo/shape.ttl +0 -1339
- package/examples/echo/test.ttl +0 -11
- 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 +0 -3
- package/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +0 -3
- package/lib/jsonld.d.ts +0 -17
- package/lib/jsonld.js +0 -135
- package/lib/testUtils.d.ts +0 -24
- package/lib/testUtils.js +0 -150
- package/minimal.ttl +0 -99
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rdfc/js-runner",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -29,38 +29,38 @@
|
|
|
29
29
|
"license": "ISC",
|
|
30
30
|
"description": "",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@eslint/js": "^9.
|
|
32
|
+
"@eslint/js": "^9.39.2",
|
|
33
33
|
"@rdfjs/types": "^2.0.1",
|
|
34
|
-
"@
|
|
35
|
-
"@types/jest": "^29.5.14",
|
|
34
|
+
"@types/jest": "^30.0.0",
|
|
36
35
|
"@types/jsonld": "^1.5.15",
|
|
37
|
-
"@types/n3": "^1.
|
|
38
|
-
"@types/node": "^
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
40
|
-
"@typescript-eslint/parser": "^8.
|
|
41
|
-
"@vitest/coverage-v8": "^
|
|
36
|
+
"@types/n3": "^1.26.1",
|
|
37
|
+
"@types/node": "^24.10.9",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
39
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
40
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
42
41
|
"eslint": "^9.21.0",
|
|
43
|
-
"eslint-config-prettier": "^10.
|
|
44
|
-
"eslint-plugin-prettier": "^5.
|
|
45
|
-
"globals": "^
|
|
42
|
+
"eslint-config-prettier": "^10.1.8",
|
|
43
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
44
|
+
"globals": "^17.3.0",
|
|
46
45
|
"husky": "^9.1.7",
|
|
47
|
-
"jest": "^
|
|
48
|
-
"lint-staged": "^
|
|
49
|
-
"prettier": "^3.
|
|
50
|
-
"ts-jest": "^29.
|
|
51
|
-
"tsc-alias": "^1.8.
|
|
52
|
-
"typescript": "^5.
|
|
53
|
-
"typescript-eslint": "^8.
|
|
54
|
-
"vitest": "^
|
|
46
|
+
"jest": "^30.2.0",
|
|
47
|
+
"lint-staged": "^16.2.7",
|
|
48
|
+
"prettier": "^3.8.1",
|
|
49
|
+
"ts-jest": "^29.4.6",
|
|
50
|
+
"tsc-alias": "^1.8.16",
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"typescript-eslint": "^8.54.0",
|
|
53
|
+
"vitest": "^4.0.18"
|
|
55
54
|
},
|
|
56
55
|
"dependencies": {
|
|
56
|
+
"@grpc/grpc-js": "^1.14.3",
|
|
57
57
|
"@rdfc/proto": "^0.1.2",
|
|
58
58
|
"@treecg/types": "^0.4.6",
|
|
59
|
-
"jsonld": "^
|
|
60
|
-
"jsonld-streaming-parser": "^5.0.
|
|
61
|
-
"n3": "^
|
|
62
|
-
"rdf-lens": "^1.3.
|
|
63
|
-
"winston": "^3.
|
|
59
|
+
"jsonld": "^9.0.0",
|
|
60
|
+
"jsonld-streaming-parser": "^5.0.1",
|
|
61
|
+
"n3": "^2.0.1",
|
|
62
|
+
"rdf-lens": "^1.3.6",
|
|
63
|
+
"winston": "^3.19.0",
|
|
64
64
|
"winston-transport": "^4.9.0"
|
|
65
65
|
}
|
|
66
66
|
}
|
package/src/reader.ts
CHANGED
|
@@ -18,14 +18,14 @@ import { promisify } from 'util'
|
|
|
18
18
|
|
|
19
19
|
export type Any =
|
|
20
20
|
| {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
string: string
|
|
22
|
+
}
|
|
23
23
|
| {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
stream: AsyncGenerator<Uint8Array>
|
|
25
|
+
}
|
|
26
26
|
| {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
buffer: Uint8Array
|
|
28
|
+
}
|
|
29
29
|
|
|
30
30
|
export interface Reader {
|
|
31
31
|
readonly uri: string
|
|
@@ -68,7 +68,7 @@ class MyIter<T> implements AsyncIterable<T> {
|
|
|
68
68
|
|
|
69
69
|
async pushStream(chunks: AsyncIterable<DataChunk>, onComplete: () => void) {
|
|
70
70
|
// This is an async generator that transforms DataChunks to Buffers
|
|
71
|
-
const stream = (async function*
|
|
71
|
+
const stream = (async function*(stream) {
|
|
72
72
|
for await (const chunk of stream) {
|
|
73
73
|
yield chunk.data
|
|
74
74
|
}
|
|
@@ -165,7 +165,7 @@ export class ReaderInstance implements Reader {
|
|
|
165
165
|
|
|
166
166
|
close() {
|
|
167
167
|
for (const iter of this.consumers) {
|
|
168
|
-
iter.close(() => {})
|
|
168
|
+
iter.close(() => { })
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
|
package/src/runner.ts
CHANGED
|
@@ -47,8 +47,7 @@ type ProcessorConfig = {
|
|
|
47
47
|
clazz?: string
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export type FullProc<C extends Proc<
|
|
51
|
-
C extends Proc<infer T> ? T & C : unknown
|
|
50
|
+
export type FullProc<C> = C extends Proc<infer T> ? T & C : never
|
|
52
51
|
export class Runner {
|
|
53
52
|
private readonly readers: { [uri: string]: ReaderInstance } = {}
|
|
54
53
|
private readonly writers: { [uri: string]: WriterInstance } = {}
|
|
@@ -75,7 +74,7 @@ export class Runner {
|
|
|
75
74
|
this.logger = logger
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
async
|
|
77
|
+
async createProcessor<P extends Proc<unknown>>(
|
|
79
78
|
proc: Processor,
|
|
80
79
|
): Promise<FullProc<P>> {
|
|
81
80
|
const procLogger = createLogger({
|
|
@@ -94,7 +93,7 @@ export class Runner {
|
|
|
94
93
|
)
|
|
95
94
|
.map((x) => x.object.value)
|
|
96
95
|
|
|
97
|
-
this.logger.info(
|
|
96
|
+
this.logger.info(`Parsing processor '${proc.uri}' of type(s) [${ty.join(', ')}]`)
|
|
98
97
|
const args = this.shapes.lenses[RDFL.TypedExtract].execute({
|
|
99
98
|
id: new NamedNode(proc.uri),
|
|
100
99
|
quads: this.quads,
|
|
@@ -104,9 +103,18 @@ export class Runner {
|
|
|
104
103
|
const jsProgram = await import(config.file)
|
|
105
104
|
const clazz = jsProgram[config.clazz || 'default']
|
|
106
105
|
const instance: Proc<unknown> = new clazz(args, procLogger)
|
|
106
|
+
|
|
107
|
+
return <FullProc<P>>instance
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async addProcessor<P extends Proc<unknown>>(
|
|
111
|
+
proc: Processor,
|
|
112
|
+
): Promise<FullProc<P>> {
|
|
113
|
+
const instance = await this.createProcessor<P>(proc)
|
|
114
|
+
|
|
107
115
|
await instance.init()
|
|
108
116
|
|
|
109
|
-
this.logger.info(
|
|
117
|
+
this.logger.info(`Initiated processor '${proc.uri}'`)
|
|
110
118
|
|
|
111
119
|
this.processors.push(instance)
|
|
112
120
|
this.processorTransforms.push(instance.transform())
|
package/src/testUtils/duplex.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Duplex } from 'stream'
|
|
2
2
|
import type {
|
|
3
3
|
ClientDuplexStream,
|
|
4
|
-
|
|
4
|
+
InterceptingCall,
|
|
5
5
|
} from '@grpc/grpc-js'
|
|
6
6
|
import { AuthContext } from '@grpc/grpc-js/build/src/auth-context'
|
|
7
7
|
|
|
@@ -23,7 +23,7 @@ export class MockClientDuplexStream<Req, Res>
|
|
|
23
23
|
|
|
24
24
|
public readonly id: number
|
|
25
25
|
|
|
26
|
-
call?:
|
|
26
|
+
call?: InterceptingCall | undefined
|
|
27
27
|
constructor() {
|
|
28
28
|
super({ objectMode: true })
|
|
29
29
|
this.id = count++
|
package/src/testUtils/index.ts
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from
|
|
8
|
-
import {} from
|
|
9
|
-
import {
|
|
10
|
-
import { NamedNode, Parser, Writer as N3Writer } from 'n3'
|
|
11
|
-
import { readFile } from 'fs/promises'
|
|
12
|
-
import winston, { createLogger } from 'winston'
|
|
13
|
-
import { Processor } from '../processor'
|
|
14
|
-
import { FullProc, Runner, Writable } from '../runner'
|
|
15
|
-
import { Quad } from '@rdfjs/types'
|
|
16
|
-
import { createTermNamespace } from '@treecg/types'
|
|
1
|
+
import { DataChunk, FromRunner, LogMessage, Processor as ProcConfig, ToRunner } from "@rdfc/proto";
|
|
2
|
+
import { extractShapes } from "rdf-lens";
|
|
3
|
+
import { NamedNode, Parser, Writer as N3Writer } from "n3";
|
|
4
|
+
import { readFile } from "fs/promises";
|
|
5
|
+
import winston, { createLogger } from "winston";
|
|
6
|
+
import { Processor } from "../processor";
|
|
7
|
+
import { FullProc, Runner, Writable } from "../runner";
|
|
8
|
+
import { Quad } from "@rdfjs/types";
|
|
9
|
+
import { createTermNamespace } from "@treecg/types";
|
|
17
10
|
import {
|
|
18
11
|
ReceivingStreamControl,
|
|
19
12
|
SendingStreamControl,
|
|
20
13
|
StreamChunk,
|
|
21
14
|
StreamIdentify,
|
|
22
|
-
} from
|
|
23
|
-
import { MockClientDuplexStream } from
|
|
24
|
-
import { promisify } from
|
|
25
|
-
import { Reader } from
|
|
26
|
-
import { Writer } from
|
|
15
|
+
} from "@rdfc/proto/lib/generated/common";
|
|
16
|
+
import { MockClientDuplexStream } from "./duplex";
|
|
17
|
+
import { promisify } from "util";
|
|
18
|
+
import { Reader } from "../reader";
|
|
19
|
+
import { Writer } from "../writer";
|
|
27
20
|
|
|
28
21
|
export function channel(runner: Runner, name: string): [Writer, Reader] {
|
|
29
22
|
const n = new NamedNode(name)
|
|
@@ -359,12 +352,13 @@ export class ProcHelper<T extends Processor<unknown>> {
|
|
|
359
352
|
pipeline: new N3Writer().quadsToString(this.quads),
|
|
360
353
|
})
|
|
361
354
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
355
|
+
return await this.runner.createProcessor<T>(
|
|
356
|
+
{
|
|
357
|
+
config: JSON.stringify(this.config),
|
|
358
|
+
arguments: '',
|
|
359
|
+
uri,
|
|
360
|
+
},
|
|
361
|
+
)
|
|
368
362
|
}
|
|
369
363
|
}
|
|
370
364
|
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="JAVA_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
-
<exclude-output />
|
|
5
|
-
<content url="file://$MODULE_DIR$" />
|
|
6
|
-
<orderEntry type="inheritedJdk" />
|
|
7
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
-
</component>
|
|
9
|
-
</module>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "disabled": ["shapes"] }
|
package/examples/echo/index.ttl
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
@prefix rdfc: <https://w3id.org/rdf-connect#>.
|
|
2
|
-
@prefix prov: <http://www.w3.org/ns/prov#>.
|
|
3
|
-
@prefix sds: <https://w3id.org/sds#>.
|
|
4
|
-
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
|
|
5
|
-
@prefix owl: <http://www.w3.org/2002/07/owl#>.
|
|
6
|
-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
|
7
|
-
@prefix sh: <http://www.w3.org/ns/shacl#>.
|
|
8
|
-
|
|
9
|
-
############################################################
|
|
10
|
-
# General statements #
|
|
11
|
-
############################################################
|
|
12
|
-
# sds:Activity is a prov:Activity
|
|
13
|
-
sds:Activity rdfs:subClassOf prov:Activity.
|
|
14
|
-
|
|
15
|
-
# rdfc:Processor too
|
|
16
|
-
rdfc:Processor rdfs:subClassOf sds:Activity.
|
|
17
|
-
|
|
18
|
-
# sds:implementationOf is subClassOf
|
|
19
|
-
sds:implementationOf rdfs:subPropertyOf rdfs:subClassOf.
|
|
20
|
-
|
|
21
|
-
############################################################
|
|
22
|
-
# Javascript statements #
|
|
23
|
-
############################################################
|
|
24
|
-
# specialized for js too
|
|
25
|
-
rdfc:jsImplementationOf rdfs:subPropertyOf sds:implementationOf.
|
|
26
|
-
|
|
27
|
-
# A node runner, runs things that are rdfc:jsImplementationOf rdfc:Processor (aka, rdfs:subClassOf prov:Activity)
|
|
28
|
-
rdfc:NodeRunner a rdfc:Runner;
|
|
29
|
-
rdfc:handlesSubjectsOf rdfc:jsImplementationOf;
|
|
30
|
-
rdfc:command "npx js-runner".
|
|
31
|
-
|
|
32
|
-
# Shape that a Js Processor should fulfil;
|
|
33
|
-
[ ] a sh:NodeShape;
|
|
34
|
-
# We target it with jsImplementationOf
|
|
35
|
-
sh:targetSubjectsOf rdfc:jsImplementationOf;
|
|
36
|
-
sh:property [
|
|
37
|
-
sh:path rdfc:entrypoint;
|
|
38
|
-
sh:name "location";
|
|
39
|
-
sh:minCount 1;
|
|
40
|
-
sh:maxCount 1;
|
|
41
|
-
sh:datatype xsd:string;
|
|
42
|
-
], [
|
|
43
|
-
sh:path rdfc:file;
|
|
44
|
-
sh:name "file";
|
|
45
|
-
sh:minCount 1;
|
|
46
|
-
sh:maxCount 1;
|
|
47
|
-
sh:datatype xsd:string;
|
|
48
|
-
], [
|
|
49
|
-
sh:path rdfc:class;
|
|
50
|
-
sh:name "clazz";
|
|
51
|
-
sh:maxCount 1;
|
|
52
|
-
sh:datatype xsd:string;
|
|
53
|
-
].
|
|
54
|
-
|
|
55
|
-
############################################################
|
|
56
|
-
# Processor statements #
|
|
57
|
-
############################################################
|
|
58
|
-
rdfc:FooBarProcessor a owl:Class, rdfs:Class;
|
|
59
|
-
rdfc:jsImplementationOf rdfc:Processor;
|
|
60
|
-
rdfs:label "My Epic FooBar Processor";
|
|
61
|
-
rdfs:description "FooBars everything!";
|
|
62
|
-
rdfc:entrypoint <./>;
|
|
63
|
-
rdfc:file <./lib/processors.js>;
|
|
64
|
-
rdfc:class "FooBarProcessor".
|
|
65
|
-
|
|
66
|
-
[ ] a sh:NodeShape;
|
|
67
|
-
sh:targetClass rdfc:FooBarProcessor;
|
|
68
|
-
sh:property [
|
|
69
|
-
sh:path rdfc:reader;
|
|
70
|
-
sh:name "reader";
|
|
71
|
-
sh:minCount 1;
|
|
72
|
-
sh:maxCount 1;
|
|
73
|
-
sh:class rdfc:Reader;
|
|
74
|
-
].
|
|
75
|
-
|
|
76
|
-
############################################################
|
|
77
|
-
# Pipeline statements #
|
|
78
|
-
############################################################
|
|
79
|
-
<> a rdfc:Pipeline;
|
|
80
|
-
rdfc:consistsOf [
|
|
81
|
-
rdfc:instantiates rdfc:NodeRunner;
|
|
82
|
-
rdfc:processor <foobar>;
|
|
83
|
-
].
|
|
84
|
-
|
|
85
|
-
# <incomingMessages> a rdfc:Reader.
|
|
86
|
-
<incomingMessages> a rdfc:Reader.
|
|
87
|
-
|
|
88
|
-
<fooBar> a rdfc:FooBarProcessor;
|
|
89
|
-
rdfc:reader <incomingMessages>.
|
|
90
|
-
|