atom.io 0.19.0 → 0.19.2
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.cjs +99 -79
- package/data/dist/index.js +2 -2
- package/data/src/join.ts +91 -74
- package/dist/{chunk-YDOGCZ53.js → chunk-ATKDGVTV.js} +29 -29
- package/dist/{chunk-CVBEVTM5.js → chunk-CC7IF7QF.js} +5 -42
- package/dist/{chunk-WX2NCOZR.js → chunk-FTONNX2R.js} +8 -8
- package/dist/{chunk-7ZR244C2.js → chunk-MSCJWACE.js} +92 -72
- package/dist/index.cjs +15 -7
- package/dist/index.d.ts +24 -35
- package/dist/index.js +15 -7
- package/internal/dist/index.cjs +56 -44
- package/internal/dist/index.d.ts +21 -21
- package/internal/dist/index.js +49 -37
- package/internal/src/atom/create-regular-atom.ts +7 -5
- package/internal/src/atom/delete-atom.ts +2 -2
- package/internal/src/families/create-readonly-selector-family.ts +2 -2
- package/internal/src/families/create-regular-atom-family.ts +1 -1
- package/internal/src/families/create-writable-selector-family.ts +1 -1
- package/internal/src/future.ts +4 -2
- package/internal/src/lineage.ts +1 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
- package/internal/src/mutable/create-mutable-atom.ts +7 -5
- package/internal/src/mutable/tracker.ts +4 -4
- package/internal/src/mutable/transceiver.ts +2 -2
- package/internal/src/selector/delete-selector.ts +1 -1
- package/internal/src/set-state/become.ts +1 -1
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/store/deposit.ts +5 -5
- package/internal/src/store/store.ts +5 -5
- package/internal/src/store/withdraw.ts +4 -5
- package/internal/src/subject.ts +3 -1
- package/internal/src/subscribe/subscribe-to-state.ts +2 -2
- package/internal/src/subscribe/subscribe-to-transaction.ts +4 -4
- package/internal/src/timeline/add-atom-to-timeline.ts +16 -11
- package/internal/src/timeline/create-timeline.ts +3 -4
- package/internal/src/transaction/act-upon-store.ts +5 -5
- package/internal/src/transaction/apply-transaction.ts +4 -4
- package/internal/src/transaction/build-transaction.ts +10 -7
- package/internal/src/transaction/create-transaction.ts +10 -10
- package/internal/src/transaction/index.ts +3 -3
- package/internal/src/transaction/is-root-store.ts +2 -2
- package/introspection/dist/index.cjs +3 -2
- package/introspection/dist/index.d.ts +6 -6
- package/introspection/dist/index.js +3 -2
- package/introspection/src/attach-atom-index.ts +5 -4
- package/introspection/src/attach-introspection-states.ts +3 -3
- package/introspection/src/attach-transaction-index.ts +4 -4
- package/introspection/src/attach-transaction-logs.ts +8 -4
- package/introspection/src/index.ts +3 -3
- package/json/dist/index.cjs +6 -2
- package/json/dist/index.d.ts +1 -1
- package/json/dist/index.js +8 -4
- package/json/src/select-json-family.ts +3 -2
- package/json/src/select-json.ts +3 -1
- package/package.json +243 -242
- package/react/dist/index.cjs +9 -3
- package/react/dist/index.js +9 -3
- package/react/src/use-i.ts +3 -1
- package/react/src/use-tl.ts +6 -2
- package/react-devtools/dist/index.cjs +332 -978
- package/react-devtools/dist/index.css +0 -18
- package/react-devtools/dist/index.d.ts +7 -9
- package/react-devtools/dist/index.js +291 -881
- package/react-devtools/src/AtomIODevtools.tsx +5 -2
- package/react-devtools/src/Button.tsx +6 -2
- package/react-devtools/src/StateEditor.tsx +13 -16
- package/react-devtools/src/StateIndex.tsx +28 -21
- package/react-devtools/src/TimelineIndex.tsx +17 -6
- package/react-devtools/src/TransactionIndex.tsx +13 -6
- package/react-devtools/src/Updates.tsx +24 -9
- package/realtime/dist/index.cjs +1 -0
- package/realtime/dist/index.d.ts +2 -2
- package/realtime/dist/index.js +1 -0
- package/realtime/src/realtime-continuity.ts +4 -3
- package/realtime-client/dist/index.cjs +29 -29
- package/realtime-client/dist/index.d.ts +2 -2
- package/realtime-client/dist/index.js +1 -1
- package/realtime-client/src/server-action.ts +2 -2
- package/realtime-client/src/sync-continuity.ts +23 -23
- package/realtime-react/dist/index.cjs +30 -30
- package/realtime-react/dist/index.d.ts +2 -2
- package/realtime-react/dist/index.js +2 -2
- package/realtime-react/src/use-server-action.ts +3 -3
- package/realtime-react/src/use-single-effect.ts +1 -1
- package/realtime-server/dist/index.cjs +54 -44
- package/realtime-server/dist/index.d.ts +6 -6
- package/realtime-server/dist/index.js +34 -24
- package/realtime-server/src/ipc-sockets/child-socket.ts +7 -7
- package/realtime-server/src/ipc-sockets/custom-socket.ts +4 -8
- package/realtime-server/src/ipc-sockets/parent-socket.ts +13 -7
- package/realtime-server/src/realtime-action-receiver.ts +7 -5
- package/realtime-server/src/realtime-continuity-synchronizer.ts +3 -3
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +2 -2
- package/realtime-server/src/realtime-state-receiver.ts +3 -1
- package/realtime-testing/dist/index.cjs +15 -13
- package/realtime-testing/dist/index.js +9 -7
- package/realtime-testing/src/setup-realtime-test.tsx +7 -5
- package/src/atom.ts +4 -8
- package/src/dispose.ts +1 -0
- package/src/index.ts +2 -9
- package/src/selector.ts +4 -8
- package/src/silo.ts +13 -3
- package/src/subscribe.ts +6 -6
- package/src/timeline.ts +4 -4
- package/src/transaction.ts +24 -24
- package/src/validators.ts +2 -2
- package/transceivers/set-rtx/dist/index.cjs +11 -12
- package/transceivers/set-rtx/dist/index.js +11 -12
- package/transceivers/set-rtx/src/set-rtx.ts +10 -10
- /package/dist/{chunk-VAE5OCKN.js → chunk-BF4MVQF6.js} +0 -0
package/data/src/join.ts
CHANGED
|
@@ -73,7 +73,7 @@ export type JoinStateFamilies<
|
|
|
73
73
|
[string, Content] | null,
|
|
74
74
|
string
|
|
75
75
|
>
|
|
76
|
-
|
|
76
|
+
}
|
|
77
77
|
: {}) & {
|
|
78
78
|
readonly [AB in ASide | BSide as AB extends ASide
|
|
79
79
|
? `${AB}KeyOf${Capitalize<BSide>}`
|
|
@@ -81,33 +81,33 @@ export type JoinStateFamilies<
|
|
|
81
81
|
string | null,
|
|
82
82
|
string
|
|
83
83
|
>
|
|
84
|
-
|
|
84
|
+
}
|
|
85
85
|
: Cardinality extends `1:n`
|
|
86
|
-
|
|
86
|
+
? (Content extends Json.Object
|
|
87
87
|
? {
|
|
88
88
|
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorFamily<
|
|
89
89
|
[string, Content] | null,
|
|
90
90
|
string
|
|
91
91
|
>
|
|
92
|
-
|
|
92
|
+
} & {
|
|
93
93
|
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorFamily<
|
|
94
94
|
[string, Content][],
|
|
95
95
|
string
|
|
96
96
|
>
|
|
97
|
-
|
|
97
|
+
}
|
|
98
98
|
: {}) & {
|
|
99
99
|
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorFamily<
|
|
100
100
|
string | null,
|
|
101
101
|
string
|
|
102
102
|
>
|
|
103
|
-
|
|
103
|
+
} & {
|
|
104
104
|
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorFamily<
|
|
105
105
|
string[],
|
|
106
106
|
string
|
|
107
107
|
>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
}
|
|
109
|
+
: Cardinality extends `n:n`
|
|
110
|
+
? (Content extends Json.Object
|
|
111
111
|
? {
|
|
112
112
|
readonly [AB in ASide | BSide as AB extends ASide
|
|
113
113
|
? `${AB}EntriesOf${Capitalize<BSide>}`
|
|
@@ -115,7 +115,7 @@ export type JoinStateFamilies<
|
|
|
115
115
|
[string, Content][],
|
|
116
116
|
string
|
|
117
117
|
>
|
|
118
|
-
|
|
118
|
+
}
|
|
119
119
|
: {}) & {
|
|
120
120
|
readonly [AB in ASide | BSide as AB extends ASide
|
|
121
121
|
? `${AB}KeysOf${Capitalize<BSide>}`
|
|
@@ -123,8 +123,8 @@ export type JoinStateFamilies<
|
|
|
123
123
|
string[],
|
|
124
124
|
string
|
|
125
125
|
>
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
}
|
|
127
|
+
: never
|
|
128
128
|
|
|
129
129
|
export class Join<
|
|
130
130
|
const ASide extends string,
|
|
@@ -178,11 +178,13 @@ export class Join<
|
|
|
178
178
|
this.alternates.set(store.config.name, this)
|
|
179
179
|
this.transactors = {
|
|
180
180
|
get: (token) => getFromStore(token, store),
|
|
181
|
-
set: (token, value) =>
|
|
181
|
+
set: (token, value) => {
|
|
182
|
+
setIntoStore(token, value, store)
|
|
183
|
+
},
|
|
182
184
|
find: ((token, key) => findInStore(token, key, store)) as typeof findState,
|
|
183
185
|
}
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
+
const aSide: ASide = options.between[0]
|
|
187
|
+
const bSide: BSide = options.between[1]
|
|
186
188
|
const relatedKeysAtoms = createMutableAtomFamily<
|
|
187
189
|
SetRTX<string>,
|
|
188
190
|
SetRTXJson<string>,
|
|
@@ -305,12 +307,18 @@ export class Join<
|
|
|
305
307
|
}
|
|
306
308
|
const baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {
|
|
307
309
|
getRelatedKeys: (key) => getRelatedKeys(this.transactors, key),
|
|
308
|
-
addRelation: (a, b) =>
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
310
|
+
addRelation: (a, b) => {
|
|
311
|
+
addRelation(this.transactors, a, b)
|
|
312
|
+
},
|
|
313
|
+
deleteRelation: (a, b) => {
|
|
314
|
+
deleteRelation(this.transactors, a, b)
|
|
315
|
+
},
|
|
316
|
+
replaceRelationsSafely: (a, bs) => {
|
|
317
|
+
replaceRelationsSafely(this.transactors, a, bs)
|
|
318
|
+
},
|
|
319
|
+
replaceRelationsUnsafely: (a, bs) => {
|
|
320
|
+
replaceRelationsUnsafely(this.transactors, a, bs)
|
|
321
|
+
},
|
|
314
322
|
has: (a, b) => has(this.transactors, a, b),
|
|
315
323
|
}
|
|
316
324
|
let externalStore: ExternalStoreConfiguration<Content>
|
|
@@ -331,9 +339,12 @@ export class Join<
|
|
|
331
339
|
{ find, set },
|
|
332
340
|
key,
|
|
333
341
|
content,
|
|
334
|
-
) =>
|
|
335
|
-
|
|
342
|
+
) => {
|
|
343
|
+
set(find(contentAtoms, key), content)
|
|
344
|
+
}
|
|
345
|
+
const deleteContent: Write<(key: string) => void> = ({ find }, key) => {
|
|
336
346
|
dispose(find(contentAtoms, key))
|
|
347
|
+
}
|
|
337
348
|
const externalStoreWithContentConfiguration = {
|
|
338
349
|
getContent: (contentKey: string) => {
|
|
339
350
|
const content = getContent(this.transactors, contentKey)
|
|
@@ -435,8 +446,8 @@ export class Join<
|
|
|
435
446
|
switch (options.cardinality) {
|
|
436
447
|
case `1:1`: {
|
|
437
448
|
const findSingleRelatedKeyState = createSingleKeyStateFamily()
|
|
438
|
-
const stateKeyA = `${
|
|
439
|
-
const stateKeyB = `${
|
|
449
|
+
const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}` as const
|
|
450
|
+
const stateKeyB = `${bSide}KeyOf${capitalize(aSide)}` as const
|
|
440
451
|
const baseStates = {
|
|
441
452
|
[stateKeyA]: findSingleRelatedKeyState,
|
|
442
453
|
[stateKeyB]: findSingleRelatedKeyState,
|
|
@@ -444,8 +455,8 @@ export class Join<
|
|
|
444
455
|
let states: JoinStateFamilies<ASide, BSide, Cardinality, Content>
|
|
445
456
|
if (defaultContent) {
|
|
446
457
|
const findSingleRelatedEntryState = createSingleEntryStateFamily()
|
|
447
|
-
const entriesStateKeyA = `${
|
|
448
|
-
const entriesStateKeyB = `${
|
|
458
|
+
const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}` as const
|
|
459
|
+
const entriesStateKeyB = `${bSide}EntryOf${capitalize(aSide)}` as const
|
|
449
460
|
const contentStates = {
|
|
450
461
|
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
451
462
|
[entriesStateKeyB]: findSingleRelatedEntryState,
|
|
@@ -461,8 +472,8 @@ export class Join<
|
|
|
461
472
|
case `1:n`: {
|
|
462
473
|
const findSingleRelatedKeyState = createSingleKeyStateFamily()
|
|
463
474
|
const findMultipleRelatedKeysState = getMultipleKeyStateFamily()
|
|
464
|
-
const stateKeyA = `${
|
|
465
|
-
const stateKeyB = `${
|
|
475
|
+
const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}` as const
|
|
476
|
+
const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}` as const
|
|
466
477
|
const baseStates = {
|
|
467
478
|
[stateKeyA]: findSingleRelatedKeyState,
|
|
468
479
|
[stateKeyB]: findMultipleRelatedKeysState,
|
|
@@ -471,8 +482,10 @@ export class Join<
|
|
|
471
482
|
if (defaultContent) {
|
|
472
483
|
const findSingleRelatedEntryState = createSingleEntryStateFamily()
|
|
473
484
|
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily()
|
|
474
|
-
const entriesStateKeyA = `${
|
|
475
|
-
const entriesStateKeyB = `${
|
|
485
|
+
const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}` as const
|
|
486
|
+
const entriesStateKeyB = `${bSide}EntriesOf${capitalize(
|
|
487
|
+
aSide,
|
|
488
|
+
)}` as const
|
|
476
489
|
const contentStates = {
|
|
477
490
|
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
478
491
|
[entriesStateKeyB]: findMultipleRelatedEntriesState,
|
|
@@ -487,8 +500,8 @@ export class Join<
|
|
|
487
500
|
}
|
|
488
501
|
default: {
|
|
489
502
|
const findMultipleRelatedKeysState = getMultipleKeyStateFamily()
|
|
490
|
-
const stateKeyA = `${
|
|
491
|
-
const stateKeyB = `${
|
|
503
|
+
const stateKeyA = `${aSide}KeysOf${capitalize(bSide)}` as const
|
|
504
|
+
const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}` as const
|
|
492
505
|
const baseStates = {
|
|
493
506
|
[stateKeyA]: findMultipleRelatedKeysState,
|
|
494
507
|
[stateKeyB]: findMultipleRelatedKeysState,
|
|
@@ -496,8 +509,12 @@ export class Join<
|
|
|
496
509
|
let states: JoinStateFamilies<ASide, BSide, Cardinality, Content>
|
|
497
510
|
if (defaultContent) {
|
|
498
511
|
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily()
|
|
499
|
-
const entriesStateKeyA = `${
|
|
500
|
-
|
|
512
|
+
const entriesStateKeyA = `${aSide}EntriesOf${capitalize(
|
|
513
|
+
bSide,
|
|
514
|
+
)}` as const
|
|
515
|
+
const entriesStateKeyB = `${bSide}EntriesOf${capitalize(
|
|
516
|
+
aSide,
|
|
517
|
+
)}` as const
|
|
501
518
|
const contentStates = {
|
|
502
519
|
[entriesStateKeyA]: findMultipleRelatedEntriesState,
|
|
503
520
|
[entriesStateKeyB]: findMultipleRelatedEntriesState,
|
|
@@ -588,18 +605,18 @@ export function getJoin<
|
|
|
588
605
|
store: Store,
|
|
589
606
|
): Join<ASide, BSide, Cardinality, Content> {
|
|
590
607
|
const joinMap = getJoinMap(store)
|
|
591
|
-
let
|
|
592
|
-
if (
|
|
608
|
+
let myJoin = joinMap.get(token.key)
|
|
609
|
+
if (myJoin === undefined) {
|
|
593
610
|
const rootJoinMap = getJoinMap(IMPLICIT.STORE)
|
|
594
|
-
|
|
595
|
-
if (
|
|
611
|
+
myJoin = rootJoinMap.get(token.key)?.in(store)
|
|
612
|
+
if (myJoin === undefined) {
|
|
596
613
|
throw new Error(
|
|
597
614
|
`Join "${token.key}" not found in store "${store.config.name}"`,
|
|
598
615
|
)
|
|
599
616
|
}
|
|
600
|
-
joinMap.set(token.key,
|
|
617
|
+
joinMap.set(token.key, myJoin)
|
|
601
618
|
}
|
|
602
|
-
return
|
|
619
|
+
return myJoin
|
|
603
620
|
}
|
|
604
621
|
|
|
605
622
|
export type JoinStates<
|
|
@@ -615,47 +632,47 @@ export type JoinStates<
|
|
|
615
632
|
: `${AB}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
616
633
|
[string, Content] | null
|
|
617
634
|
>
|
|
618
|
-
|
|
635
|
+
}
|
|
619
636
|
: {}) & {
|
|
620
637
|
readonly [AB in ASide | BSide as AB extends ASide
|
|
621
638
|
? `${AB}KeyOf${Capitalize<BSide>}`
|
|
622
639
|
: `${AB}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorToken<string | null>
|
|
623
|
-
|
|
640
|
+
}
|
|
624
641
|
: Cardinality extends `1:n`
|
|
625
|
-
|
|
642
|
+
? (Content extends Json.Object
|
|
626
643
|
? {
|
|
627
644
|
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
628
645
|
[string, Content] | null
|
|
629
646
|
>
|
|
630
|
-
|
|
647
|
+
} & {
|
|
631
648
|
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
632
649
|
[string, Content][]
|
|
633
650
|
>
|
|
634
|
-
|
|
651
|
+
}
|
|
635
652
|
: {}) & {
|
|
636
653
|
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
637
654
|
string | null
|
|
638
655
|
>
|
|
639
|
-
|
|
656
|
+
} & {
|
|
640
657
|
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
641
658
|
string[]
|
|
642
659
|
>
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
660
|
+
}
|
|
661
|
+
: Cardinality extends `n:n`
|
|
662
|
+
? (Content extends Json.Object
|
|
646
663
|
? {
|
|
647
664
|
readonly [AB in ASide | BSide as AB extends ASide
|
|
648
665
|
? `${AB}EntriesOf${Capitalize<BSide>}`
|
|
649
666
|
: `${AB}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
650
667
|
[string, Content][]
|
|
651
668
|
>
|
|
652
|
-
|
|
669
|
+
}
|
|
653
670
|
: {}) & {
|
|
654
671
|
readonly [AB in ASide | BSide as AB extends ASide
|
|
655
672
|
? `${AB}KeysOf${Capitalize<BSide>}`
|
|
656
673
|
: `${AB}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<string[]>
|
|
657
|
-
|
|
658
|
-
|
|
674
|
+
}
|
|
675
|
+
: never
|
|
659
676
|
|
|
660
677
|
export function findRelationsInStore<
|
|
661
678
|
ASide extends string,
|
|
@@ -667,7 +684,7 @@ export function findRelationsInStore<
|
|
|
667
684
|
key: string,
|
|
668
685
|
store: Store,
|
|
669
686
|
): JoinStates<ASide, BSide, Cardinality, Content> {
|
|
670
|
-
const
|
|
687
|
+
const myJoin = getJoin(token, store)
|
|
671
688
|
let relations: JoinStates<ASide, BSide, Cardinality, Content>
|
|
672
689
|
switch (token.cardinality satisfies `1:1` | `1:n` | `n:n`) {
|
|
673
690
|
case `1:1`: {
|
|
@@ -675,27 +692,27 @@ export function findRelationsInStore<
|
|
|
675
692
|
const keyBA = `${token.b}KeyOf${capitalize(token.a)}`
|
|
676
693
|
relations = {
|
|
677
694
|
get [keyAB]() {
|
|
678
|
-
const familyAB =
|
|
695
|
+
const familyAB = myJoin.states[keyAB as any]
|
|
679
696
|
const state = findInStore(familyAB, key, store)
|
|
680
697
|
return state
|
|
681
698
|
},
|
|
682
699
|
get [keyBA]() {
|
|
683
|
-
const familyBA =
|
|
700
|
+
const familyBA = myJoin.states[keyBA as any]
|
|
684
701
|
const state = findInStore(familyBA, key, store)
|
|
685
702
|
return state
|
|
686
703
|
},
|
|
687
704
|
} as JoinStates<ASide, BSide, Cardinality, Content>
|
|
688
705
|
const entryAB = `${token.a}EntryOf${capitalize(token.b)}`
|
|
689
|
-
if (entryAB in
|
|
706
|
+
if (entryAB in myJoin.states) {
|
|
690
707
|
const entryBA = `${token.b}EntryOf${capitalize(token.a)}`
|
|
691
708
|
Object.assign(relations, {
|
|
692
709
|
get [entryAB]() {
|
|
693
|
-
const familyAB =
|
|
710
|
+
const familyAB = myJoin.states[entryAB as any]
|
|
694
711
|
const state = findInStore(familyAB, key, store)
|
|
695
712
|
return state
|
|
696
713
|
},
|
|
697
714
|
get [entryBA]() {
|
|
698
|
-
const familyBA =
|
|
715
|
+
const familyBA = myJoin.states[entryBA as any]
|
|
699
716
|
const state = findInStore(familyBA, key, store)
|
|
700
717
|
return state
|
|
701
718
|
},
|
|
@@ -708,27 +725,27 @@ export function findRelationsInStore<
|
|
|
708
725
|
const keysBA = `${token.b}KeysOf${capitalize(token.a)}`
|
|
709
726
|
relations = {
|
|
710
727
|
get [keyAB]() {
|
|
711
|
-
const familyAB =
|
|
728
|
+
const familyAB = myJoin.states[keyAB as any]
|
|
712
729
|
const state = findInStore(familyAB, key, store)
|
|
713
730
|
return state
|
|
714
731
|
},
|
|
715
732
|
get [keysBA]() {
|
|
716
|
-
const familyBA =
|
|
733
|
+
const familyBA = myJoin.states[keysBA as any]
|
|
717
734
|
const state = findInStore(familyBA, key, store)
|
|
718
735
|
return state
|
|
719
736
|
},
|
|
720
737
|
} as JoinStates<ASide, BSide, Cardinality, Content>
|
|
721
738
|
const entryAB = `${token.a}EntryOf${capitalize(token.b)}`
|
|
722
|
-
if (entryAB in
|
|
739
|
+
if (entryAB in myJoin.states) {
|
|
723
740
|
const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`
|
|
724
741
|
Object.assign(relations, {
|
|
725
742
|
get [entryAB]() {
|
|
726
|
-
const familyAB =
|
|
743
|
+
const familyAB = myJoin.states[entryAB as any]
|
|
727
744
|
const state = findInStore(familyAB, key, store)
|
|
728
745
|
return state
|
|
729
746
|
},
|
|
730
747
|
get [entriesBA]() {
|
|
731
|
-
const familyBA =
|
|
748
|
+
const familyBA = myJoin.states[entriesBA as any]
|
|
732
749
|
const state = findInStore(familyBA, key, store)
|
|
733
750
|
return state
|
|
734
751
|
},
|
|
@@ -741,27 +758,27 @@ export function findRelationsInStore<
|
|
|
741
758
|
const keysBA = `${token.b}KeysOf${capitalize(token.a)}`
|
|
742
759
|
relations = {
|
|
743
760
|
get [keysAB]() {
|
|
744
|
-
const familyAB =
|
|
761
|
+
const familyAB = myJoin.states[keysAB as any]
|
|
745
762
|
const state = findInStore(familyAB, key, store)
|
|
746
763
|
return state
|
|
747
764
|
},
|
|
748
765
|
get [keysBA]() {
|
|
749
|
-
const familyBA =
|
|
766
|
+
const familyBA = myJoin.states[keysBA as any]
|
|
750
767
|
const state = findInStore(familyBA, key, store)
|
|
751
768
|
return state
|
|
752
769
|
},
|
|
753
770
|
} as JoinStates<ASide, BSide, Cardinality, Content>
|
|
754
771
|
const entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`
|
|
755
|
-
if (entriesAB in
|
|
772
|
+
if (entriesAB in myJoin.states) {
|
|
756
773
|
const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`
|
|
757
774
|
Object.assign(relations, {
|
|
758
775
|
get [entriesAB]() {
|
|
759
|
-
const familyAB =
|
|
776
|
+
const familyAB = myJoin.states[entriesAB as any]
|
|
760
777
|
const state = findInStore(familyAB, key, store)
|
|
761
778
|
return state
|
|
762
779
|
},
|
|
763
780
|
get [entriesBA]() {
|
|
764
|
-
const familyBA =
|
|
781
|
+
const familyBA = myJoin.states[entriesBA as any]
|
|
765
782
|
const state = findInStore(familyBA, key, store)
|
|
766
783
|
return state
|
|
767
784
|
},
|
|
@@ -794,15 +811,15 @@ export function editRelationsInStore<
|
|
|
794
811
|
change: (relations: Junction<ASide, BSide, Content>) => void,
|
|
795
812
|
store: Store,
|
|
796
813
|
): void {
|
|
797
|
-
const
|
|
814
|
+
const myJoin = getJoin(token, store)
|
|
798
815
|
const target = newest(store)
|
|
799
816
|
if (isChildStore(target)) {
|
|
800
817
|
const { transactors } = target.transactionMeta
|
|
801
|
-
|
|
818
|
+
myJoin.transact(transactors, ({ relations }) => {
|
|
802
819
|
change(relations)
|
|
803
820
|
})
|
|
804
821
|
} else {
|
|
805
|
-
change(
|
|
822
|
+
change(myJoin.relations)
|
|
806
823
|
}
|
|
807
824
|
}
|
|
808
825
|
|
|
@@ -822,8 +839,8 @@ export function getInternalRelationsFromStore(
|
|
|
822
839
|
token: JoinToken<any, any, any, any>,
|
|
823
840
|
store: Store,
|
|
824
841
|
): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
|
|
825
|
-
const
|
|
826
|
-
const family =
|
|
842
|
+
const myJoin = getJoin(token, store)
|
|
843
|
+
const family = myJoin.core.findRelatedKeysState
|
|
827
844
|
return family
|
|
828
845
|
}
|
|
829
846
|
|
|
@@ -27,8 +27,8 @@ function syncContinuity(continuity, socket, store) {
|
|
|
27
27
|
};
|
|
28
28
|
socket.off(`continuity-init:${continuityKey}`);
|
|
29
29
|
socket.on(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
30
|
-
const registerAndAttemptConfirmedUpdate = (
|
|
31
|
-
function reconcileEpoch(optimisticUpdate,
|
|
30
|
+
const registerAndAttemptConfirmedUpdate = (confirmed) => {
|
|
31
|
+
function reconcileEpoch(optimisticUpdate, confirmedUpdate) {
|
|
32
32
|
store.logger.info(
|
|
33
33
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
34
34
|
`continuity`,
|
|
@@ -43,9 +43,9 @@ function syncContinuity(continuity, socket, store) {
|
|
|
43
43
|
},
|
|
44
44
|
store
|
|
45
45
|
);
|
|
46
|
-
if (optimisticUpdate.id ===
|
|
46
|
+
if (optimisticUpdate.id === confirmedUpdate.id) {
|
|
47
47
|
const clientResult = JSON.stringify(optimisticUpdate.updates);
|
|
48
|
-
const serverResult = JSON.stringify(
|
|
48
|
+
const serverResult = JSON.stringify(confirmedUpdate.updates);
|
|
49
49
|
if (clientResult === serverResult) {
|
|
50
50
|
store.logger.info(
|
|
51
51
|
`\u2705`,
|
|
@@ -53,7 +53,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
53
53
|
continuityKey,
|
|
54
54
|
`results for ${optimisticUpdate.id} match between client and server`
|
|
55
55
|
);
|
|
56
|
-
socket.emit(`ack:${continuityKey}`,
|
|
56
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
} else {
|
|
@@ -61,7 +61,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
61
61
|
`\u274C`,
|
|
62
62
|
`continuity`,
|
|
63
63
|
continuityKey,
|
|
64
|
-
`thought update #${
|
|
64
|
+
`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.key}:${confirmedUpdate.id}`
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
store.logger.info(
|
|
@@ -70,7 +70,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
70
70
|
continuityKey,
|
|
71
71
|
`updates do not match`,
|
|
72
72
|
optimisticUpdate,
|
|
73
|
-
|
|
73
|
+
confirmedUpdate
|
|
74
74
|
);
|
|
75
75
|
const reversedOptimisticUpdates = optimisticUpdates.toReversed();
|
|
76
76
|
for (const subsequentOptimistic of reversedOptimisticUpdates) {
|
|
@@ -91,15 +91,15 @@ function syncContinuity(continuity, socket, store) {
|
|
|
91
91
|
`undid zeroth optimistic update`,
|
|
92
92
|
optimisticUpdate
|
|
93
93
|
);
|
|
94
|
-
ingestTransactionUpdate(`newValue`,
|
|
94
|
+
ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
95
95
|
store.logger.info(
|
|
96
96
|
`\u23E9`,
|
|
97
97
|
`continuity`,
|
|
98
98
|
continuityKey,
|
|
99
99
|
`applied confirmed update`,
|
|
100
|
-
|
|
100
|
+
confirmedUpdate
|
|
101
101
|
);
|
|
102
|
-
socket.emit(`ack:${continuityKey}`,
|
|
102
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
103
103
|
for (const subsequentOptimistic of optimisticUpdates) {
|
|
104
104
|
const token = {
|
|
105
105
|
type: `transaction`,
|
|
@@ -121,7 +121,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
121
121
|
`continuity`,
|
|
122
122
|
continuityKey,
|
|
123
123
|
`integrating confirmed update`,
|
|
124
|
-
{ confirmedUpdate, confirmedUpdates, optimisticUpdates }
|
|
124
|
+
{ confirmedUpdate: confirmed, confirmedUpdates, optimisticUpdates }
|
|
125
125
|
);
|
|
126
126
|
const zerothOptimisticUpdate = optimisticUpdates[0];
|
|
127
127
|
if (zerothOptimisticUpdate) {
|
|
@@ -131,14 +131,14 @@ function syncContinuity(continuity, socket, store) {
|
|
|
131
131
|
continuityKey,
|
|
132
132
|
`has optimistic updates to reconcile`
|
|
133
133
|
);
|
|
134
|
-
if (
|
|
134
|
+
if (confirmed.epoch === zerothOptimisticUpdate.epoch) {
|
|
135
135
|
store.logger.info(
|
|
136
136
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
137
137
|
`continuity`,
|
|
138
138
|
continuityKey,
|
|
139
|
-
`epoch of confirmed update #${
|
|
139
|
+
`epoch of confirmed update #${confirmed.epoch} matches zeroth optimistic update`
|
|
140
140
|
);
|
|
141
|
-
reconcileEpoch(zerothOptimisticUpdate,
|
|
141
|
+
reconcileEpoch(zerothOptimisticUpdate, confirmed);
|
|
142
142
|
for (const nextConfirmed of confirmedUpdates) {
|
|
143
143
|
const nextOptimistic = optimisticUpdates[0];
|
|
144
144
|
if (nextConfirmed.epoch === (nextOptimistic == null ? void 0 : nextOptimistic.epoch)) {
|
|
@@ -152,10 +152,10 @@ function syncContinuity(continuity, socket, store) {
|
|
|
152
152
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
153
153
|
`continuity`,
|
|
154
154
|
continuityKey,
|
|
155
|
-
`epoch of confirmed update #${
|
|
155
|
+
`epoch of confirmed update #${confirmed.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`
|
|
156
156
|
);
|
|
157
157
|
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
158
|
-
(update) => update.epoch ===
|
|
158
|
+
(update) => update.epoch === confirmed.epoch
|
|
159
159
|
);
|
|
160
160
|
if (!confirmedUpdateIsAlreadyEnqueued) {
|
|
161
161
|
store.logger.info(
|
|
@@ -163,12 +163,12 @@ function syncContinuity(continuity, socket, store) {
|
|
|
163
163
|
`continuity`,
|
|
164
164
|
continuityKey,
|
|
165
165
|
`pushing confirmed update to queue`,
|
|
166
|
-
|
|
166
|
+
confirmed
|
|
167
167
|
);
|
|
168
168
|
setIntoStore(
|
|
169
169
|
confirmedUpdateQueue,
|
|
170
170
|
(queue) => {
|
|
171
|
-
queue.push(
|
|
171
|
+
queue.push(confirmed);
|
|
172
172
|
queue.sort((a, b) => a.epoch - b.epoch);
|
|
173
173
|
return queue;
|
|
174
174
|
},
|
|
@@ -185,48 +185,48 @@ function syncContinuity(continuity, socket, store) {
|
|
|
185
185
|
);
|
|
186
186
|
const continuityEpoch = getEpochNumberOfContinuity(continuityKey, store);
|
|
187
187
|
const isRoot = isRootStore(store);
|
|
188
|
-
if (isRoot && continuityEpoch ===
|
|
188
|
+
if (isRoot && continuityEpoch === confirmed.epoch - 1) {
|
|
189
189
|
store.logger.info(
|
|
190
190
|
`\u2705`,
|
|
191
191
|
`continuity`,
|
|
192
192
|
continuityKey,
|
|
193
|
-
`integrating update #${
|
|
193
|
+
`integrating update #${confirmed.epoch} (${confirmed.key} ${confirmed.id})`
|
|
194
194
|
);
|
|
195
|
-
ingestTransactionUpdate(`newValue`,
|
|
196
|
-
socket.emit(`ack:${continuityKey}`,
|
|
197
|
-
setEpochNumberOfContinuity(continuityKey,
|
|
195
|
+
ingestTransactionUpdate(`newValue`, confirmed, store);
|
|
196
|
+
socket.emit(`ack:${continuityKey}`, confirmed.epoch);
|
|
197
|
+
setEpochNumberOfContinuity(continuityKey, confirmed.epoch, store);
|
|
198
198
|
} else if (isRoot && continuityEpoch !== void 0) {
|
|
199
199
|
store.logger.info(
|
|
200
200
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
201
201
|
`continuity`,
|
|
202
202
|
continuityKey,
|
|
203
|
-
`received update #${
|
|
203
|
+
`received update #${confirmed.epoch} but still waiting for update #${continuityEpoch + 1}`,
|
|
204
204
|
{
|
|
205
205
|
clientEpoch: continuityEpoch,
|
|
206
|
-
serverEpoch:
|
|
206
|
+
serverEpoch: confirmed.epoch
|
|
207
207
|
}
|
|
208
208
|
);
|
|
209
209
|
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
210
|
-
(update) => update.epoch ===
|
|
210
|
+
(update) => update.epoch === confirmed.epoch
|
|
211
211
|
);
|
|
212
212
|
if (confirmedUpdateIsAlreadyEnqueued) {
|
|
213
213
|
store.logger.info(
|
|
214
214
|
`\u{1F44D}`,
|
|
215
215
|
`continuity`,
|
|
216
216
|
continuityKey,
|
|
217
|
-
`confirmed update #${
|
|
217
|
+
`confirmed update #${confirmed.epoch} is already enqueued`
|
|
218
218
|
);
|
|
219
219
|
} else {
|
|
220
220
|
store.logger.info(
|
|
221
221
|
`\u{1F448}`,
|
|
222
222
|
`continuity`,
|
|
223
223
|
continuityKey,
|
|
224
|
-
`pushing confirmed update #${
|
|
224
|
+
`pushing confirmed update #${confirmed.epoch} to queue`
|
|
225
225
|
);
|
|
226
226
|
setIntoStore(
|
|
227
227
|
confirmedUpdateQueue,
|
|
228
228
|
(queue) => {
|
|
229
|
-
queue.push(
|
|
229
|
+
queue.push(confirmed);
|
|
230
230
|
queue.sort((a, b) => a.epoch - b.epoch);
|
|
231
231
|
return queue;
|
|
232
232
|
},
|