@sladg/apex-state 3.1.0 → 3.2.1
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/README.md +2 -0
- package/dist/apply-changes-C2oP5CnU.d.ts +1554 -0
- package/dist/index.d.ts +5 -1549
- package/dist/index.js +225 -232
- package/dist/index.js.map +1 -1
- package/dist/testing/index.d.ts +113 -0
- package/dist/testing/index.js +2140 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { D as DeepKey, a as DeepValue, G as GenericMeta, g as ConcernType, y as defaultConcerns, q as StoreConfig, a2 as GenericStoreApi } from '../apply-changes-C2oP5CnU.js';
|
|
2
|
+
export { _, w as applyChangesToObject, z as dot, H as evaluateBoolLogic, I as extractPlaceholders, J as findConcern, M as hashKey, N as interpolateTemplate, Q as is, R as prebuilts, U as registerFlipPair, W as registerListenerLegacy, X as registerSideEffects, Y as registerSyncPairsBatch, Z as useBufferedField, $ as useKeyboardSelect, a0 as useThrottledField, a1 as useTransformedField } from '../apply-changes-C2oP5CnU.js';
|
|
3
|
+
import 'react/jsx-runtime';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @sladg/apex-state/testing
|
|
8
|
+
*
|
|
9
|
+
* Lightweight mock of the main module for consumer tests.
|
|
10
|
+
* No real pipeline, no WASM, no concerns — just bare-bones
|
|
11
|
+
* reactive state with call tracking.
|
|
12
|
+
*
|
|
13
|
+
* Consumer setup:
|
|
14
|
+
* __mocks__/@sladg/apex-state.ts:
|
|
15
|
+
* export * from '@sladg/apex-state/testing'
|
|
16
|
+
*
|
|
17
|
+
* Then in tests:
|
|
18
|
+
* vi.mock('@sladg/apex-state')
|
|
19
|
+
* import { __mocked } from '@sladg/apex-state/testing'
|
|
20
|
+
*
|
|
21
|
+
* // Inspect state, calls, effects
|
|
22
|
+
* expect(__mocked.state.calls).toHaveLength(1)
|
|
23
|
+
* // Programmatically set values
|
|
24
|
+
* __mocked.set('user.email', 'hello@example.com')
|
|
25
|
+
* // Reset between tests
|
|
26
|
+
* __mocked.reset()
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
interface MockCall {
|
|
30
|
+
path: string;
|
|
31
|
+
value: unknown;
|
|
32
|
+
meta?: unknown;
|
|
33
|
+
}
|
|
34
|
+
interface MockEffect {
|
|
35
|
+
id: string;
|
|
36
|
+
type: 'concerns' | 'sideEffects';
|
|
37
|
+
registration: unknown;
|
|
38
|
+
}
|
|
39
|
+
declare const __state: {
|
|
40
|
+
/** Current store state (reactive valtio proxy) */
|
|
41
|
+
value: Record<string, unknown>;
|
|
42
|
+
/** Log of all setValue / setChanges calls */
|
|
43
|
+
calls: MockCall[];
|
|
44
|
+
/** Log of all useConcerns / useSideEffects registrations */
|
|
45
|
+
effects: MockEffect[];
|
|
46
|
+
};
|
|
47
|
+
/** Typed chainable returned by `__mocked.set<T>()` — path+value pairs are type-checked */
|
|
48
|
+
interface TypedMock<T extends object> {
|
|
49
|
+
set: <P extends DeepKey<T>>(path: P, value: DeepValue<T, P>) => TypedMock<T>;
|
|
50
|
+
state: typeof __state;
|
|
51
|
+
getState: () => T;
|
|
52
|
+
flush: () => Promise<void>;
|
|
53
|
+
reset: () => void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Mock control object for test assertions and state manipulation.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { __mocked } from '@sladg/apex-state/testing'
|
|
61
|
+
*
|
|
62
|
+
* beforeEach(() => __mocked.reset())
|
|
63
|
+
*
|
|
64
|
+
* // First .set<T>() seeds data and returns typed chainable
|
|
65
|
+
* __mocked.set<MyState>({ email: '' })
|
|
66
|
+
* .set('email', 'a@b.com') // DeepKey<MyState> — autocomplete + type-checked
|
|
67
|
+
* .set('name', 'Alice')
|
|
68
|
+
*
|
|
69
|
+
* // Or just establish the type without seeding
|
|
70
|
+
* __mocked.set<MyState>()
|
|
71
|
+
* .set('email', 'a@b.com')
|
|
72
|
+
*
|
|
73
|
+
* // Assertions
|
|
74
|
+
* expect(__mocked.state.calls).toHaveLength(1)
|
|
75
|
+
* expect(__mocked.getState()).toEqual({ ... })
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare const __mocked: {
|
|
79
|
+
/** Reactive proxy — access .value, .calls, .effects for assertions */
|
|
80
|
+
state: {
|
|
81
|
+
/** Current store state (reactive valtio proxy) */
|
|
82
|
+
value: Record<string, unknown>;
|
|
83
|
+
/** Log of all setValue / setChanges calls */
|
|
84
|
+
calls: MockCall[];
|
|
85
|
+
/** Log of all useConcerns / useSideEffects registrations */
|
|
86
|
+
effects: MockEffect[];
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Seed mock state and return typed chainable.
|
|
90
|
+
* - `set<T>()` — establish type, no seeding
|
|
91
|
+
* - `set<T>(data)` — merge data into state, establish type
|
|
92
|
+
* Subsequent `.set(path, value)` calls are type-safe against T.
|
|
93
|
+
*/
|
|
94
|
+
set: <T extends object>(data?: Partial<T>) => TypedMock<T>;
|
|
95
|
+
/** Get an immutable snapshot of the current state */
|
|
96
|
+
getState: () => {
|
|
97
|
+
readonly [x: string]: unknown;
|
|
98
|
+
};
|
|
99
|
+
/** Flush pending valtio-triggered React renders */
|
|
100
|
+
flush: () => Promise<void>;
|
|
101
|
+
/** Reset all mock state between tests */
|
|
102
|
+
reset: () => void;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Mock version of createGenericStore.
|
|
106
|
+
*
|
|
107
|
+
* Returns the same API shape as the real module but backed by a shared
|
|
108
|
+
* module-level valtio proxy (__mocked.state). No pipeline, no WASM,
|
|
109
|
+
* no concerns evaluation — just reactive state with call tracking.
|
|
110
|
+
*/
|
|
111
|
+
declare const createGenericStore: <DATA extends object, META extends GenericMeta = GenericMeta, CONCERNS extends readonly ConcernType<string, any, any>[] = typeof defaultConcerns>(_config?: StoreConfig) => GenericStoreApi<DATA, META, CONCERNS>;
|
|
112
|
+
|
|
113
|
+
export { __mocked, createGenericStore, defaultConcerns };
|