@hangtime/grip-connect 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +4 -5
  2. package/deno.json +1 -1
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +1 -2
  5. package/dist/interfaces/device/climbro.interface.d.ts +1 -1
  6. package/dist/interfaces/device/entralpi.interface.d.ts +1 -1
  7. package/dist/interfaces/device/forceboard.interface.d.ts +1 -1
  8. package/dist/interfaces/device/kilterboard.interface.d.ts +1 -1
  9. package/dist/interfaces/device/motherboard.interface.d.ts +1 -1
  10. package/dist/interfaces/device/mysmartboard.interface.d.ts +1 -1
  11. package/dist/interfaces/device/progressor.interface.d.ts +1 -1
  12. package/dist/interfaces/device/wh-c06.interface.d.ts +1 -1
  13. package/dist/interfaces/device.interface.d.ts +3 -3
  14. package/dist/interfaces/index.d.ts +8 -0
  15. package/dist/interfaces/index.js +1 -0
  16. package/dist/models/base.model.d.ts +1 -1
  17. package/dist/models/device/climbro.model.d.ts +2 -2
  18. package/dist/models/device/climbro.model.js +1 -1
  19. package/dist/models/device/entralpi.model.d.ts +2 -2
  20. package/dist/models/device/entralpi.model.js +1 -1
  21. package/dist/models/device/forceboard.model.d.ts +2 -2
  22. package/dist/models/device/forceboard.model.js +1 -1
  23. package/dist/models/device/kilterboard.model.d.ts +7 -7
  24. package/dist/models/device/kilterboard.model.js +6 -6
  25. package/dist/models/device/motherboard.model.d.ts +2 -2
  26. package/dist/models/device/motherboard.model.js +1 -1
  27. package/dist/models/device/mysmartboard.model.d.ts +2 -2
  28. package/dist/models/device/mysmartboard.model.js +1 -1
  29. package/dist/models/device/progressor.model.d.ts +3 -2
  30. package/dist/models/device/progressor.model.js +3 -3
  31. package/dist/models/device/wh-c06.model.d.ts +2 -2
  32. package/dist/models/device/wh-c06.model.js +1 -1
  33. package/dist/models/device.model.d.ts +17 -27
  34. package/dist/models/device.model.js +84 -94
  35. package/dist/models/index.d.ts +8 -8
  36. package/dist/models/index.js +8 -8
  37. package/package.json +3 -3
  38. package/src/index.ts +11 -2
  39. package/src/interfaces/device/climbro.interface.ts +1 -1
  40. package/src/interfaces/device/entralpi.interface.ts +1 -1
  41. package/src/interfaces/device/forceboard.interface.ts +1 -1
  42. package/src/interfaces/device/kilterboard.interface.ts +1 -1
  43. package/src/interfaces/device/motherboard.interface.ts +1 -1
  44. package/src/interfaces/device/mysmartboard.interface.ts +1 -1
  45. package/src/interfaces/device/progressor.interface.ts +1 -1
  46. package/src/interfaces/device/wh-c06.interface.ts +1 -1
  47. package/src/interfaces/device.interface.ts +3 -3
  48. package/src/interfaces/index.ts +15 -0
  49. package/src/models/base.model.ts +1 -1
  50. package/src/models/device/climbro.model.ts +2 -2
  51. package/src/models/device/entralpi.model.ts +2 -2
  52. package/src/models/device/forceboard.model.ts +2 -2
  53. package/src/models/device/kilterboard.model.ts +14 -14
  54. package/src/models/device/motherboard.model.ts +3 -3
  55. package/src/models/device/mysmartboard.model.ts +2 -2
  56. package/src/models/device/progressor.model.ts +4 -4
  57. package/src/models/device/wh-c06.model.ts +2 -2
  58. package/src/models/device.model.ts +92 -107
  59. package/src/models/index.ts +8 -8
