@rdfc/js-runner 1.0.0-alpha.6 → 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) });
@@ -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");
@@ -44,24 +43,16 @@ export class ChannelFactory {
44
43
  if (c.channel.id.termType === "NamedNode") {
45
44
  if (!this.jsChannelsNamedNodes[id]) {
46
45
  this.jsChannelsNamedNodes[id] =
47
- new SimpleStream(undefined, c.id);
46
+ new SimpleStream();
48
47
  }
49
- const out = this.jsChannelsNamedNodes[id];
50
- if (out.id) {
51
- out.setName(out.id.value);
52
- }
53
- return out;
48
+ return this.jsChannelsNamedNodes[id];
54
49
  }
55
50
  if (c.channel.id.termType === "BlankNode") {
56
51
  if (!this.jsChannelsBlankNodes[id]) {
57
52
  this.jsChannelsBlankNodes[id] =
58
- new SimpleStream(undefined, c.id);
53
+ new SimpleStream();
59
54
  }
60
- const out = this.jsChannelsBlankNodes[id];
61
- if (out.id) {
62
- out.setName(out.id.value);
63
- }
64
- return out;
55
+ return this.jsChannelsBlankNodes[id];
65
56
  }
66
57
  throw "Should have found a thing";
67
58
  }
@@ -97,14 +88,14 @@ export class ChannelFactory {
97
88
  if (c.channel.id.termType === "NamedNode") {
98
89
  if (!this.jsChannelsNamedNodes[id]) {
99
90
  this.jsChannelsNamedNodes[id] =
100
- new SimpleStream(undefined, c.id);
91
+ new SimpleStream();
101
92
  }
102
93
  return this.jsChannelsNamedNodes[id];
103
94
  }
104
95
  if (c.channel.id.termType === "BlankNode") {
105
96
  if (!this.jsChannelsBlankNodes[id]) {
106
97
  this.jsChannelsBlankNodes[id] =
107
- new SimpleStream(undefined, c.id);
98
+ new SimpleStream();
108
99
  }
109
100
  return this.jsChannelsBlankNodes[id];
110
101
  }
@@ -123,15 +114,8 @@ export class SimpleStream {
123
114
  disconnect;
124
115
  lastElement;
125
116
  ended = false;
126
- name;
127
- id;
128
- constructor(onDisconnect, id) {
117
+ constructor(onDisconnect) {
129
118
  this.disconnect = onDisconnect || (async () => { });
130
- this.id = id;
131
- }
132
- setName(name) {
133
- console.log("setting name", name);
134
- this.name = name;
135
119
  }
136
120
  data(listener) {
137
121
  this.dataHandlers.push(listener);
@@ -142,16 +126,7 @@ export class SimpleStream {
142
126
  throw new Error("Trying to push to a stream that has ended!");
143
127
  }
144
128
  this.lastElement = data;
145
- for (const handler of this.dataHandlers) {
146
- let idx = 0;
147
- if (this.name) {
148
- idx = profiler.start(this.name);
149
- }
150
- await handler(data);
151
- if (this.name) {
152
- profiler.stop(idx);
153
- }
154
- }
129
+ await Promise.all(this.dataHandlers.map((handler) => handler(data)));
155
130
  }
156
131
  async end() {
157
132
  await this.disconnect();