@plyaz/types 1.22.4 → 1.22.5
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 +14 -9
- package/dist/core/init/types.d.ts +23 -16
- package/dist/examples/index.d.ts +1 -1
- package/dist/examples/types.d.ts +27 -11
- package/dist/store/types.d.ts +43 -2
- package/package.json +1 -1
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Type definitions for frontend domain services with store integration.
|
|
5
5
|
*/
|
|
6
6
|
import type { ReactNode } from 'react';
|
|
7
|
-
import type { StoreKey } from '../../store';
|
|
8
7
|
import type { CoreBaseDomainServiceInterface } from '../domain';
|
|
9
8
|
import type { CoreAppEnvironment, CoreAppContext } from '../modules';
|
|
10
9
|
import type { FeatureFlagValue, FeatureFlagContext } from '../../features';
|
|
@@ -531,16 +530,22 @@ export interface CoreStoreHandlers<TData = Record<string, unknown>, TStore exten
|
|
|
531
530
|
* Configuration for frontend domain services
|
|
532
531
|
*/
|
|
533
532
|
export interface CoreBaseFrontendServiceConfig<TData = Record<string, unknown>, TStore extends CoreBaseFrontendStore<TData> = CoreBaseFrontendStore<TData>> extends CoreBaseDomainServiceConfig {
|
|
534
|
-
/** Single store to connect on initialization */
|
|
535
|
-
store?: TStore;
|
|
536
|
-
/** Multiple stores to connect on initialization */
|
|
537
|
-
stores?: TStore[];
|
|
538
533
|
/**
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
534
|
+
* Primary store key - the main store this service can mutate.
|
|
535
|
+
* Service can call setData(), updateData(), setLoading() on this store.
|
|
536
|
+
* Must be a valid store key from the service's allowedStoreKeys.
|
|
537
|
+
*
|
|
538
|
+
* @example 'campaigns'
|
|
539
|
+
*/
|
|
540
|
+
store?: string;
|
|
541
|
+
/**
|
|
542
|
+
* Read-only store keys - stores this service can read from but not mutate.
|
|
543
|
+
* Service can access state but should not call mutation methods.
|
|
544
|
+
* Used for cross-domain data access (e.g., campaign service reading user data).
|
|
545
|
+
*
|
|
546
|
+
* @example ['users', 'error', 'featureFlags']
|
|
542
547
|
*/
|
|
543
|
-
|
|
548
|
+
readStores?: string[];
|
|
544
549
|
/** API base path for endpoints (e.g., '/api/examples') */
|
|
545
550
|
apiBasePath?: string;
|
|
546
551
|
/** Fetcher functions for API operations (replaces direct apiClient usage) */
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* Services must implement these interfaces to be auto-initialized.
|
|
6
6
|
*/
|
|
7
7
|
import type { ApiClientOptions } from '../../api';
|
|
8
|
-
import type { StoreKey } from '../../store';
|
|
9
8
|
import type { FeatureFlagValue, FeatureFlagPollingConfig, CacheStrategyType } from '../../features';
|
|
10
9
|
import type { PackageErrorLike, MessageCatalog } from '../../errors';
|
|
11
10
|
import type { GlobalErrorHandlerConfig, ErrorHandlerLogger } from '../../errors/middleware';
|
|
@@ -35,22 +34,25 @@ export interface CoreServiceInitConfig {
|
|
|
35
34
|
/** Whether the service is enabled (default: true) */
|
|
36
35
|
enabled?: boolean;
|
|
37
36
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* Each frontend service can specify which stores it needs access to.
|
|
41
|
-
* The service's `allowedStoreKeys` static property defines valid options.
|
|
42
|
-
* If not specified, no stores will be connected (warning logged).
|
|
37
|
+
* Primary store key - the main store this service can mutate.
|
|
38
|
+
* The service can call setData(), updateData(), setLoading() on this store.
|
|
43
39
|
*
|
|
44
40
|
* @example
|
|
45
41
|
* ```typescript
|
|
46
|
-
*
|
|
47
|
-
*
|
|
42
|
+
* { service: CampaignService, config: { store: 'campaigns' } }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
store?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Read-only store keys - stores this service can read from but not mutate.
|
|
48
|
+
* Used for cross-domain data access (e.g., campaign service reading user data).
|
|
48
49
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* { service: CampaignService, config: { store: 'campaigns', readStores: ['users', 'error'] } }
|
|
51
53
|
* ```
|
|
52
54
|
*/
|
|
53
|
-
|
|
55
|
+
readStores?: string[];
|
|
54
56
|
/**
|
|
55
57
|
* When to initialize the service:
|
|
56
58
|
* - 'immediate': Initialize during Core.initialize() (default)
|
|
@@ -303,11 +305,6 @@ export interface CoreServiceCreateOptions<TConfig = unknown, TMapper = unknown,
|
|
|
303
305
|
loggerPrefix?: string;
|
|
304
306
|
/** Whether this is a singleton instance */
|
|
305
307
|
isSingleton?: boolean;
|
|
306
|
-
/**
|
|
307
|
-
* Store keys this service should connect to.
|
|
308
|
-
* Passed from the service config to the create method.
|
|
309
|
-
*/
|
|
310
|
-
storeKeys?: StoreKey[];
|
|
311
308
|
/**
|
|
312
309
|
* Injected service instances (cache, db, api).
|
|
313
310
|
* Services built by ServiceRegistry will receive these automatically.
|
|
@@ -387,6 +384,16 @@ export interface CoreServiceRegistryConfig {
|
|
|
387
384
|
db?: Partial<CoreDbServiceConfig>;
|
|
388
385
|
/** Global cache config (shared by all services unless overridden) */
|
|
389
386
|
cache?: CoreCacheConfig;
|
|
387
|
+
/**
|
|
388
|
+
* Store registry interface for injecting stores into services.
|
|
389
|
+
* Provides type-safe store access via generics.
|
|
390
|
+
*
|
|
391
|
+
* @see StoreTypeMap in @plyaz/types/store for available stores
|
|
392
|
+
*/
|
|
393
|
+
stores?: {
|
|
394
|
+
/** Get a store by key with full type safety via generics */
|
|
395
|
+
getStore<T = unknown>(key: string): T | undefined;
|
|
396
|
+
};
|
|
390
397
|
/** Services to register and initialize */
|
|
391
398
|
services: CoreServiceEntry[];
|
|
392
399
|
}
|
package/dist/examples/index.d.ts
CHANGED
|
@@ -14,4 +14,4 @@
|
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export { CreateExampleSchema, UpdateExampleSchema, PatchExampleSchema, QueryExampleSchema, DeleteExampleSchema, ExampleResponseSchema, ExampleListResponseSchema, } from './schemas';
|
|
17
|
-
export type { CreateExampleDTO, UpdateExampleDTO, PatchExampleDTO, QueryExampleDTO, DeleteExampleDTO, ExampleResponseDTO, ExampleListResponseDTO, ExampleEntity, ExampleStoreItem, ExampleStoreState, ExampleCreatedPayload, ExampleUpdatedPayload, ExampleDeletedPayload, ExampleValidationFailedPayload, ExampleFrontendStoreData,
|
|
17
|
+
export type { CreateExampleDTO, UpdateExampleDTO, PatchExampleDTO, QueryExampleDTO, DeleteExampleDTO, ExampleResponseDTO, ExampleListResponseDTO, ExampleEntity, ExampleStoreItem, ExampleStoreState, ExampleCreatedPayload, ExampleUpdatedPayload, ExampleDeletedPayload, ExampleValidationFailedPayload, ExampleFrontendStoreData, ExampleFrontendStoreState, ExampleFrontendStoreActions, ExampleFrontendStoreSlice, ExampleFrontendServiceConfig, ExampleFrontendEventType, ExampleUser, ExampleDomainServiceConfig, } from './types';
|
package/dist/examples/types.d.ts
CHANGED
|
@@ -111,25 +111,41 @@ export interface ExampleFrontendStoreData {
|
|
|
111
111
|
selectedId: string | null;
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
* Example frontend store
|
|
114
|
+
* Example frontend store state shape.
|
|
115
115
|
*/
|
|
116
|
-
export interface
|
|
116
|
+
export interface ExampleFrontendStoreState {
|
|
117
|
+
/** Array of example items */
|
|
117
118
|
items: ExampleEntity[];
|
|
119
|
+
/** Currently selected item ID */
|
|
118
120
|
selectedId: string | null;
|
|
121
|
+
/** Loading state */
|
|
119
122
|
isLoading: boolean;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Example frontend store actions.
|
|
126
|
+
* Extends CoreBaseFrontendStore to ensure required methods are present.
|
|
127
|
+
*/
|
|
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
|
+
/** Select an item by ID */
|
|
138
|
+
selectItem: (id: string | null) => void;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Complete example frontend store slice (state + actions).
|
|
142
|
+
*/
|
|
143
|
+
export interface ExampleFrontendStoreSlice extends ExampleFrontendStoreState, ExampleFrontendStoreActions {
|
|
128
144
|
}
|
|
129
145
|
/**
|
|
130
146
|
* Example Frontend Service Configuration
|
|
131
147
|
*/
|
|
132
|
-
export interface ExampleFrontendServiceConfig extends CoreBaseFrontendServiceConfig<ExampleFrontendStoreData,
|
|
148
|
+
export interface ExampleFrontendServiceConfig extends CoreBaseFrontendServiceConfig<ExampleFrontendStoreData, ExampleFrontendStoreSlice>, CoreServiceInitConfig {
|
|
133
149
|
/** API base path for example endpoints */
|
|
134
150
|
apiBasePath?: string;
|
|
135
151
|
/** Auto-fetch on initialization */
|
package/dist/store/types.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { SerializedError, ErrorStoreActions, ErrorStoreSlice } from '../errors/store';
|
|
10
10
|
import type { FeatureFlagStoreState, FeatureFlagStoreSlice } from '../features/feature-flag/store.types';
|
|
11
|
+
import type { ExampleFrontendStoreSlice } from '../examples';
|
|
11
12
|
/**
|
|
12
13
|
* Configuration for creating an error store.
|
|
13
14
|
*/
|
|
@@ -55,9 +56,49 @@ export interface FeatureFlagStoreConfig {
|
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* Combined root store state and actions.
|
|
58
|
-
* Merges
|
|
59
|
+
* Merges ALL slice types into a single store interface.
|
|
60
|
+
*
|
|
61
|
+
* **Architecture:**
|
|
62
|
+
* - Global slices: error, featureFlags (always included)
|
|
63
|
+
* - Domain slices: example, campaigns, users, etc. (add as needed)
|
|
64
|
+
*
|
|
65
|
+
* **Benefits of single-store:**
|
|
66
|
+
* - ✅ One Zustand instance - can access without hooks
|
|
67
|
+
* - ✅ Cross-slice subscriptions work automatically
|
|
68
|
+
* - ✅ Single source of truth via store.getState()
|
|
69
|
+
* - ✅ All slices can read/update each other
|
|
70
|
+
*/
|
|
71
|
+
export type RootStoreSlice = ErrorStoreSlice & FeatureFlagStoreSlice & ExampleFrontendStoreSlice;
|
|
72
|
+
/**
|
|
73
|
+
* Type map of all available stores in the system.
|
|
74
|
+
* Maps store keys to their corresponding store types.
|
|
75
|
+
*
|
|
76
|
+
* Add new stores here for type-safe store access:
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const exampleStore = getStore<'example'>('example'); // Fully typed!
|
|
80
|
+
* ```
|
|
59
81
|
*/
|
|
60
|
-
export
|
|
82
|
+
export interface StoreTypeMap {
|
|
83
|
+
/** Error store - global error tracking (root store slice) */
|
|
84
|
+
error: ErrorStoreSlice;
|
|
85
|
+
/** Feature flags store - global feature flag state (root store slice) */
|
|
86
|
+
featureFlags: FeatureFlagStoreSlice;
|
|
87
|
+
/** Example store - example domain store (demonstrates pattern) */
|
|
88
|
+
example: ExampleFrontendStoreSlice;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Type-safe store registry interface.
|
|
92
|
+
* Use this for dependency injection of stores.
|
|
93
|
+
*/
|
|
94
|
+
export interface StoreRegistry {
|
|
95
|
+
/**
|
|
96
|
+
* Get a store by key with full type safety.
|
|
97
|
+
* @param key - Store key from STORE_KEYS
|
|
98
|
+
* @returns Typed store instance or undefined
|
|
99
|
+
*/
|
|
100
|
+
getStore<K extends keyof StoreTypeMap>(key: K): StoreTypeMap[K] | undefined;
|
|
101
|
+
}
|
|
61
102
|
/**
|
|
62
103
|
* Configuration for creating the root store.
|
|
63
104
|
*/
|
package/package.json
CHANGED