atom.io 0.35.0 → 0.36.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/dist/eslint-plugin/index.d.ts +2 -18
- package/dist/eslint-plugin/index.d.ts.map +1 -1
- package/dist/eslint-plugin/index.js +4 -141
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/internal/index.d.ts +100 -78
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +180 -163
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +5 -6
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js +2 -3
- package/dist/introspection/index.js.map +1 -1
- package/dist/json/index.d.ts +2 -10
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +1 -31
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +38 -39
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +15 -16
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts +4 -4
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +2 -6
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +7 -8
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +3 -4
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +4 -4
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +18 -18
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +5 -9
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts +9 -2
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js +3 -0
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/package.json +6 -6
- package/src/eslint-plugin/index.ts +0 -1
- package/src/eslint-plugin/rules/explicit-state-types.ts +8 -1
- package/src/eslint-plugin/rules/index.ts +0 -1
- package/src/internal/atom/create-regular-atom.ts +5 -5
- package/src/internal/atom/dispose-atom.ts +1 -0
- package/src/internal/atom/has-role.ts +12 -0
- package/src/internal/atom/index.ts +1 -0
- package/src/internal/caching.ts +38 -16
- package/src/internal/families/find-in-store.ts +4 -5
- package/src/internal/families/get-family-of-token.ts +4 -5
- package/src/internal/families/init-family-member.ts +3 -4
- package/src/internal/families/seek-in-store.ts +4 -5
- package/src/internal/get-state/read-or-compute-value.ts +37 -16
- package/src/internal/index.ts +19 -21
- package/src/internal/ingest-updates/ingest-creation-disposal.ts +18 -15
- package/src/internal/ingest-updates/ingest-selector-update.ts +9 -5
- package/src/internal/join/get-internal-relations-from-store.ts +2 -2
- package/src/internal/join/join-internal.ts +10 -18
- package/src/internal/molecule.ts +1 -0
- package/src/internal/mutable/create-mutable-atom-family.ts +40 -22
- package/src/internal/mutable/create-mutable-atom.ts +16 -12
- package/src/internal/mutable/get-json-family.ts +7 -6
- package/src/internal/mutable/get-json-token.ts +6 -13
- package/src/internal/mutable/get-update-family.ts +7 -8
- package/src/internal/mutable/get-update-token.ts +5 -9
- package/src/internal/mutable/tracker-family.ts +31 -38
- package/src/internal/mutable/tracker.ts +86 -104
- package/src/internal/mutable/transceiver.ts +37 -9
- package/src/internal/selector/create-readonly-held-selector.ts +2 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +2 -2
- package/src/internal/selector/create-writable-held-selector.ts +3 -3
- package/src/internal/selector/create-writable-pure-selector.ts +3 -3
- package/src/internal/selector/dispose-selector.ts +9 -9
- package/src/internal/set-state/reset-atom-or-selector.ts +11 -4
- package/src/internal/set-state/set-atom.ts +15 -22
- package/src/internal/set-state/set-into-store.ts +5 -4
- package/src/internal/store/counterfeit.ts +3 -4
- package/src/internal/store/deposit.ts +8 -11
- package/src/internal/store/store.ts +7 -7
- package/src/internal/store/withdraw.ts +8 -12
- package/src/internal/subscribe/subscribe-in-store.ts +2 -2
- package/src/internal/subscribe/subscribe-to-transaction.ts +2 -2
- package/src/internal/timeline/create-timeline.ts +3 -3
- package/src/internal/transaction/act-upon-store.ts +2 -2
- package/src/internal/transaction/apply-transaction.ts +2 -2
- package/src/internal/transaction/build-transaction.ts +2 -2
- package/src/internal/transaction/create-transaction.ts +3 -3
- package/src/internal/transaction/index.ts +2 -2
- package/src/internal/transaction/is-root-store.ts +4 -2
- package/src/internal/utility-types.ts +1 -1
- package/src/introspection/attach-introspection-states.ts +3 -3
- package/src/introspection/attach-transaction-index.ts +4 -4
- package/src/introspection/attach-transaction-logs.ts +4 -4
- package/src/introspection/auditor.ts +3 -3
- package/src/json/index.ts +0 -2
- package/src/main/atom.ts +24 -36
- package/src/main/dispose-state.ts +6 -5
- package/src/main/find-state.ts +3 -4
- package/src/main/get-state.ts +6 -5
- package/src/main/join.ts +2 -2
- package/src/main/logger.ts +7 -7
- package/src/main/reset-state.ts +3 -3
- package/src/main/set-state.ts +3 -3
- package/src/main/subscribe.ts +3 -3
- package/src/main/tokens.ts +8 -14
- package/src/main/transaction.ts +17 -13
- package/src/main/validators.ts +1 -1
- package/src/react/use-json.ts +14 -24
- package/src/react-devtools/TransactionIndex.tsx +3 -3
- package/src/react-devtools/Updates.tsx +2 -2
- package/src/realtime/shared-room-store.ts +11 -22
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +2 -2
- package/src/realtime-client/pull-mutable-atom-family-member.ts +8 -17
- package/src/realtime-client/pull-mutable-atom.ts +7 -14
- package/src/realtime-client/push-state.ts +6 -5
- package/src/realtime-client/server-action.ts +5 -4
- package/src/realtime-react/use-pull-mutable-atom.ts +3 -5
- package/src/realtime-react/use-pull-mutable-family-member.ts +3 -4
- package/src/realtime-react/use-server-action.ts +2 -2
- package/src/realtime-server/realtime-mutable-family-provider.ts +3 -4
- package/src/realtime-server/realtime-mutable-provider.ts +2 -3
- package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +6 -5
- package/src/realtime-server/realtime-server-stores/server-user-store.ts +8 -15
- package/src/transceivers/set-rtx/set-rtx.ts +14 -1
- package/src/eslint-plugin/rules/synchronous-selector-dependencies.ts +0 -140
- package/src/eslint-plugin/walk.ts +0 -81
- package/src/internal/set-state/copy-mutable-if-needed.ts +0 -27
- package/src/json/select-json-family.ts +0 -55
- package/src/json/select-json.ts +0 -19
|
@@ -8,12 +8,12 @@ import { newest } from "../lineage"
|
|
|
8
8
|
import type { Store } from "../store"
|
|
9
9
|
import { deposit } from "../store"
|
|
10
10
|
import { Subject } from "../subject"
|
|
11
|
-
import type {
|
|
11
|
+
import type { Fn } from "../utility-types"
|
|
12
12
|
import { abortTransaction } from "./abort-transaction"
|
|
13
13
|
import { applyTransaction } from "./apply-transaction"
|
|
14
14
|
import { buildTransaction } from "./build-transaction"
|
|
15
15
|
|
|
16
|
-
export type Transaction<F extends
|
|
16
|
+
export type Transaction<F extends Fn> = {
|
|
17
17
|
key: string
|
|
18
18
|
type: `transaction`
|
|
19
19
|
install: (store: Store) => void
|
|
@@ -21,7 +21,7 @@ export type Transaction<F extends Func> = {
|
|
|
21
21
|
run: (parameters: Parameters<F>, id?: string) => ReturnType<F>
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function createTransaction<F extends
|
|
24
|
+
export function createTransaction<F extends Fn>(
|
|
25
25
|
store: Store,
|
|
26
26
|
options: TransactionOptions<F>,
|
|
27
27
|
): TransactionToken<F> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ActorToolkit, TransactionUpdate } from "atom.io"
|
|
2
2
|
|
|
3
3
|
import type { Junction } from "../junction"
|
|
4
|
-
import type {
|
|
4
|
+
import type { Fn } from "../utility-types"
|
|
5
5
|
|
|
6
6
|
export * from "./abort-transaction"
|
|
7
7
|
export * from "./act-upon-store"
|
|
@@ -16,7 +16,7 @@ export * from "./set-epoch-number"
|
|
|
16
16
|
export const TRANSACTION_PHASES = [`idle`, `building`, `applying`] as const
|
|
17
17
|
export type TransactionPhase = (typeof TRANSACTION_PHASES)[number]
|
|
18
18
|
|
|
19
|
-
export type TransactionProgress<F extends
|
|
19
|
+
export type TransactionProgress<F extends Fn> = {
|
|
20
20
|
phase: `applying` | `building`
|
|
21
21
|
update: TransactionUpdate<F>
|
|
22
22
|
toolkit: ActorToolkit
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { LazyMap } from "../lazy-map"
|
|
1
2
|
import type { Store } from "../store"
|
|
2
|
-
import type {
|
|
3
|
+
import type { Fn } from "../utility-types"
|
|
3
4
|
import type { TransactionEpoch, TransactionProgress } from "."
|
|
4
5
|
|
|
5
6
|
export interface RootStore extends Store {
|
|
@@ -8,9 +9,10 @@ export interface RootStore extends Store {
|
|
|
8
9
|
child: ChildStore | null
|
|
9
10
|
}
|
|
10
11
|
export interface ChildStore extends Store {
|
|
11
|
-
transactionMeta: TransactionProgress<
|
|
12
|
+
transactionMeta: TransactionProgress<Fn>
|
|
12
13
|
parent: ChildStore | RootStore
|
|
13
14
|
child: ChildStore | null
|
|
15
|
+
valueMap: LazyMap<string, any>
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export function isRootStore(store: Store): store is RootStore {
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
TransactionToken,
|
|
7
7
|
TransactionUpdate,
|
|
8
8
|
} from "atom.io"
|
|
9
|
-
import type {
|
|
9
|
+
import type { Fn, Store, Timeline } from "atom.io/internal"
|
|
10
10
|
|
|
11
11
|
import { type AtomTokenIndex, attachAtomIndex } from "./attach-atom-index"
|
|
12
12
|
import type { SelectorTokenIndex } from "./attach-selector-index"
|
|
@@ -20,9 +20,9 @@ import { attachTypeSelectors } from "./attach-type-selectors"
|
|
|
20
20
|
export type IntrospectionStates = {
|
|
21
21
|
atomIndex: AtomToken<AtomTokenIndex>
|
|
22
22
|
selectorIndex: AtomToken<SelectorTokenIndex>
|
|
23
|
-
transactionIndex: AtomToken<TransactionToken<
|
|
23
|
+
transactionIndex: AtomToken<TransactionToken<Fn>[]>
|
|
24
24
|
transactionLogSelectors: ReadonlyPureSelectorFamilyToken<
|
|
25
|
-
TransactionUpdate<
|
|
25
|
+
TransactionUpdate<Fn>[],
|
|
26
26
|
string
|
|
27
27
|
>
|
|
28
28
|
timelineIndex: AtomToken<TimelineToken<any>[]>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { AtomToken, TransactionToken } from "atom.io"
|
|
2
|
-
import type {
|
|
2
|
+
import type { Fn, Store } from "atom.io/internal"
|
|
3
3
|
import { createRegularAtom, isReservedIntrospectionKey } from "atom.io/internal"
|
|
4
4
|
|
|
5
5
|
export const attachTransactionIndex = (
|
|
6
6
|
store: Store,
|
|
7
|
-
): AtomToken<TransactionToken<
|
|
8
|
-
return createRegularAtom<TransactionToken<
|
|
7
|
+
): AtomToken<TransactionToken<Fn>[]> => {
|
|
8
|
+
return createRegularAtom<TransactionToken<Fn>[]>(
|
|
9
9
|
store,
|
|
10
10
|
{
|
|
11
11
|
key: `🔍 Transaction Token Index`,
|
|
12
12
|
default: () => {
|
|
13
|
-
const tokens: TransactionToken<
|
|
13
|
+
const tokens: TransactionToken<Fn>[] = []
|
|
14
14
|
for (const [key] of store.transactions) {
|
|
15
15
|
if (isReservedIntrospectionKey(key)) {
|
|
16
16
|
continue
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { ReadonlyPureSelectorFamilyToken, TransactionUpdate } from "atom.io"
|
|
2
|
-
import type {
|
|
2
|
+
import type { Fn, Store } from "atom.io/internal"
|
|
3
3
|
import { createRegularAtomFamily, createSelectorFamily } from "atom.io/internal"
|
|
4
4
|
|
|
5
5
|
export const attachTransactionLogs = (
|
|
6
6
|
store: Store,
|
|
7
|
-
): ReadonlyPureSelectorFamilyToken<TransactionUpdate<
|
|
7
|
+
): ReadonlyPureSelectorFamilyToken<TransactionUpdate<Fn>[], string> => {
|
|
8
8
|
const transactionUpdateLogAtoms = createRegularAtomFamily<
|
|
9
|
-
TransactionUpdate<
|
|
9
|
+
TransactionUpdate<Fn>[],
|
|
10
10
|
string
|
|
11
11
|
>(store, {
|
|
12
12
|
key: `🔍 Transaction Update Log (Internal)`,
|
|
@@ -23,7 +23,7 @@ export const attachTransactionLogs = (
|
|
|
23
23
|
],
|
|
24
24
|
})
|
|
25
25
|
const findTransactionUpdateLogState = createSelectorFamily<
|
|
26
|
-
TransactionUpdate<
|
|
26
|
+
TransactionUpdate<Fn>[],
|
|
27
27
|
string
|
|
28
28
|
>(store, {
|
|
29
29
|
key: `🔍 Transaction Update Log`,
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type ReadableToken,
|
|
5
5
|
type SelectorToken,
|
|
6
6
|
} from "atom.io"
|
|
7
|
-
import
|
|
7
|
+
import { IMPLICIT, type Store } from "atom.io/internal"
|
|
8
8
|
|
|
9
9
|
import type { FamilyNode } from "."
|
|
10
10
|
import type { AtomTokenIndex } from "./attach-atom-index"
|
|
@@ -22,7 +22,7 @@ export type ListResourcesParam = {
|
|
|
22
22
|
* @experimental
|
|
23
23
|
*/
|
|
24
24
|
export class Auditor {
|
|
25
|
-
public readonly store:
|
|
25
|
+
public readonly store: Store
|
|
26
26
|
public auditorCreatedAt: number = performance.now()
|
|
27
27
|
public statesCreatedAt: Map<string, number> = new Map()
|
|
28
28
|
public readonly atomIndex: AtomToken<AtomTokenIndex>
|
|
@@ -37,7 +37,7 @@ export class Auditor {
|
|
|
37
37
|
/**
|
|
38
38
|
* @param {Store} store - The store to audit.
|
|
39
39
|
*/
|
|
40
|
-
public constructor(store:
|
|
40
|
+
public constructor(store: Store = IMPLICIT.STORE) {
|
|
41
41
|
this.store = store
|
|
42
42
|
this.atomIndex = attachAtomIndex(this.store)
|
|
43
43
|
this.selectorIndex = attachSelectorIndex(this.store)
|
package/src/json/index.ts
CHANGED
package/src/main/atom.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Transceiver } from "atom.io/internal"
|
|
1
|
+
import type { ConstructorOf, Transceiver } from "atom.io/internal"
|
|
2
2
|
import {
|
|
3
3
|
createMutableAtom,
|
|
4
4
|
createMutableAtomFamily,
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
createRegularAtomFamily,
|
|
7
7
|
IMPLICIT,
|
|
8
8
|
} from "atom.io/internal"
|
|
9
|
-
import type { Canonical
|
|
9
|
+
import type { Canonical } from "atom.io/json"
|
|
10
10
|
|
|
11
11
|
import type { Setter } from "./set-state"
|
|
12
12
|
import type {
|
|
@@ -34,20 +34,14 @@ export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T> {
|
|
|
34
34
|
return createRegularAtom(IMPLICIT.STORE, options, undefined)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
key: string
|
|
46
|
-
/** A function to create an initial value for the atom */
|
|
47
|
-
default: () => T
|
|
48
|
-
/** Hooks used to run side effects when the atom is set */
|
|
49
|
-
effects?: AtomEffect<T>[]
|
|
50
|
-
}
|
|
37
|
+
export type MutableAtomOptions<T extends Transceiver<any, any, any>> = {
|
|
38
|
+
/** The unique identifier of the atom */
|
|
39
|
+
key: string
|
|
40
|
+
/** A constructor for the atom's value */
|
|
41
|
+
class: ConstructorOf<T>
|
|
42
|
+
/** Hooks used to run side effects when the atom is set */
|
|
43
|
+
effects?: AtomEffect<T>[]
|
|
44
|
+
}
|
|
51
45
|
/**
|
|
52
46
|
* Create a mutable atom, a global reactive variable in the implicit store
|
|
53
47
|
*
|
|
@@ -57,10 +51,9 @@ export type MutableAtomOptions<
|
|
|
57
51
|
* @returns
|
|
58
52
|
* A reference to the atom created: a {@link MutableAtomToken}
|
|
59
53
|
*/
|
|
60
|
-
export function mutableAtom<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J> {
|
|
54
|
+
export function mutableAtom<T extends Transceiver<any, any, any>>(
|
|
55
|
+
options: MutableAtomOptions<T>,
|
|
56
|
+
): MutableAtomToken<T> {
|
|
64
57
|
return createMutableAtom(IMPLICIT.STORE, options, undefined)
|
|
65
58
|
}
|
|
66
59
|
|
|
@@ -105,21 +98,17 @@ export function atomFamily<T, K extends Canonical>(
|
|
|
105
98
|
return createRegularAtomFamily(IMPLICIT.STORE, options)
|
|
106
99
|
}
|
|
107
100
|
|
|
108
|
-
// biome-ignore format: intersection
|
|
109
101
|
export type MutableAtomFamilyOptions<
|
|
110
|
-
T extends Transceiver<any>,
|
|
111
|
-
J extends Json.Serializable,
|
|
102
|
+
T extends Transceiver<any, any, any>,
|
|
112
103
|
K extends Canonical,
|
|
113
|
-
> =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
effects?: (key: K) => AtomEffect<T>[]
|
|
122
|
-
}
|
|
104
|
+
> = {
|
|
105
|
+
/** The unique identifier of the atom family */
|
|
106
|
+
key: string
|
|
107
|
+
/** The class of the transceiver to be created */
|
|
108
|
+
class: ConstructorOf<T>
|
|
109
|
+
/** Hooks used to run side effects when an atom in the family is set */
|
|
110
|
+
effects?: (key: K) => AtomEffect<T>[]
|
|
111
|
+
}
|
|
123
112
|
/**
|
|
124
113
|
* Create a family of mutable atoms, allowing for the dynamic creation and disposal of atoms.
|
|
125
114
|
*
|
|
@@ -130,9 +119,8 @@ export type MutableAtomFamilyOptions<
|
|
|
130
119
|
* A reference to the atom family created: a {@link MutableAtomFamilyToken}
|
|
131
120
|
*/
|
|
132
121
|
export function mutableAtomFamily<
|
|
133
|
-
T extends Transceiver<any>,
|
|
134
|
-
J extends Json.Serializable,
|
|
122
|
+
T extends Transceiver<any, any, any>,
|
|
135
123
|
K extends Canonical,
|
|
136
|
-
>(options: MutableAtomFamilyOptions<T,
|
|
124
|
+
>(options: MutableAtomFamilyOptions<T, K>): MutableAtomFamilyToken<T, K> {
|
|
137
125
|
return createMutableAtomFamily(IMPLICIT.STORE, options)
|
|
138
126
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { disposeFromStore, IMPLICIT } from "atom.io/internal"
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import type { ReadableFamilyToken, ReadableToken } from "."
|
|
@@ -19,19 +19,20 @@ export function disposeState(token: ReadableToken<any>): void
|
|
|
19
19
|
*
|
|
20
20
|
* @param token - The token of the state family to dispose
|
|
21
21
|
* @param key - The unique key of the state to dispose
|
|
22
|
+
* @overload Streamlined
|
|
22
23
|
*/
|
|
23
24
|
export function disposeState<K extends Canonical>(
|
|
24
25
|
token: ReadableFamilyToken<any, K>,
|
|
25
26
|
key: K,
|
|
26
27
|
): void
|
|
27
28
|
export function disposeState(
|
|
28
|
-
...
|
|
29
|
+
...params:
|
|
29
30
|
| [token: ReadableFamilyToken<any, any>, key: Canonical]
|
|
30
31
|
| [token: ReadableToken<any>]
|
|
31
32
|
): void {
|
|
32
|
-
if (
|
|
33
|
-
|
|
33
|
+
if (params.length === 2) {
|
|
34
|
+
disposeFromStore(IMPLICIT.STORE, ...params)
|
|
34
35
|
} else {
|
|
35
|
-
|
|
36
|
+
disposeFromStore(IMPLICIT.STORE, ...params)
|
|
36
37
|
}
|
|
37
38
|
}
|
package/src/main/find-state.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
} from "atom.io"
|
|
13
13
|
import type { Transceiver } from "atom.io/internal"
|
|
14
14
|
import { findInStore, IMPLICIT } from "atom.io/internal"
|
|
15
|
-
import type { Canonical
|
|
15
|
+
import type { Canonical } from "atom.io/json"
|
|
16
16
|
|
|
17
17
|
import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
|
|
18
18
|
|
|
@@ -30,11 +30,10 @@ import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
|
|
|
30
30
|
* @overload Mutable Atom
|
|
31
31
|
*/
|
|
32
32
|
export function findState<
|
|
33
|
-
T extends Transceiver<any>,
|
|
34
|
-
J extends Json.Serializable,
|
|
33
|
+
T extends Transceiver<any, any, any>,
|
|
35
34
|
K extends Canonical,
|
|
36
35
|
Key extends K,
|
|
37
|
-
>(token: MutableAtomFamilyToken<T,
|
|
36
|
+
>(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T, K>
|
|
38
37
|
/**
|
|
39
38
|
* Finds a {@link RegularAtomToken} in the store, without accessing its value.
|
|
40
39
|
*
|
package/src/main/get-state.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ViewOf } from "atom.io/internal"
|
|
2
|
+
import { getFromStore, IMPLICIT } from "atom.io/internal"
|
|
2
3
|
import type { Canonical } from "atom.io/json"
|
|
3
4
|
|
|
4
5
|
import type { ReadableFamilyToken, ReadableToken } from "."
|
|
@@ -10,7 +11,7 @@ import type { ReadableFamilyToken, ReadableToken } from "."
|
|
|
10
11
|
* @overload Default
|
|
11
12
|
* @default
|
|
12
13
|
*/
|
|
13
|
-
export function getState<T>(token: ReadableToken<T>): T
|
|
14
|
+
export function getState<T>(token: ReadableToken<T>): ViewOf<T>
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Read or compute the current value of a state
|
|
@@ -22,7 +23,7 @@ export function getState<T>(token: ReadableToken<T>): T
|
|
|
22
23
|
export function getState<T, K extends Canonical, Key extends K>(
|
|
23
24
|
token: ReadableFamilyToken<T, K>,
|
|
24
25
|
key: Key,
|
|
25
|
-
): T
|
|
26
|
+
): ViewOf<T>
|
|
26
27
|
|
|
27
28
|
export function getState(
|
|
28
29
|
...params:
|
|
@@ -30,7 +31,7 @@ export function getState(
|
|
|
30
31
|
| [token: ReadableToken<any>]
|
|
31
32
|
): any {
|
|
32
33
|
if (params.length === 2) {
|
|
33
|
-
return
|
|
34
|
+
return getFromStore(IMPLICIT.STORE, ...params)
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
+
return getFromStore(IMPLICIT.STORE, ...params)
|
|
36
37
|
}
|
package/src/main/join.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
IMPLICIT,
|
|
15
15
|
} from "atom.io/internal"
|
|
16
16
|
import type { Json } from "atom.io/json"
|
|
17
|
-
import type { SetRTX
|
|
17
|
+
import type { SetRTX } from "atom.io/transceivers/set-rtx"
|
|
18
18
|
|
|
19
19
|
// biome-ignore format: intersection
|
|
20
20
|
export type JoinOptions<
|
|
@@ -262,6 +262,6 @@ export function getInternalRelations<
|
|
|
262
262
|
Content extends Json.Object | null,
|
|
263
263
|
>(
|
|
264
264
|
token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
265
|
-
): MutableAtomFamilyToken<SetRTX<string>,
|
|
265
|
+
): MutableAtomFamilyToken<SetRTX<string>, string> {
|
|
266
266
|
return getInternalRelationsFromStore(token, IMPLICIT.STORE)
|
|
267
267
|
}
|
package/src/main/logger.ts
CHANGED
|
@@ -105,7 +105,7 @@ export const simpleLogger: Logger = {
|
|
|
105
105
|
|
|
106
106
|
export class AtomIOLogger implements Logger {
|
|
107
107
|
public logLevel: `error` | `info` | `warn` | null
|
|
108
|
-
|
|
108
|
+
public filter: LogFilter | undefined
|
|
109
109
|
private readonly logger: Logger
|
|
110
110
|
|
|
111
111
|
public constructor(
|
|
@@ -119,31 +119,31 @@ export class AtomIOLogger implements Logger {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
public error: LogFn = (...args) => {
|
|
122
|
-
const filterResult = this.filter?.(...args) ?? true
|
|
123
122
|
if (this.logLevel !== null) {
|
|
123
|
+
const filterResult = this.filter?.(...args) ?? true
|
|
124
124
|
if (filterResult === true) {
|
|
125
125
|
this.logger.error(...args)
|
|
126
|
-
} else if (filterResult
|
|
126
|
+
} else if (filterResult) {
|
|
127
127
|
this.logger.error(...filterResult)
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
public info: LogFn = (...args) => {
|
|
132
|
-
const filterResult = this.filter?.(...args) ?? true
|
|
133
132
|
if (this.logLevel === `info`) {
|
|
133
|
+
const filterResult = this.filter?.(...args) ?? true
|
|
134
134
|
if (filterResult === true) {
|
|
135
135
|
this.logger.info(...args)
|
|
136
|
-
} else if (filterResult
|
|
136
|
+
} else if (filterResult) {
|
|
137
137
|
this.logger.info(...filterResult)
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
public warn: LogFn = (...args) => {
|
|
142
|
-
const filterResult = this.filter?.(...args) ?? true
|
|
143
142
|
if (this.logLevel !== `error` && this.logLevel !== null) {
|
|
143
|
+
const filterResult = this.filter?.(...args) ?? true
|
|
144
144
|
if (filterResult === true) {
|
|
145
145
|
this.logger.warn(...args)
|
|
146
|
-
} else if (filterResult
|
|
146
|
+
} else if (filterResult) {
|
|
147
147
|
this.logger.warn(...filterResult)
|
|
148
148
|
}
|
|
149
149
|
}
|
package/src/main/reset-state.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IMPLICIT, resetInStore } from "atom.io/internal"
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import type { WritableFamilyToken, WritableToken } from "."
|
|
@@ -26,8 +26,8 @@ export function resetState(
|
|
|
26
26
|
| [token: WritableToken<any>]
|
|
27
27
|
): void {
|
|
28
28
|
if (params.length === 2) {
|
|
29
|
-
|
|
29
|
+
resetInStore(IMPLICIT.STORE, ...params)
|
|
30
30
|
} else {
|
|
31
|
-
|
|
31
|
+
resetInStore(IMPLICIT.STORE, ...params)
|
|
32
32
|
}
|
|
33
33
|
}
|
package/src/main/set-state.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IMPLICIT, setIntoStore } from "atom.io/internal"
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import type { WritableFamilyToken, WritableToken } from "./tokens"
|
|
@@ -45,8 +45,8 @@ export function setState<T, New extends T>(
|
|
|
45
45
|
| [token: WritableToken<T>, value: New | Setter<T, New>]
|
|
46
46
|
): void {
|
|
47
47
|
if (params.length === 2) {
|
|
48
|
-
|
|
48
|
+
setIntoStore(IMPLICIT.STORE, ...params)
|
|
49
49
|
} else {
|
|
50
|
-
|
|
50
|
+
setIntoStore(IMPLICIT.STORE, ...params)
|
|
51
51
|
}
|
|
52
52
|
}
|
package/src/main/subscribe.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Flat,
|
|
1
|
+
import type { Flat, Fn } from "atom.io/internal"
|
|
2
2
|
import { arbitrary, IMPLICIT, subscribeInStore } from "atom.io/internal"
|
|
3
3
|
|
|
4
4
|
import type {
|
|
@@ -20,7 +20,7 @@ export type KeyedStateUpdate<T> = Flat<
|
|
|
20
20
|
}
|
|
21
21
|
>
|
|
22
22
|
export type UpdateHandler<T> = (update: StateUpdate<T>) => void
|
|
23
|
-
export type TransactionUpdateHandler<F extends
|
|
23
|
+
export type TransactionUpdateHandler<F extends Fn> = (
|
|
24
24
|
data: TransactionUpdate<F>,
|
|
25
25
|
) => void
|
|
26
26
|
|
|
@@ -45,7 +45,7 @@ export function subscribe<T>(
|
|
|
45
45
|
* @returns A function that can be called to unsubscribe from the transaction
|
|
46
46
|
* @overload Transaction
|
|
47
47
|
*/
|
|
48
|
-
export function subscribe<F extends
|
|
48
|
+
export function subscribe<F extends Fn>(
|
|
49
49
|
token: TransactionToken<F>,
|
|
50
50
|
handleUpdate: TransactionUpdateHandler<F>,
|
|
51
51
|
key?: string,
|
package/src/main/tokens.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Canonical,
|
|
1
|
+
import type { AsJSON, Fn, Transceiver } from "atom.io/internal"
|
|
2
|
+
import type { Canonical, stringified } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
|
|
@@ -53,7 +53,7 @@ export type TimelineToken<M> = {
|
|
|
53
53
|
__M?: M
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export type TransactionToken<F extends
|
|
56
|
+
export type TransactionToken<F extends Fn> = {
|
|
57
57
|
/** The unique identifier of the transaction */
|
|
58
58
|
key: string
|
|
59
59
|
/** Discriminator */
|
|
@@ -63,7 +63,7 @@ export type TransactionToken<F extends Func> = {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export type AtomToken<T, K extends Canonical = any> =
|
|
66
|
-
| MutableAtomToken<T extends Transceiver<any> ? T : never,
|
|
66
|
+
| MutableAtomToken<T extends Transceiver<any, any, any> ? T : never, K>
|
|
67
67
|
| RegularAtomToken<T, K>
|
|
68
68
|
export type RegularAtomToken<T, K extends Canonical = any> = {
|
|
69
69
|
/** The unique identifier of the atom. */
|
|
@@ -76,8 +76,7 @@ export type RegularAtomToken<T, K extends Canonical = any> = {
|
|
|
76
76
|
__T?: T
|
|
77
77
|
}
|
|
78
78
|
export type MutableAtomToken<
|
|
79
|
-
T extends Transceiver<any>,
|
|
80
|
-
J extends Json.Serializable,
|
|
79
|
+
T extends Transceiver<any, any, any>,
|
|
81
80
|
K extends Canonical = any,
|
|
82
81
|
> = {
|
|
83
82
|
/** The unique identifier of the atom. */
|
|
@@ -87,9 +86,7 @@ export type MutableAtomToken<
|
|
|
87
86
|
/** Present if the atom belongs to a family. */
|
|
88
87
|
family?: FamilyMetadata<K>
|
|
89
88
|
/** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
|
|
90
|
-
__J?:
|
|
91
|
-
/** Never present. This is a marker that preserves the type of the atom's transceiver value. */
|
|
92
|
-
__U?: T extends Transceiver<infer Update> ? Update : never
|
|
89
|
+
__J?: AsJSON<T>
|
|
93
90
|
}
|
|
94
91
|
|
|
95
92
|
export type SelectorToken<T, K extends Canonical = any> =
|
|
@@ -160,7 +157,7 @@ export type FamilyMetadata<K extends Canonical = any> = {
|
|
|
160
157
|
}
|
|
161
158
|
|
|
162
159
|
export type AtomFamilyToken<T, K extends Canonical = Canonical> =
|
|
163
|
-
| MutableAtomFamilyToken<T extends Transceiver<any> ? T : never,
|
|
160
|
+
| MutableAtomFamilyToken<T extends Transceiver<any, any, any> ? T : never, K>
|
|
164
161
|
| RegularAtomFamilyToken<T, K>
|
|
165
162
|
export type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
166
163
|
/** The unique identifier of the atom family */
|
|
@@ -173,8 +170,7 @@ export type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
|
173
170
|
__K?: K
|
|
174
171
|
}
|
|
175
172
|
export type MutableAtomFamilyToken<
|
|
176
|
-
T extends Transceiver<any>,
|
|
177
|
-
J extends Json.Serializable,
|
|
173
|
+
T extends Transceiver<any, any, any>,
|
|
178
174
|
K extends Canonical,
|
|
179
175
|
> = {
|
|
180
176
|
/** The unique identifier of the atom family */
|
|
@@ -183,8 +179,6 @@ export type MutableAtomFamilyToken<
|
|
|
183
179
|
type: `mutable_atom_family`
|
|
184
180
|
/** Never present. This is a marker that preserves the type of atoms in this family */
|
|
185
181
|
__T?: T
|
|
186
|
-
/** Never present. This is a marker that preserves the type of the JSON form of atoms in this family */
|
|
187
|
-
__J?: J
|
|
188
182
|
/** Never present. This is a marker that preserves the type of keys used for atoms in this family */
|
|
189
183
|
__K?: K
|
|
190
184
|
}
|
package/src/main/transaction.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { EnvironmentData,
|
|
1
|
+
import type { AsJSON, EnvironmentData, Fn, Transceiver } from "atom.io/internal"
|
|
2
2
|
import {
|
|
3
3
|
actUponStore,
|
|
4
4
|
arbitrary,
|
|
5
5
|
createTransaction,
|
|
6
6
|
IMPLICIT,
|
|
7
7
|
} from "atom.io/internal"
|
|
8
|
-
import type { Canonical,
|
|
8
|
+
import type { Canonical, stringified } from "atom.io/json"
|
|
9
9
|
|
|
10
10
|
import type { disposeState } from "./dispose-state"
|
|
11
11
|
import type { findState } from "./find-state"
|
|
@@ -28,6 +28,9 @@ export type StateCreation<Token extends ReadableToken<any>> = {
|
|
|
28
28
|
export type StateDisposal<Token extends ReadableToken<any>> =
|
|
29
29
|
| AtomDisposal<Token>
|
|
30
30
|
| SelectorDisposal<Token>
|
|
31
|
+
export type StateLifecycleEvent<Token extends ReadableToken<any>> =
|
|
32
|
+
| StateCreation<Token>
|
|
33
|
+
| StateDisposal<Token>
|
|
31
34
|
|
|
32
35
|
export type AtomDisposal<Token extends ReadableToken<any>> = {
|
|
33
36
|
type: `state_disposal`
|
|
@@ -55,6 +58,7 @@ export type MoleculeDisposal = {
|
|
|
55
58
|
export type MoleculeTransfer = {
|
|
56
59
|
type: `molecule_transfer`
|
|
57
60
|
key: Canonical
|
|
61
|
+
exclusive: boolean
|
|
58
62
|
from: Canonical[]
|
|
59
63
|
to: Canonical[]
|
|
60
64
|
}
|
|
@@ -66,9 +70,9 @@ export type TransactionUpdateContent =
|
|
|
66
70
|
| MoleculeTransfer
|
|
67
71
|
| StateCreation<ReadableToken<unknown>>
|
|
68
72
|
| StateDisposal<ReadableToken<unknown>>
|
|
69
|
-
| TransactionUpdate<
|
|
73
|
+
| TransactionUpdate<Fn>
|
|
70
74
|
|
|
71
|
-
export type TransactionUpdate<F extends
|
|
75
|
+
export type TransactionUpdate<F extends Fn> = {
|
|
72
76
|
type: `transaction_update`
|
|
73
77
|
key: string
|
|
74
78
|
id: string
|
|
@@ -85,29 +89,29 @@ export type ActorToolkit = Readonly<{
|
|
|
85
89
|
set: typeof setState
|
|
86
90
|
reset: typeof resetState
|
|
87
91
|
find: typeof findState
|
|
88
|
-
json: <T extends Transceiver<any
|
|
89
|
-
state: MutableAtomToken<T
|
|
90
|
-
) => WritablePureSelectorToken<
|
|
92
|
+
json: <T extends Transceiver<any, any, any>>(
|
|
93
|
+
state: MutableAtomToken<T>,
|
|
94
|
+
) => WritablePureSelectorToken<AsJSON<T>>
|
|
91
95
|
dispose: typeof disposeState
|
|
92
96
|
run: typeof runTransaction
|
|
93
97
|
env: () => EnvironmentData
|
|
94
98
|
}>
|
|
95
99
|
|
|
96
|
-
export type Read<F extends
|
|
100
|
+
export type Read<F extends Fn> = (
|
|
97
101
|
toolkit: ReaderToolkit,
|
|
98
102
|
...parameters: Parameters<F>
|
|
99
103
|
) => ReturnType<F>
|
|
100
|
-
export type Write<F extends
|
|
104
|
+
export type Write<F extends Fn> = (
|
|
101
105
|
toolkit: WriterToolkit,
|
|
102
106
|
...parameters: Parameters<F>
|
|
103
107
|
) => ReturnType<F>
|
|
104
|
-
export type Transact<F extends
|
|
108
|
+
export type Transact<F extends Fn> = (
|
|
105
109
|
toolkit: ActorToolkit,
|
|
106
110
|
...parameters: Parameters<F>
|
|
107
111
|
) => ReturnType<F>
|
|
108
112
|
export type TransactionIO<Token extends TransactionToken<any>> =
|
|
109
113
|
Token extends TransactionToken<infer F> ? F : never
|
|
110
|
-
export type TransactionOptions<F extends
|
|
114
|
+
export type TransactionOptions<F extends Fn> = {
|
|
111
115
|
/** The unique identifier of the transaction */
|
|
112
116
|
key: string
|
|
113
117
|
/** The operation to perform */
|
|
@@ -119,7 +123,7 @@ export type TransactionOptions<F extends Func> = {
|
|
|
119
123
|
* @param options - {@link TransactionOptions}
|
|
120
124
|
* @returns A reference to the transaction created: a {@link TransactionToken}
|
|
121
125
|
*/
|
|
122
|
-
export function transaction<F extends
|
|
126
|
+
export function transaction<F extends Fn>(
|
|
123
127
|
options: TransactionOptions<F>,
|
|
124
128
|
): TransactionToken<F> {
|
|
125
129
|
return createTransaction(IMPLICIT.STORE, options)
|
|
@@ -131,7 +135,7 @@ export function transaction<F extends Func>(
|
|
|
131
135
|
* @param id - A unique identifier for the transaction. If not provided, a random identifier will be generated
|
|
132
136
|
* @returns A function that can be called to run the transaction with its {@link TransactionIO} parameters
|
|
133
137
|
*/
|
|
134
|
-
export function runTransaction<F extends
|
|
138
|
+
export function runTransaction<F extends Fn>(
|
|
135
139
|
token: TransactionToken<F>,
|
|
136
140
|
id: string = arbitrary(),
|
|
137
141
|
): (...parameters: Parameters<F>) => ReturnType<F> {
|