atom.io 0.31.0 → 0.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/{chunk-42UH5F5Q.js → chunk-Y5MBNTVU.js} +240 -32
  2. package/dist/index.d.ts +236 -104
  3. package/dist/index.js +90 -5
  4. package/ephemeral/dist/index.d.ts +35 -25
  5. package/ephemeral/src/find-state.ts +35 -25
  6. package/internal/dist/index.d.ts +15 -10
  7. package/internal/dist/index.js +1 -2
  8. package/internal/src/families/find-in-store.ts +1 -6
  9. package/internal/src/index.ts +17 -9
  10. package/internal/src/ingest-updates/ingest-creation-disposal.ts +2 -3
  11. package/internal/src/install-into-store.ts +48 -0
  12. package/internal/src/molecule.ts +299 -0
  13. package/internal/src/not-found-error.ts +8 -30
  14. package/internal/src/pretty-print.ts +1 -12
  15. package/internal/src/selector/register-selector.ts +1 -8
  16. package/internal/src/store/deposit.ts +10 -8
  17. package/internal/src/store/withdraw.ts +15 -34
  18. package/json/dist/index.js +1 -2
  19. package/package.json +5 -5
  20. package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
  21. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +1 -1
  22. package/realtime-testing/dist/index.js +3 -4
  23. package/realtime-testing/src/setup-realtime-test.tsx +4 -4
  24. package/src/atom.ts +53 -29
  25. package/src/dispose-state.ts +12 -2
  26. package/src/get-state.ts +16 -0
  27. package/src/index.ts +73 -3
  28. package/src/realm.ts +169 -0
  29. package/src/selector.ts +20 -0
  30. package/src/set-state.ts +16 -8
  31. package/src/silo.ts +9 -3
  32. package/transceivers/set-rtx/dist/index.js +4 -1
  33. package/transceivers/set-rtx/src/set-rtx.ts +4 -1
  34. package/dist/chunk-ICGFFQ3H.js +0 -272
  35. package/src/allocate.ts +0 -443
  36. package/src/molecule.ts +0 -16
