Skip to content
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: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module.exports = {
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/browser/src/BrowserClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ class BrowserClientImpl extends LDClientImpl {
this.dataManager.setAutomaticStreamingState?.(hasListeners);
}

override on(eventName: LDEmitterEventName, listener: Function): void {
override on(eventName: LDEmitterEventName, listener: (...args: any[]) => void): void {
super.on(eventName, listener);
this._updateAutomaticStreamingState();
}

override off(eventName: LDEmitterEventName, listener: Function): void {
override off(eventName: LDEmitterEventName, listener: (...args: any[]) => void): void {
super.off(eventName, listener);
this._updateAutomaticStreamingState();
}
Expand Down
12 changes: 7 additions & 5 deletions packages/sdk/electron/__tests__/ElectronClient.ipcMain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ import ElectronInfo from '../src/platform/ElectronInfo';
import { createMockLogger } from './testHelpers';

type MockIpcMain = IpcMain & {
getHandler: (eventName: string) => Function | undefined;
getHandler: (eventName: string) => ((...args: any[]) => void) | undefined;
removeAllListeners: (channel: string) => void;
removeHandler: (channel: string) => void;
};
type MockPort = { postMessage: Function; close: Function };
type MockPort = { postMessage: (...args: any[]) => void; close: (...args: any[]) => void };
type MockIpcEvent = { returnValue?: any; ports?: MockPort[] };

jest.mock('electron', () => {
const handlers = new Map<string, Function>();
const handlers = new Map<string, (...args: any[]) => void>();
return {
ipcMain: {
on: (eventName: string, handler: Function) => handlers.set(eventName, handler),
handle: (eventName: string, handler: Function) => handlers.set(eventName, handler),
on: (eventName: string, handler: (...args: any[]) => void) =>
handlers.set(eventName, handler),
handle: (eventName: string, handler: (...args: any[]) => void) =>
handlers.set(eventName, handler),
getHandler: (eventName: string) => handlers.get(eventName),
removeAllListeners: (channel: string) => handlers.delete(channel),
removeHandler: (channel: string) => handlers.delete(channel),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ function createMockEventSourceThatDeliversPut(putData: object) {
});
}

const handlers = new Map<string, Function>();
const mockOn = jest.fn((eventName: string, handler: Function) => {
const handlers = new Map<string, (...args: any[]) => void>();
const mockOn = jest.fn((eventName: string, handler: (...args: any[]) => void) => {
handlers.set(eventName, handler);
});
const mockHandle = jest.fn((eventName: string, handler: Function) => {
const mockHandle = jest.fn((eventName: string, handler: (...args: any[]) => void) => {
handlers.set(eventName, handler);
});

jest.mock('electron', () => ({
ipcMain: {
on: (eventName: string, handler: Function) => mockOn(eventName, handler),
handle: (eventName: string, handler: Function) => mockHandle(eventName, handler),
on: (eventName: string, handler: (...args: any[]) => void) => mockOn(eventName, handler),
handle: (eventName: string, handler: (...args: any[]) => void) =>
mockHandle(eventName, handler),
getHandler: (eventName: string) => handlers.get(eventName),
removeAllListeners: (channel: string) => handlers.delete(channel),
removeHandler: (channel: string) => handlers.delete(channel),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe('given an instance of ElectronRendererClient', () => {
const clientForSyncClose = new ElectronRendererClient(clientSideId);
const syncCloseId = 'sync-close-id';
(ldClientBridge.addEventHandler as jest.Mock).mockImplementation(
(_eventName: string, _cb: Function, onClose?: () => void) => {
(_eventName: string, _cb: (...args: any[]) => void, onClose?: () => void) => {
onClose?.();
return syncCloseId;
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/electron/src/platform/ElectronRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default class ElectronRequests implements platform.Requests {
const impl = isSecure ? https : http;

const headers = { ...options.headers };
let bodyData: String | Buffer | undefined = options.body;
let bodyData: string | Buffer | undefined = options.body;

// For get requests we are going to automatically support compressed responses.
// Note this does not affect SSE as the event source is not using this fetch implementation.
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/server-node/src/Emits.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EventEmitter } from 'events';

// eslint-disable-next-line @typescript-eslint/ban-types
export type EventableConstructor<T = {}> = new (...args: any[]) => T;
export type Eventable = EventableConstructor<{ emitter: EventEmitter }>;

Expand Down Expand Up @@ -50,10 +51,12 @@ export function Emits<TBase extends Eventable>(Base: TBase) {
return this.emitter.getMaxListeners();
}

// eslint-disable-next-line @typescript-eslint/ban-types
listeners(eventName: string | symbol): Function[] {
return this.emitter.listeners(eventName);
}

// eslint-disable-next-line @typescript-eslint/ban-types
rawListeners(eventName: string | symbol): Function[] {
return this.emitter.rawListeners(eventName);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/server-node/src/LDClientNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ class LDClientNode extends LDClientImpl implements LDClient {
return this.emitter.getMaxListeners();
}

// eslint-disable-next-line @typescript-eslint/ban-types
listeners(eventName: string | symbol): Function[] {
return this.emitter.listeners(eventName);
}

// eslint-disable-next-line @typescript-eslint/ban-types
rawListeners(eventName: string | symbol): Function[] {
return this.emitter.rawListeners(eventName);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/server-node/src/platform/NodeRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default class NodeRequests implements platform.Requests {
const impl = isSecure ? https : http;

const headers = { ...options.headers };
let bodyData: String | Buffer | undefined = options.body;
let bodyData: string | Buffer | undefined = options.body;

// For get requests we are going to automatically support compressed responses.
// Note this does not affect SSE as the event source is not using this fetch implementation.
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/shopify-oxygen/contract-tests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const port = 8000;
const clientPool = new ClientPool();

if (debugging) {
app.use((req: Request, res: Response, next: Function) => {
app.use((req: Request, res: Response, next: (...args: any[]) => void) => {
console.debug('request', req.method, req.url);
if (req.body) {
console.debug('request', JSON.stringify(req.body, null, 2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const mockOptions = ({
} as LDOptionsInternal;
};

const expectError = (callback: Function, expectedError: Error) => {
const expectError = (callback: (...args: any[]) => void, expectedError: Error) => {
expect.assertions(1);
try {
callback();
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/common/src/utils/deepCompact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import isEmptyObject from './isEmptyObject';
* @param obj
* @param ignoreKeys
*/
const deepCompact = <T extends Object>(obj?: T, ignoreKeys?: string[]) => {
const deepCompact = <T extends object>(obj?: T, ignoreKeys?: string[]) => {
if (!obj) {
return obj;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/sdk-client/src/LDClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,11 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
});
}

on(eventName: EventName, listener: Function): void {
on(eventName: EventName, listener: (...args: any[]) => void): void {
this.emitter.on(eventName, listener);
}

off(eventName: EventName, listener: Function): void {
off(eventName: EventName, listener: (...args: any[]) => void): void {
this.emitter.off(eventName, listener);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/shared/sdk-client/src/LDEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export type EventName =
* a system to allow listeners which have counts independent of the primary listener counts.
*/
export default class LDEmitter {
private _listeners: Map<EventName, Function[]> = new Map();
private _listeners: Map<EventName, ((...args: any[]) => void)[]> = new Map();

constructor(private _logger?: LDLogger) {}

on(name: EventName, listener: Function) {
on(name: EventName, listener: (...args: any[]) => void) {
if (typeof name !== 'string') {
this._logger?.warn('Only string event names are supported.');
return;
Expand All @@ -43,7 +43,7 @@ export default class LDEmitter {
* @param name
* @param listener Optional. If unspecified, all listeners for the event will be removed.
*/
off(name: EventName, listener?: Function) {
off(name: EventName, listener?: (...args: any[]) => void) {
const existingListeners = this._listeners.get(name);
if (!existingListeners) {
return;
Expand All @@ -64,7 +64,7 @@ export default class LDEmitter {
this._listeners.delete(name);
}

private _invokeListener(listener: Function, name: EventName, ...detail: any[]) {
private _invokeListener(listener: (...args: any[]) => void, name: EventName, ...detail: any[]) {
try {
listener(...detail);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getUpdateProcessorFactory(shouldError: boolean = false, initTimeoutMs:
return (
_clientContext: LDClientContext,
featureStore: LDFeatureStore,
initSuccessHandler: Function,
initSuccessHandler: (...args: any[]) => void,
errorHandler?: (e: Error) => void,
) => ({
start: jest.fn(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export interface LDTransactionalDataSourceUpdates extends LDDataSourceUpdates {
data: LDFeatureStoreDataStorage,
callback: () => void,
initMetadata?: internal.InitMetadata,
selector?: String,
selector?: string,
): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface LDTransactionalFeatureStore extends LDFeatureStore {
data: LDFeatureStoreDataStorage,
callback: () => void,
initMetadata?: internal.InitMetadata,
selector?: String,
selector?: string,
): void;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class TransactionalDataSourceUpdates implements LDTransactionalDa
data: LDFeatureStoreDataStorage,
callback: () => void,
initMetadata?: internal.InitMetadata,
selector?: String,
selector?: string,
): void {
const checkForChanges = this._hasEventListeners();
const doApplyChanges = (oldData: LDFeatureStoreDataStorage) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class AsyncTransactionalStoreFacade {
basis: boolean,
data: LDFeatureStoreDataStorage,
initMetadata?: internal.InitMetadata,
selector?: String,
selector?: string,
): Promise<void> {
return promisify((cb) => {
this._store.applyChanges(basis, data, cb, initMetadata, selector);
Expand Down
Loading