@apibara/protocol 2.0.0-beta.4 → 2.0.0-beta.41
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/index.cjs +222 -0
- package/dist/index.d.cts +71 -0
- package/dist/index.d.mts +71 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.mjs +179 -0
- package/dist/shared/protocol.4b1cfe2c.d.cts +756 -0
- package/dist/shared/protocol.4b1cfe2c.d.mts +756 -0
- package/dist/shared/protocol.4b1cfe2c.d.ts +756 -0
- package/dist/shared/protocol.991ff9ad.mjs +1308 -0
- package/dist/shared/protocol.e39e40d6.cjs +1344 -0
- package/dist/testing/index.cjs +105 -0
- package/dist/testing/index.d.cts +76 -0
- package/dist/testing/index.d.mts +76 -0
- package/dist/testing/index.d.ts +76 -0
- package/dist/testing/index.mjs +97 -0
- package/package.json +8 -10
- package/src/client.ts +72 -28
- package/src/common.ts +28 -0
- package/src/proto/google/protobuf/duration.ts +1 -1
- package/src/proto/stream.ts +62 -3
- package/src/proto/testing.ts +1 -1
- package/src/stream.test.ts +16 -0
- package/src/stream.ts +34 -3
- package/src/testing/client.test.ts +28 -2
package/src/proto/stream.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
/* eslint-disable */
|
|
8
8
|
import Long from "long";
|
|
9
9
|
import { type CallContext, type CallOptions } from "nice-grpc-common";
|
|
10
|
-
import _m0 from "protobufjs/minimal";
|
|
11
|
-
import { Duration } from "./google/protobuf/duration";
|
|
10
|
+
import _m0 from "protobufjs/minimal.js";
|
|
11
|
+
import { Duration } from "./google/protobuf/duration.js";
|
|
12
12
|
|
|
13
13
|
export const protobufPackage = "dna.v2.stream";
|
|
14
14
|
|
|
@@ -63,6 +63,48 @@ export function dataFinalityToJSON(object: DataFinality): string {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/** Data production mode. */
|
|
67
|
+
export enum DataProduction {
|
|
68
|
+
UNKNOWN = 0,
|
|
69
|
+
/** BACKFILL - Data is for a backfilled block. */
|
|
70
|
+
BACKFILL = 1,
|
|
71
|
+
/** LIVE - Data is for a live block. */
|
|
72
|
+
LIVE = 2,
|
|
73
|
+
UNRECOGNIZED = -1,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function dataProductionFromJSON(object: any): DataProduction {
|
|
77
|
+
switch (object) {
|
|
78
|
+
case 0:
|
|
79
|
+
case "DATA_PRODUCTION_UNKNOWN":
|
|
80
|
+
return DataProduction.UNKNOWN;
|
|
81
|
+
case 1:
|
|
82
|
+
case "DATA_PRODUCTION_BACKFILL":
|
|
83
|
+
return DataProduction.BACKFILL;
|
|
84
|
+
case 2:
|
|
85
|
+
case "DATA_PRODUCTION_LIVE":
|
|
86
|
+
return DataProduction.LIVE;
|
|
87
|
+
case -1:
|
|
88
|
+
case "UNRECOGNIZED":
|
|
89
|
+
default:
|
|
90
|
+
return DataProduction.UNRECOGNIZED;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function dataProductionToJSON(object: DataProduction): string {
|
|
95
|
+
switch (object) {
|
|
96
|
+
case DataProduction.UNKNOWN:
|
|
97
|
+
return "DATA_PRODUCTION_UNKNOWN";
|
|
98
|
+
case DataProduction.BACKFILL:
|
|
99
|
+
return "DATA_PRODUCTION_BACKFILL";
|
|
100
|
+
case DataProduction.LIVE:
|
|
101
|
+
return "DATA_PRODUCTION_LIVE";
|
|
102
|
+
case DataProduction.UNRECOGNIZED:
|
|
103
|
+
default:
|
|
104
|
+
return "UNRECOGNIZED";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
66
108
|
/** A cursor over the stream content. */
|
|
67
109
|
export interface Cursor {
|
|
68
110
|
/**
|
|
@@ -192,6 +234,8 @@ export interface Data {
|
|
|
192
234
|
* This message contains chain-specific data serialized using protobuf.
|
|
193
235
|
*/
|
|
194
236
|
readonly data: readonly Uint8Array[];
|
|
237
|
+
/** The production mode of the block. */
|
|
238
|
+
readonly production: DataProduction;
|
|
195
239
|
}
|
|
196
240
|
|
|
197
241
|
/** Sent to clients to check if stream is still connected. */
|
|
@@ -838,7 +882,7 @@ export const Finalize = {
|
|
|
838
882
|
};
|
|
839
883
|
|
|
840
884
|
function createBaseData(): Data {
|
|
841
|
-
return { cursor: undefined, endCursor: undefined, finality: 0, data: [] };
|
|
885
|
+
return { cursor: undefined, endCursor: undefined, finality: 0, data: [], production: 0 };
|
|
842
886
|
}
|
|
843
887
|
|
|
844
888
|
export const Data = {
|
|
@@ -855,6 +899,9 @@ export const Data = {
|
|
|
855
899
|
for (const v of message.data) {
|
|
856
900
|
writer.uint32(34).bytes(v!);
|
|
857
901
|
}
|
|
902
|
+
if (message.production !== 0) {
|
|
903
|
+
writer.uint32(40).int32(message.production);
|
|
904
|
+
}
|
|
858
905
|
return writer;
|
|
859
906
|
},
|
|
860
907
|
|
|
@@ -893,6 +940,13 @@ export const Data = {
|
|
|
893
940
|
|
|
894
941
|
message.data.push(reader.bytes());
|
|
895
942
|
continue;
|
|
943
|
+
case 5:
|
|
944
|
+
if (tag !== 40) {
|
|
945
|
+
break;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
message.production = reader.int32() as any;
|
|
949
|
+
continue;
|
|
896
950
|
}
|
|
897
951
|
if ((tag & 7) === 4 || tag === 0) {
|
|
898
952
|
break;
|
|
@@ -908,6 +962,7 @@ export const Data = {
|
|
|
908
962
|
endCursor: isSet(object.endCursor) ? Cursor.fromJSON(object.endCursor) : undefined,
|
|
909
963
|
finality: isSet(object.finality) ? dataFinalityFromJSON(object.finality) : 0,
|
|
910
964
|
data: globalThis.Array.isArray(object?.data) ? object.data.map((e: any) => bytesFromBase64(e)) : [],
|
|
965
|
+
production: isSet(object.production) ? dataProductionFromJSON(object.production) : 0,
|
|
911
966
|
};
|
|
912
967
|
},
|
|
913
968
|
|
|
@@ -925,6 +980,9 @@ export const Data = {
|
|
|
925
980
|
if (message.data?.length) {
|
|
926
981
|
obj.data = message.data.map((e) => base64FromBytes(e));
|
|
927
982
|
}
|
|
983
|
+
if (message.production !== 0) {
|
|
984
|
+
obj.production = dataProductionToJSON(message.production);
|
|
985
|
+
}
|
|
928
986
|
return obj;
|
|
929
987
|
},
|
|
930
988
|
|
|
@@ -941,6 +999,7 @@ export const Data = {
|
|
|
941
999
|
: undefined;
|
|
942
1000
|
message.finality = object.finality ?? 0;
|
|
943
1001
|
message.data = object.data?.map((e) => e) || [];
|
|
1002
|
+
message.production = object.production ?? 0;
|
|
944
1003
|
return message;
|
|
945
1004
|
},
|
|
946
1005
|
};
|
package/src/proto/testing.ts
CHANGED
package/src/stream.test.ts
CHANGED
|
@@ -95,6 +95,11 @@ describe("StreamDataResponse", () => {
|
|
|
95
95
|
data: {
|
|
96
96
|
finality: "accepted",
|
|
97
97
|
data: [{ value: "hello" }, { value: "world" }],
|
|
98
|
+
production: "backfill",
|
|
99
|
+
endCursor: {
|
|
100
|
+
orderKey: 5_000_000n,
|
|
101
|
+
uniqueKey: "0x1234567890",
|
|
102
|
+
},
|
|
98
103
|
},
|
|
99
104
|
} as const;
|
|
100
105
|
|
|
@@ -119,7 +124,18 @@ describe("StreamDataResponse", () => {
|
|
|
119
124
|
100,
|
|
120
125
|
],
|
|
121
126
|
],
|
|
127
|
+
"endCursor": {
|
|
128
|
+
"orderKey": 5000000n,
|
|
129
|
+
"uniqueKey": Uint8Array [
|
|
130
|
+
18,
|
|
131
|
+
52,
|
|
132
|
+
86,
|
|
133
|
+
120,
|
|
134
|
+
144,
|
|
135
|
+
],
|
|
136
|
+
},
|
|
122
137
|
"finality": 2,
|
|
138
|
+
"production": 1,
|
|
123
139
|
},
|
|
124
140
|
}
|
|
125
141
|
`);
|
package/src/stream.ts
CHANGED
|
@@ -34,6 +34,35 @@ export const DataFinality = Schema.transform(
|
|
|
34
34
|
|
|
35
35
|
export type DataFinality = typeof DataFinality.Type;
|
|
36
36
|
|
|
37
|
+
/** Data production mode. */
|
|
38
|
+
export const DataProduction = Schema.transform(
|
|
39
|
+
Schema.Enums(proto.stream.DataProduction),
|
|
40
|
+
Schema.Literal("backfill", "live", "unknown"),
|
|
41
|
+
{
|
|
42
|
+
decode(value) {
|
|
43
|
+
const enumMap = {
|
|
44
|
+
[proto.stream.DataProduction.BACKFILL]: "backfill",
|
|
45
|
+
[proto.stream.DataProduction.LIVE]: "live",
|
|
46
|
+
[proto.stream.DataProduction.UNKNOWN]: "unknown",
|
|
47
|
+
[proto.stream.DataProduction.UNRECOGNIZED]: "unknown",
|
|
48
|
+
} as const;
|
|
49
|
+
|
|
50
|
+
return enumMap[value] ?? "unknown";
|
|
51
|
+
},
|
|
52
|
+
encode(value) {
|
|
53
|
+
const enumMap = {
|
|
54
|
+
backfill: proto.stream.DataProduction.BACKFILL,
|
|
55
|
+
live: proto.stream.DataProduction.LIVE,
|
|
56
|
+
unknown: proto.stream.DataProduction.UNKNOWN,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return enumMap[value] ?? proto.stream.DataProduction.UNKNOWN;
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
export type DataProduction = typeof DataProduction.Type;
|
|
65
|
+
|
|
37
66
|
export const Duration = Schema.Struct({
|
|
38
67
|
seconds: Schema.BigIntFromSelf,
|
|
39
68
|
nanos: Schema.Number,
|
|
@@ -97,7 +126,7 @@ export type StdErr = typeof StdErr.Type;
|
|
|
97
126
|
export const SystemMessage = Schema.Struct({
|
|
98
127
|
_tag: tag("systemMessage"),
|
|
99
128
|
systemMessage: Schema.Struct({
|
|
100
|
-
output: Schema.
|
|
129
|
+
output: Schema.Union(StdOut, StdErr),
|
|
101
130
|
}),
|
|
102
131
|
});
|
|
103
132
|
|
|
@@ -110,8 +139,9 @@ export const Data = <TA, TR>(
|
|
|
110
139
|
_tag: tag("data"),
|
|
111
140
|
data: Schema.Struct({
|
|
112
141
|
cursor: Schema.optional(Cursor),
|
|
113
|
-
endCursor:
|
|
142
|
+
endCursor: Cursor,
|
|
114
143
|
finality: DataFinality,
|
|
144
|
+
production: DataProduction,
|
|
115
145
|
data: Schema.Array(schema),
|
|
116
146
|
}),
|
|
117
147
|
});
|
|
@@ -134,8 +164,9 @@ export type StreamDataResponse<TA> =
|
|
|
134
164
|
_tag: "data";
|
|
135
165
|
data: {
|
|
136
166
|
cursor?: Cursor | undefined;
|
|
137
|
-
endCursor
|
|
167
|
+
endCursor: Cursor;
|
|
138
168
|
finality: DataFinality;
|
|
169
|
+
production: DataProduction;
|
|
139
170
|
data: readonly (TA | null)[];
|
|
140
171
|
};
|
|
141
172
|
};
|
|
@@ -9,7 +9,15 @@ describe("MockClient", () => {
|
|
|
9
9
|
return [
|
|
10
10
|
{
|
|
11
11
|
_tag: "data",
|
|
12
|
-
data: {
|
|
12
|
+
data: {
|
|
13
|
+
finality: "finalized",
|
|
14
|
+
data: [{ data: "hello" }],
|
|
15
|
+
production: "backfill",
|
|
16
|
+
endCursor: {
|
|
17
|
+
orderKey: 5_000_000n,
|
|
18
|
+
uniqueKey: "0x1234567890",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
13
21
|
},
|
|
14
22
|
];
|
|
15
23
|
});
|
|
@@ -29,7 +37,12 @@ describe("MockClient", () => {
|
|
|
29
37
|
"data": "hello",
|
|
30
38
|
},
|
|
31
39
|
],
|
|
40
|
+
"endCursor": {
|
|
41
|
+
"orderKey": 5000000n,
|
|
42
|
+
"uniqueKey": "0x1234567890",
|
|
43
|
+
},
|
|
32
44
|
"finality": "finalized",
|
|
45
|
+
"production": "backfill",
|
|
33
46
|
},
|
|
34
47
|
},
|
|
35
48
|
]
|
|
@@ -41,7 +54,15 @@ describe("MockClient", () => {
|
|
|
41
54
|
return [
|
|
42
55
|
{
|
|
43
56
|
_tag: "data",
|
|
44
|
-
data: {
|
|
57
|
+
data: {
|
|
58
|
+
finality: "finalized",
|
|
59
|
+
data: [{ data: "hello" }, null],
|
|
60
|
+
production: "backfill",
|
|
61
|
+
endCursor: {
|
|
62
|
+
orderKey: 5_000_000n,
|
|
63
|
+
uniqueKey: "0x1234567890",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
45
66
|
},
|
|
46
67
|
];
|
|
47
68
|
});
|
|
@@ -62,7 +83,12 @@ describe("MockClient", () => {
|
|
|
62
83
|
},
|
|
63
84
|
null,
|
|
64
85
|
],
|
|
86
|
+
"endCursor": {
|
|
87
|
+
"orderKey": 5000000n,
|
|
88
|
+
"uniqueKey": "0x1234567890",
|
|
89
|
+
},
|
|
65
90
|
"finality": "finalized",
|
|
91
|
+
"production": "backfill",
|
|
66
92
|
},
|
|
67
93
|
},
|
|
68
94
|
]
|