@@ -1,272 +0,0 @@
1
- import { IMPLICIT, newest, isChildStore, findInStore, disposeFromStore, getTrace } from 'atom.io/internal';
2
- import { stringifyJson, parseJson } from 'atom.io/json';
3
-
4
- // src/molecule.ts
5
- function makeRootMoleculeInStore(key, store = IMPLICIT.STORE) {
6
- const molecule = {
7
- key,
8
- stringKey: stringifyJson(key),
9
- dependsOn: `any`
10
- };
11
- store.molecules.set(stringifyJson(key), molecule);
12
- return key;
13
- }
14
- var $claim = Symbol(`claim`);
15
- function allocateIntoStore(store, provenance, key, dependsOn = `any`) {
16
- const origin = provenance;
17
- const stringKey = stringifyJson(key);
18
- const invalidKeys = [];
19
- const target = newest(store);
20
- if (Array.isArray(origin)) {
21
- for (const formerClaim of origin) {
22
- const claimString = stringifyJson(formerClaim);
23
- const claim = target.molecules.get(claimString);
24
- if (claim) {
25
- store.moleculeGraph.set(claimString, stringKey, { source: claimString });
26
- } else {
27
- invalidKeys.push(claimString);
28
- }
29
- }
30
- } else {
31
- const claimString = stringifyJson(origin);
32
- const claim = target.molecules.get(claimString);
33
- if (claim) {
34
- store.moleculeGraph.set(claimString, stringKey, { source: claimString });
35
- } else {
36
- invalidKeys.push(claimString);
37
- }
38
- }
39
- if (invalidKeys.length === 0) {
40
- target.molecules.set(stringKey, { key, stringKey, dependsOn });
41
- }
42
- const creationEvent = {
43
- type: `molecule_creation`,
44
- key,
45
- provenance: origin
46
- };
47
- const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
48
- if (isTransaction) {
49
- target.transactionMeta.update.updates.push(creationEvent);
50
- } else {
51
- target.on.moleculeCreation.next(creationEvent);
52
- }
53
- for (const claim of invalidKeys) {
54
- const disposal = store.disposalTraces.buffer.find(
55
- (item) => item?.key === claim
56
- );
57
- store.logger.error(
58
- `\u274C`,
59
- `molecule`,
60
- key,
61
- `allocation failed:`,
62
- `Could not allocate to ${claim} in store "${store.config.name}".`,
63
- disposal ? `
64
- ${claim} was most recently disposed
65
- ${disposal.trace}` : `No previous disposal trace for ${claim} was found.`
66
- );
67
- }
68
- return key;
69
- }
70
- function fuseWithinStore(store, type, sideA, sideB) {
71
- const compoundKey = `T$--${type}==${sideA}++${sideB}`;
72
- const above = [sideA, sideB];
73
- allocateIntoStore(
74
- store,
75
- above,
76
- compoundKey,
77
- `all`
78
- );
79
- return compoundKey;
80
- }
81
- function deallocateFromStore(store, claim) {
82
- const stringKey = stringifyJson(claim);
83
- const molecule = store.molecules.get(stringKey);
84
- if (!molecule) {
85
- const disposal = store.disposalTraces.buffer.find(
86
- (item) => item?.key === stringKey
87
- );
88
- store.logger.error(
89
- `\u274C`,
90
- `molecule`,
91
- claim,
92
- `deallocation failed:`,
93
- `Could not find allocation for ${stringKey} in store "${store.config.name}".`,
94
- disposal ? `
95
- This state was most recently deallocated
96
- ${disposal.trace}` : `No previous disposal trace for ${stringKey} was found.`
97
- );
98
- return;
99
- }
100
- const joinKeys = store.moleculeJoins.getRelatedKeys(
101
- molecule.key
102
- );
103
- if (joinKeys) {
104
- for (const joinKey of joinKeys) {
105
- const join = store.joins.get(joinKey);
106
- if (join) {
107
- join.relations.delete(molecule.key);
108
- join.molecules.delete(molecule.stringKey);
109
- }
110
- }
111
- }
112
- store.moleculeJoins.delete(molecule.stringKey);
113
- const provenance = [];
114
- const values = [];
115
- const disposalEvent = {
116
- type: `molecule_disposal`,
117
- key: molecule.key,
118
- values,
119
- provenance
120
- };
121
- const target = newest(store);
122
- target.molecules.delete(stringKey);
123
- const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
124
- if (isTransaction) {
125
- target.transactionMeta.update.updates.push(disposalEvent);
126
- }
127
- const relatedMolecules = store.moleculeGraph.getRelationEntries({
128
- downstreamMoleculeKey: molecule.stringKey
129
- });
130
- if (relatedMolecules) {
131
- for (const [relatedStringKey, { source }] of relatedMolecules) {
132
- if (source === molecule.stringKey) {
133
- const relatedKey = parseJson(relatedStringKey);
134
- deallocateFromStore(store, relatedKey);
135
- } else {
136
- provenance.push(source);
137
- }
138
- }
139
- }
140
- const familyKeys = target.moleculeData.getRelatedKeys(molecule.stringKey);
141
- if (familyKeys) {
142
- for (const familyKey of familyKeys) {
143
- const family = target.families.get(familyKey);
144
- const token = findInStore(store, family, molecule.key);
145
- values.push([family.key, token]);
146
- disposeFromStore(store, token);
147
- }
148
- }
149
- target.moleculeGraph.delete(molecule.stringKey);
150
- target.moleculeJoins.delete(molecule.stringKey);
151
- target.moleculeData.delete(molecule.stringKey);
152
- if (!isTransaction) {
153
- target.on.moleculeDisposal.next(disposalEvent);
154
- }
155
- target.molecules.delete(molecule.stringKey);
156
- const trace = getTrace(new Error());
157
- store.disposalTraces.add({ key: stringKey, trace });
158
- }
159
- function claimWithinStore(store, newProvenance, claim, exclusive) {
160
- const stringKey = stringifyJson(claim);
161
- const target = newest(store);
162
- const molecule = target.molecules.get(stringKey);
163
- if (!molecule) {
164
- const disposal = store.disposalTraces.buffer.find(
165
- (item) => item?.key === stringKey
166
- );
167
- store.logger.error(
168
- `\u274C`,
169
- `molecule`,
170
- claim,
171
- `claim failed:`,
172
- `Could not allocate to ${stringKey} in store "${store.config.name}".`,
173
- disposal ? `
174
- ${stringKey} was most recently disposed
175
- ${disposal.trace}` : `No previous disposal trace for ${stringKey} was found.`
176
- );
177
- return claim;
178
- }
179
- const newProvenanceKey = stringifyJson(newProvenance);
180
- const newProvenanceMolecule = target.molecules.get(newProvenanceKey);
181
- if (!newProvenanceMolecule) {
182
- const disposal = store.disposalTraces.buffer.find(
183
- (item) => item?.key === newProvenanceKey
184
- );
185
- store.logger.error(
186
- `\u274C`,
187
- `molecule`,
188
- claim,
189
- `claim failed:`,
190
- `Could not allocate to ${newProvenanceKey} in store "${store.config.name}".`,
191
- disposal ? `
192
- ${newProvenanceKey} was most recently disposed
193
- ${disposal.trace}` : `No previous disposal trace for ${newProvenanceKey} was found.`
194
- );
195
- return claim;
196
- }
197
- const priorProvenance = store.moleculeGraph.getRelationEntries({
198
- downstreamMoleculeKey: molecule.stringKey
199
- }).filter(([, { source }]) => source !== stringKey).map(([key]) => parseJson(key));
200
- if (exclusive) {
201
- target.moleculeGraph.delete(stringKey);
202
- }
203
- target.moleculeGraph.set(
204
- {
205
- upstreamMoleculeKey: newProvenanceMolecule.stringKey,
206
- downstreamMoleculeKey: molecule.stringKey
207
- },
208
- {
209
- source: newProvenanceMolecule.stringKey
210
- }
211
- );
212
- const transferEvent = {
213
- type: `molecule_transfer`,
214
- key: molecule.key,
215
- from: priorProvenance,
216
- to: [newProvenanceMolecule.key]
217
- };
218
- const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
219
- if (isTransaction) {
220
- target.transactionMeta.update.updates.push(transferEvent);
221
- }
222
- return claim;
223
- }
224
- var Realm = class {
225
- store;
226
- constructor(store = IMPLICIT.STORE) {
227
- this.store = store;
228
- makeRootMoleculeInStore(`root`, store);
229
- }
230
- allocate(provenance, key, attachmentStyle) {
231
- return allocateIntoStore(
232
- this.store,
233
- provenance,
234
- key,
235
- attachmentStyle
236
- );
237
- }
238
- fuse(type, reagentA, reagentB) {
239
- return fuseWithinStore(this.store, type, reagentA, reagentB);
240
- }
241
- deallocate(claim) {
242
- deallocateFromStore(this.store, claim);
243
- }
244
- claim(newProvenance, claim, exclusive) {
245
- return claimWithinStore(this.store, newProvenance, claim, exclusive);
246
- }
247
- };
248
- var T$ = `T$`;
249
- var Anarchy = class {
250
- store;
251
- realm;
252
- constructor(store = IMPLICIT.STORE) {
253
- this.store = store;
254
- this.realm = new Realm(store);
255
- }
256
- allocate(provenance, key, attachmentStyle) {
257
- allocateIntoStore(
258
- this.store,
259
- provenance,
260
- key,
261
- attachmentStyle
262
- );
263
- }
264
- deallocate(key) {
265
- deallocateFromStore(this.store, key);
266
- }
267
- claim(newProvenance, key, exclusive) {
268
- claimWithinStore(this.store, newProvenance, key, exclusive);
269
- }
270
- };
271
-
272
- export { $claim, Anarchy, Realm, T$, allocateIntoStore, claimWithinStore, deallocateFromStore, fuseWithinStore, makeRootMoleculeInStore };
package/src/allocate.ts DELETED
@@ -1,443 +0,0 @@
1
- import type { Each, Store } from "atom.io/internal"
2
- import {
3
- disposeFromStore,
4
- findInStore,
5
- getTrace,
6
- IMPLICIT,
7
- isChildStore,
8
- newest,
9
- } from "atom.io/internal"
10
- import type { Canonical, stringified } from "atom.io/json"
11
- import { parseJson, stringifyJson } from "atom.io/json"
12
-
13
- import { makeRootMoleculeInStore } from "./molecule"
14
- import type {
15
- MoleculeCreation,
16
- MoleculeDisposal,
17
- MoleculeTransfer,
18
- } from "./transaction"
19
-
20
- export const $claim = Symbol(`claim`)
21
- export type Claim<K extends Canonical> = K & { [$claim]?: true }
22
-
23
- export function allocateIntoStore<
24
- H extends Hierarchy,
25
- V extends Vassal<H>,
26
- A extends Above<V, H>,
27
- >(
28
- store: Store,
29
- provenance: A,
30
- key: V,
31
- dependsOn: `all` | `any` = `any`,
32
- ): Claim<V> {
33
- const origin = provenance as Canonical | [Canonical, Canonical]
34
- const stringKey = stringifyJson(key)
35
- const invalidKeys: stringified<Canonical>[] = []
36
- const target = newest(store)
37
-
38
- if (Array.isArray(origin)) {
39
- for (const formerClaim of origin) {
40
- const claimString = stringifyJson(formerClaim)
41
- const claim = target.molecules.get(claimString)
42
- if (claim) {
43
- store.moleculeGraph.set(claimString, stringKey, { source: claimString })
44
- } else {
45
- invalidKeys.push(claimString)
46
- }
47
- }
48
- } else {
49
- const claimString = stringifyJson(origin)
50
- const claim = target.molecules.get(claimString)
51
- if (claim) {
52
- store.moleculeGraph.set(claimString, stringKey, { source: claimString })
53
- } else {
54
- invalidKeys.push(claimString)
55
- }
56
- }
57
- if (invalidKeys.length === 0) {
58
- target.molecules.set(stringKey, { key, stringKey, dependsOn })
59
- }
60
-
61
- const creationEvent: MoleculeCreation = {
62
- type: `molecule_creation`,
63
- key,
64
- provenance: origin,
65
- }
66
- const isTransaction =
67
- isChildStore(target) && target.transactionMeta.phase === `building`
68
- if (isTransaction) {
69
- target.transactionMeta.update.updates.push(creationEvent)
70
- } else {
71
- target.on.moleculeCreation.next(creationEvent)
72
- }
73
-
74
- for (const claim of invalidKeys) {
75
- const disposal = store.disposalTraces.buffer.find(
76
- (item) => item?.key === claim,
77
- )
78
- store.logger.error(
79
- `❌`,
80
- `molecule`,
81
- key,
82
- `allocation failed:`,
83
- `Could not allocate to ${claim} in store "${store.config.name}".`,
84
- disposal
85
- ? `\n ${claim} was most recently disposed\n${disposal.trace}`
86
- : `No previous disposal trace for ${claim} was found.`,
87
- )
88
- }
89
-
90
- return key as Claim<V>
91
- }
92
-
93
- export function fuseWithinStore<
94
- H extends Hierarchy,
95
- C extends CompoundFrom<H>,
96
- T extends C extends CompoundTypedKey<infer t, any, any> ? t : never,
97
- A extends C extends CompoundTypedKey<any, infer a, any> ? a : never,
98
- B extends C extends CompoundTypedKey<any, any, infer b> ? b : never,
99
- >(
100
- store: Store,
101
- type: T,
102
- sideA: SingularTypedKey<A>,
103
- sideB: SingularTypedKey<B>,
104
- ): Claim<CompoundTypedKey<T, A, B>> {
105
- const compoundKey: CompoundTypedKey<T, A, B> =
106
- `T$--${type}==${sideA}++${sideB}`
107
- const above = [sideA, sideB] as Above<Vassal<H>, H>
108
- allocateIntoStore<H, Vassal<H>, Above<Vassal<H>, H>>(
109
- store,
110
- above,
111
- compoundKey as Vassal<H>,
112
- `all`,
113
- )
114
- return compoundKey
115
- }
116
-
117
- export function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(
118
- store: Store,
119
- claim: Claim<V>,
120
- ): void {
121
- const stringKey = stringifyJson(claim)
122
-
123
- const molecule = store.molecules.get(stringKey)
124
- if (!molecule) {
125
- const disposal = store.disposalTraces.buffer.find(
126
- (item) => item?.key === stringKey,
127
- )
128
- store.logger.error(
129
- `❌`,
130
- `molecule`,
131
- claim,
132
- `deallocation failed:`,
133
- `Could not find allocation for ${stringKey} in store "${store.config.name}".`,
134
- disposal
135
- ? `\n This state was most recently deallocated\n${disposal.trace}`
136
- : `No previous disposal trace for ${stringKey} was found.`,
137
- )
138
- return
139
- }
140
-
141
- const joinKeys = store.moleculeJoins.getRelatedKeys(
142
- molecule.key as string /* 💥 RECONCILE */,
143
- )
144
- if (joinKeys) {
145
- for (const joinKey of joinKeys) {
146
- const join = store.joins.get(joinKey)
147
- if (join) {
148
- join.relations.delete(molecule.key)
149
- join.molecules.delete(molecule.stringKey) // get rid of
150
- }
151
- }
152
- }
153
- store.moleculeJoins.delete(molecule.stringKey)
154
-
155
- const provenance: stringified<Canonical>[] = []
156
-
157
- const values: [string, any][] = []
158
- const disposalEvent: MoleculeDisposal = {
159
- type: `molecule_disposal`,
160
- key: molecule.key,
161
- values,
162
- provenance,
163
- }
164
- const target = newest(store)
165
- target.molecules.delete(stringKey)
166
- const isTransaction =
167
- isChildStore(target) && target.transactionMeta.phase === `building`
168
- if (isTransaction) {
169
- target.transactionMeta.update.updates.push(disposalEvent)
170
- }
171
- const relatedMolecules = store.moleculeGraph.getRelationEntries({
172
- downstreamMoleculeKey: molecule.stringKey,
173
- })
174
- if (relatedMolecules) {
175
- for (const [relatedStringKey, { source }] of relatedMolecules) {
176
- if (source === molecule.stringKey) {
177
- const relatedKey = parseJson(relatedStringKey)
178
- deallocateFromStore<any, any>(store, relatedKey)
179
- } else {
180
- provenance.push(source)
181
- }
182
- }
183
- }
184
- const familyKeys = target.moleculeData.getRelatedKeys(molecule.stringKey)
185
- if (familyKeys) {
186
- for (const familyKey of familyKeys) {
187
- // biome-ignore lint/style/noNonNullAssertion: tokens of molecules must have a family
188
- const family = target.families.get(familyKey)!
189
- const token = findInStore(store, family, molecule.key)
190
- values.push([family.key, token])
191
- disposeFromStore(store, token)
192
- }
193
- }
194
-
195
- target.moleculeGraph.delete(molecule.stringKey)
196
- target.moleculeJoins.delete(molecule.stringKey)
197
- target.moleculeData.delete(molecule.stringKey)
198
-
199
- if (!isTransaction) {
200
- target.on.moleculeDisposal.next(disposalEvent)
201
- }
202
- target.molecules.delete(molecule.stringKey)
203
-
204
- const trace = getTrace(new Error())
205
- store.disposalTraces.add({ key: stringKey, trace })
206
- }
207
- export function claimWithinStore<
208
- H extends Hierarchy,
209
- V extends Exclude<Vassal<H>, CompoundTypedKey>,
210
- A extends Above<V, H>,
211
- >(
212
- store: Store,
213
- newProvenance: A,
214
- claim: Claim<V>,
215
- exclusive?: `exclusive`,
216
- ): Claim<V> {
217
- const stringKey = stringifyJson(claim)
218
- const target = newest(store)
219
- const molecule = target.molecules.get(stringKey)
220
- if (!molecule) {
221
- const disposal = store.disposalTraces.buffer.find(
222
- (item) => item?.key === stringKey,
223
- )
224
- store.logger.error(
225
- `❌`,
226
- `molecule`,
227
- claim,
228
- `claim failed:`,
229
- `Could not allocate to ${stringKey} in store "${store.config.name}".`,
230
- disposal
231
- ? `\n ${stringKey} was most recently disposed\n${disposal.trace}`
232
- : `No previous disposal trace for ${stringKey} was found.`,
233
- )
234
- return claim
235
- }
236
-
237
- const newProvenanceKey = stringifyJson(newProvenance as Canonical)
238
- const newProvenanceMolecule = target.molecules.get(newProvenanceKey)
239
- if (!newProvenanceMolecule) {
240
- const disposal = store.disposalTraces.buffer.find(
241
- (item) => item?.key === newProvenanceKey,
242
- )
243
- store.logger.error(
244
- `❌`,
245
- `molecule`,
246
- claim,
247
- `claim failed:`,
248
- `Could not allocate to ${newProvenanceKey} in store "${store.config.name}".`,
249
- disposal
250
- ? `\n ${newProvenanceKey} was most recently disposed\n${disposal.trace}`
251
- : `No previous disposal trace for ${newProvenanceKey} was found.`,
252
- )
253
- return claim
254
- }
255
-
256
- const priorProvenance = store.moleculeGraph
257
- .getRelationEntries({
258
- downstreamMoleculeKey: molecule.stringKey,
259
- })
260
- .filter(([, { source }]) => source !== stringKey)
261
- .map(([key]) => parseJson(key))
262
- if (exclusive) {
263
- target.moleculeGraph.delete(stringKey)
264
- }
265
- target.moleculeGraph.set(
266
- {
267
- upstreamMoleculeKey: newProvenanceMolecule.stringKey,
268
- downstreamMoleculeKey: molecule.stringKey,
269
- },
270
- {
271
- source: newProvenanceMolecule.stringKey,
272
- },
273
- )
274
- const transferEvent: MoleculeTransfer = {
275
- type: `molecule_transfer`,
276
- key: molecule.key,
277
- from: priorProvenance,
278
- to: [newProvenanceMolecule.key],
279
- }
280
- const isTransaction =
281
- isChildStore(target) && target.transactionMeta.phase === `building`
282
- if (isTransaction) {
283
- target.transactionMeta.update.updates.push(transferEvent)
284
- }
285
-
286
- return claim
287
- }
288
-
289
- export class Realm<H extends Hierarchy> {
290
- public store: Store
291
- public constructor(store: Store = IMPLICIT.STORE) {
292
- this.store = store
293
- makeRootMoleculeInStore(`root`, store)
294
- }
295
- public allocate<V extends Vassal<H>, A extends Above<V, H>>(
296
- provenance: A,
297
- key: V,
298
- attachmentStyle?: `all` | `any`,
299
- ): Claim<V> {
300
- return allocateIntoStore<H, V, A>(
301
- this.store,
302
- provenance,
303
- key,
304
- attachmentStyle,
305
- )
306
- }
307
- public fuse<
308
- C extends CompoundFrom<H>,
309
- T extends C extends CompoundTypedKey<infer t, any, any> ? t : never,
310
- A extends C extends CompoundTypedKey<any, infer v, any> ? v : never,
311
- B extends C extends CompoundTypedKey<any, any, infer m> ? m : never,
312
- >(
313
- type: T,
314
- reagentA: SingularTypedKey<A>,
315
- reagentB: SingularTypedKey<B>,
316
- ): Claim<CompoundTypedKey<T, A, B>> {
317
- return fuseWithinStore<H, C, T, A, B>(this.store, type, reagentA, reagentB)
318
- }
319
-
320
- public deallocate<V extends Vassal<H>>(claim: Claim<V>): void {
321
- deallocateFromStore<H, V>(this.store, claim)
322
- }
323
- public claim<
324
- V extends Exclude<Vassal<H>, CompoundTypedKey>,
325
- A extends Above<V, H>,
326
- >(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V> {
327
- return claimWithinStore<H, V, A>(this.store, newProvenance, claim, exclusive)
328
- }
329
- }
330
-
331
- export const T$ = `T$`
332
- export type T$ = typeof T$
333
- export type TypeTag<T extends string> = `${T$}--${T}`
334
- export type SingularTypedKey<T extends string = string> = `${T}::${string}`
335
- export type CompoundTypedKey<
336
- A extends string = string,
337
- B extends string = string,
338
- C extends string = string,
339
- > = `${TypeTag<A>}==${SingularTypedKey<B>}++${SingularTypedKey<C>}`
340
- export type TypedKey<
341
- A extends string = string,
342
- B extends string = string,
343
- C extends string = string,
344
- > = CompoundTypedKey<A, B, C> | SingularTypedKey<A>
345
- type Scope = SingularTypedKey[]
346
- type MutualFealty = {
347
- above: Scope
348
- below: CompoundTypedKey
349
- }
350
- type ExclusiveFealty = {
351
- above: TypedKey | `root`
352
- below: Scope
353
- }
354
- type Fealty = ExclusiveFealty | MutualFealty
355
-
356
- export type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>
357
-
358
- export type Vassal<H extends Hierarchy> = {
359
- [K in keyof H]: H[K] extends MutualFealty
360
- ? H[K][`below`]
361
- : H[K] extends { below: Array<infer V> }
362
- ? V extends TypedKey
363
- ? V
364
- : never
365
- : never
366
- }[keyof H]
367
-
368
- export type Above<TK extends TypedKey, H extends Hierarchy> = {
369
- [K in keyof H]: H[K] extends MutualFealty
370
- ? TK extends H[K][`below`]
371
- ? H[K][`above`]
372
- : never
373
- : H[K] extends { below: Array<infer V> }
374
- ? TK extends V
375
- ? H[K] extends ExclusiveFealty
376
- ? H[K][`above`]
377
- : never
378
- : never
379
- : never
380
- }[keyof H]
381
-
382
- export type Below<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
383
- [K in keyof H]: H[K] extends MutualFealty
384
- ? TK extends H[K][`above`]
385
- ? H[K][`below`]
386
- : TK extends H[K][`above`][number]
387
- ? H[K][`below`]
388
- : never
389
- : H[K] extends { above: infer V }
390
- ? TK extends V
391
- ? H[K] extends ExclusiveFealty
392
- ? H[K][`below`][number]
393
- : never
394
- : never
395
- : never
396
- }[keyof H]
397
-
398
- export type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
399
- [K in keyof H]: H[K] extends MutualFealty
400
- ? TK extends H[K][`above`][number]
401
- ? [mutual: Exclude<H[K][`above`][number], TK>, below: H[K][`below`]]
402
- : never
403
- : never
404
- }[keyof H]
405
-
406
- export type CompoundFrom<H extends Hierarchy> = {
407
- [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : never
408
- }[keyof H]
409
-
410
- export class Anarchy {
411
- public store: Store
412
- public realm: Realm<any>
413
-
414
- public constructor(store: Store = IMPLICIT.STORE) {
415
- this.store = store
416
- this.realm = new Realm(store)
417
- }
418
-
419
- public allocate(
420
- provenance: Canonical,
421
- key: Canonical,
422
- attachmentStyle?: `all` | `any`,
423
- ): void {
424
- allocateIntoStore<any, any, any>(
425
- this.store,
426
- provenance,
427
- key,
428
- attachmentStyle,
429
- )
430
- }
431
-
432
- public deallocate(key: Canonical): void {
433
- deallocateFromStore<any, any>(this.store, key)
434
- }
435
-
436
- public claim(
437
- newProvenance: Canonical,
438
- key: Canonical,
439
- exclusive?: `exclusive`,
440
- ): void {
441
- claimWithinStore<any, any, any>(this.store, newProvenance, key, exclusive)
442
- }
443
- }