{"version":3,"file":"plugin.cjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { GenePlugin, PluginSettings, PrototypeOrNot, TypeDefLines } from 'graphql-gene'\nimport type { InferAttributes } from 'sequelize'\nimport { Model } from 'sequelize-typescript'\nimport { defaultResolver } from './defaultResolver'\nimport { populateTypeDefs } from './populateTypeDefs'\nimport type { GeneModel } from './constants'\nimport type { DefaultResolverIncludeOptions } from './types'\n\ndeclare module 'graphql-gene/plugin-settings' {\n  export interface GenePluginSettings<M> {\n    sequelize: PluginSettings<{\n      isMatching: PrototypeOrNot<M> extends Model ? true : false\n      fieldName: PrototypeOrNot<M> extends Model\n        ? keyof InferAttributes<PrototypeOrNot<M>> extends string\n          ? keyof InferAttributes<PrototypeOrNot<M>>\n          : 'id'\n        : 'id'\n      findOptionsState: DefaultResolverIncludeOptions\n    }>\n  }\n}\n\nexport const plugin = (): GenePlugin<typeof GeneModel> => {\n  return {\n    isMatching: model => isSequelizeFieldConfig(model),\n\n    /**\n     * @deprecated In favor of \"populateTypeDefs\"\n     */\n    getTypeDef(options) {\n      const typeDefLines: TypeDefLines = {}\n      populateTypeDefs({ typeDefLines, ...options })\n\n      return typeDefLines[options.typeName]\n    },\n    populateTypeDefs,\n    defaultResolver,\n  }\n}\n\nfunction isSequelizeFieldConfig<T>(\n  fieldConfigs: T\n): fieldConfigs is T extends typeof Model ? T & Model : T {\n  return (\n    fieldConfigs &&\n    (typeof fieldConfigs === 'object' || typeof fieldConfigs === 'function') &&\n    'sequelize' in fieldConfigs\n  )\n}\n"],"mappings":"gLAsBA,IAAa,OACJ,CACL,WAAY,GAAS,EAAuB,EAAM,CAKlD,WAAW,EAAS,CAClB,IAAM,EAA6B,EAAE,CAGrC,OAFA,EAAA,iBAAiB,CAAE,eAAc,GAAG,EAAS,CAAC,CAEvC,EAAa,EAAQ,WAE9B,iBAAA,EAAA,iBACA,gBAAA,EAAA,gBACD,EAGH,SAAS,EACP,EACwD,CACxD,OACE,IACC,OAAO,GAAiB,UAAY,OAAO,GAAiB,aAC7D,cAAe"}