@plyaz/types 1.22.5 → 1.22.6
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.
|
@@ -107,13 +107,19 @@ export type CoreValidatorClass<T extends CoreBaseValidatorInstance = CoreBaseVal
|
|
|
107
107
|
* Injected services/dependencies for domain services.
|
|
108
108
|
* These are created/managed by ServiceRegistry and injected into services.
|
|
109
109
|
*/
|
|
110
|
-
export interface CoreInjectedServices {
|
|
110
|
+
export interface CoreInjectedServices<TStores = unknown> {
|
|
111
111
|
/** Cache manager instance */
|
|
112
112
|
cache?: unknown;
|
|
113
113
|
/** Database service instance */
|
|
114
114
|
db?: unknown;
|
|
115
115
|
/** API client instance */
|
|
116
116
|
api?: unknown;
|
|
117
|
+
/**
|
|
118
|
+
* Store instances (from root store) keyed by store key.
|
|
119
|
+
* Type-safe: each key maps to its specific slice type.
|
|
120
|
+
* @example { example: ExampleStoreSlice, errors: ErrorStoreSlice }
|
|
121
|
+
*/
|
|
122
|
+
stores?: TStores extends Record<string, unknown> ? Partial<TStores> : Record<string, TStores>;
|
|
117
123
|
}
|
|
118
124
|
/**
|
|
119
125
|
* Base service configuration passed to constructor
|
|
@@ -53,15 +53,12 @@ export interface CoreFeatureFlagServiceInitConfig extends CoreBaseFrontendServic
|
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Base interface for frontend services with store integration
|
|
56
|
+
*
|
|
57
|
+
* Note: In the single root store architecture, stores are auto-injected
|
|
58
|
+
* by ServiceRegistry. Services no longer manually connect/disconnect stores.
|
|
56
59
|
*/
|
|
57
60
|
export interface CoreBaseFrontendServiceInterface<TStore extends CoreBaseFrontendStore = CoreBaseFrontendStore> extends CoreBaseDomainServiceInterface {
|
|
58
|
-
/**
|
|
59
|
-
connectStore(store: TStore): void;
|
|
60
|
-
/** Disconnect a store from receiving updates */
|
|
61
|
-
disconnectStore(store: TStore): void;
|
|
62
|
-
/** Disconnect all connected stores */
|
|
63
|
-
disconnectAllStores(): void;
|
|
64
|
-
/** Number of connected stores */
|
|
61
|
+
/** Number of connected stores (primary + read stores) */
|
|
65
62
|
readonly connectedStoreCount: number;
|
|
66
63
|
/** Whether any stores are connected */
|
|
67
64
|
readonly hasConnectedStores: boolean;
|
|
@@ -7,6 +7,7 @@ import type { ReactNode } from 'react';
|
|
|
7
7
|
import type { CoreBaseDomainServiceInterface } from '../domain';
|
|
8
8
|
import type { CoreAppEnvironment, CoreAppContext } from '../modules';
|
|
9
9
|
import type { FeatureFlagValue, FeatureFlagContext } from '../../features';
|
|
10
|
+
import type { RootStoreSlice } from '../../store';
|
|
10
11
|
import type { CoreBaseDomainServiceConfig } from '../domain';
|
|
11
12
|
import type { CoreBaseServiceConfig, CoreBaseMapperInstance, CoreBaseValidatorInstance } from '../domain';
|
|
12
13
|
import type { CoreDomainServiceInstance, CoreServiceEntry } from '../init';
|
|
@@ -533,19 +534,20 @@ export interface CoreBaseFrontendServiceConfig<TData = Record<string, unknown>,
|
|
|
533
534
|
/**
|
|
534
535
|
* Primary store key - the main store this service can mutate.
|
|
535
536
|
* Service can call setData(), updateData(), setLoading() on this store.
|
|
536
|
-
*
|
|
537
|
+
* Type-safe: only valid store keys from RootStoreSlice allowed.
|
|
537
538
|
*
|
|
538
|
-
* @example '
|
|
539
|
+
* @example 'example'
|
|
539
540
|
*/
|
|
540
|
-
store?:
|
|
541
|
+
store?: keyof RootStoreSlice;
|
|
541
542
|
/**
|
|
542
543
|
* Read-only store keys - stores this service can read from but not mutate.
|
|
543
544
|
* Service can access state but should not call mutation methods.
|
|
544
545
|
* Used for cross-domain data access (e.g., campaign service reading user data).
|
|
546
|
+
* Type-safe: only valid store keys from RootStoreSlice allowed.
|
|
545
547
|
*
|
|
546
|
-
* @example ['
|
|
548
|
+
* @example ['errors', 'featureFlags']
|
|
547
549
|
*/
|
|
548
|
-
readStores?:
|
|
550
|
+
readStores?: (keyof RootStoreSlice)[];
|
|
549
551
|
/** API base path for endpoints (e.g., '/api/examples') */
|
|
550
552
|
apiBasePath?: string;
|
|
551
553
|
/** Fetcher functions for API operations (replaces direct apiClient usage) */
|
|
@@ -8,6 +8,7 @@ import type { ApiClientOptions } from '../../api';
|
|
|
8
8
|
import type { FeatureFlagValue, FeatureFlagPollingConfig, CacheStrategyType } from '../../features';
|
|
9
9
|
import type { PackageErrorLike, MessageCatalog } from '../../errors';
|
|
10
10
|
import type { GlobalErrorHandlerConfig, ErrorHandlerLogger } from '../../errors/middleware';
|
|
11
|
+
import type { RootStoreSlice } from '../../store';
|
|
11
12
|
import type { CoreAppEnvironment, CoreAppContext, CoreRuntimeEnvironment, CoreServiceRuntime } from '../modules';
|
|
12
13
|
import type { CoreDbServiceConfig } from '../services';
|
|
13
14
|
import type { CoreInjectedServices } from '../domain';
|
|
@@ -36,23 +37,25 @@ export interface CoreServiceInitConfig {
|
|
|
36
37
|
/**
|
|
37
38
|
* Primary store key - the main store this service can mutate.
|
|
38
39
|
* The service can call setData(), updateData(), setLoading() on this store.
|
|
40
|
+
* Type-safe: only valid store keys allowed.
|
|
39
41
|
*
|
|
40
42
|
* @example
|
|
41
43
|
* ```typescript
|
|
42
44
|
* { service: CampaignService, config: { store: 'campaigns' } }
|
|
43
45
|
* ```
|
|
44
46
|
*/
|
|
45
|
-
store?:
|
|
47
|
+
store?: keyof RootStoreSlice;
|
|
46
48
|
/**
|
|
47
49
|
* Read-only store keys - stores this service can read from but not mutate.
|
|
48
50
|
* Used for cross-domain data access (e.g., campaign service reading user data).
|
|
51
|
+
* Type-safe: only valid store keys allowed.
|
|
49
52
|
*
|
|
50
53
|
* @example
|
|
51
54
|
* ```typescript
|
|
52
|
-
* { service: CampaignService, config: { store: 'campaigns', readStores: ['users', '
|
|
55
|
+
* { service: CampaignService, config: { store: 'campaigns', readStores: ['users', 'errors'] } }
|
|
53
56
|
* ```
|
|
54
57
|
*/
|
|
55
|
-
readStores?:
|
|
58
|
+
readStores?: (keyof RootStoreSlice)[];
|
|
56
59
|
/**
|
|
57
60
|
* When to initialize the service:
|
|
58
61
|
* - 'immediate': Initialize during Core.initialize() (default)
|
|
@@ -386,13 +389,17 @@ export interface CoreServiceRegistryConfig {
|
|
|
386
389
|
cache?: CoreCacheConfig;
|
|
387
390
|
/**
|
|
388
391
|
* Store registry interface for injecting stores into services.
|
|
389
|
-
* Provides type-safe store access via
|
|
392
|
+
* Provides type-safe store access via store keys.
|
|
390
393
|
*
|
|
391
|
-
* @see
|
|
394
|
+
* @see RootStoreSlice in @plyaz/types/store for available stores
|
|
392
395
|
*/
|
|
393
396
|
stores?: {
|
|
394
|
-
/**
|
|
395
|
-
|
|
397
|
+
/**
|
|
398
|
+
* Get a store slice by key with full type safety.
|
|
399
|
+
* @param key - Store key (e.g., 'example', 'errors', 'featureFlags')
|
|
400
|
+
* @returns Typed store slice or undefined
|
|
401
|
+
*/
|
|
402
|
+
getStore<K extends keyof RootStoreSlice>(key: K): RootStoreSlice[K] | undefined;
|
|
396
403
|
};
|
|
397
404
|
/** Services to register and initialize */
|
|
398
405
|
services: CoreServiceEntry[];
|
package/dist/store/types.d.ts
CHANGED
|
@@ -56,35 +56,34 @@ export interface FeatureFlagStoreConfig {
|
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Combined root store state and actions.
|
|
59
|
-
*
|
|
59
|
+
* Uses NAMESPACED structure for clear separation of slices.
|
|
60
60
|
*
|
|
61
61
|
* **Architecture:**
|
|
62
|
-
* - Global slices:
|
|
62
|
+
* - Global slices: errors, featureFlags (always included)
|
|
63
63
|
* - Domain slices: example, campaigns, users, etc. (add as needed)
|
|
64
|
+
* - Each slice is namespaced under its key (e.g., store.example.items)
|
|
64
65
|
*
|
|
65
|
-
* **Benefits of single-store:**
|
|
66
|
+
* **Benefits of namespaced single-store:**
|
|
66
67
|
* - ✅ One Zustand instance - can access without hooks
|
|
67
68
|
* - ✅ Cross-slice subscriptions work automatically
|
|
68
69
|
* - ✅ Single source of truth via store.getState()
|
|
69
|
-
* - ✅
|
|
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.
|
|
70
|
+
* - ✅ Clear ownership - no property name conflicts
|
|
71
|
+
* - ✅ getStore(key) returns specific slice (not entire root)
|
|
75
72
|
*
|
|
76
|
-
* Add new stores here for type-safe store access:
|
|
77
73
|
* @example
|
|
78
74
|
* ```typescript
|
|
79
|
-
* const
|
|
75
|
+
* const rootStore = useRootStore();
|
|
76
|
+
* rootStore.example.items; // Example slice
|
|
77
|
+
* rootStore.errors.errors; // Error slice
|
|
78
|
+
* rootStore.featureFlags.flags; // Feature flag slice
|
|
80
79
|
* ```
|
|
81
80
|
*/
|
|
82
|
-
export interface
|
|
83
|
-
/** Error
|
|
84
|
-
|
|
85
|
-
/** Feature flags
|
|
81
|
+
export interface RootStoreSlice {
|
|
82
|
+
/** Error tracking slice (global) */
|
|
83
|
+
errors: ErrorStoreSlice;
|
|
84
|
+
/** Feature flags slice (global) */
|
|
86
85
|
featureFlags: FeatureFlagStoreSlice;
|
|
87
|
-
/** Example
|
|
86
|
+
/** Example domain slice */
|
|
88
87
|
example: ExampleFrontendStoreSlice;
|
|
89
88
|
}
|
|
90
89
|
/**
|
|
@@ -93,11 +92,17 @@ export interface StoreTypeMap {
|
|
|
93
92
|
*/
|
|
94
93
|
export interface StoreRegistry {
|
|
95
94
|
/**
|
|
96
|
-
* Get a store by key with full type safety.
|
|
95
|
+
* Get a store slice by key with full type safety.
|
|
97
96
|
* @param key - Store key from STORE_KEYS
|
|
98
|
-
* @returns Typed store
|
|
97
|
+
* @returns Typed store slice or undefined
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const exampleSlice = getStore('example'); // Returns ExampleFrontendStoreSlice
|
|
102
|
+
* const errorSlice = getStore('errors'); // Returns ErrorStoreSlice
|
|
103
|
+
* ```
|
|
99
104
|
*/
|
|
100
|
-
getStore<K extends keyof
|
|
105
|
+
getStore<K extends keyof RootStoreSlice>(key: K): RootStoreSlice[K] | undefined;
|
|
101
106
|
}
|
|
102
107
|
/**
|
|
103
108
|
* Configuration for creating the root store.
|
package/package.json
CHANGED