import { DaoHookShared, DaoHookSharedParsed, DaoShared, DaoSharedParsed, daoHookNamesShared, DaoGenericMethods, MaskHook } from '../../../types/core.types.js' import mongoose from 'mongoose' import { AsFilter, RequestConfigGetOne, RequestConfigRead, RequestConfigWrite, PopulateConfig, SortConfig } from './mongoDaoTypes.js' import type { ModelNames, DbIds, AllDbIds } from '../../../cache/dbs/index.generated.js' export * from './mongoDaoTypes.js' export const daoHookNamesMongo = [...daoHookNamesShared, 'filter', 'mask'] as const export type DaoHookNamesMongo = typeof daoHookNamesMongo[number] export type LocalConfigParsed = { dbName: keyof DbIds dbId: AllDbIds, modelName: ModelNames method: DaoGenericMethods /** provided for write method to specify which config is used when returning document */ methodForRead: DaoGenericMethods isLocalConfig: true filter: AsFilter withDeleted?: boolean // may be used when retrieving archived datas inputFields?: Record ressourceId?: string filterSanitized?: boolean // isHardDelete: boolean } & (RequestConfigGetOne | RequestConfigRead | RequestConfigWrite) type MongoDaoShared< ModelType extends Record, DaoConf extends DaoHookShared | DaoHookSharedParsed > = NoExtraProperties<{ /** configs for mongoose models */ modelConfig?: { indexes?: string[] /** if false, it will not delete anything, instead it will turn isDeleted field to true and thus will be filtered from all get requests */ // hardDelete?: boolean // TODO }, /** Allow a path to match a certain pattern, please return string in format '* /* /blah...' (without white spaces) * TODO allow also type string */ mask?: NoExtraProperties>[] /** Allow to filter allowed data when fields contains a certain value or on custom code * * Use a function to modify exisitng filter * * OR use a filter object that is going to be merged with actual filter with precedence */ filter?: (DaoConf & { filter: (ctx: Ctx & LocalConfigParsed, filter: AsFilter) => void | Promise | ObjectGeneric | Promise | AsFilter })[] /** configure populate for all requests */ populate?: PopulateConfig[] /** configure sorting for all requests */ sort?: SortConfig }> export type MongoDao> = DaoShared & Partial> & { type: 'mongo' } export type MongoDaoParsed> = DaoSharedParsed & MongoDaoShared & { type: 'mongo' } export type MongoHooks = { [dbName: string]: { [modelName: string]: MongoDaoParsed } } // DELETEME TODO // export type MongoConnexionConfigs = { // [dbName in DbNames]: { // /** Useful if there is one DB in the project // * * ALLOW ctx.db.dbTypeName.collectionNameGetAll() // * * INSTEAD OF ctx.db.dbTypeName.dbName.collectionNameGetAll() */ // databaseURL: string // mongoOptions?: mongoose.ConnectOptions // } // } export type MongooseConnexion = mongoose.Connection