@rdfc/js-runner 2.0.0-alpha.6 → 2.0.0-alpha.8

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.
Files changed (43) hide show
  1. package/.editorconfig +9 -0
  2. package/__tests__/channels.test.js +117 -0
  3. package/examples/echo/.idea/echo.iml +9 -0
  4. package/examples/echo/.idea/misc.xml +6 -0
  5. package/examples/echo/.idea/modules.xml +8 -0
  6. package/examples/echo/.idea/vcs.xml +7 -0
  7. package/examples/echo/.swls/config.json +1 -0
  8. package/examples/echo/index.ttl +3 -0
  9. package/examples/echo/minimal.ttl +90 -0
  10. package/examples/echo/pipeline.ttl +22 -4
  11. package/examples/echo/processors.ttl +5 -7
  12. package/examples/echo/shacl.ttl +9 -0
  13. package/examples/echo/shape.ttl +1339 -0
  14. package/examples/echo/src/processors.js +123 -0
  15. package/examples/echo/src/processors.ts +3 -4
  16. package/examples/echo/test.ttl +9 -12
  17. package/file:/home/silvius/Projects/mumo-pipeline/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +3 -0
  18. package/index.ttl +28 -20
  19. package/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +3 -0
  20. package/lib/client.js +1 -1
  21. package/lib/index.d.ts +1 -1
  22. package/lib/index.js +2 -2
  23. package/lib/jsonld.js +4 -3
  24. package/lib/reader.d.ts +2 -1
  25. package/lib/reader.js +8 -16
  26. package/lib/reexports.d.ts +2 -2
  27. package/lib/reexports.js +3 -3
  28. package/lib/runner.js +29 -20
  29. package/lib/testUtils.js +6 -4
  30. package/lib/tsconfig.tsbuildinfo +1 -1
  31. package/lib/writer.d.ts +2 -1
  32. package/lib/writer.js +1 -1
  33. package/minimal.ttl +99 -0
  34. package/package.json +1 -1
  35. package/src/client.ts +16 -14
  36. package/src/index.ts +1 -1
  37. package/src/jsonld.ts +5 -2
  38. package/src/reader.ts +17 -20
  39. package/src/reexports.ts +5 -2
  40. package/src/runner.ts +50 -32
  41. package/src/testUtils.ts +34 -25
  42. package/src/writer.ts +2 -1
  43. package/vite.config.js +11 -0
