atom.io 0.6.4 → 0.6.6

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 (61) hide show
  1. package/README.md +32 -78
  2. package/dist/index.d.mts +4 -35
  3. package/dist/index.d.ts +4 -35
  4. package/dist/index.js +17 -129
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +17 -129
  7. package/dist/index.mjs.map +1 -1
  8. package/introspection/dist/index.js +312 -0
  9. package/introspection/dist/index.js.map +1 -0
  10. package/introspection/dist/index.mjs +289 -0
  11. package/introspection/dist/index.mjs.map +1 -0
  12. package/introspection/package.json +15 -0
  13. package/package.json +17 -8
  14. package/react-devtools/dist/index.css +22 -5
  15. package/react-devtools/dist/index.css.map +1 -1
  16. package/react-devtools/dist/index.d.mts +347 -8
  17. package/react-devtools/dist/index.d.ts +347 -8
  18. package/react-devtools/dist/index.js +2722 -674
  19. package/react-devtools/dist/index.js.map +1 -1
  20. package/react-devtools/dist/index.mjs +2669 -630
  21. package/react-devtools/dist/index.mjs.map +1 -1
  22. package/src/internal/index.ts +0 -1
  23. package/src/internal/operation.ts +1 -0
  24. package/src/internal/store.ts +3 -2
  25. package/src/internal/time-travel-internal.ts +2 -0
  26. package/src/internal/timeline/add-atom-to-timeline.ts +11 -12
  27. package/src/internal/timeline-internal.ts +5 -1
  28. package/src/introspection/attach-atom-index.ts +73 -0
  29. package/src/introspection/attach-introspection-states.ts +42 -0
  30. package/src/introspection/attach-selector-index.ts +77 -0
  31. package/src/introspection/attach-timeline-family.ts +49 -0
  32. package/src/introspection/attach-timeline-index.ts +36 -0
  33. package/src/introspection/attach-transaction-index.ts +38 -0
  34. package/src/introspection/attach-transaction-logs.ts +40 -0
  35. package/src/introspection/index.ts +20 -0
  36. package/src/react-devtools/AtomIODevtools.tsx +97 -96
  37. package/src/react-devtools/Button.tsx +24 -0
  38. package/src/react-devtools/StateEditor.tsx +14 -16
  39. package/src/react-devtools/StateIndex.tsx +153 -0
  40. package/src/react-devtools/TimelineIndex.tsx +92 -0
  41. package/src/react-devtools/TransactionIndex.tsx +70 -0
  42. package/src/react-devtools/Updates.tsx +145 -0
  43. package/src/react-devtools/devtools.scss +196 -15
  44. package/src/react-devtools/index.ts +71 -0
  45. package/src/react-explorer/AtomIOExplorer.tsx +0 -1
  46. package/src/react-explorer/explorer-effects.ts +3 -3
  47. package/src/react-explorer/explorer-states.ts +1 -1
  48. package/src/react-explorer/space-states.ts +6 -4
  49. package/src/react-explorer/view-states.ts +0 -2
  50. package/realtime-testing/dist/index.d.mts +0 -49
  51. package/realtime-testing/dist/index.d.ts +0 -49
  52. package/realtime-testing/dist/index.js +0 -165
  53. package/realtime-testing/dist/index.js.map +0 -1
  54. package/realtime-testing/dist/index.mjs +0 -129
  55. package/realtime-testing/dist/index.mjs.map +0 -1
  56. package/src/internal/meta/attach-meta.ts +0 -17
  57. package/src/internal/meta/index.ts +0 -4
  58. package/src/internal/meta/meta-state.ts +0 -135
  59. package/src/internal/meta/meta-timelines.ts +0 -1
  60. package/src/internal/meta/meta-transactions.ts +0 -1
  61. package/src/react-devtools/TokenList.tsx +0 -61
@@ -1,15 +1,354 @@
1
+ import { Hamt } from 'hamt_plus';
2
+ import { Refinement } from 'fp-ts/Refinement';
3
+ import { AtomToken as AtomToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, SelectorToken as SelectorToken$1 } from 'atom.io';
1
4
  import { FC } from 'react';
