atom.io 0.23.5 → 0.24.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 (72) hide show
  1. package/data/dist/index.cjs +51 -27
  2. package/data/dist/index.d.ts +5 -4
  3. package/data/dist/index.js +625 -9
  4. package/data/src/join.ts +74 -46
  5. package/dist/chunk-BF4MVQF6.js +44 -0
  6. package/dist/index.cjs +27 -0
  7. package/dist/index.d.ts +63 -18
  8. package/dist/index.js +27 -3
  9. package/immortal/dist/index.cjs +4 -262
  10. package/immortal/dist/index.d.ts +4 -94
  11. package/immortal/dist/index.js +3 -215
  12. package/immortal/src/index.ts +0 -2
  13. package/immortal/src/seek-state.ts +10 -11
  14. package/internal/dist/index.cjs +279 -111
  15. package/internal/dist/index.d.ts +63 -93
  16. package/internal/dist/index.js +273 -88
  17. package/internal/src/families/dispose-from-store.ts +11 -7
  18. package/internal/src/families/find-in-store.ts +2 -2
  19. package/internal/src/families/init-family-member.ts +37 -25
  20. package/internal/src/families/seek-in-store.ts +11 -15
  21. package/internal/src/get-environment-data.ts +0 -4
  22. package/internal/src/index.ts +1 -0
  23. package/internal/src/ingest-updates/ingest-creation-disposal.ts +8 -8
  24. package/internal/src/molecule/create-molecule-family.ts +30 -0
  25. package/internal/src/molecule/dispose-molecule.ts +76 -0
  26. package/internal/src/molecule/grow-molecule-in-store.ts +89 -0
  27. package/internal/src/molecule/index.ts +5 -0
  28. package/internal/src/molecule/make-molecule-in-store.ts +122 -0
  29. package/internal/src/molecule/molecule-internal.ts +48 -0
  30. package/internal/src/not-found-error.ts +4 -3
  31. package/internal/src/set-state/emit-update.ts +1 -2
  32. package/internal/src/store/deposit.ts +16 -30
  33. package/internal/src/store/store.ts +7 -12
  34. package/internal/src/store/withdraw.ts +30 -19
  35. package/internal/src/timeline/create-timeline.ts +7 -6
  36. package/internal/src/transaction/build-transaction.ts +2 -1
  37. package/introspection/dist/index.cjs +29 -33
  38. package/introspection/dist/index.js +1 -1
  39. package/introspection/src/auditor.ts +6 -6
  40. package/json/dist/index.cjs +4 -4
  41. package/json/dist/index.js +7 -8
  42. package/json/src/select-json-family.ts +6 -5
  43. package/package.json +6 -6
  44. package/react-devtools/dist/index.js +2 -3
  45. package/realtime-client/dist/index.js +362 -15
  46. package/realtime-react/dist/index.cjs +1 -326
  47. package/realtime-react/dist/index.d.ts +1 -14
  48. package/realtime-react/dist/index.js +1 -1
  49. package/realtime-react/src/use-sync-continuity.ts +2 -2
  50. package/realtime-server/dist/index.cjs +3 -151
  51. package/realtime-server/dist/index.d.ts +1 -3
  52. package/realtime-server/dist/index.js +2 -18
  53. package/realtime-server/src/index.ts +0 -2
  54. package/realtime-server/src/realtime-continuity-synchronizer.ts +1 -1
  55. package/realtime-testing/dist/index.cjs +4 -82
  56. package/realtime-testing/dist/index.js +2 -4
  57. package/realtime-testing/src/setup-realtime-test.tsx +2 -3
  58. package/src/dispose-state.ts +2 -2
  59. package/src/index.ts +1 -0
  60. package/src/logger.ts +2 -0
  61. package/src/molecule.ts +133 -0
  62. package/src/timeline.ts +3 -3
  63. package/src/transaction.ts +15 -13
  64. package/dist/chunk-6MLFYN32.js +0 -18
  65. package/dist/chunk-7DT3PVS3.js +0 -598
  66. package/dist/chunk-GVHKIJ3G.js +0 -329
  67. package/dist/chunk-O47EQUM6.js +0 -29
  68. package/dist/chunk-OAYGID5B.js +0 -27
  69. package/dist/chunk-PNIHPILQ.js +0 -8
  70. package/immortal/src/make-molecule.ts +0 -234
  71. package/immortal/src/molecule.ts +0 -167
  72. package/realtime-server/src/realtime-state-synchronizer.ts +0 -23
