teamplay 0.1.5 → 0.1.7
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.
- package/orm/Cache.js +4 -0
- package/orm/Doc.js +1 -0
- package/orm/Query.js +1 -0
- package/orm/Reaction.js +1 -0
- package/orm/Value.js +1 -0
- package/package.json +9 -9
- package/utils/MockFinalizationRegistry.js +66 -0
- package/utils/MockWeakRef.js +16 -0
- package/CHANGELOG.md +0 -62
package/orm/Cache.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import FinalizationRegistry from '../utils/MockFinalizationRegistry.js'
|
|
2
|
+
import WeakRef, { destroyMockWeakRef } from '../utils/MockWeakRef.js'
|
|
3
|
+
|
|
1
4
|
export default class Cache {
|
|
2
5
|
constructor () {
|
|
3
6
|
this.cache = new Map()
|
|
@@ -20,6 +23,7 @@ export default class Cache {
|
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
delete (key) {
|
|
26
|
+
destroyMockWeakRef(this.cache.get(key)) // TODO: remove this when WeakRef is available in RN
|
|
23
27
|
this.cache.delete(key)
|
|
24
28
|
}
|
|
25
29
|
|
package/orm/Doc.js
CHANGED
|
@@ -2,6 +2,7 @@ import { isObservable, observable } from '@nx-js/observer-util'
|
|
|
2
2
|
import { set as _set, del as _del } from './dataTree.js'
|
|
3
3
|
import { SEGMENTS } from './Signal.js'
|
|
4
4
|
import { getConnection, fetchOnly } from './connection.js'
|
|
5
|
+
import FinalizationRegistry from '../utils/MockFinalizationRegistry.js'
|
|
5
6
|
|
|
6
7
|
const ERROR_ON_EXCESSIVE_UNSUBSCRIBES = false
|
|
7
8
|
|
package/orm/Query.js
CHANGED
|
@@ -4,6 +4,7 @@ import { SEGMENTS } from './Signal.js'
|
|
|
4
4
|
import getSignal from './getSignal.js'
|
|
5
5
|
import { getConnection, fetchOnly } from './connection.js'
|
|
6
6
|
import { docSubscriptions } from './Doc.js'
|
|
7
|
+
import FinalizationRegistry from '../utils/MockFinalizationRegistry.js'
|
|
7
8
|
|
|
8
9
|
const ERROR_ON_EXCESSIVE_UNSUBSCRIBES = false
|
|
9
10
|
export const PARAMS = Symbol('query params')
|
package/orm/Reaction.js
CHANGED
|
@@ -2,6 +2,7 @@ import { observe, unobserve } from '@nx-js/observer-util'
|
|
|
2
2
|
import { SEGMENTS } from './Signal.js'
|
|
3
3
|
import { set as _set, del as _del } from './dataTree.js'
|
|
4
4
|
import { LOCAL } from './Value.js'
|
|
5
|
+
import FinalizationRegistry from '../utils/MockFinalizationRegistry.js'
|
|
5
6
|
|
|
6
7
|
// this is `let` to be able to directly change it if needed in tests or in the app
|
|
7
8
|
export let DELETION_DELAY = 0 // eslint-disable-line prefer-const
|
package/orm/Value.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teamplay",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Full-stack signals ORM with multiplayer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -23,18 +23,18 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@nx-js/observer-util": "^4.1.3",
|
|
26
|
-
"@teamplay/backend": "^0.1.
|
|
27
|
-
"@teamplay/cache": "^0.1.
|
|
28
|
-
"@teamplay/channel": "^0.1.
|
|
29
|
-
"@teamplay/debug": "^0.1.
|
|
30
|
-
"@teamplay/schema": "^0.1.
|
|
31
|
-
"@teamplay/utils": "^0.1.
|
|
26
|
+
"@teamplay/backend": "^0.1.7",
|
|
27
|
+
"@teamplay/cache": "^0.1.7",
|
|
28
|
+
"@teamplay/channel": "^0.1.7",
|
|
29
|
+
"@teamplay/debug": "^0.1.7",
|
|
30
|
+
"@teamplay/schema": "^0.1.7",
|
|
31
|
+
"@teamplay/utils": "^0.1.7",
|
|
32
32
|
"diff-match-patch": "^1.0.5",
|
|
33
33
|
"events": "^3.3.0",
|
|
34
34
|
"json0-ot-diff": "^1.1.2",
|
|
35
35
|
"lodash": "^4.17.20",
|
|
36
36
|
"sharedb": "^5.0.0",
|
|
37
|
-
"uuid": "^
|
|
37
|
+
"uuid": "^3.4.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@jest/globals": "^29.7.0",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"license": "MIT",
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "321f956c4370c7a36a1c33fdf09e91f41cb6a620"
|
|
68
68
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export const REGISTRY_FINALIZE_AFTER = 10_000
|
|
2
|
+
export const REGISTRY_SWEEP_INTERVAL = 10_000
|
|
3
|
+
|
|
4
|
+
// This is a mock implementation of FinalizationRegistry that uses setTimeout to
|
|
5
|
+
// schedule the sweep of outdated objects.
|
|
6
|
+
// It is used in environments where FinalizationRegistry is not available.
|
|
7
|
+
// For now we permanently keep the values in the registry until they are
|
|
8
|
+
// manually unregistered since we don't have a way to know when the object is
|
|
9
|
+
// no longer needed. In the future we might add the control logic to properly
|
|
10
|
+
// invalidate the objects.
|
|
11
|
+
export let PERMANENT = true
|
|
12
|
+
export function setPermanent (permanent) { PERMANENT = permanent }
|
|
13
|
+
|
|
14
|
+
export class TimerBasedFinalizationRegistry {
|
|
15
|
+
registrations = new Map()
|
|
16
|
+
sweepTimeout
|
|
17
|
+
|
|
18
|
+
constructor (finalize) {
|
|
19
|
+
this.finalize = finalize
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Token is actually required with this impl
|
|
23
|
+
register (target, value, token) {
|
|
24
|
+
this.registrations.set(token, {
|
|
25
|
+
value,
|
|
26
|
+
registeredAt: Date.now()
|
|
27
|
+
})
|
|
28
|
+
if (!PERMANENT) this.scheduleSweep()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
unregister (token) {
|
|
32
|
+
this.registrations.delete(token)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Bound so it can be used directly as setTimeout callback.
|
|
36
|
+
sweep = (maxAge = REGISTRY_FINALIZE_AFTER) => {
|
|
37
|
+
// cancel timeout so we can force sweep anytime
|
|
38
|
+
clearTimeout(this.sweepTimeout)
|
|
39
|
+
this.sweepTimeout = undefined
|
|
40
|
+
|
|
41
|
+
const now = Date.now()
|
|
42
|
+
this.registrations.forEach((registration, token) => {
|
|
43
|
+
if (now - registration.registeredAt >= maxAge) {
|
|
44
|
+
this.finalize(registration.value)
|
|
45
|
+
this.registrations.delete(token)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
if (this.registrations.size > 0) {
|
|
50
|
+
this.scheduleSweep()
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Bound so it can be exported directly as clearTimers test utility.
|
|
55
|
+
finalizeAllImmediately = () => {
|
|
56
|
+
this.sweep(0)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
scheduleSweep () {
|
|
60
|
+
if (this.sweepTimeout === undefined) {
|
|
61
|
+
this.sweepTimeout = setTimeout(this.sweep, REGISTRY_SWEEP_INTERVAL)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default (typeof FinalizationRegistry !== 'undefined' ? FinalizationRegistry : TimerBasedFinalizationRegistry)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class MockWeakRef {
|
|
2
|
+
constructor (value) {
|
|
3
|
+
this.value = value
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
deref () {
|
|
7
|
+
return this.value
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function destroyMockWeakRef (weakRef) {
|
|
12
|
+
if (!(weakRef instanceof MockWeakRef)) return
|
|
13
|
+
weakRef.value = undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default (typeof WeakRef !== 'undefined' ? WeakRef : MockWeakRef)
|
package/CHANGELOG.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# v0.1.5 (Mon May 27 2024)
|
|
2
|
-
|
|
3
|
-
#### 🚀 Enhancement
|
|
4
|
-
|
|
5
|
-
- feat: move backend implementation from startupjs. Add an example app. ([@cray0000](https://github.com/cray0000))
|
|
6
|
-
|
|
7
|
-
#### ⚠️ Pushed to `master`
|
|
8
|
-
|
|
9
|
-
- readme: add example readme ([@cray0000](https://github.com/cray0000))
|
|
10
|
-
- chore(example): add live reload support whenever client.js changes ([@cray0000](https://github.com/cray0000))
|
|
11
|
-
|
|
12
|
-
#### Authors: 1
|
|
13
|
-
|
|
14
|
-
- Pavel Zhukov ([@cray0000](https://github.com/cray0000))
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
# v0.1.4 (Thu May 23 2024)
|
|
19
|
-
|
|
20
|
-
#### 🐛 Bug Fix
|
|
21
|
-
|
|
22
|
-
- fix: rename old references to startupjs packages into teamplay packages ([@cray0000](https://github.com/cray0000))
|
|
23
|
-
|
|
24
|
-
#### Authors: 1
|
|
25
|
-
|
|
26
|
-
- Pavel Zhukov ([@cray0000](https://github.com/cray0000))
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
# v0.1.3 (Thu May 23 2024)
|
|
31
|
-
|
|
32
|
-
#### 🐛 Bug Fix
|
|
33
|
-
|
|
34
|
-
- fix: add 'events' since sharedb client requires it to work correctly ([@cray0000](https://github.com/cray0000))
|
|
35
|
-
|
|
36
|
-
#### Authors: 1
|
|
37
|
-
|
|
38
|
-
- Pavel Zhukov ([@cray0000](https://github.com/cray0000))
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
# v0.1.2 (Thu May 23 2024)
|
|
43
|
-
|
|
44
|
-
#### 🐛 Bug Fix
|
|
45
|
-
|
|
46
|
-
- fix: re-export cache as 'teamplay/cache' ([@cray0000](https://github.com/cray0000))
|
|
47
|
-
|
|
48
|
-
#### Authors: 1
|
|
49
|
-
|
|
50
|
-
- Pavel Zhukov ([@cray0000](https://github.com/cray0000))
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
# v0.1.1 (Thu May 23 2024)
|
|
55
|
-
|
|
56
|
-
#### 🐛 Bug Fix
|
|
57
|
-
|
|
58
|
-
- fix: dummy. trigger version bump ([@cray0000](https://github.com/cray0000))
|
|
59
|
-
|
|
60
|
-
#### Authors: 1
|
|
61
|
-
|
|
62
|
-
- Pavel Zhukov ([@cray0000](https://github.com/cray0000))
|