@apibara/protocol 0.4.7 → 0.4.9
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/dist/client.d.ts +9 -9
- package/dist/client.js +26 -14
- package/dist/client.js.map +1 -1
- package/dist/cursor.d.ts +15 -2
- package/dist/cursor.js +26 -2
- package/dist/cursor.js.map +1 -1
- package/dist/cursor.test.d.ts +1 -0
- package/dist/cursor.test.js +22 -0
- package/dist/cursor.test.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js.map +1 -1
- package/dist/proto/apibara/node/v1alpha2/Data.d.ts +3 -3
- package/dist/proto/apibara/node/v1alpha2/DataFinality.d.ts +8 -6
- package/dist/proto/apibara/node/v1alpha2/DataFinality.js +6 -7
- package/dist/proto/apibara/node/v1alpha2/DataFinality.js.map +1 -1
- package/dist/proto/apibara/node/v1alpha2/StreamDataRequest.d.ts +3 -3
- package/dist/proto/index.d.ts +1 -1
- package/dist/proto/index.js.map +1 -1
- package/dist/proto/stream.d.ts +1 -1
- package/dist/proto/testing.d.ts +1 -1
- package/dist/proto/testing.js +4 -2
- package/dist/proto/testing.js.map +1 -1
- package/dist/proto/v1alpha2.d.ts +9 -9
- package/dist/proto/v1alpha2.js +1 -1
- package/dist/proto/v1alpha2.js.map +1 -1
- package/dist/request.d.ts +2 -2
- package/dist/request.js +1 -0
- package/dist/request.js.map +1 -1
- package/dist/request.test.js +9 -10
- package/dist/request.test.js.map +1 -1
- package/package.json +4 -3
- package/src/client.ts +118 -97
- package/src/cursor.test.ts +21 -0
- package/src/cursor.ts +35 -7
- package/src/index.ts +4 -4
- package/src/proto/apibara/node/v1alpha2/Data.ts +3 -3
- package/src/proto/apibara/node/v1alpha2/DataFinality.ts +18 -6
- package/src/proto/apibara/node/v1alpha2/StreamDataRequest.ts +3 -3
- package/src/proto/index.ts +1 -1
- package/src/proto/testing.ts +5 -5
- package/src/proto/v1alpha2.ts +16 -14
- package/src/request.test.ts +19 -20
- package/src/request.ts +16 -16
package/src/request.test.ts
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import { v1alpha2 } from
|
|
2
|
-
import { TestFilter } from
|
|
3
|
-
import { StreamDataRequest } from
|
|
1
|
+
import { v1alpha2 } from "./proto";
|
|
2
|
+
import { TestFilter } from "./proto/testing";
|
|
3
|
+
import { StreamDataRequest } from "./request";
|
|
4
4
|
|
|
5
|
-
describe(
|
|
6
|
-
it(
|
|
7
|
-
const filter = new TestFilter(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
})
|
|
5
|
+
describe("RequestBuilder", () => {
|
|
6
|
+
it("returns the final request", () => {
|
|
7
|
+
const filter = new TestFilter();
|
|
8
|
+
filter.num = 123;
|
|
9
|
+
filter.text = "abcdef";
|
|
11
10
|
|
|
12
11
|
const request = StreamDataRequest.create()
|
|
13
12
|
.withBatchSize(10)
|
|
14
13
|
.withFilter(TestFilter.encode(filter).finish())
|
|
15
14
|
.withFinality(v1alpha2.DataFinality.DATA_STATUS_FINALIZED)
|
|
16
|
-
.encode()
|
|
15
|
+
.encode();
|
|
17
16
|
|
|
18
|
-
expect(request.batchSize).toEqual(10)
|
|
19
|
-
expect(request.filter).toBeInstanceOf(Buffer)
|
|
20
|
-
expect(request.filter?.length).toEqual(10)
|
|
17
|
+
expect(request.batchSize).toEqual(10);
|
|
18
|
+
expect(request.filter).toBeInstanceOf(Buffer);
|
|
19
|
+
expect(request.filter?.length).toEqual(10);
|
|
21
20
|
|
|
22
21
|
// make ts happy
|
|
23
|
-
if (!request.filter || typeof request.filter
|
|
24
|
-
throw new Error(
|
|
22
|
+
if (!request.filter || typeof request.filter === "string") {
|
|
23
|
+
throw new Error("undefined filter");
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
const back = TestFilter.decode(request.filter)
|
|
28
|
-
expect(back.num.toString()).toEqual(
|
|
29
|
-
expect(back.text).toEqual(
|
|
30
|
-
})
|
|
31
|
-
})
|
|
26
|
+
const back = TestFilter.decode(request.filter);
|
|
27
|
+
expect(back.num.toString()).toEqual("123");
|
|
28
|
+
expect(back.text).toEqual("abcdef");
|
|
29
|
+
});
|
|
30
|
+
});
|
package/src/request.ts
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import Long from
|
|
2
|
-
import { v1alpha2 } from
|
|
1
|
+
import Long from "long";
|
|
2
|
+
import { v1alpha2 } from "./proto";
|
|
3
3
|
|
|
4
4
|
export const StreamDataRequest = {
|
|
5
5
|
/**
|
|
6
6
|
* Start building a `StreamData` request.
|
|
7
7
|
*/
|
|
8
8
|
create: () => new StreamDataRequestBuilder(),
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
10
|
|
|
11
11
|
export class StreamDataRequestBuilder {
|
|
12
|
-
private request: v1alpha2.IStreamDataRequest
|
|
12
|
+
private request: v1alpha2.IStreamDataRequest;
|
|
13
13
|
|
|
14
14
|
constructor() {
|
|
15
|
-
this.request = {}
|
|
15
|
+
this.request = {};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Set the new stream id.
|
|
20
20
|
*/
|
|
21
21
|
withStreamId(streamId: number | Long) {
|
|
22
|
-
this.request.streamId = streamId
|
|
23
|
-
return this
|
|
22
|
+
this.request.streamId = streamId;
|
|
23
|
+
return this;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Set the number of items in each response batch.
|
|
28
28
|
*/
|
|
29
29
|
withBatchSize(size: number | Long) {
|
|
30
|
-
this.request.batchSize = size
|
|
31
|
-
return this
|
|
30
|
+
this.request.batchSize = size;
|
|
31
|
+
return this;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Set the cursor from where to resume streaming.
|
|
36
36
|
*/
|
|
37
37
|
withStartingCursor(cursor: v1alpha2.ICursor) {
|
|
38
|
-
this.request.startingCursor = cursor
|
|
39
|
-
return this
|
|
38
|
+
this.request.startingCursor = cursor;
|
|
39
|
+
return this;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Set the request finality for data.
|
|
44
44
|
*/
|
|
45
45
|
withFinality(finality: v1alpha2.DataFinality) {
|
|
46
|
-
this.request.finality = finality
|
|
47
|
-
return this
|
|
46
|
+
this.request.finality = finality;
|
|
47
|
+
return this;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Set the stream-specific filter.
|
|
52
52
|
*/
|
|
53
53
|
withFilter(filter: Uint8Array) {
|
|
54
|
-
this.request.filter = filter
|
|
55
|
-
return this
|
|
54
|
+
this.request.filter = filter;
|
|
55
|
+
return this;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Build and return the request.
|
|
60
60
|
*/
|
|
61
61
|
encode() {
|
|
62
|
-
return this.request
|
|
62
|
+
return this.request;
|
|
63
63
|
}
|
|
64
64
|
}
|