atom.io 0.14.5 → 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.
@@ -1,4 +1,6 @@
1
1
  import { FamilyMetadata, SelectorOptions, SelectorToken, ReadonlySelectorOptions, ReadonlySelectorToken, Transactors, StateToken, ƒn, TransactionUpdate, TransactionOptions, TransactionToken, AtomToken, MutableAtomOptions, MutableAtomToken, MutableAtomFamilyOptions, MutableAtomFamily, SelectorFamily, AtomFamily, StateUpdate, TimelineUpdate, TimelineOptions, TimelineToken, ReadonlySelectorFamily, AtomIOLogger, Logger, AtomOptions, AtomFamilyOptions, ReadonlySelectorFamilyOptions, SelectorFamilyOptions, UpdateHandler, TransactionUpdateHandler } from 'atom.io';
2
+ import { Json } from 'atom.io/json';
3
+ import { Store as Store$1 } from 'atom.io/internal';
2
4
 
3
5
  declare class Subject<T> {
4
6
  Subscriber: (value: T) => void;
@@ -183,28 +185,28 @@ interface Lineage {
183
185
  declare function newest<T extends Lineage>(scion: T): T;
184
186
  declare function eldest<T extends Lineage>(scion: T): T;
185
187
 
186
- interface Transceiver<Signal extends Serializable> {
188
+ interface Transceiver<Signal extends Json.Serializable> {
187
189
  do: (update: Signal) => void;
188
190
  undo: (update: Signal) => void;
189
191
  subscribe: (key: string, fn: (update: Signal) => void) => () => void;
190
192
  cacheUpdateNumber: number;
191
193
  getUpdateNumber: (update: Signal) => number;
192
194
  }
193
- declare function isTransceiver(value: unknown): value is Transceiver<Serializable>;
195
+ declare function isTransceiver(value: unknown): value is Transceiver<Json.Serializable>;
194
196
  type TransceiverMode = `playback` | `record` | `transaction`;
195
197
  type Signal<TVR extends Transceiver<any>> = TVR extends Transceiver<infer Signal> ? Signal : never;
196
198
 
197
- declare function createMutableAtom<Core extends Transceiver<any>, SerializableCore extends Serializable>(options: MutableAtomOptions<Core, SerializableCore>, store: Store): MutableAtomToken<Core, SerializableCore>;
199
+ declare function createMutableAtom<Core extends Transceiver<any>, SerializableCore extends Json.Serializable>(options: MutableAtomOptions<Core, SerializableCore>, store: Store): MutableAtomToken<Core, SerializableCore>;
198
200
 
199
- declare function createMutableAtomFamily<Core extends Transceiver<any>, SerializableCore extends Serializable, Key extends string>(options: MutableAtomFamilyOptions<Core, SerializableCore, Key>, store: Store): MutableAtomFamily<Core, SerializableCore, Key>;
201
+ declare function createMutableAtomFamily<Core extends Transceiver<any>, SerializableCore extends Json.Serializable, Key extends string>(options: MutableAtomFamilyOptions<Core, SerializableCore, Key>, store: Store): MutableAtomFamily<Core, SerializableCore, Key>;
200
202
 
201
- declare const getJsonFamily: <Core extends Transceiver<Serializable>, SerializableCore extends Serializable, Key extends string>(mutableAtomFamily: MutableAtomFamily<Core, SerializableCore, Key>, store: Store) => SelectorFamily<SerializableCore, Key>;
203
+ declare const getJsonFamily: <Core extends Transceiver<Json.Serializable>, SerializableCore extends Json.Serializable, Key extends string>(mutableAtomFamily: MutableAtomFamily<Core, SerializableCore, Key>, store: Store) => SelectorFamily<SerializableCore, Key>;
202
204
 
203
- declare const getJsonToken: <Core extends Transceiver<Serializable>, SerializableCore extends Serializable>(mutableAtomToken: MutableAtomToken<Core, SerializableCore>) => SelectorToken<SerializableCore>;
205
+ declare const getJsonToken: <Core extends Transceiver<Json.Serializable>, SerializableCore extends Json.Serializable>(mutableAtomToken: MutableAtomToken<Core, SerializableCore>) => SelectorToken<SerializableCore>;
204
206
 
205
- declare const getUpdateToken: <Core extends Transceiver<Serializable>, SerializableCore extends Serializable>(mutableAtomToken: MutableAtomToken<Core, SerializableCore>) => AtomToken<Signal<Core>>;
207
+ declare const getUpdateToken: <Core extends Transceiver<Json.Serializable>, SerializableCore extends Json.Serializable>(mutableAtomToken: MutableAtomToken<Core, SerializableCore>) => AtomToken<Signal<Core>>;
206
208
 
207
- declare const getUpdateFamily: <Core extends Transceiver<Serializable>, SerializableCore extends Serializable, Key extends string>(mutableAtomFamily: MutableAtomFamily<Core, SerializableCore, Key>, store: Store) => AtomFamily<Signal<Core> | null, Key>;
209
+ declare const getUpdateFamily: <Core extends Transceiver<Json.Serializable>, SerializableCore extends Json.Serializable, Key extends string>(mutableAtomFamily: MutableAtomFamily<Core, SerializableCore, Key>, store: Store) => AtomFamily<Signal<Core> | null, Key>;
208
210
 
209
211
  /**
210
212
  * @internal Give the tracker a transceiver state and a store, and it will
@@ -217,12 +219,12 @@ declare class Tracker<Mutable extends Transceiver<any>> {
217
219
  private unsubscribeFromInnerValue;
218
220
  private observeCore;
219
221
  private updateCore;
220
- mutableState: MutableAtomToken<Mutable, Serializable>;
222
+ mutableState: MutableAtomToken<Mutable, Json.Serializable>;
221
223
  latestUpdateState: AtomToken<typeof this.Update | null>;
222
- constructor(mutableState: MutableAtomToken<Mutable, Serializable>, store: Store);
224
+ constructor(mutableState: MutableAtomToken<Mutable, Json.Serializable>, store: Store);
223
225
  }
224
226
 
225
- declare class FamilyTracker<Core extends Transceiver<any>, FamilyMemberKey extends Serializable> {
227
+ declare class FamilyTracker<Core extends Transceiver<any>, FamilyMemberKey extends Json.Serializable> {
226
228
  private readonly Update;
227
229
  readonly findLatestUpdateState: AtomFamily<typeof this.Update | null, FamilyMemberKey>;
228
230
  readonly findMutableState: AtomFamily<Core, FamilyMemberKey>;
@@ -379,12 +381,12 @@ declare const readCachedValue: <T>(key: string, store: Store) => T;
379
381
  declare const isValueCached: (key: string, store: Store) => boolean;
380
382
  declare const evictCachedValue: (key: string, store: Store) => void;
381
383
 
382
- declare function createAtomFamily<T, K extends Serializable>(options: AtomFamilyOptions<T, K>, store: Store): AtomFamily<T, K>;
384
+ declare function createAtomFamily<T, K extends Json.Serializable>(options: AtomFamilyOptions<T, K>, store: Store): AtomFamily<T, K>;
383
385
 
384
- declare function createReadonlySelectorFamily<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store: Store): ReadonlySelectorFamily<T, K>;
386
+ declare function createReadonlySelectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store: Store): ReadonlySelectorFamily<T, K>;
385
387
 
386
- declare function createSelectorFamily<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>, store: Store): SelectorFamily<T, K>;
387
- declare function createSelectorFamily<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store: Store): ReadonlySelectorFamily<T, K>;
388
+ declare function createSelectorFamily<T, K extends Json.Serializable>(options: SelectorFamilyOptions<T, K>, store: Store): SelectorFamily<T, K>;
389
+ declare function createSelectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store: Store): ReadonlySelectorFamily<T, K>;
388
390
 
389
391
  declare class LazyMap<K, V> extends Map<K, V> {
390
392
  protected readonly source: Map<K, V>;
@@ -410,10 +412,10 @@ declare const setAtomOrSelector: <T>(state: Atom<T> | Selector<T>, value: T | ((
410
412
 
411
413
  declare const subscribeToRootAtoms: <T>(state: ReadonlySelector<T> | Selector<T>, store: Store) => (() => void)[] | null;
412
414
 
413
- declare function subscribeToState<T>(token: ReadonlySelectorToken<T> | StateToken<T>, handleUpdate: UpdateHandler<T>, key: string, store: Store): () => void;
415
+ declare function subscribeToState<T>(token: ReadonlySelectorToken<T> | StateToken<T>, handleUpdate: UpdateHandler<T>, key: string, store: Store$1): () => void;
414
416
 
415
- declare const subscribeToTimeline: (token: TimelineToken, handleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void, key: string, store: Store) => (() => void);
417
+ declare const subscribeToTimeline: (token: TimelineToken, handleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void, key: string, store: Store$1) => (() => void);
416
418
 
417
- declare const subscribeToTransaction: <ƒ extends ƒn>(token: TransactionToken<ƒ>, handleUpdate: TransactionUpdateHandler<ƒ>, key: string, store: Store) => (() => void);
419
+ declare const subscribeToTransaction: <ƒ extends ƒn>(token: TransactionToken<ƒ>, handleUpdate: TransactionUpdateHandler<ƒ>, key: string, store: Store$1) => (() => void);
418
420
 
419
421
  export { type Atom, type AtomKey, FamilyTracker, Future, IMPLICIT, LazyMap, type Lineage, type Modify, type MutableAtom, NotFoundError, type OperationProgress, type ReadonlySelector, type ReadonlySelectorKey, type Selector, type SelectorKey, type Signal, type StateKey, StatefulSubject, Store, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionMeta, type TransactionPhase, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, eldest, evictCachedValue, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, isAtomDefault, isAtomKey, isDone, isReadonlySelectorKey, isSelectorDefault, isSelectorKey, isStateKey, isTransceiver, isValueCached, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, redoTransactionUpdate, registerSelector, setAtomOrSelector, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, undoTransactionUpdate, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
@@ -1,257 +1,12 @@
1
- import { FamilyMetadata, ƒn, TransactionUpdate, MutableAtomToken, AtomToken, StateToken, TimelineUpdate, StateUpdate, AtomFamily, ReadonlySelectorFamily, SelectorFamily, ReadonlySelectorToken, SelectorToken, TransactionToken, TimelineToken, AtomIOLogger, Logger } from 'atom.io';
2
-
3
- declare class Subject<T> {
4
- Subscriber: (value: T) => void;
5
- subscribers: Map<string, this[`Subscriber`]>;
6
- subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
7
- private unsubscribe;
8
- next(value: T): void;
9
- }
10
- declare class StatefulSubject<T> extends Subject<T> {
11
- state: T;
12
- constructor(initialState: T);
13
- next(value: T): void;
14
- }
15
-
16
- type Selector<T> = {
17
- key: string;
18
- type: `selector`;
19
- family?: FamilyMetadata;
20
- install: (store: Store) => void;
21
- subject: Subject<{
22
- newValue: T;
23
- oldValue: T;
24
- }>;
25
- get: () => T;
26
- set: (newValue: T | ((oldValue: T) => T)) => void;
27
- };
28
- type ReadonlySelector<T> = {
29
- key: string;
30
- type: `readonly_selector`;
31
- family?: FamilyMetadata;
32
- install: (store: Store) => void;
33
- subject: Subject<{
34
- newValue: T;
35
- oldValue: T;
36
- }>;
37
- get: () => T;
38
- };
39
-
40
- type Transaction<ƒ extends ƒn> = {
41
- key: string;
42
- type: `transaction`;
43
- install: (store: Store) => void;
44
- subject: Subject<TransactionUpdate<ƒ>>;
45
- run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
46
- };
47
-
48
- type TransactionMeta<ƒ extends ƒn> = {
49
- phase: `applying` | `building`;
50
- time: number;
51
- update: TransactionUpdate<ƒ>;
52
- };
53
-
54
- type primitive = boolean | number | string | null;
55
-
56
- type Serializable = primitive | Readonly<{
57
- [key: string]: Serializable;
58
- }> | ReadonlyArray<Serializable>;
59
- type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
60
-
61
- type Refinement<Unrefined, Refined extends Unrefined> = (value: Unrefined) => value is Refined;
62
- type Cardinality = `1:1` | `1:n` | `n:n`;
63
-
64
- interface JunctionEntries<Content extends Object$1 | null> extends Object$1 {
65
- readonly relations: [string, string[]][];
66
- readonly contents: [string, Content][];
67
- }
68
- interface JunctionSchema<ASide extends string, BSide extends string> extends Object$1 {
69
- readonly between: [a: ASide, b: BSide];
70
- readonly cardinality: Cardinality;
71
- }
72
- type BaseExternalStoreConfiguration = {
73
- addRelation: (a: string, b: string) => void;
74
- deleteRelation: (a: string, b: string) => void;
75
- replaceRelationsSafely: (a: string, bs: string[]) => void;
76
- replaceRelationsUnsafely: (a: string, bs: string[]) => void;
77
- getRelatedKeys: (key: string) => Set<string> | undefined;
78
- has: (a: string, b?: string) => boolean;
79
- };
80
- type ExternalStoreWithContentConfiguration<Content extends Object$1> = {
81
- getContent: (contentKey: string) => Content | undefined;
82
- setContent: (contentKey: string, content: Content) => void;
83
- deleteContent: (contentKey: string) => void;
84
- };
85
- type Empty<Obj extends object> = {
86
- [Key in keyof Obj]?: undefined;
87
- };
88
- type ExternalStoreConfiguration<Content extends Object$1 | null> = Content extends Object$1 ? BaseExternalStoreConfiguration & ExternalStoreWithContentConfiguration<Content> : BaseExternalStoreConfiguration & Empty<ExternalStoreWithContentConfiguration<Object$1>>;
89
- type JunctionAdvancedConfiguration<Content extends Object$1 | null> = {
90
- externalStore?: ExternalStoreConfiguration<Content>;
91
- isContent?: Refinement<unknown, Content>;
92
- makeContentKey?: (a: string, b: string) => string;
93
- };
94
- type JunctionJSON<ASide extends string, BSide extends string, Content extends Object$1 | null> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>;
95
- declare class Junction<const ASide extends string, const BSide extends string, const Content extends Object$1 | null = null> {
96
- readonly a: ASide;
97
- readonly b: BSide;
98
- readonly cardinality: Cardinality;
99
- readonly relations: Map<string, Set<string>>;
100
- readonly contents: Map<string, Content>;
101
- isContent: Refinement<unknown, Content> | null;
102
- makeContentKey: (a: string, b: string) => string;
103
- getRelatedKeys(key: string): Set<string> | undefined;
104
- protected addRelation(a: string, b: string): void;
105
- protected deleteRelation(a: string, b: string): void;
106
- protected replaceRelationsUnsafely(a: string, bs: string[]): void;
107
- protected replaceRelationsSafely(a: string, bs: string[]): void;
108
- protected getContentInternal(contentKey: string): Content | undefined;
109
- protected setContent(contentKey: string, content: Content): void;
110
- protected deleteContent(contentKey: string): void;
111
- constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>, config?: JunctionAdvancedConfiguration<Content>);
112
- toJSON(): JunctionJSON<ASide, BSide, Content>;
113
- set(a: string, ...rest: Content extends null ? [b: string] : [b: string, content: Content]): this;
114
- set(relation: {
115
- [Key in ASide | BSide]: string;
116
- }, ...rest: Content extends null ? [] | [b?: undefined] : [content: Content]): this;
117
- delete(a: string, b?: string): this;
118
- delete(relation: Record<ASide | BSide, string> | Record<ASide, string> | Record<BSide, string>, b?: undefined): this;
119
- getRelatedKey(key: string): string | undefined;
120
- replaceRelations(a: string, relations: Content extends null ? string[] : Record<string, Content>, config?: {
121
- reckless: boolean;
122
- }): this;
123
- getContent(a: string, b: string): Content | undefined;
124
- getRelationEntries(input: Record<ASide, string> | Record<BSide, string>): [string, Content][];
125
- has(a: string, b?: string): boolean;
126
- }
127
-
128
- interface Lineage {
129
- parent: typeof this | null;
130
- child: typeof this | null;
131
- }
132
-
133
- interface Transceiver<Signal extends Serializable> {
134
- do: (update: Signal) => void;
135
- undo: (update: Signal) => void;
136
- subscribe: (key: string, fn: (update: Signal) => void) => () => void;
137
- cacheUpdateNumber: number;
138
- getUpdateNumber: (update: Signal) => number;
139
- }
140
-
141
- /**
142
- * @internal Give the tracker a transceiver state and a store, and it will
143
- * subscribe to the transceiver's inner value. When the inner value changes,
144
- * the tracker will update its own state to reflect the change.
145
- */
146
- declare class Tracker<Mutable extends Transceiver<any>> {
147
- private Update;
148
- private initializeState;
149
- private unsubscribeFromInnerValue;
150
- private observeCore;
151
- private updateCore;
152
- mutableState: MutableAtomToken<Mutable, Serializable>;
153
- latestUpdateState: AtomToken<typeof this.Update | null>;
154
- constructor(mutableState: MutableAtomToken<Mutable, Serializable>, store: Store);
155
- }
156
-
157
- interface MutableAtom<T> extends Atom<T> {
158
- mutable: true;
159
- }
160
-
161
- type OperationProgress = {
162
- open: false;
163
- } | {
164
- open: true;
165
- done: Set<string>;
166
- prev: Map<string, any>;
167
- time: number;
168
- token: StateToken<any>;
169
- };
170
-
171
- type TimelineAtomUpdate = StateUpdate<unknown> & {
172
- key: string;
173
- type: `atom_update`;
174
- timestamp: number;
175
- family?: FamilyMetadata;
176
- };
177
- type TimelineSelectorUpdate = {
178
- key: string;
179
- type: `selector_update`;
180
- timestamp: number;
181
- atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
182
- };
183
- type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
184
- key: string;
185
- type: `transaction_update`;
186
- timestamp: number;
187
- };
188
- type Timeline = {
189
- type: `timeline`;
190
- key: string;
191
- at: number;
192
- shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
193
- timeTraveling: `into_future` | `into_past` | null;
194
- history: TimelineUpdate[];
195
- selectorTime: number | null;
196
- transactionKey: string | null;
197
- install: (store: Store) => void;
198
- subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
199
- };
200
-
201
- declare class Store implements Lineage {
202
- parent: Store | null;
203
- child: Store | null;
204
- valueMap: Map<string, any>;
205
- atoms: Map<string, Atom<any> | MutableAtom<any>>;
206
- selectors: Map<string, Selector<any>>;
207
- readonlySelectors: Map<string, ReadonlySelector<any>>;
208
- trackers: Map<string, Tracker<Transceiver<any>>>;
209
- families: Map<string, AtomFamily<any, any> | ReadonlySelectorFamily<any, any> | SelectorFamily<any, any>>;
210
- timelines: Map<string, Timeline>;
211
- transactions: Map<string, Transaction<ƒn>>;
212
- atomsThatAreDefault: Set<string>;
213
- timelineAtoms: Junction<"timelineKey", "atomKey", null>;
214
- selectorAtoms: Junction<"selectorKey", "atomKey", null>;
215
- selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
216
- source: string;
217
- }>;
218
- subject: {
219
- atomCreation: Subject<AtomToken<unknown>>;
220
- selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
221
- transactionCreation: Subject<TransactionToken<ƒn>>;
222
- timelineCreation: Subject<TimelineToken>;
223
- transactionApplying: StatefulSubject<TransactionMeta<ƒn> | null>;
224
- operationStatus: Subject<OperationProgress>;
225
- };
226
- operation: OperationProgress;
227
- transactionMeta: TransactionMeta<ƒn> | null;
228
- config: {
229
- name: string;
230
- };
231
- loggers: AtomIOLogger[];
232
- logger: Logger;
233
- constructor(name: string, store?: Store | null);
234
- }
235
-
236
- type Atom<T> = {
237
- key: string;
238
- type: `atom`;
239
- mutable?: boolean;
240
- family?: FamilyMetadata;
241
- install: (store: Store) => void;
242
- subject: Subject<{
243
- newValue: T;
244
- oldValue: T;
245
- }>;
246
- default: T | (() => T);
247
- cleanup?: () => void;
248
- };
1
+ import { AtomToken, ReadonlySelectorToken, SelectorToken, TransactionToken, ƒn, ReadonlySelectorFamily, TransactionUpdate, TimelineToken } from 'atom.io';
2
+ import * as Internal from 'atom.io/internal';
3
+ import { Timeline } from 'atom.io/internal';
249
4
 
250
5
  type AtomTokenIndex = StateTokenIndex<AtomToken<unknown>>;
251
6
 
252
7
  type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
253
8
 
254
- declare const attachIntrospectionStates: (store?: Store) => {
9
+ declare const attachIntrospectionStates: (store?: Internal.Store) => {
255
10
  atomIndex: ReadonlySelectorToken<AtomTokenIndex>;
256
11
  selectorIndex: ReadonlySelectorToken<SelectorTokenIndex>;
257
12
  transactionIndex: ReadonlySelectorToken<TransactionToken<ƒn>[]>;
@@ -1,257 +1,12 @@
1
- import { FamilyMetadata, ƒn, TransactionUpdate, MutableAtomToken, AtomToken, StateToken, TimelineUpdate, StateUpdate, AtomFamily, ReadonlySelectorFamily, SelectorFamily, ReadonlySelectorToken, SelectorToken, TransactionToken, TimelineToken, AtomIOLogger, Logger } from 'atom.io';
2
-
3
- declare class Subject<T> {
4
- Subscriber: (value: T) => void;
5
- subscribers: Map<string, this[`Subscriber`]>;
6
- subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
7
- private unsubscribe;
8
- next(value: T): void;
9
- }
10
- declare class StatefulSubject<T> extends Subject<T> {
11
- state: T;
12
- constructor(initialState: T);
13
- next(value: T): void;
14
- }
15
-
16
- type Selector<T> = {
17
- key: string;
18
- type: `selector`;
19
- family?: FamilyMetadata;
20
- install: (store: Store) => void;
21
- subject: Subject<{
22
- newValue: T;
23
- oldValue: T;
24
- }>;
25
- get: () => T;
26
- set: (newValue: T | ((oldValue: T) => T)) => void;
27
- };
28
- type ReadonlySelector<T> = {
29
- key: string;
30
- type: `readonly_selector`;
31
- family?: FamilyMetadata;
32
- install: (store: Store) => void;
33
- subject: Subject<{
34
- newValue: T;
35
- oldValue: T;
36
- }>;
37
- get: () => T;
38
- };
39
-
40
- type Transaction<ƒ extends ƒn> = {
41
- key: string;
42
- type: `transaction`;
43
- install: (store: Store) => void;
44
- subject: Subject<TransactionUpdate<ƒ>>;
45
- run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
46
- };
47
-
48
- type TransactionMeta<ƒ extends ƒn> = {
49
- phase: `applying` | `building`;
50
- time: number;
51
- update: TransactionUpdate<ƒ>;
52
- };
53
-
54
- type primitive = boolean | number | string | null;
55
-
56
- type Serializable = primitive | Readonly<{
57
- [key: string]: Serializable;
58
- }> | ReadonlyArray<Serializable>;
59
- type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
60
-
61
- type Refinement<Unrefined, Refined extends Unrefined> = (value: Unrefined) => value is Refined;
62
- type Cardinality = `1:1` | `1:n` | `n:n`;
63
-
64
- interface JunctionEntries<Content extends Object$1 | null> extends Object$1 {
65
- readonly relations: [string, string[]][];
66
- readonly contents: [string, Content][];
67
- }
68
- interface JunctionSchema<ASide extends string, BSide extends string> extends Object$1 {
69
- readonly between: [a: ASide, b: BSide];
70
- readonly cardinality: Cardinality;
71
- }
72
- type BaseExternalStoreConfiguration = {
73
- addRelation: (a: string, b: string) => void;
74
- deleteRelation: (a: string, b: string) => void;
75
- replaceRelationsSafely: (a: string, bs: string[]) => void;
76
- replaceRelationsUnsafely: (a: string, bs: string[]) => void;
77
- getRelatedKeys: (key: string) => Set<string> | undefined;
78
- has: (a: string, b?: string) => boolean;
79
- };
80
- type ExternalStoreWithContentConfiguration<Content extends Object$1> = {
81
- getContent: (contentKey: string) => Content | undefined;
82
- setContent: (contentKey: string, content: Content) => void;
83
- deleteContent: (contentKey: string) => void;
84
- };
85
- type Empty<Obj extends object> = {
86
- [Key in keyof Obj]?: undefined;
87
- };
88
- type ExternalStoreConfiguration<Content extends Object$1 | null> = Content extends Object$1 ? BaseExternalStoreConfiguration & ExternalStoreWithContentConfiguration<Content> : BaseExternalStoreConfiguration & Empty<ExternalStoreWithContentConfiguration<Object$1>>;
89
- type JunctionAdvancedConfiguration<Content extends Object$1 | null> = {
90
- externalStore?: ExternalStoreConfiguration<Content>;
91
- isContent?: Refinement<unknown, Content>;
92
- makeContentKey?: (a: string, b: string) => string;
93
- };
94
- type JunctionJSON<ASide extends string, BSide extends string, Content extends Object$1 | null> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>;
95
- declare class Junction<const ASide extends string, const BSide extends string, const Content extends Object$1 | null = null> {
96
- readonly a: ASide;
97
- readonly b: BSide;
98
- readonly cardinality: Cardinality;
99
- readonly relations: Map<string, Set<string>>;
100
- readonly contents: Map<string, Content>;
101
- isContent: Refinement<unknown, Content> | null;
102
- makeContentKey: (a: string, b: string) => string;
103
- getRelatedKeys(key: string): Set<string> | undefined;
104
- protected addRelation(a: string, b: string): void;
105
- protected deleteRelation(a: string, b: string): void;
106
- protected replaceRelationsUnsafely(a: string, bs: string[]): void;
107
- protected replaceRelationsSafely(a: string, bs: string[]): void;
108
- protected getContentInternal(contentKey: string): Content | undefined;
109
- protected setContent(contentKey: string, content: Content): void;
110
- protected deleteContent(contentKey: string): void;
111
- constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>, config?: JunctionAdvancedConfiguration<Content>);
112
- toJSON(): JunctionJSON<ASide, BSide, Content>;
113
- set(a: string, ...rest: Content extends null ? [b: string] : [b: string, content: Content]): this;
114
- set(relation: {
115
- [Key in ASide | BSide]: string;
116
- }, ...rest: Content extends null ? [] | [b?: undefined] : [content: Content]): this;
117
- delete(a: string, b?: string): this;
118
- delete(relation: Record<ASide | BSide, string> | Record<ASide, string> | Record<BSide, string>, b?: undefined): this;
119
- getRelatedKey(key: string): string | undefined;
120
- replaceRelations(a: string, relations: Content extends null ? string[] : Record<string, Content>, config?: {
121
- reckless: boolean;
122
- }): this;
123
- getContent(a: string, b: string): Content | undefined;
124
- getRelationEntries(input: Record<ASide, string> | Record<BSide, string>): [string, Content][];
125
- has(a: string, b?: string): boolean;
126
- }
127
-
128
- interface Lineage {
129
- parent: typeof this | null;
130
- child: typeof this | null;
131
- }
132
-
133
- interface Transceiver<Signal extends Serializable> {
134
- do: (update: Signal) => void;
135
- undo: (update: Signal) => void;
136
- subscribe: (key: string, fn: (update: Signal) => void) => () => void;
137
- cacheUpdateNumber: number;
138
- getUpdateNumber: (update: Signal) => number;
139
- }
140
-
141
- /**
142
- * @internal Give the tracker a transceiver state and a store, and it will
143
- * subscribe to the transceiver's inner value. When the inner value changes,
144
- * the tracker will update its own state to reflect the change.
145
- */
146
- declare class Tracker<Mutable extends Transceiver<any>> {
147
- private Update;
148
- private initializeState;
149
- private unsubscribeFromInnerValue;
150
- private observeCore;
151
- private updateCore;
152
- mutableState: MutableAtomToken<Mutable, Serializable>;
153
- latestUpdateState: AtomToken<typeof this.Update | null>;
154
- constructor(mutableState: MutableAtomToken<Mutable, Serializable>, store: Store);
155
- }
156
-
157
- interface MutableAtom<T> extends Atom<T> {
158
- mutable: true;
159
- }
160
-
161
- type OperationProgress = {
162
- open: false;
163
- } | {
164
- open: true;
165
- done: Set<string>;
166
- prev: Map<string, any>;
167
- time: number;
168
- token: StateToken<any>;
169
- };
170
-
171
- type TimelineAtomUpdate = StateUpdate<unknown> & {
172
- key: string;
173
- type: `atom_update`;
174
- timestamp: number;
175
- family?: FamilyMetadata;
176
- };
177
- type TimelineSelectorUpdate = {
178
- key: string;
179
- type: `selector_update`;
180
- timestamp: number;
181
- atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
182
- };
183
- type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
184
- key: string;
185
- type: `transaction_update`;
186
- timestamp: number;
187
- };
188
- type Timeline = {
189
- type: `timeline`;
190
- key: string;
191
- at: number;
192
- shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
193
- timeTraveling: `into_future` | `into_past` | null;
194
- history: TimelineUpdate[];
195
- selectorTime: number | null;
196
- transactionKey: string | null;
197
- install: (store: Store) => void;
198
- subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
199
- };
200
-
201
- declare class Store implements Lineage {
202
- parent: Store | null;
203
- child: Store | null;
204
- valueMap: Map<string, any>;
205
- atoms: Map<string, Atom<any> | MutableAtom<any>>;
206
- selectors: Map<string, Selector<any>>;
207
- readonlySelectors: Map<string, ReadonlySelector<any>>;
208
- trackers: Map<string, Tracker<Transceiver<any>>>;
209
- families: Map<string, AtomFamily<any, any> | ReadonlySelectorFamily<any, any> | SelectorFamily<any, any>>;
210
- timelines: Map<string, Timeline>;
211
- transactions: Map<string, Transaction<ƒn>>;
212
- atomsThatAreDefault: Set<string>;
213
- timelineAtoms: Junction<"timelineKey", "atomKey", null>;
214
- selectorAtoms: Junction<"selectorKey", "atomKey", null>;
215
- selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
216
- source: string;
217
- }>;
218
- subject: {
219
- atomCreation: Subject<AtomToken<unknown>>;
220
- selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
221
- transactionCreation: Subject<TransactionToken<ƒn>>;
222
- timelineCreation: Subject<TimelineToken>;
223
- transactionApplying: StatefulSubject<TransactionMeta<ƒn> | null>;
224
- operationStatus: Subject<OperationProgress>;
225
- };
226
- operation: OperationProgress;
227
- transactionMeta: TransactionMeta<ƒn> | null;
228
- config: {
229
- name: string;
230
- };
231
- loggers: AtomIOLogger[];
232
- logger: Logger;
233
- constructor(name: string, store?: Store | null);
234
- }
235
-
236
- type Atom<T> = {
237
- key: string;
238
- type: `atom`;
239
- mutable?: boolean;
240
- family?: FamilyMetadata;
241
- install: (store: Store) => void;
242
- subject: Subject<{
243
- newValue: T;
244
- oldValue: T;
245
- }>;
246
- default: T | (() => T);
247
- cleanup?: () => void;
248
- };
1
+ import { AtomToken, ReadonlySelectorToken, SelectorToken, TransactionToken, ƒn, ReadonlySelectorFamily, TransactionUpdate, TimelineToken } from 'atom.io';
2
+ import * as Internal from 'atom.io/internal';
3
+ import { Timeline } from 'atom.io/internal';
249
4
 
250
5
  type AtomTokenIndex = StateTokenIndex<AtomToken<unknown>>;
251
6
 
252
7
  type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
253
8
 
254
- declare const attachIntrospectionStates: (store?: Store) => {
9
+ declare const attachIntrospectionStates: (store?: Internal.Store) => {
255
10
  atomIndex: ReadonlySelectorToken<AtomTokenIndex>;
256
11
  selectorIndex: ReadonlySelectorToken<SelectorTokenIndex>;
257
12
  transactionIndex: ReadonlySelectorToken<TransactionToken<ƒn>[]>;