atom.io 0.31.0 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/data/dist/index.d.ts +867 -101
  2. package/data/dist/index.js +10 -558
  3. package/data/src/index.ts +0 -2
  4. package/data/src/struct-family.ts +1 -1
  5. package/data/src/struct.ts +1 -2
  6. package/dist/chunk-354XQWHH.js +153 -0
  7. package/dist/chunk-4LWKCEW3.js +14 -0
  8. package/dist/chunk-5F2V7S3B.js +83 -0
  9. package/dist/chunk-ECOMOMUN.js +631 -0
  10. package/dist/{chunk-42UH5F5Q.js → chunk-GY2XQYZY.js} +2051 -755
  11. package/dist/chunk-NF7FJKJD.js +107 -0
  12. package/dist/chunk-R3ZUK5EH.js +1024 -0
  13. package/dist/chunk-Z2UJW4NQ.js +523 -0
  14. package/dist/index.d.ts +855 -127
  15. package/dist/index.js +1 -143
  16. package/eslint-plugin/dist/index.d.ts +1 -30
  17. package/eslint-plugin/dist/index.js +0 -146
  18. package/eslint-plugin/src/index.ts +0 -1
  19. package/eslint-plugin/src/rules/index.ts +0 -1
  20. package/internal/dist/index.d.ts +794 -70
  21. package/internal/dist/index.js +1 -2
  22. package/internal/src/atom/create-regular-atom.ts +3 -3
  23. package/internal/src/atom/dispose-atom.ts +4 -13
  24. package/internal/src/atom/is-default.ts +3 -3
  25. package/internal/src/caching.ts +5 -5
  26. package/internal/src/capitalize.ts +3 -0
  27. package/internal/src/families/create-readonly-selector-family.ts +5 -6
  28. package/internal/src/families/create-writable-selector-family.ts +1 -4
  29. package/internal/src/families/dispose-from-store.ts +3 -13
  30. package/internal/src/families/find-in-store.ts +1 -6
  31. package/internal/src/get-state/get-from-store.ts +2 -2
  32. package/internal/src/get-state/read-or-compute-value.ts +1 -1
  33. package/internal/src/index.ts +19 -9
  34. package/internal/src/ingest-updates/ingest-creation-disposal.ts +2 -3
  35. package/internal/src/install-into-store.ts +48 -0
  36. package/internal/src/join/edit-relations-in-store.ts +32 -0
  37. package/internal/src/join/find-relations-in-store.ts +124 -0
  38. package/internal/src/join/get-internal-relations-from-store.ts +14 -0
  39. package/internal/src/join/get-join.ts +31 -0
  40. package/internal/src/join/index.ts +5 -0
  41. package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
  42. package/internal/src/keys.ts +7 -7
  43. package/internal/src/molecule.ts +299 -0
  44. package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
  45. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  46. package/internal/src/mutable/get-json-token.ts +1 -1
  47. package/internal/src/mutable/tracker-family.ts +19 -17
  48. package/internal/src/mutable/tracker.ts +8 -8
  49. package/internal/src/not-found-error.ts +8 -30
  50. package/internal/src/pretty-print.ts +2 -13
  51. package/internal/src/selector/create-readonly-selector.ts +3 -7
  52. package/internal/src/selector/create-writable-selector.ts +4 -4
  53. package/internal/src/selector/dispose-selector.ts +20 -11
  54. package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
  55. package/internal/src/selector/register-selector.ts +7 -17
  56. package/internal/src/selector/trace-selector-atoms.ts +2 -2
  57. package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
  58. package/internal/src/set-state/emit-update.ts +1 -1
  59. package/internal/src/set-state/evict-downstream.ts +1 -1
  60. package/internal/src/set-state/set-atom-or-selector.ts +1 -1
  61. package/internal/src/set-state/set-atom.ts +10 -10
  62. package/internal/src/set-state/set-into-store.ts +2 -2
  63. package/internal/src/set-state/stow-update.ts +1 -1
  64. package/internal/src/store/deposit.ts +10 -8
  65. package/internal/src/store/store.ts +1 -1
  66. package/internal/src/store/withdraw.ts +34 -53
  67. package/internal/src/subscribe/recall-state.ts +1 -1
  68. package/internal/src/subscribe/subscribe-in-store.ts +3 -3
  69. package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
  70. package/internal/src/subscribe/subscribe-to-state.ts +5 -5
  71. package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
  72. package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
  73. package/internal/src/timeline/create-timeline.ts +17 -37
  74. package/internal/src/transaction/act-upon-store.ts +2 -2
  75. package/internal/src/transaction/apply-transaction.ts +5 -5
  76. package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
  77. package/internal/src/transaction/build-transaction.ts +5 -8
  78. package/internal/src/transaction/create-transaction.ts +3 -3
  79. package/internal/src/transaction/get-epoch-number.ts +3 -3
  80. package/internal/src/transaction/set-epoch-number.ts +2 -2
  81. package/introspection/dist/index.d.ts +922 -6
  82. package/introspection/dist/index.js +2 -620
  83. package/json/dist/index.d.ts +899 -5
  84. package/json/dist/index.js +1 -81
  85. package/json/src/select-json-family.ts +3 -14
  86. package/package.json +27 -45
  87. package/react/dist/index.d.ts +921 -3
  88. package/react/dist/index.js +2 -82
  89. package/react/src/use-o.ts +1 -1
  90. package/react/src/use-tl.ts +2 -2
  91. package/react-devtools/dist/index.css +16 -14
  92. package/react-devtools/dist/index.d.ts +26 -1
  93. package/react-devtools/dist/index.js +6 -6
  94. package/react-devtools/src/devtools.scss +16 -14
  95. package/realtime/dist/index.d.ts +202 -8
  96. package/realtime/dist/index.js +2 -107
  97. package/realtime/src/realtime-continuity.ts +2 -2
  98. package/realtime/src/shared-room-store.ts +1 -2
  99. package/realtime-client/dist/index.d.ts +960 -22
  100. package/realtime-client/dist/index.js +3 -509
  101. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
  102. package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
  103. package/realtime-client/src/pull-atom-family-member.ts +2 -2
  104. package/realtime-client/src/pull-atom.ts +2 -2
  105. package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
  106. package/realtime-client/src/pull-mutable-atom.ts +2 -2
  107. package/realtime-client/src/pull-selector-family-member.ts +4 -4
  108. package/realtime-client/src/pull-selector.ts +4 -4
  109. package/realtime-client/src/push-state.ts +5 -10
  110. package/realtime-client/src/server-action.ts +4 -4
  111. package/realtime-client/src/sync-continuity.ts +6 -6
  112. package/realtime-react/dist/index.d.ts +166 -12
  113. package/realtime-react/dist/index.js +5 -154
  114. package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
  115. package/realtime-react/src/use-pull-atom.ts +1 -1
  116. package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
  117. package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
  118. package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
  119. package/realtime-react/src/use-pull-selector.ts +1 -1
  120. package/realtime-react/src/use-push.ts +1 -1
  121. package/realtime-react/src/use-server-action.ts +2 -2
  122. package/realtime-react/src/use-sync-continuity.ts +1 -1
  123. package/realtime-server/dist/index.d.ts +971 -28
  124. package/realtime-server/dist/index.js +3 -1001
  125. package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
  126. package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
  127. package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
  128. package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
  129. package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
  130. package/realtime-server/src/realtime-action-receiver.ts +1 -1
  131. package/realtime-server/src/realtime-family-provider.ts +2 -2
  132. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
  133. package/realtime-server/src/realtime-mutable-provider.ts +2 -2
  134. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
  135. package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
  136. package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
  137. package/realtime-server/src/realtime-state-provider.ts +2 -2
  138. package/realtime-testing/dist/index.d.ts +1091 -3
  139. package/realtime-testing/dist/index.js +23 -26
  140. package/realtime-testing/src/setup-realtime-test.tsx +6 -5
  141. package/src/atom.ts +53 -29
  142. package/src/dispose-state.ts +12 -2
  143. package/{ephemeral/src → src}/find-state.ts +35 -25
  144. package/src/get-state.ts +16 -0
  145. package/src/index.ts +77 -3
  146. package/src/join.ts +218 -0
  147. package/src/realm.ts +169 -0
  148. package/src/selector.ts +20 -0
  149. package/src/set-state.ts +16 -8
  150. package/src/silo.ts +13 -7
  151. package/src/timeline.ts +1 -1
  152. package/src/transaction.ts +4 -8
  153. package/transceivers/set-rtx/dist/index.d.ts +37 -2
  154. package/transceivers/set-rtx/dist/index.js +1 -212
  155. package/transceivers/set-rtx/src/set-rtx.ts +4 -1
  156. package/web/dist/index.d.ts +30 -1
  157. package/web/dist/index.js +1 -15
  158. package/data/src/until.ts +0 -15
  159. package/dist/chunk-ICGFFQ3H.js +0 -272
  160. package/ephemeral/dist/index.d.ts +0 -57
  161. package/ephemeral/dist/index.js +0 -9
  162. package/ephemeral/package.json +0 -13
  163. package/ephemeral/src/index.ts +0 -1
  164. package/eslint-plugin/src/rules/lifespan.ts +0 -203
  165. package/immortal/dist/index.d.ts +0 -12
  166. package/immortal/dist/index.js +0 -9
  167. package/immortal/package.json +0 -13
  168. package/immortal/src/index.ts +0 -1
  169. package/immortal/src/seek-state.ts +0 -60
  170. package/src/allocate.ts +0 -443
  171. package/src/molecule.ts +0 -16
