atom.io 0.22.0 → 0.23.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 (82) hide show
  1. package/data/dist/index.cjs +17 -1
  2. package/data/dist/index.js +1 -1
  3. package/data/src/join.ts +30 -1
  4. package/dist/chunk-6MLFYN32.js +18 -0
  5. package/dist/{chunk-JA4V7TJY.js → chunk-7DT3PVS3.js} +18 -2
  6. package/dist/chunk-OAYGID5B.js +27 -0
  7. package/dist/index.cjs +2 -11
  8. package/dist/index.d.ts +51 -23
  9. package/dist/index.js +2 -11
  10. package/ephemeral/dist/index.d.ts +12 -0
  11. package/eslint-plugin/dist/index.cjs +0 -1
  12. package/eslint-plugin/dist/index.d.ts +73 -0
  13. package/eslint-plugin/dist/index.js +0 -1
  14. package/eslint-plugin/src/rules/lifespan.ts +0 -1
  15. package/immortal/dist/index.cjs +180 -20
  16. package/immortal/dist/index.d.ts +103 -0
  17. package/immortal/dist/index.js +134 -19
  18. package/immortal/src/index.ts +1 -0
  19. package/immortal/src/make-molecule.ts +222 -0
  20. package/immortal/src/molecule.ts +49 -16
  21. package/immortal/src/seek-state.ts +15 -2
  22. package/internal/dist/index.cjs +1119 -754
  23. package/internal/dist/index.d.ts +109 -12
  24. package/internal/dist/index.js +1098 -760
  25. package/internal/src/atom/create-regular-atom.ts +0 -2
  26. package/internal/src/atom/create-standalone-atom.ts +6 -2
  27. package/internal/src/atom/dispose-atom.ts +22 -2
  28. package/internal/src/families/create-readonly-selector-family.ts +7 -2
  29. package/internal/src/families/create-regular-atom-family.ts +6 -2
  30. package/internal/src/families/create-writable-selector-family.ts +7 -2
  31. package/internal/src/families/dispose-from-store.ts +22 -0
  32. package/internal/src/families/find-in-store.ts +0 -1
  33. package/internal/src/families/index.ts +1 -0
  34. package/internal/src/families/init-family-member.ts +22 -1
  35. package/internal/src/families/seek-in-store.ts +23 -6
  36. package/internal/src/ingest-updates/index.ts +1 -0
  37. package/internal/src/ingest-updates/ingest-creation-disposal.ts +104 -0
  38. package/internal/src/ingest-updates/ingest-transaction-update.ts +26 -4
  39. package/internal/src/mutable/create-mutable-atom-family.ts +6 -2
  40. package/internal/src/mutable/create-mutable-atom.ts +0 -2
  41. package/internal/src/mutable/get-json-token.ts +0 -1
  42. package/internal/src/mutable/tracker-family.ts +7 -7
  43. package/internal/src/not-found-error.ts +5 -0
  44. package/internal/src/selector/create-readonly-selector.ts +2 -3
  45. package/internal/src/selector/create-standalone-selector.ts +6 -2
  46. package/internal/src/selector/create-writable-selector.ts +2 -3
  47. package/internal/src/selector/dispose-selector.ts +32 -5
  48. package/internal/src/selector/register-selector.ts +2 -0
  49. package/internal/src/set-state/stow-update.ts +5 -1
  50. package/internal/src/store/deposit.ts +41 -7
  51. package/internal/src/store/store.ts +11 -0
  52. package/internal/src/store/withdraw.ts +28 -1
  53. package/internal/src/timeline/add-atom-to-timeline.ts +206 -182
  54. package/internal/src/timeline/create-timeline.ts +181 -60
  55. package/internal/src/timeline/time-travel.ts +20 -0
  56. package/internal/src/transaction/apply-transaction.ts +2 -12
  57. package/internal/src/transaction/build-transaction.ts +11 -2
  58. package/introspection/dist/index.cjs +2 -1
  59. package/introspection/dist/index.js +2 -1
  60. package/introspection/src/attach-timeline-family.ts +1 -0
  61. package/json/dist/index.cjs +3 -3
  62. package/json/dist/index.js +6 -5
  63. package/json/src/select-json-family.ts +3 -4
  64. package/package.json +8 -5
  65. package/react-devtools/dist/index.cjs +58 -47
  66. package/react-devtools/dist/index.js +60 -48
  67. package/react-devtools/src/TimelineIndex.tsx +15 -13
  68. package/react-devtools/src/Updates.tsx +41 -32
  69. package/realtime-server/dist/index.cjs +21 -10
  70. package/realtime-server/dist/index.d.ts +1 -1
  71. package/realtime-server/dist/index.js +21 -11
  72. package/realtime-server/src/realtime-server-stores/server-sync-store.ts +21 -11
  73. package/realtime-testing/dist/index.cjs +1 -0
  74. package/realtime-testing/dist/index.js +1 -1
  75. package/src/atom.ts +9 -3
  76. package/src/dispose-state.ts +3 -12
  77. package/src/index.ts +4 -0
  78. package/src/selector.ts +3 -3
  79. package/src/subscribe.ts +8 -4
  80. package/src/timeline.ts +18 -1
  81. package/src/transaction.ts +56 -4
  82. package/dist/chunk-BF4MVQF6.js +0 -44
package/src/index.ts CHANGED
@@ -23,6 +23,10 @@ export * from "./validators"
23
23
 
24
24
  export type Func = (...parameters: any[]) => any
25
25
 
