@league-of-foundry-developers/foundry-vtt-types 12.331.3-beta → 12.331.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (559) hide show
  1. package/README.md +17 -18
  2. package/package.json +91 -32
  3. package/src/configuration/configuration.d.mts +316 -0
  4. package/src/configuration/documents.d.mts +295 -0
  5. package/src/configuration/globals.d.mts +357 -0
  6. package/src/configuration/index.d.mts +5 -0
  7. package/src/foundry/client/apps/app.d.mts +129 -122
  8. package/src/foundry/client/apps/av/av-config.d.mts +12 -7
  9. package/src/foundry/client/apps/av/cameras.d.mts +12 -7
  10. package/src/foundry/client/apps/dice/dice-config.d.mts +59 -0
  11. package/src/foundry/client/apps/dice/index.d.mts +1 -0
  12. package/src/foundry/client/apps/form.d.mts +114 -86
  13. package/src/foundry/client/apps/forms/actor.d.mts +21 -11
  14. package/src/foundry/client/apps/forms/adventure-exporter.d.mts +12 -7
  15. package/src/foundry/client/apps/forms/adventure-importer.d.mts +14 -6
  16. package/src/foundry/client/apps/forms/base-sheet.d.mts +16 -8
  17. package/src/foundry/client/apps/forms/card-config.d.mts +16 -8
  18. package/src/foundry/client/apps/forms/cards-config.d.mts +15 -14
  19. package/src/foundry/client/apps/forms/combat-config.d.mts +7 -7
  20. package/src/foundry/client/apps/forms/combatant-config.d.mts +3 -3
  21. package/src/foundry/client/apps/forms/default-sheets-config.d.mts +1 -1
  22. package/src/foundry/client/apps/forms/effect-config.d.mts +7 -7
  23. package/src/foundry/client/apps/forms/folder-config.d.mts +10 -5
  24. package/src/foundry/client/apps/forms/fonts.d.mts +42 -35
  25. package/src/foundry/client/apps/forms/grid-config.d.mts +12 -13
  26. package/src/foundry/client/apps/forms/image-popout.d.mts +29 -23
  27. package/src/foundry/client/apps/forms/item.d.mts +9 -9
  28. package/src/foundry/client/apps/forms/journal-page-sheet.d.mts +16 -14
  29. package/src/foundry/client/apps/forms/journal-sheet.d.mts +48 -38
  30. package/src/foundry/client/apps/forms/macro-config.d.mts +7 -7
  31. package/src/foundry/client/apps/forms/measure-template.d.mts +10 -12
  32. package/src/foundry/client/apps/forms/ownership.d.mts +5 -5
  33. package/src/foundry/client/apps/forms/playlist-config.d.mts +8 -10
  34. package/src/foundry/client/apps/forms/playlist-sound-config.d.mts +7 -7
  35. package/src/foundry/client/apps/forms/roll-table-config.d.mts +11 -10
  36. package/src/foundry/client/apps/forms/scene-config.d.mts +40 -41
  37. package/src/foundry/client/apps/forms/sheet-config.d.mts +9 -21
  38. package/src/foundry/client/apps/forms/user-config.d.mts +13 -12
  39. package/src/foundry/client/apps/hud/chatbubble.d.mts +18 -6
  40. package/src/foundry/client/apps/hud/container.d.mts +4 -4
  41. package/src/foundry/client/apps/hud/controls.d.mts +126 -81
  42. package/src/foundry/client/apps/hud/hotbar.d.mts +17 -12
  43. package/src/foundry/client/apps/hud/hud.d.mts +5 -5
  44. package/src/foundry/client/apps/hud/menu.d.mts +10 -3
  45. package/src/foundry/client/apps/hud/navigation.d.mts +14 -9
  46. package/src/foundry/client/apps/hud/pause.d.mts +9 -4
  47. package/src/foundry/client/apps/hud/players.d.mts +14 -9
  48. package/src/foundry/client/apps/i18n.d.mts +31 -27
  49. package/src/foundry/client/apps/index.d.mts +1 -0
  50. package/src/foundry/client/apps/placeables/drawing-config.d.mts +41 -33
  51. package/src/foundry/client/apps/placeables/drawing-hud.d.mts +5 -5
  52. package/src/foundry/client/apps/placeables/index.d.mts +0 -2
  53. package/src/foundry/client/apps/placeables/note-config.d.mts +28 -18
  54. package/src/foundry/client/apps/placeables/tile-config.d.mts +23 -10
  55. package/src/foundry/client/apps/placeables/tile-hud.d.mts +10 -5
  56. package/src/foundry/client/apps/placeables/token-config.d.mts +91 -58
  57. package/src/foundry/client/apps/placeables/token-hud.d.mts +12 -7
  58. package/src/foundry/client/apps/placeables/wall-config.d.mts +21 -17
  59. package/src/foundry/client/apps/sidebar/apps/chat-popout.d.mts +5 -5
  60. package/src/foundry/client/apps/sidebar/apps/client-settings.d.mts +3 -3
  61. package/src/foundry/client/apps/sidebar/apps/compendium.d.mts +15 -13
  62. package/src/foundry/client/apps/sidebar/apps/invitation-links.d.mts +3 -3
  63. package/src/foundry/client/apps/sidebar/apps/keybindings-config.d.mts +3 -2
  64. package/src/foundry/client/apps/sidebar/apps/module-management.d.mts +6 -6
  65. package/src/foundry/client/apps/sidebar/apps/permission-config.d.mts +6 -6
  66. package/src/foundry/client/apps/sidebar/apps/support-details.d.mts +34 -29
  67. package/src/foundry/client/apps/sidebar/apps/tours-management.d.mts +2 -2
  68. package/src/foundry/client/apps/sidebar/apps/world-config.d.mts +13 -10
  69. package/src/foundry/client/apps/sidebar/directory-tab-mixin.d.mts +50 -35
  70. package/src/foundry/client/apps/sidebar/document-directory.d.mts +52 -38
  71. package/src/foundry/client/apps/sidebar/package-configuration.d.mts +4 -4
  72. package/src/foundry/client/apps/sidebar/sidebar-tab.d.mts +3 -3
  73. package/src/foundry/client/apps/sidebar/sidebar.d.mts +9 -4
  74. package/src/foundry/client/apps/sidebar/tabs/actors-directory.d.mts +11 -2
  75. package/src/foundry/client/apps/sidebar/tabs/cards-directory.d.mts +11 -2
  76. package/src/foundry/client/apps/sidebar/tabs/chat-log.d.mts +39 -27
  77. package/src/foundry/client/apps/sidebar/tabs/combat-tracker.d.mts +21 -12
  78. package/src/foundry/client/apps/sidebar/tabs/compendium-directory.d.mts +30 -15
  79. package/src/foundry/client/apps/sidebar/tabs/items-directory.d.mts +11 -2
  80. package/src/foundry/client/apps/sidebar/tabs/journal-directory.d.mts +11 -2
  81. package/src/foundry/client/apps/sidebar/tabs/macros-directory.d.mts +14 -5
  82. package/src/foundry/client/apps/sidebar/tabs/playlists-directory.d.mts +30 -22
  83. package/src/foundry/client/apps/sidebar/tabs/roll-table-directory.d.mts +11 -2
  84. package/src/foundry/client/apps/sidebar/tabs/scenes-directory.d.mts +14 -5
  85. package/src/foundry/client/apps/sidebar/tabs/settings.d.mts +23 -5
  86. package/src/foundry/client/apps/templates.d.mts +1 -1
  87. package/src/foundry/client/av/client.d.mts +1 -1
  88. package/src/foundry/client/av/clients/simplepeer.d.mts +11 -1
  89. package/src/foundry/client/av/master.d.mts +2 -2
  90. package/src/foundry/client/av/settings.d.mts +17 -15
  91. package/src/foundry/client/config.d.mts +444 -312
  92. package/src/foundry/client/core/document-index.d.mts +11 -3
  93. package/src/foundry/client/core/hooks.d.mts +2 -4
  94. package/src/foundry/client/core/image.d.mts +14 -13
  95. package/src/foundry/client/core/issues.d.mts +9 -4
  96. package/src/foundry/client/core/keybindings.d.mts +5 -5
  97. package/src/foundry/client/core/nue.d.mts +1 -1
  98. package/src/foundry/client/core/packages.d.mts +400 -62
  99. package/src/foundry/client/core/settings.d.mts +62 -38
  100. package/src/foundry/client/core/socket.d.mts +2 -2
  101. package/src/foundry/client/core/sorting.d.mts +6 -6
  102. package/src/foundry/client/core/time.d.mts +6 -3
  103. package/src/foundry/client/core/tooltip.d.mts +2 -2
  104. package/src/foundry/client/core/tour.d.mts +59 -50
  105. package/src/foundry/client/core/tours.d.mts +1 -1
  106. package/src/foundry/client/core/utils.d.mts +33 -10
  107. package/src/foundry/client/core/video.d.mts +1 -1
  108. package/src/foundry/client/core/workers.d.mts +24 -17
  109. package/src/foundry/client/data/abstract/canvas-document.d.mts +22 -28
  110. package/src/foundry/client/data/abstract/client-document.d.mts +238 -206
  111. package/src/foundry/client/data/abstract/directory-collection-mixin.d.mts +24 -40
  112. package/src/foundry/client/data/abstract/document-collection.d.mts +96 -68
  113. package/src/foundry/client/data/abstract/world-collection.d.mts +53 -54
  114. package/src/foundry/client/data/collections/actors.d.mts +30 -28
  115. package/src/foundry/client/data/collections/cards.d.mts +16 -3
  116. package/src/foundry/client/data/collections/combats.d.mts +18 -5
  117. package/src/foundry/client/data/collections/compendium-collection.d.mts +84 -101
  118. package/src/foundry/client/data/collections/compendium-folders.d.mts +6 -6
  119. package/src/foundry/client/data/collections/compendium-packs.d.mts +5 -5
  120. package/src/foundry/client/data/collections/fog.d.mts +16 -3
  121. package/src/foundry/client/data/collections/folder.d.mts +20 -6
  122. package/src/foundry/client/data/collections/items.d.mts +17 -4
  123. package/src/foundry/client/data/collections/journal.d.mts +22 -7
  124. package/src/foundry/client/data/collections/macros.d.mts +21 -19
  125. package/src/foundry/client/data/collections/messages.d.mts +19 -6
  126. package/src/foundry/client/data/collections/playlists.d.mts +17 -5
  127. package/src/foundry/client/data/collections/scenes.d.mts +24 -27
  128. package/src/foundry/client/data/collections/settings.d.mts +16 -3
  129. package/src/foundry/client/data/collections/tables.d.mts +18 -5
  130. package/src/foundry/client/data/collections/users.d.mts +22 -10
  131. package/src/foundry/client/data/documents/active-effect.d.mts +780 -112
  132. package/src/foundry/client/data/documents/actor-delta.d.mts +705 -31
  133. package/src/foundry/client/data/documents/actor.d.mts +806 -98
  134. package/src/foundry/client/data/documents/adventure.d.mts +522 -59
  135. package/src/foundry/client/data/documents/ambient-light.d.mts +427 -20
  136. package/src/foundry/client/data/documents/ambient-sound.d.mts +478 -14
  137. package/src/foundry/client/data/documents/card.d.mts +598 -44
  138. package/src/foundry/client/data/documents/cards.d.mts +862 -169
  139. package/src/foundry/client/data/documents/chat-message.d.mts +668 -77
  140. package/src/foundry/client/data/documents/combat.d.mts +757 -107
  141. package/src/foundry/client/data/documents/combatant.d.mts +545 -32
  142. package/src/foundry/client/data/documents/drawing.d.mts +545 -14
  143. package/src/foundry/client/data/documents/fog-exploration.d.mts +465 -30
  144. package/src/foundry/client/data/documents/folder.d.mts +567 -51
  145. package/src/foundry/client/data/documents/index.d.mts +2 -0
  146. package/src/foundry/client/data/documents/item.d.mts +691 -24
  147. package/src/foundry/client/data/documents/journal-entry-page.d.mts +654 -55
  148. package/src/foundry/client/data/documents/journal-entry.d.mts +631 -35
  149. package/src/foundry/client/data/documents/macro.d.mts +560 -31
  150. package/src/foundry/client/data/documents/measured-template.d.mts +484 -15
  151. package/src/foundry/client/data/documents/note.d.mts +498 -15
  152. package/src/foundry/client/data/documents/playlist-sound.d.mts +443 -45
  153. package/src/foundry/client/data/documents/playlist.d.mts +710 -99
  154. package/src/foundry/client/data/documents/region-behavior.d.mts +516 -0
  155. package/src/foundry/client/data/documents/region.d.mts +789 -0
  156. package/src/foundry/client/data/documents/scene.d.mts +1216 -159
  157. package/src/foundry/client/data/documents/setting.d.mts +406 -23
  158. package/src/foundry/client/data/documents/table-result.d.mts +488 -14
  159. package/src/foundry/client/data/documents/table.d.mts +667 -78
  160. package/src/foundry/client/data/documents/tile.d.mts +505 -14
  161. package/src/foundry/client/data/documents/token.d.mts +1191 -143
  162. package/src/foundry/client/data/documents/user.d.mts +613 -57
  163. package/src/foundry/client/data/documents/wall.d.mts +555 -14
  164. package/src/foundry/client/game.d.mts +60 -92
  165. package/src/foundry/client/head.d.mts +9 -9
  166. package/src/foundry/client/hooks.d.mts +259 -248
  167. package/src/foundry/client/pixi/board.d.mts +107 -94
  168. package/src/foundry/client/pixi/core/containers/base-canvas-group.d.mts +97 -25
  169. package/src/foundry/client/pixi/core/containers/cached-container.d.mts +37 -19
  170. package/src/foundry/client/pixi/core/containers/full-canvas-container.d.mts +7 -10
  171. package/src/foundry/client/pixi/core/containers/point-source-mesh.d.mts +25 -15
  172. package/src/foundry/client/pixi/core/containers/quad-mesh.d.mts +16 -6
  173. package/src/foundry/client/pixi/core/containers/quadtree.d.mts +113 -54
  174. package/src/foundry/client/pixi/core/containers/sprite-mesh.d.mts +69 -26
  175. package/src/foundry/client/pixi/core/containers/unbound-container.d.mts +20 -2
  176. package/src/foundry/client/pixi/core/interaction/canvas-animation.d.mts +164 -99
  177. package/src/foundry/client/pixi/core/interaction/control-icon.d.mts +61 -22
  178. package/src/foundry/client/pixi/core/interaction/mouse-handler.d.mts +120 -53
  179. package/src/foundry/client/pixi/core/interaction/ping.d.mts +62 -31
  180. package/src/foundry/client/pixi/core/interaction/pings/chevron.d.mts +23 -10
  181. package/src/foundry/client/pixi/core/interaction/pings/pulse.d.mts +91 -34
  182. package/src/foundry/client/pixi/core/interaction/render-flags.d.mts +69 -30
  183. package/src/foundry/client/pixi/core/interaction/resize-handle.d.mts +35 -5
  184. package/src/foundry/client/pixi/core/interaction/targets.d.mts +21 -18
  185. package/src/foundry/client/pixi/core/loader.d.mts +86 -76
  186. package/src/foundry/client/pixi/core/shapes/limited-angle-polygon.d.mts +42 -17
  187. package/src/foundry/client/pixi/core/shapes/polygon-mesher.d.mts +92 -64
  188. package/src/foundry/client/pixi/core/shapes/precise-text.d.mts +28 -10
  189. package/src/foundry/client/pixi/core/shapes/ray.d.mts +47 -23
  190. package/src/foundry/client/pixi/core/shapes/source-polygon.d.mts +170 -75
  191. package/src/foundry/client/pixi/extensions/circle.d.mts +128 -125
  192. package/src/foundry/client/pixi/extensions/graphics.d.mts +3 -1
  193. package/src/foundry/client/pixi/extensions/observable-transform.d.mts +5 -4
  194. package/src/foundry/client/pixi/extensions/polygon.d.mts +154 -134
  195. package/src/foundry/client/pixi/extensions/rectangle.d.mts +242 -259
  196. package/src/foundry/client/pixi/groups/effects.d.mts +75 -24
  197. package/src/foundry/client/pixi/groups/environment.d.mts +68 -19
  198. package/src/foundry/client/pixi/groups/hidden.d.mts +27 -11
  199. package/src/foundry/client/pixi/groups/interface.d.mts +62 -38
  200. package/src/foundry/client/pixi/groups/overlay.d.mts +19 -7
  201. package/src/foundry/client/pixi/groups/primary.d.mts +66 -44
  202. package/src/foundry/client/pixi/groups/rendered.d.mts +19 -7
  203. package/src/foundry/client/pixi/layers/base/canvas-layer.d.mts +11 -15
  204. package/src/foundry/client/pixi/layers/base/interaction-layer.d.mts +29 -28
  205. package/src/foundry/client/pixi/layers/base/placeables-layer.d.mts +306 -272
  206. package/src/foundry/client/pixi/layers/controls/cursor.d.mts +18 -9
  207. package/src/foundry/client/pixi/layers/controls/door.d.mts +32 -11
  208. package/src/foundry/client/pixi/layers/controls/layer.d.mts +89 -77
  209. package/src/foundry/client/pixi/layers/controls/ruler.d.mts +121 -96
  210. package/src/foundry/client/pixi/layers/effects/background-effects.d.mts +9 -12
  211. package/src/foundry/client/pixi/layers/effects/coloration-effects.d.mts +9 -10
  212. package/src/foundry/client/pixi/layers/effects/darkness-effects.d.mts +8 -8
  213. package/src/foundry/client/pixi/layers/effects/illumination-effects.d.mts +22 -22
  214. package/src/foundry/client/pixi/layers/effects/visibility.d.mts +106 -86
  215. package/src/foundry/client/pixi/layers/effects/weather/particles/effect.d.mts +14 -5
  216. package/src/foundry/client/pixi/layers/effects/weather/particles/leaves.d.mts +31 -2
  217. package/src/foundry/client/pixi/layers/effects/weather-effects.d.mts +137 -65
  218. package/src/foundry/client/pixi/layers/grid/highlight.d.mts +14 -4
  219. package/src/foundry/client/pixi/layers/grid/layer.d.mts +92 -92
  220. package/src/foundry/client/pixi/layers/grid/mesh.d.mts +37 -16
  221. package/src/foundry/client/pixi/layers/masks/depth.d.mts +12 -7
  222. package/src/foundry/client/pixi/layers/masks/occlusion.d.mts +19 -12
  223. package/src/foundry/client/pixi/layers/masks/vision.d.mts +104 -18
  224. package/src/foundry/client/pixi/layers/placeables/drawings.d.mts +16 -15
  225. package/src/foundry/client/pixi/layers/placeables/index.d.mts +1 -0
  226. package/src/foundry/client/pixi/layers/placeables/lighting.d.mts +12 -14
  227. package/src/foundry/client/pixi/layers/placeables/notes.d.mts +49 -32
  228. package/src/foundry/client/pixi/layers/placeables/regions.d.mts +113 -0
  229. package/src/foundry/client/pixi/layers/placeables/sounds.d.mts +81 -67
  230. package/src/foundry/client/pixi/layers/placeables/templates.d.mts +11 -15
  231. package/src/foundry/client/pixi/layers/placeables/tiles.d.mts +30 -21
  232. package/src/foundry/client/pixi/layers/placeables/tokens.d.mts +66 -52
  233. package/src/foundry/client/pixi/layers/placeables/walls.d.mts +54 -57
  234. package/src/foundry/client/pixi/perception/clockwise-sweep.d.mts +62 -27
  235. package/src/foundry/client/pixi/perception/detection-mode.d.mts +121 -47
  236. package/src/foundry/client/pixi/perception/fog.d.mts +38 -15
  237. package/src/foundry/client/pixi/perception/perception-manager.d.mts +136 -136
  238. package/src/foundry/client/pixi/perception/vision-mode.d.mts +91 -64
  239. package/src/foundry/client/pixi/perception/weiler-atherton-clipping.d.mts +44 -16
  240. package/src/foundry/client/pixi/placeable.d.mts +239 -137
  241. package/src/foundry/client/pixi/placeables/drawing.d.mts +255 -133
  242. package/src/foundry/client/pixi/placeables/index.d.mts +1 -0
  243. package/src/foundry/client/pixi/placeables/light.d.mts +193 -64
  244. package/src/foundry/client/pixi/placeables/note.d.mts +145 -54
  245. package/src/foundry/client/pixi/placeables/primary-canvas-objects/primary-canvas-object.d.mts +30 -8
  246. package/src/foundry/client/pixi/placeables/primary-canvas-objects/primary-graphics.d.mts +41 -11
  247. package/src/foundry/client/pixi/placeables/primary-canvas-objects/primary-occludable-object.d.mts +59 -18
  248. package/src/foundry/client/pixi/placeables/primary-canvas-objects/primary-sprite-mesh.d.mts +120 -37
  249. package/src/foundry/client/pixi/placeables/region.d.mts +280 -0
  250. package/src/foundry/client/pixi/placeables/sound.d.mts +205 -66
  251. package/src/foundry/client/pixi/placeables/template.d.mts +181 -100
  252. package/src/foundry/client/pixi/placeables/tile.d.mts +206 -140
  253. package/src/foundry/client/pixi/placeables/token.d.mts +916 -449
  254. package/src/foundry/client/pixi/placeables/wall.d.mts +249 -129
  255. package/src/foundry/client/pixi/webgl/extensions/batch-renderer.d.mts +72 -33
  256. package/src/foundry/client/pixi/webgl/extensions/batch-shader-generator.d.mts +10 -9
  257. package/src/foundry/client/pixi/webgl/helpers/{framebugger-snapshot.d.mts → framebuffer-snapshot.d.mts} +10 -9
  258. package/src/foundry/client/pixi/webgl/helpers/index.d.mts +1 -1
  259. package/src/foundry/client/pixi/webgl/helpers/smooth-noise.d.mts +38 -23
  260. package/src/foundry/client/pixi/webgl/helpers/texture-extractor.d.mts +82 -53
  261. package/src/foundry/client/pixi/webgl/shaders/base-shader-mixin.d.mts +12 -12
  262. package/src/foundry/client/pixi/webgl/shaders/base-shader.d.mts +45 -28
  263. package/src/foundry/client/pixi/webgl/shaders/filters/base-filter.d.mts +12 -11
  264. package/src/foundry/client/pixi/webgl/shaders/filters/base-mask-filter.d.mts +12 -10
  265. package/src/foundry/client/pixi/webgl/shaders/filters/blur.d.mts +22 -20
  266. package/src/foundry/client/pixi/webgl/shaders/filters/effects-masking.d.mts +36 -32
  267. package/src/foundry/client/pixi/webgl/shaders/filters/environment.d.mts +10 -9
  268. package/src/foundry/client/pixi/webgl/shaders/filters/glow-overlay.d.mts +12 -11
  269. package/src/foundry/client/pixi/webgl/shaders/filters/invisibility.d.mts +10 -9
  270. package/src/foundry/client/pixi/webgl/shaders/filters/outline-overlay.d.mts +12 -11
  271. package/src/foundry/client/pixi/webgl/shaders/filters/transition.d.mts +67 -60
  272. package/src/foundry/client/pixi/webgl/shaders/filters/visibility.d.mts +24 -17
  273. package/src/foundry/client/pixi/webgl/shaders/filters/vision-mask-filter.d.mts +13 -10
  274. package/src/foundry/client/pixi/webgl/shaders/filters/void.d.mts +10 -9
  275. package/src/foundry/client/pixi/webgl/shaders/filters/weather-occlusion-masks.d.mts +11 -10
  276. package/src/foundry/client/pixi/webgl/shaders/fragment-channel-mixin.d.mts +20 -14
  277. package/src/foundry/client/pixi/webgl/shaders/grid/grid.d.mts +12 -11
  278. package/src/foundry/client/pixi/webgl/shaders/lighting/background-lighting.d.mts +10 -9
  279. package/src/foundry/client/pixi/webgl/shaders/lighting/base-lighting.d.mts +33 -33
  280. package/src/foundry/client/pixi/webgl/shaders/lighting/coloration-lighting.d.mts +10 -9
  281. package/src/foundry/client/pixi/webgl/shaders/lighting/darkness-lighting.d.mts +10 -9
  282. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/bewitching-wave.d.mts +19 -17
  283. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/black-hole.d.mts +10 -9
  284. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/chroma.d.mts +10 -9
  285. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/emanation.d.mts +10 -9
  286. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/energy-field.d.mts +10 -9
  287. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/fairy-light.d.mts +19 -17
  288. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/flame.d.mts +19 -17
  289. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/fog.d.mts +10 -9
  290. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/force-grid.d.mts +10 -8
  291. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/ghost-light.d.mts +19 -17
  292. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/hexa-dome.d.mts +10 -9
  293. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/light-dome.d.mts +10 -9
  294. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/magical-gloom.d.mts +10 -9
  295. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/pulse.d.mts +19 -17
  296. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/radial-rainbow.d.mts +10 -9
  297. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/revolving-light.d.mts +10 -9
  298. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/roiling-mass.d.mts +10 -9
  299. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/siren-light.d.mts +19 -17
  300. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/smoke-patch.d.mts +20 -17
  301. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/star-light.d.mts +10 -9
  302. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/sunburst.d.mts +19 -17
  303. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/swirling-rainbow.d.mts +10 -9
  304. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/torch.d.mts +19 -17
  305. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/vortex.d.mts +19 -17
  306. package/src/foundry/client/pixi/webgl/shaders/lighting/effects/wave.d.mts +19 -17
  307. package/src/foundry/client/pixi/webgl/shaders/lighting/illumination-lighting.d.mts +10 -9
  308. package/src/foundry/client/pixi/webgl/shaders/region/adjust-darkness-level.d.mts +71 -29
  309. package/src/foundry/client/pixi/webgl/shaders/region/base.d.mts +54 -10
  310. package/src/foundry/client/pixi/webgl/shaders/region/highlight.d.mts +69 -9
  311. package/src/foundry/client/pixi/webgl/shaders/samplers/base-sampler.d.mts +24 -25
  312. package/src/foundry/client/pixi/webgl/shaders/samplers/baseline-illumination.d.mts +10 -9
  313. package/src/foundry/client/pixi/webgl/shaders/samplers/color-adjustment.d.mts +38 -29
  314. package/src/foundry/client/pixi/webgl/shaders/samplers/depth.d.mts +21 -17
  315. package/src/foundry/client/pixi/webgl/shaders/samplers/fog-of-war.d.mts +10 -9
  316. package/src/foundry/client/pixi/webgl/shaders/samplers/occlusion.d.mts +20 -18
  317. package/src/foundry/client/pixi/webgl/shaders/samplers/primary.d.mts +11 -2
  318. package/src/foundry/client/pixi/webgl/shaders/samplers/token-ring.d.mts +28 -2
  319. package/src/foundry/client/pixi/webgl/shaders/vision/background-vision.d.mts +10 -9
  320. package/src/foundry/client/pixi/webgl/shaders/vision/base-vision.d.mts +11 -9
  321. package/src/foundry/client/pixi/webgl/shaders/vision/coloration-vision.d.mts +10 -9
  322. package/src/foundry/client/pixi/webgl/shaders/vision/effects/amplification.d.mts +10 -9
  323. package/src/foundry/client/pixi/webgl/shaders/vision/effects/wave.d.mts +19 -17
  324. package/src/foundry/client/pixi/webgl/shaders/vision/illumination-vision.d.mts +10 -9
  325. package/src/foundry/client/pixi/webgl/shaders/weather/base-weather.d.mts +40 -36
  326. package/src/foundry/client/pixi/webgl/shaders/weather/effect.d.mts +27 -33
  327. package/src/foundry/client/pixi/webgl/shaders/weather/fog.d.mts +17 -16
  328. package/src/foundry/client/pixi/webgl/shaders/weather/rain.d.mts +19 -18
  329. package/src/foundry/client/pixi/webgl/shaders/weather/snow.d.mts +15 -14
  330. package/src/foundry/client/pixi/workers/texture-worker.d.mts +33 -53
  331. package/src/foundry/client/tours/setup-tour.d.mts +15 -10
  332. package/src/foundry/client/ui/context.d.mts +48 -40
  333. package/src/foundry/client/ui/dialog.d.mts +137 -126
  334. package/src/foundry/client/ui/drag.d.mts +1 -1
  335. package/src/foundry/client/ui/dragdrop.d.mts +34 -28
  336. package/src/foundry/client/ui/editor.d.mts +29 -21
  337. package/src/foundry/client/ui/filepicker.d.mts +43 -38
  338. package/src/foundry/client/ui/filter.d.mts +62 -50
  339. package/src/foundry/client/ui/forms.d.mts +22 -22
  340. package/src/foundry/client/ui/notifications.d.mts +10 -3
  341. package/src/foundry/client/ui/prosemirror.d.mts +15 -7
  342. package/src/foundry/client/ui/secrets.d.mts +42 -27
  343. package/src/foundry/client/ui/tabs.d.mts +40 -33
  344. package/src/foundry/client-esm/applications/_module.d.mts +3 -3
  345. package/src/foundry/client-esm/applications/_types.d.mts +0 -2
  346. package/src/foundry/client-esm/applications/api/_module.d.mts +2 -2
  347. package/src/foundry/client-esm/applications/api/application.d.mts +28 -19
  348. package/src/foundry/client-esm/applications/api/dialog.d.mts +20 -22
  349. package/src/foundry/client-esm/applications/api/document-sheet.d.mts +26 -12
  350. package/src/foundry/client-esm/applications/api/handlebars-application.d.mts +142 -126
  351. package/src/foundry/client-esm/applications/apps/_module.d.mts +2 -2
  352. package/src/foundry/client-esm/applications/apps/compendium-art-config.d.mts +10 -10
  353. package/src/foundry/client-esm/applications/apps/permission-config.d.mts +3 -3
  354. package/src/foundry/client-esm/applications/dice/_module.d.mts +2 -2
  355. package/src/foundry/client-esm/applications/dice/roll-resolver.d.mts +14 -2
  356. package/src/foundry/client-esm/applications/elements/_module.d.mts +2 -2
  357. package/src/foundry/client-esm/applications/elements/document-tags.d.mts +2 -0
  358. package/src/foundry/client-esm/applications/elements/file-picker.d.mts +1 -1
  359. package/src/foundry/client-esm/applications/elements/multi-select.d.mts +15 -5
  360. package/src/foundry/client-esm/applications/elements/string-tags.d.mts +1 -1
  361. package/src/foundry/client-esm/applications/forms/fields.d.mts +1 -1
  362. package/src/foundry/client-esm/applications/sheets/_module.d.mts +2 -2
  363. package/src/foundry/client-esm/applications/sheets/actor-sheet.d.mts +3 -3
  364. package/src/foundry/client-esm/applications/sheets/ambient-light-config.d.mts +10 -8
  365. package/src/foundry/client-esm/applications/sheets/ambient-sound-config.d.mts +9 -7
  366. package/src/foundry/client-esm/applications/sheets/item-sheet.d.mts +3 -3
  367. package/src/foundry/client-esm/applications/sheets/region-behavior-config.d.mts +30 -5
  368. package/src/foundry/client-esm/applications/sheets/region-config.d.mts +36 -5
  369. package/src/foundry/client-esm/applications/sheets/user-config.d.mts +8 -7
  370. package/src/foundry/client-esm/applications/ui/_module.d.mts +2 -2
  371. package/src/foundry/client-esm/applications/ui/region-legend.d.mts +45 -3
  372. package/src/foundry/client-esm/audio/_module.d.mts +2 -3
  373. package/src/foundry/client-esm/audio/_types.d.mts +2 -0
  374. package/src/foundry/client-esm/audio/biquad.d.mts +76 -26
  375. package/src/foundry/client-esm/audio/cache.d.mts +31 -20
  376. package/src/foundry/client-esm/audio/convolver.d.mts +47 -25
  377. package/src/foundry/client-esm/audio/helper.d.mts +124 -80
  378. package/src/foundry/client-esm/audio/sound.d.mts +230 -126
  379. package/src/foundry/client-esm/audio/timeout.d.mts +28 -12
  380. package/src/foundry/client-esm/canvas/_module.d.mts +2 -2
  381. package/src/foundry/client-esm/canvas/edges/_module.d.mts +2 -2
  382. package/src/foundry/client-esm/canvas/edges/collision.d.mts +69 -18
  383. package/src/foundry/client-esm/canvas/edges/edge.d.mts +110 -41
  384. package/src/foundry/client-esm/canvas/edges/edges.d.mts +10 -0
  385. package/src/foundry/client-esm/canvas/edges/vertex.d.mts +56 -26
  386. package/src/foundry/client-esm/canvas/regions/_module.d.mts +6 -11
  387. package/src/foundry/client-esm/canvas/regions/geometry.d.mts +38 -0
  388. package/src/foundry/client-esm/canvas/regions/mesh.d.mts +72 -0
  389. package/src/foundry/client-esm/canvas/regions/polygon-tree.d.mts +130 -0
  390. package/src/foundry/client-esm/canvas/regions/shape.d.mts +129 -0
  391. package/src/foundry/client-esm/canvas/scene-manager.d.mts +13 -3
  392. package/src/foundry/client-esm/canvas/smaa/blend.d.mts +14 -3
  393. package/src/foundry/client-esm/canvas/smaa/edges.d.mts +25 -3
  394. package/src/foundry/client-esm/canvas/smaa/smaa.d.mts +121 -23
  395. package/src/foundry/client-esm/canvas/smaa/weights.d.mts +26 -3
  396. package/src/foundry/client-esm/canvas/sources/_module.d.mts +2 -2
  397. package/src/foundry/client-esm/canvas/sources/base-effect-source.d.mts +84 -40
  398. package/src/foundry/client-esm/canvas/sources/base-light-source.d.mts +103 -39
  399. package/src/foundry/client-esm/canvas/sources/global-light-source.d.mts +89 -15
  400. package/src/foundry/client-esm/canvas/sources/point-darkness-source.d.mts +71 -27
  401. package/src/foundry/client-esm/canvas/sources/point-effect-source.d.mts +49 -20
  402. package/src/foundry/client-esm/canvas/sources/point-light-source.d.mts +57 -16
  403. package/src/foundry/client-esm/canvas/sources/point-movement-source.d.mts +31 -4
  404. package/src/foundry/client-esm/canvas/sources/point-sound-source.d.mts +45 -12
  405. package/src/foundry/client-esm/canvas/sources/point-vision-source.d.mts +98 -52
  406. package/src/foundry/client-esm/canvas/sources/rendered-effect-source.d.mts +180 -69
  407. package/src/foundry/client-esm/canvas/tokens/_module.d.mts +2 -3
  408. package/src/foundry/client-esm/canvas/tokens/ring-config.d.mts +175 -2
  409. package/src/foundry/client-esm/canvas/tokens/ring-data.d.mts +142 -2
  410. package/src/foundry/client-esm/canvas/tokens/ring.d.mts +284 -2
  411. package/src/foundry/client-esm/client.d.mts +47 -54
  412. package/src/foundry/client-esm/data/_module.d.mts +2 -2
  413. package/src/foundry/client-esm/data/client-backend.d.mts +22 -23
  414. package/src/foundry/client-esm/data/region-behaviors/_module.d.mts +11 -14
  415. package/src/foundry/client-esm/data/region-behaviors/adjust-darkness-level.d.mts +56 -0
  416. package/src/foundry/client-esm/data/region-behaviors/base.d.mts +59 -0
  417. package/src/foundry/client-esm/data/region-behaviors/display-scrolling-text.d.mts +64 -0
  418. package/src/foundry/client-esm/data/region-behaviors/execute-macro.d.mts +27 -0
  419. package/src/foundry/client-esm/data/region-behaviors/execute-script.d.mts +23 -0
  420. package/src/foundry/client-esm/data/region-behaviors/pause-game.d.mts +23 -0
  421. package/src/foundry/client-esm/data/region-behaviors/suppress-weather.d.mts +17 -0
  422. package/src/foundry/client-esm/data/region-behaviors/teleport-token.d.mts +32 -0
  423. package/src/foundry/client-esm/data/region-behaviors/toggle-behavior.d.mts +31 -0
  424. package/src/foundry/client-esm/dice/_module.d.mts +2 -3
  425. package/src/foundry/client-esm/dice/parser.d.mts +11 -25
  426. package/src/foundry/client-esm/dice/roll.d.mts +112 -89
  427. package/src/foundry/client-esm/dice/terms/_module.d.mts +2 -3
  428. package/src/foundry/client-esm/dice/terms/coin.d.mts +8 -5
  429. package/src/foundry/client-esm/dice/terms/dice.d.mts +93 -63
  430. package/src/foundry/client-esm/dice/terms/die.d.mts +11 -4
  431. package/src/foundry/client-esm/dice/terms/fate.d.mts +9 -2
  432. package/src/foundry/client-esm/dice/terms/function.d.mts +18 -18
  433. package/src/foundry/client-esm/dice/terms/numeric.d.mts +3 -5
  434. package/src/foundry/client-esm/dice/terms/operator.d.mts +2 -2
  435. package/src/foundry/client-esm/dice/terms/parenthetical.d.mts +9 -10
  436. package/src/foundry/client-esm/dice/terms/pool.d.mts +25 -31
  437. package/src/foundry/client-esm/dice/terms/string.d.mts +4 -4
  438. package/src/foundry/client-esm/dice/terms/term.d.mts +18 -4
  439. package/src/foundry/client-esm/dice/twister.d.mts +3 -3
  440. package/src/foundry/client-esm/helpers/_module.d.mts +2 -2
  441. package/src/foundry/client-esm/helpers/_types.d.mts +12 -46
  442. package/src/foundry/client-esm/helpers/compendium-art.d.mts +56 -4
  443. package/src/foundry/common/abstract/_types.d.mts +60 -54
  444. package/src/foundry/common/abstract/backend.d.mts +51 -45
  445. package/src/foundry/common/abstract/data.d.mts +265 -236
  446. package/src/foundry/common/abstract/document.d.mts +1449 -464
  447. package/src/foundry/common/abstract/embedded-collection-delta.d.mts +1 -1
  448. package/src/foundry/common/abstract/embedded-collection.d.mts +37 -7
  449. package/src/foundry/common/abstract/module.d.mts +3 -2
  450. package/src/foundry/common/abstract/singleton-collection.d.mts +1 -1
  451. package/src/foundry/common/abstract/socket.d.mts +1 -1
  452. package/src/foundry/common/abstract/type-data.d.mts +61 -55
  453. package/src/foundry/common/config.d.mts +11 -3
  454. package/src/foundry/common/constants.d.mts +261 -231
  455. package/src/foundry/common/data/data.d.mts +238 -102
  456. package/src/foundry/common/data/fields.d.mts +1334 -874
  457. package/src/foundry/common/data/module.d.mts +2 -2
  458. package/src/foundry/common/data/validation-failure.d.mts +12 -9
  459. package/src/foundry/common/documents/_module.d.mts +4 -2
  460. package/src/foundry/common/documents/_types.d.mts +22 -56
  461. package/src/foundry/common/documents/active-effect.d.mts +358 -194
  462. package/src/foundry/common/documents/actor-delta.d.mts +403 -73
  463. package/src/foundry/common/documents/actor.d.mts +359 -117
  464. package/src/foundry/common/documents/adventure.d.mts +312 -142
  465. package/src/foundry/common/documents/ambient-light.d.mts +296 -75
  466. package/src/foundry/common/documents/ambient-sound.d.mts +296 -109
  467. package/src/foundry/common/documents/card.d.mts +321 -187
  468. package/src/foundry/common/documents/cards.d.mts +353 -125
  469. package/src/foundry/common/documents/chat-message.d.mts +338 -167
  470. package/src/foundry/common/documents/combat.d.mts +358 -94
  471. package/src/foundry/common/documents/combatant.d.mts +323 -92
  472. package/src/foundry/common/documents/drawing.d.mts +327 -206
  473. package/src/foundry/common/documents/fog-exploration.d.mts +303 -69
  474. package/src/foundry/common/documents/folder.d.mts +307 -82
  475. package/src/foundry/common/documents/item.d.mts +377 -100
  476. package/src/foundry/common/documents/journal-entry-page.d.mts +327 -187
  477. package/src/foundry/common/documents/journal-entry.d.mts +345 -68
  478. package/src/foundry/common/documents/macro.d.mts +325 -139
  479. package/src/foundry/common/documents/measured-template.d.mts +328 -138
  480. package/src/foundry/common/documents/note.d.mts +312 -151
  481. package/src/foundry/common/documents/playlist-sound.d.mts +309 -102
  482. package/src/foundry/common/documents/playlist.d.mts +341 -131
  483. package/src/foundry/common/documents/region-behavior.d.mts +360 -0
  484. package/src/foundry/common/documents/region.d.mts +355 -0
  485. package/src/foundry/common/documents/roll-table.d.mts +320 -102
  486. package/src/foundry/common/documents/scene.d.mts +437 -350
  487. package/src/foundry/common/documents/setting.d.mts +285 -54
  488. package/src/foundry/common/documents/table-result.d.mts +326 -103
  489. package/src/foundry/common/documents/tile.d.mts +337 -172
  490. package/src/foundry/common/documents/token.d.mts +396 -447
  491. package/src/foundry/common/documents/user.d.mts +296 -173
  492. package/src/foundry/common/documents/wall.d.mts +303 -156
  493. package/src/foundry/common/grid/_module.d.mts +3 -3
  494. package/src/foundry/common/grid/base.d.mts +66 -49
  495. package/src/foundry/common/grid/gridless.d.mts +2 -2
  496. package/src/foundry/common/grid/hexagonal.d.mts +35 -28
  497. package/src/foundry/common/grid/square.d.mts +3 -3
  498. package/src/foundry/common/packages/base-module.d.mts +6 -24
  499. package/src/foundry/common/packages/base-package.d.mts +56 -31
  500. package/src/foundry/common/packages/base-system.d.mts +45 -63
  501. package/src/foundry/common/packages/base-world.d.mts +15 -61
  502. package/src/foundry/common/packages/module.d.mts +7 -7
  503. package/src/foundry/common/packages/sub-types.d.mts +4 -6
  504. package/src/foundry/common/primitives/array.d.mts +4 -4
  505. package/src/foundry/common/primitives/math.d.mts +7 -1
  506. package/src/foundry/common/primitives/number.d.mts +2 -2
  507. package/src/foundry/common/primitives/set.d.mts +17 -14
  508. package/src/foundry/common/primitives/string.d.mts +1 -1
  509. package/src/foundry/common/prosemirror/_module.d.mts +15 -15
  510. package/src/foundry/common/prosemirror/dirty-plugin.d.mts +1 -1
  511. package/src/foundry/common/prosemirror/dom-parser.d.mts +2 -1
  512. package/src/foundry/common/prosemirror/dropdown.d.mts +1 -1
  513. package/src/foundry/common/prosemirror/highlight-matches-plugin.d.mts +2 -2
  514. package/src/foundry/common/prosemirror/image-plugin.d.mts +1 -1
  515. package/src/foundry/common/prosemirror/menu.d.mts +3 -3
  516. package/src/foundry/common/prosemirror/paste-transformer.d.mts +1 -1
  517. package/src/foundry/common/prosemirror/plugin.d.mts +2 -2
  518. package/src/foundry/common/prosemirror/schema/index.d.mts +0 -1
  519. package/src/foundry/common/prosemirror/schema/lists.d.mts +2 -0
  520. package/src/foundry/common/prosemirror/util.d.mts +1 -1
  521. package/src/foundry/common/types.d.mts +3 -3
  522. package/src/foundry/common/utils/bitmask.d.mts +23 -11
  523. package/src/foundry/common/utils/collection.d.mts +61 -38
  524. package/src/foundry/common/utils/color.d.mts +20 -2
  525. package/src/foundry/common/utils/event-emitter.d.mts +32 -17
  526. package/src/foundry/common/utils/helpers.d.mts +36 -26
  527. package/src/foundry/common/utils/http.d.mts +2 -2
  528. package/src/foundry/common/utils/module.d.mts +2 -2
  529. package/src/foundry/common/utils/string-tree.d.mts +45 -39
  530. package/src/foundry/common/utils/word-tree.d.mts +10 -23
  531. package/src/foundry/index.d.mts +0 -1
  532. package/src/foundry/{clipper → public/scripts/clipper}/clipper.d.mts +58 -16
  533. package/src/foundry/public/scripts/index.d.mts +1 -0
  534. package/src/foundry/public/scripts/workers/image-compressor.d.mts +23 -0
  535. package/src/foundry/public/scripts/workers/index.d.mts +1 -0
  536. package/{index-lenient.d.mts → src/index-lenient.d.mts} +2 -0
  537. package/src/index.d.mts +6 -0
  538. package/src/tsconfig.json +15 -0
  539. package/src/types/augments/particles.d.mts +29 -0
  540. package/src/types/augments/pixi.d.mts +1024 -21
  541. package/src/types/augments/smooth.d.mts +31 -0
  542. package/src/types/augments/tinyMCE.d.mts +1 -1
  543. package/src/types/config.d.mts +18 -313
  544. package/src/types/documentConfiguration.d.mts +286 -542
  545. package/src/types/index.d.mts +1 -1
  546. package/src/types/lib.d.mts +12 -0
  547. package/src/types/workers/image-compressor.d.mts +176 -0
  548. package/src/utils/index.d.mts +1279 -0
  549. package/tsconfig.json +29 -0
  550. package/tsconfig.main.json +8 -0
  551. package/tsconfig.miscellaneous.json +16 -0
  552. package/index.d.mts +0 -5
  553. package/src/foundry/client/apps/placeables/light-config.d.mts +0 -100
  554. package/src/foundry/client/apps/placeables/sound-config.d.mts +0 -43
  555. package/src/foundry/common/documents/module.d.mts +0 -35
  556. package/src/foundry/common/primitives/regex.d.mts +0 -12
  557. package/src/types/helperTypes.d.mts +0 -583
  558. package/src/types/utils.d.mts +0 -539
  559. /package/src/foundry/{clipper → public/scripts/clipper}/index.d.mts +0 -0
