atom.io 0.35.0 → 0.36.1

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 (133) hide show
  1. package/dist/eslint-plugin/index.d.ts +2 -18
  2. package/dist/eslint-plugin/index.d.ts.map +1 -1
  3. package/dist/eslint-plugin/index.js +4 -141
  4. package/dist/eslint-plugin/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +100 -78
  6. package/dist/internal/index.d.ts.map +1 -1
  7. package/dist/internal/index.js +180 -163
  8. package/dist/internal/index.js.map +1 -1
  9. package/dist/introspection/index.d.ts +5 -6
  10. package/dist/introspection/index.d.ts.map +1 -1
  11. package/dist/introspection/index.js +2 -3
  12. package/dist/introspection/index.js.map +1 -1
  13. package/dist/json/index.d.ts +2 -10
  14. package/dist/json/index.d.ts.map +1 -1
  15. package/dist/json/index.js +1 -31
  16. package/dist/json/index.js.map +1 -1
  17. package/dist/main/index.d.ts +38 -39
  18. package/dist/main/index.d.ts.map +1 -1
  19. package/dist/main/index.js +15 -16
  20. package/dist/main/index.js.map +1 -1
  21. package/dist/react/index.d.ts +4 -4
  22. package/dist/react/index.d.ts.map +1 -1
  23. package/dist/react/index.js.map +1 -1
  24. package/dist/react-devtools/index.js.map +1 -1
  25. package/dist/realtime/index.d.ts +4 -4
  26. package/dist/realtime/index.d.ts.map +1 -1
  27. package/dist/realtime/index.js +2 -6
  28. package/dist/realtime/index.js.map +1 -1
  29. package/dist/realtime-client/index.d.ts +7 -8
  30. package/dist/realtime-client/index.d.ts.map +1 -1
  31. package/dist/realtime-client/index.js +3 -4
  32. package/dist/realtime-client/index.js.map +1 -1
  33. package/dist/realtime-react/index.d.ts +4 -4
  34. package/dist/realtime-react/index.d.ts.map +1 -1
  35. package/dist/realtime-react/index.js.map +1 -1
  36. package/dist/realtime-server/index.d.ts +18 -18
  37. package/dist/realtime-server/index.d.ts.map +1 -1
  38. package/dist/realtime-server/index.js +5 -9
  39. package/dist/realtime-server/index.js.map +1 -1
  40. package/dist/transceivers/set-rtx/index.d.ts +9 -2
  41. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  42. package/dist/transceivers/set-rtx/index.js +3 -0
  43. package/dist/transceivers/set-rtx/index.js.map +1 -1
  44. package/package.json +6 -6
  45. package/src/eslint-plugin/index.ts +0 -1
  46. package/src/eslint-plugin/rules/explicit-state-types.ts +8 -1
  47. package/src/eslint-plugin/rules/index.ts +0 -1
  48. package/src/internal/atom/create-regular-atom.ts +5 -5
  49. package/src/internal/atom/dispose-atom.ts +1 -0
  50. package/src/internal/atom/has-role.ts +12 -0
  51. package/src/internal/atom/index.ts +1 -0
  52. package/src/internal/caching.ts +38 -16
  53. package/src/internal/families/find-in-store.ts +4 -5
  54. package/src/internal/families/get-family-of-token.ts +4 -5
  55. package/src/internal/families/init-family-member.ts +3 -4
  56. package/src/internal/families/seek-in-store.ts +4 -5
  57. package/src/internal/get-state/read-or-compute-value.ts +37 -16
  58. package/src/internal/index.ts +19 -21
  59. package/src/internal/ingest-updates/ingest-creation-disposal.ts +18 -15
  60. package/src/internal/ingest-updates/ingest-selector-update.ts +9 -5
  61. package/src/internal/join/get-internal-relations-from-store.ts +2 -2
  62. package/src/internal/join/join-internal.ts +10 -18
  63. package/src/internal/molecule.ts +1 -0
  64. package/src/internal/mutable/create-mutable-atom-family.ts +40 -22
  65. package/src/internal/mutable/create-mutable-atom.ts +16 -12
  66. package/src/internal/mutable/get-json-family.ts +7 -6
  67. package/src/internal/mutable/get-json-token.ts +6 -13
  68. package/src/internal/mutable/get-update-family.ts +7 -8
  69. package/src/internal/mutable/get-update-token.ts +5 -9
  70. package/src/internal/mutable/tracker-family.ts +31 -38
  71. package/src/internal/mutable/tracker.ts +86 -104
  72. package/src/internal/mutable/transceiver.ts +37 -9
  73. package/src/internal/selector/create-readonly-held-selector.ts +2 -2
  74. package/src/internal/selector/create-readonly-pure-selector.ts +2 -2
  75. package/src/internal/selector/create-writable-held-selector.ts +3 -3
  76. package/src/internal/selector/create-writable-pure-selector.ts +3 -3
  77. package/src/internal/selector/dispose-selector.ts +9 -9
  78. package/src/internal/set-state/reset-atom-or-selector.ts +11 -4
  79. package/src/internal/set-state/set-atom.ts +15 -22
  80. package/src/internal/set-state/set-into-store.ts +5 -4
  81. package/src/internal/store/counterfeit.ts +3 -4
  82. package/src/internal/store/deposit.ts +8 -11
  83. package/src/internal/store/store.ts +7 -7
  84. package/src/internal/store/withdraw.ts +8 -12
  85. package/src/internal/subscribe/subscribe-in-store.ts +2 -2
  86. package/src/internal/subscribe/subscribe-to-transaction.ts +2 -2
  87. package/src/internal/timeline/create-timeline.ts +3 -3
  88. package/src/internal/transaction/act-upon-store.ts +2 -2
  89. package/src/internal/transaction/apply-transaction.ts +2 -2
  90. package/src/internal/transaction/build-transaction.ts +2 -2
  91. package/src/internal/transaction/create-transaction.ts +3 -3
  92. package/src/internal/transaction/index.ts +2 -2
  93. package/src/internal/transaction/is-root-store.ts +4 -2
  94. package/src/internal/utility-types.ts +1 -1
  95. package/src/introspection/attach-introspection-states.ts +3 -3
  96. package/src/introspection/attach-transaction-index.ts +4 -4
  97. package/src/introspection/attach-transaction-logs.ts +4 -4
  98. package/src/introspection/auditor.ts +3 -3
  99. package/src/json/index.ts +0 -2
  100. package/src/main/atom.ts +24 -36
  101. package/src/main/dispose-state.ts +6 -5
  102. package/src/main/find-state.ts +3 -4
  103. package/src/main/get-state.ts +6 -5
  104. package/src/main/join.ts +2 -2
  105. package/src/main/logger.ts +7 -7
  106. package/src/main/reset-state.ts +3 -3
  107. package/src/main/set-state.ts +3 -3
  108. package/src/main/subscribe.ts +3 -3
  109. package/src/main/tokens.ts +8 -14
  110. package/src/main/transaction.ts +17 -13
  111. package/src/main/validators.ts +1 -1
  112. package/src/react/use-json.ts +14 -24
  113. package/src/react-devtools/TransactionIndex.tsx +3 -3
  114. package/src/react-devtools/Updates.tsx +2 -2
  115. package/src/realtime/shared-room-store.ts +11 -22
  116. package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +2 -2
  117. package/src/realtime-client/pull-mutable-atom-family-member.ts +8 -17
  118. package/src/realtime-client/pull-mutable-atom.ts +7 -14
  119. package/src/realtime-client/push-state.ts +6 -5
  120. package/src/realtime-client/server-action.ts +5 -4
  121. package/src/realtime-react/use-pull-mutable-atom.ts +3 -5
  122. package/src/realtime-react/use-pull-mutable-family-member.ts +3 -4
  123. package/src/realtime-react/use-server-action.ts +2 -2
  124. package/src/realtime-server/realtime-mutable-family-provider.ts +3 -4
  125. package/src/realtime-server/realtime-mutable-provider.ts +2 -3
  126. package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +6 -5
  127. package/src/realtime-server/realtime-server-stores/server-user-store.ts +8 -15
  128. package/src/transceivers/set-rtx/set-rtx.ts +14 -1
  129. package/src/eslint-plugin/rules/synchronous-selector-dependencies.ts +0 -140
  130. package/src/eslint-plugin/walk.ts +0 -81
  131. package/src/internal/set-state/copy-mutable-if-needed.ts +0 -27
  132. package/src/json/select-json-family.ts +0 -55
  133. package/src/json/select-json.ts +0 -19
