import type { ImportDeclarationStructure, OptionalKind } from 'ts-morph'; import { IGNORE_BUT_FOLLOW_REFS, type InterfaceOverridesMap, type TypeOverrideMap, } from './types.ts'; import { docStringLines } from './comments.ts'; export const IMPORTS: OptionalKind[] = [ { isTypeOnly: true, moduleSpecifier: './custom', namedImports: [ 'AfterResponseMiddleware', 'BeforeRequestMiddleware', 'PerformFunction', ], }, { isTypeOnly: true, moduleSpecifier: './inputs', namedImports: ['InputFields', 'InferInputData'], }, { isTypeOnly: true, moduleSpecifier: './functions', namedImports: [ 'PollingTriggerPerform', 'WebhookTriggerPerform', 'WebhookTriggerPerformList', 'WebhookTriggerPerformSubscribe', 'WebhookTriggerPerformUnsubscribe', 'HookToPollTriggerPerformList', 'HookToPollTriggerPerformSubscribe', 'HookToPollTriggerPerformUnsubscribe', 'CreatePerform', 'CreatePerformResume', 'CreatePerformGet', 'SearchPerform', 'SearchPerformGet', 'SearchPerformResume', 'OAuth2AuthorizeUrl', 'OAuth2GetAccessToken', 'OAuth2RefreshAccessToken', ], }, ]; const KeyTypeParam = { name: '$Key', constraint: 'string', default: 'string', }; const InputFieldsTypeParam = { name: '$InputFields', constraint: 'InputFields', default: 'InputFields', }; export const INTERFACE_OVERRIDES: InterfaceOverridesMap = { // AppSchema is renamed to BaseApp. The Triggers, Creates, and // Searches are deliberately omitted, and separately handled by a the // `App` type from `./apps.d.ts` in zapier-platform-core, which // extends this BaseApp type. '/AppSchema': { self: { name: 'BaseApp' }, properties: { beforeRequest: 'BeforeRequestMiddleware | BeforeRequestMiddleware[]', afterResponse: 'AfterResponseMiddleware | AfterResponseMiddleware[]', creates: IGNORE_BUT_FOLLOW_REFS, triggers: IGNORE_BUT_FOLLOW_REFS, searches: IGNORE_BUT_FOLLOW_REFS, }, }, '/TriggerSchema': { self: { typeParameters: [KeyTypeParam, InputFieldsTypeParam] }, properties: { key: '$Key', operation: 'BasicPollingOperation<$InputFields> | BasicHookOperation<$InputFields> | BasicHookToPollOperation<$InputFields>', }, }, '/CreateSchema': { self: { typeParameters: [KeyTypeParam, InputFieldsTypeParam] }, properties: { key: '$Key', operation: 'BasicCreateOperation<$InputFields>', }, }, '/SearchSchema': { self: { typeParameters: [KeyTypeParam, InputFieldsTypeParam] }, properties: { key: '$Key', operation: 'BasicSearchOperation<$InputFields>', }, }, '/BasicPollingOperationSchema': { self: { typeParameters: [InputFieldsTypeParam] }, properties: { inputFields: '$InputFields', perform: 'Request | PollingTriggerPerform>', }, }, '/BasicHookOperationSchema': { self: { typeParameters: [InputFieldsTypeParam] }, properties: { inputFields: '$InputFields', perform: 'WebhookTriggerPerform>', performList: 'Request | WebhookTriggerPerformList>', performSubscribe: 'Request | WebhookTriggerPerformSubscribe>', performUnsubscribe: 'Request | WebhookTriggerPerformUnsubscribe>', }, }, '/BasicHookToPollOperationSchema': { self: { typeParameters: [InputFieldsTypeParam] }, properties: { inputFields: '$InputFields', performList: 'Request | HookToPollTriggerPerformList>', performSubscribe: 'Request | HookToPollTriggerPerformSubscribe>', performUnsubscribe: 'Request | HookToPollTriggerPerformUnsubscribe>', }, }, '/BasicCreateOperationSchema': { self: { typeParameters: [InputFieldsTypeParam] }, properties: { inputFields: '$InputFields', perform: 'Request | CreatePerform>', performResume: 'CreatePerformResume>', performGet: 'Request | CreatePerformGet>', }, }, '/BasicSearchOperationSchema': { self: { typeParameters: [InputFieldsTypeParam] }, properties: { inputFields: '$InputFields', perform: 'Request | SearchPerform>', performGet: 'Request | SearchPerformGet>', performResume: 'SearchPerformResume>', }, }, }; export const TYPE_OVERRIDES: TypeOverrideMap = { '/FunctionSchema': ({ file, typeName, schema }) => { file.addTypeAlias({ name: typeName, isExported: true, docs: docStringLines( schema.description, '\n\n@deprecated Prefer using the perform types from the `functions` module.', ), type: 'PerformFunction', leadingTrivia: '\n', }); }, // Don't render this type as it's replaced by an import. We do want // the plain input field type it references to be rendered, though. '/InputFieldsSchema': IGNORE_BUT_FOLLOW_REFS, // Don't render these types because they're reimplemented by // apps.d.ts in zapier-platform-core '/TriggersSchema': IGNORE_BUT_FOLLOW_REFS, '/CreatesSchema': IGNORE_BUT_FOLLOW_REFS, '/SearchesSchema': IGNORE_BUT_FOLLOW_REFS, };