atom.io 0.30.7 → 0.31.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 +20 -18
- package/data/dist/index.js +104 -172
- package/data/src/join.ts +138 -210
- package/dist/{chunk-UDHCFTYT.js → chunk-Y5MBNTVU.js} +582 -762
- package/dist/index.d.ts +254 -173
- package/dist/index.js +91 -14
- package/ephemeral/dist/index.d.ts +35 -25
- package/ephemeral/src/find-state.ts +35 -25
- 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 +57 -88
- package/internal/dist/index.js +1 -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 +9 -7
- 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 +17 -8
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +65 -73
- package/internal/src/ingest-updates/ingest-transaction-update.ts +4 -0
- package/internal/src/install-into-store.ts +48 -0
- package/internal/src/junction.ts +52 -12
- package/internal/src/lineage.ts +0 -7
- package/internal/src/molecule.ts +306 -0
- package/internal/src/mutable/transceiver.ts +5 -5
- package/internal/src/not-found-error.ts +8 -30
- package/internal/src/pretty-print.ts +1 -16
- package/internal/src/selector/dispose-selector.ts +3 -5
- package/internal/src/selector/register-selector.ts +3 -34
- 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 +10 -42
- package/internal/src/store/store.ts +51 -12
- package/internal/src/store/withdraw.ts +18 -60
- 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 +8 -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-server/src/ipc-sockets/child-socket.ts +0 -1
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +1 -1
- package/realtime-testing/dist/index.js +5 -7
- package/realtime-testing/src/setup-realtime-test.tsx +5 -6
- package/src/atom.ts +53 -29
- package/src/dispose-state.ts +17 -23
- package/src/get-state.ts +19 -21
- package/src/index.ts +73 -3
- package/src/realm.ts +169 -0
- package/src/selector.ts +20 -0
- package/src/set-state.ts +16 -8
- package/src/silo.ts +9 -14
- package/src/timeline.ts +2 -3
- package/src/transaction.ts +25 -38
- package/transceivers/set-rtx/dist/index.js +4 -1
- package/transceivers/set-rtx/src/set-rtx.ts +4 -1
- 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
- package/src/allocate.ts +0 -277
- package/src/molecule.ts +0 -138
|
@@ -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
|
@@ -17,6 +17,8 @@ import type { Canonical, Json, JsonInterface } from "atom.io/json"
|
|
|
17
17
|
import type { Transceiver } from "./mutable"
|
|
18
18
|
import type { Store } from "./store"
|
|
19
19
|
import type { Subject } from "./subject"
|
|
20
|
+
import type { Timeline } from "./timeline"
|
|
21
|
+
import type { Transaction } from "./transaction"
|
|
20
22
|
|
|
21
23
|
export * from "./arbitrary"
|
|
22
24
|
export * from "./atom"
|
|
@@ -25,6 +27,7 @@ export * from "./families"
|
|
|
25
27
|
export * from "./future"
|
|
26
28
|
export * from "./get-environment-data"
|
|
27
29
|
export * from "./get-state"
|
|
30
|
+
export * from "./get-trace"
|
|
28
31
|
export * from "./ingest-updates"
|
|
29
32
|
export * from "./junction"
|
|
30
33
|
export * from "./keys"
|
|
@@ -99,14 +102,14 @@ T extends Transceiver<any>,
|
|
|
99
102
|
J extends Json.Serializable,
|
|
100
103
|
K extends Canonical,
|
|
101
104
|
> =
|
|
102
|
-
& JsonInterface<T, J>
|
|
103
|
-
& MutableAtomFamilyToken<T, J, K>
|
|
104
|
-
& {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
& JsonInterface<T, J>
|
|
106
|
+
& MutableAtomFamilyToken<T, J, K>
|
|
107
|
+
& {
|
|
108
|
+
(key: K): MutableAtomToken<T, J>
|
|
109
|
+
subject: Subject<StateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>>
|
|
110
|
+
install: (store: Store) => void
|
|
111
|
+
internalRoles: string[] | undefined
|
|
112
|
+
}
|
|
110
113
|
|
|
111
114
|
export type AtomFamily<T, K extends Canonical = Canonical> =
|
|
112
115
|
| MutableAtomFamily<T extends Transceiver<any> ? T : never, any, K>
|
|
@@ -144,3 +147,9 @@ export type WritableFamily<T, K extends Canonical> =
|
|
|
144
147
|
export type ReadableFamily<T, K extends Canonical> =
|
|
145
148
|
| AtomFamily<T, K>
|
|
146
149
|
| SelectorFamily<T, K>
|
|
150
|
+
|
|
151
|
+
export type AtomIOInternalResource =
|
|
152
|
+
| ReadableFamily<any, any>
|
|
153
|
+
| ReadableState<any>
|
|
154
|
+
| Timeline<any>
|
|
155
|
+
| Transaction<any>
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
MoleculeCreation,
|
|
3
3
|
MoleculeDisposal,
|
|
4
|
+
MoleculeTransfer,
|
|
4
5
|
ReadableToken,
|
|
5
6
|
StateCreation,
|
|
6
7
|
StateDisposal,
|
|
7
8
|
} from "atom.io"
|
|
8
9
|
import { parseJson, stringifyJson } from "atom.io/json"
|
|
9
10
|
|
|
11
|
+
import { disposeFromStore, findInStore } from "../families"
|
|
10
12
|
import {
|
|
11
13
|
allocateIntoStore,
|
|
14
|
+
claimWithinStore,
|
|
12
15
|
deallocateFromStore,
|
|
13
|
-
} from "
|
|
14
|
-
|
|
15
|
-
import { disposeFromStore, findInStore } from "../families"
|
|
16
|
-
import { growMoleculeInStore, makeMoleculeInStore } from "../molecule"
|
|
17
|
-
import { type Store, withdraw } from "../store"
|
|
16
|
+
} from "../molecule"
|
|
17
|
+
import type { Store } from "../store"
|
|
18
18
|
|
|
19
19
|
export function ingestCreationEvent(
|
|
20
20
|
update: StateCreation<any>,
|
|
@@ -45,7 +45,9 @@ export function ingestDisposalEvent(
|
|
|
45
45
|
}
|
|
46
46
|
case `oldValue`: {
|
|
47
47
|
createInStore(update, store)
|
|
48
|
-
|
|
48
|
+
if (update.subType === `atom`) {
|
|
49
|
+
store.valueMap.set(update.token.key, update.value)
|
|
50
|
+
}
|
|
49
51
|
break
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -65,36 +67,17 @@ function createInStore(
|
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
export function ingestMoleculeCreationEvent(
|
|
68
|
-
update: MoleculeCreation
|
|
70
|
+
update: MoleculeCreation,
|
|
69
71
|
applying: `newValue` | `oldValue`,
|
|
70
72
|
store: Store,
|
|
71
73
|
): void {
|
|
72
74
|
switch (applying) {
|
|
73
75
|
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
|
-
}
|
|
76
|
+
allocateIntoStore<any, any, any>(store, update.provenance, update.key)
|
|
88
77
|
break
|
|
78
|
+
|
|
89
79
|
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
|
-
}
|
|
80
|
+
deallocateFromStore<any, any>(store, update.key)
|
|
98
81
|
break
|
|
99
82
|
}
|
|
100
83
|
}
|
|
@@ -105,56 +88,65 @@ export function ingestMoleculeDisposalEvent(
|
|
|
105
88
|
): void {
|
|
106
89
|
switch (applying) {
|
|
107
90
|
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
|
-
}
|
|
91
|
+
deallocateFromStore<any, any>(store, update.key)
|
|
116
92
|
break
|
|
93
|
+
|
|
117
94
|
case `oldValue`:
|
|
118
95
|
{
|
|
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
|
-
}
|
|
96
|
+
// let first = t rue
|
|
97
|
+
// for (const ownerString of update.provenance) {
|
|
98
|
+
// // const owner = parseJson(ownerString)
|
|
99
|
+
// // if (first) {
|
|
100
|
+
// // first = false
|
|
101
|
+
// // allocateIntoStore<any, any, any>(store, owner, update.key)
|
|
102
|
+
// // continue
|
|
103
|
+
// // }
|
|
104
|
+
|
|
105
|
+
// // claimWithinStore<any, any, any>(store, owner, update.key)
|
|
106
|
+
|
|
107
|
+
// }
|
|
108
|
+
const provenanceJson = update.provenance.map(parseJson)
|
|
109
|
+
allocateIntoStore<any, any, any>(store, provenanceJson, update.key)
|
|
110
|
+
for (const [familyKey, value] of update.values) {
|
|
111
|
+
const family = store.families.get(familyKey)
|
|
112
|
+
if (family) {
|
|
113
|
+
findInStore(store, family, update.key)
|
|
114
|
+
const memberKey = `${familyKey}(${stringifyJson(update.key)})`
|
|
115
|
+
store.valueMap.set(memberKey, value)
|
|
155
116
|
}
|
|
156
117
|
}
|
|
157
118
|
}
|
|
158
119
|
break
|
|
159
120
|
}
|
|
160
121
|
}
|
|
122
|
+
export function ingestMoleculeTransferEvent(
|
|
123
|
+
update: MoleculeTransfer,
|
|
124
|
+
applying: `newValue` | `oldValue`,
|
|
125
|
+
store: Store,
|
|
126
|
+
): void {
|
|
127
|
+
switch (applying) {
|
|
128
|
+
case `newValue`:
|
|
129
|
+
{
|
|
130
|
+
const provenance = update.to.length === 1 ? update.to[0] : update.to
|
|
131
|
+
claimWithinStore<any, any, any>(
|
|
132
|
+
store,
|
|
133
|
+
provenance,
|
|
134
|
+
update.key,
|
|
135
|
+
`exclusive`,
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
break
|
|
139
|
+
case `oldValue`:
|
|
140
|
+
{
|
|
141
|
+
const provenance =
|
|
142
|
+
update.from.length === 1 ? update.from[0] : update.from
|
|
143
|
+
claimWithinStore<any, any, any>(
|
|
144
|
+
store,
|
|
145
|
+
provenance,
|
|
146
|
+
update.key,
|
|
147
|
+
`exclusive`,
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
break
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -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
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AtomIOToken } from "atom.io"
|
|
2
|
+
|
|
3
|
+
import { newest } from "./lineage"
|
|
4
|
+
import { type Store, withdraw } from "./store"
|
|
5
|
+
import { isChildStore } from "./transaction"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
* Install the given tokens into the target store
|
|
10
|
+
* @param tokens - States, families, transactions, and timelines to install into the target store
|
|
11
|
+
* @param target - The store to install the tokens into
|
|
12
|
+
* @param source - The store to install the tokens from
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export function installIntoStore(
|
|
16
|
+
tokens: AtomIOToken[],
|
|
17
|
+
target: Store,
|
|
18
|
+
source: Store,
|
|
19
|
+
): void {
|
|
20
|
+
const sourceNewest = newest(source)
|
|
21
|
+
if (isChildStore(sourceNewest)) {
|
|
22
|
+
source.logger.error(
|
|
23
|
+
`❌`,
|
|
24
|
+
`transaction`,
|
|
25
|
+
sourceNewest.transactionMeta.update.key,
|
|
26
|
+
`could not install the following tokens into store "${target.config.name} from "${source.config.name}":`,
|
|
27
|
+
tokens,
|
|
28
|
+
`${sourceNewest.config.name} is undergoing a transaction.`,
|
|
29
|
+
)
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
const targetNewest = newest(target)
|
|
33
|
+
if (isChildStore(targetNewest)) {
|
|
34
|
+
target.logger.error(
|
|
35
|
+
`❌`,
|
|
36
|
+
`transaction`,
|
|
37
|
+
targetNewest.transactionMeta.update.key,
|
|
38
|
+
`could not install the following tokens into store "${target.config.name} from "${source.config.name}":`,
|
|
39
|
+
tokens,
|
|
40
|
+
`${targetNewest.config.name} is undergoing a transaction.`,
|
|
41
|
+
)
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
for (const token of tokens) {
|
|
45
|
+
const resource = withdraw(token, source)
|
|
46
|
+
resource.install(target)
|
|
47
|
+
}
|
|
48
|
+
}
|
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