Skip to content

Commit 814fb65

Browse files
[PANA-5341] Add constants to make interacting with BrowserChangeRecords easier (#336)
1 parent 6869c74 commit 814fb65

10 files changed

Lines changed: 159 additions & 5 deletions

lib/cjs/src/session-replay-browser.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export declare const RecordType: {
1515
ViewEnd: SessionReplay.ViewEndRecord['type'];
1616
VisualViewport: SessionReplay.VisualViewportRecord['type'];
1717
FrustrationRecord: SessionReplay.FrustrationRecord['type'];
18+
Change: SessionReplay.BrowserChangeRecord['type'];
1819
};
1920
export declare type RecordType = typeof RecordType[keyof typeof RecordType];
2021
export declare const NodeType: {
@@ -56,3 +57,23 @@ export declare const MediaInteractionType: {
5657
readonly Pause: 1;
5758
};
5859
export declare type MediaInteractionType = typeof MediaInteractionType[keyof typeof MediaInteractionType];
60+
declare type ChangeTypeId<Id, Data> = [Id, ...Data[]] extends SessionReplay.Change ? Id : never;
61+
export declare const ChangeType: {
62+
AddString: ChangeTypeId<0, SessionReplay.AddStringChange>;
63+
AddNode: ChangeTypeId<1, SessionReplay.AddNodeChange>;
64+
RemoveNode: ChangeTypeId<2, SessionReplay.RemoveNodeChange>;
65+
Attribute: ChangeTypeId<3, SessionReplay.AttributeChange>;
66+
Text: ChangeTypeId<4, SessionReplay.TextChange>;
67+
Size: ChangeTypeId<5, SessionReplay.SizeChange>;
68+
ScrollPosition: ChangeTypeId<6, SessionReplay.ScrollPositionChange>;
69+
AddStyleSheet: ChangeTypeId<7, SessionReplay.AddStyleSheetChange>;
70+
AttachedStyleSheets: ChangeTypeId<8, SessionReplay.AttachedStyleSheetsChange>;
71+
MediaPlaybackState: ChangeTypeId<9, SessionReplay.MediaPlaybackStateChange>;
72+
VisualViewport: ChangeTypeId<10, SessionReplay.VisualViewportChange>;
73+
};
74+
export declare type ChangeType = typeof ChangeType[keyof typeof ChangeType];
75+
export declare const PlaybackState: {
76+
Playing: SessionReplay.PlaybackStatePlaying;
77+
Paused: SessionReplay.PlaybackStatePaused;
78+
};
79+
export declare type PlaybackState = typeof PlaybackState[keyof typeof PlaybackState];

lib/cjs/src/session-replay-browser.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
1414
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1515
};
1616
Object.defineProperty(exports, "__esModule", { value: true });
17-
exports.MediaInteractionType = exports.MouseInteractionType = exports.IncrementalSource = exports.NodeType = exports.RecordType = exports.BrowserSource = void 0;
17+
exports.PlaybackState = exports.ChangeType = exports.MediaInteractionType = exports.MouseInteractionType = exports.IncrementalSource = exports.NodeType = exports.RecordType = exports.BrowserSource = void 0;
1818
__exportStar(require("../generated/browserSessionReplay"), exports);
1919
/**
2020
* For backward compatibility reasons, `undefined` should be accepted as a possible value for Browser segments, too.
@@ -30,6 +30,7 @@ exports.RecordType = {
3030
ViewEnd: 7,
3131
VisualViewport: 8,
3232
FrustrationRecord: 9,
33+
Change: 12,
3334
};
3435
exports.NodeType = {
3536
Document: 0,
@@ -67,3 +68,20 @@ exports.MediaInteractionType = {
6768
Play: 0,
6869
Pause: 1,
6970
};
71+
exports.ChangeType = {
72+
AddString: 0,
73+
AddNode: 1,
74+
RemoveNode: 2,
75+
Attribute: 3,
76+
Text: 4,
77+
Size: 5,
78+
ScrollPosition: 6,
79+
AddStyleSheet: 7,
80+
AttachedStyleSheets: 8,
81+
MediaPlaybackState: 9,
82+
VisualViewport: 10,
83+
};
84+
exports.PlaybackState = {
85+
Playing: 0,
86+
Paused: 1,
87+
};

lib/cjs/src/session-replay.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { IncrementalSource as BrowserIncrementalSource, RecordType as BrowserRecordType } from './session-replay-browser';
22
import type { IncrementalSource as MobileIncrementalSource, RecordType as MobileRecordType } from './session-replay-mobile';
33
export * from '../generated/sessionReplay';
4-
export { BrowserSource, NodeType, IncrementalSource as BrowserIncrementalSource, MouseInteractionType, MediaInteractionType, } from './session-replay-browser';
4+
export { BrowserSource, ChangeType as BrowserChangeType, NodeType, IncrementalSource as BrowserIncrementalSource, MouseInteractionType, MediaInteractionType, PlaybackState, } from './session-replay-browser';
55
export { IncrementalSource as MobileIncrementalSource, MobileSource, WireframeType } from './session-replay-mobile';
66
export declare const RecordType: {
77
BrowserFullSnapshot: typeof BrowserRecordType.FullSnapshot;
@@ -13,6 +13,7 @@ export declare const RecordType: {
1313
FrustrationRecord: typeof BrowserRecordType.FrustrationRecord;
1414
MobileFullSnapshot: typeof MobileRecordType.FullSnapshot;
1515
MobileIncrementalSnapshot: typeof MobileRecordType.IncrementalSnapshot;
16+
BrowserChange: typeof BrowserRecordType.Change;
1617
};
1718
export declare type RecordType = typeof RecordType[keyof typeof RecordType];
1819
export declare type IncrementalSource = BrowserIncrementalSource | MobileIncrementalSource;
@@ -28,3 +29,12 @@ export declare const PointerType: {
2829
readonly Pen: "pen";
2930
};
3031
export declare type PointerType = typeof PointerType[keyof typeof PointerType];
32+
export declare type NodeId = number & {
33+
__brand: 'NodeId';
34+
};
35+
export declare type StringId = number & {
36+
__brand: 'StringId';
37+
};
38+
export declare type StyleSheetId = number & {
39+
__brand: 'StyleSheetId';
40+
};

lib/cjs/src/session-replay.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
1414
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1515
};
1616
Object.defineProperty(exports, "__esModule", { value: true });
17-
exports.PointerType = exports.PointerEventType = exports.RecordType = exports.WireframeType = exports.MobileSource = exports.MobileIncrementalSource = exports.MediaInteractionType = exports.MouseInteractionType = exports.BrowserIncrementalSource = exports.NodeType = exports.BrowserSource = void 0;
17+
exports.PointerType = exports.PointerEventType = exports.RecordType = exports.WireframeType = exports.MobileSource = exports.MobileIncrementalSource = exports.PlaybackState = exports.MediaInteractionType = exports.MouseInteractionType = exports.BrowserIncrementalSource = exports.NodeType = exports.BrowserChangeType = exports.BrowserSource = void 0;
1818
__exportStar(require("../generated/sessionReplay"), exports);
1919
var session_replay_browser_1 = require("./session-replay-browser");
2020
Object.defineProperty(exports, "BrowserSource", { enumerable: true, get: function () { return session_replay_browser_1.BrowserSource; } });
21+
Object.defineProperty(exports, "BrowserChangeType", { enumerable: true, get: function () { return session_replay_browser_1.ChangeType; } });
2122
Object.defineProperty(exports, "NodeType", { enumerable: true, get: function () { return session_replay_browser_1.NodeType; } });
2223
Object.defineProperty(exports, "BrowserIncrementalSource", { enumerable: true, get: function () { return session_replay_browser_1.IncrementalSource; } });
2324
Object.defineProperty(exports, "MouseInteractionType", { enumerable: true, get: function () { return session_replay_browser_1.MouseInteractionType; } });
2425
Object.defineProperty(exports, "MediaInteractionType", { enumerable: true, get: function () { return session_replay_browser_1.MediaInteractionType; } });
26+
Object.defineProperty(exports, "PlaybackState", { enumerable: true, get: function () { return session_replay_browser_1.PlaybackState; } });
2527
var session_replay_mobile_1 = require("./session-replay-mobile");
2628
Object.defineProperty(exports, "MobileIncrementalSource", { enumerable: true, get: function () { return session_replay_mobile_1.IncrementalSource; } });
2729
Object.defineProperty(exports, "MobileSource", { enumerable: true, get: function () { return session_replay_mobile_1.MobileSource; } });
@@ -36,6 +38,7 @@ exports.RecordType = {
3638
FrustrationRecord: 9,
3739
MobileFullSnapshot: 10,
3840
MobileIncrementalSnapshot: 11,
41+
BrowserChange: 12,
3942
};
4043
exports.PointerEventType = {
4144
PointerDown: 'down',

lib/esm/src/session-replay-browser.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export declare const RecordType: {
1515
ViewEnd: SessionReplay.ViewEndRecord['type'];
1616
VisualViewport: SessionReplay.VisualViewportRecord['type'];
1717
FrustrationRecord: SessionReplay.FrustrationRecord['type'];
18+
Change: SessionReplay.BrowserChangeRecord['type'];
1819
};
1920
export declare type RecordType = typeof RecordType[keyof typeof RecordType];
2021
export declare const NodeType: {
@@ -56,3 +57,23 @@ export declare const MediaInteractionType: {
5657
readonly Pause: 1;
5758
};
5859
export declare type MediaInteractionType = typeof MediaInteractionType[keyof typeof MediaInteractionType];
60+
declare type ChangeTypeId<Id, Data> = [Id, ...Data[]] extends SessionReplay.Change ? Id : never;
61+
export declare const ChangeType: {
62+
AddString: ChangeTypeId<0, SessionReplay.AddStringChange>;
63+
AddNode: ChangeTypeId<1, SessionReplay.AddNodeChange>;
64+
RemoveNode: ChangeTypeId<2, SessionReplay.RemoveNodeChange>;
65+
Attribute: ChangeTypeId<3, SessionReplay.AttributeChange>;
66+
Text: ChangeTypeId<4, SessionReplay.TextChange>;
67+
Size: ChangeTypeId<5, SessionReplay.SizeChange>;
68+
ScrollPosition: ChangeTypeId<6, SessionReplay.ScrollPositionChange>;
69+
AddStyleSheet: ChangeTypeId<7, SessionReplay.AddStyleSheetChange>;
70+
AttachedStyleSheets: ChangeTypeId<8, SessionReplay.AttachedStyleSheetsChange>;
71+
MediaPlaybackState: ChangeTypeId<9, SessionReplay.MediaPlaybackStateChange>;
72+
VisualViewport: ChangeTypeId<10, SessionReplay.VisualViewportChange>;
73+
};
74+
export declare type ChangeType = typeof ChangeType[keyof typeof ChangeType];
75+
export declare const PlaybackState: {
76+
Playing: SessionReplay.PlaybackStatePlaying;
77+
Paused: SessionReplay.PlaybackStatePaused;
78+
};
79+
export declare type PlaybackState = typeof PlaybackState[keyof typeof PlaybackState];

lib/esm/src/session-replay-browser.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export var RecordType = {
1313
ViewEnd: 7,
1414
VisualViewport: 8,
1515
FrustrationRecord: 9,
16+
Change: 12,
1617
};
1718
export var NodeType = {
1819
Document: 0,
@@ -50,3 +51,20 @@ export var MediaInteractionType = {
5051
Play: 0,
5152
Pause: 1,
5253
};
54+
export var ChangeType = {
55+
AddString: 0,
56+
AddNode: 1,
57+
RemoveNode: 2,
58+
Attribute: 3,
59+
Text: 4,
60+
Size: 5,
61+
ScrollPosition: 6,
62+
AddStyleSheet: 7,
63+
AttachedStyleSheets: 8,
64+
MediaPlaybackState: 9,
65+
VisualViewport: 10,
66+
};
67+
export var PlaybackState = {
68+
Playing: 0,
69+
Paused: 1,
70+
};

lib/esm/src/session-replay.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { IncrementalSource as BrowserIncrementalSource, RecordType as BrowserRecordType } from './session-replay-browser';
22
import type { IncrementalSource as MobileIncrementalSource, RecordType as MobileRecordType } from './session-replay-mobile';
33
export * from '../generated/sessionReplay';
4-
export { BrowserSource, NodeType, IncrementalSource as BrowserIncrementalSource, MouseInteractionType, MediaInteractionType, } from './session-replay-browser';
4+
export { BrowserSource, ChangeType as BrowserChangeType, NodeType, IncrementalSource as BrowserIncrementalSource, MouseInteractionType, MediaInteractionType, PlaybackState, } from './session-replay-browser';
55
export { IncrementalSource as MobileIncrementalSource, MobileSource, WireframeType } from './session-replay-mobile';
66
export declare const RecordType: {
77
BrowserFullSnapshot: typeof BrowserRecordType.FullSnapshot;
@@ -13,6 +13,7 @@ export declare const RecordType: {
1313
FrustrationRecord: typeof BrowserRecordType.FrustrationRecord;
1414
MobileFullSnapshot: typeof MobileRecordType.FullSnapshot;
1515
MobileIncrementalSnapshot: typeof MobileRecordType.IncrementalSnapshot;
16+
BrowserChange: typeof BrowserRecordType.Change;
1617
};
1718
export declare type RecordType = typeof RecordType[keyof typeof RecordType];
1819
export declare type IncrementalSource = BrowserIncrementalSource | MobileIncrementalSource;
@@ -28,3 +29,12 @@ export declare const PointerType: {
2829
readonly Pen: "pen";
2930
};
3031
export declare type PointerType = typeof PointerType[keyof typeof PointerType];
32+
export declare type NodeId = number & {
33+
__brand: 'NodeId';
34+
};
35+
export declare type StringId = number & {
36+
__brand: 'StringId';
37+
};
38+
export declare type StyleSheetId = number & {
39+
__brand: 'StyleSheetId';
40+
};

lib/esm/src/session-replay.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export * from '../generated/sessionReplay';
2-
export { BrowserSource, NodeType, IncrementalSource as BrowserIncrementalSource, MouseInteractionType, MediaInteractionType, } from './session-replay-browser';
2+
export { BrowserSource, ChangeType as BrowserChangeType, NodeType, IncrementalSource as BrowserIncrementalSource, MouseInteractionType, MediaInteractionType, PlaybackState, } from './session-replay-browser';
33
export { IncrementalSource as MobileIncrementalSource, MobileSource, WireframeType } from './session-replay-mobile';
44
export var RecordType = {
55
BrowserFullSnapshot: 2,
@@ -11,6 +11,7 @@ export var RecordType = {
1111
FrustrationRecord: 9,
1212
MobileFullSnapshot: 10,
1313
MobileIncrementalSnapshot: 11,
14+
BrowserChange: 12,
1415
};
1516
export var PointerEventType = {
1617
PointerDown: 'down',

lib/src/session-replay-browser.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const RecordType: {
1919
ViewEnd: SessionReplay.ViewEndRecord['type']
2020
VisualViewport: SessionReplay.VisualViewportRecord['type']
2121
FrustrationRecord: SessionReplay.FrustrationRecord['type']
22+
Change: SessionReplay.BrowserChangeRecord['type']
2223
} = {
2324
FullSnapshot: 2,
2425
IncrementalSnapshot: 3,
@@ -27,6 +28,7 @@ export const RecordType: {
2728
ViewEnd: 7,
2829
VisualViewport: 8,
2930
FrustrationRecord: 9,
31+
Change: 12,
3032
} as const
3133

3234
export type RecordType = typeof RecordType[keyof typeof RecordType]
@@ -96,3 +98,45 @@ export const MediaInteractionType = {
9698
} as const
9799

98100
export type MediaInteractionType = typeof MediaInteractionType[keyof typeof MediaInteractionType]
101+
102+
// ChangeTypeId evaluates to Id if [Id, ...Data[]] is a valid variant of Change;
103+
// otherwise, it triggers a compile-time error.
104+
type ChangeTypeId<Id, Data> = [Id, ...Data[]] extends SessionReplay.Change ? Id : never
105+
106+
export const ChangeType: {
107+
AddString: ChangeTypeId<0, SessionReplay.AddStringChange>
108+
AddNode: ChangeTypeId<1, SessionReplay.AddNodeChange>
109+
RemoveNode: ChangeTypeId<2, SessionReplay.RemoveNodeChange>
110+
Attribute: ChangeTypeId<3, SessionReplay.AttributeChange>
111+
Text: ChangeTypeId<4, SessionReplay.TextChange>
112+
Size: ChangeTypeId<5, SessionReplay.SizeChange>
113+
ScrollPosition: ChangeTypeId<6, SessionReplay.ScrollPositionChange>
114+
AddStyleSheet: ChangeTypeId<7, SessionReplay.AddStyleSheetChange>
115+
AttachedStyleSheets: ChangeTypeId<8, SessionReplay.AttachedStyleSheetsChange>
116+
MediaPlaybackState: ChangeTypeId<9, SessionReplay.MediaPlaybackStateChange>
117+
VisualViewport: ChangeTypeId<10, SessionReplay.VisualViewportChange>
118+
} = {
119+
AddString: 0,
120+
AddNode: 1,
121+
RemoveNode: 2,
122+
Attribute: 3,
123+
Text: 4,
124+
Size: 5,
125+
ScrollPosition: 6,
126+
AddStyleSheet: 7,
127+
AttachedStyleSheets: 8,
128+
MediaPlaybackState: 9,
129+
VisualViewport: 10,
130+
} as const
131+
132+
export type ChangeType = typeof ChangeType[keyof typeof ChangeType]
133+
134+
export const PlaybackState: {
135+
Playing: SessionReplay.PlaybackStatePlaying
136+
Paused: SessionReplay.PlaybackStatePaused
137+
} = {
138+
Playing: 0,
139+
Paused: 1,
140+
} as const
141+
142+
export type PlaybackState = typeof PlaybackState[keyof typeof PlaybackState]

lib/src/session-replay.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ export * from '../generated/sessionReplay'
1111

1212
export {
1313
BrowserSource,
14+
ChangeType as BrowserChangeType,
1415
NodeType,
1516
IncrementalSource as BrowserIncrementalSource,
1617
MouseInteractionType,
1718
MediaInteractionType,
19+
PlaybackState,
1820
} from './session-replay-browser'
1921
export { IncrementalSource as MobileIncrementalSource, MobileSource, WireframeType } from './session-replay-mobile'
2022

@@ -28,6 +30,7 @@ export const RecordType: {
2830
FrustrationRecord: typeof BrowserRecordType.FrustrationRecord
2931
MobileFullSnapshot: typeof MobileRecordType.FullSnapshot
3032
MobileIncrementalSnapshot: typeof MobileRecordType.IncrementalSnapshot
33+
BrowserChange: typeof BrowserRecordType.Change
3134
} = {
3235
BrowserFullSnapshot: 2,
3336
BrowserIncrementalSnapshot: 3,
@@ -38,6 +41,7 @@ export const RecordType: {
3841
FrustrationRecord: 9,
3942
MobileFullSnapshot: 10,
4043
MobileIncrementalSnapshot: 11,
44+
BrowserChange: 12,
4145
} as const
4246

4347
export type RecordType = typeof RecordType[keyof typeof RecordType]
@@ -59,3 +63,7 @@ export const PointerType = {
5963
} as const
6064

6165
export type PointerType = typeof PointerType[keyof typeof PointerType]
66+
67+
export type NodeId = number & { __brand: 'NodeId' }
68+
export type StringId = number & { __brand: 'StringId' }
69+
export type StyleSheetId = number & { __brand: 'StyleSheetId' }

0 commit comments

Comments
 (0)