atom.io 0.6.8 → 0.6.9

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 (130) hide show
  1. package/dist/index.d.mts +226 -258
  2. package/dist/index.d.ts +226 -258
  3. package/dist/index.js +28 -1917
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +5 -1877
  6. package/dist/index.mjs.map +1 -1
  7. package/introspection/dist/index.d.mts +117 -171
  8. package/introspection/dist/index.d.ts +117 -171
  9. package/introspection/dist/index.js +6 -346
  10. package/introspection/dist/index.js.map +1 -1
  11. package/introspection/dist/index.mjs +5 -324
  12. package/introspection/dist/index.mjs.map +1 -1
  13. package/json/dist/index.d.mts +32 -1
  14. package/json/dist/index.d.ts +32 -1
  15. package/json/dist/index.js +31 -48
  16. package/json/dist/index.js.map +1 -1
  17. package/json/dist/index.mjs +6 -14
  18. package/json/dist/index.mjs.map +1 -1
  19. package/package.json +22 -14
  20. package/react/dist/index.js +34 -83
  21. package/react/dist/index.js.map +1 -1
  22. package/react/dist/index.mjs +7 -43
  23. package/react/dist/index.mjs.map +1 -1
  24. package/react-devtools/dist/index.css +1 -50
  25. package/react-devtools/dist/index.css.map +1 -1
  26. package/react-devtools/dist/index.d.mts +124 -188
  27. package/react-devtools/dist/index.d.ts +124 -188
  28. package/react-devtools/dist/index.js +56 -4674
  29. package/react-devtools/dist/index.js.map +1 -1
  30. package/react-devtools/dist/index.mjs +19 -4642
  31. package/react-devtools/dist/index.mjs.map +1 -1
  32. package/realtime/dist/index.d.mts +1 -3
  33. package/realtime/dist/index.d.ts +1 -3
  34. package/realtime/dist/index.js +26 -184
  35. package/realtime/dist/index.js.map +1 -1
  36. package/realtime/dist/index.mjs +4 -148
  37. package/realtime/dist/index.mjs.map +1 -1
  38. package/realtime-react/dist/index.d.mts +2 -4
  39. package/realtime-react/dist/index.d.ts +2 -4
  40. package/realtime-react/dist/index.js +41 -214
  41. package/realtime-react/dist/index.js.map +1 -1
  42. package/realtime-react/dist/index.mjs +9 -169
  43. package/realtime-react/dist/index.mjs.map +1 -1
  44. package/src/atom.ts +4 -3
  45. package/src/index.ts +12 -9
  46. package/src/logger.ts +5 -5
  47. package/src/selector.ts +3 -3
  48. package/src/silo.ts +36 -39
  49. package/src/subscribe.ts +24 -19
  50. package/src/timeline.ts +9 -4
  51. package/src/transaction.ts +3 -4
  52. package/src/internal/atom-internal.ts +0 -54
  53. package/src/internal/families-internal.ts +0 -144
  54. package/src/internal/get.ts +0 -129
  55. package/src/internal/index.ts +0 -15
  56. package/src/internal/is-default.ts +0 -35
  57. package/src/internal/operation.ts +0 -139
  58. package/src/internal/selector/create-read-write-selector.ts +0 -68
  59. package/src/internal/selector/create-readonly-selector.ts +0 -48
  60. package/src/internal/selector/index.ts +0 -4
  61. package/src/internal/selector/lookup-selector-sources.ts +0 -16
  62. package/src/internal/selector/register-selector.ts +0 -57
  63. package/src/internal/selector/trace-selector-atoms.ts +0 -43
  64. package/src/internal/selector/update-selector-atoms.ts +0 -33
  65. package/src/internal/selector-internal.ts +0 -58
  66. package/src/internal/set.ts +0 -99
  67. package/src/internal/store.ts +0 -151
  68. package/src/internal/subscribe-internal.ts +0 -88
  69. package/src/internal/time-travel-internal.ts +0 -91
  70. package/src/internal/timeline/add-atom-to-timeline.ts +0 -168
  71. package/src/internal/timeline/index.ts +0 -1
  72. package/src/internal/timeline-internal.ts +0 -107
  73. package/src/internal/transaction/abort-transaction.ts +0 -12
  74. package/src/internal/transaction/apply-transaction.ts +0 -57
  75. package/src/internal/transaction/build-transaction.ts +0 -33
  76. package/src/internal/transaction/index.ts +0 -25
  77. package/src/internal/transaction/redo-transaction.ts +0 -23
  78. package/src/internal/transaction/undo-transaction.ts +0 -23
  79. package/src/internal/transaction-internal.ts +0 -61
  80. package/src/introspection/attach-atom-index.ts +0 -73
  81. package/src/introspection/attach-introspection-states.ts +0 -42
  82. package/src/introspection/attach-selector-index.ts +0 -77
  83. package/src/introspection/attach-timeline-family.ts +0 -59
  84. package/src/introspection/attach-timeline-index.ts +0 -36
  85. package/src/introspection/attach-transaction-index.ts +0 -38
  86. package/src/introspection/attach-transaction-logs.ts +0 -40
  87. package/src/introspection/index.ts +0 -20
  88. package/src/json/index.ts +0 -1
  89. package/src/json/select-json.ts +0 -18
  90. package/src/react/index.ts +0 -2
  91. package/src/react/store-context.tsx +0 -13
  92. package/src/react/store-hooks.ts +0 -47
  93. package/src/react-devtools/AtomIODevtools.tsx +0 -107
  94. package/src/react-devtools/Button.tsx +0 -24
  95. package/src/react-devtools/StateEditor.tsx +0 -74
  96. package/src/react-devtools/StateIndex.tsx +0 -156
  97. package/src/react-devtools/TimelineIndex.tsx +0 -92
  98. package/src/react-devtools/TransactionIndex.tsx +0 -70
  99. package/src/react-devtools/Updates.tsx +0 -145
  100. package/src/react-devtools/devtools.scss +0 -310
  101. package/src/react-devtools/index.ts +0 -72
  102. package/src/react-explorer/AtomIOExplorer.tsx +0 -218
  103. package/src/react-explorer/explorer-effects.ts +0 -20
  104. package/src/react-explorer/explorer-states.ts +0 -217
  105. package/src/react-explorer/index.ts +0 -23
  106. package/src/react-explorer/space-states.ts +0 -72
  107. package/src/react-explorer/view-states.ts +0 -41
  108. package/src/realtime/README.md +0 -33
  109. package/src/realtime/hook-composition/expose-family.ts +0 -101
  110. package/src/realtime/hook-composition/expose-single.ts +0 -38
  111. package/src/realtime/hook-composition/expose-timeline.ts +0 -60
  112. package/src/realtime/hook-composition/index.ts +0 -12
  113. package/src/realtime/hook-composition/receive-state.ts +0 -29
  114. package/src/realtime/hook-composition/receive-transaction.ts +0 -18
  115. package/src/realtime/index.ts +0 -1
  116. package/src/realtime-react/index.ts +0 -3
  117. package/src/realtime-react/realtime-context.tsx +0 -30
  118. package/src/realtime-react/realtime-hooks.ts +0 -39
  119. package/src/realtime-react/realtime-state.ts +0 -10
  120. package/src/realtime-react/use-pull-family-member.ts +0 -26
  121. package/src/realtime-react/use-pull-family.ts +0 -24
  122. package/src/realtime-react/use-pull.ts +0 -24
  123. package/src/realtime-react/use-push.ts +0 -27
  124. package/src/realtime-react/use-server-action.ts +0 -33
  125. package/src/realtime-testing/index.ts +0 -1
  126. package/src/realtime-testing/setup-realtime-test.tsx +0 -159
  127. package/src/tracker/index.ts +0 -3
  128. package/src/tracker/tracker.ts +0 -61
  129. package/src/web-effects/index.ts +0 -1
  130. package/src/web-effects/storage.ts +0 -30
