@rdfc/js-runner 3.0.2 → 3.0.4-remote

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 (84) hide show
  1. package/.claude/settings.local.json +12 -0
  2. package/README.md +41 -1
  3. package/__tests__/echoProcessor.test.ts +11 -12
  4. package/bin/runner.js +7 -1
  5. package/bin/server.js +13 -0
  6. package/bun.lock +820 -0
  7. package/examples/echo/.idea/echo.iml +9 -0
  8. package/examples/echo/.idea/misc.xml +6 -0
  9. package/{.idea → examples/echo/.idea}/modules.xml +1 -1
  10. package/examples/echo/.idea/vcs.xml +7 -0
  11. package/examples/echo/.swls/config.json +1 -0
  12. package/examples/echo/package-lock.json +27 -29
  13. package/examples/echo/pipeline.ttl +0 -1
  14. package/examples/echo/processors.ttl +1 -1
  15. package/examples/echo/remote_pipeline.ttl +18 -0
  16. package/examples/echo/server.ttl +5 -0
  17. package/examples/echo/untitled:/types/MyType.ttl +0 -0
  18. package/file:/home/silvius/Projects/mumo-pipeline/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +3 -0
  19. package/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +3 -0
  20. package/lib/client.d.ts +2 -1
  21. package/lib/client.js +70 -22
  22. package/lib/index.d.ts +2 -0
  23. package/lib/index.js +3 -1
  24. package/lib/jsonld.d.ts +17 -0
  25. package/lib/jsonld.js +135 -0
  26. package/lib/logger.d.ts +1 -0
  27. package/lib/logger.js +19 -9
  28. package/lib/reader.d.ts +4 -1
  29. package/lib/reader.js +11 -3
  30. package/lib/runner.d.ts +6 -1
  31. package/lib/runner.js +43 -15
  32. package/lib/server.d.ts +9 -0
  33. package/lib/server.js +459 -0
  34. package/lib/state.d.ts +32 -0
  35. package/lib/state.js +71 -0
  36. package/lib/testUtils/duplex.js +1 -1
  37. package/lib/testUtils/index.d.ts +9 -9
  38. package/lib/testUtils/index.js +9 -9
  39. package/lib/testUtils.d.ts +24 -0
  40. package/lib/testUtils.js +150 -0
  41. package/lib/tsconfig.tsbuildinfo +1 -1
  42. package/lib/writer.d.ts +5 -1
  43. package/lib/writer.js +26 -10
  44. package/minimal.ttl +99 -0
  45. package/package.json +21 -19
  46. package/src/client.ts +99 -24
  47. package/src/index.ts +2 -0
  48. package/src/logger.ts +15 -7
  49. package/src/reader.ts +19 -9
  50. package/src/runner.ts +61 -12
  51. package/src/server.ts +545 -0
  52. package/src/state.ts +105 -0
  53. package/src/testUtils/duplex.ts +1 -4
  54. package/src/testUtils/index.ts +25 -21
  55. package/src/writer.ts +36 -12
  56. package/.idea/LNKD.tech Editor.xml +0 -194
  57. package/.idea/codeStyles/Project.xml +0 -52
  58. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  59. package/.idea/copilot.data.migration.agent.xml +0 -6
  60. package/.idea/copilot.data.migration.ask.xml +0 -6
  61. package/.idea/copilot.data.migration.ask2agent.xml +0 -6
  62. package/.idea/copilot.data.migration.edit.xml +0 -6
  63. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  64. package/.idea/js-runner.iml +0 -12
  65. package/.idea/vcs.xml +0 -6
  66. package/dist/args.d.ts +0 -4
  67. package/dist/args.js +0 -58
  68. package/dist/connectors/file.d.ts +0 -15
  69. package/dist/connectors/file.js +0 -89
  70. package/dist/connectors/http.d.ts +0 -14
  71. package/dist/connectors/http.js +0 -82
  72. package/dist/connectors/kafka.d.ts +0 -48
  73. package/dist/connectors/kafka.js +0 -68
  74. package/dist/connectors/ws.d.ts +0 -10
  75. package/dist/connectors/ws.js +0 -72
  76. package/dist/connectors.d.ts +0 -73
  77. package/dist/connectors.js +0 -168
  78. package/dist/index.cjs +0 -732
  79. package/dist/index.d.ts +0 -42
  80. package/dist/index.js +0 -83
  81. package/dist/tsconfig.tsbuildinfo +0 -1
  82. package/dist/util.d.ts +0 -71
  83. package/dist/util.js +0 -92
  84. package/jest.config.js +0 -2
@@ -0,0 +1,12 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(npm test:*)",
5
+ "Bash(npx tsc:*)",
6
+ "Bash(npm run:*)",
7
+ "Bash(chmod +x *)",
8
+ "Bash(node bin/server.js)",
9
+ "Bash(echo \"exit:$?\")"
10
+ ]
11
+ }
12
+ }
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # JavaScript runner for RDF-Connect
2
2
 
