atom.io 0.6.8 → 0.7.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 (214) hide show
  1. package/README.md +21 -2
  2. package/dist/index.d.mts +42 -461
  3. package/dist/index.d.ts +42 -461
  4. package/dist/index.js +128 -1792
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +75 -1742
  7. package/dist/index.mjs.map +1 -1
  8. package/internal/dist/index.d.mts +342 -0
  9. package/internal/dist/index.d.ts +342 -0
  10. package/internal/dist/index.js +1873 -0
  11. package/internal/dist/index.js.map +1 -0
  12. package/internal/dist/index.mjs +1798 -0
  13. package/internal/dist/index.mjs.map +1 -0
  14. package/internal/package.json +15 -0
  15. package/internal/src/atom/create-atom.ts +75 -0
  16. package/internal/src/atom/delete-atom.ts +10 -0
  17. package/internal/src/atom/index.ts +3 -0
  18. package/{src/internal → internal/src/atom}/is-default.ts +4 -2
  19. package/internal/src/caching.ts +21 -0
  20. package/internal/src/families/create-atom-family.ts +59 -0
  21. package/internal/src/families/create-readonly-selector-family.ts +45 -0
  22. package/internal/src/families/create-selector-family.ts +67 -0
  23. package/internal/src/families/index.ts +3 -0
  24. package/internal/src/get-state-internal.ts +23 -0
  25. package/internal/src/index.ts +13 -0
  26. package/internal/src/mutable/create-mutable-atom-family.ts +25 -0
  27. package/internal/src/mutable/create-mutable-atom.ts +49 -0
  28. package/internal/src/mutable/get-json-token.ts +22 -0
  29. package/internal/src/mutable/get-update-token.ts +20 -0
  30. package/internal/src/mutable/index.ts +17 -0
  31. package/internal/src/mutable/is-atom-token-mutable.ts +7 -0
  32. package/internal/src/mutable/tracker-family.ts +61 -0
  33. package/internal/src/mutable/tracker.ts +164 -0
  34. package/internal/src/mutable/transceiver.ts +110 -0
  35. package/internal/src/operation.ts +68 -0
  36. package/{src/internal → internal/src}/selector/create-read-write-selector.ts +10 -13
  37. package/{src/internal → internal/src}/selector/create-readonly-selector.ts +9 -8
  38. package/internal/src/selector/create-selector.ts +65 -0
  39. package/{src/internal → internal/src}/selector/index.ts +1 -0
  40. package/internal/src/selector/lookup-selector-sources.ts +20 -0
  41. package/{src/internal → internal/src}/selector/register-selector.ts +13 -9
  42. package/{src/internal → internal/src}/selector/trace-selector-atoms.ts +4 -2
  43. package/{src/internal → internal/src}/selector/update-selector-atoms.ts +4 -3
  44. package/internal/src/set-state/become.ts +10 -0
  45. package/internal/src/set-state/copy-mutable-if-needed.ts +23 -0
  46. package/internal/src/set-state/copy-mutable-in-transaction.ts +59 -0
  47. package/internal/src/set-state/copy-mutable-into-new-store.ts +34 -0
  48. package/internal/src/set-state/emit-update.ts +23 -0
  49. package/internal/src/set-state/evict-downstream.ts +39 -0
  50. package/internal/src/set-state/index.ts +2 -0
  51. package/internal/src/set-state/set-atom-state.ts +38 -0
  52. package/internal/src/set-state/set-selector-state.ts +19 -0
  53. package/internal/src/set-state/set-state-internal.ts +18 -0
  54. package/internal/src/set-state/stow-update.ts +42 -0
  55. package/internal/src/store/deposit.ts +43 -0
  56. package/internal/src/store/index.ts +5 -0
  57. package/internal/src/store/lookup.ts +26 -0
  58. package/internal/src/store/store.ts +154 -0
  59. package/internal/src/store/withdraw-new-family-member.ts +53 -0
  60. package/internal/src/store/withdraw.ts +113 -0
  61. package/internal/src/subject.ts +21 -0
  62. package/internal/src/subscribe/index.ts +1 -0
  63. package/internal/src/subscribe/recall-state.ts +19 -0
  64. package/internal/src/subscribe/subscribe-to-root-atoms.ts +47 -0
  65. package/{src/internal → internal/src}/timeline/add-atom-to-timeline.ts +50 -29
  66. package/internal/src/timeline/index.ts +3 -0
  67. package/{src/internal → internal/src/timeline}/time-travel-internal.ts +6 -6
  68. package/{src/internal → internal/src/timeline}/timeline-internal.ts +20 -12
  69. package/{src/internal → internal/src}/transaction/abort-transaction.ts +1 -1
  70. package/{src/internal → internal/src}/transaction/apply-transaction.ts +25 -18
  71. package/{src/internal → internal/src}/transaction/build-transaction.ts +12 -6
  72. package/{src/internal → internal/src}/transaction/index.ts +3 -2
  73. package/{src/internal → internal/src}/transaction/redo-transaction.ts +4 -5
  74. package/{src/internal → internal/src/transaction}/transaction-internal.ts +16 -13
  75. package/{src/internal → internal/src}/transaction/undo-transaction.ts +4 -5
  76. package/introspection/dist/index.d.mts +12 -260
  77. package/introspection/dist/index.d.ts +12 -260
  78. package/introspection/dist/index.js +125 -140
  79. package/introspection/dist/index.js.map +1 -1
  80. package/introspection/dist/index.mjs +103 -116
  81. package/introspection/dist/index.mjs.map +1 -1
  82. package/{src/introspection → introspection/src}/attach-atom-index.ts +41 -30
  83. package/{src/introspection → introspection/src}/attach-introspection-states.ts +6 -10
  84. package/introspection/src/attach-selector-index.ts +90 -0
  85. package/{src/introspection → introspection/src}/attach-timeline-family.ts +16 -16
  86. package/introspection/src/attach-timeline-index.ts +38 -0
  87. package/introspection/src/attach-transaction-index.ts +40 -0
  88. package/{src/introspection → introspection/src}/attach-transaction-logs.ts +11 -8
  89. package/json/dist/index.d.mts +41 -2
  90. package/json/dist/index.d.ts +41 -2
  91. package/json/dist/index.js +88 -48
  92. package/json/dist/index.js.map +1 -1
  93. package/json/dist/index.mjs +76 -13
  94. package/json/dist/index.mjs.map +1 -1
  95. package/json/src/index.ts +5 -0
  96. package/json/src/select-json-family.ts +35 -0
  97. package/json/src/select-json.ts +22 -0
  98. package/package.json +105 -57
  99. package/react/dist/index.d.mts +9 -17
  100. package/react/dist/index.d.ts +9 -17
  101. package/react/dist/index.js +45 -77
  102. package/react/dist/index.js.map +1 -1
  103. package/react/dist/index.mjs +18 -34
  104. package/react/dist/index.mjs.map +1 -1
  105. package/react/src/store-context.tsx +12 -0
  106. package/react/src/store-hooks.ts +36 -0
  107. package/react-devtools/dist/index.css +1 -1
  108. package/react-devtools/dist/index.css.map +1 -1
  109. package/react-devtools/dist/index.d.mts +199 -230
  110. package/react-devtools/dist/index.d.ts +199 -230
  111. package/react-devtools/dist/index.js +610 -2466
  112. package/react-devtools/dist/index.js.map +1 -1
  113. package/react-devtools/dist/index.mjs +543 -2401
  114. package/react-devtools/dist/index.mjs.map +1 -1
  115. package/{src/react-devtools → react-devtools/src}/AtomIODevtools.tsx +5 -3
  116. package/{src/react-devtools → react-devtools/src}/Button.tsx +2 -3
  117. package/{src/react-devtools → react-devtools/src}/StateEditor.tsx +3 -2
  118. package/{src/react-devtools → react-devtools/src}/StateIndex.tsx +7 -4
  119. package/{src/react-devtools → react-devtools/src}/TimelineIndex.tsx +7 -11
  120. package/{src/react-devtools → react-devtools/src}/TransactionIndex.tsx +4 -4
  121. package/{src/react-devtools → react-devtools/src}/Updates.tsx +9 -4
  122. package/{src/react-devtools → react-devtools/src}/index.ts +5 -5
  123. package/realtime-react/dist/index.d.mts +9 -25
  124. package/realtime-react/dist/index.d.ts +9 -25
  125. package/realtime-react/dist/index.js +75 -193
  126. package/realtime-react/dist/index.js.map +1 -1
  127. package/realtime-react/dist/index.mjs +44 -148
  128. package/realtime-react/dist/index.mjs.map +1 -1
  129. package/realtime-react/src/index.ts +7 -0
  130. package/{src/realtime-react → realtime-react/src}/realtime-context.tsx +3 -4
  131. package/realtime-react/src/use-pull-family-member.ts +15 -0
  132. package/realtime-react/src/use-pull-mutable-family-member.ts +20 -0
  133. package/realtime-react/src/use-pull-mutable.ts +17 -0
  134. package/realtime-react/src/use-pull.ts +15 -0
  135. package/realtime-react/src/use-push.ts +19 -0
  136. package/realtime-react/src/use-server-action.ts +18 -0
  137. package/realtime-testing/dist/index.d.mts +49 -0
  138. package/realtime-testing/dist/index.d.ts +49 -0
  139. package/realtime-testing/dist/index.js +147 -0
  140. package/realtime-testing/dist/index.js.map +1 -0
  141. package/realtime-testing/dist/index.mjs +116 -0
  142. package/realtime-testing/dist/index.mjs.map +1 -0
  143. package/{src/realtime-testing → realtime-testing/src}/setup-realtime-test.tsx +10 -8
  144. package/src/atom.ts +64 -8
  145. package/src/index.ts +36 -29
  146. package/src/logger.ts +7 -7
  147. package/src/selector.ts +5 -5
  148. package/src/silo.ts +49 -43
  149. package/src/subscribe.ts +27 -22
  150. package/src/timeline.ts +9 -4
  151. package/src/transaction.ts +3 -4
  152. package/transceivers/set-rtx/dist/index.d.mts +39 -0
  153. package/transceivers/set-rtx/dist/index.d.ts +39 -0
  154. package/transceivers/set-rtx/dist/index.js +213 -0
  155. package/transceivers/set-rtx/dist/index.js.map +1 -0
  156. package/transceivers/set-rtx/dist/index.mjs +211 -0
  157. package/transceivers/set-rtx/dist/index.mjs.map +1 -0
  158. package/{realtime → transceivers/set-rtx}/package.json +1 -1
  159. package/transceivers/set-rtx/src/index.ts +1 -0
  160. package/transceivers/set-rtx/src/set-rtx.ts +242 -0
  161. package/realtime/dist/index.d.mts +0 -25
  162. package/realtime/dist/index.d.ts +0 -25
  163. package/realtime/dist/index.js +0 -190
  164. package/realtime/dist/index.js.map +0 -1
  165. package/realtime/dist/index.mjs +0 -151
  166. package/realtime/dist/index.mjs.map +0 -1
  167. package/src/internal/atom-internal.ts +0 -54
  168. package/src/internal/families-internal.ts +0 -144
  169. package/src/internal/get.ts +0 -129
  170. package/src/internal/index.ts +0 -15
  171. package/src/internal/operation.ts +0 -139
  172. package/src/internal/selector/lookup-selector-sources.ts +0 -16
  173. package/src/internal/selector-internal.ts +0 -58
  174. package/src/internal/set.ts +0 -99
  175. package/src/internal/store.ts +0 -151
  176. package/src/internal/subscribe-internal.ts +0 -88
  177. package/src/internal/timeline/index.ts +0 -1
  178. package/src/introspection/attach-selector-index.ts +0 -77
  179. package/src/introspection/attach-timeline-index.ts +0 -36
  180. package/src/introspection/attach-transaction-index.ts +0 -38
  181. package/src/json/index.ts +0 -1
  182. package/src/json/select-json.ts +0 -18
  183. package/src/react/store-context.tsx +0 -13
  184. package/src/react/store-hooks.ts +0 -47
  185. package/src/react-explorer/AtomIOExplorer.tsx +0 -218
  186. package/src/react-explorer/explorer-effects.ts +0 -20
  187. package/src/react-explorer/explorer-states.ts +0 -217
  188. package/src/react-explorer/index.ts +0 -23
  189. package/src/react-explorer/space-states.ts +0 -72
  190. package/src/react-explorer/view-states.ts +0 -41
  191. package/src/realtime/README.md +0 -33
  192. package/src/realtime/hook-composition/expose-family.ts +0 -101
  193. package/src/realtime/hook-composition/expose-single.ts +0 -38
  194. package/src/realtime/hook-composition/expose-timeline.ts +0 -60
  195. package/src/realtime/hook-composition/index.ts +0 -12
  196. package/src/realtime/hook-composition/receive-state.ts +0 -29
  197. package/src/realtime/hook-composition/receive-transaction.ts +0 -18
  198. package/src/realtime/index.ts +0 -1
  199. package/src/realtime-react/index.ts +0 -3
  200. package/src/realtime-react/realtime-hooks.ts +0 -39
  201. package/src/realtime-react/realtime-state.ts +0 -10
  202. package/src/realtime-react/use-pull-family-member.ts +0 -26
  203. package/src/realtime-react/use-pull-family.ts +0 -24
  204. package/src/realtime-react/use-pull.ts +0 -24
  205. package/src/realtime-react/use-push.ts +0 -27
  206. package/src/realtime-react/use-server-action.ts +0 -33
  207. package/src/tracker/index.ts +0 -3
  208. package/src/tracker/tracker.ts +0 -61
  209. package/src/web-effects/index.ts +0 -1
  210. package/src/web-effects/storage.ts +0 -30
  211. /package/{src/introspection → introspection/src}/index.ts +0 -0
  212. /package/{src/react → react/src}/index.ts +0 -0
  213. /package/{src/react-devtools → react-devtools/src}/devtools.scss +0 -0
  214. /package/{src/realtime-testing → realtime-testing/src}/index.ts +0 -0
