atom.io 0.27.3 → 0.27.5

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 (96) hide show
  1. package/data/dist/index.js +57 -72
  2. package/data/src/dict.ts +9 -12
  3. package/data/src/join.ts +25 -26
  4. package/data/src/struct-family.ts +17 -23
  5. package/data/src/struct.ts +9 -12
  6. package/dist/{chunk-ETCFHO7J.js → chunk-6ABWLAGY.js} +246 -159
  7. package/dist/index.d.ts +4 -4
  8. package/dist/index.js +33 -53
  9. package/ephemeral/dist/index.js +1 -1
  10. package/ephemeral/src/find-state.ts +1 -1
  11. package/immortal/dist/index.js +2 -2
  12. package/immortal/src/seek-state.ts +2 -2
  13. package/internal/dist/index.d.ts +88 -73
  14. package/internal/dist/index.js +1 -1
  15. package/internal/src/atom/create-regular-atom.ts +3 -3
  16. package/internal/src/atom/create-standalone-atom.ts +7 -5
  17. package/internal/src/families/create-atom-family.ts +5 -5
  18. package/internal/src/families/create-readonly-selector-family.ts +35 -7
  19. package/internal/src/families/create-regular-atom-family.ts +16 -6
  20. package/internal/src/families/create-selector-family.ts +5 -5
  21. package/internal/src/families/create-writable-selector-family.ts +35 -8
  22. package/internal/src/families/dispose-from-store.ts +22 -16
  23. package/internal/src/families/find-in-store.ts +11 -11
  24. package/internal/src/families/init-family-member.ts +9 -9
  25. package/internal/src/families/seek-in-store.ts +10 -13
  26. package/internal/src/get-state/get-from-store.ts +58 -20
  27. package/internal/src/get-state/read-or-compute-value.ts +1 -1
  28. package/internal/src/index.ts +5 -3
  29. package/internal/src/ingest-updates/ingest-atom-update.ts +1 -1
  30. package/internal/src/ingest-updates/ingest-creation-disposal.ts +5 -5
  31. package/internal/src/molecule/create-molecule-family.ts +1 -1
  32. package/internal/src/molecule/dispose-molecule.ts +1 -1
  33. package/internal/src/molecule/grow-molecule-in-store.ts +1 -1
  34. package/internal/src/molecule/make-molecule-in-store.ts +5 -5
  35. package/internal/src/mutable/create-mutable-atom-family.ts +15 -6
  36. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  37. package/internal/src/mutable/get-json-token.ts +2 -2
  38. package/internal/src/mutable/tracker-family.ts +3 -3
  39. package/internal/src/mutable/tracker.ts +14 -18
  40. package/internal/src/selector/create-readonly-selector.ts +2 -2
  41. package/internal/src/selector/create-standalone-selector.ts +5 -5
  42. package/internal/src/selector/create-writable-selector.ts +8 -8
  43. package/internal/src/selector/register-selector.ts +9 -9
  44. package/internal/src/set-state/set-into-store.ts +21 -18
  45. package/internal/src/store/deposit.ts +62 -21
  46. package/internal/src/store/store.ts +2 -1
  47. package/internal/src/subscribe/index.ts +2 -0
  48. package/internal/src/subscribe/subscribe-in-store.ts +62 -0
  49. package/internal/src/timeline/time-travel.ts +1 -1
  50. package/internal/src/transaction/build-transaction.ts +7 -6
  51. package/introspection/dist/index.js +66 -87
  52. package/introspection/src/attach-atom-index.ts +5 -8
  53. package/introspection/src/attach-selector-index.ts +6 -8
  54. package/introspection/src/attach-timeline-family.ts +25 -28
  55. package/introspection/src/attach-timeline-index.ts +5 -8
  56. package/introspection/src/attach-transaction-index.ts +5 -8
  57. package/introspection/src/attach-transaction-logs.ts +21 -27
  58. package/json/dist/index.js +12 -15
  59. package/json/src/select-json-family.ts +4 -4
  60. package/json/src/select-json.ts +6 -9
  61. package/package.json +4 -4
  62. package/react/dist/index.js +7 -7
  63. package/react/src/parse-state-overloads.ts +2 -2
  64. package/react/src/use-i.ts +1 -1
  65. package/react/src/use-json.ts +2 -2
  66. package/react/src/use-o.ts +2 -2
  67. package/realtime-client/dist/index.js +35 -55
  68. package/realtime-client/src/pull-atom-family-member.ts +1 -1
  69. package/realtime-client/src/pull-atom.ts +1 -1
  70. package/realtime-client/src/pull-mutable-atom-family-member.ts +3 -3
  71. package/realtime-client/src/pull-mutable-atom.ts +3 -3
  72. package/realtime-client/src/sync-continuity.ts +27 -47
  73. package/realtime-react/dist/index.js +3 -3
  74. package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
  75. package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
  76. package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
  77. package/realtime-server/dist/index.js +32 -32
  78. package/realtime-server/src/realtime-continuity-synchronizer.ts +16 -16
  79. package/realtime-server/src/realtime-family-provider.ts +3 -3
  80. package/realtime-server/src/realtime-mutable-family-provider.ts +5 -5
  81. package/realtime-server/src/realtime-mutable-provider.ts +2 -2
  82. package/realtime-server/src/realtime-state-provider.ts +1 -1
  83. package/realtime-server/src/realtime-state-receiver.ts +1 -1
  84. package/realtime-testing/dist/index.js +7 -7
  85. package/realtime-testing/src/setup-realtime-test.tsx +7 -7
  86. package/src/atom.ts +2 -2
  87. package/src/dispose-state.ts +2 -2
  88. package/src/get-state.ts +9 -13
  89. package/src/logger.ts +4 -0
  90. package/src/molecule.ts +1 -1
  91. package/src/selector.ts +2 -2
  92. package/src/set-state.ts +10 -7
  93. package/src/silo.ts +23 -53
  94. package/src/subscribe.ts +3 -23
  95. package/src/timeline.ts +2 -2
  96. package/internal/src/families/throw-in-case-of-conflicting-family.ts +0 -18
