atom.io 0.27.3 → 0.27.5
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.js +57 -72
- package/data/src/dict.ts +9 -12
- package/data/src/join.ts +25 -26
- package/data/src/struct-family.ts +17 -23
- package/data/src/struct.ts +9 -12
- package/dist/{chunk-ETCFHO7J.js → chunk-6ABWLAGY.js} +246 -159
- package/dist/index.d.ts +4 -4
- package/dist/index.js +33 -53
- package/ephemeral/dist/index.js +1 -1
- package/ephemeral/src/find-state.ts +1 -1
- package/immortal/dist/index.js +2 -2
- package/immortal/src/seek-state.ts +2 -2
- package/internal/dist/index.d.ts +88 -73
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/create-regular-atom.ts +3 -3
- package/internal/src/atom/create-standalone-atom.ts +7 -5
- package/internal/src/families/create-atom-family.ts +5 -5
- package/internal/src/families/create-readonly-selector-family.ts +35 -7
- package/internal/src/families/create-regular-atom-family.ts +16 -6
- package/internal/src/families/create-selector-family.ts +5 -5
- package/internal/src/families/create-writable-selector-family.ts +35 -8
- package/internal/src/families/dispose-from-store.ts +22 -16
- package/internal/src/families/find-in-store.ts +11 -11
- package/internal/src/families/init-family-member.ts +9 -9
- package/internal/src/families/seek-in-store.ts +10 -13
- package/internal/src/get-state/get-from-store.ts +58 -20
- package/internal/src/get-state/read-or-compute-value.ts +1 -1
- package/internal/src/index.ts +5 -3
- package/internal/src/ingest-updates/ingest-atom-update.ts +1 -1
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +5 -5
- package/internal/src/molecule/create-molecule-family.ts +1 -1
- package/internal/src/molecule/dispose-molecule.ts +1 -1
- package/internal/src/molecule/grow-molecule-in-store.ts +1 -1
- package/internal/src/molecule/make-molecule-in-store.ts +5 -5
- package/internal/src/mutable/create-mutable-atom-family.ts +15 -6
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-token.ts +2 -2
- package/internal/src/mutable/tracker-family.ts +3 -3
- package/internal/src/mutable/tracker.ts +14 -18
- package/internal/src/selector/create-readonly-selector.ts +2 -2
- package/internal/src/selector/create-standalone-selector.ts +5 -5
- package/internal/src/selector/create-writable-selector.ts +8 -8
- package/internal/src/selector/register-selector.ts +9 -9
- package/internal/src/set-state/set-into-store.ts +21 -18
- package/internal/src/store/deposit.ts +62 -21
- package/internal/src/store/store.ts +2 -1
- package/internal/src/subscribe/index.ts +2 -0
- package/internal/src/subscribe/subscribe-in-store.ts +62 -0
- package/internal/src/timeline/time-travel.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +7 -6
- package/introspection/dist/index.js +66 -87
- package/introspection/src/attach-atom-index.ts +5 -8
- package/introspection/src/attach-selector-index.ts +6 -8
- package/introspection/src/attach-timeline-family.ts +25 -28
- package/introspection/src/attach-timeline-index.ts +5 -8
- package/introspection/src/attach-transaction-index.ts +5 -8
- package/introspection/src/attach-transaction-logs.ts +21 -27
- package/json/dist/index.js +12 -15
- package/json/src/select-json-family.ts +4 -4
- package/json/src/select-json.ts +6 -9
- package/package.json +4 -4
- package/react/dist/index.js +7 -7
- package/react/src/parse-state-overloads.ts +2 -2
- package/react/src/use-i.ts +1 -1
- package/react/src/use-json.ts +2 -2
- package/react/src/use-o.ts +2 -2
- package/realtime-client/dist/index.js +35 -55
- package/realtime-client/src/pull-atom-family-member.ts +1 -1
- package/realtime-client/src/pull-atom.ts +1 -1
- package/realtime-client/src/pull-mutable-atom-family-member.ts +3 -3
- package/realtime-client/src/pull-mutable-atom.ts +3 -3
- package/realtime-client/src/sync-continuity.ts +27 -47
- package/realtime-react/dist/index.js +3 -3
- package/realtime-react/src/use-pull-atom-family-member.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-server/dist/index.js +32 -32
- package/realtime-server/src/realtime-continuity-synchronizer.ts +16 -16
- package/realtime-server/src/realtime-family-provider.ts +3 -3
- package/realtime-server/src/realtime-mutable-family-provider.ts +5 -5
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-state-provider.ts +1 -1
- package/realtime-server/src/realtime-state-receiver.ts +1 -1
- package/realtime-testing/dist/index.js +7 -7
- package/realtime-testing/src/setup-realtime-test.tsx +7 -7
- package/src/atom.ts +2 -2
- package/src/dispose-state.ts +2 -2
- package/src/get-state.ts +9 -13
- package/src/logger.ts +4 -0
- package/src/molecule.ts +1 -1
- package/src/selector.ts +2 -2
- package/src/set-state.ts +10 -7
- package/src/silo.ts +23 -53
- package/src/subscribe.ts +3 -23
- package/src/timeline.ts +2 -2
- package/internal/src/families/throw-in-case-of-conflicting-family.ts +0 -18
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
FamilyMetadata,
|
|
3
|
+
getState,
|
|
3
4
|
ReadonlySelectorFamilyOptions,
|
|
4
5
|
ReadonlySelectorFamilyToken,
|
|
5
6
|
ReadonlySelectorToken,
|
|
6
7
|
StateCreation,
|
|
7
8
|
StateDisposal,
|
|
8
9
|
} from "atom.io"
|
|
10
|
+
import type { findState } from "atom.io/ephemeral"
|
|
11
|
+
import type { seekState } from "atom.io/immortal"
|
|
9
12
|
import type { Canonical } from "atom.io/json"
|
|
10
13
|
import { stringifyJson } from "atom.io/json"
|
|
11
14
|
|
|
12
|
-
import
|
|
15
|
+
import {
|
|
16
|
+
findInStore,
|
|
17
|
+
getFromStore,
|
|
18
|
+
getJsonToken,
|
|
19
|
+
prettyPrintTokenType,
|
|
20
|
+
type ReadonlySelectorFamily,
|
|
21
|
+
seekInStore,
|
|
22
|
+
} from ".."
|
|
13
23
|
import { newest } from "../lineage"
|
|
14
24
|
import { createReadonlySelector } from "../selector"
|
|
15
25
|
import type { Store } from "../store"
|
|
16
26
|
import { Subject } from "../subject"
|
|
17
|
-
import { throwInCaseOfConflictingFamily } from "./throw-in-case-of-conflicting-family"
|
|
18
27
|
|
|
19
28
|
export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
20
|
-
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
21
29
|
store: Store,
|
|
30
|
+
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
22
31
|
internalRoles?: string[],
|
|
23
32
|
): ReadonlySelectorFamilyToken<T, K> {
|
|
24
33
|
const familyToken = {
|
|
@@ -26,7 +35,17 @@ export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
|
26
35
|
type: `readonly_selector_family`,
|
|
27
36
|
} as const satisfies ReadonlySelectorFamilyToken<T, K>
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
const existing = store.families.get(options.key)
|
|
39
|
+
if (existing) {
|
|
40
|
+
store.logger.error(
|
|
41
|
+
`❗`,
|
|
42
|
+
`readonly_selector_family`,
|
|
43
|
+
options.key,
|
|
44
|
+
`Overwriting an existing ${prettyPrintTokenType(
|
|
45
|
+
existing,
|
|
46
|
+
)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
30
49
|
|
|
31
50
|
const subject = new Subject<
|
|
32
51
|
| StateCreation<ReadonlySelectorToken<T>>
|
|
@@ -40,12 +59,12 @@ export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
|
40
59
|
const target = newest(store)
|
|
41
60
|
|
|
42
61
|
const token = createReadonlySelector(
|
|
62
|
+
target,
|
|
43
63
|
{
|
|
44
64
|
key: fullKey,
|
|
45
65
|
get: options.get(key),
|
|
46
66
|
},
|
|
47
67
|
family,
|
|
48
|
-
target,
|
|
49
68
|
)
|
|
50
69
|
|
|
51
70
|
subject.next({ type: `state_creation`, token })
|
|
@@ -53,9 +72,18 @@ export function createReadonlySelectorFamily<T, K extends Canonical>(
|
|
|
53
72
|
}
|
|
54
73
|
|
|
55
74
|
const readonlySelectorFamily = Object.assign(familyFunction, familyToken, {
|
|
56
|
-
subject,
|
|
57
|
-
install: (s: Store) => createReadonlySelectorFamily(options, s),
|
|
58
75
|
internalRoles,
|
|
76
|
+
subject,
|
|
77
|
+
install: (s: Store) => createReadonlySelectorFamily(s, options),
|
|
78
|
+
default: (key: K) => {
|
|
79
|
+
const getFn = options.get(key)
|
|
80
|
+
return getFn({
|
|
81
|
+
get: ((...ps: [any]) => getFromStore(store, ...ps)) as typeof getState,
|
|
82
|
+
find: ((token, k) => findInStore(store, token, k)) as typeof findState,
|
|
83
|
+
seek: ((token, k) => seekInStore(store, token, k)) as typeof seekState,
|
|
84
|
+
json: (token) => getJsonToken(store, token),
|
|
85
|
+
})
|
|
86
|
+
},
|
|
59
87
|
}) satisfies ReadonlySelectorFamily<T, K>
|
|
60
88
|
|
|
61
89
|
store.families.set(options.key, readonlySelectorFamily)
|
|
@@ -10,16 +10,15 @@ import type {
|
|
|
10
10
|
import type { Canonical } from "atom.io/json"
|
|
11
11
|
import { stringifyJson } from "atom.io/json"
|
|
12
12
|
|
|
13
|
-
import type
|
|
13
|
+
import { prettyPrintTokenType, type RegularAtomFamily } from ".."
|
|
14
14
|
import { createRegularAtom } from "../atom"
|
|
15
15
|
import { newest } from "../lineage"
|
|
16
16
|
import type { Store } from "../store"
|
|
17
17
|
import { Subject } from "../subject"
|
|
18
|
-
import { throwInCaseOfConflictingFamily } from "./throw-in-case-of-conflicting-family"
|
|
19
18
|
|
|
20
19
|
export function createRegularAtomFamily<T, K extends Canonical>(
|
|
21
|
-
options: RegularAtomFamilyOptions<T, K>,
|
|
22
20
|
store: Store,
|
|
21
|
+
options: RegularAtomFamilyOptions<T, K>,
|
|
23
22
|
internalRoles?: string[],
|
|
24
23
|
): RegularAtomFamilyToken<T, K> {
|
|
25
24
|
const familyToken = {
|
|
@@ -27,7 +26,17 @@ export function createRegularAtomFamily<T, K extends Canonical>(
|
|
|
27
26
|
type: `atom_family`,
|
|
28
27
|
} as const satisfies RegularAtomFamilyToken<T, K>
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
const existing = store.families.get(options.key)
|
|
30
|
+
if (existing) {
|
|
31
|
+
store.logger.error(
|
|
32
|
+
`❗`,
|
|
33
|
+
`atom_family`,
|
|
34
|
+
options.key,
|
|
35
|
+
`Overwriting an existing ${prettyPrintTokenType(
|
|
36
|
+
existing,
|
|
37
|
+
)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`,
|
|
38
|
+
)
|
|
39
|
+
}
|
|
31
40
|
|
|
32
41
|
const subject = new Subject<
|
|
33
42
|
StateCreation<RegularAtomToken<T>> | StateDisposal<RegularAtomToken<T>>
|
|
@@ -48,7 +57,7 @@ export function createRegularAtomFamily<T, K extends Canonical>(
|
|
|
48
57
|
individualOptions.effects = options.effects(key)
|
|
49
58
|
}
|
|
50
59
|
|
|
51
|
-
const token = createRegularAtom(individualOptions, family
|
|
60
|
+
const token = createRegularAtom(target, individualOptions, family)
|
|
52
61
|
|
|
53
62
|
subject.next({ type: `state_creation`, token })
|
|
54
63
|
return token
|
|
@@ -56,10 +65,11 @@ export function createRegularAtomFamily<T, K extends Canonical>(
|
|
|
56
65
|
|
|
57
66
|
const atomFamily = Object.assign(familyFunction, familyToken, {
|
|
58
67
|
subject,
|
|
59
|
-
install: (s: Store) => createRegularAtomFamily(
|
|
68
|
+
install: (s: Store) => createRegularAtomFamily(s, options),
|
|
60
69
|
internalRoles,
|
|
61
70
|
}) satisfies RegularAtomFamily<T, K>
|
|
62
71
|
|
|
63
72
|
store.families.set(options.key, atomFamily)
|
|
73
|
+
store.defaults.set(options.key, options.default)
|
|
64
74
|
return familyToken
|
|
65
75
|
}
|
|
@@ -12,23 +12,23 @@ import { createReadonlySelectorFamily } from "./create-readonly-selector-family"
|
|
|
12
12
|
import { createWritableSelectorFamily } from "./create-writable-selector-family"
|
|
13
13
|
|
|
14
14
|
export function createSelectorFamily<T, K extends Canonical>(
|
|
15
|
-
options: WritableSelectorFamilyOptions<T, K>,
|
|
16
15
|
store: Store,
|
|
16
|
+
options: WritableSelectorFamilyOptions<T, K>,
|
|
17
17
|
): WritableSelectorFamilyToken<T, K>
|
|
18
18
|
export function createSelectorFamily<T, K extends Canonical>(
|
|
19
|
-
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
20
19
|
store: Store,
|
|
20
|
+
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
21
21
|
): ReadonlySelectorFamilyToken<T, K>
|
|
22
22
|
export function createSelectorFamily<T, K extends Canonical>(
|
|
23
|
+
store: Store,
|
|
23
24
|
options:
|
|
24
25
|
| ReadonlySelectorFamilyOptions<T, K>
|
|
25
26
|
| WritableSelectorFamilyOptions<T, K>,
|
|
26
|
-
store: Store,
|
|
27
27
|
): SelectorFamilyToken<T, K> {
|
|
28
28
|
const isWritable = `set` in options
|
|
29
29
|
|
|
30
30
|
if (isWritable) {
|
|
31
|
-
return createWritableSelectorFamily(
|
|
31
|
+
return createWritableSelectorFamily(store, options)
|
|
32
32
|
}
|
|
33
|
-
return createReadonlySelectorFamily(
|
|
33
|
+
return createReadonlySelectorFamily(store, options)
|
|
34
34
|
}
|
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
FamilyMetadata,
|
|
3
|
+
getState,
|
|
3
4
|
StateCreation,
|
|
4
5
|
StateDisposal,
|
|
5
6
|
WritableSelectorFamilyOptions,
|
|
6
7
|
WritableSelectorFamilyToken,
|
|
7
8
|
WritableSelectorToken,
|
|
8
9
|
} from "atom.io"
|
|
10
|
+
import type { findState } from "atom.io/ephemeral"
|
|
11
|
+
import type { seekState } from "atom.io/immortal"
|
|
9
12
|
import type { Canonical } from "atom.io/json"
|
|
10
13
|
import { stringifyJson } from "atom.io/json"
|
|
11
14
|
|
|
12
|
-
import
|
|
15
|
+
import {
|
|
16
|
+
findInStore,
|
|
17
|
+
getFromStore,
|
|
18
|
+
getJsonToken,
|
|
19
|
+
prettyPrintTokenType,
|
|
20
|
+
seekInStore,
|
|
21
|
+
type WritableSelectorFamily,
|
|
22
|
+
} from ".."
|
|
13
23
|
import { newest } from "../lineage"
|
|
14
24
|
import { createWritableSelector } from "../selector"
|
|
15
25
|
import type { Store } from "../store"
|
|
16
26
|
import { Subject } from "../subject"
|
|
17
|
-
import { throwInCaseOfConflictingFamily } from "./throw-in-case-of-conflicting-family"
|
|
18
27
|
|
|
19
28
|
export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
20
|
-
options: WritableSelectorFamilyOptions<T, K>,
|
|
21
29
|
store: Store,
|
|
30
|
+
options: WritableSelectorFamilyOptions<T, K>,
|
|
22
31
|
internalRoles?: string[],
|
|
23
32
|
): WritableSelectorFamilyToken<T, K> {
|
|
24
33
|
const familyToken = {
|
|
@@ -26,8 +35,17 @@ export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
|
26
35
|
type: `selector_family`,
|
|
27
36
|
} as const satisfies WritableSelectorFamilyToken<T, K>
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
const existing = store.families.get(options.key)
|
|
39
|
+
if (existing) {
|
|
40
|
+
store.logger.error(
|
|
41
|
+
`❗`,
|
|
42
|
+
`selector_family`,
|
|
43
|
+
options.key,
|
|
44
|
+
`Overwriting an existing ${prettyPrintTokenType(
|
|
45
|
+
existing,
|
|
46
|
+
)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
31
49
|
const subject = new Subject<
|
|
32
50
|
| StateCreation<WritableSelectorToken<T>>
|
|
33
51
|
| StateDisposal<WritableSelectorToken<T>>
|
|
@@ -40,13 +58,13 @@ export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
|
40
58
|
const target = newest(store)
|
|
41
59
|
|
|
42
60
|
const token = createWritableSelector(
|
|
61
|
+
target,
|
|
43
62
|
{
|
|
44
63
|
key: fullKey,
|
|
45
64
|
get: options.get(key),
|
|
46
65
|
set: options.set(key),
|
|
47
66
|
},
|
|
48
67
|
family,
|
|
49
|
-
target,
|
|
50
68
|
)
|
|
51
69
|
|
|
52
70
|
subject.next({ type: `state_creation`, token })
|
|
@@ -54,9 +72,18 @@ export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
|
54
72
|
}
|
|
55
73
|
|
|
56
74
|
const selectorFamily = Object.assign(familyFunction, familyToken, {
|
|
57
|
-
subject,
|
|
58
|
-
install: (s: Store) => createWritableSelectorFamily(options, s),
|
|
59
75
|
internalRoles,
|
|
76
|
+
subject,
|
|
77
|
+
install: (s: Store) => createWritableSelectorFamily(s, options),
|
|
78
|
+
default: (key: K) => {
|
|
79
|
+
const getFn = options.get(key)
|
|
80
|
+
return getFn({
|
|
81
|
+
get: ((...ps: [any]) => getFromStore(store, ...ps)) as typeof getState,
|
|
82
|
+
find: ((token, k) => findInStore(store, token, k)) as typeof findState,
|
|
83
|
+
seek: ((token, k) => seekInStore(store, token, k)) as typeof seekState,
|
|
84
|
+
json: (token) => getJsonToken(store, token),
|
|
85
|
+
})
|
|
86
|
+
},
|
|
60
87
|
}) satisfies WritableSelectorFamily<T, K>
|
|
61
88
|
|
|
62
89
|
store.families.set(options.key, selectorFamily)
|
|
@@ -6,56 +6,62 @@ import type {
|
|
|
6
6
|
ReadableFamilyToken,
|
|
7
7
|
ReadableToken,
|
|
8
8
|
} from "atom.io"
|
|
9
|
-
import type
|
|
9
|
+
import { type Canonical, stringifyJson } from "atom.io/json"
|
|
10
10
|
|
|
11
11
|
import { disposeAtom } from "../atom"
|
|
12
12
|
import { disposeMolecule } from "../molecule/dispose-molecule"
|
|
13
|
-
import { NotFoundError } from "../not-found-error"
|
|
14
13
|
import { disposeSelector } from "../selector"
|
|
15
14
|
import type { Store } from "../store"
|
|
16
15
|
import { findInStore } from "./find-in-store"
|
|
17
16
|
import { seekInStore } from "./seek-in-store"
|
|
18
17
|
|
|
19
18
|
export function disposeFromStore(
|
|
20
|
-
token: MoleculeToken<any> | ReadableToken<any>,
|
|
21
19
|
store: Store,
|
|
20
|
+
token: MoleculeToken<any> | ReadableToken<any>,
|
|
22
21
|
): void
|
|
23
22
|
|
|
24
23
|
export function disposeFromStore<K extends Canonical>(
|
|
24
|
+
store: Store,
|
|
25
25
|
token: ReadableFamilyToken<any, K>,
|
|
26
26
|
key: K,
|
|
27
|
-
store: Store,
|
|
28
27
|
): void
|
|
29
28
|
|
|
30
29
|
export function disposeFromStore<M extends MoleculeConstructor>(
|
|
30
|
+
store: Store,
|
|
31
31
|
token: MoleculeFamilyToken<M>,
|
|
32
32
|
key: MoleculeKey<M>,
|
|
33
|
-
store: Store,
|
|
34
33
|
): void
|
|
35
34
|
|
|
36
35
|
export function disposeFromStore(
|
|
36
|
+
store: Store,
|
|
37
37
|
...params:
|
|
38
|
-
| [token: MoleculeFamilyToken<any>, key: MoleculeKey<any
|
|
39
|
-
| [token: MoleculeToken<any> | ReadableToken<any
|
|
40
|
-
| [token: ReadableFamilyToken<any, any>, key: Canonical
|
|
38
|
+
| [token: MoleculeFamilyToken<any>, key: MoleculeKey<any>]
|
|
39
|
+
| [token: MoleculeToken<any> | ReadableToken<any>]
|
|
40
|
+
| [token: ReadableFamilyToken<any, any>, key: Canonical]
|
|
41
41
|
): void {
|
|
42
42
|
let token: MoleculeToken<any> | ReadableToken<any>
|
|
43
|
-
|
|
44
|
-
if (params.length === 2) {
|
|
43
|
+
if (params.length === 1) {
|
|
45
44
|
token = params[0]
|
|
46
|
-
store = params[1]
|
|
47
45
|
} else {
|
|
48
46
|
const family = params[0]
|
|
49
47
|
const key = params[1]
|
|
50
|
-
store = params[2]
|
|
51
48
|
const maybeToken =
|
|
52
49
|
family.type === `molecule_family`
|
|
53
|
-
? seekInStore(family, key
|
|
50
|
+
? seekInStore(store, family, key)
|
|
54
51
|
: store.config.lifespan === `immortal`
|
|
55
|
-
? seekInStore(family, key
|
|
56
|
-
: findInStore(family, key
|
|
52
|
+
? seekInStore(store, family, key)
|
|
53
|
+
: findInStore(store, family, key)
|
|
57
54
|
if (!maybeToken) {
|
|
58
|
-
|
|
55
|
+
store.logger.error(
|
|
56
|
+
`❗`,
|
|
57
|
+
family.type,
|
|
58
|
+
family.key,
|
|
59
|
+
`tried to dispose of member`,
|
|
60
|
+
stringifyJson(key),
|
|
61
|
+
`but it was not found in store`,
|
|
62
|
+
store.config.name,
|
|
63
|
+
)
|
|
64
|
+
return
|
|
59
65
|
}
|
|
60
66
|
token = maybeToken
|
|
61
67
|
}
|
|
@@ -29,67 +29,67 @@ export function findInStore<
|
|
|
29
29
|
K extends Canonical,
|
|
30
30
|
Key extends K,
|
|
31
31
|
>(
|
|
32
|
+
store: Store,
|
|
32
33
|
token: MutableAtomFamilyToken<T, J, K>,
|
|
33
34
|
key: Key,
|
|
34
|
-
store: Store,
|
|
35
35
|
): MutableAtomToken<T, J>
|
|
36
36
|
|
|
37
37
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
38
|
+
store: Store,
|
|
38
39
|
token: RegularAtomFamilyToken<T, K>,
|
|
39
40
|
key: Key,
|
|
40
|
-
store: Store,
|
|
41
41
|
): RegularAtomToken<T>
|
|
42
42
|
|
|
43
43
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
44
|
+
store: Store,
|
|
44
45
|
token: AtomFamilyToken<T, K>,
|
|
45
46
|
key: Key,
|
|
46
|
-
store: Store,
|
|
47
47
|
): AtomToken<T>
|
|
48
48
|
|
|
49
49
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
50
|
+
store: Store,
|
|
50
51
|
token: WritableSelectorFamilyToken<T, K>,
|
|
51
52
|
key: Key,
|
|
52
|
-
store: Store,
|
|
53
53
|
): WritableSelectorToken<T>
|
|
54
54
|
|
|
55
55
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
56
|
+
store: Store,
|
|
56
57
|
token: ReadonlySelectorFamilyToken<T, K>,
|
|
57
58
|
key: Key,
|
|
58
|
-
store: Store,
|
|
59
59
|
): ReadonlySelectorToken<T>
|
|
60
60
|
|
|
61
61
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
62
|
+
store: Store,
|
|
62
63
|
token: SelectorFamilyToken<T, K>,
|
|
63
64
|
key: Key,
|
|
64
|
-
store: Store,
|
|
65
65
|
): SelectorToken<T>
|
|
66
66
|
|
|
67
67
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
68
|
+
store: Store,
|
|
68
69
|
token: WritableFamilyToken<T, K>,
|
|
69
70
|
key: Key,
|
|
70
|
-
store: Store,
|
|
71
71
|
): WritableToken<T>
|
|
72
72
|
|
|
73
73
|
export function findInStore<T, K extends Canonical, Key extends K>(
|
|
74
|
+
store: Store,
|
|
74
75
|
token: ReadableFamilyToken<T, K>,
|
|
75
76
|
key: Key,
|
|
76
|
-
store: Store,
|
|
77
77
|
): ReadableToken<T>
|
|
78
78
|
|
|
79
79
|
export function findInStore(
|
|
80
|
+
store: Store,
|
|
80
81
|
token: ReadableFamilyToken<any, any>,
|
|
81
82
|
key: Json.Serializable,
|
|
82
|
-
store: Store,
|
|
83
83
|
): ReadableToken<any> {
|
|
84
84
|
if (store.config.lifespan === `immortal`) {
|
|
85
85
|
throw new Error(
|
|
86
86
|
`Do not use \`find\` or \`findState\` in an immortal store. Prefer \`seek\` or \`seekState\`.`,
|
|
87
87
|
)
|
|
88
88
|
}
|
|
89
|
-
let state = seekInStore(token, key
|
|
89
|
+
let state = seekInStore(store, token, key)
|
|
90
90
|
if (state) {
|
|
91
91
|
return state
|
|
92
92
|
}
|
|
93
|
-
state = initFamilyMemberInStore(token, key
|
|
93
|
+
state = initFamilyMemberInStore(store, token, key)
|
|
94
94
|
return state
|
|
95
95
|
}
|
|
@@ -30,57 +30,57 @@ export function initFamilyMemberInStore<
|
|
|
30
30
|
K extends Canonical,
|
|
31
31
|
Key extends K,
|
|
32
32
|
>(
|
|
33
|
+
store: Store,
|
|
33
34
|
token: MutableAtomFamilyToken<T, J, K>,
|
|
34
35
|
key: Key,
|
|
35
|
-
store: Store,
|
|
36
36
|
): MutableAtomToken<T, J>
|
|
37
37
|
|
|
38
38
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
39
|
+
store: Store,
|
|
39
40
|
token: RegularAtomFamilyToken<T, K>,
|
|
40
41
|
key: Key,
|
|
41
|
-
store: Store,
|
|
42
42
|
): RegularAtomToken<T>
|
|
43
43
|
|
|
44
44
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
45
|
+
store: Store,
|
|
45
46
|
token: AtomFamilyToken<T, K>,
|
|
46
47
|
key: Key,
|
|
47
|
-
store: Store,
|
|
48
48
|
): AtomToken<T>
|
|
49
49
|
|
|
50
50
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
51
|
+
store: Store,
|
|
51
52
|
token: WritableSelectorFamilyToken<T, K>,
|
|
52
53
|
key: Key,
|
|
53
|
-
store: Store,
|
|
54
54
|
): WritableSelectorToken<T>
|
|
55
55
|
|
|
56
56
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
57
|
+
store: Store,
|
|
57
58
|
token: ReadonlySelectorFamilyToken<T, K>,
|
|
58
59
|
key: Key,
|
|
59
|
-
store: Store,
|
|
60
60
|
): ReadonlySelectorToken<T>
|
|
61
61
|
|
|
62
62
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
63
|
+
store: Store,
|
|
63
64
|
token: SelectorFamilyToken<T, K>,
|
|
64
65
|
key: Key,
|
|
65
|
-
store: Store,
|
|
66
66
|
): SelectorToken<T>
|
|
67
67
|
|
|
68
68
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
69
|
+
store: Store,
|
|
69
70
|
token: WritableFamilyToken<T, K>,
|
|
70
71
|
key: Key,
|
|
71
|
-
store: Store,
|
|
72
72
|
): WritableToken<T>
|
|
73
73
|
|
|
74
74
|
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
75
|
+
store: Store,
|
|
75
76
|
token: ReadableFamilyToken<T, K>,
|
|
76
77
|
key: Key,
|
|
77
|
-
store: Store,
|
|
78
78
|
): ReadableToken<T>
|
|
79
79
|
|
|
80
80
|
export function initFamilyMemberInStore(
|
|
81
|
+
store: Store,
|
|
81
82
|
token: ReadableFamilyToken<any, any>,
|
|
82
83
|
key: Json.Serializable,
|
|
83
|
-
store: Store,
|
|
84
84
|
): ReadableToken<any> {
|
|
85
85
|
const familyKey = token.key
|
|
86
86
|
const family = store.families.get(familyKey)
|
|
@@ -34,63 +34,63 @@ export function seekInStore<
|
|
|
34
34
|
K extends Canonical,
|
|
35
35
|
Key extends K,
|
|
36
36
|
>(
|
|
37
|
+
store: Store,
|
|
37
38
|
token: MutableAtomFamilyToken<T, J, K>,
|
|
38
39
|
key: Key,
|
|
39
|
-
store: Store,
|
|
40
40
|
): MutableAtomToken<T, J> | undefined
|
|
41
41
|
|
|
42
42
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
43
|
+
store: Store,
|
|
43
44
|
token: RegularAtomFamilyToken<T, K>,
|
|
44
45
|
key: Key,
|
|
45
|
-
store: Store,
|
|
46
46
|
): RegularAtomToken<T> | undefined
|
|
47
47
|
|
|
48
48
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
49
|
+
store: Store,
|
|
49
50
|
token: AtomFamilyToken<T, K>,
|
|
50
51
|
key: Key,
|
|
51
|
-
store: Store,
|
|
52
52
|
): AtomToken<T> | undefined
|
|
53
53
|
|
|
54
54
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
55
|
+
store: Store,
|
|
55
56
|
token: WritableSelectorFamilyToken<T, K>,
|
|
56
57
|
key: Key,
|
|
57
|
-
store: Store,
|
|
58
58
|
): WritableSelectorToken<T> | undefined
|
|
59
59
|
|
|
60
60
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
61
|
+
store: Store,
|
|
61
62
|
token: ReadonlySelectorFamilyToken<T, K>,
|
|
62
63
|
key: Key,
|
|
63
|
-
store: Store,
|
|
64
64
|
): ReadonlySelectorToken<T> | undefined
|
|
65
65
|
|
|
66
66
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
67
|
+
store: Store,
|
|
67
68
|
token: SelectorFamilyToken<T, K>,
|
|
68
69
|
key: Key,
|
|
69
|
-
store: Store,
|
|
70
70
|
): SelectorToken<T> | undefined
|
|
71
71
|
|
|
72
72
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
73
|
+
store: Store,
|
|
73
74
|
token: WritableFamilyToken<T, K>,
|
|
74
75
|
key: Key,
|
|
75
|
-
store: Store,
|
|
76
76
|
): WritableToken<T> | undefined
|
|
77
77
|
|
|
78
78
|
export function seekInStore<T, K extends Canonical, Key extends K>(
|
|
79
|
+
store: Store,
|
|
79
80
|
token: ReadableFamilyToken<T, K>,
|
|
80
81
|
key: Key,
|
|
81
|
-
store: Store,
|
|
82
82
|
): ReadableToken<T> | undefined
|
|
83
83
|
|
|
84
84
|
export function seekInStore<M extends MoleculeConstructor>(
|
|
85
|
+
store: Store,
|
|
85
86
|
token: MoleculeFamilyToken<M>,
|
|
86
87
|
key: MoleculeKey<M>,
|
|
87
|
-
store: Store,
|
|
88
88
|
): MoleculeKey<M> | undefined
|
|
89
89
|
|
|
90
90
|
export function seekInStore(
|
|
91
|
+
store: Store,
|
|
91
92
|
token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
|
|
92
93
|
key: Canonical,
|
|
93
|
-
store: Store,
|
|
94
94
|
): MoleculeToken<any> | ReadableToken<any> | undefined {
|
|
95
95
|
const subKey = stringifyJson(key)
|
|
96
96
|
const fullKey = `${token.key}(${subKey})`
|
|
@@ -109,9 +109,6 @@ export function seekInStore(
|
|
|
109
109
|
break
|
|
110
110
|
case `molecule_family`:
|
|
111
111
|
state = target.molecules.get(stringifyJson(key))
|
|
112
|
-
if (state) {
|
|
113
|
-
return deposit(state)
|
|
114
|
-
}
|
|
115
112
|
}
|
|
116
113
|
if (state) {
|
|
117
114
|
return deposit(state)
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
ReadableFamilyToken,
|
|
7
7
|
ReadableToken,
|
|
8
8
|
} from "atom.io"
|
|
9
|
-
import type
|
|
9
|
+
import { type Canonical, stringifyJson } from "atom.io/json"
|
|
10
10
|
|
|
11
11
|
import { findInStore, seekInStore } from "../families"
|
|
12
12
|
import { NotFoundError } from "../not-found-error"
|
|
@@ -14,49 +14,87 @@ import type { Store } from "../store"
|
|
|
14
14
|
import { withdraw } from "../store"
|
|
15
15
|
import { readOrComputeValue } from "./read-or-compute-value"
|
|
16
16
|
|
|
17
|
-
export function getFromStore<T>(token: ReadableToken<T
|
|
17
|
+
export function getFromStore<T>(store: Store, token: ReadableToken<T>): T
|
|
18
18
|
|
|
19
19
|
export function getFromStore<M extends MoleculeConstructor>(
|
|
20
|
-
token: MoleculeToken<M>,
|
|
21
20
|
store: Store,
|
|
22
|
-
|
|
21
|
+
token: MoleculeToken<M>,
|
|
22
|
+
): InstanceType<M>
|
|
23
23
|
|
|
24
24
|
export function getFromStore<T, K extends Canonical>(
|
|
25
|
+
store: Store,
|
|
25
26
|
token: ReadableFamilyToken<T, K>,
|
|
26
27
|
key: K,
|
|
27
|
-
store: Store,
|
|
28
28
|
): T
|
|
29
29
|
|
|
30
30
|
export function getFromStore<M extends MoleculeConstructor>(
|
|
31
|
+
store: Store,
|
|
31
32
|
token: MoleculeFamilyToken<M>,
|
|
32
33
|
key: MoleculeKey<M>,
|
|
33
|
-
store: Store,
|
|
34
34
|
): InstanceType<M>
|
|
35
35
|
|
|
36
|
-
export function getFromStore
|
|
36
|
+
export function getFromStore(
|
|
37
|
+
store: Store,
|
|
38
|
+
token: MoleculeToken<any> | ReadableToken<any>,
|
|
39
|
+
): any
|
|
40
|
+
|
|
41
|
+
export function getFromStore(
|
|
42
|
+
store: Store,
|
|
43
|
+
token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
|
|
44
|
+
key: Canonical,
|
|
45
|
+
): any
|
|
46
|
+
|
|
47
|
+
export function getFromStore(
|
|
48
|
+
store: Store,
|
|
37
49
|
...params:
|
|
38
|
-
| [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
| [
|
|
51
|
+
token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
|
|
52
|
+
key: Canonical,
|
|
53
|
+
]
|
|
54
|
+
| [token: MoleculeFamilyToken<any>, key: MoleculeKey<any>]
|
|
55
|
+
| [token: MoleculeToken<any> | ReadableToken<any>]
|
|
56
|
+
| [token: MoleculeToken<any>]
|
|
57
|
+
| [token: ReadableFamilyToken<any, any>, key: Canonical]
|
|
58
|
+
| [token: ReadableToken<any>]
|
|
42
59
|
): any {
|
|
43
|
-
let token: MoleculeToken<any> | ReadableToken<
|
|
44
|
-
|
|
45
|
-
if (params.length === 2) {
|
|
60
|
+
let token: MoleculeToken<any> | ReadableToken<any>
|
|
61
|
+
if (params.length === 1) {
|
|
46
62
|
token = params[0]
|
|
47
|
-
store = params[1]
|
|
48
63
|
} else {
|
|
49
64
|
const family = params[0]
|
|
50
65
|
const key = params[1]
|
|
51
|
-
store = params[2]
|
|
52
66
|
const maybeToken =
|
|
53
67
|
family.type === `molecule_family`
|
|
54
|
-
? seekInStore(family, key
|
|
68
|
+
? seekInStore(store, family, key)
|
|
55
69
|
: store.config.lifespan === `immortal`
|
|
56
|
-
? seekInStore(family, key
|
|
57
|
-
: findInStore(family, key
|
|
70
|
+
? seekInStore(store, family, key)
|
|
71
|
+
: findInStore(store, family, key)
|
|
58
72
|
if (!maybeToken) {
|
|
59
|
-
|
|
73
|
+
store.logger.error(
|
|
74
|
+
`❗`,
|
|
75
|
+
family.type,
|
|
76
|
+
family.key,
|
|
77
|
+
`tried to get member`,
|
|
78
|
+
stringifyJson(key),
|
|
79
|
+
`but it was not found in store`,
|
|
80
|
+
store.config.name,
|
|
81
|
+
)
|
|
82
|
+
switch (family.type) {
|
|
83
|
+
case `atom_family`:
|
|
84
|
+
case `mutable_atom_family`:
|
|
85
|
+
return store.defaults.get(family.key)
|
|
86
|
+
case `selector_family`:
|
|
87
|
+
case `readonly_selector_family`: {
|
|
88
|
+
if (store.defaults.has(family.key)) {
|
|
89
|
+
return store.defaults.get(family.key)
|
|
90
|
+
}
|
|
91
|
+
const defaultValue = withdraw(family, store).default(key)
|
|
92
|
+
store.defaults.set(family.key, defaultValue)
|
|
93
|
+
return defaultValue
|
|
94
|
+
}
|
|
95
|
+
case `molecule_family`:
|
|
96
|
+
throw new NotFoundError(family, key, store)
|
|
97
|
+
}
|
|
60
98
|
}
|
|
61
99
|
token = maybeToken
|
|
62
100
|
}
|