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.
- package/data/dist/index.d.ts +3 -154
- package/data/dist/index.js +11 -559
- 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-3PQTWLQQ.js +83 -0
- package/dist/chunk-3ZFTRSNG.js +523 -0
- package/dist/chunk-4LWKCEW3.js +14 -0
- package/dist/chunk-KVI5OBF2.js +153 -0
- package/dist/{chunk-Y5MBNTVU.js → chunk-UQEYZ3OI.js} +1814 -721
- package/dist/chunk-UYYKOGZQ.js +1034 -0
- package/dist/chunk-VRJP2PCU.js +631 -0
- package/dist/chunk-X7SD2NXU.js +108 -0
- package/dist/index.d.ts +137 -12
- package/dist/index.js +1 -228
- package/eslint-plugin/dist/index.d.ts +1 -30
- package/eslint-plugin/dist/index.js +3 -149
- package/eslint-plugin/src/index.ts +0 -1
- package/eslint-plugin/src/rules/explicit-state-types.ts +1 -0
- package/eslint-plugin/src/rules/index.ts +0 -1
- package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +1 -0
- package/eslint-plugin/src/walk.ts +1 -0
- package/internal/dist/index.d.ts +129 -58
- 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} +21 -430
- package/internal/src/junction.ts +7 -4
- 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 +4 -2
- 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 +19 -38
- package/internal/src/timeline/time-travel.ts +2 -1
- 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.js +2 -620
- package/json/dist/index.d.ts +2 -2
- package/json/dist/index.js +1 -80
- package/json/src/select-json-family.ts +3 -14
- package/package.json +31 -49
- 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.js +31 -18
- package/react-devtools/src/Updates.tsx +12 -0
- package/react-devtools/src/devtools.scss +16 -14
- package/react-devtools/src/json-editor/editors-by-type/utilities/cast-to-json.ts +2 -1
- package/realtime/dist/index.d.ts +1 -2
- package/realtime/dist/index.js +2 -107
- package/realtime/src/realtime-continuity.ts +3 -2
- package/realtime/src/shared-room-store.ts +1 -2
- package/realtime-client/dist/index.d.ts +9 -9
- 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.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 +2 -4
- 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/ipc-sockets/child-socket.ts +2 -0
- 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-sync-store.ts +10 -2
- 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.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 +4 -3
- package/transceivers/set-rtx/dist/index.js +1 -215
- package/transceivers/set-rtx/src/set-rtx.ts +4 -7
- 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/react-devtools/src/json-editor/assets/Untitled-1.ai +2 -1436
- package/react-devtools/src/json-editor/assets/data-vis.ai +1 -1548
- package/react-devtools/src/json-editor/comp/json-editor-sketches.ai +5 -1449
- /package/{ephemeral/src → src}/find-state.ts +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { newest } from "../lineage"
|
|
2
2
|
import type { Store } from "../store"
|
|
3
3
|
|
|
4
|
-
export const isAtomDefault = (
|
|
4
|
+
export const isAtomDefault = (store: Store, key: string): boolean => {
|
|
5
5
|
const core = newest(store)
|
|
6
6
|
return core.atomsThatAreDefault.has(key)
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export const markAtomAsDefault = (
|
|
9
|
+
export const markAtomAsDefault = (store: Store, key: string): void => {
|
|
10
10
|
const core = newest(store)
|
|
11
11
|
core.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key)
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export const markAtomAsNotDefault = (
|
|
14
|
+
export const markAtomAsNotDefault = (store: Store, key: string): void => {
|
|
15
15
|
const core = newest(store)
|
|
16
16
|
core.atomsThatAreDefault = new Set(newest(store).atomsThatAreDefault)
|
|
17
17
|
core.atomsThatAreDefault.delete(key)
|
package/internal/src/caching.ts
CHANGED
|
@@ -8,22 +8,22 @@ import type { Store } from "./store"
|
|
|
8
8
|
import type { Subject } from "./subject"
|
|
9
9
|
|
|
10
10
|
export function cacheValue<T>(
|
|
11
|
+
store: Store,
|
|
11
12
|
key: string,
|
|
12
13
|
value: T,
|
|
13
14
|
subject: Subject<StateUpdate<unknown>>,
|
|
14
|
-
store: Store,
|
|
15
15
|
): T
|
|
16
16
|
export function cacheValue<T extends Promise<any>>(
|
|
17
|
+
store: Store,
|
|
17
18
|
key: string,
|
|
18
19
|
value: T,
|
|
19
20
|
subject: Subject<StateUpdate<unknown>>,
|
|
20
|
-
store: Store,
|
|
21
21
|
): Future<T>
|
|
22
22
|
export function cacheValue<T>(
|
|
23
|
+
target: Store,
|
|
23
24
|
key: string,
|
|
24
25
|
value: T,
|
|
25
26
|
subject: Subject<StateUpdate<unknown>>,
|
|
26
|
-
target: Store,
|
|
27
27
|
): Future<T> | T {
|
|
28
28
|
const currentValue = target.valueMap.get(key)
|
|
29
29
|
if (currentValue instanceof Future) {
|
|
@@ -35,7 +35,7 @@ export function cacheValue<T>(
|
|
|
35
35
|
target.valueMap.set(key, future)
|
|
36
36
|
future
|
|
37
37
|
.then((resolved) => {
|
|
38
|
-
cacheValue(key, resolved, subject
|
|
38
|
+
cacheValue(target, key, resolved, subject)
|
|
39
39
|
subject.next({ newValue: resolved, oldValue: future })
|
|
40
40
|
})
|
|
41
41
|
.catch((thrown) => {
|
|
@@ -54,7 +54,7 @@ export const readCachedValue = <T>(
|
|
|
54
54
|
let value = target.valueMap.get(token.key) as T
|
|
55
55
|
if (token.type === `mutable_atom` && isChildStore(target)) {
|
|
56
56
|
const { parent } = target
|
|
57
|
-
const copiedValue = copyMutableIfNeeded(token, parent
|
|
57
|
+
const copiedValue = copyMutableIfNeeded(target, token, parent)
|
|
58
58
|
value = copiedValue
|
|
59
59
|
}
|
|
60
60
|
return value
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
FamilyMetadata,
|
|
3
|
+
findState,
|
|
3
4
|
getState,
|
|
4
5
|
ReadonlySelectorFamilyOptions,
|
|
5
6
|
ReadonlySelectorFamilyToken,
|
|
@@ -7,8 +8,6 @@ import type {
|
|
|
7
8
|
StateCreation,
|
|
8
9
|
StateDisposal,
|
|
9
10
|
} from "atom.io"
|
|
10
|
-
import type { findState } from "atom.io/ephemeral"
|
|
11
|
-
import type { seekState } from "atom.io/immortal"
|
|
12
11
|
import type { Canonical } from "atom.io/json"
|
|
13
12
|
import { stringifyJson } from "atom.io/json"
|
|
14
13
|
|
|
@@ -18,7 +17,6 @@ import {
|
|
|
18
17
|
getJsonToken,
|
|
19
18
|
prettyPrintTokenType,
|
|
20
19
|
type ReadonlySelectorFamily,
|
|
21
|
-
seekInStore,
|
|
22
20
|
} from ".."
|
|
23
21
|
import { newest } from "../lineage"
|
|
24
22
|
import { createReadonlySelector } from "../selector"
|
|
@@ -78,9 +76,10 @@ export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
|
78
76
|
default: (key: K) => {
|
|
79
77
|
const getFn = options.get(key)
|
|
80
78
|
return getFn({
|
|
81
|
-
get: ((...
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
get: ((...args: Parameters<typeof getState>) =>
|
|
80
|
+
getFromStore(store, ...args)) as typeof getState,
|
|
81
|
+
find: ((...args: Parameters<typeof findState>) =>
|
|
82
|
+
findInStore(store, ...args)) as typeof findState,
|
|
84
83
|
json: (token) => getJsonToken(store, token),
|
|
85
84
|
})
|
|
86
85
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
FamilyMetadata,
|
|
3
|
+
findState,
|
|
3
4
|
getState,
|
|
4
5
|
StateCreation,
|
|
5
6
|
StateDisposal,
|
|
@@ -7,8 +8,6 @@ import type {
|
|
|
7
8
|
WritableSelectorFamilyToken,
|
|
8
9
|
WritableSelectorToken,
|
|
9
10
|
} from "atom.io"
|
|
10
|
-
import type { findState } from "atom.io/ephemeral"
|
|
11
|
-
import type { seekState } from "atom.io/immortal"
|
|
12
11
|
import type { Canonical } from "atom.io/json"
|
|
13
12
|
import { stringifyJson } from "atom.io/json"
|
|
14
13
|
|
|
@@ -17,7 +16,6 @@ import {
|
|
|
17
16
|
getFromStore,
|
|
18
17
|
getJsonToken,
|
|
19
18
|
prettyPrintTokenType,
|
|
20
|
-
seekInStore,
|
|
21
19
|
type WritableSelectorFamily,
|
|
22
20
|
} from ".."
|
|
23
21
|
import { newest } from "../lineage"
|
|
@@ -80,7 +78,6 @@ export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
|
80
78
|
return getFn({
|
|
81
79
|
get: ((...ps: [any]) => getFromStore(store, ...ps)) as typeof getState,
|
|
82
80
|
find: ((token, k) => findInStore(store, token, k)) as typeof findState,
|
|
83
|
-
seek: ((token, k) => seekInStore(store, token, k)) as typeof seekState,
|
|
84
81
|
json: (token) => getJsonToken(store, token),
|
|
85
82
|
})
|
|
86
83
|
},
|
|
@@ -2,7 +2,6 @@ import type { ReadableFamilyToken, ReadableToken } from "atom.io"
|
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import { disposeAtom } from "../atom"
|
|
5
|
-
import { getTrace } from "../get-trace"
|
|
6
5
|
import { disposeSelector } from "../selector"
|
|
7
6
|
import { type Store, withdraw } from "../store"
|
|
8
7
|
import { findInStore } from "./find-in-store"
|
|
@@ -31,33 +30,24 @@ export function disposeFromStore(
|
|
|
31
30
|
token = maybeToken
|
|
32
31
|
}
|
|
33
32
|
try {
|
|
34
|
-
withdraw(
|
|
33
|
+
withdraw(store, token)
|
|
35
34
|
} catch (thrown) {
|
|
36
|
-
// const disposal = store.disposalTraces.buffer.find(
|
|
37
|
-
// (item) => item?.key === token.key,
|
|
38
|
-
// )
|
|
39
35
|
store.logger.error(
|
|
40
36
|
`❌`,
|
|
41
37
|
token.type,
|
|
42
38
|
token.key,
|
|
43
39
|
`could not be disposed because it was not found in the store "${store.config.name}".`,
|
|
44
|
-
// disposal
|
|
45
|
-
// ? `\n This state was most recently disposed\n${disposal.trace}`
|
|
46
|
-
// : `No previous disposal trace was found.`,
|
|
47
40
|
)
|
|
48
41
|
return
|
|
49
42
|
}
|
|
50
43
|
switch (token.type) {
|
|
51
44
|
case `atom`:
|
|
52
45
|
case `mutable_atom`:
|
|
53
|
-
disposeAtom(
|
|
46
|
+
disposeAtom(store, token)
|
|
54
47
|
break
|
|
55
48
|
case `selector`:
|
|
56
49
|
case `readonly_selector`:
|
|
57
|
-
disposeSelector(
|
|
50
|
+
disposeSelector(store, token)
|
|
58
51
|
break
|
|
59
52
|
}
|
|
60
|
-
|
|
61
|
-
// const trace = getTrace(new Error())
|
|
62
|
-
// store.disposalTraces.add({ key: token.key, trace })
|
|
63
53
|
}
|
|
@@ -55,12 +55,12 @@ export function getFromStore(
|
|
|
55
55
|
if (store.defaults.has(family.key)) {
|
|
56
56
|
return store.defaults.get(token.family.key)
|
|
57
57
|
}
|
|
58
|
-
const defaultValue = withdraw(
|
|
58
|
+
const defaultValue = withdraw(store, family).default(subKey)
|
|
59
59
|
store.defaults.set(family.key, defaultValue)
|
|
60
60
|
return defaultValue
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
return readOrComputeValue(withdraw(
|
|
65
|
+
return readOrComputeValue(store, withdraw(store, token))
|
|
66
66
|
}
|
|
@@ -3,8 +3,8 @@ import { readCachedValue } from "../caching"
|
|
|
3
3
|
import type { Store } from "../store"
|
|
4
4
|
|
|
5
5
|
export const readOrComputeValue = <T>(
|
|
6
|
-
state: ReadableState<T>,
|
|
7
6
|
target: Store,
|
|
7
|
+
state: ReadableState<T>,
|
|
8
8
|
): T => {
|
|
9
9
|
if (target.valueMap.has(state.key)) {
|
|
10
10
|
target.logger.info(`📖`, state.type, state.key, `reading cached value`)
|
package/internal/src/index.ts
CHANGED
|
@@ -23,12 +23,14 @@ import type { Transaction } from "./transaction"
|
|
|
23
23
|
export * from "./arbitrary"
|
|
24
24
|
export * from "./atom"
|
|
25
25
|
export * from "./caching"
|
|
26
|
+
export * from "./capitalize"
|
|
26
27
|
export * from "./families"
|
|
27
28
|
export * from "./future"
|
|
28
29
|
export * from "./get-environment-data"
|
|
29
30
|
export * from "./get-state"
|
|
30
31
|
export * from "./get-trace"
|
|
31
32
|
export * from "./ingest-updates"
|
|
33
|
+
export * from "./join"
|
|
32
34
|
export * from "./junction"
|
|
33
35
|
export * from "./keys"
|
|
34
36
|
export * from "./lazy-map"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { JoinToken } from "atom.io"
|
|
2
|
+
import type { Json } from "atom.io/json"
|
|
3
|
+
|
|
4
|
+
import type { Junction } from "../junction"
|
|
5
|
+
import { newest } from "../lineage"
|
|
6
|
+
import type { Store } from "../store"
|
|
7
|
+
import { isChildStore } from "../transaction"
|
|
8
|
+
import { getJoin } from "./get-join"
|
|
9
|
+
|
|
10
|
+
export function editRelationsInStore<
|
|
11
|
+
ASide extends string,
|
|
12
|
+
AType extends string,
|
|
13
|
+
BSide extends string,
|
|
14
|
+
BType extends string,
|
|
15
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
16
|
+
Content extends Json.Object | null,
|
|
17
|
+
>(
|
|
18
|
+
token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
19
|
+
change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void,
|
|
20
|
+
store: Store,
|
|
21
|
+
): void {
|
|
22
|
+
const myJoin = getJoin(token, store)
|
|
23
|
+
const target = newest(store)
|
|
24
|
+
if (isChildStore(target)) {
|
|
25
|
+
const { toolkit } = target.transactionMeta
|
|
26
|
+
myJoin.transact(toolkit, ({ relations }) => {
|
|
27
|
+
change(relations)
|
|
28
|
+
})
|
|
29
|
+
} else {
|
|
30
|
+
change(myJoin.relations)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { JoinStates, JoinToken } from "atom.io"
|
|
2
|
+
import type { Json } from "atom.io/json"
|
|
3
|
+
|
|
4
|
+
import { capitalize } from "../capitalize"
|
|
5
|
+
import { findInStore } from "../families"
|
|
6
|
+
import type { Store } from "../store"
|
|
7
|
+
import { getJoin } from "./get-join"
|
|
8
|
+
|
|
9
|
+
export function findRelationsInStore<
|
|
10
|
+
ASide extends string,
|
|
11
|
+
AType extends string,
|
|
12
|
+
BSide extends string,
|
|
13
|
+
BType extends string,
|
|
14
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
15
|
+
Content extends Json.Object | null,
|
|
16
|
+
>(
|
|
17
|
+
token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
18
|
+
key: AType | BType,
|
|
19
|
+
store: Store,
|
|
20
|
+
): JoinStates<ASide, AType, BSide, BType, Cardinality, Content> {
|
|
21
|
+
const myJoin = getJoin(token, store)
|
|
22
|
+
let relations: JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
|
|
23
|
+
switch (token.cardinality satisfies `1:1` | `1:n` | `n:n`) {
|
|
24
|
+
case `1:1`: {
|
|
25
|
+
const keyAB = `${token.a}KeyOf${capitalize(token.b)}`
|
|
26
|
+
const keyBA = `${token.b}KeyOf${capitalize(token.a)}`
|
|
27
|
+
relations = {
|
|
28
|
+
get [keyAB]() {
|
|
29
|
+
const familyAB = myJoin.states[keyAB as any]
|
|
30
|
+
const state = findInStore(store, familyAB, key)
|
|
31
|
+
return state
|
|
32
|
+
},
|
|
33
|
+
get [keyBA]() {
|
|
34
|
+
const familyBA = myJoin.states[keyBA as any]
|
|
35
|
+
const state = findInStore(store, familyBA, key)
|
|
36
|
+
return state
|
|
37
|
+
},
|
|
38
|
+
} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
|
|
39
|
+
const entryAB = `${token.a}EntryOf${capitalize(token.b)}`
|
|
40
|
+
if (entryAB in myJoin.states) {
|
|
41
|
+
const entryBA = `${token.b}EntryOf${capitalize(token.a)}`
|
|
42
|
+
Object.assign(relations, {
|
|
43
|
+
get [entryAB]() {
|
|
44
|
+
const familyAB = myJoin.states[entryAB as any]
|
|
45
|
+
const state = findInStore(store, familyAB, key)
|
|
46
|
+
return state
|
|
47
|
+
},
|
|
48
|
+
get [entryBA]() {
|
|
49
|
+
const familyBA = myJoin.states[entryBA as any]
|
|
50
|
+
const state = findInStore(store, familyBA, key)
|
|
51
|
+
return state
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
break
|
|
56
|
+
}
|
|
57
|
+
case `1:n`: {
|
|
58
|
+
const keyAB = `${token.a}KeyOf${capitalize(token.b)}`
|
|
59
|
+
const keysBA = `${token.b}KeysOf${capitalize(token.a)}`
|
|
60
|
+
relations = {
|
|
61
|
+
get [keyAB]() {
|
|
62
|
+
const familyAB = myJoin.states[keyAB as any]
|
|
63
|
+
const state = findInStore(store, familyAB, key)
|
|
64
|
+
return state
|
|
65
|
+
},
|
|
66
|
+
get [keysBA]() {
|
|
67
|
+
const familyBA = myJoin.states[keysBA as any]
|
|
68
|
+
const state = findInStore(store, familyBA, key)
|
|
69
|
+
return state
|
|
70
|
+
},
|
|
71
|
+
} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
|
|
72
|
+
const entryAB = `${token.a}EntryOf${capitalize(token.b)}`
|
|
73
|
+
if (entryAB in myJoin.states) {
|
|
74
|
+
const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`
|
|
75
|
+
Object.assign(relations, {
|
|
76
|
+
get [entryAB]() {
|
|
77
|
+
const familyAB = myJoin.states[entryAB as any]
|
|
78
|
+
const state = findInStore(store, familyAB, key)
|
|
79
|
+
return state
|
|
80
|
+
},
|
|
81
|
+
get [entriesBA]() {
|
|
82
|
+
const familyBA = myJoin.states[entriesBA as any]
|
|
83
|
+
const state = findInStore(store, familyBA, key)
|
|
84
|
+
return state
|
|
85
|
+
},
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
break
|
|
89
|
+
}
|
|
90
|
+
case `n:n`: {
|
|
91
|
+
const keysAB = `${token.a}KeysOf${capitalize(token.b)}`
|
|
92
|
+
const keysBA = `${token.b}KeysOf${capitalize(token.a)}`
|
|
93
|
+
relations = {
|
|
94
|
+
get [keysAB]() {
|
|
95
|
+
const familyAB = myJoin.states[keysAB as any]
|
|
96
|
+
const state = findInStore(store, familyAB, key)
|
|
97
|
+
return state
|
|
98
|
+
},
|
|
99
|
+
get [keysBA]() {
|
|
100
|
+
const familyBA = myJoin.states[keysBA as any]
|
|
101
|
+
const state = findInStore(store, familyBA, key)
|
|
102
|
+
return state
|
|
103
|
+
},
|
|
104
|
+
} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
|
|
105
|
+
const entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`
|
|
106
|
+
if (entriesAB in myJoin.states) {
|
|
107
|
+
const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`
|
|
108
|
+
Object.assign(relations, {
|
|
109
|
+
get [entriesAB]() {
|
|
110
|
+
const familyAB = myJoin.states[entriesAB as any]
|
|
111
|
+
const state = findInStore(store, familyAB, key)
|
|
112
|
+
return state
|
|
113
|
+
},
|
|
114
|
+
get [entriesBA]() {
|
|
115
|
+
const familyBA = myJoin.states[entriesBA as any]
|
|
116
|
+
const state = findInStore(store, familyBA, key)
|
|
117
|
+
return state
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return relations
|
|
124
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { JoinToken, MutableAtomFamilyToken } from "atom.io"
|
|
2
|
+
import type { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
3
|
+
|
|
4
|
+
import type { Store } from "../store"
|
|
5
|
+
import { getJoin } from "./get-join"
|
|
6
|
+
|
|
7
|
+
export function getInternalRelationsFromStore(
|
|
8
|
+
token: JoinToken<any, any, any, any, any, any>,
|
|
9
|
+
store: Store,
|
|
10
|
+
): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
|
|
11
|
+
const myJoin = getJoin(token, store)
|
|
12
|
+
const family = myJoin.core.relatedKeysAtoms
|
|
13
|
+
return family
|
|
14
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { JoinToken } from "atom.io"
|
|
2
|
+
import type { Json } from "atom.io/json"
|
|
3
|
+
|
|
4
|
+
import { IMPLICIT, type Store } from "../store"
|
|
5
|
+
import { Join } from "./join-internal"
|
|
6
|
+
|
|
7
|
+
export function getJoin<
|
|
8
|
+
ASide extends string,
|
|
9
|
+
AType extends string,
|
|
10
|
+
BSide extends string,
|
|
11
|
+
BType extends string,
|
|
12
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
13
|
+
Content extends Json.Object | null,
|
|
14
|
+
>(
|
|
15
|
+
token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
16
|
+
store: Store,
|
|
17
|
+
): Join<ASide, AType, BSide, BType, Cardinality, Content> {
|
|
18
|
+
let myJoin = store.joins.get(token.key)
|
|
19
|
+
if (myJoin === undefined) {
|
|
20
|
+
const rootJoinMap = IMPLICIT.STORE.joins
|
|
21
|
+
const rootJoin = rootJoinMap.get(token.key)
|
|
22
|
+
if (rootJoin === undefined) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Join "${token.key}" not found in store "${store.config.name}"`,
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
myJoin = new Join(rootJoin.options, rootJoin.defaultContent, store)
|
|
28
|
+
store.joins.set(token.key, myJoin)
|
|
29
|
+
}
|
|
30
|
+
return myJoin
|
|
31
|
+
}
|