atom.io 0.14.0 → 0.14.1

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.
Files changed (122) hide show
  1. package/data/dist/index.cjs +1473 -52
  2. package/data/dist/index.cjs.map +1 -1
  3. package/data/dist/index.d.cts +315 -16
  4. package/data/dist/index.js +10 -267
  5. package/data/dist/index.js.map +1 -1
  6. package/data/package.json +5 -5
  7. package/data/src/join.ts +3 -3
  8. package/dist/chunk-5VJ77LZE.js +176 -0
  9. package/dist/chunk-5VJ77LZE.js.map +1 -0
  10. package/dist/chunk-CK7GNCU5.js +309 -0
  11. package/dist/chunk-CK7GNCU5.js.map +1 -0
  12. package/dist/chunk-KW7RA7IM.js +67 -0
  13. package/dist/chunk-KW7RA7IM.js.map +1 -0
  14. package/dist/chunk-LFXB7Y6M.js +68 -0
  15. package/dist/chunk-LFXB7Y6M.js.map +1 -0
  16. package/dist/chunk-NYCVSXQB.js +181 -0
  17. package/dist/chunk-NYCVSXQB.js.map +1 -0
  18. package/dist/chunk-TE3ZSTQ6.js +2516 -0
  19. package/dist/chunk-TE3ZSTQ6.js.map +1 -0
  20. package/dist/index.cjs +2244 -55
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +268 -21
  23. package/dist/index.js +1 -152
  24. package/dist/index.js.map +1 -1
  25. package/dist/metafile-cjs.json +1 -1
  26. package/internal/dist/index.cjs +208 -79
  27. package/internal/dist/index.cjs.map +1 -1
  28. package/internal/dist/index.d.cts +226 -27
  29. package/internal/dist/index.js +1 -2240
  30. package/internal/dist/index.js.map +1 -1
  31. package/internal/package.json +5 -5
  32. package/introspection/dist/index.cjs +1618 -46
  33. package/introspection/dist/index.cjs.map +1 -1
  34. package/introspection/dist/index.d.cts +374 -4
  35. package/introspection/dist/index.js +2 -316
  36. package/introspection/dist/index.js.map +1 -1
  37. package/introspection/package.json +5 -5
  38. package/json/dist/index.cjs +1560 -8
  39. package/json/dist/index.cjs.map +1 -1
  40. package/json/dist/index.d.cts +371 -7
  41. package/json/dist/index.js +1 -76
  42. package/json/dist/index.js.map +1 -1
  43. package/json/package.json +5 -5
  44. package/package.json +5 -4
  45. package/react/dist/index.cjs +1604 -14
  46. package/react/dist/index.cjs.map +1 -1
  47. package/react/dist/index.d.cts +375 -4
  48. package/react/dist/index.js +2 -68
  49. package/react/dist/index.js.map +1 -1
  50. package/react/package.json +5 -5
  51. package/react-devtools/dist/index.cjs +2268 -198
  52. package/react-devtools/dist/index.cjs.map +1 -1
  53. package/react-devtools/dist/index.css +2 -2
  54. package/react-devtools/dist/index.d.cts +148 -24
  55. package/react-devtools/dist/index.js +57 -297
  56. package/react-devtools/dist/index.js.map +1 -1
  57. package/react-devtools/package.json +5 -5
  58. package/realtime-client/dist/index.cjs +1585 -35
  59. package/realtime-client/dist/index.cjs.map +1 -1
  60. package/realtime-client/dist/index.d.cts +382 -12
  61. package/realtime-client/dist/index.js +2 -165
  62. package/realtime-client/dist/index.js.map +1 -1
  63. package/realtime-client/package.json +5 -5
  64. package/realtime-react/dist/index.cjs +1782 -35
  65. package/realtime-react/dist/index.cjs.map +1 -1
  66. package/realtime-react/dist/index.d.cts +49 -9
  67. package/realtime-react/dist/index.js +4 -66
  68. package/realtime-react/dist/index.js.map +1 -1
  69. package/realtime-react/package.json +5 -5
  70. package/realtime-server/dist/index.cjs +1604 -58
  71. package/realtime-server/dist/index.cjs.map +1 -1
  72. package/realtime-server/dist/index.d.cts +391 -11
  73. package/realtime-server/dist/index.js +27 -21
  74. package/realtime-server/dist/index.js.map +1 -1
  75. package/realtime-server/package.json +6 -6
  76. package/realtime-testing/dist/index.cjs +2352 -16
  77. package/realtime-testing/dist/index.cjs.map +1 -1
  78. package/realtime-testing/dist/index.d.cts +486 -3
  79. package/realtime-testing/dist/index.js +10 -31
  80. package/realtime-testing/dist/index.js.map +1 -1
  81. package/realtime-testing/package.json +5 -5
  82. package/transceivers/set-rtx/dist/index.cjs +31 -10
  83. package/transceivers/set-rtx/dist/index.cjs.map +1 -1
  84. package/transceivers/set-rtx/dist/index.d.cts +29 -3
  85. package/transceivers/set-rtx/dist/index.js +2 -3
  86. package/transceivers/set-rtx/dist/index.js.map +1 -1
  87. package/transceivers/set-rtx/package.json +6 -6
  88. package/data/dist/index.d.ts +0 -158
  89. package/data/dist/metafile-cjs.json +0 -1
  90. package/data/dist/metafile-esm.json +0 -1
  91. package/dist/index.d.ts +0 -243
  92. package/dist/metafile-esm.json +0 -1
  93. package/internal/dist/index.d.ts +0 -421
  94. package/internal/dist/metafile-cjs.json +0 -1
  95. package/internal/dist/metafile-esm.json +0 -1
  96. package/introspection/dist/index.d.ts +0 -24
  97. package/introspection/dist/metafile-cjs.json +0 -1
  98. package/introspection/dist/metafile-esm.json +0 -1
  99. package/json/dist/index.d.ts +0 -51
  100. package/json/dist/metafile-cjs.json +0 -1
  101. package/json/dist/metafile-esm.json +0 -1
  102. package/react/dist/index.d.ts +0 -23
  103. package/react/dist/metafile-cjs.json +0 -1
  104. package/react/dist/metafile-esm.json +0 -1
  105. package/react-devtools/dist/index.d.ts +0 -341
  106. package/react-devtools/dist/metafile-cjs.json +0 -1
  107. package/react-devtools/dist/metafile-esm.json +0 -1
  108. package/realtime-client/dist/index.d.ts +0 -22
  109. package/realtime-client/dist/metafile-cjs.json +0 -1
  110. package/realtime-client/dist/metafile-esm.json +0 -1
  111. package/realtime-react/dist/index.d.ts +0 -27
  112. package/realtime-react/dist/metafile-cjs.json +0 -1
  113. package/realtime-react/dist/metafile-esm.json +0 -1
  114. package/realtime-server/dist/index.d.ts +0 -25
  115. package/realtime-server/dist/metafile-cjs.json +0 -1
  116. package/realtime-server/dist/metafile-esm.json +0 -1
  117. package/realtime-testing/dist/index.d.ts +0 -49
  118. package/realtime-testing/dist/metafile-cjs.json +0 -1
  119. package/realtime-testing/dist/metafile-esm.json +0 -1
  120. package/transceivers/set-rtx/dist/index.d.ts +0 -40
  121. package/transceivers/set-rtx/dist/metafile-cjs.json +0 -1
  122. package/transceivers/set-rtx/dist/metafile-esm.json +0 -1
