atom.io 0.21.1 → 0.23.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 (116) hide show
  1. package/data/dist/index.cjs +152 -63
  2. package/data/dist/index.d.ts +6 -0
  3. package/data/dist/index.js +3 -3
  4. package/data/src/join.ts +164 -51
  5. package/data/src/struct-family.ts +2 -2
  6. package/dist/chunk-6MLFYN32.js +18 -0
  7. package/dist/{chunk-HITX3MO4.js → chunk-7DT3PVS3.js} +151 -62
  8. package/dist/{chunk-RT43TVKP.js → chunk-GVHKIJ3G.js} +1 -1
  9. package/dist/chunk-OAYGID5B.js +27 -0
  10. package/dist/index.cjs +4 -18
  11. package/dist/index.d.ts +71 -28
  12. package/dist/index.js +6 -19
  13. package/ephemeral/dist/index.cjs +11 -0
  14. package/ephemeral/dist/index.js +9 -0
  15. package/ephemeral/package.json +16 -0
  16. package/ephemeral/src/index.ts +1 -0
  17. package/eslint-plugin/dist/index.cjs +155 -1
  18. package/eslint-plugin/dist/index.js +155 -1
  19. package/eslint-plugin/src/rules/index.ts +1 -0
  20. package/eslint-plugin/src/rules/lifespan.ts +203 -0
  21. package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +1 -65
  22. package/eslint-plugin/src/walk.ts +73 -0
  23. package/immortal/dist/index.cjs +260 -0
  24. package/immortal/dist/index.js +212 -0
  25. package/immortal/package.json +16 -0
  26. package/immortal/src/index.ts +3 -0
  27. package/immortal/src/make-molecule.ts +222 -0
  28. package/immortal/src/molecule.ts +167 -0
  29. package/immortal/src/seek-state.ts +73 -0
  30. package/internal/dist/index.cjs +1242 -837
  31. package/internal/dist/index.d.ts +135 -22
  32. package/internal/dist/index.js +1215 -838
  33. package/internal/src/atom/create-regular-atom.ts +0 -2
  34. package/internal/src/atom/create-standalone-atom.ts +6 -2
  35. package/internal/src/atom/dispose-atom.ts +26 -3
  36. package/internal/src/families/create-readonly-selector-family.ts +15 -10
  37. package/internal/src/families/create-regular-atom-family.ts +20 -21
  38. package/internal/src/families/create-writable-selector-family.ts +13 -9
  39. package/{src/dispose.ts → internal/src/families/dispose-from-store.ts} +7 -4
  40. package/internal/src/families/find-in-store.ts +11 -6
  41. package/internal/src/families/index.ts +3 -0
  42. package/internal/src/families/init-family-member.ts +112 -0
  43. package/internal/src/families/seek-in-store.ts +123 -0
  44. package/internal/src/get-state/get-from-store.ts +2 -2
  45. package/internal/src/ingest-updates/index.ts +1 -0
  46. package/internal/src/ingest-updates/ingest-creation-disposal.ts +104 -0
  47. package/internal/src/ingest-updates/ingest-transaction-update.ts +26 -4
  48. package/internal/src/mutable/create-mutable-atom-family.ts +22 -24
  49. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  50. package/internal/src/mutable/get-json-family.ts +2 -2
  51. package/internal/src/mutable/get-json-token.ts +26 -12
  52. package/internal/src/mutable/tracker-family.ts +21 -19
  53. package/internal/src/not-found-error.ts +16 -3
  54. package/internal/src/selector/create-readonly-selector.ts +2 -3
  55. package/internal/src/selector/create-standalone-selector.ts +6 -2
  56. package/internal/src/selector/create-writable-selector.ts +2 -3
  57. package/internal/src/selector/dispose-selector.ts +68 -24
  58. package/internal/src/selector/register-selector.ts +10 -5
  59. package/internal/src/set-state/set-into-store.ts +2 -2
  60. package/internal/src/set-state/stow-update.ts +5 -1
  61. package/internal/src/store/deposit.ts +41 -7
  62. package/internal/src/store/index.ts +0 -1
  63. package/internal/src/store/store.ts +29 -5
  64. package/internal/src/store/withdraw.ts +28 -1
  65. package/internal/src/subscribe/subscribe-to-state.ts +2 -2
  66. package/internal/src/timeline/add-atom-to-timeline.ts +206 -182
  67. package/internal/src/timeline/create-timeline.ts +181 -60
  68. package/internal/src/timeline/time-travel.ts +20 -0
  69. package/internal/src/transaction/apply-transaction.ts +2 -12
  70. package/internal/src/transaction/build-transaction.ts +16 -2
  71. package/introspection/dist/index.cjs +40 -53
  72. package/introspection/dist/index.js +40 -53
  73. package/introspection/src/attach-atom-index.ts +38 -48
  74. package/introspection/src/attach-selector-index.ts +45 -50
  75. package/introspection/src/attach-timeline-family.ts +1 -0
  76. package/json/dist/index.cjs +40 -6
  77. package/json/dist/index.js +44 -9
  78. package/json/src/select-json-family.ts +47 -9
  79. package/package.json +30 -10
  80. package/react/dist/index.cjs +1 -1
  81. package/react/dist/index.js +1 -1
  82. package/react/src/use-json.ts +1 -1
  83. package/react-devtools/dist/index.cjs +69 -57
  84. package/react-devtools/dist/index.js +62 -49
  85. package/react-devtools/src/StateIndex.tsx +2 -1
  86. package/react-devtools/src/TimelineIndex.tsx +17 -14
  87. package/react-devtools/src/TransactionIndex.tsx +7 -7
  88. package/react-devtools/src/Updates.tsx +41 -32
  89. package/realtime-client/dist/index.cjs +3 -3
  90. package/realtime-client/dist/index.js +3 -3
  91. package/realtime-client/src/pull-mutable-atom-family-member.ts +1 -1
  92. package/realtime-client/src/pull-mutable-atom.ts +1 -1
  93. package/realtime-client/src/sync-continuity.ts +1 -2
  94. package/realtime-react/dist/index.cjs +1 -1
  95. package/realtime-react/dist/index.js +1 -1
  96. package/realtime-server/dist/index.cjs +39 -27
  97. package/realtime-server/dist/index.d.ts +1 -1
  98. package/realtime-server/dist/index.js +27 -16
  99. package/realtime-server/src/realtime-continuity-synchronizer.ts +5 -3
  100. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -1
  101. package/realtime-server/src/realtime-mutable-provider.ts +1 -1
  102. package/realtime-server/src/realtime-server-stores/server-sync-store.ts +21 -11
  103. package/realtime-testing/dist/index.cjs +7 -2
  104. package/realtime-testing/dist/index.js +8 -5
  105. package/realtime-testing/src/setup-realtime-test.tsx +5 -2
  106. package/src/atom.ts +19 -7
  107. package/src/dispose-state.ts +10 -0
  108. package/src/index.ts +5 -2
  109. package/src/selector.ts +13 -7
  110. package/src/silo.ts +3 -3
  111. package/src/subscribe.ts +8 -4
  112. package/src/timeline.ts +18 -1
  113. package/src/transaction.ts +59 -4
  114. package/dist/chunk-BF4MVQF6.js +0 -44
  115. package/internal/src/store/withdraw-new-family-member.ts +0 -69
  116. /package/{src → ephemeral/src}/find-state.ts +0 -0
