atomirx 0.0.7 → 0.1.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 (138) hide show
  1. package/README.md +198 -2234
  2. package/bin/cli.js +90 -0
  3. package/dist/core/derived.d.ts +2 -2
  4. package/dist/core/effect.d.ts +3 -2
  5. package/dist/core/onCreateHook.d.ts +15 -2
  6. package/dist/core/onErrorHook.d.ts +4 -1
  7. package/dist/core/pool.d.ts +78 -0
  8. package/dist/core/pool.test.d.ts +1 -0
  9. package/dist/core/select-boolean.test.d.ts +1 -0
  10. package/dist/core/select-pool.test.d.ts +1 -0
  11. package/dist/core/select.d.ts +278 -86
  12. package/dist/core/types.d.ts +233 -1
  13. package/dist/core/withAbort.d.ts +95 -0
  14. package/dist/core/withReady.d.ts +3 -3
  15. package/dist/devtools/constants.d.ts +41 -0
  16. package/dist/devtools/index.cjs +1 -0
  17. package/dist/devtools/index.d.ts +29 -0
  18. package/dist/devtools/index.js +429 -0
  19. package/dist/devtools/registry.d.ts +98 -0
  20. package/dist/devtools/registry.test.d.ts +1 -0
  21. package/dist/devtools/setup.d.ts +61 -0
  22. package/dist/devtools/types.d.ts +311 -0
  23. package/dist/index-BZEnfIcB.cjs +1 -0
  24. package/dist/index-BbPZhsDl.js +1653 -0
  25. package/dist/index.cjs +1 -1
  26. package/dist/index.d.ts +4 -3
  27. package/dist/index.js +18 -14
  28. package/dist/onDispatchHook-C8yLzr-o.cjs +1 -0
  29. package/dist/onDispatchHook-SKbiIUaJ.js +5 -0
  30. package/dist/onErrorHook-BGGy3tqK.js +38 -0
  31. package/dist/onErrorHook-DHBASmYw.cjs +1 -0
  32. package/dist/react/index.cjs +1 -30
  33. package/dist/react/index.js +206 -791
  34. package/dist/react/onDispatchHook.d.ts +106 -0
  35. package/dist/react/useAction.d.ts +4 -1
  36. package/dist/react-devtools/DevToolsPanel.d.ts +93 -0
  37. package/dist/react-devtools/EntityDetails.d.ts +10 -0
  38. package/dist/react-devtools/EntityList.d.ts +15 -0
  39. package/dist/react-devtools/LogList.d.ts +12 -0
  40. package/dist/react-devtools/hooks.d.ts +50 -0
  41. package/dist/react-devtools/index.cjs +1 -0
  42. package/dist/react-devtools/index.d.ts +31 -0
  43. package/dist/react-devtools/index.js +1589 -0
  44. package/dist/react-devtools/styles.d.ts +148 -0
  45. package/package.json +26 -2
  46. package/skills/atomirx/SKILL.md +456 -0
  47. package/skills/atomirx/references/async-patterns.md +188 -0
  48. package/skills/atomirx/references/atom-patterns.md +238 -0
  49. package/skills/atomirx/references/deferred-loading.md +191 -0
  50. package/skills/atomirx/references/derived-patterns.md +428 -0
  51. package/skills/atomirx/references/effect-patterns.md +426 -0
  52. package/skills/atomirx/references/error-handling.md +140 -0
  53. package/skills/atomirx/references/hooks.md +322 -0
  54. package/skills/atomirx/references/pool-patterns.md +229 -0
  55. package/skills/atomirx/references/react-integration.md +411 -0
  56. package/skills/atomirx/references/rules.md +407 -0
  57. package/skills/atomirx/references/select-context.md +309 -0
  58. package/skills/atomirx/references/service-template.md +172 -0
  59. package/skills/atomirx/references/store-template.md +205 -0
  60. package/skills/atomirx/references/testing-patterns.md +431 -0
  61. package/coverage/base.css +0 -224
  62. package/coverage/block-navigation.js +0 -87
  63. package/coverage/clover.xml +0 -1440
  64. package/coverage/coverage-final.json +0 -14
  65. package/coverage/favicon.png +0 -0
  66. package/coverage/index.html +0 -131
  67. package/coverage/prettify.css +0 -1
  68. package/coverage/prettify.js +0 -2
  69. package/coverage/sort-arrow-sprite.png +0 -0
  70. package/coverage/sorter.js +0 -210
  71. package/coverage/src/core/atom.ts.html +0 -889
  72. package/coverage/src/core/batch.ts.html +0 -223
  73. package/coverage/src/core/define.ts.html +0 -805
  74. package/coverage/src/core/emitter.ts.html +0 -919
  75. package/coverage/src/core/equality.ts.html +0 -631
  76. package/coverage/src/core/hook.ts.html +0 -460
  77. package/coverage/src/core/index.html +0 -281
  78. package/coverage/src/core/isAtom.ts.html +0 -100
  79. package/coverage/src/core/isPromiseLike.ts.html +0 -133
  80. package/coverage/src/core/onCreateHook.ts.html +0 -138
  81. package/coverage/src/core/scheduleNotifyHook.ts.html +0 -94
  82. package/coverage/src/core/types.ts.html +0 -523
  83. package/coverage/src/core/withUse.ts.html +0 -253
  84. package/coverage/src/index.html +0 -116
  85. package/coverage/src/index.ts.html +0 -106
  86. package/dist/index-CBVj1kSj.js +0 -1350
  87. package/dist/index-Cxk9v0um.cjs +0 -1
  88. package/scripts/publish.js +0 -198
  89. package/src/core/atom.test.ts +0 -633
  90. package/src/core/atom.ts +0 -311
  91. package/src/core/atomState.test.ts +0 -342
  92. package/src/core/atomState.ts +0 -256
  93. package/src/core/batch.test.ts +0 -257
  94. package/src/core/batch.ts +0 -172
  95. package/src/core/define.test.ts +0 -343
  96. package/src/core/define.ts +0 -243
  97. package/src/core/derived.test.ts +0 -1215
  98. package/src/core/derived.ts +0 -450
  99. package/src/core/effect.test.ts +0 -802
  100. package/src/core/effect.ts +0 -188
  101. package/src/core/emitter.test.ts +0 -364
  102. package/src/core/emitter.ts +0 -392
  103. package/src/core/equality.test.ts +0 -392
  104. package/src/core/equality.ts +0 -182
  105. package/src/core/getAtomState.ts +0 -69
  106. package/src/core/hook.test.ts +0 -227
  107. package/src/core/hook.ts +0 -177
  108. package/src/core/isAtom.ts +0 -27
  109. package/src/core/isPromiseLike.test.ts +0 -72
  110. package/src/core/isPromiseLike.ts +0 -16
  111. package/src/core/onCreateHook.ts +0 -107
  112. package/src/core/onErrorHook.test.ts +0 -350
  113. package/src/core/onErrorHook.ts +0 -52
  114. package/src/core/promiseCache.test.ts +0 -241
  115. package/src/core/promiseCache.ts +0 -284
  116. package/src/core/scheduleNotifyHook.ts +0 -53
  117. package/src/core/select.ts +0 -729
  118. package/src/core/selector.test.ts +0 -799
  119. package/src/core/types.ts +0 -389
  120. package/src/core/withReady.test.ts +0 -534
  121. package/src/core/withReady.ts +0 -191
  122. package/src/core/withUse.test.ts +0 -249
  123. package/src/core/withUse.ts +0 -56
  124. package/src/index.test.ts +0 -80
  125. package/src/index.ts +0 -65
  126. package/src/react/index.ts +0 -21
  127. package/src/react/rx.test.tsx +0 -571
  128. package/src/react/rx.tsx +0 -531
  129. package/src/react/strictModeTest.tsx +0 -71
  130. package/src/react/useAction.test.ts +0 -987
  131. package/src/react/useAction.ts +0 -607
  132. package/src/react/useSelector.test.ts +0 -182
  133. package/src/react/useSelector.ts +0 -292
  134. package/src/react/useStable.test.ts +0 -553
  135. package/src/react/useStable.ts +0 -288
  136. package/tsconfig.json +0 -9
  137. package/v2.md +0 -725
  138. package/vite.config.ts +0 -39
