atom.io 0.32.1 → 0.32.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/README.md +17 -37
- package/data/dist/index.js +1 -1
- package/dist/{chunk-X7SD2NXU.js → chunk-2XDFCXGB.js} +5 -4
- package/dist/{chunk-UQEYZ3OI.js → chunk-35NB2XZU.js} +108 -110
- package/dist/{chunk-3ZFTRSNG.js → chunk-EF4S7H42.js} +6 -3
- package/dist/{chunk-KVI5OBF2.js → chunk-LTLDKXDN.js} +3 -3
- package/dist/{chunk-3PQTWLQQ.js → chunk-MENOYVPP.js} +1 -1
- package/dist/{chunk-VRJP2PCU.js → chunk-RGUNRT72.js} +43 -40
- package/dist/{chunk-UYYKOGZQ.js → chunk-TS76LQVD.js} +8 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/internal/dist/index.d.ts +8 -5
- package/internal/dist/index.js +1 -1
- package/internal/src/get-state/read-or-compute-value.ts +23 -13
- package/internal/src/index.ts +2 -1
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +0 -12
- package/internal/src/lazy-map.ts +3 -1
- package/internal/src/reserved-keys.ts +7 -0
- package/internal/src/set-state/copy-mutable-if-needed.ts +12 -11
- package/internal/src/set-state/set-atom-or-selector.ts +1 -1
- package/internal/src/set-state/set-atom.ts +43 -21
- package/internal/src/store/store.ts +2 -1
- package/internal/src/transaction/get-epoch-number.ts +15 -19
- package/internal/src/transaction/set-epoch-number.ts +2 -2
- package/introspection/dist/index.js +2 -2
- package/introspection/src/attach-atom-index.ts +16 -14
- package/introspection/src/attach-selector-index.ts +16 -14
- package/introspection/src/auditor.ts +3 -3
- package/json/dist/index.js +1 -1
- package/package.json +19 -17
- package/react/dist/index.js +2 -2
- package/react-devtools/dist/index.js +78 -66
- package/react-devtools/src/AtomIODevtools.tsx +10 -2
- package/react-devtools/src/error-boundary/ReactErrorBoundary.tsx +1 -1
- package/realtime/dist/index.d.ts +1 -1
- package/realtime/dist/index.js +2 -2
- package/realtime/src/realtime-continuity.ts +4 -1
- package/realtime-client/dist/index.js +2 -2
- package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +5 -2
- package/realtime-react/dist/index.js +4 -4
- package/realtime-server/dist/index.d.ts +1 -1
- package/realtime-server/dist/index.js +3 -3
- package/realtime-server/src/ipc-sockets/custom-socket.ts +6 -1
- package/realtime-testing/dist/index.js +6 -6
- package/src/logger.ts +12 -4
- package/transceivers/set-rtx/dist/index.js +1 -1
- package/internal/src/set-state/stow-update.ts +0 -60
package/internal/dist/index.d.ts
CHANGED
|
@@ -185,8 +185,8 @@ type Transaction<F extends Func> = {
|
|
|
185
185
|
};
|
|
186
186
|
declare function createTransaction<F extends Func>(store: Store, options: TransactionOptions<F>): TransactionToken<F>;
|
|
187
187
|
|
|
188
|
-
declare function getContinuityKey(store:
|
|
189
|
-
declare function getEpochNumberOfContinuity(store:
|
|
188
|
+
declare function getContinuityKey(store: RootStore, transactionKey: string): string | undefined;
|
|
189
|
+
declare function getEpochNumberOfContinuity(store: RootStore, continuityKey: string): number | undefined;
|
|
190
190
|
declare function getEpochNumberOfAction(store: Store, transactionKey: string): number | undefined;
|
|
191
191
|
|
|
192
192
|
declare function setEpochNumberOfContinuity(store: Store, continuityKey: string, newEpoch: number): void;
|
|
@@ -622,8 +622,8 @@ type StateKey<T> = AtomKey<T> | ReadonlySelectorKey<T> | SelectorKey<T>;
|
|
|
622
622
|
declare const isStateKey: (store: Store, key: string) => key is StateKey<unknown>;
|
|
623
623
|
|
|
624
624
|
declare class LazyMap<K, V> extends Map<K, V> {
|
|
625
|
-
protected readonly source: Map<K, V>;
|
|
626
625
|
deleted: Set<K>;
|
|
626
|
+
protected readonly source: Map<K, V>;
|
|
627
627
|
constructor(source: Map<K, V>);
|
|
628
628
|
get(key: K): V | undefined;
|
|
629
629
|
set(key: K, value: V): this;
|
|
@@ -638,6 +638,9 @@ declare class NotFoundError extends Error {
|
|
|
638
638
|
|
|
639
639
|
declare function prettyPrintTokenType(token: AtomIOToken): string;
|
|
640
640
|
|
|
641
|
+
type ReservedIntrospectionKey = `🔍 ${string}`;
|
|
642
|
+
declare function isReservedIntrospectionKey(value: string): value is ReservedIntrospectionKey;
|
|
643
|
+
|
|
641
644
|
declare const createReadonlySelector: <T>(store: Store, options: ReadonlySelectorOptions<T>, family: FamilyMetadata | undefined) => ReadonlySelectorToken<T>;
|
|
642
645
|
|
|
643
646
|
declare function createStandaloneSelector<T>(store: Store, options: WritableSelectorOptions<T>): WritableSelectorToken<T>;
|
|
@@ -695,7 +698,7 @@ type RegularAtom<T> = AtomIOState & {
|
|
|
695
698
|
};
|
|
696
699
|
type MutableAtom<T extends Transceiver<any>, J extends Json.Serializable> = AtomIOState & JsonInterface<T, J> & {
|
|
697
700
|
type: `mutable_atom`;
|
|
698
|
-
default:
|
|
701
|
+
default: () => T;
|
|
699
702
|
cleanup?: () => void;
|
|
700
703
|
};
|
|
701
704
|
type Atom<T> = RegularAtom<T> | (T extends Transceiver<any> ? MutableAtom<T, any> : never);
|
|
@@ -741,4 +744,4 @@ type WritableFamily<T, K extends Canonical> = AtomFamily<T, K> | WritableSelecto
|
|
|
741
744
|
type ReadableFamily<T, K extends Canonical> = AtomFamily<T, K> | SelectorFamily<T, K>;
|
|
742
745
|
type AtomIOInternalResource = ReadableFamily<any, any> | ReadableState<any> | Timeline<any> | Transaction<any>;
|
|
743
746
|
|
|
744
|
-
export { type Atom, type AtomFamily, type AtomIOInternalResource, type AtomIOState, type AtomKey, type BaseExternalStoreConfiguration, type ChildStore, CircularBuffer, type Count, type Each, type Empty, type EnvironmentData, type ExternalStoreConfiguration, type ExternalStoreWithContentConfiguration, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, type Flat, type Func, Future, IMPLICIT, Join, type JoinStateFamilies, Junction, type JunctionAdvancedConfiguration, type JunctionEntries, type JunctionEntriesBase, type JunctionJSON, type JunctionSchema, type JunctionSchemaBase, LazyMap, type Lineage, type Modify, type Molecule, type MutableAtom, type MutableAtomFamily, NotFoundError, type OperationProgress, type ReadableFamily, type ReadableState, type ReadonlySelector, type ReadonlySelectorFamily, type ReadonlySelectorKey, type Refinement, type RegularAtom, type RegularAtomFamily, type RootStore, type Selector, type SelectorFamily, type SelectorKey, type Signal, type StateKey, StatefulSubject, Store, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineMoleculeCreation, type TimelineMoleculeDisposal, type TimelineSelectorUpdate, type TimelineStateCreation, type TimelineStateDisposal, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionEpoch, type TransactionPhase, type TransactionProgress, type Transceiver, type TransceiverMode, type WritableFamily, type WritableSelector, type WritableSelectorFamily, type WritableState, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, capitalize, claimWithinStore, clearStore, closeOperation, counterfeit, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deallocateFromStore, deposit, disposeAtom, disposeFromStore, disposeSelector, editRelationsInStore, evictCachedValue, findInStore, findRelationsInStore, fuseWithinStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getInternalRelationsFromStore, getJoin, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getTrace, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeRootMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw };
|
|
747
|
+
export { type Atom, type AtomFamily, type AtomIOInternalResource, type AtomIOState, type AtomKey, type BaseExternalStoreConfiguration, type ChildStore, CircularBuffer, type Count, type Each, type Empty, type EnvironmentData, type ExternalStoreConfiguration, type ExternalStoreWithContentConfiguration, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, type Flat, type Func, Future, IMPLICIT, Join, type JoinStateFamilies, Junction, type JunctionAdvancedConfiguration, type JunctionEntries, type JunctionEntriesBase, type JunctionJSON, type JunctionSchema, type JunctionSchemaBase, LazyMap, type Lineage, type Modify, type Molecule, type MutableAtom, type MutableAtomFamily, NotFoundError, type OperationProgress, type ReadableFamily, type ReadableState, type ReadonlySelector, type ReadonlySelectorFamily, type ReadonlySelectorKey, type Refinement, type RegularAtom, type RegularAtomFamily, type ReservedIntrospectionKey, type RootStore, type Selector, type SelectorFamily, type SelectorKey, type Signal, type StateKey, StatefulSubject, Store, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineMoleculeCreation, type TimelineMoleculeDisposal, type TimelineSelectorUpdate, type TimelineStateCreation, type TimelineStateDisposal, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionEpoch, type TransactionPhase, type TransactionProgress, type Transceiver, type TransceiverMode, type WritableFamily, type WritableSelector, type WritableSelectorFamily, type WritableState, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, capitalize, claimWithinStore, clearStore, closeOperation, counterfeit, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deallocateFromStore, deposit, disposeAtom, disposeFromStore, disposeSelector, editRelationsInStore, evictCachedValue, findInStore, findRelationsInStore, fuseWithinStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getInternalRelationsFromStore, getJoin, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getTrace, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isReservedIntrospectionKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeRootMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw };
|
package/internal/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Join, Junction, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, capitalize, claimWithinStore, clearStore, closeOperation, counterfeit, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deallocateFromStore, deposit, disposeAtom, disposeFromStore, disposeSelector, editRelationsInStore, evictCachedValue, findInStore, findRelationsInStore, fuseWithinStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getInternalRelationsFromStore, getJoin, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getTrace, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeRootMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw } from '../../dist/chunk-
|
|
1
|
+
export { CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Join, Junction, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, capitalize, claimWithinStore, clearStore, closeOperation, counterfeit, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deallocateFromStore, deposit, disposeAtom, disposeFromStore, disposeSelector, editRelationsInStore, evictCachedValue, findInStore, findRelationsInStore, fuseWithinStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getInternalRelationsFromStore, getJoin, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getTrace, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isReservedIntrospectionKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeRootMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw } from '../../dist/chunk-35NB2XZU.js';
|
|
2
2
|
import '../../dist/chunk-XWL6SNVU.js';
|
|
@@ -10,18 +10,28 @@ export const readOrComputeValue = <T>(
|
|
|
10
10
|
target.logger.info(`📖`, state.type, state.key, `reading cached value`)
|
|
11
11
|
return readCachedValue(state, target)
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
switch (state.type) {
|
|
14
|
+
case `selector`:
|
|
15
|
+
case `readonly_selector`:
|
|
16
|
+
target.logger.info(`🧮`, state.type, state.key, `computing value`)
|
|
17
|
+
return state.get()
|
|
18
|
+
case `atom`:
|
|
19
|
+
case `mutable_atom`: {
|
|
20
|
+
const def = state.default
|
|
21
|
+
let fallback: T
|
|
22
|
+
if (def instanceof Function) {
|
|
23
|
+
fallback = def()
|
|
24
|
+
} else {
|
|
25
|
+
fallback = def
|
|
26
|
+
}
|
|
27
|
+
target.logger.info(
|
|
28
|
+
`💁`,
|
|
29
|
+
`atom`,
|
|
30
|
+
state.key,
|
|
31
|
+
`could not find cached value; using default`,
|
|
32
|
+
fallback,
|
|
33
|
+
)
|
|
34
|
+
return fallback
|
|
35
|
+
}
|
|
16
36
|
}
|
|
17
|
-
const fallback =
|
|
18
|
-
state.default instanceof Function ? state.default() : state.default
|
|
19
|
-
target.logger.info(
|
|
20
|
-
`💁`,
|
|
21
|
-
`atom`,
|
|
22
|
-
state.key,
|
|
23
|
-
`could not find cached value; using default`,
|
|
24
|
-
fallback,
|
|
25
|
-
)
|
|
26
|
-
return state.default instanceof Function ? state.default() : state.default
|
|
27
37
|
}
|
package/internal/src/index.ts
CHANGED
|
@@ -40,6 +40,7 @@ export * from "./mutable"
|
|
|
40
40
|
export * from "./not-found-error"
|
|
41
41
|
export * from "./operation"
|
|
42
42
|
export * from "./pretty-print"
|
|
43
|
+
export * from "./reserved-keys"
|
|
43
44
|
export * from "./selector"
|
|
44
45
|
export * from "./set-state"
|
|
45
46
|
export * from "./store"
|
|
@@ -67,7 +68,7 @@ export type MutableAtom<
|
|
|
67
68
|
> = AtomIOState &
|
|
68
69
|
JsonInterface<T, J> & {
|
|
69
70
|
type: `mutable_atom`
|
|
70
|
-
default:
|
|
71
|
+
default: () => T
|
|
71
72
|
cleanup?: () => void
|
|
72
73
|
}
|
|
73
74
|
export type Atom<T> =
|
|
@@ -93,18 +93,6 @@ export function ingestMoleculeDisposalEvent(
|
|
|
93
93
|
|
|
94
94
|
case `oldValue`:
|
|
95
95
|
{
|
|
96
|
-
// let first = t rue
|
|
97
|
-
// for (const ownerString of update.provenance) {
|
|
98
|
-
// // const owner = parseJson(ownerString)
|
|
99
|
-
// // if (first) {
|
|
100
|
-
// // first = false
|
|
101
|
-
// // allocateIntoStore<any, any, any>(store, owner, update.key)
|
|
102
|
-
// // continue
|
|
103
|
-
// // }
|
|
104
|
-
|
|
105
|
-
// // claimWithinStore<any, any, any>(store, owner, update.key)
|
|
106
|
-
|
|
107
|
-
// }
|
|
108
96
|
const provenanceJson = update.provenance.map(parseJson)
|
|
109
97
|
allocateIntoStore<any, any, any>(store, provenanceJson, update.key)
|
|
110
98
|
for (const [familyKey, value] of update.values) {
|
package/internal/src/lazy-map.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export class LazyMap<K, V> extends Map<K, V> {
|
|
2
2
|
public deleted = new Set<K>()
|
|
3
|
+
protected readonly source: Map<K, V>
|
|
3
4
|
|
|
4
|
-
public constructor(
|
|
5
|
+
public constructor(source: Map<K, V>) {
|
|
5
6
|
super()
|
|
7
|
+
this.source = source
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
public get(key: K): V | undefined {
|
|
@@ -10,17 +10,18 @@ export function copyMutableIfNeeded<T extends Transceiver<any>>(
|
|
|
10
10
|
const originValue = origin.valueMap.get(atom.key)
|
|
11
11
|
const targetValue = target.valueMap.get(atom.key)
|
|
12
12
|
|
|
13
|
-
if (originValue
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
13
|
+
if (originValue !== targetValue) {
|
|
14
|
+
return targetValue
|
|
15
|
+
}
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const copiedValue = atom.fromJson(jsonValue)
|
|
21
|
-
target.valueMap.set(atom.key, copiedValue)
|
|
22
|
-
new Tracker(atom, origin)
|
|
23
|
-
return copiedValue
|
|
17
|
+
if (originValue === undefined) {
|
|
18
|
+
return atom.default()
|
|
24
19
|
}
|
|
25
|
-
|
|
20
|
+
|
|
21
|
+
origin.logger.info(`📃`, `atom`, atom.key, `copying`)
|
|
22
|
+
const jsonValue = atom.toJson(originValue)
|
|
23
|
+
const copiedValue = atom.fromJson(jsonValue)
|
|
24
|
+
target.valueMap.set(atom.key, copiedValue)
|
|
25
|
+
new Tracker(atom, origin)
|
|
26
|
+
return copiedValue
|
|
26
27
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { KeyedStateUpdate } from "atom.io"
|
|
2
|
+
|
|
3
|
+
import type { Atom, Store } from ".."
|
|
2
4
|
import { isAtomDefault, markAtomAsNotDefault } from "../atom"
|
|
3
5
|
import { cacheValue } from "../caching"
|
|
4
6
|
import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
5
|
-
import type
|
|
7
|
+
import { isTransceiver, type Transceiver } from "../mutable"
|
|
6
8
|
import { markDone } from "../operation"
|
|
7
|
-
import
|
|
8
|
-
import { isChildStore, isRootStore } from "../transaction/is-root-store"
|
|
9
|
+
import { isChildStore } from "../transaction/is-root-store"
|
|
9
10
|
import { become } from "./become"
|
|
10
11
|
import { copyMutableIfNeeded } from "./copy-mutable-if-needed"
|
|
11
12
|
import { emitUpdate } from "./emit-update"
|
|
12
13
|
import { evictDownStream } from "./evict-downstream"
|
|
13
|
-
import { stowUpdate } from "./stow-update"
|
|
14
14
|
|
|
15
15
|
export const setAtom = <T>(
|
|
16
|
+
target: Store,
|
|
16
17
|
atom: Atom<T>,
|
|
17
18
|
next: T | ((oldValue: T) => T),
|
|
18
|
-
target: Store,
|
|
19
19
|
): void => {
|
|
20
20
|
const oldValue = readOrComputeValue(target, atom)
|
|
21
21
|
let newValue = oldValue
|
|
@@ -33,22 +33,44 @@ export const setAtom = <T>(
|
|
|
33
33
|
markDone(target, atom.key)
|
|
34
34
|
evictDownStream(target, atom)
|
|
35
35
|
const update = { oldValue, newValue }
|
|
36
|
-
if (
|
|
36
|
+
if (!isChildStore(target)) {
|
|
37
37
|
emitUpdate(target, atom, update)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
if (target.on.transactionApplying.state === null) {
|
|
41
|
+
const { key } = atom
|
|
42
|
+
if (isTransceiver(update.newValue)) {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
const atomUpdate: KeyedStateUpdate<T> = {
|
|
46
|
+
type: `atom_update`,
|
|
47
|
+
key,
|
|
48
|
+
...update,
|
|
49
|
+
}
|
|
50
|
+
if (atom.family) {
|
|
51
|
+
atomUpdate.family = atom.family
|
|
52
|
+
}
|
|
53
|
+
target.transactionMeta.update.updates.push(atomUpdate)
|
|
54
|
+
target.logger.info(
|
|
55
|
+
`📁`,
|
|
56
|
+
`atom`,
|
|
57
|
+
key,
|
|
58
|
+
`stowed (`,
|
|
59
|
+
update.oldValue,
|
|
60
|
+
`->`,
|
|
61
|
+
update.newValue,
|
|
62
|
+
`)`,
|
|
63
|
+
)
|
|
64
|
+
} else if (atom.key.startsWith(`*`)) {
|
|
65
|
+
const mutableKey = atom.key.slice(1)
|
|
66
|
+
const mutableAtom = target.atoms.get(mutableKey) as Atom<any>
|
|
67
|
+
let transceiver: Transceiver<any> = target.valueMap.get(mutableKey)
|
|
68
|
+
if (mutableAtom.type === `mutable_atom` && isChildStore(target)) {
|
|
69
|
+
const { parent } = target
|
|
70
|
+
const copiedValue = copyMutableIfNeeded(target, mutableAtom, parent)
|
|
71
|
+
transceiver = copiedValue
|
|
52
72
|
}
|
|
73
|
+
const accepted = transceiver.do(update.newValue) === null
|
|
74
|
+
if (accepted) evictDownStream(target, mutableAtom)
|
|
53
75
|
}
|
|
54
76
|
}
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
WritableSelector,
|
|
21
21
|
WritableSelectorFamily,
|
|
22
22
|
} from ".."
|
|
23
|
+
import { isReservedIntrospectionKey } from ".."
|
|
23
24
|
import type { Join } from "../join"
|
|
24
25
|
import { Junction } from "../junction"
|
|
25
26
|
import type { Lineage } from "../lineage"
|
|
@@ -177,7 +178,7 @@ export class Store implements Lineage {
|
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
public loggers: AtomIOLogger[] = [
|
|
180
|
-
new AtomIOLogger(`warn`, (_, __, key) => !key
|
|
181
|
+
new AtomIOLogger(`warn`, (_, __, key) => !isReservedIntrospectionKey(key)),
|
|
181
182
|
]
|
|
182
183
|
public logger: Logger = {
|
|
183
184
|
error: (...messages) => {
|
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import type { Store } from "../store"
|
|
2
|
+
import type { RootStore } from "./is-root-store"
|
|
2
3
|
import { isRootStore } from "./is-root-store"
|
|
3
4
|
|
|
4
5
|
export function getContinuityKey(
|
|
5
|
-
store:
|
|
6
|
+
store: RootStore,
|
|
6
7
|
transactionKey: string,
|
|
7
8
|
): string | undefined {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
: undefined
|
|
9
|
+
const continuity =
|
|
10
|
+
store.transactionMeta.actionContinuities.getRelatedKey(transactionKey)
|
|
11
|
+
|
|
12
12
|
return continuity
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function getEpochNumberOfContinuity(
|
|
16
|
-
store:
|
|
16
|
+
store: RootStore,
|
|
17
17
|
continuityKey: string,
|
|
18
18
|
): number | undefined {
|
|
19
|
-
const
|
|
20
|
-
const epoch =
|
|
21
|
-
isRoot && continuityKey
|
|
22
|
-
? store.transactionMeta.epoch.get(continuityKey)
|
|
23
|
-
: undefined
|
|
19
|
+
const epoch = store.transactionMeta.epoch.get(continuityKey)
|
|
24
20
|
return epoch
|
|
25
21
|
}
|
|
26
22
|
|
|
@@ -29,12 +25,12 @@ export function getEpochNumberOfAction(
|
|
|
29
25
|
transactionKey: string,
|
|
30
26
|
): number | undefined {
|
|
31
27
|
const isRoot = isRootStore(store)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return
|
|
28
|
+
if (!isRoot) {
|
|
29
|
+
return undefined
|
|
30
|
+
}
|
|
31
|
+
const continuityKey = getContinuityKey(store, transactionKey)
|
|
32
|
+
if (continuityKey === undefined) {
|
|
33
|
+
return undefined
|
|
34
|
+
}
|
|
35
|
+
return getEpochNumberOfContinuity(store, continuityKey)
|
|
40
36
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Store } from "../store"
|
|
2
|
+
import { getContinuityKey } from "./get-epoch-number"
|
|
2
3
|
import { isRootStore } from "./is-root-store"
|
|
3
4
|
|
|
4
5
|
export function setEpochNumberOfContinuity(
|
|
@@ -21,8 +22,7 @@ export function setEpochNumberOfAction(
|
|
|
21
22
|
if (!isRoot) {
|
|
22
23
|
return
|
|
23
24
|
}
|
|
24
|
-
const continuityKey =
|
|
25
|
-
store.transactionMeta.actionContinuities.getRelatedKey(transactionKey)
|
|
25
|
+
const continuityKey = getContinuityKey(store, transactionKey)
|
|
26
26
|
|
|
27
27
|
if (continuityKey !== undefined) {
|
|
28
28
|
store.transactionMeta.epoch.set(continuityKey, newEpoch)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { Auditor, Differ, Refinery, attachIntrospectionStates, diffArray, diffBoolean, diffNumber, diffObject, diffString, discoverType, isPlainObject, jsonRefinery, jsonTreeRefinery, prettyJson, primitiveRefinery, sprawl } from '../../dist/chunk-
|
|
2
|
-
import '../../dist/chunk-
|
|
1
|
+
export { Auditor, Differ, Refinery, attachIntrospectionStates, diffArray, diffBoolean, diffNumber, diffObject, diffString, discoverType, isPlainObject, jsonRefinery, jsonTreeRefinery, prettyJson, primitiveRefinery, sprawl } from '../../dist/chunk-RGUNRT72.js';
|
|
2
|
+
import '../../dist/chunk-35NB2XZU.js';
|
|
3
3
|
import '../../dist/chunk-XWL6SNVU.js';
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
createRegularAtom,
|
|
5
5
|
createStandaloneSelector,
|
|
6
6
|
deposit,
|
|
7
|
+
isReservedIntrospectionKey,
|
|
7
8
|
} from "atom.io/internal"
|
|
8
9
|
|
|
9
10
|
import type { WritableTokenIndex } from "."
|
|
@@ -20,21 +21,22 @@ export const attachAtomIndex = (
|
|
|
20
21
|
default: () => {
|
|
21
22
|
const base: AtomTokenIndex = new Map()
|
|
22
23
|
for (const [key, val] of store.atoms) {
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
if (isReservedIntrospectionKey(key)) {
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
const token = deposit(val)
|
|
28
|
+
if (val.family) {
|
|
29
|
+
let familyNode = base.get(val.family.key)
|
|
30
|
+
if (!familyNode || !(`familyMembers` in familyNode)) {
|
|
31
|
+
familyNode = {
|
|
32
|
+
key: val.family.key,
|
|
33
|
+
familyMembers: new Map(),
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
} else {
|
|
36
|
-
base.set(key, token)
|
|
35
|
+
base.set(val.family.key, familyNode)
|
|
37
36
|
}
|
|
37
|
+
familyNode.familyMembers.set(val.family.subKey, token)
|
|
38
|
+
} else {
|
|
39
|
+
base.set(key, token)
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
return base
|
|
@@ -42,7 +44,7 @@ export const attachAtomIndex = (
|
|
|
42
44
|
effects: [
|
|
43
45
|
({ setSelf }) => {
|
|
44
46
|
store.on.atomCreation.subscribe(`introspection`, (atomToken) => {
|
|
45
|
-
if (atomToken.key
|
|
47
|
+
if (isReservedIntrospectionKey(atomToken.key)) {
|
|
46
48
|
return
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
createRegularAtom,
|
|
5
5
|
createStandaloneSelector,
|
|
6
6
|
deposit,
|
|
7
|
+
isReservedIntrospectionKey,
|
|
7
8
|
} from "atom.io/internal"
|
|
8
9
|
|
|
9
10
|
import type { WritableTokenIndex } from "."
|
|
@@ -23,21 +24,22 @@ export const attachSelectorIndex = (
|
|
|
23
24
|
const base: SelectorTokenIndex = new Map()
|
|
24
25
|
for (const map of [store.readonlySelectors, store.selectors]) {
|
|
25
26
|
for (const [key, val] of map) {
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
if (isReservedIntrospectionKey(key)) {
|
|
28
|
+
continue
|
|
29
|
+
}
|
|
30
|
+
const token = deposit(val)
|
|
31
|
+
if (val.family) {
|
|
32
|
+
let familyNode = base.get(val.family.key)
|
|
33
|
+
if (!familyNode || !(`familyMembers` in familyNode)) {
|
|
34
|
+
familyNode = {
|
|
35
|
+
key: val.family.key,
|
|
36
|
+
familyMembers: new Map(),
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
} else {
|
|
39
|
-
base.set(key, token)
|
|
38
|
+
base.set(val.family.key, familyNode)
|
|
40
39
|
}
|
|
40
|
+
familyNode.familyMembers.set(val.family.subKey, token)
|
|
41
|
+
} else {
|
|
42
|
+
base.set(key, token)
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -48,7 +50,7 @@ export const attachSelectorIndex = (
|
|
|
48
50
|
store.on.selectorCreation.subscribe(
|
|
49
51
|
`introspection`,
|
|
50
52
|
(selectorToken) => {
|
|
51
|
-
if (selectorToken.key
|
|
53
|
+
if (isReservedIntrospectionKey(selectorToken.key)) {
|
|
52
54
|
return
|
|
53
55
|
}
|
|
54
56
|
|
|
@@ -23,6 +23,7 @@ export type ListResourcesParam = {
|
|
|
23
23
|
* @experimental
|
|
24
24
|
*/
|
|
25
25
|
export class Auditor {
|
|
26
|
+
public readonly store: Internal.Store
|
|
26
27
|
public auditorCreatedAt: number = performance.now()
|
|
27
28
|
public statesCreatedAt: Map<string, number> = new Map()
|
|
28
29
|
public readonly atomIndex: ReadonlySelectorToken<AtomTokenIndex>
|
|
@@ -37,9 +38,8 @@ export class Auditor {
|
|
|
37
38
|
/**
|
|
38
39
|
* @param {Store} store - The store to audit.
|
|
39
40
|
*/
|
|
40
|
-
public constructor(
|
|
41
|
-
|
|
42
|
-
) {
|
|
41
|
+
public constructor(store: Internal.Store = Internal.IMPLICIT.STORE) {
|
|
42
|
+
this.store = store
|
|
43
43
|
this.atomIndex = attachAtomIndex(this.store)
|
|
44
44
|
this.selectorIndex = attachSelectorIndex(this.store)
|
|
45
45
|
this.unsubscribeFromAtomCreation = this.store.on.atomCreation.subscribe(
|
package/json/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { JSON_DEFAULTS, JSON_TYPE_NAMES, fromEntries, isJson, parseJson, selectJson, selectJsonFamily, stringifyJson, toEntries } from '../../dist/chunk-
|
|
1
|
+
export { JSON_DEFAULTS, JSON_TYPE_NAMES, fromEntries, isJson, parseJson, selectJson, selectJsonFamily, stringifyJson, toEntries } from '../../dist/chunk-35NB2XZU.js';
|
|
2
2
|
import '../../dist/chunk-XWL6SNVU.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.3",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -59,38 +59,38 @@
|
|
|
59
59
|
"@types/npmlog": "7.0.0",
|
|
60
60
|
"@types/react": "19.0.10",
|
|
61
61
|
"@types/tmp": "0.2.6",
|
|
62
|
-
"@typescript-eslint/parser": "8.
|
|
63
|
-
"@typescript-eslint/rule-tester": "8.
|
|
64
|
-
"@typescript-eslint/utils": "8.
|
|
65
|
-
"@vitest/coverage-v8": "3.0.
|
|
66
|
-
"@vitest/ui": "3.0.
|
|
67
|
-
"bun-types": "1.2.
|
|
62
|
+
"@typescript-eslint/parser": "8.26.1",
|
|
63
|
+
"@typescript-eslint/rule-tester": "8.26.1",
|
|
64
|
+
"@typescript-eslint/utils": "8.26.1",
|
|
65
|
+
"@vitest/coverage-v8": "3.0.8",
|
|
66
|
+
"@vitest/ui": "3.0.8",
|
|
67
|
+
"bun-types": "1.2.5",
|
|
68
68
|
"concurrently": "9.1.2",
|
|
69
69
|
"drizzle-kit": "0.30.5",
|
|
70
70
|
"drizzle-orm": "0.40.0",
|
|
71
|
-
"eslint": "9.
|
|
72
|
-
"happy-dom": "17.
|
|
71
|
+
"eslint": "9.22.0",
|
|
72
|
+
"happy-dom": "17.4.4",
|
|
73
73
|
"http-proxy": "1.18.1",
|
|
74
|
-
"motion": "12.
|
|
74
|
+
"motion": "12.5.0",
|
|
75
75
|
"npmlog": "7.0.1",
|
|
76
76
|
"nyc": "17.1.0",
|
|
77
77
|
"postgres": "3.4.5",
|
|
78
|
-
"preact": "10.26.
|
|
78
|
+
"preact": "10.26.4",
|
|
79
79
|
"react": "19.0.0",
|
|
80
80
|
"react-dom": "19.0.0",
|
|
81
|
-
"react-router-dom": "7.
|
|
81
|
+
"react-router-dom": "7.3.0",
|
|
82
82
|
"socket.io": "4.8.1",
|
|
83
83
|
"socket.io-client": "4.8.1",
|
|
84
84
|
"tmp": "0.2.3",
|
|
85
85
|
"tsup": "8.4.0",
|
|
86
86
|
"tsx": "4.19.3",
|
|
87
87
|
"typescript": "5.8.2",
|
|
88
|
-
"vite": "6.2.
|
|
88
|
+
"vite": "6.2.2",
|
|
89
89
|
"vite-tsconfig-paths": "5.1.4",
|
|
90
|
-
"vitest": "3.0.
|
|
90
|
+
"vitest": "3.0.8",
|
|
91
91
|
"zod": "3.24.2",
|
|
92
|
-
"break-check": "0.6.
|
|
93
|
-
"recoverage": "0.
|
|
92
|
+
"break-check": "0.6.7",
|
|
93
|
+
"recoverage": "0.1.3"
|
|
94
94
|
},
|
|
95
95
|
"main": "dist/index.js",
|
|
96
96
|
"types": "dist/index.d.ts",
|
|
@@ -243,7 +243,9 @@
|
|
|
243
243
|
"watch:types": "tsc --watch --noEmit",
|
|
244
244
|
"lint": "concurrently \"bun:lint:*\"",
|
|
245
245
|
"test": "vitest",
|
|
246
|
-
"test:coverage": "
|
|
246
|
+
"test:coverage": "pnpm test:coverage:once && pnpm test:coverage:increased",
|
|
247
|
+
"test:coverage:once": "vitest run --coverage",
|
|
248
|
+
"test:coverage:increased": "recoverage",
|
|
247
249
|
"test:build": "bun run test:manifest && cross-env IMPORT=dist vitest run",
|
|
248
250
|
"test:once": "echo tested built code",
|
|
249
251
|
"test:once:public": "cross-env IMPORT=dist vitest run public",
|
package/react/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { StoreContext, StoreProvider, useI, useJSON, useO, useTL } from '../../dist/chunk-
|
|
2
|
-
import '../../dist/chunk-
|
|
1
|
+
export { StoreContext, StoreProvider, useI, useJSON, useO, useTL } from '../../dist/chunk-MENOYVPP.js';
|
|
2
|
+
import '../../dist/chunk-35NB2XZU.js';
|
|
3
3
|
import '../../dist/chunk-XWL6SNVU.js';
|