@apibara/protocol 2.1.0-beta.23 → 2.1.0-beta.25

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 +15 -29
  7. package/dist/index.d.cts +3 -4
  8. package/dist/index.d.mts +3 -4
  9. package/dist/index.d.ts +3 -4
  10. package/dist/index.mjs +14 -19
  11. package/dist/shared/{protocol.4b1cfe2c.d.cts → protocol.68a15d69.d.mts} +398 -247
  12. package/dist/shared/{protocol.4b1cfe2c.d.mts → protocol.8b5e318a.d.ts} +398 -247
  13. package/dist/shared/{protocol.991ff9ad.mjs → protocol.a64f7660.mjs} +173 -170
  14. package/dist/shared/{protocol.e39e40d6.cjs → protocol.d8bad371.cjs} +174 -176
  15. package/dist/shared/{protocol.4b1cfe2c.d.ts → protocol.f52df848.d.cts} +398 -247
  16. package/dist/testing/index.cjs +23 -37
  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 +23 -37
  21. package/package.json +7 -3
  22. package/src/client.ts +7 -12
  23. package/src/codec.ts +662 -0
  24. package/src/common.ts +70 -53
  25. package/src/config.ts +3 -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 +35 -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
package/dist/codec.cjs ADDED
@@ -0,0 +1,241 @@
1
+ 'use strict';
2
+
3
+ function MessageCodec(schema) {
4
+ return {
5
+ encode(app) {
6
+ return new Proxy(app, {
7
+ get(target, property) {
8
+ if (!Object.hasOwn(target, property)) {
9
+ return Reflect.get(target, property);
10
+ }
11
+ const v = Reflect.get(target, property);
12
+ return schema[property].encode(v);
13
+ }
14
+ });
15
+ },
16
+ decode(proto) {
17
+ return new Proxy(proto, {
18
+ get(target, property) {
19
+ if (!Object.hasOwn(target, property)) {
20
+ return Reflect.get(target, property);
21
+ }
22
+ const v = Reflect.get(target, property);
23
+ return schema[property].decode(v);
24
+ }
25
+ });
26
+ }
27
+ };
28
+ }
29
+ function ArrayCodec(t) {
30
+ return {
31
+ encode(app) {
32
+ return app.map(t.encode);
33
+ },
34
+ decode(proto) {
35
+ if (proto === void 0)
36
+ return [];
37
+ return proto.map(t.decode);
38
+ }
39
+ };
40
+ }
41
+ function MutableArrayCodec(t) {
42
+ return {
43
+ encode(app) {
44
+ return app.map(t.encode);
45
+ },
46
+ decode(proto) {
47
+ if (proto === void 0)
48
+ return [];
49
+ return proto.map(t.decode);
50
+ }
51
+ };
52
+ }
53
+ function OptionalCodec(t) {
54
+ return {
55
+ encode(app) {
56
+ if (app === void 0)
57
+ return void 0;
58
+ return t.encode(app);
59
+ },
60
+ decode(proto) {
61
+ if (proto === void 0)
62
+ return void 0;
63
+ return t.decode(proto);
64
+ }
65
+ };
66
+ }
67
+ function RequiredCodec(t) {
68
+ return {
69
+ encode(app) {
70
+ if (app === void 0)
71
+ throw new Error("Value is required but undefined");
72
+ return t.encode(app);
73
+ },
74
+ decode(proto) {
75
+ if (proto === void 0)
76
+ throw new Error("Value is required but undefined");
77
+ return t.decode(proto);
78
+ }
79
+ };
80
+ }
81
+ function NullOrCodec(t) {
82
+ return {
83
+ encode(app) {
84
+ if (app === null)
85
+ return null;
86
+ return t.encode(app);
87
+ },
88
+ decode(proto) {
89
+ if (proto === null)
90
+ return null;
91
+ return t.decode(proto);
92
+ }
93
+ };
94
+ }
95
+ const BigIntCodec = {
96
+ encode(app) {
97
+ return app;
98
+ },
99
+ decode(proto) {
100
+ return proto;
101
+ }
102
+ };
103
+ const NumberCodec = {
104
+ encode(app) {
105
+ return app;
106
+ },
107
+ decode(proto) {
108
+ return proto;
109
+ }
110
+ };
111
+ const Uint8ArrayCodec = {
112
+ encode(app) {
113
+ return app;
114
+ },
115
+ decode(proto) {
116
+ return proto;
117
+ }
118
+ };
119
+ const DateCodec = {
120
+ encode(app) {
121
+ return new Date(app);
122
+ },
123
+ decode(proto) {
124
+ return new Date(proto);
125
+ }
126
+ };
127
+ const BooleanCodec = {
128
+ encode(app) {
129
+ return app;
130
+ },
131
+ decode(proto) {
132
+ return proto;
133
+ }
134
+ };
135
+ const StringCodec = {
136
+ encode(app) {
137
+ return app;
138
+ },
139
+ decode(proto) {
140
+ return proto;
141
+ }
142
+ };
143
+ const UndefinedCodec = {
144
+ encode(app) {
145
+ return void 0;
146
+ },
147
+ decode(proto) {
148
+ return void 0;
149
+ }
150
+ };
151
+ const LiteralCodec = (value) => {
152
+ return {
153
+ encode(app) {
154
+ if (app !== value) {
155
+ throw new Error(`Expected ${String(value)}, got ${String(app)}`);
156
+ }
157
+ return app;
158
+ },
159
+ decode(proto) {
160
+ if (proto !== value) {
161
+ throw new Error(`Expected ${String(value)}, got ${String(proto)}`);
162
+ }
163
+ return proto;
164
+ }
165
+ };
166
+ };
167
+ const LiteralUnionCodec = (values) => {
168
+ return {
169
+ encode(app) {
170
+ if (!values.includes(app)) {
171
+ throw new Error(
172
+ `Expected one of [${values.join(", ")}], got ${String(app)}`
173
+ );
174
+ }
175
+ return app;
176
+ },
177
+ decode(proto) {
178
+ if (!values.includes(proto)) {
179
+ throw new Error(
180
+ `Expected one of [${values.join(", ")}], got ${String(proto)}`
181
+ );
182
+ }
183
+ return proto;
184
+ }
185
+ };
186
+ };
187
+ const VariantCodec = (options) => {
188
+ return {
189
+ encode(app) {
190
+ const tag = app[options.tag];
191
+ const codec = options.variants[tag];
192
+ if (!codec) {
193
+ throw new Error(`Unknown variant: ${String(tag)}`);
194
+ }
195
+ const variantData = app[tag];
196
+ const encodedData = codec.encode(variantData);
197
+ return {
198
+ [options.discriminator]: tag,
199
+ [tag]: encodedData
200
+ };
201
+ },
202
+ decode(proto) {
203
+ const tag = proto[options.discriminator];
204
+ const codec = options.variants[tag];
205
+ if (!codec) {
206
+ throw new Error(`Unknown variant: ${String(tag)}`);
207
+ }
208
+ const variantData = proto[tag];
209
+ const decodedData = codec.decode(variantData);
210
+ return {
211
+ [options.tag]: tag,
212
+ [tag]: decodedData
213
+ };
214
+ }
215
+ };
216
+ };
217
+ function OneOfCodec(variants) {
218
+ return VariantCodec({
219
+ tag: "_tag",
220
+ discriminator: "$case",
221
+ variants
222
+ });
223
+ }
224
+
225
+ exports.ArrayCodec = ArrayCodec;
226
+ exports.BigIntCodec = BigIntCodec;
227
+ exports.BooleanCodec = BooleanCodec;
228
+ exports.DateCodec = DateCodec;
229
+ exports.LiteralCodec = LiteralCodec;
230
+ exports.LiteralUnionCodec = LiteralUnionCodec;
231
+ exports.MessageCodec = MessageCodec;
232
+ exports.MutableArrayCodec = MutableArrayCodec;
233
+ exports.NullOrCodec = NullOrCodec;
234
+ exports.NumberCodec = NumberCodec;
235
+ exports.OneOfCodec = OneOfCodec;
236
+ exports.OptionalCodec = OptionalCodec;
237
+ exports.RequiredCodec = RequiredCodec;
238
+ exports.StringCodec = StringCodec;
239
+ exports.Uint8ArrayCodec = Uint8ArrayCodec;
240
+ exports.UndefinedCodec = UndefinedCodec;
241
+ exports.VariantCodec = VariantCodec;
@@ -0,0 +1,81 @@
1
+ /** Codec to encode and decode protobuf messages */
2
+ type Codec<TApp = unknown, TProto = unknown> = {
3
+ encode(app: TApp): TProto;
4
+ decode(proto: TProto): TApp;
5
+ };
6
+ type CodecType<C extends Codec> = ReturnType<C["decode"]>;
7
+ type CodecProto<C extends Codec> = ReturnType<C["encode"]>;
8
+ type Evaluate<T> = T extends infer O ? {
9
+ [K in keyof O]: O[K];
10
+ } : never;
11
+ type TPropertyKey = string | symbol;
12
+ type TProperties = Record<TPropertyKey, Codec>;
13
+ type OptionalPropertyKeys<T> = {
14
+ [K in keyof T]: undefined extends T[K] ? K : never;
15
+ }[keyof T];
16
+ type RequiredPropertyKeys<T> = keyof Omit<T, OptionalPropertyKeys<T>>;
17
+ type _MessageCodecType<T extends TProperties> = {
18
+ [K in keyof T]: CodecType<T[K]>;
19
+ };
20
+ type _MessageCodecProto<T extends TProperties> = {
21
+ [K in keyof T]: CodecProto<T[K]>;
22
+ };
23
+ type MessageCodecType<T extends TProperties> = _MessageCodecType<T> extends infer R ? Evaluate<Partial<R> & Required<Pick<R, RequiredPropertyKeys<R>>>> : never;
24
+ type MessageCodecProto<T extends TProperties> = _MessageCodecProto<T> extends infer R ? Evaluate<Partial<R> & Required<Pick<R, RequiredPropertyKeys<R>>>> : never;
25
+ type MessageCodec<T extends TProperties = TProperties> = Codec<MessageCodecType<T>, MessageCodecProto<T>>;
26
+ declare function MessageCodec<T extends TProperties>(schema: T): MessageCodec<T>;
27
+ type ArrayCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? Codec<readonly TApp[], readonly TProto[] | undefined> : never;
28
+ declare function ArrayCodec<T extends Codec<TApp, TProto>, TApp, TProto>(t: T): ArrayCodec<T>;
29
+ type MutableArrayCodec<T extends Codec<TApp, TProto>, TApp, TProto> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp[], TProto[]> : never;
30
+ declare function MutableArrayCodec<T extends Codec<TApp, TProto>, TApp, TProto>(t: T): MutableArrayCodec<T, TApp, TProto>;
31
+ type OptionalCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp | undefined, TProto | undefined> : never;
32
+ declare function OptionalCodec<T extends Codec>(t: T): OptionalCodec<T>;
33
+ type RequiredCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? TApp extends undefined ? never : Codec<TApp, TProto | undefined> : never;
34
+ declare function RequiredCodec<T extends Codec>(t: T): RequiredCodec<T>;
35
+ type NullOrCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp | null, TProto | null> : never;
36
+ declare function NullOrCodec<T extends Codec>(t: T): NullOrCodec<T>;
37
+ type BigIntCodec = CodecType<typeof BigIntCodec>;
38
+ declare const BigIntCodec: Codec<bigint, bigint>;
39
+ type NumberCodec = CodecType<typeof NumberCodec>;
40
+ declare const NumberCodec: Codec<number, number>;
41
+ type Uint8ArrayCodec = CodecType<typeof Uint8ArrayCodec>;
42
+ declare const Uint8ArrayCodec: Codec<Uint8Array, Uint8Array>;
43
+ type DateCodec = CodecType<typeof DateCodec>;
44
+ declare const DateCodec: Codec<Date, Date>;
45
+ type BooleanCodec = CodecType<typeof BooleanCodec>;
46
+ declare const BooleanCodec: Codec<boolean, boolean>;
47
+ type StringCodec = CodecType<typeof StringCodec>;
48
+ declare const StringCodec: Codec<string, string>;
49
+ type UndefinedCodec = CodecType<typeof UndefinedCodec>;
50
+ declare const UndefinedCodec: Codec<undefined, undefined>;
51
+ type Literal = string | number | boolean | null | undefined;
52
+ type LiteralCodec<T extends Codec, L extends Literal> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp, TProto> : never;
53
+ declare const LiteralCodec: <const L extends Literal>(value: L) => LiteralCodec<Codec<L, L>, L>;
54
+ type LiteralUnionCodec<T extends Codec, L extends readonly Literal[]> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp, TProto> : never;
55
+ declare const LiteralUnionCodec: <const L extends readonly Literal[]>(values: L) => LiteralUnionCodec<Codec<L[number], L[number]>, L>;
56
+ type AppVariantMap<TTag extends TPropertyKey, TVariants extends TProperties> = {
57
+ [K in keyof TVariants]: {
58
+ [P in TTag]: K;
59
+ } & (CodecType<TVariants[K]> extends UndefinedCodec ? {} : {
60
+ [P in K & TPropertyKey]: CodecType<TVariants[K]>;
61
+ });
62
+ };
63
+ type VariantCodecType<TTag extends TPropertyKey, TVariants extends TProperties> = AppVariantMap<TTag, TVariants>[keyof TVariants];
64
+ type ProtoVariantMap<TDiscriminator extends TPropertyKey, TVariants extends TProperties> = {
65
+ [K in keyof TVariants]: {
66
+ [P in TDiscriminator]: K;
67
+ } & {
68
+ [P in K & TPropertyKey]: CodecProto<TVariants[K]>;
69
+ };
70
+ };
71
+ type VariantCodecProto<TDiscriminator extends TPropertyKey, TVariants extends TProperties> = ProtoVariantMap<TDiscriminator, TVariants>[keyof TVariants];
72
+ type VariantCodec<T extends Codec, TTag extends TPropertyKey, TDiscriminator extends TPropertyKey> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp, TProto> : never;
73
+ declare const VariantCodec: <TTag extends TPropertyKey, TDiscriminator extends TPropertyKey, TVariants extends TProperties, TCodec extends Codec<VariantCodecType<TTag, TVariants>, VariantCodecProto<TDiscriminator, TVariants>>>(options: {
74
+ tag: TTag;
75
+ discriminator: TDiscriminator;
76
+ variants: TVariants;
77
+ }) => VariantCodec<TCodec, TTag, TDiscriminator>;
78
+ type OneOfCodec<TVariants extends TProperties> = VariantCodec<Codec<VariantCodecType<"_tag", TVariants>, VariantCodecProto<"$case", TVariants>>, "_tag", "$case">;
79
+ declare function OneOfCodec<TVariants extends TProperties>(variants: TVariants): OneOfCodec<TVariants>;
80
+
81
+ export { ArrayCodec, BigIntCodec, BooleanCodec, type Codec, type CodecProto, type CodecType, DateCodec, type Evaluate, LiteralCodec, LiteralUnionCodec, MessageCodec, MutableArrayCodec, NullOrCodec, NumberCodec, OneOfCodec, OptionalCodec, RequiredCodec, StringCodec, Uint8ArrayCodec, UndefinedCodec, VariantCodec };
@@ -0,0 +1,81 @@
1
+ /** Codec to encode and decode protobuf messages */
2
+ type Codec<TApp = unknown, TProto = unknown> = {
3
+ encode(app: TApp): TProto;
4
+ decode(proto: TProto): TApp;
5
+ };
6
+ type CodecType<C extends Codec> = ReturnType<C["decode"]>;
7
+ type CodecProto<C extends Codec> = ReturnType<C["encode"]>;
8
+ type Evaluate<T> = T extends infer O ? {
9
+ [K in keyof O]: O[K];
10
+ } : never;
11
+ type TPropertyKey = string | symbol;
12
+ type TProperties = Record<TPropertyKey, Codec>;
13
+ type OptionalPropertyKeys<T> = {
14
+ [K in keyof T]: undefined extends T[K] ? K : never;
15
+ }[keyof T];
16
+ type RequiredPropertyKeys<T> = keyof Omit<T, OptionalPropertyKeys<T>>;
17
+ type _MessageCodecType<T extends TProperties> = {
18
+ [K in keyof T]: CodecType<T[K]>;
19
+ };
20
+ type _MessageCodecProto<T extends TProperties> = {
21
+ [K in keyof T]: CodecProto<T[K]>;
22
+ };
23
+ type MessageCodecType<T extends TProperties> = _MessageCodecType<T> extends infer R ? Evaluate<Partial<R> & Required<Pick<R, RequiredPropertyKeys<R>>>> : never;
24
+ type MessageCodecProto<T extends TProperties> = _MessageCodecProto<T> extends infer R ? Evaluate<Partial<R> & Required<Pick<R, RequiredPropertyKeys<R>>>> : never;
25
+ type MessageCodec<T extends TProperties = TProperties> = Codec<MessageCodecType<T>, MessageCodecProto<T>>;
26
+ declare function MessageCodec<T extends TProperties>(schema: T): MessageCodec<T>;
27
+ type ArrayCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? Codec<readonly TApp[], readonly TProto[] | undefined> : never;
28
+ declare function ArrayCodec<T extends Codec<TApp, TProto>, TApp, TProto>(t: T): ArrayCodec<T>;
29
+ type MutableArrayCodec<T extends Codec<TApp, TProto>, TApp, TProto> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp[], TProto[]> : never;
30
+ declare function MutableArrayCodec<T extends Codec<TApp, TProto>, TApp, TProto>(t: T): MutableArrayCodec<T, TApp, TProto>;
31
+ type OptionalCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp | undefined, TProto | undefined> : never;
32
+ declare function OptionalCodec<T extends Codec>(t: T): OptionalCodec<T>;
33
+ type RequiredCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? TApp extends undefined ? never : Codec<TApp, TProto | undefined> : never;
34
+ declare function RequiredCodec<T extends Codec>(t: T): RequiredCodec<T>;
35
+ type NullOrCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp | null, TProto | null> : never;
36
+ declare function NullOrCodec<T extends Codec>(t: T): NullOrCodec<T>;
37
+ type BigIntCodec = CodecType<typeof BigIntCodec>;
38
+ declare const BigIntCodec: Codec<bigint, bigint>;
39
+ type NumberCodec = CodecType<typeof NumberCodec>;
40
+ declare const NumberCodec: Codec<number, number>;
41
+ type Uint8ArrayCodec = CodecType<typeof Uint8ArrayCodec>;
42
+ declare const Uint8ArrayCodec: Codec<Uint8Array, Uint8Array>;
43
+ type DateCodec = CodecType<typeof DateCodec>;
44
+ declare const DateCodec: Codec<Date, Date>;
45
+ type BooleanCodec = CodecType<typeof BooleanCodec>;
46
+ declare const BooleanCodec: Codec<boolean, boolean>;
47
+ type StringCodec = CodecType<typeof StringCodec>;
48
+ declare const StringCodec: Codec<string, string>;
49
+ type UndefinedCodec = CodecType<typeof UndefinedCodec>;
50
+ declare const UndefinedCodec: Codec<undefined, undefined>;
51
+ type Literal = string | number | boolean | null | undefined;
52
+ type LiteralCodec<T extends Codec, L extends Literal> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp, TProto> : never;
53
+ declare const LiteralCodec: <const L extends Literal>(value: L) => LiteralCodec<Codec<L, L>, L>;
54
+ type LiteralUnionCodec<T extends Codec, L extends readonly Literal[]> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp, TProto> : never;
55
+ declare const LiteralUnionCodec: <const L extends readonly Literal[]>(values: L) => LiteralUnionCodec<Codec<L[number], L[number]>, L>;
56
+ type AppVariantMap<TTag extends TPropertyKey, TVariants extends TProperties> = {
57
+ [K in keyof TVariants]: {
58
+ [P in TTag]: K;
59
+ } & (CodecType<TVariants[K]> extends UndefinedCodec ? {} : {
60
+ [P in K & TPropertyKey]: CodecType<TVariants[K]>;
61
+ });
62
+ };
63
+ type VariantCodecType<TTag extends TPropertyKey, TVariants extends TProperties> = AppVariantMap<TTag, TVariants>[keyof TVariants];
64
+ type ProtoVariantMap<TDiscriminator extends TPropertyKey, TVariants extends TProperties> = {
65
+ [K in keyof TVariants]: {
66
+ [P in TDiscriminator]: K;
67
+ } & {
68
+ [P in K & TPropertyKey]: CodecProto<TVariants[K]>;
69
+ };
70
+ };
71
+ type VariantCodecProto<TDiscriminator extends TPropertyKey, TVariants extends TProperties> = ProtoVariantMap<TDiscriminator, TVariants>[keyof TVariants];
72
+ type VariantCodec<T extends Codec, TTag extends TPropertyKey, TDiscriminator extends TPropertyKey> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp, TProto> : never;
73
+ declare const VariantCodec: <TTag extends TPropertyKey, TDiscriminator extends TPropertyKey, TVariants extends TProperties, TCodec extends Codec<VariantCodecType<TTag, TVariants>, VariantCodecProto<TDiscriminator, TVariants>>>(options: {
74
+ tag: TTag;
75
+ discriminator: TDiscriminator;
76
+ variants: TVariants;
77
+ }) => VariantCodec<TCodec, TTag, TDiscriminator>;
78
+ type OneOfCodec<TVariants extends TProperties> = VariantCodec<Codec<VariantCodecType<"_tag", TVariants>, VariantCodecProto<"$case", TVariants>>, "_tag", "$case">;
79
+ declare function OneOfCodec<TVariants extends TProperties>(variants: TVariants): OneOfCodec<TVariants>;
80
+
81
+ export { ArrayCodec, BigIntCodec, BooleanCodec, type Codec, type CodecProto, type CodecType, DateCodec, type Evaluate, LiteralCodec, LiteralUnionCodec, MessageCodec, MutableArrayCodec, NullOrCodec, NumberCodec, OneOfCodec, OptionalCodec, RequiredCodec, StringCodec, Uint8ArrayCodec, UndefinedCodec, VariantCodec };
@@ -0,0 +1,81 @@
1
+ /** Codec to encode and decode protobuf messages */
2
+ type Codec<TApp = unknown, TProto = unknown> = {
3
+ encode(app: TApp): TProto;
4
+ decode(proto: TProto): TApp;
5
+ };
6
+ type CodecType<C extends Codec> = ReturnType<C["decode"]>;
7
+ type CodecProto<C extends Codec> = ReturnType<C["encode"]>;
8
+ type Evaluate<T> = T extends infer O ? {
9
+ [K in keyof O]: O[K];
10
+ } : never;
11
+ type TPropertyKey = string | symbol;
12
+ type TProperties = Record<TPropertyKey, Codec>;
13
+ type OptionalPropertyKeys<T> = {
14
+ [K in keyof T]: undefined extends T[K] ? K : never;
15
+ }[keyof T];
16
+ type RequiredPropertyKeys<T> = keyof Omit<T, OptionalPropertyKeys<T>>;
17
+ type _MessageCodecType<T extends TProperties> = {
18
+ [K in keyof T]: CodecType<T[K]>;
19
+ };
20
+ type _MessageCodecProto<T extends TProperties> = {
21
+ [K in keyof T]: CodecProto<T[K]>;
22
+ };
23
+ type MessageCodecType<T extends TProperties> = _MessageCodecType<T> extends infer R ? Evaluate<Partial<R> & Required<Pick<R, RequiredPropertyKeys<R>>>> : never;
24
+ type MessageCodecProto<T extends TProperties> = _MessageCodecProto<T> extends infer R ? Evaluate<Partial<R> & Required<Pick<R, RequiredPropertyKeys<R>>>> : never;
25
+ type MessageCodec<T extends TProperties = TProperties> = Codec<MessageCodecType<T>, MessageCodecProto<T>>;
26
+ declare function MessageCodec<T extends TProperties>(schema: T): MessageCodec<T>;
27
+ type ArrayCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? Codec<readonly TApp[], readonly TProto[] | undefined> : never;
28
+ declare function ArrayCodec<T extends Codec<TApp, TProto>, TApp, TProto>(t: T): ArrayCodec<T>;
29
+ type MutableArrayCodec<T extends Codec<TApp, TProto>, TApp, TProto> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp[], TProto[]> : never;
30
+ declare function MutableArrayCodec<T extends Codec<TApp, TProto>, TApp, TProto>(t: T): MutableArrayCodec<T, TApp, TProto>;
31
+ type OptionalCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp | undefined, TProto | undefined> : never;
32
+ declare function OptionalCodec<T extends Codec>(t: T): OptionalCodec<T>;
33
+ type RequiredCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? TApp extends undefined ? never : Codec<TApp, TProto | undefined> : never;
34
+ declare function RequiredCodec<T extends Codec>(t: T): RequiredCodec<T>;
35
+ type NullOrCodec<T extends Codec> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp | null, TProto | null> : never;
36
+ declare function NullOrCodec<T extends Codec>(t: T): NullOrCodec<T>;
37
+ type BigIntCodec = CodecType<typeof BigIntCodec>;
38
+ declare const BigIntCodec: Codec<bigint, bigint>;
39
+ type NumberCodec = CodecType<typeof NumberCodec>;
40
+ declare const NumberCodec: Codec<number, number>;
41
+ type Uint8ArrayCodec = CodecType<typeof Uint8ArrayCodec>;
42
+ declare const Uint8ArrayCodec: Codec<Uint8Array, Uint8Array>;
43
+ type DateCodec = CodecType<typeof DateCodec>;
44
+ declare const DateCodec: Codec<Date, Date>;
45
+ type BooleanCodec = CodecType<typeof BooleanCodec>;
46
+ declare const BooleanCodec: Codec<boolean, boolean>;
47
+ type StringCodec = CodecType<typeof StringCodec>;
48
+ declare const StringCodec: Codec<string, string>;
49
+ type UndefinedCodec = CodecType<typeof UndefinedCodec>;
50
+ declare const UndefinedCodec: Codec<undefined, undefined>;
51
+ type Literal = string | number | boolean | null | undefined;
52
+ type LiteralCodec<T extends Codec, L extends Literal> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp, TProto> : never;
53
+ declare const LiteralCodec: <const L extends Literal>(value: L) => LiteralCodec<Codec<L, L>, L>;
54
+ type LiteralUnionCodec<T extends Codec, L extends readonly Literal[]> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp, TProto> : never;
55
+ declare const LiteralUnionCodec: <const L extends readonly Literal[]>(values: L) => LiteralUnionCodec<Codec<L[number], L[number]>, L>;
56
+ type AppVariantMap<TTag extends TPropertyKey, TVariants extends TProperties> = {
57
+ [K in keyof TVariants]: {
58
+ [P in TTag]: K;
59
+ } & (CodecType<TVariants[K]> extends UndefinedCodec ? {} : {
60
+ [P in K & TPropertyKey]: CodecType<TVariants[K]>;
61
+ });
62
+ };
63
+ type VariantCodecType<TTag extends TPropertyKey, TVariants extends TProperties> = AppVariantMap<TTag, TVariants>[keyof TVariants];
64
+ type ProtoVariantMap<TDiscriminator extends TPropertyKey, TVariants extends TProperties> = {
65
+ [K in keyof TVariants]: {
66
+ [P in TDiscriminator]: K;
67
+ } & {
68
+ [P in K & TPropertyKey]: CodecProto<TVariants[K]>;
69
+ };
70
+ };
71
+ type VariantCodecProto<TDiscriminator extends TPropertyKey, TVariants extends TProperties> = ProtoVariantMap<TDiscriminator, TVariants>[keyof TVariants];
72
+ type VariantCodec<T extends Codec, TTag extends TPropertyKey, TDiscriminator extends TPropertyKey> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp, TProto> : never;
73
+ declare const VariantCodec: <TTag extends TPropertyKey, TDiscriminator extends TPropertyKey, TVariants extends TProperties, TCodec extends Codec<VariantCodecType<TTag, TVariants>, VariantCodecProto<TDiscriminator, TVariants>>>(options: {
74
+ tag: TTag;
75
+ discriminator: TDiscriminator;
76
+ variants: TVariants;
77
+ }) => VariantCodec<TCodec, TTag, TDiscriminator>;
78
+ type OneOfCodec<TVariants extends TProperties> = VariantCodec<Codec<VariantCodecType<"_tag", TVariants>, VariantCodecProto<"$case", TVariants>>, "_tag", "$case">;
79
+ declare function OneOfCodec<TVariants extends TProperties>(variants: TVariants): OneOfCodec<TVariants>;
80
+
81
+ export { ArrayCodec, BigIntCodec, BooleanCodec, type Codec, type CodecProto, type CodecType, DateCodec, type Evaluate, LiteralCodec, LiteralUnionCodec, MessageCodec, MutableArrayCodec, NullOrCodec, NumberCodec, OneOfCodec, OptionalCodec, RequiredCodec, StringCodec, Uint8ArrayCodec, UndefinedCodec, VariantCodec };