atom.io 0.31.0 → 0.32.0

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 (171) hide show
  1. package/data/dist/index.d.ts +867 -101
  2. package/data/dist/index.js +10 -558
  3. package/data/src/index.ts +0 -2
  4. package/data/src/struct-family.ts +1 -1
  5. package/data/src/struct.ts +1 -2
  6. package/dist/chunk-354XQWHH.js +153 -0
  7. package/dist/chunk-4LWKCEW3.js +14 -0
  8. package/dist/chunk-5F2V7S3B.js +83 -0
  9. package/dist/chunk-ECOMOMUN.js +631 -0
  10. package/dist/{chunk-42UH5F5Q.js → chunk-GY2XQYZY.js} +2051 -755
  11. package/dist/chunk-NF7FJKJD.js +107 -0
  12. package/dist/chunk-R3ZUK5EH.js +1024 -0
  13. package/dist/chunk-Z2UJW4NQ.js +523 -0
  14. package/dist/index.d.ts +855 -127
  15. package/dist/index.js +1 -143
  16. package/eslint-plugin/dist/index.d.ts +1 -30
  17. package/eslint-plugin/dist/index.js +0 -146
  18. package/eslint-plugin/src/index.ts +0 -1
  19. package/eslint-plugin/src/rules/index.ts +0 -1
  20. package/internal/dist/index.d.ts +794 -70
  21. package/internal/dist/index.js +1 -2
  22. package/internal/src/atom/create-regular-atom.ts +3 -3
  23. package/internal/src/atom/dispose-atom.ts +4 -13
  24. package/internal/src/atom/is-default.ts +3 -3
  25. package/internal/src/caching.ts +5 -5
  26. package/internal/src/capitalize.ts +3 -0
  27. package/internal/src/families/create-readonly-selector-family.ts +5 -6
  28. package/internal/src/families/create-writable-selector-family.ts +1 -4
  29. package/internal/src/families/dispose-from-store.ts +3 -13
  30. package/internal/src/families/find-in-store.ts +1 -6
  31. package/internal/src/get-state/get-from-store.ts +2 -2
  32. package/internal/src/get-state/read-or-compute-value.ts +1 -1
  33. package/internal/src/index.ts +19 -9
  34. package/internal/src/ingest-updates/ingest-creation-disposal.ts +2 -3
  35. package/internal/src/install-into-store.ts +48 -0
  36. package/internal/src/join/edit-relations-in-store.ts +32 -0
  37. package/internal/src/join/find-relations-in-store.ts +124 -0
  38. package/internal/src/join/get-internal-relations-from-store.ts +14 -0
  39. package/internal/src/join/get-join.ts +31 -0
  40. package/internal/src/join/index.ts +5 -0
  41. package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
  42. package/internal/src/keys.ts +7 -7
  43. package/internal/src/molecule.ts +299 -0
  44. package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
  45. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  46. package/internal/src/mutable/get-json-token.ts +1 -1
  47. package/internal/src/mutable/tracker-family.ts +19 -17
  48. package/internal/src/mutable/tracker.ts +8 -8
  49. package/internal/src/not-found-error.ts +8 -30
  50. package/internal/src/pretty-print.ts +2 -13
  51. package/internal/src/selector/create-readonly-selector.ts +3 -7
  52. package/internal/src/selector/create-writable-selector.ts +4 -4
  53. package/internal/src/selector/dispose-selector.ts +20 -11
  54. package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
  55. package/internal/src/selector/register-selector.ts +7 -17
  56. package/internal/src/selector/trace-selector-atoms.ts +2 -2
  57. package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
  58. package/internal/src/set-state/emit-update.ts +1 -1
  59. package/internal/src/set-state/evict-downstream.ts +1 -1
  60. package/internal/src/set-state/set-atom-or-selector.ts +1 -1
  61. package/internal/src/set-state/set-atom.ts +10 -10
  62. package/internal/src/set-state/set-into-store.ts +2 -2
  63. package/internal/src/set-state/stow-update.ts +1 -1
  64. package/internal/src/store/deposit.ts +10 -8
  65. package/internal/src/store/store.ts +1 -1
  66. package/internal/src/store/withdraw.ts +34 -53
  67. package/internal/src/subscribe/recall-state.ts +1 -1
  68. package/internal/src/subscribe/subscribe-in-store.ts +3 -3
  69. package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
  70. package/internal/src/subscribe/subscribe-to-state.ts +5 -5
  71. package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
  72. package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
  73. package/internal/src/timeline/create-timeline.ts +17 -37
  74. package/internal/src/transaction/act-upon-store.ts +2 -2
  75. package/internal/src/transaction/apply-transaction.ts +5 -5
  76. package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
  77. package/internal/src/transaction/build-transaction.ts +5 -8
  78. package/internal/src/transaction/create-transaction.ts +3 -3
  79. package/internal/src/transaction/get-epoch-number.ts +3 -3
  80. package/internal/src/transaction/set-epoch-number.ts +2 -2
  81. package/introspection/dist/index.d.ts +922 -6
  82. package/introspection/dist/index.js +2 -620
  83. package/json/dist/index.d.ts +899 -5
  84. package/json/dist/index.js +1 -81
  85. package/json/src/select-json-family.ts +3 -14
  86. package/package.json +27 -45
  87. package/react/dist/index.d.ts +921 -3
  88. package/react/dist/index.js +2 -82
  89. package/react/src/use-o.ts +1 -1
  90. package/react/src/use-tl.ts +2 -2
  91. package/react-devtools/dist/index.css +16 -14
  92. package/react-devtools/dist/index.d.ts +26 -1
  93. package/react-devtools/dist/index.js +6 -6
  94. package/react-devtools/src/devtools.scss +16 -14
  95. package/realtime/dist/index.d.ts +202 -8
  96. package/realtime/dist/index.js +2 -107
  97. package/realtime/src/realtime-continuity.ts +2 -2
  98. package/realtime/src/shared-room-store.ts +1 -2
  99. package/realtime-client/dist/index.d.ts +960 -22
  100. package/realtime-client/dist/index.js +3 -509
  101. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
  102. package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
  103. package/realtime-client/src/pull-atom-family-member.ts +2 -2
  104. package/realtime-client/src/pull-atom.ts +2 -2
  105. package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
  106. package/realtime-client/src/pull-mutable-atom.ts +2 -2
  107. package/realtime-client/src/pull-selector-family-member.ts +4 -4
  108. package/realtime-client/src/pull-selector.ts +4 -4
  109. package/realtime-client/src/push-state.ts +5 -10
  110. package/realtime-client/src/server-action.ts +4 -4
  111. package/realtime-client/src/sync-continuity.ts +6 -6
  112. package/realtime-react/dist/index.d.ts +166 -12
  113. package/realtime-react/dist/index.js +5 -154
  114. package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
  115. package/realtime-react/src/use-pull-atom.ts +1 -1
  116. package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
  117. package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
  118. package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
  119. package/realtime-react/src/use-pull-selector.ts +1 -1
  120. package/realtime-react/src/use-push.ts +1 -1
  121. package/realtime-react/src/use-server-action.ts +2 -2
  122. package/realtime-react/src/use-sync-continuity.ts +1 -1
  123. package/realtime-server/dist/index.d.ts +971 -28
  124. package/realtime-server/dist/index.js +3 -1001
  125. package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
  126. package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
  127. package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
  128. package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
  129. package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
  130. package/realtime-server/src/realtime-action-receiver.ts +1 -1
  131. package/realtime-server/src/realtime-family-provider.ts +2 -2
  132. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
  133. package/realtime-server/src/realtime-mutable-provider.ts +2 -2
  134. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
  135. package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
  136. package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
  137. package/realtime-server/src/realtime-state-provider.ts +2 -2
  138. package/realtime-testing/dist/index.d.ts +1091 -3
  139. package/realtime-testing/dist/index.js +23 -26
  140. package/realtime-testing/src/setup-realtime-test.tsx +6 -5
  141. package/src/atom.ts +53 -29
  142. package/src/dispose-state.ts +12 -2
  143. package/{ephemeral/src → src}/find-state.ts +35 -25
  144. package/src/get-state.ts +16 -0
  145. package/src/index.ts +77 -3
  146. package/src/join.ts +218 -0
  147. package/src/realm.ts +169 -0
  148. package/src/selector.ts +20 -0
  149. package/src/set-state.ts +16 -8
  150. package/src/silo.ts +13 -7
  151. package/src/timeline.ts +1 -1
  152. package/src/transaction.ts +4 -8
  153. package/transceivers/set-rtx/dist/index.d.ts +37 -2
  154. package/transceivers/set-rtx/dist/index.js +1 -212
  155. package/transceivers/set-rtx/src/set-rtx.ts +4 -1
  156. package/web/dist/index.d.ts +30 -1
  157. package/web/dist/index.js +1 -15
  158. package/data/src/until.ts +0 -15
  159. package/dist/chunk-ICGFFQ3H.js +0 -272
  160. package/ephemeral/dist/index.d.ts +0 -57
  161. package/ephemeral/dist/index.js +0 -9
  162. package/ephemeral/package.json +0 -13
  163. package/ephemeral/src/index.ts +0 -1
  164. package/eslint-plugin/src/rules/lifespan.ts +0 -203
  165. package/immortal/dist/index.d.ts +0 -12
  166. package/immortal/dist/index.js +0 -9
  167. package/immortal/package.json +0 -13
  168. package/immortal/src/index.ts +0 -1
  169. package/immortal/src/seek-state.ts +0 -60
  170. package/src/allocate.ts +0 -443
  171. package/src/molecule.ts +0 -16
