mobx-keystone 0.67.4 → 0.68.1-alpha

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 (394) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/_virtual/_tslib.mjs +12 -0
  3. package/dist/mobx-keystone.umd.js +5339 -5261
  4. package/dist/model/utils.d.ts +1 -1
  5. package/dist/node_modules/fast-deep-equal/es6/index.mjs +68 -0
  6. package/dist/node_modules/nanoid/non-secure/index.mjs +11 -0
  7. package/dist/snapshot/index.d.ts +0 -8
  8. package/dist/{dataModel/_BaseDataModel.d.ts → snapshot/registerDefaultReconcilers.d.ts} +0 -0
  9. package/dist/{model/_BaseModel.d.ts → snapshot/registerDefaultSnapshotters.d.ts} +0 -0
  10. package/dist/src/action/actionDecoratorUtils.mjs +25 -0
  11. package/dist/src/action/applyAction.mjs +54 -0
  12. package/dist/src/action/applyDelete.mjs +20 -0
  13. package/dist/src/action/applyMethodCall.mjs +19 -0
  14. package/dist/src/action/applySet.mjs +25 -0
  15. package/dist/src/action/builtInActions.mjs +15 -0
  16. package/dist/src/action/context.mjs +22 -0
  17. package/dist/src/action/hookActions.mjs +13 -0
  18. package/dist/src/action/isModelAction.mjs +6 -0
  19. package/dist/src/action/middleware.mjs +84 -0
  20. package/dist/src/action/modelAction.mjs +34 -0
  21. package/dist/src/action/modelFlow.mjs +251 -0
  22. package/dist/src/action/pendingActions.mjs +30 -0
  23. package/dist/src/action/protection.mjs +19 -0
  24. package/dist/src/action/runUnprotected.mjs +24 -0
  25. package/dist/src/action/wrapInAction.mjs +90 -0
  26. package/dist/src/actionMiddlewares/actionSerialization/actionSerialization.mjs +131 -0
  27. package/dist/src/actionMiddlewares/actionSerialization/applySerializedAction.mjs +110 -0
  28. package/dist/src/actionMiddlewares/actionSerialization/arraySerializer.mjs +15 -0
  29. package/dist/src/actionMiddlewares/actionSerialization/core.mjs +3 -0
  30. package/dist/src/actionMiddlewares/actionSerialization/dateSerializer.mjs +15 -0
  31. package/dist/src/actionMiddlewares/actionSerialization/mapSerializer.mjs +32 -0
  32. package/dist/src/actionMiddlewares/actionSerialization/objectPathSerializer.mjs +33 -0
  33. package/dist/src/actionMiddlewares/actionSerialization/objectSnapshotSerializer.mjs +18 -0
  34. package/dist/src/actionMiddlewares/actionSerialization/plainObjectSerializer.mjs +27 -0
  35. package/dist/src/actionMiddlewares/actionSerialization/primitiveSerializer.mjs +39 -0
  36. package/dist/src/actionMiddlewares/actionSerialization/setSerializer.mjs +29 -0
  37. package/dist/src/actionMiddlewares/actionTrackingMiddleware.mjs +239 -0
  38. package/dist/src/actionMiddlewares/onActionMiddleware.mjs +44 -0
  39. package/dist/src/actionMiddlewares/readonlyMiddleware.mjs +49 -0
  40. package/dist/src/actionMiddlewares/transactionMiddleware.mjs +69 -0
  41. package/dist/src/actionMiddlewares/undoMiddleware.mjs +472 -0
  42. package/dist/src/actionMiddlewares/utils.mjs +25 -0
  43. package/dist/src/computedTree/computedTree.mjs +63 -0
  44. package/dist/src/context/context.mjs +141 -0
  45. package/dist/src/dataModel/BaseDataModel.mjs +108 -0
  46. package/dist/src/dataModel/DataModel.mjs +32 -0
  47. package/dist/src/dataModel/actions.mjs +12 -0
  48. package/dist/src/dataModel/getDataModelMetadata.mjs +14 -0
  49. package/dist/src/dataModel/newDataModel.mjs +31 -0
  50. package/dist/src/dataModel/utils.mjs +29 -0
  51. package/dist/src/frozen/Frozen.mjs +68 -0
  52. package/dist/src/globalConfig/globalConfig.mjs +57 -0
  53. package/dist/src/index.mjs +97 -0
  54. package/dist/src/model/BaseModel.mjs +118 -0
  55. package/dist/src/model/Model.mjs +36 -0
  56. package/dist/src/model/getModelMetadata.mjs +19 -0
  57. package/dist/src/model/metadata.mjs +7 -0
  58. package/dist/src/model/newModel.mjs +95 -0
  59. package/dist/src/model/utils.mjs +33 -0
  60. package/dist/src/modelShared/BaseModelShared.mjs +9 -0
  61. package/dist/src/modelShared/Model.mjs +249 -0
  62. package/dist/src/modelShared/checkModelDecoratorArgs.mjs +21 -0
  63. package/dist/src/modelShared/modelClassInitializer.mjs +14 -0
  64. package/dist/src/modelShared/modelDecorator.mjs +117 -0
  65. package/dist/src/modelShared/modelInfo.mjs +7 -0
  66. package/dist/src/modelShared/modelPropsInfo.mjs +9 -0
  67. package/dist/src/modelShared/modelSymbols.mjs +5 -0
  68. package/dist/src/modelShared/newModel.mjs +13 -0
  69. package/dist/src/modelShared/prop.mjs +138 -0
  70. package/dist/src/modelShared/utils.mjs +10 -0
  71. package/dist/src/parent/core.mjs +34 -0
  72. package/dist/src/parent/coreObjectChildren.mjs +98 -0
  73. package/dist/src/parent/detach.mjs +32 -0
  74. package/dist/src/parent/findChildren.mjs +16 -0
  75. package/dist/src/parent/findParent.mjs +30 -0
  76. package/dist/src/parent/getChildrenObjects.mjs +12 -0
  77. package/dist/src/parent/onChildAttachedTo.mjs +101 -0
  78. package/dist/src/parent/path.mjs +149 -0
  79. package/dist/src/parent/path2.mjs +12 -0
  80. package/dist/src/parent/setParent.mjs +83 -0
  81. package/dist/src/parent/walkTree.mjs +104 -0
  82. package/dist/src/patch/applyPatches.mjs +118 -0
  83. package/dist/src/patch/emitPatch.mjs +100 -0
  84. package/dist/src/patch/jsonPatch.mjs +60 -0
  85. package/dist/src/patch/patchRecorder.mjs +75 -0
  86. package/dist/src/redux/connectReduxDevTools.mjs +153 -0
  87. package/dist/src/redux/redux.mjs +60 -0
  88. package/dist/src/ref/Ref.mjs +38 -0
  89. package/dist/src/ref/core.mjs +179 -0
  90. package/dist/src/ref/customRef.mjs +9 -0
  91. package/dist/src/ref/rootRef.mjs +34 -0
  92. package/dist/src/rootStore/attachDetach.mjs +53 -0
  93. package/dist/src/rootStore/rootStore.mjs +50 -0
  94. package/dist/src/snapshot/SnapshotterAndReconcilerPriority.mjs +9 -0
  95. package/dist/src/snapshot/applySnapshot.mjs +92 -0
  96. package/dist/src/snapshot/clone.mjs +29 -0
  97. package/dist/src/snapshot/fromArraySnapshot.mjs +23 -0
  98. package/dist/src/snapshot/fromFrozenSnapshot.mjs +13 -0
  99. package/dist/src/snapshot/fromModelSnapshot.mjs +38 -0
  100. package/dist/src/snapshot/fromPlainObjectSnapshot.mjs +26 -0
  101. package/dist/src/snapshot/fromSnapshot.mjs +91 -0
  102. package/dist/src/snapshot/getSnapshot.mjs +27 -0
  103. package/dist/src/snapshot/internal.mjs +97 -0
  104. package/dist/src/snapshot/onSnapshot.mjs +16 -0
  105. package/dist/src/snapshot/reconcileArraySnapshot.mjs +40 -0
  106. package/dist/src/snapshot/reconcileFrozenSnapshot.mjs +19 -0
  107. package/dist/src/snapshot/reconcileModelSnapshot.mjs +77 -0
  108. package/dist/src/snapshot/reconcilePlainObjectSnapshot.mjs +47 -0
  109. package/dist/src/snapshot/reconcileSnapshot.mjs +49 -0
  110. package/dist/src/snapshot/registerDefaultReconcilers.mjs +17 -0
  111. package/dist/src/snapshot/registerDefaultSnapshotters.mjs +17 -0
  112. package/dist/src/standardActions/actions.mjs +35 -0
  113. package/dist/src/standardActions/arrayActions.mjs +66 -0
  114. package/dist/src/standardActions/objectActions.mjs +36 -0
  115. package/dist/src/standardActions/standaloneActions.mjs +9 -0
  116. package/dist/src/transforms/ImmutableDate.mjs +51 -0
  117. package/dist/src/transforms/asMap.mjs +29 -0
  118. package/dist/src/transforms/asSet.mjs +12 -0
  119. package/dist/src/transforms/bigint.mjs +14 -0
  120. package/dist/src/transforms/date.mjs +27 -0
  121. package/dist/src/treeUtils/deepEquals.mjs +40 -0
  122. package/dist/src/treeUtils/draft.mjs +116 -0
  123. package/dist/src/treeUtils/sandbox.mjs +158 -0
  124. package/dist/src/tweaker/TweakerPriority.mjs +9 -0
  125. package/dist/src/tweaker/core.mjs +38 -0
  126. package/dist/src/tweaker/registerDefaultTweakers.mjs +17 -0
  127. package/dist/src/tweaker/tweak.mjs +109 -0
  128. package/dist/src/tweaker/tweakArray.mjs +272 -0
  129. package/dist/src/tweaker/tweakFrozen.mjs +28 -0
  130. package/dist/src/tweaker/tweakModel.mjs +26 -0
  131. package/dist/src/tweaker/tweakPlainObject.mjs +205 -0
  132. package/dist/src/tweaker/typeChecking.mjs +46 -0
  133. package/dist/src/tweaker/withoutTypeChecking.mjs +15 -0
  134. package/dist/src/types/TypeCheckError.mjs +31 -0
  135. package/dist/src/types/TypeChecker.mjs +165 -0
  136. package/dist/src/types/arrayBased/array.mjs +68 -0
  137. package/dist/src/types/arrayBased/tuple.mjs +71 -0
  138. package/dist/src/types/getTypeInfo.mjs +12 -0
  139. package/dist/src/types/objectBased/arraySet.mjs +83 -0
  140. package/dist/src/types/objectBased/dataModelData.mjs +95 -0
  141. package/dist/src/types/objectBased/model.mjs +133 -0
  142. package/dist/src/types/objectBased/object.mjs +119 -0
  143. package/dist/src/types/objectBased/objectMap.mjs +90 -0
  144. package/dist/src/types/objectBased/record.mjs +80 -0
  145. package/dist/src/types/objectBased/ref.mjs +62 -0
  146. package/dist/src/types/primitiveBased/enum.mjs +20 -0
  147. package/dist/src/types/primitiveBased/primitives.mjs +59 -0
  148. package/dist/src/types/primitiveBased/refinedPrimitives.mjs +6 -0
  149. package/dist/src/types/registerDefaultStandardTypeResolvers.mjs +13 -0
  150. package/dist/src/types/resolveTypeChecker.mjs +52 -0
  151. package/dist/src/types/tProp.mjs +53 -0
  152. package/dist/src/types/typeCheck.mjs +11 -0
  153. package/dist/src/types/types.mjs +69 -0
  154. package/dist/src/types/utility/maybe.mjs +10 -0
  155. package/dist/src/types/utility/or.mjs +99 -0
  156. package/dist/src/types/utility/refinement.mjs +52 -0
  157. package/dist/src/types/utility/unchecked.mjs +10 -0
  158. package/dist/src/utils/ModelPool.mjs +50 -0
  159. package/dist/src/utils/chainFns.mjs +15 -0
  160. package/dist/src/utils/index.mjs +228 -0
  161. package/dist/src/utils/mapUtils.mjs +10 -0
  162. package/dist/src/utils/tag.mjs +16 -0
  163. package/dist/src/wrappers/ArraySet.mjs +85 -0
  164. package/dist/src/wrappers/ObjectMap.mjs +96 -0
  165. package/dist/src/wrappers/asMap.mjs +181 -0
  166. package/dist/src/wrappers/asSet.mjs +97 -0
  167. package/dist/tweaker/index.d.ts +0 -4
  168. package/dist/tweaker/registerDefaultTweakers.d.ts +1 -0
  169. package/dist/types/registerDefaultStandardTypeResolvers.d.ts +1 -0
  170. package/package.json +12 -14
  171. package/src/actionMiddlewares/actionSerialization/actionSerialization.ts +24 -9
  172. package/src/dataModel/BaseDataModel.ts +0 -3
  173. package/src/dataModel/utils.ts +4 -4
  174. package/src/dist/action/actionDecoratorUtils.d.ts +5 -0
  175. package/src/dist/action/applyAction.d.ts +36 -0
  176. package/src/dist/action/applyDelete.d.ts +7 -0
  177. package/src/dist/action/applyMethodCall.d.ts +9 -0
  178. package/src/dist/action/applySet.d.ts +8 -0
  179. package/src/dist/action/builtInActions.d.ts +39 -0
  180. package/src/dist/action/context.d.ts +85 -0
  181. package/src/dist/action/hookActions.d.ts +32 -0
  182. package/src/dist/action/index.d.ts +12 -0
  183. package/src/dist/action/isModelAction.d.ts +7 -0
  184. package/src/dist/action/middleware.d.ts +34 -0
  185. package/src/dist/action/modelAction.d.ts +9 -0
  186. package/src/dist/action/modelFlow.d.ts +34 -0
  187. package/src/dist/action/pendingActions.d.ts +1 -0
  188. package/src/dist/action/protection.d.ts +1 -0
  189. package/src/dist/action/runUnprotected.d.ts +19 -0
  190. package/src/dist/action/wrapInAction.d.ts +1 -0
  191. package/src/dist/actionMiddlewares/actionSerialization/actionSerialization.d.ts +84 -0
  192. package/src/dist/actionMiddlewares/actionSerialization/applySerializedAction.d.ts +45 -0
  193. package/src/dist/actionMiddlewares/actionSerialization/arraySerializer.d.ts +3 -0
  194. package/src/dist/actionMiddlewares/actionSerialization/core.d.ts +28 -0
  195. package/src/dist/actionMiddlewares/actionSerialization/dateSerializer.d.ts +2 -0
  196. package/src/dist/actionMiddlewares/actionSerialization/index.d.ts +3 -0
  197. package/src/dist/actionMiddlewares/actionSerialization/mapSerializer.d.ts +6 -0
  198. package/src/dist/actionMiddlewares/actionSerialization/objectPathSerializer.d.ts +8 -0
  199. package/src/dist/actionMiddlewares/actionSerialization/objectSnapshotSerializer.d.ts +2 -0
  200. package/src/dist/actionMiddlewares/actionSerialization/plainObjectSerializer.d.ts +2 -0
  201. package/src/dist/actionMiddlewares/actionSerialization/primitiveSerializer.d.ts +2 -0
  202. package/src/dist/actionMiddlewares/actionSerialization/setSerializer.d.ts +3 -0
  203. package/src/dist/actionMiddlewares/actionTrackingMiddleware.d.ts +122 -0
  204. package/src/dist/actionMiddlewares/index.d.ts +6 -0
  205. package/src/dist/actionMiddlewares/onActionMiddleware.d.ts +26 -0
  206. package/src/dist/actionMiddlewares/readonlyMiddleware.d.ts +35 -0
  207. package/src/dist/actionMiddlewares/transactionMiddleware.d.ts +21 -0
  208. package/src/dist/actionMiddlewares/undoMiddleware.d.ts +283 -0
  209. package/src/dist/actionMiddlewares/utils.d.ts +1 -0
  210. package/src/dist/computedTree/computedTree.d.ts +16 -0
  211. package/src/dist/computedTree/index.d.ts +1 -0
  212. package/src/dist/context/context.d.ts +84 -0
  213. package/src/dist/context/index.d.ts +1 -0
  214. package/src/dist/dataModel/BaseDataModel.d.ts +52 -0
  215. package/src/dist/dataModel/DataModel.d.ts +47 -0
  216. package/src/dist/dataModel/DataModelConstructorOptions.d.ts +1 -0
  217. package/src/dist/dataModel/actions.d.ts +1 -0
  218. package/src/dist/dataModel/getDataModelMetadata.d.ts +19 -0
  219. package/src/dist/dataModel/index.d.ts +4 -0
  220. package/src/dist/dataModel/newDataModel.d.ts +1 -0
  221. package/src/dist/dataModel/utils.d.ts +8 -0
  222. package/src/dist/frozen/Frozen.d.ts +50 -0
  223. package/src/dist/frozen/index.d.ts +1 -0
  224. package/src/dist/globalConfig/globalConfig.d.ts +51 -0
  225. package/src/dist/globalConfig/index.d.ts +1 -0
  226. package/src/dist/index.d.ts +23 -0
  227. package/src/dist/mobx-keystone.umd.js +8201 -0
  228. package/src/dist/model/BaseModel.d.ts +125 -0
  229. package/src/dist/model/Model.d.ts +94 -0
  230. package/src/dist/model/ModelConstructorOptions.d.ts +1 -0
  231. package/src/dist/model/getModelMetadata.d.ts +27 -0
  232. package/src/dist/model/index.d.ts +5 -0
  233. package/src/dist/model/metadata.d.ts +8 -0
  234. package/src/dist/model/newModel.d.ts +1 -0
  235. package/src/dist/model/utils.d.ts +8 -0
  236. package/src/dist/modelShared/BaseModelShared.d.ts +76 -0
  237. package/src/dist/modelShared/Model.d.ts +15 -0
  238. package/src/dist/modelShared/checkModelDecoratorArgs.d.ts +1 -0
  239. package/src/dist/modelShared/index.d.ts +3 -0
  240. package/src/dist/modelShared/modelClassInitializer.d.ts +1 -0
  241. package/src/dist/modelShared/modelDecorator.d.ts +24 -0
  242. package/src/dist/modelShared/modelInfo.d.ts +1 -0
  243. package/src/dist/modelShared/modelPropsInfo.d.ts +1 -0
  244. package/src/dist/modelShared/modelSymbols.d.ts +3 -0
  245. package/src/dist/modelShared/newModel.d.ts +4 -0
  246. package/src/dist/modelShared/prop.d.ts +179 -0
  247. package/src/dist/modelShared/utils.d.ts +1 -0
  248. package/src/dist/parent/core.d.ts +1 -0
  249. package/src/dist/parent/coreObjectChildren.d.ts +1 -0
  250. package/src/dist/parent/detach.d.ts +9 -0
  251. package/src/dist/parent/findChildren.d.ts +13 -0
  252. package/src/dist/parent/findParent.d.ts +41 -0
  253. package/src/dist/parent/getChildrenObjects.d.ts +11 -0
  254. package/src/dist/parent/index.d.ts +9 -0
  255. package/src/dist/parent/onChildAttachedTo.d.ts +22 -0
  256. package/src/dist/parent/path.d.ts +107 -0
  257. package/src/dist/parent/path2.d.ts +16 -0
  258. package/src/dist/parent/pathTypes.d.ts +12 -0
  259. package/src/dist/parent/setParent.d.ts +1 -0
  260. package/src/dist/parent/walkTree.d.ts +25 -0
  261. package/src/dist/patch/Patch.d.ts +16 -0
  262. package/src/dist/patch/applyPatches.d.ts +9 -0
  263. package/src/dist/patch/emitPatch.d.ts +29 -0
  264. package/src/dist/patch/index.d.ts +5 -0
  265. package/src/dist/patch/jsonPatch.d.ts +45 -0
  266. package/src/dist/patch/patchRecorder.d.ts +70 -0
  267. package/src/dist/redux/connectReduxDevTools.d.ts +12 -0
  268. package/src/dist/redux/index.d.ts +2 -0
  269. package/src/dist/redux/redux.d.ts +47 -0
  270. package/src/dist/ref/Ref.d.ts +53 -0
  271. package/src/dist/ref/core.d.ts +46 -0
  272. package/src/dist/ref/customRef.d.ts +38 -0
  273. package/src/dist/ref/index.d.ts +4 -0
  274. package/src/dist/ref/rootRef.d.ts +33 -0
  275. package/src/dist/rootStore/attachDetach.d.ts +1 -0
  276. package/src/dist/rootStore/index.d.ts +1 -0
  277. package/src/dist/rootStore/rootStore.d.ts +33 -0
  278. package/src/dist/snapshot/SnapshotOf.d.ts +47 -0
  279. package/src/dist/snapshot/SnapshotterAndReconcilerPriority.d.ts +1 -0
  280. package/src/dist/snapshot/applySnapshot.d.ts +17 -0
  281. package/src/dist/snapshot/clone.d.ts +18 -0
  282. package/src/dist/snapshot/fromArraySnapshot.d.ts +1 -0
  283. package/src/dist/snapshot/fromFrozenSnapshot.d.ts +1 -0
  284. package/src/dist/snapshot/fromModelSnapshot.d.ts +1 -0
  285. package/src/dist/snapshot/fromPlainObjectSnapshot.d.ts +1 -0
  286. package/src/dist/snapshot/fromSnapshot.d.ts +36 -0
  287. package/src/dist/snapshot/getSnapshot.d.ts +22 -0
  288. package/src/dist/snapshot/index.d.ts +6 -0
  289. package/src/dist/snapshot/internal.d.ts +1 -0
  290. package/src/dist/snapshot/onSnapshot.d.ts +18 -0
  291. package/src/dist/snapshot/reconcileArraySnapshot.d.ts +1 -0
  292. package/src/dist/snapshot/reconcileFrozenSnapshot.d.ts +1 -0
  293. package/src/dist/snapshot/reconcileModelSnapshot.d.ts +1 -0
  294. package/src/dist/snapshot/reconcilePlainObjectSnapshot.d.ts +1 -0
  295. package/src/dist/snapshot/reconcileSnapshot.d.ts +1 -0
  296. package/src/dist/snapshot/registerDefaultReconcilers.d.ts +1 -0
  297. package/src/dist/snapshot/registerDefaultSnapshotters.d.ts +1 -0
  298. package/src/dist/standardActions/actions.d.ts +1 -0
  299. package/src/dist/standardActions/arrayActions.d.ts +18 -0
  300. package/src/dist/standardActions/index.d.ts +3 -0
  301. package/src/dist/standardActions/objectActions.d.ts +7 -0
  302. package/src/dist/standardActions/standaloneActions.d.ts +16 -0
  303. package/src/dist/transforms/ImmutableDate.d.ts +1 -0
  304. package/src/dist/transforms/asMap.d.ts +3 -0
  305. package/src/dist/transforms/asSet.d.ts +2 -0
  306. package/src/dist/transforms/bigint.d.ts +2 -0
  307. package/src/dist/transforms/date.d.ts +3 -0
  308. package/src/dist/transforms/index.d.ts +4 -0
  309. package/src/dist/treeUtils/deepEquals.d.ts +20 -0
  310. package/src/dist/treeUtils/draft.d.ts +70 -0
  311. package/src/dist/treeUtils/index.d.ts +3 -0
  312. package/src/dist/treeUtils/sandbox.d.ts +85 -0
  313. package/src/dist/tweaker/TweakerPriority.d.ts +1 -0
  314. package/src/dist/tweaker/core.d.ts +14 -0
  315. package/src/dist/tweaker/index.d.ts +2 -0
  316. package/src/dist/tweaker/registerDefaultTweakers.d.ts +1 -0
  317. package/src/dist/tweaker/tweak.d.ts +22 -0
  318. package/src/dist/tweaker/tweakArray.d.ts +1 -0
  319. package/src/dist/tweaker/tweakFrozen.d.ts +1 -0
  320. package/src/dist/tweaker/tweakModel.d.ts +1 -0
  321. package/src/dist/tweaker/tweakPlainObject.d.ts +1 -0
  322. package/src/dist/tweaker/typeChecking.d.ts +1 -0
  323. package/src/dist/tweaker/withoutTypeChecking.d.ts +2 -0
  324. package/src/dist/types/TypeCheckError.d.ts +22 -0
  325. package/src/dist/types/TypeChecker.d.ts +8 -0
  326. package/src/dist/types/arrayBased/array.d.ts +23 -0
  327. package/src/dist/types/arrayBased/tuple.d.ts +24 -0
  328. package/src/dist/types/getTypeInfo.d.ts +9 -0
  329. package/src/dist/types/index.d.ts +5 -0
  330. package/src/dist/types/objectBased/arraySet.d.ts +24 -0
  331. package/src/dist/types/objectBased/dataModelData.d.ts +44 -0
  332. package/src/dist/types/objectBased/model.d.ts +43 -0
  333. package/src/dist/types/objectBased/object.d.ts +63 -0
  334. package/src/dist/types/objectBased/objectMap.d.ts +24 -0
  335. package/src/dist/types/objectBased/record.d.ts +24 -0
  336. package/src/dist/types/objectBased/ref.d.ts +21 -0
  337. package/src/dist/types/primitiveBased/enum.d.ts +34 -0
  338. package/src/dist/types/primitiveBased/primitives.d.ts +81 -0
  339. package/src/dist/types/primitiveBased/refinedPrimitives.d.ts +18 -0
  340. package/src/dist/types/registerDefaultStandardTypeResolvers.d.ts +1 -0
  341. package/src/dist/types/resolveTypeChecker.d.ts +1 -0
  342. package/src/dist/types/schemas.d.ts +53 -0
  343. package/src/dist/types/tProp.d.ts +92 -0
  344. package/src/dist/types/typeCheck.d.ts +11 -0
  345. package/src/dist/types/types.d.ts +51 -0
  346. package/src/dist/types/utility/maybe.d.ts +29 -0
  347. package/src/dist/types/utility/or.d.ts +35 -0
  348. package/src/dist/types/utility/refinement.d.ts +45 -0
  349. package/src/dist/types/utility/unchecked.d.ts +22 -0
  350. package/src/dist/utils/ModelPool.d.ts +7 -0
  351. package/src/dist/utils/chainFns.d.ts +1 -0
  352. package/src/dist/utils/index.d.ts +6 -0
  353. package/src/dist/utils/mapUtils.d.ts +2 -0
  354. package/src/dist/utils/tag.d.ts +13 -0
  355. package/src/dist/utils/types.d.ts +39 -0
  356. package/src/dist/wrappers/ArraySet.d.ts +29 -0
  357. package/src/dist/wrappers/ObjectMap.d.ts +32 -0
  358. package/src/dist/wrappers/asMap.d.ts +29 -0
  359. package/src/dist/wrappers/asSet.d.ts +15 -0
  360. package/src/dist/wrappers/index.d.ts +4 -0
  361. package/src/model/BaseModel.ts +0 -3
  362. package/src/model/utils.ts +4 -5
  363. package/src/modelShared/checkModelDecoratorArgs.ts +6 -6
  364. package/src/parent/setParent.ts +2 -2
  365. package/src/rootStore/attachDetach.ts +2 -3
  366. package/src/snapshot/fromArraySnapshot.ts +11 -6
  367. package/src/snapshot/fromFrozenSnapshot.ts +11 -6
  368. package/src/snapshot/fromModelSnapshot.ts +11 -6
  369. package/src/snapshot/fromPlainObjectSnapshot.ts +11 -6
  370. package/src/snapshot/fromSnapshot.ts +3 -0
  371. package/src/snapshot/index.ts +0 -10
  372. package/src/snapshot/reconcileArraySnapshot.ts +11 -6
  373. package/src/snapshot/reconcileFrozenSnapshot.ts +11 -6
  374. package/src/snapshot/reconcileModelSnapshot.ts +11 -6
  375. package/src/snapshot/reconcilePlainObjectSnapshot.ts +11 -6
  376. package/src/snapshot/reconcileSnapshot.ts +3 -0
  377. package/src/snapshot/registerDefaultReconcilers.ts +21 -0
  378. package/src/snapshot/registerDefaultSnapshotters.ts +21 -0
  379. package/src/tweaker/index.ts +0 -6
  380. package/src/tweaker/registerDefaultTweakers.ts +21 -0
  381. package/src/tweaker/tweak.ts +3 -0
  382. package/src/tweaker/tweakArray.ts +406 -401
  383. package/src/tweaker/tweakFrozen.ts +11 -6
  384. package/src/tweaker/tweakModel.ts +11 -6
  385. package/src/tweaker/tweakPlainObject.ts +288 -283
  386. package/src/types/objectBased/model.ts +6 -1
  387. package/src/types/objectBased/ref.ts +1 -1
  388. package/src/types/primitiveBased/primitives.ts +177 -166
  389. package/src/types/registerDefaultStandardTypeResolvers.ts +17 -0
  390. package/src/types/resolveTypeChecker.ts +7 -1
  391. package/dist/mobx-keystone.es.js +0 -7856
  392. package/dist/mobx-keystone.es.mjs +0 -7856
  393. package/src/dataModel/_BaseDataModel.ts +0 -15
  394. package/src/model/_BaseModel.ts +0 -15
