@but212/atom-effect 0.27.0 → 0.29.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.
package/dist/index.d.ts CHANGED
@@ -31,6 +31,17 @@ export declare class AtomError extends Error {
31
31
  constructor(message: string, cause?: Error | null, recoverable?: boolean);
32
32
  }
33
33
 
34
+ /**
35
+ * Creates a two-way "lens" for a specific property path on an object-based atom.
36
+ *
37
+ * @example
38
+ * const store = atom({ user: { name: 'Alice' } });
39
+ * const nameLens = atomLens(store, 'user.name');
40
+ * console.log(nameLens.value); // 'Alice'
41
+ * nameLens.value = 'Bob'; // Updates store.user.name immutably
42
+ */
43
+ export declare function atomLens<T extends object, P extends Paths<T>>(atom: WritableAtom<T>, path: P): WritableAtom<PathValue<T, P>>;
44
+
34
45
  /**
35
46
  * Atom options.
36
47
  */
@@ -47,6 +58,11 @@ export declare interface AtomOptions {
47
58
  */
48
59
  export declare function batch<T>(fn: () => T): T;
49
60
 
61
+ /**
62
+ * Composes an existing lens with a sub-path to create a deeper lens.
63
+ */
64
+ export declare const composeLens: <T extends object, P extends Paths<T>>(lens: WritableAtom<T>, path: P) => WritableAtom<PathValue<T, P>>;
65
+
50
66
  /**
51
67
  * Creates a computed value.
52
68
  * @param fn - Computation function
@@ -93,8 +109,6 @@ export declare interface ComputedOptions<T = unknown> {
93
109
  lazy?: boolean;
94
110
  /** Error handler. */
95
111
  onError?: (error: Error) => void;
96
- /** Maximum number of async retries before giving up (default: 3). */
97
- maxAsyncRetries?: number;
98
112
  }
99
113
 
100
114
  /**
@@ -186,6 +200,11 @@ export declare interface EffectOptions {
186
200
  onError?: (error: unknown) => void;
187
201
  }
188
202
 
203
+ /**
204
+ * Helper to retrieve a nested value from an object/array at a given path.
205
+ */
206
+ export declare function getPathValue(source: unknown, parts: string[]): unknown;
207
+
189
208
  /**
190
209
  * Readonly atom check.
191
210
  *
@@ -203,6 +222,36 @@ export declare function isComputed(obj: unknown): obj is ComputedAtom;
203
222
  */
204
223
  export declare function isEffect(obj: unknown): obj is EffectObject;
205
224
 
225
+ /**
226
+ * Creates a lens factory bound to a specific atom.
227
+ */
228
+ export declare const lensFor: <T extends object>(atom: WritableAtom<T>) => <P extends Paths<T>>(path: P) => WritableAtom<PathValue<T, P>>;
229
+
230
+ /** Max recursion depth for dot-paths. */
231
+ export declare type MaxDepth = 8;
232
+
233
+ /**
234
+ * Generates a union of all possible dot-separated paths for a given type T.
235
+ *
236
+ * Used for `atomLens` to provide IDE autocomplete and type safety when
237
+ * zooming into deeply nested reactive objects.
238
+ *
239
+ * @example
240
+ * type User = { profile: { name: string } };
241
+ * type P = Paths<User>; // "profile" | "profile.name"
242
+ */
243
+ export declare type Paths<T, D extends unknown[] = []> = D['length'] extends MaxDepth ? never : T extends object ? {
244
+ [K in keyof T & (string | number)]-?: `${K}` | (T[K] extends object ? `${K}.${Paths<T[K], [...D, 1]>}` : never);
245
+ }[keyof T & (string | number)] : never;
246
+
247
+ /**
248
+ * Resolves the type of a value at a specific dot-path P within type T.
249
+ *
250
+ * Works in tandem with `Paths<T>` to ensure that lensed atoms have
251
+ * the correct inferred type for the member they point to.
252
+ */
253
+ export declare type PathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? StringKeyToNumber<K> extends keyof T ? PathValue<T[StringKeyToNumber<K> & keyof T], Rest> : never : StringKeyToNumber<P> extends keyof T ? T[StringKeyToNumber<P> & keyof T] : never;
254
+
206
255
  export declare interface PoolStats {
207
256
  acquired: number;
208
257
  released: number;
@@ -319,6 +368,15 @@ declare interface SchedulerJobObject {
319
368
  _nextEpoch?: number;
320
369
  }
321
370
 
371
+ /**
372
+ * Internal recursive helper for creating deep immutable copies with structural sharing.
373
+ * Only clones nodes along the path where changes occur.
374
+ */
375
+ export declare function setDeepValue(obj: unknown, keys: string[], index: number, value: unknown): unknown;
376
+
377
+ /** Helper to convert numeric string to number for array indexing. */
378
+ export declare type StringKeyToNumber<S extends string> = S extends `${infer N extends number}` ? N : S;
379
+
322
380
  export declare interface Subscriber {
323
381
  execute(): void;
324
382
  }