-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1419 from ably/1396-Crypto-tree-shaking
[SDK-3735] Create tree-shakable `Crypto` module
- Loading branch information
Showing
24 changed files
with
455 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
import { BaseRest } from './baserest'; | ||
import ClientOptions from '../../types/ClientOptions'; | ||
import { allCommonModules } from './modulesmap'; | ||
import Platform from 'common/platform'; | ||
import { DefaultMessage } from '../types/defaultmessage'; | ||
|
||
/** | ||
`DefaultRest` is the class that the non tree-shakable version of the SDK exports as `Rest`. It ensures that this version of the SDK includes all of the functionality which is optionally available in the tree-shakable version. | ||
*/ | ||
export class DefaultRest extends BaseRest { | ||
constructor(options: ClientOptions | string) { | ||
super(options, allCommonModules); | ||
super(options, { ...allCommonModules, Crypto: DefaultRest.Crypto ?? undefined }); | ||
} | ||
|
||
private static _Crypto: typeof Platform.Crypto = null; | ||
static get Crypto() { | ||
if (this._Crypto === null) { | ||
throw new Error('Encryption not enabled; use ably.encryption.js instead'); | ||
} | ||
|
||
return this._Crypto; | ||
} | ||
static set Crypto(newValue: typeof Platform.Crypto) { | ||
this._Crypto = newValue; | ||
} | ||
|
||
static Message = DefaultMessage; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { Rest } from './rest'; | ||
import { IUntypedCryptoStatic } from '../../types/ICryptoStatic'; | ||
|
||
export interface ModulesMap { | ||
Rest?: typeof Rest; | ||
Crypto?: IUntypedCryptoStatic; | ||
} | ||
|
||
export const allCommonModules: ModulesMap = { Rest }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Message, { fromEncoded, fromEncodedArray } from './message'; | ||
import * as API from '../../../../ably'; | ||
import Platform from 'common/platform'; | ||
|
||
/** | ||
`DefaultMessage` is the class returned by `DefaultRest` and `DefaultRealtime`’s `Message` static property. It introduces the static methods described in the `MessageStatic` interface of the public API of the non tree-shakable version of the library. | ||
*/ | ||
export class DefaultMessage extends Message { | ||
static async fromEncoded(encoded: unknown, inputOptions?: API.Types.ChannelOptions): Promise<Message> { | ||
return fromEncoded(Platform.Crypto, encoded, inputOptions); | ||
} | ||
|
||
static async fromEncodedArray(encodedArray: Array<unknown>, options?: API.Types.ChannelOptions): Promise<Message[]> { | ||
return fromEncodedArray(Platform.Crypto, encodedArray, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.