package/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ # top-most EditorConfig file
2
+ root = true
3
+
4
+ # Unix-style newlines with a newline ending every file
5
+ [*]
6
+ end_of_line = lf
7
+ insert_final_newline = true
8
+ indent_style = space
9
+ indent_size = 2
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
12
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
+ var m = o[Symbol.asyncIterator], i;
14
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ const vitest_1 = require("vitest");
20
+ const reader_1 = require("../src/reader");
21
+ const testUtils_1 = require("../src/testUtils");
22
+ const encoder = new TextEncoder();
23
+ (0, vitest_1.describe)('Reader', () => __awaiter(void 0, void 0, void 0, function* () {
24
+ (0, vitest_1.test)('handles string', () => __awaiter(void 0, void 0, void 0, function* () {
25
+ const reader = new reader_1.ReaderInstance(testUtils_1.uri, testUtils_1.client, testUtils_1.logger);
26
+ const promise = (0, testUtils_1.one)(reader.strings());
27
+ reader.handleMsg({ data: encoder.encode('Hello world'), channel: testUtils_1.uri });
28
+ const out = yield promise;
29
+ (0, vitest_1.expect)(out).toEqual('Hello world');
30
+ }));
31
+ (0, vitest_1.test)('handles closed string', () => __awaiter(void 0, void 0, void 0, function* () {
32
+ const reader = new reader_1.ReaderInstance(testUtils_1.uri, testUtils_1.client, testUtils_1.logger);
33
+ const promise = (0, testUtils_1.one)(reader.strings());
34
+ reader.close();
35
+ const out = yield promise;
36
+ (0, vitest_1.expect)(out).toEqual(undefined);
37
+ }));
38
+ (0, vitest_1.test)('handles strings', () => __awaiter(void 0, void 0, void 0, function* () {
39
+ const reader = new reader_1.ReaderInstance(testUtils_1.uri, testUtils_1.client, testUtils_1.logger);
40
+ const msgsPromise = (() => __awaiter(void 0, void 0, void 0, function* () {
41
+ var _a, e_1, _b, _c;
42
+ const msgs = [];
43
+ try {
44
+ for (var _d = true, _e = __asyncValues(reader.strings()), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
45
+ _c = _f.value;
46
+ _d = false;
47
+ const msg = _c;
48
+ msgs.push(msg);
49
+ }
50
+ }
51
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
52
+ finally {
53
+ try {
54
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
55
+ }
56
+ finally { if (e_1) throw e_1.error; }
57
+ }
58
+ return msgs;
59
+ }))();
60
+ reader.handleMsg({ data: encoder.encode('Hello'), channel: testUtils_1.uri });
61
+ reader.handleMsg({ data: encoder.encode('World'), channel: testUtils_1.uri });
62
+ reader.close();
63
+ const msgs = yield msgsPromise;
64
+ (0, vitest_1.expect)(msgs).toEqual(['Hello', 'World']);
65
+ }));
66
+ (0, vitest_1.test)('handles buffer', () => __awaiter(void 0, void 0, void 0, function* () {
67
+ const reader = new reader_1.ReaderInstance(testUtils_1.uri, testUtils_1.client, testUtils_1.logger);
68
+ const data = encoder.encode('Hello world');
69
+ const promise = (0, testUtils_1.one)(reader.buffers());
70
+ reader.handleMsg({ data, channel: testUtils_1.uri });
71
+ const out = yield promise;
72
+ (0, vitest_1.expect)(out).toEqual(data);
73
+ }));
74
+ (0, vitest_1.test)('handles buffers', () => __awaiter(void 0, void 0, void 0, function* () {
75
+ const reader = new reader_1.ReaderInstance(testUtils_1.uri, testUtils_1.client, testUtils_1.logger);
76
+ const data = encoder.encode('Hello world');
77
+ const promise = (0, testUtils_1.one)(reader.buffers());
78
+ reader.handleMsg({ data, channel: testUtils_1.uri });
79
+ const out = yield promise;
80
+ (0, vitest_1.expect)(out).toEqual(data);
81
+ }));
82
+ (0, vitest_1.test)('handles stream', () => __awaiter(void 0, void 0, void 0, function* () {
83
+ const reader = new reader_1.ReaderInstance(testUtils_1.uri, testUtils_1.client, testUtils_1.logger);
84
+ const nextStream = testUtils_1.client.nextStream();
85
+ const promise = (0, testUtils_1.one)(reader.streams());
86
+ reader.handleStreamingMessage({ id: { id: 5 }, channel: testUtils_1.uri });
87
+ const stream = yield nextStream;
88
+ stream.push('Hello');
89
+ stream.push('World');
90
+ console.log(stream.eventNames());
91
+ const out = yield promise;
92
+ const msgsPromise = (() => __awaiter(void 0, void 0, void 0, function* () {
93
+ var _a, e_2, _b, _c;
94
+ const msgs = [];
95
+ try {
96
+ for (var _d = true, _e = __asyncValues(out), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
97
+ _c = _f.value;
98
+ _d = false;
99
+ const msg = _c;
100
+ msgs.push(msg);
101
+ }
102
+ }
103
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
104
+ finally {
105
+ try {
106
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
107
+ }
108
+ finally { if (e_2) throw e_2.error; }
109
+ }
110
+ return msgs;
111
+ }))();
112
+ stream.emit('end');
113
+ stream.emit('close');
114
+ const msgs = yield msgsPromise;
115
+ console.log(msgs);
116
+ }));
117
+ }));
@@ -0,0 +1,9 @@
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>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_23" project-jdk-name="24" project-jdk-type="JavaSDK">
4
+ <output url="file://$PROJECT_DIR$/out" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/echo.iml" filepath="$PROJECT_DIR$/.idea/echo.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
5
+ <mapping directory="$PROJECT_DIR$/node_modules/@rdfc/js-runner" vcs="Git" />
6
+ </component>
7
+ </project>
@@ -0,0 +1 @@
1
+ { "disabled": ["shapes"] }
@@ -0,0 +1,3 @@
1
+ @prefix foaf: <http://xmlns.com/foaf/0.1/>.
2
+ <#me> a foaf:Person;
3
+ foaf:name "".
@@ -0,0 +1,90 @@
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
+
@@ -1,14 +1,32 @@
1
1
  @prefix owl: <http://www.w3.org/2002/07/owl#>.
