import { assign } from "lodash"; import { ConnectOptions } from "mongoose"; import { MongooseModule } from "./helpers"; export { AccountCallerType, AccountIndustry, DepartmentReportOdometer, DroneProvider, FireMapperLayers, IncidentFilterKind, LocationKindType, LocationSource, LocationVisibility, NerisBenchmarkType, ShareIncidentRuleKind, UserStealthStatus, } from "./constants"; async function wireModels(mongoose: MongooseModule) { type ModelType unknown>> = ReturnType; async function getModel unknown>>(m: Promise): Promise> { const module = await m; return module.default(mongoose) as Promise>; } return { ADSB: await getModel(import("./models/adsb")), ActionLog: await getModel(import("./models/action-log")), Agency: await getModel(import("./models/agency")), ArcGISGroup: await getModel(import("./models/arcgis-group")), Assignment: await getModel(import("./models/assignment")), Battalion: await getModel(import("./models/battalion")), BeaconLog: await getModel(import("./models/beacon-log")), CADIncident: await getModel(import("./models/cad-incident")), CADIncidentBlock: await getModel(import("./models/cad-incident-block")), CADIncidentStream: await getModel(import("./models/cad-incident-stream")), CADInterfaceMetaData: await getModel(import("./models/cad-interface-meta-data")), CADSimulation: await getModel(import("./models/cad-simulation")), CADStatus: await getModel(import("./models/cad-status")), CADStatusMap: await getModel(import("./models/cad-status-map")), CADVehicle: await getModel(import("./models/cad-vehicle")), CADVehicleStatus: await getModel(import("./models/cad-vehicle-status")), CADVehicleStatusHistory: await getModel(import("./models/cad-vehicle-status-history")), ChartDeviceStats: await getModel(import("./models/chart-device-stats")), ChartIncident: await getModel(import("./models/chart-incident")), ChartManagedIncident: await getModel(import("./models/chart-managed-incident")), ChartUser: await getModel(import("./models/chart-user")), Checklist: await getModel(import("./models/checklist")), ChecklistItem: await getModel(import("./models/checklist-item")), CSVImport: await getModel(import("./models/csv-import")), AudioStreamAuthentication: await getModel(import("./models/audio-stream-authentication")), DataSharingAgreement: await getModel(import("./models/data-sharing-agreement")), Department: await getModel(import("./models/department")), DeviceMapping: await getModel(import("./models/device-mapping")), DroneConnection: await getModel(import("./models/drone-connection")), Esri: await getModel(import("./models/esri")), GSTMapping: await getModel(import("./models/gst-mapping")), GlobalSettings: await getModel(import("./models/global-settings")), IncidentEvent: await getModel(import("./models/incident-event")), IncidentFilter: await getModel(import("./models/incident-filter")), IncidentFilterGlobal: await getModel(import("./models/incident-filter-global")), IncidentNotified: await getModel(import("./models/incident-notified")), IncidentShareCode: await getModel(import("./models/incident-share-code")), IncidentTakeover: await getModel(import("./models/incident-takeover")), JobLog: await getModel(import("./models/job-log")), KindTypeCatalog: await getModel(import("./models/kindtype-catalog")), Location: await getModel(import("./models/location")), MailLog: await getModel(import("./models/mail-log")), ManagedIncident: await getModel(import("./models/managed-incident")), Mark43IncidentRetry: await getModel(import("./models/mark43-incident-retry")), Message: await getModel(import("./models/message")), Monitor: await getModel(import("./models/monitor")), PersonnelImport: await getModel(import("./models/personnel-import")), PersonnelKnown: await getModel(import("./models/personnel-known")), Partner: await getModel(import("./models/partner")), PersonnelRoster: await getModel(import("./models/personnel-roster")), RateLimit: await getModel(import("./models/rate-limit")), ReleaseNote: await getModel(import("./models/release-note")), RemoteLog: await getModel(import("./models/remote-log")), RemoteLogStream: await getModel(import("./models/remote-log-stream")), Session: await getModel(import("./models/session")), SAML: await getModel(import("./models/saml")), SMSLog: await getModel(import("./models/sms-log")), SMTPUnhandled: await getModel(import("./models/smtp-unhandled")), StatusBeacon: await getModel(import("./models/status-beacon")), StatusBeaconTransition: await getModel(import("./models/status-beacon-transition")), Template: await getModel(import("./models/template")), TrackerResponder: await getModel(import("./models/tracker-responder")), User: await getModel(import("./models/user")), UserDevice: await getModel(import("./models/user-device")), UserRegistration: await getModel(import("./models/user-registration")), ValidationReport: await getModel(import("./models/validation-report")), WatchDutyEvent: await getModel(import("./models/watchduty-event")), ZonehavenAccount: await getModel(import("./models/zonehaven-account")), }; } export { ActionLog, ActionLogModel } from "./models/action-log"; export { ADSB, ADSBModel } from "./models/adsb"; export { Agency, AgencyModel } from "./models/agency"; export { ArcGISGroup, ArcGISGroupModel } from "./models/arcgis-group"; export { Assignment, AssignmentModel } from "./models/assignment"; export { Battalion, BattalionModel } from "./models/battalion"; export { BeaconLog, BeaconLogModel } from "./models/beacon-log"; export { CADIncident, CADIncidentModel } from "./models/cad-incident"; export { CADIncidentBlock, CADIncidentBlockModel } from "./models/cad-incident-block"; export { CADIncidentStream, CADIncidentStreamModel } from "./models/cad-incident-stream"; export { CADInterfaceMetaData, CADInterfaceMetaDataModel } from "./models/cad-interface-meta-data"; export { CADSimulation, CADSimulationModel } from "./models/cad-simulation"; export { CADStatus, CADStatusModel } from "./models/cad-status"; export { CADStatusMap, CADStatusMapModel } from "./models/cad-status-map"; export { CADVehicle, CADVehicleModel } from "./models/cad-vehicle"; export { CADVehicleStatus, CADVehicleStatusModel } from "./models/cad-vehicle-status"; export { CADVehicleStatusHistory, CADVehicleStatusHistoryModel } from "./models/cad-vehicle-status-history"; export { ChartDeviceStats, ChartDeviceStatsModel } from "./models/chart-device-stats"; export { ChartIncident, ChartIncidentModel } from "./models/chart-incident"; export { ChartManagedIncident, ChartManagedIncidentModel } from "./models/chart-managed-incident"; export { ChartUser, ChartUserModel } from "./models/chart-user"; export { Checklist, ChecklistModel } from "./models/checklist"; export { ChecklistItem, ChecklistItemModel } from "./models/checklist-item"; export { CSVImport, CSVImportModel } from "./models/csv-import"; export { AudioStreamAuthentication, AudioStreamAuthenticationModel } from "./models/audio-stream-authentication"; export { DataSharingAgreement, DataSharingAgreementModel } from "./models/data-sharing-agreement"; export { Department, DepartmentModel } from "./models/department"; export { DeviceMapping, DeviceMappingModel } from "./models/device-mapping"; export { DroneConnection, DroneConnectionModel } from "./models/drone-connection"; export { Esri, EsriModel } from "./models/esri"; export { GSTMapping, GSTMappingModel } from "./models/gst-mapping"; export { GlobalSettings, GlobalSettingsModel } from "./models/global-settings"; export { IncidentEvent, IncidentEventModel } from "./models/incident-event"; export { IncidentFilter, IncidentFilterModel } from "./models/incident-filter"; export { IncidentFilterGlobal, IncidentFilterGlobalModel } from "./models/incident-filter-global"; export { IncidentNotified, IncidentNotifiedModel } from "./models/incident-notified"; export { IncidentShareCode, IncidentShareCodeModel } from "./models/incident-share-code"; export { IncidentTakeover, IncidentTakeoverModel } from "./models/incident-takeover"; export { JobLog, JobLogModel } from "./models/job-log"; export { KindTypeCatalog, KindTypeCatalogModel } from "./models/kindtype-catalog"; export { Location, LocationModel } from "./models/location"; export { MailLog, MailLogModel } from "./models/mail-log"; export { ManagedIncident, ManagedIncidentModel } from "./models/managed-incident"; export { Mark43IncidentRetry, Mark43IncidentRetryModel } from "./models/mark43-incident-retry"; export { Message, MessageModel } from "./models/message"; export { Monitor, MonitorModel } from "./models/monitor"; export { PersonnelImport, PersonnelImportModel } from "./models/personnel-import"; export { PersonnelKnown, PersonnelKnownModel } from "./models/personnel-known"; export { Partner, PartnerModel } from "./models/partner"; export { PersonnelRoster, PersonnelRosterModel } from "./models/personnel-roster"; export { RateLimit, RateLimitModel } from "./models/rate-limit"; export { ReleaseNote, ReleaseNoteModel } from "./models/release-note"; export { RemoteLog, RemoteLogModel } from "./models/remote-log"; export { RemoteLogStream, RemoteLogStreamModel } from "./models/remote-log-stream"; export { Session, SessionModel } from "./models/session"; export { SAML, SAMLModel } from "./models/saml"; export { SMSLog, SMSLogModel } from "./models/sms-log"; export { SMTPUnhandled, SMTPUnhandledModel } from "./models/smtp-unhandled"; export { StatusBeacon, StatusBeaconModel } from "./models/status-beacon"; export { StatusBeaconTransition, StatusBeaconTransitionModel } from "./models/status-beacon-transition"; export { Template, TemplateModel } from "./models/template"; export { TrackerResponder, TrackerResponderModel } from "./models/tracker-responder"; export { User, UserModel } from "./models/user"; export { UserDevice, UserDeviceModel } from "./models/user-device"; export { UserRegistration, UserRegistrationModel } from "./models/user-registration"; export { ValidationReport, ValidationReportModel } from "./models/validation-report"; export { WatchDutyEvent, WatchDutyEventModel } from "./models/watchduty-event"; export { ZonehavenAccount, ZonehavenAccountModel } from "./models/zonehaven-account"; export * from "./helpers"; export { IntegrationTypes } from "./types/department"; export { DataSharingAgreementActions } from "./types/data-sharing-agreement"; export * from "./checklist-item-event-message"; // Export types export type { DronesConfigurationType, DronesVideoType, DronesVideoUrlsType, ForwardingConnectionType, ForwardingConfigType, ForwardFieldsType, IntegrationType, AccountConfigurationZonehaven, } from "./types/department"; export type { DroneConnectionOptionsType, DroneConnectionType, } from "./types/drone-connection"; export type { CADInterfaceMetaDataType, } from "./types/cad-interface-meta-data"; export type { DataSharingAgreementAction, DataSharingAgreementType, DataSharingVendorConsentType, } from "./types/data-sharing-agreement"; export type { ZonehavenAccountType, } from "./types/zonehaven-account"; // Export default vars export { ManagedIncidentModeDefault, ManagedIncidentPriorityDefault, OrientationMarkerColorDefault, } from "./models/department"; export async function connect(url: string, overwriteOpts?: ConnectOptions, enableDebug = false) { const mongoose = await import("mongoose"); mongoose.set("debug", enableDebug); const models = await wireModels(mongoose); const defaultOpts: ConnectOptions = { autoIndex: false, readPreference: "primaryPreferred", }; // If present, overwrite options const opts: ConnectOptions = assign({}, defaultOpts, overwriteOpts); const connection = await mongoose.connect(url, opts); return { connection, models, mongoose, }; } type UnboxPromise> = T extends Promise ? U : never; export type BackendModels = UnboxPromise>["models"]; export type MongooseTypes = MongooseModule; export default connect;