atom.io 0.32.0 → 0.32.2

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 (57) hide show
  1. package/data/dist/index.d.ts +8 -925
  2. package/data/dist/index.js +2 -2
  3. package/dist/{chunk-5F2V7S3B.js → chunk-HEEVASKG.js} +1 -1
  4. package/dist/{chunk-ECOMOMUN.js → chunk-KMBRCA5Q.js} +20 -19
  5. package/dist/{chunk-R3ZUK5EH.js → chunk-NDTM5IY3.js} +22 -11
  6. package/dist/{chunk-354XQWHH.js → chunk-QRPY4LSO.js} +5 -5
  7. package/dist/{chunk-GY2XQYZY.js → chunk-RXQWAO26.js} +50 -41
  8. package/dist/{chunk-Z2UJW4NQ.js → chunk-XN3EO2UT.js} +3 -3
  9. package/dist/{chunk-NF7FJKJD.js → chunk-YPME5OLO.js} +6 -4
  10. package/dist/index.d.ts +45 -516
  11. package/dist/index.js +1 -1
  12. package/eslint-plugin/dist/index.js +3 -3
  13. package/eslint-plugin/src/rules/explicit-state-types.ts +1 -0
  14. package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +1 -0
  15. package/eslint-plugin/src/walk.ts +1 -0
  16. package/internal/dist/index.d.ts +9 -657
  17. package/internal/dist/index.js +1 -1
  18. package/internal/src/join/join-internal.ts +1 -1
  19. package/internal/src/junction.ts +7 -4
  20. package/internal/src/lazy-map.ts +3 -1
  21. package/internal/src/set-state/emit-update.ts +3 -1
  22. package/internal/src/timeline/create-timeline.ts +2 -1
  23. package/internal/src/timeline/time-travel.ts +2 -1
  24. package/introspection/dist/index.d.ts +6 -922
  25. package/introspection/dist/index.js +2 -2
  26. package/introspection/src/auditor.ts +3 -3
  27. package/json/dist/index.d.ts +5 -899
  28. package/json/dist/index.js +1 -1
  29. package/package.json +10 -10
  30. package/react/dist/index.d.ts +3 -921
  31. package/react/dist/index.js +2 -2
  32. package/react-devtools/dist/index.d.ts +1 -26
  33. package/react-devtools/dist/index.js +28 -15
  34. package/react-devtools/src/Updates.tsx +12 -0
  35. package/react-devtools/src/json-editor/editors-by-type/utilities/cast-to-json.ts +2 -1
  36. package/realtime/dist/index.d.ts +8 -203
  37. package/realtime/dist/index.js +2 -2
  38. package/realtime/src/realtime-continuity.ts +5 -1
  39. package/realtime-client/dist/index.d.ts +21 -959
  40. package/realtime-client/dist/index.js +2 -2
  41. package/realtime-react/dist/index.d.ts +12 -166
  42. package/realtime-react/dist/index.js +4 -4
  43. package/realtime-server/dist/index.d.ts +27 -972
  44. package/realtime-server/dist/index.js +3 -3
  45. package/realtime-server/src/ipc-sockets/child-socket.ts +2 -0
  46. package/realtime-server/src/ipc-sockets/custom-socket.ts +6 -1
  47. package/realtime-server/src/realtime-server-stores/server-sync-store.ts +10 -2
  48. package/realtime-testing/dist/index.d.ts +3 -1091
  49. package/realtime-testing/dist/index.js +7 -7
  50. package/src/logger.ts +12 -4
  51. package/transceivers/set-rtx/dist/index.d.ts +6 -40
  52. package/transceivers/set-rtx/dist/index.js +1 -1
  53. package/transceivers/set-rtx/src/set-rtx.ts +4 -7
  54. package/web/dist/index.d.ts +1 -30
  55. package/react-devtools/src/json-editor/assets/Untitled-1.ai +2 -1436
  56. package/react-devtools/src/json-editor/assets/data-vis.ai +1 -1548
  57. package/react-devtools/src/json-editor/comp/json-editor-sketches.ai +5 -1449
@@ -1,1097 +1,9 @@
1
1
  import { RenderResult } from '@testing-library/react';
2
+ import * as AtomIO from 'atom.io';
2
3
  import * as React from 'react';
3
4
  import * as SocketIO from 'socket.io';
4
5
  import { Socket } from 'socket.io-client';
5
6
 
