atom.io 0.34.1 → 0.35.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/dist/internal/index.d.ts +32 -41
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +106 -128
- package/dist/internal/index.js.map +1 -1
- package/dist/json/index.d.ts +19 -7
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +4 -0
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +704 -788
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +61 -33
- package/dist/main/index.js.map +1 -1
- package/dist/react-devtools/index.js +10 -10
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +3 -5
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.js +10 -10
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +8 -10
- package/dist/realtime-server/index.js.map +1 -1
- package/package.json +12 -12
- package/src/internal/atom/create-regular-atom.ts +1 -0
- package/src/internal/atom/index.ts +0 -1
- package/src/internal/families/index.ts +0 -1
- package/src/internal/index.ts +111 -89
- package/src/internal/join/join-internal.ts +3 -4
- package/src/internal/mutable/create-mutable-atom-family.ts +0 -1
- package/src/internal/mutable/create-mutable-atom.ts +1 -1
- package/src/internal/selector/register-selector.ts +2 -2
- package/src/json/entries.ts +10 -3
- package/src/json/index.ts +40 -17
- package/src/main/atom.ts +68 -115
- package/src/main/dispose-state.ts +0 -2
- package/src/main/find-state.ts +3 -9
- package/src/main/get-state.ts +0 -2
- package/src/main/index.ts +1 -176
- package/src/main/join.ts +12 -20
- package/src/main/reset-state.ts +0 -2
- package/src/main/selector.ts +5 -72
- package/src/main/set-state.ts +1 -4
- package/src/main/silo.ts +14 -5
- package/src/main/subscribe.ts +0 -7
- package/src/main/timeline.ts +24 -32
- package/src/main/tokens.ts +247 -0
- package/src/main/transaction.ts +17 -55
- package/src/main/validators.ts +1 -1
- package/src/react-devtools/store.ts +61 -45
- package/src/realtime/shared-room-store.ts +3 -5
- package/src/realtime-server/realtime-server-stores/server-user-store.ts +3 -5
- package/src/internal/atom/create-standalone-atom.ts +0 -39
- package/src/internal/families/create-atom-family.ts +0 -38
package/src/internal/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type { Store } from "./store"
|
|
|
23
23
|
import type { Subject } from "./subject"
|
|
24
24
|
import type { Timeline } from "./timeline"
|
|
25
25
|
import type { Transaction } from "./transaction"
|
|
26
|
+
import type { Flat } from "./utility-types"
|
|
26
27
|
|
|
27
28
|
export * from "./arbitrary"
|
|
28
29
|
export * from "./atom"
|
|
@@ -61,45 +62,56 @@ export type AtomIOState = {
|
|
|
61
62
|
install: (store: Store) => void
|
|
62
63
|
subject: Subject<{ newValue: any; oldValue: any }>
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
65
|
+
export type RegularAtom<T> = Flat<
|
|
66
|
+
AtomIOState & {
|
|
67
|
+
type: `atom`
|
|
68
|
+
default: T | (() => T)
|
|
69
|
+
cleanup?: () => void
|
|
70
|
+
}
|
|
71
|
+
>
|
|
70
72
|
export type MutableAtom<
|
|
71
73
|
T extends Transceiver<any>,
|
|
72
74
|
J extends Json.Serializable,
|
|
73
|
-
> =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
> = Flat<
|
|
76
|
+
AtomIOState &
|
|
77
|
+
JsonInterface<T, J> & {
|
|
78
|
+
type: `mutable_atom`
|
|
79
|
+
default: () => T
|
|
80
|
+
cleanup?: () => void
|
|
81
|
+
}
|
|
82
|
+
>
|
|
79
83
|
export type Atom<T> =
|
|
80
84
|
| RegularAtom<T>
|
|
81
85
|
| (T extends Transceiver<any> ? MutableAtom<T, any> : never)
|
|
82
86
|
|
|
83
|
-
export type WritableHeldSelector<T> =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
87
|
+
export type WritableHeldSelector<T> = Flat<
|
|
88
|
+
AtomIOState & {
|
|
89
|
+
type: `writable_held_selector`
|
|
90
|
+
const: T
|
|
91
|
+
get: () => T
|
|
92
|
+
set: (newValue: T | ((oldValue: T) => T)) => void
|
|
93
|
+
}
|
|
94
|
+
>
|
|
95
|
+
export type ReadonlyHeldSelector<T> = Flat<
|
|
96
|
+
AtomIOState & {
|
|
97
|
+
type: `readonly_held_selector`
|
|
98
|
+
const: T
|
|
99
|
+
get: () => T
|
|
100
|
+
}
|
|
101
|
+
>
|
|
102
|
+
export type WritablePureSelector<T> = Flat<
|
|
103
|
+
AtomIOState & {
|
|
104
|
+
type: `writable_pure_selector`
|
|
105
|
+
get: () => T
|
|
106
|
+
set: (newValue: T | ((oldValue: T) => T)) => void
|
|
107
|
+
}
|
|
108
|
+
>
|
|
109
|
+
export type ReadonlyPureSelector<T> = Flat<
|
|
110
|
+
AtomIOState & {
|
|
111
|
+
type: `readonly_pure_selector`
|
|
112
|
+
get: () => T
|
|
113
|
+
}
|
|
114
|
+
>
|
|
103
115
|
export type ReadonlySelector<T> =
|
|
104
116
|
| ReadonlyHeldSelector<T>
|
|
105
117
|
| ReadonlyPureSelector<T>
|
|
@@ -118,13 +130,13 @@ export type WritableState<T> = Atom<T> | WritableSelector<T>
|
|
|
118
130
|
export type ReadableState<T> = Atom<T> | Selector<T>
|
|
119
131
|
|
|
120
132
|
// biome-ignore format: intersection
|
|
121
|
-
export type RegularAtomFamily<T, K extends Canonical> =
|
|
133
|
+
export type RegularAtomFamily<T, K extends Canonical> =
|
|
122
134
|
& RegularAtomFamilyToken<T, K>
|
|
123
135
|
& {
|
|
124
136
|
(key: K): RegularAtomToken<T>
|
|
125
|
-
subject: Subject<StateCreation<AtomToken<T>> | StateDisposal<AtomToken<T>>>
|
|
126
137
|
install: (store: Store) => void
|
|
127
138
|
internalRoles: string[] | undefined
|
|
139
|
+
subject: Subject<StateCreation<AtomToken<T>> | StateDisposal<AtomToken<T>>>
|
|
128
140
|
}
|
|
129
141
|
|
|
130
142
|
// biome-ignore format: intersection
|
|
@@ -132,75 +144,85 @@ export type MutableAtomFamily<
|
|
|
132
144
|
T extends Transceiver<any>,
|
|
133
145
|
J extends Json.Serializable,
|
|
134
146
|
K extends Canonical,
|
|
135
|
-
> =
|
|
136
|
-
&
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
147
|
+
> =
|
|
148
|
+
& Flat<
|
|
149
|
+
& JsonInterface<T, J>
|
|
150
|
+
& MutableAtomFamilyToken<T, J, K>
|
|
151
|
+
& {
|
|
152
|
+
install: (store: Store) => void
|
|
153
|
+
internalRoles: string[] | undefined
|
|
154
|
+
subject: Subject<StateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>>
|
|
155
|
+
}
|
|
156
|
+
>
|
|
157
|
+
& ((key: K) => MutableAtomToken<T, J>)
|
|
144
158
|
|
|
145
159
|
export type AtomFamily<T, K extends Canonical = Canonical> =
|
|
146
160
|
| MutableAtomFamily<T extends Transceiver<any> ? T : never, any, K>
|
|
147
161
|
| RegularAtomFamily<T, K>
|
|
148
162
|
|
|
149
163
|
// biome-ignore format: intersection
|
|
150
|
-
export type WritablePureSelectorFamily<T, K extends Canonical> =
|
|
151
|
-
&
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
export type WritablePureSelectorFamily<T, K extends Canonical> =
|
|
165
|
+
& Flat<
|
|
166
|
+
& WritablePureSelectorFamilyToken<T, K>
|
|
167
|
+
& {
|
|
168
|
+
default: (key: K) => T,
|
|
169
|
+
install: (store: Store) => void
|
|
170
|
+
internalRoles: string[] | undefined
|
|
171
|
+
subject: Subject<
|
|
172
|
+
| StateCreation<WritablePureSelectorToken<T>>
|
|
173
|
+
| StateDisposal<WritablePureSelectorToken<T>>
|
|
174
|
+
>
|
|
175
|
+
}
|
|
176
|
+
>
|
|
177
|
+
& ((key: K) => WritablePureSelectorToken<T>)
|
|
162
178
|
|
|
163
179
|
// biome-ignore format: intersection
|
|
164
|
-
export type WritableHeldSelectorFamily<T , K extends Canonical> =
|
|
165
|
-
&
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
export type WritableHeldSelectorFamily<T , K extends Canonical> =
|
|
181
|
+
& Flat<
|
|
182
|
+
& WritableHeldSelectorFamilyToken<T, K>
|
|
183
|
+
& {
|
|
184
|
+
default: (key: K) => T,
|
|
185
|
+
install: (store: Store) => void
|
|
186
|
+
internalRoles: string[] | undefined
|
|
187
|
+
subject: Subject<
|
|
188
|
+
| StateCreation<WritableHeldSelectorToken<T>>
|
|
189
|
+
| StateDisposal<WritableHeldSelectorToken<T>>
|
|
190
|
+
>
|
|
191
|
+
}
|
|
192
|
+
>
|
|
193
|
+
& ((key: K) => WritableHeldSelectorToken<T>)
|
|
176
194
|
|
|
177
195
|
// biome-ignore format: intersection
|
|
178
|
-
export type ReadonlyPureSelectorFamily<T, K extends Canonical> =
|
|
179
|
-
&
|
|
196
|
+
export type ReadonlyPureSelectorFamily<T, K extends Canonical> =
|
|
197
|
+
& Flat<
|
|
198
|
+
& ReadonlyPureSelectorFamilyToken<T, K>
|
|
199
|
+
& {
|
|
200
|
+
default: (key: K) => T,
|
|
201
|
+
install: (store: Store) => void
|
|
202
|
+
internalRoles: string[] | undefined
|
|
203
|
+
subject: Subject<
|
|
204
|
+
| StateCreation<ReadonlyPureSelectorToken<T>>
|
|
205
|
+
| StateDisposal<ReadonlyPureSelectorToken<T>>
|
|
206
|
+
>
|
|
207
|
+
}
|
|
208
|
+
>
|
|
180
209
|
& ((key: K) => ReadonlyPureSelectorToken<T>)
|
|
181
|
-
& {
|
|
182
|
-
default: (key: K) => T,
|
|
183
|
-
subject: Subject<
|
|
184
|
-
| StateCreation<ReadonlyPureSelectorToken<T>>
|
|
185
|
-
| StateDisposal<ReadonlyPureSelectorToken<T>>
|
|
186
|
-
>
|
|
187
|
-
install: (store: Store) => void
|
|
188
|
-
internalRoles : string[] | undefined
|
|
189
|
-
}
|
|
190
210
|
|
|
191
211
|
// biome-ignore format: intersection
|
|
192
|
-
export type ReadonlyHeldSelectorFamily<T , K extends Canonical> =
|
|
193
|
-
&
|
|
212
|
+
export type ReadonlyHeldSelectorFamily<T , K extends Canonical> =
|
|
213
|
+
& Flat<
|
|
214
|
+
& ReadonlyHeldSelectorFamilyToken<T, K>
|
|
215
|
+
& {
|
|
216
|
+
default: (key: K) => T,
|
|
217
|
+
install: (store: Store) => void
|
|
218
|
+
internalRoles: string[] | undefined
|
|
219
|
+
subject: Subject<
|
|
220
|
+
| StateCreation<ReadonlyHeldSelectorToken<T>>
|
|
221
|
+
| StateDisposal<ReadonlyHeldSelectorToken<T>>
|
|
222
|
+
>
|
|
223
|
+
}
|
|
224
|
+
>
|
|
194
225
|
& ((key: K) => ReadonlyHeldSelectorToken<T>)
|
|
195
|
-
& {
|
|
196
|
-
default: (key: K) => T,
|
|
197
|
-
subject: Subject<
|
|
198
|
-
| StateCreation<ReadonlyHeldSelectorToken<T>>
|
|
199
|
-
| StateDisposal<ReadonlyHeldSelectorToken<T>>
|
|
200
|
-
>
|
|
201
|
-
install: (store: Store) => void
|
|
202
|
-
internalRoles : string[] | undefined
|
|
203
|
-
}
|
|
204
226
|
|
|
205
227
|
export type PureSelectorFamily<T, K extends Canonical> =
|
|
206
228
|
| ReadonlyPureSelectorFamily<T, K>
|
|
@@ -8,8 +8,8 @@ import type {
|
|
|
8
8
|
ReadonlyPureSelectorFamilyToken,
|
|
9
9
|
RegularAtomFamilyToken,
|
|
10
10
|
setState,
|
|
11
|
-
SetterToolkit,
|
|
12
11
|
Write,
|
|
12
|
+
WriterToolkit,
|
|
13
13
|
} from "atom.io"
|
|
14
14
|
import { Anarchy } from "atom.io"
|
|
15
15
|
import type { Canonical, Json, stringified } from "atom.io/json"
|
|
@@ -129,7 +129,7 @@ export class Join<
|
|
|
129
129
|
BSide
|
|
130
130
|
> = CompoundTypedKey<`content`, ASide, BSide>,
|
|
131
131
|
> {
|
|
132
|
-
private toolkit:
|
|
132
|
+
private toolkit: WriterToolkit
|
|
133
133
|
public options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>
|
|
134
134
|
public defaultContent: Content | undefined
|
|
135
135
|
public molecules: Map<string, Molecule<any>> = new Map()
|
|
@@ -150,7 +150,7 @@ export class Join<
|
|
|
150
150
|
>
|
|
151
151
|
}
|
|
152
152
|
public transact(
|
|
153
|
-
toolkit:
|
|
153
|
+
toolkit: WriterToolkit,
|
|
154
154
|
run: (join: Join<ASide, AType, BSide, BType, Cardinality, Content>) => void,
|
|
155
155
|
): void {
|
|
156
156
|
const originalToolkit = this.toolkit
|
|
@@ -202,7 +202,6 @@ export class Join<
|
|
|
202
202
|
{
|
|
203
203
|
key: `${options.key}/relatedKeys`,
|
|
204
204
|
default: () => new SetRTX(),
|
|
205
|
-
mutable: true,
|
|
206
205
|
fromJson: (json) => SetRTX.fromJSON(json),
|
|
207
206
|
toJson: (set) => set.toJSON(),
|
|
208
207
|
},
|
|
@@ -3,9 +3,9 @@ import type {
|
|
|
3
3
|
ReadableFamilyToken,
|
|
4
4
|
ReadableToken,
|
|
5
5
|
setState,
|
|
6
|
-
SetterToolkit,
|
|
7
6
|
WritableFamilyToken,
|
|
8
7
|
WritableToken,
|
|
8
|
+
WriterToolkit,
|
|
9
9
|
} from "atom.io"
|
|
10
10
|
import type { Json } from "atom.io/json"
|
|
11
11
|
|
|
@@ -27,7 +27,7 @@ export const registerSelector = (
|
|
|
27
27
|
| `writable_pure_selector`,
|
|
28
28
|
selectorKey: string,
|
|
29
29
|
covered: Set<string>,
|
|
30
|
-
):
|
|
30
|
+
): WriterToolkit => ({
|
|
31
31
|
get: (
|
|
32
32
|
...params:
|
|
33
33
|
| [ReadableFamilyToken<any, any>, Json.Serializable]
|
package/src/json/entries.ts
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
import type { Count, Flat } from "atom.io/internal"
|
|
2
2
|
|
|
3
|
+
/** Tuples of `[key, value]` pairs, as returned from `Object.entries` */
|
|
3
4
|
export type Entries<K extends PropertyKey = PropertyKey, V = any> = [K, V][]
|
|
4
5
|
|
|
6
|
+
/** The collective or "union" type of the keys in a set of entries */
|
|
5
7
|
export type KeyOfEntries<E extends Entries> = E extends [infer K, any][]
|
|
6
8
|
? K
|
|
7
9
|
: never
|
|
8
10
|
|
|
11
|
+
/** The type of the value of entry `K` in a set of entries `E` */
|
|
9
12
|
export type ValueOfEntry<E extends Entries, K extends KeyOfEntries<E>> = {
|
|
10
13
|
[P in Count<E[`length`]>]: E[P] extends [K, infer V] ? V : never
|
|
11
14
|
}[Count<E[`length`]>]
|
|
12
15
|
|
|
16
|
+
/** The type of a set of entries `E` in object form */
|
|
13
17
|
export type FromEntries<E extends Entries> = Flat<{
|
|
14
18
|
[K in KeyOfEntries<E>]: ValueOfEntry<E, K>
|
|
15
19
|
}>
|
|
16
20
|
|
|
21
|
+
/** Typed form of `Object.fromEntries` */
|
|
17
22
|
export function fromEntries<E extends Entries>(entries: E): FromEntries<E> {
|
|
18
23
|
return Object.fromEntries(entries) as FromEntries<E>
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
/** The type of an object T in {@link Entries} form */
|
|
27
|
+
export type ToEntries<T extends object> = Entries<keyof T, T[keyof T]>
|
|
28
|
+
|
|
29
|
+
/** Typed form of `Object.entries` */
|
|
30
|
+
export function toEntries<T extends object>(obj: T): ToEntries<T> {
|
|
24
31
|
return Object.entries(obj) as Entries<keyof T, T[keyof T]>
|
|
25
32
|
}
|
package/src/json/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ export namespace Json {
|
|
|
15
15
|
export type Node = Fork | Leaf
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/** A value can survive being {@link JSON.stringify}-ed and {@link JSON.parse}-d fully intact */
|
|
18
19
|
export type Serializable =
|
|
19
20
|
| primitive
|
|
20
21
|
| Readonly<{ [key: string]: Serializable }>
|
|
@@ -29,33 +30,55 @@ export namespace Json {
|
|
|
29
30
|
ReadonlyArray<Element>
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
/** A generic that retains the type information of a {@link Json.Serializable} value while in string form */
|
|
34
|
+
// biome-ignore format: long silly ternary
|
|
35
|
+
export type stringified<J extends Json.Serializable> = (
|
|
36
|
+
J extends string
|
|
37
|
+
? `"${J}"`
|
|
38
|
+
: J extends number
|
|
39
|
+
? `${J}`
|
|
40
|
+
: J extends true
|
|
41
|
+
? `true`
|
|
42
|
+
: J extends false
|
|
43
|
+
? `false`
|
|
44
|
+
: J extends boolean
|
|
45
|
+
? `false` | `true`
|
|
46
|
+
: J extends null
|
|
47
|
+
? `null`
|
|
48
|
+
: J extends []
|
|
49
|
+
? `[]`
|
|
50
|
+
: J extends [infer Element extends Json.Serializable]
|
|
51
|
+
? `[${stringified<Element>}]`
|
|
52
|
+
: J extends [
|
|
53
|
+
infer Element1 extends Json.Serializable,
|
|
54
|
+
infer Element2 extends Json.Serializable,
|
|
55
|
+
]
|
|
56
|
+
? `[${stringified<Element1>}, ${stringified<Element2>}]`
|
|
57
|
+
: J extends [
|
|
58
|
+
infer Element1 extends Json.Serializable,
|
|
59
|
+
infer Element2 extends Json.Serializable,
|
|
60
|
+
infer Element3 extends Json.Serializable,
|
|
61
|
+
]
|
|
62
|
+
? `[${stringified<Element1>}, ${stringified<Element2>}, ${stringified<Element3>}]`
|
|
63
|
+
: J extends any[]
|
|
64
|
+
? `[${string}]` & { __json?: J }
|
|
65
|
+
: string & { __json?: J }
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
/** Type-safe wrapper for {@link JSON.parse} */
|
|
46
69
|
export const parseJson = <S extends stringified<Json.Serializable>>(
|
|
47
70
|
str: S | string,
|
|
48
71
|
): S extends stringified<infer J> ? J : Json.Serializable => JSON.parse(str)
|
|
49
72
|
|
|
73
|
+
/** Type-safe wrapper for {@link JSON.stringify} */
|
|
50
74
|
export const stringifyJson = <J extends Json.Serializable>(
|
|
51
75
|
json: J,
|
|
52
76
|
): stringified<J> => JSON.stringify(json) as stringified<J>
|
|
53
77
|
|
|
54
|
-
/**
|
|
55
|
-
* Always serializes to the same string.
|
|
56
|
-
*/
|
|
78
|
+
/** Only Canonical values should be used for keys because they always serialize to the same string */
|
|
57
79
|
export type Canonical = primitive | ReadonlyArray<Canonical>
|
|
58
80
|
|
|
81
|
+
/** A function whose parameters and return value are {@link Json.Serializable} */
|
|
59
82
|
export type JsonIO = (...params: Json.Serializable[]) => Json.Serializable | void
|
|
60
83
|
|
|
61
84
|
export type JsonInterface<T, J extends Json.Serializable = Json.Serializable> = {
|