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/main/atom.ts
CHANGED
|
@@ -1,15 +1,54 @@
|
|
|
1
1
|
import type { Transceiver } from "atom.io/internal"
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
createMutableAtom,
|
|
4
|
+
createMutableAtomFamily,
|
|
5
|
+
createRegularAtom,
|
|
6
|
+
createRegularAtomFamily,
|
|
5
7
|
IMPLICIT,
|
|
6
8
|
} from "atom.io/internal"
|
|
7
9
|
import type { Canonical, Json, JsonInterface } from "atom.io/json"
|
|
8
10
|
|
|
9
|
-
import type {
|
|
11
|
+
import type { Setter } from "./set-state"
|
|
12
|
+
import type {
|
|
13
|
+
MutableAtomFamilyToken,
|
|
14
|
+
MutableAtomToken,
|
|
15
|
+
RegularAtomFamilyToken,
|
|
16
|
+
RegularAtomToken,
|
|
17
|
+
} from "./tokens"
|
|
10
18
|
|
|
19
|
+
export type RegularAtomOptions<T> = {
|
|
20
|
+
/** The unique identifier of the atom */
|
|
21
|
+
key: string
|
|
22
|
+
/** The starting value of the atom */
|
|
23
|
+
default: T | (() => T)
|
|
24
|
+
/** Hooks used to run side effects when the atom is set */
|
|
25
|
+
effects?: AtomEffect<T>[]
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a regular atom, a global reactive variable in the implicit store
|
|
29
|
+
* @param options - {@link RegularAtomOptions}.
|
|
30
|
+
* @returns
|
|
31
|
+
* A reference to the atom created: a {@link RegularAtomToken}
|
|
32
|
+
*/
|
|
33
|
+
export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T> {
|
|
34
|
+
return createRegularAtom(IMPLICIT.STORE, options, undefined)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// biome-ignore format: intersection
|
|
38
|
+
export type MutableAtomOptions<
|
|
39
|
+
T extends Transceiver<any>,
|
|
40
|
+
J extends Json.Serializable,
|
|
41
|
+
> =
|
|
42
|
+
& JsonInterface<T, J>
|
|
43
|
+
& {
|
|
44
|
+
/** The unique identifier of the atom */
|
|
45
|
+
key: string
|
|
46
|
+
/** A function to create an initial value for the atom */
|
|
47
|
+
default: () => T
|
|
48
|
+
/** Hooks used to run side effects when the atom is set */
|
|
49
|
+
effects?: AtomEffect<T>[]
|
|
50
|
+
}
|
|
11
51
|
/**
|
|
12
|
-
* @public
|
|
13
52
|
* Create a mutable atom, a global reactive variable in the implicit store
|
|
14
53
|
*
|
|
15
54
|
* The value of a mutable atom must be some kind of {@link Transceiver}.
|
|
@@ -17,27 +56,21 @@ import type { AtomToken, MutableAtomToken, RegularAtomToken, Setter } from "."
|
|
|
17
56
|
* @param options - {@link MutableAtomOptions}.
|
|
18
57
|
* @returns
|
|
19
58
|
* A reference to the atom created: a {@link MutableAtomToken}
|
|
20
|
-
* @overload Mutable
|
|
21
59
|
*/
|
|
22
|
-
export function
|
|
23
|
-
|
|
24
|
-
|
|
60
|
+
export function mutableAtom<
|
|
61
|
+
T extends Transceiver<any>,
|
|
62
|
+
J extends Json.Serializable,
|
|
63
|
+
>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J> {
|
|
64
|
+
return createMutableAtom(IMPLICIT.STORE, options, undefined)
|
|
65
|
+
}
|
|
66
|
+
|
|
25
67
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @param options - {@link RegularAtomOptions}.
|
|
68
|
+
* A function that runs side effects when the atom is set
|
|
69
|
+
* @param tools - {@link Effectors} that can be used to run side effects
|
|
29
70
|
* @returns
|
|
30
|
-
*
|
|
31
|
-
* @overload Regular
|
|
71
|
+
* Optionally, a cleanup function that will be called when the atom is disposed
|
|
32
72
|
*/
|
|
33
|
-
export
|
|
34
|
-
export function atom(
|
|
35
|
-
options: MutableAtomOptions<any, any> | RegularAtomOptions<any>,
|
|
36
|
-
): AtomToken<any> {
|
|
37
|
-
return createStandaloneAtom(IMPLICIT.STORE, options)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** @public */
|
|
73
|
+
export type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void
|
|
41
74
|
export type Effectors<T> = {
|
|
42
75
|
/**
|
|
43
76
|
* Reset the value of the atom to its default
|
|
@@ -52,44 +85,6 @@ export type Effectors<T> = {
|
|
|
52
85
|
onSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void
|
|
53
86
|
}
|
|
54
87
|
|
|
55
|
-
/**
|
|
56
|
-
* @public
|
|
57
|
-
* A function that runs side effects when the atom is set
|
|
58
|
-
* @param tools - {@link Effectors} that can be used to run side effects
|
|
59
|
-
* @returns
|
|
60
|
-
* Optionally, a cleanup function that will be called when the atom is disposed
|
|
61
|
-
*/
|
|
62
|
-
export type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void
|
|
63
|
-
|
|
64
|
-
/** @public */
|
|
65
|
-
export type RegularAtomOptions<T> = {
|
|
66
|
-
/** The unique identifier of the atom */
|
|
67
|
-
key: string
|
|
68
|
-
/** The starting value of the atom */
|
|
69
|
-
default: T | (() => T)
|
|
70
|
-
/** Hooks used to run side effects when the atom is set */
|
|
71
|
-
effects?: AtomEffect<T>[]
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** @public */
|
|
75
|
-
// biome-ignore format: intersection
|
|
76
|
-
export type MutableAtomOptions<
|
|
77
|
-
T extends Transceiver<any>,
|
|
78
|
-
J extends Json.Serializable,
|
|
79
|
-
> =
|
|
80
|
-
& JsonInterface<T, J>
|
|
81
|
-
& {
|
|
82
|
-
/** Used to signal that the atom is mutable */
|
|
83
|
-
mutable: true
|
|
84
|
-
/** The unique identifier of the atom */
|
|
85
|
-
key: string
|
|
86
|
-
/** A function to create an initial value for the atom */
|
|
87
|
-
default: () => T
|
|
88
|
-
/** Hooks used to run side effects when the atom is set */
|
|
89
|
-
effects?: AtomEffect<T>[]
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** @public */
|
|
93
88
|
export type RegularAtomFamilyOptions<T, K extends Canonical> = {
|
|
94
89
|
/** The unique identifier of the atom family */
|
|
95
90
|
key: string
|
|
@@ -98,29 +93,26 @@ export type RegularAtomFamilyOptions<T, K extends Canonical> = {
|
|
|
98
93
|
/** Hooks used to run side effects when an atom in the family is set */
|
|
99
94
|
effects?: (key: K) => AtomEffect<T>[]
|
|
100
95
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Create a family of regular atoms, allowing for the dynamic creation and disposal of atoms.
|
|
98
|
+
* @param options - {@link RegularAtomFamilyOptions}
|
|
99
|
+
* @returns
|
|
100
|
+
* A reference to the atom family created: a {@link RegularAtomFamilyToken}
|
|
101
|
+
*/
|
|
102
|
+
export function atomFamily<T, K extends Canonical>(
|
|
103
|
+
options: RegularAtomFamilyOptions<T, K>,
|
|
104
|
+
): RegularAtomFamilyToken<T, K> {
|
|
105
|
+
return createRegularAtomFamily(IMPLICIT.STORE, options)
|
|
111
106
|
}
|
|
112
107
|
|
|
113
|
-
/** @public */
|
|
114
108
|
// biome-ignore format: intersection
|
|
115
109
|
export type MutableAtomFamilyOptions<
|
|
116
110
|
T extends Transceiver<any>,
|
|
117
111
|
J extends Json.Serializable,
|
|
118
112
|
K extends Canonical,
|
|
119
113
|
> =
|
|
120
|
-
& JsonInterface<T, J>
|
|
114
|
+
& JsonInterface<T, J>
|
|
121
115
|
& {
|
|
122
|
-
/** Used to signal that the atoms created from this family are mutable */
|
|
123
|
-
mutable: true
|
|
124
116
|
/** The unique identifier of the atom family */
|
|
125
117
|
key: string
|
|
126
118
|
/** A function to create an initial value for each atom in the family */
|
|
@@ -128,29 +120,7 @@ export type MutableAtomFamilyOptions<
|
|
|
128
120
|
/** Hooks used to run side effects when an atom in the family is set */
|
|
129
121
|
effects?: (key: K) => AtomEffect<T>[]
|
|
130
122
|
}
|
|
131
|
-
|
|
132
|
-
export type MutableAtomFamilyToken<
|
|
133
|
-
T extends Transceiver<any>,
|
|
134
|
-
J extends Json.Serializable,
|
|
135
|
-
K extends Canonical,
|
|
136
|
-
> = {
|
|
137
|
-
/** The unique identifier of the atom family */
|
|
138
|
-
key: string
|
|
139
|
-
/** Discriminator */
|
|
140
|
-
type: `mutable_atom_family`
|
|
141
|
-
/** Never present. This is a marker that preserves the type of atoms in this family */
|
|
142
|
-
__T?: T
|
|
143
|
-
/** Never present. This is a marker that preserves the type of the JSON form of atoms in this family */
|
|
144
|
-
__J?: J
|
|
145
|
-
/** Never present. This is a marker that preserves the type of keys used for atoms in this family */
|
|
146
|
-
__K?: K
|
|
147
|
-
}
|
|
148
|
-
export type AtomFamilyToken<T, K extends Canonical = Canonical> =
|
|
149
|
-
| MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>
|
|
150
|
-
| RegularAtomFamilyToken<T, K>
|
|
151
|
-
|
|
152
123
|
/**
|
|
153
|
-
* @public
|
|
154
124
|
* Create a family of mutable atoms, allowing for the dynamic creation and disposal of atoms.
|
|
155
125
|
*
|
|
156
126
|
* The value of a mutable atom must be some kind of {@link Transceiver}.
|
|
@@ -158,28 +128,11 @@ export type AtomFamilyToken<T, K extends Canonical = Canonical> =
|
|
|
158
128
|
* @param options - {@link MutableAtomFamilyOptions}
|
|
159
129
|
* @returns
|
|
160
130
|
* A reference to the atom family created: a {@link MutableAtomFamilyToken}
|
|
161
|
-
* @overload Mutable
|
|
162
131
|
*/
|
|
163
|
-
export function
|
|
132
|
+
export function mutableAtomFamily<
|
|
164
133
|
T extends Transceiver<any>,
|
|
165
134
|
J extends Json.Serializable,
|
|
166
135
|
K extends Canonical,
|
|
167
|
-
>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamilyToken<T, J, K>
|
|
168
|
-
|
|
169
|
-
* @public
|
|
170
|
-
* Create a family of regular atoms, allowing for the dynamic creation and disposal of atoms.
|
|
171
|
-
* @param options - {@link RegularAtomFamilyOptions}
|
|
172
|
-
* @returns
|
|
173
|
-
* A reference to the atom family created: a {@link RegularAtomFamilyToken}
|
|
174
|
-
* @overload Regular
|
|
175
|
-
*/
|
|
176
|
-
export function atomFamily<T, K extends Canonical>(
|
|
177
|
-
options: RegularAtomFamilyOptions<T, K>,
|
|
178
|
-
): RegularAtomFamilyToken<T, K>
|
|
179
|
-
export function atomFamily<T, K extends Canonical>(
|
|
180
|
-
options:
|
|
181
|
-
| MutableAtomFamilyOptions<any, any, any>
|
|
182
|
-
| RegularAtomFamilyOptions<T, K>,
|
|
183
|
-
): MutableAtomFamilyToken<any, any, any> | RegularAtomFamilyToken<T, K> {
|
|
184
|
-
return createAtomFamily(IMPLICIT.STORE, options)
|
|
136
|
+
>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamilyToken<T, J, K> {
|
|
137
|
+
return createMutableAtomFamily(IMPLICIT.STORE, options)
|
|
185
138
|
}
|
|
@@ -4,7 +4,6 @@ import type { Canonical } from "atom.io/json"
|
|
|
4
4
|
import type { ReadableFamilyToken, ReadableToken } from "."
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @public
|
|
8
7
|
* Disposes of a state in the implicit store.
|
|
9
8
|
*
|
|
10
9
|
* Only family members can be disposed of.
|
|
@@ -14,7 +13,6 @@ import type { ReadableFamilyToken, ReadableToken } from "."
|
|
|
14
13
|
*/
|
|
15
14
|
export function disposeState(token: ReadableToken<any>): void
|
|
16
15
|
/**
|
|
17
|
-
* @public
|
|
18
16
|
* Disposes of a state in the implicit store.
|
|
19
17
|
*
|
|
20
18
|
* Only family members can be disposed of.
|
package/src/main/find-state.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
MutableAtomFamilyToken,
|
|
3
2
|
MutableAtomToken,
|
|
4
3
|
ReadableFamilyToken,
|
|
5
4
|
ReadableToken,
|
|
6
5
|
ReadonlySelectorFamilyToken,
|
|
7
6
|
ReadonlySelectorToken,
|
|
8
|
-
RegularAtomFamilyToken,
|
|
9
7
|
RegularAtomToken,
|
|
10
8
|
WritableFamilyToken,
|
|
11
9
|
WritableSelectorFamilyToken,
|
|
@@ -16,8 +14,9 @@ import type { Transceiver } from "atom.io/internal"
|
|
|
16
14
|
import { findInStore, IMPLICIT } from "atom.io/internal"
|
|
17
15
|
import type { Canonical, Json } from "atom.io/json"
|
|
18
16
|
|
|
17
|
+
import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
|
|
18
|
+
|
|
19
19
|
/**
|
|
20
|
-
* @public
|
|
21
20
|
* Finds a {@link MutableAtomToken} in the store, without accessing its value.
|
|
22
21
|
*
|
|
23
22
|
* In an ephemeral store, this will create a new atom if one does not exist with the given key.
|
|
@@ -37,7 +36,6 @@ export function findState<
|
|
|
37
36
|
Key extends K,
|
|
38
37
|
>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J, K>
|
|
39
38
|
/**
|
|
40
|
-
* @public
|
|
41
39
|
* Finds a {@link RegularAtomToken} in the store, without accessing its value.
|
|
42
40
|
*
|
|
43
41
|
* In an ephemeral store, this will create a new atom if one does not exist with the given key.
|
|
@@ -55,7 +53,6 @@ export function findState<T, K extends Canonical, Key extends K>(
|
|
|
55
53
|
key: Key,
|
|
56
54
|
): RegularAtomToken<T, K>
|
|
57
55
|
/**
|
|
58
|
-
* @public
|
|
59
56
|
* Finds a {@link WritableSelectorToken} in the store, without accessing its value.
|
|
60
57
|
*
|
|
61
58
|
* In an ephemeral store, this will create a new selector if one does not exist with the given key.
|
|
@@ -73,7 +70,6 @@ export function findState<T, K extends Canonical, Key extends K>(
|
|
|
73
70
|
key: Key,
|
|
74
71
|
): WritableSelectorToken<T, K>
|
|
75
72
|
/**
|
|
76
|
-
* @public
|
|
77
73
|
* Finds a {@link ReadonlySelectorToken} in the store, without accessing its value.
|
|
78
74
|
*
|
|
79
75
|
* In an ephemeral store, this will create a new selector if one does not exist with the given key.
|
|
@@ -91,7 +87,6 @@ export function findState<T, K extends Canonical, Key extends K>(
|
|
|
91
87
|
key: Key,
|
|
92
88
|
): ReadonlySelectorToken<T, K>
|
|
93
89
|
/**
|
|
94
|
-
* @public
|
|
95
90
|
* Finds a {@link WritableToken} in the store, without accessing its value.
|
|
96
91
|
*
|
|
97
92
|
* In an ephemeral store, this will create a new atom or selector if one does not exist with the given key.
|
|
@@ -109,7 +104,6 @@ export function findState<T, K extends Canonical, Key extends K>(
|
|
|
109
104
|
key: Key,
|
|
110
105
|
): WritableToken<T, K>
|
|
111
106
|
/**
|
|
112
|
-
* @public
|
|
113
107
|
* Finds a {@link MutableAtomToken} in the store, without accessing its value.
|
|
114
108
|
*
|
|
115
109
|
* In an ephemeral store, this will create a new atom or selector if one does not exist with the given key.
|
|
@@ -130,7 +124,7 @@ export function findState<T, K extends Canonical, Key extends K>(
|
|
|
130
124
|
|
|
131
125
|
export function findState(
|
|
132
126
|
token: ReadableFamilyToken<any, any>,
|
|
133
|
-
key:
|
|
127
|
+
key: Canonical,
|
|
134
128
|
): ReadableToken<any> {
|
|
135
129
|
const state = findInStore(IMPLICIT.STORE, token, key)
|
|
136
130
|
return state
|
package/src/main/get-state.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { Canonical } from "atom.io/json"
|
|
|
4
4
|
import type { ReadableFamilyToken, ReadableToken } from "."
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @public
|
|
8
7
|
* Read or compute the current value of a state
|
|
9
8
|
* @param token - The token of the state to get
|
|
10
9
|
* @return The current value of the state
|
|
@@ -14,7 +13,6 @@ import type { ReadableFamilyToken, ReadableToken } from "."
|
|
|
14
13
|
export function getState<T>(token: ReadableToken<T>): T
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
|
-
* @public
|
|
18
16
|
* Read or compute the current value of a state
|
|
19
17
|
* @param token - The token of a state family
|
|
20
18
|
* @param key - The unique key of the state to get
|
package/src/main/index.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import type { Transceiver } from "atom.io/internal"
|
|
2
|
-
import type { Canonical, Json, stringified } from "atom.io/json"
|
|
3
|
-
|
|
4
|
-
import type { AtomFamilyToken } from "./atom"
|
|
5
|
-
import type {
|
|
6
|
-
SelectorFamilyToken,
|
|
7
|
-
WritableSelectorFamilyToken,
|
|
8
|
-
} from "./selector"
|
|
9
|
-
import type { TimelineToken } from "./timeline"
|
|
10
|
-
import type { TransactionToken } from "./transaction"
|
|
11
|
-
|
|
12
1
|
export * from "./atom"
|
|
13
2
|
export * from "./dispose-state"
|
|
14
3
|
export * from "./find-state"
|
|
@@ -22,175 +11,11 @@ export * from "./set-state"
|
|
|
22
11
|
export * from "./silo"
|
|
23
12
|
export * from "./subscribe"
|
|
24
13
|
export * from "./timeline"
|
|
14
|
+
export type * from "./tokens"
|
|
25
15
|
export * from "./transaction"
|
|
26
16
|
export * from "./validators"
|
|
27
17
|
|
|
28
18
|
/**
|
|
29
|
-
* @public
|
|
30
|
-
* A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
|
|
31
|
-
*
|
|
32
|
-
* While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank.
|
|
33
|
-
*
|
|
34
|
-
* Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}.
|
|
35
|
-
*
|
|
36
|
-
* Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}.
|
|
37
|
-
*
|
|
38
|
-
* Tokens are fully serializable, so they can be passed between processes.
|
|
39
|
-
*/
|
|
40
|
-
export type AtomIOToken =
|
|
41
|
-
| ReadableFamilyToken<any, any>
|
|
42
|
-
| ReadableToken<any>
|
|
43
|
-
| TimelineToken<any>
|
|
44
|
-
| TransactionToken<any>
|
|
45
|
-
|
|
46
|
-
/** @public */
|
|
47
|
-
export type RegularAtomToken<T, K extends Canonical = any> = {
|
|
48
|
-
/** The unique identifier of the atom. */
|
|
49
|
-
key: string
|
|
50
|
-
/** Discriminator. */
|
|
51
|
-
type: `atom`
|
|
52
|
-
/** Present if the atom belongs to a family. */
|
|
53
|
-
family?: FamilyMetadata<K>
|
|
54
|
-
/** Never present. This is a marker that preserves the type of the atom's value. */
|
|
55
|
-
__T?: T
|
|
56
|
-
}
|
|
57
|
-
/** @public */
|
|
58
|
-
export type MutableAtomToken<
|
|
59
|
-
T extends Transceiver<any>,
|
|
60
|
-
J extends Json.Serializable,
|
|
61
|
-
K extends Canonical = any,
|
|
62
|
-
> = {
|
|
63
|
-
/** The unique identifier of the atom. */
|
|
64
|
-
key: string
|
|
65
|
-
/** Discriminator. */
|
|
66
|
-
type: `mutable_atom`
|
|
67
|
-
/** Present if the atom belongs to a family. */
|
|
68
|
-
family?: FamilyMetadata<K>
|
|
69
|
-
/** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
|
|
70
|
-
__J?: J
|
|
71
|
-
/** Never present. This is a marker that preserves the type of the atom's transceiver value. */
|
|
72
|
-
__U?: T extends Transceiver<infer Update> ? Update : never
|
|
73
|
-
}
|
|
74
|
-
/** @public */
|
|
75
|
-
export type AtomToken<T, K extends Canonical = any> =
|
|
76
|
-
| MutableAtomToken<T extends Transceiver<any> ? T : never, any, K>
|
|
77
|
-
| RegularAtomToken<T, K>
|
|
78
|
-
|
|
79
|
-
/** @public */
|
|
80
|
-
export type WritablePureSelectorToken<T, K extends Canonical = any> = {
|
|
81
|
-
/** The unique identifier of the selector. */
|
|
82
|
-
key: string
|
|
83
|
-
/** Discriminator. */
|
|
84
|
-
type: `writable_pure_selector`
|
|
85
|
-
/** Present if the selector belongs to a family. */
|
|
86
|
-
family?: FamilyMetadata<K>
|
|
87
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
88
|
-
__T?: T
|
|
89
|
-
}
|
|
90
|
-
/** @public */
|
|
91
|
-
export type WritableHeldSelectorToken<T, K extends Canonical = any> = {
|
|
92
|
-
/** The unique identifier of the selector. */
|
|
93
|
-
key: string
|
|
94
|
-
/** Discriminator. */
|
|
95
|
-
type: `writable_held_selector`
|
|
96
|
-
/** Present if the selector belongs to a family. */
|
|
97
|
-
family?: FamilyMetadata<K>
|
|
98
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
99
|
-
__T?: T
|
|
100
|
-
}
|
|
101
|
-
/** @public */
|
|
102
|
-
export type ReadonlyPureSelectorToken<T, K extends Canonical = any> = {
|
|
103
|
-
/** The unique identifier of the selector. */
|
|
104
|
-
key: string
|
|
105
|
-
/** Discriminator. */
|
|
106
|
-
type: `readonly_pure_selector`
|
|
107
|
-
/** Present if the selector belongs to a family. */
|
|
108
|
-
family?: FamilyMetadata<K>
|
|
109
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
110
|
-
__T?: T
|
|
111
|
-
}
|
|
112
|
-
/** @public */
|
|
113
|
-
export type ReadonlyHeldSelectorToken<T, K extends Canonical = any> = {
|
|
114
|
-
/** The unique identifier of the selector. */
|
|
115
|
-
key: string
|
|
116
|
-
/** Discriminator. */
|
|
117
|
-
type: `readonly_held_selector`
|
|
118
|
-
/** Present if the selector belongs to a family. */
|
|
119
|
-
family?: FamilyMetadata<K>
|
|
120
|
-
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
121
|
-
__T?: T
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** @public */
|
|
125
|
-
export type PureSelectorToken<T, K extends Canonical = any> =
|
|
126
|
-
| ReadonlyPureSelectorToken<T, K>
|
|
127
|
-
| WritablePureSelectorToken<T, K>
|
|
128
|
-
|
|
129
|
-
/** @public */
|
|
130
|
-
export type HeldSelectorToken<T, K extends Canonical = any> =
|
|
131
|
-
| ReadonlyHeldSelectorToken<T, K>
|
|
132
|
-
| WritableHeldSelectorToken<T, K>
|
|
133
|
-
|
|
134
|
-
/** @public */
|
|
135
|
-
export type ReadonlySelectorToken<T, K extends Canonical = any> =
|
|
136
|
-
| ReadonlyHeldSelectorToken<T, K>
|
|
137
|
-
| ReadonlyPureSelectorToken<T, K>
|
|
138
|
-
|
|
139
|
-
/** @public */
|
|
140
|
-
export type WritableSelectorToken<T, K extends Canonical = any> =
|
|
141
|
-
| WritableHeldSelectorToken<T, K>
|
|
142
|
-
| WritablePureSelectorToken<T, K>
|
|
143
|
-
|
|
144
|
-
/** @public */
|
|
145
|
-
export type SelectorToken<T, K extends Canonical = any> =
|
|
146
|
-
| ReadonlyHeldSelectorToken<T, K>
|
|
147
|
-
| ReadonlyPureSelectorToken<T, K>
|
|
148
|
-
| WritableHeldSelectorToken<T, K>
|
|
149
|
-
| WritablePureSelectorToken<T, K>
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @public
|
|
153
|
-
* These states can be set.
|
|
154
|
-
*/
|
|
155
|
-
export type WritableToken<T, K extends Canonical = any> =
|
|
156
|
-
| AtomToken<T, K>
|
|
157
|
-
| WritableSelectorToken<T, K>
|
|
158
|
-
/**
|
|
159
|
-
* @public
|
|
160
|
-
* These states cannot be set.
|
|
161
|
-
*/
|
|
162
|
-
export type ReadableToken<T, K extends Canonical = any> =
|
|
163
|
-
| AtomToken<T, K>
|
|
164
|
-
| SelectorToken<T, K>
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @public
|
|
168
|
-
* States belonging to this family can be set.
|
|
169
|
-
*/
|
|
170
|
-
export type WritableFamilyToken<T, K extends Canonical> =
|
|
171
|
-
| AtomFamilyToken<T, K>
|
|
172
|
-
| WritableSelectorFamilyToken<T, K>
|
|
173
|
-
/**
|
|
174
|
-
* @public
|
|
175
|
-
* States belonging to this family cannot be set.
|
|
176
|
-
*/
|
|
177
|
-
export type ReadableFamilyToken<T, K extends Canonical> =
|
|
178
|
-
| AtomFamilyToken<T, K>
|
|
179
|
-
| SelectorFamilyToken<T, K>
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* @public
|
|
183
|
-
* Identifies a state's connection to its family.
|
|
184
|
-
*/
|
|
185
|
-
export type FamilyMetadata<K extends Canonical = any> = {
|
|
186
|
-
/** The family's unique key. */
|
|
187
|
-
key: string
|
|
188
|
-
/** The family member's unique identifier, in the form of a string. */
|
|
189
|
-
subKey: stringified<K>
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* @public
|
|
194
19
|
* Loadable is used to type atoms or selectors that may at some point be initialized to or set to a {@link Promise}.
|
|
195
20
|
*
|
|
196
21
|
* When a Promise is cached as the value of a state in atom.io, that state will be automatically set to the resolved value of the Promise when it is resolved.
|
package/src/main/join.ts
CHANGED
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
import type { Json } from "atom.io/json"
|
|
17
17
|
import type { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
18
18
|
|
|
19
|
-
/** @public */
|
|
20
19
|
// biome-ignore format: intersection
|
|
21
20
|
export type JoinOptions<
|
|
22
21
|
ASide extends string,
|
|
@@ -25,7 +24,7 @@ export type JoinOptions<
|
|
|
25
24
|
BType extends string,
|
|
26
25
|
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
27
26
|
Content extends Json.Object | null,
|
|
28
|
-
> =
|
|
27
|
+
> =
|
|
29
28
|
Flat<
|
|
30
29
|
& JunctionSchemaBase<ASide, BSide>
|
|
31
30
|
& {
|
|
@@ -40,7 +39,6 @@ export type JoinOptions<
|
|
|
40
39
|
}
|
|
41
40
|
> & Partial<JunctionEntriesBase<AType, BType, Content>>
|
|
42
41
|
|
|
43
|
-
/** @public */
|
|
44
42
|
export type JoinToken<
|
|
45
43
|
ASide extends string,
|
|
46
44
|
AType extends string,
|
|
@@ -68,7 +66,6 @@ export type JoinToken<
|
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
/**
|
|
71
|
-
* @public
|
|
72
69
|
* Create a join, an interface for managing relations between two sets of keys.
|
|
73
70
|
*
|
|
74
71
|
* Use joins when it is important to view relationships from either side.
|
|
@@ -91,19 +88,7 @@ export function join<
|
|
|
91
88
|
options: JoinOptions<ASide, AType, BSide, BType, Cardinality, null>,
|
|
92
89
|
defaultContent?: undefined,
|
|
93
90
|
): JoinToken<ASide, AType, BSide, BType, Cardinality, null>
|
|
94
|
-
export function join<
|
|
95
|
-
const ASide extends string,
|
|
96
|
-
const AType extends string,
|
|
97
|
-
const BSide extends string,
|
|
98
|
-
const BType extends string,
|
|
99
|
-
const Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
100
|
-
const Content extends Json.Object,
|
|
101
|
-
>(
|
|
102
|
-
options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
103
|
-
defaultContent: Content,
|
|
104
|
-
): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>
|
|
105
91
|
/**
|
|
106
|
-
* @public
|
|
107
92
|
* Create a join, an interface for managing relations between two sets of keys.
|
|
108
93
|
*
|
|
109
94
|
* Use joins when it is important to view relationships from either side.
|
|
@@ -116,6 +101,17 @@ export function join<
|
|
|
116
101
|
* A reference to the join created: a {@link JoinToken}
|
|
117
102
|
* @overload With Content
|
|
118
103
|
*/
|
|
104
|
+
export function join<
|
|
105
|
+
const ASide extends string,
|
|
106
|
+
const AType extends string,
|
|
107
|
+
const BSide extends string,
|
|
108
|
+
const BType extends string,
|
|
109
|
+
const Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
110
|
+
const Content extends Json.Object,
|
|
111
|
+
>(
|
|
112
|
+
options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
113
|
+
defaultContent: Content,
|
|
114
|
+
): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>
|
|
119
115
|
export function join<
|
|
120
116
|
ASide extends string,
|
|
121
117
|
AType extends string,
|
|
@@ -130,7 +126,6 @@ export function join<
|
|
|
130
126
|
return createJoin(IMPLICIT.STORE, options, defaultContent)
|
|
131
127
|
}
|
|
132
128
|
|
|
133
|
-
/** @public */
|
|
134
129
|
export type JoinStates<
|
|
135
130
|
ASide extends string,
|
|
136
131
|
AType extends string,
|
|
@@ -213,7 +208,6 @@ export type JoinStates<
|
|
|
213
208
|
: never
|
|
214
209
|
|
|
215
210
|
/**
|
|
216
|
-
* @public
|
|
217
211
|
* Find the current value of a relation owned by a {@link join}
|
|
218
212
|
* @param token - The token of the join
|
|
219
213
|
* @param key - The key of the relation to find
|
|
@@ -236,7 +230,6 @@ export function findRelations<
|
|
|
236
230
|
}
|
|
237
231
|
|
|
238
232
|
/**
|
|
239
|
-
* @public
|
|
240
233
|
* Change one or multiple relations owned by a {@link join}
|
|
241
234
|
* @param token - The token of the join
|
|
242
235
|
* @param change - A function that takes a {@link Junction} interface to edit the relations
|
|
@@ -256,7 +249,6 @@ export function editRelations<
|
|
|
256
249
|
}
|
|
257
250
|
|
|
258
251
|
/**
|
|
259
|
-
* @public
|
|
260
252
|
* @param token - The token of the join
|
|
261
253
|
* @returns
|
|
262
254
|
* A {@link MutableAtomFamilyToken} to access the internal relations
|
package/src/main/reset-state.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { Canonical } from "atom.io/json"
|
|
|
4
4
|
import type { WritableFamilyToken, WritableToken } from "."
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @public
|
|
8
7
|
* Set the value of a state into the implicit store back to its default value.
|
|
9
8
|
* @param token - An atom or writable selector token.
|
|
10
9
|
* @overload Default
|
|
@@ -12,7 +11,6 @@ import type { WritableFamilyToken, WritableToken } from "."
|
|
|
12
11
|
*/
|
|
13
12
|
export function resetState(token: WritableToken<any>): void
|
|
14
13
|
/**
|
|
15
|
-
* @public
|
|
16
14
|
* Set the value of a state into the implicit store back to its default value.
|
|
17
15
|
* @param token - An atom family or writable selector family token.
|
|
18
16
|
* @param key - The unique key of the state to set.
|