@apibara/protocol 2.0.0-beta.32 → 2.0.0-beta.34
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 +42 -20
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +42 -22
- package/dist/shared/{protocol.74b3c596.cjs → protocol.2d8d950d.cjs} +81 -2
- package/dist/shared/{protocol.32079ba8.mjs → protocol.91527bce.mjs} +81 -3
- package/dist/shared/{protocol.f9e14c27.d.ts → protocol.ef662c22.d.cts} +30 -3
- package/dist/shared/{protocol.f9e14c27.d.cts → protocol.ef662c22.d.mts} +30 -3
- package/dist/shared/{protocol.f9e14c27.d.mts → protocol.ef662c22.d.ts} +30 -3
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.d.cts +2 -1
- package/dist/testing/index.d.mts +2 -1
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.mjs +1 -1
- package/package.json +1 -1
- package/src/client.ts +51 -23
- package/src/proto/stream.ts +60 -1
- package/src/stream.test.ts +2 -0
- package/src/stream.ts +31 -0
- package/src/testing/client.test.ts +12 -2
|
@@ -115,6 +115,17 @@ declare enum DataFinality$1 {
|
|
|
115
115
|
}
|
|
116
116
|
declare function dataFinalityFromJSON(object: any): DataFinality$1;
|
|
117
117
|
declare function dataFinalityToJSON(object: DataFinality$1): string;
|
|
118
|
+
/** Data production mode. */
|
|
119
|
+
declare enum DataProduction$1 {
|
|
120
|
+
UNKNOWN = 0,
|
|
121
|
+
/** BACKFILL - Data is for a backfilled block. */
|
|
122
|
+
BACKFILL = 1,
|
|
123
|
+
/** LIVE - Data is for a live block. */
|
|
124
|
+
LIVE = 2,
|
|
125
|
+
UNRECOGNIZED = -1
|
|
126
|
+
}
|
|
127
|
+
declare function dataProductionFromJSON(object: any): DataProduction$1;
|
|
128
|
+
declare function dataProductionToJSON(object: DataProduction$1): string;
|
|
118
129
|
/** A cursor over the stream content. */
|
|
119
130
|
interface Cursor$1 {
|
|
120
131
|
/**
|
|
@@ -286,6 +297,8 @@ interface Data$1 {
|
|
|
286
297
|
* This message contains chain-specific data serialized using protobuf.
|
|
287
298
|
*/
|
|
288
299
|
readonly data: readonly Uint8Array[];
|
|
300
|
+
/** The production mode of the block. */
|
|
301
|
+
readonly production: DataProduction$1;
|
|
289
302
|
}
|
|
290
303
|
declare const Data$1: {
|
|
291
304
|
encode(message: Data$1, writer?: _m0.Writer): _m0.Writer;
|
|
@@ -410,9 +423,11 @@ type stream_DnaStreamServiceImplementation<CallContextExt = {}> = DnaStreamServi
|
|
|
410
423
|
type stream_ServerStreamingMethodResult<Response> = ServerStreamingMethodResult<Response>;
|
|
411
424
|
declare const stream_dataFinalityFromJSON: typeof dataFinalityFromJSON;
|
|
412
425
|
declare const stream_dataFinalityToJSON: typeof dataFinalityToJSON;
|
|
426
|
+
declare const stream_dataProductionFromJSON: typeof dataProductionFromJSON;
|
|
427
|
+
declare const stream_dataProductionToJSON: typeof dataProductionToJSON;
|
|
413
428
|
declare const stream_protobufPackage: typeof protobufPackage;
|
|
414
429
|
declare namespace stream {
|
|
415
|
-
export { Cursor$1 as Cursor, Data$1 as Data, DataFinality$1 as DataFinality, type stream_DeepPartial as DeepPartial, type stream_DnaStreamClient as DnaStreamClient, stream_DnaStreamDefinition as DnaStreamDefinition, type stream_DnaStreamServiceImplementation as DnaStreamServiceImplementation, Finalize$1 as Finalize, Heartbeat$1 as Heartbeat, Invalidate$1 as Invalidate, type stream_ServerStreamingMethodResult as ServerStreamingMethodResult, StatusRequest$1 as StatusRequest, StatusResponse$1 as StatusResponse, StreamDataRequest$1 as StreamDataRequest, StreamDataResponse$1 as StreamDataResponse, SystemMessage$1 as SystemMessage, stream_dataFinalityFromJSON as dataFinalityFromJSON, stream_dataFinalityToJSON as dataFinalityToJSON, stream_protobufPackage as protobufPackage };
|
|
430
|
+
export { Cursor$1 as Cursor, Data$1 as Data, DataFinality$1 as DataFinality, DataProduction$1 as DataProduction, type stream_DeepPartial as DeepPartial, type stream_DnaStreamClient as DnaStreamClient, stream_DnaStreamDefinition as DnaStreamDefinition, type stream_DnaStreamServiceImplementation as DnaStreamServiceImplementation, Finalize$1 as Finalize, Heartbeat$1 as Heartbeat, Invalidate$1 as Invalidate, type stream_ServerStreamingMethodResult as ServerStreamingMethodResult, StatusRequest$1 as StatusRequest, StatusResponse$1 as StatusResponse, StreamDataRequest$1 as StreamDataRequest, StreamDataResponse$1 as StreamDataResponse, SystemMessage$1 as SystemMessage, stream_dataFinalityFromJSON as dataFinalityFromJSON, stream_dataFinalityToJSON as dataFinalityToJSON, stream_dataProductionFromJSON as dataProductionFromJSON, stream_dataProductionToJSON as dataProductionToJSON, stream_protobufPackage as protobufPackage };
|
|
416
431
|
}
|
|
417
432
|
|
|
418
433
|
/** Bytes encoded as a 0x-prefixed hex string. */
|
|
@@ -479,6 +494,9 @@ declare const statusResponseFromProto: (i: {
|
|
|
479
494
|
/** Data finality. */
|
|
480
495
|
declare const DataFinality: Schema.transform<Schema.Enums<typeof DataFinality$1>, Schema.Literal<["finalized", "accepted", "pending", "unknown"]>>;
|
|
481
496
|
type DataFinality = typeof DataFinality.Type;
|
|
497
|
+
/** Data production mode. */
|
|
498
|
+
declare const DataProduction: Schema.transform<Schema.Enums<typeof DataProduction$1>, Schema.Literal<["backfill", "live", "unknown"]>>;
|
|
499
|
+
type DataProduction = typeof DataProduction.Type;
|
|
482
500
|
declare const Duration: Schema.Struct<{
|
|
483
501
|
seconds: typeof Schema.BigIntFromSelf;
|
|
484
502
|
nanos: typeof Schema.Number;
|
|
@@ -545,6 +563,7 @@ declare const Data: <TA, TR>(schema: Schema.Schema<TA | null, Uint8Array, TR>) =
|
|
|
545
563
|
cursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
546
564
|
endCursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
547
565
|
finality: Schema.transform<Schema.Enums<typeof DataFinality$1>, Schema.Literal<["finalized", "accepted", "pending", "unknown"]>>;
|
|
566
|
+
production: Schema.transform<Schema.Enums<typeof DataProduction$1>, Schema.Literal<["backfill", "live", "unknown"]>>;
|
|
548
567
|
data: Schema.Array$<Schema.Schema<TA | null, Uint8Array, TR>>;
|
|
549
568
|
}>;
|
|
550
569
|
}>;
|
|
@@ -579,6 +598,7 @@ declare const StreamDataResponse: <TA, TR>(data: Schema.Schema<TA | null, Uint8A
|
|
|
579
598
|
cursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
580
599
|
endCursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
581
600
|
finality: Schema.transform<Schema.Enums<typeof DataFinality$1>, Schema.Literal<["finalized", "accepted", "pending", "unknown"]>>;
|
|
601
|
+
production: Schema.transform<Schema.Enums<typeof DataProduction$1>, Schema.Literal<["backfill", "live", "unknown"]>>;
|
|
582
602
|
data: Schema.Array$<Schema.Schema<TA | null, Uint8Array, TR>>;
|
|
583
603
|
}>;
|
|
584
604
|
}>, Schema.Struct<{
|
|
@@ -611,6 +631,7 @@ type StreamDataResponse<TA> = ResponseWithoutData | {
|
|
|
611
631
|
cursor?: Cursor | undefined;
|
|
612
632
|
endCursor?: Cursor | undefined;
|
|
613
633
|
finality: DataFinality;
|
|
634
|
+
production: DataProduction;
|
|
614
635
|
data: readonly (TA | null)[];
|
|
615
636
|
};
|
|
616
637
|
};
|
|
@@ -644,6 +665,7 @@ declare class StreamConfig<TFilter, TBlock> {
|
|
|
644
665
|
cursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
645
666
|
endCursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
646
667
|
finality: Schema.transform<Schema.Enums<typeof DataFinality$1>, Schema.Literal<["finalized", "accepted", "pending", "unknown"]>>;
|
|
668
|
+
production: Schema.transform<Schema.Enums<typeof DataProduction$1>, Schema.Literal<["backfill", "live", "unknown"]>>;
|
|
647
669
|
data: Schema.Array$<Schema.Schema<TBlock | null, Uint8Array, never>>;
|
|
648
670
|
}>;
|
|
649
671
|
}>, Schema.Struct<{
|
|
@@ -672,13 +694,18 @@ declare class StreamConfig<TFilter, TBlock> {
|
|
|
672
694
|
}>]>;
|
|
673
695
|
}
|
|
674
696
|
|
|
697
|
+
declare class TimeoutError extends Error {
|
|
698
|
+
constructor(timeout: number);
|
|
699
|
+
}
|
|
675
700
|
/** Client call options. */
|
|
676
701
|
interface ClientCallOptions {
|
|
677
702
|
signal?: AbortSignal;
|
|
678
703
|
}
|
|
679
704
|
interface StreamDataOptions extends ClientCallOptions {
|
|
680
|
-
/** Stop at the specified cursor (inclusive) */
|
|
705
|
+
/** Stop at the specified cursor (inclusive). */
|
|
681
706
|
endingCursor?: Cursor;
|
|
707
|
+
/** Timeout between messages, in milliseconds. */
|
|
708
|
+
timeout?: number;
|
|
682
709
|
}
|
|
683
710
|
/** DNA client. */
|
|
684
711
|
interface Client<TFilter, TBlock> {
|
|
@@ -715,4 +742,4 @@ declare class StreamDataIterable<TBlock> {
|
|
|
715
742
|
[Symbol.asyncIterator](): AsyncIterator<StreamDataResponse<TBlock>>;
|
|
716
743
|
}
|
|
717
744
|
|
|
718
|
-
export { type
|
|
745
|
+
export { type ClientCallOptions as A, Bytes as B, type CursorProto as C, type DnaStreamClient as D, type StreamDataOptions as E, Finalize as F, type Client as G, Heartbeat as H, Invalidate as I, type CreateClientOptions as J, createClient as K, GrpcClient as L, StreamDataIterable as M, DataFinality$1 as N, DataProduction$1 as O, StatusRequest as S, TimeoutError as T, _Cursor as _, DnaStreamDefinition as a, BytesFromUint8Array as b, Cursor as c, createCursor as d, cursorToProto as e, cursorFromProto as f, CursorFromBytes as g, cursorToBytes as h, cursorFromBytes as i, isCursor as j, statusRequestToProto as k, statusRequestFromProto as l, StatusResponse as m, statusResponseToProto as n, statusResponseFromProto as o, DataFinality as p, DataProduction as q, Duration as r, stream as s, StreamDataRequest as t, StdOut as u, StdErr as v, SystemMessage as w, Data as x, StreamDataResponse as y, StreamConfig as z };
|
|
@@ -115,6 +115,17 @@ declare enum DataFinality$1 {
|
|
|
115
115
|
}
|
|
116
116
|
declare function dataFinalityFromJSON(object: any): DataFinality$1;
|
|
117
117
|
declare function dataFinalityToJSON(object: DataFinality$1): string;
|
|
118
|
+
/** Data production mode. */
|
|
119
|
+
declare enum DataProduction$1 {
|
|
120
|
+
UNKNOWN = 0,
|
|
121
|
+
/** BACKFILL - Data is for a backfilled block. */
|
|
122
|
+
BACKFILL = 1,
|
|
123
|
+
/** LIVE - Data is for a live block. */
|
|
124
|
+
LIVE = 2,
|
|
125
|
+
UNRECOGNIZED = -1
|
|
126
|
+
}
|
|
127
|
+
declare function dataProductionFromJSON(object: any): DataProduction$1;
|
|
128
|
+
declare function dataProductionToJSON(object: DataProduction$1): string;
|
|
118
129
|
/** A cursor over the stream content. */
|
|
119
130
|
interface Cursor$1 {
|
|
120
131
|
/**
|
|
@@ -286,6 +297,8 @@ interface Data$1 {
|
|
|
286
297
|
* This message contains chain-specific data serialized using protobuf.
|
|
287
298
|
*/
|
|
288
299
|
readonly data: readonly Uint8Array[];
|
|
300
|
+
/** The production mode of the block. */
|
|
301
|
+
readonly production: DataProduction$1;
|
|
289
302
|
}
|
|
290
303
|
declare const Data$1: {
|
|
291
304
|
encode(message: Data$1, writer?: _m0.Writer): _m0.Writer;
|
|
@@ -410,9 +423,11 @@ type stream_DnaStreamServiceImplementation<CallContextExt = {}> = DnaStreamServi
|
|
|
410
423
|
type stream_ServerStreamingMethodResult<Response> = ServerStreamingMethodResult<Response>;
|
|
411
424
|
declare const stream_dataFinalityFromJSON: typeof dataFinalityFromJSON;
|
|
412
425
|
declare const stream_dataFinalityToJSON: typeof dataFinalityToJSON;
|
|
426
|
+
declare const stream_dataProductionFromJSON: typeof dataProductionFromJSON;
|
|
427
|
+
declare const stream_dataProductionToJSON: typeof dataProductionToJSON;
|
|
413
428
|
declare const stream_protobufPackage: typeof protobufPackage;
|
|
414
429
|
declare namespace stream {
|
|
415
|
-
export { Cursor$1 as Cursor, Data$1 as Data, DataFinality$1 as DataFinality, type stream_DeepPartial as DeepPartial, type stream_DnaStreamClient as DnaStreamClient, stream_DnaStreamDefinition as DnaStreamDefinition, type stream_DnaStreamServiceImplementation as DnaStreamServiceImplementation, Finalize$1 as Finalize, Heartbeat$1 as Heartbeat, Invalidate$1 as Invalidate, type stream_ServerStreamingMethodResult as ServerStreamingMethodResult, StatusRequest$1 as StatusRequest, StatusResponse$1 as StatusResponse, StreamDataRequest$1 as StreamDataRequest, StreamDataResponse$1 as StreamDataResponse, SystemMessage$1 as SystemMessage, stream_dataFinalityFromJSON as dataFinalityFromJSON, stream_dataFinalityToJSON as dataFinalityToJSON, stream_protobufPackage as protobufPackage };
|
|
430
|
+
export { Cursor$1 as Cursor, Data$1 as Data, DataFinality$1 as DataFinality, DataProduction$1 as DataProduction, type stream_DeepPartial as DeepPartial, type stream_DnaStreamClient as DnaStreamClient, stream_DnaStreamDefinition as DnaStreamDefinition, type stream_DnaStreamServiceImplementation as DnaStreamServiceImplementation, Finalize$1 as Finalize, Heartbeat$1 as Heartbeat, Invalidate$1 as Invalidate, type stream_ServerStreamingMethodResult as ServerStreamingMethodResult, StatusRequest$1 as StatusRequest, StatusResponse$1 as StatusResponse, StreamDataRequest$1 as StreamDataRequest, StreamDataResponse$1 as StreamDataResponse, SystemMessage$1 as SystemMessage, stream_dataFinalityFromJSON as dataFinalityFromJSON, stream_dataFinalityToJSON as dataFinalityToJSON, stream_dataProductionFromJSON as dataProductionFromJSON, stream_dataProductionToJSON as dataProductionToJSON, stream_protobufPackage as protobufPackage };
|
|
416
431
|
}
|
|
417
432
|
|
|
418
433
|
/** Bytes encoded as a 0x-prefixed hex string. */
|
|
@@ -479,6 +494,9 @@ declare const statusResponseFromProto: (i: {
|
|
|
479
494
|
/** Data finality. */
|
|
480
495
|
declare const DataFinality: Schema.transform<Schema.Enums<typeof DataFinality$1>, Schema.Literal<["finalized", "accepted", "pending", "unknown"]>>;
|
|
481
496
|
type DataFinality = typeof DataFinality.Type;
|
|
497
|
+
/** Data production mode. */
|
|
498
|
+
declare const DataProduction: Schema.transform<Schema.Enums<typeof DataProduction$1>, Schema.Literal<["backfill", "live", "unknown"]>>;
|
|
499
|
+
type DataProduction = typeof DataProduction.Type;
|
|
482
500
|
declare const Duration: Schema.Struct<{
|
|
483
501
|
seconds: typeof Schema.BigIntFromSelf;
|
|
484
502
|
nanos: typeof Schema.Number;
|
|
@@ -545,6 +563,7 @@ declare const Data: <TA, TR>(schema: Schema.Schema<TA | null, Uint8Array, TR>) =
|
|
|
545
563
|
cursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
546
564
|
endCursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
547
565
|
finality: Schema.transform<Schema.Enums<typeof DataFinality$1>, Schema.Literal<["finalized", "accepted", "pending", "unknown"]>>;
|
|
566
|
+
production: Schema.transform<Schema.Enums<typeof DataProduction$1>, Schema.Literal<["backfill", "live", "unknown"]>>;
|
|
548
567
|
data: Schema.Array$<Schema.Schema<TA | null, Uint8Array, TR>>;
|
|
549
568
|
}>;
|
|
550
569
|
}>;
|
|
@@ -579,6 +598,7 @@ declare const StreamDataResponse: <TA, TR>(data: Schema.Schema<TA | null, Uint8A
|
|
|
579
598
|
cursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
580
599
|
endCursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
581
600
|
finality: Schema.transform<Schema.Enums<typeof DataFinality$1>, Schema.Literal<["finalized", "accepted", "pending", "unknown"]>>;
|
|
601
|
+
production: Schema.transform<Schema.Enums<typeof DataProduction$1>, Schema.Literal<["backfill", "live", "unknown"]>>;
|
|
582
602
|
data: Schema.Array$<Schema.Schema<TA | null, Uint8Array, TR>>;
|
|
583
603
|
}>;
|
|
584
604
|
}>, Schema.Struct<{
|
|
@@ -611,6 +631,7 @@ type StreamDataResponse<TA> = ResponseWithoutData | {
|
|
|
611
631
|
cursor?: Cursor | undefined;
|
|
612
632
|
endCursor?: Cursor | undefined;
|
|
613
633
|
finality: DataFinality;
|
|
634
|
+
production: DataProduction;
|
|
614
635
|
data: readonly (TA | null)[];
|
|
615
636
|
};
|
|
616
637
|
};
|
|
@@ -644,6 +665,7 @@ declare class StreamConfig<TFilter, TBlock> {
|
|
|
644
665
|
cursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
645
666
|
endCursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
646
667
|
finality: Schema.transform<Schema.Enums<typeof DataFinality$1>, Schema.Literal<["finalized", "accepted", "pending", "unknown"]>>;
|
|
668
|
+
production: Schema.transform<Schema.Enums<typeof DataProduction$1>, Schema.Literal<["backfill", "live", "unknown"]>>;
|
|
647
669
|
data: Schema.Array$<Schema.Schema<TBlock | null, Uint8Array, never>>;
|
|
648
670
|
}>;
|
|
649
671
|
}>, Schema.Struct<{
|
|
@@ -672,13 +694,18 @@ declare class StreamConfig<TFilter, TBlock> {
|
|
|
672
694
|
}>]>;
|
|
673
695
|
}
|
|
674
696
|
|
|
697
|
+
declare class TimeoutError extends Error {
|
|
698
|
+
constructor(timeout: number);
|
|
699
|
+
}
|
|
675
700
|
/** Client call options. */
|
|
676
701
|
interface ClientCallOptions {
|
|
677
702
|
signal?: AbortSignal;
|
|
678
703
|
}
|
|
679
704
|
interface StreamDataOptions extends ClientCallOptions {
|
|
680
|
-
/** Stop at the specified cursor (inclusive) */
|
|
705
|
+
/** Stop at the specified cursor (inclusive). */
|
|
681
706
|
endingCursor?: Cursor;
|
|
707
|
+
/** Timeout between messages, in milliseconds. */
|
|
708
|
+
timeout?: number;
|
|
682
709
|
}
|
|
683
710
|
/** DNA client. */
|
|
684
711
|
interface Client<TFilter, TBlock> {
|
|
@@ -715,4 +742,4 @@ declare class StreamDataIterable<TBlock> {
|
|
|
715
742
|
[Symbol.asyncIterator](): AsyncIterator<StreamDataResponse<TBlock>>;
|
|
716
743
|
}
|
|
717
744
|
|
|
718
|
-
export { type
|
|
745
|
+
export { type ClientCallOptions as A, Bytes as B, type CursorProto as C, type DnaStreamClient as D, type StreamDataOptions as E, Finalize as F, type Client as G, Heartbeat as H, Invalidate as I, type CreateClientOptions as J, createClient as K, GrpcClient as L, StreamDataIterable as M, DataFinality$1 as N, DataProduction$1 as O, StatusRequest as S, TimeoutError as T, _Cursor as _, DnaStreamDefinition as a, BytesFromUint8Array as b, Cursor as c, createCursor as d, cursorToProto as e, cursorFromProto as f, CursorFromBytes as g, cursorToBytes as h, cursorFromBytes as i, isCursor as j, statusRequestToProto as k, statusRequestFromProto as l, StatusResponse as m, statusResponseToProto as n, statusResponseFromProto as o, DataFinality as p, DataProduction as q, Duration as r, stream as s, StreamDataRequest as t, StdOut as u, StdErr as v, SystemMessage as w, Data as x, StreamDataResponse as y, StreamConfig as z };
|
package/dist/testing/index.cjs
CHANGED
package/dist/testing/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as Client, t as StreamDataRequest, E as StreamDataOptions, y as StreamDataResponse, S as StatusRequest, A as ClientCallOptions, m as StatusResponse, z as StreamConfig, c as Cursor, C as CursorProto, N as DataFinality, O as DataProduction } from '../shared/protocol.ef662c22.cjs';
|
|
2
2
|
import { Schema } from '@effect/schema';
|
|
3
3
|
import 'nice-grpc';
|
|
4
4
|
import 'nice-grpc-common';
|
|
@@ -42,6 +42,7 @@ declare const MockStreamResponse: Schema.Union<[Schema.Struct<{
|
|
|
42
42
|
cursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
43
43
|
endCursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
44
44
|
finality: Schema.transform<Schema.Enums<typeof DataFinality>, Schema.Literal<["finalized", "accepted", "pending", "unknown"]>>;
|
|
45
|
+
production: Schema.transform<Schema.Enums<typeof DataProduction>, Schema.Literal<["backfill", "live", "unknown"]>>;
|
|
45
46
|
data: Schema.Array$<Schema.Schema<{
|
|
46
47
|
readonly data?: string | undefined;
|
|
47
48
|
} | null, Uint8Array, never>>;
|
package/dist/testing/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as Client, t as StreamDataRequest, E as StreamDataOptions, y as StreamDataResponse, S as StatusRequest, A as ClientCallOptions, m as StatusResponse, z as StreamConfig, c as Cursor, C as CursorProto, N as DataFinality, O as DataProduction } from '../shared/protocol.ef662c22.mjs';
|
|
2
2
|
import { Schema } from '@effect/schema';
|
|
3
3
|
import 'nice-grpc';
|
|
4
4
|
import 'nice-grpc-common';
|
|
@@ -42,6 +42,7 @@ declare const MockStreamResponse: Schema.Union<[Schema.Struct<{
|
|
|
42
42
|
cursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
43
43
|
endCursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
44
44
|
finality: Schema.transform<Schema.Enums<typeof DataFinality>, Schema.Literal<["finalized", "accepted", "pending", "unknown"]>>;
|
|
45
|
+
production: Schema.transform<Schema.Enums<typeof DataProduction>, Schema.Literal<["backfill", "live", "unknown"]>>;
|
|
45
46
|
data: Schema.Array$<Schema.Schema<{
|
|
46
47
|
readonly data?: string | undefined;
|
|
47
48
|
} | null, Uint8Array, never>>;
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as Client, t as StreamDataRequest, E as StreamDataOptions, y as StreamDataResponse, S as StatusRequest, A as ClientCallOptions, m as StatusResponse, z as StreamConfig, c as Cursor, C as CursorProto, N as DataFinality, O as DataProduction } from '../shared/protocol.ef662c22.js';
|
|
2
2
|
import { Schema } from '@effect/schema';
|
|
3
3
|
import 'nice-grpc';
|
|
4
4
|
import 'nice-grpc-common';
|
|
@@ -42,6 +42,7 @@ declare const MockStreamResponse: Schema.Union<[Schema.Struct<{
|
|
|
42
42
|
cursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
43
43
|
endCursor: Schema.optional<Schema.Schema<Cursor, CursorProto, never>>;
|
|
44
44
|
finality: Schema.transform<Schema.Enums<typeof DataFinality>, Schema.Literal<["finalized", "accepted", "pending", "unknown"]>>;
|
|
45
|
+
production: Schema.transform<Schema.Enums<typeof DataProduction>, Schema.Literal<["backfill", "live", "unknown"]>>;
|
|
45
46
|
data: Schema.Array$<Schema.Schema<{
|
|
46
47
|
readonly data?: string | undefined;
|
|
47
48
|
} | null, Uint8Array, never>>;
|
package/dist/testing/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from '@effect/schema';
|
|
2
|
-
import { M as MockFilter$1,
|
|
2
|
+
import { M as MockFilter$1, r as MockBlock$1, q as StreamConfig, S as StreamDataResponse } from '../shared/protocol.91527bce.mjs';
|
|
3
3
|
import 'protobufjs/minimal.js';
|
|
4
4
|
import 'effect';
|
|
5
5
|
import 'viem';
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -23,14 +23,25 @@ import { type StreamDataRequest, StreamDataResponse } from "./stream";
|
|
|
23
23
|
|
|
24
24
|
export { ClientError, Status } from "nice-grpc";
|
|
25
25
|
|
|
26
|
+
const DEFAULT_TIMEOUT_MS = 45_000;
|
|
27
|
+
|
|
28
|
+
export class TimeoutError extends Error {
|
|
29
|
+
constructor(timeout: number) {
|
|
30
|
+
super(`No message received in ${timeout}ms`);
|
|
31
|
+
this.name = "TimeoutError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
/** Client call options. */
|
|
27
36
|
export interface ClientCallOptions {
|
|
28
37
|
signal?: AbortSignal;
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
export interface StreamDataOptions extends ClientCallOptions {
|
|
32
|
-
/** Stop at the specified cursor (inclusive) */
|
|
41
|
+
/** Stop at the specified cursor (inclusive). */
|
|
33
42
|
endingCursor?: Cursor;
|
|
43
|
+
/** Timeout between messages, in milliseconds. */
|
|
44
|
+
timeout?: number;
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
/** DNA client. */
|
|
@@ -112,44 +123,61 @@ export class StreamDataIterable<TBlock> {
|
|
|
112
123
|
const inner = this.it[Symbol.asyncIterator]();
|
|
113
124
|
const schema = StreamDataResponse(this.schema);
|
|
114
125
|
const decoder = Schema.decodeSync(schema);
|
|
115
|
-
const { endingCursor } = this.options ?? {};
|
|
126
|
+
const { endingCursor, timeout = DEFAULT_TIMEOUT_MS } = this.options ?? {};
|
|
116
127
|
let shouldStop = false;
|
|
117
128
|
|
|
129
|
+
let clock: string | number | NodeJS.Timeout | undefined;
|
|
130
|
+
|
|
118
131
|
return {
|
|
119
132
|
async next() {
|
|
120
133
|
if (shouldStop) {
|
|
121
134
|
return { done: true, value: undefined };
|
|
122
135
|
}
|
|
123
136
|
|
|
124
|
-
|
|
137
|
+
// biome-ignore lint/suspicious/noExplicitAny: any is ok
|
|
138
|
+
const t: Promise<{ done: boolean; value: any }> = new Promise(
|
|
139
|
+
(_, reject) => {
|
|
140
|
+
clock = setTimeout(() => {
|
|
141
|
+
reject(new TimeoutError(timeout));
|
|
142
|
+
}, timeout);
|
|
143
|
+
},
|
|
144
|
+
);
|
|
125
145
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
146
|
+
try {
|
|
147
|
+
const { done, value } = await Promise.race([inner.next(), t]);
|
|
148
|
+
|
|
149
|
+
clearTimeout(clock);
|
|
150
|
+
|
|
151
|
+
if (done || value.message === undefined) {
|
|
152
|
+
return { done: true, value: undefined };
|
|
153
|
+
}
|
|
129
154
|
|
|
130
|
-
|
|
155
|
+
const decodedMessage = decoder(value.message);
|
|
131
156
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
157
|
+
if (endingCursor) {
|
|
158
|
+
assert(value.message.$case === "data");
|
|
159
|
+
assert(decodedMessage._tag === "data");
|
|
135
160
|
|
|
136
|
-
|
|
137
|
-
|
|
161
|
+
const { orderKey, uniqueKey } = endingCursor;
|
|
162
|
+
const endCursor = decodedMessage.data.endCursor;
|
|
138
163
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
164
|
+
// Check if the orderKey matches
|
|
165
|
+
if (orderKey === endCursor?.orderKey) {
|
|
166
|
+
// If a uniqueKey is specified, it must also match
|
|
167
|
+
if (!uniqueKey || uniqueKey === endCursor.uniqueKey) {
|
|
168
|
+
shouldStop = true;
|
|
169
|
+
return { done: false, value: decodedMessage };
|
|
170
|
+
}
|
|
145
171
|
}
|
|
146
172
|
}
|
|
147
|
-
}
|
|
148
173
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
174
|
+
return {
|
|
175
|
+
done: false,
|
|
176
|
+
value: decodedMessage,
|
|
177
|
+
};
|
|
178
|
+
} finally {
|
|
179
|
+
clearTimeout(clock);
|
|
180
|
+
}
|
|
153
181
|
},
|
|
154
182
|
};
|
|
155
183
|
}
|
package/src/proto/stream.ts
CHANGED
|
@@ -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/stream.test.ts
CHANGED
|
@@ -95,6 +95,7 @@ describe("StreamDataResponse", () => {
|
|
|
95
95
|
data: {
|
|
96
96
|
finality: "accepted",
|
|
97
97
|
data: [{ value: "hello" }, { value: "world" }],
|
|
98
|
+
production: "backfill",
|
|
98
99
|
},
|
|
99
100
|
} as const;
|
|
100
101
|
|
|
@@ -120,6 +121,7 @@ describe("StreamDataResponse", () => {
|
|
|
120
121
|
],
|
|
121
122
|
],
|
|
122
123
|
"finality": 2,
|
|
124
|
+
"production": 1,
|
|
123
125
|
},
|
|
124
126
|
}
|
|
125
127
|
`);
|
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,
|
|
@@ -112,6 +141,7 @@ export const Data = <TA, TR>(
|
|
|
112
141
|
cursor: Schema.optional(Cursor),
|
|
113
142
|
endCursor: Schema.optional(Cursor),
|
|
114
143
|
finality: DataFinality,
|
|
144
|
+
production: DataProduction,
|
|
115
145
|
data: Schema.Array(schema),
|
|
116
146
|
}),
|
|
117
147
|
});
|
|
@@ -136,6 +166,7 @@ export type StreamDataResponse<TA> =
|
|
|
136
166
|
cursor?: Cursor | undefined;
|
|
137
167
|
endCursor?: Cursor | undefined;
|
|
138
168
|
finality: DataFinality;
|
|
169
|
+
production: DataProduction;
|
|
139
170
|
data: readonly (TA | null)[];
|
|
140
171
|
};
|
|
141
172
|
};
|
|
@@ -9,7 +9,11 @@ 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
|
+
},
|
|
13
17
|
},
|
|
14
18
|
];
|
|
15
19
|
});
|
|
@@ -30,6 +34,7 @@ describe("MockClient", () => {
|
|
|
30
34
|
},
|
|
31
35
|
],
|
|
32
36
|
"finality": "finalized",
|
|
37
|
+
"production": "backfill",
|
|
33
38
|
},
|
|
34
39
|
},
|
|
35
40
|
]
|
|
@@ -41,7 +46,11 @@ describe("MockClient", () => {
|
|
|
41
46
|
return [
|
|
42
47
|
{
|
|
43
48
|
_tag: "data",
|
|
44
|
-
data: {
|
|
49
|
+
data: {
|
|
50
|
+
finality: "finalized",
|
|
51
|
+
data: [{ data: "hello" }, null],
|
|
52
|
+
production: "backfill",
|
|
53
|
+
},
|
|
45
54
|
},
|
|
46
55
|
];
|
|
47
56
|
});
|
|
@@ -63,6 +72,7 @@ describe("MockClient", () => {
|
|
|
63
72
|
null,
|
|
64
73
|
],
|
|
65
74
|
"finality": "finalized",
|
|
75
|
+
"production": "backfill",
|
|
66
76
|
},
|
|
67
77
|
},
|
|
68
78
|
]
|