@@ -0,0 +1,33 @@
1
+ import { RefIdResolver, RefOnResolvedValueChange } from "./core";
2
+ import type { RefConstructor } from "./Ref";
3
+ /**
4
+ * Custom reference options.
5
+ */
6
+ export interface RootRefOptions<T extends object> {
7
+ /**
8
+ * Must return the ID associated to the given target object, or `undefined` if it has no ID.
9
+ * If not provided it will try to get the reference id from the model `getRefId()` method.
10
+ *
11
+ * @param target Target object.
12
+ */
13
+ getId?: RefIdResolver;
14
+ /**
15
+ * What should happen when the resolved value changes.
16
+ *
17
+ * @param ref Reference object.
18
+ * @param newValue New resolved value.
19
+ * @param oldValue Old resolved value.
20
+ */
21
+ onResolvedValueChange?: RefOnResolvedValueChange<T>;
22
+ }
23
+ /**
24
+ * Creates a root ref to an object, which in its snapshot form has an id.
25
+ * A root ref will only be able to resolve references as long as both the Ref
26
+ * and the referenced object share a common root.
27
+ *
28
+ * @typeparam T Target object type.
29
+ * @param modelTypeId Unique model type id.
30
+ * @param [options] Root reference options.
31
+ * @returns A function that allows you to construct that type of root reference.
32
+ */
33
+ export declare const rootRef: <T extends object>(modelTypeId: string, options?: RootRefOptions<T> | undefined) => RefConstructor<T>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./rootStore";
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Registers a model / tree node object as a root store tree.
3
+ * Marking a model object as a root store tree serves several purposes:
4
+ * - It allows the `onAttachedToRootStore` hook (plus disposer) to be invoked on models once they become part of this tree.
5
+ * These hooks can be used for example to attach effects and serve as some sort of initialization.
6
+ * - It allows auto detachable references to work properly.
7
+ *
8
+ * @typeparam T Object type.
9
+ * @param node Node object to register as root store.
10
+ * @returns The same model object that was passed.
11
+ */
12
+ export declare const registerRootStore: <T extends object>(node: T) => T;
13
+ /**
14
+ * Unregisters an object to mark it as no longer a root store.
15
+ *
16
+ * @param node Node object to unregister as root store.
17
+ */
18
+ export declare const unregisterRootStore: (node: object) => void;
19
+ /**
20
+ * Checks if a given object is marked as a root store.
21
+ *
22
+ * @param node Object.
23
+ * @returns
24
+ */
25
+ export declare function isRootStore(node: object): boolean;
26
+ /**
27
+ * Gets the root store of a given tree child, or undefined if none.
28
+ *
29
+ * @typeparam T Root store type.
30
+ * @param node Target to find the root store for.
31
+ * @returns
32
+ */
33
+ export declare function getRootStore<T extends object>(node: object): T | undefined;
@@ -0,0 +1,47 @@
1
+ import type { Frozen, frozenKey } from "../frozen/Frozen";
2
+ import type { AnyModel } from "../model/BaseModel";
3
+ import type { modelIdKey, modelTypeKey } from "../model/metadata";
4
+ import type { ModelFromSnapshot, ModelToSnapshot } from "../modelShared/BaseModelShared";
5
+ import type { ArraySet, ObjectMap } from "../wrappers";
6
+ export declare type SnapshotOutOfObject<T> = {
7
+ [k in keyof T]: SnapshotOutOf<T[k]> extends infer R ? R : never;
8
+ };
9
+ export declare type SnapshotOutOfModel<M extends AnyModel> = ModelToSnapshot<M>;
10
+ export declare type SnapshotOutOfFrozen<F extends Frozen<any>> = {
11
+ [frozenKey]: true;
12
+ data: F["data"];
13
+ };
14
+ export interface SnapshotOutOfObjectMap<V> {
15
+ items: {
16
+ [k: string]: SnapshotOutOf<V>;
17
+ };
18
+ [modelTypeKey]?: string;
19
+ [modelIdKey]: string;
20
+ }
21
+ export interface SnapshotOutOfArraySet<V> {
22
+ items: SnapshotOutOf<V>[];
23
+ [modelTypeKey]?: string;
24
+ [modelIdKey]: string;
25
+ }
26
+ export declare type SnapshotOutOf<T> = T extends ObjectMap<infer V> ? SnapshotOutOfObjectMap<V> extends infer R ? R : never : T extends ArraySet<infer V> ? SnapshotOutOfArraySet<V> extends infer R ? R : never : T extends AnyModel ? SnapshotOutOfModel<T> extends infer R ? R : never : T extends Frozen<any> ? SnapshotOutOfFrozen<T> extends infer R ? R : never : T extends object ? SnapshotOutOfObject<T> extends infer R ? R : never : T;
27
+ export declare type SnapshotInOfObject<T> = {
28
+ [k in keyof T]: SnapshotInOf<T[k]> extends infer R ? R : never;
29
+ };
30
+ export declare type SnapshotInOfModel<M extends AnyModel> = ModelFromSnapshot<M>;
31
+ export declare type SnapshotInOfFrozen<F extends Frozen<any>> = {
32
+ [frozenKey]: true;
33
+ data: F["data"];
34
+ };
35
+ export interface SnapshotInOfObjectMap<V> {
36
+ items?: {
37
+ [k: string]: SnapshotOutOf<V>;
38
+ };
39
+ [modelTypeKey]?: string;
40
+ [modelIdKey]: string;
41
+ }
42
+ export interface SnapshotInOfArraySet<V> {
43
+ items?: SnapshotOutOf<V>[];
44
+ [modelTypeKey]?: string;
45
+ [modelIdKey]: string;
46
+ }
47
+ export declare type SnapshotInOf<T> = T extends ObjectMap<infer V> ? SnapshotInOfObjectMap<V> extends infer R ? R : never : T extends ArraySet<infer V> ? SnapshotInOfArraySet<V> extends infer R ? R : never : T extends AnyModel ? SnapshotInOfModel<T> extends infer R ? R : never : T extends Frozen<any> ? SnapshotInOfFrozen<T> extends infer R ? R : never : T extends object ? SnapshotInOfObject<T> extends infer R ? R : never : T;
@@ -0,0 +1,17 @@
1
+ import type { SnapshotInOf, SnapshotOutOf } from "./SnapshotOf";
2
+ /**
3
+ * Applies a full snapshot over an object, reconciling it with the current contents of the object.
4
+ *
5
+ * @typeparam T Object type.
6
+ * @param node Target object (model object, object or array).
7
+ * @param snapshot Snapshot to apply.
8
+ */
9
+ export declare function applySnapshot<T extends object>(node: T, snapshot: SnapshotInOf<T>): void;
10
+ /**
11
+ * Applies a full snapshot over an object, reconciling it with the current contents of the object.
12
+ *
13
+ * @typeparam T Object type.
14
+ * @param node Target object (model object, object or array).
15
+ * @param snapshot Snapshot to apply.
16
+ */
17
+ export declare function applySnapshot<T extends object>(node: T, snapshot: SnapshotOutOf<T>): void;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Clone options.
3
+ */
4
+ export interface CloneOptions {
5
+ /**
6
+ * Pass `true` to generate new internal ids for models rather than reusing them. (Default is `true`)
7
+ */
8
+ generateNewIds: boolean;
9
+ }
10
+ /**
11
+ * Clones an object by doing a `fromSnapshot(getSnapshot(value), { generateNewIds: true })`.
12
+ *
13
+ * @typeparam T Object type.
14
+ * @param node Object to clone.
15
+ * @param [options] Options.
16
+ * @returns The cloned object.
17
+ */
18
+ export declare function clone<T extends object>(node: T, options?: Partial<CloneOptions>): T;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import type { AnyDataModel } from "../dataModel/BaseDataModel";
2
+ import type { AnyModel } from "../model/BaseModel";
3
+ import type { ModelClass } from "../modelShared/BaseModelShared";
4
+ import type { AnyStandardType, TypeToData } from "../types/schemas";
5
+ import type { SnapshotInOf, SnapshotOutOf } from "./SnapshotOf";
6
+ /**
7
+ * From snapshot options.
8
+ */
9
+ export interface FromSnapshotOptions {
10
+ /**
11
+ * Pass `true` to generate new internal ids for models rather than reusing them. (Default is `false`)
12
+ */
13
+ generateNewIds: boolean;
14
+ }
15
+ /**
16
+ * Given a type deserializes a data structure from its snapshot form.
17
+ *
18
+ * @typeparam TType Object type.
19
+ * @param type Type.
20
+ * @param snapshot Snapshot, even if a primitive.
21
+ * @param options Options.
22
+ * @returns The deserialized object.
23
+ */
24
+ export declare function fromSnapshot<TType extends AnyStandardType | ModelClass<AnyModel> | ModelClass<AnyDataModel>>(type: TType, snapshot: SnapshotInOf<TypeToData<TType>>, options?: Partial<FromSnapshotOptions>): TypeToData<TType>;
25
+ /**
26
+ * Deserializes a data structure from its snapshot form.
27
+ *
28
+ * @typeparam T Object type.
29
+ * @param snapshot Snapshot, even if a primitive.
30
+ * @param options Options.
31
+ * @returns The deserialized object.
32
+ */
33
+ export declare function fromSnapshot<T>(snapshot: SnapshotInOf<T> | SnapshotOutOf<T>, options?: Partial<FromSnapshotOptions>): T;
34
+ export declare const observableOptions: {
35
+ deep: boolean;
36
+ };
@@ -0,0 +1,22 @@
1
+ import { AnyType, TypeToData } from "../types/schemas";
2
+ import type { SnapshotOutOf } from "./SnapshotOf";
3
+ /**
4
+ * Retrieves an immutable snapshot for a data structure.
5
+ * Since returned snapshots are immutable they will respect shallow equality, this is,
6
+ * if no changes are made then the snapshot will be kept the same.
7
+ *
8
+ * @typeparam T Object type.
9
+ * @param nodeOrPrimitive Data structure, including primtives.
10
+ * @returns The snapshot.
11
+ */
12
+ export declare function getSnapshot<T extends AnyType>(type: T, nodeOrPrimitive: TypeToData<T>): SnapshotOutOf<TypeToData<T>>;
13
+ /**
14
+ * Retrieves an immutable snapshot for a data structure.
15
+ * Since returned snapshots are immutable they will respect shallow equality, this is,
16
+ * if no changes are made then the snapshot will be kept the same.
17
+ *
18
+ * @typeparam T Object type.
19
+ * @param nodeOrPrimitive Data structure, including primtives.
20
+ * @returns The snapshot.
21
+ */
22
+ export declare function getSnapshot<T>(nodeOrPrimitive: T): SnapshotOutOf<T>;
@@ -0,0 +1,6 @@
1
+ export * from "./applySnapshot";
2
+ export * from "./clone";
3
+ export * from "./fromSnapshot";
4
+ export * from "./getSnapshot";
5
+ export * from "./onSnapshot";
6
+ export * from "./SnapshotOf";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { SnapshotOutOf } from "./SnapshotOf";
2
+ /**
3
+ * Listener function for onSnapshot.
4
+ */
5
+ export declare type OnSnapshotListener<T> = (sn: SnapshotOutOf<T>, prevSn: SnapshotOutOf<T>) => void;
6
+ /**
7
+ * Disposer function for onSnapshot.
8
+ */
9
+ export declare type OnSnapshotDisposer = () => void;
10
+ /**
11
+ * Adds a reaction that will trigger every time an snapshot changes.
12
+ *
13
+ * @typeparam T Object type.
14
+ * @param nodeOrFn Object to get the snapshot from or a function to get it.
15
+ * @param listener Function that will be triggered when the snapshot changes.
16
+ * @returns A disposer.
17
+ */
18
+ export declare function onSnapshot<T extends object>(nodeOrFn: T | (() => T), listener: OnSnapshotListener<T>): OnSnapshotDisposer;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ export declare const arrayActions: {
2
+ set: <T>(array: T[], index: number, value: any) => void;
3
+ delete: <T_1>(array: T_1[], index: number) => boolean;
4
+ setLength: <T_2>(array: T_2[], length: number) => void;
5
+ concat: <T_3>(array: T_3[], ...items: ConcatArray<T_3>[]) => T_3[];
6
+ copyWithin: <T_4>(array: T_4[], target: number, start: number, end?: number | undefined) => T_4[];
7
+ fill: <T_5>(array: T_5[], value: T_5, start?: number | undefined, end?: number | undefined) => T_5[];
8
+ pop: <T_6>(array: T_6[]) => T_6 | undefined;
9
+ push: <T_7>(array: T_7[], ...items: T_7[]) => number;
10
+ reverse: <T_8>(array: T_8[]) => T_8[];
11
+ shift: <T_9>(array: T_9[]) => T_9 | undefined;
12
+ slice: <T_10>(array: T_10[], start?: number | undefined, end?: number | undefined) => T_10[];
13
+ sort: <T_11>(array: T_11[], compareFn?: ((a: T_11, b: T_11) => number) | undefined) => T_11[];
14
+ splice: (<T_12>(array: T_12[], start: number, deleteCount?: number | undefined) => T_12[]) | (<T_13>(array: T_13[], start: number, deleteCount: number, ...items: T_13[]) => T_13[]);
15
+ unshift: <T_14>(array: T_14[], ...items: T_14[]) => number;
16
+ swap: <T_15>(array: T_15[], index1: number, index2: number) => boolean;
17
+ create: <T_16>(data: T_16[]) => T_16[];
18
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./arrayActions";
2
+ export * from "./objectActions";
3
+ export * from "./standaloneActions";
@@ -0,0 +1,7 @@
1
+ export declare const objectActions: {
2
+ set: <T extends object, K extends keyof T>(target: T, key: K, value: T[K]) => void;
3
+ assign: <T_1 extends object>(target: T_1, partialObject: Partial<T_1>) => void;
4
+ delete: <T_2 extends object, K_1 extends keyof T_2>(target: T_2, key: K_1) => boolean;
5
+ call: <T_3 extends object, K_2 extends keyof T_3>(target: T_3, methodName: K_2, ...args: T_3[K_2] extends (...args: any[]) => any ? Parameters<T_3[K_2]> : never) => T_3[K_2] extends (...args: any[]) => any ? ReturnType<T_3[K_2]> : never;
6
+ create: <T_4 extends object>(data: T_4) => T_4;
7
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Creates a standalone action. A standalone action must always take an existing tree node as first argument.
3
+ *
4
+ * @param actionName Unique action name.
5
+ * @param fn Function.
6
+ * @returns The function as an standalone action.
7
+ */
8
+ export declare function standaloneAction<FN extends (target: any, ...args: any[]) => any>(actionName: string, fn: FN): FN;
9
+ /**
10
+ * Creates a standalone flow. A standalone flow must always take an existing tree node as first argument.
11
+ *
12
+ * @param actionName Unique action name.
13
+ * @param fn Function.
14
+ * @returns The function as an standalone flow.
15
+ */
16
+ export declare function standaloneFlow<FN extends (target: any, ...args: any[]) => Generator<any, any, any>>(actionName: string, fn: FN): FN;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { ModelPropTransform } from "../modelShared/prop";
2
+ export declare const objectToMapTransform: <T>() => ModelPropTransform<Record<string, T>, Map<string, T>>;
3
+ export declare const arrayToMapTransform: <K, V>() => ModelPropTransform<[K, V][], Map<K, V>>;
@@ -0,0 +1,2 @@
1
+ import type { ModelPropTransform } from "../modelShared/prop";
2
+ export declare const arrayToSetTransform: <T>() => ModelPropTransform<T[], Set<T>>;
@@ -0,0 +1,2 @@
1
+ import type { ModelPropTransform } from "../modelShared/prop";
2
+ export declare const stringToBigIntTransform: () => ModelPropTransform<string, bigint>;
@@ -0,0 +1,3 @@
1
+ import type { ModelPropTransform } from "../modelShared/prop";
2
+ export declare const timestampToDateTransform: () => ModelPropTransform<number, Date>;
3
+ export declare const isoStringToDateTransform: () => ModelPropTransform<string, Date>;
@@ -0,0 +1,4 @@
1
+ export * from "./asMap";
2
+ export * from "./asSet";
3
+ export * from "./bigint";
4
+ export * from "./date";
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Deeply compares two values.
3
+ *
4
+ * Supported values are:
5
+ * - Primitives
6
+ * - Boxed observables
7
+ * - Objects, observable objects
8
+ * - Arrays, observable arrays
9
+ * - Typed arrays
10
+ * - Maps, observable maps
11
+ * - Sets, observable sets
12
+ * - Tree nodes (optimized by using snapshot comparison internally)
13
+ *
14
+ * Note that in the case of models the result will be false if their model IDs are different.
15
+ *
16
+ * @param a First value to compare.
17
+ * @param b Second value to compare.
18
+ * @returns `true` if they are the equivalent, `false` otherwise.
19
+ */
20
+ export declare function deepEquals(a: any, b: any): boolean;
@@ -0,0 +1,70 @@
1
+ import type { Path } from "../parent/pathTypes";
2
+ /**
3
+ * A class with the implementationm of draft.
4
+ * Use `draft` to create an instance of this class.
5
+ *
6
+ * @typeparam T Data type.
7
+ */
8
+ export declare class Draft<T extends object> {
9
+ /**
10
+ * Draft data object.
11
+ */
12
+ readonly data: T;
13
+ /**
14
+ * Commits current draft changes to the original object.
15
+ */
16
+ commit(): void;
17
+ /**
18
+ * Partially commits current draft changes to the original object.
19
+ * If the path cannot be resolved in either the draft or the original object it will throw.
20
+ * Note that model IDs are checked to be the same when resolving the paths.
21
+ *
22
+ * @param path Path to commit.
23
+ */
24
+ commitByPath(path: Path): void;
25
+ /**
26
+ * Resets the draft to be an exact copy of the current state of the original object.
27
+ */
28
+ reset(): void;
29
+ /**
30
+ * Partially resets current draft changes to be the same as the original object.
31
+ * If the path cannot be resolved in either the draft or the original object it will throw.
32
+ * Note that model IDs are checked to be the same when resolving the paths.
33
+ *
34
+ * @param path Path to reset.
35
+ */
36
+ resetByPath(path: Path): void;
37
+ /**
38
+ * Returns `true` if the draft has changed compared to the original object, `false` otherwise.
39
+ */
40
+ get isDirty(): boolean;
41
+ /**
42
+ * Returns `true` if the value at the given path of the draft has changed compared to the original object.
43
+ * If the path cannot be resolved in the draft it will throw.
44
+ * If the path cannot be resolved in the original object it will return `true`.
45
+ * Note that model IDs are checked to be the same when resolving the paths.
46
+ *
47
+ * @param path Path to check.
48
+ */
49
+ isDirtyByPath(path: Path): boolean;
50
+ /**
51
+ * Original data object.
52
+ */
53
+ readonly originalData: T;
54
+ private get originalSnapshot();
55
+ /**
56
+ * Creates an instance of Draft.
57
+ * Do not use directly, use `draft` instead.
58
+ *
59
+ * @param original
60
+ */
61
+ constructor(original: T);
62
+ }
63
+ /**
64
+ * Creates a draft copy of a tree node and all its children.
65
+ *
66
+ * @typeparam T Data type.
67
+ * @param original Original node.
68
+ * @returns The draft object.
69
+ */
70
+ export declare function draft<T extends object>(original: T): Draft<T>;
@@ -0,0 +1,3 @@
1
+ export * from "./deepEquals";
2
+ export * from "./draft";
3
+ export * from "./sandbox";
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Returns the sandbox manager of a node, or `undefined` if none.
3
+ *
4
+ * @param node Node to check.
5
+ * @returns The sandbox manager of a node, or `undefined` if none.
6
+ */
7
+ export declare function getNodeSandboxManager(node: object): SandboxManager | undefined;
8
+ /**
9
+ * Returns if a given node is a sandboxed node.
10
+ *
11
+ * @param node Node to check.
12
+ * @returns `true` if it is sandboxed, `false`
13
+ */
14
+ export declare function isSandboxedNode(node: object): boolean;
15
+ /**
16
+ * Callback function for `SandboxManager.withSandbox`.
17
+ */
18
+ export declare type WithSandboxCallback<T extends readonly [object, ...object[]], R> = (...nodes: T) => boolean | {
19
+ commit: boolean;
20
+ return: R;
21
+ };
22
+ /**
23
+ * Manager class returned by `sandbox` that allows you to make changes to a sandbox copy of the
24
+ * original subtree and apply them to the original subtree or reject them.
25
+ */
26
+ export declare class SandboxManager {
27
+ private readonly subtreeRoot;
28
+ /**
29
+ * The sandbox copy of the original subtree.
30
+ */
31
+ private readonly subtreeRootClone;
32
+ /**
33
+ * The internal disposer.
34
+ */
35
+ private disposer;
36
+ /**
37
+ * The internal `withSandbox` patch recorder. If `undefined`, no `withSandbox` call is being
38
+ * executed.
39
+ */
40
+ private withSandboxPatchRecorder;
41
+ /**
42
+ * Function from `readonlyMiddleware` that will allow actions to be started inside the provided
43
+ * code block on a readonly node.
44
+ */
45
+ private allowWrite;
46
+ /**
47
+ * Whether changes made in the sandbox are currently being committed to the original subtree.
48
+ */
49
+ private isCommitting;
50
+ /**
51
+ * Creates an instance of `SandboxManager`.
52
+ * Do not use directly, use `sandbox` instead.
53
+ *
54
+ * @param subtreeRoot Subtree root target object.
55
+ */
56
+ constructor(subtreeRoot: object);
57
+ /**
58
+ * Executes `fn` with sandbox copies of the elements of `nodes`. The changes made to the sandbox
59
+ * in `fn` can be accepted, i.e. applied to the original subtree, or rejected.
60
+ *
61
+ * @typeparam T Object type.
62
+ * @typeparam R Return type.
63
+ * @param nodes Tuple of objects for which to obtain sandbox copies.
64
+ * @param fn Function that is called with sandbox copies of the elements of `nodes`. Any changes
65
+ * made to the sandbox are applied to the original subtree when `fn` returns `true` or
66
+ * `{ commit: true, ... }`. When `fn` returns `false` or `{ commit: false, ... }` the changes made
67
+ * to the sandbox are rejected.
68
+ * @returns Value of type `R` when `fn` returns an object of type `{ commit: boolean; return: R }`
69
+ * or `void` when `fn` returns a boolean.
70
+ */
71
+ withSandbox<T extends readonly [object, ...object[]], R = void>(nodes: T, fn: WithSandboxCallback<T, R>): R;
72
+ /**
73
+ * Disposes of the sandbox.
74
+ */
75
+ dispose(): void;
76
+ private prepareSandboxChanges;
77
+ }
78
+ /**
79
+ * Creates a sandbox.
80
+ *
81
+ * @param subtreeRoot Subtree root target object.
82
+ * @returns A `SandboxManager` which allows you to manage the sandbox operations and dispose of the
83
+ * sandbox.
84
+ */
85
+ export declare function sandbox(subtreeRoot: object): SandboxManager;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Checks if a given object is now a tree node.
3
+ *
4
+ * @param value Value to check.
5
+ * @returns true if it is a tree node, false otherwise.
6
+ */
7
+ export declare function isTreeNode(value: unknown): value is object;
8
+ /**
9
+ * Asserts a given object is now a tree node, or throws otherwise.
10
+ *
11
+ * @param value Value to check.
12
+ * @param argName Argument name, part of the thrown error description.
13
+ */
14
+ export declare function assertIsTreeNode(value: unknown, argName?: string): asserts value is object;
@@ -0,0 +1,2 @@
1
+ export * from "./core";
2
+ export * from "./tweak";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { AnyStandardType, TypeToData } from "../types/schemas";
2
+ /**
3
+ * Turns an object (array, plain object) into a tree node,
4
+ * which then can accept calls to `getParent`, `getSnapshot`, etc.
5
+ * If a tree node is passed it will return the passed argument directly.
6
+ * Additionally this method will use the type passed to check the value
7
+ * conforms to the type when model auto type checking is enabled.
8
+ *
9
+ * @param type Type checker.
10
+ * @param value Object to turn into a tree node.
11
+ * @returns The object as a tree node.
12
+ */
13
+ export declare function toTreeNode<TType extends AnyStandardType, V extends TypeToData<TType>>(type: TType, value: V): V;
14
+ /**
15
+ * Turns an object (array, plain object) into a tree node,
16
+ * which then can accept calls to `getParent`, `getSnapshot`, etc.
17
+ * If a tree node is passed it will return the passed argument directly.
18
+ *
19
+ * @param value Object to turn into a tree node.
20
+ * @returns The object as a tree node.
21
+ */
22
+ export declare function toTreeNode<T extends object>(value: T): T;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function withoutTypeChecking(fn: () => void): void;
2
+ export declare function isTypeCheckingAllowed(): boolean;