atom.io 0.30.6 → 0.31.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.
Files changed (81) hide show
  1. package/data/dist/index.d.ts +20 -18
  2. package/data/dist/index.js +104 -172
  3. package/data/src/join.ts +138 -210
  4. package/dist/{chunk-LSCRHXLI.js → chunk-42UH5F5Q.js} +385 -773
  5. package/dist/chunk-ICGFFQ3H.js +272 -0
  6. package/dist/index.d.ts +52 -103
  7. package/dist/index.js +3 -11
  8. package/eslint-plugin/dist/index.d.ts +22 -3
  9. package/eslint-plugin/dist/index.js +7 -7
  10. package/immortal/dist/index.d.ts +1 -2
  11. package/immortal/dist/index.js +0 -3
  12. package/immortal/src/seek-state.ts +2 -14
  13. package/internal/dist/index.d.ts +59 -95
  14. package/internal/dist/index.js +2 -2
  15. package/internal/src/atom/dispose-atom.ts +31 -15
  16. package/internal/src/families/dispose-from-store.ts +15 -44
  17. package/internal/src/families/find-in-store.ts +15 -8
  18. package/internal/src/families/init-family-member.ts +1 -1
  19. package/internal/src/families/seek-in-store.ts +2 -14
  20. package/internal/src/get-state/get-from-store.ts +13 -79
  21. package/internal/src/get-trace.ts +7 -0
  22. package/internal/src/index.ts +2 -1
  23. package/internal/src/ingest-updates/ingest-creation-disposal.ts +63 -70
  24. package/internal/src/ingest-updates/ingest-transaction-update.ts +4 -0
  25. package/internal/src/junction.ts +52 -12
  26. package/internal/src/lineage.ts +0 -7
  27. package/internal/src/molecule.ts +7 -0
  28. package/internal/src/mutable/transceiver.ts +5 -5
  29. package/internal/src/pretty-print.ts +0 -4
  30. package/internal/src/selector/dispose-selector.ts +3 -5
  31. package/internal/src/selector/register-selector.ts +2 -26
  32. package/internal/src/set-state/set-into-store.ts +3 -2
  33. package/internal/src/store/counterfeit.ts +11 -25
  34. package/internal/src/store/deposit.ts +5 -39
  35. package/internal/src/store/index.ts +1 -0
  36. package/internal/src/store/store.ts +51 -12
  37. package/internal/src/store/withdraw.ts +3 -26
  38. package/internal/src/timeline/create-timeline.ts +133 -237
  39. package/internal/src/timeline/time-travel.ts +1 -8
  40. package/internal/src/transaction/build-transaction.ts +10 -5
  41. package/internal/src/transaction/index.ts +1 -1
  42. package/internal/src/utility-types.ts +2 -0
  43. package/introspection/dist/index.d.ts +2 -3
  44. package/introspection/dist/index.js +9 -9
  45. package/introspection/src/refinery.ts +1 -3
  46. package/json/dist/index.js +9 -40
  47. package/json/src/index.ts +2 -0
  48. package/json/src/select-json-family.ts +7 -44
  49. package/package.json +34 -29
  50. package/react/dist/index.js +2 -10
  51. package/react/src/parse-state-overloads.ts +3 -11
  52. package/react-devtools/dist/index.js +13 -13
  53. package/react-devtools/src/Updates.tsx +2 -0
  54. package/realtime-client/dist/index.d.ts +20 -12
  55. package/realtime-client/dist/index.js +241 -244
  56. package/realtime-client/src/continuity/index.ts +3 -0
  57. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +231 -0
  58. package/realtime-client/src/continuity/use-conceal-state.ts +11 -0
  59. package/realtime-client/src/continuity/use-reveal-state.ts +19 -0
  60. package/realtime-client/src/index.ts +1 -0
  61. package/realtime-client/src/sync-continuity.ts +18 -262
  62. package/realtime-react/dist/index.js +2 -2
  63. package/realtime-server/dist/index.d.ts +1 -1
  64. package/realtime-server/dist/index.js +2 -2
  65. package/realtime-server/src/index.ts +1 -1
  66. package/realtime-testing/dist/index.js +2 -3
  67. package/realtime-testing/src/setup-realtime-test.tsx +1 -2
  68. package/src/allocate.ts +311 -145
  69. package/src/dispose-state.ts +5 -21
  70. package/src/get-state.ts +3 -21
  71. package/src/molecule.ts +11 -133
  72. package/src/silo.ts +1 -12
  73. package/src/timeline.ts +2 -3
  74. package/src/transaction.ts +25 -38
  75. package/dist/chunk-ADMEAXYU.js +0 -167
  76. package/internal/src/molecule/create-molecule-family.ts +0 -30
  77. package/internal/src/molecule/dispose-molecule.ts +0 -79
  78. package/internal/src/molecule/grow-molecule-in-store.ts +0 -95
  79. package/internal/src/molecule/index.ts +0 -5
  80. package/internal/src/molecule/make-molecule-in-store.ts +0 -191
  81. package/internal/src/molecule/molecule-internal.ts +0 -52