@@ -1,16 +1,4 @@
1
- import { AtomToken as AtomToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, SelectorToken as SelectorToken$1, __INTERNAL__, TransactionToken as TransactionToken$1, ReadonlySelectorFamily, TransactionUpdate as TransactionUpdate$1, TimelineToken as TimelineToken$1 } from 'atom.io';
2
- import { Refinement } from 'fp-ts/Refinement';
3
-
4
- type ƒn = (...parameters: any[]) => any;
5
-
6
- type AtomTokenIndex = StateTokenIndex<AtomToken$1<unknown>>;
7
-
8
- type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>>;
9
-
10
- type JsonInterface<T, J extends Serializable = Serializable> = {
11
- toJson: (t: T) => J;
12
- fromJson: (json: J) => T;
13
- };
1
+ import { StateToken, FamilyMetadata, TimelineUpdate, StateUpdate, TransactionUpdate, ƒn, AtomToken, ReadonlySelectorToken, SelectorToken, TransactionToken, TimelineToken, Logger, __INTERNAL__, ReadonlySelectorFamily } from 'atom.io';
14
2
 
15
3
  type primitive = boolean | number | string | null;
16
4
 
@@ -19,152 +7,64 @@ type Serializable = primitive | Readonly<{
19
7
  }> | ReadonlyArray<Serializable>;
20
8
  type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
21
9
 
22
- type Identified = {
23
- id: string;
24
- };
25
-
26
- declare const RELATION_TYPES: readonly ["1:1", "1:n", "n:n"];
27
- type RelationType = typeof RELATION_TYPES[number];
28
- type RelationData<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> = {
29
- contents: Object$1<string, CONTENT>;
30
- relations: Object$1<string, string[]>;
31
- relationType: RelationType;
32
- a: A;
33
- b: B;
34
- };
35
- type IsRelationDataOptions<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> = {
36
- from?: A;
37
- to?: B;
38
- isContent?: (json: Serializable) => json is CONTENT;
39
- };
10
+ type Refinement<Unrefined, Refined extends Unrefined> = (value: Unrefined) => value is Refined;
11
+ type Cardinality = `1:1` | `1:n` | `n:n`;
40
12
 
