From 288923fd558797ca59bc41c54cc8664d3f97f630 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Tue, 1 Aug 2023 10:41:23 -0300 Subject: [PATCH] Remove Platform.Crypto Unused as of 480aaa6. Resolves #1396. TODO can we make some stuff generic now? if not, update comments that relate to it (note that to see the correct bundle sizes you need to `build` first) --- src/common/lib/client/defaultrealtime.ts | 6 +++--- src/common/lib/client/defaultrest.ts | 6 +++--- src/common/platform.ts | 7 ------- src/platform/nativescript/index.ts | 1 - src/platform/nodejs/index.ts | 1 - src/platform/react-native/index.ts | 1 - src/platform/web-noencryption/index.ts | 1 - src/platform/web/index.ts | 1 - src/platform/web/modules.ts | 1 - test/realtime/crypto.test.js | 2 +- test/rest/presence.test.js | 2 +- 11 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/common/lib/client/defaultrealtime.ts b/src/common/lib/client/defaultrealtime.ts index f1d6f88d10..a8500c7d5c 100644 --- a/src/common/lib/client/defaultrealtime.ts +++ b/src/common/lib/client/defaultrealtime.ts @@ -4,7 +4,7 @@ import { allCommonModules } from './modulesmap'; import * as Utils from '../util/utils'; import ConnectionManager from '../transport/connectionmanager'; import ProtocolMessage from '../types/protocolmessage'; -import Platform from 'common/platform'; +import { IUntypedCryptoStatic } from 'common/types/ICryptoStatic'; export class DefaultRealtime extends BaseRealtime { constructor(options: ClientOptions) { @@ -15,7 +15,7 @@ export class DefaultRealtime extends BaseRealtime { static ConnectionManager = ConnectionManager; static ProtocolMessage = ProtocolMessage; - private static _Crypto: typeof Platform.Crypto = null; + private static _Crypto: IUntypedCryptoStatic | null = null; static get Crypto() { if (this._Crypto === null) { throw new Error('TODO'); @@ -23,7 +23,7 @@ export class DefaultRealtime extends BaseRealtime { return this._Crypto; } - static set Crypto(newValue: typeof Platform.Crypto) { + static set Crypto(newValue: IUntypedCryptoStatic | null) { this._Crypto = newValue; } } diff --git a/src/common/lib/client/defaultrest.ts b/src/common/lib/client/defaultrest.ts index 66cc8290d7..cc1e6eb2ba 100644 --- a/src/common/lib/client/defaultrest.ts +++ b/src/common/lib/client/defaultrest.ts @@ -1,14 +1,14 @@ import BaseRest from './baserest'; import ClientOptions from '../../types/ClientOptions'; import { allCommonModules } from './modulesmap'; -import Platform from 'common/platform'; +import { IUntypedCryptoStatic } from 'common/types/ICryptoStatic'; export class DefaultRest extends BaseRest { constructor(options: ClientOptions | string) { super(options, { ...allCommonModules, Crypto: DefaultRest.Crypto ?? undefined }); } - private static _Crypto: typeof Platform.Crypto = null; + private static _Crypto: IUntypedCryptoStatic | null = null; static get Crypto() { if (this._Crypto === null) { throw new Error('TODO'); @@ -16,7 +16,7 @@ export class DefaultRest extends BaseRest { return this._Crypto; } - static set Crypto(newValue: typeof Platform.Crypto) { + static set Crypto(newValue: IUntypedCryptoStatic | null) { this._Crypto = newValue; } } diff --git a/src/common/platform.ts b/src/common/platform.ts index 7d983c2307..ff0bd44a9f 100644 --- a/src/common/platform.ts +++ b/src/common/platform.ts @@ -7,7 +7,6 @@ import IBufferUtils from './types/IBufferUtils'; import Transport from './lib/transport/transport'; import * as WebBufferUtils from '../platform/web/lib/util/bufferutils'; import * as NodeBufferUtils from '../platform/nodejs/lib/util/bufferutils'; -import { IUntypedCryptoStatic } from '../common/types/ICryptoStatic'; type Bufferlike = WebBufferUtils.Bufferlike | NodeBufferUtils.Bufferlike; type BufferUtilsOutput = WebBufferUtils.Output | NodeBufferUtils.Output; @@ -23,12 +22,6 @@ export default class Platform { can in reality handle. */ static BufferUtils: IBufferUtils; - /* - We’d like this to be ICryptoStatic with the correct generic arguments, - but Platform doesn’t currently allow that, as described in the BufferUtils - comment above - */ - static Crypto: IUntypedCryptoStatic | null; static Http: typeof IHttp; static Transports: Array<(connectionManager: typeof ConnectionManager) => Transport>; static Defaults: IDefaults; diff --git a/src/platform/nativescript/index.ts b/src/platform/nativescript/index.ts index 22f336f6d2..6acc9d483b 100644 --- a/src/platform/nativescript/index.ts +++ b/src/platform/nativescript/index.ts @@ -22,7 +22,6 @@ import msgpack from '../web/lib/util/msgpack'; const Crypto = createCryptoClass(Config, BufferUtils); -Platform.Crypto = Crypto; Platform.BufferUtils = BufferUtils; Platform.Http = Http; Platform.Config = Config; diff --git a/src/platform/nodejs/index.ts b/src/platform/nodejs/index.ts index e0e8beb6f2..6a7d9cd217 100644 --- a/src/platform/nodejs/index.ts +++ b/src/platform/nodejs/index.ts @@ -18,7 +18,6 @@ import PlatformDefaults from './lib/util/defaults'; const Crypto = createCryptoClass(BufferUtils); -Platform.Crypto = Crypto; Platform.BufferUtils = BufferUtils as typeof Platform.BufferUtils; Platform.Http = Http; Platform.Config = Config; diff --git a/src/platform/react-native/index.ts b/src/platform/react-native/index.ts index b2927355db..e993ddcc54 100644 --- a/src/platform/react-native/index.ts +++ b/src/platform/react-native/index.ts @@ -22,7 +22,6 @@ const Config = configFactory(BufferUtils); const Crypto = createCryptoClass(Config, BufferUtils); -Platform.Crypto = Crypto; Platform.BufferUtils = BufferUtils; Platform.Http = Http; Platform.Config = Config; diff --git a/src/platform/web-noencryption/index.ts b/src/platform/web-noencryption/index.ts index cd906d3030..60c1b6abf8 100644 --- a/src/platform/web-noencryption/index.ts +++ b/src/platform/web-noencryption/index.ts @@ -17,7 +17,6 @@ import WebStorage from '../web/lib/util/webstorage'; import PlatformDefaults from '../web/lib/util/defaults'; import msgpack from '../web/lib/util/msgpack'; -Platform.Crypto = null; Platform.BufferUtils = BufferUtils; Platform.Http = Http; Platform.Config = Config; diff --git a/src/platform/web/index.ts b/src/platform/web/index.ts index fc20ed0870..a91d1488a7 100644 --- a/src/platform/web/index.ts +++ b/src/platform/web/index.ts @@ -18,7 +18,6 @@ import WebStorage from './lib/util/webstorage'; import PlatformDefaults from './lib/util/defaults'; import msgpack from './lib/util/msgpack'; -Platform.Crypto = Crypto; Platform.BufferUtils = BufferUtils; Platform.Http = Http; Platform.Config = Config; diff --git a/src/platform/web/modules.ts b/src/platform/web/modules.ts index 82b6f710ca..409dd1d67e 100644 --- a/src/platform/web/modules.ts +++ b/src/platform/web/modules.ts @@ -15,7 +15,6 @@ import { getDefaults } from '../../common/lib/util/defaults'; import WebStorage from './lib/util/webstorage'; import PlatformDefaults from './lib/util/defaults'; -Platform.Crypto = Crypto; Platform.BufferUtils = BufferUtils; Platform.Http = Http; Platform.Config = Config; diff --git a/test/realtime/crypto.test.js b/test/realtime/crypto.test.js index 8952bcf71e..59dff04ce3 100644 --- a/test/realtime/crypto.test.js +++ b/test/realtime/crypto.test.js @@ -4,7 +4,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var expect = chai.expect; var loadTestData = helper.loadTestData; var BufferUtils = Ably.Realtime.Platform.BufferUtils; - var Crypto = Ably.Realtime.Platform.Crypto; + var Crypto = Ably.Realtime.Crypto; var Message = Ably.Realtime.Message; var displayError = helper.displayError; var testResourcesPath = helper.testResourcesPath; diff --git a/test/rest/presence.test.js b/test/rest/presence.test.js index 1c9640631f..a19b38ad2e 100644 --- a/test/rest/presence.test.js +++ b/test/rest/presence.test.js @@ -4,7 +4,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async var rest; var cipherConfig; var expect = chai.expect; - var Crypto = Ably.Realtime.Platform.Crypto; + var Crypto = Ably.Realtime.Crypto; var BufferUtils = Ably.Realtime.Platform.BufferUtils; var arrFind = helper.arrFind;