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,56 +1,11 @@
1
1
  import * as AtomIO from 'atom.io';
2
- import { FamilyMetadata, ƒn, TransactionUpdate, MutableAtomToken, AtomToken, StateToken, TimelineUpdate, StateUpdate, AtomFamily, ReadonlySelectorFamily, SelectorFamily, ReadonlySelectorToken, SelectorToken, TransactionToken, TimelineToken, AtomIOLogger, Logger } from 'atom.io';
2
+ import { SelectorFamily } from 'atom.io';
3
+ import { Store } from 'atom.io/internal';
4
+ import { Json, Stringified } from 'atom.io/json';
3
5
 
4
- declare class Subject<T> {
5
- Subscriber: (value: T) => void;
6
- subscribers: Map<string, this[`Subscriber`]>;
7
- subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
8
- private unsubscribe;
9
- next(value: T): void;
10
- }
11
- declare class StatefulSubject<T> extends Subject<T> {
12
- state: T;
13
- constructor(initialState: T);
14
- next(value: T): void;
15
- }
16
-
17
- type Selector<T> = {
18
- key: string;
19
- type: `selector`;
20
- family?: FamilyMetadata;
21
- install: (store: Store) => void;
22
- subject: Subject<{
23
- newValue: T;
24
- oldValue: T;
25
- }>;
26
- get: () => T;
27
- set: (newValue: T | ((oldValue: T) => T)) => void;
28
- };
29
- type ReadonlySelector<T> = {
30
- key: string;
31
- type: `readonly_selector`;
32
- family?: FamilyMetadata;
33
- install: (store: Store) => void;
34
- subject: Subject<{
35
- newValue: T;
36
- oldValue: T;
37
- }>;
38
- get: () => T;
39
- };
40
-
41
- type Transaction<ƒ extends ƒn> = {
42
- key: string;
43
- type: `transaction`;
44
- install: (store: Store) => void;
45
- subject: Subject<TransactionUpdate<ƒ>>;
46
- run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
47
- };
48
-
49
- type TransactionMeta<ƒ extends ƒn> = {
50
- phase: `applying` | `building`;
51
- time: number;
52
- update: TransactionUpdate<ƒ>;
53
- };
6
+ declare function dict<State, Key extends Json.Serializable>(findState: AtomIO.AtomFamily<State, Key> | AtomIO.ReadonlySelectorFamily<State, Key> | AtomIO.SelectorFamily<State, Key>, index: AtomIO.AtomToken<Key[]> | AtomIO.ReadonlySelectorToken<Key[]> | AtomIO.SelectorToken<Key[]>, store?: Store): AtomIO.ReadonlySelectorToken<{
7
+ [K in Stringified<Key>]: State;
8
+ }>;
54
9
 
55
10
  type primitive = boolean | number | string | null;
56
11
 
@@ -126,148 +81,18 @@ declare class Junction<const ASide extends string, const BSide extends string, c
126
81
  has(a: string, b?: string): boolean;
127
82
  }
128
83
 
