atom.io 0.21.0 → 0.22.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 (99) hide show
  1. package/data/dist/index.cjs +139 -66
  2. package/data/dist/index.d.ts +6 -0
  3. package/data/dist/index.js +3 -3
  4. package/data/src/join.ts +135 -56
  5. package/data/src/struct-family.ts +2 -2
  6. package/dist/{chunk-RT43TVKP.js → chunk-GVHKIJ3G.js} +1 -1
  7. package/dist/{chunk-KGZGBCYS.js → chunk-JA4V7TJY.js} +135 -62
  8. package/dist/index.cjs +2 -7
  9. package/dist/index.d.ts +29 -14
  10. package/dist/index.js +4 -8
  11. package/ephemeral/dist/index.cjs +11 -0
  12. package/ephemeral/dist/index.js +9 -0
  13. package/ephemeral/package.json +16 -0
  14. package/ephemeral/src/index.ts +1 -0
  15. package/eslint-plugin/dist/index.cjs +156 -1
  16. package/eslint-plugin/dist/index.js +156 -1
  17. package/eslint-plugin/src/rules/index.ts +1 -0
  18. package/eslint-plugin/src/rules/lifespan.ts +204 -0
  19. package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +1 -65
  20. package/eslint-plugin/src/walk.ts +73 -0
  21. package/immortal/dist/index.cjs +100 -0
  22. package/immortal/dist/index.js +97 -0
  23. package/immortal/package.json +16 -0
  24. package/immortal/src/index.ts +2 -0
  25. package/immortal/src/molecule.ts +134 -0
  26. package/immortal/src/seek-state.ts +60 -0
  27. package/internal/dist/index.cjs +211 -194
  28. package/internal/dist/index.d.ts +30 -14
  29. package/internal/dist/index.js +210 -194
  30. package/internal/src/atom/dispose-atom.ts +4 -1
  31. package/internal/src/families/create-readonly-selector-family.ts +9 -9
  32. package/internal/src/families/create-regular-atom-family.ts +15 -20
  33. package/internal/src/families/create-writable-selector-family.ts +6 -7
  34. package/internal/src/families/find-in-store.ts +11 -5
  35. package/internal/src/families/index.ts +2 -0
  36. package/internal/src/families/init-family-member.ts +91 -0
  37. package/internal/src/families/seek-in-store.ts +106 -0
  38. package/internal/src/future.ts +6 -20
  39. package/internal/src/get-state/get-from-store.ts +2 -3
  40. package/internal/src/mutable/create-mutable-atom-family.ts +17 -23
  41. package/internal/src/mutable/create-mutable-atom.ts +3 -1
  42. package/internal/src/mutable/get-json-family.ts +2 -2
  43. package/internal/src/mutable/get-json-token.ts +27 -12
  44. package/internal/src/mutable/tracker-family.ts +14 -12
  45. package/internal/src/mutable/tracker.ts +2 -24
  46. package/internal/src/not-found-error.ts +11 -3
  47. package/internal/src/operation.ts +0 -1
  48. package/internal/src/selector/create-readonly-selector.ts +2 -2
  49. package/internal/src/selector/create-writable-selector.ts +2 -2
  50. package/internal/src/selector/dispose-selector.ts +40 -23
  51. package/internal/src/selector/register-selector.ts +8 -5
  52. package/internal/src/set-state/set-into-store.ts +2 -2
  53. package/internal/src/store/index.ts +0 -1
  54. package/internal/src/store/store.ts +18 -5
  55. package/internal/src/subscribe/recall-state.ts +3 -3
  56. package/internal/src/subscribe/subscribe-to-state.ts +18 -5
  57. package/internal/src/transaction/build-transaction.ts +7 -2
  58. package/introspection/dist/index.cjs +39 -65
  59. package/introspection/dist/index.js +39 -65
  60. package/introspection/src/attach-atom-index.ts +38 -48
  61. package/introspection/src/attach-introspection-states.ts +0 -1
  62. package/introspection/src/attach-selector-index.ts +45 -50
  63. package/introspection/src/attach-timeline-family.ts +2 -17
  64. package/json/dist/index.cjs +38 -4
  65. package/json/dist/index.js +40 -6
  66. package/json/src/select-json-family.ts +46 -7
  67. package/package.json +31 -11
  68. package/react/dist/index.cjs +1 -1
  69. package/react/dist/index.js +1 -1
  70. package/react/src/use-json.ts +1 -1
  71. package/react-devtools/dist/index.cjs +11 -10
  72. package/react-devtools/dist/index.js +2 -1
  73. package/react-devtools/src/StateIndex.tsx +2 -1
  74. package/react-devtools/src/TimelineIndex.tsx +2 -1
  75. package/react-devtools/src/TransactionIndex.tsx +7 -7
  76. package/realtime-client/dist/index.cjs +3 -3
  77. package/realtime-client/dist/index.js +3 -3
  78. package/realtime-client/src/pull-mutable-atom-family-member.ts +1 -1
  79. package/realtime-client/src/pull-mutable-atom.ts +1 -1
  80. package/realtime-client/src/sync-continuity.ts +1 -2
  81. package/realtime-react/dist/index.cjs +1 -1
  82. package/realtime-react/dist/index.js +1 -1
  83. package/realtime-server/dist/index.cjs +18 -17
  84. package/realtime-server/dist/index.js +7 -6
  85. package/realtime-server/src/realtime-continuity-synchronizer.ts +5 -3
  86. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -1
  87. package/realtime-server/src/realtime-mutable-provider.ts +1 -1
  88. package/realtime-testing/dist/index.cjs +6 -2
  89. package/realtime-testing/dist/index.js +8 -5
  90. package/realtime-testing/src/setup-realtime-test.tsx +5 -2
  91. package/src/atom.ts +10 -4
  92. package/src/index.ts +1 -2
  93. package/src/selector.ts +10 -4
  94. package/src/silo.ts +3 -3
  95. package/src/transaction.ts +5 -2
  96. package/src/validators.ts +0 -6
  97. package/internal/src/store/withdraw-new-family-member.ts +0 -69
  98. /package/{src → ephemeral/src}/find-state.ts +0 -0
  99. /package/src/{dispose.ts → dispose-state.ts} +0 -0