package/src/allocate.ts CHANGED
@@ -1,202 +1,330 @@
1
1
  import type { Each, Store } from "atom.io/internal"
2
2
  import {
3
3
  disposeFromStore,
4
+ findInStore,
5
+ getTrace,
6
+ IMPLICIT,
4
7
  isChildStore,
5
- Molecule,
6
8
  newest,
7
9
  } from "atom.io/internal"
8
- import type { Canonical } from "atom.io/json"
9
- import { stringifyJson } from "atom.io/json"
10
+ import type { Canonical, stringified } from "atom.io/json"
11
+ import { parseJson, stringifyJson } from "atom.io/json"
10
12
 
11
13
  import { makeRootMoleculeInStore } from "./molecule"
12
14
  import type {
13
- MoleculeCreationModern,
14
- MoleculeDisposalModern,
15
+ MoleculeCreation,
16
+ MoleculeDisposal,
17
+ MoleculeTransfer,
15
18
  } from "./transaction"
16
19
 
17
- export const $provenance = Symbol(`provenance`)
18
- export type Claim<
19
- H extends Hierarchy,
20
- V extends Vassal<H>,
21
- A extends Above<V, H>,
22
- > = V & {
23
- [$provenance]?: A
24
- }
20
+ export const $claim = Symbol(`claim`)
21
+ export type Claim<K extends Canonical> = K & { [$claim]?: true }
25
22
 
26
23
  export function allocateIntoStore<
27
24
  H extends Hierarchy,
28
25
  V extends Vassal<H>,
29
26
  A extends Above<V, H>,
30
- >(store: Store, provenance: A, key: V): Claim<H, V, A> {
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]
31
34
  const stringKey = stringifyJson(key)
32
- try {
33
- const above: Molecule<any>[] = []
34
-
35
- let allocationAttachmentStyle: `all` | `any`
36
- if (provenance === `root`) {
37
- // biome-ignore lint/style/noNonNullAssertion: let's assume we made the root molecule to get here
38
- above.push(store.molecules.get(`"root"`)!)
39
- allocationAttachmentStyle = `all`
40
- } else if (typeof provenance === `string` && provenance.startsWith(T$)) {
41
- allocationAttachmentStyle = `any`
42
- const provenanceKey = stringifyJson(provenance as Canonical)
43
- const provenanceMolecule = store.molecules.get(provenanceKey)
44
- if (!provenanceMolecule) {
45
- throw new Error(
46
- `Molecule ${provenanceKey} not found in store "${store.config.name}"`,
47
- )
48
- }
49
- above.push(provenanceMolecule)
50
- } else {
51
- const allocationIsCompound = key.startsWith(`T$--`)
52
- if (allocationIsCompound) {
53
- allocationAttachmentStyle = `all`
54
- for (const claim of provenance as SingularTypedKey[]) {
55
- const provenanceKey = stringifyJson(claim)
56
- const provenanceMolecule = store.molecules.get(provenanceKey)
57
- if (!provenanceMolecule) {
58
- throw new Error(
59
- `Molecule ${provenanceKey} not found in store "${store.config.name}"`,
60
- )
61
- }
62
- above.push(provenanceMolecule)
63
- }
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 })
64
44
  } else {
65
- allocationAttachmentStyle = `any`
66
- const provenanceKey = stringifyJson(provenance as Canonical)
67
- const provenanceMolecule = store.molecules.get(provenanceKey)
68
- if (!provenanceMolecule) {
69
- throw new Error(
70
- `Molecule ${provenanceKey} not found in store "${store.config.name}"`,
71
- )
72
- }
73
- above.push(provenanceMolecule)
45
+ invalidKeys.push(claimString)
74
46
  }
75
47
  }
