atom.io 0.30.7 → 0.31.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 +20 -18
- package/data/dist/index.js +104 -172
- package/data/src/join.ts +138 -210
- package/dist/{chunk-UDHCFTYT.js → chunk-42UH5F5Q.js} +356 -744
- package/dist/chunk-ICGFFQ3H.js +272 -0
- package/dist/index.d.ts +52 -103
- package/dist/index.js +3 -11
- package/eslint-plugin/dist/index.d.ts +22 -3
- package/eslint-plugin/dist/index.js +7 -7
- package/immortal/dist/index.d.ts +1 -2
- package/immortal/dist/index.js +0 -3
- package/immortal/src/seek-state.ts +2 -14
- package/internal/dist/index.d.ts +48 -84
- package/internal/dist/index.js +2 -2
- package/internal/src/atom/dispose-atom.ts +31 -15
- package/internal/src/families/dispose-from-store.ts +15 -44
- package/internal/src/families/find-in-store.ts +15 -8
- package/internal/src/families/init-family-member.ts +1 -1
- package/internal/src/families/seek-in-store.ts +2 -14
- package/internal/src/get-state/get-from-store.ts +13 -79
- package/internal/src/get-trace.ts +7 -0
- package/internal/src/index.ts +2 -1
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +63 -70
- package/internal/src/ingest-updates/ingest-transaction-update.ts +4 -0
- package/internal/src/junction.ts +52 -12
- package/internal/src/lineage.ts +0 -7
- package/internal/src/molecule.ts +7 -0
- package/internal/src/mutable/transceiver.ts +5 -5
- package/internal/src/pretty-print.ts +0 -4
- package/internal/src/selector/dispose-selector.ts +3 -5
- package/internal/src/selector/register-selector.ts +2 -26
- package/internal/src/set-state/set-into-store.ts +3 -2
- package/internal/src/store/counterfeit.ts +11 -25
- package/internal/src/store/deposit.ts +5 -39
- package/internal/src/store/store.ts +51 -12
- package/internal/src/store/withdraw.ts +3 -26
- package/internal/src/timeline/create-timeline.ts +133 -237
- package/internal/src/timeline/time-travel.ts +1 -8
- package/internal/src/transaction/build-transaction.ts +10 -5
- package/internal/src/transaction/index.ts +1 -1
- package/internal/src/utility-types.ts +2 -0
- package/introspection/dist/index.d.ts +2 -3
- package/introspection/dist/index.js +9 -9
- package/introspection/src/refinery.ts +1 -3
- package/json/dist/index.js +9 -40
- package/json/src/index.ts +2 -0
- package/json/src/select-json-family.ts +7 -44
- package/package.json +33 -28
- package/react/dist/index.js +2 -10
- package/react/src/parse-state-overloads.ts +3 -11
- package/react-devtools/dist/index.js +13 -13
- package/react-devtools/src/Updates.tsx +2 -0
- package/realtime-client/dist/index.d.ts +20 -12
- package/realtime-client/dist/index.js +241 -244
- package/realtime-client/src/continuity/index.ts +3 -0
- package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +231 -0
- package/realtime-client/src/continuity/use-conceal-state.ts +11 -0
- package/realtime-client/src/continuity/use-reveal-state.ts +19 -0
- package/realtime-client/src/index.ts +1 -0
- package/realtime-client/src/sync-continuity.ts +18 -262
- package/realtime-react/dist/index.js +2 -2
- package/realtime-server/dist/index.d.ts +1 -1
- package/realtime-server/dist/index.js +2 -2
- package/realtime-server/src/index.ts +1 -1
- package/realtime-testing/dist/index.js +2 -3
- package/realtime-testing/src/setup-realtime-test.tsx +1 -2
- package/src/allocate.ts +311 -145
- package/src/dispose-state.ts +5 -21
- package/src/get-state.ts +3 -21
- package/src/molecule.ts +11 -133
- package/src/silo.ts +1 -12
- package/src/timeline.ts +2 -3
- package/src/transaction.ts +25 -38
- package/dist/chunk-ADMEAXYU.js +0 -167
- package/internal/src/molecule/create-molecule-family.ts +0 -30
- package/internal/src/molecule/dispose-molecule.ts +0 -79
- package/internal/src/molecule/grow-molecule-in-store.ts +0 -95
- package/internal/src/molecule/index.ts +0 -5
- package/internal/src/molecule/make-molecule-in-store.ts +0 -191
- package/internal/src/molecule/molecule-internal.ts +0 -52
|
@@ -1,98 +1,41 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
MoleculeFamilyToken,
|
|
4
|
-
MoleculeKey,
|
|
5
|
-
MoleculeToken,
|
|
6
|
-
ReadableFamilyToken,
|
|
7
|
-
ReadableToken,
|
|
8
|
-
} from "atom.io"
|
|
9
|
-
import { type Canonical, parseJson } from "atom.io/json"
|
|
1
|
+
import type { ReadableFamilyToken, ReadableToken } from "atom.io"
|
|
2
|
+
import type { Canonical } from "atom.io/json"
|
|
10
3
|
|
|
11
|
-
import { findInStore
|
|
12
|
-
import { getFamilyOfToken } from "../families/get-family-of-token"
|
|
13
|
-
import { NotFoundError } from "../not-found-error"
|
|
4
|
+
import { findInStore } from "../families"
|
|
14
5
|
import type { Store } from "../store"
|
|
15
|
-
import {
|
|
6
|
+
import { withdraw } from "../store"
|
|
16
7
|
import { readOrComputeValue } from "./read-or-compute-value"
|
|
17
8
|
|
|
18
9
|
export function getFromStore<T>(store: Store, token: ReadableToken<T>): T
|
|
19
10
|
|
|
20
|
-
export function getFromStore<M extends MoleculeConstructor>(
|
|
21
|
-
store: Store,
|
|
22
|
-
token: MoleculeToken<M>,
|
|
23
|
-
): InstanceType<M>
|
|
24
|
-
|
|
25
11
|
export function getFromStore<T, K extends Canonical>(
|
|
26
12
|
store: Store,
|
|
27
13
|
token: ReadableFamilyToken<T, K>,
|
|
28
14
|
key: K,
|
|
29
15
|
): T
|
|
30
16
|
|
|
31
|
-
export function getFromStore<M extends MoleculeConstructor>(
|
|
32
|
-
store: Store,
|
|
33
|
-
token: MoleculeFamilyToken<M>,
|
|
34
|
-
key: MoleculeKey<M>,
|
|
35
|
-
): InstanceType<M>
|
|
36
|
-
|
|
37
|
-
export function getFromStore(
|
|
38
|
-
store: Store,
|
|
39
|
-
token: MoleculeToken<any> | ReadableToken<any>,
|
|
40
|
-
): any
|
|
41
|
-
|
|
42
|
-
export function getFromStore(
|
|
43
|
-
store: Store,
|
|
44
|
-
token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
|
|
45
|
-
key: Canonical,
|
|
46
|
-
): any
|
|
47
|
-
|
|
48
17
|
export function getFromStore(
|
|
49
18
|
store: Store,
|
|
50
19
|
...params:
|
|
51
|
-
| [
|
|
52
|
-
token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
|
|
53
|
-
key: Canonical,
|
|
54
|
-
]
|
|
55
|
-
| [token: MoleculeFamilyToken<any>, key: MoleculeKey<any>]
|
|
56
|
-
| [token: MoleculeToken<any> | ReadableToken<any>]
|
|
57
|
-
| [token: MoleculeToken<any>]
|
|
58
20
|
| [token: ReadableFamilyToken<any, any>, key: Canonical]
|
|
59
21
|
| [token: ReadableToken<any>]
|
|
60
22
|
): any {
|
|
61
|
-
let token:
|
|
62
|
-
let family:
|
|
63
|
-
| MoleculeFamilyToken<any>
|
|
64
|
-
| ReadableFamilyToken<any, Canonical>
|
|
65
|
-
| null
|
|
23
|
+
let token: ReadableToken<any>
|
|
24
|
+
let family: ReadableFamilyToken<any, Canonical> | null
|
|
66
25
|
let key: Canonical | null
|
|
67
26
|
if (params.length === 1) {
|
|
68
27
|
token = params[0]
|
|
69
|
-
if (token.type !== `molecule`) {
|
|
70
|
-
family = getFamilyOfToken(store, token) ?? null
|
|
71
|
-
if (family) {
|
|
72
|
-
key = token.family ? parseJson(token.family.subKey) : null
|
|
73
|
-
token = findInStore(store, family, key)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
28
|
} else {
|
|
77
29
|
family = params[0]
|
|
78
30
|
key = params[1]
|
|
79
|
-
|
|
80
|
-
if (family.type === `molecule_family`) {
|
|
81
|
-
maybeToken = seekInStore(store, family, key) ?? counterfeit(family, key)
|
|
82
|
-
} else {
|
|
83
|
-
maybeToken = findInStore(store, family, key)
|
|
84
|
-
}
|
|
85
|
-
token = maybeToken
|
|
31
|
+
token = findInStore(store, family, key)
|
|
86
32
|
}
|
|
87
33
|
if (`counterfeit` in token && `family` in token) {
|
|
88
|
-
family
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
: // biome-ignore lint/style/noNonNullAssertion: family must be present
|
|
92
|
-
store.families.get(token.family.key)!
|
|
93
|
-
const subKey = token.type === `molecule` ? token.key : token.family.subKey
|
|
34
|
+
// biome-ignore lint/style/noNonNullAssertion: family must be present
|
|
35
|
+
family = store.families.get(token.family.key)!
|
|
36
|
+
const subKey = token.family.subKey
|
|
94
37
|
const disposal = store.disposalTraces.buffer.find(
|
|
95
|
-
(item) => item?.key ===
|
|
38
|
+
(item) => item?.key === subKey,
|
|
96
39
|
)
|
|
97
40
|
store.logger.error(
|
|
98
41
|
`❌`,
|
|
@@ -116,17 +59,8 @@ export function getFromStore(
|
|
|
116
59
|
store.defaults.set(family.key, defaultValue)
|
|
117
60
|
return defaultValue
|
|
118
61
|
}
|
|
119
|
-
case `molecule_family`:
|
|
120
|
-
throw new NotFoundError(family, subKey, store)
|
|
121
62
|
}
|
|
122
63
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
case `mutable_atom`:
|
|
126
|
-
case `selector`:
|
|
127
|
-
case `readonly_selector`:
|
|
128
|
-
return readOrComputeValue(withdraw(token, store), store)
|
|
129
|
-
case `molecule`:
|
|
130
|
-
return withdraw(token, store).instance
|
|
131
|
-
}
|
|
64
|
+
|
|
65
|
+
return readOrComputeValue(withdraw(token, store), store)
|
|
132
66
|
}
|
package/internal/src/index.ts
CHANGED
|
@@ -25,12 +25,13 @@ export * from "./families"
|
|
|
25
25
|
export * from "./future"
|
|
26
26
|
export * from "./get-environment-data"
|
|
27
27
|
export * from "./get-state"
|
|
28
|
+
export * from "./get-trace"
|
|
28
29
|
export * from "./ingest-updates"
|
|
29
30
|
export * from "./junction"
|
|
30
31
|
export * from "./keys"
|
|
31
32
|
export * from "./lazy-map"
|
|
32
33
|
export * from "./lineage"
|
|
33
|
-
export * from "./molecule"
|
|
34
|
+
export type * from "./molecule"
|
|
34
35
|
export * from "./mutable"
|
|
35
36
|
export * from "./not-found-error"
|
|
36
37
|
export * from "./operation"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
MoleculeCreation,
|
|
3
3
|
MoleculeDisposal,
|
|
4
|
+
MoleculeTransfer,
|
|
4
5
|
ReadableToken,
|
|
5
6
|
StateCreation,
|
|
6
7
|
StateDisposal,
|
|
@@ -9,12 +10,12 @@ import { parseJson, stringifyJson } from "atom.io/json"
|
|
|
9
10
|
|
|
10
11
|
import {
|
|
11
12
|
allocateIntoStore,
|
|
13
|
+
claimWithinStore,
|
|
12
14
|
deallocateFromStore,
|
|
13
15
|
} from "~/packages/atom.io/src/allocate"
|
|
14
16
|
|
|
15
17
|
import { disposeFromStore, findInStore } from "../families"
|
|
16
|
-
import {
|
|
17
|
-
import { type Store, withdraw } from "../store"
|
|
18
|
+
import type { Store } from "../store"
|
|
18
19
|
|
|
19
20
|
export function ingestCreationEvent(
|
|
20
21
|
update: StateCreation<any>,
|
|
@@ -45,7 +46,9 @@ export function ingestDisposalEvent(
|
|
|
45
46
|
}
|
|
46
47
|
case `oldValue`: {
|
|
47
48
|
createInStore(update, store)
|
|
48
|
-
|
|
49
|
+
if (update.subType === `atom`) {
|
|
50
|
+
store.valueMap.set(update.token.key, update.value)
|
|
51
|
+
}
|
|
49
52
|
break
|
|
50
53
|
}
|
|
51
54
|
}
|
|
@@ -65,36 +68,17 @@ function createInStore(
|
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
export function ingestMoleculeCreationEvent(
|
|
68
|
-
update: MoleculeCreation
|
|
71
|
+
update: MoleculeCreation,
|
|
69
72
|
applying: `newValue` | `oldValue`,
|
|
70
73
|
store: Store,
|
|
71
74
|
): void {
|
|
72
75
|
switch (applying) {
|
|
73
76
|
case `newValue`:
|
|
74
|
-
|
|
75
|
-
case `classic`:
|
|
76
|
-
makeMoleculeInStore(
|
|
77
|
-
store,
|
|
78
|
-
update.context,
|
|
79
|
-
update.family,
|
|
80
|
-
update.token.key,
|
|
81
|
-
...update.params,
|
|
82
|
-
)
|
|
83
|
-
break
|
|
84
|
-
case `modern`:
|
|
85
|
-
allocateIntoStore<any, any, any>(store, update.provenance, update.key)
|
|
86
|
-
break
|
|
87
|
-
}
|
|
77
|
+
allocateIntoStore<any, any, any>(store, update.provenance, update.key)
|
|
88
78
|
break
|
|
79
|
+
|
|
89
80
|
case `oldValue`:
|
|
90
|
-
|
|
91
|
-
case `classic`:
|
|
92
|
-
disposeFromStore(store, update.token)
|
|
93
|
-
break
|
|
94
|
-
case `modern`:
|
|
95
|
-
deallocateFromStore<any, any, any>(store, update.key)
|
|
96
|
-
break
|
|
97
|
-
}
|
|
81
|
+
deallocateFromStore<any, any>(store, update.key)
|
|
98
82
|
break
|
|
99
83
|
}
|
|
100
84
|
}
|
|
@@ -105,56 +89,65 @@ export function ingestMoleculeDisposalEvent(
|
|
|
105
89
|
): void {
|
|
106
90
|
switch (applying) {
|
|
107
91
|
case `newValue`:
|
|
108
|
-
|
|
109
|
-
case `classic`:
|
|
110
|
-
disposeFromStore(store, update.token)
|
|
111
|
-
break
|
|
112
|
-
case `modern`:
|
|
113
|
-
deallocateFromStore<any, any, any>(store, update.key)
|
|
114
|
-
break
|
|
115
|
-
}
|
|
92
|
+
deallocateFromStore<any, any>(store, update.key)
|
|
116
93
|
break
|
|
94
|
+
|
|
117
95
|
case `oldValue`:
|
|
118
96
|
{
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
break
|
|
141
|
-
case `modern`: {
|
|
142
|
-
allocateIntoStore<any, any, any>(
|
|
143
|
-
store,
|
|
144
|
-
update.provenance,
|
|
145
|
-
update.key,
|
|
146
|
-
)
|
|
147
|
-
for (const [familyKey, value] of update.values) {
|
|
148
|
-
const family = store.families.get(familyKey)
|
|
149
|
-
if (family) {
|
|
150
|
-
findInStore(store, family, update.key)
|
|
151
|
-
const memberKey = `${familyKey}(${stringifyJson(update.key)})`
|
|
152
|
-
store.valueMap.set(memberKey, value)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
97
|
+
// let first = t rue
|
|
98
|
+
// for (const ownerString of update.provenance) {
|
|
99
|
+
// // const owner = parseJson(ownerString)
|
|
100
|
+
// // if (first) {
|
|
101
|
+
// // first = false
|
|
102
|
+
// // allocateIntoStore<any, any, any>(store, owner, update.key)
|
|
103
|
+
// // continue
|
|
104
|
+
// // }
|
|
105
|
+
|
|
106
|
+
// // claimWithinStore<any, any, any>(store, owner, update.key)
|
|
107
|
+
|
|
108
|
+
// }
|
|
109
|
+
const provenanceJson = update.provenance.map(parseJson)
|
|
110
|
+
allocateIntoStore<any, any, any>(store, provenanceJson, update.key)
|
|
111
|
+
for (const [familyKey, value] of update.values) {
|
|
112
|
+
const family = store.families.get(familyKey)
|
|
113
|
+
if (family) {
|
|
114
|
+
findInStore(store, family, update.key)
|
|
115
|
+
const memberKey = `${familyKey}(${stringifyJson(update.key)})`
|
|
116
|
+
store.valueMap.set(memberKey, value)
|
|
155
117
|
}
|
|
156
118
|
}
|
|
157
119
|
}
|
|
158
120
|
break
|
|
159
121
|
}
|
|
160
122
|
}
|
|
123
|
+
export function ingestMoleculeTransferEvent(
|
|
124
|
+
update: MoleculeTransfer,
|
|
125
|
+
applying: `newValue` | `oldValue`,
|
|
126
|
+
store: Store,
|
|
127
|
+
): void {
|
|
128
|
+
switch (applying) {
|
|
129
|
+
case `newValue`:
|
|
130
|
+
{
|
|
131
|
+
const provenance = update.to.length === 1 ? update.to[0] : update.to
|
|
132
|
+
claimWithinStore<any, any, any>(
|
|
133
|
+
store,
|
|
134
|
+
provenance,
|
|
135
|
+
update.key,
|
|
136
|
+
`exclusive`,
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
break
|
|
140
|
+
case `oldValue`:
|
|
141
|
+
{
|
|
142
|
+
const provenance =
|
|
143
|
+
update.from.length === 1 ? update.from[0] : update.from
|
|
144
|
+
claimWithinStore<any, any, any>(
|
|
145
|
+
store,
|
|
146
|
+
provenance,
|
|
147
|
+
update.key,
|
|
148
|
+
`exclusive`,
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
break
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
ingestDisposalEvent,
|
|
8
8
|
ingestMoleculeCreationEvent,
|
|
9
9
|
ingestMoleculeDisposalEvent,
|
|
10
|
+
ingestMoleculeTransferEvent,
|
|
10
11
|
} from "./ingest-creation-disposal"
|
|
11
12
|
|
|
12
13
|
export function ingestTransactionUpdate(
|
|
@@ -36,6 +37,9 @@ export function ingestTransactionUpdate(
|
|
|
36
37
|
case `molecule_disposal`:
|
|
37
38
|
ingestMoleculeDisposalEvent(updateFromTransaction, applying, store)
|
|
38
39
|
break
|
|
40
|
+
case `molecule_transfer`:
|
|
41
|
+
ingestMoleculeTransferEvent(updateFromTransaction, applying, store)
|
|
42
|
+
break
|
|
39
43
|
case `transaction_update`:
|
|
40
44
|
ingestTransactionUpdate(applying, updateFromTransaction, store)
|
|
41
45
|
break
|
package/internal/src/junction.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { Refinement } from "atom.io/introspection"
|
|
2
1
|
import type { Json } from "atom.io/json"
|
|
3
2
|
|
|
3
|
+
import type { Refinement } from "./utility-types"
|
|
4
|
+
|
|
4
5
|
export type JunctionEntriesBase<
|
|
5
6
|
AType extends string,
|
|
6
7
|
BType extends string,
|
|
@@ -279,18 +280,57 @@ export class Junction<
|
|
|
279
280
|
...rest: Content extends null ? [] | [void?: undefined] : [content: Content]
|
|
280
281
|
): this
|
|
281
282
|
public set(
|
|
282
|
-
a: AType | ({ [Key in ASide]: AType } & { [Key in BSide]: BType }),
|
|
283
|
-
...rest: Content extends null
|
|
284
|
-
|
|
285
|
-
|
|
283
|
+
// a: AType | ({ [Key in ASide]: AType } & { [Key in BSide]: BType }),
|
|
284
|
+
// ...rest: Content extends null
|
|
285
|
+
// ? [] | [b?: BType | undefined]
|
|
286
|
+
// : [b: BType, content: Content] | [content: Content]
|
|
287
|
+
...params:
|
|
288
|
+
| [
|
|
289
|
+
a: AType,
|
|
290
|
+
...rest: Content extends null
|
|
291
|
+
? [b: BType]
|
|
292
|
+
: [b: BType, content: Content],
|
|
293
|
+
]
|
|
294
|
+
| [
|
|
295
|
+
relation: { [Key in ASide]: AType } & { [Key in BSide]: BType },
|
|
296
|
+
...rest: Content extends null
|
|
297
|
+
? [] | [void?: undefined]
|
|
298
|
+
: [content: Content],
|
|
299
|
+
]
|
|
300
|
+
// | [{ [Key in ASide]: AType } & { [Key in BSide]: BType }, content: Content]
|
|
301
|
+
// | [{ [Key in ASide]: AType } & { [Key in BSide]: BType }]
|
|
302
|
+
// | [a: AType, b: BType, content: Content]
|
|
303
|
+
// | [a: AType, b: BType]
|
|
286
304
|
): this {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
305
|
+
let a: AType
|
|
306
|
+
let b: BType
|
|
307
|
+
let content: Content | undefined
|
|
308
|
+
switch (params.length) {
|
|
309
|
+
case 1: {
|
|
310
|
+
const relation = params[0] as Record<ASide, AType> & Record<BSide, BType>
|
|
311
|
+
a = relation[this.a]
|
|
312
|
+
b = relation[this.b]
|
|
313
|
+
content = undefined
|
|
314
|
+
break
|
|
315
|
+
}
|
|
316
|
+
case 2: {
|
|
317
|
+
const zeroth = params[0]
|
|
318
|
+
if (typeof zeroth === `string`) {
|
|
319
|
+
;[a, b] = params as unknown as [AType, BType]
|
|
320
|
+
} else {
|
|
321
|
+
a = zeroth[this.a]
|
|
322
|
+
b = zeroth[this.b]
|
|
323
|
+
content = params[1] as Content
|
|
324
|
+
}
|
|
325
|
+
break
|
|
326
|
+
}
|
|
327
|
+
default: {
|
|
328
|
+
a = params[0] as AType
|
|
329
|
+
b = params[1] as BType
|
|
330
|
+
content = params[2] as Content
|
|
331
|
+
break
|
|
332
|
+
}
|
|
333
|
+
}
|
|
294
334
|
switch (this.cardinality) {
|
|
295
335
|
// biome-ignore lint/suspicious/noFallthroughSwitchClause: perfect here
|
|
296
336
|
case `1:1`: {
|
package/internal/src/lineage.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Json } from "atom.io/json"
|
|
2
2
|
|
|
3
|
-
export interface Transceiver<
|
|
4
|
-
do: (update:
|
|
5
|
-
undo: (update:
|
|
6
|
-
subscribe: (key: string, fn: (update:
|
|
3
|
+
export interface Transceiver<S extends Json.Serializable> {
|
|
4
|
+
do: (update: S) => number | `OUT_OF_RANGE` | null
|
|
5
|
+
undo: (update: S) => void
|
|
6
|
+
subscribe: (key: string, fn: (update: S) => void) => () => void
|
|
7
7
|
cacheUpdateNumber: number
|
|
8
|
-
getUpdateNumber: (update:
|
|
8
|
+
getUpdateNumber: (update: S) => number
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function isTransceiver(
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
MoleculeFamilyToken,
|
|
3
|
-
MoleculeToken,
|
|
4
2
|
ReadableFamilyToken,
|
|
5
3
|
ReadableToken,
|
|
6
4
|
TimelineToken,
|
|
@@ -10,8 +8,6 @@ import type {
|
|
|
10
8
|
const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
|
|
11
9
|
|
|
12
10
|
export type AtomIOToken =
|
|
13
|
-
| MoleculeFamilyToken<any>
|
|
14
|
-
| MoleculeToken<any>
|
|
15
11
|
| ReadableFamilyToken<any, any>
|
|
16
12
|
| ReadableToken<any>
|
|
17
13
|
| TimelineToken<any>
|
|
@@ -20,7 +20,7 @@ export function disposeSelector(
|
|
|
20
20
|
} else {
|
|
21
21
|
const molecule = target.molecules.get(selector.family.subKey)
|
|
22
22
|
if (molecule) {
|
|
23
|
-
|
|
23
|
+
target.moleculeData.delete(selector.family.subKey, selector.family.key)
|
|
24
24
|
}
|
|
25
25
|
switch (selectorToken.type) {
|
|
26
26
|
case `selector`:
|
|
@@ -30,10 +30,6 @@ export function disposeSelector(
|
|
|
30
30
|
{ key: selector.family.key, type: `selector_family` },
|
|
31
31
|
store,
|
|
32
32
|
)
|
|
33
|
-
family.subject.next({
|
|
34
|
-
type: `state_disposal`,
|
|
35
|
-
token: selectorToken,
|
|
36
|
-
})
|
|
37
33
|
}
|
|
38
34
|
break
|
|
39
35
|
case `readonly_selector`:
|
|
@@ -45,6 +41,7 @@ export function disposeSelector(
|
|
|
45
41
|
)
|
|
46
42
|
family.subject.next({
|
|
47
43
|
type: `state_disposal`,
|
|
44
|
+
subType: `selector`,
|
|
48
45
|
token: selectorToken,
|
|
49
46
|
})
|
|
50
47
|
}
|
|
@@ -57,6 +54,7 @@ export function disposeSelector(
|
|
|
57
54
|
if (isChildStore(target) && target.transactionMeta.phase === `building`) {
|
|
58
55
|
target.transactionMeta.update.updates.push({
|
|
59
56
|
type: `state_disposal`,
|
|
57
|
+
subType: `selector`,
|
|
60
58
|
token: selectorToken,
|
|
61
59
|
})
|
|
62
60
|
} else {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
MoleculeConstructor,
|
|
3
|
-
MoleculeFamilyToken,
|
|
4
|
-
MoleculeToken,
|
|
5
2
|
ReadableFamilyToken,
|
|
6
3
|
ReadableToken,
|
|
7
4
|
setState,
|
|
@@ -14,7 +11,6 @@ import type { seekState } from "atom.io/immortal"
|
|
|
14
11
|
import type { Json } from "atom.io/json"
|
|
15
12
|
|
|
16
13
|
import { findInStore, seekInStore } from "../families"
|
|
17
|
-
import { getFromStore } from "../get-state"
|
|
18
14
|
import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
19
15
|
import { newest } from "../lineage"
|
|
20
16
|
import { getJsonToken } from "../mutable"
|
|
@@ -31,39 +27,19 @@ export const registerSelector = (
|
|
|
31
27
|
): SetterToolkit => ({
|
|
32
28
|
get: (
|
|
33
29
|
...params:
|
|
34
|
-
| [MoleculeFamilyToken<any>, Json.Serializable]
|
|
35
|
-
| [MoleculeToken<MoleculeConstructor>]
|
|
36
30
|
| [ReadableFamilyToken<any, any>, Json.Serializable]
|
|
37
31
|
| [ReadableToken<any>]
|
|
38
32
|
) => {
|
|
39
33
|
const target = newest(store)
|
|
40
|
-
let dependency:
|
|
34
|
+
let dependency: ReadableToken<any>
|
|
41
35
|
|
|
42
36
|
if (params.length === 2) {
|
|
43
37
|
const [family, key] = params
|
|
44
|
-
|
|
45
|
-
case `molecule_family`:
|
|
46
|
-
return getFromStore(store, family, key)
|
|
47
|
-
default:
|
|
48
|
-
if (store.config.lifespan === `ephemeral`) {
|
|
49
|
-
dependency = findInStore(store, family, key)
|
|
50
|
-
} else {
|
|
51
|
-
const maybeDependency = seekInStore(store, family, key)
|
|
52
|
-
if (maybeDependency) {
|
|
53
|
-
dependency = maybeDependency
|
|
54
|
-
} else {
|
|
55
|
-
throw new NotFoundError(family, key, store)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
38
|
+
dependency = findInStore(store, family, key)
|
|
59
39
|
} else {
|
|
60
40
|
;[dependency] = params
|
|
61
41
|
}
|
|
62
42
|
|
|
63
|
-
if (dependency.type === `molecule`) {
|
|
64
|
-
return getFromStore(store, dependency)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
43
|
const dependencyState = withdraw(dependency, store)
|
|
68
44
|
const dependencyValue = readOrComputeValue(dependencyState, store)
|
|
69
45
|
|
|
@@ -50,9 +50,10 @@ export function setIntoStore<T, New extends T>(
|
|
|
50
50
|
token = findInStore(store, family, key)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
if (`counterfeit` in token) {
|
|
53
|
+
if (`counterfeit` in token && `family` in token) {
|
|
54
|
+
const subKey = token.family.subKey
|
|
54
55
|
const disposal = store.disposalTraces.buffer.find(
|
|
55
|
-
(item) => item?.key ===
|
|
56
|
+
(item) => item?.key === subKey,
|
|
56
57
|
)
|
|
57
58
|
store.logger.error(
|
|
58
59
|
`❌`,
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AtomFamilyToken,
|
|
3
3
|
AtomToken,
|
|
4
|
-
MoleculeConstructor,
|
|
5
|
-
MoleculeFamilyToken,
|
|
6
|
-
MoleculeKey,
|
|
7
|
-
MoleculeToken,
|
|
8
4
|
MutableAtomFamilyToken,
|
|
9
5
|
MutableAtomToken,
|
|
10
6
|
ReadableFamilyToken,
|
|
@@ -75,35 +71,25 @@ export function counterfeit<T, K extends Canonical, Key extends K>(
|
|
|
75
71
|
key: Key,
|
|
76
72
|
): ReadableToken<T>
|
|
77
73
|
|
|
78
|
-
export function counterfeit<M extends MoleculeConstructor>(
|
|
79
|
-
token: MoleculeFamilyToken<M>,
|
|
80
|
-
key: MoleculeKey<M>,
|
|
81
|
-
): MoleculeKey<M>
|
|
82
|
-
|
|
83
74
|
export function counterfeit(
|
|
84
|
-
token:
|
|
75
|
+
token: ReadableFamilyToken<any, any>,
|
|
85
76
|
key: Canonical,
|
|
86
|
-
):
|
|
77
|
+
): ReadableToken<any> {
|
|
87
78
|
const subKey = stringifyJson(key)
|
|
88
79
|
const fullKey = `${token.key}(${subKey})`
|
|
89
80
|
const type = FAMILY_MEMBER_TOKEN_TYPES[token.type]
|
|
90
81
|
const stateToken = {
|
|
91
82
|
key: fullKey,
|
|
92
83
|
type,
|
|
93
|
-
} satisfies
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
key: token.key,
|
|
103
|
-
subKey,
|
|
104
|
-
},
|
|
105
|
-
})
|
|
106
|
-
}
|
|
84
|
+
} satisfies ReadableToken<any>
|
|
85
|
+
|
|
86
|
+
Object.assign(stateToken, {
|
|
87
|
+
family: {
|
|
88
|
+
key: token.key,
|
|
89
|
+
subKey,
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
|
|
107
93
|
Object.assign(stateToken, { counterfeit: true })
|
|
108
94
|
return stateToken
|
|
109
95
|
}
|