Skip to content

Commit d8ebbb8

Browse files
committed
Run formatter.
1 parent 72e87b4 commit d8ebbb8

File tree

4 files changed

+167
-70
lines changed

4 files changed

+167
-70
lines changed

packages/functions/src/api.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ export function connectFunctionsEmulator(
8888
* @param name - The name of the trigger.
8989
* @public
9090
*/
91-
export function httpsCallable<RequestData = unknown, ResponseData = unknown, StreamData = unknown>(
91+
export function httpsCallable<
92+
RequestData = unknown,
93+
ResponseData = unknown,
94+
StreamData = unknown
95+
>(
9296
functionsInstance: Functions,
9397
name: string,
9498
options?: HttpsCallableOptions
@@ -108,7 +112,7 @@ export function httpsCallable<RequestData = unknown, ResponseData = unknown, Str
108112
export function httpsCallableFromURL<
109113
RequestData = unknown,
110114
ResponseData = unknown,
111-
StreamData = unknown,
115+
StreamData = unknown
112116
>(
113117
functionsInstance: Functions,
114118
url: string,

packages/functions/src/callable.test.ts

Lines changed: 106 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ describe('Firebase Functions > Call', () => {
9898
{ message: string; code: number; long: number }
9999
>(functions, 'dataTest');
100100
try {
101-
102101
const result = await func(data);
103102

104103
expect(result.data).to.deep.equal({
@@ -329,9 +328,15 @@ describe('Firebase Functions > Stream', () => {
329328
it('successfully streams data and resolves final result', async () => {
330329
const mockResponse = new ReadableStream({
331330
start(controller) {
332-
controller.enqueue(new TextEncoder().encode('data: {"message":"Hello"}\n'));
333-
controller.enqueue(new TextEncoder().encode('data: {"message":"World"}\n'));
334-
controller.enqueue(new TextEncoder().encode('data: {"result":"Final Result"}\n'));
331+
controller.enqueue(
332+
new TextEncoder().encode('data: {"message":"Hello"}\n')
333+
);
334+
controller.enqueue(
335+
new TextEncoder().encode('data: {"message":"World"}\n')
336+
);
337+
controller.enqueue(
338+
new TextEncoder().encode('data: {"result":"Final Result"}\n')
339+
);
335340
controller.close();
336341
}
337342
});
@@ -340,10 +345,13 @@ describe('Firebase Functions > Stream', () => {
340345
body: mockResponse,
341346
headers: new Headers({ 'Content-Type': 'text/event-stream' }),
342347
status: 200,
343-
statusText: 'OK',
348+
statusText: 'OK'
344349
} as Response);
345350

346-
const func = httpsCallable<Record<string, any>, string, string>(functions, 'streamTest');
351+
const func = httpsCallable<Record<string, any>, string, string>(
352+
functions,
353+
'streamTest'
354+
);
347355
const streamResult = await func.stream({});
348356

349357
const messages: string[] = [];
@@ -358,8 +366,14 @@ describe('Firebase Functions > Stream', () => {
358366
it('successfully process request chunk with multiple events', async () => {
359367
const mockResponse = new ReadableStream({
360368
start(controller) {
361-
controller.enqueue(new TextEncoder().encode('data: {"message":"Hello"}\n\ndata: {"message":"World"}\n'));
362-
controller.enqueue(new TextEncoder().encode('data: {"result":"Final Result"}\n'));
369+
controller.enqueue(
370+
new TextEncoder().encode(
371+
'data: {"message":"Hello"}\n\ndata: {"message":"World"}\n'
372+
)
373+
);
374+
controller.enqueue(
375+
new TextEncoder().encode('data: {"result":"Final Result"}\n')
376+
);
363377
controller.close();
364378
}
365379
});
@@ -368,10 +382,13 @@ describe('Firebase Functions > Stream', () => {
368382
body: mockResponse,
369383
headers: new Headers({ 'Content-Type': 'text/event-stream' }),
370384
status: 200,
371-
statusText: 'OK',
385+
statusText: 'OK'
372386
} as Response);
373387

374-
const func = httpsCallable<Record<string, any>, string, string>(functions, 'streamTest');
388+
const func = httpsCallable<Record<string, any>, string, string>(
389+
functions,
390+
'streamTest'
391+
);
375392
const streamResult = await func.stream({});
376393

377394
const messages: string[] = [];
@@ -386,7 +403,10 @@ describe('Firebase Functions > Stream', () => {
386403
it('handles network errors', async () => {
387404
mockFetch.rejects(new Error('Network error'));
388405

389-
const func = httpsCallable<Record<string, any>, string, string>(functions, 'errTest');
406+
const func = httpsCallable<Record<string, any>, string, string>(
407+
functions,
408+
'errTest'
409+
);
390410
const streamResult = await func.stream({});
391411

392412
let errorThrown = false;
@@ -396,16 +416,22 @@ describe('Firebase Functions > Stream', () => {
396416
}
397417
} catch (error: unknown) {
398418
errorThrown = true;
399-
expect((error as FunctionsError).code).to.equal(`${FUNCTIONS_TYPE}/internal`);
419+
expect((error as FunctionsError).code).to.equal(
420+
`${FUNCTIONS_TYPE}/internal`
421+
);
400422
}
401423
expect(errorThrown).to.be.true;
402-
await expectError(streamResult.data, "internal", "internal");
424+
await expectError(streamResult.data, 'internal', 'internal');
403425
});
404426

405427
it('handles server-side errors', async () => {
406428
const mockResponse = new ReadableStream({
407429
start(controller) {
408-
controller.enqueue(new TextEncoder().encode('data: {"error":{"status":"INVALID_ARGUMENT","message":"Invalid input"}}\n'));
430+
controller.enqueue(
431+
new TextEncoder().encode(
432+
'data: {"error":{"status":"INVALID_ARGUMENT","message":"Invalid input"}}\n'
433+
)
434+
);
409435
controller.close();
410436
}
411437
});
@@ -414,10 +440,13 @@ describe('Firebase Functions > Stream', () => {
414440
body: mockResponse,
415441
headers: new Headers({ 'Content-Type': 'text/event-stream' }),
416442
status: 200,
417-
statusText: 'OK',
443+
statusText: 'OK'
418444
} as Response);
419445

420-
const func = httpsCallable<Record<string, any>, string, string>(functions, 'stream');
446+
const func = httpsCallable<Record<string, any>, string, string>(
447+
functions,
448+
'stream'
449+
);
421450
const streamResult = await func.stream({});
422451

423452
let errorThrown = false;
@@ -427,12 +456,14 @@ describe('Firebase Functions > Stream', () => {
427456
}
428457
} catch (error) {
429458
errorThrown = true;
430-
expect((error as FunctionsError).code).to.equal(`${FUNCTIONS_TYPE}/invalid-argument`);
459+
expect((error as FunctionsError).code).to.equal(
460+
`${FUNCTIONS_TYPE}/invalid-argument`
461+
);
431462
expect((error as FunctionsError).message).to.equal('Invalid input');
432463
}
433464

434465
expect(errorThrown).to.be.true;
435-
await expectError(streamResult.data, "invalid-argument", "Invalid input");
466+
await expectError(streamResult.data, 'invalid-argument', 'Invalid input');
436467
});
437468

438469
it('includes authentication and app check tokens in request headers', async () => {
@@ -461,12 +492,20 @@ describe('Firebase Functions > Stream', () => {
461492
)
462493
);
463494

464-
const functions = createTestService(app, region, authProvider, undefined, appCheckProvider);
495+
const functions = createTestService(
496+
app,
497+
region,
498+
authProvider,
499+
undefined,
500+
appCheckProvider
501+
);
465502
const mockFetch = sinon.stub(functions, 'fetchImpl' as any);
466503

467504
const mockResponse = new ReadableStream({
468505
start(controller) {
469-
controller.enqueue(new TextEncoder().encode('data: {"result":"Success"}\n'));
506+
controller.enqueue(
507+
new TextEncoder().encode('data: {"result":"Success"}\n')
508+
);
470509
controller.close();
471510
}
472511
});
@@ -475,10 +514,13 @@ describe('Firebase Functions > Stream', () => {
475514
body: mockResponse,
476515
headers: new Headers({ 'Content-Type': 'text/event-stream' }),
477516
status: 200,
478-
statusText: 'OK',
517+
statusText: 'OK'
479518
} as Response);
480519

481-
const func = httpsCallable<Record<string, any>, string, string>(functions, 'stream');
520+
const func = httpsCallable<Record<string, any>, string, string>(
521+
functions,
522+
'stream'
523+
);
482524
await func.stream({});
483525

484526
expect(mockFetch.calledOnce).to.be.true;
@@ -501,7 +543,10 @@ describe('Firebase Functions > Stream', () => {
501543
});
502544
mockFetch.returns(fetchPromise);
503545

504-
const func = httpsCallable<Record<string, any>, string, string>(functions, 'streamTest');
546+
const func = httpsCallable<Record<string, any>, string, string>(
547+
functions,
548+
'streamTest'
549+
);
505550
const streamPromise = func.stream({}, { signal: controller.signal });
506551

507552
controller.abort();
@@ -521,23 +566,31 @@ describe('Firebase Functions > Stream', () => {
521566
}
522567
} catch (error) {
523568
errorThrown = true;
524-
expect((error as FunctionsError).code).to.equal(`${FUNCTIONS_TYPE}/cancelled`);
569+
expect((error as FunctionsError).code).to.equal(
570+
`${FUNCTIONS_TYPE}/cancelled`
571+
);
525572
}
526573
expect(errorThrown).to.be.true;
527-
await expectError(streamResult.data, "cancelled", "Request was cancelled.");
574+
await expectError(streamResult.data, 'cancelled', 'Request was cancelled.');
528575
});
529576

530577
it('aborts during streaming', async () => {
531578
const controller = new AbortController();
532579

533580
const mockResponse = new ReadableStream({
534581
async start(controller) {
535-
controller.enqueue(new TextEncoder().encode('data: {"message":"First"}\n'));
582+
controller.enqueue(
583+
new TextEncoder().encode('data: {"message":"First"}\n')
584+
);
536585
// Add delay to simulate network latency
537586
await new Promise(resolve => setTimeout(resolve, 50));
538-
controller.enqueue(new TextEncoder().encode('data: {"message":"Second"}\n'));
587+
controller.enqueue(
588+
new TextEncoder().encode('data: {"message":"Second"}\n')
589+
);
539590
await new Promise(resolve => setTimeout(resolve, 50));
540-
controller.enqueue(new TextEncoder().encode('data: {"result":"Final"}\n'));
591+
controller.enqueue(
592+
new TextEncoder().encode('data: {"result":"Final"}\n')
593+
);
541594
controller.close();
542595
}
543596
});
@@ -546,10 +599,13 @@ describe('Firebase Functions > Stream', () => {
546599
body: mockResponse,
547600
headers: new Headers({ 'Content-Type': 'text/event-stream' }),
548601
status: 200,
549-
statusText: 'OK',
602+
statusText: 'OK'
550603
} as Response);
551604

552-
const func = httpsCallable<Record<string, any>, string, string>(functions, 'streamTest');
605+
const func = httpsCallable<Record<string, any>, string, string>(
606+
functions,
607+
'streamTest'
608+
);
553609
const streamResult = await func.stream({}, { signal: controller.signal });
554610

555611
const messages: string[] = [];
@@ -563,10 +619,12 @@ describe('Firebase Functions > Stream', () => {
563619
}
564620
throw new Error('Stream should have been aborted');
565621
} catch (error) {
566-
expect((error as FunctionsError).code).to.equal(`${FUNCTIONS_TYPE}/cancelled`);
622+
expect((error as FunctionsError).code).to.equal(
623+
`${FUNCTIONS_TYPE}/cancelled`
624+
);
567625
}
568626
expect(messages).to.deep.equal(['First']);
569-
await expectError(streamResult.data, "cancelled", "Request was cancelled.");
627+
await expectError(streamResult.data, 'cancelled', 'Request was cancelled.');
570628
});
571629

572630
it('fails immediately with pre-aborted signal', async () => {
@@ -578,7 +636,10 @@ describe('Firebase Functions > Stream', () => {
578636
}
579637
return Promise.resolve(new Response());
580638
});
581-
const func = httpsCallable<Record<string, any>, string, string>(functions, 'streamTest');
639+
const func = httpsCallable<Record<string, any>, string, string>(
640+
functions,
641+
'streamTest'
642+
);
582643
const streamResult = await func.stream({}, { signal: AbortSignal.abort() });
583644

584645
let errorThrown = false;
@@ -588,10 +649,12 @@ describe('Firebase Functions > Stream', () => {
588649
}
589650
} catch (error) {
590651
errorThrown = true;
591-
expect((error as FunctionsError).code).to.equal(`${FUNCTIONS_TYPE}/cancelled`);
652+
expect((error as FunctionsError).code).to.equal(
653+
`${FUNCTIONS_TYPE}/cancelled`
654+
);
592655
}
593656
expect(errorThrown).to.be.true;
594-
await expectError(streamResult.data, "cancelled", "Request was cancelled.");
657+
await expectError(streamResult.data, 'cancelled', 'Request was cancelled.');
595658
});
596659

597660
it('properly handles AbortSignal.timeout()', async () => {
@@ -612,7 +675,10 @@ describe('Firebase Functions > Stream', () => {
612675
return new Response();
613676
});
614677

615-
const func = httpsCallable<Record<string, any>, string, string>(functions, 'streamTest');
678+
const func = httpsCallable<Record<string, any>, string, string>(
679+
functions,
680+
'streamTest'
681+
);
616682
const streamResult = await func.stream({}, { signal });
617683

618684
try {
@@ -621,8 +687,10 @@ describe('Firebase Functions > Stream', () => {
621687
}
622688
throw new Error('Stream should have timed out');
623689
} catch (error) {
624-
expect((error as FunctionsError).code).to.equal(`${FUNCTIONS_TYPE}/cancelled`);
690+
expect((error as FunctionsError).code).to.equal(
691+
`${FUNCTIONS_TYPE}/cancelled`
692+
);
625693
}
626-
await expectError(streamResult.data, "cancelled", "Request was cancelled.");
694+
await expectError(streamResult.data, 'cancelled', 'Request was cancelled.');
627695
});
628696
});

packages/functions/src/public-types.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export interface HttpsCallableResult<ResponseData = unknown> {
3131
* An `HttpsCallableStreamResult` wraps a single streaming result from a function call.
3232
* @public
3333
*/
34-
export interface HttpsCallableStreamResult<ResponseData = unknown, StreamData = unknown> {
34+
export interface HttpsCallableStreamResult<
35+
ResponseData = unknown,
36+
StreamData = unknown
37+
> {
3538
readonly data: Promise<ResponseData>;
3639
readonly stream: AsyncIterable<StreamData>;
3740
}
@@ -41,9 +44,16 @@ export interface HttpsCallableStreamResult<ResponseData = unknown, StreamData =
4144
* @param data - Data to be passed to callable function.
4245
* @public
4346
*/
44-
export interface HttpsCallable<RequestData = unknown, ResponseData = unknown, StreamData = unknown> {
47+
export interface HttpsCallable<
48+
RequestData = unknown,
49+
ResponseData = unknown,
50+
StreamData = unknown
51+
> {
4552
(data?: RequestData | null): Promise<HttpsCallableResult<ResponseData>>;
46-
stream: (data?: RequestData | null, options?: HttpsCallableStreamOptions) => Promise<HttpsCallableStreamResult<ResponseData, StreamData>>;
53+
stream: (
54+
data?: RequestData | null,
55+
options?: HttpsCallableStreamOptions
56+
) => Promise<HttpsCallableStreamResult<ResponseData, StreamData>>;
4757
}
4858

4959
/**
@@ -64,7 +74,6 @@ export interface HttpsCallableOptions {
6474
limitedUseAppCheckTokens?: boolean;
6575
}
6676

67-
6877
/**
6978
* An interface for metadata about how stream call should be executed.
7079
* @public
@@ -74,11 +83,9 @@ export interface HttpsCallableStreamOptions {
7483
* An AbortSignal that can be used to cancel the streaming response. When the signal is aborted,
7584
* both the underlying connection and stream will be terminated.
7685
*/
77-
signal?: AbortSignal
86+
signal?: AbortSignal;
7887
}
7988

80-
81-
8289
/**
8390
* A `Functions` instance.
8491
* @public

0 commit comments

Comments
 (0)