@@ -1,167 +0,0 @@
1
- import type {
2
- MutableAtomFamilyToken,
3
- MutableAtomToken,
4
- ReadableFamilyToken,
5
- ReadableToken,
6
- ReadonlySelectorFamilyToken,
7
- ReadonlySelectorToken,
8
- RegularAtomFamilyToken,
9
- RegularAtomToken,
10
- StateCreation,
11
- StateDisposal,
12
- WritableFamilyToken,
13
- WritableSelectorFamilyToken,
14
- WritableSelectorToken,
15
- WritableToken,
16
- } from "atom.io"
17
- import type { Join, JoinToken } from "atom.io/data"
18
- import { getJoin } from "atom.io/data"
19
- import type { Store, Transceiver } from "atom.io/internal"
20
- import {
21
- disposeFromStore,
22
- getJsonFamily,
23
- initFamilyMember,
24
- newest,
25
- Subject,
26
- } from "atom.io/internal"
27
- import { type Json, stringifyJson } from "atom.io/json"
28
-
29
- import type { MoleculeFamilyToken, MoleculeToken } from "./make-molecule"
30
-
31
- export class Molecule<Key extends Json.Serializable> {
32
- public readonly type = `molecule`
33
- public get key(): Key {
34
- return this.token.key
35
- }
36
- public readonly family?: MoleculeFamilyToken<Key, any, any>
37
- public readonly above: Molecule<any>[]
38
- public readonly below: Molecule<any>[] = []
39
- public readonly tokens: ReadableToken<any>[] = []
40
- public readonly joins: Join<any, any, any, any>[] = []
41
- public readonly subject = new Subject<
42
- StateCreation<any> | StateDisposal<any>
43
- >()
44
- public constructor(
45
- public readonly store: Store,
46
- above: Molecule<any> | Molecule<any>[] | undefined,
47
- public readonly token: MoleculeToken<Key, any, any>,
48
- ) {
49
- // store.molecules.set(stringifyJson(key), this) // consider removing this
50
- if (above) {
51
- if (Array.isArray(above)) {
52
- this.above = above
53
- for (const parent of above) {
54
- parent.below.push(this)
55
- }
56
- } else {
57
- this.above = [above]
58
- above.below.push(this)
59
- }
60
- } else {
61
- this.above = []
62
- }
63
- }
64
-
65
- public bond<
66
- T extends Transceiver<any>,
67
- J extends Json.Serializable,
68
- K extends string,
69
- >(token: MutableAtomFamilyToken<T, J, K>): MutableAtomToken<T, J>
70
- public bond<T, K extends Key>(
71
- token: RegularAtomFamilyToken<T, K>,
72
- ): RegularAtomToken<T>
73
- public bond<T, K extends Json.Serializable>(
74
- token: WritableSelectorFamilyToken<T, K>,
75
- ): WritableSelectorToken<T>
76
- public bond<T, K extends Json.Serializable>(
77
- token: ReadonlySelectorFamilyToken<T, K>,
78
- ): ReadonlySelectorToken<T>
79
- public bond<T, K extends Json.Serializable>(
80
- token: WritableFamilyToken<T, K>,
81
- ): WritableToken<T>
82
- public bond<T, K extends Json.Serializable>(
83
- token: ReadableFamilyToken<T, K>,
84
- ): ReadableToken<T>
85
- public bond(token: ReadableFamilyToken<any, any>): ReadableToken<any> {
86
- const state = initFamilyMember(token, this.token.key, this.store)
87
- if (token.type === `mutable_atom_family`) {
88
- const jsonFamily = getJsonFamily(token, this.store)
89
- const jsonState = initFamilyMember(jsonFamily, this.token.key, this.store)
90
- this.tokens.push(jsonState)
91
- }
92
- this.tokens.push(state)
93
- this.subject.next({ type: `state_creation`, token: state })
94
- return state
95
- }
96
-
97
- public spawn<K extends Json.Serializable>(key: K): Molecule<K> {
98
- const child = new Molecule(this.store, this, { key, type: `molecule` })
99
- return child
100
- }
101
-
102
- public with(molecule: Molecule<any>): (key: string) => Molecule<any> {
103
- return (key) => {
104
- const child = new Molecule(this.store, [this, molecule], {
105
- key,
106
- type: `molecule`,
107
- })
108
- return child
109
- }
110
- }
111
-
112
- public detach(child: Molecule<any>): void {
113
- const childIndex = this.below.indexOf(child)
114
- if (childIndex !== -1) {
115
- this.below.splice(childIndex, 1)
116
- }
117
- const parentIndex = child.above.indexOf(this)
118
- if (parentIndex !== -1) {
119
- child.above.splice(parentIndex, 1)
120
- }
121
- }
122
-
123
- public claim(child: Molecule<any>): void {
124
- if (child === this) {
125
- return
126
- }
127
- for (const parent of child.above) {
128
- parent.detach(child)
129
- }
130
- this.below.push(child)
131
- child.above.push(this)
132
- }
133
-
134
- public clear(): void {
135
- while (this.below.length > 0) {
136
- this.below.pop()?.dispose()
137
- }
138
- while (this.tokens.length > 0) {
139
- const token = this.tokens.pop()
140
- if (token) {
141
- disposeFromStore(token, this.store)
142
- }
143
- }
144
- while (this.joins.length > 0) {
145
- const join = this.joins.pop()
146
- if (join) {
147
- join.molecules.delete(stringifyJson(this.token.key))
148
- }
149
- }
150
- }
151
-
152
- public join(token: JoinToken<any, any, any, any>): void {
153
- const join = getJoin(token, this.store)
154
- join.molecules.set(stringifyJson(this.token.key), this)
155
- this.joins.push(join)
156
- }
157
-
158
- protected [Symbol.dispose](): void {
159
- this.clear()
160
- const target = newest(this.store)
161
- target.molecules.delete(stringifyJson(this.token.key))
162
- for (const parent of this.above) {
163
- parent.detach(this)
164
- }
165
- }
166
- public dispose = this[Symbol.dispose]
167
- }
@@ -1,23 +0,0 @@
1
- import type * as AtomIO from "atom.io"
2
- import { getFromStore, IMPLICIT } from "atom.io/internal"
3
- import type { Json } from "atom.io/json"
4
-
5
- import type { ServerConfig } from "."
6
-
7
- export function realtimeStateSynchronizer({
8
- socket,
9
- store = IMPLICIT.STORE,
10
- }: ServerConfig) {
11
- return function stateSynchronizer<J extends Json.Serializable>(
12
- token: AtomIO.WritableToken<J>,
13
- ): () => void {
14
- const fillGetRequest = () => {
15
- socket.emit(`value:${token.key}`, getFromStore(token, store))
16
- }
17
-
18
- socket.on(`get:${token.key}`, fillGetRequest)
19
- return () => {
20
- socket.off(`get:${token.key}`, fillGetRequest)
21
- }
22
- }
23
- }