@rdfc/js-runner 2.0.0-alpha.7 → 2.0.0-alpha.9

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 (62) hide show
  1. package/.idea/LNKD.tech Editor.xml +194 -0
  2. package/.idea/codeStyles/Project.xml +52 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  5. package/.idea/js-runner.iml +12 -0
  6. package/{examples/echo/.idea → .idea}/modules.xml +1 -1
  7. package/.idea/vcs.xml +6 -0
  8. package/dist/args.d.ts +4 -0
  9. package/dist/args.js +58 -0
  10. package/dist/connectors/file.d.ts +15 -0
  11. package/dist/connectors/file.js +89 -0
  12. package/dist/connectors/http.d.ts +14 -0
  13. package/dist/connectors/http.js +82 -0
  14. package/dist/connectors/kafka.d.ts +48 -0
  15. package/dist/connectors/kafka.js +68 -0
  16. package/dist/connectors/ws.d.ts +10 -0
  17. package/dist/connectors/ws.js +72 -0
  18. package/dist/connectors.d.ts +73 -0
  19. package/dist/connectors.js +168 -0
  20. package/dist/index.cjs +732 -0
  21. package/dist/index.d.ts +42 -0
  22. package/dist/index.js +83 -0
  23. package/dist/tsconfig.tsbuildinfo +1 -0
  24. package/dist/util.d.ts +71 -0
  25. package/dist/util.js +92 -0
  26. package/examples/echo/src/processors.ts +29 -31
  27. package/lib/index.d.ts +2 -1
  28. package/lib/index.js +3 -2
  29. package/lib/jsonld.js +3 -2
  30. package/lib/logger.d.ts +3 -1
  31. package/lib/logger.js +23 -1
  32. package/lib/reader.js +8 -16
  33. package/lib/reexports.d.ts +2 -2
  34. package/lib/reexports.js +3 -3
  35. package/lib/runner.js +27 -16
  36. package/lib/testUtils.js +6 -4
  37. package/lib/tsconfig.tsbuildinfo +1 -1
  38. package/lib/util_processors.js +1 -1
  39. package/lib/writer.js +1 -1
  40. package/package.json +1 -1
  41. package/src/index.ts +2 -1
  42. package/src/jsonld.ts +4 -1
  43. package/src/logger.ts +27 -1
  44. package/src/reader.ts +124 -130
  45. package/src/reexports.ts +5 -2
  46. package/src/runner.ts +158 -143
  47. package/src/testUtils.ts +34 -25
  48. package/src/util_processors.ts +1 -1
  49. package/src/writer.ts +66 -66
  50. package/examples/echo/.idea/echo.iml +0 -9
  51. package/examples/echo/.idea/misc.xml +0 -6
  52. package/examples/echo/.idea/vcs.xml +0 -7
  53. package/examples/echo/.swls/config.json +0 -1
  54. package/examples/echo/index.ttl +0 -3
  55. package/examples/echo/minimal.ttl +0 -90
  56. package/examples/echo/shacl.ttl +0 -9
  57. package/examples/echo/shape.ttl +0 -1339
  58. package/examples/echo/test.ttl +0 -11
  59. package/examples/echo/untitled:/types/MyType.ttl +0 -0
  60. package/file:/home/silvius/Projects/mumo-pipeline/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +0 -3
  61. package/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +0 -3
  62. package/minimal.ttl +0 -99
package/src/testUtils.ts CHANGED
@@ -1,20 +1,22 @@
1
- import { DataChunk, OrchestratorMessage, RunnerClient } from '@rdfc/proto'
1
+ import { DataChunk, RunnerClient } from '@rdfc/proto'
2
2
  import { ClientReadableStream } from '@grpc/grpc-js'
3
3
  import * as grpc from '@grpc/grpc-js'
4
4
  import { ClientReadableStreamImpl } from './reexports'
5
- import { extractShapes } from 'rdf-lens';
6
- import { Parser } from 'n3';
7
- import { readFile } from 'fs/promises';
8
- import winston, { createLogger } from 'winston';
9
- import { WriterInstance } from './writer';
10
- import { ReaderInstance } from './reader';
5
+ import { extractShapes } from 'rdf-lens'
6
+ import { Parser } 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
11
 
