Skip to content

Commit 653d816

Browse files
committed
ref(replay): Extract types into types.ts
To avoid circular dependencies.
1 parent b0cc06b commit 653d816

28 files changed

+94
-81
lines changed

packages/replay/.madgerc

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/replay/jest.setup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import { getCurrentHub } from '@sentry/core';
33
import { Transport } from '@sentry/types';
44

5-
import { ReplayContainer } from './src/replay';
6-
import { Session } from './src/session/Session';
5+
import type { ReplayContainer, Session } from './src/types';
76

87
// @ts-ignore TS error, this is replaced in prod builds bc of rollup
98
global.__SENTRY_REPLAY_VERSION__ = 'version:Test';

packages/replay/src/coreHandlers/breadcrumbHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Breadcrumb, Scope } from '@sentry/types';
22

3-
import { InstrumentationTypeBreadcrumb } from '../types';
3+
import type { InstrumentationTypeBreadcrumb } from '../types';
44
import { DomHandlerData, handleDom } from './handleDom';
55
import { handleScope } from './handleScope';
66

packages/replay/src/coreHandlers/handleFetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReplayPerformanceEntry } from '../createPerformanceEntry';
2-
import type { ReplayContainer } from '../replay';
2+
import type { ReplayContainer } from '../types';
33
import { createPerformanceSpans } from '../util/createPerformanceSpans';
44
import { isIngestHost } from '../util/isIngestHost';
55

packages/replay/src/coreHandlers/handleGlobalEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Event } from '@sentry/types';
22

33
import { REPLAY_EVENT_NAME, UNABLE_TO_SEND_REPLAY } from '../constants';
4-
import type { ReplayContainer } from '../replay';
4+
import type { ReplayContainer } from '../types';
55
import { addInternalBreadcrumb } from '../util/addInternalBreadcrumb';
66

77
/**

packages/replay/src/coreHandlers/handleHistory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ReplayPerformanceEntry } from '../createPerformanceEntry';
2-
import type { ReplayContainer } from '../replay';
2+
import type { ReplayContainer } from '../types';
33
import { createPerformanceSpans } from '../util/createPerformanceSpans';
44

55
interface HistoryHandlerData {

packages/replay/src/coreHandlers/handleXhr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ReplayPerformanceEntry } from '../createPerformanceEntry';
2-
import type { ReplayContainer } from '../replay';
2+
import type { ReplayContainer } from '../types';
33
import { createPerformanceSpans } from '../util/createPerformanceSpans';
44
import { isIngestHost } from '../util/isIngestHost';
55

packages/replay/src/coreHandlers/performanceObserver.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { ReplayContainer } from '../replay';
2-
import { AllPerformanceEntry } from '../types';
1+
import type { AllPerformanceEntry, ReplayContainer } from '../types';
32
import { dedupePerformanceEntries } from '../util/dedupePerformanceEntries';
43

54
/**

packages/replay/src/createPerformanceEntry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { browserPerformanceTimeOrigin } from '@sentry/utils';
22
import { record } from 'rrweb';
33

44
import { WINDOW } from './constants';
5-
import { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming } from './types';
5+
import type { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming } from './types';
66
import { isIngestHost } from './util/isIngestHost';
77

88
export interface ReplayPerformanceEntry {

packages/replay/src/eventBuffer.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { captureException } from '@sentry/core';
55
import { logger } from '@sentry/utils';
66

7-
import { RecordingEvent, WorkerRequest, WorkerResponse } from './types';
7+
import type { EventBuffer, RecordingEvent, WorkerRequest, WorkerResponse } from './types';
88
import workerString from './worker/worker.js';
99

1010
interface CreateEventBufferParams {
@@ -35,13 +35,6 @@ export function createEventBuffer({ useCompression }: CreateEventBufferParams):
3535
return new EventBufferArray();
3636
}
3737

38-
export interface EventBuffer {
39-
readonly length: number;
40-
destroy(): void;
41-
addEvent(event: RecordingEvent, isCheckout?: boolean): void;
42-
finish(): Promise<string | Uint8Array>;
43-
}
44-
4538
class EventBufferArray implements EventBuffer {
4639
private _events: RecordingEvent[];
4740

packages/replay/src/replay.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,23 @@ import { handleHistorySpanListener } from './coreHandlers/handleHistory';
2020
import { handleXhrSpanListener } from './coreHandlers/handleXhr';
2121
import { setupPerformanceObserver } from './coreHandlers/performanceObserver';
2222
import { createPerformanceEntries } from './createPerformanceEntry';
23-
import { createEventBuffer, EventBuffer } from './eventBuffer';
23+
import { createEventBuffer } from './eventBuffer';
2424
import { deleteSession } from './session/deleteSession';
2525
import { getSession } from './session/getSession';
2626
import { saveSession } from './session/saveSession';
27-
import { Session } from './session/Session';
2827
import type {
28+
AddUpdateCallback,
2929
AllPerformanceEntry,
30+
EventBuffer,
3031
InstrumentationTypeBreadcrumb,
3132
InternalEventContext,
3233
PopEventContext,
3334
RecordingEvent,
3435
RecordingOptions,
36+
ReplayContainer as ReplayContainerInterface,
3537
ReplayPluginOptions,
3638
SendReplay,
39+
Session,
3740
} from './types';
3841
import { addEvent } from './util/addEvent';
3942
import { addMemoryEntry } from './util/addMemoryEntry';
@@ -48,12 +51,11 @@ import { overwriteRecordDroppedEvent, restoreRecordDroppedEvent } from './util/m
4851
/**
4952
* Returns true to return control to calling function, otherwise continue with normal batching
5053
*/
51-
type AddUpdateCallback = () => boolean | void;
5254

