import"./fields-extensions.mjs";import{COMPENDIUM_DOCUMENT_TYPES,COMPATIBILITY_MODES}from"../../common/constants.mjs";import LevelDatabase from"./backend/level-database.mjs";import ServerDatabaseBackend from"./backend/server-backend.mjs";import ServerCompendiumMixin from"./backend/server-compendium.mjs";import ActiveEffect from"./documents/active-effect.mjs";import Actor from"./documents/actor.mjs";import ActorDelta from"./documents/actor-delta.mjs";import Adventure from"./documents/adventure.mjs";import AmbientLight from"./documents/ambient-light.mjs";import AmbientSound from"./documents/ambient-sound.mjs";import Card from"./documents/card.mjs";import Cards from"./documents/cards.mjs";import ChatMessage from"./documents/chat-message.mjs";import Combat from"./documents/combat.mjs";import Combatant from"./documents/combatant.mjs";import Drawing from"./documents/drawing.mjs";import FogExploration from"./documents/fog.mjs";import Folder from"./documents/folder.mjs";import Item from"./documents/item.mjs";import JournalEntry from"./documents/journal.mjs";import JournalEntryPage from"./documents/journal-page.mjs";import Playlist from"./documents/playlist.mjs";import MeasuredTemplate from"./documents/measured-template.mjs";import Note from"./documents/note.mjs";import Region from"./documents/region.mjs";import RegionBehavior from"./documents/region-behavior.mjs";import Scene from"./documents/scene.mjs";import Setting from"./documents/setting.mjs";import TableResult from"./documents/table-result.mjs";import Tile from"./documents/tile.mjs";import Token from"./documents/token.mjs";import User from"./documents/user.mjs";import Wall from"./documents/wall.mjs";import{CombatantGroup,JournalEntryCategory,Macro,PlaylistSound,RollTable}from"./documents/others.mjs";export const DatabaseBackend=new ServerDatabaseBackend;export const documents=[Actor,Cards,ChatMessage,Combat,FogExploration,Folder,Item,JournalEntry,Macro,Playlist,RollTable,Scene,Setting,User];export function getDocumentClass(e){return global.db[e]}export async function disconnect(){const e=[];for(const t of packs.values())e.push(t.disconnect());packs.clear();for(const t of documents)e.push(t.disconnect()),t.clearSanitizedFields();const t=await Promise.allSettled(e);e.length=0;for(let t of LevelDatabase.databases.values())e.push(t.close());const o=await Promise.allSettled(e);for(const e of t.concat(o))"rejected"===e.status&&global.logger.error(e.reason)}export const packs=new Map;export function defineCompendium(e){_validateCompendiumMetadata(e);const t=global.db[e.type],o=ServerCompendiumMixin(t,e);return db.packs.set(o.collectionName,o),o}function _validateCompendiumMetadata(e={}){if(!("name"in e))throw new Error("Compendium packs must define a canonical name");if(!("path"in e))throw new Error("Compendium packs must specify their relative file path.");if(!("type"in e))throw new Error("Compendium packs must specify the document type they contain.");if(!("absPath"in e))throw new Error("An absolute file path must be provided when a new Compendium is defined.");if(!COMPENDIUM_DOCUMENT_TYPES.includes(e.type))throw new Error(`Compendium ${e.label} is configured for an invalid Document type ${e.type}`);return!0}globalThis.CONFIG={compatibility:{mode:COMPATIBILITY_MODES.WARNING,includePatterns:[],excludePatterns:[]},DatabaseBackend:DatabaseBackend,Actor:{documentClass:Actor},Adventure:{documentClass:foundry.documents.BaseAdventure},Cards:{documentClass:Cards},ChatMessage:{documentClass:ChatMessage},Combat:{documentClass:Combat},FogExploration:{documentClass:FogExploration},Folder:{documentClass:Folder},Item:{documentClass:Item},JournalEntry:{documentClass:JournalEntry},JournalEntryCategory:{documentClass:JournalEntryCategory},JournalEntryPage:{documentClass:JournalEntryPage},Macro:{documentClass:Macro},Playlist:{documentClass:Playlist},RollTable:{documentClass:RollTable},Scene:{documentClass:Scene},Setting:{documentClass:Setting},User:{documentClass:User},ActiveEffect:{documentClass:ActiveEffect},Card:{documentClass:Card},TableResult:{documentClass:TableResult},PlaylistSound:{documentClass:PlaylistSound},AmbientLight:{documentClass:AmbientLight},AmbientSound:{documentClass:AmbientSound},Combatant:{documentClass:Combatant},CombatantGroup:{documentClass:CombatantGroup},Drawing:{documentClass:Drawing},MeasuredTemplate:{documentClass:MeasuredTemplate},Note:{documentClass:Note},Region:{documentClass:Region},RegionBehavior:{documentClass:RegionBehavior},Tile:{documentClass:Tile},Token:{documentClass:Token},Wall:{documentClass:Wall},ActorDelta:{documentClass:ActorDelta}};export{Actor,ActiveEffect,Adventure,AmbientLight,AmbientSound,Card,Cards,ChatMessage,Combat,Combatant,CombatantGroup,Drawing,FogExploration,Folder,Item,JournalEntry,JournalEntryCategory,JournalEntryPage,MeasuredTemplate,Note,Playlist,PlaylistSound,Scene,Setting,Macro,RollTable,Region,RegionBehavior,TableResult,Tile,Token,ActorDelta,User,Wall};