atom.io 0.25.2 → 0.25.4

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 (46) hide show
  1. package/dist/index.d.ts +38 -13
  2. package/ephemeral/dist/index.d.ts +45 -0
  3. package/ephemeral/src/find-state.ts +45 -5
  4. package/internal/dist/index.cjs +7 -6
  5. package/internal/dist/index.d.ts +12 -6
  6. package/internal/dist/index.js +7 -6
  7. package/internal/src/index.ts +1 -0
  8. package/internal/src/ingest-updates/index.ts +1 -1
  9. package/internal/src/molecule/make-molecule-in-store.ts +2 -3
  10. package/internal/src/molecule/molecule-internal.ts +2 -2
  11. package/internal/src/store/deposit.ts +1 -1
  12. package/internal/src/store/store.ts +6 -7
  13. package/internal/src/store/withdraw.ts +1 -1
  14. package/internal/src/subscribe/subscribe-to-transaction.ts +2 -2
  15. package/internal/src/timeline/create-timeline.ts +1 -2
  16. package/internal/src/transaction/act-upon-store.ts +2 -1
  17. package/internal/src/transaction/apply-transaction.ts +1 -2
  18. package/internal/src/transaction/build-transaction.ts +2 -1
  19. package/internal/src/transaction/create-transaction.ts +1 -1
  20. package/internal/src/transaction/index.ts +3 -1
  21. package/internal/src/transaction/is-root-store.ts +1 -2
  22. package/internal/src/utility-types.ts +5 -0
  23. package/introspection/dist/index.d.ts +2 -2
  24. package/introspection/src/attach-introspection-states.ts +1 -2
  25. package/introspection/src/attach-transaction-index.ts +2 -2
  26. package/introspection/src/attach-transaction-logs.ts +2 -6
  27. package/package.json +18 -19
  28. package/react/dist/index.cjs +29 -11
  29. package/react/dist/index.js +30 -12
  30. package/react/src/parse-state-overloads.ts +43 -0
  31. package/react/src/use-i.ts +6 -11
  32. package/react/src/use-o.ts +7 -21
  33. package/react-devtools/dist/index.d.ts +2 -2
  34. package/react-devtools/src/TransactionIndex.tsx +1 -1
  35. package/react-devtools/src/Updates.tsx +1 -1
  36. package/realtime-client/dist/index.d.ts +3 -3
  37. package/realtime-client/src/server-action.ts +1 -1
  38. package/realtime-client/src/sync-continuity.ts +2 -2
  39. package/realtime-react/dist/index.d.ts +2 -2
  40. package/realtime-react/src/use-server-action.ts +2 -1
  41. package/src/atom.ts +17 -0
  42. package/src/index.ts +0 -6
  43. package/src/molecule.ts +2 -4
  44. package/src/set-state.ts +16 -0
  45. package/src/subscribe.ts +1 -3
  46. package/src/transaction.ts +1 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atom.io",
3
- "version": "0.25.2",
3
+ "version": "0.25.4",
4
4
  "description": "Composable and testable reactive data library.",
5
5
  "homepage": "https://atom.io.fyi",
6
6
  "sideEffects": false,
@@ -49,43 +49,42 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@testing-library/react": "16.0.0",
52
- "@types/eslint": "npm:@types/eslint@8.56.10",
53
- "@types/eslint-v9": "npm:@types/eslint@8.56.10",
52
+ "@types/eslint": "npm:@types/eslint@9.6.0",
53
+ "@types/eslint-v9": "npm:@types/eslint@9.6.0",
54
54
  "@types/estree": "1.0.5",
55
55
  "@types/http-proxy": "1.17.14",
56
56
  "@types/npmlog": "7.0.0",
57
57
  "@types/react": "18.3.3",
58
58
  "@types/tmp": "0.2.6",
59
- "@typescript-eslint/parser": "7.14.1",
60
- "@typescript-eslint/rule-tester": "7.14.1",
61
- "@vitest/coverage-v8": "1.6.0",
62
- "@vitest/ui": "1.6.0",
59
+ "@typescript-eslint/parser": "7.17.0",
60
+ "@typescript-eslint/rule-tester": "7.17.0",
61
+ "@vitest/coverage-v8": "2.0.4",
62
+ "@vitest/ui": "2.0.4",
63
63
  "concurrently": "8.2.2",