@@ -1,47 +1,76 @@
1
1
  import type {
2
- ConfiguredDocuments,
2
+ ConfigurationFailure,
3
+ ConfiguredDocumentClass,
4
+ ConfiguredDocumentInstance,
3
5
  ConfiguredMetadata,
4
- DefaultDocuments,
5
- ConstructorData,
6
+ CreateData,
6
7
  } from "../../../types/documentConfiguration.d.mts";
7
8
  import type {
8
- DatabaseOperationsFor,
9
9
  GetKey,
10
10
  InterfaceToObject,
11
11
  MakeConform,
12
12
  MustConform,
13
13
  ToMethod,
14
- } from "../../../types/helperTypes.mts";
15
- import type {
16
14
  AnyObject,
17
- DeepPartial,
18
15
  EmptyObject,
19
16
  InexactPartial,
20
17
  RemoveIndexSignatures,
21
- } from "../../../types/utils.mts";
22
- import type { documents } from "../../client-esm/client.d.mts";
18
+ FixedInstanceType,
19
+ NullishProps,
20
+ AllKeysOf,
21
+ DiscriminatedUnion,
22
+ SimpleMerge,
23
+ PickValue,
24
+ Identity,
25
+ Brand,
26
+ AnyMutableObject,
27
+ MaybePromise,
28
+ } from "#utils";
23
29
  import type * as CONST from "../constants.mts";
