Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #313 from LedgerHQ/stricter-devices-flowtype
Browse files Browse the repository at this point in the history
Strict-er flowtype for @ledgerhq/devices ids
  • Loading branch information
gre authored Mar 20, 2019
2 parents 1145d50 + d657210 commit 2643fb9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
34 changes: 32 additions & 2 deletions packages/devices/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Logic for all Ledger devices.
- [getBluetoothServiceUuids](#getbluetoothserviceuuids)
- [getInfosForServiceUuid](#getinfosforserviceuuid)
- [Parameters](#parameters-3)
- [DeviceModelId](#devicemodelid)
- [DeviceModel](#devicemodel)
- [Properties](#properties)
- [BluetoothInfos](#bluetoothinfos)
Expand All @@ -40,7 +41,7 @@ Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa

#### Parameters

- `id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `id` **[DeviceModelId](#devicemodelid)**

Returns **[DeviceModel](#devicemodel)**

Expand All @@ -62,13 +63,42 @@ Returns **[DeviceModel](#devicemodel)?**

Returns **[BluetoothInfos](#bluetoothinfos)?**

### DeviceModelId

Type: $Keys<any>

### DeviceModel

Type: {id: [DeviceModelId](#devicemodelid), productName: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), usbProductId: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), usbOnly: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean), bluetoothSpec: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<{serviceUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), writeUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), notifyUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>?}

#### Properties

- `id` **[DeviceModelId](#devicemodelid)**
- `productName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `usbProductId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `usbOnly` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
- `bluetoothSpec` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<{serviceUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), writeUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), notifyUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>?**

### BluetoothInfos

Type: {deviceModel: [DeviceModel](#devicemodel), serviceUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), writeUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), notifyUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}

#### Properties

- `deviceModel` **[DeviceModel](#devicemodel)**
- `serviceUuid` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `writeUuid` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `notifyUuid` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**

# Type: {id: [DeviceModelId](#devicemodelid), productName: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), usbProductId: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), bluetoothSpec: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<{serviceUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), writeUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), notifyUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>?}

Type: {id: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), productName: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), usbProductId: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), usbOnly: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean), bluetoothSpec: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<{serviceUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), writeUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), notifyUuid: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>?}

> > > > > > > master
#### Properties

- `id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `id` **[DeviceModelId](#devicemodelid)**
- `productName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `usbProductId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `usbOnly` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
Expand Down
11 changes: 8 additions & 3 deletions packages/devices/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

const devices: { [id: string]: DeviceModel } = {
const devices = {
blue: {
id: "blue",
productName: "Ledger Blue",
Expand Down Expand Up @@ -45,7 +45,7 @@ export const ledgerUSBVendorId = 0x2c97;
/**
*
*/
export const getDeviceModel = (id: string): DeviceModel => {
export const getDeviceModel = (id: DeviceModelId): DeviceModel => {
const info = devices[id];
if (!info) throw new Error("device '" + id + "' does not exist");
return info;
Expand Down Expand Up @@ -85,11 +85,16 @@ export const getBluetoothServiceUuids = () => bluetoothServices;
export const getInfosForServiceUuid = (uuid: string): ?BluetoothInfos =>
serviceUuidToInfos[uuid.toLowerCase()];

/**
*
*/
export type DeviceModelId = $Keys<typeof devices>;

/**
*
*/
export type DeviceModel = {
id: string,
id: DeviceModelId,
productName: string,
usbProductId: number,
usbOnly: boolean,
Expand Down

0 comments on commit 2643fb9

Please sign in to comment.