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.
- package/data/dist/index.d.ts +867 -101
- package/data/dist/index.js +10 -558
- package/data/src/index.ts +0 -2
- package/data/src/struct-family.ts +1 -1
- package/data/src/struct.ts +1 -2
- package/dist/chunk-354XQWHH.js +153 -0
- package/dist/chunk-4LWKCEW3.js +14 -0
- package/dist/chunk-5F2V7S3B.js +83 -0
- package/dist/chunk-ECOMOMUN.js +631 -0
- package/dist/{chunk-Y5MBNTVU.js → chunk-GY2XQYZY.js} +1791 -703
- package/dist/chunk-NF7FJKJD.js +107 -0
- package/dist/chunk-R3ZUK5EH.js +1024 -0
- package/dist/chunk-Z2UJW4NQ.js +523 -0
- package/dist/index.d.ts +622 -26
- package/dist/index.js +1 -228
- package/eslint-plugin/dist/index.d.ts +1 -30
- package/eslint-plugin/dist/index.js +0 -146
- package/eslint-plugin/src/index.ts +0 -1
- package/eslint-plugin/src/rules/index.ts +0 -1
- package/internal/dist/index.d.ts +783 -64
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/create-regular-atom.ts +3 -3
- package/internal/src/atom/dispose-atom.ts +4 -13
- package/internal/src/atom/is-default.ts +3 -3
- package/internal/src/caching.ts +5 -5
- package/internal/src/capitalize.ts +3 -0
- package/internal/src/families/create-readonly-selector-family.ts +5 -6
- package/internal/src/families/create-writable-selector-family.ts +1 -4
- package/internal/src/families/dispose-from-store.ts +3 -13
- package/internal/src/get-state/get-from-store.ts +2 -2
- package/internal/src/get-state/read-or-compute-value.ts +1 -1
- package/internal/src/index.ts +2 -0
- package/internal/src/install-into-store.ts +1 -1
- package/internal/src/join/edit-relations-in-store.ts +32 -0
- package/internal/src/join/find-relations-in-store.ts +124 -0
- package/internal/src/join/get-internal-relations-from-store.ts +14 -0
- package/internal/src/join/get-join.ts +31 -0
- package/internal/src/join/index.ts +5 -0
- package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
- package/internal/src/keys.ts +7 -7
- package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-token.ts +1 -1
- package/internal/src/mutable/tracker-family.ts +19 -17
- package/internal/src/mutable/tracker.ts +8 -8
- package/internal/src/pretty-print.ts +1 -1
- package/internal/src/selector/create-readonly-selector.ts +3 -7
- package/internal/src/selector/create-writable-selector.ts +4 -4
- package/internal/src/selector/dispose-selector.ts +20 -11
- package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
- package/internal/src/selector/register-selector.ts +6 -9
- package/internal/src/selector/trace-selector-atoms.ts +2 -2
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/set-state/emit-update.ts +1 -1
- package/internal/src/set-state/evict-downstream.ts +1 -1
- package/internal/src/set-state/set-atom-or-selector.ts +1 -1
- package/internal/src/set-state/set-atom.ts +10 -10
- package/internal/src/set-state/set-into-store.ts +2 -2
- package/internal/src/set-state/stow-update.ts +1 -1
- package/internal/src/store/store.ts +1 -1
- package/internal/src/store/withdraw.ts +22 -22
- package/internal/src/subscribe/recall-state.ts +1 -1
- package/internal/src/subscribe/subscribe-in-store.ts +3 -3
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
- package/internal/src/subscribe/subscribe-to-state.ts +5 -5
- package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
- package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
- package/internal/src/timeline/create-timeline.ts +17 -37
- package/internal/src/transaction/act-upon-store.ts +2 -2
- package/internal/src/transaction/apply-transaction.ts +5 -5
- package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +5 -8
- package/internal/src/transaction/create-transaction.ts +3 -3
- package/internal/src/transaction/get-epoch-number.ts +3 -3
- package/internal/src/transaction/set-epoch-number.ts +2 -2
- package/introspection/dist/index.d.ts +922 -6
- package/introspection/dist/index.js +2 -620
- package/json/dist/index.d.ts +899 -5
- package/json/dist/index.js +1 -80
- package/json/src/select-json-family.ts +3 -14
- package/package.json +24 -42
- package/react/dist/index.d.ts +921 -3
- package/react/dist/index.js +2 -82
- package/react/src/use-o.ts +1 -1
- package/react/src/use-tl.ts +2 -2
- package/react-devtools/dist/index.css +16 -14
- package/react-devtools/dist/index.d.ts +26 -1
- package/react-devtools/dist/index.js +6 -6
- package/react-devtools/src/devtools.scss +16 -14
- package/realtime/dist/index.d.ts +202 -8
- package/realtime/dist/index.js +2 -107
- package/realtime/src/realtime-continuity.ts +2 -2
- package/realtime/src/shared-room-store.ts +1 -2
- package/realtime-client/dist/index.d.ts +960 -22
- package/realtime-client/dist/index.js +3 -509
- package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
- package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
- package/realtime-client/src/pull-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-atom.ts +2 -2
- package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-mutable-atom.ts +2 -2
- package/realtime-client/src/pull-selector-family-member.ts +4 -4
- package/realtime-client/src/pull-selector.ts +4 -4
- package/realtime-client/src/push-state.ts +5 -10
- package/realtime-client/src/server-action.ts +4 -4
- package/realtime-client/src/sync-continuity.ts +6 -6
- package/realtime-react/dist/index.d.ts +166 -12
- package/realtime-react/dist/index.js +5 -154
- package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
- package/realtime-react/src/use-pull-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector.ts +1 -1
- package/realtime-react/src/use-push.ts +1 -1
- package/realtime-react/src/use-server-action.ts +2 -2
- package/realtime-react/src/use-sync-continuity.ts +1 -1
- package/realtime-server/dist/index.d.ts +971 -28
- package/realtime-server/dist/index.js +3 -1001
- package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
- package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
- package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
- package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
- package/realtime-server/src/realtime-action-receiver.ts +1 -1
- package/realtime-server/src/realtime-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
- package/realtime-server/src/realtime-state-provider.ts +2 -2
- package/realtime-testing/dist/index.d.ts +1091 -3
- package/realtime-testing/dist/index.js +20 -22
- package/realtime-testing/src/setup-realtime-test.tsx +2 -1
- package/src/index.ts +4 -0
- package/src/join.ts +218 -0
- package/src/silo.ts +4 -4
- package/src/timeline.ts +1 -1
- package/src/transaction.ts +4 -8
- package/transceivers/set-rtx/dist/index.d.ts +37 -2
- package/transceivers/set-rtx/dist/index.js +1 -215
- package/web/dist/index.d.ts +30 -1
- package/web/dist/index.js +1 -15
- package/data/src/until.ts +0 -15
- package/ephemeral/dist/index.d.ts +0 -67
- package/ephemeral/dist/index.js +0 -9
- package/ephemeral/package.json +0 -13
- package/ephemeral/src/index.ts +0 -1
- package/eslint-plugin/src/rules/lifespan.ts +0 -203
- package/immortal/dist/index.d.ts +0 -12
- package/immortal/dist/index.js +0 -9
- package/immortal/package.json +0 -13
- package/immortal/src/index.ts +0 -1
- package/immortal/src/seek-state.ts +0 -60
- /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
|
-
|
|
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
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
}
|
package/internal/src/keys.ts
CHANGED
|
@@ -8,23 +8,23 @@ export type ReadonlySelectorKey<T> = string & {
|
|
|
8
8
|
__brand?: T
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export const isAtomKey = (
|
|
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(
|
|
29
|
-
isSelectorKey(
|
|
30
|
-
isReadonlySelectorKey(
|
|
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
|
|
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
|
|
65
|
-
cacheValue(options.key, initialValue, subject
|
|
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(
|
|
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(
|
|
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
|
|
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(
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
},
|
|
@@ -70,7 +70,9 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
70
70
|
},
|
|
71
71
|
)
|
|
72
72
|
this.unsubscribeFromState = subscribeToState(
|
|
73
|
+
target,
|
|
73
74
|
mutableState,
|
|
75
|
+
subscriptionKey,
|
|
74
76
|
(update) => {
|
|
75
77
|
if (update.newValue !== update.oldValue) {
|
|
76
78
|
this.unsubscribeFromInnerValue()
|
|
@@ -82,8 +84,6 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
82
84
|
)
|
|
83
85
|
}
|
|
84
86
|
},
|
|
85
|
-
subscriptionKey,
|
|
86
|
-
target,
|
|
87
87
|
)
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -96,7 +96,9 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
96
96
|
isChildStore(target) ? target.transactionMeta.update.key : `main`
|
|
97
97
|
}:${mutableState.key}`
|
|
98
98
|
subscribeToState(
|
|
99
|
+
target,
|
|
99
100
|
latestUpdateState,
|
|
101
|
+
subscriptionKey,
|
|
100
102
|
({ newValue, oldValue }) => {
|
|
101
103
|
const timelineId = target.timelineTopics.getRelatedKey(
|
|
102
104
|
latestUpdateState.key,
|
|
@@ -106,7 +108,9 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
106
108
|
const timelineData = target.timelines.get(timelineId)
|
|
107
109
|
if (timelineData?.timeTraveling) {
|
|
108
110
|
const unsubscribe = subscribeToTimeline(
|
|
111
|
+
target,
|
|
109
112
|
{ key: timelineId, type: `timeline` },
|
|
113
|
+
subscriptionKey,
|
|
110
114
|
(update) => {
|
|
111
115
|
unsubscribe()
|
|
112
116
|
setIntoStore(target, mutableState, (transceiver) => {
|
|
@@ -118,8 +122,6 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
118
122
|
return transceiver
|
|
119
123
|
})
|
|
120
124
|
},
|
|
121
|
-
subscriptionKey,
|
|
122
|
-
target,
|
|
123
125
|
)
|
|
124
126
|
return
|
|
125
127
|
}
|
|
@@ -152,15 +154,13 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
152
154
|
},
|
|
153
155
|
)
|
|
154
156
|
},
|
|
155
|
-
subscriptionKey,
|
|
156
|
-
target,
|
|
157
157
|
)
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
public mutableState: MutableAtomToken<Mutable, Json.Serializable>
|
|
161
161
|
public latestUpdateState: RegularAtomToken<typeof this.Update | null>
|
|
162
162
|
|
|
163
|
-
public dispose: () => void
|
|
163
|
+
public [Symbol.dispose]: () => void
|
|
164
164
|
|
|
165
165
|
public constructor(
|
|
166
166
|
mutableState: MutableAtomToken<Mutable, Json.Serializable>,
|
|
@@ -172,7 +172,7 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
172
172
|
this.observeCore(mutableState, this.latestUpdateState, target)
|
|
173
173
|
this.updateCore(mutableState, this.latestUpdateState, target)
|
|
174
174
|
target.trackers.set(mutableState.key, this)
|
|
175
|
-
this.dispose = () => {
|
|
175
|
+
this[Symbol.dispose] = () => {
|
|
176
176
|
this.unsubscribeFromInnerValue()
|
|
177
177
|
this.unsubscribeFromState()
|
|
178
178
|
target.trackers.delete(mutableState.key)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AtomIOToken } from "atom.io"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { capitalize } from "./capitalize"
|
|
4
4
|
|
|
5
5
|
export function prettyPrintTokenType(token: AtomIOToken): string {
|
|
6
6
|
return token.type.split(`_`).map(capitalize).join(` `)
|