@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.
Files changed (61) hide show
  1. package/.github/workflows/build-test.yml +24 -0
  2. package/.idea/LNKD.tech Editor.xml +194 -0
  3. package/.idea/codeStyles/Project.xml +52 -0
  4. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  5. package/.idea/copilot.data.migration.agent.xml +6 -0
  6. package/.idea/copilot.data.migration.ask.xml +6 -0
  7. package/.idea/copilot.data.migration.ask2agent.xml +6 -0
  8. package/.idea/copilot.data.migration.edit.xml +6 -0
  9. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  10. package/.idea/js-runner.iml +12 -0
  11. package/{examples/echo/.idea → .idea}/modules.xml +1 -1
  12. package/.idea/vcs.xml +6 -0
  13. package/__tests__/echoProcessor.test.ts +12 -11
  14. package/dist/args.d.ts +4 -0
  15. package/dist/args.js +58 -0
  16. package/dist/connectors/file.d.ts +15 -0
  17. package/dist/connectors/file.js +89 -0
  18. package/dist/connectors/http.d.ts +14 -0
  19. package/dist/connectors/http.js +82 -0
  20. package/dist/connectors/kafka.d.ts +48 -0
  21. package/dist/connectors/kafka.js +68 -0
  22. package/dist/connectors/ws.d.ts +10 -0
  23. package/dist/connectors/ws.js +72 -0
  24. package/dist/connectors.d.ts +73 -0
  25. package/dist/connectors.js +168 -0
  26. package/dist/index.cjs +732 -0
  27. package/dist/index.d.ts +42 -0
  28. package/dist/index.js +83 -0
  29. package/dist/tsconfig.tsbuildinfo +1 -0
  30. package/dist/util.d.ts +71 -0
  31. package/dist/util.js +92 -0
  32. package/lib/reader.js +1 -1
  33. package/lib/runner.d.ts +2 -1
  34. package/lib/runner.js +8 -4
  35. package/lib/testUtils/duplex.d.ts +2 -2
  36. package/lib/testUtils/duplex.js +1 -1
  37. package/lib/testUtils/index.d.ts +9 -9
  38. package/lib/testUtils/index.js +10 -11
  39. package/lib/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +25 -25
  41. package/src/reader.ts +8 -8
  42. package/src/runner.ts +13 -5
  43. package/src/testUtils/duplex.ts +2 -2
  44. package/src/testUtils/index.ts +21 -27
  45. package/examples/echo/.idea/echo.iml +0 -9
  46. package/examples/echo/.idea/misc.xml +0 -6
  47. package/examples/echo/.idea/vcs.xml +0 -7
  48. package/examples/echo/.swls/config.json +0 -1
  49. package/examples/echo/index.ttl +0 -3
  50. package/examples/echo/minimal.ttl +0 -90
  51. package/examples/echo/shacl.ttl +0 -9
  52. package/examples/echo/shape.ttl +0 -1339
  53. package/examples/echo/test.ttl +0 -11
  54. package/examples/echo/untitled:/types/MyType.ttl +0 -0
  55. package/file:/home/silvius/Projects/mumo-pipeline/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +0 -3
  56. package/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +0 -3
  57. package/lib/jsonld.d.ts +0 -17
  58. package/lib/jsonld.js +0 -135
  59. package/lib/testUtils.d.ts +0 -24
  60. package/lib/testUtils.js +0 -150
  61. 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.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.21.0",
32
+ "@eslint/js": "^9.39.2",
33
33
  "@rdfjs/types": "^2.0.1",
34
- "@grpc/grpc-js": "^1.12.6",
35
- "@types/jest": "^29.5.14",
34
+ "@types/jest": "^30.0.0",
36
35
  "@types/jsonld": "^1.5.15",
37
- "@types/n3": "^1.21.1",
38
- "@types/node": "^22.13.5",
39
- "@typescript-eslint/eslint-plugin": "^8.25.0",
40
- "@typescript-eslint/parser": "^8.25.0",
41
- "@vitest/coverage-v8": "^3.2.4",
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.0.1",
44
- "eslint-plugin-prettier": "^5.2.3",
45
- "globals": "^16.0.0",
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": "^29.7.0",
48
- "lint-staged": "^15.4.3",
49
- "prettier": "^3.5.2",
50
- "ts-jest": "^29.2.6",
51
- "tsc-alias": "^1.8.10",
52
- "typescript": "^5.7.3",
53
- "typescript-eslint": "^8.25.0",
54
- "vitest": "^3.2.4"
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": "^8.3.3",
60
- "jsonld-streaming-parser": "^5.0.0",
61
- "n3": "^1.23.1",
62
- "rdf-lens": "^1.3.5",
63
- "winston": "^3.17.0",
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
- string: string
22
- }
21
+ string: string
22
+ }
23
23
  | {
24
- stream: AsyncGenerator<Uint8Array>
25
- }
24
+ stream: AsyncGenerator<Uint8Array>
25
+ }
26
26
  | {
27
- buffer: Uint8Array
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* (stream) {
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<unknown>> =
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 addProcessor<P extends Proc<unknown>>(
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('parsing ' + proc.uri + ' type ' + ty)
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('inited ' + proc.uri + ' type ' + ty)
117
+ this.logger.info(`Initiated processor '${proc.uri}'`)
110
118
 
111
119
  this.processors.push(instance)
112
120
  this.processorTransforms.push(instance.transform())
@@ -1,7 +1,7 @@
1
1
  import { Duplex } from 'stream'
2
2
  import type {
3
3
  ClientDuplexStream,
4
- InterceptingCallInterface,
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?: InterceptingCallInterface | undefined
26
+ call?: InterceptingCall | undefined
27
27
  constructor() {
28
28
  super({ objectMode: true })
29
29
  this.id = count++
@@ -1,29 +1,22 @@
1
- import {
2
- DataChunk,
3
- FromRunner,
4
- LogMessage,
5
- Processor as ProcConfig,
6
- ToRunner,
7
- } from '@rdfc/proto'
8
- import {} from '../reexports'
9
- import { extractShapes } from 'rdf-lens'
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 '@rdfc/proto/lib/generated/common'
23
- import { MockClientDuplexStream } from './duplex'
24
- import { promisify } from 'util'
25
- import { Reader } from '../reader'
26
- import { Writer } from '../writer'
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
- const proc = await this.runner.addProcessor<T>({
363
- config: JSON.stringify(this.config),
364
- arguments: '',
365
- uri,
366
- })
367
- return proc
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,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
- ].