@apibara/protocol 2.1.0-beta.4 → 2.1.0-beta.40
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 +242 -0
- package/dist/codec.cjs.map +1 -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 +224 -0
- package/dist/codec.mjs.map +1 -0
- package/dist/index.cjs +43 -30
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -5
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.mjs +40 -22
- package/dist/index.mjs.map +1 -0
- package/dist/shared/{protocol.4b1cfe2c.d.cts → protocol.0e734e33.d.cts} +400 -247
- package/dist/shared/{protocol.4b1cfe2c.d.mts → protocol.21e66b9e.d.mts} +400 -247
- package/dist/shared/{protocol.e39e40d6.cjs → protocol.53f81a1e.cjs} +177 -177
- package/dist/shared/protocol.53f81a1e.cjs.map +1 -0
- package/dist/shared/{protocol.991ff9ad.mjs → protocol.68fdd897.mjs} +176 -171
- package/dist/shared/protocol.68fdd897.mjs.map +1 -0
- package/dist/shared/{protocol.4b1cfe2c.d.ts → protocol.8fb09325.d.ts} +400 -247
- package/dist/testing/index.cjs +26 -38
- package/dist/testing/index.cjs.map +1 -0
- 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 +26 -38
- package/dist/testing/index.mjs.map +1 -0
- package/package.json +8 -3
- package/src/client.ts +39 -14
- package/src/codec.ts +662 -0
- package/src/common.ts +70 -53
- package/src/config.ts +4 -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 +36 -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/dist/codec.cjs
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
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;
|
|
242
|
+
//# sourceMappingURL=codec.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.cjs","sources":["../src/codec.ts"],"sourcesContent":["/*\n\n █████████ █████ \n ███░░░░░███ ░░███ \n ███ ░░░ ██████ ███████ ██████ ██████ \n░███ ███░░███ ███░░███ ███░░███ ███░░███\n░███ ░███ ░███░███ ░███ ░███████ ░███ ░░░ \n░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ███\n ░░█████████ ░░██████ ░░████████░░██████ ░░██████ \n ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░ \n \n*/\n\n/** Codec to encode and decode protobuf messages */\nexport type Codec<TApp = unknown, TProto = unknown> = {\n encode(app: TApp): TProto;\n decode(proto: TProto): TApp;\n};\n\n/* Helper to get the high-level type of a codec */\nexport type CodecType<C extends Codec> = ReturnType<C[\"decode\"]>;\n\n/* Helper to get the protobuf type of a codec */\nexport type CodecProto<C extends Codec> = ReturnType<C[\"encode\"]>;\n\n/*\n \n ██████ ██████ \n░░██████ ██████ \n ░███░█████░███ ██████ █████ █████ ██████ ███████ ██████ \n ░███░░███ ░███ ███░░███ ███░░ ███░░ ░░░░░███ ███░░███ ███░░███\n ░███ ░░░ ░███ ░███████ ░░█████ ░░█████ ███████ ░███ ░███░███████ \n ░███ ░███ ░███░░░ ░░░░███ ░░░░███ ███░░███ ░███ ░███░███░░░ \n █████ █████░░██████ ██████ ██████ ░░████████░░███████░░██████ \n░░░░░ ░░░░░ ░░░░░░ ░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░███ ░░░░░░ \n ███ ░███ \n ░░██████ \n ░░░░░░ \n*/\n\nexport type Evaluate<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;\n\ntype TPropertyKey = string | symbol;\n// Message properties as codec.\ntype TProperties = Record<TPropertyKey, Codec>;\n\n// Optional properties in an object.\n// Properties are optional when they have the `undefined` type.\ntype OptionalPropertyKeys<T> = {\n [K in keyof T]: undefined extends T[K] ? K : never;\n}[keyof T];\n\n// Properties that are not optional are required.\ntype RequiredPropertyKeys<T> = keyof Omit<T, OptionalPropertyKeys<T>>;\n\n// Helper to get the app type of a message codec.\ntype _MessageCodecType<T extends TProperties> = {\n [K in keyof T]: CodecType<T[K]>;\n};\n\n// Helper to get the protobuf type of a message codec.\ntype _MessageCodecProto<T extends TProperties> = {\n [K in keyof T]: CodecProto<T[K]>;\n};\n\n// Adjust the app type of the codec so that optional properties are optional.\ntype MessageCodecType<T extends TProperties> =\n _MessageCodecType<T> extends infer R\n ? Evaluate<Partial<R> & Required<Pick<R, RequiredPropertyKeys<R>>>>\n : never;\n\n// Adjust the protobuf type of the codec so that optional properties are optional.\ntype MessageCodecProto<T extends TProperties> =\n _MessageCodecProto<T> extends infer R\n ? Evaluate<Partial<R> & Required<Pick<R, RequiredPropertyKeys<R>>>>\n : never;\n\nexport type MessageCodec<T extends TProperties = TProperties> = Codec<\n MessageCodecType<T>,\n MessageCodecProto<T>\n>;\n\nexport function MessageCodec<T extends TProperties>(\n schema: T,\n): MessageCodec<T> {\n return {\n encode(app) {\n return new Proxy(app, {\n get(target, property) {\n if (!Object.hasOwn(target, property)) {\n return Reflect.get(target, property);\n }\n\n const v = Reflect.get(target, property);\n return schema[property].encode(v);\n },\n });\n },\n decode(proto) {\n return new Proxy(proto, {\n get(target, property) {\n if (!Object.hasOwn(target, property)) {\n return Reflect.get(target, property);\n }\n\n const v = Reflect.get(target, property);\n return schema[property].decode(v);\n },\n });\n },\n };\n}\n\n/*\n █████████ \n ███░░░░░███ \n ░███ ░███ ████████ ████████ ██████ █████ ████\n ░███████████ ░░███░░███░░███░░███ ░░░░░███ ░░███ ░███ \n ░███░░░░░███ ░███ ░░░ ░███ ░░░ ███████ ░███ ░███ \n ░███ ░███ ░███ ░███ ███░░███ ░███ ░███ \n █████ █████ █████ █████ ░░████████ ░░███████ \n░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░░███ \n ███ ░███ \n ░░██████ \n ░░░░░░ \n \n*/\n\nexport type ArrayCodec<T extends Codec> = T extends Codec<\n infer TApp,\n infer TProto\n>\n ? Codec<readonly TApp[], readonly TProto[] | undefined>\n : never;\n\nexport function ArrayCodec<T extends Codec<TApp, TProto>, TApp, TProto>(\n t: T,\n): ArrayCodec<T> {\n return {\n encode(app) {\n return app.map(t.encode) as readonly TProto[];\n },\n decode(proto) {\n if (proto === undefined) return [];\n return proto.map(t.decode) as readonly TApp[];\n },\n } as ArrayCodec<T>;\n}\n\n/*\n ██████ ██████ █████ █████ ████ █████████ █████ \n░░██████ ██████ ░░███ ░░███ ░░███ ███░░░░░███ ░░███ \n ░███░█████░███ █████ ████ ███████ ██████ ░███████ ░███ ██████ ███ ░░░ ██████ ███████ ██████ ██████ \n ░███░░███ ░███ ░░███ ░███ ░░░███░ ░░░░░███ ░███░░███ ░███ ███░░███░███ ███░░███ ███░░███ ███░░███ ███░░███\n ░███ ░░░ ░███ ░███ ░███ ░███ ███████ ░███ ░███ ░███ ░███████ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░░░ \n ░███ ░███ ░███ ░███ ░███ ███ ███░░███ ░███ ░███ ░███ ░███░░░ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ███\n █████ █████ ░░████████ ░░█████ ░░████████ ████████ █████░░██████ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ \n░░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░░░░░░ ░░░░░░░░ ░░░░░ ░░░░░░ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░ \n*/\nexport type MutableArrayCodec<\n T extends Codec<TApp, TProto>,\n TApp,\n TProto,\n> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp[], TProto[]> : never;\n\nexport function MutableArrayCodec<T extends Codec<TApp, TProto>, TApp, TProto>(\n t: T,\n): MutableArrayCodec<T, TApp, TProto> {\n return {\n encode(app) {\n return app.map(t.encode) as TProto[];\n },\n decode(proto) {\n if (proto === undefined) return [];\n return proto.map(t.decode) as TApp[];\n },\n } as MutableArrayCodec<T, TApp, TProto>;\n}\n\n/*\n ███████ █████ ███ ████ \n ███░░░░░███ ░░███ ░░░ ░░███ \n ███ ░░███ ████████ ███████ ████ ██████ ████████ ██████ ░███ \n░███ ░███░░███░░███░░░███░ ░░███ ███░░███░░███░░███ ░░░░░███ ░███ \n░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ███████ ░███ \n░░███ ███ ░███ ░███ ░███ ███ ░███ ░███ ░███ ░███ ░███ ███░░███ ░███ \n ░░░███████░ ░███████ ░░█████ █████░░██████ ████ █████░░████████ █████\n ░░░░░░░ ░███░░░ ░░░░░ ░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░░░░ ░░░░░ \n ░███ \n █████ \n ░░░░░ \n*/\n\nexport type OptionalCodec<T extends Codec> = T extends Codec<\n infer TApp,\n infer TProto\n>\n ? Codec<TApp | undefined, TProto | undefined>\n : never;\n\nexport function OptionalCodec<T extends Codec>(t: T): OptionalCodec<T> {\n return {\n encode(app) {\n if (app === undefined) return undefined;\n return t.encode(app);\n },\n decode(proto) {\n if (proto === undefined) return undefined;\n return t.decode(proto);\n },\n } as OptionalCodec<T>;\n}\n\n/*\n ███████████ ███ █████\n░░███░░░░░███ ░░░ ░░███ \n ░███ ░███ ██████ ████████ █████ ████ ████ ████████ ██████ ███████ \n ░██████████ ███░░███ ███░░███ ░░███ ░███ ░░███ ░░███░░███ ███░░███ ███░░███ \n ░███░░░░░███ ░███████ ░███ ░███ ░███ ░███ ░███ ░███ ░░░ ░███████ ░███ ░███ \n ░███ ░███ ░███░░░ ░███ ░███ ░███ ░███ ░███ ░███ ░███░░░ ░███ ░███ \n █████ █████░░██████ ░░███████ ░░████████ █████ █████ ░░██████ ░░████████\n░░░░░ ░░░░░ ░░░░░░ ░░░░░███ ░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░ ░░░░░░░░ \n ░███ \n █████ \n ░░░░░ \n*/\n\nexport type RequiredCodec<T extends Codec> = T extends Codec<\n infer TApp,\n infer TProto\n>\n ? TApp extends undefined\n ? never\n : Codec<TApp, TProto | undefined>\n : never;\n\nexport function RequiredCodec<T extends Codec>(t: T): RequiredCodec<T> {\n return {\n encode(app) {\n if (app === undefined) throw new Error(\"Value is required but undefined\");\n return t.encode(app);\n },\n decode(proto) {\n if (proto === undefined)\n throw new Error(\"Value is required but undefined\");\n return t.decode(proto);\n },\n } as RequiredCodec<T>;\n}\n\n/*\n ██████ █████ ████ ████ ███████ \n░░██████ ░░███ ░░███ ░░███ ███░░░░░███ \n ░███░███ ░███ █████ ████ ░███ ░███ ███ ░░███ ████████ \n ░███░░███░███ ░░███ ░███ ░███ ░███ ░███ ░███░░███░░███\n ░███ ░░██████ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░░░ \n ░███ ░░█████ ░███ ░███ ░███ ░███ ░░███ ███ ░███ \n █████ ░░█████ ░░████████ █████ █████ ░░░███████░ █████ \n░░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░ ░░░░░ \n*/\n\nexport type NullOrCodec<T extends Codec> = T extends Codec<\n infer TApp,\n infer TProto\n>\n ? Codec<TApp | null, TProto | null>\n : never;\n\nexport function NullOrCodec<T extends Codec>(t: T): NullOrCodec<T> {\n return {\n encode(app) {\n if (app === null) return null;\n return t.encode(app);\n },\n decode(proto) {\n if (proto === null) return null;\n return t.decode(proto);\n },\n } as NullOrCodec<T>;\n}\n\n/*\n\n ███████████ ███ █████ █████ \n░░███░░░░░███ ░░░ ░░███ ░░███ \n ░███ ░███ ████ ███████ ░███ ████████ ███████ \n ░██████████ ░░███ ███░░███ ░███ ░░███░░███ ░░░███░ \n ░███░░░░░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ \n ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ███\n ███████████ █████░░███████ █████ ████ █████ ░░█████ \n░░░░░░░░░░░ ░░░░░ ░░░░░███░░░░░ ░░░░ ░░░░░ ░░░░░ \n ███ ░███ \n ░░██████ \n ░░░░░░ \n*/\n\nexport type BigIntCodec = CodecType<typeof BigIntCodec>;\n\nexport const BigIntCodec: Codec<bigint, bigint> = {\n encode(app) {\n return app;\n },\n decode(proto) {\n return proto;\n },\n};\n\n/*\n\n ██████ █████ █████ \n░░██████ ░░███ ░░███ \n ░███░███ ░███ █████ ████ █████████████ ░███████ ██████ ████████ \n ░███░░███░███ ░░███ ░███ ░░███░░███░░███ ░███░░███ ███░░███░░███░░███\n ░███ ░░██████ ░███ ░███ ░███ ░███ ░███ ░███ ░███░███████ ░███ ░░░ \n ░███ ░░█████ ░███ ░███ ░███ ░███ ░███ ░███ ░███░███░░░ ░███ \n █████ ░░█████ ░░████████ █████░███ █████ ████████ ░░██████ █████ \n░░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░ ░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░ \n \n*/\n\nexport type NumberCodec = CodecType<typeof NumberCodec>;\n\nexport const NumberCodec: Codec<number, number> = {\n encode(app) {\n return app;\n },\n decode(proto) {\n return proto;\n },\n};\n\n/*\n █████ █████ ███ █████ ████████ █████████ \n░░███ ░░███ ░░░ ░░███ ███░░░░███ ███░░░░░███ \n ░███ ░███ ████ ████████ ███████ ░███ ░███ ░███ ░███ ████████ ████████ ██████ █████ ████\n ░███ ░███ ░░███ ░░███░░███ ░░░███░ ░░████████ ░███████████ ░░███░░███░░███░░███ ░░░░░███ ░░███ ░███ \n ░███ ░███ ░███ ░███ ░███ ░███ ███░░░░███ ░███░░░░░███ ░███ ░░░ ░███ ░░░ ███████ ░███ ░███ \n ░███ ░███ ░███ ░███ ░███ ░███ ███░███ ░███ ░███ ░███ ░███ ░███ ███░░███ ░███ ░███ \n ░░████████ █████ ████ █████ ░░█████ ░░████████ █████ █████ █████ █████ ░░████████ ░░███████ \n ░░░░░░░░ ░░░░░ ░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░░███ \n ███ ░███ \n ░░██████ \n ░░░░░░ \n*/\n\nexport type Uint8ArrayCodec = CodecType<typeof Uint8ArrayCodec>;\n\nexport const Uint8ArrayCodec: Codec<Uint8Array, Uint8Array> = {\n encode(app) {\n return app;\n },\n decode(proto) {\n return proto;\n },\n};\n\n/*\n\n ██████████ █████ \n░░███░░░░███ ░░███ \n ░███ ░░███ ██████ ███████ ██████ \n ░███ ░███ ░░░░░███ ░░░███░ ███░░███\n ░███ ░███ ███████ ░███ ░███████ \n ░███ ███ ███░░███ ░███ ███░███░░░ \n ██████████ ░░████████ ░░█████ ░░██████ \n░░░░░░░░░░ ░░░░░░░░ ░░░░░ ░░░░░░ \n \n*/\n\nexport type DateCodec = CodecType<typeof DateCodec>;\n\nexport const DateCodec: Codec<Date, Date> = {\n encode(app) {\n return new Date(app);\n },\n decode(proto) {\n return new Date(proto);\n },\n};\n\n/*\n\n ███████████ ████ \n░░███░░░░░███ ░░███ \n ░███ ░███ ██████ ██████ ░███ ██████ ██████ ████████ \n ░██████████ ███░░███ ███░░███ ░███ ███░░███ ░░░░░███ ░░███░░███ \n ░███░░░░░███░███ ░███░███ ░███ ░███ ░███████ ███████ ░███ ░███ \n ░███ ░███░███ ░███░███ ░███ ░███ ░███░░░ ███░░███ ░███ ░███ \n ███████████ ░░██████ ░░██████ █████░░██████ ░░████████ ████ █████\n░░░░░░░░░░░ ░░░░░░ ░░░░░░ ░░░░░ ░░░░░░ ░░░░░░░░ ░░░░ ░░░░░ \n \n*/\n\nexport type BooleanCodec = CodecType<typeof BooleanCodec>;\n\nexport const BooleanCodec: Codec<boolean, boolean> = {\n encode(app) {\n return app;\n },\n decode(proto) {\n return proto;\n },\n};\n\n/*\n\n █████████ █████ ███ \n ███░░░░░███ ░░███ ░░░ \n░███ ░░░ ███████ ████████ ████ ████████ ███████\n░░█████████ ░░░███░ ░░███░░███░░███ ░░███░░███ ███░░███\n ░░░░░░░░███ ░███ ░███ ░░░ ░███ ░███ ░███ ░███ ░███\n ███ ░███ ░███ ███ ░███ ░███ ░███ ░███ ░███ ░███\n░░█████████ ░░█████ █████ █████ ████ █████░░███████\n ░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░ ░░░░░ ░░░░░███\n ███ ░███\n ░░██████ \n ░░░░░░ \n*/\n\nexport type StringCodec = CodecType<typeof StringCodec>;\n\nexport const StringCodec: Codec<string, string> = {\n encode(app) {\n return app;\n },\n decode(proto) {\n return proto;\n },\n};\n\n/*\n\n █████ █████ █████ ██████ ███ █████\n░░███ ░░███ ░░███ ███░░███ ░░░ ░░███ \n ░███ ░███ ████████ ███████ ██████ ░███ ░░░ ████ ████████ ██████ ███████ \n ░███ ░███ ░░███░░███ ███░░███ ███░░███ ███████ ░░███ ░░███░░███ ███░░███ ███░░███ \n ░███ ░███ ░███ ░███ ░███ ░███ ░███████ ░░░███░ ░███ ░███ ░███ ░███████ ░███ ░███ \n ░███ ░███ ░███ ░███ ░███ ░███ ░███░░░ ░███ ░███ ░███ ░███ ░███░░░ ░███ ░███ \n ░░████████ ████ █████░░████████░░██████ █████ █████ ████ █████░░██████ ░░████████\n ░░░░░░░░ ░░░░ ░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░ ░░░░░ ░░░░ ░░░░░ ░░░░░░ ░░░░░░░░ \n \n*/\n\nexport type UndefinedCodec = CodecType<typeof UndefinedCodec>;\n\nexport const UndefinedCodec: Codec<undefined, undefined> = {\n encode(app) {\n return undefined;\n },\n decode(proto) {\n return undefined;\n },\n};\n\n/*\n █████ ███ █████ ████ \n░░███ ░░░ ░░███ ░░███ \n ░███ ████ ███████ ██████ ████████ ██████ ░███ \n ░███ ░░███ ░░░███░ ███░░███░░███░░███ ░░░░░███ ░███ \n ░███ ░███ ░███ ░███████ ░███ ░░░ ███████ ░███ \n ░███ █ ░███ ░███ ███░███░░░ ░███ ███░░███ ░███ \n ███████████ █████ ░░█████ ░░██████ █████ ░░████████ █████\n░░░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░ ░░░░░ ░░░░░░░░ ░░░░░ \n \n*/\n\ntype Literal = string | number | boolean | null | undefined;\n\nexport type LiteralCodec<T extends Codec, L extends Literal> = T extends Codec<\n infer TApp,\n infer TProto\n>\n ? Codec<TApp, TProto>\n : never;\n\nexport const LiteralCodec = <const L extends Literal>(\n value: L,\n): LiteralCodec<Codec<L, L>, L> => {\n return {\n encode(app) {\n if (app !== value) {\n throw new Error(`Expected ${String(value)}, got ${String(app)}`);\n }\n return app;\n },\n decode(proto) {\n if (proto !== value) {\n throw new Error(`Expected ${String(value)}, got ${String(proto)}`);\n }\n return proto;\n },\n } as LiteralCodec<Codec<L, L>, L>;\n};\n\n/*\n █████ ███ █████ ████ █████ █████ ███ \n░░███ ░░░ ░░███ ░░███ ░░███ ░░███ ░░░ \n ░███ ████ ███████ ██████ ████████ ██████ ░███ ░███ ░███ ████████ ████ ██████ ████████ \n ░███ ░░███ ░░░███░ ███░░███░░███░░███ ░░░░░███ ░███ ░███ ░███ ░░███░░███ ░░███ ███░░███░░███░░███ \n ░███ ░███ ░███ ░███████ ░███ ░░░ ███████ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ \n ░███ █ ░███ ░███ ███░███░░░ ░███ ███░░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ \n ███████████ █████ ░░█████ ░░██████ █████ ░░████████ █████ ░░████████ ████ █████ █████░░██████ ████ █████\n░░░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░░░░░░ ░░░░ ░░░░░ ░░░░░ ░░░░░░ ░░░░ ░░░░░ \n*/\n\nexport type LiteralUnionCodec<\n T extends Codec,\n L extends readonly Literal[],\n> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp, TProto> : never;\n\nexport const LiteralUnionCodec = <const L extends readonly Literal[]>(\n values: L,\n): LiteralUnionCodec<Codec<L[number], L[number]>, L> => {\n return {\n encode(app) {\n if (!values.includes(app as L[number])) {\n throw new Error(\n `Expected one of [${values.join(\", \")}], got ${String(app)}`,\n );\n }\n return app;\n },\n decode(proto) {\n if (!values.includes(proto as L[number])) {\n throw new Error(\n `Expected one of [${values.join(\", \")}], got ${String(proto)}`,\n );\n }\n return proto;\n },\n } as LiteralUnionCodec<Codec<L[number], L[number]>, L>;\n};\n\n/*\n █████ █████ ███ █████ \n░░███ ░░███ ░░░ ░░███ \n ░███ ░███ ██████ ████████ ████ ██████ ████████ ███████ \n ░███ ░███ ░░░░░███ ░░███░░███░░███ ░░░░░███ ░░███░░███ ░░░███░ \n ░░███ ███ ███████ ░███ ░░░ ░███ ███████ ░███ ░███ ░███ \n ░░░█████░ ███░░███ ░███ ░███ ███░░███ ░███ ░███ ░███ ███\n ░░███ ░░████████ █████ █████░░████████ ████ █████ ░░█████ \n ░░░ ░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░ ░░░░░ ░░░░░ \n*/\n\n// Maps variant keys to their corresponding decoded types, adding a tag field\n// For example: { _tag: \"declareV1\", declareV1: { data: string } }\n// if the variant is undefined type, it will be just the tag - { _tag: \"heartbeat\" }\ntype AppVariantMap<TTag extends TPropertyKey, TVariants extends TProperties> = {\n [K in keyof TVariants]: {\n [P in TTag]: K;\n } & (CodecType<TVariants[K]> extends UndefinedCodec\n ? // biome-ignore lint/complexity/noBannedTypes: had to return empty object to satisfy type\n {}\n : { [P in K & TPropertyKey]: CodecType<TVariants[K]> });\n};\ntype VariantCodecType<\n TTag extends TPropertyKey,\n TVariants extends TProperties,\n> = AppVariantMap<TTag, TVariants>[keyof TVariants];\n\n// Maps variant keys to their corresponding encoded types, adding a discriminator field\n// For example: { $case: \"declareV1\", declareV1: { data: string } }\ntype ProtoVariantMap<\n TDiscriminator extends TPropertyKey,\n TVariants extends TProperties,\n> = {\n [K in keyof TVariants]: {\n [P in TDiscriminator]: K;\n } & {\n [P in K & TPropertyKey]: CodecProto<TVariants[K]>;\n };\n};\n\ntype VariantCodecProto<\n TDiscriminator extends TPropertyKey,\n TVariants extends TProperties,\n> = ProtoVariantMap<TDiscriminator, TVariants>[keyof TVariants];\n\n// Type helper for VariantCodec that preserves the input/output types\nexport type VariantCodec<\n T extends Codec,\n TTag extends TPropertyKey,\n TDiscriminator extends TPropertyKey,\n> = T extends Codec<infer TApp, infer TProto> ? Codec<TApp, TProto> : never;\n\nexport const VariantCodec = <\n TTag extends TPropertyKey,\n TDiscriminator extends TPropertyKey,\n TVariants extends TProperties,\n TCodec extends Codec<\n VariantCodecType<TTag, TVariants>,\n VariantCodecProto<TDiscriminator, TVariants>\n >,\n>(options: {\n tag: TTag;\n discriminator: TDiscriminator;\n variants: TVariants;\n}): VariantCodec<TCodec, TTag, TDiscriminator> => {\n return {\n encode(app) {\n const tag = app[options.tag];\n const codec = options.variants[tag];\n if (!codec) {\n throw new Error(`Unknown variant: ${String(tag)}`);\n }\n\n const variantData = app[tag as keyof typeof app];\n const encodedData = codec.encode(variantData);\n\n return {\n [options.discriminator]: tag,\n [tag]: encodedData,\n };\n },\n decode(proto) {\n const tag = proto[options.discriminator];\n const codec = options.variants[tag];\n if (!codec) {\n throw new Error(`Unknown variant: ${String(tag)}`);\n }\n\n const variantData = proto[tag as keyof typeof proto];\n const decodedData = codec.decode(variantData);\n\n return {\n [options.tag]: tag,\n [tag]: decodedData,\n };\n },\n } as VariantCodec<TCodec, TTag, TDiscriminator>;\n};\n\n/*\n ███████ ███████ ██████ \n ███░░░░░███ ███░░░░░███ ███░░███\n ███ ░░███ ████████ ██████ ███ ░░███ ░███ ░░░ \n░███ ░███░░███░░███ ███░░███░███ ░███ ███████ \n░███ ░███ ░███ ░███ ░███████ ░███ ░███░░░███░ \n░░███ ███ ░███ ░███ ░███░░░ ░░███ ███ ░███ \n ░░░███████░ ████ █████░░██████ ░░░███████░ █████ \n ░░░░░░░ ░░░░ ░░░░░ ░░░░░░ ░░░░░░░ ░░░░░ \n \n*/\n\nexport type OneOfCodec<TVariants extends TProperties> = VariantCodec<\n Codec<\n VariantCodecType<\"_tag\", TVariants>,\n VariantCodecProto<\"$case\", TVariants>\n >,\n \"_tag\",\n \"$case\"\n>;\n\nexport function OneOfCodec<TVariants extends TProperties>(\n variants: TVariants,\n): OneOfCodec<TVariants> {\n return VariantCodec({\n tag: \"_tag\",\n discriminator: \"$case\",\n variants,\n });\n}\n"],"names":[],"mappings":";;AAkFO,SAAS,aACd,MACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,OAAO,GAAK,EAAA;AACV,MAAO,OAAA,IAAI,MAAM,GAAK,EAAA;AAAA,QACpB,GAAA,CAAI,QAAQ,QAAU,EAAA;AACpB,UAAA,IAAI,CAAC,MAAA,CAAO,MAAO,CAAA,MAAA,EAAQ,QAAQ,CAAG,EAAA;AACpC,YAAO,OAAA,OAAA,CAAQ,GAAI,CAAA,MAAA,EAAQ,QAAQ,CAAA,CAAA;AAAA,WACrC;AAEA,UAAA,MAAM,CAAI,GAAA,OAAA,CAAQ,GAAI,CAAA,MAAA,EAAQ,QAAQ,CAAA,CAAA;AACtC,UAAA,OAAO,MAAO,CAAA,QAAQ,CAAE,CAAA,MAAA,CAAO,CAAC,CAAA,CAAA;AAAA,SAClC;AAAA,OACD,CAAA,CAAA;AAAA,KACH;AAAA,IAC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AAA,WAAA,GAAc,MAAM,GAAyB,CAAA,CAAA;AACnD,MAAM,MAAA,WAAA,GAAc,KAAM,CAAA,MAAA,CAAO,WAAW,CAAA,CAAA;AAE5C,MAAO,OAAA;AAAA,QACL,CAAC,OAAQ,CAAA,GAAG,GAAG,GAAA;AAAA,QACf,CAAC,GAAG,GAAG,WAAA;AAAA,OACT,CAAA;AAAA,KACF;AAAA,GACF,CAAA;AACF,EAAA;AAuBO,SAAS,WACd,QACuB,EAAA;AACvB,EAAA,OAAO,YAAa,CAAA;AAAA,IAClB,GAAK,EAAA,MAAA;AAAA,IACL,aAAe,EAAA,OAAA;AAAA,IACf,QAAA;AAAA,GACD,CAAA,CAAA;AACH;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/codec.d.cts
ADDED
|
@@ -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 };
|
package/dist/codec.d.mts
ADDED
|
@@ -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 };
|
package/dist/codec.d.ts
ADDED
|
@@ -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 };
|