package/dist/index.d.cts CHANGED
@@ -1,6 +1,253 @@
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';
1
+ declare class Subject<T> {
2
+ Subscriber: (value: T) => void;
3
+ subscribers: Map<string, this[`Subscriber`]>;
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
+ family?: FamilyMetadata;
243
+ install: (store: Store) => void;
244
+ subject: Subject<{
245
+ newValue: T;
246
+ oldValue: T;
247
+ }>;
248
+ default: T | (() => T);
249
+ cleanup?: () => void;
250
+ };
4
251
 
5
252
  type Effectors<T> = {
6
253
  setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void;
@@ -15,36 +262,36 @@ type AtomOptions<T> = {
15
262
  default: T | (() => T);
16
263
  effects?: AtomEffect<T>[];
17
264
  };
18
- type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = JsonInterface<T, J> & Omit<AtomOptions<T>, `default`> & {
265
+ type MutableAtomOptions<T extends Transceiver<any>, J extends Serializable> = JsonInterface<T, J> & Omit<AtomOptions<T>, `default`> & {
19
266
  default: () => T;
20
267
  mutable: true;
21
268
  };
22
- declare function atom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>;
269
+ declare function atom<T extends Transceiver<any>, J extends Serializable>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>;
23
270
  declare function atom<T>(options: AtomOptions<T>): AtomToken<T>;
24
- type AtomFamilyOptions<T, K extends Json.Serializable> = {
271
+ type AtomFamilyOptions<T, K extends Serializable> = {
25
272
  key: string;
26
273
  default: T | ((key: K) => T);
27
274
  effects?: (key: K) => AtomEffect<T>[];
28
275
  };
29
- type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => AtomToken<T>) & {
276
+ type AtomFamily<T, K extends Serializable = Serializable> = ((key: K) => AtomToken<T>) & {
30
277
  key: string;
31
278
  type: `atom_family`;
32
279
  subject: Subject<AtomToken<T>>;
33
280
  };
34
- type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> = AtomFamilyOptions<T, K> & JsonInterface<T, J> & {
281
+ type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Serializable, K extends Serializable> = AtomFamilyOptions<T, K> & JsonInterface<T, J> & {
35
282
  mutable: true;
36
283
  };
37
- type MutableAtomFamily<Core extends Transceiver<any>, SerializableCore extends Json.Serializable, Key extends Json.Serializable> = JsonInterface<Core, SerializableCore> & ((key: Key) => MutableAtomToken<Core, SerializableCore>) & {
284
+ type MutableAtomFamily<Core extends Transceiver<any>, SerializableCore extends Serializable, Key extends Serializable> = JsonInterface<Core, SerializableCore> & ((key: Key) => MutableAtomToken<Core, SerializableCore>) & {
38
285
  key: `${string}::mutable`;
39
286
  type: `atom_family`;
40
287
  subject: Subject<MutableAtomToken<Core, SerializableCore>>;
41
288
  };
42
- declare function atomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>;
43
- declare function atomFamily<T, K extends Json.Serializable>(options: AtomFamilyOptions<T, K>): AtomFamily<T, K>;
289
+ declare function atomFamily<T extends Transceiver<any>, J extends Serializable, K extends Serializable>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>;
290
+ declare function atomFamily<T, K extends Serializable>(options: AtomFamilyOptions<T, K>): AtomFamily<T, K>;
44
291
 
45
- declare function dispose(token: ReadonlySelectorToken<any> | StateToken<any>, store?: Internal.Store): void;
292
+ declare function dispose(token: ReadonlySelectorToken<any> | StateToken<any>, store?: Store): void;
46
293
 
47
- declare function getState<T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Internal.Store): T;
294
+ declare function getState<T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Store): T;
48
295
 
49
296
  declare const LoggerIconDictionary: {
50
297
  readonly "\u231B": "Timeline event fully captured";
@@ -143,29 +390,29 @@ type ReadonlySelectorOptions<T> = {
143
390
  };
144
391
  declare function selector<T>(options: SelectorOptions<T>): SelectorToken<T>;
145
392
  declare function selector<T>(options: ReadonlySelectorOptions<T>): ReadonlySelectorToken<T>;
146
- type SelectorFamilyOptions<T, K extends Json.Serializable> = {
393
+ type SelectorFamilyOptions<T, K extends Serializable> = {
147
394
  key: string;
148
395
  get: (key: K) => Read<() => T>;
149
396
  set: (key: K) => Write<(newValue: T) => void>;
150
397
  };
151
- type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {
398
+ type ReadonlySelectorFamilyOptions<T, K extends Serializable> = {
152
399
  key: string;
153
400
  get: (key: K) => Read<() => T>;
154
401
  };
155
- type SelectorFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => SelectorToken<T>) & {
402
+ type SelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => SelectorToken<T>) & {
156
403
  key: string;
157
404
  type: `selector_family`;
158
405
  subject: Subject<SelectorToken<T>>;
159
406
  };
160
- type ReadonlySelectorFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
407
+ type ReadonlySelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
161
408
  key: string;
162
409
  type: `readonly_selector_family`;
163
410
  subject: Subject<ReadonlySelectorToken<T>>;
164
411
  };
165
- declare function selectorFamily<T, K extends Json.Serializable>(options: SelectorFamilyOptions<T, K>): SelectorFamily<T, K>;
166
- declare function selectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamily<T, K>;
412
+ declare function selectorFamily<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>): SelectorFamily<T, K>;
413
+ declare function selectorFamily<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamily<T, K>;
167
414
 
168
- declare function setState<T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Internal.Store): void;
415
+ declare function setState<T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Store): void;
169
416
 
170
417
  declare class Silo {
171
418
  store: Store;
@@ -218,7 +465,7 @@ type AtomToken<_> = {
218
465
  family?: FamilyMetadata;
219
466
  __brand?: _;
220
467
  };
221
- interface MutableAtomToken<T extends Transceiver<any>, J extends Json.Serializable> extends AtomToken<T> {
468
+ interface MutableAtomToken<T extends Transceiver<any>, J extends Serializable> extends AtomToken<T> {
222
469
  __asJSON?: J;
223
470
  __update?: T extends Transceiver<infer Update> ? Update : never;
224
471
  }
package/dist/index.js CHANGED
@@ -1,154 +1,3 @@
1
- import * as Internal3 from 'atom.io/internal';
2
- import { createMutableAtom, IMPLICIT, createAtom, createMutableAtomFamily, createAtomFamily, createSelector, createSelectorFamily, Store, createTransaction, createTimeline, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, withdraw } from 'atom.io/internal';
3
-
4
- // src/atom.ts
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 };
1
+ export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, dispose, getState, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo } from './chunk-TE3ZSTQ6.js';
153
2
  //# sourceMappingURL=out.js.map
154
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,SAAS,SAAS,KAAK;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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}\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}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\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"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}