atom.io 0.31.1 → 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 (155) 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-Y5MBNTVU.js → chunk-GY2XQYZY.js} +1791 -703
  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 +622 -26
  15. package/dist/index.js +1 -228
  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 +783 -64
  21. package/internal/dist/index.js +1 -1
  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/get-state/get-from-store.ts +2 -2
  31. package/internal/src/get-state/read-or-compute-value.ts +1 -1
  32. package/internal/src/index.ts +2 -0
  33. package/internal/src/install-into-store.ts +1 -1
  34. package/internal/src/join/edit-relations-in-store.ts +32 -0
  35. package/internal/src/join/find-relations-in-store.ts +124 -0
  36. package/internal/src/join/get-internal-relations-from-store.ts +14 -0
  37. package/internal/src/join/get-join.ts +31 -0
  38. package/internal/src/join/index.ts +5 -0
  39. package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
  40. package/internal/src/keys.ts +7 -7
  41. package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
  42. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  43. package/internal/src/mutable/get-json-token.ts +1 -1
  44. package/internal/src/mutable/tracker-family.ts +19 -17
  45. package/internal/src/mutable/tracker.ts +8 -8
  46. package/internal/src/pretty-print.ts +1 -1
  47. package/internal/src/selector/create-readonly-selector.ts +3 -7
  48. package/internal/src/selector/create-writable-selector.ts +4 -4
  49. package/internal/src/selector/dispose-selector.ts +20 -11
  50. package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
  51. package/internal/src/selector/register-selector.ts +6 -9
  52. package/internal/src/selector/trace-selector-atoms.ts +2 -2
  53. package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
  54. package/internal/src/set-state/emit-update.ts +1 -1
  55. package/internal/src/set-state/evict-downstream.ts +1 -1
  56. package/internal/src/set-state/set-atom-or-selector.ts +1 -1
  57. package/internal/src/set-state/set-atom.ts +10 -10
  58. package/internal/src/set-state/set-into-store.ts +2 -2
  59. package/internal/src/set-state/stow-update.ts +1 -1
  60. package/internal/src/store/store.ts +1 -1
  61. package/internal/src/store/withdraw.ts +22 -22
  62. package/internal/src/subscribe/recall-state.ts +1 -1
  63. package/internal/src/subscribe/subscribe-in-store.ts +3 -3
  64. package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
  65. package/internal/src/subscribe/subscribe-to-state.ts +5 -5
  66. package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
  67. package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
  68. package/internal/src/timeline/create-timeline.ts +17 -37
  69. package/internal/src/transaction/act-upon-store.ts +2 -2
  70. package/internal/src/transaction/apply-transaction.ts +5 -5
  71. package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
  72. package/internal/src/transaction/build-transaction.ts +5 -8
  73. package/internal/src/transaction/create-transaction.ts +3 -3
  74. package/internal/src/transaction/get-epoch-number.ts +3 -3
  75. package/internal/src/transaction/set-epoch-number.ts +2 -2
  76. package/introspection/dist/index.d.ts +922 -6
  77. package/introspection/dist/index.js +2 -620
  78. package/json/dist/index.d.ts +899 -5
  79. package/json/dist/index.js +1 -80
  80. package/json/src/select-json-family.ts +3 -14
  81. package/package.json +24 -42
  82. package/react/dist/index.d.ts +921 -3
  83. package/react/dist/index.js +2 -82
  84. package/react/src/use-o.ts +1 -1
  85. package/react/src/use-tl.ts +2 -2
  86. package/react-devtools/dist/index.css +16 -14
  87. package/react-devtools/dist/index.d.ts +26 -1
  88. package/react-devtools/dist/index.js +6 -6
  89. package/react-devtools/src/devtools.scss +16 -14
  90. package/realtime/dist/index.d.ts +202 -8
  91. package/realtime/dist/index.js +2 -107
  92. package/realtime/src/realtime-continuity.ts +2 -2
  93. package/realtime/src/shared-room-store.ts +1 -2
  94. package/realtime-client/dist/index.d.ts +960 -22
  95. package/realtime-client/dist/index.js +3 -509
  96. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
  97. package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
  98. package/realtime-client/src/pull-atom-family-member.ts +2 -2
  99. package/realtime-client/src/pull-atom.ts +2 -2
  100. package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
  101. package/realtime-client/src/pull-mutable-atom.ts +2 -2
  102. package/realtime-client/src/pull-selector-family-member.ts +4 -4
  103. package/realtime-client/src/pull-selector.ts +4 -4
  104. package/realtime-client/src/push-state.ts +5 -10
  105. package/realtime-client/src/server-action.ts +4 -4
  106. package/realtime-client/src/sync-continuity.ts +6 -6
  107. package/realtime-react/dist/index.d.ts +166 -12
  108. package/realtime-react/dist/index.js +5 -154
  109. package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
  110. package/realtime-react/src/use-pull-atom.ts +1 -1
  111. package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
  112. package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
  113. package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
  114. package/realtime-react/src/use-pull-selector.ts +1 -1
  115. package/realtime-react/src/use-push.ts +1 -1
  116. package/realtime-react/src/use-server-action.ts +2 -2
  117. package/realtime-react/src/use-sync-continuity.ts +1 -1
  118. package/realtime-server/dist/index.d.ts +971 -28
  119. package/realtime-server/dist/index.js +3 -1001
  120. package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
  121. package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
  122. package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
  123. package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
  124. package/realtime-server/src/realtime-action-receiver.ts +1 -1
  125. package/realtime-server/src/realtime-family-provider.ts +2 -2
  126. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
  127. package/realtime-server/src/realtime-mutable-provider.ts +2 -2
  128. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
  129. package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
  130. package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
  131. package/realtime-server/src/realtime-state-provider.ts +2 -2
  132. package/realtime-testing/dist/index.d.ts +1091 -3
  133. package/realtime-testing/dist/index.js +20 -22
  134. package/realtime-testing/src/setup-realtime-test.tsx +2 -1
  135. package/src/index.ts +4 -0
  136. package/src/join.ts +218 -0
  137. package/src/silo.ts +4 -4
  138. package/src/timeline.ts +1 -1
  139. package/src/transaction.ts +4 -8
  140. package/transceivers/set-rtx/dist/index.d.ts +37 -2
  141. package/transceivers/set-rtx/dist/index.js +1 -215
  142. package/web/dist/index.d.ts +30 -1
  143. package/web/dist/index.js +1 -15
  144. package/data/src/until.ts +0 -15
  145. package/ephemeral/dist/index.d.ts +0 -67
  146. package/ephemeral/dist/index.js +0 -9
  147. package/ephemeral/package.json +0 -13
  148. package/ephemeral/src/index.ts +0 -1
  149. package/eslint-plugin/src/rules/lifespan.ts +0 -203
  150. package/immortal/dist/index.d.ts +0 -12
  151. package/immortal/dist/index.js +0 -9
  152. package/immortal/package.json +0 -13
  153. package/immortal/src/index.ts +0 -1
  154. package/immortal/src/seek-state.ts +0 -60
  155. /package/{ephemeral/src → src}/find-state.ts +0 -0
@@ -1,2 +1,2 @@
1
- export { CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Junction, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, claimWithinStore, clearStore, closeOperation, counterfeit, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deallocateFromStore, deposit, disposeAtom, disposeFromStore, disposeSelector, evictCachedValue, findInStore, fuseWithinStore, 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, 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-Y5MBNTVU.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';
2
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
  }
@@ -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`)
@@ -23,12 +23,14 @@ import type { Transaction } from "./transaction"
23
23
  export * from "./arbitrary"
24
24
  export * from "./atom"
25
25
  export * from "./caching"
26
+ export * from "./capitalize"
26
27
  export * from "./families"
27
28
  export * from "./future"
28
29
  export * from "./get-environment-data"
29
30
  export * from "./get-state"
30
31
  export * from "./get-trace"
31
32
  export * from "./ingest-updates"
33
+ export * from "./join"
32
34
  export * from "./junction"
33
35
  export * from "./keys"
34
36
  export * from "./lazy-map"
@@ -42,7 +42,7 @@ export function installIntoStore(
42
42
  return
43
43
  }
44
44
  for (const token of tokens) {
45
- const resource = withdraw(token, source)
45
+ const resource = withdraw(source, token)
46
46
  resource.install(target)
47
47
  }
48
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"