atom.io 0.24.4 → 0.24.6

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.
@@ -1,11 +1,11 @@
1
1
  import { __spreadProps, __spreadValues } from '../../dist/chunk-S4N6XNPH.js';
2
2
  import { parseJson, stringifyJson } from 'atom.io/json';
3
- import { getUpdateToken, IMPLICIT, Subject, getFromStore, subscribeToState, findInStore, getJsonToken, actUponStore, isRootStore, subscribeToTransaction, setIntoStore } from 'atom.io/internal';
3
+ import { Subject, IMPLICIT, getFromStore, subscribeToState, findInStore, getJsonToken, getUpdateToken, actUponStore, isRootStore, subscribeToTransaction, setIntoStore } from 'atom.io/internal';
4
4
  import { SetRTX } from 'atom.io/transceivers/set-rtx';
5
5
  import { editRelationsInStore, join, findRelationsInStore } from 'atom.io/data';
6
6
  import * as AtomIO from 'atom.io';
7
- import { selectorFamily, atomFamily, atom } from 'atom.io';
8
- import { SyncGroup, roomIndex, usersInRooms } from 'atom.io/realtime';
7
+ import { atomFamily, selectorFamily, atom } from 'atom.io';
8
+ import { roomIndex, usersInRooms } from 'atom.io/realtime';
9
9
  import { spawn } from 'child_process';
10
10
 
11
11
  // realtime-server/src/ipc-sockets/custom-socket.ts
@@ -329,67 +329,6 @@ function realtimeActionReceiver({
329
329
  };
330
330
  };
331
331
  }
