atom.io 0.15.6 → 0.16.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 +20 -22
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.ts +6 -6
- package/data/dist/index.js +21 -23
- package/data/dist/index.js.map +1 -1
- package/data/src/dict.ts +6 -7
- package/data/src/join.ts +23 -23
- package/data/src/struct-family.ts +2 -2
- package/data/src/struct.ts +4 -5
- package/dist/index.cjs +12 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +67 -60
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +910 -887
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +157 -162
- package/internal/dist/index.js +482 -458
- package/internal/dist/index.js.map +1 -1
- package/internal/src/atom/create-regular-atom.ts +9 -12
- package/internal/src/atom/create-standalone-atom.ts +33 -0
- package/internal/src/atom/delete-atom.ts +5 -2
- package/internal/src/atom/index.ts +1 -16
- package/internal/src/atom/is-default.ts +0 -1
- package/internal/src/caching.ts +6 -3
- package/internal/src/families/create-atom-family.ts +11 -7
- package/internal/src/families/create-readonly-selector-family.ts +4 -3
- package/internal/src/families/create-regular-atom-family.ts +12 -27
- package/internal/src/families/create-selector-family.ts +13 -49
- package/internal/src/families/create-writable-selector-family.ts +51 -0
- package/internal/src/index.ts +44 -3
- package/internal/src/lineage.ts +0 -7
- package/internal/src/mutable/create-mutable-atom-family.ts +61 -15
- package/internal/src/mutable/create-mutable-atom.ts +70 -25
- package/internal/src/mutable/get-json-family.ts +4 -5
- package/internal/src/mutable/get-json-token.ts +6 -3
- package/internal/src/mutable/get-update-token.ts +3 -3
- package/internal/src/mutable/index.ts +1 -7
- package/internal/src/mutable/is-mutable.ts +6 -7
- package/internal/src/mutable/tracker-family.ts +4 -4
- package/internal/src/mutable/tracker.ts +6 -6
- package/internal/src/read-or-compute-value.ts +6 -3
- package/internal/src/selector/create-readonly-selector.ts +2 -3
- package/internal/src/selector/create-standalone-selector.ts +32 -0
- package/internal/src/selector/{create-read-write-selector.ts → create-writable-selector.ts} +12 -9
- package/internal/src/selector/delete-selector.ts +2 -2
- package/internal/src/selector/index.ts +3 -1
- package/internal/src/selector/trace-selector-atoms.ts +3 -2
- package/internal/src/selector/update-selector-atoms.ts +1 -1
- package/internal/src/set-state/copy-mutable-if-needed.ts +5 -6
- package/internal/src/set-state/copy-mutable-in-transaction.ts +4 -36
- package/internal/src/set-state/emit-update.ts +2 -3
- package/internal/src/set-state/evict-downstream.ts +1 -1
- package/internal/src/set-state/set-atom-or-selector.ts +3 -3
- package/internal/src/set-state/set-atom.ts +1 -2
- package/internal/src/set-state/stow-update.ts +1 -1
- package/internal/src/store/deposit.ts +25 -13
- package/internal/src/store/store.ts +21 -21
- package/internal/src/store/withdraw-new-family-member.ts +16 -9
- package/internal/src/store/withdraw.ts +43 -19
- package/internal/src/subscribe/recall-state.ts +2 -6
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +39 -41
- package/internal/src/subscribe/subscribe-to-state.ts +3 -1
- package/internal/src/timeline/add-atom-to-timeline.ts +5 -5
- package/internal/src/timeline/create-timeline.ts +19 -22
- package/introspection/dist/index.cjs +4 -8
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +5 -5
- package/introspection/dist/index.js +5 -9
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-atom-index.ts +4 -5
- package/introspection/src/attach-selector-index.ts +4 -5
- package/introspection/src/attach-timeline-index.ts +6 -3
- package/introspection/src/attach-transaction-index.ts +6 -3
- package/introspection/src/index.ts +9 -5
- package/json/dist/index.cjs +3 -4
- package/json/dist/index.cjs.map +1 -1
- package/json/dist/index.d.ts +4 -3
- package/json/dist/index.js +4 -5
- package/json/dist/index.js.map +1 -1
- package/json/src/select-json-family.ts +24 -4
- package/json/src/select-json.ts +3 -4
- package/package.json +2 -2
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.d.ts +9 -9
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateIndex.tsx +18 -10
- package/react-devtools/src/TimelineIndex.tsx +6 -2
- package/react-devtools/src/TransactionIndex.tsx +2 -2
- package/realtime-client/dist/index.cjs +27 -13
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +6 -4
- package/realtime-client/dist/index.js +20 -7
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +4 -3
- package/realtime-client/src/server-action.ts +2 -55
- package/realtime-client/src/sync-server-action.ts +75 -0
- package/realtime-react/dist/index.cjs +22 -13
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +3 -1
- package/realtime-react/dist/index.js +20 -12
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/index.ts +1 -0
- package/realtime-react/src/use-server-action.ts +2 -4
- package/realtime-react/src/use-sync-server-action.ts +19 -0
- package/realtime-server/dist/index.cjs +83 -81
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +8 -8
- package/realtime-server/dist/index.js +58 -56
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/index.ts +15 -1
- package/realtime-server/src/{hook-composition/receive-transaction.ts → realtime-action-receiver.ts} +6 -2
- package/realtime-server/src/{hook-composition/sync-transaction.ts → realtime-action-synchronizer.ts} +10 -43
- package/realtime-server/src/{hook-composition/expose-family.ts → realtime-family-provider.ts} +9 -23
- package/realtime-server/src/{hook-composition/expose-mutable-family.ts → realtime-mutable-family-provider.ts} +4 -4
- package/realtime-server/src/{hook-composition/expose-mutable.ts → realtime-mutable-provider.ts} +4 -5
- package/realtime-server/src/realtime-server-store.ts +39 -0
- package/realtime-server/src/{hook-composition/expose-single.ts → realtime-state-provider.ts} +7 -8
- package/realtime-server/src/{hook-composition/receive-state.ts → realtime-state-receiver.ts} +7 -4
- package/src/atom.ts +39 -24
- package/src/find-state.ts +20 -19
- package/src/index.ts +41 -28
- package/src/logger.ts +1 -0
- package/src/selector.ts +31 -16
- package/src/silo.ts +45 -6
- package/src/subscribe.ts +1 -0
- package/src/validators.ts +35 -25
- package/internal/src/atom/create-atom.ts +0 -21
- package/internal/src/mutable/get-update-family.ts +0 -23
- package/internal/src/selector/create-selector.ts +0 -65
- package/realtime-server/src/hook-composition/index.ts +0 -15
- /package/realtime-client/src/{pull.ts → pull-state.ts} +0 -0
- /package/realtime-client/src/{push.ts → push-state.ts} +0 -0
- /package/realtime-client/src/{realtime-state.ts → realtime-client-store.ts} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Internal from 'atom.io/internal';
|
|
2
2
|
import { Transceiver, Subject, Store, EnvironmentData, Timeline, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
|
|
3
3
|
import { Json, JsonInterface } from 'atom.io/json';
|
|
4
|
-
import { ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1, MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1,
|
|
4
|
+
import { ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1, MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1, RegularAtomFamilyToken as RegularAtomFamilyToken$1, RegularAtomToken as RegularAtomToken$1, WritableSelectorFamilyToken as WritableSelectorFamilyToken$1, WritableSelectorToken as WritableSelectorToken$1, ReadonlySelectorFamilyToken as ReadonlySelectorFamilyToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, WritableFamilyToken as WritableFamilyToken$1, WritableToken as WritableToken$1, ReadableFamily as ReadableFamily$1, RegularAtomFamily as RegularAtomFamily$1, MutableAtomFamily as MutableAtomFamily$1, WritableSelectorFamily as WritableSelectorFamily$1, ReadonlySelectorFamily as ReadonlySelectorFamily$1, WritableFamily as WritableFamily$1 } from 'atom.io';
|
|
5
5
|
|
|
6
6
|
type Effectors<T> = {
|
|
7
7
|
setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void;
|
|
@@ -11,45 +11,46 @@ type Effectors<T> = {
|
|
|
11
11
|
}) => void) => void;
|
|
12
12
|
};
|
|
13
13
|
type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void;
|
|
14
|
-
type
|
|
14
|
+
type RegularAtomOptions<T> = {
|
|
15
15
|
key: string;
|
|
16
16
|
default: T | (() => T);
|
|
17
17
|
effects?: AtomEffect<T>[];
|
|
18
18
|
};
|
|
19
|
-
type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = JsonInterface<T, J> & Omit<
|
|
19
|
+
type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = JsonInterface<T, J> & Omit<RegularAtomOptions<T>, `default`> & {
|
|
20
20
|
default: () => T;
|
|
21
21
|
mutable: true;
|
|
22
22
|
};
|
|
23
23
|
declare function atom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>;
|
|
24
|
-
declare function atom<T>(options:
|
|
25
|
-
type
|
|
24
|
+
declare function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>;
|
|
25
|
+
type RegularAtomFamilyOptions<T, K extends Json.Serializable> = {
|
|
26
26
|
key: string;
|
|
27
27
|
default: T | ((key: K) => T);
|
|
28
28
|
effects?: (key: K) => AtomEffect<T>[];
|
|
29
29
|
};
|
|
30
|
-
type
|
|
30
|
+
type RegularAtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => RegularAtomToken<T>) & {
|
|
31
31
|
key: string;
|
|
32
32
|
type: `atom_family`;
|
|
33
|
-
subject: Subject<
|
|
34
|
-
mutable?: boolean;
|
|
33
|
+
subject: Subject<RegularAtomToken<T>>;
|
|
35
34
|
install: (store: Store) => void;
|
|
36
35
|
__T?: T;
|
|
37
36
|
__K?: K;
|
|
38
37
|
};
|
|
39
|
-
type
|
|
38
|
+
type RegularAtomFamilyToken<T, K extends Json.Serializable> = {
|
|
40
39
|
key: string;
|
|
41
40
|
type: `atom_family`;
|
|
42
41
|
__T?: T;
|
|
43
42
|
__K?: K;
|
|
44
43
|
};
|
|
45
|
-
type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> =
|
|
44
|
+
type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> = JsonInterface<T, J> & {
|
|
45
|
+
key: string;
|
|
46
|
+
default: (key: K) => T;
|
|
47
|
+
effects?: (key: K) => AtomEffect<T>[];
|
|
46
48
|
mutable: true;
|
|
47
49
|
};
|
|
48
50
|
type MutableAtomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> = JsonInterface<T, J> & ((key: K) => MutableAtomToken<T, J>) & {
|
|
49
51
|
key: string;
|
|
50
|
-
type: `
|
|
52
|
+
type: `mutable_atom_family`;
|
|
51
53
|
subject: Subject<MutableAtomToken<T, J>>;
|
|
52
|
-
mutable: true;
|
|
53
54
|
install: (store: Store) => void;
|
|
54
55
|
__T?: T;
|
|
55
56
|
__J?: J;
|
|
@@ -57,14 +58,15 @@ type MutableAtomFamily<T extends Transceiver<any>, J extends Json.Serializable,
|
|
|
57
58
|
};
|
|
58
59
|
type MutableAtomFamilyToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> = {
|
|
59
60
|
key: string;
|
|
60
|
-
type: `
|
|
61
|
-
mutable: true;
|
|
61
|
+
type: `mutable_atom_family`;
|
|
62
62
|
__T?: T;
|
|
63
63
|
__J?: J;
|
|
64
64
|
__K?: K;
|
|
65
65
|
};
|
|
66
|
+
type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = MutableAtomFamily<T extends Transceiver<any> ? T : never, any, K> | RegularAtomFamily<T, K>;
|
|
67
|
+
type AtomFamilyToken<T, K extends Json.Serializable = Json.Serializable> = MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomFamilyToken<T, K>;
|
|
66
68
|
declare function atomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>;
|
|
67
|
-
declare function atomFamily<T, K extends Json.Serializable>(options:
|
|
69
|
+
declare function atomFamily<T, K extends Json.Serializable>(options: RegularAtomFamilyOptions<T, K>): RegularAtomFamily<T, K>;
|
|
68
70
|
|
|
69
71
|
type TransactionToken<_> = {
|
|
70
72
|
key: string;
|
|
@@ -103,7 +105,7 @@ type TransactionIO<Token extends TransactionToken<any>> = Token extends Transact
|
|
|
103
105
|
declare function transaction<ƒ extends ƒn>(options: TransactionOptions<ƒ>): TransactionToken<ƒ>;
|
|
104
106
|
declare const runTransaction: <ƒ extends ƒn>(token: TransactionToken<ƒ>, store?: Store, id?: string) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
105
107
|
|
|
106
|
-
type
|
|
108
|
+
type WritableSelectorOptions<T> = {
|
|
107
109
|
key: string;
|
|
108
110
|
get: Read<() => T>;
|
|
109
111
|
set: Write<(newValue: T) => void>;
|
|
@@ -112,9 +114,9 @@ type ReadonlySelectorOptions<T> = {
|
|
|
112
114
|
key: string;
|
|
113
115
|
get: Read<() => T>;
|
|
114
116
|
};
|
|
115
|
-
declare function selector<T>(options:
|
|
117
|
+
declare function selector<T>(options: WritableSelectorOptions<T>): WritableSelectorToken<T>;
|
|
116
118
|
declare function selector<T>(options: ReadonlySelectorOptions<T>): ReadonlySelectorToken<T>;
|
|
117
|
-
type
|
|
119
|
+
type WritableSelectorFamilyOptions<T, K extends Json.Serializable> = {
|
|
118
120
|
key: string;
|
|
119
121
|
get: (key: K) => Read<() => T>;
|
|
120
122
|
set: (key: K) => Write<(newValue: T) => void>;
|
|
@@ -123,15 +125,15 @@ type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {
|
|
|
123
125
|
key: string;
|
|
124
126
|
get: (key: K) => Read<() => T>;
|
|
125
127
|
};
|
|
126
|
-
type
|
|
128
|
+
type WritableSelectorFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => WritableSelectorToken<T>) & {
|
|
127
129
|
key: string;
|
|
128
130
|
type: `selector_family`;
|
|
129
|
-
subject: Subject<
|
|
131
|
+
subject: Subject<WritableSelectorToken<T>>;
|
|
130
132
|
install: (store: Store) => void;
|
|
131
133
|
__T?: T;
|
|
132
134
|
__K?: K;
|
|
133
135
|
};
|
|
134
|
-
type
|
|
136
|
+
type WritableSelectorFamilyToken<T, K extends Json.Serializable> = {
|
|
135
137
|
key: string;
|
|
136
138
|
type: `selector_family`;
|
|
137
139
|
__T?: T;
|
|
@@ -151,18 +153,20 @@ type ReadonlySelectorFamilyToken<T, K extends Json.Serializable> = {
|
|
|
151
153
|
__T?: T;
|
|
152
154
|
__K?: K;
|
|
153
155
|
};
|
|
154
|
-
|
|
156
|
+
type SelectorFamily<T, K extends Json.Serializable> = ReadonlySelectorFamily<T, K> | WritableSelectorFamily<T, K>;
|
|
157
|
+
type SelectorFamilyToken<T, K extends Json.Serializable> = ReadonlySelectorFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
|
|
158
|
+
declare function selectorFamily<T, K extends Json.Serializable>(options: WritableSelectorFamilyOptions<T, K>): WritableSelectorFamily<T, K>;
|
|
155
159
|
declare function selectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamily<T, K>;
|
|
156
160
|
|
|
157
161
|
declare function dispose(token: ReadableToken<any>, store?: Internal.Store): void;
|
|
158
162
|
|
|
159
163
|
declare function findInStore(token: ReadableFamilyToken$1<any, any>, key: Json.Serializable, store: Store): ReadableToken$1<any>;
|
|
160
|
-
declare function findState<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable>(token: MutableAtomFamilyToken$1<T, J, K>, key:
|
|
161
|
-
declare function findState<T, K extends Json.Serializable>(token:
|
|
162
|
-
declare function findState<T, K extends Json.Serializable>(token:
|
|
163
|
-
declare function findState<T, K extends Json.Serializable>(token: ReadonlySelectorFamilyToken$1<T, K>, key:
|
|
164
|
-
declare function findState<T, K extends Json.Serializable>(token: WritableFamilyToken$1<T, K>, key:
|
|
165
|
-
declare function findState<T, K extends Json.Serializable>(token: ReadableFamilyToken$1<T, K>, key:
|
|
164
|
+
declare function findState<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable, Key extends K>(token: MutableAtomFamilyToken$1<T, J, K>, key: Key): MutableAtomToken$1<T, J>;
|
|
165
|
+
declare function findState<T, K extends Json.Serializable, Key extends K>(token: RegularAtomFamilyToken$1<T, K>, key: Key): RegularAtomToken$1<T>;
|
|
166
|
+
declare function findState<T, K extends Json.Serializable, Key extends K>(token: WritableSelectorFamilyToken$1<T, K>, key: Key): WritableSelectorToken$1<T>;
|
|
167
|
+
declare function findState<T, K extends Json.Serializable, Key extends K>(token: ReadonlySelectorFamilyToken$1<T, K>, key: Key): ReadonlySelectorToken$1<T>;
|
|
168
|
+
declare function findState<T, K extends Json.Serializable, Key extends K>(token: WritableFamilyToken$1<T, K>, key: Key): WritableToken$1<T>;
|
|
169
|
+
declare function findState<T, K extends Json.Serializable, Key extends K>(token: ReadableFamilyToken$1<T, K>, key: Key): ReadableToken$1<T>;
|
|
166
170
|
|
|
167
171
|
declare function getState<T>(token: ReadableToken<T>, store?: Internal.Store): T;
|
|
168
172
|
|
|
@@ -209,7 +213,7 @@ declare const LoggerIconDictionary: {
|
|
|
209
213
|
type LoggerIcon = keyof typeof LoggerIconDictionary;
|
|
210
214
|
declare const LOG_LEVELS: readonly ["info", "warn", "error"];
|
|
211
215
|
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
212
|
-
type LogFn = (icon: LoggerIcon, tokenType: `atom` | `readonly_selector` | `selector` | `state` | `timeline` | `transaction` | `unknown`, tokenKey: string, message: string, ...rest: unknown[]) => void;
|
|
216
|
+
type LogFn = (icon: LoggerIcon, tokenType: `atom` | `mutable_atom` | `readonly_selector` | `selector` | `state` | `timeline` | `transaction` | `unknown`, tokenKey: string, message: string, ...rest: unknown[]) => void;
|
|
213
217
|
type LogFilter = (...params: Parameters<LogFn>) => boolean;
|
|
214
218
|
type Logger = Record<LogLevel, LogFn>;
|
|
215
219
|
declare const simpleLog: (logLevel: keyof Logger) => LogFn;
|
|
@@ -273,53 +277,56 @@ declare const redo: (timeline: TimelineToken<any>) => void;
|
|
|
273
277
|
declare const undo: (timeline: TimelineToken<any>) => void;
|
|
274
278
|
|
|
275
279
|
type TokenType<Comparison extends ReadableFamily$1<any, any> | ReadableToken$1<any>> = Comparison extends ReadableToken$1<infer RepresentedValue> ? RepresentedValue : Comparison extends ReadableFamily$1<infer RepresentedValue, any> ? RepresentedValue : never;
|
|
276
|
-
declare function isToken<KnownToken extends
|
|
277
|
-
declare function isToken<KnownToken extends
|
|
278
|
-
declare function isToken<KnownToken extends
|
|
279
|
-
declare function isToken<KnownToken extends
|
|
280
|
-
declare function isToken<KnownToken extends WritableToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<
|
|
281
|
-
declare function
|
|
282
|
-
declare function belongsTo<Family extends
|
|
283
|
-
declare function belongsTo<Family extends
|
|
284
|
-
declare function belongsTo<Family extends
|
|
285
|
-
declare function belongsTo<Family extends
|
|
280
|
+
declare function isToken<KnownToken extends RegularAtomToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is RegularAtomToken$1<TokenType<KnownToken>>;
|
|
281
|
+
declare function isToken<KnownToken extends MutableAtomToken$1<any, any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is MutableAtomToken$1<TokenType<KnownToken>, any>;
|
|
282
|
+
declare function isToken<KnownToken extends WritableSelectorToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is WritableSelectorToken$1<TokenType<KnownToken>>;
|
|
283
|
+
declare function isToken<KnownToken extends ReadonlySelectorToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is ReadonlySelectorToken$1<TokenType<KnownToken>>;
|
|
284
|
+
declare function isToken<KnownToken extends WritableToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is WritableToken$1<TokenType<KnownToken>>;
|
|
285
|
+
declare function isToken<KnownToken extends ReadableToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is ReadableToken$1<TokenType<KnownToken>>;
|
|
286
|
+
declare function belongsTo<Family extends RegularAtomFamily$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is RegularAtomToken$1<TokenType<Family>>;
|
|
287
|
+
declare function belongsTo<Family extends MutableAtomFamily$1<any, any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is MutableAtomToken$1<TokenType<Family>, any>;
|
|
288
|
+
declare function belongsTo<Family extends WritableSelectorFamily$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is WritableSelectorToken$1<TokenType<Family>>;
|
|
289
|
+
declare function belongsTo<Family extends ReadonlySelectorFamily$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is ReadonlySelectorToken$1<TokenType<Family>>;
|
|
290
|
+
declare function belongsTo<Family extends WritableFamily$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is WritableToken$1<TokenType<Family>>;
|
|
291
|
+
declare function belongsTo<Family extends ReadableFamily$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is ReadableToken$1<TokenType<Family>>;
|
|
286
292
|
|
|
287
293
|
type ƒn = (...parameters: any[]) => any;
|
|
288
|
-
type
|
|
294
|
+
type RegularAtomToken<T> = {
|
|
289
295
|
key: string;
|
|
290
296
|
type: `atom`;
|
|
291
297
|
family?: FamilyMetadata;
|
|
292
|
-
|
|
298
|
+
__T?: T;
|
|
293
299
|
};
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
300
|
+
type MutableAtomToken<T extends Transceiver<any>, J extends Json.Serializable> = {
|
|
301
|
+
key: string;
|
|
302
|
+
type: `mutable_atom`;
|
|
303
|
+
family?: FamilyMetadata;
|
|
304
|
+
__J?: J;
|
|
305
|
+
__U?: T extends Transceiver<infer Update> ? Update : never;
|
|
306
|
+
};
|
|
307
|
+
type AtomToken<T> = MutableAtomToken<T extends Transceiver<any> ? T : never, any> | RegularAtomToken<T>;
|
|
308
|
+
type WritableSelectorToken<T> = {
|
|
299
309
|
key: string;
|
|
300
310
|
type: `selector`;
|
|
301
311
|
family?: FamilyMetadata;
|
|
302
|
-
|
|
312
|
+
__T?: T;
|
|
303
313
|
};
|
|
304
|
-
|
|
305
|
-
* @deprecated Prefer `WritableToken`.
|
|
306
|
-
*/
|
|
307
|
-
type StateToken<T> = AtomToken<T> | SelectorToken<T>;
|
|
308
|
-
type WritableToken<T> = AtomToken<T> | SelectorToken<T>;
|
|
309
|
-
type ReadableToken<T> = ReadonlySelectorToken<T> | WritableToken<T>;
|
|
310
|
-
type WritableFamily<T, K extends Json.Serializable> = AtomFamily<T, K> | SelectorFamily<T, K>;
|
|
311
|
-
type ReadableFamily<T, K extends Json.Serializable> = ReadonlySelectorFamily<T, K> | WritableFamily<T, K>;
|
|
312
|
-
type WritableFamilyToken<T, K extends Json.Serializable> = AtomFamilyToken<T, K> | SelectorFamilyToken<T, K>;
|
|
313
|
-
type ReadableFamilyToken<T, K extends Json.Serializable> = ReadonlySelectorFamilyToken<T, K> | WritableFamilyToken<T, K>;
|
|
314
|
-
type ReadonlySelectorToken<_> = {
|
|
314
|
+
type ReadonlySelectorToken<T> = {
|
|
315
315
|
key: string;
|
|
316
316
|
type: `readonly_selector`;
|
|
317
317
|
family?: FamilyMetadata;
|
|
318
|
-
|
|
318
|
+
__T?: T;
|
|
319
319
|
};
|
|
320
|
+
type SelectorToken<T> = ReadonlySelectorToken<T> | WritableSelectorToken<T>;
|
|
321
|
+
type WritableToken<T> = AtomToken<T> | WritableSelectorToken<T>;
|
|
322
|
+
type ReadableToken<T> = AtomToken<T> | SelectorToken<T>;
|
|
323
|
+
type WritableFamily<T, K extends Json.Serializable> = AtomFamily<T, K> | WritableSelectorFamily<T, K>;
|
|
324
|
+
type ReadableFamily<T, K extends Json.Serializable> = AtomFamily<T, K> | SelectorFamily<T, K>;
|
|
325
|
+
type WritableFamilyToken<T, K extends Json.Serializable> = AtomFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
|
|
326
|
+
type ReadableFamilyToken<T, K extends Json.Serializable> = AtomFamilyToken<T, K> | SelectorFamilyToken<T, K>;
|
|
320
327
|
type FamilyMetadata = {
|
|
321
328
|
key: string;
|
|
322
329
|
subKey: string;
|
|
323
330
|
};
|
|
324
331
|
|
|
325
|
-
export { type AtomEffect, type AtomFamily, type
|
|
332
|
+
export { type AtomEffect, type AtomFamily, type AtomFamilyToken, AtomIOLogger, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type RegularAtomFamily, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomOptions, type RegularAtomToken, type SelectorFamily, type SelectorFamilyToken, type SelectorToken, Silo, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type Transactors, type TransactorsWithRunAndEnv, type UpdateHandler, type WritableFamily, type WritableFamilyToken, type WritableSelectorFamily, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, dispose, findInStore, findState, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo, type ƒn };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import './chunk-PZLG2HP3.js';
|
|
2
2
|
import * as Internal3 from 'atom.io/internal';
|
|
3
|
-
import {
|
|
3
|
+
import { createStandaloneAtom, IMPLICIT, createAtomFamily, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, withdraw } from 'atom.io/internal';
|
|
4
4
|
|
|
5
5
|
function atom(options) {
|
|
6
|
-
return
|
|
6
|
+
return createStandaloneAtom(options, IMPLICIT.STORE);
|
|
7
7
|
}
|
|
8
8
|
function atomFamily(options) {
|
|
9
9
|
return createAtomFamily(options, IMPLICIT.STORE);
|
|
@@ -77,7 +77,7 @@ var AtomIOLogger = class {
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
function selector(options) {
|
|
80
|
-
return
|
|
80
|
+
return createStandaloneSelector(options, IMPLICIT.STORE);
|
|
81
81
|
}
|
|
82
82
|
function selectorFamily(options) {
|
|
83
83
|
return createSelectorFamily(options, IMPLICIT.STORE);
|
|
@@ -98,10 +98,16 @@ function setState(token, value, store = Internal3.IMPLICIT.STORE) {
|
|
|
98
98
|
var Silo = class {
|
|
99
99
|
constructor(name, fromStore = null) {
|
|
100
100
|
const s = new Store(name, fromStore);
|
|
101
|
+
function _atom(options) {
|
|
102
|
+
return createStandaloneAtom(options, s);
|
|
103
|
+
}
|
|
104
|
+
function _atomFamily(options) {
|
|
105
|
+
return createAtomFamily(options, s);
|
|
106
|
+
}
|
|
101
107
|
this.store = s;
|
|
102
|
-
this.atom =
|
|
103
|
-
this.atomFamily =
|
|
104
|
-
this.selector = (options) =>
|
|
108
|
+
this.atom = _atom;
|
|
109
|
+
this.atomFamily = _atomFamily;
|
|
110
|
+
this.selector = (options) => createStandaloneSelector(options, s);
|
|
105
111
|
this.selectorFamily = (options) => createSelectorFamily(options, s);
|
|
106
112
|
this.transaction = (options) => createTransaction(options, s);
|
|
107
113
|
this.timeline = (options) => createTimeline(options, s);
|
|
@@ -115,6 +121,7 @@ var Silo = class {
|
|
|
115
121
|
function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) {
|
|
116
122
|
switch (token.type) {
|
|
117
123
|
case `atom`:
|
|
124
|
+
case `mutable_atom`:
|
|
118
125
|
case `readonly_selector`:
|
|
119
126
|
case `selector`:
|
|
120
127
|
return subscribeToState(token, handleUpdate, key, store);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/find-state.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts","../src/validators.ts"],"names":["IMPLICIT","Internal","createAtom","createAtomFamily","createSelector","createSelectorFamily","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";;;AACA,SAAS,UAAU,YAAY,wBAAwB;AA8BhD,SAAS,KACf,SACiB;AACjB,SAAO,WAAW,SAAS,QAAW,SAAS,KAAK;AACrD;AA2EO,SAAS,WACf,SACsD;AACtD,SAAO,iBAAiB,SAAS,SAAS,KAAK;AAChD;;;AClHA,YAAY,cAAc;AAInB,SAAS,QACf,OACA,QAAiC,kBAAS,OACnC;AACP,UAAQ,MAAM,MAAM;AAAA,IACnB,KAAK;AACJ,MAAS,oBAAW,OAAO,KAAK;AAChC;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AACJ,MAAS,wBAAe,OAAO,KAAK;AACpC;AAAA,EACF;AACD;;;ACFA,SAAS,YAAAA,iBAAgB;AAGlB,SAAS,YACf,OACA,KACA,OACqB;AACrB,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C,WAAUR,UAAS,KAAK;AAC5C;;;AC3CA,SAAS,YAAAA,WAAU,qBAAAS,oBAAmB,YAAAC,iBAAgB;AAwE/C,SAAS,YACf,SACsB;AACtB,SAAOD,mBAAkB,SAAST,UAAS,KAAK;AACjD;AAEO,IAAM,iBACZ,CACC,OACA,QAAeA,UAAS,OACxB,OAED,IAAI,eAA6C;AAChD,QAAM,KAAKU,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,YAAY,EAAE;AAAA,EAC7B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD;;;ACpDM,SAAS,QACf,YACA,cACuD;AACvD,SAAO,WAAW,QAAQ,aAAa;AACxC;AAsBO,SAAS,UACf,QACA,cACmD;AAvEpD;AAwEC,SAAO,OAAO,UAAQ,kBAAa,WAAb,mBAAqB;AAC5C","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT, createAtom, createAtomFamily } from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\treturn createAtom(options, undefined, IMPLICIT.STORE)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n\tmutable?: boolean\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type AtomFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `atom_family`\n\t__T?: T\n\t__K?: K\n}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& JsonInterface<T, J>\n\t& ((key: K) => MutableAtomToken<T, J>) \n\t& {\n\t\t\tkey: string\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<T, J>>\n\t\t\tmutable: true\n\t\t\tinstall: (store: Store) => void\n\t\t\t__T?: T\n\t\t\t__J?: J\n\t\t\t__K?: K\n\t\t}\nexport type MutableAtomFamilyToken<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = {\n\tkey: string\n\ttype: `atom_family`\n\tmutable: true\n\t__T?: T\n\t__J?: J\n\t__K?: K\n}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadableToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlySelectorFamilyToken,\n\tReadonlySelectorToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function findInStore(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n\tstore: Store,\n): ReadableToken<any> {\n\tconst familyKey = token.key\n\tconst family = store.families.get(familyKey)\n\tif (family === undefined) {\n\t\tthrow new Error(`Family ${familyKey} not found`)\n\t}\n\tconst state = family(key)\n\treturn state\n}\n\nexport function findState<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(token: MutableAtomFamilyToken<T, J, K>, key: K): MutableAtomToken<T, J>\nexport function findState<T, K extends Json.Serializable>(\n\ttoken: AtomFamilyToken<T, K>,\n\tkey: K,\n): AtomToken<T>\nexport function findState<T, K extends Json.Serializable>(\n\ttoken: SelectorFamilyToken<T, K>,\n\tkey: K,\n): SelectorToken<T>\nexport function findState<T, K extends Json.Serializable>(\n\ttoken: ReadonlySelectorFamilyToken<T, K>,\n\tkey: K,\n): ReadonlySelectorToken<T>\nexport function findState<T, K extends Json.Serializable>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: K,\n): WritableToken<T>\nexport function findState<T, K extends Json.Serializable>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: K,\n): ReadableToken<T>\nexport function findState(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n): ReadableToken<any> {\n\tconst state = findInStore(token, key, IMPLICIT.STORE)\n\treturn state\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n\t\"🚀\": `Performance measure`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options, undefined, IMPLICIT.STORE)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type SelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `selector_family`\n\t__T?: T\n\t__K?: K\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type ReadonlySelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `readonly_selector_family`\n\t__T?: T\n\t__K?: K\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { WritableToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: WritableToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => createAtom(options, undefined, s)\n\t\tthis.atomFamily = (options) => createAtomFamily(options, s)\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => timeTravel(`undo`, token, s)\n\t\tthis.redo = (token) => timeTravel(`redo`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadableToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n\thandleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineManageable = AtomFamily<any, any> | AtomToken<any>\n\nexport type TimelineToken<_> = {\n\tkey: string\n\ttype: `timeline`\n\t__brand?: _\n}\n\nexport type TimelineOptions<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\tatoms: ManagedAtom[]\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<ManagedAtom>,\n\t\ttimeline: Timeline<TimelineManageable>,\n\t) => boolean\n}\n\nexport type TimelineUpdate<ManagedAtom extends TimelineManageable> =\n\t| TimelineAtomUpdate<ManagedAtom>\n\t| TimelineSelectorUpdate<ManagedAtom>\n\t| TimelineTransactionUpdate\n\nexport const timeline = <ManagedAtom extends TimelineManageable>(\n\toptions: TimelineOptions<ManagedAtom>,\n): TimelineToken<ManagedAtom> => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`redo`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`undo`, timeline, IMPLICIT.STORE)\n}\n","import type { EnvironmentData, Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type {\n\tKeyedStateUpdate,\n\tReadonlySelectorToken,\n\tWritableToken,\n\tfindState,\n\tƒn,\n} from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdateContent =\n\t| KeyedStateUpdate<unknown>\n\t| TransactionUpdate<ƒn>\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tid: string\n\tupdates: TransactionUpdateContent[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n}>\nexport type TransactorsWithRunAndEnv = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n\trun: typeof runTransaction\n\tenv: () => EnvironmentData\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `find` | `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRunAndEnv,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(\n\t\ttoken: TransactionToken<ƒ>,\n\t\tstore: Store = IMPLICIT.STORE,\n\t\tid?: string,\n\t) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(parameters, id)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n","import type {\n\tAtomFamily,\n\tAtomToken,\n\tReadableFamily,\n\tReadableToken,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tSelectorFamily,\n\tSelectorToken,\n\tWritableFamily,\n\tWritableToken,\n} from \"atom.io\"\n\nexport type TokenType<\n\tComparison extends ReadableFamily<any, any> | ReadableToken<any>,\n> = Comparison extends ReadableToken<infer RepresentedValue>\n\t? RepresentedValue\n\t: Comparison extends ReadableFamily<infer RepresentedValue, any>\n\t ? RepresentedValue\n\t : never\n\nexport function isToken<KnownToken extends AtomToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is AtomToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends SelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is SelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadonlySelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadonlySelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is WritableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<KnownToken>> {\n\treturn knownToken.key === unknownToken.key\n}\n\nexport function belongsTo<Family extends AtomFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is AtomToken<TokenType<Family>>\nexport function belongsTo<Family extends SelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is SelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadonlySelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadonlySelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends WritableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is WritableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<Family>> {\n\treturn family.key === unknownToken.family?.key\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/find-state.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts","../src/validators.ts"],"names":["IMPLICIT","Internal","createAtomFamily","createSelectorFamily","createStandaloneAtom","createStandaloneSelector","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,SAAO,qBAAqB,SAAS,SAAS,KAAK;AACpD;AAoFO,SAAS,WACf,SAG6D;AAC7D,SAAO,iBAAiB,SAAS,SAAS,KAAK;AAChD;;;ACjIA,YAAY,cAAc;AAInB,SAAS,QACf,OACA,QAAiC,kBAAS,OACnC;AACP,UAAQ,MAAM,MAAM;AAAA,IACnB,KAAK;AACJ,MAAS,oBAAW,OAAO,KAAK;AAChC;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AACJ,MAAS,wBAAe,OAAO,KAAK;AACpC;AAAA,EACF;AACD;;;ACFA,SAAS,YAAAA,iBAAgB;AAGlB,SAAS,YACf,OACA,KACA,OACqB;AACrB,QAAM,YAAY,MAAM;AACxB,QAAM,SAAS,MAAM,SAAS,IAAI,SAAS;AAC3C,MAAI,WAAW,QAAW;AACzB,UAAM,IAAI,MAAM,UAAU,SAAS,YAAY;AAAA,EAChD;AACA,QAAM,QAAQ,OAAO,GAAG;AACxB,SAAO;AACR;AA4BO,SAAS,UACf,OACA,KACqB;AACrB,QAAM,QAAQ,YAAY,OAAO,KAAKA,UAAS,KAAK;AACpD,SAAO;AACR;;;AChEA,YAAYC,eAAc;AAInB,SAAS,SACf,OACA,QAAiC,mBAAS,OACtC;AA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AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,YAAY,EAAE;AAAA,EAC7B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD;;;AC9CM,SAAS,QACf,YACA,cACuD;AACvD,SAAO,WAAW,QAAQ,aAAa;AACxC;AA0BO,SAAS,UACf,QACA,cACmD;AAjFpD;AAkFC,SAAO,OAAO,UAAQ,kBAAa,WAAb,mBAAqB;AAC5C","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateAtomFamily,\n\tcreateStandaloneAtom,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken, RegularAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void\n\nexport type RegularAtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<RegularAtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>\nexport function atom(\n\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<any>,\n): AtomToken<any> {\n\treturn createStandaloneAtom(options, IMPLICIT.STORE)\n}\n\nexport type RegularAtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type RegularAtomFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => RegularAtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<RegularAtomToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type RegularAtomFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `atom_family`\n\t__T?: T\n\t__K?: K\n}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& JsonInterface<T, J>\n\t& { \n\t\tkey: string\n\t\tdefault: (key: K) => T\n\t\teffects?: (key: K) => AtomEffect<T>[]\n\t\tmutable: true,\n\t}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& JsonInterface<T, J>\n\t& ((key: K) => MutableAtomToken<T, J>) \n\t& {\n\t\t\tkey: string\n\t\t\ttype: `mutable_atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<T, J>>\n\t\t\tinstall: (store: Store) => void\n\t\t\t__T?: T\n\t\t\t__J?: J\n\t\t\t__K?: K\n\t\t}\nexport type MutableAtomFamilyToken<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = {\n\tkey: string\n\ttype: `mutable_atom_family`\n\t__T?: T\n\t__J?: J\n\t__K?: K\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> =\n\t| MutableAtomFamily<T extends Transceiver<any> ? T : never, any, K>\n\t| RegularAtomFamily<T, K>\nexport type AtomFamilyToken<T, K extends Json.Serializable = Json.Serializable> =\n\t| MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>\n\t| RegularAtomFamilyToken<T, K>\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: RegularAtomFamilyOptions<T, K>,\n): RegularAtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions:\n\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t| RegularAtomFamilyOptions<T, K>,\n): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadableToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import type {\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlySelectorFamilyToken,\n\tReadonlySelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tWritableFamilyToken,\n\tWritableSelectorFamilyToken,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function findInStore(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n\tstore: Store,\n): ReadableToken<any> {\n\tconst familyKey = token.key\n\tconst family = store.families.get(familyKey)\n\tif (family === undefined) {\n\t\tthrow new Error(`Family ${familyKey} not found`)\n\t}\n\tconst state = family(key)\n\treturn state\n}\n\nexport function findState<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n\tKey extends K,\n>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: RegularAtomFamilyToken<T, K>,\n\tkey: Key,\n): RegularAtomToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: WritableSelectorFamilyToken<T, K>,\n\tkey: Key,\n): WritableSelectorToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: ReadonlySelectorFamilyToken<T, K>,\n\tkey: Key,\n): ReadonlySelectorToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: Key,\n): WritableToken<T>\nexport function findState<T, K extends Json.Serializable, Key extends K>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: Key,\n): ReadableToken<T>\nexport function findState(\n\ttoken: ReadableFamilyToken<any, any>,\n\tkey: Json.Serializable,\n): ReadableToken<any> {\n\tconst state = findInStore(token, key, IMPLICIT.STORE)\n\treturn state\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadableToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadableToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n\t\"🚀\": `Performance measure`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `mutable_atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateSelectorFamily,\n\tcreateStandaloneSelector,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, WritableSelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type WritableSelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(\n\toptions: WritableSelectorOptions<T>,\n): WritableSelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | WritableSelectorOptions<T>,\n): ReadonlySelectorToken<T> | WritableSelectorToken<T> {\n\treturn createStandaloneSelector(options, IMPLICIT.STORE)\n}\n\nexport type WritableSelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type WritableSelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => WritableSelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<WritableSelectorToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type WritableSelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `selector_family`\n\t__T?: T\n\t__K?: K\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n\tinstall: (store: Store) => void\n\t__T?: T\n\t__K?: K\n}\nexport type ReadonlySelectorFamilyToken<T, K extends Json.Serializable> = {\n\tkey: string\n\ttype: `readonly_selector_family`\n\t__T?: T\n\t__K?: K\n}\n\nexport type SelectorFamily<T, K extends Json.Serializable> =\n\t| ReadonlySelectorFamily<T, K>\n\t| WritableSelectorFamily<T, K>\nexport type SelectorFamilyToken<T, K extends Json.Serializable> =\n\t| ReadonlySelectorFamilyToken<T, K>\n\t| WritableSelectorFamilyToken<T, K>\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: WritableSelectorFamilyOptions<T, K>,\n): WritableSelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions:\n\t\t| ReadonlySelectorFamilyOptions<T, K>\n\t\t| WritableSelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | WritableSelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { WritableToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: WritableToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import type { Transceiver } from \"atom.io/internal\"\nimport {\n\tStore,\n\tcreateAtomFamily,\n\tcreateSelectorFamily,\n\tcreateStandaloneAtom,\n\tcreateStandaloneSelector,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type {\n\tAtomToken,\n\tMutableAtomFamily,\n\tMutableAtomFamilyOptions,\n\tMutableAtomOptions,\n\tMutableAtomToken,\n\tRegularAtomFamily,\n\tRegularAtomFamilyOptions,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tredo,\n\ttimeline,\n\tundo,\n} from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tfunction _atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>\n\t\tfunction _atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\t\t\toptions: MutableAtomOptions<T, J>,\n\t\t): MutableAtomToken<T, J>\n\t\tfunction _atom<T>(\n\t\t\toptions: MutableAtomOptions<any, any> | RegularAtomOptions<T>,\n\t\t): AtomToken<T> {\n\t\t\treturn createStandaloneAtom(options, s)\n\t\t}\n\t\tfunction _atomFamily<\n\t\t\tT extends Transceiver<any>,\n\t\t\tJ extends Json.Serializable,\n\t\t\tK extends Json.Serializable,\n\t\t>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\n\t\tfunction _atomFamily<T, K extends Json.Serializable>(\n\t\t\toptions: RegularAtomFamilyOptions<T, K>,\n\t\t): RegularAtomFamily<T, K>\n\t\tfunction _atomFamily<T, K extends Json.Serializable>(\n\t\t\toptions:\n\t\t\t\t| MutableAtomFamilyOptions<any, any, any>\n\t\t\t\t| RegularAtomFamilyOptions<T, K>,\n\t\t): MutableAtomFamily<any, any, any> | RegularAtomFamily<T, K> {\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.store = s\n\t\tthis.atom = _atom\n\t\tthis.atomFamily = _atomFamily\n\t\tthis.selector = (options) => createStandaloneSelector(options, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => timeTravel(`undo`, token, s)\n\t\tthis.redo = (token) => timeTravel(`redo`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadableToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n\thandleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineManageable = AtomFamily<any, any> | AtomToken<any>\n\nexport type TimelineToken<_> = {\n\tkey: string\n\ttype: `timeline`\n\t__brand?: _\n}\n\nexport type TimelineOptions<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\tatoms: ManagedAtom[]\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<ManagedAtom>,\n\t\ttimeline: Timeline<TimelineManageable>,\n\t) => boolean\n}\n\nexport type TimelineUpdate<ManagedAtom extends TimelineManageable> =\n\t| TimelineAtomUpdate<ManagedAtom>\n\t| TimelineSelectorUpdate<ManagedAtom>\n\t| TimelineTransactionUpdate\n\nexport const timeline = <ManagedAtom extends TimelineManageable>(\n\toptions: TimelineOptions<ManagedAtom>,\n): TimelineToken<ManagedAtom> => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`redo`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`undo`, timeline, IMPLICIT.STORE)\n}\n","import type { EnvironmentData, Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type {\n\tKeyedStateUpdate,\n\tReadonlySelectorToken,\n\tWritableToken,\n\tfindState,\n\tƒn,\n} from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdateContent =\n\t| KeyedStateUpdate<unknown>\n\t| TransactionUpdate<ƒn>\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tid: string\n\tupdates: TransactionUpdateContent[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n}>\nexport type TransactorsWithRunAndEnv = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: WritableToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\tfind: typeof findState\n\trun: typeof runTransaction\n\tenv: () => EnvironmentData\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `find` | `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRunAndEnv,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(\n\t\ttoken: TransactionToken<ƒ>,\n\t\tstore: Store = IMPLICIT.STORE,\n\t\tid?: string,\n\t) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(parameters, id)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n","import type {\n\tMutableAtomFamily,\n\tMutableAtomToken,\n\tReadableFamily,\n\tReadableToken,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tRegularAtomFamily,\n\tRegularAtomToken,\n\tWritableFamily,\n\tWritableSelectorFamily,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\n\nexport type TokenType<\n\tComparison extends ReadableFamily<any, any> | ReadableToken<any>,\n> = Comparison extends ReadableToken<infer RepresentedValue>\n\t? RepresentedValue\n\t: Comparison extends ReadableFamily<infer RepresentedValue, any>\n\t ? RepresentedValue\n\t : never\n\nexport function isToken<KnownToken extends RegularAtomToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is RegularAtomToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends MutableAtomToken<any, any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is MutableAtomToken<TokenType<KnownToken>, any>\nexport function isToken<KnownToken extends WritableSelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableSelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadonlySelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadonlySelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<KnownToken>> {\n\treturn knownToken.key === unknownToken.key\n}\n\nexport function belongsTo<Family extends RegularAtomFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is RegularAtomToken<TokenType<Family>>\nexport function belongsTo<Family extends MutableAtomFamily<any, any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is MutableAtomToken<TokenType<Family>, any>\nexport function belongsTo<Family extends WritableSelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableSelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadonlySelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadonlySelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends WritableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is WritableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<any>,\n): unknownToken is ReadableToken<TokenType<Family>> {\n\treturn family.key === unknownToken.family?.key\n}\n"]}
|