@apibara/protocol 2.1.0-beta.23 → 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/src/stream.ts
CHANGED
|
@@ -1,179 +1,180 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ArrayCodec,
|
|
3
|
+
BigIntCodec,
|
|
4
|
+
type Codec,
|
|
5
|
+
type CodecType,
|
|
6
|
+
MessageCodec,
|
|
7
|
+
MutableArrayCodec,
|
|
8
|
+
NumberCodec,
|
|
9
|
+
OneOfCodec,
|
|
10
|
+
OptionalCodec,
|
|
11
|
+
StringCodec,
|
|
12
|
+
UndefinedCodec,
|
|
13
|
+
} from "./codec";
|
|
3
14
|
import { Cursor } from "./common";
|
|
4
15
|
import * as proto from "./proto";
|
|
5
16
|
|
|
6
17
|
/** Data finality. */
|
|
7
|
-
export const DataFinality
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
18
|
+
export const DataFinality: Codec<
|
|
19
|
+
"finalized" | "accepted" | "pending" | "unknown",
|
|
20
|
+
proto.stream.DataFinality
|
|
21
|
+
> = {
|
|
22
|
+
encode(x) {
|
|
23
|
+
const enumMap = {
|
|
24
|
+
finalized: proto.stream.DataFinality.FINALIZED,
|
|
25
|
+
accepted: proto.stream.DataFinality.ACCEPTED,
|
|
26
|
+
pending: proto.stream.DataFinality.PENDING,
|
|
27
|
+
unknown: proto.stream.DataFinality.UNKNOWN,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return enumMap[x] ?? proto.stream.DataFinality.UNKNOWN;
|
|
31
|
+
},
|
|
32
|
+
decode(p) {
|
|
33
|
+
const enumMap = {
|
|
34
|
+
[proto.stream.DataFinality.FINALIZED]: "finalized",
|
|
35
|
+
[proto.stream.DataFinality.ACCEPTED]: "accepted",
|
|
36
|
+
[proto.stream.DataFinality.PENDING]: "pending",
|
|
37
|
+
[proto.stream.DataFinality.UNKNOWN]: "unknown",
|
|
38
|
+
[proto.stream.DataFinality.UNRECOGNIZED]: "unknown",
|
|
39
|
+
} as const;
|
|
40
|
+
|
|
41
|
+
return enumMap[p] ?? "unknown";
|
|
32
42
|
},
|
|
33
|
-
|
|
43
|
+
};
|
|
34
44
|
|
|
35
|
-
export type DataFinality = typeof DataFinality
|
|
45
|
+
export type DataFinality = CodecType<typeof DataFinality>;
|
|
36
46
|
|
|
37
47
|
/** Data production mode. */
|
|
38
|
-
export const DataProduction
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
48
|
+
export const DataProduction: Codec<
|
|
49
|
+
"backfill" | "live" | "unknown",
|
|
50
|
+
proto.stream.DataProduction
|
|
51
|
+
> = {
|
|
52
|
+
encode(x) {
|
|
53
|
+
switch (x) {
|
|
54
|
+
case "backfill":
|
|
55
|
+
return proto.stream.DataProduction.BACKFILL;
|
|
56
|
+
case "live":
|
|
57
|
+
return proto.stream.DataProduction.LIVE;
|
|
58
|
+
case "unknown":
|
|
59
|
+
return proto.stream.DataProduction.UNKNOWN;
|
|
60
|
+
default:
|
|
61
|
+
return proto.stream.DataProduction.UNRECOGNIZED;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
decode(p) {
|
|
65
|
+
const enumMap = {
|
|
66
|
+
[proto.stream.DataProduction.BACKFILL]: "backfill",
|
|
67
|
+
[proto.stream.DataProduction.LIVE]: "live",
|
|
68
|
+
[proto.stream.DataProduction.UNKNOWN]: "unknown",
|
|
69
|
+
[proto.stream.DataProduction.UNRECOGNIZED]: "unknown",
|
|
70
|
+
} as const;
|
|
71
|
+
|
|
72
|
+
return enumMap[p] ?? "unknown";
|
|
61
73
|
},
|
|
62
|
-
|
|
74
|
+
};
|
|
63
75
|
|
|
64
|
-
export type DataProduction = typeof DataProduction
|
|
76
|
+
export type DataProduction = CodecType<typeof DataProduction>;
|
|
65
77
|
|
|
66
|
-
export const
|
|
67
|
-
seconds:
|
|
68
|
-
nanos:
|
|
78
|
+
export const DurationCodec = MessageCodec({
|
|
79
|
+
seconds: BigIntCodec,
|
|
80
|
+
nanos: NumberCodec,
|
|
69
81
|
});
|
|
70
82
|
|
|
83
|
+
export type Duration = CodecType<typeof DurationCodec>;
|
|
84
|
+
|
|
71
85
|
/** Create a `StreamDataRequest` with the given filter schema. */
|
|
72
|
-
export const StreamDataRequest = <TA,
|
|
73
|
-
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
filter: Schema.mutable(Schema.Array(filter)),
|
|
79
|
-
heartbeatInterval: Schema.optional(Duration),
|
|
86
|
+
export const StreamDataRequest = <TA>(filter: Codec<TA, Uint8Array>) =>
|
|
87
|
+
MessageCodec({
|
|
88
|
+
finality: OptionalCodec(DataFinality),
|
|
89
|
+
startingCursor: OptionalCodec(Cursor),
|
|
90
|
+
filter: MutableArrayCodec(filter),
|
|
91
|
+
heartbeatInterval: OptionalCodec(DurationCodec),
|
|
80
92
|
});
|
|
81
93
|
|
|
82
|
-
export type StreamDataRequest<TA> =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
filter: TA[];
|
|
86
|
-
};
|
|
94
|
+
export type StreamDataRequest<TA> = CodecType<
|
|
95
|
+
ReturnType<typeof StreamDataRequest<TA>>
|
|
96
|
+
>;
|
|
87
97
|
|
|
88
|
-
export const Invalidate =
|
|
89
|
-
|
|
90
|
-
invalidate: Schema.Struct({
|
|
91
|
-
cursor: Schema.optional(Cursor),
|
|
92
|
-
}),
|
|
98
|
+
export const Invalidate = MessageCodec({
|
|
99
|
+
cursor: OptionalCodec(Cursor),
|
|
93
100
|
});
|
|
94
101
|
|
|
95
|
-
export type Invalidate = typeof Invalidate
|
|
102
|
+
export type Invalidate = CodecType<typeof Invalidate>;
|
|
96
103
|
|
|
97
|
-
export const Finalize =
|
|
98
|
-
|
|
99
|
-
finalize: Schema.Struct({
|
|
100
|
-
cursor: Schema.optional(Cursor),
|
|
101
|
-
}),
|
|
104
|
+
export const Finalize = MessageCodec({
|
|
105
|
+
cursor: OptionalCodec(Cursor),
|
|
102
106
|
});
|
|
103
107
|
|
|
104
|
-
export type Finalize = typeof Finalize
|
|
108
|
+
export type Finalize = CodecType<typeof Finalize>;
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
});
|
|
110
|
+
// TODO: Double check this; This is a hack to make the heartbeat variant undefined
|
|
111
|
+
export const Heartbeat = UndefinedCodec;
|
|
109
112
|
|
|
110
|
-
export type Heartbeat = typeof Heartbeat
|
|
113
|
+
export type Heartbeat = CodecType<typeof Heartbeat>;
|
|
111
114
|
|
|
112
|
-
export const StdOut =
|
|
113
|
-
_tag: tag("stdout"),
|
|
114
|
-
stdout: Schema.String,
|
|
115
|
-
});
|
|
115
|
+
export const StdOut = StringCodec;
|
|
116
116
|
|
|
117
|
-
export type StdOut = typeof StdOut
|
|
117
|
+
export type StdOut = CodecType<typeof StdOut>;
|
|
118
118
|
|
|
119
|
-
export const StdErr =
|
|
120
|
-
_tag: tag("stderr"),
|
|
121
|
-
stderr: Schema.String,
|
|
122
|
-
});
|
|
119
|
+
export const StdErr = StringCodec;
|
|
123
120
|
|
|
124
|
-
export type StdErr = typeof StdErr
|
|
121
|
+
export type StdErr = CodecType<typeof StdErr>;
|
|
125
122
|
|
|
126
|
-
export const SystemMessage =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
export const SystemMessage = MessageCodec({
|
|
124
|
+
output: OneOfCodec({
|
|
125
|
+
stdout: StdOut,
|
|
126
|
+
stderr: StdErr,
|
|
130
127
|
}),
|
|
131
128
|
});
|
|
132
129
|
|
|
133
|
-
export type SystemMessage = typeof SystemMessage
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
schema:
|
|
137
|
-
) =>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
130
|
+
export type SystemMessage = CodecType<typeof SystemMessage>;
|
|
131
|
+
|
|
132
|
+
const _DataOrNull = <TA>(
|
|
133
|
+
schema: Codec<TA, Uint8Array>,
|
|
134
|
+
): Codec<TA | null, Uint8Array> => ({
|
|
135
|
+
encode(x) {
|
|
136
|
+
if (x === null) {
|
|
137
|
+
return new Uint8Array();
|
|
138
|
+
}
|
|
139
|
+
return schema.encode(x);
|
|
140
|
+
},
|
|
141
|
+
decode(p) {
|
|
142
|
+
if (p.length === 0) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
return schema.decode(p);
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
export const Data = <TA>(schema: Codec<TA | null, Uint8Array>) =>
|
|
150
|
+
MessageCodec({
|
|
151
|
+
cursor: OptionalCodec(Cursor),
|
|
152
|
+
endCursor: Cursor,
|
|
153
|
+
finality: DataFinality,
|
|
154
|
+
production: DataProduction,
|
|
155
|
+
data: ArrayCodec(_DataOrNull(schema)),
|
|
147
156
|
});
|
|
148
157
|
|
|
149
|
-
export
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
finality: DataFinality;
|
|
169
|
-
production: DataProduction;
|
|
170
|
-
data: readonly (TA | null)[];
|
|
171
|
-
};
|
|
172
|
-
};
|
|
158
|
+
export type Data<TA> = CodecType<ReturnType<typeof Data<TA>>>;
|
|
159
|
+
|
|
160
|
+
export const StreamDataResponse = <TA>(schema: Codec<TA | null, Uint8Array>) =>
|
|
161
|
+
OneOfCodec({
|
|
162
|
+
data: Data(schema),
|
|
163
|
+
invalidate: Invalidate,
|
|
164
|
+
finalize: Finalize,
|
|
165
|
+
heartbeat: Heartbeat,
|
|
166
|
+
systemMessage: SystemMessage,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
export const ResponseWithoutData = OneOfCodec({
|
|
170
|
+
invalidate: Invalidate,
|
|
171
|
+
finalize: Finalize,
|
|
172
|
+
heartbeat: Heartbeat,
|
|
173
|
+
systemMessage: SystemMessage,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
export type ResponseWithoutData = CodecType<typeof ResponseWithoutData>;
|
|
173
177
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
Schema.fromKey("$case"),
|
|
178
|
-
);
|
|
179
|
-
}
|
|
178
|
+
export type StreamDataResponse<TA> = CodecType<
|
|
179
|
+
ReturnType<typeof StreamDataResponse<TA>>
|
|
180
|
+
>;
|
package/src/testing/mock.ts
CHANGED
|
@@ -1,53 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type Codec,
|
|
3
|
+
type CodecType,
|
|
4
|
+
MessageCodec,
|
|
5
|
+
OptionalCodec,
|
|
6
|
+
StringCodec,
|
|
7
|
+
} from "../codec";
|
|
2
8
|
import { StreamConfig } from "../config";
|
|
3
9
|
import * as proto from "../proto";
|
|
4
10
|
import { StreamDataResponse } from "../stream";
|
|
5
11
|
|
|
6
|
-
export const MockFilter =
|
|
7
|
-
filter:
|
|
12
|
+
export const MockFilter = MessageCodec({
|
|
13
|
+
filter: OptionalCodec(StringCodec),
|
|
8
14
|
});
|
|
9
15
|
|
|
10
|
-
export type MockFilter = typeof MockFilter
|
|
16
|
+
export type MockFilter = CodecType<typeof MockFilter>;
|
|
11
17
|
|
|
12
|
-
export const MockFilterFromBytes =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
strict: false,
|
|
17
|
-
decode(value) {
|
|
18
|
-
return proto.testing.MockFilter.decode(value);
|
|
19
|
-
},
|
|
20
|
-
encode(value) {
|
|
21
|
-
return proto.testing.MockFilter.encode(value).finish();
|
|
22
|
-
},
|
|
18
|
+
export const MockFilterFromBytes: Codec<MockFilter, Uint8Array> = {
|
|
19
|
+
decode(value) {
|
|
20
|
+
return proto.testing.MockFilter.decode(value);
|
|
23
21
|
},
|
|
24
|
-
)
|
|
22
|
+
encode(value) {
|
|
23
|
+
return proto.testing.MockFilter.encode(value).finish();
|
|
24
|
+
},
|
|
25
|
+
};
|
|
25
26
|
|
|
26
|
-
const MockBlock =
|
|
27
|
-
data:
|
|
27
|
+
const MockBlock = MessageCodec({
|
|
28
|
+
data: OptionalCodec(StringCodec),
|
|
28
29
|
});
|
|
29
30
|
|
|
30
|
-
export type MockBlock = typeof MockBlock
|
|
31
|
+
export type MockBlock = CodecType<typeof MockBlock>;
|
|
31
32
|
|
|
32
|
-
export const MockBlockFromBytes =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
decode(value)
|
|
38
|
-
if (value.length === 0) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
return proto.testing.MockBlock.decode(value);
|
|
42
|
-
},
|
|
43
|
-
encode(value) {
|
|
44
|
-
if (value === null) {
|
|
45
|
-
return new Uint8Array();
|
|
46
|
-
}
|
|
47
|
-
return proto.testing.MockBlock.encode(value).finish();
|
|
48
|
-
},
|
|
33
|
+
export const MockBlockFromBytes: Codec<MockBlock | null, Uint8Array> = {
|
|
34
|
+
decode(value) {
|
|
35
|
+
if (value.length === 0) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return proto.testing.MockBlock.decode(value);
|
|
49
39
|
},
|
|
50
|
-
)
|
|
40
|
+
encode(value) {
|
|
41
|
+
if (value === null) {
|
|
42
|
+
return new Uint8Array();
|
|
43
|
+
}
|
|
44
|
+
return proto.testing.MockBlock.encode(value).finish();
|
|
45
|
+
},
|
|
46
|
+
};
|
|
51
47
|
|
|
52
48
|
/** For testing, simply concatenate the values of `.filter` */
|
|
53
49
|
function mergeMockFilter(a: MockFilter, b: MockFilter): MockFilter {
|
|
@@ -68,4 +64,5 @@ export const MockStream = new StreamConfig(
|
|
|
68
64
|
);
|
|
69
65
|
|
|
70
66
|
export const MockStreamResponse = StreamDataResponse(MockBlockFromBytes);
|
|
71
|
-
|
|
67
|
+
|
|
68
|
+
export type MockStreamResponse = CodecType<typeof MockStreamResponse>;
|
package/src/common.test.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { createCursor, cursorFromProto, cursorToProto } from "./common";
|
|
3
|
-
|
|
4
|
-
describe("Cursor", () => {
|
|
5
|
-
describe("proto", () => {
|
|
6
|
-
it("should encode and decode (with uniqueKey)", () => {
|
|
7
|
-
const cursor = createCursor({
|
|
8
|
-
orderKey: 123n,
|
|
9
|
-
uniqueKey: "0xcafecafe",
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const proto = cursorToProto(cursor);
|
|
13
|
-
expect(proto).toMatchInlineSnapshot(`
|
|
14
|
-
{
|
|
15
|
-
"orderKey": 123n,
|
|
16
|
-
"uniqueKey": Uint8Array [
|
|
17
|
-
202,
|
|
18
|
-
254,
|
|
19
|
-
202,
|
|
20
|
-
254,
|
|
21
|
-
],
|
|
22
|
-
}
|
|
23
|
-
`);
|
|
24
|
-
const back = cursorFromProto(proto);
|
|
25
|
-
expect(back).toEqual(cursor);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("should encode and decode (without uniqueKey)", () => {
|
|
29
|
-
const cursor = createCursor({
|
|
30
|
-
orderKey: 123n,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const proto = cursorToProto(cursor);
|
|
34
|
-
expect(proto).toMatchInlineSnapshot(`
|
|
35
|
-
{
|
|
36
|
-
"orderKey": 123n,
|
|
37
|
-
"uniqueKey": Uint8Array [],
|
|
38
|
-
}
|
|
39
|
-
`);
|
|
40
|
-
const back = cursorFromProto(proto);
|
|
41
|
-
expect(back).toEqual(cursor);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("bytes", () => {
|
|
46
|
-
it("should encode and decode (with uniqueKey)", () => {
|
|
47
|
-
const cursor = createCursor({
|
|
48
|
-
orderKey: 123n,
|
|
49
|
-
uniqueKey: "0xcafecafe",
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const proto = cursorToProto(cursor);
|
|
53
|
-
const back = cursorFromProto(proto);
|
|
54
|
-
expect(back).toEqual(cursor);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should encode and decode (without uniqueKey)", () => {
|
|
58
|
-
const cursor = createCursor({
|
|
59
|
-
orderKey: 123n,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const proto = cursorToProto(cursor);
|
|
63
|
-
const back = cursorFromProto(proto);
|
|
64
|
-
expect(back).toEqual(cursor);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
package/src/status.test.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
StatusResponse,
|
|
5
|
-
statusRequestFromProto,
|
|
6
|
-
statusRequestToProto,
|
|
7
|
-
statusResponseFromProto,
|
|
8
|
-
statusResponseToProto,
|
|
9
|
-
} from "./status";
|
|
10
|
-
|
|
11
|
-
describe("StatusRequest", () => {
|
|
12
|
-
describe("proto", () => {
|
|
13
|
-
it("should encode and decode", () => {
|
|
14
|
-
const proto = statusRequestToProto({});
|
|
15
|
-
expect(proto).toMatchInlineSnapshot("{}");
|
|
16
|
-
const back = statusRequestFromProto(proto);
|
|
17
|
-
expect(back).toEqual({});
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe("StatusResponse", () => {
|
|
23
|
-
describe("proto", () => {
|
|
24
|
-
it("should encode and decode", () => {
|
|
25
|
-
const response = StatusResponse.make({
|
|
26
|
-
currentHead: {
|
|
27
|
-
orderKey: 123n,
|
|
28
|
-
},
|
|
29
|
-
lastIngested: {
|
|
30
|
-
orderKey: 123n,
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const proto = statusResponseToProto(response);
|
|
35
|
-
expect(proto).toMatchInlineSnapshot(`
|
|
36
|
-
{
|
|
37
|
-
"currentHead": {
|
|
38
|
-
"orderKey": 123n,
|
|
39
|
-
"uniqueKey": Uint8Array [],
|
|
40
|
-
},
|
|
41
|
-
"lastIngested": {
|
|
42
|
-
"orderKey": 123n,
|
|
43
|
-
"uniqueKey": Uint8Array [],
|
|
44
|
-
},
|
|
45
|
-
}
|
|
46
|
-
`);
|
|
47
|
-
const back = statusResponseFromProto(proto);
|
|
48
|
-
expect(back).toEqual(response);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
package/src/stream.test-d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Schema } from "@effect/schema";
|
|
2
|
-
import { test } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { Data } from "./stream";
|
|
5
|
-
|
|
6
|
-
const Inner = Schema.Struct({
|
|
7
|
-
data: Schema.String,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const Good = Schema.transform(Schema.Uint8ArrayFromSelf, Schema.NullOr(Inner), {
|
|
11
|
-
decode(value) {
|
|
12
|
-
throw new Error("not implemented");
|
|
13
|
-
},
|
|
14
|
-
encode(value) {
|
|
15
|
-
throw new Error("not implemented");
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const Bad = Schema.transform(Schema.Uint8ArrayFromSelf, Inner, {
|
|
20
|
-
decode(value) {
|
|
21
|
-
throw new Error("not implemented");
|
|
22
|
-
},
|
|
23
|
-
encode(value) {
|
|
24
|
-
throw new Error("not implemented");
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test("Data", () => {
|
|
29
|
-
const GoodData = Data(Good);
|
|
30
|
-
|
|
31
|
-
// @ts-expect-error
|
|
32
|
-
const BadData = Data(Bad);
|
|
33
|
-
});
|