@rdfc/js-runner 2.0.0 → 3.0.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.
Files changed (70) hide show
  1. package/.editorconfig +9 -0
  2. package/.github/renovate.json +3 -0
  3. package/README.md +127 -3
  4. package/__tests__/channels.test.ts +131 -74
  5. package/__tests__/echoProcessor.test.ts +131 -0
  6. package/__tests__/testProcessor.test.ts +69 -0
  7. package/eslint.config.mjs +1 -1
  8. package/examples/echo/.idea/echo.iml +9 -0
  9. package/examples/echo/.idea/misc.xml +6 -0
  10. package/{.idea → examples/echo/.idea}/modules.xml +1 -1
  11. package/examples/echo/.idea/vcs.xml +7 -0
  12. package/examples/echo/.swls/config.json +1 -0
  13. package/examples/echo/index.ttl +3 -0
  14. package/examples/echo/minimal.ttl +90 -0
  15. package/examples/echo/shacl.ttl +9 -0
  16. package/examples/echo/shape.ttl +1339 -0
  17. package/examples/echo/test.ttl +11 -0
  18. package/examples/echo/untitled:/types/MyType.ttl +0 -0
  19. package/file:/home/silvius/Projects/mumo-pipeline/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +3 -0
  20. package/index.ttl +3 -31
  21. package/ldes/http_3A_2F_2Fdata.mumo.be_2Fstreams_2Fnodes_2Fdefault/root/index.trig +3 -0
  22. package/lib/client.js +6 -9
  23. package/lib/logger.d.ts +2 -2
  24. package/lib/logger.js +3 -3
  25. package/lib/reader.d.ts +8 -6
  26. package/lib/reader.js +135 -25
  27. package/lib/runner.d.ts +10 -5
  28. package/lib/runner.js +86 -46
  29. package/lib/testUtils/duplex.d.ts +25 -0
  30. package/lib/testUtils/duplex.js +70 -0
  31. package/lib/testUtils/index.d.ts +51 -0
  32. package/lib/testUtils/index.js +243 -0
  33. package/lib/tsconfig.tsbuildinfo +1 -1
  34. package/lib/writer.d.ts +12 -5
  35. package/lib/writer.js +66 -13
  36. package/minimal.ttl +99 -0
  37. package/package.json +3 -3
  38. package/src/client.ts +8 -11
  39. package/src/logger.ts +3 -3
  40. package/src/reader.ts +207 -29
  41. package/src/runner.ts +128 -65
  42. package/src/testUtils/duplex.ts +112 -0
  43. package/src/testUtils/index.ts +430 -0
  44. package/src/writer.ts +106 -16
  45. package/.idea/LNKD.tech Editor.xml +0 -194
  46. package/.idea/codeStyles/Project.xml +0 -52
  47. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  48. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  49. package/.idea/js-runner.iml +0 -12
  50. package/.idea/vcs.xml +0 -6
  51. package/dist/args.d.ts +0 -4
  52. package/dist/args.js +0 -58
  53. package/dist/connectors/file.d.ts +0 -15
  54. package/dist/connectors/file.js +0 -89
  55. package/dist/connectors/http.d.ts +0 -14
  56. package/dist/connectors/http.js +0 -82
  57. package/dist/connectors/kafka.d.ts +0 -48
  58. package/dist/connectors/kafka.js +0 -68
  59. package/dist/connectors/ws.d.ts +0 -10
  60. package/dist/connectors/ws.js +0 -72
  61. package/dist/connectors.d.ts +0 -73
  62. package/dist/connectors.js +0 -168
  63. package/dist/index.cjs +0 -732
  64. package/dist/index.d.ts +0 -42
  65. package/dist/index.js +0 -83
  66. package/dist/tsconfig.tsbuildinfo +0 -1
  67. package/dist/util.d.ts +0 -71
  68. package/dist/util.js +0 -92
  69. package/src/jsonld.ts +0 -220
  70. package/src/testUtils.ts +0 -196
