Skip to content

fix(types): Vendor in TextEncoderCommon type #5221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type { Severity, SeverityLevel } from './severity';
export type { Span, SpanContext } from './span';
export type { StackFrame } from './stackframe';
export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';
export type { TextEncoderInternal } from './textencoder';
export type {
CustomSamplingContext,
Measurements,
Expand Down
16 changes: 16 additions & 0 deletions packages/types/src/textencoder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Vendored type from TS 3.8 `typescript/lib/lib.dom.d.ts`.
*
* Type is vendored in so that users don't have to opt-in to DOM types.
*/
export interface TextEncoderCommon {
/**
* Returns "utf-8".
*/
readonly encoding: string;
}

// Combination of global TextEncoder and Node require('util').TextEncoder
export interface TextEncoderInternal extends TextEncoderCommon {
encode(input?: string): Uint8Array;
}
6 changes: 1 addition & 5 deletions packages/types/src/transport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventDropReason } from './clientreport';
import { DataCategory } from './datacategory';
import { Envelope } from './envelope';
import { TextEncoderInternal } from './textencoder';

export type TransportRequest = {
body: string | Uint8Array;
Expand All @@ -15,11 +16,6 @@ export type TransportMakeRequestResponse = {
};
};

// Combination of global TextEncoder and Node require('util').TextEncoder
interface TextEncoderInternal extends TextEncoderCommon {
encode(input?: string): Uint8Array;
}

export interface InternalBaseTransportOptions {
bufferSize?: number;
recordDroppedEvent: (reason: EventDropReason, dataCategory: DataCategory) => void;
Expand Down
15 changes: 9 additions & 6 deletions packages/utils/src/envelope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Attachment, AttachmentItem, DataCategory, Envelope, EnvelopeItem, EnvelopeItemType } from '@sentry/types';
import {
Attachment,
AttachmentItem,
DataCategory,
Envelope,
EnvelopeItem,
EnvelopeItemType,
TextEncoderInternal,
} from '@sentry/types';

import { dropUndefinedKeys } from './object';

Expand Down Expand Up @@ -36,11 +44,6 @@ export function forEachEnvelopeItem<E extends Envelope>(
});
}

// Combination of global TextEncoder and Node require('util').TextEncoder
interface TextEncoderInternal extends TextEncoderCommon {
encode(input?: string): Uint8Array;
}

function encodeUTF8(input: string, textEncoder?: TextEncoderInternal): Uint8Array {
const utf8 = textEncoder || new TextEncoder();
return utf8.encode(input);
Expand Down