atom.io 0.17.0 → 0.18.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.cjs +62 -40
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.ts +8 -2
- package/data/dist/index.js +64 -42
- package/data/dist/index.js.map +1 -1
- package/data/src/dict.ts +8 -4
- package/data/src/join.ts +74 -33
- package/data/src/struct-family.ts +18 -17
- package/dist/chunk-IZHOMSXA.js +331 -0
- package/dist/chunk-IZHOMSXA.js.map +1 -0
- package/dist/chunk-JDUNWJFB.js +18 -0
- package/dist/chunk-JDUNWJFB.js.map +1 -0
- package/dist/index.cjs +4 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +66 -51
- package/dist/index.js +5 -11
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +187 -58
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +95 -71
- package/internal/dist/index.js +179 -53
- package/internal/dist/index.js.map +1 -1
- package/internal/src/arbitrary.ts +3 -0
- package/internal/src/atom/delete-atom.ts +7 -6
- package/internal/src/caching.ts +6 -4
- package/internal/src/families/find-in-store.ts +16 -0
- package/internal/src/get-environment-data.ts +4 -7
- package/internal/src/index.ts +6 -5
- package/internal/src/ingest-updates/ingest-atom-update.ts +6 -2
- package/internal/src/ingest-updates/ingest-transaction-update.ts +0 -1
- package/internal/src/selector/create-standalone-selector.ts +0 -2
- package/internal/src/set-state/copy-mutable-if-needed.ts +5 -0
- package/internal/src/set-state/emit-update.ts +25 -11
- package/internal/src/set-state/set-atom.ts +15 -18
- package/internal/src/store/store.ts +14 -2
- package/internal/src/store/withdraw.ts +72 -2
- package/internal/src/subscribe/subscribe-to-timeline.ts +2 -2
- package/internal/src/subscribe/subscribe-to-transaction.ts +2 -2
- package/internal/src/timeline/create-timeline.ts +12 -1
- package/internal/src/transaction/act-upon-store.ts +19 -0
- package/internal/src/transaction/apply-transaction.ts +6 -1
- package/internal/src/transaction/assign-transaction-to-continuity.ts +18 -0
- package/internal/src/transaction/build-transaction.ts +7 -6
- package/internal/src/transaction/create-transaction.ts +1 -1
- package/internal/src/transaction/get-epoch-number.ts +40 -0
- package/internal/src/transaction/index.ts +10 -1
- package/internal/src/transaction/set-epoch-number.ts +30 -0
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +3 -3
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-introspection-states.ts +6 -2
- package/introspection/src/attach-timeline-family.ts +5 -2
- package/introspection/src/attach-transaction-logs.ts +2 -2
- package/json/dist/index.d.ts +3 -1
- package/json/src/index.ts +4 -0
- package/package.json +241 -230
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.ts +1 -1
- package/react/dist/index.js.map +1 -1
- package/react/src/use-json.ts +1 -1
- package/react-devtools/dist/index.cjs +131 -134
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.css +2 -2
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.ts +3 -3
- package/react-devtools/dist/index.js +91 -108
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateEditor.tsx +4 -4
- package/react-devtools/src/StateIndex.tsx +1 -4
- package/react-devtools/src/TimelineIndex.tsx +3 -3
- package/react-devtools/src/TransactionIndex.tsx +9 -8
- package/react-devtools/src/index.ts +2 -2
- package/realtime/dist/index.cjs +120 -0
- package/realtime/dist/index.cjs.map +1 -0
- package/realtime/dist/index.d.ts +146 -0
- package/realtime/dist/index.js +111 -0
- package/realtime/dist/index.js.map +1 -0
- package/realtime/package.json +16 -0
- package/realtime/src/index.ts +2 -0
- package/realtime/src/realtime-continuity.ts +162 -0
- package/realtime/src/shared-room-store.ts +48 -0
- package/realtime-client/dist/index.cjs +424 -170
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +15 -11
- package/realtime-client/dist/index.js +96 -177
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +8 -7
- package/realtime-client/src/{pull-family-member.ts → pull-atom-family-member.ts} +2 -2
- package/realtime-client/src/{pull-state.ts → pull-atom.ts} +2 -2
- package/realtime-client/src/{pull-mutable-family-member.ts → pull-mutable-atom-family-member.ts} +6 -6
- package/realtime-client/src/{pull-mutable.ts → pull-mutable-atom.ts} +1 -1
- package/realtime-client/src/pull-selector-family-member.ts +42 -0
- package/realtime-client/src/pull-selector.ts +38 -0
- package/realtime-client/src/realtime-client-stores/client-main-store.ts +12 -2
- package/realtime-client/src/realtime-client-stores/client-sync-store.ts +7 -7
- package/realtime-client/src/sync-continuity.ts +368 -0
- package/realtime-react/dist/index.cjs +367 -27
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +24 -8
- package/realtime-react/dist/index.js +38 -22
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/index.ts +6 -5
- package/realtime-react/src/use-pull-atom-family-member.ts +21 -0
- package/realtime-react/src/{use-sync.ts → use-pull-atom.ts} +4 -4
- package/realtime-react/src/{use-pull-mutable.ts → use-pull-mutable-atom.ts} +4 -3
- package/realtime-react/src/use-pull-mutable-family-member.ts +9 -4
- package/realtime-react/src/use-pull-selector-family-member.ts +21 -0
- package/realtime-react/src/{use-pull.ts → use-pull-selector.ts} +7 -5
- package/realtime-react/src/use-push.ts +3 -2
- package/realtime-react/src/use-server-action.ts +3 -2
- package/realtime-react/src/use-sync-continuity.ts +12 -0
- package/realtime-server/dist/index.cjs +769 -371
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +130 -60
- package/realtime-server/dist/index.js +753 -361
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/index.ts +17 -3
- package/realtime-server/src/ipc-sockets/child-socket.ts +135 -0
- package/realtime-server/src/ipc-sockets/custom-socket.ts +90 -0
- package/realtime-server/src/ipc-sockets/index.ts +3 -0
- package/realtime-server/src/ipc-sockets/parent-socket.ts +185 -0
- package/realtime-server/src/realtime-action-receiver.ts +8 -5
- package/realtime-server/src/realtime-continuity-synchronizer.ts +376 -0
- package/realtime-server/src/realtime-family-provider.ts +30 -71
- package/realtime-server/src/realtime-mutable-family-provider.ts +24 -86
- package/realtime-server/src/realtime-server-stores/index.ts +4 -1
- package/realtime-server/src/realtime-server-stores/realtime-continuity-store.ts +109 -0
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +64 -0
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +42 -0
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +51 -98
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +14 -29
- package/realtime-server/src/realtime-state-receiver.ts +0 -1
- package/realtime-testing/dist/index.cjs +34 -32
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.ts +1 -0
- package/realtime-testing/dist/index.js +33 -31
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +44 -32
- package/src/atom.ts +49 -31
- package/src/logger.ts +14 -5
- package/src/selector.ts +44 -25
- package/src/subscribe.ts +2 -1
- package/src/timeline.ts +4 -4
- package/src/transaction.ts +13 -17
- package/src/validators.ts +15 -9
- package/dist/chunk-H4Q5FTPZ.js +0 -11
- package/dist/chunk-H4Q5FTPZ.js.map +0 -1
- package/internal/src/set-state/copy-mutable-in-transaction.ts +0 -19
- package/realtime-client/src/sync-server-action.ts +0 -170
- package/realtime-client/src/sync-state.ts +0 -19
- package/realtime-react/src/use-pull-family-member.ts +0 -16
- package/realtime-react/src/use-sync-server-action.ts +0 -16
- package/realtime-server/src/realtime-action-synchronizer.ts +0 -152
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AtomFamilyToken,
|
|
3
|
+
AtomToken,
|
|
4
|
+
ReadableFamilyToken,
|
|
5
|
+
ReadableToken,
|
|
6
|
+
TransactionToken,
|
|
7
|
+
} from "atom.io"
|
|
8
|
+
import {
|
|
9
|
+
IMPLICIT,
|
|
10
|
+
assignTransactionToContinuity,
|
|
11
|
+
getUpdateToken,
|
|
12
|
+
setEpochNumberOfContinuity,
|
|
13
|
+
} from "atom.io/internal"
|
|
14
|
+
import type { Json } from "atom.io/json"
|
|
15
|
+
|
|
16
|
+
export class InvariantMap<K, V> extends Map<K, V> {
|
|
17
|
+
public set(key: K, value: V): this {
|
|
18
|
+
if (this.has(key)) {
|
|
19
|
+
console.warn(`Tried to set a key that already exists in an InvariantMap`, {
|
|
20
|
+
key,
|
|
21
|
+
value,
|
|
22
|
+
})
|
|
23
|
+
return this
|
|
24
|
+
}
|
|
25
|
+
return super.set(key, value)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public clear(): void {
|
|
29
|
+
throw new Error(`Cannot clear an InvariantMap`)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type PerspectiveToken<
|
|
34
|
+
F extends AtomFamilyToken<any>,
|
|
35
|
+
T extends F extends AtomFamilyToken<infer T, any> ? T : never,
|
|
36
|
+
> = {
|
|
37
|
+
type: `realtime_perspective`
|
|
38
|
+
resourceAtoms: F
|
|
39
|
+
viewAtoms: ReadableFamilyToken<ReadableToken<T>[], string>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type ContinuityToken = {
|
|
43
|
+
readonly type: `continuity`
|
|
44
|
+
readonly key: string
|
|
45
|
+
readonly globals: AtomToken<any>[]
|
|
46
|
+
readonly actions: TransactionToken<any>[]
|
|
47
|
+
readonly perspectives: PerspectiveToken<
|
|
48
|
+
AtomFamilyToken<any, Json.Serializable>,
|
|
49
|
+
Json.Serializable
|
|
50
|
+
>[]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class SyncGroup {
|
|
54
|
+
protected type = `continuity` as const
|
|
55
|
+
|
|
56
|
+
protected globals: AtomToken<any>[] = []
|
|
57
|
+
protected actions: TransactionToken<any>[] = []
|
|
58
|
+
protected perspectives: PerspectiveToken<any, any>[] = []
|
|
59
|
+
|
|
60
|
+
protected constructor(protected readonly key: string) {}
|
|
61
|
+
|
|
62
|
+
public static existing: InvariantMap<string, ContinuityToken> =
|
|
63
|
+
new InvariantMap()
|
|
64
|
+
public static create(
|
|
65
|
+
key: string,
|
|
66
|
+
builder: (group: SyncGroup) => SyncGroup,
|
|
67
|
+
): ContinuityToken {
|
|
68
|
+
const group = new SyncGroup(key)
|
|
69
|
+
const { type, globals, actions, perspectives } = builder(group)
|
|
70
|
+
const token = { type, key, globals, actions, perspectives }
|
|
71
|
+
SyncGroup.existing.set(key, token)
|
|
72
|
+
return token
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public add(...atoms: AtomToken<any>[]): SyncGroup
|
|
76
|
+
public add(...args: TransactionToken<any>[]): SyncGroup
|
|
77
|
+
public add<
|
|
78
|
+
F extends AtomFamilyToken<any>,
|
|
79
|
+
T extends F extends AtomFamilyToken<infer T> ? T : never,
|
|
80
|
+
>(
|
|
81
|
+
family: AtomFamilyToken<T, any>,
|
|
82
|
+
index: ReadableFamilyToken<Iterable<AtomToken<T>>, string>,
|
|
83
|
+
): SyncGroup
|
|
84
|
+
public add(
|
|
85
|
+
...args:
|
|
86
|
+
| readonly AtomToken<any>[]
|
|
87
|
+
| readonly TransactionToken<any>[]
|
|
88
|
+
| [AtomFamilyToken<any, any>, ReadableFamilyToken<Iterable<any>, string>]
|
|
89
|
+
): SyncGroup {
|
|
90
|
+
const zeroth = args[0]
|
|
91
|
+
if (zeroth.type === `atom` || zeroth.type === `mutable_atom`) {
|
|
92
|
+
const globals = args as AtomToken<any>[]
|
|
93
|
+
for (const global of globals) {
|
|
94
|
+
switch (global.type) {
|
|
95
|
+
case `atom`:
|
|
96
|
+
this.globals.push(global)
|
|
97
|
+
break
|
|
98
|
+
case `mutable_atom`:
|
|
99
|
+
this.globals.push(getUpdateToken(global))
|
|
100
|
+
break
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} else if (zeroth.type === `transaction`) {
|
|
104
|
+
const actions = args as TransactionToken<any>[]
|
|
105
|
+
this.actions.push(...actions)
|
|
106
|
+
} else {
|
|
107
|
+
const [family, index] = args as [
|
|
108
|
+
AtomFamilyToken<any, any>,
|
|
109
|
+
ReadableFamilyToken<ReadableToken<any>[], string>,
|
|
110
|
+
]
|
|
111
|
+
this.perspectives.push({
|
|
112
|
+
type: `realtime_perspective`,
|
|
113
|
+
resourceAtoms: family,
|
|
114
|
+
viewAtoms: index,
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
return this
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type ContinuityOptions = {
|
|
122
|
+
key: string
|
|
123
|
+
config: (group: SyncGroup) => SyncGroup
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function continuity(options: ContinuityOptions): ContinuityToken {
|
|
127
|
+
const { key, config } = options
|
|
128
|
+
const token = SyncGroup.create(key, config)
|
|
129
|
+
const { actions } = token
|
|
130
|
+
for (const action of actions) {
|
|
131
|
+
assignTransactionToContinuity(key, action.key, IMPLICIT.STORE)
|
|
132
|
+
}
|
|
133
|
+
setEpochNumberOfContinuity(key, -1, IMPLICIT.STORE)
|
|
134
|
+
return token
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// const counterStates = atomFamily<number, { c: string }>({
|
|
138
|
+
// key: `counter`,
|
|
139
|
+
// default: 0,
|
|
140
|
+
// })
|
|
141
|
+
// const counterIndices = atomFamily<{ c: string }[], string>({
|
|
142
|
+
// key: `counterIndex`,
|
|
143
|
+
// default: [],
|
|
144
|
+
// })
|
|
145
|
+
// const nameStates = atomFamily<number, { n: string }>({
|
|
146
|
+
// key: `name`,
|
|
147
|
+
// default: 0,
|
|
148
|
+
// })
|
|
149
|
+
// const nameIndices = atomFamily<{ n: string }[], string>({
|
|
150
|
+
// key: `nameIndex`,
|
|
151
|
+
// default: [],
|
|
152
|
+
// })
|
|
153
|
+
|
|
154
|
+
// const counterContinuity = continuity({
|
|
155
|
+
// key: `counter`,
|
|
156
|
+
// config: (group) =>
|
|
157
|
+
// group
|
|
158
|
+
// .add(counterStates, counterIndices)
|
|
159
|
+
// .add(nameStates, nameIndices)
|
|
160
|
+
// .add(nameStates, nameIndices)
|
|
161
|
+
// .add(nameStates, nameIndices),
|
|
162
|
+
// })
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { MutableAtomToken } from "atom.io"
|
|
2
|
+
import { atom, selectorFamily } from "atom.io"
|
|
3
|
+
import { join } from "atom.io/data"
|
|
4
|
+
import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
5
|
+
import { SetRTX } from "atom.io/transceivers/set-rtx"
|
|
6
|
+
|
|
7
|
+
export const usersInThisRoomIndex = atom<SetRTX<string>, SetRTXJson<string>>({
|
|
8
|
+
key: `usersInRoomIndex`,
|
|
9
|
+
mutable: true,
|
|
10
|
+
default: () => new SetRTX<string>(),
|
|
11
|
+
toJson: (set) => set.toJSON(),
|
|
12
|
+
fromJson: (json) => SetRTX.fromJSON(json),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export const roomIndex = atom({
|
|
16
|
+
key: `roomIndex`,
|
|
17
|
+
default: () => new SetRTX<string>(),
|
|
18
|
+
mutable: true,
|
|
19
|
+
toJson: (set) => set.toJSON(),
|
|
20
|
+
fromJson: (json) => SetRTX.fromJSON(json),
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export type UserInRoomMeta = {
|
|
24
|
+
enteredAtEpoch: number
|
|
25
|
+
}
|
|
26
|
+
export const DEFAULT_USER_IN_ROOM_META: UserInRoomMeta = {
|
|
27
|
+
enteredAtEpoch: 0,
|
|
28
|
+
}
|
|
29
|
+
export const usersInRooms = join(
|
|
30
|
+
{
|
|
31
|
+
key: `usersInRooms`,
|
|
32
|
+
between: [`room`, `user`],
|
|
33
|
+
cardinality: `1:n`,
|
|
34
|
+
},
|
|
35
|
+
DEFAULT_USER_IN_ROOM_META,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
export const usersInMyRoomView = selectorFamily<
|
|
39
|
+
MutableAtomToken<SetRTX<string>, SetRTXJson<string>>[],
|
|
40
|
+
string
|
|
41
|
+
>({
|
|
42
|
+
key: `usersInMyRoomView`,
|
|
43
|
+
get:
|
|
44
|
+
(username) =>
|
|
45
|
+
({ find }) => {
|
|
46
|
+
return [find(usersInRooms.core.findRelatedKeysState, username)]
|
|
47
|
+
},
|
|
48
|
+
})
|