64
- "drizzle-kit": "0.22.7",
65
- "drizzle-orm": "0.31.2",
64
+ "drizzle-kit": "0.23.0",
65
+ "drizzle-orm": "0.32.0",
66
66
  "eslint": "npm:eslint@8.57.0",
67
- "eslint-v9": "npm:eslint@9.6.0",
68
- "framer-motion": "11.2.12",
67
+ "eslint-v9": "npm:eslint@9.7.0",
68
+ "framer-motion": "11.3.8",
69
69
  "happy-dom": "14.12.3",
70
70
  "http-proxy": "1.18.1",
71
71
  "npmlog": "7.0.1",
72
72
  "postgres": "3.4.4",
73
- "preact": "10.22.0",
73
+ "preact": "10.22.1",
74
74
  "react": "18.3.1",
75
75
  "react-dom": "18.3.1",
76
- "react-router-dom": "6.24.0",
76
+ "react-router-dom": "6.25.1",
77
77
  "socket.io": "4.7.5",
78
78
  "socket.io-client": "4.7.5",
79
79
  "tmp": "0.2.3",
80
- "tsup": "8.1.0",
81
- "typescript": "5.5.2",
82
- "vite": "5.3.2",
80
+ "tsup": "8.2.2",
81
+ "typescript": "5.5.3",
82
+ "vite": "5.3.4",
83
83
  "vite-tsconfig-paths": "4.3.2",
84
- "vitest": "1.6.0"
84
+ "vitest": "2.0.4"
85
85
  },
86
86
  "main": "dist/index.js",
87
87
  "types": "dist/index.d.ts",
