atom.io 0.31.1 → 0.32.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 (162) hide show
  1. package/data/dist/index.d.ts +3 -154
  2. package/data/dist/index.js +11 -559
  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-3PQTWLQQ.js +83 -0
  7. package/dist/chunk-3ZFTRSNG.js +523 -0
  8. package/dist/chunk-4LWKCEW3.js +14 -0
  9. package/dist/chunk-KVI5OBF2.js +153 -0
  10. package/dist/{chunk-Y5MBNTVU.js → chunk-UQEYZ3OI.js} +1814 -721
  11. package/dist/chunk-UYYKOGZQ.js +1034 -0
  12. package/dist/chunk-VRJP2PCU.js +631 -0
  13. package/dist/chunk-X7SD2NXU.js +108 -0
  14. package/dist/index.d.ts +137 -12
  15. package/dist/index.js +1 -228
  16. package/eslint-plugin/dist/index.d.ts +1 -30
  17. package/eslint-plugin/dist/index.js +3 -149
  18. package/eslint-plugin/src/index.ts +0 -1
  19. package/eslint-plugin/src/rules/explicit-state-types.ts +1 -0
  20. package/eslint-plugin/src/rules/index.ts +0 -1
  21. package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +1 -0
  22. package/eslint-plugin/src/walk.ts +1 -0
  23. package/internal/dist/index.d.ts +129 -58
  24. package/internal/dist/index.js +1 -1
  25. package/internal/src/atom/create-regular-atom.ts +3 -3
  26. package/internal/src/atom/dispose-atom.ts +4 -13
  27. package/internal/src/atom/is-default.ts +3 -3
  28. package/internal/src/caching.ts +5 -5
  29. package/internal/src/capitalize.ts +3 -0
  30. package/internal/src/families/create-readonly-selector-family.ts +5 -6
  31. package/internal/src/families/create-writable-selector-family.ts +1 -4
  32. package/internal/src/families/dispose-from-store.ts +3 -13
  33. package/internal/src/get-state/get-from-store.ts +2 -2
  34. package/internal/src/get-state/read-or-compute-value.ts +1 -1
  35. package/internal/src/index.ts +2 -0
  36. package/internal/src/install-into-store.ts +1 -1
  37. package/internal/src/join/edit-relations-in-store.ts +32 -0
  38. package/internal/src/join/find-relations-in-store.ts +124 -0
  39. package/internal/src/join/get-internal-relations-from-store.ts +14 -0
  40. package/internal/src/join/get-join.ts +31 -0
  41. package/internal/src/join/index.ts +5 -0
  42. package/{data/src/join.ts → internal/src/join/join-internal.ts} +21 -430
  43. package/internal/src/junction.ts +7 -4
  44. package/internal/src/keys.ts +7 -7
  45. package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
  46. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  47. package/internal/src/mutable/get-json-token.ts +1 -1
  48. package/internal/src/mutable/tracker-family.ts +19 -17
  49. package/internal/src/mutable/tracker.ts +8 -8
  50. package/internal/src/pretty-print.ts +1 -1
  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 +6 -9
  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 +4 -2
  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/store.ts +1 -1
  65. package/internal/src/store/withdraw.ts +22 -22
  66. package/internal/src/subscribe/recall-state.ts +1 -1
  67. package/internal/src/subscribe/subscribe-in-store.ts +3 -3
  68. package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
  69. package/internal/src/subscribe/subscribe-to-state.ts +5 -5
  70. package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
  71. package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
  72. package/internal/src/timeline/create-timeline.ts +19 -38
  73. package/internal/src/timeline/time-travel.ts +2 -1
  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.js +2 -620
  82. package/json/dist/index.d.ts +2 -2
  83. package/json/dist/index.js +1 -80
  84. package/json/src/select-json-family.ts +3 -14
  85. package/package.json +31 -49
  86. package/react/dist/index.js +2 -82
  87. package/react/src/use-o.ts +1 -1
  88. package/react/src/use-tl.ts +2 -2
  89. package/react-devtools/dist/index.css +16 -14
  90. package/react-devtools/dist/index.js +31 -18
  91. package/react-devtools/src/Updates.tsx +12 -0
  92. package/react-devtools/src/devtools.scss +16 -14
  93. package/react-devtools/src/json-editor/editors-by-type/utilities/cast-to-json.ts +2 -1
  94. package/realtime/dist/index.d.ts +1 -2
  95. package/realtime/dist/index.js +2 -107
  96. package/realtime/src/realtime-continuity.ts +3 -2
  97. package/realtime/src/shared-room-store.ts +1 -2
  98. package/realtime-client/dist/index.d.ts +9 -9
  99. package/realtime-client/dist/index.js +3 -509
  100. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
  101. package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
  102. package/realtime-client/src/pull-atom-family-member.ts +2 -2
  103. package/realtime-client/src/pull-atom.ts +2 -2
  104. package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
  105. package/realtime-client/src/pull-mutable-atom.ts +2 -2
  106. package/realtime-client/src/pull-selector-family-member.ts +4 -4
  107. package/realtime-client/src/pull-selector.ts +4 -4
  108. package/realtime-client/src/push-state.ts +5 -10
  109. package/realtime-client/src/server-action.ts +4 -4
  110. package/realtime-client/src/sync-continuity.ts +6 -6
  111. package/realtime-react/dist/index.js +5 -154
  112. package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
  113. package/realtime-react/src/use-pull-atom.ts +1 -1
  114. package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
  115. package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
  116. package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
  117. package/realtime-react/src/use-pull-selector.ts +1 -1
  118. package/realtime-react/src/use-push.ts +1 -1
  119. package/realtime-react/src/use-server-action.ts +2 -2
  120. package/realtime-react/src/use-sync-continuity.ts +1 -1
  121. package/realtime-server/dist/index.d.ts +2 -4
  122. package/realtime-server/dist/index.js +3 -1001
  123. package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
  124. package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
  125. package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
  126. package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
  127. package/realtime-server/src/ipc-sockets/child-socket.ts +2 -0
  128. package/realtime-server/src/realtime-action-receiver.ts +1 -1
  129. package/realtime-server/src/realtime-family-provider.ts +2 -2
  130. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
  131. package/realtime-server/src/realtime-mutable-provider.ts +2 -2
  132. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
  133. package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
  134. package/realtime-server/src/realtime-server-stores/server-sync-store.ts +10 -2
  135. package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
  136. package/realtime-server/src/realtime-state-provider.ts +2 -2
  137. package/realtime-testing/dist/index.js +20 -22
  138. package/realtime-testing/src/setup-realtime-test.tsx +2 -1
  139. package/src/index.ts +4 -0
  140. package/src/join.ts +218 -0
  141. package/src/silo.ts +4 -4
  142. package/src/timeline.ts +1 -1
  143. package/src/transaction.ts +4 -8
  144. package/transceivers/set-rtx/dist/index.d.ts +4 -3
  145. package/transceivers/set-rtx/dist/index.js +1 -215
  146. package/transceivers/set-rtx/src/set-rtx.ts +4 -7
  147. package/web/dist/index.js +1 -15
  148. package/data/src/until.ts +0 -15
  149. package/ephemeral/dist/index.d.ts +0 -67
  150. package/ephemeral/dist/index.js +0 -9
  151. package/ephemeral/package.json +0 -13
  152. package/ephemeral/src/index.ts +0 -1
  153. package/eslint-plugin/src/rules/lifespan.ts +0 -203
  154. package/immortal/dist/index.d.ts +0 -12
  155. package/immortal/dist/index.js +0 -9
  156. package/immortal/package.json +0 -13
  157. package/immortal/src/index.ts +0 -1
  158. package/immortal/src/seek-state.ts +0 -60
  159. package/react-devtools/src/json-editor/assets/Untitled-1.ai +2 -1436
  160. package/react-devtools/src/json-editor/assets/data-vis.ai +1 -1548
  161. package/react-devtools/src/json-editor/comp/json-editor-sketches.ai +5 -1449
  162. /package/{ephemeral/src → src}/find-state.ts +0 -0