26
+ export type Flat<R extends { [K in PropertyKey]: any }> = {
27
+ [K in keyof R]: R[K]
28
+ }
29
+
26
30
  export type RegularAtomToken<T> = {
27
31
  key: string
28
32
  type: `atom`
package/src/selector.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  import type { Json } from "atom.io/json"
8
8
 
9
9
  import type { ReadonlySelectorToken, WritableSelectorToken } from "."
10
- import type { Read, Write } from "./transaction"
10
+ import type { Read, StateCreation, StateDisposal, Write } from "./transaction"
11
11
 
12
12
  export type WritableSelectorOptions<T> = {
13
13
  key: string
@@ -63,7 +63,7 @@ export type WritableSelectorFamily<T, K extends Json.Serializable> =
63
63
  & WritableSelectorFamilyToken<T, K>
64
64
  & {
65
65
  (key: K): WritableSelectorToken<T>
66
- subject: Subject<WritableSelectorToken<T>>
66
+ subject: Subject<StateCreation<WritableSelectorToken<T>> | StateDisposal<WritableSelectorToken<T>>>
67
67
  install: (store: Store) => void
68
68
  }
69
69
 
@@ -90,7 +90,7 @@ export type ReadonlySelectorFamily<T, K extends Json.Serializable> =
90
90
  & {
91
91
  key: string
92
92
  type: `readonly_selector_family`
93
- subject: Subject<ReadonlySelectorToken<T>>
93
+ subject: Subject<StateCreation<ReadonlySelectorToken<T>> | StateDisposal<ReadonlySelectorToken<T>>>
94
94
  install: (store: Store) => void
95
95
  __T?: T
96
96
  __K?: K
package/src/subscribe.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
 
10
10
  import type {
11
11
  FamilyMetadata,
12
+ Flat,
12
13
  Func,
13
14
  ReadableToken,
14
15
  TimelineManageable,
@@ -19,10 +20,13 @@ import type {
19
20
  } from "."
20
21
 
21
22
  export type StateUpdate<T> = { newValue: T; oldValue: T }
22
- export type KeyedStateUpdate<T> = StateUpdate<T> & {
23
- key: string
24
- family?: FamilyMetadata
25
- }
23
+ export type KeyedStateUpdate<T> = Flat<
24
+ StateUpdate<T> & {
25
+ key: string
26
+ type: `atom_update` | `selector_update`
27
+ family?: FamilyMetadata
28
+ }
29
+ >
26
30
  export type UpdateHandler<T> = (update: StateUpdate<T>) => void
27
31
 
28
32
  export type TransactionUpdateHandler<F extends Func> = (
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,17 +1,28 @@
1
1
  import type { findState } from "atom.io/ephemeral"
2
- import type { EnvironmentData } from "atom.io/internal"
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"
3
9
  import {
4
10
  actUponStore,
5
11
  arbitrary,
6
12
  createTransaction,
7
13
  IMPLICIT,
8
14
  } from "atom.io/internal"
15
+ import type { Json } from "atom.io/json"
9
16
 
10
- import type { seekState } from "../immortal/src/seek-state"
11
17
  import type {
18
+ disposeState,
12
19
  Func,
13
20
  KeyedStateUpdate,
21
+ MutableAtomToken,
22
+ ReadableToken,
14
23
  ReadonlySelectorToken,
24
+ TokenType,
25
+ WritableSelectorToken,
15
26
  WritableToken,
16
27
  } from "."
17
28
 
@@ -21,11 +32,41 @@ export type TransactionToken<F extends Func> = {
21
32
  __F?: F
22
33
  }
23
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
+
24
60
  export type TransactionUpdateContent =
25
61
  | KeyedStateUpdate<unknown>
62
+ | MoleculeCreation<any>
63
+ | MoleculeDisposal<any>
64
+ | StateCreation<ReadableToken<unknown>>
65
+ | StateDisposal<ReadableToken<unknown>>
26
66
  | TransactionUpdate<Func>
27
67
 
28
68
  export type TransactionUpdate<F extends Func> = {
69
+ type: `transaction_update`
29
70
  key: string
30
71
  id: string
31
72
  epoch: number
@@ -35,13 +76,16 @@ export type TransactionUpdate<F extends Func> = {
35
76
  }
36
77
 
37
78
  export type Transactors = Readonly<{
38
- get: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S
79
+ get: <S>(state: ReadableToken<S>) => S
39
80
  set: <S, New extends S>(
40
81
  state: WritableToken<S>,
41
82
  newValue: New | ((oldValue: S) => New),
42
83
  ) => void
43
84
  find: typeof findState
44
85
  seek: typeof seekState
86
+ json: <T extends Transceiver<any>, J extends Json.Serializable>(
87
+ state: MutableAtomToken<T, J>,
88
+ ) => WritableSelectorToken<J>
45
89
  }>
46
90
  export type TransactorsWithRunAndEnv = Readonly<{
47
91
  get: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S
@@ -51,10 +95,18 @@ export type TransactorsWithRunAndEnv = Readonly<{
51
95
  ) => void
52
96
  find: typeof findState
53
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
54
103
  run: typeof runTransaction
55
104
  env: () => EnvironmentData
56
105
  }>
57
- export type ReadonlyTransactors = Pick<Transactors, `find` | `get` | `seek`>
106
+ export type ReadonlyTransactors = Pick<
107
+ Transactors,
108
+ `find` | `get` | `json` | `seek`
109
+ >
58
110
 
59
111
  export type Read<F extends Func> = (
60
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 };