@apibara/protocol 2.1.0-beta.3 → 2.1.0-beta.30

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.
Files changed (36) hide show
  1. package/dist/codec.cjs +241 -0
  2. package/dist/codec.d.cts +81 -0
  3. package/dist/codec.d.mts +81 -0
  4. package/dist/codec.d.ts +81 -0
  5. package/dist/codec.mjs +223 -0
  6. package/dist/index.cjs +17 -29
  7. package/dist/index.d.cts +4 -5
  8. package/dist/index.d.mts +4 -5
  9. package/dist/index.d.ts +4 -5
  10. package/dist/index.mjs +15 -20
  11. package/dist/shared/{protocol.4b1cfe2c.d.cts → protocol.21b07506.d.mts} +399 -247
  12. package/dist/shared/{protocol.4b1cfe2c.d.mts → protocol.526c6532.d.ts} +399 -247
  13. package/dist/shared/{protocol.e39e40d6.cjs → protocol.53f81a1e.cjs} +176 -177
  14. package/dist/shared/{protocol.991ff9ad.mjs → protocol.68fdd897.mjs} +175 -171
  15. package/dist/shared/{protocol.4b1cfe2c.d.ts → protocol.a5762a90.d.cts} +399 -247
  16. package/dist/testing/index.cjs +25 -38
  17. package/dist/testing/index.d.cts +107 -54
  18. package/dist/testing/index.d.mts +107 -54
  19. package/dist/testing/index.d.ts +107 -54
  20. package/dist/testing/index.mjs +25 -38
  21. package/package.json +7 -3
  22. package/src/client.ts +8 -13
  23. package/src/codec.ts +662 -0
  24. package/src/common.ts +70 -53
  25. package/src/config.ts +4 -4
  26. package/src/proto/google/protobuf/duration.ts +8 -6
  27. package/src/proto/stream.ts +38 -24
  28. package/src/status.ts +9 -16
  29. package/src/stream.ts +145 -144
  30. package/src/testing/mock.ts +36 -38
  31. package/src/common.test.ts +0 -67
  32. package/src/status.test.ts +0 -51
  33. package/src/stream.test-d.ts +0 -33
  34. package/src/stream.test.ts +0 -254
  35. package/src/testing/client.test.ts +0 -97
  36. package/src/testing/mock.test.ts +0 -35
@@ -1,7 +1,6 @@
1
- import { Schema } from '@effect/schema';
2
- import { M as MockFilter$1, u as MockBlock$1, r as StreamConfig, S as StreamDataResponse } from '../shared/protocol.991ff9ad.mjs';
1
+ import { MessageCodec, OptionalCodec, StringCodec } from '../codec.mjs';
2
+ import { l as StreamConfig, M as MockFilter$1, m as MockBlock, S as StreamDataResponse } from '../shared/protocol.68fdd897.mjs';
3
3
  import 'protobufjs/minimal.js';
4
- import 'effect';
5
4
  import 'viem';
6
5
  import 'long';
7
6
 
@@ -39,44 +38,31 @@ class StreamDataIterable {
39
38
  }
40
39
  }
41
40
 
