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,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
 
@@ -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
- }
@@ -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)