129
- interface Lineage {
130
- parent: typeof this | null;
131
- child: typeof this | null;
132
- }
133
-
134
- type Stringified<J extends Serializable> = string & {
135
- __json: J;
136
- };
137
-
138
- interface Transceiver<Signal extends Serializable> {
139
- do: (update: Signal) => void;
140
- undo: (update: Signal) => void;
141
- subscribe: (key: string, fn: (update: Signal) => void) => () => void;
142
- cacheUpdateNumber: number;
143
- getUpdateNumber: (update: Signal) => number;
144
- }
145
-
146
- /**
147
- * @internal Give the tracker a transceiver state and a store, and it will
148
- * subscribe to the transceiver's inner value. When the inner value changes,
149
- * the tracker will update its own state to reflect the change.
150
- */
151
- declare class Tracker<Mutable extends Transceiver<any>> {
152
- private Update;
153
- private initializeState;
154
- private unsubscribeFromInnerValue;
155
- private observeCore;
156
- private updateCore;
157
- mutableState: MutableAtomToken<Mutable, Serializable>;
158
- latestUpdateState: AtomToken<typeof this.Update | null>;
159
- constructor(mutableState: MutableAtomToken<Mutable, Serializable>, store: Store);
160
- }
161
-
162
- interface MutableAtom<T> extends Atom<T> {
163
- mutable: true;
164
- }
165
-
166
- type OperationProgress = {
167
- open: false;
168
- } | {
169
- open: true;
170
- done: Set<string>;
171
- prev: Map<string, any>;
172
- time: number;
173
- token: StateToken<any>;
174
- };
175
-
176
- type TimelineAtomUpdate = StateUpdate<unknown> & {
177
- key: string;
178
- type: `atom_update`;
179
- timestamp: number;
180
- family?: FamilyMetadata;
181
- };
182
- type TimelineSelectorUpdate = {
183
- key: string;
184
- type: `selector_update`;
185
- timestamp: number;
186
- atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
187
- };
188
- type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
189
- key: string;
190
- type: `transaction_update`;
191
- timestamp: number;
192
- };
193
- type Timeline = {
194
- type: `timeline`;
195
- key: string;
196
- at: number;
197
- shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
198
- timeTraveling: `into_future` | `into_past` | null;
199
- history: TimelineUpdate[];
200
- selectorTime: number | null;
201
- transactionKey: string | null;
202
- install: (store: Store) => void;
203
- subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
204
- };
205
-
206
- declare class Store implements Lineage {
207
- parent: Store | null;
208
- child: Store | null;
209
- valueMap: Map<string, any>;
210
- atoms: Map<string, Atom<any> | MutableAtom<any>>;
211
- selectors: Map<string, Selector<any>>;
212
- readonlySelectors: Map<string, ReadonlySelector<any>>;
213
- trackers: Map<string, Tracker<Transceiver<any>>>;
214
- families: Map<string, AtomFamily<any, any> | ReadonlySelectorFamily<any, any> | SelectorFamily<any, any>>;
215
- timelines: Map<string, Timeline>;
216
- transactions: Map<string, Transaction<ƒn>>;
217
- atomsThatAreDefault: Set<string>;
218
- timelineAtoms: Junction<"timelineKey", "atomKey", null>;
219
- selectorAtoms: Junction<"selectorKey", "atomKey", null>;
220
- selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
221
- source: string;
222
- }>;
223
- subject: {
224
- atomCreation: Subject<AtomToken<unknown>>;
225
- selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
226
- transactionCreation: Subject<TransactionToken<ƒn>>;
227
- timelineCreation: Subject<TimelineToken>;
228
- transactionApplying: StatefulSubject<TransactionMeta<ƒn> | null>;
229
- operationStatus: Subject<OperationProgress>;
230
- };
231
- operation: OperationProgress;
232
- transactionMeta: TransactionMeta<ƒn> | null;
233
- config: {
234
- name: string;
235
- };
236
- loggers: AtomIOLogger[];
237
- logger: Logger;
238
- constructor(name: string, store?: Store | null);
239
- }
240
-
241
- type Atom<T> = {
242
- key: string;
243
- type: `atom`;
244
- mutable?: boolean;
245
- family?: FamilyMetadata;
246
- install: (store: Store) => void;
247
- subject: Subject<{
248
- newValue: T;
249
- oldValue: T;
250
- }>;
251
- default: T | (() => T);
252
- cleanup?: () => void;
253
- };
254
-
255
- declare function dict<State, Key extends Serializable>(findState: AtomIO.AtomFamily<State, Key> | AtomIO.ReadonlySelectorFamily<State, Key> | AtomIO.SelectorFamily<State, Key>, index: AtomIO.AtomToken<Key[]> | AtomIO.ReadonlySelectorToken<Key[]> | AtomIO.SelectorToken<Key[]>, store?: Store): AtomIO.ReadonlySelectorToken<{
256
- [K in Stringified<Key>]: State;
257
- }>;
258
-
259
- interface JoinOptions<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Object$1 | null> extends Object$1, JunctionSchema<ASide, BSide>, Partial<JunctionEntries<Content>> {
84
+ interface JoinOptions<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Json.Object | null> extends Json.Object, JunctionSchema<ASide, BSide>, Partial<JunctionEntries<Content>> {
260
85
  readonly key: string;
261
86
  readonly cardinality: Cardinality;
262
87
  }
263
- type JoinState<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Object$1 | null> = Cardinality extends `1:1` ? (Content extends Object$1 ? {
88
+ type JoinState<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? {
264
89
  readonly [AB in ASide | BSide as AB extends ASide ? `${AB}EntryOf${Capitalize<BSide>}` : `${AB}EntryOf${Capitalize<ASide>}`]: SelectorFamily<[
265
90
  string,
266
91
  Content
267
92
  ] | undefined, string>;
268
93
  } : {}) & {
269
94
  readonly [AB in ASide | BSide as AB extends ASide ? `${AB}KeyOf${Capitalize<BSide>}` : `${AB}KeyOf${Capitalize<ASide>}`]: SelectorFamily<string | undefined, string>;
270
- } : Cardinality extends `1:n` ? (Content extends Object$1 ? {
95
+ } : Cardinality extends `1:n` ? (Content extends Json.Object ? {
271
96
  readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: SelectorFamily<[
272
97
  string,
273
98
  Content
@@ -281,7 +106,7 @@ type JoinState<ASide extends string, BSide extends string, Cardinality extends C
281
106
  readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: SelectorFamily<string | undefined, string>;
282
107
  } & {
283
108
  readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: SelectorFamily<string[], string>;
284
- } : Cardinality extends `n:n` ? (Content extends Object$1 ? {
109
+ } : Cardinality extends `n:n` ? (Content extends Json.Object ? {
285
110
  readonly [AB in ASide | BSide as AB extends ASide ? `${AB}EntriesOf${Capitalize<BSide>}` : `${AB}EntriesOf${Capitalize<ASide>}`]: SelectorFamily<[
286
111
  string,
287
112
  Content
@@ -293,7 +118,7 @@ declare function join<const ASide extends string, const BSide extends string, co
293
118
  relations: Junction<ASide, BSide>;
294
119
  findState: JoinState<ASide, BSide, Cardinality, null>;
295
120
  };
296
- declare function join<const ASide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const BSide extends string, const Content extends Object$1>(options: JoinOptions<ASide, BSide, Cardinality, Content>, defaultContent: Content, store?: Store): {
121
+ declare function join<const ASide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const BSide extends string, const Content extends Json.Object>(options: JoinOptions<ASide, BSide, Cardinality, Content>, defaultContent: Content, store?: Store): {
297
122
  relations: Junction<ASide, BSide, Content>;
298
123
  findState: JoinState<ASide, BSide, Cardinality, Content>;
299
124
  };
@@ -1,56 +1,11 @@
1
1
  import * as AtomIO from 'atom.io';
2
- import { FamilyMetadata, ƒn, TransactionUpdate, MutableAtomToken, AtomToken, StateToken, TimelineUpdate, StateUpdate, AtomFamily, ReadonlySelectorFamily, SelectorFamily, ReadonlySelectorToken, SelectorToken, TransactionToken, TimelineToken, AtomIOLogger, Logger } from 'atom.io';
2
+ import { SelectorFamily } from 'atom.io';
3
+ import { Store } from 'atom.io/internal';
4
+ import { Json, Stringified } from 'atom.io/json';
3
5
 
4
- declare class Subject<T> {
5
- Subscriber: (value: T) => void;
6
- subscribers: Map<string, this[`Subscriber`]>;
7
- subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
8
- private unsubscribe;
9
- next(value: T): void;
10
- }
11
- declare class StatefulSubject<T> extends Subject<T> {
12
- state: T;
13
- constructor(initialState: T);
14
- next(value: T): void;
15
- }
16
-
17
- type Selector<T> = {
18
- key: string;
19
- type: `selector`;
20
- family?: FamilyMetadata;
21
- install: (store: Store) => void;
22
- subject: Subject<{
23
- newValue: T;
24
- oldValue: T;
25
- }>;
26
- get: () => T;
27
- set: (newValue: T | ((oldValue: T) => T)) => void;
28
- };
29
- type ReadonlySelector<T> = {
30
- key: string;
31
- type: `readonly_selector`;
32
- family?: FamilyMetadata;
33
- install: (store: Store) => void;
34
- subject: Subject<{
35
- newValue: T;
36
- oldValue: T;
37
- }>;
38
- get: () => T;
39
- };
40
-
41
- type Transaction<ƒ extends ƒn> = {
42
- key: string;
43
- type: `transaction`;
44
- install: (store: Store) => void;
45
- subject: Subject<TransactionUpdate<ƒ>>;
46
- run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
47
- };
48
-
49
- type TransactionMeta<ƒ extends ƒn> = {
50
- phase: `applying` | `building`;
51
- time: number;
52
- update: TransactionUpdate<ƒ>;
53
- };
6
+ declare function dict<State, Key extends Json.Serializable>(findState: AtomIO.AtomFamily<State, Key> | AtomIO.ReadonlySelectorFamily<State, Key> | AtomIO.SelectorFamily<State, Key>, index: AtomIO.AtomToken<Key[]> | AtomIO.ReadonlySelectorToken<Key[]> | AtomIO.SelectorToken<Key[]>, store?: Store): AtomIO.ReadonlySelectorToken<{
7
+ [K in Stringified<Key>]: State;
8
+ }>;
54
9
 
55
10
  type primitive = boolean | number | string | null;
56
11
 
@@ -126,148 +81,18 @@ declare class Junction<const ASide extends string, const BSide extends string, c
126
81
  has(a: string, b?: string): boolean;
127
82
  }
128
83
 
129
- interface Lineage {
130
- parent: typeof this | null;
131
- child: typeof this | null;
132
- }
133
-
134
- type Stringified<J extends Serializable> = string & {
135
- __json: J;
136
- };
137
-
138
- interface Transceiver<Signal extends Serializable> {
139
- do: (update: Signal) => void;
140
- undo: (update: Signal) => void;
141
- subscribe: (key: string, fn: (update: Signal) => void) => () => void;
142
- cacheUpdateNumber: number;
143
- getUpdateNumber: (update: Signal) => number;
144
- }
145
-
146
- /**
147
- * @internal Give the tracker a transceiver state and a store, and it will
148
- * subscribe to the transceiver's inner value. When the inner value changes,
149
- * the tracker will update its own state to reflect the change.
150
- */
151
- declare class Tracker<Mutable extends Transceiver<any>> {
152
- private Update;
153
- private initializeState;
154
- private unsubscribeFromInnerValue;
155
- private observeCore;
156
- private updateCore;
157
- mutableState: MutableAtomToken<Mutable, Serializable>;
158
- latestUpdateState: AtomToken<typeof this.Update | null>;
159
- constructor(mutableState: MutableAtomToken<Mutable, Serializable>, store: Store);
160
- }
161
-
162
- interface MutableAtom<T> extends Atom<T> {
163
- mutable: true;
164
- }
165
-
166
- type OperationProgress = {
167
- open: false;
168
- } | {
169
- open: true;
170
- done: Set<string>;
171
- prev: Map<string, any>;
172
- time: number;
173
- token: StateToken<any>;
174
- };
175
-
176
- type TimelineAtomUpdate = StateUpdate<unknown> & {
177
- key: string;
178
- type: `atom_update`;
179
- timestamp: number;
180
- family?: FamilyMetadata;
181
- };
182
- type TimelineSelectorUpdate = {
183
- key: string;
184
- type: `selector_update`;
185
- timestamp: number;
186
- atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
187
- };
188
- type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
189
- key: string;
190
- type: `transaction_update`;
191
- timestamp: number;
192
- };
193
- type Timeline = {
194
- type: `timeline`;
195
- key: string;
196
- at: number;
197
- shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
198
- timeTraveling: `into_future` | `into_past` | null;
199
- history: TimelineUpdate[];
200
- selectorTime: number | null;
201
- transactionKey: string | null;
202
- install: (store: Store) => void;
203
- subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
204
- };
205
-
206
- declare class Store implements Lineage {
207
- parent: Store | null;
208
- child: Store | null;
209
- valueMap: Map<string, any>;
210
- atoms: Map<string, Atom<any> | MutableAtom<any>>;
211
- selectors: Map<string, Selector<any>>;
212
- readonlySelectors: Map<string, ReadonlySelector<any>>;
213
- trackers: Map<string, Tracker<Transceiver<any>>>;
214
- families: Map<string, AtomFamily<any, any> | ReadonlySelectorFamily<any, any> | SelectorFamily<any, any>>;
215
- timelines: Map<string, Timeline>;
216
- transactions: Map<string, Transaction<ƒn>>;
217
- atomsThatAreDefault: Set<string>;
218
- timelineAtoms: Junction<"timelineKey", "atomKey", null>;
219
- selectorAtoms: Junction<"selectorKey", "atomKey", null>;
220
- selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
221
- source: string;
222
- }>;
223
- subject: {
224
- atomCreation: Subject<AtomToken<unknown>>;
225
- selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
226
- transactionCreation: Subject<TransactionToken<ƒn>>;
227
- timelineCreation: Subject<TimelineToken>;
228
- transactionApplying: StatefulSubject<TransactionMeta<ƒn> | null>;
229
- operationStatus: Subject<OperationProgress>;
230
- };
231
- operation: OperationProgress;
232
- transactionMeta: TransactionMeta<ƒn> | null;
233
- config: {
234
- name: string;
235
- };
236
- loggers: AtomIOLogger[];
237
- logger: Logger;
238
- constructor(name: string, store?: Store | null);
239
- }
240
-
241
- type Atom<T> = {
242
- key: string;
243
- type: `atom`;
244
- mutable?: boolean;
245
- family?: FamilyMetadata;
246
- install: (store: Store) => void;
247
- subject: Subject<{
248
- newValue: T;
249
- oldValue: T;
250
- }>;
251
- default: T | (() => T);
252
- cleanup?: () => void;
253
- };
254
-
255
- declare function dict<State, Key extends Serializable>(findState: AtomIO.AtomFamily<State, Key> | AtomIO.ReadonlySelectorFamily<State, Key> | AtomIO.SelectorFamily<State, Key>, index: AtomIO.AtomToken<Key[]> | AtomIO.ReadonlySelectorToken<Key[]> | AtomIO.SelectorToken<Key[]>, store?: Store): AtomIO.ReadonlySelectorToken<{
256
- [K in Stringified<Key>]: State;
257
- }>;
258
-
259
- interface JoinOptions<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Object$1 | null> extends Object$1, JunctionSchema<ASide, BSide>, Partial<JunctionEntries<Content>> {
84
+ interface JoinOptions<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Json.Object | null> extends Json.Object, JunctionSchema<ASide, BSide>, Partial<JunctionEntries<Content>> {
260
85
  readonly key: string;
261
86
  readonly cardinality: Cardinality;
262
87
  }
263
- type JoinState<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Object$1 | null> = Cardinality extends `1:1` ? (Content extends Object$1 ? {
88
+ type JoinState<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? {
264
89
  readonly [AB in ASide | BSide as AB extends ASide ? `${AB}EntryOf${Capitalize<BSide>}` : `${AB}EntryOf${Capitalize<ASide>}`]: SelectorFamily<[
265
90
  string,
266
91
  Content
267
92
  ] | undefined, string>;
268
93
  } : {}) & {
269
94
  readonly [AB in ASide | BSide as AB extends ASide ? `${AB}KeyOf${Capitalize<BSide>}` : `${AB}KeyOf${Capitalize<ASide>}`]: SelectorFamily<string | undefined, string>;
270
- } : Cardinality extends `1:n` ? (Content extends Object$1 ? {
95
+ } : Cardinality extends `1:n` ? (Content extends Json.Object ? {
271
96
  readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: SelectorFamily<[
272
97
  string,
273
98
  Content
@@ -281,7 +106,7 @@ type JoinState<ASide extends string, BSide extends string, Cardinality extends C
281
106
  readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: SelectorFamily<string | undefined, string>;
282
107
  } & {
283
108
  readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: SelectorFamily<string[], string>;
284
- } : Cardinality extends `n:n` ? (Content extends Object$1 ? {
109
+ } : Cardinality extends `n:n` ? (Content extends Json.Object ? {
285
110
  readonly [AB in ASide | BSide as AB extends ASide ? `${AB}EntriesOf${Capitalize<BSide>}` : `${AB}EntriesOf${Capitalize<ASide>}`]: SelectorFamily<[
286
111
  string,
287
112
  Content
@@ -293,7 +118,7 @@ declare function join<const ASide extends string, const BSide extends string, co
293
118
  relations: Junction<ASide, BSide>;
294
119
  findState: JoinState<ASide, BSide, Cardinality, null>;
295
120
  };
296
- declare function join<const ASide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const BSide extends string, const Content extends Object$1>(options: JoinOptions<ASide, BSide, Cardinality, Content>, defaultContent: Content, store?: Store): {
121
+ declare function join<const ASide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const BSide extends string, const Content extends Json.Object>(options: JoinOptions<ASide, BSide, Cardinality, Content>, defaultContent: Content, store?: Store): {
297
122
  relations: Junction<ASide, BSide, Content>;
298
123
  findState: JoinState<ASide, BSide, Cardinality, Content>;
299
124
  };