package/src/logger.ts CHANGED
@@ -52,12 +52,16 @@ const LoggerIconDictionary = {
52
52
  } as const
53
53
  export type LoggerIcon = keyof typeof LoggerIconDictionary
54
54
  export type TokenDenomination =
55
+ | `atom_family`
55
56
  | `atom`
56
57
  | `continuity`
57
58
  | `molecule_family`
58
59
  | `molecule`
60
+ | `mutable_atom_family`
59
61
  | `mutable_atom`
62
+ | `readonly_selector_family`
60
63
  | `readonly_selector`
64
+ | `selector_family`
61
65
  | `selector`
62
66
  | `state`
63
67
  | `timeline`
package/src/molecule.ts CHANGED
@@ -101,7 +101,7 @@ export type MoleculeToken<M extends MoleculeConstructor> = {
101
101
  export function moleculeFamily<M extends MoleculeConstructor>(
102
102
  options: MoleculeFamilyOptions<M>,
103
103
  ): MoleculeFamilyToken<M> {
104
- return createMoleculeFamily(options, IMPLICIT.STORE)
104
+ return createMoleculeFamily(IMPLICIT.STORE, options)
105
105
  }
106
106
 
107
107
  export function makeMolecule<M extends MoleculeConstructor>(
package/src/selector.ts CHANGED
@@ -27,7 +27,7 @@ export function selector<T>(
27
27
  export function selector<T>(
28
28
  options: ReadonlySelectorOptions<T> | WritableSelectorOptions<T>,
29
29
  ): ReadonlySelectorToken<T> | WritableSelectorToken<T> {
30
- return createStandaloneSelector(options, IMPLICIT.STORE)
30
+ return createStandaloneSelector(IMPLICIT.STORE, options)
31
31
  }
32
32
 
33
33
  export type WritableSelectorFamilyOptions<T, K extends Canonical> = {
@@ -69,5 +69,5 @@ export function selectorFamily<T, K extends Canonical>(
69
69
  | ReadonlySelectorFamilyOptions<T, K>
70
70
  | WritableSelectorFamilyOptions<T, K>,
71
71
  ): ReadonlySelectorFamilyToken<T, K> | WritableSelectorFamilyToken<T, K> {
72
- return createSelectorFamily(options, IMPLICIT.STORE)
72
+ return createSelectorFamily(IMPLICIT.STORE, options)
73
73
  }
package/src/set-state.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import * as Internal from "atom.io/internal"
2
2
  import type { Canonical } from "atom.io/json"
3
- import type { Json } from "rel8"
4
3
 
5
4
  import type { WritableFamilyToken, WritableToken } from "."
6
5
 
@@ -32,13 +31,17 @@ export function setState<T, K extends Canonical, New extends T, Key extends K>(
32
31
  ): void
33
32
 
34
33
  export function setState<T, New extends T>(
35
- token: WritableFamilyToken<T, Canonical> | WritableToken<T>,
36
- p1: Json.Serializable | New | ((oldValue: T) => New),
37
- p2?: New | ((oldValue: T) => New),
34
+ ...params:
35
+ | [
36
+ token: WritableFamilyToken<T, Canonical>,
37
+ key: Canonical,
38
+ value: New | ((oldValue: T) => New),
39
+ ]
40
+ | [token: WritableToken<T>, value: New | ((oldValue: T) => New)]
38
41
  ): void {
39
- if (p2) {
40
- Internal.setIntoStore(token as any, p1 as any, p2, Internal.IMPLICIT.STORE)
42
+ if (params.length === 2) {
43
+ Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
41
44
  } else {
42
- Internal.setIntoStore(token as any, p1 as any, Internal.IMPLICIT.STORE)
45
+ Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params)
43
46
  }
44
47
  }
package/src/silo.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { findState } from "atom.io/ephemeral"
2
- import type { Transceiver } from "atom.io/internal"
3
2
  import {
4
3
  createAtomFamily,
5
4
  createMoleculeFamily,
@@ -14,30 +13,21 @@ import {
14
13
  makeMoleculeInStore,
15
14
  setIntoStore,
16
15
  Store,
16
+ subscribeInStore,
17
17
  timeTravel,
18
18
  } from "atom.io/internal"
19
- import type { Canonical, Json } from "atom.io/json"
20
19
 
21
20
  import type {
22
- AtomToken,
23
21
  disposeState,
24
22
  getState,
25
23
  makeMolecule,
26
24
  moleculeFamily,
27
- MutableAtomFamilyOptions,
28
- MutableAtomFamilyToken,
29
- MutableAtomOptions,
30
- MutableAtomToken,
31
25
  redo,
32
- RegularAtomFamilyOptions,
33
- RegularAtomFamilyToken,
34
- RegularAtomOptions,
35
- RegularAtomToken,
36
26
  setState,
27
+ subscribe,
37
28
  timeline,
38
29
  undo,
39
30
  } from "."
40
- import { subscribe } from "."
41
31
  import type { atom, atomFamily } from "./atom"
42
32
  import type { selector, selectorFamily } from "./selector"
43
33
  import type { transaction } from "./transaction"
@@ -61,60 +51,40 @@ export class Silo {
61
51
  public makeMolecule: typeof makeMolecule
62
52
  public constructor(config: Store[`config`], fromStore: Store | null = null) {
63
53
  const s = new Store(config, fromStore)
64
- function _atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>
65
- function _atom<T extends Transceiver<any>, J extends Json.Serializable>(
66
- options: MutableAtomOptions<T, J>,
67
- ): MutableAtomToken<T, J>
68
- function _atom<T>(
69
- options: MutableAtomOptions<any, any> | RegularAtomOptions<T>,
70
- ): AtomToken<T> {
71
- return createStandaloneAtom(options, s)
72
- }
73
- function _atomFamily<
74
- T extends Transceiver<any>,
75
- J extends Json.Serializable,
76
- K extends Canonical,
77
- >(
78
- options: MutableAtomFamilyOptions<T, J, K>,
79
- ): MutableAtomFamilyToken<T, J, K>
80
- function _atomFamily<T, K extends Canonical>(
81
- options: RegularAtomFamilyOptions<T, K>,
82
- ): RegularAtomFamilyToken<T, K>
83
- function _atomFamily<T, K extends Canonical>(
84
- options:
85
- | MutableAtomFamilyOptions<any, any, any>
86
- | RegularAtomFamilyOptions<T, K>,
87
- ): MutableAtomFamilyToken<any, any, any> | RegularAtomFamilyToken<T, K> {
88
- return createAtomFamily(options, s)
89
- }
90
54
  this.store = s
91
- this.atom = _atom
92
- this.atomFamily = _atomFamily
93
- this.selector = (options) => createStandaloneSelector(options, s) as any
94
- this.selectorFamily = (options) => createSelectorFamily(options, s) as any
55
+ this.atom = ((options: Parameters<typeof atom>[0]) =>
56
+ createStandaloneAtom(s, options)) as typeof atom
57
+ this.atomFamily = ((options: Parameters<typeof atomFamily>[0]) =>
58
+ createAtomFamily(s, options)) as typeof atomFamily
59
+ this.selector = ((options: Parameters<typeof selector>[0]) =>
60
+ createStandaloneSelector(s, options)) as typeof selector
61
+ this.selectorFamily = ((options: Parameters<typeof selectorFamily>[0]) =>
62
+ createSelectorFamily(s, options)) as typeof selectorFamily
95
63
  this.transaction = (options) => createTransaction(options, s)
96
64
  this.timeline = (options) => createTimeline(options, s)
97
- this.findState = (token, key) => findInStore(token, key, s) as any
65
+ this.findState = ((...params: Parameters<typeof findState>) =>
66
+ findInStore(s, ...params)) as typeof findState
98
67
  this.getState = ((...params: Parameters<typeof getState>) =>
99
- getFromStore(...params, s)) as typeof getState
68
+ getFromStore(s, ...params)) as typeof getState
100
69
  this.setState = ((...params: Parameters<typeof setState>) => {
101
- setIntoStore(...params, s)
70
+ setIntoStore(s, ...params)
102
71
  }) as typeof setState
103
72
  this.disposeState = ((...params: Parameters<typeof disposeState>) => {
104
- disposeFromStore(...params, s)
73
+ disposeFromStore(s, ...params)
105
74
  }) as typeof disposeState
106
- this.subscribe = (token, handler, key) => subscribe(token, handler, key, s)
75
+ this.subscribe = ((...params: Parameters<typeof subscribe>) =>
76
+ subscribeInStore(s, ...params)) as typeof subscribe
107
77
  this.undo = (token) => {
108
- timeTravel(`undo`, token, s)
78
+ timeTravel(s, `undo`, token)
109
79
  }
110
80
  this.redo = (token) => {
111
- timeTravel(`redo`, token, s)
81
+ timeTravel(s, `redo`, token)
112
82
  }
113
- this.moleculeFamily = ((...params: Parameters<typeof moleculeFamily>) => {
114
- return createMoleculeFamily(...params, s)
115
- }) as any
83
+ this.moleculeFamily = ((options: Parameters<typeof moleculeFamily>[0]) => {
84
+ return createMoleculeFamily(s, options)
85
+ }) as typeof moleculeFamily
116
86
  this.makeMolecule = ((...params: Parameters<typeof makeMolecule>) => {
117
87
  return makeMoleculeInStore(s, ...params)
118
- }) as any
88
+ }) as typeof makeMolecule
119
89
  }
120
90
  }
package/src/subscribe.ts CHANGED
@@ -1,11 +1,5 @@
1
- import type { Flat, Func, Store } from "atom.io/internal"
2
- import {
3
- arbitrary,
4
- IMPLICIT,
5
- subscribeToState,
6
- subscribeToTimeline,
7
- subscribeToTransaction,
8
- } from "atom.io/internal"
1
+ import type { Flat, Func } from "atom.io/internal"
2
+ import { arbitrary, IMPLICIT, subscribeInStore } from "atom.io/internal"
9
3
 
10
4
  import type {
11
5
  FamilyMetadata,
@@ -35,35 +29,21 @@ export function subscribe<T>(
35
29
  token: ReadableToken<T>,
36
30
  handleUpdate: UpdateHandler<T>,
37
31
  key?: string,
38
- store?: Store,
39
32
  ): () => void
40
33
  export function subscribe<F extends Func>(
41
34
  token: TransactionToken<F>,
42
35
  handleUpdate: TransactionUpdateHandler<F>,
43
36
  key?: string,
44
- store?: Store,
45
37
  ): () => void
46
38
  export function subscribe<M extends TimelineManageable>(
47
39
  token: TimelineToken<M>,
48
40
  handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,
49
41
  key?: string,
50
- store?: Store,
51
42
  ): () => void
52
43
  export function subscribe(
53
44
  token: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,
54
45
  handleUpdate: (update: any) => void,
55
46
  key: string = arbitrary(),
56
- store = IMPLICIT.STORE,
57
47
  ): () => void {
58
- switch (token.type) {
59
- case `atom`:
60
- case `mutable_atom`:
61
- case `readonly_selector`:
62
- case `selector`:
63
- return subscribeToState(token, handleUpdate, key, store)
64
- case `transaction`:
65
- return subscribeToTransaction(token, handleUpdate, key, store)
66
- case `timeline`:
67
- return subscribeToTimeline(token, handleUpdate, key, store)
68
- }
48
+ return subscribeInStore(IMPLICIT.STORE, token, handleUpdate, key)
69
49
  }
package/src/timeline.ts CHANGED
@@ -54,9 +54,9 @@ export const timeline = <ManagedAtom extends TimelineManageable>(
54
54
  }
55
55
 
56
56
  export const redo = (tl: TimelineToken<any>): void => {
57
- timeTravel(`redo`, tl, IMPLICIT.STORE)
57
+ timeTravel(IMPLICIT.STORE, `redo`, tl)
58
58
  }
59
59
 
60
60
  export const undo = (tl: TimelineToken<any>): void => {
61
- timeTravel(`undo`, tl, IMPLICIT.STORE)
61
+ timeTravel(IMPLICIT.STORE, `undo`, tl)
62
62
  }
@@ -1,18 +0,0 @@
1
- import type { AtomFamilyToken, SelectorFamilyToken } from "atom.io"
2
-
3
- import { prettyPrintTokenType } from "../pretty-print"
4
- import type { Store } from "../store"
5
-
6
- export function throwInCaseOfConflictingFamily(
7
- family: AtomFamilyToken<any, any> | SelectorFamilyToken<any, any>,
8
- store: Store,
9
- ): void {
10
- const existingFamily = store.families.get(family.key)
11
- if (existingFamily) {
12
- throw new Error(
13
- `Tried to create ${family.type === `atom_family` ? `an` : `a`} ${prettyPrintTokenType(family)} with key "${family.key}", but "${family.key}" already exists in store "${store.config.name}" as ${existingFamily.type === `atom_family` ? `an` : `a`} ${prettyPrintTokenType(
14
- existingFamily,
15
- )}`,
16
- )
17
- }
18
- }