@@ -1,19 +1,221 @@
1
- import * as AtomIO from 'atom.io';
2
- import { ReadonlySelectorFamilyToken, SingularTypedKey, Hierarchy, CompoundTypedKey, MutableAtomFamilyToken, SetterToolkit, Anarchy, ReadonlySelectorToken } from 'atom.io';
3
- import { Store, JunctionSchemaBase, JunctionEntriesBase, Refinement, Molecule, Junction } from 'atom.io/internal';
4
- import { Canonical, stringified, Json } from 'atom.io/json';
5
- import { SetRTX, SetRTXJson } from 'atom.io/transceivers/set-rtx';
1
+ type primitive = boolean | number | string | null;
2
+ declare namespace Json {
3
+ namespace Tree {
4
+ type Array<Element = unknown> = ReadonlyArray<Element>;
5
+ type Object<K extends string = string, V = unknown> = Record<K, V>;
6
+ type Fork = Array | Object;
7
+ type Leaf = primitive;
8
+ type Node = Fork | Leaf;
9
+ }
10
+ type Serializable = primitive | Readonly<{
11
+ [key: string]: Serializable;
12
+ }> | ReadonlyArray<Serializable>;
13
+ type Object<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
14
+ type Array<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
15
+ }
16
+ 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 & {
17
+ __json?: J;
18
+ };
19
+ type Canonical = primitive | ReadonlyArray<Canonical>;
20
+ type JsonInterface<T, J extends Json.Serializable = Json.Serializable> = {
21
+ toJson: (t: T) => J;
22
+ fromJson: (json: J) => T;
23
+ };
6
24
 
7
- declare function dict<State, Key extends Canonical>(family: AtomIO.ReadonlySelectorFamilyToken<State, Key> | AtomIO.RegularAtomFamilyToken<State, Key> | AtomIO.WritableSelectorFamilyToken<State, Key>, index: AtomIO.ReadonlySelectorToken<Key[]> | AtomIO.RegularAtomToken<Key[]> | AtomIO.WritableSelectorToken<Key[]>, store?: Store): AtomIO.ReadonlySelectorToken<{
8
- [K in stringified<Key>]: State;
9
- }>;
25
+ declare class CircularBuffer<T> {
26
+ protected _buffer: T[];
27
+ protected _index: number;
28
+ constructor(array: T[]);
29
+ constructor(length: number);
30
+ get buffer(): ReadonlyArray<T | undefined>;
31
+ get index(): number;
32
+ add(item: T): void;
33
+ copy(): CircularBuffer<T>;
34
+ }
10
35
 