76
-
77
- const molecule = new Molecule(above, key)
78
- molecule._dependsOn = allocationAttachmentStyle
79
-
80
- store.molecules.set(stringKey, molecule)
81
-
82
- for (const aboveMolecule of above) {
83
- aboveMolecule.below.set(molecule.stringKey, molecule)
84
- }
85
-
86
- const creationEvent: MoleculeCreationModern = {
87
- type: `molecule_creation`,
88
- subType: `modern`,
89
- key: molecule.key,
90
- provenance: provenance as Canonical,
91
- }
92
- const target = newest(store)
93
- const isTransaction =
94
- isChildStore(target) && target.transactionMeta.phase === `building`
95
- if (isTransaction) {
96
- target.transactionMeta.update.updates.push(creationEvent)
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 })
97
53
  } else {
98
- target.on.moleculeCreationStart.next(creationEvent)
99
- }
100
- } catch (thrown) {
101
- if (thrown instanceof Error) {
102
- store.logger.error(
103
- `❌`,
104
- `molecule`,
105
- stringKey,
106
- `allocation failed:`,
107
- thrown.message,
108
- )
54
+ invalidKeys.push(claimString)
109
55
  }
110
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
+ }
111
73
 
112
- return key as Claim<H, V, A>
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>
113
91
  }
114
92
 
115
- export function deallocateFromStore<
93
+ export function fuseWithinStore<
116
94
  H extends Hierarchy,