332
- selectorFamily({
333
- key: `perspectiveRedactor`,
334
- get: ({ userId, syncGroupKey }) => ({ get, find }) => {
335
- const syncGroup = SyncGroup.existing.get(syncGroupKey);
336
- if (!syncGroup) {
337
- throw new Error(
338
- `Tried to create a synchronizer for a sync group that does not exist.`
339
- );
340
- }
341
- const userPerspectiveTokens = syncGroup.perspectives.flatMap(
342
- ({ viewAtoms }) => {
343
- const userPerspectiveToken = find(viewAtoms, userId);
344
- const userPerspective = get(userPerspectiveToken);
345
- const visibleTokens = [...userPerspective].map((token) => {
346
- return token.type === `mutable_atom` ? getUpdateToken(token).key : token.key;
347
- });
348
- IMPLICIT.STORE.logger.info(
349
- `\u{1F52D}`,
350
- `continuity`,
351
- syncGroupKey,
352
- `${userId} can see ${visibleTokens.length} tokens in ${viewAtoms.key}`,
353
- visibleTokens
354
- );
355
- return visibleTokens;
356
- }
357
- );
358
- const filterTransactionUpdate = (visible, transactionUpdate) => {
359
- IMPLICIT.STORE.logger.info(
360
- `\u{1F58C}`,
361
- `continuity`,
362
- syncGroupKey,
363
- `redacting updates from ${transactionUpdate.epoch}:${transactionUpdate.key}:${transactionUpdate.id}`,
364
- visible,
365
- transactionUpdate.updates
366
- );
367
- const updates = transactionUpdate.updates.filter((update) => {
368
- if (`newValue` in update) {
369
- return visible.includes(update.key);
370
- }
371
- return true;
372
- }).map((update) => {
373
- if (`updates` in update) {
374
- return filterTransactionUpdate(visible, update);
375
- }
376
- return update;
377
- });
378
- const filtered = __spreadProps(__spreadValues({}, transactionUpdate), {
379
- updates
380
- });
381
- return filtered;
382
- };
383
- const filter = (update) => {
384
- const visibleKeys = syncGroup.globals.map(
385
- (atomToken) => atomToken.type === `mutable_atom` ? getUpdateToken(atomToken).key : atomToken.key
386
- );
387
- visibleKeys.push(...userPerspectiveTokens);
388
- return filterTransactionUpdate(visibleKeys, update);
389
- };
390
- return filter;
391
- }
392
- });
393
332
  var roomArgumentsAtoms = atomFamily({
394
333
  key: `roomArguments`,
395
334
  default: [`echo`, [`Hello World!`]]
@@ -1,4 +1,3 @@
1
- export * from "./realtime-continuity-store"
2
1
  export * from "./server-room-external-actions"
3
2
  export * from "./server-room-external-store"
4
3
  export * from "./server-sync-store"
@@ -57,7 +57,7 @@ export type MoleculeDisposal = {
57
57
  token: MoleculeToken<any>
58
58
  family: MoleculeFamilyToken<any>
59
59
  context: MoleculeToken<any>[]
60
- familyKeys: string[]
60
+ values: [key: string, value: any][]
61
61
  }
62
62
 
63
63
  export type TransactionUpdateContent =
@@ -1,265 +0,0 @@
1
- import type {
2
- AtomToken,
3
- Func,
4
- TimelineUpdate,
5
- TransactionToken,
6
- TransactionUpdate,
7
- } from "atom.io"
8
-
9
- import { newest } from "../lineage"
10
- import { getUpdateToken } from "../mutable"
11
- import type { Store } from "../store"
12
- import { withdraw } from "../store"
13
- import type {
14
- Timeline,
15
- TimelineAtomUpdate,
16
- TimelineTransactionUpdate,
17
- } from "./create-timeline"
18
-
19
- export const addAtomToTimeline = (
20
- atomToken: AtomToken<any>,
21
- tl: Timeline<any>,
22
- store: Store,
23
- ): void => {
24
- let maybeAtom = withdraw(atomToken, store)
25
- if (maybeAtom.type === `mutable_atom`) {
26
- const updateToken = getUpdateToken(maybeAtom)
27
- maybeAtom = withdraw(updateToken, store)
28
- }
29
- const atom = maybeAtom
30
- store.timelineAtoms.set({ atomKey: atom.key, timelineKey: tl.key })
31
-
32
- tl.subscriptions.set(
33
- atom.key,
34
- atom.subject.subscribe(`timeline`, (update) => {
35
- const target = newest(store)
36
- const currentSelectorKey =
37
- store.operation.open && store.operation.token.type === `selector`
38
- ? store.operation.token.key
39
- : null
40
- const currentSelectorTime =
41
- store.operation.open && store.operation.token.type === `selector`
42
- ? store.operation.time
43
- : null
44
- const { transactionApplying } = target.on
45
- const currentTransactionKey = transactionApplying.state?.update.key
46
- const currentTransactionInstanceId = transactionApplying.state?.update.id
47
-
48
- store.logger.info(
49
- `⏳`,
50
- `timeline`,
51
- tl.key,
52
- `atom`,
53
- atomToken.key,
54
- `went`,
55
- update.oldValue,
56
- `->`,
57
- update.newValue,
58
- currentTransactionKey
59
- ? `in transaction "${currentTransactionKey}"`
60
- : currentSelectorKey
61
- ? `in selector "${currentSelectorKey}"`
62
- : ``,
63
- )
64
- if (tl.timeTraveling === null) {
65
- if (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {
66
- const mostRecentUpdate: TimelineUpdate<any> | undefined =
67
- tl.history.at(-1)
68
- if (mostRecentUpdate === undefined) {
69
- throw new Error(
70
- `Timeline "${tl.key}" has a selectorTime, but no history. This is most likely a bug in AtomIO.`,
71
- )
72
- }
73
- }
74
- if (currentTransactionKey) {
75
- const txToken: TransactionToken<any> = {
76
- key: currentTransactionKey,
77
- type: `transaction`,
78
- }
79
- const currentTransaction = withdraw(txToken, store)
80
- if (tl.transactionKey !== currentTransactionKey) {
81
- if (tl.transactionKey) {
82
- store.logger.error(
83
- `🐞`,
84
- `timeline`,
85
- tl.key,
86
- `unable to resolve transaction "${tl.transactionKey}. This is probably a bug in AtomIO.`,
87
- )
88
- }
89
- tl.transactionKey = currentTransactionKey
90
- const unsubscribe = currentTransaction.subject.subscribe(
91
- `timeline:${tl.key}`,
92
- (transactionUpdate) => {
93
- unsubscribe()
94
- if (tl.timeTraveling === null && currentTransactionInstanceId) {
95
- if (tl.at !== tl.history.length) {
96
- tl.history.splice(tl.at)
97
- }
98
-
99
- const filterUpdates = (
100
- updates: TransactionUpdate<Func>[`updates`],
101
- ) =>
102
- updates
103
- .filter((updateFromTx) => {
104
- const newestStore = newest(store)
105
- if (`updates` in updateFromTx) {
106
- return true
107
- }
108
- const atomOrFamilyKeys =
109
- newestStore.timelineAtoms.getRelatedKeys(tl.key)
110
-
111
- if (!atomOrFamilyKeys) {
112
- return false
113
- }
114
- let key: string | undefined
115
- let familyKey: string | undefined
116
- switch (updateFromTx.type) {
117
- case `state_creation`:
118
- case `state_disposal`:
119
- key = updateFromTx.token.key
120
- familyKey = updateFromTx.token.family?.key
121
- break
122
- case `molecule_creation`:
123
- case `molecule_disposal`:
124
- break
125
- default:
126
- key = updateFromTx.key
127
- familyKey = updateFromTx.family?.key
128
- break
129
- }
130
- if (key === undefined) {
131
- return false
132
- }
133
- if (atomOrFamilyKeys.has(key)) {
134
- return true
135
- }
136
- if (familyKey !== undefined) {
137
- return atomOrFamilyKeys.has(familyKey)
138
- }
139
- return false
140
- })
141
- .map((updateFromTx) => {
142
- if (`updates` in updateFromTx) {
143
- return {
144
- ...updateFromTx,
145
- updates: filterUpdates(updateFromTx.updates),
146
- }
147
- }
148
- return updateFromTx
149
- })
150
-
151
- const updates = filterUpdates(transactionUpdate.updates)
152
-
153
- const timelineTransactionUpdate: TimelineTransactionUpdate = {
154
- timestamp: Date.now(),
155
- ...transactionUpdate,
156
- updates,
157
- }
158
- const willCapture =
159
- tl.shouldCapture?.(timelineTransactionUpdate, tl) ?? true
160
- if (willCapture) {
161
- tl.history.push(timelineTransactionUpdate)
162
- tl.at = tl.history.length
163
- tl.subject.next(timelineTransactionUpdate)
164
- }
165
- }
166
- tl.transactionKey = null
167
- store.logger.info(
168
- `⌛`,
169
- `timeline`,
170
- tl.key,
171
- `got a transaction_update "${transactionUpdate.key}"`,
172
- )
173
- },
174
- )
175
- }
176
- } else if (currentSelectorKey && currentSelectorTime) {
177
- let latestUpdate: TimelineUpdate<any> | undefined = tl.history.at(-1)
178
-
179
- if (currentSelectorTime !== tl.selectorTime) {
180
- latestUpdate = {
181
- type: `selector_update`,
182
- timestamp: currentSelectorTime,
183
- key: currentSelectorKey,
184
- atomUpdates: [],
185
- }
186
- latestUpdate.atomUpdates.push({
187
- key: atom.key,
188
- type: `atom_update`,
189
- ...update,
190
- })
191
- if (tl.at !== tl.history.length) {
192
- tl.history.splice(tl.at)
193
- }
194
-
195
- tl.history.push(latestUpdate)
196
-
197
- store.logger.info(
198
- `⌛`,
199
- `timeline`,
200
- tl.key,
201
- `got a selector_update "${currentSelectorKey}" with`,
202
- latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key),
203
- )
204
-
205
- tl.at = tl.history.length
206
- tl.selectorTime = currentSelectorTime
207
- } else {
208
- if (latestUpdate?.type === `selector_update`) {
209
- latestUpdate.atomUpdates.push({
210
- key: atom.key,
211
- type: `atom_update`,
212
- ...update,
213
- })
214
- store.logger.info(
215
- `⌛`,
216
- `timeline`,
217
- tl.key,
218
- `set selector_update "${currentSelectorKey}" to`,
219
- latestUpdate?.atomUpdates.map((atomUpdate) => atomUpdate.key),
220
- )
221
- }
222
- }
223
- if (latestUpdate) {
224
- const willCaptureSelectorUpdate =
225
- tl.shouldCapture?.(latestUpdate, tl) ?? true
226
- if (willCaptureSelectorUpdate) {
227
- tl.subject.next(latestUpdate)
228
- } else {
229
- tl.history.pop()
230
- tl.at = tl.history.length
231
- }
232
- }
233
- } else {
234
- const timestamp = Date.now()
235
- tl.selectorTime = null
236
- if (tl.at !== tl.history.length) {
237
- tl.history.splice(tl.at)
238
- }
239
- const atomUpdate: TimelineAtomUpdate<any> = {
240
- type: `atom_update`,
241
- timestamp,
242
- key: atom.key,
243
- oldValue: update.oldValue,
244
- newValue: update.newValue,
245
- }
246
- if (atom.family) {
247
- atomUpdate.family = atom.family
248
- }
249
- const willCapture = tl.shouldCapture?.(atomUpdate, tl) ?? true
250
- store.logger.info(
251
- `⌛`,
252
- `timeline`,
253
- tl.key,
254
- `got an atom_update to "${atom.key}"`,
255
- )
256
- if (willCapture) {
257
- tl.history.push(atomUpdate)
258
- tl.at = tl.history.length
259
- tl.subject.next(atomUpdate)
260
- }
261
- }
262
- }
263
- }),
264
- )
265
- }
@@ -1,109 +0,0 @@
1
- import type { TransactionUpdate } from "atom.io"
2
- import { selectorFamily } from "atom.io"
3
- import { getJsonToken, getUpdateToken, IMPLICIT } from "atom.io/internal"
4
- import type { JsonIO } from "atom.io/json"
5
- import { SyncGroup } from "atom.io/realtime"
6
- // import { completeUpdateAtoms } from "atom.io/realtime-server"
7
-
8
- const redactorAtoms = selectorFamily<
9
- (update: TransactionUpdate<any>) => TransactionUpdate<any>,
10
- { userId: string; syncGroupKey: string }
11
- >({
12
- key: `perspectiveRedactor`,
13
- get:
14
- ({ userId, syncGroupKey }) =>
15
- ({ get, find }) => {
16
- const syncGroup = SyncGroup.existing.get(syncGroupKey)
17
- if (!syncGroup) {
18
- throw new Error(
19
- `Tried to create a synchronizer for a sync group that does not exist.`,
20
- )
21
- }
22
-
23
- const userPerspectiveTokens = syncGroup.perspectives.flatMap(
24
- ({ viewAtoms }) => {
25
- const userPerspectiveToken = find(viewAtoms, userId)
26
- const userPerspective = get(userPerspectiveToken)
27
- const visibleTokens = [...userPerspective].map((token) => {
28
- return token.type === `mutable_atom`
29
- ? getUpdateToken(token).key
30
- : token.key
31
- })
32
- IMPLICIT.STORE.logger.info(
33
- `🔭`,
34
- `continuity`,
35
- syncGroupKey,
36
- `${userId} can see ${visibleTokens.length} tokens in ${viewAtoms.key}`,
37
- visibleTokens,
38
- )
39
- return visibleTokens
40
- },
41
- )
42
-
43
- const filterTransactionUpdate = (
44
- visible: string[],
45
- transactionUpdate: TransactionUpdate<any>,
46
- ): TransactionUpdate<any> => {
47
- IMPLICIT.STORE.logger.info(
48
- `🖌`,
49
- `continuity`,
50
- syncGroupKey,
51
- `redacting updates from ${transactionUpdate.epoch}:${transactionUpdate.key}:${transactionUpdate.id}`,
52
- visible,
53
- transactionUpdate.updates,
54
- )
55
- const updates = transactionUpdate.updates
56
- .filter((update) => {
57
- if (`newValue` in update) {
58
- return visible.includes(update.key)
59
- }
60
- return true
61
- })
62
- .map((update) => {
63
- if (`updates` in update) {
64
- return filterTransactionUpdate(visible, update)
65
- }
66
- return update
67
- })
68
- const filtered: TransactionUpdate<any> = {
69
- ...transactionUpdate,
70
- updates,
71
- }
72
- return filtered
73
- }
74
- const filter: (updates: TransactionUpdate<any>) => TransactionUpdate<any> =
75
- (update) => {
76
- const visibleKeys: string[] = syncGroup.globals.map((atomToken) =>
77
- atomToken.type === `mutable_atom`
78
- ? getUpdateToken(atomToken).key
79
- : atomToken.key,
80
- )
81
- visibleKeys.push(...userPerspectiveTokens)
82
- return filterTransactionUpdate(visibleKeys, update)
83
- }
84
- return filter
85
- },
86
- })
87
- // export const occludedUpdateSelectors = selectorFamily<
88
- // Pick<
89
- // TransactionUpdate<JsonIO>,
90
- // `epoch` | `id` | `key` | `output` | `updates`
91
- // > | null,
92
- // { userId: string; syncGroupKey: string; updateId: string }
93
- // >({
94
- // key: `occludedUpdate`,
95
- // get:
96
- // ({ userId, syncGroupKey, updateId }) =>
97
- // ({ get, find }) => {
98
- // const updateState = find(completeUpdateAtoms, updateId)
99
- // const update = get(updateState)
100
- // const redactorKey = { userId, syncGroupKey }
101
- // const redactorState = find(redactorAtoms, redactorKey)
102
- // const redact = get(redactorState)
103
- // if (update) {
104
- // // return redact(update)
105
- // return update
106
- // }
107
- // return null
108
- // },
109
- // })