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,191 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CtorToolkit,
|
|
3
|
-
getState,
|
|
4
|
-
MoleculeConstructor,
|
|
5
|
-
MoleculeCreationClassic,
|
|
6
|
-
MoleculeFamilyToken,
|
|
7
|
-
MoleculeKey,
|
|
8
|
-
MoleculeParams,
|
|
9
|
-
MoleculeToken,
|
|
10
|
-
ReadableFamilyToken,
|
|
11
|
-
setState,
|
|
12
|
-
} from "atom.io"
|
|
13
|
-
import { findRelations, getJoin, type JoinToken } from "atom.io/data"
|
|
14
|
-
import type { seekState } from "atom.io/immortal"
|
|
15
|
-
import { stringifyJson } from "atom.io/json"
|
|
16
|
-
|
|
17
|
-
import { arbitrary } from "../arbitrary"
|
|
18
|
-
import { disposeFromStore, seekInStore } from "../families"
|
|
19
|
-
import { getEnvironmentData } from "../get-environment-data"
|
|
20
|
-
import { getFromStore } from "../get-state"
|
|
21
|
-
import { eldest, newest } from "../lineage"
|
|
22
|
-
import { getJsonToken } from "../mutable"
|
|
23
|
-
import { setIntoStore } from "../set-state"
|
|
24
|
-
import type { Store } from "../store"
|
|
25
|
-
import { withdraw } from "../store"
|
|
26
|
-
import { actUponStore, isChildStore, isRootStore } from "../transaction"
|
|
27
|
-
import { growMoleculeInStore } from "./grow-molecule-in-store"
|
|
28
|
-
import { Molecule } from "./molecule-internal"
|
|
29
|
-
|
|
30
|
-
function capitalize<S extends string>(string: S): Capitalize<S> {
|
|
31
|
-
return (string[0].toUpperCase() + string.slice(1)) as Capitalize<S>
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function makeMoleculeInStore<M extends MoleculeConstructor>(
|
|
35
|
-
store: Store,
|
|
36
|
-
context: MoleculeToken<M> | MoleculeToken<M>[],
|
|
37
|
-
familyToken: MoleculeFamilyToken<M>,
|
|
38
|
-
key: MoleculeKey<M>,
|
|
39
|
-
...params: MoleculeParams<M>
|
|
40
|
-
): MoleculeToken<M> {
|
|
41
|
-
const rootStore = eldest(store)
|
|
42
|
-
const target = newest(store)
|
|
43
|
-
const stringKey = stringifyJson(key)
|
|
44
|
-
|
|
45
|
-
target.moleculeInProgress = stringKey
|
|
46
|
-
|
|
47
|
-
const contextArray = Array.isArray(context) ? context : [context]
|
|
48
|
-
const owners = contextArray.map<Molecule<M>>((ctx) => {
|
|
49
|
-
if (ctx instanceof Molecule) {
|
|
50
|
-
return ctx
|
|
51
|
-
}
|
|
52
|
-
const ctxStringKey = stringifyJson(ctx.key)
|
|
53
|
-
const molecule = store.molecules.get(ctxStringKey)
|
|
54
|
-
|
|
55
|
-
if (!molecule) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
`Molecule ${ctxStringKey} not found in store "${store.config.name}"`,
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
return molecule
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
const molecule = new Molecule(owners, key, familyToken)
|
|
64
|
-
target.molecules.set(stringKey, molecule)
|
|
65
|
-
for (const owner of owners) {
|
|
66
|
-
owner.below.set(molecule.stringKey, molecule)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const toolkit = {
|
|
70
|
-
get: ((...ps: Parameters<typeof getState>) =>
|
|
71
|
-
getFromStore(newest(rootStore), ...ps)) as typeof getState,
|
|
72
|
-
set: ((...ps: Parameters<typeof setState>) => {
|
|
73
|
-
setIntoStore(newest(rootStore), ...ps)
|
|
74
|
-
}) as typeof setState,
|
|
75
|
-
seek: ((t, k) => seekInStore(newest(rootStore), t, k)) as typeof seekState,
|
|
76
|
-
json: (t) => getJsonToken(newest(rootStore), t),
|
|
77
|
-
run: (t, i = arbitrary()) => actUponStore(t, i, newest(store)),
|
|
78
|
-
make: (ctx, f, k, ...args) =>
|
|
79
|
-
makeMoleculeInStore(newest(rootStore), ctx, f, k, ...args),
|
|
80
|
-
dispose: (t) => {
|
|
81
|
-
disposeFromStore(newest(rootStore), t)
|
|
82
|
-
},
|
|
83
|
-
env: () => getEnvironmentData(newest(rootStore)),
|
|
84
|
-
bond: ((
|
|
85
|
-
token:
|
|
86
|
-
| JoinToken<any, any, any, any, any, any>
|
|
87
|
-
| ReadableFamilyToken<any, any>,
|
|
88
|
-
maybeRole,
|
|
89
|
-
) => {
|
|
90
|
-
if (token.type === `join`) {
|
|
91
|
-
const { as: role } = maybeRole
|
|
92
|
-
const join = getJoin(token, rootStore)
|
|
93
|
-
join.molecules.set(stringKey, molecule)
|
|
94
|
-
molecule.joins.set(token.key, join)
|
|
95
|
-
const unsubFromFamily = family.subject.subscribe(
|
|
96
|
-
`join:${token.key}-${stringKey}`,
|
|
97
|
-
(event) => {
|
|
98
|
-
if (event.type === `molecule_disposal`) {
|
|
99
|
-
if (stringifyJson(event.token.key) === stringKey) {
|
|
100
|
-
unsubFromFamily()
|
|
101
|
-
join.molecules.delete(stringKey)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
if (role === null) {
|
|
108
|
-
return
|
|
109
|
-
}
|
|
110
|
-
const otherRole = token.a === role ? token.b : token.a
|
|
111
|
-
const relations = findRelations(token, key)
|
|
112
|
-
const relatedKeys =
|
|
113
|
-
relations[
|
|
114
|
-
`${otherRole}KeysOf${capitalize(role)}` as keyof typeof relations
|
|
115
|
-
]
|
|
116
|
-
const relatedEntries =
|
|
117
|
-
relations[
|
|
118
|
-
`${otherRole}EntriesOf${capitalize(role)}` as keyof typeof relations
|
|
119
|
-
]
|
|
120
|
-
let tokens = { relatedKeys }
|
|
121
|
-
if (relatedEntries) {
|
|
122
|
-
tokens = Object.assign(tokens, { relatedEntries })
|
|
123
|
-
}
|
|
124
|
-
return tokens
|
|
125
|
-
}
|
|
126
|
-
return growMoleculeInStore(
|
|
127
|
-
molecule,
|
|
128
|
-
withdraw(token, rootStore),
|
|
129
|
-
newest(rootStore),
|
|
130
|
-
)
|
|
131
|
-
}) as CtorToolkit<MoleculeKey<M>>[`bond`],
|
|
132
|
-
claim: (below, options) => {
|
|
133
|
-
const { exclusive } = options
|
|
134
|
-
const belowMolecule = newest(store).molecules.get(stringifyJson(below.key))
|
|
135
|
-
if (belowMolecule) {
|
|
136
|
-
if (exclusive) {
|
|
137
|
-
for (const value of belowMolecule.above.values()) {
|
|
138
|
-
value.below.delete(belowMolecule.stringKey)
|
|
139
|
-
}
|
|
140
|
-
belowMolecule.above.clear()
|
|
141
|
-
belowMolecule.above.set(molecule.stringKey, molecule)
|
|
142
|
-
molecule.below.set(belowMolecule.stringKey, belowMolecule)
|
|
143
|
-
} else {
|
|
144
|
-
belowMolecule.above.set(molecule.stringKey, molecule)
|
|
145
|
-
molecule.below.set(belowMolecule.stringKey, belowMolecule)
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
spawn: (f: MoleculeFamilyToken<any>, k: any, ...p: any[]) =>
|
|
150
|
-
makeMoleculeInStore(
|
|
151
|
-
newest(store),
|
|
152
|
-
[molecule],
|
|
153
|
-
withdraw(f, store),
|
|
154
|
-
k,
|
|
155
|
-
...p,
|
|
156
|
-
),
|
|
157
|
-
} satisfies CtorToolkit<MoleculeKey<M>>
|
|
158
|
-
|
|
159
|
-
const family = withdraw(familyToken, store)
|
|
160
|
-
const Constructor = family.new
|
|
161
|
-
|
|
162
|
-
molecule.instance = new Constructor(toolkit, key, ...params)
|
|
163
|
-
|
|
164
|
-
const token = {
|
|
165
|
-
type: `molecule`,
|
|
166
|
-
key,
|
|
167
|
-
family: familyToken,
|
|
168
|
-
} as const satisfies MoleculeToken<M>
|
|
169
|
-
|
|
170
|
-
const update = {
|
|
171
|
-
type: `molecule_creation`,
|
|
172
|
-
subType: `classic`,
|
|
173
|
-
token,
|
|
174
|
-
family: familyToken,
|
|
175
|
-
context: contextArray,
|
|
176
|
-
params,
|
|
177
|
-
} satisfies MoleculeCreationClassic<M>
|
|
178
|
-
|
|
179
|
-
if (isRootStore(target)) {
|
|
180
|
-
family.subject.next(update)
|
|
181
|
-
} else if (
|
|
182
|
-
isChildStore(target) &&
|
|
183
|
-
target.on.transactionApplying.state === null
|
|
184
|
-
) {
|
|
185
|
-
target.transactionMeta.update.updates.push(update)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
target.moleculeInProgress = null
|
|
189
|
-
|
|
190
|
-
return token
|
|
191
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
MoleculeConstructor,
|
|
3
|
-
MoleculeFamilyToken,
|
|
4
|
-
MoleculeKey,
|
|
5
|
-
MoleculeToken,
|
|
6
|
-
ReadableToken,
|
|
7
|
-
StateCreation,
|
|
8
|
-
StateDisposal,
|
|
9
|
-
} from "atom.io"
|
|
10
|
-
import type { Join } from "atom.io/data"
|
|
11
|
-
import { stringifyJson } from "atom.io/json"
|
|
12
|
-
|
|
13
|
-
import { Subject } from "../subject"
|
|
14
|
-
|
|
15
|
-
export class Molecule<M extends MoleculeConstructor>
|
|
16
|
-
implements MoleculeToken<M>
|
|
17
|
-
{
|
|
18
|
-
public readonly type = `molecule`
|
|
19
|
-
public stringKey: string
|
|
20
|
-
public family?: MoleculeFamilyToken<M>
|
|
21
|
-
public _dependsOn: `all` | `any`
|
|
22
|
-
public get dependsOn(): `all` | `any` {
|
|
23
|
-
if (this.family) {
|
|
24
|
-
return this.family.dependsOn
|
|
25
|
-
}
|
|
26
|
-
return this._dependsOn
|
|
27
|
-
}
|
|
28
|
-
public readonly subject = new Subject<
|
|
29
|
-
StateCreation<any> | StateDisposal<any>
|
|
30
|
-
>()
|
|
31
|
-
public tokens = new Map<string, ReadableToken<any>>()
|
|
32
|
-
public above = new Map<string, Molecule<any>>()
|
|
33
|
-
public below = new Map<string, Molecule<any>>()
|
|
34
|
-
public joins = new Map<string, Join<any, any, any, any, any, any>>()
|
|
35
|
-
public instance: InstanceType<M>
|
|
36
|
-
public constructor(
|
|
37
|
-
ctx: Molecule<any>[] | undefined,
|
|
38
|
-
public readonly key: MoleculeKey<M>,
|
|
39
|
-
family?: MoleculeFamilyToken<M>,
|
|
40
|
-
) {
|
|
41
|
-
this.stringKey = stringifyJson(key)
|
|
42
|
-
if (family) {
|
|
43
|
-
this.family = family
|
|
44
|
-
this._dependsOn = family.dependsOn
|
|
45
|
-
}
|
|
46
|
-
if (ctx) {
|
|
47
|
-
for (const molecule of ctx) {
|
|
48
|
-
this.above.set(molecule.stringKey, molecule)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|