@plyaz/types 1.22.6 → 1.22.8

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.
@@ -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
- * addItem: (item) => set((state) => ({ items: [...state.items, item] })),
70
- * updateItem: (id, item) => set((state) => ({
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
- * removeItem: (id) => set((state) => ({
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()` → service calls custom `addItem()` in `afterCreate` hook
83
- * - After `update()` → service calls custom `updateItem()` in `afterUpdate` hook
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
@@ -726,18 +837,6 @@ export interface CoreFeatureFlagStoreInitConfig {
726
837
  * Base service config for frontend services (constructor config)
727
838
  */
728
839
  export interface CoreBaseFrontendServiceConstructorConfig<TConfig extends CoreBaseFrontendServiceConfig<TData, TStore>, TStore extends CoreBaseFrontendStore<TData>, TData = Record<string, unknown>, TMapper extends CoreBaseMapperInstance = CoreBaseMapperInstance, TValidator extends CoreBaseValidatorInstance = CoreBaseValidatorInstance> extends CoreBaseServiceConfig<TConfig, TMapper, TValidator> {
729
- /**
730
- * Data key used for store sync - indicates which property in the store contains the primary data.
731
- *
732
- * Examples:
733
- * - For feature flags: 'flags' (store has flags property)
734
- * - For items/entities: 'items' (store has items property)
735
- * - For nested data: 'nested.items' (store has nested.items)
736
- *
737
- * This is used as metadata and for potential helper methods.
738
- * For custom sync behavior, use `storeHandlers` in serviceConfig instead.
739
- */
740
- storeDataKey?: string;
741
840
  }
742
841
  /**
743
842
  * Props for initialization error component
@@ -9,6 +9,7 @@ import type { CreateExampleSchema, UpdateExampleSchema, PatchExampleSchema, Quer
9
9
  import type { CoreEntityCreatedPayload, CoreEntityUpdatedPayload, CoreEntityDeletedPayload, CoreValidationFailedPayload } from '../core/events';
10
10
  import type { CoreBaseFrontendStore, CoreBaseFrontendServiceConfig } from '../core/frontend';
11
11
  import type { CoreServiceInitConfig } from '../core/init';
12
+ import type { CoreInjectedServices } from '../core/domain';
12
13
  /**
13
14
  * Create request DTO (POST body)
14
15
  */
@@ -123,17 +124,9 @@ export interface ExampleFrontendStoreState {
123
124
  }
124
125
  /**
125
126
  * Example frontend store actions.
126
- * Extends CoreBaseFrontendStore to ensure required methods are present.
127
+ * Extends CoreBaseFrontendStore which provides all CRUD methods.
127
128
  */
128
129
  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
130
  /** Select an item by ID */
138
131
  selectItem: (id: string | null) => void;
139
132
  }
@@ -152,6 +145,8 @@ export interface ExampleFrontendServiceConfig extends CoreBaseFrontendServiceCon
152
145
  autoFetch?: boolean;
153
146
  /** Polling interval in ms (0 = disabled) */
154
147
  pollingInterval?: number;
148
+ /** Injected services (for testing/manual store injection) */
149
+ injected?: CoreInjectedServices;
155
150
  }
156
151
  /**
157
152
  * Example frontend event types
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.22.6",
3
+ "version": "1.22.8",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",