12
- export async function getProcessorShape(baseIRI = process.cwd() + "/node_modules/@rdfc/js-runner/index.ttl") {
13
- const configFile = await readFile(baseIRI, { encoding: "utf8" });
14
- const configQuads = new Parser().parse(configFile);
15
- const shapes = extractShapes(configQuads);
12
+ export async function getProcessorShape(
13
+ baseIRI = process.cwd() + '/node_modules/@rdfc/js-runner/index.ttl',
14
+ ) {
15
+ const configFile = await readFile(baseIRI, { encoding: 'utf8' })
16
+ const configQuads = new Parser().parse(configFile)
17
+ const shapes = extractShapes(configQuads)
16
18
 
17
- return shapes;
19
+ return shapes
18
20
  }
19
21
 
20
22
  export class TestClient extends RunnerClient {
@@ -46,23 +48,30 @@ export async function one<T>(iter: AsyncIterable<T>): Promise<T | undefined> {
46
48
  export const client = new TestClient()
47
49
  export const uri = 'someUri'
48
50
  export const logger = createLogger({
49
- transports: new winston.transports.Console({ level: process.env['DEBUG'] || 'info' }),
51
+ transports: new winston.transports.Console({
52
+ level: process.env['DEBUG'] || 'info',
53
+ }),
50
54
  })
51
55
 
52
56
  export function createWriter(iri = uri): [WriterInstance, ReaderInstance] {
53
- const reader = createReader(iri);
54
- const writeStream = new WriterInstance(iri, client, async (msg) => {
55
- if (msg.msg) {
56
- reader.handleMsg(msg.msg);
57
- }
58
- if(msg.close) {
59
- reader.close()
60
- }
61
- }, logger)
62
- return [writeStream, reader];
57
+ const reader = createReader(iri)
58
+ const writeStream = new WriterInstance(
59
+ iri,
60
+ client,
61
+ async (msg) => {
62
+ if (msg.msg) {
63
+ reader.handleMsg(msg.msg)
64
+ }
65
+ if (msg.close) {
66
+ reader.close()
67
+ }
68
+ },
69
+ logger,
70
+ )
71
+ return [writeStream, reader]
63
72
  }
64
73
 
65
74
  export function createReader(iri = uri): ReaderInstance {
66
- const reader = new ReaderInstance(iri, client, logger);
67
- return reader;
75
+ const reader = new ReaderInstance(iri, client, logger)
76
+ return reader
68
77
  }
@@ -16,5 +16,5 @@ export class LogProcessor extends Processor<LogArgs> {
16
16
  }
17
17
  }
18
18
 
19
- async produce() { }
19
+ async produce() {}
20
20
  }
package/src/writer.ts CHANGED
@@ -5,86 +5,86 @@ import { Any } from './reader'
5
5
 
6
6
  type Writable = (msg: OrchestratorMessage) => Promise<unknown>
7
7
  export interface Writer {
8
- readonly uri: string;
9
- buffer(buffer: Uint8Array): Promise<void>
8
+ readonly uri: string
9
+ buffer(buffer: Uint8Array): Promise<void>
10
10
 
11
- stream(buffer: AsyncIterable<Uint8Array>): Promise<void>
12
- stream<T>(
13
- buffer: AsyncIterable<T>,
14
- tranform: (x: T) => Uint8Array,
15
- ): Promise<void>
11
+ stream(buffer: AsyncIterable<Uint8Array>): Promise<void>
12
+ stream<T>(
13
+ buffer: AsyncIterable<T>,
14
+ tranform: (x: T) => Uint8Array,
15
+ ): Promise<void>
16
16
 
17
- string(buffer: string): Promise<void>
18
- any(any: Any): Promise<void>
19
- close(): Promise<void>
17
+ string(buffer: string): Promise<void>
18
+ any(any: Any): Promise<void>
19
+ close(): Promise<void>
20
20
  }
21
21
  const encoder = new TextEncoder()
22
22
  export class WriterInstance implements Writer {
23
- readonly uri: string
24
- private readonly client: RunnerClient
25
- private readonly write: Writable
26
- private readonly logger: Logger
23
+ readonly uri: string
24
+ private readonly client: RunnerClient
25
+ private readonly write: Writable
26
+ private readonly logger: Logger
27
27
 
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
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
38
+ }
39
+ async any(any: Any): Promise<void> {
40
+ if ('stream' in any) {
41
+ await this.stream(any.stream)
38
42
  }
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
- }
43
+ if ('buffer' in any) {
44
+ await this.buffer(any.buffer)
49
45
  }
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 } })
46
+ if ('string' in any) {
47
+ await this.string(any.string)
54
48
  }
49
+ }
55
50
 
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 } })
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 } })
54
+ }
65
55
 
66
- const write = promisify(stream.write.bind(stream))
67
- for await (const msg of buffer) {
68
- await write({ data: t(msg) })
69
- }
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 } })
70
65
 
71
- this.logger.debug(`${this.uri} is done streaming message with id ${id.id}`)
72
- stream.end()
66
+ const write = promisify(stream.write.bind(stream))
67
+ for await (const msg of buffer) {
68
+ await write({ data: t(msg) })
73
69
  }
74
70
 
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
- }
71
+ this.logger.debug(`${this.uri} is done streaming message with id ${id.id}`)
72
+ stream.end()
73
+ }
74
+
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
+ }
81
81
 
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
- }
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
+ })
89
88
  }
89
+ }
90
90
  }
@@ -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,6 +0,0 @@
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>
@@ -1,7 +0,0 @@
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>
@@ -1 +0,0 @@
1
- { "disabled": ["shapes"] }
@@ -1,3 +0,0 @@
1
- @prefix foaf: <http://xmlns.com/foaf/0.1/>.
2
- <#me> a foaf:Person;
3
- foaf:name "".
@@ -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
-
@@ -1,9 +0,0 @@
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
- ].