2
- import * as AtomIO from 'atom.io';
3
5
 
4
- type Modifier<T> = (thing: T) => T;
6
+ type PlainObject = Record<keyof any, unknown>;
5
7
 
6
- type StoreHooks = {
7
- useI: <T>(token: AtomIO.StateToken<T>) => (next: Modifier<T> | T) => void;
8
- useO: <T>(token: AtomIO.ReadonlySelectorToken<T> | AtomIO.StateToken<T>) => T;
9
- useIO: <T>(token: AtomIO.StateToken<T>) => [T, (next: Modifier<T> | T) => void];
8
+ type ƒn = (...parameters: any[]) => any;
9
+
10
+ type JsonInterface<T, J extends Json = Json> = {
11
+ toJson: (t: T) => J;
12
+ fromJson: (json: J) => T;
13
+ };
14
+
15
+ type Primitive = boolean | number | string | null;
16
+ type Serializable = Primitive | Readonly<{
17
+ [key: string]: Serializable;
18
+ }> | ReadonlyArray<Serializable>;
19
+ type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
20
+ type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
21
+ type Json = JsonArr | JsonObj | Primitive;
22
+
23
+ type Identified = {
24
+ id: string;
25
+ };
26
+
27
+ declare const RELATION_TYPES: readonly ["1:1", "1:n", "n:n"];
28
+ type RelationType = typeof RELATION_TYPES[number];
29
+ type RelationData<CONTENT extends JsonObj | null = null, A extends string = `from`, B extends string = `to`> = {
30
+ contents: JsonObj<string, CONTENT>;
31
+ relations: JsonObj<string, string[]>;
32
+ relationType: RelationType;
33
+ a: A;
34
+ b: B;
35
+ };
36
+ type IsRelationDataOptions<CONTENT extends JsonObj | null = null, A extends string = `from`, B extends string = `to`> = {
37
+ from?: A;
38
+ to?: B;
39
+ isContent?: (json: Json) => json is CONTENT;
40
+ };
41
+
42
+ type NullSafeUnion<Base, Extension> = Extension extends null ? Base : Base & Extension;
43
+ type NullSafeRest<MaybeArg> = MaybeArg extends null ? [] | [undefined] : [MaybeArg];
44
+
45
+ declare class Join<CONTENT extends JsonObj | null = null, A extends string = `from`, B extends string = `to`> implements RelationData<CONTENT, A, B> {
46
+ readonly relationType: `1:1` | `1:n` | `n:n`;
47
+ readonly a: A;
48
+ readonly b: B;
49
+ readonly relations: Record<string, string[]>;
50
+ readonly contents: Record<string, CONTENT>;
51
+ constructor(json?: Partial<RelationData<CONTENT, A, B>>);
52
+ toJSON(): RelationData<CONTENT, A, B>;
53
+ static fromJSON<CONTENT extends JsonObj | null, A extends string, B extends string>(json: Json, options?: IsRelationDataOptions<CONTENT, A, B>): Join<CONTENT, A, B>;
54
+ from<AA extends string>(newA: AA): Join<CONTENT, AA, B>;
55
+ to<BB extends string>(newB: BB): Join<CONTENT, A, BB>;
56
+ makeJsonInterface: (...params: CONTENT extends null ? [
57
+ ] : [Refinement<unknown, CONTENT>]) => JsonInterface<Join<CONTENT, A, B>, RelationData<CONTENT, A, B>>;
58
+ getRelatedId(id: string): string | undefined;
59
+ getRelatedIds(id: string): string[];
60
+ getContent(idA: string, idB: string): CONTENT | undefined;
61
+ getRelationEntries(id: string): [string, CONTENT][];
62
+ getRelationRecord(id: string): Record<string, CONTENT>;
63
+ getRelation(id: string): NullSafeUnion<Identified, CONTENT> | undefined;
64
+ getRelations(id: string): NullSafeUnion<Identified, CONTENT>[];
65
+ setRelations(subject: {
66
+ [from in A]: string;
67
+ } | {
68
+ [to in B]: string;
69
+ }, relations: NullSafeUnion<Identified, CONTENT>[]): Join<CONTENT, A, B>;
70
+ set(relation: {
71
+ [key in A | B]: string;
72
+ }, ...rest: NullSafeRest<CONTENT>): Join<CONTENT, A, B>;
73
+ remove(relation: Partial<Record<A | B, string>>): Join<CONTENT, A, B>;
74
+ }
75
+
76
+ type AtomFamily<T, K extends Serializable = Serializable> = ((key: K) => AtomToken<T>) & {
77
+ key: string;
78
+ type: `atom_family`;
79
+ subject: Subject<AtomToken<T>>;
80
+ };
81
+
82
+ type Logger = Pick<Console, `error` | `info` | `warn`>;
83
+
84
+ type TransactionToken<_> = {
85
+ key: string;
86
+ type: `transaction`;
87
+ __brand?: _;
10
88
  };
89
+ type TransactionUpdate<ƒ extends ƒn> = {
90
+ key: string;
91
+ atomUpdates: KeyedStateUpdate<unknown>[];
92
+ params: Parameters<ƒ>;
93
+ output: ReturnType<ƒ>;
94
+ };
95
+
96
+ type ReadonlySelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
97
+ key: string;
98
+ type: `readonly_selector_family`;
99
+ subject: Subject<ReadonlySelectorToken<T>>;
100
+ };
101
+
102
+ type StateUpdate<T> = {
103
+ newValue: T;
104
+ oldValue: T;
105
+ };
106
+ type KeyedStateUpdate<T> = StateUpdate<T> & {
107
+ key: string;
108
+ };
109
+
110
+ type TimelineToken = {
111
+ key: string;
112
+ type: `timeline`;
113
+ };
114
+ type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
115
+
116
+ type AtomToken<_> = {
117
+ key: string;
118
+ type: `atom`;
119
+ family?: FamilyMetadata;
120
+ __brand?: _;
121
+ };
122
+ type SelectorToken<_> = {
123
+ key: string;
124
+ type: `selector`;
125
+ family?: FamilyMetadata;
126
+ __brand?: _;
127
+ };
128
+ type StateToken<T> = AtomToken<T> | SelectorToken<T>;
129
+ type ReadonlySelectorToken<_> = {
130
+ key: string;
131
+ type: `readonly_selector`;
132
+ family?: FamilyMetadata;
133
+ __brand?: _;
134
+ };
135
+ type FamilyMetadata = {
136
+ key: string;
137
+ subKey: string;
138
+ };
139
+
140
+ type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `transactions` | `valueMap`>;
141
+ interface Store {
142
+ atoms: Hamt<Atom<any>, string>;
143
+ atomsThatAreDefault: Set<string>;
144
+ readonlySelectors: Hamt<ReadonlySelector<any>, string>;
145
+ selectorAtoms: Join<null, `selectorKey`, `atomKey`>;
146
+ selectorGraph: Join<{
147
+ source: string;
148
+ }>;
149
+ selectors: Hamt<Selector<any>, string>;
150
+ timelineAtoms: Join<null, `timelineKey`, `atomKey`>;
151
+ timelines: Hamt<Timeline, string>;
152
+ transactions: Hamt<Transaction<any>, string>;
153
+ valueMap: Hamt<any, string>;
154
+ subject: {
155
+ atomCreation: Subject<AtomToken<unknown>>;
156
+ selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
157
+ transactionCreation: Subject<TransactionToken<ƒn>>;
158
+ timelineCreation: Subject<TimelineToken>;
159
+ operationStatus: Subject<OperationProgress>;
160
+ };
161
+ operation: OperationProgress;
162
+ transactionStatus: TransactionStatus<ƒn>;
163
+ config: {
164
+ name: string;
165
+ logger: Logger | null;
166
+ logger__INTERNAL: Logger;
167
+ };
168
+ }
169
+
170
+ type Atom<T> = {
171
+ key: string;
172
+ type: `atom`;
173
+ family?: FamilyMetadata;
174
+ subject: Subject<{
175
+ newValue: T;
176
+ oldValue: T;
177
+ }>;
178
+ default: T;
179
+ };
180
+
181
+ type OperationProgress = {
182
+ open: false;
183
+ } | {
184
+ open: true;
185
+ done: Set<string>;
186
+ prev: Hamt<any, string>;
187
+ time: number;
188
+ token: StateToken<any>;
189
+ };
190
+
191
+ type Selector<T> = {
192
+ key: string;
193
+ type: `selector`;
194
+ family?: FamilyMetadata;
195
+ install: (store: Store) => void;
196
+ subject: Subject<{
197
+ newValue: T;
198
+ oldValue: T;
199
+ }>;
200
+ get: () => T;
201
+ set: (newValue: T | ((oldValue: T) => T)) => void;
202
+ };
203
+ type ReadonlySelector<T> = {
204
+ key: string;
205
+ type: `readonly_selector`;
206
+ family?: FamilyMetadata;
207
+ install: (store: Store) => void;
208
+ subject: Subject<{
209
+ newValue: T;
210
+ oldValue: T;
211
+ }>;
212
+ get: () => T;
213
+ };
214
+
215
+ type Subscriber<T> = (value: T) => void;
216
+ declare class Subject<T> {
217
+ subscribers: Subscriber<T>[];
218
+ subscribe(subscriber: Subscriber<T>): {
219
+ unsubscribe: () => void;
220
+ };
221
+ private unsubscribe;
222
+ next(value: T): void;
223
+ }
224
+
225
+ type TimelineAtomUpdate = StateUpdate<unknown> & {
226
+ key: string;
227
+ type: `atom_update`;
228
+ timestamp: number;
229
+ };
230
+ type TimelineSelectorUpdate = {
231
+ key: string;
232
+ type: `selector_update`;
233
+ timestamp: number;
234
+ atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
235
+ };
236
+ type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
237
+ key: string;
238
+ type: `transaction_update`;
239
+ timestamp: number;
240
+ };
241
+ type Timeline = {
242
+ key: string;
243
+ at: number;
244
+ timeTraveling: boolean;
245
+ history: TimelineUpdate[];
246
+ selectorTime: number | null;
247
+ transactionKey: string | null;
248
+ install: (store: Store) => void;
249
+ subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
250
+ };
251
+
252
+ type Transaction<ƒ extends ƒn> = {
253
+ key: string;
254
+ type: `transaction`;
255
+ install: (store: Store) => void;
256
+ subject: Subject<TransactionUpdate<ƒ>>;
257
+ run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
258
+ };
259
+
260
+ type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
261
+ phase: `applying` | `building`;
262
+ time: number;
263
+ core: StoreCore;
264
+ };
265
+ type TransactionIdle = {
266
+ phase: `idle`;
267
+ };
268
+ type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
269
+
270
+ type AtomTokenIndex = StateTokenIndex<AtomToken$1<unknown>>;
271
+
272
+ type FamilyNode<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = {
273
+ key: string;
274
+ familyMembers: Record<string, Token>;
275
+ };
276
+ type StateTokenIndex<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = Record<string, FamilyNode<Token> | Token>;
277
+
278
+ type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>>;
279
+
280
+ type ClassSignature = abstract new (...args: any) => any;
281
+
282
+ type RefinementStrategy = ClassSignature | Refinement<unknown, any>;
283
+ type Supported<Refine extends RefinementStrategy> = Refine extends Refinement<unknown, infer T> ? T : Refine extends ClassSignature ? InstanceType<Refine> : never;
284
+ type RefinementSupport = Record<string, RefinementStrategy>;
285
+ declare class Refinery<SupportedTypes extends RefinementSupport> {
286
+ supported: SupportedTypes;
287
+ constructor(supported: SupportedTypes);
288
+ refine(input: unknown): {
289
+ [K in keyof SupportedTypes]: {
290
+ type: K;
291
+ data: Supported<SupportedTypes[K]>;
292
+ };
293
+ }[keyof SupportedTypes] | null;
294
+ }
295
+
296
+ type Delta = {
297
+ summary: string;
298
+ added?: [path: string, addedStringifiedValue: string][];
299
+ removed?: [path: string, removedStringifiedValue: string][];
300
+ changed?: [path: string, delta: Delta][];
301
+ };
302
+ type Diff<T> = (a: T, b: T) => Delta;
303
+ type DiffTree<T> = (a: T, b: T, recurse: Differ<any, any>[`diff`]) => Delta;
304
+ declare class Differ<Leaf extends Record<string, any>, Tree extends Record<string, any>> {
305
+ leafRefinery: Refinery<Leaf>;
306
+ treeRefinery: Refinery<Tree>;
307
+ leafDiffers: {
308
+ [K in keyof Leaf]: Diff<Supported<Leaf[K]>>;
309
+ };
310
+ treeDiffers: {
311
+ [K in keyof Tree]: DiffTree<Supported<Tree[K]>>;
312
+ };
313
+ constructor(leafRefinery: Refinery<Leaf>, treeRefinery: Refinery<Tree>, diffFunctions: {
314
+ [K in keyof Tree]: DiffTree<Supported<Tree[K]>>;
315
+ } & {
316
+ [K in keyof Leaf]: Diff<Supported<Leaf[K]>>;
317
+ });
318
+ diff(a: unknown, b: unknown): Delta;
319
+ }
11
320
 
