@plyaz/types 1.9.1 → 1.9.3

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.
@@ -38,6 +38,7 @@ export type * from './config/types';
38
38
  export type * from './utils/types';
39
39
  export type * from './pubsub/types';
40
40
  export type * from './hooks/types';
41
+ export type * from './services/types';
41
42
  export type * from './endpoints/types';
42
43
  export type * from './endpoints/health/types';
43
44
  export type * from './endpoints/campaigns/types';
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Service Layer Types
3
+ * Core types for service functions and configuration
4
+ */
5
+ import type { ApiClientWithEvents, UpdateConfigOptions } from '../client/types';
6
+ import type { ApiConfig } from '../config';
7
+ /**
8
+ * Options for service functions
9
+ * Allows overriding the API client instance, temporary config updates, and update strategy
10
+ *
11
+ * By default, services use a shared client instance with all available endpoints.
12
+ * This interface allows customization of the client behavior per-request or permanently.
13
+ *
14
+ * @template TEndpoints - The endpoints type for the API client
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // Use default client (has access to all endpoints internally)
19
+ * const campaign = await fetchCampaign('123');
20
+ *
21
+ * // Override timeout temporarily (uses temporary config mode by default)
22
+ * const campaign = await fetchCampaign('123', {
23
+ * apiConfig: { timeout: 5000 }
24
+ * });
25
+ *
26
+ * // Override with different update strategy
27
+ * const campaign = await fetchCampaign('123', {
28
+ * apiConfig: { timeout: 5000 },
29
+ * updateConfigOptions: { strategy: 'merge', scope: 'client' }
30
+ * });
31
+ *
32
+ * // Use custom client instance (rare - usually for testing)
33
+ * const customClient = await createApiClient({ baseURL: 'https://staging.api.com' });
34
+ * const campaign = await fetchCampaign('123', {
35
+ * apiClient: customClient,
36
+ * apiConfig: { retry: { attempts: 5 } }
37
+ * });
38
+ * ```
39
+ */
40
+ export interface ServiceOptions<TEndpoints = unknown, TEventManager = unknown> {
41
+ /**
42
+ * Optional API client instance override
43
+ * Use this when you need a different client configuration
44
+ * The client should have all required endpoints for the service
45
+ */
46
+ apiClient?: ApiClientWithEvents<TEventManager, TEndpoints>;
47
+ /**
48
+ * Optional API configuration updates
49
+ * By default applied with { strategy: 'temporary' } mode (affects only this request)
50
+ * Can be overridden via updateConfigOptions
51
+ */
52
+ apiConfig?: Partial<ApiConfig>;
53
+ /**
54
+ * Optional update config options
55
+ * Controls how apiConfig is applied to the client
56
+ *
57
+ * Defaults to: { strategy: 'temporary' }
58
+ * - 'temporary': Only affects this request (highest priority)
59
+ * - 'merge': Merges with client config (persists)
60
+ * - 'replace': Replaces client config (persists)
61
+ */
62
+ updateConfigOptions?: UpdateConfigOptions;
63
+ }
@@ -1,3 +1,4 @@
1
+ import type pino from 'pino';
1
2
  export interface LoggerInterface {
2
3
  debug(message: string, ...supportingDetials: unknown[]): void;
3
4
  info(message: string, ...supportingDetials: unknown[]): void;
@@ -7,3 +8,48 @@ export interface LoggerInterface {
7
8
  }
8
9
  export type LoggerMethodTypes = 'debug' | 'info' | 'warn' | 'error' | 'fatal';
9
10
  export type LoggerEnvironment = 'development' | 'production';
11
+ /**
12
+ * Infers the parameter types for a specific logger method from the `pino.Logger` interface.
13
+ *
14
+ * @template T - The logger method name (e.g., `'info'`, `'error'`, `'warn'`, `'debug'`, `'fatal'`, `'trace'`).
15
+ *
16
+ * @description
17
+ * This utility type extracts the argument list of a given logger method dynamically.
18
+ * For example, if `T` is `'info'`, it will return the tuple type of parameters accepted by `pino.info()`.
19
+ *
20
+ * - It leverages TypeScript’s `infer` keyword to capture parameter types.
21
+ * - It returns a tuple type representing those arguments.
22
+ * - It never falls back to `any` or `unknown` — ensuring strict typing.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * type InfoArgs = LoggerFnArgs<'info'>;
27
+ * // => same as Parameters<pino.Logger['info']>
28
+ * ```
29
+ */
30
+ export type LoggerFnArgs<T extends LoggerMethodTypes> = pino.Logger<'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'trace', boolean>[T] extends (...args: infer A) => void ? A : never;
31
+ /**
32
+ * Defines the structure of the Logger React Context.
33
+ *
34
+ * @description
35
+ * Provides a generic, strongly-typed logging function that mirrors `pino`’s
36
+ * available log methods (`debug`, `info`, `warn`, `error`, `fatal`, `trace`).
37
+ *
38
+ * This ensures that:
39
+ * - Each log method infers the correct argument types.
40
+ * - No `any` or `unknown` is used anywhere in the type definitions.
41
+ *
42
+ * @template T - The specific log level method name.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const context: LoggerContextType = {
47
+ * log: (level, ...args) => {
48
+ * // example usage: log('info', 'User created', { id: 123 });
49
+ * },
50
+ * };
51
+ * ```
52
+ */
53
+ export type LoggerContextType = {
54
+ log: <T extends LoggerMethodTypes>(level: T, ...args: LoggerFnArgs<T>) => void;
55
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
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.",
@@ -172,6 +172,7 @@
172
172
  "keywords": [],
173
173
  "packageManager": "pnpm@10.11.0",
174
174
  "dependencies": {
175
+ "pino": "^10.0.0",
175
176
  "type-fest": "^4.41.0"
176
177
  },
177
178
  "devDependencies": {