juststore 1.2.1 → 1.2.2

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/form.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { FieldPath, FieldPathValue, FieldValues, IsEqual } from './path';
2
- import type { ArrayProxy, DerivedStateProps, ObjectMutationMethods, Prettify, ValueState } from './types';
2
+ import type { ArrayProxy, DerivedStateProps, ObjectMutationMethods, ObjectStateValue, Prettify, ValueState } from './types';
3
3
  export { type CreateFormOptions, createForm, type DeepNonNullable, type FormArrayState, type FormObjectState, type FormState, type FormStore, type FormValueState, useForm };
4
4
  /**
5
5
  * Common form field methods available on every form state node.
@@ -35,17 +35,17 @@ interface FormValueState<T> extends Omit<ValueState<T>, 'ensureArray' | 'ensureO
35
35
  */
36
36
  derived: <R>({ from, to }: DerivedStateProps<T, R>) => FormState<R>;
37
37
  }
38
- type FormObjectProxy<T extends FieldValues> = {
38
+ type FormObjectProxy<T extends FieldValues, TObject = T> = {
39
39
  /** Virtual state for the object's keys.
40
40
  *
41
41
  * This does NOT read from a real `keys` property on the stored object; it results in a stable array of keys.
42
42
  */
43
43
  readonly keys: FormReadOnlyState<FieldPath<T>[]>;
44
44
  } & {
45
- [K in keyof T]-?: FormState<T[K]>;
45
+ [K in keyof T]-?: FormState<ObjectStateValue<TObject, T, K>>;
46
46
  };
47
47
  type FormArrayState<TValue, TArray = TValue[]> = IsEqual<TValue, unknown> extends true ? never : FormValueState<TArray> & ArrayProxy<TValue, FormState<TValue>>;
48
- type FormObjectState<TNonNullable extends FieldValues, TObject = TNonNullable> = FormObjectProxy<TNonNullable> & FormValueState<TObject> & ObjectMutationMethods;
48
+ type FormObjectState<TNonNullable extends FieldValues, TObject = TNonNullable> = FormObjectProxy<TNonNullable, TObject> & FormValueState<TObject> & ObjectMutationMethods;
49
49
  /** Type for nested objects with proxy methods */
50
50
  type DeepNonNullable<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U[] : [NonNullable<T>] extends [FieldValues] ? {
51
51
  [K in keyof NonNullable<T>]-?: DeepNonNullable<NonNullable<T>[K]>;
package/dist/store.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { FieldValues } from './path';
2
2
  import { type StoreOptions } from './root';
3
- import type { State, StoreRoot } from './types';
3
+ import type { ObjectProxy, StoreRoot } from './types';
4
4
  export { createStore, type Store };
5
5
  /**
6
6
  * A persistent, hierarchical, cross-tab synchronized key-value store with React bindings.
@@ -13,9 +13,7 @@ export { createStore, type Store };
13
13
  * - Type-safe paths using FieldPath.
14
14
  * - Dynamic deep access via Proxy for ergonomic usage like `store.a.b.c.use()` and `store.a.b.c.set(v)`.
15
15
  */
16
- type Store<T extends FieldValues> = StoreRoot<T> & {
17
- [K in keyof T]-?: State<T[K]>;
18
- };
16
+ type Store<T extends FieldValues> = StoreRoot<T> & ObjectProxy<T>;
19
17
  /**
20
18
  * Creates a persistent, hierarchical store with localStorage backing and cross-tab synchronization.
21
19
  *
package/dist/types.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import type { FieldPath, FieldPathValue, FieldValues, IsEqual } from './path';
2
- export type { AllowedKeys, ArrayProxy, ArrayState, DerivedStateProps, ObjectMutationMethods, ObjectState, Prettify, ReadOnlyState, State, StoreRoot, StoreSetStateValue, StoreUseComputeFn, StoreUseState, ValueState };
2
+ export type { AllowedKeys, ArrayProxy, ArrayState, DerivedStateProps, ObjectMutationMethods, ObjectProxy, ObjectState, ObjectStateValue, Prettify, ReadOnlyState, State, StoreRoot, StoreSetStateValue, StoreUseComputeFn, StoreUseState, ValueState };
3
3
  type Prettify<T> = {
4
4
  [K in keyof T]: T[K];
5
5
  } & {};
6
6
  type AllowedKeys<T> = Exclude<keyof T, keyof ValueState<unknown> | keyof ObjectMutationMethods>;
7
+ type MaybeMissingParent<TParent, TValue> = undefined extends TParent ? TValue | undefined : null extends TParent ? TValue | undefined : TValue;
8
+ type ObjectStateValue<TObject, TNonNullable extends FieldValues, K extends keyof TNonNullable> = {} extends TNonNullable ? TNonNullable[K] | undefined : MaybeMissingParent<TObject, TNonNullable[K]>;
7
9
  type ArrayMutationMethods<T> = Prettify<Pick<Array<T>, 'push' | 'pop' | 'shift' | 'unshift' | 'splice' | 'reverse' | 'sort' | 'fill' | 'copyWithin'>>;
8
10
  /** Type for array proxy with index access */
9
11
  type ArrayProxy<T, ElementState = State<T>> = ArrayMutationMethods<NonNullable<T>> & {
@@ -25,14 +27,14 @@ type ArrayProxy<T, ElementState = State<T>> = ArrayMutationMethods<NonNullable<T
25
27
  /** Insert items into the array in sorted order using the provided comparison function. */
26
28
  sortedInsert(cmp: (a: T, b: T) => number, ...items: T[]): number;
27
29
  };
28
- type ObjectProxy<T extends FieldValues> = {
30
+ type ObjectProxy<T extends FieldValues, TObject = T> = {
29
31
  /** Virtual state for the object's keys.
30
32
  *
31
33
  * This does NOT read from a real `keys` property on the stored object; it results in a stable array of keys.
32
34
  */
33
35
  readonly keys: ReadOnlyState<FieldPath<T>[]>;
34
36
  } & {
35
- [K in keyof T]-?: State<T[K]>;
37
+ [K in keyof T]-?: State<ObjectStateValue<TObject, T, K>>;
36
38
  };
37
39
  type ObjectMutationMethods = {
38
40
  /** Rename a key in an object. */
@@ -131,7 +133,7 @@ type ValueState<T> = {
131
133
  type ReadOnlyState<T> = Prettify<Pick<ValueState<Readonly<Required<T>>>, 'value' | 'use' | 'useCompute'>>;
132
134
  type State<T> = IsEqual<T, unknown> extends true ? never : [NonNullable<T>] extends [readonly (infer U)[]] ? ArrayState<U, T> : [NonNullable<T>] extends [FieldValues] ? ObjectState<NonNullable<T>, T> : ValueState<T>;
133
135
  type ArrayState<TValue, TArray = TValue[]> = IsEqual<TValue, unknown> extends true ? never : ValueState<TArray> & ArrayProxy<TValue>;
134
- type ObjectState<TNonNullable extends FieldValues, TObject = TNonNullable> = ObjectProxy<TNonNullable> & ValueState<TObject> & ObjectMutationMethods;
136
+ type ObjectState<TNonNullable extends FieldValues, TObject = TNonNullable> = ObjectProxy<TNonNullable, TObject> & ValueState<TObject> & ObjectMutationMethods;
135
137
  /** Type for useCompute function. */
136
138
  type StoreUseComputeFn<T extends FieldValues, P extends FieldPath<T>, R> = (value: FieldPathValue<T, P>) => R;
137
139
  type DerivedStateProps<T, R> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juststore",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "A small, expressive, and type-safe state management library for React.",
5
5
  "keywords": [
6
6
  "hooks",