@apibara/protocol 2.1.0-beta.22 → 2.1.0-beta.24
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/codec.cjs +241 -0
- package/dist/codec.d.cts +81 -0
- package/dist/codec.d.mts +81 -0
- package/dist/codec.d.ts +81 -0
- package/dist/codec.mjs +223 -0
- package/dist/index.cjs +15 -29
- package/dist/index.d.cts +3 -4
- package/dist/index.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +14 -19
- package/dist/shared/{protocol.4b1cfe2c.d.cts → protocol.68a15d69.d.mts} +398 -247
- package/dist/shared/{protocol.4b1cfe2c.d.mts → protocol.8b5e318a.d.ts} +398 -247
- package/dist/shared/{protocol.991ff9ad.mjs → protocol.a64f7660.mjs} +173 -170
- package/dist/shared/{protocol.e39e40d6.cjs → protocol.d8bad371.cjs} +174 -176
- package/dist/shared/{protocol.4b1cfe2c.d.ts → protocol.f52df848.d.cts} +398 -247
- package/dist/testing/index.cjs +23 -37
- package/dist/testing/index.d.cts +107 -54
- package/dist/testing/index.d.mts +107 -54
- package/dist/testing/index.d.ts +107 -54
- package/dist/testing/index.mjs +23 -37
- package/package.json +7 -3
- package/src/client.ts +7 -12
- package/src/codec.ts +662 -0
- package/src/common.ts +70 -53
- package/src/config.ts +3 -4
- package/src/proto/google/protobuf/duration.ts +8 -6
- package/src/proto/stream.ts +38 -24
- package/src/status.ts +9 -16
- package/src/stream.ts +145 -144
- package/src/testing/mock.ts +35 -38
- package/src/common.test.ts +0 -67
- package/src/status.test.ts +0 -51
- package/src/stream.test-d.ts +0 -33
- package/src/stream.test.ts +0 -254
- package/src/testing/client.test.ts +0 -97
- package/src/testing/mock.test.ts +0 -35
package/dist/testing/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { MessageCodec, OptionalCodec, StringCodec } from '../codec.mjs';
|
|
2
|
+
import { l as StreamConfig, M as MockFilter$1, m as MockBlock, S as StreamDataResponse } from '../shared/protocol.a64f7660.mjs';
|
|
3
3
|
import 'protobufjs/minimal.js';
|
|
4
|
-
import 'effect';
|
|
5
4
|
import 'viem';
|
|
6
5
|
import 'long';
|
|
7
6
|
|
|
@@ -39,44 +38,31 @@ class StreamDataIterable {
|
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
const MockFilter =
|
|
43
|
-
filter:
|
|
41
|
+
const MockFilter = MessageCodec({
|
|
42
|
+
filter: OptionalCodec(StringCodec)
|
|
44
43
|
});
|
|
45
|
-
const MockFilterFromBytes =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return MockFilter$1.decode(value);
|
|
52
|
-
},
|
|
53
|
-
encode(value) {
|
|
54
|
-
return MockFilter$1.encode(value).finish();
|
|
55
|
-
}
|
|
44
|
+
const MockFilterFromBytes = {
|
|
45
|
+
decode(value) {
|
|
46
|
+
return MockFilter$1.decode(value);
|
|
47
|
+
},
|
|
48
|
+
encode(value) {
|
|
49
|
+
return MockFilter$1.encode(value).finish();
|
|
56
50
|
}
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
return MockBlock$1.decode(value);
|
|
71
|
-
},
|
|
72
|
-
encode(value) {
|
|
73
|
-
if (value === null) {
|
|
74
|
-
return new Uint8Array();
|
|
75
|
-
}
|
|
76
|
-
return MockBlock$1.encode(value).finish();
|
|
51
|
+
};
|
|
52
|
+
const MockBlockFromBytes = {
|
|
53
|
+
decode(value) {
|
|
54
|
+
if (value.length === 0) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return MockBlock.decode(value);
|
|
58
|
+
},
|
|
59
|
+
encode(value) {
|
|
60
|
+
if (value === null) {
|
|
61
|
+
return new Uint8Array();
|
|
77
62
|
}
|
|
63
|
+
return MockBlock.encode(value).finish();
|
|
78
64
|
}
|
|
79
|
-
|
|
65
|
+
};
|
|
80
66
|
function mergeMockFilter(a, b) {
|
|
81
67
|
let filter = "";
|
|
82
68
|
if (a.filter) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apibara/protocol",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -21,6 +21,12 @@
|
|
|
21
21
|
"import": "./dist/testing/index.mjs",
|
|
22
22
|
"require": "./dist/testing/index.cjs",
|
|
23
23
|
"default": "./dist/testing/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"./codec": {
|
|
26
|
+
"types": "./dist/codec.d.ts",
|
|
27
|
+
"import": "./dist/codec.mjs",
|
|
28
|
+
"require": "./dist/codec.cjs",
|
|
29
|
+
"default": "./dist/codec.mjs"
|
|
24
30
|
}
|
|
25
31
|
},
|
|
26
32
|
"scripts": {
|
|
@@ -41,8 +47,6 @@
|
|
|
41
47
|
"vitest": "^1.6.0"
|
|
42
48
|
},
|
|
43
49
|
"dependencies": {
|
|
44
|
-
"@effect/schema": "^0.67.15",
|
|
45
|
-
"effect": "^3.2.6",
|
|
46
50
|
"long": "^5.2.3",
|
|
47
51
|
"nice-grpc": "^2.1.8",
|
|
48
52
|
"nice-grpc-common": "^2.0.2",
|
package/src/client.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Schema } from "@effect/schema";
|
|
2
1
|
import {
|
|
3
2
|
type ChannelCredentials,
|
|
4
3
|
type ChannelOptions,
|
|
@@ -11,14 +10,10 @@ import {
|
|
|
11
10
|
import * as proto from "./proto";
|
|
12
11
|
|
|
13
12
|
import assert from "node:assert";
|
|
13
|
+
import type { Codec } from "./codec";
|
|
14
14
|
import type { Cursor } from "./common";
|
|
15
15
|
import type { StreamConfig } from "./config";
|
|
16
|
-
import {
|
|
17
|
-
type StatusRequest,
|
|
18
|
-
type StatusResponse,
|
|
19
|
-
statusRequestToProto,
|
|
20
|
-
statusResponseFromProto,
|
|
21
|
-
} from "./status";
|
|
16
|
+
import { StatusRequest, StatusResponse } from "./status";
|
|
22
17
|
import { type StreamDataRequest, StreamDataResponse } from "./stream";
|
|
23
18
|
|
|
24
19
|
export { ClientError, Status, Metadata } from "nice-grpc";
|
|
@@ -95,15 +90,15 @@ export class GrpcClient<TFilter, TBlock> implements Client<TFilter, TBlock> {
|
|
|
95
90
|
private config: StreamConfig<TFilter, TBlock>,
|
|
96
91
|
private client: proto.stream.DnaStreamClient,
|
|
97
92
|
) {
|
|
98
|
-
this.encodeRequest =
|
|
93
|
+
this.encodeRequest = config.Request.encode;
|
|
99
94
|
}
|
|
100
95
|
|
|
101
96
|
async status(request?: StatusRequest, options?: ClientCallOptions) {
|
|
102
97
|
const response = await this.client.status(
|
|
103
|
-
|
|
98
|
+
StatusRequest.encode(request ?? {}),
|
|
104
99
|
options,
|
|
105
100
|
);
|
|
106
|
-
return
|
|
101
|
+
return StatusResponse.decode(response);
|
|
107
102
|
}
|
|
108
103
|
|
|
109
104
|
streamData(request: StreamDataRequest<TFilter>, options?: StreamDataOptions) {
|
|
@@ -115,14 +110,14 @@ export class GrpcClient<TFilter, TBlock> implements Client<TFilter, TBlock> {
|
|
|
115
110
|
export class StreamDataIterable<TBlock> {
|
|
116
111
|
constructor(
|
|
117
112
|
private it: AsyncIterable<proto.stream.StreamDataResponse>,
|
|
118
|
-
private schema:
|
|
113
|
+
private schema: Codec<TBlock, Uint8Array>,
|
|
119
114
|
private options?: StreamDataOptions,
|
|
120
115
|
) {}
|
|
121
116
|
|
|
122
117
|
[Symbol.asyncIterator](): AsyncIterator<StreamDataResponse<TBlock>> {
|
|
123
118
|
const inner = this.it[Symbol.asyncIterator]();
|
|
124
119
|
const schema = StreamDataResponse(this.schema);
|
|
125
|
-
const decoder =
|
|
120
|
+
const decoder = schema.decode;
|
|
126
121
|
const { endingCursor, timeout = DEFAULT_TIMEOUT_MS } = this.options ?? {};
|
|
127
122
|
let shouldStop = false;
|
|
128
123
|
|