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
package/src/join.ts ADDED
@@ -0,0 +1,218 @@
1
+ import type { MutableAtomFamilyToken, ReadonlySelectorToken } from "atom.io"
2
+ import type {
3
+ Junction,
4
+ JunctionEntriesBase,
5
+ JunctionSchemaBase,
6
+ Refinement,
7
+ Store,
8
+ } from "atom.io/internal"
9
+ import {
10
+ editRelationsInStore,
11
+ findRelationsInStore,
12
+ getInternalRelationsFromStore,
13
+ IMPLICIT,
14
+ Join,
15
+ } from "atom.io/internal"
16
+ import type { Json } from "atom.io/json"
17
+ import type { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx"
18
+
19
+ export interface JoinOptions<
20
+ ASide extends string,
21
+ AType extends string,
22
+ BSide extends string,
23
+ BType extends string,
24
+ Cardinality extends `1:1` | `1:n` | `n:n`,
25
+ Content extends Json.Object | null,
26
+ > extends JunctionSchemaBase<ASide, BSide>,
27
+ Partial<JunctionEntriesBase<AType, BType, Content>> {
28
+ readonly key: string
29
+ readonly cardinality: Cardinality
30
+ readonly isAType: Refinement<string, AType>
31
+ readonly isBType: Refinement<string, BType>
32
+ }
33
+
34
+ export type JoinToken<
35
+ ASide extends string,
36
+ AType extends string,
37
+ BSide extends string,
38
+ BType extends string,
39
+ Cardinality extends `1:1` | `1:n` | `n:n`,
40
+ Content extends Json.Object | null = null,
41
+ > = {
42
+ key: string
43
+ type: `join`
44
+ cardinality: Cardinality
45
+ a: ASide
46
+ b: BSide
47
+ __aType?: AType
48
+ __bType?: BType
49
+ __content?: Content
50
+ }
51
+
52
+ export function join<
53
+ const ASide extends string,
54
+ const AType extends string,
55
+ const BSide extends string,
56
+ const BType extends string,
57
+ const Cardinality extends `1:1` | `1:n` | `n:n`,
58
+ >(
59
+ options: JoinOptions<ASide, AType, BSide, BType, Cardinality, null>,
60
+ defaultContent?: undefined,
61
+ store?: Store,
62
+ ): JoinToken<ASide, AType, BSide, BType, Cardinality, null>
63
+ export function join<
64
+ const ASide extends string,
65
+ const AType extends string,
66
+ const BSide extends string,
67
+ const BType extends string,
68
+ const Cardinality extends `1:1` | `1:n` | `n:n`,
69
+ const Content extends Json.Object,
70
+ >(
71
+ options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
72
+ defaultContent: Content,
73
+ store?: Store,
74
+ ): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>
75
+ export function join<
76
+ ASide extends string,
77
+ AType extends string,
78
+ BSide extends string,
79
+ BType extends string,
80
+ Cardinality extends `1:1` | `1:n` | `n:n`,
81
+ Content extends Json.Object,
82
+ >(
83
+ options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
84
+ defaultContent: Content | undefined,
85
+ store: Store = IMPLICIT.STORE,
86
+ ): JoinToken<ASide, AType, BSide, BType, Cardinality, Content> {
87
+ store.joins.set(options.key, new Join(options, defaultContent, store))
88
+ const token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content> = {
89
+ key: options.key,
90
+ type: `join`,
91
+ a: options.between[0],
92
+ b: options.between[1],
93
+ cardinality: options.cardinality,
94
+ }
95
+ return token
96
+ }
97
+
98
+ export type JoinStates<
99
+ ASide extends string,
100
+ AType extends string,
101
+ BSide extends string,
102
+ BType extends string,
103
+ Cardinality extends `1:1` | `1:n` | `n:n`,
104
+ Content extends Json.Object | null,
105
+ > = Cardinality extends `1:1`
106
+ ? (Content extends Json.Object
107
+ ? {
108
+ readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
109
+ [AType, Content] | null,
110
+ BType
111
+ >
112
+ } & {
113
+ readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
114
+ [BType, Content] | null,
115
+ AType
116
+ >
117
+ }
118
+ : {}) & {
119
+ readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
120
+ AType | null,
121
+ BType
122
+ >
123
+ } & {
124
+ readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
125
+ BType | null,
126
+ AType
127
+ >
128
+ }
129
+ : Cardinality extends `1:n`
130
+ ? (Content extends Json.Object
131
+ ? {
132
+ readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
133
+ [AType, Content] | null,
134
+ BType
135
+ >
136
+ } & {
137
+ readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
138
+ [BType, Content][],
139
+ AType
140
+ >
141
+ }
142
+ : {}) & {
143
+ readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
144
+ AType | null,
145
+ BType
146
+ >
147
+ } & {
148
+ readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
149
+ BType[],
150
+ AType
151
+ >
152
+ }
153
+ : Cardinality extends `n:n`
154
+ ? (Content extends Json.Object
155
+ ? {
156
+ readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
157
+ [AType, Content][],
158
+ BType
159
+ >
160
+ } & {
161
+ readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
162
+ [BType, Content][],
163
+ AType
164
+ >
165
+ }
166
+ : {}) & {
167
+ readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
168
+ AType[],
169
+ BType
170
+ >
171
+ } & {
172
+ readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
173
+ BType[],
174
+ AType
175
+ >
176
+ }
177
+ : never
178
+
179
+ export function findRelations<
180
+ ASide extends string,
181
+ AType extends string,
182
+ BSide extends string,
183
+ BType extends string,
184
+ Cardinality extends `1:1` | `1:n` | `n:n`,
185
+ Content extends Json.Object | null,
186
+ >(
187
+ token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
188
+ key: AType | BType,
189
+ ): JoinStates<ASide, AType, BSide, BType, Cardinality, Content> {
190
+ return findRelationsInStore(token, key, IMPLICIT.STORE)
191
+ }
192
+
193
+ export function editRelations<
194
+ ASide extends string,
195
+ AType extends string,
196
+ BSide extends string,
197
+ BType extends string,
198
+ Cardinality extends `1:1` | `1:n` | `n:n`,
199
+ Content extends Json.Object | null,
200
+ >(
201
+ token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
202
+ change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void,
203
+ ): void {
204
+ editRelationsInStore(token, change, IMPLICIT.STORE)
205
+ }
206
+
207
+ export function getInternalRelations<
208
+ ASide extends string,
209
+ AType extends string,
210
+ BSide extends string,
211
+ BType extends string,
212
+ Cardinality extends `1:1` | `1:n` | `n:n`,
213
+ Content extends Json.Object | null,
214
+ >(
215
+ token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
216
+ ): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
217
+ return getInternalRelationsFromStore(token, IMPLICIT.STORE)
218
+ }
package/src/realm.ts ADDED
@@ -0,0 +1,169 @@
1
+ import type { Each, Store } from "atom.io/internal"
2
+ import {
3
+ allocateIntoStore,
4
+ claimWithinStore,
5
+ deallocateFromStore,
6
+ fuseWithinStore,
7
+ IMPLICIT,
8
+ makeRootMoleculeInStore,
9
+ } from "atom.io/internal"
10
+ import type { Canonical } from "atom.io/json"
11
+
12
+ export const $claim = Symbol(`claim`)
13
+ export type Claim<K extends Canonical> = K & { [$claim]?: true }
14
+
15
+ export class Realm<H extends Hierarchy> {
16
+ public store: Store
17
+ public constructor(store: Store = IMPLICIT.STORE) {
18
+ this.store = store
19
+ makeRootMoleculeInStore(`root`, store)
20
+ }
21
+ public allocate<V extends Vassal<H>, A extends Above<V, H>>(
22
+ provenance: A,
23
+ key: V,
24
+ attachmentStyle?: `all` | `any`,
25
+ ): Claim<V> {
26
+ return allocateIntoStore<H, V, A>(
27
+ this.store,
28
+ provenance,
29
+ key,
30
+ attachmentStyle,
31
+ )
32
+ }
33
+ public fuse<
34
+ C extends CompoundFrom<H>,
35
+ T extends C extends CompoundTypedKey<infer t, any, any> ? t : never,
36
+ A extends C extends CompoundTypedKey<any, infer v, any> ? v : never,
37
+ B extends C extends CompoundTypedKey<any, any, infer m> ? m : never,
38
+ >(
39
+ type: T,
40
+ reagentA: SingularTypedKey<A>,
41
+ reagentB: SingularTypedKey<B>,
42
+ ): Claim<CompoundTypedKey<T, A, B>> {
43
+ return fuseWithinStore<H, C, T, A, B>(this.store, type, reagentA, reagentB)
44
+ }
45
+
46
+ public deallocate<V extends Vassal<H>>(claim: Claim<V>): void {
47
+ deallocateFromStore<H, V>(this.store, claim)
48
+ }
49
+ public claim<
50
+ V extends Exclude<Vassal<H>, CompoundTypedKey>,
51
+ A extends Above<V, H>,
52
+ >(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V> {
53
+ return claimWithinStore<H, V, A>(this.store, newProvenance, claim, exclusive)
54
+ }
55
+ }
56
+
57
+ export class Anarchy {
58
+ public store: Store
59
+ public realm: Realm<any>
60
+
61
+ public constructor(store: Store = IMPLICIT.STORE) {
62
+ this.store = store
63
+ this.realm = new Realm(store)
64
+ }
65
+
66
+ public allocate(
67
+ provenance: Canonical,
68
+ key: Canonical,
69
+ attachmentStyle?: `all` | `any`,
70
+ ): void {
71
+ allocateIntoStore<any, any, any>(
72
+ this.store,
73
+ provenance,
74
+ key,
75
+ attachmentStyle,
76
+ )
77
+ }
78
+
79
+ public deallocate(key: Canonical): void {
80
+ deallocateFromStore<any, any>(this.store, key)
81
+ }
82
+
83
+ public claim(
84
+ newProvenance: Canonical,
85
+ key: Canonical,
86
+ exclusive?: `exclusive`,
87
+ ): void {
88
+ claimWithinStore<any, any, any>(this.store, newProvenance, key, exclusive)
89
+ }
90
+ }
91
+
92
+ export const T$ = `T$`
93
+ export type T$ = typeof T$
94
+ export type TypeTag<T extends string> = `${T$}--${T}`
95
+ export type SingularTypedKey<T extends string = string> = `${T}::${string}`
96
+ export type CompoundTypedKey<
97
+ A extends string = string,
98
+ B extends string = string,
99
+ C extends string = string,
100
+ > = `${TypeTag<A>}==${SingularTypedKey<B>}++${SingularTypedKey<C>}`
101
+ export type TypedKey<
102
+ A extends string = string,
103
+ B extends string = string,
104
+ C extends string = string,
105
+ > = CompoundTypedKey<A, B, C> | SingularTypedKey<A>
106
+ type Scope = SingularTypedKey[]
107
+ type MutualFealty = {
108
+ above: Scope
109
+ below: CompoundTypedKey
110
+ }
111
+ type ExclusiveFealty = {
112
+ above: TypedKey | `root`
113
+ below: Scope
114
+ }
115
+ type Fealty = ExclusiveFealty | MutualFealty
116
+
117
+ export type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>
118
+
119
+ export type Vassal<H extends Hierarchy> = {
120
+ [K in keyof H]: H[K] extends MutualFealty
121
+ ? H[K][`below`]
122
+ : H[K] extends { below: Array<infer V> }
123
+ ? V extends TypedKey
124
+ ? V
125
+ : never
126
+ : never
127
+ }[keyof H]
128
+
129
+ export type Above<TK extends TypedKey, H extends Hierarchy> = {
130
+ [K in keyof H]: H[K] extends MutualFealty
131
+ ? TK extends H[K][`below`]
132
+ ? H[K][`above`]
133
+ : never
134
+ : H[K] extends { below: Array<infer V> }
135
+ ? TK extends V
136
+ ? H[K] extends ExclusiveFealty
137
+ ? H[K][`above`]
138
+ : never
139
+ : never
140
+ : never
141
+ }[keyof H]
142
+
143
+ export type Below<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
144
+ [K in keyof H]: H[K] extends MutualFealty
145
+ ? TK extends H[K][`above`]
146
+ ? H[K][`below`]
147
+ : TK extends H[K][`above`][number]
148
+ ? H[K][`below`]
149
+ : never
150
+ : H[K] extends { above: infer V }
151
+ ? TK extends V
152
+ ? H[K] extends ExclusiveFealty
153
+ ? H[K][`below`][number]
154
+ : never
155
+ : never
156
+ : never
157
+ }[keyof H]
158
+
159
+ export type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
160
+ [K in keyof H]: H[K] extends MutualFealty
161
+ ? TK extends H[K][`above`][number]
162
+ ? [mutual: Exclude<H[K][`above`][number], TK>, below: H[K][`below`]]
163
+ : never
164
+ : never
165
+ }[keyof H]
166
+
167
+ export type CompoundFrom<H extends Hierarchy> = {
168
+ [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : never
169
+ }[keyof H]
package/src/selector.ts CHANGED
@@ -18,9 +18,29 @@ export type ReadonlySelectorOptions<T> = {
18
18
  get: Read<() => T>
19
19
  }
20
20
 
21
+ /**
22
+ * @public
23
+ * Declare a selector. The value of a selector should depend
24
+ * on the value of atoms or other selectors in the store.
25
+ *
26
+ * A writable selector can be "set" to a new value.
27
+ * It is advised to set its dependencies to values
28
+ * that would produce the new value of the selector.
29
+ * @param options - {@link WritableSelectorOptions}.
30
+ * @returns
31
+ * The token for your selector.
32
+ * @overload Writable
33
+ */
21
34
  export function selector<T>(
22
35
  options: WritableSelectorOptions<T>,
23
36
  ): WritableSelectorToken<T>
37
+
38
+ /**
39
+ * @public
40
+ * Declare a selector. The value of a selector should depend
41
+ * on the value of atoms or other selectors in the store.
42
+ * @param options - {@link ReadonlySelectorOptions}.
43
+ */
24
44
  export function selector<T>(
25
45
  options: ReadonlySelectorOptions<T>,
26
46
  ): ReadonlySelectorToken<T>
package/src/set-state.ts CHANGED
@@ -3,41 +3,49 @@ import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { WritableFamilyToken, WritableToken } from "."
5
5
 
6
+ /**
7
+ * @public
8
+ * A function that sets the value of a state.
9
+ * @param oldValue - The current value of the state.
10
+ * @returns
11
+ * The new value of the state.
12
+ */
13
+ export type Setter<T, New extends T> = (oldValue: T) => New
14
+
6
15
  /**
7
16
  * @public
8
17
  * Set the value of a state into the implicit store.
9
- * @param token - The unique identifier of the state to set.
18
+ * @param token - An atom or writable selector token.
10
19
  * @param value - The new value of the state.
11
20
  * @overload Default
12
21
  * @default
13
22
  */
14
23
  export function setState<T, New extends T>(
15
24
  token: WritableToken<T>,
16
- value: New | ((oldValue: T) => New),
25
+ value: New | Setter<T, New>,
17
26
  ): void
18
27
 
19
28
  /**
20
29
  * @public
21
30
  * Set the value of a state into the implicit store.
22
- * @param token - The unique identifier of a state family.
23
- * @param key - The key of the state to set.
31
+ * @param token - An atom family or writable selector family token.
32
+ * @param key - The unique key of the state to set.
24
33
  * @param value - The new value of the state.
25
34
  * @overload Streamlined
26
35
  */
27
36
  export function setState<T, K extends Canonical, New extends T, Key extends K>(
28
37
  token: WritableFamilyToken<T, K>,
29
38
  key: Key,
30
- value: New | ((oldValue: T) => New),
39
+ value: New | Setter<T, New>,
31
40
  ): void
32
-
33
41
  export function setState<T, New extends T>(
34
42
  ...params:
35
43
  | [
36
44
  token: WritableFamilyToken<T, Canonical>,
37
45
  key: Canonical,
38
- value: New | ((oldValue: T) => New),
46
+ value: New | Setter<T, New>,
39
47
  ]
40
- | [token: WritableToken<T>, value: New | ((oldValue: T) => New)]
48
+ | [token: WritableToken<T>, value: New | Setter<T, New>]
41
49
  ): void {
42
50
  if (params.length === 2) {
43
51
  Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
package/src/silo.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { findState } from "atom.io/ephemeral"
1
+ import type { findState } from "atom.io"
2
2
  import {
3
3
  actUponStore,
4
4
  arbitrary,
@@ -11,13 +11,16 @@ import {
11
11
  disposeFromStore,
12
12
  findInStore,
13
13
  getFromStore,
14
+ IMPLICIT,
14
15
  setIntoStore,
15
16
  Store,
16
17
  subscribeInStore,
17
18
  timeTravel,
18
19
  } from "atom.io/internal"
19
20
 
21
+ import { installIntoStore } from "../internal/src/install-into-store"
20
22
  import type {
23
+ AtomIOToken,
21
24
  disposeState,
22
25
  getState,
23
26
  redo,
@@ -45,11 +48,11 @@ export class Silo {
45
48
  public subscribe: typeof subscribe
46
49
  public undo: typeof undo
47
50
  public redo: typeof redo
48
-
49
51
  public runTransaction: typeof runTransaction
52
+ public install: (tokens: AtomIOToken[], store?: Store) => void
53
+
50
54
  public constructor(config: Store[`config`], fromStore: Store | null = null) {
51
- const s = new Store(config, fromStore)
52
- this.store = s
55
+ const s = (this.store = new Store(config, fromStore))
53
56
  this.atom = ((options: Parameters<typeof atom>[0]) =>
54
57
  createStandaloneAtom(s, options)) as typeof atom
55
58
  this.atomFamily = ((options: Parameters<typeof atomFamily>[0]) =>
@@ -58,8 +61,8 @@ export class Silo {
58
61
  createStandaloneSelector(s, options)) as typeof selector
59
62
  this.selectorFamily = ((options: Parameters<typeof selectorFamily>[0]) =>
60
63
  createSelectorFamily(s, options)) as typeof selectorFamily
61
- this.transaction = (options) => createTransaction(options, s)
62
- this.timeline = (options) => createTimeline(options, s)
64
+ this.transaction = (options) => createTransaction(s, options)
65
+ this.timeline = (options) => createTimeline(s, options)
63
66
  this.findState = ((...params: Parameters<typeof findState>) =>
64
67
  findInStore(s, ...params)) as typeof findState
65
68
  this.getState = ((...params: Parameters<typeof getState>) =>
@@ -78,6 +81,9 @@ export class Silo {
78
81
  this.redo = (token) => {
79
82
  timeTravel(s, `redo`, token)
80
83
  }
81
- this.runTransaction = (token, id = arbitrary()) => actUponStore(token, id, s)
84
+ this.runTransaction = (token, id = arbitrary()) => actUponStore(s, token, id)
85
+ this.install = (tokens, source = IMPLICIT.STORE) => {
86
+ installIntoStore(tokens, s, source)
87
+ }
82
88
  }
83
89
  }
package/src/timeline.ts CHANGED
@@ -49,7 +49,7 @@ export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
49
49
  export const timeline = <ManagedAtom extends TimelineManageable>(
50
50
  options: TimelineOptions<ManagedAtom>,
51
51
  ): TimelineToken<ManagedAtom> => {
52
- return createTimeline(options, IMPLICIT.STORE)
52
+ return createTimeline(IMPLICIT.STORE, options)
53
53
  }
54
54
 
55
55
  export const redo = (tl: TimelineToken<any>): void => {
@@ -1,6 +1,4 @@
1
- import type { getState, setState } from "atom.io"
2
- import type { findState } from "atom.io/ephemeral"
3
- import type { seekState } from "atom.io/immortal"
1
+ import type { findState, getState, setState } from "atom.io"
4
2
  import type { EnvironmentData, Func, Transceiver } from "atom.io/internal"
5
3
  import {
6
4
  actUponStore,
@@ -83,12 +81,11 @@ export type TransactionUpdate<F extends Func> = {
83
81
  output: ReturnType<F>
84
82
  }
85
83
 
86
- export type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json` | `seek`>
84
+ export type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json`>
87
85
  export type SetterToolkit = Readonly<{
88
86
  get: typeof getState
89
87
  set: typeof setState
90
88
  find: typeof findState
91
- seek: typeof seekState
92
89
  json: <T extends Transceiver<any>, J extends Json.Serializable>(
93
90
  state: MutableAtomToken<T, J>,
94
91
  ) => WritableSelectorToken<J>
@@ -97,7 +94,6 @@ export type ActorToolkit = Readonly<{
97
94
  get: typeof getState
98
95
  set: typeof setState
99
96
  find: typeof findState
100
- seek: typeof seekState
101
97
  json: <T extends Transceiver<any>, J extends Json.Serializable>(
102
98
  state: MutableAtomToken<T, J>,
103
99
  ) => WritableSelectorToken<J>
@@ -132,12 +128,12 @@ export type TransactionIO<Token extends TransactionToken<any>> =
132
128
  export function transaction<F extends Func>(
133
129
  options: TransactionOptions<F>,
134
130
  ): TransactionToken<F> {
135
- return createTransaction(options, IMPLICIT.STORE)
131
+ return createTransaction(IMPLICIT.STORE, options)
136
132
  }
137
133
 
138
134
  export function runTransaction<F extends Func>(
139
135
  token: TransactionToken<F>,
140
136
  id = arbitrary(),
141
137
  ): (...parameters: Parameters<F>) => ReturnType<F> {
142
- return actUponStore(token, id, IMPLICIT.STORE)
138
+ return actUponStore(IMPLICIT.STORE, token, id)
143
139
  }
@@ -1,5 +1,40 @@
1
- import { Transceiver, Lineage, TransceiverMode, Subject } from 'atom.io/internal';
2
- import { primitive, Json } from 'atom.io/json';
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
+
17
+ declare class Subject<T> {
18
+ Subscriber: (value: T) => void;
19
+ subscribers: Map<string, this[`Subscriber`]>;
20
+ subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
21
+ private unsubscribe;
22
+ next(value: T): void;
23
+ }
24
+
25
+ interface Lineage {
26
+ parent: typeof this | null;
27
+ child: typeof this | null;
28
+ }
29
+
30
+ interface Transceiver<S extends Json.Serializable> {
31
+ do: (update: S) => number | `OUT_OF_RANGE` | null;
32
+ undo: (update: S) => void;
33
+ subscribe: (key: string, fn: (update: S) => void) => () => void;
34
+ cacheUpdateNumber: number;
35
+ getUpdateNumber: (update: S) => number;
36
+ }
37
+ type TransceiverMode = `playback` | `record` | `transaction`;
3
38
 
4
39
  type SetUpdate = `add:${string}` | `clear:${string}` | `del:${string}` | `tx:${string}`;
5
40
  type NumberedSetUpdate = `${number}=${SetUpdate}`;