@rdfc/js-runner 1.0.0 → 2.0.0-alpha.10
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.
- package/.husky/pre-commit +6 -0
- package/.idea/LNKD.tech Editor.xml +194 -0
- package/.idea/codeStyles/Project.xml +52 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/js-runner.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.prettierrc +4 -0
- package/README.md +3 -38
- package/__tests__/channels.test.ts +96 -0
- package/bin/runner.js +8 -0
- package/dist/args.d.ts +3 -3
- package/dist/args.js +50 -51
- package/dist/connectors/file.d.ts +11 -11
- package/dist/connectors/file.js +79 -79
- package/dist/connectors/http.d.ts +10 -10
- package/dist/connectors/http.js +76 -76
- package/dist/connectors/kafka.d.ts +36 -36
- package/dist/connectors/kafka.js +66 -62
- package/dist/connectors/ws.d.ts +6 -6
- package/dist/connectors/ws.js +66 -63
- package/dist/connectors.d.ts +61 -42
- package/dist/connectors.js +155 -132
- package/dist/index.cjs +650 -595
- package/dist/index.d.ts +40 -31
- package/dist/index.js +72 -63
- package/dist/util.d.ts +63 -35
- package/dist/util.js +80 -63
- package/eslint.config.mjs +21 -0
- package/examples/echo/package-lock.json +80 -0
- package/examples/echo/package.json +18 -0
- package/examples/echo/pipeline.ttl +48 -0
- package/examples/echo/processors.ttl +82 -0
- package/examples/echo/src/processors.ts +74 -0
- package/examples/echo/tsconfig.json +114 -0
- package/index.ttl +71 -0
- package/jest.config.js +2 -0
- package/lib/client.d.ts +1 -0
- package/lib/client.js +43 -0
- package/lib/convertor.d.ts +9 -0
- package/lib/convertor.js +51 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +8 -0
- package/lib/jsonld.d.ts +17 -0
- package/lib/jsonld.js +135 -0
- package/lib/logger.d.ts +17 -0
- package/lib/logger.js +49 -0
- package/lib/processor.d.ts +19 -0
- package/lib/processor.js +13 -0
- package/lib/reader.d.ts +30 -0
- package/lib/reader.js +101 -0
- package/lib/reexports.d.ts +3 -0
- package/lib/reexports.js +4 -0
- package/lib/runner.d.ts +26 -0
- package/lib/runner.js +121 -0
- package/lib/testUtils.d.ts +24 -0
- package/lib/testUtils.js +150 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/util_processors.d.ts +11 -0
- package/lib/util_processors.js +13 -0
- package/lib/writer.d.ts +26 -0
- package/lib/writer.js +57 -0
- package/package.json +49 -51
- package/src/client.ts +52 -0
- package/src/convertor.ts +59 -0
- package/src/index.ts +8 -0
- package/src/jsonld.ts +220 -0
- package/src/logger.ts +64 -0
- package/src/processor.ts +39 -0
- package/src/reader.ts +142 -0
- package/src/reexports.ts +6 -0
- package/src/runner.ts +197 -0
- package/src/testUtils.ts +196 -0
- package/src/util_processors.ts +20 -0
- package/src/writer.ts +90 -0
- package/tsconfig.json +33 -0
- package/vite.config.ts +10 -0
- package/LICENSE +0 -21
- package/bin/js-runner.js +0 -4
- package/channels/file.ttl +0 -37
- package/channels/http.ttl +0 -59
- package/channels/kafka.ttl +0 -98
- package/channels/ws.ttl +0 -33
- package/ontology.ttl +0 -169
- package/processor/echo.ttl +0 -38
- package/processor/resc.ttl +0 -34
- package/processor/send.ttl +0 -40
- package/processor/test.js +0 -35
package/dist/connectors/file.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import { createReadStream, openSync } from
|
|
2
|
-
import { appendFile, readFile, stat, writeFile } from
|
|
3
|
-
import { isAbsolute } from
|
|
4
|
-
import { watch } from
|
|
5
|
-
import { SimpleStream
|
|
1
|
+
import { createReadStream, openSync } from 'fs'
|
|
2
|
+
import { appendFile, readFile, stat, writeFile } from 'fs/promises'
|
|
3
|
+
import { isAbsolute } from 'path'
|
|
4
|
+
import { watch } from 'node:fs'
|
|
5
|
+
import { SimpleStream } from '../connectors.js'
|
|
6
6
|
async function getFileSize(path) {
|
|
7
|
-
|
|
7
|
+
return (await stat(path)).size
|
|
8
8
|
}
|
|
9
9
|
function readPart(path, start, end, encoding) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
return new Promise((res) => {
|
|
11
|
+
const stream = createReadStream(path, { encoding, start, end })
|
|
12
|
+
let buffer = ''
|
|
13
|
+
stream.on('data', (chunk) => {
|
|
14
|
+
buffer += chunk
|
|
15
|
+
})
|
|
16
|
+
stream.on('close', () => res(buffer))
|
|
17
|
+
})
|
|
18
18
|
}
|
|
19
19
|
function debounce(func, timeout = 100) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
let timer
|
|
21
|
+
return (...args) => {
|
|
22
|
+
clearTimeout(timer)
|
|
23
|
+
timer = setTimeout(() => {
|
|
24
|
+
func(...args)
|
|
25
|
+
}, timeout)
|
|
26
|
+
}
|
|
27
27
|
}
|
|
28
28
|
export const startFileStreamReader = (config) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
content = await readPart(path, currentPos, newSize, encoding);
|
|
51
|
-
currentPos = newSize;
|
|
52
|
-
}
|
|
53
|
-
await reader.push(content);
|
|
29
|
+
const path = isAbsolute(config.path)
|
|
30
|
+
? config.path
|
|
31
|
+
: `${process.cwd()}/${config.path}`
|
|
32
|
+
openSync(path, 'a+')
|
|
33
|
+
const encoding = config.encoding || 'utf-8'
|
|
34
|
+
const reader = new SimpleStream()
|
|
35
|
+
const init = async () => {
|
|
36
|
+
let currentPos = await getFileSize(path)
|
|
37
|
+
const watcher = watch(path, { encoding: 'utf-8' })
|
|
38
|
+
watcher.on(
|
|
39
|
+
'change',
|
|
40
|
+
debounce(async () => {
|
|
41
|
+
try {
|
|
42
|
+
let content
|
|
43
|
+
if (config.onReplace) {
|
|
44
|
+
content = await readFile(path, { encoding })
|
|
45
|
+
} else {
|
|
46
|
+
const newSize = await getFileSize(path)
|
|
47
|
+
if (newSize <= currentPos) {
|
|
48
|
+
currentPos = newSize
|
|
49
|
+
return
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
await reader.push(content);
|
|
51
|
+
content = await readPart(path, currentPos, newSize, encoding)
|
|
52
|
+
currentPos = newSize
|
|
53
|
+
}
|
|
54
|
+
await reader.push(content)
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (error.code === 'ENOENT') {
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
throw error
|
|
65
60
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
}),
|
|
62
|
+
)
|
|
63
|
+
if (config.onReplace && config.readFirstContent) {
|
|
64
|
+
const content = await readFile(path, { encoding })
|
|
65
|
+
await reader.push(content)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { reader, init }
|
|
69
|
+
}
|
|
69
70
|
export const startFileStreamWriter = (config) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
71
|
+
const path = isAbsolute(config.path)
|
|
72
|
+
? config.path
|
|
73
|
+
: `${process.cwd()}/${config.path}`
|
|
74
|
+
const encoding = config.encoding || 'utf-8'
|
|
75
|
+
const writer = new SimpleStream()
|
|
76
|
+
const init = async () => {
|
|
77
|
+
if (!config.onReplace) {
|
|
78
|
+
await writeFile(path, '', { encoding })
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
writer.push = async (item) => {
|
|
82
|
+
if (config.onReplace) {
|
|
83
|
+
await writeFile(path, item, { encoding })
|
|
84
|
+
} else {
|
|
85
|
+
await appendFile(path, item, { encoding })
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { writer, init }
|
|
89
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ReaderConstructor, WriterConstructor } from
|
|
1
|
+
import { ReaderConstructor, WriterConstructor } from '../connectors.js'
|
|
2
2
|
export interface HttpReaderConfig {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
endpoint: string
|
|
4
|
+
port: number
|
|
5
|
+
binary: boolean
|
|
6
|
+
waitHandled?: boolean
|
|
7
|
+
responseCode?: number
|
|
8
8
|
}
|
|
9
|
-
export declare const startHttpStreamReader: ReaderConstructor<HttpReaderConfig
|
|
9
|
+
export declare const startHttpStreamReader: ReaderConstructor<HttpReaderConfig>
|
|
10
10
|
export interface HttpWriterConfig {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
endpoint: string
|
|
12
|
+
method: string
|
|
13
13
|
}
|
|
14
|
-
export declare const startHttpStreamWriter: WriterConstructor<HttpWriterConfig
|
|
14
|
+
export declare const startHttpStreamWriter: WriterConstructor<HttpWriterConfig>
|
package/dist/connectors/http.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import * as http from
|
|
2
|
-
import { createServer } from
|
|
3
|
-
import { SimpleStream
|
|
1
|
+
import * as http from 'http'
|
|
2
|
+
import { createServer } from 'http'
|
|
3
|
+
import { SimpleStream } from '../connectors.js'
|
|
4
4
|
function streamToString(stream, binary) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
const datas = []
|
|
6
|
+
return new Promise((res) => {
|
|
7
|
+
stream.on('data', (data) => {
|
|
8
|
+
datas.push(data)
|
|
9
|
+
})
|
|
10
|
+
stream.on('end', () => {
|
|
11
|
+
const streamData = Buffer.concat(datas)
|
|
12
|
+
res(binary ? streamData : streamData.toString())
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
15
|
}
|
|
16
16
|
export const startHttpStreamReader = (config) => {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
let server = undefined
|
|
18
|
+
const stream = new SimpleStream(
|
|
19
|
+
() =>
|
|
20
|
+
new Promise((res) => {
|
|
19
21
|
if (server !== undefined) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
res();
|
|
26
|
-
}
|
|
27
|
-
}));
|
|
28
|
-
const requestListener = async function (req, res) {
|
|
29
|
-
try {
|
|
30
|
-
const content = await streamToString(req, config.binary);
|
|
31
|
-
const promise = stream.push(content).catch((error) => {
|
|
32
|
-
throw error;
|
|
33
|
-
});
|
|
34
|
-
if (config.waitHandled) {
|
|
35
|
-
await promise;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
console.error("Failed", error);
|
|
22
|
+
server.close(() => {
|
|
23
|
+
res()
|
|
24
|
+
})
|
|
25
|
+
} else {
|
|
26
|
+
res()
|
|
40
27
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
28
|
+
}),
|
|
29
|
+
)
|
|
30
|
+
const requestListener = async function (req, res) {
|
|
31
|
+
try {
|
|
32
|
+
const content = await streamToString(req, config.binary)
|
|
33
|
+
const promise = stream.push(content).catch((error) => {
|
|
34
|
+
throw error
|
|
35
|
+
})
|
|
36
|
+
if (config.waitHandled) {
|
|
37
|
+
await promise
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('Failed', error)
|
|
41
|
+
}
|
|
42
|
+
res.writeHead(config.responseCode || 200)
|
|
43
|
+
res.end('OK')
|
|
44
|
+
}
|
|
45
|
+
server = createServer(requestListener)
|
|
46
|
+
const init = () => {
|
|
47
|
+
return new Promise((res) => {
|
|
48
|
+
const cb = () => res(undefined)
|
|
49
|
+
if (server) {
|
|
50
|
+
server.listen(config.port, config.endpoint, cb)
|
|
51
|
+
} else {
|
|
52
|
+
cb()
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
return { reader: stream, init }
|
|
57
|
+
}
|
|
58
58
|
export const startHttpStreamWriter = (config) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
59
|
+
const requestConfig = new URL(config.endpoint)
|
|
60
|
+
const writer = new SimpleStream()
|
|
61
|
+
writer.push = async (item) => {
|
|
62
|
+
await new Promise((resolve) => {
|
|
63
|
+
const options = {
|
|
64
|
+
hostname: requestConfig.hostname,
|
|
65
|
+
path: requestConfig.path,
|
|
66
|
+
method: config.method,
|
|
67
|
+
port: requestConfig.port,
|
|
68
|
+
}
|
|
69
|
+
const cb = (response) => {
|
|
70
|
+
response.on('data', () => {})
|
|
71
|
+
response.on('end', () => {
|
|
72
|
+
resolve(null)
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
const req = http.request(options, cb)
|
|
76
|
+
req.write(item, () => {
|
|
77
|
+
req.end()
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
return { writer, init: async () => {} }
|
|
82
|
+
}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import type { ProducerConfig } from
|
|
2
|
-
import { ReaderConstructor, WriterConstructor } from
|
|
1
|
+
import type { ProducerConfig } from 'kafkajs'
|
|
2
|
+
import { ReaderConstructor, WriterConstructor } from '../connectors.js'
|
|
3
3
|
export interface SASLOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
mechanism: 'plain'
|
|
5
|
+
username: string
|
|
6
|
+
password: string
|
|
7
7
|
}
|
|
8
8
|
export interface BrokerConfig {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
hosts: string[]
|
|
10
|
+
ssl?: boolean
|
|
11
|
+
sasl?: SASLOptions
|
|
12
12
|
}
|
|
13
13
|
export interface ConsumerConfig {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
groupId: string
|
|
15
|
+
metadataMaxAge?: number
|
|
16
|
+
sessionTimeout?: number
|
|
17
|
+
rebalanceTimeout?: number
|
|
18
|
+
heartbeatInterval?: number
|
|
19
|
+
maxBytesPerPartition?: number
|
|
20
|
+
minBytes?: number
|
|
21
|
+
maxBytes?: number
|
|
22
|
+
maxWaitTimeInMs?: number
|
|
23
|
+
allowAutoTopicCreation?: boolean
|
|
24
|
+
maxInFlightRequests?: number
|
|
25
|
+
readUncommitted?: boolean
|
|
26
|
+
rackId?: string
|
|
27
27
|
}
|
|
28
28
|
export interface CSTopic {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
topic: string
|
|
30
|
+
fromBeginning?: boolean
|
|
31
31
|
}
|
|
32
32
|
export interface KafkaReaderConfig {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
topic: {
|
|
34
|
+
name: string
|
|
35
|
+
fromBeginning?: boolean
|
|
36
|
+
}
|
|
37
|
+
consumer: ConsumerConfig
|
|
38
|
+
broker: string | BrokerConfig
|
|
39
39
|
}
|
|
40
|
-
export declare const startKafkaStreamReader: ReaderConstructor<KafkaReaderConfig
|
|
40
|
+
export declare const startKafkaStreamReader: ReaderConstructor<KafkaReaderConfig>
|
|
41
41
|
export interface KafkaWriterConfig {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
topic: {
|
|
43
|
+
name: string
|
|
44
|
+
}
|
|
45
|
+
producer: ProducerConfig
|
|
46
|
+
broker: BrokerConfig | string
|
|
47
47
|
}
|
|
48
|
-
export declare const startKafkaStreamWriter: WriterConstructor<KafkaWriterConfig
|
|
48
|
+
export declare const startKafkaStreamWriter: WriterConstructor<KafkaWriterConfig>
|
package/dist/connectors/kafka.js
CHANGED
|
@@ -1,64 +1,68 @@
|
|
|
1
|
-
import { readFileSync } from
|
|
2
|
-
import { Kafka } from
|
|
3
|
-
import { SimpleStream
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { Kafka } from 'kafkajs'
|
|
3
|
+
import { SimpleStream } from '../connectors.js'
|
|
4
4
|
export const startKafkaStreamReader = (config) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
5
|
+
const brokerConfig = {}
|
|
6
|
+
if (typeof config.broker === 'string' || config.broker instanceof String) {
|
|
7
|
+
Object.assign(
|
|
8
|
+
brokerConfig,
|
|
9
|
+
JSON.parse(readFileSync(config.broker, 'utf-8')),
|
|
10
|
+
)
|
|
11
|
+
} else {
|
|
12
|
+
Object.assign(brokerConfig, config.broker)
|
|
13
|
+
}
|
|
14
|
+
if (brokerConfig && brokerConfig.hosts) {
|
|
15
|
+
brokerConfig.brokers = brokerConfig.hosts
|
|
16
|
+
}
|
|
17
|
+
const kafka = new Kafka(brokerConfig)
|
|
18
|
+
const consumer = kafka.consumer(config.consumer)
|
|
19
|
+
const stream = new SimpleStream(async () => {
|
|
20
|
+
await consumer.disconnect()
|
|
21
|
+
await consumer.stop()
|
|
22
|
+
})
|
|
23
|
+
const init = async () => {
|
|
24
|
+
await consumer.connect()
|
|
25
|
+
await consumer.subscribe({
|
|
26
|
+
topic: config.topic.name,
|
|
27
|
+
fromBeginning: config.topic.fromBeginning,
|
|
28
|
+
})
|
|
29
|
+
consumer
|
|
30
|
+
.run({
|
|
31
|
+
async eachMessage({ topic, message }) {
|
|
32
|
+
if (topic === config.topic.name) {
|
|
33
|
+
const element = message.value?.toString() ?? ''
|
|
34
|
+
await stream.push(element)
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
.catch((error) => {
|
|
39
|
+
throw error
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
return { reader: stream, init }
|
|
43
|
+
}
|
|
42
44
|
export const startKafkaStreamWriter = (config) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
45
|
+
const topic = config.topic.name
|
|
46
|
+
const brokerConfig = {}
|
|
47
|
+
if (typeof config.broker === 'string' || config.broker instanceof String) {
|
|
48
|
+
Object.assign(
|
|
49
|
+
brokerConfig,
|
|
50
|
+
JSON.parse(readFileSync(config.broker, 'utf-8')),
|
|
51
|
+
)
|
|
52
|
+
} else {
|
|
53
|
+
Object.assign(brokerConfig, config.broker)
|
|
54
|
+
}
|
|
55
|
+
if (brokerConfig && brokerConfig.hosts) {
|
|
56
|
+
brokerConfig.brokers = brokerConfig.hosts
|
|
57
|
+
}
|
|
58
|
+
const kafka = new Kafka(brokerConfig)
|
|
59
|
+
const producer = kafka.producer(config.producer)
|
|
60
|
+
const writer = new SimpleStream(async () => {
|
|
61
|
+
await producer.disconnect()
|
|
62
|
+
})
|
|
63
|
+
const init = () => producer.connect()
|
|
64
|
+
writer.push = async (item) => {
|
|
65
|
+
await producer.send({ topic, messages: [{ value: item }] })
|
|
66
|
+
}
|
|
67
|
+
return { writer, init }
|
|
68
|
+
}
|
package/dist/connectors/ws.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ReaderConstructor, WriterConstructor } from
|
|
1
|
+
import { ReaderConstructor, WriterConstructor } from '../connectors.js'
|
|
2
2
|
export interface WsWriterConfig {
|
|
3
|
-
|
|
3
|
+
url: string
|
|
4
4
|
}
|
|
5
5
|
export interface WsReaderConfig {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
host: string
|
|
7
|
+
port: number
|
|
8
8
|
}
|
|
9
|
-
export declare const startWsStreamReader: ReaderConstructor<WsReaderConfig
|
|
10
|
-
export declare const startWsStreamWriter: WriterConstructor<WsWriterConfig
|
|
9
|
+
export declare const startWsStreamReader: ReaderConstructor<WsReaderConfig>
|
|
10
|
+
export declare const startWsStreamWriter: WriterConstructor<WsWriterConfig>
|