2
- @prefix rdfc: <https://w3id.org/rdf-connect/ontology#>.
2
+ @prefix rdfc: <https://w3id.org/rdf-connect#>.
3
3
 
4
4
  <> owl:imports <./processors.ttl>.
5
5
  <> a rdfc:Pipeline;
6
- rdfc:dependency <>;
7
- rdfc:processor <sender>, <echo>, <log>, <test>;
8
- rdfc:runner rdfc:JsRunner.
6
+ rdfc:consistsOf [
7
+ rdfc:instantiates rdfc:NodeRunner;
8
+ rdfc:processor <sender>, <echo>, <log>;
9
+ ].
9
10
 
11
+ # <> a rdfc:Pipeline;
12
+ # rdfc:dependency <>;
13
+ # rdfc:processor <sender>, <echo>, <log>;
14
+ # rdfc:runner rdfc:JsRunner;
15
+ # rdfc:consistsOf [
16
+ # rdfc:instantiates rdfc:BunRunner;
17
+ # rdfc:processor <log>;
18
+ # ], [
19
+ # rdfc:instantiates rdfc:AnyRunner;
20
+ # rdfc:processor <echo>, <test>;
21
+ # rdfc:via [
22
+ # a rdfc:HttpEndpoint;
23
+ # rdfc:url "http://myRemote:5000/";
24
+ # ];
25
+ # ].
10
26
  <1> a rdfc:Writer, rdfc:Reader.
27
+
11
28
  <2> a rdfc:Writer, rdfc:Reader.
29
+ #
12
30
  <sender> a rdfc:SendProcessor;
13
31
  rdfc:writer <1>;
14
32
  rdfc:msg "hallo", "world".
@@ -5,11 +5,10 @@
5
5
  @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
6
6
  @prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
7
7
  @prefix sh: <http://www.w3.org/ns/shacl#>.
8
- @prefix rdfc: <https://w3id.org/rdf-connect/ontology#>.
8
+ @prefix rdfc: <https://w3id.org/rdf-connect#>.
9
9
 
10
10
  <> owl:imports <../../index.ttl>.
11
-
12
- rdfc:Test a rdfc:JsProcessor;
11
+ rdfc:Test rdfc:jsImplementationOf rdfc:Processor;
13
12
  rdfc:entrypoint <./>;
14
13
  rdfc:file <./lib/processors.js>;
15
14
  rdfc:class "TestProcessor".
@@ -26,8 +25,7 @@ rdfc:Test a rdfc:JsProcessor;
26
25
  sh:class rdfl:CBD;
27
26
  ].
28
27
 
29
-
30
- rdfc:EchoProcessor a rdfc:JsProcessor, owl:Class;
28
+ rdfc:EchoProcessor rdfc:jsImplementationOf rdfc:Processor;
31
29
  rdfc:entrypoint <./>;
32
30
  rdfc:file <./lib/processors.js>;
33
31
  rdfc:class "EchoProcessor".
@@ -48,7 +46,7 @@ rdfc:EchoProcessor a rdfc:JsProcessor, owl:Class;
48
46
  sh:class rdfc:Writer;
49
47
  ].
50
48
 
51
- rdfc:LogProcessor a rdfc:JsProcessor;
49
+ rdfc:LogProcessor rdfc:jsImplementationOf rdfc:Processor;
52
50
  rdfc:entrypoint <./>;
53
51
  rdfc:file <./lib/processors.js>;
54
52
  rdfc:class "LogProcessor".
@@ -63,7 +61,7 @@ rdfc:LogProcessor a rdfc:JsProcessor;
63
61
  sh:class rdfc:Reader;
64
62
  ].
65
63
 
66
- rdfc:SendProcessor a rdfc:JsProcessor;
64
+ rdfc:SendProcessor rdfc:jsImplementationOf rdfc:Processor;
67
65
  rdfc:entrypoint <./>;
68
66
  rdfc:file <./lib/processors.js>;
69
67
  rdfc:class "SendProcessor".
@@ -0,0 +1,9 @@
1
+
2
+ @prefix foaf: <http://xmlns.com/foaf/0.1/>.
3
+ @prefix sh: <http://www.w3.org/ns/shacl#>.
4
+ [] a sh:NodeShape;
5
+ sh:targetClass foaf:Person;
6
+ sh:property [
7
+ sh:path foaf:name;
8
+ sh:minCount 1;
9
+ ].