atom.io 0.34.0 → 0.34.1
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/dist/eslint-plugin/index.js +1 -2
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/internal/index.d.ts +6 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +26 -22
- package/dist/internal/index.js.map +1 -1
- package/dist/json/index.d.ts +3 -0
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +405 -23
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +107 -11
- package/dist/main/index.js.map +1 -1
- package/dist/realtime-client/index.js +4 -8
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.js +1 -1
- package/dist/realtime-server/index.js.map +1 -1
- package/package.json +6 -6
- package/src/internal/join/create-join.ts +27 -0
- package/src/internal/join/index.ts +1 -0
- package/src/internal/junction.ts +2 -0
- package/src/json/index.ts +3 -0
- package/src/main/atom.ts +54 -13
- package/src/main/dispose-state.ts +8 -2
- package/src/main/find-state.ts +44 -14
- package/src/main/get-state.ts +2 -2
- package/src/main/index.ts +8 -0
- package/src/main/join.ts +79 -22
- package/src/main/realm.ts +50 -4
- package/src/main/selector.ts +116 -6
- package/src/main/subscribe.ts +31 -1
- package/src/main/timeline.ts +17 -0
- package/src/main/transaction.ts +39 -3
package/src/main/subscribe.ts
CHANGED
|
@@ -11,7 +11,9 @@ import type {
|
|
|
11
11
|
TransactionUpdate,
|
|
12
12
|
} from "."
|
|
13
13
|
|
|
14
|
+
/** @public */
|
|
14
15
|
export type StateUpdate<T> = { newValue: T; oldValue: T }
|
|
16
|
+
/** @public */
|
|
15
17
|
export type KeyedStateUpdate<T> = Flat<
|
|
16
18
|
StateUpdate<T> & {
|
|
17
19
|
key: string
|
|
@@ -19,22 +21,50 @@ export type KeyedStateUpdate<T> = Flat<
|
|
|
19
21
|
family?: FamilyMetadata
|
|
20
22
|
}
|
|
21
23
|
>
|
|
24
|
+
/** @public */
|
|
22
25
|
export type UpdateHandler<T> = (update: StateUpdate<T>) => void
|
|
23
|
-
|
|
26
|
+
/** @public */
|
|
24
27
|
export type TransactionUpdateHandler<F extends Func> = (
|
|
25
28
|
data: TransactionUpdate<F>,
|
|
26
29
|
) => void
|
|
27
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @public
|
|
33
|
+
* Subscribe to a state in the implicit store
|
|
34
|
+
* @param token - The token of the state to subscribe to
|
|
35
|
+
* @param handleUpdate - A function that will be called when the state is updated
|
|
36
|
+
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
37
|
+
* @returns A function that can be called to unsubscribe from the state
|
|
38
|
+
* @overload State
|
|
39
|
+
*/
|
|
28
40
|
export function subscribe<T>(
|
|
29
41
|
token: ReadableToken<T>,
|
|
30
42
|
handleUpdate: UpdateHandler<T>,
|
|
31
43
|
key?: string,
|
|
32
44
|
): () => void
|
|
45
|
+
/**
|
|
46
|
+
* @public
|
|
47
|
+
* Subscribe to a transaction in the implicit store
|
|
48
|
+
* @param token - The token of the transaction to subscribe to
|
|
49
|
+
* @param handleUpdate - A function that will be called when the transaction succeeds
|
|
50
|
+
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
51
|
+
* @returns A function that can be called to unsubscribe from the transaction
|
|
52
|
+
* @overload Transaction
|
|
53
|
+
*/
|
|
33
54
|
export function subscribe<F extends Func>(
|
|
34
55
|
token: TransactionToken<F>,
|
|
35
56
|
handleUpdate: TransactionUpdateHandler<F>,
|
|
36
57
|
key?: string,
|
|
37
58
|
): () => void
|
|
59
|
+
/**
|
|
60
|
+
* @public
|
|
61
|
+
* Subscribe to a timeline in the implicit store
|
|
62
|
+
* @param token - The token of the timeline to subscribe to
|
|
63
|
+
* @param handleUpdate - A function that will be called when a new update is available
|
|
64
|
+
* @param key - A unique key for the subscription. If not provided, a random key will be generated.
|
|
65
|
+
* @returns A function that can be called to unsubscribe from the timeline
|
|
66
|
+
* @overload Timeline
|
|
67
|
+
*/
|
|
38
68
|
export function subscribe<M extends TimelineManageable>(
|
|
39
69
|
token: TimelineToken<M>,
|
|
40
70
|
handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,
|
package/src/main/timeline.ts
CHANGED
|
@@ -12,7 +12,9 @@ import { createTimeline, IMPLICIT, timeTravel } from "atom.io/internal"
|
|
|
12
12
|
|
|
13
13
|
import type { AtomFamilyToken, AtomToken } from "."
|
|
14
14
|
|
|
15
|
+
/** @public */
|
|
15
16
|
export type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>
|
|
17
|
+
/** @public */
|
|
16
18
|
export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
|
|
17
19
|
any,
|
|
18
20
|
any
|
|
@@ -22,21 +24,30 @@ export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
|
|
|
22
24
|
? M
|
|
23
25
|
: never
|
|
24
26
|
|
|
27
|
+
/** @public */
|
|
25
28
|
export type TimelineToken<M> = {
|
|
29
|
+
/** The unique identifier of the timeline */
|
|
26
30
|
key: string
|
|
31
|
+
/** Discriminator */
|
|
27
32
|
type: `timeline`
|
|
33
|
+
/** Never present. This is a marker that preserves the type of the managed atoms */
|
|
28
34
|
__M?: M
|
|
29
35
|
}
|
|
30
36
|
|
|
37
|
+
/** @public */
|
|
31
38
|
export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
|
|
39
|
+
/** The unique identifier of the timeline */
|
|
32
40
|
key: string
|
|
41
|
+
/** The managed atoms (and families of atoms) to record */
|
|
33
42
|
scope: ManagedAtom[]
|
|
43
|
+
/** A function that determines whether a given update should be recorded */
|
|
34
44
|
shouldCapture?: (
|
|
35
45
|
update: TimelineUpdate<ManagedAtom>,
|
|
36
46
|
timeline: Timeline<TimelineManageable>,
|
|
37
47
|
) => boolean
|
|
38
48
|
}
|
|
39
49
|
|
|
50
|
+
/** @public */
|
|
40
51
|
export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
|
|
41
52
|
| TimelineAtomUpdate<ManagedAtom>
|
|
42
53
|
| TimelineMoleculeCreation
|
|
@@ -46,6 +57,12 @@ export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
|
|
|
46
57
|
| TimelineStateDisposal<AtomOnly<ManagedAtom>>
|
|
47
58
|
| TimelineTransactionUpdate
|
|
48
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @public
|
|
62
|
+
* Create a timeline, a mechanism for recording, undoing, and replaying changes to groups of atoms.
|
|
63
|
+
* @param options - {@link TimelineOptions}
|
|
64
|
+
* @returns A reference to the timeline created: a {@link TimelineToken}
|
|
65
|
+
*/
|
|
49
66
|
export const timeline = <ManagedAtom extends TimelineManageable>(
|
|
50
67
|
options: TimelineOptions<ManagedAtom>,
|
|
51
68
|
): TimelineToken<ManagedAtom> => {
|
package/src/main/transaction.ts
CHANGED
|
@@ -18,37 +18,47 @@ import type {
|
|
|
18
18
|
} from "."
|
|
19
19
|
import type { resetState } from "./reset-state"
|
|
20
20
|
|
|
21
|
+
/** @public */
|
|
21
22
|
export type TransactionToken<F extends Func> = {
|
|
23
|
+
/** The unique identifier of the transaction */
|
|
22
24
|
key: string
|
|
25
|
+
/** Discriminator */
|
|
23
26
|
type: `transaction`
|
|
27
|
+
/** Never present. This is a marker that preserves the type of the transaction function */
|
|
24
28
|
__F?: F
|
|
25
29
|
}
|
|
26
30
|
|
|
31
|
+
/** @public */
|
|
27
32
|
export type StateCreation<Token extends ReadableToken<any>> = {
|
|
28
33
|
type: `state_creation`
|
|
29
34
|
token: Token
|
|
30
35
|
}
|
|
36
|
+
/** @public */
|
|
31
37
|
export type AtomDisposal<Token extends ReadableToken<any>> = {
|
|
32
38
|
type: `state_disposal`
|
|
33
39
|
subType: `atom`
|
|
34
40
|
token: Token
|
|
35
41
|
value: TokenType<Token>
|
|
36
42
|
}
|
|
43
|
+
/** @public */
|
|
37
44
|
export type SelectorDisposal<Token extends ReadableToken<any>> = {
|
|
38
45
|
type: `state_disposal`
|
|
39
46
|
subType: `selector`
|
|
40
47
|
token: Token
|
|
41
48
|
}
|
|
49
|
+
/** @public */
|
|
42
50
|
export type StateDisposal<Token extends ReadableToken<any>> =
|
|
43
51
|
| AtomDisposal<Token>
|
|
44
52
|
| SelectorDisposal<Token>
|
|
45
53
|
|
|
54
|
+
/** @public */
|
|
46
55
|
export type MoleculeCreation = {
|
|
47
56
|
type: `molecule_creation`
|
|
48
57
|
key: Canonical
|
|
49
58
|
provenance: Canonical
|
|
50
59
|
}
|
|
51
60
|
|
|
61
|
+
/** @public */
|
|
52
62
|
export type MoleculeDisposal = {
|
|
53
63
|
type: `molecule_disposal`
|
|
54
64
|
key: Canonical
|
|
@@ -56,6 +66,7 @@ export type MoleculeDisposal = {
|
|
|
56
66
|
values: [key: string, value: any][]
|
|
57
67
|
}
|
|
58
68
|
|
|
69
|
+
/** @public */
|
|
59
70
|
export type MoleculeTransfer = {
|
|
60
71
|
type: `molecule_transfer`
|
|
61
72
|
key: Canonical
|
|
@@ -63,6 +74,7 @@ export type MoleculeTransfer = {
|
|
|
63
74
|
to: Canonical[]
|
|
64
75
|
}
|
|
65
76
|
|
|
77
|
+
/** @public */
|
|
66
78
|
export type TransactionUpdateContent =
|
|
67
79
|
| KeyedStateUpdate<unknown>
|
|
68
80
|
| MoleculeCreation
|
|
@@ -72,6 +84,7 @@ export type TransactionUpdateContent =
|
|
|
72
84
|
| StateDisposal<ReadableToken<unknown>>
|
|
73
85
|
| TransactionUpdate<Func>
|
|
74
86
|
|
|
87
|
+
/** @public */
|
|
75
88
|
export type TransactionUpdate<F extends Func> = {
|
|
76
89
|
type: `transaction_update`
|
|
77
90
|
key: string
|
|
@@ -82,7 +95,9 @@ export type TransactionUpdate<F extends Func> = {
|
|
|
82
95
|
output: ReturnType<F>
|
|
83
96
|
}
|
|
84
97
|
|
|
98
|
+
/** @public */
|
|
85
99
|
export type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json`>
|
|
100
|
+
/** @public */
|
|
86
101
|
export type SetterToolkit = Readonly<{
|
|
87
102
|
get: typeof getState
|
|
88
103
|
set: typeof setState
|
|
@@ -91,6 +106,7 @@ export type SetterToolkit = Readonly<{
|
|
|
91
106
|
state: MutableAtomToken<T, J>,
|
|
92
107
|
) => WritablePureSelectorToken<J>
|
|
93
108
|
}>
|
|
109
|
+
/** @public */
|
|
94
110
|
export type ActorToolkit = Readonly<{
|
|
95
111
|
get: typeof getState
|
|
96
112
|
set: typeof setState
|
|
@@ -104,35 +120,55 @@ export type ActorToolkit = Readonly<{
|
|
|
104
120
|
env: () => EnvironmentData
|
|
105
121
|
}>
|
|
106
122
|
|
|
123
|
+
/** @public */
|
|
107
124
|
export type Read<F extends Func> = (
|
|
108
125
|
toolkit: GetterToolkit,
|
|
109
126
|
...parameters: Parameters<F>
|
|
110
127
|
) => ReturnType<F>
|
|
111
128
|
|
|
129
|
+
/** @public */
|
|
112
130
|
export type Write<F extends Func> = (
|
|
113
131
|
toolkit: SetterToolkit,
|
|
114
132
|
...parameters: Parameters<F>
|
|
115
133
|
) => ReturnType<F>
|
|
116
134
|
|
|
135
|
+
/** @public */
|
|
117
136
|
export type Transact<F extends Func> = (
|
|
118
137
|
toolkit: ActorToolkit,
|
|
119
138
|
...parameters: Parameters<F>
|
|
120
139
|
) => ReturnType<F>
|
|
121
140
|
|
|
141
|
+
/** @public */
|
|
142
|
+
export type TransactionIO<Token extends TransactionToken<any>> =
|
|
143
|
+
Token extends TransactionToken<infer F> ? F : never
|
|
144
|
+
|
|
145
|
+
/** @public */
|
|
122
146
|
export type TransactionOptions<F extends Func> = {
|
|
147
|
+
/** The unique identifier of the transaction */
|
|
123
148
|
key: string
|
|
149
|
+
/** The operation to perform */
|
|
124
150
|
do: Transact<F>
|
|
125
151
|
}
|
|
126
152
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
153
|
+
/**
|
|
154
|
+
* @public
|
|
155
|
+
* Create a transaction, a mechanism for batching updates multiple states in a single, all-or-nothing operation
|
|
156
|
+
* @param options - {@link TransactionOptions}
|
|
157
|
+
* @returns A reference to the transaction created: a {@link TransactionToken}
|
|
158
|
+
*/
|
|
130
159
|
export function transaction<F extends Func>(
|
|
131
160
|
options: TransactionOptions<F>,
|
|
132
161
|
): TransactionToken<F> {
|
|
133
162
|
return createTransaction(IMPLICIT.STORE, options)
|
|
134
163
|
}
|
|
135
164
|
|
|
165
|
+
/**
|
|
166
|
+
* @public
|
|
167
|
+
* Execute a {@link transaction}
|
|
168
|
+
* @param token - A {@link TransactionToken}
|
|
169
|
+
* @param id - A unique identifier for the transaction. If not provided, a random identifier will be generated
|
|
170
|
+
* @returns A function that can be called to run the transaction with its {@link TransactionIO} parameters
|
|
171
|
+
*/
|
|
136
172
|
export function runTransaction<F extends Func>(
|
|
137
173
|
token: TransactionToken<F>,
|
|
138
174
|
id: string = arbitrary(),
|