@@ -1,67 +1,39 @@
1
1
  import type {
2
2
  CompoundTypedKey,
3
+ findState,
3
4
  getState,
4
- Hierarchy,
5
+ JoinOptions,
5
6
  MutableAtomFamilyToken,
6
7
  Read,
7
8
  ReadonlySelectorFamilyToken,
8
- ReadonlySelectorToken,
9
9
  RegularAtomFamilyToken,
10
10
  setState,
11
11
  SetterToolkit,
12
- SingularTypedKey,
13
12
  Write,
14
13
  } from "atom.io"
15
- import { Anarchy, Realm } from "atom.io"
16
- import type { findState } from "atom.io/ephemeral"
17
- import type { seekState } from "atom.io/immortal"
18
- import type {
19
- BaseExternalStoreConfiguration,
20
- ExternalStoreConfiguration,
21
- JunctionEntriesBase,
22
- JunctionSchemaBase,
23
- Molecule,
24
- Refinement,
25
- Store,
26
- } from "atom.io/internal"
27
- import {
28
- createMutableAtomFamily,
29
- createReadonlySelectorFamily,
30
- createRegularAtomFamily,
31
- findInStore,
32
- getFromStore,
33
- getJsonFamily,
34
- getJsonToken,
35
- IMPLICIT,
36
- isChildStore,
37
- Junction,
38
- newest,
39
- seekInStore,
40
- setIntoStore,
41
- } from "atom.io/internal"
14
+ import { Anarchy } from "atom.io"
42
15
  import type { Canonical, Json, stringified } from "atom.io/json"