@@ -76,7 +76,10 @@ export const setupRealtimeTestServer = (
76
76
  options: TestSetupOptions,
77
77
  ): RealtimeTestServer => {
78
78
  ++testNumber
79
- const silo = new AtomIO.Silo(`SERVER-${testNumber}`, IMPLICIT.STORE)
79
+ const silo = new AtomIO.Silo(
80
+ { name: `SERVER-${testNumber}`, lifespan: `ephemeral` },
81
+ IMPLICIT.STORE,
82
+ )
80
83
 
81
84
  const httpServer = http.createServer((_, res) => res.end(`Hello World!`))
82
85
  const address = httpServer.listen(options.port).address()
@@ -139,7 +142,7 @@ export const setupRealtimeTestClient = (
139
142
  const socket: ClientSocket = io(`http://localhost:${port}/`, {
140
143
  auth: { token: `test`, username: `${name}-${testNumber}` },
141
144
  })
142
- const silo = new AtomIO.Silo(name, IMPLICIT.STORE)
145
+ const silo = new AtomIO.Silo({ name, lifespan: `ephemeral` }, IMPLICIT.STORE)
143
146
  for (const [key, value] of silo.store.valueMap.entries()) {
144
147
  if (Array.isArray(value)) {
145
148
  silo.store.valueMap.set(key, [...value])
package/src/atom.ts CHANGED
@@ -57,8 +57,11 @@ export type RegularAtomFamilyTokenWithCall<
57
57
  K extends Json.Serializable,
58
58
  > =
59
59
  & RegularAtomFamilyToken<T, K>
60
- & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
61
- ((key: K) => RegularAtomToken<T>)
60
+ & {
61
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
62
+ /* eslint-disable-next-line @typescript-eslint/prefer-function-type */
63
+ (key: K): RegularAtomToken<T>
64
+ }
62
65
  // biome-ignore format: intersection
63
66
  export type RegularAtomFamily<T, K extends Json.Serializable> =
64
67
  & RegularAtomFamilyToken<T, K>
@@ -100,8 +103,11 @@ export type MutableAtomFamilyTokenWithCall<
100
103
  K extends Json.Serializable,
101
104
  > =
102
105
  & MutableAtomFamilyToken<T, J, K>
103
- & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
104
- ((key: K) => MutableAtomToken<T, J>)
106
+ & {
107
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
108
+ /* eslint-disable-next-line @typescript-eslint/prefer-function-type */
109
+ (key: K): MutableAtomToken<T, J>
110
+ }
105
111
  // biome-ignore format: intersection
106
112
  export type MutableAtomFamily<
107
113
  T extends Transceiver<any>,
package/src/index.ts CHANGED
@@ -10,8 +10,7 @@ import type {
10
10
  } from "./selector"
11
11
 
12
12
  export * from "./atom"
13
- export * from "./dispose"
14
- export * from "./find-state"
13
+ export * from "./dispose-state"
15
14
  export * from "./get-state"
16
15
  export * from "./logger"
17
16
  export * from "./selector"
package/src/selector.ts CHANGED
@@ -53,8 +53,11 @@ export type WritableSelectorFamilyTokenWithCall<
53
53
  K extends Json.Serializable,
54
54
  > =
55
55
  & WritableSelectorFamilyToken<T, K>
56
- & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
57
- ((key: K) => WritableSelectorToken<T>)
56
+ & {
57
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
58
+ /* eslint-disable-next-line @typescript-eslint/prefer-function-type */
59
+ (key: K): WritableSelectorToken<T>
60
+ }
58
61
  // biome-ignore format: intersection
59
62
  export type WritableSelectorFamily<T, K extends Json.Serializable> =
60
63
  & WritableSelectorFamilyToken<T, K>
@@ -76,8 +79,11 @@ export type ReadonlySelectorFamilyTokenWithCall<
76
79
  K extends Json.Serializable,
77
80
  > =
78
81
  & ReadonlySelectorFamilyToken<T, K>
79
- & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
80
- ((key: K) => ReadonlySelectorToken<T>)
82
+ & {
83
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
84
+ /* eslint-disable-next-line @typescript-eslint/prefer-function-type */
85
+ (key: K): ReadonlySelectorToken<T>
86
+ }
81
87
  // biome-ignore format: intersection
82
88
  export type ReadonlySelectorFamily<T, K extends Json.Serializable> =
83
89
  & ((key: K) => ReadonlySelectorToken<T>)
package/src/silo.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { findState } from "atom.io/ephemeral"
1
2
  import type { Transceiver } from "atom.io/internal"
2
3
  import {
3
4
  createAtomFamily,
@@ -16,7 +17,6 @@ import type { Json } from "atom.io/json"
16
17
 
17
18
  import type {
18
19
  AtomToken,
19
- findState,
20
20
  getState,
21
21
  MutableAtomFamily,
22
22
  MutableAtomFamilyOptions,
@@ -50,8 +50,8 @@ export class Silo {
50
50
  public subscribe: typeof subscribe
51
51
  public undo: typeof undo
52
52
  public redo: typeof redo
53
- public constructor(name: string, fromStore: Store | null = null) {
54
- const s = new Store(name, fromStore)
53
+ public constructor(config: Store[`config`], fromStore: Store | null = null) {
54
+ const s = new Store(config, fromStore)
55
55
  function _atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>
56
56
  function _atom<T extends Transceiver<any>, J extends Json.Serializable>(
57
57
  options: MutableAtomOptions<T, J>,
@@ -1,3 +1,4 @@
1
+ import type { findState } from "atom.io/ephemeral"
1
2
  import type { EnvironmentData } from "atom.io/internal"
2
3
  import {
3
4
  actUponStore,
@@ -6,8 +7,8 @@ import {
6
7
  IMPLICIT,
7
8
  } from "atom.io/internal"
8
9
 
10
+ import type { seekState } from "../immortal/src/seek-state"
9
11
  import type {
10
- findState,
11
12
  Func,
12
13
  KeyedStateUpdate,
13
14
  ReadonlySelectorToken,
@@ -40,6 +41,7 @@ export type Transactors = Readonly<{
40
41
  newValue: New | ((oldValue: S) => New),
41
42
  ) => void
42
43
  find: typeof findState
44
+ seek: typeof seekState
43
45
  }>
44
46
  export type TransactorsWithRunAndEnv = Readonly<{
45
47
  get: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S
@@ -48,10 +50,11 @@ export type TransactorsWithRunAndEnv = Readonly<{
48
50
  newValue: New | ((oldValue: S) => New),
49
51
  ) => void
50
52
  find: typeof findState
53
+ seek: typeof seekState
51
54
  run: typeof runTransaction
52
55
  env: () => EnvironmentData
53
56
  }>
54
- export type ReadonlyTransactors = Pick<Transactors, `find` | `get`>
57
+ export type ReadonlyTransactors = Pick<Transactors, `find` | `get` | `seek`>
55
58
 
56
59
  export type Read<F extends Func> = (
57
60
  transactors: ReadonlyTransactors,
package/src/validators.ts CHANGED
@@ -1,19 +1,13 @@
1
1
  import type {
2
- MutableAtomFamily,
3
2
  MutableAtomFamilyToken,
4
3
  MutableAtomToken,
5
- ReadableFamily,
6
4
  ReadableFamilyToken,
7
5
  ReadableToken,
8
- ReadonlySelectorFamily,
9
6
  ReadonlySelectorFamilyToken,
10
7
  ReadonlySelectorToken,
11
- RegularAtomFamily,
12
8
  RegularAtomFamilyToken,
13
9
  RegularAtomToken,
14
- WritableFamily,
15
10
  WritableFamilyToken,
16
- WritableSelectorFamily,
17
11
  WritableSelectorFamilyToken,
18
12
  WritableSelectorToken,
19
13
  WritableToken,
@@ -1,69 +0,0 @@
1
- import type {
2
- ReadableToken,
3
- ReadonlySelectorToken,
4
- RegularAtomToken,
5
- WritableSelectorToken,
6
- WritableToken,
7
- } from "atom.io"
8
-
9
- import type {
10
- Atom,
11
- ReadableState,
12
- ReadonlySelector,
13
- Store,
14
- WritableSelector,
15
- WritableState,
16
- } from ".."
17
- import { newest, NotFoundError, withdraw } from ".."
18
-
19
- export function withdrawOrCreate<T>(
20
- token: RegularAtomToken<T>,
21
- store: Store,
22
- ): Atom<T>
23
- export function withdrawOrCreate<T>(
24
- token: WritableSelectorToken<T>,
25
- store: Store,
26
- ): WritableSelector<T>
27
- export function withdrawOrCreate<T>(
28
- token: ReadonlySelectorToken<T>,
29
- store: Store,
30
- ): ReadonlySelector<T>
31
- export function withdrawOrCreate<T>(
32
- token: WritableToken<T>,
33
- store: Store,
34
- ): WritableState<T>
35
- export function withdrawOrCreate<T>(
36
- token: ReadableToken<T>,
37
- store: Store,
38
- ): ReadableState<T>
39
- export function withdrawOrCreate<T>(
40
- token: ReadableToken<T>,
41
- store: Store,
42
- ): ReadableState<T> {
43
- try {
44
- const state = withdraw(token, store)
45
- return state
46
- } catch (notFoundError) {
47
- if (token.family) {
48
- store.logger.info(
49
- `👪`,
50
- token.type,
51
- token.key,
52
- `creating new family member in store "${store.config.name}"`,
53
- )
54
- const target = newest(store)
55
- const family = target.families.get(token.family.key)
56
- if (family) {
57
- const jsonSubKey = JSON.parse(token.family.subKey)
58
- family(jsonSubKey)
59
- const state = withdraw(token, store)
60
- return state
61
- }
62
- throw new NotFoundError(
63
- { key: token.family.key, type: `${token.type}_family` },
64
- store,
65
- )
66
- }
67
- throw notFoundError
68
- }
69
- }
File without changes
File without changes