@apibara/protocol 2.0.0-beta.2 → 2.0.0-beta.4
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/package.json +33 -45
- package/src/common.ts +2 -2
- package/src/proto/google/protobuf/duration.ts +189 -0
- package/src/proto/index.ts +1 -2
- package/src/proto/stream.ts +441 -10
- package/src/status.ts +2 -0
- package/src/stream.ts +22 -2
- package/CHANGELOG.md +0 -103
- package/LICENSE.txt +0 -202
- package/buf.gen.yaml +0 -14
- package/build.config.ts +0 -11
- package/dist/index.cjs +0 -189
- package/dist/index.d.cts +0 -72
- package/dist/index.d.mts +0 -72
- package/dist/index.d.ts +0 -72
- package/dist/index.mjs +0 -153
- package/dist/shared/protocol.6b1bdade.cjs +0 -1060
- package/dist/shared/protocol.a07a51b5.mjs +0 -1028
- package/dist/shared/protocol.e9aed6a3.d.cts +0 -549
- package/dist/shared/protocol.e9aed6a3.d.mts +0 -549
- package/dist/shared/protocol.e9aed6a3.d.ts +0 -549
- package/dist/testing/index.cjs +0 -105
- package/dist/testing/index.d.cts +0 -70
- package/dist/testing/index.d.mts +0 -70
- package/dist/testing/index.d.ts +0 -70
- package/dist/testing/index.mjs +0 -97
- package/proto/common.proto +0 -22
- package/proto/stream.proto +0 -83
- package/proto/testing.proto +0 -11
- package/src/proto/common.ts +0 -279
- package/tsconfig.json +0 -12
package/dist/index.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { c as common, s as stream } from './shared/protocol.e9aed6a3.js';
|
|
2
|
-
export { B as Bytes, b as BytesFromUint8Array, A as Client, y as ClientCallOptions, d as Cursor, h as CursorFromBytes, C as CursorProto, v as Data, p as DataFinality, D as DnaStreamClient, a as DnaStreamDefinition, G as GrpcClient, H as Heartbeat, I as Invalidate, S as StatusRequest, m as StatusResponse, t as StdErr, r as StdOut, x as StreamConfig, F as StreamDataIterable, z as StreamDataOptions, q as StreamDataRequest, w as StreamDataResponse, u as SystemMessage, _ as _Cursor, E as createClient, e as createCursor, j as cursorFromBytes, g as cursorFromProto, i as cursorToBytes, f as cursorToProto, l as statusRequestFromProto, k as statusRequestToProto, o as statusResponseFromProto, n as statusResponseToProto } from './shared/protocol.e9aed6a3.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_common: typeof common;
|
|
52
|
-
declare const index_stream: typeof stream;
|
|
53
|
-
declare const index_testing: typeof testing;
|
|
54
|
-
declare namespace index {
|
|
55
|
-
export { index_common as common, index_stream as stream, index_testing as testing };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Track data rate using high precision timers. */
|
|
59
|
-
declare class RateGauge {
|
|
60
|
-
private interval;
|
|
61
|
-
private prev?;
|
|
62
|
-
private rateMs?;
|
|
63
|
-
private var;
|
|
64
|
-
constructor(intervalSeconds: number);
|
|
65
|
-
record(items: number): void;
|
|
66
|
-
/** Returns the average rate per second. */
|
|
67
|
-
average(): number | undefined;
|
|
68
|
-
/** Returns the variance. */
|
|
69
|
-
variance(): number;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export { RateGauge, index as proto };
|
package/dist/index.mjs
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { c as common, s as stream, t as testing, C as Cursor, D as DnaStreamDefinition, S as StreamDataResponse } from './shared/protocol.a07a51b5.mjs';
|
|
2
|
-
export { B as Bytes, a as BytesFromUint8Array, f as CursorFromBytes, n as Data, i as DataFinality, H as Heartbeat, I as Invalidate, l as StdErr, k as StdOut, o as StreamConfig, j as StreamDataRequest, m as SystemMessage, _ as _Cursor, b as createCursor, h as cursorFromBytes, e as cursorFromProto, g as cursorToBytes, d as cursorToProto } from './shared/protocol.a07a51b5.mjs';
|
|
3
|
-
import { Schema } from '@effect/schema';
|
|
4
|
-
import { createChannel, createClient as createClient$1 } from 'nice-grpc';
|
|
5
|
-
import assert from 'node:assert';
|
|
6
|
-
import 'protobufjs/minimal';
|
|
7
|
-
import 'effect';
|
|
8
|
-
import 'viem';
|
|
9
|
-
import 'long';
|
|
10
|
-
|
|
11
|
-
const index = {
|
|
12
|
-
__proto__: null,
|
|
13
|
-
common: common,
|
|
14
|
-
stream: stream,
|
|
15
|
-
testing: testing
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const StatusRequest = Schema.Struct({});
|
|
19
|
-
const statusRequestToProto = Schema.encodeSync(StatusRequest);
|
|
20
|
-
const statusRequestFromProto = Schema.decodeSync(StatusRequest);
|
|
21
|
-
const StatusResponse = Schema.Struct({
|
|
22
|
-
currentHead: Schema.optional(Cursor),
|
|
23
|
-
lastIngested: Schema.optional(Cursor)
|
|
24
|
-
});
|
|
25
|
-
const statusResponseToProto = Schema.encodeSync(StatusResponse);
|
|
26
|
-
const statusResponseFromProto = Schema.decodeSync(StatusResponse);
|
|
27
|
-
|
|
28
|
-
var __defProp$1 = Object.defineProperty;
|
|
29
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
30
|
-
var __publicField$1 = (obj, key, value) => {
|
|
31
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
|
-
return value;
|
|
33
|
-
};
|
|
34
|
-
function createClient(config, streamUrl, defaultCallOptions) {
|
|
35
|
-
const channel = createChannel(streamUrl);
|
|
36
|
-
const client = createClient$1(
|
|
37
|
-
DnaStreamDefinition,
|
|
38
|
-
channel,
|
|
39
|
-
defaultCallOptions
|
|
40
|
-
);
|
|
41
|
-
return new GrpcClient(config, client);
|
|
42
|
-
}
|
|
43
|
-
class GrpcClient {
|
|
44
|
-
constructor(config, client) {
|
|
45
|
-
this.config = config;
|
|
46
|
-
this.client = client;
|
|
47
|
-
__publicField$1(this, "encodeRequest");
|
|
48
|
-
this.encodeRequest = Schema.encodeSync(config.Request);
|
|
49
|
-
}
|
|
50
|
-
async status(request, options) {
|
|
51
|
-
const response = await this.client.status(
|
|
52
|
-
statusRequestToProto(request ?? {}),
|
|
53
|
-
options
|
|
54
|
-
);
|
|
55
|
-
return statusResponseFromProto(response);
|
|
56
|
-
}
|
|
57
|
-
streamData(request, options) {
|
|
58
|
-
const it = this.client.streamData(this.encodeRequest(request), options);
|
|
59
|
-
return new StreamDataIterable(it, this.config.Block, options);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
class StreamDataIterable {
|
|
63
|
-
constructor(it, schema, options) {
|
|
64
|
-
this.it = it;
|
|
65
|
-
this.schema = schema;
|
|
66
|
-
this.options = options;
|
|
67
|
-
}
|
|
68
|
-
[Symbol.asyncIterator]() {
|
|
69
|
-
const inner = this.it[Symbol.asyncIterator]();
|
|
70
|
-
const schema = StreamDataResponse(this.schema);
|
|
71
|
-
const decoder = Schema.decodeSync(schema);
|
|
72
|
-
const { endingCursor } = this.options ?? {};
|
|
73
|
-
let shouldStop = false;
|
|
74
|
-
return {
|
|
75
|
-
async next() {
|
|
76
|
-
if (shouldStop) {
|
|
77
|
-
return { done: true, value: void 0 };
|
|
78
|
-
}
|
|
79
|
-
const { done, value } = await inner.next();
|
|
80
|
-
if (done || value.message === void 0) {
|
|
81
|
-
return { done: true, value: void 0 };
|
|
82
|
-
}
|
|
83
|
-
const decodedMessage = decoder(value.message);
|
|
84
|
-
if (endingCursor) {
|
|
85
|
-
assert(value.message.$case === "data");
|
|
86
|
-
assert(decodedMessage._tag === "data");
|
|
87
|
-
const { orderKey, uniqueKey } = endingCursor;
|
|
88
|
-
const endCursor = decodedMessage.data.endCursor;
|
|
89
|
-
if (orderKey === endCursor?.orderKey) {
|
|
90
|
-
if (!uniqueKey || uniqueKey === endCursor.uniqueKey) {
|
|
91
|
-
shouldStop = true;
|
|
92
|
-
return { done: false, value: decodedMessage };
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
done: false,
|
|
98
|
-
value: decodedMessage
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
var __defProp = Object.defineProperty;
|
|
106
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
107
|
-
var __publicField = (obj, key, value) => {
|
|
108
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
109
|
-
return value;
|
|
110
|
-
};
|
|
111
|
-
class RateGauge {
|
|
112
|
-
constructor(intervalSeconds) {
|
|
113
|
-
__publicField(this, "interval");
|
|
114
|
-
__publicField(this, "prev");
|
|
115
|
-
__publicField(this, "rateMs");
|
|
116
|
-
__publicField(this, "var");
|
|
117
|
-
this.interval = intervalSeconds * 1e3;
|
|
118
|
-
this.var = 0;
|
|
119
|
-
}
|
|
120
|
-
record(items) {
|
|
121
|
-
const prev = this.prev;
|
|
122
|
-
const now = process.hrtime.bigint();
|
|
123
|
-
this.prev = now;
|
|
124
|
-
if (!prev) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const deltaMs = Number(now - prev) / 1e6;
|
|
128
|
-
const rateMs = items / deltaMs;
|
|
129
|
-
if (this.rateMs === void 0) {
|
|
130
|
-
this.rateMs = rateMs;
|
|
131
|
-
this.var = 0;
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const alpha = 1 - Math.exp(-deltaMs / this.interval);
|
|
135
|
-
this.rateMs = alpha * rateMs + (1 - alpha) * this.rateMs;
|
|
136
|
-
const diff = rateMs - this.rateMs;
|
|
137
|
-
const incr = alpha * diff;
|
|
138
|
-
this.var = (1 - alpha) * (this.var + incr * diff);
|
|
139
|
-
}
|
|
140
|
-
/** Returns the average rate per second. */
|
|
141
|
-
average() {
|
|
142
|
-
if (this.rateMs === void 0) {
|
|
143
|
-
return void 0;
|
|
144
|
-
}
|
|
145
|
-
return this.rateMs * 1e3;
|
|
146
|
-
}
|
|
147
|
-
/** Returns the variance. */
|
|
148
|
-
variance() {
|
|
149
|
-
return this.var;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export { Cursor, DnaStreamDefinition, GrpcClient, RateGauge, StatusRequest, StatusResponse, StreamDataIterable, StreamDataResponse, createClient, index as proto, statusRequestFromProto, statusRequestToProto, statusResponseFromProto, statusResponseToProto };
|