package/src/testUtils.ts DELETED
@@ -1,196 +0,0 @@
1
- import { DataChunk, RunnerClient } from '@rdfc/proto'
2
- import * as grpc from '@grpc/grpc-js'
3
- import { ClientReadableStream } from '@grpc/grpc-js'
4
- import { ClientReadableStreamImpl, OrchestratorMessage } from './reexports'
5
- import { extractShapes } from 'rdf-lens'
6
- import { NamedNode, Parser, Writer } 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
- import { Processor } from './processor'
12
- import { FullProc, Runner } from './runner'
13
- import { Quad, Term } from '@rdfjs/types'
14
- import { createTermNamespace } from '@treecg/types'
15
- import { expect } from 'vitest'
16
-
17
- export async function getProcessorShape(
18
- baseIRI = process.cwd() + '/node_modules/@rdfc/js-runner/index.ttl',
19
- ) {
20
- const configFile = await readFile(baseIRI, { encoding: 'utf8' })
21
- const configQuads = new Parser().parse(configFile)
22
- const shapes = extractShapes(configQuads)
23
-
24
- return shapes
25
- }
26
-
27
- export class TestClient extends RunnerClient {
28
- next: (stream: ClientReadableStream<DataChunk>) => unknown
29
-
30
- constructor() {
31
- super('localhost:5400', grpc.credentials.createInsecure())
32
- }
33
-
34
- nextStream(): Promise<ClientReadableStream<DataChunk>> {
35
- return new Promise((res) => (this.next = res))
36
- }
37
-
38
- receiveStreamMessage(): ClientReadableStream<DataChunk> {
39
- const stream = new ClientReadableStreamImpl<DataChunk>((data: Buffer) => {
40
- return { data }
41
- })
42
- this.next(stream)
43
- return stream
44
- }
45
- }
46
-
47
- export async function one<T>(iter: AsyncIterable<T>): Promise<T | undefined> {
48
- for await (const item of iter) {
49
- return item
50
- }
51
- }
52
-
53
- export const client = new TestClient()
54
- export const uri = 'someUri'
55
- export const logger = createLogger({
56
- transports: new winston.transports.Console({
57
- level: process.env['DEBUG'] || 'info',
58
- }),
59
- })
60
-
61
- export function createWriter(iri = uri): [WriterInstance, ReaderInstance] {
62
- const reader = createReader(iri)
63
- const writeStream = new WriterInstance(
64
- iri,
65
- client,
66
- async (msg) => {
67
- if (msg.msg) {
68
- reader.handleMsg(msg.msg)
69
- }
70
- if (msg.close) {
71
- reader.close()
72
- }
73
- },
74
- logger,
75
- )
76
- return [writeStream, reader]
77
- }
78
-
79
- export function createReader(iri = uri): ReaderInstance {
80
- const reader = new ReaderInstance(iri, client, logger)
81
- return reader
82
- }
83
-
84
- const shapeQuads = `
85
- @prefix rdfc: <https://w3id.org/rdf-connect#>.
86
- @prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
87
- @prefix sh: <http://www.w3.org/ns/shacl#>.
88
- [ ] a sh:NodeShape;
89
- sh:targetClass <JsProcessorShape>;
90
- sh:property [
91
- sh:path rdfc:entrypoint;
92
- sh:name "location";
93
- sh:minCount 1;
94
- sh:maxCount 1;
95
- sh:datatype xsd:string;
96
- ], [
97
- sh:path rdfc:file;
98
- sh:name "file";
99
- sh:minCount 1;
100
- sh:maxCount 1;
101
- sh:datatype xsd:string;
102
- ], [
103
- sh:path rdfc:class;
104
- sh:name "clazz";
105
- sh:maxCount 1;
106
- sh:datatype xsd:string;
107
- ].
108
- `
109
- const OWL = createTermNamespace('http://www.w3.org/2002/07/owl#', 'imports')
110
- const processorShapes = extractShapes(new Parser().parse(shapeQuads))
111
- const base = 'https://w3id.org/rdf-connect#'
112
-
113
- export async function importFile(file: string): Promise<Quad[]> {
114
- const done = new Set<string>()
115
- const todo = [new URL('file://' + file)]
116
- const quads: Quad[] = []
117
-
118
- let item = todo.pop()
119
- while (item !== undefined) {
120
- if (done.has(item.toString())) {
121
- item = todo.pop()
122
- continue
123
- }
124
- done.add(item.toString())
125
- if (item.protocol !== 'file:') {
126
- throw 'No supported protocol ' + item.protocol
127
- }
128
-
129
- const txt = await readFile(item.pathname, { encoding: 'utf8' })
130
- const extras = new Parser({ baseIRI: item.toString() }).parse(txt)
131
-
132
- for (const o of extras
133
- .filter(
134
- (x) =>
135
- x.subject.value === item?.toString() &&
136
- x.predicate.equals(OWL.imports),
137
- )
138
- .map((x) => x.object.value)) {
139
- todo.push(new URL(o))
140
- }
141
- quads.push(...extras)
142
-
143
- item = todo.pop()
144
- }
145
-
146
- return quads
147
- }
148
-
149
- export async function getProc<T extends Processor<unknown>>(
150
- config: string,
151
- ty: string,
152
- configLocation: string,
153
- uri = 'http://example.com/ns#processor',
154
- ): Promise<FullProc<T>> {
155
- const configQuads = await importFile(configLocation)
156
- const procConfig = processorShapes.lenses['JsProcessorShape'].execute({
157
- id: new NamedNode(base + ty),
158
- quads: configQuads,
159
- })
160
-
161
- const msgs: OrchestratorMessage[] = []
162
- const write = async (x: OrchestratorMessage) => {
163
- msgs.push(x)
164
- }
165
- const runner = new Runner(
166
- new TestClient(),
167
- write,
168
- 'http://example.com/ns#',
169
- logger,
170
- )
171
- configQuads.push(...new Parser().parse(config))
172
- await runner.handleOrchMessage({
173
- pipeline: new Writer().quadsToString(configQuads),
174
- })
175
-
176
- const proc = await runner.addProcessor<T>({
177
- config: JSON.stringify(procConfig),
178
- arguments: '',
179
- uri,
180
- })
181
-
182
- return proc
183
- }
184
-
185
- export async function checkProcDefinition(file: string, n: string) {
186
- const quads = await importFile(file)
187
- const procConfig = <{ file: Term; location: string; clazz: string }>(
188
- processorShapes.lenses['JsProcessorShape'].execute({
189
- id: new NamedNode(base + n),
190
- quads: quads,
191
- })
192
- )
193
- expect(procConfig.file, n + ' has file').toBeDefined()
194
- expect(procConfig.location, n + ' has location').toBeDefined()
195
- expect(procConfig.clazz, n + ' has clazz').toBeDefined()
196
- }