atom.io 0.14.4 → 0.14.6
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 +47 -1416
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.cts +16 -317
- package/data/dist/index.d.ts +16 -317
- package/data/dist/index.js +4 -6
- package/data/dist/index.js.map +1 -1
- package/dist/chunk-NYTGCPHB.js +261 -0
- package/dist/chunk-NYTGCPHB.js.map +1 -0
- package/dist/chunk-PZLG2HP3.js +36 -0
- package/dist/chunk-PZLG2HP3.js.map +1 -0
- package/dist/chunk-XACXFU3B.js +46 -0
- package/dist/chunk-XACXFU3B.js.map +1 -0
- package/dist/index.cjs +55 -2330
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -269
- package/dist/index.d.ts +21 -269
- package/dist/index.js +152 -1
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/internal/dist/index.cjs +30 -159
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.cts +28 -229
- package/internal/dist/index.d.ts +28 -229
- package/internal/dist/index.js +2027 -1
- package/internal/dist/index.js.map +1 -1
- package/introspection/dist/index.cjs +45 -1565
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.cts +4 -376
- package/introspection/dist/index.d.ts +4 -376
- package/introspection/dist/index.js +298 -2
- package/introspection/dist/index.js.map +1 -1
- package/json/dist/index.cjs +5 -1502
- package/json/dist/index.cjs.map +1 -1
- package/json/dist/index.d.cts +7 -373
- package/json/dist/index.d.ts +7 -373
- package/json/dist/index.js +37 -1
- package/json/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/react/dist/index.cjs +14 -1549
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.cts +4 -377
- package/react/dist/index.d.ts +4 -377
- package/react/dist/index.js +62 -2
- package/react/dist/index.js.map +1 -1
- package/react-devtools/dist/index.cjs +135 -2153
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.d.cts +24 -149
- package/react-devtools/dist/index.d.ts +24 -149
- package/react-devtools/dist/index.js +5 -3
- package/react-devtools/dist/index.js.map +1 -1
- package/realtime-client/dist/index.cjs +34 -1529
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.cts +12 -384
- package/realtime-client/dist/index.d.ts +12 -384
- package/realtime-client/dist/index.js +165 -2
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-react/dist/index.cjs +35 -1727
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.cts +9 -49
- package/realtime-react/dist/index.d.ts +9 -49
- package/realtime-react/dist/index.js +66 -4
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-server/dist/index.cjs +57 -1548
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.cts +11 -394
- package/realtime-server/dist/index.d.ts +11 -394
- package/realtime-server/dist/index.js +21 -27
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-testing/dist/index.cjs +15 -2376
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.cts +3 -489
- package/realtime-testing/dist/index.d.ts +3 -489
- package/realtime-testing/dist/index.js +10 -9
- package/realtime-testing/dist/index.js.map +1 -1
- package/transceivers/set-rtx/dist/index.cjs +9 -31
- package/transceivers/set-rtx/dist/index.cjs.map +1 -1
- package/transceivers/set-rtx/dist/index.d.cts +3 -29
- package/transceivers/set-rtx/dist/index.d.ts +3 -29
- package/transceivers/set-rtx/dist/index.js +3 -2
- package/transceivers/set-rtx/dist/index.js.map +1 -1
- package/dist/chunk-GMN5KH6A.js +0 -309
- package/dist/chunk-GMN5KH6A.js.map +0 -1
- package/dist/chunk-HQWWV67P.js +0 -62
- package/dist/chunk-HQWWV67P.js.map +0 -1
- package/dist/chunk-MK4OJD24.js +0 -67
- package/dist/chunk-MK4OJD24.js.map +0 -1
- package/dist/chunk-N7ADBQJG.js +0 -176
- package/dist/chunk-N7ADBQJG.js.map +0 -1
- package/dist/chunk-PURABO5G.js +0 -2581
- package/dist/chunk-PURABO5G.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,254 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
|
|
5
|
-
private unsubscribe;
|
|
6
|
-
next(value: T): void;
|
|
7
|
-
}
|
|
8
|
-
declare class StatefulSubject<T> extends Subject<T> {
|
|
9
|
-
state: T;
|
|
10
|
-
constructor(initialState: T);
|
|
11
|
-
next(value: T): void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type Selector<T> = {
|
|
15
|
-
key: string;
|
|
16
|
-
type: `selector`;
|
|
17
|
-
family?: FamilyMetadata;
|
|
18
|
-
install: (store: Store) => void;
|
|
19
|
-
subject: Subject<{
|
|
20
|
-
newValue: T;
|
|
21
|
-
oldValue: T;
|
|
22
|
-
}>;
|
|
23
|
-
get: () => T;
|
|
24
|
-
set: (newValue: T | ((oldValue: T) => T)) => void;
|
|
25
|
-
};
|
|
26
|
-
type ReadonlySelector<T> = {
|
|
27
|
-
key: string;
|
|
28
|
-
type: `readonly_selector`;
|
|
29
|
-
family?: FamilyMetadata;
|
|
30
|
-
install: (store: Store) => void;
|
|
31
|
-
subject: Subject<{
|
|
32
|
-
newValue: T;
|
|
33
|
-
oldValue: T;
|
|
34
|
-
}>;
|
|
35
|
-
get: () => T;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
type Transaction<ƒ extends ƒn> = {
|
|
39
|
-
key: string;
|
|
40
|
-
type: `transaction`;
|
|
41
|
-
install: (store: Store) => void;
|
|
42
|
-
subject: Subject<TransactionUpdate<ƒ>>;
|
|
43
|
-
run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
type TransactionMeta<ƒ extends ƒn> = {
|
|
47
|
-
phase: `applying` | `building`;
|
|
48
|
-
time: number;
|
|
49
|
-
update: TransactionUpdate<ƒ>;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
type primitive = boolean | number | string | null;
|
|
53
|
-
|
|
54
|
-
type Serializable = primitive | Readonly<{
|
|
55
|
-
[key: string]: Serializable;
|
|
56
|
-
}> | ReadonlyArray<Serializable>;
|
|
57
|
-
type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
|
|
58
|
-
|
|
59
|
-
type Refinement<Unrefined, Refined extends Unrefined> = (value: Unrefined) => value is Refined;
|
|
60
|
-
type Cardinality = `1:1` | `1:n` | `n:n`;
|
|
61
|
-
|
|
62
|
-
interface JunctionEntries<Content extends Object$1 | null> extends Object$1 {
|
|
63
|
-
readonly relations: [string, string[]][];
|
|
64
|
-
readonly contents: [string, Content][];
|
|
65
|
-
}
|
|
66
|
-
interface JunctionSchema<ASide extends string, BSide extends string> extends Object$1 {
|
|
67
|
-
readonly between: [a: ASide, b: BSide];
|
|
68
|
-
readonly cardinality: Cardinality;
|
|
69
|
-
}
|
|
70
|
-
type BaseExternalStoreConfiguration = {
|
|
71
|
-
addRelation: (a: string, b: string) => void;
|
|
72
|
-
deleteRelation: (a: string, b: string) => void;
|
|
73
|
-
replaceRelationsSafely: (a: string, bs: string[]) => void;
|
|
74
|
-
replaceRelationsUnsafely: (a: string, bs: string[]) => void;
|
|
75
|
-
getRelatedKeys: (key: string) => Set<string> | undefined;
|
|
76
|
-
has: (a: string, b?: string) => boolean;
|
|
77
|
-
};
|
|
78
|
-
type ExternalStoreWithContentConfiguration<Content extends Object$1> = {
|
|
79
|
-
getContent: (contentKey: string) => Content | undefined;
|
|
80
|
-
setContent: (contentKey: string, content: Content) => void;
|
|
81
|
-
deleteContent: (contentKey: string) => void;
|
|
82
|
-
};
|
|
83
|
-
type Empty<Obj extends object> = {
|
|
84
|
-
[Key in keyof Obj]?: undefined;
|
|
85
|
-
};
|
|
86
|
-
type ExternalStoreConfiguration<Content extends Object$1 | null> = Content extends Object$1 ? BaseExternalStoreConfiguration & ExternalStoreWithContentConfiguration<Content> : BaseExternalStoreConfiguration & Empty<ExternalStoreWithContentConfiguration<Object$1>>;
|
|
87
|
-
type JunctionAdvancedConfiguration<Content extends Object$1 | null> = {
|
|
88
|
-
externalStore?: ExternalStoreConfiguration<Content>;
|
|
89
|
-
isContent?: Refinement<unknown, Content>;
|
|
90
|
-
makeContentKey?: (a: string, b: string) => string;
|
|
91
|
-
};
|
|
92
|
-
type JunctionJSON<ASide extends string, BSide extends string, Content extends Object$1 | null> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>;
|
|
93
|
-
declare class Junction<const ASide extends string, const BSide extends string, const Content extends Object$1 | null = null> {
|
|
94
|
-
readonly a: ASide;
|
|
95
|
-
readonly b: BSide;
|
|
96
|
-
readonly cardinality: Cardinality;
|
|
97
|
-
readonly relations: Map<string, Set<string>>;
|
|
98
|
-
readonly contents: Map<string, Content>;
|
|
99
|
-
isContent: Refinement<unknown, Content> | null;
|
|
100
|
-
makeContentKey: (a: string, b: string) => string;
|
|
101
|
-
getRelatedKeys(key: string): Set<string> | undefined;
|
|
102
|
-
protected addRelation(a: string, b: string): void;
|
|
103
|
-
protected deleteRelation(a: string, b: string): void;
|
|
104
|
-
protected replaceRelationsUnsafely(a: string, bs: string[]): void;
|
|
105
|
-
protected replaceRelationsSafely(a: string, bs: string[]): void;
|
|
106
|
-
protected getContentInternal(contentKey: string): Content | undefined;
|
|
107
|
-
protected setContent(contentKey: string, content: Content): void;
|
|
108
|
-
protected deleteContent(contentKey: string): void;
|
|
109
|
-
constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>, config?: JunctionAdvancedConfiguration<Content>);
|
|
110
|
-
toJSON(): JunctionJSON<ASide, BSide, Content>;
|
|
111
|
-
set(a: string, ...rest: Content extends null ? [b: string] : [b: string, content: Content]): this;
|
|
112
|
-
set(relation: {
|
|
113
|
-
[Key in ASide | BSide]: string;
|
|
114
|
-
}, ...rest: Content extends null ? [] | [b?: undefined] : [content: Content]): this;
|
|
115
|
-
delete(a: string, b?: string): this;
|
|
116
|
-
delete(relation: Record<ASide | BSide, string> | Record<ASide, string> | Record<BSide, string>, b?: undefined): this;
|
|
117
|
-
getRelatedKey(key: string): string | undefined;
|
|
118
|
-
replaceRelations(a: string, relations: Content extends null ? string[] : Record<string, Content>, config?: {
|
|
119
|
-
reckless: boolean;
|
|
120
|
-
}): this;
|
|
121
|
-
getContent(a: string, b: string): Content | undefined;
|
|
122
|
-
getRelationEntries(input: Record<ASide, string> | Record<BSide, string>): [string, Content][];
|
|
123
|
-
has(a: string, b?: string): boolean;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
interface Lineage {
|
|
127
|
-
parent: typeof this | null;
|
|
128
|
-
child: typeof this | null;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
type JsonInterface<T, J extends Serializable = Serializable> = {
|
|
132
|
-
toJson: (t: T) => J;
|
|
133
|
-
fromJson: (json: J) => T;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
interface Transceiver<Signal extends Serializable> {
|
|
137
|
-
do: (update: Signal) => void;
|
|
138
|
-
undo: (update: Signal) => void;
|
|
139
|
-
subscribe: (key: string, fn: (update: Signal) => void) => () => void;
|
|
140
|
-
cacheUpdateNumber: number;
|
|
141
|
-
getUpdateNumber: (update: Signal) => number;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* @internal Give the tracker a transceiver state and a store, and it will
|
|
146
|
-
* subscribe to the transceiver's inner value. When the inner value changes,
|
|
147
|
-
* the tracker will update its own state to reflect the change.
|
|
148
|
-
*/
|
|
149
|
-
declare class Tracker<Mutable extends Transceiver<any>> {
|
|
150
|
-
private Update;
|
|
151
|
-
private initializeState;
|
|
152
|
-
private unsubscribeFromInnerValue;
|
|
153
|
-
private observeCore;
|
|
154
|
-
private updateCore;
|
|
155
|
-
mutableState: MutableAtomToken<Mutable, Serializable>;
|
|
156
|
-
latestUpdateState: AtomToken<typeof this.Update | null>;
|
|
157
|
-
constructor(mutableState: MutableAtomToken<Mutable, Serializable>, store: Store);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
interface MutableAtom<T> extends Atom<T> {
|
|
161
|
-
mutable: true;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
type OperationProgress = {
|
|
165
|
-
open: false;
|
|
166
|
-
} | {
|
|
167
|
-
open: true;
|
|
168
|
-
done: Set<string>;
|
|
169
|
-
prev: Map<string, any>;
|
|
170
|
-
time: number;
|
|
171
|
-
token: StateToken<any>;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
type TimelineAtomUpdate = StateUpdate<unknown> & {
|
|
175
|
-
key: string;
|
|
176
|
-
type: `atom_update`;
|
|
177
|
-
timestamp: number;
|
|
178
|
-
family?: FamilyMetadata;
|
|
179
|
-
};
|
|
180
|
-
type TimelineSelectorUpdate = {
|
|
181
|
-
key: string;
|
|
182
|
-
type: `selector_update`;
|
|
183
|
-
timestamp: number;
|
|
184
|
-
atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
|
|
185
|
-
};
|
|
186
|
-
type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
|
|
187
|
-
key: string;
|
|
188
|
-
type: `transaction_update`;
|
|
189
|
-
timestamp: number;
|
|
190
|
-
};
|
|
191
|
-
type Timeline = {
|
|
192
|
-
type: `timeline`;
|
|
193
|
-
key: string;
|
|
194
|
-
at: number;
|
|
195
|
-
shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
|
|
196
|
-
timeTraveling: `into_future` | `into_past` | null;
|
|
197
|
-
history: TimelineUpdate[];
|
|
198
|
-
selectorTime: number | null;
|
|
199
|
-
transactionKey: string | null;
|
|
200
|
-
install: (store: Store) => void;
|
|
201
|
-
subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
declare class Store implements Lineage {
|
|
205
|
-
parent: Store | null;
|
|
206
|
-
child: Store | null;
|
|
207
|
-
valueMap: Map<string, any>;
|
|
208
|
-
atoms: Map<string, Atom<any> | MutableAtom<any>>;
|
|
209
|
-
selectors: Map<string, Selector<any>>;
|
|
210
|
-
readonlySelectors: Map<string, ReadonlySelector<any>>;
|
|
211
|
-
trackers: Map<string, Tracker<Transceiver<any>>>;
|
|
212
|
-
families: Map<string, AtomFamily<any, any> | ReadonlySelectorFamily<any, any> | SelectorFamily<any, any>>;
|
|
213
|
-
timelines: Map<string, Timeline>;
|
|
214
|
-
transactions: Map<string, Transaction<ƒn>>;
|
|
215
|
-
atomsThatAreDefault: Set<string>;
|
|
216
|
-
timelineAtoms: Junction<"timelineKey", "atomKey", null>;
|
|
217
|
-
selectorAtoms: Junction<"selectorKey", "atomKey", null>;
|
|
218
|
-
selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
|
|
219
|
-
source: string;
|
|
220
|
-
}>;
|
|
221
|
-
subject: {
|
|
222
|
-
atomCreation: Subject<AtomToken<unknown>>;
|
|
223
|
-
selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
|
|
224
|
-
transactionCreation: Subject<TransactionToken<ƒn>>;
|
|
225
|
-
timelineCreation: Subject<TimelineToken>;
|
|
226
|
-
transactionApplying: StatefulSubject<TransactionMeta<ƒn> | null>;
|
|
227
|
-
operationStatus: Subject<OperationProgress>;
|
|
228
|
-
};
|
|
229
|
-
operation: OperationProgress;
|
|
230
|
-
transactionMeta: TransactionMeta<ƒn> | null;
|
|
231
|
-
config: {
|
|
232
|
-
name: string;
|
|
233
|
-
};
|
|
234
|
-
loggers: AtomIOLogger[];
|
|
235
|
-
logger: Logger;
|
|
236
|
-
constructor(name: string, store?: Store | null);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
type Atom<T> = {
|
|
240
|
-
key: string;
|
|
241
|
-
type: `atom`;
|
|
242
|
-
mutable?: boolean;
|
|
243
|
-
family?: FamilyMetadata;
|
|
244
|
-
install: (store: Store) => void;
|
|
245
|
-
subject: Subject<{
|
|
246
|
-
newValue: T;
|
|
247
|
-
oldValue: T;
|
|
248
|
-
}>;
|
|
249
|
-
default: T | (() => T);
|
|
250
|
-
cleanup?: () => void;
|
|
251
|
-
};
|
|
1
|
+
import * as Internal from 'atom.io/internal';
|
|
2
|
+
import { Transceiver, Subject, Store, Timeline, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
|
|
3
|
+
import { Json, JsonInterface } from 'atom.io/json';
|
|
252
4
|
|
|
253
5
|
type Effectors<T> = {
|
|
254
6
|
setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void;
|
|
@@ -263,38 +15,38 @@ type AtomOptions<T> = {
|
|
|
263
15
|
default: T | (() => T);
|
|
264
16
|
effects?: AtomEffect<T>[];
|
|
265
17
|
};
|
|
266
|
-
type MutableAtomOptions<T extends Transceiver<any>, J extends Serializable> = JsonInterface<T, J> & Omit<AtomOptions<T>, `default`> & {
|
|
18
|
+
type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = JsonInterface<T, J> & Omit<AtomOptions<T>, `default`> & {
|
|
267
19
|
default: () => T;
|
|
268
20
|
mutable: true;
|
|
269
21
|
};
|
|
270
|
-
declare function atom<T extends Transceiver<any>, J extends Serializable>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>;
|
|
22
|
+
declare function atom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>;
|
|
271
23
|
declare function atom<T>(options: AtomOptions<T>): AtomToken<T>;
|
|
272
|
-
type AtomFamilyOptions<T, K extends Serializable> = {
|
|
24
|
+
type AtomFamilyOptions<T, K extends Json.Serializable> = {
|
|
273
25
|
key: string;
|
|
274
26
|
default: T | ((key: K) => T);
|
|
275
27
|
effects?: (key: K) => AtomEffect<T>[];
|
|
276
28
|
};
|
|
277
|
-
type AtomFamily<T, K extends Serializable = Serializable> = ((key: K) => AtomToken<T>) & {
|
|
29
|
+
type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => AtomToken<T>) & {
|
|
278
30
|
key: string;
|
|
279
31
|
type: `atom_family`;
|
|
280
32
|
subject: Subject<AtomToken<T>>;
|
|
281
33
|
mutable?: boolean;
|
|
282
34
|
};
|
|
283
|
-
type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Serializable, K extends Serializable> = AtomFamilyOptions<T, K> & JsonInterface<T, J> & {
|
|
35
|
+
type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> = AtomFamilyOptions<T, K> & JsonInterface<T, J> & {
|
|
284
36
|
mutable: true;
|
|
285
37
|
};
|
|
286
|
-
type MutableAtomFamily<Core extends Transceiver<any>, SerializableCore extends Serializable, Key extends Serializable> = JsonInterface<Core, SerializableCore> & ((key: Key) => MutableAtomToken<Core, SerializableCore>) & {
|
|
38
|
+
type MutableAtomFamily<Core extends Transceiver<any>, SerializableCore extends Json.Serializable, Key extends Json.Serializable> = JsonInterface<Core, SerializableCore> & ((key: Key) => MutableAtomToken<Core, SerializableCore>) & {
|
|
287
39
|
key: `${string}`;
|
|
288
40
|
type: `atom_family`;
|
|
289
41
|
subject: Subject<MutableAtomToken<Core, SerializableCore>>;
|
|
290
42
|
mutable: true;
|
|
291
43
|
};
|
|
292
|
-
declare function atomFamily<T extends Transceiver<any>, J extends Serializable, K extends Serializable>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>;
|
|
293
|
-
declare function atomFamily<T, K extends Serializable>(options: AtomFamilyOptions<T, K>): AtomFamily<T, K>;
|
|
44
|
+
declare function atomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>;
|
|
45
|
+
declare function atomFamily<T, K extends Json.Serializable>(options: AtomFamilyOptions<T, K>): AtomFamily<T, K>;
|
|
294
46
|
|
|
295
|
-
declare function dispose(token: ReadonlySelectorToken<any> | StateToken<any>, store?: Store): void;
|
|
47
|
+
declare function dispose(token: ReadonlySelectorToken<any> | StateToken<any>, store?: Internal.Store): void;
|
|
296
48
|
|
|
297
|
-
declare function getState<T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Store): T;
|
|
49
|
+
declare function getState<T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Internal.Store): T;
|
|
298
50
|
|
|
299
51
|
declare const LoggerIconDictionary: {
|
|
300
52
|
readonly "\u231B": "Timeline event fully captured";
|
|
@@ -393,29 +145,29 @@ type ReadonlySelectorOptions<T> = {
|
|
|
393
145
|
};
|
|
394
146
|
declare function selector<T>(options: SelectorOptions<T>): SelectorToken<T>;
|
|
395
147
|
declare function selector<T>(options: ReadonlySelectorOptions<T>): ReadonlySelectorToken<T>;
|
|
396
|
-
type SelectorFamilyOptions<T, K extends Serializable> = {
|
|
148
|
+
type SelectorFamilyOptions<T, K extends Json.Serializable> = {
|
|
397
149
|
key: string;
|
|
398
150
|
get: (key: K) => Read<() => T>;
|
|
399
151
|
set: (key: K) => Write<(newValue: T) => void>;
|
|
400
152
|
};
|
|
401
|
-
type ReadonlySelectorFamilyOptions<T, K extends Serializable> = {
|
|
153
|
+
type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {
|
|
402
154
|
key: string;
|
|
403
155
|
get: (key: K) => Read<() => T>;
|
|
404
156
|
};
|
|
405
|
-
type SelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => SelectorToken<T>) & {
|
|
157
|
+
type SelectorFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => SelectorToken<T>) & {
|
|
406
158
|
key: string;
|
|
407
159
|
type: `selector_family`;
|
|
408
160
|
subject: Subject<SelectorToken<T>>;
|
|
409
161
|
};
|
|
410
|
-
type ReadonlySelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
|
|
162
|
+
type ReadonlySelectorFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
|
|
411
163
|
key: string;
|
|
412
164
|
type: `readonly_selector_family`;
|
|
413
165
|
subject: Subject<ReadonlySelectorToken<T>>;
|
|
414
166
|
};
|
|
415
|
-
declare function selectorFamily<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>): SelectorFamily<T, K>;
|
|
416
|
-
declare function selectorFamily<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamily<T, K>;
|
|
167
|
+
declare function selectorFamily<T, K extends Json.Serializable>(options: SelectorFamilyOptions<T, K>): SelectorFamily<T, K>;
|
|
168
|
+
declare function selectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamily<T, K>;
|
|
417
169
|
|
|
418
|
-
declare function setState<T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Store): void;
|
|
170
|
+
declare function setState<T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Internal.Store): void;
|
|
419
171
|
|
|
420
172
|
declare class Silo {
|
|
421
173
|
store: Store;
|
|
@@ -468,7 +220,7 @@ type AtomToken<_> = {
|
|
|
468
220
|
family?: FamilyMetadata;
|
|
469
221
|
__brand?: _;
|
|
470
222
|
};
|
|
471
|
-
interface MutableAtomToken<T extends Transceiver<any>, J extends Serializable> extends AtomToken<T> {
|
|
223
|
+
interface MutableAtomToken<T extends Transceiver<any>, J extends Json.Serializable> extends AtomToken<T> {
|
|
472
224
|
__asJSON?: J;
|
|
473
225
|
__update?: T extends Transceiver<infer Update> ? Update : never;
|
|
474
226
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,154 @@
|
|
|
1
|
-
|
|
1
|
+
import './chunk-PZLG2HP3.js';
|
|
2
|
+
import * as Internal3 from 'atom.io/internal';
|
|
3
|
+
import { createMutableAtom, IMPLICIT, createAtom, createMutableAtomFamily, createAtomFamily, createSelector, createSelectorFamily, Store, createTransaction, createTimeline, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, withdraw } from 'atom.io/internal';
|
|
4
|
+
|
|
5
|
+
function atom(options) {
|
|
6
|
+
if (`mutable` in options) {
|
|
7
|
+
return createMutableAtom(options, IMPLICIT.STORE);
|
|
8
|
+
}
|
|
9
|
+
return createAtom(options, void 0, IMPLICIT.STORE);
|
|
10
|
+
}
|
|
11
|
+
function atomFamily(options) {
|
|
12
|
+
if (`mutable` in options) {
|
|
13
|
+
return createMutableAtomFamily(options, IMPLICIT.STORE);
|
|
14
|
+
}
|
|
15
|
+
return createAtomFamily(options, IMPLICIT.STORE);
|
|
16
|
+
}
|
|
17
|
+
function dispose(token, store = Internal3.IMPLICIT.STORE) {
|
|
18
|
+
switch (token.type) {
|
|
19
|
+
case `atom`:
|
|
20
|
+
Internal3.deleteAtom(token, store);
|
|
21
|
+
break;
|
|
22
|
+
case `selector`:
|
|
23
|
+
case `readonly_selector`:
|
|
24
|
+
Internal3.deleteSelector(token, store);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function getState(token, store = Internal3.IMPLICIT.STORE) {
|
|
29
|
+
var _a;
|
|
30
|
+
const state = (_a = Internal3.withdraw(token, store)) != null ? _a : Internal3.withdrawNewFamilyMember(token, store);
|
|
31
|
+
if (state === void 0) {
|
|
32
|
+
throw new Internal3.NotFoundError(token, store);
|
|
33
|
+
}
|
|
34
|
+
return Internal3.readOrComputeValue(state, store);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/logger.ts
|
|
38
|
+
var LOG_LEVELS = [`info`, `warn`, `error`];
|
|
39
|
+
var simpleLog = (logLevel) => (icon, tokenType, tokenKey, message, ...rest) => {
|
|
40
|
+
console[logLevel](`${icon} ${tokenType} "${tokenKey}" ${message}`, ...rest);
|
|
41
|
+
};
|
|
42
|
+
var simpleLogger = {
|
|
43
|
+
error: simpleLog(`error`),
|
|
44
|
+
info: simpleLog(`info`),
|
|
45
|
+
warn: simpleLog(`warn`)
|
|
46
|
+
};
|
|
47
|
+
var AtomIOLogger = class {
|
|
48
|
+
constructor(logLevel, filter, logger = simpleLogger) {
|
|
49
|
+
this.logLevel = logLevel;
|
|
50
|
+
this.filter = filter;
|
|
51
|
+
this.logger = logger;
|
|
52
|
+
this.error = (...args) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== null) {
|
|
55
|
+
this.logger.error(...args);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
this.info = (...args) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel === `info`) {
|
|
61
|
+
this.logger.info(...args);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
this.warn = (...args) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
|
|
67
|
+
this.logger.warn(...args);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function selector(options) {
|
|
73
|
+
return createSelector(options, void 0, IMPLICIT.STORE);
|
|
74
|
+
}
|
|
75
|
+
function selectorFamily(options) {
|
|
76
|
+
return createSelectorFamily(options, IMPLICIT.STORE);
|
|
77
|
+
}
|
|
78
|
+
function setState(token, value, store = Internal3.IMPLICIT.STORE) {
|
|
79
|
+
var _a;
|
|
80
|
+
const rejection = Internal3.openOperation(token, store);
|
|
81
|
+
if (rejection) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const state = (_a = Internal3.withdraw(token, store)) != null ? _a : Internal3.withdrawNewFamilyMember(token, store);
|
|
85
|
+
if (state === void 0) {
|
|
86
|
+
throw new Internal3.NotFoundError(token, store);
|
|
87
|
+
}
|
|
88
|
+
Internal3.setAtomOrSelector(state, value, store);
|
|
89
|
+
Internal3.closeOperation(store);
|
|
90
|
+
}
|
|
91
|
+
var Silo = class {
|
|
92
|
+
constructor(name, fromStore = null) {
|
|
93
|
+
const s = new Store(name, fromStore);
|
|
94
|
+
this.store = s;
|
|
95
|
+
this.atom = (options) => {
|
|
96
|
+
if (`mutable` in options) {
|
|
97
|
+
return createMutableAtom(options, s);
|
|
98
|
+
}
|
|
99
|
+
return createAtom(options, void 0, s);
|
|
100
|
+
};
|
|
101
|
+
this.atomFamily = (options) => {
|
|
102
|
+
if (`mutable` in options) {
|
|
103
|
+
return createMutableAtomFamily(options, s);
|
|
104
|
+
}
|
|
105
|
+
return createAtomFamily(options, s);
|
|
106
|
+
};
|
|
107
|
+
this.selector = (options) => createSelector(options, void 0, s);
|
|
108
|
+
this.selectorFamily = (options) => createSelectorFamily(options, s);
|
|
109
|
+
this.transaction = (options) => createTransaction(options, s);
|
|
110
|
+
this.timeline = (options) => createTimeline(options, s);
|
|
111
|
+
this.getState = (token) => getState(token, s);
|
|
112
|
+
this.setState = (token, newValue) => setState(token, newValue, s);
|
|
113
|
+
this.subscribe = (token, handler, key) => subscribe(token, handler, key, s);
|
|
114
|
+
this.undo = (token) => timeTravel(`backward`, token, s);
|
|
115
|
+
this.redo = (token) => timeTravel(`forward`, token, s);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) {
|
|
119
|
+
switch (token.type) {
|
|
120
|
+
case `atom`:
|
|
121
|
+
case `readonly_selector`:
|
|
122
|
+
case `selector`:
|
|
123
|
+
return subscribeToState(token, handleUpdate, key, store);
|
|
124
|
+
case `transaction`:
|
|
125
|
+
return subscribeToTransaction(token, handleUpdate, key, store);
|
|
126
|
+
case `timeline`:
|
|
127
|
+
return subscribeToTimeline(token, handleUpdate, key, store);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
var timeline = (options) => {
|
|
131
|
+
return createTimeline(options, IMPLICIT.STORE);
|
|
132
|
+
};
|
|
133
|
+
var redo = (timeline2) => {
|
|
134
|
+
timeTravel(`forward`, timeline2, IMPLICIT.STORE);
|
|
135
|
+
};
|
|
136
|
+
var undo = (timeline2) => {
|
|
137
|
+
timeTravel(`backward`, timeline2, IMPLICIT.STORE);
|
|
138
|
+
};
|
|
139
|
+
function transaction(options) {
|
|
140
|
+
return createTransaction(options, IMPLICIT.STORE);
|
|
141
|
+
}
|
|
142
|
+
var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
|
|
143
|
+
const tx = withdraw(token, store);
|
|
144
|
+
if (tx) {
|
|
145
|
+
return tx.run(...parameters);
|
|
146
|
+
}
|
|
147
|
+
throw new Error(
|
|
148
|
+
`Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, dispose, getState, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
|
2
153
|
//# sourceMappingURL=out.js.map
|
|
3
154
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":["../src/atom.ts","../src/dispose.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"],"names":["Internal","IMPLICIT","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AA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IACL,KAAK;AACJ,aAAO,iBAAiB,OAAO,cAAc,KAAK,KAAK;AAAA,IACxD,KAAK;AACJ,aAAO,uBAAuB,OAAO,cAAc,KAAK,KAAK;AAAA,IAC9D,KAAK;AACJ,aAAO,oBAAoB,OAAO,cAAc,KAAK,KAAK;AAAA,EAC5D;AACD;;;AC9DA,SAAS,YAAAA,WAAU,kBAAAO,iBAAgB,cAAAC,mBAAkB;AAoB9C,IAAM,WAAW,CAAC,YAA4C;AACpE,SAAOD,gBAAe,SAASP,UAAS,KAAK;AAC9C;AAEO,IAAM,OAAO,CAACS,cAAkC;AACtD,EAAAD,YAAW,WAAWC,WAAUT,UAAS,KAAK;AAC/C;AAEO,IAAM,OAAO,CAACS,cAAkC;AACtD,EAAAD,YAAW,YAAYC,WAAUT,UAAS,KAAK;AAChD;;;ACnCA,SAAS,YAAAA,WAAU,qBAAAU,oBAAmB,YAAAC,iBAAgB;AA8C/C,SAAS,YACf,SACsB;AACtB,SAAOD,mBAAkB,SAASV,UAAS,KAAK;AACjD;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeA,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKW,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} 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<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options, IMPLICIT.STORE)\n\t}\n\treturn createAtom<T>(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}\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\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t\tmutable: true\n\t\t}\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\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options, IMPLICIT.STORE)\n\t}\n\treturn createAtomFamily<T, K>(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadonlySelectorToken<any> | StateToken<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 * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<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} 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 { 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}\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}\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 { StateToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: StateToken<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\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\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) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\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(`backward`, token, s)\n\t\tthis.redo = (token) => timeTravel(`forward`, 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\tReadonlySelectorToken,\n\tStateToken,\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: ReadonlySelectorToken<T> | StateToken<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(\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken:\n\t\t| ReadonlySelectorToken<any>\n\t\t| StateToken<any>\n\t\t| TimelineToken\n\t\t| 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 TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n\tshouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken): void => {\n\ttimeTravel(`forward`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken): void => {\n\ttimeTravel(`backward`, timeline, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tupdates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `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 Act<ƒ extends ƒn> = (\n\ttransactors: Transactors & { run: typeof runTransaction },\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Act<ƒ>\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>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\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"]}
|