43
16
  import { stringifyJson } from "atom.io/json"
44
17
  import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
45
18
  import { SetRTX } from "atom.io/transceivers/set-rtx"
46
19
 
47
- function capitalize<S extends string>(string: S): Capitalize<S> {
48
- return (string[0].toUpperCase() + string.slice(1)) as Capitalize<S>
49
- }
50
-
51
- export interface JoinOptions<
52
- ASide extends string,
53
- AType extends string,
54
- BSide extends string,
55
- BType extends string,
56
- Cardinality extends `1:1` | `1:n` | `n:n`,
57
- Content extends Json.Object | null,
58
- > extends JunctionSchemaBase<ASide, BSide>,
59
- Partial<JunctionEntriesBase<AType, BType, Content>> {
60
- readonly key: string
61
- readonly cardinality: Cardinality
62
- readonly isAType: Refinement<string, AType>
63
- readonly isBType: Refinement<string, BType>
64
- }
20
+ import { capitalize } from "../capitalize"
21
+ import {
22
+ createReadonlySelectorFamily,
23
+ createRegularAtomFamily,
24
+ findInStore,
25
+ } from "../families"
26
+ import { getFromStore } from "../get-state"
27
+ import type {
28
+ BaseExternalStoreConfiguration,
29
+ ExternalStoreConfiguration,
30
+ } from "../junction"
31
+ import { Junction } from "../junction"
32
+ import type { Molecule } from "../molecule"
33
+ import { createMutableAtomFamily, getJsonFamily, getJsonToken } from "../mutable"
34
+ import { setIntoStore } from "../set-state"
35
+ import type { Store } from "../store"
36
+ import { IMPLICIT } from "../store"
65
37
 
66
38
  export type JoinStateFamilies<
67
39
  ASide extends string,
@@ -144,23 +116,6 @@ export type JoinStateFamilies<
144
116
  }
145
117
  : never
146
118
 
