atom.io 0.30.7 → 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 (92) 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-UDHCFTYT.js → chunk-Y5MBNTVU.js} +582 -762
  5. package/dist/index.d.ts +254 -173
  6. package/dist/index.js +91 -14
  7. package/ephemeral/dist/index.d.ts +35 -25
  8. package/ephemeral/src/find-state.ts +35 -25
  9. package/eslint-plugin/dist/index.d.ts +22 -3
  10. package/eslint-plugin/dist/index.js +7 -7
  11. package/immortal/dist/index.d.ts +1 -2
  12. package/immortal/dist/index.js +0 -3
  13. package/immortal/src/seek-state.ts +2 -14
  14. package/internal/dist/index.d.ts +57 -88
  15. package/internal/dist/index.js +1 -2
  16. package/internal/src/atom/dispose-atom.ts +31 -15
  17. package/internal/src/families/dispose-from-store.ts +15 -44
  18. package/internal/src/families/find-in-store.ts +9 -7
  19. package/internal/src/families/init-family-member.ts +1 -1
  20. package/internal/src/families/seek-in-store.ts +2 -14
  21. package/internal/src/get-state/get-from-store.ts +13 -79
  22. package/internal/src/get-trace.ts +7 -0
  23. package/internal/src/index.ts +17 -8
  24. package/internal/src/ingest-updates/ingest-creation-disposal.ts +65 -73
  25. package/internal/src/ingest-updates/ingest-transaction-update.ts +4 -0
  26. package/internal/src/install-into-store.ts +48 -0
  27. package/internal/src/junction.ts +52 -12
  28. package/internal/src/lineage.ts +0 -7
  29. package/internal/src/molecule.ts +306 -0
  30. package/internal/src/mutable/transceiver.ts +5 -5
  31. package/internal/src/not-found-error.ts +8 -30
  32. package/internal/src/pretty-print.ts +1 -16
  33. package/internal/src/selector/dispose-selector.ts +3 -5
  34. package/internal/src/selector/register-selector.ts +3 -34
  35. package/internal/src/set-state/set-into-store.ts +3 -2
  36. package/internal/src/store/counterfeit.ts +11 -25
  37. package/internal/src/store/deposit.ts +10 -42
  38. package/internal/src/store/store.ts +51 -12
  39. package/internal/src/store/withdraw.ts +18 -60
  40. package/internal/src/timeline/create-timeline.ts +133 -237
  41. package/internal/src/timeline/time-travel.ts +1 -8
  42. package/internal/src/transaction/build-transaction.ts +10 -5
  43. package/internal/src/transaction/index.ts +1 -1
  44. package/internal/src/utility-types.ts +2 -0
  45. package/introspection/dist/index.d.ts +2 -3
  46. package/introspection/dist/index.js +9 -9
  47. package/introspection/src/refinery.ts +1 -3
  48. package/json/dist/index.js +8 -40
  49. package/json/src/index.ts +2 -0
  50. package/json/src/select-json-family.ts +7 -44
  51. package/package.json +33 -28
  52. package/react/dist/index.js +2 -10
  53. package/react/src/parse-state-overloads.ts +3 -11
  54. package/react-devtools/dist/index.js +13 -13
  55. package/react-devtools/src/Updates.tsx +2 -0
  56. package/realtime-client/dist/index.d.ts +20 -12
  57. package/realtime-client/dist/index.js +241 -244
  58. package/realtime-client/src/continuity/index.ts +3 -0
  59. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +231 -0
  60. package/realtime-client/src/continuity/use-conceal-state.ts +11 -0
  61. package/realtime-client/src/continuity/use-reveal-state.ts +19 -0
  62. package/realtime-client/src/index.ts +1 -0
  63. package/realtime-client/src/sync-continuity.ts +18 -262
  64. package/realtime-react/dist/index.js +2 -2
  65. package/realtime-server/dist/index.d.ts +1 -1
  66. package/realtime-server/dist/index.js +2 -2
  67. package/realtime-server/src/index.ts +1 -1
  68. package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
  69. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +1 -1
  70. package/realtime-testing/dist/index.js +5 -7
  71. package/realtime-testing/src/setup-realtime-test.tsx +5 -6
  72. package/src/atom.ts +53 -29
  73. package/src/dispose-state.ts +17 -23
  74. package/src/get-state.ts +19 -21
  75. package/src/index.ts +73 -3
  76. package/src/realm.ts +169 -0
  77. package/src/selector.ts +20 -0
  78. package/src/set-state.ts +16 -8
  79. package/src/silo.ts +9 -14
  80. package/src/timeline.ts +2 -3
  81. package/src/transaction.ts +25 -38
  82. package/transceivers/set-rtx/dist/index.js +4 -1
  83. package/transceivers/set-rtx/src/set-rtx.ts +4 -1
  84. package/dist/chunk-ADMEAXYU.js +0 -167
  85. package/internal/src/molecule/create-molecule-family.ts +0 -30
  86. package/internal/src/molecule/dispose-molecule.ts +0 -79
  87. package/internal/src/molecule/grow-molecule-in-store.ts +0 -95
  88. package/internal/src/molecule/index.ts +0 -5
  89. package/internal/src/molecule/make-molecule-in-store.ts +0 -191
  90. package/internal/src/molecule/molecule-internal.ts +0 -52
  91. package/src/allocate.ts +0 -277
  92. package/src/molecule.ts +0 -138
