atom.io 0.27.4 → 0.28.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 (134) hide show
  1. package/data/dist/index.d.ts +31 -29
  2. package/data/dist/index.js +65 -81
  3. package/data/src/dict.ts +9 -12
  4. package/data/src/join.ts +30 -33
  5. package/data/src/struct-family.ts +17 -23
  6. package/data/src/struct.ts +9 -12
  7. package/dist/{chunk-JRENM6KL.js → chunk-BX3MTH2Z.js} +482 -385
  8. package/dist/chunk-D52JNVER.js +721 -0
  9. package/dist/chunk-EUVKUTW3.js +89 -0
  10. package/dist/index.d.ts +4 -3
  11. package/dist/index.js +35 -53
  12. package/ephemeral/dist/index.js +1 -1
  13. package/ephemeral/src/find-state.ts +1 -1
  14. package/immortal/dist/index.js +2 -2
  15. package/immortal/src/seek-state.ts +2 -2
  16. package/internal/dist/index.d.ts +141 -87
  17. package/internal/dist/index.js +1 -1
  18. package/internal/src/atom/create-regular-atom.ts +3 -3
  19. package/internal/src/atom/create-standalone-atom.ts +7 -5
  20. package/internal/src/atom/dispose-atom.ts +2 -9
  21. package/internal/src/families/create-atom-family.ts +5 -5
  22. package/internal/src/families/create-readonly-selector-family.ts +20 -9
  23. package/internal/src/families/create-regular-atom-family.ts +15 -6
  24. package/internal/src/families/create-selector-family.ts +5 -5
  25. package/internal/src/families/create-writable-selector-family.ts +20 -10
  26. package/internal/src/families/dispose-from-store.ts +43 -29
  27. package/internal/src/families/find-in-store.ts +28 -18
  28. package/internal/src/families/init-family-member.ts +9 -9
  29. package/internal/src/families/seek-in-store.ts +10 -10
  30. package/internal/src/get-state/get-from-store.ts +70 -47
  31. package/internal/src/ingest-updates/ingest-atom-update.ts +1 -1
  32. package/internal/src/ingest-updates/ingest-creation-disposal.ts +15 -6
  33. package/internal/src/molecule/create-molecule-family.ts +1 -1
  34. package/internal/src/molecule/dispose-molecule.ts +7 -18
  35. package/internal/src/molecule/grow-molecule-in-store.ts +1 -1
  36. package/internal/src/molecule/make-molecule-in-store.ts +5 -5
  37. package/internal/src/mutable/create-mutable-atom-family.ts +15 -6
  38. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  39. package/internal/src/mutable/get-json-token.ts +2 -2
  40. package/internal/src/mutable/tracker-family.ts +3 -3
  41. package/internal/src/mutable/tracker.ts +14 -18
  42. package/internal/src/pretty-print.ts +1 -16
  43. package/internal/src/selector/create-readonly-selector.ts +2 -2
  44. package/internal/src/selector/create-standalone-selector.ts +5 -5
  45. package/internal/src/selector/create-writable-selector.ts +2 -2
  46. package/internal/src/selector/dispose-selector.ts +2 -9
  47. package/internal/src/selector/register-selector.ts +9 -9
  48. package/internal/src/set-state/set-into-store.ts +23 -33
  49. package/internal/src/store/circular-buffer.ts +34 -0
  50. package/internal/src/store/counterfeit.ts +109 -0
  51. package/internal/src/store/deposit.ts +67 -13
  52. package/internal/src/store/index.ts +1 -0
  53. package/internal/src/store/store.ts +4 -1
  54. package/internal/src/store/withdraw.ts +15 -10
  55. package/internal/src/subscribe/index.ts +2 -0
  56. package/internal/src/subscribe/subscribe-in-store.ts +62 -0
  57. package/internal/src/timeline/time-travel.ts +1 -1
  58. package/internal/src/transaction/build-transaction.ts +7 -6
  59. package/introspection/dist/index.d.ts +84 -4
  60. package/introspection/dist/index.js +1 -413
  61. package/introspection/src/attach-atom-index.ts +5 -8
  62. package/introspection/src/attach-introspection-states.ts +7 -4
  63. package/introspection/src/attach-selector-index.ts +6 -8
  64. package/introspection/src/attach-timeline-family.ts +25 -28
  65. package/introspection/src/attach-timeline-index.ts +5 -8
  66. package/introspection/src/attach-transaction-index.ts +5 -8
  67. package/introspection/src/attach-transaction-logs.ts +21 -27
  68. package/introspection/src/attach-type-selectors.ts +26 -0
  69. package/introspection/src/differ.ts +167 -0
  70. package/introspection/src/index.ts +2 -0
  71. package/introspection/src/refinery.ts +100 -0
  72. package/json/dist/index.d.ts +31 -30
  73. package/json/dist/index.js +2 -80
  74. package/json/src/entries.ts +6 -0
  75. package/json/src/index.ts +47 -6
  76. package/json/src/select-json-family.ts +4 -4
  77. package/json/src/select-json.ts +6 -9
  78. package/package.json +17 -8
  79. package/react/dist/index.js +7 -7
  80. package/react/src/parse-state-overloads.ts +2 -2
  81. package/react/src/use-i.ts +1 -1
  82. package/react/src/use-json.ts +2 -2
  83. package/react/src/use-o.ts +2 -2
  84. package/react-devtools/dist/index.d.ts +1 -91
  85. package/react-devtools/dist/index.js +285 -414
  86. package/react-devtools/src/AtomIODevtools.tsx +2 -2
  87. package/react-devtools/src/StateEditor.tsx +20 -12
  88. package/react-devtools/src/StateIndex.tsx +8 -26
  89. package/react-devtools/src/TimelineIndex.tsx +3 -3
  90. package/react-devtools/src/TransactionIndex.tsx +6 -6
  91. package/react-devtools/src/Updates.tsx +1 -4
  92. package/react-devtools/src/index.ts +0 -71
  93. package/react-devtools/src/store.ts +51 -0
  94. package/realtime/dist/index.d.ts +7 -7
  95. package/realtime/dist/index.js +18 -22
  96. package/realtime/src/realtime-continuity.ts +27 -35
  97. package/realtime-client/dist/index.js +59 -65
  98. package/realtime-client/src/pull-atom-family-member.ts +1 -1
  99. package/realtime-client/src/pull-atom.ts +1 -1
  100. package/realtime-client/src/pull-mutable-atom-family-member.ts +3 -3
  101. package/realtime-client/src/pull-mutable-atom.ts +3 -3
  102. package/realtime-client/src/realtime-client-stores/client-main-store.ts +6 -6
  103. package/realtime-client/src/sync-continuity.ts +55 -53
  104. package/realtime-react/dist/index.js +3 -3
  105. package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
  106. package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
  107. package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
  108. package/realtime-server/dist/index.js +72 -36
  109. package/realtime-server/src/realtime-continuity-synchronizer.ts +57 -93
  110. package/realtime-server/src/realtime-family-provider.ts +3 -3
  111. package/realtime-server/src/realtime-mutable-family-provider.ts +5 -5
  112. package/realtime-server/src/realtime-mutable-provider.ts +2 -2
  113. package/realtime-server/src/realtime-state-provider.ts +1 -1
  114. package/realtime-server/src/realtime-state-receiver.ts +1 -1
  115. package/realtime-testing/dist/index.d.ts +2 -0
  116. package/realtime-testing/dist/index.js +57 -15
  117. package/realtime-testing/src/setup-realtime-test.tsx +66 -16
  118. package/src/atom.ts +2 -2
  119. package/src/dispose-state.ts +2 -2
  120. package/src/get-state.ts +9 -13
  121. package/src/molecule.ts +1 -1
  122. package/src/selector.ts +2 -2
  123. package/src/set-state.ts +10 -7
  124. package/src/silo.ts +29 -55
  125. package/src/subscribe.ts +3 -23
  126. package/src/timeline.ts +2 -2
  127. package/web/dist/index.d.ts +9 -0
  128. package/{dist/chunk-H6EDLPKH.js → web/dist/index.js} +5 -4
  129. package/web/package.json +13 -0
  130. package/web/src/index.ts +1 -0
  131. package/web/src/persist-sync.ts +25 -0
  132. package/dist/chunk-AK23DRMD.js +0 -21
  133. package/dist/chunk-IW6WYRS7.js +0 -140
  134. package/internal/src/families/throw-in-case-of-conflicting-family.ts +0 -18