42
- const MockFilter = Schema.Struct({
43
- filter: Schema.optional(Schema.String)
41
+ const MockFilter = MessageCodec({
42
+ filter: OptionalCodec(StringCodec)
44
43
  });
45
- const MockFilterFromBytes = Schema.transform(
46
- Schema.Uint8ArrayFromSelf,
47
- MockFilter,
48
- {
49
- strict: false,
50
- decode(value) {
51
- return MockFilter$1.decode(value);
52
- },
53
- encode(value) {
54
- return MockFilter$1.encode(value).finish();
55
- }
44
+ const MockFilterFromBytes = {
45
+ decode(value) {
46
+ return MockFilter$1.decode(value);
47
+ },
48
+ encode(value) {
49
+ return MockFilter$1.encode(value).finish();
56
50
  }
57
- );
58
- const MockBlock = Schema.Struct({
59
- data: Schema.optional(Schema.String)
60
- });
61
- const MockBlockFromBytes = Schema.transform(
62
- Schema.Uint8ArrayFromSelf,
63
- Schema.NullOr(MockBlock),
64
- {
65
- strict: false,
66
- decode(value) {
67
- if (value.length === 0) {
68
- return null;
69
- }
70
- return MockBlock$1.decode(value);
71
- },
72
- encode(value) {
73
- if (value === null) {
74
- return new Uint8Array();
75
- }
76
- return MockBlock$1.encode(value).finish();
51
+ };
52
+ const MockBlockFromBytes = {
53
+ decode(value) {
54
+ if (value.length === 0) {
55
+ return null;
56
+ }
57
+ return MockBlock.decode(value);
58
+ },
59
+ encode(value) {
60
+ if (value === null) {
61
+ return new Uint8Array();
77
62
  }
63
+ return MockBlock.encode(value).finish();
78
64
  }
79
- );
65
+ };
80
66
  function mergeMockFilter(a, b) {
81
67
  let filter = "";
82
68
  if (a.filter) {
@@ -90,7 +76,8 @@ function mergeMockFilter(a, b) {
90
76
  const MockStream = new StreamConfig(
91
77
  MockFilterFromBytes,
92
78
  MockBlockFromBytes,
93
- mergeMockFilter
79
+ mergeMockFilter,
80
+ "mock"
94
81
  );
95
82
  const MockStreamResponse = StreamDataResponse(MockBlockFromBytes);
96
83
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apibara/protocol",
3
- "version": "2.1.0-beta.3",
3
+ "version": "2.1.0-beta.30",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -21,6 +21,12 @@
21
21
  "import": "./dist/testing/index.mjs",
22
22
  "require": "./dist/testing/index.cjs",
23
23
  "default": "./dist/testing/index.mjs"
24
+ },
25
+ "./codec": {
26
+ "types": "./dist/codec.d.ts",
27
+ "import": "./dist/codec.mjs",
28
+ "require": "./dist/codec.cjs",
29
+ "default": "./dist/codec.mjs"
24
30
  }
25
31
  },
26
32
  "scripts": {
@@ -41,8 +47,6 @@
41
47
  "vitest": "^1.6.0"
42
48
  },
43
49
  "dependencies": {
44
- "@effect/schema": "^0.67.15",
45
- "effect": "^3.2.6",
46
50
  "long": "^5.2.3",
47
51
  "nice-grpc": "^2.1.8",
48
52
  "nice-grpc-common": "^2.0.2",
package/src/client.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { Schema } from "@effect/schema";
2
1
  import {
3
2
  type ChannelCredentials,
4
3
  type ChannelOptions,
@@ -11,17 +10,13 @@ import {
11
10
  import * as proto from "./proto";
12
11
 
13
12
  import assert from "node:assert";
13
+ import type { Codec } from "./codec";
14
14
  import type { Cursor } from "./common";
15
15
  import type { StreamConfig } from "./config";
16
- import {
17
- type StatusRequest,
18
- type StatusResponse,
19
- statusRequestToProto,
20
- statusResponseFromProto,
21
- } from "./status";
16
+ import { StatusRequest, StatusResponse } from "./status";
22
17
  import { type StreamDataRequest, StreamDataResponse } from "./stream";
23
18
 
24
- export { ClientError, Status } from "nice-grpc";
19
+ export { ClientError, ServerError, Status, Metadata } from "nice-grpc";
25
20
 
26
21
  const DEFAULT_TIMEOUT_MS = 45_000;
27
22
 
@@ -95,15 +90,15 @@ export class GrpcClient<TFilter, TBlock> implements Client<TFilter, TBlock> {
95
90
  private config: StreamConfig<TFilter, TBlock>,
96
91
  private client: proto.stream.DnaStreamClient,
97
92
  ) {
98
- this.encodeRequest = Schema.encodeSync(config.Request);
93
+ this.encodeRequest = config.Request.encode;
99
94
  }
100
95
 
101
96
  async status(request?: StatusRequest, options?: ClientCallOptions) {
102
97
  const response = await this.client.status(
103
- statusRequestToProto(request ?? {}),
98
+ StatusRequest.encode(request ?? {}),
104
99
  options,
105
100
  );
106
- return statusResponseFromProto(response);
101
+ return StatusResponse.decode(response);
107
102
  }
108
103
 
109
104
  streamData(request: StreamDataRequest<TFilter>, options?: StreamDataOptions) {
@@ -115,14 +110,14 @@ export class GrpcClient<TFilter, TBlock> implements Client<TFilter, TBlock> {
115
110
  export class StreamDataIterable<TBlock> {
116
111
  constructor(
117
112
  private it: AsyncIterable<proto.stream.StreamDataResponse>,
118
- private schema: Schema.Schema<TBlock | null, Uint8Array, never>,
113
+ private schema: Codec<TBlock, Uint8Array>,
119
114
  private options?: StreamDataOptions,
120
115
  ) {}
121
116
 
122
117
  [Symbol.asyncIterator](): AsyncIterator<StreamDataResponse<TBlock>> {
123
118
  const inner = this.it[Symbol.asyncIterator]();
124
119
  const schema = StreamDataResponse(this.schema);
125
- const decoder = Schema.decodeSync(schema);
120
+ const decoder = schema.decode;
126
121
  const { endingCursor, timeout = DEFAULT_TIMEOUT_MS } = this.options ?? {};
127
122
  let shouldStop = false;
128
123