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,3 +1,2 @@
1
- export { CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Junction, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, counterfeit, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deposit, disposeAtom, disposeFromStore, disposeSelector, evictCachedValue, findInStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getTrace, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw } from '../../dist/chunk-42UH5F5Q.js';
2
- import '../../dist/chunk-ICGFFQ3H.js';
1
+ export { CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Join, Junction, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, capitalize, claimWithinStore, clearStore, closeOperation, counterfeit, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deallocateFromStore, deposit, disposeAtom, disposeFromStore, disposeSelector, editRelationsInStore, evictCachedValue, findInStore, findRelationsInStore, fuseWithinStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getInternalRelationsFromStore, getJoin, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getTrace, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeRootMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw } from '../../dist/chunk-GY2XQYZY.js';
3
2
  import '../../dist/chunk-XWL6SNVU.js';
@@ -59,8 +59,8 @@ export function createRegularAtom<T>(
59
59
  initialValue = options.default()
60
60
  }
61
61
  target.atoms.set(newAtom.key, newAtom)
62
- markAtomAsDefault(options.key, store)
63
- cacheValue(options.key, initialValue, subject, target)
62
+ markAtomAsDefault(store, options.key)
63
+ cacheValue(target, options.key, initialValue, subject)
64
64
  const token = deposit(newAtom)
65
65
  if (options.effects) {
66
66
  let effectIndex = 0
@@ -71,7 +71,7 @@ export function createRegularAtom<T>(
71
71
  setIntoStore(store, token, next)
72
72
  },
73
73
  onSet: (handle: UpdateHandler<T>) =>
74
- subscribeToState(token, handle, `effect[${effectIndex}]`, store),
74
+ subscribeToState(store, token, `effect[${effectIndex}]`, handle),
75
75
  })
