@rdfc/js-runner 1.0.0-alpha.7 → 1.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.
package/bin/js-runner.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  import { jsRunner } from "../dist/index.js";
3
3
 
4
- jsRunner().catch((e) => { console.error("Error:", e); console.error(e.stack); });
4
+ jsRunner().catch((e) => { console.error("Error:", e); console.error(e.stack) });
@@ -10,11 +10,11 @@ export interface Config<T> {
10
10
  config: T;
11
11
  }
12
12
  export type ReaderConstructor<C> = (config: C) => {
13
- reader: SimpleStream<string | Buffer>;
13
+ reader: Stream<string | Buffer>;
14
14
  init: () => Promise<void>;
15
15
  };
16
16
  export type WriterConstructor<C> = (config: C) => {
17
- writer: SimpleStream<string | Buffer>;
17
+ writer: Writer<string | Buffer>;
18
18
  init: () => Promise<void>;
19
19
  };
20
20
  export declare const JsOntology: import("@treecg/types").Namespace<("JsProcess" | "JsChannel" | "JsReaderChannel" | "JsWriterChannel")[], NamedNode<string>, string>;
@@ -45,10 +45,7 @@ export declare class SimpleStream<T> implements Stream<T> {
45
45
  readonly disconnect: () => Promise<void>;
46
46
  lastElement?: T | undefined;
47
47
  private ended;
48
- private name?;
49
- readonly id?: Term;
50
- constructor(onDisconnect?: () => Promise<void>, id?: Term);
51
- setName(name: string): void;
48
+ constructor(onDisconnect?: () => Promise<void>);
52
49
  data(listener: Handler<T>): this;
53
50
  push(data: T): Promise<void>;
54
51
  end(): Promise<void>;
@@ -7,7 +7,6 @@ import { startKafkaStreamReader, startKafkaStreamWriter, } from "./connectors/ka
7
7
  export * from "./connectors/kafka.js";
8
8
  import { startHttpStreamReader, startHttpStreamWriter, } from "./connectors/http.js";
9
9
  import { LOG } from "./util.js";
10
- import { profiler } from "./profiling.js";
11
10
  export * from "./connectors/http.js";
12
11
  export const Conn = createTermNamespace("https://w3id.org/conn#", "FileReaderChannel", "FileWriterChannel", "HttpReaderChannel", "HttpWriterChannel", "KafkaReaderChannel", "KafkaWriterChannel", "WsReaderChannel", "WsWriterChannel", "WriterChannel", "ReaderChannel");
13
12
  export const JsOntology = createTermNamespace("https://w3id.org/conn/js#", "JsProcess", "JsChannel", "JsReaderChannel", "JsWriterChannel");
@@ -19,25 +18,21 @@ export class ChannelFactory {
19
18
  LOG.channel("Creating reader %s: a %s", config.id.value, config.ty.value);
20
19
  if (config.ty.equals(Conn.FileReaderChannel)) {
21
20
  const { reader, init } = startFileStreamReader(config.config);
22
- reader.setName(config.id.value);
23
21
  this.inits.push(init);
24
22
  return reader;
25
23
  }
26
24
  if (config.ty.equals(Conn.WsReaderChannel)) {
27
25
  const { reader, init } = startWsStreamReader(config.config);
28
- reader.setName(config.id.value);
29
26
  this.inits.push(init);
30
27
  return reader;
31
28
  }
32
29
  if (config.ty.equals(Conn.KafkaReaderChannel)) {
33
30
  const { reader, init } = startKafkaStreamReader(config.config);
34
- reader.setName(config.id.value);
35
31
  this.inits.push(init);
36
32
  return reader;
37
33
  }
38
34
  if (config.ty.equals(Conn.HttpReaderChannel)) {
39
35
  const { reader, init } = startHttpStreamReader(config.config);
40
- reader.setName(config.id.value);
41
36
  this.inits.push(init);
42
37
  return reader;
43
38
  }
@@ -48,24 +43,16 @@ export class ChannelFactory {
48
43
  if (c.channel.id.termType === "NamedNode") {
49
44
  if (!this.jsChannelsNamedNodes[id]) {
50
45
  this.jsChannelsNamedNodes[id] =
51
- new SimpleStream(undefined, c.id);
46
+ new SimpleStream();
52
47
  }
53
- const out = this.jsChannelsNamedNodes[id];
54
- if (out.id) {
55
- out.setName(out.id.value);
56
- }
57
- return out;
48
+ return this.jsChannelsNamedNodes[id];
58
49
  }
59
50
  if (c.channel.id.termType === "BlankNode") {
60
51
  if (!this.jsChannelsBlankNodes[id]) {
61
52
  this.jsChannelsBlankNodes[id] =
62
- new SimpleStream(undefined, c.id);
53
+ new SimpleStream();
63
54
  }
64
- const out = this.jsChannelsBlankNodes[id];
65
- if (out.id) {
66
- out.setName(out.id.value);
67
- }
68
- return out;
55
+ return this.jsChannelsBlankNodes[id];
69
56
  }
70
57
  throw "Should have found a thing";
71
58
  }
@@ -101,14 +88,14 @@ export class ChannelFactory {
101
88
  if (c.channel.id.termType === "NamedNode") {
102
89
  if (!this.jsChannelsNamedNodes[id]) {
103
90
  this.jsChannelsNamedNodes[id] =
104
- new SimpleStream(undefined, c.id);
91
+ new SimpleStream();
105
92
  }
106
93
  return this.jsChannelsNamedNodes[id];
107
94
  }
108
95
  if (c.channel.id.termType === "BlankNode") {
109
96
  if (!this.jsChannelsBlankNodes[id]) {
110
97
  this.jsChannelsBlankNodes[id] =
111
- new SimpleStream(undefined, c.id);
98
+ new SimpleStream();
112
99
  }
113
100
  return this.jsChannelsBlankNodes[id];
114
101
  }
@@ -127,15 +114,8 @@ export class SimpleStream {
127
114
  disconnect;
128
115
  lastElement;
129
116
  ended = false;
130
- name;
131
- id;
132
- constructor(onDisconnect, id) {
117
+ constructor(onDisconnect) {
133
118
  this.disconnect = onDisconnect || (async () => { });
134
- this.id = id;
135
- }
136
- setName(name) {
137
- console.log("setting name", name);
138
- this.name = name;
139
119
  }
140
120
  data(listener) {
141
121
  this.dataHandlers.push(listener);
@@ -146,16 +126,7 @@ export class SimpleStream {
146
126
  throw new Error("Trying to push to a stream that has ended!");
147
127
  }
148
128
  this.lastElement = data;
149
- for (const handler of this.dataHandlers) {
150
- let idx = 0;
151
- if (this.name) {
152
- idx = profiler.start(this.name);
153
- }
154
- await handler(data);
155
- if (this.name) {
156
- profiler.stop(idx);
157
- }
158
- }
129
+ await Promise.all(this.dataHandlers.map((handler) => handler(data)));
159
130
  }
160
131
  async end() {
161
132
  await this.disconnect();