atom.io 0.24.8 → 0.25.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.
- package/data/dist/index.cjs +40 -62
- package/data/dist/index.d.ts +3 -3
- package/data/dist/index.js +41 -63
- package/data/src/join.ts +47 -64
- package/dist/index.cjs +26 -8
- package/dist/index.d.ts +37 -15
- package/dist/index.js +27 -9
- package/internal/dist/index.cjs +204 -104
- package/internal/dist/index.d.ts +10 -5
- package/internal/dist/index.js +205 -105
- package/internal/src/families/dispose-from-store.ts +56 -3
- package/internal/src/get-state/get-from-store.ts +58 -25
- package/internal/src/molecule/make-molecule-in-store.ts +59 -23
- package/internal/src/not-found-error.ts +29 -6
- package/internal/src/selector/create-writable-selector.ts +5 -5
- package/internal/src/selector/register-selector.ts +58 -9
- package/internal/src/set-state/set-into-store.ts +48 -1
- package/internal/src/store/store.ts +4 -4
- package/internal/src/transaction/build-transaction.ts +10 -9
- package/internal/src/transaction/create-transaction.ts +2 -2
- package/internal/src/transaction/index.ts +2 -2
- package/package.json +5 -5
- package/react/dist/index.cjs +4 -1
- package/react/dist/index.js +5 -2
- package/react/src/use-o.ts +11 -3
- package/realtime/dist/index.cjs +0 -1
- package/realtime/dist/index.js +0 -1
- package/realtime/src/realtime-continuity.ts +0 -1
- package/realtime-server/dist/index.cjs +7 -7
- package/realtime-server/dist/index.js +7 -7
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +7 -7
- package/src/dispose-state.ts +32 -3
- package/src/get-state.ts +37 -4
- package/src/molecule.ts +20 -7
- package/src/set-state.ts +19 -2
- package/src/silo.ts +11 -4
- package/src/transaction.ts +9 -17
|
@@ -370,41 +370,41 @@ var createRoomTX = AtomIO.transaction({
|
|
|
370
370
|
});
|
|
371
371
|
var joinRoomTX = AtomIO.transaction({
|
|
372
372
|
key: `joinRoom`,
|
|
373
|
-
do: (
|
|
373
|
+
do: (tools, roomId, userId, enteredAtEpoch) => {
|
|
374
374
|
const meta = { enteredAtEpoch };
|
|
375
375
|
editRelationsInStore(
|
|
376
376
|
usersInRooms,
|
|
377
377
|
(relations) => {
|
|
378
378
|
relations.set({ room: roomId, user: userId }, meta);
|
|
379
379
|
},
|
|
380
|
-
|
|
380
|
+
tools.env().store
|
|
381
381
|
);
|
|
382
382
|
return meta;
|
|
383
383
|
}
|
|
384
384
|
});
|
|
385
385
|
var leaveRoomTX = AtomIO.transaction({
|
|
386
386
|
key: `leaveRoom`,
|
|
387
|
-
do: (
|
|
387
|
+
do: (tools, roomId, userId) => {
|
|
388
388
|
editRelationsInStore(
|
|
389
389
|
usersInRooms,
|
|
390
390
|
(relations) => {
|
|
391
391
|
relations.delete({ room: roomId, user: userId });
|
|
392
392
|
},
|
|
393
|
-
|
|
393
|
+
tools.env().store
|
|
394
394
|
);
|
|
395
395
|
}
|
|
396
396
|
});
|
|
397
397
|
var destroyRoomTX = AtomIO.transaction({
|
|
398
398
|
key: `destroyRoom`,
|
|
399
|
-
do: (
|
|
399
|
+
do: (tools, roomId) => {
|
|
400
400
|
editRelationsInStore(
|
|
401
401
|
usersInRooms,
|
|
402
402
|
(relations) => {
|
|
403
403
|
relations.delete({ room: roomId });
|
|
404
404
|
},
|
|
405
|
-
|
|
405
|
+
tools.env().store
|
|
406
406
|
);
|
|
407
|
-
|
|
407
|
+
tools.set(roomIndex, (s) => (s.delete(roomId), s));
|
|
408
408
|
}
|
|
409
409
|
});
|
|
410
410
|
function redactTransactionUpdateContent(visibleStateKeys, updates) {
|
|
@@ -31,14 +31,14 @@ export const joinRoomTX = AtomIO.transaction<
|
|
|
31
31
|
(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta
|
|
32
32
|
>({
|
|
33
33
|
key: `joinRoom`,
|
|
34
|
-
do: (
|
|
34
|
+
do: (tools, roomId, userId, enteredAtEpoch) => {
|
|
35
35
|
const meta = { enteredAtEpoch }
|
|
36
36
|
editRelationsInStore(
|
|
37
37
|
usersInRooms,
|
|
38
38
|
(relations) => {
|
|
39
39
|
relations.set({ room: roomId, user: userId }, meta)
|
|
40
40
|
},
|
|
41
|
-
|
|
41
|
+
tools.env().store,
|
|
42
42
|
)
|
|
43
43
|
return meta
|
|
44
44
|
},
|
|
@@ -49,13 +49,13 @@ export const leaveRoomTX = AtomIO.transaction<
|
|
|
49
49
|
(roomId: string, userId: string) => void
|
|
50
50
|
>({
|
|
51
51
|
key: `leaveRoom`,
|
|
52
|
-
do: (
|
|
52
|
+
do: (tools, roomId, userId) => {
|
|
53
53
|
editRelationsInStore(
|
|
54
54
|
usersInRooms,
|
|
55
55
|
(relations) => {
|
|
56
56
|
relations.delete({ room: roomId, user: userId })
|
|
57
57
|
},
|
|
58
|
-
|
|
58
|
+
tools.env().store,
|
|
59
59
|
)
|
|
60
60
|
},
|
|
61
61
|
})
|
|
@@ -63,14 +63,14 @@ export type LeaveRoomIO = AtomIO.TransactionIO<typeof leaveRoomTX>
|
|
|
63
63
|
|
|
64
64
|
export const destroyRoomTX = AtomIO.transaction<(roomId: string) => void>({
|
|
65
65
|
key: `destroyRoom`,
|
|
66
|
-
do: (
|
|
66
|
+
do: (tools, roomId) => {
|
|
67
67
|
editRelationsInStore(
|
|
68
68
|
usersInRooms,
|
|
69
69
|
(relations) => {
|
|
70
70
|
relations.delete({ room: roomId })
|
|
71
71
|
},
|
|
72
|
-
|
|
72
|
+
tools.env().store,
|
|
73
73
|
)
|
|
74
|
-
|
|
74
|
+
tools.set(roomIndex, (s) => (s.delete(roomId), s))
|
|
75
75
|
},
|
|
76
76
|
})
|
package/src/dispose-state.ts
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
import * as Internal from "atom.io/internal"
|
|
2
|
+
import type { Json } from "atom.io/json"
|
|
2
3
|
|
|
3
|
-
import type { ReadableToken } from "."
|
|
4
|
-
import type {
|
|
4
|
+
import type { ReadableFamilyToken, ReadableToken } from "."
|
|
5
|
+
import type {
|
|
6
|
+
MoleculeConstructor,
|
|
7
|
+
MoleculeFamilyToken,
|
|
8
|
+
MoleculeKey,
|
|
9
|
+
MoleculeToken,
|
|
10
|
+
} from "./molecule"
|
|
5
11
|
|
|
6
12
|
export function disposeState(
|
|
7
13
|
token: MoleculeToken<any> | ReadableToken<any>,
|
|
14
|
+
): void
|
|
15
|
+
|
|
16
|
+
export function disposeState<K extends Json.Serializable>(
|
|
17
|
+
token: ReadableFamilyToken<any, K>,
|
|
18
|
+
key: K,
|
|
19
|
+
): void
|
|
20
|
+
|
|
21
|
+
export function disposeState<M extends MoleculeConstructor>(
|
|
22
|
+
token: MoleculeFamilyToken<M>,
|
|
23
|
+
key: MoleculeKey<M>,
|
|
24
|
+
): void
|
|
25
|
+
|
|
26
|
+
export function disposeState(
|
|
27
|
+
token:
|
|
28
|
+
| MoleculeFamilyToken<any>
|
|
29
|
+
| MoleculeToken<any>
|
|
30
|
+
| ReadableFamilyToken<any, any>
|
|
31
|
+
| ReadableToken<any>,
|
|
32
|
+
key?: Json.Serializable,
|
|
8
33
|
): void {
|
|
9
|
-
|
|
34
|
+
if (key) {
|
|
35
|
+
Internal.disposeFromStore(token as any, key, Internal.IMPLICIT.STORE)
|
|
36
|
+
} else {
|
|
37
|
+
Internal.disposeFromStore(token as any, Internal.IMPLICIT.STORE)
|
|
38
|
+
}
|
|
10
39
|
}
|
package/src/get-state.ts
CHANGED
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
import * as Internal from "atom.io/internal"
|
|
2
|
+
import type { Json } from "atom.io/json"
|
|
2
3
|
|
|
3
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
MoleculeConstructor,
|
|
6
|
+
MoleculeFamilyToken,
|
|
7
|
+
MoleculeToken,
|
|
8
|
+
ReadableFamilyToken,
|
|
9
|
+
ReadableToken,
|
|
10
|
+
} from "."
|
|
4
11
|
|
|
5
12
|
export function getState<T>(token: ReadableToken<T>): T
|
|
13
|
+
|
|
6
14
|
export function getState<M extends MoleculeConstructor>(
|
|
7
15
|
token: MoleculeToken<M>,
|
|
8
|
-
): InstanceType<M>
|
|
9
|
-
|
|
10
|
-
|
|
16
|
+
): InstanceType<M>
|
|
17
|
+
|
|
18
|
+
export function getState<T, K extends Json.Serializable>(
|
|
19
|
+
token: ReadableFamilyToken<T, K>,
|
|
20
|
+
key: K,
|
|
21
|
+
): T
|
|
22
|
+
|
|
23
|
+
export function getState<M extends MoleculeConstructor>(
|
|
24
|
+
token: MoleculeFamilyToken<M>,
|
|
25
|
+
key: Json.Serializable,
|
|
26
|
+
): InstanceType<M>
|
|
27
|
+
|
|
28
|
+
export function getState(
|
|
29
|
+
token:
|
|
30
|
+
| MoleculeFamilyToken<any>
|
|
31
|
+
| MoleculeToken<any>
|
|
32
|
+
| ReadableFamilyToken<any, any>
|
|
33
|
+
| ReadableToken<any>,
|
|
34
|
+
key?: Json.Serializable,
|
|
35
|
+
): any {
|
|
36
|
+
if (key) {
|
|
37
|
+
return Internal.getFromStore(
|
|
38
|
+
token as any,
|
|
39
|
+
key as any,
|
|
40
|
+
Internal.IMPLICIT.STORE,
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
return Internal.getFromStore(token as any, Internal.IMPLICIT.STORE)
|
|
11
44
|
}
|
package/src/molecule.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
ActorToolkit,
|
|
2
3
|
Flat,
|
|
3
4
|
MoleculeCreation,
|
|
4
5
|
MoleculeDisposal,
|
|
@@ -10,7 +11,6 @@ import type {
|
|
|
10
11
|
ReadonlySelectorToken,
|
|
11
12
|
RegularAtomFamilyToken,
|
|
12
13
|
RegularAtomToken,
|
|
13
|
-
TransactorsWithRunAndEnv,
|
|
14
14
|
WritableFamilyToken,
|
|
15
15
|
WritableSelectorFamilyToken,
|
|
16
16
|
WritableSelectorToken,
|
|
@@ -26,8 +26,8 @@ import {
|
|
|
26
26
|
} from "atom.io/internal"
|
|
27
27
|
import { type Json, stringifyJson } from "atom.io/json"
|
|
28
28
|
|
|
29
|
-
export type
|
|
30
|
-
Omit<
|
|
29
|
+
export type CtorToolkit<K extends Json.Serializable> = Flat<
|
|
30
|
+
Omit<ActorToolkit, `find`> & {
|
|
31
31
|
bond<T extends Transceiver<any>, J extends Json.Serializable>(
|
|
32
32
|
family: MutableAtomFamilyToken<T, J, K>,
|
|
33
33
|
): MutableAtomToken<T, J>
|
|
@@ -36,10 +36,23 @@ export type MoleculeTransactors<K extends Json.Serializable> = Flat<
|
|
|
36
36
|
bond<T>(family: ReadonlySelectorFamilyToken<T, K>): ReadonlySelectorToken<T>
|
|
37
37
|
bond<T>(family: WritableFamilyToken<T, K>): WritableToken<T>
|
|
38
38
|
bond<T>(family: ReadableFamilyToken<T, K>): ReadableToken<T>
|
|
39
|
+
bond<J extends JoinToken<any, any, any, any>>(
|
|
40
|
+
joinToken: J,
|
|
41
|
+
role: {
|
|
42
|
+
as: J extends JoinToken<infer A, infer B, any, any> ? A | B : never
|
|
43
|
+
},
|
|
44
|
+
): J extends JoinToken<any, any, any, infer Content>
|
|
45
|
+
? Content extends null
|
|
46
|
+
? { relatedKeys: ReadonlySelectorToken<string[]> }
|
|
47
|
+
: {
|
|
48
|
+
relatedKeys: ReadonlySelectorToken<string[]>
|
|
49
|
+
relatedEntries: ReadonlySelectorToken<
|
|
50
|
+
[key: string, value: Content][]
|
|
51
|
+
>
|
|
52
|
+
}
|
|
53
|
+
: never
|
|
39
54
|
|
|
40
|
-
claim(below: MoleculeToken<any>, options: { exclusive: boolean })
|
|
41
|
-
|
|
42
|
-
join<J extends JoinToken<any, any, any, any>>(joinToken: J): J
|
|
55
|
+
claim(below: MoleculeToken<any>, options: { exclusive: boolean }): void
|
|
43
56
|
|
|
44
57
|
spawn<Key extends Json.Serializable, Ctor extends MoleculeConstructor>(
|
|
45
58
|
family: MoleculeFamilyToken<Ctor>,
|
|
@@ -49,7 +62,7 @@ export type MoleculeTransactors<K extends Json.Serializable> = Flat<
|
|
|
49
62
|
}
|
|
50
63
|
>
|
|
51
64
|
export type MoleculeConstructor = new (
|
|
52
|
-
|
|
65
|
+
toolkit: CtorToolkit<any>,
|
|
53
66
|
key: any,
|
|
54
67
|
...params: any
|
|
55
68
|
) => any
|
package/src/set-state.ts
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import * as Internal from "atom.io/internal"
|
|
2
|
+
import type { Json } from "rel8"
|
|
2
3
|
|
|
3
|
-
import type { WritableToken } from "."
|
|
4
|
+
import type { WritableFamilyToken, WritableToken } from "."
|
|
4
5
|
|
|
5
6
|
export function setState<T, New extends T>(
|
|
6
7
|
token: WritableToken<T>,
|
|
7
8
|
value: New | ((oldValue: T) => New),
|
|
9
|
+
): void
|
|
10
|
+
|
|
11
|
+
export function setState<T, K extends Json.Serializable, New extends T>(
|
|
12
|
+
token: WritableFamilyToken<T, K>,
|
|
13
|
+
key: K,
|
|
14
|
+
value: New | ((oldValue: T) => New),
|
|
15
|
+
): void
|
|
16
|
+
|
|
17
|
+
export function setState<T, New extends T>(
|
|
18
|
+
token: WritableFamilyToken<T, Json.Serializable> | WritableToken<T>,
|
|
19
|
+
p1: Json.Serializable | New | ((oldValue: T) => New),
|
|
20
|
+
p2?: New | ((oldValue: T) => New),
|
|
8
21
|
): void {
|
|
9
|
-
|
|
22
|
+
if (p2) {
|
|
23
|
+
Internal.setIntoStore(token as any, p1 as any, p2, Internal.IMPLICIT.STORE)
|
|
24
|
+
} else {
|
|
25
|
+
Internal.setIntoStore(token as any, p1 as any, Internal.IMPLICIT.STORE)
|
|
26
|
+
}
|
|
10
27
|
}
|
package/src/silo.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
createStandaloneSelector,
|
|
8
8
|
createTimeline,
|
|
9
9
|
createTransaction,
|
|
10
|
+
disposeFromStore,
|
|
10
11
|
findInStore,
|
|
11
12
|
getFromStore,
|
|
12
13
|
setIntoStore,
|
|
@@ -17,6 +18,7 @@ import type { Json } from "atom.io/json"
|
|
|
17
18
|
|
|
18
19
|
import type {
|
|
19
20
|
AtomToken,
|
|
21
|
+
disposeState,
|
|
20
22
|
getState,
|
|
21
23
|
MutableAtomFamily,
|
|
22
24
|
MutableAtomFamilyOptions,
|
|
@@ -47,6 +49,7 @@ export class Silo {
|
|
|
47
49
|
public findState: typeof findState
|
|
48
50
|
public getState: typeof getState
|
|
49
51
|
public setState: typeof setState
|
|
52
|
+
public disposeState: typeof disposeState
|
|
50
53
|
public subscribe: typeof subscribe
|
|
51
54
|
public undo: typeof undo
|
|
52
55
|
public redo: typeof redo
|
|
@@ -84,10 +87,14 @@ export class Silo {
|
|
|
84
87
|
this.transaction = (options) => createTransaction(options, s)
|
|
85
88
|
this.timeline = (options) => createTimeline(options, s)
|
|
86
89
|
this.findState = (token, key) => findInStore(token, key, s) as any
|
|
87
|
-
this.getState = (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
this.getState = ((...params: Parameters<typeof getState>) =>
|
|
91
|
+
getFromStore(...params, s)) as typeof getState
|
|
92
|
+
this.setState = ((...params: Parameters<typeof setState>) => {
|
|
93
|
+
setIntoStore(...params, s)
|
|
94
|
+
}) as typeof setState
|
|
95
|
+
this.disposeState = ((...params: Parameters<typeof disposeState>) => {
|
|
96
|
+
disposeFromStore(...params, s)
|
|
97
|
+
}) as typeof disposeState
|
|
91
98
|
this.subscribe = (token, handler, key) => subscribe(token, handler, key, s)
|
|
92
99
|
this.undo = (token) => {
|
|
93
100
|
timeTravel(`undo`, token, s)
|
package/src/transaction.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
MoleculeFamilyToken,
|
|
6
6
|
MoleculeParams,
|
|
7
7
|
MoleculeToken,
|
|
8
|
+
setState,
|
|
8
9
|
} from "atom.io"
|
|
9
10
|
import type { findState } from "atom.io/ephemeral"
|
|
10
11
|
import type { seekState } from "atom.io/immortal"
|
|
@@ -78,24 +79,19 @@ export type TransactionUpdate<F extends Func> = {
|
|
|
78
79
|
output: ReturnType<F>
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
export type
|
|
82
|
+
export type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json` | `seek`>
|
|
83
|
+
export type SetterToolkit = Readonly<{
|
|
82
84
|
get: typeof getState
|
|
83
|
-
set:
|
|
84
|
-
state: WritableToken<S>,
|
|
85
|
-
newValue: New | ((oldValue: S) => New),
|
|
86
|
-
) => void
|
|
85
|
+
set: typeof setState
|
|
87
86
|
find: typeof findState
|
|
88
87
|
seek: typeof seekState
|
|
89
88
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(
|
|
90
89
|
state: MutableAtomToken<T, J>,
|
|
91
90
|
) => WritableSelectorToken<J>
|
|
92
91
|
}>
|
|
93
|
-
export type
|
|
92
|
+
export type ActorToolkit = Readonly<{
|
|
94
93
|
get: typeof getState
|
|
95
|
-
set:
|
|
96
|
-
state: WritableToken<S>,
|
|
97
|
-
newValue: New | ((oldValue: S) => New),
|
|
98
|
-
) => void
|
|
94
|
+
set: typeof setState
|
|
99
95
|
find: typeof findState
|
|
100
96
|
seek: typeof seekState
|
|
101
97
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(
|
|
@@ -106,23 +102,19 @@ export type TransactorsWithRunAndEnv = Readonly<{
|
|
|
106
102
|
run: typeof runTransaction
|
|
107
103
|
env: () => EnvironmentData
|
|
108
104
|
}>
|
|
109
|
-
export type ReadonlyTransactors = Pick<
|
|
110
|
-
Transactors,
|
|
111
|
-
`find` | `get` | `json` | `seek`
|
|
112
|
-
>
|
|
113
105
|
|
|
114
106
|
export type Read<F extends Func> = (
|
|
115
|
-
|
|
107
|
+
toolkit: GetterToolkit,
|
|
116
108
|
...parameters: Parameters<F>
|
|
117
109
|
) => ReturnType<F>
|
|
118
110
|
|
|
119
111
|
export type Write<F extends Func> = (
|
|
120
|
-
|
|
112
|
+
toolkit: SetterToolkit,
|
|
121
113
|
...parameters: Parameters<F>
|
|
122
114
|
) => ReturnType<F>
|
|
123
115
|
|
|
124
116
|
export type Transact<F extends Func> = (
|
|
125
|
-
|
|
117
|
+
toolkit: ActorToolkit,
|
|
126
118
|
...parameters: Parameters<F>
|
|
127
119
|
) => ReturnType<F>
|
|
128
120
|
|