@plyaz/types 1.7.15 → 1.7.16

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.
@@ -45,8 +45,8 @@ export type ErrorDetail<ValueGiven, AllowedValues, Constraints> = WithValidation
45
45
  */
46
46
  export type ErrorDetailsList = readonly ErrorDetail<string | number | boolean, Record<string, string>, Record<string, string>>[];
47
47
  export type ErrorCodeKey = keyof typeof ERRORS_CODES;
48
- export type ErrorCodeValue = typeof ERRORS_CODES[ErrorCodeKey];
49
- export type ErrorCodeMsg = typeof ERRORS_CODES[ErrorCodeKey];
48
+ export type ErrorCodeValue = (typeof ERRORS_CODES)[ErrorCodeKey];
49
+ export type ErrorCodeMsg = (typeof ERRORS_CODES)[ErrorCodeKey];
50
50
  export interface ReturnResponseType<T = unknown> {
51
51
  codeStatus: number;
52
52
  message: string;
@@ -1 +1 @@
1
- export type * from "./types";
1
+ export type * from './types';
@@ -335,3 +335,69 @@ export interface ErrorDeduplicatorOptions {
335
335
  /** Time window in ms for considering errors as duplicates */
336
336
  windowMs?: number;
337
337
  }
338
+ /**
339
+ * Generic event payload type for testing event-driven systems
340
+ * Represents arbitrary data that can be passed with events
341
+ *
342
+ * @example
343
+ * ```typescript
344
+ * const payload: EventPayload = {
345
+ * userId: '123',
346
+ * action: 'login',
347
+ * timestamp: Date.now()
348
+ * };
349
+ * ```
350
+ */
351
+ export interface EventPayload {
352
+ [key: string]: unknown;
353
+ }
354
+ /**
355
+ * Event bus interface for testing event-driven architectures
356
+ * Provides methods for subscribing to, emitting, and managing events
357
+ *
358
+ * @typeParam T - Type of data passed to event handlers
359
+ *
360
+ * @example
361
+ * ```typescript
362
+ * const eventBus: EventBusLike<EventPayload> = {
363
+ * on: (event, handler) => { subscribe(event, handler); },
364
+ * off: (event, handler) => { unsubscribe(event, handler); },
365
+ * emit: (event, ...args) => { emitEvent(event, ...args); }
366
+ * };
367
+ * ```
368
+ */
369
+ export interface EventBusLike<T = unknown> {
370
+ /** Subscribe to an event */
371
+ on: (event: string, handler: (...args: T[]) => void) => void;
372
+ /** Unsubscribe from an event */
373
+ off: (event: string, handler: (...args: T[]) => void) => void;
374
+ /** Emit an event with optional data */
375
+ emit: (event: string, ...args: T[]) => void;
376
+ /** Subscribe to an event for one-time execution */
377
+ once?: (event: string, handler: (...args: T[]) => void) => void;
378
+ /** Get all listeners for an event */
379
+ listeners?: (event: string) => Function[];
380
+ /** Remove all listeners for specific event or all events */
381
+ removeAllListeners?: (event?: string) => void;
382
+ }
383
+ /**
384
+ * Options for event emission assertions in tests
385
+ * Controls how event emissions are validated and waited for
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * const options: EmissionAssertionOptions = {
390
+ * times: 3,
391
+ * timeout: 5000,
392
+ * partial: true
393
+ * };
394
+ * ```
395
+ */
396
+ export interface EmissionAssertionOptions {
397
+ /** Expected number of times the event should be emitted */
398
+ times?: number;
399
+ /** Timeout in milliseconds to wait for the event */
400
+ timeout?: number;
401
+ /** Whether to match the payload exactly or partially */
402
+ partial?: boolean;
403
+ }
@@ -655,6 +655,8 @@ export interface MockFetch {
655
655
  * ```
656
656
  */
657
657
  export interface MockLocalStorage {
658
+ /** Internal storage object holding key-value pairs */
659
+ store?: Record<string, string>;
658
660
  /** Get item from storage */
659
661
  getItem: Vitest.Mock;
660
662
  /** Set item in storage */
@@ -667,6 +669,71 @@ export interface MockLocalStorage {
667
669
  length: number;
668
670
  /** Get key at index */
669
671
  key: Vitest.Mock;
672
+ /** Function to update the length property dynamically */
673
+ setLength?: (value: number) => void;
674
+ }
675
+ /**
676
+ * Test context for storage mocks
677
+ * Contains both original and mocked storage implementations for testing
678
+ *
679
+ * @example
680
+ * ```typescript
681
+ * const context: StorageTestContext = {
682
+ * originalSessionStorage: window.sessionStorage,
683
+ * originalLocalStorage: window.localStorage,
684
+ * mockSessionStorage: createMockLocalStorage(),
685
+ * mockLocalStorage: createMockLocalStorage()
686
+ * };
687
+ * ```
688
+ */
689
+ export interface StorageTestContext {
690
+ /** Original sessionStorage instance before mocking */
691
+ originalSessionStorage: Storage | undefined;
692
+ /** Original localStorage instance before mocking */
693
+ originalLocalStorage: Storage | undefined;
694
+ /** Mocked sessionStorage instance */
695
+ mockSessionStorage: MockLocalStorage;
696
+ /** Mocked localStorage instance */
697
+ mockLocalStorage: MockLocalStorage;
698
+ }
699
+ /**
700
+ * Mock geolocation interface for testing location-based features
701
+ * Provides a mocked implementation of the browser's Geolocation API
702
+ *
703
+ * @example
704
+ * ```typescript
705
+ * const mockGeolocation: MockGeolocationReturn = {
706
+ * getCurrentPosition: vi.fn().mockImplementation((success) => {
707
+ * success({ coords: { latitude: 40.7128, longitude: -74.0060 } });
708
+ * })
709
+ * };
710
+ * ```
711
+ */
712
+ export interface MockGeolocationReturn {
713
+ /** Mock function for getting current position */
714
+ getCurrentPosition: ReturnType<Vitest.Mock>;
715
+ }
716
+ /**
717
+ * Extended test context for regional detection testing
718
+ * Includes storage mocks plus global objects needed for testing internationalization and geolocation
719
+ *
720
+ * @example
721
+ * ```typescript
722
+ * const context: RegionalTestContext = {
723
+ * ...storageContext,
724
+ * originalNavigator: window.navigator,
725
+ * originalIntl: Intl,
726
+ * originalGeolocation: navigator.geolocation
727
+ * };
728
+ * ```
729
+ */
730
+ export interface RegionalTestContext extends StorageTestContext {
731
+ /** Original Navigator instance before mocking */
732
+ originalNavigator: globalThis.Navigator;
733
+ /** Original Intl object before mocking */
734
+ originalIntl: typeof Intl;
735
+ /** Original Geolocation instance before mocking */
736
+ originalGeolocation: globalThis.Geolocation;
670
737
  }
671
738
  /**
672
739
  * Mock IntersectionObserver instance interface
@@ -0,0 +1 @@
1
+ export type * from './types';
@@ -0,0 +1,140 @@
1
+ import type * as Vitest from 'vitest';
2
+ /**
3
+ * Options for setupApiTest helper
4
+ */
5
+ export interface SetupApiTestOptions {
6
+ /**
7
+ * EventManager singleton to reset between tests
8
+ * Pass the EventManager class if you want automatic reset
9
+ * @default undefined
10
+ */
11
+ eventManager?: {
12
+ reset: () => void;
13
+ };
14
+ /**
15
+ * Whether to use fake timers in tests
16
+ * @default false
17
+ */
18
+ useFakeTimers?: boolean;
19
+ /**
20
+ * Whether to clear all mocks before each test
21
+ * @default true
22
+ */
23
+ clearMocks?: boolean;
24
+ /**
25
+ * Whether to clear all spies before each test
26
+ * Requires spies utility that has clearAll method
27
+ * @default false
28
+ */
29
+ clearSpies?: boolean | {
30
+ clearAll: () => void;
31
+ };
32
+ /**
33
+ * Custom setup function to run before each test
34
+ * Runs after built-in setup
35
+ * @default undefined
36
+ */
37
+ beforeEach?: () => void | Promise<void>;
38
+ /**
39
+ * Custom teardown function to run after each test
40
+ * Runs before built-in teardown
41
+ * @default undefined
42
+ */
43
+ afterEach?: () => void | Promise<void>;
44
+ }
45
+ /**
46
+ * Creates tracked spies for fetchff module
47
+ */
48
+ export interface FetchffSpies {
49
+ createApiFetcher: Vitest.Mock;
50
+ isSlowConnection: Vitest.Mock;
51
+ fetchf: Vitest.Mock;
52
+ mutate: Vitest.Mock;
53
+ revalidate: Vitest.Mock;
54
+ getCache: Vitest.Mock;
55
+ setCache: Vitest.Mock;
56
+ deleteCache: Vitest.Mock;
57
+ }
58
+ /**
59
+ * Return type for setupFetchffMocks utility
60
+ * Provides spies and setup functions for testing fetchff module
61
+ */
62
+ export interface SetupFetchffMocksReturn {
63
+ spies: ApiMockSpies;
64
+ setupMocks: {
65
+ fetchff: () => FetchffSpies;
66
+ adapter: () => ConfigAdapterSpies;
67
+ builder: () => ConfigBuilderSpies;
68
+ };
69
+ }
70
+ /**
71
+ * Combined API mock spies for convenience
72
+ */
73
+ export interface ApiMockSpies {
74
+ fetchff: FetchffSpies;
75
+ adapter: ConfigAdapterSpies;
76
+ builder: ConfigBuilderSpies;
77
+ }
78
+ /**
79
+ * Config builder spies
80
+ */
81
+ export interface ConfigBuilderSpies {
82
+ mergeConfigs: Vitest.Mock;
83
+ buildApiConfig: Vitest.Mock;
84
+ applyDefaults: Vitest.Mock;
85
+ validateConfig: Vitest.Mock;
86
+ }
87
+ /**
88
+ * Config adapter spies
89
+ */
90
+ export interface ConfigAdapterSpies {
91
+ toFetchffConfig: Vitest.Mock;
92
+ fromFetchffResponse: Vitest.Mock;
93
+ mergeHeaders: Vitest.Mock;
94
+ parseRetryConfig: Vitest.Mock;
95
+ parseCacheConfig: Vitest.Mock;
96
+ }
97
+ /**
98
+ * Connection types based on Network Information API
99
+ */
100
+ export type ConnectionType = 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi' | 'wimax' | 'other' | 'unknown';
101
+ /**
102
+ * Effective connection types (quality assessment)
103
+ */
104
+ export type EffectiveConnectionType = 'slow-2g' | '2g' | '3g' | '4g' | 'unknown';
105
+ /**
106
+ * Network connection information
107
+ */
108
+ export interface NetworkInfo {
109
+ type: ConnectionType;
110
+ effectiveType: EffectiveConnectionType;
111
+ downlink: number | null;
112
+ downlinkMax: number | null;
113
+ rtt: number | null;
114
+ saveData: boolean;
115
+ online: boolean;
116
+ deviceMemory?: number | null;
117
+ }
118
+ /**
119
+ * Network connection information interface
120
+ * Represents the connection property of navigator for testing
121
+ */
122
+ export interface NetworkInfoConnection {
123
+ type: ConnectionType;
124
+ effectiveType: EffectiveConnectionType;
125
+ downlink: number | null;
126
+ downlinkMax: number | null;
127
+ rtt: number | null;
128
+ saveData: boolean;
129
+ }
130
+ /**
131
+ * Mock navigator interface for testing network information
132
+ * Includes connection details and language settings
133
+ */
134
+ export interface NetworkInfoNavigatorMock {
135
+ type?: ConnectionType;
136
+ onLine: boolean;
137
+ connection: NetworkInfoConnection;
138
+ language: string;
139
+ languages: string[];
140
+ }
@@ -1,2 +1,3 @@
1
1
  export type * from './cache';
2
2
  export type * from './feature-flags';
3
+ export type * from './api';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.7.15",
3
+ "version": "1.7.16",
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.",