@apibara/protocol 0.4.9 → 2.0.0-beta.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/CHANGELOG.md +103 -0
- package/buf.gen.yaml +14 -0
- package/build.config.ts +8 -0
- package/dist/index.d.mts +610 -0
- package/dist/index.d.ts +610 -4
- package/dist/index.mjs +1172 -0
- package/package.json +44 -24
- package/proto/common.proto +22 -0
- package/proto/stream.proto +83 -0
- package/proto/testing.proto +11 -0
- package/src/client.ts +113 -333
- package/src/common.test.ts +67 -0
- package/src/common.ts +65 -0
- package/src/config.ts +38 -0
- package/src/index.ts +10 -3
- package/src/proto/common.ts +279 -0
- package/src/proto/index.ts +3 -1
- package/src/proto/stream.ts +728 -17
- package/src/proto/testing.ts +143 -8
- package/src/rate.ts +54 -0
- package/src/status.test.ts +51 -0
- package/src/status.ts +22 -0
- package/src/stream.test-d.ts +33 -0
- package/src/stream.test.ts +238 -0
- package/src/stream.ts +128 -0
- package/src/testing/client.test.ts +71 -0
- package/src/testing/client.ts +49 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/mock.test.ts +35 -0
- package/src/testing/mock.ts +71 -0
- package/tsconfig.json +12 -0
- package/dist/client.d.ts +0 -130
- package/dist/client.js +0 -215
- package/dist/client.js.map +0 -1
- package/dist/cursor.d.ts +0 -35
- package/dist/cursor.js +0 -67
- package/dist/cursor.js.map +0 -1
- package/dist/cursor.test.d.ts +0 -1
- package/dist/cursor.test.js +0 -22
- package/dist/cursor.test.js.map +0 -1
- package/dist/index.js +0 -21
- package/dist/index.js.map +0 -1
- package/dist/proto/apibara/node/v1alpha2/Cursor.d.ts +0 -10
- package/dist/proto/apibara/node/v1alpha2/Cursor.js +0 -4
- package/dist/proto/apibara/node/v1alpha2/Cursor.js.map +0 -1
- package/dist/proto/apibara/node/v1alpha2/Data.d.ts +0 -15
- package/dist/proto/apibara/node/v1alpha2/Data.js +0 -4
- package/dist/proto/apibara/node/v1alpha2/Data.js.map +0 -1
- package/dist/proto/apibara/node/v1alpha2/DataFinality.d.ts +0 -8
- package/dist/proto/apibara/node/v1alpha2/DataFinality.js +0 -11
- package/dist/proto/apibara/node/v1alpha2/DataFinality.js.map +0 -1
- package/dist/proto/apibara/node/v1alpha2/Heartbeat.d.ts +0 -4
- package/dist/proto/apibara/node/v1alpha2/Heartbeat.js +0 -4
- package/dist/proto/apibara/node/v1alpha2/Heartbeat.js.map +0 -1
- package/dist/proto/apibara/node/v1alpha2/Invalidate.d.ts +0 -7
- package/dist/proto/apibara/node/v1alpha2/Invalidate.js +0 -4
- package/dist/proto/apibara/node/v1alpha2/Invalidate.js.map +0 -1
- package/dist/proto/apibara/node/v1alpha2/Stream.d.ts +0 -16
- package/dist/proto/apibara/node/v1alpha2/Stream.js +0 -4
- package/dist/proto/apibara/node/v1alpha2/Stream.js.map +0 -1
- package/dist/proto/apibara/node/v1alpha2/StreamDataRequest.d.ts +0 -24
- package/dist/proto/apibara/node/v1alpha2/StreamDataRequest.js +0 -4
- package/dist/proto/apibara/node/v1alpha2/StreamDataRequest.js.map +0 -1
- package/dist/proto/apibara/node/v1alpha2/StreamDataResponse.d.ts +0 -18
- package/dist/proto/apibara/node/v1alpha2/StreamDataResponse.js +0 -4
- package/dist/proto/apibara/node/v1alpha2/StreamDataResponse.js.map +0 -1
- package/dist/proto/index.d.ts +0 -1
- package/dist/proto/index.js +0 -28
- package/dist/proto/index.js.map +0 -1
- package/dist/proto/stream.d.ts +0 -25
- package/dist/proto/stream.js +0 -3
- package/dist/proto/stream.js.map +0 -1
- package/dist/proto/stream.proto +0 -76
- package/dist/proto/testing.d.ts +0 -5
- package/dist/proto/testing.js +0 -24
- package/dist/proto/testing.js.map +0 -1
- package/dist/proto/v1alpha2.d.ts +0 -11
- package/dist/proto/v1alpha2.js +0 -15
- package/dist/proto/v1alpha2.js.map +0 -1
- package/dist/request.d.ts +0 -36
- package/dist/request.js +0 -58
- package/dist/request.js.map +0 -1
- package/dist/request.test.d.ts +0 -1
- package/dist/request.test.js +0 -28
- package/dist/request.test.js.map +0 -1
- package/src/cursor.test.ts +0 -21
- package/src/cursor.ts +0 -67
- package/src/proto/apibara/node/v1alpha2/Cursor.ts +0 -13
- package/src/proto/apibara/node/v1alpha2/Data.ts +0 -18
- package/src/proto/apibara/node/v1alpha2/DataFinality.ts +0 -20
- package/src/proto/apibara/node/v1alpha2/Heartbeat.ts +0 -8
- package/src/proto/apibara/node/v1alpha2/Invalidate.ts +0 -11
- package/src/proto/apibara/node/v1alpha2/Stream.ts +0 -23
- package/src/proto/apibara/node/v1alpha2/StreamDataRequest.ts +0 -27
- package/src/proto/apibara/node/v1alpha2/StreamDataResponse.ts +0 -22
- package/src/proto/stream.proto +0 -76
- package/src/proto/v1alpha2.ts +0 -24
- package/src/request.test.ts +0 -30
- package/src/request.ts +0 -64
package/dist/request.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StreamDataRequestBuilder = exports.StreamDataRequest = void 0;
|
|
4
|
-
exports.StreamDataRequest = {
|
|
5
|
-
/**
|
|
6
|
-
* Start building a `StreamData` request.
|
|
7
|
-
*/
|
|
8
|
-
create: () => new StreamDataRequestBuilder(),
|
|
9
|
-
};
|
|
10
|
-
class StreamDataRequestBuilder {
|
|
11
|
-
request;
|
|
12
|
-
constructor() {
|
|
13
|
-
this.request = {};
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Set the new stream id.
|
|
17
|
-
*/
|
|
18
|
-
withStreamId(streamId) {
|
|
19
|
-
this.request.streamId = streamId;
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Set the number of items in each response batch.
|
|
24
|
-
*/
|
|
25
|
-
withBatchSize(size) {
|
|
26
|
-
this.request.batchSize = size;
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Set the cursor from where to resume streaming.
|
|
31
|
-
*/
|
|
32
|
-
withStartingCursor(cursor) {
|
|
33
|
-
this.request.startingCursor = cursor;
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Set the request finality for data.
|
|
38
|
-
*/
|
|
39
|
-
withFinality(finality) {
|
|
40
|
-
this.request.finality = finality;
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Set the stream-specific filter.
|
|
45
|
-
*/
|
|
46
|
-
withFilter(filter) {
|
|
47
|
-
this.request.filter = filter;
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Build and return the request.
|
|
52
|
-
*/
|
|
53
|
-
encode() {
|
|
54
|
-
return this.request;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.StreamDataRequestBuilder = StreamDataRequestBuilder;
|
|
58
|
-
//# sourceMappingURL=request.js.map
|
package/dist/request.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":";;;AAGa,QAAA,iBAAiB,GAAG;IAC/B;;OAEG;IACH,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,wBAAwB,EAAE;CAC7C,CAAC;AAEF,MAAa,wBAAwB;IAC3B,OAAO,CAA8B;IAE7C;QACE,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,QAAuB;QAClC,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,IAAmB;QAC/B,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,kBAAkB,CAAC,MAAwB;QACzC,IAAI,CAAC,OAAO,CAAC,cAAc,GAAG,MAAM,CAAC;QACrC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,QAA+B;QAC1C,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,MAAkB;QAC3B,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AArDD,4DAqDC"}
|
package/dist/request.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/request.test.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const proto_1 = require("./proto");
|
|
4
|
-
const testing_1 = require("./proto/testing");
|
|
5
|
-
const request_1 = require("./request");
|
|
6
|
-
describe("RequestBuilder", () => {
|
|
7
|
-
it("returns the final request", () => {
|
|
8
|
-
const filter = new testing_1.TestFilter();
|
|
9
|
-
filter.num = 123;
|
|
10
|
-
filter.text = "abcdef";
|
|
11
|
-
const request = request_1.StreamDataRequest.create()
|
|
12
|
-
.withBatchSize(10)
|
|
13
|
-
.withFilter(testing_1.TestFilter.encode(filter).finish())
|
|
14
|
-
.withFinality(proto_1.v1alpha2.DataFinality.DATA_STATUS_FINALIZED)
|
|
15
|
-
.encode();
|
|
16
|
-
expect(request.batchSize).toEqual(10);
|
|
17
|
-
expect(request.filter).toBeInstanceOf(Buffer);
|
|
18
|
-
expect(request.filter?.length).toEqual(10);
|
|
19
|
-
// make ts happy
|
|
20
|
-
if (!request.filter || typeof request.filter === "string") {
|
|
21
|
-
throw new Error("undefined filter");
|
|
22
|
-
}
|
|
23
|
-
const back = testing_1.TestFilter.decode(request.filter);
|
|
24
|
-
expect(back.num.toString()).toEqual("123");
|
|
25
|
-
expect(back.text).toEqual("abcdef");
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
//# sourceMappingURL=request.test.js.map
|
package/dist/request.test.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.test.js","sourceRoot":"","sources":["../src/request.test.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AACnC,6CAA6C;AAC7C,uCAA8C;AAE9C,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,MAAM,GAAG,IAAI,oBAAU,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;QACjB,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC;QAEvB,MAAM,OAAO,GAAG,2BAAiB,CAAC,MAAM,EAAE;aACvC,aAAa,CAAC,EAAE,CAAC;aACjB,UAAU,CAAC,oBAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;aAC9C,YAAY,CAAC,gBAAQ,CAAC,YAAY,CAAC,qBAAqB,CAAC;aACzD,MAAM,EAAE,CAAC;QAEZ,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACtC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAE3C,gBAAgB;QAChB,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,EAAE;YACzD,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;SACrC;QAED,MAAM,IAAI,GAAG,oBAAU,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/src/cursor.test.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import Long from "long";
|
|
2
|
-
import { Cursor } from "./cursor";
|
|
3
|
-
|
|
4
|
-
describe("Cursor", () => {
|
|
5
|
-
it("can be converted to and from javascript objects", () => {
|
|
6
|
-
const cursorObject = {
|
|
7
|
-
orderKey: "1234",
|
|
8
|
-
uniqueKey:
|
|
9
|
-
"0x05dd5e4f023a81a8daaf86b8bf3967b04276a89c81b840e8e55d658323854ad7",
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const cursor = Cursor.fromObject(cursorObject);
|
|
13
|
-
expect(cursor.orderKey).toEqual(Long.fromNumber(1234));
|
|
14
|
-
expect(cursor.uniqueKey).toHaveLength(32);
|
|
15
|
-
|
|
16
|
-
const back = Cursor.toObject(cursor);
|
|
17
|
-
|
|
18
|
-
expect(back?.orderKey).toEqual(cursorObject.orderKey);
|
|
19
|
-
expect(back?.uniqueKey).toEqual(cursorObject.uniqueKey);
|
|
20
|
-
});
|
|
21
|
-
});
|
package/src/cursor.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import Long from "long";
|
|
2
|
-
import { ICursor } from "./proto/v1alpha2";
|
|
3
|
-
|
|
4
|
-
export const Cursor = {
|
|
5
|
-
/**
|
|
6
|
-
* Creates a new cursor with only the `orderKey` set.
|
|
7
|
-
*
|
|
8
|
-
* Notice that this cursor does not uniquely identify a message in the stream
|
|
9
|
-
* and may result in missing information.
|
|
10
|
-
*/
|
|
11
|
-
createWithOrderKey: (order: string | number | Long): ICursor => {
|
|
12
|
-
return {
|
|
13
|
-
orderKey: Long.fromValue(order),
|
|
14
|
-
uniqueKey: new Uint8Array(),
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Creates a new cursor with both order and unique keys.
|
|
20
|
-
*
|
|
21
|
-
* This cursor uniquely identifies a message in the stream, even if it has
|
|
22
|
-
* been invalidated.
|
|
23
|
-
*/
|
|
24
|
-
create: (order: string | number | Long, unique: Uint8Array): ICursor => {
|
|
25
|
-
return {
|
|
26
|
-
orderKey: Long.fromValue(order),
|
|
27
|
-
uniqueKey: unique,
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Creates a new cursor from a plain Javascript object.
|
|
33
|
-
*/
|
|
34
|
-
fromObject({ orderKey, uniqueKey }: ReturnType<typeof _toObject>): ICursor {
|
|
35
|
-
return {
|
|
36
|
-
orderKey: Long.fromString(orderKey),
|
|
37
|
-
uniqueKey: Buffer.from(uniqueKey.slice(2), "hex"),
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Returns the cursor string representation.
|
|
43
|
-
*/
|
|
44
|
-
toString: (cursor?: ICursor | null): string | undefined => {
|
|
45
|
-
if (!cursor) return;
|
|
46
|
-
const { orderKey, uniqueKey } = _toObject(cursor);
|
|
47
|
-
return `${orderKey}/${uniqueKey}`;
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Returns the cursor as plain Javascript object.
|
|
52
|
-
*/
|
|
53
|
-
toObject: (
|
|
54
|
-
cursor?: ICursor | null,
|
|
55
|
-
): ReturnType<typeof _toObject> | undefined => {
|
|
56
|
-
if (!cursor) return;
|
|
57
|
-
return _toObject(cursor);
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
function _toObject(cursor: ICursor): { orderKey: string; uniqueKey: string } {
|
|
62
|
-
const hash = Buffer.from(cursor.uniqueKey).toString("hex");
|
|
63
|
-
return {
|
|
64
|
-
orderKey: cursor.orderKey.toString(),
|
|
65
|
-
uniqueKey: `0x${hash}`,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Original file: src/proto/stream.proto
|
|
2
|
-
|
|
3
|
-
import type { Long } from '@grpc/proto-loader';
|
|
4
|
-
|
|
5
|
-
export interface Cursor {
|
|
6
|
-
'orderKey'?: (number | string | Long);
|
|
7
|
-
'uniqueKey'?: (Buffer | Uint8Array | string);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface Cursor__Output {
|
|
11
|
-
'orderKey': (Long);
|
|
12
|
-
'uniqueKey': (Uint8Array);
|
|
13
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Original file: src/proto/stream.proto
|
|
2
|
-
|
|
3
|
-
import type { Cursor as _apibara_node_v1alpha2_Cursor, Cursor__Output as _apibara_node_v1alpha2_Cursor__Output } from '../../../apibara/node/v1alpha2/Cursor';
|
|
4
|
-
import type { DataFinality as _apibara_node_v1alpha2_DataFinality, DataFinality__Output as _apibara_node_v1alpha2_DataFinality__Output } from '../../../apibara/node/v1alpha2/DataFinality';
|
|
5
|
-
|
|
6
|
-
export interface Data {
|
|
7
|
-
'endCursor'?: (_apibara_node_v1alpha2_Cursor | null);
|
|
8
|
-
'finality'?: (_apibara_node_v1alpha2_DataFinality);
|
|
9
|
-
'data'?: (Buffer | Uint8Array | string)[];
|
|
10
|
-
'cursor'?: (_apibara_node_v1alpha2_Cursor | null);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface Data__Output {
|
|
14
|
-
'endCursor': (_apibara_node_v1alpha2_Cursor__Output | null);
|
|
15
|
-
'finality': (_apibara_node_v1alpha2_DataFinality__Output);
|
|
16
|
-
'data': (Uint8Array)[];
|
|
17
|
-
'cursor': (_apibara_node_v1alpha2_Cursor__Output | null);
|
|
18
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Original file: src/proto/stream.proto
|
|
2
|
-
|
|
3
|
-
export const DataFinality = {
|
|
4
|
-
DATA_STATUS_UNKNOWN: 'DATA_STATUS_UNKNOWN',
|
|
5
|
-
DATA_STATUS_PENDING: 'DATA_STATUS_PENDING',
|
|
6
|
-
DATA_STATUS_ACCEPTED: 'DATA_STATUS_ACCEPTED',
|
|
7
|
-
DATA_STATUS_FINALIZED: 'DATA_STATUS_FINALIZED',
|
|
8
|
-
} as const;
|
|
9
|
-
|
|
10
|
-
export type DataFinality =
|
|
11
|
-
| 'DATA_STATUS_UNKNOWN'
|
|
12
|
-
| 0
|
|
13
|
-
| 'DATA_STATUS_PENDING'
|
|
14
|
-
| 1
|
|
15
|
-
| 'DATA_STATUS_ACCEPTED'
|
|
16
|
-
| 2
|
|
17
|
-
| 'DATA_STATUS_FINALIZED'
|
|
18
|
-
| 3
|
|
19
|
-
|
|
20
|
-
export type DataFinality__Output = typeof DataFinality[keyof typeof DataFinality]
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Original file: src/proto/stream.proto
|
|
2
|
-
|
|
3
|
-
import type { Cursor as _apibara_node_v1alpha2_Cursor, Cursor__Output as _apibara_node_v1alpha2_Cursor__Output } from '../../../apibara/node/v1alpha2/Cursor';
|
|
4
|
-
|
|
5
|
-
export interface Invalidate {
|
|
6
|
-
'cursor'?: (_apibara_node_v1alpha2_Cursor | null);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface Invalidate__Output {
|
|
10
|
-
'cursor': (_apibara_node_v1alpha2_Cursor__Output | null);
|
|
11
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Original file: src/proto/stream.proto
|
|
2
|
-
|
|
3
|
-
import type * as grpc from '@grpc/grpc-js'
|
|
4
|
-
import type { MethodDefinition } from '@grpc/proto-loader'
|
|
5
|
-
import type { StreamDataRequest as _apibara_node_v1alpha2_StreamDataRequest, StreamDataRequest__Output as _apibara_node_v1alpha2_StreamDataRequest__Output } from '../../../apibara/node/v1alpha2/StreamDataRequest';
|
|
6
|
-
import type { StreamDataResponse as _apibara_node_v1alpha2_StreamDataResponse, StreamDataResponse__Output as _apibara_node_v1alpha2_StreamDataResponse__Output } from '../../../apibara/node/v1alpha2/StreamDataResponse';
|
|
7
|
-
|
|
8
|
-
export interface StreamClient extends grpc.Client {
|
|
9
|
-
StreamData(metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientDuplexStream<_apibara_node_v1alpha2_StreamDataRequest, _apibara_node_v1alpha2_StreamDataResponse__Output>;
|
|
10
|
-
StreamData(options?: grpc.CallOptions): grpc.ClientDuplexStream<_apibara_node_v1alpha2_StreamDataRequest, _apibara_node_v1alpha2_StreamDataResponse__Output>;
|
|
11
|
-
streamData(metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientDuplexStream<_apibara_node_v1alpha2_StreamDataRequest, _apibara_node_v1alpha2_StreamDataResponse__Output>;
|
|
12
|
-
streamData(options?: grpc.CallOptions): grpc.ClientDuplexStream<_apibara_node_v1alpha2_StreamDataRequest, _apibara_node_v1alpha2_StreamDataResponse__Output>;
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface StreamHandlers extends grpc.UntypedServiceImplementation {
|
|
17
|
-
StreamData: grpc.handleBidiStreamingCall<_apibara_node_v1alpha2_StreamDataRequest__Output, _apibara_node_v1alpha2_StreamDataResponse>;
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface StreamDefinition extends grpc.ServiceDefinition {
|
|
22
|
-
StreamData: MethodDefinition<_apibara_node_v1alpha2_StreamDataRequest, _apibara_node_v1alpha2_StreamDataResponse, _apibara_node_v1alpha2_StreamDataRequest__Output, _apibara_node_v1alpha2_StreamDataResponse__Output>
|
|
23
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Original file: src/proto/stream.proto
|
|
2
|
-
|
|
3
|
-
import type { Cursor as _apibara_node_v1alpha2_Cursor, Cursor__Output as _apibara_node_v1alpha2_Cursor__Output } from '../../../apibara/node/v1alpha2/Cursor';
|
|
4
|
-
import type { DataFinality as _apibara_node_v1alpha2_DataFinality, DataFinality__Output as _apibara_node_v1alpha2_DataFinality__Output } from '../../../apibara/node/v1alpha2/DataFinality';
|
|
5
|
-
import type { Long } from '@grpc/proto-loader';
|
|
6
|
-
|
|
7
|
-
export interface StreamDataRequest {
|
|
8
|
-
'streamId'?: (number | string | Long);
|
|
9
|
-
'batchSize'?: (number | string | Long);
|
|
10
|
-
'startingCursor'?: (_apibara_node_v1alpha2_Cursor | null);
|
|
11
|
-
'finality'?: (_apibara_node_v1alpha2_DataFinality);
|
|
12
|
-
'filter'?: (Buffer | Uint8Array | string);
|
|
13
|
-
'_streamId'?: "streamId";
|
|
14
|
-
'_batchSize'?: "batchSize";
|
|
15
|
-
'_finality'?: "finality";
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface StreamDataRequest__Output {
|
|
19
|
-
'streamId'?: (Long);
|
|
20
|
-
'batchSize'?: (Long);
|
|
21
|
-
'startingCursor': (_apibara_node_v1alpha2_Cursor__Output | null);
|
|
22
|
-
'finality'?: (_apibara_node_v1alpha2_DataFinality__Output);
|
|
23
|
-
'filter': (Uint8Array);
|
|
24
|
-
'_streamId': "streamId";
|
|
25
|
-
'_batchSize': "batchSize";
|
|
26
|
-
'_finality': "finality";
|
|
27
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Original file: src/proto/stream.proto
|
|
2
|
-
|
|
3
|
-
import type { Invalidate as _apibara_node_v1alpha2_Invalidate, Invalidate__Output as _apibara_node_v1alpha2_Invalidate__Output } from '../../../apibara/node/v1alpha2/Invalidate';
|
|
4
|
-
import type { Data as _apibara_node_v1alpha2_Data, Data__Output as _apibara_node_v1alpha2_Data__Output } from '../../../apibara/node/v1alpha2/Data';
|
|
5
|
-
import type { Heartbeat as _apibara_node_v1alpha2_Heartbeat, Heartbeat__Output as _apibara_node_v1alpha2_Heartbeat__Output } from '../../../apibara/node/v1alpha2/Heartbeat';
|
|
6
|
-
import type { Long } from '@grpc/proto-loader';
|
|
7
|
-
|
|
8
|
-
export interface StreamDataResponse {
|
|
9
|
-
'streamId'?: (number | string | Long);
|
|
10
|
-
'invalidate'?: (_apibara_node_v1alpha2_Invalidate | null);
|
|
11
|
-
'data'?: (_apibara_node_v1alpha2_Data | null);
|
|
12
|
-
'heartbeat'?: (_apibara_node_v1alpha2_Heartbeat | null);
|
|
13
|
-
'message'?: "invalidate"|"data"|"heartbeat";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface StreamDataResponse__Output {
|
|
17
|
-
'streamId': (Long);
|
|
18
|
-
'invalidate'?: (_apibara_node_v1alpha2_Invalidate__Output | null);
|
|
19
|
-
'data'?: (_apibara_node_v1alpha2_Data__Output | null);
|
|
20
|
-
'heartbeat'?: (_apibara_node_v1alpha2_Heartbeat__Output | null);
|
|
21
|
-
'message': "invalidate"|"data"|"heartbeat";
|
|
22
|
-
}
|
package/src/proto/stream.proto
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// Apibara Stream service.
|
|
2
|
-
syntax = "proto3";
|
|
3
|
-
|
|
4
|
-
package apibara.node.v1alpha2;
|
|
5
|
-
|
|
6
|
-
service Stream {
|
|
7
|
-
// Stream data from the node.
|
|
8
|
-
rpc StreamData(stream StreamDataRequest) returns (stream StreamDataResponse);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Request data to be streamed.
|
|
12
|
-
message StreamDataRequest {
|
|
13
|
-
// Used by the client to uniquely identify a stream.
|
|
14
|
-
// All streams use `stream_id = 0` by default.
|
|
15
|
-
optional uint64 stream_id = 1;
|
|
16
|
-
// How many items to send in a single response.
|
|
17
|
-
optional uint64 batch_size = 2;
|
|
18
|
-
// Start streaming from the provided cursor.
|
|
19
|
-
Cursor starting_cursor = 3;
|
|
20
|
-
// Return data with the specified finality.
|
|
21
|
-
// If not specified, defaults to `DATA_STATUS_ACCEPTED`.
|
|
22
|
-
optional DataFinality finality = 4;
|
|
23
|
-
// Return data according to the stream-specific filter.
|
|
24
|
-
bytes filter = 5;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Contains the data requested from the client.
|
|
28
|
-
message StreamDataResponse {
|
|
29
|
-
// The stream id.
|
|
30
|
-
uint64 stream_id = 1;
|
|
31
|
-
oneof message {
|
|
32
|
-
Invalidate invalidate = 2;
|
|
33
|
-
Data data = 3;
|
|
34
|
-
Heartbeat heartbeat = 4;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// A cursor over the stream content.
|
|
39
|
-
message Cursor {
|
|
40
|
-
// Key used for ordering messages in the stream.
|
|
41
|
-
uint64 order_key = 1;
|
|
42
|
-
// Key used to discriminate branches in the stream.
|
|
43
|
-
bytes unique_key = 2;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Data finality.
|
|
47
|
-
enum DataFinality {
|
|
48
|
-
DATA_STATUS_UNKNOWN = 0;
|
|
49
|
-
// Data was received, but is not part of the canonical chain yet.
|
|
50
|
-
DATA_STATUS_PENDING = 1;
|
|
51
|
-
// Data is now part of the canonical chain, but could still be invalidated.
|
|
52
|
-
DATA_STATUS_ACCEPTED = 2;
|
|
53
|
-
// Data is finalized and cannot be invalidated.
|
|
54
|
-
DATA_STATUS_FINALIZED = 3;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Invalidate data after the given cursor.
|
|
58
|
-
message Invalidate {
|
|
59
|
-
// The cursor of the message before the now invalid data.
|
|
60
|
-
Cursor cursor = 1;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// A batch of data.
|
|
64
|
-
message Data {
|
|
65
|
-
// Cursor of the last item in the batch.
|
|
66
|
-
Cursor end_cursor = 1;
|
|
67
|
-
// The finality status of the data in the batch.
|
|
68
|
-
DataFinality finality = 2;
|
|
69
|
-
// The stream data.
|
|
70
|
-
repeated bytes data = 3;
|
|
71
|
-
// Cursor used to produced the batch.
|
|
72
|
-
Cursor cursor = 4;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Sent to clients to check if stream is still connected.
|
|
76
|
-
message Heartbeat {}
|
package/src/proto/v1alpha2.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { loadPackageDefinition } from "@grpc/grpc-js";
|
|
2
|
-
import { loadSync } from "@grpc/proto-loader";
|
|
3
|
-
import { ProtoGrpcType } from "./stream";
|
|
4
|
-
|
|
5
|
-
const __NODE_PROTO_PATH = __dirname + "/stream.proto";
|
|
6
|
-
|
|
7
|
-
// export definitions
|
|
8
|
-
export const packageDefinition = loadSync(__NODE_PROTO_PATH, {
|
|
9
|
-
oneofs: true,
|
|
10
|
-
defaults: true,
|
|
11
|
-
});
|
|
12
|
-
export const protoDescriptor = loadPackageDefinition(
|
|
13
|
-
packageDefinition,
|
|
14
|
-
) as unknown as ProtoGrpcType;
|
|
15
|
-
|
|
16
|
-
// re-export all types, use same naming convention as protobufjs
|
|
17
|
-
export { Cursor__Output as ICursor } from "./apibara/node/v1alpha2/Cursor";
|
|
18
|
-
export { Data__Output as IData } from "./apibara/node/v1alpha2/Data";
|
|
19
|
-
export { DataFinality } from "./apibara/node/v1alpha2/DataFinality";
|
|
20
|
-
export { Heartbeat__Output as IHeartbeat } from "./apibara/node/v1alpha2/Heartbeat";
|
|
21
|
-
export { Invalidate__Output as IInvalidate } from "./apibara/node/v1alpha2/Invalidate";
|
|
22
|
-
export { StreamClient } from "./apibara/node/v1alpha2/Stream";
|
|
23
|
-
export { StreamDataRequest as IStreamDataRequest } from "./apibara/node/v1alpha2/StreamDataRequest";
|
|
24
|
-
export { StreamDataResponse__Output as IStreamDataResponse } from "./apibara/node/v1alpha2/StreamDataResponse";
|
package/src/request.test.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { v1alpha2 } from "./proto";
|
|
2
|
-
import { TestFilter } from "./proto/testing";
|
|
3
|
-
import { StreamDataRequest } from "./request";
|
|
4
|
-
|
|
5
|
-
describe("RequestBuilder", () => {
|
|
6
|
-
it("returns the final request", () => {
|
|
7
|
-
const filter = new TestFilter();
|
|
8
|
-
filter.num = 123;
|
|
9
|
-
filter.text = "abcdef";
|
|
10
|
-
|
|
11
|
-
const request = StreamDataRequest.create()
|
|
12
|
-
.withBatchSize(10)
|
|
13
|
-
.withFilter(TestFilter.encode(filter).finish())
|
|
14
|
-
.withFinality(v1alpha2.DataFinality.DATA_STATUS_FINALIZED)
|
|
15
|
-
.encode();
|
|
16
|
-
|
|
17
|
-
expect(request.batchSize).toEqual(10);
|
|
18
|
-
expect(request.filter).toBeInstanceOf(Buffer);
|
|
19
|
-
expect(request.filter?.length).toEqual(10);
|
|
20
|
-
|
|
21
|
-
// make ts happy
|
|
22
|
-
if (!request.filter || typeof request.filter === "string") {
|
|
23
|
-
throw new Error("undefined filter");
|
|
24
|
-
}
|
|
25
|
-
|
|
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
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import Long from "long";
|
|
2
|
-
import { v1alpha2 } from "./proto";
|
|
3
|
-
|
|
4
|
-
export const StreamDataRequest = {
|
|
5
|
-
/**
|
|
6
|
-
* Start building a `StreamData` request.
|
|
7
|
-
*/
|
|
8
|
-
create: () => new StreamDataRequestBuilder(),
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export class StreamDataRequestBuilder {
|
|
12
|
-
private request: v1alpha2.IStreamDataRequest;
|
|
13
|
-
|
|
14
|
-
constructor() {
|
|
15
|
-
this.request = {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Set the new stream id.
|
|
20
|
-
*/
|
|
21
|
-
withStreamId(streamId: number | Long) {
|
|
22
|
-
this.request.streamId = streamId;
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Set the number of items in each response batch.
|
|
28
|
-
*/
|
|
29
|
-
withBatchSize(size: number | Long) {
|
|
30
|
-
this.request.batchSize = size;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Set the cursor from where to resume streaming.
|
|
36
|
-
*/
|
|
37
|
-
withStartingCursor(cursor: v1alpha2.ICursor) {
|
|
38
|
-
this.request.startingCursor = cursor;
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Set the request finality for data.
|
|
44
|
-
*/
|
|
45
|
-
withFinality(finality: v1alpha2.DataFinality) {
|
|
46
|
-
this.request.finality = finality;
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Set the stream-specific filter.
|
|
52
|
-
*/
|
|
53
|
-
withFilter(filter: Uint8Array) {
|
|
54
|
-
this.request.filter = filter;
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Build and return the request.
|
|
60
|
-
*/
|
|
61
|
-
encode() {
|
|
62
|
-
return this.request;
|
|
63
|
-
}
|
|
64
|
-
}
|