24
- import type { DataField, EmbeddedCollectionField, EmbeddedDocumentField } from "../data/fields.d.mts";
25
- import type { fields } from "../data/module.mts";
30
+ import type {
31
+ DataSchema,
32
+ DataField,
33
+ DocumentStatsField,
34
+ EmbeddedCollectionField,
35
+ EmbeddedDocumentField,
36
+ SchemaField,
37
+ TypeDataField,
38
+ } from "../data/fields.d.mts";
26
39
  import type { LogCompatibilityWarningOptions } from "../utils/logging.mts";
27
40
  import type {
41
+ DatabaseAction,
28
42
  DatabaseCreateOperation,
29
43
  DatabaseDeleteOperation,
30
44
  DatabaseGetOperation,
31
45
  DatabaseUpdateOperation,
46
+ DocumentSocketRequest,
32
47
  } from "./_types.d.mts";
33
48
  import type DataModel from "./data.mts";
49
+ import type DocumentSocketResponse from "./socket.d.mts";
50
+ import type EmbeddedCollection from "./embedded-collection.d.mts";
34
51
 
35
52
  export default Document;
36
53
 
37
- declare const __DocumentBrand: unique symbol;
38
-
39
- declare const __Schema: unique symbol;
40
- declare const __Parent: unique symbol;
41
-
42
54
  type _ClassMustBeAssignableToInternal = MustConform<typeof Document, Document.Internal.Constructor>;
43
55
  type _InstanceMustBeAssignableToInternal = MustConform<Document.Any, Document.Internal.Instance.Any>;
44
56
 
57
+ // Note(LukeAbby): Properties from `Schema` technically derive from `DataModel`. This means that if
58
+ // `name?: string` etc. were to be put in `Document` directly they'd actually override the schema.
59
+ // Therefore this workaround is used to force `DataModel` to override the properties.
60
+ declare const _InternalDocument: (new (...args: any[]) => {
61
+ // TODO: removing undefined breaks everything, but should be valid to do, investigate
62
+ name?: string | null | undefined;
63
+
64
+ // `{}` is used so that `{}` and the actual shape of `system` are merged.
65
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
66
+ system?: {} | undefined;
67
+ _stats?: DocumentStatsField.InitializedData | undefined;
68
+
69
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
70
+ flags?: {} | undefined;
71
+ }) &
72
+ typeof DataModel;
73
+
45
74
  /**
46
75
  * An extension of the base DataModel which defines a Document.
47
76
  * Documents are special in that they are persisted to the database and referenced by _id.
@@ -50,29 +79,26 @@ declare abstract class Document<
50
79
  DocumentName extends Document.Type,
51
80
  Schema extends DataSchema,
52
81
  Parent extends Document.Any | null = null,
53
- > extends DataModel<Schema, Parent, InterfaceToObject<Document.ConstructionContext<Parent>>> {
54
- static [__DocumentBrand]: never;
55
-
56
- [__Schema]: Schema;
57
- [__Parent]: Parent;
58
-
82
+ > extends _InternalDocument<Schema, Parent, InterfaceToObject<Document.ConstructionContext<Parent>>> {
59
83
  /**
60
84
  * @param data - Initial data provided to construct the Document
61
85
  * @param context - Construction context options
62
86
  */
63
- constructor(data?: fields.SchemaField.InnerConstructorType<Schema>, context?: Document.ConstructionContext<Parent>);
87
+ // Note: The constructor has been replaced with `never` in `Document` itself because it never makes
88
+ // sense to try to construct `new Document(...)` directly. Not only is it an abstract class but
89
+ // also it varies based upon the `Schema`. While this could be supported it also simplifies
90
+ // typechecking and helps stymy circularities.
91
+ constructor(...args: never);
64
92
 
65
93
  override parent: Parent;
66
94
 
67
- protected override _configure(options?: {
68
- pack?: string | null | undefined;
69
- parentCollection?: string | null | undefined;
70
- }): void;
95
+ // options: not null (destructured)
96
+ protected override _configure(options?: Document.ConfigureOptions): void;
71
97
 
72
98
  /**
73
99
  * An immutable reverse-reference to the name of the collection that this Document exists in on its parent, if any.
74
100
  */
75
- readonly parentCollection: string | null;
101
+ readonly parentCollection: Document.MetadataFor<DocumentName>["collection"] | null;
76
102
 
77
103
  /**
78
104
  * An immutable reference to a containing Compendium collection to which this Document belongs.
@@ -87,9 +113,10 @@ declare abstract class Document<
87
113
  /**
88
114
  * Ensure that all Document classes share the same schema of their base declaration.
89
115
  */
90
- static get schema(): foundry.data.fields.SchemaField.Any;
116
+ static get schema(): SchemaField.Any;
91
117
 
92
- protected _initialize(options?: any): void;
118
+ // options: not null (parameter default only)
119
+ protected _initialize(options?: Document.InitializeOptions): void;
93
120
 
94
121
  /**
95
122
  * A mapping of singleton embedded Documents which exist in this model.
@@ -120,7 +147,7 @@ declare abstract class Document<
120
147
  * }
121
148
  * ```
122
149
  */
123
- static metadata: Readonly<Document.Metadata.Any>;
150
+ static metadata: Document.Metadata.Any;
124
151
 
125
152
  /**
126
153
  * The database backend used to execute operations and handle results
@@ -130,8 +157,6 @@ declare abstract class Document<
130
157
  /**
131
158
  * Return a reference to the implemented subclass of this base document type.
132
159
  */
133
- // Referencing the concrete class the config is not possible because accessors cannot be generic and there is not
134
- // static polymorphic this type
135
160
  static get implementation(): Document.AnyConstructor;
136
161
 
137
162
  /**
@@ -147,7 +172,7 @@ declare abstract class Document<
147
172
  /**
148
173
  * The named collection to which this Document belongs.
149
174
  */
150
- get collectionName(): Document.Internal.SimpleMetadata<DocumentName>["collection"];
175
+ get collectionName(): Document.MetadataFor<DocumentName>["collection"];
151
176
 
152
177
  /**
153
178
  * The canonical name of this Document type, for example "Actor".
@@ -161,23 +186,25 @@ declare abstract class Document<
161
186
 
162
187
  /**
163
188
  * The allowed types which may exist for this Document class
164
- * @remarks Document.TYPES is overly generic so subclasses don't cause problems
165
189
  */
166
190
  static get TYPES(): string[];
167
191
 
168
192
  /**
169
193
  * Does this Document support additional subtypes?
170
194
  */
171
- static get hasTypeData(): boolean;
195
+ static get hasTypeData(): undefined | true;
172
196
 
173
197
  /**
174
198
  * The Embedded Document hierarchy for this Document.
175
199
  */
176
- static get hierarchy(): Record<string, EmbeddedCollectionField<any, any> | EmbeddedDocumentField<any>>;
200
+ static get hierarchy(): Record<string, EmbeddedCollectionField.Any | EmbeddedDocumentField.Any>;
177
201
 
178
202
  /**
179
203
  * Identify the collection in a parent Document that this Document exists belongs to, if any.
180
204
  * @param parentCollection - An explicitly provided parent collection name.
205
+ * @remarks If passed a value for `parentCollection`, simply returns that value
206
+ *
207
+ * Foundry marked `@internal`
181
208
  */
182
209
  _getParentCollection(parentCollection?: string): string | null;
183
210
 
@@ -201,17 +228,18 @@ declare abstract class Document<
201
228
  * @param user - The User being tested
202
229
  * @returns Does the User have a sufficient role to create?
203
230
  */
204
- static canUserCreate(user: foundry.documents.BaseUser): boolean;
231
+ static canUserCreate(user: User.Implementation): boolean;
205
232
 
206
233
  /**
207
- * Get the explicit permission level that a specific User has over this Document, a value in CONST.DOCUMENT_OWNERSHIP_LEVELS.
234
+ * Get the explicit permission level that a specific User has over this Document, a value in {@link CONST.DOCUMENT_OWNERSHIP_LEVELS | `CONST.DOCUMENT_OWNERSHIP_LEVELS`}.
208
235
  * This method returns the value recorded in Document ownership, regardless of the User's role.
209
236
  * To test whether a user has a certain capability over the document, testUserPermission should be used.
210
- * @param user - The User being tested
211
- * (default: `game.user`)
237
+ * @param user - The User being tested (default: `game.user`)
212
238
  * @returns A numeric permission level from CONST.DOCUMENT_OWNERSHIP_LEVELS or null
239
+ *
240
+ * @privateRemarks Making this just `User.Implementation` causes circularities
213
241
  */
214
- getUserLevel(user?: foundry.documents.BaseUser): CONST.DOCUMENT_OWNERSHIP_LEVELS | null;
242
+ getUserLevel(user?: User.Internal.Implementation | null): CONST.DOCUMENT_OWNERSHIP_LEVELS | null;
215
243
 
216
244
  /**
217
245
  * Test whether a certain User has a requested permission level (or greater) over the Document
@@ -219,28 +247,31 @@ declare abstract class Document<
219
247
  * @param permission - The permission level from DOCUMENT_PERMISSION_LEVELS to test
220
248
  * @param options - Additional options involved in the permission test
221
249
  * @returns Does the user have this permission level over the Document?
250
+ *
251
+ * @privateRemarks Making this just `User.Implementation` causes circularities
222
252
  */
253
+ // options: not null (destructured)
223
254
  testUserPermission(
224
- user: foundry.documents.BaseUser,
225
- permission: keyof typeof CONST.DOCUMENT_OWNERSHIP_LEVELS | CONST.DOCUMENT_OWNERSHIP_LEVELS,
226
- options?: InexactPartial<{
227
- /**
228
- * Require the exact permission level requested?
229
- * @defaultValue `false`
230
- */
231
- exact: boolean;
232
- }>,
255
+ user: User.Internal.Implementation,
256
+ permission: Document.ActionPermission,
257
+ options?: Document.TestUserPermissionOptions,
233
258
  ): boolean;
234
259
 
235
260
  /**
236
261
  * Test whether a given User has permission to perform some action on this Document
237
262
  * @param user - The User attempting modification
238
263
  * @param action - The attempted action
239
- * @param data - Data involved in the attempted action
240
- * (default: `{}`)
264
+ * @param data - Data involved in the attempted action (default: `{}`)
241
265
  * @returns Does the User have permission?
266
+ *
267
+ * @privateRemarks Making this just `User.Implementation` causes circularities
242
268
  */
243
- canUserModify(user: foundry.documents.BaseUser, action: "create" | "update" | "delete", data?: object): boolean;
269
+ // data: not null (parameter default only)
270
+ canUserModify<Action extends "create" | "update" | "delete">(
271
+ user: User.Internal.Implementation,
272
+ action: Action,
273
+ data?: Document.CanUserModifyData<Schema, Action>,
274
+ ): boolean;
244
275
 
245
276
  /**
246
277
  * Clone a document, creating a new document by combining current data with provided overrides.
@@ -249,40 +280,22 @@ declare abstract class Document<
249
280
  * @param context - Additional context options passed to the create method
250
281
  * @returns The cloned Document instance
251
282
  */
252
- override clone<Save extends boolean = false>(
253
- data?: fields.SchemaField.AssignmentType<Schema, EmptyObject>,
254
- context?: InexactPartial<
255
- {
256
- /**
257
- * Save the clone to the World database?
258
- * @defaultValue `false`
259
- */
260
- save: Save;
261
-
262
- /**
263
- * Keep the same ID of the original document
264
- * @defaultValue `false`
265
- */
266
- keepId: boolean;
267
-
268
- /**
269
- * Track the clone source
270
- * @defaultValue `false`
271
- */
272
- addSource: boolean;
273
- } & Document.ConstructionContext<this["parent"]>
274
- >, // FIXME(LukeAbby): Adding Document.Stored to the return causes a recursive type error in Scene
283
+ // data: not null (property access), context: not null (destructured)
284
+ override clone<Save extends boolean | null | undefined = false>(
285
+ data?: SchemaField.UpdateData<Schema>,
286
+ context?: Document.CloneContext<Save>,
275
287
  ): Save extends true ? Promise<this> : this;
276
288
 
277
289
  /**
278
290
  * For Documents which include game system data, migrate the system data object to conform to its latest data model.
279
291
  * The data model is defined by the template.json specification included by the game system.
280
292
  * @returns The migrated system data object
293
+ * @throws If this document type either doesn't have subtypes or it does but the one on this document is a DataModel
281
294
  */
282
295
  migrateSystemData(): object;
283
296
 
284
- override toObject(source: true): this["_source"];
285
- override toObject(source?: boolean): ReturnType<this["schema"]["toObject"]>;
297
+ /** @remarks `Document#toObject` calls `this.constructor.shimData()` on the data before returning */
298
+ override toObject(source?: boolean | null): SchemaField.SourceData<Schema>;
286
299
 
287
300
  /**
288
301
  * Create multiple Documents using provided input data.
@@ -318,14 +331,12 @@ declare abstract class Document<
318
331
  * const data = [{name: "Compendium Actor", type: "character", img: "path/to/profile.jpg"}];
319
332
  * const created = await Actor.createDocuments(data, {pack: "mymodule.mypack"});
320
333
  * ```
334
+ *
335
+ * @remarks If a document is skipped by a hook or `_preCreate` then that element is skipped in the
336
+ * return type. This means that you receive only documents that were actually created.
321
337
  */
322
- static createDocuments<T extends Document.AnyConstructor, Temporary extends boolean | undefined>(
323
- this: T,
324
- data: Array<Document.ConstructorDataFor<T>>,
325
- operation?: InexactPartial<Omit<DatabaseOperationsFor<T["metadata"]["name"], "create">, "data">> & {
326
- temporary?: Temporary;
327
- },
328
- ): Promise<Document.ToStoredIf<T, Temporary>[] | undefined>;
338
+ // Note: This uses `never` because it's unsound to try to do `Document.createDocuments` directly.
339
+ static createDocuments(data: never, operation?: never): Promise<Document.Any[]>;
329
340
 
330
341
  /**
331
342
  * Update multiple Document instances using provided differential data.
@@ -361,12 +372,12 @@ declare abstract class Document<
361
372
  * const actor = await pack.getDocument(documentId);
362
373
  * const updated = await Actor.updateDocuments([{_id: actor.id, name: "New Name"}], {pack: "mymodule.mypack"});
363
374
  * ```
375
+ *
376
+ * @remarks If a document is skipped by a hook or `_preCreate` then that element is skipped in the
377
+ * return type. This means that you receive only documents that were actually updated.
364
378
  */
365
- static updateDocuments<T extends Document.AnyConstructor>(
366
- this: T,
367
- updates?: Array<DeepPartial<Document.UpdateDataFor<T>>>,
368
- operation?: InexactPartial<Omit<DatabaseOperationsFor<InstanceType<T>["documentName"], "update">, "updates">>,
369
- ): Promise<Document.ToConfiguredInstance<T>[]>;
379
+ // Note: This uses `never` because it's unsound to try to do `Document.updateDocuments`
380
+ static updateDocuments(updates: never, operation?: never): Promise<Document.Any[]>;
370
381
 
371
382
  /**
372
383
  * Delete one or multiple existing Documents using an array of provided ids.
@@ -404,16 +415,16 @@ declare abstract class Document<
404
415
  * const actor = await pack.getDocument(documentId);
405
416
  * const deleted = await Actor.deleteDocuments([actor.id], {pack: "mymodule.mypack"});
406
417
  * ```
418
+ *
419
+ * @remarks If a document is skipped by a hook or `_preDelete` then that element is skipped in the
420
+ * return type. This means that you receive only documents that were actually deleted.
407
421
  */
408
- static deleteDocuments<T extends Document.AnyConstructor>(
409
- this: T,
410
- ids?: string[],
411
- operation?: InexactPartial<Omit<DatabaseOperationsFor<InstanceType<T>["documentName"], "delete">, "ids">>,
412
- ): Promise<Document.ToConfiguredInstance<T>[]>;
422
+ // Note: This uses `never` because it's unsound to try to pass the operation for `Document.deleteDocument`
423
+ static deleteDocuments(ids?: readonly string[], operation?: never): Promise<Document.Any[]>;
413
424
 
414
425
  /**
415
426
  * Create a new Document using provided input data, saving it to the database.
416
- * @see {@link Document.createDocuments}
427
+ * @see {@link Document.createDocuments | `Document.createDocuments`}
417
428
  * @param data - Initial data used to create this Document, or a Document instance to persist.
418
429
  * @param operation - Parameters of the creation operation
419
430
  * (default: `{}`)
@@ -438,53 +449,56 @@ declare abstract class Document<
438
449
  * const created = await Item.create(data, {pack: "mymodule.mypack"});
439
450
  * ```
440
451
  *
441
- * @remarks If no document has actually been created, the returned {@link Promise} resolves to `undefined`.
452
+ * @remarks If the document creation is skipped by a hook or `_preCreate` then `undefined` is
453
+ * returned.
442
454
  */
443
- static create<T extends Document.AnyConstructor, Temporary extends boolean | undefined>(
444
- this: T,
445
- data: Document.ConstructorDataFor<T> | Document.ConstructorDataFor<T>[],
446
- operation?: InexactPartial<Omit<DatabaseOperationsFor<T["metadata"]["name"], "create">, "data">> & {
447
- temporary?: Temporary;
448
- },
449
- ): Promise<Document.ToStoredIf<T, Temporary> | undefined>;
455
+ // Note: This uses `never` because it's unsound to try to call `Document.create` directly.
456
+ // TODO: This can take an array of data and return an array of documents, in addition to its current typing
457
+ static create(data: never, operation?: never): Promise<Document.Any | undefined>;
450
458
 
451
459
  /**
452
460
  * Update this Document using incremental data, saving it to the database.
453
- * @see {@link Document.updateDocuments}
461
+ * @see {@link Document.updateDocuments | `Document.updateDocuments`}
454
462
  * @param data - Differential update data which modifies the existing values of this document data
455
463
  * (default: `{}`)
456
464
  * @param operation - Parameters of the update operation
457
465
  * (default: `{}`)
458
466
  * @returns The updated Document instance
459
467
  *
460
- * @remarks If no document has actually been updated, the returned {@link Promise} resolves to `undefined`.
468
+ * @remarks If the document update is skipped by a hook or `_preUpdate` then `undefined` is
469
+ * returned.
461
470
  */
462
- update(
463
- // TODO: Determine if this is Partial, DeepPartial, or InexactPartial.
464
- data?: Partial<Document.ConstructorDataForSchema<Schema>>,
465
- operation?: InexactPartial<Omit<DatabaseOperationsFor<DocumentName, "update">, "updates">>,
466
- ): Promise<this | undefined>;
471
+ // Note: This uses `never` because it's unsound to try to call `Document#update` directly.
472
+ update(data: never, operation: never): Promise<this | undefined>;
467
473
 
468
474
  /**
469
475
  * Delete this Document, removing it from the database.
470
- * @see {@link Document.deleteDocuments}
476
+ * @see {@link Document.deleteDocuments | `Document.deleteDocuments`}
471
477
  * @param operation - Parameters of the deletion operation
472
478
  * (default: `{}`)
473
479
  * @returns The deleted Document instance
474
480
  *
475
- * @remarks If no document has actually been deleted, the returned {@link Promise} resolves to `undefined`.
481
+ * @remarks If the document deletion is skipped by a hook or `_preUpdate` then `undefined` is
482
+ * returned.
476
483
  */
477
- delete(
478
- operation?: InexactPartial<Omit<DatabaseOperationsFor<DocumentName, "delete">, "ids">>,
479
- ): Promise<this | undefined>;
484
+ // Note: This uses `never` because it's unsound to try to call `Document#delete` directly.
485
+ delete(operation: never): Promise<this | undefined>;
480
486
 
481
487
  /**
482
488
  * Get a World-level Document of this type by its id.
483
489
  * @param documentId - The Document ID
484
- * @param options - Additional options which customize the request
490
+ * @param operation - Additional options which customize the request
485
491
  * @returns The retrieved Document, or null
492
+ *
493
+ * @remarks If the Document is in a compendium (i.e `operation.pack` is provided), returns the index
494
+ * entry (or `null`), instead of the Document.
495
+ *
496
+ * {@link FogExploration.get | `FogExploration.get`} can possibly forward args and return to/from
497
+ * {@link FogExploration.load | `FogExploration.load`}, which accounts for the `Promise<>` part
498
+ * of the return; All other documents return `SomeDoc.Implementation | null`
486
499
  */
487
- static get(documentId: string, options?: InexactPartial<DatabaseGetOperation>): Document.Any | null;
500
+ // TODO: Type for possible index entry return
501
+ static get(documentId: string, operation?: Document.Database.GetOptions): MaybePromise<Document.Any | null>;
488
502
 
489
503
  /**
490
504
  * A compatibility method that returns the appropriate name of an embedded collection within this Document.
@@ -503,7 +517,7 @@ declare abstract class Document<
503
517
  * // returns "items"
504
518
  * ```
505
519
  */
506
- static getCollectionName(name: string): string | null;
520
+ static getCollectionName(name: never): string | null;
507
521
 
508
522
  /**
509
523
  * Obtain a reference to the Array of source data within the data object for a certain embedded Document name
@@ -511,10 +525,8 @@ declare abstract class Document<
511
525
  * @returns The Collection instance of embedded Documents of the requested type
512
526
  * @remarks Usually returns some form of DocumentCollection, but not always (e.g. Token["actors"])
513
527
  */
514
- // TODO: After regions are defined, change first parameter to `extends foundry.CONST.EMBEDDED_DOCUMENT_TYPES`
515
- getEmbeddedCollection<
516
- EmbeddedName extends Exclude<foundry.CONST.EMBEDDED_DOCUMENT_TYPES, "Region" | "RegionBehavior">,
517
- >(embeddedName: EmbeddedName): Collection<Document.ConfiguredInstanceForName<EmbeddedName>>;
528
+ // Note: This uses `never` because it's unsound to try to call `Document#getEmbeddedCollection` directly.
529
+ getEmbeddedCollection(embeddedName: never): unknown;
518
530
 
519
531
  /**
520
532
  * Get an embedded document by its id from a named collection in the parent document.
@@ -524,26 +536,16 @@ declare abstract class Document<
524
536
  * @returns The retrieved embedded Document instance, or undefined
525
537
  * @throws If the embedded collection does not exist, or if strict is true and the Embedded Document could not be found.
526
538
  */
539
+ // Note: This uses `never` because it's unsound to try to call `Document#getEmbeddedDocument` directly.
527
540
  getEmbeddedDocument(
528
- embeddedName: string,
541
+ embeddedName: never,
529
542
  id: string,
530
- options: InexactPartial<{
531
- /**
532
- * Throw an Error if the requested id does not exist. See Collection#get
533
- * @defaultValue `false`
534
- */
535
- strict: boolean;
536
- /**
537
- * Allow retrieving an invalid Embedded Document.
538
- * @defaultValue `false`
539
- */
540
- invalid: boolean;
541
- }>,
542
- ): Document.AnyChild<this> | undefined;
543
+ options: Document.GetEmbeddedDocumentOptions,
544
+ ): Document.Any | undefined;
543
545
 
544
546
  /**
545
547
  * Create multiple embedded Document instances within this parent Document using provided input data.
546
- * @see {@link Document.createDocuments}
548
+ * @see {@link Document.createDocuments | `Document.createDocuments`}
547
549
  * @param embeddedName - The name of the embedded Document type
548
550
  * @param data - An array of data objects used to create multiple documents
549
551
  * (default: `[]`)
@@ -551,24 +553,18 @@ declare abstract class Document<
551
553
  * (default: `{}`)
552
554
  * @returns An array of created Document instances
553
555
  */