147
- export type JoinHierarchy<
148
- AType extends SingularTypedKey,
149
- BType extends SingularTypedKey,
150
- > = Hierarchy<
151
- [
152
- {
153
- above: `root`
154
- below: [AType, BType]
155
- },
156
- {
157
- above: [AType, BType]
158
- style: `all`
159
- below: CompoundTypedKey<`content`, AType, BType>
160
- },
161
- ]
162
- >
163
-
164
119
  export class Join<
165
120
  const ASide extends string,
166
121
  const AType extends string,
@@ -233,8 +188,6 @@ export class Join<
233
188
  }) as typeof setState,
234
189
  find: ((...ps: Parameters<typeof findState>) =>
235
190
  findInStore(store, ...ps)) as typeof findState,
236
- seek: ((...ps: Parameters<typeof seekState>) =>
237
- seekInStore(store, ...ps)) as typeof seekState,
238
191
  json: (token) => getJsonToken(store, token),
239
192
  }
240
193
 
@@ -608,7 +561,7 @@ export class Join<
608
561
  this.states = states
609
562
  break
610
563
  }
611
- default: {
564
+ case `n:n`: {
612
565
  const multipleRelatedKeysSelectors = getMultipleKeySelectorFamily()
613
566
  const stateKeyA = `${aSide}KeysOf${capitalize(bSide)}` as const
614
567
  const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}` as const
@@ -647,365 +600,3 @@ export class Join<
647
600
  }
648
601
  }
649
602
  }
650
-
651
- export type JoinToken<
652
- ASide extends string,
653
- AType extends string,
654
- BSide extends string,
655
- BType extends string,
656
- Cardinality extends `1:1` | `1:n` | `n:n`,
657
- Content extends Json.Object | null = null,
658
- > = {
659
- key: string
660
- type: `join`
661
- cardinality: Cardinality
662
- a: ASide
663
- b: BSide
664
- __aType?: AType
665
- __bType?: BType
666
- __content?: Content
667
- }
668
-
669
- export function join<
670
- const ASide extends string,
671
- const AType extends string,
672
- const BSide extends string,
673
- const BType extends string,
674
- const Cardinality extends `1:1` | `1:n` | `n:n`,
675
- >(
676
- options: JoinOptions<ASide, AType, BSide, BType, Cardinality, null>,
677
- defaultContent?: undefined,
678
- store?: Store,
679
- ): JoinToken<ASide, AType, BSide, BType, Cardinality, null>
680
- export function join<
681
- const ASide extends string,
682
- const AType extends string,
683
- const BSide extends string,
684
- const BType extends string,
685
- const Cardinality extends `1:1` | `1:n` | `n:n`,
686
- const Content extends Json.Object,
687
- >(
688
- options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
689
- defaultContent: Content,
690
- store?: Store,
691
- ): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>
692
- export function join<
693
- ASide extends string,
694
- AType extends string,
695
- BSide extends string,
696
- BType extends string,
697
- Cardinality extends `1:1` | `1:n` | `n:n`,
698
- Content extends Json.Object,
699
- >(
700
- options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
701
- defaultContent: Content | undefined,
702
- store: Store = IMPLICIT.STORE,
703
- ): JoinToken<ASide, AType, BSide, BType, Cardinality, Content> {
704
- store.joins.set(options.key, new Join(options, defaultContent, store))
705
- const token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content> = {
706
- key: options.key,
707
- type: `join`,
708
- a: options.between[0],
709
- b: options.between[1],
710
- cardinality: options.cardinality,
711
- }
712
- return token
713
- }
714
-
715
- export function getJoin<
716
- ASide extends string,
717
- AType extends string,
718
- BSide extends string,
719
- BType extends string,
720
- Cardinality extends `1:1` | `1:n` | `n:n`,
721
- Content extends Json.Object | null,
722
- >(
723
- token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
724
- store: Store,
725
- ): Join<ASide, AType, BSide, BType, Cardinality, Content> {
726
- let myJoin = store.joins.get(token.key)
727
- if (myJoin === undefined) {
728
- const rootJoinMap = IMPLICIT.STORE.joins
729
- const rootJoin = rootJoinMap.get(token.key)
730
- if (rootJoin === undefined) {
731
- throw new Error(
732
- `Join "${token.key}" not found in store "${store.config.name}"`,
733
- )
734
- }
735
- myJoin = new Join(rootJoin.options, rootJoin.defaultContent, store)
736
- store.joins.set(token.key, myJoin)
737
- }
738
- return myJoin
739
- }
740
-
741
- export type JoinStates<
742
- ASide extends string,
743
- AType extends string,
744
- BSide extends string,
745
- BType extends string,
746
- Cardinality extends `1:1` | `1:n` | `n:n`,
747
- Content extends Json.Object | null,
748
- > = Cardinality extends `1:1`
749
- ? (Content extends Json.Object
750
- ? {
751
- readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
752
- [AType, Content] | null,
753
- BType
754
- >
755
- } & {
756
- readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
757
- [BType, Content] | null,
758
- AType
759
- >
760
- }
761
- : {}) & {
762
- readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
763
- AType | null,
764
- BType
765
- >
766
- } & {
767
- readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
768
- BType | null,
769
- AType
770
- >
771
- }
772
- : Cardinality extends `1:n`
773
- ? (Content extends Json.Object
774
- ? {
775
- readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
776
- [AType, Content] | null,
777
- BType
778
- >
779
- } & {
780
- readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
781
- [BType, Content][],
782
- AType
783
- >
784
- }
785
- : {}) & {
786
- readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
787
- AType | null,
788
- BType
789
- >
790
- } & {
791
- readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
792
- BType[],
793
- AType
794
- >
795
- }
796
- : Cardinality extends `n:n`
797
- ? (Content extends Json.Object
798
- ? {
799
- readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
800
- [AType, Content][],
801
- BType
802
- >
803
- } & {
804
- readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
805
- [BType, Content][],
806
- AType
807
- >
808
- }
809
- : {}) & {
810
- readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
811
- AType[],
812
- BType
813
- >
814
- } & {
815
- readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
816
- BType[],
817
- AType
818
- >
819
- }
820
- : never
821
-
822
- export function findRelationsInStore<
823
- ASide extends string,
824
- AType extends string,
825
- BSide extends string,
826
- BType extends string,
827
- Cardinality extends `1:1` | `1:n` | `n:n`,
828
- Content extends Json.Object | null,
829
- >(
830
- token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
831
- key: AType | BType,
832
- store: Store,
833
- ): JoinStates<ASide, AType, BSide, BType, Cardinality, Content> {
834
- const myJoin = getJoin(token, store)
835
- let relations: JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
836
- switch (token.cardinality satisfies `1:1` | `1:n` | `n:n`) {
837
- case `1:1`: {
838
- const keyAB = `${token.a}KeyOf${capitalize(token.b)}`
839
- const keyBA = `${token.b}KeyOf${capitalize(token.a)}`
840
- relations = {
841
- get [keyAB]() {
842
- const familyAB = myJoin.states[keyAB as any]
843
- const state = findInStore(store, familyAB, key)
844
- return state
845
- },
846
- get [keyBA]() {
847
- const familyBA = myJoin.states[keyBA as any]
848
- const state = findInStore(store, familyBA, key)
849
- return state
850
- },
851
- } as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
852
- const entryAB = `${token.a}EntryOf${capitalize(token.b)}`
853
- if (entryAB in myJoin.states) {
854
- const entryBA = `${token.b}EntryOf${capitalize(token.a)}`
855
- Object.assign(relations, {
856
- get [entryAB]() {
857
- const familyAB = myJoin.states[entryAB as any]
858
- const state = findInStore(store, familyAB, key)
859
- return state
860
- },
861
- get [entryBA]() {
862
- const familyBA = myJoin.states[entryBA as any]
863
- const state = findInStore(store, familyBA, key)
864
- return state
865
- },
866
- })
867
- }
868
- break
869
- }
870
- case `1:n`: {
871
- const keyAB = `${token.a}KeyOf${capitalize(token.b)}`
872
- const keysBA = `${token.b}KeysOf${capitalize(token.a)}`
873
- relations = {
874
- get [keyAB]() {
875
- const familyAB = myJoin.states[keyAB as any]
876
- const state = findInStore(store, familyAB, key)
877
- return state
878
- },
879
- get [keysBA]() {
880
- const familyBA = myJoin.states[keysBA as any]
881
- const state = findInStore(store, familyBA, key)
882
- return state
883
- },
884
- } as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
885
- const entryAB = `${token.a}EntryOf${capitalize(token.b)}`
886
- if (entryAB in myJoin.states) {
887
- const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`
888
- Object.assign(relations, {
889
- get [entryAB]() {
890
- const familyAB = myJoin.states[entryAB as any]
891
- const state = findInStore(store, familyAB, key)
892
- return state
893
- },
894
- get [entriesBA]() {
895
- const familyBA = myJoin.states[entriesBA as any]
896
- const state = findInStore(store, familyBA, key)
897
- return state
898
- },
899
- })
900
- }
901
- break
902
- }
903
- case `n:n`: {
904
- const keysAB = `${token.a}KeysOf${capitalize(token.b)}`
905
- const keysBA = `${token.b}KeysOf${capitalize(token.a)}`
906
- relations = {
907
- get [keysAB]() {
908
- const familyAB = myJoin.states[keysAB as any]
909
- const state = findInStore(store, familyAB, key)
910
- return state
911
- },
912
- get [keysBA]() {
913
- const familyBA = myJoin.states[keysBA as any]
914
- const state = findInStore(store, familyBA, key)
915
- return state
916
- },
917
- } as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
918
- const entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`
919
- if (entriesAB in myJoin.states) {
920
- const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`
921
- Object.assign(relations, {
922
- get [entriesAB]() {
923
- const familyAB = myJoin.states[entriesAB as any]
924
- const state = findInStore(store, familyAB, key)
925
- return state
926
- },
927
- get [entriesBA]() {
928
- const familyBA = myJoin.states[entriesBA as any]
929
- const state = findInStore(store, familyBA, key)
930
- return state
931
- },
932
- })
933
- }
934
- }
935
- }
936
- return relations
937
- }
938
-
939
- export function findRelations<
940
- ASide extends string,
941
- AType extends string,
942
- BSide extends string,
943
- BType extends string,
944
- Cardinality extends `1:1` | `1:n` | `n:n`,
945
- Content extends Json.Object | null,
946
- >(
947
- token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
948
- key: AType | BType,
949
- ): JoinStates<ASide, AType, BSide, BType, Cardinality, Content> {
950
- return findRelationsInStore(token, key, IMPLICIT.STORE)
951
- }
952
-
953
- export function editRelationsInStore<
954
- ASide extends string,
955
- AType extends string,
956
- BSide extends string,
957
- BType extends string,
958
- Cardinality extends `1:1` | `1:n` | `n:n`,
959
- Content extends Json.Object | null,
960
- >(
961
- token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
962
- change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void,
963
- store: Store,
964
- ): void {
965
- const myJoin = getJoin(token, store)
966
- const target = newest(store)
967
- if (isChildStore(target)) {
968
- const { toolkit } = target.transactionMeta
969
- myJoin.transact(toolkit, ({ relations }) => {
970
- change(relations)
971
- })
972
- } else {
973
- change(myJoin.relations)
974
- }
975
- }
976
-
977
- export function editRelations<
978
- ASide extends string,
979
- AType extends string,
980
- BSide extends string,
981
- BType extends string,
982
- Cardinality extends `1:1` | `1:n` | `n:n`,
983
- Content extends Json.Object | null,
984
- >(
985
- token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
986
- change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void,
987
- ): void {
988
- editRelationsInStore(token, change, IMPLICIT.STORE)
989
- }
990
-
991
- export function getInternalRelationsFromStore(
992
- token: JoinToken<any, any, any, any, any, any>,
993
- store: Store,
994
- ): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
995
- const myJoin = getJoin(token, store)
996
- const family = myJoin.core.relatedKeysAtoms
997
- return family
998
- }
999
-
1000
- export function getInternalRelations<
1001
- ASide extends string,
1002
- AType extends string,
1003
- BSide extends string,
1004
- BType extends string,
1005
- Cardinality extends `1:1` | `1:n` | `n:n`,
1006
- Content extends Json.Object | null,
1007
- >(
1008
- token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
1009
- ): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
1010
- return getInternalRelationsFromStore(token, IMPLICIT.STORE)
1011
- }
@@ -337,10 +337,13 @@ export class Junction<
337
337
  const bPrev = this.getRelatedKey(a)