@@ -1,9 +1,8 @@
1
- import type { ƒn } from "~/packages/anvl/src/function"
1
+ import type { AtomToken, ƒn } from "atom.io"
2
+ import { setState, transaction } from "atom.io"
2
3
 
3
- import type { Store } from ".."
4
- import { withdraw } from ".."
5
- import type { AtomToken } from "../.."
6
- import { setState } from "../.."
4
+ import { withdraw } from "../store"
5
+ import type { Store } from "../store"
7
6
 
8
7
  export const applyTransaction = <ƒ extends ƒn>(
9
8
  output: ReturnType<ƒ>,
@@ -15,26 +14,34 @@ export const applyTransaction = <ƒ extends ƒn>(
15
14
  )
16
15
  return
17
16
  }
18
- store.config.logger?.info(
19
- `🛃 apply transaction "${store.transactionStatus.key}"`,
20
- )
21
17
  store.transactionStatus.phase = `applying`
22
18
  store.transactionStatus.output = output
23
19
  const { atomUpdates } = store.transactionStatus
24
-
20
+ store.config.logger?.info(
21
+ `🛃 applying transaction "${store.transactionStatus.key}" with ${atomUpdates.length} updates.`,
22
+ )
23
+ store.config.logger?.info(`🛃 the updates are:`, atomUpdates)
25
24
  for (const { key, newValue } of atomUpdates) {
26
25
  const token: AtomToken<unknown> = { key, type: `atom` }
27
26
  if (!store.valueMap.has(token.key)) {
28
- const newAtom = store.transactionStatus.core.atoms.get(token.key)
29
- if (!newAtom) {
30
- throw new Error(
31
- `Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${store.transactionStatus.key}" to store "${store.config.name}"`,
32
- )
27
+ if (token.family) {
28
+ const family = store.families.get(token.family.key)
29
+ if (family) {
30
+ family(token.family.subKey)
31
+ }
32
+ } else {
33
+ const newAtom = store.transactionStatus.core.atoms.get(token.key)
34
+ if (!newAtom) {
35
+ throw new Error(
36
+ `Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${store.transactionStatus.key}" to store "${store.config.name}"`,
37
+ )
38
+ }
39
+ store.atoms.set(newAtom.key, newAtom)
40
+ store.valueMap.set(newAtom.key, newAtom.default)
41
+ store.config.logger?.info(`🔧`, `add atom "${newAtom.key}"`)
33
42
  }
34
- store.atoms.set(newAtom.key, newAtom)
35
- store.valueMap.set(newAtom.key, newAtom.default)
36
- store.config.logger?.info(`🔧`, `add atom "${newAtom.key}"`)
37
43
  }
44
+ // if (store.transactionStatus.key === `dealCards`) debugger
38
45
  setState(token, newValue, store)
39
46
  }
40
47
  const myTransaction = withdraw<ƒ>(
@@ -53,5 +60,5 @@ export const applyTransaction = <ƒ extends ƒn>(
53
60
  params: store.transactionStatus.params as Parameters<ƒ>,
54
61
  })
55
62
  store.transactionStatus = { phase: `idle` }
56
- store.config.logger?.info(`🛬`, `transaction done`)
63
+ store.config.logger?.info(`🛬`, `transaction "${myTransaction.key}" applied`)
57
64
  }