package/src/timeline.ts CHANGED
@@ -1,7 +1,12 @@
1
+ import type { MoleculeFamilyToken } from "atom.io/immortal"
1
2
  import type {
2
3
  Timeline,
3
4
  TimelineAtomUpdate,
5
+ TimelineMoleculeCreation,
6
+ TimelineMoleculeDisposal,
4
7
  TimelineSelectorUpdate,
8
+ TimelineStateCreation,
9
+ TimelineStateDisposal,
5
10
  TimelineTransactionUpdate,
6
11
  } from "atom.io/internal"
7
12
  import { createTimeline, IMPLICIT, timeTravel } from "atom.io/internal"
@@ -9,6 +14,14 @@ import { createTimeline, IMPLICIT, timeTravel } from "atom.io/internal"
9
14
  import type { AtomFamilyToken, AtomToken } from "."
10
15
 
11
16
  export type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>
17
+ export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
18
+ any,
19
+ any
20
+ >
21
+ ? AtomToken<any>
22
+ : M extends AtomToken<any>
23
+ ? M
24
+ : never
12
25
 
13
26
  export type TimelineToken<M> = {
14
27
  key: string
@@ -18,7 +31,7 @@ export type TimelineToken<M> = {
18
31
 
19
32
  export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
20
33
  key: string
21
- atoms: ManagedAtom[]
34
+ scope: (ManagedAtom | MoleculeFamilyToken<any, any, any>)[]
22
35
  shouldCapture?: (
23
36
  update: TimelineUpdate<ManagedAtom>,
24
37
  timeline: Timeline<TimelineManageable>,
@@ -27,7 +40,11 @@ export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
27
40
 
28
41
  export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
29
42
  | TimelineAtomUpdate<ManagedAtom>
43
+ | TimelineMoleculeCreation<any>
44
+ | TimelineMoleculeDisposal<any>
30
45
  | TimelineSelectorUpdate<ManagedAtom>
46
+ | TimelineStateCreation<AtomOnly<ManagedAtom>>
47
+ | TimelineStateDisposal<AtomOnly<ManagedAtom>>
31
48
  | TimelineTransactionUpdate
32
49
 
33
50
  export const timeline = <ManagedAtom extends TimelineManageable>(
@@ -1,16 +1,28 @@
1
- import type { EnvironmentData } from "atom.io/internal"
1
+ import type { findState } from "atom.io/ephemeral"
2
+ import type {
3
+ makeMolecule,
4
+ MoleculeFamilyToken,
5
+ MoleculeToken,
6
+ seekState,
7
+ } from "atom.io/immortal"
8
+ import type { EnvironmentData, Transceiver } from "atom.io/internal"
2
9
  import {
3
10
  actUponStore,
4
11
  arbitrary,
5
12
  createTransaction,
6
13
  IMPLICIT,
7
14
  } from "atom.io/internal"
15
+ import type { Json } from "atom.io/json"
8
16
 
9
17
  import type {
10
- findState,
18
+ disposeState,
11
19
  Func,
12
20
  KeyedStateUpdate,
21
+ MutableAtomToken,
22
+ ReadableToken,
13
23
  ReadonlySelectorToken,
24
+ TokenType,
25
+ WritableSelectorToken,
14
26
  WritableToken,
15
27
  } from "."
16
28
 
@@ -20,11 +32,41 @@ export type TransactionToken<F extends Func> = {
20
32
  __F?: F
21
33
  }
22
34
 
35
+ export type StateCreation<Token extends ReadableToken<any>> = {
36
+ type: `state_creation`
37
+ token: Token
38
+ }
39
+ export type StateDisposal<Token extends ReadableToken<any>> = {
40
+ type: `state_disposal`
41
+ token: Token
42
+ value?: TokenType<Token>
43
+ }
44
+
45
+ export type MoleculeCreation<Key extends Json.Serializable> = {
46
+ type: `molecule_creation`
47
+ token: MoleculeToken<Key, any, any>
48
+ family: MoleculeFamilyToken<Key, any, any>
49
+ context: MoleculeToken<any, any, any>[]
50
+ params: any[]
51
+ }
52
+ export type MoleculeDisposal<Key extends Json.Serializable> = {
53
+ type: `molecule_disposal`
54
+ token: MoleculeToken<Key, any, any>
55
+ family: MoleculeFamilyToken<any, any, any>
56
+ context: MoleculeToken<any, any, any>[]
57
+ familyKeys: string[]
58
+ }
59
+
23
60
  export type TransactionUpdateContent =
24
61
  | KeyedStateUpdate<unknown>
62
+ | MoleculeCreation<any>
63
+ | MoleculeDisposal<any>
64
+ | StateCreation<ReadableToken<unknown>>
65
+ | StateDisposal<ReadableToken<unknown>>
25
66
  | TransactionUpdate<Func>
26
67
 
27
68
  export type TransactionUpdate<F extends Func> = {
69
+ type: `transaction_update`
28
70
  key: string
29
71
  id: string
30
72
  epoch: number
@@ -34,12 +76,16 @@ export type TransactionUpdate<F extends Func> = {
34
76
  }
35
77
 
36
78
  export type Transactors = Readonly<{
37
- get: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S
79
+ get: <S>(state: ReadableToken<S>) => S
38
80
  set: <S, New extends S>(
39
81
  state: WritableToken<S>,
40
82
  newValue: New | ((oldValue: S) => New),
41
83
  ) => void
42
84
  find: typeof findState
85
+ seek: typeof seekState
86
+ json: <T extends Transceiver<any>, J extends Json.Serializable>(
87
+ state: MutableAtomToken<T, J>,
88
+ ) => WritableSelectorToken<J>
43
89
  }>
44
90
  export type TransactorsWithRunAndEnv = Readonly<{
45
91
  get: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S
@@ -48,10 +94,19 @@ export type TransactorsWithRunAndEnv = Readonly<{
48
94
  newValue: New | ((oldValue: S) => New),
49
95
  ) => void
50
96
  find: typeof findState
97
+ seek: typeof seekState
98
+ json: <T extends Transceiver<any>, J extends Json.Serializable>(
99
+ state: MutableAtomToken<T, J>,
100
+ ) => WritableSelectorToken<J>
101
+ make: typeof makeMolecule
102
+ dispose: typeof disposeState
51
103
  run: typeof runTransaction
52
104
  env: () => EnvironmentData
53
105
  }>
54
- export type ReadonlyTransactors = Pick<Transactors, `find` | `get`>
106
+ export type ReadonlyTransactors = Pick<
107
+ Transactors,
108
+ `find` | `get` | `json` | `seek`
109
+ >
55
110
 
56
111
  export type Read<F extends Func> = (
57
112
  transactors: ReadonlyTransactors,
@@ -1,44 +0,0 @@
1
- // ../anvl/src/json/json-interface.ts
2
- var stringSetJsonInterface = {
3
- toJson: (stringSet) => Array.from(stringSet),
4
- fromJson: (json) => new Set(json)
5
- };
6
-
7
- // ../anvl/src/json/index.ts
8
- var parseJson = (str) => JSON.parse(str);
9
- var stringifyJson = (json) => JSON.stringify(json);
10
- var JSON_TYPE_NAMES = [
11
- `array`,
12
- `boolean`,
13
- `null`,
14
- `number`,
15
- `object`,
16
- `string`
17
- ];
18
- var JSON_DEFAULTS = {
19
- array: [],
20
- boolean: false,
21
- null: null,
22
- number: 0,
23
- object: {},
24
- string: ``
25
- };
26
-
27
- // ../anvl/src/primitive/index.ts
28
- var isString = (input) => {
29
- return typeof input === `string`;
30
- };
31
- var isNumber = (input) => {
32
- return typeof input === `number`;
33
- };
34
- var isBoolean = (input) => {
35
- return typeof input === `boolean`;
36
- };
37
- var isNull = (input) => {
38
- return input === null;
39
- };
40
- var isPrimitive = (input) => {
41
- return isString(input) || isNumber(input) || isBoolean(input) || isNull(input);
42
- };
43
-
44
- export { JSON_DEFAULTS, JSON_TYPE_NAMES, isBoolean, isNull, isNumber, isPrimitive, isString, parseJson, stringSetJsonInterface, stringifyJson };
@@ -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