Skip to content

Commit

Permalink
upgrade to ts5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergonz committed Jun 22, 2024
1 parent aea9bc3 commit f791a30
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.10.2

- Fixed some types so set transformations are compatible with TypeSscript 5.5 once more.

## 1.10.1

- Some more minor optimizations, for example creating models should be around 10% faster now.
Expand Down
2 changes: 1 addition & 1 deletion apps/benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"@types/benchmark": "^2.1.5",
"cross-env": "^7.0.3",
"shx": "^0.3.4",
"typescript": "^5.4.5"
"typescript": "^5.5.2"
}
}
2 changes: 1 addition & 1 deletion apps/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@types/uuid": "^10.0.0",
"raw-loader": "^4.0.2",
"shx": "^0.3.4",
"typescript": "^5.4.5"
"typescript": "^5.5.2"
},
"browserslist": {
"production": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"prettier": "^3.3.2",
"prettier-plugin-organize-imports": "^3.2.4",
"turbo": "^2.0.4",
"typescript": "^5.4.5",
"typescript": "^5.5.2",
"typescript-eslint": "^7.13.1"
},
"packageManager": "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-keystone",
"version": "1.10.1",
"version": "1.10.2",
"description": "A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more",
"keywords": [
"mobx",
Expand Down Expand Up @@ -86,7 +86,7 @@
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"typedoc": "^0.26.0",
"typescript": "^5.4.5",
"typescript": "^5.5.2",
"vite": "^5.3.1"
},
"dependencies": {
Expand Down
5 changes: 3 additions & 2 deletions packages/lib/src/transforms/asSet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ObservableSet } from "mobx"
import type { ModelPropTransform } from "../modelShared/prop"
import { asSet } from "../wrappers/asSet"