@@ -1,4 +1,6 @@
1
- import type { Store } from ".."
1
+ import { Junction } from "~/packages/rel8/junction/src"
2
+
3
+ import type { Store } from "../store"
2
4
 
3
5
  export const buildTransaction = (
4
6
  key: string,
@@ -11,14 +13,18 @@ export const buildTransaction = (
11
13
  time: Date.now(),
12
14
  core: {
13
15
  atoms: new Map(store.atoms),
14
- atomsThatAreDefault: store.atomsThatAreDefault,
16
+ atomsThatAreDefault: new Set(store.atomsThatAreDefault),
17
+ families: new Map(store.families),
15
18
  operation: { open: false },
16
19
  readonlySelectors: new Map(store.readonlySelectors),
17
20
  timelines: new Map(store.timelines),
18
- timelineAtoms: store.timelineAtoms,
21
+ timelineAtoms: new Junction(store.timelineAtoms.toJSON()),
22
+ trackers: new Map(),
19
23
  transactions: new Map(store.transactions),
20
- selectorAtoms: store.selectorAtoms,
21
- selectorGraph: store.selectorGraph,
24
+ selectorAtoms: new Junction(store.selectorAtoms.toJSON()),
25
+ selectorGraph: new Junction(store.selectorGraph.toJSON(), {
26
+ makeContentKey: (...keys) => keys.sort().join(`:`),
27
+ }),
22
28
  selectors: new Map(store.selectors),
23
29
  valueMap: new Map(store.valueMap),
24
30
  },
@@ -28,6 +34,6 @@ export const buildTransaction = (
28
34
  }
29
35
  store.config.logger?.info(
30
36
  `🛫`,
31
- `transaction "${key}" started in store "${store.config.name}"`,
37
+ `transaction "${key}" building in store "${store.config.name}"`,
32
38
  )
33
39
  }
@@ -1,7 +1,8 @@
1
- import type { ƒn } from "~/packages/anvl/src/function"
1
+ import type { TransactionUpdate, ƒn } from "atom.io"
2
2
 
3
3
  import type { StoreCore } from ".."
4
- import type { StateUpdate, TransactionUpdate } from "../.."
4
+
5
+ export * from "./transaction-internal"
5
6
 
6
7
  export * from "./abort-transaction"
7
8
  export * from "./apply-transaction"
@@ -1,9 +1,8 @@
1
- import type { ƒn } from "~/packages/anvl/src/function"
1
+ import type { AtomToken, TransactionUpdate, ƒn } from "atom.io"
2
+ import { setState } from "atom.io"
2
3
 
3
- import type { Store } from ".."
4
- import { withdraw } from ".."
5
- import type { AtomToken, TransactionUpdate } from "../.."
6
- import { setState } from "../.."
4
+ import { withdraw } from "../store"
5
+ import type { Store } from "../store"
7
6
 
8
7
  export const redoTransactionUpdate = <ƒ extends ƒn>(
9
8
  update: TransactionUpdate<ƒ>,
@@ -1,16 +1,16 @@
1
- import type { ƒn } from "~/packages/anvl/src/function"
1
+ import type {
2
+ TransactionOptions,
3
+ TransactionToken,
4
+ TransactionUpdate,
5
+ ƒn,
6
+ } from "atom.io"
7
+ import { getState, setState } from "atom.io"
2
8
 
3
- import type { Store, StoreCore } from "."
4
- import {
5
- Subject,
6
- abortTransaction,
7
- applyTransaction,
8
- buildTransaction,
9
- deposit,
10
- IMPLICIT,
11
- } from "."
12
- import type { TransactionOptions, TransactionToken, TransactionUpdate } from ".."
13
- import { getState, setState } from ".."
9
+ import { IMPLICIT, type Store, type StoreCore, deposit } from "../store"
10
+ import { Subject } from "../subject"
11
+ import { abortTransaction } from "./abort-transaction"
12
+ import { applyTransaction } from "./apply-transaction"
13
+ import { buildTransaction } from "./build-transaction"
14
14
 
15
15
  export type Transaction<ƒ extends ƒn> = {
16
16
  key: string
@@ -41,7 +41,10 @@ export function transaction__INTERNAL<ƒ extends ƒn>(
41
41
  return output
42
42
  } catch (thrown) {
43
43
  abortTransaction(store)
44
- store.config.logger?.error(`Transaction ${options.key} failed`, thrown)
44
+ store.config.logger?.error(
45
+ `Transaction "${options.key}" failed in store "${store.config.name}":`,
46
+ thrown,
47
+ )
45
48
  throw thrown
46
49
  }
47
50
  },
@@ -1,9 +1,8 @@
1
- import type { ƒn } from "~/packages/anvl/src/function"
1
+ import type { AtomToken, TransactionUpdate, ƒn } from "atom.io"
2
+ import { setState } from "atom.io"
2
3
 
3
- import type { Store } from ".."
4
- import { withdraw } from ".."
5
- import type { AtomToken, TransactionUpdate } from "../.."
6
- import { setState } from "../.."
4
+ import { withdraw } from "../store"
5
+ import type { Store } from "../store"
7
6
 
8
7
  export const undoTransactionUpdate = <ƒ extends ƒn>(
9
8
  update: TransactionUpdate<ƒ>,
@@ -1,272 +1,24 @@
1
- import { AtomToken as AtomToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, SelectorToken as SelectorToken$1, __INTERNAL__, TransactionToken as TransactionToken$1, ReadonlySelectorFamily, TransactionUpdate as TransactionUpdate$1, TimelineToken as TimelineToken$1 } from 'atom.io';
2
- import { Refinement } from 'fp-ts/Refinement';
1
+ import { AtomToken, ReadonlySelectorToken, SelectorToken, TransactionToken, ƒn, ReadonlySelectorFamily, TransactionUpdate, TimelineToken } from 'atom.io';
2
+ import * as __INTERNAL__ from 'atom.io/internal';
3
+ import { Timeline } from 'atom.io/internal';
3
4
 
4
- type ƒn = (...parameters: any[]) => any;
5
+ type AtomTokenIndex = StateTokenIndex<AtomToken<unknown>>;
5
6
 
6
- type AtomTokenIndex = StateTokenIndex<AtomToken$1<unknown>>;
7
-
8
- type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>>;
9
-
10
- type JsonInterface<T, J extends Serializable = Serializable> = {
11
- toJson: (t: T) => J;
12
- fromJson: (json: J) => T;
13
- };
14
-
15
- type primitive = boolean | number | string | null;
16
-
17
- type Serializable = primitive | Readonly<{
18
- [key: string]: Serializable;
19
- }> | ReadonlyArray<Serializable>;
20
- type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
21
-
22
- type Identified = {
23
- id: string;
24
- };
25
-
26
- declare const RELATION_TYPES: readonly ["1:1", "1:n", "n:n"];
27
- type RelationType = typeof RELATION_TYPES[number];
28
- type RelationData<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> = {
29
- contents: Object$1<string, CONTENT>;
30
- relations: Object$1<string, string[]>;
31
- relationType: RelationType;
32
- a: A;
33
- b: B;
34
- };
35
- type IsRelationDataOptions<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> = {
36
- from?: A;
37
- to?: B;
38
- isContent?: (json: Serializable) => json is CONTENT;
39
- };
40
-
41
- type NullSafeUnion<Base, Extension> = Extension extends null ? Base : Base & Extension;
42
- type NullSafeRest<MaybeArg, IfArg = MaybeArg> = MaybeArg extends null ? [] | [undefined] : [IfArg];
43
-
44
- declare class Join<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> implements RelationData<CONTENT, A, B> {
45
- readonly relationType: `1:1` | `1:n` | `n:n`;
46
- readonly a: A;
47
- readonly b: B;
48
- readonly relations: Record<string, string[]>;
49
- readonly contents: Record<string, CONTENT>;
50
- constructor(json?: Partial<RelationData<CONTENT, A, B>>);
51
- toJSON(): RelationData<CONTENT, A, B>;
52
- static fromJSON<CONTENT extends Object$1 | null, A extends string, B extends string>(json: Serializable, options?: IsRelationDataOptions<CONTENT, A, B>): Join<CONTENT, A, B>;
53
- from<AA extends string>(newA: AA): Join<CONTENT, AA, B>;
54
- to<BB extends string>(newB: BB): Join<CONTENT, A, BB>;
55
- makeJsonInterface: (...params: CONTENT extends null ? [
56
- ] : [Refinement<unknown, CONTENT>]) => JsonInterface<Join<CONTENT, A, B>, RelationData<CONTENT, A, B>>;
57
- getRelatedId(id: string): string | undefined;
58
- getRelatedIds(id: string): string[];
59
- getContent(idA: string, idB: string): CONTENT | undefined;
60
- getRelationEntries(id: string): [string, CONTENT][];
61
- getRelationRecord(id: string): Record<string, CONTENT>;
62
- getRelation(id: string): NullSafeUnion<Identified, CONTENT> | undefined;
63
- getRelations(id: string): NullSafeUnion<Identified, CONTENT>[];
64
- setRelations(subject: {
65
- [from in A]: string;
66
- } | {
67
- [to in B]: string;
68
- }, relations: NullSafeUnion<Identified, CONTENT>[]): Join<CONTENT, A, B>;
69
- set(relation: {
70
- [key in A | B]: string;
71
- }, ...rest: NullSafeRest<CONTENT>): Join<CONTENT, A, B>;
72
- remove(relation: Partial<Record<A | B, string>>): Join<CONTENT, A, B>;
73
- }
74
-
75
- type Logger = Pick<Console, `error` | `info` | `warn`>;
76
-
77
- type TransactionToken<_> = {
78
- key: string;
79
- type: `transaction`;
80
- __brand?: _;
81
- };
82
- type TransactionUpdate<ƒ extends ƒn> = {
83
- key: string;
84
- atomUpdates: KeyedStateUpdate<unknown>[];
85
- params: Parameters<ƒ>;
86
- output: ReturnType<ƒ>;
87
- };
88
-
89
- type StateUpdate<T> = {
90
- newValue: T;
91
- oldValue: T;
92
- };
93
- type KeyedStateUpdate<T> = StateUpdate<T> & {
94
- key: string;
95
- };
96
-
97
- type TimelineToken = {
98
- key: string;
99
- type: `timeline`;
100
- };
101
- type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
102
-
103
- type AtomToken<_> = {
104
- key: string;
105
- type: `atom`;
106
- family?: FamilyMetadata;
107
- __brand?: _;
108
- };
109
- type SelectorToken<_> = {
110
- key: string;
111
- type: `selector`;
112
- family?: FamilyMetadata;
113
- __brand?: _;
114
- };
115
- type StateToken<T> = AtomToken<T> | SelectorToken<T>;
116
- type ReadonlySelectorToken<_> = {
117
- key: string;
118
- type: `readonly_selector`;
119
- family?: FamilyMetadata;
120
- __brand?: _;
121
- };
122
- type FamilyMetadata = {
123
- key: string;
124
- subKey: string;
125
- };
126
-
127
- type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `transactions` | `valueMap`>;
128
- interface Store {
129
- atoms: Map<string, Atom<any>>;
130
- atomsThatAreDefault: Set<string>;
131
- readonlySelectors: Map<string, ReadonlySelector<any>>;
132
- selectorAtoms: Join<null, `selectorKey`, `atomKey`>;
133
- selectorGraph: Join<{
134
- source: string;
135
- }>;
136
- selectors: Map<string, Selector<any>>;
137
- timelineAtoms: Join<null, `timelineKey`, `atomKey`>;
138
- timelines: Map<string, Timeline>;
139
- transactions: Map<string, Transaction<any>>;
140
- valueMap: Map<string, any>;
141
- subject: {
142
- atomCreation: Subject<AtomToken<unknown>>;
143
- selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
144
- transactionCreation: Subject<TransactionToken<ƒn>>;
145
- timelineCreation: Subject<TimelineToken>;
146
- operationStatus: Subject<OperationProgress>;
147
- };
148
- operation: OperationProgress;
149
- transactionStatus: TransactionStatus<ƒn>;
150
- config: {
151
- name: string;
152
- logger: Logger | null;
153
- logger__INTERNAL: Logger;
154
- };
155
- }
156
-
157
- type Atom<T> = {
158
- key: string;
159
- type: `atom`;
160
- family?: FamilyMetadata;
161
- subject: Subject<{
162
- newValue: T;
163
- oldValue: T;
164
- }>;
165
- default: T;
166
- };
167
-
168
- type OperationProgress = {
169
- open: false;
170
- } | {
171
- open: true;
172
- done: Set<string>;
173
- prev: Map<string, any>;
174
- time: number;
175
- token: StateToken<any>;
176
- };
177
-
178
- type Selector<T> = {
179
- key: string;
180
- type: `selector`;
181
- family?: FamilyMetadata;
182
- install: (store: Store) => void;
183
- subject: Subject<{
184
- newValue: T;
185
- oldValue: T;
186
- }>;
187
- get: () => T;
188
- set: (newValue: T | ((oldValue: T) => T)) => void;
189
- };
190
- type ReadonlySelector<T> = {
191
- key: string;
192
- type: `readonly_selector`;
193
- family?: FamilyMetadata;
194
- install: (store: Store) => void;
195
- subject: Subject<{
196
- newValue: T;
197
- oldValue: T;
198
- }>;
199
- get: () => T;
200
- };
201
-
202
- type Subscriber<T> = (value: T) => void;
203
- declare class Subject<T> {
204
- subscribers: Subscriber<T>[];
205
- subscribe(subscriber: Subscriber<T>): {
206
- unsubscribe: () => void;
207
- };
208
- private unsubscribe;
209
- next(value: T): void;
210
- }
211
-
212
- type TimelineAtomUpdate = StateUpdate<unknown> & {
213
- key: string;
214
- type: `atom_update`;
215
- timestamp: number;
216
- };
217
- type TimelineSelectorUpdate = {
218
- key: string;
219
- type: `selector_update`;
220
- timestamp: number;
221
- atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
222
- };
223
- type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
224
- key: string;
225
- type: `transaction_update`;
226
- timestamp: number;
227
- };
228
- type Timeline = {
229
- key: string;
230
- at: number;
231
- timeTraveling: `into_future` | `into_past` | null;
232
- history: TimelineUpdate[];
233
- selectorTime: number | null;
234
- transactionKey: string | null;
235
- install: (store: Store) => void;
236
- subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
237
- };
238
-
239
- type Transaction<ƒ extends ƒn> = {
240
- key: string;
241
- type: `transaction`;
242
- install: (store: Store) => void;
243
- subject: Subject<TransactionUpdate<ƒ>>;
244
- run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
245
- };
246
-
247
- type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
248
- phase: `applying` | `building`;
249
- time: number;
250
- core: StoreCore;
251
- };
252
- type TransactionIdle = {
253
- phase: `idle`;
254
- };
255
- type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
7
+ type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
256
8
 
257
9
  declare const attachIntrospectionStates: (store?: __INTERNAL__.Store) => {
258
- atomIndex: ReadonlySelectorToken$1<AtomTokenIndex>;
259
- selectorIndex: ReadonlySelectorToken$1<SelectorTokenIndex>;
260
- transactionIndex: ReadonlySelectorToken$1<TransactionToken$1<ƒn>[]>;
261
- findTransactionLogState: ReadonlySelectorFamily<TransactionUpdate$1<ƒn>[]>;
262
- timelineIndex: ReadonlySelectorToken$1<TimelineToken$1[]>;
10
+ atomIndex: ReadonlySelectorToken<AtomTokenIndex>;
11
+ selectorIndex: ReadonlySelectorToken<SelectorTokenIndex>;
12
+ transactionIndex: ReadonlySelectorToken<TransactionToken<ƒn>[]>;
13
+ findTransactionLogState: ReadonlySelectorFamily<TransactionUpdate<ƒn>[]>;
14
+ timelineIndex: ReadonlySelectorToken<TimelineToken[]>;
263
15
  findTimelineState: ReadonlySelectorFamily<Timeline>;
264
16
  };
265
17
 
266
- type FamilyNode<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = {
18
+ type FamilyNode<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>> = {
267
19
  key: string;
268
20
  familyMembers: Record<string, Token>;
269
21
  };
270
- type StateTokenIndex<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = Record<string, FamilyNode<Token> | Token>;
22
+ type StateTokenIndex<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>> = Record<string, FamilyNode<Token> | Token>;
271
23
 
272
24
  export { FamilyNode, StateTokenIndex, attachIntrospectionStates };