package/README.md CHANGED
@@ -35,9 +35,8 @@ Learn more: [Documentation](https://stevie-ray.github.io/hangtime-grip-connect/)
35
35
 
36
36
  ## Install
37
37
 
38
- This package is compatible with both Node.js and browser environments. It can be found in the
39
- [NPM](https://www.npmjs.com/package/@hangtime/grip-connect) and [JSR](https://jsr.io/@hangtime/grip-connect) package
40
- registries.
38
+ This package works with Node.js, Bun, Deno, and the web, and is available on both
39
+ [NPM](https://www.npmjs.com/package/@hangtime/grip-connect) and [JSR](https://jsr.io/@hangtime/grip-connect).
41
40
 
42
41
  ```sh [npm]
43
42
  $ npm install @hangtime/grip-connect
@@ -102,10 +101,10 @@ document.querySelector("#motherboard").addEventListener("click", async () => {
102
101
  // await motherboard.stop()
103
102
 
104
103
  // Download data as CSV, JSON, or XML (default: CSV) format => timestamp, frame, battery, samples, masses
105
- // motherboard.download('json')
104
+ // await motherboard.download('json')
106
105
 
107
106
  // Optionally disconnect from device after we are done
108
- motherboard.disconnect(Motherboard)
107
+ motherboard.disconnect()
109
108
  },
110
109
  (error) => {
111
110
  // Optinal custom error handeling
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hangtime/grip-connect",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "license": "BSD-2-Clause",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export { Climbro, Entralpi, ForceBoard, KilterBoard, Motherboard, mySmartBoard, Progressor, WHC06, } from "./models/index.js";
1
+ export type { IClimbro, IEntralpi, IForceBoard, IKilterBoard, IMotherboard, ImySmartBoard, IProgressor, IWHC06, } from "./interfaces/index";
2
+ export { Climbro, Entralpi, ForceBoard, KilterBoard, Motherboard, mySmartBoard, Progressor, WHC06, } from "./models/index";
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
- // @ts-types="npm:@types/web-bluetooth@^0.0.20"
2
- export { Climbro, Entralpi, ForceBoard, KilterBoard, Motherboard, mySmartBoard, Progressor, WHC06, } from "./models/index.js";
1
+ export { Climbro, Entralpi, ForceBoard, KilterBoard, Motherboard, mySmartBoard, Progressor, WHC06, } from "./models/index";
@@ -1,4 +1,4 @@
1
- import type { IDevice } from "../device.interface.js";
1
+ import type { IDevice } from "../device.interface";
2
2
  /**
3
3
  * Interface representing the Climbro device, extending the base Device interface.
4
4
  */
@@ -1,4 +1,4 @@
1
- import type { IDevice } from "../device.interface.js";
1
+ import type { IDevice } from "../device.interface";
2
2
  /**
3
3
  * Interface representing the Entralpi device, extending the base Device interface.
4
4
  */
@@ -1,4 +1,4 @@
1
- import type { IDevice } from "../device.interface.js";
1
+ import type { IDevice } from "../device.interface";
2
2
  /**
3
3
  * Interface representing the PitchSix ForceBoard device, extending the base Device interface.
4
4
  */
@@ -1,4 +1,4 @@
1
- import type { IDevice } from "../device.interface.js";
1
+ import type { IDevice } from "../device.interface";
2
2
  /**
3
3
  * Interface representing the KilterBoard device, extending the base Device interface.
4
4
  */
@@ -1,4 +1,4 @@
1
- import type { IDevice } from "../device.interface.js";
1
+ import type { IDevice } from "../device.interface";
2
2
  /**
3
3
  * Interface representing the Griptonite Motherboard device, extending the base Device interface.
4
4
  */
@@ -1,4 +1,4 @@
1
- import type { IDevice } from "../device.interface.js";
1
+ import type { IDevice } from "../device.interface";
2
2
  /**
3
3
  * Interface representing the Smartboard Climbing mySmartBoard device, extending the base Device interface.
4
4
  */
@@ -1,4 +1,4 @@
1
- import type { IDevice } from "../device.interface.js";
1
+ import type { IDevice } from "../device.interface";
2
2
  /**
3
3
  * Interface representing the Tindeq Progressor device, extending the base Device interface.
4
4
  */
@@ -1,4 +1,4 @@
1
- import type { IDevice } from "../device.interface.js";
1
+ import type { IDevice } from "../device.interface";
2
2
  /**
3
3
  * Interface representing the Weiheng WH-C06 device, extending the base Device interface.
4
4
  */
@@ -1,6 +1,6 @@
1
- import type { IBase } from "./base.interface.js";
2
- import type { massObject } from "./callback.interface.js";
3
- import type { Commands } from "./command.interface.js";
1
+ import type { IBase } from "./base.interface";
2
+ import type { massObject } from "./callback.interface";
3
+ import type { Commands } from "./command.interface";
4
4
  /**
5
5
  * Represents a characteristic of a Bluetooth service.
6
6
  */
@@ -0,0 +1,8 @@
1
+ export type { IClimbro } from "./device/climbro.interface";
2
+ export type { IEntralpi } from "./device/entralpi.interface";
3
+ export type { IForceBoard } from "./device/forceboard.interface";
4
+ export type { IKilterBoard } from "./device/kilterboard.interface";
5
+ export type { IMotherboard } from "./device/motherboard.interface";
6
+ export type { ImySmartBoard } from "./device/mysmartboard.interface";
7
+ export type { IProgressor } from "./device/progressor.interface";
8
+ export type { IWHC06 } from "./device/wh-c06.interface";
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import type { IBase } from "../interfaces/base.interface.js";
1
+ import type { IBase } from "../interfaces/base.interface";
2
2
  export declare abstract class BaseModel {
3
3
  id?: string;
4
4
  createdAt?: Date;
@@ -1,5 +1,5 @@
1
- import { Device } from "../device.model.js";
2
- import type { IClimbro } from "../../interfaces/device/climbro.interface.js";
1
+ import { Device } from "../device.model";
2
+ import type { IClimbro } from "../../interfaces/device/climbro.interface";
3
3
  /**
4
4
  * Represents a Climbro device.
5
5
  * TODO: Add services, do you own a Climbro? Help us!
@@ -1,4 +1,4 @@
1
- import { Device } from "../device.model.js";
1
+ import { Device } from "../device.model";
2
2
  /**
3
3
  * Represents a Climbro device.
4
4
  * TODO: Add services, do you own a Climbro? Help us!
@@ -1,5 +1,5 @@
1
- import { Device } from "../device.model.js";
2
- import type { IEntralpi } from "../../interfaces/device/entralpi.interface.js";
1
+ import { Device } from "../device.model";
2
+ import type { IEntralpi } from "../../interfaces/device/entralpi.interface";
3
3
  /**
4
4
  * Represents a Entralpi device.
5
5
  * {@link https://entralpi.com}
@@ -1,4 +1,4 @@
1
- import { Device } from "../device.model.js";
1
+ import { Device } from "../device.model";
2
2
  /**
3
3
  * Represents a Entralpi device.
4
4
  * {@link https://entralpi.com}
@@ -1,5 +1,5 @@
1
- import { Device } from "../device.model.js";
2
- import type { IForceBoard } from "../../interfaces/device/forceboard.interface.js";
1
+ import { Device } from "../device.model";
2
+ import type { IForceBoard } from "../../interfaces/device/forceboard.interface";
3
3
  /**
4
4
  * Represents a PitchSix Force Board device.
5
5
  * {@link https://pitchsix.com}
@@ -1,4 +1,4 @@
1
- import { Device } from "../device.model.js";
1
+ import { Device } from "../device.model";
2
2
  /**
3
3
  * Represents a PitchSix Force Board device.
4
4
  * {@link https://pitchsix.com}
@@ -1,5 +1,5 @@
1
- import { Device } from "../device.model.js";
2
- import type { IKilterBoard } from "../../interfaces/device/kilterboard.interface.js";
1
+ import { Device } from "../device.model";
2
+ import type { IKilterBoard } from "../../interfaces/device/kilterboard.interface";
3
3
  /**
4
4
  * For API level 2 and API level 3.
5
5
  * The first byte in the data is dependent on where the packet is in the message as a whole.
@@ -74,13 +74,13 @@ export declare class KilterBoard extends Device implements IKilterBoard {
74
74
  /**
75
75
  * Calculates the checksum for a byte array by summing up all bytes ot hre packet in a single-byte variable.
76
76
  * @param data - The array of bytes to calculate the checksum for.
77
- * @returns The calculated checksum value.
77
+ * @returns {number} The calculated checksum value.
78
78
  */
79
79
  private checksum;
80
80
  /**
81
81
  * Wraps a byte array with header and footer bytes for transmission.
82
82
  * @param data - The array of bytes to wrap.
83
- * @returns The wrapped byte array.
83
+ * @returns {number[]} The wrapped byte array.
84
84
  */
85
85
  private wrapBytes;
86
86
  /**
@@ -88,7 +88,7 @@ export declare class KilterBoard extends Device implements IKilterBoard {
88
88
  * The lowest 8 bits of the position get put in the first byte of the group.
89
89
  * The highest 8 bits of the position get put in the second byte of the group.
90
90
  * @param position - The position to encode.
91
- * @returns The encoded byte array representing the position.
91
+ * @returns {number[]} The encoded byte array representing the position.
92
92
  */
93
93
  private encodePosition;
94
94
  /**
@@ -113,10 +113,10 @@ export declare class KilterBoard extends Device implements IKilterBoard {
113
113
  private prepBytesV3;
114
114
  /**
115
115
  * Splits a collection into slices of the specified length.
116
- * https://github.com/ramda/ramda/blob/master/source/splitEvery.js
116
+ * https://github.com/ramda/ramda/blob/master/source/splitEvery
117
117
  * @param {Number} n
118
118
  * @param {Array} list
119
- * @return {Array}
119
+ * @return {Array<number[]>}
120
120
  */
121
121
  private splitEvery;
122
122
  /**
@@ -1,4 +1,4 @@
1
- import { Device } from "../device.model.js";
1
+ import { Device } from "../device.model";
2
2
  /**
3
3
  * For API level 2 and API level 3.
4
4
  * The first byte in the data is dependent on where the packet is in the message as a whole.
@@ -130,7 +130,7 @@ export class KilterBoard extends Device {
130
130
  /**
131
131
  * Calculates the checksum for a byte array by summing up all bytes ot hre packet in a single-byte variable.
132
132
  * @param data - The array of bytes to calculate the checksum for.
133
- * @returns The calculated checksum value.
133
+ * @returns {number} The calculated checksum value.
134
134
  */
135
135
  checksum(data) {
136
136
  let i = 0;
@@ -142,7 +142,7 @@ export class KilterBoard extends Device {
142
142
  /**
143
143
  * Wraps a byte array with header and footer bytes for transmission.
144
144
  * @param data - The array of bytes to wrap.
145
- * @returns The wrapped byte array.
145
+ * @returns {number[]} The wrapped byte array.
146
146
  */
147
147
  wrapBytes(data) {
148
148
  if (data.length > KilterBoard.messageBodyMaxLength) {
@@ -165,7 +165,7 @@ export class KilterBoard extends Device {
165
165
  * The lowest 8 bits of the position get put in the first byte of the group.
166
166
  * The highest 8 bits of the position get put in the second byte of the group.
167
167
  * @param position - The position to encode.
168
- * @returns The encoded byte array representing the position.
168
+ * @returns {number[]} The encoded byte array representing the position.
169
169
  */
170
170
  encodePosition(position) {
171
171
  const position1 = position & 255;
@@ -234,10 +234,10 @@ export class KilterBoard extends Device {
234
234
  }
235
235
  /**
236
236
  * Splits a collection into slices of the specified length.
237
- * https://github.com/ramda/ramda/blob/master/source/splitEvery.js
237
+ * https://github.com/ramda/ramda/blob/master/source/splitEvery
238
238
  * @param {Number} n
239
239
  * @param {Array} list
240
- * @return {Array}
240
+ * @return {Array<number[]>}
241
241
  */
242
242
  splitEvery(n, list) {
243
243
  if (n <= 0) {
@@ -1,5 +1,5 @@
1
- import { Device } from "../device.model.js";
2
- import type { IMotherboard } from "../../interfaces/device/motherboard.interface.js";
1
+ import { Device } from "../device.model";
2
+ import type { IMotherboard } from "../../interfaces/device/motherboard.interface";
3
3
  /**
4
4
  * Represents a Griptonite Motherboard device.
5
5
  * {@link https://griptonite.io}
@@ -1,4 +1,4 @@
1
- import { Device } from "../device.model.js";
1
+ import { Device } from "../device.model";
2
2
  /**
3
3
  * Represents a Griptonite Motherboard device.
4
4
  * {@link https://griptonite.io}
@@ -1,5 +1,5 @@
1
- import { Device } from "../device.model.js";
2
- import type { ImySmartBoard } from "../../interfaces/device/mysmartboard.interface.js";
1
+ import { Device } from "../device.model";
2
+ import type { ImySmartBoard } from "../../interfaces/device/mysmartboard.interface";
3
3
  /**
4
4
  * Represents a Smartboard Climbing mySmartBoard device.
5
5
  * TODO: Add services, do you own a mySmartBoard? Help us!
@@ -1,4 +1,4 @@
1
- import { Device } from "../device.model.js";
1
+ import { Device } from "../device.model";
2
2
  /**
3
3
  * Represents a Smartboard Climbing mySmartBoard device.
4
4
  * TODO: Add services, do you own a mySmartBoard? Help us!
@@ -1,7 +1,8 @@
1
- import { Device } from "../device.model.js";
2
- import type { IProgressor } from "../../interfaces/device/progressor.interface.js";
1
+ import { Device } from "../device.model";
2
+ import type { IProgressor } from "../../interfaces/device/progressor.interface";
3
3
  /**
4
4
  * Represents a Tindeq Progressor device.
5
+ * {@link https://tindeq.com}
5
6
  */
6
7
  export declare class Progressor extends Device implements IProgressor {
7
8
  constructor();
@@ -1,7 +1,6 @@
1
- import { Device } from "../device.model.js";
1
+ import { Device } from "../device.model";
2
2
  /**
3
- * Represents a Tindeq Progressor device.
4
- * {@link https://tindeq.com}
3
+ * Progressor responses
5
4
  */
6
5
  var ProgressorResponses;
7
6
  (function (ProgressorResponses) {
@@ -33,6 +32,7 @@ var ProgressorResponses;
33
32
  })(ProgressorResponses || (ProgressorResponses = {}));
34
33
  /**
35
34
  * Represents a Tindeq Progressor device.
35
+ * {@link https://tindeq.com}
36
36
  */
37
37
  export class Progressor extends Device {
38
38
  constructor() {
@@ -1,5 +1,5 @@
1
- import { Device } from "../device.model.js";
2
- import type { IWHC06 } from "../../interfaces/device/wh-c06.interface.js";
1
+ import { Device } from "../device.model";
2
+ import type { IWHC06 } from "../../interfaces/device/wh-c06.interface";
3
3
  /**
4
4
  * Represents a Weiheng - WH-C06 (or MAT Muscle Meter) device.
5
5
  * To use this device enable: `chrome://flags/#enable-experimental-web-platform-features`.
@@ -1,4 +1,4 @@
1
- import { Device } from "../device.model.js";
1
+ import { Device } from "../device.model";
2
2
  /**
3
3
  * Represents a Weiheng - WH-C06 (or MAT Muscle Meter) device.
4
4
  * To use this device enable: `chrome://flags/#enable-experimental-web-platform-features`.
@@ -1,8 +1,8 @@
1
- import { BaseModel } from "./../models/base.model.js";
2
- import type { IDevice, Service } from "../interfaces/device.interface.js";
3
- import type { ActiveCallback, NotifyCallback, WriteCallback } from "../interfaces/callback.interface.js";
4
- import type { DownloadPacket } from "../interfaces/download.interface.js";
5
- import type { Commands } from "../interfaces/command.interface.js";
1
+ import { BaseModel } from "./../models/base.model";
2
+ import type { IDevice, Service } from "../interfaces/device.interface";
3
+ import type { ActiveCallback, NotifyCallback, WriteCallback } from "../interfaces/callback.interface";
4
+ import type { DownloadPacket } from "../interfaces/download.interface";
5
+ import type { Commands } from "../interfaces/command.interface";
6
6
  export declare abstract class Device extends BaseModel implements IDevice {
7
7
  /**
8
8
  * Filters to identify the device during Bluetooth scanning.
@@ -26,7 +26,7 @@ export declare abstract class Device extends BaseModel implements IDevice {
26
26
  * @type {BluetoothDevice | undefined}
27
27
  * @public
28
28
  */
29
- bluetooth?: BluetoothDevice | undefined;
29
+ bluetooth?: BluetoothDevice;
30
30
  /**
31
31
  * Object representing the set of commands available for this device.
32
32
  * These commands allow communication with the device to perform various operations such as starting measurements, retrieving data, or calibrating the device.
@@ -257,13 +257,13 @@ export declare abstract class Device extends BaseModel implements IDevice {
257
257
  * @param {('csv' | 'json' | 'xml')} [format='csv'] - The format in which to download the data.
258
258
  * Defaults to 'csv'. Accepted values are 'csv', 'json', and 'xml'.
259
259
  *
260
- * @returns {void} Initiates a download of the data in the specified format.
261
- * @private
260
+ * @returns {Promise<void>} Resolves when the data has been downloaded/written
261
+ * @public
262
262
  *
263
263
  * @example
264
- * device.download('json');
264
+ * await device.download('json');
265
265
  */
266
- download: (format?: "csv" | "json" | "xml") => void;
266
+ download: (format?: "csv" | "json" | "xml") => Promise<void>;
267
267
  /**
268
268
  * Returns UUIDs of all services associated with the device.
269
269
  * @returns {string[]} Array of service UUIDs.
@@ -275,25 +275,15 @@ export declare abstract class Device extends BaseModel implements IDevice {
275
275
  */
276
276
  protected getAllServiceUUIDs: () => string[];
277
277
  /**
278
- * Attempt to use ES module import rather than require.
279
- * This approach uses an async dynamic import for `webbluetooth`,
280
- * so we can fallback if `navigator.bluetooth` is unavailable.
281
- */
282
- protected getBluetooth(): Promise<Bluetooth | import("webbluetooth").Bluetooth>;
283
- /**
284
- * Retrieves the characteristic from the device's service.
285
- * @param {string} serviceId - The UUID of the service.
286
- * @param {string} characteristicId - The UUID of the characteristic.
287
- * @returns {BluetoothRemoteGATTCharacteristic | undefined} The characteristic, if found.
288
- * @protected
278
+ * Returns the Bluetooth instance available for the current environment.
279
+ * In browsers, it returns the native Web Bluetooth API (i.e. `navigator.bluetooth`).
280
+ * In a Node, Bun, or Deno environment, it dynamically imports the `webbluetooth` package.
281
+ * {@link https://github.com/thegecko/webbluetooth}
289
282
  *
290
- * @example
291
- * const characteristic = device.getCharacteristic('battery', 'level');
292
- * if (characteristic) {
293
- * console.log('Characteristic found');
294
- * }
283
+ * @returns {Promise<Bluetooth>} A promise that resolves to the Bluetooth instance.
284
+ * @throws {Error} If Web Bluetooth is not available in the current environment.
295
285
  */
296
- protected getCharacteristic: (serviceId: string, characteristicId: string) => BluetoothRemoteGATTCharacteristic | undefined;
286
+ protected getBluetooth(): Promise<Bluetooth>;
297
287
  /**
298
288
  * Handles notifications received from a characteristic.
299
289
  * @param {BluetoothRemoteGATTCharacteristic} characteristic - The notification event.