338
338
  if (bPrev && bPrev !== b) this.delete(a, bPrev)
339
339
  }
340
- case `1:n`: {
341
- const aPrev = this.getRelatedKey(b)
342
- if (aPrev && aPrev !== a) this.delete(aPrev, b)
343
- }
340
+ case `1:n`:
341
+ {
342
+ const aPrev = this.getRelatedKey(b)
343
+ if (aPrev && aPrev !== a) this.delete(aPrev, b)
344
+ }
345
+ break
346
+ case `n:n`: // do nothing
344
347
  }
345
348
  if (content) {
346
349
  const contentKey = this.makeContentKey(a, b)
@@ -8,23 +8,23 @@ export type ReadonlySelectorKey<T> = string & {
8
8
  __brand?: T
9
9
  }
10
10
 
11
- export const isAtomKey = (key: string, store: Store): key is AtomKey<unknown> =>
11
+ export const isAtomKey = (store: Store, key: string): key is AtomKey<unknown> =>
12
12
  newest(store).atoms.has(key)
13
13
  export const isSelectorKey = (
14
- key: string,
15
14
  store: Store,
15
+ key: string,
16
16
  ): key is SelectorKey<unknown> => newest(store).selectors.has(key)
17
17
  export const isReadonlySelectorKey = (
18
- key: string,
19
18
  store: Store,
19
+ key: string,
20
20
  ): key is ReadonlySelectorKey<unknown> =>
21
21
  newest(store).readonlySelectors.has(key)
22
22
 
23
23
  export type StateKey<T> = AtomKey<T> | ReadonlySelectorKey<T> | SelectorKey<T>
24
24
  export const isStateKey = (
25
- key: string,
26
25
  store: Store,
26
+ key: string,
27
27
  ): key is StateKey<unknown> =>
28
- isAtomKey(key, store) ||
29
- isSelectorKey(key, store) ||
30
- isReadonlySelectorKey(key, store)
28
+ isAtomKey(store, key) ||
29
+ isSelectorKey(store, key) ||
30
+ isReadonlySelectorKey(store, key)
@@ -80,7 +80,7 @@ export function createMutableAtomFamily<
80
80
  }) satisfies MutableAtomFamily<T, J, K>