88
- "module": "dist/index.mjs",
89
88
  "files": [
90
89
  "dist",
91
90
  "src",
@@ -252,7 +251,7 @@
252
251
  "scripts": {
253
252
  "manifest": "tsx __scripts__/manifest-build.node.ts",
254
253
  "clean:build": "find . -type d -name 'dist' -not -path '*/node_modules/*' | xargs rm -rf",
255
- "build": "bun run clean:build && concurrently \"npm:build:*\"",
254
+ "build": "bun run clean:build && concurrently \"bun:build:*\"",
256
255
  "build:main": "tsup",
257
256
  "build:types": "tsup --dts",
258
257
  "build:data": "cd data && tsup",
@@ -28,28 +28,46 @@ var React5__namespace = /*#__PURE__*/_interopNamespace(React5);
28
28
  // react/src/store-context.tsx
29
29
  var StoreContext = React5__namespace.createContext(internal.IMPLICIT.STORE);
30
30
  var StoreProvider = ({ children, store = internal.IMPLICIT.STORE }) => /* @__PURE__ */ jsxRuntime.jsx(StoreContext.Provider, { value: store, children });
31
- function useI(token, key) {
31
+ function parseStateOverloads(store, ...rest) {
32
+ let token;
33
+ if (rest.length === 2) {
34
+ const family = rest[0];
35
+ const key = rest[1];
36
+ if (store.config.lifespan === `immortal`) {
37
+ const maybeToken = internal.seekInStore(family, key, store);
38
+ if (!maybeToken) {
39
+ throw new internal.NotFoundError(family, key, store);
40
+ }
41
+ token = maybeToken;
42
+ } else {
43
+ token = internal.findInStore(family, key, store);
44
+ }
45
+ } else {
46
+ token = rest[0];
47
+ }
48
+ return token;
49
+ }
50
+
51
+ // react/src/use-i.ts
52
+ function useI(...params) {
32
53
  const store = React5__namespace.useContext(StoreContext);
33
- const stateToken = token.type === `atom_family` || token.type === `mutable_atom_family` || token.type === `selector_family` ? internal.findInStore(token, key, store) : token;
54
+ const token = parseStateOverloads(store, ...params);
34
55
  const setter = React5__namespace.useRef(null);
35
56
  if (setter.current === null) {
36
57
  setter.current = (next) => {
37
- internal.setIntoStore(stateToken, next, store);
58
+ internal.setIntoStore(token, next, store);
38
59
  };
39
60
  }
40
61
  return setter.current;
41
62
  }
42
- function useO(token, key) {
63
+ function useO(...params) {
43
64
  const store = React5__namespace.useContext(StoreContext);
44
- const stateToken = token.type === `atom_family` || token.type === `mutable_atom_family` || token.type === `selector_family` || token.type === `readonly_selector_family` ? internal.seekInStore(token, key, store) : token;
45
- if (!stateToken) {
46
- throw new internal.NotFoundError(token, store);
47
- }
65
+ const token = parseStateOverloads(store, ...params);
48
66
  const id = React5__namespace.useId();
49
67
  return React5__namespace.useSyncExternalStore(
50
- (dispatch) => internal.subscribeToState(stateToken, dispatch, `use-o:${id}`, store),
51
- () => internal.getFromStore(stateToken, store),
52
- () => internal.getFromStore(stateToken, store)
68
+ (dispatch) => internal.subscribeToState(token, dispatch, `use-o:${id}`, store),
69
+ () => internal.getFromStore(token, store),
70
+ () => internal.getFromStore(token, store)
53
71
  );
54
72
  }
55
73
 
@@ -1,33 +1,51 @@
1
1
  import '../../dist/chunk-S4N6XNPH.js';
2
- import { IMPLICIT, findInStore, setIntoStore, seekInStore, NotFoundError, subscribeToState, getFromStore, getJsonToken, withdraw, subscribeToTimeline } from 'atom.io/internal';
2
+ import { IMPLICIT, setIntoStore, subscribeToState, getFromStore, findInStore, getJsonToken, withdraw, subscribeToTimeline, seekInStore, NotFoundError } from 'atom.io/internal';
3
3
  import * as React5 from 'react';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
  import { undo, redo } from 'atom.io';
6
6
 
7
7
  var StoreContext = React5.createContext(IMPLICIT.STORE);
8
8
  var StoreProvider = ({ children, store = IMPLICIT.STORE }) => /* @__PURE__ */ jsx(StoreContext.Provider, { value: store, children });
9
- function useI(token, key) {
9
+ function parseStateOverloads(store, ...rest) {
10
+ let token;
11
+ if (rest.length === 2) {
12
+ const family = rest[0];
13
+ const key = rest[1];
14
+ if (store.config.lifespan === `immortal`) {
15
+ const maybeToken = seekInStore(family, key, store);
16
+ if (!maybeToken) {
17
+ throw new NotFoundError(family, key, store);
18
+ }
19
+ token = maybeToken;
20
+ } else {
21
+ token = findInStore(family, key, store);
22
+ }
23
+ } else {
24
+ token = rest[0];
25
+ }
26
+ return token;
27
+ }
28
+
29
+ // react/src/use-i.ts
30
+ function useI(...params) {
10
31
  const store = React5.useContext(StoreContext);
11
- const stateToken = token.type === `atom_family` || token.type === `mutable_atom_family` || token.type === `selector_family` ? findInStore(token, key, store) : token;
32
+ const token = parseStateOverloads(store, ...params);
12
33
  const setter = React5.useRef(null);
13
34
  if (setter.current === null) {
14
35
  setter.current = (next) => {
15
- setIntoStore(stateToken, next, store);
36
+ setIntoStore(token, next, store);
16
37
  };
17
38
  }
18
39
  return setter.current;
19
40
  }
20
- function useO(token, key) {
41
+ function useO(...params) {
21
42
  const store = React5.useContext(StoreContext);
22
- const stateToken = token.type === `atom_family` || token.type === `mutable_atom_family` || token.type === `selector_family` || token.type === `readonly_selector_family` ? seekInStore(token, key, store) : token;
23
- if (!stateToken) {
24
- throw new NotFoundError(token, store);
25
- }
43
+ const token = parseStateOverloads(store, ...params);
26
44
  const id = React5.useId();
27
45
  return React5.useSyncExternalStore(
28
- (dispatch) => subscribeToState(stateToken, dispatch, `use-o:${id}`, store),
29
- () => getFromStore(stateToken, store),
30
- () => getFromStore(stateToken, store)
46
+ (dispatch) => subscribeToState(token, dispatch, `use-o:${id}`, store),
47
+ () => getFromStore(token, store),
48
+ () => getFromStore(token, store)
31
49
  );
32
50
  }
33
51
 
@@ -0,0 +1,43 @@
1
+ import type {
2
+ ReadableFamilyToken,
3
+ ReadableToken,
4
+ WritableFamilyToken,
5
+ WritableToken,
6
+ } from "atom.io"
7
+ import type { Store } from "atom.io/internal"
8
+ import { findInStore, NotFoundError, seekInStore } from "atom.io/internal"
9
+ import type { Json } from "atom.io/json"
10
+
11
+ export function parseStateOverloads<T, K extends Json.Serializable>(
12
+ store: Store,
13
+ ...rest: [WritableFamilyToken<T, K>, K] | [WritableToken<T>]
14
+ ): WritableToken<T>
15
+
16
+ export function parseStateOverloads<T, K extends Json.Serializable>(
17
+ store: Store,
18
+ ...rest: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]
19
+ ): ReadableToken<T>
20
+
21
+ export function parseStateOverloads<T, K extends Json.Serializable>(
22
+ store: Store,
23
+ ...rest: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]
24
+ ): ReadableToken<T> {
25
+ let token: ReadableToken<any>
26
+ if (rest.length === 2) {
27
+ const family = rest[0]
28
+ const key = rest[1]
29
+
30
+ if (store.config.lifespan === `immortal`) {
31
+ const maybeToken = seekInStore(family, key, store)
32
+ if (!maybeToken) {
33
+ throw new NotFoundError(family, key, store)
34
+ }
35
+ token = maybeToken
36
+ } else {
37
+ token = findInStore(family, key, store)
38
+ }
39
+ } else {
40
+ token = rest[0]
41
+ }
42
+ return token
43
+ }
@@ -1,8 +1,9 @@
1
- import type { ReadableToken, WritableFamilyToken, WritableToken } from "atom.io"
2
- import { findInStore, setIntoStore } from "atom.io/internal"
1
+ import type { WritableFamilyToken, WritableToken } from "atom.io"
2
+ import { setIntoStore } from "atom.io/internal"
3
3
  import type { Json } from "atom.io/json"
4
4
  import * as React from "react"
5
5
 
6
+ import { parseStateOverloads } from "./parse-state-overloads"
6
7
  import { StoreContext } from "./store-context"
7
8
 
8
9
  export function useI<T>(
@@ -15,22 +16,16 @@ export function useI<T, K extends Json.Serializable>(
15
16
  ): <New extends T>(next: New | ((old: T) => New)) => void
16
17
 
17
18
  export function useI<T, K extends Json.Serializable>(
18
- token: WritableFamilyToken<T, K> | WritableToken<T>,
19
- key?: K,
19
+ ...params: [WritableFamilyToken<T, K>, K] | [WritableToken<T>]
20
20
  ): <New extends T>(next: New | ((old: T) => New)) => void {
21
21
  const store = React.useContext(StoreContext)
22
- const stateToken: ReadableToken<any> =
23
- token.type === `atom_family` ||
24
- token.type === `mutable_atom_family` ||
25
- token.type === `selector_family`
26
- ? findInStore(token, key as K, store)
27
- : token
22
+ const token = parseStateOverloads(store, ...params)
28
23
  const setter: React.MutableRefObject<
29
24
  (<New extends T>(next: New | ((old: T) => New)) => void) | null
30
25
  > = React.useRef(null)
31
26
  if (setter.current === null) {
32
27
  setter.current = (next) => {
33
- setIntoStore(stateToken, next, store)
28
+ setIntoStore(token, next, store)
34
29
  }
35
30
  }
36
31
  return setter.current
@@ -1,13 +1,9 @@
1
1
  import type { ReadableFamilyToken, ReadableToken } from "atom.io"
2
- import {
3
- getFromStore,
4
- NotFoundError,
5
- seekInStore,
6
- subscribeToState,
7
- } from "atom.io/internal"
2
+ import { getFromStore, subscribeToState } from "atom.io/internal"
8
3
  import type { Json } from "atom.io/json"
9
4
  import * as React from "react"
10
5
 
6
+ import { parseStateOverloads } from "./parse-state-overloads"
11
7
  import { StoreContext } from "./store-context"
12
8
 
13
9
  export function useO<T>(token: ReadableToken<T>): T
@@ -18,24 +14,14 @@ export function useO<T, K extends Json.Serializable>(
18
14
  ): T
19
15
 
20
16
  export function useO<T, K extends Json.Serializable>(
21
- token: ReadableFamilyToken<T, K> | ReadableToken<T>,
22
- key?: K,
17
+ ...params: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]
23
18
  ): T {
24
19
  const store = React.useContext(StoreContext)
25
- const stateToken: ReadableToken<any> | undefined =
26
- token.type === `atom_family` ||
27
- token.type === `mutable_atom_family` ||
28
- token.type === `selector_family` ||
29
- token.type === `readonly_selector_family`
30
- ? seekInStore(token, key as K, store)
31
- : token
32
- if (!stateToken) {
33
- throw new NotFoundError(token, store)
34
- }
20
+ const token = parseStateOverloads(store, ...params)
35
21
  const id = React.useId()
36
22
  return React.useSyncExternalStore<T>(
37
- (dispatch) => subscribeToState(stateToken, dispatch, `use-o:${id}`, store),
38
- () => getFromStore(stateToken, store),
39
- () => getFromStore(stateToken, store),
23
+ (dispatch) => subscribeToState(token, dispatch, `use-o:${id}`, store),
24
+ () => getFromStore(token, store),
25
+ () => getFromStore(token, store),
40
26
  )
41
27
  }
@@ -61,8 +61,8 @@ declare const AtomIODevtools: () => JSX.Element;
61
61
 
62
62
  declare const atomIndex: atom_io.ReadonlySelectorToken<AtomTokenIndex>;
63
63
  declare const selectorIndex: atom_io.ReadonlySelectorToken<SelectorTokenIndex>;
64
- declare const transactionIndex: atom_io.ReadonlySelectorToken<atom_io.TransactionToken<atom_io.Func>[]>;
65
- declare const findTransactionLogState: atom_io.ReadonlySelectorFamilyToken<atom_io.TransactionUpdate<atom_io.Func>[], string>;
64
+ declare const transactionIndex: atom_io.ReadonlySelectorToken<atom_io.TransactionToken<Internal.Func>[]>;
65
+ declare const findTransactionLogState: atom_io.ReadonlySelectorFamilyToken<atom_io.TransactionUpdate<Internal.Func>[], string>;
66
66
  declare const timelineIndex: atom_io.ReadonlySelectorToken<atom_io.TimelineToken<any>[]>;
67
67
  declare const findTimelineState: atom_io.ReadonlySelectorFamilyToken<Internal.Timeline<any>, string>;
68
68
  declare const devtoolsAreOpenState: atom_io.RegularAtomToken<boolean>;
@@ -1,11 +1,11 @@
1
1
  import type {
2
- Func,
3
2
  ReadonlySelectorToken,
4
3
  RegularAtomToken,
5
4
  TransactionToken,
6
5
  TransactionUpdate,
7
6
  } from "atom.io"
8
7
  import { findState } from "atom.io/ephemeral"
8
+ import type { Func } from "atom.io/internal"
9
9
  import { useI, useO } from "atom.io/react"
10
10
  import type { FC } from "react"
11
11
 
@@ -1,9 +1,9 @@
1
1
  import type {
2
- Func,
3
2
  KeyedStateUpdate,
4
3
  TimelineUpdate,
5
4
  TransactionUpdate,
6
5
  } from "atom.io"
6
+ import type { Func } from "atom.io/internal"
7
7
  import * as React from "react"
8
8
 
9
9
  import { discoverType } from "~/packages/anvl/src/refinement/refinery"
@@ -1,6 +1,6 @@
1
1
  import * as AtomIO from 'atom.io';
2
2
  import * as Internal from 'atom.io/internal';
3
- import { Store, Transceiver } from 'atom.io/internal';
3
+ import { Store, Transceiver, Func } from 'atom.io/internal';
4
4
  import { Json } from 'atom.io/json';
5
5
  import { Socket } from 'socket.io-client';
6
6
  import { ContinuityToken } from 'atom.io/realtime';
@@ -26,8 +26,8 @@ declare const myUsernameState: AtomIO.RegularAtomToken<string | null>;
26
26
  declare const optimisticUpdateQueue: AtomIO.RegularAtomToken<AtomIO.TransactionUpdate<any>[]>;
27
27
  declare const confirmedUpdateQueue: AtomIO.RegularAtomToken<AtomIO.TransactionUpdate<any>[]>;
28
28
 
29
- declare function serverAction<F extends AtomIO.Func>(token: AtomIO.TransactionToken<F>, socket: Socket, store: Internal.Store): () => void;
29
+ declare function serverAction<F extends Internal.Func>(token: AtomIO.TransactionToken<F>, socket: Socket, store: Internal.Store): () => void;
30
30
 
31
- declare function syncContinuity<F extends AtomIO.Func>(continuity: ContinuityToken, socket: Socket, store: Store): () => void;
31
+ declare function syncContinuity<F extends Func>(continuity: ContinuityToken, socket: Socket, store: Store): () => void;
32
32
 
33
33
  export { confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue, pullAtom, pullAtomFamilyMember, pullMutableAtom, pullMutableAtomFamilyMember, pullSelector, pullSelectorFamilyMember, pushState, serverAction, syncContinuity };
@@ -2,7 +2,7 @@ import type * as AtomIO from "atom.io"
2
2
  import * as Internal from "atom.io/internal"
3
3
  import type { Socket } from "socket.io-client"
4
4
 
5
- export function serverAction<F extends AtomIO.Func>(
5
+ export function serverAction<F extends Internal.Func>(
6
6
  token: AtomIO.TransactionToken<F>,
7
7
  socket: Socket,
8
8
  store: Internal.Store,
@@ -1,5 +1,5 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { Store } from "atom.io/internal"
2
+ import type { Func, Store } from "atom.io/internal"
3
3
  import {
4
4
  actUponStore,
5
5
  assignTransactionToContinuity,
@@ -21,7 +21,7 @@ import {
21
21
  } from "atom.io/realtime-client"
22
22
  import type { Socket } from "socket.io-client"
23
23
 
24
- export function syncContinuity<F extends AtomIO.Func>(
24
+ export function syncContinuity<F extends Func>(
25
25
  continuity: ContinuityToken,
26
26
  socket: Socket,
27
27
  store: Store,
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { Socket } from 'socket.io-client';
3
3
  import * as AtomIO from 'atom.io';
4
4
  import { Json } from 'atom.io/json';
5
- import { Transceiver } from 'atom.io/internal';
5
+ import { Transceiver, Func } from 'atom.io/internal';
6
6
  import { ContinuityToken } from 'atom.io/realtime';
7
7
 
8
8
  type RealtimeReactStore = {
@@ -32,7 +32,7 @@ declare function usePullSelectorFamilyMember<T, K extends Json.Serializable, Key
32
32
 
33
33
  declare function usePush<J extends Json.Serializable>(token: AtomIO.WritableToken<J>): <New extends J>(next: New | ((old: J) => New)) => void;
34
34
 
35
- declare function useServerAction<F extends AtomIO.Func>(token: AtomIO.TransactionToken<F>): (...parameters: Parameters<F>) => ReturnType<F>;
35
+ declare function useServerAction<F extends Func>(token: AtomIO.TransactionToken<F>): (...parameters: Parameters<F>) => ReturnType<F>;
36
36
 
37
37
  declare function useSyncContinuity(token: ContinuityToken): void;
38
38
 
@@ -1,4 +1,5 @@
1
1
  import type * as AtomIO from "atom.io"
2
+ import type { Func } from "atom.io/internal"
2
3
  import { actUponStore, arbitrary } from "atom.io/internal"
3
4
  import { StoreContext } from "atom.io/react"
4
5
  import * as RTC from "atom.io/realtime-client"
@@ -6,7 +7,7 @@ import * as React from "react"
6
7
 
7
8
  import { useRealtimeService } from "./use-realtime-service"
8
9
 
9
- export function useServerAction<F extends AtomIO.Func>(
10
+ export function useServerAction<F extends Func>(
10
11
  token: AtomIO.TransactionToken<F>,
11
12
  ): (...parameters: Parameters<F>) => ReturnType<F> {
12
13
  const store = React.useContext(StoreContext)
package/src/atom.ts CHANGED
@@ -35,10 +35,27 @@ export type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serial
35
35
  mutable: true
36
36
  }
37
37
 
38
+ /**
39
+ * @public
40
+ * Declare a mutable global reactive variable.
41
+ * @param options - Configuration for this mutable atom.
42
+ * @returns
43
+ * The token for your mutable atom.
44
+ * @overload Mutable
45
+ */
38
46
  export function atom<T extends Transceiver<any>, J extends Json.Serializable>(
39
47
  options: MutableAtomOptions<T, J>,
40
48
  ): MutableAtomToken<T, J>
49
+ /**
50
+ * @public
51
+ * Declare a regular global reactive variable.
52
+ * @param options - Configuration for this regular atom.
53
+ * @returns
54
+ * The token for your regular atom.
55
+ * @overload Regular
56
+ */
41
57
  export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>
58
+
42
59
  export function atom(
43
60
  options: MutableAtomOptions<any, any> | RegularAtomOptions<any>,
44
61
  ): AtomToken<any> {
package/src/index.ts CHANGED
@@ -22,12 +22,6 @@ export * from "./timeline"
22
22
  export * from "./transaction"
23
23
  export * from "./validators"
24
24
 
25
- export type Func = (...parameters: any[]) => any
26
-
27
- export type Flat<R extends { [K in PropertyKey]: any }> = {
28
- [K in keyof R]: R[K]
29
- }
30
-
31
25
  export type RegularAtomToken<T> = {
32
26
  key: string
33
27
  type: `atom`
package/src/molecule.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type {
2
2
  ActorToolkit,
3
- Flat,
4
3
  MoleculeCreation,
5
4
  MoleculeDisposal,
6
5
  MutableAtomFamilyToken,
@@ -17,7 +16,7 @@ import type {
17
16
  WritableToken,
18
17
  } from "atom.io"
19
18
  import type { JoinToken } from "atom.io/data"
20
- import type { Store, Subject, Transceiver } from "atom.io/internal"
19
+ import type { Flat, Store, Subject, Transceiver } from "atom.io/internal"
21
20
  import {
22
21
  createMoleculeFamily,
23
22
  IMPLICIT,
@@ -92,7 +91,7 @@ export type MoleculeFamily<M extends MoleculeConstructor> = Flat<
92
91
  }
93
92
  >
94
93
  export type MoleculeToken<M extends MoleculeConstructor> = {
95
- key: MK<M>
94
+ key: MoleculeKey<M>
96
95
  type: `molecule`
97
96
  family?: MoleculeFamilyToken<M>
98
97
  __M?: M
@@ -120,7 +119,6 @@ export type MoleculeType<T extends MoleculeFamilyToken<any>> =
120
119
  ? M
121
120
  : never
122
121
  export type MoleculeKey<M extends MoleculeConstructor> = InstanceType<M>[`key`]
123
- export type MK<M extends MoleculeConstructor> = MoleculeKey<M>
124
122
 
125
123
  export function makeRootMolecule(
126
124
  key: string,
package/src/set-state.ts CHANGED
@@ -3,11 +3,27 @@ import type { Json } from "rel8"
3
3
 
4
4
  import type { WritableFamilyToken, WritableToken } from "."
5
5
 
6
+ /**
7
+ * @public
8
+ * Set the value of a state into the implicit store.
9
+ * @param token - The unique identifier of the state to set.
10
+ * @param value - The new value of the state.
11
+ * @overload Default
12
+ * @default
13
+ */
6
14
  export function setState<T, New extends T>(
7
15
  token: WritableToken<T>,
8
16
  value: New | ((oldValue: T) => New),
9
17
  ): void
10
18
 
19
+ /**
20
+ * @public
21
+ * Set the value of a state into the implicit store.
22
+ * @param token - The unique identifier of a state family.
23
+ * @param key - The key of the state to set.
24
+ * @param value - The new value of the state.
25
+ * @overload Streamlined
26
+ */
11
27
  export function setState<T, K extends Json.Serializable, New extends T>(
12
28
  token: WritableFamilyToken<T, K>,
13
29
  key: K,
package/src/subscribe.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Store } from "atom.io/internal"
1
+ import type { Flat, Func, Store } from "atom.io/internal"
2
2
  import {
3
3
  arbitrary,
4
4
  IMPLICIT,
@@ -9,8 +9,6 @@ import {
9
9
 
10
10
  import type {
11
11
  FamilyMetadata,
12
- Flat,
13
- Func,
14
12
  ReadableToken,
15
13
  TimelineManageable,
16
14
  TimelineToken,
@@ -9,7 +9,7 @@ import type {
9
9
  } from "atom.io"
10
10
  import type { findState } from "atom.io/ephemeral"
11
11
  import type { seekState } from "atom.io/immortal"
12
- import type { EnvironmentData, Transceiver } from "atom.io/internal"
12
+ import type { EnvironmentData, Func, Transceiver } from "atom.io/internal"
13
13
  import {
14
14
  actUponStore,
15
15
  arbitrary,
@@ -20,11 +20,9 @@ import type { Json } from "atom.io/json"
20
20
 
21
21
  import type {
22
22
  disposeState,
23
- Func,
24
23
  KeyedStateUpdate,
25
24
  MutableAtomToken,
26
25
  ReadableToken,
27
- ReadonlySelectorToken,
28
26
  TokenType,
29
27
  WritableSelectorToken,
30
28
  WritableToken,