mobx-keystone 2.1.0 → 2.3.0

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 (83) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -1
  3. package/dist/mobx-keystone.esm.js +555 -516
  4. package/dist/mobx-keystone.esm.mjs +555 -516
  5. package/dist/mobx-keystone.umd.js +558 -519
  6. package/dist/types/actionMiddlewares/undoMiddleware.d.ts +2 -10
  7. package/dist/types/modelShared/modelDecorator.d.ts +5 -2
  8. package/dist/types/modelShared/prop.d.ts +42 -29
  9. package/dist/types/ref/Ref.d.ts +1 -4
  10. package/dist/types/snapshot/SnapshotOf.d.ts +4 -4
  11. package/dist/types/snapshot/applySnapshot.d.ts +1 -1
  12. package/dist/types/snapshot/fromSnapshot.d.ts +2 -2
  13. package/dist/types/snapshot/getSnapshot.d.ts +1 -1
  14. package/dist/types/types/SnapshotTypeMismatchError.d.ts +3 -1
  15. package/dist/types/types/index.d.ts +1 -0
  16. package/dist/types/types/modelTypeMatching.d.ts +1 -0
  17. package/dist/types/types/schemas.d.ts +41 -37
  18. package/dist/types/types/tProp.d.ts +12 -6
  19. package/dist/types/types/types.d.ts +6 -6
  20. package/dist/types/types/utility/typeToStoredData.d.ts +14 -10
  21. package/dist/types/types/utility/typesCodecCore.d.ts +3 -0
  22. package/dist/types/utils/ModelPool.d.ts +0 -1
  23. package/dist/types/utils/types.d.ts +6 -0
  24. package/dist/types/wrappers/ArraySet.d.ts +1 -0
  25. package/package.json +13 -11
  26. package/src/action/modelFlow.ts +35 -66
  27. package/src/actionMiddlewares/actionTrackingMiddleware.ts +41 -71
  28. package/src/actionMiddlewares/transactionMiddleware.ts +1 -1
  29. package/src/actionMiddlewares/undoMiddleware.ts +16 -22
  30. package/src/context/context.ts +15 -36
  31. package/src/dataModel/utils.ts +5 -28
  32. package/src/deepChange/onDeepChange.ts +44 -126
  33. package/src/model/BaseModel.ts +1 -1
  34. package/src/model/utils.ts +5 -10
  35. package/src/modelShared/modelDecorator.ts +13 -10
  36. package/src/modelShared/modelInfo.ts +75 -0
  37. package/src/modelShared/prop.ts +115 -111
  38. package/src/modelShared/sharedInternalModel.ts +2 -2
  39. package/src/parent/arrayPaths.ts +1 -4
  40. package/src/parent/path.ts +0 -10
  41. package/src/patch/patchRecorder.ts +13 -28
  42. package/src/ref/core.ts +6 -19
  43. package/src/rootStore/rootStore.ts +1 -3
  44. package/src/snapshot/SnapshotOf.ts +24 -48
  45. package/src/snapshot/applySnapshot.ts +1 -1
  46. package/src/snapshot/fromSnapshot.ts +10 -3
  47. package/src/snapshot/getSnapshot.ts +1 -1
  48. package/src/snapshot/internal.ts +0 -2
  49. package/src/snapshot/reconcileModelSnapshot.ts +5 -3
  50. package/src/snapshot/reconcilePlainObjectSnapshot.ts +3 -1
  51. package/src/treeUtils/draft.ts +6 -1
  52. package/src/treeUtils/sandbox.ts +10 -7
  53. package/src/tweaker/tweakArray.ts +20 -50
  54. package/src/tweaker/tweakPlainObject.ts +9 -15
  55. package/src/types/SnapshotTypeMismatchError.ts +3 -1
  56. package/src/types/arrayBased/typesArray.ts +13 -19
  57. package/src/types/arrayBased/typesTuple.ts +16 -25
  58. package/src/types/createCachedTypeCheck.ts +17 -30
  59. package/src/types/index.ts +1 -0
  60. package/src/types/modelTypeMatching.ts +276 -0
  61. package/src/types/objectBased/typesDataModelData.ts +7 -8
  62. package/src/types/objectBased/typesModel.ts +23 -6
  63. package/src/types/objectBased/typesObject.ts +11 -15
  64. package/src/types/objectBased/typesRecord.ts +11 -15
  65. package/src/types/objectBased/typesRef.ts +23 -4
  66. package/src/types/schemas.ts +59 -71
  67. package/src/types/tProp.ts +29 -29
  68. package/src/types/utility/typeToStoredData.ts +22 -21
  69. package/src/types/utility/typesCodecCore.ts +8 -1
  70. package/src/types/utility/typesCodecSupport.ts +16 -10
  71. package/src/types/utility/typesMap.ts +43 -51
  72. package/src/types/utility/typesOr.ts +38 -8
  73. package/src/types/utility/typesRefinement.ts +7 -8
  74. package/src/types/utility/typesSkipCheck.ts +7 -8
  75. package/src/types/utility/typesTag.ts +7 -8
  76. package/src/utils/ModelPool.ts +1 -18
  77. package/src/utils/decorators.ts +5 -5
  78. package/src/utils/index.ts +1 -20
  79. package/src/utils/types.ts +5 -0
  80. package/src/wrappers/ArraySet.ts +27 -14
  81. package/src/wrappers/ObjectMap.ts +1 -6
  82. package/src/wrappers/asMap.ts +1 -21
  83. package/src/wrappers/asSet.ts +0 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Change Log
