@plyaz/types 1.22.4 → 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.
- package/dist/core/domain/types.d.ts +7 -1
- package/dist/core/frontend/featureFlags.d.ts +4 -7
- package/dist/core/frontend/types.d.ts +16 -9
- package/dist/core/init/types.d.ts +30 -16
- package/dist/examples/index.d.ts +1 -1
- package/dist/examples/types.d.ts +27 -11
- package/dist/store/types.d.ts +48 -2
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -4,10 +4,10 @@
|
|
|
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';
|
|
10
|
+
import type { RootStoreSlice } from '../../store';
|
|
11
11
|
import type { CoreBaseDomainServiceConfig } from '../domain';
|
|
12
12
|
import type { CoreBaseServiceConfig, CoreBaseMapperInstance, CoreBaseValidatorInstance } from '../domain';
|
|
13
13
|
import type { CoreDomainServiceInstance, CoreServiceEntry } from '../init';
|
|
@@ -531,16 +531,23 @@ export interface CoreStoreHandlers<TData = Record<string, unknown>, TStore exten
|
|
|
531
531
|
* Configuration for frontend domain services
|
|
532
532
|
*/
|
|
533
533
|
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
534
|
/**
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
535
|
+
* Primary store key - the main store this service can mutate.
|
|
536
|
+
* Service can call setData(), updateData(), setLoading() on this store.
|
|
537
|
+
* Type-safe: only valid store keys from RootStoreSlice allowed.
|
|
538
|
+
*
|
|
539
|
+
* @example 'example'
|
|
540
|
+
*/
|
|
541
|
+
store?: keyof RootStoreSlice;
|
|
542
|
+
/**
|
|
543
|
+
* Read-only store keys - stores this service can read from but not mutate.
|
|
544
|
+
* Service can access state but should not call mutation methods.
|
|
545
|
+
* Used for cross-domain data access (e.g., campaign service reading user data).
|
|
546
|
+
* Type-safe: only valid store keys from RootStoreSlice allowed.
|
|
547
|
+
*
|
|
548
|
+
* @example ['errors', 'featureFlags']
|
|
542
549
|
*/
|
|
543
|
-
|
|
550
|
+
readStores?: (keyof RootStoreSlice)[];
|
|
544
551
|
/** API base path for endpoints (e.g., '/api/examples') */
|
|
545
552
|
apiBasePath?: string;
|
|
546
553
|
/** Fetcher functions for API operations (replaces direct apiClient usage) */
|
|
@@ -5,10 +5,10 @@
|
|
|
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';
|
|
11
|
+
import type { RootStoreSlice } from '../../store';
|
|
12
12
|
import type { CoreAppEnvironment, CoreAppContext, CoreRuntimeEnvironment, CoreServiceRuntime } from '../modules';
|
|
13
13
|
import type { CoreDbServiceConfig } from '../services';
|
|
14
14
|
import type { CoreInjectedServices } from '../domain';
|
|
@@ -35,22 +35,27 @@ export interface CoreServiceInitConfig {
|
|
|
35
35
|
/** Whether the service is enabled (default: true) */
|
|
36
36
|
enabled?: boolean;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* The service's `allowedStoreKeys` static property defines valid options.
|
|
42
|
-
* If not specified, no stores will be connected (warning logged).
|
|
38
|
+
* Primary store key - the main store this service can mutate.
|
|
39
|
+
* The service can call setData(), updateData(), setLoading() on this store.
|
|
40
|
+
* Type-safe: only valid store keys allowed.
|
|
43
41
|
*
|
|
44
42
|
* @example
|
|
45
43
|
* ```typescript
|
|
46
|
-
*
|
|
47
|
-
*
|
|
44
|
+
* { service: CampaignService, config: { store: 'campaigns' } }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
store?: keyof RootStoreSlice;
|
|
48
|
+
/**
|
|
49
|
+
* Read-only store keys - stores this service can read from but not mutate.
|
|
50
|
+
* Used for cross-domain data access (e.g., campaign service reading user data).
|
|
51
|
+
* Type-safe: only valid store keys allowed.
|
|
48
52
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* { service: CampaignService, config: { store: 'campaigns', readStores: ['users', 'errors'] } }
|
|
51
56
|
* ```
|
|
52
57
|
*/
|
|
53
|
-
|
|
58
|
+
readStores?: (keyof RootStoreSlice)[];
|
|
54
59
|
/**
|
|
55
60
|
* When to initialize the service:
|
|
56
61
|
* - 'immediate': Initialize during Core.initialize() (default)
|
|
@@ -303,11 +308,6 @@ export interface CoreServiceCreateOptions<TConfig = unknown, TMapper = unknown,
|
|
|
303
308
|
loggerPrefix?: string;
|
|
304
309
|
/** Whether this is a singleton instance */
|
|
305
310
|
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
311
|
/**
|
|
312
312
|
* Injected service instances (cache, db, api).
|
|
313
313
|
* Services built by ServiceRegistry will receive these automatically.
|
|
@@ -387,6 +387,20 @@ export interface CoreServiceRegistryConfig {
|
|
|
387
387
|
db?: Partial<CoreDbServiceConfig>;
|
|
388
388
|
/** Global cache config (shared by all services unless overridden) */
|
|
389
389
|
cache?: CoreCacheConfig;
|
|
390
|
+
/**
|
|
391
|
+
* Store registry interface for injecting stores into services.
|
|
392
|
+
* Provides type-safe store access via store keys.
|
|
393
|
+
*
|
|
394
|
+
* @see RootStoreSlice in @plyaz/types/store for available stores
|
|
395
|
+
*/
|
|
396
|
+
stores?: {
|
|
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;
|
|
403
|
+
};
|
|
390
404
|
/** Services to register and initialize */
|
|
391
405
|
services: CoreServiceEntry[];
|
|
392
406
|
}
|
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,54 @@ export interface FeatureFlagStoreConfig {
|
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* Combined root store state and actions.
|
|
58
|
-
*
|
|
59
|
+
* Uses NAMESPACED structure for clear separation of slices.
|
|
60
|
+
*
|
|
61
|
+
* **Architecture:**
|
|
62
|
+
* - Global slices: errors, featureFlags (always included)
|
|
63
|
+
* - Domain slices: example, campaigns, users, etc. (add as needed)
|
|
64
|
+
* - Each slice is namespaced under its key (e.g., store.example.items)
|
|
65
|
+
*
|
|
66
|
+
* **Benefits of namespaced single-store:**
|
|
67
|
+
* - ✅ One Zustand instance - can access without hooks
|
|
68
|
+
* - ✅ Cross-slice subscriptions work automatically
|
|
69
|
+
* - ✅ Single source of truth via store.getState()
|
|
70
|
+
* - ✅ Clear ownership - no property name conflicts
|
|
71
|
+
* - ✅ getStore(key) returns specific slice (not entire root)
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const rootStore = useRootStore();
|
|
76
|
+
* rootStore.example.items; // Example slice
|
|
77
|
+
* rootStore.errors.errors; // Error slice
|
|
78
|
+
* rootStore.featureFlags.flags; // Feature flag slice
|
|
79
|
+
* ```
|
|
59
80
|
*/
|
|
60
|
-
export
|
|
81
|
+
export interface RootStoreSlice {
|
|
82
|
+
/** Error tracking slice (global) */
|
|
83
|
+
errors: ErrorStoreSlice;
|
|
84
|
+
/** Feature flags slice (global) */
|
|
85
|
+
featureFlags: FeatureFlagStoreSlice;
|
|
86
|
+
/** Example domain slice */
|
|
87
|
+
example: ExampleFrontendStoreSlice;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Type-safe store registry interface.
|
|
91
|
+
* Use this for dependency injection of stores.
|
|
92
|
+
*/
|
|
93
|
+
export interface StoreRegistry {
|
|
94
|
+
/**
|
|
95
|
+
* Get a store slice by key with full type safety.
|
|
96
|
+
* @param key - Store key from STORE_KEYS
|
|
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
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
getStore<K extends keyof RootStoreSlice>(key: K): RootStoreSlice[K] | undefined;
|
|
106
|
+
}
|
|
61
107
|
/**
|
|
62
108
|
* Configuration for creating the root store.
|
|
63
109
|
*/
|
package/package.json
CHANGED