@apibara/protocol 2.0.0-beta.5 → 2.0.0-beta.6

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 ADDED
@@ -0,0 +1,192 @@
1
+ 'use strict';
2
+
3
+ const config = require('./shared/protocol.474b6107.cjs');
4
+ const schema = require('@effect/schema');
5
+ const niceGrpc = require('nice-grpc');
6
+ require('protobufjs/minimal');
7
+ const assert = require('node:assert');
8
+ require('effect');
9
+ require('viem');
10
+ require('long');
11
+
12
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
13
+
14
+ const assert__default = /*#__PURE__*/_interopDefaultCompat(assert);
15
+
16
+ const index = {
17
+ __proto__: null,
18
+ stream: config.stream,
19
+ testing: config.testing
20
+ };
21
+
22
+ const StatusRequest = schema.Schema.Struct({});
23
+ const statusRequestToProto = schema.Schema.encodeSync(StatusRequest);
24
+ const statusRequestFromProto = schema.Schema.decodeSync(StatusRequest);
25
+ const StatusResponse = schema.Schema.Struct({
26
+ currentHead: schema.Schema.optional(config.Cursor),
27
+ lastIngested: schema.Schema.optional(config.Cursor),
28
+ finalized: schema.Schema.optional(config.Cursor),
29
+ starting: schema.Schema.optional(config.Cursor)
30
+ });
31
+ const statusResponseToProto = schema.Schema.encodeSync(StatusResponse);
32
+ const statusResponseFromProto = schema.Schema.decodeSync(StatusResponse);
33
+
34
+ var __defProp$1 = Object.defineProperty;
35
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
36
+ var __publicField$1 = (obj, key, value) => {
37
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
38
+ return value;
39
+ };
40
+ function createClient(config$1, streamUrl, defaultCallOptions) {
41
+ const channel = niceGrpc.createChannel(streamUrl);
42
+ const client = niceGrpc.createClient(
43
+ config.DnaStreamDefinition,
44
+ channel,
45
+ defaultCallOptions
46
+ );
47
+ return new GrpcClient(config$1, client);
48
+ }
49
+ class GrpcClient {
50
+ constructor(config, client) {
51
+ this.config = config;
52
+ this.client = client;
53
+ __publicField$1(this, "encodeRequest");
54
+ this.encodeRequest = schema.Schema.encodeSync(config.Request);
55
+ }
56
+ async status(request, options) {
57
+ const response = await this.client.status(
58
+ statusRequestToProto(request ?? {}),
59
+ options
60
+ );
61
+ return statusResponseFromProto(response);
62
+ }
63
+ streamData(request, options) {
64
+ const it = this.client.streamData(this.encodeRequest(request), options);
65
+ return new StreamDataIterable(it, this.config.Block, options);
66
+ }
67
+ }
68
+ class StreamDataIterable {
69
+ constructor(it, schema, options) {
70
+ this.it = it;
71
+ this.schema = schema;
72
+ this.options = options;
73
+ }
74
+ [Symbol.asyncIterator]() {
75
+ const inner = this.it[Symbol.asyncIterator]();
76
+ const schema$1 = config.StreamDataResponse(this.schema);
77
+ const decoder = schema.Schema.decodeSync(schema$1);
78
+ const { endingCursor } = this.options ?? {};
79
+ let shouldStop = false;
80
+ return {
81
+ async next() {
82
+ if (shouldStop) {
83
+ return { done: true, value: void 0 };
84
+ }
85
+ const { done, value } = await inner.next();
86
+ if (done || value.message === void 0) {
87
+ return { done: true, value: void 0 };
88
+ }
89
+ const decodedMessage = decoder(value.message);
90
+ if (endingCursor) {
91
+ assert__default(value.message.$case === "data");
92
+ assert__default(decodedMessage._tag === "data");
93
+ const { orderKey, uniqueKey } = endingCursor;
94
+ const endCursor = decodedMessage.data.endCursor;
95
+ if (orderKey === endCursor?.orderKey) {
96
+ if (!uniqueKey || uniqueKey === endCursor.uniqueKey) {
97
+ shouldStop = true;
98
+ return { done: false, value: decodedMessage };
99
+ }
100
+ }
101
+ }
102
+ return {
103
+ done: false,
104
+ value: decodedMessage
105
+ };
106
+ }
107
+ };
108
+ }
109
+ }
110
+
111
+ var __defProp = Object.defineProperty;
112
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
113
+ var __publicField = (obj, key, value) => {
114
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
115
+ return value;
116
+ };
117
+ class RateGauge {
118
+ constructor(intervalSeconds) {
119
+ __publicField(this, "interval");
120
+ __publicField(this, "prev");
121
+ __publicField(this, "rateMs");
122
+ __publicField(this, "var");
123
+ this.interval = intervalSeconds * 1e3;
124
+ this.var = 0;
125
+ }
126
+ record(items) {
127
+ const prev = this.prev;
128
+ const now = process.hrtime.bigint();
129
+ this.prev = now;
130
+ if (!prev) {
131
+ return;
132
+ }
133
+ const deltaMs = Number(now - prev) / 1e6;
134
+ const rateMs = items / deltaMs;
135
+ if (this.rateMs === void 0) {
136
+ this.rateMs = rateMs;
137
+ this.var = 0;
138
+ return;
139
+ }
140
+ const alpha = 1 - Math.exp(-deltaMs / this.interval);
141
+ this.rateMs = alpha * rateMs + (1 - alpha) * this.rateMs;
142
+ const diff = rateMs - this.rateMs;
143
+ const incr = alpha * diff;
144
+ this.var = (1 - alpha) * (this.var + incr * diff);
145
+ }
146
+ /** Returns the average rate per second. */
147
+ average() {
148
+ if (this.rateMs === void 0) {
149
+ return void 0;
150
+ }
151
+ return this.rateMs * 1e3;
152
+ }
153
+ /** Returns the variance. */
154
+ variance() {
155
+ return this.var;
156
+ }
157
+ }
158
+
159
+ exports.Bytes = config.Bytes;
160
+ exports.BytesFromUint8Array = config.BytesFromUint8Array;
161
+ exports.Cursor = config.Cursor;
162
+ exports.CursorFromBytes = config.CursorFromBytes;
163
+ exports.Data = config.Data;
164
+ exports.DataFinality = config.DataFinality;
165
+ exports.DnaStreamDefinition = config.DnaStreamDefinition;
166
+ exports.Duration = config.Duration;
167
+ exports.Finalize = config.Finalize;
168
+ exports.Heartbeat = config.Heartbeat;
169
+ exports.Invalidate = config.Invalidate;
170
+ exports.StdErr = config.StdErr;
171
+ exports.StdOut = config.StdOut;
172
+ exports.StreamConfig = config.StreamConfig;
173
+ exports.StreamDataRequest = config.StreamDataRequest;
174
+ exports.StreamDataResponse = config.StreamDataResponse;
175
+ exports.SystemMessage = config.SystemMessage;
176
+ exports._Cursor = config._Cursor;
177
+ exports.createCursor = config.createCursor;
178
+ exports.cursorFromBytes = config.cursorFromBytes;
179
+ exports.cursorFromProto = config.cursorFromProto;
180
+ exports.cursorToBytes = config.cursorToBytes;
181
+ exports.cursorToProto = config.cursorToProto;
182
+ exports.GrpcClient = GrpcClient;
183
+ exports.RateGauge = RateGauge;
184
+ exports.StatusRequest = StatusRequest;
185
+ exports.StatusResponse = StatusResponse;
186
+ exports.StreamDataIterable = StreamDataIterable;
187
+ exports.createClient = createClient;
188
+ exports.proto = index;
189
+ exports.statusRequestFromProto = statusRequestFromProto;
190
+ exports.statusRequestToProto = statusRequestToProto;
191
+ exports.statusResponseFromProto = statusResponseFromProto;
192
+ exports.statusResponseToProto = statusResponseToProto;
@@ -0,0 +1,71 @@
1
+ import { s as stream } from './shared/protocol.42d7ad57.cjs';
2
+ export { B as Bytes, b as BytesFromUint8Array, A as Client, y as ClientCallOptions, c as Cursor, g as CursorFromBytes, C as CursorProto, v as Data, o as DataFinality, D as DnaStreamClient, a as DnaStreamDefinition, p as Duration, F as Finalize, G as GrpcClient, H as Heartbeat, I as Invalidate, S as StatusRequest, l as StatusResponse, t as StdErr, r as StdOut, x as StreamConfig, J as StreamDataIterable, z as StreamDataOptions, q as StreamDataRequest, w as StreamDataResponse, u as SystemMessage, _ as _Cursor, E as createClient, d as createCursor, i as cursorFromBytes, f as cursorFromProto, h as cursorToBytes, e as cursorToProto, k as statusRequestFromProto, j as statusRequestToProto, n as statusResponseFromProto, m as statusResponseToProto } from './shared/protocol.42d7ad57.cjs';
3
+ import _m0 from 'protobufjs/minimal';
4
+ import '@effect/schema';
5
+ import 'nice-grpc';
6
+ import 'nice-grpc-common';
7
+ import '@effect/schema/AST';
8
+
9
+ declare const protobufPackage = "dna.v2.testing";
10
+ interface MockFilter {
11
+ readonly filter?: string | undefined;
12
+ }
13
+ declare const MockFilter: {
14
+ encode(message: MockFilter, writer?: _m0.Writer): _m0.Writer;
15
+ decode(input: _m0.Reader | Uint8Array, length?: number): MockFilter;
16
+ fromJSON(object: any): MockFilter;
17
+ toJSON(message: MockFilter): unknown;
18
+ create(base?: DeepPartial<MockFilter>): MockFilter;
19
+ fromPartial(object: DeepPartial<MockFilter>): MockFilter;
20
+ };
21
+ interface MockBlock {
22
+ readonly data?: string | undefined;
23
+ }
24
+ declare const MockBlock: {
25
+ encode(message: MockBlock, writer?: _m0.Writer): _m0.Writer;
26
+ decode(input: _m0.Reader | Uint8Array, length?: number): MockBlock;
27
+ fromJSON(object: any): MockBlock;
28
+ toJSON(message: MockBlock): unknown;
29
+ create(base?: DeepPartial<MockBlock>): MockBlock;
30
+ fromPartial(object: DeepPartial<MockBlock>): MockBlock;
31
+ };
32
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
33
+ type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
34
+ readonly $case: string;
35
+ } ? {
36
+ [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
37
+ } & {
38
+ readonly $case: T["$case"];
39
+ } : T extends {} ? {
40
+ [K in keyof T]?: DeepPartial<T[K]>;
41
+ } : Partial<T>;
42
+
43
+ type testing_DeepPartial<T> = DeepPartial<T>;
44
+ declare const testing_MockBlock: typeof MockBlock;
45
+ declare const testing_MockFilter: typeof MockFilter;
46
+ declare const testing_protobufPackage: typeof protobufPackage;
47
+ declare namespace testing {
48
+ export { type testing_DeepPartial as DeepPartial, testing_MockBlock as MockBlock, testing_MockFilter as MockFilter, testing_protobufPackage as protobufPackage };
49
+ }
50
+
51
+ declare const index_stream: typeof stream;
52
+ declare const index_testing: typeof testing;
53
+ declare namespace index {
54
+ export { index_stream as stream, index_testing as testing };
55
+ }
56
+
57
+ /** Track data rate using high precision timers. */
58
+ declare class RateGauge {
59
+ private interval;
60
+ private prev?;
61
+ private rateMs?;
62
+ private var;
63
+ constructor(intervalSeconds: number);
64
+ record(items: number): void;
65
+ /** Returns the average rate per second. */
66
+ average(): number | undefined;
67
+ /** Returns the variance. */
68
+ variance(): number;
69
+ }
70
+
71
+ export { RateGauge, index as proto };
@@ -0,0 +1,71 @@
1
+ import { s as stream } from './shared/protocol.42d7ad57.mjs';
2
+ export { B as Bytes, b as BytesFromUint8Array, A as Client, y as ClientCallOptions, c as Cursor, g as CursorFromBytes, C as CursorProto, v as Data, o as DataFinality, D as DnaStreamClient, a as DnaStreamDefinition, p as Duration, F as Finalize, G as GrpcClient, H as Heartbeat, I as Invalidate, S as StatusRequest, l as StatusResponse, t as StdErr, r as StdOut, x as StreamConfig, J as StreamDataIterable, z as StreamDataOptions, q as StreamDataRequest, w as StreamDataResponse, u as SystemMessage, _ as _Cursor, E as createClient, d as createCursor, i as cursorFromBytes, f as cursorFromProto, h as cursorToBytes, e as cursorToProto, k as statusRequestFromProto, j as statusRequestToProto, n as statusResponseFromProto, m as statusResponseToProto } from './shared/protocol.42d7ad57.mjs';
3
+ import _m0 from 'protobufjs/minimal';
4
+ import '@effect/schema';
5
+ import 'nice-grpc';
6
+ import 'nice-grpc-common';
7
+ import '@effect/schema/AST';
8
+
9
+ declare const protobufPackage = "dna.v2.testing";
10
+ interface MockFilter {
11
+ readonly filter?: string | undefined;
12
+ }
13
+ declare const MockFilter: {
14
+ encode(message: MockFilter, writer?: _m0.Writer): _m0.Writer;
15
+ decode(input: _m0.Reader | Uint8Array, length?: number): MockFilter;
16
+ fromJSON(object: any): MockFilter;
17
+ toJSON(message: MockFilter): unknown;
18
+ create(base?: DeepPartial<MockFilter>): MockFilter;
19
+ fromPartial(object: DeepPartial<MockFilter>): MockFilter;
20
+ };
21
+ interface MockBlock {
22
+ readonly data?: string | undefined;
23
+ }
24
+ declare const MockBlock: {
25
+ encode(message: MockBlock, writer?: _m0.Writer): _m0.Writer;
26
+ decode(input: _m0.Reader | Uint8Array, length?: number): MockBlock;
27
+ fromJSON(object: any): MockBlock;
28
+ toJSON(message: MockBlock): unknown;
29
+ create(base?: DeepPartial<MockBlock>): MockBlock;
30
+ fromPartial(object: DeepPartial<MockBlock>): MockBlock;
31
+ };
32
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
33
+ type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
34
+ readonly $case: string;
35
+ } ? {
36
+ [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
37
+ } & {
38
+ readonly $case: T["$case"];
39
+ } : T extends {} ? {
40
+ [K in keyof T]?: DeepPartial<T[K]>;
41
+ } : Partial<T>;
42
+
43
+ type testing_DeepPartial<T> = DeepPartial<T>;
44
+ declare const testing_MockBlock: typeof MockBlock;
45
+ declare const testing_MockFilter: typeof MockFilter;
46
+ declare const testing_protobufPackage: typeof protobufPackage;
47
+ declare namespace testing {
48
+ export { type testing_DeepPartial as DeepPartial, testing_MockBlock as MockBlock, testing_MockFilter as MockFilter, testing_protobufPackage as protobufPackage };
49
+ }
50
+
51
+ declare const index_stream: typeof stream;
52
+ declare const index_testing: typeof testing;
53
+ declare namespace index {
54
+ export { index_stream as stream, index_testing as testing };
55
+ }
56
+
57
+ /** Track data rate using high precision timers. */
58
+ declare class RateGauge {
59
+ private interval;
60
+ private prev?;
61
+ private rateMs?;
62
+ private var;
63
+ constructor(intervalSeconds: number);
64
+ record(items: number): void;
65
+ /** Returns the average rate per second. */
66
+ average(): number | undefined;
67
+ /** Returns the variance. */
68
+ variance(): number;
69
+ }
70
+
71
+ export { RateGauge, index as proto };
@@ -0,0 +1,71 @@
1
+ import { s as stream } from './shared/protocol.42d7ad57.js';
2
+ export { B as Bytes, b as BytesFromUint8Array, A as Client, y as ClientCallOptions, c as Cursor, g as CursorFromBytes, C as CursorProto, v as Data, o as DataFinality, D as DnaStreamClient, a as DnaStreamDefinition, p as Duration, F as Finalize, G as GrpcClient, H as Heartbeat, I as Invalidate, S as StatusRequest, l as StatusResponse, t as StdErr, r as StdOut, x as StreamConfig, J as StreamDataIterable, z as StreamDataOptions, q as StreamDataRequest, w as StreamDataResponse, u as SystemMessage, _ as _Cursor, E as createClient, d as createCursor, i as cursorFromBytes, f as cursorFromProto, h as cursorToBytes, e as cursorToProto, k as statusRequestFromProto, j as statusRequestToProto, n as statusResponseFromProto, m as statusResponseToProto } from './shared/protocol.42d7ad57.js';
3
+ import _m0 from 'protobufjs/minimal';
4
+ import '@effect/schema';
5
+ import 'nice-grpc';
6
+ import 'nice-grpc-common';
7
+ import '@effect/schema/AST';
8
+
9
+ declare const protobufPackage = "dna.v2.testing";
10
+ interface MockFilter {
11
+ readonly filter?: string | undefined;
12
+ }
13
+ declare const MockFilter: {
14
+ encode(message: MockFilter, writer?: _m0.Writer): _m0.Writer;
15
+ decode(input: _m0.Reader | Uint8Array, length?: number): MockFilter;
16
+ fromJSON(object: any): MockFilter;
17
+ toJSON(message: MockFilter): unknown;
18
+ create(base?: DeepPartial<MockFilter>): MockFilter;
19
+ fromPartial(object: DeepPartial<MockFilter>): MockFilter;
20
+ };
21
+ interface MockBlock {
22
+ readonly data?: string | undefined;
23
+ }
24
+ declare const MockBlock: {
25
+ encode(message: MockBlock, writer?: _m0.Writer): _m0.Writer;
26
+ decode(input: _m0.Reader | Uint8Array, length?: number): MockBlock;
27
+ fromJSON(object: any): MockBlock;
28
+ toJSON(message: MockBlock): unknown;
29
+ create(base?: DeepPartial<MockBlock>): MockBlock;
30
+ fromPartial(object: DeepPartial<MockBlock>): MockBlock;
31
+ };
32
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
33
+ type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
34
+ readonly $case: string;
35
+ } ? {
36
+ [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
37
+ } & {
38
+ readonly $case: T["$case"];
39
+ } : T extends {} ? {
40
+ [K in keyof T]?: DeepPartial<T[K]>;
41
+ } : Partial<T>;
42
+
43
+ type testing_DeepPartial<T> = DeepPartial<T>;
44
+ declare const testing_MockBlock: typeof MockBlock;
45
+ declare const testing_MockFilter: typeof MockFilter;
46
+ declare const testing_protobufPackage: typeof protobufPackage;
47
+ declare namespace testing {
48
+ export { type testing_DeepPartial as DeepPartial, testing_MockBlock as MockBlock, testing_MockFilter as MockFilter, testing_protobufPackage as protobufPackage };
49
+ }
50
+
51
+ declare const index_stream: typeof stream;
52
+ declare const index_testing: typeof testing;
53
+ declare namespace index {
54
+ export { index_stream as stream, index_testing as testing };
55
+ }
56
+
57
+ /** Track data rate using high precision timers. */
58
+ declare class RateGauge {
59
+ private interval;
60
+ private prev?;
61
+ private rateMs?;
62
+ private var;
63
+ constructor(intervalSeconds: number);
64
+ record(items: number): void;
65
+ /** Returns the average rate per second. */
66
+ average(): number | undefined;
67
+ /** Returns the variance. */
68
+ variance(): number;
69
+ }
70
+
71
+ export { RateGauge, index as proto };
package/dist/index.mjs ADDED
@@ -0,0 +1,154 @@
1
+ import { s as stream, t as testing, C as Cursor, D as DnaStreamDefinition, S as StreamDataResponse } from './shared/protocol.ff7dfded.mjs';
2
+ export { B as Bytes, a as BytesFromUint8Array, e as CursorFromBytes, n as Data, h as DataFinality, i as Duration, F as Finalize, H as Heartbeat, I as Invalidate, l as StdErr, k as StdOut, o as StreamConfig, j as StreamDataRequest, m as SystemMessage, _ as _Cursor, c as createCursor, g as cursorFromBytes, d as cursorFromProto, f as cursorToBytes, b as cursorToProto } from './shared/protocol.ff7dfded.mjs';
3
+ import { Schema } from '@effect/schema';
4
+ import { createChannel, createClient as createClient$1 } from 'nice-grpc';
5
+ import 'protobufjs/minimal';
6
+ import assert from 'node:assert';
7
+ import 'effect';
8
+ import 'viem';
9
+ import 'long';
10
+
11
+ const index = {
12
+ __proto__: null,
13
+ stream: stream,
14
+ testing: testing
15
+ };
16
+
17
+ const StatusRequest = Schema.Struct({});
18
+ const statusRequestToProto = Schema.encodeSync(StatusRequest);
19
+ const statusRequestFromProto = Schema.decodeSync(StatusRequest);
20
+ const StatusResponse = Schema.Struct({
21
+ currentHead: Schema.optional(Cursor),
22
+ lastIngested: Schema.optional(Cursor),
23
+ finalized: Schema.optional(Cursor),
24
+ starting: Schema.optional(Cursor)
25
+ });
26
+ const statusResponseToProto = Schema.encodeSync(StatusResponse);
27
+ const statusResponseFromProto = Schema.decodeSync(StatusResponse);
28
+
29
+ var __defProp$1 = Object.defineProperty;
30
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
31
+ var __publicField$1 = (obj, key, value) => {
32
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
33
+ return value;
34
+ };
35
+ function createClient(config, streamUrl, defaultCallOptions) {
36
+ const channel = createChannel(streamUrl);
37
+ const client = createClient$1(
38
+ DnaStreamDefinition,
39
+ channel,
40
+ defaultCallOptions
41
+ );
42
+ return new GrpcClient(config, client);
43
+ }
44
+ class GrpcClient {
45
+ constructor(config, client) {
46
+ this.config = config;
47
+ this.client = client;
48
+ __publicField$1(this, "encodeRequest");
49
+ this.encodeRequest = Schema.encodeSync(config.Request);
50
+ }
51
+ async status(request, options) {
52
+ const response = await this.client.status(
53
+ statusRequestToProto(request ?? {}),
54
+ options
55
+ );
56
+ return statusResponseFromProto(response);
57
+ }
58
+ streamData(request, options) {
59
+ const it = this.client.streamData(this.encodeRequest(request), options);
60
+ return new StreamDataIterable(it, this.config.Block, options);
61
+ }
62
+ }
63
+ class StreamDataIterable {
64
+ constructor(it, schema, options) {
65
+ this.it = it;
66
+ this.schema = schema;
67
+ this.options = options;
68
+ }
69
+ [Symbol.asyncIterator]() {
70
+ const inner = this.it[Symbol.asyncIterator]();
71
+ const schema = StreamDataResponse(this.schema);
72
+ const decoder = Schema.decodeSync(schema);
73
+ const { endingCursor } = this.options ?? {};
74
+ let shouldStop = false;
75
+ return {
76
+ async next() {
77
+ if (shouldStop) {
78
+ return { done: true, value: void 0 };
79
+ }
80
+ const { done, value } = await inner.next();
81
+ if (done || value.message === void 0) {
82
+ return { done: true, value: void 0 };
83
+ }
84
+ const decodedMessage = decoder(value.message);
85
+ if (endingCursor) {
86
+ assert(value.message.$case === "data");
87
+ assert(decodedMessage._tag === "data");
88
+ const { orderKey, uniqueKey } = endingCursor;
89
+ const endCursor = decodedMessage.data.endCursor;
90
+ if (orderKey === endCursor?.orderKey) {
91
+ if (!uniqueKey || uniqueKey === endCursor.uniqueKey) {
92
+ shouldStop = true;
93
+ return { done: false, value: decodedMessage };
94
+ }
95
+ }
96
+ }
97
+ return {
98
+ done: false,
99
+ value: decodedMessage
100
+ };
101
+ }
102
+ };
103
+ }
104
+ }
105
+
106
+ var __defProp = Object.defineProperty;
107
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
108
+ var __publicField = (obj, key, value) => {
109
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
110
+ return value;
111
+ };
112
+ class RateGauge {
113
+ constructor(intervalSeconds) {
114
+ __publicField(this, "interval");
115
+ __publicField(this, "prev");
116
+ __publicField(this, "rateMs");
117
+ __publicField(this, "var");
118
+ this.interval = intervalSeconds * 1e3;
119
+ this.var = 0;
120
+ }
121
+ record(items) {
122
+ const prev = this.prev;
123
+ const now = process.hrtime.bigint();
124
+ this.prev = now;
125
+ if (!prev) {
126
+ return;
127
+ }
128
+ const deltaMs = Number(now - prev) / 1e6;
129
+ const rateMs = items / deltaMs;
130
+ if (this.rateMs === void 0) {
131
+ this.rateMs = rateMs;
132
+ this.var = 0;
133
+ return;
134
+ }
135
+ const alpha = 1 - Math.exp(-deltaMs / this.interval);
136
+ this.rateMs = alpha * rateMs + (1 - alpha) * this.rateMs;
137
+ const diff = rateMs - this.rateMs;
138
+ const incr = alpha * diff;
139
+ this.var = (1 - alpha) * (this.var + incr * diff);
140
+ }
141
+ /** Returns the average rate per second. */
142
+ average() {
143
+ if (this.rateMs === void 0) {
144
+ return void 0;
145
+ }
146
+ return this.rateMs * 1e3;
147
+ }
148
+ /** Returns the variance. */
149
+ variance() {
150
+ return this.var;
151
+ }
152
+ }
153
+
154
+ export { Cursor, DnaStreamDefinition, GrpcClient, RateGauge, StatusRequest, StatusResponse, StreamDataIterable, StreamDataResponse, createClient, index as proto, statusRequestFromProto, statusRequestToProto, statusResponseFromProto, statusResponseToProto };