import { type Class, hasFunction } from '@travetto/runtime'; import { type ModelType, type ModelCrudSupport, ModelRegistryIndex } from '@travetto/model'; import type { ModelQueryCrudSupport } from '../types/crud.ts'; export class ModelQueryCrudUtil { /** * Type guard for determining if service supports query crud operations */ static isSupported = hasFunction('deleteByQuery'); /** * Delete all expired */ static async deleteExpired(service: ModelQueryCrudSupport & ModelCrudSupport, cls: Class): Promise { const expiry = await ModelRegistryIndex.getExpiryFieldName(cls); const count = await service.deleteByQuery(cls, { where: { [expiry]: { $lt: new Date() } } }); return count ?? 0; } }