@@ -1,15 +1,13 @@
1
+ import { RealtimeProvider } from '../../dist/chunk-354XQWHH.js';
2
+ import { myUsernameState } from '../../dist/chunk-Z2UJW4NQ.js';
3
+ import { socketAtoms, usersOfSockets, userIndex, socketIndex, roomSelectors } from '../../dist/chunk-R3ZUK5EH.js';
4
+ import { roomIndex } from '../../dist/chunk-NF7FJKJD.js';
5
+ import '../../dist/chunk-4LWKCEW3.js';
6
+ import { StoreProvider } from '../../dist/chunk-5F2V7S3B.js';
7
+ import { Silo, IMPLICIT, Realm, findInStore, setIntoStore, editRelationsInStore, toEntries, findRelationsInStore, getFromStore, AtomIOLogger, clearStore } from '../../dist/chunk-GY2XQYZY.js';
1
8
  import '../../dist/chunk-XWL6SNVU.js';
2
9
  import * as http from 'node:http';
3
10
  import { render, prettyDOM } from '@testing-library/react';
4
- import * as AtomIO from 'atom.io';
5
- import { editRelationsInStore, findRelationsInStore } from 'atom.io/data';
6
- import { IMPLICIT, findInStore, setIntoStore, getFromStore, clearStore } from 'atom.io/internal';
7
- import { toEntries } from 'atom.io/json';
8
- import * as AR from 'atom.io/react';
9
- import * as RT from 'atom.io/realtime';
10
- import * as RTC from 'atom.io/realtime-client';
11
- import * as RTR from 'atom.io/realtime-react';
12
- import * as RTS from 'atom.io/realtime-server';
13
11
  import * as Happy from 'happy-dom';