@@ -0,0 +1,109 @@
1
+ import type {
2
+ AtomFamilyToken,
3
+ AtomToken,
4
+ MoleculeConstructor,
5
+ MoleculeFamilyToken,
6
+ MoleculeKey,
7
+ MoleculeToken,
8
+ MutableAtomFamilyToken,
9
+ MutableAtomToken,
10
+ ReadableFamilyToken,
11
+ ReadableToken,
12
+ ReadonlySelectorFamilyToken,
13
+ ReadonlySelectorToken,
14
+ RegularAtomFamilyToken,
15
+ RegularAtomToken,
16
+ SelectorFamilyToken,
17
+ SelectorToken,
18
+ WritableFamilyToken,
19
+ WritableSelectorFamilyToken,
20
+ WritableSelectorToken,
21
+ WritableToken,
22
+ } from "atom.io"
23
+ import type { Canonical, Json } from "atom.io/json"
24
+ import { stringifyJson } from "atom.io/json"
25
+
26
+ import type { Transceiver } from "../mutable"
27
+
28
+ export const FAMILY_MEMBER_TOKEN_TYPES = {
29
+ atom_family: `atom`,
30
+ mutable_atom_family: `mutable_atom`,
31
+ selector_family: `selector`,
32
+ readonly_selector_family: `readonly_selector`,
33
+ molecule_family: `molecule`,
34
+ } as const
35
+
36
+ export function counterfeit<
37
+ T extends Transceiver<any>,
38
+ J extends Json.Serializable,
39
+ K extends Canonical,
40
+ Key extends K,
41
+ >(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>
42
+
43
+ export function counterfeit<T, K extends Canonical, Key extends K>(
44
+ token: RegularAtomFamilyToken<T, K>,
45
+ key: Key,
46
+ ): RegularAtomToken<T>
47
+
48
+ export function counterfeit<T, K extends Canonical, Key extends K>(
49
+ token: AtomFamilyToken<T, K>,
50
+ key: Key,
51
+ ): AtomToken<T>
52
+
53
+ export function counterfeit<T, K extends Canonical, Key extends K>(
54
+ token: WritableSelectorFamilyToken<T, K>,
55
+ key: Key,
56
+ ): WritableSelectorToken<T>
57
+
58
+ export function counterfeit<T, K extends Canonical, Key extends K>(
59
+ token: ReadonlySelectorFamilyToken<T, K>,
60
+ key: Key,
61
+ ): ReadonlySelectorToken<T>
62
+
63
+ export function counterfeit<T, K extends Canonical, Key extends K>(
64
+ token: SelectorFamilyToken<T, K>,
65
+ key: Key,
66
+ ): SelectorToken<T>
67
+
68
+ export function counterfeit<T, K extends Canonical, Key extends K>(
69
+ token: WritableFamilyToken<T, K>,
70
+ key: Key,
71
+ ): WritableToken<T>
72
+
73
+ export function counterfeit<T, K extends Canonical, Key extends K>(
74
+ token: ReadableFamilyToken<T, K>,
75
+ key: Key,
76
+ ): ReadableToken<T>
77
+
78
+ export function counterfeit<M extends MoleculeConstructor>(
79
+ token: MoleculeFamilyToken<M>,
80
+ key: MoleculeKey<M>,
81
+ ): MoleculeKey<M>
82
+
83
+ export function counterfeit(
84
+ token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
85
+ key: Canonical,
86
+ ): MoleculeToken<any> | ReadableToken<any> {
87
+ const subKey = stringifyJson(key)
88
+ const fullKey = `${token.key}(${subKey})`
89
+ const type = FAMILY_MEMBER_TOKEN_TYPES[token.type]
90
+ const stateToken = {
91
+ key: fullKey,
92
+ type,
93
+ } satisfies MoleculeToken<any> | ReadableToken<any>
94
+ if (type === `molecule`) {
95
+ Object.assign(stateToken, {
96
+ key,
97
+ family: token,
98
+ })
99
+ } else {
100
+ Object.assign(stateToken, {
101
+ family: {
102
+ key: token.key,
103
+ subKey,
104
+ },
105
+ })
106
+ }
107
+ Object.assign(stateToken, { counterfeit: true })
108
+ return stateToken
109
+ }
@@ -1,31 +1,47 @@
1
1
  import type {
2
+ AtomFamilyToken,
2
3
  AtomToken,
3
4
  MoleculeConstructor,
4
5
  MoleculeFamily,
5
6
  MoleculeFamilyToken,
6
7
  MoleculeToken,
8
+ MutableAtomFamilyToken,
7
9
  MutableAtomToken,
10
+ ReadableFamilyToken,
8
11
  ReadableToken,
12
+ ReadonlySelectorFamilyToken,
9
13
  ReadonlySelectorToken,
14
+ RegularAtomFamilyToken,
10
15
  RegularAtomToken,
16
+ SelectorFamilyToken,
11
17
  SelectorToken,
12
18
  TransactionToken,
19
+ WritableFamilyToken,
20
+ WritableSelectorFamilyToken,
13
21
  WritableSelectorToken,
14
22
  WritableToken,
15
23
  } from "atom.io"
16
- import type { Canonical } from "atom.io/json"
24
+ import type { Canonical, Json } from "atom.io/json"
17
25
 
18
26
  import type {
19
27
  Atom,
28
+ AtomFamily,
20
29
  Func,
21
30
  Molecule,
22
31
  MutableAtom,
32
+ MutableAtomFamily,
33
+ ReadableFamily,
23
34
  ReadableState,
24
35
  ReadonlySelector,
36
+ ReadonlySelectorFamily,
25
37
  RegularAtom,
38
+ RegularAtomFamily,
26
39
  Selector,
40
+ SelectorFamily,
27
41
  Transceiver,
42
+ WritableFamily,
28
43
  WritableSelector,
44
+ WritableSelectorFamily,
29
45
  WritableState,
30
46
  } from ".."
31
47
  import type { Transaction } from "../transaction"
@@ -39,37 +55,75 @@ export function deposit<T>(state: WritableSelector<T>): WritableSelectorToken<T>
39
55
  export function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>
40
56
  export function deposit<T>(state: Selector<T>): SelectorToken<T>
41
57
  export function deposit<T>(state: WritableState<T>): WritableToken<T>
58
+ export function deposit<T>(state: ReadableState<T>): ReadableToken<T>
59
+
60
+ export function deposit<T, K extends Canonical>(
61
+ state: RegularAtomFamily<T, K>,
62
+ ): RegularAtomFamilyToken<T, K>
63
+ export function deposit<
64
+ T extends Transceiver<any>,
65
+ J extends Json.Serializable,
66
+ K extends Canonical,
67
+ >(state: MutableAtomFamily<T, J, K>): MutableAtomFamilyToken<T, J, K>
68
+ export function deposit<T>(state: AtomFamily<T, any>): AtomFamilyToken<T, any>
69
+ export function deposit<T>(
70
+ state: WritableSelectorFamily<T, any>,
71
+ ): WritableSelectorFamilyToken<T, any>
72
+ export function deposit<T>(
73
+ state: ReadonlySelectorFamily<T, any>,
74
+ ): ReadonlySelectorFamilyToken<T, any>
75
+ export function deposit<T>(
76
+ state: SelectorFamily<T, any>,
77
+ ): SelectorFamilyToken<T, any>
78
+ export function deposit<T>(
79
+ state: WritableFamily<T, any>,
80
+ ): WritableFamilyToken<T, any>
81
+ export function deposit<T>(
82
+ state: ReadableFamily<T, any>,
83
+ ): ReadableFamilyToken<T, any>
84
+
42
85
  export function deposit<M extends MoleculeConstructor>(
43
86
  state: MoleculeFamily<M>,
44
87
  ): MoleculeFamilyToken<M>
45
88
  export function deposit<M extends MoleculeConstructor>(
46
89
  state: Molecule<M>,
47
90
  ): MoleculeToken<M>
91
+
48
92
  export function deposit<T extends Func>(
49
93
  state: Transaction<T>,
50
94
  ): TransactionToken<T>
51
- export function deposit<T>(state: ReadableState<T>): ReadableToken<T>
95
+
52
96
  export function deposit(
53
97
  state: Molecule<any> | ReadableState<any>,
54
98
  ): MoleculeToken<any> | ReadableToken<any>
55
99
 
56
- export function deposit<T>(
100
+ export function deposit(
101
+ state:
102
+ | Molecule<any>
103
+ | MoleculeFamily<any>
104
+ | ReadableFamily<any, any>
105
+ | ReadableState<any>
106
+ | Transaction<Func>,
107
+ ):
108
+ | MoleculeFamilyToken<any>
109
+ | MoleculeToken<any>
110
+ | ReadableFamilyToken<any, any>
111
+ | ReadableToken<any>
112
+ | TransactionToken<Func>
113
+
114
+ export function deposit(
57
115
  state:
58
116
  | Molecule<any>
59
117
  | MoleculeFamily<any>
60
- | ReadableState<T>
61
- | ReadonlySelector<T>
62
- | RegularAtom<T>
63
- | Transaction<T extends Func ? T : never>
64
- | WritableSelector<T>
65
- | (T extends Transceiver<any> ? MutableAtom<T, any> : never),
118
+ | ReadableFamily<any, any>
119
+ | ReadableState<any>
120
+ | Transaction<Func>,
66
121
  ):
67
122
  | MoleculeFamilyToken<any>
68
123
  | MoleculeToken<any>
69
- | MutableAtomToken<T extends Transceiver<any> ? T : never, any>
70
- | RegularAtomToken<T>
71
- | SelectorToken<T>
72
- | TransactionToken<T extends Func ? T : never> {
124
+ | ReadableFamilyToken<any, any>
125
+ | ReadableToken<any>
126
+ | TransactionToken<Func> {
73
127
  const token = {
74
128
  key: state.key,
75
129
  type: state.type,
@@ -1,3 +1,4 @@
1
+ export * from "./counterfeit"
1
2
  export * from "./deposit"
2
3
  export * from "./store"
3
4
  export * from "./withdraw"
@@ -36,6 +36,7 @@ import type {
36
36
  TransactionProgress,
37
37
  } from "../transaction"
38
38
  import { isRootStore } from "../transaction"
39
+ import { CircularBuffer } from "./circular-buffer"
39
40
 
40
41
  export class Store implements Lineage {
41
42
  public parent: Store | null = null
@@ -94,6 +95,8 @@ export class Store implements Lineage {
94
95
  cardinality: `1:n`,
95
96
  })
96
97
 
98
+ public disposalTraces = new CircularBuffer<{ key: string; trace: string }>(100)
99
+
97
100
  public molecules = new Map<string, Molecule<any>>()
98
101
  public moleculeFamilies = new Map<string, MoleculeFamily<any>>()
99
102
  public moleculeInProgress: string | null = null
@@ -176,7 +179,7 @@ export class Store implements Lineage {
176
179
  }
177
180
  atom.install(this)
178
181
  if (atom.type === `mutable_atom`) {
179
- const originalJsonToken = getJsonToken(atom, store)
182
+ const originalJsonToken = getJsonToken(store, atom)
180
183
  const originalUpdateToken = getUpdateToken(atom)
181
184
  mutableHelpers.add(originalJsonToken.key)
182
185
  mutableHelpers.add(originalUpdateToken.key)
@@ -155,19 +155,24 @@ export function withdraw<T>(
155
155
  token: TimelineToken<T>,
156
156
  store: Store,
157
157
  ): Timeline<T extends TimelineManageable ? T : never>
158
- export function withdraw<T>(
158
+
159
+ export function withdraw<T, M extends MoleculeConstructor>(
160
+ token: MoleculeToken<M> | ReadableToken<T>,
161
+ store: Store,
162
+ ): Molecule<M> | ReadableState<T>
163
+
164
+ export function withdraw(
159
165
  token:
160
166
  | MoleculeFamilyToken<any>
161
167
  | MoleculeToken<any>
162
- | RegularAtomFamilyToken<T, any>
163
- | RegularAtomToken<T>
164
- | SelectorFamilyToken<T, any>
165
- | SelectorToken<T>
166
- | TimelineToken<T>
167
- | TransactionToken<T extends Func ? T : never>
168
- | (T extends Transceiver<any>
169
- ? MutableAtomFamilyToken<T, any, any> | MutableAtomToken<T, any>
170
- : never),
168
+ | MutableAtomFamilyToken<any, any, any>
169
+ | MutableAtomToken<any, any>
170
+ | RegularAtomFamilyToken<any, any>
171
+ | RegularAtomToken<any>
172
+ | SelectorFamilyToken<any, any>
173
+ | SelectorToken<any>
174
+ | TimelineToken<any>
175
+ | TransactionToken<any>,
171
176
  store: Store,
172
177
  ): Withdrawable {
173
178
  let withdrawn: Withdrawable | undefined
@@ -1,3 +1,5 @@
1
+ export * from "./recall-state"
2
+ export * from "./subscribe-in-store"
1
3
  export * from "./subscribe-to-root-atoms"
2
4
  export * from "./subscribe-to-state"
3
5
  export * from "./subscribe-to-timeline"
@@ -0,0 +1,62 @@
1
+ import type {
2
+ ReadableToken,
3
+ TimelineManageable,
4
+ TimelineToken,
5
+ TimelineUpdate,
6
+ TransactionToken,
7
+ TransactionUpdateHandler,
8
+ UpdateHandler,
9
+ } from "atom.io"
10
+ import type { Func, Store } from "atom.io/internal"
11
+ import {
12
+ arbitrary,
13
+ subscribeToState,
14
+ subscribeToTimeline,
15
+ subscribeToTransaction,
16
+ } from "atom.io/internal"
17
+
18
+ export function subscribeInStore<T>(
19
+ store: Store,
20
+ token: ReadableToken<T>,
21
+ handleUpdate: UpdateHandler<T>,
22
+ key?: string,
23
+ ): () => void
24
+ export function subscribeInStore<F extends Func>(
25
+ store: Store,
26
+ token: TransactionToken<F>,
27
+ handleUpdate: TransactionUpdateHandler<F>,
28
+ key?: string,
29
+ ): () => void
30
+ export function subscribeInStore<M extends TimelineManageable>(
31
+ store: Store,
32
+ token: TimelineToken<M>,
33
+ handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,
34
+ key?: string,
35
+ ): () => void
36
+ export function subscribeInStore<M extends TimelineManageable>(
37
+ store: Store,
38
+ token: ReadableToken<any> | TimelineToken<M> | TransactionToken<any>,
39
+ handleUpdate:
40
+ | TransactionUpdateHandler<any>
41
+ | UpdateHandler<any>
42
+ | ((update: TimelineUpdate<M> | `redo` | `undo`) => void),
43
+ key?: string,
44
+ ): () => void
45
+ export function subscribeInStore(
46
+ store: Store,
47
+ token: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,
48
+ handleUpdate: (update: any) => void,
49
+ key: string = arbitrary(),
50
+ ): () => void {
51
+ switch (token.type) {
52
+ case `atom`:
53
+ case `mutable_atom`:
54
+ case `readonly_selector`:
55
+ case `selector`:
56
+ return subscribeToState(token, handleUpdate, key, store)
57
+ case `transaction`:
58
+ return subscribeToTransaction(token, handleUpdate, key, store)
59
+ case `timeline`:
60
+ return subscribeToTimeline(token, handleUpdate, key, store)
61
+ }
62
+ }
@@ -12,9 +12,9 @@ import {
12
12
  import type { Store } from "../store"
13
13
 
14
14
  export const timeTravel = (
15
+ store: Store,
15
16
  action: `redo` | `undo`,
16
17
  token: TimelineToken<any>,
17
- store: Store,
18
18
  ): void => {
19
19
  store.logger.info(
20
20
  action === `redo` ? `⏩` : `⏪`,
@@ -49,6 +49,7 @@ export const buildTransaction = (
49
49
  selectors: new LazyMap(parent.selectors),
50
50
  valueMap: new LazyMap(parent.valueMap),
51
51
  defaults: parent.defaults,
52
+ disposalTraces: store.disposalTraces.copy(),
52
53
  molecules: new LazyMap(parent.molecules),
53
54
  moleculeFamilies: new LazyMap(parent.moleculeFamilies),
54
55
  moleculeInProgress: parent.moleculeInProgress,
@@ -68,19 +69,19 @@ export const buildTransaction = (
68
69
  },
69
70
  toolkit: {
70
71
  get: ((...ps: Parameters<typeof getState>) =>
71
- getFromStore(...ps, child)) as typeof getState,
72
+ getFromStore(child, ...ps)) as typeof getState,
72
73
  set: ((...ps: Parameters<typeof setState>) => {
73
- setIntoStore(...ps, child)
74
+ setIntoStore(child, ...ps)
74
75
  }) as typeof setState,
75
76
  run: (token, identifier = arbitrary()) =>
76
77
  actUponStore(token, identifier, child),
77
- find: ((token, k) => findInStore(token, k, child)) as typeof findState,
78
- seek: ((token, k) => seekInStore(token, k, child)) as typeof seekState,
79
- json: (token) => getJsonToken(token, child),
78
+ find: ((token, k) => findInStore(child, token, k)) as typeof findState,
79
+ seek: ((token, k) => seekInStore(child, token, k)) as typeof seekState,
80
+ json: (token) => getJsonToken(child, token),
80
81
  make: (context, family, k, ...args) =>
81
82
  makeMoleculeInStore(child, context, family, k, ...args),
82
83
  dispose: ((...ps: Parameters<typeof disposeState>) => {
83
- disposeFromStore(...ps, child)
84
+ disposeFromStore(child, ...ps)
84
85
  }) as typeof disposeState,
85
86
  env: () => getEnvironmentData(child),
86
87
  },
@@ -1,6 +1,7 @@
1
1
  import { AtomToken, SelectorToken, ReadonlySelectorToken, TransactionToken, ReadonlySelectorFamilyToken, TransactionUpdate, TimelineToken, ReadableToken } from 'atom.io';
2
2
  import * as Internal from 'atom.io/internal';
3
- import { Func, Timeline } from 'atom.io/internal';
3
+ import { Func, Timeline, Flat } from 'atom.io/internal';
4
+ import { Json } from 'atom.io/json';
4
5
 
5
6
  type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown>>;
6
7
 
@@ -10,9 +11,10 @@ declare const attachIntrospectionStates: (store?: Internal.Store) => {
10
11
  atomIndex: ReadonlySelectorToken<AtomTokenIndex>;
11
12
  selectorIndex: ReadonlySelectorToken<SelectorTokenIndex>;
12
13
  transactionIndex: ReadonlySelectorToken<TransactionToken<Func>[]>;
13
- findTransactionLogState: ReadonlySelectorFamilyToken<TransactionUpdate<Func>[], string>;
14
+ transactionLogSelectors: ReadonlySelectorFamilyToken<TransactionUpdate<Func>[], string>;
14
15
  timelineIndex: ReadonlySelectorToken<TimelineToken<any>[]>;
15
- findTimelineState: ReadonlySelectorFamilyToken<Timeline<any>, string>;
16
+ timelineSelectors: ReadonlySelectorFamilyToken<Timeline<any>, string>;
17
+ typeSelectors: ReadonlySelectorFamilyToken<string, string>;
16
18
  };
17
19
 
18
20
  type ListResourcesParam = {
@@ -52,10 +54,88 @@ declare class Auditor {
52
54
  [Symbol.dispose](): void;
53
55
  }
54
56
 
57
+ type Refinement<A, B extends A> = (a: A) => a is B;
58
+ type ClassSignature = abstract new (...args: any) => any;
59
+ type RefinementStrategy = ClassSignature | Refinement<unknown, any>;
60
+ type Supported<Refine extends RefinementStrategy> = Refine extends Refinement<unknown, infer T> ? T : Refine extends ClassSignature ? InstanceType<Refine> : never;
61
+ type RefinementSupport = Record<string, RefinementStrategy>;
62
+ declare class Refinery<SupportedTypes extends RefinementSupport> {
63
+ supported: SupportedTypes;
64
+ constructor(supported: SupportedTypes);
65
+ refine<T>(input: T): Flat<{
66
+ [K in keyof SupportedTypes]: T extends Supported<SupportedTypes[K]> ? {
67
+ type: K;
68
+ data: Supported<SupportedTypes[K]>;
69
+ } : Supported<SupportedTypes[K]> extends T ? {
70
+ type: K;
71
+ data: Supported<SupportedTypes[K]>;
72
+ } : never;
73
+ }>[keyof SupportedTypes] | (T extends Supported<SupportedTypes[keyof SupportedTypes]> ? never : null);
74
+ }
75
+ declare const primitiveRefinery: Refinery<{
76
+ number: (input: unknown) => input is number;
77
+ string: (input: unknown) => input is string;
78
+ boolean: (input: unknown) => input is boolean;
79
+ null: (input: unknown) => input is null;
80
+ }>;
81
+ declare const jsonTreeRefinery: Refinery<{
82
+ object: (input: unknown) => input is Json.Tree.Object;
83
+ array: (input: unknown) => input is Json.Tree.Array;
84
+ }>;
85
+ declare const jsonRefinery: Refinery<{
86
+ object: (input: unknown) => input is Json.Tree.Object;
87
+ array: (input: unknown) => input is Json.Tree.Array;
88
+ number: (input: unknown) => input is number;
89
+ string: (input: unknown) => input is string;
90
+ boolean: (input: unknown) => input is boolean;
91
+ null: (input: unknown) => input is null;
92
+ }>;
93
+ type JsonType = keyof typeof jsonRefinery.supported;
94
+ declare const discoverType: (input: unknown) => JsonType | `Map` | `Set` | `undefined` | (string & {});
95
+
96
+ declare function diffNumber(a: number, b: number): Delta;
97
+ declare function diffString(a: string, b: string): Delta;
98
+ declare function diffBoolean(a: boolean, b: boolean): Delta;
99
+ declare function diffObject(a: Json.Tree.Object, b: Json.Tree.Object, recurse: Diff<unknown>): Delta;
100
+ declare function diffArray(a: Json.Tree.Array, b: Json.Tree.Array, recurse: Diff<unknown>): Delta;
101
+ type Delta = {
102
+ summary: string;
103
+ added?: [path: string, addedStringifiedValue: string][];
104
+ removed?: [path: string, removedStringifiedValue: string][];
105
+ changed?: [path: string, delta: Delta][];
106
+ };
107
+ type Diff<T> = (a: T, b: T) => Delta;
108
+ type DiffTree<T> = (a: T, b: T, recurse: Differ<any, any>[`diff`]) => Delta;
109
+ declare class Differ<Leaf extends Record<string, any>, Tree extends Record<string, any>> {
110
+ leafRefinery: Refinery<Leaf>;
111
+ treeRefinery: Refinery<Tree>;
112
+ leafDiffers: {
113
+ [KL in keyof Leaf]: Diff<Supported<Leaf[KL]>>;
114
+ };
115
+ treeDiffers: {
116
+ [KT in keyof Tree]: DiffTree<Supported<Tree[KT]>>;
117
+ };
118
+ constructor(leafRefinery: Refinery<Leaf>, treeRefinery: Refinery<Tree>, diffFunctions: {
119
+ [KT in keyof Tree]: DiffTree<Supported<Tree[KT]>>;
120
+ } & {
121
+ [KL in keyof Leaf]: Diff<Supported<Leaf[KL]>>;
122
+ });
123
+ diff(a: unknown, b: unknown): Delta;
124
+ }
125
+ declare const prettyJson: Differ<{
126
+ number: (input: unknown) => input is number;
127
+ string: (input: unknown) => input is string;
128
+ boolean: (input: unknown) => input is boolean;
129
+ null: (input: unknown) => input is null;
130
+ }, {
131
+ object: (input: unknown) => input is Json.Tree.Object;
132
+ array: (input: unknown) => input is Json.Tree.Array;
133
+ }>;
134
+
55
135
  type FamilyNode<Token extends ReadableToken<unknown>> = {
56
136
  key: string;
57
137
  familyMembers: Map<string, Token>;
58
138
  };
59
139
  type WritableTokenIndex<Token extends ReadableToken<unknown>> = Map<string, FamilyNode<Token> | Token>;
60
140
 
61
- export { Auditor, type FamilyNode, type ListResourcesParam, type WritableTokenIndex, attachIntrospectionStates };
141
+ export { Auditor, type ClassSignature, Differ, type FamilyNode, type JsonType, type ListResourcesParam, type Refinement, type RefinementStrategy, type RefinementSupport, Refinery, type Supported, type WritableTokenIndex, attachIntrospectionStates, diffArray, diffBoolean, diffNumber, diffObject, diffString, discoverType, jsonRefinery, jsonTreeRefinery, prettyJson, primitiveRefinery };