11
- 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>> {
12
- readonly key: string;
13
- readonly cardinality: Cardinality;
14
- readonly isAType: Refinement<string, AType>;
15
- readonly isBType: Refinement<string, BType>;
36
+ type Func = (...parameters: any[]) => any;
37
+ type Flat<R extends {
38
+ [K in PropertyKey]: any;
39
+ }> = {
40
+ [K in keyof R]: R[K];
41
+ };
42
+ type Count<N extends number, A extends any[] = []> = [
43
+ ...A,
44
+ any
45
+ ][`length`] extends N ? A[`length`] : A[`length`] | Count<N, [...A, any]>;
46
+ type Each<E extends any[]> = {
47
+ [P in Count<E[`length`]>]: E[P];
48
+ };
49
+ type Refinement<A, B extends A> = (a: A) => a is B;
50
+
51
+ type JunctionEntriesBase<AType extends string, BType extends string, Content extends Json.Object | null> = {
52
+ readonly relations: ([AType, BType[]] | [BType, AType[]])[];
53
+ readonly contents: [string, Content][];
54
+ };
55
+ interface JunctionEntries<AType extends string, BType extends string, Content extends Json.Object | null> extends Json.Object, JunctionEntriesBase<AType, BType, Content> {
56
+ }
57
+ type JunctionSchemaBase<ASide extends string, BSide extends string> = {
58
+ readonly between: [a: ASide, b: BSide];
59
+ readonly cardinality: `1:1` | `1:n` | `n:n`;
60
+ };
61
+ interface JunctionSchema<ASide extends string, BSide extends string> extends Json.Object, JunctionSchemaBase<ASide, BSide> {
62
+ }
63
+ type BaseExternalStoreConfiguration = {
64
+ addRelation: (a: string, b: string) => void;
65
+ deleteRelation: (a: string, b: string) => void;
66
+ replaceRelationsSafely: (a: string, bs: string[]) => void;
67
+ replaceRelationsUnsafely: (a: string, bs: string[]) => void;
68
+ getRelatedKeys(key: string): Set<string> | undefined;
69
+ has: (a: string, b?: string) => boolean;
70
+ };
71
+ type ExternalStoreWithContentConfiguration<Content extends Json.Object> = {
72
+ getContent: (contentKey: string) => Content | undefined;
73
+ setContent: (contentKey: string, content: Content) => void;
74
+ deleteContent: (contentKey: string) => void;
75
+ };
76
+ type Empty<Obj extends object> = {
77
+ [Key in keyof Obj]?: undefined;
78
+ };
79
+ type ExternalStoreConfiguration<Content extends Json.Object | null> = Content extends Json.Object ? BaseExternalStoreConfiguration & ExternalStoreWithContentConfiguration<Content> : BaseExternalStoreConfiguration & Empty<ExternalStoreWithContentConfiguration<Json.Object>>;
80
+ type JunctionAdvancedConfiguration<AType extends string, BType extends string, Content extends Json.Object | null> = {
81
+ warn?: (...args: any[]) => void;
82
+ externalStore?: ExternalStoreConfiguration<Content>;
83
+ isAType?: Refinement<string, AType>;
84
+ isBType?: Refinement<string, BType>;
85
+ isContent?: Refinement<unknown, Content>;
86
+ makeContentKey?: (a: AType, b: BType) => string;
87
+ };
88
+ 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>;
89
+ 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> {
90
+ readonly a: ASide;
91
+ readonly b: BSide;
92
+ readonly cardinality: `1:1` | `1:n` | `n:n`;
93
+ readonly relations: Map<AType | BType, Set<AType> | Set<BType>>;
94
+ readonly contents: Map<string, Content>;
95
+ isAType?: Refinement<string, AType> | null;
96
+ isBType?: Refinement<string, BType> | null;
97
+ isContent: Refinement<unknown, Content> | null;
98
+ makeContentKey: (a: AType, b: BType) => string;
99
+ warn?: (...args: any[]) => void;
100
+ getRelatedKeys(key: AType): Set<BType> | undefined;
101
+ getRelatedKeys(key: BType): Set<AType> | undefined;
102
+ getRelatedKeys(key: AType | BType): Set<AType> | Set<BType> | undefined;
103
+ protected addRelation(a: AType, b: BType): void;
104
+ protected deleteRelation(a: AType, b: BType): void;
105
+ protected replaceRelationsUnsafely(a: AType, bs: BType[]): void;
106
+ protected replaceRelationsUnsafely(b: BType, as: AType[]): void;
107
+ protected replaceRelationsSafely(a: AType, bs: BType[]): void;
108
+ protected replaceRelationsSafely(b: BType, as: AType[]): void;
109
+ protected getContentInternal(contentKey: string): Content | undefined;
110
+ protected setContent(contentKey: string, content: Content): void;
111
+ protected deleteContent(contentKey: string): void;
112
+ constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<NoInfer<AType>, NoInfer<BType>, Content>>, config?: JunctionAdvancedConfiguration<AType, BType, Content>);
113
+ toJSON(): JunctionJSON<ASide, AType, BSide, BType, Content>;
114
+ set(a: AType, ...rest: Content extends null ? [b: BType] : [b: BType, content: Content]): this;
115
+ set(relation: {
116
+ [Key in ASide]: AType;
117
+ } & {
118
+ [Key in BSide]: BType;
119
+ }, ...rest: Content extends null ? [] | [void?: undefined] : [content: Content]): this;
120
+ delete(a: AType, b?: BType): this;
121
+ delete(b: BType, a?: AType): this;
122
+ delete(relation: {
123
+ [Key in ASide]: AType;
124
+ } | {
125
+ [Key in BSide]: BType;
126
+ } | ({
127
+ [Key in ASide]: AType;
128
+ } & {
129
+ [Key in BSide]: BType;
130
+ }), b?: undefined): this;
131
+ getRelatedKey(key: AType): BType | undefined;
132
+ getRelatedKey(key: BType): AType | undefined;
133
+ replaceRelations(a: AType, relations: Content extends null ? BType[] : Record<BType, Content>, config?: {
134
+ reckless: boolean;
135
+ }): this;
136
+ replaceRelations(b: BType, relations: Content extends null ? AType[] : Record<AType, Content>, config?: {
137
+ reckless: boolean;
138
+ }): this;
139
+ getContent(a: AType, b: BType): Content | undefined;
140
+ getRelationEntries(input: Record<ASide, AType>): [BType, Content][];
141
+ getRelationEntries(input: Record<BSide, BType>): [AType, Content][];
142
+ has(a: AType, b?: BType): boolean;
143
+ has(b: BType, a?: AType): boolean;
144
+ }
145
+
146
+ declare class Subject<T> {
147
+ Subscriber: (value: T) => void;
148
+ subscribers: Map<string, this[`Subscriber`]>;
149
+ subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
150
+ private unsubscribe;
151
+ next(value: T): void;
16
152
  }