5355
const BASE_RETRY_INTERVAL = 5000;
5456
const MAX_RETRY_COUNT = 3;
5557

56-
export class ReplayContainer {
58+
export class ReplayContainer implements ReplayContainerInterface {
5759
public eventBuffer: EventBuffer | null = null;
5860

5961
/**
@@ -398,7 +400,7 @@ export class ReplayContainer {
398400
* Accepts a callback to perform side-effects and returns true to stop batch
399401
* processing and hand back control to caller.
400402
*/
401-
addUpdate(cb?: AddUpdateCallback): void {
403+
addUpdate(cb: AddUpdateCallback): void {
402404
// We need to always run `cb` (e.g. in the case of `this._waitForError == true`)
403405
const cbResult = cb?.();
404406

packages/replay/src/session/Session.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,8 @@
11
import { uuid4 } from '@sentry/utils';
22

3+
import type { Sampled, Session } from '../types';
34
import { isSampled } from '../util/isSampled';
45

5-
type Sampled = false | 'session' | 'error';
6-
7-
export interface Session {
8-
id: string;
9-
10-
/**
11-
* Start time of current session
12-
*/
13-
started: number;
14-
15-
/**
16-
* Last known activity of the session
17-
*/
18-
lastActivity: number;
19-
20-
/**
21-
* Segment ID for replay events
22-
*/
23-
segmentId: number;
24-
25-
/**
26-
* The ID of the previous session.
27-
* If this is empty, there was no previous session.
28-
*/
29-
previousSessionId?: string;
30-
31-
/**
32-
* Is the session sampled? `false` if not sampled, otherwise, `session` or `error`
33-
*/
34-
sampled: Sampled;
35-
}
36-
376
/**
387
* Get a session with defaults & applied sampling.
398
*/

packages/replay/src/session/createSession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { logger } from '@sentry/utils';
22

3-
import { SessionOptions } from '../types';
3+
import type { Session, SessionOptions } from '../types';
44
import { saveSession } from './saveSession';
5-
import { getSessionSampleType, makeSession, Session } from './Session';
5+
import { getSessionSampleType, makeSession } from './Session';
66

77
/**
88
* Create a new session, which in its current implementation is a Sentry event

packages/replay/src/session/fetchSession.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { REPLAY_SESSION_KEY, WINDOW } from '../constants';
2-
import { makeSession, Session } from './Session';
2+
import type { Session } from '../types';
3+
import { makeSession } from './Session';
34

45
/**
56
* Fetches a session from storage

packages/replay/src/session/getSession.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { logger } from '@sentry/utils';
22

3-
import { SessionOptions } from '../types';
3+
import type { Session, SessionOptions } from '../types';
44
import { isSessionExpired } from '../util/isSessionExpired';
55
import { createSession } from './createSession';
66
import { fetchSession } from './fetchSession';
7-
import { Session } from './Session';
87

98
interface GetSessionParams extends SessionOptions {
109
/**

packages/replay/src/session/saveSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { REPLAY_SESSION_KEY, WINDOW } from '../constants';
2-
import { Session } from './Session';
2+
import type { Session } from '../types';
33

44
export function saveSession(session: Session): void {
55
const hasSessionStorage = 'sessionStorage' in WINDOW;

packages/replay/src/types.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,62 @@ export interface InternalEventContext extends CommonEventContext {
160160
*/
161161
earliestEvent: number | null;
162162
}
163+
164+
export type Sampled = false | 'session' | 'error';
165+
166+
export interface Session {
167+
id: string;
168+
169+
/**
170+
* Start time of current session
171+
*/
172+
started: number;
173+
174+
/**
175+
* Last known activity of the session
176+
*/
177+
lastActivity: number;
178+
179+
/**
180+
* Segment ID for replay events
181+
*/
182+
segmentId: number;
183+
184+
/**
185+
* The ID of the previous session.
186+
* If this is empty, there was no previous session.
187+
*/
188+
previousSessionId?: string;
189+
190+
/**
191+
* Is the session sampled? `false` if not sampled, otherwise, `session` or `error`
192+
*/
193+
sampled: Sampled;
194+
}
195+
196+
export interface EventBuffer {
197+
readonly length: number;
198+
destroy(): void;
199+
addEvent(event: RecordingEvent, isCheckout?: boolean): void;
200+
finish(): Promise<string | Uint8Array>;
201+
}
202+
203+
export type AddUpdateCallback = () => boolean | void;
204+
205+
export interface ReplayContainer {
206+
eventBuffer: EventBuffer | null;
207+
performanceEvents: AllPerformanceEntry[];
208+
session: Session | undefined;
209+
isEnabled(): boolean;
210+
isPaused(): boolean;
211+
getContext(): InternalEventContext;
212+
start(): void;
213+
stop(): void;
214+
pause(): void;
215+
resume(): void;
216+
startRecording(): void;
217+
stopRecording(): boolean;
218+
flushImmediate(): void;
219+
triggerUserActivity(): void;
220+
addUpdate(cb: AddUpdateCallback): void;
221+
}

packages/replay/src/util/addEvent.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { SESSION_IDLE_DURATION } from '../constants';
2-
import type { ReplayContainer } from '../replay';
3-
import { RecordingEvent } from '../types';
2+
import type { RecordingEvent, ReplayContainer } from '../types';
43

54
/**
65
* Add an event to the event buffer

packages/replay/src/util/addMemoryEntry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { WINDOW } from '../constants';
2-
import type { ReplayContainer } from '../replay';
2+
import type { ReplayContainer } from '../types';
33
import { createPerformanceSpans } from './createPerformanceSpans';
44

55
/**

packages/replay/src/util/createPayload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RecordedEvents } from '../types';
1+
import type { RecordedEvents } from '../types';
22

33
export function createPayload({
44
events,

packages/replay/src/util/createPerformanceSpans.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EventType } from 'rrweb';
22

33
import { ReplayPerformanceEntry } from '../createPerformanceEntry';
4-
import type { ReplayContainer } from '../replay';
4+
import type { ReplayContainer } from '../types';
55
import { addEvent } from './addEvent';
66

77
/**

packages/replay/src/util/isSessionExpired.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MAX_SESSION_LIFE } from '../constants';
2-
import { Session } from '../session/Session';
2+
import type { Session } from '../types';
33
import { isExpired } from './isExpired';
44

55
/**

packages/replay/test/fixtures/performanceEntry/lcp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PerformancePaintTiming } from '../../../src/types';
1+
import type { PerformancePaintTiming } from '../../../src/types';
22

33
export function PerformanceEntryLcp(obj?: Partial<PerformancePaintTiming>): PerformancePaintTiming {
44
const entry = {

packages/replay/test/mocks/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getCurrentHub } from '@sentry/core';
22

33
import { ReplayContainer } from '../../src/replay';
44
import { BASE_TIMESTAMP, RecordMock } from './../index';
5-
import { DomHandler, MockTransportSend } from './../types';
5+
import type { DomHandler, MockTransportSend } from './../types';
66
import { MockSdkParams } from './mockSdk';
77

88
export async function resetSdkMock({ replayOptions, sentryOptions }: MockSdkParams): Promise<{

packages/replay/test/mocks/mockRrweb.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { record as rrwebRecord } from 'rrweb';
22

3-
import { RecordingEvent } from '../../src/types';
3+
import type { RecordingEvent } from '../../src/types';
44

55
type RecordAdditionalProperties = {
66
takeFullSnapshot: jest.Mock;

packages/replay/test/mocks/mockSdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Envelope, Transport } from '@sentry/types';
33

44
import { Replay as ReplayIntegration } from '../../src';
55
import { ReplayContainer } from '../../src/replay';
6-
import { ReplayConfiguration } from '../../src/types';
6+
import type { ReplayConfiguration } from '../../src/types';
77

88
export interface MockSdkParams {
99
replayOptions?: ReplayConfiguration;

packages/replay/test/unit/index-errorSampleRate.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ReplayContainer } from './../../src/replay';
88
import { PerformanceEntryResource } from './../fixtures/performanceEntry/resource';
99
import { BASE_TIMESTAMP, RecordMock } from './../index';
1010
import { resetSdkMock } from './../mocks';
11-
import { DomHandler, MockTransportSend } from './../types';
11+
import type { DomHandler, MockTransportSend } from './../types';
1212
import { useFakeTimers } from './../utils/use-fake-timers';
1313

1414
useFakeTimers();

packages/replay/test/unit/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { EventType } from 'rrweb';
66

77
import { MAX_SESSION_LIFE, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
88
import { ReplayContainer } from '../../src/replay';
9-
import { RecordingEvent } from '../../src/types';
9+
import type { RecordingEvent } from '../../src/types';
1010
import { addEvent } from '../../src/util/addEvent';
1111
import { createPerformanceSpans } from '../../src/util/createPerformanceSpans';
1212
import { useFakeTimers } from '../utils/use-fake-timers';
1313
import { PerformanceEntryResource } from './../fixtures/performanceEntry/resource';
1414
import { BASE_TIMESTAMP, RecordMock } from './../index';
1515
import { resetSdkMock } from './../mocks';
16-
import { DomHandler, MockTransportSend } from './../types';
16+
import type { DomHandler, MockTransportSend } from './../types';
1717

1818
useFakeTimers();
1919

0 commit comments

Comments
 (0)