2
2
 
3
+ ## 2.3.0
4
+
5
+ - Fixed typed `fromSnapshot(Type, snapshot)` silently creating an unrelated model when a model snapshot's `$modelType` names a model that is neither the expected one nor a subclass of it (#590). It now throws `SnapshotTypeMismatchError` (whatever `modelAutoTypeChecking` is set to), also for models nested in typed props/containers, `types.ref` snapshots and `applySnapshot` into typed props. With `modelAutoTypeChecking` on, such a mismatch in a typed prop now throws `SnapshotTypeMismatchError` instead of a `TypeCheckError`.
6
+ - Unions of model types now accept subclass snapshots for a base model branch, preferring the branch of the snapshot's own model when there is one.
7
+ - Fixed `types.model(...)` and `types.ref(...)` type checking rejecting valid instances after hot reloading re-registered a model.
8
+
9
+ ## 2.2.0
10
+
11
+ - Now requires TypeScript 5.4 or newer (the types use the built-in `NoInfer`).
12
+ - Faster TypeScript type-checking of models and runtime types: the snapshot, model data and `types.object` type mappings now create far fewer type instantiations (about 35% fewer in a typical model-heavy project), with no change to the resulting types. `tProp` defaults, `fromSnapshot(type, snapshot)`, `getSnapshot(type, value)` and `applySnapshot` no longer infer their type parameter from the data / snapshot argument, which makes those calls much cheaper to type-check (e.g. about 40% fewer instantiations for a typed `fromSnapshot` call). The `@model` decorator also no longer computes the creation data type of the decorated class. A typed `fromSnapshot(type, snapshot)` call now also accepts the output snapshot type of `type` (which must always round-trip, as with `applySnapshot` and the untyped `fromSnapshot(snapshot)`), so round trips such as `fromSnapshot(M, getSnapshot(m))` no longer compare the output and input snapshot types (about 65% cheaper to type-check).
13
+ - Smaller and faster declaration (`.d.ts`) emit for exported model classes: the types of `idProp` and `tProp` properties (`TypedModelIdProp`, `TypedMaybeOptionalModelProp`, `TypedOptionalModelProp`) and `CodecFromEncoded` are now exported, so emitted declarations reference them by name instead of expanding them inline.
14
+ - Fixed the types of `tProp` codec props (e.g. `tProp(types.dateAsTimestamp)`) after `.withSetter()`, `.withSnapshotProcessor()` or `.withTransform()`: `$` and snapshots now use the encoded type (e.g. `number`) instead of the runtime type (e.g. `Date`). The new `ModelPropWithSetter`, `ModelPropWithSnapshotProcessor` and `ModelPropWithTransform` types describe the props these modifiers return.
15
+ - Fixed `applySnapshot` throwing when the snapshot adds an object under a key named like an `Object.prototype` member (e.g. `toString` or `constructor`).
16
+ - Fixed `Draft`'s `isDirty` not being cached and `commit` / `reset` not running as MobX actions with MobX 6.
17
+ - `fromSnapshot` (and `cloneTreeValue` for plain objects / arrays) now reports a clear error when the snapshot contains tree nodes, instead of a generic "unsupported snapshot".
18
+ - Fixed `ArraySet` set operations (`union`, `intersection`, `isSubsetOf`, etc.) throwing on runtimes without the native ES2025 `Set` methods.
19
+
3
20
  ## 2.1.0
4
21
 
5
22
  - [BREAKING CHANGE] `UndoStore` keeps undo/redo events as frozen data, making recording ~4x faster and undo/redo ~3x faster:
package/README.md CHANGED
@@ -136,7 +136,7 @@ This library requires a modern JavaScript environment with support for:
136
136
 
137
137
  In practice, this covers current browsers and Node.js releases, but not Internet Explorer.
138
138
 
139
- TypeScript 5.0 or newer is recommended so you can use standard decorators. Legacy decorators remain supported by `mobx-keystone`; see the [installation guide](https://mobx-keystone.js.org/installation) for the required compiler configuration and the MobX 7 compatibility note.
139
+ When using TypeScript, version 5.4 or newer is required. Legacy decorators remain supported by `mobx-keystone`; see the [installation guide](https://mobx-keystone.js.org/installation) for the required compiler configuration and the MobX 7 compatibility note.
140
140
 
141
141
  ## Installation
142
142