14
12
  import * as SocketIO from 'socket.io';
15
13
  import { io } from 'socket.io-client';
@@ -17,7 +15,7 @@ import { jsx } from 'react/jsx-runtime';
17
15
 
18
16
  var testNumber = 0;
19
17
  function prefixLogger(store, prefix) {
20
- store.loggers[0] = new AtomIO.AtomIOLogger(`info`, undefined, {
18
+ store.loggers[0] = new AtomIOLogger(`info`, undefined, {
21
19
  info: (...args) => {
22
20
  console.info(prefix, ...args);
23
21
  },
@@ -31,14 +29,14 @@ function prefixLogger(store, prefix) {
31
29
  }
32
30
  var setupRealtimeTestServer = (options) => {
33
31
  ++testNumber;
34
- const silo = new AtomIO.Silo(
32
+ const silo = new Silo(
35
33
  {
36
34
  name: `SERVER-${testNumber}`,
37
35
  lifespan: options.immortal?.server ? `immortal` : `ephemeral`
38
36
  },
39
37
  IMPLICIT.STORE
40
38
  );
41
- const socketRealm = new AtomIO.Realm(silo.store);
39
+ const socketRealm = new Realm(silo.store);
42
40
  const httpServer = http.createServer((_, res) => res.end(`Hello World!`));
43
41
  const address = httpServer.listen(options.port).address();
44
42
  const port = typeof address === `string` ? null : address === null ? null : address.port;
@@ -48,22 +46,21 @@ var setupRealtimeTestServer = (options) => {
48
46
  if (token === `test` && socket.id) {
49
47
  const userClaim = socketRealm.allocate(`root`, `user::${username}`);
50
48
  const socketClaim = socketRealm.allocate(`root`, `socket::${socket.id}`);
51
- const socketState = findInStore(silo.store, RTS.socketAtoms, socketClaim);
49
+ const socketState = findInStore(silo.store, socketAtoms, socketClaim);
52
50
  setIntoStore(silo.store, socketState, socket);
53
51
  editRelationsInStore(
54
- RTS.usersOfSockets,
52
+ usersOfSockets,
55
53
  (relations) => {
56
54
  relations.set(userClaim, socketClaim);
57
55
  },
58
56
  silo.store
59
57
  );
60
- setIntoStore(silo.store, RTS.userIndex, (index) => index.add(userClaim));
58
+ setIntoStore(silo.store, userIndex, (index) => index.add(userClaim));
61
59
  setIntoStore(
62
60
  silo.store,
63
- RTS.socketIndex,
61
+ socketIndex,
64
62
  (index) => index.add(socketClaim)
65
63
  );
66
- console.log(`${username} connected on ${socket.id}`);
67
64
  next();
68
65
  } else {
69
66
  next(new Error(`Authentication error`));
@@ -73,7 +70,7 @@ var setupRealtimeTestServer = (options) => {
73
70
  let userKey = null;
74
71
  function enableLogging() {
75
72
  const userKeyState = findRelationsInStore(
76
- RTS.usersOfSockets,
73
+ usersOfSockets,
77
74
  `socket::${socket.id}`,
78
75
  silo.store
79
76
  ).userKeyOfSocket;
@@ -85,17 +82,17 @@ var setupRealtimeTestServer = (options) => {
85
82
  socket.onAnyOutgoing((event, ...args) => {
86
83
  console.log(`\u{1F6F0} >>`, userKey, event, ...args);
87
84
  });
85
+ socket.on(`disconnect`, () => {
86
+ console.log(`${userKey} disconnected`);
87
+ });
88
88
  }
89
89
  options.server({ socket, enableLogging, silo });
90
- socket.on(`disconnect`, () => {
91
- console.log(`${userKey} disconnected`);
92
- });
93
90
  });
94
91
  const dispose = async () => {
95
92
  await server.close();
96
- const roomKeys = getFromStore(silo.store, RT.roomIndex);
93
+ const roomKeys = getFromStore(silo.store, roomIndex);
97
94
  for (const roomKey of roomKeys) {
98
- const roomState = findInStore(silo.store, RTS.roomSelectors, roomKey);
95
+ const roomState = findInStore(silo.store, roomSelectors, roomKey);
99
96
  const room = getFromStore(silo.store, roomState);
100
97
  if (room && !(room instanceof Promise)) {
101
98
  room.process.kill();
@@ -117,17 +114,17 @@ var setupRealtimeTestClient = (options, name, port) => {
117
114
  const socket = io(`http://localhost:${port}/`, {
118
115
  auth: { token: `test`, username: `${name}-${testNumber}` }
119
116
  });
120
- const silo = new AtomIO.Silo({ name, lifespan: `ephemeral` }, IMPLICIT.STORE);
117
+ const silo = new Silo({ name, lifespan: `ephemeral` }, IMPLICIT.STORE);
121
118
  for (const [key, value] of silo.store.valueMap.entries()) {
122
119
  if (Array.isArray(value)) {
123
120
  silo.store.valueMap.set(key, [...value]);
124
121
  }
125
122
  }
126
- silo.setState(RTC.myUsernameState, `${name}-${testNumber}`);
123
+ silo.setState(myUsernameState, `${name}-${testNumber}`);
127
124
  const { document } = new Happy.Window();
128
125
  document.body.innerHTML = `<div id="app"></div>`;
129
126
  const renderResult = render(
130
- /* @__PURE__ */ jsx(AR.StoreProvider, { store: silo.store, children: /* @__PURE__ */ jsx(RTR.RealtimeProvider, { socket, children: /* @__PURE__ */ jsx(options.client, {}) }) }),
127
+ /* @__PURE__ */ jsx(StoreProvider, { store: silo.store, children: /* @__PURE__ */ jsx(RealtimeProvider, { socket, children: /* @__PURE__ */ jsx(options.client, {}) }) }),
131
128
  {
132
129
  container: document.querySelector(`#app`)
133
130
  }
@@ -3,11 +3,12 @@ import * as http from "node:http"
3
3
  import type { RenderResult } from "@testing-library/react"
4
4
  import { prettyDOM, render } from "@testing-library/react"
5
5
  import * as AtomIO from "atom.io"
6
- import { editRelationsInStore, findRelationsInStore } from "atom.io/data"
7
6
  import type { Store } from "atom.io/internal"
8
7
  import {
9
8
  clearStore,
9
+ editRelationsInStore,
10
10
  findInStore,
11
+ findRelationsInStore,
11
12
  getFromStore,
12
13
  IMPLICIT,
13
14
  setIntoStore,
@@ -130,7 +131,7 @@ export const setupRealtimeTestServer = (
130
131
  setIntoStore(silo.store, RTS.socketIndex, (index) =>
131
132
  index.add(socketClaim),
132
133
  )
133
- console.log(`${username} connected on ${socket.id}`)
134
+ // console.log(`${username} connected on ${socket.id}`)
134
135
  next()
135
136
  } else {
136
137
  next(new Error(`Authentication error`))
@@ -153,11 +154,11 @@ export const setupRealtimeTestServer = (
153
154
  socket.onAnyOutgoing((event, ...args) => {
154
155
  console.log(`🛰 >>`, userKey, event, ...args)
155
156
  })
157
+ socket.on(`disconnect`, () => {
158
+ console.log(`${userKey} disconnected`)
159
+ })
156
160
  }
157
161
  options.server({ socket, enableLogging, silo })
158
- socket.on(`disconnect`, () => {
159
- console.log(`${userKey} disconnected`)
160
- })
161
162
  })
162
163
 
163
164
  const dispose = async () => {
package/src/atom.ts CHANGED
@@ -6,59 +6,83 @@ import {
6
6
  } from "atom.io/internal"
7
7
  import type { Canonical, Json, JsonInterface } from "atom.io/json"
8
8
 
9
- import type { AtomToken, MutableAtomToken, RegularAtomToken } from "."
10
-
11
- export type Effectors<T> = {
12
- setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void
13
- onSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void
14
- }
15
-
16
- export type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void
17
-
18
- export type RegularAtomOptions<T> = {
19
- key: string
20
- default: T | (() => T)
21
- effects?: AtomEffect<T>[]
22
- }
23
- // biome-ignore format: complex intersection
24
- export type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> =
25
- & JsonInterface<T, J>
26
- & Omit<RegularAtomOptions<T>, `default`>
27
- & {
28
- default: () => T
29
- mutable: true
30
- }
9
+ import type { AtomToken, MutableAtomToken, RegularAtomToken, Setter } from "."
31
10
 
32
11
  /**
33
12
  * @public
34
- * Declare a mutable global reactive variable.
35
- * @param options - Configuration for this mutable atom.
13
+ * Create a mutable atom, a global reactive variable in the implicit store
14
+ *
15
+ * The value of a mutable atom must be some kind of {@link Transceiver}.
16
+ *
17
+ * @param options - {@link MutableAtomOptions}.
36
18
  * @returns
37
- * The token for your mutable atom.
19
+ * A reference to the atom created: a {@link MutableAtomToken}
38
20
  * @overload Mutable
39
21
  */
40
22
  export function atom<T extends Transceiver<any>, J extends Json.Serializable>(
41
23
  options: MutableAtomOptions<T, J>,
42
24
  ): MutableAtomToken<T, J>
25
+
43
26
  /**
44
27
  * @public
45
- * Declare a regular global reactive variable.
46
- * @param options - Configuration for this regular atom.
28
+ * Create a regular atom, a global reactive variable in the implicit store
29
+ * @param options - {@link RegularAtomOptions}.
47
30
  * @returns
48
- * The token for your regular atom.
31
+ * A reference to the atom created: a {@link RegularAtomToken}
49
32
  * @overload Regular
50
33
  */
51
34
  export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>
52
-
53
35
  export function atom(
54
36
  options: MutableAtomOptions<any, any> | RegularAtomOptions<any>,
55
37
  ): AtomToken<any> {
56
38
  return createStandaloneAtom(IMPLICIT.STORE, options)
57
39
  }
58
40
 
41
+ /** @public */
42
+ export type Effectors<T> = {
43
+ /**
44
+ * Set the value of the atom
45
+ * @param next - The new value of the atom, or a setter function
46
+ */
47
+ setSelf: <New extends T>(next: New | Setter<T, New>) => void
48
+ /** Subscribe to changes to the atom */
49
+ onSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void
50
+ }
51
+
52
+ /**
53
+ * @public
54
+ * A function that runs side effects when the atom is set
55
+ * @param tools - {@link Effectors} that can be used to run side effects
56
+ * @returns
57
+ * Optionally, a cleanup function that will be called when the atom is disposed
58
+ */
59
+ export type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void
60
+
61
+ /** @public */
62
+ export type RegularAtomOptions<T> = {
63
+ /** The unique identifier of the atom */
64
+ key: string
65
+ /** The starting value of the atom */
66
+ default: T | (() => T)
67
+ /** Hooks used to run side effects when the atom is set */
68
+ effects?: AtomEffect<T>[]
69
+ }
70
+ // biome-ignore format: complex intersection
71
+ export type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> =
72
+ & JsonInterface<T, J>
73
+ & Omit<RegularAtomOptions<T>, `default`>
74
+ & {
75
+ default: () => T
76
+ mutable: true
77
+ }
78
+
79
+ /** @public */
59
80
  export type RegularAtomFamilyOptions<T, K extends Canonical> = {
81
+ /** The unique identifier of the atom family */
60
82
  key: string
83
+ /** The starting value of the atom family */
61
84
  default: T | ((key: K) => T)
85
+ /** Hooks used to run side effects when an atom in the family is set */
62
86
  effects?: (key: K) => AtomEffect<T>[]
63
87
  }
64
88
 
@@ -3,13 +3,23 @@ import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { ReadableFamilyToken, ReadableToken } from "."
5
5
 
6
+ /**
7
+ * @public
8
+ * Disposes of a state in the implicit store
9
+ * @param token - The token of the state to dispose
10
+ * @overload Default
11
+ */
6
12
  export function disposeState(token: ReadableToken<any>): void
7
-
13
+ /**
14
+ * @public
15
+ * Disposes of a state family in the implicit store
16
+ * @param token - The token of the state family to dispose
17
+ * @param key - The unique key of the state to dispose
18
+ */
8
19
  export function disposeState<K extends Canonical>(
9
20
  token: ReadableFamilyToken<any, K>,
10
21
  key: K,
11
22
  ): void
12
-
13
23
  export function disposeState(
14
24
  ...[token, key]:
15
25
  | [token: ReadableFamilyToken<any, any>, key: Canonical]
@@ -17,12 +17,13 @@ import { findInStore, IMPLICIT } from "atom.io/internal"
17
17
  import type { Canonical, Json } from "atom.io/json"
18
18
 
19
19
  /**
20
- * @overload Mutable Atom
21
- * Finds a {@link MutableAtomToken} in the store.
22
- * @param token - A {@link MutableAtomFamilyToken}.
23
- * @param key - The key of the state.
20
+ * @public
21
+ * Finds a {@link MutableAtomToken} in the store
22
+ * @param token - A {@link MutableAtomFamilyToken}
23
+ * @param key - The key of the state
24
24
  * @returns
25
- * The current value of the state.
25
+ * The current value of the state
26
+ * @overload Mutable Atom
26
27
  */
27
28
  export function findState<
28
29
  T extends Transceiver<any>,
@@ -31,44 +32,52 @@ export function findState<
31
32
  Key extends K,
32
33
  >(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J, K>
33
34
  /**
34
- * Finds a state in the store.
35
- * @param token - The token of the state family.
36
- * @param key - The key of the state.
35
+ * @public
36
+ * Finds a state in the store
37
+ * @param token - The token of the state family
38
+ * @param key - The key of the state
37
39
  * @returns
38
- * The current value of the state.
40
+ * The current value of the state
41
+ * @overload Regular Atom
39
42
  */
40
43
  export function findState<T, K extends Canonical, Key extends K>(
41
44
  token: RegularAtomFamilyToken<T, K>,
42
45
  key: Key,
43
46
  ): RegularAtomToken<T, K>
44
47
  /**
45
- * Finds a state in the store.
46
- * @param token - The token of the state family.
47
- * @param key - The key of the state.
48
+ * @public
49
+ * Finds a state in the store
50
+ * @param token - The token of the state family
51
+ * @param key - The key of the state
48
52
  * @returns
49
- * The current value of the state.
53
+ * The current value of the state
54
+ * @overload Writable Selector
50
55
  */
51
56
  export function findState<T, K extends Canonical, Key extends K>(
52
57
  token: WritableSelectorFamilyToken<T, K>,
53
58
  key: Key,
54
59
  ): WritableSelectorToken<T, K>
55
60
  /**
56
- * Finds a state in the store.
57
- * @param token - The token of the state family.
58
- * @param key - The key of the state.
61
+ * @public
62
+ * Finds a state in the store
63
+ * @param token - The token of the state family
64
+ * @param key - The key of the state
59
65
  * @returns
60
- * The current value of the state.
66
+ * The current value of the state
67
+ * @overload Readonly Selector
61
68
  */
62
69
  export function findState<T, K extends Canonical, Key extends K>(
63
70
  token: ReadonlySelectorFamilyToken<T, K>,
64
71
  key: Key,
65
72
  ): ReadonlySelectorToken<T, K>
66
73
  /**
67
- * Finds a state in the store.
68
- * @param token - The token of the state family.
69
- * @param key - The key of the state.
74
+ * @public
75
+ * Finds a state in the store
76
+ * @param token - The token of the state family
77
+ * @param key - The key of the state
70
78
  * @returns
71
- * The current value of the state.
79
+ * The current value of the state
80
+ * @overload Writable State
72
81
  */
73
82
  export function findState<T, K extends Canonical, Key extends K>(
74
83
  token: WritableFamilyToken<T, K>,
@@ -76,12 +85,13 @@ export function findState<T, K extends Canonical, Key extends K>(
76
85
  ): WritableToken<T, K>
77
86
  /**
78
87
  * @public
79
- * Finds a {@link ReadableToken} in the store.
80
- * @param token - A {@link ReadableFamilyToken}.
81
- * @param key - The key of the state.
88
+ * Finds a {@link ReadableToken} in the store
89
+ * @param token - A {@link ReadableFamilyToken}
90
+ * @param key - The key of the state
82
91
  * @returns
83
- * The current value of the state.
92
+ * The current value of the state
84
93
  * @overload Unknown
94
+ * @default
85
95
  */
86
96
  export function findState<T, K extends Canonical, Key extends K>(
87
97
  token: ReadableFamilyToken<T, K>,
package/src/get-state.ts CHANGED
@@ -3,8 +3,24 @@ import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { ReadableFamilyToken, ReadableToken } from "."
5
5
 
6
+ /**
7
+ * @public
8
+ * Get the current value of a state
9
+ * @param token - The token of the state to get
10
+ * @return The current value of the state
11
+ * @overload Default
12
+ * @default
13
+ */
6
14
  export function getState<T>(token: ReadableToken<T>): T
7
15
 
16
+ /**
17
+ * @public
18
+ * Get the current value of a state family
19
+ * @param token - The token of a state family
20
+ * @param key - The unique key of the state to get
21
+ * @return The current value of the state
22
+ * @overload Streamlined
23
+ */
8
24
  export function getState<T, K extends Canonical, Key extends K>(
9
25
  token: ReadableFamilyToken<T, K>,
10
26
  key: Key,
package/src/index.ts CHANGED
@@ -1,18 +1,27 @@
1
1
  import type { Transceiver } from "atom.io/internal"
2
2
  import type { Canonical, Json, stringified } from "atom.io/json"
3
3
 
4
- import type { AtomFamilyToken } from "./atom"
4
+ import type { atom, AtomFamilyToken } from "./atom"
5
+ import type { getState } from "./get-state"
5
6
  import type {
6
7
  SelectorFamilyToken,
7
8
  WritableSelectorFamilyToken,
8
9
  } from "./selector"
10
+ import type { setState } from "./set-state"
11
+ import type { TimelineToken } from "./timeline"
12
+ import type {
13
+ runTransaction,
14
+ transaction,
15
+ TransactionToken,
16
+ } from "./transaction"
9
17
 
10
- export * from "./allocate"
11
18
  export * from "./atom"
12
19
  export * from "./dispose-state"
20
+ export * from "./find-state"
13
21
  export * from "./get-state"
22
+ export * from "./join"
14
23
  export * from "./logger"
15
- export * from "./molecule"
24
+ export * from "./realm"
16
25
  export * from "./selector"
17
26
  export * from "./set-state"
18
27
  export * from "./silo"
@@ -21,58 +30,123 @@ export * from "./timeline"
21
30
  export * from "./transaction"
22
31
  export * from "./validators"
23
32
 
33
+ /**
34
+ * @public
35
+ * A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
36
+ *
37
+ * While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank.
38
+ *
39
+ * Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}.
40
+ *
41
+ * Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}.
42
+ *
43
+ * Tokens are fully serializable, so they can be passed between processes.
44
+ */
45
+ export type AtomIOToken =
46
+ | ReadableFamilyToken<any, any>
47
+ | ReadableToken<any>
48
+ | TimelineToken<any>
49
+ | TransactionToken<any>
50
+
51
+ /** @public */
24
52
  export type RegularAtomToken<T, K extends Canonical = any> = {
53
+ /** The unique identifier of the atom. */
25
54
  key: string
55
+ /** Discriminator. */
26
56
  type: `atom`
57
+ /** Present if the atom belongs to a family. */
27
58
  family?: FamilyMetadata<K>
59
+ /** Never present. This is a marker that preserves the type of the atom's value. */
28
60
  __T?: T
29
61
  }
62
+ /** @public */
30
63
  export type MutableAtomToken<
31
64
  T extends Transceiver<any>,
32
65
  J extends Json.Serializable,
33
66
  K extends Canonical = any,
34
67
  > = {
68
+ /** The unique identifier of the atom. */
35
69
  key: string
70
+ /** Discriminator. */
36
71
  type: `mutable_atom`
72
+ /** Present if the atom belongs to a family. */
37
73
  family?: FamilyMetadata<K>
74
+ /** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
38
75
  __J?: J
76
+ /** Never present. This is a marker that preserves the type of the atom's transceiver value. */
39
77
  __U?: T extends Transceiver<infer Update> ? Update : never
40
78
  }
79
+ /** @public */
41
80
  export type AtomToken<T, K extends Canonical = any> =
42
81
  | MutableAtomToken<T extends Transceiver<any> ? T : never, any, K>
43
82
  | RegularAtomToken<T, K>
44
83
 
84
+ /** @public */
45
85
  export type WritableSelectorToken<T, K extends Canonical = any> = {
86
+ /** The unique identifier of the selector. */
46
87
  key: string
88
+ /** Discriminator. */
47
89
  type: `selector`
90
+ /** Present if the selector belongs to a family. */
48
91
  family?: FamilyMetadata<K>
92
+ /** Never present. This is a marker that preserves the type of the selector's value. */
49
93
  __T?: T
50
94
  }
95
+ /** @public */
51
96
  export type ReadonlySelectorToken<T, K extends Canonical = any> = {
97
+ /** The unique identifier of the selector. */
52
98
  key: string
99
+ /** Discriminator. */
53
100
  type: `readonly_selector`
101
+ /** Present if the selector belongs to a family. */
54
102
  family?: FamilyMetadata<K>
103
+ /** Never present. This is a marker that preserves the type of the selector's value. */
55
104
  __T?: T
56
105
  }
106
+ /** @public */
57
107
  export type SelectorToken<T, K extends Canonical = any> =
58
108
  | ReadonlySelectorToken<T, K>
59
109
  | WritableSelectorToken<T, K>
60
110
 
111
+ /**
112
+ * @public
113
+ * These states can be set.
114
+ */
61
115
  export type WritableToken<T, K extends Canonical = any> =
62
116
  | AtomToken<T, K>
63
117
  | WritableSelectorToken<T, K>
118
+ /**
119
+ * @public
120
+ * These states cannot be set.
121
+ */
64
122
  export type ReadableToken<T, K extends Canonical = any> =
65
123
  | AtomToken<T, K>
66
124
  | SelectorToken<T, K>
67
125
 
126
+ /**
127
+ * @public
128
+ * States belonging to this family can be set.
129
+ */
68
130
  export type WritableFamilyToken<T, K extends Canonical> =
69
131
  | AtomFamilyToken<T, K>
70
132
  | WritableSelectorFamilyToken<T, K>
133
+ /**
134
+ * @public
135
+ * States belonging to this family cannot be set.
136
+ */
71
137
  export type ReadableFamilyToken<T, K extends Canonical> =
72
138
  | AtomFamilyToken<T, K>
73
139
  | SelectorFamilyToken<T, K>
74
140
 
141
+ /**
142
+ * @public
143
+ * Identifies a state's connection to its family.
144
+ */
75
145
  export type FamilyMetadata<K extends Canonical = any> = {
146
+ /** The family's unique key. */
76
147
  key: string
148
+ /** The family member's unique identifier, in the form of a string. */
77
149
  subKey: stringified<K>
78
150
  }
151
+
152
+ export type Loadable<T> = Promise<T> | T