76
76
  if (cleanup) {
77
77
  cleanupFunctions.push(cleanup)
@@ -3,16 +3,16 @@ import type { AtomDisposal, AtomToken } from "atom.io"
3
3
  import type { Store } from ".."
4
4
  import { getUpdateToken, isChildStore, newest, withdraw } from ".."
5
5
 
6
- export function disposeAtom(atomToken: AtomToken<unknown>, store: Store): void {
6
+ export function disposeAtom(store: Store, atomToken: AtomToken<unknown>): void {
7
7
  const target = newest(store)
8
8
  const { key, family } = atomToken
9
- const atom = withdraw(atomToken, target)
9
+ const atom = withdraw(target, atomToken)
10
10
  if (!family) {
11
11
  store.logger.error(`❌`, `atom`, key, `Standalone atoms cannot be disposed.`)
12
12
  } else {
13
13
  atom.cleanup?.()
14
14
  const lastValue = store.valueMap.get(atom.key)
15
- const atomFamily = withdraw({ key: family.key, type: `atom_family` }, store)
15
+ const atomFamily = withdraw(store, { key: family.key, type: `atom_family` })
16
16
 
17
17
  const disposal: AtomDisposal<AtomToken<unknown>> = {
18
18
  type: `state_disposal`,
@@ -24,15 +24,6 @@ export function disposeAtom(atomToken: AtomToken<unknown>, store: Store): void {
24
24
  atomFamily.subject.next(disposal)
25
25
 
26
26
  const isChild = isChildStore(target)
27
- // let molecule = target.molecules.get(family.subKey)
28
- // if (molecule && isChild) {
29
- // const parentMolecule = target.parent.molecules.get(family.subKey)
30
- // if (parentMolecule === molecule) {
31
- // molecule = parentMolecule.copy()
32
- // target.molecules.set(family.subKey, molecule)
33
- // }
34
- // }
35
- // molecule?.tokens.delete(family.key)
36
27
 
37
28
  target.atoms.delete(key)
38
29
  target.valueMap.delete(key)
@@ -42,7 +33,7 @@ export function disposeAtom(atomToken: AtomToken<unknown>, store: Store): void {
42
33
 
43
34
  if (atomToken.type === `mutable_atom`) {
44
35
  const updateToken = getUpdateToken(atomToken)
45
- disposeAtom(updateToken, store)
36
+ disposeAtom(store, updateToken)
46
37
  store.trackers.delete(key)
47
38
  }
48
39
  store.logger.info(`🔥`, `atom`, key, `deleted`)
@@ -1,17 +1,17 @@
1
1
  import { newest } from "../lineage"
2
2
  import type { Store } from "../store"
3
3
 
4
- export const isAtomDefault = (key: string, store: Store): boolean => {
4
+ export const isAtomDefault = (store: Store, key: string): boolean => {
5
5
  const core = newest(store)
6
6
  return core.atomsThatAreDefault.has(key)
7
7
  }
8
8
 
9
- export const markAtomAsDefault = (key: string, store: Store): void => {
9
+ export const markAtomAsDefault = (store: Store, key: string): void => {
10
10
  const core = newest(store)
11
11
  core.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key)
12
12
  }
13
13
 
14
- export const markAtomAsNotDefault = (key: string, store: Store): void => {
14
+ export const markAtomAsNotDefault = (store: Store, key: string): void => {
15
15
  const core = newest(store)
16
16
  core.atomsThatAreDefault = new Set(newest(store).atomsThatAreDefault)
17
17
  core.atomsThatAreDefault.delete(key)
@@ -8,22 +8,22 @@ import type { Store } from "./store"
8
8
  import type { Subject } from "./subject"
9
9
 
10
10
  export function cacheValue<T>(
11
+ store: Store,
11
12
  key: string,
12
13
  value: T,
13
14
  subject: Subject<StateUpdate<unknown>>,
14
- store: Store,
15
15
  ): T
16
16
  export function cacheValue<T extends Promise<any>>(
17
+ store: Store,
17
18
  key: string,
18
19
  value: T,
19
20
  subject: Subject<StateUpdate<unknown>>,
20
- store: Store,
21
21
  ): Future<T>
22
22
  export function cacheValue<T>(
23
+ target: Store,
23
24
  key: string,
24
25
  value: T,
25
26
  subject: Subject<StateUpdate<unknown>>,
26
- target: Store,
27
27
  ): Future<T> | T {
28
28
  const currentValue = target.valueMap.get(key)
29
29
  if (currentValue instanceof Future) {
@@ -35,7 +35,7 @@ export function cacheValue<T>(
35
35
  target.valueMap.set(key, future)
36
36
  future
37
37
  .then((resolved) => {
38
- cacheValue(key, resolved, subject, target)
38
+ cacheValue(target, key, resolved, subject)
39
39
  subject.next({ newValue: resolved, oldValue: future })
40
40
  })
41
41
  .catch((thrown) => {
@@ -54,7 +54,7 @@ export const readCachedValue = <T>(
54
54
  let value = target.valueMap.get(token.key) as T
55
55
  if (token.type === `mutable_atom` && isChildStore(target)) {
56
56
  const { parent } = target
57
- const copiedValue = copyMutableIfNeeded(token, parent, target)
57
+ const copiedValue = copyMutableIfNeeded(target, token, parent)
58
58
  value = copiedValue
59
59
  }
60
60
  return value
@@ -0,0 +1,3 @@
1
+ export function capitalize<S extends string>(string: S): Capitalize<S> {
2
+ return (string[0].toUpperCase() + string.slice(1)) as Capitalize<S>
3
+ }
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  FamilyMetadata,
3
+ findState,
3
4
  getState,
4
5
  ReadonlySelectorFamilyOptions,
5
6
  ReadonlySelectorFamilyToken,
@@ -7,8 +8,6 @@ import type {
7
8
  StateCreation,
8
9
  StateDisposal,
9
10
  } from "atom.io"
10
- import type { findState } from "atom.io/ephemeral"
11
- import type { seekState } from "atom.io/immortal"
12
11
  import type { Canonical } from "atom.io/json"
13
12
  import { stringifyJson } from "atom.io/json"
14
13
 
@@ -18,7 +17,6 @@ import {
18
17
  getJsonToken,
19
18
  prettyPrintTokenType,
20
19
  type ReadonlySelectorFamily,
21
- seekInStore,
22
20
  } from ".."
23
21
  import { newest } from "../lineage"
24
22
  import { createReadonlySelector } from "../selector"
@@ -78,9 +76,10 @@ export function createReadonlySelectorFamily<T, K extends Canonical>(
78
76
  default: (key: K) => {
79
77
  const getFn = options.get(key)
80
78
  return getFn({
81
- get: ((...ps: [any]) => getFromStore(store, ...ps)) as typeof getState,
82
- find: ((token, k) => findInStore(store, token, k)) as typeof findState,
83
- seek: ((token, k) => seekInStore(store, token, k)) as typeof seekState,
79
+ get: ((...args: Parameters<typeof getState>) =>
80
+ getFromStore(store, ...args)) as typeof getState,
81
+ find: ((...args: Parameters<typeof findState>) =>
82
+ findInStore(store, ...args)) as typeof findState,
84
83
  json: (token) => getJsonToken(store, token),
85
84
  })
86
85
  },
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  FamilyMetadata,
3
+ findState,
3
4
  getState,
4
5
  StateCreation,
5
6
  StateDisposal,
@@ -7,8 +8,6 @@ import type {
7
8
  WritableSelectorFamilyToken,
8
9
  WritableSelectorToken,
9
10
  } from "atom.io"
10
- import type { findState } from "atom.io/ephemeral"
11
- import type { seekState } from "atom.io/immortal"
12
11
  import type { Canonical } from "atom.io/json"
13
12
  import { stringifyJson } from "atom.io/json"
14
13
 
@@ -17,7 +16,6 @@ import {
17
16
  getFromStore,
18
17
  getJsonToken,
19
18
  prettyPrintTokenType,
20
- seekInStore,
21
19
  type WritableSelectorFamily,
22
20
  } from ".."
23
21
  import { newest } from "../lineage"
@@ -80,7 +78,6 @@ export function createWritableSelectorFamily<T, K extends Canonical>(
80
78
  return getFn({
81
79
  get: ((...ps: [any]) => getFromStore(store, ...ps)) as typeof getState,
82
80
  find: ((token, k) => findInStore(store, token, k)) as typeof findState,
83
- seek: ((token, k) => seekInStore(store, token, k)) as typeof seekState,
84
81
  json: (token) => getJsonToken(store, token),
85
82
  })
86
83
  },
@@ -2,7 +2,6 @@ import type { ReadableFamilyToken, ReadableToken } from "atom.io"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import { disposeAtom } from "../atom"
5
- import { getTrace } from "../get-trace"
6
5
  import { disposeSelector } from "../selector"
7
6
  import { type Store, withdraw } from "../store"
8
7
  import { findInStore } from "./find-in-store"
@@ -31,33 +30,24 @@ export function disposeFromStore(
31
30
  token = maybeToken
32
31
  }
33
32
  try {
34
- withdraw(token, store)
33
+ withdraw(store, token)
35
34
  } catch (thrown) {
36
- // const disposal = store.disposalTraces.buffer.find(
37
- // (item) => item?.key === token.key,
38
- // )
39
35
  store.logger.error(
40
36
  `❌`,
41
37
  token.type,
42
38
  token.key,
43
39
  `could not be disposed because it was not found in the store "${store.config.name}".`,
44
- // disposal
45
- // ? `\n This state was most recently disposed\n${disposal.trace}`
46
- // : `No previous disposal trace was found.`,
47
40
  )
48
41
  return
49
42
  }
50
43
  switch (token.type) {
51
44
  case `atom`:
52
45
  case `mutable_atom`:
53
- disposeAtom(token, store)
46
+ disposeAtom(store, token)
54
47
  break
55
48
  case `selector`:
56
49
  case `readonly_selector`:
57
- disposeSelector(token, store)
50
+ disposeSelector(store, token)
58
51
  break
59
52
  }
60
-
61
- // const trace = getTrace(new Error())
62
- // store.disposalTraces.add({ key: token.key, trace })
63
53
  }
@@ -16,12 +16,7 @@ import type {
16
16
  WritableSelectorToken,
17
17
  WritableToken,
18
18
  } from "atom.io"
19
- import {
20
- type Canonical,
21
- type Json,
22
- stringified,
23
- stringifyJson,
24
- } from "atom.io/json"
19
+ import { type Canonical, type Json, stringifyJson } from "atom.io/json"
25
20
 
26
21
  import { newest } from "../lineage"
27
22
  import type { Transceiver } from "../mutable"
@@ -55,12 +55,12 @@ export function getFromStore(
55
55
  if (store.defaults.has(family.key)) {
56
56
  return store.defaults.get(token.family.key)
57
57
  }
58
- const defaultValue = withdraw(family, store).default(subKey)
58
+ const defaultValue = withdraw(store, family).default(subKey)
59
59
  store.defaults.set(family.key, defaultValue)
60
60
  return defaultValue
61
61
  }
62
62
  }
63
63
  }
64
64
 
65
- return readOrComputeValue(withdraw(token, store), store)
65
+ return readOrComputeValue(store, withdraw(store, token))
66
66
  }
@@ -3,8 +3,8 @@ import { readCachedValue } from "../caching"
3
3
  import type { Store } from "../store"
4
4
 
5
5
  export const readOrComputeValue = <T>(
6
- state: ReadableState<T>,
7
6
  target: Store,
7
+ state: ReadableState<T>,
8
8
  ): T => {
9
9
  if (target.valueMap.has(state.key)) {
10
10
  target.logger.info(`📖`, state.type, state.key, `reading cached value`)
@@ -17,21 +17,25 @@ import type { Canonical, Json, JsonInterface } from "atom.io/json"
17
17
  import type { Transceiver } from "./mutable"
18
18
  import type { Store } from "./store"
19
19
  import type { Subject } from "./subject"
20
+ import type { Timeline } from "./timeline"
21
+ import type { Transaction } from "./transaction"
20
22
 
21
23
  export * from "./arbitrary"
22
24
  export * from "./atom"
23
25
  export * from "./caching"
26
+ export * from "./capitalize"
24
27
  export * from "./families"
25
28
  export * from "./future"
26
29
  export * from "./get-environment-data"
27
30
  export * from "./get-state"
28
31
  export * from "./get-trace"
29
32
  export * from "./ingest-updates"
33
+ export * from "./join"
30
34
  export * from "./junction"
31
35
  export * from "./keys"
32
36
  export * from "./lazy-map"
33
37
  export * from "./lineage"
34
- export type * from "./molecule"
38
+ export * from "./molecule"
35
39
  export * from "./mutable"
36
40
  export * from "./not-found-error"
37
41
  export * from "./operation"
@@ -100,14 +104,14 @@ T extends Transceiver<any>,
100
104
  J extends Json.Serializable,
101
105
  K extends Canonical,
102
106
  > =
103
- & JsonInterface<T, J>
104
- & MutableAtomFamilyToken<T, J, K>
105
- & {
106
- (key: K): MutableAtomToken<T, J>
107
- subject: Subject<StateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>>
108
- install: (store: Store) => void
109
- internalRoles: string[] | undefined
110
- }
107
+ & JsonInterface<T, J>
108
+ & MutableAtomFamilyToken<T, J, K>
109
+ & {
110
+ (key: K): MutableAtomToken<T, J>
111
+ subject: Subject<StateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>>
112
+ install: (store: Store) => void
113
+ internalRoles: string[] | undefined
114
+ }
111
115
 
112
116
  export type AtomFamily<T, K extends Canonical = Canonical> =
113
117
  | MutableAtomFamily<T extends Transceiver<any> ? T : never, any, K>
@@ -145,3 +149,9 @@ export type WritableFamily<T, K extends Canonical> =
145
149
  export type ReadableFamily<T, K extends Canonical> =
146
150
  | AtomFamily<T, K>
147
151
  | SelectorFamily<T, K>
152
+
153
+ export type AtomIOInternalResource =
154
+ | ReadableFamily<any, any>
155
+ | ReadableState<any>
156
+ | Timeline<any>
157
+ | Transaction<any>
@@ -8,13 +8,12 @@ import type {
8
8
  } from "atom.io"
9
9
  import { parseJson, stringifyJson } from "atom.io/json"
10
10
 
11
+ import { disposeFromStore, findInStore } from "../families"
11
12
  import {
12
13
  allocateIntoStore,
13
14
  claimWithinStore,
14
15
  deallocateFromStore,
15
- } from "~/packages/atom.io/src/allocate"
16
-
17
- import { disposeFromStore, findInStore } from "../families"
16
+ } from "../molecule"
18
17
  import type { Store } from "../store"
19
18
 
20
19
  export function ingestCreationEvent(
@@ -0,0 +1,48 @@
1
+ import type { AtomIOToken } from "atom.io"
2
+
3
+ import { newest } from "./lineage"
4
+ import { type Store, withdraw } from "./store"
5
+ import { isChildStore } from "./transaction"
6
+
7
+ /**
8
+ * @public
9
+ * Install the given tokens into the target store
10
+ * @param tokens - States, families, transactions, and timelines to install into the target store
11
+ * @param target - The store to install the tokens into
12
+ * @param source - The store to install the tokens from
13
+ *
14
+ */
15
+ export function installIntoStore(
16
+ tokens: AtomIOToken[],
17
+ target: Store,
18
+ source: Store,
19
+ ): void {
20
+ const sourceNewest = newest(source)
21
+ if (isChildStore(sourceNewest)) {
22
+ source.logger.error(
23
+ `❌`,
24
+ `transaction`,
25
+ sourceNewest.transactionMeta.update.key,
26
+ `could not install the following tokens into store "${target.config.name} from "${source.config.name}":`,
27
+ tokens,
28
+ `${sourceNewest.config.name} is undergoing a transaction.`,
29
+ )
30
+ return
31
+ }
32
+ const targetNewest = newest(target)
33
+ if (isChildStore(targetNewest)) {
34
+ target.logger.error(
35
+ `❌`,
36
+ `transaction`,
37
+ targetNewest.transactionMeta.update.key,
38
+ `could not install the following tokens into store "${target.config.name} from "${source.config.name}":`,
39
+ tokens,
40
+ `${targetNewest.config.name} is undergoing a transaction.`,
41
+ )
42
+ return
43
+ }
44
+ for (const token of tokens) {
45
+ const resource = withdraw(source, token)
46
+ resource.install(target)
47
+ }
48
+ }
@@ -0,0 +1,32 @@
1
+ import type { JoinToken } from "atom.io"
2
+ import type { Json } from "atom.io/json"
3
+
4
+ import type { Junction } from "../junction"
5
+ import { newest } from "../lineage"
6
+ import type { Store } from "../store"
7
+ import { isChildStore } from "../transaction"
8
+ import { getJoin } from "./get-join"
9
+
10
+ export function editRelationsInStore<
11
+ ASide extends string,
12
+ AType extends string,
13
+ BSide extends string,
14
+ BType extends string,
15
+ Cardinality extends `1:1` | `1:n` | `n:n`,
16
+ Content extends Json.Object | null,
17
+ >(
18
+ token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
19
+ change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void,
20
+ store: Store,
21
+ ): void {
22
+ const myJoin = getJoin(token, store)
23
+ const target = newest(store)
24
+ if (isChildStore(target)) {
25
+ const { toolkit } = target.transactionMeta
26
+ myJoin.transact(toolkit, ({ relations }) => {
27
+ change(relations)
28
+ })
29
+ } else {
30
+ change(myJoin.relations)
31
+ }
32
+ }
@@ -0,0 +1,124 @@
1
+ import type { JoinStates, JoinToken } from "atom.io"
2
+ import type { Json } from "atom.io/json"
3
+
4
+ import { capitalize } from "../capitalize"
5
+ import { findInStore } from "../families"
6
+ import type { Store } from "../store"
7
+ import { getJoin } from "./get-join"
8
+
9
+ export function findRelationsInStore<
10
+ ASide extends string,
11
+ AType extends string,
12
+ BSide extends string,
13
+ BType extends string,
14
+ Cardinality extends `1:1` | `1:n` | `n:n`,
15
+ Content extends Json.Object | null,
16
+ >(
17
+ token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
18
+ key: AType | BType,
19
+ store: Store,
20
+ ): JoinStates<ASide, AType, BSide, BType, Cardinality, Content> {
21
+ const myJoin = getJoin(token, store)
22
+ let relations: JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
23
+ switch (token.cardinality satisfies `1:1` | `1:n` | `n:n`) {
24
+ case `1:1`: {
25
+ const keyAB = `${token.a}KeyOf${capitalize(token.b)}`
26
+ const keyBA = `${token.b}KeyOf${capitalize(token.a)}`
27
+ relations = {
28
+ get [keyAB]() {
29
+ const familyAB = myJoin.states[keyAB as any]
30
+ const state = findInStore(store, familyAB, key)
31
+ return state
32
+ },
33
+ get [keyBA]() {
34
+ const familyBA = myJoin.states[keyBA as any]
35
+ const state = findInStore(store, familyBA, key)
36
+ return state
37
+ },
38
+ } as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
39
+ const entryAB = `${token.a}EntryOf${capitalize(token.b)}`
40
+ if (entryAB in myJoin.states) {
41
+ const entryBA = `${token.b}EntryOf${capitalize(token.a)}`
42
+ Object.assign(relations, {
43
+ get [entryAB]() {
44
+ const familyAB = myJoin.states[entryAB as any]
45
+ const state = findInStore(store, familyAB, key)
46
+ return state
47
+ },
48
+ get [entryBA]() {
49
+ const familyBA = myJoin.states[entryBA as any]
50
+ const state = findInStore(store, familyBA, key)
51
+ return state
52
+ },
53
+ })
54
+ }
55
+ break
56
+ }
57
+ case `1:n`: {
58
+ const keyAB = `${token.a}KeyOf${capitalize(token.b)}`
59
+ const keysBA = `${token.b}KeysOf${capitalize(token.a)}`
60
+ relations = {
61
+ get [keyAB]() {
62
+ const familyAB = myJoin.states[keyAB as any]
63
+ const state = findInStore(store, familyAB, key)
64
+ return state
65
+ },
66
+ get [keysBA]() {
67
+ const familyBA = myJoin.states[keysBA as any]
68
+ const state = findInStore(store, familyBA, key)
69
+ return state
70
+ },
71
+ } as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
72
+ const entryAB = `${token.a}EntryOf${capitalize(token.b)}`
73
+ if (entryAB in myJoin.states) {
74
+ const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`
75
+ Object.assign(relations, {
76
+ get [entryAB]() {
77
+ const familyAB = myJoin.states[entryAB as any]
78
+ const state = findInStore(store, familyAB, key)
79
+ return state
80
+ },
81
+ get [entriesBA]() {
82
+ const familyBA = myJoin.states[entriesBA as any]
83
+ const state = findInStore(store, familyBA, key)
84
+ return state
85
+ },
86
+ })
87
+ }
88
+ break
89
+ }
90
+ case `n:n`: {
91
+ const keysAB = `${token.a}KeysOf${capitalize(token.b)}`
92
+ const keysBA = `${token.b}KeysOf${capitalize(token.a)}`
93
+ relations = {
94
+ get [keysAB]() {
95
+ const familyAB = myJoin.states[keysAB as any]
96
+ const state = findInStore(store, familyAB, key)
97
+ return state
98
+ },
99
+ get [keysBA]() {
100
+ const familyBA = myJoin.states[keysBA as any]
101
+ const state = findInStore(store, familyBA, key)
102
+ return state
103
+ },
104
+ } as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
105
+ const entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`
106
+ if (entriesAB in myJoin.states) {
107
+ const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`
108
+ Object.assign(relations, {
109
+ get [entriesAB]() {
110
+ const familyAB = myJoin.states[entriesAB as any]
111
+ const state = findInStore(store, familyAB, key)
112
+ return state
113
+ },
114
+ get [entriesBA]() {
115
+ const familyBA = myJoin.states[entriesBA as any]
116
+ const state = findInStore(store, familyBA, key)
117
+ return state
118
+ },
119
+ })
120
+ }
121
+ }
122
+ }
123
+ return relations
124
+ }
@@ -0,0 +1,14 @@
1
+ import type { JoinToken, MutableAtomFamilyToken } from "atom.io"
2
+ import type { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx"
3
+
4
+ import type { Store } from "../store"
5
+ import { getJoin } from "./get-join"
6
+
7
+ export function getInternalRelationsFromStore(
8
+ token: JoinToken<any, any, any, any, any, any>,
9
+ store: Store,
10
+ ): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
11
+ const myJoin = getJoin(token, store)
12
+ const family = myJoin.core.relatedKeysAtoms
13
+ return family
14
+ }
@@ -0,0 +1,31 @@
1
+ import type { JoinToken } from "atom.io"
2
+ import type { Json } from "atom.io/json"
3
+
4
+ import { IMPLICIT, type Store } from "../store"
5
+ import { Join } from "./join-internal"
6
+
7
+ export function getJoin<
8
+ ASide extends string,
9
+ AType extends string,
10
+ BSide extends string,
11
+ BType extends string,
12
+ Cardinality extends `1:1` | `1:n` | `n:n`,
13
+ Content extends Json.Object | null,
14
+ >(
15
+ token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
16
+ store: Store,
17
+ ): Join<ASide, AType, BSide, BType, Cardinality, Content> {
18
+ let myJoin = store.joins.get(token.key)
19
+ if (myJoin === undefined) {
20
+ const rootJoinMap = IMPLICIT.STORE.joins
21
+ const rootJoin = rootJoinMap.get(token.key)
22
+ if (rootJoin === undefined) {
23
+ throw new Error(
24
+ `Join "${token.key}" not found in store "${store.config.name}"`,
25
+ )
26
+ }
27
+ myJoin = new Join(rootJoin.options, rootJoin.defaultContent, store)
28
+ store.joins.set(token.key, myJoin)
29
+ }
30
+ return myJoin
31
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./edit-relations-in-store"
2
+ export * from "./find-relations-in-store"
3
+ export * from "./get-internal-relations-from-store"
4
+ export * from "./get-join"
5
+ export * from "./join-internal"