117
- V extends Vassal<H>,
118
- A extends Above<V, H>,
119
- >(store: Store, claim: Claim<H, V, A>): void {
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 {
120
121
  const stringKey = stringifyJson(claim)
122
+
121
123
  const molecule = store.molecules.get(stringKey)
122
124
  if (!molecule) {
123
- throw new Error(
124
- `Molecule ${stringKey} not found in store "${store.config.name}"`,
125
+ const disposal = store.disposalTraces.buffer.find(
126
+ (item) => item?.key === stringKey,
125
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
126
139
  }
127
140
 
128
- for (const join of molecule.joins.values()) {
129
- join.relations.delete(molecule.key)
130
- join.molecules.delete(molecule.stringKey)
131
- }
132
-
133
- let provenance: Canonical
134
- if (molecule.above.size === 1) {
135
- const above = molecule.above.values().next().value
136
- provenance = above.key
137
- } else {
138
- provenance = [...molecule.above.values()].map(({ key }) => key)
139
- }
140
- const values: [string, any][] = []
141
- for (const stateToken of molecule.tokens.values()) {
142
- // biome-ignore lint/style/noNonNullAssertion: tokens of molecules must have a family
143
- const tokenFamily = stateToken.family!
144
- values.push([tokenFamily.key, store.valueMap.get(stateToken.key)])
145
- }
146
-
147
- for (const state of molecule.tokens.values()) {
148
- disposeFromStore(store, state)
149
- }
150
- for (const child of molecule.below.values()) {
151
- if (child.dependsOn === `all`) {
152
- deallocateFromStore<any, any, any>(store, child.key)
153
- } else {
154
- child.above.delete(molecule.stringKey)
155
- if (child.above.size === 0) {
156
- deallocateFromStore<any, any, any>(store, child.key)
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
157
150
  }
158
151
  }
159
152
  }
160
- molecule.below.clear()
153
+ store.moleculeJoins.delete(molecule.stringKey)
161
154
 
162
- const disposalEvent: MoleculeDisposalModern = {
155
+ const provenance: stringified<Canonical>[] = []
156
+
157
+ const values: [string, any][] = []
158
+ const disposalEvent: MoleculeDisposal = {
163
159
  type: `molecule_disposal`,
164
- subType: `modern`,
165
160
  key: molecule.key,
166
161
  values,
167
162
  provenance,
168
163
  }
169
164
  const target = newest(store)
165
+ target.molecules.delete(stringKey)
170
166
  const isTransaction =
171
167
  isChildStore(target) && target.transactionMeta.phase === `building`
172
168
  if (isTransaction) {
173
169
  target.transactionMeta.update.updates.push(disposalEvent)
174
- } else {
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) {
175
200
  target.on.moleculeDisposal.next(disposalEvent)
176
201
  }
177
202
  target.molecules.delete(molecule.stringKey)
178
203
 
179
- for (const parent of molecule.above.values()) {
180
- parent.below.delete(molecule.stringKey)
181
- }
204
+ const trace = getTrace(new Error())
205
+ store.disposalTraces.add({ key: stringKey, trace })
182
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
+ }
183
255
 
184
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
185
- export function realm<H extends Hierarchy>(store: Store) {
186
- const root = makeRootMoleculeInStore(`root`, store)
187
- return {
188
- root,
189
- allocate: <V extends Vassal<H>, A extends Above<V, H>>(
190
- provenance: A,
191
- key: V,
192
- ): Claim<H, V, A> => {
193
- return allocateIntoStore(store, provenance, key)
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,
194
269
  },
195
- deallocate: <V extends Vassal<H>, A extends Above<V, H>>(
196
- claim: Claim<H, V, A>,
197
- ): void => {
198
- deallocateFromStore(store, claim)
270
+ {
271
+ source: newProvenanceMolecule.stringKey,
199
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)
200
328
  }
201
329
  }
202
330
 
@@ -218,7 +346,6 @@ type Scope = SingularTypedKey[]
218
346
  type MutualFealty = {
219
347
  above: Scope
220
348
  below: CompoundTypedKey
221
- style: `all` | `any`
222
349
  }
223
350
  type ExclusiveFealty = {
224
351
  above: TypedKey | `root`
@@ -275,3 +402,42 @@ export type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
275
402
  : never
276
403
  : never
277
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
+ }
@@ -1,35 +1,19 @@
1
1
  import * as Internal from "atom.io/internal"
2
- import type { Canonical, Json } from "atom.io/json"
2
+ import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { ReadableFamilyToken, ReadableToken } from "."
5
- import type {
6
- MoleculeConstructor,
7
- MoleculeFamilyToken,
8
- MoleculeKey,
9
- MoleculeToken,
10
- } from "./molecule"
11
5
 
12
- export function disposeState(
13
- token: MoleculeToken<any> | ReadableToken<any>,
14
- ): void
6
+ export function disposeState(token: ReadableToken<any>): void
15
7
 
16
8
  export function disposeState<K extends Canonical>(
17
9
  token: ReadableFamilyToken<any, K>,
18
10
  key: K,
19
11
  ): void
20
12
 
21
- export function disposeState<M extends MoleculeConstructor>(
22
- token: MoleculeFamilyToken<M>,
23
- key: MoleculeKey<M>,
24
- ): void
25
-
26
13
  export function disposeState(
27
- token:
28
- | MoleculeFamilyToken<any>
29
- | MoleculeToken<any>
30
- | ReadableFamilyToken<any, any>
31
- | ReadableToken<any>,
32
- key?: Json.Serializable,
14
+ ...[token, key]:
15
+ | [token: ReadableFamilyToken<any, any>, key: Canonical]
16
+ | [token: ReadableToken<any>]
33
17
  ): void {
34
18
  if (key) {
35
19
  Internal.disposeFromStore(Internal.IMPLICIT.STORE, token as any, key)
package/src/get-state.ts CHANGED
@@ -1,37 +1,19 @@
1
1
  import * as Internal from "atom.io/internal"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
- import type {
5
- MoleculeConstructor,
6
- MoleculeFamilyToken,
7
- MoleculeToken,
8
- ReadableFamilyToken,
9
- ReadableToken,
10
- } from "."
4
+ import type { ReadableFamilyToken, ReadableToken } from "."
11
5
 
12
6
  export function getState<T>(token: ReadableToken<T>): T
13
7
 
14
- export function getState<M extends MoleculeConstructor>(
15
- token: MoleculeToken<M>,
16
- ): InstanceType<M>
17
-
18
8
  export function getState<T, K extends Canonical, Key extends K>(
19
9
  token: ReadableFamilyToken<T, K>,
20
10
  key: Key,
21
11
  ): T
22
12
 
23
- export function getState<M extends MoleculeConstructor>(
24
- token: MoleculeFamilyToken<M>,
25
- key: Canonical,
26
- ): InstanceType<M>
27
-
28
13
  export function getState(
29
14
  ...params:
30
- | [
31
- token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
32
- key: Canonical,
33
- ]
34
- | [token: MoleculeToken<any> | ReadableToken<any>]
15
+ | [token: ReadableFamilyToken<any, any>, key: Canonical]
16
+ | [token: ReadableToken<any>]
35
17
  ): any {
36
18
  if (params.length === 2) {
37
19
  return Internal.getFromStore(Internal.IMPLICIT.STORE, ...params)