81
81
 
82
82
  store.families.set(options.key, atomFamily)
83
- selectJsonFamily(atomFamily, options, store)
83
+ selectJsonFamily(store, atomFamily, options)
84
84
  new FamilyTracker(atomFamily, store)
85
85
  return familyToken
86
86
  }
@@ -61,8 +61,8 @@ export function createMutableAtom<
61
61
  }
62
62
  const initialValue = options.default()
63
63
  target.atoms.set(newAtom.key, newAtom)
64
- markAtomAsDefault(options.key, store)
65
- cacheValue(options.key, initialValue, subject, target)
64
+ markAtomAsDefault(store, options.key)
65
+ cacheValue(target, options.key, initialValue, subject)
66
66
  const token = deposit(newAtom)
67
67
  if (options.effects) {
68
68
  let effectIndex = 0
@@ -73,7 +73,7 @@ export function createMutableAtom<
73
73
  setIntoStore(store, token, next)
74
74
  },
75
75
  onSet: (handle: UpdateHandler<T>) =>
76
- subscribeToState(token, handle, `effect[${effectIndex}]`, store),
76
+ subscribeToState(store, token, `effect[${effectIndex}]`, handle),
77
77
  })
78
78
  if (cleanup) {
79
79
  cleanupFunctions.push(cleanup)
@@ -27,7 +27,7 @@ export const getJsonToken = <
27
27
  key: jsonFamilyKey,
28
28
  type: `selector_family`,
29
29
  }
