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/src/join.ts
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import type { MutableAtomFamilyToken, ReadonlySelectorToken } from "atom.io"
|
|
2
|
+
import type {
|
|
3
|
+
Junction,
|
|
4
|
+
JunctionEntriesBase,
|
|
5
|
+
JunctionSchemaBase,
|
|
6
|
+
Refinement,
|
|
7
|
+
Store,
|
|
8
|
+
} from "atom.io/internal"
|
|
9
|
+
import {
|
|
10
|
+
editRelationsInStore,
|
|
11
|
+
findRelationsInStore,
|
|
12
|
+
getInternalRelationsFromStore,
|
|
13
|
+
IMPLICIT,
|
|
14
|
+
Join,
|
|
15
|
+
} from "atom.io/internal"
|
|
16
|
+
import type { Json } from "atom.io/json"
|
|
17
|
+
import type { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
18
|
+
|
|
19
|
+
export interface JoinOptions<
|
|
20
|
+
ASide extends string,
|
|
21
|
+
AType extends string,
|
|
22
|
+
BSide extends string,
|
|
23
|
+
BType extends string,
|
|
24
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
25
|
+
Content extends Json.Object | null,
|
|
26
|
+
> extends JunctionSchemaBase<ASide, BSide>,
|
|
27
|
+
Partial<JunctionEntriesBase<AType, BType, Content>> {
|
|
28
|
+
readonly key: string
|
|
29
|
+
readonly cardinality: Cardinality
|
|
30
|
+
readonly isAType: Refinement<string, AType>
|
|
31
|
+
readonly isBType: Refinement<string, BType>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type JoinToken<
|
|
35
|
+
ASide extends string,
|
|
36
|
+
AType extends string,
|
|
37
|
+
BSide extends string,
|
|
38
|
+
BType extends string,
|
|
39
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
40
|
+
Content extends Json.Object | null = null,
|
|
41
|
+
> = {
|
|
42
|
+
key: string
|
|
43
|
+
type: `join`
|
|
44
|
+
cardinality: Cardinality
|
|
45
|
+
a: ASide
|
|
46
|
+
b: BSide
|
|
47
|
+
__aType?: AType
|
|
48
|
+
__bType?: BType
|
|
49
|
+
__content?: Content
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function join<
|
|
53
|
+
const ASide extends string,
|
|
54
|
+
const AType extends string,
|
|
55
|
+
const BSide extends string,
|
|
56
|
+
const BType extends string,
|
|
57
|
+
const Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
58
|
+
>(
|
|
59
|
+
options: JoinOptions<ASide, AType, BSide, BType, Cardinality, null>,
|
|
60
|
+
defaultContent?: undefined,
|
|
61
|
+
store?: Store,
|
|
62
|
+
): JoinToken<ASide, AType, BSide, BType, Cardinality, null>
|
|
63
|
+
export function join<
|
|
64
|
+
const ASide extends string,
|
|
65
|
+
const AType extends string,
|
|
66
|
+
const BSide extends string,
|
|
67
|
+
const BType extends string,
|
|
68
|
+
const Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
69
|
+
const Content extends Json.Object,
|
|
70
|
+
>(
|
|
71
|
+
options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
72
|
+
defaultContent: Content,
|
|
73
|
+
store?: Store,
|
|
74
|
+
): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>
|
|
75
|
+
export function join<
|
|
76
|
+
ASide extends string,
|
|
77
|
+
AType extends string,
|
|
78
|
+
BSide extends string,
|
|
79
|
+
BType extends string,
|
|
80
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
81
|
+
Content extends Json.Object,
|
|
82
|
+
>(
|
|
83
|
+
options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
84
|
+
defaultContent: Content | undefined,
|
|
85
|
+
store: Store = IMPLICIT.STORE,
|
|
86
|
+
): JoinToken<ASide, AType, BSide, BType, Cardinality, Content> {
|
|
87
|
+
store.joins.set(options.key, new Join(options, defaultContent, store))
|
|
88
|
+
const token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content> = {
|
|
89
|
+
key: options.key,
|
|
90
|
+
type: `join`,
|
|
91
|
+
a: options.between[0],
|
|
92
|
+
b: options.between[1],
|
|
93
|
+
cardinality: options.cardinality,
|
|
94
|
+
}
|
|
95
|
+
return token
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type JoinStates<
|
|
99
|
+
ASide extends string,
|
|
100
|
+
AType extends string,
|
|
101
|
+
BSide extends string,
|
|
102
|
+
BType extends string,
|
|
103
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
104
|
+
Content extends Json.Object | null,
|
|
105
|
+
> = Cardinality extends `1:1`
|
|
106
|
+
? (Content extends Json.Object
|
|
107
|
+
? {
|
|
108
|
+
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
109
|
+
[AType, Content] | null,
|
|
110
|
+
BType
|
|
111
|
+
>
|
|
112
|
+
} & {
|
|
113
|
+
readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
114
|
+
[BType, Content] | null,
|
|
115
|
+
AType
|
|
116
|
+
>
|
|
117
|
+
}
|
|
118
|
+
: {}) & {
|
|
119
|
+
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
120
|
+
AType | null,
|
|
121
|
+
BType
|
|
122
|
+
>
|
|
123
|
+
} & {
|
|
124
|
+
readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
125
|
+
BType | null,
|
|
126
|
+
AType
|
|
127
|
+
>
|
|
128
|
+
}
|
|
129
|
+
: Cardinality extends `1:n`
|
|
130
|
+
? (Content extends Json.Object
|
|
131
|
+
? {
|
|
132
|
+
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
133
|
+
[AType, Content] | null,
|
|
134
|
+
BType
|
|
135
|
+
>
|
|
136
|
+
} & {
|
|
137
|
+
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
138
|
+
[BType, Content][],
|
|
139
|
+
AType
|
|
140
|
+
>
|
|
141
|
+
}
|
|
142
|
+
: {}) & {
|
|
143
|
+
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
144
|
+
AType | null,
|
|
145
|
+
BType
|
|
146
|
+
>
|
|
147
|
+
} & {
|
|
148
|
+
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
149
|
+
BType[],
|
|
150
|
+
AType
|
|
151
|
+
>
|
|
152
|
+
}
|
|
153
|
+
: Cardinality extends `n:n`
|
|
154
|
+
? (Content extends Json.Object
|
|
155
|
+
? {
|
|
156
|
+
readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
157
|
+
[AType, Content][],
|
|
158
|
+
BType
|
|
159
|
+
>
|
|
160
|
+
} & {
|
|
161
|
+
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
162
|
+
[BType, Content][],
|
|
163
|
+
AType
|
|
164
|
+
>
|
|
165
|
+
}
|
|
166
|
+
: {}) & {
|
|
167
|
+
readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
168
|
+
AType[],
|
|
169
|
+
BType
|
|
170
|
+
>
|
|
171
|
+
} & {
|
|
172
|
+
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
173
|
+
BType[],
|
|
174
|
+
AType
|
|
175
|
+
>
|
|
176
|
+
}
|
|
177
|
+
: never
|
|
178
|
+
|
|
179
|
+
export function findRelations<
|
|
180
|
+
ASide extends string,
|
|
181
|
+
AType extends string,
|
|
182
|
+
BSide extends string,
|
|
183
|
+
BType extends string,
|
|
184
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
185
|
+
Content extends Json.Object | null,
|
|
186
|
+
>(
|
|
187
|
+
token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
188
|
+
key: AType | BType,
|
|
189
|
+
): JoinStates<ASide, AType, BSide, BType, Cardinality, Content> {
|
|
190
|
+
return findRelationsInStore(token, key, IMPLICIT.STORE)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function editRelations<
|
|
194
|
+
ASide extends string,
|
|
195
|
+
AType extends string,
|
|
196
|
+
BSide extends string,
|
|
197
|
+
BType extends string,
|
|
198
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
199
|
+
Content extends Json.Object | null,
|
|
200
|
+
>(
|
|
201
|
+
token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
202
|
+
change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void,
|
|
203
|
+
): void {
|
|
204
|
+
editRelationsInStore(token, change, IMPLICIT.STORE)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function getInternalRelations<
|
|
208
|
+
ASide extends string,
|
|
209
|
+
AType extends string,
|
|
210
|
+
BSide extends string,
|
|
211
|
+
BType extends string,
|
|
212
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
213
|
+
Content extends Json.Object | null,
|
|
214
|
+
>(
|
|
215
|
+
token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
216
|
+
): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
|
|
217
|
+
return getInternalRelationsFromStore(token, IMPLICIT.STORE)
|
|
218
|
+
}
|
package/src/realm.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { Each, Store } from "atom.io/internal"
|
|
2
|
+
import {
|
|
3
|
+
allocateIntoStore,
|
|
4
|
+
claimWithinStore,
|
|
5
|
+
deallocateFromStore,
|
|
6
|
+
fuseWithinStore,
|
|
7
|
+
IMPLICIT,
|
|
8
|
+
makeRootMoleculeInStore,
|
|
9
|
+
} from "atom.io/internal"
|
|
10
|
+
import type { Canonical } from "atom.io/json"
|
|
11
|
+
|
|
12
|
+
export const $claim = Symbol(`claim`)
|
|
13
|
+
export type Claim<K extends Canonical> = K & { [$claim]?: true }
|
|
14
|
+
|
|
15
|
+
export class Realm<H extends Hierarchy> {
|
|
16
|
+
public store: Store
|
|
17
|
+
public constructor(store: Store = IMPLICIT.STORE) {
|
|
18
|
+
this.store = store
|
|
19
|
+
makeRootMoleculeInStore(`root`, store)
|
|
20
|
+
}
|
|
21
|
+
public allocate<V extends Vassal<H>, A extends Above<V, H>>(
|
|
22
|
+
provenance: A,
|
|
23
|
+
key: V,
|
|
24
|
+
attachmentStyle?: `all` | `any`,
|
|
25
|
+
): Claim<V> {
|
|
26
|
+
return allocateIntoStore<H, V, A>(
|
|
27
|
+
this.store,
|
|
28
|
+
provenance,
|
|
29
|
+
key,
|
|
30
|
+
attachmentStyle,
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
public fuse<
|
|
34
|
+
C extends CompoundFrom<H>,
|
|
35
|
+
T extends C extends CompoundTypedKey<infer t, any, any> ? t : never,
|
|
36
|
+
A extends C extends CompoundTypedKey<any, infer v, any> ? v : never,
|
|
37
|
+
B extends C extends CompoundTypedKey<any, any, infer m> ? m : never,
|
|
38
|
+
>(
|
|
39
|
+
type: T,
|
|
40
|
+
reagentA: SingularTypedKey<A>,
|
|
41
|
+
reagentB: SingularTypedKey<B>,
|
|
42
|
+
): Claim<CompoundTypedKey<T, A, B>> {
|
|
43
|
+
return fuseWithinStore<H, C, T, A, B>(this.store, type, reagentA, reagentB)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public deallocate<V extends Vassal<H>>(claim: Claim<V>): void {
|
|
47
|
+
deallocateFromStore<H, V>(this.store, claim)
|
|
48
|
+
}
|
|
49
|
+
public claim<
|
|
50
|
+
V extends Exclude<Vassal<H>, CompoundTypedKey>,
|
|
51
|
+
A extends Above<V, H>,
|
|
52
|
+
>(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V> {
|
|
53
|
+
return claimWithinStore<H, V, A>(this.store, newProvenance, claim, exclusive)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class Anarchy {
|
|
58
|
+
public store: Store
|
|
59
|
+
public realm: Realm<any>
|
|
60
|
+
|
|
61
|
+
public constructor(store: Store = IMPLICIT.STORE) {
|
|
62
|
+
this.store = store
|
|
63
|
+
this.realm = new Realm(store)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public allocate(
|
|
67
|
+
provenance: Canonical,
|
|
68
|
+
key: Canonical,
|
|
69
|
+
attachmentStyle?: `all` | `any`,
|
|
70
|
+
): void {
|
|
71
|
+
allocateIntoStore<any, any, any>(
|
|
72
|
+
this.store,
|
|
73
|
+
provenance,
|
|
74
|
+
key,
|
|
75
|
+
attachmentStyle,
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public deallocate(key: Canonical): void {
|
|
80
|
+
deallocateFromStore<any, any>(this.store, key)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public claim(
|
|
84
|
+
newProvenance: Canonical,
|
|
85
|
+
key: Canonical,
|
|
86
|
+
exclusive?: `exclusive`,
|
|
87
|
+
): void {
|
|
88
|
+
claimWithinStore<any, any, any>(this.store, newProvenance, key, exclusive)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const T$ = `T$`
|
|
93
|
+
export type T$ = typeof T$
|
|
94
|
+
export type TypeTag<T extends string> = `${T$}--${T}`
|
|
95
|
+
export type SingularTypedKey<T extends string = string> = `${T}::${string}`
|
|
96
|
+
export type CompoundTypedKey<
|
|
97
|
+
A extends string = string,
|
|
98
|
+
B extends string = string,
|
|
99
|
+
C extends string = string,
|
|
100
|
+
> = `${TypeTag<A>}==${SingularTypedKey<B>}++${SingularTypedKey<C>}`
|
|
101
|
+
export type TypedKey<
|
|
102
|
+
A extends string = string,
|
|
103
|
+
B extends string = string,
|
|
104
|
+
C extends string = string,
|
|
105
|
+
> = CompoundTypedKey<A, B, C> | SingularTypedKey<A>
|
|
106
|
+
type Scope = SingularTypedKey[]
|
|
107
|
+
type MutualFealty = {
|
|
108
|
+
above: Scope
|
|
109
|
+
below: CompoundTypedKey
|
|
110
|
+
}
|
|
111
|
+
type ExclusiveFealty = {
|
|
112
|
+
above: TypedKey | `root`
|
|
113
|
+
below: Scope
|
|
114
|
+
}
|
|
115
|
+
type Fealty = ExclusiveFealty | MutualFealty
|
|
116
|
+
|
|
117
|
+
export type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>
|
|
118
|
+
|
|
119
|
+
export type Vassal<H extends Hierarchy> = {
|
|
120
|
+
[K in keyof H]: H[K] extends MutualFealty
|
|
121
|
+
? H[K][`below`]
|
|
122
|
+
: H[K] extends { below: Array<infer V> }
|
|
123
|
+
? V extends TypedKey
|
|
124
|
+
? V
|
|
125
|
+
: never
|
|
126
|
+
: never
|
|
127
|
+
}[keyof H]
|
|
128
|
+
|
|
129
|
+
export type Above<TK extends TypedKey, H extends Hierarchy> = {
|
|
130
|
+
[K in keyof H]: H[K] extends MutualFealty
|
|
131
|
+
? TK extends H[K][`below`]
|
|
132
|
+
? H[K][`above`]
|
|
133
|
+
: never
|
|
134
|
+
: H[K] extends { below: Array<infer V> }
|
|
135
|
+
? TK extends V
|
|
136
|
+
? H[K] extends ExclusiveFealty
|
|
137
|
+
? H[K][`above`]
|
|
138
|
+
: never
|
|
139
|
+
: never
|
|
140
|
+
: never
|
|
141
|
+
}[keyof H]
|
|
142
|
+
|
|
143
|
+
export type Below<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
|
|
144
|
+
[K in keyof H]: H[K] extends MutualFealty
|
|
145
|
+
? TK extends H[K][`above`]
|
|
146
|
+
? H[K][`below`]
|
|
147
|
+
: TK extends H[K][`above`][number]
|
|
148
|
+
? H[K][`below`]
|
|
149
|
+
: never
|
|
150
|
+
: H[K] extends { above: infer V }
|
|
151
|
+
? TK extends V
|
|
152
|
+
? H[K] extends ExclusiveFealty
|
|
153
|
+
? H[K][`below`][number]
|
|
154
|
+
: never
|
|
155
|
+
: never
|
|
156
|
+
: never
|
|
157
|
+
}[keyof H]
|
|
158
|
+
|
|
159
|
+
export type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
|
|
160
|
+
[K in keyof H]: H[K] extends MutualFealty
|
|
161
|
+
? TK extends H[K][`above`][number]
|
|
162
|
+
? [mutual: Exclude<H[K][`above`][number], TK>, below: H[K][`below`]]
|
|
163
|
+
: never
|
|
164
|
+
: never
|
|
165
|
+
}[keyof H]
|
|
166
|
+
|
|
167
|
+
export type CompoundFrom<H extends Hierarchy> = {
|
|
168
|
+
[K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : never
|
|
169
|
+
}[keyof H]
|
package/src/selector.ts
CHANGED
|
@@ -18,9 +18,29 @@ export type ReadonlySelectorOptions<T> = {
|
|
|
18
18
|
get: Read<() => T>
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
* Declare a selector. The value of a selector should depend
|
|
24
|
+
* on the value of atoms or other selectors in the store.
|
|
25
|
+
*
|
|
26
|
+
* A writable selector can be "set" to a new value.
|
|
27
|
+
* It is advised to set its dependencies to values
|
|
28
|
+
* that would produce the new value of the selector.
|
|
29
|
+
* @param options - {@link WritableSelectorOptions}.
|
|
30
|
+
* @returns
|
|
31
|
+
* The token for your selector.
|
|
32
|
+
* @overload Writable
|
|
33
|
+
*/
|
|
21
34
|
export function selector<T>(
|
|
22
35
|
options: WritableSelectorOptions<T>,
|
|
23
36
|
): WritableSelectorToken<T>
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @public
|
|
40
|
+
* Declare a selector. The value of a selector should depend
|
|
41
|
+
* on the value of atoms or other selectors in the store.
|
|
42
|
+
* @param options - {@link ReadonlySelectorOptions}.
|
|
43
|
+
*/
|
|
24
44
|
export function selector<T>(
|
|
25
45
|
options: ReadonlySelectorOptions<T>,
|
|
26
46
|
): ReadonlySelectorToken<T>
|
package/src/set-state.ts
CHANGED
|
@@ -3,41 +3,49 @@ import type { Canonical } from "atom.io/json"
|
|
|
3
3
|
|
|
4
4
|
import type { WritableFamilyToken, WritableToken } from "."
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
* A function that sets the value of a state.
|
|
9
|
+
* @param oldValue - The current value of the state.
|
|
10
|
+
* @returns
|
|
11
|
+
* The new value of the state.
|
|
12
|
+
*/
|
|
13
|
+
export type Setter<T, New extends T> = (oldValue: T) => New
|
|
14
|
+
|
|
6
15
|
/**
|
|
7
16
|
* @public
|
|
8
17
|
* Set the value of a state into the implicit store.
|
|
9
|
-
* @param token -
|
|
18
|
+
* @param token - An atom or writable selector token.
|
|
10
19
|
* @param value - The new value of the state.
|
|
11
20
|
* @overload Default
|
|
12
21
|
* @default
|
|
13
22
|
*/
|
|
14
23
|
export function setState<T, New extends T>(
|
|
15
24
|
token: WritableToken<T>,
|
|
16
|
-
value: New |
|
|
25
|
+
value: New | Setter<T, New>,
|
|
17
26
|
): void
|
|
18
27
|
|
|
19
28
|
/**
|
|
20
29
|
* @public
|
|
21
30
|
* Set the value of a state into the implicit store.
|
|
22
|
-
* @param token -
|
|
23
|
-
* @param key - The key of the state to set.
|
|
31
|
+
* @param token - An atom family or writable selector family token.
|
|
32
|
+
* @param key - The unique key of the state to set.
|
|
24
33
|
* @param value - The new value of the state.
|
|
25
34
|
* @overload Streamlined
|
|
26
35
|
*/
|
|
27
36
|
export function setState<T, K extends Canonical, New extends T, Key extends K>(
|
|
28
37
|
token: WritableFamilyToken<T, K>,
|
|
29
38
|
key: Key,
|
|
30
|
-
value: New |
|
|
39
|
+
value: New | Setter<T, New>,
|
|
31
40
|
): void
|
|
32
|
-
|
|
33
41
|
export function setState<T, New extends T>(
|
|
34
42
|
...params:
|
|
35
43
|
| [
|
|
36
44
|
token: WritableFamilyToken<T, Canonical>,
|
|
37
45
|
key: Canonical,
|
|
38
|
-
value: New |
|
|
46
|
+
value: New | Setter<T, New>,
|
|
39
47
|
]
|
|
40
|
-
| [token: WritableToken<T>, value: New |
|
|
48
|
+
| [token: WritableToken<T>, value: New | Setter<T, New>]
|
|
41
49
|
): void {
|
|
42
50
|
if (params.length === 2) {
|
|
43
51
|
Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
|
package/src/silo.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { findState } from "atom.io
|
|
1
|
+
import type { findState } from "atom.io"
|
|
2
2
|
import {
|
|
3
3
|
actUponStore,
|
|
4
4
|
arbitrary,
|
|
@@ -11,13 +11,16 @@ import {
|
|
|
11
11
|
disposeFromStore,
|
|
12
12
|
findInStore,
|
|
13
13
|
getFromStore,
|
|
14
|
+
IMPLICIT,
|
|
14
15
|
setIntoStore,
|
|
15
16
|
Store,
|
|
16
17
|
subscribeInStore,
|
|
17
18
|
timeTravel,
|
|
18
19
|
} from "atom.io/internal"
|
|
19
20
|
|
|
21
|
+
import { installIntoStore } from "../internal/src/install-into-store"
|
|
20
22
|
import type {
|
|
23
|
+
AtomIOToken,
|
|
21
24
|
disposeState,
|
|
22
25
|
getState,
|
|
23
26
|
redo,
|
|
@@ -45,11 +48,11 @@ export class Silo {
|
|
|
45
48
|
public subscribe: typeof subscribe
|
|
46
49
|
public undo: typeof undo
|
|
47
50
|
public redo: typeof redo
|
|
48
|
-
|
|
49
51
|
public runTransaction: typeof runTransaction
|
|
52
|
+
public install: (tokens: AtomIOToken[], store?: Store) => void
|
|
53
|
+
|
|
50
54
|
public constructor(config: Store[`config`], fromStore: Store | null = null) {
|
|
51
|
-
const s = new Store(config, fromStore)
|
|
52
|
-
this.store = s
|
|
55
|
+
const s = (this.store = new Store(config, fromStore))
|
|
53
56
|
this.atom = ((options: Parameters<typeof atom>[0]) =>
|
|
54
57
|
createStandaloneAtom(s, options)) as typeof atom
|
|
55
58
|
this.atomFamily = ((options: Parameters<typeof atomFamily>[0]) =>
|
|
@@ -58,8 +61,8 @@ export class Silo {
|
|
|
58
61
|
createStandaloneSelector(s, options)) as typeof selector
|
|
59
62
|
this.selectorFamily = ((options: Parameters<typeof selectorFamily>[0]) =>
|
|
60
63
|
createSelectorFamily(s, options)) as typeof selectorFamily
|
|
61
|
-
this.transaction = (options) => createTransaction(
|
|
62
|
-
this.timeline = (options) => createTimeline(
|
|
64
|
+
this.transaction = (options) => createTransaction(s, options)
|
|
65
|
+
this.timeline = (options) => createTimeline(s, options)
|
|
63
66
|
this.findState = ((...params: Parameters<typeof findState>) =>
|
|
64
67
|
findInStore(s, ...params)) as typeof findState
|
|
65
68
|
this.getState = ((...params: Parameters<typeof getState>) =>
|
|
@@ -78,6 +81,9 @@ export class Silo {
|
|
|
78
81
|
this.redo = (token) => {
|
|
79
82
|
timeTravel(s, `redo`, token)
|
|
80
83
|
}
|
|
81
|
-
this.runTransaction = (token, id = arbitrary()) => actUponStore(token, id
|
|
84
|
+
this.runTransaction = (token, id = arbitrary()) => actUponStore(s, token, id)
|
|
85
|
+
this.install = (tokens, source = IMPLICIT.STORE) => {
|
|
86
|
+
installIntoStore(tokens, s, source)
|
|
87
|
+
}
|
|
82
88
|
}
|
|
83
89
|
}
|
package/src/timeline.ts
CHANGED
|
@@ -49,7 +49,7 @@ export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
|
|
|
49
49
|
export const timeline = <ManagedAtom extends TimelineManageable>(
|
|
50
50
|
options: TimelineOptions<ManagedAtom>,
|
|
51
51
|
): TimelineToken<ManagedAtom> => {
|
|
52
|
-
return createTimeline(
|
|
52
|
+
return createTimeline(IMPLICIT.STORE, options)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export const redo = (tl: TimelineToken<any>): void => {
|
package/src/transaction.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { getState, setState } from "atom.io"
|
|
2
|
-
import type { findState } from "atom.io/ephemeral"
|
|
3
|
-
import type { seekState } from "atom.io/immortal"
|
|
1
|
+
import type { findState, getState, setState } from "atom.io"
|
|
4
2
|
import type { EnvironmentData, Func, Transceiver } from "atom.io/internal"
|
|
5
3
|
import {
|
|
6
4
|
actUponStore,
|
|
@@ -83,12 +81,11 @@ export type TransactionUpdate<F extends Func> = {
|
|
|
83
81
|
output: ReturnType<F>
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
export type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json
|
|
84
|
+
export type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json`>
|
|
87
85
|
export type SetterToolkit = Readonly<{
|
|
88
86
|
get: typeof getState
|
|
89
87
|
set: typeof setState
|
|
90
88
|
find: typeof findState
|
|
91
|
-
seek: typeof seekState
|
|
92
89
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(
|
|
93
90
|
state: MutableAtomToken<T, J>,
|
|
94
91
|
) => WritableSelectorToken<J>
|
|
@@ -97,7 +94,6 @@ export type ActorToolkit = Readonly<{
|
|
|
97
94
|
get: typeof getState
|
|
98
95
|
set: typeof setState
|
|
99
96
|
find: typeof findState
|
|
100
|
-
seek: typeof seekState
|
|
101
97
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(
|
|
102
98
|
state: MutableAtomToken<T, J>,
|
|
103
99
|
) => WritableSelectorToken<J>
|
|
@@ -132,12 +128,12 @@ export type TransactionIO<Token extends TransactionToken<any>> =
|
|
|
132
128
|
export function transaction<F extends Func>(
|
|
133
129
|
options: TransactionOptions<F>,
|
|
134
130
|
): TransactionToken<F> {
|
|
135
|
-
return createTransaction(
|
|
131
|
+
return createTransaction(IMPLICIT.STORE, options)
|
|
136
132
|
}
|
|
137
133
|
|
|
138
134
|
export function runTransaction<F extends Func>(
|
|
139
135
|
token: TransactionToken<F>,
|
|
140
136
|
id = arbitrary(),
|
|
141
137
|
): (...parameters: Parameters<F>) => ReturnType<F> {
|
|
142
|
-
return actUponStore(token, id
|
|
138
|
+
return actUponStore(IMPLICIT.STORE, token, id)
|
|
143
139
|
}
|
|
@@ -1,5 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
+
|
|
17
|
+
declare class Subject<T> {
|
|
18
|
+
Subscriber: (value: T) => void;
|
|
19
|
+
subscribers: Map<string, this[`Subscriber`]>;
|
|
20
|
+
subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
|
|
21
|
+
private unsubscribe;
|
|
22
|
+
next(value: T): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface Lineage {
|
|
26
|
+
parent: typeof this | null;
|
|
27
|
+
child: typeof this | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface Transceiver<S extends Json.Serializable> {
|
|
31
|
+
do: (update: S) => number | `OUT_OF_RANGE` | null;
|
|
32
|
+
undo: (update: S) => void;
|
|
33
|
+
subscribe: (key: string, fn: (update: S) => void) => () => void;
|
|
34
|
+
cacheUpdateNumber: number;
|
|
35
|
+
getUpdateNumber: (update: S) => number;
|
|
36
|
+
}
|
|
37
|
+
type TransceiverMode = `playback` | `record` | `transaction`;
|
|
3
38
|
|
|
4
39
|
type SetUpdate = `add:${string}` | `clear:${string}` | `del:${string}` | `tx:${string}`;
|
|
5
40
|
type NumberedSetUpdate = `${number}=${SetUpdate}`;
|