const _arrayToSetTransform: ModelPropTransform<Array<unknown>, Set<unknown>> = {
const _arrayToSetTransform: ModelPropTransform<Array<unknown>, ObservableSet<unknown>> = {
transform({ originalValue: arr, cachedTransformedValue: cachedSet }) {
return cachedSet ?? asSet(arr)
},
Expand All @@ -14,4 +15,4 @@ const _arrayToSetTransform: ModelPropTransform<Array<unknown>, Set<unknown>> = {
}

export const arrayToSetTransform = <T>() =>
_arrayToSetTransform as ModelPropTransform<Array<T>, Set<T>>
_arrayToSetTransform as ModelPropTransform<Array<T>, Set<T> | ObservableSet<T>>
10 changes: 8 additions & 2 deletions packages/lib/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ export function assertIsObservableArray(
/**
* @internal
*/
export function assertIsMap(value: unknown, argName: string): asserts value is Map<any, any> {
export function assertIsMap(
value: unknown,
argName: string
): asserts value is Map<any, any> | ObservableMap {
if (!isMap(value)) {
throw failure(`${argName} must be a map`)
}
Expand All @@ -205,7 +208,10 @@ export function assertIsMap(value: unknown, argName: string): asserts value is M
/**
* @internal
*/
export function assertIsSet(value: unknown, argName: string): asserts value is Set<any> {
export function assertIsSet(
value: unknown,
argName: string
): asserts value is Set<any> | ObservableSet {
if (!isSet(value)) {
throw failure(`${argName} must be a set`)
}
Expand Down
35 changes: 35 additions & 0 deletions packages/lib/src/wrappers/ArraySet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,41 @@ export class ArraySet<V>
}

readonly [Symbol.toStringTag] = "ArraySet"

union<U>(other: ReadonlySetLike<U>): Set<V | U> {
const s = new Set(this)
return s.union(other)
}

intersection<U>(other: ReadonlySetLike<U>): Set<V & U> {
const s = new Set(this)
return s.intersection(other)
}

difference<U>(other: ReadonlySetLike<U>): Set<V> {
const s = new Set(this)
return s.difference(other)
}

symmetricDifference<U>(other: ReadonlySetLike<U>): Set<V | U> {
const s = new Set(this)
return s.symmetricDifference(other)
}

isSubsetOf(other: ReadonlySetLike<unknown>): boolean {
const s = new Set(this)
return s.isSubsetOf(other)
}

isSupersetOf(other: ReadonlySetLike<unknown>): boolean {
const s = new Set(this)
return s.isSupersetOf(other)
}

isDisjointFrom(other: ReadonlySetLike<unknown>): boolean {
const s = new Set(this)
return s.isDisjointFrom(other)
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/wrappers/asSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function asSet<T>(array: Array<T>): ObservableSet<T> & { dataObject: type
*
* @param set
*/
export function setToArray<T>(set: Set<T>): Array<T> {
export function setToArray<T>(set: Set<T> | ObservableSet<T>): Array<T> {
assertIsSet(set, "set")

const dataObject = (set as Set<T> & { dataObject: Array<T> }).dataObject
Expand Down
8 changes: 4 additions & 4 deletions packages/lib/test/model/propTransform.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { set, toJS } from "mobx"
import { ObservableSet, set, toJS } from "mobx"
import { assert, _ } from "spec.ts"
import {
arrayToMapTransform,
Expand Down Expand Up @@ -309,7 +309,7 @@ test("prop with arr->set transform", () => {
set: set1,
})

assert(t.set, _ as Set<number>)
assert(t.set, _ as Set<number> | ObservableSet<number>)
expect(t.set.has(1)).toBe(true)
expect(t.set).not.toBe(set1) // should not be cached
expect(t.set).toBe(t.set) // should be cached
Expand All @@ -331,7 +331,7 @@ test("prop with arr->set transform", () => {

t.setSet(set2)

assert(t.set, _ as Set<number>)
assert(t.set, _ as Set<number> | ObservableSet<number>)
expect(t.set.has(2)).toBe(true)
expect(t.set).not.toBe(set2) // should not be cached
expect(t.set).toBe(t.set) // should be cached
Expand All @@ -340,7 +340,7 @@ test("prop with arr->set transform", () => {
const tsn = getSnapshot(t)
assert(tsn.set, _ as Array<number>)
const tfsn = fromSnapshot(T, tsn)
assert(tfsn.set, _ as Set<number>)
assert(tfsn.set, _ as Set<number> | ObservableSet<number>)
expect(toJS(t.$.set)).toEqual([2])

t.setNumberArr([4])
Expand Down
2 changes: 1 addition & 1 deletion packages/mobx-keystone-yjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"spec.ts": "^1.1.3",
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"typescript": "^5.5.2",
"vite": "^5.3.1"
},
"dependencies": {
Expand Down
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7493,7 +7493,7 @@ __metadata:
mobx-state-tree: "npm:^6.0.0"
shx: "npm:^0.3.4"
tslib: "npm:^2.6.3"
typescript: "npm:^5.4.5"
typescript: "npm:^5.5.2"
peerDependencies:
mobx: ^6.0.0
languageName: unknown
Expand Down Expand Up @@ -16375,7 +16375,7 @@ __metadata:
ts-jest: "npm:^29.1.5"
ts-node: "npm:^10.9.2"
tslib: "npm:^2.6.3"
typescript: "npm:^5.4.5"
typescript: "npm:^5.5.2"
vite: "npm:^5.3.1"
peerDependencies:
mobx: ^6.0.0 || ^5.0.0 || ^4.0.0
Expand Down Expand Up @@ -16411,7 +16411,7 @@ __metadata:
ts-toolbelt: "npm:^9.6.0"
tslib: "npm:^2.6.3"
typedoc: "npm:^0.26.0"
typescript: "npm:^5.4.5"
typescript: "npm:^5.5.2"
vite: "npm:^5.3.1"
peerDependencies:
mobx: ^6.0.0 || ^5.0.0 || ^4.0.0
Expand Down Expand Up @@ -19868,7 +19868,7 @@ __metadata:
prettier: "npm:^3.3.2"
prettier-plugin-organize-imports: "npm:^3.2.4"
turbo: "npm:^2.0.4"
typescript: "npm:^5.4.5"
typescript: "npm:^5.5.2"
typescript-eslint: "npm:^7.13.1"
yjs: "npm:^13.6.18"
languageName: unknown
Expand Down Expand Up @@ -20469,7 +20469,7 @@ __metadata:
react-dom: "npm:^18.3.1"
remotedev: "npm:^0.2.9"
shx: "npm:^0.3.4"
typescript: "npm:^5.4.5"
typescript: "npm:^5.5.2"
utf-8-validate: "npm:^5.0.10"
y-webrtc: "npm:^10.3.0"
peerDependencies:
Expand Down Expand Up @@ -22023,23 +22023,23 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:^5.0.0, typescript@npm:^5.0.4, typescript@npm:^5.4.5":
version: 5.4.5
resolution: "typescript@npm:5.4.5"
"typescript@npm:^5.0.0, typescript@npm:^5.0.4, typescript@npm:^5.5.2":
version: 5.5.2
resolution: "typescript@npm:5.5.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/2954022ada340fd3d6a9e2b8e534f65d57c92d5f3989a263754a78aba549f7e6529acc1921913560a4b816c46dce7df4a4d29f9f11a3dc0d4213bb76d043251e
checksum: 10c0/8ca39b27b5f9bd7f32db795045933ab5247897660627251e8254180b792a395bf061ea7231947d5d7ffa5cb4cc771970fd4ef543275f9b559f08c9325cccfce3
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A^5.0.0#optional!builtin<compat/typescript>, typescript@patch:typescript@npm%3A^5.0.4#optional!builtin<compat/typescript>, typescript@patch:typescript@npm%3A^5.4.5#optional!builtin<compat/typescript>":
version: 5.4.5
resolution: "typescript@patch:typescript@npm%3A5.4.5#optional!builtin<compat/typescript>::version=5.4.5&hash=5adc0c"
"typescript@patch:typescript@npm%3A^5.0.0#optional!builtin<compat/typescript>, typescript@patch:typescript@npm%3A^5.0.4#optional!builtin<compat/typescript>, typescript@patch:typescript@npm%3A^5.5.2#optional!builtin<compat/typescript>":
version: 5.5.2
resolution: "typescript@patch:typescript@npm%3A5.5.2#optional!builtin<compat/typescript>::version=5.5.2&hash=b45daf"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/db2ad2a16ca829f50427eeb1da155e7a45e598eec7b086d8b4e8ba44e5a235f758e606d681c66992230d3fc3b8995865e5fd0b22a2c95486d0b3200f83072ec9
checksum: 10c0/6721ac8933a70c252d7b640b345792e103d881811ff660355617c1836526dbb71c2044e2e77a8823fb3570b469f33276875a4cab6d3c4de4ae7d7ee1c3074ae4
languageName: node
linkType: hard

Expand Down

0 comments on commit f791a30

Please sign in to comment.