package/src/core/types.ts DELETED
@@ -1,389 +0,0 @@
1
- /**
2
- * Generic function type that accepts any arguments and returns any value.
3
- * Used internally for type-safe function handling.
4
- */
5
- export type AnyFunc = (...args: any[]) => any;
6
-
7
- /**
8
- * Unique symbol used to identify atom instances.
9
- * Uses Symbol.for() to ensure the same symbol across different module instances.
10
- */
11
- export const SYMBOL_ATOM = Symbol.for("atomirx.atom");
12
-
13
- /**
14
- * Symbol to identify derived atoms.
15
- */
16
- export const SYMBOL_DERIVED = Symbol.for("atomirx.derived");
17
-
18
- /**
19
- * Interface for objects that support the `.use()` plugin pattern.
20
- *
21
- * The `.use()` method enables chainable transformations via plugins.
22
- * Return type behavior:
23
- * - `void` → returns original source (side-effect only)
24
- * - Object with `.use` → returns as-is (already pipeable)
25
- * - Object without `.use` → wraps with Pipeable
26
- * - Primitive → returns directly (not chainable)
27
- *
28
- * @example
29
- * ```ts
30
- * const enhanced = atom(0)
31
- * .use(source => ({ ...source, double: () => source.get() * 2 }))
32
- * .use(source => ({ ...source, triple: () => source.get() * 3 }));
33
- * ```
34
- */
35
- export interface Pipeable {
36
- use<TNew = void>(
37
- plugin: (source: this) => TNew
38
- ): void extends TNew
39
- ? this
40
- : TNew extends object
41
- ? TNew extends { use: any }
42
- ? TNew
43
- : Pipeable & TNew
44
- : TNew;
45
- }
46
-
47
- /**
48
- * Optional metadata for atoms.
49
- */
50
- export interface AtomMeta extends AtomirxMeta {
51
- key?: string;
52
- }
53
-
54
- /**
55
- * Base interface for all atoms.
56
- * Represents a reactive value container with subscription capability.
57
- *
58
- * @template T - The type of value stored in the atom
59
- */
60
- export interface Atom<T> {
61
- /** Symbol marker to identify atom instances */
62
- readonly [SYMBOL_ATOM]: true;
63
-
64
- /** Optional metadata for the atom */
65
- readonly meta?: AtomMeta;
66
-
67
- /** Get the current value */
68
- get(): T;
69
-
70
- /**
71
- * Subscribe to value changes.
72
- * @param listener - Callback invoked when value changes
73
- * @returns Unsubscribe function
74
- */
75
- on(listener: VoidFunction): VoidFunction;
76
- }
77
-
78
- /**
79
- * A mutable atom that can be updated via `set()` and reset to initial state.
80
- *
81
- * MutableAtom is a raw storage container. It stores values as-is, including Promises.
82
- * Unlike DerivedAtom, it does not automatically unwrap or track Promise states.
83
- *
84
- * @template T - The type of value stored in the atom
85
- *
86
- * @example
87
- * ```ts
88
- * // Sync value
89
- * const count = atom(0);
90
- * count.set(5); // Direct value
91
- * count.set(n => n + 1); // Reducer function
92
- * count.reset(); // Back to 0
93
- *
94
- * // Async value (stores Promise as-is)
95
- * const posts = atom(fetchPosts());
96
- * posts.get(); // Promise<Post[]>
97
- * posts.set(fetchPosts()); // Store new Promise
98
- * ```
99
- */
100
- export interface MutableAtom<T> extends Atom<T>, Pipeable {
101
- /** Reset atom to its initial state (also clears dirty flag) */
102
- reset(): void;
103
- /**
104
- * Update the atom's value.
105
- *
106
- * @param value - New value or reducer function (prev) => newValue
107
- */
108
- set(value: T | ((prev: T) => T)): void;
109
- /**
110
- * Returns `true` if the value has changed since initialization or last `reset()`.
111
- *
112
- * Useful for:
113
- * - Tracking unsaved changes
114
- * - Enabling/disabling save buttons
115
- * - Detecting form modifications
116
- *
117
- * @example
118
- * ```ts
119
- * const form$ = atom({ name: "", email: "" });
120
- *
121
- * form$.dirty(); // false - just initialized
122
- *
123
- * form$.set({ name: "John", email: "" });
124
- * form$.dirty(); // true - value changed
125
- *
126
- * form$.reset();
127
- * form$.dirty(); // false - reset clears dirty flag
128
- * ```
129
- */
130
- dirty(): boolean;
131
- }
132
-
133
- /**
134
- * A derived (computed) atom that always returns Promise<T> for its value.
135
- *
136
- * DerivedAtom computes its value from other atoms. The computation is
137
- * re-run whenever dependencies change. The `.get()` always returns a Promise,
138
- * even for synchronous computations.
139
- *
140
- * @template T - The resolved type of the computed value
141
- * @template F - Whether fallback is provided (affects staleValue type)
142
- *
143
- * @example
144
- * ```ts
145
- * // Without fallback
146
- * const double$ = derived(({ read }) => read(count$) * 2);
147
- * await double$.get(); // number
148
- * double$.staleValue; // number | undefined
149
- * double$.state(); // { status: "ready", value: 10 }
150
- *
151
- * // With fallback - during loading
152
- * const double$ = derived(({ read }) => read(count$) * 2, { fallback: 0 });
153
- * double$.staleValue; // number (guaranteed)
154
- * double$.state(); // { status: "loading", promise } during loading
155
- * ```
156
- */
157
- export interface DerivedAtom<T, F extends boolean = false> extends Atom<
158
- Promise<T>
159
- > {
160
- /** Symbol marker to identify derived atom instances */
161
- readonly [SYMBOL_DERIVED]: true;
162
- /** Re-run the computation */
163
- refresh(): void;
164
- /**
165
- * Get the current state of the derived atom.
166
- * Returns a discriminated union with status, value/error, and stale flag.
167
- */
168
- state(): AtomState<T>;
169
- /**
170
- * The stale value - fallback or last resolved value.
171
- * - Without fallback: T | undefined
172
- * - With fallback: T (guaranteed)
173
- */
174
- readonly staleValue: F extends true ? T : T | undefined;
175
- }
176
-
177
- /**
178
- * Union type for any atom (mutable or derived).
179
- */
180
- export type AnyAtom<T> = MutableAtom<T> | DerivedAtom<T, boolean>;
181
-
182
- /**
183
- * Extract the value type from an atom.
184
- * For DerivedAtom, returns the awaited type.
185
- */
186
- export type AtomValue<A> =
187
- A extends DerivedAtom<infer V, boolean>
188
- ? V
189
- : A extends Atom<infer V>
190
- ? Awaited<V>
191
- : never;
192
-
193
- /**
194
- * Represents the state of an atom as a discriminated union.
195
- *
196
- * Uses intuitive state terms:
197
- * - `ready` - Value is available
198
- * - `error` - Computation failed
199
- * - `loading` - Waiting for async value
200
- *
201
- * @template T - The type of the atom's value
202
- */
203
- export type AtomState<T> =
204
- | { status: "ready"; value: T; error?: undefined; promise?: undefined }
205
- | { status: "error"; error: unknown; value?: undefined; promise?: undefined }
206
- | {
207
- status: "loading";
208
- promise: Promise<T>;
209
- value?: undefined;
210
- error?: undefined;
211
- };
212
-
213
- /**
214
- * Result type for SelectContext.state() - simplified AtomState without promise.
215
- *
216
- * All properties (`status`, `value`, `error`) are always present:
217
- * - `value` is `T` when ready, `undefined` otherwise
218
- * - `error` is the error when errored, `undefined` otherwise
219
- *
220
- * This enables easy destructuring without type narrowing:
221
- * ```ts
222
- * const { status, value, error } = state(atom$);
223
- * ```
224
- *
225
- * Equality comparisons work correctly (no promise reference issues).
226
- */
227
- export type SelectStateResult<T> =
228
- | { status: "ready"; value: T; error: undefined }
229
- | { status: "error"; value: undefined; error: unknown }
230
- | { status: "loading"; value: undefined; error: undefined };
231
-
232
- /**
233
- * Result type for race() and any() - includes winning key.
234
- *
235
- * @template K - The key type (string literal union)
236
- * @template V - The value type
237
- */
238
- export type KeyedResult<K extends string, V> = {
239
- /** The key that won the race/any */
240
- key: K;
241
- /** The resolved value */
242
- value: V;
243
- };
244
-
245
- export type AtomPlugin = <T extends Atom<any>>(atom: T) => T | void;
246
-
247
- /**
248
- * Result type for settled operations.
249
- */
250
- export type SettledResult<T> =
251
- | { status: "ready"; value: T }
252
- | { status: "error"; error: unknown };
253
-
254
- /**
255
- * Configuration options for creating a mutable atom.
256
- *
257
- * @template T - The type of value stored in the atom
258
- */
259
- export interface AtomOptions<T> {
260
- /** Optional metadata for the atom */
261
- meta?: MutableAtomMeta;
262
- /** Equality strategy for change detection (default: "strict") */
263
- equals?: Equality<T>;
264
- }
265
-
266
- export interface MutableAtomMeta extends AtomMeta {}
267
-
268
- export interface DerivedAtomMeta extends AtomMeta {}
269
-
270
- /**
271
- * Configuration options for creating a derived atom.
272
- *
273
- * @template T - The type of the derived value
274
- */
275
- export interface DerivedOptions<T> {
276
- /** Optional metadata for the atom */
277
- meta?: DerivedAtomMeta;
278
- /** Equality strategy for change detection (default: "strict") */
279
- equals?: Equality<T>;
280
- /**
281
- * Callback invoked when the derived computation throws an error.
282
- * This is called for actual errors, NOT for Promise throws (Suspense).
283
- *
284
- * @param error - The error thrown during computation
285
- *
286
- * @example
287
- * ```ts
288
- * const data$ = derived(
289
- * ({ read }) => {
290
- * const raw = read(source$);
291
- * return JSON.parse(raw); // May throw SyntaxError
292
- * },
293
- * {
294
- * onError: (error) => {
295
- * console.error('Derived computation failed:', error);
296
- * reportToSentry(error);
297
- * }
298
- * }
299
- * );
300
- * ```
301
- */
302
- onError?: (error: unknown) => void;
303
- }
304
-
305
- /**
306
- * Configuration options for effects.
307
- */
308
- export interface EffectOptions {
309
- meta?: EffectMeta;
310
- /**
311
- * Callback invoked when the effect computation throws an error.
312
- * This is called for actual errors, NOT for Promise throws (Suspense).
313
- *
314
- * @param error - The error thrown during effect execution
315
- *
316
- * @example
317
- * ```ts
318
- * effect(
319
- * ({ read }) => {
320
- * const data = read(source$);
321
- * riskyOperation(data); // May throw
322
- * },
323
- * {
324
- * onError: (error) => {
325
- * console.error('Effect failed:', error);
326
- * showErrorNotification(error);
327
- * }
328
- * }
329
- * );
330
- * ```
331
- */
332
- onError?: (error: unknown) => void;
333
- }
334
-
335
- export interface AtomirxMeta {}
336
-
337
- export interface EffectMeta extends AtomirxMeta {
338
- key?: string;
339
- }
340
-
341
- /**
342
- * A function that returns a value when called.
343
- * Used for lazy evaluation in derived atoms.
344
- *
345
- * @template T - The type of value returned
346
- */
347
- export type Getter<T> = () => T;
348
-
349
- /**
350
- * Built-in equality strategy names.
351
- *
352
- * Used with atoms to control when subscribers are notified:
353
- * - `"strict"` - Object.is (default, fastest)
354
- * - `"shallow"` - Compare object keys/array items with Object.is
355
- * - `"shallow2"` - 2 levels deep
356
- * - `"shallow3"` - 3 levels deep
357
- * - `"deep"` - Full recursive comparison (slowest)
358
- */
359
- export type EqualityShorthand =
360
- | "strict"
361
- | "shallow"
362
- | "shallow2"
363
- | "shallow3"
364
- | "deep";
365
-
366
- /**
367
- * Equality strategy for change detection.
368
- *
369
- * Can be a shorthand string or custom comparison function.
370
- * Used by atoms to determine if value has "changed" -
371
- * if equal, subscribers won't be notified.
372
- *
373
- * @template T - Type of values being compared
374
- */
375
- export type Equality<T = unknown> =
376
- | EqualityShorthand
377
- | ((a: T, b: T) => boolean);
378
-
379
- /**
380
- * Prettify a type by adding all properties to the type.
381
- * @template T - The type to prettify
382
- */
383
- export type Prettify<T> = { [K in keyof T]: T[K] } & {};
384
-
385
- export interface ModuleMeta {}
386
-
387
- export type Listener<T> = (value: T) => void;
388
-
389
- export type SingleOrMultipleListeners<T> = Listener<T> | Listener<T>[];