@@ -8,12 +8,12 @@ import { newest } from "../lineage"
8
8
  import type { Store } from "../store"
9
9
  import { deposit } from "../store"
10
10
  import { Subject } from "../subject"
11
- import type { Func } from "../utility-types"
11
+ import type { Fn } from "../utility-types"
12
12
  import { abortTransaction } from "./abort-transaction"
13
13
  import { applyTransaction } from "./apply-transaction"
14
14
  import { buildTransaction } from "./build-transaction"
15
15
 
16
- export type Transaction<F extends Func> = {
16
+ export type Transaction<F extends Fn> = {
17
17
  key: string
18
18
  type: `transaction`
19
19
  install: (store: Store) => void
@@ -21,7 +21,7 @@ export type Transaction<F extends Func> = {
21
21
  run: (parameters: Parameters<F>, id?: string) => ReturnType<F>
22
22
  }
23
23
 
24
- export function createTransaction<F extends Func>(
24
+ export function createTransaction<F extends Fn>(
25
25
  store: Store,
26
26
  options: TransactionOptions<F>,
27
27
  ): TransactionToken<F> {
@@ -1,7 +1,7 @@
1
1
  import type { ActorToolkit, TransactionUpdate } from "atom.io"
2
2
 
3
3
  import type { Junction } from "../junction"
4
- import type { Func } from "../utility-types"
4
+ import type { Fn } from "../utility-types"
5
5
 
6
6
  export * from "./abort-transaction"
7
7
  export * from "./act-upon-store"
@@ -16,7 +16,7 @@ export * from "./set-epoch-number"
16
16
  export const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const
17
17
  export type TransactionPhase = (typeof TRANSACTION_PHASES)[number]
18
18
 
19
- export type TransactionProgress<F extends Func> = {
19
+ export type TransactionProgress<F extends Fn> = {
20
20
  phase: `applying` | `building`
21
21
  update: TransactionUpdate<F>
22
22
  toolkit: ActorToolkit
@@ -1,5 +1,6 @@
1
+ import type { LazyMap } from "../lazy-map"
1
2
  import type { Store } from "../store"
2
- import type { Func } from "../utility-types"
3
+ import type { Fn } from "../utility-types"
3
4
  import type { TransactionEpoch, TransactionProgress } from "."
4
5
 
5
6
  export interface RootStore extends Store {
@@ -8,9 +9,10 @@ export interface RootStore extends Store {
8
9
  child: ChildStore | null
9
10
  }
10
11
  export interface ChildStore extends Store {
11
- transactionMeta: TransactionProgress<Func>
12
+ transactionMeta: TransactionProgress<Fn>
12
13
  parent: ChildStore | RootStore
13
14
  child: ChildStore | null
15
+ valueMap: LazyMap<string, any>
14
16
  }
15
17
 
16
18
  export function isRootStore(store: Store): store is RootStore {
@@ -1,4 +1,4 @@
1
- export type Func = (...parameters: any[]) => any
1
+ export type Fn = (...parameters: any[]) => any
2
2
 
3
3
  export type Flat<R extends { [K in PropertyKey]: any }> = {
4
4
  [K in keyof R]: R[K]
@@ -6,7 +6,7 @@ import type {
6
6
  TransactionToken,
7
7
  TransactionUpdate,
8
8
  } from "atom.io"
9
- import type { Func, Store, Timeline } from "atom.io/internal"
9
+ import type { Fn, Store, Timeline } from "atom.io/internal"
10
10
 
11
11
  import { type AtomTokenIndex, attachAtomIndex } from "./attach-atom-index"
12
12
  import type { SelectorTokenIndex } from "./attach-selector-index"
@@ -20,9 +20,9 @@ import { attachTypeSelectors } from "./attach-type-selectors"
20
20
  export type IntrospectionStates = {
21
21
  atomIndex: AtomToken<AtomTokenIndex>
22
22
  selectorIndex: AtomToken<SelectorTokenIndex>
23
- transactionIndex: AtomToken<TransactionToken<Func>[]>
23
+ transactionIndex: AtomToken<TransactionToken<Fn>[]>
24
24
  transactionLogSelectors: ReadonlyPureSelectorFamilyToken<
25
- TransactionUpdate<Func>[],
25
+ TransactionUpdate<Fn>[],
26
26
  string
27
27
  >
28
28
  timelineIndex: AtomToken<TimelineToken<any>[]>
@@ -1,16 +1,16 @@
1
1
  import type { AtomToken, TransactionToken } from "atom.io"
2
- import type { Func, Store } from "atom.io/internal"
2
+ import type { Fn, Store } from "atom.io/internal"
3
3
  import { createRegularAtom, isReservedIntrospectionKey } from "atom.io/internal"
4
4
 
5
5
  export const attachTransactionIndex = (
6
6
  store: Store,
7
- ): AtomToken<TransactionToken<Func>[]> => {
8
- return createRegularAtom<TransactionToken<Func>[]>(
7
+ ): AtomToken<TransactionToken<Fn>[]> => {
8
+ return createRegularAtom<TransactionToken<Fn>[]>(
9
9
  store,
10
10
  {
11
11
  key: `🔍 Transaction Token Index`,
12
12
  default: () => {
13
- const tokens: TransactionToken<Func>[] = []
13
+ const tokens: TransactionToken<Fn>[] = []
14
14
  for (const [key] of store.transactions) {
15
15
  if (isReservedIntrospectionKey(key)) {
16
16
  continue
@@ -1,12 +1,12 @@
1
1
  import type { ReadonlyPureSelectorFamilyToken, TransactionUpdate } from "atom.io"
2
- import type { Func, Store } from "atom.io/internal"
2
+ import type { Fn, Store } from "atom.io/internal"
3
3
  import { createRegularAtomFamily, createSelectorFamily } from "atom.io/internal"
4
4
 
5
5
  export const attachTransactionLogs = (
6
6
  store: Store,
7
- ): ReadonlyPureSelectorFamilyToken<TransactionUpdate<Func>[], string> => {
7
+ ): ReadonlyPureSelectorFamilyToken<TransactionUpdate<Fn>[], string> => {
8
8
  const transactionUpdateLogAtoms = createRegularAtomFamily<
9
- TransactionUpdate<Func>[],
9
+ TransactionUpdate<Fn>[],
10
10
  string
11
11
  >(store, {
12
12
  key: `🔍 Transaction Update Log (Internal)`,
@@ -23,7 +23,7 @@ export const attachTransactionLogs = (
23
23
  ],
24
24
  })
25
25
  const findTransactionUpdateLogState = createSelectorFamily<
26
- TransactionUpdate<Func>[],
26
+ TransactionUpdate<Fn>[],
27
27
  string
28
28
  >(store, {
29
29
  key: `🔍 Transaction Update Log`,
@@ -4,7 +4,7 @@ import {
4
4
  type ReadableToken,
5
5
  type SelectorToken,
6
6
  } from "atom.io"
7
- import * as Internal from "atom.io/internal"
7
+ import { IMPLICIT, type Store } from "atom.io/internal"
8
8
 
9
9
  import type { FamilyNode } from "."
10
10
  import type { AtomTokenIndex } from "./attach-atom-index"
@@ -22,7 +22,7 @@ export type ListResourcesParam = {
22
22
  * @experimental
23
23
  */
24
24
  export class Auditor {
25
- public readonly store: Internal.Store
25
+ public readonly store: Store
26
26
  public auditorCreatedAt: number = performance.now()
27
27
  public statesCreatedAt: Map<string, number> = new Map()
28
28
  public readonly atomIndex: AtomToken<AtomTokenIndex>
@@ -37,7 +37,7 @@ export class Auditor {
37
37
  /**
38
38
  * @param {Store} store - The store to audit.
39
39
  */
40
- public constructor(store: Internal.Store = Internal.IMPLICIT.STORE) {
40
+ public constructor(store: Store = IMPLICIT.STORE) {
41
41
  this.store = store
42
42
  this.atomIndex = attachAtomIndex(this.store)
43
43
  this.selectorIndex = attachSelectorIndex(this.store)
package/src/json/index.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  export * from "./entries"
2
- export * from "./select-json"
3
- export * from "./select-json-family"
4
2
 
5
3
  export type primitive = boolean | number | string | null
6
4
 
package/src/main/atom.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Transceiver } from "atom.io/internal"
1
+ import type { ConstructorOf, Transceiver } from "atom.io/internal"
2
2
  import {
3
3
  createMutableAtom,
4
4
  createMutableAtomFamily,
@@ -6,7 +6,7 @@ import {
6
6
  createRegularAtomFamily,
7
7
  IMPLICIT,
8
8
  } from "atom.io/internal"
9
- import type { Canonical, Json, JsonInterface } from "atom.io/json"
9
+ import type { Canonical } from "atom.io/json"
10
10
 
11
11
  import type { Setter } from "./set-state"
12
12
  import type {
@@ -34,20 +34,14 @@ export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T> {
34
34
  return createRegularAtom(IMPLICIT.STORE, options, undefined)
35
35
  }
36
36
 
37
- // biome-ignore format: intersection
38
- export type MutableAtomOptions<
39
- T extends Transceiver<any>,
40
- J extends Json.Serializable,
41
- > =
42
- & JsonInterface<T, J>
43
- & {
44
- /** The unique identifier of the atom */
45
- key: string
46
- /** A function to create an initial value for the atom */
47
- default: () => T
48
- /** Hooks used to run side effects when the atom is set */
49
- effects?: AtomEffect<T>[]
50
- }
37
+ export type MutableAtomOptions<T extends Transceiver<any, any, any>> = {
38
+ /** The unique identifier of the atom */
39
+ key: string
40
+ /** A constructor for the atom's value */
41
+ class: ConstructorOf<T>
42
+ /** Hooks used to run side effects when the atom is set */
43
+ effects?: AtomEffect<T>[]
44
+ }
51
45
  /**
52
46
  * Create a mutable atom, a global reactive variable in the implicit store
53
47
  *
@@ -57,10 +51,9 @@ export type MutableAtomOptions<
57
51
  * @returns
58
52
  * A reference to the atom created: a {@link MutableAtomToken}
59
53
  */
60
- export function mutableAtom<
61
- T extends Transceiver<any>,
62
- J extends Json.Serializable,
63
- >(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J> {
54
+ export function mutableAtom<T extends Transceiver<any, any, any>>(
55
+ options: MutableAtomOptions<T>,
56
+ ): MutableAtomToken<T> {
64
57
  return createMutableAtom(IMPLICIT.STORE, options, undefined)
65
58
  }
66
59
 
@@ -105,21 +98,17 @@ export function atomFamily<T, K extends Canonical>(
105
98
  return createRegularAtomFamily(IMPLICIT.STORE, options)
106
99
  }
107
100
 
108
- // biome-ignore format: intersection
109
101
  export type MutableAtomFamilyOptions<
110
- T extends Transceiver<any>,
111
- J extends Json.Serializable,
102
+ T extends Transceiver<any, any, any>,
112
103
  K extends Canonical,
113
- > =
114
- & JsonInterface<T, J>
115
- & {
116
- /** The unique identifier of the atom family */
117
- key: string
118
- /** A function to create an initial value for each atom in the family */
119
- default: (key: K) => T
120
- /** Hooks used to run side effects when an atom in the family is set */
121
- effects?: (key: K) => AtomEffect<T>[]
122
- }
104
+ > = {
105
+ /** The unique identifier of the atom family */
106
+ key: string
107
+ /** The class of the transceiver to be created */
108
+ class: ConstructorOf<T>
109
+ /** Hooks used to run side effects when an atom in the family is set */
110
+ effects?: (key: K) => AtomEffect<T>[]
111
+ }
123
112
  /**
124
113
  * Create a family of mutable atoms, allowing for the dynamic creation and disposal of atoms.
125
114
  *
@@ -130,9 +119,8 @@ export type MutableAtomFamilyOptions<
130
119
  * A reference to the atom family created: a {@link MutableAtomFamilyToken}
131
120
  */
132
121
  export function mutableAtomFamily<
133
- T extends Transceiver<any>,
134
- J extends Json.Serializable,
122
+ T extends Transceiver<any, any, any>,
135
123
  K extends Canonical,
136
- >(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamilyToken<T, J, K> {
124
+ >(options: MutableAtomFamilyOptions<T, K>): MutableAtomFamilyToken<T, K> {
137
125
  return createMutableAtomFamily(IMPLICIT.STORE, options)
138
126
  }
@@ -1,4 +1,4 @@
1
- import * as Internal from "atom.io/internal"
1
+ import { disposeFromStore, IMPLICIT } from "atom.io/internal"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { ReadableFamilyToken, ReadableToken } from "."
@@ -19,19 +19,20 @@ export function disposeState(token: ReadableToken<any>): void
19
19
  *
20
20
  * @param token - The token of the state family to dispose
21
21
  * @param key - The unique key of the state to dispose
22
+ * @overload Streamlined
22
23
  */
23
24
  export function disposeState<K extends Canonical>(
24
25
  token: ReadableFamilyToken<any, K>,
25
26
  key: K,
26
27
  ): void
27
28
  export function disposeState(
28
- ...[token, key]:
29
+ ...params:
29
30
  | [token: ReadableFamilyToken<any, any>, key: Canonical]
30
31
  | [token: ReadableToken<any>]
31
32
  ): void {
32
- if (key) {
33
- Internal.disposeFromStore(Internal.IMPLICIT.STORE, token as any, key)
33
+ if (params.length === 2) {
34
+ disposeFromStore(IMPLICIT.STORE, ...params)
34
35
  } else {
35
- Internal.disposeFromStore(Internal.IMPLICIT.STORE, token as any)
36
+ disposeFromStore(IMPLICIT.STORE, ...params)
36
37
  }
37
38
  }
@@ -12,7 +12,7 @@ import type {
12
12
  } from "atom.io"
13
13
  import type { Transceiver } from "atom.io/internal"
14
14
  import { findInStore, IMPLICIT } from "atom.io/internal"
15
- import type { Canonical, Json } from "atom.io/json"
15
+ import type { Canonical } from "atom.io/json"
16
16
 
17
17
  import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
18
18
 
@@ -30,11 +30,10 @@ import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
30
30
  * @overload Mutable Atom
31
31
  */
32
32
  export function findState<
33
- T extends Transceiver<any>,
34
- J extends Json.Serializable,
33
+ T extends Transceiver<any, any, any>,
35
34
  K extends Canonical,
36
35
  Key extends K,
37
- >(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J, K>
36
+ >(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T, K>
38
37
  /**
39
38
  * Finds a {@link RegularAtomToken} in the store, without accessing its value.
40
39
  *
@@ -1,4 +1,5 @@
1
- import * as Internal from "atom.io/internal"
1
+ import type { ViewOf } from "atom.io/internal"
2
+ import { getFromStore, IMPLICIT } from "atom.io/internal"
2
3
  import type { Canonical } from "atom.io/json"
3
4
 
4
5
  import type { ReadableFamilyToken, ReadableToken } from "."
@@ -10,7 +11,7 @@ import type { ReadableFamilyToken, ReadableToken } from "."
10
11
  * @overload Default
11
12
  * @default
12
13
  */
13
- export function getState<T>(token: ReadableToken<T>): T
14
+ export function getState<T>(token: ReadableToken<T>): ViewOf<T>
14
15
 
15
16
  /**
16
17
  * Read or compute the current value of a state
@@ -22,7 +23,7 @@ export function getState<T>(token: ReadableToken<T>): T
22
23
  export function getState<T, K extends Canonical, Key extends K>(
23
24
  token: ReadableFamilyToken<T, K>,
24
25
  key: Key,
25
- ): T
26
+ ): ViewOf<T>
26
27
 
27
28
  export function getState(
28
29
  ...params:
@@ -30,7 +31,7 @@ export function getState(
30
31
  | [token: ReadableToken<any>]
31
32
  ): any {
32
33
  if (params.length === 2) {
33
- return Internal.getFromStore(Internal.IMPLICIT.STORE, ...params)
34
+ return getFromStore(IMPLICIT.STORE, ...params)
34
35
  }
35
- return Internal.getFromStore(Internal.IMPLICIT.STORE, ...params)
36
+ return getFromStore(IMPLICIT.STORE, ...params)
36
37
  }
package/src/main/join.ts CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  IMPLICIT,
15
15
  } from "atom.io/internal"
16
16
  import type { Json } from "atom.io/json"
17
- import type { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx"
17
+ import type { SetRTX } from "atom.io/transceivers/set-rtx"
18
18
 
19
19
  // biome-ignore format: intersection
20
20
  export type JoinOptions<
@@ -262,6 +262,6 @@ export function getInternalRelations<
262
262
  Content extends Json.Object | null,
263
263
  >(
264
264
  token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
265
- ): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
265
+ ): MutableAtomFamilyToken<SetRTX<string>, string> {
266
266
  return getInternalRelationsFromStore(token, IMPLICIT.STORE)
267
267
  }
@@ -105,7 +105,7 @@ export const simpleLogger: Logger = {
105
105
 
106
106
  export class AtomIOLogger implements Logger {
107
107
  public logLevel: `error` | `info` | `warn` | null
108
- private readonly filter: LogFilter | undefined
108
+ public filter: LogFilter | undefined
109
109
  private readonly logger: Logger
110
110
 
111
111
  public constructor(
@@ -119,31 +119,31 @@ export class AtomIOLogger implements Logger {
119
119
  }
120
120
 
121
121
  public error: LogFn = (...args) => {
122
- const filterResult = this.filter?.(...args) ?? true
123
122
  if (this.logLevel !== null) {
123
+ const filterResult = this.filter?.(...args) ?? true
124
124
  if (filterResult === true) {
125
125
  this.logger.error(...args)
126
- } else if (filterResult !== false) {
126
+ } else if (filterResult) {
127
127
  this.logger.error(...filterResult)
128
128
  }
129
129
  }
130
130
  }
131
131
  public info: LogFn = (...args) => {
132
- const filterResult = this.filter?.(...args) ?? true
133
132
  if (this.logLevel === `info`) {
133
+ const filterResult = this.filter?.(...args) ?? true
134
134
  if (filterResult === true) {
135
135
  this.logger.info(...args)
136
- } else if (filterResult !== false) {
136
+ } else if (filterResult) {
137
137
  this.logger.info(...filterResult)
138
138
  }
139
139
  }
140
140
  }
141
141
  public warn: LogFn = (...args) => {
142
- const filterResult = this.filter?.(...args) ?? true
143
142
  if (this.logLevel !== `error` && this.logLevel !== null) {
143
+ const filterResult = this.filter?.(...args) ?? true
144
144
  if (filterResult === true) {
145
145
  this.logger.warn(...args)
146
- } else if (filterResult !== false) {
146
+ } else if (filterResult) {
147
147
  this.logger.warn(...filterResult)
148
148
  }
149
149
  }
@@ -1,4 +1,4 @@
1
- import * as Internal from "atom.io/internal"
1
+ import { IMPLICIT, resetInStore } from "atom.io/internal"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { WritableFamilyToken, WritableToken } from "."
@@ -26,8 +26,8 @@ export function resetState(
26
26
  | [token: WritableToken<any>]
27
27
  ): void {
28
28
  if (params.length === 2) {
29
- Internal.resetInStore(Internal.IMPLICIT.STORE, ...params)
29
+ resetInStore(IMPLICIT.STORE, ...params)
30
30
  } else {
31
- Internal.resetInStore(Internal.IMPLICIT.STORE, ...params)
31
+ resetInStore(IMPLICIT.STORE, ...params)
32
32
  }
33
33
  }
@@ -1,4 +1,4 @@
1
- import * as Internal from "atom.io/internal"
1
+ import { IMPLICIT, setIntoStore } from "atom.io/internal"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { WritableFamilyToken, WritableToken } from "./tokens"
@@ -45,8 +45,8 @@ export function setState<T, New extends T>(
45
45
  | [token: WritableToken<T>, value: New | Setter<T, New>]
46
46
  ): void {
47
47
  if (params.length === 2) {
48
- Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
48
+ setIntoStore(IMPLICIT.STORE, ...params)
49
49
  } else {
50
- Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
50
+ setIntoStore(IMPLICIT.STORE, ...params)
51
51
  }
52
52
  }
@@ -1,4 +1,4 @@
1
- import type { Flat, Func } from "atom.io/internal"
1
+ import type { Flat, Fn } from "atom.io/internal"
2
2
  import { arbitrary, IMPLICIT, subscribeInStore } from "atom.io/internal"
3
3
 
4
4
  import type {
@@ -20,7 +20,7 @@ export type KeyedStateUpdate<T> = Flat<
20
20
  }
21
21
  >
22
22
  export type UpdateHandler<T> = (update: StateUpdate<T>) => void
23
- export type TransactionUpdateHandler<F extends Func> = (
23
+ export type TransactionUpdateHandler<F extends Fn> = (
24
24
  data: TransactionUpdate<F>,
25
25
  ) => void
26
26
 
@@ -45,7 +45,7 @@ export function subscribe<T>(
45
45
  * @returns A function that can be called to unsubscribe from the transaction
46
46
  * @overload Transaction
47
47
  */
48
- export function subscribe<F extends Func>(
48
+ export function subscribe<F extends Fn>(
49
49
  token: TransactionToken<F>,
50
50
  handleUpdate: TransactionUpdateHandler<F>,
51
51
  key?: string,
@@ -1,5 +1,5 @@
1
- import type { Func, Transceiver } from "atom.io/internal"
2
- import type { Canonical, Json, stringified } from "atom.io/json"
1
+ import type { AsJSON, Fn, Transceiver } from "atom.io/internal"
2
+ import type { Canonical, stringified } from "atom.io/json"
3
3
 
4
4
  /**
5
5
  * A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
@@ -53,7 +53,7 @@ export type TimelineToken<M> = {
53
53
  __M?: M
54
54
  }
55
55
 
56
- export type TransactionToken<F extends Func> = {
56
+ export type TransactionToken<F extends Fn> = {
57
57
  /** The unique identifier of the transaction */
58
58
  key: string
59
59
  /** Discriminator */
@@ -63,7 +63,7 @@ export type TransactionToken<F extends Func> = {
63
63
  }
64
64
 
65
65
  export type AtomToken<T, K extends Canonical = any> =
66
- | MutableAtomToken<T extends Transceiver<any> ? T : never, any, K>
66
+ | MutableAtomToken<T extends Transceiver<any, any, any> ? T : never, K>
67
67
  | RegularAtomToken<T, K>
68
68
  export type RegularAtomToken<T, K extends Canonical = any> = {
69
69
  /** The unique identifier of the atom. */
@@ -76,8 +76,7 @@ export type RegularAtomToken<T, K extends Canonical = any> = {
76
76
  __T?: T
77
77
  }
78
78
  export type MutableAtomToken<
79
- T extends Transceiver<any>,
80
- J extends Json.Serializable,
79
+ T extends Transceiver<any, any, any>,
81
80
  K extends Canonical = any,
82
81
  > = {
83
82
  /** The unique identifier of the atom. */
@@ -87,9 +86,7 @@ export type MutableAtomToken<
87
86
  /** Present if the atom belongs to a family. */
88
87
  family?: FamilyMetadata<K>
89
88
  /** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
90
- __J?: J
91
- /** Never present. This is a marker that preserves the type of the atom's transceiver value. */
92
- __U?: T extends Transceiver<infer Update> ? Update : never
89
+ __J?: AsJSON<T>
93
90
  }
94
91
 
95
92
  export type SelectorToken<T, K extends Canonical = any> =
@@ -160,7 +157,7 @@ export type FamilyMetadata<K extends Canonical = any> = {
160
157
  }
161
158
 
162
159
  export type AtomFamilyToken<T, K extends Canonical = Canonical> =
163
- | MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>
160
+ | MutableAtomFamilyToken<T extends Transceiver<any, any, any> ? T : never, K>
164
161
  | RegularAtomFamilyToken<T, K>
165
162
  export type RegularAtomFamilyToken<T, K extends Canonical> = {
166
163
  /** The unique identifier of the atom family */
@@ -173,8 +170,7 @@ export type RegularAtomFamilyToken<T, K extends Canonical> = {
173
170
  __K?: K
174
171
  }
175
172
  export type MutableAtomFamilyToken<
176
- T extends Transceiver<any>,
177
- J extends Json.Serializable,
173
+ T extends Transceiver<any, any, any>,
178
174
  K extends Canonical,
179
175
  > = {
180
176
  /** The unique identifier of the atom family */
@@ -183,8 +179,6 @@ export type MutableAtomFamilyToken<
183
179
  type: `mutable_atom_family`
184
180
  /** Never present. This is a marker that preserves the type of atoms in this family */
185
181
  __T?: T
186
- /** Never present. This is a marker that preserves the type of the JSON form of atoms in this family */
187
- __J?: J
188
182
  /** Never present. This is a marker that preserves the type of keys used for atoms in this family */
189
183
  __K?: K
190
184
  }
@@ -1,11 +1,11 @@
1
- import type { EnvironmentData, Func, Transceiver } from "atom.io/internal"
1
+ import type { AsJSON, EnvironmentData, Fn, Transceiver } from "atom.io/internal"
2
2
  import {
3
3
  actUponStore,
4
4
  arbitrary,
5
5
  createTransaction,
6
6
  IMPLICIT,
7
7
  } from "atom.io/internal"
8
- import type { Canonical, Json, stringified } from "atom.io/json"
8
+ import type { Canonical, stringified } from "atom.io/json"
9
9
 
10
10
  import type { disposeState } from "./dispose-state"
11
11
  import type { findState } from "./find-state"
@@ -28,6 +28,9 @@ export type StateCreation<Token extends ReadableToken<any>> = {
28
28
  export type StateDisposal<Token extends ReadableToken<any>> =
29
29
  | AtomDisposal<Token>
30
30
  | SelectorDisposal<Token>
31
+ export type StateLifecycleEvent<Token extends ReadableToken<any>> =
32
+ | StateCreation<Token>
33
+ | StateDisposal<Token>
31
34
 
32
35
  export type AtomDisposal<Token extends ReadableToken<any>> = {
33
36
  type: `state_disposal`
@@ -55,6 +58,7 @@ export type MoleculeDisposal = {
55
58
  export type MoleculeTransfer = {
56
59
  type: `molecule_transfer`
57
60
  key: Canonical
61
+ exclusive: boolean
58
62
  from: Canonical[]
59
63
  to: Canonical[]
60
64
  }
@@ -66,9 +70,9 @@ export type TransactionUpdateContent =
66
70
  | MoleculeTransfer
67
71
  | StateCreation<ReadableToken<unknown>>
68
72
  | StateDisposal<ReadableToken<unknown>>
69
- | TransactionUpdate<Func>
73
+ | TransactionUpdate<Fn>
70
74
 
71
- export type TransactionUpdate<F extends Func> = {
75
+ export type TransactionUpdate<F extends Fn> = {
72
76
  type: `transaction_update`
73
77
  key: string
74
78
  id: string
@@ -85,29 +89,29 @@ export type ActorToolkit = Readonly<{
85
89
  set: typeof setState
86
90
  reset: typeof resetState
87
91
  find: typeof findState
88
- json: <T extends Transceiver<any>, J extends Json.Serializable>(
89
- state: MutableAtomToken<T, J>,
90
- ) => WritablePureSelectorToken<J>
92
+ json: <T extends Transceiver<any, any, any>>(
93
+ state: MutableAtomToken<T>,
94
+ ) => WritablePureSelectorToken<AsJSON<T>>
91
95
  dispose: typeof disposeState
92
96
  run: typeof runTransaction
93
97
  env: () => EnvironmentData
94
98
  }>
95
99
 
96
- export type Read<F extends Func> = (
100
+ export type Read<F extends Fn> = (
97
101
  toolkit: ReaderToolkit,
98
102
  ...parameters: Parameters<F>
99
103
  ) => ReturnType<F>
100
- export type Write<F extends Func> = (
104
+ export type Write<F extends Fn> = (
101
105
  toolkit: WriterToolkit,
102
106
  ...parameters: Parameters<F>
103
107
  ) => ReturnType<F>
104
- export type Transact<F extends Func> = (
108
+ export type Transact<F extends Fn> = (
105
109
  toolkit: ActorToolkit,
106
110
  ...parameters: Parameters<F>
107
111
  ) => ReturnType<F>
108
112
  export type TransactionIO<Token extends TransactionToken<any>> =
109
113
  Token extends TransactionToken<infer F> ? F : never
110
- export type TransactionOptions<F extends Func> = {
114
+ export type TransactionOptions<F extends Fn> = {
111
115
  /** The unique identifier of the transaction */
112
116
  key: string
113
117
  /** The operation to perform */
@@ -119,7 +123,7 @@ export type TransactionOptions<F extends Func> = {
119
123
  * @param options - {@link TransactionOptions}
120
124
  * @returns A reference to the transaction created: a {@link TransactionToken}
121
125
  */
122
- export function transaction<F extends Func>(
126
+ export function transaction<F extends Fn>(
123
127
  options: TransactionOptions<F>,
124
128
  ): TransactionToken<F> {
125
129
  return createTransaction(IMPLICIT.STORE, options)
@@ -131,7 +135,7 @@ export function transaction<F extends Func>(
131
135
  * @param id - A unique identifier for the transaction. If not provided, a random identifier will be generated
132
136
  * @returns A function that can be called to run the transaction with its {@link TransactionIO} parameters
133
137
  */
134
- export function runTransaction<F extends Func>(
138
+ export function runTransaction<F extends Fn>(
135
139
  token: TransactionToken<F>,
136
140
  id: string = arbitrary(),
137
141
  ): (...parameters: Parameters<F>) => ReturnType<F> {