30
- const family = withdraw(jsonFamilyToken, target)
30
+ const family = withdraw(target, jsonFamilyToken)
31
31
  const subKey = JSON.parse(mutableAtomToken.family.subKey)
32
32
  const jsonToken = findInStore(store, family, subKey)
33
33
  return jsonToken
@@ -2,7 +2,7 @@ import type { Canonical } from "atom.io/json"
2
2
  import { parseJson } from "atom.io/json"
3
3
 
4
4
  import type { MutableAtomFamily, RegularAtomFamily } from ".."
5
- import { createRegularAtomFamily, seekInStore } from "../families"
5
+ import { createRegularAtomFamily } from "../families"
6
6
  import { type Store, withdraw } from "../store"
7
7
  import { Tracker } from "./tracker"
8
8
  import type { Transceiver } from "./transceiver"
@@ -11,6 +11,7 @@ export class FamilyTracker<
11
11
  Core extends Transceiver<any>,
12
12
  FamilyMemberKey extends Canonical,
13
13
  > {
14
+ private trackers: Map<FamilyMemberKey, Tracker<Core>> = new Map()
14
15
  private readonly Update: Core extends Transceiver<infer Signal>
15
16
  ? Signal
16
17
  : never
@@ -36,26 +37,27 @@ export class FamilyTracker<
36
37
  },