554
- // TODO: After regions are defined, change first parameter to `extends foundry.CONST.EMBEDDED_DOCUMENT_TYPES`
555
- // TODO: I think we could do a better job on all the embedded methods of limiting the types here based on the
556
- // allowed embedded types of the parent (vs. allowing any document to create embedded
557
- // documents of any type)
558
- createEmbeddedDocuments<
559
- EmbeddedName extends foundry.CONST.EMBEDDED_DOCUMENT_TYPES,
560
- Temporary extends boolean | undefined,
561
- >(
562
- embeddedName: EmbeddedName,
563
- data?: Array<Document.ConstructorDataForName<Extract<EmbeddedName, Document.Type>>>,
564
- operation?: InexactPartial<DatabaseOperationsFor<Extract<EmbeddedName, Document.Type>, "create">> & {
565
- temporary?: Temporary;
566
- },
567
- ): Promise<Array<Document.ConfiguredInstanceForName<Extract<EmbeddedName, Document.Type>>> | undefined>;
556
+ // Note: This uses `never` because it's unsound to try to call `Document#createEmbeddedDocuments` directly.
557
+ // Note(LukeAbby): Returns `unknown` instead of `Promise<Array<Document.AnyStored> | undefined>` to stymy errors.
558
+ createEmbeddedDocuments(
559
+ embeddedName: never,
560
+ // Note: Not optional because `createEmbeddedDocuments("Actor")` does effectively nothing.
561
+ data: never,
562
+ operation?: never,
563
+ ): unknown;
568
564
 
569
565
  /**
570
566
  * Update multiple embedded Document instances within a parent Document using provided differential data.
571
- * @see {@link Document.updateDocuments}
567
+ * @see {@link Document.updateDocuments | `Document.updateDocuments`}
572
568
  * @param embeddedName - The name of the embedded Document type
573
569
  * @param updates - An array of differential data objects, each used to update a single Document
574
570
  * (default: `[]`)
@@ -576,37 +572,34 @@ declare abstract class Document<
576
572
  * (default: `{}`)
577
573
  * @returns An array of updated Document instances
578
574
  */
579
- // TODO: After regions are defined, change first parameter to `extends foundry.CONST.EMBEDDED_DOCUMENT_TYPES`
580
- updateEmbeddedDocuments<EmbeddedName extends foundry.CONST.EMBEDDED_DOCUMENT_TYPES>(
581
- embeddedName: EmbeddedName,
582
- updates?: Array<AnyObject>,
583
- context?: Document.ModificationContext<this["parent"]>,
584
- ): Promise<Array<Document.Stored<Document.ConfiguredInstanceForName<Extract<EmbeddedName, Document.Type>>>>>;
575
+ // Note: This uses `never` because it's unsound to try to call `Document#updateEmbeddedDocuments` directly.
576
+ // Note(LukeAbby): Returns `unknown` instead of `Promise<Array<Document.AnyStored> | undefined>` to stymy errors.
577
+ updateEmbeddedDocuments(
578
+ embeddedName: never,
579
+ // Note: Not optional because `updateEmbeddedDocuments("Actor")` does effectively nothing.
580
+ updates: never,
581
+ context?: never,
582
+ ): unknown;
585
583
 
586
584
  /**
587
585
  * Delete multiple embedded Document instances within a parent Document using provided string ids.
588
- * @see {@link Document.deleteDocuments}
586
+ * @see {@link Document.deleteDocuments | `Document.deleteDocuments`}
589
587
  * @param embeddedName - The name of the embedded Document type
590
588
  * @param ids - An array of string ids for each Document to be deleted
591
589
  * @param operation - Parameters of the database deletion workflow
592
590
  * (default: `{}`)
593
591
  * @returns An array of deleted Document instances
594
592
  */
595
- // TODO: After regions are defined, change first parameter to `extends foundry.CONST.EMBEDDED_DOCUMENT_TYPES`
596
- deleteEmbeddedDocuments<
597
- EmbeddedName extends Exclude<foundry.CONST.EMBEDDED_DOCUMENT_TYPES, "Region" | "RegionBehavior">,
598
- >(
599
- embeddedName: EmbeddedName,
600
- ids: Array<string>,
601
- operation?: DatabaseOperationsFor<DocumentName, "delete">,
602
- ): Promise<Array<Document.Stored<Document.ConfiguredInstanceForName<EmbeddedName>>>>;
593
+ // Note: This uses `never` because it's unsound to try to call `Document#deleteEmbeddedDocuments` directly.
594
+ // Note(LukeAbby): Returns `unknown` instead of `Promise<Array<Document.AnyStored> | undefined>` to stymy errors.
595
+ deleteEmbeddedDocuments(embeddedName: never, ids: Array<string>, operation?: never): unknown;
603
596
 
604
597
  /**
605
598
  * Iterate over all embedded Documents that are hierarchical children of this Document.
606
599
  * @param _parentPath - A parent field path already traversed
607
600
  * @remarks Not called within Foundry's client-side code, likely exists for server documents
608
601
  */
609
- traverseEmbeddedDocuments(_parentPath?: string): Generator<[string, Document.Any]>;
602
+ traverseEmbeddedDocuments(_parentPath?: string): Generator<[string, Document.AnyChild<this>]>;
610
603
 
611
604
  /**
612
605
  * Get the value of a "flag" for this document
@@ -616,10 +609,7 @@ declare abstract class Document<
616
609
  * @param key - The flag key
617
610
  * @returns The flag value
618
611
  */
619
- getFlag<
620
- S extends Document.FlagKeyOf<Document.ConfiguredFlagsForName<DocumentName>>,
621
- K extends Document.FlagKeyOf<Document.FlagGetKey<Document.ConfiguredFlagsForName<DocumentName>, S>>,
622
- >(scope: S, key: K): Document.GetFlag<DocumentName, S, K>;
612
+ getFlag(scope: never, key: never): unknown;
623
613
 
624
614
  /**
625
615
  * Assign a "flag" to this document.
@@ -639,11 +629,7 @@ declare abstract class Document<
639
629
  * @param value - The flag value
640
630
  * @returns A Promise resolving to the updated document
641
631
  */
642
- setFlag<
643
- S extends Document.FlagKeyOf<Document.ConfiguredFlagsForName<DocumentName>>,
644
- K extends Document.FlagKeyOf<Document.FlagGetKey<Document.ConfiguredFlagsForName<DocumentName>, S>>,
645
- V extends Document.GetFlag<DocumentName, S, K>,
646
- >(scope: S, key: K, value: V): Promise<this>;
632
+ setFlag(scope: never, key: never, value: never): Promise<this>;
647
633
 
648
634
  /**
649
635
  * Remove a flag assigned to the document
@@ -651,22 +637,18 @@ declare abstract class Document<
651
637
  * @param key - The flag key
652
638
  * @returns The updated document instance
653
639
  */
654
- unsetFlag(scope: string, key: string): Promise<this>;
640
+ unsetFlag(scope: never, key: never): Promise<this>;
655
641
 
656
642
  /**
657
643
  * Pre-process a creation operation for a single Document instance.
658
644
  * Pre-operation events only occur for the client which requested the operation.
659
- * Modifications to the pending Document instance must be performed using {@link Document#updateSource}.
645
+ * Modifications to the pending Document instance must be performed using {@link Document.updateSource | `Document#updateSource`}.
660
646
  * @param data - The initial data object provided to the document creation request
661
647
  * @param options - Additional options which modify the creation request
662
648
  * @param user - The User requesting the document creation
663
649
  * @returns Return false to exclude this Document from the creation operation
664
650
  */
665
- protected _preCreate(
666
- data: fields.SchemaField.AssignmentType<Schema>,
667
- options: Document.PreCreateOptions<DocumentName>,
668
- user: foundry.documents.BaseUser,
669
- ): Promise<boolean | void>;
651
+ protected _preCreate(data: never, options: never, user: User.Internal.Implementation): Promise<boolean | void>;
670
652
 
671
653
  /**
672
654
  * Post-process a creation operation for a single Document instance.
@@ -675,48 +657,44 @@ declare abstract class Document<
675
657
  * @param options - Additional options which modify the creation request
676
658
  * @param userId - The id of the User requesting the document update
677
659
  */
678
- protected _onCreate(
679
- data: fields.SchemaField.InnerAssignmentType<Schema>,
680
- options: Document.OnCreateOptions<DocumentName>,
681
- userId: string,
682
- ): void;
660
+ protected _onCreate(data: never, options: never, userId: string): MaybePromise<void>;
683
661
 
684
662
  /**
685
663
  * Pre-process a creation operation, potentially altering its instructions or input data. Pre-operation events only
686
664
  * occur for the client which requested the operation.
687
665
  *
688
- * This batch-wise workflow occurs after individual {@link Document#_preCreate} workflows and provides a final
666
+ * This batch-wise workflow occurs after individual {@link Document._preCreate | `Document#_preCreate`} workflows and provides a final
689
667
  * pre-flight check before a database operation occurs.
690
668
  *
691
669
  * Modifications to pending documents must mutate the documents array or alter individual document instances using
692
- * {@link Document#updateSource}.
670
+ * {@link Document.updateSource | `Document#updateSource`}.
693
671
  * @param documents - Pending document instances ot be created
694
672
  * @param operation - Parameters of the database creation operation
695
673
  * @param user - The User requesting the creation operation
696
674
  * @returns Return false to cancel the creation operation entirely
697
675
  */
