atom.io 0.21.1 → 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 (92) hide show
  1. package/data/dist/index.cjs +136 -63
  2. package/data/dist/index.d.ts +6 -0
  3. package/data/dist/index.js +3 -3
  4. package/data/src/join.ts +135 -51
  5. package/data/src/struct-family.ts +2 -2
  6. package/dist/{chunk-RT43TVKP.js → chunk-GVHKIJ3G.js} +1 -1
  7. package/dist/{chunk-HITX3MO4.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 +186 -146
  28. package/internal/dist/index.d.ts +29 -13
  29. package/internal/dist/index.js +185 -146
  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/get-state/get-from-store.ts +2 -2
  39. package/internal/src/mutable/create-mutable-atom-family.ts +17 -23
  40. package/internal/src/mutable/create-mutable-atom.ts +3 -1
  41. package/internal/src/mutable/get-json-family.ts +2 -2
  42. package/internal/src/mutable/get-json-token.ts +27 -12
  43. package/internal/src/mutable/tracker-family.ts +14 -12
  44. package/internal/src/not-found-error.ts +11 -3
  45. package/internal/src/selector/create-readonly-selector.ts +2 -2
  46. package/internal/src/selector/create-writable-selector.ts +2 -2
  47. package/internal/src/selector/dispose-selector.ts +40 -23
  48. package/internal/src/selector/register-selector.ts +8 -5
  49. package/internal/src/set-state/set-into-store.ts +2 -2
  50. package/internal/src/store/index.ts +0 -1
  51. package/internal/src/store/store.ts +18 -5
  52. package/internal/src/subscribe/subscribe-to-state.ts +2 -2
  53. package/internal/src/transaction/build-transaction.ts +7 -2
  54. package/introspection/dist/index.cjs +38 -52
  55. package/introspection/dist/index.js +38 -52
  56. package/introspection/src/attach-atom-index.ts +38 -48
  57. package/introspection/src/attach-selector-index.ts +45 -50
  58. package/json/dist/index.cjs +38 -4
  59. package/json/dist/index.js +40 -6
  60. package/json/src/select-json-family.ts +46 -7
  61. package/package.json +30 -10
  62. package/react/dist/index.cjs +1 -1
  63. package/react/dist/index.js +1 -1
  64. package/react/src/use-json.ts +1 -1
  65. package/react-devtools/dist/index.cjs +11 -10
  66. package/react-devtools/dist/index.js +2 -1
  67. package/react-devtools/src/StateIndex.tsx +2 -1
  68. package/react-devtools/src/TimelineIndex.tsx +2 -1
  69. package/react-devtools/src/TransactionIndex.tsx +7 -7
  70. package/realtime-client/dist/index.cjs +3 -3
  71. package/realtime-client/dist/index.js +3 -3
  72. package/realtime-client/src/pull-mutable-atom-family-member.ts +1 -1
  73. package/realtime-client/src/pull-mutable-atom.ts +1 -1
  74. package/realtime-client/src/sync-continuity.ts +1 -2
  75. package/realtime-react/dist/index.cjs +1 -1
  76. package/realtime-react/dist/index.js +1 -1
  77. package/realtime-server/dist/index.cjs +18 -17
  78. package/realtime-server/dist/index.js +7 -6
  79. package/realtime-server/src/realtime-continuity-synchronizer.ts +5 -3
  80. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -1
  81. package/realtime-server/src/realtime-mutable-provider.ts +1 -1
  82. package/realtime-testing/dist/index.cjs +6 -2
  83. package/realtime-testing/dist/index.js +8 -5
  84. package/realtime-testing/src/setup-realtime-test.tsx +5 -2
  85. package/src/atom.ts +10 -4
  86. package/src/index.ts +1 -2
  87. package/src/selector.ts +10 -4
  88. package/src/silo.ts +3 -3
  89. package/src/transaction.ts +5 -2
  90. package/internal/src/store/withdraw-new-family-member.ts +0 -69
  91. /package/{src → ephemeral/src}/find-state.ts +0 -0
  92. /package/src/{dispose.ts → dispose-state.ts} +0 -0
@@ -0,0 +1,73 @@
1
+ import type * as ESTree from "estree"
2
+
3
+ export function walk(
4
+ node: ESTree.Node,
5
+ callback: (node: ESTree.Node, depth: number) => void,
6
+ depth = 0,
7
+ ): void {
8
+ callback(node, depth)
9
+
10
+ switch (node.type) {
11
+ case `FunctionDeclaration`:
12
+ case `FunctionExpression`:
13
+ case `ArrowFunctionExpression`:
14
+ for (const param of node.params) {
15
+ walk(param, callback, depth + 1)
16
+ }
17
+ walk(node.body, callback, depth + 1)
18
+ break
19
+ case `BlockStatement`:
20
+ for (const statement of node.body) {
21
+ walk(statement, callback, depth + 1)
22
+ }
23
+ break
24
+ case `IfStatement`:
25
+ walk(node.test, callback, depth)
26
+ walk(node.consequent, callback, depth)
27
+ if (node.alternate) {
28
+ walk(node.alternate, callback, depth)
29
+ }
30
+ break
31
+ case `SwitchStatement`:
32
+ walk(node.discriminant, callback, depth + 1)
33
+ for (const caseOrDefault of node.cases) {
34
+ walk(caseOrDefault, callback, depth)
35
+ }
36
+ break
37
+ case `ReturnStatement`:
38
+ if (node.argument) {
39
+ walk(node.argument, callback, depth)
40
+ }
41
+ break
42
+ case `SwitchCase`:
43
+ if (node.test) {
44
+ walk(node.test, callback, depth)
45
+ }
46
+ for (const statement of node.consequent) {
47
+ walk(statement, callback, depth)
48
+ }
49
+ break
50
+ case `VariableDeclaration`:
51
+ for (const declaration of node.declarations) {
52
+ walk(declaration, callback, depth)
53
+ if (declaration.init) {
54
+ walk(declaration.init, callback, depth)
55
+ }
56
+ }
57
+ break
58
+ case `BinaryExpression`:
59
+ walk(node.left, callback, depth)
60
+ walk(node.right, callback, depth)
61
+ break
62
+ case `MemberExpression`:
63
+ walk(node.object, callback, depth)
64
+ walk(node.property, callback, depth)
65
+ break
66
+ case `CallExpression`:
67
+ walk(node.callee, callback, depth)
68
+ for (const argument of node.arguments) {
69
+ walk(argument, callback, depth)
70
+ }
71
+ break
72
+ }
73
+ }
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+
3
+ var atom_io = require('atom.io');
4
+ var data = require('atom.io/data');
5
+ var internal = require('atom.io/internal');
6
+ var json = require('atom.io/json');
7
+
8
+ // immortal/src/molecule.ts
9
+ var Molecule = class _Molecule {
10
+ constructor(key, above = [], store = internal.IMPLICIT.STORE) {
11
+ this.key = key;
12
+ this.above = above;
13
+ this.store = store;
14
+ this.below = [];
15
+ this.tokens = [];
16
+ this.joins = [];
17
+ this.dispose = this[Symbol.dispose];
18
+ store.molecules.set(json.stringifyJson(key), this);
19
+ for (const parent of above) {
20
+ parent.below.push(this);
21
+ }
22
+ }
23
+ bond(token) {
24
+ const state = internal.initFamilyMember(token, this.key, this.store);
25
+ if (token.type === `mutable_atom_family`) {
26
+ const jsonFamily = internal.getJsonFamily(token, this.store);
27
+ const jsonState = internal.initFamilyMember(jsonFamily, this.key, this.store);
28
+ this.tokens.push(jsonState);
29
+ }
30
+ this.tokens.push(state);
31
+ return state;
32
+ }
33
+ spawn(key) {
34
+ const child = new _Molecule(key, [this], this.store);
35
+ return child;
36
+ }
37
+ with(molecule) {
38
+ return (key) => {
39
+ const child = new _Molecule(key, [this, molecule], this.store);
40
+ return child;
41
+ };
42
+ }
43
+ detach(child) {
44
+ const childIndex = this.below.indexOf(child);
45
+ if (childIndex !== void 0) {
46
+ this.below.splice(childIndex, 1);
47
+ }
48
+ const parentIndex = child.above.indexOf(this);
49
+ if (parentIndex !== void 0) {
50
+ child.above.splice(parentIndex, 1);
51
+ }
52
+ }
53
+ claim(child) {
54
+ if (child === this) {
55
+ return;
56
+ }
57
+ for (const parent of child.above) {
58
+ parent.detach(child);
59
+ }
60
+ this.below.push(child);
61
+ child.above.push(this);
62
+ }
63
+ clear() {
64
+ var _a;
65
+ while (this.below.length > 0) {
66
+ (_a = this.below.pop()) == null ? void 0 : _a.dispose();
67
+ }
68
+ while (this.tokens.length > 0) {
69
+ const token = this.tokens.pop();
70
+ if (token) {
71
+ atom_io.disposeState(token, this.store);
72
+ }
73
+ }
74
+ while (this.joins.length > 0) {
75
+ const join = this.joins.pop();
76
+ if (join) {
77
+ join.molecules.delete(json.stringifyJson(this.key));
78
+ }
79
+ }
80
+ }
81
+ join(token) {
82
+ const join = data.getJoin(token, this.store);
83
+ join.molecules.set(json.stringifyJson(this.key), this);
84
+ this.joins.push(join);
85
+ }
86
+ [Symbol.dispose]() {
87
+ this.clear();
88
+ this.store.molecules.delete(json.stringifyJson(this.key));
89
+ for (const parent of this.above) {
90
+ parent.detach(this);
91
+ }
92
+ }
93
+ };
94
+ function seekState(token, key) {
95
+ const state = internal.seekInStore(token, key, internal.IMPLICIT.STORE);
96
+ return state;
97
+ }
98
+
99
+ exports.Molecule = Molecule;
100
+ exports.seekState = seekState;
@@ -0,0 +1,97 @@
1
+ import '../../dist/chunk-F2X4B4VY.js';
2
+ import { disposeState } from 'atom.io';
3
+ import { getJoin } from 'atom.io/data';
4
+ import { IMPLICIT, initFamilyMember, getJsonFamily, seekInStore } from 'atom.io/internal';
5
+ import { stringifyJson } from 'atom.io/json';
6
+
7
+ var Molecule = class _Molecule {
8
+ constructor(key, above = [], store = IMPLICIT.STORE) {
9
+ this.key = key;
10
+ this.above = above;
11
+ this.store = store;
12
+ this.below = [];
13
+ this.tokens = [];
14
+ this.joins = [];
15
+ this.dispose = this[Symbol.dispose];
16
+ store.molecules.set(stringifyJson(key), this);
17
+ for (const parent of above) {
18
+ parent.below.push(this);
19
+ }
20
+ }
21
+ bond(token) {
22
+ const state = initFamilyMember(token, this.key, this.store);
23
+ if (token.type === `mutable_atom_family`) {
24
+ const jsonFamily = getJsonFamily(token, this.store);
25
+ const jsonState = initFamilyMember(jsonFamily, this.key, this.store);
26
+ this.tokens.push(jsonState);
27
+ }
28
+ this.tokens.push(state);
29
+ return state;
30
+ }
31
+ spawn(key) {
32
+ const child = new _Molecule(key, [this], this.store);
33
+ return child;
34
+ }
35
+ with(molecule) {
36
+ return (key) => {
37
+ const child = new _Molecule(key, [this, molecule], this.store);
38
+ return child;
39
+ };
40
+ }
41
+ detach(child) {
42
+ const childIndex = this.below.indexOf(child);
43
+ if (childIndex !== void 0) {
44
+ this.below.splice(childIndex, 1);
45
+ }
46
+ const parentIndex = child.above.indexOf(this);
47
+ if (parentIndex !== void 0) {
48
+ child.above.splice(parentIndex, 1);
49
+ }
50
+ }
51
+ claim(child) {
52
+ if (child === this) {
53
+ return;
54
+ }
55
+ for (const parent of child.above) {
56
+ parent.detach(child);
57
+ }
58
+ this.below.push(child);
59
+ child.above.push(this);
60
+ }
61
+ clear() {
62
+ var _a;
63
+ while (this.below.length > 0) {
64
+ (_a = this.below.pop()) == null ? void 0 : _a.dispose();
65
+ }
66
+ while (this.tokens.length > 0) {
67
+ const token = this.tokens.pop();
68
+ if (token) {
69
+ disposeState(token, this.store);
70
+ }
71
+ }
72
+ while (this.joins.length > 0) {
73
+ const join = this.joins.pop();
74
+ if (join) {
75
+ join.molecules.delete(stringifyJson(this.key));
76
+ }
77
+ }
78
+ }
79
+ join(token) {
80
+ const join = getJoin(token, this.store);
81
+ join.molecules.set(stringifyJson(this.key), this);
82
+ this.joins.push(join);
83
+ }
84
+ [Symbol.dispose]() {
85
+ this.clear();
86
+ this.store.molecules.delete(stringifyJson(this.key));
87
+ for (const parent of this.above) {
88
+ parent.detach(this);
89
+ }
90
+ }
91
+ };
92
+ function seekState(token, key) {
93
+ const state = seekInStore(token, key, IMPLICIT.STORE);
94
+ return state;
95
+ }
96
+
97
+ export { Molecule, seekState };
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "atom.io-immortal",
3
+ "type": "module",
4
+ "private": true,
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "browser": "./dist/index.js",
12
+ "require": "./dist/index.cjs",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./molecule"
2
+ export * from "./seek-state"
@@ -0,0 +1,134 @@
1
+ import type {
2
+ MutableAtomFamilyToken,
3
+ MutableAtomToken,
4
+ ReadableFamilyToken,
5
+ ReadableToken,
6
+ ReadonlySelectorFamilyToken,
7
+ ReadonlySelectorToken,
8
+ RegularAtomFamilyToken,
9
+ RegularAtomToken,
10
+ WritableFamilyToken,
11
+ WritableSelectorFamilyToken,
12
+ WritableSelectorToken,
13
+ WritableToken,
14
+ } from "atom.io"
15
+ import { disposeState } from "atom.io"
16
+ import type { Join, JoinToken } from "atom.io/data"
17
+ import { getJoin } from "atom.io/data"
18
+ import type { Store, Transceiver } from "atom.io/internal"
19
+ import { getJsonFamily, IMPLICIT, initFamilyMember } from "atom.io/internal"
20
+ import { type Json, stringifyJson } from "atom.io/json"
21
+
22
+ export class Molecule<Key extends Json.Serializable> {
23
+ public readonly below: Molecule<any>[] = []
24
+ public readonly tokens: ReadableToken<any>[] = []
25
+ public readonly joins: Join<any, any, any, any>[] = []
26
+ public constructor(
27
+ public readonly key: Key,
28
+ public readonly above: Molecule<any>[] = [],
29
+ public readonly store: Store = IMPLICIT.STORE,
30
+ ) {
31
+ store.molecules.set(stringifyJson(key), this)
32
+ for (const parent of above) {
33
+ parent.below.push(this)
34
+ }
35
+ }
36
+
37
+ public bond<
38
+ T extends Transceiver<any>,
39
+ J extends Json.Serializable,
40
+ K extends string,
41
+ >(token: MutableAtomFamilyToken<T, J, K>): MutableAtomToken<T, J>
42
+ public bond<T, K extends Key>(
43
+ token: RegularAtomFamilyToken<T, K>,
44
+ ): RegularAtomToken<T>
45
+ public bond<T, K extends Json.Serializable>(
46
+ token: WritableSelectorFamilyToken<T, K>,
47
+ ): WritableSelectorToken<T>
48
+ public bond<T, K extends Json.Serializable>(
49
+ token: ReadonlySelectorFamilyToken<T, K>,
50
+ ): ReadonlySelectorToken<T>
51
+ public bond<T, K extends Json.Serializable>(
52
+ token: WritableFamilyToken<T, K>,
53
+ ): WritableToken<T>
54
+ public bond<T, K extends Json.Serializable>(
55
+ token: ReadableFamilyToken<T, K>,
56
+ ): ReadableToken<T>
57
+ public bond(token: ReadableFamilyToken<any, any>): ReadableToken<any> {
58
+ const state = initFamilyMember(token, this.key, this.store)
59
+ if (token.type === `mutable_atom_family`) {
60
+ const jsonFamily = getJsonFamily(token, this.store)
61
+ const jsonState = initFamilyMember(jsonFamily, this.key, this.store)
62
+ this.tokens.push(jsonState)
63
+ }
64
+ this.tokens.push(state)
65
+ return state
66
+ }
67
+
68
+ public spawn<K extends Json.Serializable>(key: K): Molecule<K> {
69
+ const child = new Molecule(key, [this], this.store)
70
+ return child
71
+ }
72
+
73
+ public with(molecule: Molecule<any>): (key: string) => Molecule<any> {
74
+ return (key) => {
75
+ const child = new Molecule(key, [this, molecule], this.store)
76
+ return child
77
+ }
78
+ }
79
+
80
+ public detach(child: Molecule<any>): void {
81
+ const childIndex = this.below.indexOf(child)
82
+ if (childIndex !== undefined) {
83
+ this.below.splice(childIndex, 1)
84
+ }
85
+ const parentIndex = child.above.indexOf(this)
86
+ if (parentIndex !== undefined) {
87
+ child.above.splice(parentIndex, 1)
88
+ }
89
+ }
90
+
91
+ public claim(child: Molecule<any>): void {
92
+ if (child === this) {
93
+ return
94
+ }
95
+ for (const parent of child.above) {
96
+ parent.detach(child)
97
+ }
98
+ this.below.push(child)
99
+ child.above.push(this)
100
+ }
101
+
102
+ public clear(): void {
103
+ while (this.below.length > 0) {
104
+ this.below.pop()?.dispose()
105
+ }
106
+ while (this.tokens.length > 0) {
107
+ const token = this.tokens.pop()
108
+ if (token) {
109
+ disposeState(token, this.store)
110
+ }
111
+ }
112
+ while (this.joins.length > 0) {
113
+ const join = this.joins.pop()
114
+ if (join) {
115
+ join.molecules.delete(stringifyJson(this.key))
116
+ }
117
+ }
118
+ }
119
+
120
+ public join(token: JoinToken<any, any, any, any>): void {
121
+ const join = getJoin(token, this.store)
122
+ join.molecules.set(stringifyJson(this.key), this)
123
+ this.joins.push(join)
124
+ }
125
+
126
+ private [Symbol.dispose](): void {
127
+ this.clear()
128
+ this.store.molecules.delete(stringifyJson(this.key))
129
+ for (const parent of this.above) {
130
+ parent.detach(this)
131
+ }
132
+ }
133
+ public dispose = this[Symbol.dispose]
134
+ }
@@ -0,0 +1,60 @@
1
+ import type {
2
+ MutableAtomFamilyToken,
3
+ MutableAtomToken,
4
+ ReadableFamilyToken,
5
+ ReadableToken,
6
+ ReadonlySelectorFamilyToken,
7
+ ReadonlySelectorToken,
8
+ RegularAtomFamilyToken,
9
+ RegularAtomToken,
10
+ WritableFamilyToken,
11
+ WritableSelectorFamilyToken,
12
+ WritableSelectorToken,
13
+ WritableToken,
14
+ } from "atom.io"
15
+ import type { Transceiver } from "atom.io/internal"
16
+ import { IMPLICIT, seekInStore } from "atom.io/internal"
17
+ import type { Json } from "atom.io/json"
18
+
19
+ export function seekState<
20
+ T extends Transceiver<any>,
21
+ J extends Json.Serializable,
22
+ K extends Json.Serializable,
23
+ Key extends K,
24
+ >(
25
+ token: MutableAtomFamilyToken<T, J, K>,
26
+ key: Key,
27
+ ): MutableAtomToken<T, J> | undefined
28
+
29
+ export function seekState<T, K extends Json.Serializable, Key extends K>(
30
+ token: RegularAtomFamilyToken<T, K>,
31
+ key: Key,
32
+ ): RegularAtomToken<T> | undefined
33
+
34
+ export function seekState<T, K extends Json.Serializable, Key extends K>(
35
+ token: WritableSelectorFamilyToken<T, K>,
36
+ key: Key,
37
+ ): WritableSelectorToken<T> | undefined
38
+
39
+ export function seekState<T, K extends Json.Serializable, Key extends K>(
40
+ token: ReadonlySelectorFamilyToken<T, K>,
41
+ key: Key,
42
+ ): ReadonlySelectorToken<T> | undefined
43
+
44
+ export function seekState<T, K extends Json.Serializable, Key extends K>(
45
+ token: WritableFamilyToken<T, K>,
46
+ key: Key,
47
+ ): WritableToken<T> | undefined
48
+
49
+ export function seekState<T, K extends Json.Serializable, Key extends K>(
50
+ token: ReadableFamilyToken<T, K>,
51
+ key: Key,
52
+ ): ReadableToken<T> | undefined
53
+
54
+ export function seekState(
55
+ token: ReadableFamilyToken<any, any>,
56
+ key: Json.Serializable,
57
+ ): ReadableToken<any> | undefined {
58
+ const state = seekInStore(token, key, IMPLICIT.STORE)
59
+ return state
60
+ }