@plyaz/types 1.22.1 → 1.22.2
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/api/index.cjs.map +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/core/domain/crud.d.ts +27 -0
- package/dist/core/domain/index.d.ts +2 -1
- package/dist/core/domain/types.d.ts +34 -0
- package/dist/core/events/payloads.d.ts +1 -0
- package/dist/core/frontend/featureFlags.d.ts +3 -3
- package/dist/core/frontend/index.d.ts +1 -1
- package/dist/core/frontend/types.d.ts +544 -8
- package/dist/core/index.d.ts +1 -0
- package/dist/core/init/index.d.ts +1 -1
- package/dist/core/init/types.d.ts +111 -2
- package/dist/core/services/index.d.ts +1 -0
- package/dist/core/services/keys.d.ts +40 -0
- package/dist/errors/codes.d.ts +11 -0
- package/dist/errors/index.cjs +13 -1
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.js +13 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/examples/types.d.ts +9 -5
- package/dist/features/cache/index.cjs +6 -0
- package/dist/features/cache/index.cjs.map +1 -1
- package/dist/features/cache/index.d.ts +1 -0
- package/dist/features/cache/index.js +5 -0
- package/dist/features/cache/index.js.map +1 -1
- package/dist/features/cache/types.d.ts +9 -1
- package/dist/features/index.cjs +6 -0
- package/dist/features/index.cjs.map +1 -1
- package/dist/features/index.d.ts +1 -0
- package/dist/features/index.js +5 -0
- package/dist/features/index.js.map +1 -1
- package/dist/index.cjs +30 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +28 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { ApiClientOptions } from '../../api';
|
|
8
8
|
import type { StoreKey } from '../../store';
|
|
9
|
-
import type { FeatureFlagValue, FeatureFlagPollingConfig } from '../../features';
|
|
9
|
+
import type { FeatureFlagValue, FeatureFlagPollingConfig, CacheStrategyType } from '../../features';
|
|
10
10
|
import type { PackageErrorLike } from '../../errors';
|
|
11
11
|
import type { GlobalErrorHandlerConfig, ErrorHandlerLogger } from '../../errors/middleware';
|
|
12
12
|
import type { CoreAppEnvironment, CoreAppContext, CoreRuntimeEnvironment } from '../modules';
|
|
@@ -148,6 +148,42 @@ export interface CoreServiceInitConfig {
|
|
|
148
148
|
* ```
|
|
149
149
|
*/
|
|
150
150
|
dedicatedDb?: boolean | Partial<CoreDbServiceConfig>;
|
|
151
|
+
/**
|
|
152
|
+
* Create a dedicated cache instance for this service.
|
|
153
|
+
*
|
|
154
|
+
* By default, services share the global cache instance. Use this when
|
|
155
|
+
* a service needs its own isolated cache (e.g., different TTL, separate namespace).
|
|
156
|
+
*
|
|
157
|
+
* - `false` or `undefined`: Use global shared cache (default)
|
|
158
|
+
* - `true`: Create dedicated instance using global config
|
|
159
|
+
* - `CoreCacheConfig`: Create dedicated instance with custom config
|
|
160
|
+
*
|
|
161
|
+
* For Redis strategy, services using the same URL will share connections.
|
|
162
|
+
* For memory strategy, each service gets its own isolated cache.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* // Use global shared cache (default)
|
|
167
|
+
* { service: UserService, config: { enabled: true } }
|
|
168
|
+
*
|
|
169
|
+
* // Create dedicated cache with global config
|
|
170
|
+
* { service: SessionService, config: { dedicatedCache: true } }
|
|
171
|
+
*
|
|
172
|
+
* // Create dedicated cache with custom config
|
|
173
|
+
* {
|
|
174
|
+
* service: RateLimitService,
|
|
175
|
+
* config: {
|
|
176
|
+
* dedicatedCache: {
|
|
177
|
+
* strategy: 'redis',
|
|
178
|
+
* isEnabled: true,
|
|
179
|
+
* ttl: 60, // 1 minute TTL for rate limits
|
|
180
|
+
* prefix: 'ratelimit',
|
|
181
|
+
* },
|
|
182
|
+
* },
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
dedicatedCache?: boolean | CoreCacheConfig;
|
|
151
187
|
}
|
|
152
188
|
/**
|
|
153
189
|
* Options passed to the service factory method
|
|
@@ -168,6 +204,11 @@ export interface CoreServiceCreateOptions {
|
|
|
168
204
|
* Used to create dedicated instance or configure global.
|
|
169
205
|
*/
|
|
170
206
|
options?: ApiClientOptions;
|
|
207
|
+
/**
|
|
208
|
+
* Actual API client instance to use.
|
|
209
|
+
* Injected by ServiceRegistry, not created by service.
|
|
210
|
+
*/
|
|
211
|
+
instance?: unknown;
|
|
171
212
|
};
|
|
172
213
|
/**
|
|
173
214
|
* Database configuration and mode.
|
|
@@ -184,6 +225,32 @@ export interface CoreServiceCreateOptions {
|
|
|
184
225
|
* Used to create dedicated instance or configure global.
|
|
185
226
|
*/
|
|
186
227
|
config?: Partial<CoreDbServiceConfig>;
|
|
228
|
+
/**
|
|
229
|
+
* Actual database service instance to use.
|
|
230
|
+
* Injected by ServiceRegistry, not created by service.
|
|
231
|
+
*/
|
|
232
|
+
instance?: unknown;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Cache configuration and mode.
|
|
236
|
+
*/
|
|
237
|
+
cache?: {
|
|
238
|
+
/**
|
|
239
|
+
* Whether to use a dedicated (isolated) cache instance.
|
|
240
|
+
* - `false`: Use global shared instance (default)
|
|
241
|
+
* - `true`: Create dedicated instance
|
|
242
|
+
*/
|
|
243
|
+
dedicated: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Cache config (merged global + per-service config).
|
|
246
|
+
* Used to create dedicated instance or configure global.
|
|
247
|
+
*/
|
|
248
|
+
config?: CoreCacheConfig;
|
|
249
|
+
/**
|
|
250
|
+
* Actual CacheManager instance to use.
|
|
251
|
+
* Injected by ServiceRegistry, not created by service.
|
|
252
|
+
*/
|
|
253
|
+
instance?: unknown;
|
|
187
254
|
};
|
|
188
255
|
/** Logger prefix */
|
|
189
256
|
loggerPrefix?: string;
|
|
@@ -258,10 +325,16 @@ export interface CoreServiceEntry<TConfig extends CoreServiceInitConfig = CoreSe
|
|
|
258
325
|
* ```
|
|
259
326
|
*/
|
|
260
327
|
export interface CoreServiceRegistryConfig {
|
|
328
|
+
/** Global environment (production, staging, development, test) */
|
|
329
|
+
environment?: CoreAppEnvironment;
|
|
330
|
+
/** Runtime environment (node, browser, react-native, etc.) */
|
|
331
|
+
runtime?: CoreRuntimeEnvironment;
|
|
261
332
|
/** Global API client options (shared by all services unless overridden) */
|
|
262
333
|
apiClient?: ApiClientOptions;
|
|
263
334
|
/** Global database config (shared by all services unless overridden) */
|
|
264
335
|
db?: Partial<CoreDbServiceConfig>;
|
|
336
|
+
/** Global cache config (shared by all services unless overridden) */
|
|
337
|
+
cache?: CoreCacheConfig;
|
|
265
338
|
/** Services to register and initialize */
|
|
266
339
|
services: CoreServiceEntry[];
|
|
267
340
|
}
|
|
@@ -321,6 +394,36 @@ export interface CoreErrorHandlerInitConfig extends Omit<GlobalErrorHandlerConfi
|
|
|
321
394
|
*/
|
|
322
395
|
logger?: ErrorHandlerLogger | boolean;
|
|
323
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* Cache initialization configuration
|
|
399
|
+
*/
|
|
400
|
+
export interface CoreCacheConfig {
|
|
401
|
+
/** Cache strategy to use */
|
|
402
|
+
strategy: CacheStrategyType;
|
|
403
|
+
/** Whether caching is enabled (default: true) */
|
|
404
|
+
isEnabled: boolean;
|
|
405
|
+
/** Default TTL in seconds (default: 300 - 5 minutes) */
|
|
406
|
+
ttl?: number;
|
|
407
|
+
/** Key prefix for all cache entries (default: 'app') */
|
|
408
|
+
prefix?: string;
|
|
409
|
+
/** Redis-specific configuration (required when strategy is 'redis') */
|
|
410
|
+
redis?: {
|
|
411
|
+
/** Redis connection URL (e.g., redis://localhost:6379) */
|
|
412
|
+
url?: string;
|
|
413
|
+
/** Redis host (alternative to url) */
|
|
414
|
+
host?: string;
|
|
415
|
+
/** Redis port (default: 6379) */
|
|
416
|
+
port?: number;
|
|
417
|
+
/** Redis password */
|
|
418
|
+
password?: string;
|
|
419
|
+
/** Redis database number (default: 0) */
|
|
420
|
+
db?: number;
|
|
421
|
+
/** Connection timeout in milliseconds */
|
|
422
|
+
connectTimeout?: number;
|
|
423
|
+
/** Key prefix for Redis keys */
|
|
424
|
+
keyPrefix?: string;
|
|
425
|
+
};
|
|
426
|
+
}
|
|
324
427
|
/**
|
|
325
428
|
* Base core initialization options
|
|
326
429
|
* Extended by @plyaz/core's CoreInitOptions with specific types
|
|
@@ -338,10 +441,14 @@ export interface CoreInitOptionsBase<TDb = unknown, TApi = unknown> {
|
|
|
338
441
|
db?: TDb;
|
|
339
442
|
/** API client configuration */
|
|
340
443
|
api?: TApi;
|
|
444
|
+
/** Cache configuration */
|
|
445
|
+
cache?: CoreCacheConfig;
|
|
341
446
|
/** Skip database initialization */
|
|
342
447
|
skipDb?: boolean;
|
|
343
448
|
/** Skip API client initialization */
|
|
344
449
|
skipApi?: boolean;
|
|
450
|
+
/** Skip cache initialization */
|
|
451
|
+
skipCache?: boolean;
|
|
345
452
|
/** Enable verbose logging */
|
|
346
453
|
verbose?: boolean;
|
|
347
454
|
/** Error handler configuration */
|
|
@@ -354,11 +461,13 @@ export interface CoreInitOptionsBase<TDb = unknown, TApi = unknown> {
|
|
|
354
461
|
/**
|
|
355
462
|
* Core services result from initialization
|
|
356
463
|
*/
|
|
357
|
-
export interface CoreServicesResultBase<TDb = unknown, TApi = unknown> {
|
|
464
|
+
export interface CoreServicesResultBase<TDb = unknown, TApi = unknown, TCache = unknown> {
|
|
358
465
|
/** Database service instance (null if skipped or on frontend) */
|
|
359
466
|
db: TDb | null;
|
|
360
467
|
/** API client service class */
|
|
361
468
|
api: TApi | null;
|
|
469
|
+
/** Cache service instance (null if skipped or on frontend) */
|
|
470
|
+
cache: TCache | null;
|
|
362
471
|
/** Loaded environment variables */
|
|
363
472
|
env: Record<string, string | undefined>;
|
|
364
473
|
/** Detected runtime environment */
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Keys Constants
|
|
3
|
+
*
|
|
4
|
+
* Centralized service key constants for service registry and dependency injection.
|
|
5
|
+
* Use these constants instead of string literals for type safety and consistency.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { SERVICE_KEYS } from '@plyaz/types/core/services';
|
|
10
|
+
*
|
|
11
|
+
* class MyService {
|
|
12
|
+
* static readonly serviceKey = SERVICE_KEYS.EXAMPLE;
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* // Use in service registry
|
|
16
|
+
* const service = ServiceRegistry.get(SERVICE_KEYS.EXAMPLE);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Keys for all available domain services.
|
|
21
|
+
* These keys are used for service registration and lookup in the ServiceRegistry.
|
|
22
|
+
*/
|
|
23
|
+
export declare const SERVICE_KEYS: {
|
|
24
|
+
/** Example domain service (backend) */
|
|
25
|
+
readonly EXAMPLE: "example";
|
|
26
|
+
/** Example domain service (frontend) */
|
|
27
|
+
readonly EXAMPLE_FRONTEND: "example-frontend";
|
|
28
|
+
/** Feature flags service */
|
|
29
|
+
readonly FEATURE_FLAGS: "featureFlags";
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Type for service keys.
|
|
33
|
+
* Ensures only valid service keys can be used.
|
|
34
|
+
*/
|
|
35
|
+
export type ServiceKey = (typeof SERVICE_KEYS)[keyof typeof SERVICE_KEYS];
|
|
36
|
+
/**
|
|
37
|
+
* Array of all service keys for iteration.
|
|
38
|
+
* Useful for validating service configurations or iterating over all services.
|
|
39
|
+
*/
|
|
40
|
+
export declare const ALL_SERVICE_KEYS: ServiceKey[];
|
package/dist/errors/codes.d.ts
CHANGED
|
@@ -826,6 +826,17 @@ export declare const CORE_ERROR_CODES: {
|
|
|
826
826
|
readonly CONFIGURATION_INVALID: "core.configuration_invalid";
|
|
827
827
|
readonly OPERATION_FAILED: "core.operation_failed";
|
|
828
828
|
readonly UNKNOWN_ERROR: "core.unknown_error";
|
|
829
|
+
readonly CLIENT_INITIALIZATION_FAILED: "CLIENT_INITIALIZATION_FAILED";
|
|
830
|
+
readonly CLIENT_INVALID_CONFIG: "CLIENT_INVALID_CONFIG";
|
|
831
|
+
readonly CONTEXT_OPERATION_FAILED: "CONTEXT_OPERATION_FAILED";
|
|
832
|
+
readonly FEATURE_NOT_SUPPORTED: "feature.not.supported";
|
|
833
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
834
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
835
|
+
readonly RESOURCE_NOT_FOUND: "RESOURCE_NOT_FOUND";
|
|
836
|
+
readonly DB_CONNECTION_FAILED: "db.connection_failed";
|
|
837
|
+
readonly DB_DUPLICATE_ENTRY: "db.duplicate_entry";
|
|
838
|
+
readonly PROVIDER_NOT_IMPLEMENTED: "provider.not.implemented";
|
|
839
|
+
readonly STORAGE_FILE_WRITE_FAILED: "storage.file.write.failed";
|
|
829
840
|
};
|
|
830
841
|
/**
|
|
831
842
|
* PAYMENT-specific error codes
|
package/dist/errors/index.cjs
CHANGED
|
@@ -1324,7 +1324,19 @@ var CORE_ERROR_CODES = {
|
|
|
1324
1324
|
INITIALIZATION_FAILED: ERROR_CODES.CORE_INITIALIZATION_FAILED,
|
|
1325
1325
|
CONFIGURATION_INVALID: ERROR_CODES.CORE_CONFIGURATION_INVALID,
|
|
1326
1326
|
OPERATION_FAILED: ERROR_CODES.CORE_OPERATION_FAILED,
|
|
1327
|
-
UNKNOWN_ERROR: ERROR_CODES.CORE_UNKNOWN_ERROR
|
|
1327
|
+
UNKNOWN_ERROR: ERROR_CODES.CORE_UNKNOWN_ERROR,
|
|
1328
|
+
// Common/Generic Errors (used across core package)
|
|
1329
|
+
CLIENT_INITIALIZATION_FAILED: ERROR_CODES.CLIENT_INITIALIZATION_FAILED,
|
|
1330
|
+
CLIENT_INVALID_CONFIG: ERROR_CODES.CLIENT_INVALID_CONFIG,
|
|
1331
|
+
CONTEXT_OPERATION_FAILED: ERROR_CODES.CONTEXT_OPERATION_FAILED,
|
|
1332
|
+
FEATURE_NOT_SUPPORTED: ERROR_CODES.FEATURE_NOT_SUPPORTED,
|
|
1333
|
+
VALIDATION_ERROR: ERROR_CODES.VALIDATION_ERROR,
|
|
1334
|
+
NETWORK_ERROR: ERROR_CODES.NETWORK_ERROR,
|
|
1335
|
+
RESOURCE_NOT_FOUND: ERROR_CODES.RESOURCE_NOT_FOUND,
|
|
1336
|
+
DB_CONNECTION_FAILED: ERROR_CODES.DB_CONNECTION_FAILED,
|
|
1337
|
+
DB_DUPLICATE_ENTRY: ERROR_CODES.DB_DUPLICATE_ENTRY,
|
|
1338
|
+
PROVIDER_NOT_IMPLEMENTED: ERROR_CODES.PROVIDER_NOT_IMPLEMENTED,
|
|
1339
|
+
STORAGE_FILE_WRITE_FAILED: ERROR_CODES.STORAGE_FILE_WRITE_FAILED
|
|
1328
1340
|
};
|
|
1329
1341
|
var PAYMENT_ERROR_CODES = {
|
|
1330
1342
|
// Timeout & Network
|