153
+ declare class StatefulSubject<T> extends Subject<T> {
154
+ state: T;
155
+ constructor(initialState: T);
156
+ next(value: T): void;
157
+ }
158
+
159
+ type Transaction<F extends Func> = {
160
+ key: string;
161
+ type: `transaction`;
162
+ install: (store: Store) => void;
163
+ subject: Subject<TransactionUpdate<F>>;
164
+ run: (parameters: Parameters<F>, id?: string) => ReturnType<F>;
165
+ };
166
+
167
+ type TransactionProgress<F extends Func> = {
168
+ phase: `applying` | `building`;
169
+ update: TransactionUpdate<F>;
170
+ toolkit: ActorToolkit;
171
+ };
172
+ type TransactionEpoch = {
173
+ epoch: Map<string, number>;
174
+ actionContinuities: Junction<`continuity`, string, `action`, string>;
175
+ };
176
+
177
+ type SetUpdate = `add:${string}` | `clear:${string}` | `del:${string}` | `tx:${string}`;
178
+ type NumberedSetUpdate = `${number}=${SetUpdate}`;
179
+ interface SetRTXJson<P extends primitive> extends Json.Object {
180
+ members: P[];
181
+ cache: (NumberedSetUpdate | null)[];
182
+ cacheLimit: number;
183
+ cacheIdx: number;
184
+ cacheUpdateNumber: number;
185
+ }
186
+ declare class SetRTX<P extends primitive> extends Set<P> implements Transceiver<NumberedSetUpdate>, Lineage {
187
+ mode: TransceiverMode;
188
+ readonly subject: Subject<SetUpdate>;
189
+ cacheLimit: number;
190
+ cache: (NumberedSetUpdate | null)[];
191
+ cacheIdx: number;
192
+ cacheUpdateNumber: number;
193
+ constructor(values?: Iterable<P>, cacheLimit?: number);
194
+ toJSON(): SetRTXJson<P>;
195
+ static fromJSON<P extends primitive>(json: SetRTXJson<P>): SetRTX<P>;
196
+ add(value: P): this;
197
+ clear(): void;
198
+ delete(value: P): boolean;
199
+ readonly parent: SetRTX<P> | null;
200
+ child: SetRTX<P> | null;
201
+ transactionUpdates: SetUpdate[] | null;
202
+ transaction(run: (child: SetRTX<P>) => boolean): void;
203
+ protected _subscribe(key: string, fn: (update: SetUpdate) => void): () => void;
204
+ subscribe(key: string, fn: (update: NumberedSetUpdate) => void): () => void;
205
+ emit(update: SetUpdate): void;
206
+ private doStep;
207
+ getUpdateNumber(update: NumberedSetUpdate): number;
208
+ do(update: NumberedSetUpdate): number | `OUT_OF_RANGE` | null;
209
+ undoStep(update: SetUpdate): void;
210
+ undo(update: NumberedSetUpdate): number | null;
211
+ }
212
+
213
+ type Molecule<K extends Canonical> = {
214
+ readonly key: K;
215
+ readonly stringKey: stringified<K>;
216
+ readonly dependsOn: `all` | `any`;
217
+ };
218
+
17
219
  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 ? {
18
220
  readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<[
19
221
  AType,
@@ -57,17 +259,6 @@ type JoinStateFamilies<ASide extends string, AType extends string, BSide extends
57
259
  } & {
58
260
  readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<BType[], AType>;
59
261
  } : never;
60
- type JoinHierarchy<AType extends SingularTypedKey, BType extends SingularTypedKey> = Hierarchy<[
61
- {
62
- above: `root`;
63
- below: [AType, BType];
64
- },
65
- {
66
- above: [AType, BType];
67
- style: `all`;
68
- below: CompoundTypedKey<`content`, AType, BType>;
69
- }
70
- ]>;
71
262
  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>> {
72
263
  private toolkit;
73
264
  options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>;
@@ -84,68 +275,653 @@ declare class Join<const ASide extends string, const AType extends string, const
84
275
  [Symbol.dispose](): void;
85
276
  constructor(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>, defaultContent: Content | undefined, store?: Store);
86
277
  }
87
- type JoinToken<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 = null> = {
88
- key: string;
89
- type: `join`;
90
- cardinality: Cardinality;
91
- a: ASide;
92
- b: BSide;
93
- __aType?: AType;
94
- __bType?: BType;
95
- __content?: Content;
96
- };
97
- declare function 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`>(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, null>, defaultContent?: undefined, store?: Store): JoinToken<ASide, AType, BSide, BType, Cardinality, null>;
98
- declare function 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>(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>, defaultContent: Content, store?: Store): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>;
99
- declare function getJoin<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>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>, store: Store): Join<ASide, AType, BSide, BType, Cardinality, Content>;
100
- type JoinStates<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 ? {
101
- readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<[
102
- AType,
103
- Content
104
- ] | null, BType>;
105
- } & {
106
- readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorToken<[
107
- BType,
108
- Content
109
- ] | null, AType>;
110
- } : {}) & {
111
- readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<AType | null, BType>;
112
- } & {
113
- readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorToken<BType | null, AType>;
114
- } : Cardinality extends `1:n` ? (Content extends Json.Object ? {
115
- readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<[
116
- AType,
117
- Content
118
- ] | null, BType>;
119
- } & {
120
- readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<[
121
- BType,
122
- Content
123
- ][], AType>;
124
- } : {}) & {
125
- readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<AType | null, BType>;
126
- } & {
127
- readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<BType[], AType>;
128
- } : Cardinality extends `n:n` ? (Content extends Json.Object ? {
129
- readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlySelectorToken<[
130
- AType,
131
- Content
132
- ][], BType>;
133
- } & {
134
- readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<[
135
- BType,
136
- Content
137
- ][], AType>;
138
- } : {}) & {
139
- readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlySelectorToken<AType[], BType>;
140
- } & {
141
- readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<BType[], AType>;
142
- } : never;
143
- declare function findRelationsInStore<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>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>, key: AType | BType, store: Store): JoinStates<ASide, AType, BSide, BType, Cardinality, Content>;
144
- declare function findRelations<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>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>, key: AType | BType): JoinStates<ASide, AType, BSide, BType, Cardinality, Content>;
145
- declare function editRelationsInStore<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>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>, change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void, store: Store): void;
146
- declare function editRelations<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>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>, change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void): void;
147
- declare function getInternalRelationsFromStore(token: JoinToken<any, any, any, any, any, any>, store: Store): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string>;
148
- declare function getInternalRelations<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>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string>;
278
+
279
+ interface Lineage {
280
+ parent: typeof this | null;
281
+ child: typeof this | null;
282
+ }
283
+
284
+ type OperationProgress = {
285
+ open: false;
286
+ } | {
287
+ open: true;
288
+ done: Set<string>;
289
+ prev: Map<string, any>;
290
+ time: number;
291
+ token: WritableToken<any>;
292
+ };
293
+
294
+ type TimelineAtomUpdate<ManagedAtom extends TimelineManageable> = Flat<StateUpdate<TokenType<ManagedAtom>> & {
295
+ key: string;
296
+ type: `atom_update`;
297
+ timestamp: number;
298
+ family?: FamilyMetadata;
299
+ }>;
300
+ type TimelineSelectorUpdate<ManagedAtom extends TimelineManageable> = {
301
+ key: string;
302
+ type: `selector_update`;
303
+ timestamp: number;
304
+ atomUpdates: Omit<TimelineAtomUpdate<ManagedAtom>, `timestamp`>[];
305
+ };
306
+ type TimelineTransactionUpdate = Flat<TransactionUpdate<Func> & {
307
+ key: string;
308
+ type: `transaction_update`;
309
+ timestamp: number;
310
+ }>;
311
+ type TimelineStateCreation<T extends ReadableToken<any>> = Flat<StateCreation<T> & {
312
+ timestamp: number;
313
+ }>;
314
+ type TimelineStateDisposal<T extends ReadableToken<any>> = Flat<StateDisposal<T> & {
315
+ timestamp: number;
316
+ }>;
317
+ type TimelineMoleculeCreation = Flat<MoleculeCreation & {
318
+ timestamp: number;
319
+ }>;
320
+ type TimelineMoleculeDisposal = Flat<MoleculeDisposal & {
321
+ timestamp: number;
322
+ }>;
323
+ type Timeline<ManagedAtom extends TimelineManageable> = {
324
+ type: `timeline`;
325
+ key: string;
326
+ at: number;
327
+ shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<ManagedAtom>) => boolean;
328
+ timeTraveling: `into_future` | `into_past` | null;
329
+ history: TimelineUpdate<ManagedAtom>[];
330
+ selectorTime: number | null;
331
+ transactionKey: string | null;
332
+ install: (store: Store) => void;
333
+ subject: Subject<TimelineUpdate<ManagedAtom> | `redo` | `undo`>;
334
+ subscriptions: Map<string, () => void>;
335
+ };
336
+
337
+ declare class Store implements Lineage {
338
+ parent: Store | null;
339
+ child: Store | null;
340
+ valueMap: Map<string, any>;
341
+ defaults: Map<string, any>;
342
+ atoms: Map<string, Atom<any>>;
343
+ selectors: Map<string, WritableSelector<any>>;
344
+ readonlySelectors: Map<string, ReadonlySelector<any>>;
345
+ atomsThatAreDefault: Set<string>;
346
+ selectorAtoms: Junction<"selectorKey", string, "atomKey", string, null>;
347
+ selectorGraph: Junction<"upstreamSelectorKey", string, "downstreamSelectorKey", string, {
348
+ source: string;
349
+ }>;
350
+ trackers: Map<string, Tracker<Transceiver<any>>>;
351
+ families: Map<string, MutableAtomFamily<any, any, any> | ReadonlySelectorFamily<any, any> | RegularAtomFamily<any, any> | WritableSelectorFamily<any, any>>;
352
+ joins: Map<string, Join<any, any, any, any, any, any, `T$--content==${any}::${string}++${any}::${string}`>>;
353
+ transactions: Map<string, Transaction<Func>>;
354
+ transactionMeta: TransactionEpoch | TransactionProgress<Func>;
355
+ timelines: Map<string, Timeline<any>>;
356
+ timelineTopics: Junction<"timelineKey", string, "topicKey", string, {
357
+ topicType: `atom_family` | `atom` | `molecule_family` | `molecule`;
358
+ }>;
359
+ disposalTraces: CircularBuffer<{
360
+ key: string;
361
+ trace: string;
362
+ }>;
363
+ molecules: Map<string, Molecule<Canonical>>;
364
+ moleculeJoins: Junction<"moleculeKey", stringified<Canonical>, "joinKey", string, null>;
365
+ moleculeGraph: Junction<"upstreamMoleculeKey", stringified<Canonical> | "root", "downstreamMoleculeKey", stringified<Canonical>, {
366
+ source: stringified<Canonical>;
367
+ }>;
368
+ moleculeData: Junction<"moleculeKey", stringified<Canonical>, "stateFamilyKey", string, null>;
369
+ miscResources: Map<string, Disposable>;
370
+ on: {
371
+ atomCreation: Subject<AtomToken<unknown>>;
372
+ atomDisposal: Subject<AtomToken<unknown>>;
373
+ selectorCreation: Subject<ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>>;
374
+ selectorDisposal: Subject<ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>>;
375
+ timelineCreation: Subject<TimelineToken<unknown>>;
376
+ transactionCreation: Subject<TransactionToken<Func>>;
377
+ transactionApplying: StatefulSubject<TransactionProgress<Func> | null>;
378
+ operationClose: Subject<OperationProgress>;
379
+ moleculeCreation: Subject<MoleculeCreation>;
380
+ moleculeDisposal: Subject<MoleculeDisposal>;
381
+ };
382
+ operation: OperationProgress;
383
+ config: {
384
+ name: string;
385
+ lifespan: `ephemeral` | `immortal`;
386
+ };
387
+ loggers: AtomIOLogger[];
388
+ logger: Logger;
389
+ constructor(config: Store[`config`], store?: Store | null);
390
+ }
391
+
392
+ interface Transceiver<S extends Json.Serializable> {
393
+ do: (update: S) => number | `OUT_OF_RANGE` | null;
394
+ undo: (update: S) => void;
395
+ subscribe: (key: string, fn: (update: S) => void) => () => void;
396
+ cacheUpdateNumber: number;
397
+ getUpdateNumber: (update: S) => number;
398
+ }
399
+ type TransceiverMode = `playback` | `record` | `transaction`;
400
+
401
+ /**
402
+ * @internal Give the tracker a transceiver state and a store, and it will
403
+ * subscribe to the transceiver's inner value. When the inner value changes,
404
+ * the tracker will update its own state to reflect the change.
405
+ */
406
+ declare class Tracker<Mutable extends Transceiver<any>> {
407
+ private Update;
408
+ private initializeState;
409
+ private unsubscribeFromInnerValue;
410
+ private unsubscribeFromState;
411
+ private observeCore;
412
+ private updateCore;
413
+ mutableState: MutableAtomToken<Mutable, Json.Serializable>;
414
+ latestUpdateState: RegularAtomToken<typeof this.Update | null>;
415
+ [Symbol.dispose]: () => void;
416
+ constructor(mutableState: MutableAtomToken<Mutable, Json.Serializable>, store: Store);
417
+ }
418
+
419
+ type EnvironmentData = {
420
+ store: Store;
421
+ };
422
+
423
+ type AtomIOState = {
424
+ key: string;
425
+ family?: FamilyMetadata;
426
+ install: (store: Store) => void;
427
+ subject: Subject<{
428
+ newValue: any;
429
+ oldValue: any;
430
+ }>;
431
+ };
432
+ type RegularAtom<T> = AtomIOState & {
433
+ type: `atom`;
434
+ default: T | (() => T);
435
+ cleanup?: () => void;
436
+ };
437
+ type MutableAtom<T extends Transceiver<any>, J extends Json.Serializable> = AtomIOState & JsonInterface<T, J> & {
438
+ type: `mutable_atom`;
439
+ default: T | (() => T);
440
+ cleanup?: () => void;
441
+ };
442
+ type Atom<T> = RegularAtom<T> | (T extends Transceiver<any> ? MutableAtom<T, any> : never);
443
+ type WritableSelector<T> = AtomIOState & {
444
+ type: `selector`;
445
+ get: () => T;
446
+ set: (newValue: T | ((oldValue: T) => T)) => void;
447
+ };
448
+ type ReadonlySelector<T> = AtomIOState & {
449
+ type: `readonly_selector`;
450
+ get: () => T;
451
+ };
452
+ type RegularAtomFamily<T, K extends Canonical> = RegularAtomFamilyToken<T, K> & {
453
+ (key: K): RegularAtomToken<T>;
454
+ subject: Subject<StateCreation<AtomToken<T>> | StateDisposal<AtomToken<T>>>;
455
+ install: (store: Store) => void;
456
+ internalRoles: string[] | undefined;
457
+ };
458
+ type MutableAtomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical> = JsonInterface<T, J> & MutableAtomFamilyToken<T, J, K> & {
459
+ (key: K): MutableAtomToken<T, J>;
460
+ subject: Subject<StateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>>;
461
+ install: (store: Store) => void;
462
+ internalRoles: string[] | undefined;
463
+ };
464
+ type WritableSelectorFamily<T, K extends Canonical> = WritableSelectorFamilyToken<T, K> & ((key: K) => WritableSelectorToken<T>) & {
465
+ default: (key: K) => T;
466
+ subject: Subject<StateCreation<WritableSelectorToken<T>> | StateDisposal<WritableSelectorToken<T>>>;
467
+ install: (store: Store) => void;
468
+ internalRoles: string[] | undefined;
469
+ };
470
+ type ReadonlySelectorFamily<T, K extends Canonical> = ReadonlySelectorFamilyToken<T, K> & ((key: K) => ReadonlySelectorToken<T>) & {
471
+ default: (key: K) => T;
472
+ subject: Subject<StateCreation<ReadonlySelectorToken<T>> | StateDisposal<ReadonlySelectorToken<T>>>;
473
+ install: (store: Store) => void;
474
+ internalRoles: string[] | undefined;
475
+ };
476
+
477
+ type RegularAtomFamilyToken<T, K extends Canonical> = {
478
+ key: string;
479
+ type: `atom_family`;
480
+ __T?: T;
481
+ __K?: K;
482
+ };
483
+ type MutableAtomFamilyToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical> = {
484
+ key: string;
485
+ type: `mutable_atom_family`;
486
+ __T?: T;
487
+ __J?: J;
488
+ __K?: K;
489
+ };
490
+ type AtomFamilyToken<T, K extends Canonical = Canonical> = MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomFamilyToken<T, K>;
491
+
492
+ type TransactionToken<F extends Func> = {
493
+ key: string;
494
+ type: `transaction`;
495
+ __F?: F;
496
+ };
497
+ type StateCreation<Token extends ReadableToken<any>> = {
498
+ type: `state_creation`;
499
+ token: Token;
500
+ };
501
+ type AtomDisposal<Token extends ReadableToken<any>> = {
502
+ type: `state_disposal`;
503
+ subType: `atom`;
504
+ token: Token;
505
+ value: TokenType<Token>;
506
+ };
507
+ type SelectorDisposal<Token extends ReadableToken<any>> = {
508
+ type: `state_disposal`;
509
+ subType: `selector`;
510
+ token: Token;
511
+ };
512
+ type StateDisposal<Token extends ReadableToken<any>> = AtomDisposal<Token> | SelectorDisposal<Token>;
513
+ type MoleculeCreation = {
514
+ type: `molecule_creation`;
515
+ key: Canonical;
516
+ provenance: Canonical;
517
+ };
518
+ type MoleculeDisposal = {
519
+ type: `molecule_disposal`;
520
+ key: Canonical;
521
+ provenance: stringified<Canonical>[];
522
+ values: [key: string, value: any][];
523
+ };
524
+ type MoleculeTransfer = {
525
+ type: `molecule_transfer`;
526
+ key: Canonical;
527
+ from: Canonical[];
528
+ to: Canonical[];
529
+ };
530
+ type TransactionUpdateContent = KeyedStateUpdate<unknown> | MoleculeCreation | MoleculeDisposal | MoleculeTransfer | StateCreation<ReadableToken<unknown>> | StateDisposal<ReadableToken<unknown>> | TransactionUpdate<Func>;
531
+ type TransactionUpdate<F extends Func> = {
532
+ type: `transaction_update`;
533
+ key: string;
534
+ id: string;
535
+ epoch: number;
536
+ updates: TransactionUpdateContent[];
537
+ params: Parameters<F>;
538
+ output: ReturnType<F>;
539
+ };
540
+ type SetterToolkit = Readonly<{
541
+ get: typeof getState;
542
+ set: typeof setState;
543
+ find: typeof findState;
544
+ json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritableSelectorToken<J>;
545
+ }>;
546
+ type ActorToolkit = Readonly<{
547
+ get: typeof getState;
548
+ set: typeof setState;
549
+ find: typeof findState;
550
+ json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritableSelectorToken<J>;
551
+ dispose: typeof disposeState;
552
+ run: typeof runTransaction;
553
+ env: () => EnvironmentData;
554
+ }>;
555
+ declare function runTransaction<F extends Func>(token: TransactionToken<F>, id?: string): (...parameters: Parameters<F>) => ReturnType<F>;
556
+
557
+ type WritableSelectorFamilyToken<T, K extends Canonical> = {
558
+ key: string;
559
+ type: `selector_family`;
560
+ __T?: T;
561
+ __K?: K;
562
+ };
563
+ type ReadonlySelectorFamilyToken<T, K extends Canonical> = {
564
+ key: string;
565
+ type: `readonly_selector_family`;
566
+ __T?: T;
567
+ __K?: K;
568
+ };
569
+ type SelectorFamilyToken<T, K extends Canonical> = ReadonlySelectorFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
570
+
571
+ type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>;
572
+ type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<any, any> ? AtomToken<any> : M extends AtomToken<any> ? M : never;
573
+ type TimelineToken<M> = {
574
+ key: string;
575
+ type: `timeline`;
576
+ __M?: M;
577
+ };
578
+ type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineMoleculeCreation | TimelineMoleculeDisposal | TimelineSelectorUpdate<ManagedAtom> | TimelineStateCreation<AtomOnly<ManagedAtom>> | TimelineStateDisposal<AtomOnly<ManagedAtom>> | TimelineTransactionUpdate;
579
+
580
+ /**
581
+ * @public
582
+ * Disposes of a state in the implicit store
583
+ * @param token - The token of the state to dispose
584
+ * @overload Default
585
+ */
586
+ declare function disposeState(token: ReadableToken<any>): void;
587
+ /**
588
+ * @public
589
+ * Disposes of a state family in the implicit store
590
+ * @param token - The token of the state family to dispose
591
+ * @param key - The unique key of the state to dispose
592
+ */
593
+ declare function disposeState<K extends Canonical>(token: ReadableFamilyToken<any, K>, key: K): void;
594
+
595
+ /**
596
+ * @public
597
+ * Finds a {@link MutableAtomToken} in the store
598
+ * @param token - A {@link MutableAtomFamilyToken}
599
+ * @param key - The key of the state
600
+ * @returns
601
+ * The current value of the state
602
+ * @overload Mutable Atom
603
+ */
604
+ 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>;
605
+ /**
606
+ * @public
607
+ * Finds a state in the store
608
+ * @param token - The token of the state family
609
+ * @param key - The key of the state
610
+ * @returns
611
+ * The current value of the state
612
+ * @overload Regular Atom
613
+ */
614
+ declare function findState<T, K extends Canonical, Key extends K>(token: RegularAtomFamilyToken<T, K>, key: Key): RegularAtomToken<T, K>;
615
+ /**
616
+ * @public
617
+ * Finds a state in the store
618
+ * @param token - The token of the state family
619
+ * @param key - The key of the state
620
+ * @returns
621
+ * The current value of the state
622
+ * @overload Writable Selector
623
+ */
624
+ declare function findState<T, K extends Canonical, Key extends K>(token: WritableSelectorFamilyToken<T, K>, key: Key): WritableSelectorToken<T, K>;
625
+ /**
626
+ * @public
627
+ * Finds a state in the store
628
+ * @param token - The token of the state family
629
+ * @param key - The key of the state
630
+ * @returns
631
+ * The current value of the state
632
+ * @overload Readonly Selector
633
+ */
634
+ declare function findState<T, K extends Canonical, Key extends K>(token: ReadonlySelectorFamilyToken<T, K>, key: Key): ReadonlySelectorToken<T, K>;
635
+ /**
636
+ * @public
637
+ * Finds a state in the store
638
+ * @param token - The token of the state family
639
+ * @param key - The key of the state
640
+ * @returns
641
+ * The current value of the state
642
+ * @overload Writable State
643
+ */
644
+ declare function findState<T, K extends Canonical, Key extends K>(token: WritableFamilyToken<T, K>, key: Key): WritableToken<T, K>;
645
+ /**
646
+ * @public
647
+ * Finds a {@link ReadableToken} in the store
648
+ * @param token - A {@link ReadableFamilyToken}
649
+ * @param key - The key of the state
650
+ * @returns
651
+ * The current value of the state
652
+ * @overload Unknown
653
+ * @default
654
+ */
655
+ declare function findState<T, K extends Canonical, Key extends K>(token: ReadableFamilyToken<T, K>, key: Key): ReadableToken<T, K>;
656
+
657
+ /**
658
+ * @public
659
+ * Get the current value of a state
660
+ * @param token - The token of the state to get
661
+ * @return The current value of the state
662
+ * @overload Default
663
+ * @default
664
+ */
665
+ declare function getState<T>(token: ReadableToken<T>): T;
666
+ /**
667
+ * @public
668
+ * Get the current value of a state family
669
+ * @param token - The token of a state family
670
+ * @param key - The unique key of the state to get
671
+ * @return The current value of the state
672
+ * @overload Streamlined
673
+ */
674
+ declare function getState<T, K extends Canonical, Key extends K>(token: ReadableFamilyToken<T, K>, key: Key): T;
675
+
676
+ 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>> {
677
+ readonly key: string;
678
+ readonly cardinality: Cardinality;
679
+ readonly isAType: Refinement<string, AType>;
680
+ readonly isBType: Refinement<string, BType>;
681
+ }
682
+
683
+ declare const LoggerIconDictionary: {
684
+ readonly "\u231B": "Timeline event fully captured";
685
+ readonly "\u23E9": "Timeline redo";
686
+ readonly "\u23EA": "Timeline undo";
687
+ readonly "\u23ED\uFE0F": "Transaction redo";
688
+ readonly "\u23EE\uFE0F": "Transaction undo";
689
+ readonly "\u23F3": "Timeline event partially captured";
690
+ readonly "\u23F9\uFE0F": "Time-travel complete";
691
+ readonly "\u2705": "Realtime transaction success";
692
+ readonly "\u2728": "Computation complete";
693
+ readonly "\u274C": "Conflict prevents attempted action";
694
+ readonly "\u2B55": "Operation start";
695
+ readonly "\uD83D\uDD34": "Operation complete";
696
+ readonly "\u2757": "Operation blocked";
697
+ readonly "\uD83D\uDFE2": "Operation unblocked";
698
+ readonly "\uD83D\uDC1E": "Possible bug in AtomIO";
699
+ readonly "\uD83D\uDC40": "Subscription added";
700
+ readonly "\uD83D\uDC4B": "Greeting";
701
+ readonly "\uD83D\uDC4D": "Realtime acknowledgment";
702
+ readonly "\uD83D\uDC6A": "Family member added";
703
+ readonly "\uD83D\uDC81": "Notice";
704
+ readonly "\uD83D\uDCA5": "Caught";
705
+ readonly "\uD83D\uDCC1": "Stow update";
706
+ readonly "\uD83D\uDCC3": "Copy mutable";
707
+ readonly "\uD83D\uDCD6": "Read state";
708
+ readonly "\uD83D\uDCDD": "Write state";
709
+ readonly "\uD83D\uDCE2": "Notify subscribers";
710
+ readonly "\uD83D\uDD04": "Realtime transaction synchronized";
711
+ readonly "\uD83D\uDD0C": "Register dependency";
712
+ readonly "\uD83D\uDD0D": "Discover root";
713
+ readonly "\uD83D\uDD25": "Delete state";
714
+ readonly "\uD83D\uDD27": "Create mutable atom";
715
+ readonly "\uD83D\uDD28": "Create immutable atom";
716
+ readonly "\uD83D\uDDD1": "Evict cached value";
717
+ readonly "\uD83D\uDE48": "Subscription canceled";
718
+ readonly "\uD83D\uDE80": "Performance measure";
719
+ readonly "\uD83D\uDEC4": "Apply transaction";
720
+ readonly "\uD83D\uDEE0\uFE0F": "Install atom into store";
721
+ readonly "\uD83D\uDEEB": "Begin transaction";
722
+ readonly "\uD83D\uDEEC": "Complete transaction";
723
+ readonly "\uD83E\uDDEE": "Computing selector";
724
+ readonly "\uD83E\uDDF9": "Prepare to evict";
725
+ readonly "\uD83E\uDE82": "Abort transaction";
726
+ readonly "\uD83E\uDD1E": "Realtime optimistic update enqueued";
727
+ readonly "\uD83D\uDC48": "Realtime confirmed update enqueued";
728
+ readonly "\uD83E\uDDD1\u200D\u2696\uFE0F": "Realtime update beginning reconciliation";
729
+ readonly "\uD83D\uDECE\uFE0F": "Realtime transaction received";
730
+ readonly "\uD83D\uDD2D": "Determining realtime perspective";
731
+ readonly "\uD83D\uDD8C": "Redacting realtime update";
732
+ readonly "\uD83D\uDC41": "Determining perspective";
733
+ };
734
+ type LoggerIcon = keyof typeof LoggerIconDictionary;
735
+ 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`;
736
+ declare const LOG_LEVELS: readonly ["info", "warn", "error"];
737
+ type LogLevel = (typeof LOG_LEVELS)[number];
738
+ type LogFn = (icon: LoggerIcon, denomination: TokenDenomination, tokenKey: string, message: string, ...rest: unknown[]) => void;
739
+ type LogFilter = (...params: Parameters<LogFn>) => boolean;
740
+ type Logger = Record<LogLevel, LogFn>;
741
+ declare class AtomIOLogger implements Logger {
742
+ logLevel: `error` | `info` | `warn` | null;
743
+ private readonly filter?;
744
+ private readonly logger;
745
+ constructor(logLevel: `error` | `info` | `warn` | null, filter?: LogFilter | undefined, logger?: Logger);
746
+ error: LogFn;
747
+ info: LogFn;
748
+ warn: LogFn;
749
+ }
750
+
751
+ declare const $claim: unique symbol;
752
+ type Claim<K extends Canonical> = K & {
753
+ [$claim]?: true;
754
+ };
755
+ declare class Realm<H extends Hierarchy> {
756
+ store: Store;
757
+ constructor(store?: Store);
758
+ allocate<V extends Vassal<H>, A extends Above<V, H>>(provenance: A, key: V, attachmentStyle?: `all` | `any`): Claim<V>;
759
+ 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>>;
760
+ deallocate<V extends Vassal<H>>(claim: Claim<V>): void;
761
+ claim<V extends Exclude<Vassal<H>, CompoundTypedKey>, A extends Above<V, H>>(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V>;
762
+ }
763
+ declare class Anarchy {
764
+ store: Store;
765
+ realm: Realm<any>;
766
+ constructor(store?: Store);
767
+ allocate(provenance: Canonical, key: Canonical, attachmentStyle?: `all` | `any`): void;
768
+ deallocate(key: Canonical): void;
769
+ claim(newProvenance: Canonical, key: Canonical, exclusive?: `exclusive`): void;
770
+ }
771
+ declare const T$ = "T$";
772
+ type T$ = typeof T$;
773
+ type TypeTag<T extends string> = `${T$}--${T}`;
774
+ type SingularTypedKey<T extends string = string> = `${T}::${string}`;
775
+ type CompoundTypedKey<A extends string = string, B extends string = string, C extends string = string> = `${TypeTag<A>}==${SingularTypedKey<B>}++${SingularTypedKey<C>}`;
776
+ type TypedKey<A extends string = string, B extends string = string, C extends string = string> = CompoundTypedKey<A, B, C> | SingularTypedKey<A>;
777
+ type Scope = SingularTypedKey[];
778
+ type MutualFealty = {
779
+ above: Scope;
780
+ below: CompoundTypedKey;
781
+ };
782
+ type ExclusiveFealty = {
783
+ above: TypedKey | `root`;
784
+ below: Scope;
785
+ };
786
+ type Fealty = ExclusiveFealty | MutualFealty;
787
+ type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>;
788
+ type Vassal<H extends Hierarchy> = {
789
+ [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : H[K] extends {
790
+ below: Array<infer V>;
791
+ } ? V extends TypedKey ? V : never : never;
792
+ }[keyof H];
793
+ type Above<TK extends TypedKey, H extends Hierarchy> = {
794
+ [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`below`] ? H[K][`above`] : never : H[K] extends {
795
+ below: Array<infer V>;
796
+ } ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`above`] : never : never : never;
797
+ }[keyof H];
798
+ type CompoundFrom<H extends Hierarchy> = {
799
+ [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : never;
800
+ }[keyof H];
801
+
802
+ /**
803
+ * @public
804
+ * A function that sets the value of a state.
805
+ * @param oldValue - The current value of the state.
806
+ * @returns
807
+ * The new value of the state.
808
+ */
809
+ type Setter<T, New extends T> = (oldValue: T) => New;
810
+ /**
811
+ * @public
812
+ * Set the value of a state into the implicit store.
813
+ * @param token - An atom or writable selector token.
814
+ * @param value - The new value of the state.
815
+ * @overload Default
816
+ * @default
817
+ */
818
+ declare function setState<T, New extends T>(token: WritableToken<T>, value: New | Setter<T, New>): void;
819
+ /**
820
+ * @public
821
+ * Set the value of a state into the implicit store.
822
+ * @param token - An atom family or writable selector family token.
823
+ * @param key - The unique key of the state to set.
824
+ * @param value - The new value of the state.
825
+ * @overload Streamlined
826
+ */
827
+ 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;
828
+
829
+ type StateUpdate<T> = {
830
+ newValue: T;
831
+ oldValue: T;
832
+ };
833
+ type KeyedStateUpdate<T> = Flat<StateUpdate<T> & {
834
+ key: string;
835
+ type: `atom_update` | `selector_update`;
836
+ family?: FamilyMetadata;
837
+ }>;
838
+
839
+ type TokenType<Comparison extends ReadableFamilyToken<any, any> | ReadableToken<any>> = Comparison extends ReadableToken<infer RepresentedValue> ? RepresentedValue : Comparison extends ReadableFamilyToken<infer RepresentedValue, any> ? RepresentedValue : never;
840
+
841
+ /** @public */
842
+ type RegularAtomToken<T, K extends Canonical = any> = {
843
+ /** The unique identifier of the atom. */
844
+ key: string;
845
+ /** Discriminator. */
846
+ type: `atom`;
847
+ /** Present if the atom belongs to a family. */
848
+ family?: FamilyMetadata<K>;
849
+ /** Never present. This is a marker that preserves the type of the atom's value. */
850
+ __T?: T;
851
+ };
852
+ /** @public */
853
+ type MutableAtomToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical = any> = {
854
+ /** The unique identifier of the atom. */
855
+ key: string;
856
+ /** Discriminator. */
857
+ type: `mutable_atom`;
858
+ /** Present if the atom belongs to a family. */
859
+ family?: FamilyMetadata<K>;
860
+ /** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
861
+ __J?: J;
862
+ /** Never present. This is a marker that preserves the type of the atom's transceiver value. */
863
+ __U?: T extends Transceiver<infer Update> ? Update : never;
864
+ };
865
+ /** @public */
866
+ type AtomToken<T, K extends Canonical = any> = MutableAtomToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomToken<T, K>;
867
+ /** @public */
868
+ type WritableSelectorToken<T, K extends Canonical = any> = {
869
+ /** The unique identifier of the selector. */
870
+ key: string;
871
+ /** Discriminator. */
872
+ type: `selector`;
873
+ /** Present if the selector belongs to a family. */
874
+ family?: FamilyMetadata<K>;
875
+ /** Never present. This is a marker that preserves the type of the selector's value. */
876
+ __T?: T;
877
+ };
878
+ /** @public */
879
+ type ReadonlySelectorToken<T, K extends Canonical = any> = {
880
+ /** The unique identifier of the selector. */
881
+ key: string;
882
+ /** Discriminator. */
883
+ type: `readonly_selector`;
884
+ /** Present if the selector belongs to a family. */
885
+ family?: FamilyMetadata<K>;
886
+ /** Never present. This is a marker that preserves the type of the selector's value. */
887
+ __T?: T;
888
+ };
889
+ /** @public */
890
+ type SelectorToken<T, K extends Canonical = any> = ReadonlySelectorToken<T, K> | WritableSelectorToken<T, K>;
891
+ /**
892
+ * @public
893
+ * These states can be set.
894
+ */
895
+ type WritableToken<T, K extends Canonical = any> = AtomToken<T, K> | WritableSelectorToken<T, K>;
896
+ /**
897
+ * @public
898
+ * These states cannot be set.
899
+ */
900
+ type ReadableToken<T, K extends Canonical = any> = AtomToken<T, K> | SelectorToken<T, K>;
901
+ /**
902
+ * @public
903
+ * States belonging to this family can be set.
904
+ */
905
+ type WritableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
906
+ /**
907
+ * @public
908
+ * States belonging to this family cannot be set.
909
+ */
910
+ type ReadableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | SelectorFamilyToken<T, K>;
911
+ /**
912
+ * @public
913
+ * Identifies a state's connection to its family.
914
+ */
915
+ type FamilyMetadata<K extends Canonical = any> = {
916
+ /** The family's unique key. */
917
+ key: string;
918
+ /** The family member's unique identifier, in the form of a string. */
919
+ subKey: stringified<K>;
920
+ };
921
+
922
+ declare function dict<State, Key extends Canonical>(family: ReadonlySelectorFamilyToken<State, Key> | RegularAtomFamilyToken<State, Key> | WritableSelectorFamilyToken<State, Key>, index: ReadonlySelectorToken<Key[]> | RegularAtomToken<Key[]> | WritableSelectorToken<Key[]>, store?: Store): ReadonlySelectorToken<{
923
+ [K in stringified<Key>]: State;
924
+ }>;
149
925
 
150
926
  declare function struct<Struct extends {
151
927
  [key: string]: unknown;
@@ -154,9 +930,9 @@ declare function struct<Struct extends {
154
930
  default: Struct;
155
931
  }, store?: Store): [
156
932
  {
157
- [K in keyof Struct as `${Key}${Capitalize<K & string>}State`]: AtomIO.RegularAtomToken<Struct[K]>;
933
+ [K in keyof Struct as `${Key}${Capitalize<K & string>}State`]: RegularAtomToken<Struct[K]>;
158
934
  },
159
- AtomIO.ReadonlySelectorToken<Struct>
935
+ ReadonlySelectorToken<Struct>
160
936
  ];
161
937
 
162
938
  declare function structFamily<Struct extends object, Key extends string>(options: {
@@ -164,19 +940,9 @@ declare function structFamily<Struct extends object, Key extends string>(options
164
940
  default: Struct;
165
941
  }): [
166
942
  {
167
- [K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<K & string>}State`]: AtomIO.RegularAtomFamilyToken<Struct[K], string>;
943
+ [K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<K & string>}State`]: RegularAtomFamilyToken<Struct[K], string>;
168
944
  },
169
- AtomIO.ReadonlySelectorFamilyToken<Struct, string>
945
+ ReadonlySelectorFamilyToken<Struct, string>
170
946
  ];
171
947
 
172
- type Loadable<T> = Promise<T> | T;
173
- type Fated<T, E extends Error = Error> = Loadable<E | T>;
174
- /**
175
- * Utility for handling loadable values
176
- * @param loadable Loadable value
177
- * @param fallback Fallback value until Loadable is resolved
178
- * @returns Fallback value if your loadable is a promise, otherwise the loadable's resolved value
179
- */
180
- declare function until<T>(loadable: Loadable<T>, fallback: T): T;
181
-
182
- export { type Fated, Join, type JoinHierarchy, type JoinOptions, type JoinStateFamilies, type JoinStates, type JoinToken, type Loadable, dict, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, join, struct, structFamily, until };
948
+ export { dict, struct, structFamily };