atom.io 0.32.2 → 0.32.4
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/data/src/struct.ts +1 -0
- package/dist/{chunk-RXQWAO26.js → chunk-7SJVR7FZ.js} +111 -119
- package/dist/{chunk-XN3EO2UT.js → chunk-IR77IXS7.js} +6 -3
- package/dist/{chunk-NDTM5IY3.js → chunk-PG57JXN4.js} +2 -2
- package/dist/{chunk-QRPY4LSO.js → chunk-PXB4YZDI.js} +4 -4
- package/dist/{chunk-KMBRCA5Q.js → chunk-Q6OOJWM4.js} +33 -31
- package/dist/{chunk-HEEVASKG.js → chunk-TJPLOX7Z.js} +4 -6
- package/dist/{chunk-YPME5OLO.js → chunk-U4K63VLA.js} +1 -1
- package/dist/index.js +1 -1
- package/eslint-plugin/dist/index.d.ts +2 -15
- package/internal/dist/index.d.ts +10 -4
- package/internal/dist/index.js +1 -1
- package/internal/src/families/create-writable-selector-family.ts +4 -2
- 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/join/find-relations-in-store.ts +12 -0
- package/internal/src/reserved-keys.ts +7 -0
- package/internal/src/selector/register-selector.ts +2 -1
- 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 +11 -8
- package/internal/src/transaction/build-transaction.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/json/dist/index.js +1 -1
- package/package.json +26 -24
- package/react/dist/index.js +2 -2
- package/react/src/use-i.ts +3 -5
- package/react-devtools/dist/index.d.ts +12 -3
- package/react-devtools/dist/index.js +80 -68
- package/react-devtools/src/AtomIODevtools.tsx +10 -2
- package/react-devtools/src/error-boundary/ReactErrorBoundary.tsx +1 -1
- package/react-devtools/src/json-editor/developer-interface.tsx +2 -2
- package/react-devtools/src/json-editor/editors-by-type/utilities/cast-json.ts +2 -2
- package/react-devtools/src/json-editor/editors-by-type/utilities/object-properties.ts +3 -3
- package/react-devtools/src/json-editor/index.ts +2 -5
- package/react-devtools/src/json-editor/json-editor-internal.tsx +4 -2
- package/realtime/dist/index.js +2 -2
- 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-react/src/use-single-effect.ts +2 -1
- package/realtime-server/dist/index.js +3 -3
- package/realtime-server/src/ipc-sockets/child-socket.ts +1 -1
- package/realtime-testing/dist/index.js +6 -6
- 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;
|
|
@@ -423,6 +423,9 @@ declare class Store implements Lineage {
|
|
|
423
423
|
logger: Logger;
|
|
424
424
|
constructor(config: Store[`config`], store?: Store | null);
|
|
425
425
|
}
|
|
426
|
+
declare global {
|
|
427
|
+
var ATOM_IO_IMPLICIT_STORE: Store | undefined;
|
|
428
|
+
}
|
|
426
429
|
declare const IMPLICIT: {
|
|
427
430
|
readonly STORE: Store;
|
|
428
431
|
};
|
|
@@ -638,6 +641,9 @@ declare class NotFoundError extends Error {
|
|
|
638
641
|
|
|
639
642
|
declare function prettyPrintTokenType(token: AtomIOToken): string;
|
|
640
643
|
|
|
644
|
+
type ReservedIntrospectionKey = `🔍 ${string}`;
|
|
645
|
+
declare function isReservedIntrospectionKey(value: string): value is ReservedIntrospectionKey;
|
|
646
|
+
|
|
641
647
|
declare const createReadonlySelector: <T>(store: Store, options: ReadonlySelectorOptions<T>, family: FamilyMetadata | undefined) => ReadonlySelectorToken<T>;
|
|
642
648
|
|
|
643
649
|
declare function createStandaloneSelector<T>(store: Store, options: WritableSelectorOptions<T>): WritableSelectorToken<T>;
|
|
@@ -695,7 +701,7 @@ type RegularAtom<T> = AtomIOState & {
|
|
|
695
701
|
};
|
|
696
702
|
type MutableAtom<T extends Transceiver<any>, J extends Json.Serializable> = AtomIOState & JsonInterface<T, J> & {
|
|
697
703
|
type: `mutable_atom`;
|
|
698
|
-
default:
|
|
704
|
+
default: () => T;
|
|
699
705
|
cleanup?: () => void;
|
|
700
706
|
};
|
|
701
707
|
type Atom<T> = RegularAtom<T> | (T extends Transceiver<any> ? MutableAtom<T, any> : never);
|
|
@@ -741,4 +747,4 @@ type WritableFamily<T, K extends Canonical> = AtomFamily<T, K> | WritableSelecto
|
|
|
741
747
|
type ReadableFamily<T, K extends Canonical> = AtomFamily<T, K> | SelectorFamily<T, K>;
|
|
742
748
|
type AtomIOInternalResource = ReadableFamily<any, any> | ReadableState<any> | Timeline<any> | Transaction<any>;
|
|
743
749
|
|
|
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 };
|
|
750
|
+
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-7SJVR7FZ.js';
|
|
2
2
|
import '../../dist/chunk-XWL6SNVU.js';
|
|
@@ -76,8 +76,10 @@ export function createWritableSelectorFamily<T, K extends Canonical>(
|
|
|
76
76
|
default: (key: K) => {
|
|
77
77
|
const getFn = options.get(key)
|
|
78
78
|
return getFn({
|
|
79
|
-
get: ((...
|
|
80
|
-
|
|
79
|
+
get: ((...args: Parameters<typeof getState>) =>
|
|
80
|
+
getFromStore(store, ...args)) as typeof getState,
|
|
81
|
+
find: ((...args: Parameters<typeof findState>) =>
|
|
82
|
+
findInStore(store, ...args)) as typeof findState,
|
|
81
83
|
json: (token) => getJsonToken(store, token),
|
|
82
84
|
})
|
|
83
85
|
},
|
|
@@ -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) {
|
|
@@ -26,11 +26,13 @@ export function findRelationsInStore<
|
|
|
26
26
|
const keyBA = `${token.b}KeyOf${capitalize(token.a)}`
|
|
27
27
|
relations = {
|
|
28
28
|
get [keyAB]() {
|
|
29
|
+
// @ts-expect-error way too complicated to represent
|
|
29
30
|
const familyAB = myJoin.states[keyAB as any]
|
|
30
31
|
const state = findInStore(store, familyAB, key)
|
|
31
32
|
return state
|
|
32
33
|
},
|
|
33
34
|
get [keyBA]() {
|
|
35
|
+
// @ts-expect-error way too complicated to represent
|
|
34
36
|
const familyBA = myJoin.states[keyBA as any]
|
|
35
37
|
const state = findInStore(store, familyBA, key)
|
|
36
38
|
return state
|
|
@@ -41,11 +43,13 @@ export function findRelationsInStore<
|
|
|
41
43
|
const entryBA = `${token.b}EntryOf${capitalize(token.a)}`
|
|
42
44
|
Object.assign(relations, {
|
|
43
45
|
get [entryAB]() {
|
|
46
|
+
// @ts-expect-error way too complicated to represent
|
|
44
47
|
const familyAB = myJoin.states[entryAB as any]
|
|
45
48
|
const state = findInStore(store, familyAB, key)
|
|
46
49
|
return state
|
|
47
50
|
},
|
|
48
51
|
get [entryBA]() {
|
|
52
|
+
// @ts-expect-error way too complicated to represent
|
|
49
53
|
const familyBA = myJoin.states[entryBA as any]
|
|
50
54
|
const state = findInStore(store, familyBA, key)
|
|
51
55
|
return state
|
|
@@ -59,11 +63,13 @@ export function findRelationsInStore<
|
|
|
59
63
|
const keysBA = `${token.b}KeysOf${capitalize(token.a)}`
|
|
60
64
|
relations = {
|
|
61
65
|
get [keyAB]() {
|
|
66
|
+
// @ts-expect-error way too complicated to represent
|
|
62
67
|
const familyAB = myJoin.states[keyAB as any]
|
|
63
68
|
const state = findInStore(store, familyAB, key)
|
|
64
69
|
return state
|
|
65
70
|
},
|
|
66
71
|
get [keysBA]() {
|
|
72
|
+
// @ts-expect-error way too complicated to represent
|
|
67
73
|
const familyBA = myJoin.states[keysBA as any]
|
|
68
74
|
const state = findInStore(store, familyBA, key)
|
|
69
75
|
return state
|
|
@@ -74,11 +80,13 @@ export function findRelationsInStore<
|
|
|
74
80
|
const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`
|
|
75
81
|
Object.assign(relations, {
|
|
76
82
|
get [entryAB]() {
|
|
83
|
+
// @ts-expect-error way too complicated to represent
|
|
77
84
|
const familyAB = myJoin.states[entryAB as any]
|
|
78
85
|
const state = findInStore(store, familyAB, key)
|
|
79
86
|
return state
|
|
80
87
|
},
|
|
81
88
|
get [entriesBA]() {
|
|
89
|
+
// @ts-expect-error way too complicated to represent
|
|
82
90
|
const familyBA = myJoin.states[entriesBA as any]
|
|
83
91
|
const state = findInStore(store, familyBA, key)
|
|
84
92
|
return state
|
|
@@ -92,11 +100,13 @@ export function findRelationsInStore<
|
|
|
92
100
|
const keysBA = `${token.b}KeysOf${capitalize(token.a)}`
|
|
93
101
|
relations = {
|
|
94
102
|
get [keysAB]() {
|
|
103
|
+
// @ts-expect-error way too complicated to represent
|
|
95
104
|
const familyAB = myJoin.states[keysAB as any]
|
|
96
105
|
const state = findInStore(store, familyAB, key)
|
|
97
106
|
return state
|
|
98
107
|
},
|
|
99
108
|
get [keysBA]() {
|
|
109
|
+
// @ts-expect-error way too complicated to represent
|
|
100
110
|
const familyBA = myJoin.states[keysBA as any]
|
|
101
111
|
const state = findInStore(store, familyBA, key)
|
|
102
112
|
return state
|
|
@@ -107,11 +117,13 @@ export function findRelationsInStore<
|
|
|
107
117
|
const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`
|
|
108
118
|
Object.assign(relations, {
|
|
109
119
|
get [entriesAB]() {
|
|
120
|
+
// @ts-expect-error way too complicated to represent
|
|
110
121
|
const familyAB = myJoin.states[entriesAB as any]
|
|
111
122
|
const state = findInStore(store, familyAB, key)
|
|
112
123
|
return state
|
|
113
124
|
},
|
|
114
125
|
get [entriesBA]() {
|
|
126
|
+
// @ts-expect-error way too complicated to represent
|
|
115
127
|
const familyBA = myJoin.states[entriesBA as any]
|
|
116
128
|
const state = findInStore(store, familyBA, key)
|
|
117
129
|
return state
|
|
@@ -86,6 +86,7 @@ export const registerSelector = (
|
|
|
86
86
|
const state = withdraw(target, token)
|
|
87
87
|
setAtomOrSelector(target, state, value)
|
|
88
88
|
}) as typeof setState,
|
|
89
|
-
find: ((
|
|
89
|
+
find: ((...args: Parameters<typeof findState>) =>
|
|
90
|
+
findInStore(store, ...args)) as typeof findState,
|
|
90
91
|
json: (token) => getJsonToken(store, token),
|
|
91
92
|
})
|
|
@@ -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) => {
|
|
@@ -249,15 +250,17 @@ export class Store implements Lineage {
|
|
|
249
250
|
}
|
|
250
251
|
}
|
|
251
252
|
|
|
253
|
+
declare global {
|
|
254
|
+
var ATOM_IO_IMPLICIT_STORE: Store | undefined
|
|
255
|
+
}
|
|
256
|
+
|
|
252
257
|
export const IMPLICIT = {
|
|
253
258
|
get STORE(): Store {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
return globalThis.ATOM_IO_IMPLICIT_STORE as Store
|
|
259
|
+
globalThis.ATOM_IO_IMPLICIT_STORE ??= new Store({
|
|
260
|
+
name: `IMPLICIT_STORE`,
|
|
261
|
+
lifespan: `ephemeral`,
|
|
262
|
+
})
|
|
263
|
+
return globalThis.ATOM_IO_IMPLICIT_STORE
|
|
261
264
|
},
|
|
262
265
|
}
|
|
263
266
|
|
|
@@ -79,7 +79,8 @@ export const buildTransaction = (
|
|
|
79
79
|
}) as typeof setState,
|
|
80
80
|
run: (token, identifier = arbitrary()) =>
|
|
81
81
|
actUponStore(child, token, identifier),
|
|
82
|
-
find: ((
|
|
82
|
+
find: ((...ps: Parameters<typeof findState>) =>
|
|
83
|
+
findInStore(store, ...ps)) as typeof findState,
|
|
83
84
|
json: (token) => getJsonToken(child, token),
|
|
84
85
|
dispose: ((...ps: Parameters<typeof disposeState>) => {
|
|
85
86
|
disposeFromStore(child, ...ps)
|
|
@@ -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-Q6OOJWM4.js';
|
|
2
|
+
import '../../dist/chunk-7SJVR7FZ.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
|
|
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-7SJVR7FZ.js';
|
|
2
2
|
import '../../dist/chunk-XWL6SNVU.js';
|