@@ -0,0 +1,306 @@
1
+ import type {
2
+ Above,
3
+ Claim,
4
+ CompoundFrom,
5
+ CompoundTypedKey,
6
+ Hierarchy,
7
+ MoleculeCreation,
8
+ MoleculeDisposal,
9
+ MoleculeTransfer,
10
+ SingularTypedKey,
11
+ Vassal,
12
+ } from "atom.io"
13
+ import type { Canonical, stringified } from "atom.io/json"
14
+ import { parseJson, stringifyJson } from "atom.io/json"
15
+
16
+ import { disposeFromStore, findInStore } from "./families"
17
+ import { getTrace } from "./get-trace"
18
+ import { newest } from "./lineage"
19
+ import type { Store } from "./store"
20
+ import { IMPLICIT } from "./store"
21
+ import { isChildStore } from "./transaction"
22
+
23
+ export type Molecule<K extends Canonical> = {
24
+ readonly key: K
25
+ readonly stringKey: stringified<K>
26
+ readonly dependsOn: `all` | `any`
27
+ }
28
+
29
+ export function makeRootMoleculeInStore<S extends string>(
30
+ key: S,
31
+ store: Store = IMPLICIT.STORE,
32
+ ): S {
33
+ const molecule = {
34
+ key,
35
+ stringKey: stringifyJson(key),
36
+ dependsOn: `any`,
37
+ } satisfies Molecule<S>
38
+ store.molecules.set(stringifyJson(key), molecule)
39
+ return key
40
+ }
41
+
42
+ export function allocateIntoStore<
43
+ H extends Hierarchy,
44
+ V extends Vassal<H>,
45
+ A extends Above<V, H>,
46
+ >(
47
+ store: Store,
48
+ provenance: A,
49
+ key: V,
50
+ dependsOn: `all` | `any` = `any`,
51
+ ): Claim<V> {
52
+ const origin = provenance as Canonical | [Canonical, Canonical]
53
+ const stringKey = stringifyJson(key)
54
+ const invalidKeys: stringified<Canonical>[] = []
55
+ const target = newest(store)
56
+
57
+ if (Array.isArray(origin)) {
58
+ for (const formerClaim of origin) {
59
+ const claimString = stringifyJson(formerClaim)
60
+ const claim = target.molecules.get(claimString)
61
+ if (claim) {
62
+ store.moleculeGraph.set(claimString, stringKey, { source: claimString })
63
+ } else {
64
+ invalidKeys.push(claimString)
65
+ }
66
+ }
67
+ } else {
68
+ const claimString = stringifyJson(origin)
69
+ const claim = target.molecules.get(claimString)
70
+ if (claim) {
71
+ store.moleculeGraph.set(claimString, stringKey, { source: claimString })
72
+ } else {
73
+ invalidKeys.push(claimString)
74
+ }
75
+ }
76
+ if (invalidKeys.length === 0) {
77
+ target.molecules.set(stringKey, { key, stringKey, dependsOn })
78
+ }
79
+
80
+ const creationEvent: MoleculeCreation = {
81
+ type: `molecule_creation`,
82
+ key,
83
+ provenance: origin,
84
+ }
85
+ const isTransaction =
86
+ isChildStore(target) && target.transactionMeta.phase === `building`
87
+ if (isTransaction) {
88
+ target.transactionMeta.update.updates.push(creationEvent)
89
+ } else {
90
+ target.on.moleculeCreation.next(creationEvent)
91
+ }
92
+
93
+ for (const claim of invalidKeys) {
94
+ const disposal = store.disposalTraces.buffer.find(
95
+ (item) => item?.key === claim,
96
+ )
97
+ store.logger.error(
98
+ `❌`,
99
+ `molecule`,
100
+ key,
101
+ `allocation failed:`,
102
+ `Could not allocate to ${claim} in store "${store.config.name}".`,
103
+ disposal
104
+ ? `\n ${claim} was most recently disposed\n${disposal.trace}`
105
+ : `No previous disposal trace for ${claim} was found.`,
106
+ )
107
+ }
108
+
109
+ return key as Claim<V>
110
+ }
111
+
112
+ export function fuseWithinStore<
113
+ H extends Hierarchy,
114
+ C extends CompoundFrom<H>,
115
+ T extends C extends CompoundTypedKey<infer t, any, any> ? t : never,
116
+ A extends C extends CompoundTypedKey<any, infer a, any> ? a : never,
117
+ B extends C extends CompoundTypedKey<any, any, infer b> ? b : never,
118
+ >(
119
+ store: Store,
120
+ type: T,
121
+ sideA: SingularTypedKey<A>,
122
+ sideB: SingularTypedKey<B>,
123
+ ): Claim<CompoundTypedKey<T, A, B>> {
124
+ const compoundKey: CompoundTypedKey<T, A, B> =
125
+ `T$--${type}==${sideA}++${sideB}`
126
+ const above = [sideA, sideB] as Above<Vassal<H>, H>
127
+ allocateIntoStore<H, Vassal<H>, Above<Vassal<H>, H>>(
128
+ store,
129
+ above,
130
+ compoundKey as Vassal<H>,
131
+ `all`,
132
+ )
133
+ return compoundKey
134
+ }
135
+
136
+ export function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(
137
+ store: Store,
138
+ claim: Claim<V>,
139
+ ): void {
140
+ const stringKey = stringifyJson(claim)
141
+
142
+ const molecule = store.molecules.get(stringKey)
143
+ if (!molecule) {
144
+ const disposal = store.disposalTraces.buffer.find(
145
+ (item) => item?.key === stringKey,
146
+ )
147
+ store.logger.error(
148
+ `❌`,
149
+ `molecule`,
150
+ claim,
151
+ `deallocation failed:`,
152
+ `Could not find allocation for ${stringKey} in store "${store.config.name}".`,
153
+ disposal
154
+ ? `\n This state was most recently deallocated\n${disposal.trace}`
155
+ : `No previous disposal trace for ${stringKey} was found.`,
156
+ )
157
+ return
158
+ }
159
+
160
+ const joinKeys = store.moleculeJoins.getRelatedKeys(
161
+ molecule.key as string /* 💥 RECONCILE */,
162
+ )
163
+ if (joinKeys) {
164
+ for (const joinKey of joinKeys) {
165
+ const join = store.joins.get(joinKey)
166
+ if (join) {
167
+ join.relations.delete(molecule.key)
168
+ join.molecules.delete(molecule.stringKey) // get rid of
169
+ }
170
+ }
171
+ }
172
+ store.moleculeJoins.delete(molecule.stringKey)
173
+
174
+ const provenance: stringified<Canonical>[] = []
175
+
176
+ const values: [string, any][] = []
177
+ const disposalEvent: MoleculeDisposal = {
178
+ type: `molecule_disposal`,
179
+ key: molecule.key,
180
+ values,
181
+ provenance,
182
+ }
183
+ const target = newest(store)
184
+ target.molecules.delete(stringKey)
185
+ const isTransaction =
186
+ isChildStore(target) && target.transactionMeta.phase === `building`
187
+ if (isTransaction) {
188
+ target.transactionMeta.update.updates.push(disposalEvent)
189
+ }
190
+ const relatedMolecules = store.moleculeGraph.getRelationEntries({
191
+ downstreamMoleculeKey: molecule.stringKey,
192
+ })
193
+ if (relatedMolecules) {
194
+ for (const [relatedStringKey, { source }] of relatedMolecules) {
195
+ if (source === molecule.stringKey) {
196
+ const relatedKey = parseJson(relatedStringKey)
197
+ deallocateFromStore<any, any>(store, relatedKey)
198
+ } else {
199
+ provenance.push(source)
200
+ }
201
+ }
202
+ }
203
+ const familyKeys = target.moleculeData.getRelatedKeys(molecule.stringKey)
204
+ if (familyKeys) {
205
+ for (const familyKey of familyKeys) {
206
+ // biome-ignore lint/style/noNonNullAssertion: tokens of molecules must have a family
207
+ const family = target.families.get(familyKey)!
208
+ const token = findInStore(store, family, molecule.key)
209
+ values.push([family.key, token])
210
+ disposeFromStore(store, token)
211
+ }
212
+ }
213
+
214
+ target.moleculeGraph.delete(molecule.stringKey)
215
+ target.moleculeJoins.delete(molecule.stringKey)
216
+ target.moleculeData.delete(molecule.stringKey)
217
+
218
+ if (!isTransaction) {
219
+ target.on.moleculeDisposal.next(disposalEvent)
220
+ }
221
+ target.molecules.delete(molecule.stringKey)
222
+
223
+ const trace = getTrace(new Error())
224
+ store.disposalTraces.add({ key: stringKey, trace })
225
+ }
226
+ export function claimWithinStore<
227
+ H extends Hierarchy,
228
+ V extends Exclude<Vassal<H>, CompoundTypedKey>,
229
+ A extends Above<V, H>,
230
+ >(
231
+ store: Store,
232
+ newProvenance: A,
233
+ claim: Claim<V>,
234
+ exclusive?: `exclusive`,
235
+ ): Claim<V> {
236
+ const stringKey = stringifyJson(claim)
237
+ const target = newest(store)
238
+ const molecule = target.molecules.get(stringKey)
239
+ if (!molecule) {
240
+ const disposal = store.disposalTraces.buffer.find(
241
+ (item) => item?.key === stringKey,
242
+ )
243
+ store.logger.error(
244
+ `❌`,
245
+ `molecule`,
246
+ claim,
247
+ `claim failed:`,
248
+ `Could not allocate to ${stringKey} in store "${store.config.name}".`,
249
+ disposal
250
+ ? `\n ${stringKey} was most recently disposed\n${disposal.trace}`
251
+ : `No previous disposal trace for ${stringKey} was found.`,
252
+ )
253
+ return claim
254
+ }
255
+
256
+ const newProvenanceKey = stringifyJson(newProvenance as Canonical)
257
+ const newProvenanceMolecule = target.molecules.get(newProvenanceKey)
258
+ if (!newProvenanceMolecule) {
259
+ const disposal = store.disposalTraces.buffer.find(
260
+ (item) => item?.key === newProvenanceKey,
261
+ )
262
+ store.logger.error(
263
+ `❌`,
264
+ `molecule`,
265
+ claim,
266
+ `claim failed:`,
267
+ `Could not allocate to ${newProvenanceKey} in store "${store.config.name}".`,
268
+ disposal
269
+ ? `\n ${newProvenanceKey} was most recently disposed\n${disposal.trace}`
270
+ : `No previous disposal trace for ${newProvenanceKey} was found.`,
271
+ )
272
+ return claim
273
+ }
274
+
275
+ const priorProvenance = store.moleculeGraph
276
+ .getRelationEntries({
277
+ downstreamMoleculeKey: molecule.stringKey,
278
+ })
279
+ .filter(([, { source }]) => source !== stringKey)
280
+ .map(([key]) => parseJson(key))
281
+ if (exclusive) {
282
+ target.moleculeGraph.delete(stringKey)
283
+ }
284
+ target.moleculeGraph.set(
285
+ {
286
+ upstreamMoleculeKey: newProvenanceMolecule.stringKey,
287
+ downstreamMoleculeKey: molecule.stringKey,
288
+ },
289
+ {
290
+ source: newProvenanceMolecule.stringKey,
291
+ },
292
+ )
293
+ const transferEvent: MoleculeTransfer = {
294
+ type: `molecule_transfer`,
295
+ key: molecule.key,
296
+ from: priorProvenance,
297
+ to: [newProvenanceMolecule.key],
298
+ }
299
+ const isTransaction =
300
+ isChildStore(target) && target.transactionMeta.phase === `building`
301
+ if (isTransaction) {
302
+ target.transactionMeta.update.updates.push(transferEvent)
303
+ }
304
+
305
+ return claim
306
+ }
@@ -1,11 +1,11 @@
1
1
  import type { Json } from "atom.io/json"
