atom.io 0.31.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/dist/index.d.ts +867 -101
- package/data/dist/index.js +10 -558
- package/data/src/index.ts +0 -2
- package/data/src/struct-family.ts +1 -1
- package/data/src/struct.ts +1 -2
- package/dist/chunk-354XQWHH.js +153 -0
- package/dist/chunk-4LWKCEW3.js +14 -0
- package/dist/chunk-5F2V7S3B.js +83 -0
- package/dist/chunk-ECOMOMUN.js +631 -0
- package/dist/{chunk-42UH5F5Q.js → chunk-GY2XQYZY.js} +2051 -755
- package/dist/chunk-NF7FJKJD.js +107 -0
- package/dist/chunk-R3ZUK5EH.js +1024 -0
- package/dist/chunk-Z2UJW4NQ.js +523 -0
- package/dist/index.d.ts +855 -127
- package/dist/index.js +1 -143
- package/eslint-plugin/dist/index.d.ts +1 -30
- package/eslint-plugin/dist/index.js +0 -146
- package/eslint-plugin/src/index.ts +0 -1
- package/eslint-plugin/src/rules/index.ts +0 -1
- package/internal/dist/index.d.ts +794 -70
- package/internal/dist/index.js +1 -2
- package/internal/src/atom/create-regular-atom.ts +3 -3
- package/internal/src/atom/dispose-atom.ts +4 -13
- package/internal/src/atom/is-default.ts +3 -3
- package/internal/src/caching.ts +5 -5
- package/internal/src/capitalize.ts +3 -0
- package/internal/src/families/create-readonly-selector-family.ts +5 -6
- package/internal/src/families/create-writable-selector-family.ts +1 -4
- package/internal/src/families/dispose-from-store.ts +3 -13
- package/internal/src/families/find-in-store.ts +1 -6
- package/internal/src/get-state/get-from-store.ts +2 -2
- package/internal/src/get-state/read-or-compute-value.ts +1 -1
- package/internal/src/index.ts +19 -9
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +2 -3
- package/internal/src/install-into-store.ts +48 -0
- package/internal/src/join/edit-relations-in-store.ts +32 -0
- package/internal/src/join/find-relations-in-store.ts +124 -0
- package/internal/src/join/get-internal-relations-from-store.ts +14 -0
- package/internal/src/join/get-join.ts +31 -0
- package/internal/src/join/index.ts +5 -0
- package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
- package/internal/src/keys.ts +7 -7
- package/internal/src/molecule.ts +299 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-token.ts +1 -1
- package/internal/src/mutable/tracker-family.ts +19 -17
- package/internal/src/mutable/tracker.ts +8 -8
- package/internal/src/not-found-error.ts +8 -30
- package/internal/src/pretty-print.ts +2 -13
- package/internal/src/selector/create-readonly-selector.ts +3 -7
- package/internal/src/selector/create-writable-selector.ts +4 -4
- package/internal/src/selector/dispose-selector.ts +20 -11
- package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
- package/internal/src/selector/register-selector.ts +7 -17
- package/internal/src/selector/trace-selector-atoms.ts +2 -2
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/set-state/emit-update.ts +1 -1
- package/internal/src/set-state/evict-downstream.ts +1 -1
- package/internal/src/set-state/set-atom-or-selector.ts +1 -1
- package/internal/src/set-state/set-atom.ts +10 -10
- package/internal/src/set-state/set-into-store.ts +2 -2
- package/internal/src/set-state/stow-update.ts +1 -1
- package/internal/src/store/deposit.ts +10 -8
- package/internal/src/store/store.ts +1 -1
- package/internal/src/store/withdraw.ts +34 -53
- package/internal/src/subscribe/recall-state.ts +1 -1
- package/internal/src/subscribe/subscribe-in-store.ts +3 -3
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
- package/internal/src/subscribe/subscribe-to-state.ts +5 -5
- package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
- package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
- package/internal/src/timeline/create-timeline.ts +17 -37
- package/internal/src/transaction/act-upon-store.ts +2 -2
- package/internal/src/transaction/apply-transaction.ts +5 -5
- package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +5 -8
- package/internal/src/transaction/create-transaction.ts +3 -3
- package/internal/src/transaction/get-epoch-number.ts +3 -3
- package/internal/src/transaction/set-epoch-number.ts +2 -2
- package/introspection/dist/index.d.ts +922 -6
- package/introspection/dist/index.js +2 -620
- package/json/dist/index.d.ts +899 -5
- package/json/dist/index.js +1 -81
- package/json/src/select-json-family.ts +3 -14
- package/package.json +27 -45
- package/react/dist/index.d.ts +921 -3
- package/react/dist/index.js +2 -82
- package/react/src/use-o.ts +1 -1
- package/react/src/use-tl.ts +2 -2
- package/react-devtools/dist/index.css +16 -14
- package/react-devtools/dist/index.d.ts +26 -1
- package/react-devtools/dist/index.js +6 -6
- package/react-devtools/src/devtools.scss +16 -14
- package/realtime/dist/index.d.ts +202 -8
- package/realtime/dist/index.js +2 -107
- package/realtime/src/realtime-continuity.ts +2 -2
- package/realtime/src/shared-room-store.ts +1 -2
- package/realtime-client/dist/index.d.ts +960 -22
- package/realtime-client/dist/index.js +3 -509
- package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
- package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
- package/realtime-client/src/pull-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-atom.ts +2 -2
- package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-mutable-atom.ts +2 -2
- package/realtime-client/src/pull-selector-family-member.ts +4 -4
- package/realtime-client/src/pull-selector.ts +4 -4
- package/realtime-client/src/push-state.ts +5 -10
- package/realtime-client/src/server-action.ts +4 -4
- package/realtime-client/src/sync-continuity.ts +6 -6
- package/realtime-react/dist/index.d.ts +166 -12
- package/realtime-react/dist/index.js +5 -154
- package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
- package/realtime-react/src/use-pull-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector.ts +1 -1
- package/realtime-react/src/use-push.ts +1 -1
- package/realtime-react/src/use-server-action.ts +2 -2
- package/realtime-react/src/use-sync-continuity.ts +1 -1
- package/realtime-server/dist/index.d.ts +971 -28
- package/realtime-server/dist/index.js +3 -1001
- package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
- package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
- package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
- package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
- package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
- package/realtime-server/src/realtime-action-receiver.ts +1 -1
- package/realtime-server/src/realtime-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
- package/realtime-server/src/realtime-state-provider.ts +2 -2
- package/realtime-testing/dist/index.d.ts +1091 -3
- package/realtime-testing/dist/index.js +23 -26
- package/realtime-testing/src/setup-realtime-test.tsx +6 -5
- package/src/atom.ts +53 -29
- package/src/dispose-state.ts +12 -2
- package/{ephemeral/src → src}/find-state.ts +35 -25
- package/src/get-state.ts +16 -0
- package/src/index.ts +77 -3
- package/src/join.ts +218 -0
- package/src/realm.ts +169 -0
- package/src/selector.ts +20 -0
- package/src/set-state.ts +16 -8
- package/src/silo.ts +13 -7
- package/src/timeline.ts +1 -1
- package/src/transaction.ts +4 -8
- package/transceivers/set-rtx/dist/index.d.ts +37 -2
- package/transceivers/set-rtx/dist/index.js +1 -212
- package/transceivers/set-rtx/src/set-rtx.ts +4 -1
- package/web/dist/index.d.ts +30 -1
- package/web/dist/index.js +1 -15
- package/data/src/until.ts +0 -15
- package/dist/chunk-ICGFFQ3H.js +0 -272
- package/ephemeral/dist/index.d.ts +0 -57
- package/ephemeral/dist/index.js +0 -9
- package/ephemeral/package.json +0 -13
- package/ephemeral/src/index.ts +0 -1
- package/eslint-plugin/src/rules/lifespan.ts +0 -203
- package/immortal/dist/index.d.ts +0 -12
- package/immortal/dist/index.js +0 -9
- package/immortal/package.json +0 -13
- package/immortal/src/index.ts +0 -1
- package/immortal/src/seek-state.ts +0 -60
- package/src/allocate.ts +0 -443
- package/src/molecule.ts +0 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,47 +1,541 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
type primitive = boolean | number | string | null;
|
|
2
|
+
declare namespace Json {
|
|
3
|
+
namespace Tree {
|
|
4
|
+
type Array<Element = unknown> = ReadonlyArray<Element>;
|
|
5
|
+
type Object<K extends string = string, V = unknown> = Record<K, V>;
|
|
6
|
+
type Fork = Array | Object;
|
|
7
|
+
type Leaf = primitive;
|
|
8
|
+
type Node = Fork | Leaf;
|
|
9
|
+
}
|
|
10
|
+
type Serializable = primitive | Readonly<{
|
|
11
|
+
[key: string]: Serializable;
|
|
12
|
+
}> | ReadonlyArray<Serializable>;
|
|
13
|
+
type Object<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
|
|
14
|
+
type Array<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
|
|
15
|
+
}
|
|
16
|
+
type stringified<J extends Json.Serializable> = J extends string ? `"${J}"` : J extends number ? `${J}` : J extends true ? `true` : J extends false ? `false` : J extends boolean ? `false` | `true` : J extends null ? `null` : string & {
|
|
17
|
+
__json?: J;
|
|
18
|
+
};
|
|
19
|
+
type Canonical = primitive | ReadonlyArray<Canonical>;
|
|
20
|
+
type JsonInterface<T, J extends Json.Serializable = Json.Serializable> = {
|
|
21
|
+
toJson: (t: T) => J;
|
|
22
|
+
fromJson: (json: J) => T;
|
|
23
|
+
};
|
|
6
24
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
25
|
+
declare class CircularBuffer<T> {
|
|
26
|
+
protected _buffer: T[];
|
|
27
|
+
protected _index: number;
|
|
28
|
+
constructor(array: T[]);
|
|
29
|
+
constructor(length: number);
|
|
30
|
+
get buffer(): ReadonlyArray<T | undefined>;
|
|
31
|
+
get index(): number;
|
|
32
|
+
add(item: T): void;
|
|
33
|
+
copy(): CircularBuffer<T>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type Func = (...parameters: any[]) => any;
|
|
37
|
+
type Flat<R extends {
|
|
38
|
+
[K in PropertyKey]: any;
|
|
39
|
+
}> = {
|
|
40
|
+
[K in keyof R]: R[K];
|
|
13
41
|
};
|
|
14
|
-
type
|
|
15
|
-
|
|
42
|
+
type Count<N extends number, A extends any[] = []> = [
|
|
43
|
+
...A,
|
|
44
|
+
any
|
|
45
|
+
][`length`] extends N ? A[`length`] : A[`length`] | Count<N, [...A, any]>;
|
|
46
|
+
type Each<E extends any[]> = {
|
|
47
|
+
[P in Count<E[`length`]>]: E[P];
|
|
48
|
+
};
|
|
49
|
+
type Refinement<A, B extends A> = (a: A) => a is B;
|
|
50
|
+
|
|
51
|
+
type JunctionEntriesBase<AType extends string, BType extends string, Content extends Json.Object | null> = {
|
|
52
|
+
readonly relations: ([AType, BType[]] | [BType, AType[]])[];
|
|
53
|
+
readonly contents: [string, Content][];
|
|
54
|
+
};
|
|
55
|
+
interface JunctionEntries<AType extends string, BType extends string, Content extends Json.Object | null> extends Json.Object, JunctionEntriesBase<AType, BType, Content> {
|
|
56
|
+
}
|
|
57
|
+
type JunctionSchemaBase<ASide extends string, BSide extends string> = {
|
|
58
|
+
readonly between: [a: ASide, b: BSide];
|
|
59
|
+
readonly cardinality: `1:1` | `1:n` | `n:n`;
|
|
60
|
+
};
|
|
61
|
+
interface JunctionSchema<ASide extends string, BSide extends string> extends Json.Object, JunctionSchemaBase<ASide, BSide> {
|
|
62
|
+
}
|
|
63
|
+
type BaseExternalStoreConfiguration = {
|
|
64
|
+
addRelation: (a: string, b: string) => void;
|
|
65
|
+
deleteRelation: (a: string, b: string) => void;
|
|
66
|
+
replaceRelationsSafely: (a: string, bs: string[]) => void;
|
|
67
|
+
replaceRelationsUnsafely: (a: string, bs: string[]) => void;
|
|
68
|
+
getRelatedKeys(key: string): Set<string> | undefined;
|
|
69
|
+
has: (a: string, b?: string) => boolean;
|
|
70
|
+
};
|
|
71
|
+
type ExternalStoreWithContentConfiguration<Content extends Json.Object> = {
|
|
72
|
+
getContent: (contentKey: string) => Content | undefined;
|
|
73
|
+
setContent: (contentKey: string, content: Content) => void;
|
|
74
|
+
deleteContent: (contentKey: string) => void;
|
|
75
|
+
};
|
|
76
|
+
type Empty<Obj extends object> = {
|
|
77
|
+
[Key in keyof Obj]?: undefined;
|
|
78
|
+
};
|
|
79
|
+
type ExternalStoreConfiguration<Content extends Json.Object | null> = Content extends Json.Object ? BaseExternalStoreConfiguration & ExternalStoreWithContentConfiguration<Content> : BaseExternalStoreConfiguration & Empty<ExternalStoreWithContentConfiguration<Json.Object>>;
|
|
80
|
+
type JunctionAdvancedConfiguration<AType extends string, BType extends string, Content extends Json.Object | null> = {
|
|
81
|
+
warn?: (...args: any[]) => void;
|
|
82
|
+
externalStore?: ExternalStoreConfiguration<Content>;
|
|
83
|
+
isAType?: Refinement<string, AType>;
|
|
84
|
+
isBType?: Refinement<string, BType>;
|
|
85
|
+
isContent?: Refinement<unknown, Content>;
|
|
86
|
+
makeContentKey?: (a: AType, b: BType) => string;
|
|
87
|
+
};
|
|
88
|
+
type JunctionJSON<ASide extends string, AType extends string, BSide extends string, BType extends string, Content extends Json.Object | null> = JunctionEntries<AType, BType, Content> & JunctionSchema<ASide, BSide>;
|
|
89
|
+
declare class Junction<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Content extends Json.Object | null = null> {
|
|
90
|
+
readonly a: ASide;
|
|
91
|
+
readonly b: BSide;
|
|
92
|
+
readonly cardinality: `1:1` | `1:n` | `n:n`;
|
|
93
|
+
readonly relations: Map<AType | BType, Set<AType> | Set<BType>>;
|
|
94
|
+
readonly contents: Map<string, Content>;
|
|
95
|
+
isAType?: Refinement<string, AType> | null;
|
|
96
|
+
isBType?: Refinement<string, BType> | null;
|
|
97
|
+
isContent: Refinement<unknown, Content> | null;
|
|
98
|
+
makeContentKey: (a: AType, b: BType) => string;
|
|
99
|
+
warn?: (...args: any[]) => void;
|
|
100
|
+
getRelatedKeys(key: AType): Set<BType> | undefined;
|
|
101
|
+
getRelatedKeys(key: BType): Set<AType> | undefined;
|
|
102
|
+
getRelatedKeys(key: AType | BType): Set<AType> | Set<BType> | undefined;
|
|
103
|
+
protected addRelation(a: AType, b: BType): void;
|
|
104
|
+
protected deleteRelation(a: AType, b: BType): void;
|
|
105
|
+
protected replaceRelationsUnsafely(a: AType, bs: BType[]): void;
|
|
106
|
+
protected replaceRelationsUnsafely(b: BType, as: AType[]): void;
|
|
107
|
+
protected replaceRelationsSafely(a: AType, bs: BType[]): void;
|
|
108
|
+
protected replaceRelationsSafely(b: BType, as: AType[]): void;
|
|
109
|
+
protected getContentInternal(contentKey: string): Content | undefined;
|
|
110
|
+
protected setContent(contentKey: string, content: Content): void;
|
|
111
|
+
protected deleteContent(contentKey: string): void;
|
|
112
|
+
constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<NoInfer<AType>, NoInfer<BType>, Content>>, config?: JunctionAdvancedConfiguration<AType, BType, Content>);
|
|
113
|
+
toJSON(): JunctionJSON<ASide, AType, BSide, BType, Content>;
|
|
114
|
+
set(a: AType, ...rest: Content extends null ? [b: BType] : [b: BType, content: Content]): this;
|
|
115
|
+
set(relation: {
|
|
116
|
+
[Key in ASide]: AType;
|
|
117
|
+
} & {
|
|
118
|
+
[Key in BSide]: BType;
|
|
119
|
+
}, ...rest: Content extends null ? [] | [void?: undefined] : [content: Content]): this;
|
|
120
|
+
delete(a: AType, b?: BType): this;
|
|
121
|
+
delete(b: BType, a?: AType): this;
|
|
122
|
+
delete(relation: {
|
|
123
|
+
[Key in ASide]: AType;
|
|
124
|
+
} | {
|
|
125
|
+
[Key in BSide]: BType;
|
|
126
|
+
} | ({
|
|
127
|
+
[Key in ASide]: AType;
|
|
128
|
+
} & {
|
|
129
|
+
[Key in BSide]: BType;
|
|
130
|
+
}), b?: undefined): this;
|
|
131
|
+
getRelatedKey(key: AType): BType | undefined;
|
|
132
|
+
getRelatedKey(key: BType): AType | undefined;
|
|
133
|
+
replaceRelations(a: AType, relations: Content extends null ? BType[] : Record<BType, Content>, config?: {
|
|
134
|
+
reckless: boolean;
|
|
135
|
+
}): this;
|
|
136
|
+
replaceRelations(b: BType, relations: Content extends null ? AType[] : Record<AType, Content>, config?: {
|
|
137
|
+
reckless: boolean;
|
|
138
|
+
}): this;
|
|
139
|
+
getContent(a: AType, b: BType): Content | undefined;
|
|
140
|
+
getRelationEntries(input: Record<ASide, AType>): [BType, Content][];
|
|
141
|
+
getRelationEntries(input: Record<BSide, BType>): [AType, Content][];
|
|
142
|
+
has(a: AType, b?: BType): boolean;
|
|
143
|
+
has(b: BType, a?: AType): boolean;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
declare class Subject<T> {
|
|
147
|
+
Subscriber: (value: T) => void;
|
|
148
|
+
subscribers: Map<string, this[`Subscriber`]>;
|
|
149
|
+
subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
|
|
150
|
+
private unsubscribe;
|
|
151
|
+
next(value: T): void;
|
|
152
|
+
}
|
|
153
|
+
declare class StatefulSubject<T> extends Subject<T> {
|
|
154
|
+
state: T;
|
|
155
|
+
constructor(initialState: T);
|
|
156
|
+
next(value: T): void;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
type Transaction<F extends Func> = {
|
|
160
|
+
key: string;
|
|
161
|
+
type: `transaction`;
|
|
162
|
+
install: (store: Store) => void;
|
|
163
|
+
subject: Subject<TransactionUpdate<F>>;
|
|
164
|
+
run: (parameters: Parameters<F>, id?: string) => ReturnType<F>;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
type TransactionProgress<F extends Func> = {
|
|
168
|
+
phase: `applying` | `building`;
|
|
169
|
+
update: TransactionUpdate<F>;
|
|
170
|
+
toolkit: ActorToolkit;
|
|
171
|
+
};
|
|
172
|
+
type TransactionEpoch = {
|
|
173
|
+
epoch: Map<string, number>;
|
|
174
|
+
actionContinuities: Junction<`continuity`, string, `action`, string>;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
type SetUpdate = `add:${string}` | `clear:${string}` | `del:${string}` | `tx:${string}`;
|
|
178
|
+
type NumberedSetUpdate = `${number}=${SetUpdate}`;
|
|
179
|
+
interface SetRTXJson<P extends primitive> extends Json.Object {
|
|
180
|
+
members: P[];
|
|
181
|
+
cache: (NumberedSetUpdate | null)[];
|
|
182
|
+
cacheLimit: number;
|
|
183
|
+
cacheIdx: number;
|
|
184
|
+
cacheUpdateNumber: number;
|
|
185
|
+
}
|
|
186
|
+
declare class SetRTX<P extends primitive> extends Set<P> implements Transceiver<NumberedSetUpdate>, Lineage {
|
|
187
|
+
mode: TransceiverMode;
|
|
188
|
+
readonly subject: Subject<SetUpdate>;
|
|
189
|
+
cacheLimit: number;
|
|
190
|
+
cache: (NumberedSetUpdate | null)[];
|
|
191
|
+
cacheIdx: number;
|
|
192
|
+
cacheUpdateNumber: number;
|
|
193
|
+
constructor(values?: Iterable<P>, cacheLimit?: number);
|
|
194
|
+
toJSON(): SetRTXJson<P>;
|
|
195
|
+
static fromJSON<P extends primitive>(json: SetRTXJson<P>): SetRTX<P>;
|
|
196
|
+
add(value: P): this;
|
|
197
|
+
clear(): void;
|
|
198
|
+
delete(value: P): boolean;
|
|
199
|
+
readonly parent: SetRTX<P> | null;
|
|
200
|
+
child: SetRTX<P> | null;
|
|
201
|
+
transactionUpdates: SetUpdate[] | null;
|
|
202
|
+
transaction(run: (child: SetRTX<P>) => boolean): void;
|
|
203
|
+
protected _subscribe(key: string, fn: (update: SetUpdate) => void): () => void;
|
|
204
|
+
subscribe(key: string, fn: (update: NumberedSetUpdate) => void): () => void;
|
|
205
|
+
emit(update: SetUpdate): void;
|
|
206
|
+
private doStep;
|
|
207
|
+
getUpdateNumber(update: NumberedSetUpdate): number;
|
|
208
|
+
do(update: NumberedSetUpdate): number | `OUT_OF_RANGE` | null;
|
|
209
|
+
undoStep(update: SetUpdate): void;
|
|
210
|
+
undo(update: NumberedSetUpdate): number | null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
type Molecule<K extends Canonical> = {
|
|
214
|
+
readonly key: K;
|
|
215
|
+
readonly stringKey: stringified<K>;
|
|
216
|
+
readonly dependsOn: `all` | `any`;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
type JoinStateFamilies<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? {
|
|
220
|
+
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<[
|
|
221
|
+
AType,
|
|
222
|
+
Content
|
|
223
|
+
] | null, BType>;
|
|
224
|
+
} & {
|
|
225
|
+
readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<[
|
|
226
|
+
BType,
|
|
227
|
+
Content
|
|
228
|
+
] | null, AType>;
|
|
229
|
+
} : {}) & {
|
|
230
|
+
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<AType | null, BType>;
|
|
231
|
+
} & {
|
|
232
|
+
readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<BType | null, AType>;
|
|
233
|
+
} : Cardinality extends `1:n` ? (Content extends Json.Object ? {
|
|
234
|
+
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<[
|
|
235
|
+
AType,
|
|
236
|
+
Content
|
|
237
|
+
] | null, BType>;
|
|
238
|
+
} & {
|
|
239
|
+
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<[
|
|
240
|
+
BType,
|
|
241
|
+
Content
|
|
242
|
+
][], AType>;
|
|
243
|
+
} : {}) & {
|
|
244
|
+
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<AType | null, BType>;
|
|
245
|
+
} & {
|
|
246
|
+
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<BType[], AType>;
|
|
247
|
+
} : Cardinality extends `n:n` ? (Content extends Json.Object ? {
|
|
248
|
+
readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<[
|
|
249
|
+
AType,
|
|
250
|
+
Content
|
|
251
|
+
][], BType>;
|
|
252
|
+
} & {
|
|
253
|
+
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<[
|
|
254
|
+
BType,
|
|
255
|
+
Content
|
|
256
|
+
][], AType>;
|
|
257
|
+
} : {}) & {
|
|
258
|
+
readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlySelectorFamilyToken<AType[], BType>;
|
|
259
|
+
} & {
|
|
260
|
+
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<BType[], AType>;
|
|
261
|
+
} : never;
|
|
262
|
+
declare class Join<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object | null = null, const ContentKey extends CompoundTypedKey<`content`, ASide, BSide> = CompoundTypedKey<`content`, ASide, BSide>> {
|
|
263
|
+
private toolkit;
|
|
264
|
+
options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>;
|
|
265
|
+
defaultContent: Content | undefined;
|
|
266
|
+
molecules: Map<string, Molecule<any>>;
|
|
267
|
+
relations: Junction<ASide, AType, BSide, BType, Content>;
|
|
268
|
+
states: JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>;
|
|
269
|
+
core: {
|
|
270
|
+
relatedKeysAtoms: MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string>;
|
|
271
|
+
};
|
|
272
|
+
transact(toolkit: SetterToolkit, run: (join: Join<ASide, AType, BSide, BType, Cardinality, Content>) => void): void;
|
|
273
|
+
store: Store;
|
|
274
|
+
realm: Anarchy;
|
|
275
|
+
[Symbol.dispose](): void;
|
|
276
|
+
constructor(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>, defaultContent: Content | undefined, store?: Store);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
interface Lineage {
|
|
280
|
+
parent: typeof this | null;
|
|
281
|
+
child: typeof this | null;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
type OperationProgress = {
|
|
285
|
+
open: false;
|
|
286
|
+
} | {
|
|
287
|
+
open: true;
|
|
288
|
+
done: Set<string>;
|
|
289
|
+
prev: Map<string, any>;
|
|
290
|
+
time: number;
|
|
291
|
+
token: WritableToken<any>;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
type TimelineAtomUpdate<ManagedAtom extends TimelineManageable> = Flat<StateUpdate<TokenType<ManagedAtom>> & {
|
|
295
|
+
key: string;
|
|
296
|
+
type: `atom_update`;
|
|
297
|
+
timestamp: number;
|
|
298
|
+
family?: FamilyMetadata;
|
|
299
|
+
}>;
|
|
300
|
+
type TimelineSelectorUpdate<ManagedAtom extends TimelineManageable> = {
|
|
301
|
+
key: string;
|
|
302
|
+
type: `selector_update`;
|
|
303
|
+
timestamp: number;
|
|
304
|
+
atomUpdates: Omit<TimelineAtomUpdate<ManagedAtom>, `timestamp`>[];
|
|
305
|
+
};
|
|
306
|
+
type TimelineTransactionUpdate = Flat<TransactionUpdate<Func> & {
|
|
307
|
+
key: string;
|
|
308
|
+
type: `transaction_update`;
|
|
309
|
+
timestamp: number;
|
|
310
|
+
}>;
|
|
311
|
+
type TimelineStateCreation<T extends ReadableToken<any>> = Flat<StateCreation<T> & {
|
|
312
|
+
timestamp: number;
|
|
313
|
+
}>;
|
|
314
|
+
type TimelineStateDisposal<T extends ReadableToken<any>> = Flat<StateDisposal<T> & {
|
|
315
|
+
timestamp: number;
|
|
316
|
+
}>;
|
|
317
|
+
type TimelineMoleculeCreation = Flat<MoleculeCreation & {
|
|
318
|
+
timestamp: number;
|
|
319
|
+
}>;
|
|
320
|
+
type TimelineMoleculeDisposal = Flat<MoleculeDisposal & {
|
|
321
|
+
timestamp: number;
|
|
322
|
+
}>;
|
|
323
|
+
type Timeline<ManagedAtom extends TimelineManageable> = {
|
|
324
|
+
type: `timeline`;
|
|
325
|
+
key: string;
|
|
326
|
+
at: number;
|
|
327
|
+
shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<ManagedAtom>) => boolean;
|
|
328
|
+
timeTraveling: `into_future` | `into_past` | null;
|
|
329
|
+
history: TimelineUpdate<ManagedAtom>[];
|
|
330
|
+
selectorTime: number | null;
|
|
331
|
+
transactionKey: string | null;
|
|
332
|
+
install: (store: Store) => void;
|
|
333
|
+
subject: Subject<TimelineUpdate<ManagedAtom> | `redo` | `undo`>;
|
|
334
|
+
subscriptions: Map<string, () => void>;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
declare class Store implements Lineage {
|
|
338
|
+
parent: Store | null;
|
|
339
|
+
child: Store | null;
|
|
340
|
+
valueMap: Map<string, any>;
|
|
341
|
+
defaults: Map<string, any>;
|
|
342
|
+
atoms: Map<string, Atom<any>>;
|
|
343
|
+
selectors: Map<string, WritableSelector<any>>;
|
|
344
|
+
readonlySelectors: Map<string, ReadonlySelector<any>>;
|
|
345
|
+
atomsThatAreDefault: Set<string>;
|
|
346
|
+
selectorAtoms: Junction<"selectorKey", string, "atomKey", string, null>;
|
|
347
|
+
selectorGraph: Junction<"upstreamSelectorKey", string, "downstreamSelectorKey", string, {
|
|
348
|
+
source: string;
|
|
349
|
+
}>;
|
|
350
|
+
trackers: Map<string, Tracker<Transceiver<any>>>;
|
|
351
|
+
families: Map<string, MutableAtomFamily<any, any, any> | ReadonlySelectorFamily<any, any> | RegularAtomFamily<any, any> | WritableSelectorFamily<any, any>>;
|
|
352
|
+
joins: Map<string, Join<any, any, any, any, any, any, `T$--content==${any}::${string}++${any}::${string}`>>;
|
|
353
|
+
transactions: Map<string, Transaction<Func>>;
|
|
354
|
+
transactionMeta: TransactionEpoch | TransactionProgress<Func>;
|
|
355
|
+
timelines: Map<string, Timeline<any>>;
|
|
356
|
+
timelineTopics: Junction<"timelineKey", string, "topicKey", string, {
|
|
357
|
+
topicType: `atom_family` | `atom` | `molecule_family` | `molecule`;
|
|
358
|
+
}>;
|
|
359
|
+
disposalTraces: CircularBuffer<{
|
|
360
|
+
key: string;
|
|
361
|
+
trace: string;
|
|
362
|
+
}>;
|
|
363
|
+
molecules: Map<string, Molecule<Canonical>>;
|
|
364
|
+
moleculeJoins: Junction<"moleculeKey", stringified<Canonical>, "joinKey", string, null>;
|
|
365
|
+
moleculeGraph: Junction<"upstreamMoleculeKey", stringified<Canonical> | "root", "downstreamMoleculeKey", stringified<Canonical>, {
|
|
366
|
+
source: stringified<Canonical>;
|
|
367
|
+
}>;
|
|
368
|
+
moleculeData: Junction<"moleculeKey", stringified<Canonical>, "stateFamilyKey", string, null>;
|
|
369
|
+
miscResources: Map<string, Disposable>;
|
|
370
|
+
on: {
|
|
371
|
+
atomCreation: Subject<AtomToken<unknown>>;
|
|
372
|
+
atomDisposal: Subject<AtomToken<unknown>>;
|
|
373
|
+
selectorCreation: Subject<ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>>;
|
|
374
|
+
selectorDisposal: Subject<ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>>;
|
|
375
|
+
timelineCreation: Subject<TimelineToken<unknown>>;
|
|
376
|
+
transactionCreation: Subject<TransactionToken<Func>>;
|
|
377
|
+
transactionApplying: StatefulSubject<TransactionProgress<Func> | null>;
|
|
378
|
+
operationClose: Subject<OperationProgress>;
|
|
379
|
+
moleculeCreation: Subject<MoleculeCreation>;
|
|
380
|
+
moleculeDisposal: Subject<MoleculeDisposal>;
|
|
381
|
+
};
|
|
382
|
+
operation: OperationProgress;
|
|
383
|
+
config: {
|
|
384
|
+
name: string;
|
|
385
|
+
lifespan: `ephemeral` | `immortal`;
|
|
386
|
+
};
|
|
387
|
+
loggers: AtomIOLogger[];
|
|
388
|
+
logger: Logger;
|
|
389
|
+
constructor(config: Store[`config`], store?: Store | null);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
interface Transceiver<S extends Json.Serializable> {
|
|
393
|
+
do: (update: S) => number | `OUT_OF_RANGE` | null;
|
|
394
|
+
undo: (update: S) => void;
|
|
395
|
+
subscribe: (key: string, fn: (update: S) => void) => () => void;
|
|
396
|
+
cacheUpdateNumber: number;
|
|
397
|
+
getUpdateNumber: (update: S) => number;
|
|
398
|
+
}
|
|
399
|
+
type TransceiverMode = `playback` | `record` | `transaction`;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* @internal Give the tracker a transceiver state and a store, and it will
|
|
403
|
+
* subscribe to the transceiver's inner value. When the inner value changes,
|
|
404
|
+
* the tracker will update its own state to reflect the change.
|
|
405
|
+
*/
|
|
406
|
+
declare class Tracker<Mutable extends Transceiver<any>> {
|
|
407
|
+
private Update;
|
|
408
|
+
private initializeState;
|
|
409
|
+
private unsubscribeFromInnerValue;
|
|
410
|
+
private unsubscribeFromState;
|
|
411
|
+
private observeCore;
|
|
412
|
+
private updateCore;
|
|
413
|
+
mutableState: MutableAtomToken<Mutable, Json.Serializable>;
|
|
414
|
+
latestUpdateState: RegularAtomToken<typeof this.Update | null>;
|
|
415
|
+
[Symbol.dispose]: () => void;
|
|
416
|
+
constructor(mutableState: MutableAtomToken<Mutable, Json.Serializable>, store: Store);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
type EnvironmentData = {
|
|
420
|
+
store: Store;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
type AtomIOState = {
|
|
16
424
|
key: string;
|
|
425
|
+
family?: FamilyMetadata;
|
|
426
|
+
install: (store: Store) => void;
|
|
427
|
+
subject: Subject<{
|
|
428
|
+
newValue: any;
|
|
429
|
+
oldValue: any;
|
|
430
|
+
}>;
|
|
431
|
+
};
|
|
432
|
+
type RegularAtom<T> = AtomIOState & {
|
|
433
|
+
type: `atom`;
|
|
17
434
|
default: T | (() => T);
|
|
18
|
-
|
|
435
|
+
cleanup?: () => void;
|
|
19
436
|
};
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
437
|
+
type MutableAtom<T extends Transceiver<any>, J extends Json.Serializable> = AtomIOState & JsonInterface<T, J> & {
|
|
438
|
+
type: `mutable_atom`;
|
|
439
|
+
default: T | (() => T);
|
|
440
|
+
cleanup?: () => void;
|
|
441
|
+
};
|
|
442
|
+
type Atom<T> = RegularAtom<T> | (T extends Transceiver<any> ? MutableAtom<T, any> : never);
|
|
443
|
+
type WritableSelector<T> = AtomIOState & {
|
|
444
|
+
type: `selector`;
|
|
445
|
+
get: () => T;
|
|
446
|
+
set: (newValue: T | ((oldValue: T) => T)) => void;
|
|
23
447
|
};
|
|
448
|
+
type ReadonlySelector<T> = AtomIOState & {
|
|
449
|
+
type: `readonly_selector`;
|
|
450
|
+
get: () => T;
|
|
451
|
+
};
|
|
452
|
+
type RegularAtomFamily<T, K extends Canonical> = RegularAtomFamilyToken<T, K> & {
|
|
453
|
+
(key: K): RegularAtomToken<T>;
|
|
454
|
+
subject: Subject<StateCreation<AtomToken<T>> | StateDisposal<AtomToken<T>>>;
|
|
455
|
+
install: (store: Store) => void;
|
|
456
|
+
internalRoles: string[] | undefined;
|
|
457
|
+
};
|
|
458
|
+
type MutableAtomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical> = JsonInterface<T, J> & MutableAtomFamilyToken<T, J, K> & {
|
|
459
|
+
(key: K): MutableAtomToken<T, J>;
|
|
460
|
+
subject: Subject<StateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>>;
|
|
461
|
+
install: (store: Store) => void;
|
|
462
|
+
internalRoles: string[] | undefined;
|
|
463
|
+
};
|
|
464
|
+
type WritableSelectorFamily<T, K extends Canonical> = WritableSelectorFamilyToken<T, K> & ((key: K) => WritableSelectorToken<T>) & {
|
|
465
|
+
default: (key: K) => T;
|
|
466
|
+
subject: Subject<StateCreation<WritableSelectorToken<T>> | StateDisposal<WritableSelectorToken<T>>>;
|
|
467
|
+
install: (store: Store) => void;
|
|
468
|
+
internalRoles: string[] | undefined;
|
|
469
|
+
};
|
|
470
|
+
type ReadonlySelectorFamily<T, K extends Canonical> = ReadonlySelectorFamilyToken<T, K> & ((key: K) => ReadonlySelectorToken<T>) & {
|
|
471
|
+
default: (key: K) => T;
|
|
472
|
+
subject: Subject<StateCreation<ReadonlySelectorToken<T>> | StateDisposal<ReadonlySelectorToken<T>>>;
|
|
473
|
+
install: (store: Store) => void;
|
|
474
|
+
internalRoles: string[] | undefined;
|
|
475
|
+
};
|
|
476
|
+
|
|
24
477
|
/**
|
|
25
478
|
* @public
|
|
26
|
-
*
|
|
27
|
-
*
|
|
479
|
+
* Create a mutable atom, a global reactive variable in the implicit store
|
|
480
|
+
*
|
|
481
|
+
* The value of a mutable atom must be some kind of {@link Transceiver}.
|
|
482
|
+
*
|
|
483
|
+
* @param options - {@link MutableAtomOptions}.
|
|
28
484
|
* @returns
|
|
29
|
-
*
|
|
485
|
+
* A reference to the atom created: a {@link MutableAtomToken}
|
|
30
486
|
* @overload Mutable
|
|
31
487
|
*/
|
|
32
488
|
declare function atom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>;
|
|
33
489
|
/**
|
|
34
490
|
* @public
|
|
35
|
-
*
|
|
36
|
-
* @param options -
|
|
491
|
+
* Create a regular atom, a global reactive variable in the implicit store
|
|
492
|
+
* @param options - {@link RegularAtomOptions}.
|
|
37
493
|
* @returns
|
|
38
|
-
*
|
|
494
|
+
* A reference to the atom created: a {@link RegularAtomToken}
|
|
39
495
|
* @overload Regular
|
|
40
496
|
*/
|
|
41
497
|
declare function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>;
|
|
498
|
+
/** @public */
|
|
499
|
+
type Effectors<T> = {
|
|
500
|
+
/**
|
|
501
|
+
* Set the value of the atom
|
|
502
|
+
* @param next - The new value of the atom, or a setter function
|
|
503
|
+
*/
|
|
504
|
+
setSelf: <New extends T>(next: New | Setter<T, New>) => void;
|
|
505
|
+
/** Subscribe to changes to the atom */
|
|
506
|
+
onSet: (callback: (options: {
|
|
507
|
+
newValue: T;
|
|
508
|
+
oldValue: T;
|
|
509
|
+
}) => void) => void;
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* @public
|
|
513
|
+
* A function that runs side effects when the atom is set
|
|
514
|
+
* @param tools - {@link Effectors} that can be used to run side effects
|
|
515
|
+
* @returns
|
|
516
|
+
* Optionally, a cleanup function that will be called when the atom is disposed
|
|
517
|
+
*/
|
|
518
|
+
type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void;
|
|
519
|
+
/** @public */
|
|
520
|
+
type RegularAtomOptions<T> = {
|
|
521
|
+
/** The unique identifier of the atom */
|
|
522
|
+
key: string;
|
|
523
|
+
/** The starting value of the atom */
|
|
524
|
+
default: T | (() => T);
|
|
525
|
+
/** Hooks used to run side effects when the atom is set */
|
|
526
|
+
effects?: AtomEffect<T>[];
|
|
527
|
+
};
|
|
528
|
+
type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = JsonInterface<T, J> & Omit<RegularAtomOptions<T>, `default`> & {
|
|
529
|
+
default: () => T;
|
|
530
|
+
mutable: true;
|
|
531
|
+
};
|
|
532
|
+
/** @public */
|
|
42
533
|
type RegularAtomFamilyOptions<T, K extends Canonical> = {
|
|
534
|
+
/** The unique identifier of the atom family */
|
|
43
535
|
key: string;
|
|
536
|
+
/** The starting value of the atom family */
|
|
44
537
|
default: T | ((key: K) => T);
|
|
538
|
+
/** Hooks used to run side effects when an atom in the family is set */
|
|
45
539
|
effects?: (key: K) => AtomEffect<T>[];
|
|
46
540
|
};
|
|
47
541
|
type RegularAtomFamilyToken<T, K extends Canonical> = {
|
|
@@ -115,19 +609,17 @@ type TransactionUpdate<F extends Func> = {
|
|
|
115
609
|
params: Parameters<F>;
|
|
116
610
|
output: ReturnType<F>;
|
|
117
611
|
};
|
|
118
|
-
type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json
|
|
612
|
+
type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json`>;
|
|
119
613
|
type SetterToolkit = Readonly<{
|
|
120
|
-
get: typeof getState
|
|
121
|
-
set: typeof setState
|
|
614
|
+
get: typeof getState;
|
|
615
|
+
set: typeof setState;
|
|
122
616
|
find: typeof findState;
|
|
123
|
-
seek: typeof seekState;
|
|
124
617
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritableSelectorToken<J>;
|
|
125
618
|
}>;
|
|
126
619
|
type ActorToolkit = Readonly<{
|
|
127
|
-
get: typeof getState
|
|
128
|
-
set: typeof setState
|
|
620
|
+
get: typeof getState;
|
|
621
|
+
set: typeof setState;
|
|
129
622
|
find: typeof findState;
|
|
130
|
-
seek: typeof seekState;
|
|
131
623
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritableSelectorToken<J>;
|
|
132
624
|
dispose: typeof disposeState;
|
|
133
625
|
run: typeof runTransaction;
|
|
@@ -153,7 +645,26 @@ type ReadonlySelectorOptions<T> = {
|
|
|
153
645
|
key: string;
|
|
154
646
|
get: Read<() => T>;
|
|
155
647
|
};
|
|
648
|
+
/**
|
|
649
|
+
* @public
|
|
650
|
+
* Declare a selector. The value of a selector should depend
|
|
651
|
+
* on the value of atoms or other selectors in the store.
|
|
652
|
+
*
|
|
653
|
+
* A writable selector can be "set" to a new value.
|
|
654
|
+
* It is advised to set its dependencies to values
|
|
655
|
+
* that would produce the new value of the selector.
|
|
656
|
+
* @param options - {@link WritableSelectorOptions}.
|
|
657
|
+
* @returns
|
|
658
|
+
* The token for your selector.
|
|
659
|
+
* @overload Writable
|
|
660
|
+
*/
|
|
156
661
|
declare function selector<T>(options: WritableSelectorOptions<T>): WritableSelectorToken<T>;
|
|
662
|
+
/**
|
|
663
|
+
* @public
|
|
664
|
+
* Declare a selector. The value of a selector should depend
|
|
665
|
+
* on the value of atoms or other selectors in the store.
|
|
666
|
+
* @param options - {@link ReadonlySelectorOptions}.
|
|
667
|
+
*/
|
|
157
668
|
declare function selector<T>(options: ReadonlySelectorOptions<T>): ReadonlySelectorToken<T>;
|
|
158
669
|
type WritableSelectorFamilyOptions<T, K extends Canonical> = {
|
|
159
670
|
key: string;
|
|
@@ -180,75 +691,184 @@ type SelectorFamilyToken<T, K extends Canonical> = ReadonlySelectorFamilyToken<T
|
|
|
180
691
|
declare function selectorFamily<T, K extends Canonical>(options: WritableSelectorFamilyOptions<T, K>): WritableSelectorFamilyToken<T, K>;
|
|
181
692
|
declare function selectorFamily<T, K extends Canonical>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamilyToken<T, K>;
|
|
182
693
|
|
|
183
|
-
|
|
184
|
-
type
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
declare function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(store: Store, claim: Claim<V>): void;
|
|
190
|
-
declare function claimWithinStore<H extends Hierarchy, V extends Exclude<Vassal<H>, CompoundTypedKey>, A extends Above<V, H>>(store: Store, newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V>;
|
|
191
|
-
declare class Realm<H extends Hierarchy> {
|
|
192
|
-
store: Store;
|
|
193
|
-
constructor(store?: Store);
|
|
194
|
-
allocate<V extends Vassal<H>, A extends Above<V, H>>(provenance: A, key: V, attachmentStyle?: `all` | `any`): Claim<V>;
|
|
195
|
-
fuse<C extends CompoundFrom<H>, T extends C extends CompoundTypedKey<infer t, any, any> ? t : never, A extends C extends CompoundTypedKey<any, infer v, any> ? v : never, B extends C extends CompoundTypedKey<any, any, infer m> ? m : never>(type: T, reagentA: SingularTypedKey<A>, reagentB: SingularTypedKey<B>): Claim<CompoundTypedKey<T, A, B>>;
|
|
196
|
-
deallocate<V extends Vassal<H>>(claim: Claim<V>): void;
|
|
197
|
-
claim<V extends Exclude<Vassal<H>, CompoundTypedKey>, A extends Above<V, H>>(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V>;
|
|
198
|
-
}
|
|
199
|
-
declare const T$ = "T$";
|
|
200
|
-
type T$ = typeof T$;
|
|
201
|
-
type TypeTag<T extends string> = `${T$}--${T}`;
|
|
202
|
-
type SingularTypedKey<T extends string = string> = `${T}::${string}`;
|
|
203
|
-
type CompoundTypedKey<A extends string = string, B extends string = string, C extends string = string> = `${TypeTag<A>}==${SingularTypedKey<B>}++${SingularTypedKey<C>}`;
|
|
204
|
-
type TypedKey<A extends string = string, B extends string = string, C extends string = string> = CompoundTypedKey<A, B, C> | SingularTypedKey<A>;
|
|
205
|
-
type Scope = SingularTypedKey[];
|
|
206
|
-
type MutualFealty = {
|
|
207
|
-
above: Scope;
|
|
208
|
-
below: CompoundTypedKey;
|
|
694
|
+
type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>;
|
|
695
|
+
type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<any, any> ? AtomToken<any> : M extends AtomToken<any> ? M : never;
|
|
696
|
+
type TimelineToken<M> = {
|
|
697
|
+
key: string;
|
|
698
|
+
type: `timeline`;
|
|
699
|
+
__M?: M;
|
|
209
700
|
};
|
|
210
|
-
type
|
|
211
|
-
|
|
212
|
-
|
|
701
|
+
type TimelineOptions<ManagedAtom extends TimelineManageable> = {
|
|
702
|
+
key: string;
|
|
703
|
+
scope: ManagedAtom[];
|
|
704
|
+
shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<TimelineManageable>) => boolean;
|
|
213
705
|
};
|
|
214
|
-
type
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
below: Array<infer V>;
|
|
219
|
-
} ? V extends TypedKey ? V : never : never;
|
|
220
|
-
}[keyof H];
|
|
221
|
-
type Above<TK extends TypedKey, H extends Hierarchy> = {
|
|
222
|
-
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`below`] ? H[K][`above`] : never : H[K] extends {
|
|
223
|
-
below: Array<infer V>;
|
|
224
|
-
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`above`] : never : never : never;
|
|
225
|
-
}[keyof H];
|
|
226
|
-
type Below<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
|
|
227
|
-
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`] ? H[K][`below`] : TK extends H[K][`above`][number] ? H[K][`below`] : never : H[K] extends {
|
|
228
|
-
above: infer V;
|
|
229
|
-
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`below`][number] : never : never : never;
|
|
230
|
-
}[keyof H];
|
|
231
|
-
type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
|
|
232
|
-
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`][number] ? [mutual: Exclude<H[K][`above`][number], TK>, below: H[K][`below`]] : never : never;
|
|
233
|
-
}[keyof H];
|
|
234
|
-
type CompoundFrom<H extends Hierarchy> = {
|
|
235
|
-
[K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : never;
|
|
236
|
-
}[keyof H];
|
|
237
|
-
declare class Anarchy {
|
|
238
|
-
store: Store;
|
|
239
|
-
realm: Realm<any>;
|
|
240
|
-
constructor(store?: Store);
|
|
241
|
-
allocate(provenance: Canonical, key: Canonical, attachmentStyle?: `all` | `any`): void;
|
|
242
|
-
deallocate(key: Canonical): void;
|
|
243
|
-
claim(newProvenance: Canonical, key: Canonical, exclusive?: `exclusive`): void;
|
|
244
|
-
}
|
|
706
|
+
type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineMoleculeCreation | TimelineMoleculeDisposal | TimelineSelectorUpdate<ManagedAtom> | TimelineStateCreation<AtomOnly<ManagedAtom>> | TimelineStateDisposal<AtomOnly<ManagedAtom>> | TimelineTransactionUpdate;
|
|
707
|
+
declare const timeline: <ManagedAtom extends TimelineManageable>(options: TimelineOptions<ManagedAtom>) => TimelineToken<ManagedAtom>;
|
|
708
|
+
declare const redo: (tl: TimelineToken<any>) => void;
|
|
709
|
+
declare const undo: (tl: TimelineToken<any>) => void;
|
|
245
710
|
|
|
711
|
+
/**
|
|
712
|
+
* @public
|
|
713
|
+
* Disposes of a state in the implicit store
|
|
714
|
+
* @param token - The token of the state to dispose
|
|
715
|
+
* @overload Default
|
|
716
|
+
*/
|
|
246
717
|
declare function disposeState(token: ReadableToken<any>): void;
|
|
718
|
+
/**
|
|
719
|
+
* @public
|
|
720
|
+
* Disposes of a state family in the implicit store
|
|
721
|
+
* @param token - The token of the state family to dispose
|
|
722
|
+
* @param key - The unique key of the state to dispose
|
|
723
|
+
*/
|
|
247
724
|
declare function disposeState<K extends Canonical>(token: ReadableFamilyToken<any, K>, key: K): void;
|
|
248
725
|
|
|
726
|
+
/**
|
|
727
|
+
* @public
|
|
728
|
+
* Finds a {@link MutableAtomToken} in the store
|
|
729
|
+
* @param token - A {@link MutableAtomFamilyToken}
|
|
730
|
+
* @param key - The key of the state
|
|
731
|
+
* @returns
|
|
732
|
+
* The current value of the state
|
|
733
|
+
* @overload Mutable Atom
|
|
734
|
+
*/
|
|
735
|
+
declare function findState<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical, Key extends K>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J, K>;
|
|
736
|
+
/**
|
|
737
|
+
* @public
|
|
738
|
+
* Finds a state in the store
|
|
739
|
+
* @param token - The token of the state family
|
|
740
|
+
* @param key - The key of the state
|
|
741
|
+
* @returns
|
|
742
|
+
* The current value of the state
|
|
743
|
+
* @overload Regular Atom
|
|
744
|
+
*/
|
|
745
|
+
declare function findState<T, K extends Canonical, Key extends K>(token: RegularAtomFamilyToken<T, K>, key: Key): RegularAtomToken<T, K>;
|
|
746
|
+
/**
|
|
747
|
+
* @public
|
|
748
|
+
* Finds a state in the store
|
|
749
|
+
* @param token - The token of the state family
|
|
750
|
+
* @param key - The key of the state
|
|
751
|
+
* @returns
|
|
752
|
+
* The current value of the state
|
|
753
|
+
* @overload Writable Selector
|
|
754
|
+
*/
|
|
755
|
+
declare function findState<T, K extends Canonical, Key extends K>(token: WritableSelectorFamilyToken<T, K>, key: Key): WritableSelectorToken<T, K>;
|
|
756
|
+
/**
|
|
757
|
+
* @public
|
|
758
|
+
* Finds a state in the store
|
|
759
|
+
* @param token - The token of the state family
|
|
760
|
+
* @param key - The key of the state
|
|
761
|
+
* @returns
|
|
762
|
+
* The current value of the state
|
|
763
|
+
* @overload Readonly Selector
|
|
764
|
+
*/
|
|
765
|
+
declare function findState<T, K extends Canonical, Key extends K>(token: ReadonlySelectorFamilyToken<T, K>, key: Key): ReadonlySelectorToken<T, K>;
|
|
766
|
+
/**
|
|
767
|
+
* @public
|
|
768
|
+
* Finds a state in the store
|
|
769
|
+
* @param token - The token of the state family
|
|
770
|
+
* @param key - The key of the state
|
|
771
|
+
* @returns
|
|
772
|
+
* The current value of the state
|
|
773
|
+
* @overload Writable State
|
|
774
|
+
*/
|
|
775
|
+
declare function findState<T, K extends Canonical, Key extends K>(token: WritableFamilyToken<T, K>, key: Key): WritableToken<T, K>;
|
|
776
|
+
/**
|
|
777
|
+
* @public
|
|
778
|
+
* Finds a {@link ReadableToken} in the store
|
|
779
|
+
* @param token - A {@link ReadableFamilyToken}
|
|
780
|
+
* @param key - The key of the state
|
|
781
|
+
* @returns
|
|
782
|
+
* The current value of the state
|
|
783
|
+
* @overload Unknown
|
|
784
|
+
* @default
|
|
785
|
+
*/
|
|
786
|
+
declare function findState<T, K extends Canonical, Key extends K>(token: ReadableFamilyToken<T, K>, key: Key): ReadableToken<T, K>;
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* @public
|
|
790
|
+
* Get the current value of a state
|
|
791
|
+
* @param token - The token of the state to get
|
|
792
|
+
* @return The current value of the state
|
|
793
|
+
* @overload Default
|
|
794
|
+
* @default
|
|
795
|
+
*/
|
|
249
796
|
declare function getState<T>(token: ReadableToken<T>): T;
|
|
797
|
+
/**
|
|
798
|
+
* @public
|
|
799
|
+
* Get the current value of a state family
|
|
800
|
+
* @param token - The token of a state family
|
|
801
|
+
* @param key - The unique key of the state to get
|
|
802
|
+
* @return The current value of the state
|
|
803
|
+
* @overload Streamlined
|
|
804
|
+
*/
|
|
250
805
|
declare function getState<T, K extends Canonical, Key extends K>(token: ReadableFamilyToken<T, K>, key: Key): T;
|
|
251
806
|
|
|
807
|
+
interface JoinOptions<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> extends JunctionSchemaBase<ASide, BSide>, Partial<JunctionEntriesBase<AType, BType, Content>> {
|
|
808
|
+
readonly key: string;
|
|
809
|
+
readonly cardinality: Cardinality;
|
|
810
|
+
readonly isAType: Refinement<string, AType>;
|
|
811
|
+
readonly isBType: Refinement<string, BType>;
|
|
812
|
+
}
|
|
813
|
+
type JoinToken<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null = null> = {
|
|
814
|
+
key: string;
|
|
815
|
+
type: `join`;
|
|
816
|
+
cardinality: Cardinality;
|
|
817
|
+
a: ASide;
|
|
818
|
+
b: BSide;
|
|
819
|
+
__aType?: AType;
|
|
820
|
+
__bType?: BType;
|
|
821
|
+
__content?: Content;
|
|
822
|
+
};
|
|
823
|
+
declare function join<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Cardinality extends `1:1` | `1:n` | `n:n`>(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, null>, defaultContent?: undefined, store?: Store): JoinToken<ASide, AType, BSide, BType, Cardinality, null>;
|
|
824
|
+
declare function join<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object>(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>, defaultContent: Content, store?: Store): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>;
|
|
825
|
+
type JoinStates<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? {
|
|
826
|
+
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<[
|
|
827
|
+
AType,
|
|
828
|
+
Content
|
|
829
|
+
] | null, BType>;
|
|
830
|
+
} & {
|
|
831
|
+
readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorToken<[
|
|
832
|
+
BType,
|
|
833
|
+
Content
|
|
834
|
+
] | null, AType>;
|
|
835
|
+
} : {}) & {
|
|
836
|
+
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<AType | null, BType>;
|
|
837
|
+
} & {
|
|
838
|
+
readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorToken<BType | null, AType>;
|
|
839
|
+
} : Cardinality extends `1:n` ? (Content extends Json.Object ? {
|
|
840
|
+
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<[
|
|
841
|
+
AType,
|
|
842
|
+
Content
|
|
843
|
+
] | null, BType>;
|
|
844
|
+
} & {
|
|
845
|
+
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<[
|
|
846
|
+
BType,
|
|
847
|
+
Content
|
|
848
|
+
][], AType>;
|
|
849
|
+
} : {}) & {
|
|
850
|
+
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<AType | null, BType>;
|
|
851
|
+
} & {
|
|
852
|
+
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<BType[], AType>;
|
|
853
|
+
} : Cardinality extends `n:n` ? (Content extends Json.Object ? {
|
|
854
|
+
readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlySelectorToken<[
|
|
855
|
+
AType,
|
|
856
|
+
Content
|
|
857
|
+
][], BType>;
|
|
858
|
+
} & {
|
|
859
|
+
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<[
|
|
860
|
+
BType,
|
|
861
|
+
Content
|
|
862
|
+
][], AType>;
|
|
863
|
+
} : {}) & {
|
|
864
|
+
readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlySelectorToken<AType[], BType>;
|
|
865
|
+
} & {
|
|
866
|
+
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<BType[], AType>;
|
|
867
|
+
} : never;
|
|
868
|
+
declare function findRelations<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>, key: AType | BType): JoinStates<ASide, AType, BSide, BType, Cardinality, Content>;
|
|
869
|
+
declare function editRelations<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>, change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void): void;
|
|
870
|
+
declare function getInternalRelations<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string>;
|
|
871
|
+
|
|
252
872
|
declare const LoggerIconDictionary: {
|
|
253
873
|
readonly "\u231B": "Timeline event fully captured";
|
|
254
874
|
readonly "\u23E9": "Timeline redo";
|
|
@@ -319,26 +939,91 @@ declare class AtomIOLogger implements Logger {
|
|
|
319
939
|
warn: LogFn;
|
|
320
940
|
}
|
|
321
941
|
|
|
322
|
-
declare
|
|
942
|
+
declare const $claim: unique symbol;
|
|
943
|
+
type Claim<K extends Canonical> = K & {
|
|
944
|
+
[$claim]?: true;
|
|
945
|
+
};
|
|
946
|
+
declare class Realm<H extends Hierarchy> {
|
|
947
|
+
store: Store;
|
|
948
|
+
constructor(store?: Store);
|
|
949
|
+
allocate<V extends Vassal<H>, A extends Above<V, H>>(provenance: A, key: V, attachmentStyle?: `all` | `any`): Claim<V>;
|
|
950
|
+
fuse<C extends CompoundFrom<H>, T extends C extends CompoundTypedKey<infer t, any, any> ? t : never, A extends C extends CompoundTypedKey<any, infer v, any> ? v : never, B extends C extends CompoundTypedKey<any, any, infer m> ? m : never>(type: T, reagentA: SingularTypedKey<A>, reagentB: SingularTypedKey<B>): Claim<CompoundTypedKey<T, A, B>>;
|
|
951
|
+
deallocate<V extends Vassal<H>>(claim: Claim<V>): void;
|
|
952
|
+
claim<V extends Exclude<Vassal<H>, CompoundTypedKey>, A extends Above<V, H>>(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V>;
|
|
953
|
+
}
|
|
954
|
+
declare class Anarchy {
|
|
955
|
+
store: Store;
|
|
956
|
+
realm: Realm<any>;
|
|
957
|
+
constructor(store?: Store);
|
|
958
|
+
allocate(provenance: Canonical, key: Canonical, attachmentStyle?: `all` | `any`): void;
|
|
959
|
+
deallocate(key: Canonical): void;
|
|
960
|
+
claim(newProvenance: Canonical, key: Canonical, exclusive?: `exclusive`): void;
|
|
961
|
+
}
|
|
962
|
+
declare const T$ = "T$";
|
|
963
|
+
type T$ = typeof T$;
|
|
964
|
+
type TypeTag<T extends string> = `${T$}--${T}`;
|
|
965
|
+
type SingularTypedKey<T extends string = string> = `${T}::${string}`;
|
|
966
|
+
type CompoundTypedKey<A extends string = string, B extends string = string, C extends string = string> = `${TypeTag<A>}==${SingularTypedKey<B>}++${SingularTypedKey<C>}`;
|
|
967
|
+
type TypedKey<A extends string = string, B extends string = string, C extends string = string> = CompoundTypedKey<A, B, C> | SingularTypedKey<A>;
|
|
968
|
+
type Scope = SingularTypedKey[];
|
|
969
|
+
type MutualFealty = {
|
|
970
|
+
above: Scope;
|
|
971
|
+
below: CompoundTypedKey;
|
|
972
|
+
};
|
|
973
|
+
type ExclusiveFealty = {
|
|
974
|
+
above: TypedKey | `root`;
|
|
975
|
+
below: Scope;
|
|
976
|
+
};
|
|
977
|
+
type Fealty = ExclusiveFealty | MutualFealty;
|
|
978
|
+
type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>;
|
|
979
|
+
type Vassal<H extends Hierarchy> = {
|
|
980
|
+
[K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : H[K] extends {
|
|
981
|
+
below: Array<infer V>;
|
|
982
|
+
} ? V extends TypedKey ? V : never : never;
|
|
983
|
+
}[keyof H];
|
|
984
|
+
type Above<TK extends TypedKey, H extends Hierarchy> = {
|
|
985
|
+
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`below`] ? H[K][`above`] : never : H[K] extends {
|
|
986
|
+
below: Array<infer V>;
|
|
987
|
+
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`above`] : never : never : never;
|
|
988
|
+
}[keyof H];
|
|
989
|
+
type Below<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
|
|
990
|
+
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`] ? H[K][`below`] : TK extends H[K][`above`][number] ? H[K][`below`] : never : H[K] extends {
|
|
991
|
+
above: infer V;
|
|
992
|
+
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`below`][number] : never : never : never;
|
|
993
|
+
}[keyof H];
|
|
994
|
+
type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
|
|
995
|
+
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`][number] ? [mutual: Exclude<H[K][`above`][number], TK>, below: H[K][`below`]] : never : never;
|
|
996
|
+
}[keyof H];
|
|
997
|
+
type CompoundFrom<H extends Hierarchy> = {
|
|
998
|
+
[K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : never;
|
|
999
|
+
}[keyof H];
|
|
323
1000
|
|
|
1001
|
+
/**
|
|
1002
|
+
* @public
|
|
1003
|
+
* A function that sets the value of a state.
|
|
1004
|
+
* @param oldValue - The current value of the state.
|
|
1005
|
+
* @returns
|
|
1006
|
+
* The new value of the state.
|
|
1007
|
+
*/
|
|
1008
|
+
type Setter<T, New extends T> = (oldValue: T) => New;
|
|
324
1009
|
/**
|
|
325
1010
|
* @public
|
|
326
1011
|
* Set the value of a state into the implicit store.
|
|
327
|
-
* @param token -
|
|
1012
|
+
* @param token - An atom or writable selector token.
|
|
328
1013
|
* @param value - The new value of the state.
|
|
329
1014
|
* @overload Default
|
|
330
1015
|
* @default
|
|
331
1016
|
*/
|
|
332
|
-
declare function setState<T, New extends T>(token: WritableToken<T>, value: New |
|
|
1017
|
+
declare function setState<T, New extends T>(token: WritableToken<T>, value: New | Setter<T, New>): void;
|
|
333
1018
|
/**
|
|
334
1019
|
* @public
|
|
335
1020
|
* Set the value of a state into the implicit store.
|
|
336
|
-
* @param token -
|
|
337
|
-
* @param key - The key of the state to set.
|
|
1021
|
+
* @param token - An atom family or writable selector family token.
|
|
1022
|
+
* @param key - The unique key of the state to set.
|
|
338
1023
|
* @param value - The new value of the state.
|
|
339
1024
|
* @overload Streamlined
|
|
340
1025
|
*/
|
|
341
|
-
declare function setState<T, K extends Canonical, New extends T, Key extends K>(token: WritableFamilyToken<T, K>, key: Key, value: New |
|
|
1026
|
+
declare function setState<T, K extends Canonical, New extends T, Key extends K>(token: WritableFamilyToken<T, K>, key: Key, value: New | Setter<T, New>): void;
|
|
342
1027
|
|
|
343
1028
|
declare class Silo {
|
|
344
1029
|
store: Store;
|
|
@@ -356,6 +1041,7 @@ declare class Silo {
|
|
|
356
1041
|
undo: typeof undo;
|
|
357
1042
|
redo: typeof redo;
|
|
358
1043
|
runTransaction: typeof runTransaction;
|
|
1044
|
+
install: (tokens: AtomIOToken[], store?: Store) => void;
|
|
359
1045
|
constructor(config: Store[`config`], fromStore?: Store | null);
|
|
360
1046
|
}
|
|
361
1047
|
|
|
@@ -374,71 +1060,113 @@ declare function subscribe<T>(token: ReadableToken<T>, handleUpdate: UpdateHandl
|
|
|
374
1060
|
declare function subscribe<F extends Func>(token: TransactionToken<F>, handleUpdate: TransactionUpdateHandler<F>, key?: string): () => void;
|
|
375
1061
|
declare function subscribe<M extends TimelineManageable>(token: TimelineToken<M>, handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void, key?: string): () => void;
|
|
376
1062
|
|
|
377
|
-
type
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
declare const timeline: <ManagedAtom extends TimelineManageable>(options: TimelineOptions<ManagedAtom>) => TimelineToken<ManagedAtom>;
|
|
391
|
-
declare const redo: (tl: TimelineToken<any>) => void;
|
|
392
|
-
declare const undo: (tl: TimelineToken<any>) => void;
|
|
393
|
-
|
|
394
|
-
type TokenType<Comparison extends ReadableFamilyToken$1<any, any> | ReadableToken$1<any>> = Comparison extends ReadableToken$1<infer RepresentedValue> ? RepresentedValue : Comparison extends ReadableFamilyToken$1<infer RepresentedValue, any> ? RepresentedValue : never;
|
|
395
|
-
declare function isToken<KnownToken extends RegularAtomToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is RegularAtomToken$1<TokenType<KnownToken>>;
|
|
396
|
-
declare function isToken<KnownToken extends MutableAtomToken$1<any, any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is MutableAtomToken$1<TokenType<KnownToken>, any>;
|
|
397
|
-
declare function isToken<KnownToken extends WritableSelectorToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is WritableSelectorToken$1<TokenType<KnownToken>>;
|
|
398
|
-
declare function isToken<KnownToken extends ReadonlySelectorToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is ReadonlySelectorToken$1<TokenType<KnownToken>>;
|
|
399
|
-
declare function isToken<KnownToken extends WritableToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is WritableToken$1<TokenType<KnownToken>>;
|
|
400
|
-
declare function isToken<KnownToken extends ReadableToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is ReadableToken$1<TokenType<KnownToken>>;
|
|
401
|
-
declare function belongsTo<Family extends RegularAtomFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is RegularAtomToken$1<TokenType<Family>>;
|
|
402
|
-
declare function belongsTo<Family extends MutableAtomFamilyToken$1<any, any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is MutableAtomToken$1<TokenType<Family>, any>;
|
|
403
|
-
declare function belongsTo<Family extends WritableSelectorFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is WritableSelectorToken$1<TokenType<Family>>;
|
|
404
|
-
declare function belongsTo<Family extends ReadonlySelectorFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is ReadonlySelectorToken$1<TokenType<Family>>;
|
|
405
|
-
declare function belongsTo<Family extends WritableFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is WritableToken$1<TokenType<Family>>;
|
|
406
|
-
declare function belongsTo<Family extends ReadableFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is ReadableToken$1<TokenType<Family>>;
|
|
1063
|
+
type TokenType<Comparison extends ReadableFamilyToken<any, any> | ReadableToken<any>> = Comparison extends ReadableToken<infer RepresentedValue> ? RepresentedValue : Comparison extends ReadableFamilyToken<infer RepresentedValue, any> ? RepresentedValue : never;
|
|
1064
|
+
declare function isToken<KnownToken extends RegularAtomToken<any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is RegularAtomToken<TokenType<KnownToken>>;
|
|
1065
|
+
declare function isToken<KnownToken extends MutableAtomToken<any, any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is MutableAtomToken<TokenType<KnownToken>, any>;
|
|
1066
|
+
declare function isToken<KnownToken extends WritableSelectorToken<any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is WritableSelectorToken<TokenType<KnownToken>>;
|
|
1067
|
+
declare function isToken<KnownToken extends ReadonlySelectorToken<any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is ReadonlySelectorToken<TokenType<KnownToken>>;
|
|
1068
|
+
declare function isToken<KnownToken extends WritableToken<any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is WritableToken<TokenType<KnownToken>>;
|
|
1069
|
+
declare function isToken<KnownToken extends ReadableToken<any>>(knownToken: KnownToken, unknownToken: ReadableToken<any>): unknownToken is ReadableToken<TokenType<KnownToken>>;
|
|
1070
|
+
declare function belongsTo<Family extends RegularAtomFamilyToken<any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is RegularAtomToken<TokenType<Family>>;
|
|
1071
|
+
declare function belongsTo<Family extends MutableAtomFamilyToken<any, any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is MutableAtomToken<TokenType<Family>, any>;
|
|
1072
|
+
declare function belongsTo<Family extends WritableSelectorFamilyToken<any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is WritableSelectorToken<TokenType<Family>>;
|
|
1073
|
+
declare function belongsTo<Family extends ReadonlySelectorFamilyToken<any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is ReadonlySelectorToken<TokenType<Family>>;
|
|
1074
|
+
declare function belongsTo<Family extends WritableFamilyToken<any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is WritableToken<TokenType<Family>>;
|
|
1075
|
+
declare function belongsTo<Family extends ReadableFamilyToken<any, any>>(family: Family, unknownToken: ReadableToken<any>): unknownToken is ReadableToken<TokenType<Family>>;
|
|
407
1076
|
|
|
1077
|
+
/**
|
|
1078
|
+
* @public
|
|
1079
|
+
* A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
|
|
1080
|
+
*
|
|
1081
|
+
* While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank.
|
|
1082
|
+
*
|
|
1083
|
+
* Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}.
|
|
1084
|
+
*
|
|
1085
|
+
* Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}.
|
|
1086
|
+
*
|
|
1087
|
+
* Tokens are fully serializable, so they can be passed between processes.
|
|
1088
|
+
*/
|
|
1089
|
+
type AtomIOToken = ReadableFamilyToken<any, any> | ReadableToken<any> | TimelineToken<any> | TransactionToken<any>;
|
|
1090
|
+
/** @public */
|
|
408
1091
|
type RegularAtomToken<T, K extends Canonical = any> = {
|
|
1092
|
+
/** The unique identifier of the atom. */
|
|
409
1093
|
key: string;
|
|
1094
|
+
/** Discriminator. */
|
|
410
1095
|
type: `atom`;
|
|
1096
|
+
/** Present if the atom belongs to a family. */
|
|
411
1097
|
family?: FamilyMetadata<K>;
|
|
1098
|
+
/** Never present. This is a marker that preserves the type of the atom's value. */
|
|
412
1099
|
__T?: T;
|
|
413
1100
|
};
|
|
1101
|
+
/** @public */
|
|
414
1102
|
type MutableAtomToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical = any> = {
|
|
1103
|
+
/** The unique identifier of the atom. */
|
|
415
1104
|
key: string;
|
|
1105
|
+
/** Discriminator. */
|
|
416
1106
|
type: `mutable_atom`;
|
|
1107
|
+
/** Present if the atom belongs to a family. */
|
|
417
1108
|
family?: FamilyMetadata<K>;
|
|
1109
|
+
/** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
|
|
418
1110
|
__J?: J;
|
|
1111
|
+
/** Never present. This is a marker that preserves the type of the atom's transceiver value. */
|
|
419
1112
|
__U?: T extends Transceiver<infer Update> ? Update : never;
|
|
420
1113
|
};
|
|
1114
|
+
/** @public */
|
|
421
1115
|
type AtomToken<T, K extends Canonical = any> = MutableAtomToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomToken<T, K>;
|
|
1116
|
+
/** @public */
|
|
422
1117
|
type WritableSelectorToken<T, K extends Canonical = any> = {
|
|
1118
|
+
/** The unique identifier of the selector. */
|
|
423
1119
|
key: string;
|
|
1120
|
+
/** Discriminator. */
|
|
424
1121
|
type: `selector`;
|
|
1122
|
+
/** Present if the selector belongs to a family. */
|
|
425
1123
|
family?: FamilyMetadata<K>;
|
|
1124
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
426
1125
|
__T?: T;
|
|
427
1126
|
};
|
|
1127
|
+
/** @public */
|
|
428
1128
|
type ReadonlySelectorToken<T, K extends Canonical = any> = {
|
|
1129
|
+
/** The unique identifier of the selector. */
|
|
429
1130
|
key: string;
|
|
1131
|
+
/** Discriminator. */
|
|
430
1132
|
type: `readonly_selector`;
|
|
1133
|
+
/** Present if the selector belongs to a family. */
|
|
431
1134
|
family?: FamilyMetadata<K>;
|
|
1135
|
+
/** Never present. This is a marker that preserves the type of the selector's value. */
|
|
432
1136
|
__T?: T;
|
|
433
1137
|
};
|
|
1138
|
+
/** @public */
|
|
434
1139
|
type SelectorToken<T, K extends Canonical = any> = ReadonlySelectorToken<T, K> | WritableSelectorToken<T, K>;
|
|
1140
|
+
/**
|
|
1141
|
+
* @public
|
|
1142
|
+
* These states can be set.
|
|
1143
|
+
*/
|
|
435
1144
|
type WritableToken<T, K extends Canonical = any> = AtomToken<T, K> | WritableSelectorToken<T, K>;
|
|
1145
|
+
/**
|
|
1146
|
+
* @public
|
|
1147
|
+
* These states cannot be set.
|
|
1148
|
+
*/
|
|
436
1149
|
type ReadableToken<T, K extends Canonical = any> = AtomToken<T, K> | SelectorToken<T, K>;
|
|
1150
|
+
/**
|
|
1151
|
+
* @public
|
|
1152
|
+
* States belonging to this family can be set.
|
|
1153
|
+
*/
|
|
437
1154
|
type WritableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
|
|
1155
|
+
/**
|
|
1156
|
+
* @public
|
|
1157
|
+
* States belonging to this family cannot be set.
|
|
1158
|
+
*/
|
|
438
1159
|
type ReadableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | SelectorFamilyToken<T, K>;
|
|
1160
|
+
/**
|
|
1161
|
+
* @public
|
|
1162
|
+
* Identifies a state's connection to its family.
|
|
1163
|
+
*/
|
|
439
1164
|
type FamilyMetadata<K extends Canonical = any> = {
|
|
1165
|
+
/** The family's unique key. */
|
|
440
1166
|
key: string;
|
|
1167
|
+
/** The family member's unique identifier, in the form of a string. */
|
|
441
1168
|
subKey: stringified<K>;
|
|
442
1169
|
};
|
|
1170
|
+
type Loadable<T> = Promise<T> | T;
|
|
443
1171
|
|
|
444
|
-
export { $claim, type Above, type ActorToolkit, Anarchy, type AtomDisposal, type AtomEffect, type AtomFamilyToken, AtomIOLogger, type AtomOnly, type AtomToken, type Below, type Claim, type CompoundFrom, type CompoundTypedKey, type Effectors, type FamilyMetadata, type GetterToolkit, type Hierarchy, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MoleculeCreation, type MoleculeDisposal, type MoleculeTransfer, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomOptions, type MutableAtomToken, type Mutuals, type Read, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorOptions, type ReadonlySelectorToken, Realm, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomOptions, type RegularAtomToken, type SelectorDisposal, type SelectorFamilyToken, type SelectorToken, type SetterToolkit, Silo, type SingularTypedKey, type StateCreation, type StateDisposal, type StateUpdate, T$, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type TypeTag, type TypedKey, type UpdateHandler, type Vassal, type WritableFamilyToken, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write,
|
|
1172
|
+
export { $claim, type Above, type ActorToolkit, Anarchy, type AtomDisposal, type AtomEffect, type AtomFamilyToken, AtomIOLogger, type AtomIOToken, type AtomOnly, type AtomToken, type Below, type Claim, type CompoundFrom, type CompoundTypedKey, type Effectors, type FamilyMetadata, type GetterToolkit, type Hierarchy, type JoinOptions, type JoinStates, type JoinToken, type KeyedStateUpdate, LOG_LEVELS, type Loadable, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MoleculeCreation, type MoleculeDisposal, type MoleculeTransfer, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomOptions, type MutableAtomToken, type Mutuals, type Read, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorOptions, type ReadonlySelectorToken, Realm, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomOptions, type RegularAtomToken, type SelectorDisposal, type SelectorFamilyToken, type SelectorToken, type Setter, type SetterToolkit, Silo, type SingularTypedKey, type StateCreation, type StateDisposal, type StateUpdate, T$, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type TypeTag, type TypedKey, type UpdateHandler, type Vassal, type WritableFamilyToken, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, disposeState, editRelations, findRelations, findState, getInternalRelations, getState, isToken, join, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|