atom.io 0.40.0 → 0.40.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 (134) hide show
  1. package/dist/data/index.d.ts +1 -1
  2. package/dist/data/index.d.ts.map +1 -1
  3. package/dist/data/index.js.map +1 -1
  4. package/dist/internal/index.d.ts +205 -196
  5. package/dist/internal/index.d.ts.map +1 -1
  6. package/dist/internal/index.js +145 -107
  7. package/dist/internal/index.js.map +1 -1
  8. package/dist/introspection/index.d.ts +6 -6
  9. package/dist/introspection/index.d.ts.map +1 -1
  10. package/dist/introspection/index.js.map +1 -1
  11. package/dist/main/index.d.ts +93 -66
  12. package/dist/main/index.d.ts.map +1 -1
  13. package/dist/main/index.js +16 -13
  14. package/dist/main/index.js.map +1 -1
  15. package/dist/react/index.d.ts +14 -14
  16. package/dist/react/index.d.ts.map +1 -1
  17. package/dist/react/index.js.map +1 -1
  18. package/dist/react-devtools/index.js +1 -1
  19. package/dist/react-devtools/index.js.map +1 -1
  20. package/dist/realtime-client/index.d.ts +3 -3
  21. package/dist/realtime-client/index.d.ts.map +1 -1
  22. package/dist/realtime-client/index.js +3 -4
  23. package/dist/realtime-client/index.js.map +1 -1
  24. package/dist/realtime-server/index.d.ts +2 -2
  25. package/dist/realtime-server/index.d.ts.map +1 -1
  26. package/package.json +2 -2
  27. package/src/data/struct.ts +2 -2
  28. package/src/internal/atom/create-regular-atom.ts +11 -9
  29. package/src/internal/atom/dispose-atom.ts +11 -8
  30. package/src/internal/atom/has-role.ts +1 -1
  31. package/src/internal/caching.ts +15 -15
  32. package/src/internal/events/ingest-creation-disposal.ts +1 -1
  33. package/src/internal/families/create-readonly-held-selector-family.ts +3 -4
  34. package/src/internal/families/create-readonly-pure-selector-family.ts +25 -23
  35. package/src/internal/families/create-regular-atom-family.ts +21 -15
  36. package/src/internal/families/create-selector-family.ts +15 -15
  37. package/src/internal/families/create-writable-held-selector-family.ts +2 -2
  38. package/src/internal/families/create-writable-pure-selector-family.ts +25 -21
  39. package/src/internal/families/dispose-from-store.ts +17 -7
  40. package/src/internal/families/find-in-store.ts +23 -23
  41. package/src/internal/families/get-family-of-token.ts +17 -17
  42. package/src/internal/families/mint-in-store.ts +10 -10
  43. package/src/internal/families/seek-in-store.ts +26 -26
  44. package/src/internal/get-state/get-fallback.ts +8 -8
  45. package/src/internal/get-state/get-from-store.ts +20 -8
  46. package/src/internal/get-state/read-or-compute-value.ts +78 -14
  47. package/src/internal/get-state/reduce-reference.ts +10 -10
  48. package/src/internal/index.ts +65 -60
  49. package/src/internal/install-into-store.ts +2 -1
  50. package/src/internal/join/create-join.ts +2 -2
  51. package/src/internal/join/find-relations-in-store.ts +2 -2
  52. package/src/internal/join/get-internal-relations-from-store.ts +2 -2
  53. package/src/internal/join/get-join.ts +5 -2
  54. package/src/internal/join/join-internal.ts +30 -26
  55. package/src/internal/lineage.ts +12 -1
  56. package/src/internal/molecule.ts +64 -36
  57. package/src/internal/mutable/create-mutable-atom-family.ts +5 -5
  58. package/src/internal/mutable/create-mutable-atom.ts +2 -2
  59. package/src/internal/mutable/get-json-family.ts +3 -2
  60. package/src/internal/mutable/get-update-family.ts +7 -5
  61. package/src/internal/mutable/tracker-family.ts +8 -4
  62. package/src/internal/mutable/tracker.ts +5 -1
  63. package/src/internal/operation.ts +4 -2
  64. package/src/internal/selector/create-readonly-held-selector.ts +2 -2
  65. package/src/internal/selector/create-readonly-pure-selector.ts +10 -8
  66. package/src/internal/selector/create-standalone-selector.ts +10 -10
  67. package/src/internal/selector/create-writable-held-selector.ts +2 -2
  68. package/src/internal/selector/create-writable-pure-selector.ts +11 -9
  69. package/src/internal/selector/dispose-selector.ts +2 -2
  70. package/src/internal/selector/register-selector.ts +2 -2
  71. package/src/internal/selector/trace-selector-atoms.ts +3 -3
  72. package/src/internal/selector/update-selector-atoms.ts +1 -1
  73. package/src/internal/set-state/become.ts +1 -3
  74. package/src/internal/set-state/dispatch-state-update.ts +10 -6
  75. package/src/internal/set-state/evict-downstream.ts +4 -1
  76. package/src/internal/set-state/operate-on-store.ts +16 -10
  77. package/src/internal/set-state/reset-atom-or-selector.ts +7 -7
  78. package/src/internal/set-state/reset-in-store.ts +17 -16
  79. package/src/internal/set-state/set-atom-or-selector.ts +1 -1
  80. package/src/internal/set-state/set-atom.ts +1 -1
  81. package/src/internal/set-state/set-into-store.ts +34 -7
  82. package/src/internal/set-state/set-selector.ts +1 -1
  83. package/src/internal/store/deposit.ts +38 -30
  84. package/src/internal/store/mint-or-counterfeit.ts +23 -23
  85. package/src/internal/store/store.ts +23 -21
  86. package/src/internal/store/withdraw.ts +68 -62
  87. package/src/internal/subscribe/recall-state.ts +4 -1
  88. package/src/internal/subscribe/subscribe-to-root-atoms.ts +2 -2
  89. package/src/internal/subscribe/subscribe-to-state.ts +4 -4
  90. package/src/internal/timeline/create-timeline.ts +11 -10
  91. package/src/internal/timeline/time-travel.ts +4 -3
  92. package/src/internal/transaction/abort-transaction.ts +3 -15
  93. package/src/internal/transaction/act-upon-store.ts +1 -5
  94. package/src/internal/transaction/apply-transaction.ts +3 -15
  95. package/src/internal/transaction/assign-transaction-to-continuity.ts +2 -7
  96. package/src/internal/transaction/build-transaction.ts +2 -3
  97. package/src/internal/transaction/create-transaction.ts +5 -6
  98. package/src/internal/transaction/get-epoch-number.ts +1 -7
  99. package/src/internal/transaction/set-epoch-number.ts +4 -12
  100. package/src/introspection/attach-atom-index.ts +2 -2
  101. package/src/introspection/attach-introspection-states.ts +4 -2
  102. package/src/introspection/attach-selector-index.ts +4 -2
  103. package/src/introspection/attach-timeline-family.ts +15 -13
  104. package/src/introspection/attach-timeline-index.ts +1 -1
  105. package/src/introspection/attach-transaction-index.ts +1 -1
  106. package/src/introspection/attach-transaction-logs.ts +6 -4
  107. package/src/introspection/attach-type-selectors.ts +4 -3
  108. package/src/introspection/index.ts +3 -5
  109. package/src/main/atom.ts +14 -8
  110. package/src/main/dispose-state.ts +1 -5
  111. package/src/main/events.ts +26 -26
  112. package/src/main/get-state.ts +10 -11
  113. package/src/main/realm.ts +36 -12
  114. package/src/main/reset-state.ts +5 -9
  115. package/src/main/selector.ts +40 -24
  116. package/src/main/set-state.ts +8 -11
  117. package/src/main/silo.ts +4 -3
  118. package/src/main/timeline.ts +5 -3
  119. package/src/main/tokens.ts +72 -44
  120. package/src/main/validators.ts +4 -4
  121. package/src/react/parse-state-overloads.ts +10 -10
  122. package/src/react/store-context.tsx +3 -3
  123. package/src/react/use-i.ts +6 -6
  124. package/src/react/use-loadable.ts +15 -15
  125. package/src/react/use-o.ts +9 -9
  126. package/src/react-devtools/Button.tsx +3 -2
  127. package/src/react-devtools/StateEditor.tsx +5 -3
  128. package/src/react-devtools/StateIndex.tsx +6 -4
  129. package/src/react-devtools/TimelineIndex.tsx +0 -2
  130. package/src/react-devtools/Updates.tsx +1 -1
  131. package/src/react-devtools/store.ts +18 -9
  132. package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +4 -8
  133. package/src/realtime-client/sync-continuity.ts +2 -2
  134. package/src/realtime-server/index.ts +2 -2
