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
package/data/src/join.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
disposeState,
|
|
2
|
+
CompoundTypedKey,
|
|
4
3
|
getState,
|
|
5
|
-
|
|
4
|
+
Hierarchy,
|
|
6
5
|
MutableAtomFamilyToken,
|
|
7
6
|
Read,
|
|
8
|
-
ReadableFamilyToken,
|
|
9
|
-
ReadableToken,
|
|
10
7
|
ReadonlySelectorFamilyToken,
|
|
11
8
|
ReadonlySelectorToken,
|
|
12
9
|
RegularAtomFamilyToken,
|
|
13
10
|
setState,
|
|
14
11
|
SetterToolkit,
|
|
12
|
+
SingularTypedKey,
|
|
15
13
|
Write,
|
|
16
14
|
} from "atom.io"
|
|
15
|
+
import { Anarchy, Realm } from "atom.io"
|
|
17
16
|
import type { findState } from "atom.io/ephemeral"
|
|
18
17
|
import type { seekState } from "atom.io/immortal"
|
|
19
18
|
import type {
|
|
@@ -22,31 +21,25 @@ import type {
|
|
|
22
21
|
JunctionEntriesBase,
|
|
23
22
|
JunctionSchemaBase,
|
|
24
23
|
Molecule,
|
|
24
|
+
Refinement,
|
|
25
25
|
Store,
|
|
26
26
|
} from "atom.io/internal"
|
|
27
27
|
import {
|
|
28
|
-
createMoleculeFamily,
|
|
29
28
|
createMutableAtomFamily,
|
|
30
29
|
createReadonlySelectorFamily,
|
|
31
30
|
createRegularAtomFamily,
|
|
32
|
-
|
|
31
|
+
findInStore,
|
|
33
32
|
getFromStore,
|
|
34
33
|
getJsonFamily,
|
|
35
34
|
getJsonToken,
|
|
36
|
-
growMoleculeInStore,
|
|
37
35
|
IMPLICIT,
|
|
38
|
-
initFamilyMemberInStore,
|
|
39
36
|
isChildStore,
|
|
40
37
|
Junction,
|
|
41
|
-
makeMoleculeInStore,
|
|
42
38
|
newest,
|
|
43
|
-
NotFoundError,
|
|
44
39
|
seekInStore,
|
|
45
40
|
setIntoStore,
|
|
46
|
-
withdraw,
|
|
47
41
|
} from "atom.io/internal"
|
|
48
|
-
import type {
|
|
49
|
-
import type { Json } from "atom.io/json"
|
|
42
|
+
import type { Canonical, Json, stringified } from "atom.io/json"
|
|
50
43
|
import { stringifyJson } from "atom.io/json"
|
|
51
44
|
import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
52
45
|
import { SetRTX } from "atom.io/transceivers/set-rtx"
|
|
@@ -151,6 +144,23 @@ export type JoinStateFamilies<
|
|
|
151
144
|
}
|
|
152
145
|
: never
|
|
153
146
|
|
|
147
|
+
export type JoinHierarchy<
|
|
148
|
+
AType extends SingularTypedKey,
|
|
149
|
+
BType extends SingularTypedKey,
|
|
150
|
+
> = Hierarchy<
|
|
151
|
+
[
|
|
152
|
+
{
|
|
153
|
+
above: `root`
|
|
154
|
+
below: [AType, BType]
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
above: [AType, BType]
|
|
158
|
+
style: `all`
|
|
159
|
+
below: CompoundTypedKey<`content`, AType, BType>
|
|
160
|
+
},
|
|
161
|
+
]
|
|
162
|
+
>
|
|
163
|
+
|
|
154
164
|
export class Join<
|
|
155
165
|
const ASide extends string,
|
|
156
166
|
const AType extends string,
|
|
@@ -158,11 +168,15 @@ export class Join<
|
|
|
158
168
|
const BType extends string,
|
|
159
169
|
const Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
160
170
|
const Content extends Json.Object | null = null,
|
|
171
|
+
const ContentKey extends CompoundTypedKey<
|
|
172
|
+
`content`,
|
|
173
|
+
ASide,
|
|
174
|
+
BSide
|
|
175
|
+
> = CompoundTypedKey<`content`, ASide, BSide>,
|
|
161
176
|
> {
|
|
162
|
-
private
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
public retrieve: typeof findState
|
|
177
|
+
private toolkit: SetterToolkit
|
|
178
|
+
public options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>
|
|
179
|
+
public defaultContent: Content | undefined
|
|
166
180
|
public molecules: Map<string, Molecule<any>> = new Map()
|
|
167
181
|
public relations: Junction<ASide, AType, BSide, BType, Content>
|
|
168
182
|
public states: JoinStateFamilies<
|
|
@@ -174,14 +188,14 @@ export class Join<
|
|
|
174
188
|
Content
|
|
175
189
|
>
|
|
176
190
|
public core: {
|
|
177
|
-
|
|
191
|
+
relatedKeysAtoms: MutableAtomFamilyToken<
|
|
178
192
|
SetRTX<string>,
|
|
179
193
|
SetRTXJson<string>,
|
|
180
194
|
string
|
|
181
195
|
>
|
|
182
196
|
}
|
|
183
197
|
public transact(
|
|
184
|
-
toolkit: SetterToolkit
|
|
198
|
+
toolkit: SetterToolkit,
|
|
185
199
|
run: (join: Join<ASide, AType, BSide, BType, Cardinality, Content>) => void,
|
|
186
200
|
): void {
|
|
187
201
|
const originalToolkit = this.toolkit
|
|
@@ -191,27 +205,9 @@ export class Join<
|
|
|
191
205
|
}
|
|
192
206
|
|
|
193
207
|
public store: Store
|
|
194
|
-
public
|
|
195
|
-
string,
|
|
196
|
-
Join<ASide, AType, BSide, BType, Cardinality, Content>
|
|
197
|
-
>
|
|
198
|
-
public [Symbol.dispose](): void {
|
|
199
|
-
this.alternates.delete(this.store.config.name)
|
|
200
|
-
}
|
|
208
|
+
public realm: Anarchy
|
|
201
209
|
|
|
202
|
-
public
|
|
203
|
-
store: Store,
|
|
204
|
-
): Join<ASide, AType, BSide, BType, Cardinality, Content> {
|
|
205
|
-
const key = store.config.name
|
|
206
|
-
const alternate = this.alternates.get(key)
|
|
207
|
-
if (alternate) {
|
|
208
|
-
return alternate
|
|
209
|
-
}
|
|
210
|
-
const join = new Join(this.options, this.defaultContent, store)
|
|
211
|
-
this.alternates.set(key, join)
|
|
212
|
-
join.alternates = this.alternates
|
|
213
|
-
return join
|
|
214
|
-
}
|
|
210
|
+
public [Symbol.dispose](): void {}
|
|
215
211
|
|
|
216
212
|
public constructor(
|
|
217
213
|
options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
@@ -221,44 +217,25 @@ export class Join<
|
|
|
221
217
|
type AnyKey = AType & BType
|
|
222
218
|
|
|
223
219
|
this.store = store
|
|
220
|
+
this.realm = new Anarchy(store)
|
|
224
221
|
this.options = options
|
|
225
222
|
this.defaultContent = defaultContent
|
|
226
|
-
this.alternates = new Map()
|
|
227
|
-
this.alternates.set(store.config.name, this)
|
|
228
223
|
|
|
229
224
|
this.store.miscResources.set(`join:${options.key}`, this)
|
|
230
225
|
|
|
231
|
-
this.
|
|
232
|
-
|
|
233
|
-
key: Json.Serializable,
|
|
234
|
-
): ReadableToken<any> => {
|
|
235
|
-
const maybeToken = this.toolkit.seek(token, key)
|
|
236
|
-
if (maybeToken) {
|
|
237
|
-
return maybeToken
|
|
238
|
-
}
|
|
239
|
-
const molecule = this.store.molecules.get(stringifyJson(key))
|
|
240
|
-
if (molecule) {
|
|
241
|
-
const family = withdraw(token, store)
|
|
242
|
-
return growMoleculeInStore(molecule, family, store)
|
|
243
|
-
}
|
|
244
|
-
if (store.config.lifespan === `immortal`) {
|
|
245
|
-
throw new NotFoundError(token, key, store)
|
|
246
|
-
}
|
|
247
|
-
return initFamilyMemberInStore(store, token, key)
|
|
248
|
-
}) as typeof findState
|
|
226
|
+
this.realm.allocate(`root`, options.key)
|
|
227
|
+
|
|
249
228
|
this.toolkit = {
|
|
250
229
|
get: ((...ps: Parameters<typeof getState>) =>
|
|
251
230
|
getFromStore(store, ...ps)) as typeof getState,
|
|
252
231
|
set: ((...ps: Parameters<typeof setState>) => {
|
|
253
232
|
setIntoStore(store, ...ps)
|
|
254
233
|
}) as typeof setState,
|
|
255
|
-
find:
|
|
234
|
+
find: ((...ps: Parameters<typeof findState>) =>
|
|
235
|
+
findInStore(store, ...ps)) as typeof findState,
|
|
256
236
|
seek: ((...ps: Parameters<typeof seekState>) =>
|
|
257
237
|
seekInStore(store, ...ps)) as typeof seekState,
|
|
258
238
|
json: (token) => getJsonToken(store, token),
|
|
259
|
-
dispose: ((...ps: Parameters<typeof disposeState>) => {
|
|
260
|
-
disposeFromStore(store, ...ps)
|
|
261
|
-
}) as typeof disposeState,
|
|
262
239
|
}
|
|
263
240
|
|
|
264
241
|
const aSide: ASide = options.between[0]
|
|
@@ -278,62 +255,47 @@ export class Join<
|
|
|
278
255
|
},
|
|
279
256
|
[`join`, `relations`],
|
|
280
257
|
)
|
|
281
|
-
this.core = {
|
|
258
|
+
this.core = { relatedKeysAtoms }
|
|
282
259
|
const getRelatedKeys: Read<
|
|
283
260
|
(key: string) => SetRTX<AType> | SetRTX<BType>
|
|
284
|
-
> = ({ get }, key) => get(
|
|
261
|
+
> = ({ get }, key) => get(relatedKeysAtoms, key) as any
|
|
285
262
|
const addRelation: Write<(a: string, b: string) => void> = (
|
|
286
|
-
|
|
263
|
+
{ set },
|
|
287
264
|
a,
|
|
288
265
|
b,
|
|
289
266
|
) => {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
set(
|
|
294
|
-
set(
|
|
267
|
+
if (!this.store.molecules.has(stringifyJson(a))) {
|
|
268
|
+
this.realm.allocate(options.key, a)
|
|
269
|
+
}
|
|
270
|
+
set(relatedKeysAtoms, a, (aKeys) => aKeys.add(b))
|
|
271
|
+
set(relatedKeysAtoms, b, (bKeys) => bKeys.add(a))
|
|
295
272
|
}
|
|
296
273
|
const deleteRelation: Write<(a: string, b: string) => void> = (
|
|
297
|
-
|
|
274
|
+
{ set },
|
|
298
275
|
a,
|
|
299
276
|
b,
|
|
300
277
|
) => {
|
|
301
|
-
|
|
302
|
-
const aKeysState = this.retrieve(relatedKeysAtoms, a)
|
|
303
|
-
const bKeysState = this.retrieve(relatedKeysAtoms, b)
|
|
304
|
-
let stringA: string | undefined
|
|
305
|
-
let stringB: string | undefined
|
|
306
|
-
set(aKeysState, (aKeys) => {
|
|
278
|
+
set(relatedKeysAtoms, a, (aKeys) => {
|
|
307
279
|
aKeys.delete(b)
|
|
308
|
-
if (aKeys.size === 0) {
|
|
309
|
-
stringA = `"${a}"`
|
|
310
|
-
}
|
|
311
280
|
return aKeys
|
|
312
281
|
})
|
|
313
|
-
set(
|
|
282
|
+
set(relatedKeysAtoms, b, (bKeys) => {
|
|
314
283
|
bKeys.delete(a)
|
|
315
|
-
if (bKeys.size === 0) {
|
|
316
|
-
stringB = `"${b}"`
|
|
317
|
-
}
|
|
318
284
|
return bKeys
|
|
319
285
|
})
|
|
320
286
|
}
|
|
321
287
|
const replaceRelationsSafely: Write<
|
|
322
288
|
(a: string, newRelationsOfA: string[]) => void
|
|
323
289
|
> = (toolkit, a, newRelationsOfA) => {
|
|
324
|
-
const { get, set } = toolkit
|
|
325
|
-
const relationsOfAState =
|
|
290
|
+
const { find, get, set } = toolkit
|
|
291
|
+
const relationsOfAState = find(relatedKeysAtoms, a)
|
|
326
292
|
const currentRelationsOfA = get(relationsOfAState)
|
|
327
293
|
for (const currentRelationB of currentRelationsOfA) {
|
|
328
294
|
const remainsRelated = newRelationsOfA.includes(currentRelationB)
|
|
329
295
|
if (remainsRelated) {
|
|
330
296
|
continue
|
|
331
297
|
}
|
|
332
|
-
|
|
333
|
-
relatedKeysAtoms,
|
|
334
|
-
currentRelationB,
|
|
335
|
-
)
|
|
336
|
-
set(relationsOfBState, (relationsOfB) => {
|
|
298
|
+
set(relatedKeysAtoms, currentRelationB, (relationsOfB) => {
|
|
337
299
|
relationsOfB.delete(a)
|
|
338
300
|
return relationsOfB
|
|
339
301
|
})
|
|
@@ -382,8 +344,7 @@ export class Join<
|
|
|
382
344
|
(a: string, newRelationsOfA: string[]) => void
|
|
383
345
|
> = (toolkit, a, newRelationsOfA) => {
|
|
384
346
|
const { set } = toolkit
|
|
385
|
-
|
|
386
|
-
set(relationsOfAState, (relationsOfA) => {
|
|
347
|
+
set(relatedKeysAtoms, a, (relationsOfA) => {
|
|
387
348
|
relationsOfA.transaction((nextRelationsOfA) => {
|
|
388
349
|
for (const newRelationB of newRelationsOfA) {
|
|
389
350
|
nextRelationsOfA.add(newRelationB)
|
|
@@ -393,8 +354,7 @@ export class Join<
|
|
|
393
354
|
return relationsOfA
|
|
394
355
|
})
|
|
395
356
|
for (const newRelationB of newRelationsOfA) {
|
|
396
|
-
|
|
397
|
-
set(newRelationsBState, (newRelationsB) => {
|
|
357
|
+
set(relatedKeysAtoms, newRelationB, (newRelationsB) => {
|
|
398
358
|
newRelationsB.add(a)
|
|
399
359
|
return newRelationsB
|
|
400
360
|
})
|
|
@@ -408,6 +368,14 @@ export class Join<
|
|
|
408
368
|
const baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {
|
|
409
369
|
getRelatedKeys: (key) => getRelatedKeys(this.toolkit, key),
|
|
410
370
|
addRelation: (a, b) => {
|
|
371
|
+
this.store.moleculeJoins.set(
|
|
372
|
+
a as stringified<Canonical> /* 💥 RECONCILE */,
|
|
373
|
+
options.key,
|
|
374
|
+
)
|
|
375
|
+
this.store.moleculeJoins.set(
|
|
376
|
+
b as stringified<Canonical> /* 💥 RECONCILE */,
|
|
377
|
+
options.key,
|
|
378
|
+
)
|
|
411
379
|
addRelation(this.toolkit, a, b)
|
|
412
380
|
},
|
|
413
381
|
deleteRelation: (a, b) => {
|
|
@@ -423,13 +391,9 @@ export class Join<
|
|
|
423
391
|
}
|
|
424
392
|
let externalStore: ExternalStoreConfiguration<Content>
|
|
425
393
|
let contentAtoms: RegularAtomFamilyToken<Content, string>
|
|
426
|
-
|
|
427
|
-
new (
|
|
428
|
-
..._: any[]
|
|
429
|
-
) => { key: string }
|
|
430
|
-
>
|
|
394
|
+
|
|
431
395
|
if (defaultContent) {
|
|
432
|
-
contentAtoms = createRegularAtomFamily<Content,
|
|
396
|
+
contentAtoms = createRegularAtomFamily<Content, ContentKey>(
|
|
433
397
|
store,
|
|
434
398
|
{
|
|
435
399
|
key: `${options.key}/content`,
|
|
@@ -437,44 +401,27 @@ export class Join<
|
|
|
437
401
|
},
|
|
438
402
|
[`join`, `content`],
|
|
439
403
|
)
|
|
440
|
-
|
|
441
|
-
key: `${options.key}/content-molecules`,
|
|
442
|
-
new: class ContentMolecule {
|
|
443
|
-
public constructor(
|
|
444
|
-
_: CtorToolkit<string>,
|
|
445
|
-
public key: string,
|
|
446
|
-
) {}
|
|
447
|
-
},
|
|
448
|
-
})
|
|
404
|
+
|
|
449
405
|
const getContent: Read<(key: string) => Content | null> = ({ get }, key) =>
|
|
450
|
-
get(
|
|
406
|
+
get(contentAtoms, key)
|
|
451
407
|
const setContent: Write<(key: string, content: Content) => void> = (
|
|
452
408
|
{ set },
|
|
453
409
|
key,
|
|
454
410
|
content,
|
|
455
411
|
) => {
|
|
456
|
-
set(
|
|
457
|
-
}
|
|
458
|
-
const deleteContent: Write<(compositeKey: string) => void> = (
|
|
459
|
-
_,
|
|
460
|
-
compositeKey,
|
|
461
|
-
) => {
|
|
462
|
-
const contentMolecule = store.molecules.get(`"${compositeKey}"`)
|
|
463
|
-
if (contentMolecule) {
|
|
464
|
-
this.toolkit.dispose(contentMolecule)
|
|
465
|
-
this.molecules.delete(`"${compositeKey}"`)
|
|
466
|
-
}
|
|
412
|
+
set(contentAtoms, key, content)
|
|
467
413
|
}
|
|
414
|
+
|
|
468
415
|
const externalStoreWithContentConfiguration = {
|
|
469
|
-
getContent: (contentKey:
|
|
416
|
+
getContent: (contentKey: ContentKey) => {
|
|
470
417
|
const content = getContent(this.toolkit, contentKey)
|
|
471
418
|
return content
|
|
472
419
|
},
|
|
473
|
-
setContent: (contentKey:
|
|
420
|
+
setContent: (contentKey: ContentKey, content: Content) => {
|
|
474
421
|
setContent(this.toolkit, contentKey, content)
|
|
475
422
|
},
|
|
476
|
-
deleteContent: (contentKey:
|
|
477
|
-
|
|
423
|
+
deleteContent: (contentKey: ContentKey) => {
|
|
424
|
+
this.realm.deallocate(contentKey)
|
|
478
425
|
},
|
|
479
426
|
}
|
|
480
427
|
externalStore = Object.assign(
|
|
@@ -492,30 +439,26 @@ export class Join<
|
|
|
492
439
|
isAType: options.isAType,
|
|
493
440
|
isBType: options.isBType,
|
|
494
441
|
makeContentKey: (...args) => {
|
|
442
|
+
const [a, b] = args
|
|
495
443
|
const sorted = args.sort()
|
|
496
444
|
const compositeKey = `${sorted[0]}:${sorted[1]}`
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
)
|
|
500
|
-
|
|
501
|
-
const target = newest(store)
|
|
502
|
-
const moleculeToken = makeMoleculeInStore(
|
|
503
|
-
target,
|
|
504
|
-
[m0, m1],
|
|
505
|
-
contentMolecules,
|
|
506
|
-
compositeKey,
|
|
507
|
-
)
|
|
508
|
-
this.molecules.set(
|
|
509
|
-
`"${compositeKey}"`,
|
|
510
|
-
withdraw(moleculeToken, target),
|
|
511
|
-
)
|
|
445
|
+
const aMolecule = store.molecules.get(stringifyJson(a))
|
|
446
|
+
const bMolecule = store.molecules.get(stringifyJson(b))
|
|
447
|
+
if (!aMolecule) {
|
|
448
|
+
this.realm.allocate(options.key, a)
|
|
512
449
|
}
|
|
450
|
+
if (!bMolecule) {
|
|
451
|
+
this.realm.allocate(options.key, b)
|
|
452
|
+
}
|
|
453
|
+
this.realm.allocate(a, compositeKey, `all`)
|
|
454
|
+
this.realm.claim(b, compositeKey)
|
|
455
|
+
this.store.moleculeJoins.set(compositeKey, options.key)
|
|
513
456
|
return compositeKey
|
|
514
457
|
},
|
|
515
458
|
},
|
|
516
459
|
)
|
|
517
460
|
|
|
518
|
-
const
|
|
461
|
+
const createSingleKeySelectorFamily = () =>
|
|
519
462
|
createReadonlySelectorFamily<string | null, string>(
|
|
520
463
|
store,
|
|
521
464
|
{
|
|
@@ -523,8 +466,7 @@ export class Join<
|
|
|
523
466
|
get:
|
|
524
467
|
(key) =>
|
|
525
468
|
({ get }) => {
|
|
526
|
-
const
|
|
527
|
-
const relatedKeys = get(relatedKeysState)
|
|
469
|
+
const relatedKeys = get(relatedKeysAtoms, key)
|
|
528
470
|
for (const relatedKey of relatedKeys) {
|
|
529
471
|
return relatedKey
|
|
530
472
|
}
|
|
@@ -533,7 +475,7 @@ export class Join<
|
|
|
533
475
|
},
|
|
534
476
|
[`join`, `keys`],
|
|
535
477
|
)
|
|
536
|
-
const
|
|
478
|
+
const getMultipleKeySelectorFamily = () => {
|
|
537
479
|
return createReadonlySelectorFamily<string[], string>(
|
|
538
480
|
store,
|
|
539
481
|
{
|
|
@@ -542,15 +484,14 @@ export class Join<
|
|
|
542
484
|
(key) =>
|
|
543
485
|
({ get }) => {
|
|
544
486
|
const jsonFamily = getJsonFamily(relatedKeysAtoms, store)
|
|
545
|
-
const
|
|
546
|
-
const json = get(jsonState)
|
|
487
|
+
const json = get(jsonFamily, key)
|
|
547
488
|
return json.members
|
|
548
489
|
},
|
|
549
490
|
},
|
|
550
491
|
[`join`, `keys`],
|
|
551
492
|
)
|
|
552
493
|
}
|
|
553
|
-
const
|
|
494
|
+
const createSingleEntrySelectorFamily = () =>
|
|
554
495
|
createReadonlySelectorFamily<[string, Content] | null, string>(
|
|
555
496
|
store,
|
|
556
497
|
{
|
|
@@ -558,16 +499,14 @@ export class Join<
|
|
|
558
499
|
get:
|
|
559
500
|
(x) =>
|
|
560
501
|
({ get }) => {
|
|
561
|
-
const
|
|
562
|
-
const relatedKeys = get(relatedKeysState)
|
|
502
|
+
const relatedKeys = get(relatedKeysAtoms, x)
|
|
563
503
|
for (const y of relatedKeys) {
|
|
564
504
|
let a = relations.isAType?.(x) ? x : undefined
|
|
565
505
|
let b = a === undefined ? (x as BType) : undefined
|
|
566
506
|
a ??= y as AType
|
|
567
507
|
b ??= y as BType
|
|
568
508
|
const contentKey = relations.makeContentKey(a, b)
|
|
569
|
-
const
|
|
570
|
-
const content = get(contentState)
|
|
509
|
+
const content = get(contentAtoms, contentKey)
|
|
571
510
|
return [y, content]
|
|
572
511
|
}
|
|
573
512
|
return null
|
|
@@ -575,7 +514,7 @@ export class Join<
|
|
|
575
514
|
},
|
|
576
515
|
[`join`, `entries`],
|
|
577
516
|
)
|
|
578
|
-
const
|
|
517
|
+
const getMultipleEntrySelectorFamily = () =>
|
|
579
518
|
createReadonlySelectorFamily<[string, Content][], string>(
|
|
580
519
|
store,
|
|
581
520
|
{
|
|
@@ -584,16 +523,14 @@ export class Join<
|
|
|
584
523
|
(x) =>
|
|
585
524
|
({ get }) => {
|
|
586
525
|
const jsonFamily = getJsonFamily(relatedKeysAtoms, store)
|
|
587
|
-
const
|
|
588
|
-
const json = get(jsonState)
|
|
526
|
+
const json = get(jsonFamily, x)
|
|
589
527
|
return json.members.map((y) => {
|
|
590
528
|
let a = relations.isAType?.(x) ? x : undefined
|
|
591
529
|
let b = a === undefined ? (x as BType) : undefined
|
|
592
530
|
a ??= y as AType
|
|
593
531
|
b ??= y as BType
|
|
594
532
|
const contentKey = relations.makeContentKey(a, b)
|
|
595
|
-
const
|
|
596
|
-
const content = get(contentState)
|
|
533
|
+
const content = get(contentAtoms, contentKey)
|
|
597
534
|
return [y, content]
|
|
598
535
|
})
|
|
599
536
|
},
|
|
@@ -603,12 +540,12 @@ export class Join<
|
|
|
603
540
|
|
|
604
541
|
switch (options.cardinality) {
|
|
605
542
|
case `1:1`: {
|
|
606
|
-
const
|
|
543
|
+
const singleRelatedKeySelectors = createSingleKeySelectorFamily()
|
|
607
544
|
const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}` as const
|
|
608
545
|
const stateKeyB = `${bSide}KeyOf${capitalize(aSide)}` as const
|
|
609
546
|
const baseStates = {
|
|
610
|
-
[stateKeyA]:
|
|
611
|
-
[stateKeyB]:
|
|
547
|
+
[stateKeyA]: singleRelatedKeySelectors,
|
|
548
|
+
[stateKeyB]: singleRelatedKeySelectors,
|
|
612
549
|
} as JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>
|
|
613
550
|
let states: JoinStateFamilies<
|
|
614
551
|
ASide,
|
|
@@ -619,12 +556,12 @@ export class Join<
|
|
|
619
556
|
Content
|
|
620
557
|
>
|
|
621
558
|
if (defaultContent) {
|
|
622
|
-
const
|
|
559
|
+
const singleEntrySelectors = createSingleEntrySelectorFamily()
|
|
623
560
|
const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}` as const
|
|
624
561
|
const entriesStateKeyB = `${bSide}EntryOf${capitalize(aSide)}` as const
|
|
625
562
|
const contentStates = {
|
|
626
|
-
[entriesStateKeyA]:
|
|
627
|
-
[entriesStateKeyB]:
|
|
563
|
+
[entriesStateKeyA]: singleEntrySelectors,
|
|
564
|
+
[entriesStateKeyB]: singleEntrySelectors,
|
|
628
565
|
}
|
|
629
566
|
states = Object.assign(baseStates, contentStates)
|
|
630
567
|
} else {
|
|
@@ -635,13 +572,13 @@ export class Join<
|
|
|
635
572
|
break
|
|
636
573
|
}
|
|
637
574
|
case `1:n`: {
|
|
638
|
-
const
|
|
639
|
-
const
|
|
575
|
+
const singleRelatedKeySelectors = createSingleKeySelectorFamily()
|
|
576
|
+
const multipleRelatedKeysSelectors = getMultipleKeySelectorFamily()
|
|
640
577
|
const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}` as const
|
|
641
578
|
const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}` as const
|
|
642
579
|
const baseStates = {
|
|
643
|
-
[stateKeyA]:
|
|
644
|
-
[stateKeyB]:
|
|
580
|
+
[stateKeyA]: singleRelatedKeySelectors,
|
|
581
|
+
[stateKeyB]: multipleRelatedKeysSelectors,
|
|
645
582
|
} as JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>
|
|
646
583
|
let states: JoinStateFamilies<
|
|
647
584
|
ASide,
|
|
@@ -652,15 +589,16 @@ export class Join<
|
|
|
652
589
|
Content
|
|
653
590
|
>
|
|
654
591
|
if (defaultContent) {
|
|
655
|
-
const
|
|
656
|
-
const
|
|
592
|
+
const singleRelatedEntrySelectors = createSingleEntrySelectorFamily()
|
|
593
|
+
const multipleRelatedEntriesSelectors =
|
|
594
|
+
getMultipleEntrySelectorFamily()
|
|
657
595
|
const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}` as const
|
|
658
596
|
const entriesStateKeyB = `${bSide}EntriesOf${capitalize(
|
|
659
597
|
aSide,
|
|
660
598
|
)}` as const
|
|
661
599
|
const contentStates = {
|
|
662
|
-
[entriesStateKeyA]:
|
|
663
|
-
[entriesStateKeyB]:
|
|
600
|
+
[entriesStateKeyA]: singleRelatedEntrySelectors,
|
|
601
|
+
[entriesStateKeyB]: multipleRelatedEntriesSelectors,
|
|
664
602
|
}
|
|
665
603
|
states = Object.assign(baseStates, contentStates)
|
|
666
604
|
} else {
|
|
@@ -671,12 +609,12 @@ export class Join<
|
|
|
671
609
|
break
|
|
672
610
|
}
|
|
673
611
|
default: {
|
|
674
|
-
const
|
|
612
|
+
const multipleRelatedKeysSelectors = getMultipleKeySelectorFamily()
|
|
675
613
|
const stateKeyA = `${aSide}KeysOf${capitalize(bSide)}` as const
|
|
676
614
|
const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}` as const
|
|
677
615
|
const baseStates = {
|
|
678
|
-
[stateKeyA]:
|
|
679
|
-
[stateKeyB]:
|
|
616
|
+
[stateKeyA]: multipleRelatedKeysSelectors,
|
|
617
|
+
[stateKeyB]: multipleRelatedKeysSelectors,
|
|
680
618
|
} as JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>
|
|
681
619
|
let states: JoinStateFamilies<
|
|
682
620
|
ASide,
|
|
@@ -687,7 +625,8 @@ export class Join<
|
|
|
687
625
|
Content
|
|
688
626
|
>
|
|
689
627
|
if (defaultContent) {
|
|
690
|
-
const
|
|
628
|
+
const multipleRelatedEntriesSelectors =
|
|
629
|
+
getMultipleEntrySelectorFamily()
|
|
691
630
|
const entriesStateKeyA = `${aSide}EntriesOf${capitalize(
|
|
692
631
|
bSide,
|
|
693
632
|
)}` as const
|
|
@@ -695,8 +634,8 @@ export class Join<
|
|
|
695
634
|
aSide,
|
|
696
635
|
)}` as const
|
|
697
636
|
const contentStates = {
|
|
698
|
-
[entriesStateKeyA]:
|
|
699
|
-
[entriesStateKeyB]:
|
|
637
|
+
[entriesStateKeyA]: multipleRelatedEntriesSelectors,
|
|
638
|
+
[entriesStateKeyB]: multipleRelatedEntriesSelectors,
|
|
700
639
|
}
|
|
701
640
|
states = Object.assign(baseStates, contentStates)
|
|
702
641
|
} else {
|
|
@@ -762,8 +701,7 @@ export function join<
|
|
|
762
701
|
defaultContent: Content | undefined,
|
|
763
702
|
store: Store = IMPLICIT.STORE,
|
|
764
703
|
): JoinToken<ASide, AType, BSide, BType, Cardinality, Content> {
|
|
765
|
-
|
|
766
|
-
joins.set(options.key, new Join(options, defaultContent, store))
|
|
704
|
+
store.joins.set(options.key, new Join(options, defaultContent, store))
|
|
767
705
|
const token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content> = {
|
|
768
706
|
key: options.key,
|
|
769
707
|
type: `join`,
|
|
@@ -774,16 +712,6 @@ export function join<
|
|
|
774
712
|
return token
|
|
775
713
|
}
|
|
776
714
|
|
|
777
|
-
export function getJoinMap(
|
|
778
|
-
store: Store & { joins?: Map<string, Join<any, any, any, any, any, any>> },
|
|
779
|
-
): Map<string, Join<any, any, any, any, any, any>> {
|
|
780
|
-
if (`joins` in store && store.joins instanceof Map) {
|
|
781
|
-
return store.joins
|
|
782
|
-
}
|
|
783
|
-
const joins = new Map<string, Join<any, any, any, any, any, any>>()
|
|
784
|
-
store.joins = joins
|
|
785
|
-
return joins
|
|
786
|
-
}
|
|
787
715
|
export function getJoin<
|
|
788
716
|
ASide extends string,
|
|
789
717
|
AType extends string,
|
|
@@ -795,17 +723,17 @@ export function getJoin<
|
|
|
795
723
|
token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
796
724
|
store: Store,
|
|
797
725
|
): Join<ASide, AType, BSide, BType, Cardinality, Content> {
|
|
798
|
-
|
|
799
|
-
let myJoin = joinMap.get(token.key)
|
|
726
|
+
let myJoin = store.joins.get(token.key)
|
|
800
727
|
if (myJoin === undefined) {
|
|
801
|
-
const rootJoinMap =
|
|
802
|
-
|
|
803
|
-
if (
|
|
728
|
+
const rootJoinMap = IMPLICIT.STORE.joins
|
|
729
|
+
const rootJoin = rootJoinMap.get(token.key)
|
|
730
|
+
if (rootJoin === undefined) {
|
|
804
731
|
throw new Error(
|
|
805
732
|
`Join "${token.key}" not found in store "${store.config.name}"`,
|
|
806
733
|
)
|
|
807
734
|
}
|
|
808
|
-
|
|
735
|
+
myJoin = new Join(rootJoin.options, rootJoin.defaultContent, store)
|
|
736
|
+
store.joins.set(token.key, myJoin)
|
|
809
737
|
}
|
|
810
738
|
return myJoin
|
|
811
739
|
}
|
|
@@ -912,12 +840,12 @@ export function findRelationsInStore<
|
|
|
912
840
|
relations = {
|
|
913
841
|
get [keyAB]() {
|
|
914
842
|
const familyAB = myJoin.states[keyAB as any]
|
|
915
|
-
const state =
|
|
843
|
+
const state = findInStore(store, familyAB, key)
|
|
916
844
|
return state
|
|
917
845
|
},
|
|
918
846
|
get [keyBA]() {
|
|
919
847
|
const familyBA = myJoin.states[keyBA as any]
|
|
920
|
-
const state =
|
|
848
|
+
const state = findInStore(store, familyBA, key)
|
|
921
849
|
return state
|
|
922
850
|
},
|
|
923
851
|
} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
|
|
@@ -927,12 +855,12 @@ export function findRelationsInStore<
|
|
|
927
855
|
Object.assign(relations, {
|
|
928
856
|
get [entryAB]() {
|
|
929
857
|
const familyAB = myJoin.states[entryAB as any]
|
|
930
|
-
const state =
|
|
858
|
+
const state = findInStore(store, familyAB, key)
|
|
931
859
|
return state
|
|
932
860
|
},
|
|
933
861
|
get [entryBA]() {
|
|
934
862
|
const familyBA = myJoin.states[entryBA as any]
|
|
935
|
-
const state =
|
|
863
|
+
const state = findInStore(store, familyBA, key)
|
|
936
864
|
return state
|
|
937
865
|
},
|
|
938
866
|
})
|
|
@@ -945,12 +873,12 @@ export function findRelationsInStore<
|
|
|
945
873
|
relations = {
|
|
946
874
|
get [keyAB]() {
|
|
947
875
|
const familyAB = myJoin.states[keyAB as any]
|
|
948
|
-
const state =
|
|
876
|
+
const state = findInStore(store, familyAB, key)
|
|
949
877
|
return state
|
|
950
878
|
},
|
|
951
879
|
get [keysBA]() {
|
|
952
880
|
const familyBA = myJoin.states[keysBA as any]
|
|
953
|
-
const state =
|
|
881
|
+
const state = findInStore(store, familyBA, key)
|
|
954
882
|
return state
|
|
955
883
|
},
|
|
956
884
|
} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
|
|
@@ -960,12 +888,12 @@ export function findRelationsInStore<
|
|
|
960
888
|
Object.assign(relations, {
|
|
961
889
|
get [entryAB]() {
|
|
962
890
|
const familyAB = myJoin.states[entryAB as any]
|
|
963
|
-
const state =
|
|
891
|
+
const state = findInStore(store, familyAB, key)
|
|
964
892
|
return state
|
|
965
893
|
},
|
|
966
894
|
get [entriesBA]() {
|
|
967
895
|
const familyBA = myJoin.states[entriesBA as any]
|
|
968
|
-
const state =
|
|
896
|
+
const state = findInStore(store, familyBA, key)
|
|
969
897
|
return state
|
|
970
898
|
},
|
|
971
899
|
})
|
|
@@ -978,12 +906,12 @@ export function findRelationsInStore<
|
|
|
978
906
|
relations = {
|
|
979
907
|
get [keysAB]() {
|
|
980
908
|
const familyAB = myJoin.states[keysAB as any]
|
|
981
|
-
const state =
|
|
909
|
+
const state = findInStore(store, familyAB, key)
|
|
982
910
|
return state
|
|
983
911
|
},
|
|
984
912
|
get [keysBA]() {
|
|
985
913
|
const familyBA = myJoin.states[keysBA as any]
|
|
986
|
-
const state =
|
|
914
|
+
const state = findInStore(store, familyBA, key)
|
|
987
915
|
return state
|
|
988
916
|
},
|
|
989
917
|
} as JoinStates<ASide, AType, BSide, BType, Cardinality, Content>
|
|
@@ -993,12 +921,12 @@ export function findRelationsInStore<
|
|
|
993
921
|
Object.assign(relations, {
|
|
994
922
|
get [entriesAB]() {
|
|
995
923
|
const familyAB = myJoin.states[entriesAB as any]
|
|
996
|
-
const state =
|
|
924
|
+
const state = findInStore(store, familyAB, key)
|
|
997
925
|
return state
|
|
998
926
|
},
|
|
999
927
|
get [entriesBA]() {
|
|
1000
928
|
const familyBA = myJoin.states[entriesBA as any]
|
|
1001
|
-
const state =
|
|
929
|
+
const state = findInStore(store, familyBA, key)
|
|
1002
930
|
return state
|
|
1003
931
|
},
|
|
1004
932
|
})
|
|
@@ -1065,7 +993,7 @@ export function getInternalRelationsFromStore(
|
|
|
1065
993
|
store: Store,
|
|
1066
994
|
): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
|
|
1067
995
|
const myJoin = getJoin(token, store)
|
|
1068
|
-
const family = myJoin.core.
|
|
996
|
+
const family = myJoin.core.relatedKeysAtoms
|
|
1069
997
|
return family
|
|
1070
998
|
}
|
|
1071
999
|
|