@apibara/protocol 0.1.1 → 0.2.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/dist/buffer.d.ts +12 -0
- package/dist/buffer.js +22 -0
- package/dist/buffer.js.map +1 -0
- package/dist/client.d.ts +24 -0
- package/dist/client.js +35 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +3 -24
- package/dist/index.js +29 -31
- package/dist/index.js.map +1 -1
- package/dist/proto/apibara/node/v1alpha1/StreamMessagesRequest.d.ts +2 -0
- package/dist/proto/apibara/node/v1alpha1/StreamMessagesResponse.d.ts +4 -2
- package/dist/proto/index.d.ts +11 -0
- package/dist/proto/index.js +28 -0
- package/dist/proto/index.js.map +1 -0
- package/dist/proto/node.proto +3 -0
- package/package.json +1 -1
- package/src/buffer.ts +17 -0
- package/src/client.ts +41 -0
- package/src/index.ts +3 -41
- package/src/proto/apibara/node/v1alpha1/StreamMessagesRequest.ts +2 -0
- package/src/proto/apibara/node/v1alpha1/StreamMessagesResponse.ts +4 -2
- package/src/proto/index.ts +11 -0
- package/src/proto/node.proto +3 -0
- package/dist/node.proto +0 -96
package/dist/buffer.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Converts the hex-encoded bytes to a `Buffer`.
|
|
4
|
+
* @param hex The hex string
|
|
5
|
+
* @param size The buffer size, in bytes
|
|
6
|
+
*/
|
|
7
|
+
export declare function hexToBuffer(hex: string, size: number): Buffer;
|
|
8
|
+
/**
|
|
9
|
+
* Converts the buffer to its hex representation.
|
|
10
|
+
* @param buff the buffer
|
|
11
|
+
*/
|
|
12
|
+
export declare function bufferToHex(buff: Buffer): string;
|
package/dist/buffer.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bufferToHex = exports.hexToBuffer = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts the hex-encoded bytes to a `Buffer`.
|
|
6
|
+
* @param hex The hex string
|
|
7
|
+
* @param size The buffer size, in bytes
|
|
8
|
+
*/
|
|
9
|
+
function hexToBuffer(hex, size) {
|
|
10
|
+
const padSize = size * 2;
|
|
11
|
+
return Buffer.from(hex.replace('0x', '').padStart(padSize, '0'), 'hex');
|
|
12
|
+
}
|
|
13
|
+
exports.hexToBuffer = hexToBuffer;
|
|
14
|
+
/**
|
|
15
|
+
* Converts the buffer to its hex representation.
|
|
16
|
+
* @param buff the buffer
|
|
17
|
+
*/
|
|
18
|
+
function bufferToHex(buff) {
|
|
19
|
+
return '0x' + buff.toString('hex');
|
|
20
|
+
}
|
|
21
|
+
exports.bufferToHex = bufferToHex;
|
|
22
|
+
//# sourceMappingURL=buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,SAAgB,WAAW,CAAC,GAAW,EAAE,IAAY;IACnD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAA;IACxB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;AACzE,CAAC;AAHD,kCAGC;AAED;;;GAGG;AACH,SAAgB,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AACpC,CAAC;AAFD,kCAEC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ClientOptions, ChannelCredentials, ClientReadableStream } from '@grpc/grpc-js';
|
|
2
|
+
import { NodeClient as GrpcNodeClient } from './proto/apibara/node/v1alpha1/Node';
|
|
3
|
+
import { StatusResponse__Output } from './proto/apibara/node/v1alpha1/StatusResponse';
|
|
4
|
+
import { StreamMessagesResponse__Output } from './proto/apibara/node/v1alpha1/StreamMessagesResponse';
|
|
5
|
+
import { StreamMessagesRequest } from './proto/apibara/node/v1alpha1/StreamMessagesRequest';
|
|
6
|
+
export declare const Node: (new (address: string, credentials: ChannelCredentials, options?: ClientOptions | undefined) => GrpcNodeClient) & {
|
|
7
|
+
service: import("./proto/apibara/node/v1alpha1/Node").NodeDefinition;
|
|
8
|
+
};
|
|
9
|
+
export declare const credentials: {
|
|
10
|
+
combineChannelCredentials: (channelCredentials: ChannelCredentials, ...callCredentials: import("@grpc/grpc-js").CallCredentials[]) => ChannelCredentials;
|
|
11
|
+
combineCallCredentials: (first: import("@grpc/grpc-js").CallCredentials, ...additional: import("@grpc/grpc-js").CallCredentials[]) => import("@grpc/grpc-js").CallCredentials;
|
|
12
|
+
createInsecure: typeof ChannelCredentials.createInsecure;
|
|
13
|
+
createSsl: typeof ChannelCredentials.createSsl;
|
|
14
|
+
createFromSecureContext: typeof ChannelCredentials.createFromSecureContext;
|
|
15
|
+
createFromMetadataGenerator: typeof import("@grpc/grpc-js").CallCredentials.createFromMetadataGenerator;
|
|
16
|
+
createFromGoogleCredential: typeof import("@grpc/grpc-js").CallCredentials.createFromGoogleCredential;
|
|
17
|
+
createEmpty: typeof import("@grpc/grpc-js").CallCredentials.createEmpty;
|
|
18
|
+
};
|
|
19
|
+
export declare class NodeClient {
|
|
20
|
+
private readonly client;
|
|
21
|
+
constructor(address: string, credentials: ChannelCredentials, options?: ClientOptions);
|
|
22
|
+
status(): Promise<StatusResponse__Output | undefined>;
|
|
23
|
+
streamMessages(args: StreamMessagesRequest): ClientReadableStream<StreamMessagesResponse__Output>;
|
|
24
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.NodeClient = exports.credentials = exports.Node = void 0;
|
|
13
|
+
const util_1 = require("util");
|
|
14
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
15
|
+
const proto_loader_1 = require("@grpc/proto-loader");
|
|
16
|
+
const __NODE_PROTO_PATH = __dirname + '/proto/node.proto';
|
|
17
|
+
const packageDefinition = (0, proto_loader_1.loadSync)(__NODE_PROTO_PATH, {});
|
|
18
|
+
const protoDescriptor = (0, grpc_js_1.loadPackageDefinition)(packageDefinition);
|
|
19
|
+
exports.Node = protoDescriptor.apibara.node.v1alpha1.Node;
|
|
20
|
+
exports.credentials = grpc_js_1.credentials;
|
|
21
|
+
class NodeClient {
|
|
22
|
+
constructor(address, credentials, options) {
|
|
23
|
+
this.client = new exports.Node(address, credentials, options);
|
|
24
|
+
}
|
|
25
|
+
status() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return (0, util_1.promisify)(this.client.Status.bind(this.client, {}))();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
streamMessages(args) {
|
|
31
|
+
return this.client.streamMessages(args);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.NodeClient = NodeClient;
|
|
35
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAgC;AAChC,2CAMsB;AACtB,qDAA6C;AAO7C,MAAM,iBAAiB,GAAG,SAAS,GAAG,mBAAmB,CAAA;AAEzD,MAAM,iBAAiB,GAAG,IAAA,uBAAQ,EAAC,iBAAiB,EAAE,EAAE,CAAC,CAAA;AACzD,MAAM,eAAe,GAAG,IAAA,+BAAqB,EAAC,iBAAiB,CAA6B,CAAA;AAE/E,QAAA,IAAI,GAAG,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAA;AAEjD,QAAA,WAAW,GAAG,qBAAe,CAAA;AAE1C,MAAa,UAAU;IAGrB,YAAY,OAAe,EAAE,WAA+B,EAAE,OAAuB;QACnF,IAAI,CAAC,MAAM,GAAG,IAAI,YAAI,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAA;IACvD,CAAC;IAEY,MAAM;;YACjB,OAAO,IAAA,gBAAS,EAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,CAAA;QAC9D,CAAC;KAAA;IAEM,cAAc,CACnB,IAA2B;QAE3B,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;IACzC,CAAC;CACF;AAhBD,gCAgBC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { StreamMessagesResponse__Output } from './proto/apibara/node/v1alpha1/StreamMessagesResponse';
|
|
5
|
-
import { StreamMessagesRequest } from './proto/apibara/node/v1alpha1/StreamMessagesRequest';
|
|
6
|
-
export declare const Node: (new (address: string, credentials: ChannelCredentials, options?: ClientOptions | undefined) => GrpcNodeClient) & {
|
|
7
|
-
service: import("./proto/apibara/node/v1alpha1/Node").NodeDefinition;
|
|
8
|
-
};
|
|
9
|
-
export declare const credentials: {
|
|
10
|
-
combineChannelCredentials: (channelCredentials: ChannelCredentials, ...callCredentials: import("@grpc/grpc-js").CallCredentials[]) => ChannelCredentials;
|
|
11
|
-
combineCallCredentials: (first: import("@grpc/grpc-js").CallCredentials, ...additional: import("@grpc/grpc-js").CallCredentials[]) => import("@grpc/grpc-js").CallCredentials;
|
|
12
|
-
createInsecure: typeof ChannelCredentials.createInsecure;
|
|
13
|
-
createSsl: typeof ChannelCredentials.createSsl;
|
|
14
|
-
createFromSecureContext: typeof ChannelCredentials.createFromSecureContext;
|
|
15
|
-
createFromMetadataGenerator: typeof import("@grpc/grpc-js").CallCredentials.createFromMetadataGenerator;
|
|
16
|
-
createFromGoogleCredential: typeof import("@grpc/grpc-js").CallCredentials.createFromGoogleCredential;
|
|
17
|
-
createEmpty: typeof import("@grpc/grpc-js").CallCredentials.createEmpty;
|
|
18
|
-
};
|
|
19
|
-
export declare class NodeClient {
|
|
20
|
-
private readonly client;
|
|
21
|
-
constructor(address: string, credentials: ChannelCredentials, options?: ClientOptions);
|
|
22
|
-
status(): Promise<StatusResponse__Output | undefined>;
|
|
23
|
-
streamMessages(args: StreamMessagesRequest): ClientReadableStream<StreamMessagesResponse__Output>;
|
|
24
|
-
}
|
|
1
|
+
export * from './client';
|
|
2
|
+
export * from './buffer';
|
|
3
|
+
export * as proto from './proto';
|
package/dist/index.js
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
10
27
|
};
|
|
11
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const __NODE_PROTO_PATH = __dirname + '/proto/node.proto';
|
|
17
|
-
const packageDefinition = (0, proto_loader_1.loadSync)(__NODE_PROTO_PATH, {});
|
|
18
|
-
const protoDescriptor = (0, grpc_js_1.loadPackageDefinition)(packageDefinition);
|
|
19
|
-
exports.Node = protoDescriptor.apibara.node.v1alpha1.Node;
|
|
20
|
-
exports.credentials = grpc_js_1.credentials;
|
|
21
|
-
class NodeClient {
|
|
22
|
-
constructor(address, credentials, options) {
|
|
23
|
-
this.client = new exports.Node(address, credentials, options);
|
|
24
|
-
}
|
|
25
|
-
status() {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
return (0, util_1.promisify)(this.client.Status.bind(this.client, {}))();
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
streamMessages(args) {
|
|
31
|
-
return this.client.streamMessages(args);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.NodeClient = NodeClient;
|
|
29
|
+
exports.proto = void 0;
|
|
30
|
+
__exportStar(require("./client"), exports);
|
|
31
|
+
__exportStar(require("./buffer"), exports);
|
|
32
|
+
exports.proto = __importStar(require("./proto"));
|
|
35
33
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,2CAAwB;AACxB,iDAAgC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Long } from '@grpc/proto-loader';
|
|
2
2
|
export interface StreamMessagesRequest {
|
|
3
3
|
'startingSequence'?: (number | string | Long);
|
|
4
|
+
'pendingBlockIntervalSeconds'?: (number);
|
|
4
5
|
}
|
|
5
6
|
export interface StreamMessagesRequest__Output {
|
|
6
7
|
'startingSequence': (string);
|
|
8
|
+
'pendingBlockIntervalSeconds': (number);
|
|
7
9
|
}
|
|
@@ -5,11 +5,13 @@ export interface StreamMessagesResponse {
|
|
|
5
5
|
'invalidate'?: (_apibara_node_v1alpha1_Invalidate | null);
|
|
6
6
|
'data'?: (_apibara_node_v1alpha1_Data | null);
|
|
7
7
|
'heartbeat'?: (_apibara_node_v1alpha1_Heartbeat | null);
|
|
8
|
-
'
|
|
8
|
+
'pending'?: (_apibara_node_v1alpha1_Data | null);
|
|
9
|
+
'message'?: "invalidate" | "data" | "heartbeat" | "pending";
|
|
9
10
|
}
|
|
10
11
|
export interface StreamMessagesResponse__Output {
|
|
11
12
|
'invalidate'?: (_apibara_node_v1alpha1_Invalidate__Output | null);
|
|
12
13
|
'data'?: (_apibara_node_v1alpha1_Data__Output | null);
|
|
13
14
|
'heartbeat'?: (_apibara_node_v1alpha1_Heartbeat__Output | null);
|
|
14
|
-
'
|
|
15
|
+
'pending'?: (_apibara_node_v1alpha1_Data__Output | null);
|
|
16
|
+
'message': "invalidate" | "data" | "heartbeat" | "pending";
|
|
15
17
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './apibara/node/v1alpha1/Data';
|
|
2
|
+
export * from './apibara/node/v1alpha1/Heartbeat';
|
|
3
|
+
export * from './apibara/node/v1alpha1/InputSyncingStatus';
|
|
4
|
+
export * from './apibara/node/v1alpha1/Invalidate';
|
|
5
|
+
export * from './apibara/node/v1alpha1/NotStartedStatus';
|
|
6
|
+
export * from './apibara/node/v1alpha1/StatusRequest';
|
|
7
|
+
export * from './apibara/node/v1alpha1/StatusResponse';
|
|
8
|
+
export * from './apibara/node/v1alpha1/StreamMessagesRequest';
|
|
9
|
+
export * from './apibara/node/v1alpha1/StreamMessagesResponse';
|
|
10
|
+
export * from './apibara/node/v1alpha1/SyncedStatus';
|
|
11
|
+
export * from './apibara/node/v1alpha1/SyncingStatus';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./apibara/node/v1alpha1/Data"), exports);
|
|
18
|
+
__exportStar(require("./apibara/node/v1alpha1/Heartbeat"), exports);
|
|
19
|
+
__exportStar(require("./apibara/node/v1alpha1/InputSyncingStatus"), exports);
|
|
20
|
+
__exportStar(require("./apibara/node/v1alpha1/Invalidate"), exports);
|
|
21
|
+
__exportStar(require("./apibara/node/v1alpha1/NotStartedStatus"), exports);
|
|
22
|
+
__exportStar(require("./apibara/node/v1alpha1/StatusRequest"), exports);
|
|
23
|
+
__exportStar(require("./apibara/node/v1alpha1/StatusResponse"), exports);
|
|
24
|
+
__exportStar(require("./apibara/node/v1alpha1/StreamMessagesRequest"), exports);
|
|
25
|
+
__exportStar(require("./apibara/node/v1alpha1/StreamMessagesResponse"), exports);
|
|
26
|
+
__exportStar(require("./apibara/node/v1alpha1/SyncedStatus"), exports);
|
|
27
|
+
__exportStar(require("./apibara/node/v1alpha1/SyncingStatus"), exports);
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proto/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA4C;AAC5C,oEAAiD;AACjD,6EAA0D;AAC1D,qEAAkD;AAClD,2EAAwD;AACxD,wEAAqD;AACrD,yEAAsD;AACtD,gFAA6D;AAC7D,iFAA8D;AAC9D,uEAAoD;AACpD,wEAAqD"}
|
package/dist/proto/node.proto
CHANGED
|
@@ -70,6 +70,8 @@ message ConnectResponse {
|
|
|
70
70
|
message StreamMessagesRequest {
|
|
71
71
|
// Start streaming from the provided sequence number.
|
|
72
72
|
uint64 starting_sequence = 1;
|
|
73
|
+
// If greater than 0, send pending blocks at the specified interval.
|
|
74
|
+
uint32 pending_block_interval_seconds = 2;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
// Message sent from the node to the client.
|
|
@@ -78,6 +80,7 @@ message StreamMessagesResponse {
|
|
|
78
80
|
Invalidate invalidate = 1;
|
|
79
81
|
Data data = 2;
|
|
80
82
|
Heartbeat heartbeat = 3;
|
|
83
|
+
Data pending = 4;
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
|
package/package.json
CHANGED
package/src/buffer.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the hex-encoded bytes to a `Buffer`.
|
|
3
|
+
* @param hex The hex string
|
|
4
|
+
* @param size The buffer size, in bytes
|
|
5
|
+
*/
|
|
6
|
+
export function hexToBuffer(hex: string, size: number): Buffer {
|
|
7
|
+
const padSize = size * 2
|
|
8
|
+
return Buffer.from(hex.replace('0x', '').padStart(padSize, '0'), 'hex')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Converts the buffer to its hex representation.
|
|
13
|
+
* @param buff the buffer
|
|
14
|
+
*/
|
|
15
|
+
export function bufferToHex(buff: Buffer): string {
|
|
16
|
+
return '0x' + buff.toString('hex')
|
|
17
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { promisify } from 'util'
|
|
2
|
+
import {
|
|
3
|
+
loadPackageDefinition,
|
|
4
|
+
credentials as grpcCredentials,
|
|
5
|
+
ClientOptions,
|
|
6
|
+
ChannelCredentials,
|
|
7
|
+
ClientReadableStream,
|
|
8
|
+
} from '@grpc/grpc-js'
|
|
9
|
+
import { loadSync } from '@grpc/proto-loader'
|
|
10
|
+
import { NodeClient as GrpcNodeClient } from './proto/apibara/node/v1alpha1/Node'
|
|
11
|
+
import { ProtoGrpcType } from './proto/node'
|
|
12
|
+
import { StatusResponse__Output } from './proto/apibara/node/v1alpha1/StatusResponse'
|
|
13
|
+
import { StreamMessagesResponse__Output } from './proto/apibara/node/v1alpha1/StreamMessagesResponse'
|
|
14
|
+
import { StreamMessagesRequest } from './proto/apibara/node/v1alpha1/StreamMessagesRequest'
|
|
15
|
+
|
|
16
|
+
const __NODE_PROTO_PATH = __dirname + '/proto/node.proto'
|
|
17
|
+
|
|
18
|
+
const packageDefinition = loadSync(__NODE_PROTO_PATH, {})
|
|
19
|
+
const protoDescriptor = loadPackageDefinition(packageDefinition) as unknown as ProtoGrpcType
|
|
20
|
+
|
|
21
|
+
export const Node = protoDescriptor.apibara.node.v1alpha1.Node
|
|
22
|
+
|
|
23
|
+
export const credentials = grpcCredentials
|
|
24
|
+
|
|
25
|
+
export class NodeClient {
|
|
26
|
+
private readonly client: GrpcNodeClient
|
|
27
|
+
|
|
28
|
+
constructor(address: string, credentials: ChannelCredentials, options?: ClientOptions) {
|
|
29
|
+
this.client = new Node(address, credentials, options)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public async status(): Promise<StatusResponse__Output | undefined> {
|
|
33
|
+
return promisify(this.client.Status.bind(this.client, {}))()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public streamMessages(
|
|
37
|
+
args: StreamMessagesRequest
|
|
38
|
+
): ClientReadableStream<StreamMessagesResponse__Output> {
|
|
39
|
+
return this.client.streamMessages(args)
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,41 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
credentials as grpcCredentials,
|
|
5
|
-
ClientOptions,
|
|
6
|
-
ChannelCredentials,
|
|
7
|
-
ClientReadableStream,
|
|
8
|
-
} from '@grpc/grpc-js'
|
|
9
|
-
import { loadSync } from '@grpc/proto-loader'
|
|
10
|
-
import { NodeClient as GrpcNodeClient } from './proto/apibara/node/v1alpha1/Node'
|
|
11
|
-
import { ProtoGrpcType } from './proto/node'
|
|
12
|
-
import { StatusResponse__Output } from './proto/apibara/node/v1alpha1/StatusResponse'
|
|
13
|
-
import { StreamMessagesResponse__Output } from './proto/apibara/node/v1alpha1/StreamMessagesResponse'
|
|
14
|
-
import { StreamMessagesRequest } from './proto/apibara/node/v1alpha1/StreamMessagesRequest'
|
|
15
|
-
|
|
16
|
-
const __NODE_PROTO_PATH = __dirname + '/proto/node.proto'
|
|
17
|
-
|
|
18
|
-
const packageDefinition = loadSync(__NODE_PROTO_PATH, {})
|
|
19
|
-
const protoDescriptor = loadPackageDefinition(packageDefinition) as unknown as ProtoGrpcType
|
|
20
|
-
|
|
21
|
-
export const Node = protoDescriptor.apibara.node.v1alpha1.Node
|
|
22
|
-
|
|
23
|
-
export const credentials = grpcCredentials
|
|
24
|
-
|
|
25
|
-
export class NodeClient {
|
|
26
|
-
private readonly client: GrpcNodeClient
|
|
27
|
-
|
|
28
|
-
constructor(address: string, credentials: ChannelCredentials, options?: ClientOptions) {
|
|
29
|
-
this.client = new Node(address, credentials, options)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public async status(): Promise<StatusResponse__Output | undefined> {
|
|
33
|
-
return promisify(this.client.Status.bind(this.client, {}))()
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public streamMessages(
|
|
37
|
-
args: StreamMessagesRequest
|
|
38
|
-
): ClientReadableStream<StreamMessagesResponse__Output> {
|
|
39
|
-
return this.client.streamMessages(args)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
export * from './client'
|
|
2
|
+
export * from './buffer'
|
|
3
|
+
export * as proto from './proto'
|
|
@@ -4,8 +4,10 @@ import type { Long } from '@grpc/proto-loader';
|
|
|
4
4
|
|
|
5
5
|
export interface StreamMessagesRequest {
|
|
6
6
|
'startingSequence'?: (number | string | Long);
|
|
7
|
+
'pendingBlockIntervalSeconds'?: (number);
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export interface StreamMessagesRequest__Output {
|
|
10
11
|
'startingSequence': (string);
|
|
12
|
+
'pendingBlockIntervalSeconds': (number);
|
|
11
13
|
}
|
|
@@ -8,12 +8,14 @@ export interface StreamMessagesResponse {
|
|
|
8
8
|
'invalidate'?: (_apibara_node_v1alpha1_Invalidate | null);
|
|
9
9
|
'data'?: (_apibara_node_v1alpha1_Data | null);
|
|
10
10
|
'heartbeat'?: (_apibara_node_v1alpha1_Heartbeat | null);
|
|
11
|
-
'
|
|
11
|
+
'pending'?: (_apibara_node_v1alpha1_Data | null);
|
|
12
|
+
'message'?: "invalidate"|"data"|"heartbeat"|"pending";
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export interface StreamMessagesResponse__Output {
|
|
15
16
|
'invalidate'?: (_apibara_node_v1alpha1_Invalidate__Output | null);
|
|
16
17
|
'data'?: (_apibara_node_v1alpha1_Data__Output | null);
|
|
17
18
|
'heartbeat'?: (_apibara_node_v1alpha1_Heartbeat__Output | null);
|
|
18
|
-
'
|
|
19
|
+
'pending'?: (_apibara_node_v1alpha1_Data__Output | null);
|
|
20
|
+
'message': "invalidate"|"data"|"heartbeat"|"pending";
|
|
19
21
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './apibara/node/v1alpha1/Data'
|
|
2
|
+
export * from './apibara/node/v1alpha1/Heartbeat'
|
|
3
|
+
export * from './apibara/node/v1alpha1/InputSyncingStatus'
|
|
4
|
+
export * from './apibara/node/v1alpha1/Invalidate'
|
|
5
|
+
export * from './apibara/node/v1alpha1/NotStartedStatus'
|
|
6
|
+
export * from './apibara/node/v1alpha1/StatusRequest'
|
|
7
|
+
export * from './apibara/node/v1alpha1/StatusResponse'
|
|
8
|
+
export * from './apibara/node/v1alpha1/StreamMessagesRequest'
|
|
9
|
+
export * from './apibara/node/v1alpha1/StreamMessagesResponse'
|
|
10
|
+
export * from './apibara/node/v1alpha1/SyncedStatus'
|
|
11
|
+
export * from './apibara/node/v1alpha1/SyncingStatus'
|
package/src/proto/node.proto
CHANGED
|
@@ -70,6 +70,8 @@ message ConnectResponse {
|
|
|
70
70
|
message StreamMessagesRequest {
|
|
71
71
|
// Start streaming from the provided sequence number.
|
|
72
72
|
uint64 starting_sequence = 1;
|
|
73
|
+
// If greater than 0, send pending blocks at the specified interval.
|
|
74
|
+
uint32 pending_block_interval_seconds = 2;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
// Message sent from the node to the client.
|
|
@@ -78,6 +80,7 @@ message StreamMessagesResponse {
|
|
|
78
80
|
Invalidate invalidate = 1;
|
|
79
81
|
Data data = 2;
|
|
80
82
|
Heartbeat heartbeat = 3;
|
|
83
|
+
Data pending = 4;
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
|
package/dist/node.proto
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// # Apibara Node service.
|
|
2
|
-
syntax = "proto3";
|
|
3
|
-
|
|
4
|
-
package apibara.node.v1alpha1;
|
|
5
|
-
|
|
6
|
-
import "google/protobuf/any.proto";
|
|
7
|
-
|
|
8
|
-
service Node {
|
|
9
|
-
// Get information about the node and its status.
|
|
10
|
-
rpc Status(StatusRequest) returns (StatusResponse);
|
|
11
|
-
|
|
12
|
-
// Stream messages from the node.
|
|
13
|
-
rpc StreamMessages(StreamMessagesRequest) returns (stream StreamMessagesResponse);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Status request. It's empty.
|
|
17
|
-
message StatusRequest {
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Status response. Returns information about the node's stream.
|
|
21
|
-
message StatusResponse {
|
|
22
|
-
oneof message {
|
|
23
|
-
SyncingStatus syncing = 1;
|
|
24
|
-
SyncedStatus synced = 2;
|
|
25
|
-
NotStartedStatus not_started = 3;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Node is syncing with their sources.
|
|
30
|
-
message SyncingStatus {
|
|
31
|
-
// The latest sequence number.
|
|
32
|
-
uint64 sequence = 1;
|
|
33
|
-
// The syncing status of each input.
|
|
34
|
-
repeated InputSyncingStatus inputs = 2;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Syncing status of the node's input.
|
|
38
|
-
message InputSyncingStatus {
|
|
39
|
-
// Latest sequence number.
|
|
40
|
-
uint64 head = 1;
|
|
41
|
-
// Latest indexed sequenced number.
|
|
42
|
-
uint64 indexed = 2;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Node is fully synced.
|
|
46
|
-
message SyncedStatus {
|
|
47
|
-
// The latest sequence number.
|
|
48
|
-
uint64 sequence = 1;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Node didn't start syncing.
|
|
52
|
-
message NotStartedStatus {
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Message sent from the client to the node.
|
|
56
|
-
message ConnectRequest {
|
|
57
|
-
// Start streaming from the provided sequence number.
|
|
58
|
-
uint64 starting_sequence = 1;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Message sent from the node to the client.
|
|
62
|
-
message ConnectResponse {
|
|
63
|
-
oneof message {
|
|
64
|
-
Invalidate invalidate = 1;
|
|
65
|
-
Data data = 2;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Message sent from the client to the node.
|
|
70
|
-
message StreamMessagesRequest {
|
|
71
|
-
// Start streaming from the provided sequence number.
|
|
72
|
-
uint64 starting_sequence = 1;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Message sent from the node to the client.
|
|
76
|
-
message StreamMessagesResponse {
|
|
77
|
-
oneof message {
|
|
78
|
-
Invalidate invalidate = 1;
|
|
79
|
-
Data data = 2;
|
|
80
|
-
Heartbeat heartbeat = 3;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Invalidate data after (inclusive) the given sequence number.
|
|
85
|
-
message Invalidate {
|
|
86
|
-
uint64 sequence = 1;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
message Data {
|
|
90
|
-
uint64 sequence = 1;
|
|
91
|
-
google.protobuf.Any data = 2;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Sent to clients to check if stream is still connected.
|
|
95
|
-
message Heartbeat {
|
|
96
|
-
}
|