import { expectAssignable, expectType } from 'tsd'; import type { PollingTriggerPerform, SearchPerform } from './functions'; import { Bundle, ZObject } from './custom'; import { InferInputData } from './inputs'; import { defineInputFields } from './typeHelpers'; const simplePerform = (async (z, bundle) => { return [{ id: '1', name: 'test' }]; }) satisfies PollingTriggerPerform; expectAssignable>( simplePerform, ); const primaryKeyOverridePerform = (async (z, bundle) => { return [{ itemId: 123, name: 'test' }]; }) satisfies PollingTriggerPerform<{}, { itemId: number; name: string }>; expectAssignable>( primaryKeyOverridePerform, ); // // Automatic inputData inference // // Pass shape directly const simplePerformWithInputFields = (async (z, bundle) => { return [{ id: '1', name: 'test' }]; }) satisfies PollingTriggerPerform<{ key: 'string' }>; expectType< ( z: ZObject, bundle: Bundle<{ key: 'string' }>, ) => Promise<{ id: string; name: string }[]> >(simplePerformWithInputFields); // Use InputFields and manually infer inputData const inputFields = defineInputFields([ { key: 'key1', type: 'string', required: true }, { key: 'key2', type: 'number', required: false }, ]); const simplePerformWithInputFieldsAndManualInference = (async (z, bundle) => { return [{ id: '1', name: 'test' }]; }) satisfies PollingTriggerPerform>; expectType< ( z: ZObject, bundle: Bundle<{ key1: string; key2?: number | undefined }>, ) => Promise<{ id: string; name: string }[]> >(simplePerformWithInputFieldsAndManualInference); // Use inputFields and automatically infer inputData const simplePerformWithInputFieldsAndAutomaticInference = (async ( z, bundle, ) => { return [{ id: '1', name: 'test' }]; }) satisfies PollingTriggerPerform; expectType< ( z: ZObject, bundle: Bundle<{ key1: string; key2?: number | undefined }>, ) => Promise<{ id: string; name: string }[]> >(simplePerformWithInputFieldsAndAutomaticInference); // // SearchResult and SearchPerform tests // // Test SearchResult with simple array return const simpleSearchPerform = (async (z, bundle) => { return [{ id: '1', name: 'test' }]; }) satisfies SearchPerform; expectAssignable>( simpleSearchPerform, ); // Test SearchResult with paginated object return const paginatedSearchPerform = (async (z, bundle) => { return { results: [{ id: '1', name: 'test' }], paging_token: 'next-page-token', }; }) satisfies SearchPerform; expectAssignable>( paginatedSearchPerform, ); // Test SearchResult with null paging_token const nullPagingTokenSearchPerform = (async (z, bundle) => { return { results: [{ id: '1', name: 'test' }], paging_token: null, }; }) satisfies SearchPerform; expectAssignable>( nullPagingTokenSearchPerform, ); // Test SearchResult with undefined paging_token const undefinedPagingTokenSearchPerform = (async (z, bundle) => { return { results: [{ id: '1', name: 'test' }], paging_token: undefined, }; }) satisfies SearchPerform; expectAssignable>( undefinedPagingTokenSearchPerform, ); // Test SearchResult with empty results array const emptyResultsSearchPerform = (async (z, bundle) => { return { results: [], paging_token: 'next-page-token', }; }) satisfies SearchPerform; expectAssignable>( emptyResultsSearchPerform, ); // Test SearchResult with empty array return const emptyArraySearchPerform = (async (z, bundle) => { return []; }) satisfies SearchPerform; expectAssignable>( emptyArraySearchPerform, );