atom.io 0.16.1 → 0.16.3
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 +31 -14
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.js +31 -14
- package/data/dist/index.js.map +1 -1
- package/data/src/join.ts +31 -14
- package/dist/chunk-H4Q5FTPZ.js +11 -0
- package/dist/chunk-H4Q5FTPZ.js.map +1 -0
- package/dist/index.cjs +7 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.js +8 -14
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +240 -193
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +30 -9
- package/internal/dist/index.js +233 -194
- package/internal/dist/index.js.map +1 -1
- package/internal/src/families/find-in-store.ts +74 -0
- package/internal/src/families/index.ts +1 -0
- package/internal/src/ingest-updates/ingest-transaction-update.ts +1 -0
- package/internal/src/mutable/tracker.ts +37 -32
- package/internal/src/mutable/transceiver.ts +1 -1
- package/internal/src/not-found-error.ts +14 -3
- package/internal/src/operation.ts +2 -1
- package/internal/src/selector/create-writable-selector.ts +2 -1
- package/internal/src/selector/register-selector.ts +5 -4
- package/internal/src/set-state/set-atom.ts +23 -6
- package/internal/src/set-state/stow-update.ts +2 -4
- package/internal/src/store/store.ts +13 -4
- package/internal/src/timeline/add-atom-to-timeline.ts +5 -5
- package/internal/src/transaction/abort-transaction.ts +2 -1
- package/internal/src/transaction/apply-transaction.ts +5 -3
- package/internal/src/transaction/build-transaction.ts +17 -10
- package/internal/src/transaction/create-transaction.ts +2 -3
- package/internal/src/transaction/index.ts +3 -2
- package/internal/src/transaction/is-root-store.ts +23 -0
- package/package.json +10 -10
- package/react/dist/index.cjs +27 -21
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.ts +8 -2
- package/react/dist/index.js +27 -21
- package/react/dist/index.js.map +1 -1
- package/react/src/index.ts +4 -1
- package/react/src/use-i.ts +36 -0
- package/react/src/use-json.ts +38 -0
- package/react/src/use-o.ts +34 -0
- package/react/src/use-tl.ts +45 -0
- package/realtime-client/dist/index.cjs +163 -62
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +10 -6
- package/realtime-client/dist/index.js +153 -60
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +2 -1
- package/realtime-client/src/pull-state.ts +4 -3
- package/realtime-client/src/{realtime-client-store.ts → realtime-client-stores/client-main-store.ts} +0 -8
- package/realtime-client/src/realtime-client-stores/client-sync-store.ts +15 -0
- package/realtime-client/src/realtime-client-stores/index.ts +2 -0
- package/realtime-client/src/sync-server-action.ts +131 -39
- package/realtime-client/src/sync-state.ts +19 -0
- package/realtime-react/dist/index.cjs +43 -26
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +3 -1
- package/realtime-react/dist/index.js +41 -25
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/index.ts +1 -0
- package/realtime-react/src/on-mount.ts +3 -21
- package/realtime-react/src/use-realtime-service.ts +1 -1
- package/realtime-react/src/use-server-action.ts +1 -1
- package/realtime-react/src/use-single-effect.ts +29 -0
- package/realtime-react/src/use-sync-server-action.ts +5 -8
- package/realtime-react/src/use-sync.ts +17 -0
- package/realtime-server/dist/index.cjs +242 -48
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +147 -9
- package/realtime-server/dist/index.js +232 -51
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/index.ts +2 -0
- package/realtime-server/src/realtime-action-receiver.ts +4 -3
- package/realtime-server/src/realtime-action-synchronizer.ts +100 -13
- package/realtime-server/src/realtime-family-provider.ts +10 -6
- package/realtime-server/src/realtime-mutable-family-provider.ts +15 -18
- package/realtime-server/src/realtime-mutable-provider.ts +1 -0
- package/realtime-server/src/realtime-server-stores/index.ts +2 -0
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +115 -0
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +45 -0
- package/realtime-server/src/realtime-state-provider.ts +16 -8
- package/realtime-server/src/realtime-state-receiver.ts +1 -0
- package/realtime-server/src/realtime-state-synchronizer.ts +23 -0
- package/realtime-testing/dist/index.cjs +65 -26
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.ts +11 -7
- package/realtime-testing/dist/index.js +64 -26
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +83 -43
- package/src/find-state.ts +8 -16
- package/src/logger.ts +16 -11
- package/src/transaction.ts +4 -4
- package/react/src/store-hooks.ts +0 -87
- package/realtime-server/src/realtime-server-store.ts +0 -39
package/src/find-state.ts
CHANGED
|
@@ -12,50 +12,42 @@ import type {
|
|
|
12
12
|
WritableSelectorToken,
|
|
13
13
|
WritableToken,
|
|
14
14
|
} from "atom.io"
|
|
15
|
-
import type {
|
|
16
|
-
import { IMPLICIT } from "atom.io/internal"
|
|
15
|
+
import type { Transceiver } from "atom.io/internal"
|
|
16
|
+
import { IMPLICIT, findInStore } from "atom.io/internal"
|
|
17
17
|
import type { Json } from "atom.io/json"
|
|
18
18
|
|
|
19
|
-
export function findInStore(
|
|
20
|
-
token: ReadableFamilyToken<any, any>,
|
|
21
|
-
key: Json.Serializable,
|
|
22
|
-
store: Store,
|
|
23
|
-
): ReadableToken<any> {
|
|
24
|
-
const familyKey = token.key
|
|
25
|
-
const family = store.families.get(familyKey)
|
|
26
|
-
if (family === undefined) {
|
|
27
|
-
throw new Error(`Family ${familyKey} not found`)
|
|
28
|
-
}
|
|
29
|
-
const state = family(key)
|
|
30
|
-
return state
|
|
31
|
-
}
|
|
32
|
-
|
|
33
19
|
export function findState<
|
|
34
20
|
T extends Transceiver<any>,
|
|
35
21
|
J extends Json.Serializable,
|
|
36
22
|
K extends Json.Serializable,
|
|
37
23
|
Key extends K,
|
|
38
24
|
>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J>
|
|
25
|
+
|
|
39
26
|
export function findState<T, K extends Json.Serializable, Key extends K>(
|
|
40
27
|
token: RegularAtomFamilyToken<T, K>,
|
|
41
28
|
key: Key,
|
|
42
29
|
): RegularAtomToken<T>
|
|
30
|
+
|
|
43
31
|
export function findState<T, K extends Json.Serializable, Key extends K>(
|
|
44
32
|
token: WritableSelectorFamilyToken<T, K>,
|
|
45
33
|
key: Key,
|
|
46
34
|
): WritableSelectorToken<T>
|
|
35
|
+
|
|
47
36
|
export function findState<T, K extends Json.Serializable, Key extends K>(
|
|
48
37
|
token: ReadonlySelectorFamilyToken<T, K>,
|
|
49
38
|
key: Key,
|
|
50
39
|
): ReadonlySelectorToken<T>
|
|
40
|
+
|
|
51
41
|
export function findState<T, K extends Json.Serializable, Key extends K>(
|
|
52
42
|
token: WritableFamilyToken<T, K>,
|
|
53
43
|
key: Key,
|
|
54
44
|
): WritableToken<T>
|
|
45
|
+
|
|
55
46
|
export function findState<T, K extends Json.Serializable, Key extends K>(
|
|
56
47
|
token: ReadableFamilyToken<T, K>,
|
|
57
48
|
key: Key,
|
|
58
49
|
): ReadableToken<T>
|
|
50
|
+
|
|
59
51
|
export function findState(
|
|
60
52
|
token: ReadableFamilyToken<any, any>,
|
|
61
53
|
key: Json.Serializable,
|
package/src/logger.ts
CHANGED
|
@@ -39,21 +39,23 @@ const LoggerIconDictionary = {
|
|
|
39
39
|
"🚀": `Performance measure`,
|
|
40
40
|
} as const
|
|
41
41
|
export type LoggerIcon = keyof typeof LoggerIconDictionary
|
|
42
|
+
export type TokenDenomination =
|
|
43
|
+
| `atom`
|
|
44
|
+
| `mutable_atom`
|
|
45
|
+
| `readonly_selector`
|
|
46
|
+
| `realtime_sync_group`
|
|
47
|
+
| `selector`
|
|
48
|
+
| `state`
|
|
49
|
+
| `timeline`
|
|
50
|
+
| `transaction`
|
|
51
|
+
| `unknown`
|
|
42
52
|
|
|
43
53
|
export const LOG_LEVELS = [`info`, `warn`, `error`] as const
|
|
44
54
|
export type LogLevel = (typeof LOG_LEVELS)[number]
|
|
45
55
|
|
|
46
56
|
export type LogFn = (
|
|
47
57
|
icon: LoggerIcon,
|
|
48
|
-
|
|
49
|
-
| `atom`
|
|
50
|
-
| `mutable_atom`
|
|
51
|
-
| `readonly_selector`
|
|
52
|
-
| `selector`
|
|
53
|
-
| `state`
|
|
54
|
-
| `timeline`
|
|
55
|
-
| `transaction`
|
|
56
|
-
| `unknown`,
|
|
58
|
+
denomination: TokenDenomination,
|
|
57
59
|
tokenKey: string,
|
|
58
60
|
message: string,
|
|
59
61
|
...rest: unknown[]
|
|
@@ -64,8 +66,11 @@ export type Logger = Record<LogLevel, LogFn>
|
|
|
64
66
|
|
|
65
67
|
export const simpleLog =
|
|
66
68
|
(logLevel: keyof Logger): LogFn =>
|
|
67
|
-
(icon,
|
|
68
|
-
console[logLevel](
|
|
69
|
+
(icon, denomination, tokenKey, message, ...rest) => {
|
|
70
|
+
console[logLevel](
|
|
71
|
+
`${icon} ${denomination} "${tokenKey}" ${message}`,
|
|
72
|
+
...rest,
|
|
73
|
+
)
|
|
69
74
|
}
|
|
70
75
|
export const simpleLogger: Logger = {
|
|
71
76
|
error: simpleLog(`error`),
|
package/src/transaction.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { EnvironmentData, Store } from "atom.io/internal"
|
|
2
2
|
import { IMPLICIT, createTransaction, withdraw } from "atom.io/internal"
|
|
3
|
-
import type { Json } from "atom.io/json"
|
|
4
3
|
|
|
5
4
|
import type {
|
|
6
5
|
KeyedStateUpdate,
|
|
@@ -10,10 +9,10 @@ import type {
|
|
|
10
9
|
ƒn,
|
|
11
10
|
} from "."
|
|
12
11
|
|
|
13
|
-
export type TransactionToken<
|
|
12
|
+
export type TransactionToken<F> = {
|
|
14
13
|
key: string
|
|
15
14
|
type: `transaction`
|
|
16
|
-
|
|
15
|
+
__F?: F
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
export type TransactionUpdateContent =
|
|
@@ -23,6 +22,7 @@ export type TransactionUpdateContent =
|
|
|
23
22
|
export type TransactionUpdate<ƒ extends ƒn> = {
|
|
24
23
|
key: string
|
|
25
24
|
id: string
|
|
25
|
+
epoch: number
|
|
26
26
|
updates: TransactionUpdateContent[]
|
|
27
27
|
params: Parameters<ƒ>
|
|
28
28
|
output: ReturnType<ƒ>
|
|
@@ -80,8 +80,8 @@ export function transaction<ƒ extends ƒn>(
|
|
|
80
80
|
export const runTransaction =
|
|
81
81
|
<ƒ extends ƒn>(
|
|
82
82
|
token: TransactionToken<ƒ>,
|
|
83
|
-
store: Store = IMPLICIT.STORE,
|
|
84
83
|
id?: string,
|
|
84
|
+
store: Store = IMPLICIT.STORE,
|
|
85
85
|
) =>
|
|
86
86
|
(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {
|
|
87
87
|
const tx = withdraw(token, store)
|
package/react/src/store-hooks.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import * as React from "react"
|
|
2
|
-
|
|
3
|
-
import { getState, redo, setState, undo } from "atom.io"
|
|
4
|
-
import type {
|
|
5
|
-
MutableAtomToken,
|
|
6
|
-
ReadableToken,
|
|
7
|
-
TimelineToken,
|
|
8
|
-
WritableToken,
|
|
9
|
-
} from "atom.io"
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
getJsonToken,
|
|
13
|
-
subscribeToState,
|
|
14
|
-
subscribeToTimeline,
|
|
15
|
-
withdraw,
|
|
16
|
-
} from "atom.io/internal"
|
|
17
|
-
import type { Json } from "atom.io/json"
|
|
18
|
-
import { StoreContext } from "./store-context"
|
|
19
|
-
|
|
20
|
-
export function useI<T>(
|
|
21
|
-
token: WritableToken<T>,
|
|
22
|
-
): <New extends T>(next: New | ((old: T) => New)) => void {
|
|
23
|
-
const store = React.useContext(StoreContext)
|
|
24
|
-
const setter: React.MutableRefObject<
|
|
25
|
-
(<New extends T>(next: New | ((old: T) => New)) => void) | null
|
|
26
|
-
> = React.useRef(null)
|
|
27
|
-
if (setter.current === null) {
|
|
28
|
-
setter.current = (next) => setState(token, next, store)
|
|
29
|
-
}
|
|
30
|
-
return setter.current
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function useO<T>(token: ReadableToken<T>): T {
|
|
34
|
-
const store = React.useContext(StoreContext)
|
|
35
|
-
const id = React.useId()
|
|
36
|
-
return React.useSyncExternalStore<T>(
|
|
37
|
-
(dispatch) => subscribeToState(token, dispatch, `use-o:${id}`, store),
|
|
38
|
-
() => getState(token, store),
|
|
39
|
-
() => getState(token, store),
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function useJSON<Serializable extends Json.Serializable>(
|
|
44
|
-
token: MutableAtomToken<any, Serializable>,
|
|
45
|
-
): Serializable {
|
|
46
|
-
const jsonToken = getJsonToken(token)
|
|
47
|
-
return useO(jsonToken)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export type TimelineMeta = {
|
|
51
|
-
at: number
|
|
52
|
-
length: number
|
|
53
|
-
undo: () => void
|
|
54
|
-
redo: () => void
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function useTL(token: TimelineToken<any>): TimelineMeta {
|
|
58
|
-
const store = React.useContext(StoreContext)
|
|
59
|
-
const id = React.useId()
|
|
60
|
-
const timeline = withdraw(token, store)
|
|
61
|
-
const tokenRef = React.useRef(token)
|
|
62
|
-
const rebuildMeta = () => {
|
|
63
|
-
return {
|
|
64
|
-
at: timeline?.at ?? NaN,
|
|
65
|
-
length: timeline?.history.length ?? NaN,
|
|
66
|
-
undo: () => undo(token),
|
|
67
|
-
redo: () => redo(token),
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const meta = React.useRef<TimelineMeta>(rebuildMeta())
|
|
71
|
-
const retrieve = () => {
|
|
72
|
-
if (
|
|
73
|
-
meta.current.at !== timeline?.at ||
|
|
74
|
-
meta.current.length !== timeline?.history.length ||
|
|
75
|
-
tokenRef.current !== token
|
|
76
|
-
) {
|
|
77
|
-
tokenRef.current = token
|
|
78
|
-
meta.current = rebuildMeta()
|
|
79
|
-
}
|
|
80
|
-
return meta.current
|
|
81
|
-
}
|
|
82
|
-
return React.useSyncExternalStore<TimelineMeta>(
|
|
83
|
-
(dispatch) => subscribeToTimeline(token, dispatch, `use-tl:${id}`, store),
|
|
84
|
-
retrieve,
|
|
85
|
-
retrieve,
|
|
86
|
-
)
|
|
87
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as AtomIO from "atom.io"
|
|
2
|
-
|
|
3
|
-
export const completeUpdateAtoms = AtomIO.atomFamily<
|
|
4
|
-
AtomIO.TransactionUpdate<any> | null,
|
|
5
|
-
string
|
|
6
|
-
>({
|
|
7
|
-
key: `completeUpdate`,
|
|
8
|
-
default: null,
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
export const transactionRedactorAtoms = AtomIO.atomFamily<
|
|
12
|
-
{
|
|
13
|
-
filter: (
|
|
14
|
-
updates: AtomIO.TransactionUpdateContent[],
|
|
15
|
-
) => AtomIO.TransactionUpdateContent[]
|
|
16
|
-
},
|
|
17
|
-
string
|
|
18
|
-
>({
|
|
19
|
-
key: `transactionRedactor`,
|
|
20
|
-
default: { filter: (updates) => updates },
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
export const redactedUpdateSelectors = AtomIO.selectorFamily<
|
|
24
|
-
AtomIO.TransactionUpdate<any> | null,
|
|
25
|
-
[transactionKey: string, updateId: string]
|
|
26
|
-
>({
|
|
27
|
-
key: `redactedUpdate`,
|
|
28
|
-
get:
|
|
29
|
-
([transactionKey, updateId]) =>
|
|
30
|
-
({ get, find }) => {
|
|
31
|
-
const update = get(find(completeUpdateAtoms, updateId))
|
|
32
|
-
const { filter } = get(find(transactionRedactorAtoms, transactionKey))
|
|
33
|
-
|
|
34
|
-
if (update && filter) {
|
|
35
|
-
return { ...update, updates: filter(update.updates) }
|
|
36
|
-
}
|
|
37
|
-
return null
|
|
38
|
-
},
|
|
39
|
-
})
|