@@ -11,36 +11,36 @@ import type {
11
11
  } from "atom.io"
12
12
  import type { Canonical } from "atom.io/json"
13
13
 
14
- import type { Store } from "../store"
14
+ import type { RootStore } from "../transaction"
15
15
  import { createReadonlyHeldSelectorFamily } from "./create-readonly-held-selector-family"
16
16
  import { createReadonlyPureSelectorFamily } from "./create-readonly-pure-selector-family"
17
17
  import { createWritableHeldSelectorFamily } from "./create-writable-held-selector-family"
18
18
  import { createWritablePureSelectorFamily } from "./create-writable-pure-selector-family"
19
19
 
20
20
  export function createSelectorFamily<T extends object, K extends Canonical>(
21
- store: Store,
21
+ store: RootStore,
22
22
  options: WritableHeldSelectorFamilyOptions<T, K>,
23
23
  ): WritableHeldSelectorFamilyToken<T, K>
24
24
  export function createSelectorFamily<T extends object, K extends Canonical>(
25
- store: Store,
25
+ store: RootStore,
26
26
  options: ReadonlyHeldSelectorFamilyOptions<T, K>,
27
27
  ): ReadonlyHeldSelectorFamilyToken<T, K>
28
- export function createSelectorFamily<T, K extends Canonical>(
29
- store: Store,
30
- options: WritablePureSelectorFamilyOptions<T, K>,
31
- ): WritablePureSelectorFamilyToken<T, K>
32
- export function createSelectorFamily<T, K extends Canonical>(
33
- store: Store,
34
- options: ReadonlyPureSelectorFamilyOptions<T, K>,
35
- ): ReadonlyPureSelectorFamilyToken<T, K>
28
+ export function createSelectorFamily<T, K extends Canonical, E>(
29
+ store: RootStore,
30
+ options: WritablePureSelectorFamilyOptions<T, K, E>,
31
+ ): WritablePureSelectorFamilyToken<T, K, E>
32
+ export function createSelectorFamily<T, K extends Canonical, E>(
33
+ store: RootStore,
34
+ options: ReadonlyPureSelectorFamilyOptions<T, K, E>,
35
+ ): ReadonlyPureSelectorFamilyToken<T, K, E>
36
36
  export function createSelectorFamily(
37
- store: Store,
37
+ store: RootStore,
38
38
  options:
39
39
  | ReadonlyHeldSelectorFamilyOptions<any, any>
40
- | ReadonlyPureSelectorFamilyOptions<any, any>
40
+ | ReadonlyPureSelectorFamilyOptions<any, any, any>
41
41
  | WritableHeldSelectorFamilyOptions<any, any>
42
- | WritablePureSelectorFamilyOptions<any, any>,
43
- ): SelectorFamilyToken<any, any> {
42
+ | WritablePureSelectorFamilyOptions<any, any, any>,
43
+ ): SelectorFamilyToken<any, any, any> {
44
44
  const isWritable = `set` in options
45
45
  const isHeld = `const` in options
46
46
 
@@ -9,7 +9,7 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
9
9
  import type { Canonical } from "atom.io/json"
10
10
  import { stringifyJson } from "atom.io/json"
11
11
 
12
- import type { WritableHeldSelectorFamily } from ".."
12
+ import type { RootStore, WritableHeldSelectorFamily } from ".."
13
13
  import { newest } from "../lineage"
14
14
  import { createWritableHeldSelector } from "../selector"
15
15
  import type { Store } from "../store"
@@ -68,7 +68,7 @@ export function createWritableHeldSelectorFamily<
68
68
  const selectorFamily = Object.assign(familyFunction, familyToken, {
69
69
  internalRoles,
70
70
  subject,
71
- install: (s: Store) => createWritableHeldSelectorFamily(s, options),
71
+ install: (s: RootStore) => createWritableHeldSelectorFamily(s, options),
72
72
  default: options.const,
73
73
  }) satisfies WritableHeldSelectorFamily<T, K>
74
74
 
@@ -5,35 +5,32 @@ import type {
5
5
  StateLifecycleEvent,
6
6
  WritablePureSelectorFamilyOptions,
7
7
  WritablePureSelectorFamilyToken,
8
+ WritablePureSelectorOptions,
8
9
  WritablePureSelectorToken,
9
10
  } from "atom.io"
10
11
  import { PRETTY_TOKEN_TYPES } from "atom.io"
11
12
  import type { Canonical } from "atom.io/json"
12
13
  import { stringifyJson } from "atom.io/json"
13
14
 
14
- import {
15
- findInStore,
16
- getFromStore,
17
- getJsonToken,
18
- type WritablePureSelectorFamily,
19
- } from ".."
15
+ import type { RootStore, WritablePureSelectorFamily } from ".."
16
+ import { findInStore, getFromStore, getJsonToken } from ".."
20
17
  import { newest } from "../lineage"
21
18
  import { createWritablePureSelector } from "../selector"
22
19
  import type { Store } from "../store"
23
20
  import { Subject } from "../subject"
24
21
 
25
- export function createWritablePureSelectorFamily<T, K extends Canonical>(
22
+ export function createWritablePureSelectorFamily<T, K extends Canonical, E>(
26
23
  store: Store,
27
- options: WritablePureSelectorFamilyOptions<T, K>,
24
+ options: WritablePureSelectorFamilyOptions<T, K, E>,
28
25
  internalRoles?: string[],
29
- ): WritablePureSelectorFamilyToken<T, K> {
26
+ ): WritablePureSelectorFamilyToken<T, K, E> {
30
27
  const familyKey = options.key
31
28
  const type = `writable_pure_selector_family`
32
29
 
33
30
  const familyToken = {
34
31
  key: familyKey,
35
32
  type,
36
- } as const satisfies WritablePureSelectorFamilyToken<T, K>
33
+ } as const satisfies WritablePureSelectorFamilyToken<T, K, E>
37
34
 
38
35
  const existing = store.families.get(familyKey)
39
36
  if (existing) {
@@ -45,22 +42,28 @@ export function createWritablePureSelectorFamily<T, K extends Canonical>(
45
42
  )
46
43
  }
47
44
  const subject = new Subject<
48
- StateLifecycleEvent<WritablePureSelectorToken<T>>
45
+ StateLifecycleEvent<WritablePureSelectorToken<T, K, E>>
49
46
  >()
50
47
 
51
- const familyFunction = (key: K): WritablePureSelectorToken<T> => {
48
+ const familyFunction = <Key extends K>(
49
+ key: Key,
50
+ ): WritablePureSelectorToken<T, Key, E> => {
52
51
  const subKey = stringifyJson(key)
53
- const family: FamilyMetadata = { key: familyKey, subKey }
52
+ const family: FamilyMetadata<Key> = { key: familyKey, subKey }
54
53
  const fullKey = `${familyKey}(${subKey})`
55
54
  const target = newest(store)
55
+ const individualOptions: WritablePureSelectorOptions<T, E> = {
56
+ key: fullKey,
57
+ get: options.get(key),
58
+ set: options.set(key),
59
+ }
60
+ if (options.catch) {
61
+ individualOptions.catch = options.catch
62
+ }
56
63
 
57
- const token = createWritablePureSelector(
64
+ const token = createWritablePureSelector<T, Key, E>(
58
65
  target,
59
- {
60
- key: fullKey,
61
- get: options.get(key),
62
- set: options.set(key),
63
- },
66
+ individualOptions,
64
67
  family,
65
68
  )
66
69
 
@@ -71,7 +74,7 @@ export function createWritablePureSelectorFamily<T, K extends Canonical>(
71
74
  const selectorFamily = Object.assign(familyFunction, familyToken, {
72
75
  internalRoles,
73
76
  subject,
74
- install: (s: Store) => createWritablePureSelectorFamily(s, options),
77
+ install: (s: RootStore) => createWritablePureSelectorFamily(s, options),
75
78
  default: (key: K) => {
76
79
  const getFn = options.get(key)
77
80
  return getFn({
@@ -82,7 +85,8 @@ export function createWritablePureSelectorFamily<T, K extends Canonical>(
82
85
  json: (token) => getJsonToken(store, token),
83
86
  })
84
87
  },
85
- }) satisfies WritablePureSelectorFamily<T, K>
88
+ ...(options.catch ? { catch: options.catch } : {}),
89
+ }) satisfies WritablePureSelectorFamily<T, K, E>
86
90
 
87
91
  store.families.set(familyKey, selectorFamily)
88
92
  return familyToken
@@ -6,21 +6,31 @@ import { disposeSelector } from "../selector"
6
6
  import { type Store, withdraw } from "../store"
7
7
  import { findInStore } from "./find-in-store"
8
8
 
9
- export function disposeFromStore(store: Store, token: ReadableToken<any>): void
9
+ export function disposeFromStore(
10
+ store: Store,
11
+ token: ReadableToken<any, any, any>,
12
+ ): void
10
13
 
11
- export function disposeFromStore<K extends Canonical>(
14
+ export function disposeFromStore<K extends Canonical, Key extends K>(
12
15
  store: Store,
13
- token: ReadableFamilyToken<any, K>,
14
- key: K,
16
+ token: ReadableFamilyToken<any, K, any>,
17
+ key: Key,
18
+ ): void
19
+
20
+ export function disposeFromStore<K extends Canonical, Key extends K>(
21
+ store: Store,
22
+ ...params:
23
+ | [token: ReadableFamilyToken<any, K, any>, key: Key]
24
+ | [token: ReadableToken<any, any, any>]
15
25
  ): void
16
26
 
17
27
  export function disposeFromStore(
18
28
  store: Store,
19
29
  ...params:
20
- | [token: ReadableFamilyToken<any, any>, key: Canonical]
21
- | [token: ReadableToken<any>]
30
+ | [token: ReadableFamilyToken<any, any, any>, key: Canonical]
31
+ | [token: ReadableToken<any, any, any>]
22
32
  ): void {
23
- let token: ReadableToken<any>
33
+ let token: ReadableToken<any, any, any>
24
34
  if (params.length === 1) {
25
35
  token = params[0]
26
36
  } else {
@@ -38,53 +38,53 @@ export function findInStore<
38
38
  key: Key,
39
39
  ): MutableAtomToken<T, K>
40
40
 
41
- export function findInStore<T, K extends Canonical, Key extends K>(
41
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
42
42
  store: Store,
43
- familyToken: RegularAtomFamilyToken<T, K>,
43
+ familyToken: RegularAtomFamilyToken<T, K, E>,
44
44
  key: Key,
45
- ): RegularAtomToken<T, K>
45
+ ): RegularAtomToken<T, K, E>
46
46
 
47
- export function findInStore<T, K extends Canonical, Key extends K>(
47
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
48
48
  store: Store,
49
- familyToken: AtomFamilyToken<T, K>,
49
+ familyToken: AtomFamilyToken<T, K, E>,
50
50
  key: Key,
51
- ): AtomToken<T, K>
51
+ ): AtomToken<T, K, E>
52
52
 
53
- export function findInStore<T, K extends Canonical, Key extends K>(
53
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
54
54
  store: Store,
55
- familyToken: WritablePureSelectorFamilyToken<T, K>,
55
+ familyToken: WritablePureSelectorFamilyToken<T, K, E>,
56
56
  key: Key,
57
- ): WritablePureSelectorToken<T, K>
57
+ ): WritablePureSelectorToken<T, K, E>
58
58
 
59
- export function findInStore<T, K extends Canonical, Key extends K>(
59
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
60
60
  store: Store,
61
- familyToken: ReadonlyPureSelectorFamilyToken<T, K>,
61
+ familyToken: ReadonlyPureSelectorFamilyToken<T, K, E>,
62
62
  key: Key,
63
- ): ReadonlyPureSelectorToken<T, K>
63
+ ): ReadonlyPureSelectorToken<T, K, E>
64
64
 
65
- export function findInStore<T, K extends Canonical, Key extends K>(
65
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
66
66
  store: Store,
67
- familyToken: SelectorFamilyToken<T, K>,
67
+ familyToken: SelectorFamilyToken<T, K, E>,
68
68
  key: Key,
69
- ): SelectorToken<T, K>
69
+ ): SelectorToken<T, K, E>
70
70
 
71
- export function findInStore<T, K extends Canonical, Key extends K>(
71
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
72
72
  store: Store,
73
- familyToken: WritableFamilyToken<T, K>,
73
+ familyToken: WritableFamilyToken<T, K, E>,
74
74
  key: Key,
75
- ): WritableToken<T, K>
75
+ ): WritableToken<T, K, E>
76
76
 
77
- export function findInStore<T, K extends Canonical, Key extends K>(
77
+ export function findInStore<T, K extends Canonical, Key extends K, E>(
78
78
  store: Store,
79
- familyToken: ReadableFamilyToken<T, K>,
79
+ familyToken: ReadableFamilyToken<T, K, E>,
80
80
  key: Key,
81
- ): ReadableToken<T, K>
81
+ ): ReadableToken<T, K, E>
82
82
 
83
83
  export function findInStore(
84
84
  store: Store,
85
- familyToken: ReadableFamilyToken<any, any>,
85
+ familyToken: ReadableFamilyToken<any, any, any>,
86
86
  key: Canonical,
87
- ): ReadableToken<any> {
87
+ ): ReadableToken<any, any, any> {
88
88
  const family = withdraw(store, familyToken)
89
89
  const existingStateToken = seekInStore(store, familyToken, key)
90
90
  if (existingStateToken) {
@@ -24,35 +24,35 @@ export function getFamilyOfToken<
24
24
  K extends Canonical,
25
25
  >(store: Store, token: MutableAtomToken<T, K>): MutableAtomFamily<T, K>
26
26
 
27
- export function getFamilyOfToken<T, K extends Canonical>(
27
+ export function getFamilyOfToken<T, K extends Canonical, E>(
28
28
  store: Store,
29
- token: RegularAtomToken<T, K>,
30
- ): RegularAtomFamily<T, K>
29
+ token: RegularAtomToken<T, K, E>,
30
+ ): RegularAtomFamily<T, K, E>
31
31
 
32
- export function getFamilyOfToken<T, K extends Canonical>(
32
+ export function getFamilyOfToken<T, K extends Canonical, E>(
33
33
  store: Store,
34
- token: WritablePureSelectorToken<T, K>,
35
- ): WritablePureSelectorFamily<T, K>
34
+ token: WritablePureSelectorToken<T, K, E>,
35
+ ): WritablePureSelectorFamily<T, K, E>
36
36
 
37
- export function getFamilyOfToken<T, K extends Canonical>(
37
+ export function getFamilyOfToken<T, K extends Canonical, E>(
38
38
  store: Store,
39
- token: ReadonlyPureSelectorToken<T, K>,
40
- ): ReadonlyPureSelectorFamily<T, K>
39
+ token: ReadonlyPureSelectorToken<T, K, E>,
40
+ ): ReadonlyPureSelectorFamily<T, K, E>
41
41
 
42
- export function getFamilyOfToken<T, K extends Canonical>(
42
+ export function getFamilyOfToken<T, K extends Canonical, E>(
43
43
  store: Store,
44
- token: WritableToken<T, K>,
45
- ): WritableFamily<T, K>
44
+ token: WritableToken<T, K, E>,
45
+ ): WritableFamily<T, K, E>
46
46
 
47
- export function getFamilyOfToken<T, K extends Canonical>(
47
+ export function getFamilyOfToken<T, K extends Canonical, E>(
48
48
  store: Store,
49
- token: ReadableToken<T, K>,
50
- ): ReadableFamily<T, K>
49
+ token: ReadableToken<T, K, E>,
50
+ ): ReadableFamily<T, K, E>
51
51
 
52
52
  export function getFamilyOfToken(
53
53
  store: Store,
54
- token: ReadableToken<any, any>,
55
- ): ReadableFamily<any, any> {
54
+ token: ReadableToken<any, any, any>,
55
+ ): ReadableFamily<any, any, any> {
56
56
  return withdraw(store, {
57
57
  // biome-ignore lint/style/noNonNullAssertion: family is required
58
58
  key: token.family!.key,
@@ -8,24 +8,24 @@ import { COUNTERFEIT, mint } from "../store"
8
8
 
9
9
  export const MUST_CREATE: unique symbol = Symbol(`MUST_CREATE`)
10
10
 
11
- export function mintInStore<T, K extends Canonical, Key extends K>(
11
+ export function mintInStore<T, K extends Canonical, Key extends K, E>(
12
12
  store: Store,
13
- family: ReadableFamily<T, K>,
13
+ family: ReadableFamily<T, K, E>,
14
14
  key: Key,
15
15
  mustCreate?: typeof MUST_CREATE,
16
- ): WritableToken<T, K>
17
- export function mintInStore<T, K extends Canonical, Key extends K>(
16
+ ): WritableToken<T, Key, E>
17
+ export function mintInStore<T, K extends Canonical, Key extends K, E>(
18
18
  store: Store,
19
- family: ReadableFamily<T, K>,
19
+ family: ReadableFamily<T, K, E>,
20
20
  key: Key,
21
21
  mustCreate?: typeof MUST_CREATE,
22
- ): ReadableToken<T, K>
23
- export function mintInStore<T, K extends Canonical, Key extends K>(
22
+ ): ReadableToken<T, Key, E>
23
+ export function mintInStore<T, K extends Canonical, Key extends K, E>(
24
24
  store: Store,
25
- family: ReadableFamily<T, K>,
25
+ family: ReadableFamily<T, K, E>,
26
26
  key: Key,
27
27
  mustCreate?: typeof MUST_CREATE,
28
- ): ReadableToken<T, K> {
28
+ ): ReadableToken<T, Key, E> {
29
29
  const stringKey = stringifyJson(key)
30
30
  const molecule = store.molecules.get(stringKey)
31
31
 
@@ -43,7 +43,7 @@ export function mintInStore<T, K extends Canonical, Key extends K>(
43
43
  return mint(family, key, COUNTERFEIT)
44
44
  }
45
45
 
46
- let token: ReadableToken<T, K>
46
+ let token: ReadableToken<T, Key, E>
47
47
  if (mustCreate === MUST_CREATE) {
48
48
  store.logger.info(
49
49
  `👪`,
@@ -19,7 +19,7 @@ import type {
19
19
  import type { Canonical } from "atom.io/json"
20
20
  import { stringifyJson } from "atom.io/json"
21
21
 
22
- import type { Molecule, ReadableState } from ".."
22
+ import type { ReadableState } from ".."
23
23
  import { newest } from "../lineage"
24
24
  import type { Transceiver } from "../mutable"
25
25
  import { deposit, type Store } from "../store"
@@ -32,59 +32,59 @@ export function seekInStore<
32
32
  store: Store,
33
33
  token: MutableAtomFamilyToken<T, K>,
34
34
  key: Key,
35
- ): MutableAtomToken<T, K> | undefined
35
+ ): MutableAtomToken<T, Key> | undefined
36
36
 
37
- export function seekInStore<T, K extends Canonical, Key extends K>(
37
+ export function seekInStore<T, K extends Canonical, Key extends K, E>(
38
38
  store: Store,
39
- token: RegularAtomFamilyToken<T, K>,
39
+ token: RegularAtomFamilyToken<T, K, E>,
40
40
  key: Key,
41
- ): RegularAtomToken<T, K> | undefined
41
+ ): RegularAtomToken<T, Key, E> | undefined
42
42
 
43
- export function seekInStore<T, K extends Canonical, Key extends K>(
43
+ export function seekInStore<T, K extends Canonical, Key extends K, E>(
44
44
  store: Store,
45
- token: AtomFamilyToken<T, K>,
45
+ token: AtomFamilyToken<T, K, E>,
46
46
  key: Key,
47
- ): AtomToken<T, K> | undefined
47
+ ): AtomToken<T, Key, E> | undefined
48
48
 
49
- export function seekInStore<T, K extends Canonical, Key extends K>(
49
+ export function seekInStore<T, K extends Canonical, Key extends K, E>(
50
50
  store: Store,
51
- token: WritablePureSelectorFamilyToken<T, K>,
51
+ token: WritablePureSelectorFamilyToken<T, K, E>,
52
52
  key: Key,
53
- ): WritablePureSelectorToken<T, K> | undefined
53
+ ): WritablePureSelectorToken<T, Key, E> | undefined
54
54
 
55
- export function seekInStore<T, K extends Canonical, Key extends K>(
55
+ export function seekInStore<T, K extends Canonical, Key extends K, E>(
56
56
  store: Store,
57
- token: ReadonlyPureSelectorFamilyToken<T, K>,
57
+ token: ReadonlyPureSelectorFamilyToken<T, K, E>,
58
58
  key: Key,
59
- ): ReadonlyPureSelectorToken<T, K> | undefined
59
+ ): ReadonlyPureSelectorToken<T, Key, E> | undefined
60
60
 
61
- export function seekInStore<T, K extends Canonical, Key extends K>(
61
+ export function seekInStore<T, K extends Canonical, Key extends K, E>(
62
62
  store: Store,
63
- token: SelectorFamilyToken<T, K>,
63
+ token: SelectorFamilyToken<T, K, E>,
64
64
  key: Key,
65
- ): SelectorToken<T, K> | undefined
65
+ ): SelectorToken<T, Key, E> | undefined
66
66
 
67
- export function seekInStore<T, K extends Canonical, Key extends K>(
67
+ export function seekInStore<T, K extends Canonical, Key extends K, E>(
68
68
  store: Store,
69
- token: WritableFamilyToken<T, K>,
69
+ token: WritableFamilyToken<T, K, E>,
70
70
  key: Key,
71
- ): WritableToken<T, K> | undefined
71
+ ): WritableToken<T, Key, E> | undefined
72
72
 
73
- export function seekInStore<T, K extends Canonical, Key extends K>(
73
+ export function seekInStore<T, K extends Canonical, Key extends K, E>(
74
74
  store: Store,
75
- token: ReadableFamilyToken<T, K>,
75
+ token: ReadableFamilyToken<T, K, E>,
76
76
  key: Key,
77
- ): ReadableToken<T, K> | undefined
77
+ ): ReadableToken<T, Key, E> | undefined
78
78
 
79
79
  export function seekInStore(
80
80
  store: Store,
81
- token: ReadableFamilyToken<any, any>,
81
+ token: ReadableFamilyToken<any, any, any>,
82
82
  key: Canonical,
83
- ): ReadableToken<any> | undefined {
83
+ ): ReadableToken<any, any, any> | undefined {
84
84
  const subKey = stringifyJson(key)
85
85
  const fullKey = `${token.key}(${subKey})`
86
86
  const target = newest(store)
87
- let state: Molecule<any> | ReadableState<any> | undefined
87
+ let state: ReadableState<any, any> | undefined
88
88
  switch (token.type) {
89
89
  case `atom_family`:
90
90
  case `mutable_atom_family`:
@@ -1,15 +1,15 @@
1
- import type { ReadableToken } from "atom.io"
1
+ import type { ReadableToken, ViewOf } from "atom.io"
2
2
  import { type Canonical, stringifyJson } from "atom.io/json"
3
3
 
4
4
  import type { ReadableFamily } from ".."
5
5
  import type { Store } from "../store"
6
6
 
7
- export function getFallback<T, K extends Canonical>(
7
+ export function getFallback<T, K extends Canonical, E>(
8
8
  store: Store,
9
- token: ReadableToken<T, K>,
10
- family: ReadableFamily<T, K>,
9
+ token: ReadableToken<T, K, E>,
10
+ family: ReadableFamily<T, K, E>,
11
11
  subKey: K,
12
- ): T {
12
+ ): ViewOf<E | T> {
13
13
  const disposal = store.disposalTraces.buffer.find(
14
14
  (item) => item?.key === stringifyJson(subKey),
15
15
  )
@@ -31,7 +31,7 @@ export function getFallback<T, K extends Canonical>(
31
31
  }
32
32
  const defaultValue = new family.class()
33
33
  store.defaults.set(family.key, defaultValue)
34
- return defaultValue
34
+ return defaultValue.READONLY_VIEW
35
35
  }
36
36
  case `atom_family`: {
37
37
  if (store.defaults.has(family.key)) {
@@ -40,7 +40,7 @@ export function getFallback<T, K extends Canonical>(
40
40
  const def = family.default as (key: K) => T
41
41
  const defaultValue = def(subKey)
42
42
  store.defaults.set(family.key, defaultValue)
43
- return defaultValue
43
+ return defaultValue as ViewOf<T>
44
44
  }
45
45
  case `readonly_pure_selector_family`:
46
46
  case `writable_pure_selector_family`:
@@ -51,7 +51,7 @@ export function getFallback<T, K extends Canonical>(
51
51
  }
52
52
  const defaultValue = family.default(subKey)
53
53
  store.defaults.set(family.key, defaultValue)
54
- return defaultValue
54
+ return defaultValue as ViewOf<T>
55
55
  }
56
56
  }
57
57
  }
@@ -1,4 +1,4 @@
1
- import type { ReadableFamilyToken, ReadableToken } from "atom.io"
1
+ import type { ReadableFamilyToken, ReadableToken, ViewOf } from "atom.io"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import { type Store, withdraw } from "../store"
@@ -8,18 +8,30 @@ import { reduceReference } from "./reduce-reference"
8
8
 
9
9
  export function getFromStore<T>(store: Store, token: ReadableToken<T>): T
10
10
 
11
- export function getFromStore<T, K extends Canonical>(
11
+ export function getFromStore<T, E>(
12
12
  store: Store,
13
- token: ReadableFamilyToken<T, K>,
13
+ token: ReadableToken<T, any, E>,
14
+ ): E | T
15
+
16
+ export function getFromStore<T, K extends Canonical, E>(
17
+ store: Store,
18
+ token: ReadableFamilyToken<T, K, E>,
14
19
  key: K,
15
- ): T
20
+ ): ViewOf<E | T>
21
+
22
+ export function getFromStore<T, K extends Canonical, Key extends K, E>(
23
+ store: Store,
24
+ ...params:
25
+ | [token: ReadableFamilyToken<T, K, E>, key: Key]
26
+ | [token: ReadableToken<T, any, E>]
27
+ ): ViewOf<E | T>
16
28
 
17
- export function getFromStore(
29
+ export function getFromStore<T, K extends Canonical, Key extends K, E>(
18
30
  store: Store,
19
31
  ...params:
20
- | [token: ReadableFamilyToken<any, any>, key: Canonical]
21
- | [token: ReadableToken<any>]
22
- ): any {
32
+ | [token: ReadableFamilyToken<T, K, E>, key: Key]
33
+ | [token: ReadableToken<T, any, E>]
34
+ ): ViewOf<E | T> {
23
35
  const { token, family, subKey } = reduceReference(store, ...params)
24
36
 
25
37
  if (`counterfeit` in token && family && subKey) {