@graphql-mesh/transport-protobuf 0.0.0-stage → 0.7.2

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.
@@ -0,0 +1,259 @@
1
+ /**
2
+ * Compact protobuf mapping dialect (see Mesh protobuf RPC spec).
3
+ * body/selection: fieldId(type): bind with nested { }
4
+ */
5
+
6
+ export type ProtoScalar =
7
+ | 'bool'
8
+ | 'int32'
9
+ | 'sint32'
10
+ | 'uint32'
11
+ | 'int64'
12
+ | 'sint64'
13
+ | 'uint64'
14
+ | 'fixed32'
15
+ | 'fixed64'
16
+ | 'sfixed32'
17
+ | 'sfixed64'
18
+ | 'float'
19
+ | 'double'
20
+ | 'string'
21
+ | 'bytes';
22
+
23
+ export type ProtoType =
24
+ | { kind: 'scalar'; name: ProtoScalar }
25
+ | { kind: 'enum'; values: Record<string, number> }
26
+ | { kind: 'message'; fields: MappingField[] }
27
+ | { kind: 'repeated'; element: ProtoType }
28
+ | { kind: 'map'; key: ProtoType; value: ProtoType };
29
+
30
+ export interface MappingField {
31
+ id: number;
32
+ type: ProtoType;
33
+ /** GraphQL bind path (e.g. year, $args.year, input.movie) or nested omit when type is message with fields */
34
+ bind?: string;
35
+ fields?: MappingField[];
36
+ }
37
+
38
+ export function parseMapping(source: string): MappingField[] {
39
+ const s = source.trim();
40
+ if (!s) return [];
41
+ return parseFieldList(s, 0).fields;
42
+ }
43
+
44
+ function parseFieldList(source: string, start: number): { fields: MappingField[]; end: number } {
45
+ const fields: MappingField[] = [];
46
+ let i = skipWs(source, start);
47
+ while (i < source.length && source[i] !== '}') {
48
+ const parsed = parseField(source, i);
49
+ fields.push(parsed.field);
50
+ i = skipWs(source, parsed.end);
51
+ }
52
+ return { fields, end: i };
53
+ }
54
+
55
+ function parseField(source: string, start: number): { field: MappingField; end: number } {
56
+ let i = skipWs(source, start);
57
+ const idStart = i;
58
+ while (i < source.length && /[0-9]/.test(source[i])) i++;
59
+ if (i === idStart) {
60
+ throw new Error(`Expected field id at ${snippet(source, start)}`);
61
+ }
62
+ const id = Number(source.slice(idStart, i));
63
+ i = skipWs(source, i);
64
+ if (source[i] !== '(') {
65
+ throw new Error(`Expected '(' after field id ${id} at ${snippet(source, i)}`);
66
+ }
67
+ i++;
68
+ const typeParsed = parseType(source, i);
69
+ i = skipWs(source, typeParsed.end);
70
+ if (source[i] !== ')') {
71
+ throw new Error(`Expected ')' after type at ${snippet(source, i)}`);
72
+ }
73
+ i++;
74
+ i = skipWs(source, i);
75
+ if (source[i] !== ':') {
76
+ throw new Error(`Expected ':' after type at ${snippet(source, i)}`);
77
+ }
78
+ i++;
79
+ i = skipWs(source, i);
80
+
81
+ if (source[i] === '{') {
82
+ i++;
83
+ const nested = parseFieldList(source, i);
84
+ i = skipWs(source, nested.end);
85
+ if (source[i] !== '}') {
86
+ throw new Error(`Expected '}' at ${snippet(source, i)}`);
87
+ }
88
+ i++;
89
+ // optional bind after nested block: `1(message): movie { ... }` already consumed;
90
+ // support `1(message): { ... }` or `1(message): name { ... }` — if we had a bind before `{`
91
+ return {
92
+ field: {
93
+ id,
94
+ type: { kind: 'message', fields: nested.fields },
95
+ fields: nested.fields,
96
+ },
97
+ end: i,
98
+ };
99
+ }
100
+
101
+ const bindStart = i;
102
+ while (i < source.length && !/[\s}]/.test(source[i])) {
103
+ // allow $args.foo.bar
104
+ if (source[i] === '{') break;
105
+ i++;
106
+ }
107
+ // If next non-ws is `{`, bind was a name before nested message
108
+ const afterBind = skipWs(source, i);
109
+ if (source[afterBind] === '{') {
110
+ const bind = source.slice(bindStart, i).trim();
111
+ i = afterBind + 1;
112
+ const nested = parseFieldList(source, i);
113
+ i = skipWs(source, nested.end);
114
+ if (source[i] !== '}') {
115
+ throw new Error(`Expected '}' at ${snippet(source, i)}`);
116
+ }
117
+ i++;
118
+ const baseType = typeParsed.type;
119
+ const messageType: ProtoType = { kind: 'message', fields: nested.fields };
120
+ const type: ProtoType =
121
+ baseType.kind === 'repeated' ? { kind: 'repeated', element: messageType } : messageType;
122
+ return {
123
+ field: {
124
+ id,
125
+ type,
126
+ bind: bind || undefined,
127
+ fields: nested.fields,
128
+ },
129
+ end: i,
130
+ };
131
+ }
132
+
133
+ const bind = source.slice(bindStart, i).trim();
134
+ return {
135
+ field: {
136
+ id,
137
+ type: typeParsed.type,
138
+ bind: bind || undefined,
139
+ },
140
+ end: i,
141
+ };
142
+ }
143
+
144
+ function parseType(source: string, start: number): { type: ProtoType; end: number } {
145
+ let i = skipWs(source, start);
146
+ if (source.startsWith('repeated', i)) {
147
+ i = skipWs(source, i + 'repeated'.length);
148
+ const el = parseType(source, i);
149
+ return { type: { kind: 'repeated', element: el.type }, end: el.end };
150
+ }
151
+ if (source.startsWith('map<', i)) {
152
+ i = skipWs(source, i + 4);
153
+ const key = parseType(source, i);
154
+ i = skipWs(source, key.end);
155
+ if (source[i] !== ',') {
156
+ throw new Error(`Expected ',' in map<> at ${snippet(source, i)}`);
157
+ }
158
+ i++;
159
+ const value = parseType(source, i);
160
+ i = skipWs(source, value.end);
161
+ if (source[i] !== '>') {
162
+ throw new Error(`Expected '>' in map<> at ${snippet(source, i)}`);
163
+ }
164
+ return {
165
+ type: { kind: 'map', key: key.type, value: value.type },
166
+ end: i + 1,
167
+ };
168
+ }
169
+ if (source.startsWith('enum{', i) || source.startsWith('enum {', i)) {
170
+ const brace = source.indexOf('{', i);
171
+ i = brace + 1;
172
+ const values: Record<string, number> = {};
173
+ i = skipWs(source, i);
174
+ while (i < source.length && source[i] !== '}') {
175
+ const nameStart = i;
176
+ while (i < source.length && /[A-Za-z0-9_]/.test(source[i])) i++;
177
+ const name = source.slice(nameStart, i);
178
+ i = skipWs(source, i);
179
+ if (source[i] !== '=') {
180
+ throw new Error(`Expected '=' in enum at ${snippet(source, i)}`);
181
+ }
182
+ i++;
183
+ i = skipWs(source, i);
184
+ const numStart = i;
185
+ while (i < source.length && /[0-9-]/.test(source[i])) i++;
186
+ values[name] = Number(source.slice(numStart, i));
187
+ i = skipWs(source, i);
188
+ if (source[i] === ',') {
189
+ i++;
190
+ i = skipWs(source, i);
191
+ }
192
+ }
193
+ if (source[i] !== '}') {
194
+ throw new Error(`Expected '}' in enum at ${snippet(source, i)}`);
195
+ }
196
+ return { type: { kind: 'enum', values }, end: i + 1 };
197
+ }
198
+ if (source.startsWith('message', i)) {
199
+ return { type: { kind: 'message', fields: [] }, end: i + 'message'.length };
200
+ }
201
+ const nameStart = i;
202
+ while (i < source.length && /[a-z0-9]/.test(source[i])) i++;
203
+ const name = source.slice(nameStart, i) as ProtoScalar;
204
+ return { type: { kind: 'scalar', name }, end: i };
205
+ }
206
+
207
+ function skipWs(source: string, i: number): number {
208
+ while (i < source.length) {
209
+ if (/\s/.test(source[i])) {
210
+ i++;
211
+ continue;
212
+ }
213
+ // `#` comments are documentation-only (loader emit / hand SDL); skip to EOL
214
+ if (source[i] === '#') {
215
+ while (i < source.length && source[i] !== '\n') i++;
216
+ continue;
217
+ }
218
+ break;
219
+ }
220
+ return i;
221
+ }
222
+
223
+ function snippet(source: string, i: number): string {
224
+ return JSON.stringify(source.slice(Math.max(0, i - 10), i + 20));
225
+ }
226
+
227
+ export function resolveBind(
228
+ bind: string | undefined,
229
+ args: Record<string, any>,
230
+ thisRoot?: Record<string, any>,
231
+ ): any {
232
+ if (bind == null || bind === '') {
233
+ return undefined;
234
+ }
235
+ if (bind.startsWith('$this.')) {
236
+ return getPath(thisRoot ?? args, bind.slice('$this.'.length));
237
+ }
238
+ if (bind === '$this') {
239
+ return thisRoot ?? args;
240
+ }
241
+ if (bind.startsWith('$args.')) {
242
+ return getPath(args, bind.slice('$args.'.length));
243
+ }
244
+ if (bind === '$args') {
245
+ return args;
246
+ }
247
+ return getPath(args, bind);
248
+ }
249
+
250
+ function getPath(obj: any, pathStr: string): any {
251
+ if (obj == null) return undefined;
252
+ const parts = pathStr.split('.');
253
+ let cur = obj;
254
+ for (const p of parts) {
255
+ if (cur == null) return undefined;
256
+ cur = cur[p];
257
+ }
258
+ return cur;
259
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,158 @@
1
+ import { GraphQLError, type GraphQLScalarType } from 'graphql';
2
+ import lodashGet from 'lodash.get';
3
+ import type { ResolverData } from '@graphql-mesh/string-interpolation';
4
+ import { stringInterpolator } from '@graphql-mesh/string-interpolation';
5
+ import { withCancel } from '@graphql-mesh/utils';
6
+ import type {
7
+ CallOptions,
8
+ ClientDuplexStream,
9
+ ClientReadableStream,
10
+ ClientUnaryCall,
11
+ MetadataValue,
12
+ ServiceError,
13
+ } from '@grpc/grpc-js';
14
+ import { status as GrpcStatus, Metadata } from '@grpc/grpc-js';
15
+
16
+ function isBlob(input: any): input is Blob {
17
+ return input != null && input.stream instanceof Function;
18
+ }
19
+
20
+ function isGrpcServiceError(error: unknown): error is ServiceError {
21
+ return (
22
+ typeof error === 'object' &&
23
+ error != null &&
24
+ typeof (error as ServiceError).code === 'number' &&
25
+ typeof (error as ServiceError).details === 'string'
26
+ );
27
+ }
28
+
29
+ /**
30
+ * Convert a gRPC `ServiceError` into a GraphQLError so gateways do not mask it.
31
+ * Upstream details live under `extensions.grpc` (code, status, details, metadata).
32
+ * Non-ServiceError values are returned unchanged.
33
+ */
34
+ export function toGrpcGraphQLError(error: unknown) {
35
+ if (!isGrpcServiceError(error)) {
36
+ return error;
37
+ }
38
+ const status = GrpcStatus[error.code] != null ? String(GrpcStatus[error.code]) : 'UNKNOWN';
39
+ // Do not set `originalError` to the raw ServiceError — Envelop's maskedErrors
40
+ // walks originalError and would treat a non-GraphQLError root as unexpected.
41
+ return new GraphQLError(error.message || status, {
42
+ extensions: {
43
+ code: 'DOWNSTREAM_SERVICE_ERROR',
44
+ grpc: {
45
+ code: error.code,
46
+ status,
47
+ details: error.details,
48
+ metadata: error.metadata?.getMap?.(),
49
+ },
50
+ },
51
+ });
52
+ }
53
+
54
+ export function buildGrpcMetadata(
55
+ metaData: Record<string, string | string[] | Buffer> | [string, string][] | undefined,
56
+ resolverData: ResolverData,
57
+ ): Metadata | undefined {
58
+ if (!metaData) {
59
+ return undefined;
60
+ }
61
+ const meta = new Metadata();
62
+ const entries = Array.isArray(metaData) ? Object.fromEntries(metaData) : metaData;
63
+ for (const [key, value] of Object.entries(entries)) {
64
+ let metaValue: unknown = value;
65
+ if (Array.isArray(value)) {
66
+ // Extract data from context
67
+ metaValue = lodashGet(resolverData.context, value);
68
+ }
69
+
70
+ // Ensure that the metadata is compatible with what node-grpc expects
71
+ if (typeof metaValue !== 'string' && !(metaValue instanceof Buffer)) {
72
+ metaValue = JSON.stringify(metaValue);
73
+ }
74
+
75
+ if (typeof metaValue === 'string') {
76
+ metaValue = stringInterpolator.parse(metaValue, resolverData);
77
+ }
78
+
79
+ meta.add(key, metaValue as MetadataValue);
80
+ }
81
+ return meta;
82
+ }
83
+
84
+ export function addMetaDataToCall(
85
+ callFn: any,
86
+ input: any,
87
+ resolverData: ResolverData,
88
+ metaData?: Record<string, string | string[] | Buffer> | [string, string][],
89
+ isResponseStream = false,
90
+ requestTimeout?: number,
91
+ ) {
92
+ const callFnArguments: any[] = [];
93
+ if (!isBlob(input)) {
94
+ callFnArguments.push(input);
95
+ }
96
+ const meta = buildGrpcMetadata(metaData, resolverData);
97
+ const callOptions: CallOptions = {};
98
+ if (requestTimeout != null && requestTimeout > 0) {
99
+ callOptions.deadline = Date.now() + requestTimeout;
100
+ }
101
+ const hasCallOptions = Object.keys(callOptions).length > 0;
102
+ if (meta || hasCallOptions) {
103
+ // grpc-js accepts (argument, metadata, options, callback)
104
+ callFnArguments.push(meta ?? new Metadata());
105
+ if (hasCallOptions) {
106
+ callFnArguments.push(callOptions);
107
+ }
108
+ }
109
+ const { promise, resolve, reject } = Promise.withResolvers<any>();
110
+ const call: ClientDuplexStream<any, any> = callFn(
111
+ ...callFnArguments,
112
+ (error: Error, response: ClientUnaryCall | ClientReadableStream<unknown>) => {
113
+ if (error) {
114
+ reject(toGrpcGraphQLError(error));
115
+ return;
116
+ }
117
+ resolve(response);
118
+ },
119
+ );
120
+ if (isResponseStream) {
121
+ let isCancelled = false;
122
+ const responseStreamWithCancel = withCancel(call, reason => {
123
+ if (!isCancelled) {
124
+ call.call?.cancelWithStatus(0, reason?.toString() || 'aborted');
125
+ isCancelled = true;
126
+ }
127
+ });
128
+ resolve(responseStreamWithCancel);
129
+ if (isBlob(input)) {
130
+ const blobStream = input.stream();
131
+ (blobStream as any).pipe(call);
132
+ }
133
+ }
134
+ return promise;
135
+ }
136
+
137
+ export function addExecutionLogicToScalar(
138
+ nonExecutableScalar: GraphQLScalarType,
139
+ actualScalar: GraphQLScalarType,
140
+ ) {
141
+ Object.defineProperties(nonExecutableScalar, {
142
+ serialize: {
143
+ value: actualScalar.serialize,
144
+ },
145
+ parseValue: {
146
+ value: actualScalar.parseValue,
147
+ },
148
+ parseLiteral: {
149
+ value: actualScalar.parseLiteral,
150
+ },
151
+ extensions: {
152
+ value: {
153
+ ...actualScalar.extensions,
154
+ ...nonExecutableScalar.extensions,
155
+ },
156
+ },
157
+ });
158
+ }
@@ -0,0 +1,52 @@
1
+ import { describe, expect, it } from '@jest/globals';
2
+ import { decodeMessage, encodeMessage } from '../src/protobuf/codec.js';
3
+ import { parseMapping } from '../src/protobuf/mapping.js';
4
+
5
+ describe('protobuf mapping + codec', () => {
6
+ it('roundtrips MovieRequest-like body', () => {
7
+ const fields = parseMapping(`
8
+ 1(message): input.movie {
9
+ 2(int64): year
10
+ 6(enum{UNSPECIFIED=0,ACTION=1,DRAMA=2}): genre
11
+ }
12
+ `);
13
+ const bytes = encodeMessage(fields, {
14
+ input: { movie: { year: 2015, genre: 'DRAMA' } },
15
+ });
16
+ expect(bytes.length).toBeGreaterThan(0);
17
+ const decoded = decodeMessage(
18
+ parseMapping(`
19
+ 1(message): movie {
20
+ 2(int64): year
21
+ 6(enum{UNSPECIFIED=0,ACTION=1,DRAMA=2}): genre
22
+ }
23
+ `),
24
+ bytes,
25
+ );
26
+ expect(decoded.movie.year).toBe(2015);
27
+ expect(decoded.movie.genre).toBe('DRAMA');
28
+ });
29
+
30
+ it('parses repeated message selection', () => {
31
+ const fields = parseMapping(`
32
+ 1(repeated message): result {
33
+ 1(string): name
34
+ 2(int64): year
35
+ }
36
+ `);
37
+ expect(fields[0].type.kind).toBe('repeated');
38
+ expect(fields[0].fields?.[0].bind).toBe('name');
39
+ });
40
+
41
+ it('skips # documentation comments', () => {
42
+ const fields = parseMapping(`
43
+ # Encode GraphQL field arguments into the protobuf request message.
44
+ 1(message): input.movie {
45
+ # year is int64 on the wire
46
+ 2(int64): year
47
+ }
48
+ `);
49
+ expect(fields).toHaveLength(1);
50
+ expect(fields[0].fields?.[0].bind).toBe('year');
51
+ });
52
+ });
@@ -0,0 +1,182 @@
1
+ /* eslint-disable @typescript-eslint/no-floating-promises */
2
+ import { GraphQLError } from 'graphql';
3
+ import { process } from '@graphql-mesh/cross-helpers';
4
+ import { status as GrpcStatus, Metadata } from '@grpc/grpc-js';
5
+ import { addMetaDataToCall, toGrpcGraphQLError } from '../src/utils.js';
6
+
7
+ describe('grpc utils', () => {
8
+ describe('toGrpcGraphQLError', () => {
9
+ test('maps ServiceError into GraphQLError with extensions.grpc', () => {
10
+ const grpcError = Object.assign(new Error('Deadline exceeded'), {
11
+ code: GrpcStatus.DEADLINE_EXCEEDED,
12
+ details: 'Deadline exceeded',
13
+ metadata: new Metadata(),
14
+ });
15
+ const gqlError = toGrpcGraphQLError(grpcError);
16
+ expect(gqlError).toBeInstanceOf(GraphQLError);
17
+ expect((gqlError as GraphQLError).message).toBe('Deadline exceeded');
18
+ expect((gqlError as GraphQLError).extensions).toMatchObject({
19
+ code: 'DOWNSTREAM_SERVICE_ERROR',
20
+ grpc: {
21
+ code: GrpcStatus.DEADLINE_EXCEEDED,
22
+ status: 'DEADLINE_EXCEEDED',
23
+ details: 'Deadline exceeded',
24
+ metadata: {},
25
+ },
26
+ });
27
+ });
28
+
29
+ test('passes through non-ServiceError values unchanged', () => {
30
+ const err = new Error('boom');
31
+ expect(toGrpcGraphQLError(err)).toBe(err);
32
+ expect(toGrpcGraphQLError('nope')).toBe('nope');
33
+ });
34
+ });
35
+
36
+ describe('addMetaDataToCall', () => {
37
+ const grpcClientMethod = jest.fn();
38
+ beforeEach(() => {
39
+ grpcClientMethod.mockReset();
40
+ });
41
+ const input = { sport: 'Baseball' };
42
+ const context = { team: 'Oakland As', players: { pitcher: 'Kershaw' }, number: 42 };
43
+ const binarySportsTeam = Buffer.from([
44
+ 68, 111, 100, 103, 101, 114, 115, 32, 82, 117, 108, 101, 33,
45
+ ]);
46
+ const binaryPlayer = Buffer.from([75, 101, 114, 115, 104, 97, 119]);
47
+
48
+ function createExpectedMetadata(key: string, value: string | Buffer): Metadata {
49
+ const meta = new Metadata();
50
+ meta.add(key, value);
51
+
52
+ return meta;
53
+ }
54
+
55
+ test(`when no metadata is supplied by the config`, () => {
56
+ addMetaDataToCall(grpcClientMethod, input, { context, env: process.env }, undefined);
57
+ expect(grpcClientMethod).toHaveBeenCalledWith(input, expect.any(Function));
58
+ });
59
+
60
+ test(`rejects with GraphQLError when the gRPC callback returns a ServiceError`, async () => {
61
+ grpcClientMethod.mockImplementationOnce((_input, cb) => {
62
+ cb(
63
+ Object.assign(new Error('too big'), {
64
+ code: GrpcStatus.RESOURCE_EXHAUSTED,
65
+ details: 'Received message larger than max',
66
+ metadata: new Metadata(),
67
+ }),
68
+ );
69
+ });
70
+ await expect(
71
+ addMetaDataToCall(grpcClientMethod, input, { context, env: process.env }, undefined),
72
+ ).rejects.toMatchObject({
73
+ message: 'too big',
74
+ extensions: {
75
+ code: 'DOWNSTREAM_SERVICE_ERROR',
76
+ grpc: {
77
+ code: GrpcStatus.RESOURCE_EXHAUSTED,
78
+ status: 'RESOURCE_EXHAUSTED',
79
+ },
80
+ },
81
+ });
82
+ });
83
+
84
+ test(`when requestTimeout is supplied, passes a deadline CallOptions`, () => {
85
+ const now = 1_700_000_000_000;
86
+ const dateNowSpy = jest.spyOn(Date, 'now').mockReturnValue(now);
87
+ addMetaDataToCall(
88
+ grpcClientMethod,
89
+ input,
90
+ { context, env: process.env },
91
+ undefined,
92
+ false,
93
+ 4000,
94
+ );
95
+ expect(grpcClientMethod).toHaveBeenCalledWith(
96
+ input,
97
+ expect.any(Metadata),
98
+ { deadline: now + 4000 },
99
+ expect.any(Function),
100
+ );
101
+ dateNowSpy.mockRestore();
102
+ });
103
+
104
+ test(`when requestTimeout and metadata are supplied, passes both`, () => {
105
+ const now = 1_700_000_000_000;
106
+ const dateNowSpy = jest.spyOn(Date, 'now').mockReturnValue(now);
107
+ addMetaDataToCall(
108
+ grpcClientMethod,
109
+ input,
110
+ { context, env: process.env },
111
+ { sportsTeam: 'Dodgers' },
112
+ false,
113
+ 2500,
114
+ );
115
+ expect(grpcClientMethod).toHaveBeenCalledWith(
116
+ input,
117
+ createExpectedMetadata('sportsTeam', 'Dodgers'),
118
+ { deadline: now + 2500 },
119
+ expect.any(Function),
120
+ );
121
+ dateNowSpy.mockRestore();
122
+ });
123
+
124
+ describe.each<[string, Record<string, string | Buffer | string[]>, Metadata]>([
125
+ ['static', { sportsTeam: 'Dodgers' }, createExpectedMetadata('sportsTeam', 'Dodgers')],
126
+ [
127
+ 'static all lowercase',
128
+ { sportsteam: 'Dodgers' },
129
+ createExpectedMetadata('sportsteam', 'Dodgers'),
130
+ ],
131
+ [
132
+ 'dynamic',
133
+ { bestPlayer: ['players', 'pitcher'] },
134
+ createExpectedMetadata('bestplayer', 'Kershaw'),
135
+ ],
136
+ [
137
+ 'dynamic number',
138
+ { jerseyNumber: ['number'] },
139
+ createExpectedMetadata('jerseynumber', '42'),
140
+ ],
141
+ [
142
+ 'dynamic underscore key',
143
+ { best_player: ['players', 'pitcher'] },
144
+ createExpectedMetadata('best_player', 'Kershaw'),
145
+ ],
146
+ [
147
+ 'static binary',
148
+ { 'sportsTeam-bin': binarySportsTeam },
149
+ createExpectedMetadata('sportsTeam-bin', binarySportsTeam),
150
+ ],
151
+ [
152
+ 'dynamic binary',
153
+ { 'bestPlayer-bin': binaryPlayer },
154
+ createExpectedMetadata('bestPlayer-bin', binaryPlayer),
155
+ ],
156
+ ])('should generate gRPC Metadata', (type, config, expectedMetadata) => {
157
+ beforeEach(() => {
158
+ grpcClientMethod.mockClear();
159
+ });
160
+
161
+ test(`when ${type} metadata is supplied by the config`, () => {
162
+ addMetaDataToCall(grpcClientMethod, input, { context, env: process.env }, config);
163
+ expect(grpcClientMethod).toHaveBeenCalledWith(
164
+ input,
165
+ expectedMetadata,
166
+ expect.any(Function),
167
+ );
168
+ });
169
+ });
170
+
171
+ describe.each<[string, Record<string, string | Buffer | string[]>]>([
172
+ ['static binary', { sportsTeam: binarySportsTeam }],
173
+ ['dynamic binary', { bestPlayer: binaryPlayer }],
174
+ ])('should throw errors when generating gRPC Metadata', (type, config) => {
175
+ test(`when ${type} metadata is supplied by the config`, () => {
176
+ expect(() =>
177
+ addMetaDataToCall(grpcClientMethod, input, { context, env: process.env }, config),
178
+ ).toThrow(/keys that don't end with '-bin' must have String values/);
179
+ });
180
+ });
181
+ });
182
+ });
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.