2
2
 
3
- export interface Transceiver<Signal extends Json.Serializable> {
4
- do: (update: Signal) => number | `OUT_OF_RANGE` | null
5
- undo: (update: Signal) => void
6
- subscribe: (key: string, fn: (update: Signal) => void) => () => void
3
+ export interface Transceiver<S extends Json.Serializable> {
4
+ do: (update: S) => number | `OUT_OF_RANGE` | null
5
+ undo: (update: S) => void
6
+ subscribe: (key: string, fn: (update: S) => void) => () => void
7
7
  cacheUpdateNumber: number
8
- getUpdateNumber: (update: Signal) => number
8
+ getUpdateNumber: (update: S) => number
9
9
  }
10
10
 
11
11
  export function isTransceiver(
@@ -1,37 +1,15 @@
1
- import { type Json, stringifyJson } from "atom.io/json"
1
+ import type { AtomIOToken } from "atom.io"
2
+ import { stringifyJson } from "atom.io/json"
2
3
 
3
- import type { AtomIOToken } from "./pretty-print"
4
4
  import { prettyPrintTokenType } from "./pretty-print"
5
5
  import type { Store } from "./store"
6
6
 
7
7
  export class NotFoundError extends Error {
8
- public constructor(token: AtomIOToken, store: Store)
9
- public constructor(
10
- familyToken: AtomIOToken,
11
- key: Json.Serializable,
12
- store: Store,
13
- )
14
- public constructor(
15
- ...params:
16
- | [token: AtomIOToken, key: Json.Serializable, store: Store]
17
- | [token: AtomIOToken, store: Store]
18
- ) {
19
- const token: AtomIOToken = params[0]
20
- const store: Store = params.length === 2 ? params[1] : params[2]
21
-
22
- if (params.length === 2) {
23
- super(
24
- `${prettyPrintTokenType(token)} ${stringifyJson(token.key)} not found in store "${
25
- store.config.name
26
- }".`,
27
- )
28
- } else {
29
- const key = params[1]
30
- super(
31
- `${prettyPrintTokenType(token)} "${token.key}" member ${stringifyJson(key)} not found in store "${
32
- store.config.name
33
- }".`,
34
- )
35
- }
8
+ public constructor(token: AtomIOToken, store: Store) {
9
+ super(
10
+ `${prettyPrintTokenType(token)} ${stringifyJson(token.key)} not found in store "${
11
+ store.config.name
12
+ }".`,
13
+ )
36
14
  }
37
15
  }
@@ -1,22 +1,7 @@
1
- import type {
2
- MoleculeFamilyToken,
3
- MoleculeToken,
4
- ReadableFamilyToken,
5
- ReadableToken,
6
- TimelineToken,
7
- TransactionToken,
8
- } from "atom.io"
1
+ import type { AtomIOToken } from "atom.io"
9
2
 
10
3
  const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
11
4
 
12
- export type AtomIOToken =
13
- | MoleculeFamilyToken<any>
14
- | MoleculeToken<any>
15
- | ReadableFamilyToken<any, any>
16
- | ReadableToken<any>
17
- | TimelineToken<any>
18
- | TransactionToken<any>
19
-
20
5
  export function prettyPrintTokenType(token: AtomIOToken): string {
21
6
  return token.type.split(`_`).map(capitalize).join(` `)
22
7
  }
@@ -20,7 +20,7 @@ export function disposeSelector(
20
20
  } else {
21
21
  const molecule = target.molecules.get(selector.family.subKey)
22
22
  if (molecule) {
23
- molecule.tokens.delete(key)
23
+ target.moleculeData.delete(selector.family.subKey, selector.family.key)
24
24
  }
25
25
  switch (selectorToken.type) {
26
26
  case `selector`:
@@ -30,10 +30,6 @@ export function disposeSelector(
30
30
  { key: selector.family.key, type: `selector_family` },
31
31
  store,
32
32
  )
33
- family.subject.next({
34
- type: `state_disposal`,
35
- token: selectorToken,
36
- })
37
33
  }
38
34
  break
39
35
  case `readonly_selector`:
@@ -45,6 +41,7 @@ export function disposeSelector(
45
41
  )
46
42
  family.subject.next({
47
43
  type: `state_disposal`,
44
+ subType: `selector`,
48
45
  token: selectorToken,
49
46
  })
50
47
  }
@@ -57,6 +54,7 @@ export function disposeSelector(
57
54
  if (isChildStore(target) && target.transactionMeta.phase === `building`) {
58
55
  target.transactionMeta.update.updates.push({
59
56
  type: `state_disposal`,
57
+ subType: `selector`,
60
58
  token: selectorToken,
61
59
  })
62
60
  } else {
@@ -1,7 +1,4 @@
1
1
  import type {
2
- MoleculeConstructor,
3
- MoleculeFamilyToken,
4
- MoleculeToken,
5
2
  ReadableFamilyToken,
6
3
  ReadableToken,
7
4
  setState,
@@ -14,7 +11,6 @@ import type { seekState } from "atom.io/immortal"
14
11
  import type { Json } from "atom.io/json"
15
12
 
16
13
  import { findInStore, seekInStore } from "../families"
17
- import { getFromStore } from "../get-state"
18
14
  import { readOrComputeValue } from "../get-state/read-or-compute-value"
19
15
  import { newest } from "../lineage"
20
16
  import { getJsonToken } from "../mutable"
@@ -31,39 +27,19 @@ export const registerSelector = (
31
27
  ): SetterToolkit => ({
32
28
  get: (
33
29
  ...params:
34
- | [MoleculeFamilyToken<any>, Json.Serializable]
35
- | [MoleculeToken<MoleculeConstructor>]
36
30
  | [ReadableFamilyToken<any, any>, Json.Serializable]
37
31
  | [ReadableToken<any>]
38
32
  ) => {
39
33
  const target = newest(store)
40
- let dependency: MoleculeToken<MoleculeConstructor> | ReadableToken<any>
34
+ let dependency: ReadableToken<any>
41
35
 
42
36
  if (params.length === 2) {
43
37
  const [family, key] = params
44
- switch (family.type) {
45
- case `molecule_family`:
46
- return getFromStore(store, family, key)
47
- default:
48
- if (store.config.lifespan === `ephemeral`) {
49
- dependency = findInStore(store, family, key)
50
- } else {
51
- const maybeDependency = seekInStore(store, family, key)
52
- if (maybeDependency) {
53
- dependency = maybeDependency
54
- } else {
55
- throw new NotFoundError(family, key, store)
56
- }
57
- }
58
- }
38
+ dependency = findInStore(store, family, key)
59
39
  } else {
60
40
  ;[dependency] = params
61
41
  }
62
42
 
63
- if (dependency.type === `molecule`) {
64
- return getFromStore(store, dependency)
65
- }
66
-
67
43
  const dependencyState = withdraw(dependency, store)
68
44
  const dependencyValue = readOrComputeValue(dependencyState, store)
69
45
 
@@ -106,14 +82,7 @@ export const registerSelector = (
106
82
  const family = params[0]
107
83
  const key = params[1]
108
84
  value = params[2]
109
- const maybeToken =
110
- store.config.lifespan === `ephemeral`
111
- ? findInStore(store, family, key)
112
- : seekInStore(store, family, key)
113
- if (!maybeToken) {
114
- throw new NotFoundError(family, key, store)
115
- }
116
- token = maybeToken
85
+ token = findInStore(store, family, key)
117
86
  }
118
87
  const target = newest(store)
119
88
  const state = withdraw(token, target)
@@ -50,9 +50,10 @@ export function setIntoStore<T, New extends T>(
50
50
  token = findInStore(store, family, key)
51
51
  }
52
52
 
53
- if (`counterfeit` in token) {
53
+ if (`counterfeit` in token && `family` in token) {
54
+ const subKey = token.family.subKey
54
55
  const disposal = store.disposalTraces.buffer.find(
55
- (item) => item?.key === token.key,
56
+ (item) => item?.key === subKey,
56
57
  )
57
58
  store.logger.error(
58
59
  `❌`,
@@ -1,10 +1,6 @@
1
1
  import type {
2
2
  AtomFamilyToken,
3
3
  AtomToken,
4
- MoleculeConstructor,
5
- MoleculeFamilyToken,
6
- MoleculeKey,
7
- MoleculeToken,
8
4
  MutableAtomFamilyToken,
9
5
  MutableAtomToken,
10
6
  ReadableFamilyToken,
@@ -75,35 +71,25 @@ export function counterfeit<T, K extends Canonical, Key extends K>(
75
71
  key: Key,
76
72
  ): ReadableToken<T>
77
73
 
78
- export function counterfeit<M extends MoleculeConstructor>(
79
- token: MoleculeFamilyToken<M>,
80
- key: MoleculeKey<M>,
81
- ): MoleculeKey<M>
82
-
83
74
  export function counterfeit(
84
- token: MoleculeFamilyToken<any> | ReadableFamilyToken<any, any>,
75
+ token: ReadableFamilyToken<any, any>,
85
76
  key: Canonical,
86
- ): MoleculeToken<any> | ReadableToken<any> {
77
+ ): ReadableToken<any> {
87
78
  const subKey = stringifyJson(key)
88
79
  const fullKey = `${token.key}(${subKey})`
89
80
  const type = FAMILY_MEMBER_TOKEN_TYPES[token.type]
90
81
  const stateToken = {
91
82
  key: fullKey,
92
83
  type,
93
- } satisfies MoleculeToken<any> | ReadableToken<any>
94
- if (type === `molecule`) {
95
- Object.assign(stateToken, {
96
- key,
97
- family: token,
98
- })
99
- } else {
100
- Object.assign(stateToken, {
101
- family: {
102
- key: token.key,
103
- subKey,
104
- },
105
- })
106
- }
84
+ } satisfies ReadableToken<any>
85
+
86
+ Object.assign(stateToken, {
87
+ family: {
88
+ key: token.key,
89
+ subKey,
90
+ },
91
+ })
92
+
107
93
  Object.assign(stateToken, { counterfeit: true })
108
94
  return stateToken
109
95
  }
@@ -1,10 +1,7 @@
1
1
  import type {
2
2
  AtomFamilyToken,
3
+ AtomIOToken,
3
4
  AtomToken,
4
- MoleculeConstructor,
5
- MoleculeFamily,
6
- MoleculeFamilyToken,
7
- MoleculeToken,
8
5
  MutableAtomFamilyToken,
9
6
  MutableAtomToken,
10
7
  ReadableFamilyToken,
@@ -15,6 +12,8 @@ import type {
15
12
  RegularAtomToken,
16
13
  SelectorFamilyToken,
17
14
  SelectorToken,
15
+ TimelineManageable,
16
+ TimelineToken,
18
17
  TransactionToken,
19
18
  WritableFamilyToken,
20
19
  WritableSelectorFamilyToken,
@@ -26,8 +25,8 @@ import type { Canonical, Json } from "atom.io/json"
26
25
  import type {
27
26
  Atom,
28
27
  AtomFamily,
28
+ AtomIOInternalResource,
29
29
  Func,
30
- Molecule,
31
30
  MutableAtom,
32
31
  MutableAtomFamily,
33
32
  ReadableFamily,
@@ -38,6 +37,7 @@ import type {
38
37
  RegularAtomFamily,
39
38
  Selector,
40
39
  SelectorFamily,
40
+ Timeline,
41
41
  Transceiver,
42
42
  WritableFamily,
43
43
  WritableSelector,
@@ -82,48 +82,16 @@ export function deposit<T>(
82
82
  state: ReadableFamily<T, any>,
83
83
  ): ReadableFamilyToken<T, any>
84
84
 
85
- export function deposit<M extends MoleculeConstructor>(
86
- state: MoleculeFamily<M>,
87
- ): MoleculeFamilyToken<M>
88
- export function deposit<M extends MoleculeConstructor>(
89
- state: Molecule<M>,
90
- ): MoleculeToken<M>
91
-
92
85
  export function deposit<T extends Func>(
93
86
  state: Transaction<T>,
94
87
  ): TransactionToken<T>
88
+ export function deposit<M extends TimelineManageable>(
89
+ state: Timeline<M>,
90
+ ): TimelineToken<M>
95
91
 
96
- export function deposit(
97
- state: Molecule<any> | ReadableState<any>,
98
- ): MoleculeToken<any> | ReadableToken<any>
99
-
100
- export function deposit(
101
- state:
102
- | Molecule<any>
103
- | MoleculeFamily<any>
104
- | ReadableFamily<any, any>
105
- | ReadableState<any>
106
- | Transaction<Func>,
107
- ):
108
- | MoleculeFamilyToken<any>
109
- | MoleculeToken<any>
110
- | ReadableFamilyToken<any, any>
111
- | ReadableToken<any>
112
- | TransactionToken<Func>
92
+ export function deposit(resource: AtomIOInternalResource): AtomIOToken
113
93
 
114
- export function deposit(
115
- state:
116
- | Molecule<any>
117
- | MoleculeFamily<any>
118
- | ReadableFamily<any, any>
119
- | ReadableState<any>
120
- | Transaction<Func>,
121
- ):
122
- | MoleculeFamilyToken<any>
123
- | MoleculeToken<any>
124
- | ReadableFamilyToken<any, any>
125
- | ReadableToken<any>
126
- | TransactionToken<Func> {
94
+ export function deposit(state: AtomIOInternalResource): AtomIOToken {
127
95
  const token = {
128
96
  key: state.key,
129
97
  type: state.type,