From 551f4da2062178b9ab5f32f58e95841997766f48 Mon Sep 17 00:00:00 2001 From: Corie Watson Date: Thu, 28 May 2026 20:05:13 +0100 Subject: [PATCH 1/3] fix: tighten v2 wrapper event typing --- spec/v2.spec.ts | 13 +++++++++++++ src/v2.ts | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/spec/v2.spec.ts b/spec/v2.spec.ts index 1101aa7..ef9cec7 100644 --- a/spec/v2.spec.ts +++ b/spec/v2.spec.ts @@ -39,12 +39,25 @@ import { import { defineString } from 'firebase-functions/params'; import { makeDataSnapshot } from '../src/providers/database'; import { makeDocumentSnapshot } from '../src/providers/firestore'; +import { makeChange } from '../src/v1'; import { inspect } from 'util'; describe('v2', () => { describe('#wrapV2', () => { const handler = (cloudEvent) => ({ cloudEvent }); + function assertWrappedV2FunctionTypes() { + const cloudFn = firestore.onDocumentWritten('foo/bar/baz', handler); + const cloudFnWrap = wrapV2(cloudFn); + const before = makeDocumentSnapshot({ snapshot: 'before' }, 'foo/bar/baz'); + const after = makeDocumentSnapshot({ snapshot: 'after' }, 'foo/bar/baz'); + const change = makeChange(before, after); + + cloudFnWrap({ data: change }); + // @ts-expect-error V2 wrappers accept CloudEvent partials, not raw event data. + cloudFnWrap(change); + } + describe('alerts', () => { describe('alerts.onAlertPublished()', () => { it('should update CloudEvent appropriately', () => { diff --git a/src/v2.ts b/src/v2.ts index e3fef18..9fdc883 100644 --- a/src/v2.ts +++ b/src/v2.ts @@ -27,11 +27,17 @@ import { generateCombinedCloudEvent } from './cloudevent/generate'; import { DeepPartial } from './cloudevent/types'; import * as express from 'express'; +type WrappedV2CloudEventPartial> = DeepPartial< + Omit +> & { + data?: T['data'] | object; +}; + /** A function that can be called with test data and optional override values for {@link CloudEvent} * It will subsequently invoke the cloud function it wraps with the provided {@link CloudEvent} */ export type WrappedV2Function> = ( - cloudEventPartial?: DeepPartial + cloudEventPartial?: WrappedV2CloudEventPartial ) => any | Promise; export type WrappedV2CallableFunction = ( From 00b942d5bd57d7b5ebf74635816b4d5343124b58 Mon Sep 17 00:00:00 2001 From: Corie Watson Date: Fri, 29 May 2026 15:59:00 +0100 Subject: [PATCH 2/3] test: run v2 wrapper type assertions --- spec/v2.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/v2.spec.ts b/spec/v2.spec.ts index ef9cec7..ef0932c 100644 --- a/spec/v2.spec.ts +++ b/spec/v2.spec.ts @@ -46,7 +46,7 @@ describe('v2', () => { describe('#wrapV2', () => { const handler = (cloudEvent) => ({ cloudEvent }); - function assertWrappedV2FunctionTypes() { + it('should restrict V2 wrapper arguments to CloudEvent partials', () => { const cloudFn = firestore.onDocumentWritten('foo/bar/baz', handler); const cloudFnWrap = wrapV2(cloudFn); const before = makeDocumentSnapshot({ snapshot: 'before' }, 'foo/bar/baz'); @@ -56,7 +56,7 @@ describe('v2', () => { cloudFnWrap({ data: change }); // @ts-expect-error V2 wrappers accept CloudEvent partials, not raw event data. cloudFnWrap(change); - } + }); describe('alerts', () => { describe('alerts.onAlertPublished()', () => { From 4d6b2f17827d4bc6eee22a42c2dad324cce02743 Mon Sep 17 00:00:00 2001 From: Corie Watson Date: Fri, 29 May 2026 16:54:02 +0100 Subject: [PATCH 3/3] style: format v2 wrapper type test --- spec/v2.spec.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/v2.spec.ts b/spec/v2.spec.ts index ef0932c..6a4b77b 100644 --- a/spec/v2.spec.ts +++ b/spec/v2.spec.ts @@ -49,7 +49,10 @@ describe('v2', () => { it('should restrict V2 wrapper arguments to CloudEvent partials', () => { const cloudFn = firestore.onDocumentWritten('foo/bar/baz', handler); const cloudFnWrap = wrapV2(cloudFn); - const before = makeDocumentSnapshot({ snapshot: 'before' }, 'foo/bar/baz'); + const before = makeDocumentSnapshot( + { snapshot: 'before' }, + 'foo/bar/baz' + ); const after = makeDocumentSnapshot({ snapshot: 'after' }, 'foo/bar/baz'); const change = makeChange(before, after);