@plyaz/types 1.22.6 → 1.22.7
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/core/frontend/types.d.ts +129 -18
- package/dist/examples/types.d.ts +1 -9
- package/package.json +1 -1
|
@@ -41,36 +41,28 @@ import type { CoreDomainServiceInstance, CoreServiceEntry } from '../init';
|
|
|
41
41
|
* selectedId: string | null;
|
|
42
42
|
* }
|
|
43
43
|
*
|
|
44
|
+
* // Extend CoreBaseFrontendStore - all CRUD methods included in base
|
|
44
45
|
* interface MyStore extends CoreBaseFrontendStore<MyStoreData> {
|
|
45
46
|
* items: MyEntity[];
|
|
46
47
|
* selectedId: string | null;
|
|
47
48
|
* isLoading: boolean;
|
|
48
|
-
*
|
|
49
|
-
* // Required by CoreBaseFrontendStore
|
|
50
|
-
* setData: (data: MyStoreData) => void;
|
|
51
|
-
* updateData: (data: Partial<MyStoreData>) => void;
|
|
52
|
-
* setLoading: (isLoading: boolean) => void;
|
|
53
|
-
*
|
|
54
|
-
* // Domain-specific methods
|
|
55
|
-
* addItem: (item: MyEntity) => void;
|
|
56
|
-
* updateItem: (id: string, item: MyEntity) => void;
|
|
57
|
-
* removeItem: (id: string) => void;
|
|
58
49
|
* }
|
|
59
50
|
*
|
|
60
|
-
* export const useMyStore = create<MyStore>((set) => ({
|
|
51
|
+
* export const useMyStore = create<MyStore>((set, get) => ({
|
|
61
52
|
* items: [],
|
|
62
53
|
* selectedId: null,
|
|
63
54
|
* isLoading: false,
|
|
64
55
|
*
|
|
56
|
+
* // CoreBaseFrontendStore methods
|
|
57
|
+
* getData: () => ({ items: get().items, selectedId: get().selectedId }),
|
|
65
58
|
* setData: (data) => set({ items: data.items, selectedId: data.selectedId }),
|
|
66
59
|
* updateData: (data) => set((state) => ({ ...state, ...data })),
|
|
67
60
|
* setLoading: (isLoading) => set({ isLoading }),
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* items: state.items.map((i) => (i.id === id ? item : i)),
|
|
61
|
+
* addData: (item) => set((state) => ({ items: [...state.items, item] })),
|
|
62
|
+
* updateDataById: (id, item) => set((state) => ({
|
|
63
|
+
* items: state.items.map((i) => i.id === id ? { ...i, ...item } : i),
|
|
72
64
|
* })),
|
|
73
|
-
*
|
|
65
|
+
* removeData: (id) => set((state) => ({
|
|
74
66
|
* items: state.items.filter((i) => i.id !== id),
|
|
75
67
|
* })),
|
|
76
68
|
* }));
|
|
@@ -79,8 +71,9 @@ import type { CoreDomainServiceInstance, CoreServiceEntry } from '../init';
|
|
|
79
71
|
* ## Service Integration
|
|
80
72
|
* Services automatically call these methods after successful operations:
|
|
81
73
|
* - After `fetchAll()` → calls `setData()` with full dataset
|
|
82
|
-
* - After `create()` →
|
|
83
|
-
* - After `update()` →
|
|
74
|
+
* - After `create()` → calls `addData()` to append new item
|
|
75
|
+
* - After `update()` → calls `updateDataById()` to update specific item
|
|
76
|
+
* - After `delete()` → calls `removeData()` to remove item
|
|
84
77
|
* - Before any operation → calls `setLoading(true)`
|
|
85
78
|
* - After operation completes → calls `setLoading(false)`
|
|
86
79
|
*
|
|
@@ -90,6 +83,20 @@ import type { CoreDomainServiceInstance, CoreServiceEntry } from '../init';
|
|
|
90
83
|
* @see {@link BaseFrontendDomainService} for service implementation
|
|
91
84
|
*/
|
|
92
85
|
export interface CoreBaseFrontendStore<TData = Record<string, unknown>> {
|
|
86
|
+
/**
|
|
87
|
+
* Get current store data.
|
|
88
|
+
*
|
|
89
|
+
* Used by services to read current state for operations like delete
|
|
90
|
+
* (filter out item) or optimistic updates.
|
|
91
|
+
*
|
|
92
|
+
* @returns Current data object
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* getData: () => ({ items: get().items, selectedId: get().selectedId })
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
getData?(): TData;
|
|
93
100
|
/**
|
|
94
101
|
* Set/replace all data in the store (full replacement).
|
|
95
102
|
*
|
|
@@ -133,6 +140,55 @@ export interface CoreBaseFrontendStore<TData = Record<string, unknown>> {
|
|
|
133
140
|
* ```
|
|
134
141
|
*/
|
|
135
142
|
setLoading?(isLoading: boolean): void;
|
|
143
|
+
/**
|
|
144
|
+
* Add data to store (append to array).
|
|
145
|
+
*
|
|
146
|
+
* Called by services after successful create operations.
|
|
147
|
+
* Store implementation handles appending to the items array.
|
|
148
|
+
*
|
|
149
|
+
* @param item - Item to add
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* addData: (item) => set((state) => ({
|
|
154
|
+
* items: [...state.items, item]
|
|
155
|
+
* }))
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
addData?(item: unknown): void;
|
|
159
|
+
/**
|
|
160
|
+
* Update data in store by ID.
|
|
161
|
+
*
|
|
162
|
+
* Called by services after successful update operations.
|
|
163
|
+
* Store implementation handles finding and updating the specific item.
|
|
164
|
+
*
|
|
165
|
+
* @param id - Item ID to update
|
|
166
|
+
* @param item - Updated item data
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* updateDataById: (id, item) => set((state) => ({
|
|
171
|
+
* items: state.items.map((i) => i.id === id ? { ...i, ...item } : i)
|
|
172
|
+
* }))
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
updateDataById?(id: string, item: unknown): void;
|
|
176
|
+
/**
|
|
177
|
+
* Remove data from store by ID.
|
|
178
|
+
*
|
|
179
|
+
* Called by services after successful delete operations.
|
|
180
|
+
* Store implementation handles filtering out the item.
|
|
181
|
+
*
|
|
182
|
+
* @param id - Item ID to remove
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* removeData: (id) => set((state) => ({
|
|
187
|
+
* items: state.items.filter((item) => item.id !== id)
|
|
188
|
+
* }))
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
removeData?(id: string): void;
|
|
136
192
|
}
|
|
137
193
|
/**
|
|
138
194
|
* Fetcher function type for API operations
|
|
@@ -526,6 +582,61 @@ export interface CoreStoreHandlers<TData = Record<string, unknown>, TStore exten
|
|
|
526
582
|
* ```
|
|
527
583
|
*/
|
|
528
584
|
setLoading?: (store: TStore, isLoading: boolean) => void;
|
|
585
|
+
/**
|
|
586
|
+
* Custom handler for adding data to store.
|
|
587
|
+
*
|
|
588
|
+
* Replaces the default `store.addData(item)` call.
|
|
589
|
+
* Called during create operations.
|
|
590
|
+
*
|
|
591
|
+
* @param store - Store instance
|
|
592
|
+
* @param item - Item to add
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* ```typescript
|
|
596
|
+
* addData: (store, item) => {
|
|
597
|
+
* store.appendItem(item);
|
|
598
|
+
* store.setLastCreated(item.id);
|
|
599
|
+
* }
|
|
600
|
+
* ```
|
|
601
|
+
*/
|
|
602
|
+
addData?: (store: TStore, item: unknown) => void;
|
|
603
|
+
/**
|
|
604
|
+
* Custom handler for updating data by ID.
|
|
605
|
+
*
|
|
606
|
+
* Replaces the default `store.updateDataById(id, item)` call.
|
|
607
|
+
* Called during update operations.
|
|
608
|
+
*
|
|
609
|
+
* @param store - Store instance
|
|
610
|
+
* @param id - Item ID to update
|
|
611
|
+
* @param item - Updated item data
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
* ```typescript
|
|
615
|
+
* updateDataById: (store, id, item) => {
|
|
616
|
+
* store.updateItemById(id, item);
|
|
617
|
+
* store.setLastUpdated(id);
|
|
618
|
+
* }
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
updateDataById?: (store: TStore, id: string, item: unknown) => void;
|
|
622
|
+
/**
|
|
623
|
+
* Custom handler for removing data by ID.
|
|
624
|
+
*
|
|
625
|
+
* Replaces the default `store.removeData(id)` call.
|
|
626
|
+
* Called during delete operations.
|
|
627
|
+
*
|
|
628
|
+
* @param store - Store instance
|
|
629
|
+
* @param id - Item ID to remove
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```typescript
|
|
633
|
+
* removeData: (store, id) => {
|
|
634
|
+
* store.removeItemById(id);
|
|
635
|
+
* store.clearSelection();
|
|
636
|
+
* }
|
|
637
|
+
* ```
|
|
638
|
+
*/
|
|
639
|
+
removeData?: (store: TStore, id: string) => void;
|
|
529
640
|
}
|
|
530
641
|
/**
|
|
531
642
|
* Configuration for frontend domain services
|
package/dist/examples/types.d.ts
CHANGED
|
@@ -123,17 +123,9 @@ export interface ExampleFrontendStoreState {
|
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
125
|
* Example frontend store actions.
|
|
126
|
-
* Extends CoreBaseFrontendStore
|
|
126
|
+
* Extends CoreBaseFrontendStore which provides all CRUD methods.
|
|
127
127
|
*/
|
|
128
128
|
export interface ExampleFrontendStoreActions extends CoreBaseFrontendStore<ExampleFrontendStoreData> {
|
|
129
|
-
/** Set items array */
|
|
130
|
-
setItems: (items: ExampleEntity[]) => void;
|
|
131
|
-
/** Add a single item */
|
|
132
|
-
addItem: (item: ExampleEntity) => void;
|
|
133
|
-
/** Update a single item */
|
|
134
|
-
updateItem: (id: string, updates: Partial<ExampleEntity>) => void;
|
|
135
|
-
/** Remove a single item */
|
|
136
|
-
removeItem: (id: string) => void;
|
|
137
129
|
/** Select an item by ID */
|
|
138
130
|
selectItem: (id: string | null) => void;
|
|
139
131
|
}
|
package/package.json
CHANGED