@rdfc/js-runner 0.2.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/LICENSE +21 -0
- package/README.md +42 -0
- package/channels/file.ttl +37 -0
- package/channels/http.ttl +59 -0
- package/channels/kafka.ttl +98 -0
- package/channels/ws.ttl +33 -0
- package/ontology.ttl +169 -0
- package/package.json +68 -0
- package/processor/echo.ttl +38 -0
- package/processor/resc.ttl +34 -0
- package/processor/send.ttl +40 -0
- package/processor/test.js +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Jens Pots
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Js-runner
|
|
2
|
+
|
|
3
|
+
[](https://github.com/ajuvercr/js-runner/actions/workflows/build-test.yml)
|
|
4
|
+
|
|
5
|
+
Executor for a javascript workbench. Starting from a turtle file describing the workbench.
|
|
6
|
+
|
|
7
|
+
## Process definition
|
|
8
|
+
|
|
9
|
+
Each js process must have `js:file`, `js:function` and `js:mapping` objects.
|
|
10
|
+
|
|
11
|
+
- `js:file` points to the location of the main javascript file, containing the function.
|
|
12
|
+
- `js:location` points to the starting location for `js:file` relative from the current file.
|
|
13
|
+
- `js:function` points to the function name in the file.
|
|
14
|
+
- `js:mapping` is a `fno:Mapping` object that links properties to function arguments.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
When you declare a new js process, it is required to add a shacl shape.
|
|
18
|
+
Each `sh:property` is accounted for, noting the type `sh:class` or `sh:datatype`.
|
|
19
|
+
|
|
20
|
+
Example definitions are available in `processor/configs/*.ttl`.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Pipeline configuration
|
|
24
|
+
|
|
25
|
+
In a js pipeline you can use all declared js processes, as defined in their shacl shapes.
|
|
26
|
+
|
|
27
|
+
An example can be found in `input.ttl`, here a `js:Send` process and a `js:Resc` process are defined.
|
|
28
|
+
`js:Send` takes in a message to send, and a channel to send it to.
|
|
29
|
+
`js:Resc` only takes a channel to read from.
|
|
30
|
+
|
|
31
|
+
(implementation can be found in `procossor/test.js`)
|
|
32
|
+
|
|
33
|
+
Note: currently websockets are configured, but changing the configuration to use the JsReaderChannel and JsWriterChannel will work too, even without a serialization step.
|
|
34
|
+
|
|
35
|
+
You can execute this pipeline with
|
|
36
|
+
```bash
|
|
37
|
+
$ tsc
|
|
38
|
+
$ bun bin/js-runner.js input.ttl
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This example input configuration file uses `owl:imports` to specify additional configuration files.
|
|
42
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@prefix : <https://w3id.org/conn#>.
|
|
2
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
|
|
3
|
+
@prefix sh: <http://www.w3.org/ns/shacl#>.
|
|
4
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
|
5
|
+
|
|
6
|
+
:FileWriterChannel rdfs:subClassOf :WriterChannel.
|
|
7
|
+
:FileReaderChannel rdfs:subClassOf :ReaderChannel.
|
|
8
|
+
[ ] a sh:NodeShape;
|
|
9
|
+
sh:targetClass :FileReaderChannel, :FileWriterChannel;
|
|
10
|
+
sh:property [
|
|
11
|
+
sh:path :filePath;
|
|
12
|
+
sh:name "path";
|
|
13
|
+
sh:maxCount 1;
|
|
14
|
+
sh:minCount 1;
|
|
15
|
+
sh:datatype xsd:string;
|
|
16
|
+
sh:description "Path of the used file";
|
|
17
|
+
], [
|
|
18
|
+
sh:path :fileOnReplace;
|
|
19
|
+
sh:name "onReplace";
|
|
20
|
+
sh:maxCount 1;
|
|
21
|
+
sh:minCount 1;
|
|
22
|
+
sh:datatype xsd:boolean;
|
|
23
|
+
sh:description "Boolean indicating if the files is always replaced, or appended to";
|
|
24
|
+
], [
|
|
25
|
+
sh:path :fileReadFirstContent;
|
|
26
|
+
sh:name "readFirstContent";
|
|
27
|
+
sh:maxCount 1;
|
|
28
|
+
sh:datatype xsd:boolean;
|
|
29
|
+
sh:description "Boolean indicating whether or not the initial content is also a message";
|
|
30
|
+
], [
|
|
31
|
+
sh:path :fileEncoding;
|
|
32
|
+
sh:name "encoding";
|
|
33
|
+
sh:maxCount 1;
|
|
34
|
+
sh:datatype xsd:string;
|
|
35
|
+
sh:description "The encoding used for the file";
|
|
36
|
+
].
|
|
37
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
@prefix : <https://w3id.org/conn#>.
|
|
2
|
+
@prefix sh: <http://www.w3.org/ns/shacl#>.
|
|
3
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
|
4
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
|
|
5
|
+
|
|
6
|
+
:HttpReaderChannel rdfs:subClassOf :ReaderChannel.
|
|
7
|
+
:HttpWriterChannel rdfs:subClassOf :WriterChannel.
|
|
8
|
+
[ ] a sh:NodeShape;
|
|
9
|
+
sh:targetClass :HttpReaderChannel;
|
|
10
|
+
sh:property [
|
|
11
|
+
sh:path :httpEndpoint;
|
|
12
|
+
sh:name "endpoint";
|
|
13
|
+
sh:maxCount 1;
|
|
14
|
+
sh:datatype xsd:string;
|
|
15
|
+
sh:description "Used endpoint";
|
|
16
|
+
], [
|
|
17
|
+
sh:path :httpPort;
|
|
18
|
+
sh:name "port";
|
|
19
|
+
sh:maxCount 1;
|
|
20
|
+
sh:datatype xsd:integer;
|
|
21
|
+
sh:description "Used port";
|
|
22
|
+
], [
|
|
23
|
+
sh:path :binary;
|
|
24
|
+
sh:name "binary";
|
|
25
|
+
sh:maxCount 1;
|
|
26
|
+
sh:datatype xsd:boolean;
|
|
27
|
+
sh:description "Stream raw bytes if true";
|
|
28
|
+
], [
|
|
29
|
+
sh:path :waitHandled;
|
|
30
|
+
sh:name "waitHandled";
|
|
31
|
+
sh:maxCount 1;
|
|
32
|
+
sh:datatype xsd:boolean;
|
|
33
|
+
sh:description "Wait for handlers to be have handled the incoming message";
|
|
34
|
+
], [
|
|
35
|
+
sh:path :responseCode;
|
|
36
|
+
sh:name "responseCode";
|
|
37
|
+
sh:maxCount 1;
|
|
38
|
+
sh:datatype xsd:integer;
|
|
39
|
+
sh:description "Specify the expected response code (default 200)";
|
|
40
|
+
].
|
|
41
|
+
|
|
42
|
+
[ ] a sh:NodeShape;
|
|
43
|
+
sh:targetClass :HttpWriterChannel;
|
|
44
|
+
sh:property [
|
|
45
|
+
sh:path :httpEndpoint;
|
|
46
|
+
sh:name "endpoint";
|
|
47
|
+
sh:maxCount 1;
|
|
48
|
+
sh:minCount 1;
|
|
49
|
+
sh:datatype xsd:string;
|
|
50
|
+
sh:description "Used endpoint";
|
|
51
|
+
], [
|
|
52
|
+
sh:path :httpMethod;
|
|
53
|
+
sh:name "method";
|
|
54
|
+
sh:minCount 1;
|
|
55
|
+
sh:maxCount 1;
|
|
56
|
+
sh:datatype xsd:string;
|
|
57
|
+
sh:description "Used method";
|
|
58
|
+
].
|
|
59
|
+
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
@prefix : <https://w3id.org/conn#>.
|
|
2
|
+
@prefix sh: <http://www.w3.org/ns/shacl#>.
|
|
3
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
|
4
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
|
|
5
|
+
|
|
6
|
+
:KafkaReaderChannel rdfs:subClassOf :ReaderChannel.
|
|
7
|
+
:KafkaReaderChannelShape a sh:NodeShape;
|
|
8
|
+
sh:targetClass :KafkaReaderChannel;
|
|
9
|
+
sh:property [
|
|
10
|
+
sh:path :kafkaTopic;
|
|
11
|
+
sh:name "topic";
|
|
12
|
+
sh:minCount 1;
|
|
13
|
+
sh:maxCount 1;
|
|
14
|
+
sh:class :KafkaTopic;
|
|
15
|
+
sh:description "Information about the used topic";
|
|
16
|
+
], [
|
|
17
|
+
sh:path :kafkaConsumer;
|
|
18
|
+
sh:name "consumer";
|
|
19
|
+
sh:minCount 1;
|
|
20
|
+
sh:maxCount 1;
|
|
21
|
+
sh:class :KafkaConsumer;
|
|
22
|
+
sh:description "Information about the kafka consumer";
|
|
23
|
+
], [
|
|
24
|
+
sh:path :kafkaBroker;
|
|
25
|
+
sh:name "broker";
|
|
26
|
+
sh:minCount 1;
|
|
27
|
+
sh:maxCount 1;
|
|
28
|
+
sh:class :KafkaBroker;
|
|
29
|
+
sh:description "Information about the kafka broker";
|
|
30
|
+
].
|
|
31
|
+
|
|
32
|
+
[ ] a sh:NodeShape;
|
|
33
|
+
sh:targetClass :KafkaTopic;
|
|
34
|
+
sh:property [
|
|
35
|
+
sh:path :topicName;
|
|
36
|
+
sh:name "name";
|
|
37
|
+
sh:minCount 1;
|
|
38
|
+
sh:maxCount 1;
|
|
39
|
+
sh:datatype xsd:string;
|
|
40
|
+
sh:description "Name of the topic";
|
|
41
|
+
], [
|
|
42
|
+
sh:path :topicFromBeginning;
|
|
43
|
+
sh:name "fromBeginning";
|
|
44
|
+
sh:maxCount 1;
|
|
45
|
+
sh:datatype xsd:boolean;
|
|
46
|
+
sh:description "Restart the topic from the beginning";
|
|
47
|
+
].
|
|
48
|
+
|
|
49
|
+
[ ] a sh:NodeShape;
|
|
50
|
+
sh:targetClass :KafkaConsumer;
|
|
51
|
+
sh:property [
|
|
52
|
+
sh:path :groupId;
|
|
53
|
+
sh:name "groupId";
|
|
54
|
+
sh:minCount 1;
|
|
55
|
+
sh:maxCount 1;
|
|
56
|
+
sh:datatype xsd:string;
|
|
57
|
+
sh:description "Group identifier";
|
|
58
|
+
].
|
|
59
|
+
|
|
60
|
+
[ ] a sh:NodeShape;
|
|
61
|
+
sh:targetClass :KafkaBroker;
|
|
62
|
+
sh:property [
|
|
63
|
+
sh:path :brokerHost;
|
|
64
|
+
sh:name "hosts";
|
|
65
|
+
sh:minCount 1;
|
|
66
|
+
sh:datatype xsd:string;
|
|
67
|
+
sh:description "Broker host to connect to";
|
|
68
|
+
].
|
|
69
|
+
|
|
70
|
+
:KafkaWriterChannel rdfs:subClassOf :WriterChannel.
|
|
71
|
+
[ ] a sh:NodeShape;
|
|
72
|
+
sh:targetClass :KafkaWriterChannel;
|
|
73
|
+
sh:property [
|
|
74
|
+
sh:path :kafkaTopic;
|
|
75
|
+
sh:name "topic";
|
|
76
|
+
sh:minCount 1;
|
|
77
|
+
sh:maxCount 1;
|
|
78
|
+
sh:class :KafkaTopic;
|
|
79
|
+
sh:description "Information about the used topic";
|
|
80
|
+
], [
|
|
81
|
+
sh:path :kafkaBroker;
|
|
82
|
+
sh:name "broker";
|
|
83
|
+
sh:minCount 1;
|
|
84
|
+
sh:maxCount 1;
|
|
85
|
+
sh:class :KafkaBroker;
|
|
86
|
+
sh:description "Information about the kafka broker";
|
|
87
|
+
], [
|
|
88
|
+
sh:path :kafkaProducer;
|
|
89
|
+
sh:name "producer";
|
|
90
|
+
sh:minCount 1;
|
|
91
|
+
sh:maxCount 1;
|
|
92
|
+
sh:class :KafkaProducer;
|
|
93
|
+
sh:description "Information about the kafka producer";
|
|
94
|
+
].
|
|
95
|
+
|
|
96
|
+
[ ] a sh:NodeShape;
|
|
97
|
+
sh:targetClass :KafkaProducer.
|
|
98
|
+
|
package/channels/ws.ttl
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
@prefix : <https://w3id.org/conn#>.
|
|
2
|
+
@prefix sh: <http://www.w3.org/ns/shacl#>.
|
|
3
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
|
4
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
|
|
5
|
+
|
|
6
|
+
:WsReaderChannel rdfs:subClassOf :ReaderChannel.
|
|
7
|
+
:WsWriterChannel rdfs:subClassOf :WriterChannel.
|
|
8
|
+
[ ] a sh:NodeShape;
|
|
9
|
+
sh:targetClass :WsReaderChannel;
|
|
10
|
+
sh:property [
|
|
11
|
+
sh:name "url";
|
|
12
|
+
sh:path :wsUrl;
|
|
13
|
+
sh:datatype xsd:string;
|
|
14
|
+
sh:maxCount 1;
|
|
15
|
+
sh:minCount 1;
|
|
16
|
+
].
|
|
17
|
+
|
|
18
|
+
[ ] a sh:NodeShape;
|
|
19
|
+
sh:targetClass :WsWriterChannel;
|
|
20
|
+
sh:property [
|
|
21
|
+
sh:name "port";
|
|
22
|
+
sh:path :wsPort;
|
|
23
|
+
sh:datatype xsd:integer;
|
|
24
|
+
sh:maxCount 1;
|
|
25
|
+
sh:minCount 1;
|
|
26
|
+
], [
|
|
27
|
+
sh:name "host";
|
|
28
|
+
sh:path :wsHost;
|
|
29
|
+
sh:datatype xsd:string;
|
|
30
|
+
sh:maxCount 1;
|
|
31
|
+
sh:minCount 1;
|
|
32
|
+
].
|
|
33
|
+
|
package/ontology.ttl
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
@prefix js: <https://w3id.org/conn/js#>.
|
|
2
|
+
@prefix fno: <https://w3id.org/function/ontology#>.
|
|
3
|
+
@prefix fnom: <https://w3id.org/function/vocabulary/mapping#>.
|
|
4
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
|
5
|
+
@prefix : <https://w3id.org/conn#>.
|
|
6
|
+
@prefix sh: <http://www.w3.org/ns/shacl#>.
|
|
7
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
|
|
8
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
|
|
9
|
+
@prefix dc: <http://purl.org/dc/terms/>.
|
|
10
|
+
@prefix rdfl: <https://w3id.org/rdf-lens/ontology#>.
|
|
11
|
+
|
|
12
|
+
[ ] a sh:NodeShape;
|
|
13
|
+
sh:targetClass :Channel;
|
|
14
|
+
sh:property [
|
|
15
|
+
sh:path ( );
|
|
16
|
+
sh:name "id";
|
|
17
|
+
sh:maxCount 1;
|
|
18
|
+
sh:minCount 1;
|
|
19
|
+
sh:datatype xsd:iri;
|
|
20
|
+
], [
|
|
21
|
+
sh:path :reader;
|
|
22
|
+
sh:name "reader";
|
|
23
|
+
sh:maxCount 1;
|
|
24
|
+
sh:datatype xsd:iri;
|
|
25
|
+
], [
|
|
26
|
+
sh:path :writer;
|
|
27
|
+
sh:name "writer";
|
|
28
|
+
sh:maxCount 1;
|
|
29
|
+
sh:datatype xsd:iri;
|
|
30
|
+
].
|
|
31
|
+
|
|
32
|
+
[ ] a sh:NodeShape;
|
|
33
|
+
sh:targetClass :ReaderChannel;
|
|
34
|
+
sh:property [
|
|
35
|
+
sh:path ( );
|
|
36
|
+
sh:name "id";
|
|
37
|
+
sh:maxCount 1;
|
|
38
|
+
sh:minCount 1;
|
|
39
|
+
sh:datatype xsd:iri;
|
|
40
|
+
], [
|
|
41
|
+
sh:path rdf:type;
|
|
42
|
+
sh:name "ty";
|
|
43
|
+
sh:maxCount 1;
|
|
44
|
+
sh:datatype xsd:iri;
|
|
45
|
+
], [
|
|
46
|
+
sh:path ( );
|
|
47
|
+
sh:name "config";
|
|
48
|
+
sh:maxCount 1;
|
|
49
|
+
sh:minCount 1;
|
|
50
|
+
sh:class rdfl:TypedExtract;
|
|
51
|
+
].
|
|
52
|
+
|
|
53
|
+
[ ] a sh:NodeShape;
|
|
54
|
+
sh:targetClass :WriterChannel;
|
|
55
|
+
sh:property [
|
|
56
|
+
sh:path ( );
|
|
57
|
+
sh:name "id";
|
|
58
|
+
sh:maxCount 1;
|
|
59
|
+
sh:minCount 1;
|
|
60
|
+
sh:datatype xsd:iri;
|
|
61
|
+
], [
|
|
62
|
+
sh:path rdf:type;
|
|
63
|
+
sh:name "ty";
|
|
64
|
+
sh:maxCount 1;
|
|
65
|
+
sh:minCount 1;
|
|
66
|
+
sh:datatype xsd:iri;
|
|
67
|
+
], [
|
|
68
|
+
sh:path ( );
|
|
69
|
+
sh:name "config";
|
|
70
|
+
sh:maxCount 1;
|
|
71
|
+
sh:minCount 1;
|
|
72
|
+
sh:class rdfl:TypedExtract;
|
|
73
|
+
].
|
|
74
|
+
|
|
75
|
+
js:JsChannel rdfs:subClassOf :Channel.
|
|
76
|
+
js:JsReaderChannel rdfs:subClassOf :ReaderChannel.
|
|
77
|
+
[ ] a sh:NodeShape;
|
|
78
|
+
sh:targetClass js:JsReaderChannel;
|
|
79
|
+
sh:property [
|
|
80
|
+
sh:path [ sh:inversePath :reader ];
|
|
81
|
+
sh:name "channel";
|
|
82
|
+
sh:maxCount 1;
|
|
83
|
+
sh:minCount 1;
|
|
84
|
+
sh:class :Channel;
|
|
85
|
+
].
|
|
86
|
+
|
|
87
|
+
js:JsWriterChannel rdfs:subClassOf :WriterChannel.
|
|
88
|
+
[ ] a sh:NodeShape;
|
|
89
|
+
sh:targetClass js:JsWriterChannel;
|
|
90
|
+
sh:property [
|
|
91
|
+
sh:path [ sh:inversePath :writer ];
|
|
92
|
+
sh:name "channel";
|
|
93
|
+
sh:maxCount 1;
|
|
94
|
+
sh:minCount 1;
|
|
95
|
+
sh:class :Channel;
|
|
96
|
+
].
|
|
97
|
+
|
|
98
|
+
#
|
|
99
|
+
js:JsChannel a :Channel;
|
|
100
|
+
dc:title "Javascript in memory channel";
|
|
101
|
+
dc:description "Channel only used by the JsRunner, enabling fast in memory communication.";
|
|
102
|
+
:reader :JsReaderChannel;
|
|
103
|
+
:writer :JsWriterChannel.
|
|
104
|
+
|
|
105
|
+
js:JsProcess a :ProcessClass;
|
|
106
|
+
dc:title "Javascript Runner";
|
|
107
|
+
dc:description "The JSRunner is one of the most feature rich runners of the connector architecture. It enables lifting javascript functions to connector architecture components. It allows for fast in memory communication between these processors with the js:JsChannel. More information can be found at https://the-connector-architecture.github.io/site/.";
|
|
108
|
+
:supportsChannel :WsChannel,
|
|
109
|
+
:JsChannel,
|
|
110
|
+
:FileChannel,
|
|
111
|
+
:KafkaChannel,
|
|
112
|
+
:HttpChannel.
|
|
113
|
+
|
|
114
|
+
[ ] a sh:NodeShape;
|
|
115
|
+
sh:targetClass fno:Mapping;
|
|
116
|
+
sh:property [
|
|
117
|
+
sh:class fnom:PositionParameterMapping;
|
|
118
|
+
sh:path fno:parameterMapping;
|
|
119
|
+
sh:name "parameters";
|
|
120
|
+
].
|
|
121
|
+
|
|
122
|
+
[ ] a sh:NodeShape;
|
|
123
|
+
sh:targetClass fnom:PositionParameterMapping;
|
|
124
|
+
sh:property [
|
|
125
|
+
sh:datatype xsd:string;
|
|
126
|
+
sh:path fnom:functionParameter;
|
|
127
|
+
sh:name "parameter";
|
|
128
|
+
sh:maxCount 1;
|
|
129
|
+
], [
|
|
130
|
+
sh:datatype xsd:integer;
|
|
131
|
+
sh:path fnom:implementationParameterPosition;
|
|
132
|
+
sh:name "position";
|
|
133
|
+
sh:maxCount 1;
|
|
134
|
+
].
|
|
135
|
+
|
|
136
|
+
js:JsProcessorShape a sh:NodeShape;
|
|
137
|
+
sh:targetClass js:JsProcess;
|
|
138
|
+
sh:property [
|
|
139
|
+
sh:datatype xsd:iri;
|
|
140
|
+
sh:path ( );
|
|
141
|
+
sh:name "ty";
|
|
142
|
+
sh:maxCount 1;
|
|
143
|
+
sh:minCount 1;
|
|
144
|
+
], [
|
|
145
|
+
sh:datatype xsd:string;
|
|
146
|
+
sh:path js:file;
|
|
147
|
+
sh:name "file";
|
|
148
|
+
sh:maxCount 1;
|
|
149
|
+
sh:minCount 1;
|
|
150
|
+
], [
|
|
151
|
+
sh:datatype xsd:string;
|
|
152
|
+
sh:path js:location;
|
|
153
|
+
sh:name "location";
|
|
154
|
+
sh:maxCount 1;
|
|
155
|
+
sh:minCount 1;
|
|
156
|
+
], [
|
|
157
|
+
sh:datatype xsd:string;
|
|
158
|
+
sh:path js:function;
|
|
159
|
+
sh:name "func";
|
|
160
|
+
sh:maxCount 1;
|
|
161
|
+
sh:minCount 1;
|
|
162
|
+
], [
|
|
163
|
+
sh:class fno:Mapping;
|
|
164
|
+
sh:path js:mapping;
|
|
165
|
+
sh:name "mapping";
|
|
166
|
+
sh:maxCount 1;
|
|
167
|
+
sh:minCount 1;
|
|
168
|
+
].
|
|
169
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rdfc/js-runner",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
"import": "./dist/index.js",
|
|
7
|
+
"require": "./dist/index.cjs"
|
|
8
|
+
},
|
|
9
|
+
"description": "",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"./dist/**/*",
|
|
13
|
+
"./ontology.ttl",
|
|
14
|
+
"./processor/**/*",
|
|
15
|
+
"./channels/**/*"
|
|
16
|
+
],
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"bin": {
|
|
19
|
+
"js-runner": "bin/bundle.mjs"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc && tsc-alias && rollup ./dist/index.js --file ./dist/index.cjs --format cjs && bun build --external debug ./bin/js-runner.js --outfile bin/bundle.mjs --target node && npm run build:recompose",
|
|
23
|
+
"build:recompose": "sed -z 's/var __require = (id) => {\\n return import.meta.require(id);\\n};/import Module from \"node:module\";\\nconst __require = Module.createRequire(import.meta.url);/' -i bin/bundle.mjs",
|
|
24
|
+
"watch": "tsc -w",
|
|
25
|
+
"test": "vitest run --coverage --coverage.include src",
|
|
26
|
+
"prepare": "husky"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [],
|
|
29
|
+
"author": "",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@rdfjs/types": "^1.1.0",
|
|
33
|
+
"@treecg/types": "^0.4.5",
|
|
34
|
+
"command-line-args": "^5.2.1",
|
|
35
|
+
"command-line-usage": "^6.1.3",
|
|
36
|
+
"debug": "^4.3.4",
|
|
37
|
+
"kafkajs": "^2.2.4",
|
|
38
|
+
"n3": "^1.17.1",
|
|
39
|
+
"rdf-lens": "^1.2.8",
|
|
40
|
+
"stream-to-array": "^2.3.0",
|
|
41
|
+
"ws": "^8.14.2"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@jest/globals": "^29.7.0",
|
|
45
|
+
"@knighted/duel": "^1.0.6",
|
|
46
|
+
"@types/command-line-args": "^5.2.2",
|
|
47
|
+
"@types/command-line-usage": "^5.0.3",
|
|
48
|
+
"@types/debug": "^4.1.12",
|
|
49
|
+
"@types/n3": "^1.16.3",
|
|
50
|
+
"@types/node": "^18.11.15",
|
|
51
|
+
"@types/ws": "^8.5.8",
|
|
52
|
+
"rollup": "^4.12.0",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
|
54
|
+
"@typescript-eslint/parser": "^7.4.0",
|
|
55
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
56
|
+
"dotenv": "^16.4.5",
|
|
57
|
+
"eslint": "^8.57.0",
|
|
58
|
+
"eslint-config-prettier": "^9.1.0",
|
|
59
|
+
"husky": "^9.0.11",
|
|
60
|
+
"lint-staged": "^15.2.2",
|
|
61
|
+
"prettier": "^3.2.5",
|
|
62
|
+
"ts-node": "^10.9.2",
|
|
63
|
+
"tsc-alias": "^1.8.8",
|
|
64
|
+
"typescript": "^5.4.3",
|
|
65
|
+
"vite-tsconfig-paths": "^4.3.2",
|
|
66
|
+
"vitest": "^1.4.0"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
@prefix js: <https://w3id.org/conn/js#>.
|
|
2
|
+
@prefix fno: <https://w3id.org/function/ontology#>.
|
|
3
|
+
@prefix fnom: <https://w3id.org/function/vocabulary/mapping#>.
|
|
4
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
|
5
|
+
@prefix : <https://w3id.org/conn#>.
|
|
6
|
+
@prefix sh: <http://www.w3.org/ns/shacl#>.
|
|
7
|
+
|
|
8
|
+
js:Echo a js:JsProcess;
|
|
9
|
+
js:file <./test.js>;
|
|
10
|
+
js:function "echo";
|
|
11
|
+
js:location <./>;
|
|
12
|
+
js:mapping [
|
|
13
|
+
a fno:Mapping;
|
|
14
|
+
fno:parameterMapping [
|
|
15
|
+
a fnom:PositionParameterMapping;
|
|
16
|
+
fnom:functionParameter "Input Channel";
|
|
17
|
+
fnom:implementationParameterPosition "0"^^xsd:int;
|
|
18
|
+
], [
|
|
19
|
+
a fnom:PositionParameterMapping;
|
|
20
|
+
fnom:functionParameter "Output Channel";
|
|
21
|
+
fnom:implementationParameterPosition "1"^^xsd:int;
|
|
22
|
+
];
|
|
23
|
+
].
|
|
24
|
+
|
|
25
|
+
[ ] a sh:NodeShape;
|
|
26
|
+
sh:targetClass js:Echo;
|
|
27
|
+
sh:property [
|
|
28
|
+
sh:class :ReaderChannel;
|
|
29
|
+
sh:path js:input;
|
|
30
|
+
sh:name "Input Channel";
|
|
31
|
+
sh:maxCount 1;
|
|
32
|
+
], [
|
|
33
|
+
sh:class :WriterChannel;
|
|
34
|
+
sh:path js:output;
|
|
35
|
+
sh:name "Output Channel";
|
|
36
|
+
sh:maxCount 1;
|
|
37
|
+
].
|
|
38
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
@prefix js: <https://w3id.org/conn/js#>.
|
|
2
|
+
@prefix fno: <https://w3id.org/function/ontology#>.
|
|
3
|
+
@prefix fnom: <https://w3id.org/function/vocabulary/mapping#>.
|
|
4
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
|
5
|
+
@prefix : <https://w3id.org/conn#>.
|
|
6
|
+
@prefix sh: <http://www.w3.org/ns/shacl#>.
|
|
7
|
+
|
|
8
|
+
<> :install [
|
|
9
|
+
a :LocalInstall;
|
|
10
|
+
:path <./>;
|
|
11
|
+
].
|
|
12
|
+
|
|
13
|
+
js:Resc a js:JsProcess;
|
|
14
|
+
js:file <./test.js>;
|
|
15
|
+
js:function "resc";
|
|
16
|
+
js:location <./>;
|
|
17
|
+
js:mapping [
|
|
18
|
+
a fno:Mapping;
|
|
19
|
+
fno:parameterMapping [
|
|
20
|
+
a fnom:PositionParameterMapping;
|
|
21
|
+
fnom:functionParameter "input";
|
|
22
|
+
fnom:implementationParameterPosition "0"^^xsd:int;
|
|
23
|
+
];
|
|
24
|
+
].
|
|
25
|
+
|
|
26
|
+
[ ] a sh:NodeShape;
|
|
27
|
+
sh:targetClass js:Resc;
|
|
28
|
+
sh:property [
|
|
29
|
+
sh:class :ReaderChannel;
|
|
30
|
+
sh:path js:rescReader;
|
|
31
|
+
sh:name "input";
|
|
32
|
+
sh:maxCount 1;
|
|
33
|
+
].
|
|
34
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
@prefix js: <https://w3id.org/conn/js#>.
|
|
2
|
+
@prefix fno: <https://w3id.org/function/ontology#>.
|
|
3
|
+
@prefix fnom: <https://w3id.org/function/vocabulary/mapping#>.
|
|
4
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
|
5
|
+
@prefix : <https://w3id.org/conn#>.
|
|
6
|
+
@prefix sh: <http://www.w3.org/ns/shacl#>.
|
|
7
|
+
|
|
8
|
+
js:Send a js:JsProcess;
|
|
9
|
+
js:file <./test.js>;
|
|
10
|
+
js:function "send";
|
|
11
|
+
js:location <./>;
|
|
12
|
+
js:mapping [
|
|
13
|
+
a fno:Mapping;
|
|
14
|
+
fno:parameterMapping [
|
|
15
|
+
a fnom:PositionParameterMapping;
|
|
16
|
+
fnom:functionParameter "msg";
|
|
17
|
+
fnom:implementationParameterPosition "0"^^xsd:int;
|
|
18
|
+
], [
|
|
19
|
+
a fnom:PositionParameterMapping;
|
|
20
|
+
fnom:functionParameter "output";
|
|
21
|
+
fnom:implementationParameterPosition "1"^^xsd:int;
|
|
22
|
+
];
|
|
23
|
+
].
|
|
24
|
+
|
|
25
|
+
[ ] a sh:NodeShape;
|
|
26
|
+
sh:targetClass js:Send;
|
|
27
|
+
sh:property [
|
|
28
|
+
sh:datatype xsd:string;
|
|
29
|
+
sh:path js:msg;
|
|
30
|
+
sh:name "msg";
|
|
31
|
+
sh:maxCount 1;
|
|
32
|
+
sh:minCount 1;
|
|
33
|
+
], [
|
|
34
|
+
sh:class :WriterChannel;
|
|
35
|
+
sh:path js:sendWriter;
|
|
36
|
+
sh:name "output";
|
|
37
|
+
sh:maxCount 1;
|
|
38
|
+
sh:minCount 1;
|
|
39
|
+
].
|
|
40
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import http from "http";
|
|
2
|
+
|
|
3
|
+
function streamToString(ev) {
|
|
4
|
+
const datas = [];
|
|
5
|
+
return new Promise((res) => {
|
|
6
|
+
ev.on("data", (d) => datas.push(d));
|
|
7
|
+
ev.on("end", () => res(Buffer.concat(datas)));
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function send(msg, writer) {
|
|
12
|
+
const host = "0.0.0.0";
|
|
13
|
+
const port = 8000;
|
|
14
|
+
const requestListener = async function (req, res) {
|
|
15
|
+
const data = await streamToString(req);
|
|
16
|
+
const ret = `${msg} ${data}`;
|
|
17
|
+
await writer.push(ret);
|
|
18
|
+
res.writeHead(200);
|
|
19
|
+
res.end(ret);
|
|
20
|
+
};
|
|
21
|
+
const server = http.createServer(requestListener);
|
|
22
|
+
|
|
23
|
+
await new Promise((res) => {
|
|
24
|
+
server.listen(port, host, () => {
|
|
25
|
+
console.log(`Server is running on http://${host}:${port} prefix ${msg}`);
|
|
26
|
+
res();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return () => writer.push("Hallo!");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function resc(reader) {
|
|
34
|
+
reader.data((x) => console.log("data", x));
|
|
35
|
+
}
|