41
- type NullSafeUnion<Base, Extension> = Extension extends null ? Base : Base & Extension;
42
- type NullSafeRest<MaybeArg, IfArg = MaybeArg> = MaybeArg extends null ? [] | [undefined] : [IfArg];
43
-
44
- declare class Join<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> implements RelationData<CONTENT, A, B> {
45
- readonly relationType: `1:1` | `1:n` | `n:n`;
46
- readonly a: A;
47
- readonly b: B;
48
- readonly relations: Record<string, string[]>;
49
- readonly contents: Record<string, CONTENT>;
50
- constructor(json?: Partial<RelationData<CONTENT, A, B>>);
51
- toJSON(): RelationData<CONTENT, A, B>;
52
- static fromJSON<CONTENT extends Object$1 | null, A extends string, B extends string>(json: Serializable, options?: IsRelationDataOptions<CONTENT, A, B>): Join<CONTENT, A, B>;
53
- from<AA extends string>(newA: AA): Join<CONTENT, AA, B>;
54
- to<BB extends string>(newB: BB): Join<CONTENT, A, BB>;
55
- makeJsonInterface: (...params: CONTENT extends null ? [
56
- ] : [Refinement<unknown, CONTENT>]) => JsonInterface<Join<CONTENT, A, B>, RelationData<CONTENT, A, B>>;
57
- getRelatedId(id: string): string | undefined;
58
- getRelatedIds(id: string): string[];
59
- getContent(idA: string, idB: string): CONTENT | undefined;
60
- getRelationEntries(id: string): [string, CONTENT][];
61
- getRelationRecord(id: string): Record<string, CONTENT>;
62
- getRelation(id: string): NullSafeUnion<Identified, CONTENT> | undefined;
63
- getRelations(id: string): NullSafeUnion<Identified, CONTENT>[];
64
- setRelations(subject: {
65
- [from in A]: string;
66
- } | {
67
- [to in B]: string;
68
- }, relations: NullSafeUnion<Identified, CONTENT>[]): Join<CONTENT, A, B>;
69
- set(relation: {
70
- [key in A | B]: string;
71
- }, ...rest: NullSafeRest<CONTENT>): Join<CONTENT, A, B>;
72
- remove(relation: Partial<Record<A | B, string>>): Join<CONTENT, A, B>;
13
+ interface JunctionEntries<Content extends Object$1 | null> extends Object$1 {
14
+ readonly relations: [string, string[]][];
15
+ readonly contents: [string, Content][];
73
16
  }
74
-
75
- type Logger = Pick<Console, `error` | `info` | `warn`>;
76
-
77
- type TransactionToken<_> = {
78
- key: string;
79
- type: `transaction`;
80
- __brand?: _;
81
- };
82
- type TransactionUpdate<ƒ extends ƒn> = {
83
- key: string;
84
- atomUpdates: KeyedStateUpdate<unknown>[];
85
- params: Parameters<ƒ>;
86
- output: ReturnType<ƒ>;
87
- };
88
-
89
- type StateUpdate<T> = {
90
- newValue: T;
91
- oldValue: T;
92
- };
93
- type KeyedStateUpdate<T> = StateUpdate<T> & {
94
- key: string;
95
- };
96
-
97
- type TimelineToken = {
98
- key: string;
99
- type: `timeline`;
100
- };
101
- type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
102
-
103
- type AtomToken<_> = {
104
- key: string;
105
- type: `atom`;
106
- family?: FamilyMetadata;
107
- __brand?: _;
108
- };
109
- type SelectorToken<_> = {
110
- key: string;
111
- type: `selector`;
112
- family?: FamilyMetadata;
113
- __brand?: _;
114
- };
115
- type StateToken<T> = AtomToken<T> | SelectorToken<T>;
116
- type ReadonlySelectorToken<_> = {
117
- key: string;
118
- type: `readonly_selector`;
119
- family?: FamilyMetadata;
120
- __brand?: _;
121
- };
122
- type FamilyMetadata = {
123
- key: string;
124
- subKey: string;
125
- };
126
-
127
- type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `transactions` | `valueMap`>;
128
- interface Store {
129
- atoms: Map<string, Atom<any>>;
130
- atomsThatAreDefault: Set<string>;
131
- readonlySelectors: Map<string, ReadonlySelector<any>>;
132
- selectorAtoms: Join<null, `selectorKey`, `atomKey`>;
133
- selectorGraph: Join<{
134
- source: string;
135
- }>;
136
- selectors: Map<string, Selector<any>>;
137
- timelineAtoms: Join<null, `timelineKey`, `atomKey`>;
138
- timelines: Map<string, Timeline>;
139
- transactions: Map<string, Transaction<any>>;
140
- valueMap: Map<string, any>;
141
- subject: {
142
- atomCreation: Subject<AtomToken<unknown>>;
143
- selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
144
- transactionCreation: Subject<TransactionToken<ƒn>>;
145
- timelineCreation: Subject<TimelineToken>;
146
- operationStatus: Subject<OperationProgress>;
147
- };
148
- operation: OperationProgress;
149
- transactionStatus: TransactionStatus<ƒn>;
150
- config: {
151
- name: string;
152
- logger: Logger | null;
153
- logger__INTERNAL: Logger;
17
+ interface JunctionSchema<ASide extends string, BSide extends string> extends Object$1 {
18
+ readonly between: [a: ASide, b: BSide];
19
+ readonly cardinality: Cardinality;
20
+ }
21
+ type JunctionAdvancedConfiguration<Content extends Object$1 | null> = {
22
+ externalStore?: (Content extends null ? {
23
+ getContent?: undefined;
24
+ setContent?: undefined;
25
+ deleteContent?: undefined;
26
+ } : {
27
+ getContent: (contentKey: string) => Content | undefined;
28
+ setContent: (contentKey: string, content: Content) => void;
29
+ deleteContent: (g: any) => void;
30
+ }) & {
31
+ addRelation: (a: string, b: string) => void;
32
+ deleteRelation: (a: string, b: string) => void;
33
+ getRelatedKeys: (key: string) => Set<string> | undefined;
34
+ has: (a: string, b?: string) => boolean;
154
35
  };
36
+ isContent?: Refinement<unknown, Content>;
37
+ makeContentKey?: (a: string, b: string) => string;
38
+ };
39
+ type JunctionJSON<ASide extends string, BSide extends string, Content extends Object$1 | null> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>;
40
+ declare class Junction<ASide extends string, BSide extends string, Content extends Object$1 | null = null> {
41
+ readonly a: ASide;
42
+ readonly b: BSide;
43
+ readonly cardinality: Cardinality;
44
+ readonly relations: Map<string, Set<string>>;
45
+ readonly contents: Map<string, Content>;
46
+ isContent: Refinement<unknown, Content> | null;
47
+ makeContentKey: (a: string, b: string) => string;
48
+ getRelatedKeys(key: string): Set<string> | undefined;
49
+ protected addRelation(a: string, b: string): void;
50
+ protected deleteRelation(a: string, b: string): void;
51
+ protected getContentInternal(contentKey: string): Content | undefined;
52
+ protected setContent(contentKey: string, content: Content): void;
53
+ protected deleteContent(contentKey: string): void;
54
+ constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>, config?: JunctionAdvancedConfiguration<Content>);
55
+ toJSON(): JunctionJSON<ASide, BSide, Content>;
56
+ set(a: string, ...rest: Content extends null ? [b: string] : [b: string, content: Content]): this;
57
+ set(relation: {
58
+ [Key in ASide | BSide]: string;
59
+ }, ...rest: Content extends null ? [] | [b?: undefined] : [content: Content]): this;
60
+ delete(a: string, b?: string): this;
61
+ delete(relation: Record<ASide | BSide, string> | Record<ASide, string> | Record<BSide, string>, b?: undefined): this;
62
+ getRelatedKey(key: string): string | undefined;
63
+ getContent(a: string, b: string): Content | undefined;
64
+ getRelationEntries(input: Record<ASide, string> | Record<BSide, string>): [string, Content][];
65
+ has(a: string, b?: string): boolean;
155
66
  }
156
67
 
157
- type Atom<T> = {
158
- key: string;
159
- type: `atom`;
160
- family?: FamilyMetadata;
161
- subject: Subject<{
162
- newValue: T;
163
- oldValue: T;
164
- }>;
165
- default: T;
166
- };
167
-
168
68
  type OperationProgress = {
169
69
  open: false;
170
70
  } | {
@@ -175,6 +75,14 @@ type OperationProgress = {
175
75
  token: StateToken<any>;
176
76
  };
177
77
 
78
+ type Subscriber<T> = (value: T) => void;
79
+ declare class Subject<T> {
80
+ subscribers: Map<string, Subscriber<T>>;
81
+ subscribe(key: string, subscriber: Subscriber<T>): () => void;
82
+ private unsubscribe;
83
+ next(value: T): void;
84
+ }
85
+
178
86
  type Selector<T> = {
179
87
  key: string;
180
88
  type: `selector`;
@@ -199,20 +107,11 @@ type ReadonlySelector<T> = {
199
107
  get: () => T;
200
108
  };
201
109
 
202
- type Subscriber<T> = (value: T) => void;
203
- declare class Subject<T> {
204
- subscribers: Subscriber<T>[];
205
- subscribe(subscriber: Subscriber<T>): {
206
- unsubscribe: () => void;
207
- };
208
- private unsubscribe;
209
- next(value: T): void;
210
- }
211
-
212
110
  type TimelineAtomUpdate = StateUpdate<unknown> & {
213
111
  key: string;
214
112
  type: `atom_update`;
215
113
  timestamp: number;
114
+ family?: FamilyMetadata;
216
115
  };
217
116
  type TimelineSelectorUpdate = {
218
117
  key: string;
@@ -226,6 +125,7 @@ type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
226
125
  timestamp: number;
227
126
  };
228
127
  type Timeline = {
128
+ type: `timeline`;
229
129
  key: string;
230
130
  at: number;
231
131
  timeTraveling: `into_future` | `into_past` | null;
@@ -254,19 +154,65 @@ type TransactionIdle = {
254
154
  };
255
155
  type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
256
156
 
157
+ type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `transactions` | `valueMap`>;
158
+ declare class Store {
159
+ valueMap: Map<string, any>;
160
+ atoms: Map<string, Atom<any>>;
161
+ selectors: Map<string, Selector<any>>;
162
+ readonlySelectors: Map<string, ReadonlySelector<any>>;
163
+ timelines: Map<string, Timeline>;
164
+ transactions: Map<string, Transaction<ƒn>>;
165
+ atomsThatAreDefault: Set<string>;
166
+ timelineAtoms: Junction<"timelineKey", "atomKey", null>;
167
+ selectorAtoms: Junction<"selectorKey", "atomKey", null>;
168
+ selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
169
+ source: string;
170
+ }>;
171
+ subject: {
172
+ atomCreation: Subject<AtomToken<unknown>>;
173
+ selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
174
+ transactionCreation: Subject<TransactionToken<ƒn>>;
175
+ timelineCreation: Subject<TimelineToken>;
176
+ operationStatus: Subject<OperationProgress>;
177
+ };
178
+ operation: OperationProgress;
179
+ transactionStatus: TransactionStatus<ƒn>;
180
+ config: {
181
+ name: string;
182
+ logger: Logger | null;
183
+ logger__INTERNAL: Logger;
184
+ };
185
+ constructor(name: string, store?: Store | null);
186
+ }
187
+
188
+ type Atom<T> = {
189
+ key: string;
190
+ type: `atom`;
191
+ family?: FamilyMetadata;
192
+ subject: Subject<{
193
+ newValue: T;
194
+ oldValue: T;
195
+ }>;
196
+ default: T;
197
+ };
198
+
199
+ type AtomTokenIndex = StateTokenIndex<AtomToken<unknown>>;
200
+
201
+ type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
202
+
257
203
  declare const attachIntrospectionStates: (store?: __INTERNAL__.Store) => {
258
- atomIndex: ReadonlySelectorToken$1<AtomTokenIndex>;
259
- selectorIndex: ReadonlySelectorToken$1<SelectorTokenIndex>;
260
- transactionIndex: ReadonlySelectorToken$1<TransactionToken$1<ƒn>[]>;
261
- findTransactionLogState: ReadonlySelectorFamily<TransactionUpdate$1<ƒn>[]>;
262
- timelineIndex: ReadonlySelectorToken$1<TimelineToken$1[]>;
204
+ atomIndex: ReadonlySelectorToken<AtomTokenIndex>;
205
+ selectorIndex: ReadonlySelectorToken<SelectorTokenIndex>;
206
+ transactionIndex: ReadonlySelectorToken<TransactionToken<ƒn>[]>;
207
+ findTransactionLogState: ReadonlySelectorFamily<TransactionUpdate<ƒn>[]>;
208
+ timelineIndex: ReadonlySelectorToken<TimelineToken[]>;
263
209
  findTimelineState: ReadonlySelectorFamily<Timeline>;
264
210
  };
265
211
 
266
- type FamilyNode<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = {
212
+ type FamilyNode<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>> = {
267
213
  key: string;
268
214
  familyMembers: Record<string, Token>;
269
215
  };
270
- type StateTokenIndex<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = Record<string, FamilyNode<Token> | Token>;
216
+ type StateTokenIndex<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>> = Record<string, FamilyNode<Token> | Token>;
271
217
 
272
218
  export { FamilyNode, StateTokenIndex, attachIntrospectionStates };
@@ -1,16 +1,4 @@
1
- import { AtomToken as AtomToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, SelectorToken as SelectorToken$1, __INTERNAL__, TransactionToken as TransactionToken$1, ReadonlySelectorFamily, TransactionUpdate as TransactionUpdate$1, TimelineToken as TimelineToken$1 } from 'atom.io';
2
- import { Refinement } from 'fp-ts/Refinement';
3
-
4
- type ƒn = (...parameters: any[]) => any;
5
-
6
- type AtomTokenIndex = StateTokenIndex<AtomToken$1<unknown>>;
7
-
8
- type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>>;
9
-
10
- type JsonInterface<T, J extends Serializable = Serializable> = {
11
- toJson: (t: T) => J;
12
- fromJson: (json: J) => T;
13
- };
1
+ import { StateToken, FamilyMetadata, TimelineUpdate, StateUpdate, TransactionUpdate, ƒn, AtomToken, ReadonlySelectorToken, SelectorToken, TransactionToken, TimelineToken, Logger, __INTERNAL__, ReadonlySelectorFamily } from 'atom.io';
14
2
 
15
3
  type primitive = boolean | number | string | null;
16
4
 
@@ -19,152 +7,64 @@ type Serializable = primitive | Readonly<{
19
7
  }> | ReadonlyArray<Serializable>;
20
8
  type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
21
9
 
22
- type Identified = {
23
- id: string;
24
- };
25
-
26
- declare const RELATION_TYPES: readonly ["1:1", "1:n", "n:n"];
27
- type RelationType = typeof RELATION_TYPES[number];
28
- type RelationData<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> = {
29
- contents: Object$1<string, CONTENT>;
30
- relations: Object$1<string, string[]>;
31
- relationType: RelationType;
32
- a: A;
33
- b: B;
34
- };
35
- type IsRelationDataOptions<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> = {
36
- from?: A;
37
- to?: B;
38
- isContent?: (json: Serializable) => json is CONTENT;
39
- };
10
+ type Refinement<Unrefined, Refined extends Unrefined> = (value: Unrefined) => value is Refined;
11
+ type Cardinality = `1:1` | `1:n` | `n:n`;
40
12
 
41
- type NullSafeUnion<Base, Extension> = Extension extends null ? Base : Base & Extension;
42
- type NullSafeRest<MaybeArg, IfArg = MaybeArg> = MaybeArg extends null ? [] | [undefined] : [IfArg];
43
-
44
- declare class Join<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> implements RelationData<CONTENT, A, B> {
45
- readonly relationType: `1:1` | `1:n` | `n:n`;
46
- readonly a: A;
47
- readonly b: B;
48
- readonly relations: Record<string, string[]>;
49
- readonly contents: Record<string, CONTENT>;
50
- constructor(json?: Partial<RelationData<CONTENT, A, B>>);
51
- toJSON(): RelationData<CONTENT, A, B>;
52
- static fromJSON<CONTENT extends Object$1 | null, A extends string, B extends string>(json: Serializable, options?: IsRelationDataOptions<CONTENT, A, B>): Join<CONTENT, A, B>;
53
- from<AA extends string>(newA: AA): Join<CONTENT, AA, B>;
54
- to<BB extends string>(newB: BB): Join<CONTENT, A, BB>;
55
- makeJsonInterface: (...params: CONTENT extends null ? [
56
- ] : [Refinement<unknown, CONTENT>]) => JsonInterface<Join<CONTENT, A, B>, RelationData<CONTENT, A, B>>;
57
- getRelatedId(id: string): string | undefined;
58
- getRelatedIds(id: string): string[];
59
- getContent(idA: string, idB: string): CONTENT | undefined;
60
- getRelationEntries(id: string): [string, CONTENT][];
61
- getRelationRecord(id: string): Record<string, CONTENT>;
62
- getRelation(id: string): NullSafeUnion<Identified, CONTENT> | undefined;
63
- getRelations(id: string): NullSafeUnion<Identified, CONTENT>[];
64
- setRelations(subject: {
65
- [from in A]: string;
66
- } | {
67
- [to in B]: string;
68
- }, relations: NullSafeUnion<Identified, CONTENT>[]): Join<CONTENT, A, B>;
69
- set(relation: {
70
- [key in A | B]: string;
71
- }, ...rest: NullSafeRest<CONTENT>): Join<CONTENT, A, B>;
72
- remove(relation: Partial<Record<A | B, string>>): Join<CONTENT, A, B>;
13
+ interface JunctionEntries<Content extends Object$1 | null> extends Object$1 {
14
+ readonly relations: [string, string[]][];
15
+ readonly contents: [string, Content][];
73
16
  }
74
-
75
- type Logger = Pick<Console, `error` | `info` | `warn`>;
76
-
77
- type TransactionToken<_> = {
78
- key: string;
79
- type: `transaction`;
80
- __brand?: _;
81
- };
82
- type TransactionUpdate<ƒ extends ƒn> = {
83
- key: string;
84
- atomUpdates: KeyedStateUpdate<unknown>[];
85
- params: Parameters<ƒ>;
86
- output: ReturnType<ƒ>;
87
- };
88
-
89
- type StateUpdate<T> = {
90
- newValue: T;
91
- oldValue: T;
92
- };
93
- type KeyedStateUpdate<T> = StateUpdate<T> & {
94
- key: string;
95
- };
96
-
97
- type TimelineToken = {
98
- key: string;
99
- type: `timeline`;
100
- };
101
- type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
102
-
103
- type AtomToken<_> = {
104
- key: string;
105
- type: `atom`;
106
- family?: FamilyMetadata;
107
- __brand?: _;
108
- };
109
- type SelectorToken<_> = {
110
- key: string;
111
- type: `selector`;
112
- family?: FamilyMetadata;
113
- __brand?: _;
114
- };
115
- type StateToken<T> = AtomToken<T> | SelectorToken<T>;
116
- type ReadonlySelectorToken<_> = {
117
- key: string;
118
- type: `readonly_selector`;
119
- family?: FamilyMetadata;
120
- __brand?: _;
121
- };
122
- type FamilyMetadata = {
123
- key: string;
124
- subKey: string;
125
- };
126
-
127
- type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `transactions` | `valueMap`>;
128
- interface Store {
129
- atoms: Map<string, Atom<any>>;
130
- atomsThatAreDefault: Set<string>;
131
- readonlySelectors: Map<string, ReadonlySelector<any>>;
132
- selectorAtoms: Join<null, `selectorKey`, `atomKey`>;
133
- selectorGraph: Join<{
134
- source: string;
135
- }>;
136
- selectors: Map<string, Selector<any>>;
137
- timelineAtoms: Join<null, `timelineKey`, `atomKey`>;
138
- timelines: Map<string, Timeline>;
139
- transactions: Map<string, Transaction<any>>;
140
- valueMap: Map<string, any>;
141
- subject: {
142
- atomCreation: Subject<AtomToken<unknown>>;
143
- selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
144
- transactionCreation: Subject<TransactionToken<ƒn>>;
145
- timelineCreation: Subject<TimelineToken>;
146
- operationStatus: Subject<OperationProgress>;
147
- };
148
- operation: OperationProgress;
149
- transactionStatus: TransactionStatus<ƒn>;
150
- config: {
151
- name: string;
152
- logger: Logger | null;
153
- logger__INTERNAL: Logger;
17
+ interface JunctionSchema<ASide extends string, BSide extends string> extends Object$1 {
18
+ readonly between: [a: ASide, b: BSide];
19
+ readonly cardinality: Cardinality;
20
+ }
21
+ type JunctionAdvancedConfiguration<Content extends Object$1 | null> = {
22
+ externalStore?: (Content extends null ? {
23
+ getContent?: undefined;
24
+ setContent?: undefined;
25
+ deleteContent?: undefined;
26
+ } : {
27
+ getContent: (contentKey: string) => Content | undefined;
28
+ setContent: (contentKey: string, content: Content) => void;
29
+ deleteContent: (g: any) => void;
30
+ }) & {
31
+ addRelation: (a: string, b: string) => void;
32
+ deleteRelation: (a: string, b: string) => void;
33
+ getRelatedKeys: (key: string) => Set<string> | undefined;
34
+ has: (a: string, b?: string) => boolean;
154
35
  };
36
+ isContent?: Refinement<unknown, Content>;
37
+ makeContentKey?: (a: string, b: string) => string;
38
+ };
39
+ type JunctionJSON<ASide extends string, BSide extends string, Content extends Object$1 | null> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>;
40
+ declare class Junction<ASide extends string, BSide extends string, Content extends Object$1 | null = null> {
41
+ readonly a: ASide;
42
+ readonly b: BSide;
43
+ readonly cardinality: Cardinality;
44
+ readonly relations: Map<string, Set<string>>;
45
+ readonly contents: Map<string, Content>;
46
+ isContent: Refinement<unknown, Content> | null;
47
+ makeContentKey: (a: string, b: string) => string;
48
+ getRelatedKeys(key: string): Set<string> | undefined;
49
+ protected addRelation(a: string, b: string): void;
50
+ protected deleteRelation(a: string, b: string): void;
51
+ protected getContentInternal(contentKey: string): Content | undefined;
52
+ protected setContent(contentKey: string, content: Content): void;
53
+ protected deleteContent(contentKey: string): void;
54
+ constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>, config?: JunctionAdvancedConfiguration<Content>);
55
+ toJSON(): JunctionJSON<ASide, BSide, Content>;
56
+ set(a: string, ...rest: Content extends null ? [b: string] : [b: string, content: Content]): this;
57
+ set(relation: {
58
+ [Key in ASide | BSide]: string;
59
+ }, ...rest: Content extends null ? [] | [b?: undefined] : [content: Content]): this;
60
+ delete(a: string, b?: string): this;
61
+ delete(relation: Record<ASide | BSide, string> | Record<ASide, string> | Record<BSide, string>, b?: undefined): this;
62
+ getRelatedKey(key: string): string | undefined;
63
+ getContent(a: string, b: string): Content | undefined;
64
+ getRelationEntries(input: Record<ASide, string> | Record<BSide, string>): [string, Content][];
65
+ has(a: string, b?: string): boolean;
155
66
  }
156
67
 
157
- type Atom<T> = {
158
- key: string;
159
- type: `atom`;
160
- family?: FamilyMetadata;
161
- subject: Subject<{
162
- newValue: T;
163
- oldValue: T;
164
- }>;
165
- default: T;
166
- };
167
-
168
68
  type OperationProgress = {
169
69
  open: false;
170
70
  } | {
@@ -175,6 +75,14 @@ type OperationProgress = {
175
75
  token: StateToken<any>;
176
76
  };
177
77
 
78
+ type Subscriber<T> = (value: T) => void;
79
+ declare class Subject<T> {
80
+ subscribers: Map<string, Subscriber<T>>;
81
+ subscribe(key: string, subscriber: Subscriber<T>): () => void;
82
+ private unsubscribe;
83
+ next(value: T): void;
84
+ }
85
+
178
86
  type Selector<T> = {
179
87
  key: string;
180
88
  type: `selector`;
@@ -199,20 +107,11 @@ type ReadonlySelector<T> = {
199
107
  get: () => T;
200
108
  };
201
109
 
202
- type Subscriber<T> = (value: T) => void;
203
- declare class Subject<T> {
204
- subscribers: Subscriber<T>[];
205
- subscribe(subscriber: Subscriber<T>): {
206
- unsubscribe: () => void;
207
- };
208
- private unsubscribe;
209
- next(value: T): void;
210
- }
211
-
212
110
  type TimelineAtomUpdate = StateUpdate<unknown> & {
213
111
  key: string;
214
112
  type: `atom_update`;
215
113
  timestamp: number;
114
+ family?: FamilyMetadata;
216
115
  };
217
116
  type TimelineSelectorUpdate = {
218
117
  key: string;
@@ -226,6 +125,7 @@ type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
226
125
  timestamp: number;
227
126
  };
228
127
  type Timeline = {
128
+ type: `timeline`;
229
129
  key: string;
230
130
  at: number;
231
131
  timeTraveling: `into_future` | `into_past` | null;
@@ -254,19 +154,65 @@ type TransactionIdle = {
254
154
  };
255
155
  type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
256
156
 
157
+ type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `transactions` | `valueMap`>;
158
+ declare class Store {
159
+ valueMap: Map<string, any>;
160
+ atoms: Map<string, Atom<any>>;
161
+ selectors: Map<string, Selector<any>>;
162
+ readonlySelectors: Map<string, ReadonlySelector<any>>;
163
+ timelines: Map<string, Timeline>;
164
+ transactions: Map<string, Transaction<ƒn>>;
165
+ atomsThatAreDefault: Set<string>;
166
+ timelineAtoms: Junction<"timelineKey", "atomKey", null>;
167
+ selectorAtoms: Junction<"selectorKey", "atomKey", null>;
168
+ selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
169
+ source: string;
170
+ }>;
171
+ subject: {
172
+ atomCreation: Subject<AtomToken<unknown>>;
173
+ selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
174
+ transactionCreation: Subject<TransactionToken<ƒn>>;
175
+ timelineCreation: Subject<TimelineToken>;
176
+ operationStatus: Subject<OperationProgress>;
177
+ };
178
+ operation: OperationProgress;
179
+ transactionStatus: TransactionStatus<ƒn>;
180
+ config: {
181
+ name: string;
182
+ logger: Logger | null;
183
+ logger__INTERNAL: Logger;
184
+ };
185
+ constructor(name: string, store?: Store | null);
186
+ }
187
+
188
+ type Atom<T> = {
189
+ key: string;
190
+ type: `atom`;
191
+ family?: FamilyMetadata;
192
+ subject: Subject<{
193
+ newValue: T;
194
+ oldValue: T;
195
+ }>;
196
+ default: T;
197
+ };
198
+
199
+ type AtomTokenIndex = StateTokenIndex<AtomToken<unknown>>;
200
+
201
+ type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
202
+
257
203
  declare const attachIntrospectionStates: (store?: __INTERNAL__.Store) => {
258
- atomIndex: ReadonlySelectorToken$1<AtomTokenIndex>;
259
- selectorIndex: ReadonlySelectorToken$1<SelectorTokenIndex>;
260
- transactionIndex: ReadonlySelectorToken$1<TransactionToken$1<ƒn>[]>;
261
- findTransactionLogState: ReadonlySelectorFamily<TransactionUpdate$1<ƒn>[]>;
262
- timelineIndex: ReadonlySelectorToken$1<TimelineToken$1[]>;
204
+ atomIndex: ReadonlySelectorToken<AtomTokenIndex>;
205
+ selectorIndex: ReadonlySelectorToken<SelectorTokenIndex>;
206
+ transactionIndex: ReadonlySelectorToken<TransactionToken<ƒn>[]>;
207
+ findTransactionLogState: ReadonlySelectorFamily<TransactionUpdate<ƒn>[]>;
208
+ timelineIndex: ReadonlySelectorToken<TimelineToken[]>;
263
209
  findTimelineState: ReadonlySelectorFamily<Timeline>;
264
210
  };
265
211
 
266
- type FamilyNode<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = {
212
+ type FamilyNode<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>> = {
267
213
  key: string;
268
214
  familyMembers: Record<string, Token>;
269
215
  };
270
- type StateTokenIndex<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = Record<string, FamilyNode<Token> | Token>;
216
+ type StateTokenIndex<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>> = Record<string, FamilyNode<Token> | Token>;
271
217
 
272
218
  export { FamilyNode, StateTokenIndex, attachIntrospectionStates };