37
38
  [`mutable`, `updates`],
38
39
  )
39
- this.latestUpdateAtoms = withdraw(updateAtoms, store)
40
+ this.latestUpdateAtoms = withdraw(store, updateAtoms)
40
41
  this.mutableAtoms = mutableAtoms
41
42
  this.mutableAtoms.subject.subscribe(
42
43
  `store=${store.config.name}::tracker-atom-family`,
43
44
  (event) => {
44
- if (event.token.family) {
45
- const key = parseJson(event.token.family.subKey) as FamilyMemberKey
46
- seekInStore(store, this.latestUpdateAtoms, key)
47
- new Tracker<Core>(event.token, store)
48
- }
49
- },
50
- )
51
- this.latestUpdateAtoms.subject.subscribe(
52
- `store=${store.config.name}::tracker-atom-family`,
53
- (event) => {
54
- if (event.token.family) {
55
- const key = parseJson(event.token.family.subKey) as FamilyMemberKey
56
- const mutableAtomToken = seekInStore(store, this.mutableAtoms, key)
57
- if (mutableAtomToken) {
58
- new Tracker<Core>(mutableAtomToken, store)
45
+ const { type, token } = event
46
+ if (token.family) {
47
+ const key = parseJson(token.family.subKey)
48
+ switch (type) {
49
+ case `state_creation`:
50
+ this.trackers.set(key, new Tracker<Core>(token, store))
51
+ break
52
+ case `state_disposal`:
53
+ {
54
+ const tracker = this.trackers.get(key)
55
+ if (tracker) {
56
+ tracker[Symbol.dispose]()
57
+ this.trackers.delete(key)
58
+ }
59
+ }
60
+ break
59
61
  }
60
62
  }
61
63
  },