6
- type primitive = boolean | number | string | null;
7
- declare namespace Json {
8
- namespace Tree {
9
- type Array<Element = unknown> = ReadonlyArray<Element>;
10
- type Object<K extends string = string, V = unknown> = Record<K, V>;
11
- type Fork = Array | Object;
12
- type Leaf = primitive;
13
- type Node = Fork | Leaf;
14
- }
15
- type Serializable = primitive | Readonly<{
16
- [key: string]: Serializable;
17
- }> | ReadonlyArray<Serializable>;
18
- type Object<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
19
- type Array<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
20
- }
21
- type stringified<J extends Json.Serializable> = J extends string ? `"${J}"` : J extends number ? `${J}` : J extends true ? `true` : J extends false ? `false` : J extends boolean ? `false` | `true` : J extends null ? `null` : string & {
22
- __json?: J;
23
- };
24
- type Canonical = primitive | ReadonlyArray<Canonical>;
25
- type JsonInterface<T, J extends Json.Serializable = Json.Serializable> = {
26
- toJson: (t: T) => J;
27
- fromJson: (json: J) => T;
28
- };
29
-
30
- declare class CircularBuffer<T> {
31
- protected _buffer: T[];
32
- protected _index: number;
33
- constructor(array: T[]);
34
- constructor(length: number);
35
- get buffer(): ReadonlyArray<T | undefined>;
36
- get index(): number;
37
- add(item: T): void;
38
- copy(): CircularBuffer<T>;
39
- }
40
-
41
- type Func = (...parameters: any[]) => any;
42
- type Flat<R extends {
43
- [K in PropertyKey]: any;
44
- }> = {
45
- [K in keyof R]: R[K];
46
- };
47
- type Count<N extends number, A extends any[] = []> = [
48
- ...A,
49
- any
50
- ][`length`] extends N ? A[`length`] : A[`length`] | Count<N, [...A, any]>;
51
- type Each<E extends any[]> = {
52
- [P in Count<E[`length`]>]: E[P];
53
- };
54
- type Refinement<A, B extends A> = (a: A) => a is B;
55
-
56
- type JunctionEntriesBase<AType extends string, BType extends string, Content extends Json.Object | null> = {
57
- readonly relations: ([AType, BType[]] | [BType, AType[]])[];
58
- readonly contents: [string, Content][];
59
- };
60
- interface JunctionEntries<AType extends string, BType extends string, Content extends Json.Object | null> extends Json.Object, JunctionEntriesBase<AType, BType, Content> {
61
- }
62
- type JunctionSchemaBase<ASide extends string, BSide extends string> = {
63
- readonly between: [a: ASide, b: BSide];
64
- readonly cardinality: `1:1` | `1:n` | `n:n`;
65
- };
66
- interface JunctionSchema<ASide extends string, BSide extends string> extends Json.Object, JunctionSchemaBase<ASide, BSide> {
67
- }
68
- type BaseExternalStoreConfiguration = {
69
- addRelation: (a: string, b: string) => void;
70
- deleteRelation: (a: string, b: string) => void;
71
- replaceRelationsSafely: (a: string, bs: string[]) => void;
72
- replaceRelationsUnsafely: (a: string, bs: string[]) => void;
73
- getRelatedKeys(key: string): Set<string> | undefined;
74
- has: (a: string, b?: string) => boolean;
75
- };
76
- type ExternalStoreWithContentConfiguration<Content extends Json.Object> = {
77
- getContent: (contentKey: string) => Content | undefined;
78
- setContent: (contentKey: string, content: Content) => void;
79
- deleteContent: (contentKey: string) => void;
80
- };
81
- type Empty<Obj extends object> = {
82
- [Key in keyof Obj]?: undefined;
83
- };
84
- type ExternalStoreConfiguration<Content extends Json.Object | null> = Content extends Json.Object ? BaseExternalStoreConfiguration & ExternalStoreWithContentConfiguration<Content> : BaseExternalStoreConfiguration & Empty<ExternalStoreWithContentConfiguration<Json.Object>>;
85
- type JunctionAdvancedConfiguration<AType extends string, BType extends string, Content extends Json.Object | null> = {
86
- warn?: (...args: any[]) => void;
87
- externalStore?: ExternalStoreConfiguration<Content>;
88
- isAType?: Refinement<string, AType>;
89
- isBType?: Refinement<string, BType>;
90
- isContent?: Refinement<unknown, Content>;
91
- makeContentKey?: (a: AType, b: BType) => string;
92
- };
93
- type JunctionJSON<ASide extends string, AType extends string, BSide extends string, BType extends string, Content extends Json.Object | null> = JunctionEntries<AType, BType, Content> & JunctionSchema<ASide, BSide>;
94
- declare class Junction<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Content extends Json.Object | null = null> {
95
- readonly a: ASide;
96
- readonly b: BSide;
97
- readonly cardinality: `1:1` | `1:n` | `n:n`;
98
- readonly relations: Map<AType | BType, Set<AType> | Set<BType>>;
99
- readonly contents: Map<string, Content>;
100
- isAType?: Refinement<string, AType> | null;
101
- isBType?: Refinement<string, BType> | null;
102
- isContent: Refinement<unknown, Content> | null;
103
- makeContentKey: (a: AType, b: BType) => string;
104
- warn?: (...args: any[]) => void;
105
- getRelatedKeys(key: AType): Set<BType> | undefined;
106
- getRelatedKeys(key: BType): Set<AType> | undefined;
107
- getRelatedKeys(key: AType | BType): Set<AType> | Set<BType> | undefined;
108
- protected addRelation(a: AType, b: BType): void;
109
- protected deleteRelation(a: AType, b: BType): void;
110
- protected replaceRelationsUnsafely(a: AType, bs: BType[]): void;
111
- protected replaceRelationsUnsafely(b: BType, as: AType[]): void;
112
- protected replaceRelationsSafely(a: AType, bs: BType[]): void;
113
- protected replaceRelationsSafely(b: BType, as: AType[]): void;
114
- protected getContentInternal(contentKey: string): Content | undefined;
115
- protected setContent(contentKey: string, content: Content): void;
116
- protected deleteContent(contentKey: string): void;
117
- constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<NoInfer<AType>, NoInfer<BType>, Content>>, config?: JunctionAdvancedConfiguration<AType, BType, Content>);
118
- toJSON(): JunctionJSON<ASide, AType, BSide, BType, Content>;
119
- set(a: AType, ...rest: Content extends null ? [b: BType] : [b: BType, content: Content]): this;
120
- set(relation: {
121
- [Key in ASide]: AType;
122
- } & {
123
- [Key in BSide]: BType;
124
- }, ...rest: Content extends null ? [] | [void?: undefined] : [content: Content]): this;
125
- delete(a: AType, b?: BType): this;
126
- delete(b: BType, a?: AType): this;
127
- delete(relation: {
128
- [Key in ASide]: AType;
129
- } | {
130
- [Key in BSide]: BType;
131
- } | ({
132
- [Key in ASide]: AType;
133
- } & {
134
- [Key in BSide]: BType;
135
- }), b?: undefined): this;
136
- getRelatedKey(key: AType): BType | undefined;
137
- getRelatedKey(key: BType): AType | undefined;
138
- replaceRelations(a: AType, relations: Content extends null ? BType[] : Record<BType, Content>, config?: {
139
- reckless: boolean;
140
- }): this;
141
- replaceRelations(b: BType, relations: Content extends null ? AType[] : Record<AType, Content>, config?: {
142
- reckless: boolean;
143
- }): this;
144
- getContent(a: AType, b: BType): Content | undefined;
145
- getRelationEntries(input: Record<ASide, AType>): [BType, Content][];
146
- getRelationEntries(input: Record<BSide, BType>): [AType, Content][];
147
- has(a: AType, b?: BType): boolean;
148
- has(b: BType, a?: AType): boolean;
149
- }
150
-
151
- declare class Subject<T> {
152
- Subscriber: (value: T) => void;
153
- subscribers: Map<string, this[`Subscriber`]>;
154
- subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
155
- private unsubscribe;
156
- next(value: T): void;
157
- }
158
- declare class StatefulSubject<T> extends Subject<T> {
159
- state: T;
160
- constructor(initialState: T);
161
- next(value: T): void;
162
- }
163
-
164
- type Transaction<F extends Func> = {
165
- key: string;
166
- type: `transaction`;
167
- install: (store: Store) => void;
168
- subject: Subject<TransactionUpdate<F>>;
169
- run: (parameters: Parameters<F>, id?: string) => ReturnType<F>;
170
- };
171
-
172
- type TransactionProgress<F extends Func> = {
173
- phase: `applying` | `building`;
174
- update: TransactionUpdate<F>;
175
- toolkit: ActorToolkit;
176
- };
177
- type TransactionEpoch = {
178
- epoch: Map<string, number>;
179
- actionContinuities: Junction<`continuity`, string, `action`, string>;
180
- };
181
-
182
- type SetUpdate = `add:${string}` | `clear:${string}` | `del:${string}` | `tx:${string}`;
183
- type NumberedSetUpdate = `${number}=${SetUpdate}`;
184
- interface SetRTXJson<P extends primitive> extends Json.Object {
185
- members: P[];
186
- cache: (NumberedSetUpdate | null)[];
187
- cacheLimit: number;
188
- cacheIdx: number;
189
- cacheUpdateNumber: number;
190
- }
191
- declare class SetRTX<P extends primitive> extends Set<P> implements Transceiver<NumberedSetUpdate>, Lineage {
192
- mode: TransceiverMode;
193
- readonly subject: Subject<SetUpdate>;
194
- cacheLimit: number;
195
- cache: (NumberedSetUpdate | null)[];
196
- cacheIdx: number;
197
- cacheUpdateNumber: number;
198
- constructor(values?: Iterable<P>, cacheLimit?: number);
199
- toJSON(): SetRTXJson<P>;
200
- static fromJSON<P extends primitive>(json: SetRTXJson<P>): SetRTX<P>;
201
- add(value: P): this;
202
- clear(): void;
203
- delete(value: P): boolean;
204
- readonly parent: SetRTX<P> | null;
205
- child: SetRTX<P> | null;
206
- transactionUpdates: SetUpdate[] | null;
207
- transaction(run: (child: SetRTX<P>) => boolean): void;
208
- protected _subscribe(key: string, fn: (update: SetUpdate) => void): () => void;
209
- subscribe(key: string, fn: (update: NumberedSetUpdate) => void): () => void;
210
- emit(update: SetUpdate): void;
211
- private doStep;
212
- getUpdateNumber(update: NumberedSetUpdate): number;
213
- do(update: NumberedSetUpdate): number | `OUT_OF_RANGE` | null;
214
- undoStep(update: SetUpdate): void;
215
- undo(update: NumberedSetUpdate): number | null;
216
- }
217
-
218
- type Molecule<K extends Canonical> = {
219
- readonly key: K;
220
- readonly stringKey: stringified<K>;
221
- readonly dependsOn: `all` | `any`;
222
- };
223
-
224
- type JoinStateFamilies<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? {
225
- readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<[
226
- AType,
227
- Content
228
- ] | null, BType>;
229
- } & {
230
- readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<[
231
- BType,
232
- Content
233
- ] | null, AType>;
234
- } : {}) & {
235
- readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<AType | null, BType>;
236
- } & {
237
- readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<BType | null, AType>;
238
- } : Cardinality extends `1:n` ? (Content extends Json.Object ? {
239
- readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<[
240
- AType,
241
- Content
242
- ] | null, BType>;
243
- } & {
244
- readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<[
245
- BType,
246
- Content
247
- ][], AType>;
248
- } : {}) & {
249
- readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<AType | null, BType>;
250
- } & {
251
- readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<BType[], AType>;
252
- } : Cardinality extends `n:n` ? (Content extends Json.Object ? {
253
- readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<[
254
- AType,
255
- Content
256
- ][], BType>;
257
- } & {
258
- readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<[
259
- BType,
260
- Content
261
- ][], AType>;
262
- } : {}) & {
263
- readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<AType[], BType>;
264
- } & {
265
- readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<BType[], AType>;
266
- } : never;
267
- declare class Join<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object | null = null, const ContentKey extends CompoundTypedKey<`content`, ASide, BSide> = CompoundTypedKey<`content`, ASide, BSide>> {
268
- private toolkit;
269
- options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>;
270
- defaultContent: Content | undefined;
271
- molecules: Map<string, Molecule<any>>;
272
- relations: Junction<ASide, AType, BSide, BType, Content>;
273
- states: JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>;
274
- core: {
275
- relatedKeysAtoms: MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string>;
276
- };
277
- transact(toolkit: SetterToolkit, run: (join: Join<ASide, AType, BSide, BType, Cardinality, Content>) => void): void;
278
- store: Store;
279
- realm: Anarchy;
280
- [Symbol.dispose](): void;
281
- constructor(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>, defaultContent: Content | undefined, store?: Store);
282
- }
283
-
284
- interface Lineage {
285
- parent: typeof this | null;
286
- child: typeof this | null;
287
- }
288
-
289
- type OperationProgress = {
290
- open: false;
291
- } | {
292
- open: true;
293
- done: Set<string>;
294
- prev: Map<string, any>;
295
- time: number;
296
- token: WritableToken<any>;
297
- };
298
-
299
- type TimelineAtomUpdate<ManagedAtom extends TimelineManageable> = Flat<StateUpdate<TokenType<ManagedAtom>> & {
300
- key: string;
301
- type: `atom_update`;
302
- timestamp: number;
303
- family?: FamilyMetadata;
304
- }>;
305
- type TimelineSelectorUpdate<ManagedAtom extends TimelineManageable> = {
306
- key: string;
307
- type: `selector_update`;
308
- timestamp: number;
309
- atomUpdates: Omit<TimelineAtomUpdate<ManagedAtom>, `timestamp`>[];
310
- };
311
- type TimelineTransactionUpdate = Flat<TransactionUpdate<Func> & {
312
- key: string;
313
- type: `transaction_update`;
314
- timestamp: number;
315
- }>;
316
- type TimelineStateCreation<T extends ReadableToken<any>> = Flat<StateCreation<T> & {
317
- timestamp: number;
318
- }>;
319
- type TimelineStateDisposal<T extends ReadableToken<any>> = Flat<StateDisposal<T> & {
320
- timestamp: number;
321
- }>;
322
- type TimelineMoleculeCreation = Flat<MoleculeCreation & {
323
- timestamp: number;
324
- }>;
325
- type TimelineMoleculeDisposal = Flat<MoleculeDisposal & {
326
- timestamp: number;
327
- }>;
328
- type Timeline<ManagedAtom extends TimelineManageable> = {
329
- type: `timeline`;
330
- key: string;
331
- at: number;
332
- shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<ManagedAtom>) => boolean;
333
- timeTraveling: `into_future` | `into_past` | null;
334
- history: TimelineUpdate<ManagedAtom>[];
335
- selectorTime: number | null;
336
- transactionKey: string | null;
337
- install: (store: Store) => void;
338
- subject: Subject<TimelineUpdate<ManagedAtom> | `redo` | `undo`>;
339
- subscriptions: Map<string, () => void>;
340
- };
341
-
342
- declare class Store implements Lineage {
343
- parent: Store | null;
344
- child: Store | null;
345
- valueMap: Map<string, any>;
346
- defaults: Map<string, any>;
347
- atoms: Map<string, Atom<any>>;
348
- selectors: Map<string, WritableSelector<any>>;
349
- readonlySelectors: Map<string, ReadonlySelector<any>>;
350
- atomsThatAreDefault: Set<string>;
351
- selectorAtoms: Junction<"selectorKey", string, "atomKey", string, null>;
352
- selectorGraph: Junction<"upstreamSelectorKey", string, "downstreamSelectorKey", string, {
353
- source: string;
354
- }>;
355
- trackers: Map<string, Tracker<Transceiver<any>>>;
356
- families: Map<string, MutableAtomFamily<any, any, any> | ReadonlySelectorFamily<any, any> | RegularAtomFamily<any, any> | WritableSelectorFamily<any, any>>;
357
- joins: Map<string, Join<any, any, any, any, any, any, `T$--content==${any}::${string}++${any}::${string}`>>;
358
- transactions: Map<string, Transaction<Func>>;
359
- transactionMeta: TransactionEpoch | TransactionProgress<Func>;
360
- timelines: Map<string, Timeline<any>>;
361
- timelineTopics: Junction<"timelineKey", string, "topicKey", string, {
362
- topicType: `atom_family` | `atom` | `molecule_family` | `molecule`;
363
- }>;
364
- disposalTraces: CircularBuffer<{
365
- key: string;
366
- trace: string;
367
- }>;
368
- molecules: Map<string, Molecule<Canonical>>;
369
- moleculeJoins: Junction<"moleculeKey", stringified<Canonical>, "joinKey", string, null>;
370
- moleculeGraph: Junction<"upstreamMoleculeKey", stringified<Canonical> | "root", "downstreamMoleculeKey", stringified<Canonical>, {
371
- source: stringified<Canonical>;
372
- }>;
373
- moleculeData: Junction<"moleculeKey", stringified<Canonical>, "stateFamilyKey", string, null>;
374
- miscResources: Map<string, Disposable>;
375
- on: {
376
- atomCreation: Subject<AtomToken<unknown>>;
377
- atomDisposal: Subject<AtomToken<unknown>>;
378
- selectorCreation: Subject<ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>>;
379
- selectorDisposal: Subject<ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>>;
380
- timelineCreation: Subject<TimelineToken<unknown>>;
381
- transactionCreation: Subject<TransactionToken<Func>>;
382
- transactionApplying: StatefulSubject<TransactionProgress<Func> | null>;
383
- operationClose: Subject<OperationProgress>;
384
- moleculeCreation: Subject<MoleculeCreation>;
385
- moleculeDisposal: Subject<MoleculeDisposal>;
386
- };
387
- operation: OperationProgress;
388
- config: {
389
- name: string;
390
- lifespan: `ephemeral` | `immortal`;
391
- };
392
- loggers: AtomIOLogger[];
393
- logger: Logger;
394
- constructor(config: Store[`config`], store?: Store | null);
395
- }
396
-
397
- interface Transceiver<S extends Json.Serializable> {
398
- do: (update: S) => number | `OUT_OF_RANGE` | null;
399
- undo: (update: S) => void;
400
- subscribe: (key: string, fn: (update: S) => void) => () => void;
401
- cacheUpdateNumber: number;
402
- getUpdateNumber: (update: S) => number;
403
- }
404
- type TransceiverMode = `playback` | `record` | `transaction`;
405
-
406
- /**
407
- * @internal Give the tracker a transceiver state and a store, and it will
408
- * subscribe to the transceiver's inner value. When the inner value changes,
409
- * the tracker will update its own state to reflect the change.
410
- */
411
- declare class Tracker<Mutable extends Transceiver<any>> {
412
- private Update;
413
- private initializeState;
414
- private unsubscribeFromInnerValue;
415
- private unsubscribeFromState;
416
- private observeCore;
417
- private updateCore;
418
- mutableState: MutableAtomToken<Mutable, Json.Serializable>;
419
- latestUpdateState: RegularAtomToken<typeof this.Update | null>;
420
- [Symbol.dispose]: () => void;
421
- constructor(mutableState: MutableAtomToken<Mutable, Json.Serializable>, store: Store);
422
- }
423
-
424
- type EnvironmentData = {
425
- store: Store;
426
- };
427
-
428
- type AtomIOState = {
429
- key: string;
430
- family?: FamilyMetadata;
431
- install: (store: Store) => void;
432
- subject: Subject<{
433
- newValue: any;
434
- oldValue: any;
435
- }>;
436
- };
437
- type RegularAtom<T> = AtomIOState & {
438
- type: `atom`;
439
- default: T | (() => T);
440
- cleanup?: () => void;
441
- };
442
- type MutableAtom<T extends Transceiver<any>, J extends Json.Serializable> = AtomIOState & JsonInterface<T, J> & {
443
- type: `mutable_atom`;
444
- default: T | (() => T);
445
- cleanup?: () => void;
446
- };
447
- type Atom<T> = RegularAtom<T> | (T extends Transceiver<any> ? MutableAtom<T, any> : never);
448
- type WritableSelector<T> = AtomIOState & {
449
- type: `selector`;
450
- get: () => T;
451
- set: (newValue: T | ((oldValue: T) => T)) => void;
452
- };
453
- type ReadonlySelector<T> = AtomIOState & {
454
- type: `readonly_selector`;
455
- get: () => T;
456
- };
457
- type RegularAtomFamily<T, K extends Canonical> = RegularAtomFamilyToken<T, K> & {
458
- (key: K): RegularAtomToken<T>;
459
- subject: Subject<StateCreation<AtomToken<T>> | StateDisposal<AtomToken<T>>>;
460
- install: (store: Store) => void;
461
- internalRoles: string[] | undefined;
462
- };
463
- type MutableAtomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical> = JsonInterface<T, J> & MutableAtomFamilyToken<T, J, K> & {
464
- (key: K): MutableAtomToken<T, J>;
465
- subject: Subject<StateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>>;
466
- install: (store: Store) => void;
467
- internalRoles: string[] | undefined;
468
- };
469
- type WritableSelectorFamily<T, K extends Canonical> = WritableSelectorFamilyToken<T, K> & ((key: K) => WritableSelectorToken<T>) & {
470
- default: (key: K) => T;
471
- subject: Subject<StateCreation<WritableSelectorToken<T>> | StateDisposal<WritableSelectorToken<T>>>;
472
- install: (store: Store) => void;
473
- internalRoles: string[] | undefined;
474
- };
475
- type ReadonlySelectorFamily<T, K extends Canonical> = ReadonlySelectorFamilyToken<T, K> & ((key: K) => ReadonlySelectorToken<T>) & {
476
- default: (key: K) => T;
477
- subject: Subject<StateCreation<ReadonlySelectorToken<T>> | StateDisposal<ReadonlySelectorToken<T>>>;
478
- install: (store: Store) => void;
479
- internalRoles: string[] | undefined;
480
- };
481
-
482
- /**
483
- * @public
484
- * Create a mutable atom, a global reactive variable in the implicit store
485
- *
486
- * The value of a mutable atom must be some kind of {@link Transceiver}.
487
- *
488
- * @param options - {@link MutableAtomOptions}.
489
- * @returns
490
- * A reference to the atom created: a {@link MutableAtomToken}
491
- * @overload Mutable
492
- */
493
- declare function atom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>;
494
- /**
495
- * @public
496
- * Create a regular atom, a global reactive variable in the implicit store
497
- * @param options - {@link RegularAtomOptions}.
498
- * @returns
499
- * A reference to the atom created: a {@link RegularAtomToken}
500
- * @overload Regular
501
- */
502
- declare function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>;
503
- /** @public */
504
- type Effectors<T> = {
505
- /**
506
- * Set the value of the atom
507
- * @param next - The new value of the atom, or a setter function
508
- */
509
- setSelf: <New extends T>(next: New | Setter<T, New>) => void;
510
- /** Subscribe to changes to the atom */
511
- onSet: (callback: (options: {
512
- newValue: T;
513
- oldValue: T;
514
- }) => void) => void;
515
- };
516
- /**
517
- * @public
518
- * A function that runs side effects when the atom is set
519
- * @param tools - {@link Effectors} that can be used to run side effects
520
- * @returns
521
- * Optionally, a cleanup function that will be called when the atom is disposed
522
- */
523
- type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void;
524
- /** @public */
525
- type RegularAtomOptions<T> = {
526
- /** The unique identifier of the atom */
527
- key: string;
528
- /** The starting value of the atom */
529
- default: T | (() => T);
530
- /** Hooks used to run side effects when the atom is set */
531
- effects?: AtomEffect<T>[];
532
- };
533
- type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = JsonInterface<T, J> & Omit<RegularAtomOptions<T>, `default`> & {
534
- default: () => T;
535
- mutable: true;
536
- };
537
- /** @public */
538
- type RegularAtomFamilyOptions<T, K extends Canonical> = {
539
- /** The unique identifier of the atom family */
540
- key: string;
541
- /** The starting value of the atom family */
542
- default: T | ((key: K) => T);
543
- /** Hooks used to run side effects when an atom in the family is set */
544
- effects?: (key: K) => AtomEffect<T>[];
545
- };
546
- type RegularAtomFamilyToken<T, K extends Canonical> = {
547
- key: string;
548
- type: `atom_family`;
549
- __T?: T;
550
- __K?: K;
551
- };
552
- type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical> = JsonInterface<T, J> & {
553
- key: string;
554
- default: (key: K) => T;
555
- effects?: (key: K) => AtomEffect<T>[];
556
- mutable: true;
557
- };
558
- type MutableAtomFamilyToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical> = {
559
- key: string;
560
- type: `mutable_atom_family`;
561
- __T?: T;
562
- __J?: J;
563
- __K?: K;
564
- };
565
- type AtomFamilyToken<T, K extends Canonical = Canonical> = MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomFamilyToken<T, K>;
566
- declare function atomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamilyToken<T, J, K>;
567
- declare function atomFamily<T, K extends Canonical>(options: RegularAtomFamilyOptions<T, K>): RegularAtomFamilyToken<T, K>;
568
-
569
- type TransactionToken<F extends Func> = {
570
- key: string;
571
- type: `transaction`;
572
- __F?: F;
573
- };
574
- type StateCreation<Token extends ReadableToken<any>> = {
575
- type: `state_creation`;
576
- token: Token;
577
- };
578
- type AtomDisposal<Token extends ReadableToken<any>> = {
579
- type: `state_disposal`;
580
- subType: `atom`;
581
- token: Token;
582
- value: TokenType<Token>;
583
- };
584
- type SelectorDisposal<Token extends ReadableToken<any>> = {
585
- type: `state_disposal`;
586
- subType: `selector`;
587
- token: Token;
588
- };
589
- type StateDisposal<Token extends ReadableToken<any>> = AtomDisposal<Token> | SelectorDisposal<Token>;
590
- type MoleculeCreation = {
591
- type: `molecule_creation`;
592
- key: Canonical;
593
- provenance: Canonical;
594
- };
595
- type MoleculeDisposal = {
596
- type: `molecule_disposal`;
597
- key: Canonical;
598
- provenance: stringified<Canonical>[];
599
- values: [key: string, value: any][];
600
- };
601
- type MoleculeTransfer = {
602
- type: `molecule_transfer`;
603
- key: Canonical;
604
- from: Canonical[];
605
- to: Canonical[];
606
- };
607
- type TransactionUpdateContent = KeyedStateUpdate<unknown> | MoleculeCreation | MoleculeDisposal | MoleculeTransfer | StateCreation<ReadableToken<unknown>> | StateDisposal<ReadableToken<unknown>> | TransactionUpdate<Func>;
608
- type TransactionUpdate<F extends Func> = {
609
- type: `transaction_update`;
610
- key: string;
611
- id: string;
612
- epoch: number;
613
- updates: TransactionUpdateContent[];
614
- params: Parameters<F>;
615
- output: ReturnType<F>;
616
- };
617
- type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json`>;
618
- type SetterToolkit = Readonly<{
619
- get: typeof getState;
620
- set: typeof setState;
621
- find: typeof findState;
622
- json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritableSelectorToken<J>;
623
- }>;
624
- type ActorToolkit = Readonly<{
625
- get: typeof getState;
626
- set: typeof setState;
627
- find: typeof findState;
628
- json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritableSelectorToken<J>;
629
- dispose: typeof disposeState;
630
- run: typeof runTransaction;
631
- env: () => EnvironmentData;
632
- }>;
633
- type Read<F extends Func> = (toolkit: GetterToolkit, ...parameters: Parameters<F>) => ReturnType<F>;
634
- type Write<F extends Func> = (toolkit: SetterToolkit, ...parameters: Parameters<F>) => ReturnType<F>;
635
- type Transact<F extends Func> = (toolkit: ActorToolkit, ...parameters: Parameters<F>) => ReturnType<F>;
636
- type TransactionOptions<F extends Func> = {
637
- key: string;
638
- do: Transact<F>;
639
- };
640
- declare function transaction<F extends Func>(options: TransactionOptions<F>): TransactionToken<F>;
641
- declare function runTransaction<F extends Func>(token: TransactionToken<F>, id?: string): (...parameters: Parameters<F>) => ReturnType<F>;
642
-
643
- type WritableSelectorOptions<T> = {
644
- key: string;
645
- get: Read<() => T>;
646
- set: Write<(newValue: T) => void>;
647
- };
648
- type ReadonlySelectorOptions<T> = {
649
- key: string;
650
- get: Read<() => T>;
651
- };
652
- /**
653
- * @public
654
- * Declare a selector. The value of a selector should depend
655
- * on the value of atoms or other selectors in the store.
656
- *
657
- * A writable selector can be "set" to a new value.
658
- * It is advised to set its dependencies to values
659
- * that would produce the new value of the selector.
660
- * @param options - {@link WritableSelectorOptions}.
661
- * @returns
662
- * The token for your selector.
663
- * @overload Writable
664
- */
665
- declare function selector<T>(options: WritableSelectorOptions<T>): WritableSelectorToken<T>;
666
- /**
667
- * @public
668
- * Declare a selector. The value of a selector should depend
669
- * on the value of atoms or other selectors in the store.
670
- * @param options - {@link ReadonlySelectorOptions}.
671
- */
672
- declare function selector<T>(options: ReadonlySelectorOptions<T>): ReadonlySelectorToken<T>;
673
- type WritableSelectorFamilyOptions<T, K extends Canonical> = {
674
- key: string;
675
- get: (key: K) => Read<() => T>;
676
- set: (key: K) => Write<(newValue: T) => void>;
677
- };
678
- type ReadonlySelectorFamilyOptions<T, K extends Canonical> = {
679
- key: string;
680
- get: (key: K) => Read<() => T>;
681
- };
682
- type WritableSelectorFamilyToken<T, K extends Canonical> = {
683
- key: string;
684
- type: `selector_family`;
685
- __T?: T;
686
- __K?: K;
687
- };
688
- type ReadonlySelectorFamilyToken<T, K extends Canonical> = {
689
- key: string;
690
- type: `readonly_selector_family`;
691
- __T?: T;
692
- __K?: K;
693
- };
694
- type SelectorFamilyToken<T, K extends Canonical> = ReadonlySelectorFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
695
- declare function selectorFamily<T, K extends Canonical>(options: WritableSelectorFamilyOptions<T, K>): WritableSelectorFamilyToken<T, K>;
696
- declare function selectorFamily<T, K extends Canonical>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamilyToken<T, K>;
697
-
698
- type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>;
699
- type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<any, any> ? AtomToken<any> : M extends AtomToken<any> ? M : never;
700
- type TimelineToken<M> = {
701
- key: string;
702
- type: `timeline`;
703
- __M?: M;
704
- };
705
- type TimelineOptions<ManagedAtom extends TimelineManageable> = {
706
- key: string;
707
- scope: ManagedAtom[];
708
- shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<TimelineManageable>) => boolean;
709
- };
710
- type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineMoleculeCreation | TimelineMoleculeDisposal | TimelineSelectorUpdate<ManagedAtom> | TimelineStateCreation<AtomOnly<ManagedAtom>> | TimelineStateDisposal<AtomOnly<ManagedAtom>> | TimelineTransactionUpdate;
711
- declare const timeline: <ManagedAtom extends TimelineManageable>(options: TimelineOptions<ManagedAtom>) => TimelineToken<ManagedAtom>;
712
- declare const redo: (tl: TimelineToken<any>) => void;
713
- declare const undo: (tl: TimelineToken<any>) => void;
714
-
715
- /**
716
- * @public
717
- * Disposes of a state in the implicit store
718
- * @param token - The token of the state to dispose
719
- * @overload Default
720
- */
721
- declare function disposeState(token: ReadableToken<any>): void;
722
- /**
723
- * @public
724
- * Disposes of a state family in the implicit store
725
- * @param token - The token of the state family to dispose
726
- * @param key - The unique key of the state to dispose
727
- */
728
- declare function disposeState<K extends Canonical>(token: ReadableFamilyToken<any, K>, key: K): void;
729
-
730
- /**
731
- * @public
732
- * Finds a {@link MutableAtomToken} in the store
733
- * @param token - A {@link MutableAtomFamilyToken}
734
- * @param key - The key of the state
735
- * @returns
736
- * The current value of the state
737
- * @overload Mutable Atom
738
- */
739
- declare function findState<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical, Key extends K>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J, K>;
740
- /**
741
- * @public
742
- * Finds a state in the store
743
- * @param token - The token of the state family
744
- * @param key - The key of the state
745
- * @returns
746
- * The current value of the state
747
- * @overload Regular Atom
748
- */
749
- declare function findState<T, K extends Canonical, Key extends K>(token: RegularAtomFamilyToken<T, K>, key: Key): RegularAtomToken<T, K>;
750
- /**
751
- * @public
752
- * Finds a state in the store
753
- * @param token - The token of the state family
754
- * @param key - The key of the state
755
- * @returns
756
- * The current value of the state
757
- * @overload Writable Selector
758
- */
759
- declare function findState<T, K extends Canonical, Key extends K>(token: WritableSelectorFamilyToken<T, K>, key: Key): WritableSelectorToken<T, K>;
760
- /**
761
- * @public
762
- * Finds a state in the store
763
- * @param token - The token of the state family
764
- * @param key - The key of the state
765
- * @returns
766
- * The current value of the state
767
- * @overload Readonly Selector
768
- */
769
- declare function findState<T, K extends Canonical, Key extends K>(token: ReadonlySelectorFamilyToken<T, K>, key: Key): ReadonlySelectorToken<T, K>;
770
- /**
771
- * @public
772
- * Finds a state in the store
773
- * @param token - The token of the state family
774
- * @param key - The key of the state
775
- * @returns
776
- * The current value of the state
777
- * @overload Writable State
778
- */
779
- declare function findState<T, K extends Canonical, Key extends K>(token: WritableFamilyToken<T, K>, key: Key): WritableToken<T, K>;
780
- /**
781
- * @public
782
- * Finds a {@link ReadableToken} in the store
783
- * @param token - A {@link ReadableFamilyToken}
784
- * @param key - The key of the state
785
- * @returns
786
- * The current value of the state
787
- * @overload Unknown
788
- * @default
789
- */
790
- declare function findState<T, K extends Canonical, Key extends K>(token: ReadableFamilyToken<T, K>, key: Key): ReadableToken<T, K>;
791
-
792
- /**
793
- * @public
794
- * Get the current value of a state
795
- * @param token - The token of the state to get
796
- * @return The current value of the state
797
- * @overload Default
798
- * @default
799
- */
800
- declare function getState<T>(token: ReadableToken<T>): T;
801
- /**
802
- * @public
803
- * Get the current value of a state family
804
- * @param token - The token of a state family
805
- * @param key - The unique key of the state to get
806
- * @return The current value of the state
807
- * @overload Streamlined
808
- */
809
- declare function getState<T, K extends Canonical, Key extends K>(token: ReadableFamilyToken<T, K>, key: Key): T;
810
-
811
- interface JoinOptions<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> extends JunctionSchemaBase<ASide, BSide>, Partial<JunctionEntriesBase<AType, BType, Content>> {
812
- readonly key: string;
813
- readonly cardinality: Cardinality;
814
- readonly isAType: Refinement<string, AType>;
815
- readonly isBType: Refinement<string, BType>;
816
- }
817
-
818
- declare const LoggerIconDictionary: {
819
- readonly "\u231B": "Timeline event fully captured";
820
- readonly "\u23E9": "Timeline redo";
821
- readonly "\u23EA": "Timeline undo";
822
- readonly "\u23ED\uFE0F": "Transaction redo";
823
- readonly "\u23EE\uFE0F": "Transaction undo";
824
- readonly "\u23F3": "Timeline event partially captured";
825
- readonly "\u23F9\uFE0F": "Time-travel complete";
826
- readonly "\u2705": "Realtime transaction success";
827
- readonly "\u2728": "Computation complete";
828
- readonly "\u274C": "Conflict prevents attempted action";
829
- readonly "\u2B55": "Operation start";
830
- readonly "\uD83D\uDD34": "Operation complete";
831
- readonly "\u2757": "Operation blocked";
832
- readonly "\uD83D\uDFE2": "Operation unblocked";
833
- readonly "\uD83D\uDC1E": "Possible bug in AtomIO";
834
- readonly "\uD83D\uDC40": "Subscription added";
835
- readonly "\uD83D\uDC4B": "Greeting";
836
- readonly "\uD83D\uDC4D": "Realtime acknowledgment";
837
- readonly "\uD83D\uDC6A": "Family member added";
838
- readonly "\uD83D\uDC81": "Notice";
839
- readonly "\uD83D\uDCA5": "Caught";
840
- readonly "\uD83D\uDCC1": "Stow update";
841
- readonly "\uD83D\uDCC3": "Copy mutable";
842
- readonly "\uD83D\uDCD6": "Read state";
843
- readonly "\uD83D\uDCDD": "Write state";
844
- readonly "\uD83D\uDCE2": "Notify subscribers";
845
- readonly "\uD83D\uDD04": "Realtime transaction synchronized";
846
- readonly "\uD83D\uDD0C": "Register dependency";
847
- readonly "\uD83D\uDD0D": "Discover root";
848
- readonly "\uD83D\uDD25": "Delete state";
849
- readonly "\uD83D\uDD27": "Create mutable atom";
850
- readonly "\uD83D\uDD28": "Create immutable atom";
851
- readonly "\uD83D\uDDD1": "Evict cached value";
852
- readonly "\uD83D\uDE48": "Subscription canceled";
853
- readonly "\uD83D\uDE80": "Performance measure";
854
- readonly "\uD83D\uDEC4": "Apply transaction";
855
- readonly "\uD83D\uDEE0\uFE0F": "Install atom into store";
856
- readonly "\uD83D\uDEEB": "Begin transaction";
857
- readonly "\uD83D\uDEEC": "Complete transaction";
858
- readonly "\uD83E\uDDEE": "Computing selector";
859
- readonly "\uD83E\uDDF9": "Prepare to evict";
860
- readonly "\uD83E\uDE82": "Abort transaction";
861
- readonly "\uD83E\uDD1E": "Realtime optimistic update enqueued";
862
- readonly "\uD83D\uDC48": "Realtime confirmed update enqueued";
863
- readonly "\uD83E\uDDD1\u200D\u2696\uFE0F": "Realtime update beginning reconciliation";
864
- readonly "\uD83D\uDECE\uFE0F": "Realtime transaction received";
865
- readonly "\uD83D\uDD2D": "Determining realtime perspective";
866
- readonly "\uD83D\uDD8C": "Redacting realtime update";
867
- readonly "\uD83D\uDC41": "Determining perspective";
868
- };
869
- type LoggerIcon = keyof typeof LoggerIconDictionary;
870
- type TokenDenomination = `atom_family` | `atom` | `continuity` | `molecule_family` | `molecule` | `mutable_atom_family` | `mutable_atom` | `readonly_selector_family` | `readonly_selector` | `selector_family` | `selector` | `state` | `timeline` | `transaction` | `unknown`;
871
- declare const LOG_LEVELS: readonly ["info", "warn", "error"];
872
- type LogLevel = (typeof LOG_LEVELS)[number];
873
- type LogFn = (icon: LoggerIcon, denomination: TokenDenomination, tokenKey: string, message: string, ...rest: unknown[]) => void;
874
- type LogFilter = (...params: Parameters<LogFn>) => boolean;
875
- type Logger = Record<LogLevel, LogFn>;
876
- declare class AtomIOLogger implements Logger {
877
- logLevel: `error` | `info` | `warn` | null;
878
- private readonly filter?;
879
- private readonly logger;
880
- constructor(logLevel: `error` | `info` | `warn` | null, filter?: LogFilter | undefined, logger?: Logger);
881
- error: LogFn;
882
- info: LogFn;
883
- warn: LogFn;
884
- }
885
-
886
- declare const $claim: unique symbol;
887
- type Claim<K extends Canonical> = K & {
888
- [$claim]?: true;
889
- };
890
- declare class Realm<H extends Hierarchy> {
891
- store: Store;
892
- constructor(store?: Store);
893
- allocate<V extends Vassal<H>, A extends Above<V, H>>(provenance: A, key: V, attachmentStyle?: `all` | `any`): Claim<V>;
894
- fuse<C extends CompoundFrom<H>, T extends C extends CompoundTypedKey<infer t, any, any> ? t : never, A extends C extends CompoundTypedKey<any, infer v, any> ? v : never, B extends C extends CompoundTypedKey<any, any, infer m> ? m : never>(type: T, reagentA: SingularTypedKey<A>, reagentB: SingularTypedKey<B>): Claim<CompoundTypedKey<T, A, B>>;
895
- deallocate<V extends Vassal<H>>(claim: Claim<V>): void;
896
- claim<V extends Exclude<Vassal<H>, CompoundTypedKey>, A extends Above<V, H>>(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V>;
897
- }
898
- declare class Anarchy {
899
- store: Store;
900
- realm: Realm<any>;
901
- constructor(store?: Store);
902
- allocate(provenance: Canonical, key: Canonical, attachmentStyle?: `all` | `any`): void;
903
- deallocate(key: Canonical): void;
904
- claim(newProvenance: Canonical, key: Canonical, exclusive?: `exclusive`): void;
905
- }
906
- declare const T$ = "T$";
907
- type T$ = typeof T$;
908
- type TypeTag<T extends string> = `${T$}--${T}`;
909
- type SingularTypedKey<T extends string = string> = `${T}::${string}`;
910
- type CompoundTypedKey<A extends string = string, B extends string = string, C extends string = string> = `${TypeTag<A>}==${SingularTypedKey<B>}++${SingularTypedKey<C>}`;
911
- type TypedKey<A extends string = string, B extends string = string, C extends string = string> = CompoundTypedKey<A, B, C> | SingularTypedKey<A>;
912
- type Scope = SingularTypedKey[];
913
- type MutualFealty = {
914
- above: Scope;
915
- below: CompoundTypedKey;
916
- };
917
- type ExclusiveFealty = {
918
- above: TypedKey | `root`;
919
- below: Scope;
920
- };
921
- type Fealty = ExclusiveFealty | MutualFealty;
922
- type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>;
923
- type Vassal<H extends Hierarchy> = {
924
- [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : H[K] extends {
925
- below: Array<infer V>;
926
- } ? V extends TypedKey ? V : never : never;
927
- }[keyof H];
928
- type Above<TK extends TypedKey, H extends Hierarchy> = {
929
- [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`below`] ? H[K][`above`] : never : H[K] extends {
930
- below: Array<infer V>;
931
- } ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`above`] : never : never : never;
932
- }[keyof H];
933
- type CompoundFrom<H extends Hierarchy> = {
934
- [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : never;
935
- }[keyof H];
936
-
937
- /**
938
- * @public
939
- * A function that sets the value of a state.
940
- * @param oldValue - The current value of the state.
941
- * @returns
942
- * The new value of the state.
943
- */
944
- type Setter<T, New extends T> = (oldValue: T) => New;
945
- /**
946
- * @public
947
- * Set the value of a state into the implicit store.
948
- * @param token - An atom or writable selector token.
949
- * @param value - The new value of the state.
950
- * @overload Default
951
- * @default
952
- */
953
- declare function setState<T, New extends T>(token: WritableToken<T>, value: New | Setter<T, New>): void;
954
- /**
955
- * @public
956
- * Set the value of a state into the implicit store.
957
- * @param token - An atom family or writable selector family token.
958
- * @param key - The unique key of the state to set.
959
- * @param value - The new value of the state.
960
- * @overload Streamlined
961
- */
962
- declare function setState<T, K extends Canonical, New extends T, Key extends K>(token: WritableFamilyToken<T, K>, key: Key, value: New | Setter<T, New>): void;
963
-
964
- declare class Silo {
965
- store: Store;
966
- atom: typeof atom;
967
- atomFamily: typeof atomFamily;
968
- selector: typeof selector;
969
- selectorFamily: typeof selectorFamily;
970
- transaction: typeof transaction;
971
- timeline: typeof timeline;
972
- findState: typeof findState;
973
- getState: typeof getState;
974
- setState: typeof setState;
975
- disposeState: typeof disposeState;
976
- subscribe: typeof subscribe;
977
- undo: typeof undo;
978
- redo: typeof redo;
979
- runTransaction: typeof runTransaction;
980
- install: (tokens: AtomIOToken[], store?: Store) => void;
981
- constructor(config: Store[`config`], fromStore?: Store | null);
982
- }
983
-
984
- type StateUpdate<T> = {
985
- newValue: T;
986
- oldValue: T;
987
- };
988
- type KeyedStateUpdate<T> = Flat<StateUpdate<T> & {
989
- key: string;
990
- type: `atom_update` | `selector_update`;
991
- family?: FamilyMetadata;
992
- }>;
993
- type UpdateHandler<T> = (update: StateUpdate<T>) => void;
994
- type TransactionUpdateHandler<F extends Func> = (data: TransactionUpdate<F>) => void;
995
- declare function subscribe<T>(token: ReadableToken<T>, handleUpdate: UpdateHandler<T>, key?: string): () => void;
996
- declare function subscribe<F extends Func>(token: TransactionToken<F>, handleUpdate: TransactionUpdateHandler<F>, key?: string): () => void;
997
- declare function subscribe<M extends TimelineManageable>(token: TimelineToken<M>, handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void, key?: string): () => void;
998
-
999
- type TokenType<Comparison extends ReadableFamilyToken<any, any> | ReadableToken<any>> = Comparison extends ReadableToken<infer RepresentedValue> ? RepresentedValue : Comparison extends ReadableFamilyToken<infer RepresentedValue, any> ? RepresentedValue : never;
1000
-
1001
- /**
1002
- * @public
1003
- * A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
1004
- *
1005
- * While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank.
1006
- *
1007
- * Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}.
1008
- *
1009
- * Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}.
1010
- *
1011
- * Tokens are fully serializable, so they can be passed between processes.
1012
- */
1013
- type AtomIOToken = ReadableFamilyToken<any, any> | ReadableToken<any> | TimelineToken<any> | TransactionToken<any>;
1014
- /** @public */
1015
- type RegularAtomToken<T, K extends Canonical = any> = {
1016
- /** The unique identifier of the atom. */
1017
- key: string;
1018
- /** Discriminator. */
1019
- type: `atom`;
1020
- /** Present if the atom belongs to a family. */
1021
- family?: FamilyMetadata<K>;
1022
- /** Never present. This is a marker that preserves the type of the atom's value. */
1023
- __T?: T;
1024
- };
1025
- /** @public */
1026
- type MutableAtomToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical = any> = {
1027
- /** The unique identifier of the atom. */
1028
- key: string;
1029
- /** Discriminator. */
1030
- type: `mutable_atom`;
1031
- /** Present if the atom belongs to a family. */
1032
- family?: FamilyMetadata<K>;
1033
- /** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
1034
- __J?: J;
1035
- /** Never present. This is a marker that preserves the type of the atom's transceiver value. */
1036
- __U?: T extends Transceiver<infer Update> ? Update : never;
1037
- };
1038
- /** @public */
1039
- type AtomToken<T, K extends Canonical = any> = MutableAtomToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomToken<T, K>;
1040
- /** @public */
1041
- type WritableSelectorToken<T, K extends Canonical = any> = {
1042
- /** The unique identifier of the selector. */
1043
- key: string;
1044
- /** Discriminator. */
1045
- type: `selector`;
1046
- /** Present if the selector belongs to a family. */
1047
- family?: FamilyMetadata<K>;
1048
- /** Never present. This is a marker that preserves the type of the selector's value. */
1049
- __T?: T;
1050
- };
1051
- /** @public */
1052
- type ReadonlySelectorToken<T, K extends Canonical = any> = {
1053
- /** The unique identifier of the selector. */
1054
- key: string;
1055
- /** Discriminator. */
1056
- type: `readonly_selector`;
1057
- /** Present if the selector belongs to a family. */
1058
- family?: FamilyMetadata<K>;
1059
- /** Never present. This is a marker that preserves the type of the selector's value. */
1060
- __T?: T;
1061
- };
1062
- /** @public */
1063
- type SelectorToken<T, K extends Canonical = any> = ReadonlySelectorToken<T, K> | WritableSelectorToken<T, K>;
1064
- /**
1065
- * @public
1066
- * These states can be set.
1067
- */
1068
- type WritableToken<T, K extends Canonical = any> = AtomToken<T, K> | WritableSelectorToken<T, K>;
1069
- /**
1070
- * @public
1071
- * These states cannot be set.
1072
- */
1073
- type ReadableToken<T, K extends Canonical = any> = AtomToken<T, K> | SelectorToken<T, K>;
1074
- /**
1075
- * @public
1076
- * States belonging to this family can be set.
1077
- */
1078
- type WritableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
1079
- /**
1080
- * @public
1081
- * States belonging to this family cannot be set.
1082
- */
1083
- type ReadableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | SelectorFamilyToken<T, K>;
1084
- /**
1085
- * @public
1086
- * Identifies a state's connection to its family.
1087
- */
1088
- type FamilyMetadata<K extends Canonical = any> = {
1089
- /** The family's unique key. */
1090
- key: string;
1091
- /** The family member's unique identifier, in the form of a string. */
1092
- subKey: stringified<K>;
1093
- };
1094
-
1095
7
  type TestSetupOptions = {
1096
8
  port: number;
1097
9
  immortal?: {
@@ -1099,7 +11,7 @@ type TestSetupOptions = {
1099
11
  };
1100
12
  server: (tools: {
1101
13
  socket: SocketIO.Socket;
1102
- silo: Silo;
14
+ silo: AtomIO.Silo;
1103
15
  enableLogging: () => void;
1104
16
  }) => void;
1105
17
  };
@@ -1113,7 +25,7 @@ type TestSetupOptions__MultiClient<ClientNames extends string> = TestSetupOption
1113
25
  };
1114
26
  type RealtimeTestTools = {
1115
27
  name: string;
1116
- silo: Silo;
28
+ silo: AtomIO.Silo;
1117
29
  };
1118
30
  type RealtimeTestClient = RealtimeTestTools & {
1119
31
  renderResult: RenderResult;