698
- protected static _preCreateOperation<T extends Document.AnyConstructor>(
699
- this: T,
700
- documents: Document.ToConfiguredInstance<T>[],
701
- operation: DatabaseOperationsFor<T["metadata"]["name"], "create">,
702
- user: foundry.documents.BaseUser,
676
+ // Note: This uses `never` because it's unsound to try to do `Document._preCreateOperation` directly.
677
+ protected static _preCreateOperation(
678
+ documents: never[],
679
+ operation: never,
680
+ user: User.Internal.Implementation,
703
681
  ): Promise<boolean | void>;
704
682
 
705
683
  /**
706
684
  * Post-process a creation operation, reacting to database changes which have occurred. Post-operation events occur
707
685
  * for all connected clients.
708
686
  *
709
- * This batch-wise workflow occurs after individual {@link Document#_onCreate} workflows.
687
+ * This batch-wise workflow occurs after individual {@link Document._onCreate | `Document#_onCreate`} workflows.
710
688
  *
711
689
  * @param documents - The Document instances which were created
712
690
  * @param operation - Parameters of the database creation operation
713
691
  * @param user - The User who performed the creation operation
714
692
  */
715
- protected static _onCreateOperation<T extends Document.AnyConstructor>(
716
- this: T,
717
- documents: InstanceType<Document.ConfiguredClass<T>>[],
718
- operation: DatabaseOperationsFor<T["metadata"]["name"], "create">,
719
- user: foundry.documents.BaseUser,
693
+ // Note: This uses `never` because it's unsound to try to do `Document._onCreateOperation` directly.
694
+ protected static _onCreateOperation(
695
+ documents: never,
696
+ operation: never,
697
+ user: User.Internal.Implementation,
720
698
  ): Promise<void>;
721
699
 
722
700
  /**
@@ -727,11 +705,7 @@ declare abstract class Document<
727
705
  * @param user - The User requesting the document update
728
706
  * @returns A return value of false indicates the update operation should be cancelled
729
707
  */
730
- protected _preUpdate(
731
- changed: fields.SchemaField.AssignmentType<Schema>,
732
- options: Document.PreUpdateOptions<DocumentName>,
733
- user: foundry.documents.BaseUser,
734
- ): Promise<boolean | void>;
708
+ protected _preUpdate(changed: never, options: never, user: User.Internal.Implementation): Promise<boolean | void>;
735
709
 
736
710
  /**
737
711
  * Perform follow-up operations after a Document of this type is updated.
@@ -740,49 +714,45 @@ declare abstract class Document<
740
714
  * @param options - Additional options which modify the update request
741
715
  * @param userId - The id of the User requesting the document update
742
716
  */
743
- protected _onUpdate(
744
- changed: fields.SchemaField.InnerAssignmentType<Schema>,
745
- options: Document.OnUpdateOptions<DocumentName>,
746
- userId: string,
747
- ): void;
717
+ protected _onUpdate(changed: never, options: never, userId: string): MaybePromise<void>;
748
718
 
749
719
  /**
750
720
  * Pre-process an update operation, potentially altering its instructions or input data. Pre-operation events only
751
721
  * occur for the client which requested the operation.
752
722
  *
753
- * This batch-wise workflow occurs after individual {@link Document#_preUpdate} workflows and provides a final
723
+ * This batch-wise workflow occurs after individual {@link Document._preUpdate | `Document#_preUpdate`} workflows and provides a final
754
724
  * pre-flight check before a database operation occurs.
755
725
  *
756
726
  * Modifications to the requested updates are performed by mutating the data array of the operation.
757
- * {@link Document#updateSource}.
727
+ * {@link Document.updateSource | `Document#updateSource`}.
758
728
  *
759
729
  * @param documents - Document instances to be updated
760
730
  * @param operation - Parameters of the database update operation
761
731
  * @param user - The User requesting the update operation
762
732
  * @returns Return false to cancel the update operation entirely
763
733
  */
764
- protected static _preUpdateOperation<T extends Document.AnyConstructor>(
765
- this: T,
766
- documents: InstanceType<Document.ConfiguredClass<T>>[],
767
- operation: DatabaseOperationsFor<InstanceType<T>["documentName"], "update">,
768
- user: foundry.documents.BaseUser,
734
+ // Note: This uses `never` because it's unsound to try to do `Document._preUpdateOperation` directly.
735
+ protected static _preUpdateOperation(
736
+ documents: never,
737
+ operation: never,
738
+ user: User.Internal.Implementation,
769
739
  ): Promise<boolean | void>;
770
740
 
771
741
  /**
772
742
  * Post-process an update operation, reacting to database changes which have occurred. Post-operation events occur
773
743
  * for all connected clients.
774
744
  *
775
- * This batch-wise workflow occurs after individual {@link Document#_onUpdate} workflows.
745
+ * This batch-wise workflow occurs after individual {@link Document._onUpdate | `Document#_onUpdate`} workflows.
776
746
  *
777
747
  * @param documents - The Document instances which were updated
778
748
  * @param operation - Parameters of the database update operation
779
749
  * @param user - The User who performed the update operation
780
750
  */
781
- protected static _onUpdateOperation<T extends Document.AnyConstructor>(
782
- this: T,
783
- documents: InstanceType<Document.ConfiguredClass<T>>[],
784
- operation: DatabaseOperationsFor<InstanceType<T>["documentName"], "update">,
785
- user: foundry.documents.BaseUser,
751
+ // Note: This uses `never` because it's unsound to try to do `Document._onUpdateOperation` directly.
752
+ protected static _onUpdateOperation(
753
+ documents: never,
754
+ operation: never,
755
+ user: User.Internal.Implementation,
786
756
  ): Promise<void>;
787
757
 
788
758
  /**
@@ -792,10 +762,7 @@ declare abstract class Document<
792
762
  * @param user - The User requesting the document deletion
793
763
  * @returns A return value of false indicates the delete operation should be cancelled
794
764
  */
795
- protected _preDelete(
796
- options: Document.PreDeleteOptions<DocumentName>,
797
- user: foundry.documents.BaseUser,
798
- ): Promise<boolean | void>;
765
+ protected _preDelete(options: never, user: User.Internal.Implementation): Promise<boolean | void>;
799
766
 
800
767
  /**
801
768
  * Perform follow-up operations after a Document of this type is deleted.
@@ -803,17 +770,17 @@ declare abstract class Document<
803
770
  * @param options - Additional options which modify the deletion request
804
771
  * @param userId - The id of the User requesting the document update
805
772
  */
806
- protected _onDelete(options: Document.OnDeleteOptions<DocumentName>, userId: string): void;
773
+ protected _onDelete(options: never, userId: string): MaybePromise<void>;
807
774
 
808
775
  /**
809
776
  * Pre-process a deletion operation, potentially altering its instructions or input data. Pre-operation events only
810
777
  * occur for the client which requested the operation.
811
778
  *
812
- * This batch-wise workflow occurs after individual {@link Document#_preDelete} workflows and provides a final
779
+ * This batch-wise workflow occurs after individual {@link Document._preDelete | `Document#_preDelete`} workflows and provides a final
813
780
  * pre-flight check before a database operation occurs.
814
781
  *
815
782
  * Modifications to the requested deletions are performed by mutating the operation object.
816
- * {@link Document#updateSource}.
783
+ * {@link Document.updateSource | `Document#updateSource`}.
817
784
  *
818
785
  * @param documents - Document instances to be deleted
819
786
  * @param operation - Parameters of the database update operation
@@ -821,50 +788,64 @@ declare abstract class Document<
821
788
  * @returns Return false to cancel the deletion operation entirely
822
789
  * @internal
823
790
  */
824
- protected static _preDeleteOperation<T extends Document.AnyConstructor>(
825
- this: T,
826
- documents: Array<Document.ToConfiguredInstance<T>>,
827
- operation: DatabaseOperationsFor<InstanceType<T>["documentName"], "delete">,
828
- user: foundry.documents.BaseUser,
791
+ // Note: This uses `never` because it's unsound to try to do `Document._preDeleteOperation` directly.
792
+ protected static _preDeleteOperation(
793
+ documents: never,
794
+ operation: never,
795
+ user: User.Internal.Implementation,
829
796
  ): Promise<unknown>;
830
797
 
831
798
  /**
832
799
  * Post-process a deletion operation, reacting to database changes which have occurred. Post-operation events occur
833
800
  * for all connected clients.
834
801
  *
835
- * This batch-wise workflow occurs after individual {@link Document#_onDelete} workflows.
802
+ * This batch-wise workflow occurs after individual {@link Document._onDelete | `Document#_onDelete`} workflows.
836
803
  *
837
804
  * @param documents - The Document instances which were deleted
838
805
  * @param operation - Parameters of the database deletion operation
839
806
  * @param user - The User who performed the deletion operation
840
807
  */
841
- protected static _onDeleteOperation<T extends Document.AnyConstructor>(
842
- this: T,
843
- documents: Array<Document.ToConfiguredInstance<T>>,
844
- operation: DatabaseOperationsFor<InstanceType<T>["documentName"], "delete">,
845
- user: foundry.documents.BaseUser,
808
+ // Note: This uses `never` because it's unsound to try to do `Document._onDeleteOperation` directly.
809
+ protected static _onDeleteOperation(
810
+ documents: never,
811
+ operation: never,
812
+ user: User.Internal.Implementation,
846
813
  ): Promise<unknown>;
847
814
 
848
815
  /**
849
- * Configure whether V10 Document Model migration warnings should be logged for this class.
816
+ * @deprecated since v10, no specified end
817
+ * @remarks "You are accessing the "data" field of which was deprecated in v10 and replaced with "system".
818
+ * Continued usage of pre-v10 ".data" paths is no longer supported"
819
+ *
820
+ * @throws An error with the above deprecation warning, if this Document's schema has a `system` field
850
821
  */
851
- static LOG_V10_COMPATIBILITY_WARNINGS: boolean;
822
+ get data(): never;
852
823
 
853
824
  /**
854
825
  * @deprecated since v11, will be removed in v13
855
826
  * @remarks "You are accessing `Document.hasSystemData` which is deprecated. Please use `Document.hasTypeData` instead."
856
827
  */
857
- static get hasSystemData(): boolean;
828
+ static get hasSystemData(): undefined | true;
858
829
 
859
830
  /**
860
831
  * A reusable helper for adding migration shims.
861
832
  */
862
- protected static _addDataFieldShims(data: object, shims: object, options: object): unknown;
863
-
833
+ // options: not null (parameter default only in _addDataFieldShim)
834
+ protected static _addDataFieldShims(
835
+ data: AnyMutableObject,
836
+ shims: Record<string, string>,
837
+ options?: Document.DataFieldShimOptions,
838
+ ): void;
864
839
  /**
865
840
  * A reusable helper for adding a migration shim
866
841
  */
867
- protected static _addDataFieldShim(data: object, oldKey: string, newKey: string, options?: object): unknown;
842
+ // options: not null (parameter default only)
843
+ protected static _addDataFieldShim(
844
+ data: AnyMutableObject,
845
+ oldKey: string,
846
+ newKey: string,
847
+ options?: Document.DataFieldShimOptions,
848
+ ): void;
868
849
 
869
850
  /**
870
851
  * Define a simple migration from one field name to another.
@@ -873,15 +854,16 @@ declare abstract class Document<
873
854
  * @param oldKey - The old field name
874
855
  * @param newKey - The new field name
875
856
  * @param apply - An application function, otherwise the old value is applied
876
- * @internal
857
+ * @remarks Foundry marked `@internal`
877
858
  */
878
859
  protected static _addDataFieldMigration(
879
- data: object,
860
+ data: AnyMutableObject,
880
861
  oldKey: string,
881
862
  newKey: string,
882
- apply?: (data: object) => any,
863
+ apply?: (data: AnyMutableObject) => unknown,
883
864
  ): unknown;
884
865
 
866
+ // options: not null (destructured where forwarded)
885
867
  protected static _logDataFieldMigration(
886
868
  oldKey: string,
887
869
  newKey: string,
@@ -890,81 +872,58 @@ declare abstract class Document<
890
872
 
891
873
  /**
892
874
  * @deprecated since v12, will be removed in v14
893
- * @remarks `"The Document._onCreateDocuments static method is deprecated in favor of Document._onCreateOperation"`
875
+ * @remarks "The `Document._onCreateDocuments` static method is deprecated in favor of {@link Document._onCreateOperation | `Document._onCreateOperation`}"
894
876
  */
895
- protected static _onCreateDocuments<T extends Document.AnyConstructor>(
896
- this: T,
897
- documents: Array<Document.ToConfiguredInstance<T>>,
877
+ // Note: This uses `never` because it's unsound to try to do `Document._onCreateDocuments` directly.
878
+ protected static _onCreateDocuments(
879
+ documents: never,
898
880
  context: Document.ModificationContext<Document.Any | null>,
899
881
  ): Promise<void>;
900
882
 
901
883
  /**
902
884
  * @deprecated since v12, will be removed in v14
903
- * @remarks `"The Document._onUpdateDocuments static method is deprecated in favor of Document._onUpdateOperation"`
885
+ * @remarks "The `Document._onUpdateDocuments` static method is deprecated in favor of {@link Document._onUpdateOperation | `Document._onUpdateOperation`}"
904
886
  */
905
- protected static _onUpdateDocuments<T extends Document.AnyConstructor>(
906
- this: T,
907
- documents: Array<Document.ToConfiguredInstance<T>>,
887
+ // Note: This uses `never` because it's unsound to try to do `Document._onUpdateDocuments` directly.
888
+ protected static _onUpdateDocuments(
889
+ documents: never,
908
890
  context: Document.ModificationContext<Document.Any | null>,
909
891
  ): Promise<unknown>;
910
892
 
911
893
  /**
912
894
  * @deprecated since v12, will be removed in v14
913
- * @remarks `"The Document._onDeleteDocuments static method is deprecated in favor of Document._onDeleteOperation"`
895
+ * @remarks "The `Document._onDeleteDocuments` static method is deprecated in favor of {@link Document._onDeleteOperation | `Document._onDeleteOperation`}"
914
896
  */
915
- protected static _onDeleteDocuments<T extends Document.AnyConstructor>(
916
- this: T,
917
- documents: Array<Document.ToConfiguredInstance<T>>,
897
+ // Note: This uses `never` because it's unsound to try to do `Document._onDeleteDocuments` directly.
898
+ protected static _onDeleteDocuments(
899
+ documents: never,
918
900
  context: Document.ModificationContext<Document.Any | null>,
919
901
  ): Promise<unknown>;
920
- }
921
902
 
922
- declare abstract class AnyDocument extends Document<any, any, any> {
923
- constructor(arg0: never, ...args: never[]);
903
+ static " fvtt_types_internal_document_name_static": Document.Type;
924
904
 
925
- // Note(LukeAbby): Specifically adding the `__DocumentBrand` should be redundant but in practice it seems to help tsc more efficiently deduce that it's actually inheriting from `Document`.
926
- // This is odd but probably is because it bails from looking up the parent class properties at times or something.
927
- static [__DocumentBrand]: never;
905
+ " fvtt_types_internal_document_name": DocumentName;
906
+ " fvtt_types_internal_document_schema": Schema;
907
+ " fvtt_types_internal_document_parent": Parent;
908
+ }
928
909
 
929
- flags?: unknown;
910
+ // An empty schema is the most accurate because index signatures are stripped.
911
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
912
+ declare abstract class AnyDocument extends Document<Document.Type, {}, Document.Any | null> {
913
+ constructor(...args: never);
930
914
 
931
- getFlag(scope: never, key: never): any;
915
+ // Note(LukeAbby): This uses `object` instead of `AnyObject` to avoid more thorough evaluation of
916
+ // the involved types which can cause a loop.
917
+ _source: object;
932
918
  }
933
919
 
934
- // Note(LukeAbby): The point of this class is to show up in intellisense.
935
- // When something fails to be configured it should be replaced with `typeof ConfigurationFailure & typeof Item` or whatever the relevant class is.
936
- // This helps to minimize the number of errors that appears in a repo with broken configuration as they can be very misleading and confusing.
937
- declare abstract class ConfigurationFailure extends AnyDocument {}
938
-
939
920
  declare namespace Document {
940
- /** Any Document, except for Settings */
941
- type Any = AnyDocument;
921
+ interface Any extends AnyDocument {}
922
+ interface AnyStored extends Stored<Any> {}
923
+ interface AnyValid extends AnyDocument {}
924
+ interface AnyConstructor extends Identity<typeof AnyDocument> {}
942
925
 
943
- type Type =
944
- | "ActiveEffect"
945
- | "ActorDelta"
946
- | "Actor"
947
- | "Adventure"
948
- | "Card"
949
- | "Cards"
950
- | "ChatMessage"
951
- | "Combat"
952
- | "Combatant"
953
- | "FogExploration"
954
- | "Folder"
955
- | "Item"
956
- | "JournalEntryPage"
957
- | "JournalEntry"
958
- | "Macro"
959
- | "PlaylistSound"
960
- | "Playlist"
961
- | "RollTable"
962
- | "Scene"
963
- | "Setting"
964
- | "TableResult"
965
- | "User"
966
- // All placeables also have a corresponding document class.
967
- | PlaceableType;
926
+ type Type = CONST.ALL_DOCUMENT_TYPES;
968
927
 
969
928
  type PlaceableType =
970
929
  | "AmbientLight"
@@ -972,12 +931,89 @@ declare namespace Document {
972
931
  | "Drawing"
973
932
  | "MeasuredTemplate"
974
933
  | "Note"
934
+ | "Region"
975
935
  | "Tile"
976
936
  | "Token"
977
937
  | "Wall";
978
938
 
939
+ type PrimaryType = CONST.PRIMARY_DOCUMENT_TYPES;
940
+ type EmbeddedType = CONST.EMBEDDED_DOCUMENT_TYPES;
941
+ type WorldType = CONST.WORLD_DOCUMENT_TYPES;
942
+ type CompendiumType = CONST.COMPENDIUM_DOCUMENT_TYPES;
943
+
944
+ type WithSubTypes = WithSystem | "Folder" | "Macro" | "TableResult";
945
+
946
+ type WithSystem =
947
+ | "ActiveEffect"
948
+ | "ActorDelta"
949
+ | "Actor"
950
+ | "Card"
951
+ | "Cards"
952
+ | "ChatMessage"
953
+ | "Combat"
954
+ | "Combatant"
955
+ | "Item"
956
+ | "JournalEntryPage"
957
+ | "RegionBehavior";
958
+
959
+ // The `data` parameter has a default of `{}`. This means it's optional in that scenario.
960
+ // Note(LukeAbby): Update when `ParameterWithDefaults` is added.
961
+ // `CreateData` also should be updated to allow `undefined` directly.
962
+ type ConstructorParameters<CreateData extends object | undefined, Parent extends Document.Any | null> = [
963
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
964
+ {},
965
+ ] extends [CreateData]
966
+ ? [data?: CreateData, context?: Document.ConstructionContext<Parent>]
967
+ : [data: CreateData, context?: Document.ConstructionContext<Parent>];
968
+
979
969
  type CoreTypesForName<Name extends Type> = string &
980
- GetKey<Document.Internal.SimpleMetadata<Name>, "coreTypes", ["base"]>[number];
970
+ GetKey<Document.MetadataFor<Name>, "coreTypes", [CONST.BASE_DOCUMENT_TYPE]>[number];
971
+
972
+ type ConfiguredSubTypesOf<Name extends Type> = Name extends "ActorDelta"
973
+ ? ConfiguredSubTypesOf<"Actor">
974
+ : string & (keyof GetKey<DataModelConfig, Name, unknown> | keyof GetKey<SourceConfig, Name, unknown>);
975
+
976
+ type SubTypesOf<Name extends Type> = Name extends "ActorDelta"
977
+ ? SubTypesOf<"Actor">
978
+ :
979
+ | Document.CoreTypesForName<Name>
980
+ | ConfiguredSubTypesOf<Name>
981
+ | (Document.MetadataFor<Name> extends { readonly hasTypeData: true } ? Document.ModuleSubtype : never);
982
+
983
+ type ModuleSubtype = Brand<`${string}.${string}`, "Document.ModuleSubtype">;
984
+
985
+ type OfType<Name extends WithSubTypes, SubType extends SubTypesOf<Name>> =
986
+ | (Name extends "ActiveEffect" ? ActiveEffect.OfType<SubType & ActiveEffect.SubType> : never)
987
+ | (Name extends "ActorDelta" ? ActorDelta.OfType<SubType & ActorDelta.SubType> : never)
988
+ | (Name extends "Actor" ? Actor.OfType<SubType & Actor.SubType> : never)
989
+ | (Name extends "Card" ? Card.OfType<SubType & Card.SubType> : never)
990
+ | (Name extends "Cards" ? Cards.OfType<SubType & Cards.SubType> : never)
991
+ | (Name extends "ChatMessage" ? ChatMessage.OfType<SubType & ChatMessage.SubType> : never)
992
+ | (Name extends "Combat" ? Combat.OfType<SubType & Combat.SubType> : never)
993
+ | (Name extends "Combatant" ? Combatant.OfType<SubType & Combatant.SubType> : never)
994
+ | (Name extends "Folder" ? Folder.OfType<SubType & Folder.SubType> : never)
995
+ | (Name extends "Item" ? Item.OfType<SubType & Item.SubType> : never)
996
+ | (Name extends "JournalEntryPage" ? JournalEntryPage.OfType<SubType & JournalEntryPage.SubType> : never)
997
+ | (Name extends "Macro" ? Macro.OfType<SubType & Macro.SubType> : never)
998
+ | (Name extends "RegionBehavior" ? RegionBehavior.OfType<SubType & RegionBehavior.SubType> : never)
999
+ | (Name extends "TableResult" ? TableResult.OfType<SubType & TableResult.SubType> : never);
1000
+
1001
+ /**
1002
+ * With the existence of custom module subtypes a system can no longer rely on their configured types being the only ones.
1003
+ * A module can provide its own custom type though it is always of the form `${moduleName}.${subType}` so the `.` is a pretty
1004
+ * strong indicator.
1005
+ *
1006
+ * `UnknownSourceData` covers the case where it's configured without a data model.
1007
+ * See {@link UnknownSystem | `UnknownSystem`} for other possibilities.
1008
+ */
1009
+ interface UnknownSourceData extends AnyObject {
1010
+ type: ModuleSubtype;
1011
+ }
1012
+
1013
+ /**
1014
+ * With the existence of custom module subtypes a system can no longer rely on their configured types being the only ones.
1015
+ */
1016
+ type UnknownSystem = UnknownSourceData | TypeDataField.UnknownTypeDataModel | DataModel.UnknownDataModel;
981
1017
 
982
1018
  // TODO: Probably a way to auto-determine this
983
1019
  type SystemType =
@@ -989,170 +1025,324 @@ declare namespace Document {
989
1025
  | "Combat"
990
1026
  | "Combatant"
991
1027
  | "Item"
992
- | "JournalEntryPage";
1028
+ | "JournalEntryPage"
1029
+ | "RegionBehavior";
1030
+
1031
+ namespace Embedded {
1032
+ type CollectionNameFor<
1033
+ Embedded extends Document.Metadata.Embedded,
1034
+ CollectionName extends Document.Embedded.CollectionName<Embedded>,
1035
+ > = Extract<GetKey<Metadata.Embedded, CollectionName, CollectionName>, Document.Type>;
1036
+
1037
+ type DocumentFor<
1038
+ Embedded extends Document.Metadata.Embedded,
1039
+ CollectionName extends Document.Embedded.CollectionName<Embedded>,
1040
+ > = Document.ImplementationFor<CollectionNameFor<Embedded, CollectionName>>;
1041
+
1042
+ type CollectionFor<
1043
+ Parent extends Document.Any,
1044
+ Embedded extends Document.Metadata.Embedded,
1045
+ CollectionName extends Document.Embedded.CollectionName<Embedded>,
1046
+ > = EmbeddedCollection<DocumentFor<Embedded, CollectionName>, Parent>;
1047
+
1048
+ type CollectionName<Embedded extends Document.Metadata.Embedded> = {
1049
+ [K in keyof Embedded]: K extends Document.Type ? Extract<K | Embedded[K], string> : never;
1050
+ }[keyof Embedded];
1051
+ }
993
1052
 
994
- type EmbeddableNamesFor<ConcreteDocument extends Document.Internal.Instance.Any> = {
995
- [K in keyof ConfiguredDocuments]: IsParentOf<ConcreteDocument, InstanceType<ConfiguredDocuments[K]>> extends true
996
- ? K
997
- : never;
998
- };
1053
+ /**
1054
+ * @internal
1055
+ */
1056
+ interface _WorldCollectionMap {
1057
+ Actor: Actors.Configured;
1058
+ Cards: CardStacks;
1059
+ Combat: CombatEncounters;
1060
+ FogExploration: FogExplorations;
1061
+ Folder: Folders;
1062
+ Item: Items;
1063
+ JournalEntry: Journal;
1064
+ Macro: Macros;
1065
+ ChatMessage: Messages;
1066
+ Playlist: Playlists;
1067
+ Scene: Scenes;
1068
+ Setting: WorldSettings;
1069
+ RollTable: RollTables;
1070
+ User: Users;
1071
+ }
1072
+
1073
+ type WorldCollectionFor<Name extends Document.WorldType> = _WorldCollectionMap[Name];
1074
+
1075
+ // Note(LukeAbby): Will be updated with the CONFIG revamp.
1076
+ type ConfiguredCollectionClass<Name extends Document.Type> = CONFIG extends {
1077
+ readonly [K in Name]: {
1078
+ readonly documentClass?: infer DocumentClass;
1079
+ };
1080
+ }
1081
+ ? DocumentClass
1082
+ : never;
1083
+
1084
+ // Note(LukeAbby): Will be updated with the CONFIG revamp.
1085
+ type ConfiguredCollection<Name extends Document.Type> = FixedInstanceType<ConfiguredCollectionClass<Name>>;
999
1086
 
1000
1087
  type IsParentOf<
1001
1088
  ParentDocument extends Document.Internal.Instance.Any,
1002
1089
  ChildDocument extends Document.Internal.Instance.Any,
1003
1090
  > = ParentDocument extends Internal.ParentFor<ChildDocument> ? true : false;
1004
1091
 
1092
+ type SocketRequest<Action extends DatabaseAction> = DocumentSocketRequest<Action>;
1093
+ type SocketResponse<Action extends DatabaseAction> = DocumentSocketResponse<Action>;
1094
+
1005
1095
  // Documented at https://gist.github.com/LukeAbby/c7420b053d881db4a4d4496b95995c98
1006
1096
  namespace Internal {
1007
- type SimpleMetadata<Name extends Document.Type> = ConfiguredMetadata<Document.Any>[Name];
1008
-
1009
- type Constructor = (abstract new (arg0: never, ...args: never[]) => Instance.Any) & {
1010
- [__DocumentBrand]: never;
1097
+ type Constructor = (abstract new (...args: never) => Instance.Any) & {
1098
+ " fvtt_types_internal_document_name_static": Document.Type;
1011
1099
  };
1012
1100
 
1013
- interface Instance<Schema extends DataSchema, Parent extends Document.Internal.Instance.Any | null> {
1014
- [__Schema]: Schema;
1015
- [__Parent]: Parent;
1101
+ interface Instance<
1102
+ DocumentName extends Document.Type,
1103
+ Schema extends DataSchema,
1104
+ Parent extends Document.Internal.Instance.Any | null,
1105
+ > {
1106
+ " fvtt_types_internal_document_name": DocumentName;
1107
+ " fvtt_types_internal_document_schema": Schema;
1108
+ " fvtt_types_internal_document_parent": Parent;
1016
1109
  }
1017
1110
 
1018
- type SchemaFor<ConcreteInstance extends Instance.Any> = ConcreteInstance[typeof __Schema];
1111
+ type DocumentNameFor<ConcreteInstance extends Instance.Any> =
1112
+ ConcreteInstance[" fvtt_types_internal_document_name"];
1019
1113
 
1020
- type ParentFor<ConcreteInstance extends Instance.Any> = ConcreteInstance[typeof __Parent];
1114
+ type SchemaFor<ConcreteInstance extends Instance.Any> = ConcreteInstance[" fvtt_types_internal_document_schema"];
1115
+
1116
+ type ParentFor<ConcreteInstance extends Instance.Any> = ConcreteInstance[" fvtt_types_internal_document_parent"];
1021
1117
 
1022
1118
  namespace Instance {
1023
- type Any = Instance<any, any>;
1119
+ interface Any extends Instance<any, any, any> {}
1024
1120
 
1025
1121
  type Complete<T extends Any> = T extends Document.Any ? T : never;
1026
1122
  }
1123
+
1124
+ type OfType<Configured, Document extends Document.Any> = Configured extends { document: infer D }
1125
+ ? D extends Document
1126
+ ? D
1127
+ : FixedInstanceType<ConfigurationFailure[Document["documentName"]]>
1128
+ : Document;
1129
+
1130
+ type SystemMap<Name extends Document.WithSystem> = _SystemMap<
1131
+ Name,
1132
+ GetKey<DataModelConfig, Name>,
1133
+ GetKey<SourceConfig, Name>
1134
+ >;
1135
+
1136
+ type _SystemMap<Name extends Document.WithSystem, DataModel, SourceData> = {
1137
+ [SubType in SubTypesOf<Name>]: DataModel extends {
1138
+ [K in SubType]: abstract new (...args: infer _) => infer Model;
1139
+ }
1140
+ ? Model
1141
+ : SourceData extends {
1142
+ [K in SubType]: infer Source;
1143
+ }
1144
+ ? Source
1145
+ : SubType extends Document.ModuleSubtype
1146
+ ? // eslint-disable-next-line @typescript-eslint/no-empty-object-type
1147
+ {}
1148
+ : UnknownSystem;
1149
+ };
1150
+
1151
+ type SystemOfType<SystemMap extends Record<SubType, object>, SubType extends string> =
1152
+ | DiscriminatedUnion<SystemMap[SubType]>
1153
+ | (SubType extends ModuleSubtype ? UnknownSystem : never);
1027
1154
  }
1028
1155
 
1029
1156
  /** Any Document, that is a child of the given parent Document. */
1030
- type AnyChild<Parent extends Any | null> = Document<any, any, Parent>;
1157
+ // An empty schema is the most appropriate type due to removing index signatures.
1158
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
1159
+ type AnyChild<Parent extends Any | null> = Document<Document.Type, {}, Parent>;
1031
1160
 
1032
- type AnyConstructor = typeof AnyDocument;
1161
+ /**
1162
+ * @deprecated {@link Document.CreateDataFor | `Document.CreateDataFor`}
1163
+ */
1164
+ type ConstructorDataFor<T extends Document.Internal.Constructor> = SchemaField.CreateData<
1165
+ T extends { defineSchema: () => infer R extends DataSchema } ? R : never
1166
+ >;
1033
1167
 
1034
1168
  /**
1035
- * Returns the type of the constructor data for the given {@link foundry.abstract.Document}.
1169
+ * Returns the type of the constructor data for the given {@link foundry.abstract.Document | `foundry.abstract.Document`}.
1036
1170
  */
1037
- type ConstructorDataFor<T extends Document.Internal.Constructor> = ConstructorDataForSchema<
1171
+ type CreateDataFor<T extends Document.Internal.Constructor> = SchemaField.CreateData<
1038
1172
  T extends { defineSchema: () => infer R extends DataSchema } ? R : never
1039
1173
  >;
1040
1174
 
1041
- // TODO(LukeAbby): Actually make this distinguishable from `Document.ConstructorDataFor` and `Document.ConstructorDataForSchema`.
1042
- type UpdateDataFor<T extends Document.Internal.Constructor> = ConstructorDataForSchema<
1175
+ type UpdateDataFor<T extends Document.Internal.Constructor> = SchemaField.UpdateData<
1043
1176
  T extends { defineSchema: () => infer R extends DataSchema } ? R : never
1044
1177
  >;
1045
1178
 
1046
1179
  // These helper types exist to help break a loop
1047
- type ConstructorDataForName<T extends Document.Type> = ConstructorData[T];
1048
- type UpdateDataForName<T extends Document.Type> = ConstructorData[T];
1049
1180
 
1050
- type ConstructorDataForSchema<Schema extends DataSchema> =
1051
- foundry.data.fields.SchemaField.InnerAssignmentType<Schema>;
1181
+ type CreateDataForName<DocumentType extends Document.Type> =
1182
+ | (DocumentType extends "ActiveEffect" ? ActiveEffect.CreateData : never)
1183
+ | (DocumentType extends "ActorDelta" ? ActorDelta.CreateData : never)
1184
+ | (DocumentType extends "Actor" ? Actor.CreateData : never)
1185
+ | (DocumentType extends "Adventure" ? Adventure.CreateData : never)
1186
+ | (DocumentType extends "Card" ? Card.CreateData : never)
1187
+ | (DocumentType extends "Cards" ? Cards.CreateData : never)
1188
+ | (DocumentType extends "ChatMessage" ? ChatMessage.CreateData : never)
1189
+ | (DocumentType extends "Combat" ? Combat.CreateData : never)
1190
+ | (DocumentType extends "Combatant" ? Combatant.CreateData : never)
1191
+ | (DocumentType extends "FogExploration" ? FogExploration.CreateData : never)
1192
+ | (DocumentType extends "Folder" ? Folder.CreateData : never)
1193
+ | (DocumentType extends "Item" ? Item.CreateData : never)
1194
+ | (DocumentType extends "JournalEntryPage" ? JournalEntryPage.CreateData : never)
1195
+ | (DocumentType extends "JournalEntry" ? JournalEntry.CreateData : never)
1196
+ | (DocumentType extends "Macro" ? Macro.CreateData : never)
1197
+ | (DocumentType extends "PlaylistSound" ? PlaylistSound.CreateData : never)
1198
+ | (DocumentType extends "Playlist" ? Playlist.CreateData : never)
1199
+ | (DocumentType extends "RegionBehavior" ? RegionBehavior.CreateData : never)
1200
+ | (DocumentType extends "RollTable" ? RollTable.CreateData : never)
1201
+ | (DocumentType extends "Scene" ? Scene.CreateData : never)
1202
+ | (DocumentType extends "Setting" ? Setting.CreateData : never)
1203
+ | (DocumentType extends "TableResult" ? TableResult.CreateData : never)
1204
+ | (DocumentType extends "User" ? User.CreateData : never)
1205
+ | (DocumentType extends "AmbientLight" ? AmbientLightDocument.CreateData : never)
1206
+ | (DocumentType extends "AmbientSound" ? AmbientSoundDocument.CreateData : never)
1207
+ | (DocumentType extends "Drawing" ? DrawingDocument.CreateData : never)
1208
+ | (DocumentType extends "MeasuredTemplate" ? MeasuredTemplateDocument.CreateData : never)
1209
+ | (DocumentType extends "Note" ? NoteDocument.CreateData : never)
1210
+ | (DocumentType extends "Region" ? RegionDocument.CreateData : never)
1211
+ | (DocumentType extends "Tile" ? TileDocument.CreateData : never)
1212
+ | (DocumentType extends "Token" ? TokenDocument.CreateData : never)
1213
+ | (DocumentType extends "Wall" ? WallDocument.CreateData : never);
1214
+
1215
+ type UpdateDataForName<DocumentType extends Document.Type> =
1216
+ | (DocumentType extends "ActiveEffect" ? ActiveEffect.UpdateData : never)
1217
+ | (DocumentType extends "ActorDelta" ? ActorDelta.UpdateData : never)
1218
+ | (DocumentType extends "Actor" ? Actor.UpdateData : never)
1219
+ | (DocumentType extends "Adventure" ? Adventure.UpdateData : never)
1220
+ | (DocumentType extends "Card" ? Card.UpdateData : never)
1221
+ | (DocumentType extends "Cards" ? Cards.UpdateData : never)
1222
+ | (DocumentType extends "ChatMessage" ? ChatMessage.UpdateData : never)
1223
+ | (DocumentType extends "Combat" ? Combat.UpdateData : never)
1224
+ | (DocumentType extends "Combatant" ? Combatant.UpdateData : never)
1225
+ | (DocumentType extends "FogExploration" ? FogExploration.UpdateData : never)
1226
+ | (DocumentType extends "Folder" ? Folder.UpdateData : never)
1227
+ | (DocumentType extends "Item" ? Item.UpdateData : never)
1228
+ | (DocumentType extends "JournalEntryPage" ? JournalEntryPage.UpdateData : never)
1229
+ | (DocumentType extends "JournalEntry" ? JournalEntry.UpdateData : never)
1230
+ | (DocumentType extends "Macro" ? Macro.UpdateData : never)
1231
+ | (DocumentType extends "PlaylistSound" ? PlaylistSound.UpdateData : never)
1232
+ | (DocumentType extends "Playlist" ? Playlist.UpdateData : never)
1233
+ | (DocumentType extends "RegionBehavior" ? RegionBehavior.UpdateData : never)
1234
+ | (DocumentType extends "RollTable" ? RollTable.UpdateData : never)
1235
+ | (DocumentType extends "Scene" ? Scene.UpdateData : never)
1236
+ | (DocumentType extends "Setting" ? Setting.UpdateData : never)
1237
+ | (DocumentType extends "TableResult" ? TableResult.UpdateData : never)
1238
+ | (DocumentType extends "User" ? User.UpdateData : never)
1239
+ | (DocumentType extends "AmbientLight" ? AmbientLightDocument.UpdateData : never)
1240
+ | (DocumentType extends "AmbientSound" ? AmbientSoundDocument.UpdateData : never)
1241
+ | (DocumentType extends "Drawing" ? DrawingDocument.UpdateData : never)
1242
+ | (DocumentType extends "MeasuredTemplate" ? MeasuredTemplateDocument.UpdateData : never)
1243
+ | (DocumentType extends "Note" ? NoteDocument.UpdateData : never)
1244
+ | (DocumentType extends "Region" ? NoteDocument.UpdateData : never)
1245
+ | (DocumentType extends "Tile" ? TileDocument.UpdateData : never)
1246
+ | (DocumentType extends "Token" ? TokenDocument.UpdateData : never)
1247
+ | (DocumentType extends "Wall" ? WallDocument.UpdateData : never);
1248
+
1249
+ /**
1250
+ * @deprecated {@link SchemaField.CreateData | `SchemaField.CreateData`}
1251
+ */
1252
+ type ConstructorDataForSchema<Schema extends DataSchema> = SchemaField.CreateData<Schema>;
1052
1253
 
1053
1254
  type SystemConstructor = AnyConstructor & {
1054
1255
  metadata: { name: SystemType };
1055
1256
  };
1056
1257
 
1057
- // TODO(LukeAbby): Look into this. Inconsistent name, deprecate?
1058
- type ConfiguredClass<T extends { metadata: Metadata.Any }> = ConfiguredClassForName<T["metadata"]["name"]>;
1059
-
1060
- type ConfiguredClassForName<Name extends Type> = MakeConform<
1061
- ConfiguredDocuments[Name],
1062
- typeof ConfigurationFailure & DefaultDocuments[Name]
1258
+ type ToConfiguredClass<ConcreteDocument extends Document.Internal.Constructor> = ImplementationClassFor<
1259
+ NameFor<ConcreteDocument>
1063
1260
  >;
1064
1261
 
1065
- type SubTypesOf<T extends Type> =
1066
- ConfiguredInstanceForName<T> extends { type: infer Types } ? Types : typeof foundry.CONST.BASE_DOCUMENT_TYPE;
1067
-
1068
- // NOTE(LukeAbby): This type is less DRY than it could be to avoid undue complexity in such a critical helpeer.
1069
- // This has _many_ times been seen to cause loops so this type is written in an intentionally more paranoid way.
1070
- // The reason for the verbosity and repetition is to avoid eagerly evaluating any branches that might cause a loop.
1071
- type ToConfiguredClass<ConcreteDocument extends Document.Internal.Constructor> =
1072
- NameFor<ConcreteDocument> extends keyof DocumentClassConfig
1073
- ? MakeConform<
1074
- ConfiguredDocuments[NameFor<ConcreteDocument>],
1075
- typeof ConfigurationFailure & DefaultDocuments[NameFor<ConcreteDocument>]
1076
- >
1077
- : DefaultDocuments[NameFor<ConcreteDocument>];
1078
-
1079
- type ToConfiguredInstance<ConcreteDocument extends Document.Internal.Constructor> =
1080
- ConfiguredDocuments[NameFor<ConcreteDocument>] extends Document.AnyConstructor
1081
- ? _CheckConfiguredInstance<
1082
- NameFor<ConcreteDocument>,
1083
- InstanceType<ConfiguredDocuments[NameFor<ConcreteDocument>]>
1084
- >
1085
- : InstanceType<DefaultDocuments[NameFor<ConcreteDocument>]>;
1086
-
1087
- /**
1088
- * @internal
1089
- */
1090
- type _CheckConfiguredInstance<Name extends Document.Type, T> = T extends Document.Any
1091
- ? T
1092
- : ConfigurationFailure & DefaultDocuments[Name];
1262
+ type ToConfiguredInstance<ConcreteDocument extends Document.Internal.Constructor> = MakeConform<
1263
+ FixedInstanceType<ConfiguredDocumentClass[NameFor<ConcreteDocument>]>,
1264
+ Document.Any
1265
+ // TODO(LukeAbby): Look into if there's a way to do this without causing circular loops.
1266
+ // FixedInstanceType<ConfigurationFailure[Name]>
1267
+ >;
1093
1268
 
1094
- type ToConfiguredStored<D extends Document.Internal.Constructor> = Stored<ToConfiguredInstance<D>>;
1269
+ type ToConfiguredStored<D extends Document.AnyConstructor> = Stored<ToConfiguredInstance<D>>;
1095
1270
 
1096
- type Stored<D extends Document.Internal.Instance.Any> = D & {
1271
+ type Stored<D extends Document.Any> = D & {
1097
1272
  id: string;
1098
1273
  _id: string;
1099
1274
  _source: GetKey<D, "_source"> & { _id: string };
1100
1275
  };
1101
1276
 
1102
- type ToStoredIf<
1103
- D extends Document.Internal.Constructor,
1104
- Temporary extends boolean | undefined,
1105
- > = Temporary extends true ? ToConfiguredStored<D> : ToConfiguredInstance<D>;
1277
+ type Invalid<D extends Document.Any> = SimpleMerge<
1278
+ D,
1279
+ {
1280
+ id: string;
1281
+ _id: string;
1282
+ _source: object;
1283
+ system: object;
1284
+ }
1285
+ >;
1106
1286
 
1107
- type Temporary<D extends Document.Internal.Instance.Any> = D extends Stored<infer U> ? U : D;
1287
+ type ToStored<D extends Document.AnyConstructor> = Stored<FixedInstanceType<D>>;
1108
1288
 
1109
- type NameFor<ConcreteDocument extends Document.Internal.Constructor> = ConcreteDocument extends {
1110
- readonly metadata: { readonly name: infer Name extends Type };
1111
- }
1112
- ? Name
1113
- : never;
1289
+ type ToStoredIf<D extends Document.AnyConstructor, Temporary extends boolean | undefined> = Temporary extends true
1290
+ ? FixedInstanceType<D>
1291
+ : ToConfiguredStored<D>;
1114
1292
 
1115
- type ConfiguredInstanceForName<Name extends Type> = MakeConform<
1116
- InstanceType<ConfiguredDocuments[Name]>,
1117
- Document.Any
1118
- >;
1293
+ /** @deprecated {@link Document.TemporaryIf | `Document.TemporaryIf`} */
1294
+ type StoredIf<D extends Document.Any, Temporary extends boolean | undefined> = TemporaryIf<D, Temporary>;
1295
+
1296
+ type TemporaryIf<D extends Document.Any, Temporary extends boolean | undefined> = Temporary extends true
1297
+ ? D
1298
+ : Stored<D>;
1119
1299
 
1120
- type ConfiguredObjectClassForName<Name extends PlaceableType> = CONFIG[Name]["objectClass"];
1121
- type ConfiguredObjectInstanceForName<Name extends PlaceableType> = InstanceType<CONFIG[Name]["objectClass"]>;
1300
+ type Temporary<D extends Document.Any> = D extends Stored<infer U> ? U : D;
1301
+
1302
+ type NameFor<ConcreteDocument extends Document.Internal.Constructor> =
1303
+ ConcreteDocument[" fvtt_types_internal_document_name_static"];
1304
+
1305
+ type ImplementationFor<Name extends Type> = ConfiguredDocumentInstance[Name];
1306
+ type ImplementationClassFor<Name extends Type> = ConfiguredDocumentClass[Name];
1307
+
1308
+ type ObjectClassFor<Name extends PlaceableType> = CONFIG[Name]["objectClass"];
1309
+ type ObjectFor<Name extends PlaceableType> = FixedInstanceType<CONFIG[Name]["objectClass"]>;
1310
+
1311
+ /**
1312
+ * @deprecated {@link ObjectClassFor | `ObjectClassFor`}
1313
+ */
1314
+ type ConfiguredObjectClassForName<Name extends PlaceableType> = ObjectClassFor<Name>;
1315
+
1316
+ /**
1317
+ * @deprecated {@link ObjectFor | `ObjectFor`}
1318
+ */
1319
+ type ConfiguredObjectInstanceForName<Name extends PlaceableType> = ObjectFor<Name>;
1122
1320
 
1123
1321
  type ConfiguredDataForName<Name extends Type> = GetKey<DataConfig, Name, EmptyObject>;
1124
1322
 
1125
1323
  type ConfiguredSourceForName<Name extends Type> = GetKey<SourceConfig, Name, EmptyObject>;
1126
1324
 
1127
- type ConfiguredFlagsForName<Name extends Type> = GetKey<FlagConfig, Name, EmptyObject>;
1128
-
1129
- type ToObjectFalseType<T extends Document.Internal.Instance.Any> = T extends {
1130
- toObject: (source: false) => infer U;
1131
- }
1132
- ? U
1133
- : T;
1325
+ // The type `{}` is useful here because in an intersection it reduces down to nothing unlike `EmptyObject`.
1326
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
1327
+ type ConfiguredFlagsForName<Name extends Type> = GetKey<FlagConfig, Name, {}>;
1134
1328
 
1135
1329
  type SchemaFor<ConcreteDocument extends Internal.Instance.Any> =
1136
- ConcreteDocument extends Internal.Instance<infer Schema, any> ? Schema : never;
1330
+ ConcreteDocument extends Internal.Instance<infer _1, infer Schema, infer _2> ? Schema : never;
1137
1331
 
1138
- type MetadataFor<ConcreteDocument extends Document.Internal.Instance.Any> =
1139
- ConfiguredMetadata<ConcreteDocument>[ConcreteDocument extends {
1140
- readonly documentName: infer Name extends Document.Type;
1141
- }
1142
- ? Name
1143
- : never];
1332
+ type MetadataFor<Name extends Document.Type> = ConfiguredMetadata[Name];
1144
1333
 
1145
1334
  type CollectionRecord<Schema extends DataSchema> = {
1146
- [Key in keyof Schema]: Schema[Key] extends fields.EmbeddedCollectionField.Any ? Schema[Key] : never;
1335
+ [Key in keyof Schema]: Schema[Key] extends EmbeddedCollectionField.Any ? Schema[Key] : never;
1147
1336
  };
1148
1337
 
1149
1338
  type Flags<ConcreteDocument extends Internal.Instance.Any> = OptionsForSchema<SchemaFor<ConcreteDocument>>;
1150
1339
 
1151
- interface OptionsInFlags<Options extends DataFieldOptions.Any> {
1340
+ /** @internal */
1341
+ interface OptionsInFlags<Options extends DataField.Options.Any> {
1152
1342
  readonly flags?: DataField<Options, any>;
1153
1343
  }
1154
1344
 
1155
- // These types only exists to simplify solving the `Document` type. Using `Document.Flags<this>` means the constraint `this extends Document.Any` has to be proved.
1345
+ // These types only exists to simplify solving the `Document` type. Using `Document.Flags<this>` means the constraint `this extends Document.Any` has to be proved.
1156
1346
  // This is much more complex than proving the constraint for `Document.FlagsInternal<Schema>` that `Schema extends DataSchema`.
1157
1347
 
1158
1348
  // TODO: This needs to use the derived flags not just how they're initialized.
@@ -1175,7 +1365,7 @@ declare namespace Document {
1175
1365
  type FlagGetKey<T, K extends PropertyKey> = T extends unknown ? (K extends keyof T ? T[K] : never) : never;
1176
1366
 
1177
1367
  // Note(LukeAbby): It's at times been very important for `GetFlag` to be covariant over `ConcreteSchema`.
1178
- // If it isn't then issues arise where the `Document` type ends up becoming invaraint.
1368
+ // If it isn't then issues arise where the `Document` type ends up becoming invariant.
1179
1369
  // Currently it is actually contravariant over `ConcreteSchema` and this may cause issues (because of the usage of `keyof`).
1180
1370
  // Unfortunately it's not easy to avoid because the typical `GetKey` trick has issues between `never`, not defined at all, and `unknown` etc.
1181
1371
  type GetFlag<Name extends Document.Type, S extends string, K extends string> = FlagGetKey<
@@ -1183,30 +1373,66 @@ declare namespace Document {
1183
1373
  K
1184
1374
  >;
1185
1375
 
1186
- interface ConstructionContext<Parent extends Document.Any | null> {
1376
+ interface CoreFlags {
1377
+ core?: {
1378
+ sheetLock?: boolean;
1379
+ sheetClass?: string;
1380
+ };
1381
+ }
1382
+
1383
+ /** @internal */
1384
+ type _ConstructionContext<Parent extends Document.Any | null> = NullishProps<{
1187
1385
  /**
1188
1386
  * The parent Document of this one, if this one is embedded
1189
1387
  * @defaultValue `null`
1190
1388
  */
1191
- parent?: Parent | undefined;
1389
+ parent: Parent;
1192
1390
 
1193
1391
  /**
1194
1392
  * The compendium collection ID which contains this Document, if any
1195
1393
  * @defaultValue `null`
1196
1394
  */
1197
- pack?: string | null | undefined;
1395
+ pack: string;
1198
1396
 
1199
1397
  /**
1200
1398
  * Whether to validate initial data strictly?
1201
1399
  * @defaultValue `true`
1202
1400
  */
1203
- strict?: boolean | null | undefined;
1401
+ strict: boolean;
1204
1402
 
1205
1403
  /**
1206
- * An immutable reverse-reference to the name of the collection that thi8s Document exists in on its parent, if any.
1404
+ * An immutable reverse-reference to the name of the collection that this Document exists in on its parent, if any.
1405
+ * @privateRemarks Omitted from the typedef, inferred from usage in {@link Document._configure | `Document#_configure`}
1406
+ * (and included in the construction context rather than `ConfigureOptions` due to being passed to construction in
1407
+ * {@link foundry.abstract.EmbeddedCollection.createDocument | `EmbeddedCollection#createDocument`})
1207
1408
  */
1208
- parentCollection?: string | null | undefined;
1209
- }
1409
+ parentCollection: string;
1410
+ }>;
1411
+
1412
+ /**
1413
+ * Foundry does not include the properties from the DataModel construction context in `DocumentConstructionContext`,
1414
+ * but they're all still valid.
1415
+ *
1416
+ * `strict` is omitted from the DataModel interface so the Document interface's property
1417
+ * description takes precedence.
1418
+ */
1419
+ interface ConstructionContext<Parent extends Document.Any | null = Document.Any | null>
1420
+ extends Omit<DataModel._ConstructionContext, "strict">,
1421
+ _ConstructionContext<Parent> {}
1422
+
1423
+ /** `DataModel#constructor` pulls `parent` and `strict` out of the passed context before forwarding to `#_configure` */
1424
+ interface ConfigureOptions extends Omit<ConstructionContext, "parent" | "strict"> {}
1425
+
1426
+ /** `DataModel#constructor` pulls `parent` out of the passed context before forwarding to `#_initializeSource` */
1427
+ interface InitializeOptions extends Omit<ConstructionContext, "parent"> {}
1428
+
1429
+ /**
1430
+ * `DataModel#constructor` pulls `parent` out of the passed context before forwarding to `#_initializeSource`
1431
+ * @privateRemarks `Document` doesn't override `_initializeSource`, but at least one specific document does (Actor only, as of v12);
1432
+ * Without an override, this is handled by the `& ExtraConstructorOptions` in the `DataModel` signature, but with one,
1433
+ * a manually combined interface is needed.
1434
+ */
1435
+ interface InitializeSourceOptions extends DataModel.InitializeSourceOptions, Omit<ConstructionContext, "parent"> {}
1210
1436
 
1211
1437
  interface ModificationContext<Parent extends Document.Any | null> {
1212
1438
  /**
@@ -1292,102 +1518,756 @@ declare namespace Document {
1292
1518
  deleteAll?: boolean | undefined;
1293
1519
  }
1294
1520
 
1521
+ /** @internal */
1522
+ type _CloneContext<Save extends boolean | null | undefined = boolean | null | undefined> = NullishProps<{
1523
+ /**
1524
+ * Save the clone to the World database?
1525
+ * @defaultValue `false`
1526
+ */
1527
+ save: Save;
1528
+
1529
+ /**
1530
+ * Keep the same ID of the original document
1531
+ * @defaultValue `false`
1532
+ */
1533
+ keepId: boolean;
1534
+
1535
+ /**
1536
+ * Track the clone source
1537
+ * @defaultValue `false`
1538
+ */
1539
+ addSource: boolean;
1540
+ }>;
1541
+
1542
+ /**
1543
+ * @privateRemarks Since we've lost the ExtraConstructorOptions type param, we have to extend
1544
+ * the (parentless) construction context
1545
+ */
1546
+ interface CloneContext<Save extends boolean | null | undefined = boolean | null | undefined>
1547
+ extends _CloneContext<Save>,
1548
+ Omit<Document.ConstructionContext, "parent"> {}
1549
+
1295
1550
  type ModificationOptions = Omit<Document.ModificationContext<Document.Any | null>, "parent" | "pack">;
1296
1551
 
1552
+ /* eslint-disable @typescript-eslint/no-deprecated */
1553
+ /** @deprecated Use {@link Database.PreCreateOptions | `Database.PreCreateOptions`} */
1297
1554
  type PreCreateOptions<Name extends Type> = Omit<
1298
- DatabaseOperationsFor<Name, "create">,
1555
+ Document.Database.OperationOf<Name, "create">,
1299
1556
  "data" | "noHook" | "pack" | "parent"
1300
1557
  >;
1558
+
1559
+ /** @deprecated Use {@link Database.CreateOptions | `Database.CreateOptions`} */
1301
1560
  type OnCreateOptions<Name extends Type> = Omit<
1302
- DatabaseOperationsFor<Name, "create">,
1561
+ Document.Database.OperationOf<Name, "create">,
1303
1562
  "pack" | "parentUuid" | "syntheticActorUpdate"
1304
1563
  >;
1305
1564
 
1565
+ /** @deprecated Use {@link Database.PreUpdateOptions | `Database.PreUpdateOperation`} */
1306
1566
  type PreUpdateOptions<Name extends Type> = Omit<
1307
- DatabaseOperationsFor<Name, "update">,
1567
+ Document.Database.OperationOf<Name, "update">,
1308
1568
  "updates" | "restoreDelta" | "noHook" | "parent" | "pack"
1309
1569
  >;
1570
+
1571
+ /** @deprecated Use {@link Database.UpdateOptions | `Database.OnUpdateOperation`} */
1310
1572
  type OnUpdateOptions<Name extends Type> = Omit<
1311
- DatabaseOperationsFor<Name, "update">,
1573
+ Document.Database.OperationOf<Name, "update">,
1312
1574
  "pack" | "parentUuid" | "syntheticActorUpdate"
1313
1575
  >;
1314
1576
 
1577
+ /** @deprecated Use {@link Database.PreDeleteOperationInstance | `Database.PreDeleteOperationInstance`} */
1315
1578
  type PreDeleteOptions<Name extends Type> = Omit<
1316
- DatabaseOperationsFor<Name, "delete">,
1579
+ Document.Database.OperationOf<Name, "delete">,
1317
1580
  "ids" | "deleteAll" | "noHook" | "pack" | "parent"
1318
1581
  >;
1582
+
1583
+ /** @deprecated Use {@link Database.DeleteOptions | `Database.OnDeleteOptions`} */
1319
1584
  type OnDeleteOptions<Name extends Type> = Omit<
1320
- DatabaseOperationsFor<Name, "delete">,
1585
+ Document.Database.OperationOf<Name, "delete">,
1321
1586
  "deleteAll" | "pack" | "parentUuid" | "syntheticActorUpdate"
1322
1587
  >;
1323
1588
 
1589
+ /** @deprecated Use {@link Database.PreCreateOptions | `Database.PreCreateOptions`} or {@link Database.PreUpdateOptions | `Database.PreUpdateOperation`}*/
1324
1590
  type PreUpsertOptions<Name extends Type> = PreCreateOptions<Name> | PreUpdateOptions<Name>;
1591
+
1592
+ /** @deprecated Use {@link Database.CreateOptions | `Database.CreateOptions`} or {@link Database.UpdateOptions | `Database.OnUpdateOperation`} */
1325
1593
  type OnUpsertOptions<Name extends Type> = OnCreateOptions<Name> | OnUpdateOptions<Name>;
1594
+ /* eslint-enable @typescript-eslint/no-deprecated */
1326
1595
 
1327
1596
  interface Metadata<out ThisType extends Document.Any> {
1328
1597
  readonly name: ThisType["documentName"];
1329
1598
  readonly collection: string;
1330
- readonly indexed?: boolean | undefined;
1331
- readonly compendiumIndexFields?: readonly string[] | undefined;
1599
+ readonly indexed: boolean;
1600
+ readonly compendiumIndexFields: readonly string[];
1332
1601
  readonly label: string;
1333
1602
  readonly coreTypes: readonly string[];
1334
- readonly embedded: Record<string, string>;
1603
+ readonly embedded: {
1604
+ [DocumentType in Document.Type]?: string;
1605
+ };
1335
1606
  readonly permissions: {
1336
- create:
1337
- | string
1338
- | ToMethod<
1339
- (user: foundry.documents.BaseUser, doc: ThisType, data: Document.ConstructorDataForName<Type>) => boolean
1340
- >;
1341
- update:
1342
- | string
1343
- | ToMethod<
1344
- (user: foundry.documents.BaseUser, doc: ThisType, data: Document.UpdateDataForName<Type>) => boolean
1345
- >;
1346
- delete: string | ToMethod<(user: foundry.documents.BaseUser, doc: ThisType, data: EmptyObject) => boolean>;
1607
+ create: string | ToMethod<(user: User.Internal.Implementation, doc: ThisType, data: AnyObject) => boolean>;
1608
+ update: string | ToMethod<(user: User.Internal.Implementation, doc: ThisType, data: AnyObject) => boolean>;
1609
+ delete: string | ToMethod<(user: User.Internal.Implementation, doc: ThisType, data: EmptyObject) => boolean>;
1347
1610
  };
1348
- readonly preserveOnImport?: readonly string[] | undefined;
1349
- readonly schemaVersion: string | undefined;
1350
- readonly labelPlural: string; // This is not set for the Document class but every class that implements Document actually provides it.
1351
- readonly types: readonly string[];
1352
- readonly hasSystemData: boolean;
1611
+ readonly preserveOnImport: readonly string[];
1612
+ readonly schemaVersion?: string | undefined;
1613
+ readonly labelPlural?: string; // This is not set for the Document class but every class that implements Document actually provides it.
1614
+ readonly types?: readonly string[];
1615
+ readonly hasSystemData?: boolean;
1353
1616
  }
1354
1617
 
1355
1618
  namespace Metadata {
1356
- type Any = Metadata<any>;
1357
-
1358
- export interface Default {
1359
- name: "Document";
1360
- collection: "documents";
1361
- label: "DOCUMENT.Document";
1362
- coreTypes: [typeof foundry.CONST.BASE_DOCUMENT_TYPE];
1363
- types: [];
1364
- embedded: EmptyObject;
1365
- hasSystemData: false;
1366
- permissions: {
1619
+ interface Any extends Metadata<any> {}
1620
+
1621
+ interface Default {
1622
+ readonly name: "Document";
1623
+ readonly collection: "documents";
1624
+ readonly indexed: false;
1625
+ readonly compendiumIndexFields: [];
1626
+ readonly label: "DOCUMENT.Document";
1627
+ readonly coreTypes: [CONST.BASE_DOCUMENT_TYPE];
1628
+ readonly embedded: EmptyObject;
1629
+ readonly permissions: {
1367
1630
  create: "ASSISTANT";
1368
1631
  update: "ASSISTANT";
1369
1632
  delete: "ASSISTANT";
1370
1633
  };
1371
- pack: null;
1634
+ readonly preserveOnImport: ["_id", "sort", "ownership"];
1372
1635
  }
1636
+
1637
+ interface Embedded extends Identity<{ [K in Document.Type]?: string }> {}
1373
1638
  }
1374
- }
1375
1639
 
1376
- export type Operation = "create" | "update" | "delete";
1377
-
1378
- /* eslint-disable @typescript-eslint/no-empty-object-type */
1379
- export interface DocumentDatabaseOperations<
1380
- T extends Document.Internal.Instance.Any = Document.Internal.Instance.Any,
1381
- ExtraCreateOptions extends AnyObject = {},
1382
- ExtraUpdateOptions extends AnyObject = {},
1383
- ExtraDeleteOptions extends AnyObject = {},
1384
- > {
1385
- create: DatabaseCreateOperation<T> & InexactPartial<ExtraCreateOptions>;
1386
- update: DatabaseUpdateOperation<T> & InexactPartial<ExtraUpdateOptions>;
1387
- delete: DatabaseDeleteOperation & InexactPartial<ExtraDeleteOptions>;
1640
+ type ConfiguredSheetClassFor<Name extends Document.Type> = MakeConform<
1641
+ GetKey<GetKey<CONFIG, Name>, "sheetClass">,
1642
+ AnyConstructor
1643
+ >;
1644
+
1645
+ type ConfiguredObjectClassFor<Name extends Document.Type> = GetKey<GetKey<CONFIG, Name>, "objectClass">;
1646
+
1647
+ type ConfiguredLayerClassFor<Name extends Document.Type> = GetKey<GetKey<CONFIG, Name>, "layerClass">;
1648
+
1649
+ type DropData<T extends Document.Any> = T extends { id: string | undefined }
1650
+ ? DropData.Data<T> & DropData.UUID
1651
+ : DropData.Data<T>;
1652
+
1653
+ namespace DropData {
1654
+ type Any = DropData<any>;
1655
+
1656
+ interface Data<T extends Document.Any> {
1657
+ type: T["documentName"];
1658
+ data: T["_source"];
1659
+ }
1660
+
1661
+ interface UUID {
1662
+ uuid: string;
1663
+ }
1664
+ }
1665
+
1666
+ namespace Database {
1667
+ type Operation = "create" | "update" | "delete";
1668
+
1669
+ /**
1670
+ * @privateRemarks Foundry types {@link Document.get | `Document.get`} as taking a {@link DatabaseGetOperation | `DatabaseGetOperation`}
1671
+ * but it only ever looks for `pack`
1672
+ */
1673
+ interface GetOptions extends Pick<DatabaseGetOperation, "pack"> {}
1674
+
1675
+ /** Used for {@link Document.createDocuments | `Document.createDocuments`} */
1676
+ type CreateOperation<Op extends DatabaseCreateOperation> = NullishProps<Omit<Op, "data" | "modifiedTime">>;
1677
+
1678
+ /** Used for {@link Document.update | `Document.update`} */
1679
+ type UpdateOperation<Op extends DatabaseUpdateOperation> = InexactPartial<Omit<Op, "updates">>;
1680
+
1681
+ /** Used for {@link Document.delete | `Document.delete`} */
1682
+ type DeleteOperation<Op extends DatabaseDeleteOperation> = InexactPartial<Omit<Op, "ids">>;
1683
+
1684
+ /** Used for {@link Document._preCreateOperation | `Document._preCreateOperation`} */
1685
+ type PreCreateOperationStatic<Op extends DatabaseCreateOperation> = InexactPartial<
1686
+ Op,
1687
+ Exclude<AllKeysOf<Op>, "modifiedTime" | "render" | "renderSheet" | "data" | "noHook" | "pack" | "parent">
1688
+ >;
1689
+
1690
+ /** Used for {@link Document._preCreate | `Document#_preCreate`} */
1691
+ type PreCreateOptions<Op extends DatabaseCreateOperation> = Omit<
1692
+ PreCreateOperationStatic<Op>,
1693
+ "data" | "noHook" | "pack" | "parent"
1694
+ >;
1695
+
1696
+ /** Used for {@link Document._onCreate | `Document#_onCreate`} */
1697
+ type CreateOptions<Op extends DatabaseCreateOperation> = Omit<
1698
+ Op,
1699
+ "data" | "pack" | "parentUuid" | "syntheticActorUpdate"
1700
+ >;
1701
+
1702
+ /** Used for {@link Document.updateDocuments | `Document.updateDocuments`} */
1703
+ type UpdateDocumentsOperation<Op extends DatabaseUpdateOperation> = NullishProps<
1704
+ Omit<Op, "updates" | "modifiedTime">
1705
+ >;
1706
+
1707
+ /** Used for {@link Document.update | `Document#update`} */
1708
+ type UpdateOperationInstance<Op extends DatabaseUpdateOperation> = InexactPartial<
1709
+ Omit<Op, "updates" | "parent" | "pack">
1710
+ >;
1711
+
1712
+ /** Used for {@link Document._preUpdateOperation | `Document._preUpdateOperation`} */
1713
+ type PreUpdateOperationStatic<Op extends DatabaseUpdateOperation> = InexactPartial<
1714
+ Op,
1715
+ Exclude<
1716
+ AllKeysOf<Op>,
1717
+ "modifiedTime" | "diff" | "recursive" | "render" | "updates" | "restoreDelta" | "noHook" | "pack" | "parent"
1718
+ >
1719
+ >;
1720
+
1721
+ /** Used for {@link Document._preUpdate | `Document#_preUpdate`} */
1722
+ type PreUpdateOptions<Op extends DatabaseUpdateOperation> = Omit<
1723
+ PreUpdateOperationStatic<Op>,
1724
+ "updates" | "restoreDelta" | "noHook" | "pack" | "parent"
1725
+ >;
1726
+
1727
+ /** Used for {@link Document._onUpdate | `Document#_onUpdate`} */
1728
+ type UpdateOptions<Op extends DatabaseUpdateOperation> = Omit<
1729
+ Op,
1730
+ "updates" | "pack" | "parentUuid" | "syntheticActorUpdate"
1731
+ >;
1732
+
1733
+ /** Used for {@link Document.deleteDocuments | `Document.deleteDocuments`} */
1734
+ type DeleteDocumentsOperation<Op extends DatabaseDeleteOperation> = NullishProps<Omit<Op, "ids" | "modifiedTime">>;
1735
+
1736
+ /** Used for {@link Document.delete | `Document.delete`} */
1737
+ type DeleteOperationInstance<Op extends DatabaseDeleteOperation> = InexactPartial<
1738
+ Omit<Op, "ids" | "parent" | "pack">
1739
+ >;
1740
+
1741
+ /** Used for {@link Document._preDeleteOperation | `Document._preDeleteOperation`} */
1742
+ type PreDeleteOperationStatic<Op extends DatabaseDeleteOperation> = InexactPartial<
1743
+ Op,
1744
+ Exclude<AllKeysOf<Op>, "modifiedTime" | "render" | "ids" | "deleteAll" | "noHook" | "pack" | "parent">
1745
+ >;
1746
+
1747
+ /** Used for {@link Document._preDelete | `Document#_preDelete`} */
1748
+ type PreDeleteOperationInstance<Op extends DatabaseDeleteOperation> = Omit<
1749
+ InexactPartial<Op, Exclude<AllKeysOf<Op>, "modifiedTime" | "render">>,
1750
+ "ids" | "deleteAll" | "noHook" | "pack" | "parent"
1751
+ >;
1752
+
1753
+ /** Used for {@link Document._onDelete | `Document#_onDelete`} */
1754
+ type DeleteOptions<Op extends DatabaseDeleteOperation> = Omit<
1755
+ Op,
1756
+ "ids" | "deleteAll" | "pack" | "parentUuid" | "syntheticActorUpdate"
1757
+ >;
1758
+
1759
+ /**
1760
+ * This is a helper type that gets the right DatabaseOperation (including the
1761
+ * proper options) for a particular Document type.
1762
+ *
1763
+ * @deprecated This is no longer used internally inside fvtt-types. If you have use for it please file an issue.
1764
+ */
1765
+ type OperationOf<T extends Document.Type, Operation extends Database.Operation> =
1766
+ | (Operation extends "create" ? DatabaseOperationCreateMap[T] : never)
1767
+ | (Operation extends "update" ? DatabaseOperationUpdateMap[T] : never)
1768
+ | (Operation extends "delete" ? DatabaseOperationDeleteMap[T] : never);
1769
+
1770
+ /**
1771
+ * @deprecated See individual document's namespaces.
1772
+ */
1773
+ interface Operations<
1774
+ _T extends Document.Internal.Instance.Any = Document.Internal.Instance.Any,
1775
+ _ExtraCreateOptions extends AnyObject = any,
1776
+ _ExtraUpdateOptions extends AnyObject = any,
1777
+ _ExtraDeleteOptions extends AnyObject = any,
1778
+ > {
1779
+ create: AnyObject;
1780
+ update: AnyObject;
1781
+ delete: AnyObject;
1782
+ }
1783
+
1784
+ type CreateForName<DocumentType extends Document.Type> =
1785
+ | (DocumentType extends "ActiveEffect" ? ActiveEffect.Database.Create : never)
1786
+ | (DocumentType extends "ActorDelta" ? ActorDelta.Database.Create : never)
1787
+ | (DocumentType extends "Actor" ? Actor.Database.Create : never)
1788
+ | (DocumentType extends "Adventure" ? Adventure.Database.Create : never)
1789
+ | (DocumentType extends "Card" ? Card.Database.Create : never)
1790
+ | (DocumentType extends "Cards" ? Cards.Database.Create : never)
1791
+ | (DocumentType extends "ChatMessage" ? ChatMessage.Database.Create : never)
1792
+ | (DocumentType extends "Combat" ? Combat.Database.Create : never)
1793
+ | (DocumentType extends "Combatant" ? Combatant.Database.Create : never)
1794
+ | (DocumentType extends "FogExploration" ? FogExploration.Database.Create : never)
1795
+ | (DocumentType extends "Folder" ? Folder.Database.Create : never)
1796
+ | (DocumentType extends "Item" ? Item.Database.Create : never)
1797
+ | (DocumentType extends "JournalEntryPage" ? JournalEntryPage.Database.Create : never)
1798
+ | (DocumentType extends "JournalEntry" ? JournalEntry.Database.Create : never)
1799
+ | (DocumentType extends "Macro" ? Macro.Database.Create : never)
1800
+ | (DocumentType extends "PlaylistSound" ? PlaylistSound.Database.Create : never)
1801
+ | (DocumentType extends "Playlist" ? Playlist.Database.Create : never)
1802
+ | (DocumentType extends "RegionBehavior" ? RegionBehavior.Database.Create : never)
1803
+ | (DocumentType extends "RollTable" ? RollTable.Database.Create : never)
1804
+ | (DocumentType extends "Scene" ? Scene.Database.Create : never)
1805
+ | (DocumentType extends "Setting" ? Setting.Database.Create : never)
1806
+ | (DocumentType extends "TableResult" ? TableResult.Database.Create : never)
1807
+ | (DocumentType extends "User" ? User.Database.Create : never)
1808
+ | (DocumentType extends "AmbientLight" ? AmbientLightDocument.Database.Create : never)
1809
+ | (DocumentType extends "AmbientSound" ? AmbientSoundDocument.Database.Create : never)
1810
+ | (DocumentType extends "Drawing" ? DrawingDocument.Database.Create : never)
1811
+ | (DocumentType extends "MeasuredTemplate" ? MeasuredTemplateDocument.Database.Create : never)
1812
+ | (DocumentType extends "Note" ? NoteDocument.Database.Create : never)
1813
+ | (DocumentType extends "Region" ? RegionDocument.Database.Create : never)
1814
+ | (DocumentType extends "Tile" ? TileDocument.Database.Create : never)
1815
+ | (DocumentType extends "Token" ? TokenDocument.Database.Create : never)
1816
+ | (DocumentType extends "Wall" ? WallDocument.Database.Create : never);
1817
+
1818
+ type UpdateOperationForName<DocumentType extends Document.Type> =
1819
+ | (DocumentType extends "ActiveEffect" ? ActiveEffect.Database.UpdateOperation : never)
1820
+ | (DocumentType extends "ActorDelta" ? ActorDelta.Database.UpdateOperation : never)
1821
+ | (DocumentType extends "Actor" ? Actor.Database.UpdateOperation : never)
1822
+ | (DocumentType extends "Adventure" ? Adventure.Database.UpdateOperation : never)
1823
+ | (DocumentType extends "Card" ? Card.Database.UpdateOperation : never)
1824
+ | (DocumentType extends "Cards" ? Cards.Database.UpdateOperation : never)
1825
+ | (DocumentType extends "ChatMessage" ? ChatMessage.Database.UpdateOperation : never)
1826
+ | (DocumentType extends "Combat" ? Combat.Database.UpdateOperation : never)
1827
+ | (DocumentType extends "Combatant" ? Combatant.Database.UpdateOperation : never)
1828
+ | (DocumentType extends "FogExploration" ? FogExploration.Database.UpdateOperation : never)
1829
+ | (DocumentType extends "Folder" ? Folder.Database.UpdateOperation : never)
1830
+ | (DocumentType extends "Item" ? Item.Database.UpdateOperation : never)
1831
+ | (DocumentType extends "JournalEntryPage" ? JournalEntryPage.Database.UpdateOperation : never)
1832
+ | (DocumentType extends "JournalEntry" ? JournalEntry.Database.UpdateOperation : never)
1833
+ | (DocumentType extends "Macro" ? Macro.Database.UpdateOperation : never)
1834
+ | (DocumentType extends "PlaylistSound" ? PlaylistSound.Database.UpdateOperation : never)
1835
+ | (DocumentType extends "Playlist" ? Playlist.Database.UpdateOperation : never)
1836
+ | (DocumentType extends "RegionBehavior" ? RegionBehavior.Database.UpdateOperation : never)
1837
+ | (DocumentType extends "RollTable" ? RollTable.Database.UpdateOperation : never)
1838
+ | (DocumentType extends "Scene" ? Scene.Database.UpdateOperation : never)
1839
+ | (DocumentType extends "Setting" ? Setting.Database.UpdateOperation : never)
1840
+ | (DocumentType extends "TableResult" ? TableResult.Database.UpdateOperation : never)
1841
+ | (DocumentType extends "User" ? User.Database.UpdateOperation : never)
1842
+ | (DocumentType extends "AmbientLight" ? AmbientLightDocument.Database.UpdateOperation : never)
1843
+ | (DocumentType extends "AmbientSound" ? AmbientSoundDocument.Database.UpdateOperation : never)
1844
+ | (DocumentType extends "Drawing" ? DrawingDocument.Database.UpdateOperation : never)
1845
+ | (DocumentType extends "MeasuredTemplate" ? MeasuredTemplateDocument.Database.UpdateOperation : never)
1846
+ | (DocumentType extends "Note" ? NoteDocument.Database.UpdateOperation : never)
1847
+ | (DocumentType extends "Region" ? RegionDocument.Database.UpdateOperation : never)
1848
+ | (DocumentType extends "Tile" ? TileDocument.Database.UpdateOperation : never)
1849
+ | (DocumentType extends "Token" ? TokenDocument.Database.UpdateOperation : never)
1850
+ | (DocumentType extends "Wall" ? WallDocument.Database.UpdateOperation : never);
1851
+
1852
+ type DeleteOperationForName<DocumentType extends Document.Type> =
1853
+ | (DocumentType extends "ActiveEffect" ? ActiveEffect.Database.DeleteOperation : never)
1854
+ | (DocumentType extends "ActorDelta" ? ActorDelta.Database.DeleteOperation : never)
1855
+ | (DocumentType extends "Actor" ? Actor.Database.DeleteOperation : never)
1856
+ | (DocumentType extends "Adventure" ? Adventure.Database.DeleteOperation : never)
1857
+ | (DocumentType extends "Card" ? Card.Database.DeleteOperation : never)
1858
+ | (DocumentType extends "Cards" ? Cards.Database.DeleteOperation : never)
1859
+ | (DocumentType extends "ChatMessage" ? ChatMessage.Database.DeleteOperation : never)
1860
+ | (DocumentType extends "Combat" ? Combat.Database.DeleteOperation : never)
1861
+ | (DocumentType extends "Combatant" ? Combatant.Database.DeleteOperation : never)
1862
+ | (DocumentType extends "FogExploration" ? FogExploration.Database.DeleteOperation : never)
1863
+ | (DocumentType extends "Folder" ? Folder.Database.DeleteOperation : never)
1864
+ | (DocumentType extends "Item" ? Item.Database.DeleteOperation : never)
1865
+ | (DocumentType extends "JournalEntryPage" ? JournalEntryPage.Database.DeleteOperation : never)
1866
+ | (DocumentType extends "JournalEntry" ? JournalEntry.Database.DeleteOperation : never)
1867
+ | (DocumentType extends "Macro" ? Macro.Database.DeleteOperation : never)
1868
+ | (DocumentType extends "PlaylistSound" ? PlaylistSound.Database.DeleteOperation : never)
1869
+ | (DocumentType extends "Playlist" ? Playlist.Database.DeleteOperation : never)
1870
+ | (DocumentType extends "RegionBehavior" ? RegionBehavior.Database.DeleteOperation : never)
1871
+ | (DocumentType extends "RollTable" ? RollTable.Database.DeleteOperation : never)
1872
+ | (DocumentType extends "Scene" ? Scene.Database.DeleteOperation : never)
1873
+ | (DocumentType extends "Setting" ? Setting.Database.DeleteOperation : never)
1874
+ | (DocumentType extends "TableResult" ? TableResult.Database.DeleteOperation : never)
1875
+ | (DocumentType extends "User" ? User.Database.DeleteOperation : never)
1876
+ | (DocumentType extends "AmbientLight" ? AmbientLightDocument.Database.DeleteOperation : never)
1877
+ | (DocumentType extends "AmbientSound" ? AmbientSoundDocument.Database.DeleteOperation : never)
1878
+ | (DocumentType extends "Drawing" ? DrawingDocument.Database.DeleteOperation : never)
1879
+ | (DocumentType extends "MeasuredTemplate" ? MeasuredTemplateDocument.Database.DeleteOperation : never)
1880
+ | (DocumentType extends "Note" ? NoteDocument.Database.DeleteOperation : never)
1881
+ | (DocumentType extends "Region" ? RegionDocument.Database.DeleteOperation : never)
1882
+ | (DocumentType extends "Tile" ? TileDocument.Database.DeleteOperation : never)
1883
+ | (DocumentType extends "Token" ? TokenDocument.Database.DeleteOperation : never)
1884
+ | (DocumentType extends "Wall" ? WallDocument.Database.DeleteOperation : never);
1885
+
1886
+ type CreateOptionsFor<DocumentType extends Document.Type> =
1887
+ | (DocumentType extends "ActiveEffect" ? ActiveEffect.Database.CreateOptions : never)
1888
+ | (DocumentType extends "ActorDelta" ? ActorDelta.Database.CreateOptions : never)
1889
+ | (DocumentType extends "Actor" ? Actor.Database.CreateOptions : never)
1890
+ | (DocumentType extends "Adventure" ? Adventure.Database.CreateOptions : never)
1891
+ | (DocumentType extends "Card" ? Card.Database.CreateOptions : never)
1892
+ | (DocumentType extends "Cards" ? Cards.Database.CreateOptions : never)
1893
+ | (DocumentType extends "ChatMessage" ? ChatMessage.Database.CreateOptions : never)
1894
+ | (DocumentType extends "Combat" ? Combat.Database.CreateOptions : never)
1895
+ | (DocumentType extends "Combatant" ? Combatant.Database.CreateOptions : never)
1896
+ | (DocumentType extends "FogExploration" ? FogExploration.Database.CreateOptions : never)
1897
+ | (DocumentType extends "Folder" ? Folder.Database.CreateOptions : never)
1898
+ | (DocumentType extends "Item" ? Item.Database.CreateOptions : never)
1899
+ | (DocumentType extends "JournalEntryPage" ? JournalEntryPage.Database.CreateOptions : never)
1900
+ | (DocumentType extends "JournalEntry" ? JournalEntry.Database.CreateOptions : never)
1901
+ | (DocumentType extends "Macro" ? Macro.Database.CreateOptions : never)
1902
+ | (DocumentType extends "PlaylistSound" ? PlaylistSound.Database.CreateOptions : never)
1903
+ | (DocumentType extends "Playlist" ? Playlist.Database.CreateOptions : never)
1904
+ | (DocumentType extends "RegionBehavior" ? RegionBehavior.Database.CreateOptions : never)
1905
+ | (DocumentType extends "RollTable" ? RollTable.Database.CreateOptions : never)
1906
+ | (DocumentType extends "Scene" ? Scene.Database.CreateOptions : never)
1907
+ | (DocumentType extends "Setting" ? Setting.Database.CreateOptions : never)
1908
+ | (DocumentType extends "TableResult" ? TableResult.Database.CreateOptions : never)
1909
+ | (DocumentType extends "User" ? User.Database.CreateOptions : never)
1910
+ | (DocumentType extends "AmbientLight" ? AmbientLightDocument.Database.CreateOptions : never)
1911
+ | (DocumentType extends "AmbientSound" ? AmbientSoundDocument.Database.CreateOptions : never)
1912
+ | (DocumentType extends "Drawing" ? DrawingDocument.Database.CreateOptions : never)
1913
+ | (DocumentType extends "MeasuredTemplate" ? MeasuredTemplateDocument.Database.CreateOptions : never)
1914
+ | (DocumentType extends "Note" ? NoteDocument.Database.CreateOptions : never)
1915
+ | (DocumentType extends "Region" ? RegionDocument.Database.CreateOptions : never)
1916
+ | (DocumentType extends "Tile" ? TileDocument.Database.CreateOptions : never)
1917
+ | (DocumentType extends "Token" ? TokenDocument.Database.CreateOptions : never)
1918
+ | (DocumentType extends "Wall" ? WallDocument.Database.CreateOptions : never);
1919
+
1920
+ type UpdateOptionsFor<DocumentType extends Document.Type> =
1921
+ | (DocumentType extends "ActiveEffect" ? ActiveEffect.Database.UpdateOptions : never)
1922
+ | (DocumentType extends "ActorDelta" ? ActorDelta.Database.UpdateOptions : never)
1923
+ | (DocumentType extends "Actor" ? Actor.Database.UpdateOptions : never)
1924
+ | (DocumentType extends "Adventure" ? Adventure.Database.UpdateOptions : never)
1925
+ | (DocumentType extends "Card" ? Card.Database.UpdateOptions : never)
1926
+ | (DocumentType extends "Cards" ? Cards.Database.UpdateOptions : never)
1927
+ | (DocumentType extends "ChatMessage" ? ChatMessage.Database.UpdateOptions : never)
1928
+ | (DocumentType extends "Combat" ? Combat.Database.UpdateOptions : never)
1929
+ | (DocumentType extends "Combatant" ? Combatant.Database.UpdateOptions : never)
1930
+ | (DocumentType extends "FogExploration" ? FogExploration.Database.UpdateOptions : never)
1931
+ | (DocumentType extends "Folder" ? Folder.Database.UpdateOptions : never)
1932
+ | (DocumentType extends "Item" ? Item.Database.UpdateOptions : never)
1933
+ | (DocumentType extends "JournalEntryPage" ? JournalEntryPage.Database.UpdateOptions : never)
1934
+ | (DocumentType extends "JournalEntry" ? JournalEntry.Database.UpdateOptions : never)
1935
+ | (DocumentType extends "Macro" ? Macro.Database.UpdateOptions : never)
1936
+ | (DocumentType extends "PlaylistSound" ? PlaylistSound.Database.UpdateOptions : never)
1937
+ | (DocumentType extends "Playlist" ? Playlist.Database.UpdateOptions : never)
1938
+ | (DocumentType extends "RegionBehavior" ? RegionBehavior.Database.UpdateOptions : never)
1939
+ | (DocumentType extends "RollTable" ? RollTable.Database.UpdateOptions : never)
1940
+ | (DocumentType extends "Scene" ? Scene.Database.UpdateOptions : never)
1941
+ | (DocumentType extends "Setting" ? Setting.Database.UpdateOptions : never)
1942
+ | (DocumentType extends "TableResult" ? TableResult.Database.UpdateOptions : never)
1943
+ | (DocumentType extends "User" ? User.Database.UpdateOptions : never)
1944
+ | (DocumentType extends "AmbientLight" ? AmbientLightDocument.Database.UpdateOptions : never)
1945
+ | (DocumentType extends "AmbientSound" ? AmbientSoundDocument.Database.UpdateOptions : never)
1946
+ | (DocumentType extends "Drawing" ? DrawingDocument.Database.UpdateOptions : never)
1947
+ | (DocumentType extends "MeasuredTemplate" ? MeasuredTemplateDocument.Database.UpdateOptions : never)
1948
+ | (DocumentType extends "Note" ? NoteDocument.Database.UpdateOptions : never)
1949
+ | (DocumentType extends "Region" ? RegionDocument.Database.UpdateOptions : never)
1950
+ | (DocumentType extends "Tile" ? TileDocument.Database.UpdateOptions : never)
1951
+ | (DocumentType extends "Token" ? TokenDocument.Database.UpdateOptions : never)
1952
+ | (DocumentType extends "Wall" ? WallDocument.Database.UpdateOptions : never);
1953
+
1954
+ type DeleteOptionsFor<DocumentType extends Document.Type> =
1955
+ | (DocumentType extends "ActiveEffect" ? ActiveEffect.Database.DeleteOptions : never)
1956
+ | (DocumentType extends "ActorDelta" ? ActorDelta.Database.DeleteOptions : never)
1957
+ | (DocumentType extends "Actor" ? Actor.Database.DeleteOptions : never)
1958
+ | (DocumentType extends "Adventure" ? Adventure.Database.DeleteOptions : never)
1959
+ | (DocumentType extends "Card" ? Card.Database.DeleteOptions : never)
1960
+ | (DocumentType extends "Cards" ? Cards.Database.DeleteOptions : never)
1961
+ | (DocumentType extends "ChatMessage" ? ChatMessage.Database.DeleteOptions : never)
1962
+ | (DocumentType extends "Combat" ? Combat.Database.DeleteOptions : never)
1963
+ | (DocumentType extends "Combatant" ? Combatant.Database.DeleteOptions : never)
1964
+ | (DocumentType extends "FogExploration" ? FogExploration.Database.DeleteOptions : never)
1965
+ | (DocumentType extends "Folder" ? Folder.Database.DeleteOptions : never)
1966
+ | (DocumentType extends "Item" ? Item.Database.DeleteOptions : never)
1967
+ | (DocumentType extends "JournalEntryPage" ? JournalEntryPage.Database.DeleteOptions : never)
1968
+ | (DocumentType extends "JournalEntry" ? JournalEntry.Database.DeleteOptions : never)
1969
+ | (DocumentType extends "Macro" ? Macro.Database.DeleteOptions : never)
1970
+ | (DocumentType extends "PlaylistSound" ? PlaylistSound.Database.DeleteOptions : never)
1971
+ | (DocumentType extends "Playlist" ? Playlist.Database.DeleteOptions : never)
1972
+ | (DocumentType extends "RegionBehavior" ? RegionBehavior.Database.DeleteOptions : never)
1973
+ | (DocumentType extends "RollTable" ? RollTable.Database.DeleteOptions : never)
1974
+ | (DocumentType extends "Scene" ? Scene.Database.DeleteOptions : never)
1975
+ | (DocumentType extends "Setting" ? Setting.Database.DeleteOptions : never)
1976
+ | (DocumentType extends "TableResult" ? TableResult.Database.DeleteOptions : never)
1977
+ | (DocumentType extends "User" ? User.Database.DeleteOptions : never)
1978
+ | (DocumentType extends "AmbientLight" ? AmbientLightDocument.Database.DeleteOptions : never)
1979
+ | (DocumentType extends "AmbientSound" ? AmbientSoundDocument.Database.DeleteOptions : never)
1980
+ | (DocumentType extends "Drawing" ? DrawingDocument.Database.DeleteOptions : never)
1981
+ | (DocumentType extends "MeasuredTemplate" ? MeasuredTemplateDocument.Database.DeleteOptions : never)
1982
+ | (DocumentType extends "Note" ? NoteDocument.Database.DeleteOptions : never)
1983
+ | (DocumentType extends "Region" ? RegionDocument.Database.DeleteOptions : never)
1984
+ | (DocumentType extends "Tile" ? TileDocument.Database.DeleteOptions : never)
1985
+ | (DocumentType extends "Token" ? TokenDocument.Database.DeleteOptions : never)
1986
+ | (DocumentType extends "Wall" ? WallDocument.Database.DeleteOptions : never);
1987
+ }
1988
+
1989
+ interface DataFieldShimOptions {
1990
+ /**
1991
+ * A string to log as a compatibility warning on accessing the `oldKey`
1992
+ */
1993
+ warning?: string | null | undefined;
1994
+
1995
+ /**
1996
+ * @remarks Foundry uses `if ("value" in options)` to determine whether to override the default value.
1997
+ */
1998
+ value?: unknown;
1999
+ }
2000
+
2001
+ /**
2002
+ * @internal
2003
+ * If a `parent` is required for a given Document's creation, its template must pass `NonNullable<X.Parent>` to `CreateDialogContext`
2004
+ */
2005
+ type ParentContext<Parent extends Document.Any | null> = Parent extends null
2006
+ ? {
2007
+ /** A parent document within which the created Document should belong */
2008
+ parent?: Parent | undefined;
2009
+ }
2010
+ : {
2011
+ /** A parent document within which the created Document should belong */
2012
+ parent: Parent;
2013
+ };
2014
+
2015
+ /** @internal */
2016
+ type _PossibleSubtypeContext<DocumentName extends Document.Type> =
2017
+ GetKey<Document.MetadataFor<DocumentName>, "hasTypeData"> extends true
2018
+ ? NullishProps<{
2019
+ /**
2020
+ * The sub-type of the document
2021
+ * @remarks Pulls from `CONFIG[documentName].typeLabels?.[type]` if provided. Ignored if falsey.
2022
+ */
2023
+ type: Document.SubTypesOf<DocumentName>;
2024
+ }>
2025
+ : {
2026
+ /** @deprecated This Document type does not support subtypes */
2027
+ type?: never;
2028
+ };
2029
+
2030
+ type DefaultNameContext<DocumentName extends Document.Type, Parent extends Document.Any | null> = NullishProps<{
2031
+ /**
2032
+ * A compendium pack within which the Document should be created
2033
+ * @remarks Only used to generate the list of existing names to check against when incrementing the index for the `(number)` suffix.
2034
+ * Ignored if falsey, or if `parent` is provided and truthy.
2035
+ */
2036
+ pack: string;
2037
+
2038
+ /**
2039
+ * A parent document within which the created Document should belong
2040
+ * @remarks Only used to generate the list of existing names to check against when incrementing the index for the `(number)` suffix.
2041
+ * Ignored if falsey.
2042
+ */
2043
+ parent: Parent;
2044
+ }> &
2045
+ _PossibleSubtypeContext<DocumentName>;
2046
+
2047
+ type CreateDialogData<CreateData extends object> = InexactPartial<
2048
+ CreateData,
2049
+ Extract<AllKeysOf<CreateData>, "name" | "type" | "folder">
2050
+ >;
2051
+
2052
+ /** @internal */
2053
+ type _PossibleSubtypesContext<DocumentName extends Document.Type> =
2054
+ GetKey<Document.MetadataFor<DocumentName>, "hasTypeData"> extends true
2055
+ ? {
2056
+ /** @deprecated This Document type does not support subtypes */
2057
+ types?: never;
2058
+ }
2059
+ : NullishProps<{
2060
+ /**
2061
+ * A restriction the selectable sub-types of the Dialog.
2062
+ * @remarks Only checked if the document has `static TYPES` of length \> 1 (i.e it both `hasTypeData` and has
2063
+ * at least one non-`"base"` type registered). The computed list will always exclude {@link CONST.BASE_DOCUMENT_TYPE | `CONST.BASE_DOCUMENT_TYPE`},
2064
+ * so it is disallowed in this whitelist.
2065
+ */
2066
+ types: Exclude<Document.SubTypesOf<DocumentName>, "base">[];
2067
+ }>;
2068
+
2069
+ type CreateDialogContext<
2070
+ DocumentName extends Document.Type,
2071
+ Parent extends Document.Any | null,
2072
+ > = InexactPartial<Dialog.Options> &
2073
+ NullishProps<{
2074
+ /**
2075
+ * A compendium pack within which the Document should be created
2076
+ * @remarks Only checked if `parent` is falsey, and only used to generate the list of folders for the dialog
2077
+ */
2078
+ pack: string;
2079
+ }> &
2080
+ _PossibleSubtypesContext<DocumentName> &
2081
+ ParentContext<Parent>;
2082
+
2083
+ interface FromImportContext<Parent extends Document.Any | null> extends Omit<ConstructionContext<Parent>, "strict"> {
2084
+ /**
2085
+ * Strict validation is enabled by default.
2086
+ * @defaultValue `true`
2087
+ * @remarks Not allowed to be `undefined` as that would produce `false`, not the expected default of `true`, due to being spread
2088
+ * into an object with `strict: true`, then passed to {@link Document.fromSource | `Document.fromSource`}, where the parameter
2089
+ * default is `false`
2090
+ */
2091
+ strict?: boolean | null;
2092
+ }
2093
+
2094
+ type ActionPermission = keyof typeof CONST.DOCUMENT_OWNERSHIP_LEVELS | CONST.DOCUMENT_OWNERSHIP_LEVELS;
2095
+
2096
+ /** @deprecated Use {@linkcode Document.ActionPermission} instead */
2097
+ type TestableOwnershipLevel = ActionPermission;
2098
+
2099
+ /** @internal */
2100
+ type _TestUserPermissionsOptions = NullishProps<{
2101
+ /**
2102
+ * Require the exact permission level requested?
2103
+ * @defaultValue `false`
2104
+ */
2105
+ exact: boolean;
2106
+ }>;
2107
+
2108
+ interface TestUserPermissionOptions extends _TestUserPermissionsOptions {}
2109
+
2110
+ /**
2111
+ * @deprecated {@link ImplementationFor | `ImplementationFor`}
2112
+ */
2113
+ type ConfiguredInstanceForName<Name extends Type> = ImplementationFor<Name>;
2114
+
2115
+ /**
2116
+ * @deprecated {@link ImplementationClassFor | `ImplementationClassFor`}
2117
+ */
2118
+ type ConfiguredClassForName<Name extends Type> = ImplementationClassFor<Name>;
2119
+
2120
+ /**
2121
+ * @deprecated {@link SchemaField.SourceData | `SchemaField.SourceData<Schema>`}
2122
+ */
2123
+ type ToObjectFalseType<T extends Document.Internal.Instance.Any> = T extends {
2124
+ toObject: (source: false) => infer U;
2125
+ }
2126
+ ? U
2127
+ : T;
2128
+
2129
+ /**
2130
+ * @deprecated {@link Document.Database.OperationOf | `Document.Database.OperationOf`}
2131
+ */
2132
+ type DatabaseOperationsFor<
2133
+ Name extends Document.Type,
2134
+ ConcreteOperation extends Document.Database.Operation,
2135
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
2136
+ > = Document.Database.OperationOf<Name, ConcreteOperation>;
2137
+
2138
+ /**
2139
+ * @deprecated {@link CreateDataForName | `CreateDataForName`}
2140
+ */
2141
+ type ConstructorDataForName<T extends Document.Type> = CreateData[T];
2142
+
2143
+ type CanUserModifyData<Schema extends DataSchema, Action extends "create" | "update" | "delete"> =
2144
+ | (Action extends "create" ? SchemaField.CreateData<Schema> : never)
2145
+ | (Action extends "update" ? SchemaField.UpdateData<Schema> : never)
2146
+ | (Action extends "delete" ? EmptyObject : never);
2147
+
2148
+ /**
2149
+ * @internal
2150
+ */
2151
+ type _GetEmbeddedDocumentOptions = InexactPartial<{
2152
+ /**
2153
+ * Throw an Error if the requested id does not exist. See {@link Collection.get | `Collection#get`}
2154
+ * @defaultValue `false`
2155
+ */
2156
+ strict: boolean;
2157
+
2158
+ /**
2159
+ * Allow retrieving an invalid Embedded Document.
2160
+ * @defaultValue `false`
2161
+ */
2162
+ invalid: boolean;
2163
+ }>;
2164
+
2165
+ interface GetEmbeddedDocumentOptions extends _GetEmbeddedDocumentOptions {}
2166
+
2167
+ /**
2168
+ * Gets the hierarchical fields in the schema. Hardcoded to whatever Foundry fields are hierarchical
2169
+ * as there is no way to access the a static property of a custom fields from an instance.
2170
+ */
2171
+ type HierarchyOf<Schema extends DataSchema> = PickValue<
2172
+ Schema,
2173
+ EmbeddedCollectionField.Any | EmbeddedDocumentField.Any
2174
+ >;
2175
+
2176
+ type PreCreateDescendantDocumentsArgs<
2177
+ Parent extends Document.AnyStored,
2178
+ DirectDescendant extends Document.Any,
2179
+ Embedded extends Document.Metadata.Embedded,
2180
+ > = DirectDescendant extends unknown
2181
+ ? [
2182
+ parent: Parent,
2183
+ collection: Embedded[DirectDescendant["documentName"]],
2184
+ data: Document.CreateDataForName<DirectDescendant["documentName"]>[],
2185
+ options: Document.Database.CreateOptionsFor<DirectDescendant["documentName"]>,
2186
+ userId: string,
2187
+ ]
2188
+ : never;
2189
+
2190
+ type OnCreateDescendantDocumentsArgs<
2191
+ Parent extends Document.AnyStored,
2192
+ DirectDescendant extends Document.Any,
2193
+ Embedded extends Document.Metadata.Embedded,
2194
+ > = DirectDescendant extends unknown
2195
+ ? [
2196
+ parent: Parent,
2197
+ collection: Embedded[DirectDescendant["documentName"]],
2198
+ documents: DirectDescendant[],
2199
+ data: Document.CreateDataForName<DirectDescendant["documentName"]>[],
2200
+ options: Document.Database.CreateOptionsFor<DirectDescendant["documentName"]>,
2201
+ userId: string,
2202
+ ]
2203
+ : never;
2204
+
2205
+ type PreUpdateDescendantDocumentsArgs<
2206
+ Parent extends Document.AnyStored,
2207
+ DirectDescendant extends Document.Any,
2208
+ Embedded extends Document.Metadata.Embedded,
2209
+ > = DirectDescendant extends unknown
2210
+ ? [
2211
+ parent: Parent,
2212
+ collection: Embedded[DirectDescendant["documentName"]],
2213
+ changes: Document.UpdateDataForName<DirectDescendant["documentName"]>[],
2214
+ options: Document.Database.UpdateOptionsFor<DirectDescendant["documentName"]>,
2215
+ userId: string,
2216
+ ]
2217
+ : never;
2218
+
2219
+ type OnUpdateDescendantDocumentsArgs<
2220
+ Parent extends Document.AnyStored,
2221
+ DirectDescendant extends Document.Any,
2222
+ Embedded extends Document.Metadata.Embedded,
2223
+ > = DirectDescendant extends unknown
2224
+ ? [
2225
+ parent: Parent,
2226
+ collection: Embedded[DirectDescendant["documentName"]],
2227
+ documents: DirectDescendant[],
2228
+ changes: Document.UpdateDataForName<DirectDescendant["documentName"]>[],
2229
+ options: Document.Database.UpdateOptionsFor<DirectDescendant["documentName"]>,
2230
+ userId: string,
2231
+ ]
2232
+ : never;
2233
+
2234
+ type PreDeleteDescendantDocumentsArgs<
2235
+ Parent extends Document.AnyStored,
2236
+ DirectDescendant extends Document.Any,
2237
+ Embedded extends Document.Metadata.Embedded,
2238
+ > = DirectDescendant extends unknown
2239
+ ? [
2240
+ parent: Parent,
2241
+ collection: Embedded[DirectDescendant["documentName"]],
2242
+ ids: string[],
2243
+ options: Document.Database.DeleteOptionsFor<DirectDescendant["documentName"]>,
2244
+ userId: string,
2245
+ ]
2246
+ : never;
2247
+
2248
+ type OnDeleteDescendantDocumentsArgs<
2249
+ Parent extends Document.AnyStored,
2250
+ DirectDescendant extends Document.Any,
2251
+ Embedded extends Document.Metadata.Embedded,
2252
+ > = DirectDescendant extends unknown
2253
+ ? [
2254
+ parent: Parent,
2255
+ collection: Embedded[DirectDescendant["documentName"]],
2256
+ documents: DirectDescendant[],
2257
+ ids: string[],
2258
+ options: Document.Database.DeleteOptionsFor<DirectDescendant["documentName"]>,
2259
+ userId: string,
2260
+ ]
2261
+ : never;
1388
2262
  }
1389
- /* eslint-enable @typescript-eslint/no-empty-object-type */
1390
2263
 
2264
+ /** @deprecated {@link Document.Database.Operation | `Document.Database.Operation`} */
2265
+ export type Operation = Document.Database.Operation;
2266
+
2267
+ /* eslint-disable @typescript-eslint/no-deprecated */
2268
+ /**
2269
+ * @deprecated if you want to get individual operations see {@link Document.Database.OperationOf | `Document.Database.OperationOf`}
2270
+ */
1391
2271
  export interface DatabaseOperationMap {
1392
2272
  ActiveEffect: ActiveEffect.DatabaseOperations;
1393
2273
  Actor: Actor.DatabaseOperations;
@@ -1411,9 +2291,8 @@ export interface DatabaseOperationMap {
1411
2291
  Note: NoteDocument.DatabaseOperations;
1412
2292
  Playlist: Playlist.DatabaseOperations;
1413
2293
  PlaylistSound: PlaylistSound.DatabaseOperations;
1414
- // TODO: Add these once documents are done
1415
- // Region: ActiveEffect.DatabaseOperations;
1416
- // RegionBehavior: ActiveEffect.DatabaseOperations;
2294
+ Region: RegionDocument.DatabaseOperations;
2295
+ RegionBehavior: RegionBehavior.DatabaseOperations;
1417
2296
  RollTable: RollTable.DatabaseOperations;
1418
2297
  Scene: Scene.DatabaseOperations;
1419
2298
  Setting: Setting.DatabaseOperations;
@@ -1423,3 +2302,109 @@ export interface DatabaseOperationMap {
1423
2302
  User: User.DatabaseOperations;
1424
2303
  Wall: WallDocument.DatabaseOperations;
1425
2304
  }
2305
+ /* eslint-enable @typescript-eslint/no-deprecated */
2306
+
2307
+ interface DatabaseOperationCreateMap {
2308
+ ActiveEffect: ActiveEffect.Database.Create;
2309
+ Actor: Actor.Database.Create;
2310
+ ActorDelta: ActorDelta.Database.Create;
2311
+ Adventure: Adventure.Database.Create;
2312
+ AmbientLight: AmbientLightDocument.Database.Create;
2313
+ AmbientSound: AmbientSoundDocument.Database.Create;
2314
+ Card: Card.Database.Create;
2315
+ Cards: Cards.Database.Create;
2316
+ ChatMessage: ChatMessage.Database.Create;
2317
+ Combat: Combat.Database.Create;
2318
+ Combatant: Combatant.Database.Create;
2319
+ Drawing: DrawingDocument.Database.Create;
2320
+ FogExploration: FogExploration.Database.Create;
2321
+ Folder: Folder.Database.Create;
2322
+ Item: Item.Database.Create;
2323
+ JournalEntry: JournalEntry.Database.Create;
2324
+ JournalEntryPage: JournalEntryPage.Database.Create;
2325
+ Macro: Macro.Database.Create;
2326
+ MeasuredTemplate: MeasuredTemplateDocument.Database.Create;
2327
+ Note: NoteDocument.Database.Create;
2328
+ Playlist: Playlist.Database.Create;
2329
+ PlaylistSound: PlaylistSound.Database.Create;
2330
+ Region: RegionDocument.Database.Create;
2331
+ RegionBehavior: RegionBehavior.Database.Create;
2332
+ RollTable: RollTable.Database.Create;
2333
+ Scene: Scene.Database.Create;
2334
+ Setting: Setting.Database.Create;
2335
+ TableResult: TableResult.Database.Create;
2336
+ Tile: TileDocument.Database.Create;
2337
+ Token: TokenDocument.Database.Create;
2338
+ User: User.Database.Create;
2339
+ Wall: WallDocument.Database.Create;
2340
+ }
2341
+
2342
+ interface DatabaseOperationUpdateMap {
2343
+ ActiveEffect: ActiveEffect.Database.Update;
2344
+ Actor: Actor.Database.Update;
2345
+ ActorDelta: ActorDelta.Database.Update;
2346
+ Adventure: Adventure.Database.Update;
2347
+ AmbientLight: AmbientLightDocument.Database.Update;
2348
+ AmbientSound: AmbientSoundDocument.Database.Update;
2349
+ Card: Card.Database.Update;
2350
+ Cards: Cards.Database.Update;
2351
+ ChatMessage: ChatMessage.Database.Update;
2352
+ Combat: Combat.Database.Update;
2353
+ Combatant: Combatant.Database.Update;
2354
+ Drawing: DrawingDocument.Database.Update;
2355
+ FogExploration: FogExploration.Database.Update;
2356
+ Folder: Folder.Database.Update;
2357
+ Item: Item.Database.Update;
2358
+ JournalEntry: JournalEntry.Database.Update;
2359
+ JournalEntryPage: JournalEntryPage.Database.Update;
2360
+ Macro: Macro.Database.Update;
2361
+ MeasuredTemplate: MeasuredTemplateDocument.Database.Update;
2362
+ Note: NoteDocument.Database.Update;
2363
+ Playlist: Playlist.Database.Update;
2364
+ PlaylistSound: PlaylistSound.Database.Update;
2365
+ Region: RegionDocument.Database.Update;
2366
+ RegionBehavior: RegionBehavior.Database.Update;
2367
+ RollTable: RollTable.Database.Update;
2368
+ Scene: Scene.Database.Update;
2369
+ Setting: Setting.Database.Update;
2370
+ TableResult: TableResult.Database.Update;
2371
+ Tile: TileDocument.Database.Update;
2372
+ Token: TokenDocument.Database.Update;
2373
+ User: User.Database.Update;
2374
+ Wall: WallDocument.Database.Update;
2375
+ }
2376
+
2377
+ interface DatabaseOperationDeleteMap {
2378
+ ActiveEffect: ActiveEffect.Database.Delete;
2379
+ Actor: Actor.Database.Delete;
2380
+ ActorDelta: ActorDelta.Database.Delete;
2381
+ Adventure: Adventure.Database.Delete;
2382
+ AmbientLight: AmbientLightDocument.Database.Delete;
2383
+ AmbientSound: AmbientSoundDocument.Database.Delete;
2384
+ Card: Card.Database.Delete;
2385
+ Cards: Cards.Database.Delete;
2386
+ ChatMessage: ChatMessage.Database.Delete;
2387
+ Combat: Combat.Database.Delete;
2388
+ Combatant: Combatant.Database.Delete;
2389
+ Drawing: DrawingDocument.Database.Delete;
2390
+ FogExploration: FogExploration.Database.Delete;
2391
+ Folder: Folder.Database.Delete;
2392
+ Item: Item.Database.Delete;
2393
+ JournalEntry: JournalEntry.Database.Delete;
2394
+ JournalEntryPage: JournalEntryPage.Database.Delete;
2395
+ Macro: Macro.Database.Delete;
2396
+ MeasuredTemplate: MeasuredTemplateDocument.Database.Delete;
2397
+ Note: NoteDocument.Database.Delete;
2398
+ Playlist: Playlist.Database.Delete;
2399
+ PlaylistSound: PlaylistSound.Database.Delete;
2400
+ Region: RegionDocument.Database.Delete;
2401
+ RegionBehavior: RegionBehavior.Database.Delete;
2402
+ RollTable: RollTable.Database.Delete;
2403
+ Scene: Scene.Database.Delete;
2404
+ Setting: Setting.Database.Delete;
2405
+ TableResult: TableResult.Database.Delete;
2406
+ Tile: TileDocument.Database.Delete;
2407
+ Token: TokenDocument.Database.Delete;
2408
+ User: User.Database.Delete;
2409
+ Wall: WallDocument.Database.Delete;
2410
+ }