12
- declare const composeDevtools: (storeHooks: StoreHooks) => FC;
13
321
  declare const AtomIODevtools: FC;
14
322
 
15
- export { AtomIODevtools, composeDevtools };
323
+ declare const atomIndex: ReadonlySelectorToken<AtomTokenIndex>;
324
+ declare const selectorIndex: ReadonlySelectorToken<SelectorTokenIndex>;
325
+ declare const transactionIndex: ReadonlySelectorToken<TransactionToken<ƒn>[]>;
326
+ declare const findTransactionLogState: ReadonlySelectorFamily<TransactionUpdate<ƒn>[]>;
327
+ declare const timelineIndex: ReadonlySelectorToken<TimelineToken[]>;
328
+ declare const findTimelineState: ReadonlySelectorFamily<Timeline>;
329
+ declare const devtoolsAreOpenState: AtomToken<boolean>;
330
+ type DevtoolsView = `atoms` | `selectors` | `timelines` | `transactions`;
331
+ declare const devtoolsViewSelectionState: AtomToken<DevtoolsView>;
332
+ declare const devtoolsViewOptionsState: AtomToken<DevtoolsView[]>;
333
+ declare const findViewIsOpenState: AtomFamily<boolean, string>;
334
+ declare const primitiveRefinery: Refinery<{
335
+ number: (input: unknown) => input is number;
336
+ string: (input: unknown) => input is string;
337
+ boolean: (input: unknown) => input is boolean;
338
+ null: (input: unknown) => input is null;
339
+ }>;
340
+ declare const jsonTreeRefinery: Refinery<{
341
+ object: (input: unknown) => input is PlainObject;
342
+ array: (input: unknown) => input is unknown[];
343
+ }>;
344
+ declare const prettyJson: Differ<{
345
+ number: (input: unknown) => input is number;
346
+ string: (input: unknown) => input is string;
347
+ boolean: (input: unknown) => input is boolean;
348
+ null: (input: unknown) => input is null;
349
+ }, {
350
+ object: (input: unknown) => input is PlainObject;
351
+ array: (input: unknown) => input is unknown[];
352
+ }>;
353
+
354
+ export { AtomIODevtools, atomIndex, devtoolsAreOpenState, devtoolsViewOptionsState, devtoolsViewSelectionState, findTimelineState, findTransactionLogState, findViewIsOpenState, jsonTreeRefinery, prettyJson, primitiveRefinery, selectorIndex, timelineIndex, transactionIndex };