3
+ [![Build and tests with Node.js](https://github.com/rdf-connect/js-runner/actions/workflows/build-test.yml/badge.svg)](https://github.com/rdf-connect/js-runner/actions/workflows/build-test.yml) [![npm](https://img.shields.io/npm/v/@rdfc/js-runner.svg?style=popout)](https://npmjs.com/package/@rdfc/js-runner)
4
+
5
+ This package provides a JavaScript runner implementation for RDF-Connect, which allows you to run JavaScript/TypeScript processors in your [RDF-Connect](https://github.com/rdf-connect/rdf-connect) pipeline.
6
+
3
7
  ## Usage
4
8
 
5
9
  To use the JavaScript (Node or Bun) runner for RDF-Connect, you need to have a pipeline configuration that includes JavaScript/TypeScript processors.
@@ -28,6 +32,42 @@ You can install the js-runner package using the following command:
28
32
  npm install @rdfc/js-runner
29
33
  ```
30
34
 
35
+ ### Remote runner usage
36
+
37
+ The js-runner can also be used as a remote runner. To do this, start the runner server using `npx js-runner-server ./server.ttl`.
38
+ This starts the remote server as configured in `server.ttl`
39
+
40
+ ```turtle
41
+ @prefix rdfc: <https://w3id.org/rdf-connect#>.
42
+
43
+ <> a rdfc:JsRunnerServer;
44
+ rdfc:port 3000;
45
+ # one or more processor definition files to host
46
+ rdfc:processorConfig <./processors.ttl>.
47
+ ```
48
+
49
+ This enables the user to configure the pipeline just like a normal pipeline. The runner definition is automatically available at `localhost:{PORT}`.
50
+
51
+ ```turtle
52
+ @prefix owl: <http://www.w3.org/2002/07/owl#>.
53
+ @prefix rdfc: <https://w3id.org/rdf-connect#>.
54
+
55
+ # the endpoint serving the example configuration
56
+ @prefix runner: <http://localhost:3000/>.
57
+
58
+ # import the runner and the processor definitions
59
+ <> owl:imports runner:, runner:processors.ttl.
60
+
61
+ # setup the pipeline
62
+ <> a rdfc:Pipeline;
63
+ rdfc:consistsOf [
64
+ rdfc:processor <logProc>, <sendProc>;
65
+ rdfc:instantiates runner:runner;
66
+ ].
67
+ ```
68
+
69
+ There is an example in `./examples/echo`, start the server with `npx js-runner-server ./server.ttl` and run the pipeline `npx rdfc ./remote_pipeline.ttl`.
70
+
31
71
  ## Logging
32
72
 
33
73
  The JavaScript runner and processors use the `winston` logging library for logging.
@@ -86,7 +126,7 @@ JavaScript/TypeScript processors must include the JavaScript specific configurat
86
126
 
87
127
  The JavaScript runner is implemented in TypeScript.
88
128
  The source code is contained in the `src` folder.
89
- The main cli entry point is the `bin/runner.js` file, which you can also run after installation of the package using `npx js-runner`.
129
+ The main cli entry points are the `bin/runner.js` and `bin/server.js` files, which you can also run after installation of the package using `npx js-runner` and `npx js-runner-server` respectively.
90
130
 
91
131
  If you want to get started with the development of the js-runner, you can clone the repository and install the dependencies using the following commands.
92
132
 
@@ -70,12 +70,11 @@ describe('EchoProcessor', () => {
70
70
 
71
71
  const msgs: string[] = []
72
72
 
73
- ; (async () => {
74
- for await (const m of outputReader.strings()) {
75
- msgs.push(m)
76
- }
77
- })()
78
-
73
+ ;(async () => {
74
+ for await (const m of outputReader.strings()) {
75
+ msgs.push(m)
76
+ }
77
+ })()
79
78
 
80
79
  await inputWriter.string('Hello')
81
80
  expect(msgs).toEqual(['Hello'])
@@ -107,13 +106,13 @@ describe('EchoProcessor', () => {
107
106
 
108
107
  const msgs: string[] = []
109
108
 
110
- ; (async () => {
111
- for await (const m of outputReader.strings()) {
112
- msgs.push(m)
113
- }
114
- })()
109
+ ;(async () => {
110
+ for await (const m of outputReader.strings()) {
111
+ msgs.push(m)
112
+ }
113
+ })()
115
114
 
116
- const gen = async function*() {
115
+ const gen = async function* () {
117
116
  yield encoder.encode('Hello')
118
117
  yield encoder.encode('World')
119
118
  }
package/bin/runner.js CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  import { start } from '../lib/client.js'
4
4
 
5
+ // One-shot CLI mode: connect to an existing orchestrator, run processors, then exit.
6
+ // process.exit is needed because grpc-js keeps the event loop alive after client.close().
5
7
  const host = process.argv[2]
6
8
  const uri = process.argv[3]
7
-
8
9
  start(host, uri)
10
+ .then(() => process.exit(0))
11
+ .catch((err) => {
12
+ console.error(err)
13
+ process.exit(1)
14
+ })
package/bin/server.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { serve } from '../lib/server.js'
4
+
5
+ const configPath = process.argv[2]
6
+ if (!configPath) {
7
+ console.error('Usage: js-runner-server <config>')
8
+ process.exit(1)
9
+ }
10
+ serve(configPath).catch((err) => {
11
+ console.error(err)
12
+ process.exit(1)
13
+ })